A Pi-native extension that provides the Pi coding agent with structural code exploration capabilities through the CodeGraph CLI.
- Pi-native: Integrates using Pi's native extension APIs (
registerTool,addPromptGuidelines,addPromptSnippet) rather than introducing an MCP server lifecycle or adapter layer. - CodeGraph-compatible: Interacts strictly through CodeGraph's public CLI interface (
codegraph explore <query>). It does not touch.codegraphdatabase internals or import internal CodeGraph packages. - Upstream-independent: Functions independently without requiring CodeGraph upstream modifications, forks, or PRs.
- Node.js 22+ (macOS, Linux; Windows experimental).
- CodeGraph CLI installed and available on your system
PATH:# Verify CodeGraph CLI is available codegraph --version - Initialized Workspace Index: The active workspace must have a
.codegraph/index:# Run in your project root once codegraph init
Install the package as a Pi package:
pi install npm:@allenmuu/pi-codegraphPi will load the extension from the package manifest automatically. For a manual import in a custom Pi setup:
import registerPiExtension from "@allenmuu/pi-codegraph";
export default function (pi) {
registerPiExtension(pi);
}For local trial or direct audit without npm dependencies, copy examples/pi-codegraph.ts into your local Pi extensions directory.
Exposes exactly one focused LLM-callable tool:
{
"query": "How does authentication flow from API endpoints to the database?"
}The extension injects native prompt guidelines advising the agent when to choose codegraph_explore:
- Use
codegraph_explorefor:- System or module architecture
- Multi-file feature implementations
- Symbol relationships and implementations
- Call paths and request lifecycles
- Cross-file dependencies and change blast radius
- Use built-in
grep/find/readfor:- Exact literal string matching
- Known files and line numbers
- Documentation, configuration, build scripts, or generated files
- Workspace Sandbox: Derived exclusively from the active Pi session (
cwd); LLM cannot supply arbitrary directory paths. - Safe Process Spawning: Uses argument arrays (
spawn), strictly preventing shell interpolation and injection risks. - Output Bounds: Exploration output is capped at 50 KB or 2,000 lines with an explicit truncation notice to prevent model context exhaustion.
- Timeout & Cancellation: 30-second timeout (
CODEGRAPH_TIMEOUT) andAbortSignalcancellation propagation ensure child processes are terminated promptly. - Zero Network & Zero Telemetry: Sends no external network requests and collects no telemetry.
Process failures return actionable error messages without leaking internal Node stack traces:
| Error Code | Meaning | Remediation |
|---|---|---|
CODEGRAPH_NOT_FOUND |
CLI binary not located on PATH |
Install CodeGraph or update system PATH. |
CODEGRAPH_NOT_INITIALIZED |
Workspace missing .codegraph/ |
Run codegraph init in workspace. |
CODEGRAPH_TIMEOUT |
Process exceeded 30 seconds | Refine query to be more specific. |
CODEGRAPH_ABORTED |
Cancelled by agent signal | Re-run if cancelled unintentionally. |
CODEGRAPH_COMMAND_FAILED |
CLI returned non-zero exit | Inspect the bounded stderr tail (up to 4 KB). |
npm install # Install dependencies
npm run build # Compile TypeScript (tsc)
npm test # Run test suite
npm run lint # Static type-check