M31A is a TypeScript monorepo using npm workspaces. It builds to JavaScript, bundles into a single CLI entry point, and can also be packaged as a single-executable application (SEA).
Workspace packages
| Package | Directory | Responsibility |
|---|---|---|
@m31a/cli | packages/cli | Ink/React terminal UI, yargs CLI, slash commands, ACP, hub, schedules, connectors, extensions. |
@m31a/core | packages/core | Agent loop, NIM client, prompt construction, tools, policies, hooks, skills, services, sandbox helpers. |
@m31a/genai | packages/genai | Structural request and response types bridged to NVIDIA NIM. |
@m31a/devtools | packages/devtools | Integrated developer tools inspector. |
@m31a/test-utils | packages/test-utils | Shared test utilities and harness. |
m31a-ide-companion | packages/vscode-ide-companion | VS Code companion extension. |
ESLint enforces import boundaries between packages; use package imports rather than relative paths across workspaces.
Runtime flow
- Entry point —
packages/cli/src/m31a.tsx(built todist/index.js; published asbundle/m31a.js). - Argument parsing —
parseArguments()inconfig/config.tsregisters subcommands and validates flag combinations. - Configuration — settings are loaded from user, workspace, system, and admin scopes; trust and policy state are resolved.
- Runtime construction —
Configin@m31a/corewires up models, tools, hooks, MCP clients, skills, and services. - Agent loop — prompts are constructed with workspace context (
M31A.md, include directories), sent to the OpenAI-compatible NVIDIA NIM endpoint, and streamed back into the Ink UI or headless output. - Tool execution — tool calls pass through policy and approval checks, hooks, and optional sandboxing before execution.
- Persistence — session records, checkpoints, and a SQLite session search index are written locally.
Key subsystems
- NIM client —
packages/core/src/core/nvidiaNimContentGenerator.ts; usesNVIDIA_API_KEYand an OpenAI-compatible protocol mapping. - Tool system —
packages/core/src/tools/; see Built-in tools. - Policy engine —
packages/core/src/policy/; see Approval modes. - Context compression —
packages/core/src/context/; see Sessions and context. - MCP —
packages/core/src/tools/mcp-client-manager.tsandpackages/core/src/mcp/. - Hooks —
packages/core/src/hooks/. - Skills —
packages/core/src/skills/. - ACP —
packages/cli/src/acp/. - Sandbox —
packages/cli/src/utils/sandbox.tsand macOS profile files.
Build and bundle pipeline
| Command | Effect |
|---|---|
npm run build | Compile all workspaces via scripts/build.js. |
npm run bundle | Generate build info, bundle with esbuild, copy assets. |
npm run build:all | Build packages and the sandbox image. |
npm run build:binary | Build a SEA binary via scripts/build_binary.js. |
npm run generate | Generate git commit information. |
npm run clean | Remove generated artifacts. |
npm run preflight | Clean, install, format, build, lint, typecheck, test. |
esbuild.config.js produces bundle/m31a.js. scripts/copy_bundle_assets.js copies bundled assets; when a root docs/ directory is present it is copied to bundle/docs/ and packages/core/dist/docs/.
On-disk layout
| Path | Purpose |
|---|---|
~/.m31a/settings.json | User settings. |
~/.m31a/keybindings.json | User keybinding overrides. |
<project>/.m31a/ | Workspace settings, commands, skills, custom sandbox files. |
M31A.md | Workspace context instructions. |
bundle/ | Bundled CLI and example assets. |
schemas/settings.schema.json | Generated settings JSON Schema. |
Design principles
- Terminal first. The UI is React rendered through Ink; every capability is also reachable without a mouse.
- One core, several front ends. The interactive TUI, headless mode, and ACP all drive the same
@m31a/coreruntime. - Explicit authorization. Model output never executes directly; it proposes tool calls that pass confirmation, policy, hooks, and sandbox boundaries.
- Scoped extensibility. MCP, skills, hooks, extensions, and commands attach through narrow interfaces rather than forking the agent loop.
- Local-first state. Settings, session records, and credentials stay under the user's configuration directory by default.
Extension seams
| Seam | Contract | Guide |
|---|---|---|
| Tools | Typed declarations in @m31a/core | Tool reference |
| MCP | External servers exposing tools, resources, prompts | MCP |
| Skills | SKILL.md with front matter | Skills |
| Hooks | JSON-in/JSON-out commands on lifecycle events | Hooks |
| Extensions | Bundles of commands, skills, MCP, policies, themes | Extensions |
| ACP | JSON-RPC over stdio | ACP |
Release artifacts
The release workflow publishes npm packages, source and bundle tarballs, cross-platform SEA binaries, and a sandbox container image. See Installation and Releases.
Next steps
See Contributing for development workflows.