Repository navigation
feat(bin): run a per-project setup hook in fresh task worktrees before launch - #1
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.shnow looks for an optional local, gitignoredconfig/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, getsFM_TASK_ID,FM_TASK_KIND,FM_PROJECT,FM_PROJECT_DIRandFM_WORKTREEin its environment, and is time-limited byFM_PROJECT_SETUP_TIMEOUT(600s by default). Relaunches and secondmate spawns never run it.docs/configuration.md"Project setup hook", a matchingAGENTS.mdconfig entry, andtests/fm-spawn-project-setup.test.sh(registered in thebackend-dispatchfamily inbin/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.Evidence: Live Herdr lab transcript (all 9 scenarios)
Source: Live Herdr lab transcript (all 9 scenarios)
Evidence: Live lab driver script
Source: Live lab driver script
Evidence: Focused hook test output
Source: Focused hook test output
Evidence: Agent pane after taskbase ship spawn (S1)
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
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 plaingit clone https://github.com/clarsen/bmad-submodule.gitfails 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.
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 runninggit 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 paneLive S2:fm-teardown.sh tb-ship1without --force on the set-up worktreeLive 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 fileLive S7–S8: non-executable hook and FM_PROJECT_SETUP_TIMEOUT=0, with Herdr pane counts taken before and afterLive S9: spawn of a second project that has no setup script✅ **Document** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.