Architecture
System Design & Core Internals
4-Layer Architecture
Entry Layer
CLI parsing, bootstrap, env initialization
Query Engine
LLM orchestration, streaming, tool loop
Tool & Service Layer
39 tools + 36 service modules
UI Layer
React/Ink terminal UI, 111 components
Bootstrap Flow
1
main.tsx entry
2
Parallel: MDM prefetch + Keychain prefetch
3
Parse CLI args (Commander.js)
4
Load config, OAuth, policy limits
5
Initialize MCP connections
6
Launch React/Ink UI + QueryEngine
Key Files by Size
| File | Size | Purpose |
|---|---|---|
| main.tsx | 4,683 lines | CLI entry + React bootstrap |
| query.ts | 1,729 lines | Query pipeline |
| QueryEngine.ts | 1,295 lines | LLM orchestration |
| Tool.ts | 792 lines | Tool framework base |
| commands.ts | 754 lines | Command registry |