omp packages

@rakshazi/plan-mode0.1.0

Plan a change, review it, then implement it in a fresh session

rakshazi Published 4 days ago LGPL-3.0-or-later ~0 downloads/mo

Untested on omp

This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.

Did it work for you?

Result

One report per person. A new report replaces your old one.

Reports 0

No reports yet.

Readme

plan-mode: plan a change, review it, approve it, implement it fresh

Install with pi install npm:@rakshazi/plan-mode.

The harness runs the planning procedure and the model fills in the plan. /plan locks the session to read-only work and one writable file, the plan. plan_submit checks the plan's structure, has plan-reviewer attack it, and then shows it to the user for approval. An approved plan is pasted whole into a new session, which implements it with full write access.

Using it

/plan add a --json flag to the list command
  • /plan [task] toggles plan mode. With a task, the task is sent as the first message. Toggling off keeps the plan file.
  • pi --plan starts in plan mode. Only a real startup honours the flag; a session that /implement opens does not.
  • /implement [path] implements a plan saved earlier. Without a path it takes the current plan. Typed into a session with no messages yet, it works there; anywhere else it opens a new session.

Plans live in ~/.pi/plans/<date>-<slug>.md ($PLAN_DIR overrides the directory). A slug that already has a file reopens it.

Requirements

Two tools come from other Pi packages. Both are optional, and plan mode degrades without them:

Tool Package Without it
Agent npm:@tintinweb/pi-subagents No review runs. The approval dialog shows Review: skipped, no Agent tool.
ask_user_question npm:@juicesharp/rpiv-ask-user-question The model takes its recommended option and records it under Assumptions. A "do not build" finding leaves the plan as it is, and the user sees the verdict in the dialog.

The review also needs three agent definitions, which this repository does not ship. The pi-subagents README says where they live.

  • plan-reviewer reviews the plan. Its reply needs a line starting Verdict:, which the dialog title quotes; without one the title reads Review: no verdict line. A call that fails, a missing definition included, shows as Review: failed.
  • reviewer and security-reviewer review the finished change. The plan template tells the implementing session to call them.

What the model gets

Two tools, active only in plan mode:

Tool Does
plan_start {slug} Creates the plan file from template.md, or reopens the existing one for that slug. That file becomes the only writable path.
plan_submit Runs the checker. With failures it returns them. The first passing call runs plan-reviewer in the foreground and returns its findings. The next one opens the approval dialog.

While plan mode is on:

  • write and edit are blocked on every path except the plan file.
  • bash commands matching the upstream destructive list are blocked: rm, mv, >, git commit and the rest. The list has no /i flag, so rg -n Shutdown passes.
  • The first user message gets prompt.md as a hidden custom message, injected again after compaction.
  • Every model request ends with a one-line reminder naming the writable file.

A reviewer finding marked P0 that says "do not build" goes to the user through ask_user_question with three options: rework, keep, drop. The model does not settle it itself.

Approval dialog

Title: Plan: <file> | Review: <verdict> | Unverified: <n>.

Choice Effect
Approve and implement in new session After the run settles, /implement opens a new session named <planning session name> (imp) whose first message is approved.md with the whole plan. The old session stays locked.
Approve and implement here Plan mode ends and the same session implements.
Refine The user types what should change; the model edits and submits again.
Save plan and exit pi quits; the path is shown for a later /implement.
Open plan in editor Edit the file in place, then the dialog returns.

Esc closes the dialog and leaves plan mode on. Under pi -p there is no dialog: plan_submit ends the run with Plan ready: <path> and Review: <verdict>.

The implementing session follows the plan for what to build and the house rules for how to write it. When a ttsr <rule-reminder> conflicts with a literal in the plan, the rule wins unless the plan names it and waives it with a reason.

Layout

Path Purpose
index.ts State, tools, commands, hooks, the dialog and the session handoff
gate.ts Bash blocklist and plan-path resolution; pure, node: imports only
check.ts Plan file creation and the plan checker; pure, node: imports only
gate.test.ts, check.test.ts node:test suites
template.md The plan skeleton
prompt.md Plan-mode instructions for the model
approved.md The message that starts implementation

check.test.ts pins every checker message and the order they come out in.

How the handoff works

A tool cannot open a session, since newSession exists only on command contexts. The dialog records the choice and ends the turn with terminate: true. An agent_settled handler then sends /implement <path> as a command. The command builds the message before switching, and after the switch it sends only through the replacement context, because the old pi and ctx are stale. The session title crosses the switch on globalThis, since pi loads extensions per session with no module cache.

Exactly-once guards: plan_submit runs sequentially within a tool batch. Once a handoff is queued, or plan mode has ended, it refuses to open a dialog. An Esc on the run after approval cancels the queued session and prints the /implement command to run instead.

Tests

cd ~/.pi/agent/extensions/plan-mode && node --test

The suites cover gate.ts and check.ts on plain Node. index.ts imports pi packages, which a plain Node run does not have. It is covered by a headless run: pi -p started with --plan, ending in Plan ready with a real verdict. The dialog, editor and new-session paths need the TUI.

Limits

  • The bash gate is a tripwire for a model that forgets it is planning; the sandbox is the isolation. sed -i, go run, gofmt -w and a subagent with write tools all get through.
  • Lowercase command words inside an unquoted search still block: rg -n touch. A path segment named like a command does too (ls internal/cp/), as do git stash list and git tag -l.
  • ttsr reminders ride on write and edit results, and plan mode writes one Markdown file, so the planner rarely sees them. The rule-wins sentence above is what reconciles a plan with them at implementation time.
  • Open plan in editor writes the edited text without re-running the checker or the reviewer.
  • After Save plan and exit, the path survives only in the transcript; ls -t ~/.pi/plans | head -1 finds it.