A monorepo of TypeScript packages (packages/) and Rust crates (crates/). This file is a map; to find a specific symbol or file, search the code rather than this document.
crates/
mc-core/ cache-stability transform and classification logic
mc-store/ the module's durable SQLite store (schema, migrations, CAS transitions)
mc-tokenizer/ token estimator
mc-module/ the subc module (ck-mc): transform, historian, tool facades
packages/
plugin/ OpenCode plugin and the shared TypeScript core (@cortexkit/opencode-magic-context)
pi-plugin/ Pi and OMP plugin (@cortexkit/pi-magic-context)
cli/ setup, doctor and migration CLI (@cortexkit/magic-context)
dashboard/ Tauri desktop dashboard
docs/ documentation site (docs.cortexkit.io/magic-context), deployed by hand
e2e-tests/ end-to-end suites against real OpenCode 1, OpenCode 2, Pi, OMP and Rust stacks
retina-local-fs/ local file and git checks for smart-note conditions
scripts/ release, version sync, diagnostics (cache-bust analysis, context dumps)
docs/ design references and audit evidence (docs/private is gitignored)
index.ts: entry point. Keep it free of named exports; OpenCode's legacy loader calls every exported function.plugin/: OpenCode 1 adapters (hooks, tool registry, RPC handlers, dream timer).v2/: OpenCode 2 adapters (context and compaction hooks, store reader, hidden completions, fold ownership, TUI seam). Built separately todist/v2/server.js.hooks/magic-context/: the transform and everything that runs inside a pass.transform.tsorchestrates;transform-postprocess-phase.tsholds the mutation gates;inject-compartments.tsrendersm[0]/m[1].features/magic-context/: services, grouped by area: storage and migrations,dreamer/,memory/,mural/,smart-notes/,user-memory/,git-commits/, search and indexes.tools/: one directory per agent tool.config/: schema (schema/magic-context.ts), loader, profiles, project trust boundary.shared/: small utilities used by several subsystems, including the logger and the SQLite backend selector.tui/: OpenCode sidebar and dialogs, shipped as source through the./tuiexport.agents/: hidden agent names and prompt helpers.
packages/pi-plugin/src: the Pi context handler (context-handler.ts), Pi-specific commands, dreamer and subagent runners, Pi pressure and LKG handling. Parity with OpenCode is tracked inPARITY.md.packages/cli/src:commands/(setup, doctor, migrate) andadapters/per host.packages/dashboard:src/(Solid frontend) andsrc-tauri/src/(Rust backend: database readers, commands, log parser).crates/mc-module/src:lib.rsroutes requests;transform.rs,historian.rs,injection.rs,boundary.rsmirror the TypeScript runtime.
- Transform behaviour:
src/hooks/magic-context/, wired throughhook.ts. Mirror it inpackages/pi-plugin/src/and, if the Rust module runs it, incrates/mc-module/src/. - A service:
src/features/magic-context/<area>/. - An agent tool:
src/tools/<name>/, registered insrc/plugin/tool-registry.ts, with the Pi and Rust facades. - A slash command: defined in
src/features/builtin-commands/commands.ts, handled insrc/hooks/magic-context/command-handler.ts. - An RPC endpoint: handler in
src/plugin/rpc-handlers.ts, types insrc/shared/rpc-types.ts, consumed fromsrc/tui/data/. - A migration: a new entry in
migrations.ts,LATEST_SUPPORTED_VERSIONbumped instorage-db.ts, the fresh schema andensureColumn()updated, amigrations-v<N>.test.ts, and session-scoped tables added toSESSION_SCOPED_TABLES. - A hidden agent: its name in
src/agents/, its prompt next to the owning feature, registration insrc/index.ts. - A CLI command:
packages/cli/src/commands/, wired frompackages/cli/src/index.ts. - Shared utilities:
src/shared/, only when at least two subsystems use them.
- Files are kebab-case;
index.tsonly for entry points and barrels. - Tests sit next to the code as
*.test.ts; migration tests aremigrations-v<N>.test.ts; end-to-end scenarios go inpackages/e2e-tests/tests/and are registered inmode-manifest.json. - Tests never touch the live database: test preloads point the data and config directories at temporary paths.