Skip to content

feat(bin): lint only the changed shard locally, full lint in CI - #1925

Merged
kunchenguid merged 2 commits into
mainfrom
fm/fm-lint-changed-shard-r1
Aug 8, 2026
Merged

kunchenguid merged 2 commits into
mainfrom
fm/fm-lint-changed-shard-r1

Conversation

@kunchenguid

Copy link
Copy Markdown
Owner

Intent

fm-lint: only lint changed shard locally, full lint in CI.

Captain observed two ships hitting fm-lint.sh at once causing 190% CPU, load 8.58, and fan spin, even though each run finishes quickly and each ShellCheck worker is bounded (2 workers, 96% CPU + 1GB each). Captain's explicit request: "only linting changed shard is a great idea. but in CI i want full lint."

Ship requirements for bin/fm-lint.sh (single owner of firstmate's shell-lint definition):

  • When run with no explicit paths, be smart about file-set selection:
  • Full lint (canonical set bin/.sh bin/backends/.sh tests/*.sh, same 2 workers, deterministic order, exit 0 only if all shards pass) when: in CI (GITHUB_ACTIONS=true or CI=true), OR on the main branch (git rev-parse --abbrev-ref HEAD == main), OR when no merge-base can be found. This keeps CI parity - CI coverage must never depend on a local diff.
  • Changed-files lint otherwise (an ordinary local branch with a real merge-base): compute changed files in the canonical lint set via git diff --name-only against the merge-base with origin/main (fallback to local main if origin/main is missing), filtered to existing files matching the canonical globs (bin/.sh, bin/backends/.sh, tests/*.sh), including uncommitted local edits. Keep the same 2-worker sharding, telemetry, and deterministic replay for the reduced set.
  • Zero changed files matching -> exit 0 with a "no changed lint targets" note, but still print the ShellCheck version line for parity (no full run).
  • Explicit paths (fm-lint.sh ...) always bypass this selection entirely and lint exactly those paths, ignoring changed-file logic - this preserves tests/fm-lint.test.sh's existing explicit-path tests and manual runs.
  • Implementation constraints: pure local git only (git merge-base + git diff --name-only --diff-filter=ACMR, handling renames via the R filter and rejecting tab/newline paths as before); no gh or network dependency. If git is unavailable or this isn't a git repo, fall back to full lint (safe default). Keep the existing ShellCheck version pin (0.11.0) and telemetry behavior; telemetry shard weights now naturally reflect the reduced changed set when in changed mode. --list-files must reflect whichever mode/file-set would be linted (the changed set when no explicit paths are given locally, the full set in CI/main/no-merge-base).
  • Keep bin/fm-lint.sh as the single owner of this lint definition (per firstmate-coding-guidelines); do not duplicate the logic elsewhere.
  • Added tests to tests/fm-lint.test.sh (extending the existing suite, not a new runner): (a) changed mode lints only the changed file (git mocked via a PATH-shimmed git stub since fm-lint.sh always cd's to its own real repo root, so a fabricated temp-repo approach would not exercise the real branch/remote state), (b) CI env forces full lint even when the diff would be empty, (c) being on the main branch forces full lint, (d) an explicit path overrides/bypasses the changed-file logic even when git would fail, (e) zero changed files exits 0 with the note, (f) --list-files respects the active mode. Also fixed the pre-existing test_list_files_reports_the_shell_inventory test to force CI=true so it stays deterministic regardless of the ambient branch/diff state a local test run happens to have (it previously assumed --list-files with no args always returns the full canonical set unconditionally, which is no longer true).
  • Updated the fm-lint.sh header/usage comment and CONTRIBUTING.md's toolbelt-check command comments to document the new default behavior, since docs/fm-lint.sh's own header is the authoritative mechanics owner per firstmate-coding-guidelines' knowledge-placement tree.

Delivery: no-mistakes, yolo off (captain merges). This is firstmate's own shared tracked material (bin/, tests/, CONTRIBUTING.md).

Local validation already performed before this run: bin/fm-lint.sh lints itself and the changed test file cleanly (both as explicit paths and via CI=true full mode); all 16 tests in tests/fm-lint.test.sh pass including the 6 new ones; a full CI=true lint of the entire repo exits 0; bin/fm-doc-audience-check.sh reports ok after the CONTRIBUTING.md edit. Noted but explicitly out of scope: tests/fm-lint-calm-pi-extension.test.sh's "/export did not complete while calm mode was on" failure is pre-existing on the unmodified base branch (verified via git stash) and unrelated to this change; it was not touched.

What Changed

  • bin/fm-lint.sh now selects its default file set by context when invoked with no explicit paths: it runs the full canonical set (bin/*.sh bin/backends/*.sh tests/*.sh) in CI (GITHUB_ACTIONS/CI), on main, or when no merge-base is found, and otherwise lints only the canonical-set files changed since the merge-base against origin/main (falling back to local main) using pure local git diff --name-only --diff-filter=ACMR, including uncommitted edits; a branch with zero matching changes exits 0 with a "no changed lint targets" note, and --list-files reflects whichever set would be linted while explicit paths bypass selection entirely.
  • Added helpers fm_lint_changed_base_ref and fm_lint_is_canonical_root, kept the ShellCheck 0.11.0 pin, 2-worker sharding, telemetry, and deterministic replay, and updated the script header/usage comments to document the new default behavior.
  • Extended tests/fm-lint.test.sh with six cases (git-shimmed changed-mode single-file lint, CI-forced full lint, main-branch-forced full lint, explicit-path override when git fails, zero-changed exit-0 note, and --list-files mode) and pinned the pre-existing inventory test to CI=true; updated CONTRIBUTING.md toolbelt-check comments to describe the changed-vs-full behavior.

Risk Assessment

✅ Low: The change is well-bounded, fully conforms to the authoritative intent (mode selection, explicit-path bypass, zero-target note, --list-files parity, tab/newline rejection, pinned ShellCheck version, single-owner), and is backed by behavioral tests that exercise the executable interface rather than source text.

Testing

Ran the full targeted suite bash tests/fm-lint.test.sh (16/16 pass, including the 6 new changed-mode/CI-parity tests) and then exercised the real bin/fm-lint.sh end-to-end as an end user would: captured CLI transcripts showing local changed-files mode selecting only the two changed canonical files while CI=true selects the entire canonical inventory, both a local changed-mode lint and a full CI-mode lint exiting 0, and the zero-changed-targets path printing the pinned-version line plus the "no changed lint targets" note and exiting 0. This is a CLI change with no visual surface, so evidence is CLI transcripts rather than screenshots. Worktree left clean; no findings.

Evidence: list-files: changed mode (2 files) vs CI full inventory
### 1. LOCAL (changed-files mode): bin/fm-lint.sh --list-files
$ bin/fm-lint.sh --list-files
bin/fm-lint.sh
tests/fm-lint.test.sh

### 2. CI mode (full lint): CI=true bin/fm-lint.sh --list-files
$ CI=true bin/fm-lint.sh --list-files
bin/fm-afk-launch.sh
bin/fm-afk-return.sh
bin/fm-afk-start.sh
bin/fm-arm-pretool-check.sh
bin/fm-backend-hometag-lib.sh
bin/fm-backend.sh
bin/fm-backlog-handoff.sh
bin/fm-backlog-receive.sh
bin/fm-bearings-snapshot.sh
bin/fm-bootstrap.sh
bin/fm-brief.sh
bin/fm-busy-event.sh
bin/fm-busy-lib.sh
bin/fm-cd-pretool-check.sh
bin/fm-check-lib.sh
bin/fm-check-register.sh
bin/fm-classify-lib.sh
bin/fm-claude-stop-autoarm.sh
bin/fm-composer-lib.sh
bin/fm-config-inherit-lib.sh
bin/fm-config-push.sh
bin/fm-crew-state.sh
bin/fm-decision-hold.sh
bin/fm-doc-audience-check.sh
bin/fm-ensure-agents-md.sh
bin/fm-ff-lib.sh
bin/fm-fleet-snapshot.sh
bin/fm-fleet-sync.sh
bin/fm-fleet-view.sh
bin/fm-gate-refuse-lib.sh
bin/fm-guard.sh
bin/fm-harness.sh
bin/fm-herdr-ci-cleanup.sh
bin/fm-herdr-lab.sh
bin/fm-herdr-session-cleanup.sh
bin/fm-home-seed.sh
bin/fm-install-herdr.sh
bin/fm-install-shellcheck.sh
bin/fm-install-treehouse.sh
bin/fm-kimi-turnend-hook.sh
bin/fm-line-cap-lib.sh
bin/fm-lint.sh
bin/fm-lock-lib.sh
bin/fm-lock.sh
bin/fm-marker-lib.sh
bin/fm-merge-local.sh
bin/fm-nm-run-lib.sh
bin/fm-on.sh
bin/fm-operational-input.sh
bin/fm-peek.sh
bin/fm-pending-reply-lib.sh
bin/fm-pr-check-migrate.sh
bin/fm-pr-check.sh
bin/fm-pr-lib.sh
bin/fm-pr-merge.sh
bin/fm-pr-poll.sh
bin/fm-primary-scope-lib.sh
bin/fm-procevent-lavish.sh
bin/fm-procevent-lib.sh
bin/fm-procevent-remote-reply.sh
bin/fm-procevent.sh
bin/fm-project-mode.sh
bin/fm-project-origin-lib.sh
bin/fm-promote.sh
bin/fm-public-followup-emit.sh
bin/fm-public-followup-lib.sh
bin/fm-public-followup.sh
bin/fm-push-transition-lib.sh
bin/fm-quota-axi-lib.sh
bin/fm-remote-delta-read.sh
bin/fm-remote-doctor.sh
bin/fm-remote-entrypoint.sh
bin/fm-remote-file.sh
bin/fm-remote-home-provision.sh
bin/fm-remote-home-seed.sh
bin/fm-remote-inherit-push.sh
bin/fm-remote-inherit.sh
bin/fm-remote-job-lib.sh
bin/fm-remote-job-worker.sh
bin/fm-remote-readiness-lib.sh
bin/fm-remote-secondmate-control.sh
bin/fm-review-diff.sh
bin/fm-secondmate-charter-lib.sh
bin/fm-secondmate-nudge-lib.sh
bin/fm-secondmate-parent-lib.sh
bin/fm-secondmate-registry-lib.sh
bin/fm-secondmate-report.sh
bin/fm-send.sh
bin/fm-session-lock-lib.sh
bin/fm-session-start.sh
bin/fm-sessionstart-nudge.sh
bin/fm-sessionstart-run.sh
bin/fm-spawn.sh
bin/fm-startup-memory-budget-lib.sh
bin/fm-startup-memory-budget.sh
bin/fm-startup-network.sh
bin/fm-subagent-pretool-check.sh
bin/fm-supervise-daemon.sh
bin/fm-supervision-instructions.sh
bin/fm-supervision-lib.sh
bin/fm-supervisor-target-lib.sh
bin/fm-tangle-lib.sh
bin/fm-tasks-axi-lib.sh
bin/fm-teardown.sh
bin/fm-test-isolation-proof.sh
bin/fm-test-run.sh
bin/fm-timeout-lib.sh
bin/fm-timing-lib.sh
bin/fm-tmux-lib.sh
bin/fm-trace-context-lib.sh
bin/fm-transition-lib.sh
bin/fm-turnend-guard-grok.sh
bin/fm-turnend-guard.sh
bin/fm-update.sh
bin/fm-vendor-auth-probe.sh
bin/fm-wake-drain.sh
bin/fm-wake-lib.sh
bin/fm-watch-arm.sh
bin/fm-watch-checkpoint.sh
bin/fm-watch.sh
bin/fm-x-dismiss.sh
bin/fm-x-followup.sh
bin/fm-x-lib.sh
bin/fm-x-link.sh
bin/fm-x-poll.sh
bin/fm-x-reply.sh
bin/backends/cmux.sh
bin/backends/herdr.sh
bin/backends/orca.sh
bin/backends/tmux.sh
bin/backends/zellij.sh
tests/cmux-test-safety.sh
tests/fm-afk-inject-e2e.test.sh
tests/fm-afk-inject-herdr-e2e.test.sh
tests/fm-afk-launch.test.sh
tests/fm-afk-pi-herdr-return-e2e.test.sh
tests/fm-afk-return.test.sh
tests/fm-arm-pretool-check.test.sh
tests/fm-ask-user-authority.test.sh
tests/fm-backend-autodetect-smoke.test.sh
tests/fm-backend-cmux-smoke.test.sh
tests/fm-backend-cmux.test.sh
tests/fm-backend-herdr-eventwait-smoke.test.sh
tests/fm-backend-herdr-focus-flash-e2e.test.sh
tests/fm-backend-herdr-launcher-workspace-e2e.test.sh
tests/fm-backend-herdr-presentation-e2e.test.sh
tests/fm-backend-herdr-prune-safety-e2e.test.sh
tests/fm-backend-herdr-respawn-idem-e2e.test.sh
tests/fm-backend-herdr-smoke.test.sh
tests/fm-backend-herdr-workspace-per-home-e2e.test.sh
tests/fm-backend-herdr.test.sh
tests/fm-backend-orca.test.sh
tests/fm-backend-tmux-smoke.test.sh
tests/fm-backend-zellij-smoke.test.sh
tests/fm-backend-zellij.test.sh
tests/fm-backend.test.sh
tests/fm-backlog-handoff.test.sh
tests/fm-bearings-snapshot.test.sh
tests/fm-bootstrap.test.sh
tests/fm-brief.test.sh
tests/fm-busy-adapter-wiring.test.sh
tests/fm-busy-state.test.sh
tests/fm-calm-pi-extension.test.sh
tests/fm-cd-pretool-check.test.sh
tests/fm-claude-stop-autoarm-live-e2e.test.sh
tests/fm-claude-stop-autoarm.test.sh
tests/fm-codex-continuity-live-e2e.test.sh
tests/fm-composer-ghost.test.sh
tests/fm-composer-lib.test.sh
tests/fm-crew-state.test.sh
tests/fm-daemon.test.sh
tests/fm-decision-hold-lifecycle.test.sh
tests/fm-documentation-audiences.test.sh
tests/fm-ensure-agents-md.test.sh
tests/fm-fleet-snapshot-view.test.sh
tests/fm-fleet-sync.test.sh
tests/fm-gate-refuse.test.sh
tests/fm-gitignore-config.test.sh
tests/fm-gotmp.test.sh
tests/fm-grok-continuity-live-e2e.test.sh
tests/fm-grok-harness.test.sh
tests/fm-grok-stop-live-e2e.test.sh
tests/fm-guard-stale-banner.test.sh
tests/fm-harness-liveness-drift-live-e2e.test.sh
tests/fm-herdr-lab.test.sh
tests/fm-herdr-session-cleanup-e2e.test.sh
tests/fm-herdr-session-cleanup.test.sh
tests/fm-herdr-version-floor-live-e2e.test.sh
tests/fm-kimi-harness.test.sh
tests/fm-lint.test.sh
tests/fm-muse-harness.test.sh
tests/fm-muse-signals-live-e2e.test.sh
tests/fm-on.test.sh
tests/fm-opencode-primary-live-e2e.test.sh
tests/fm-operational-input.test.sh
tests/fm-pending-reply.test.sh
tests/fm-pi-primary-live-e2e.test.sh
tests/fm-pi-primary-types.test.sh
tests/fm-pi-watch-extension.test.sh
tests/fm-pr-check-security.test.sh
tests/fm-pr-merge.test.sh
tests/fm-procevent.test.sh
tests/fm-project-origin.test.sh
tests/fm-public-followup.test.sh
tests/fm-quota-array-dispatch-live-e2e.test.sh
tests/fm-remote-backlog-handoff.test.sh
tests/fm-remote-doctor.test.sh
tests/fm-remote-entrypoint.test.sh
tests/fm-remote-job.test.sh
tests/fm-remote-reply.test.sh
tests/fm-remote-secondmate-lifecycle-e2e.test.sh
tests/fm-remote-secondmate-parent-binding.test.sh
tests/fm-remote-secondmate-trace-context.test.sh
tests/fm-review-diff.test.sh
tests/fm-secondmate-harness.test.sh
tests/fm-secondmate-lifecycle-e2e.test.sh
tests/fm-secondmate-liveness.test.sh
tests/fm-secondmate-safety.test.sh
tests/fm-secondmate-sync.test.sh
tests/fm-send-popup-settle.test.sh
tests/fm-send-resolve-key.test.sh
tests/fm-send-secondmate-marker-herdr-e2e.test.sh
tests/fm-send-secondmate-marker.test.sh
tests/fm-send-settle.test.sh
tests/fm-send-strict.test.sh
tests/fm-session-lock-ancestry.test.sh
tests/fm-session-start.test.sh
tests/fm-sessionstart-hook-live-e2e.test.sh
tests/fm-sessionstart-nudge.test.sh
tests/fm-shared-captain-inheritance.test.sh
tests/fm-spawn-batch.test.sh
tests/fm-spawn-dispatch-profile.test.sh
tests/fm-spawn-worktree-settle.test.sh
tests/fm-startup-memory-budget.test.sh
tests/fm-startup-network.test.sh
tests/fm-subagent-pretool-check.test.sh
tests/fm-supervision-events.test.sh
tests/fm-supervision-instructions.test.sh
tests/fm-tangle-guard.test.sh
tests/fm-task-delivery.test.sh
tests/fm-teardown-endpoint-safety.test.sh
tests/fm-teardown.test.sh
tests/fm-test-fixture-cleanup.test.sh
tests/fm-test-isolation-proof.test.sh
tests/fm-test-run.test.sh
tests/fm-tmux-agent-liveness.test.sh
tests/fm-tmux-submit-busy.test.sh
tests/fm-trace-context-lib.test.sh
tests/fm-trace-context-spawn.test.sh
tests/fm-transition-lib.test.sh
tests/fm-turnend-guard.test.sh
tests/fm-update.test.sh
tests/fm-vendor-auth-probe.test.sh
tests/fm-wake-daemon-lifecycle-e2e.test.sh
tests/fm-wake-drain-open-decisions-cursor.test.sh
tests/fm-wake-drain-open-decisions.test.sh
tests/fm-wake-queue.test.sh
tests/fm-watch-arm.test.sh
tests/fm-watch-checkpoint.test.sh
tests/fm-watch-triage.test.sh
tests/fm-watcher-lock.test.sh
tests/fm-x-mode.test.sh
tests/herdr-test-safety.sh
tests/lib.sh
tests/remote-herdr-fixture.sh
tests/secondmate-helpers.sh
tests/wake-helpers.sh
tests/zellij-test-safety.sh
Evidence: Local changed-mode real lint run (exit 0)
### LOCAL changed-files mode: real lint run (only the changed shard)
$ bin/fm-lint.sh
fm-lint.sh: ShellCheck 0.11.0 (pinned 0.11.0)
(exit 0)  <- lints only bin/fm-lint.sh + tests/fm-lint.test.sh
Evidence: CI-mode full canonical lint run (exit 0)
### CI mode full lint of the entire canonical set (2 bounded workers)
$ CI=true bin/fm-lint.sh   # (stdout suppressed; capturing header + exit)
fm-lint.sh: ShellCheck 0.11.0 (pinned 0.11.0)
(exit 0)  <- full canonical set linted clean in CI mode
Evidence: Zero changed files: version line + note, exit 0
### LOCAL branch with zero changed canonical files
$ bin/fm-lint.sh   # (git reports empty diff)
fm-lint.sh: ShellCheck 0.11.0 (pinned 0.11.0)
fm-lint.sh: no changed lint targets
(exit 0)
Evidence: Test suite result (16/16 pass)
ok - fm-lint.sh changed mode lints only the changed canonical file
ok - fm-lint.sh forces a full lint in CI even when the local diff would be empty
ok - fm-lint.sh forces a full lint when HEAD is on main
ok - fm-lint.sh explicit paths bypass changed-file mode selection
ok - fm-lint.sh exits 0 with a note when the local branch has no changed lint targets
ok - fm-lint.sh --list-files reports the would-be changed set in changed mode
(all 16 tests pass)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ℹ️ bin/fm-lint.sh:206 - Changed mode selects files via git diff --name-only --diff-filter=ACMR &lt;merge_base&gt; (bin/fm-lint.sh:206), which compares the merge-base tree to the working tree and therefore only reports tracked (committed or staged) files. A brand-new, not-yet-git added shell script under bin/ or tests/ produces no diff entry, so a local run reports 'no changed lint targets' (or an incomplete set) and gives a false sense of a clean lint. Full lint in CI (glob-based) still catches it, so this is the intended CI-parity safety net rather than a defect; flagging so the local false-confidence case is understood. The doc/prose phrase 'including uncommitted local edits' could be read as covering new files, which it does not until they are staged.
✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-lint.test.sh - all 16 tests pass including the 6 new ones (changed-mode-only, CI-forces-full, main-forces-full, explicit-path-bypass, zero-changed-note, list-files-respects-mode)
  • bin/fm-lint.sh --list-files vs CI=true bin/fm-lint.sh --list-files against real git - changed set (2 files) vs full canonical inventory
  • bin/fm-lint.sh real local changed-mode lint run - exit 0, lints only the 2 changed files
  • CI=true bin/fm-lint.sh real full canonical lint - exit 0
  • PATH-shimmed empty-diff run of the real bin/fm-lint.sh - prints ShellCheck version + 'no changed lint targets', exit 0
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Two ships hitting fm-lint.sh at once could spike CPU to 190% and load
to 8.58 on a captain's Mac, even though each run finishes quickly.
fm-lint.sh now defaults to linting only the canonical-set files
changed since the merge-base with origin/main (including uncommitted
edits) on an ordinary local branch, using plain local git with no
network calls. It still lints the full canonical set in CI
(GITHUB_ACTIONS=true or CI=true), on the main branch, or whenever no
merge-base can be found, so CI coverage never depends on a local diff.
Explicit paths keep bypassing this selection entirely.
@kunchenguid
kunchenguid merged commit 833a9a2 into main Aug 8, 2026
13 checks passed
@kunchenguid
kunchenguid deleted the fm/fm-lint-changed-shard-r1 branch August 8, 2026 00:20
pruge referenced this pull request in pruge/firstmate_old Aug 8, 2026
…#7)

* fix(bin): keep tracked Claude hook entries inert under grok 1.0.0 (#1917)

* fix(hooks): keep tracked Claude entries inert under grok 1.0.0 hooks

Grok loads Claude-compatible settings, so the tracked `.claude/settings.json`
hook entries also fire under Grok. They were meant to be inert there, guarded
by `[ -z "${GROK_AGENT:-}" ] || exit 0`. That guard silently stopped working.

Verified from the live process environment of a wedged grok 1.0.0 Stop hook on
2026-08-07: a grok 1.0.0 HOOK process carries GROK_HOOK_EVENT, GROK_HOOK_NAME,
GROK_SESSION_ID, and GROK_WORKSPACE_ROOT, but no GROK_AGENT. The observed hook
process was labelled `GROK_HOOK_NAME=project/settings:stop[0].hooks[1]`, which
is the Claude-only auto-arm entry.

Consequence: Grok ran `bin/fm-claude-stop-autoarm.sh` synchronously. Grok has
no `asyncRewake`, so it waited on the foregrounded watcher for that entry's
declared 28800-second timeout and the Grok turn never ended - the operator saw
an infinite "Responding".

Widen the guard to `[ -z "${GROK_AGENT:-}${GROK_HOOK_EVENT:-}" ] || exit 0` on
the five entries that have a `.grok/hooks/` counterpart: both Stop entries, the
SessionStart entry, and the two PreToolUse Bash entries.

Two deliberate limits:

- The guard is NOT widened to GROK_SESSION_ID. Grok injects it into every child
  process, so it can survive into a Claude session that Grok launched and would
  silently disable Claude's own watcher continuity. GROK_HOOK_EVENT is
  per-hook-invocation and does not leak that way.
- `bin/fm-subagent-pretool-check.sh` stays unguarded on purpose. It is the one
  tracked entry with no `.grok/hooks/` counterpart, so guarding it would remove
  the guard from Grok entirely rather than deduplicate it. The new test asserts
  it stays unguarded so the exception cannot be closed silently, and
  docs/subagent-guard.md is honest that the coverage it leaves is partial.

`bin/fm-harness.sh` corrects a comment that presented GROK_AGENT as reliably
present; it is a fast path only, and the ancestry walk is what actually
guarantees grok identification.

tests/fm-turnend-guard.test.sh adds test_tracked_claude_entries_inert_under_grok,
which runs every tracked entry under a real grok 1.0.0 hook environment, a
legacy GROK_AGENT environment, and a native Claude environment.

* no-mistakes(document): docs: sync grok hook-marker guard facts to owners

* no-mistakes(review): docs: state grok guard criterion by event coverage

* feat(startup-network): record per-step elapsed times for the deferred stage (#1918)

The deferred network stage published one aggregate started/finished pair, so
a run that took a minute could not be attributed to a phase, a host, or a
clone without re-running it by hand under manual tracing.

Add bin/fm-timing-lib.sh as the single owner of elapsed-time records, and
bracket each network owner with one: the gh auth probe, the secondmate
liveness sweep, secondmate convergence, pending handoff delivery, and the
project clone refresh, plus one record per secondmate for the remote-touching
steps (id and host) and one per project clone. Each record carries a start
offset from one shared origin, so the artifact reads as a timeline.

The stage publishes them beside its report as state/.startup-network.timings,
for a timed-out or failed run too, where the partial record is the answer.
Only the on-demand `report` command prints them: `harvest` composes the
session-start digest, so its output, the wake cadence, and every other part
of a normal session start are unchanged.

Recording is inert unless a run asks for it, so nothing else that sources
these scripts pays for it. Details are identities only - a detail carrying
whitespace is refused rather than cleaned up, which is what keeps a command
line, an environment dump, or a captured error out of the file.

Split two per-item loop bodies into their own functions so each iteration can
be timed; every `continue` became a `return 0` with the same meaning, and the
sweeps still run directly, in the same order, returning the same results.

* feat(stow): cascade the internal /stow to every registered secondmate (#1928)

* feat(stow): cascade the internal /stow to every registered secondmate

Invoked in a primary home, /stow now sweeps every registered secondmate
after the primary's own required pass, enforcing the same startup-memory
threshold in each home against that home's own allowance rather than a
fleet total.

bin/fm-stow-cascade.sh owns the mechanical inputs: it enumerates each
registered secondmate exactly once from data/secondmates.md, reports that
home's own budget accounting, and resolves how the sweep reaches it. A
live agent sweeps its own home so its uncaptured session knowledge is
captured too; a local home without one is curated in place; a remote home
without one is accounted read-only and deferred, because there is no
generic remote write path for a home's own memory files. Every host-
crossing step and each home's accounting runs under one hard bound, so a
slow or unreachable home reports an exception and the sweep continues.

Nothing changes until /stow is invoked: no new notification, digest
section, or background work. The public skills/stow skill is untouched.

* no-mistakes(review): fix(stow): extend cascade --help range to include full exit-code contract

* fix(remote-job): stop workers abandoned by a pruned code root (#1927)

29 fm-remote-job-worker.sh processes were found running at ppid 1, 1-2 days
old, each still polling and appending to a log inside a no-mistakes gate
worktree that had already been returned.

Three things combined to make that possible:

- The recorded worker.pid is the serving child, not the restart supervisor
  above it, so a teardown that stops that one pid only makes the supervisor
  respawn. The Linux start path also left the worker tree in the launching
  command's process group, so there was no group to signal instead.
- Neither the serving loop nor the supervisor ever rechecked whether its
  configured FM_ROOT still existed, so a worker launched from a worktree
  outlived that worktree indefinitely.
- The supervisor restarted a failing child with a fixed 0.1s delay and no
  bound, which is what grew the logs (~66MB/day measured).

The Linux start path now puts the worker tree in its own process group, and
fm_remote_job_stop_worker_tree signals that whole group - refusing any group
whose leader is not itself a worker, so a worker from an older build or from
launchd's own session is still stopped safely as a single process. The worker
stops itself once its code root stops being a Firstmate checkout, confirmed
across a grace window so an ordinary transient cannot stop a healthy worker.
The supervisor backs off and gives up rather than restarting forever.

bin/fm-remote-job-reap-orphans.sh is the belt-and-suspenders sweep for workers
already orphaned that way, wired into fm-teardown.sh. Its reap condition is
exactly "the code root named in the worker's own command line is gone", which
is why the account's healthy LaunchAgent worker and every live remote
secondmate worker are never candidates.

The two suites that leaked these in the first place now stop the worker tree
rather than the recorded pid alone.

* feat(bin): lint only the changed shard locally, full lint in CI (#1925)

* fix(bin): lint only the changed shard locally, full lint in CI

Two ships hitting fm-lint.sh at once could spike CPU to 190% and load
to 8.58 on a captain's Mac, even though each run finishes quickly.
fm-lint.sh now defaults to linting only the canonical-set files
changed since the merge-base with origin/main (including uncommitted
edits) on an ordinary local branch, using plain local git with no
network calls. It still lints the full canonical set in CI
(GITHUB_ACTIONS=true or CI=true), on the main branch, or whenever no
merge-base can be found, so CI coverage never depends on a local diff.
Explicit paths keep bypassing this selection entirely.

* no-mistakes: apply CI fixes

* no-mistakes(document): docs(scripts): add missing fm-stow-cascade.sh entry to scripts table

---------

Co-authored-by: Jay Park <[email protected]>
Co-authored-by: Kun Chen <[email protected]>
chipssss added a commit to lighthouser-agent/firstmate that referenced this pull request Aug 8, 2026
* fix: move network checks off the session-start blocking path (kunchenguid#1860)

* perf(session-start): run every network check off the blocking path

The session-start digest runs on a session-open hook that blocks session
initialization, and every external-network call it made was individually
unbounded: `gh auth status`, secondmate liveness, secondmate convergence,
pending remote handoff delivery, and the fleet-sync fetch. One unreachable
remote secondmate could consume the whole FM_SESSION_START_TIMEOUT and
truncate the digest, so a slow network could cost the work queue itself.
Measured against a host hanging 25s per SSH connection, that startup took
1m18s.

The digest is now composed from local reads alone. bin/fm-startup-network.sh
runs the same checks concurrently in a bounded detached worker and the digest
harvests whatever finished, without ever waiting. Same fixture: 0.84s.

Nothing is dropped. fm-bootstrap.sh stays the single owner of every sweep and
still runs all of them, through a new FM_BOOTSTRAP_NETWORK phase split whose
`skip` and `only` halves are a partition of the unsplit run. Deferral is safe
because the sweeps are idempotent detectors, the result is durable and always
surfaces (inline, or as a `check: startup-network` wake), and the worker
re-verifies that the fleet lock still names the session that asked before it
mutates anything. While the worker is still running the digest names exactly
what is unconfirmed rather than implying it passed.

A relaunch performed by the deferred pass is now always reported, because the
digest that printed the superseded endpoint record is already out.

Also collapses the duplicate tasks-axi compatibility probe: the verdict is
computed once and handed to the bootstrap child for one process hop, then
consumed so it never reaches a spawned agent's environment. 10 tasks-axi
invocations per startup become 7.

Verified on Claude Code 2.1.222 that a worker detached by the session-open
hook survives the hook returning, the one vendor behavior this design needs
and no portable test can see.

Re-landed on current main, superseding PR kunchenguid#1845, which was cut from a
pre-kunchenguid#1842 base. The digest's section numbering in AGENTS.md section 3 now
states the emission order directly - supervision block and its read-once
contract, fleet state, network checks, then context - which keeps kunchenguid#1826's
fleet-state-before-context ordering. The old-bin test shim keeps main's
git-archive baseline from kunchenguid#1851, which already subsumes this branch's reason
for widening that shim.

* docs(verification): re-measure the deferred startup stage on the current base

Re-runs the unreachable-remote latency fixture against default-branch tip
8398d31 rather than the now-historical 345de4e, and records the sweep-result
comparison the deferral's safety argument rests on: the deferred worker's
published report is byte-identical to the three sweep lines the blocking
baseline printed, with the unreachable route preserved in both.

* no-mistakes(review): Fail deferred startup when report publication fails

* no-mistakes(document): Document deferred startup network behavior accurately

* fix(procevent): apply remote replies during capture (kunchenguid#1831)

* fix(procevent): apply a captured adapter result in code, not by instruction

A remote secondmate's reply was captured and announced, but never applied.
Nothing dispatched the reply adapter's `handle` on a `procevent remote-reply`
wake, and the handling instruction named only the generic acknowledgement, so
the wake was retired while everything it carried was dropped: the reply never
reached the secondmate's local status mirror, the request it answered kept
escalating as a missed report, and the relay - whose registration each capture
retires, and which only that same handling re-arms - was left dead until the
next session start armed it again.

Applying such a result carries no judgement, so it belongs in code. After
publishing, the runner now calls
`bin/fm-procevent-<adapter>.sh autohandle <source-id> <sequence> <result-file>`
and lets the adapter apply and acknowledge its own result, through the same kind
of seam that already owns the terminal verdict. It runs strictly after terminal
retirement, because a handling adapter re-arms its own next source and retiring
afterwards would drop that fresh registration. An adapter with no such command,
or one whose pass does not complete, leaves the result unacknowledged and
therefore still announced, so a handler receives it exactly as before.

Resolving the request was not enough on its own either. An escalation opens a
durable keyed decision in the parent status log, and nothing ever closed it, so
a request the remote had answered kept surfacing in every later open-decisions
fold. The pending-reply library now owns both ends of that decision: it opens
one under a per-request key rather than the shared default key, and closes it
once the record resolves, appending the closing line only while that exact
decision is still open in the fold so it can neither double-close nor clear an
unrelated decision that has since taken the same key.

The handling instruction still routes a wake to its adapter, now as the
idempotent confirmation of what the runner already did rather than as the
guarantee.

Verified end to end in a throwaway isolated home driving the real armed source,
blocking delta reader, runner, and wake queue, with the handler doing only the
generic acknowledgement and no part of the ingest stubbed: before, seven failed
observations reproducing the incident; after, none. Each half is independently
load-bearing - without the runner change the reply never reaches the mirror,
without the escalation close the settled request still surfaces as an open
decision.

* no-mistakes(review): Prevent legacy reply closure from masking decisions

* no-mistakes(review): Serialize pending reply resolution and escalation closure

* no-mistakes(review): Serialize pending reply escalation with resolution

* no-mistakes(review): Clarify guarded legacy escalation closure behavior

* no-mistakes(review): Guard legacy closure and reserve pending reply keys

* no-mistakes(review): Match pending reply escalations by construction

* no-mistakes(document): Document automatic remote reply resolution

* no-mistakes(lint): Fix unused concurrent escalation loop variable

* no-mistakes(lint): Fix unused concurrent resolution loop binding

* no-mistakes(review): Version fold cache and gate autohandle on publication

* no-mistakes(document): Clarify remote reply relay documentation

* feat(skills): port internal stow curation disciplines to the public skill (kunchenguid#1841)

Bring the public installer-facing stow skill up to the internal skill's
current curation behavior while keeping it fully standalone:

- Replace the total-capture thesis with the compact-operating-map framing.
- Add read-the-destination-before-writing with the inspect-then-update
  triad (supersedes what, one-sentence rewrite, delete stale now).
- Add the concrete prune list together with its unique-fact guard, as an
  accuracy discipline with no size-budget machinery.
- Curate every memory file the pass has open, not only the routed one.
- Add the standing-decisions sweep category.
- Add the stronger-owner pointer-over-copy test before filing.
- Add tool-agnostic task-note discipline (inspect, classify, considered
  replacement body, never blind-append) and blocked-on recording.
- Give .stow-notes.md a closed set of three exits.
- Forbid storing, creating, or editing a skill as a stow destination.
- Report per-file action verbs in the completion receipt.
- Consolidate the repeated local-vs-external and .gitignore prose and fix
  the second-person voice slip, so the file does not grow (11334 -> 11276
  bytes).

* chore(bootstrap): raise lavish-axi version floor to 0.1.46 (kunchenguid#1865)

* fix(bin): keep tracked Claude hook entries inert under grok 1.0.0 (kunchenguid#1917)

* fix(hooks): keep tracked Claude entries inert under grok 1.0.0 hooks

Grok loads Claude-compatible settings, so the tracked `.claude/settings.json`
hook entries also fire under Grok. They were meant to be inert there, guarded
by `[ -z "${GROK_AGENT:-}" ] || exit 0`. That guard silently stopped working.

Verified from the live process environment of a wedged grok 1.0.0 Stop hook on
2026-08-07: a grok 1.0.0 HOOK process carries GROK_HOOK_EVENT, GROK_HOOK_NAME,
GROK_SESSION_ID, and GROK_WORKSPACE_ROOT, but no GROK_AGENT. The observed hook
process was labelled `GROK_HOOK_NAME=project/settings:stop[0].hooks[1]`, which
is the Claude-only auto-arm entry.

Consequence: Grok ran `bin/fm-claude-stop-autoarm.sh` synchronously. Grok has
no `asyncRewake`, so it waited on the foregrounded watcher for that entry's
declared 28800-second timeout and the Grok turn never ended - the operator saw
an infinite "Responding".

Widen the guard to `[ -z "${GROK_AGENT:-}${GROK_HOOK_EVENT:-}" ] || exit 0` on
the five entries that have a `.grok/hooks/` counterpart: both Stop entries, the
SessionStart entry, and the two PreToolUse Bash entries.

Two deliberate limits:

- The guard is NOT widened to GROK_SESSION_ID. Grok injects it into every child
  process, so it can survive into a Claude session that Grok launched and would
  silently disable Claude's own watcher continuity. GROK_HOOK_EVENT is
  per-hook-invocation and does not leak that way.
- `bin/fm-subagent-pretool-check.sh` stays unguarded on purpose. It is the one
  tracked entry with no `.grok/hooks/` counterpart, so guarding it would remove
  the guard from Grok entirely rather than deduplicate it. The new test asserts
  it stays unguarded so the exception cannot be closed silently, and
  docs/subagent-guard.md is honest that the coverage it leaves is partial.

`bin/fm-harness.sh` corrects a comment that presented GROK_AGENT as reliably
present; it is a fast path only, and the ancestry walk is what actually
guarantees grok identification.

tests/fm-turnend-guard.test.sh adds test_tracked_claude_entries_inert_under_grok,
which runs every tracked entry under a real grok 1.0.0 hook environment, a
legacy GROK_AGENT environment, and a native Claude environment.

* no-mistakes(document): docs: sync grok hook-marker guard facts to owners

* no-mistakes(review): docs: state grok guard criterion by event coverage

* feat(startup-network): record per-step elapsed times for the deferred stage (kunchenguid#1918)

The deferred network stage published one aggregate started/finished pair, so
a run that took a minute could not be attributed to a phase, a host, or a
clone without re-running it by hand under manual tracing.

Add bin/fm-timing-lib.sh as the single owner of elapsed-time records, and
bracket each network owner with one: the gh auth probe, the secondmate
liveness sweep, secondmate convergence, pending handoff delivery, and the
project clone refresh, plus one record per secondmate for the remote-touching
steps (id and host) and one per project clone. Each record carries a start
offset from one shared origin, so the artifact reads as a timeline.

The stage publishes them beside its report as state/.startup-network.timings,
for a timed-out or failed run too, where the partial record is the answer.
Only the on-demand `report` command prints them: `harvest` composes the
session-start digest, so its output, the wake cadence, and every other part
of a normal session start are unchanged.

Recording is inert unless a run asks for it, so nothing else that sources
these scripts pays for it. Details are identities only - a detail carrying
whitespace is refused rather than cleaned up, which is what keeps a command
line, an environment dump, or a captured error out of the file.

Split two per-item loop bodies into their own functions so each iteration can
be timed; every `continue` became a `return 0` with the same meaning, and the
sweeps still run directly, in the same order, returning the same results.

* feat(stow): cascade the internal /stow to every registered secondmate (kunchenguid#1928)

* feat(stow): cascade the internal /stow to every registered secondmate

Invoked in a primary home, /stow now sweeps every registered secondmate
after the primary's own required pass, enforcing the same startup-memory
threshold in each home against that home's own allowance rather than a
fleet total.

bin/fm-stow-cascade.sh owns the mechanical inputs: it enumerates each
registered secondmate exactly once from data/secondmates.md, reports that
home's own budget accounting, and resolves how the sweep reaches it. A
live agent sweeps its own home so its uncaptured session knowledge is
captured too; a local home without one is curated in place; a remote home
without one is accounted read-only and deferred, because there is no
generic remote write path for a home's own memory files. Every host-
crossing step and each home's accounting runs under one hard bound, so a
slow or unreachable home reports an exception and the sweep continues.

Nothing changes until /stow is invoked: no new notification, digest
section, or background work. The public skills/stow skill is untouched.

* no-mistakes(review): fix(stow): extend cascade --help range to include full exit-code contract

* fix(remote-job): stop workers abandoned by a pruned code root (kunchenguid#1927)

29 fm-remote-job-worker.sh processes were found running at ppid 1, 1-2 days
old, each still polling and appending to a log inside a no-mistakes gate
worktree that had already been returned.

Three things combined to make that possible:

- The recorded worker.pid is the serving child, not the restart supervisor
  above it, so a teardown that stops that one pid only makes the supervisor
  respawn. The Linux start path also left the worker tree in the launching
  command's process group, so there was no group to signal instead.
- Neither the serving loop nor the supervisor ever rechecked whether its
  configured FM_ROOT still existed, so a worker launched from a worktree
  outlived that worktree indefinitely.
- The supervisor restarted a failing child with a fixed 0.1s delay and no
  bound, which is what grew the logs (~66MB/day measured).

The Linux start path now puts the worker tree in its own process group, and
fm_remote_job_stop_worker_tree signals that whole group - refusing any group
whose leader is not itself a worker, so a worker from an older build or from
launchd's own session is still stopped safely as a single process. The worker
stops itself once its code root stops being a Firstmate checkout, confirmed
across a grace window so an ordinary transient cannot stop a healthy worker.
The supervisor backs off and gives up rather than restarting forever.

bin/fm-remote-job-reap-orphans.sh is the belt-and-suspenders sweep for workers
already orphaned that way, wired into fm-teardown.sh. Its reap condition is
exactly "the code root named in the worker's own command line is gone", which
is why the account's healthy LaunchAgent worker and every live remote
secondmate worker are never candidates.

The two suites that leaked these in the first place now stop the worker tree
rather than the recorded pid alone.

* feat(bin): lint only the changed shard locally, full lint in CI (kunchenguid#1925)

* fix(bin): lint only the changed shard locally, full lint in CI

Two ships hitting fm-lint.sh at once could spike CPU to 190% and load
to 8.58 on a captain's Mac, even though each run finishes quickly.
fm-lint.sh now defaults to linting only the canonical-set files
changed since the merge-base with origin/main (including uncommitted
edits) on an ordinary local branch, using plain local git with no
network calls. It still lints the full canonical set in CI
(GITHUB_ACTIONS=true or CI=true), on the main branch, or whenever no
merge-base can be found, so CI coverage never depends on a local diff.
Explicit paths keep bypassing this selection entirely.

* no-mistakes: apply CI fixes

---------

Co-authored-by: Kun Chen <[email protected]>
Co-authored-by: Jay Park <[email protected]>
Co-authored-by: RALPH <[email protected]>
blazingbunny pushed a commit to blazingbunny/firstmate that referenced this pull request Aug 9, 2026
…henguid#1925)

* fix(bin): lint only the changed shard locally, full lint in CI

Two ships hitting fm-lint.sh at once could spike CPU to 190% and load
to 8.58 on a captain's Mac, even though each run finishes quickly.
fm-lint.sh now defaults to linting only the canonical-set files
changed since the merge-base with origin/main (including uncommitted
edits) on an ordinary local branch, using plain local git with no
network calls. It still lints the full canonical set in CI
(GITHUB_ACTIONS=true or CI=true), on the main branch, or whenever no
merge-base can be found, so CI coverage never depends on a local diff.
Explicit paths keep bypassing this selection entirely.

* no-mistakes: apply CI fixes
spirispark added a commit to spirispark/firstmate that referenced this pull request Aug 13, 2026