Repository navigation
feat(bin): support zcode as a primary session harness - #7
Merged
Merged
Conversation
Promotes zcode from a crewmate/scout-only adapter to a verified primary session harness: a firstmate running inside the zcode TUI can now acquire and verify the per-home fleet lock, and session start renders a named supervision protocol instead of the unknown-harness fallback. - bin/fm-zcode-lib.sh is new and owns zcode's structural process identity (fm_zcode_path_is_zcode, fm_zcode_args_are_zcode), moved verbatim from bin/fm-agent-process-lib.sh so the pane-liveness classifier, the session-lock ancestry walk, and the own-harness detector read one rule. - bin/fm-session-lock-lib.sh adds the anchored ^zcode$|^zcode-cli$ tokens to FM_HARNESS_RE (the per-call zcode-node-repl MCP kernel stays excluded because it is not a session-lifetime process) and claims a wrapper that presents as `node /path/to/zcode` through the structural argv rule. - bin/fm-harness.sh replaces its loose *zcode* args glob with the same structural rule, so an unrelated node command line that merely mentions zcode never claims the identity. - bin/fm-supervision-instructions.sh renders the new zcode protocol, docs/supervision-protocols/zcode.md: the grok-shaped background-notify cycle where one Bash-tool background task (run_in_background) arms bin/fm-watch-arm.sh and the harness task notification is both the wake and the failure path; the interactive TUI is the supported host. - bin/fm-spawn.sh keeps refusing a zcode secondmate with its own honest reason (secondmate launches have no dated live pass), distinct from the muse/gemini/agy no-primary-protocol refusal it previously shared. - AGENTS.md, README.md, docs/configuration.md, the audiences inventory, and the harness-adapters zcode reference move zcode into the verified primary set with dated live-pass records. - tests pin both layers: portable unit and end-to-end cases in fm-session-lock-ancestry.test.sh (engine and launcher shapes, MCP-kernel and fragment-decoy exclusions, real lock acquisition and refusal trees), renderer coverage in fm-supervision-instructions.test.sh, and a new opt-in live guard fm-zcode-primary-live-e2e.test.sh that proves inside a real zcode session (zcode-app-cli 3.11.2-24 wrapping zcode-runtime 0.16.5) that detection resolves zcode and the lock is acquired naming the session's own engine pid and verified live.
…ib owner pointers
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.
What Changed
FM_HARNESS_REnow anchors thezcodeandzcode-cliprocess names (but not the per-callzcode-node-replMCP kernel),bin/fm-supervision-instructions.shemits zcode wake and repair lines from a newdocs/supervision-protocols/zcode.mdbackground-notify protocol, andbin/fm-spawn.shno longer lists zcode among the crewmate/scout-only harnesses (a zcode--secondmateis still refused, with its own message, until a secondmate live pass exists).bin/fm-zcode-lib.sh, sourced by the pane-liveness classifier, the session-lock ancestry walk, andbin/fm-harness.sh; own-harness detection now uses that argv rule instead of a*zcode*substring glob, so unrelated node command lines that merely mention zcode never match.zcodegraphdecoys, realfm-lock.shacquisition/refusal), a supervision-instructions zcode case, an opt-intests/fm-zcode-primary-live-e2e.test.shregistered in the live family, and update the harness-adapter skill, README, and docs inventories to record zcode's primary role.Risk Assessment
✅ Low: The fix round is four one-line edits that each verifiably resolve their prior finding (the skill index now matches AGENTS.md, README, docs/configuration.md, fm-spawn.sh's secondmate refusal, and the adapter reference; the new opt-in live guard is enumerated in the live-harness-optin family so its fm_live_gate skip is covered; the tmux comment and the live test both point at bin/fm-zcode-lib.sh, which is self-contained and safe to source alone), and the underlying change remains an anchored, structurally-bounded identity extension whose lock, detection, and classifier paths are exercised by behavioral fixtures rather than source greps.
Testing
Drove the change against the real installed zcode harness: the opt-in live guard passed, and a second real zcode session ran a base-vs-target probe from its own tool shell showing the base commit refusing the fleet lock while the target acquires it naming the zcode-cli engine pid and verifies it live. Real orphaned process trees confirmed the kernel, decoy, launcher, unrelated-node, and stale-holder boundaries against the real fm-lock.sh and fm-harness.sh. The supervision renderer emits the zcode primary protocol, and the test runner now schedules the new guard in the live-harness-optin family. The lock-ancestry, supervision-instructions, and zcode-harness unit suites all pass, but the secondmate refusal and the ancestry suite coverage were only exercised through those suites (fake tmux backend and fixtures), so they are recorded as untested rather than live passes. The harness-adapters SKILL.md prose fix has no runtime surface and is left untested. Every scenario driven live passed. Overall result: go.
target fm-harness.sh: zcodeerror: cannot locate harness process in ancestryrc=1; targetlock acquired: harness pid 3278010rc=0;lock: held by live harness pid 3278010; holder comm=zcod…lock acquired: harness pid <zcode-cli pid>with kernel pid skipped; basecannot locate harness process in ancestry(harness-named stages are b…lock: free, no lock file; fm-harness.sh prints unknown for the decoy and unrelated node caseslock acquired: harness pid <node pid>, status live; case 7:lock: stale (pid 3314851 dead or not a harness)primary harness: zcode,Mode: Zcode background-notify supervision., ordinary-wake and repair lines naming the zcode Bash tool background taskEvidence: Real zcode session probe: base refuses the lock, target acquires it naming the zcode-cli engine pid
Source: Real zcode session probe: base refuses the lock, target acquires it naming the zcode-cli engine pid
Evidence: tmux pane transcript of the real zcode session answering the probe
Source: tmux pane transcript of the real zcode session answering the probe
Evidence: Opt-in live guard tests/fm-zcode-primary-live-e2e.test.sh result
Source: Opt-in live guard tests/fm-zcode-primary-live-e2e.test.sh result
ok - a real zcode session detects itself, acquires the fleet lock naming its engine pid, and verifies the holder live exit=0Evidence: Real-process lock boundary drives: engine vs kernel, decoy, node launcher, unrelated node, stale holder
Source: Real-process lock boundary drives: engine vs kernel, decoy, node launcher, unrelated node, stale holder
Evidence: Rendered zcode primary supervision instructions and repair line
Source: Rendered zcode primary supervision instructions and repair line
Evidence: Test-runner family classification of the new live guard (target vs base)
Source: Test-runner family classification of the new live guard (target vs base)
$ bin/fm-test-run.sh --list --family live-harness-optin | grep zcode tests/fm-zcode-primary-live-e2e.test.sh tests/fm-zcode-signals-live-e2e.test.sh $ bin/fm-test-run.sh --list --family unclassified | grep zcode (no zcode test in unclassified) # base commit runner: $ bash <base fm-test-run.sh> --list --family unclassified | grep zcode tests/fm-zcode-primary-live-e2e.test.shEvidence: Lock-ancestry and supervision-instructions suites
Source: Lock-ancestry and supervision-instructions suites
Evidence: zcode harness suite including the secondmate refusal
Source: zcode harness suite including the secondmate refusal
Pipeline
Updates from git push no-mistakes
⏭️ **intent** - skipped
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 5 issues found → auto-fixed ✅
.agents/skills/harness-adapters/SKILL.md:38- The harness-adapters skill index still states that zcode is verified only for crewmate and scout work and never a primary, and cites only the 2026-09-14 pass. AGENTS.md instructs the supervisor to load this skill before every spawn, recovery, and adapter verification, so a firstmate on zcode would read a rule that contradicts AGENTS.md, README.md, docs/configuration.md, and the updated adapter reference in the same change. Fix: move zcode out of the crewmate/scout-only sentence on line 38 and update line 39 to name the 2026-09-15 primary pass and docs/supervision-protocols/zcode.md.bin/fm-test-run.sh:349- The new opt-in live guard tests/fm-zcode-primary-live-e2e.test.sh is not enumerated in the live-harness family list in bin/fm-test-run.sh, unlike its sibling fm-zcode-signals-live-e2e.test.sh and every other *-primary-live-e2e guard. It therefore lands in the serialunclassifiedresidual, where its fm_live_gate opt-in skip is not covered by the family'slive-capabilityexpected-gate-skip class. Fix: add the basename to the live family alternation next to fm-zcode-signals-live-e2e.test.sh.bin/fm-session-lock-lib.sh:32- Simplification: the^zcode$token added to FM_HARNESS_RE accepts a process whose comm is the bare wordzcode. No such process exists in the verified tree: the wrapper is a node script (commnode) and the runtime child renames itselfzcode-cli, which is the shape the live pass, the unit fixture, and the e2e fixture all rely on. The intent (a firstmate inside the zcode TUI acquires and verifies the fleet lock) is satisfied by^zcode-cli$alone. Recommend removing the^zcode$alternative.bin/fm-session-lock-lib.sh:96- Simplification: the new fm_zcode_args_are_zcode call inside fm_harness_process_matches claims a barenode /path/to/zcodelauncher as lock-owning harness identity. In the real tree the tool shell is parented by thezcode-cliengine, so the ancestry walk matches the engine first and stops before ever reaching the wrapper, and a lock never names the wrapper pid for fm_harness_pid_alive to check. This path is exercised only by the syntheticlaunchershape in the unit test, which models an engine that does not rename itself. No stated requirement needs it; recommend removing the branch and the launcher fixture shape.bin/backends/tmux.sh:339- The comment says fm_zcode_args_are_zcode lives in bin/fm-agent-process-lib.sh, but this change moved it to bin/fm-zcode-lib.sh (the tmux backend still gets it transitively). The new live test at tests/fm-zcode-primary-live-e2e.test.sh:116 likewise sources fm-agent-process-lib.sh to reach the function. Point both at bin/fm-zcode-lib.sh so the single-owner claim in the new file's header stays true.🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
target fm-harness.sh: zcodeerror: cannot locate harness process in ancestryrc=1; targetlock acquired: harness pid 3278010rc=0;lock: held by live harness pid 3278010; holder comm=zcod…lock acquired: harness pid <zcode-cli pid>with kernel pid skipped; basecannot locate harness process in ancestry(harness-named stages are b…lock: free, no lock file; fm-harness.sh prints unknown for the decoy and unrelated node caseslock acquired: harness pid <node pid>, status live; case 7:lock: stale (pid 3314851 dead or not a harness)primary harness: zcode,Mode: Zcode background-notify supervision., ordinary-wake and repair lines naming the zcode Bash tool background taskFM_ZCODE_PRIMARY_LIVE=1 bash tests/fm-zcode-primary-live-e2e.test.sh(real zcode one-shot session in tmux, real model turn)Manual live drive: realzcode --mode yolo --promptsession in tmux running a probe from its own tool shell that prints its ancestry, then runs targetbin/fm-harness.sh, base-commitfm-harness.sh, base-commitfm-lock.sh, targetbin/fm-lock.sh,bin/fm-lock.sh status, and base-libfm-lock.sh statuson the target's lockReal orphaned process trees throughbin/fm-lock.sh,bin/fm-lock.sh status, andbin/fm-harness.sh: zcode-cli engine → zcode-node-repl kernel → tool shell (target and base bin/), zcode-node-repl kernel only, zcodegraph decoy,node <...>/zcode-app-cli/bin/zcodelauncher, unrelatednode app.js ... --tag zcode /usr/local/bin/zcode, and stale read after the engine exitsbin/fm-supervision-instructions.sh --harness zcodeand--harness zcode --repair-linebin/fm-test-run.sh --list --family live-harness-optinand--list --family unclassifiedon target vs. base-commit runnerbash tests/fm-session-lock-ancestry.test.shbash tests/fm-supervision-instructions.test.shbash tests/fm-zcode-harness.test.sh(includestest_zcode_is_refused_as_a_secondmate)🔧 **Document** - 2 issues found → auto-fixed (2) ✅
docs/architecture.md:257- Two harness inventories predate this change and still omit zcode: docs/architecture.md line 257 lists the adapters spawn launch stays compatible with (claude ... omp, and agy) without zcode, and docs/tmux-backend.md line 51 lists the pane-liveness classifier identities without zcode even though bin/fm-agent-process-lib.sh classifies zcode/zcode-cli/zcode-node-repl as agent. Both were stale before this branch (zcode became a crewmate adapter earlier), so they were left untouched under scope discipline; a one-word addition to each is the follow-up.bin/fm-test-run.sh:1363- bin/fm-test-run.sh's changed-file family mapping has an explicit entry for bin/fm-agent-process-lib.sh (backend-dispatch, real-herdr-gated, pure-contract-unit) but none for the new bin/fm-zcode-lib.sh, which that classifier, bin/fm-session-lock-lib.sh, and bin/fm-harness.sh now all source. This is executable test-selection behavior rather than documentation, so it was not changed here; decide whether the new lib should map to the same families so a change to it selects the tmux, herdr, and session-lock suites.🔧 Fix applied.
2 infos still open:
bin/fm-test-run.sh:1363- No explicit family entry is needed for bin/fm-zcode-lib.sh. Verified with a temporary probe commit (removed afterwards): a change to only that file already selects tests/fm-tmux-agent-liveness.test.sh, tests/fm-backend-herdr.test.sh, tests/fm-session-lock-ancestry.test.sh, tests/fm-zcode-harness.test.sh, tests/fm-cursor-primary.test.sh, tests/fm-claude-stop-autoarm.test.sh, tests/fm-turnend-guard.test.sh, and both zcode live guards (137 scripts total) through families_for_unmapped_bin, which scans test references and the lib's consumers (fm-agent-process-lib.sh, fm-session-lock-lib.sh, fm-harness.sh). Since this is executable test-selection behavior and the fallback already covers the requested suites, the runner was left unchanged.docs/tmux-backend.md:51- The pane-liveness identity sentence I extended with Zcode still omits Gemini and omp, both of which bin/fm-agent-process-lib.sh classifies as agent (omp anchored by name, Gemini through bin/fm-gemini-lib.sh's node-launcher rule). Both omissions predate this branch and are unrelated to zcode, so I applied only the selected one-word zcode fix; adding the two names is a trivial follow-up.🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.