pi-plans

Human-in-the-loop planning extension for the Pi coding agent: researched, refined Markdown plans before any code changes.

Packages

Package details

extensionskill

Install pi-plans from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:pi-plans
Package
pi-plans
Version
0.6.0
Published
Sep 29, 2026
Downloads
1,817/mo · 536/wk
Author
maxingaussian
License
MIT
Types
extension, skill
Size
1.8 MB
Dependencies
0 dependencies · 0 peers
Pi manifest JSON
{
  "skills": [
    "./skills",
    "./skills/debug-and-plan",
    "./skills/plan-small",
    "./skills/plan-normal",
    "./skills/plan-big",
    "./skills/plan-with-refs"
  ],
  "extensions": [
    "./index.ts"
  ]
}

Security note

Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.

README


A rough change request becomes a versioned Markdown plan instead of a surprise diff. The agent inspects your repository read-only, asks scoped planning questions one at a time, and stores every answer in a per-run ledger. Reviewer and criticizer subagents refine the plan until it converges — and only after you explicitly approve the handoff does the extension enter a tracked execution loop that injects the remaining verifier checklist every turn and lifts the write guard. Nothing outside planning artifacts is writable until that approval.

Benchmarked: 6× more tasks solved

On Terminal-Bench 2.0 (36-task stratified sample, GLM-5.3-Flash), a paired A/B per task found: 50.0% of tasks solved with pi-plans vs 8.3% with stock pi (McNemar exact p = 0.0003) at 7.6× fewer tokens per solved task.

Terminal-Bench 2.0 GLM-5.3-Flash + Vanilla Pi GLM-5.3-Flash + Pi with pi-plans (/plan-big)
Tasks solved (seed 1, n=36) 3/36 (8.3%) 18/36 (50.0%)
Tokens per solved task 2,783,085 366,011 (7.6× fewer)

[!NOTE] Exploratory result: single model, single seed, forced /plan-big variant, eval-only auto-approve. Full methodology and disclosures: docs/benchmarks/tech-note.md.

Contents

How it works

        rough change request
                 |
   language + docs location (once per workspace)
                 |
   planning questions, one ask_choice at a time  | write guard ON
                 |                              | only .git/pi_plans/,
                 v                              | run artifacts, cache
        PLAN_vN.md + Verifier Checklist              | are writable
                 ^                |
                 |  refine rounds |
                 +----------------+
         reviewer (x1..x3) -> criticizer -> revise
                 |
                 v
     explicit approval (never auto-completed)
                 |
   =============================================== write guard OFF
                 |
        tracked execution loop
   fused AGENTS.md × Ponytail executor rules
   checklist injected each turn, [DONE:VC-xxx]
   markers tracked via bottom status bar
                 |
                 v
           run status: done

Every plan version carries stable IDs (I-###, VC-###) that never get recycled across revisions, so acceptance criteria survive refinement rounds intact.

Quick start

Install from npm:

pi install npm:pi-plans
# or try it without installing:
pi -e npm:pi-plans

Then describe a change from any repository:

You: Create a plan to split the execution loop into smaller modules.

Pi:  Which planning docs location should this workspace use?
     1. ./docs/pi-plans (recommended)
     2. ./.git/pi_plans/plans
     3. Other
     4. Auto-complete

Pi:  Wrote ./docs/pi-plans/2026-08-26-split-execution-loop/PLAN_v1.md
     Example verifier item:
     - [ ] `VC-001` covers `I-001`; pass condition: `npm test` passes;
       evidence: test output; metric: zero failing tests.

Pi:  Accept the plan and execute it now?
     1. ✓ Accept plan and execute now (recommended)
     2. Accept plan, don't execute yet
     3. Run another round: Reviewer
     ...

You: 1 — accept and execute.

Planning artifacts live under ./docs/pi-plans/YYYY-MM-DD-<topic>/ by default (public, committed). Prefer .git/pi_plans/plans if you want them private to the repository.

What it does

Capability In short
Planning router + five specialist skills Start with /skill:planning to route to the narrowest matching specialist (plan-small → plan-big, debug-and-plan, plan-with-refs)
Choice prompts ask_choice: recommended option first, answers auto-recorded per run; every option you author states its advantage and its drawback as ✓ <advantage> / ✗ <drawback> in the configured language, so the user can weigh each option before answering; choosing Auto-complete enables recommendation-only answers for later eligible questions in the current planning run, with /plans-autocomplete-stop available to take back control. After execution completes, the continuation prompt enters goal-running mode by default: it asks only for the implementation-review loop's termination condition and then keeps refining until the loop ends or the cap is reached.
Refinement rounds Read-only reviewer/criticizer Pi subagents consolidate findings into the next plan version; delegated runs have standalone Reviewer/Criticizer progress overlays that close before the tool result returns; analyze_refs shows the same kind of overlay titled Refs while per-reference analysis subagents run
Workspace state Config, runs, decisions, refs, and subagent ledgers in .git/pi_plans/ (git common dir)
VCC compact Active planning/execution compaction uses deterministic, no-LLM VCC-style summaries when Pi core emits manual /compact, threshold, or overflow events. Summaries use five bracket sections plus a brief transcript, keep a smart recent tail, support keep:N, and write VCC details/stats without adding /pi-vcc commands.
Visible Refiner overlay Delegated reviewer/criticizer subagents surface as a named public overlay in the TUI — one Reviewer/Criticizer panel with per-lane tool progress, full streaming transcript with follow-bottom scroll, Tab-pane focus, retention until the user presses Esc after completion, and clean cancelled/timed-out vs completed states. reviewers: 3 renders three equal-height panes inside the same overlay
Tracked execution Checklist injected each turn; [DONE:VC-xxx] markers drive completion; implementation items report progress with [I-xxx:implemented] / [I-xxx:validating] markers; the bottom status bar shows lifecycle, x/y progress, elapsed time, and input/output token usage in real time
Multi-run workdirs (0.6.0) Several pi sessions can plan concurrently in one workdir: the run registry derives from runs/ (no shared pointer to race), each session binds to its run, and same-topic runs get suffixed artifact dirs. /plans-abandon, /plans-execute, and /resume-plans are binding-first and open a descriptive run-picker form when more than one candidate exists; /plans lists all runs (newest first, bound run marked)
Goal-wait continuation In TUI/RPC, only a fully settled agent with unpassed VCs and no pending input or compaction gets one hidden wake carrying the latest checklist. Tool turns never queue reminders or consume guard rounds. The status bar shows progress; 3 no-progress cycles or 6 waiting cycles pause continuation. User interruption and final model errors also pause it. Only genuine user input or /plans-execute resumes; extension messages cannot. Print/JSON single-shot sessions track progress without automatic wakes. /plans-stop terminates execution
Execution handoff The accepted plan resumes in the current session (recommended) or, after the runtime question, on a delegated executor subagent running a different model: ≥3 switch targets (session-visible models + registry, deduped), one child for the whole plan with native write tools, Executor overlay progress, parent-side [DONE:VC-xxx] tracking, Esc///plans-stop → stopped (resumable), and a configurable timeout (executor_timeout_minutes, default 60). Auto-approve/no-UI skips the question (current session, [auto-approve] recorded)
Execution-phase compaction Pi core owns scheduling; pi-plans maps the active plan path, current I-###, implementation IDs, and remaining VC-### checklist into the VCC sections. The old current-I proactive trigger and model-generated summary path are removed.
Planning-phase compaction During run.status=planning with no active execution, pi-plans maps active run, artifact directory, latest plan path from session entries, and observed current-I markers into the VCC sections. Without an active planning run, compaction returns to Pi core. Additionally, creating a new run (plans start-run) proactively requests one pre-plan VCC compaction and resumes planning with a hidden message (default on; prePlanCompact:false disables).
Efficient executor prompt Each turn, the executor is steered by a fused rule set — Marcos Hernanz's AGENTS.md principles × Ponytail minimalism: layered growth, simplest implementation, long-term architecture (no stopgaps), library discipline — so plans finish in fewer tokens and fewer detours
Write guard edit/write blocked outside planning artifacts while a run is active; delegated executor children (and PI_PLANS_RUN_ID-pinned children) are exempt so a foreign session's planning run can never block an executing child; graph-aware file tools fall back to native writes for executor children

Interface overview

Tool / Command Purpose
plans State CLI: init, show, set-language, set-artifact-root, set-refs-root, set-role, start-run, set-status, record-decision, record-ref, record-subagent, record-checkpoint (state-machine-validated workflow transitions)
ask_choice Numbered choice prompt; autoComplete: false for the merged accept/execute question and external-state questions
refine Reviewer/criticizer round via standalone read-only subagents (--mode json -p --no-session --tools read,grep,find,ls, plus code_graph for both roles when the workspace has the code graph enabled); target: "plan" (default) reviews the plan, target: "implementation" reviews the implemented worktree against the plan; delegated TUI runs show one Reviewer/Criticizer overlay (78% width × 78% height, top-center, ≥72 cols) with per-lane transcript, follow-bottom scroll, Tab focus, and retention until Esc; reviewers: 3 renders three equal-height panes; enforces role/model confirmation gates
analyze_refs plan-with-refs reference analysis: one independent read-only subagent per downloaded reference (cwd = the ref directory), reusing the reviewer role gates and the concurrent overlay (titled Refs); batches of at most 3 lanes run sequentially; returns structured per-reference sections for REF_ANALYSIS.md
execute_plan Execution handoff: re-confirms with the user, asks the runtime (current session vs switch model → delegated executor), and enters extension-managed execution mode; picks the run via a descriptive form when several planned runs coexist
/plans Show config, all runs (newest first, bound run marked, cap 50), and execution progress
/config-pi-plans Re-ask workspace defaults for language, artifact root, refs root, code graph, reviewer mode/model, and criticizer mode/model
/resume-plans Resume a run in the CURRENT session across restarts: unfinished planning (pending question + answered decisions), reviewing (round/lane state, successful outputs reused), execution (approval digest + HEAD + verified VCs), and implementation review (termination condition + round count). Binding-first: the session-bound resumable run resumes directly; a unique candidate goes direct; multiple candidates get a descriptive chooser. Linked worktrees share candidates; a cross-worktree resume confirms, copies artifacts without overwriting, and resets approval + VC validity (the termination condition survives, rounds restart at 0). An unchanged plan digest with a changed HEAD keeps the authorization but re-verifies old VCs first. Busy sessions and runs actively owned by a live process only notify — no queueing, no takeover. Interactive (TUI/RPC) only
/plans-execute [plan.md] Resume a paused active execution without losing verified progress; otherwise enter the explicit execution handoff (run-picker form when several planned runs coexist; runtime question: current session or switch model)
/update-plan [plan.md] [reason…] Interrupt-and-refine: stops execution (if any), returns the run to planning, and directs the agent to revise the plan into PLAN_vN+1.md while preserving verified work
/plans-autocomplete-stop Stop the current run's Auto-complete mode and return later planning questions to normal interaction
/init-graph Build the code graph: tree-sitter function index + cross-file call/import edges (EXTRACTED vs INFERRED confidence) + label-propagation communities; writes .git/pi_plans/graph/GRAPH_REPORT.md (subsystems, god nodes, edge stats). Full rebuilds never touch files with staged edits (fail-closed pending guard)
/update-graph Incrementally reindex changed files (shared path used by apply/final-commit triggers and the watcher)
/apply-graph Materialize DB-first staged edits to the worktree; auto-reindexes the materialized set afterward
/graph-status /graph-drift Graph inventory and DB↔source convergence
/watch-graph /unwatch-graph 300ms-debounced filesystem watcher feeding incremental reindex; single-writer per worktree (atomically claimed PID+heartbeat lock, stale takeover), skips files with staged edits, fails closed on errors, stops cleanly on fs.watch errors / repeated failures / session shutdown, auto-restarts when enabled
code_graph actions Read-only: status (files/functions/edges + confidence×resolution distribution), screening (per-row freshness probes), get-function, query (keyword→BFS/DFS with token budget + shown/omitted counts), path A B (shortest call path), explain <fn> (community/degrees/neighbors), impact <fn> (reverse call closure + affected files); write path: DB-first staged edits + apply (auto-reindexes the materialized set). Edge resolution covers re-export barrels (export {x} from / export * follow to the defining module), namespace/default imports, require destructuring, and dynamic import(); same-name exports classify as ambiguous
/plans-stop Stop execution mode
/plans-abandon Abandon a run (pick via form when several candidates; lifts the write guard; artifacts stay)
Status bar (lifecycle) 💬 Q&A → 📝 draft written (planning sub-phases) → ⌛ executing x/y · spent · in/out-toks in the bottom status bar → ⛔ stopped / 🎯 done / 🚫 abandoned

VCC compact

Pi core remains the owner of compaction scheduling: manual /compact, threshold, and overflow events are emitted by Pi as usual. During an active pi-plans planning or execution run, pi-plans handles session_before_compact with a deterministic VCC-style compiler instead of calling a model for a summary.

  • Summary shape. The summary contains exactly five bracket sections: [Session Goal], [Files And Changes], [Commits], [Outstanding Context], and [User Preferences], followed by --- and a ranked brief transcript. Execution contributes plan path, current I-###, implementation IDs, and remaining verifier IDs; planning contributes run ID, artifact directory, latest plan path from session entries, and any observed current-I marker.
  • Session-only input. Compact summaries are built from the event's branch entries, previous summary, file ops, pi-plans custom session entries, and live phase state. The compiler does not read plan files, git history, or the worktree to invent context.
  • Tail policy. The default keep is one recent user turn; smart keep may retain more turns when the tail is still small. Explicit keep:N is honored, while no-anchor and oversized-tail cases use a deterministic token-budget cut that avoids starting retained context with an orphan tool result.
  • Manual matrix. Plain /compact and /compact keep:N compact and show stats without continuing. /compact <text> and /compact keep:N <text> compact, then send the text once as the follow-up prompt. Internal pi-plans compaction markers are never reused as user follow-up prompts.
  • Fallbacks and stats. Unsafe manual/threshold cuts cancel with a warning; overflow or retrying unsafe cuts return control to Pi core. Successful VCC compactions notify with kept-tail and summarized-message stats. Threshold/overflow compactions may queue one hidden continuation only when the running Pi version still needs it and continueAfterThresholdCompact is enabled.
  • Pre-plan compaction. When plans start-run creates a new planning run, pi-plans proactively requests one VCC compaction (internal hint pi-plans planning pre-plan compact) right after the run is created and before the first planning question, then resumes the planning turn with a hidden message — so each new plan starts on a lean context (LLM reasoning degrades with longer input). Small sessions, already-compacted sessions, and failures skip silently and still resume. prePlanCompact:false in the repo-private config restores the old behavior.
  • Repo-private config. Defaults are scaffolded in .git/pi_plans/pi-vcc-config.json under the resolved git common dir: overrideDefaultCompaction:true, smartKeepTail:true, continueAfterThresholdCompact:true, prePlanCompact:true, debug:false. Global pi-vcc config and PI_VCC_CONFIG_PATH are intentionally ignored.

Visible Refiner overlay

Delegated refine rounds (reviewer or criticizer) and analyze_refs rounds (titled Refs) show their progress directly inside the Pi TUI instead of disappearing into the child process's terminal. The overlay is a public, named panel so users always know who is doing what:

  • Pi-btw-aligned geometry. Each round uses width: "78%", minWidth: 72, maxHeight: "78%", anchor: "top-center", and { top: 1, left: 2, right: 2 } margins (no dependency on pi-btw; the renderer is built on Pi's public pi-tui primitives).
  • Complete streaming transcript. Assistant text, thinking blocks, tool calls, tool results, and stderr are merged per turn/content block into lane entries without overlay-facing truncation; only the viewport slices them. Final message_end / tool_execution_end overwrite the live snapshot with the authoritative content.
  • No input row. The overlay has no composer, no submit path, and no printable input forwarding. Only Esc, Tab/Shift+Tab, ↑/↓, PgUp/PgDn, and SGR mouse wheel are consumed; everything else is ignored by design.
  • Equal-height panes for reviewers: 3. Concurrent reviewer rounds render one reviewer lane per subagent as three independent equal-height panes inside the same top-center overlay; each pane keeps its own scroll offset and follow-bottom state. Tab/Shift+Tab switches the focused pane and scroll keys only affect it.
  • Lifecycle. The overlay opens at round start, advances via the JSONL progress feed emitted by pi --mode json, and is dismissed by Esc. Esc is close-only — it never aborts the refiner child; the child keeps running to natural completion and its result still flows back through the tool result path. A new refinement round replaces any retained finished overlay to avoid overlay stacking. Cancelled and timed-out children render as terminal states with the original error message — never as silent drops.
  • Tool-only progress. The overlay only consumes tool and message lifecycle events from the child; unrelated pi events are ignored, so a noisy upstream release does not desync the panel.

The execution rules

Once you approve the handoff, every turn injects a compact rule set that fuses Marcos Hernanz's AGENTS.md seven principles with Ponytail minimalism — so the executor finishes plans in fewer tokens and fewer detours:

  1. Grow in layers — smallest end-to-end slice first, then stack each new capability on top of what already works.
  2. Simplest implementation — no speculative abstractions, configuration, or indirection; modular components with clearly separated concerns.
  3. Long-term architecture, no stopgaps — no backward-compatibility layers, fallbacks, or migrations; remove the obsolete paths a change obsoletes.
  4. Library discipline — prefer established, well-maintained libraries; check the project's existing dependencies (docs and types) before writing your own or adding a package.

The rules cost four lines per turn and buy back far more: fewer wrong turns, shorter implementation paths, plans that finish in fewer tokens.

Waiting for subprocess-backed verification: For subprocess-backed verification, when a step starts a subprocess and needs its result before verifying, use literal waiting for with backoff 5s -> 10s -> 20s -> 40s -> 80s, then keep polling at 80s; restart at 5s for each new subprocess.

Skills

Invoked via resources_discover, callable as /skill:<name>, directly as /<name> (e.g. /planning, /plan-small — extension aliases that forward to the skill), or picked automatically from the task description.

Skill Use it when
planning General router; selects the narrowest specialist skill before planning starts
plan-small Small scoped change; 1–3 questions; one criticizer round
plan-normal Broad or risky change; 5–10 questions; reviewer + criticizer rounds
plan-big Open-ended/high-risk effort; 10+ questions; three concurrent reviewers
debug-and-plan Bug, CI failure, regression, incident — diagnose before planning
plan-with-refs External references must be analyzed before planning — repos, papers (arXiv), engineering blogs, and docs sites all count; theoretical references are equal citizens. plan-normal/plan-big may optionally cite 1–2 search-found references without downloading

Installation details

Dev / quick test against a local checkout:

pi -e /path/to/pi-plans

Permanent (global), via symlink into the auto-discovered extensions dir:

mkdir -p ~/.pi/agent/extensions/pi-plans
ln -s "$(pwd)"/index.ts "$(pwd)"/tools "$(pwd)"/src "$(pwd)"/skills "$(pwd)"/references "$(pwd)"/agents ~/.pi/agent/extensions/pi-plans/

or register the absolute path in ~/.pi/agent/settings.json:

{ "extensions": ["/absolute/path/to/pi-plans"] }

Benchmarks

First full A/B run complete (36-task stratified TB2.0 sample, GLM-5.3-Flash, seed 1) — headline numbers above; full methodology and disclosures in docs/benchmarks/tech-note.md.

Terminal-Bench 2.0 GLM-5.3-Flash + Vanilla Pi GLM-5.3-Flash + Pi with pi-plans (/plan-big)
Tasks solved (seed 1, n=36) 3/36 (8.3%) 18/36 (50.0%)
Tokens per solved task 2,783,085 366,011 (7.6× fewer)

We evaluate pi-plans with a controlled A/B: vanilla pi vs pi + pi-plans (planning entry injected at the adapter level; task instructions verbatim in both arms) on Terminal-Bench 2.0 (89 tasks) through the harbor framework, paired per task and analyzed with a pre-registered McNemar exact test plus paired bootstrap CIs. Cost accounting includes parent and subagent usage.

Scope of any published claim (strictly limited): pi-plans (forced-/plan-big variant) on Terminal-Bench 2.0 / single model / single seed — an exploratory paired difference, not a general claim about pi-plans. Human-approval gates are bypassed by an eval-only PI_PLANS_AUTO_APPROVE=1 env (lifecycle questions only, default off), so results do not represent the interactive experience.

Reproduce:

node --experimental-strip-types scripts/bench/run-ab.ts --prepare
node --experimental-strip-types scripts/bench/run-ab.ts --arm both --full   # requires docker + harbor
node --experimental-strip-types scripts/bench/analyze.ts --results-dir scripts/bench/results/<date>

Methodology, preregistered statistics, and disclosures: docs/benchmarks/tech-note.md.

Layout

pi-plans/
├── index.ts               # Extension entry: tools, commands, guard, execution loop
├── tools/                 # plans, ask-choice, refine, execute-plan, code-graph
├── src/                   # state, guard, plan parsing, subagent runner, refine overlay, exec loop
│   └── code-graph/        # SQLite schema/store, parsers, indexer, summary, materialize
├── skills/                # The planning router plus five specialist planning skills
├── references/            # Shared workflow, state/config, plan template (normative)
├── agents/                # reviewer.md / criticizer.md subagent prompts
├── scripts/validate.ts    # Structure + package artifact guard
└── tests/                 # node:test suite (state, guard, plan parsing, execution, refine progress, code-graph)

Safety model

Before the approved handoff the workflow writes only .git/pi_plans/ state, the run's artifact directory, ~/.cache/pi-plans/, and the configured refs root (set via plans set-refs-root or /config-pi-plans; the recommended .git/pi-plans/refs/ lives inside the git dir and needs no extra guard) — the extension blocks edit/write elsewhere while a run is planning/accepted (bash stays discipline-bound: inspection, git init, downloads into the cache). Reviewer/criticizer/ref-analyst subagents run with read-only tools. Auto-complete may answer planning and refinement questions only; it is never offered for execution, installs, publishing, deployment, merge, push, or credential use, and non-interactive sessions stop instead of auto-approving those.

Delegated executor children (0.6.0) write natively with the approval already recorded — the planning guard no-ops for PI_PLANS_EXECUTOR=1 children and honors a PI_PLANS_RUN_ID pin, so another session's concurrent planning run can never block an executing child; graph-aware file tools bypass DB-first staging for executor children so edits always land on disk. The child inherits pi's project-trust model (built-in write tools are always available; pi has no permission popups) and never loads run bookkeeping beyond its pinned id. ask_choice refuses to run inside an executor child (no interactive user — decide autonomously).

Verification

npm run validate   # structure + package artifact guard
npm test           # node:test suite (stdlib only, no deps)

Both run on Node ≥ 22.6 via --experimental-strip-types. The graph extension additionally requires node:sqlite (Node ≥ 22.13 unflagged, or any Node ≥ 22.6 with --experimental-sqlite) and the four parser dependencies listed in dependencies.

FAQ

Why do I have to approve before any code changes?

The plan is the contract. Refinement converges on scope while nothing is writable yet; the merged accept/execute question is an explicit, never-auto-completed approval that also lifts the write guard. You always see — and can veto — what will happen before it happens.

What can Auto-complete decide on my behalf?

Planning and refinement choices only (the recommended option). Choosing Auto-complete enables the recommended answer for later eligible planning questions in the current run and the extension continues the planning turn when the model stops early. Use /plans-autocomplete-stop to take back control. It is never offered for execution approval, installs, publishing, deployment, merge, push, or credentials — those questions stop and wait for you. After execution completes, interactive sessions enter goal-running review mode automatically and ask only for the implementation-review loop's termination condition; the loop then continues until that condition or the 5-round cap. Headless sessions stay silent.

Where does all the state live?

Preferences and run ledgers in .git/pi_plans/ inside your workspace's git directory (never tracked, never published); plan artifacts under the configured artifact root (default ./docs/pi-plans/); reference downloads under the configured refs root — asked once per workspace (recommended .git/pi-plans/refs/), changeable via plans set-refs-root or /config-pi-plans.

How is this different from just prompting an AI to make changes?

Prompts produce one-shot diffs with no recorded reasoning. pi-plans produces versioned artifacts — decisions, references, reviewer findings, dispositions, a verifier checklist — that are auditable, resumable across sessions, and enforced by tooling rather than goodwill.

Doesn't injecting execution rules every turn cost extra tokens?

The injected rule set is four compressed lines. It buys back more than it costs: the executor stops re-deriving discipline (no speculative abstractions, no compatibility detours, no reinvented helpers), so finished items converge in fewer turns and fewer tokens overall.

Contributing

Contributions are welcome — see CONTRIBUTING.md for the full workflow (setup, checks, commit style, and PR expectations). Small fixes can go straight to a pull request; for larger changes, open an issue first. Look for issues labeled good first issue to get started.

License

MIT.