Files
2026-07-13 12:22:59 +08:00

12 KiB

Developing @oh-my-pi/pi-coding-agent

This package is the omp CLI. This file is a developer's map: where things live in src/, how to run the local loops, and — for each subsystem — which document in the repo docs/ tree is the authoritative reference.

The long architecture walkthrough that used to live here drifted out of date faster than anyone re-read it. The docs/ tree is kept current (and indexed for the in-agent docs:// / /docs surface), so this file links there instead of duplicating prose that goes stale.

Local development

Run from packages/coding-agent/ (or add --cwd=packages/coding-agent):

Task Command
Typecheck + lint (the gate) bun run check
Types only bun run check:types
Lint only bun run lint
Tests bun run test
Autofix: lint + format prompts + docs index bun run fix
Reformat prompt .md assets bun run format-prompts
Regenerate the docs:// index bun run gen:docs
Build the dist/omp binary bun run build

Never invoke tsc/npx tsc directly — bun run check is the typecheck gate. After changing the React tool renderers under collab-web/src/tool-render/, rebuild them with bun run gen:tool-views.

Boot flow

process argv
   │
   ▼
src/cli.ts (runCli)            ── worker-host dispatch + Bun version guard;
   │  default subcommand: launch    argv normalization
   ▼
src/commands/* (+ src/cli/)   ── per-command adapters
   │
   ▼
src/main.ts (runRootCommand)  ── theme / settings / model registry / session opts
   │
   ▼
createAgentSession(...)        ── src/sdk.ts → AgentSession
   │
   ├── InteractiveMode   (src/modes/, TUI event loop)
   ├── runPrintMode      (one-shot text/json)
   └── runRpcMode        (JSONL stdin/stdout server)

cli.ts doubles as the worker host: it declares itself via declareWorkerHostEntry() and dispatches the hidden __omp_worker_* argv selectors before loading the command registry (see AGENTS.mdWorker scripts).

Source layout (src/)

Top-level entry modules: cli.ts, main.ts, sdk.ts, index.ts (SDK barrel), config.ts, system-prompt.ts, thinking.ts, workspace-tree.ts, cli-commands.ts, telemetry-export.ts.

Directory Responsibility Reference
cli/, commands/, commit/, export/ Command-line adapters and concrete subcommands
modes/ Interactive TUI, print, and RPC runtimes rpc.md, sdk.md
session/ AgentSession, JSONL session tree, storage, history session.md, session-tree-plan.md
config/, registry/, secrets/ Settings, model/provider registry, secret obfuscation settings.md, config-usage.md, models.md, secrets.md
tools/ Built-in tool implementations + render/meta helpers custom-tools.md, tools/
exec/, eval/, ssh/, dap/, debug/ Execution backends (shell, py/js kernels, ssh, debugger) bash-tool-runtime.md, python-repl.md
lsp/ Language-server client/runtime lsp-config.md, tools/lsp.md
task/, swarm/, irc/, goals/, plan-mode/ Subagent delegation, parallelism, inter-agent IRC, plan mode task-agent-discovery.md, tools/task.md
web/, exa/ Fetch, browser automation, search providers, scrapers tools/web_search.md, tools/browser.md
mcp/ MCP transport / manager / loader / tool bridge mcp-config.md, mcp-runtime-lifecycle.md
extensibility/, slash-commands/ Extensions, hooks, custom tools/commands, skills, plugins extensions.md, hooks.md, skills.md
capability/, discovery/, tool-discovery/ Capability registry + provider discovery modules extension-loading.md, context-files.md
advisor/, autolearn/, autoresearch/ Advisor/watchdog, managed skills, background research advisor-watchdog.md
memories/, memory-backend/, mnemopi/, hindsight/ Memory subsystems and backends memory.md, mnemosyne-memory-backend.md
internal-urls/ Router + handlers (agent://, docs://, rule://, …) tree.md
tui/, collab/ Low-level TUI primitives, live session sharing tui.md, collab.md
tts/, stt/ Text-to-speech / speech-to-text
tiny/, auto-thinking/ Embedded tiny-model experiments, auto thinking level local-models.md
async/, lib/, utils/, prompts/, edit/ Shared plumbing, prompt assets, patch/diff engine tools/edit.md

Subsystem reference

Sessions, persistence, and turn lifecycle

Configuration, models, providers, auth

Tools framework and built-in tools

Execution backends

Task delegation and subagents

Web I/O and retrieval

MCP

Memory

Discovery, context, and rules

TUI and theming

Natives (crates/pi-natives, packages/natives)

Build, release, and porting

Extending omp

To add… Start here
A built-in tool src/tools/index.ts (BUILTIN_TOOLS / HIDDEN_TOOLS) + custom-tools.md
An extension (TS/JS module) extensions.md, extension-loading.md, skills/authoring-extensions.md
A hook src/extensibility/hooks/types.ts + hooks.md, skills/authoring-hooks.md
A slash command slash-command-internals.md
An RPC command src/modes/rpc/rpc-types.ts + rpc.md
A skill skills.md
A marketplace plugin marketplace.md, plugin-manager-installer-plumbing.md, skills/authoring-marketplaces.md, gemini-manifest-extensions.md
A custom MCP tool/server mcp-server-tool-authoring.md, custom-tools.md
A provider adding-a-provider.md
Programmatic/SDK use sdk.md

See also AGENTS.md at the repo root for repo-wide conventions (Bun-over-Node, logging, TUI sanitization, generated files, changelog, releasing).