Repository navigation
feat(logbook): auto-sync attention board at session start and surface its link - #2
Merged
Merged
Conversation
…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
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]>
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
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:
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).
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.
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
bin/fm-logbook-compose.sh, a read-only helper that derives a{projects, items}attention baseline fromdata/projects.md,data/backlog.md, andstate/*.meta/state/*.status(one card per in-flight task, classed decision > action > fyi, PR-ready tasks getting Merge/Hold options,kind=secondmatemetas excluded), plusbin/fm-logbook-refresh.shwhich pipes compose intofm-logbook-sync.sh; both are hard no-ops unlessLOGBOOK_ENABLEis truthy and inject all text viajq --arg/--argjson.logbook_setup()inbin/fm-bootstrap.shto, on the reachable branch only, print a captain-facingLOGBOOK: attention board: <url>link and runfm-logbook-refresh.shbest-effort and non-blocking (a failure prints one diagnostic and bootstrap continues), so a dead board never yields a stale link or a hang.AGENTS.md(§3/§9/§15),docs/architecture.md,docs/configuration.md,docs/scripts.md,docs/examples/logbook.env,README.md, andCONTRIBUTING.md, and added 7 new cases totests/fm-logbook.test.shcovering 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 realfm-logbook-compose.shproduced a truthful {projects, items} attention set from a realistic fleet (correct action/decision/fyi classing, PR carried, secondmate excluded, +yolo stripped), and two genuinefm-bootstrap.shsession-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.Evidence: Captain-facing session-start output — REACHABLE board (real fm-bootstrap.sh)
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.envEvidence: 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.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)Evidence: Rendered attention board (review rendering of the composed JSON; production surface is the separate board tool)
Evidence: Loopback board stand-in used for the real bootstrap runs (stand-in for the separate, un-cloned board tool)
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
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_autosyncDeliverable 3: ranFM_HOME=<fleet-fixture> LOGBOOK_ENABLE=1 bin/fm-logbook-compose.shagainst 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-linersDeliverables 1 & 2 (reachable): ran the realbin/fm-bootstrap.shagainst a live loopback board stand-in → captured captain-facingLOGBOOK: attention board: <url>link, verified auto-sync landed by reading backGET /api/board(3 projects, 3 cards), and confirmed noboard not auto-syncedfailure lineDeliverable 1 (unreachable): ran the realbin/fm-bootstrap.shagainst a dead port / nonexistent tool dir → confirmed only the degradedserver not reachable yetline prints, noLOGBOOK: attention board:dead link, and no auto-sync attemptedRendered the real composed attention set tocomposed-attention-set.htmlfor visual review (browser screenshot not possible — Chrome is not installed in this environment)Confirmedgit statusclean — 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.