Skip to content

add pi agent target#442

Open
peachest wants to merge 1 commit into
colbymchenry:mainfrom
peachest:feat/pi-agent-target
Open

add pi agent target#442
peachest wants to merge 1 commit into
colbymchenry:mainfrom
peachest:feat/pi-agent-target

Conversation

@peachest
Copy link
Copy Markdown

Description

Add pi agent framework support to the CodeGraph installer, following the established multi-target architecture.

pi is a minimal terminal coding harness that reads AGENTS.md (or CLAUDE.md) from ~/.pi/agent/ (global) and from parent directories / the current working directory (local). It does not natively support MCP servers — its design philosophy is "No MCP. Build CLI tools with READMEs." — so this integration writes instructions into AGENTS.md telling the pi agent to invoke codegraph via its CLI (codegraph search, codegraph trace, etc.) through pi's bash tool, rather than writing an MCP server config.

What this PR does

  • New target filesrc/installer/targets/pi.ts (213 lines): A full AgentTarget implementation that:
    • Detects pi installation by checking ~/.pi/ and the PI_CODING_AGENT_DIR environment variable
    • Installs a CLI-oriented instructions block to ~/.pi/agent/AGENTS.md (global) or ./AGENTS.md (local) using the same marker-based section replacement as other targets
    • Uninstalls cleanly via marker section removal
    • Supports both global and local install locations (pi walks from cwd upward loading AGENTS.md)
    • Handles legacy unmarked ## CodeGraph sections by migrating them to the marker-delimited format (matching claude's writeInstructionsEntry pattern)
    • Respects PI_CODING_AGENT_DIR env var for custom config directories
  • Registry registration'pi' added to the TargetId union and piTarget registered in ALL_TARGETS
  • Test coverage'pi' included in the getTarget registry assertion
  • DocumentationCLAUDE.md target list updated

Why CLI instructions instead of MCP?

pi explicitly does not support MCP servers. The template in PI_INSTRUCTIONS_TEMPLATE adapts the standard codegraph usage guidance for CLI invocation (e.g. codegraph trace <from> <to> instead of codegraph_trace) and includes a note about MCP-gap extension workarounds.

Related Issues

Closes the following requests for pi agent support:

Issue Request Author
#184 Add pi and omp as code agents to the installer @corrm
#328 How to use it in PI @cherish-ltt
#397 Support for pi agent @SeanPedersen

#184 was the original feature request filed shortly after the multi-target installer shipped. #328 shows real user demand — someone asking how to use codegraph with pi before installer support existed. #397 came with a companion pi-codegraph extension by @SeanPedersen, providing a complementary MCP-gap workaround.

This also relates to #65 ("Does it support other AI assistants besides Claude") — a broader request that this PR helps address by adding another supported agent to the installer.

Type of Change

  • Bug fix
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring
  • Performance improvement
  • Test update

How Has This Been Tested?

Unit tests

npx vitest run __tests__/installer-targets.test.ts
# 92 tests passed (all existing tests continue to pass)

Real-world detection verification

Tested against an actual pi installation on macOS:

// Global — detects ~/.pi/agent/ directory
piTarget.detect('global')
// → { installed: true, alreadyConfigured: true, configPath: "~/.pi/agent/AGENTS.md" }

// Local — detects ~/.pi/ exists on the system
piTarget.detect('local')
// → { installed: true, alreadyConfigured: false, configPath: "/cwd/AGENTS.md" }

Build

npm run build  # compiles cleanly

Cross-target comparison (via subagent review)

The implementation was reviewed side-by-side against all four existing targets:

Reviewer Comparison Findings
Reviewer 1 pi vs claude 0 bugs; legacy heading migration added, install notes added
Reviewer 2 pi vs codex 0 bugs; no significant missing features
Reviewer 3 pi vs hermes 0 bugs; shared helper reuse preferred over hermes's 140-line custom YAML parser
Reviewer 4 pi vs opencode 0 bugs; virtually identical instructions-writing pattern

All reviewers confirmed: pi correctly implements the AgentTarget interface, handles edge cases appropriately, and its "No MCP" design is correctly reflected.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (CLAUDE.md)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally (npm test)
  • Any dependent changes have been merged and published in downstream modules

Files Changed

File Change Description
src/installer/targets/pi.ts New (213 lines) Full pi agent target implementation
src/installer/targets/types.ts Modified (+1 line) Added 'pi' to TargetId union
src/installer/targets/registry.ts Modified (+2 lines) Imported and registered piTarget
__tests__/installer-targets.test.ts Modified (+1 line) Added 'pi' to getTarget assertion
CLAUDE.md Modified (+1 line) Updated target list to include pi.ts

Screenshots / Demo

N/A — installer target, no UI.

Additional Context

Architecture notes

pi follows the same marker-based section replacement pattern as claude, cursor, codex, and opencode targets:

<!-- CODEGRAPH_START -->
## CodeGraph

…CLI-oriented usage guidance…

<!-- CODEGRAPH_END -->

The PI_INSTRUCTIONS_TEMPLATE diverges from the shared INSTRUCTIONS_TEMPLATE intentionally — the shared template assumes MCP tool calls (codegraph_search, codegraph_trace), while pi's template instructs the agent to use CLI commands via bash (codegraph search, codegraph trace).

Environment variable support

piAgentDir() respects PI_CODING_AGENT_DIR when set, falling back to ~/.pi/agent/. This mirrors HERMES_HOME in the hermes target and provides users with flexible configuration.

Subagent review methodology

Three parallel subagent reviewers examined the implementation from different angles:

  1. Contract correctness — interface compliance and type safety
  2. pi-context accuracy — correct paths, filenames, and "No MCP" philosophy adherence
  3. Code quality & cross-target comparison — edge-case handling, shared helper reuse, missing features

All findings were addressed before finalizing the PR: legacy heading migration, install notes, env var support, and detection accuracy.

Add pi (https://pi.dev) agent framework support to the CodeGraph
installer, following the established multi-target AgentTarget
architecture.

pi is a terminal coding harness that reads AGENTS.md from
~/.pi/agent/ (global) and parent/current directories (local).
It does not natively support MCP servers, so this target writes
CLI-oriented codegraph usage instructions to AGENTS.md instead
of an MCP server config.

Key decisions:
- No MCP config writing — pi's design philosophy is 'No MCP'
- CLI-based instructions template adapted for pi's bash tool
- Marker-based section replacement (same pattern as claude/codex)
- PI_CODING_AGENT_DIR env var support for custom config dirs
- Both global (~/.pi/agent/AGENTS.md) and local (./AGENTS.md)
- Legacy heading migration for pre-marker ## CodeGraph sections

Closes colbymchenry#184, colbymchenry#328, colbymchenry#397.
Refs colbymchenry#65.

Signed-off-by: houyuxi <yuxi.hou@transwarp.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant