Skip to content

feat(logbook): auto-sync attention board at session start and surface its link - #2

Merged
SchokoShake merged 2 commits into
mainfrom
fm/logbook-integ-fix-k7
Jul 10, 2026
Merged

SchokoShake merged 2 commits into
mainfrom
fm/logbook-integ-fix-k7

Conversation

@SchokoShake

Copy link
Copy Markdown
Owner

Intent

Make the logbook<->firstmate integration reliable on the firstmate side (board tool under projects/logbook is a separate repo and must NOT be touched). Three approved deliverables:

  1. Surface the board link to the captain: bootstrap's logbook_setup() now emits a captain-facing 'LOGBOOK: attention board: ' line, but ONLY on the reachable branch (when fm-logbook-up.sh succeeds) so a dead link is never handed over. AGENTS.md sections 3/9/15 carry a tight relay rule; mechanism is deliberately kept in the script, not in always-loaded AGENTS.md (GitHub issue Move the X-mode cadence block out of always-loaded AGENTS.md kunchenguid/firstmate#363 tracks moving content OUT of AGENTS.md).

  2. Auto-sync at session start + push-on-update rule: new bin/fm-logbook-refresh.sh (compose then sync) is wired into logbook_setup() after the server is ensured up. It is intentionally best-effort and non-blocking (bootstrap must never block) - a failure prints exactly one diagnostic and bootstrap continues; it is gated on the reachable branch so it never times out against a dead board. Push-on-update is now an explicit AGENTS.md 9/15 rule and supersedes queued backlog item logbook-surface-rule-x2.

  3. Attention-set compose helper: new bin/fm-logbook-compose.sh derives a {projects, items} baseline from data/projects.md, data/backlog.md, state/.meta, and state/.status and emits it on stdout for fm-logbook-sync.sh. Deliberate design: it is a truthful MECHANICAL BASELINE (one card per in-flight task, classed decision > action > fyi; PR-ready tasks get Merge/Hold options; projects flagged active where they carry a card), on top of which firstmate composes richer captain-facing cards via fm-logbook-push.sh (upsert keyed by id). kind=secondmate metas are intentionally excluded (infrastructure, not attention items). Baseline titles/bodies are kept plain and non-jargony on purpose.

Key deliberate choices a diff-only reviewer would not know: compose is read-only and needs NO dry-run branch (it never posts; refresh honors LOGBOOK_DRY_RUN transitively through its sync step); all item text is injected into JSON via jq --arg/--argjson, never interpolated into a shell word or the jq program (security requirement mirroring the other fm-logbook-*.sh scripts); every new script is inert-by-default (hard no-op, exit 0, no output) unless LOGBOOK_ENABLE is truthy; the watcher backbone (fm-watch.sh, fm-watch-arm.sh, fm-wake-lib.sh, fm-supervise-daemon.sh, afk skill) was intentionally left untouched (hard constraint - logbook stays purely additive to it); opt-out remains a complete no-op; no new inheritance was introduced. Verified end-to-end against the real board tool and a real fm-bootstrap.sh run, plus the reachable/unreachable/opt-out cases, with new shell tests in tests/fm-logbook.test.sh. Docs updated across docs/scripts.md, docs/configuration.md, docs/architecture.md, README.md, CONTRIBUTING.md, and docs/examples/logbook.env.

What Changed

  • Added bin/fm-logbook-compose.sh, a read-only helper that derives a {projects, items} attention baseline from data/projects.md, data/backlog.md, and state/*.meta/state/*.status (one card per in-flight task, classed decision > action > fyi, PR-ready tasks getting Merge/Hold options, kind=secondmate metas excluded), plus bin/fm-logbook-refresh.sh which pipes compose into fm-logbook-sync.sh; both are hard no-ops unless LOGBOOK_ENABLE is truthy and inject all text via jq --arg/--argjson.
  • Wired logbook_setup() in bin/fm-bootstrap.sh to, on the reachable branch only, print a captain-facing LOGBOOK: attention board: <url> link and run fm-logbook-refresh.sh best-effort and non-blocking (a failure prints one diagnostic and bootstrap continues), so a dead board never yields a stale link or a hang.
  • Documented the session-start auto-sync and push-on-update rules across AGENTS.md (§3/§9/§15), docs/architecture.md, docs/configuration.md, docs/scripts.md, docs/examples/logbook.env, README.md, and CONTRIBUTING.md, and added 7 new cases to tests/fm-logbook.test.sh covering compose, refresh (dry-run and live), and the reachable/unreachable bootstrap branches.

Risk Assessment

✅ Low: The change is purely additive to the opt-in logbook path (watcher backbone untouched), security-conscious (all fleet text via jq --arg), well-covered by new hermetic tests, and correctly gated on the reachable branch; the only issue is a low-probability defensive robustness gap.

Testing

Baseline test command and the full logbook suite (tests/fm-logbook.test.sh, 42 tests incl. 7 new) pass. Beyond unit tests I demonstrated all three deliverables end-to-end: the real fm-logbook-compose.sh produced a truthful {projects, items} attention set from a realistic fleet (correct action/decision/fyi classing, PR carried, secondmate excluded, +yolo stripped), and two genuine fm-bootstrap.sh session-start runs against a live loopback board stand-in showed the captain-facing board link + auto-synced board state on the reachable path and correctly withheld the link and skipped the sync on the unreachable path. No product screenshot of a firstmate UI was captured because this is a CLI/backend change whose real visual surface is the separate logbook board tool (a distinct repo, not cloned in this worktree and out of scope to touch); the genuine end-user surfaces here are the session-start CLI transcript and the JSON attention-set payload the board receives, both captured as artifacts, plus a labeled HTML rendering of the composed set. Overall result: all checks green, intent demonstrated, no findings.

Evidence: Composed attention set from real fleet state (fm-logbook-compose.sh output)

items: fix-launch-crash-k3 → kind=action (Merge/Hold, source.pr=.../pull/42); nav-redesign-b7 → kind=decision ("bottom tab bar or side drawer?"); slow-query-scout-c2 → kind=fyi ("profiling the ledger query with EXPLAIN"). projects: schokoslauncher active, homemux active, ledger inactive; homemux mode=direct-PR (+yolo stripped). The persistent secondmate triage-sm is absent.

{
  "projects": [
    {
      "name": "schokoslauncher",
      "repo": "schokoslauncher",
      "mode": "no-mistakes",
      "active": true
    },
    {
      "name": "homemux",
      "repo": "homemux",
      "mode": "direct-PR",
      "active": true
    },
    {
      "name": "ledger",
      "repo": "ledger",
      "mode": "local-only",
      "active": false
    }
  ],
  "items": [
    {
      "id": "fix-launch-crash-k3",
      "project": "schokoslauncher",
      "kind": "action",
      "title": "Fix the crash on cold launch",
      "body": "Ready for your review.\n\nPR: https://github.com/acme/schokoslauncher/pull/42",
      "options": [
        {
          "label": "Merge",
          "value": "merge"
        },
        {
          "label": "Hold",
          "value": "hold"
        }
      ],
      "source": {
        "task": "fix-launch-crash-k3",
        "pr": "https://github.com/acme/schokoslauncher/pull/42"
      }
    },
    {
      "id": "nav-redesign-b7",
      "project": "schokoslauncher",
      "kind": "decision",
      "title": "Redesign the home navigation",
      "body": "bottom tab bar or side drawer? (options: tabs, drawer)",
      "options": [],
      "source": {
        "task": "nav-redesign-b7"
      }
    },
    {
      "id": "slow-query-scout-c2",
      "project": "homemux",
      "kind": "fyi",
      "title": "Investigate the slow ledger query",
      "body": "profiling the ledger query with EXPLAIN",
      "options": [],
      "source": {
        "task": "slow-query-scout-c2"
      }
    }
  ]
}
Evidence: Captain-facing session-start output — REACHABLE board (real fm-bootstrap.sh)

LOGBOOK: on - board at http://127.0.0.1:18137&#10;LOGBOOK: attention board: http://127.0.0.1:18137&#10;LOGBOOK: board-response poll armed via state/logbook-watch.check.sh; 15s watcher cadence in config/logbook-mode.env

TASKS_AXI: available
SECONDMATE_SYNC: secondmate triage-sm: skipped: primary default-branch commit cannot be resolved
LOGBOOK: on - board at http://127.0.0.1:18137
LOGBOOK: attention board: http://127.0.0.1:18137
LOGBOOK: board-response poll armed via state/logbook-watch.check.sh; 15s watcher cadence in config/logbook-mode.env
Evidence: Board state after real bootstrap auto-sync (authenticated GET /api/board)

3 projects (schokoslauncher/homemux active, ledger inactive) and 3 cards (action fix-launch-crash-k3 with Merge/Hold, decision nav-redesign-b7, fyi slow-query-scout-c2) — the board now mirrors live fleet state, proving session-start auto-sync landed.

{
  "projects": [
    {
      "name": "schokoslauncher",
      "mode": "no-mistakes",
      "active": true
    },
    {
      "name": "homemux",
      "mode": "direct-PR",
      "active": true
    },
    {
      "name": "ledger",
      "mode": "local-only",
      "active": false
    }
  ],
  "items": [
    {
      "id": "fix-launch-crash-k3",
      "kind": "action",
      "title": "Fix the crash on cold launch",
      "project": "schokoslauncher",
      "options": [
        "Merge",
        "Hold"
      ]
    },
    {
      "id": "nav-redesign-b7",
      "kind": "decision",
      "title": "Redesign the home navigation",
      "project": "schokoslauncher",
      "options": []
    },
    {
      "id": "slow-query-scout-c2",
      "kind": "fyi",
      "title": "Investigate the slow ledger query",
      "project": "homemux",
      "options": []
    }
  ]
}
Evidence: Captain-facing session-start output — UNREACHABLE board (no dead link, no auto-sync)

LOGBOOK: on - board at http://127.0.0.1:19999 (server not reachable yet; see the diagnostic above) LOGBOOK: board-response poll armed via state/logbook-watch.check.sh; 15s watcher cadence in config/logbook-mode.env (no 'LOGBOOK: attention board:' line, no auto-sync attempted)

TASKS_AXI: available
LOGBOOK: on - board at http://127.0.0.1:19999 (server not reachable yet; see the diagnostic above)
LOGBOOK: board-response poll armed via state/logbook-watch.check.sh; 15s watcher cadence in config/logbook-mode.env
Evidence: Rendered attention board (review rendering of the composed JSON; production surface is the separate board tool)
<!doctype html><meta charset=utf8><title>Composed attention set</title>
<style>
body{font:15px/1.5 -apple-system,Segoe UI,Roboto,sans-serif;background:#0f172a;color:#e2e8f0;margin:0;padding:28px}
h1{font-size:19px;margin:0 0 4px} .note{color:#94a3b8;font-size:12.5px;margin:0 0 18px;max-width:760px}
.projrow{margin:0 0 20px;display:flex;gap:8px;flex-wrap:wrap;align-items:center}
.pchip{font-size:12px;padding:3px 10px;border-radius:999px;border:1px solid #334155}
.pchip.on{background:#1e293b;color:#e2e8f0;border-color:#475569}.pchip.off{color:#64748b}
.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(300px,1fr));gap:14px}
.card{background:#1e293b;border:1px solid #334155;border-radius:12px;padding:14px 16px;min-width:0}
.card.decision{border-left:4px solid #ef4444}.card.action{border-left:4px solid #f59e0b}.card.fyi{border-left:4px solid #84cc16}
.row{display:flex;justify-content:space-between;align-items:center;margin-bottom:8px;min-width:0}
.kind{color:#fff;font-size:10.5px;font-weight:700;letter-spacing:.06em;padding:2px 8px;border-radius:6px}
.proj{color:#94a3b8;font-size:12px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}
.title{font-weight:600;font-size:15px;margin-bottom:6px}
.body{color:#cbd5e1;font-size:13px;white-space:normal;word-break:break-word}
.opts{margin-top:12px;display:flex;gap:8px}
.opts button{background:#334155;color:#e2e8f0;border:1px solid #475569;border-radius:7px;padding:5px 14px;font-size:12.5px;cursor:pointer}
.opts button:first-child{background:#2563eb;border-color:#2563eb}
</style>
<h1>Attention board — composed from live fleet state at session start</h1>
<p class="note">Rendered from the real <code>fm-logbook-compose.sh</code> output that <code>fm-bootstrap.sh</code> auto-synced to the board (deliverables 2 &amp; 3). This is a review rendering of the composed <code>{projects, items}</code> payload — the production surface is the separate logbook board tool. Cards are ordered decision &gt; action &gt; fyi; the persistent secondmate is intentionally absent.</p>
<div class="projrow"><b style="color:#94a3b8;font-size:12px">PROJECTS:</b> <span class="pchip on">schokoslauncher •</span><span class="pchip on">homemux •</span><span class="pchip off">ledger</span></div>
<div class="grid">
  <div class="card decision">
    <div class="row"><span class="kind" style="background:#b91c1c">DECISION</span>
      <span class="proj">schokoslauncher</span></div>
    <div class="title">Redesign the home navigation</div>
    <div class="body">bottom tab bar or side drawer? (options: tabs, drawer)</div>
    
  </div>
  <div class="card action">
    <div class="row"><span class="kind" style="background:#b45309">ACTION</span>
      <span class="proj">schokoslauncher</span></div>
    <div class="title">Fix the crash on cold launch</div>
    <div class="body">Ready for your review.<br><br>PR: https://github.com/acme/schokoslauncher/pull/42</div>
    <div class="opts"><button>Merge</button><button>Hold</button></div>
  </div>
  <div class="card fyi">
    <div class="row"><span class="kind" style="background:#3f6212">FYI</span>
      <span class="proj">homemux</span></div>
    <div class="title">Investigate the slow ledger query</div>
    <div class="body">profiling the ledger query with EXPLAIN</div>
    
  </div></div>
Evidence: Loopback board stand-in used for the real bootstrap runs (stand-in for the separate, un-cloned board tool)
// Minimal loopback stand-in for the separate logbook board tool (which is a
// separate repo, not cloned in this worktree and NOT under test). It implements
// only the endpoints fm-logbook-*.sh drives, so a REAL fm-bootstrap.sh run can
// exercise the genuine bootstrap -> refresh -> compose -> sync chain over real
// HTTP on 127.0.0.1, and we can read back what the board would render.
import http from 'node:http';
import fs from 'node:fs';
const PORT = Number(process.env.PORT || 8137);
const TOKEN = process.env.TOKEN || '';
const STORE = process.env.STORE || '/tmp/board-store.json';
let board = { projects: [], items: [] };
const auth = (req) => !TOKEN || req.headers['authorization'] === `Bearer ${TOKEN}`;
const server = http.createServer((req, res) => {
  const send = (code, obj) => { res.writeHead(code, {'content-type':'application/json'}); res.end(obj?JSON.stringify(obj):''); };
  if (req.url === '/health') return send(200, {ok:true});
  if (req.url.startsWith('/api/') && !auth(req)) return send(401, {error:'unauthorized'});
  let body = '';
  req.on('data', c => body += c);
  req.on('end', () => {
    if (req.method === 'POST' && req.url === '/api/sync') {
      try { board = JSON.parse(body); } catch { return send(400,{error:'bad json'}); }
      fs.writeFileSync(STORE, JSON.stringify(board, null, 2));
      return send(200, {ok:true, projects: board.projects?.length||0, items: board.items?.length||0});
    }
    if (req.method === 'GET' && req.url === '/api/board') return send(200, board);
    send(404, {error:'not found'});
  });
});
server.listen(PORT, '127.0.0.1', () => console.error(`board stand-in on 127.0.0.1:${PORT}`));

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ℹ️ bin/fm-logbook-compose.sh:195 - fm-logbook-compose.sh emits an item with project:"" when a task meta lacks a usable project= (missing key, or a basename rejected by valid_project_name, e.g. a repo dir name containing whitespace). Per this repo's own documented tool contract (fm-logbook-resolve.sh header and AGENTS.md §15: every item is validated with kind/title/project required), such an item can make the whole POST /api/sync 400, and because bootstrap's refresh swallows the error (>/dev/null 2>&1) the only signal is the generic 'board not auto-synced ... may be stale' line, so the entire session-start reconcile silently fails and re-fails every session until the meta is fixed. In practice fm-spawn always records a valid non-empty project for ship/scout tasks (and secondmates are skipped), so this is a low-reachability defensive gap rather than a live bug; a cheap guard (skip an item, or fall back its project, when project is empty) would keep one malformed task from poisoning the whole reconcile.
✅ **Test** - passed

✅ No issues found.

  • command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"
  • bash tests/fm-logbook.test.sh — all 42 tests pass, including the 7 new ones: test_compose_hard_noop_when_disabled, test_compose_baseline_from_fleet_state, test_refresh_hard_noop_when_disabled, test_refresh_dry_run_records_sync, test_refresh_live_posts_sync, test_bootstrap_opt_in_surfaces_link_and_autosyncs, test_bootstrap_unreachable_omits_link_and_autosync
  • Deliverable 3: ran FM_HOME=&lt;fleet-fixture&gt; LOGBOOK_ENABLE=1 bin/fm-logbook-compose.sh against a realistic fleet (PR-ready ship, needs-decision ship, in-progress scout, persistent secondmate) → verified 3 cards classed action/decision/fyi, secondmate excluded, PR carried in source.pr, +yolo stripped from project mode, human titles from backlog one-liners
  • Deliverables 1 & 2 (reachable): ran the real bin/fm-bootstrap.sh against a live loopback board stand-in → captured captain-facing LOGBOOK: attention board: &lt;url&gt; link, verified auto-sync landed by reading back GET /api/board (3 projects, 3 cards), and confirmed no board not auto-synced failure line
  • Deliverable 1 (unreachable): ran the real bin/fm-bootstrap.sh against a dead port / nonexistent tool dir → confirmed only the degraded server not reachable yet line prints, no LOGBOOK: attention board: dead link, and no auto-sync attempted
  • Rendered the real composed attention set to composed-attention-set.html for visual review (browser screenshot not possible — Chrome is not installed in this environment)
  • Confirmed git status clean — all evidence written under /tmp/no-mistakes-evidence, nothing left in the worktree
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…d compose helper

Make the logbook<->firstmate integration reliable on the firstmate side:

- Surface the board link: on a reachable board, logbook_setup emits a
  captain-facing "LOGBOOK: attention board: <url>" line that firstmate
  relays once at session start (and after a restart). AGENTS.md sections
  3/9/15 carry the tight relay rule; mechanism stays in the script.

- Auto-sync at session start: after the server is ensured up, bootstrap
  runs the new fm-logbook-refresh.sh (compose|sync), best-effort and
  bounded, so the board is truth-restored automatically instead of relying
  on firstmate remembering. Inert when opted out; one diagnostic on failure.

- Push-on-update: AGENTS.md 9/15 now state as an explicit rule that every
  decision/action/FYI hits the board promptly the moment it arises, in
  addition to chat. Supersedes queued backlog item logbook-surface-rule-x2.

- Attention-set compose helper: new fm-logbook-compose.sh derives a
  {projects, items} baseline from data/projects.md, data/backlog.md,
  state/*.meta, and state/*.status (one card per in-flight task, classed
  decision > action > fyi; projects flagged active where they carry a card)
  and emits it on stdout for fm-logbook-sync.sh. Read-only, inert when off,
  bodies built via jq --arg (never inlined). fm-logbook-refresh.sh wraps
  compose|sync and honors LOGBOOK_DRY_RUN through the sync step.

Watcher backbone and projects/logbook are untouched; opt-out stays a
complete no-op. Tests cover compose/refresh (inert-when-off, classification,
dry-run, live sync) and bootstrap (captain link + auto-sync, reachable and
unreachable). Docs updated across scripts/configuration/architecture/README/
CONTRIBUTING and docs/examples/logbook.env.
@SchokoShake
SchokoShake merged this pull request into main Jul 10, 2026
SchokoShake added a commit that referenced this pull request Jul 13, 2026
… its link (#2)

* feat(logbook): auto-sync board at session start, surface its link, add compose helper

Make the logbook<->firstmate integration reliable on the firstmate side:

- Surface the board link: on a reachable board, logbook_setup emits a
  captain-facing "LOGBOOK: attention board: <url>" line that firstmate
  relays once at session start (and after a restart). AGENTS.md sections
  3/9/15 carry the tight relay rule; mechanism stays in the script.

- Auto-sync at session start: after the server is ensured up, bootstrap
  runs the new fm-logbook-refresh.sh (compose|sync), best-effort and
  bounded, so the board is truth-restored automatically instead of relying
  on firstmate remembering. Inert when opted out; one diagnostic on failure.

- Push-on-update: AGENTS.md 9/15 now state as an explicit rule that every
  decision/action/FYI hits the board promptly the moment it arises, in
  addition to chat. Supersedes queued backlog item logbook-surface-rule-x2.

- Attention-set compose helper: new fm-logbook-compose.sh derives a
  {projects, items} baseline from data/projects.md, data/backlog.md,
  state/*.meta, and state/*.status (one card per in-flight task, classed
  decision > action > fyi; projects flagged active where they carry a card)
  and emits it on stdout for fm-logbook-sync.sh. Read-only, inert when off,
  bodies built via jq --arg (never inlined). fm-logbook-refresh.sh wraps
  compose|sync and honors LOGBOOK_DRY_RUN through the sync step.

Watcher backbone and projects/logbook are untouched; opt-out stays a
complete no-op. Tests cover compose/refresh (inert-when-off, classification,
dry-run, live sync) and bootstrap (captain link + auto-sync, reachable and
unreachable). Docs updated across scripts/configuration/architecture/README/
CONTRIBUTING and docs/examples/logbook.env.

* no-mistakes(lint): fix shellcheck SC2318 in fm-logbook-compose local declaration

---------

Co-authored-by: Kun Chen <[email protected]>
SchokoShake added a commit that referenced this pull request Jul 21, 2026
…awn reuse

Address the review on PR #7:

- treehouse_reservation replaces the boolean holds-check and captures the
  `treehouse status` exit code separately, so a treehouse outage reports
  could-not-ask instead of a false "no longer reserves" on every respawn (#1).
- Match the leased `(held by <holder>)` against this task's fm-<id>, so a
  worktree treehouse re-leased to a different task is caught, not silently
  adopted; an in-use row carries no holder, so the gate only strengthens (#3).
- Cover the lease-release trap for a turn-end hook-block failure between the
  lease and the meta write, the leak class new to this change (#2).
- Record the deliberate readiness-barrier trade at the cd site, marking the
  brief's isolation assertion load-bearing and forbidding a re-added pane probe (#4).
- Make the two treehouse human-text couplings a conscious v2.0.0 assumption;
  v2.0.0 has no --json/--porcelain and both fail loud-but-wrong (#5).

The test treehouse stub now records the real --lease-holder so status renders
the caller's fm-<id>, exercising the holder match faithfully.
SchokoShake added a commit that referenced this pull request Jul 22, 2026
…ane-cwd discovery (#7)

* fix(spawn): capture crew worktree via treehouse get --lease; guard against $FM_HOME

Every projects/* spawn recorded worktree=$FM_HOME (the primary checkout) in
state/<id>.meta instead of the crew's real ~/.treehouse/... worktree, forcing a
manual repair each time and risking teardown/review on the wrong path. The crew
itself was always fine; firstmate-self spawns were immune.

Root cause: worktree discovery sent `treehouse get` into the pane and polled
#{pane_current_path} until it differed from the project dir, taking that as the
worktree. Right after `tmux new-window -c <project>`, the pane process is still
the forked tmux-server child (the shell has not yet exec'd and chdir'd), so
#{pane_current_path} transiently reports the tmux SERVER's own cwd - $FM_HOME
(the server was started there) - before settling on the -c dir a moment later.
The poll's "any path != project dir" exit latched that transient $FM_HOME on the
first iteration of a projects/* spawn ($FM_HOME != $FM_HOME/projects/<repo>),
before `treehouse get` even ran; a firstmate-self spawn ($FM_HOME == project dir)
kept polling to the real worktree - the exact projects/*-only signature. kunchenguid#134's
stable-window-id targeting could not help: the correctly-targeted pane
transiently reports the server cwd.

Fix (bin/fm-spawn.sh):
- Capture authoritatively: lease from fm-spawn itself with `treehouse get
  --lease` (prints only the ~/.treehouse/... path to stdout, banners to stderr)
  and cd the pane into that exact path. No poll, no startup-transient race.
  worktree= and the turn-end hook use the leased path; fm-teardown's existing
  `treehouse return --force <worktree=>` releases it, same as before. Consistent
  with fm-home-seed.sh's existing lease pattern. Applies to every non-orca
  backend and to batch (which re-execs the single path per pair).
- Loud backstop in validate_spawn_worktree: assert the worktree is not the
  primary checkout ($FM_HOME/$FM_ROOT). Because firstmate is a git repo of
  itself, $FM_HOME is a valid git toplevel that cleared every prior clause
  silently; now a regression aborts loudly instead of corrupting meta.

Tests updated to the lease-based capture; new cases pin real-worktree capture
(never $FM_HOME) and the $FM_HOME abort. Docs: tmux-backend.md gains a
root-cause/verification section; architecture.md and herdr-backend.md corrected.
Root cause reproduced with tmux 3.6; fix verified end-to-end against real
treehouse (worktree= records a real .treehouse/... path, pane cd's into it).

Refs fm-spawn-wt-batch-x5.

* test(spawn): strengthen symlinked-prefix test with a tangle case guarding PROJ_ABS_REAL

Review (decision A, captain rule: fix the root cause, do not soften) found the
reframed test_spawn_symlinked_project_prefix_avoids_false_refusal no longer
exercised the PROJ_ABS_REAL canonicalization its comment claimed to guard: its
leased worktree was entirely distinct from the project, so validate_spawn_worktree's
only project-dependent clause (wt_real == proj_real) was never near-triggered and
the test would pass even if PROJ_ABS_REAL regressed to a logical PROJ_ABS.

Add a tangle case: the treehouse stub leases the PROJECT ITSELF reached back
through the symlinked prefix (physical path equal to the project), and the spawn
must be REFUSED with "did not yield an isolated worktree". That refusal holds
ONLY because validate_spawn_worktree resolves both sides with pwd -P; were
PROJ_ABS_REAL the logical PROJ_ABS the physical worktree path would compare
unequal and the tangle would be wrongly allowed. Test-only; bin/fm-spawn.sh
unchanged.

Refs fm-spawn-wt-batch-x5.

* no-mistakes(review): fix(spawn): release treehouse lease on abort; drop dead current_path ops

* no-mistakes(review): fix(spawn): reuse recorded worktree on respawn; refresh stale adapter docs

* no-mistakes(review): fix(spawn): gate respawn reuse on meta identity and lease reservation

* no-mistakes(review): extend respawn identity gate to recorded backend

* no-mistakes(review): scope respawn backend refusal to orca; derive --help range

* no-mistakes(document): sync backend docs with treehouse-lease worktree capture and respawn

* fix(spawn): distinguish treehouse-status failure and re-lease on respawn reuse

Address the review on PR #7:

- treehouse_reservation replaces the boolean holds-check and captures the
  `treehouse status` exit code separately, so a treehouse outage reports
  could-not-ask instead of a false "no longer reserves" on every respawn (#1).
- Match the leased `(held by <holder>)` against this task's fm-<id>, so a
  worktree treehouse re-leased to a different task is caught, not silently
  adopted; an in-use row carries no holder, so the gate only strengthens (#3).
- Cover the lease-release trap for a turn-end hook-block failure between the
  lease and the meta write, the leak class new to this change (#2).
- Record the deliberate readiness-barrier trade at the cd site, marking the
  brief's isolation assertion load-bearing and forbidding a re-added pane probe (#4).
- Make the two treehouse human-text couplings a conscious v2.0.0 assumption;
  v2.0.0 has no --json/--porcelain and both fail loud-but-wrong (#5).

The test treehouse stub now records the real --lease-holder so status renders
the caller's fm-<id>, exercising the holder match faithfully.

* no-mistakes(document): sync tmux worktree-capture doc with --lease-holder flag

---------

Co-authored-by: SchokoShake <[email protected]>
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.

2 participants