Unipi

Overview

System: Unipi — extension suite for the Pi coding agent
C4 Level: System Context (Level 1)
Document generated: 2026-09-16 06:51:20 (UTC)


1. Project Introduction

1.1 Project Name and Description

Unipi is a TypeScript monorepo containing approximately 25 extension packages, all published under the @pi-unipi/* scope, that plug into the Pi coding agent — a terminal-based AI coding assistant. Unipi is not a standalone application; it is a set of extensions that load into the Pi host process through Pi's ExtensionAPI. Each package registers tools (with TypeBox schemas), slash commands, lifecycle hooks, TUI overlays and footer/widget segments, and the umbrella package @pi-unipi/unipi composes them into a single working assistant at runtime.

AttributeValue
Project nameUnipi
Project typeCLI tool extension suite (plugin system)
Language / platformTypeScript, Node.js (Python bridge for MemPalace)
Deployment form~25 @pi-unipi/* packages loaded in-process by the Pi coding agent
Primary interfaceTerminal UI (TUI) inside Pi; one small HTTP-served kanban UI

1.2 Core Functionality and Business Value

Unipi extends a single terminal AI coding agent into a fuller development platform. Its capabilities cluster around five functional areas:

AreaWhat it deliversRepresentative packages
Agent orchestrationDelegate work to subagents, run background child processes with budgets and tracked state, execute autonomous "Ralph" loopssubagents, background-tasks, ralph
Context & memory managementDeterministic multi-stage context compaction, SQLite session store with recall on resume, durable memory backed by MemPalace, trajectory capturecompactor, memory, trajectory
External capability integrationBridge MCP servers into Pi tools, web search and smart-fetch extraction, image generation/recognition, model fusion with a sidekick runtimemcp, web-api, image, fusion
User interaction & presentationResponsive footer status bar, interactive ask_user prompts and session handoff, keyboard chords with undo/redo, info screen, autocomplete, quick side questions, outbound notificationsfooter, ask-user, input-shortcuts, notify, info-screen, autocomplete, btw
Structured development workflowWorkflow commands with sandboxes, milestone tracking, a kanban board rendered from plan/milestone markdownworkflow, milestone, kanboard

Business value in one sentence: developers get longer autonomous agent sessions (less context-window pressure), parallel and long-running task execution, memory that survives across sessions, and access to external tools and data — all without leaving one CLI.

1.3 Technical Characteristics

  • Plugin-style, event-driven architecture. A thin shared kernel (@pi-unipi/core) supplies constants, an inter-module event bus (MODULE_READY discovery and feature events), sandbox primitives and TUI helpers. Every other package depends on core but remains independently loadable and config-gated.
  • Loose cross-package coupling. Packages communicate primarily through core events and footer segments rather than direct imports; the notable exception is kanboard importing milestone types.
  • Process-oriented delegation. Subagents and MCP servers run as OS child processes; Unipi tails their output, tracks usage, and can terminate whole process trees (including Windows taskkill).
  • File- and SQLite-based persistence with crash-safe atomic writes for task artifacts, session events and compaction statistics.
  • Deterministic compaction pipeline. A six-stage compile() pipeline (normalize → filterNoise → buildSections → formatSummary → merge → ranked brief) produces structured summaries rather than relying solely on model-generated summaries.

2. Target Users

2.1 User Roles

%% litho-mermaid
graph LR
    AgentUser["AI coding agent user - developer running Pi in a terminal"]
    ExtDev["Extension developer - maintains packages in the monorepo"]
    Team["Team using structured workflows"]
    Unipi["Unipi extension suite"]

    AgentUser -->|installs and uses tools, commands, TUI| Unipi
    ExtDev -->|builds packages against core contracts| Unipi
    Team -->|runs workflow, milestone and kanban tooling| Unipi
RoleDescriptionPrimary needs
AI coding agent usersDevelopers who run the Pi coding agent in a terminal and install Unipi extensions.Longer sessions without hitting context limits; parallel and background task execution; persistent memory across sessions; access to external tools and data via MCP.
Extension developersEngineers building or maintaining packages inside the Unipi monorepo.Clear package boundaries and shared core contracts; consistent registration with the Pi extension API; reusable TUI and tooling primitives.
Teams using structured workflowsGroups that adopt the workflow, kanboard and milestone packages to manage disciplined development.Workflow commands and sandboxes; kanban document parsing and a board UI; milestone and trajectory tracking.

2.2 Usage Scenarios

ScenarioActorUnipi behaviour
Delegating a sub-taskAgent user (via the LLM)spawn_helper launches a child Pi process with budgets and policies; result returned through get_helper_result; user notified; footer updated.
Long session nearing context limitAgent userAuto-trigger evaluates the token estimate, runs the compaction pipeline, persists statistics to SQLite; prior context is re-injected on resume and recallable via session_recall.
Using an external MCP toolAgent userMCP server started as a child process; its tools translated and registered as Pi tools; calls proxied over JSON-RPC stdio.
Reading a web pageAgent user (via the LLM)URL validated, fetched with TLS fingerprinting, routed by content type, extracted with fallbacks, cached and returned as formatted text.
Switching model pairingAgent user/unipi:model opens a picker; preset persisted; sidekick runtime started; active pair and savings shown in the footer.
Agent needs a human decisionAgent userask_user renders a TUI prompt (optionally hands off to a new session) and can alert a remote device through notify.
Managing project milestones on a boardTeamWorkflow commands enforce sandboxes; milestones defined via commands/hooks; kanboard parses markdown into a web UI.
Adding a new capabilityExtension developerNew package imports @pi-unipi/core, emits MODULE_READY, registers tools/commands with the Pi ExtensionAPI, optionally contributes a footer segment.

3. System Boundaries

3.1 Scope Statement

The system boundary is the collection of @pi-unipi/* packages that load into the Pi coding agent, plus their on-disk state (task artifacts, session databases, memory stores). Everything the extensions register, render, persist or spawn is in scope. The Pi host itself, external model providers, third-party MCP server implementations and OS notification services are outside the boundary.

3.2 Included Components

DomainPackages / components in scope
Platform Core & Shared Infrastructurepackages/core (constants, event bus, sandbox, TUI overlay/width, model cache, fusion status, bounded output), packages/utility (lifecycle, cleanup, diagnostics, analytics, skill discovery), packages/updater (version check, installer, changelog overlays), packages/unipi (umbrella entry), scripts (bundle build, pin sync)
Agent Orchestrationpackages/subagents (spawn_helper, get_helper_result, AgentManager, runners, budgets, authority policy, worktree isolation), packages/background-tasks (task registry, child-process control, delegate artifact store, result packages), packages/ralph (autonomous loops)
Context & Memory Managementpackages/compactor (compaction engine, tools, sandbox executor and security policy, SQLite SessionDB, resume injection), packages/memory (MemoryStorage, MemPalace bridge, markdown tier, migration), packages/trajectory (capture, prefix integrity, server)
External Capability Integrationpackages/mcp (ServerRegistry, McpClient, translator, config), packages/web-api (extraction engine, provider registry, cache), packages/image (image_generate, image_recognize, vision gating), packages/fusion (model picker, presets, sidekick runtime, savings)
User Interaction & Presentationpackages/footer (FooterRenderer, segment registry, presets), packages/ask-user, packages/input-shortcuts, packages/notify (platform dispatch), packages/info-screen, packages/autocomplete, packages/btw
Structured Development Workflowpackages/workflow (commands, sandboxes), packages/milestone (model, commands, hooks), packages/kanboard (parsers, HTTP server, server-rendered UI)
Persisted stateTask artifacts and snapshots, per-project session SQLite databases, memory stores (MemPalace + markdown), fusion presets, per-package configuration

3.3 Excluded Components

Excluded elementReason
Pi coding agent host runtime and its built-in toolsUnipi is a set of extensions loaded into Pi; Pi's own runtime, built-in tools, model registry and TUI framework are external.
Third-party MCP server implementationsSpawned and consumed by mcp, but implemented and maintained externally.
External LLM and image model providersResolved through Pi's model registry; provider APIs are outside Unipi's control.
Operating system notification services and their transportNotify dispatches to native/ntfy/gotify/telegram/focus platforms but does not implement them.
Remote content servers fetched by web-apiUnipi fetches and extracts; the servers themselves are external.
End-user shell, terminal emulator and window managerHost environment; Unipi renders through Pi's TUI APIs.

4. External System Interactions

4.1 External System Inventory

External systemRole relative to UnipiInteraction typeUnipi packages involved
Pi coding agent (pi-coding-agent)Host application; provides ExtensionAPI, tool registration, TUI APIs (setFooter, setWidget), model registry and event busIn-process extension host APIAll packages (via @pi-unipi/unipi composition)
MCP serversModel Context Protocol servers exposing toolsJSON-RPC over stdio to spawned child processesmcp
LLM and image model providersChat and image models resolved through Pi's model registryModel registry / provider APIimage, fusion, compactor
MemPalacePrimary memory backend, auto-installed and auto-migrated from legacy SQLite/markdown dataEmbedded storage backend via Python bridgememory
SQLiteSession event and compaction statistics store; legacy memory migration sourceEmbedded databasecompactor, memory
wreq-js and defuddleTLS-fingerprinted fetch and content extraction librariesLibrary calls / outbound HTTP to remote content serversweb-api
Web search / reader providersDuckDuckGo, Tavily, SerpAPI, Perplexity, Jina Reader, Firecrawl, WigoloOutbound HTTP API callsweb-api
Notification platformsNative desktop, ntfy, gotify, Telegram, focusOutbound notification dispatchnotify
Operating system process and file systemsChild process spawning and tree termination (incl. Windows taskkill), atomic file writes for artifactsOS process control and filesystembackground-tasks, subagents, mcp, fusion
Web browser (kanban board viewer)Consumer of the kanboard HTTP UIHTTP (server-rendered pages)kanboard

4.2 Interaction Descriptions

Pi coding agent (host). This is the single most important relationship: Unipi has no runtime without Pi. Packages register tools with TypeBox schemas, slash commands (e.g. /unipi compact, /unipi:model, /unipi:ralph), hooks (compaction, lifecycle, milestone), and TUI overlays. The footer package drives Pi's setFooter/setWidget APIs, and the fusion, image and compactor packages consume Pi's model registry. Pi lifecycle events feed the notify package.

MCP servers. ServerRegistry loads server configuration, starts each configured server as a child process, and McpClient performs the initialize handshake and listTools over stdio. The translator converts MCP tool definitions into Pi-compatible schemas with unique names and registers them. Partial failures are cleaned up so one broken server does not block others. Agent tool calls are proxied back to the owning server via callTool.

LLM and image model providers. Unipi never talks to providers directly for chat; it resolves models through Pi's registry (cached in core/model-cache). The image package additionally includes an OpenAI-images-style API client and a chat-provider-to-images bridge, with vision gating based on the active model.

MemPalace and SQLite. Memory uses MemPalace as its primary backend through a Python bridge, with a markdown durable tier and migration from legacy SQLite. The compactor's SessionDB uses SQLite for per-project events, sessions and compaction counters, including schema migration.

Web fetch stack. The extraction pipeline validates URLs, fetches via wreq-js (TLS fingerprinting), routes by content type, extracts with defuddle and fallbacks, detects meta-refresh, and caches results. Search dispatch goes through a provider registry selectable via a TUI.

Notification platforms. Notify subscribes to Pi lifecycle events and to feature events discovered dynamically via MODULE_READY (task completion, ralph loop start/end, ask-user prompts), builds message text with priority mapping and recap summarization, and dispatches to whichever platforms are enabled.

Operating system. Background tasks and subagents spawn child Pi processes, tail output, parse usage payloads, persist snapshots and terminate process trees. The DelegateArtifactStore writes seed/prompt/result artifacts with crash-safe atomic writes and manifests.

4.3 Dependency Analysis

DependencyDirectionCriticalityFailure impact
Pi coding agentUnipi → PiCriticalUnipi cannot load or run at all.
OS process/filesystemUnipi → OSCritical for orchestrationSubagents, background tasks, MCP servers and sidekick runtime unavailable.
SQLiteUnipi → SQLiteHighSession store and compaction statistics unavailable; compaction summaries themselves still computable.
MemPalaceUnipi → MemPalaceHigh for memoryMemory falls back to markdown tier / legacy data per migration logic.
Model providersUnipi → Pi registry → providersHighImage, fusion and model-dependent compaction features degrade.
MCP serversUnipi → serversMedium (per server)Individual servers fail independently thanks to partial-failure cleanup.
Web providers / librariesUnipi → HTTPMediumFallback extraction and alternate providers mitigate single-provider outages.
Notification platformsUnipi → platformsLowNotifications not delivered; core agent function unaffected.

5. System Context Diagram

5.1 C4 System Context

%% litho-mermaid
graph TD
    AgentUser["AI coding agent user"]
    ExtDev["Extension developer"]
    Team["Team using structured workflows"]

    subgraph Boundary["System boundary"]
        Unipi["Unipi extension suite - about 25 pi-unipi packages loaded into Pi"]
    end

    PiHost["Pi coding agent host - ExtensionAPI, TUI APIs, model registry, event bus"]
    MCP["MCP servers - child processes"]
    Models["LLM and image model providers"]
    MemPalace["MemPalace memory backend"]
    SQLite["SQLite session and stats store"]
    WebStack["wreq-js, defuddle and web search providers"]
    Notif["Notification platforms - native, ntfy, gotify, Telegram, focus"]
    OS["Operating system - processes and filesystem"]
    Browser["Web browser - kanban board viewer"]

    AgentUser -->|uses tools, slash commands, TUI in terminal| PiHost
    ExtDev -->|develops packages against core contracts| Unipi
    Team -->|runs workflow and milestone commands| PiHost

    PiHost -->|loads extensions via ExtensionAPI| Unipi
    Unipi -->|registers tools, commands, hooks, footer| PiHost
    Unipi -->|resolves models via Pi registry| Models
    Unipi -->|JSON-RPC over stdio| MCP
    Unipi -->|stores and recalls memories via Python bridge| MemPalace
    Unipi -->|persists session events and counters| SQLite
    Unipi -->|fetches, searches, extracts content| WebStack
    Unipi -->|dispatches notifications| Notif
    Unipi -->|spawns child Pi processes, writes artifacts| OS
    Unipi -->|serves kanban pages over HTTP| Browser
    Browser -->|viewed by| Team

5.2 Internal Domain View (context for the next level)

While the SystemContext level treats Unipi as a single box, the domain analysis reveals six internal domains connected through the core kernel. This view is provided to orient readers toward the Container level.

%% litho-mermaid
graph TD
    Core["Platform Core and Shared Infrastructure - core, utility, updater, unipi"]
    Orch["Agent Orchestration - subagents, background-tasks, ralph"]
    Ctx["Context and Memory Management - compactor, memory, trajectory"]
    Ext["External Capability Integration - mcp, web-api, image, fusion"]
    UI["User Interaction and Presentation - footer, ask-user, notify, input-shortcuts, info-screen, autocomplete, btw"]
    Flow["Structured Development Workflow - workflow, milestone, kanboard"]

    Orch -->|imports constants, events, sandbox| Core
    Ctx -->|imports events, TUI helpers| Core
    Ext -->|imports core, publishes fusion status| Core
    UI -->|imports events, reads fusion status| Core
    Flow -->|imports sandbox and events| Core

    UI -->|footer segments and notify subscribe| Orch
    UI -->|footer segments show compaction and memory| Ctx
    UI -->|footer mcp segment, model autocomplete| Ext
    UI -->|footer workflow and kanboard segments| Flow
    Orch -->|context policy and token budgets| Ctx
    Flow -->|optional ralph detection, workflowScripts| Orch

5.3 Key Interaction Flows

The following flows are ranked by importance in the domain analysis and illustrate how external systems participate.

Flow 1 — Subagent Delegation (importance 9.5)

%% litho-mermaid
sequenceDiagram
    participant LLM as Pi agent LLM
    participant SA as subagents tool-handler
    participant BT as background-tasks registry
    participant OS as OS child process
    participant Core as core event bus
    participant Notify as notify
    participant Footer as footer

    LLM->>SA: spawn_helper
    SA->>SA: resolve agent, aliases, depth guard, budgets, context policy
    SA->>BT: launch delegate
    BT->>OS: spawn child Pi process, write seed and prompt artifacts
    OS-->>BT: output tailed, usage payload parsed, snapshot persisted
    BT->>Core: task completion event
    Core->>Notify: event delivered
    Notify->>Notify: dispatch to enabled platforms
    Core->>Footer: segment refresh
    LLM->>SA: get_helper_result
    SA-->>LLM: truncated result package

Flow 2 — Context Compaction and Session Recall (importance 9.0)

  1. A compaction hook, the /unipi compact command or the auto-trigger fires; the auto-trigger compares the token estimate against the budget (compactor/src/compaction/auto-trigger.ts).
  2. compile() runs the six-stage pipeline: normalize → filterNoise → buildSections → formatSummary → merge, optionally producing a ranked brief.
  3. SessionDB records events and compaction counters in SQLite.
  4. The compactor footer segment displays compaction statistics.
  5. On resume, resume-inject and the session_recall tool restore prior context.

Flow 3 — MCP Server Tool Bridging (importance 8.0)

  1. Configuration is loaded and synced (mcp/src/config/manager.ts).
  2. ServerRegistry prepares and starts servers, handling partial failures.
  3. McpClient performs the initialize handshake and listTools over stdio.
  4. The translator converts tools and registers them with Pi's ExtensionAPI.
  5. The MCP footer segment shows active server and tool counts.

Flow 4 — Web Smart-Fetch (importance 6.5)

Tool invoked → provider selected from registry → URL validated, fetched via wreq-js, content-type routed, extracted with defuddle and fallbacks → result formatted and cached.

Flow 5 — Model Fusion Preset (importance 6.5)

/unipi:model → model registry resolved, picker overlay mounted → preset persisted, sidekick runtime spawned → fusion status (active pair, savings) published through core → footer core segment renders it.

Flow 6 — Structured Workflow with Kanban Board (importance 6.0)

Workflow command dispatched to a skill with sandbox enforcement → milestones created/updated via commands and hooks → ParserRegistry parses plan and milestone markdown; HTTP routes render board pages → footer workflow and kanboard segments reflect state.

Flow 7 — Interactive Ask-User (importance 6.0)

ask_user validates schema against the settings allow-list and normalizes options → prompt notification dispatched to platforms → TUI renderer collects the answer, or the launcher hands off to a new session → AskUserResponse returned.

5.4 Architecture Decisions Visible at the Context Level

DecisionRationaleConsequence
Ship as Pi extensions rather than a standalone CLIReuse Pi's agent loop, model registry and TUI; deliver value inside an existing workflowHard dependency on Pi's ExtensionAPI stability; no operation outside Pi
Run subagents as separate child Pi processesIsolation, independent budgets, crash containment, parallelismOS process management complexity (tailing, usage parsing, tree termination, Windows specifics)
Bridge MCP via stdio child processes with tool translationStandard protocol gives access to a broad tool ecosystem without bespoke integrationsServer lifecycle and partial-failure handling become Unipi responsibilities
Deterministic compaction pipeline with SQLite persistencePredictable summaries and measurable statistics across sessionsAdditional local state to migrate and manage
MemPalace as primary memory backend with markdown tierDurable, queryable memory with a human-readable fallbackIntroduces a Python bridge and auto-install/migration logic
Event bus with MODULE_READY discoveryPackages remain independently loadable and config-gated; consumers (notify, footer) discover features dynamicallyImplicit coupling via event names; contract lives in core

6. Technical Architecture Overview

6.1 Technology Stack

LayerTechnology
LanguageTypeScript (monorepo); Python for the MemPalace bridge and migration script
Host / runtimeNode.js inside the Pi coding agent process
Extension contractsPi ExtensionAPI — tools with TypeBox schemas, slash commands, hooks, TUI overlays, setFooter/setWidget
Inter-module communication@pi-unipi/core event bus (MODULE_READY, feature events such as RALPH_LOOP_START/END)
PersistenceSQLite (session events, compaction statistics), MemPalace + markdown (memory), filesystem with atomic writes (task artifacts, snapshots, presets, config)
External protocolsJSON-RPC over stdio (MCP), HTTP/HTTPS (web providers, notification platforms, kanboard UI)
Web extractionwreq-js (TLS-fingerprinted fetch), defuddle (content extraction)
Process controlNode child processes, Windows taskkill tree termination, worktree isolation for subagents
Build toolingBundle build and dependency pin sync scripts (scripts/build-bundle.mjs, scripts/sync-pins.mjs)

6.2 Architecture Patterns

  • Plugin / microkernel. @pi-unipi/core is the kernel; all other packages are plugins that register with the host and discover one another through events. The umbrella @pi-unipi/unipi package composes them.
  • Event-driven integration. Cross-domain coupling is deliberately loose — the presentation domain (footer, notify) subscribes to events from orchestration, context and integration domains rather than importing their internals.
  • Registry pattern. Recurs throughout: background-task registry, MCP ServerRegistry, web provider registry, footer segment registry, notify event-subscription registry, kanboard ParserRegistry, info-screen registry.
  • Pipeline pattern. Compaction compile() and web extract() are explicit staged pipelines with well-defined intermediate representations.
  • Policy objects. Subagent spawning applies budgets, depth guards, context policy and authority policy as separable libraries; the compactor's sandbox executor is guarded by a security policy scanner/evaluator.
  • Durable, crash-safe state. DelegateArtifactStore and durable-fs provide atomic writes and manifests so process crashes do not corrupt artifacts.

6.3 Key Design Decisions and Observations

Complexity concentration. Although coupling between domains is low, complexity inside a few hub files is high: background-tasks/src/registry.ts, subagents/src/tool-handler.ts, compactor/src/compaction/summarize.ts and tools/register.ts, mcp/src/bridge/registry.ts, and web-api/src/engine/extract.ts. These are the natural focus points for review and testing.

Domain placement versus documentation. Product documentation groups "structured development" as workflow/kanboard/milestone/trajectory/ralph. In code, ralph behaves as orchestration (iterative loops emitting loop events) and trajectory as context capture; this document places them with Agent Orchestration and Context & Memory Management respectively. Readers reconciling with earlier documentation should note this refinement.

Cross-package coupling to watch. kanboard/parser imports milestone types directly (strength 7.0 in the domain analysis). This is the strongest direct inter-package dependency outside the core kernel and is worth monitoring if the milestone model evolves.

Configuration gating. Every package is independently enableable, which supports incremental adoption but means the effective system context varies per installation — e.g. notify, kanboard's HTTP server or MCP bridging may be absent.

Platform specifics. Windows process-tree termination is handled explicitly (windows-taskkill.ts); the memory package depends on a Python runtime for the MemPalace bridge. Both are environmental prerequisites that sit at the system boundary.

6.4 Summary

Unipi occupies a clear position in its environment: it lives entirely inside the Pi coding agent as a family of loosely coupled extensions, and it reaches outward to MCP servers, model providers, web content, notification platforms and the operating system to make the agent more capable and its sessions longer. Its boundary is the set of @pi-unipi/* packages plus the local state they persist; everything it hosts, bridges or notifies is external. The core kernel and event bus are the architectural linchpin, and the next level of documentation (Container view) should elaborate the six internal domains and their hub components identified here.

On this page