Skip to content

feat(bin): run a per-project setup hook in fresh task worktrees before launch - #1

Merged
clarsen merged 4 commits into
mainfrom
fm/project-setup-hook-v2
Sep 23, 2026
Merged

clarsen merged 4 commits into
mainfrom
fm/project-setup-hook-v2

Conversation

@clarsen

@clarsen clarsen commented Sep 23, 2026

Copy link
Copy Markdown
Owner

Intent

i have taskbase project in github. when checking out, you also need to do this to initialize worktree before invoking agent harness:
git clone https://github.com/clarsen/bmad-submodule.git
(cd bmad-submodule; git checkout ctlarsen-v6.12.1-2026-09-10)
bmad-submodule/install.sh

Context: Firstmate creates a task worktree and launches the agent in one spawn step, with no point in between where a per-project setup can run. The chosen fix is a per-project setup hook in Firstmate: a private per-project setup script that runs in each new task worktree before the agent launches, so the taskbase bmad setup (and similar setups for other projects) happens automatically on every launch.

What Changed

  • bin/fm-spawn.sh now looks for an optional local, gitignored config/project-setup/<project>.sh, where <project> is the project directory's basename. On a fresh ship or scout spawn it runs this script in the task worktree after the base refresh and before any harness wiring or worker launch. The script runs with no stdin, sends its output to stderr, gets FM_TASK_ID, FM_TASK_KIND, FM_PROJECT, FM_PROJECT_DIR and FM_WORKTREE in its environment, and is time-limited by FM_PROJECT_SETUP_TIMEOUT (600s by default). Relaunches and secondmate spawns never run it.
  • The spawn refuses before any worktree or endpoint exists if the script is not an executable regular file or the timeout is not a positive whole number. After allocation, it refuses the launch and leaves the worktree for inspection if the script exits nonzero, times out, or leaves changes that git can see. The Treehouse project lock is released while the script runs and taken back afterwards, but the home's task-set lock stays held.
  • Adds docs/configuration.md "Project setup hook", a matching AGENTS.md config entry, and tests/fm-spawn-project-setup.test.sh (registered in the backend-dispatch family in bin/fm-test-run.sh).

Risk Assessment

✅ Low: The hook is opt-in and absent by default. It is checked before any side effects, and the timeout kills the whole process group. The Treehouse project lock is released and taken back symmetrically, and the exit trap already covers a claim left behind when the lock is not held. Behavioral tests cover success, failure, timeout, git-visible output, bad config and a concurrent same-project return.

Testing

I ran the focused project-setup-hook test suite (all 8 passed). I then drove nine live scenarios against the real product: real fm-spawn and fm-teardown, a throwaway fm-lab Herdr session, real Treehouse pool worktrees in a scratch root, and a local copy of the real taskbase repo running your exact bmad-submodule clone, checkout and install. All nine passed. I first ran the focused suite with the default TMPDIR (~/tmp); it failed its first case because the folder on disk is actually /Tmp, and Treehouse rejected the case-mismatched path. That is a quirk of this machine, not a product bug, so I reran with TMPDIR=/Tmp. An earlier live attempt used the default ~/.treehouse pool and left five orphaned scratch slots there. Four came from two harness mistakes (the teardown call lacked FM_HOME, and a regex missed the timeout-case worktree path) and one from deleting the scratch repo before returning its slot. I removed them and reran with the pool inside the scratch directory. This is CLI and terminal behaviour only, so the evidence is a transcript, not screenshots. The lab session, scratch homes and pool worktrees were all torn down, and the worktree is clean.

  • Live validation: ✅ go - 9 of 10 scenarios driven live against the product
Scenario Result Live Evidence
Ship spawn of taskbase runs the operator's bmad clone, checkout and install.sh in the fresh worktree before the agent starts; the agent sees bmad-submodule at the tag, the _bmad and .agents links, and… ✅ pass live live-setup-hook-lab.log S1: hook output comes before the 'spawned tb-ship1' line; the pane shows the checkout ctlarsen-v6.12.1-2026-09-10 @ 271ea3c and git-status-lines: 0
Hook receives FM_TASK_ID, FM_TASK_KIND and FM_PROJECT, with the task worktree as its working directory, for both ship and scout ✅ pass live live-setup-hook-lab.log S1 and S3 'hook:' lines (kind=ship and kind=scout, cwd = the pool slot)
Teardown of a task whose worktree was set up by the hook is not blocked by the setup output ✅ pass live live-setup-hook-lab.log S2: fm-teardown.sh without --force exits 0, the worktree returns to the pool and the meta is removed
A reused pool slot re-runs the hook over its earlier bmad output without errors ✅ pass live live-setup-hook-lab.log S3: same slot as S1 = yes, 'Already on ctlarsen-v6.12.1-2026-09-10', install complete, the scout agent launches
A hook that exits nonzero refuses the launch, names the script and exit status, publishes no task, and leaves the worktree for inspection ✅ pass live live-setup-hook-lab.log S4: 'exited with status 7 ... refusing to launch the agent', exit=1, no task meta
A hook that runs past FM_PROJECT_SETUP_TIMEOUT is killed and the launch is refused ✅ pass live live-setup-hook-lab.log S5: 'timed out after 3s', exit=1 after 6s (the hook sleeps 120s), no task meta
A hook that leaves files git can see refuses the launch and lists them ✅ pass live live-setup-hook-lab.log S6: 'left changes git can see' with '?? setup-junk.txt', exit=1
A non-executable hook, or an invalid FM_PROJECT_SETUP_TIMEOUT, refuses before any Herdr pane or worktree is created ✅ pass live live-setup-hook-lab.log S7/S8: error messages, exit=1, pane count 4 before and 4 after
A project with no setup script spawns exactly as before ✅ pass live live-setup-hook-lab.log S9: 'spawned other1', no 'project setup' output
Relaunch never re-runs the hook, and secondmate spawns never run it ⏸️ untested no Not driven live: no tool or credential was missing. It needs a lab relaunch of an existing Herdr task and a secondmate home, which were out of scope for this proportionate pass. Add both to the live l…
Evidence: Live Herdr lab transcript (all 9 scenarios)

Source: Live Herdr lab transcript (all 9 scenarios)


===== provision lab fm-lab-setuphook-90881-32424 =====

===== scratch taskbase project (local bare mirror of github clarsen/taskbase) =====
55b1d21 feat(e48): row-click selection — ⌘/Shift-click the row, no checkbox (#74)

===== S1 ship spawn of taskbase runs the real bmad setup before launch =====
warning: ~/Tmp/fm-setup-live.RnpbaD/home/data/tb-ship1/launch-brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
project setup: running ~/Tmp/fm-setup-live.RnpbaD/home/config/project-setup/taskbase.sh in ~/Tmp/fm-setup-live.RnpbaD/treehouse-pool/.treehouse/taskbase-c2af62/1/taskbase (timeout 600s)
hook: FM_TASK_ID=tb-ship1 FM_TASK_KIND=ship FM_PROJECT=taskbase cwd=~/Tmp/fm-setup-live.RnpbaD/treehouse-pool/.treehouse/taskbase-c2af62/1/taskbase
Cloning into 'bmad-submodule'...
Switched to a new branch 'ctlarsen-v6.12.1-2026-09-10'
branch 'ctlarsen-v6.12.1-2026-09-10' set up to track 'origin/ctlarsen-v6.12.1-2026-09-10'.
Install complete in ~/Tmp/fm-setup-live.RnpbaD/treehouse-pool/.treehouse/taskbase-c2af62/1/taskbase
Next: edit _bmad/custom/projects.toml to register your project(s).
spawned tb-ship1 harness=bash kind=ship mode=no-mistakes yolo=off window=fm-lab-setuphook-90881-32424:w1:p2 worktree=~/Tmp/fm-setup-live.RnpbaD/treehouse-pool/.treehouse/taskbase-c2af62/1/taskbase
exit=0
meta worktree=~/Tmp/fm-setup-live.RnpbaD/treehouse-pool/.treehouse/taskbase-c2af62/1/taskbase pane=w1:p2
--- agent pane capture ---
AGENT-START cwd=~/Tmp/fm-setup-live.RnpbaD/treehouse-pool/.treehouse/taskbase-c2af62/1/taskbase
AGENT bmad-submodule checkout: ctlarsen-v6.12.1-2026-09-10 @ 271ea3c
AGENT .agents -> bmad-submodule/.agents
AGENT _bmad entries: _config _memory bmad-loop bmb bmm cis config.toml config.user.toml core custom render scripts tea w
AGENT git-status-lines: 0
AGENT-END
--- worktree git status (expect empty) ---
[end status]

===== S2 teardown of the set-up ship task is not blocked by setup output =====
●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
teardown: reaping leaked worktree process(es) for tb-ship1: 92018 93099 93134 94123
teardown: force-killing leaked worktree process(es) for tb-ship1: 92018
🌳 Worktree returned to pool.
~/Tmp/fm-setup-live.RnpbaD/taskbase: already current
teardown tb-ship1 complete (window fm-lab-setuphook-90881-32424:w1:p2, worktree ~/Tmp/fm-setup-live.RnpbaD/treehouse-pool/.treehouse/taskbase-c2af62/1/taskbase)
Backlog: tb-ship1 just finished (this home keeps no markdown backlog at ~/Tmp/fm-setup-live.RnpbaD/home/data/backlog.md). Update ~/Tmp/fm-setup-live.RnpbaD/home/data/backlog.md - move tb-ship1 to Done, keep Done to the 10 most recent, then re-scan Queued and dispatch only work whose blockers are gone and date is due.
teardown exit=0
meta removed

===== S3 scout spawn reuses the pooled slot; hook is idempotent over its earlier output =====
project setup: running ~/Tmp/fm-setup-live.RnpbaD/home/config/project-setup/taskbase.sh in ~/Tmp/fm-setup-live.RnpbaD/treehouse-pool/.treehouse/taskbase-c2af62/1/taskbase (timeout 600s)
hook: FM_TASK_ID=tb-scout1 FM_TASK_KIND=scout FM_PROJECT=taskbase cwd=~/Tmp/fm-setup-live.RnpbaD/treehouse-pool/.treehouse/taskbase-c2af62/1/taskbase
Already on 'ctlarsen-v6.12.1-2026-09-10'
Your branch is up to date with 'origin/ctlarsen-v6.12.1-2026-09-10'.
Install complete in ~/Tmp/fm-setup-live.RnpbaD/treehouse-pool/.treehouse/taskbase-c2af62/1/taskbase
Next: edit _bmad/custom/projects.toml to register your project(s).
spawned tb-scout1 harness=bash kind=scout window=fm-lab-setuphook-90881-32424:w2:p2 worktree=~/Tmp/fm-setup-live.RnpbaD/treehouse-pool/.treehouse/taskbase-c2af62/1/taskbase
exit=0
meta worktree=~/Tmp/fm-setup-live.RnpbaD/treehouse-pool/.treehouse/taskbase-c2af62/1/taskbase (same slot as S1: yes) pane=w2:p2
AGENT-START cwd=~/Tmp/fm-setup-live.RnpbaD/treehouse-pool/.treehouse/taskbase-c2af62/1/taskbase
AGENT bmad-submodule checkout: ctlarsen-v6.12.1-2026-09-10 @ 271ea3c
AGENT .agents -> bmad-submodule/.agents
AGENT _bmad entries: _config _memory bmad-loop bmb bmm cis config.toml config.user.toml core custom render scripts tea w
AGENT git-status-lines: 0
AGENT-END

===== S4 failing hook refuses the launch and publishes no task =====
warning: ~/Tmp/fm-setup-live.RnpbaD/home/data/tb-fail1/launch-brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
project setup: running ~/Tmp/fm-setup-live.RnpbaD/home/config/project-setup/taskbase.sh in ~/Tmp/fm-setup-live.RnpbaD/treehouse-pool/.treehouse/taskbase-c2af62/2/taskbase (timeout 600s)
clone failed (simulated)
error: project setup script ~/Tmp/fm-setup-live.RnpbaD/home/config/project-setup/taskbase.sh exited with status 7 in ~/Tmp/fm-setup-live.RnpbaD/treehouse-pool/.treehouse/taskbase-c2af62/2/taskbase; refusing to launch the agent; inspect window fm-lab-setuphook-90881-32424:w2:p3
exit=1
left worktree for inspection: ~/Tmp/fm-setup-live.RnpbaD/treehouse-pool/.treehouse/taskbase-c2af62/2/taskbase
no task meta published
panes before=1 after=2

===== S5 hook exceeding FM_PROJECT_SETUP_TIMEOUT refuses the launch =====
warning: ~/Tmp/fm-setup-live.RnpbaD/home/data/tb-hang1/launch-brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
project setup: running ~/Tmp/fm-setup-live.RnpbaD/home/config/project-setup/taskbase.sh in ~/Tmp/fm-setup-live.RnpbaD/treehouse-pool/.treehouse/taskbase-c2af62/3/taskbase (timeout 3s)
hanging
error: project setup script ~/Tmp/fm-setup-live.RnpbaD/home/config/project-setup/taskbase.sh timed out after 3s in ~/Tmp/fm-setup-live.RnpbaD/treehouse-pool/.treehouse/taskbase-c2af62/3/taskbase (FM_PROJECT_SETUP_TIMEOUT); refusing to launch the agent; inspect window fm-lab-setuphook-90881-32424:w2:p4
exit=1 elapsed=6s
no task meta published

===== S6 hook leaving git-visible output refuses the launch =====
warning: ~/Tmp/fm-setup-live.RnpbaD/home/data/tb-dirty1/launch-brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
project setup: running ~/Tmp/fm-setup-live.RnpbaD/home/config/project-setup/taskbase.sh in ~/Tmp/fm-setup-live.RnpbaD/treehouse-pool/.treehouse/taskbase-c2af62/4/taskbase (timeout 600s)
error: project setup script ~/Tmp/fm-setup-live.RnpbaD/home/config/project-setup/taskbase.sh left changes git can see in ~/Tmp/fm-setup-live.RnpbaD/treehouse-pool/.treehouse/taskbase-c2af62/4/taskbase; exclude its output (for example in $(git rev-parse --git-path info/exclude)) so it cannot be committed or block cleanup; refusing to launch the agent; inspect window fm-lab-setuphook-90881-32424:w2:p5:
?? setup-junk.txt
exit=1
no task meta published

===== S7 non-executable hook refuses before any pane or worktree exists =====
error: project setup script ~/Tmp/fm-setup-live.RnpbaD/home/config/project-setup/taskbase.sh must be an executable regular file; refusing to launch without the setup it declares
exit=1 panes before=4 after=4

===== S8 bad FM_PROJECT_SETUP_TIMEOUT refuses before any pane =====
error: FM_PROJECT_SETUP_TIMEOUT must be a positive whole number of seconds (got '0')
exit=1 panes before=4 after=4

===== S9 project without a setup script spawns unchanged =====
warning: ~/Tmp/fm-setup-live.RnpbaD/home/data/other1/launch-brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
spawned other1 harness=bash kind=ship mode=no-mistakes yolo=off window=fm-lab-setuphook-90881-32424:w2:p6 worktree=~/Tmp/fm-setup-live.RnpbaD/treehouse-pool/.treehouse/otherproj-4929dd/1/otherproj
exit=0
no project setup activity

===== cleanup =====
returned ~/Tmp/fm-setup-live.RnpbaD/treehouse-pool/.treehouse/taskbase-c2af62/1/taskbase
returned ~/Tmp/fm-setup-live.RnpbaD/treehouse-pool/.treehouse/taskbase-c2af62/1/taskbase
returned ~/Tmp/fm-setup-live.RnpbaD/treehouse-pool/.treehouse/taskbase-c2af62/2/taskbase
returned ~/Tmp/fm-setup-live.RnpbaD/treehouse-pool/.treehouse/taskbase-c2af62/3/taskbase
returned ~/Tmp/fm-setup-live.RnpbaD/treehouse-pool/.treehouse/taskbase-c2af62/4/taskbase
returned ~/Tmp/fm-setup-live.RnpbaD/treehouse-pool/.treehouse/otherproj-4929dd/1/otherproj
lab fm-lab-setuphook-90881-32424 torn down
Evidence: Live lab driver script

Source: Live lab driver script

#!/usr/bin/env bash
# Live validation of config/project-setup/<project>.sh against a real Herdr lab
# session, real treehouse pool worktrees, and a scratch copy of the real
# clarsen/taskbase repo, using the operator's exact bmad setup commands.
set -u
ROOT=~/.no-mistakes/worktrees/bf7f38e6f6d2/01M36E07187GAE99XBGW38PPTX
EV=~/.no-mistakes/evidence/01M36E07187GAE99XBGW38PPTX
LAB="$ROOT/bin/fm-herdr-lab.sh"
unset HERDR_ENV HERDR_PANE_ID HERDR_TAB_ID HERDR_WORKSPACE_ID HERDR_SOCKET_PATH HERDR_SESSION
export FM_GATE_REFUSE_BYPASS=1
SESSION=$("$LAB" name setuphook)
export HERDR_SESSION="$SESSION"
TMP_ROOT=$(mktemp -d "$(cd ~/Tmp && pwd -P)/fm-setup-live.XXXXXX")
export TREEHOUSE_ROOT="$TMP_ROOT/treehouse-pool"
WTS=()
say() { printf '\n===== %s =====\n' "$*"; }
cleanup() {
  say "cleanup"
  local w
  for w in "${WTS[@]}"; do [ -n "$w" ] && treehouse return --force "$w" >/dev/null 2>&1 && echo "returned $w"; done
  "$LAB" teardown "$SESSION" && echo "lab $SESSION torn down"
  rm -rf "$TMP_ROOT"
}
trap cleanup EXIT

say "provision lab $SESSION"
"$LAB" provision "$SESSION" || exit 1

HOME_DIR="$TMP_ROOT/home"
mkdir -p "$HOME_DIR/state" "$HOME_DIR/config" "$HOME_DIR/projects"
printf 'off\n' > "$HOME_DIR/config/herdr-presentation-spaces"
brief() { mkdir -p "$HOME_DIR/data/$1"; printf '# Task\n## Captain'"'"'s intent\nLive setup hook check.\n\n## Firstmate spec\nNothing.\n' > "$HOME_DIR/data/$1/brief.md"; }

say "scratch taskbase project (local bare mirror of github clarsen/taskbase)"
git clone --quiet --bare https://github.com/clarsen/taskbase.git "$TMP_ROOT/taskbase.origin.git" || exit 1
git clone --quiet "file://$TMP_ROOT/taskbase.origin.git" "$TMP_ROOT/taskbase" || exit 1
git -C "$TMP_ROOT/taskbase" log --oneline -1
mkdir -p "$TMP_ROOT/otherproj"; git -C "$TMP_ROOT/otherproj" init -q -b main
echo x > "$TMP_ROOT/otherproj/README.md"; git -C "$TMP_ROOT/otherproj" add README.md
git -C "$TMP_ROOT/otherproj" -c user.name=t -c [email protected] commit -qm init
git clone --quiet --bare "$TMP_ROOT/otherproj" "$TMP_ROOT/otherproj.origin.git"
git -C "$TMP_ROOT/otherproj" remote add origin "file://$TMP_ROOT/otherproj.origin.git"

install_hook() { mkdir -p "$HOME_DIR/config/project-setup"; printf '#!/usr/bin/env bash\n%s\n' "$1" > "$HOME_DIR/config/project-setup/taskbase.sh"; chmod 0755 "$HOME_DIR/config/project-setup/taskbase.sh"; }
# The operator's exact commands, made safe to re-run on a reused pool slot.
TASKBASE_HOOK='set -euo pipefail
echo "hook: FM_TASK_ID=$FM_TASK_ID FM_TASK_KIND=$FM_TASK_KIND FM_PROJECT=$FM_PROJECT cwd=$(pwd)"
[ -d bmad-submodule/.git ] || git clone https://github.com/clarsen/bmad-submodule.git
(cd bmad-submodule; git checkout ctlarsen-v6.12.1-2026-09-10)
bmad-submodule/install.sh'
AGENT="$TMP_ROOT/agent.sh"
cat > "$AGENT" <<'EOF'
echo "AGENT-START cwd=$(pwd)"
echo "AGENT bmad-submodule checkout: $(git -C bmad-submodule rev-parse --abbrev-ref HEAD) @ $(git -C bmad-submodule rev-parse --short HEAD)"
echo "AGENT .agents -> $(readlink .agents)"
echo "AGENT _bmad entries: $(ls _bmad | tr '\n' ' ')"
echo "AGENT git-status-lines: $(git status --porcelain | wc -l | tr -d ' ')"
echo AGENT-END
sleep 900
EOF

spawn() { # <id> <project> [args...]
  local id=$1 proj=$2; shift 2
  FM_SPAWN_NO_GUARD=1 FM_HOME="$HOME_DIR" FM_ROOT_OVERRIDE="$ROOT" \
    "$ROOT/bin/fm-spawn.sh" "$id" "$proj" "bash $AGENT" --backend herdr "$@" 2>&1
}
panes() { herdr pane list --session "$SESSION" 2>/dev/null | jq -r '[.result.panes[]?] | length'; }
. "$ROOT/bin/fm-backend.sh"; fm_backend_source herdr
capture() { fm_backend_herdr_capture "$SESSION:$1" 40; }
meta_val() { grep "^$2=" "$HOME_DIR/state/$1.meta" 2>/dev/null | cut -d= -f2-; }
wt_from_err() { printf '%s\n' "$1" | sed -n 's/.* in \(\/[^ ;:]*\).*/\1/p' | head -1; }

say "S1 ship spawn of taskbase runs the real bmad setup before launch"
brief tb-ship1
install_hook "$TASKBASE_HOOK"
out=$(spawn tb-ship1 "$TMP_ROOT/taskbase" --mode no-mistakes --yolo off); rc=$?
printf '%s\n' "$out"; echo "exit=$rc"
WT1=$(meta_val tb-ship1 worktree); WTS+=("$WT1"); P1=$(meta_val tb-ship1 herdr_pane_id)
echo "meta worktree=$WT1 pane=$P1"
sleep 3
echo "--- agent pane capture ---"; capture "$P1" | grep AGENT
echo "--- worktree git status (expect empty) ---"; git -C "$WT1" status --porcelain; echo "[end status]"

say "S2 teardown of the set-up ship task is not blocked by setup output"
FM_HOME="$HOME_DIR" FM_ROOT_OVERRIDE="$ROOT" FM_STATE_OVERRIDE="$HOME_DIR/state" FM_DATA_OVERRIDE="$HOME_DIR/data" FM_CONFIG_OVERRIDE="$HOME_DIR/config" \
  "$ROOT/bin/fm-teardown.sh" tb-ship1 2>&1 | tail -8; echo "teardown exit=${PIPESTATUS[0]}"
[ -f "$HOME_DIR/state/tb-ship1.meta" ] && echo "meta still present" || echo "meta removed"

say "S3 scout spawn reuses the pooled slot; hook is idempotent over its earlier output"
brief tb-scout1
out=$(spawn tb-scout1 "$TMP_ROOT/taskbase" --scout); rc=$?
printf '%s\n' "$out"; echo "exit=$rc"
WT2=$(meta_val tb-scout1 worktree); WTS+=("$WT2"); P2=$(meta_val tb-scout1 herdr_pane_id)
echo "meta worktree=$WT2 (same slot as S1: $([ "$WT2" = "$WT1" ] && echo yes || echo no)) pane=$P2"
sleep 3; capture "$P2" | grep AGENT

say "S4 failing hook refuses the launch and publishes no task"
brief tb-fail1
install_hook 'echo "clone failed (simulated)" >&2; exit 7'
before=$(panes)
out=$(spawn tb-fail1 "$TMP_ROOT/taskbase" --mode no-mistakes --yolo off); rc=$?
printf '%s\n' "$out"; echo "exit=$rc"
w=$(wt_from_err "$out"); WTS+=("$w"); echo "left worktree for inspection: $w"
[ -f "$HOME_DIR/state/tb-fail1.meta" ] && echo "meta PRESENT (bad)" || echo "no task meta published"
echo "panes before=$before after=$(panes)"

say "S5 hook exceeding FM_PROJECT_SETUP_TIMEOUT refuses the launch"
brief tb-hang1
install_hook 'echo "hanging"; sleep 120'
start=$(date +%s)
out=$(FM_PROJECT_SETUP_TIMEOUT=3 spawn tb-hang1 "$TMP_ROOT/taskbase" --mode no-mistakes --yolo off); rc=$?
printf '%s\n' "$out"; echo "exit=$rc elapsed=$(( $(date +%s) - start ))s"
w=$(wt_from_err "$out"); WTS+=("$w")
[ -f "$HOME_DIR/state/tb-hang1.meta" ] && echo "meta PRESENT (bad)" || echo "no task meta published"

say "S6 hook leaving git-visible output refuses the launch"
brief tb-dirty1
install_hook 'echo junk > setup-junk.txt'
out=$(spawn tb-dirty1 "$TMP_ROOT/taskbase" --mode no-mistakes --yolo off); rc=$?
printf '%s\n' "$out"; echo "exit=$rc"
w=$(wt_from_err "$out"); WTS+=("$w")
[ -n "$w" ] && rm -f "$w/setup-junk.txt"
[ -f "$HOME_DIR/state/tb-dirty1.meta" ] && echo "meta PRESENT (bad)" || echo "no task meta published"

say "S7 non-executable hook refuses before any pane or worktree exists"
brief tb-noexec1
install_hook 'echo should-not-run'; chmod 0644 "$HOME_DIR/config/project-setup/taskbase.sh"
before=$(panes)
out=$(spawn tb-noexec1 "$TMP_ROOT/taskbase" --mode no-mistakes --yolo off); rc=$?
printf '%s\n' "$out"; echo "exit=$rc panes before=$before after=$(panes)"

say "S8 bad FM_PROJECT_SETUP_TIMEOUT refuses before any pane"
install_hook 'echo should-not-run'
before=$(panes)
out=$(FM_PROJECT_SETUP_TIMEOUT=0 spawn tb-noexec1 "$TMP_ROOT/taskbase" --mode no-mistakes --yolo off); rc=$?
printf '%s\n' "$out"; echo "exit=$rc panes before=$before after=$(panes)"

say "S9 project without a setup script spawns unchanged"
brief other1
out=$(spawn other1 "$TMP_ROOT/otherproj" --mode no-mistakes --yolo off); rc=$?
printf '%s\n' "$out"; echo "exit=$rc"
WTS+=("$(meta_val other1 worktree)")
printf '%s\n' "$out" | grep -q "project setup" && echo "mentions project setup (bad)" || echo "no project setup activity"
Evidence: Focused hook test output

Source: Focused hook test output

ok - an absent project setup script leaves the spawn unchanged
ok - a ship spawn runs the project setup script in the task worktree before launching the agent
ok - a scout spawn runs the project setup script in the task worktree before launching the agent
ok - a failing project setup script refuses the launch and leaves the worktree for inspection
ok - a project setup script that outlives FM_PROJECT_SETUP_TIMEOUT refuses the launch
ok - a project setup script whose output git can see refuses the launch
ok - an invalid project setup script or timeout refuses before any terminal or worktree work
ok - a return of another task of the same project is not refused while the project setup script runs
# all fm-spawn-project-setup tests passed
Evidence: Agent pane after taskbase ship spawn (S1)
project setup: running .../config/project-setup/taskbase.sh in .../taskbase-c2af62/1/taskbase (timeout 600s)
hook: FM_TASK_ID=tb-ship1 FM_TASK_KIND=ship FM_PROJECT=taskbase cwd=.../1/taskbase
Cloning into 'bmad-submodule'...
Switched to a new branch 'ctlarsen-v6.12.1-2026-09-10'
Install complete in .../1/taskbase
spawned tb-ship1 harness=bash kind=ship ...
--- agent pane ---
AGENT bmad-submodule checkout: ctlarsen-v6.12.1-2026-09-10 @ 271ea3c
AGENT .agents -> bmad-submodule/.agents
AGENT _bmad entries: _config _memory bmad-loop bmb bmm cis config.toml config.user.toml core custom render scripts tea w
AGENT git-status-lines: 0

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ℹ️ docs/configuration.md:417 - As intended, the change ships only the hook mechanism. The operator still has to write the private config/project-setup/taskbase.sh (it is gitignored under config/). Treehouse pool slots are reused, so a plain git clone https://github.com/clarsen/bmad-submodule.git fails with 'destination path already exists' on the second spawn that lands in the same slot, and the spawn is refused. The script needs a guard such as [ -d bmad-submodule/.git ] || git clone .... It also has to add /bmad-submodule/ and any files install.sh writes to $(git rev-parse --git-path info/exclude), or the git-visible-output check at bin/fm-spawn.sh:3061 refuses the launch. The docs already describe both requirements.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 9 of 10 scenarios driven live against the product
Scenario Result Live Evidence
Ship spawn of taskbase runs the operator's bmad clone, checkout and install.sh in the fresh worktree before the agent starts; the agent sees bmad-submodule at the tag, the _bmad and .agents links, and… ✅ pass live live-setup-hook-lab.log S1: hook output comes before the 'spawned tb-ship1' line; the pane shows the checkout ctlarsen-v6.12.1-2026-09-10 @ 271ea3c and git-status-lines: 0
Hook receives FM_TASK_ID, FM_TASK_KIND and FM_PROJECT, with the task worktree as its working directory, for both ship and scout ✅ pass live live-setup-hook-lab.log S1 and S3 'hook:' lines (kind=ship and kind=scout, cwd = the pool slot)
Teardown of a task whose worktree was set up by the hook is not blocked by the setup output ✅ pass live live-setup-hook-lab.log S2: fm-teardown.sh without --force exits 0, the worktree returns to the pool and the meta is removed
A reused pool slot re-runs the hook over its earlier bmad output without errors ✅ pass live live-setup-hook-lab.log S3: same slot as S1 = yes, 'Already on ctlarsen-v6.12.1-2026-09-10', install complete, the scout agent launches
A hook that exits nonzero refuses the launch, names the script and exit status, publishes no task, and leaves the worktree for inspection ✅ pass live live-setup-hook-lab.log S4: 'exited with status 7 ... refusing to launch the agent', exit=1, no task meta
A hook that runs past FM_PROJECT_SETUP_TIMEOUT is killed and the launch is refused ✅ pass live live-setup-hook-lab.log S5: 'timed out after 3s', exit=1 after 6s (the hook sleeps 120s), no task meta
A hook that leaves files git can see refuses the launch and lists them ✅ pass live live-setup-hook-lab.log S6: 'left changes git can see' with '?? setup-junk.txt', exit=1
A non-executable hook, or an invalid FM_PROJECT_SETUP_TIMEOUT, refuses before any Herdr pane or worktree is created ✅ pass live live-setup-hook-lab.log S7/S8: error messages, exit=1, pane count 4 before and 4 after
A project with no setup script spawns exactly as before ✅ pass live live-setup-hook-lab.log S9: 'spawned other1', no 'project setup' output
Relaunch never re-runs the hook, and secondmate spawns never run it ⏸️ untested no Not driven live: no tool or credential was missing. It needs a lab relaunch of an existing Herdr task and a secondmate home, which were out of scope for this proportionate pass. Add both to the live l…
  • TMPDIR=~/Tmp bash tests/fm-spawn-project-setup.test.sh (focused hook suite that runs the real spawn path with a fake terminal; all 8 cases passed)
  • bash ~/.no-mistakes/evidence/01M36E07187GAE99XBGW38PPTX/live-setup-hook-lab.sh (live: bin/fm-herdr-lab.sh provision → real bin/fm-spawn.sh --backend herdr and bin/fm-teardown.sh in a lab session with scratch FM_HOME and TREEHOUSE_ROOT → guarded lab teardown)
  • Live S1: ship spawn of the taskbase copy with a hook running git clone https://github.com/clarsen/bmad-submodule.git; (cd bmad-submodule; git checkout ctlarsen-v6.12.1-2026-09-10); bmad-submodule/install.sh, then read the agent pane
  • Live S2: fm-teardown.sh tb-ship1 without --force on the set-up worktree
  • Live S3: scout spawn that reused the same pool slot (hook re-run over its earlier output)
  • Live S4–S6: hook exits 7, hook outlasts FM_PROJECT_SETUP_TIMEOUT=3, hook leaves an untracked file
  • Live S7–S8: non-executable hook and FM_PROJECT_SETUP_TIMEOUT=0, with Herdr pane counts taken before and after
  • Live S9: spawn of a second project that has no setup script
✅ **Document** - passed

✅ No issues found.

⚠️ **Lint** - 1 warning
  • ⚠️ linter found issues (exit code 1)
✅ **Push** - passed

✅ No issues found.

…ore launch

A private config/project-setup/<project>.sh runs in each fresh ship or scout worktree after its base refresh and before any harness wiring or launch, bounded by FM_PROJECT_SETUP_TIMEOUT. A nonzero exit, timeout, invalid script, or git-visible setup output refuses the launch; an absent script changes nothing, relaunch never reruns it, and secondmate homes do not inherit it.
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.

1 participant