Package Overview
Main Components
CLI and Modes
TheChatCLI struct in cli/cli.go is the central point. The Start() method initiates interactive mode using go-prompt v0.2.6.
| Mode | File | Description |
|---|---|---|
| Interactive | cli/cli.go | Interactive prompt with auto-completion |
| Agent | cli/agent_mode.go | Task planning and execution |
| Coder | cli/cli.go + cli/agent_mode.go | Engineering loop with tool calls |
| One-shot | cli/cli.go (flag -p) | Single execution without TUI |
panic/recover mechanism to exit the go-prompt loop.
ChatCLI uses a unified history (cli.history) shared across all modes. When switching modes, the full context is preserved. The /compact and /rewind commands operate directly on this single history.
Provider Registry
Each LLM provider auto-registers viainit() in the llm/registry package. This eliminates switch/case blocks and makes adding new providers easy — just create the package and implement the LLMClient interface.
Message Bus
Thecli/bus package implements a typed message bus with:
- Pub/sub with channel and type filters
- Request-reply with correlation IDs
- Atomic throughput metrics
Multi-Agent
The orchestration system incli/agent/workers manages 12 specialist agents running in parallel goroutines with a configurable semaphore. Each worker has:
- Isolated mini ReAct loop (observe -> reason -> act)
- Own skills (accelerator and descriptive scripts)
- File locks (mutex per-filepath)
- Configurable timeout and max turns
Technologies
| Category | Library |
|---|---|
| TUI | go-prompt v0.2.6 |
| Markdown | Glamour (Charmbracelet) |
| Colors | Lipgloss (Charmbracelet) |
| Logger | Zap (Uber) |
| Log rotation | Lumberjack |
| Env files | Godotenv |
| i18n | golang.org/x/text |
| gRPC | google.golang.org/grpc |
| Kubernetes | k8s.io/client-go |
| Operator | controller-runtime (Kubebuilder) |
| Protobuf | google.golang.org/protobuf |
Design Patterns
- Auto-registration via
init()— Providers register themselves automatically - Interface-driven —
LLMClientandToolAwareClientfor polymorphism - Fallback chain — Intelligent error classification + exponential cooldown
- Stateful parser — XML parsing with escaped attributes (more robust than regex)
- embed.FS — i18n files embedded in the binary (always uses
/, neverfilepath.Join) - Panic/recover — Mode switching in go-prompt without restarting the process
- Unified history — A single message array shared across chat, agent, and coder modes
- Checkpoint/rewind — Deep copy of history before each LLM call, with selective restore
- 3-level compaction — Near-lossless trimming, structured summarization, emergency truncation
- Workspace context injection — Bootstrap + memory automatically injected into every system prompt
- Unified system prompt with caching — Attached contexts (
/context attach) now flow through the system prompt viaSystemPartswithCacheControlhints in the Message model, enabling provider-level prompt caching (Anthropiccache_control: ephemeral, OpenAI automatic caching, Google context caching). Previously, attached contexts were injected as user messages, which prevented caching across turns