How xiaomimimo/mimo-code works
1. This is a TypeScript/Bun monorepo organized around one core product runtime and several adjacent surfaces. The main execution engine lives in packages/opencode, while packages/app, packages/desktop, packages/web, packages/console, packages/enterprise, packages/ui, packages/sdk, and packages/plugin provide alternate clients, cloud services, documentation, and integrations.
2. The heart of the system is packages/opencode: a terminal-native AI coding assistant. Its top-level flow is: CLI bootstrap → config/env loading → runtime initialization → server/session orchestration → provider calls and tool execution → persistence and resume. The runtime is designed around long-lived sessions, not short request/response cycles.
3. Session management is the core domain layer. packages/opencode/src/session, actor, task, workflow, history, memory, inbox, and share implement the long-horizon agent loop: prompt assembly, LLM request/response handling, checkpoints, compaction, retries, task trees, imports, and sharing. The README’s “persistent memory” and “automatic checkpoints” are backed by this layer.
4. The agent/tool boundary is explicit. packages/opencode/src/tool defines the available capabilities such as shell, file read/write/edit, git, ripgrep/search, LSP, MCP, web fetch/search, memory access, tasks, and workflows. Session code decides when to invoke tools; tool modules encapsulate the concrete side effects and permission checks.
5. Model/provider integration is another major boundary. packages/opencode/src/provider normalizes multiple LLM backends and their auth/model schemas, while packages/opencode/src/plugin adds provider-specific adapters and custom behaviors. This is what allows MiMo Auto, Xiaomi MiMo Platform OAuth, Claude imports, and OpenAI-compatible custom providers to coexist under one abstraction.
6. Persistent state is stored locally and is a first-class subsystem. packages/opencode/src/storage and the SQL schema files under session, memory, task, workflow, sync, and related modules indicate a SQLite-backed store with migrations. Memory and history use FTS-style search and are treated as durable context inputs for future sessions, not just logs.
7. The local UI is split across multiple shells. packages/opencode/src/cli/cmd/tui provides the terminal UI, packages/desktop wraps the same product in an Electron-style desktop shell, and packages/app contains a separate Solid/Vite web app that mirrors much of the session UI. These surfaces all sit above the same core session/service layer rather than reimplementing agent logic.
8. packages/ui is the shared presentation library. It contains reusable components, theming, i18n, and small interaction primitives used by the app/desktop/web surfaces. The architecture boundary here is “visual and interaction components only”; business logic stays in opencode or the product-specific apps.
9. packages/console is the cloud control plane for MiMoCode. It is an Astro/Vite app plus backend route handlers, auth, billing, model/provider management, workspace administration, and public marketing/docs endpoints. Unlike the local agent runtime, this side focuses on account lifecycle, subscriptions, rate limiting, provider routing, and enterprise features.
10. The console’s backend is split into packages/console/core, function, mail, and resource. core contains domain logic and database schema/migrations via Drizzle; function holds serverless helpers such as auth/log processing; mail renders transactional email templates; resource declares cloud resources. External dependencies here materially shape the architecture: OAuth, Stripe webhooks, provider APIs, and rate limit enforcement.
11. Sharing and enterprise distribution have their own surface area. packages/enterprise serves shared session/content views, while packages/opencode/src/share and the web app’s pages/s/[id] route support rendering exported conversations. This is a separate read-only publishing path from the interactive session runtime.
12. Integrations are packaged independently. packages/plugin is the generic plugin package, sdks/vscode is a VS Code extension, and packages/extensions/zed is a Zed integration. These consume the core runtime contracts but remain outside the local CLI/session implementation.
13. The documentation and public website are separate from the product runtime. packages/web is the Astro-based docs/marketing site with multilingual content, while packages/console/app also serves product-facing pages and docs routes for the cloud service. These sites are content-heavy and mostly consume shared share-rendering components rather than core agent logic.
14. Cross-cutting build and deployment concerns are centralized in the repo root. sst.config.ts, infra/, and the various script/ and packages/*/script directories orchestrate cloud deployment, releases, code generation, and packaging. The repo uses Bun, Turborepo, Vite, Storybook, Playwright, and extensive tests to keep the local runtime, cloud control plane, and UI surfaces aligned.
Main entry points: index.ts Session engine · server.ts Local server · bootstrap.ts CLI bootstrap · runtime.ts App runtime
Components 22
Repo root
Workspace-wide build, infra, and orchestration
- Build & infra · Repo-wide scripts, deployment, and packaging entrypoints
Core runtime
Local AI coding assistant runtime and its subsystems
- CLI bootstrap · Command parsing, startup, upgrades, and TUI launch
packages/opencode/src/cli/bootstrap.ts - Config layer · Loads and normalizes app, provider, model, plugin, and permission config
packages/opencode/src/config/index.ts - App runtime · Bootstraps services, logging, observability, and process coordination
packages/opencode/src/effect/runtime.ts - Local server · Bun/Node server, routes, middleware, and control-plane endpoints
packages/opencode/src/server/server.ts - Session engine · Long-lived session state, prompt assembly, checkpoints, compaction, retries, and summaries
packages/opencode/src/session/index.ts - Tool system · Shell, file, search, LSP, MCP, memory, task, and workflow tool definitions and execution
packages/opencode/src/tool/index.ts - Provider layer · Normalizes LLM backends, auth, model schemas, and response transforms
packages/opencode/src/provider/index.ts - Plugin system · Provider-specific adapters, checkpoint hooks, and plugin loading
packages/opencode/src/plugin/index.ts - SQLite store · Local durable storage, schema, migrations, and SQLite access
packages/opencode/src/storage/index.ts - History & memory · Persistent history, memory FTS, inbox, share, and sync-related context stores
packages/opencode/src/history/index.ts - Task workflow · Task trees, gates, events, and workflow orchestration for agent work
packages/opencode/src/task/index.ts - Workspace mgmt · Project, workspace, VCS, trust, and worktree lifecycle
packages/opencode/src/project/index.ts
User surfaces
Local and web client shells built on top of the runtime
- Terminal UI · Terminal-native interactive shell, dialogs, and session views
packages/opencode/src/cli/cmd/tui/app.tsx - Desktop shell · Desktop main/preload/renderer app with IPC, windows, updates, and local state
packages/desktop/src/main/index.ts - Web app · Browser-based session UI and shared session rendering routes
packages/app/src/app.tsx - Share views · Shared session rendering and export/read-only share surfaces
packages/enterprise/src/routes/share/[shareID].tsx
Cloud console
MiMoCode cloud control plane and admin surfaces
- Console app · Astro/Vite product site, auth, billing, providers, workspace admin, and API routes
packages/console/app/src/app.tsx - Console core · Shared cloud domain logic, database schema, billing, providers, accounts, and workspaces
packages/console/core/src/account.ts
Ecosystem
SDKs, plugins, extensions, and shared libraries
- SDKs & plugins · JS SDK, VS Code extension, generic plugin package, and other external integrations
packages/sdk/js/src/index.ts - Shared UI · Reusable presentation components, theming, i18n, and interaction primitives
packages/ui/src/components/button.tsx - Docs site · Documentation and marketing content plus share-rendering components
packages/web/src/pages/[...slug].md.ts
Connections 25
- Build & infra → CLI bootstrap: builds · Root scripts package and release the core runtime
- Build & infra → Desktop shell: packages · Desktop build and signing are orchestrated from the repo root
- Build & infra → Console app: deploys · Infra definitions wire the cloud console into cloud resources
- CLI bootstrap → Config layer: loads · CLI startup resolves config, env, and defaults
- CLI bootstrap → App runtime: starts · Bootstrap hands control to the effect runtime
- App runtime → Local server: hosts · Runtime serves local IPC/HTTP endpoints and route handlers
- App runtime → Workspace mgmt: binds · Runtime attaches project/workspace context to execution
- Local server → Session engine: orchestrates · Server routes create, inspect, and drive sessions
- Session engine → Provider layer: calls · Session loop invokes model providers for generation
- Session engine → Tool system: invokes · Agent turns request tool actions through the tool boundary
- Session engine → SQLite store: persists · Sessions write checkpoints, messages, and durable state locally
- Session engine → History & memory: reads/writes · History, memory, inbox, and share data feed the long-horizon loop
- Session engine → Task workflow: coordinates · Task trees and workflow state structure agent work
- Provider layer → Plugin system: extends · Plugins adapt specific providers and custom behaviors
- Tool system → Workspace mgmt: operates on · Tools act within the current project/worktree context
- Tool system → SQLite store: guards · Tool execution consults local permissions and stored state
- Terminal UI → Local server: talks to · Terminal UI consumes the local server/session API
- Desktop shell → Local server: talks to · Desktop shell reuses the same runtime services
- Web app → Local server: talks to · Web client mirrors session interactions through the shared service layer
- Console app → Console core: uses · Console routes rely on shared domain logic and schema
- Console app → Shared UI: renders with · Cloud UI reuses the shared presentation library
- Share views → History & memory: renders · Read-only share views consume exported session content
- Docs site → Share views: reuses · Docs and marketing pages reuse share-rendering components
- SDKs & plugins → Local server: integrates with · SDKs and extensions target the core runtime contracts
- SDKs & plugins → Shared UI: shares · Some integrations reuse shared visual primitives and theming