Skip to content

feat: add pi agent support #1429

Description

@ZeR020

Summary

Add first-class support for the pi coding agent as codemem's fourth client integration, alongside opencode, Claude Code, and Codex.

Motivation

Pi is a deliberately minimal, TypeScript-native coding agent whose only plugin surface is its extension API (pi.on() events + pi.registerTool()); it has no native MCP support and no hooks mechanism — extensions loaded from npm/git/local "pi-packages" are the entire integration surface. Its extension API is arguably the richest of the four clients: per-turn before_agent_start handlers can append to the system prompt, tool_result middleware can patch results, and session_before_compact exposes compaction boundaries.

A pi integration built on codemem's existing thin-client pattern (HTTP to the viewer server + CLI fallback) lands at opencode-level first-classness, plus two pi-only capabilities:

  • compaction-boundary memory extraction — flush extraction before pi discards context (observe-only; never replaces pi's own summarizer)
  • fork/resume-aware raw-event streams — pi session ids mint per fork

Proposed scope

  • @codemem/pi-extension (new npm pi-package, lockstep-versioned with @codemem/opencode-plugin): event ingest via POST /api/pi-hooks, per-turn memory injection via system-prompt append (never the persistent message channel), and codemem's 14 memory_* tools registered natively (no pi-mcp-adapter required; optional --pi-mcp opt-in for adapter users).
  • core: pi event adapter (AdapterEvent v1 with source: "pi", deterministic event ids, flush-only compaction signals) + observer extraction configuration derived from pi's own settings.json/models.json/auth.json (API-key providers only in v1; OAuth reported as explicitly unsupported rather than silently 401).
  • viewer-server: dedicated POST /api/pi-hooks (server-side source assertion) + closes the HTTP route gap so all 14 tools work over HTTP.
  • cli: pi-hook-ingest (HTTP-first, spool + boundary flush) / pi-hook-inject commands, and codemem setup pi target — one-command install (--pi-only, --pi-mcp, --pi-extension-path).
  • ui/docs: pi in settings/health client enumerations; README + docs updated in the same PR.

Because the store is shared, pi users who also run opencode/claude/codex get cross-agent memory automatically (pack filtering is project-scoped, never agent-scoped).

Non-goals (this iteration)

  • OAuth-based extraction via pi providers (API-key providers only in v1).
  • Google / non-OpenAI-or-Anthropic observer wire APIs.
  • Replacing or customizing pi's compaction summarizer (observe-only).
  • Generalizing /api/raw-events to arbitrary sources (dedicated route instead, mirroring /api/claude-hooks).

I have this implemented and reviewed (multi-pass adversarial review + full quality gates green) and will open the linked PR shortly.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions