Skip to content

development cookbook

github-actions[bot] edited this page Oct 22, 2026 · 53 revisions

Cookbook

Step-by-step recipes for common changes. Each lists files, order, tests, and docs. Testing detail: Testing. Package context: architecture portal.

Add a slash command

  1. Implement handler in internal/agent/commands/ (new file or existing).
  2. Register in builtin_slash.go (Registry entry with names + help text).
  3. Ensure help.go lists it (sorted catalogue for /help).
  4. Wire callbacks on commands.Deps if the command needs runtime state — set in slash_deps.go.
  5. Optional: first-arg completion in replcomplete/slash_args.go.
  6. Test: test/slash_dispatch_test.go using testDeps.
  7. Docs: Usage and commands if user-facing.

Do not parse slash lines outside slash/dispatch.go.

Add a native tool (plan or build)

  1. Implement tool in internal/agent/tools/ (handler func).
  2. Register OpenAI schema in params.go for the right Mode(s).
  3. Route execution in exec.go (mode guards, switch on tool name).
  4. If the tool needs env/context, extend toolenv/env.go, wire fields in runtime/exec.go toolEnv(), read from handler via tools.Env alias (tools/env.go).
  5. Optional: plan/build dump strings in dump_*.go if the tool should appear in system prompt listings.
  6. Test: new or extended file in test/ with t.TempDir() for filesystem tools.
  7. Docs: Native tools, Plan vs build if mode-specific.

MCP tools are separate — configure mcp.json, not this path (MCP integration).

Change the agent turn loop or legacy XML

  1. Stream loop: internal/agent/runtime/turns.go.
  2. Native vs legacy resolution: legacy.go.
  3. Terminal tool lines / legacy stream writer: tool_print.go.
  4. XML parse/stream: internal/tooling/.
  5. Test: legacy_runtime_test.go, legacy_tools_test.go.
  6. Docs: Agent turn pipeline.

Preserve: fail-closed stream integrity (llm/stream/completion.go), SIGINT cancel via WithCancelCause.

Modify REPL input or tab completion

  1. Keys/buffer: repl/editor/read.go.
  2. Redraw: repl/editor/refresh.go.
  3. Loop dispatch: repl/loop.go.
  4. Completion: replcomplete/ + wiring replcomplete_runtime.go.
  5. Add test exports in editor/editorhistory.go if needed.
  6. Test: repl_editor_test.go, repl_complete_*_test.go.
  7. Docs: Runtime — REPL input.

Add a web search engine

  1. Implement search.Engine in new file under internal/search/.
  2. Register in web_search.go and config keys.
  3. Test: focused test with HTTP stub if the engine calls the network.
  4. Docs: Configuration — web search, Supporting packages.

Change deep research

  1. Job lifecycle and record snapshots: internal/research/job.go and types.go.
  2. Engine rounds, extraction, and report rendering: internal/research/engine.go and html/.
  3. Runtime/native/slash surfaces: researchmanager.go, deep_research.go, and research.go.
  4. Keep status reads independent from background mutations; test the runtime and web adapters through test/web_surfaces_test.go and run the Linux -race command before committing.
  5. Docs: Deep research, Usage — /research, Configuration, and Data layout.

Add or change an LLM provider path

  1. Provider config: internal/config/, wizard commands/connect/.
  2. Backend factory: internal/llm/factory.go.
  3. Protocol adapter: openai_backend.go or anthropic_*.go.
  4. OAuth (ChatGPT Sub): internal/auth/openai/codex/, providersetup/.
  5. Test: httptest — see api_resilience_*_test.go, provider_auth_test.go.
  6. Docs: Configuration, LLM layer.

Cursor sidecar / bridge change

  1. Go process/install: internal/integrations/cursor/.
  2. Node proxy: integrations/cursor/src/ — especially legacy.ts, chat.ts.
  3. Runtime hooks: cursor_sidecar.go, cursor_native_display.go.
  4. Rebuild embed: go run scripts/cursor_bundler.go build && bundle (or make build).
  5. Test: Go stream_cursor_tool_test.go; TS make cursor-proxy-test.
  6. Docs: Cursor integration — update tool bridge table if aliases change.

Docs change checklist

  1. Update the architecture or user article for the behavior change.
  2. Add or link tests in the article if non-obvious.
  3. Run make check-docs (markdown links, anchors, cited paths, package index).

Design rationale stays in architecture articles; there is no separate ADR folder.

See also

Clone this wiki locally