Repository navigation
fix(bin): name the next step in cd-guard refusals and print absolute wake-drain recipes - #16
Merged
Merged
Conversation
…wake-drain recipes
…ontaining comments
… parser to accept absolute drain paths for both main and branch sessions. Reproduced the CI failure before the fix. The full wake-queue suite, targeted pinned ShellCheck lint, and git diff --check now pass
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
Yes on cd guard fixes
Context: Fable's advice (data/fm-cd-guard-advice-fable/report.md) is to keep refusing a persistent top-level cd in the primary firstmate checkout and not rewrite commands, but to make two small fixes: (2) the refusal says "the shell is already at the home, drop the cd" when the target resolves to the home, and otherwise quotes the exact rewritten command to run, such as (cd
&& rest) for a one-line command, or tells the agent to wrap a multi-line command in ( and ) on their own lines; (4) the WAKE_ACK_REQUIRED recipe printed by bin/fm-wake-drain.sh uses an absolute path to the script instead of a relative bin/ path. Of 87 past refusals, 30 were a redundant cd back to the home, 14 of them wrapping a relative bin/fm-* call.What Changed
bin/fm-cd-command-policy.mjsno longer gives one fixedpersistent-cdreason. When thecdtarget and the shell's cwd both resolve to the home, the refusal says to drop the redundantcd. In other cases it quotes a one-line command back wrapped as a subshell(…). If the command spans several lines, it says to wrap it in(and)on their own lines. Commands that are very long (over 160 characters) or contain#are not quoted. The policy accepts new--home/--cwdarguments, andbin/fm-cd-pretool-check.shfills them from the firstmate root and the payload'scwd. These arguments only change the wording: the deny decision does not use them, and no rewritten command is returned to the harness.bin/fm-wake-drain.sh, theWAKE_ACK_REQUIREDrecipe and the related "re-run" / "run … --ack-through" messages now use the script's absolute directory ($SCRIPT_DIR/fm-wake-drain.sh) instead of a relativebin/path.docs/cd-guard.mddescribes the new reason forms. The tests intests/fm-cd-pretool-check.test.sh,tests/fm-supervision-host.test.shandtests/fm-wake-drain-outcome-backstop.test.share updated for the new reasons and the absolute recipe paths.🤖 Generated with Claude Code
Risk Assessment
✅ Low: Only the refusal wording and the printed recipe paths change; the deny decision is unchanged and SCRIPT_DIR is already absolute. The one defect found is an occasional broken suggestion for commands that end in a comment.
Testing
The real cd-guard hook ran in a disposable plain firstmate clone with every refusal shape the intent names, plus adversarial cases: a cd to the home from inside a clone, a trailing comment, an over-long command, and a symlinked path to the home. A real Claude primary on the lab tmux socket received both the subshell suggestion and the 'already at the home, drop the cd' refusal, and recovered by dropping the cd. When asked to run a cd straight to the home path, the model itself stripped the cd before the hook saw it, so the symlinked home path was used to get that refusal through the live harness. The wake drain printed an absolute-path WAKE_ACK_REQUIRED recipe. Run verbatim from /, that recipe acknowledged the wake and emptied the queue. Both changed targeted test files pass. All disposable clones, lab homes, and tmux servers were removed. Every scenario passed.
cd <symlink-home> && ls ...and then ranls bin/fm-cd-pretool-check.shsucces…(cd projects/foo && rest)command is quoted backRun it scoped to a subshell instead: (cd projects/foo && ls)Evidence: cd-guard hook transcript (all refusal shapes + adversarial cases)
Source: cd-guard hook transcript (all refusal shapes + adversarial cases)
Evidence: Live Claude primary pane showing deny messages and recovery
Source: Live Claude primary pane showing deny messages and recovery
Evidence: Live Claude Bash tool calls and hook results from session transcript
Source: Live Claude Bash tool calls and hook results from session transcript
Evidence: Wake drain absolute-path recipe executed from /
Source: Wake drain absolute-path recipe executed from /
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-cd-command-policy.mjs:40- One-line refusals quote the command back as(${command}), but a command ending in a shell comment gives a suggestion that will not parse. Reproduced:cd projects/x && make # runproduces(cd projects/x && make # run), where the#comments out the closing). An agent that copies the suggested command verbatim hits a syntax error or an unterminated-subshell prompt. Fix at bin/fm-cd-command-policy.mjs:40: when the lexed command contains a top-level comment, either use the generic 'wrap the whole command in ( and )' wording or put the)on its own line. The multi-line branch at line 37 already handles commands with#correctly because its)goes on a separate line.bin/fm-cd-command-policy.mjs:24- Component not required by the intent: the MAX_QUOTED_COMMAND (160-char) fallback at lines 24 and 42. The intent says a one-line command should otherwise be quoted back exactly as(cd <dir> && rest), with no length cap. For one-line commands over 160 characters, this fallback prints only generic 'wrap the whole command in ( and )' advice, which goes beyond what the intent specifies. Recommended remedy: remove the length cap and always quote one-line commands, unless the author confirms the cap is wanted.bin/fm-cd-command-policy.mjs:31- The 'already at the home' wording is narrower than the intent. The intent says to use it when the target resolves to the home; the code also requires the shell's cwd (from the payload, or the hook's $PWD) to resolve to the home. This is a deliberate safety tightening, documented in docs/cd-guard.md. It only means that a cd to the home from somewhere else gets the subshell advice instead, which is still correct. No action needed.🔧 Fix applied.
2 issues (1 warning, 1 info) still open:
bin/fm-cd-command-policy.mjs:24- Component not required by the intent: the MAX_QUOTED_COMMAND (160-char) fallback at lines 24 and 42. The intent says a one-line command should otherwise be quoted back exactly as(cd <dir> && rest), with no length cap. For one-line commands over 160 characters, this fallback prints only generic 'wrap the whole command in ( and )' advice, which goes beyond what the intent specifies. Recommended remedy: remove the length cap and always quote one-line commands, unless the author confirms the cap is wanted.bin/fm-cd-command-policy.mjs:31- The 'already at the home' wording is narrower than the intent. The intent says to use it when the target resolves to the home; the code also requires the shell's cwd (from the payload, or the hook's $PWD) to resolve to the home. This is a deliberate safety tightening, documented in docs/cd-guard.md. It only means that a cd to the home from somewhere else gets the subshell advice instead, which is still correct. No action needed.✅ **Test** - passed
✅ No issues found.
cd <symlink-home> && ls ...and then ranls bin/fm-cd-pretool-check.shsucces…(cd projects/foo && rest)command is quoted backRun it scoped to a subshell instead: (cd projects/foo && ls)bin/fm-cd-pretool-check.sh --claudefed Claude-shaped PreToolUse payloads (tool_input.command + cwd) inside a disposable plaingit cloneof the target commit: redundant cd to home, one-line clone cd, multi-line cd, cd-to-home from inside a clone, trailing#comment, >160-char command, symlink-to-home cd, subshell-scoped cd, git -CRealclaudeprimary started per runbook ontmux -L fm-labwith abin/fm-lab-home.sh createFM_HOME, cwd = the disposable plain clone; prompted it to runcd projects/foo && lsandcd <symlink-to-home> && ls bin/fm-cd-pretool-check.sh, and to follow the deny advice; tool calls and results were read from the session transcriptFM_SUPERVISION_ACTOR=branch bin/fm-wake-drain.shrun from /tmp against a disposable FM_STATE_OVERRIDE with one queued signal and a published grant; the printed WAKE_ACK_REQUIRED recipe was then run verbatim from/bash tests/fm-cd-pretool-check.test.shbash tests/fm-wake-drain-outcome-backstop.test.sh✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.