Skip to content

fix: preserve Herdr gate during task replacement - #2838

Merged
kunchenguid merged 1 commit into
kunchenguid:mainfrom
karotkriss:fm/fm-2575-brief-gate
Aug 23, 2026
Merged

kunchenguid merged 1 commit into
kunchenguid:mainfrom
karotkriss:fm/fm-2575-brief-gate

Conversation

@karotkriss

Copy link
Copy Markdown
Contributor

Intent

Fix upstream issue #2575 in bin/fm-brief.sh: fm-brief's Herdr safety gate quotes {TASK}, so filling the brief with the documented global replace corrupts the gate.

Defect: AGENTS.md section 11 and fm-brief.sh's own help instruct firstmate to 'replace every {TASK} placeholder'. The unguarded Herdr declaration section then quoted that same placeholder in its prose ('this scaffold cannot inspect the task text that replaces {TASK} later.'), so the documented global replace spliced the entire task body into the middle of the safety gate's sentence. The result is a second garbled copy of the task and a destroyed safety contract - the exact failure that gate exists to prevent, and it gets less visible the longer the task body is. Live reproduction: a real triage brief showed the corruption.

Fix chosen: reword the gate so the placeholder exists only at its genuine fill site ('this scaffold cannot inspect the task text filled in above.'). The issue author preferred renaming the fillable token to {TASK_BODY}, but that is deliberately NOT what was done here: renaming would have to propagate through AGENTS.md, the secondmate-provisioning skill, and the unfilled-charter guards in bin/fm-home-seed.sh and bin/fm-remote-home-seed.sh which grep briefs for the literal '{TASK}'. The reword removes the trap entirely in one file with no cross-surface contract change, and the gate's wording stays precise about what it cannot inspect (the task text sits directly above the gate in both the ship and scout scaffolds). The issue explicitly permits either option ('Pick either, but pick one'), and its third option (a duplicate-detection validation pass) was rejected as symptom-catching.

Scope is deliberately minimal and confined to one script plus its colocated test: no rename of the placeholder token, no new validation pass, no changes to AGENTS.md or the seed guards.

Regression test first, then the fix: tests/fm-brief.test.sh gains test_documented_global_replace_leaves_the_herdr_gate_intact, which scaffolds ship and scout briefs, asserts exactly one {TASK} fill site, performs the documented global replace end to end, and asserts the task body lands exactly once and the safety-gate sentence survives. It fails on the pre-fix script ('ship brief must carry exactly one {TASK} fill site, found 2') and passes after. The secondmate charter path is out of scope for that assertion because its two {TASK} occurrences (charter and routing scope) are both genuine fill sites and it carries no Herdr section.

Verification run locally: tests/fm-brief.test.sh passes all 21 checks; shellcheck on both touched files reports only pre-existing SC1091/SC2153 informational notes. Three failures in the broader changed-file selection (fm-lint-workflows, fm-lint, fm-test-run) are environment-only - actionlint and ruby are not installed on this machine - and are unrelated to this diff, which touches no workflows.

Deliverable: a PR to upstream kunchenguid/firstmate with 'Fixes #2575'.

What Changed

Risk Assessment

✅ Low: The change is narrowly scoped, removes the only accidental {TASK} occurrence from both affected generated brief paths, and tests the generated brief as an intentional public output contract.

Testing

The author supplied prior focused and shellcheck verification; this phase independently passed tests/fm-brief.test.sh and reproduced the end-user global-replacement workflow for ship and scout briefs. Captured evidence shows the historical output duplicated the task and corrupted the safety gate, while the fixed output contains one task body and an intact gate. No UI surface exists for this CLI-generated Markdown change, so rendered visual evidence was not applicable.

Evidence: Baseline versus fixed global replacement comparison

Source: Baseline versus fixed global replacement comparison

End-user reproduction: scaffold each brief, then globally replace every documented {TASK} placeholder.
Task body: Restart the Herdr session, then profile it.

baseline ship: task body occurrences=2
4:Restart the Herdr session, then profile it.
7:**HARD SAFETY GATE:** this scaffold cannot inspect the task text that replaces `Restart the Herdr session, then profile it.` later.
7:**HARD SAFETY GATE:** this scaffold cannot inspect the task text that replaces `Restart the Herdr session, then profile it.` later.

baseline scout: task body occurrences=2
4:Restart the Herdr session, then profile it.
7:**HARD SAFETY GATE:** this scaffold cannot inspect the task text that replaces `Restart the Herdr session, then profile it.` later.
7:**HARD SAFETY GATE:** this scaffold cannot inspect the task text that replaces `Restart the Herdr session, then profile it.` later.

current ship: task body occurrences=1
4:Restart the Herdr session, then profile it.
7:**HARD SAFETY GATE:** this scaffold cannot inspect the task text filled in above.

current scout: task body occurrences=1
4:Restart the Herdr session, then profile it.
7:**HARD SAFETY GATE:** this scaffold cannot inspect the task text filled in above.
Evidence: Filled ship brief

Source: Filled ship brief