The runtime is a TypeScript monorepo with four functional packages. A separate Next.js application provides this landing page and guide. The core never prints; consumers choose how to render its async event stream.
Technology stack
| Layer | Technologies | Responsibility |
|---|---|---|
| Workspace | pnpm, Turborepo | Dependencies and task graph |
| Language | TypeScript, ESM | Typed contracts and modules |
| Model I/O | Fetch, SSE, provider adapters | Translate vendor protocols |
| Agent runtime | Async generators, AbortSignal | Stream work and cancel it |
| Tools | Zod, MCP SDK, Node APIs | Validate and execute capabilities |
| Context | js-tiktoken, model metadata | Estimate budgets and compact history |
| Terminal | pi-tui | Differential rendering and keyboard input |
| CLI build | tsup; optional Bun | Node bundle and native executable |
| Verification | Vitest, headless xterm, eval fixtures | Protocol, runtime, and screen regressions |
| Website | Next.js App Router, React, MDX | Static guides and interactive examples |
| Documentation | Shiki, Mermaid, Playwright | Code rendering, diagrams, browser checks |
Exact versions live in package manifests and pnpm-lock.yaml. The CLI requires Node 24+. The website currently uses Next.js 16 and React 19; the terminal is not a React application.
Package boundaries
View Mermaid source (.mmd)
flowchart TD
U[Developer] --> CLI[packages/cli]
CLI --> CORE[packages/core]
CLI --> TOOLS[packages/tools]
CLI --> AI[packages/ai]
CORE --> TOOLS
CORE --> AI
TOOLS --> AI
AI --> MODEL[Model providers]
TOOLS --> LOCAL[Local files and shell]
TOOLS --> MCP[MCP services]
CORE --> JOURNAL[Session journal]
WEB[apps/web] -. documents .-> CLI
WEB -. documents .-> CORE
packages/ai owns provider contracts and credentials. It knows nothing about terminal layout. packages/tools defines capabilities and enforcement. packages/core owns the conversation and execution loop. packages/cli composes the runtime and supplies interactive, print, JSON, and RPC consumers.
apps/web documents those packages but does not import or run the agent in visitors' browsers. It uses a generated source index to explain the checkout.
How the system is assembled
cli.tsparses startup options and selects the consumer.session.tsbuilds providers, tools, permission control, extensions, journal, and workers.createStateestablishes the conversation state and limits.runaccepts a prompt and yields runtime events.- A consumer renders events without changing provider protocol code.
- Journal and UI sidecars persist the durable parts independently.
This is an implementation walkthrough, not a claim about the historical order of commits.
Shared contracts
packages/ai/src/types.ts defines messages, tool specs, usage, blocks, and provider events. An assistant message may contain text, signed thinking, and tool calls. Tool results reference call IDs. Preserving that relationship matters when replaying context to strict providers.
packages/core/src/types.ts adds runtime state and lifecycle events. packages/tools/src/types.ts describes executable tools and their effects. These interfaces are the seams for adding another provider, tool, or consumer.
Cancellation and failures
Long operations receive an AbortSignal. Cancellation propagates to model requests, tool execution, and worker lifetimes. Errors retain useful provider or tool context. Retries are bounded and should not replay a partially emitted answer as if it were a new one.
Permission rules, budgets, repeated-call guards, and timeouts constrain work. They are complementary application controls, not a substitute for operating-system isolation.
Where to read next
The decision guide compares alternative languages, terminal libraries, persistence, and web stacks. Infrastructure explains hosting and isolation choices. Performance separates implemented optimizations, measurements, and open questions.
Trace the agent loop, inspect the terminal UI, or search every source file. Package and folder READMEs provide local maps when browsing the checkout.