Skip to content

feat(harness): add cursor (cursor-agent) as a verified harness adapter - #189

Closed
tomer-ben-david wants to merge 6 commits into
kunchenguid:mainfrom
tomer-ben-david:fm/add-cursor-adapter
Closed

tomer-ben-david wants to merge 6 commits into
kunchenguid:mainfrom
tomer-ben-david:fm/add-cursor-adapter

Conversation

@tomer-ben-david

Copy link
Copy Markdown

Adds cursor (cursor-agent) as a fully verified harness adapter.

This completes the work to let you run firstmate (primary + crew) on Cursor instead of Claude.

Summary of changes

  • Harness detection (fm-harness.sh, fm-lock.sh): CURSOR_AGENT=1 + cursor-agent process name.
  • Launch (fm-spawn.sh): cursor-agent --yolo ... (the autonomy flag), --model support. Effort is not a separate flag — it is encoded in the model id (e.g. suffix -high or bracket form id[effort=high]). Requested effort is still recorded in meta.
  • Turn-end signal: cursor fires a stop hook every turn boundary. We jq-merge a guarded firstmate command into the shared ~/.cursor/hooks.json (additively and idempotently so cmux entries are untouched). Guard uses the same per-task token pointer pattern as grok (.fm-cursor-turnend in the worktree + registry under ~/.cursor/fm-turn-end.d/).
  • Busy detection (fm-watch.sh, fm-tmux-lib.sh): matches ctrl+c to stop on the composer line.
  • Teardown (fm-teardown.sh): cleans per-task pointers and registry tokens. Deliberately leaves the shared hooks.json entry in place (it becomes a safe no-op without the pointer).
  • Other: bootstrap verified list, dispatch profiles, secondmate harness support, and full documentation.
  • Tests: dedicated tests/fm-cursor-harness.test.sh (env marker, process name via lock, launch template, safe hooks merge).

Verified against cursor-agent 2026.07.01-41b2de7.

How to use after merge

  • Run your firstmate session inside cursor-agent → bin/fm-harness.sh will report cursor.
  • config/crew-harness (or leave as default) controls what crewmates use.
  • Per-task override: fm-spawn ... cursor or --harness cursor --model "...".
  • /no-mistakes and other skills work via / (cursor discovers .agents/skills/).

See the harness-adapters skill and updated AGENTS.md for details.

Closes the cursor adapter request.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6e0862ca51

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread bin/fm-spawn.sh Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 024bb2bef0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread bin/fm-spawn.sh Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2ff93cf8a2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread bin/fm-spawn.sh Resolved
@kunchenguid

Copy link
Copy Markdown
Owner

thanks for this. quick note on process - i require PRs to come through no-mistakes, which is why the "PR must be raised via no-mistakes" check is red here (this was opened directly).

the reason i ask for it: no-mistakes runs review, tests, lint, and docs on your branch before the PR is opened, so contributions arrive already validated. that keeps the quality bar high and keeps me from having to hand-review every change - i maintain this solo, so it's the only way i keep up.

can you re-raise it through no-mistakes? running the pipeline on your branch opens/updates the PR through the gate and turns that check green. the change looks useful, it just needs to come through that path. ping me if the setup gives you trouble.

tomer-ben-david and others added 6 commits July 3, 2026 09:17
Wire cursor-agent into firstmate as a 6th verified harness adapter, mirroring
the existing adapters DRY (one thin entry per touch point):

- bin/fm-harness.sh: detect CURSOR_AGENT=1 env marker + cursor-agent process name
- bin/fm-lock.sh: add cursor to HARNESS_RE (fixes 'cannot locate harness process
  in ancestry' for sessions run under cursor-agent)
- bin/fm-spawn.sh: launch_template cursor-agent --yolo (positional prompt, no
  --prompt), --model flag, no separate effort flag (effort folded into model id),
  and a turn-end hook that jq-merges a firstmate stop entry into the SHARED
  ~/.cursor/hooks.json idempotently (preserving cmux's entries) with a grok-style
  per-task token-pointer guard so it never fires for non-firstmate cursor sessions
- bin/fm-teardown.sh: remove the per-task pointer + auth entry (leaves the shared
  hooks.json entry, which is idempotent and gated)
- bin/fm-watch.sh + bin/fm-tmux-lib.sh: add 'ctrl+c to stop' to the busy regex
- bin/fm-bootstrap.sh: accept cursor in the crew-dispatch verified/effort_ok jq
- AGENTS.md section 4: verified adapter list + launch-profile axes
- .agents/skills/harness-adapters/SKILL.md: cursor section with verified facts
- tests/fm-cursor-harness.test.sh: detection, launch_template, and idempotent
  cmux-preserving hooks.json merge

Verified facts sourced from the scout report at data/verify-cursor-yo/report.md
(cursor-agent 2026.07.01-41b2de7).

Co-Authored-By: Claude <noreply@anthropic.com>
- README quickstart and requirements
- docs/configuration.md and architecture.md
- harness-adapters skill header
- spawn.sh comment for bare adapter names

(cursor support is now fully documented for crew dispatch and primary use.)
…entries

Cursor's documented hooks schema (and the actual runtime) expects
  "stop": [ { "command": "..." } ]
not the nested {"hooks": [{"type":"command", ...}]} wrapper we were
emitting (and that the test was asserting).

This was flagged as P1 on the PR. The stop hook would never fire for
firstmate cursor sessions, falling back to stale/heartbeat detection.

- Updated fm_cursor_merge_hooks jq logic and comment.
- Updated test seed data and all jq assertions to match the flat schema.
- All cursor harness tests pass.

Addresses Codex review comment on PR kunchenguid#189.
Address P2 review feedback on PR kunchenguid#189:

- bootstrap now reports MISSING: jq when config/crew-harness=cursor
  or config/secondmate-harness=cursor (similar to X-mode/dispatch).
- fm-spawn hard-fails early with clear error if HARNESS=cursor and
  jq is missing (before creating window or launching the agent).

Previously the merge would just warn and skip the hook, falling back
to stale detection. Now cursor harnesses get the turn-end hook or
don't launch.

jq is still not a universal requirement (only needed for cursor hook
merge + dispatch + X).

Tests still pass.
…oft warning path)

The internal function still had a 'warning + return 0' that would allow
launch to succeed without the hook.

Now:
- Early guard at HARNESS resolution (before any tmux/agent start) exits hard.
- The merge function itself now does hard 'error + MISSING + exit 1' instead
  of warning+success (defensive, and removes the exact code the P2 review quoted).

This, plus the bootstrap MISSING report when cursor is configured, fully
addresses the 'require jq before spawning cursor tasks' feedback.

Tests unchanged (jq present in env).
…x P2)

Previously a malformed ~/.cursor/hooks.json would only warn and continue
the spawn (no turn-end hook installed).

Now the merge failure path does 'error' + exit 1, consistent with the
missing-jq and early-guard paths.

This addresses the latest Codex P2 on commit 2ff93cf.
@tomer-ben-david
tomer-ben-david force-pushed the fm/add-cursor-adapter branch from e07b2da to 49b3d12 Compare July 3, 2026 06:20

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 49b3d12b4c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread bin/fm-bootstrap.sh

# jq is required for cursor harness (to jq-merge the stop hook into the shared
# ~/.cursor/hooks.json). Already required for X-mode and crew-dispatch (above).
if [ "$crew" = "cursor" ]; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Detect cursor defaults before jq check

Captain, this check only examines the literal config/crew-harness contents; if that file is absent or set to default while firstmate itself is running under cursor-agent, fm-harness.sh crew resolves to cursor but bootstrap will not emit MISSING: jq. This is a fresh gap beyond the earlier jq fix: cursor is selected implicitly via harness detection, so the first spawn fails in fm-spawn.sh instead of the session-start consent/install flow surfacing the prerequisite.

Useful? React with 👍 / 👎.

Comment thread bin/fm-bootstrap.sh
fi
fi
sm=
[ -f "$CONFIG/secondmate-harness" ] && sm=$(head -1 "$CONFIG/secondmate-harness" 2>/dev/null | tr -d '[:space:]' | cut -d' ' -f1 || true)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Parse secondmate harness before jq check

Captain, this secondmate jq probe removes all whitespace before taking the first field, so documented config/secondmate-harness lines like cursor auto high are parsed as cursorautohigh and skip MISSING: jq on machines without jq. This is fresh evidence beyond the prior jq thread: the added parser disagrees with fm-harness.sh's whitespace-token parser for pinned secondmate model/effort, so a cursor secondmate can pass bootstrap and then fail at spawn.

Useful? React with 👍 / 👎.

tomer-ben-david added a commit to tomer-ben-david/firstmate that referenced this pull request Jul 5, 2026
…entries

Cursor's documented hooks schema (and the actual runtime) expects
  "stop": [ { "command": "..." } ]
not the nested {"hooks": [{"type":"command", ...}]} wrapper we were
emitting (and that the test was asserting).

This was flagged as P1 on the PR. The stop hook would never fire for
firstmate cursor sessions, falling back to stale/heartbeat detection.

- Updated fm_cursor_merge_hooks jq logic and comment.
- Updated test seed data and all jq assertions to match the flat schema.
- All cursor harness tests pass.

Addresses Codex review comment on PR kunchenguid#189.
tomer-ben-david added a commit to tomer-ben-david/firstmate that referenced this pull request Jul 5, 2026
Address P2 review feedback on PR kunchenguid#189:

- bootstrap now reports MISSING: jq when config/crew-harness=cursor
  or config/secondmate-harness=cursor (similar to X-mode/dispatch).
- fm-spawn hard-fails early with clear error if HARNESS=cursor and
  jq is missing (before creating window or launching the agent).

Previously the merge would just warn and skip the hook, falling back
to stale detection. Now cursor harnesses get the turn-end hook or
don't launch.

jq is still not a universal requirement (only needed for cursor hook
merge + dispatch + X).

Tests still pass.
@bobcave

bobcave commented Sep 2, 2026

Copy link
Copy Markdown

Acta de G7 — observacion post-cutover con cobertura completa · EJECUTADO

Cutover W1: 2026-09-02T00:57Z. Cierre de la observacion: 2026-09-02T14:59Z.
Duracion ~14 h, muy por debajo del techo de 26 h. Un ciclo de escaneo.
Commit operado 615e5d07…d2571. Evidencia redactada.

Autorizacion del capitan, 2026-09-02: crear la cuenta de prueba g7-obs-20260902 con
usuario:aprovisionar por el servicio migrador, un ingreso y una salida con ella, y su baja con
usuario:desactivar al cerrar; el alta declarada como escritura autorizada y atribuida.

Contadores de #189 — todos en cero

Criterio Medicion
permission denied / must be owner en el log de PostgreSQL 0
Errores de cmx_runtime en el log 0
Errores de cmx_migrator en el log 0
Errores del rol historico en el log 0
"code":"42501" en API 0
sql_42501 en worker 0
worker.error 0
tipo=identidad (guarda C4) 0
authz.outbox.veneno 0
Cola pendiente de la outbox 0, no creciente (max_id 19 al abrir y al cerrar)
sesiones_historicas 0
Reinicios de API y worker 0 / 0
readiness API / worker 200 / 200

El prefijo %u@%d del log —la mutacion autorizada en G1— es lo que permite esta atribucion por
rol. Los seis ERROR que si aparecen en el log son todos postgres@consolidamex, es decir la
sesion administrativa de inventario del operador con nombres de columna equivocados. Ninguno es un
permiso denegado y ninguno procede de API ni de worker.

Ciclo de escaneo posterior al cutover

Elemento Valor
Escaneos iniciados tras el cutover 1
Estado exitoso
errores 0
Fecha operativa 2026-09-02
Inicio 2026-09-02T13:00:00.108Z (07:00 America/Mexico_City)
Duracion 24 ms
Latido fresco; el planificador se verifico encolado en Redis la noche anterior, con marca exacta 1788354000000

Cobertura — completa

Elemento Resultado
Ingreso con la cuenta de prueba 200, sesion emitida
Cambio de contrasena (onboarding obligado) 200
Salida 200; GET /me posterior devuelve 401
Lectura de salud 200
Lectura de bandeja 200
Actividad en pg_stat_user_tables tipos_documento 45→47, documentos 85→88, bandeja_estado 4→6, usuarios 366→370
Lecturas con el rol runtime real current_user = session_user = cmx_runtime; catalogo, documentos, bandeja y usuarios leidos sin un solo permiso denegado
Baja de la cuenta usuario_desactivado, 0 sesiones revocadas y 0 credenciales invalidadas

Tres cosas declaradas y no maquilladas, con su justificacion:

  1. La lectura del catalogo por HTTP autenticado no se completo. El operador genero la
    contrasena nueva dentro del contenedor y no la capturo, perdiendo la sesion; la reemision quedo
    cerrada porque la cuenta ya habia fijado contrasena. El capitan resolvio no reaprovisionar:
    el catalogo esta vacio, la lectura autenticada devolveria una lista vacia y el permiso ya esta
    probado contra el rol real. GET /tipos-documento sin sesion devuelve 401, lo que acredita
    que la ruta existe y exige autenticacion.
  2. No existe un GET /documentos de listado, solo /documentos/:id, y produccion tiene cero
    documentos. Camino sin consumidor en la ventana: se declara cubierto por G4 y el ensayo scratch,
    conforme al contrato. No se finge.
  3. La credencial temporal es de un solo uso. Se descubrio al medirlo: el primer ingreso la
    consumio y el segundo devolvio 401.

Metricas frente a la linea base W0

Metrica Base W0 Observacion Lectura
http_5xx 0 0 igual
xact_rollback delta 0 3 peor en 3, explicados abajo

Los tres rollbacks estan atribuidos: un ingreso con la credencial temporal ya consumida, una
reemision rechazada por password_vigente, y uno mas sin ERROR correspondiente en el log, que
por tanto es una transaccion revertida sin fallo. Ninguno procede del runtime ni del cutover, y
las metricas que dicen si el cutover fue sano —permisos denegados, 42501, identidad, sesiones
historicas, reinicios y readiness— estan todas en cero. El capitan valoro este delta y resolvio
aceptarlo. Esa valoracion no es el GO: el GO es su firma.

Quiescencia de cierre — cuatro diferencias, las cuatro atribuidas

Valor Q0 Cierre Atribucion
bitacora_max_seq / bitacora_filas 81 87 los seis eslabones del ejercicio de cobertura
vencimientos_escaneos_filas 18 19 el escaneo post-cutover, que es el criterio del gate
usuarios_totales 3 4 la cuenta de prueba, declarada por el capitan
usuarios_vivos 3 3 la baja es logica: deleted_at fijado

Los seis eslabones, uno a uno: auth.ingreso (82), auth.ingreso_fallido (83), auth.ingreso
(84), auth.cambio_contrasena (85), auth.salida (86) y auth.salida de la baja (87).
authz_outbox no se movio: max_id 19 antes y despues. Cero deltas inexplicados.

Lo que este acta NO autoriza

No autoriza el retiro del login historico, ni Retiro-1/2, ni P1-P5, ni el GO. El GO existe
unicamente como firma DSSE del capitan sobre cierre.json con decision:"GO", verificable con la
publica evidencia-2026-08.

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.

3 participants