Skip to content

feat: support Cursor Agent CLI as a primary harness - #2305

Merged
kunchenguid merged 25 commits into
mainfrom
fm/fm-cursor-primary-build-r1
Aug 13, 2026
Merged

kunchenguid merged 25 commits into
mainfrom
fm/fm-cursor-primary-build-r1

Conversation

@kunchenguid

@kunchenguid kunchenguid commented Aug 13, 2026 •

Copy link
Copy Markdown
Owner

Intent

Make Cursor Agent CLI usable as a firstmate PRIMARY harness, not just a crewmate/scout adapter. This is firstmate SHARED, TRACKED material touching the core supervision surface: the turn-end guard, the watcher/supervision protocol, session start, and the away-mode daemon.

The authoritative spec was a completed feasibility scout report (data/fm-cursor-primary-feasibility-s1/report.md) that had already located every primitive with file:line references, live evidence, exact bundle offsets, the config schema, and a gap list G1-G9. The instruction was to IMPLEMENT that report rather than re-investigate or redesign it, and to escalate rather than silently diverge if the report turned out to be wrong about a concrete fact.

Captain-ordered sequence, done in this order:

  1. G1/G2/G9 - ship a TRACKED project-scope .cursor/hooks.json registering stop and sessionStart (plus preToolUse for the watcher-arm seatbelt). Add a cursor mode to the turn-end guard that, when the shared predicate returns 2, prints {"followup_message":"<the U+2063 FIRSTMATE_OP: turn-end-guard follow-up>"} on stdout and exits 0, and NEVER exits 2, because the report proved exit 2 is a silent no-op on cursor's stop step. Self-bound the follow-up loop on BOTH loop_count from the stop payload AND a loop_limit in the registration - both, not either, because a naive always-follow-up hook loops forever. This step alone had to deliver "no turn ends blind" for a cursor primary.
  2. G4/G3 - register sessionStart to run the digest through firstmate's run-tier session-start wrapper, emitting the digest as additional_context, supplying --source ourselves because cursor's payload has no Claude-style source field, with timeout 180 so it sits above bin/fm-session-start.sh's own 120s budget. Add docs/supervision-protocols/cursor.md using the park model the report recommended, and a cursor branch in bin/fm-supervision-instructions.sh. The original brief also asked to route cursor's native preCompact for the compact case; see the SUPERSEDED SCOPE section below - that half has been CUT by explicit owner decision and is NOT part of this change.
  3. G5, the one substantive gap the report identified - teach the away-mode path the same idle-to-busy / "ctrl+c to stop" transition acknowledgement the crew steer path already uses, keyed on the token transition rather than the composer-empty verdict cursor never produces. The explicit instruction was to genuinely TRY the ack, and if a primitive truly could not work, to STOP and escalate the concrete gap with evidence rather than papering over it or quietly shipping cursor-primary as not-away-mode-capable.
  4. G6 - lift the cursor launch refusals LAST, only after steps 1-3 landed and live evidence was recorded in docs/verification/supervision.md. Do not lift the --secondmate refusals early.
    Also add cursor to the primary-tier tables and adapter facts so the always-loaded contract records that cursor now HAS a hooks system and can be a primary; the report explicitly framed this as an ADDITION rather than a correction, since no existing line was factually wrong (they were all scoped to "has been verified").

Binding constraints accepted for this work: firstmate's coding guidelines apply (one-owner rule for contracts, one sentence per line in tracked Markdown, plain dash never an em dash, shellcheck-clean bin scripts via bin/fm-lint.sh, no agent co-author on commits). Tests must exercise behavior through an executable interface and must never assert implementation source bytes. The cursor stop and sessionStart hooks are HARNESS-DEPENDENT checks, so they required BOTH a portable tests/ regression using real processes with no harness installed AND a live-harness-optin guard in the bin/fm-test-run.sh family that is env-gated, self-skipping, and fails naming the harness and version - proven against the REAL cursor-agent, never a stub - plus dated per-harness evidence in docs/verification/supervision.md and docs/verification/runtime-backends.md. All live validation had to run in an isolated throwaway firstmate home on a separate tmux server, never against the live home or the fleet's default tmux/herdr session, and hooks were never to be installed at user or global scope because a global hook fires inside every live cursor crew agent in the fleet.

SUPERSEDED SCOPE - READ THIS BEFORE FLAGGING ANYTHING AS MISSING. The preCompact staged-digest feature has been REMOVED from this change by an explicit, current decision of the repository owner, and deferred to a clean follow-up. This is an accepted exclusion, not an omission, not an oversight, and not a regression. Do NOT re-implement it, do NOT restore bin/fm-precompact-cursor.sh or any equivalent adapter, do NOT re-register preCompact in .cursor/hooks.json, and do NOT reintroduce any staged-context path in bin/fm-turnend-guard-cursor.sh. A regression in tests/fm-cursor-primary.test.sh deliberately asserts that preCompact stays UNREGISTERED; that assertion encodes the intended contract and must not be weakened or deleted.

Why it was cut: an earlier review of this same branch surfaced two ask-user concurrency findings in that path - a superseded park could still deliver a duplicate follow-up, and an in-flight staged claim could strand the required post-compaction digest indefinitely. Each attempt to close them enlarged a critical section inside a hook that Cursor AWAITS at the turn boundary, where blocking is the most dangerous failure available. Native preCompact firing was also never observed, because a real compaction could not be forced in the isolated session, so the surface had no empirical basis to justify that risk. The owner therefore directed shipping the proven core only.

The shipping scope of this change is exactly three things, all live-verified against the real cursor-agent: the turn-end follow-up park, the run-tier session start, and away-mode escalation delivery. Cursor's compaction surface is recorded as DEFERRED and uncovered, in the same sense as the Codex interactive TUI, with the static reason stated: preCompact can return only user_message and is absent from Cursor's additional_context step set, so it cannot inject a digest and needs its own design. A cursor primary therefore does not re-emit its digest after a compaction, and that is the intended, documented behavior of this change.

Decisions and findings made while doing the work that a reviewer reading only the diff would not know:

  • Step 3 was solved at the ROOT cause instead of the transition-ack path the report proposed, and the result is FULL away-mode parity rather than a documented gap. The report was right that cursor's tmux composer verdict is unknown, but that is true only of the CURSOR-ANCHORED read: cursor parks its terminal cursor below its footer, so tmux's cursor row is not a composer locator. Read cursorlessly - the same rule herdr, zellij, cmux, and orca already use for every harness - the same live capture classifies correctly as empty when idle and pending with real typed text. bin/fm-tmux-lib.sh therefore reclassifies a pane only when it can prove the pane's foreground process is genuinely Cursor, via the existing single owner bin/fm-cursor-lib.sh, so the strict blank-cursor-row posture stays in force for every other harness and a dead shell still never reads empty. That restored a genuine composer-empty proof and the away-mode daemon needed NO cursor-specific branch at all. Verified live: bin/fm-supervise-daemon.sh's own inject_msg into a real cursor pane returned 0 and the pane processed the typed escalation.
  • Two defects were found by the live run that the report did not predict, and both are fixed here. First, bin/fm-session-lock-lib.sh could not locate cursor in the process ancestry, so EVERY cursor session start refused the fleet lock with "cannot locate harness process in ancestry" and produced a read-only digest; cursor's identity is not expressible as a command-name pattern (its installed names are cursor-agent and the far-too-generic legacy alias agent, and it runs as a bundled node script), so the lib now delegates to bin/fm-cursor-lib.sh rather than widening the name regex. Second, fm_supervision_model classified cursor as persistent, so the mid-turn pull guard reported WATCHER DOWN between turns even with a beacon seconds old; cursor's park runs the watcher only between turns, exactly like Claude's Stop auto-arm, so cursor is now classified autoarm, including the FM_SUPERVISION_MODEL value baked into a secondmate launch.
  • A hazard this change would otherwise have introduced was found and closed: cursor also loads /.claude/settings.json, so a cursor primary in a firstmate checkout fires BOTH registrations for every event cursor's Claude-compatibility map covers, which would run session start twice and evaluate each PreToolUse seatbelt twice. bin/fm-hook-host-lib.sh lets each tracked Claude-shaped entrypoint stand down on a cursor-delivered payload. The predicate deliberately reads the delivered payload's own cursor_version and NOT the environment, because cursor exports CURSOR_INVOKED_AS, CURSOR_PROJECT_DIR, and CURSOR_VERSION into every child process, so an env guard would also fire inside a Claude session started by hand from a cursor pane and would silently disable Claude's own supervision - the exact hazard docs/turnend-guard.md already records for GROK_SESSION_ID. Claude-shaped Stop does not currently fire under cursor but is guarded anyway, because cursor has no asyncRewake and a future build firing it would run bin/fm-claude-stop-autoarm.sh synchronously inside cursor's stop step and hold that turn open for its multi-hour timeout, which is the wedge grok 1.0.0 produced.
  • Supersession is a deliberate addition beyond the report's gap list, driven by a live finding: a captain message typed while the hook is parked is accepted and runs its turn immediately, but cursor does NOT terminate the parked hook, so its follow-up is still delivered when the park finally closes. Without handling, every captain message during a park would leak one process and one duplicate wake. state/.cursor-park-owner is a generation baton so the newest stop wins and a superseded park stands down without emitting.
  • The two loop bounds nest deliberately rather than duplicating each other: the registered loop_limit (200) is cursor's own ceiling and the only bound that still holds if the adapter is broken or replaced, while FM_CURSOR_TURNEND_LOOP_CEILING (180) sits below it so firstmate's bound bites first and can emit one final loud notice instead of supervision going silently dark at cursor's ceiling. A delivered wake is productive work and resets the separate bounded repair-nag budget; only consecutive unproductive nags consume it.
  • preCompact staging was built, then withdrawn under the owner decision recorded in SUPERSEDED SCOPE above. The removal commit is deliberate and complete: adapter, registration, staged path in the park, and tests, with every doc owner updated to describe the surface as deferred rather than shipped.
  • A third refusal the report's gap list missed was also lifted, in bin/fm-remote-secondmate-control.sh, so the remote path does not contradict the local one.
  • Two pre-existing tests asserted shellcheck cleanliness with a bare shellcheck call, a second and weaker copy of the lint definition that bin/fm-lint.sh owns (it omits --external-sources). They broke the moment these checkers sourced a shared library, and now delegate to that single owner instead. The existing test asserting that a cursor secondmate spawn is refused was replaced with one asserting the new contract: --trust so the home's project hooks load at all, its own home pinned as the workspace, and the autoarm supervision model inherited across the launch.
  • Deliberately NOT fixed here, by explicit captain decision: tests/fm-calm-pi-extension.test.sh fails with "/export did not complete while calm mode was on". That failure reproduces on a clean clone at the unmodified merge base 4930d2c, so it is pre-existing and unrelated to this change; fixing it would be scope creep and the captain will file it separately.

Delivery: mode=no-mistakes with yolo OFF, so the captain merges. Any ask-user finding must be escalated rather than answered here. The PR must state that homes need a self-update after merge because this changes the running primary supervision surface, and must state explicitly that cursor primary away-mode support is COMPLETE rather than partial.

What Changed

  • Register project-scoped Cursor hooks for run-tier session start, pre-tool guards, and bounded stop-hook watcher parking, enabling primary and secondmate operation.
  • Add Cursor-aware process, session-lock, supervision, and tmux composer handling so Cursor primary away-mode escalation support is complete.
  • Add portable and opt-in live coverage plus primary-harness documentation, while keeping compaction refresh explicitly deferred; homes need a self-update after merge because the running primary supervision surface changed.

Risk Assessment

⚠️ Medium: The implementation appears intent-conformant and the prior documentation overclaim is corrected, but the change remains a broad, concurrency-sensitive expansion of core supervision and harness lifecycle behavior.

Testing

The focused process-level regressions and manual protocol probe validated Cursor turn-end parking, loop bounds and supersession, session-start context, composer/away-mode classification, session locking, and secondmate launch behavior. The credentialed real-Cursor guard self-skipped as designed; it was not opted in because it documents Cursor user-data writes outside the permitted worktree boundary. No baseline test commands were supplied, and the worktree remained clean.

Evidence: Cursor primary executable protocol transcript
Cursor primary executable protocol probe
stop_exit=0
stop_output={
  "followup_message": "⁣FIRSTMATE_OP: v1 watcher: firstmate watcher wake - one supervision event needs a handling turn now.\nstale: product-probe requires attention\n\nRun bin/fm-wake-drain.sh first, handle the wake, then run its exact WAKE_ACK_REQUIRED --ack-through command. Until that post-handling acknowledgement, interruption leaves the wake durable for idempotent re-handling. This stop hook owns watcher continuity: when the handling turn ends, the next needed cycle parks automatically - do NOT run bin/fm-watch-arm.sh after an ordinary wake."
}
stop_followup_kind=watcher
stop_followup_mentions_wake=true
sessionStart_output={
  "additional_context": "FIRSTMATE DIGEST: captain marker CURSOR_PRIMARY_OK"
}
sessionStart_context=FIRSTMATE DIGEST: captain marker CURSOR_PRIMARY_OK
preCompact_registered=false
Evidence: Targeted Cursor primary regression transcript
FM_TEST_BEGIN 2026-08-13T17:28:19Z tests/fm-cursor-primary.test.sh family=watcher-wake-lock expected_gate_skip=none
ok - fm-turnend-guard: Cursor payload is inert without --cursor and blocks with it
ok - fm-turnend-guard: a non-Cursor payload keeps blocking
ok - fm-claude-stop-autoarm: inert on a Cursor-delivered payload
ok - fm-sessionstart-run: inert on a Cursor payload, unchanged otherwise
ok - fm-arm-pretool-check: Cursor duplicate allows, --cursor denies in Cursor's own shape
ok - fm-cd-pretool-check: Cursor duplicate allows, --cursor denies in Cursor's own shape
ok - cursor park: silent no-op when no supervision is needed
ok - cursor park: an actionable close is delivered as one watcher-kind follow-up
ok - cursor park: always exits 0, even when supervision is genuinely down
ok - cursor park: the repair nag is bounded and then goes quiet
ok - cursor park: a repair nag is emitted only after its budget persists
ok - cursor park: a delivered wake resets the bounded repair budget
ok - cursor park: the loop_count ceiling warns exactly once, then stops the loop
ok - cursor park: an older park stands down after a newer stop claim
ok - cursor park: the newest stop exclusively owns a concurrent commit
ok - cursor park: a superseded park cannot consume repair budget
ok - cursor park: inert while away mode is active
ok - cursor park: an away-mode transition wins before follow-up commit
ok - cursor park: inert when this session does not hold the home lock
ok - cursor park: session takeover stops polling without output or state mutation
ok - cursor park: inert inside a child crewmate worktree
ok - cursor park: malformed payloads fail open without arming
ok - fm-sessionstart-cursor: sessionStart injects context
ok - fm-sessionstart-cursor: silent inside a child crewmate worktree
ok - cursor registration: covers every primary event with a bounded stop loop
ok - cursor bounds nest: firstmate's default ceiling stops the loop before Cursor's loop_limit does
FM_TEST_END 2026-08-13T17:29:27Z tests/fm-cursor-primary.test.sh exit=0 duration_ms=67997 gate_skip=false
FM_TEST_BEGIN 2026-08-13T17:29:27Z tests/fm-tmux-agent-liveness.test.sh family=backend-dispatch expected_gate_skip=none
ok - tmux liveness: a harness-named foreground process classifies alive
ok - tmux liveness: muse's version-suffixed muse-bin-<version> classifies alive
ok - tmux liveness: unrelated muse-containing command names stay ambiguous
ok - tmux liveness: a version-named executable under a harness install path classifies alive
ok - tmux liveness: a version-named executable under a decoy path stays ambiguous
ok - tmux liveness: a process neither name source attributes stays ambiguous rather than inventing an agent
ok - tmux liveness: a launcher whose own identity reads as a bare shell classifies alive from its harness child
ok - tmux liveness: an idle shell pane classifies dead
ok - tmux liveness: a harness-named background process in an idle pane still classifies dead
ok - tmux liveness: an absent window classifies missing rather than inheriting tmux's active-window fallback
ok - cursor composer: an idle Cursor pane reads empty even though the cursor row is blind
ok - cursor composer: real typed text still reads pending, so the injection guard holds
ok - cursor composer: an identical screen stays unknown when the pane is not Cursor
ok - cursor composer: a stale Cursor screen over a dead shell never reads empty
FM_TEST_END 2026-08-13T17:29:30Z tests/fm-tmux-agent-liveness.test.sh exit=0 duration_ms=3697 gate_skip=false
FM_TEST_BEGIN 2026-08-13T17:29:30Z tests/fm-session-lock-ancestry.test.sh family=watcher-wake-lock expected_gate_skip=none
ok - session-lock: a version-named Claude Code session is identified from its install path and argv[0]
ok - session-lock: ordinary script paths under a harness directory are not harness processes
ok - session-lock: ownership stops at the first non-harness gap above the contiguous run
ok - session-lock: a live version-named session holding the lock is not mistaken for a stale owner
ok - session-lock e2e: a version-named session claims the home and arms supervision
ok - session-lock e2e: a session parented by a harness-named daemon claims the home and arms supervision
ok - session-lock e2e: a version-named session under a harness-named daemon keeps its own lock
FM_TEST_END 2026-08-13T17:29:35Z tests/fm-session-lock-ancestry.test.sh exit=0 duration_ms=4630 gate_skip=false
FM_TEST_BEGIN 2026-08-13T17:29:35Z tests/fm-secondmate-harness.test.sh family=secondmate expected_gate_skip=none
ok - A1 fm-harness.sh secondmate resolves the fallback chain; crew mode unchanged
ok - fm-harness detects only Cursor Agent CLI's exact invocation marker
ok - C1 fm-harness.sh secondmate-model/secondmate-effort resolve the optional tokens; bare harness stays empty (backward-compat)
ok - pi-signed identity: authoritative launch selection distinguishes shared wrapper ancestry
ok - harness identity: dash-leading ps command names are basename operands, not options
ok - B1 propagate_inheritable_config: copy, idempotence, convergence, absence-mirror, exclusion, no-op, skip diagnostics
ok - B2 spawn: secondmate runs the secondmate harness; its home inherits declared config
ok - B3 spawn: an absent secondmate-harness falls back to the crew harness (backward-compat)
ok - B4 spawn: no config at all -> own harness and no propagation side effects
ok - B5 spawn: an explicit per-spawn harness arg overrides config/secondmate-harness
ok - B6 spawn: an unverified resolved secondmate harness is refused (guard intact)
ok - Cursor is accepted for secondmates and launches with the contract its park needs
ok - B5b spawn: FM_BACKEND wins over inherited config/backend
ok - B5c spawn: explicit --backend wins over FM_BACKEND and inherited config/backend
ok - C2 spawn: a bare harness-only secondmate-harness file launches with no model/effort flag (backward-compat)
ok - C3 spawn: config/secondmate-harness's model token threads --model into the launch and meta
ok - C4 spawn: config/secondmate-harness's model+effort tokens thread into the launch and meta
ok - C5 spawn: an explicit --model overrides config/secondmate-harness's model token; the file's effort token still applies
ok - C6 spawn: an explicit --effort overrides config/secondmate-harness's effort token; the file's model token still applies
ok - C7 spawn: an explicit --harness starts with clean model/effort defaults
ok - C8 spawn: an explicit --harness still honors explicit model/effort flags
ok - C9 spawn: secondmate launch pins supervision to its own harness
ok - C9 spawn: the harness fallback chain still resolves with no tokens; crew/scout launches are unaffected by this feature
ok - B7 bootstrap sweep pushes, re-converges, and mirrors absence; never inherits secondmate-harness
ok - B8 bootstrap sweep propagates config even when the home's tracked files are already current
ok - B9 bootstrap sweep defers new inherited config until the home ignores it
ok - B10 bootstrap sweep materializes and inherits the startup-memory default while fast-forwarding
ok - B12b backend inheritance: present values and primary absence converge exactly
ok - B12c presentation inheritance: the primary default converges on, and only an explicit opt-out propagates off
ok - B11 bootstrap sweep surfaces config propagation failures
ok - B11 bootstrap rereads completed config writes after partial propagation
ok - B12 config-push propagates via shared live discovery, reports items, rereads on change only, and does not fast-forward
ok - B13 config-push reports dirty, non-allowing, and invalid homes without failing warnings-only runs
ok - B14 config-push exits nonzero on real propagation errors
ok - B14 config-push rereads completed config writes after partial propagation
ok - B15 config reread is per-home, exact-byte, ordered, and pointer-only
ok - B16 config reread isolation, ABSENT, generation safety, send failure, and retry
ok - B20 config reread publication failures retain exact generations for retry
ok - B21 config reread instruction-write failures retain exact retry generations
ok - B21 config reread preserves exact bytes when temporary adoption also fails
ok - B21 config reread serializes concurrent propagation and delivery
ok - B22 full config reread retry queues drain before new publication
ok - B23 mixed config reread delivery failures still bound sent history
ok - B26 config reread delivery stops after the oldest failed generation
ok - B17 config reread skips unchanged homes and reads destination post-write bytes
ok - B18 bootstrap config reread path works; spawn flexibility remains defaults-only
ok - B19 bootstrap respawns before inherited-config reread
ok - B25 spawn quarantines stale rereads without blocking relaunch
ok - B24 bootstrap detect-only mode remains filesystem read-only
# all fm-secondmate-harness tests passed
FM_TEST_END 2026-08-13T17:32:15Z tests/fm-secondmate-harness.test.sh exit=0 duration_ms=160056 gate_skip=false
FM_TEST_BEGIN 2026-08-13T17:32:15Z tests/fm-turnend-guard.test.sh family=watcher-wake-lock expected_gate_skip=none
ok - fm_supervision_unhealthy: false with no state/*.meta at all
ok - fm_supervision_unhealthy: true with in-flight task and no beacon ever
ok - fm_supervision_unhealthy: true with in-flight task and a beacon far outside the grace window
ok - fm_supervision_unhealthy: false with in-flight task and a fresh beacon
ok - fm_supervision_status: FM_SUP_QUEUE_PENDING tracks state/.wake-queue
ok - fm_supervision_needed: X-mode relay poll needs supervision
ok - fm_supervision_unhealthy: source-only home needs supervision
ok - fm-turnend-guard: silent no-op with nothing in flight
ok - fm-turnend-guard: blocks when a fresh beacon has no live watcher lock
ok - fm-turnend-guard: non-Claude path blocks a source-only home
ok - fm-turnend-guard: blocks on a dead watcher lock even when the beacon is fresh
ok - fm-turnend-guard: silent no-op with a live watcher lock and fresh beacon
ok - fm-turnend-guard: healthy non-Claude harness paths ignore Claude episode contention
ok - fm-turnend-guard: blocks on a live watcher lock with an ancient beacon
ok - fm-turnend-guard: blocks with the exact required reason in the primary when unhealthy
ok - fm-turnend-guard: blocks from active FM_HOME state, not only repo-root state
ok - fm-turnend-guard: X-mode repair reason sources the cadence config
ok - fm-turnend-guard: X-mode-only supervision remains guarded in default mode
ok - fm-turnend-guard: ignores stale repo-root state when FM_HOME is set
ok - fm-turnend-guard: uses FM_STATE_OVERRIDE ahead of FM_HOME/state
ok - fm-turnend-guard: stop_hook_active=true always allows the stop (never blocks twice in one turn)
ok - fm-turnend-guard: blocks a blind turn end in a secondmate's own home (.fm-secondmate-home no longer excludes it)
ok - fm-turnend-guard: idle-by-default - silent in a secondmate home with nothing in flight
ok - fm-turnend-guard: stop_hook_active=true allows the stop in a secondmate home (never blocks twice in one turn)
ok - fm-turnend-guard: secondmate deferred-death recovery - silent while watched, forces re-arm once the watcher exits
ok - fm-turnend-guard: inert in a secondmate's own child worktree (linked git worktree) even when unhealthy
ok - fm-turnend-guard: blocks a blind turn end in a treehouse-leased LINKED secondmate home (marker force-include)
ok - fm-turnend-guard: an invalid (empty) marker cannot spoof inclusion; linked worktree stays exempt
ok - fm-turnend-guard: a non-ASCII marker cannot spoof inclusion; linked worktree stays exempt
ok - fm-turnend-guard: inert in a crewmate/scout task worktree (linked git worktree) even when unhealthy
ok - fm-turnend-guard: fails open (never blocks) when jq is missing
ok - fm-turnend-guard: silent no-op on empty stdin
ok - fm-turnend-guard: runs well under the generous timing margin (0s)
ok - fm-turnend-guard-grok: forces one explicitly marked same-session resume when the shared predicate blocks
ok - fm-turnend-guard-grok: legacy environment loop guard prevents a nested resume loop
ok - fm-turnend-guard-grok: native false delegates blocking feedback with zero resume processes
ok - fm-turnend-guard-grok: native true remains bounded and starts no resume process
ok - fm-turnend-guard-grok: both spellings are typed and camelCase has deterministic precedence
ok - fm-turnend-guard-grok: malformed, invalidly typed, and missing-prerequisite payloads start neither path
ok - fm-turnend-guard-grok: missing jq and no-supervision-needed stops stay silent and bounded
ok - tracked .claude/settings.json entries: 5 inert under grok, the documented subagent exception still armed, all live under Claude
ok - .codex/hooks.json: Stop hook uses hook process root when payload cwd is outside
ok - .codex/hooks.json: Stop hook ignores nested git root guard scripts
ok - .opencode primary plugin: guard path is anchored to worktree, not directory
ok - .pi primary extension: no-tool and multi-tool runs each inject exactly one guard follow-up
ok - .pi primary extension: delivery failure resets the logical-run latch
ok - fm-turnend-guard --claude: re-blocks a loop-guarded stop while unhealthy and unclaimed (incident regression)
ok - fm-turnend-guard --claude: X-mode-only homes re-block when auto-arm recovery is absent
ok - fm-turnend-guard --claude: a live arming epoch advances once and repeated observation is idempotent
ok - fm-turnend-guard --claude: repeated failed-to-arming races make bounded monotonic progress
ok - fm-turnend-guard --claude: terminal owner boundary excludes a concurrent start without deadlock
ok - fm-turnend-guard --claude: fresh rewake epoch prevents a duplicate continuation for the same event
ok - fm-turnend-guard --claude: fresh failed epochs preserve and advance monotonic fail-open progression
ok - fm-turnend-guard --claude: integrated fresh failures reach one bounded fail-open, stop continuation, and reset on recovery
ok - fm-turnend-guard --claude: reset contention preserves all episode state until retry
ok - fm-turnend-guard --claude: concurrent auto-arm and guard resets are idempotent and deadlock-free
ok - fm-turnend-guard --claude: stale rewake epoch does not allow a blind stop
ok - fm-turnend-guard --claude: budget exhaustion alone cannot permit a blind stop
ok - fm-turnend-guard --claude: verified fail-open is loud, bounded, attended, and non-repeating
ok - fm-turnend-guard --claude: fail-open requires both exhausted retries and consumed notice
ok - fm-turnend-guard --claude: away ownership excludes the Stop-autoarm fail-open
ok - fm-turnend-guard --claude: positive watcher recovery resets failure episode state
ok - fm-turnend-guard --claude: bounded claim wait avoids a token-consuming forced continuation
ok - fm-turnend-guard --claude: secondmate home re-blocks unclaimed and allows auto-arm-claimed stops
FM_TEST_END 2026-08-13T17:32:51Z tests/fm-turnend-guard.test.sh exit=0 duration_ms=36331 gate_skip=false
FM_TEST_SUMMARY total=5 failed=0 skipped_gate=0 duration_ms=272903
FM_TEST_SUMMARY_FAMILY family=backend-dispatch count=1 duration_ms=3697 failed=0
FM_TEST_SUMMARY_FAMILY family=secondmate count=1 duration_ms=160056 failed=0
FM_TEST_SUMMARY_FAMILY family=watcher-wake-lock count=3 duration_ms=108958 failed=0
FM_TEST_SLOWEST rank=1 script=tests/fm-secondmate-harness.test.sh duration_ms=160056
FM_TEST_SLOWEST rank=2 script=tests/fm-cursor-primary.test.sh duration_ms=67997
FM_TEST_SLOWEST rank=3 script=tests/fm-turnend-guard.test.sh duration_ms=36331
FM_TEST_SLOWEST rank=4 script=tests/fm-session-lock-ancestry.test.sh duration_ms=4630
FM_TEST_SLOWEST rank=5 script=tests/fm-tmux-agent-liveness.test.sh duration_ms=3697
Evidence: Environment-gated live Cursor guard self-skip
skip: set FM_CURSOR_PRIMARY_LIVE_E2E=1 to run the live Cursor primary guard

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • 🚨 bin/fm-turnend-guard-cursor.sh:304 - The required claim that a captain-interrupted park “stands down without emitting” remains false until the captain's new turn ends. The old park checks only whether a newer stop has claimed PARK_SEQ, but the new stop is created after the captain turn finishes. If the watcher closes actionably during that turn, the old park remains owner and emits its stale follow-up at lines 345-350. Invalidate the park at the earliest supported Cursor state transition that observes the captain's new turn, before committing any follow-up; if no such primitive exists, escalate that concrete limitation rather than claiming complete supersession.

🔧 Fix: Correct Cursor park supersession documentation
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • bin/fm-test-run.sh tests/fm-cursor-primary.test.sh tests/fm-tmux-agent-liveness.test.sh tests/fm-session-lock-ancestry.test.sh tests/fm-secondmate-harness.test.sh tests/fm-turnend-guard.test.sh
  • Manual executable protocol probe using real hook processes and fake Cursor ancestry: verified stop exits 0 with a watcher followup_message, sessionStart emits additional_context, and preCompact remains unregistered.
  • tests/fm-cursor-primary-live-e2e.test.sh without opt-in: verified the live guard self-skips with the required environment-gated instruction.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@kunchenguid
kunchenguid force-pushed the fm/fm-cursor-primary-build-r1 branch from c0a206a to ecbdaef Compare August 13, 2026 17:37
@kunchenguid kunchenguid changed the title feat: support Cursor as a primary harness feat: support Cursor Agent CLI as a primary harness Aug 13, 2026
kunchenguid and others added 23 commits August 13, 2026 10:37
…nd session start

Register a tracked project-scope .cursor/hooks.json for Cursor's stop,
sessionStart, preCompact, and preToolUse steps.

bin/fm-turnend-guard-cursor.sh owns Cursor's turn boundary as a park: it
foregrounds the watcher arm, holds the boundary open until an actionable close,
and returns that wake as one follow-up. Exit 2 is a silent no-op on Cursor's
stop step, so the adapter never uses it. The follow-up loop is bounded twice,
by Cursor's own loop_limit and by the payload's loop_count.

bin/fm-sessionstart-cursor.sh delivers the digest as additional_context at
sessionStart, and stages it for the next turn boundary at preCompact, which
cannot inject context.

Cursor also loads the tracked Claude settings, so bin/fm-hook-host-lib.sh lets
each tracked Claude-shaped entrypoint stand down on a Cursor-delivered payload
rather than running every covered event twice.

bin/fm-tmux-lib.sh reclassifies a Cursor pane's composer cursorlessly, because
Cursor parks its terminal cursor outside the composer, which restores a genuine
composer-empty proof and unblocks away-mode escalation delivery.
Resolve Cursor in the session-lock ancestry through bin/fm-cursor-lib.sh, which
a Cursor primary needs before it can hold its own home lock, and classify its
stop-hook park under the autoarm supervision model so the mid-turn pull guard
stops reporting a healthy between-turns watcher as down.

Read a Cursor pane's composer cursorlessly on tmux, gated on Cursor's own
structural process identity, which restores a genuine composer-empty proof and
lets away-mode escalations reach a Cursor primary with no daemon change.

Lift the secondmate refusals in bin/fm-spawn.sh and bin/fm-control-lib.sh now
that the supervision protocol exists and is recorded.

Cover the whole surface with a portable regression over real processes, an
opt-in live guard against the installed cursor-agent, and dated per-harness
evidence.
…urfaces

Update the turn-end guard, session-start, arm-seatbelt, cd-guard, watcher
continuity, architecture, configuration, README, and harness-adapters owners,
and add dated live evidence to the supervision and runtime-backend verification
records. Correct the recorded Cursor tmux composer verdict: the cursor-anchored
read is still blind, but the composite reader is no longer unknown.

Lift the remaining remote-secondmate refusal missed in the previous commit, and
add the new libs to the existing fixtures that copy a fixed dependency list.
…auses

Also record that Cursor's preCompact firing itself is not yet live-verified,
while the static evidence that it cannot inject context, and the staging path
that follows from it, both are.
The cd-guard fixture copies a fixed dependency list and now needs the shared
hook-host predicate. Both pretool suites also asserted cleanliness with a bare
shellcheck call, a second and weaker copy of the lint definition that
bin/fm-lint.sh owns: it omits --external-sources, so it failed the moment these
checkers sourced a shared library. They now delegate to that owner.
…fusal

A cursor secondmate now launches, so the suite asserts what its park actually
needs: --trust so the home's project hooks load at all, its own home pinned as
the workspace, and the autoarm supervision model inherited across the launch.
Carrying a compaction digest across two concurrently running stop hooks kept
producing races that could deliver it twice or strand it indefinitely, and
closing them kept enlarging a critical section inside a hook Cursor awaits at
the turn boundary. Native preCompact firing was never observed either, so the
surface has no empirical basis yet.

Remove the adapter, its registration, its staged path in the park, and its
tests, and record the surface as deferred and uncovered alongside the Codex
interactive TUI. A regression now asserts preCompact stays unregistered so it
cannot return without its own design and evidence.

This change ships the proven core only: the turn-end follow-up park, the
run-tier session start, and away-mode delivery.
@kunchenguid
kunchenguid force-pushed the fm/fm-cursor-primary-build-r1 branch from ecbdaef to 937c228 Compare August 13, 2026 17:39
@kunchenguid
kunchenguid merged commit 81f7020 into main Aug 13, 2026
13 checks passed
@kunchenguid
kunchenguid deleted the fm/fm-cursor-primary-build-r1 branch August 13, 2026 18:42