Repository navigation
Architecture
Settled for v0.1. This page explains why the codebase is shaped the way it is. The build spec says what to build; this says how the pieces fit and which seams are load-bearing.
Four forces dictate every structural rule:
- Deterministic testability. The agent loop, approval gating, cancellation, and the max-turn guard must be testable offline in milliseconds, without a live model.
-
Cancellation everywhere.
Escmust return control in under a second — including mid-tool, mid-HTTP-stream, and mid-approval. - No silent side effects. Every write and every command execution passes through a policy decision the user can see. The call graph enforces this; bypassing it must be awkward by design.
-
Durability across a crash. The session record must survive
kill -9with at most one torn line, and a resumed session must reconstruct exactly what the user and the model saw.
cmd/kirsch/main.go entry point: flags, subcommands, builds the App
internal/app coordinator: wiring, adapters, root context
internal/tui Bubble Tea program: renders state, emits intents
internal/agent turn state machine, prompts, budget, compaction
internal/provider Provider interface + anthropic adapter + Fake
internal/tool tool registry + implementations + envelope
internal/policy allowlist, session grants, approval decisions
internal/workspace root detection, containment, denylist, ignore, detect
internal/session JSONL event store: append, load, resume, repair
internal/config global + project config, env-only secrets
internal/telemetry structured debug log; token/cost tracking
internal/doctor kirsch doctor: health checks and exit status
plan/ build instructions and spec (not shipped in releases)
doc/ end-user documentation
testdata/ fixture repositories for tests
scripts/ smoke test and release tooling
internal/app owns the root context and wires everything together. internal/agent talks to its leaf packages (provider, tool, policy, session, workspace) through consumer-defined interfaces only — it never imports concrete implementations directly. This is what makes turn-loop tests deterministic: swap the real anthropic adapter for Fake and the whole loop runs offline.
internal/tui communicates with internal/app through typed messages (program.Send), not direct calls. The TUI renders state; it does not own state.
Packages at the same level do not import each other. No package is created before the milestone that needs it.
Sessions are append-only JSONL files on local disk. Each event (message, tool call, tool result, approval, compaction) is one line. The file survives a kill -9 with at most one torn line at the tail; the loader repairs it on resume. No server, no telemetry, no cloud storage.
One wire format for v0.1: the Anthropic Messages format. The two built-in providers (opencode and anthropic) both use it. Custom endpoints can be defined in configuration and must speak the same format.
macOS and Linux, amd64 and arm64. No Windows: Kirsch stops commands by stopping their Unix process group, which Windows does not have.