This is a translated and structured digest of a long-form architecture review of Pi (@earendil-works/pi-*, ~v0.80.x), posted on zhichai.net.
Key points
- Positioning: Pi is an *agent harness* — a minimal terminal coding agent whose philosophy is "keep the core tiny; let extensions shape the workflow." It explicitly rejects MCP, sub-agents, permission popups, plan mode, built-in todos, and background bash in the core, offering extensions/skills/packages as alternatives.
- Four delivery modes: Interactive TUI, Print/JSON (
-p,--mode json), RPC (--mode rpc), and SDK (createAgentSession()). All share the sameAgentSessionsemantics — modes are I/O layers, not business layers. - Layered monorepo with strict downward dependencies:
pi-tui— terminal UI framework (component tree, differential rendering, CSI 2026 synchronized output, overlays, bracketed paste, image protocols)pi-ai— multi-vendor LLM layer: API dialects (Anthropic Messages, OpenAI Completions/Responses, Google Generative AI, Bedrock Converse), providers, auth (env → credential store → OAuth refresh), unified stream events, faux provider for testing. Only tool-calling-capable models are supported; errors are encoded into events/final messages rather than thrown.pi-agent-core— generic agent loop, tool execution (parallel by default, with preflight hooksbeforeToolCall/afterToolCall), event model (agent_start → turn_start → message/tool events → turn_end → agent_end), and an evolvingAgentHarnessdistinguishing harness config, turn snapshots, session, and pending writes.pi-coding-agent— product assembly: CLI entry, tools (read/write/edit/bashplus discovery toolsgrep/find/ls), extensions, skills, compaction, resource loader, model runtime.pi-orchestrator— experimental multi-process orchestration, explicitly unstable.- Sessions are append-only JSONL trees at
~/.pi/agent/sessions/--<cwd>--/<timestamp>_<uuid>.jsonl, withid/parentIdlinks (v1 linear → v2 tree → v3 unifiedcustomentries). Entry types includemessage,compaction,branch_summary,model_change,custom, andlabel. - Compaction triggers when
contextTokens > contextWindow - reserveTokens(default 16k reserve); branch summarization preserves context when navigating via/tree. Compaction is a session-layer strategy (auditable, works across model handoffs), not hidden provider truncation. - Sessions support
/tree,/fork,/clone, HTML export, and sharing to HF datasets. - Resources: Extensions (TypeScript modules: tools, commands, hooks, custom TUI, session entries), Skills (Markdown + frontmatter, loaded by the model via
read), prompt templates, themes, packages (npm/git), and context files (AGENTS.md/CLAUDE.md, discovered up the directory tree). - Extension API:
pi.on(event, handler),registerTool(TypeBox schema),registerCommand,ctx.ui(confirm/select/input/custom components),appendEntry. - Extensions run with full user privileges; trust boundary is load-time (project trust), not a sandbox interpreter.
- Wide provider matrix: official APIs, subscription OAuth (Claude/Codex/Copilot), gateways (OpenRouter, Vercel AI Gateway), regional variants, local servers (llama.cpp, Ollama-compatible). Context is serializable for cross-provider handoff within one session.
- Security layers: OS process permissions, project trust, supply-chain hardening (pinned deps, npm-shrinkwrap,
--ignore-scripts), optional isolation (Gondolin micro-VM, Docker, OpenShell). - Erasable TypeScript only (Node strip-only), no inline dynamic imports,
npm run check(biome + pinned deps + shrinkwrap + tsgo + browser smoke), faux-provider tests, and Git discipline for multi-agent parallel development. - Lockstep versioning across packages; minor = breaking change.
Session system
Extension system (first-class)
Models, auth, security
Engineering signals
Conclusion
The author summarizes Pi as: (1) a layered harness (pi-ai for protocols, pi-agent-core for the loop, pi-tui for presentation, pi-coding-agent for assembly), (2) a tiny core with first-class extensions replacing feature flags, and (3) sessions as externalized state machines (append-only JSONL trees enabling branching, compaction, and multi-mode replay). Best suited for users who want deep customization or SDK/RPC embedding; not for those expecting an out-of-the-box "everything included" agent.
Source map (from the original post)
| Topic | Path |
|-------|------|
| Philosophy | packages/coding-agent/README.md § Philosophy |
| Session hub | packages/coding-agent/src/core/agent-session.ts |
| Session storage | packages/coding-agent/src/core/session-manager.ts |
| Extensions | packages/coding-agent/src/core/extensions/ |
| Agent loop | packages/agent/src/agent-loop.ts |
| Harness design | packages/agent/docs/agent-harness.md |
| LLM types | packages/ai/src/types.ts |
| TUI core | packages/tui/src/tui.ts |