Architecture
MomongaCode is an npm workspace of packages under packages/. The momonga command is a client; the work is done by background processes.
- Client.
packages/cli(command line, terminal UI, ACP server). It starts and talks to the daemon. - Supervisor.
packages/supervisorruns the daemon: it starts, restarts, and stops two child processes, the gateway and the runtime. Each start of the daemon is a generation with its own supervisor; a newer generation takes over new work while an older one finishes what it runs and ends by itself. A settings change applies in place: each child reads the settings per operation, and no child is restarted for it. - Runtime.
packages/runtimeruns sessions, runs, and the model and tool loop. It builds each request withpackages/context, appliespackages/policyto tool calls, executes tools frompackages/toolsinsidepackages/sandbox, and records everything inpackages/store. - Gateway.
packages/gatewayis the one place that talks to models. It has adapters for chat-completions, Open Responses, Anthropic, and Ollama, plus routing, retry, admission, and probing. Apple'sfmis a managed server: a server program that MomongaCode starts itself and reaches through the chat-completions adapter. - Store.
packages/storeholds runs, events, approvals, memories, rules, and jobs in databases under~/.momonga/state. - Context.
packages/contextbuilds the context under a token budget, compacts history, and formats tool output. - Memory.
packages/memoryholds the logic for memory validity, recall order, deduplication, forgetting, and the memory budget share. - Tools.
packages/toolsdefines the built-in tools and executes tool calls.packages/skillsandpackages/agentsload skills and custom agents.packages/mcpconnects MCP servers. - Policy.
packages/policydecides whether a tool call is allowed, from the permission rules, the parsed command, and the paths it touches. - Sandbox.
packages/sandboxruns commands under Seatbelt or bubblewrap. - Configuration.
packages/configdefines the settings schema and merges the user, project, and local layers. - Shared.
packages/protocol(types, constants, wire formats),packages/foundation(paths, locks, platform code, credentials),packages/observability(traces, cost, OTLP),packages/reliability(reliability reports). - Verification and evaluation.
packages/verify(rule verification with Z3),packages/eval(datasets, reports, comparison),packages/testkit(fakes for tests).
The formal models of the state machines are TLA+ specifications in specs/tla/, checked with TLC in the test suite.