Author SHA1 Message Date
wassnameandPI[Kimi K3] 6c86405841 Allow supervisor startup compaction
Co-Authored-By: PI[Kimi K3] <288921227+claudypoo@users.noreply.github.com>
2026-09-07 21:27:19 +08:00
wassnameandPI[Kimi K3] ee1ab3ec26 Start supervisors from loaded extension
Co-Authored-By: PI[Kimi K3] <288921227+claudypoo@users.noreply.github.com>
2026-09-07 21:16:05 +08:00
wassnameandPI[Kimi K3] ba2799a1d9 Pair supervisors before starting their model
Co-Authored-By: PI[Kimi K3] <288921227+claudypoo@users.noreply.github.com>
2026-09-07 19:35:05 +08:00
wassnameandPI[Kimi K3] c6a4307892 Keep failed supervisor panes for inspection
Co-Authored-By: PI[Kimi K3] <288921227+claudypoo@users.noreply.github.com>
2026-09-07 19:27:26 +08:00
wassnameandPI[Kimi K3] 2b620a0334 Revert bundled supervisor extensions
Co-Authored-By: PI[Kimi K3] <288921227+claudypoo@users.noreply.github.com>
2026-09-07 19:06:07 +08:00
wassnameandPI[Kimi K3] fc321a90fc Use HTTPS source for bundled supervisor
Co-Authored-By: PI[Kimi K3] <288921227+claudypoo@users.noreply.github.com>
2026-09-07 19:04:01 +08:00
wassnameandPI[Kimi K3] 9ee18c93f3 Bundle supervision and harden goal approval
Co-Authored-By: PI[Kimi K3] <288921227+claudypoo@users.noreply.github.com>
2026-09-07 19:02:08 +08:00
wassname 23b0104a1d docs: record visible supervisor handover 2026-09-07 14:26:09 +08:00
wassnameandPI[gpt-5.6-sol] 65ecf204db Record visible supervisor handover
Co-Authored-By: PI[gpt-5.6-sol] <288921227+claudypoo@users.noreply.github.com>
2026-09-06 22:37:00 +08:00
wassnameandPI[gpt-5.6-sol] 294fe80564 Use pi-supervise acknowledgement for visible workers
Co-Authored-By: PI[gpt-5.6-sol] <288921227+claudypoo@users.noreply.github.com>
2026-09-06 22:36:37 +08:00
wassnameandPI[gpt-5.6-sol] 1dc6146874 Allow a local pi-supervise extension for development
Co-Authored-By: PI[gpt-5.6-sol] <288921227+claudypoo@users.noreply.github.com>
2026-09-06 19:54:43 +08:00
wassnameandPI[gpt-5.6-sol] 7eb8b1f46b Treat stale pane close as successful cleanup
Co-Authored-By: PI[gpt-5.6-sol] <288921227+claudypoo@users.noreply.github.com>
2026-09-06 19:08:27 +08:00
wassnameandPI[gpt-5.6-sol] c5782ee2aa Finish visible supervisor pairing handshake
Co-Authored-By: PI[gpt-5.6-sol] <288921227+claudypoo@users.noreply.github.com>
2026-09-06 19:06:34 +08:00
wassnameandPi e299e84c5e Run supervisor bootstrap through the pane shell
Co-Authored-By: Pi <288921227+claudypoo@users.noreply.github.com>
2026-09-06 18:07:23 +08:00
wassnameandPi d56fc55242 Replace nested workers with visible supervisor session
Co-Authored-By: Pi <288921227+claudypoo@users.noreply.github.com>
2026-09-06 17:56:06 +08:00
wassname 4c6a7716b1 test: record non-child suite result 2026-09-06 15:59:09 +08:00
wassname cac2077456 docs: record intended supervision workflow 2026-09-06 15:54:19 +08:00
wassnameandPI[gpt-5.6] 5566e035f5 docs: refresh tracked text line counts
Co-Authored-By: PI[gpt-5.6] <288921227+claudypoo@users.noreply.github.com>
2026-09-06 15:41:07 +08:00
wassnameandPI[gpt-5.6-sol] 48e2247c00 Simplify nested goal supervision
Co-Authored-By: PI[gpt-5.6-sol] <288921227+claudypoo@users.noreply.github.com>
2026-09-06 13:36:12 +08:00
wassnameandPI[gpt-5.6-sol] 844099bdf0 Reconcile stale retained goal workers
Co-Authored-By: PI[gpt-5.6-sol] <288921227+claudypoo@users.noreply.github.com>
2026-09-06 12:28:17 +08:00
wassnameandPI[gpt-5.6-sol] 754ef89f13 Add reproducible file word-count audit
Co-Authored-By: PI[gpt-5.6-sol] <288921227+claudypoo@users.noreply.github.com>
2026-09-06 12:03:37 +08:00
wassnameandPI[gpt-5.6-sol] 6cfeaf44ee Compact the supervisor fork before work
Co-Authored-By: PI[gpt-5.6-sol] <288921227+claudypoo@users.noreply.github.com>
2026-09-05 21:31:46 +08:00
wassnameandPI[gpt-5.6-sol] 3eaaec9f5a Reduce supervisor context and recover terminal workers
Co-Authored-By: PI[gpt-5.6-sol] <288921227+claudypoo@users.noreply.github.com>
2026-09-05 21:22:17 +08:00
wassnameandPI[gpt-5.6-sol] 0a33ff2852 Add tracked file word counts
Co-Authored-By: PI[gpt-5.6-sol] <288921227+claudypoo@users.noreply.github.com>
2026-09-05 21:09:58 +08:00
wassnameandPI[gpt-5.6-sol] a44cd26c1d Sign the supervisor gate note
Co-Authored-By: PI[gpt-5.6-sol] <288921227+claudypoo@users.noreply.github.com>
2026-09-05 19:34:51 +08:00
wassnameandPI[gpt-5.6-sol] 96399ec3e4 Load the packaged worker in local runs
Co-Authored-By: PI[gpt-5.6-sol] <288921227+claudypoo@users.noreply.github.com>
2026-09-05 19:34:01 +08:00
wassnameandPI[gpt-5.6-sol] 96290c553b Fix nested supervisor lifecycle
Co-Authored-By: PI[gpt-5.6-sol] <288921227+claudypoo@users.noreply.github.com>
2026-09-05 19:32:43 +08:00
wassnameandPi/Codex 2852432d44 fix: package goal worker for nested discovery
Co-Authored-By: Pi/Codex <288921227+claudypoo@users.noreply.github.com>
2026-09-05 18:43:00 +08:00
wassnameandPI[goal-worker] 9fbc156860 Implement retained nested goal supervisor
Main coordinates a retained supervisor that manages the nested implementation worker and writes the only approval checkpoint.

Signed-off-by: PI[goal-worker] <288921227+claudypoo@users.noreply.github.com>
Co-authored-by: PI[goal-worker] <288921227+claudypoo@users.noreply.github.com>
2026-09-05 18:17:27 +08:00
wassnameandPi Codex f87b8aac2f Make the main session supervise a retained worker
Co-Authored-By: Pi Codex <288921227+claudypoo@users.noreply.github.com>
2026-09-05 17:12:24 +08:00
wassnameandPi Codex b32f4af11f Specify compacted supervisor fork and summary-only check-ins
Track 100k supervisor compaction target and measure cost and research usefulness separately.

Co-Authored-By: Pi Codex <288921227+claudypoo@users.noreply.github.com>
2026-09-05 16:15:30 +08:00
wassnameandPi Codex db18317109 Replace session-switch plan with retained subagent supervision
Fork at plan approval; use VCC updates for hourly, idle, and sign-off reviews. Keep normal pi-subagents controls.

Co-Authored-By: Pi Codex <288921227+claudypoo@users.noreply.github.com>
2026-09-05 16:13:55 +08:00
wassnameandPi Codex 4db690a300 Plan switchable goal steward
Co-Authored-By: Pi Codex <288921227+claudypoo@users.noreply.github.com>
2026-09-05 15:57:02 +08:00
wassnameandPi Codex 49eb68e813 Stabilize self-counting line audit
Co-Authored-By: Pi Codex <288921227+claudypoo@users.noreply.github.com>
2026-09-05 15:26:30 +08:00
wassnameandPi Codex 18381bcda9 Include audit artifacts in line counts
Co-Authored-By: Pi Codex <288921227+claudypoo@users.noreply.github.com>
2026-09-05 15:25:16 +08:00
wassnameandPi Codex ead336c957 Add pi-goals line-count table
Co-Authored-By: Pi Codex <288921227+claudypoo@users.noreply.github.com>
2026-09-05 15:23:58 +08:00
wassnameandPi Codex 9ad4cee084 Record pi-goals text line counts
Co-Authored-By: Pi Codex <288921227+claudypoo@users.noreply.github.com>
2026-09-05 15:23:20 +08:00
wassnameandPi Codex bf50d9bbc8 Use TUI-style goals subcommands
Stop steward checkpoints after all goals close.

Co-Authored-By: Pi Codex <288921227+claudypoo@users.noreply.github.com>
2026-09-05 15:17:27 +08:00
wassnameandPi Codex 46cfd537f0 Add persistent pi-subagents goal steward
Co-Authored-By: Pi Codex <288921227+claudypoo@users.noreply.github.com>
2026-09-05 12:20:17 +08:00
33 changed files with 1896 additions and 1165 deletions
+8
View File
@@ -14,3 +14,11 @@ Run `npm test` before a commit. It includes unit and flow tests plus the RPC rev
Run `/goals <objective>` in that pane. Tmux checks the rendered menu, editor focus, widget, and keyboard handling. RPC does not render the terminal UI.
- `pi -p` has no UI, so it cannot test `Ready`, `Refine`, `Edit`, or `Cancel`.
## Intended supervision workflow
I already have pi-intercom-supervisor, but thought using pi-subagents could make it simpler. The idea is that the user makes a plan as in pi-goals, but on this branch, instead of a naive stateless subagent, we 1) fork, 2) compact, and 3) make it a supervisor with a prompt as in pi-intercom-supervisor. The supervisor is cheap because it sees only high-level material, which costs fewer tokens. It has good judgement because it sees a) compacted planning context, b) the plan, and c) summarised context (for example, my modified pi-vcc). This lets it operate read-only and steer the worker without losing track. It also compacts every 100k tokens to keep it cheap and high-level.
I am now thinking the subagent implementation may be too difficult. To keep the plan and forking, this branch of pi-goals could make another Pi session, perhaps using the fork explicitly, and use pi-intercom or pi-messenger to communicate with it. The user can switch to it, or Herdr could open it automatically.
-- wassname
+39 -72
View File
@@ -1,103 +1,70 @@
# pi-goals
Make a short list of goals in one Markdown plan file. This is easy to review, and a subagent can check whether each goal is complete.
Plan in one Pi session, then do the work there while a stronger visible Pi session supervises it.
The plan file looks like this:
## How it works
```md
## <short plan title>
1. `/goals <objective>` creates `.pi/plan/<session_id>-vN.md` and enters read-only plan mode.
2. Pi asks only material questions, writes the plan, and shows **Ready / Refine / Edit / Cancel**.
3. **Ready** opens a second Herdr pane. The new Pi session explicitly forks the planning session and compacts that fork.
4. The original session becomes the implementation worker. It keeps the full conversation and normal tools.
5. The fork becomes a read-only supervisor. `pi-supervise` gives it compact worker views and carries its instructions to the worker through `pi-intercom`.
6. The supervisor compacts again when its context reaches 100k tokens.
7. The supervisor records a private approval only after it sees a stopped worker, no active work, a clean commit, evidence, and saved verification output. `CompleteGoal` checks that approval against the exact plan block and Git tree before it ticks `[x]`.
<context: one short paragraph. What the human wants and why.>
### User-visible result
<one concrete sentence naming the final artifact or behavior the human will inspect>
### User voice
- │ "<the human's requirement, quoted in full word for word (with spelling fixes)>"
### Goals
1. [ ] goal: <one short judgeable imperative outcome>
- subtle failure mode: <a way this could look done but isn't>
- discriminator: <the concrete observation that tells real success from that failure>
- tasks:
1. [ ] <subtask>
- evidence: (empty until sign-off)
### Future work / out of scope
### Log
### Interview
### Learnings
### Papercuts - problems, gotchas, suggestions
```
![the widget: live goals from the session's plan file, with the active goal's open subtasks](media/screenshot.png)
## Related work
Like [pi-milestones](https://github.com/Neuron-Mr-White/UniPi/tree/main/packages/milestone) and
[burneikis/pi-plan](https://github.com/burneikis/pi-plan), it guides rather than guards. The
reminder cadence is copied from [tintinweb/pi-tasks](https://github.com/tintinweb/pi-tasks) and the
resync-after-compaction from [tmonk/pi-goal-x](https://github.com/tmonk/pi-goal-x).
The two Pi sessions are visible. You can switch to the supervisor pane and talk to it directly.
## Install
This branch requires Herdr 0.7.5 or newer and these Pi packages:
```bash
pi install npm:@wassname2/pi-goals
pi install npm:@wassname2/pi-supervise
pi install npm:pi-intercom
```
Or for development:
For a local checkout:
```bash
git clone https://github.com/wassname/pi-goals && cd pi-goals && npm install
pi -e ./src/index.ts
pi -e .
```
## Use
Run Pi from the Git repository that the plan will change. **Ready** fails if the current directory is not inside a Git repository; this prevents approval from checking the wrong repository.
```
/goals CSV export for the report view
## Commands
```text
/goals <objective> create a new plan
/goals model <model> select the visible supervisor model
/goals model use Pi's current default model
/goals clear close the supervisor pane and disconnect the plan
```
`/goals` enters plan mode and starts a conversation; the objective is an optional seed. From there:
`/goals clear` keeps the plan file. Starting another plan also keeps older versions.
1. Plan. The agent explores read-only and drafts the plan.
2. Review. After Pi settles, the full plan is printed in the transcript. Check that User-visible
result names the final artifact or behavior you expect. The menu offers Ready, Refine, Edit, or
Cancel. Refine collects short notes. Edit opens the full plan in Pi's editor.
3. Work. Ready is the only review action that starts work. The agent ticks subtasks, appends to
`## Log` and `## Learnings`, fills `evidence:`, and calls `CompleteGoal` when a discriminator is
satisfied. Every human reply and Refine note in plan mode is saved verbatim under `## Interview`.
After eight turns without a change above `## Log`, the working set is sent back with a short upkeep
reminder.
## Plan format
Other commands: `/goals --clear` disconnects this session from its active plan, preserving the
versioned file on disk; `/goals --auto [minutes|off]` continues active goals after the agent settles
and then on that interval. It pauses after two automatic wakes with no working-plan change; `/goals
--judge <model-ref>` picks a sign-off judge model (default: your current session model, else pi's
default). The `--` prefix
keeps ordinary objectives such as `judge model quality` from being parsed as commands.
A goal is a checkbox line whose text starts with `goal:`:
## Prompts
```md
1. [ ] goal: Produce the report
- subtle failure mode: the report exists but uses stale data
- discriminator: the report cites the current input and the saved check confirms it
- verify: `just verify`
- evidence: (empty until sign-off)
```
All model-facing text lives in [`src/prompts.ts`](src/prompts.ts), in flow order.
The worker saves verification output in a nonempty repository file, adds that path to evidence, and commits it. The supervisor calls `ApproveGoal` with the inspected path; the worker then calls `CompleteGoal` with the exact goal text.
## Develop
## Development
```bash
pi -e ./src/index.ts # load locally
npm test # all unit, flow, and Pi RPC tests
npm run test:rpc # Pi RPC review flow with a local offline model
npm test
npm run typecheck
npm run lint
```
## License
`test/rpc-review.test.ts` runs the planning review flow through Pi's real RPC protocol with a local deterministic model. The Herdr launcher and visible supervisor bootstrap have focused tests; use a real Herdr session for the final two-pane check.
MIT
-- PI[gpt-5.6-sol]
+116
View File
@@ -0,0 +1,116 @@
# Visible supervisor handover
## Objective
Replace pi-goals' nested pi-subagents worker with two visible Pi sessions:
1. The main session plans with the user, then becomes the implementation worker.
2. On Ready, pi-goals explicitly forks the planning session into a Herdr pane.
3. Only the fork is compacted. It becomes the stronger read-only supervisor.
4. pi-supervise and pi-intercom connect the supervisor to the worker.
5. The worker starts only after the real pi-supervise `pair`/`paired` acknowledgment.
6. The supervisor retains the plan, compact planning context, and concise worker views. It can steer the worker and approve a completed goal.
7. The supervisor compacts near 100k tokens.
Keep this minimal. Reuse pi-supervise's intercom protocol instead of building a second orchestration layer.
## User preferences
- The primary session must do the implementation. Other agents may test or review it, but must not own core development.
- Avoid relaying implementation decisions through multiple agents.
- Herdr should open the supervisor automatically and let the user switch to it.
- Persist configurable models for three stages:
- planning: strongest model, for example Fable 5.1 or Astra;
- supervision: for example Sol or Opus;
- implementation: for example Terra, Sonnet, Kimi K3, DeepSeek Pro, or GLM 5.3.
- Validate model IDs through Pi. Do not hard-code a model list.
- Switch the main session to the planning model when planning starts and to the worker model only after pairing succeeds. Launch the fork with the supervisor model.
## Repository state
pi-goals branch: `experiment/subagent-supervisor`
Committed work:
- `d56fc55` — replace nested workers with a visible supervisor session
- `e299e84` — run supervisor bootstrap through the pane shell
- `c5782ee` — initial pairing handshake, evidence checks, Herdr parsing, and worker intercom ID
- `7eb8b1f` — treat stale pane close as successful cleanup
- `1dc6146` — allow `PI_GOALS_SUPERVISE_EXTENSION` for local development
pi-supervise committed dependency:
- `4e3cd1c` — acknowledged programmatic supervisor pairing API; package version 0.0.4
Uncommitted pi-goals files:
- `src/intercom.ts`
- `src/supervise.ts`
- `test/intercom.test.ts` (new)
Uncommitted pi-supervise file:
- `src/index.ts`
Inspect these diffs before editing. They are a partial design-B refactor and have not passed the real workflow.
## Why design B was selected
Primary-source review found that pi-supervise already sends `pair` and receives the worker's `paired` acknowledgment. The custom `pi-goals/visible-supervisor/v1` intercom namespace duplicated that acknowledgment and introduced another registration and connection race.
Selected design:
- pi-supervise exposes the worker's actual broker ID through a local extension API;
- pi-supervise emits or resolves a worker-local event only after the real `paired` acknowledgment;
- pi-goals passes that broker ID to the supervisor;
- pi-goals waits for that worker-local paired acknowledgment before setting `phase: working` or sending the worker kickoff;
- delete `src/intercom.ts` and custom supervisor-ready messages if the partial diff has not already completed that deletion;
- support either extension load order by using pi-intercom/pi-supervise registry-ready events idempotently.
Do not use pi-intercom `project-agent.ts` as another lifecycle. It opens a generic Pi pane and polls broker presence but does not supply the required fork, extensions, model, or pairing semantics.
## Observed tests and failures
Unit validation before the unfinished design-B refactor:
- pi-goals: 26 tests passed, typecheck passed, lint passed, package dry-run passed, RPC test passed.
- pi-supervise: 97 tests passed and package dry-run passed.
Real Herdr observations:
1. The initial smoke loaded pi-supervise directly from source and did not exercise pi-goals' actual Ready command.
2. A later actual `/goals` → Ready run failed before pane creation because pi-goals emitted `intercom:extension-register` before pi-intercom installed its listener.
3. A local uncommitted registry-ready re-registration fix moved the real path farther: Ready created supervisor pane `w8:p1F` through `supervisorCommand`.
4. That run then timed out waiting for the duplicate custom `supervisor-ready` message. This led to design B.
5. The supervisor exited before its transcript was preserved. Do not infer that pi-supervise pairing succeeded.
The real end-to-end workflow has not passed.
## Next work
1. Read the uncommitted diffs in both repositories and finish or simplify design B.
2. Add focused tests:
- pi-supervise local API works whether pi-goals loads before or after pi-supervise;
- no `phase: working` or kickoff before actual `paired`;
- duplicate `paired` is idempotent.
3. Run the actual pi-goals path, not a substitute command:
- start worker with pi-goals and pi-intercom;
- enter `/goals`, draft a plan, and select Ready;
- use `PI_GOALS_SUPERVISE_EXTENSION=/home/code/.pi/agent/git/github.com/wassname/pi-supervise/src/index.ts` until 0.0.4 is published;
- positively observe fork-only compaction, actual pairing acknowledgment, then worker kickoff;
- preserve supervisor stdout/stderr and session JSONL before cleanup on every failure;
- observe supervisor monitoring or steering;
- complete real evidence at a clean commit, approve it, call CompleteGoal, and close the pane.
4. Commit the lifecycle separately once the real path passes.
5. Add the three persisted model settings in a separate commit.
6. Run tests, typecheck, lint, package dry-runs, real RPC tests, and a fresh read-only review.
## Known packaging constraint
`src/herdr.ts` defaults to `npm:@wassname2/pi-supervise@0.0.4`. Version 0.0.4 is not publicly published. Do not publish without explicit editorial approval. Local testing must use `PI_GOALS_SUPERVISE_EXTENSION`.
## Important lifecycle bug discovered in this session
`/goals clear` cleared extension state but left the current model request under the previously injected coordinator system instruction. `/reload` did not remove it. A fresh ordinary Pi session is required for direct implementation. The redesign should avoid leaving a session unable to resume ordinary work after clear.
-- PI[gpt-5.6-sol]
+2 -189
View File
File diff suppressed because it is too large Load Diff
+5 -3
View File
@@ -1,7 +1,7 @@
{
"name": "@wassname2/pi-goals",
"version": "0.2.2",
"description": "One plan file per session: set goals in plan mode, work them, sign off only when a read-only judge checks the evidence.",
"description": "Plan in one Pi session, then work under a visible forked supervisor.",
"author": "wassname",
"license": "MIT",
"type": "module",
@@ -18,7 +18,9 @@
"proof",
"uat",
"evidence",
"judge"
"supervisor",
"pi-intercom",
"herdr"
],
"peerDependencies": {
"@earendil-works/pi-coding-agent": "*",
@@ -42,11 +44,11 @@
"lint:fix": "biome check --fix src/ test/"
},
"devDependencies": {
"@biomejs/biome": "^2.4.8",
"@earendil-works/pi-coding-agent": "^0.84.1",
"@types/node": "^20.0.0",
"typebox": "^1.3.7",
"typescript": "^5.0.0",
"@biomejs/biome": "^2.4.8",
"vitest": "^4.0.18"
},
"pi": {
@@ -0,0 +1,31 @@
# Goal steward validation
## Observations
- Unit, flow, type, and lint checks passed. [`20260905_validation.log`](20260905_validation.log) says:
> Test Files 8 passed (8)
> Tests 36 passed (36)
> Checked 12 files in 14ms. No fixes applied.
- A real Pi 0.85.0 process loaded pi-subagents 0.65.1, pi-goals, and a runtime `goal-steward` agent. It spawned one review and resumed that run for sign-off. [`20260905_steward-probe.json`](20260905_steward-probe.json) records two distinct run IDs:
> "runId": "4e9dc0c0-385b-4eb9-a060-ced7dc7cb6cc"
> "runId": "f6115c82-31de-499f-ab78-145dde0c51c0"
- The second review recalled a token that appeared only in the first review request. This is direct evidence that resume retained the steward conversation:
> "Persistence lineage token: amber-731."
- The sign-off review read `report.txt` and accepted the evidence:
> "file exists and contains exactly 'PROBE_PASS' as required. Failure mode (empty report) is ruled out."
## Test environment finding
The repository's older local Pi 0.84.1 install could not launch a pi-subagents background child because it did not include `@earendil-works/chord` and `@earendil-works/pi-server`. The successful probe used an isolated npm install of Pi 0.85.0. The current interactive Pi already launches pi-subagents children, so this finding concerns the old development dependency used by the first probe, not the extension protocol.
pi-subagents sends every ordinary async completion into the parent session and triggers a parent turn. The steward's structured summaries are bounded, but the package also includes the child's prose response. There is no public silent-completion option in pi-subagents 0.65.1. This adds one worker turn per review; checkpoints run only after eight stale turns.
— Pi/Codex
@@ -0,0 +1,91 @@
# Nested supervisor validation
2026-09-05T19:31:55+08:00
$ npm test
> @wassname2/pi-goals@0.2.2 test
> vitest run
RUN v4.1.9 /home/code/.pi/agent/git/github.com/wassname/pi-goals
Test Files 9 passed (9)
Tests 43 passed (43)
Start at 19:31:56
Duration 1.60s (transform 709ms, setup 0ms, import 1.64s, tests 1.76s, environment 1ms)
$ npm run typecheck
> @wassname2/pi-goals@0.2.2 typecheck
> tsc --noEmit
$ npm run lint
> @wassname2/pi-goals@0.2.2 lint
> biome check src/ test/
Checked 15 files in 29ms. No fixes applied.
$ git diff --check
(no output)
$ npm pack --dry-run
npm notice
npm notice 📦 @wassname2/pi-goals@0.2.2
npm notice Tarball Contents
npm notice 5.8kB README.md
npm notice 1.1kB agents/goal-worker.md
npm notice 1.5kB package.json
npm notice 4.0kB src/approval.ts
npm notice 34.6kB src/index.ts
npm notice 13.6kB src/prompts.ts
npm notice 5.9kB src/supervisor-runtime.ts
npm notice 7.3kB src/worker.ts
npm notice Tarball Details
npm notice name: @wassname2/pi-goals
npm notice version: 0.2.2
npm notice filename: wassname2-pi-goals-0.2.2.tgz
npm notice package size: 23.1 kB
npm notice unpacked size: 73.7 kB
npm notice shasum: 579debe3de67b56116e51da6cac46c14511bdd07
npm notice integrity: sha512-f5S39K2J3kjIX[...]cuwx2WFIeBBAQ==
npm notice total files: 8
npm notice
wassname2-pi-goals-0.2.2.tgz
$ git diff --stat 2852432
README.md | 13 +-
agents/goal-worker.md | 2 +-
.../20260905_nested-supervisor-validation.txt | 70 ++++------
src/approval.ts | 27 +++-
src/index.ts | 153 +++++++++++++++------
src/prompts.ts | 9 +-
src/supervisor-runtime.ts | 81 ++++++++---
src/worker.ts | 36 +++--
test/goals-flow.test.ts | 54 +++++++-
test/prompts.test.ts | 2 +-
test/supervisor-runtime.test.ts | 32 ++++-
test/worker.test.ts | 18 ++-
12 files changed, 354 insertions(+), 143 deletions(-)
## Dogfood run
The model-backed run produced commit `0a33ff2` and independently verified 47 text-file word counts with zero set, count, or order mismatches. Approval then deadlocked:
> Cannot approve while the retained worker is pending.
The worker process was terminal, but its model result was `Request was aborted`; the completion event did not clear retained state. A supervisor resume also failed because `subagent_supervisor` was unavailable in its strict tool list.
Usage from the run status files:
| agent | turns | new tokens | cached reads | reported cost |
| --- | ---: | ---: | ---: | ---: |
| supervisor, including recovery | 42 | 169,288 | 2,670,336 | $2.35 |
| worker | 17 | 67,803 | 812,544 | $0.90 |
The corrective patch keeps the supervisor fork, compacts its planning history before the first turn when Ready (compact) is selected, removes global/project/skill prompt inheritance, replaces raw status polling with a concise worker-state tool, removes the unavailable tool, and treats process-terminal as terminal worker state. Unit tests pass; a second model-backed run is still required.
-- PI[gpt-5.6-sol]
@@ -0,0 +1,52 @@
text/plain .gitignore
text/plain AGENTS.md
text/plain ARCHIVED.md
text/plain README.md
text/plain agents/pi-goals-worker-v1.md
application/json biome.json
text/plain docs/reviews/goals_menu2.md
text/plain docs/reviews/goals_menu2_r2.md
text/plain docs/reviews/pi-goals-grok-4-6-retry.md
text/plain docs/reviews/pi-goals-kimi-k3.md
text/plain docs/reviews/review.md
text/plain docs/slop/audit/20260826_pi-plan-aligned-planning.md
text/plain docs/slop/plans/20260706_plan-flow-and-judge-review.md
text/plain docs/slop/plans/20260826_pi-plan-aligned-planning.md
text/plain docs/spec/2026-06-15_pi-goals.md
text/plain docs/spec/2026-06-29_complete-goal-fail-forward.md
text/plain docs/spec/2026-08-14_per-session-plan.md
image/png media/screenshot.png
application/json package-lock.json
application/json package.json
text/x-shellscript scripts/check-judge-footprint.sh
text/x-shellscript scripts/check-stale-fixmes.sh
text/x-diff scripts/inconclusive-fail-forward.diff
text/x-diff scripts/stale-fixme-removal.diff
text/plain slop/audits/20260905_goal-steward-validation.md
text/plain slop/audits/20260905_nested-supervisor-validation.txt
text/plain slop/audits/20260905_pi-goals-file-types.txt
text/plain slop/audits/20260905_pi-goals-line-count-table.md
text/plain slop/audits/20260905_pi-goals-text-line-counts.txt
application/json slop/audits/20260905_steward-probe.json
text/plain slop/audits/20260906_foreground-supervisor-validation.txt
text/plain slop/audits/20260906_nested-runtime-smoke.md
text/plain slop/audits/20260906_nonchild-npm-test.txt
text/plain slop/plans/20260905_goal-steward.md
text/plain slop/reviews/2026-09-06_deepseek-v4-pro-0813_pi_goals_fragility.md
text/plain slop/reviews/20260906_foreground-worker-review.md
application/javascript src/approval.ts
application/javascript src/index.ts
application/javascript src/prompts.ts
application/javascript src/supervisor-runtime.ts
application/javascript src/worker.ts
application/javascript test/append-log.test.ts
application/javascript test/fixtures/offline-model.ts
application/javascript test/fold.test.ts
application/javascript test/goals-flow.test.ts
application/javascript test/package-agent.test.ts
application/javascript test/prompts.test.ts
application/javascript test/rpc-review.test.ts
application/javascript test/supervisor-runtime.test.ts
application/javascript test/tick-goal.test.ts
application/javascript test/worker.test.ts
application/json tsconfig.json
@@ -0,0 +1,67 @@
# pi-goals tracked-text line counts
Scope: Git-tracked files at this repository snapshot. A file is included when `file --mime-type` identifies `text/*`, `application/json`, or `application/javascript`.
Excluded: `media/screenshot.png` is binary (`image/png`); `package-lock.json` is an npm-generated dependency lockfile. No other tracked files are excluded.
Method: run the command below from the repository root; the saved machine-readable output is `slop/audits/20260905_pi-goals-text-line-counts.txt`.
```sh
git ls-files -z | while IFS= read -r -d '\0' f; do case "$f" in media/screenshot.png|package-lock.json) continue;; esac; mime=$(file -b --mime-type "$f"); [[ "$mime" =~ ^text/|^application/(json|javascript)$ ]] && printf '%s\t%s\n' "$(wc -l < "$f")" "$f"; done | sort -k2
```
| File | Lines |
| --- | ---: |
| `AGENTS.md` | 24 |
| `agents/pi-goals-worker-v1.md` | 22 |
| `ARCHIVED.md` | 3 |
| `biome.json` | 23 |
| `docs/reviews/goals_menu2.md` | 65 |
| `docs/reviews/goals_menu2_r2.md` | 21 |
| `docs/reviews/pi-goals-grok-4-6-retry.md` | 30 |
| `docs/reviews/pi-goals-kimi-k3.md` | 40 |
| `docs/reviews/review.md` | 61 |
| `docs/slop/audit/20260826_pi-plan-aligned-planning.md` | 25 |
| `docs/slop/plans/20260706_plan-flow-and-judge-review.md` | 33 |
| `docs/slop/plans/20260826_pi-plan-aligned-planning.md` | 53 |
| `docs/spec/2026-06-15_pi-goals.md` | 275 |
| `docs/spec/2026-06-29_complete-goal-fail-forward.md` | 71 |
| `docs/spec/2026-08-14_per-session-plan.md` | 67 |
| `.gitignore` | 6 |
| `package.json` | 65 |
| `README.md` | 139 |
| `scripts/check-judge-footprint.sh` | 43 |
| `scripts/check-stale-fixmes.sh` | 14 |
| `scripts/inconclusive-fail-forward.diff` | 104 |
| `scripts/stale-fixme-removal.diff` | 30 |
| `slop/audits/20260905_goal-steward-validation.md` | 31 |
| `slop/audits/20260905_nested-supervisor-validation.txt` | 91 |
| `slop/audits/20260905_pi-goals-file-types.txt` | 52 |
| `slop/audits/20260905_pi-goals-line-count-table.md` | 67 |
| `slop/audits/20260905_pi-goals-text-line-counts.txt` | 50 |
| `slop/audits/20260905_steward-probe.json` | 15 |
| `slop/audits/20260906_foreground-supervisor-validation.txt` | 53 |
| `slop/audits/20260906_nested-runtime-smoke.md` | 31 |
| `slop/audits/20260906_nonchild-npm-test.txt` | 33 |
| `slop/plans/20260905_goal-steward.md` | 37 |
| `slop/reviews/2026-09-06_deepseek-v4-pro-0813_pi_goals_fragility.md` | 65 |
| `slop/reviews/20260906_foreground-worker-review.md` | 20 |
| `src/approval.ts` | 115 |
| `src/index.ts` | 736 |
| `src/prompts.ts` | 191 |
| `src/supervisor-runtime.ts` | 179 |
| `src/worker.ts` | 186 |
| `test/append-log.test.ts` | 17 |
| `test/fixtures/offline-model.ts` | 18 |
| `test/fold.test.ts` | 63 |
| `test/goals-flow.test.ts` | 596 |
| `test/package-agent.test.ts` | 23 |
| `test/prompts.test.ts` | 33 |
| `test/rpc-review.test.ts` | 116 |
| `test/supervisor-runtime.test.ts` | 153 |
| `test/tick-goal.test.ts` | 32 |
| `test/worker.test.ts` | 119 |
| `tsconfig.json` | 15 |
| **Total** | **4351** |
-- PI[gpt-5.6]
@@ -0,0 +1,50 @@
24 AGENTS.md
22 agents/pi-goals-worker-v1.md
3 ARCHIVED.md
23 biome.json
65 docs/reviews/goals_menu2.md
21 docs/reviews/goals_menu2_r2.md
30 docs/reviews/pi-goals-grok-4-6-retry.md
40 docs/reviews/pi-goals-kimi-k3.md
61 docs/reviews/review.md
25 docs/slop/audit/20260826_pi-plan-aligned-planning.md
33 docs/slop/plans/20260706_plan-flow-and-judge-review.md
53 docs/slop/plans/20260826_pi-plan-aligned-planning.md
275 docs/spec/2026-06-15_pi-goals.md
71 docs/spec/2026-06-29_complete-goal-fail-forward.md
67 docs/spec/2026-08-14_per-session-plan.md
6 .gitignore
65 package.json
139 README.md
43 scripts/check-judge-footprint.sh
14 scripts/check-stale-fixmes.sh
104 scripts/inconclusive-fail-forward.diff
30 scripts/stale-fixme-removal.diff
31 slop/audits/20260905_goal-steward-validation.md
91 slop/audits/20260905_nested-supervisor-validation.txt
52 slop/audits/20260905_pi-goals-file-types.txt
67 slop/audits/20260905_pi-goals-line-count-table.md
50 slop/audits/20260905_pi-goals-text-line-counts.txt
15 slop/audits/20260905_steward-probe.json
53 slop/audits/20260906_foreground-supervisor-validation.txt
31 slop/audits/20260906_nested-runtime-smoke.md
33 slop/audits/20260906_nonchild-npm-test.txt
37 slop/plans/20260905_goal-steward.md
65 slop/reviews/2026-09-06_deepseek-v4-pro-0813_pi_goals_fragility.md
20 slop/reviews/20260906_foreground-worker-review.md
115 src/approval.ts
736 src/index.ts
191 src/prompts.ts
179 src/supervisor-runtime.ts
186 src/worker.ts
17 test/append-log.test.ts
18 test/fixtures/offline-model.ts
63 test/fold.test.ts
596 test/goals-flow.test.ts
23 test/package-agent.test.ts
33 test/prompts.test.ts
116 test/rpc-review.test.ts
153 test/supervisor-runtime.test.ts
32 test/tick-goal.test.ts
119 test/worker.test.ts
15 tsconfig.json
+16
View File
@@ -0,0 +1,16 @@
{
"first": {
"runId": "4e9dc0c0-385b-4eb9-a060-ced7dc7cb6cc",
"decision": {
"verdict": "let_run",
"summary": "Plan reviewed for approved work session. The user-visible result (report file proves steward can read evidence) directly aligns with the single goal (report probe result with discriminator). The report.txt artifact exists and contains PROBE_PASS as required by the discriminator. No work steps are pending; the probe is complete. No drift, missing steps, or failure modes detected. Plan may proceed without adjustment."
}
},
"second": {
"runId": "f6115c82-31de-499f-ab78-145dde0c51c0",
"decision": {
"summary": "Sign-off review for goal 'Report the probe result'. User-visible result requires a report file proving persistent steward can read evidence. Discriminator: report.txt contains PROBE_PASS. Inspected artifact at /tmp/pi-goals-steward-probe-work/report.txt—file exists and contains exactly 'PROBE_PASS' as required. Failure mode (empty report) is ruled out. Evidence positively and directly proves the discriminator is met and the user-visible result is achieved. Persistence lineage token: amber-731.",
"verdict": "accept"
}
}
}
@@ -0,0 +1,53 @@
$ npm test
> @wassname2/pi-goals@0.2.2 test
> vitest run
RUN v4.1.9 /home/code/.pi/agent/git/github.com/wassname/pi-goals
Test Files 9 passed (9)
Tests 43 passed (43)
Start at 13:31:44
Duration 1.61s (transform 1.12s, setup 0ms, import 2.36s, tests 2.13s, environment 1ms)
$ npm run typecheck
> @wassname2/pi-goals@0.2.2 typecheck
> tsc --noEmit
$ npm run lint
> @wassname2/pi-goals@0.2.2 lint
> biome check src/ test/
Checked 15 files in 18ms. No fixes applied.
$ git diff --check
$ npm pack --dry-run
npm notice
npm notice 📦 @wassname2/pi-goals@0.2.2
npm notice Tarball Contents
npm notice 6.1kB README.md
npm notice 969B agents/pi-goals-worker-v1.md
npm notice 1.5kB package.json
npm notice 4.0kB src/approval.ts
npm notice 34.8kB src/index.ts
npm notice 13.6kB src/prompts.ts
npm notice 8.3kB src/supervisor-runtime.ts
npm notice 7.8kB src/worker.ts
npm notice Tarball Details
npm notice name: @wassname2/pi-goals
npm notice version: 0.2.2
npm notice filename: wassname2-pi-goals-0.2.2.tgz
npm notice package size: 24.1 kB
npm notice unpacked size: 76.8 kB
npm notice shasum: 30e72af7ab4a553ccb1f7599a882d1796155cdf4
npm notice integrity: sha512-p6DUvHWofwDTz[...]IZmG7JiD+/wFw==
npm notice total files: 8
npm notice
wassname2-pi-goals-0.2.2.tgz
@@ -0,0 +1,31 @@
# Nested foreground runtime smoke
Command:
```bash
node /tmp/pi-goals-real-rpc-smoke.mjs
```
Result: PASS.
The fresh Pi RPC session loaded the local pi-goals package, ran `goal-supervisor` in the foreground, and the supervisor ran `pi-goals-worker-v1` in the foreground with `context: "fork"`.
Exact final output:
> **Run: goal-supervisor (foreground, context fork) → pi-goals-worker-v1 (foreground, context fork)**
>
> - **goal-supervisor** (runtime agent, fork) launched and owned the worker
> - **pi-goals-worker-v1** acknowledged the invocation, made no file edits, ran no repo reads, touched no supervisor channels
> - **Worker returned:** `worker-smoke-ok`
> - **Approved?** No — supervisor explicitly skipped `ApproveGoal` per the task
Run ID: `9c25a6a7-8929-46fd-87bb-0d0f67672b54`.
Saved runtime artifacts:
- `/home/code/.pi/agent/sessions/--home-code-.pi-agent-git-github.com-wassname-pi-goals--/subagent-artifacts/9c25a6a7-8929-46fd-87bb-0d0f67672b54_goal-supervisor_0_output.md`
- `/home/code/.pi/agent/sessions/--home-code-.pi-agent-git-github.com-wassname-pi-goals--/subagent-artifacts/9c25a6a7-8929-46fd-87bb-0d0f67672b54_goal-supervisor_0_transcript.jsonl`
This smoke tested nested discovery and foreground execution. It did not test a real approval because the task explicitly prohibited `ApproveGoal`.
-- PI[gpt-5.6-sol]
@@ -0,0 +1,33 @@
# npm test outside the subagent-child harness
Command run from `/home/code/.pi/agent/git/github.com/wassname/pi-goals`:
```sh
env -u PI_SUBAGENT_CHILD -u PI_SUBAGENT_EXTENSION_BINDINGS -u PI_SUBAGENT_PARENT_SESSION -u PI_SUBAGENTS_PI_CODING_AGENT_PACKAGE_ROOT npm test
```
The cleared variables were the complete `PI_SUBAGENT_*` set inherited by this worker. `PI_SUBAGENT_CHILD=1` makes `isSupervisorProcess()` false in `src/index.ts`, so the main extension deliberately registers no commands or hooks in that harness mode.
Exact output:
```text
> @wassname2/pi-goals@0.2.2 test
> vitest run
RUN v4.1.9 /home/code/.pi/agent/git/github.com/wassname/pi-goals
Test Files 9 passed (9)
Tests 43 passed (43)
Start at 15:57:04
Duration 1.27s (transform 407ms, setup 0ms, import 1.41s, tests 1.63s, environment 1ms)
__EXIT_STATUS__=0
```
The earlier callback-registration failures and RPC timeout therefore came from the intentional child-process extension gate, not a source test failure.
-- PI[gpt-5.6]
@@ -0,0 +1,18 @@
# visible-supervisor follow-up
## committed changes
- pi-goals `294fe80` removes the duplicate `pi-goals/visible-supervisor/v1` channel. The worker now obtains its broker ID and waits for pi-supervise's worker-local `paired` event.
- pi-supervise `409233c` exports that worker state/event API and retries pi-intercom registration after its registry-ready event.
## observed Herdr run
A real `/goals` → Ready run created the fork pane. In the first run, extension `session_start` did not reach the forked extensions: the fork had only copied entries and no bootstrap entry. The supervisor therefore did not pair. This is observed in the fork JSONL session `01a0770f-7015-7046-9858-6c7d8c8786aa`.
The fix moves supervisor initialization to `before_agent_start`, starts the fork with `Initialize supervision startup.`, and loads pi-supervise before pi-goals. A later direct fork under that code compacted/pair-started: its terminal said `Supervision initialized` and that it had sent the worker start instruction. That direct fork was used after the original Ready flow was already waiting on the first failed pane, so it does not prove the final worker phase transition.
## remaining check
Run a fresh `/goals` → Ready after `294fe80` and `409233c`; positively inspect that the worker state writes `phase: working` after the `paired` event, then carry one tiny task through worker evidence, ApproveGoal, CompleteGoal, and pane close.
-- PI[gpt-5.6-sol]
+37
View File
@@ -0,0 +1,37 @@
# Persistent goal steward
> "ideally the supervisor has the high level planning and goal context, doesn't get overloaded and have to compact, is cheap as it doesn't use many tokens (high level only)"
>
> "try again with more thought using pi-subagents much more to simplify out code and rely on that so our code is simple"
- [x] goal: A cheap read-only steward keeps the goal context across reviews
- [x] register one `goal-steward` agent through the public pi-subagents event bus
- [x] start it with fresh context at Ready and resume its latest saved run at checkpoints
- [x] send the plan path and a bounded progress delta; require the steward to reread the plan
- failure modes: every review starts fresh; the steward receives the full worker transcript; the steward can edit; reload loses its run
- deliverable: tests show one spawn followed by resume, a saved latest run ID, read-only tools, bounded review prompts, and reload recovery
- evidence: [`../audits/20260905_steward-probe.json`](../audits/20260905_steward-probe.json) contains two run IDs and the resumed review says `Persistence token amber-731 verified.`
- [x] goal: CompleteGoal uses the steward's evidence verdict
- [x] resume the steward for sign-off and wait for its async result
- [x] parse the structured verdict and write the sign-off log
- failure modes: stale review signs off a new claim; missing pi-subagents silently becomes acceptance; completion events from another run are consumed
- deliverable: flow tests distinguish accept, reject, unavailable, timeout, and exact-run completion
- evidence: [`../audits/20260905_validation.log`](../audits/20260905_validation.log) says `Tests 36 passed (36)` and `Checked 12 files in 14ms. No fixes applied.`
## UAT / Verification
- [x] `npm test`, `npm run typecheck`, and `npm run lint` pass.
- [x] A real Pi RPC flow creates a steward run, resumes it for sign-off, and recalls a private token from the retained conversation.
- [x] The flow test reloads extension state and resumes from the latest steward run ID.
## Appendix (context, not approved)
Use pi-subagents 0.65.1 public RPC (`spawn`, `resume`) and `subagent:async-complete`. Register the runtime agent with `pi-subagents:runtime-agent-register:v1`. Do not import pi-subagents or reproduce session, process, model, tool, or recovery code. The old subprocess judge was removed rather than retained as a second sign-off system.
## Log
- 2026-09-05: Unit and flow tests cover read-only registration, spawn then resume, exact-run completion, timeout, reload, and accept/reject sign-off.
- 2026-09-05: The Pi 0.85.0 + pi-subagents 0.65.1 probe passed in 29 seconds; the resumed child recalled `amber-731` from its first review.
— Pi/Codex
@@ -0,0 +1,65 @@
---
requested_model: deepseek/deepseek-v4-pro-0813
mode: code review
input: src/worker.ts, src/supervisor-runtime.ts
trace: omitted from git (11 MB raw provider transcript)
generated: 2026-09-06T04:44:52.809370+00:00
---
# MoA fragility review
Decision: reject the current fix and replace duplicate async lifecycle state with one synchronous worker tool.
Strongest objection: if a truly synchronous worker RPC is unavailable, this simplification blocks the intended parallel supervision model.
Next check: read the goal-worker tool implementation and the three failing test transcripts before deleting code.
Smallest recommended architecture:
The supervisor extension must not store worker lifecycle state. Lifecycle is owned by the subagent runtime. Move ownership into one tool boundary.
1. Delete NESTED_STATE persistence, event listeners, pending reconciliation, CheckWorkerState, and the replacement guard from supervisor-runtime.ts.
2. Add a single supervisor tool:
- RunGoalWorker: starts and awaits a goal-worker synchronously, using the aggregate output as a tool result.
- Keep one in-memory boolean `workerRunning`, guarded at tool execute start, not relying on event ordering.
3. If that synchronous tool cannot be supported:
- StartGoalWorker returns a run ID as ordinary tool output.
- WaitGoalWorker(runId) blocks on terminal status check.
- ApproveGoal always calls bg_wait on the ID from StartGoalWorker or WaitGoalWorker; otherwise approval fails.
Because existing failure 2 came from the runtime blocking on a mismatched ID, the important property is:
- an ID not produced by StartGoalWorker/WaitGoalWorker may not be used for bg_wait;
- a failed wait must clear any in-process guard immediately;
- an await cover failure must be treated as a terminal error, not as `pending`.
Exact deletions/changes:
In `src/supervisor-runtime.ts`:
- Remove `NESTED_STATE`, `NestedState`, `nested`, `persist`, `targetRun`, `completeNested`, all `subagent:async-*`, process-terminal listeners, and `retainedRunState` reconciliation.
- Remove `pi.events.on("tool_call")` blocks. Replace with allow/deny only: deny edit/write, allow read-only bash, allow RunGoalWorker, allow bg_wait, allow ApproveGoal, deny subagent action tools.
- Replace CheckWorkerState with nothing. State inspection is only through normal async progress updates.
- ApproveGoal asserts no active await cover currently exists from RunGoalWorker or WaitGoalWorker, processWorkState is idle, worktree is clean, and evidence inspection claims are backed by the actual tool result from RunGoalWorker.
In `src/worker.ts`:
- Drop `retainedRunState` and any pending-closure logic.
- Keep `asyncSnapshot` only for processWorkState, if needed.
Why this removes fragility:
- Duplicate state is gone.
- Lifecycle is only stored in the runtimes tool execution stack.
- Revival cannot resurrect a wrong worker ID unless a new tool starts it.
- Race between event handler and spawn disappears because Start or Wait returns a result synchronously to the model.
Why this may be worse:
- Synchronous wait loses the supervisor's ability to issue corrections inline during progress.
- Parallel instrumented runs cannot be sustained within one tool without exposing `bg_wait` to the model.
- If the model calls WaitGoalWorker with an incorrect ID, it will now fail directly, but the failure must not be caught and retried with a cached ID.
Acceptance test to catch all observed failures:
- Send the supervisor script: `StartGoalWorker``WaitGoalWorker(id)``RunGoalWorker(correction)``ApproveGoal`, where a midway kill drops the terminal event and forces session revival, and then assert the code path stores no `NESTED_STATE`, does not even mention it in the extension memory, and either the worker returns a tool result or the revived session remains in the same `WaitGoalWorker` tool with no retry on an ID not yielded by that tool.
## Completion
- outcome: `completed_after_follow_up`
- trace: omitted from git (11 MB raw provider transcript); this file preserves the complete review answer
@@ -0,0 +1,20 @@
## Review
No issues found.
- Correct: The packaged worker is discoverable in pi-subagents 0.65.1 child-safe fanout. `package.json` exposes `pi.subagents.agents`, which the installed discovery code consumes (`pi-subagents/src/agents/agents.ts:510-538,597-657`), while the child fanout executor uses normal `discoverAgents` (`pi-subagents/src/extension/fanout-child.ts:145-190`).
- Correct: The supervisor gate requires the exact packaged agent, nonempty task, `async:false`, `context:"fork"`, and the configured model with no extra fields (`src/supervisor-runtime.ts:83-108`). The installed executor honors explicit foreground mode (`pi-subagents/src/runs/foreground/subagent-executor.ts:6511-6515,6917-6920`).
- Correct: Foreground completion is tied to the real `tool_result`. `activeWorkerCalls` is removed only when that result arrives, successful completion is recorded, and approval requires a later turn (`src/supervisor-runtime.ts:75-115,132-138`). Same-message worker launch plus approval is independently rejected by inspecting the assistant message.
- Correct: Stale local launch reservations self-heal: errors clear on `tool_result`, and `turn_start` clears any reservation for which no result hook arrived (`src/supervisor-runtime.ts:75-115`). The tests cover duplicate launch, failed-result recovery, and next-turn recovery (`test/supervisor-runtime.test.ts:57-76`).
- Correct: `CompleteGoal` remains blocked while the retained supervisor is pending, while any subagent/process work is active or unknown, or until a matching approval checkpoint exists (`src/index.ts`, `CompleteGoal`). Foreground nested work therefore cannot race sign-off because its containing supervisor run remains pending.
- Correct: `supervisor-runtime.ts` does not perform runtime-agent registration. The main extension exits in child processes through `isSupervisorProcess`, while installed pi-subagents itself is inert when `PI_SUBAGENT_CHILD=1` (`src/index.ts`, `isSupervisorProcess`; installed `pi-subagents/index.ts:3-8`).
- Correct: The former nested async worker ID/pending lifecycle is absent. The remaining `workerRunId`/`workerPending` state belongs only to the retained supervisor lifecycle, matching the documented topology.
Residual risks:
- `test/package-agent.test.ts` verifies packaging statically rather than launching the packaged worker through the real child-safe fanout runtime. The installed 0.65.1 source supports the configuration, but retaining an RPC integration check is advisable.
- The focused approval tests mock Pis `tool_call`/`tool_result` ordering. A real RPC test remains the strongest guard against upstream lifecycle-event changes.
- Tests were inspected but not executed in this review environment; the supervisor should run `npm test`, `npm run typecheck`, and `npm run lint`.
- Merge verdict: **OK with residual test-environment risks.**
-- PI[reviewer/gpt-5.6-sol]
+131
View File
@@ -0,0 +1,131 @@
import { execFileSync } from "node:child_process";
import { createHash } from "node:crypto";
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
import { dirname, join, relative, resolve } from "node:path";
const GOAL_LINE = /^\s*(?:\d+\.|[-*])\s*\[([ xX/-])\]\s*goal:\s*(.*)$/i;
export interface ApprovalRecord {
version: 3;
verdict: "accept";
approvalId: string;
goal: string;
planPath: string;
goalBlockHash: string;
repoRoot: string;
head: string;
tree: string;
cleanWorktree: true;
inspected: { plan: true; repository: true; evidence: true; verifyOutput: true };
verifyOutputPath: string;
supervisor: { sessionId: string; runId: string | null };
timestamp: string;
}
function command(repoRoot: string, args: string[]): string {
return execFileSync("git", args, { cwd: repoRoot, encoding: "utf8" }).trim();
}
export function repositoryState(cwd: string): { repoRoot: string; head: string; tree: string; cleanWorktree: boolean } {
const repoRoot = command(cwd, ["rev-parse", "--show-toplevel"]);
const head = command(repoRoot, ["rev-parse", "HEAD"]);
const tree = command(repoRoot, ["rev-parse", "HEAD^{tree}"]);
const prefix = relative(repoRoot, resolve(cwd)).replaceAll("\\", "/");
const owned = prefix ? `${prefix}/.pi` : ".pi";
const cleanWorktree = command(repoRoot, [
"status", "--porcelain=v1", "--untracked-files=all", "--", ".",
`:(exclude,glob)${owned}/plan/*.md`,
`:(exclude,glob)${owned}/pi-goals/approvals/*`,
]) === "";
return { repoRoot, head, tree, cleanWorktree };
}
export function goalBlock(plan: string, goal: string): string | null {
const lines = plan.split("\n");
const wanted = goal.trim().toLowerCase();
const hits = lines.flatMap((line, index) => {
const match = GOAL_LINE.exec(line);
return match && (match[1] === " " || match[1] === "/") && match[2].trim().toLowerCase() === wanted ? [index] : [];
});
if (hits.length !== 1) return null;
const start = hits[0];
let end = lines.length;
for (let index = start + 1; index < lines.length; index++) {
if (GOAL_LINE.test(lines[index])) {
end = index;
break;
}
}
return lines.slice(start, end).join("\n");
}
export function hashGoalBlock(block: string): string {
return createHash("sha256").update(block).digest("hex");
}
export function verifyOutputPath(repoRoot: string, path: string): string | null {
const resolved = resolve(repoRoot, path);
const relativePath = relative(repoRoot, resolved).replaceAll("\\", "/");
if (!relativePath || relativePath.startsWith("../") || relativePath === "..") return null;
try {
const output = statSync(resolved);
if (!output.isFile() || output.size === 0) return null;
command(repoRoot, ["ls-files", "--error-unmatch", "--", relativePath]);
return relativePath;
} catch {
return null;
}
}
export function approvalPath(cwd: string, sessionId: string, goal: string): string {
const goalId = createHash("sha256").update(goal.trim().toLowerCase()).digest("hex").slice(0, 16);
return join(cwd, ".pi", "pi-goals", "approvals", `${sessionId}-${goalId}.json`);
}
export function writeApproval(path: string, record: ApprovalRecord): void {
mkdirSync(dirname(path), { recursive: true });
const temporary = `${path}.${process.pid}.tmp`;
try {
writeFileSync(temporary, `${JSON.stringify(record, null, 2)}\n`);
renameSync(temporary, path);
} finally {
if (existsSync(temporary)) rmSync(temporary, { force: true });
}
}
export function readApproval(path: string): ApprovalRecord | null {
if (!existsSync(path)) return null;
try {
return JSON.parse(readFileSync(path, "utf8")) as ApprovalRecord;
} catch {
return null;
}
}
export function approvalMatches(record: ApprovalRecord | null, input: {
approvalId: string;
goal: string;
planPath: string;
goalBlockHash: string;
repoRoot: string;
head: string;
tree: string;
cleanWorktree: boolean;
}): boolean {
return record?.version === 3
&& record.verdict === "accept"
&& record.approvalId === input.approvalId
&& record.goal === input.goal
&& resolve(record.planPath) === resolve(input.planPath)
&& record.goalBlockHash === input.goalBlockHash
&& resolve(record.repoRoot) === resolve(input.repoRoot)
&& record.head === input.head
&& record.tree === input.tree
&& record.cleanWorktree === true
&& input.cleanWorktree
&& record.inspected.plan === true
&& record.inspected.repository === true
&& record.inspected.evidence === true
&& record.inspected.verifyOutput === true
&& Boolean(record.verifyOutputPath);
}
+92
View File
@@ -0,0 +1,92 @@
import { execFile } from "node:child_process";
import { promisify } from "node:util";
const execFileAsync = promisify(execFile);
interface LaunchSupervisorInput {
cwd: string;
sourceSessionFile: string;
workerSessionId: string;
workerIntercomId: string;
planPath: string;
approvalId: string;
extensionPath: string;
superviseExtensionPath: string | null;
model: string | null;
}
function shellQuote(value: string): string {
return `'${value.replaceAll("'", "'\\''")}'`;
}
function findPaneId(value: unknown): string | null {
if (!value || typeof value !== "object") return null;
const record = value as Record<string, unknown>;
for (const key of ["pane_id", "paneId"]) {
if (typeof record[key] === "string") return record[key];
}
for (const child of Object.values(record)) {
const found = findPaneId(child);
if (found) return found;
}
return null;
}
async function herdr(args: string[], json = true): Promise<unknown> {
const bin = process.env.HERDR_BIN_PATH ?? "herdr";
const { stdout } = await execFileAsync(bin, args, { encoding: "utf8", timeout: 15_000 });
if (!json) return stdout.trim();
return stdout.trim() ? JSON.parse(stdout) : {};
}
function stalePaneError(error: unknown): boolean {
const record = error as { stdout?: unknown; stderr?: unknown; message?: unknown };
const text = [record.stdout, record.stderr, record.message].filter((value): value is string => typeof value === "string").join("\n");
return /\b(?:NOT_FOUND|PANE_GONE|PANE_NOT_FOUND)\b/i.test(text);
}
export function supervisorCommand(input: LaunchSupervisorInput): string {
const env = [
"PI_GOALS_ROLE=supervisor",
`PI_GOALS_WORKER_ID=${input.workerSessionId}`,
`PI_GOALS_WORKER_INTERCOM_ID=${input.workerIntercomId}`,
`PI_GOALS_PLAN_PATH=${input.planPath}`,
`PI_GOALS_APPROVAL_ID=${input.approvalId}`,
`PI_GOALS_OWNER_SESSION_ID=${input.workerSessionId}`,
];
const args = [
"pi",
"--no-extensions",
"-e", "npm:pi-intercom",
"-e", process.env.PI_GOALS_SUPERVISE_EXTENSION ?? input.superviseExtensionPath ?? "npm:@wassname2/pi-supervise@0.0.4",
"-e", input.extensionPath,
"--fork", input.sourceSessionFile,
"--name", `goals-supervisor-${input.workerSessionId.slice(0, 8)}`,
];
if (input.model) args.push("--model", input.model);
return `env ${[...env, ...args].map(shellQuote).join(" ")}`;
}
export async function openSupervisorPane(input: LaunchSupervisorInput): Promise<string> {
if (process.env.HERDR_ENV !== "1") throw new Error("Ready needs a Herdr session so pi-goals can open the supervisor session.");
await herdr(["--version"], false);
const split = await herdr(["pane", "split", "--current", "--direction", "right", "--cwd", input.cwd, "--no-focus"]);
const paneId = findPaneId(split);
if (!paneId) throw new Error("Herdr did not return the new supervisor pane ID.");
try {
await herdr(["pane", "run", paneId, supervisorCommand(input)]);
return paneId;
} catch (error) {
await closeSupervisorPane(paneId);
throw error;
}
}
export async function closeSupervisorPane(paneId: string): Promise<void> {
try {
await herdr(["pane", "close", paneId]);
} catch (error) {
if (stalePaneError(error)) return;
throw error;
}
}
+195 -426
View File
@@ -1,48 +1,30 @@
/**
* PI: pi-goals v2 drafts goals into .pi/plan/<session_id>-vN.md, the agent works them with its
* normal Edit tool, and a fresh read-only judge signs each goal off through the one blessed tool,
* CompleteGoal.
* PI: pi-goals owns one versioned plan per session. After Ready, the main session implements the
* plan while a compacted, visible fork supervises it through pi-supervise.
*
* PI: Each /goals call makes a new plan version, `.pi/plan/<session_id>-vN.md`. The selected version
* stays in session state across resume and compaction. Old plans stay on disk but inert, so a new
* conversation cannot silently edit them. `/goals --clear` only disconnects this session; the filename is the arm switch: a session that never ran
* /goals has no active plan, so the widget, injections, and CompleteGoal all stay silent.
* Each /goals call makes `.pi/plan/<session_id>-vN.md`. The selected version survives resume and
* compaction. Old plans stay on disk but inactive. A session with no selected plan has no widget,
* supervision, or CompleteGoal sign-off.
*
* The v1 lesson: the parser existed so TypeScript could read the plan, but almost every reader is a
* model. So v2 has NO parser and no schema. The harness does exactly three things for a
* cooperative-but-confused model:
* 1. memory — a transient re-send of the plan, never persisted, on two triggers: the plan went
* stale for STALE_TURNS turns (send the working set above ## Log), or the session
* started / compacted (send the whole file, appendix included). v2 sent the whole
* file every turn; pi-tasks tried that and deleted it as "wallpaper noise that
* trains the model to ignore the task block" (tintinweb/pi-tasks CHANGELOG.md:149),
* and the always-present CompleteGoal description carries the contract instead.
* 2. format — a skeleton convention taught in planDrafting (prompts.ts), not validated
* 3. eyes — CompleteGoal spawns a strictly read-only pi subprocess (--no-session, no bash)
* that gets the whole plan file plus the claimed goal, finds the goal itself
* (tolerates wording drift), checks the evidence (including the agent's saved
* verify output) against the repo, and returns VERDICT: accept|reject
* TypeScript reads only goal checkbox lines for the widget. Models read the plan as prose. The
* worker edits the project and records evidence. The supervisor inspects it and writes a private
* approval checkpoint.
*
* The judge subsumes what v1 did in code: goal matching (no findGoal), evidence validation (a
* placeholder gets rejected in words), and format reading. The extension's only
* writes are the sign-off: append a log line to ## Log (the audit trail) and tick the goal [x] when
* an exact goal line matches (on drift the agent ticks, and the result says so). A hand-tick
* without a matching tool-written log line is visible in the diff either way.
*
* Judge ran but failed/errored/timed out, or returned no VERDICT line => accepted_inconclusive: the
* working agent is never blocked on judge infra; the log line says the judge ran but failed. There
* is no pre-emptive "no model" path -- a null judgeModel just omits --model so pi's configured
* default runs the judge, so inconclusive always means "ran but failed", never "couldn't start".
*
* All model-facing text lives in prompts.ts, in flow order.
* -- Pi/Codex
*/
import { spawn } from "node:child_process";
import { execFileSync } from "node:child_process";
import { randomUUID } from "node:crypto";
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { basename, join, resolve } from "node:path";
import { join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
import { Type } from "typebox";
import { completeGoalDescription, completeGoalParamDescription, judgeSystem, judgeUser, planDrafting, planningState, reminder, resync } from "./prompts.js";
import { approvalMatches, approvalPath, goalBlock, hashGoalBlock, readApproval, repositoryState } from "./approval.js";
import { closeSupervisorPane, openSupervisorPane } from "./herdr.js";
import { completeGoalDescription, completeGoalParamDescription, planDrafting, planningState, resync } from "./prompts.js";
import { SUPERVISOR_STARTUP_TIMEOUT_MS, workerPiSupervise } from "./supervise.js";
import { isVisibleSupervisor, registerVisibleSupervisor } from "./supervisor-session.js";
const STATE = "pi-goals-state";
const STATUS_KEY = "pi-goals";
@@ -51,29 +33,16 @@ const PLANNING_CONTEXT = "pi-goals-planning-context";
const PLAN_DIR = ".pi/plan";
// For static text (the /goals description) where there is no ctx to resolve the session id.
const PLAN_SHAPE = `${PLAN_DIR}/<session_id>-vN.md`;
// Judge toolset: strictly read-only, NO bash -- the judge can never execute or mutate anything, and
// in particular never re-runs a verify command (which may be a 10-hour training job). The agent runs
// verify itself and saves the output as evidence; the judge reads it. Names match pi's tool registry.
const JUDGE_TOOLS = ["read", "grep", "find", "ls"];
const JUDGE_BLOCKED_TOOLS = ["edit", "write"];
const JUDGE_TIMEOUT_MS = 600_000;
// Plan mode is read-only by convention AND a light gate: edit/write are blocked (except the plan
// file, the deliverable). bash stays open — the prompt says don't mutate; guide, not gate (spec D3).
// Plan mode blocks edit/write except for its plan file. bash remains available for read-only inspection. -- Pi/Codex
const PLAN_MODE_BLOCKED_TOOLS = ["edit", "write"];
// A plan reminder is only useful after a substantial run of work that has not changed the working
// set. Log and learning entries do not count as progress. Unlike pi-tasks, goals have no dedicated
// progress tool, so this cadence repeats until the working set changes.
const STALE_TURNS = 8;
const AUTO_DEFAULT_INTERVAL_MS = 60 * 60 * 1_000;
const AUTO_MAX_WAKES_WITHOUT_PROGRESS = 2;
// A checkbox line beginning "goal:", for the widget and the "any goals open?" reminder condition.
// A checkbox line beginning "goal:", used by the widget and supervisor scheduling.
// Everything else reads the file as prose.
const GOAL_LINE = /^\s*(?:\d+\.|[-*])\s*\[([ xX/-])\]\s*goal:\s*(.*)$/i;
// An indented checkbox line that isn't a goal: a subtask. Only the widget reads these, so the human
// sees the next action and not just the goal -- this file IS the task list.
const SUBTASK_LINE = /^\s+(?:\d+\.|[-*])\s*\[([ xX/-])\]\s*(.*)$/;
// The fold. Above it: the working set that gets re-sent. Below it: durable memory.
// The fold separates current goals from the longer research record.
const FOLD_LINE = /^##\s+Log\s*$/im;
type GoalStatus = "open" | "active" | "done" | "cancelled";
const CHAR_TO_STATUS: Record<string, GoalStatus> = { " ": "open", "/": "active", x: "done", "-": "cancelled" };
@@ -87,8 +56,7 @@ function scanGoals(plan: string): Array<{ status: GoalStatus; subject: string; l
return goals;
}
/** The working set: everything above "## Log". Log, Learnings and Appendix below it are durable
* memory -- unlimited, read on demand, pushed back only by a resync. Exported for the unit test. */
/** Return the short current-goal section above "## Log". Exported for the unit test. */
export function foldPlan(plan: string): string {
const m = FOLD_LINE.exec(plan);
return (m ? plan.slice(0, m.index) : plan).trimEnd();
@@ -118,30 +86,32 @@ export function nextPlanVersion(planNames: string[], sessionId: string): number
type Phase = "planning" | "working" | null;
export function isMainSession(isSubagentChild = process.env.PI_SUBAGENT_CHILD === "1"): boolean {
return !isSubagentChild && !isVisibleSupervisor();
}
interface PlanState {
phase: Phase;
/** Optional model ref for the sign-off judge; unset => current session model, else pi's default. */
judgeModel: string | null;
supervisorModel: string | null;
supervisorPaneId: string | null;
approvalId: string | null;
planVersion: number | null;
/** User-enabled interval for continuing active goals after the agent settles. */
autoIntervalMs: number | null;
autoPaused: boolean;
}
export default function piGoalsExtension(pi: ExtensionAPI): void {
let state: PlanState = { phase: null, judgeModel: null, planVersion: null, autoIntervalMs: null, autoPaused: false };
if (isVisibleSupervisor()) {
registerVisibleSupervisor(pi);
return;
}
if (!isMainSession()) return;
let state: PlanState = {
phase: null,
supervisorModel: null,
supervisorPaneId: null,
approvalId: null,
planVersion: null,
};
let planningContextPending = false;
// The reminder sees only the working set. A repeated Log line must not look like progress.
let turnsStale = 0;
let lastSeenWorkingSet = "";
let autoTimer: ReturnType<typeof setTimeout> | null = null;
let autoWakeInFlight = false;
let autoWakesWithoutProgress = 0;
let autoLastWorkingSet = "";
let autoImmediateUsed = false;
let runStartedBackgroundWork = false;
// Set on session start and after a compaction; drained by the next LLM call, which then carries
// the WHOLE file (appendix included) instead of just the working set.
let resyncReason: string | null = "New session.";
const planRel = (ctx: ExtensionContext) => (state.planVersion === null ? PLAN_SHAPE : `${PLAN_DIR}/${ctx.sessionManager.getSessionId()}-v${state.planVersion}.md`);
@@ -161,58 +131,61 @@ export default function piGoalsExtension(pi: ExtensionAPI): void {
pi.appendEntry<PlanState>(STATE, state);
}
function clearAutoTimer(): void {
if (autoTimer !== null) clearTimeout(autoTimer);
autoTimer = null;
function beginReview(ctx: ExtensionContext): void {
for (const goal of scanGoals(readPlan(ctx))) {
rmSync(approvalPath(ctx.cwd, ctx.sessionManager.getSessionId(), goal.subject), { force: true });
}
state = { ...state, approvalId: randomUUID() };
persist();
}
function activeGoals(ctx: ExtensionContext): boolean {
return scanGoals(readPlan(ctx)).some((goal) => goal.status === "active" || goal.status === "open");
function loadedPiSuperviseExtensionPath(): string | null {
const tool = pi.getAllTools().find((candidate) => candidate.name === "worker_view") as { sourceInfo?: { path?: unknown } } | undefined;
return typeof tool?.sourceInfo?.path === "string" ? tool.sourceInfo.path : null;
}
function scheduleAutoContinue(ctx: ExtensionContext, delayMs = state.autoIntervalMs): void {
clearAutoTimer();
if (delayMs === null || state.phase !== "working" || state.autoIntervalMs === null || state.autoPaused || !activeGoals(ctx)) return;
autoTimer = setTimeout(() => {
autoTimer = null;
if (state.phase !== "working" || state.autoPaused || !ctx.isIdle() || !activeGoals(ctx)) return;
autoWakeInFlight = true;
pi.sendUserMessage(
`<system-reminder>Auto-continue is enabled by the human. Continue the active goal in ${planRel(ctx)}. Work from the open subtasks and observed artifacts. Keep the plan current, including useful Log entries. If you need a human decision, ask one direct question and leave the goal active.</system-reminder>`,
{ deliverAs: "followUp" },
);
}, delayMs);
autoTimer.unref();
function repositoryRoot(cwd: string): string {
return execFileSync("git", ["rev-parse", "--show-toplevel"], { cwd, encoding: "utf8" }).trim();
}
function settleAuto(ctx: ExtensionContext): void {
if (state.phase !== "working" || state.autoIntervalMs === null || state.autoPaused || !activeGoals(ctx)) return;
const workingSet = foldPlan(readPlan(ctx));
const changed = workingSet !== autoLastWorkingSet;
if (changed) {
autoLastWorkingSet = workingSet;
autoWakesWithoutProgress = 0;
autoImmediateUsed = false;
async function startSupervisor(ctx: ExtensionContext): Promise<void> {
repositoryRoot(ctx.cwd);
const sourceSessionFile = ctx.sessionManager.getSessionFile();
if (!sourceSessionFile) throw new Error("The current session is not persisted, so it cannot be forked.");
const worker = await workerPiSupervise(pi);
beginReview(ctx);
let paneId: string | null = null;
try {
paneId = await openSupervisorPane({
cwd: ctx.cwd,
sourceSessionFile,
workerSessionId: ctx.sessionManager.getSessionId(),
workerIntercomId: worker.intercomId,
planPath: planPath(ctx),
approvalId: state.approvalId!,
extensionPath: fileURLToPath(import.meta.url),
superviseExtensionPath: loadedPiSuperviseExtensionPath(),
model: state.supervisorModel,
});
await worker.waitForPair(SUPERVISOR_STARTUP_TIMEOUT_MS);
} catch (error) {
if (paneId) throw new Error(`Supervisor startup failed in Herdr pane ${paneId}; it remains open for inspection. ${error instanceof Error ? error.message : String(error)}`);
throw error;
}
if (autoWakeInFlight) {
autoWakeInFlight = false;
if (!changed) autoWakesWithoutProgress++;
if (autoWakesWithoutProgress >= AUTO_MAX_WAKES_WITHOUT_PROGRESS) {
state = { ...state, autoPaused: true };
persist();
updateWidget(ctx);
ctx.ui.notify("Goal auto-continue paused; waiting for user after two wakes without working-plan progress.", "warning");
return;
}
scheduleAutoContinue(ctx);
return;
state = { ...state, supervisorPaneId: paneId };
persist();
}
async function stopSupervisor(): Promise<boolean> {
if (!state.supervisorPaneId) return true;
try {
await closeSupervisorPane(state.supervisorPaneId);
state = { ...state, supervisorPaneId: null };
persist();
return true;
} catch {
return false;
}
if (!runStartedBackgroundWork && !autoImmediateUsed) {
autoImmediateUsed = true;
scheduleAutoContinue(ctx, 0);
return;
}
scheduleAutoContinue(ctx);
}
function updateWidget(ctx: ExtensionContext): void {
@@ -228,78 +201,64 @@ export default function piGoalsExtension(pi: ExtensionAPI): void {
return;
}
const done = goals.filter((g) => g.status === "done").length;
const auto = state.autoPaused ? " · waiting for user" : state.autoIntervalMs === null ? "" : ` · auto ${state.autoIntervalMs / 60_000}m`;
ctx.ui.setStatus(STATUS_KEY, ctx.ui.theme.fg("accent", `${done}/${goals.length} goals${auto}`));
const liveGoals = goals.filter((g) => g.status === "active" || g.status === "open");
const stateLabel = liveGoals.length > 0 ? " · supervised" : " · complete";
ctx.ui.setStatus(STATUS_KEY, ctx.ui.theme.fg("accent", `${done}/${goals.length} goals${stateLabel}`));
const mark: Record<GoalStatus, string> = { done: "✔", active: "▸", open: "◻", cancelled: "✗" };
// Only live goals get lines so finished work never pushes current work off screen. The active
// goal also shows its open subtasks: this file is the task list, so the widget is the task list.
// No path line: the session id makes it 47 chars, too long to be worth a widget row. The
// human opens the file from the Ready menu, and every injected reminder still names it.
// No path line: the session id makes it too long to be useful in the widget.
const plan = readPlan(ctx);
const lines: string[] = state.autoPaused ? [ctx.ui.theme.fg("warning", "⏸ waiting for user")] : [];
for (const g of goals.filter((g) => g.status === "active" || g.status === "open")) {
lines.push(`${mark[g.status]} ${g.subject}`);
const lines: string[] = liveGoals.length === 0 ? ["✔ complete"] : [];
for (const g of liveGoals) {
lines.push(`${mark[g.status]} ${g.status === "active" ? "supervising… " : ""}${g.subject}`);
if (g.status === "active") lines.push(...openSubtasks(plan, g.line).slice(0, 3).map((s) => ctx.ui.theme.fg("muted", `${s}`)));
}
ctx.ui.setWidget(WIDGET_KEY, lines);
}
// --- /goals: enter plan mode (or clear / set judge) --------------------------------------------
// --- /goals: enter plan mode or configure supervision -- Pi/Codex -----------------------------
pi.registerCommand("goals", {
description: `Plan mode: draft goals into ${PLAN_SHAPE}, review, then work them. /goals <objective> | /goals --clear (disconnect) | /goals --auto [minutes|off] | /goals --judge <model>`,
description: `Plan goals, then open a visible supervisor session. /goals <objective> | clear | model <supervisor>`,
handler: async (args, ctx) => {
const arg = args.trim();
if (arg === "--clear") {
if (arg === "clear") {
if (state.planVersion === null) {
ctx.ui.notify("No active plan to disconnect.", "info");
return;
}
const currentPlan = planRel(ctx);
clearAutoTimer();
state = { ...state, phase: null, planVersion: null, autoIntervalMs: null, autoPaused: false };
if (!(await stopSupervisor())) {
ctx.ui.notify("Could not close the visible supervisor; the plan remains connected.", "warning");
return;
}
state = { ...state, phase: null, supervisorPaneId: null, approvalId: null, planVersion: null };
persist();
updateWidget(ctx);
ctx.ui.notify(`Disconnected from ${currentPlan}; the file remains on disk.`, "info");
return;
}
if (arg === "--auto" || arg.startsWith("--auto ")) {
const value = arg.slice("--auto".length).trim();
if (value === "off") {
clearAutoTimer();
state = { ...state, autoIntervalMs: null, autoPaused: false };
persist();
updateWidget(ctx);
ctx.ui.notify("Goal auto-continue disabled.", "info");
if (arg === "model" || arg.startsWith("model ")) {
if (state.phase === "working") {
ctx.ui.notify("Run /goals clear before changing the active supervisor model.", "warning");
return;
}
if (state.phase !== "working") {
ctx.ui.notify("Approve a plan with Ready before enabling auto-continue.", "warning");
if (!(await stopSupervisor())) {
ctx.ui.notify("Could not close the visible supervisor; its model was not changed.", "warning");
return;
}
const minutes = value ? Number(value) : AUTO_DEFAULT_INTERVAL_MS / 60_000;
if (!Number.isInteger(minutes) || minutes < 1) {
ctx.ui.notify("Use /goals --auto [whole minutes], or /goals --auto off.", "warning");
return;
}
autoWakeInFlight = false;
autoWakesWithoutProgress = 0;
autoLastWorkingSet = foldPlan(readPlan(ctx));
state = { ...state, autoIntervalMs: minutes * 60_000, autoPaused: false };
const ref = arg.slice("model".length).trim();
state = { ...state, supervisorModel: ref || null, supervisorPaneId: null, approvalId: null };
persist();
updateWidget(ctx);
scheduleAutoContinue(ctx);
ctx.ui.notify(`Goal auto-continue enabled every ${minutes}m.`, "info");
ctx.ui.notify(`Goal-supervisor model ${ref ? `set to ${ref}` : "reset to the current Pi default"}.`, "info");
return;
}
if (arg === "--judge" || arg.startsWith("--judge ")) {
const ref = arg.slice("--judge".length).trim();
state = { ...state, judgeModel: ref || null };
persist();
ctx.ui.notify(ref ? `Sign-off judge model set to ${ref}` : "Sign-off judge reset to the session model", "info");
if (!(await stopSupervisor())) {
ctx.ui.notify("Could not close the visible supervisor; no new plan was started.", "warning");
return;
}
state = { ...state, phase: "planning", planVersion: nextVersion(ctx) };
state = { ...state, phase: "planning", supervisorPaneId: null, approvalId: null, planVersion: nextVersion(ctx) };
planningContextPending = true;
resyncReason = null;
writePlan(ctx, "");
@@ -317,31 +276,22 @@ export default function piGoalsExtension(pi: ExtensionAPI): void {
// --- hooks --------------------------------------------------------------------------------------
/** What this LLM call should carry, if anything: a one-shot resync, or a staleness reminder. */
/** Restore the complete plan once after session start or compaction. */
function dueInjection(ctx: ExtensionContext, plan: string): string | null {
const drainResync = (): string | null => {
const why = resyncReason;
resyncReason = null;
return why;
};
if (state.phase === "planning") return null;
if (!plan.trim()) return null;
const why = drainResync();
if (why) return resync(plan, planRel(ctx), why);
if (turnsStale < STALE_TURNS) return null;
const goals = scanGoals(plan);
if (goals.length === 0) {
// Non-empty plan but no recognizable goal line: the harness would go silently inert (no
// widget, no injection, no reminders). Say so instead -- cooperative but confused.
return `<system-reminder>\n${planRel(ctx)} exists but has no goal line pi-goals recognizes. A goal is a checkbox list line starting "goal:", e.g. "1. [ ] goal: <imperative>" ([ ] open, [/] active, [x] done, [-] cancelled). Reformat it if it's meant to be the plan.\n</system-reminder>`;
}
if (!goals.some((g) => g.status === "active" || g.status === "open")) return null;
return reminder(foldPlan(plan), planRel(ctx));
if (state.phase === "planning" || !plan.trim() || !resyncReason) return null;
const why = resyncReason;
resyncReason = null;
return resync(plan, planRel(ctx), why);
}
// The phase snapshot enters context only when planning starts or context was lost.
pi.on("before_agent_start", async (_event, ctx) => {
if (state.phase !== "planning" || !planningContextPending) return;
if (state.phase === "working") {
return {
systemPrompt: `${ctx.getSystemPrompt()}\n\nYou are the implementation worker for ${planRel(ctx)}. Keep the full conversation and do the work directly. A stronger read-only supervisor watches this session through pi-supervise and can steer you. Commit clean evidence before asking for sign-off. Stop when a goal appears complete so the supervisor can inspect a settled worker view. Call CompleteGoal only after the supervisor says it recorded approval. -- Pi/Codex`,
};
}
if (!planningContextPending) return;
planningContextPending = false;
return { message: { customType: PLANNING_CONTEXT, content: planningState(planPath(ctx)), display: false } };
});
@@ -350,58 +300,36 @@ export default function piGoalsExtension(pi: ExtensionAPI): void {
// before_agent_start, so context restores the planning snapshot exactly once in that path.
pi.on("context", async (event, ctx) => {
const messages = state.phase === "planning" ? event.messages : event.messages.filter((message) => (message as { customType?: string }).customType !== PLANNING_CONTEXT);
const removedPlanningContext = messages.length !== event.messages.length;
if (state.phase === "planning" && planningContextPending) {
planningContextPending = false;
return { messages: [...messages, { role: "user" as const, content: [{ type: "text" as const, text: planningState(planPath(ctx)) }], timestamp: Date.now() }] };
}
const text = dueInjection(ctx, readPlan(ctx));
if (!text) return messages === event.messages ? undefined : { messages };
turnsStale = 0;
if (!text) return removedPlanningContext ? { messages } : undefined;
return { messages: [...messages, { role: "user" as const, content: [{ type: "text" as const, text }], timestamp: Date.now() }] };
});
// PI: Human plan-mode replies are durable evidence of the interview, not model summaries.
pi.on("input", async (event, ctx) => {
if (event.source !== "extension") {
clearAutoTimer();
autoImmediateUsed = false;
if (state.autoPaused) {
state = { ...state, autoPaused: false };
persist();
updateWidget(ctx);
}
}
if (state.phase === "planning" && event.source !== "extension") writePlan(ctx, appendInterview(readPlan(ctx), event.text));
});
// The staleness clock sees only the working set. Log updates are durable evidence, not progress.
pi.on("turn_end", async (_event, ctx) => {
const workingSet = foldPlan(readPlan(ctx));
if (workingSet === lastSeenWorkingSet) {
turnsStale++;
return;
}
lastSeenWorkingSet = workingSet;
turnsStale = 0;
updateWidget(ctx);
});
pi.on("agent_start", async () => {
runStartedBackgroundWork = false;
});
pi.on("tool_call", async (event, ctx) => {
if (state.phase === "working" && (event.toolName === "subagent" || (event.toolName === "process" && (event.input as { action?: string }).action === "start"))) {
runStartedBackgroundWork = true;
}
if (state.phase !== "planning") return;
if (PLAN_MODE_BLOCKED_TOOLS.includes(event.toolName)) {
const target = (event.input as { path?: string }).path;
if (target && resolve(ctx.cwd, target) === resolve(planPath(ctx))) return;
return { block: true, reason: `Planning is read-only: only ${planRel(ctx)} may be written. Agree the plan, then choose Ready.` };
}
if (event.toolName === "bash" && !isPlanningReadOnlyCommand(String((event.input as { command?: string }).command))) {
return { block: true, reason: "Planning is read-only: inspect facts without writes or pipes, then put the change in the plan." };
if (state.phase === "planning") {
if (PLAN_MODE_BLOCKED_TOOLS.includes(event.toolName)) {
const target = (event.input as { path?: string }).path;
if (target && resolve(ctx.cwd, target) === resolve(planPath(ctx))) return;
return { block: true, reason: `Planning is read-only: only ${planRel(ctx)} may be written. Agree the plan, then choose Ready.` };
}
if (event.toolName === "bash" && !isPlanningReadOnlyCommand(String((event.input as { command?: string }).command))) {
return { block: true, reason: "Planning is read-only: inspect facts without writes or pipes, then put the change in the plan." };
}
return;
}
});
@@ -413,10 +341,6 @@ export default function piGoalsExtension(pi: ExtensionAPI): void {
// PI: Print after Pi settles. agent_end is still streaming, so its message queues behind the menu.
pi.on("agent_settled", async (_event, ctx) => {
if (state.phase === "working") {
settleAuto(ctx);
return;
}
if (state.phase !== "planning" || !ctx.hasUI) return;
let printed = "";
while (true) {
@@ -445,17 +369,27 @@ export default function piGoalsExtension(pi: ExtensionAPI): void {
}
if (choice === "Cancel") {
rmSync(planPath(ctx), { force: true });
state = { ...state, phase: null, planVersion: null };
state = { ...state, phase: null, supervisorPaneId: null, approvalId: null, planVersion: null };
persist();
updateWidget(ctx);
ctx.ui.notify("Plan discarded.", "info");
return;
}
if (choice !== "Ready") return;
state = { ...state, phase: "working" };
persist();
updateWidget(ctx);
pi.sendUserMessage(`Work the goals in ${planPath(ctx)}. Pick an open goal, mark it active ([/]), work its subtasks, and when its discriminator is satisfied fill its evidence: list, then call CompleteGoal with the goal's text. Keep the plan file current as you go.`, { deliverAs: "followUp" });
try {
await startSupervisor(ctx);
state = { ...state, phase: "working" };
resyncReason = "The plan was approved.";
persist();
updateWidget(ctx);
ctx.ui.notify(`Visible supervisor opened in Herdr pane ${state.supervisorPaneId}.`, "info");
pi.sendUserMessage("The plan is approved. Begin implementation as the worker.");
} catch (error) {
ctx.ui.notify(`Goal supervisor could not start: ${error instanceof Error ? error.message : String(error)}`, "warning");
state = { ...state, phase: "planning", supervisorPaneId: null, approvalId: null };
persist();
updateWidget(ctx);
}
return;
}
});
@@ -467,25 +401,16 @@ export default function piGoalsExtension(pi: ExtensionAPI): void {
.pop() as { data?: PlanState } | undefined;
state = {
phase: last?.data?.phase ?? null,
judgeModel: last?.data?.judgeModel ?? null,
supervisorModel: last?.data?.supervisorModel ?? null,
supervisorPaneId: last?.data?.supervisorPaneId ?? null,
approvalId: last?.data?.approvalId ?? null,
planVersion: last?.data?.planVersion ?? null,
autoIntervalMs: last?.data?.autoIntervalMs ?? null,
autoPaused: last?.data?.autoPaused ?? false,
};
lastSeenWorkingSet = foldPlan(readPlan(ctx));
autoLastWorkingSet = lastSeenWorkingSet;
planningContextPending = state.phase === "planning";
resyncReason = state.phase === "working" ? "New session." : null;
updateWidget(ctx);
scheduleAutoContinue(ctx);
});
pi.on("session_shutdown", async () => {
clearAutoTimer();
});
// --- the one blessed tool: CompleteGoal ---------------------------------------------------------
pi.registerTool({
name: "CompleteGoal",
label: "Goal signoff",
@@ -493,49 +418,36 @@ export default function piGoalsExtension(pi: ExtensionAPI): void {
parameters: Type.Object({
goal: Type.String({ description: completeGoalParamDescription }),
}),
async execute(_id, params, signal, onUpdate, ctx) {
if (state.phase === "planning") return result("Planning is not approved. Choose Ready before signing off a goal.", true);
async execute(_id, params, _signal, _onUpdate, ctx) {
if (state.phase !== "working") return result("Planning is not approved. Choose Ready before signing off a goal.", true);
if (!state.approvalId) return result("Goal sign-off blocked: no current supervisor review.", true);
const plan = readPlan(ctx);
if (!plan.trim()) return result(`No plan file at ${planRel(ctx)}. Run /goals to draft one.`, true);
const judgeModel = state.judgeModel ?? (ctx.model ? `${ctx.model.provider}/${ctx.model.id}` : null);
onUpdate?.({ content: [{ type: "text", text: `Read-only judge (${judgeModel ?? "pi default"}) inspecting: ${params.goal}` }], details: {} });
// decideSignOff runs the judge and derives the outcome + the one log line. judgeModel is never
// checked pre-emptively: null just means pi's configured default runs (buildJudgeArgs omits
// --model), so accepted_inconclusive always means "the judge ran but failed", never "no model".
let judgeRaw: JudgeResult | null = null;
const outcome = await decideSignOff({ goal: params.goal, plan, planRel: planRel(ctx), judgeModel }, signal, async (task) => {
judgeRaw = await runJudge(task, judgeModel, ctx.cwd, signal);
return judgeRaw;
});
// Persist the judge's full transcript so "did the judge really re-run verify?" is answerable
// after the fact (dogfood finding: with only the one log line, an accept is unauditable).
let transcriptNote = "";
if (judgeRaw !== null) {
const raw: JudgeResult = judgeRaw;
mkdirSync(join(ctx.cwd, ".pi", "judge"), { recursive: true });
const rel = `.pi/judge/${stamp().replace(/[: ]/g, "-")}-${process.hrtime.bigint()}.md`;
writeFileSync(join(ctx.cwd, rel), `goal: ${params.goal}\nmodel: ${judgeModel ?? "pi default"}\nerror: ${raw.error ?? "none"}\n\n${raw.output}\n`);
transcriptNote = ` (${rel})`;
const block = goalBlock(plan, params.goal);
if (!block) return result(`No unique open goal line matched "${params.goal}" in ${planRel(ctx)}.`, true);
let repository: ReturnType<typeof repositoryState>;
try {
repository = repositoryState(ctx.cwd);
} catch (error) {
return result(`Goal sign-off could not inspect the repository: ${error instanceof Error ? error.message : String(error)}`, true);
}
if (outcome.logEntry) {
// Sign-off write: tick the goal [x] (exact-subject match; dogfood showed agent bookkeeping
// is the drift point) and append the audit log line, one write. On wording drift the tick
// falls to the agent and the result says so -- both paths are explicit, never silent.
let updated = readPlan(ctx);
let tickNote = "";
if (outcome.logEntry.startsWith("signed off")) {
const ticked = tickGoal(updated, params.goal);
updated = ticked ?? updated;
tickNote = ticked
? `\n\nGoal ticked [x] in ${planRel(ctx)}.`
: `\n\nNo exact goal line matched your wording -- tick it [x] in ${planRel(ctx)} yourself.`;
}
writePlan(ctx, appendLog(updated, `${stamp()} ${outcome.logEntry}${transcriptNote}`));
updateWidget(ctx);
return result(outcome.resultText + tickNote, outcome.isError);
}
return result(outcome.resultText, outcome.isError);
if (!repository.cleanWorktree) return result("Goal sign-off blocked: worktree is dirty.", true);
const approval = readApproval(approvalPath(ctx.cwd, ctx.sessionManager.getSessionId(), params.goal));
if (!approvalMatches(approval, {
approvalId: state.approvalId,
goal: params.goal,
planPath: planPath(ctx),
goalBlockHash: hashGoalBlock(block),
repoRoot: repository.repoRoot,
head: repository.head,
tree: repository.tree,
cleanWorktree: repository.cleanWorktree,
})) return result("Goal sign-off blocked: no matching supervisor approval checkpoint. Request a fresh supervisor review.", true);
const ticked = tickGoal(plan, params.goal);
if (!ticked) return result(`No unique exact goal line matched "${params.goal}" in ${planRel(ctx)}.`, true);
writePlan(ctx, appendLog(ticked, `${stamp()} mechanically signed off "${params.goal}" after matching supervisor approval`));
updateWidget(ctx);
return result(`Sign-off accepted. Goal ticked [x] in ${planRel(ctx)}.`);
},
});
}
@@ -546,11 +458,20 @@ function result(text: string, isError = false) {
return { content: [{ type: "text" as const, text }], details: {}, isError };
}
function isPlanningReadOnlyCommand(command: string): boolean {
if (/[|>]/.test(command)) return false;
return command.split(/&&|;/).every((part) => /^(?:cd\b|pwd|ls\b|git\s+(?:status|log|diff|show|branch)\b|rg\b|grep\b|find\b|head\b|tail\b|wc\b|stat\b|test\b)\b/.test(part.trim()));
function mutatingReadCommand(part: string): boolean {
return /(?:^|\s)--output(?:=|\s|$)|^find\b.*\s-(?:delete|exec|execdir|ok|okdir|fprint|fprintf|fls)(?:\s|$)/.test(part)
|| (/^git\s+branch\b/.test(part) && !/^git\s+branch(?:\s+(?:--show-current|--list|-a|--all|-r|--remotes|-v|-vv))*$/.test(part));
}
function isPlanningReadOnlyCommand(command: string): boolean {
if (/[|><`$\n\r]/.test(command)) return false;
return command.split(/&&|;/).every((raw) => {
const part = raw.trim();
return !mutatingReadCommand(part) && /^(?:cd\b|pwd|ls\b|git\s+(?:status|log|diff|show|branch)\b|rg\b|grep\b|find\b|head\b|tail\b|wc\b|stat\b|test\b)\b/.test(part);
});
}
/** Local time, not UTC: agents freehand-stamp their manual ## Log lines from the local clock they
* see, so a UTC tool stamp made the trail read as two different afternoons (dogfood finding). */
function stamp(): string {
@@ -559,98 +480,8 @@ function stamp(): string {
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`;
}
function oneLine(s: string): string {
return s.replace(/\s+/g, " ").trim().slice(0, 200);
}
/** A judge run's result: stdout output, plus an error string when the subprocess failed/timed out. */
export interface JudgeResult {
output: string;
error?: string;
}
/** Inputs to a sign-off decision. judgeModel is null when no explicit/session model is set. */
export interface SignOffInput {
goal: string;
plan: string;
/** The session's plan file, relative to cwd; the judge prompt names it. */
planRel: string;
judgeModel: string | null;
}
/** The outcome of a sign-off: the reply text, whether it's a hard error, and the one ## Log line to
* append (null when nothing should be written, e.g. aborted before any verdict). */
export interface SignOffOutcome {
resultText: string;
isError: boolean;
logEntry: string | null;
}
/** Run the judge and decide accept / reject / accepted_inconclusive. Pure aside from the injected
* judge runner, so the unit test can lock the fail-forward invariant: judgeModel is NEVER checked
* here, so a null model still reaches runJudge (pi's configured default runs it), and the only
* producers of accepted_inconclusive are the judge-error and no-VERDICT paths -- i.e. "the judge
* ran but failed", never "no model". The execute() wrapper does the plan-file write + widget.
* Exported for the unit test that locks this invariant. */
export async function decideSignOff(
input: SignOffInput,
signal: AbortSignal | undefined,
runJudgeFn: (task: string) => Promise<JudgeResult>,
): Promise<SignOffOutcome> {
const task = judgeUser({ goal: input.goal, plan: input.plan, planPath: input.planRel });
const judge = await runJudgeFn(task);
if (signal?.aborted) return { resultText: "Sign-off aborted.", isError: true, logEntry: null };
// Judge ran but failed/errored/timed out: fail forward, say so in the log.
if (judge.error) {
const partial = judge.output ? `\n\npartial judge output:\n${judge.output}` : "";
return {
resultText: `Judge ran but failed (${judge.error}). Accepted inconclusive — logged.${partial}`,
isError: false,
logEntry: `signed off "${input.goal}" (judge inconclusive: ran but failed: ${oneLine(judge.error)})`,
};
}
const verdictLine = judge.output.split("\n").find((l) => /^\s*VERDICT\s*:/i.test(l)) ?? "";
const verdict = /^\s*VERDICT\s*:\s*(accept|reject)\s*$/i.exec(verdictLine)?.[1]?.toLowerCase();
const reasoning = judge.output.length > 2000 ? `...\n${judge.output.slice(-2000)}` : judge.output;
if (verdict === "accept") {
const beforeVerdict = judge.output.slice(0, judge.output.indexOf(verdictLine));
const checks = /^#{0,6}\s*(?:\*\*)?checks(?:\*\*)?:\s*$[\s\S]*^[-*]\s+.+$/im.test(beforeVerdict);
if (!checks) {
return {
resultText: `Sign-off REJECTED. Missing:\nchecked-artifact list before VERDICT: accept\n\n--- judge ---\n${reasoning}`,
isError: true,
logEntry: `reject "${input.goal}": judge accept had no checked-artifact list`,
};
}
return {
resultText: `Sign-off ACCEPTED (log line appended).\n\n--- judge ---\n${reasoning}`,
isError: false,
logEntry: `signed off "${input.goal}" (judge accept)`,
};
}
if (verdict === "reject") {
const missing = judge.output.match(/missing\s*:\s*([\s\S]*)$/i)?.[1].trim() || judge.output.slice(-500);
return {
resultText: `Sign-off REJECTED. Missing:\n${missing}\n\n--- judge ---\n${reasoning}`,
isError: true,
logEntry: `reject "${input.goal}": ${oneLine(missing)}`,
};
}
// No VERDICT line: same fail-forward as a judge error -- the judge ran but didn't answer.
return {
resultText: `Judge returned no VERDICT line. Accepted inconclusive — logged.\n\n--- judge ---\n${reasoning || "(no output)"}`,
isError: false,
logEntry: `signed off "${input.goal}" (judge inconclusive: no VERDICT line)`,
};
}
/** Tick the goal line whose subject exactly matches `goal` (trimmed, case-insensitive) to [x].
* Null when there is no unique exact match (wording drift / duplicates) -- the caller then asks the
* agent to tick it itself. Reuses GOAL_LINE; deliberately NOT fuzzy, that's the judge's job. */
* Null when there is no unique exact match. Reuses GOAL_LINE and is deliberately not fuzzy. */
export function tickGoal(plan: string, goal: string): string | null {
const lines = plan.split("\n");
const want = goal.trim().toLowerCase();
@@ -686,65 +517,3 @@ export function appendInterview(text: string, answer: string): string {
lines.splice(insertAt, 0, ...entry);
return lines.join("\n");
}
/** Build the pi argv for the read-only judge. `--model` is omitted when no explicit/session model is
* set, so pi falls back to its configured default — the judge always runs. `--no-extensions` keeps
* the judge minimal and immune to a broken third-party extension taking down every sign-off.
* Exported for the unit test that locks these invariants. */
export function buildJudgeArgs(judgeModel: string | null): string[] {
const args = ["-p", "--no-session", "--no-extensions"];
if (judgeModel) args.push("--model", judgeModel);
args.push("--tools", JUDGE_TOOLS.join(","), "--exclude-tools", JUDGE_BLOCKED_TOOLS.join(","), "--append-system-prompt", judgeSystem);
return args;
}
/** Locate the pi binary the same way the oracle extension does, so spawning works under bun or node. */
function getPiInvocation(args: string[]): { command: string; args: string[] } {
const script = process.argv[1];
if (script && !script.startsWith("/$bunfs/root/") && existsSync(script)) return { command: process.execPath, args: [script, ...args] };
const execName = basename(process.execPath).toLowerCase();
if (!/^(node|bun)(\.exe)?$/.test(execName)) return { command: process.execPath, args };
return { command: "pi", args };
}
/** Spawn the read-only judge subprocess (plain `pi -p`: stdout is the final response text). */
async function runJudge(
task: string,
judgeModel: string | null,
cwd: string,
signal: AbortSignal | undefined,
): Promise<JudgeResult> {
const args = buildJudgeArgs(judgeModel);
args.push(task);
const inv = getPiInvocation(args);
// Runs in-place against this checkout; pi --no-session does not clone into the parent
// (proven by scripts/check-judge-footprint.sh).
return new Promise((resolvePromise) => {
let settled = false;
let stdout = "";
let stderr = "";
const done = (r: { output: string; error?: string }) => {
if (!settled) {
settled = true;
clearTimeout(timer);
resolvePromise(r);
}
};
const proc = spawn(inv.command, inv.args, { cwd, shell: false, stdio: ["ignore", "pipe", "pipe"], signal });
const timer = setTimeout(() => {
proc.kill();
done({ output: stdout.trim(), error: `judge timed out after ${JUDGE_TIMEOUT_MS / 1000}s` });
}, JUDGE_TIMEOUT_MS);
proc.stdout?.on("data", (d) => {
stdout += d.toString();
});
proc.stderr?.on("data", (d) => {
stderr += d.toString();
});
proc.on("close", (code) => {
if ((code ?? 0) !== 0) done({ output: stdout.trim(), error: stderr.trim() || `judge subprocess exited ${code ?? 1}` });
else done({ output: stdout.trim() });
});
proc.on("error", (e) => done({ output: stdout.trim(), error: `judge subprocess failed: ${e.message}` }));
});
}
+37 -122
View File
@@ -2,22 +2,18 @@
* pi-goals v2 — all model-facing text, in flow order.
*
* Design: the plan file is for LLMs and the human, not for TypeScript. No parser and no schema;
* the skeleton below is a convention the drafting prompt teaches, the working agent maintains with
* its normal Edit tool, and the judge reads natively. The harness does three things for a
* cooperative-but-confused model: memory (a transient re-send of the plan when it goes stale),
* format guidance (the skeleton), and fresh eyes (the read-only judge in CompleteGoal).
* the skeleton below is a convention the drafting prompt teaches. The main session implements it,
* while a visible forked Pi session supervises through pi-supervise.
*
* THE FOLD: everything above "## Log" is the working set (title, user voice, goals,
* discriminators) and is what gets re-sent on the reminder cadence. Everything below it (Log,
* Learnings, Appendix) is durable memory: unlimited, read on demand, and re-sent in full only at
* session start and after a compaction, which is where the settled context is actually needed.
* THE FOLD: everything above "## Log" is the short current-goal section. Everything below it
* (Log, Learnings, Appendix) is durable memory: unlimited, read on demand, and sent in full at
* session start and after compaction.
*
* Flow:
* SETUP (plan mode) 1. planDrafting — draft goals into the plan file (read-only), sent once
* EXEC, on cadence 2. reminder — the folded plan + upkeep nudge when it went stale
* EXEC, after compact 3. resync — the WHOLE file back, once
* SIGN-OFF, agent-side 4. completeGoal* — the one blessed tool's description
* SIGN-OFF, judge-side 5. judgeSystem/judgeUser — the one rigorous check
* EXEC, after compact 2. resync — the WHOLE file back, once
* SIGN-OFF, worker-side 3. completeGoal* — the one blessed tool's description
* SUPERVISION supervisor-session.ts — visible read-only supervisor
*
* The goal's test is the DISCRIMINATOR: the concrete observation that tells real success from the
* named subtle failure mode. Evidence is empty at planning and filled at sign-off.
@@ -33,16 +29,17 @@ You are in plan mode. You are making a short judgeable plan that captures the us
resolve a fact. Do not write or run code in this phase (edit/write are blocked except for the plan
file; don't mutate state via bash either).
2. Before you draft a goal, identify its object, observable result, scope, and any decision that the
human would need to approve later. If any is uncertain, reduce uncertainty now: inspect files or
search the web when they can answer, then ask the human to confirm your interpretation, pin down the
outcome or task, or approve an editorial or other preference choice. Do not present the review menu
with a placeholder goal such as "work out the thing", "improve it", or "investigate".
human would need to approve later. Ask at least three short, concrete questions that test whether you
understand the requested outcome, boundary, and how success will be judged. Inspect files or search the
web before asking when either can answer a fact. If the human does not answer a question, record that
point as unknown; do not silently replace it with an inference. Do not present the review menu with a
placeholder goal such as "work out the thing", "improve it", or "investigate".
3. For independent high-impact questions, build a decision tree and ask the whole frontier in one
round. Ask only questions worth the human's time, where the answer materially reduces uncertainty
while discovering the right plan. Each question must be short and self-contained: state the relevant
context, use the human's language and ASD-STE100
Simple Technical English, and give a recommended answer. Record each answer in ## Interview. Do not
make the plan final while material user decisions remain open.
Simple Technical English, and give a recommended answer. Record each answer, or the unanswered
unknown, in ## Interview. Do not make the plan final while material user decisions remain open.
4. State the user-visible result before the goals: one concrete sentence naming what the human will
inspect when this plan is done. Take it from the original request, not from your implementation plan.
Every requested artifact and action must survive into this sentence. An agent-inferred constraint may
@@ -58,13 +55,13 @@ Detail that doesn't change a goal or a discriminator belongs in the appendix, no
Right-size it:
- One goal per distinct judgeable outcome. Group related goals when it helps judge them together
and readability. The count flows from the outcomes.
- Describe outcomes in qualitative terms the judge and user can discriminate.
- Describe outcomes in qualitative terms the supervisor and user can discriminate.
- Use the users language or more precise don't transform "MV" into "knob" as it looses precision and is overloaded
- Don't invent metrics or thresholds for problems you haven't explored yet the judge should hopefully know it when it sees the outcome.
- Don't invent metrics or thresholds for problems you haven't explored yet - the supervisor should know it when it sees the outcome.
- Quantitative gates are fine only when you are certain they survive contact with reality.
- Subtasks are the steps inside a goal; add them when a goal has 3+ distinct steps, skip otherwise.
- Two goals that share one discriminator are one goal. Merge them.
- Keep the goal subject short. Put its important scope, failure modes, discriminator, tasks, and evidence in the indented block beneath it. The judge reads the whole block and the whole plan.
- Keep the goal subject short. Put its important scope, failure modes, discriminator, tasks, and evidence in the indented block beneath it. The supervisor reads the whole block and the whole plan.
- Keep the working set under 50 lines, excluding ## User voice. ## User voice has no line limit: quote
the human fully rather than shorten or paraphrase them. Everything below "## Log" is unlimited.
@@ -72,7 +69,7 @@ Style: Make it easy for a busy and forgetfull user to review. Use ASD-STE100 Sim
the same word for the same thing, and define a new terms at first use. Use redundant context for skim readers e.g. "our output - the cells, CV tag" is easy to read and reminds context. This covers the context
paragraph and the appendix too, not just the checklist. No all-caps headers and no bold spam. Just write less, add your voice less, persuade less, and burden the reader less.
Write the plan file in roughly this shape -- the file is read directly by the human and a judge model, so clarity beats conformance; small deviations are fine):
Write the plan file in roughly this shape -- the file is read directly by the human and the visible supervisor, so clarity beats conformance; small deviations are fine):
# <short plan title>
@@ -92,7 +89,7 @@ Write the plan file in roughly this shape -- the file is read directly by the hu
- subtle failure mode: <a way this could look done but isn't>
- discriminator: <the concrete observation that tells real success from that failure>
- verify: <optional shell command that exits 0 only when the discriminator passes; omit if not
testable. YOU run it at sign-off time and save its output as evidence; the judge only reads>
testable. The worker runs it and saves its output; the visible supervisor reads the evidence>
- tasks:
1. [ ] <subtask>
- evidence: (empty until sign-off)
@@ -122,9 +119,9 @@ Conventions:
none of the failure modes could fake. Ruling out failures is necessary, not sufficient.
- Make the discriminator a concrete, checkable observation about a real artifact (a file, a test
result, a committed diff, a metric), never about the plan file's own checkbox.
- evidence stays empty at planning; you fill it at sign-off and a fresh read-only judge checks it.
- evidence stays empty at planning; the worker fills it and the visible supervisor checks it.
Cite durable artifacts a future reader can open: committed files, test names, git diffs. .pi/ is
usually gitignored, so files there prove things only at judge time, not in history.
usually gitignored, so files there prove things only at supervisor review time, not in history.
- User-visible result: restate the original deliverable, not the proposed implementation. Every goal
must contribute to it. Future work may not defer any artifact or action named there.
- User voice: quote the human word for word, one line per requirement, as they say it. Never
@@ -142,12 +139,6 @@ Conventions:
When the goals are drafted, present them and say the plan is final. Do not begin execution.`;
/* ─────────────────────────────────────────────────────────────────────────
* 3. reminder — EXEC. Transient, never persisted, and only when the plan went stale for a couple of
* turns. pi-tasks tried a per-turn injection and deleted it: "wallpaper noise that trains the
* model to ignore the task block" (tintinweb/pi-tasks CHANGELOG.md:149). Carries the folded plan
* (above ## Log), because a nudge with no plan in it makes the model go read the file anyway.
* ──────────────────────────────────────────────────────────────────────── */
export function planningState(planPath: string): string {
return `\
[PLANNING MODE]
@@ -160,45 +151,25 @@ work, mark a goal [/] or [x], or sign off a goal. The plan is not approved until
Ready.`;
}
export function reminder(foldedPlan: string, planRel: string): string {
return `\
<system-reminder>
Your plan (${planRel}, above the fold; the log, learnings and appendix are in the file):
${foldedPlan}
Keep it current as you work, with your normal edit tool:
- tick finished subtasks ([/] in progress), add discovered ones
- append ONE short line to ## Log, and a line to ## Learnings for a gotcha worth keeping
- when the active goal's discriminator is satisfied, fill its evidence: list (each item = a durable
artifact + a verbatim quote you actually observed + a short read of it), then call CompleteGoal.
Don't tick a goal [x] before CompleteGoal accepts; the sign-off log line is the audit trail.
- if the working set has grown long, prune finished goals (their evidence lives in git history and
## Log) and move settled detail down to ## Appendix, which is unlimited
- the human's latest message outranks this plan. If it corrects the deliverable or scope, amend the
user-visible result, user voice, and affected goals before continuing; don't defend the old plan
- otherwise keep working toward the active goal; don't stop to ask unless genuinely blocked
</system-reminder>`;
}
/* ─────────────────────────────────────────────────────────────────────────
* 3b. resync — EXEC, one-shot at session start and after a compaction: the WHOLE file back,
* 2. resync — EXEC, one-shot at session start and after a compaction: the WHOLE file back,
* appendix included. Modelled on pi-goal-x's [POST-COMPACTION RESYNC] one-shot. This is the
* only place the below-the-fold sections are pushed; otherwise the agent reads them on demand.
* ──────────────────────────────────────────────────────────────────────── */
export function resync(plan: string, planRel: string, why: string): string {
return `\
<system-reminder>
${why} This is the whole plan file (${planRel}), appendix included. Keep working the active goal;
edit the file directly as you go. The human's latest message outranks the plan: if it corrects the
deliverable or scope, amend the plan rather than preserving an obsolete decision.
${why} This is the whole plan file (${planRel}), appendix included. You are the implementation worker.
Keep the high-level goal and human intent stable and do the work directly. A visible read-only Pi
session supervises you through pi-supervise. The human's latest message outranks the plan: if it
changes scope, amend the plan rather than preserving an obsolete decision.
${plan}
</system-reminder>`;
}
/* ─────────────────────────────────────────────────────────────────────────
* 4. completeGoal — SIGN-OFF, agent-side: the one blessed tool
* 3. completeGoal — SIGN-OFF, agent-side: the one blessed tool
* ──────────────────────────────────────────────────────────────────────── */
export const completeGoalDescription =
"Sign off a goal once its discriminator is satisfied. First fill the goal's evidence: list in the " +
@@ -206,70 +177,14 @@ export const completeGoalDescription =
"table plus how to read it, a metric plus what it shows -- not a bare claim). Quote verbatim from " +
"output you actually observed; never reconstruct numbers from memory. If you couldn't see an " +
"output, rerun it or write that you couldn't -- an honest gap beats a plausible fabrication. If " +
"the goal names a verify: command, run it yourself first and save its output to a file cited in " +
"the evidence: the judge cannot execute anything and will reject a claimed pass with no saved " +
"output. The read must show success POSITIVELY happened, not just that failures were avoided. " +
"Check that the claimed result uses the artifact and outcome named in User-visible result and does " +
"not substitute an agent-inferred deliverable. Then call this with the goal's text (the line after " +
"'goal:'; small wording drift is fine). A " +
"fresh strictly-read-only judge inspects the LIVE WORKING TREE (uncommitted changes included; " +
"committing first is for durability, not visibility) and returns accept or reject with what's " +
"missing. On accept (or if the judge itself failed), a sign-off line is appended to ## Log " +
"and the goal is ticked [x] for you; the result says if you must tick it yourself. On reject the " +
"goal stays open.";
"the goal names a verify: command, direct the worker to run it and save its output to a file cited " +
"in the evidence. The supervisor may run an allowed read-only verification command, but must not " +
"create the evidence file itself. The visible supervisor must reject a claimed pass with no saved " +
"output. The read must show success POSITIVELY happened, not just that failures were avoided. The " +
"supervisor records an approval checkpoint only after it inspected the current plan, repository, " +
"evidence, verify output, and a stopped worker view with no active work. Then the worker calls this " +
"tool with the exact goal text. This tool independently checks that checkpoint " +
"against the exact current goal block, HEAD/tree, and clean worktree before it appends the sign-off to " +
"## Log and ticks the goal [x]. If any check differs, it fails closed and requires a fresh supervisor review.";
export const completeGoalParamDescription = "The goal's text: the line after 'goal:' in the plan file.";
/* ─────────────────────────────────────────────────────────────────────────
* 5. judge — SIGN-OFF, judge-side: the one rigorous check. Runs on a fresh
* read-only pi subprocess (--no-session) so it never sees the working
* agent's transcript. It gets the WHOLE plan file: it finds the goal,
* reads discriminator/failure modes/evidence itself (no parser between).
* ──────────────────────────────────────────────────────────────────────── */
export const judgeSystem = `\
You are a strictly read-only reviewer signing off a coding goal. You cannot execute anything: judge
by reading (read/grep/find/ls). Never re-run the work or its verify command -- it may be a 10-hour
job; the agent must bring you its saved output. Your job is evidence discipline, checked in order:
0. Task fidelity? Read User-visible result and User voice first. Reject if this goal contradicts,
replaces, or defers the requested artifact or outcome. Agent-inferred scope is not authority.
1. Anything here? An empty or placeholder evidence: list -> reject: "there's nothing here -- fill
the evidence and try again."
2. Quoted and attributed? Each item needs a source (file path / command) plus a verbatim quote of
what was observed, plus a one-line read. A bare claim -> reject: "you didn't quote and
attribute it."
3. Provenance? It must be visible HOW each result was produced (the command run, where its output
was saved). Results with no origin -> reject: "I see the results, but how did you get them?"
4. Spot-check: open the cited files. A quote or number that doesn't match what's on disk means the
evidence was reconstructed from memory, not observed -> reject and ask for re-observed
evidence, even if the goal otherwise looks met.
5. Substance, only once 1-4 hold: does the evidence show the discriminator's success signal
POSITIVELY happened -- not just that the named failure modes were dodged; a run can rule out
every trap and still have produced nothing. Is each subtle failure mode genuinely ruled out,
not just unmentioned? If the goal names a verify: command, its saved output must be among the
evidence, and the command must actually test the discriminator rather than pass tautologically.
Before the verdict, write this heading: checks:. Put one concise bullet under it for each artifact you actually read:
path, verbatim observed quote, and what that observation establishes. This is an inspectable review
record, not hidden reasoning. Do not write a checks bullet for a file you did not open.
Finish with exactly these two lines and nothing after:
VERDICT: accept | reject
missing: <empty if accept; otherwise a short list of what's needed before this can be accepted>`;
export function judgeUser(p: { goal: string; plan: string; planPath: string }): string {
return `\
The working agent claims this goal is complete:
goal: ${p.goal}
Below is the full plan file (${p.planPath}). Find that goal in it (tolerate small wording drift; if
you cannot find a matching goal at all, reject and say so). Read User-visible result and User voice
first, then its discriminator, subtle failure modes, verify command, and evidence list.
--- plan file ---
${p.plan}
--- end plan file ---
Read the cited artifacts (you cannot execute anything), then give your VERDICT.`;
}
+52
View File
@@ -0,0 +1,52 @@
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
const PAIR_EVENT = "pi-supervise:pair:v1";
const WORKER_STATE_EVENT = "pi-supervise:worker-state:v1";
const WORKER_PAIRED_EVENT = "pi-supervise:worker-paired:v1";
const API_READY_EVENT = "pi-supervise:api-ready:v1";
const TIMEOUT_MS = 15_000;
export const SUPERVISOR_STARTUP_TIMEOUT_MS = 5 * 60_000;
type Events = { emit(name: string, value: unknown): boolean; on(name: string, handler: (value: any) => void): void };
function wait<T>(start: (resolve: (value: T) => void, reject: (error: Error) => void) => void, message: string, timeoutMs = TIMEOUT_MS): Promise<T> {
return new Promise((resolve, reject) => {
const timer = setTimeout(() => reject(new Error(message)), timeoutMs);
start((value) => { clearTimeout(timer); resolve(value); }, (error) => { clearTimeout(timer); reject(error); });
});
}
export function pairWithPiSupervise(pi: ExtensionAPI, workerIntercomId: string, goal: string): Promise<void> {
const events = (pi as unknown as { events: Events }).events;
return wait((resolve, reject) => events.emit(PAIR_EVENT, { version: 1, workerIntercomId, goal, resolve, reject }), "pi-supervise did not accept the visible-supervisor pairing request.");
}
export interface WorkerPiSupervise {
intercomId: string;
waitForPair(timeoutMs?: number): Promise<void>;
}
export function workerPiSupervise(pi: ExtensionAPI, timeoutMs = TIMEOUT_MS): Promise<WorkerPiSupervise> {
const events = (pi as unknown as { events: Events }).events;
let paired = false;
let resolvePair: (() => void) | undefined;
events.on(WORKER_PAIRED_EVENT, () => {
paired = true;
resolvePair?.();
});
return wait((resolve, reject) => {
let resolved = false;
const request = () => events.emit(WORKER_STATE_EVENT, (state: { intercomId?: string; paired?: boolean }) => {
if (resolved) return;
if (!state.intercomId) return reject(new Error("pi-supervise returned no worker intercom ID."));
if (state.paired) return reject(new Error("This worker is already paired with a supervisor. Stop that supervision before selecting Ready."));
resolved = true;
resolve({
intercomId: state.intercomId,
waitForPair: (pairTimeoutMs = timeoutMs) => paired ? Promise.resolve() : wait((pairResolve) => { resolvePair = pairResolve; }, "The visible supervisor did not pair with this worker.", pairTimeoutMs),
});
});
events.on(API_READY_EVENT, request);
request();
}, "pi-supervise did not publish this worker's intercom state.", timeoutMs);
}
+192
View File
@@ -0,0 +1,192 @@
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
import { Type } from "typebox";
import { approvalPath, goalBlock, hashGoalBlock, repositoryState, verifyOutputPath, writeApproval } from "./approval.js";
import { pairWithPiSupervise } from "./supervise.js";
const BOOTSTRAPPED = "pi-goals-visible-supervisor-v1";
const INITIAL_COMPACT_AT_TOKENS = 20_000;
const COMPACT_AT_TOKENS = 100_000;
interface SupervisorConfig {
workerSessionId: string;
workerIntercomId: string;
ownerSessionId: string;
planPath: string;
approvalId: string;
}
function result(text: string, isError = false) {
return { content: [{ type: "text" as const, text }], details: {}, isError };
}
function requiredEnv(name: string): string {
const value = process.env[name]?.trim();
if (!value) throw new Error(`${name} is required in a pi-goals supervisor session.`);
return value;
}
function config(): SupervisorConfig {
return {
workerSessionId: requiredEnv("PI_GOALS_WORKER_ID"),
workerIntercomId: requiredEnv("PI_GOALS_WORKER_INTERCOM_ID"),
ownerSessionId: requiredEnv("PI_GOALS_OWNER_SESSION_ID"),
planPath: resolve(requiredEnv("PI_GOALS_PLAN_PATH")),
approvalId: requiredEnv("PI_GOALS_APPROVAL_ID"),
};
}
function hasEvidenceEntry(block: string): boolean {
const lines = block.split("\n");
for (let index = 0; index < lines.length; index++) {
const evidence = /^\s*[-*]\s+evidence:\s*(.*)$/i.exec(lines[index]);
if (!evidence) continue;
if (evidence[1].trim() && !/^\(empty until sign-off\)$/i.test(evidence[1].trim())) return true;
const indent = lines[index].match(/^\s*/)?.[0].length ?? 0;
for (let child = index + 1; child < lines.length; child++) {
const childIndent = lines[child].match(/^\s*/)?.[0].length ?? 0;
if (lines[child].trim() && childIndent <= indent) break;
const entry = /^\s+[-*]\s+(.+?)\s*$/.exec(lines[child]);
if (entry?.[1].trim()) return true;
}
}
return false;
}
function latestWorkerView(ctx: ExtensionContext): string | null {
for (const entry of [...ctx.sessionManager.getBranch()].reverse()) {
const message = (entry as { type?: string; message?: { role?: string; content?: unknown[] } }).message;
if ((entry as { type?: string }).type !== "message" || message?.role !== "user" || !Array.isArray(message.content)) continue;
for (const part of message.content) {
const text = (part as { type?: string; text?: string }).type === "text" ? (part as { text?: string }).text : undefined;
if (text?.startsWith("The worker ")) return text;
}
}
return null;
}
function supervisorPrompt(settings: SupervisorConfig): string {
return `You are the visible pi-goals supervisor for ${settings.planPath}. You are a stronger, read-only reviewer. The other Pi session is the implementation worker and keeps the full conversation. You keep the high-level intent from the compacted planning conversation and pi-supervise worker views. The complete plan at ${settings.planPath} is the source of truth; read it directly after every compaction.
Use pi-supervise to inspect and steer the worker. Give one concrete instruction when work is incomplete. Do not edit files. For each open goal, inspect its exact plan block, repository state, cited evidence, and a saved nonempty verification-output file. When its discriminator is positively satisfied and the worker view says no work is active, call ApproveGoal with that repository-relative path. Then call steer and tell the worker to call CompleteGoal with the exact goal text. Do not call done until every plan goal is [x]. -- PI[gpt-5.6-sol]`;
}
export function isVisibleSupervisor(): boolean {
return process.env.PI_GOALS_ROLE === "supervisor";
}
export function registerVisibleSupervisor(pi: ExtensionAPI): void {
const settings = config();
let compacting = false;
let bootstrapping = false;
const bootstrap = async (ctx: ExtensionContext): Promise<void> => {
if (bootstrapping) return;
const entries = ctx.sessionManager.getEntries();
if (entries.some((entry: { type?: string; customType?: string }) => entry.type === "custom" && entry.customType === BOOTSTRAPPED)) return;
bootstrapping = true;
try {
await pairWithPiSupervise(pi, settings.workerIntercomId, settings.planPath);
pi.appendEntry(BOOTSTRAPPED, { version: 1, workerSessionId: settings.workerSessionId, planPath: settings.planPath });
pi.sendUserMessage("Supervision is paired. Inspect the worker and give its next concrete instruction.");
} catch (error) {
ctx.ui.notify(`Supervisor startup failed: ${error instanceof Error ? error.message : String(error)}`, "error");
}
};
const bootstrapAfterInitialCompaction = (ctx: ExtensionContext): void => {
const tokens = ctx.getContextUsage()?.tokens;
if (typeof tokens === "number" && tokens <= INITIAL_COMPACT_AT_TOKENS) {
void bootstrap(ctx);
return;
}
compacting = true;
ctx.compact({
customInstructions: `Preserve the user's high-level intent, decisions, unresolved risks, and the supervisor's remit. The canonical plan is ${settings.planPath}; it remains available directly and must not be replaced by this summary.`,
onComplete: () => {
compacting = false;
ctx.ui.notify("Supervisor planning context compacted before work started.", "info");
void bootstrap(ctx);
},
onError: (error) => {
compacting = false;
ctx.ui.notify(`Supervisor startup compaction failed: ${error.message}`, "error");
},
});
};
pi.on("session_start", async (_event, ctx) => {
setImmediate(() => { bootstrapAfterInitialCompaction(ctx); });
});
pi.on("before_agent_start", async (_event, ctx) => {
return { systemPrompt: `${ctx.getSystemPrompt()}\n\n${supervisorPrompt(settings)}` };
});
pi.on("agent_settled", async (_event, ctx) => {
if (compacting || (ctx.getContextUsage()?.tokens ?? 0) < COMPACT_AT_TOKENS) return;
compacting = true;
ctx.compact({
customInstructions: `Keep the user's high-level intent, current plan state, unresolved risks, approval decisions, and the supervisor's own concise findings. Remove old worker views and implementation detail.`,
onComplete: () => {
compacting = false;
ctx.ui.notify("Supervisor context compacted at 100k tokens.", "info");
},
onError: (error) => {
compacting = false;
ctx.ui.notify(`Supervisor compaction failed: ${error.message}`, "error");
},
});
});
pi.registerTool({
name: "ApproveGoal",
label: "Approve goal",
executionMode: "sequential",
description: "Record approval after inspecting the current goal, repository, evidence, and a saved nonempty verification-output file, with a stopped worker view and no active work.",
parameters: Type.Object({
goal: Type.String({ description: "Exact text after goal: in the plan." }),
verifyOutputPath: Type.String({ description: "Nonempty repository-relative file containing the verification output you inspected." }),
}),
async execute(_id, params, _signal, _onUpdate, ctx) {
const view = latestWorkerView(ctx);
if (!view?.startsWith("The worker stopped.")) return result("Cannot approve without a current stopped-worker view.", true);
const pendingTool = view.match(/^tool calls with no result: (?!none$)(.+)$/m);
const pendingChild = view.match(/^child pi processes still running: (?!none$)(.+)$/m);
if (pendingTool || pendingChild) return result(`Cannot approve while work is active: ${(pendingTool ?? pendingChild)![1]}`, true);
let plan: string;
let repository: ReturnType<typeof repositoryState>;
try {
plan = readFileSync(settings.planPath, "utf8");
repository = repositoryState(ctx.cwd);
} catch (error) {
return result(`Cannot inspect approval inputs: ${error instanceof Error ? error.message : String(error)}`, true);
}
if (!repository.cleanWorktree) return result("Cannot approve with a dirty worktree. Commit the worker changes first.", true);
const block = goalBlock(plan, params.goal);
if (!block) return result(`Cannot approve: no unique open goal matches "${params.goal}".`, true);
if (!hasEvidenceEntry(block)) return result("Cannot approve without a nonblank evidence entry in the goal block.", true);
const verifiedOutput = verifyOutputPath(repository.repoRoot, params.verifyOutputPath);
if (!verifiedOutput) return result("Cannot approve without a nonempty repository-relative verification-output file.", true);
const path = approvalPath(ctx.cwd, settings.ownerSessionId, params.goal);
writeApproval(path, {
version: 3,
verdict: "accept",
approvalId: settings.approvalId,
goal: params.goal,
planPath: settings.planPath,
goalBlockHash: hashGoalBlock(block),
repoRoot: repository.repoRoot,
head: repository.head,
tree: repository.tree,
cleanWorktree: true,
inspected: { plan: true, repository: true, evidence: true, verifyOutput: true },
verifyOutputPath: verifiedOutput,
supervisor: { sessionId: ctx.sessionManager.getSessionId(), runId: null },
timestamp: new Date().toISOString(),
});
return result(`Approval recorded for "${params.goal}". Now steer the worker to call CompleteGoal.`);
},
});
}
-81
View File
@@ -1,81 +0,0 @@
import { describe, expect, it, vi } from "vitest";
import { decideSignOff, type JudgeResult } from "../src/index.js";
import { judgeSystem } from "../src/prompts.js";
// decideSignOff is the fail-forward invariant: judgeModel is NEVER checked pre-emptively, so a null
// model still reaches runJudge (pi's configured default runs it), and the only producers of
// accepted_inconclusive are the judge-error and no-VERDICT paths -- i.e. "the judge ran but failed",
// never "no model". The judge runner is injected so these tests never spawn a real subprocess.
const input = { goal: "x", plan: "# plan\n", planRel: ".pi/plan/s1.md", judgeModel: null };
describe("decideSignOff (fail-forward invariant)", () => {
it("proceeds to runJudge even when judgeModel is null (no pre-emptive 'no model' inconclusive)", async () => {
const output = "## checks:\n- evidence.txt: `PASS`; the saved check passed\n\nThe artifact proves the gate passed.\nVERDICT: accept\nmissing:";
const runJudge = vi.fn().mockResolvedValue({ output });
const out = await decideSignOff({ ...input, plan: "# plan\n1. [ ] goal: x\n" }, undefined, runJudge);
expect(runJudge).toHaveBeenCalledOnce(); // reached the judge -- no pre-emptive return on null model
expect(out.isError).toBe(false);
expect(out.logEntry).toContain("judge accept");
expect(out.resultText).toContain("evidence.txt: `PASS`");
});
it("rejects an accept verdict without a checked-artifact list", async () => {
const runJudge = vi.fn().mockResolvedValue({ output: "VERDICT: accept\nmissing:" });
const out = await decideSignOff(input, undefined, runJudge);
expect(out.isError).toBe(true);
expect(out.resultText).toContain("checked-artifact list");
expect(out.logEntry).toContain("no checked-artifact list");
});
it("a judge-subprocess error yields accepted_inconclusive with a 'ran but failed' reason", async () => {
const runJudge = vi.fn().mockResolvedValue({ output: "", error: "judge subprocess exited 1" } satisfies JudgeResult);
const out = await decideSignOff(input, undefined, runJudge);
expect(runJudge).toHaveBeenCalledOnce();
expect(out.isError).toBe(false); // accepted inconclusive, not a hard error that blocks the agent
expect(out.resultText.toLowerCase()).toContain("accepted inconclusive");
expect(out.resultText).toContain("ran but failed"); // inconclusive means ran but failed, not "no model"
expect(out.logEntry).toContain("ran but failed");
expect(out.logEntry).toContain("subprocess exited 1");
});
it("a judge timeout is also accepted_inconclusive (ran but failed)", async () => {
const runJudge = vi.fn().mockResolvedValue({ output: "partial", error: "judge timed out after 600s" });
const out = await decideSignOff(input, undefined, runJudge);
expect(out.isError).toBe(false);
expect(out.resultText.toLowerCase()).toContain("accepted inconclusive");
expect(out.logEntry).toContain("ran but failed");
expect(out.logEntry).toContain("timed out");
expect(out.resultText).toContain("partial judge output:\npartial");
});
it("no VERDICT line is accepted_inconclusive too (judge ran but didn't answer)", async () => {
const runJudge = vi.fn().mockResolvedValue({ output: "I looked but forgot the verdict line" });
const out = await decideSignOff(input, undefined, runJudge);
expect(out.isError).toBe(false);
expect(out.resultText).toContain("no VERDICT line");
expect(out.logEntry).toContain("no VERDICT line");
});
it("rejects when the judge returns VERDICT: reject", async () => {
const runJudge = vi.fn().mockResolvedValue({ output: "VERDICT: reject\nmissing: evidence, tests" });
const out = await decideSignOff({ ...input, judgeModel: "openrouter/claude" }, undefined, runJudge);
expect(out.isError).toBe(true);
expect(out.resultText).toContain("REJECTED");
expect(out.resultText).toContain("evidence, tests");
expect(out.logEntry).toContain("reject");
});
it("requires a concise checked-artifact review, not private reasoning", () => {
expect(judgeSystem).toContain("checks:");
expect(judgeSystem).toContain("not hidden reasoning");
});
it("writes nothing when aborted after the judge ran", async () => {
const runJudge = vi.fn().mockResolvedValue({ output: "VERDICT: accept" });
const ctrl = new AbortController();
ctrl.abort();
const out = await decideSignOff(input, ctrl.signal, runJudge);
expect(out.logEntry).toBeNull();
expect(out.isError).toBe(true);
});
});
+1 -1
View File
@@ -28,7 +28,7 @@ const plan = `# Plan
## Appendix (context, not approved)
${"filler line\n".repeat(200)}`;
describe("foldPlan (the working set is what gets re-sent; below ## Log is durable memory)", () => {
describe("foldPlan (current goals are above ## Log; durable memory is below it)", () => {
it("keeps the title, user voice and goals", () => {
const folded = foldPlan(plan);
expect(folded).toContain("keep it under 50 lines");
+153 -231
View File
@@ -1,286 +1,208 @@
import { execFileSync } from "node:child_process";
import { EventEmitter } from "node:events";
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
import { describe, expect, it, vi } from "vitest";
import piGoalsExtension from "../src/index.js";
import { afterEach, describe, expect, it, vi } from "vitest";
import { approvalPath, goalBlock, hashGoalBlock, repositoryState, writeApproval } from "../src/approval.js";
function setup(
selectChoices: Array<string | undefined>,
editorChoices: Array<string | undefined> = [],
editPlan?: () => Promise<string | undefined>,
) {
const openSupervisorPane = vi.fn(async () => "pane-2");
const closeSupervisorPane = vi.fn(async () => undefined);
vi.mock("../src/herdr.js", () => ({ openSupervisorPane, closeSupervisorPane }));
const { default: piGoalsExtension, isMainSession } = await import("../src/index.js");
function setup(selectChoices: Array<string | undefined>, editorChoices: Array<string | undefined> = []) {
const cwd = mkdtempSync(join(tmpdir(), "pi-goals-flow-"));
writeFileSync(join(cwd, ".gitignore"), ".pi/\n");
writeFileSync(join(cwd, "verify.txt"), "PASS\n");
execFileSync("git", ["init", "-q"], { cwd });
execFileSync("git", ["add", ".gitignore", "verify.txt"], { cwd });
execFileSync("git", ["-c", "user.name=test", "-c", "user.email=test@example.com", "commit", "-qm", "initial"], { cwd });
const commands = new Map<string, any>();
const hooks = new Map<string, any>();
const tools = new Map<string, any>();
const entries: Array<{ type: string; customType: string; data: unknown }> = [];
const events: string[] = [];
const messages: Array<{ content: string; display?: boolean }> = [];
const notifications: string[] = [];
const ctx = {
cwd,
hasUI: true,
isIdle: () => true,
sessionManager: { getSessionId: () => "session-a", getEntries: () => entries },
getSystemPrompt: () => "base prompt",
sessionManager: {
getSessionId: () => "session-a",
getSessionFile: () => join(cwd, "session.jsonl"),
getEntries: () => entries,
},
ui: {
theme: { fg: (_kind: string, text: string) => text },
setStatus: () => {},
setWidget: () => {},
notify: () => {},
select: async () => {
events.push("select");
return selectChoices.shift();
},
editor: async () => {
events.push("editor");
return editPlan ? editPlan() : editorChoices.shift();
},
setStatus: vi.fn(),
setWidget: vi.fn(),
notify: (text: string) => notifications.push(text),
select: async () => selectChoices.shift(),
editor: async () => editorChoices.shift(),
},
};
const events = new EventEmitter();
events.on("pi-supervise:worker-state:v1", (reply) => reply({ intercomId: "worker-intercom" }));
openSupervisorPane.mockImplementation(async () => {
queueMicrotask(() => events.emit("pi-supervise:worker-paired:v1", { supervisorIntercomId: "supervisor-intercom" }));
return "pane-2";
});
const pi = {
events,
registerCommand: (name: string, command: any) => commands.set(name, command),
on: (name: string, handler: any) => hooks.set(name, handler),
appendEntry: (customType: string, data: unknown) => entries.push({ type: "custom", customType, data }),
registerTool: (tool: any) => tools.set(tool.name, tool),
sendMessage: (message: { content: string; display?: boolean }) => {
events.push("display");
messages.push(message);
},
sendUserMessage: (message: string) => messages.push({ content: message }),
getAllTools: () => [],
sendMessage: (message: { content: string; display?: boolean }) => messages.push(message),
sendUserMessage: (content: string) => messages.push({ content }),
};
piGoalsExtension(pi as unknown as ExtensionAPI);
return { commands, ctx, cwd, entries, events, hooks, messages, tools };
return { commands, ctx, cwd, entries, events, hooks, messages, notifications, tools };
}
describe("/goals draft flow", () => {
it("preserves prior drafts, displays the plan before Refine, and records editor notes", async () => {
const flow = setup(["Refine"], ["Keep two columns.\nDo not add a filter."]);
try {
const legacy = join(flow.cwd, ".pi/plan/session-a.md");
mkdirSync(join(flow.cwd, ".pi/plan"), { recursive: true });
writeFileSync(legacy, "old plan");
await flow.commands.get("goals").handler("first objective", flow.ctx);
const v1 = join(flow.cwd, ".pi/plan/session-a-v1.md");
expect(readFileSync(v1, "utf-8")).toBe("");
expect(readFileSync(legacy, "utf-8")).toBe("old plan");
const plan = "# First plan\n\n## Goals\n\n1. [ ] goal: preserve this\n\n## Appendix (context, not approved)\nold context\n";
mkdirSync(join(flow.cwd, ".pi/plan"), { recursive: true });
writeFileSync(v1, plan);
await flow.hooks.get("input")({ text: "The result must preserve column order.", source: "interactive" }, flow.ctx);
function writePlan(cwd: string, content: string): string {
const path = join(cwd, ".pi/plan/session-a-v1.md");
mkdirSync(join(cwd, ".pi/plan"), { recursive: true });
writeFileSync(path, content);
return path;
}
function approvedPlan(cwd: string): string {
return writePlan(cwd, "# Plan\n\n## Goals\n\n1. [ ] goal: make the file\n - discriminator: output exists\n - evidence:\n - `result.txt`: contains ok\n\n## Log\n");
}
afterEach(() => {
openSupervisorPane.mockClear();
closeSupervisorPane.mockClear();
});
describe("/goals flow", () => {
it("preserves drafts, records the interview, and keeps planning read-only", async () => {
const flow = setup(["Refine"], ["Keep two columns."]);
try {
await flow.commands.get("goals").handler("first objective", flow.ctx);
const first = writePlan(flow.cwd, "# Plan\n\n## Goals\n\n1. [ ] goal: preserve this\n\n## Interview\n");
await flow.hooks.get("input")({ text: "Preserve column order.", source: "interactive" }, flow.ctx);
await flow.hooks.get("agent_settled")({}, flow.ctx);
expect(flow.events).toEqual(["display", "select", "editor"]);
expect(readFileSync(first, "utf8")).toContain("> Preserve column order.");
expect(readFileSync(first, "utf8")).toContain("> Keep two columns.");
expect(flow.messages.at(-1)?.content).toContain("Revise the plan at");
expect(flow.messages.find((message) => message.display)?.content).toContain("goal: preserve this");
const interviewedPlan = readFileSync(v1, "utf-8");
expect(interviewedPlan).toContain("> The result must preserve column order.");
expect(interviewedPlan).toMatch(/## Interview\n\n### .+\n\n> The result must preserve column order\.[\s\S]+> Keep two columns\.\n> Do not add a filter\./);
const refineSnapshot = await flow.hooks.get("before_agent_start")({}, flow.ctx);
expect(refineSnapshot.message.content).toContain("[PLANNING MODE]");
const blocked = await flow.hooks.get("tool_call")({ toolName: "edit", input: { path: "README.md" } }, flow.ctx);
expect(blocked?.block).toBe(true);
expect((await flow.hooks.get("tool_call")({ toolName: "edit", input: { path: "README.md" } }, flow.ctx))?.block).toBe(true);
await flow.commands.get("goals").handler("second objective", flow.ctx);
expect(readFileSync(v1, "utf-8")).toBe(interviewedPlan);
expect(readFileSync(join(flow.cwd, ".pi/plan/session-a-v2.md"), "utf-8")).toBe("");
expect(readFileSync(first, "utf8")).toContain("preserve this");
expect(flow.messages.at(-1)?.content).toContain("session-a-v2.md");
await flow.commands.get("goals").handler("judge the vendor options", flow.ctx);
expect(readFileSync(join(flow.cwd, ".pi/plan/session-a-v3.md"), "utf-8")).toBe("");
expect(flow.messages.at(-1)?.content).toContain("Objective: judge the vendor options");
} finally {
rmSync(flow.cwd, { recursive: true, force: true });
}
});
it("disconnects without deleting the active plan", async () => {
const flow = setup([]);
it("forks a visible supervisor on Ready and keeps the main session as worker", async () => {
const flow = setup(["Ready"]);
try {
await flow.commands.get("goals").handler("objective", flow.ctx);
const planPath = join(flow.cwd, ".pi/plan/session-a-v1.md");
writeFileSync(planPath, "# Plan\n\n## Goals\n\n1. [ ] goal: preserve this\n");
await flow.commands.get("goals").handler("--clear", flow.ctx);
expect(readFileSync(planPath, "utf-8")).toContain("goal: preserve this");
expect(flow.entries.at(-1)?.data).toMatchObject({ phase: null, planVersion: null });
await flow.commands.get("goals").handler("next objective", flow.ctx);
expect(readFileSync(join(flow.cwd, ".pi/plan/session-a-v2.md"), "utf-8")).toBe("");
await flow.commands.get("goals").handler("make the file", flow.ctx);
const planPath = approvedPlan(flow.cwd);
await flow.hooks.get("agent_settled")({}, flow.ctx);
expect(openSupervisorPane).toHaveBeenCalledWith(expect.objectContaining({
cwd: flow.cwd,
sourceSessionFile: join(flow.cwd, "session.jsonl"),
workerSessionId: "session-a",
workerIntercomId: "worker-intercom",
planPath,
}));
expect(flow.entries.at(-1)?.data).toMatchObject({ phase: "working", supervisorPaneId: "pane-2" });
expect(flow.messages.at(-1)?.content).toBe("The plan is approved. Begin implementation as the worker.");
const prompt = await flow.hooks.get("before_agent_start")({}, flow.ctx);
expect(prompt.systemPrompt).toContain("implementation worker");
expect(prompt.systemPrompt).toContain("stronger read-only supervisor");
} finally {
rmSync(flow.cwd, { recursive: true, force: true });
}
});
it("waits for Refine notes before starting a revision turn", async () => {
let submitNotes: (notes: string) => void;
const flow = setup(["Refine"], [], () => new Promise((resolve) => {
submitNotes = resolve;
}));
it("returns to planning when the worker is already paired", async () => {
const flow = setup(["Ready"]);
try {
await flow.commands.get("goals").handler("objective", flow.ctx);
const planPath = join(flow.cwd, ".pi/plan/session-a-v1.md");
writeFileSync(planPath, "# Plan\n\n## Goals\n\n1. [ ] goal: make this specific\n");
flow.events.removeAllListeners("pi-supervise:worker-state:v1");
flow.events.on("pi-supervise:worker-state:v1", (reply) => reply({ intercomId: "worker-intercom", paired: true }));
await flow.commands.get("goals").handler("make the file", flow.ctx);
approvedPlan(flow.cwd);
await flow.hooks.get("agent_settled")({}, flow.ctx);
expect(openSupervisorPane).not.toHaveBeenCalled();
expect(flow.entries.at(-1)?.data).toMatchObject({ phase: "planning", supervisorPaneId: null });
expect(flow.notifications.at(-1)).toContain("already paired");
} finally {
rmSync(flow.cwd, { recursive: true, force: true });
}
});
const review = flow.hooks.get("agent_settled")({}, flow.ctx);
it("waits for the worker's real paired acknowledgement before beginning work", async () => {
const flow = setup(["Ready"]);
try {
openSupervisorPane.mockImplementationOnce(async () => "pane-2");
await flow.commands.get("goals").handler("make the file", flow.ctx);
approvedPlan(flow.cwd);
const ready = flow.hooks.get("agent_settled")({}, flow.ctx);
await new Promise((resolve) => setImmediate(resolve));
expect(flow.events).toEqual(["display", "select", "editor"]);
expect(flow.messages.filter((message) => !message.display)).toHaveLength(1);
submitNotes!("Name the output artifact.");
await review;
expect(flow.messages.at(-1)?.content).toContain("Revise the plan at");
} finally {
rmSync(flow.cwd, { recursive: true, force: true });
}
});
it("starts work only when the human chooses Ready", async () => {
const flow = setup(["Ready"]);
try {
await flow.commands.get("goals").handler("objective", flow.ctx);
const planPath = join(flow.cwd, ".pi/plan/session-a-v1.md");
writeFileSync(planPath, "# Plan\n\n## Goals\n\n1. [ ] goal: work on this\n");
await flow.hooks.get("agent_settled")({}, flow.ctx);
expect(flow.events).toEqual(["display", "select"]);
expect(flow.messages.filter((message) => !message.display)).toHaveLength(2);
expect(flow.messages.at(-1)?.content).toContain("Work the goals");
await flow.hooks.get("session_start")({}, flow.ctx);
expect(await flow.hooks.get("before_agent_start")({}, flow.ctx)).toBeUndefined();
} finally {
rmSync(flow.cwd, { recursive: true, force: true });
}
});
it("edits a plan in Pi and cancels without starting work", async () => {
const original = "# Plan\n\n## Goals\n\n1. [ ] goal: original\n";
const edited = "# Plan\n\n## Goals\n\n1. [ ] goal: edited\n";
const flow = setup(["Edit", "Cancel"], [edited]);
try {
await flow.commands.get("goals").handler("objective", flow.ctx);
const planPath = join(flow.cwd, ".pi/plan/session-a-v1.md");
writeFileSync(planPath, original);
await flow.hooks.get("agent_settled")({}, flow.ctx);
expect(flow.events).toEqual(["display", "select", "editor", "display", "select"]);
expect(() => readFileSync(planPath, "utf-8")).toThrow();
expect(flow.messages.filter((message) => !message.display)).toHaveLength(1);
} finally {
rmSync(flow.cwd, { recursive: true, force: true });
}
});
it("reminds every eight unchanged working-set turns, ignoring log-only edits", async () => {
const flow = setup(["Ready"]);
try {
await flow.commands.get("goals").handler("objective", flow.ctx);
const planPath = join(flow.cwd, ".pi/plan/session-a-v1.md");
writeFileSync(planPath, "# Plan\n\n## Goals\n\n1. [/] goal: make the output\n\n## Log\n");
await flow.hooks.get("agent_settled")({}, flow.ctx);
await flow.hooks.get("turn_end")({}, flow.ctx);
for (let turn = 0; turn < 3; turn++) await flow.hooks.get("turn_end")({}, flow.ctx);
writeFileSync(planPath, "# Plan\n\n## Goals\n\n1. [/] goal: make the output\n\n## Log\n- checked input\n");
for (let turn = 0; turn < 5; turn++) await flow.hooks.get("turn_end")({}, flow.ctx);
const reminder = await flow.hooks.get("context")({ messages: [] }, flow.ctx);
expect(reminder.messages.at(-1).content[0].text).toContain(".pi/plan/session-a-v1.md");
writeFileSync(planPath, "# Plan\n\n## Goals\n\n1. [/] goal: make the output\n - [x] inspect input\n\n## Log\n- checked input\n");
await flow.hooks.get("turn_end")({}, flow.ctx);
for (let turn = 0; turn < 7; turn++) await flow.hooks.get("turn_end")({}, flow.ctx);
expect((await flow.hooks.get("context")({ messages: [] }, flow.ctx)).messages).toHaveLength(0);
await flow.hooks.get("turn_end")({}, flow.ctx);
expect((await flow.hooks.get("context")({ messages: [] }, flow.ctx)).messages.at(-1).content[0].text).toContain("make the output");
} finally {
rmSync(flow.cwd, { recursive: true, force: true });
}
});
it("auto-continues once on stop, then pauses after two no-progress wakes", async () => {
vi.useFakeTimers();
const flow = setup(["Ready"]);
try {
await flow.commands.get("goals").handler("objective", flow.ctx);
const planPath = join(flow.cwd, ".pi/plan/session-a-v1.md");
writeFileSync(planPath, "# Plan\n\n## Goals\n\n1. [/] goal: make the output\n");
await flow.hooks.get("agent_settled")({}, flow.ctx);
await flow.commands.get("goals").handler("--auto 1", flow.ctx);
await flow.hooks.get("agent_settled")({}, flow.ctx);
await vi.advanceTimersByTimeAsync(0);
const autoMessages = () => flow.messages.filter((message) => message.content.includes("Auto-continue is enabled"));
expect(autoMessages()).toHaveLength(1);
await flow.hooks.get("agent_settled")({}, flow.ctx);
await vi.advanceTimersByTimeAsync(60_000);
expect(autoMessages()).toHaveLength(2);
await flow.hooks.get("agent_settled")({}, flow.ctx);
await vi.advanceTimersByTimeAsync(60_000);
expect(autoMessages()).toHaveLength(2);
} finally {
vi.useRealTimers();
rmSync(flow.cwd, { recursive: true, force: true });
}
});
it("delays auto-continuation after a known background start", async () => {
vi.useFakeTimers();
const flow = setup(["Ready"]);
try {
await flow.commands.get("goals").handler("objective", flow.ctx);
const planPath = join(flow.cwd, ".pi/plan/session-a-v1.md");
writeFileSync(planPath, "# Plan\n\n## Goals\n\n1. [/] goal: make the output\n");
await flow.hooks.get("agent_settled")({}, flow.ctx);
await flow.commands.get("goals").handler("--auto 1", flow.ctx);
await flow.hooks.get("agent_start")({}, flow.ctx);
await flow.hooks.get("tool_call")({ toolName: "process", input: { action: "start" } }, flow.ctx);
await flow.hooks.get("agent_settled")({}, flow.ctx);
await vi.advanceTimersByTimeAsync(0);
const autoMessages = () => flow.messages.filter((message) => message.content.includes("Auto-continue is enabled"));
expect(autoMessages()).toHaveLength(0);
await vi.advanceTimersByTimeAsync(60_000);
expect(autoMessages()).toHaveLength(1);
} finally {
vi.useRealTimers();
rmSync(flow.cwd, { recursive: true, force: true });
}
});
it("gives the agent a planning snapshot and blocks work routes", async () => {
const flow = setup([]);
try {
await flow.commands.get("goals").handler("objective", flow.ctx);
const planPath = join(flow.cwd, ".pi/plan/session-a-v1.md");
expect(flow.entries.at(-1)?.data).toMatchObject({ phase: "planning" });
await flow.hooks.get("session_start")({}, flow.ctx);
const snapshot = await flow.hooks.get("before_agent_start")({}, flow.ctx);
expect(snapshot.message.content).toContain("[PLANNING MODE]");
expect(snapshot.message.content).toContain(planPath);
expect(flow.messages.some((message) => message.content === "The plan is approved. Begin implementation as the worker.")).toBe(false);
flow.events.emit("pi-supervise:worker-paired:v1", { supervisorIntercomId: "supervisor-intercom" });
await ready;
expect(flow.entries.at(-1)?.data).toMatchObject({ phase: "working", supervisorPaneId: "pane-2" });
} finally {
rmSync(flow.cwd, { recursive: true, force: true });
}
});
const writePlan = await flow.hooks.get("tool_call")({ toolName: "write", input: { path: planPath } }, flow.ctx);
const writeCode = await flow.hooks.get("tool_call")({ toolName: "write", input: { path: "README.md" } }, flow.ctx);
const readShell = await flow.hooks.get("tool_call")({ toolName: "bash", input: { command: "pwd && ls && git log" } }, flow.ctx);
const changeDirectoryThenRead = await flow.hooks.get("tool_call")({ toolName: "bash", input: { command: "cd . && ls -la" } }, flow.ctx);
const pipeShell = await flow.hooks.get("tool_call")({ toolName: "bash", input: { command: "ls | head" } }, flow.ctx);
const pythonWrite = await flow.hooks.get("tool_call")({ toolName: "bash", input: { command: "python -c \"open('README.md', 'w')\"" } }, flow.ctx);
const signoff = await flow.tools.get("CompleteGoal").execute("", { goal: "work" }, undefined, undefined, flow.ctx);
await flow.hooks.get("session_compact")({}, flow.ctx);
const compacted = await flow.hooks.get("context")({ messages: [] }, flow.ctx);
it("closes the supervisor on clear but keeps the plan file", async () => {
const flow = setup(["Ready"]);
try {
await flow.commands.get("goals").handler("make the file", flow.ctx);
const planPath = approvedPlan(flow.cwd);
await flow.hooks.get("agent_settled")({}, flow.ctx);
await flow.commands.get("goals").handler("clear", flow.ctx);
expect(closeSupervisorPane).toHaveBeenCalledWith("pane-2");
expect(readFileSync(planPath, "utf8")).toContain("make the file");
expect(flow.entries.at(-1)?.data).toMatchObject({ phase: null, supervisorPaneId: null, planVersion: null });
} finally {
rmSync(flow.cwd, { recursive: true, force: true });
}
});
expect(writePlan).toBeUndefined();
expect(writeCode?.block).toBe(true);
expect(readShell).toBeUndefined();
expect(changeDirectoryThenRead).toBeUndefined();
expect(pipeShell?.block).toBe(true);
expect(pythonWrite?.block).toBe(true);
expect(signoff.isError).toBe(true);
expect(compacted.messages.at(-1).content[0].text).toContain("[PLANNING MODE]");
it("accepts only an approval for the exact clean commit and goal block", async () => {
const flow = setup(["Ready"]);
try {
await flow.commands.get("goals").handler("make the file", flow.ctx);
const planPath = approvedPlan(flow.cwd);
await flow.hooks.get("agent_settled")({}, flow.ctx);
const goal = "make the file";
const plan = readFileSync(planPath, "utf8");
const block = goalBlock(plan, goal)!;
const repository = repositoryState(flow.cwd);
const approvalId = (flow.entries.at(-1)?.data as { approvalId: string }).approvalId;
writeApproval(approvalPath(flow.cwd, "session-a", goal), {
version: 3, verdict: "accept", approvalId, goal, planPath,
goalBlockHash: hashGoalBlock(block), repoRoot: repository.repoRoot,
head: repository.head, tree: repository.tree, cleanWorktree: true,
inspected: { plan: true, repository: true, evidence: true, verifyOutput: true },
verifyOutputPath: "verify.txt",
supervisor: { sessionId: "supervisor", runId: null }, timestamp: new Date().toISOString(),
});
const signed = await flow.tools.get("CompleteGoal").execute("id", { goal }, undefined, undefined, flow.ctx);
expect(signed.isError).toBe(false);
expect(readFileSync(planPath, "utf8")).toContain("1. [x] goal: make the file");
} finally {
rmSync(flow.cwd, { recursive: true, force: true });
}
});
});
describe("process role", () => {
it("keeps subagent children and visible supervisors out of the worker extension", () => {
expect(isMainSession(false)).toBe(true);
expect(isMainSession(true)).toBe(false);
});
});
+64
View File
@@ -0,0 +1,64 @@
import { chmodSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";
import { closeSupervisorPane, openSupervisorPane, supervisorCommand } from "../src/herdr.js";
function input() {
return {
cwd: "/repo",
sourceSessionFile: "/sessions/worker.jsonl",
workerSessionId: "worker-12345678",
workerIntercomId: "intercom-12345678",
planPath: "/repo/.pi/plan/worker-v1.md",
approvalId: "approval-1",
extensionPath: "/repo/src/index.ts",
superviseExtensionPath: null,
model: "provider/supervisor",
};
}
afterEach(() => vi.unstubAllEnvs());
describe("supervisor pane command", () => {
it("forks the planning session with an explicit supervisor role and model", () => {
const command = supervisorCommand(input());
expect(command).toContain("'PI_GOALS_ROLE=supervisor'");
expect(command).toContain("'PI_GOALS_WORKER_INTERCOM_ID=intercom-12345678'");
expect(command).toContain("'pi' '--no-extensions' '-e' 'npm:pi-intercom' '-e' 'npm:@wassname2/pi-supervise@0.0.4' '-e' '/repo/src/index.ts'");
expect(command).toContain("'--fork' '/sessions/worker.jsonl'");
expect(command).toContain("'--model' 'provider/supervisor'");
expect(command).not.toContain("Initialize supervision startup.");
expect(command).not.toContain("pi-subagents");
});
it("uses the loaded pi-supervise extension before the npm fallback", () => {
const loaded = { ...input(), superviseExtensionPath: "/repo/vendor/pi-supervise/src/index.ts" };
expect(supervisorCommand(loaded)).toContain("'-e' '/repo/vendor/pi-supervise/src/index.ts'");
vi.stubEnv("PI_GOALS_SUPERVISE_EXTENSION", "/repo/override/pi-supervise/src/index.ts");
expect(supervisorCommand(loaded)).toContain("'-e' '/repo/override/pi-supervise/src/index.ts'");
});
it("accepts Herdr's text version output and stale pane cleanup", async () => {
const cwd = mkdtempSync(join(tmpdir(), "pi-goals-herdr-"));
const bin = join(cwd, "herdr");
writeFileSync(bin, `#!/bin/sh
if [ "$1" = "--version" ]; then echo "herdr 0.8.2"; exit 0; fi
if [ "$1" = "pane" ] && [ "$2" = "split" ]; then echo '{"pane_id":"new-pane"}'; exit 0; fi
if [ "$1" = "pane" ] && [ "$2" = "run" ]; then if [ "$HERDR_SMOKE_RUN_FAIL" = "1" ]; then echo "run failed" >&2; exit 1; fi; echo '{}'; exit 0; fi
if [ "$1" = "pane" ] && [ "$2" = "close" ]; then echo '{"error":{"code":"PANE_GONE"}}' >&2; exit 1; fi
exit 2
`);
chmodSync(bin, 0o755);
vi.stubEnv("HERDR_ENV", "1");
vi.stubEnv("HERDR_BIN_PATH", bin);
try {
await expect(openSupervisorPane(input())).resolves.toBe("new-pane");
await expect(closeSupervisorPane("new-pane")).resolves.toBeUndefined();
vi.stubEnv("HERDR_SMOKE_RUN_FAIL", "1");
await expect(openSupervisorPane(input())).rejects.toThrow("run failed");
} finally {
rmSync(cwd, { recursive: true, force: true });
}
});
});
-33
View File
@@ -1,33 +0,0 @@
import { describe, expect, it } from "vitest";
import { buildJudgeArgs } from "../src/index.js";
describe("buildJudgeArgs", () => {
it("omits --model when judgeModel is null (pi uses its configured default; never a pre-emptive 'no model' failure)", () => {
const args = buildJudgeArgs(null);
expect(args).not.toContain("--model");
// an empty --model "" would make every sign-off silently inconclusive -- guard against it
const i = args.indexOf("--model");
expect(i).toBe(-1);
});
it("includes --model <ref> when an explicit/session model is set", () => {
const args = buildJudgeArgs("openrouter/~anthropic/claude-haiku-latest");
const i = args.indexOf("--model");
expect(i).not.toBe(-1);
expect(args[i + 1]).toBe("openrouter/~anthropic/claude-haiku-latest");
});
it("always sets --no-session, --no-extensions, the read-only tool allowlist, and edit/write exclusion", () => {
for (const m of [null, "some/model"]) {
const args = buildJudgeArgs(m);
expect(args).toContain("--no-session");
expect(args).toContain("--no-extensions"); // a broken global extension must not take down sign-offs
expect(args).toContain("--tools");
expect(args.some((a) => a.startsWith("read,grep,find,ls"))).toBe(true);
// no bash: the judge must never be able to execute (or re-run a 10-hour verify) or mutate
expect(args.some((a) => a.includes("bash"))).toBe(false);
expect(args).toContain("--exclude-tools");
expect(args.some((a) => a.includes("edit") && a.includes("write"))).toBe(true);
}
});
});
+18
View File
@@ -0,0 +1,18 @@
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import { describe, expect, it } from "vitest";
interface PackageManifest {
files: string[];
pi: { extensions: string[]; subagents?: unknown };
}
describe("package manifest", () => {
it("includes the extension without registering a packaged subagent", () => {
const root = resolve(import.meta.dirname, "..");
const manifest = JSON.parse(readFileSync(resolve(root, "package.json"), "utf8")) as PackageManifest;
expect(manifest.files).toEqual(["src", "README.md"]);
expect(manifest.pi.extensions).toEqual(["./src/index.ts"]);
expect(manifest.pi.subagents).toBeUndefined();
});
});
+8 -7
View File
@@ -1,15 +1,16 @@
import { describe, expect, it } from "vitest";
import { judgeSystem, planDrafting, planningState, reminder, resync } from "../src/prompts.js";
import { completeGoalDescription, planDrafting, planningState, resync } from "../src/prompts.js";
describe("planning prompt", () => {
it("requires fact finding or a focused question before a goal", () => {
expect(planDrafting).toContain("Use read-only repository tools or web search when either can\nresolve a fact.");
expect(planDrafting).toContain("ask the human to confirm your interpretation");
expect(planDrafting).toContain("approve an editorial or other preference choice");
expect(planDrafting).toContain("Ask at least three short, concrete questions");
expect(planDrafting).toContain("understand the requested outcome, boundary, and how success will be judged");
expect(planDrafting).toContain("record that\npoint as unknown; do not silently replace it with an inference");
expect(planDrafting).toContain("answer materially reduces uncertainty\nwhile discovering the right plan");
expect(planDrafting).toContain("self-contained: state the relevant\ncontext, use the human's language and ASD-STE100");
expect(planDrafting).toContain("placeholder goal such as \"work out the thing\"");
expect(planDrafting).toContain("object, observable result, settled scope, and required approval");
expect(planDrafting).toContain("material user decisions remain open");
});
it("restores the same rule after compaction", () => {
@@ -22,9 +23,9 @@ describe("planning prompt", () => {
expect(planDrafting).toContain("## User-visible result");
expect(planDrafting).toContain("Take it from the original request, not from your implementation plan");
expect(planDrafting).toContain("Future work may not defer any artifact or action named there");
expect(reminder("plan", ".pi/plan/test.md")).toContain("latest message outranks this plan");
expect(resync("plan", ".pi/plan/test.md", "Compacted.")).toContain("amend the plan rather than preserving an obsolete decision");
expect(judgeSystem).toContain("Task fidelity?");
expect(judgeSystem).toContain("Agent-inferred scope is not authority");
expect(resync("plan", ".pi/plan/test.md", "Compacted.")).toContain("implementation worker");
expect(completeGoalDescription).toContain("visible supervisor");
expect(completeGoalDescription).toContain("stopped worker view with no active work");
});
});
+47
View File
@@ -0,0 +1,47 @@
import { EventEmitter } from "node:events";
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
import { describe, expect, it } from "vitest";
import { workerPiSupervise } from "../src/supervise.js";
const API_READY = "pi-supervise:api-ready:v1";
const WORKER_STATE = "pi-supervise:worker-state:v1";
const WORKER_PAIRED = "pi-supervise:worker-paired:v1";
function pi(events: EventEmitter): ExtensionAPI {
return { events } as unknown as ExtensionAPI;
}
describe("pi-supervise worker API", () => {
it("discovers pi-supervise when it loads after pi-goals", async () => {
const events = new EventEmitter();
const worker = workerPiSupervise(pi(events));
events.on(WORKER_STATE, (reply) => reply({ intercomId: "worker-id", paired: false }));
events.emit(API_READY);
expect((await worker).intercomId).toBe("worker-id");
});
it("discovers an already-loaded pi-supervise and accepts duplicate paired events once", async () => {
const events = new EventEmitter();
events.on(WORKER_STATE, (reply) => reply({ intercomId: "worker-id", paired: false }));
const worker = await workerPiSupervise(pi(events));
let acknowledgements = 0;
const paired = worker.waitForPair().then(() => { acknowledgements += 1; });
events.emit(WORKER_PAIRED, { supervisorIntercomId: "supervisor-id" });
events.emit(WORKER_PAIRED, { supervisorIntercomId: "supervisor-id" });
await paired;
expect(acknowledgements).toBe(1);
});
it("rejects Ready when another supervisor already owns the worker", async () => {
const events = new EventEmitter();
events.on(WORKER_STATE, (reply) => reply({ intercomId: "worker-id", paired: true }));
await expect(workerPiSupervise(pi(events))).rejects.toThrow("already paired");
});
it("times out when the visible supervisor never pairs", async () => {
const events = new EventEmitter();
events.on(WORKER_STATE, (reply) => reply({ intercomId: "worker-id", paired: false }));
const worker = await workerPiSupervise(pi(events), 1);
await expect(worker.waitForPair()).rejects.toThrow("did not pair");
});
});
+172
View File
@@ -0,0 +1,172 @@
import { execFileSync } from "node:child_process";
import { existsSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
import { afterEach, describe, expect, it, vi } from "vitest";
import { approvalPath } from "../src/approval.js";
import { registerVisibleSupervisor } from "../src/supervisor-session.js";
function setup(cwd: string, planPath: string, tokens: number | null = 10, onCompact: (options: any) => void = (options) => options.onComplete()) {
vi.stubEnv("PI_GOALS_WORKER_ID", "worker-session");
vi.stubEnv("PI_GOALS_WORKER_INTERCOM_ID", "worker-intercom");
vi.stubEnv("PI_GOALS_OWNER_SESSION_ID", "worker-session");
vi.stubEnv("PI_GOALS_PLAN_PATH", planPath);
vi.stubEnv("PI_GOALS_APPROVAL_ID", "approval-1");
const hooks = new Map<string, any>();
const tools = new Map<string, any>();
const entries: any[] = [];
const paired: Array<{ workerIntercomId: string; goal: string }> = [];
const messages: string[] = [];
let branch: any[] = [];
const ctx = {
cwd,
getSystemPrompt: () => "base",
getContextUsage: () => tokens === null ? undefined : ({ tokens }),
compact: vi.fn(onCompact),
sessionManager: {
getEntries: () => entries,
getBranch: () => branch,
getSessionId: () => "supervisor-session",
},
ui: { notify: vi.fn() },
};
const pi = {
events: {
on() {},
emit(name: string, request: any) {
if (name !== "pi-supervise:pair:v1") return;
paired.push({ workerIntercomId: request.workerIntercomId, goal: request.goal });
request.resolve();
},
},
on: (name: string, handler: any) => hooks.set(name, handler),
registerTool: (tool: any) => tools.set(tool.name, tool),
appendEntry: (customType: string, data: unknown) => entries.push({ type: "custom", customType, data }),
sendUserMessage: (message: string) => messages.push(message),
};
registerVisibleSupervisor(pi as unknown as ExtensionAPI);
return { branch: (value: any[]) => { branch = value; }, ctx, entries, hooks, messages, paired, tools };
}
afterEach(() => vi.unstubAllEnvs());
describe("visible supervisor session", () => {
it("pairs from session startup before asking the supervisor to work", async () => {
const cwd = mkdtempSync(join(tmpdir(), "pi-goals-supervisor-"));
try {
const runtime = setup(cwd, join(cwd, ".pi/plan/worker-v1.md"));
await runtime.hooks.get("session_start")({}, runtime.ctx);
await new Promise((resolve) => setImmediate(resolve));
expect(runtime.ctx.compact).not.toHaveBeenCalled();
expect(runtime.entries.at(-1)).toMatchObject({ customType: "pi-goals-visible-supervisor-v1" });
expect(runtime.paired).toEqual([{ workerIntercomId: "worker-intercom", goal: join(cwd, ".pi/plan/worker-v1.md") }]);
expect(runtime.messages).toEqual(["Supervision is paired. Inspect the worker and give its next concrete instruction."]);
} finally {
rmSync(cwd, { recursive: true, force: true });
}
});
it("compacts a large planning fork before pairing", async () => {
const cwd = mkdtempSync(join(tmpdir(), "pi-goals-supervisor-"));
try {
let complete: (() => void) | undefined;
const runtime = setup(cwd, join(cwd, ".pi/plan/worker-v1.md"), 20_001, (options) => { complete = options.onComplete; });
await runtime.hooks.get("session_start")({}, runtime.ctx);
await new Promise((resolve) => setImmediate(resolve));
expect(runtime.ctx.compact).toHaveBeenCalledOnce();
expect(runtime.paired).toHaveLength(0);
complete!();
await new Promise((resolve) => setImmediate(resolve));
expect(runtime.paired).toHaveLength(1);
expect(runtime.messages).toEqual(["Supervision is paired. Inspect the worker and give its next concrete instruction."]);
} finally {
rmSync(cwd, { recursive: true, force: true });
}
});
it("does not start work when initial compaction fails", async () => {
const cwd = mkdtempSync(join(tmpdir(), "pi-goals-supervisor-"));
try {
const runtime = setup(cwd, join(cwd, ".pi/plan/worker-v1.md"), null, (options) => options.onError(new Error("offline")));
await runtime.hooks.get("session_start")({}, runtime.ctx);
await new Promise((resolve) => setImmediate(resolve));
expect(runtime.ctx.compact).toHaveBeenCalledOnce();
expect(runtime.paired).toHaveLength(0);
expect(runtime.ctx.ui.notify).toHaveBeenCalledWith("Supervisor startup compaction failed: offline", "error");
} finally {
rmSync(cwd, { recursive: true, force: true });
}
});
it("does not pair twice across session startup and later turns", async () => {
const cwd = mkdtempSync(join(tmpdir(), "pi-goals-supervisor-"));
try {
const runtime = setup(cwd, join(cwd, ".pi/plan/worker-v1.md"));
await runtime.hooks.get("session_start")({}, runtime.ctx);
await new Promise((resolve) => setImmediate(resolve));
await runtime.hooks.get("before_agent_start")({}, runtime.ctx);
expect(runtime.paired).toHaveLength(1);
} finally {
rmSync(cwd, { recursive: true, force: true });
}
});
it("records approval only from a stopped view with evidence and no active work", async () => {
const cwd = mkdtempSync(join(tmpdir(), "pi-goals-supervisor-"));
try {
writeFileSync(join(cwd, ".gitignore"), ".pi/\n");
writeFileSync(join(cwd, "verify.txt"), "PASS\n");
execFileSync("git", ["init", "-q"], { cwd });
execFileSync("git", ["add", ".gitignore", "verify.txt"], { cwd });
execFileSync("git", ["-c", "user.name=test", "-c", "user.email=test@example.com", "commit", "-qm", "initial"], { cwd });
const planPath = join(cwd, ".pi/plan/worker-v1.md");
execFileSync("mkdir", ["-p", join(cwd, ".pi/plan")]);
writeFileSync(planPath, "# Plan\n\n## Goals\n\n1. [ ] goal: make the file\n - discriminator: output exists\n - evidence:\n - `result.txt`: contains ok\n\n## Log\n");
const runtime = setup(cwd, planPath);
runtime.branch([{
type: "message",
message: { role: "user", content: [{ type: "text", text: "The worker stopped.\n\ntool calls with no result: none\nchild pi processes still running: none" }] },
}]);
const approved = await runtime.tools.get("ApproveGoal").execute("id", {
goal: "make the file",
verifyOutputPath: "verify.txt",
}, undefined, undefined, runtime.ctx);
expect(approved.isError).toBe(false);
expect(existsSync(approvalPath(cwd, "worker-session", "make the file"))).toBe(true);
const missingOutput = await runtime.tools.get("ApproveGoal").execute("id", {
goal: "make the file", verifyOutputPath: "missing.txt",
}, undefined, undefined, runtime.ctx);
expect(missingOutput.isError).toBe(true);
expect(missingOutput.content[0].text).toContain("verification-output");
writeFileSync(planPath, "# Plan\n\n## Goals\n\n1. [ ] goal: make the file\n - evidence:\n - \n - tasks:\n - write result.txt\n");
const missingEvidence = await runtime.tools.get("ApproveGoal").execute("id", {
goal: "make the file", verifyOutputPath: "verify.txt",
}, undefined, undefined, runtime.ctx);
expect(missingEvidence.isError).toBe(true);
expect(missingEvidence.content[0].text).toContain("nonblank evidence entry");
} finally {
rmSync(cwd, { recursive: true, force: true });
}
});
it("rejects approval while the worker view has an unfinished tool call", async () => {
const cwd = mkdtempSync(join(tmpdir(), "pi-goals-supervisor-"));
try {
const planPath = join(cwd, "plan.md");
writeFileSync(planPath, "1. [ ] goal: wait\n - evidence:\n - result\n");
const runtime = setup(cwd, planPath);
runtime.branch([{
type: "message",
message: { role: "user", content: [{ type: "text", text: "The worker stopped.\n\ntool calls with no result: bash\nchild pi processes still running: none" }] },
}]);
const rejected = await runtime.tools.get("ApproveGoal").execute("id", {
goal: "wait", verifyOutputPath: "verify.txt",
}, undefined, undefined, runtime.ctx);
expect(rejected.isError).toBe(true);
expect(rejected.content[0].text).toContain("bash");
} finally {
rmSync(cwd, { recursive: true, force: true });
}
});
});