Files
finish-audit-goal/README.md
T

45 lines
3.1 KiB
Markdown

# Finish Audit Goal
**A [Pi](https://github.com/earendil-works/pi) extension command that runs the finish-audit reviewer fanout — optionally on the [`pi-goal`](https://www.npmjs.com/package/@narumitw/pi-goal) continuation loop, so the audit repeats itself until the reviews come back clean.**
## Why
Pi's prompt templates and extension commands live in separate worlds. When you type a slash command, Pi dispatches *extension* commands first, then expands *prompt* templates — and the expanded template body is sent to the model as plain text. A `/goal ...` line inside a template body is never dispatched; Goal mode silently never activates. And the reverse nesting (`/goal` with a whole procedure as the objective) fights pi-goal's 4,000-character objective limit.
This extension bridges the two: it shadows the `finish_audit` prompt template with a command of the same name (extension commands win the dispatch race) and offers both modes behind one keystroke.
## Usage
| Command | Mode | Behavior |
|---|---|---|
| `/finish_audit` | One-shot | Sends the procedure body from `finish_audit.md` as a user message — the same behavior as the bare template. |
| `/finish_audit goal` | Goal mode | Starts pi-goal with an objective pointing at the procedure file. Goal mode's continuation loop carries the "repeat until reviews find no more issues" contract across turns automatically. |
Any other argument is rejected with a usage notification. Argument autocomplete offers `goal`.
## How it works
- **Goal mode** is started through pi-goal's managed-run RPC: `pi.events.emit("pi-goal:start", { runId, objective })` on Pi's shared extension event bus. Start/error events are surfaced as terminal notifications.
- **One-shot mode** reads the procedure file, strips its YAML frontmatter, and sends the body via `pi.sendUserMessage(body, { deliverAs: "followUp", expandPromptTemplates: false })`. The `expandPromptTemplates: false` flag is load-bearing — without it the sent text would re-dispatch as a command and recurse.
## Requirements
- The [`@narumitw/pi-goal`](https://www.npmjs.com/package/@narumitw/pi-goal) extension, and **Managed run RPC enabled** in its settings (`rpc.enabled: true` in `~/.pi/agent/pi-goal.json`, or `/goal` → settings).
- The audit procedure at `~/.pi/agent/prompts/finish_audit.md` (fresh-context reviewer fanout: `ponytail-review`, `security-review`, `review`). Edit `PROCEDURE_PATH` in the source if yours lives elsewhere.
## Install
Symlink the folder into Pi's user extension directory (Pi loads a subdirectory extension through its `index.ts` entry point) and reload:
```bash
ln -s ~/Projects/scripting/pi-extensions/finish-audit-goal ~/.pi/agent/extensions/finish-audit-goal
```
Then `/reload` in an active session.
## Limitations
- If a goal is already active, pi-goal's RPC refuses with `GOAL_ALREADY_EXISTS` (shown as an error notification). `/goal clear` first, or replace it from the `/goal` menu.
- The `pi-goal:start` channel is a third-party extension's protocol; a future pi-goal update could change it. Start failures surface as notifications rather than silent no-ops.
[Generated by AI]