Repository navigation
CI mirror: refactor(bin): give harness launch knowledge one owner in fm-launch-lib.sh - #2
Closed
sbracewell64 wants to merge 10 commits into
Closed
sbracewell64 wants to merge 10 commits into
sbracewell64 wants to merge 10 commits into
Intent
Give firstmate's harness launch knowledge exactly one owner, as a pure refactor with zero behavior change.
Background: firstmate is gaining a second caller of its launch knowledge - a fleet launcher that opens a PRIMARY firstmate session, alongside bin/fm-spawn.sh which opens crewmate sessions. Today that knowledge lives only inside bin/fm-spawn.sh. The drift this prevents already happened once: an external platform hand-copied Claude's launch command and dropped the CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION=false ghost-text suppression variable, which firstmate would otherwise read as real typed input when it captures a pane. One owner, or it happens again.
What was done: extracted launch_template, model_flag_for_harness, and effort_flag_for_harness out of bin/fm-spawn.sh into a new sourced bin/fm-launch-lib.sh, and had fm-spawn.sh source it. No copy of those three functions remains in fm-spawn.sh; the library is their single definition.
Deliberate decision the captain specified up front, not a free choice made during implementation: launch_template additionally gains a 'kind' axis distinguishing 'primary' from the existing crewmate shape, because a primary session has no task, no worktree, no brief, and no status file. The primary branch was added while keeping every existing crewmate call path byte-identical in behavior - a crewmate spawn on every verified harness must compose exactly the command it composes today, ghost-text variable included. The second consumer (sibling task fm-launch-menu, blocked on this one) is already designed against this exact shape, so the axis shape is intentional and any alternative shaping would have required escalation rather than a local judgment call.
Also deliberate: the launcher itself is explicitly out of scope and is not built here. bin/fm-brief.sh, bin/backends/herdr.sh, bin/fm-backend.sh, bin/fm-merge-local.sh, and bin/fm-ff-lib.sh were left untouched because other workers were concurrently live in those files.
Testing: a colocated regression test covers the extracted library directly, including the new primary kind, and proves the crewmate templates are unchanged. The existing spawn test suite passes untouched.
Repo conventions applied per firstmate's coding guidelines: shellcheck-clean bin scripts, one sentence per line in prose, plain dashes, colocated tests, no agent co-author on commits.
This is a relaunch for publication only. The implementation already passed review, tests, documentation, and lint in a prior pipeline run; that run failed solely at the push step because the GitHub account had pull-only access to the upstream repository. That is now cleared: pushes are routed to the sbracewell64/firstmate fork while fetches still track upstream, so the resulting pull request into kunchenguid/firstmate is expected to be a cross-fork PR.
Two review findings from the prior run were escalated and decided by the project owner; both decisions are already committed on this branch, so they are deliberate and should not be re-flagged:
The opencode primary template uses the full verified briefless shape - the OPENCODE_CONFIG_CONTENT allow-permission JSON plus
opencode --auto, not--prompt. The crewmate template keeps--promptbecause it has a brief to pass; a primary has none. The empirical evidence CONTRIBUTING.md:50 requires is tests/fm-opencode-primary-live-e2e.test.sh:256 and :310, which both launch a primary opencode TUI exactly that way, and it is cited in the code comment.Kimi binary resolution (resolve_kimi_binary) deliberately stays private to bin/fm-spawn.sh and was NOT extracted. The planned second consumer, fm-launch-menu, reaches Kimi through the pi harness rather than a native kimi binary, so it will never call it and there is no hand-copy drift to prevent; extracting it would have expanded a pure refactor to serve a consumer that will not exist. That rationale is recorded as a comment at the KIMIBIN placeholder so it is not re-raised, to be revisited only if a native kimi launch ever becomes a launcher entry.
Also already applied: the placeholder contract now lives in bin/fm-launch-lib.sh's own header (fm-spawn.sh points at it), AGENTS.md section 4 attributes the launch flags and unverified-adapter guard to bin/fm-launch-lib.sh, and the one-owner test guard in tests/fm-launch-lib.test.sh covers every per-harness autonomy marker with its fail-open
|| trueremoved.Publication routing note: the gate is configured with fork = sbracewell64/firstmate, so branches push to that fork while the pull request opens against kunchenguid/firstmate. A cross-fork PR is the expected and correct outcome here.
What Changed
launch_template,model_flag_for_harness, andeffort_flag_for_harness(plus theshell_quotehelper they depend on) out ofbin/fm-spawn.shinto a new sourcedbin/fm-launch-lib.sh, which is now their single definition;fm-spawn.shsources it and keepsresolve_kimi_binaryprivate, and the placeholder contract moved into the library's own header. Crewmate, scout, and secondmate launch commands are byte-identical to before.launch_templategained akindaxis with a newprimaryarm for briefless primary sessions on claude, codex, opencode, pi, and grok, while kimi returns non-zero forprimaryso the guard refuses instead of emitting an unsubstitutable command. Each arm cites its in-repo evidence, the header records a consumer obligation to disclose the permission-bypass posture of every primary template that carries one, and the library distinguishes "unverified adapter" from "verified adapter, unsupported kind" as separate refusal causes.tests/fm-launch-lib.test.shpinning every crewmate and primary template plus a one-owner guard that fails if a launch command is hand-written elsewhere inbin/, mapped the new file intobin/fm-test-run.shchange-based selection, and repointed launch-command ownership inAGENTS.md,CONTRIBUTING.md,docs/configuration.md,docs/scripts.md, and theharness-adaptersskill atbin/fm-launch-lib.sh.Risk Assessment
✅ Low: This round changes only comments, it correctly resolves the prior finding by grounding pi's posture in SKILL.md:272 and widening the consumer obligation to all five primaries rather than exempting one, every citation verifies, and the crewmate call paths remain byte-identical to the base commit.
Testing
I exercised the extraction end to end rather than only through unit assertions: the new tests/fm-launch-lib.test.sh, the touched kimi/pi/captain-translation contract tests, and the three spawn suites all pass, and on top of that I built a differential harness that compares base commit a5fe1bc against HEAD across 438 fully substituted launch commands (zero differences) and a real-script end-to-end run where bin/fm-spawn.sh at each commit types its launch line into a recording tmux (byte-identical for all five task harnesses). The new primary kind was demonstrated as the fleet launcher will consume it, including kimi's refusal and the fail-closed unverified-adapter guard still firing from the real script, and five planted mutations confirmed the one-owner guard and the template pins actually catch drift including the exact historical ghost-text omission. No visual artifact applies - this change is shell library code whose entire end-user surface is the composed launch command string, which the CLI transcripts capture directly. The only failure seen was one node-driven pi watch-extension assertion that reproduces unchanged at the base commit.
Evidence: base vs HEAD launch command differential (438 combinations, 0 differences) + the new primary kind
combinations compared (harness x kind x model x effort, fully substituted): 438 RESULT: 0 differences. Every composed launch command is byte-identical. --- ghost-text suppression survived the extraction (the drift this refactor exists to prevent) --- claude ship carries CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION=false claude scout carries CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION=false claude secondmate carries CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION=false claude primary carries CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION=false NEW 'primary' KIND: what the fleet launcher will get from the one owner claude CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION=false claude --dangerously-skip-permissions --model 'opus' --effort 'high' codex codex --model 'opus' -c 'model_reasoning_effort="high"' --dangerously-bypass-approvals-and-sandbox opencode OPENCODE_CONFIG_CONTENT='{"permission":{"*":"allow"}}' opencode --model 'opus' --auto pi pi --model 'opus' --thinking 'high' grok grok --trust --always-approve --model 'opus' --reasoning-effort 'high' kimi REFUSED (exit 1, no output) - not a verified primary harness --- unverified adapter still refused for every kind (the fail-closed guard) --- kind=ship refused (exit 1) kind=scout refused (exit 1) kind=secondmate refused (exit 1) kind=primary refused (exit 1)Evidence: end-to-end: the literal command the real fm-spawn.sh types into the crewmate pane, base vs HEAD
--- claude ------------------------------------------------------------- HEAD b08b230 (bin/fm-launch-lib.sh): CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION=false claude --dangerously-skip-permissions --model 'opus' --effort 'high' "$('<FM_ROOT>/bin/fm-operational-input.sh' encode launch-brief < '<RUN>/home/data/<TASK>/brief.md')" base a5fe1bc (pre-extraction fm-spawn.sh): IDENTICAL --- codex ------------------------------------------------------------- HEAD b08b230 (bin/fm-launch-lib.sh): codex --model 'opus' -c 'model_reasoning_effort="high"' --dangerously-bypass-approvals-and-sandbox -c "notify=["bash","-c","touch '<RUN>/home/state/<TASK>.turn-ended'"]" "$('<FM_ROOT>/bin/fm-operational-input.sh' encode launch-brief < '<RUN>/home/data/<TASK>/brief.md')" base a5fe1bc (pre-extraction fm-spawn.sh): IDENTICAL --- opencode ---------------------------------------------------------- base a5fe1bc: IDENTICAL --- pi ---------------------------------------------------------------- base a5fe1bc: IDENTICAL --- grok -------------------------------------------------------------- base a5fe1bc: IDENTICAL RESULT: real spawned launch lines are byte-identical at base and HEAD --- fail-closed unverified-adapter guard, still enforced through the sourced library --- $ fm-spawn.sh <task> <project> not-a-harness error: unknown harness 'not-a-harness'; pass a raw launch command to use an unverified adapterEvidence: mutation check: the one-owner guard and template pins catch all five planted drifts
--- mutation 1: a second bin/ consumer hand-copies claude's command --- not ok - a launch command is hand-written outside bin/fm-launch-lib.sh ('--dangerously-skip-permissions'): bin/fm-launch-menu.sh --- mutation 2: fm-spawn.sh keeps its own copy of launch_template --- not ok - bin/fm-spawn.sh defines launch_template again; bin/fm-launch-lib.sh is the single owner --- mutation 3: the grok primary template loses --trust --- not ok - launch_template grok primary drifted: expected: grok --trust --always-approve MODELFLAG____EFFORTFLAG got: grok --always-approve MODELFLAG____EFFORTFLAG --- mutation 4: the opencode primary reverts to the crewmate --prompt shape --- not ok - launch_template opencode primary drifted: expected: ... opencode MODELFLAG--auto got: ... opencode MODELFLAG--prompt --- mutation 5: a shipped crewmate template drifts (claude loses the prefix) --- not ok - launch_template claude ship drifted not ok - existing launch template changed: (tests/fm-kimi-harness.test.sh byte pin) RESULT: all five mutations are caught; the guard and the pins are load-bearing.Evidence: reproducible differential harness (base vs HEAD launch commands)
Evidence: reproducible end-to-end spawn harness
Evidence: changed-file test selection now includes tests/fm-launch-lib.test.sh