How pbga0517/mimo-code works
Purpose and Entry Points
MiMoCode is a Bun/TypeScript, terminal-native AI coding assistant forked from OpenCode. Its primary executable is mimo, backed by the core package entry point and CLI bootstrap: packages/opencode/bin/mimo, packages/opencode/src/index.ts, packages/opencode/src/cli/bootstrap.ts. Users operate through the OpenTUI terminal UI, headless CLI commands, or a local/remote HTTP server.
CLI, TUI, and Local Server
The CLI command layer selects interactive TUI, run, serve, attach, provider, session, and automation surfaces: packages/opencode/src/cli/cmd/cmd.ts, packages/opencode/src/cli/cmd/tui/app.tsx, packages/opencode/src/cli/cmd/serve.ts. The embedded server exposes instance-scoped HTTP APIs, SSE/event synchronization, PTY access, and routes for sessions, configuration, files, permissions, MCP, and workflows: packages/opencode/src/server/server.ts, packages/opencode/src/server/routes/instance/index.ts, packages/opencode/src/server/routes/instance/sync.ts. This API boundary also supports browser and desktop clients.
Session Execution and Context Lifecycle
A session is the central unit of agent work: it stores messages and run state, constructs prompts, calls models, processes tool loops, and handles retry/revert behavior. Key code is packages/opencode/src/session/session.ts, packages/opencode/src/session/prompt.ts, packages/opencode/src/session/processor.ts. Context management is an architectural differentiator: checkpoints, compaction, budgeted reads, reconstruction, and persistent summaries limit model-context growth while retaining task state: packages/opencode/src/session/checkpoint.ts, packages/opencode/src/session/compaction.ts, packages/opencode/src/session/budgeted-read.ts.
Agents, Actors, Tasks, and Workflows
Agents define behavioral modes and prompts; the actor subsystem runs primary and spawned subagents with lifecycle, grouping, cancellation, waiting, and turn tracking: packages/opencode/src/agent/agent.ts, packages/opencode/src/actor/spawn.ts, packages/opencode/src/actor/registry.ts. Task state is separately modeled as a gated tree/registry: packages/opencode/src/task/index.ts, packages/opencode/src/task/registry.ts. Deterministic multi-agent workflows run sandboxed JavaScript with persistence and workspace/worktree integration: packages/opencode/src/workflow/runtime.ts, packages/opencode/src/workflow/sandbox.ts, packages/opencode/src/workflow/persistence.ts.
Model, Tool, and Permission Boundary
Provider adapters normalize model catalogs, authentication, capabilities, images, errors, and model invocation across MiMo, OpenAI-compatible endpoints, Copilot, and other providers: packages/opencode/src/provider/provider.ts, packages/opencode/src/provider/models.ts, packages/opencode/src/provider/sdk/copilot/copilot-provider.ts. The tool registry supplies filesystem, shell/PTY, Git-aware edits, search, web, task/actor, memory, and MCP operations: packages/opencode/src/tool/registry.ts, packages/opencode/src/tool/bash.ts, packages/opencode/src/tool/actor.ts. Permissions evaluate each sensitive operation before execution, forming the primary safety boundary: packages/opencode/src/permission/evaluate.ts, packages/opencode/src/permission/permission.sql.ts.
Persistence, Memory, and Project Integration
Runtime data is persisted locally through SQLite adapters that support Bun and Node, schemas, and migrations: packages/opencode/src/storage/db.ts, packages/opencode/src/storage/schema.ts, packages/opencode/migration. Project instances bind working directories, VCS/worktrees, trust, configuration, and isolated state: packages/opencode/src/project/instance.ts, packages/opencode/src/project/project.ts, packages/opencode/src/worktree/index.ts. Persistent project/session memory and history use full-text-search-backed services: packages/opencode/src/memory/service.ts, packages/opencode/src/history/service.ts, packages/opencode/src/history/fts.sql.ts.
Extensibility and Distribution Ecosystem
Skills are discovered, ranked, injected, and may override bundled instructions; compose skills and bundled workflows extend agent behavior without changing the session engine: packages/opencode/src/skill/discovery.ts, packages/opencode/src/skill/search.ts, packages/opencode/src/skill/builtin. Plugins load executable extensions and hooks, including MiMo/Codex/Cloudflare integrations: packages/opencode/src/plugin/loader.ts, packages/opencode/src/plugin/index.ts.
Adjacent products include a Solid/Vite browser client (packages/app/src/entry.tsx, packages/app/src/context/global-sync.tsx), Electron desktop host (packages/desktop/src/main/index.ts, packages/desktop/src/main/server.ts), generated JavaScript SDK (packages/sdk/js/src/client.ts), and Cloudflare-oriented console/control plane with billing, authentication, provider proxying, rate limits, and database migrations (packages/console/app/src/routes/zen/v1/chat/completions.ts, packages/console/core/src/drizzle/index.ts, infra/app.ts).
Main entry points: session.ts Session engine · server.ts Embedded HTTP server · cmd.ts CLI command layer · prompt.ts Prompt construction
Components 23
User Interfaces
- mimo executable
packages/opencode/bin/mimo - CLI command layer
packages/opencode/src/cli/cmd/cmd.ts - Terminal UI
packages/opencode/src/cli/cmd/tui/app.tsx - Embedded HTTP server · Hosts instance-scoped APIs, SSE, and PTY access.
packages/opencode/src/server/server.ts - Instance API routes
packages/opencode/src/server/routes/instance/index.ts - Event synchronization
packages/opencode/src/server/routes/instance/sync.ts
Core Runtime
- Project instance · Binds directory, trust, configuration, and isolated state.
packages/opencode/src/project/instance.ts - SQLite storage
packages/opencode/src/storage/db.ts - Memory & history
packages/opencode/src/memory/service.ts - Skills & plugins
packages/opencode/src/plugin/loader.ts
Agent Execution
- Session engine · Stores messages and run state while driving model and tool loops.
packages/opencode/src/session/session.ts - Prompt construction
packages/opencode/src/session/prompt.ts - Context lifecycle · Controls context growth through checkpoints, summaries, and budgeted reads.
packages/opencode/src/session/compaction.ts - Agents & actors
packages/opencode/src/actor/spawn.ts - Task registry
packages/opencode/src/task/registry.ts - Workflow runtime
packages/opencode/src/workflow/runtime.ts - Provider adapters · Normalizes catalogs, auth, capabilities, and invocation.
packages/opencode/src/provider/provider.ts - Tool registry · Provides filesystem, shell, Git, search, web, MCP, and actor tools.
packages/opencode/src/tool/registry.ts - Permission evaluation · Authorizes sensitive operations before execution.
packages/opencode/src/permission/evaluate.ts
Clients & Control Plane
- Browser client
packages/app/src/entry.tsx - Desktop host
packages/desktop/src/main/server.ts - JavaScript SDK
packages/sdk/js/src/client.ts - Cloudflare control plane · Provides auth, billing, rate limits, and provider proxying.
packages/console/app/src/routes/zen/v1/chat/completions.ts
Connections 23
- mimo executable → CLI command layer: boots
- CLI command layer → Terminal UI: interactive mode
- CLI command layer → Embedded HTTP server: serve mode
- Terminal UI → Session engine: drives
- Embedded HTTP server → Instance API routes: hosts
- Embedded HTTP server → Event synchronization: streams events
- Instance API routes → Session engine: session operations
- Session engine → Prompt construction: builds
- Prompt construction → Context lifecycle: uses managed context
- Session engine → Provider adapters: invokes models
- Session engine → Tool registry: runs tool loop
- Session engine → Agents & actors: spawns subagents
- Agents & actors → Task registry: tracks work
- Workflow runtime → Agents & actors: orchestrates
- Tool registry → Permission evaluation: authorizes operations
- Session engine → SQLite storage: persists state
- Memory & history → SQLite storage: indexes persisted data
- Project instance → SQLite storage: isolates state
- Skills & plugins → Prompt construction: extends instructions
- Browser client → Embedded HTTP server: consumes API
- Desktop host → Embedded HTTP server: hosts/connects
- JavaScript SDK → Embedded HTTP server: calls API
- Cloudflare control plane → Provider adapters: proxies hosted models