Skip to content

Agent integration: Pi coding agent #221

@mcinteerj

Description

@mcinteerj

Summary

Proposing native Pi coding agent integration, similar to the existing Claude Code and Gemini CLI agents, and the in-progress OpenCode integration (#220).

Why Pi?

Pi is one of the fastest-growing coding agent CLIs right now:

  • 10,000+ GitHub stars on pi-mono (993 forks)
  • npm downloads exploding: ~4k/week in Dec 2025 → 1.3M/week by late Jan 2026 (300x growth in ~6 weeks)
  • 207 published versions across 4 months — extremely active development cadence (multiple releases per week)
  • Rapidly expanding user base that would benefit from Entire session tracking

How Extensible Pi Is (Implementation Feasibility)

Pi makes this integration straightforward due to its architecture:

JSONL Session Format (Same as Claude Code)

Pi stores sessions as JSONL at ~/.pi/agent/sessions/--<path>--/<timestamp>_<uuid>.jsonl. Each line is a typed JSON entry with id/parentId fields forming a tree. The format is well-documented (session.md) and closely parallels Claude Code's JSONL transcript format — meaning the existing ChunkJSONL/ReassembleJSONL utilities, transcript position tracking, and modified file extraction patterns all transfer directly.

TypeScript Extension System for Hooks

Pi has a rich extension API with lifecycle events that map cleanly to Entire's hook model:

Entire Hook Pi Extension Event Notes
session_start session_start Direct 1:1
session_end / stop session_shutdown / agent_end agent_end fires per-prompt; session_shutdown on exit
user_prompt_submit before_agent_start Provides event.prompt
pre_tool_use tool_call Can inspect tool name + input
post_tool_use tool_result Has result content + details

InstallHooks() would generate a .pi/extensions/entire.ts file that subscribes to these events and calls entire hooks pi <verb> via pi.exec() — the same bridge pattern used in the OpenCode integration (#220) with its .opencode/plugins/entire.js.

Extensions Are Auto-Discovered

Pi auto-discovers extensions from .pi/extensions/*.ts (project-local) or ~/.pi/agent/extensions/*.ts (global). TypeScript runs without compilation via jiti. No config file modification needed — just drop the file and it works on next session start. This makes InstallHooks()/UninstallHooks() trivially clean (create/delete a single .ts file).

Rich Session Metadata

Pi's session entries include:

  • Token usage with cost breakdowns per assistant message
  • Model/provider info on every response
  • Tool call arguments and results with structured details
  • Compaction summaries, branch summaries, labels
  • bashExecution messages with command, output, exit code

This means ReadSession() can extract rich checkpoint metadata (modified files from write/edit tool results, token usage aggregation, etc.).

Proposed Implementation

New package: cmd/entire/cli/agent/pi/

File Purpose
pi.go PiAgent struct — Agent interface, session read/write, presence detection (.pi/ dir)
hooks.go HookSupport + HookHandler — generate/remove .pi/extensions/entire.ts bridge
transcript.go Parse Pi JSONL (tree walk from leaf → root to linearize), extract modified files
types.go Pi-specific JSON types (session header, message entries, content blocks)

Key difference from Claude/Gemini: Pi's JSONL is a tree, not a flat log. ParseTranscript() would need to resolve the leaf, walk parentId chain to root, and produce a linear conversation. This is a well-defined operation — Pi's own buildSessionContext() does exactly this.

Notes

  • Happy to implement this. Wanted to open an issue first to gauge interest and get architectural feedback before writing Go code.
  • The OpenCode PR (Add OpenCode agent integration #220) establishes the extension-bridge pattern — would be good to see how that lands before/alongside this, since they share the same approach.
  • Pi's .pi/extensions/ auto-discovery means zero friction for users: entire enable --agent pi generates one file, done.

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-supportadding support for additional AI agentsenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions