$ show earendil-works/pi
This is a monorepo for 'pi', an AI coding assistant platform. The repository contains multiple packages including a coding agent with a terminal UI (TUI), multi-provider AI integration (OpenAI, Anthropic, Google, Bedrock, Mistral, xAI, and more), a durable execution framework for conversation persistence, a protocol layer with strict CBOR encoding, and telemetry infrastructure. The coding agent supports interactive mode with session management, tool orchestration, subagents, and MCP (Model Context Protocol) integration. The architecture is a TypeScript monorepo using npm workspaces with packages for AI providers, coding agent, durable execution, protocol, telemetry, and TUI components. The AI package provides a unified interface across multiple providers with OAuth flows, model catalogs, and streaming support. The coding agent implements a TUI with themes, keybindings, and interactive components. The durable package provides event-sourced storage with SQLite and JSONL backends, session management, and compaction. The repository also includes evaluation infrastructure (Docker-based evals), benchmarks for storage and delta traversal, and telemetry for usage tracking. The codebase demonstrates strong engineering practices with clean abstractions, reusable components, and comprehensive test coverage, though some areas (durable harness, experimental services) are still evolving.
The LLM identified 6 files worth highlighting for reuse:
Strict RFC 8949 CBOR encoder with configurable depth/byte/container limits. Rejects tags, indefinite items, and non-string map keys. Demonstrates a safe, defensive serialization pattern with explicit validation and bounded resource usage.
InMemoryTelemetryContext provides a reference telemetry implementation with span recording, attribute merging, and automatic error status. Demonstrates a clean span lifecycle pattern with parent/child binding and NOOP adapter for production fallback.
Serial operation queue for SQLite transactions with prepared statement reuse. Synchronizes async transactions to prevent race conditions in durable storage. Demonstrates a robust pattern for single-writer database access in concurrent TypeScript.
OAuth PKCE flow with loopback server and manual input fallback, double-checked locking for token refresh. Demonstrates a robust browser-based sign-in pattern with fallback for headless environments and concurrent refresh protection.
Provider-specific streaming implementation for OpenAI-compatible completions. Demonstrates the adapter pattern for normalizing provider-specific streaming formats into a unified interface, with error body normalization and stream body handling.
Session manager for coding agent conversations with branching, compaction, and label support. Demonstrates a robust session lifecycle pattern with durable state and JSONL-based persistence.