Skip to content

feat(bin): add Cursor harness adapter support - #1726

Closed
vipentti wants to merge 126 commits into
kunchenguid:mainfrom
vipentti:fm/cursor-adapter-ship-4
Closed

vipentti wants to merge 126 commits into
kunchenguid:mainfrom
vipentti:fm/cursor-adapter-ship-4

Conversation

@vipentti

@vipentti vipentti commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Add first-class Cursor harness support to firstmate so Cursor workers can be detected, launched, supervised, and cleaned up safely across local and remote execution. Extend primary-session supervision and shared interaction handling for Cursor's process, hook, prompt, and worker-server behavior while preserving existing harness behavior.

What Changed

  • Added verified Cursor adapter support for process detection, executable resolution, spawning, session locks, tmux and Herdr endpoints, remote readiness, and liveness.
  • Added tracked Cursor stop and preToolUse hooks with deny responses, turn-end supervision, continuation re-arming, bounded wake chains, and follow-up handling.
  • Added orphan-wake recovery for interrupted stop-hook arming, including durable interrupted-park markers and wake-queue draining.
  • Extended composer, ghost-text, busy-queue, and submission handling for Cursor prompts, idle follow-ups, ghost rendering, and Enter-while-busy behavior.
  • Added session-lock ancestry handling and detached worker-server teardown containment using recorded PID and start-time identity, including nested and secondmate cleanup.
  • Added shared process-identity helpers and Cursor-specific ownership in bin/fm-cursor-lib.sh.
  • Updated harness, backend, supervision, runtime-verification, remote-secondmate, and teardown documentation.
  • Added regression coverage for detection, spawning, session locks, liveness, hooks, composer and ghost behavior, busy submission, interrupted-park recovery, remote readiness, teardown, and hermetic fixtures.

Pipeline

Updates from git push no-mistakes

✅ Intent - passed
✅ Rebase - passed
✅ Review - completed
✅ Test - passed
✅ Document - passed
✅ Lint - passed
✅ Push - passed

@vipentti
vipentti force-pushed the fm/cursor-adapter-ship-4 branch from 3dbb21e to 02b08dd Compare August 5, 2026 06:50
@vipentti vipentti changed the title feat: add cursor-agent adapter as verified firstmate harness feat(bin): add cursor-agent as verified harness adapter Aug 5, 2026
@vipentti vipentti changed the title feat(bin): add cursor-agent as verified harness adapter feat(bin): add cursor-agent adapter as verified crewmate harness Aug 5, 2026
@vipentti
vipentti force-pushed the fm/cursor-adapter-ship-4 branch from 65dd134 to 3b84259 Compare August 5, 2026 07:37
@vipentti vipentti changed the title feat(bin): add cursor-agent adapter as verified crewmate harness feat(harness): add cursor-agent adapter as verified firstmate harness Aug 5, 2026
@vipentti vipentti changed the title feat(harness): add cursor-agent adapter as verified firstmate harness feat(harness): add verified cursor-agent adapter with spawn-time binary resolution Aug 5, 2026
@vipentti
vipentti force-pushed the fm/cursor-adapter-ship-4 branch from 406afee to 59d19df Compare August 5, 2026 10:31
@vipentti
vipentti marked this pull request as draft August 5, 2026 10:36
@vipentti
vipentti force-pushed the fm/cursor-adapter-ship-4 branch 2 times, most recently from 54afe2e to 660a09e Compare August 5, 2026 11:27
@vipentti vipentti changed the title feat(harness): add verified cursor-agent adapter with spawn-time binary resolution feat(bin): add cursor-agent adapter as verified crewmate harness Aug 5, 2026
@vipentti
vipentti marked this pull request as ready for review August 5, 2026 12:13
@vipentti vipentti changed the title feat(bin): add cursor-agent adapter as verified crewmate harness feat(bin): add cursor-agent harness adapter with alias resolution Aug 5, 2026
@vipentti
vipentti force-pushed the fm/cursor-adapter-ship-4 branch 2 times, most recently from 3c216d2 to 5b21865 Compare August 5, 2026 14:53
@vipentti vipentti changed the title feat(bin): add cursor-agent harness adapter with alias resolution feat(bin): add Cursor primary-harness support Aug 5, 2026
@vipentti
vipentti force-pushed the fm/cursor-adapter-ship-4 branch from 4341c86 to a45299f Compare August 5, 2026 18:59
@vipentti vipentti changed the title feat(bin): add Cursor primary-harness support feat(bin): add Cursor harness support and reap detached worker-server on teardown Aug 5, 2026
@vipentti
vipentti force-pushed the fm/cursor-adapter-ship-4 branch 4 times, most recently from 2398b85 to 77c909c Compare August 6, 2026 03:01
@vipentti vipentti changed the title feat(bin): add Cursor harness support and reap detached worker-server on teardown feat(harness): add Cursor agent harness support Aug 6, 2026
@kunchenguid

kunchenguid commented Aug 6, 2026 •

Copy link
Copy Markdown
Owner

Automated reminder: thanks for the PR! This branch currently has a merge conflict with the base branch.

When you get a chance, please rebase onto (or merge) the latest base branch, resolve the conflict, and push. After that, checks will re-run and the PR will get looked at again.

Noted for firstmate#1726 at 77c909c0.

@vipentti vipentti changed the title feat(harness): add Cursor agent harness support feat(cursor): add Cursor adapter with stop-hook supervision Aug 6, 2026
@vipentti
vipentti force-pushed the fm/cursor-adapter-ship-4 branch from 58ae208 to fb4ac91 Compare August 6, 2026 18:40
@kunchenguid kunchenguid removed the wheelhouse:pending-contributor-action Managed by Wheelhouse label Aug 6, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Automated reminder: thanks for the PR! This branch currently has a merge conflict with the base branch.

When you get a chance, please rebase onto (or merge) the latest base branch, resolve the conflict, and push. After that, checks will re-run and the PR will get looked at again.

Noted for firstmate#1726 at fb4ac914.

@vipentti
vipentti force-pushed the fm/cursor-adapter-ship-4 branch from fb4ac91 to 9ee19a5 Compare August 7, 2026 05:22
vipentti added 18 commits August 9, 2026 15:11
Round-7 F2 (captain-approved; F1/F3 stay declined): consolidate the duplicated exact PID+identity termination logic (parse record, liveness, identity revalidation, TERM-wait-KILL-revalidate, refuse-on-survival) into fm_process_record_terminate in bin/fm-process-identity-lib.sh, the shared owner both spawn and teardown already source. Caller policy stays outside the primitive: malformed-record action (spawn refuse / teardown remove), timings (--term-polls/--poll-interval), retention on confirmed termination (--keep-record for the harness-switch path), lifecycle diagnostics (--verbose), and refusal diagnostics (callers phrase from FM_PROCESS_RECORD_TERMINATE_REASON). The round-4 rollback-retention and round-5 preserve-on-unconfirmed contracts hold: every refusal preserves the record, removal happens only after the process is proven gone or its identity no longer matches. Exit-race tolerance: a process dying from TERM/KILL can still answer kill -0 while /proc/<pid> is already gone, so mid-wait identity-read failures recheck liveness instead of refusing; only a persistent alive-but-unreadable process refuses. spawn's cursor_worker_server_reap_record and teardown's reap_cursor_worker_server are now thin wrappers over it.
…ling races

Root cause (reproduced under throttled CPU, matching the CI failure signature): the hung-successor and unretired-successor fixtures raced the extension's wall-clock budgets under scheduling contention. (1) The spawned 'bash -lc' successor can take hundreds of ms to start (login profile sourcing on a starved runner), so the 250 ms readiness window could SIGTERM it before its script ran - the arm log lost rows and the exact-4-rows assertion failed ('expected one successor plus two retries, got N'). (2) SIGTERM-to-close observation could exceed the 250 ms retirement budget, taking the 'did not exit within 250ms' early-return path. Both budgets now carry real slack (750 ms, ~5x the observed CI per-attempt latency) while keeping the loop at ~2.5 s; retirement stays deliberately tiny (20 ms) in the unretired tests whose fixtures ignore TERM. The prompt fail-loud cap is 10 s (worst-case paced flow approaches 5 s) and the single-flight stability check waits a bounded 100 ms window covering the 5-10 ms retry delay instead of one event-loop turn. Every inner failure now surfaces the captured Node output. A second real bug found while stress-testing: the OpenCode turn-end guard plugin crashed on an unhandled EPIPE when a fast-exiting guard child closed its stdin before the payload write landed - the stdin error is now handled.
vipentti added a commit to vipentti/firstmate that referenced this pull request Aug 10, 2026
cursor_worker_server_record now writes pid+identity atomically to a
dedicated state/<id>.worker-server file via temp+mv instead of appending
two separate lines to the meta file.

On discovery timeout or missing identity, the function returns 1 instead
of 0. The spawn caller checks the return and rolls back the endpoint
(kills the backend pane, removes the partial record, writes failed status).

teardown reap_cursor_worker_server reads from the atomic record file
instead of grepping meta. remove_cursor_worker_server_record is replaced
by direct rm of the record file.

Tests: absent-record now expects refusal (was success); added regression
tests for discovery timeout rollback, atomic record completeness, and
detached-worker identification. probe-based alias fallback added to
cursor_process_matches to match the resolver behaviour.

Finding kunchenguid#1 from code-judo review PR kunchenguid#1726.
vipentti added a commit to vipentti/firstmate that referenced this pull request Aug 10, 2026
…ed hook-arm primitive

Extract the hook-owned arm lifecycle into bin/fm-hook-arm-lib.sh with
canonical functions: fm_hook_arm_foreground, fm_hook_arm_has_actionable,
fm_hook_arm_wake_reason, fm_hook_arm_interrupted_park_reason, and
fm_hook_arm_canonical_reason. The shared lib is the single owner of the
arm+classify+healthy-watcher decision tree.

Rename .cursor-hook-interrupted to .hook-arm-interrupted (harness-neutral)
across fm-watch-arm.sh, fm-wake-drain.sh, fm-turnend-guard-cursor.sh,
docs, and tests. Remove the Cursor-specific comment from the generic
watcher and drain scripts.

Rewrite fm-turnend-guard-cursor.sh (398->343 lines) to use the shared
primitive. The adapter now does: parse Cursor payload, derive session
identity, call canonical arm operation, apply bounded continuation
counter (Cursor-specific, ~140 lines), translate to {} or followup_message.

Finding kunchenguid#2 from code-judo review PR kunchenguid#1726.
vipentti added a commit to vipentti/firstmate that referenced this pull request Aug 10, 2026
…econd herdr regex

Declare Cursor-specific composer constants (prompt glyph, idle placeholder
regex, Enter-while-busy capability) once near the top of fm-composer-lib.sh
instead of hardcoding them inline and in backend files.

Remove FM_BACKEND_HERDR_BARE_PROMPT_CURSOR_RE from herdr.sh. The scanner
now builds the prompt regex dynamically by appending the Cursor glyph to
the base alternation when FM_COMPOSER_HARNESS=cursor, so the glyph is
defined once in the composer lib, not duplicated in the backend.

Finding kunchenguid#3 from code-judo review PR kunchenguid#1726. The ANSI reverse-video gap
buffering extraction from fm_composer_strip_ghost is deferred to a
follow-up; the current harness gate and comments document the boundary.
vipentti added a commit to vipentti/firstmate that referenced this pull request Aug 10, 2026
Move Cursor-specific test functions (872 lines) from the shared
tests/fm-turnend-guard.test.sh into tests/fm-turnend-guard-cursor.test.sh.
The shared guard suite sources the new file so the test list entries still
resolve. Shared contract/integration cases, the Claude-hermetic-under-Cursor
test, and genuinely reusable helpers stay in the original file.

No test function bodies are changed; this is a pure move.

Finding kunchenguid#4 from code-judo review PR kunchenguid#1726.
@kunchenguid

kunchenguid commented Aug 10, 2026 •

Copy link
Copy Markdown
Owner

Automated reminder: thanks for the PR! This branch currently has a merge conflict with the base branch.

When you get a chance, please rebase onto (or merge) the latest base branch, resolve the conflict, and push. After that, checks will re-run and the PR will get looked at again.

Noted for firstmate#1726 at 6fdc6b97.

@vipentti

Copy link
Copy Markdown
Contributor Author

Superseded by #2224: the Cursor adapter continues on a clean rebase onto current main.

@vipentti vipentti closed this Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants