Repository navigation
fix(pi): match Pi 0.99 stock tool call headers and hidden export rows - #24
Merged
Merged
Conversation
Pi 0.99 shows call arguments on the stock tool header and renders display:false custom messages into the export conversation column as rows hidden by default. Match the installed Pi's call header in the supervision outcome tools, and hold Calm's export boundary to the visible conversation. Ports the Pi-rendering portion of upstream kunchenguid/firstmate e2668de (kunchenguid#6162) without its unrelated remote-provisioning, dispatch, and queued-turn changes.
adonis-garcia-git
pushed a commit
that referenced
this pull request
Sep 30, 2026
…rtable serial 8). Serial 2 and 4 fail for a reason outside this PR. **Serial 8** (`tests/fm-precompact-handoff.test.sh`, "a session without the fleet lock wrote over the lock holder's handoff"): the test has a race. It starts the fake lock holder with `"$FAKE_CLAUDE" -c 'sleep 60; :' &`, writes that pid to `state/.lock`, and runs the hook straight away. Until the background child execs the claude-named binary, it is still a plain bash fork. So `fm_harness_pid_alive` does not recognise it as a live owner, the hook treats the lock as stale, and it writes the note. Invariant: the test must run the hook only once the pid named in the lock is a live harness-shaped process. This is the only backgrounded fake-harness holder in the PR's tests. Fix: after starting the holder, the test waits up to 5 s, checking every 0.1 s with the real `fm_harness_pid_alive` from `bin/fm-session-lock-lib.sh`, before writing the lock and running the hook. If the holder never becomes live, the test fails with a clear message. Product code is unchanged. Verified: the full suite passed 3 times in a row locally and `shellcheck -x` is clean. **Serial 2 and 4** (`tests/fm-calm-pi-extension.test.sh` "rendered export DOM violated the Calm conversation boundary"; `tests/fm-pi-branch-extension.test.sh` "Calm-off ToolExecutionComponent rendering differs from Pi stock"): these are caused by Pi 0.99.1, released 2026-09-29, which CI installs as the latest Pi. PR #24 (open, not merged) says both fail the same way on unmodified main at 26d8d42, the base of this branch, and fixes them. This PR does not touch those files, so no change was made for them here. They will stay red until PR #24 is merged
adonis-garcia-git
pushed a commit
that referenced
this pull request
Sep 30, 2026
…used by this PR, serial 5 was a flake in an existing test, and serial 2 and 4 come from outside this PR. **Serial 8** (`tests/fm-precompact-handoff.test.sh`, "a session without the fleet lock wrote over the lock holder's handoff"): the previous round's fix, which waited for the lock holder, was not the real cause. Invariant: every hook run that stands in for "Claude runs the hook" must keep the fake claude process alive as an ancestor of the hook. - The non-owner run was `"$FAKE_CLAUDE" -c '"$FM_HOME/bin/fm-precompact-handoff.sh"'`. With a single command, bash replaces itself with the hook script (exec), so the claude-named process disappears. The hook then finds no harness ancestry, the lock check says "no foreign owner", and the hook writes the note. - Locally it passed only because the test process itself runs under a real Claude session, which the ancestry walk found. CI has no such ancestor. - I reproduced the CI failure locally by running the test detached from Claude's process tree. - Fix, applied to both sites that need the fake harness as an ancestor (the non-owner run and the own-lock run, where bash can exec the last command): add a trailing `:` no-op, the same trick the holder already uses. Product code is unchanged. - Verified: passes detached from Claude (the CI-like case) and 3 times in a row in the normal environment. **Serial 5** (`tests/fm-contributions.test.sh`, "generated check did not attempt a read"): this test is not touched by the PR. It passed on this branch's previous run, and the only commit since then changed another test file. The test gives the poll a 1-second budget using whole-second clock readings. If the second ticks between setting the deadline and the reserve check, the poll correctly skips the read, which `bin/fm-contributions.sh` documents as allowed ("may be unmeasured"). The test's check that a read happened was therefore racy. - Invariant: the budget-plumbing assertion must not depend on the wall clock not ticking. - Fix: freeze the fake clock (`/bin/date +%s > "$home/forge/clock"`) as the other small-budget tests in the same file already do. This covers both the configured and inherited modes. The only small-budget test without a frozen clock was this one. - Verified: the full file passes. **Serial 2 and 4** (`tests/fm-calm-pi-extension.test.sh`, `tests/fm-pi-branch-extension.test.sh`): these are the known Pi 0.99.1 drift failures. They also fail on main (26d8d42) and are fixed by open PR #24. This PR doesn't touch those files, so I made no change for them, and they will stay red until PR #24 is merged. `shellcheck -x` is clean on both edited tests
adonis-garcia-git
pushed a commit
that referenced
this pull request
Sep 30, 2026
…t with it (#25) * feat(bin): write a pre-compaction handoff before every Claude compaction A compaction keeps the session but replaces its conversation with a summary, and an automatic compaction fires with no /stow first, so decisions and open work that existed only in conversation could be lost or blurred. bin/fm-precompact-handoff.sh is registered as an unmatched Claude PreCompact hook. Just before every manual and automatic compaction it writes a snapshot into its own marked block of data/session-handoff.md: the /compact instructions, the captain's most recent turns verbatim with the reply each answered, firstmate's last reply, held backlog items, and every task record with its last status. Lines outside the block, such as /stow's conversation threads, are preserved. It always exits 0 with empty stdout, so it can never block the compaction, and records any failure with its reason. The compact digest prints the fresh block in its fleet-state stage, or says plainly that none was recorded, it is stale, or it failed, with the pre-compaction transcript to read instead. The entry stands down under Grok, Cursor, and pi-code, in task worktrees, and in gate agents; the pi-code payload predicate moves into fm-hook-host-lib.sh so the Stop auto-arm and the new hook share it. * fix(bin): keep the pre-compaction note to the captain's words and identifiers The pre-compaction snapshot copied firstmate's replies, a reply-context excerpt per captain turn, worker status lines, and backlog hold reasons, any of which can quote patient or worker text. It now carries only the captain's own words (verbatim, clipped) plus identifiers: held backlog item ids and hold kinds, and each task record's id, kind, and PR URL. The compaction digest already reprints the work state from its own records. * no-mistakes(review): Drop origin-less fallback and skip firstmate operational input * no-mistakes(review): Match doorbells by shape so pruned records stay excluded * no-mistakes(review): Correct compact digest transcript-naming branches in sessionstart docs * fix(bin): lead the compaction digest with the handoff and drive the live guard through a pty The PreCompact hook was committed without its executable bit, so the tracked settings entry failed with "Permission denied" in a real checkout and no handoff was ever written. It is now mode 100755. Claude Code keeps only a 2KB preview of an oversized hook output inline, and a compaction digest is routinely larger, so the pre-compaction handoff now leads the compact digest ahead of every other section. Its heading points at the file the harness names on its "Full output saved to" line, and captain turns are listed newest first so the latest words fall inside the preview. The opt-in live guard now drives the real interactive TUI through a Python pty, because headless `claude -p` transcripts carry no origin field. It copies the hook at its git index mode instead of chmod-ing it, so a missing executable bit fails the guard, and it proves a typed firstmate doorbell is dropped. * no-mistakes(document): Drop /stow as the session-handoff note writer * no-mistakes(ci): Fixed the one failure caused by this PR (Behavior portable serial 8). Serial 2 and 4 fail for a reason outside this PR. **Serial 8** (`tests/fm-precompact-handoff.test.sh`, "a session without the fleet lock wrote over the lock holder's handoff"): the test has a race. It starts the fake lock holder with `"$FAKE_CLAUDE" -c 'sleep 60; :' &`, writes that pid to `state/.lock`, and runs the hook straight away. Until the background child execs the claude-named binary, it is still a plain bash fork. So `fm_harness_pid_alive` does not recognise it as a live owner, the hook treats the lock as stale, and it writes the note. Invariant: the test must run the hook only once the pid named in the lock is a live harness-shaped process. This is the only backgrounded fake-harness holder in the PR's tests. Fix: after starting the holder, the test waits up to 5 s, checking every 0.1 s with the real `fm_harness_pid_alive` from `bin/fm-session-lock-lib.sh`, before writing the lock and running the hook. If the holder never becomes live, the test fails with a clear message. Product code is unchanged. Verified: the full suite passed 3 times in a row locally and `shellcheck -x` is clean. **Serial 2 and 4** (`tests/fm-calm-pi-extension.test.sh` "rendered export DOM violated the Calm conversation boundary"; `tests/fm-pi-branch-extension.test.sh` "Calm-off ToolExecutionComponent rendering differs from Pi stock"): these are caused by Pi 0.99.1, released 2026-09-29, which CI installs as the latest Pi. PR #24 (open, not merged) says both fail the same way on unmodified main at 26d8d42, the base of this branch, and fixes them. This PR does not touch those files, so no change was made for them here. They will stay red until PR #24 is merged * no-mistakes(ci): I changed two test files. The serial 8 failure is caused by this PR, serial 5 was a flake in an existing test, and serial 2 and 4 come from outside this PR. **Serial 8** (`tests/fm-precompact-handoff.test.sh`, "a session without the fleet lock wrote over the lock holder's handoff"): the previous round's fix, which waited for the lock holder, was not the real cause. Invariant: every hook run that stands in for "Claude runs the hook" must keep the fake claude process alive as an ancestor of the hook. - The non-owner run was `"$FAKE_CLAUDE" -c '"$FM_HOME/bin/fm-precompact-handoff.sh"'`. With a single command, bash replaces itself with the hook script (exec), so the claude-named process disappears. The hook then finds no harness ancestry, the lock check says "no foreign owner", and the hook writes the note. - Locally it passed only because the test process itself runs under a real Claude session, which the ancestry walk found. CI has no such ancestor. - I reproduced the CI failure locally by running the test detached from Claude's process tree. - Fix, applied to both sites that need the fake harness as an ancestor (the non-owner run and the own-lock run, where bash can exec the last command): add a trailing `:` no-op, the same trick the holder already uses. Product code is unchanged. - Verified: passes detached from Claude (the CI-like case) and 3 times in a row in the normal environment. **Serial 5** (`tests/fm-contributions.test.sh`, "generated check did not attempt a read"): this test is not touched by the PR. It passed on this branch's previous run, and the only commit since then changed another test file. The test gives the poll a 1-second budget using whole-second clock readings. If the second ticks between setting the deadline and the reserve check, the poll correctly skips the read, which `bin/fm-contributions.sh` documents as allowed ("may be unmeasured"). The test's check that a read happened was therefore racy. - Invariant: the budget-plumbing assertion must not depend on the wall clock not ticking. - Fix: freeze the fake clock (`/bin/date +%s > "$home/forge/clock"`) as the other small-budget tests in the same file already do. This covers both the configured and inherited modes. The only small-budget test without a frozen clock was this one. - Verified: the full file passes. **Serial 2 and 4** (`tests/fm-calm-pi-extension.test.sh`, `tests/fm-pi-branch-extension.test.sh`): these are the known Pi 0.99.1 drift failures. They also fail on main (26d8d42) and are fixed by open PR #24. This PR doesn't touch those files, so I made no change for them, and they will stay red until PR #24 is merged. `shellcheck -x` is clean on both edited tests * no-mistakes(ci): I fixed all four review findings (F1-F4). Each has a regression test that I confirmed fails on the current head and passes now. I did not touch the Pi/Calm tests; serial 2 and 4 are the known Pi 0.99.1 drift that PR 24 fixes. **F1: captain turns containing `<command-name>` were silently dropped.** The rule that must hold: every captain turn is either rendered as the slash command the captain typed or kept word for word, never dropped. - The cause: jq's `capture` returns nothing at all on a non-match, so `try/catch` never fired and the turn vanished. - Fix in `bin/fm-precompact-handoff.sh`: `command_form` now reads each capture as a single value that is empty when there is no match. A turn is treated as a slash command only when it contains nothing but command tags; anything else, including prose that quotes a tag, is kept word for word. - New test: a bare `/stow` renders as `/stow`, `/bearings fleet now` renders with its arguments, and turns with an unpaired tag or a quoted paired tag keep their decision text. - The opt-in live pty guard now types a lab-local `/stow` before `/compact` and checks that the note quotes it. **F2: a killed hook left temporary files in `data/`.** The rule: a killed hook leaves no temporary files. - All three temporary files the finding named (the turns copy, the block, and the note being assembled) now live in one directory in `data/`, created with `mktemp -d`. That keeps the note's replace a same-filesystem rename. - The results-record temporary file is covered the same way. - An exit trap (with TERM, INT and HUP routed to exit) removes them all, so I deleted the scattered `rm -f` calls. - New test: the hook is held on a FIFO transcript, its process group is sent SIGTERM, and nothing is left in `data/` or `state/`. I also ran it 3 times detached from a terminal, as CI runs. - One limit: a SIGKILL cannot be caught, so nothing can clean up after it. **F3: a long `/compact` argument pushed the newest captain turn out of the 2KB preview.** The argument is now clipped to `TURN_CHARS`, the same limit as a turn. I rewrote the preview test in `tests/fm-session-start.test.sh` to run the real hook, with 10 turns of 1200 characters and a `/compact` argument of about 1500 characters. On the old hook the newest turn started at byte 2367; it now starts before byte 2048. **F4: a stale record from another session was shown as this compaction's handoff.** The rule: the digest shows a handoff only if the record is recent and names this compaction's session. - `bin/fm-sessionstart-run.sh` now reads `session_id` from the payload with the same jq-free parser it uses for `source`, and passes `--session` to `fm-session-start.sh` for both the clear and compact paths. - `bin/fm-session-start.sh` accepts `--session` and forwards it through the timed re-run. To keep that simple, I replaced its four-way branch with a single argument list. - The digest now requires the record's `session=` to match, as well as the age check. On a mismatch, or when either id is missing, it prints the "None recorded for this compaction" warning. - New tests: the block prints for a matching session; the warning prints for another session, for a missing compact id, and for a record with no session; and the run wrapper forwards the payload's `session_id` all the way through. - I updated `docs/sessionstart-nudge.md` and the headers of the three scripts. **Vendor check:** F4 only works if the compact `SessionStart` payload carries the same `session_id` as the `PreCompact` payload. The live guard now checks that. I ran it against the real Claude Code 2.1.285 TUI and both cases passed; the evidence is recorded in `docs/verification/supervision.md`. **Verification:** these suites all pass: `fm-precompact-handoff` (12), `fm-session-start` (58), `fm-sessionstart-nudge` (24), `fm-cursor-primary`, `fm-turnend-guard`, `fm-lint` and `fm-documentation-audiences`. `shellcheck -x` is clean on every edited file. The note still carries only the captain's words plus identifiers * no-mistakes(review): Gate every compaction handoff branch on a Claude primary * no-mistakes(test): Run session-forwarding nudge test as a Claude primary * no-mistakes(document): Note Claude-only handoff gating in session-start header
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Standing instruction: when you see a lint problem, test failure or flaky test, get it fixed even if your current work didn't cause it.
Context: the firstmate fork's CI (adonis-garcia-git/firstmate) is red on every PR, including unmodified main at 26d8d42. Two checks fail: Behavior portable serial 2, tests/fm-calm-pi-extension.test.sh ("rendered export DOM violated the Calm conversation boundary"), and serial 4, tests/fm-pi-branch-extension.test.sh ("Pi outcomes rendering consumers must preserve stock behavior"). Both reproduce locally with Pi 0.99.1, released 2026-09-29, which CI installs as the latest public Pi. Main's last green CI ran on Pi 0.87.x. This blocks #23 (the Helm send-failure fix) and every other PR.
What Changed
.pi/extensions/fm-branch-supervision.tsaddsstockToolCallHeader, which reads Pi'sVERSIONto rebuild the call header forfm_branch_outcomesandfm_branch_processedwhen Calm is off. Before Pi 0.99 the header is just the bold title. From 0.99 on, a collapsed call adds a mutedkey=jsonpreview cut at 100 characters, and an expanded call puts one mutedkey: valueline under the title for each argument.tests/fm-pi-branch-extension.test.shgives the Pi stub aVERSIONexport and adds a test that checks both tools' collapsed and expanded headers on 0.87.0 and 0.99.0. The existing stock-consumer test now also compares Calm-offfm_branch_processedrendering with Pi's stockToolExecutionComponent, collapsed and expanded.tests/fm-calm-pi-extension.test.shnow passes if the rendered HTML export either leaves out legacy synthetic custom messages (older Pi) or includes them ashook-message-hiddenrows hidden by default CSS (0.99). It still fails if the export opens with hidden messages shown or if any hook or synthetic row shows in the conversation column, and each check now reports its own error.docs/calm.mdanddocs/calm-mode-feasibility.mdare updated to match, including listingfm_branch_processedamong the hidden tool calls.🤖 Generated with Claude Code
Risk Assessment
✅ Low: A small change limited to tests and rendering: it gates the tool call header on Pi's exported VERSION and checks both tools against real Pi's stock renderer. The export check now allows rows that are hidden by default but still fails on any visible synthetic row. The only concern is some unexercised generic formatting code.
Testing
I ran both previously red suites against a temporary install of real Pi 0.99.1. The pi-branch suite fails at the base commit with the exact CI error and passes at the target commit. The Calm suite passes, but its tmux-driven interactive E2E cases were skipped because tmux is not on PATH. To cover the export boundary those cases guard, I exported sessions with real
pi --export0.99.1 and rendered them in headless Chrome, capturing DOM dumps and screenshots. The pre-fix check fails on an export where the synthetic row is correctly hidden (the CI regression). The post-fix check passes on it, and still fails, as it should, when the synthetic row is visible in the conversation. The screenshots show the hidden row appears only in the session tree, and the visible variant shows it in the conversation column. All temp installs and dirs were removed and the worktree is clean.Evidence: Export boundary check results, pre-fix vs post-fix
Pi 0.99.1 export, synthetic row hidden: pre-fix 26d8d42 boundary check exit=1 Pi 0.99.1 export, synthetic row hidden: post-fix d2f12e8 boundary check exit=0 Pi 0.99.1 export, synthetic row visible: pre-fix 26d8d42 boundary check exit=1 Pi 0.99.1 export, synthetic row visible: post-fix d2f12e8 boundary check exit=1 Error: a visible hook message leaked into the conversation columnEvidence: Base commit pi-branch suite on Pi 0.99.1 (reproduces CI failure)
Evidence: Target commit pi-branch suite on Pi 0.99.1 (exit 0)
Evidence: Target commit Calm suite on Pi 0.99.1 (exit 0, tmux cases skipped)
Evidence: Rendered export DOM files
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
.pi/extensions/fm-branch-supervision.ts:2166-stockToolCallHeaderre-creates Pi 0.99's privateformatToolCallWithArgsin general form. It handles non-object and array args by wrapping them asargs, cuts collapsed previews at 100 characters with..., and rewrites tabs, CRs, and multi-line strings in expanded mode. Its only callers arefm_branch_outcomes(recent?: number) andfm_branch_processed(through: number), so real calls never hit the truncation, multi-line, or non-object branches. Neither the stub test (tests/fm-pi-branch-extension.test.sh:4801) nor the real-Pi comparison (:4937{recent: 2}, :4992{through: 1}) runs them. If Pi changes its format they can drift from stock without any test failing. The intent (get Pi 0.99.1 CI green) only needs the number-argument path: bold title, pluskey=jsonwhen collapsed or\n key: valuewhen expanded. Suggested fix: cut the helper down to that narrower form, and keep the generic branches only if the author wants full fidelity with the upstream port.✅ **Test** - passed
✅ No issues found.
Installed @earendil-works/[email protected] into a throwaway temp prefix (not global);pi --version-> 0.99.1FM_PI_PACKAGE_DIR=<tmp>/pi-coding-agent PATH=<tmp>/.bin:$PATH bash tests/fm-pi-branch-extension.test.shat d2f12e8 -> exit 0Same suite fromgit archive 26d8d42against Pi 0.99.1 -> exit 1, 'Pi outcomes rendering consumers must preserve stock behavior' (reproduces CI)FM_CHROME_BIN=<Google Chrome> bash tests/fm-calm-pi-extension.test.shat d2f12e8 -> exit 0 (tmux-driven E2E cases skipped: tmux not on PATH)Built a session jsonl with a firstmate-synthetic-input custom_message (display:false, and display:true as the adversarial case), exported it with realpi --export0.99.1, dumped the DOM and took screenshots with headless ChromeRan the export-DOM boundary check from each commit's tests/fm-calm-pi-extension.test.sh (26d8d42 and d2f12e8) against both rendered DOMs✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.