Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
204 changes: 108 additions & 96 deletions bin/fm-spawn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2200,6 +2200,83 @@ launch_template() {
esac
}

prepare_harness_launch() {
# muse, gemini, agy, devin, and rovo are verified as CREWMATE/SCOUT adapters
# only. A secondmate is a firstmate instance, so it needs a primary
# supervision protocol. None of these adapters has one: docs/supervision-protocols/
# carries no wake protocol for them. Refusing here keeps that gap loud.
if [ "$KIND" = secondmate ] && { [ "$HARNESS" = muse ] || [ "$HARNESS" = gemini ] || [ "$HARNESS" = agy ] || [ "$HARNESS" = devin ] || [ "$HARNESS" = rovo ]; }; then
echo "error: $HARNESS is a verified crewmate/scout adapter only and cannot run a secondmate; it has no primary supervision protocol. Select a harness verified for secondmates." >&2
exit 1
fi

PI_BIN='' PI_TUI_MODE='' CURSOR_BIN='' OMP_BIN='' AGY_BIN='' DEVIN_BIN=''
case "$HARNESS" in
devin)
DEVIN_BIN=$(command -v devin) || {
echo "error: devin executable not found on PATH" >&2
exit 1
}
;;
pi | pi-signed)
PI_BIN=$(resolve_pi_executable "$HARNESS") || {
echo "error: $HARNESS executable not found on PATH; install it or select a different verified harness" >&2
exit 1
}
PI_TUI_MODE=
if pi_supports_tui_mode "$PI_BIN"; then
PI_TUI_MODE=' --tui-mode regular'
fi
LAUNCH=${LAUNCH//__PITUIMODE__/$PI_TUI_MODE}
LAUNCH="FM_PI_HARNESS=$HARNESS $LAUNCH"
;;
cursor)
# `cursor` is not the CLI name, and the legacy alias `agent` is too generic
# to launch on its name alone, so resolution runs through the verified owner.
CURSOR_BIN=$(fm_cursor_resolve_binary) || exit 1
if [ -n "$MODEL" ] && [ "$MODEL" != default ]; then
if CURSOR_MODELS=$(fm_cursor_list_models "$CURSOR_BIN"); then
if ! printf '%s\n' "$CURSOR_MODELS" | fm_cursor_catalog_has_model "$MODEL"; then
echo "error: Cursor model '$MODEL' is not available from '$CURSOR_BIN --list-models'; choose an id listed by that command or omit --model" >&2
exit 1
fi
fi
fi
;;
omp)
OMP_BIN=$(resolve_pi_executable omp) || {
echo "error: omp executable not found on PATH; install Oh My Pi or select a different verified harness" >&2
exit 1
}
OMP_WORKER_CFG="$FM_ROOT/.omp/fm-worker-overlay.yml"
[ -f "$OMP_WORKER_CFG" ] || {
echo "error: omp worker posture overlay missing at $OMP_WORKER_CFG; a worker launched without it can park on the captain's own approval or plan-mode settings" >&2
exit 1
}
;;
agy)
AGY_BIN=$(resolve_pi_executable agy) || {
echo "error: agy executable not found on PATH; install Antigravity CLI or select a different verified harness" >&2
exit 1
}
;;
esac

if [ "$EFFORT" = ultra ]; then
"$SCRIPT_DIR/fm-harness.sh" validate-native-effort "$HARNESS" "$MODEL" "$EFFORT" || exit 1
[ "$RAW_LAUNCH" = 0 ] || {
echo "error: --effort ultra requires the canonical --harness pi or pi-signed launch so its native flag cannot be omitted" >&2
exit 1
}
fi
if [ "$HARNESS" = omp ]; then
omp_model_validate "$OMP_BIN" "$MODEL" || exit 1
fi
if [ "$HARNESS" = agy ]; then
agy_model_validate "$AGY_BIN" "$MODEL" || exit 1
fi
}

case "$ARG3" in
*' '*) # raw launch command (unverified-adapter escape hatch)
RAW_LAUNCH=1
Expand Down Expand Up @@ -2247,88 +2324,6 @@ case "$ARG3" in
;;
esac

# muse, gemini, agy, and devin are verified as CREWMATE/SCOUT adapters only. A secondmate is
# a firstmate instance, so it needs a primary supervision protocol.
# gemini has none: docs/supervision-protocols/ carries no gemini wake protocol
# and this task verified only crewmate-side launch, busy state, interrupt, and
# exit, so a gemini secondmate is refused rather than stood up on an unverified
# supervision path. muse has none either, and its
# Claude-compatible hook dialect explicitly rejects the model-reawakening and
# asyncRewake handlers that firstmate's primary turn-end supervision is built on
# (muse 0.1.0-R708.1). Refusing here keeps that gap loud instead of standing up a
# secondmate whose supervision cycle could never be armed.
# agy has none either: it exposes no hook surface for primary supervision and
# docs/supervision-protocols/ carries no agy wake protocol (agy 1.2.0).
# devin has none either: only its worker lifecycle hooks are verified, and
# docs/supervision-protocols/ carries no devin wake protocol (devin 3000.11.1).
if [ "$KIND" = secondmate ] && { [ "$HARNESS" = muse ] || [ "$HARNESS" = gemini ] || [ "$HARNESS" = agy ] || [ "$HARNESS" = devin ]; }; then
echo "error: $HARNESS is a verified crewmate/scout adapter only and cannot run a secondmate; it has no primary supervision protocol. Select a harness verified for secondmates." >&2
exit 1
fi

# rovo carries the same primary-supervision gap as muse: no turn-end hook, no
# verified primary integration, so a secondmate (a firstmate instance that must
# itself act as a primary) could never be supervised. Refuse loudly rather than
# standing one up with no way to arm its watch cycle.
if [ "$KIND" = secondmate ] && [ "$HARNESS" = rovo ]; then
echo "error: rovo is a verified crewmate/scout adapter only and cannot run a secondmate; it has no primary supervision protocol. Select a harness verified for secondmates." >&2
exit 1
fi

case "$HARNESS" in
devin)
DEVIN_BIN=$(command -v devin) || {
echo "error: devin executable not found on PATH" >&2
exit 1
}
;;
pi | pi-signed)
PI_BIN=$(resolve_pi_executable "$HARNESS") || {
echo "error: $HARNESS executable not found on PATH; install it or select a different verified harness" >&2
exit 1
}
PI_TUI_MODE=
if pi_supports_tui_mode "$PI_BIN"; then
PI_TUI_MODE=' --tui-mode regular'
fi
LAUNCH=${LAUNCH//__PITUIMODE__/$PI_TUI_MODE}
LAUNCH="FM_PI_HARNESS=$HARNESS $LAUNCH"
;;
cursor)
# `cursor` is not the CLI name, and the legacy alias `agent` is far too
# generic to launch on its name alone, so resolution runs through the
# verified owner rather than a bare command lookup. Refusing here keeps a
# missing install a loud spawn refusal instead of a pane that dies with a
# command-not-found the supervisor would read as a wedged worker.
CURSOR_BIN=$(fm_cursor_resolve_binary) || exit 1
if [ -n "$MODEL" ] && [ "$MODEL" != default ]; then
if CURSOR_MODELS=$(fm_cursor_list_models "$CURSOR_BIN"); then
if ! printf '%s\n' "$CURSOR_MODELS" | fm_cursor_catalog_has_model "$MODEL"; then
echo "error: Cursor model '$MODEL' is not available from '$CURSOR_BIN --list-models'; choose an id listed by that command or omit --model" >&2
exit 1
fi
fi
fi
;;
omp)
OMP_BIN=$(resolve_pi_executable omp) || {
echo "error: omp executable not found on PATH; install Oh My Pi or select a different verified harness" >&2
exit 1
}
OMP_WORKER_CFG="$FM_ROOT/.omp/fm-worker-overlay.yml"
[ -f "$OMP_WORKER_CFG" ] || {
echo "error: omp worker posture overlay missing at $OMP_WORKER_CFG; a worker launched without it can park on the captain's own approval or plan-mode settings" >&2
exit 1
}
;;
agy)
AGY_BIN=$(resolve_pi_executable agy) || {
echo "error: agy executable not found on PATH; install Antigravity CLI or select a different verified harness" >&2
exit 1
}
;;
esac

# config/secondmate-harness may carry optional model/effort tokens alongside the
# harness ("<harness> [<model>] [<effort>]"). They apply only when this is a
# --secondmate spawn and no explicit per-spawn harness/raw launch was supplied, so
Expand All @@ -2350,20 +2345,37 @@ if [ "$KIND" = secondmate ] && [ -z "$ARG3" ]; then
fi
fi
fi
# Ultra is an explicit native capability, never a Pi thinking-level alias.
# Validate the fully resolved profile before worktree or endpoint provisioning.
if [ "$EFFORT" = ultra ]; then
"$SCRIPT_DIR/fm-harness.sh" validate-native-effort "$HARNESS" "$MODEL" "$EFFORT" || exit 1
[ "$RAW_LAUNCH" = 0 ] || {
echo "error: --effort ultra requires the canonical --harness pi or pi-signed launch so its native flag cannot be omitted" >&2
exit 1
}
fi
if [ "$HARNESS" = omp ]; then
omp_model_validate "$OMP_BIN" "$MODEL" || exit 1
fi
if [ "$HARNESS" = agy ]; then
agy_model_validate "$AGY_BIN" "$MODEL" || exit 1
prepare_harness_launch

# Jev Pattern 9: Pre-flight runway and token health prober
JEV_QUOTA_PROBER=${FM_TEST_JEV_PROBER_PATH:-$SCRIPT_DIR/fm-jev-quota-prober.sh}
if [ "${FM_TEST_DISABLE_JEV_PROBER:-0}" != 1 ] && [ -x "$JEV_QUOTA_PROBER" ]; then
if ! "$JEV_QUOTA_PROBER" --harness "$HARNESS" ${MODEL:+--model "$MODEL"} >/dev/null 2>&1; then
_divert=$("$JEV_QUOTA_PROBER" --harness "$HARNESS" ${MODEL:+--model "$MODEL"} --auto-divert 2>/dev/null || true)
# Read only the harness= and model= tokens; prober output is never executed.
harness='' model=''
read -r -a _divert_tokens <<<"${_divert//$'\n'/ }"
for _tok in ${_divert_tokens[@]+"${_divert_tokens[@]}"}; do
case "$_tok" in
harness=*) harness=${_tok#harness=} ;;
model=*) model=${_tok#model=} ;;
esac
done
if [ -n "$harness" ] && [ -n "$model" ]; then
if [ "$RAW_LAUNCH" = 1 ]; then
echo "error: refusing to divert raw launch command '$ARG3': lane $HARNESS${MODEL:+:$MODEL} is exhausted (divert target $harness:$model); the raw launch command runs verbatim" >&2
else
echo "jev-quota-prober: automatically diverted $HARNESS${MODEL:+:$MODEL} to viable lane $harness:$model" >&2
HARNESS="$harness"
MODEL="$model"
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
LAUNCH=$(launch_template "$HARNESS" "$KIND") || {
echo "error: no launch template for diverted harness '$HARNESS'" >&2
exit 1
}
prepare_harness_launch
fi
fi
fi
fi
# Worker account pin (header above): resolved before any endpoint, worktree, or
# record exists. An absent pin selects nothing and leaves every later launch
Expand Down
6 changes: 5 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ While the file exists, main's lease-checked commands also take the per-task leas
## Backlog backend (.tasks.toml / config/backlog-backend)

The tracked `.tasks.toml` pins the default `tasks-axi` markdown backend to `data/backlog.md`, with `done_keep = 10` and an archive at `data/done-archive.md`.
Those defaults apply only to a backlog whose data directory's parent holds that file (`bin/fm-backlog-transition-lib.sh`); bootstrap does not copy it, so a separate operational home with no `.tasks.toml` of its own gets tasks-axi's built-in retention and archive defaults until one is placed there.
A home may instead select another tasks-axi adapter such as Beads through its own `.tasks.toml` or `TASKS_AXI_BACKEND`; firstmate still uses only tasks-axi verbs for routine backlog reads and mutations, and the adapter maps `start` and evidence-bearing `done` transitions to its native statuses and evidence fields.

### Captain holds on Beads
Expand Down Expand Up @@ -769,7 +770,10 @@ Changing this pin affects the next secondmate spawn or control-plane relaunch; t

### Per-launch overrides and inherited defaults

An explicit harness argument to `fm-spawn.sh` still overrides either config file for that spawn only.
An explicit harness argument to `fm-spawn.sh` overrides either config file when selecting the initial launch profile for that spawn.
Before creating the worker, `fm-spawn.sh` can run the pre-flight quota prober and divert an unhealthy supported harness and model to the prober's viable lane, including across harnesses; the diverted harness receives its own executable resolution, validation, and launch setup rather than retaining the original harness's setup, while a raw launch command is never diverted.
The quota prober is not shipped in this repository, so the divert hook stays inert until an executable `bin/fm-jev-quota-prober.sh` is installed alongside `fm-spawn.sh`; `fm-spawn.sh` reads only the `harness=` and `model=` tokens from its `--auto-divert` output and never executes it.
The prober owns the health checks and diversion target and [`fm-spawn.sh`](../bin/fm-spawn.sh) owns applying that result to the launch.
An explicit `--model` or `--effort` overrides the matching token from `config/secondmate-harness`; for a local route, an explicit harness or raw launch command starts with clean model and effort defaults unless those flags are also passed.

Remote secondmate routes accept verified harness adapters only and reject raw launch commands.
Expand Down
Loading
Loading