Skip to content

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 ​

PackageDirectoryResponsibility
@m31a/clipackages/cliInk/React terminal UI, yargs CLI, slash commands, ACP, hub, schedules, connectors, extensions.
@m31a/corepackages/coreAgent loop, NIM client, prompt construction, tools, policies, hooks, skills, services, sandbox helpers.
@m31a/genaipackages/genaiStructural request and response types bridged to NVIDIA NIM.
@m31a/devtoolspackages/devtoolsIntegrated developer tools inspector.
@m31a/test-utilspackages/test-utilsShared test utilities and harness.
m31a-ide-companionpackages/vscode-ide-companionVS Code companion extension.

ESLint enforces import boundaries between packages; use package imports rather than relative paths across workspaces.

Runtime flow ​

  1. Entry point — packages/cli/src/m31a.tsx (built to dist/index.js; published as bundle/m31a.js).
  2. Argument parsing — parseArguments() in config/config.ts registers subcommands and validates flag combinations.
  3. Configuration — settings are loaded from user, workspace, system, and admin scopes; trust and policy state are resolved.
  4. Runtime construction — Config in @m31a/core wires up models, tools, hooks, MCP clients, skills, and services.
  5. 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.
  6. Tool execution — tool calls pass through policy and approval checks, hooks, and optional sandboxing before execution.
  7. Persistence — session records, checkpoints, and a SQLite session search index are written locally.

Key subsystems ​

  • NIM client — packages/core/src/core/nvidiaNimContentGenerator.ts; uses NVIDIA_API_KEY and 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.ts and packages/core/src/mcp/.
  • Hooks — packages/core/src/hooks/.
  • Skills — packages/core/src/skills/.
  • ACP — packages/cli/src/acp/.
  • Sandbox — packages/cli/src/utils/sandbox.ts and macOS profile files.

Build and bundle pipeline ​

CommandEffect
npm run buildCompile all workspaces via scripts/build.js.
npm run bundleGenerate build info, bundle with esbuild, copy assets.
npm run build:allBuild packages and the sandbox image.
npm run build:binaryBuild a SEA binary via scripts/build_binary.js.
npm run generateGenerate git commit information.
npm run cleanRemove generated artifacts.
npm run preflightClean, 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 ​

PathPurpose
~/.m31a/settings.jsonUser settings.
~/.m31a/keybindings.jsonUser keybinding overrides.
<project>/.m31a/Workspace settings, commands, skills, custom sandbox files.
M31A.mdWorkspace context instructions.
bundle/Bundled CLI and example assets.
schemas/settings.schema.jsonGenerated 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/core runtime.
  • 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 ​

SeamContractGuide
ToolsTyped declarations in @m31a/coreTool reference
MCPExternal servers exposing tools, resources, promptsMCP
SkillsSKILL.md with front matterSkills
HooksJSON-in/JSON-out commands on lifecycle eventsHooks
ExtensionsBundles of commands, skills, MCP, policies, themesExtensions
ACPJSON-RPC over stdioACP

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.

Built with VitePress. Powered by NVIDIA NIM.