diff --git a/.agents/skills/harness-adapters/SKILL.md b/.agents/skills/harness-adapters/SKILL.md index 03735fefb19..5abe66e52d8 100644 --- a/.agents/skills/harness-adapters/SKILL.md +++ b/.agents/skills/harness-adapters/SKILL.md @@ -69,6 +69,7 @@ The primary integrations for `claude`, `codex`, `opencode`, `pi`, `pi-signed`, a `opencode`, `pi`, and `pi-signed` block by throwing from `tool.execute.before` / returning `{block: true}` from `tool_call`. The exact hook files, commands, output-shaping quirks (Claude Code only honors the deny when stdout is empty), and validation transcripts are owned by `docs/arm-pretool-check.md`. When changing any watcher-arm PreToolUse hook, validate the real harness behavior in a scratch project before trusting it, then update that doc. + ## Primary delegation-shape guard Claude exposes built-in delegation, scheduling, and worktree tools that a primary session can use to create work with no `state/.meta`, which makes the whole guard stack inert because every guard counts that metadata. @@ -117,6 +118,10 @@ Choose intermediate levels proportionally as complexity, uncertainty, blast radi When a verified adapter lacks `xhigh`, cap the choice at its highest supported non-`max` level rather than omitting the intended effort silently. Never select `max` from this fallback; use it only when the captain has explicitly expressed that per-task or standing preference. +Role-specific effort and reviewer boundaries are owned here: routine deep Oracle review uses `xhigh`, while `max` requires an explicit architecture or security escalation from the captain. +`Fixer` is implementation-only, `Oracle` is read-only correctness and architecture review, and `Lelouch` is read-only post-PR release-risk review. +`AGENTS.md` section 7 owns Oracle review timing, fallback, and cycle budget. + The supported launch-profile flags below are verified locally; each row records its evidence. | Harness | Model flag | Effort flag | Notes | diff --git a/.agents/skills/stuck-crewmate-recovery/SKILL.md b/.agents/skills/stuck-crewmate-recovery/SKILL.md index d97ebee3025..3c102809095 100644 --- a/.agents/skills/stuck-crewmate-recovery/SKILL.md +++ b/.agents/skills/stuck-crewmate-recovery/SKILL.md @@ -30,7 +30,7 @@ Use `treehouse status` for treehouse-backed tmux, herdr, zellij, or cmux tasks, Do not sweep another home's endpoints or infer ownership from a matching window label. Before relaunch, prove that no live agent still owns the recorded task and that the existing worktree remains available. -Preserve its uncommitted changes and commits, keep the same task identity, and resume or relaunch the recorded harness in that existing worktree with the same brief plus a concise progress note. +Preserve its uncommitted changes and commits, keep the same task identity, and relaunch through `bin/fm-spawn.sh --resume` with the same brief plus a concise progress note; the script header owns exact invocation, profile reuse or override, and recovery metadata. Do not use a fresh generic spawn while the recorded worktree is unaccounted for, because allocating another worktree can split one task across two copies. If the worktree or ownership cannot be reconciled safely, leave all state intact and report the task failed or blocked with the conflicting evidence. diff --git a/AGENTS.md b/AGENTS.md index 6dd10c87e9d..eef2235a4b3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -90,7 +90,7 @@ state/ volatile runtime signals; gitignored .turn-ended touched by turn-end hooks .grok-turnend-token firstmate-owned grok hook registry token for the task; removed by teardown .kimi-turnend-token firstmate-owned Kimi hook registry token for the task; removed by teardown - .meta written by fm-spawn: window=, endpoint_task_id=, worktree=, project=, harness=, model=, effort=, kind=, mode=, yolo=, tasktmp=; kind=secondmate also records home= and projects=; a non-default runtime backend records further backend-specific fields (docs/configuration.md "Runtime backend"; bin/fm-backend.sh, section 8); fm-pr-check, including through fm-pr-merge, records one canonical pr= and the forge's pr_head= when available (GitHub pull requests and GitLab merge requests; docs/gitlab-merge-watch.md); fm-x-link appends x_request=, x_request_ts=, x_followups=, and optional x_platform=/x_reply_max_chars= for an X-mode-originated task (section 14) + .meta written by fm-spawn: window=, endpoint_task_id=, worktree=, project=, harness=, model=, effort=, kind=, mode=, yolo=, tasktmp=; same-branch recovery also records thinking=, resume=1, and branch=; kind=secondmate also records home= and projects=; a non-default runtime backend records further backend-specific fields (docs/configuration.md "Runtime backend"; bin/fm-backend.sh, section 8); fm-pr-check, including through fm-pr-merge, records one canonical pr= and the forge's pr_head= when available (GitHub pull requests and GitLab merge requests; docs/gitlab-merge-watch.md); fm-x-link appends x_request=, x_request_ts=, x_followups=, and optional x_platform=/x_reply_max_chars= for an X-mode-originated task (section 14) .herdr-presentation quarantinable attempt and restart-binding journal for Herdr's optional visual projection; never task or endpoint authority; see docs/herdr-backend.md "Optional presentation spaces" .check.sh authenticated slow poll; the watcher dispatches validated PR data and the byte-identified X shim through trusted repository scripts, runs registered custom checks from hash-validated private snapshots, and rejects every other state check without execution .check-trust private content binding created by fm-check-register.sh for an intentional custom check @@ -178,6 +178,7 @@ Break genuine evidence ties without array-order or harness bias. `quota-axi` owns how model or product windows relate to bounding account windows and remains data-only. Load `quota-array-dispatch` before choosing among a matched profile array; that skill is the single owner of the completion-aware selection procedure. The generic effort fallback and its precedence are owned by `harness-adapters`: explicit captain and standing configured effort win; otherwise use low for well-understood explicit work, xhigh for ambiguous investigation or design, intermediate levels proportionally, and never max without explicit captain preference. +The role-specific effort and reviewer boundaries are owned by `harness-adapters`; section 7 owns Oracle review timing, fallback, and cycle budget. Do not add model-specific versions of that policy. `secondmate-provisioning` owns secondmate harness pins and inherited local material, while `harness-adapters` owns the harness consequences. @@ -277,6 +278,7 @@ Supervise all live work under section 8. The selected delivery path owns its own rigor. For every PR-based ship task, after the implementation commit and before raising a PR (for direct-PR) or starting `/no-mistakes` (for no-mistakes), the worker must launch `@oracle` to review the exact committed range, absorb its correctness and risk findings, and resolve actionable findings. This provides independent review evidence for the worker, not merge authority and not a replacement for the selected delivery path's own validation or the captain's merge decision. +The review budget is one initial Oracle review plus at most one re-review after fixes; unresolved findings after that re-review become a clear escalation or failure, never an unbounded review loop. For direct-PR tasks, if `@oracle` is unavailable, the worker discloses the fallback and proceeds. For no-mistakes tasks, the worker runs `@oracle` before starting `/no-mistakes` and includes actionable findings or fallback disclosure in `--intent` before validation starts, so Oracle review does not create an unsanctioned manual clean-verdict gate outside the pipeline. Never hold work for an unsanctioned manual clean verdict, stack serial manual reviews, or infer merge authority for a reviewer from security, architecture, or risk alone. diff --git a/bin/fm-bootstrap.sh b/bin/fm-bootstrap.sh index 0ac06b162f5..d311b2a1f9a 100755 --- a/bin/fm-bootstrap.sh +++ b/bin/fm-bootstrap.sh @@ -769,6 +769,7 @@ crew_dispatch_validate() { elif [(.rules // [])[]? | select(type != "object")] | length > 0 then "each rule must be an object" elif [(.rules // [])[]? | select((.when? | type) != "string" or (.when | length) == 0)] | length > 0 then "each rule needs non-empty when" elif [(.rules // [])[]? | select((.use? | type) != "object" and (.use? | type) != "array")] | length > 0 then "each rule needs use" + elif [(.rules // [])[]? | select(has("why") and ((.why? | type) != "string" or (.why | length) == 0))] | length > 0 then "rule why must be a non-empty string when present" elif [(.rules // [])[]? | select((.use? | type) == "array" and (.use | length) == 0)] | length > 0 then "each rule needs at least one use profile" elif [(.rules // [])[]? | profiles(.use?)[]? | select(type != "object")] | length > 0 then "each use profile must be an object" elif [(.rules // [])[]? | profiles(.use?)[]? | select((.harness? | type) != "string" or (.harness | length) == 0)] | length > 0 then "each use profile needs harness" diff --git a/bin/fm-brief.sh b/bin/fm-brief.sh index 6eac59771bc..7e1ca1cbd41 100755 --- a/bin/fm-brief.sh +++ b/bin/fm-brief.sh @@ -254,7 +254,7 @@ else fi SPECIALIST_RULE="8. Standard implementation uses one \`antigravity/gemini-3.6-flash\` crewmate at high effort unless Firstmate explicitly overrides dispatch. You own narrow supporting calls to installed specialists: use \`@fixer\` for targeted implementation, \`@explorer\` for repository mapping and search, \`@plan\` for architecture or implementation planning, \`@designer\` for frontend, UI, and visual work, and \`@oracle\` for independent correctness and risk review when authorized. Inspect and incorporate returned findings yourself, then return $SPECIALIST_RESULT to Firstmate while preserving this brief's isolation, approval, and delivery rules." WEB_RESEARCH_RULE="9. For web research, use Firecrawl MCP first: call \`firecrawl_search\`, call \`firecrawl_search_feedback\` after using its results, and use \`firecrawl_scrape\` for known pages. If Firecrawl is unavailable, use another tool only as a fallback and disclose that fallback in your findings." -REVIEW_PATH_RULE="10. Before pre-commit review, record the base and HEAD SHAs, then have the reviewer inspect the exact committed range with \`git diff ...\` and use \`git show ..\` for commit details; if the review tool cannot access those commits or shows an empty range, report the mismatch instead of reviewing it." +REVIEW_PATH_RULE="10. Before pre-commit review, record the base and HEAD SHAs, then have the reviewer inspect the exact committed range with \`git diff ...\` and use \`git show ..\` for commit details; if the review tool cannot access those commits or shows an empty range, report the mismatch instead of reviewing it. Follow the authoritative role contract in \`harness-adapters\`: Fixer is implementation-only, Oracle is read-only correctness and architecture review, Lelouch is read-only post-PR release-risk review, ordinary deep Oracle review uses xhigh, and max requires explicit architecture or security escalation. Use one initial Oracle review and at most one re-review after fixes; if actionable findings remain after re-review, escalate or fail instead of looping." if [ "$KIND" = scout ]; then cat > "$BRIEF" < [--harness |harness|launch-command] [--model ] [--effort ] [--backend ] [--scout] +# Usage: fm-spawn.sh --mode --yolo [--harness |harness|launch-command] [--model ] [--effort ] [--backend ] [--resume] +# fm-spawn.sh --scout [--harness |harness|launch-command] [--model ] [--effort ] [--backend ] [--resume] # fm-spawn.sh [] [--harness |harness|launch-command] [--model ] [--effort ] [--backend ] --secondmate +# --mode and --yolo are this task's delivery contract, REQUIRED for every ship +# spawn and refused on --scout and --secondmate spawns. Firstmate resolves both +# per task at intake (AGENTS.md section 7); data/projects.md holds the captain's +# standing posture as context, not as this task's answer, so a spawn never looks +# the mode up. A ship spawn additionally reads the brief's recorded +# "Delivery contract: mode=" line and REFUSES a mismatch, so the worker's +# instructions and the recorded task delivery cannot drift apart; a brief +# scaffolded before that line existed warns once and launches on the flag. When +# the explicit mode carries less rigor than the project's standing posture, a +# loud one-line deviation notice is printed and the spawn continues. +# no-mistakes-prod-only is a registry policy rather than a task mode and is +# refused as a flag value. +# --resume reuses the recorded task worktree and branch after endpoint loss; it never allocates a replacement worktree. # --harness is the explicit per-spawn harness/profile adapter. The old # positional harness arg still works for back-compat. # --model and --effort are concrete profile -# axes chosen by firstmate at intake. They are only threaded into harnesses whose +# axes chosen by firstmate at intake. On --resume, omitted axes reuse the recorded +# actual profile and explicit axes replace them after the same quota preflight. They are only threaded into harnesses whose # installed CLIs were verified to support that axis; unsupported axes are omitted # from that harness's launch rather than guessed. # --backend is the explicit runtime session-provider backend for this @@ -196,6 +211,10 @@ HARNESS_ARG= MODEL= EFFORT= BACKEND_ARG= +MODE= +YOLO= +TRACEPARENT_ARG= +RESUME=0 HARNESS_SET=0 MODEL_SET=0 EFFORT_SET=0 @@ -228,6 +247,13 @@ for a in "$@"; do --effort=*) EFFORT=${a#--effort=}; EFFORT_SET=1 ;; --backend) want_value=backend ;; --backend=*) BACKEND_ARG=${a#--backend=}; BACKEND_SET=1 ;; + --mode) want_value=mode ;; + --mode=*) MODE=${a#--mode=}; MODE_SET=1 ;; + --yolo) want_value=yolo ;; + --yolo=*) YOLO=${a#--yolo=}; YOLO_SET=1 ;; + --traceparent) want_value=traceparent ;; + --traceparent=*) TRACEPARENT_ARG=${a#--traceparent=}; TRACEPARENT_SET=1 ;; + --resume) RESUME=1 ;; *) POS+=("$a") ;; esac done @@ -264,6 +290,7 @@ if [ "$BACKEND" = cmux ] && [ "$KIND" = secondmate ]; then exit 1 fi if [ "$BACKEND" = orca ]; then + [ "$RESUME" -eq 0 ] || { echo "error: --resume cannot reuse a recorded worktree with backend=orca" >&2; exit 1; } fm_backend_orca_runtime_check || exit 1 fi ORCA_ABORT_CLEANUP=0 @@ -401,6 +428,7 @@ if [ "${#POS[@]}" -gt 0 ] && [ "${POS[0]}" != "$idpart" ] && case "$idpart" in * [ -z "$HARNESS_ARG" ] || shared_args+=(--harness "$HARNESS_ARG") [ -z "$MODEL" ] || shared_args+=(--model "$MODEL") [ -z "$EFFORT" ] || shared_args+=(--effort "$EFFORT") + [ "$RESUME" -eq 0 ] || shared_args+=(--resume) [ -z "$BACKEND_ARG" ] || shared_args+=(--backend "$BACKEND_ARG") for pair in "${POS[@]}"; do case "$pair" in @@ -427,6 +455,50 @@ if ! fm_lock_try_acquire "$SPAWN_TASK_LOCK"; then exit 1 fi SPAWN_TASK_LOCK_HELD=1 +RESUME_META="$STATE/$ID.meta" +RESUME_PROJECT= +RESUME_WORKTREE= +if [ "$RESUME" -eq 1 ]; then + [ "$KIND" != secondmate ] || { echo "error: --resume is only supported for crewmate and scout tasks" >&2; exit 1; } + [ -f "$RESUME_META" ] && [ ! -L "$RESUME_META" ] || { + echo "error: --resume requires recorded task metadata at $RESUME_META" >&2 + exit 1 + } + RESUME_PROJECT=$(grep '^project=' "$RESUME_META" | tail -1 | cut -d= -f2- || true) + RESUME_WORKTREE=$(grep '^worktree=' "$RESUME_META" | tail -1 | cut -d= -f2- || true) + [ -n "$RESUME_PROJECT" ] && [ -n "$RESUME_WORKTREE" ] || { + echo "error: --resume requires recorded project= and worktree=" >&2 + exit 1 + } + if [ ! -d "$RESUME_WORKTREE" ] || [ ! -d "$RESUME_PROJECT" ]; then + echo "error: --resume recorded project or worktree is unavailable" >&2 + exit 1 + fi + old_target=$(fm_backend_target_of_meta "$RESUME_META" 2>/dev/null || true) + if [ -n "$old_target" ]; then + old_backend=$(fm_backend_of_meta "$RESUME_META") + old_state=$(fm_backend_agent_alive "$old_backend" "$old_target") + case "$old_state" in + alive|unknown) + echo "error: --resume refused while recorded task endpoint is $old_state" >&2 + exit 1 + ;; + esac + fi + if [ "$HARNESS_SET" -eq 0 ]; then + HARNESS_ARG=$(grep '^harness=' "$RESUME_META" | tail -1 | cut -d= -f2- || true) + [ -n "$HARNESS_ARG" ] && HARNESS_SET=1 + fi + if [ "$MODEL_SET" -eq 0 ]; then + MODEL=$(grep '^model=' "$RESUME_META" | tail -1 | cut -d= -f2- || true) + fi + if [ "$EFFORT_SET" -eq 0 ]; then + EFFORT=$(grep '^thinking=' "$RESUME_META" | tail -1 | cut -d= -f2- || true) + [ -n "$EFFORT" ] || EFFORT=$(grep '^effort=' "$RESUME_META" | tail -1 | cut -d= -f2- || true) + fi + MODEL=${MODEL:-default} + EFFORT=${EFFORT:-default} +fi PROJ= ARG3= FIRSTMATE_HOME= @@ -451,8 +523,13 @@ if [ "$KIND" = secondmate ]; then ;; esac else - PROJ=${POS[1]} - ARG3=${POS[2]:-} + if [ "$RESUME" -eq 1 ]; then + PROJ=$RESUME_PROJECT + ARG3=${POS[2]:-} + else + PROJ=${POS[1]} + ARG3=${POS[2]:-} + fi fi [ -z "$HARNESS_ARG" ] || ARG3=$HARNESS_ARG @@ -629,62 +706,35 @@ antigravity_preflight() { return 1 } - if ! command -v perl >/dev/null 2>&1; then - echo "error: Antigravity quota preflight requires perl" >&2 + local timer='' candidate candidate_path + for candidate in timeout gtimeout; do + candidate_path=$(command -v "$candidate" 2>/dev/null) || continue + if "$candidate_path" --help 2>&1 | grep -q -- '--kill-after'; then + timer=$candidate_path + break + fi + done + if [ -z "$timer" ]; then + echo "error: Antigravity quota preflight requires timeout or gtimeout with --kill-after" >&2 return 1 fi tmp_out=$(mktemp "${STATE}/.preflight-${ID}.XXXXXXXX" 2>/dev/null || mktemp "/tmp/.preflight-${ID}.XXXXXXXX") set +e - perl -e ' - my $t = shift; my $file = shift; my $limit = shift; - pipe(my $r, my $w) or die; - my $pid = fork; die "fork failed" unless defined $pid; - if (!$pid) { - close $r; - setpgrp(0, 0); - open(STDOUT, ">&", $w) or die; - open(STDERR, ">&", $w) or die; - close $w; - exec @ARGV; - } - close $w; - local $SIG{ALRM} = sub { - kill "TERM", -$pid; - select undef, undef, undef, 0.2; - kill "KILL", -$pid; - exit 124; - }; - alarm $t; - open(my $out_fh, ">", $file) or die; - my $bytes_read = 0; - my $buf; - while (sysread($r, $buf, 4096)) { - if ($bytes_read < $limit) { - my $to_write = length($buf); - if ($bytes_read + $to_write > $limit) { - $to_write = $limit - $bytes_read; - } - syswrite($out_fh, substr($buf, 0, $to_write)); - $bytes_read += $to_write; - } - } - close $out_fh; - close $r; - waitpid($pid, 0); - alarm 0; - my $sig = $? & 127; - my $rc = $sig ? 255 : ($? >> 8); - kill "TERM", -$pid; - select undef, undef, undef, 0.1; - kill "KILL", -$pid; - exit $rc; - ' "$timeout_seconds" "$tmp_out" "$output_bytes" "$checker" check >/dev/null 2>&1 - rc=$? + "$timer" --kill-after=1 "$timeout_seconds" "$checker" check 2>&1 | + { + dd bs=1 count="$output_bytes" 2>/dev/null + cat >/dev/null + } >"$tmp_out" + rc=${PIPESTATUS[0]} set -e rm -f "$tmp_out" + if [ "$rc" -ge 128 ] && [ "$rc" -le 255 ]; then + rc=255 + fi + case "$rc" in 0) return 0 ;; 1) @@ -1000,8 +1050,19 @@ if [ "$KIND" = secondmate ]; then BRIEF="$DATA/$ID/brief.md" fi else - PROJ_ABS="$(cd "$(resolve_project_dir_arg "$PROJ")" && pwd)" - WT="" + if [ "$RESUME" -eq 1 ]; then + PROJ_ABS=$RESUME_PROJECT + WT=$RESUME_WORKTREE + resume_project_top=$(git -C "$WT" rev-parse --show-toplevel 2>/dev/null || true) + resume_project_top=$(cd "$resume_project_top" 2>/dev/null && pwd -P || true) + [ -n "$resume_project_top" ] && [ "$resume_project_top" != "$PROJ_ABS" ] || { + echo "error: --resume recorded worktree is not isolated from its project" >&2 + exit 1 + } + else + PROJ_ABS="$(cd "$(resolve_project_dir_arg "$PROJ")" && pwd)" + WT="" + fi BRIEF="$DATA/$ID/brief.md" fi [ -f "$BRIEF" ] || { echo "error: no brief at $BRIEF" >&2; exit 1; } @@ -1453,7 +1514,31 @@ kimi_spawn_fail() { # } if [ "$KIND" != secondmate ] && [ "$BACKEND" != orca ]; then - spawn_send_text_line "$WT_TARGET" 'treehouse get' + if [ "$RESUME" -eq 1 ]; then + # Recovery keeps the recorded linked worktree; only move the new endpoint + # into it. No treehouse allocation is allowed on this path. + spawn_send_text_line "$WT_TARGET" "cd -- $(shell_quote "$WT")" + resume_wt_real=$(real_path_or_raw "$WT") + resume_candidate= + for _ in $(seq 1 60); do + p=$(spawn_current_path "$WT_TARGET" || true) + if [ -n "$p" ] && [ "$(real_path_or_raw "$p")" = "$resume_wt_real" ]; then + if [ "$resume_candidate" = "$resume_wt_real" ]; then + break + fi + resume_candidate=$resume_wt_real + else + resume_candidate= + fi + sleep 1 + done + [ "$resume_candidate" = "$resume_wt_real" ] || { + echo "error: recorded resume worktree was not reached; inspect endpoint $T" >&2 + exit 1 + } + validate_spawn_worktree "recorded resume worktree" "$T" + else + spawn_send_text_line "$WT_TARGET" 'treehouse get' # Wait for the treehouse subshell: the pane's cwd moves from the project to the worktree. # Target the stable window id, not the name: if the name is ever lost (e.g. an @@ -1500,6 +1585,7 @@ if [ "$KIND" != secondmate ] && [ "$BACKEND" != orca ]; then fi validate_spawn_worktree "treehouse get" "$T" + fi fi # Per-task temp root: /tmp/fm-/ with Go's build temp nested at gotmp/. Go won't @@ -1774,6 +1860,11 @@ META_WINDOW=$T echo "tasktmp=$TASK_TMP" echo "model=${MODEL:-default}" echo "effort=${EFFORT:-default}" + if [ "$RESUME" -eq 1 ]; then + echo "thinking=${EFFORT:-default}" + echo "resume=1" + echo "branch=$(git -C "$WT" symbolic-ref --quiet --short HEAD 2>/dev/null || echo detached)" + fi [ -z "${BUSY_GEN:-}" ] || echo "busy_gen=$BUSY_GEN" # backend= is written only for a non-default (non-tmux) backend, so the # default path's meta stays byte-identical (absent backend= means tmux; diff --git a/docs/configuration.md b/docs/configuration.md index d17b89faecd..aafae9c8a53 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -241,6 +241,7 @@ This section is the single owner of the canonical schema and its per-field seman "use": [ { "harness": "", "model": "", "effort": "" } ], + "select": "quota-balanced", "why": "" } ], @@ -253,14 +254,16 @@ This section is the single owner of the canonical schema and its per-field seman Per rule, `when` and `use` are required. Both `use` and the optional top-level `default` accept either one profile object or a non-empty array of profile objects. The single-object form stays fully backward-compatible, and every profile needs `harness`. -Profile `model` and `effort` fields and rule `why` are optional. +Profile `model` and `effort` fields and rule `why` and `select` fields are optional non-empty strings; `select` accepts only `quota-balanced`. An omitted model or effort means the selected harness uses its own default for that axis. Every profile array is an implicit quota-aware choice resolved through `quota-array-dispatch`. If no dispatch rule fits, firstmate resolves `default` through the same object-or-array path before falling back to `config/crew-harness`. +The copyable example shows the minimal risk matrix; use `why` to label profile roles without adding a second role schema, and follow the authoritative role and effort boundaries in [`harness-adapters`](../.agents/skills/harness-adapters/SKILL.md#launch-profile-axes). If a selected profile carries an effort value the chosen harness does not accept, `fm-spawn.sh` records the requested `effort=` in task meta for traceability but omits the launch flag, and bootstrap reports the invalid harness/effort pair as a `CREW_DISPATCH` diagnostic when it is visible in the file. See [`docs/examples/crew-dispatch.json`](examples/crew-dispatch.json) for a starting point to copy into local `config/crew-dispatch.json`. When the file exists, bootstrap validates it with `jq`. Valid files stay silent by default; with `FM_BOOTSTRAP_VERBOSE_FACTS=1`, bootstrap emits `BOOTSTRAP_INFO: crew dispatch active config/crew-dispatch.json`, one `BOOTSTRAP_INFO:` fact per rule, and one fact for the optional default profile set. +Risk rules and profile arrays remain natural-language dispatch inputs; quota evidence and the `quota-balanced` selector stay owned by `AGENTS.md` section 4 and `quota-array-dispatch`. Malformed JSON, an empty or malformed rule/default array, an unverified harness, or an effort value unsupported by that harness is reported as `CREW_DISPATCH: invalid config/crew-dispatch.json - ...`; missing `jq` is reported through the normal `MISSING: jq` install-consent flow. While the file remains present, no crewmate or scout spawn may proceed without an explicit resolved harness; malformed configuration must be reported and corrected rather than selected around. Secondmate homes inherit this file from the primary, so a secondmate's own crewmates apply the same dispatch profile behavior. @@ -269,10 +272,10 @@ Secondmate homes inherit this file from the primary, so a secondmate's own crewm Before `fm-spawn.sh` creates a worktree, backend endpoint, agent process, or task metadata, every final model whose name begins with `antigravity/` must pass the Antigravity quota preflight. The checker is the executable `antigravity-account-check.js` under `${PI_CODING_AGENT_DIR:-$HOME/.pi/agent}/extensions/antigravity-account-switcher/bin/` (falling back to `${PI_CODING_AGENT_DIR:-$HOME/.pi/agent}/extensions/pi-antigravity-account-switcher/bin/antigravity-account-check.js`), unless the test-only `FM_ANTIGRAVITY_PREFLIGHT_BIN` override is set. -The preflight invokes that checker with `check`, bounds its runtime with `FM_ANTIGRAVITY_PREFLIGHT_TIMEOUT_SECONDS` (default `30` seconds) using `timeout`, `gtimeout`, or `perl`, and discards output after the bounded `FM_ANTIGRAVITY_PREFLIGHT_OUTPUT_BYTES` limit (default `8192` bytes) so checker output cannot be surfaced as a secret-bearing diagnostic. +The preflight invokes that checker with `check`, bounds its runtime with `FM_ANTIGRAVITY_PREFLIGHT_TIMEOUT_SECONDS` (default `30` seconds) using Perl, and discards output after the bounded `FM_ANTIGRAVITY_PREFLIGHT_OUTPUT_BYTES` limit (default `8192` bytes) so checker output cannot be surfaced as a secret-bearing diagnostic. Exit `0` preserves the requested model and effort. The checker's documented exit `1` means all configured accounts are unusable and changes the final profile to `cockpit/gpt-5.6-luna` at `high` effort. -Missing or non-executable checkers, invalid limits, missing timeout support (`timeout`, `gtimeout`, or `perl`), timeouts, crashes, errors, and unknown exit results refuse the spawn before those side effects occur. +Missing or non-executable checkers, invalid limits, missing Perl, timeouts, crashes, errors, and unknown exit results refuse the spawn before those side effects occur. The same boundary applies to explicit models, dispatch-profile models, scouts, secondmates, and raw launch commands, while non-Antigravity models bypass it. ## Toolchain diff --git a/docs/examples/crew-dispatch.json b/docs/examples/crew-dispatch.json index b404e95e777..4489e095e1c 100644 --- a/docs/examples/crew-dispatch.json +++ b/docs/examples/crew-dispatch.json @@ -6,21 +6,40 @@ "why": "Grok is the preferred dispatch when current web-connected context is central to the work." }, { - "when": "The task is a trivial mechanical edit such as a rote rename, formatting sweep, targeted typo fix, or simple file gathering.", - "use": { "harness": "claude", "model": "haiku", "effort": "low" }, - "why": "Use the cheapest fast profile when the task is narrow and low ambiguity." + "when": "The task is routine implementation, a bounded mechanical edit, or a low-ambiguity fix.", + "use": [ + { "harness": "pi", "model": "antigravity/gemini-3.6-flash", "effort": "high" }, + { "harness": "codex", "model": "gpt-5.5", "effort": "high" } + ], + "select": "quota-balanced", + "why": "Fast implementation profile; Fixer remains implementation-only." }, { - "when": "The task is a big or ambiguous multi-file feature, a risky refactor, or work that requires holding many moving parts in mind.", + "when": "The task involves authentication, authorization, security, concurrency, data integrity, or a high-blast-radius refactor.", "use": [ - { "harness": "claude", "model": "claude-sonnet-5", "effort": "high" }, - { "harness": "codex", "model": "gpt-5.5", "effort": "high" } + { "harness": "pi", "model": "openai-codex/gpt-5.6-sol", "effort": "xhigh" }, + { "harness": "claude", "model": "claude-sonnet-5", "effort": "xhigh" } + ], + "select": "quota-balanced", + "why": "Stronger implementation profile for elevated risk; keep implementation with Fixer." + }, + { + "when": "The task is an independent correctness or architecture review before validation.", + "use": [ + { "harness": "pi", "model": "openai-codex/gpt-5.6-sol", "effort": "xhigh" }, + { "harness": "claude", "model": "claude-sonnet-5", "effort": "xhigh" } ], - "why": "Use a strong coding profile for big, ambiguous work; resolve the alternatives through quota-array-dispatch." + "select": "quota-balanced", + "why": "Independent deep reviewer profile; Oracle is read-only." + }, + { + "when": "The task is a post-PR release-risk review.", + "use": { "harness": "pi", "model": "openai-codex/gpt-5.6-sol", "effort": "xhigh" }, + "why": "Lelouch is read-only and limited to release risk after a PR exists." } ], "default": [ - { "harness": "codex", "model": "gpt-5.5", "effort": "medium" }, - { "harness": "pi", "model": "anthropic/claude-sonnet-5", "effort": "medium" } + { "harness": "pi", "model": "antigravity/gemini-3.6-flash", "effort": "high" }, + { "harness": "codex", "model": "gpt-5.5", "effort": "high" } ] } diff --git a/docs/scripts.md b/docs/scripts.md index 767980b75af..a8cbd9e6279 100644 --- a/docs/scripts.md +++ b/docs/scripts.md @@ -38,6 +38,7 @@ The shared no-mistakes gate refusal for fleet lifecycle entrypoints is summarize | `fm-subagent-pretool-check.sh` | Primary-home delegation-shape PreToolUse guard (docs/subagent-guard.md) | | `fm-supervision-instructions.sh` | Render the session-start primary-harness supervision block or the one-line repair instruction | | `fm-home-seed.sh` | Transactionally provision a secondmate home and maintain `data/secondmates.md` | +| `fm-secondmate-registry-lib.sh` | Parse and validate shared `data/secondmates.md` records and home bindings | | `fm-spawn.sh` | Spawn crewmates, scouts, `id=repo` batches, and secondmates on the resolved harness and runtime backend | | `fm-backend.sh` | Runtime-backend selection, meta helpers, selector resolution, and operation dispatch | | `fm-backend-hometag-lib.sh` | Shared per-installation home-tag derivation for zellij tab and cmux workspace titles | diff --git a/tests/fm-bootstrap.test.sh b/tests/fm-bootstrap.test.sh index 6c72c0bbc45..8cbe581f4de 100755 --- a/tests/fm-bootstrap.test.sh +++ b/tests/fm-bootstrap.test.sh @@ -805,6 +805,7 @@ test_crew_dispatch_validation() { esac done <<'ROWS' malformed dispatch config is flagged^{"rules":[^exact^CREW_DISPATCH: invalid config/crew-dispatch.json - malformed JSON +non-string rule rationale is flagged^{"rules":[{"when":"anything","use":{"harness":"codex"},"why":false}]}^exact^CREW_DISPATCH: invalid config/crew-dispatch.json - rule why must be a non-empty string when present unverified dispatch harness is flagged^{"rules":[{"when":"anything","use":{"harness":"spaceship"}}],"default":{"harness":"codex"}}^exact^CREW_DISPATCH: invalid config/crew-dispatch.json - unverified harness: spaceship unsupported codex max effort is flagged^{"rules":[{"when":"big feature","use":{"harness":"codex","model":"gpt-5","effort":"max"}}]}^exact^CREW_DISPATCH: invalid config/crew-dispatch.json - invalid effort: codex:max unsupported grok max effort is flagged^{"rules":[{"when":"deep current work","use":{"harness":"grok","model":"grok-4","effort":"max"}}]}^exact^CREW_DISPATCH: invalid config/crew-dispatch.json - invalid effort: grok:max diff --git a/tests/fm-brief.test.sh b/tests/fm-brief.test.sh index da60a23319c..ad0555de236 100755 --- a/tests/fm-brief.test.sh +++ b/tests/fm-brief.test.sh @@ -218,6 +218,10 @@ assert_review_path_rule() { "$context brief missing committed-range review verification" assert_grep "if the review tool cannot access those commits or shows an empty range, report the mismatch instead of reviewing it." "$brief" \ "$context brief missing committed-range mismatch handling" + assert_grep "Follow the authoritative role contract in \`harness-adapters\`: Fixer is implementation-only, Oracle is read-only correctness and architecture review, Lelouch is read-only post-PR release-risk review, ordinary deep Oracle review uses xhigh, and max requires explicit architecture or security escalation." "$brief" \ + "$context brief missing role and effort boundaries" + assert_grep "Use one initial Oracle review and at most one re-review after fixes; if actionable findings remain after re-review, escalate or fail instead of looping." "$brief" \ + "$context brief missing bounded Oracle review cycle" } test_project_mode_defaults_and_rejects_malformed() { diff --git a/tests/fm-spawn-dispatch-profile.test.sh b/tests/fm-spawn-dispatch-profile.test.sh index 59483b6b3cf..179f3d2b73d 100755 --- a/tests/fm-spawn-dispatch-profile.test.sh +++ b/tests/fm-spawn-dispatch-profile.test.sh @@ -42,7 +42,14 @@ esac exit 0 SH chmod +x "$fakebin/tmux" - fm_fake_exit0 "$fakebin" treehouse pi-signed + cat > "$fakebin/treehouse" <<'SH' +#!/usr/bin/env bash +set -u +[ -z "${FM_FAKE_TREEHOUSE_LOG:-}" ] || printf '%s\n' "$*" >> "$FM_FAKE_TREEHOUSE_LOG" +exit 0 +SH + chmod +x "$fakebin/treehouse" + fm_fake_exit0 "$fakebin" pi-signed printf '%s\n' "$fakebin" } @@ -99,7 +106,7 @@ run_spawn() { FM_PROJECTS_OVERRIDE="$home/projects" FM_CONFIG_OVERRIDE="$home/config" \ FM_SPAWN_NO_GUARD=1 FM_FAKE_PANE_PATH="$wt" TMUX="fake,1,0" \ CLAUDE_CONFIG_DIR="${FM_TEST_CLAUDE_CONFIG_DIR:-}" \ - FM_FAKE_LAUNCH_LOG="$launchlog" \ + FM_FAKE_LAUNCH_LOG="$launchlog" FM_FAKE_TREEHOUSE_LOG="$launchlog.treehouse" \ FM_ANTIGRAVITY_PREFLIGHT_BIN="${PREFLIGHT_BIN:-}" \ FM_ANTIGRAVITY_PREFLIGHT_TIMEOUT_SECONDS="${PREFLIGHT_TIMEOUT:-30}" \ FM_PREFLIGHT_LOG="${PREFLIGHT_LOG:-}" FM_PREFLIGHT_RESULT="${PREFLIGHT_RESULT:-ok}" \ @@ -138,6 +145,81 @@ SH chmod +x "$path" } +make_timeout_without_perl() { + local fakebin=$1 perl_marker=$2 native_timeout + native_timeout=$(command -v timeout || command -v gtimeout) || fail "native timeout command is unavailable" + cat > "$fakebin/timeout" < "$fakebin/perl" < '$perl_marker' +exit 127 +SH + chmod +x "$fakebin/perl" +} + +make_incompatible_timeout_with_gtimeout() { + local fakebin=$1 timeout_marker=$2 gtimeout_marker=$3 perl_marker=$4 native_timeout + native_timeout=$(command -v timeout || command -v gtimeout) || fail "native timeout command is unavailable" + cat > "$fakebin/timeout" < '$timeout_marker' +exit 127 +SH + chmod +x "$fakebin/timeout" + cat > "$fakebin/gtimeout" < '$gtimeout_marker' +exec '$native_timeout' "\$@" +SH + chmod +x "$fakebin/gtimeout" + cat > "$fakebin/perl" < '$perl_marker' +exit 127 +SH + chmod +x "$fakebin/perl" +} + +make_incompatible_timeouts() { + local fakebin=$1 timeout_marker=$2 gtimeout_marker=$3 perl_marker=$4 + cat > "$fakebin/timeout" < '$timeout_marker' +exit 127 +SH + chmod +x "$fakebin/timeout" + cat > "$fakebin/gtimeout" < '$gtimeout_marker' +exit 127 +SH + chmod +x "$fakebin/gtimeout" + cat > "$fakebin/perl" < '$perl_marker' +exit 127 +SH + chmod +x "$fakebin/perl" +} + make_large_preflight_checker() { local path=$1 result=${2:-ok} cat > "$path" < "$home_space/config/crew-harness" touch "$home_space/state/.last-watcher-beat" printf 'brief for %s\n' "$id" > "$home_space/data/$id/brief.md" PREFLIGHT_BIN="$CASE_DIR/checker" @@ -1055,7 +1209,7 @@ test_antigravity_preflight_space_in_home_path_succeeds() { PREFLIGHT_RESULT=ok make_preflight_checker "$PREFLIGHT_BIN" - out=$(run_spawn "$home_space" "$WT_DIR" "$FAKEBIN_DIR" "$LAUNCH_LOG" "$id" "$PROJ_DIR" \ + out=$(run_ship_spawn "$home_space" "$WT_DIR" "$FAKEBIN_DIR" "$LAUNCH_LOG" "$id" "$PROJ_DIR" \ --model antigravity/gemini-3.6-flash --effort high) status=$? expect_code 0 "$status" "preflight with space in home path should succeed" @@ -1073,7 +1227,7 @@ test_antigravity_preflight_quoted_embedded_raw_launch_model_uses_fallback() { PREFLIGHT_RESULT=exhausted make_preflight_checker "$PREFLIGHT_BIN" - out=$(run_spawn "$HOME_DIR" "$WT_DIR" "$FAKEBIN_DIR" "$LAUNCH_LOG" "$id" "$PROJ_DIR" \ + out=$(run_ship_spawn "$HOME_DIR" "$WT_DIR" "$FAKEBIN_DIR" "$LAUNCH_LOG" "$id" "$PROJ_DIR" \ "custom-agent --model 'antigravity/gemini-3.6-flash' --effort xhigh") status=$? expect_code 0 "$status" "raw launch with single-quoted antigravity model should trigger fallback and replace flag" @@ -1088,6 +1242,44 @@ test_antigravity_preflight_quoted_embedded_raw_launch_model_uses_fallback() { pass "single-quoted raw launch model and effort flags are parsed and cleanly replaced on fallback" } +test_resume_reuses_recorded_worktree_and_profile() { + local rec id out status old_head meta + id=resume-existing-z33 + rec=$(make_spawn_case resume-existing pi "$id") + read_case_record "$rec" + printf 'committed before resume\n' > "$WT_DIR/resume-committed.txt" + git -C "$WT_DIR" add resume-committed.txt + git -C "$WT_DIR" -c user.name='Firstmate Test' -c user.email='firstmate@example.invalid' commit -qm 'resume fixture commit' + old_head=$(git -C "$WT_DIR" rev-parse HEAD) + printf 'uncommitted before resume\n' > "$WT_DIR/resume-uncommitted.txt" + meta="$HOME_DIR/state/$id.meta" + { + printf 'worktree=%s\n' "$WT_DIR" + printf 'project=%s\n' "$PROJ_DIR" + printf 'harness=pi\n' + printf 'kind=ship\n' + printf 'model=antigravity/gemini-3.6-flash\n' + printf 'effort=high\n' + } > "$meta" + + out=$(run_ship_spawn "$HOME_DIR" "$WT_DIR" "$FAKEBIN_DIR" "$LAUNCH_LOG" "$id" "$PROJ_DIR" \ + --resume --model cockpit/gpt-5.6-luna --effort xhigh) + status=$? + expect_code 0 "$status" "resume should relaunch from the recorded worktree" + assert_contains "$out" "spawned $id harness=pi" "resume did not report the recorded harness" + [ "$(git -C "$WT_DIR" rev-parse HEAD)" = "$old_head" ] \ + || fail "resume changed the recorded branch head" + assert_present "$WT_DIR/resume-uncommitted.txt" "resume discarded an uncommitted change" + assert_grep "worktree=$WT_DIR" "$meta" "resume metadata lost the recorded worktree" + assert_grep "model=cockpit/gpt-5.6-luna" "$meta" "resume metadata lost the actual resumed model" + assert_grep "effort=xhigh" "$meta" "resume metadata lost the actual resumed effort" + assert_grep "thinking=xhigh" "$meta" "resume metadata lost the actual resumed thinking level" + assert_grep "resume=1" "$meta" "resume metadata did not record same-branch recovery" + assert_grep "branch=wt-resume-existing" "$meta" "resume metadata did not record the resumed branch" + assert_absent "$LAUNCH_LOG.treehouse" "resume allocated a replacement treehouse worktree" + pass "--resume preserves commits and uncommitted changes while recording the actual profile" +} + test_antigravity_preflight_signal_killed_checker_refuses() { local rec id out status id=preflight-sigkill-z32 @@ -1098,7 +1290,7 @@ test_antigravity_preflight_signal_killed_checker_refuses() { PREFLIGHT_RESULT=signal-kill make_preflight_checker "$PREFLIGHT_BIN" - out=$(run_spawn "$HOME_DIR" "$WT_DIR" "$FAKEBIN_DIR" "$LAUNCH_LOG" "$id" "$PROJ_DIR" \ + out=$(run_ship_spawn "$HOME_DIR" "$WT_DIR" "$FAKEBIN_DIR" "$LAUNCH_LOG" "$id" "$PROJ_DIR" \ --model antigravity/gemini-3.6-flash --effort high) status=$? expect_code 1 "$status" "signal-killed checker must refuse Antigravity launch" @@ -1134,6 +1326,9 @@ test_claude_omits_config_dir_prefix_when_unset test_non_claude_harness_ignores_config_dir test_active_dispatch_profile_does_not_block_secondmate_launch test_antigravity_preflight_exit_zero_preserves_profile +test_antigravity_preflight_without_perl_uses_native_timeout +test_antigravity_preflight_prefers_compatible_gtimeout +test_antigravity_preflight_refuses_without_compatible_timeout test_antigravity_preflight_configured_profile_covers_scouts test_antigravity_preflight_all_unusable_falls_back_before_metadata test_antigravity_preflight_raw_launch_uses_fallback @@ -1149,6 +1344,7 @@ test_antigravity_preflight_uses_secondary_fallback_checker_path test_antigravity_preflight_embedded_raw_launch_model_uses_fallback test_antigravity_preflight_large_output_does_not_fail test_antigravity_preflight_space_in_home_path_succeeds +test_resume_reuses_recorded_worktree_and_profile test_antigravity_preflight_quoted_embedded_raw_launch_model_uses_fallback test_antigravity_preflight_signal_killed_checker_refuses