# Development guide [简体中文](./development.md) | [繁體中文(台灣)](./development_zh-TW.md) | English | [日本語](./development_ja.md) | [한국어](./development_ko.md) | [Русский](./development_ru.md) | [Español](./development_es.md) | [Português (Brasil)](./development_pt.md) | [Türkçe](./development_tr.md) This guide is for people who want to run AnyModelBot from source, package it, or contribute. If you only want to use the app, download an installer from [Releases](https://github.com/modelflare-ai/AnyModelBot/releases); see the [README](../README_en.md#-download-and-run). - A bot is a persona, a default model and its memory. Accounts are global (Settings › Chat channels) and shared by all bots, with as many per service as you like. Built for personal use by one person. - Models come from a Modelflare account or your own official API keys. [Modelflare](https://modelflare.dev/?utm_source=anymodelbot&utm_campaign=amb_readme): on first launch you sign in to (or sign up for) a Modelflare account and the models are listed automatically. Requests go through the bundled [magpie](https://github.com/yetone/magpie) gateway. - Three ways to run, one codebase: **desktop app (Electron)**, **command line `npm start`**, **Docker**. ## Repository layout ``` src/ core/ shared message types, session queue and dedup, runtime (/model /reset, streaming), the notice after a restart, admission (owner + allowlist), durable outbox delivery/ proactive message delivery: quiet hours, daily caps, digests, the WeChat 24-hour window and renewal nudges agent/ agent mode: DSH host and bridge, approvals, permission presets, memory and context steward, DSH session directories prompts/ every prompt the agent model reads: persona, chat rules, memory guide, a segment's first message, skills tools/ capabilities the agent uses: web search (search.ts), image / video generation (media/), computer use (computer-use/), Windows PowerShell (pwsh/), Connect apps — built-in app connectors and custom MCP (apps/), existing Notion / Feishu accounts (accounts/) llm/ OpenAI-compatible client (model access interface) magpie/ magpie supervisor: isolated directories, free port, generated secret, health checks, crash restart, clean exit channels/ feishu/ (long connection + CardKit) weixin/ (iLink; MIT notice in LICENSE.openclaw-weixin) messenger/ (Telegram, Slack, Discord, sharing one send and receive path) tasks/ background tasks and rules: runs, stages, cost, retention and cleanup, schedules botkit/ catalog bot framework: package format, checks, packing and signing, catalog, install, static UI routes (see docs/bot-framework_en.md) skills/ skills users install themselves (ZIP packages) store/ SQLite (node:sqlite, no native build) domain/ Plain data shapes and rules: bot settings, quiet hours, schedules, catalog bot records, agent steps; no I/O, depends only on i18n. store depends only on this (dependency direction is checked by test/architecture.unit.test.ts) account/ Modelflare account: PKCE loopback sign-in, token rotation, balance and reminders, per-bot budget keys, model capabilities and reference prices web/ console server: server.ts starts, authenticates and dispatches; routes/ holds the endpoints by area (JSON API + streaming chat over SSE); http.ts has the shared helpers cli/ init first-run wizard, weixin-login providers/ where models come from: modelflare.ts (routes, key validation GET /v1/models, model routing and attribution), modelflare-domains.ts (route speed test), official.ts (official API provider table, fixed addresses) updates/ updates: check.ts (new version check), desktop.ts (desktop download and restart) guide.ts onboarding checklist progress i18n/ server-side i18n: errors, status text, tray menu, system messages from bots (messages/.ts) diagnostics.ts troubleshooting: probes, log tail, redacted diagnostics report version.ts app version (package.json) main.ts command-line entry point electron/ desktop main process (launcher + tray) ui/ console UI (Preact + htm, no build step) design/ design system: tokens/, base/, components/, bot characters bots/ locales/ UI strings: zh-CN/, zh-TW/ and en/, one file per namespace css/ lib/ components/ screens/ assets/ main.js dsh-runtime/ dependency manifest for the DSH agent runtime and AnyModelBot plugins (plugins/) scripts/ setup / build-magpie / fetch-cua-driver / prepare-dsh / bundle-dsh / electron-smoke / check-readme and more vendor/ git submodules: magpie (compiled at build time), deepseek-harness, kimi-computer-use site/ website (Astro static site); see site/README.md docs/ development guide, privacy notes, README assets (docs/assets/) ``` ## Run from source (command line) Requires Node.js 22.13+ and Go 1.26.8+ (to compile magpie from source). ```bash npm install npm run setup # fetch the vendor/magpie submodule and compile it into build/bin/ npm run init # optional: first-run setup in the terminal (sign in to Modelflare, Feishu credentials) npm start # start everything: gateway + bots + console at http://127.0.0.1:3600/ ``` Data lives in `./data` by default (change it with `AMB_DATA_DIR`). Other environment variables are listed in `.env.example`. The console opens only with an access token: when `AMB_UI_TOKEN` is not set, one is generated and saved in `ui-token` in the data directory, and starting from a terminal prints a link with the token once. On Linux, commands the agent runs only run inside the bubblewrap sandbox (Debian/Ubuntu: `apt install bubblewrap`); when bubblewrap is unavailable they are refused rather than run in another sandbox. If Landlock, which only restricts writes, is all you can use, set `AMB_ALLOW_LANDLOCK=1`. ## Desktop app (Electron) ```bash npm run electron:dev # run in development mode npm run electron:smoke # smoke test (uses xvfb-run automatically on headless Linux) npm run dist # package for the current platform (magpie ships in resources/magpie/) npm run dist:linux | dist:mac | dist:win npm run test:dsh-bundle # real DSH integration test under Electron against the packed build/dsh (run prepare:dsh + bundle:dsh first) ``` - DSH agent runtime: `scripts/prepare-dsh.mjs` installs `dsh-runtime/` for the target platform, and `scripts/bundle-dsh.mjs` packs it into `resources/dsh/dsh.asar` (all JavaScript, one file) plus `resources/dsh/node_modules/` (native packages only, about 55 files). The Electron main process and `ELECTRON_RUN_AS_NODE` child processes read the asar directly, with no extraction on first launch, so the installer only unpacks a few hundred files (on Windows, extraction and per-file antivirus scans are the main cause of slow installs). Development still uses `dsh-runtime/` directly. - PowerShell for agent commands on Windows: inside the sandbox, Windows PowerShell 5.1 takes 20–30 seconds per command and PowerShell 7 about 1 second. The app picks, in order: a working PowerShell 7 already on the system (tried once in the background the way DSH runs it; nothing is downloaded) → the app's private PowerShell 7 → Windows PowerShell 5.1. When no working 7 exists and agent mode is on, the app downloads the official PowerShell 7.6.9 (LTS) zip in the background into `%LOCALAPPDATA%\AnyModelBot\pwsh\`: no admin rights, no registry writes, no PATH changes, and your own PowerShell is untouched. The version and the SHA256 of the x64 / arm64 zips are pinned in `src/tools/pwsh/private.ts` (bump them with `node scripts/pwsh-hashes.mjs `). After download the hash is checked, after extraction Microsoft's Authenticode signature is checked, and it is only used after a DSH-style trial run (version, read/write a temp file, launch an external program) passes; failed or half-finished installs are never used and are cleaned up on the next launch. While installing, the chat screen and Settings → General show progress, and so does `/status`; commands keep using 5.1 until it is ready, and idle agent processes switch over in the background without restarting the app. If the agent cannot start it at runtime (removed or quarantined by antivirus, blocked by policy), the app falls back to the previous option and says why; Settings → Troubleshooting can install, reinstall or revert to the system default. Nothing is downloaded on systems older than Windows 10 1607 / Server 2016. The desktop app downloads through the system proxy (Chromium network stack); the command-line build uses Node's fetch (newer Node versions honour `HTTPS_PROXY` when `NODE_USE_ENV_PROXY=1`). `AMB_PWSH_MIRROR` switches to a mirror prefix (hash and signature are still checked), and `AMB_PWSH_AUTO_INSTALL=0` turns automatic installation off. - Agent commands have network access (the sandbox only restricts writes) and use your proxy: `HTTP_PROXY` / `HTTPS_PROXY` / `ALL_PROXY` / `NO_PROXY` (and their lowercase forms) and the certificate and package-index variables (`SSL_CERT_FILE`, `REQUESTS_CA_BUNDLE`, `NODE_EXTRA_CA_CERTS`, `PIP_INDEX_URL`, `npm_config_registry`, `GOPROXY`, …) are passed through from the app's environment; when the environment sets no proxy, the desktop app asks for the system proxy (system settings and PAC) each time it starts the agent process and passes it on as `http://host:port` (see `src/agent/proxy-env.ts`). Loopback (`127.0.0.1`, `localhost`, `::1`) is always added to `NO_PROXY` and never proxied. - Data directory: `/data` (macOS `~/Library/Application Support/anymodel bot/data`, Windows `%APPDATA%\anymodel bot\data`, Linux `~/.config/anymodel bot/data`). Logs are in `logs/app.log` inside the data directory. - Startup diagnostics (available since 0.1.34, to help investigate #71): the desktop main process writes `logs/startup-