From 3733390114264ea65dc40d1744841a2aa032e915 Mon Sep 17 00:00:00 2001 From: Eduard Ionel STAN Date: Mon, 14 Sep 2026 16:15:43 +0200 Subject: [PATCH 01/15] docs: verify prime-agent 0.9.4 adapter --- docs/documentation-audiences.json | 4 + docs/verification/prime-agent.md | 120 ++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 docs/verification/prime-agent.md diff --git a/docs/documentation-audiences.json b/docs/documentation-audiences.json index 907f3888ff8..3d5b78cbad4 100644 --- a/docs/documentation-audiences.json +++ b/docs/documentation-audiences.json @@ -476,6 +476,10 @@ "path": "docs/verification/rovo.md", "audience": "maintainer-verification" }, + { + "path": "docs/verification/prime-agent.md", + "audience": "maintainer-verification" + }, { "path": "docs/verification/runtime-backends.md", "audience": "maintainer-verification" diff --git a/docs/verification/prime-agent.md b/docs/verification/prime-agent.md new file mode 100644 index 00000000000..83942a4d245 --- /dev/null +++ b/docs/verification/prime-agent.md @@ -0,0 +1,120 @@ +# Verification: the prime-agent crewmate/scout and secondmate adapter + +Active empirical facts for firstmate's Prime Agent adapter. +The skill tree rooted at [`.agents/skills/harness-adapters/SKILL.md`](../../.agents/skills/harness-adapters/SKILL.md) owns the operating facts through [`references/harness/prime-agent.md`](../../.agents/skills/harness-adapters/references/harness/prime-agent.md); this record owns how they were established and what remains unproven. + +## Subject + +| Field | Value | +|---|---| +| Version | `prime-agent 0.9.4` | +| Verified | 2026-09-14 | +| Binary | `/home/eduard/.local/bin/prime-agent` | +| Platform | Linux x86_64 | +| Backend | Herdr 0.8.2, in an isolated non-`default` lab session created only through `bin/fm-herdr-lab.sh` | +| Provider and model | `openai-codex` and `gpt-5.6-terra` | + +Every Herdr command below ran through the named lab helper with a trailing `--session` argument. +The helper's fleet-state tripwire reported the same running `default` session before provisioning and after teardown. +The shared Prime Agent daemon was inspected read-only and was not stopped, restarted, upgraded, or reconfigured. + +## Detection and launch flags + +The live launch used the same marker and flags that Firstmate emits: + +``` +$ env -u CLAUDECODE -u GROK_AGENT PI_CODING_AGENT=true FM_PI_HARNESS=prime-agent prime-agent --model gpt-5.6-terra --provider openai-codex --thinking low +``` + +Herdr's process inspection returned the exact foreground identity: + +``` +{"process_info":{"foreground_processes":[{"argv":["prime-agent"],"name":"prime-agent"}],"pane_id":"w2:p1"}} +``` + +The live worker rendered the following startup fields: + +``` +version v0.9.4 +model gpt-5.6-terra +← agents/resume GPT-5.6 Terra • low ? for shortcuts +``` + +An extension captured the launch environment with these values: + +``` +PI_CODING_AGENT=true +FM_PI_HARNESS=prime-agent +PRIME_AGENT_INTERNAL_DAEMON_WORKER=1 +PRIME_AGENT_CODING_AGENT_DIR=/home/eduard/.prime/agent +``` + +The Prime Agent daemon status was read with `prime-agent status --json` and reported `version: 0.9.4`, `protocolVersion: 7`, `status: current`, `isDefault: true`, and `hasTrackedWorkers: true`. + +## Extension loading and trust + +A fresh lab project containing `.prime/agent/extensions/auto.ts` wrote its load marker without an explicit `-e` flag. +The same launch showed no trust prompt and reached the Prime Agent composer. +A worker extension supplied with `-e ` also loaded and received `session_start`, `agent_start`, `turn_end`, and `agent_end` callbacks. +The extension load and callback evidence was recorded as JSON lines: + +``` +{"name":"loaded","value":{"pi":"true","fm":"prime-agent","daemon":"1","dir":"/home/eduard/.prime/agent"}} +{"name":"session_start","value":{"type":"session_start","reason":"startup"}} +{"name":"agent_start","value":{"type":"agent_start"}} +{"name":"turn_end","value":{"type":"turn_end","turnIndex":0}} +{"name":"agent_end","value":{"type":"agent_end"}} +``` + +This verifies the 0.9.4 extension surface and the absence of a trust stop for project-local `.prime/agent/extensions/` discovery. + +## Busy and idle state + +A prompt that asked the model to run `sleep 15` changed Herdr's native agent state from `idle` to `working` while the tool was running. +The same pane returned to `idle` after the turn completed and rendered the requested response. +The decisive live reads were: + +``` +{"agent":{"agent":"prime-agent","agent_status":"working","cwd":".../.prime-live-lab","pane_id":"w2:p1"}} +{"agent":{"agent":"prime-agent","agent_status":"idle","cwd":".../.prime-live-lab","pane_id":"w2:p1"}} +``` + +The 0.9.4 extension callbacks also showed `agent_start` before the long turn and `agent_end` after it. +The adapter's semantic busy-state extension uses those two callbacks and leaves `turn_end` as a notification only. + +## Interrupt, quit, and relaunch + +A second `sleep 30` prompt reached `agent_status=working`. +One `Escape` sent through `bin/fm-herdr-lab.sh run ... pane send-keys ... escape` changed the native state to `done` and rendered `Operation aborted` without completing the requested response. + +Sending `/quit` followed by Enter returned Herdr's process inspection to a lone `/bin/bash` pane: + +``` +{"process_info":{"foreground_processes":[{"argv":["/bin/bash"],"name":"bash"}],"pane_id":"w2:p1"}} +``` + +Launching the same command again in that pane rendered `version v0.9.4`, `model gpt-5.6-terra`, and an idle composer. +The relaunch reused the same Herdr pane and project directory. + +## Detached daemon session retirement + +The Prime Agent client created a detached daemon worker while the Herdr pane was active. +The launch environment reported `PRIME_AGENT_INTERNAL_DAEMON_WORKER=1` and the daemon's `status --json` reported tracked workers. +After `/quit`, the Herdr pane had no Prime Agent process in its foreground process list while the daemon session remained registered. +The adapter's retirement path is exercised by `fm-prime-agent-lib.sh` against the exact project directory during task cleanup and secondmate relaunch; the shared daemon itself was never stopped. + +## Scope and remaining boundaries + +The live evidence covers the crewmate/scout launch, local secondmate launch surface, marker export, launch flags, project-local extension discovery, explicit extension loading, busy and idle callbacks, Escape, `/quit`, relaunch, and detached-worker behavior on Prime Agent 0.9.4. +Remote secondmates remain outside this evidence and are still refused by the remote readiness allowlist. +Pane resume and fork are not claimed because Firstmate uses deterministic relaunch for Prime Agent. +No RPC backend, RLM control-plane replacement, or upstream repository operation was tested or changed. + +## Refreshing this record + +Run the portable adapter and busy-state suites, then run the opt-in live guard after a Prime Agent or Herdr upgrade: + +``` +bin/fm-test-run.sh --jobs 1 tests/fm-prime-agent-harness.test.sh tests/fm-busy-adapter-wiring.test.sh tests/fm-quota-choose.test.sh tests/fm-spawn-dispatch-profile.test.sh +FM_PRIME_AGENT_LIVE_E2E=1 bin/fm-test-run.sh tests/fm-prime-agent-signals-live-e2e.test.sh +``` From 6eba8c54c923b1831de53405d0fd717af0b5bc8a Mon Sep 17 00:00:00 2001 From: Eduard Ionel STAN Date: Mon, 14 Sep 2026 16:18:41 +0200 Subject: [PATCH 02/15] feat: wire prime-agent semantic busy state --- bin/fm-busy-lib.sh | 2 ++ bin/fm-spawn.sh | 28 +++++++++------ tests/fm-busy-adapter-wiring.test.sh | 54 +++++++++++++++++++++++++++- 3 files changed, 73 insertions(+), 11 deletions(-) diff --git a/bin/fm-busy-lib.sh b/bin/fm-busy-lib.sh index d8f7a0ee111..8c61d34c502 100755 --- a/bin/fm-busy-lib.sh +++ b/bin/fm-busy-lib.sh @@ -29,6 +29,7 @@ # task's recorded harness classifies unknown, so one adapter's writer can # never classify another adapter): # pi-ext Pi/pi-signed per-task extension (agent_start/agent_settled) +# prime-ext Prime Agent per-task extension (agent_start/agent_end) # omp-ext omp (Oh My Pi) per-task extension (agent_start/agent_end without willContinue) # opencode-plugin OpenCode per-task plugin (session.status) # claude-hook Claude lifecycle hooks (UserPromptSubmit/Stop/StopFailure/SessionEnd) @@ -199,6 +200,7 @@ fm_busy_sources_for_harness() { # opencode*) adapter=opencode-plugin ;; gemini*) adapter=gemini-hook ;; pi|pi-signed) adapter=pi-ext ;; + prime-agent) adapter=prime-ext ;; omp) adapter=omp-ext ;; kimi*) fm_busy_kimi_verified || { printf ''; return 0; } diff --git a/bin/fm-spawn.sh b/bin/fm-spawn.sh index cd7e9a83608..f57f9874aa0 100755 --- a/bin/fm-spawn.sh +++ b/bin/fm-spawn.sh @@ -3679,7 +3679,7 @@ if [ "$KIND" != secondmate ]; then ;; esac case "$HARNESS" in - claude*|opencode*|pi|pi-signed|omp) + claude*|opencode*|pi|pi-signed|prime-agent|omp) BUSY_GEN=$("$FM_ROOT/bin/fm-busy-event.sh" arm "$STATE_REAL" "$ID") || { echo "error: failed to arm the busy-state contract for $ID" >&2 exit 1 @@ -3817,18 +3817,26 @@ EOF exclude_path '.opencode/plugins/fm-busy-state.js' ;; prime-agent) - # prime-agent's crew wake is a turn-end NOTIFICATION only, deliberately - # with no busy-state wiring. Nothing is armed for the same reason muse and - # standalone Kimi are not: a seeded busy record needs a writer that can - # clear it. Written OUTSIDE the worktree like the Pi extension, so the - # project stays clean. Cleaned by teardown. + # Written OUTSIDE the worktree like Pi's, so the task extension can write + # semantic busy state and the turn-end notification without dirtying the + # project. Cleaned by teardown. cat > "$STATE/$ID.prime-ext.ts" < + new Promise((resolve) => { + execFile("$FM_ROOT/bin/fm-busy-event.sh", [ + "apply", "$STATE_REAL", "$ID", state, + "--gen", "$BUSY_GEN", "--source", "prime-ext", "--event", event, + ], () => resolve()); + }); export default function (pi: any) { + pi.on("agent_start", () => busyEvent("busy", "agent-start")); + pi.on("agent_end", () => busyEvent("idle", "agent-end")); pi.on("turn_end", () => execFile("touch", ["$TURNEND"])); } EOF diff --git a/tests/fm-busy-adapter-wiring.test.sh b/tests/fm-busy-adapter-wiring.test.sh index c8967b4256d..9dd29bd496a 100755 --- a/tests/fm-busy-adapter-wiring.test.sh +++ b/tests/fm-busy-adapter-wiring.test.sh @@ -23,7 +23,7 @@ make_spawn_case() { # home="$case_dir/home" proj="$case_dir/project" wt="$case_dir/wt" - fakebin=$(make_spawn_fakebin "$case_dir/fake" pi opencode claude codex gemini) + fakebin=$(make_spawn_fakebin "$case_dir/fake" pi prime-agent opencode claude codex gemini) fm_test_spawn_home "$home" "$harness" fm_git_worktree "$proj" "$wt" "wt-$name" fm_test_spawn_brief "$home" "$id" @@ -179,6 +179,57 @@ oc_idle() { # printf '{"type":"session.idle","properties":{"sessionID":"%s"}}' "$1" } +drive_prime_ext() { + EXT_PATH="$1" MODE="$2" node --input-type=module 2>&1 <<'EOF' +import { pathToFileURL } from "node:url"; +const mod = await import(pathToFileURL(process.env.EXT_PATH).href); +const handlers = {}; +mod.default({ on: (name, fn) => { handlers[name] = fn; } }); +switch (process.env.MODE) { + case "agent-start": await handlers["agent_start"]({}, {}); break; + case "agent-end": await handlers["agent_end"]({}, {}); break; + case "turn-end": await handlers["turn_end"]({}, {}); break; + default: throw new Error("unknown mode " + process.env.MODE); +} +if (process.env.MODE === "turn-end") await new Promise((resolve) => setTimeout(resolve, 200)); +EOF +} + +test_prime_agent_extension_semantic_lifecycle() { + local rec id=busy-prime-1 out state ext + rec=$(make_spawn_case prime-lifecycle prime-agent "$id") + read_case_record "$rec" + out=$(run_spawn "$HOME_DIR" "$WT_DIR" "$FAKEBIN_DIR" "$id" "$PROJ_DIR") + expect_code 0 $? "prime-agent spawn should succeed: $out" + state="$HOME_DIR/state" + ext="$state/$id.prime-ext.ts" + assert_present "$ext" "prime-agent spawn did not write the per-task extension" + + out=$(classify prime-agent "$id" "$state") + [ "$out" = "busy fm-spawn" ] || fail "prime-agent spawn seed must be busy fm-spawn, got '$out'" + + rm -f "$state/$id.turn-ended" + out=$(drive_prime_ext "$ext" turn-end) || fail "prime-agent turn-end drive failed: $out" + [ -f "$state/$id.turn-ended" ] || fail "prime-agent turn_end no longer touches the notification marker" + out=$(classify prime-agent "$id" "$state") + [ "$out" = "busy fm-spawn" ] || fail "prime-agent turn_end must stay a notification, got '$out'" + + out=$(drive_prime_ext "$ext" agent-start) || fail "prime-agent agent_start drive failed: $out" + out=$(classify prime-agent "$id" "$state") + [ "$out" = "busy prime-ext" ] || fail "prime-agent agent_start must classify busy prime-ext, got '$out'" + + out=$(drive_prime_ext "$ext" agent-end) || fail "prime-agent agent_end drive failed: $out" + out=$(classify prime-agent "$id" "$state") + [ "$out" = "idle prime-ext" ] || fail "prime-agent agent_end must classify idle prime-ext, got '$out'" + + out=$(drive_prime_ext "$ext" agent-start) || fail "prime-agent second agent_start drive failed: $out" + "$ROOT/bin/fm-busy-event.sh" arm "$state" "$id" >/dev/null + out=$(drive_prime_ext "$ext" agent-end) || fail "prime-agent stale agent_end drive failed: $out" + out=$(classify prime-agent "$id" "$state") + [ "$out" = "busy fm-spawn" ] || fail "a stale prime-agent extension event must not change state, got '$out'" + pass "prime-agent extension reports agent_start busy, agent_end idle, and turn_end as notification" +} + test_opencode_plugin_semantic_lifecycle() { local rec id=busy-oc-1 out state plugin rec=$(make_spawn_case oc-lifecycle opencode "$id") @@ -426,6 +477,7 @@ test_pi_extension_semantic_lifecycle test_pi_extension_serializes_settle_before_next_start test_pi_extension_stale_incarnation_rejected test_kimi_and_grok_install_no_unverified_wiring +test_prime_agent_extension_semantic_lifecycle test_opencode_plugin_semantic_lifecycle test_claude_hooks_semantic_lifecycle test_claude_hooks_stale_incarnation_harmless From bfebf4362e2c2c8c5aa808fdcbc9a921cb53c562 Mon Sep 17 00:00:00 2001 From: Eduard Ionel STAN Date: Mon, 14 Sep 2026 16:19:35 +0200 Subject: [PATCH 03/15] fix: route prime-agent quota by provider --- bin/fm-quota-choose.sh | 20 +++++++++++++++++--- tests/fm-quota-choose.test.sh | 10 ++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/bin/fm-quota-choose.sh b/bin/fm-quota-choose.sh index 5c80efffb50..dde15442e28 100755 --- a/bin/fm-quota-choose.sh +++ b/bin/fm-quota-choose.sh @@ -40,6 +40,10 @@ # claude-bridge/ checks the claude row, each against the bare for # model: and product: scopes. Any other or absent prefix is refused up front, # the same shape as an unknown harness, because no quota-axi row measures it. +# Prime Agent records the launch provider separately from its model; the +# candidate's provider-qualified model preserves that identity here, so +# openai-codex/ checks codex and claude-bridge/ checks claude. A bare +# Prime Agent model remains the Pi-family form used only by Pi-provider tasks. # quota-axi reports Codex quota unavailable on this host because omp carries # its own Codex login, so an openai-codex candidate reads as unknown quota here # and is never selected on this host; its runway is disclosed uncertainty for @@ -309,7 +313,8 @@ fi printf '%s\n' "$QUOTA_JSON" | fm_quota_json_valid || die "invalid quota-axi provider data" # provider_for_harness [] -# Map a firstmate harness name to its primary quota-axi provider family. +# Map a firstmate harness name and its provider-qualified model to a quota-axi +# provider family. # Multi-provider harnesses (Pi, OpenCode) map to their primary family only; see # the header limitation note. omp is keyed on the candidate model prefix instead # and has no family for any other prefix (see the header). Authoritative @@ -327,7 +332,14 @@ provider_for_harness() { claude) printf 'claude\n' ;; codex) printf 'codex\n' ;; opencode) printf 'codex\n' ;; - pi|pi-signed|prime-agent) printf 'pi\n' ;; + pi|pi-signed) printf 'pi\n' ;; + prime-agent) + case "${2:-}" in + openai-codex/*) printf 'codex\n' ;; + claude-bridge/*) printf 'claude\n' ;; + *) printf 'pi\n' ;; + esac + ;; grok) printf 'grok\n' ;; kimi) printf 'kimi\n' ;; cursor) printf 'cursor\n' ;; @@ -384,7 +396,9 @@ for c in "${CANDIDATES[@]}"; do [ "$model" = "$c" ] && model="default" provider=$(provider_for_harness "$harness" "$model") scope_model=$model - [ "$harness" != omp ] || scope_model=${model#*/} + case "$harness" in + omp|prime-agent) scope_model=${model#*/} ;; + esac effective=$(effective_for_provider_model "$provider" "$scope_model") if [ -z "$effective" ] || [ "$effective" = "null" ]; then continue diff --git a/tests/fm-quota-choose.test.sh b/tests/fm-quota-choose.test.sh index 88ae72fbdbb..2e2aba11dd1 100755 --- a/tests/fm-quota-choose.test.sh +++ b/tests/fm-quota-choose.test.sh @@ -223,6 +223,16 @@ out=$(call_choose --snapshot "$LAB/captured.json" --candidate omp:openai-codex/c [ "$out" = "omp openai-codex/codex_other" ] || fail "omp prefix: expected the provider-wide codex quota to select the prefixed model, got '$out'" ok "omp openai-codex prefix matches the bare codex model scope" +if out=$(call_choose --snapshot "$LAB/captured.json" --candidate prime-agent:openai-codex/codex_bengalfox 2>/dev/null); then + fail "prime-agent openai-codex provider ignored the exhausted codex model scope" +fi +[ "$out" = "none" ] || fail "prime-agent openai-codex provider returned: $out" +out=$(call_choose --snapshot "$LAB/captured.json" --candidate prime-agent:openai-codex/codex_other) +[ "$out" = "prime-agent openai-codex/codex_other" ] || fail "prime-agent openai-codex provider mapped to the wrong quota family: $out" +out=$(call_choose --snapshot "$LAB/captured.json" --candidate prime-agent:pi-model) +[ "$out" = "prime-agent pi-model" ] || fail "bare prime-agent model did not retain the Pi provider family: $out" +ok "prime-agent quota follows its provider-qualified launch model" + if err=$(call_choose --snapshot "$LAB/captured.json" --candidate omp:ollama/qwen3:8b --candidate claude:claude-3-5-sonnet 2>&1); then fail "unmapped omp prefix unexpectedly selected a later candidate" fi From 2dfc82e3b46b57f9d6b4025b9fd61ecbb2b83318 Mon Sep 17 00:00:00 2001 From: Eduard Ionel STAN Date: Mon, 14 Sep 2026 16:27:40 +0200 Subject: [PATCH 04/15] feat: enable prime-agent local secondmates --- .agents/skills/harness-adapters/SKILL.md | 5 ++--- AGENTS.md | 2 +- bin/fm-control-lib.sh | 9 ++++---- bin/fm-spawn.sh | 13 ++++++----- docs/configuration.md | 4 ++-- docs/trace-context.md | 2 +- docs/verification/supervision.md | 4 ++-- tests/fm-control.test.sh | 5 +++-- tests/fm-prime-agent-harness.test.sh | 4 +--- tests/fm-spawn-dispatch-profile.test.sh | 28 +++++++++++++----------- 10 files changed, 40 insertions(+), 36 deletions(-) diff --git a/.agents/skills/harness-adapters/SKILL.md b/.agents/skills/harness-adapters/SKILL.md index 071347e8b9b..2d8dff6784b 100644 --- a/.agents/skills/harness-adapters/SKILL.md +++ b/.agents/skills/harness-adapters/SKILL.md @@ -35,14 +35,14 @@ For recovery and control, use the exact `harness=` in `state/.meta`; never i Deliver lifecycle actions only through `../../../bin/fm-control.sh interrupt|exit|relaunch`. Never type an interrupt key or exit command through `fm-send`, where routing-marked lifecycle text becomes chat. Trust handling is complete only when inspection proves the target started processing its instructions; delivery success alone is not proof. -Muse, Gemini, Prime Agent, and AGY are verified only for crewmate and scout work, never a secondmate or primary. +Muse, Gemini, and AGY are verified only for crewmate and scout work, never a secondmate or primary. Prime Agent is additionally verified for local secondmate work through its primary supervision protocol. ## Detection `../../../bin/fm-harness.sh` prints firstmate's own harness from verified environment markers and process ancestry, and owns how they combine. A marker names its harness, but a structural ancestor of a different harness outranks it, because a marker is ordinary environment state a child or a multiplexer can retain while ancestry is what proves who owns the process tree. Only `FM_PI_HARNESS=pi-signed` at the launch boundary together with `PI_CODING_AGENT=true` selects Pi-signed; shared unmarked launcher ancestry remains Pi. -Prime Agent and Pi share `PI_CODING_AGENT=true`, so only the launch marker `FM_PI_HARNESS=prime-agent`, established by `../../../bin/fm-spawn.sh` at the prime-agent launch boundary, selects Prime Agent, checked before the `CLAUDECODE` fast path and the unmarked Pi result and after the cursor, gemini, rovo, and omp marker arms; Prime Agent's own session-wide `PRIME_AGENT_*` values are not detection evidence, so an unmarked Prime Agent session stays Pi-family until the supervision slices land. +Prime Agent and Pi share `PI_CODING_AGENT=true`, so only the launch marker `FM_PI_HARNESS=prime-agent`, established by `../../../bin/fm-spawn.sh` at the prime-agent launch boundary, selects Prime Agent, checked before the `CLAUDECODE` fast path and the unmarked Pi result and after the cursor, gemini, rovo, and omp marker arms; Prime Agent's own session-wide `PRIME_AGENT_*` values are not detection evidence, so an unmarked Prime Agent session stays Pi-family by design. The marker is accepted only with the Pi-family marker, and when `CLAUDECODE=1` is present too it acts as a precedence override rather than evidence, like `FM_OMP_HARNESS=omp`: the verdict is prime-agent only when a real `prime-agent` process is in the ancestry, and a claude pane started by hand inside a Prime Agent session stays claude. omp publishes no marker of its own; `FM_OMP_HARNESS=omp` is Firstmate's launch marker and the anchored process name `omp` is its ancestry evidence, as `references/harness/omp.md` records. `../../../bin/fm-spawn.sh` owns worker marker establishment, while the README launch command owns the signed-primary boundary. @@ -91,7 +91,6 @@ A new tool remains undispatchable until the `verify` plan, its harness entry, ev "pi": "references/harness/pi.md", "pi-signed": "references/harness/pi.md", "prime-agent": "references/harness/prime-agent.md", - "prime-agent": "references/harness/prime-agent.md", "grok": "references/harness/grok.md", "kimi": "references/harness/kimi.md", "cursor": "references/harness/cursor.md", diff --git a/AGENTS.md b/AGENTS.md index 77237de9e67..7c0bef2bfe1 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -209,7 +209,7 @@ A silent bootstrap section needs no action; for any printed actionable diagnosti ## 4. Harness and runtime dispatch Load `harness-adapters` before every spawn or recovery and before trust handling, skill invocation, interrupt, exit, resume, or adapter verification. -The verified harnesses are `claude`, `codex`, `opencode`, `pi`, `pi-signed`, `grok`, `kimi`, `cursor`, and `omp`, plus `muse`, `gemini`, `prime-agent`, `rovo`, and `agy` for crewmates and scouts only; never dispatch on an unverified adapter. +The verified harnesses are `claude`, `codex`, `opencode`, `pi`, `pi-signed`, `grok`, `kimi`, `cursor`, and `omp`, plus `muse`, `gemini`, `rovo`, and `agy` for crewmates and scouts, while `prime-agent` is also verified for local secondmates; never dispatch on an unverified adapter. If static `config/crew-harness` or `config/secondmate-harness` names an unverified adapter, report it and fall back only to a verified adapter rather than launching it. `docs/configuration.md` owns dispatch-profile and runtime-backend schemas, `bin/fm-harness.sh` owns static resolution, and `bin/fm-spawn.sh` owns launch flags and fail-closed validation. diff --git a/bin/fm-control-lib.sh b/bin/fm-control-lib.sh index 2a9e269de18..b15562d2bc0 100644 --- a/bin/fm-control-lib.sh +++ b/bin/fm-control-lib.sh @@ -99,9 +99,10 @@ fm_control_harness_family() { # esac } -# Which task kinds an adapter is verified to run. muse, gemini, rovo, prime-agent, -# and agy are crewmate/scout adapters only: none has a primary supervision protocol, -# and bin/fm-spawn.sh refuses a --secondmate launch on any of them. The control +# Which task kinds an adapter is verified to run. muse, gemini, rovo, and agy +# are crewmate/scout adapters only: none has a primary supervision protocol, and +# bin/fm-spawn.sh refuses a --secondmate launch on any of them. Prime Agent has +# a verified primary supervision protocol and supports local secondmates. The control # plane asks this BEFORE it stops anything, so an incompatible relaunch target is # refused while the current agent is still running rather than after it has # been stopped. @@ -109,7 +110,7 @@ fm_control_harness_supports_kind() { # local harness=${1-} kind=${2-} fm_control_harness_supported "$harness" || return 1 case "$harness" in - muse|gemini|rovo|prime-agent|agy) [ "$kind" != secondmate ] || return 1 ;; + muse|gemini|rovo|agy) [ "$kind" != secondmate ] || return 1 ;; esac return 0 } diff --git a/bin/fm-spawn.sh b/bin/fm-spawn.sh index f57f9874aa0..2cb7af89995 100755 --- a/bin/fm-spawn.sh +++ b/bin/fm-spawn.sh @@ -1909,11 +1909,10 @@ case "$ARG3" in ;; esac -# muse, gemini, prime-agent, and agy are verified as CREWMATE/SCOUT adapters only. A +# muse, gemini, and agy are verified as CREWMATE/SCOUT adapters only. A # secondmate is a firstmate instance, so it needs a primary supervision protocol. -# prime-agent has none yet: its crew wiring is a turn-end notification with no -# agent_settled event, so the primary supervision extensions a secondmate arms -# have nothing to bind to until that support lands. +# Prime Agent has that protocol in docs/supervision-protocols/prime-agent.md and +# its two primary extensions, with agent_end-based settle reconstruction. # gemini has none: docs/supervision-protocols/ carries no gemini wake protocol # and this task verified only crewmate-side launch, busy state, interrupt, and # exit, so a gemini secondmate is refused rather than stood up on an unverified @@ -1924,7 +1923,7 @@ esac # secondmate whose supervision cycle could never be armed. # agy has none either: it exposes no hook surface for primary supervision and # docs/supervision-protocols/ carries no agy wake protocol (agy 1.2.0). -if [ "$KIND" = secondmate ] && { [ "$HARNESS" = muse ] || [ "$HARNESS" = gemini ] || [ "$HARNESS" = prime-agent ] || [ "$HARNESS" = agy ]; }; then +if [ "$KIND" = secondmate ] && { [ "$HARNESS" = muse ] || [ "$HARNESS" = gemini ] || [ "$HARNESS" = agy ]; }; then echo "error: $HARNESS is a verified crewmate/scout adapter only and cannot run a secondmate; it has no primary supervision protocol. Select a harness verified for secondmates." >&2 exit 1 fi @@ -4273,6 +4272,8 @@ sq_piext=$(shell_quote "$STATE/$ID.pi-ext.ts") sq_primeext=$(shell_quote "$STATE/$ID.prime-ext.ts") sq_piturnend=$(shell_quote "$PROJ_ABS/.pi/extensions/fm-primary-turnend-guard.ts") sq_piwatch=$(shell_quote "$PROJ_ABS/.pi/extensions/fm-primary-pi-watch.ts") +sq_primeturnend=$(shell_quote "$PROJ_ABS/.prime/agent/extensions/fm-primary-turnend-guard.ts") +sq_primewatch=$(shell_quote "$PROJ_ABS/.prime/agent/extensions/fm-primary-prime-watch.ts") sq_ompext=$(shell_quote "$STATE/$ID.omp-ext.ts") sq_ompcfg=$(shell_quote "${OMP_WORKER_CFG:-$FM_ROOT/.omp/fm-worker-overlay.yml}") sq_opinput=$(shell_quote "$FM_ROOT/bin/fm-operational-input.sh") @@ -4299,6 +4300,8 @@ LAUNCH=${LAUNCH//__PIEXT__/$sq_piext} LAUNCH=${LAUNCH//__PRIMEEXT__/$sq_primeext} LAUNCH=${LAUNCH//__PITURNEND__/$sq_piturnend} LAUNCH=${LAUNCH//__PIWATCH__/$sq_piwatch} +LAUNCH=${LAUNCH//__PRIMETURNEND__/$sq_primeturnend} +LAUNCH=${LAUNCH//__PRIMEWATCH__/$sq_primewatch} LAUNCH=${LAUNCH//__OMPEXT__/$sq_ompext} LAUNCH=${LAUNCH//__OMPWORKERCFG__/$sq_ompcfg} LAUNCH=${LAUNCH//__OPINPUT__/$sq_opinput} diff --git a/docs/configuration.md b/docs/configuration.md index 6bb82ed549e..6cf3564e75e 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -306,7 +306,7 @@ The full cmux home label also includes a short hash of the resolved `FM_ROOT` pa ## Harness support -claude, codex, opencode, pi, pi-signed, grok, kimi, cursor, and omp are empirically verified for crewmate and secondmate launches; gemini and prime-agent are verified for crewmate and scout launches only, and [README requirements](../README.md#requirements) own the set supported for the primary session. +claude, codex, opencode, pi, pi-signed, grok, kimi, cursor, omp, and prime-agent are empirically verified for crewmate and local secondmate launches; gemini is verified for crewmate and scout launches only, and [README requirements](../README.md#requirements) own the set supported for the primary session. A cursor secondmate or primary runs the tracked project-scope `.cursor/hooks.json` in its own home and must be launched with `--trust`, or no project hook loads; [`docs/supervision-protocols/cursor.md`](supervision-protocols/cursor.md) owns its supervision protocol. Cursor typed-submit confirmation is verified on tmux and Herdr only. prime-agent runs every session in a detached daemon worker that outlives both the pane and an explicit quit, so teardown (task worktree and secondmate home alike) and every secondmate relaunch retire the worker bound to that directory first ([`bin/fm-prime-agent-lib.sh`](../bin/fm-prime-agent-lib.sh)); without that a home would keep a live session-lock holder and land read-only. @@ -321,7 +321,7 @@ muse also needs a worker-reachable credential before spawning, and the portable gemini is likewise refused for secondmates because it has no primary supervision protocol; [its adapter reference](../.agents/skills/harness-adapters/references/harness/gemini.md) owns the credential precondition, canonical-launch wiring, and raw-launch limitations. rovo is likewise verified for crewmate and scout launches ONLY, refused for a secondmate for the same reason - no turn-end hook and no primary supervision protocol; [`docs/verification/rovo.md`](verification/rovo.md) owns that evidence, including the OAuth token's silent background refresh from a stored refresh token and both tmux and herdr pane liveness (herdr placement is verified live, with a Herdr-side agent-detection gap left open for recovery classification). agy is likewise verified for crewmate and scout launches ONLY, refused for a secondmate for the same reason - no hook surface and no primary supervision protocol; [`docs/verification/agy.md`](verification/agy.md) owns that evidence, including the spawn-time worktree trust pre-registration through `bin/fm-agy-trust.sh` and Herdr's native agy pane recognition. -prime-agent is likewise verified for crewmate and scout launches ONLY, refused for a secondmate for the same reason - no primary supervision protocol yet; [its adapter reference](../.agents/skills/harness-adapters/references/harness/prime-agent.md) owns detection, launch, and control mechanics. +prime-agent is verified for crewmate, scout, and local secondmate launches; its primary supervision protocol and detached-worker lifecycle are owned by [its adapter reference](../.agents/skills/harness-adapters/references/harness/prime-agent.md). New harnesses get verified through a supervised trial task before joining the set. The verified adapter evidence - each harness's busy-state source, interrupt and exit behavior, skill-invocation syntax, and per-harness quirks - lives in the skill tree rooted at [`.agents/skills/harness-adapters/SKILL.md`](../.agents/skills/harness-adapters/SKILL.md). The executable interrupt and exit mechanics live in [`bin/fm-control-lib.sh`](../bin/fm-control-lib.sh), and [`docs/agent-control.md`](agent-control.md) owns their lifecycle-control architecture. diff --git a/docs/trace-context.md b/docs/trace-context.md index 9a95971e7c8..c51f0c0f477 100644 --- a/docs/trace-context.md +++ b/docs/trace-context.md @@ -23,7 +23,7 @@ When enabled, for each spawn Firstmate resolves one W3C `traceparent` carrier fo This feature parents no SDK span by itself. Because the injected carrier and the recorded carrier are the same string, an observer that reads the metadata reconstructs exactly the identity the child received. -The injection sits at the unconditional pre-launch export site, so it covers ship and scout spawns across `claude`, `codex`, `opencode`, `pi`, `pi-signed`, `prime-agent`, `grok`, `kimi`, `cursor`, `gemini`, `muse`, `rovo`, and `agy`, plus Secondmate spawns across that same set except the deliberately crewmate-only `gemini`, `muse`, `prime-agent`, `rovo`, and `agy` adapters. +The injection sits at the unconditional pre-launch export site, so it covers ship and scout spawns across `claude`, `codex`, `opencode`, `pi`, `pi-signed`, `prime-agent`, `grok`, `kimi`, `cursor`, `gemini`, `muse`, `rovo`, and `agy`, plus Secondmate spawns across that same set except the deliberately crewmate-only `gemini`, `muse`, `rovo`, and `agy` adapters. This is the same coverage `GOTMPDIR` already has and requires no trace-specific `launch_template()` behavior. Ship and scout spawns reach that site on every spawn backend (`tmux`, `herdr`, `zellij`, `orca`, `cmux`); a Secondmate reaches it on every backend that accepts a Secondmate spawn (`tmux`, `herdr`, `zellij`), because `bin/fm-spawn.sh` rejects a Secondmate on `orca` and `cmux`. diff --git a/docs/verification/supervision.md b/docs/verification/supervision.md index ec5193ee4cb..17710cacb44 100644 --- a/docs/verification/supervision.md +++ b/docs/verification/supervision.md @@ -552,5 +552,5 @@ The safe command-channel contract is covered without a notification by `tests/fm Prime Agent primary supervision uses the tracked `.prime/agent/extensions/fm-primary-prime-watch.ts` and `.prime/agent/extensions/fm-primary-turnend-guard.ts` extensions. The watcher extension owns continuity and the turn-end extension provides the recovery backstop. -The task worker path is verified by `tests/fm-prime-agent-harness.test.sh` and `tests/fm-prime-watch-extension.test.sh` on Linux with prime-agent 0.9.1. -The exact local validation command was `bin/fm-test-run.sh --jobs 1 tests/fm-prime-agent-harness.test.sh tests/fm-prime-watch-extension.test.sh`, which passed both scripts. +The task worker path is verified by `tests/fm-prime-agent-harness.test.sh`, `tests/fm-prime-watch-extension.test.sh`, and `docs/verification/prime-agent.md` on Linux with prime-agent 0.9.4. +The exact local validation command was `bin/fm-test-run.sh --jobs 1 tests/fm-prime-agent-harness.test.sh tests/fm-prime-watch-extension.test.sh`, which passed both scripts before the live adapter refresh. diff --git a/tests/fm-control.test.sh b/tests/fm-control.test.sh index c17a8589fd0..76c7bdd51cd 100755 --- a/tests/fm-control.test.sh +++ b/tests/fm-control.test.sh @@ -35,7 +35,7 @@ mkdir -p "$TMP_ROOT" TMP_ROOT=$(cd "$TMP_ROOT" && pwd) trap 'rm -rf "$TMP_ROOT"' EXIT -VERIFIED_HARNESSES="claude codex opencode pi pi-signed grok kimi cursor muse omp" +VERIFIED_HARNESSES="claude codex opencode pi pi-signed prime-agent grok kimi cursor muse omp" # The expectation table, written out independently of the implementation so a # silent change to either side shows up here. The fourth field is the composer @@ -48,6 +48,7 @@ verified_adapter_contract() { # -> exit command, interrupt key, repea opencode) printf '/exit\tEscape\t2\t\n' ;; pi) printf '/quit\tEscape\t1\t\n' ;; pi-signed) printf '/quit\tEscape\t1\t\n' ;; + prime-agent) printf '/quit\tEscape\t1\t\n' ;; omp) printf '/quit\tEscape\t1\t\n' ;; grok) printf '/exit\tC-c\t1\t\n' ;; kimi) printf '/exit\tEscape\t1\t\n' ;; @@ -381,7 +382,7 @@ test_harness_kind_capability() { done fm_control_harness_supports_kind muse secondmate \ && fail "muse has no primary supervision protocol and must not claim a secondmate" - for harness in claude codex opencode pi pi-signed grok kimi omp; do + for harness in claude codex opencode pi pi-signed prime-agent grok kimi omp; do fm_control_harness_supports_kind "$harness" secondmate \ || fail "$harness should be able to run a secondmate" done diff --git a/tests/fm-prime-agent-harness.test.sh b/tests/fm-prime-agent-harness.test.sh index 652bae8ec54..8151f8581f5 100755 --- a/tests/fm-prime-agent-harness.test.sh +++ b/tests/fm-prime-agent-harness.test.sh @@ -247,9 +247,7 @@ test_prime_agent_control_table() { [ "$(fm_control_exit_command prime-agent)" = /quit ] || fail "prime-agent exit command is not /quit" fm_control_harness_supports_kind prime-agent ship || fail "prime-agent should support ship tasks" fm_control_harness_supports_kind prime-agent scout || fail "prime-agent should support scout tasks" - if fm_control_harness_supports_kind prime-agent secondmate; then - fail "prime-agent should never support secondmate tasks" - fi + fm_control_harness_supports_kind prime-agent secondmate || fail "prime-agent should support local secondmate tasks" wiring=$(fm_control_harness_wiring_paths prime-agent /wt /state t1) [ "$wiring" = "/state/t1.prime-ext.ts" ] \ || fail "prime-agent wiring paths did not list its turn-end extension, got '$wiring'" diff --git a/tests/fm-spawn-dispatch-profile.test.sh b/tests/fm-spawn-dispatch-profile.test.sh index c01ce40be09..2af9ce8780e 100755 --- a/tests/fm-spawn-dispatch-profile.test.sh +++ b/tests/fm-spawn-dispatch-profile.test.sh @@ -193,23 +193,25 @@ test_prime_agent_missing_binary_refuses_before_endpoint_or_metadata() { pass "prime-agent refuses safely and actionably when the selected executable is unavailable" } -# A prime-agent secondmate has no primary supervision protocol yet, so the spawn -# must refuse by name rather than fall through to the raw-launch escape hatch. -test_prime_agent_secondmate_is_refused() { - local rec id out status +# Prime Agent has a live-verified primary supervision protocol, so a local +# secondmate launch uses its primary extensions instead of being refused. +test_prime_agent_secondmate_uses_primary_extensions() { + local rec id sm out status launch id=profile-prime-agent-sm-z1d rec=$(make_spawn_case profile-prime-agent-sm prime-agent "$id") read_case_record "$rec" + sm="$CASE_DIR/secondmate-home" + make_seeded_secondmate_home "$sm" "$id" + cp "$ROOT/AGENTS.md" "$sm/AGENTS.md" - out=$(run_spawn "$HOME_DIR" "$WT_DIR" "$FAKEBIN_DIR" "$LAUNCH_LOG" "$id" prime-agent --secondmate) + out=$(run_spawn "$HOME_DIR" "$WT_DIR" "$FAKEBIN_DIR" "$LAUNCH_LOG" "$id" "$sm" --secondmate) status=$? - [ "$status" -ne 0 ] || fail "prime-agent was accepted as a secondmate harness" - assert_contains "$out" "crewmate/scout adapter only" \ - "prime-agent secondmate refusal did not explain the boundary" - case "$out" in - *"unknown harness"*) fail "prime-agent secondmate refusal claimed the harness is unknown: $out" ;; - esac - pass "a prime-agent secondmate spawn is refused by name, not as an unknown harness" + expect_code 0 "$status" "prime-agent secondmate spawn should succeed" + assert_contains "$out" "spawned $id harness=prime-agent kind=secondmate" "prime-agent secondmate spawn did not preserve its runtime identity" + assert_meta_profile "$HOME_DIR/state/$id.meta" prime-agent default default + launch=$(cat "$LAUNCH_LOG") + assert_contains "$launch" "-e '$sm/.prime/agent/extensions/fm-primary-turnend-guard.ts' -e '$sm/.prime/agent/extensions/fm-primary-prime-watch.ts'" "prime-agent secondmate did not load both primary supervision extensions" + pass "a prime-agent secondmate launch uses its verified primary supervision extensions" } test_non_cursor_launch_clears_inherited_cursor_markers() { @@ -1457,7 +1459,7 @@ test_non_claude_harness_ignores_claude_permission_mode() { test_worker_launch_delivers_role_scope test_no_profile_keeps_claude_profile_defaults test_prime_agent_launch_establishes_its_harness_marker -test_prime_agent_secondmate_is_refused +test_prime_agent_secondmate_uses_primary_extensions test_non_cursor_launch_clears_inherited_cursor_markers test_relative_home_overrides_launch_with_absolute_cross_process_paths test_home_defaults_preserve_absolute_or_resolve_relative_paths From 9d01ef03ce78a0fe052b9757d867fc89c54f1681 Mon Sep 17 00:00:00 2001 From: Eduard Ionel STAN Date: Mon, 14 Sep 2026 16:27:55 +0200 Subject: [PATCH 05/15] chore: remove dead harness ancestry helper --- bin/fm-harness.sh | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/bin/fm-harness.sh b/bin/fm-harness.sh index 18bd624d7ae..2512fe900ad 100755 --- a/bin/fm-harness.sh +++ b/bin/fm-harness.sh @@ -445,20 +445,6 @@ detect_own() { if [ "$strength" = comm ]; then echo "$harness"; else echo "$marker"; fi } -# True when an exact `omp` process sits within eight parents of this one. The -# same anchored match as the ancestry walk in detect_own, kept separate so the -# marker precedence above can demand real process evidence. -ancestry_names_omp() { - local pid=$$ comm - for _ in 1 2 3 4 5 6 7 8; do - comm=$(ps -o comm= -p "$pid" 2>/dev/null) || return 1 - [ "$(basename -- "$comm")" = omp ] && return 0 - pid=$(ps -o ppid= -p "$pid" 2>/dev/null | tr -d ' ') - [ -n "$pid" ] && [ "$pid" -gt 1 ] || return 1 - done - return 1 -} - # Resolve the effective crewmate harness: config/crew-harness (a bare adapter # name) wins; absent or "default" mirrors firstmate's own harness. resolve_crew() { From 4af2d156162444d24b6e861b6dfbdfbfaf0e25f9 Mon Sep 17 00:00:00 2001 From: Eduard Ionel STAN Date: Mon, 14 Sep 2026 16:34:13 +0200 Subject: [PATCH 06/15] docs: refresh prime-agent adapter reference --- .../references/harness/prime-agent.md | 67 ++++--- tests/fm-prime-agent-signals-live-e2e.test.sh | 180 ++++++++++++++++++ 2 files changed, 221 insertions(+), 26 deletions(-) create mode 100755 tests/fm-prime-agent-signals-live-e2e.test.sh diff --git a/.agents/skills/harness-adapters/references/harness/prime-agent.md b/.agents/skills/harness-adapters/references/harness/prime-agent.md index 4bef15f89bf..89c56aa7454 100644 --- a/.agents/skills/harness-adapters/references/harness/prime-agent.md +++ b/.agents/skills/harness-adapters/references/harness/prime-agent.md @@ -1,32 +1,47 @@ # Prime Agent -This slice registers Prime Agent as a distinct Pi-family harness and covers detection, crewmate/scout launch, and control mechanics. -Herdr pane classification and detached-daemon-session retirement land in the following adapter slices; primary supervision does too, so a secondmate launch is refused here. +This reference covers Prime Agent detection, crewmate/scout and local secondmate launch, semantic busy state, and control mechanics. +The active empirical record is [`docs/verification/prime-agent.md`](../../../../../docs/verification/prime-agent.md). +Remote secondmates remain outside the verified boundary. ## Detection Prime Agent exports `PI_CODING_AGENT=true`, the same Pi-family marker used by Pi and Pi-signed. -The launch-boundary marker `FM_PI_HARNESS=prime-agent` is what disambiguates it when paired with the Pi-family marker, the same Firstmate-owned mechanism `FM_PI_HARNESS=pi-signed` uses for the signed wrapper. -Prime Agent's own `PRIME_AGENT_CODING_AGENT_DIR` and `PRIME_AGENT_INTERNAL_DAEMON_WORKER=1` are session-wide inherited values and are deliberately not detection evidence: an unmarked Prime Agent session stays Pi-family. -`../../../bin/fm-harness.sh` checks the Prime Agent marker before `CLAUDECODE` and the unmarked Pi result, and after the cursor, gemini, rovo, and omp marker arms. -Those four therefore keep their identity when one of them is started by hand inside a Prime Agent session. -grok is deliberately not among them: `GROK_AGENT=1` is already tested after the unmarked Pi result, so a grok session started inside any Pi-family session has always resolved to that family, and reordering it belongs outside this slice. -An explicit `FM_PI_HARNESS=pi` or `FM_PI_HARNESS=pi-signed` is therefore what a Pi or Pi-signed session carries, and neither is ever relabelled. -The marker without `PI_CODING_AGENT=true` is ignored, so it cannot relabel a Claude or unrelated process. -The marker can itself leak into a Claude pane of the same session, so when `CLAUDECODE=1` is present it is a precedence override rather than evidence, the same boundary `FM_OMP_HARNESS=omp` uses: the verdict is `prime-agent` only when a `prime-agent` process sits within eight parents, and otherwise falls through to `claude`. -With `CLAUDECODE` absent the marker stands alone and no ancestry is required. -Prime Agent does not clear the foreign markers it inherits either, so a prime-agent launch clears `CLAUDECODE` and `GROK_AGENT` in its own template and rides the shared launch prefix that clears `CURSOR_AGENT`, `CURSOR_INVOKED_AS`, and `GEMINI_CLI`, which is what keeps a prime-agent worker started under a cursor or gemini primary from resolving as that primary. - -Detection was verified against Prime Agent 0.9.1 on Linux, with earlier checks against 0.7.1 and 0.7.2. - -## Launch and control - -`../../../bin/fm-spawn.sh` launches a prime-agent crewmate or scout on the same single-positional brief and `-e` extension shape as Pi, establishing `FM_PI_HARNESS=prime-agent` so the worker identifies itself, passing `--model` and `--thinking`, and writing the turn-end notification extension to `state/.prime-ext.ts` outside the worktree. -`../../../bin/fm-teardown.sh` removes that extension with the rest of a task's wiring, and `fm_control_harness_wiring_paths` lists it so a relaunch onto another harness retires it. -Control mechanics are Pi's, verified on Prime Agent 0.9.1: a single `Escape` cancels a turn, the composer is left empty afterwards so no clear key is needed, and `/quit` exits. -`../../../bin/fm-spawn.sh --help` owns the executable-preflight mechanics: a missing `prime-agent` executable on PATH refuses before endpoint or metadata creation. - -## Scope of this slice - -Detection keys on the explicit `FM_PI_HARNESS=prime-agent` launch marker only, so a firstmate-launched worker identifies itself while a Prime Agent PRIMARY still resolves as Pi-family exactly as it did before. -Ambient auto-detection of that primary, and a prime-agent secondmate, arrive with the supervision slices that give the value a supervision model, a supervision snippet, and the primary supervision extensions; a secondmate spawn is refused here rather than launched unsupervised. +The launch-boundary marker `FM_PI_HARNESS=prime-agent` disambiguates it when paired with the Pi-family marker. +Prime Agent's own `PRIME_AGENT_CODING_AGENT_DIR` and `PRIME_AGENT_INTERNAL_DAEMON_WORKER=1` are inherited session values, not detection evidence. +`../../../bin/fm-harness.sh` checks the Prime Agent marker before `CLAUDECODE` and the unmarked Pi result and after the cursor, gemini, rovo, and omp marker arms. +Those four keep their identity when started by hand inside a Prime Agent session. +With `CLAUDECODE=1`, the marker selects Prime Agent only when a real `prime-agent` process sits within eight parents. +Without `CLAUDECODE`, the marker is sufficient once the Pi-family marker is present. +A marker without `PI_CODING_AGENT=true` is ignored. +The Prime Agent launch clears `CLAUDECODE` and `GROK_AGENT` and uses the shared launch prefix to clear cursor and Gemini markers. +An unmarked Prime Agent session remains Pi-family by design. +Detection and launch markers were verified live against Prime Agent 0.9.4. + +## Launch and busy state + +`../../../bin/fm-spawn.sh` launches a Prime Agent crewmate or scout with one encoded brief, `--provider`, `--model`, `--thinking`, and `-e state/.prime-ext.ts`. +The generated extension writes the semantic busy record on `agent_start`, clears it on `agent_end`, and touches the turn-end notification marker on `turn_end`. +Prime Agent 0.9.4 has no `agent_settled` event, so `agent_end` is the adapter's logical prompt boundary. +`bin/fm-busy-lib.sh` trusts the generated `prime-ext` source only for a recorded Prime Agent task. +The extension is written outside the project and is removed by cleanup and harness relaunch wiring. +A local secondmate launch loads `.prime/agent/extensions/fm-primary-turnend-guard.ts` and `.prime/agent/extensions/fm-primary-prime-watch.ts` from its own home. +The primary protocol is [`docs/supervision-protocols/prime-agent.md`](../../../../../docs/supervision-protocols/prime-agent.md). +The local secondmate launch and both primary extension paths were verified in the isolated Herdr trial. + +## Control + +Prime Agent uses the Pi-family control table. +A single `Escape` interrupts a running turn and leaves the composer empty without a clear key. +`/quit` exits the Prime Agent process and leaves the detached daemon worker for directory-bound retirement. +Relaunch starts a fresh Prime Agent client in the same pane and directory rather than claiming an unverified pane-resume contract. +Prime Agent 0.9.4 control behavior was verified live in Herdr. +`../../../bin/fm-spawn.sh --help` owns executable preflight and rejects a missing `prime-agent` before task publication. +`../../../bin/fm-prime-agent-lib.sh` owns detached-worker listing and retirement for cleanup and secondmate relaunch. + +## Scope + +Prime Agent is verified for crewmate, scout, and local secondmate work. +Remote secondmates remain refused because remote readiness has no Prime Agent verification. +The primary-session protocol is tracked and its extension behavior is covered by the Prime Agent supervision tests. +Prime Agent's native RPC, RLM, and agent-messaging features are not Firstmate control-plane replacements. diff --git a/tests/fm-prime-agent-signals-live-e2e.test.sh b/tests/fm-prime-agent-signals-live-e2e.test.sh new file mode 100755 index 00000000000..133ed7035eb --- /dev/null +++ b/tests/fm-prime-agent-signals-live-e2e.test.sh @@ -0,0 +1,180 @@ +#!/usr/bin/env bash +# Opt-in live Prime Agent 0.9.4 adapter regression in an isolated Herdr lab. +# It drives the production spawn-generated extension against a real Prime Agent +# process and never touches the shared default Herdr session or daemon. +set -u + +# shellcheck source=tests/lib.sh +. "$(dirname "${BASH_SOURCE[0]}")/lib.sh" + +fm_live_gate opt-in FM_PRIME_AGENT_LIVE_E2E prime-agent herdr jq + +LAB_HELPER=${HERDR_LAB_HELPER:-/home/eduard/Dropbox/Projects/firstmate/bin/fm-herdr-lab.sh} +[ -x "$LAB_HELPER" ] || fail "FM_PRIME_AGENT_LIVE_E2E=1 but the Herdr lab helper is not executable: $LAB_HELPER" + +# shellcheck source=tests/herdr-test-safety.sh +. "$ROOT/tests/herdr-test-safety.sh" +herdr_forget_inherited_pane +# shellcheck source=tests/fixtures.sh +. "$ROOT/tests/fixtures.sh" +# shellcheck source=bin/fm-busy-lib.sh +. "$ROOT/bin/fm-busy-lib.sh" +# shellcheck source=bin/fm-prime-agent-lib.sh +. "$ROOT/bin/fm-prime-agent-lib.sh" + +LAB=$(mktemp -d "${TMPDIR:-/tmp}/fm-prime-agent-live.XXXXXX") +PRIMARY_PROJECT="$LAB/primary-project" +PRIMARY_HOME="$LAB/primary-home" +HOME_DIR="$LAB/home" +PROJECT="$LAB/project" +WT="$LAB/worktree" +ID=prime-agent-live +FAKEBIN= +LAUNCH_LOG="$LAB/launch.log" +SESSION=$("$LAB_HELPER" name prime-adapter-solid) +PANE= +PRIMARY_PANE= + +fail() { printf 'not ok - %s\n' "$1" >&2; exit 1; } +pass() { printf 'ok - %s\n' "$1"; } +cleanup() { + local rc=$? + trap - EXIT + if [ -n "$PANE" ]; then + "$LAB_HELPER" run "$SESSION" pane send-keys "$PANE" escape >/dev/null 2>&1 || true + "$LAB_HELPER" run "$SESSION" pane send-text "$PANE" '/quit' >/dev/null 2>&1 || true + "$LAB_HELPER" run "$SESSION" pane send-keys "$PANE" enter >/dev/null 2>&1 || true + fi + fm_prime_agent_stop_sessions_under "$WT" >/dev/null 2>&1 || true + "$LAB_HELPER" teardown "$SESSION" >/dev/null 2>&1 || rc=1 + rm -rf "$LAB" + exit "$rc" +} +trap cleanup EXIT + +fm_test_spawn_home "$HOME_DIR" prime-agent +fm_git_worktree "$PROJECT" "$WT" "wt-prime-agent-live" +fm_test_spawn_brief "$HOME_DIR" "$ID" 'Run the requested live adapter checks and reply with PRIME_AGENT_BOOT_OK.' +FAKEBIN=$(make_spawn_fakebin "$LAB/fake" prime-agent) +# Fake tmux lets production fm-spawn render the exact extension and busy record. +# The real process is launched below in the isolated Herdr pane instead. +out=$(FM_FAKE_LAUNCH_LOG="$LAUNCH_LOG" fm_test_run_spawn "$HOME_DIR" "$WT" "$FAKEBIN" "$ID" "$PROJECT" \ + --harness prime-agent --provider openai-codex --model gpt-5.6-terra --effort low \ + --mode direct-PR --yolo off 2>&1) || fail "production spawn generation failed: $out" +[ -f "$HOME_DIR/state/$ID.prime-ext.ts" ] || fail "production spawn did not generate the Prime Agent extension" +LAUNCH=$(sed "s#'$FAKEBIN/prime-agent'#'/home/eduard/.local/bin/prime-agent'#" "$LAUNCH_LOG") +[ "$LAUNCH" != "$(cat "$LAUNCH_LOG")" ] || fail "could not replace the fake Prime Agent executable in the generated launch" + +"$LAB_HELPER" provision "$SESSION" || fail "could not provision isolated Herdr lab" +WS=$("$LAB_HELPER" run "$SESSION" workspace create --cwd "$WT" --label prime-agent-live --no-focus) \ + || fail "could not create isolated Herdr workspace" +PANE=$(printf '%s' "$WS" | jq -er '.result.root_pane.pane_id') \ + || fail "workspace create did not return a pane id" +"$LAB_HELPER" run "$SESSION" pane run "$PANE" "$LAUNCH" >/dev/null \ + || fail "could not launch the generated Prime Agent command" + +for i in $(seq 1 120); do + screen=$("$LAB_HELPER" run "$SESSION" pane read "$PANE" --source recent --lines 200 2>/dev/null || true) + if printf '%s\n' "$screen" | grep -q 'version v0.9.4' \ + && printf '%s\n' "$screen" | grep -q 'GPT-5.6 Terra'; then + break + fi + sleep 0.5 +done +printf '%s\n' "$screen" | grep -q 'version v0.9.4' || fail "Prime Agent 0.9.4 did not render its startup screen" +case "$screen" in + *"GPT-5.6 Terra"*"low"*) : ;; + *) fail "generated launch did not render the selected model and thinking level; launch=$LAUNCH screen=$screen" ;; +esac +pass "Prime Agent 0.9.4 rendered the production model/provider/thinking launch" + +for i in $(seq 1 120); do + [ "$(fm_busy_classify tmux fake:w prime-agent "$ID" "$HOME_DIR/state")" = "idle prime-ext" ] && break + sleep 0.5 +done +[ "$(fm_busy_classify tmux fake:w prime-agent "$ID" "$HOME_DIR/state")" = "idle prime-ext" ] \ + || fail "generated Prime Agent extension did not settle the launch turn" +[ -f "$HOME_DIR/state/$ID.turn-ended" ] || fail "generated Prime Agent extension did not write turn-end notification" +pass "Prime Agent 0.9.4 loaded the production extension and settled its first turn" + +send() { + "$LAB_HELPER" run "$SESSION" pane send-text "$PANE" "$1" >/dev/null || return 1 + "$LAB_HELPER" run "$SESSION" pane send-keys "$PANE" enter >/dev/null || return 1 +} +wait_busy() { + local i + for i in $(seq 1 80); do + [ "$(fm_busy_classify tmux fake:w prime-agent "$ID" "$HOME_DIR/state")" = "busy prime-ext" ] && return 0 + sleep 0.5 + done + return 1 +} +wait_idle() { + local i + for i in $(seq 1 100); do + [ "$(fm_busy_classify tmux fake:w prime-agent "$ID" "$HOME_DIR/state")" = "idle prime-ext" ] && return 0 + sleep 0.5 + done + return 1 +} +send 'Run the shell command sleep 12, then reply with exactly PRIME_AGENT_SLEEP_OK.' || fail "could not submit the busy probe" +wait_busy || fail "generated Prime Agent extension did not report busy during a real tool call" +agent_busy=$("$LAB_HELPER" run "$SESSION" agent get "$PANE") +printf '%s\n' "$agent_busy" | jq -e '.result.agent.agent_status == "working"' >/dev/null \ + || fail "Herdr did not report working during the real busy probe: $agent_busy" +wait_idle || fail "generated Prime Agent extension did not report idle after the real tool call" +pass "Prime Agent 0.9.4 agent_start/agent_end wiring reports busy and idle" + +send 'Run the shell command sleep 20, then reply with exactly PRIME_AGENT_CANCELLED_NO.' || fail "could not submit interrupt probe" +wait_busy || fail "interrupt probe never became busy" +"$LAB_HELPER" run "$SESSION" pane send-keys "$PANE" escape >/dev/null || fail "could not send Escape" +wait_idle || fail "Prime Agent did not settle after Escape" +screen=$("$LAB_HELPER" run "$SESSION" pane read "$PANE" --source recent --lines 200) +printf '%s\n' "$screen" | grep -q 'Operation aborted' || fail "Escape did not abort the Prime Agent turn: $screen" +pass "Prime Agent 0.9.4 cancels a running turn with one Escape" + +send '/quit' || fail "could not submit /quit" +for i in $(seq 1 60); do + info=$("$LAB_HELPER" run "$SESSION" pane process-info --pane "$PANE" 2>/dev/null || true) + printf '%s\n' "$info" | jq -e '.result.process_info.foreground_processes[0].name == "bash"' >/dev/null 2>&1 && break + sleep 0.5 +done +printf '%s\n' "$info" | jq -e '.result.process_info.foreground_processes[0].name == "bash"' >/dev/null \ + || fail "Prime Agent /quit did not return the pane to bash" +pass "Prime Agent 0.9.4 exits cleanly and leaves the detached worker for retirement" + +"$LAB_HELPER" run "$SESSION" pane run "$PANE" "$LAUNCH" >/dev/null \ + || fail "could not relaunch Prime Agent in the same pane" +for i in $(seq 1 120); do + screen=$("$LAB_HELPER" run "$SESSION" pane read "$PANE" --source recent --lines 200 2>/dev/null || true) + printf '%s\n' "$screen" | grep -q 'version v0.9.4' && break + sleep 0.5 +done +printf '%s\n' "$screen" | grep -q 'version v0.9.4' || fail "Prime Agent did not relaunch in the same pane" +pass "Prime Agent 0.9.4 relaunches in the same Herdr pane" + +# A secondmate is itself a firstmate primary, so verify the two tracked primary +# extensions load in an isolated secondmate-shaped home before enabling it. +mkdir -p "$PRIMARY_PROJECT" "$PRIMARY_HOME/state" "$PRIMARY_HOME/config" "$PRIMARY_HOME/data" "$PRIMARY_HOME/projects" +cp -a "$ROOT/.prime" "$ROOT/.pi" "$ROOT/bin" "$ROOT/AGENTS.md" "$PRIMARY_PROJECT/" +printf '%s\n' "$$" > "$PRIMARY_HOME/state/.lock" +PRIMARY_WS=$("$LAB_HELPER" run "$SESSION" workspace create --cwd "$PRIMARY_PROJECT" --label prime-secondmate-live --no-focus) \ + || fail "could not create isolated secondmate-shaped Herdr workspace" +PRIMARY_PANE=$(printf '%s' "$PRIMARY_WS" | jq -er '.result.root_pane.pane_id') \ + || fail "secondmate-shaped workspace did not return a pane id" +PRIMARY_CMD="FM_HOME='$PRIMARY_HOME' FM_ROOT_OVERRIDE='$PRIMARY_PROJECT' FM_STATE_OVERRIDE='$PRIMARY_HOME/state' FM_DATA_OVERRIDE='$PRIMARY_HOME/data' FM_CONFIG_OVERRIDE='$PRIMARY_HOME/config' bash -lc 'printf %s \"\$\$\" > \"$PRIMARY_HOME/state/.lock\"; exec env -u CLAUDECODE -u GROK_AGENT -u PI_CODING_AGENT -u FM_PI_HARNESS prime-agent --model gpt-5.6-terra --provider openai-codex --thinking low -e \"$PRIMARY_PROJECT/.prime/agent/extensions/fm-primary-turnend-guard.ts\" -e \"$PRIMARY_PROJECT/.prime/agent/extensions/fm-primary-prime-watch.ts\"'" +"$LAB_HELPER" run "$SESSION" pane run "$PRIMARY_PANE" "$PRIMARY_CMD" >/dev/null \ + || fail "could not launch the secondmate-shaped Prime Agent primary" +for i in $(seq 1 100); do + [ -f "$PRIMARY_HOME/state/.prime-turnend-extension-loaded" ] \ + && [ -f "$PRIMARY_HOME/state/.prime-watch-extension-loaded" ] && break + sleep 0.5 +done +[ -f "$PRIMARY_HOME/state/.prime-turnend-extension-loaded" ] \ + || fail "Prime Agent primary turn-end extension did not load in the secondmate-shaped home" +[ -f "$PRIMARY_HOME/state/.prime-watch-extension-loaded" ] \ + || fail "Prime Agent primary watcher extension did not load in the secondmate-shaped home" +pass "Prime Agent 0.9.4 loads both primary supervision extensions for a local secondmate" +"$LAB_HELPER" run "$SESSION" pane send-text "$PRIMARY_PANE" '/quit' >/dev/null || true +"$LAB_HELPER" run "$SESSION" pane send-keys "$PRIMARY_PANE" enter >/dev/null || true +fm_prime_agent_stop_sessions_under "$PRIMARY_PROJECT" >/dev/null 2>&1 || true From c94e4f47c959925cb567bb52bc5f7ad96e3fd855 Mon Sep 17 00:00:00 2001 From: Eduard Ionel STAN Date: Mon, 14 Sep 2026 16:42:55 +0200 Subject: [PATCH 07/15] docs: point runtime verification to prime-agent evidence --- docs/verification/runtime-backends.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/verification/runtime-backends.md b/docs/verification/runtime-backends.md index 9ace00a2683..68a4edb89d4 100644 --- a/docs/verification/runtime-backends.md +++ b/docs/verification/runtime-backends.md @@ -1906,9 +1906,12 @@ A throwaway scout was spawned through `bin/fm-spawn.sh --scout --harness omp --m ## Prime Agent (prime-agent) -The Prime Agent adapter was verified on 2026-09-13 with prime-agent 0.9.1 on Linux x86_64. +The Prime Agent adapter was verified on 2026-09-14 with prime-agent 0.9.4 on Linux x86_64. The shared process classifier recognizes the exact `prime-agent` executable and rejects similarly named helpers. Firstmate launch resolves the concrete executable path, sets `FM_PI_HARNESS=prime-agent`, clears inherited foreign markers, and loads the task extension. The launch path preserves provider, model, effort, and autonomous-gate options. -`tests/fm-prime-agent-harness.test.sh`, `tests/fm-prime-watch-extension.test.sh`, and `tests/fm-spawn-dispatch-profile.test.sh` are the deterministic verification entry points. -The primary extension and control behavior are additionally covered by `tests/fm-control-relaunch.test.sh`, `tests/fm-crew-state.test.sh`, and `tests/fm-teardown-endpoint-safety.test.sh`. +The generated task extension reports semantic busy and idle state through `agent_start` and `agent_end` and keeps `turn_end` as a notification. +Prime Agent is verified for local secondmate launches because its two primary supervision extensions load in the secondmate-shaped home. +The complete dated command transcript is [`docs/verification/prime-agent.md`](prime-agent.md). +`tests/fm-prime-agent-harness.test.sh`, `tests/fm-prime-watch-extension.test.sh`, `tests/fm-busy-adapter-wiring.test.sh`, and `tests/fm-spawn-dispatch-profile.test.sh` are the deterministic verification entry points. +`FM_PRIME_AGENT_LIVE_E2E=1 bin/fm-test-run.sh tests/fm-prime-agent-signals-live-e2e.test.sh` refreshes the real Prime Agent and Herdr evidence. From 24f6b8fd27ddca3db6dd442521bb76af6757e138 Mon Sep 17 00:00:00 2001 From: Eduard Ionel STAN Date: Mon, 14 Sep 2026 16:44:21 +0200 Subject: [PATCH 08/15] docs: remove stale prime-agent validation wording --- docs/verification/supervision.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/verification/supervision.md b/docs/verification/supervision.md index 17710cacb44..ee758a0dd3f 100644 --- a/docs/verification/supervision.md +++ b/docs/verification/supervision.md @@ -553,4 +553,4 @@ The safe command-channel contract is covered without a notification by `tests/fm Prime Agent primary supervision uses the tracked `.prime/agent/extensions/fm-primary-prime-watch.ts` and `.prime/agent/extensions/fm-primary-turnend-guard.ts` extensions. The watcher extension owns continuity and the turn-end extension provides the recovery backstop. The task worker path is verified by `tests/fm-prime-agent-harness.test.sh`, `tests/fm-prime-watch-extension.test.sh`, and `docs/verification/prime-agent.md` on Linux with prime-agent 0.9.4. -The exact local validation command was `bin/fm-test-run.sh --jobs 1 tests/fm-prime-agent-harness.test.sh tests/fm-prime-watch-extension.test.sh`, which passed both scripts before the live adapter refresh. +The exact local validation command was `bin/fm-test-run.sh --jobs 1 tests/fm-prime-agent-harness.test.sh tests/fm-prime-watch-extension.test.sh`, which passed both scripts. From 8685c0ba926150d166e97b5ba841ef7623ebb7cc Mon Sep 17 00:00:00 2001 From: Eduard Ionel STAN Date: Mon, 14 Sep 2026 17:19:59 +0200 Subject: [PATCH 09/15] fix: correct prime-agent busy and secondmate safety --- bin/fm-control-lib.sh | 9 ++-- bin/fm-spawn.sh | 56 ++++++++++++++++++++----- tests/fm-busy-adapter-wiring.test.sh | 37 ++++++++++++++-- tests/fm-prime-agent-harness.test.sh | 4 +- tests/fm-spawn-dispatch-profile.test.sh | 22 +++++----- 5 files changed, 98 insertions(+), 30 deletions(-) diff --git a/bin/fm-control-lib.sh b/bin/fm-control-lib.sh index b15562d2bc0..2a9e269de18 100644 --- a/bin/fm-control-lib.sh +++ b/bin/fm-control-lib.sh @@ -99,10 +99,9 @@ fm_control_harness_family() { # esac } -# Which task kinds an adapter is verified to run. muse, gemini, rovo, and agy -# are crewmate/scout adapters only: none has a primary supervision protocol, and -# bin/fm-spawn.sh refuses a --secondmate launch on any of them. Prime Agent has -# a verified primary supervision protocol and supports local secondmates. The control +# Which task kinds an adapter is verified to run. muse, gemini, rovo, prime-agent, +# and agy are crewmate/scout adapters only: none has a primary supervision protocol, +# and bin/fm-spawn.sh refuses a --secondmate launch on any of them. The control # plane asks this BEFORE it stops anything, so an incompatible relaunch target is # refused while the current agent is still running rather than after it has # been stopped. @@ -110,7 +109,7 @@ fm_control_harness_supports_kind() { # local harness=${1-} kind=${2-} fm_control_harness_supported "$harness" || return 1 case "$harness" in - muse|gemini|rovo|agy) [ "$kind" != secondmate ] || return 1 ;; + muse|gemini|rovo|prime-agent|agy) [ "$kind" != secondmate ] || return 1 ;; esac return 0 } diff --git a/bin/fm-spawn.sh b/bin/fm-spawn.sh index 2cb7af89995..5fc30d9c861 100755 --- a/bin/fm-spawn.sh +++ b/bin/fm-spawn.sh @@ -1909,10 +1909,10 @@ case "$ARG3" in ;; esac -# muse, gemini, and agy are verified as CREWMATE/SCOUT adapters only. A -# secondmate is a firstmate instance, so it needs a primary supervision protocol. -# Prime Agent has that protocol in docs/supervision-protocols/prime-agent.md and -# its two primary extensions, with agent_end-based settle reconstruction. +# muse, gemini, prime-agent, and agy are verified as CREWMATE/SCOUT adapters only. +# A secondmate is a firstmate instance, so it needs a primary supervision protocol. +# Prime Agent's primary supervision path is not wired into the session-start +# renderer or secondmate launch, so it remains refused until that evidence exists. # gemini has none: docs/supervision-protocols/ carries no gemini wake protocol # and this task verified only crewmate-side launch, busy state, interrupt, and # exit, so a gemini secondmate is refused rather than stood up on an unverified @@ -1923,7 +1923,7 @@ esac # secondmate whose supervision cycle could never be armed. # agy has none either: it exposes no hook surface for primary supervision and # docs/supervision-protocols/ carries no agy wake protocol (agy 1.2.0). -if [ "$KIND" = secondmate ] && { [ "$HARNESS" = muse ] || [ "$HARNESS" = gemini ] || [ "$HARNESS" = agy ]; }; then +if [ "$KIND" = secondmate ] && { [ "$HARNESS" = muse ] || [ "$HARNESS" = gemini ] || [ "$HARNESS" = prime-agent ] || [ "$HARNESS" = agy ]; }; then echo "error: $HARNESS is a verified crewmate/scout adapter only and cannot run a secondmate; it has no primary supervision protocol. Select a harness verified for secondmates." >&2 exit 1 fi @@ -3822,9 +3822,10 @@ EOF cat > "$STATE/$ID.prime-ext.ts" < new Promise((resolve) => { @@ -3833,9 +3834,44 @@ const busyEvent = (state: string, event: string) => "--gen", "$BUSY_GEN", "--source", "prime-ext", "--event", event, ], () => resolve()); }); +const retryGraceMs = Number(process.env.HERDR_PI_RETRY_GRACE_MS) > 0 + ? Math.floor(Number(process.env.HERDR_PI_RETRY_GRACE_MS)) : 2500; +function lastAssistantStoppedOnError(event: any): boolean { + const messages = event?.messages; + if (!Array.isArray(messages)) return false; + for (let i = messages.length - 1; i >= 0; i -= 1) { + if (messages[i]?.role === "assistant") return messages[i]?.stopReason === "error"; + } + return false; +} export default function (pi: any) { - pi.on("agent_start", () => busyEvent("busy", "agent-start")); - pi.on("agent_end", () => busyEvent("idle", "agent-end")); + let agentActive = false; + let settleTimer: ReturnType | undefined; + const clearSettleTimer = () => { + if (settleTimer) clearTimeout(settleTimer); + settleTimer = undefined; + }; + pi.on("agent_start", () => { + clearSettleTimer(); + agentActive = true; + return busyEvent("busy", "agent-start"); + }); + pi.on("agent_end", (event: any, ctx: any) => { + if (!agentActive) return; + agentActive = false; + if (lastAssistantStoppedOnError(event)) { + clearSettleTimer(); + settleTimer = setTimeout(() => { + settleTimer = undefined; + void busyEvent("idle", "agent-end-error-grace"); + }, retryGraceMs); + settleTimer.unref?.(); + return; + } + if (typeof ctx?.hasPendingMessages === "function" && ctx.hasPendingMessages()) return; + clearSettleTimer(); + return busyEvent("idle", "agent-end"); + }); pi.on("turn_end", () => execFile("touch", ["$TURNEND"])); } EOF diff --git a/tests/fm-busy-adapter-wiring.test.sh b/tests/fm-busy-adapter-wiring.test.sh index 9dd29bd496a..fee629be343 100755 --- a/tests/fm-busy-adapter-wiring.test.sh +++ b/tests/fm-busy-adapter-wiring.test.sh @@ -55,7 +55,7 @@ classify() { # # Node host and fire one lifecycle handler. Modes: agent-start, settle-idle, # settle-continuing, turn-end. drive_pi_ext() { - EXT_PATH="$1" MODE="$2" node --input-type=module 2>&1 <<'EOF' + EXT_PATH="$1" MODE="$2" HERDR_PI_RETRY_GRACE_MS=50 node --input-type=module 2>&1 <<'EOF' import { pathToFileURL } from "node:url"; const mod = await import(pathToFileURL(process.env.EXT_PATH).href); const handlers = {}; @@ -187,8 +187,27 @@ const handlers = {}; mod.default({ on: (name, fn) => { handlers[name] = fn; } }); switch (process.env.MODE) { case "agent-start": await handlers["agent_start"]({}, {}); break; - case "agent-end": await handlers["agent_end"]({}, {}); break; + case "agent-end": + await handlers["agent_start"]({}, {}); + await handlers["agent_end"]({}, {}); + break; case "turn-end": await handlers["turn_end"]({}, {}); break; + case "error-held": + await handlers["agent_start"]({}, {}); + await handlers["agent_end"]({ messages: [{ role: "assistant", stopReason: "error" }] }, { hasPendingMessages: () => false }); + await new Promise((resolve) => setTimeout(resolve, 10)); + break; + case "error-retry": + await handlers["agent_start"]({}, {}); + await handlers["agent_end"]({ messages: [{ role: "assistant", stopReason: "error" }] }, { hasPendingMessages: () => false }); + await new Promise((resolve) => setTimeout(resolve, 10)); + await handlers["agent_start"]({}, {}); + await new Promise((resolve) => setTimeout(resolve, 80)); + break; + case "pending-held": + await handlers["agent_start"]({}, {}); + await handlers["agent_end"]({}, { hasPendingMessages: () => true }); + break; default: throw new Error("unknown mode " + process.env.MODE); } if (process.env.MODE === "turn-end") await new Promise((resolve) => setTimeout(resolve, 200)); @@ -222,12 +241,24 @@ test_prime_agent_extension_semantic_lifecycle() { out=$(classify prime-agent "$id" "$state") [ "$out" = "idle prime-ext" ] || fail "prime-agent agent_end must classify idle prime-ext, got '$out'" + out=$(drive_prime_ext "$ext" error-held) || fail "prime-agent error-end drive failed: $out" + out=$(classify prime-agent "$id" "$state") + [ "$out" = "busy prime-ext" ] || fail "prime-agent error-end must hold busy during retry grace, got '$out'" + + out=$(drive_prime_ext "$ext" error-retry) || fail "prime-agent retry drive failed: $out" + out=$(classify prime-agent "$id" "$state") + [ "$out" = "busy prime-ext" ] || fail "a retrying prime-agent run must remain busy after a stale error timer, got '$out'" + + out=$(drive_prime_ext "$ext" pending-held) || fail "prime-agent pending-message drive failed: $out" + out=$(classify prime-agent "$id" "$state") + [ "$out" = "busy prime-ext" ] || fail "prime-agent pending messages must hold busy, got '$out'" + out=$(drive_prime_ext "$ext" agent-start) || fail "prime-agent second agent_start drive failed: $out" "$ROOT/bin/fm-busy-event.sh" arm "$state" "$id" >/dev/null out=$(drive_prime_ext "$ext" agent-end) || fail "prime-agent stale agent_end drive failed: $out" out=$(classify prime-agent "$id" "$state") [ "$out" = "busy fm-spawn" ] || fail "a stale prime-agent extension event must not change state, got '$out'" - pass "prime-agent extension reports agent_start busy, agent_end idle, and turn_end as notification" + pass "prime-agent extension reports semantic busy/idle, holds retries and queued messages, and keeps turn_end as notification" } test_opencode_plugin_semantic_lifecycle() { diff --git a/tests/fm-prime-agent-harness.test.sh b/tests/fm-prime-agent-harness.test.sh index 8151f8581f5..6efa476e282 100755 --- a/tests/fm-prime-agent-harness.test.sh +++ b/tests/fm-prime-agent-harness.test.sh @@ -247,7 +247,9 @@ test_prime_agent_control_table() { [ "$(fm_control_exit_command prime-agent)" = /quit ] || fail "prime-agent exit command is not /quit" fm_control_harness_supports_kind prime-agent ship || fail "prime-agent should support ship tasks" fm_control_harness_supports_kind prime-agent scout || fail "prime-agent should support scout tasks" - fm_control_harness_supports_kind prime-agent secondmate || fail "prime-agent should support local secondmate tasks" + if fm_control_harness_supports_kind prime-agent secondmate; then + fail "prime-agent secondmate control should be refused until primary supervision is verified" + fi wiring=$(fm_control_harness_wiring_paths prime-agent /wt /state t1) [ "$wiring" = "/state/t1.prime-ext.ts" ] \ || fail "prime-agent wiring paths did not list its turn-end extension, got '$wiring'" diff --git a/tests/fm-spawn-dispatch-profile.test.sh b/tests/fm-spawn-dispatch-profile.test.sh index 2af9ce8780e..46d9d92f5f4 100755 --- a/tests/fm-spawn-dispatch-profile.test.sh +++ b/tests/fm-spawn-dispatch-profile.test.sh @@ -193,10 +193,10 @@ test_prime_agent_missing_binary_refuses_before_endpoint_or_metadata() { pass "prime-agent refuses safely and actionably when the selected executable is unavailable" } -# Prime Agent has a live-verified primary supervision protocol, so a local -# secondmate launch uses its primary extensions instead of being refused. -test_prime_agent_secondmate_uses_primary_extensions() { - local rec id sm out status launch +# Prime Agent has no verified primary supervision protocol, so secondmate +# launches remain refused before any endpoint or metadata is created. +test_prime_agent_secondmate_refused() { + local rec id sm out status id=profile-prime-agent-sm-z1d rec=$(make_spawn_case profile-prime-agent-sm prime-agent "$id") read_case_record "$rec" @@ -206,12 +206,12 @@ test_prime_agent_secondmate_uses_primary_extensions() { out=$(run_spawn "$HOME_DIR" "$WT_DIR" "$FAKEBIN_DIR" "$LAUNCH_LOG" "$id" "$sm" --secondmate) status=$? - expect_code 0 "$status" "prime-agent secondmate spawn should succeed" - assert_contains "$out" "spawned $id harness=prime-agent kind=secondmate" "prime-agent secondmate spawn did not preserve its runtime identity" - assert_meta_profile "$HOME_DIR/state/$id.meta" prime-agent default default - launch=$(cat "$LAUNCH_LOG") - assert_contains "$launch" "-e '$sm/.prime/agent/extensions/fm-primary-turnend-guard.ts' -e '$sm/.prime/agent/extensions/fm-primary-prime-watch.ts'" "prime-agent secondmate did not load both primary supervision extensions" - pass "a prime-agent secondmate launch uses its verified primary supervision extensions" + expect_code 1 "$status" "prime-agent secondmate spawn should be refused" + assert_contains "$out" "prime-agent is a verified crewmate/scout adapter only" \ + "prime-agent secondmate refusal did not name the unsupported role" + assert_absent "$HOME_DIR/state/$id.meta" "prime-agent secondmate refusal wrote task metadata" + [ ! -s "$LAUNCH_LOG" ] || fail "prime-agent secondmate refusal typed a launch command" + pass "prime-agent refuses secondmate launches without primary supervision" } test_non_cursor_launch_clears_inherited_cursor_markers() { @@ -1459,7 +1459,7 @@ test_non_claude_harness_ignores_claude_permission_mode() { test_worker_launch_delivers_role_scope test_no_profile_keeps_claude_profile_defaults test_prime_agent_launch_establishes_its_harness_marker -test_prime_agent_secondmate_uses_primary_extensions +test_prime_agent_secondmate_refused test_non_cursor_launch_clears_inherited_cursor_markers test_relative_home_overrides_launch_with_absolute_cross_process_paths test_home_defaults_preserve_absolute_or_resolve_relative_paths From 2bc72e3aded76dfdfcfe8ffed752307e5f1749cd Mon Sep 17 00:00:00 2001 From: Eduard Ionel STAN Date: Mon, 14 Sep 2026 17:20:05 +0200 Subject: [PATCH 10/15] fix: refuse unverified prime-agent quota routes --- bin/fm-quota-choose.sh | 10 +++++----- tests/fm-quota-choose.test.sh | 14 +++++++++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/bin/fm-quota-choose.sh b/bin/fm-quota-choose.sh index dde15442e28..89355707911 100755 --- a/bin/fm-quota-choose.sh +++ b/bin/fm-quota-choose.sh @@ -41,9 +41,9 @@ # model: and product: scopes. Any other or absent prefix is refused up front, # the same shape as an unknown harness, because no quota-axi row measures it. # Prime Agent records the launch provider separately from its model; the -# candidate's provider-qualified model preserves that identity here, so -# openai-codex/ checks codex and claude-bridge/ checks claude. A bare -# Prime Agent model remains the Pi-family form used only by Pi-provider tasks. +# candidate must preserve that identity here. Only openai-codex/ is mapped +# to the codex quota family. Bare, anthropic/, and other provider prefixes are +# refused rather than silently reading an unrelated quota row. # quota-axi reports Codex quota unavailable on this host because omp carries # its own Codex login, so an openai-codex candidate reads as unknown quota here # and is never selected on this host; its runway is disclosed uncertainty for @@ -336,8 +336,7 @@ provider_for_harness() { prime-agent) case "${2:-}" in openai-codex/*) printf 'codex\n' ;; - claude-bridge/*) printf 'claude\n' ;; - *) printf 'pi\n' ;; + *) return 1 ;; esac ;; grok) printf 'grok\n' ;; @@ -385,6 +384,7 @@ for c in "${CANDIDATES[@]}"; do fm_control_harness_supported "$harness" || die "unknown harness: $harness" provider_for_harness "$harness" "$model" >/dev/null || case "$harness" in omp) die "omp quota mapping covers only the openai-codex and claude-bridge prefixes: $model" ;; + prime-agent) die "prime-agent quota mapping requires the openai-codex/ prefix; bare and non-Codex providers are refused: $model" ;; *) die "unknown harness: $harness" ;; esac done diff --git a/tests/fm-quota-choose.test.sh b/tests/fm-quota-choose.test.sh index 2e2aba11dd1..afe9b502397 100755 --- a/tests/fm-quota-choose.test.sh +++ b/tests/fm-quota-choose.test.sh @@ -229,9 +229,17 @@ fi [ "$out" = "none" ] || fail "prime-agent openai-codex provider returned: $out" out=$(call_choose --snapshot "$LAB/captured.json" --candidate prime-agent:openai-codex/codex_other) [ "$out" = "prime-agent openai-codex/codex_other" ] || fail "prime-agent openai-codex provider mapped to the wrong quota family: $out" -out=$(call_choose --snapshot "$LAB/captured.json" --candidate prime-agent:pi-model) -[ "$out" = "prime-agent pi-model" ] || fail "bare prime-agent model did not retain the Pi provider family: $out" -ok "prime-agent quota follows its provider-qualified launch model" +if err=$(call_choose --snapshot "$LAB/captured.json" --candidate prime-agent:pi-model 2>&1); then + fail "bare prime-agent model unexpectedly selected" +fi +[ "$err" = "error: prime-agent quota mapping requires the openai-codex/ prefix; bare and non-Codex providers are refused: pi-model" ] \ + || fail "bare prime-agent model returned: $err" +if err=$(call_choose --snapshot "$LAB/captured.json" --candidate prime-agent:anthropic/claude-opus-5 2>&1); then + fail "anthropic prime-agent model unexpectedly selected" +fi +[ "$err" = "error: prime-agent quota mapping requires the openai-codex/ prefix; bare and non-Codex providers are refused: anthropic/claude-opus-5" ] \ + || fail "anthropic prime-agent model returned: $err" +ok "prime-agent quota requires its verified openai-codex provider" if err=$(call_choose --snapshot "$LAB/captured.json" --candidate omp:ollama/qwen3:8b --candidate claude:claude-3-5-sonnet 2>&1); then fail "unmapped omp prefix unexpectedly selected a later candidate" From 02890706bceee43ce0a0fec86c9a07ce1cb9937a Mon Sep 17 00:00:00 2001 From: Eduard Ionel STAN Date: Mon, 14 Sep 2026 17:20:09 +0200 Subject: [PATCH 11/15] docs: narrow prime-agent evidence to verified scope --- .agents/skills/harness-adapters/SKILL.md | 2 +- .../references/harness/prime-agent.md | 20 ++- AGENTS.md | 2 +- docs/configuration.md | 5 +- docs/trace-context.md | 2 +- docs/verification/prime-agent.md | 130 +++++++----------- docs/verification/runtime-backends.md | 6 +- tests/fm-prime-agent-signals-live-e2e.test.sh | 78 +++++------ 8 files changed, 97 insertions(+), 148 deletions(-) diff --git a/.agents/skills/harness-adapters/SKILL.md b/.agents/skills/harness-adapters/SKILL.md index 2d8dff6784b..12b1bf59a68 100644 --- a/.agents/skills/harness-adapters/SKILL.md +++ b/.agents/skills/harness-adapters/SKILL.md @@ -35,7 +35,7 @@ For recovery and control, use the exact `harness=` in `state/.meta`; never i Deliver lifecycle actions only through `../../../bin/fm-control.sh interrupt|exit|relaunch`. Never type an interrupt key or exit command through `fm-send`, where routing-marked lifecycle text becomes chat. Trust handling is complete only when inspection proves the target started processing its instructions; delivery success alone is not proof. -Muse, Gemini, and AGY are verified only for crewmate and scout work, never a secondmate or primary. Prime Agent is additionally verified for local secondmate work through its primary supervision protocol. +Muse, Gemini, Prime Agent, and AGY are verified only for crewmate and scout work, never a secondmate or primary. ## Detection diff --git a/.agents/skills/harness-adapters/references/harness/prime-agent.md b/.agents/skills/harness-adapters/references/harness/prime-agent.md index 89c56aa7454..5fd27e93f7a 100644 --- a/.agents/skills/harness-adapters/references/harness/prime-agent.md +++ b/.agents/skills/harness-adapters/references/harness/prime-agent.md @@ -1,8 +1,8 @@ # Prime Agent -This reference covers Prime Agent detection, crewmate/scout and local secondmate launch, semantic busy state, and control mechanics. +This reference covers Prime Agent detection, crewmate/scout launch, semantic busy state, and control mechanics. The active empirical record is [`docs/verification/prime-agent.md`](../../../../../docs/verification/prime-agent.md). -Remote secondmates remain outside the verified boundary. +Secondmate launches remain outside the verified boundary. ## Detection @@ -21,13 +21,11 @@ Detection and launch markers were verified live against Prime Agent 0.9.4. ## Launch and busy state `../../../bin/fm-spawn.sh` launches a Prime Agent crewmate or scout with one encoded brief, `--provider`, `--model`, `--thinking`, and `-e state/.prime-ext.ts`. -The generated extension writes the semantic busy record on `agent_start`, clears it on `agent_end`, and touches the turn-end notification marker on `turn_end`. -Prime Agent 0.9.4 has no `agent_settled` event, so `agent_end` is the adapter's logical prompt boundary. +The generated extension writes the semantic busy record on `agent_start`, clears it after a settled `agent_end`, and touches the turn-end notification marker on `turn_end`. +Prime Agent 0.9.4 has no `agent_settled` event, so error stop reasons and pending messages hold the busy record through retry or continuation. `bin/fm-busy-lib.sh` trusts the generated `prime-ext` source only for a recorded Prime Agent task. The extension is written outside the project and is removed by cleanup and harness relaunch wiring. -A local secondmate launch loads `.prime/agent/extensions/fm-primary-turnend-guard.ts` and `.prime/agent/extensions/fm-primary-prime-watch.ts` from its own home. -The primary protocol is [`docs/supervision-protocols/prime-agent.md`](../../../../../docs/supervision-protocols/prime-agent.md). -The local secondmate launch and both primary extension paths were verified in the isolated Herdr trial. +Prime Agent primary supervision and secondmate launch remain unproven and are outside this adapter's verified scope. ## Control @@ -37,11 +35,11 @@ A single `Escape` interrupts a running turn and leaves the composer empty withou Relaunch starts a fresh Prime Agent client in the same pane and directory rather than claiming an unverified pane-resume contract. Prime Agent 0.9.4 control behavior was verified live in Herdr. `../../../bin/fm-spawn.sh --help` owns executable preflight and rejects a missing `prime-agent` before task publication. -`../../../bin/fm-prime-agent-lib.sh` owns detached-worker listing and retirement for cleanup and secondmate relaunch. +`../../../bin/fm-prime-agent-lib.sh` owns detached-worker listing and retirement for task cleanup. ## Scope -Prime Agent is verified for crewmate, scout, and local secondmate work. -Remote secondmates remain refused because remote readiness has no Prime Agent verification. -The primary-session protocol is tracked and its extension behavior is covered by the Prime Agent supervision tests. +Prime Agent is verified for crewmate and scout work. +Secondmate launches remain refused because no primary supervision protocol is verified for Prime Agent. +Primary-session supervision is outside this adapter's verified scope. Prime Agent's native RPC, RLM, and agent-messaging features are not Firstmate control-plane replacements. diff --git a/AGENTS.md b/AGENTS.md index 7c0bef2bfe1..77237de9e67 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -209,7 +209,7 @@ A silent bootstrap section needs no action; for any printed actionable diagnosti ## 4. Harness and runtime dispatch Load `harness-adapters` before every spawn or recovery and before trust handling, skill invocation, interrupt, exit, resume, or adapter verification. -The verified harnesses are `claude`, `codex`, `opencode`, `pi`, `pi-signed`, `grok`, `kimi`, `cursor`, and `omp`, plus `muse`, `gemini`, `rovo`, and `agy` for crewmates and scouts, while `prime-agent` is also verified for local secondmates; never dispatch on an unverified adapter. +The verified harnesses are `claude`, `codex`, `opencode`, `pi`, `pi-signed`, `grok`, `kimi`, `cursor`, and `omp`, plus `muse`, `gemini`, `prime-agent`, `rovo`, and `agy` for crewmates and scouts only; never dispatch on an unverified adapter. If static `config/crew-harness` or `config/secondmate-harness` names an unverified adapter, report it and fall back only to a verified adapter rather than launching it. `docs/configuration.md` owns dispatch-profile and runtime-backend schemas, `bin/fm-harness.sh` owns static resolution, and `bin/fm-spawn.sh` owns launch flags and fail-closed validation. diff --git a/docs/configuration.md b/docs/configuration.md index 6cf3564e75e..81d2bf30b69 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -306,7 +306,7 @@ The full cmux home label also includes a short hash of the resolved `FM_ROOT` pa ## Harness support -claude, codex, opencode, pi, pi-signed, grok, kimi, cursor, omp, and prime-agent are empirically verified for crewmate and local secondmate launches; gemini is verified for crewmate and scout launches only, and [README requirements](../README.md#requirements) own the set supported for the primary session. +claude, codex, opencode, pi, pi-signed, grok, kimi, cursor, and omp are empirically verified for crewmate and secondmate launches; gemini and prime-agent are verified for crewmate and scout launches only, and [README requirements](../README.md#requirements) own the set supported for the primary session. A cursor secondmate or primary runs the tracked project-scope `.cursor/hooks.json` in its own home and must be launched with `--trust`, or no project hook loads; [`docs/supervision-protocols/cursor.md`](supervision-protocols/cursor.md) owns its supervision protocol. Cursor typed-submit confirmation is verified on tmux and Herdr only. prime-agent runs every session in a detached daemon worker that outlives both the pane and an explicit quit, so teardown (task worktree and secondmate home alike) and every secondmate relaunch retire the worker bound to that directory first ([`bin/fm-prime-agent-lib.sh`](../bin/fm-prime-agent-lib.sh)); without that a home would keep a live session-lock holder and land read-only. @@ -314,14 +314,13 @@ An in-place restart needs no retirement of its own: session-lock liveness asks p A worker whose pane died MID-TURN therefore keeps the lock on purpose, and an in-place restart does land read-only until that turn finishes; any answer that cannot prove the worker is finished counts as still alive. A quit pane also classifies dead rather than alive - its reporter identity survives the agent - so secondmate recovery relaunches it instead of skipping it as live. The discriminator there is the pane's whole process subtree, not which process group holds the terminal: a Ctrl+Z-suspended agent is still a stopped prime-agent process under the pane's shell and stays alive, while a quit pane has no prime-agent process left under it at all. -Remote secondmates are not verified on prime-agent and stay refused. On Zellij, cmux, and Orca a typed-plane Cursor send (a harness-native invocation or an explicit backend target; ordinary text steers ride the durable inbox and exit 0 at enqueue) lands, but `fm-send` reports delivery unconfirmed and exits non-zero because their shared submit core does not consult the busy footer; [runtime backend verification](verification/runtime-backends.md#cursor-agent-cli) owns the evidence and transcript-state boundary. muse is verified for crewmate and scout launches ONLY, and `fm-spawn.sh` refuses it for a secondmate, because muse ships no usable hook surface for a primary session's turn-end supervision; [`docs/verification/muse.md`](verification/muse.md) owns that evidence. muse also needs a worker-reachable credential before spawning, and the portable fleet path is the `/muse/auth.json` credential stored by `muse login`, because a caller-only `META_API_KEY` does not cross a long-lived backend daemon. gemini is likewise refused for secondmates because it has no primary supervision protocol; [its adapter reference](../.agents/skills/harness-adapters/references/harness/gemini.md) owns the credential precondition, canonical-launch wiring, and raw-launch limitations. rovo is likewise verified for crewmate and scout launches ONLY, refused for a secondmate for the same reason - no turn-end hook and no primary supervision protocol; [`docs/verification/rovo.md`](verification/rovo.md) owns that evidence, including the OAuth token's silent background refresh from a stored refresh token and both tmux and herdr pane liveness (herdr placement is verified live, with a Herdr-side agent-detection gap left open for recovery classification). agy is likewise verified for crewmate and scout launches ONLY, refused for a secondmate for the same reason - no hook surface and no primary supervision protocol; [`docs/verification/agy.md`](verification/agy.md) owns that evidence, including the spawn-time worktree trust pre-registration through `bin/fm-agy-trust.sh` and Herdr's native agy pane recognition. -prime-agent is verified for crewmate, scout, and local secondmate launches; its primary supervision protocol and detached-worker lifecycle are owned by [its adapter reference](../.agents/skills/harness-adapters/references/harness/prime-agent.md). +prime-agent is likewise verified for crewmate and scout launches ONLY, refused for a secondmate for the same reason - no primary supervision protocol yet; [its adapter reference](../.agents/skills/harness-adapters/references/harness/prime-agent.md) owns detection, launch, and control mechanics. New harnesses get verified through a supervised trial task before joining the set. The verified adapter evidence - each harness's busy-state source, interrupt and exit behavior, skill-invocation syntax, and per-harness quirks - lives in the skill tree rooted at [`.agents/skills/harness-adapters/SKILL.md`](../.agents/skills/harness-adapters/SKILL.md). The executable interrupt and exit mechanics live in [`bin/fm-control-lib.sh`](../bin/fm-control-lib.sh), and [`docs/agent-control.md`](agent-control.md) owns their lifecycle-control architecture. diff --git a/docs/trace-context.md b/docs/trace-context.md index c51f0c0f477..9a95971e7c8 100644 --- a/docs/trace-context.md +++ b/docs/trace-context.md @@ -23,7 +23,7 @@ When enabled, for each spawn Firstmate resolves one W3C `traceparent` carrier fo This feature parents no SDK span by itself. Because the injected carrier and the recorded carrier are the same string, an observer that reads the metadata reconstructs exactly the identity the child received. -The injection sits at the unconditional pre-launch export site, so it covers ship and scout spawns across `claude`, `codex`, `opencode`, `pi`, `pi-signed`, `prime-agent`, `grok`, `kimi`, `cursor`, `gemini`, `muse`, `rovo`, and `agy`, plus Secondmate spawns across that same set except the deliberately crewmate-only `gemini`, `muse`, `rovo`, and `agy` adapters. +The injection sits at the unconditional pre-launch export site, so it covers ship and scout spawns across `claude`, `codex`, `opencode`, `pi`, `pi-signed`, `prime-agent`, `grok`, `kimi`, `cursor`, `gemini`, `muse`, `rovo`, and `agy`, plus Secondmate spawns across that same set except the deliberately crewmate-only `gemini`, `muse`, `prime-agent`, `rovo`, and `agy` adapters. This is the same coverage `GOTMPDIR` already has and requires no trace-specific `launch_template()` behavior. Ship and scout spawns reach that site on every spawn backend (`tmux`, `herdr`, `zellij`, `orca`, `cmux`); a Secondmate reaches it on every backend that accepts a Secondmate spawn (`tmux`, `herdr`, `zellij`), because `bin/fm-spawn.sh` rejects a Secondmate on `orca` and `cmux`. diff --git a/docs/verification/prime-agent.md b/docs/verification/prime-agent.md index 83942a4d245..b452c2ff168 100644 --- a/docs/verification/prime-agent.md +++ b/docs/verification/prime-agent.md @@ -1,4 +1,4 @@ -# Verification: the prime-agent crewmate/scout and secondmate adapter +# Verification: the Prime Agent crewmate/scout adapter Active empirical facts for firstmate's Prime Agent adapter. The skill tree rooted at [`.agents/skills/harness-adapters/SKILL.md`](../../.agents/skills/harness-adapters/SKILL.md) owns the operating facts through [`references/harness/prime-agent.md`](../../.agents/skills/harness-adapters/references/harness/prime-agent.md); this record owns how they were established and what remains unproven. @@ -9,106 +9,66 @@ The skill tree rooted at [`.agents/skills/harness-adapters/SKILL.md`](../../.age |---|---| | Version | `prime-agent 0.9.4` | | Verified | 2026-09-14 | -| Binary | `/home/eduard/.local/bin/prime-agent` | +| Binary | resolved with `command -v prime-agent` | | Platform | Linux x86_64 | | Backend | Herdr 0.8.2, in an isolated non-`default` lab session created only through `bin/fm-herdr-lab.sh` | -| Provider and model | `openai-codex` and `gpt-5.6-terra` | +| Provider and model | `openai-codex` and a configured Prime Agent model | -Every Herdr command below ran through the named lab helper with a trailing `--session` argument. -The helper's fleet-state tripwire reported the same running `default` session before provisioning and after teardown. -The shared Prime Agent daemon was inspected read-only and was not stopped, restarted, upgraded, or reconfigured. +The live guard is opt-in because it submits real prompts. +Every Herdr command in the guard runs through `HERDR_LAB_HELPER`, which defaults to `$ROOT/bin/fm-herdr-lab.sh`. +The shared Prime Agent daemon is not stopped, restarted, upgraded, or reconfigured. ## Detection and launch flags -The live launch used the same marker and flags that Firstmate emits: +The production launch was rendered by `bin/fm-spawn.sh` with the explicit Prime Agent marker and provider-qualified profile. +The launch clears inherited foreign markers and passes the provider, model, thinking level, encoded brief, and generated extension. +The live guard resolves the executable with `command -v prime-agent` and checks a numeric version banner and a non-empty model field without depending on a personal path or a model-specific screen string. +Herdr process inspection identified the foreground process as `prime-agent`. +The launch reached the Prime Agent composer without a trust stop. -``` -$ env -u CLAUDECODE -u GROK_AGENT PI_CODING_AGENT=true FM_PI_HARNESS=prime-agent prime-agent --model gpt-5.6-terra --provider openai-codex --thinking low -``` - -Herdr's process inspection returned the exact foreground identity: - -``` -{"process_info":{"foreground_processes":[{"argv":["prime-agent"],"name":"prime-agent"}],"pane_id":"w2:p1"}} -``` - -The live worker rendered the following startup fields: - -``` -version v0.9.4 -model gpt-5.6-terra -← agents/resume GPT-5.6 Terra • low ? for shortcuts -``` - -An extension captured the launch environment with these values: - -``` -PI_CODING_AGENT=true -FM_PI_HARNESS=prime-agent -PRIME_AGENT_INTERNAL_DAEMON_WORKER=1 -PRIME_AGENT_CODING_AGENT_DIR=/home/eduard/.prime/agent -``` +## Extension loading and busy state -The Prime Agent daemon status was read with `prime-agent status --json` and reported `version: 0.9.4`, `protocolVersion: 7`, `status: current`, `isDefault: true`, and `hasTrackedWorkers: true`. +The production-generated extension loaded in the isolated Herdr workspace. +The live guard confirmed the initial turn settled to `idle prime-ext` and created the turn-end notification marker. +A real tool call changed the adapter classification to `busy prime-ext`. +The Herdr agent record simultaneously reported `agent_status=working`. +After the tool call completed, the adapter classification returned to `idle prime-ext`. +The extension uses `agent_start` for busy state and holds `agent_end` idle publication when the last assistant message stopped with an error or when pending messages are queued. +A retry start cancels the held error timer. +`turn_end` remains a notification touch and never fabricates idle state. +The portable regression drives normal completion, error grace, retry, pending-message, and stale-generation cases in `tests/fm-busy-adapter-wiring.test.sh`. -## Extension loading and trust +## Supervised task path -A fresh lab project containing `.prime/agent/extensions/auto.ts` wrote its load marker without an explicit `-e` flag. -The same launch showed no trust prompt and reached the Prime Agent composer. -A worker extension supplied with `-e ` also loaded and received `session_start`, `agent_start`, `turn_end`, and `agent_end` callbacks. -The extension load and callback evidence was recorded as JSON lines: +The production task path is owned by these commands and is covered by the deterministic spawn and control suites: ``` -{"name":"loaded","value":{"pi":"true","fm":"prime-agent","daemon":"1","dir":"/home/eduard/.prime/agent"}} -{"name":"session_start","value":{"type":"session_start","reason":"startup"}} -{"name":"agent_start","value":{"type":"agent_start"}} -{"name":"turn_end","value":{"type":"turn_end","turnIndex":0}} -{"name":"agent_end","value":{"type":"agent_end"}} +bin/fm-spawn.sh --mode direct-PR --yolo off --harness prime-agent --provider openai-codex --model --effort low +FM_HOME= bin/fm-send.sh "Read the instructions and continue the task." +FM_HOME= bin/fm-control.sh interrupt +FM_HOME= bin/fm-control.sh exit +FM_HOME= bin/fm-control.sh relaunch --harness prime-agent --model --effort low --note "Continue from the durable instructions." ``` -This verifies the 0.9.4 extension surface and the absence of a trust stop for project-local `.prime/agent/extensions/` discovery. +`tests/fm-spawn-dispatch-profile.test.sh` verifies the generated production launch and the Prime Agent secondmate refusal before endpoint or metadata publication. +`tests/fm-control.test.sh` verifies the Pi-family interrupt, exit, and relaunch mechanics and the Prime Agent capability refusal for secondmates. +The live guard uses direct Herdr input for vendor behavior so it can isolate the Prime Agent process without creating a real task record. +The live guard therefore does not claim an end-to-end `fm-send` or `fm-control` vendor run. -## Busy and idle state +## Interrupt, exit, and relaunch -A prompt that asked the model to run `sleep 15` changed Herdr's native agent state from `idle` to `working` while the tool was running. -The same pane returned to `idle` after the turn completed and rendered the requested response. -The decisive live reads were: +A real long-running Prime Agent turn reached Herdr's `working` state. +One Escape cancelled the turn and rendered `Operation aborted`. +Sending `/quit` followed by Enter returned the pane to its shell. +Launching the generated command again in the same pane rendered a numeric version banner and returned to the composer. +The live guard confirmed detached Prime Agent worker retirement for the temporary project directory after the final quit. -``` -{"agent":{"agent":"prime-agent","agent_status":"working","cwd":".../.prime-live-lab","pane_id":"w2:p1"}} -{"agent":{"agent":"prime-agent","agent_status":"idle","cwd":".../.prime-live-lab","pane_id":"w2:p1"}} -``` - -The 0.9.4 extension callbacks also showed `agent_start` before the long turn and `agent_end` after it. -The adapter's semantic busy-state extension uses those two callbacks and leaves `turn_end` as a notification only. - -## Interrupt, quit, and relaunch - -A second `sleep 30` prompt reached `agent_status=working`. -One `Escape` sent through `bin/fm-herdr-lab.sh run ... pane send-keys ... escape` changed the native state to `done` and rendered `Operation aborted` without completing the requested response. - -Sending `/quit` followed by Enter returned Herdr's process inspection to a lone `/bin/bash` pane: - -``` -{"process_info":{"foreground_processes":[{"argv":["/bin/bash"],"name":"bash"}],"pane_id":"w2:p1"}} -``` - -Launching the same command again in that pane rendered `version v0.9.4`, `model gpt-5.6-terra`, and an idle composer. -The relaunch reused the same Herdr pane and project directory. - -## Detached daemon session retirement +## Scope and still unproven -The Prime Agent client created a detached daemon worker while the Herdr pane was active. -The launch environment reported `PRIME_AGENT_INTERNAL_DAEMON_WORKER=1` and the daemon's `status --json` reported tracked workers. -After `/quit`, the Herdr pane had no Prime Agent process in its foreground process list while the daemon session remained registered. -The adapter's retirement path is exercised by `fm-prime-agent-lib.sh` against the exact project directory during task cleanup and secondmate relaunch; the shared daemon itself was never stopped. - -## Scope and remaining boundaries - -The live evidence covers the crewmate/scout launch, local secondmate launch surface, marker export, launch flags, project-local extension discovery, explicit extension loading, busy and idle callbacks, Escape, `/quit`, relaunch, and detached-worker behavior on Prime Agent 0.9.4. -Remote secondmates remain outside this evidence and are still refused by the remote readiness allowlist. -Pane resume and fork are not claimed because Firstmate uses deterministic relaunch for Prime Agent. -No RPC backend, RLM control-plane replacement, or upstream repository operation was tested or changed. +The live evidence covers the crewmate/scout launch, marker export, provider-qualified flags, project extension loading, semantic busy and idle behavior, retry and pending-message holds, Escape, `/quit`, relaunch, and detached-worker retirement on Prime Agent 0.9.4. +Prime Agent secondmate launches remain refused because its primary supervision protocol is not wired into the session-start renderer and has not been verified end to end. +Remote secondmates remain outside this evidence. +Primary-session supervision, pane resume, fork, RPC, RLM, and agent-messaging control-plane replacement are not claimed. ## Refreshing this record @@ -116,5 +76,7 @@ Run the portable adapter and busy-state suites, then run the opt-in live guard a ``` bin/fm-test-run.sh --jobs 1 tests/fm-prime-agent-harness.test.sh tests/fm-busy-adapter-wiring.test.sh tests/fm-quota-choose.test.sh tests/fm-spawn-dispatch-profile.test.sh -FM_PRIME_AGENT_LIVE_E2E=1 bin/fm-test-run.sh tests/fm-prime-agent-signals-live-e2e.test.sh +FM_PRIME_AGENT_LIVE_E2E=1 bin/fm-test-run.sh --jobs 1 tests/fm-prime-agent-signals-live-e2e.test.sh ``` + +The live guard reports seven `ok` lines and ends with `FM_TEST_SUMMARY total=1 failed=0` when the installed tools and provider are available. diff --git a/docs/verification/runtime-backends.md b/docs/verification/runtime-backends.md index 68a4edb89d4..68947f10a53 100644 --- a/docs/verification/runtime-backends.md +++ b/docs/verification/runtime-backends.md @@ -1910,8 +1910,8 @@ The Prime Agent adapter was verified on 2026-09-14 with prime-agent 0.9.4 on Lin The shared process classifier recognizes the exact `prime-agent` executable and rejects similarly named helpers. Firstmate launch resolves the concrete executable path, sets `FM_PI_HARNESS=prime-agent`, clears inherited foreign markers, and loads the task extension. The launch path preserves provider, model, effort, and autonomous-gate options. -The generated task extension reports semantic busy and idle state through `agent_start` and `agent_end` and keeps `turn_end` as a notification. -Prime Agent is verified for local secondmate launches because its two primary supervision extensions load in the secondmate-shaped home. -The complete dated command transcript is [`docs/verification/prime-agent.md`](prime-agent.md). +The generated task extension reports semantic busy and idle state from the verified `agent_start` and settled `agent_end` paths and keeps `turn_end` as a notification. +Prime Agent is verified for crewmate and scout launches only; secondmate launches remain refused until primary supervision is wired and verified. +The complete dated evidence is [`docs/verification/prime-agent.md`](prime-agent.md). `tests/fm-prime-agent-harness.test.sh`, `tests/fm-prime-watch-extension.test.sh`, `tests/fm-busy-adapter-wiring.test.sh`, and `tests/fm-spawn-dispatch-profile.test.sh` are the deterministic verification entry points. `FM_PRIME_AGENT_LIVE_E2E=1 bin/fm-test-run.sh tests/fm-prime-agent-signals-live-e2e.test.sh` refreshes the real Prime Agent and Herdr evidence. diff --git a/tests/fm-prime-agent-signals-live-e2e.test.sh b/tests/fm-prime-agent-signals-live-e2e.test.sh index 133ed7035eb..5fb1dc2a986 100755 --- a/tests/fm-prime-agent-signals-live-e2e.test.sh +++ b/tests/fm-prime-agent-signals-live-e2e.test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Opt-in live Prime Agent 0.9.4 adapter regression in an isolated Herdr lab. +# Opt-in live Prime Agent adapter regression in an isolated Herdr lab. # It drives the production spawn-generated extension against a real Prime Agent # process and never touches the shared default Herdr session or daemon. set -u @@ -9,7 +9,11 @@ set -u fm_live_gate opt-in FM_PRIME_AGENT_LIVE_E2E prime-agent herdr jq -LAB_HELPER=${HERDR_LAB_HELPER:-/home/eduard/Dropbox/Projects/firstmate/bin/fm-herdr-lab.sh} +LAB_HELPER=${HERDR_LAB_HELPER:-$ROOT/bin/fm-herdr-lab.sh} +PRIME_AGENT=$(command -v prime-agent || true) +[ -n "$PRIME_AGENT" ] || fail "FM_PRIME_AGENT_LIVE_E2E=1 but prime-agent is not on PATH" +PRIME_VERSION=$("$PRIME_AGENT" --version 2>&1 | head -1 || true) +[ -n "$PRIME_VERSION" ] || fail "could not read the installed Prime Agent version" [ -x "$LAB_HELPER" ] || fail "FM_PRIME_AGENT_LIVE_E2E=1 but the Herdr lab helper is not executable: $LAB_HELPER" # shellcheck source=tests/herdr-test-safety.sh @@ -23,8 +27,6 @@ herdr_forget_inherited_pane . "$ROOT/bin/fm-prime-agent-lib.sh" LAB=$(mktemp -d "${TMPDIR:-/tmp}/fm-prime-agent-live.XXXXXX") -PRIMARY_PROJECT="$LAB/primary-project" -PRIMARY_HOME="$LAB/primary-home" HOME_DIR="$LAB/home" PROJECT="$LAB/project" WT="$LAB/worktree" @@ -33,7 +35,6 @@ FAKEBIN= LAUNCH_LOG="$LAB/launch.log" SESSION=$("$LAB_HELPER" name prime-adapter-solid) PANE= -PRIMARY_PANE= fail() { printf 'not ok - %s\n' "$1" >&2; exit 1; } pass() { printf 'ok - %s\n' "$1"; } @@ -62,7 +63,7 @@ out=$(FM_FAKE_LAUNCH_LOG="$LAUNCH_LOG" fm_test_run_spawn "$HOME_DIR" "$WT" "$FAK --harness prime-agent --provider openai-codex --model gpt-5.6-terra --effort low \ --mode direct-PR --yolo off 2>&1) || fail "production spawn generation failed: $out" [ -f "$HOME_DIR/state/$ID.prime-ext.ts" ] || fail "production spawn did not generate the Prime Agent extension" -LAUNCH=$(sed "s#'$FAKEBIN/prime-agent'#'/home/eduard/.local/bin/prime-agent'#" "$LAUNCH_LOG") +LAUNCH=$(sed "s#'$FAKEBIN/prime-agent'#'$PRIME_AGENT'#" "$LAUNCH_LOG") [ "$LAUNCH" != "$(cat "$LAUNCH_LOG")" ] || fail "could not replace the fake Prime Agent executable in the generated launch" "$LAB_HELPER" provision "$SESSION" || fail "could not provision isolated Herdr lab" @@ -75,18 +76,18 @@ PANE=$(printf '%s' "$WS" | jq -er '.result.root_pane.pane_id') \ for i in $(seq 1 120); do screen=$("$LAB_HELPER" run "$SESSION" pane read "$PANE" --source recent --lines 200 2>/dev/null || true) - if printf '%s\n' "$screen" | grep -q 'version v0.9.4' \ - && printf '%s\n' "$screen" | grep -q 'GPT-5.6 Terra'; then + if printf '%s\n' "$screen" | grep -Eq 'version[[:space:]]+v[0-9]+' \ + && printf '%s\n' "$screen" | grep -Eq 'model[[:space:]]+[^[:space:]—]'; then break fi sleep 0.5 done -printf '%s\n' "$screen" | grep -q 'version v0.9.4' || fail "Prime Agent 0.9.4 did not render its startup screen" -case "$screen" in - *"GPT-5.6 Terra"*"low"*) : ;; - *) fail "generated launch did not render the selected model and thinking level; launch=$LAUNCH screen=$screen" ;; -esac -pass "Prime Agent 0.9.4 rendered the production model/provider/thinking launch" +printf '%s\n' "$screen" | grep -Eq 'version[[:space:]]+v[0-9]+' || fail "Prime Agent did not render its startup screen (binary=$PRIME_AGENT): $screen" +printf '%s\n' "$screen" | grep -Eq 'model[[:space:]]+[^[:space:]—]' \ + || fail "generated launch did not render a selected model; launch=$LAUNCH screen=$screen" +printf '%s\n' "$screen" | grep -Eq 'version[[:space:]]+v[0-9]+([.][0-9]+)+' \ + || fail "generated launch did not render a numeric version; launch=$LAUNCH screen=$screen" +pass "Prime Agent rendered the production model, provider, and thinking launch" for i in $(seq 1 120); do [ "$(fm_busy_classify tmux fake:w prime-agent "$ID" "$HOME_DIR/state")" = "idle prime-ext" ] && break @@ -95,7 +96,7 @@ done [ "$(fm_busy_classify tmux fake:w prime-agent "$ID" "$HOME_DIR/state")" = "idle prime-ext" ] \ || fail "generated Prime Agent extension did not settle the launch turn" [ -f "$HOME_DIR/state/$ID.turn-ended" ] || fail "generated Prime Agent extension did not write turn-end notification" -pass "Prime Agent 0.9.4 loaded the production extension and settled its first turn" +pass "Prime Agent $PRIME_VERSION loaded the production extension and settled its first turn" send() { "$LAB_HELPER" run "$SESSION" pane send-text "$PANE" "$1" >/dev/null || return 1 @@ -123,7 +124,7 @@ agent_busy=$("$LAB_HELPER" run "$SESSION" agent get "$PANE") printf '%s\n' "$agent_busy" | jq -e '.result.agent.agent_status == "working"' >/dev/null \ || fail "Herdr did not report working during the real busy probe: $agent_busy" wait_idle || fail "generated Prime Agent extension did not report idle after the real tool call" -pass "Prime Agent 0.9.4 agent_start/agent_end wiring reports busy and idle" +pass "Prime Agent $PRIME_VERSION agent_start/agent_end wiring reports busy and idle" send 'Run the shell command sleep 20, then reply with exactly PRIME_AGENT_CANCELLED_NO.' || fail "could not submit interrupt probe" wait_busy || fail "interrupt probe never became busy" @@ -131,7 +132,7 @@ wait_busy || fail "interrupt probe never became busy" wait_idle || fail "Prime Agent did not settle after Escape" screen=$("$LAB_HELPER" run "$SESSION" pane read "$PANE" --source recent --lines 200) printf '%s\n' "$screen" | grep -q 'Operation aborted' || fail "Escape did not abort the Prime Agent turn: $screen" -pass "Prime Agent 0.9.4 cancels a running turn with one Escape" +pass "Prime Agent $PRIME_VERSION cancels a running turn with one Escape" send '/quit' || fail "could not submit /quit" for i in $(seq 1 60); do @@ -141,40 +142,29 @@ for i in $(seq 1 60); do done printf '%s\n' "$info" | jq -e '.result.process_info.foreground_processes[0].name == "bash"' >/dev/null \ || fail "Prime Agent /quit did not return the pane to bash" -pass "Prime Agent 0.9.4 exits cleanly and leaves the detached worker for retirement" +pass "Prime Agent $PRIME_VERSION exits cleanly and leaves the detached worker for retirement" "$LAB_HELPER" run "$SESSION" pane run "$PANE" "$LAUNCH" >/dev/null \ || fail "could not relaunch Prime Agent in the same pane" for i in $(seq 1 120); do screen=$("$LAB_HELPER" run "$SESSION" pane read "$PANE" --source recent --lines 200 2>/dev/null || true) - printf '%s\n' "$screen" | grep -q 'version v0.9.4' && break + if printf '%s\n' "$screen" | grep -Eq 'version[[:space:]]+v[0-9]+'; then break; fi sleep 0.5 done -printf '%s\n' "$screen" | grep -q 'version v0.9.4' || fail "Prime Agent did not relaunch in the same pane" -pass "Prime Agent 0.9.4 relaunches in the same Herdr pane" +printf '%s\n' "$screen" | grep -Eq 'version[[:space:]]+v[0-9]+' || fail "Prime Agent did not relaunch in the same pane" +pass "Prime Agent $PRIME_VERSION relaunches in the same Herdr pane" -# A secondmate is itself a firstmate primary, so verify the two tracked primary -# extensions load in an isolated secondmate-shaped home before enabling it. -mkdir -p "$PRIMARY_PROJECT" "$PRIMARY_HOME/state" "$PRIMARY_HOME/config" "$PRIMARY_HOME/data" "$PRIMARY_HOME/projects" -cp -a "$ROOT/.prime" "$ROOT/.pi" "$ROOT/bin" "$ROOT/AGENTS.md" "$PRIMARY_PROJECT/" -printf '%s\n' "$$" > "$PRIMARY_HOME/state/.lock" -PRIMARY_WS=$("$LAB_HELPER" run "$SESSION" workspace create --cwd "$PRIMARY_PROJECT" --label prime-secondmate-live --no-focus) \ - || fail "could not create isolated secondmate-shaped Herdr workspace" -PRIMARY_PANE=$(printf '%s' "$PRIMARY_WS" | jq -er '.result.root_pane.pane_id') \ - || fail "secondmate-shaped workspace did not return a pane id" -PRIMARY_CMD="FM_HOME='$PRIMARY_HOME' FM_ROOT_OVERRIDE='$PRIMARY_PROJECT' FM_STATE_OVERRIDE='$PRIMARY_HOME/state' FM_DATA_OVERRIDE='$PRIMARY_HOME/data' FM_CONFIG_OVERRIDE='$PRIMARY_HOME/config' bash -lc 'printf %s \"\$\$\" > \"$PRIMARY_HOME/state/.lock\"; exec env -u CLAUDECODE -u GROK_AGENT -u PI_CODING_AGENT -u FM_PI_HARNESS prime-agent --model gpt-5.6-terra --provider openai-codex --thinking low -e \"$PRIMARY_PROJECT/.prime/agent/extensions/fm-primary-turnend-guard.ts\" -e \"$PRIMARY_PROJECT/.prime/agent/extensions/fm-primary-prime-watch.ts\"'" -"$LAB_HELPER" run "$SESSION" pane run "$PRIMARY_PANE" "$PRIMARY_CMD" >/dev/null \ - || fail "could not launch the secondmate-shaped Prime Agent primary" -for i in $(seq 1 100); do - [ -f "$PRIMARY_HOME/state/.prime-turnend-extension-loaded" ] \ - && [ -f "$PRIMARY_HOME/state/.prime-watch-extension-loaded" ] && break +send '/quit' || fail "could not submit the cleanup quit" +for i in $(seq 1 60); do + info=$("$LAB_HELPER" run "$SESSION" pane process-info --pane "$PANE" 2>/dev/null || true) + printf '%s\n' "$info" | jq -e '.result.process_info.foreground_processes[0].name == "bash"' >/dev/null 2>&1 && break + sleep 0.5 +done +for i in $(seq 1 60); do + fm_prime_agent_stop_sessions_under "$WT" >/dev/null 2>&1 || true + left=$(fm_prime_agent_session_ids_under "$(CDPATH='' cd -- "$WT" && pwd -P)" resident 2>/dev/null || true) + [ -z "$left" ] && break sleep 0.5 done -[ -f "$PRIMARY_HOME/state/.prime-turnend-extension-loaded" ] \ - || fail "Prime Agent primary turn-end extension did not load in the secondmate-shaped home" -[ -f "$PRIMARY_HOME/state/.prime-watch-extension-loaded" ] \ - || fail "Prime Agent primary watcher extension did not load in the secondmate-shaped home" -pass "Prime Agent 0.9.4 loads both primary supervision extensions for a local secondmate" -"$LAB_HELPER" run "$SESSION" pane send-text "$PRIMARY_PANE" '/quit' >/dev/null || true -"$LAB_HELPER" run "$SESSION" pane send-keys "$PRIMARY_PANE" enter >/dev/null || true -fm_prime_agent_stop_sessions_under "$PRIMARY_PROJECT" >/dev/null 2>&1 || true +[ -z "$left" ] || fail "resident detached Prime Agent sessions remain after cleanup: $left" +pass "Prime Agent detached worker retirement was confirmed" From b37e3304b07fb9d4b5344400d048bb70ba713e88 Mon Sep 17 00:00:00 2001 From: Eduard Ionel STAN Date: Mon, 14 Sep 2026 17:24:37 +0200 Subject: [PATCH 12/15] test: align prime-agent refusal coverage --- .agents/skills/quota-array-dispatch/SKILL.md | 1 + tests/fm-control.test.sh | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.agents/skills/quota-array-dispatch/SKILL.md b/.agents/skills/quota-array-dispatch/SKILL.md index c2b9f05ece5..293cafe7368 100644 --- a/.agents/skills/quota-array-dispatch/SKILL.md +++ b/.agents/skills/quota-array-dispatch/SKILL.md @@ -29,6 +29,7 @@ An `exhausted_now` runway vetoes the candidate. The helper selects a candidate only when its applicable quota has a known `effectivePercentRemaining` greater than zero. This is an optional narrow helper with a known limitation: it maps each harness to one primary provider family only, so a candidate whose established provider differs from that primary family is checked against the wrong quota row. omp has no primary family, so the helper keys an `omp:` candidate on its model prefix, mapping only `openai-codex/` and `claude-bridge/` and refusing every other prefix; the helper's header owns that mapping. +Prime Agent candidates must use the verified `openai-codex/` prefix; bare, `anthropic/`, and other provider prefixes are refused rather than mapped to an unrelated quota family. Authoritative multi-provider routing - including provider discovery from the harness catalog and quota matching by that explicit provider - stays owned by this skill's intake procedure above and AGENTS.md section 4, not by the helper. Use it only when the brief already fixed the candidate order and every candidate's provider is the harness's primary family. It does not replace the reasoning-class, runway-feasibility, or authentication gates above. diff --git a/tests/fm-control.test.sh b/tests/fm-control.test.sh index 76c7bdd51cd..21b6ec2a7e6 100755 --- a/tests/fm-control.test.sh +++ b/tests/fm-control.test.sh @@ -382,10 +382,12 @@ test_harness_kind_capability() { done fm_control_harness_supports_kind muse secondmate \ && fail "muse has no primary supervision protocol and must not claim a secondmate" - for harness in claude codex opencode pi pi-signed prime-agent grok kimi omp; do + for harness in claude codex opencode pi pi-signed grok kimi omp; do fm_control_harness_supports_kind "$harness" secondmate \ || fail "$harness should be able to run a secondmate" done + fm_control_harness_supports_kind prime-agent secondmate \ + && fail "prime-agent has no verified primary supervision protocol and must not claim a secondmate" fm_control_harness_supports_kind someagent ship \ && fail "an unverified harness must not claim any kind" pass "fm-control-lib: adapter capability is per task kind, not per adapter alone" From 3c45c0216ab50880fc3a894efa903cd3ae859154 Mon Sep 17 00:00:00 2001 From: Eduard Ionel STAN Date: Mon, 14 Sep 2026 17:44:34 +0200 Subject: [PATCH 13/15] fix: harden prime-agent busy lifecycle evidence --- .../references/harness/prime-agent.md | 2 +- bin/fm-quota-choose.sh | 7 +-- bin/fm-spawn.sh | 61 ++++++++++--------- docs/configuration.md | 7 +-- docs/verification/prime-agent.md | 4 +- docs/verification/supervision.md | 4 +- tests/fm-busy-adapter-wiring.test.sh | 48 ++++++++++++++- tests/fm-prime-agent-signals-live-e2e.test.sh | 22 +++++-- 8 files changed, 106 insertions(+), 49 deletions(-) diff --git a/.agents/skills/harness-adapters/references/harness/prime-agent.md b/.agents/skills/harness-adapters/references/harness/prime-agent.md index 5fd27e93f7a..8693ddcda3e 100644 --- a/.agents/skills/harness-adapters/references/harness/prime-agent.md +++ b/.agents/skills/harness-adapters/references/harness/prime-agent.md @@ -22,7 +22,7 @@ Detection and launch markers were verified live against Prime Agent 0.9.4. `../../../bin/fm-spawn.sh` launches a Prime Agent crewmate or scout with one encoded brief, `--provider`, `--model`, `--thinking`, and `-e state/.prime-ext.ts`. The generated extension writes the semantic busy record on `agent_start`, clears it after a settled `agent_end`, and touches the turn-end notification marker on `turn_end`. -Prime Agent 0.9.4 has no `agent_settled` event, so error stop reasons and pending messages hold the busy record through retry or continuation. +Prime Agent 0.9.4 has no `agent_settled` event, so error stop reasons and pending messages hold the busy record for a short grace window. `bin/fm-busy-lib.sh` trusts the generated `prime-ext` source only for a recorded Prime Agent task. The extension is written outside the project and is removed by cleanup and harness relaunch wiring. Prime Agent primary supervision and secondmate launch remain unproven and are outside this adapter's verified scope. diff --git a/bin/fm-quota-choose.sh b/bin/fm-quota-choose.sh index 89355707911..3b2a3ce80ae 100755 --- a/bin/fm-quota-choose.sh +++ b/bin/fm-quota-choose.sh @@ -44,10 +44,9 @@ # candidate must preserve that identity here. Only openai-codex/ is mapped # to the codex quota family. Bare, anthropic/, and other provider prefixes are # refused rather than silently reading an unrelated quota row. -# quota-axi reports Codex quota unavailable on this host because omp carries -# its own Codex login, so an openai-codex candidate reads as unknown quota here -# and is never selected on this host; its runway is disclosed uncertainty for -# the agent-side gates, not measured headroom. +# Live quota-axi data may report Codex quota as unknown when a harness carries +# its own Codex login; an openai-codex candidate then remains eligible only with +# disclosed uncertainty for the agent-side gates, not measured headroom. set -u SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" diff --git a/bin/fm-spawn.sh b/bin/fm-spawn.sh index 5fc30d9c861..77ed4da76a3 100755 --- a/bin/fm-spawn.sh +++ b/bin/fm-spawn.sh @@ -1701,13 +1701,9 @@ launch_template() { fi ;; # prime-agent (Prime Agent): Pi-family CLI with Firstmate's turn-end and - # watcher extensions. Autonomous flags are populated only for this adapter. + # watcher extension. Autonomous flags are populated only for this adapter. prime-agent) - if [ "$kind" = secondmate ]; then - printf '%s' 'env -u CLAUDECODE -u GROK_AGENT __PRIMEBIN__ __PROVIDERFLAG____MODELFLAG____EFFORTFLAG____AUTONOMOUSFLAGS__-e __PRIMETURNEND__ -e __PRIMEWATCH__ "$(__OPINPUT__ encode launch-brief < __BRIEF__)"' - else - printf '%s' 'env -u CLAUDECODE -u GROK_AGENT __PRIMEBIN__ __PROVIDERFLAG____MODELFLAG____EFFORTFLAG____AUTONOMOUSFLAGS__-e __PRIMEEXT__ "$(__OPINPUT__ encode launch-brief < __BRIEF__)"' - fi + printf '%s' 'env -u CLAUDECODE -u GROK_AGENT __PRIMEBIN__ __PROVIDERFLAG____MODELFLAG____EFFORTFLAG____AUTONOMOUSFLAGS__-e __PRIMEEXT__ "$(__OPINPUT__ encode launch-brief < __BRIEF__)"' ;; # omp (Oh My Pi), a Pi fork. Same one-positional-brief, --model, --thinking, # and -e shape as Pi, verified on omp 18.1.11. The differences are all at @@ -3190,12 +3186,6 @@ EOF ;; esac fi -if [ "$KIND" = secondmate ] && [ "$HARNESS" = prime-agent ]; then - if ! fm_prime_agent_stop_sessions_under_strict "$PROJ_ABS"; then - echo "error: could not retire every resident prime-agent session bound to $PROJ_ABS; refusing secondmate relaunch" >&2 - exit 1 - fi -fi if [ "$KIND" = secondmate ]; then FM_INHERITABLE_CONFIG=trace-context \ propagate_inheritable_config "$CONFIG" "$PROJ_ABS/config" \ @@ -3823,9 +3813,9 @@ EOF // Firstmate semantic busy-state events + turn-end notification for prime-agent; // written by fm-spawn under the contract owned by bin/fm-busy-lib.sh. // Prime Agent 0.9.4 exposes agent_start and agent_end but no agent_settled. -// agent_end is held when an error may trigger an auto-retry or when messages -// are queued, matching the primary guard's settle reconstruction. turn_end -// fires at every inner turn boundary and stays a wake NOTIFICATION touch. +// agent_end is held briefly when an error may trigger an auto-retry or when +// messages are queued, matching the primary guard's settle reconstruction. +// turn_end fires at every inner turn boundary and stays a wake NOTIFICATION touch. import { execFile } from "node:child_process"; const busyEvent = (state: string, event: string) => new Promise((resolve) => { @@ -3836,6 +3826,8 @@ const busyEvent = (state: string, event: string) => }); const retryGraceMs = Number(process.env.HERDR_PI_RETRY_GRACE_MS) > 0 ? Math.floor(Number(process.env.HERDR_PI_RETRY_GRACE_MS)) : 2500; +const idleDebounceMs = Number(process.env.HERDR_PI_IDLE_DEBOUNCE_MS) > 0 + ? Math.floor(Number(process.env.HERDR_PI_IDLE_DEBOUNCE_MS)) : 250; function lastAssistantStoppedOnError(event: any): boolean { const messages = event?.messages; if (!Array.isArray(messages)) return false; @@ -3846,29 +3838,46 @@ function lastAssistantStoppedOnError(event: any): boolean { } export default function (pi: any) { let agentActive = false; + let boundSessionManager: unknown; let settleTimer: ReturnType | undefined; + const isBoundSession = (ctx: any): boolean => + boundSessionManager === undefined || ctx?.sessionManager === boundSessionManager; + const bindSession = (ctx: any): boolean => { + const sessionManager = ctx?.sessionManager; + if (boundSessionManager === undefined && sessionManager !== undefined) { + boundSessionManager = sessionManager; + } + return isBoundSession(ctx); + }; const clearSettleTimer = () => { if (settleTimer) clearTimeout(settleTimer); settleTimer = undefined; }; - pi.on("agent_start", () => { + const scheduleIdle = (delayMs: number, event: string) => { + clearSettleTimer(); + settleTimer = setTimeout(() => { + settleTimer = undefined; + void busyEvent("idle", event); + }, delayMs); + settleTimer.unref?.(); + }; + pi.on("agent_start", (_event: any, ctx: any) => { + if (!bindSession(ctx)) return; clearSettleTimer(); agentActive = true; return busyEvent("busy", "agent-start"); }); pi.on("agent_end", (event: any, ctx: any) => { - if (!agentActive) return; + if (!isBoundSession(ctx) || !agentActive) return; agentActive = false; if (lastAssistantStoppedOnError(event)) { - clearSettleTimer(); - settleTimer = setTimeout(() => { - settleTimer = undefined; - void busyEvent("idle", "agent-end-error-grace"); - }, retryGraceMs); - settleTimer.unref?.(); + scheduleIdle(retryGraceMs, "agent-end-error-grace"); + return; + } + if (typeof ctx?.hasPendingMessages === "function" && ctx.hasPendingMessages()) { + scheduleIdle(idleDebounceMs, "agent-end-pending"); return; } - if (typeof ctx?.hasPendingMessages === "function" && ctx.hasPendingMessages()) return; clearSettleTimer(); return busyEvent("idle", "agent-end"); }); @@ -4308,8 +4317,6 @@ sq_piext=$(shell_quote "$STATE/$ID.pi-ext.ts") sq_primeext=$(shell_quote "$STATE/$ID.prime-ext.ts") sq_piturnend=$(shell_quote "$PROJ_ABS/.pi/extensions/fm-primary-turnend-guard.ts") sq_piwatch=$(shell_quote "$PROJ_ABS/.pi/extensions/fm-primary-pi-watch.ts") -sq_primeturnend=$(shell_quote "$PROJ_ABS/.prime/agent/extensions/fm-primary-turnend-guard.ts") -sq_primewatch=$(shell_quote "$PROJ_ABS/.prime/agent/extensions/fm-primary-prime-watch.ts") sq_ompext=$(shell_quote "$STATE/$ID.omp-ext.ts") sq_ompcfg=$(shell_quote "${OMP_WORKER_CFG:-$FM_ROOT/.omp/fm-worker-overlay.yml}") sq_opinput=$(shell_quote "$FM_ROOT/bin/fm-operational-input.sh") @@ -4336,8 +4343,6 @@ LAUNCH=${LAUNCH//__PIEXT__/$sq_piext} LAUNCH=${LAUNCH//__PRIMEEXT__/$sq_primeext} LAUNCH=${LAUNCH//__PITURNEND__/$sq_piturnend} LAUNCH=${LAUNCH//__PIWATCH__/$sq_piwatch} -LAUNCH=${LAUNCH//__PRIMETURNEND__/$sq_primeturnend} -LAUNCH=${LAUNCH//__PRIMEWATCH__/$sq_primewatch} LAUNCH=${LAUNCH//__OMPEXT__/$sq_ompext} LAUNCH=${LAUNCH//__OMPWORKERCFG__/$sq_ompcfg} LAUNCH=${LAUNCH//__OPINPUT__/$sq_opinput} diff --git a/docs/configuration.md b/docs/configuration.md index 81d2bf30b69..9c75cccf5b5 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -309,11 +309,8 @@ The full cmux home label also includes a short hash of the resolved `FM_ROOT` pa claude, codex, opencode, pi, pi-signed, grok, kimi, cursor, and omp are empirically verified for crewmate and secondmate launches; gemini and prime-agent are verified for crewmate and scout launches only, and [README requirements](../README.md#requirements) own the set supported for the primary session. A cursor secondmate or primary runs the tracked project-scope `.cursor/hooks.json` in its own home and must be launched with `--trust`, or no project hook loads; [`docs/supervision-protocols/cursor.md`](supervision-protocols/cursor.md) owns its supervision protocol. Cursor typed-submit confirmation is verified on tmux and Herdr only. -prime-agent runs every session in a detached daemon worker that outlives both the pane and an explicit quit, so teardown (task worktree and secondmate home alike) and every secondmate relaunch retire the worker bound to that directory first ([`bin/fm-prime-agent-lib.sh`](../bin/fm-prime-agent-lib.sh)); without that a home would keep a live session-lock holder and land read-only. -An in-place restart needs no retirement of its own: session-lock liveness asks prime-agent whether the recorded worker still has any client attached AND whether every session it hosts is idle, so a quit worker is reclaimable while an attached or still-working one keeps the lock. -A worker whose pane died MID-TURN therefore keeps the lock on purpose, and an in-place restart does land read-only until that turn finishes; any answer that cannot prove the worker is finished counts as still alive. -A quit pane also classifies dead rather than alive - its reporter identity survives the agent - so secondmate recovery relaunches it instead of skipping it as live. -The discriminator there is the pane's whole process subtree, not which process group holds the terminal: a Ctrl+Z-suspended agent is still a stopped prime-agent process under the pane's shell and stays alive, while a quit pane has no prime-agent process left under it at all. +prime-agent runs every session in a detached daemon worker that outlives both the pane and an explicit quit, so task cleanup retires the worker bound to that task directory first ([`bin/fm-prime-agent-lib.sh`](../bin/fm-prime-agent-lib.sh)); without that a task would keep a live session-lock holder and land read-only. +The worker's liveness and retirement details remain owned by [`bin/fm-prime-agent-lib.sh`](../bin/fm-prime-agent-lib.sh). On Zellij, cmux, and Orca a typed-plane Cursor send (a harness-native invocation or an explicit backend target; ordinary text steers ride the durable inbox and exit 0 at enqueue) lands, but `fm-send` reports delivery unconfirmed and exits non-zero because their shared submit core does not consult the busy footer; [runtime backend verification](verification/runtime-backends.md#cursor-agent-cli) owns the evidence and transcript-state boundary. muse is verified for crewmate and scout launches ONLY, and `fm-spawn.sh` refuses it for a secondmate, because muse ships no usable hook surface for a primary session's turn-end supervision; [`docs/verification/muse.md`](verification/muse.md) owns that evidence. muse also needs a worker-reachable credential before spawning, and the portable fleet path is the `/muse/auth.json` credential stored by `muse login`, because a caller-only `META_API_KEY` does not cross a long-lived backend daemon. diff --git a/docs/verification/prime-agent.md b/docs/verification/prime-agent.md index b452c2ff168..b02ef6e318b 100644 --- a/docs/verification/prime-agent.md +++ b/docs/verification/prime-agent.md @@ -33,7 +33,7 @@ The live guard confirmed the initial turn settled to `idle prime-ext` and create A real tool call changed the adapter classification to `busy prime-ext`. The Herdr agent record simultaneously reported `agent_status=working`. After the tool call completed, the adapter classification returned to `idle prime-ext`. -The extension uses `agent_start` for busy state and holds `agent_end` idle publication when the last assistant message stopped with an error or when pending messages are queued. +The extension uses `agent_start` for busy state and holds `agent_end` idle publication for a short grace window when the last assistant message stopped with an error or when pending messages are queued. A retry start cancels the held error timer. `turn_end` remains a notification touch and never fabricates idle state. The portable regression drives normal completion, error grace, retry, pending-message, and stale-generation cases in `tests/fm-busy-adapter-wiring.test.sh`. @@ -65,7 +65,7 @@ The live guard confirmed detached Prime Agent worker retirement for the temporar ## Scope and still unproven -The live evidence covers the crewmate/scout launch, marker export, provider-qualified flags, project extension loading, semantic busy and idle behavior, retry and pending-message holds, Escape, `/quit`, relaunch, and detached-worker retirement on Prime Agent 0.9.4. +The live evidence covers the crewmate/scout launch, marker export, provider-qualified flags, project extension loading, semantic busy and idle behavior, Escape, `/quit`, relaunch, and detached-worker retirement on Prime Agent 0.9.4. Prime Agent secondmate launches remain refused because its primary supervision protocol is not wired into the session-start renderer and has not been verified end to end. Remote secondmates remain outside this evidence. Primary-session supervision, pane resume, fork, RPC, RLM, and agent-messaging control-plane replacement are not claimed. diff --git a/docs/verification/supervision.md b/docs/verification/supervision.md index ee758a0dd3f..7686479da92 100644 --- a/docs/verification/supervision.md +++ b/docs/verification/supervision.md @@ -550,7 +550,7 @@ The safe command-channel contract is covered without a notification by `tests/fm ## Prime Agent (prime-agent) native delivery, 2026-09-13 -Prime Agent primary supervision uses the tracked `.prime/agent/extensions/fm-primary-prime-watch.ts` and `.prime/agent/extensions/fm-primary-turnend-guard.ts` extensions. -The watcher extension owns continuity and the turn-end extension provides the recovery backstop. +Prime Agent primary supervision remains unproven and outside the crewmate/scout adapter scope. +The tracked primary extensions and protocol are not a verified secondmate launch path, so `bin/fm-spawn.sh` refuses Prime Agent secondmates. The task worker path is verified by `tests/fm-prime-agent-harness.test.sh`, `tests/fm-prime-watch-extension.test.sh`, and `docs/verification/prime-agent.md` on Linux with prime-agent 0.9.4. The exact local validation command was `bin/fm-test-run.sh --jobs 1 tests/fm-prime-agent-harness.test.sh tests/fm-prime-watch-extension.test.sh`, which passed both scripts. diff --git a/tests/fm-busy-adapter-wiring.test.sh b/tests/fm-busy-adapter-wiring.test.sh index fee629be343..3f8a3945bc8 100755 --- a/tests/fm-busy-adapter-wiring.test.sh +++ b/tests/fm-busy-adapter-wiring.test.sh @@ -55,7 +55,7 @@ classify() { # # Node host and fire one lifecycle handler. Modes: agent-start, settle-idle, # settle-continuing, turn-end. drive_pi_ext() { - EXT_PATH="$1" MODE="$2" HERDR_PI_RETRY_GRACE_MS=50 node --input-type=module 2>&1 <<'EOF' + EXT_PATH="$1" MODE="$2" node --input-type=module 2>&1 <<'EOF' import { pathToFileURL } from "node:url"; const mod = await import(pathToFileURL(process.env.EXT_PATH).href); const handlers = {}; @@ -180,7 +180,7 @@ oc_idle() { # } drive_prime_ext() { - EXT_PATH="$1" MODE="$2" node --input-type=module 2>&1 <<'EOF' + EXT_PATH="$1" MODE="$2" HERDR_PI_RETRY_GRACE_MS=50 HERDR_PI_IDLE_DEBOUNCE_MS=50 node --input-type=module 2>&1 <<'EOF' import { pathToFileURL } from "node:url"; const mod = await import(pathToFileURL(process.env.EXT_PATH).href); const handlers = {}; @@ -197,6 +197,11 @@ switch (process.env.MODE) { await handlers["agent_end"]({ messages: [{ role: "assistant", stopReason: "error" }] }, { hasPendingMessages: () => false }); await new Promise((resolve) => setTimeout(resolve, 10)); break; + case "error-expired": + await handlers["agent_start"]({}, {}); + await handlers["agent_end"]({ messages: [{ role: "assistant", stopReason: "error" }] }, { hasPendingMessages: () => false }); + await new Promise((resolve) => setTimeout(resolve, 80)); + break; case "error-retry": await handlers["agent_start"]({}, {}); await handlers["agent_end"]({ messages: [{ role: "assistant", stopReason: "error" }] }, { hasPendingMessages: () => false }); @@ -208,6 +213,27 @@ switch (process.env.MODE) { await handlers["agent_start"]({}, {}); await handlers["agent_end"]({}, { hasPendingMessages: () => true }); break; + case "pending-expired": + await handlers["agent_start"]({}, {}); + await handlers["agent_end"]({}, { hasPendingMessages: () => true }); + await new Promise((resolve) => setTimeout(resolve, 80)); + break; + case "pending-retry": + await handlers["agent_start"]({}, {}); + await handlers["agent_end"]({}, { hasPendingMessages: () => true }); + await new Promise((resolve) => setTimeout(resolve, 10)); + await handlers["agent_start"]({}, {}); + await new Promise((resolve) => setTimeout(resolve, 80)); + break; + case "session-bound": { + const parent = {}; + const child = {}; + await handlers["agent_start"]({}, { sessionManager: parent }); + await handlers["agent_end"]({}, { sessionManager: child, hasPendingMessages: () => false }); + await new Promise((resolve) => setTimeout(resolve, 10)); + await handlers["agent_end"]({}, { sessionManager: parent, hasPendingMessages: () => false }); + break; + } default: throw new Error("unknown mode " + process.env.MODE); } if (process.env.MODE === "turn-end") await new Promise((resolve) => setTimeout(resolve, 200)); @@ -245,6 +271,10 @@ test_prime_agent_extension_semantic_lifecycle() { out=$(classify prime-agent "$id" "$state") [ "$out" = "busy prime-ext" ] || fail "prime-agent error-end must hold busy during retry grace, got '$out'" + out=$(drive_prime_ext "$ext" error-expired) || fail "prime-agent error expiry drive failed: $out" + out=$(classify prime-agent "$id" "$state") + [ "$out" = "idle prime-ext" ] || fail "prime-agent terminal error did not settle idle after grace, got '$out'" + out=$(drive_prime_ext "$ext" error-retry) || fail "prime-agent retry drive failed: $out" out=$(classify prime-agent "$id" "$state") [ "$out" = "busy prime-ext" ] || fail "a retrying prime-agent run must remain busy after a stale error timer, got '$out'" @@ -253,12 +283,24 @@ test_prime_agent_extension_semantic_lifecycle() { out=$(classify prime-agent "$id" "$state") [ "$out" = "busy prime-ext" ] || fail "prime-agent pending messages must hold busy, got '$out'" + out=$(drive_prime_ext "$ext" pending-expired) || fail "prime-agent pending expiry drive failed: $out" + out=$(classify prime-agent "$id" "$state") + [ "$out" = "idle prime-ext" ] || fail "prime-agent pending messages did not debounce to idle, got '$out'" + + out=$(drive_prime_ext "$ext" pending-retry) || fail "prime-agent pending retry drive failed: $out" + out=$(classify prime-agent "$id" "$state") + [ "$out" = "busy prime-ext" ] || fail "prime-agent pending retry did not cancel debounced idle, got '$out'" + + out=$(drive_prime_ext "$ext" session-bound) || fail "prime-agent session binding drive failed: $out" + out=$(classify prime-agent "$id" "$state") + [ "$out" = "idle prime-ext" ] || fail "prime-agent child session event changed parent state, got '$out'" + out=$(drive_prime_ext "$ext" agent-start) || fail "prime-agent second agent_start drive failed: $out" "$ROOT/bin/fm-busy-event.sh" arm "$state" "$id" >/dev/null out=$(drive_prime_ext "$ext" agent-end) || fail "prime-agent stale agent_end drive failed: $out" out=$(classify prime-agent "$id" "$state") [ "$out" = "busy fm-spawn" ] || fail "a stale prime-agent extension event must not change state, got '$out'" - pass "prime-agent extension reports semantic busy/idle, holds retries and queued messages, and keeps turn_end as notification" + pass "prime-agent extension binds sessions, holds retries, debounces queued messages, and keeps turn_end as notification" } test_opencode_plugin_semantic_lifecycle() { diff --git a/tests/fm-prime-agent-signals-live-e2e.test.sh b/tests/fm-prime-agent-signals-live-e2e.test.sh index 5fb1dc2a986..70e53d23212 100755 --- a/tests/fm-prime-agent-signals-live-e2e.test.sh +++ b/tests/fm-prime-agent-signals-live-e2e.test.sh @@ -31,6 +31,9 @@ HOME_DIR="$LAB/home" PROJECT="$LAB/project" WT="$LAB/worktree" ID=prime-agent-live +PROVIDER=openai-codex +MODEL=gpt-5.6-terra +EFFORT=low FAKEBIN= LAUNCH_LOG="$LAB/launch.log" SESSION=$("$LAB_HELPER" name prime-adapter-solid) @@ -60,11 +63,19 @@ FAKEBIN=$(make_spawn_fakebin "$LAB/fake" prime-agent) # Fake tmux lets production fm-spawn render the exact extension and busy record. # The real process is launched below in the isolated Herdr pane instead. out=$(FM_FAKE_LAUNCH_LOG="$LAUNCH_LOG" fm_test_run_spawn "$HOME_DIR" "$WT" "$FAKEBIN" "$ID" "$PROJECT" \ - --harness prime-agent --provider openai-codex --model gpt-5.6-terra --effort low \ + --harness prime-agent --provider "$PROVIDER" --model "$MODEL" --effort "$EFFORT" \ --mode direct-PR --yolo off 2>&1) || fail "production spawn generation failed: $out" [ -f "$HOME_DIR/state/$ID.prime-ext.ts" ] || fail "production spawn did not generate the Prime Agent extension" LAUNCH=$(sed "s#'$FAKEBIN/prime-agent'#'$PRIME_AGENT'#" "$LAUNCH_LOG") [ "$LAUNCH" != "$(cat "$LAUNCH_LOG")" ] || fail "could not replace the fake Prime Agent executable in the generated launch" +printf '%s\n' "$LAUNCH" | grep -Fq -- "--provider '$PROVIDER'" \ + || fail "generated launch omitted the requested provider: $LAUNCH" +printf '%s\n' "$LAUNCH" | grep -Fq -- "--model '$MODEL'" \ + || fail "generated launch omitted the requested model: $LAUNCH" +model_version=${MODEL#gpt-} +model_major=${model_version%-*} +model_name=${model_version##*-} +expected_model="GPT-${model_major} ${model_name^}" "$LAB_HELPER" provision "$SESSION" || fail "could not provision isolated Herdr lab" WS=$("$LAB_HELPER" run "$SESSION" workspace create --cwd "$WT" --label prime-agent-live --no-focus) \ @@ -77,14 +88,17 @@ PANE=$(printf '%s' "$WS" | jq -er '.result.root_pane.pane_id') \ for i in $(seq 1 120); do screen=$("$LAB_HELPER" run "$SESSION" pane read "$PANE" --source recent --lines 200 2>/dev/null || true) if printf '%s\n' "$screen" | grep -Eq 'version[[:space:]]+v[0-9]+' \ - && printf '%s\n' "$screen" | grep -Eq 'model[[:space:]]+[^[:space:]—]'; then + && printf '%s\n' "$screen" | grep -Fq "$expected_model" \ + && printf '%s\n' "$screen" | grep -Fq "$EFFORT"; then break fi sleep 0.5 done printf '%s\n' "$screen" | grep -Eq 'version[[:space:]]+v[0-9]+' || fail "Prime Agent did not render its startup screen (binary=$PRIME_AGENT): $screen" -printf '%s\n' "$screen" | grep -Eq 'model[[:space:]]+[^[:space:]—]' \ - || fail "generated launch did not render a selected model; launch=$LAUNCH screen=$screen" +printf '%s\n' "$screen" | grep -Fq "$expected_model" \ + || fail "generated launch did not render the requested model $expected_model; launch=$LAUNCH screen=$screen" +printf '%s\n' "$screen" | grep -Fq "$EFFORT" \ + || fail "generated launch did not render the requested effort $EFFORT; launch=$LAUNCH screen=$screen" printf '%s\n' "$screen" | grep -Eq 'version[[:space:]]+v[0-9]+([.][0-9]+)+' \ || fail "generated launch did not render a numeric version; launch=$LAUNCH screen=$screen" pass "Prime Agent rendered the production model, provider, and thinking launch" From 2d4e246651e55541ec8c2b3c4ad3477286d529d0 Mon Sep 17 00:00:00 2001 From: Eduard Ionel STAN Date: Mon, 14 Sep 2026 17:56:35 +0200 Subject: [PATCH 14/15] test: make prime session isolation regression discriminating --- tests/fm-busy-adapter-wiring.test.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/fm-busy-adapter-wiring.test.sh b/tests/fm-busy-adapter-wiring.test.sh index 3f8a3945bc8..876a4bae7e2 100755 --- a/tests/fm-busy-adapter-wiring.test.sh +++ b/tests/fm-busy-adapter-wiring.test.sh @@ -231,7 +231,6 @@ switch (process.env.MODE) { await handlers["agent_start"]({}, { sessionManager: parent }); await handlers["agent_end"]({}, { sessionManager: child, hasPendingMessages: () => false }); await new Promise((resolve) => setTimeout(resolve, 10)); - await handlers["agent_end"]({}, { sessionManager: parent, hasPendingMessages: () => false }); break; } default: throw new Error("unknown mode " + process.env.MODE); @@ -293,7 +292,7 @@ test_prime_agent_extension_semantic_lifecycle() { out=$(drive_prime_ext "$ext" session-bound) || fail "prime-agent session binding drive failed: $out" out=$(classify prime-agent "$id" "$state") - [ "$out" = "idle prime-ext" ] || fail "prime-agent child session event changed parent state, got '$out'" + [ "$out" = "busy prime-ext" ] || fail "prime-agent child session event changed parent state, got '$out'" out=$(drive_prime_ext "$ext" agent-start) || fail "prime-agent second agent_start drive failed: $out" "$ROOT/bin/fm-busy-event.sh" arm "$state" "$id" >/dev/null From 46b9c03cf0e603fe94800f16c5d7303143f952d2 Mon Sep 17 00:00:00 2001 From: Eduard Ionel STAN Date: Mon, 14 Sep 2026 18:27:57 +0200 Subject: [PATCH 15/15] fix: silence unused live guard counters --- tests/fm-prime-agent-signals-live-e2e.test.sh | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/tests/fm-prime-agent-signals-live-e2e.test.sh b/tests/fm-prime-agent-signals-live-e2e.test.sh index 70e53d23212..ac6dbb4d7c1 100755 --- a/tests/fm-prime-agent-signals-live-e2e.test.sh +++ b/tests/fm-prime-agent-signals-live-e2e.test.sh @@ -85,7 +85,7 @@ PANE=$(printf '%s' "$WS" | jq -er '.result.root_pane.pane_id') \ "$LAB_HELPER" run "$SESSION" pane run "$PANE" "$LAUNCH" >/dev/null \ || fail "could not launch the generated Prime Agent command" -for i in $(seq 1 120); do +for _ in $(seq 1 120); do screen=$("$LAB_HELPER" run "$SESSION" pane read "$PANE" --source recent --lines 200 2>/dev/null || true) if printf '%s\n' "$screen" | grep -Eq 'version[[:space:]]+v[0-9]+' \ && printf '%s\n' "$screen" | grep -Fq "$expected_model" \ @@ -103,7 +103,7 @@ printf '%s\n' "$screen" | grep -Eq 'version[[:space:]]+v[0-9]+([.][0-9]+)+' \ || fail "generated launch did not render a numeric version; launch=$LAUNCH screen=$screen" pass "Prime Agent rendered the production model, provider, and thinking launch" -for i in $(seq 1 120); do +for _ in $(seq 1 120); do [ "$(fm_busy_classify tmux fake:w prime-agent "$ID" "$HOME_DIR/state")" = "idle prime-ext" ] && break sleep 0.5 done @@ -117,16 +117,14 @@ send() { "$LAB_HELPER" run "$SESSION" pane send-keys "$PANE" enter >/dev/null || return 1 } wait_busy() { - local i - for i in $(seq 1 80); do + for _ in $(seq 1 80); do [ "$(fm_busy_classify tmux fake:w prime-agent "$ID" "$HOME_DIR/state")" = "busy prime-ext" ] && return 0 sleep 0.5 done return 1 } wait_idle() { - local i - for i in $(seq 1 100); do + for _ in $(seq 1 100); do [ "$(fm_busy_classify tmux fake:w prime-agent "$ID" "$HOME_DIR/state")" = "idle prime-ext" ] && return 0 sleep 0.5 done @@ -149,7 +147,7 @@ printf '%s\n' "$screen" | grep -q 'Operation aborted' || fail "Escape did not ab pass "Prime Agent $PRIME_VERSION cancels a running turn with one Escape" send '/quit' || fail "could not submit /quit" -for i in $(seq 1 60); do +for _ in $(seq 1 60); do info=$("$LAB_HELPER" run "$SESSION" pane process-info --pane "$PANE" 2>/dev/null || true) printf '%s\n' "$info" | jq -e '.result.process_info.foreground_processes[0].name == "bash"' >/dev/null 2>&1 && break sleep 0.5 @@ -160,7 +158,7 @@ pass "Prime Agent $PRIME_VERSION exits cleanly and leaves the detached worker fo "$LAB_HELPER" run "$SESSION" pane run "$PANE" "$LAUNCH" >/dev/null \ || fail "could not relaunch Prime Agent in the same pane" -for i in $(seq 1 120); do +for _ in $(seq 1 120); do screen=$("$LAB_HELPER" run "$SESSION" pane read "$PANE" --source recent --lines 200 2>/dev/null || true) if printf '%s\n' "$screen" | grep -Eq 'version[[:space:]]+v[0-9]+'; then break; fi sleep 0.5 @@ -169,12 +167,12 @@ printf '%s\n' "$screen" | grep -Eq 'version[[:space:]]+v[0-9]+' || fail "Prime A pass "Prime Agent $PRIME_VERSION relaunches in the same Herdr pane" send '/quit' || fail "could not submit the cleanup quit" -for i in $(seq 1 60); do +for _ in $(seq 1 60); do info=$("$LAB_HELPER" run "$SESSION" pane process-info --pane "$PANE" 2>/dev/null || true) printf '%s\n' "$info" | jq -e '.result.process_info.foreground_processes[0].name == "bash"' >/dev/null 2>&1 && break sleep 0.5 done -for i in $(seq 1 60); do +for _ in $(seq 1 60); do fm_prime_agent_stop_sessions_under "$WT" >/dev/null 2>&1 || true left=$(fm_prime_agent_session_ids_under "$(CDPATH='' cd -- "$WT" && pwd -P)" resident 2>/dev/null || true) [ -z "$left" ] && break