Skip to content

feat(bin): add the Phase A zcode crewmate/scout adapter surface - #2

Merged
d-ploutarchos merged 1 commit into
mainfrom
fm/zcode-phase-a
Sep 14, 2026
Merged

d-ploutarchos merged 1 commit into
mainfrom
fm/zcode-phase-a

Conversation

@d-ploutarchos

Copy link
Copy Markdown

zcode harness integration, Phase A (code surface)

Implements the code half of the zcode Phase A plan from data/zcode-research/report.md section 3, against the design contract the merged docs half (PR #1, references/harness/zcode.md) fixed.
Scope is bin/ + tests/ only; docs surfaces stay with the sibling docs worker.

Change-to-plan mapping

Report plan Change Evidence
§3.1 Detection - FM_ZCODE_HARNESS=zcode marker entry plus ancestry rule on the zcode bin bin/fm-harness.sh: marker block requiring real zcode ancestry (ancestry_names_zcode), anchored comm names zcode|zcode-cli|zcode-c|zco, and a *zcode* args arm for the bare node launcher Live process tree observed on zcode-runtime 0.16.5 under tmux: node <...>/.bin/zcode launcher with runtime children at comm zcode-c/zco, process title zcode-cli; pinned by tests/fm-zcode-harness.test.sh detection cases
§3.2 Launch - headless -p/--print template, worker mode pinned, foreign-marker clearing, bin-resolution refusal, crewmate/scout-only bin/fm-spawn.sh: zcode) template (--mode yolo --cwd <worktree> --prompt <encoded brief>, FM_ZCODE_HARNESS=zcode, ZCODE_DISABLE_UPDATE_CHECK=1, full foreign-marker clear), __ZCODEBIN__ resolution refusing when absent, --secondmate refusal, no busy wiring armed Template shape and refusal pinned in tests/fm-zcode-harness.test.sh; --mode default and flag set verified against the captured 0.16.5 --help
§3.2 Model/effort mapping per the captured CLI help Record-and-omit for BOTH axes: the headless flag set has no --model and no effort flag (/model is a TUI slash command only), so both stay in task metadata --model/--effort asserted absent from the launch line while model=/effort= land in meta (tests/fm-zcode-harness.test.sh)
§3.3 Busy detection - grok-regex-style screen scrape, NO Stop-hook plugin bin/fm-busy-lib.sh: zcode arm in the rovo/agy best-effort shape, but with NO default signature - FM_BUSY_ZCODE_REGEX is the only path to busy, non-match stays unknown, never idle Mock-provider probes on 0.16.5 (pipe and PTY): streaming text, a thinking block, and a tool-call turn all render NOTHING mid-turn, only the final assistant text prints after the turn completes, so no honest default signature exists; pinned in tests/fm-zcode-harness.test.sh and tests/fm-busy-adapter-wiring.test.sh
§3.4 Control - interrupt/exit via SIGINT/SIGTERM forwarding bin/fm-control-lib.sh: interrupt key C-c (SIGINT through the pane's foreground process group, the host-contract signal path), repeat 1, no clear key, no ack source, and deliberately NO typed exit command Live under tmux on 0.16.5: mid-turn C-c cancels the turn and the process exits to the pane shell; SIGTERM prints Error: Turn was cancelled.; pinned in tests/fm-zcode-harness.test.sh and the family table in tests/fm-control.test.sh
§3.5 Liveness/state - fm_backend_agent_state + crew-state tail capture (grok precedent) bin/fm-crew-state.sh: zcode joins grok's pre-captured pane-tail feed into the classifier; fm_backend_agent_state itself needs no zcode entry (it is harness-agnostic and dispatches to the backend classifier - see notes) tests/fm-crew-state.test.sh zcode case reads unknown zcode-regex through the crew path even on a busy-looking tail
§3.7 Tests - colocated harness suite + shared enumerating assertions New tests/fm-zcode-harness.test.sh (9 cases); tests/fm-busy-adapter-wiring.test.sh, tests/fm-control.test.sh, tests/fm-crew-state.test.sh extended All four suites pass locally; see evidence below

Known gotcha encoded (report section 2)

Headless error paths exit 0: reproduced on 0.16.5 - the request-signing failure exits 0 with a stack trace while the unconfigured path exits 1.
The classification and control surfaces therefore never read exit status; the fact is recorded in the spawn header and the busy-arm comments.

Evidence beyond the scout report (mock-provider probes, key-free)

All probes ran against the real wrapper/runtime (zcode-app-cli 3.11.2-24, zcode-runtime 0.16.5) with a local mock provider, no Z.AI key:

  • A real headless turn executes end to end: brief in, streamed reply out, exit 0.
  • Nothing renders mid-turn over pipe or PTY: text deltas, a thinking block, and a tool-use round (tool call executed, second request carried the tool result) all print only the final assistant text.
  • --json prints one final JSON object (sessionId, turnId, response, usage, projection.status), not a live event stream.
  • C-c mid-turn cancels and exits silently; SIGTERM cancels and prints Error: Turn was cancelled.
  • Credential path details: ZCODE_API_KEY format is id.secret (one dot), and a workspace .zcode/config.json provider override redirects the provider endpoint.

Files intentionally NOT changed (out of the task's file list)

  • bin/fm-agent-process-lib.sh and bin/fm-session-lock-lib.sh: a live zcode pane reports #{pane_current_command}=node (the wrapper is a node launcher), so without a zcode entry in the shared process-name vocabulary fm_backend_agent_state reads a mid-turn zcode pane as ambiguous - conservative, never dead, so it licenses no duplicate launch, but it also never proves liveness. The entry (anchored names plus the zcode bin path component) should land with the live verification gate together with the observed process-name evidence.
  • bin/fm-control.sh: verify_interrupt_running's agent-must-stay-alive postcondition and do_exit's typed-command path are TUI-shaped. For headless zcode the process IS the turn, so a landed interrupt legitimately ends the process (pane back at shell is the success shape) and mid-turn exit must be signal-shaped rather than a typed command. The interrupt key delivery works today through the existing executor; these two executor refinements should land before firstmate dispatches zcode work.
  • AGENTS.md section 4 and README.md verified-list lines: docs surfaces belong to the sibling docs worker; zcode correctly stays out of the dispatchable list until the live verification gate passes.

Local gates

  • bin/fm-lint.sh (pinned ShellCheck 0.11.0, changed-file mode) and bin/fm-lint-workflows.sh (actionlint 1.7.12): clean.
  • tests/fm-zcode-harness.test.sh, tests/fm-busy-adapter-wiring.test.sh, tests/fm-control.test.sh, tests/fm-crew-state.test.sh: all pass.
  • Sweep of the 78 test suites that exercise a changed file: no regressions; every remaining failure (9 suites) reproduces identically on clean main in this root-container environment and none touches a zcode surface.
  • bin/fm-test-run.sh --check-coverage reports the same sort-order complaint on clean main as on this branch (pre-existing).

Integrate the zcode coding-agent CLI (Linux via the zcode-app-cli
wrapper) as a crewmate/scout-class harness, Phase A only:

- fm-harness.sh detects zcode by anchored ancestry on the wrapper and
  runtime process names (zcode, zcode-cli, zcode-c, zco - observed live
  on zcode-runtime 0.16.5) plus a bare-node args fallback on the zcode
  bin path; FM_ZCODE_HARNESS=zcode is a Firstmate-owned precedence
  override that counts only under real zcode ancestry, the omp pattern.
- fm-spawn.sh launches the verified headless single-prompt template:
  --prompt carries the brief, --mode yolo is pinned explicitly, --cwd
  anchors the run, foreign markers are cleared, and a missing zcode bin
  refuses the spawn. Model and effort follow the record-and-omit
  contract because the headless flag set has neither (verified against
  0.16.5 --help), and zcode is refused for --secondmate.
- fm-busy-lib.sh adds the zcode configured-signature rendered-tail arm:
  no default busy signature ships because headless -p renders nothing
  mid-turn (verified over pipe and PTY across streaming text, a thinking
  block, and a tool-call turn), so FM_BUSY_ZCODE_REGEX is the only path
  to busy and a non-matching tail is unknown, never idle.
- fm-control-lib.sh pins the signal-shaped control mechanics: interrupt
  is C-c (SIGINT through the pane's foreground process group, verified
  live to cancel a mid-turn run), no composer clear, no ack source, and
  no typed exit command - the headless process IS the turn.
- fm-crew-state.sh feeds the zcode busy arm through the grok-style
  pre-captured pane tail.
- tests pin detection, control tables, busy scoping, the launch line,
  record-and-omit axes, no-wiring, bin refusal, and the secondmate
  refusal, and extend the busy-adapter-wiring, control, and crew-state
  shared assertions.
@d-ploutarchos
d-ploutarchos merged commit 290cac5 into main Sep 14, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant