From 4e1b65b5d23e2ae9e104531d923a3ff4541ef063 Mon Sep 17 00:00:00 2001 From: Lap Tran Date: Mon, 23 Nov 2026 12:49:53 -0500 Subject: [PATCH 1/4] feat(rebuild): update every installed component from one rebuild --- flake.lock | 12 +-- home.nix | 10 +- readme.md | 21 ++++ rebuild.sh | 192 ++++++++++++++++++++++++++++++++-- tests/rebuild-update-steps.sh | 64 ++++++++++++ tests/run.sh | 1 + 6 files changed, 280 insertions(+), 20 deletions(-) create mode 100755 tests/rebuild-update-steps.sh diff --git a/flake.lock b/flake.lock index 8f00637..41a13b4 100644 --- a/flake.lock +++ b/flake.lock @@ -24,11 +24,11 @@ ] }, "locked": { - "lastModified": 1792818383, - "narHash": "sha256-199i7ubVSXTMl+0AAlL7cVCXSjcI+jWByMcimYjeMX0=", + "lastModified": 1795325060, + "narHash": "sha256-XYoMPsqRFZ6jOaYI1KAAu8fzqif4tkCX8mhEKrViDXQ=", "owner": "nix-community", "repo": "home-manager", - "rev": "24f2190587513b9c2f73db112a17844ae912d965", + "rev": "6480d7d8533b88c78cc6dcda395ab89cd546e450", "type": "github" }, "original": { @@ -79,11 +79,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1793976852, - "narHash": "sha256-bWDN3JZcE9ovYoaD0/6WYbMtXYpUu0vd5onpK0pc/SE=", + "lastModified": 1795387764, + "narHash": "sha256-c2VS34FJxgjfNbfKgh837LzPzx9S2FXTez+Th1iKDZ8=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "57f1c8965649ce5bcac5118a0d2e41f1fbdc56e5", + "rev": "f0b41a99f28c34ffeaff61d4b419afff0516a923", "type": "github" }, "original": { diff --git a/home.nix b/home.nix index a883203..6ed39da 100644 --- a/home.nix +++ b/home.nix @@ -319,7 +319,8 @@ in # Firstmate companion CLIs (*-axi). None is a Homebrew or Nix formula, so # install them through Homebrew's npm. tasks-axi is version-gated by firstmate # (>= 0.2.6 is required before a spawn/teardown automatic backlog transition - # will run), so pin it and reinstall on drift; the rest install when absent. + # will run), so fill a missing or older copy; rebuild.sh moves it on to the + # latest release. The rest install when absent on a fresh machine. home.activation.axiTools = lib.hm.dag.entryAfter [ "writeBoundary" ] '' set -euo pipefail # Activation PATH lacks /opt/homebrew/bin, so npm's `#!/usr/bin/env node` @@ -331,10 +332,13 @@ in echo "axiTools: /opt/homebrew/bin/npm missing (declare node in homebrew.brews)" >&2 exit 1 fi - # Pin tasks-axi; reinstall only when the installed version differs. + # tasks-axi: install the firstmate floor only when the copy is missing or + # older. A newer copy is left alone so rebuild.sh's latest-release update + # survives the next switch. want_tasks_axi="0.2.6" have_tasks_axi="$(tasks-axi --version 2>/dev/null | head -1 | tr -d '[:space:]')" - if [ "$have_tasks_axi" != "$want_tasks_axi" ]; then + if [ -z "$have_tasks_axi" ] \ + || [ "$(printf '%s\n%s\n' "$want_tasks_axi" "$have_tasks_axi" | sort -V | head -1)" != "$want_tasks_axi" ]; then "$npm" install -g "tasks-axi@$want_tasks_axi" fi # Companion CLIs without a firstmate-enforced version floor: install once. diff --git a/readme.md b/readme.md index a772df2..eca2a10 100644 --- a/readme.md +++ b/readme.md @@ -54,6 +54,7 @@ The captain confirmed the split on 2026-11-15. Leave it unchanged: ./tests/fm-launcher.sh --live # installed zshrc; fails while it still launches Pi ./tests/fm-launcher.sh # generated zshrc; must pass ./tests/crew-dispatch.sh # routing via firstmate, model IDs via opencode models +./tests/rebuild-update-steps.sh # static audit of rebuild.sh update steps ./tests/run.sh # all checks ``` @@ -75,6 +76,26 @@ The Nix sources in this repository are the durable record. The live files are ge This follows the NIST SP 800-128 Rev. 1 (2019) Section 3.3 "Controlling Configuration Change" (CM-3) practice: route every change through review and approval, test it, record it in version control, and restrict who can change the operational configuration. The 2011 edition is withdrawn and superseded by Revision 1. +## What `rebuild.sh` updates + +One `./rebuild.sh` run brings every installed component to its latest supported version. Each step is idempotent: a current copy is left alone, and a re-run repeats no install. When a tool or the network is absent, the step prints a warning and the rebuild continues. + +Before the switch: + +- Homebrew formulae and casks, through `brew update` and `brew upgrade`. `configuration.nix` stays the declaration; `onActivation.upgrade` repeats the upgrade during the switch. +- npm globals through `/opt/homebrew/bin/npm`, never Nix's npm: `@steipete/bird`, `acpx`, `backpass`, `chrome-devtools-axi`, `defuddle`, `forgejo-axi`, `gh-axi`, `lavish-axi`, `quota-axi`, and `tasks-axi`. Each package is compared with the registry before an install. `tasks-axi` keeps its firstmate floor of 0.2.6 in `home.activation.axiTools`, which now installs only a missing or older copy, so the latest release survives the switch. +- Retired npm packages are removed only while their evidence still holds: `@opencode-ai/cli`, `opencode-ai`, and the June `pi-cli`/`pi-coding-agent` placeholders. The global `pi-context` is removed only when Pi keeps its own copy under `~/.pi/agent/npm`. If `pi` resolves into npm's global tree, the script warns and leaves those packages in place. +- `no-mistakes update`, using the binary at `~/.no-mistakes/bin/no-mistakes`. +- `hermes update --yes`, which pulls the configured channel and restarts the services that run its new code. +- `nix flake update`, so the switch builds from the newest locked inputs. Commit the resulting `flake.lock` change. + +After the switch: + +- The Skills CLI updates every skill tracked in `~/.agents/.skill-lock.json`. The pinned pstack skills are not in that lock, so they stay on the `home.nix` revision (see [pstack skills](#pstack-skills-pinned-on-every-rebuild)). `security-audit` is excluded on purpose, because `home.nix` freezes it so a rebuild never pulls a new skill mid-session; renew it by hand with the command in [security-audit skill](#security-audit-skill-agent-security-reviews). +- `pi update --extensions --no-approve`, run after the switch because the Homebrew bundle may have upgraded the `pi` binary. + +Two tools have no supported updater: `actionlint` and `shellcheck` are standalone binaries in `~/.local/bin`, downloaded from their release pages. The rebuild does not replace them. Both were current on 2026-11-23 (actionlint 1.7.12, shellcheck 0.11.0); fetch a new release by hand when one is published. The pinned pstack tree also stays put; see its section for how to move it. + ## security-audit skill (agent security reviews) `home.activation.securityAuditSkill` installs Cloudflare's `security-audit` skill from `https://github.com/cloudflare/security-audit-skill` so the coding agents can run a structured vulnerability audit. The exact command: diff --git a/rebuild.sh b/rebuild.sh index df487f6..14a84a1 100755 --- a/rebuild.sh +++ b/rebuild.sh @@ -1,19 +1,95 @@ #!/usr/bin/env bash -# Rebuild nix-darwin + home-manager. Rotates stale home-manager *.backup files -# so a second switch never fails with "would be clobbered". -# Also updates flake inputs, upgrades grok-build, removes retired npm OpenCode -# packages, updates no-mistakes, and updates pi extensions. +# Rebuild nix-darwin + home-manager from this checkout. +# +# Before the switch, update every installed component that is not declarative: +# Homebrew formulae and casks, npm globals (through Homebrew's node, never +# Nix's npm), no-mistakes, Hermes Agent, and the flake inputs. After the switch, +# update the installed agent skills and Pi extensions against the upgraded +# binaries. +# +# Rotates stale home-manager *.backup files before the switch so a second switch +# never fails with "would be clobbered". +# Every update step is idempotent and warns when its tool or network is absent, +# so one missing updater never aborts the rebuild. set -euo pipefail DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" ln -sfn "$DIR" ~/.dotfiles +NPM=/opt/homebrew/bin/npm -# Upgrade grok-build to latest (Homebrew cask). -# Skip if Homebrew API is unreachable (DNS/network issues). -echo "==> Upgrading grok-build..." -if brew upgrade grok-build 2>&1; then - echo "==> grok-build upgrade complete" +# Homebrew: configuration.nix declares the formulae and casks, and the nix-darwin +# activation upgrades them too. This explicit pass reports what moved before the +# switch and keeps the same warning-not-fail behaviour when the network is down. +echo "==> Updating Homebrew formulae and casks..." +if ! command -v brew >/dev/null 2>&1; then + echo "==> WARNING: brew not found. Skipping Homebrew update." +elif brew update 2>&1 && brew upgrade 2>&1; then + echo "==> Homebrew update complete" else - echo "==> WARNING: grok-build upgrade failed (network issue). Skipping." + echo "==> WARNING: Homebrew update failed (network or package issue). Continuing with installed versions." +fi + +# npm globals are installed outside Nix and Homebrew, so no other step moves +# them. Use /opt/homebrew/bin/npm explicitly: the activation PATH can resolve +# Nix's npm, which cannot write the Homebrew prefix, and these packages belong to +# Homebrew's node. Each package is compared with the registry first, so a current +# copy is left alone and a failed lookup or install only warns. +echo "==> Updating npm global tools..." +if [ ! -x "$NPM" ]; then + echo "==> WARNING: $NPM not found (declare node in homebrew.brews). Skipping npm global updates." +else + npm_node=/opt/homebrew/bin/node + update_npm_global() { + pkg="$1" + installed="$("$NPM" ls -g --depth=0 --json 2>/dev/null \ + | "$npm_node" -e ' +let raw = ""; +process.stdin.on("data", (chunk) => { raw += chunk; }); +process.stdin.on("end", () => { + try { + const tree = JSON.parse(raw); + const entry = (tree.dependencies || {})[process.argv[1]] || {}; + process.stdout.write(entry.version || ""); + } catch {} +}); +' "$pkg" || true)" + latest="$("$NPM" view "$pkg" version --fetch-timeout=15000 --fetch-retries=1 2>/dev/null \ + | tr -d '[:space:]' || true)" + if [ -z "$latest" ]; then + echo "==> WARNING: cannot read the latest $pkg version from the registry. Keeping the installed copy." + return 0 + fi + if [ "$installed" = "$latest" ]; then + echo "==> $pkg already at $latest" + return 0 + fi + current="$installed" + [ -n "$current" ] || current=none + echo "==> $pkg $current -> $latest" + if "$NPM" install -g "$pkg@$latest" >/dev/null 2>&1; then + echo "==> $pkg installed at $latest" + else + echo "==> WARNING: $pkg install of $latest failed. Keeping the installed copy." + fi + return 0 + } + # tasks-axi is also gated by home.nix (firstmate needs >= 0.2.6). Update it + # here so it reaches the latest release; the activation only fills a gap. + npm_globals=( + "@steipete/bird" + acpx + backpass + chrome-devtools-axi + defuddle + forgejo-axi + gh-axi + lavish-axi + quota-axi + tasks-axi + ) + for pkg in "${npm_globals[@]}"; do + update_npm_global "$pkg" + done + echo "==> npm global tools update complete" fi # Remove retired npm OpenCode installs if an older rebuild installed them: @@ -21,7 +97,6 @@ fi # `opencode` formula declared in configuration.nix is now the only OpenCode # install, unpinned so it tracks the latest release. The guard is a local check # for npm, so a rebuild without npm skips this instead of failing. -NPM=/opt/homebrew/bin/npm if [ -x "$NPM" ] && npm_root="$("$NPM" root -g 2>/dev/null)"; then for pkg in @opencode-ai/cli opencode-ai; do if [ -d "$npm_root/$pkg" ]; then @@ -45,6 +120,52 @@ for link in /opt/homebrew/bin/*; do esac done +# The npm placeholders pi-cli@0.0.0, pi-coding-agent@0.0.1, and pi-context@2.0.0 +# are leftovers from June. Evidence they are retired, not live tools: +# - pi-cli 0.0.0 is an unrelated 2022 package (gpio dependency) with no bin. +# - pi-coding-agent 0.0.1 is a name-reservation placeholder with no bin; the +# Homebrew formula owns /opt/homebrew/bin/pi. +# - pi-context is installed and updated by Pi itself (~/.pi/agent/npm), and the +# global copy has no bin. +# Remove each only while those proofs hold. When pi or Pi's own copy is missing, +# leave the global package alone and say why. +echo "==> Removing retired npm pi packages..." +if [ ! -x "$NPM" ]; then + echo "==> WARNING: $NPM not found. Skipping retired pi package cleanup." +else + npm_root="$("$NPM" root -g 2>/dev/null || true)" + pi_bin="$(command -v pi 2>/dev/null || true)" + case "$pi_bin" in + "$npm_root"/*) + echo "==> WARNING: pi resolves to npm's global tree ($pi_bin). Leaving the npm pi packages in place." + ;; + *) + if [ -n "$npm_root" ]; then + for pkg in pi-cli pi-coding-agent; do + if [ -d "$npm_root/$pkg" ]; then + if "$NPM" uninstall -g "$pkg" >/dev/null 2>&1; then + echo "==> Removed retired npm package $pkg" + else + echo "==> WARNING: $pkg removal failed. Remove it manually: $NPM uninstall -g $pkg" + fi + fi + done + fi + ;; + esac + if [ -d "$HOME/.pi/agent/npm/node_modules/pi-context" ]; then + if [ -d "$npm_root/pi-context" ]; then + if "$NPM" uninstall -g pi-context >/dev/null 2>&1; then + echo "==> Removed unused global pi-context (Pi keeps its own copy)" + else + echo "==> WARNING: pi-context removal failed. Remove it manually: $NPM uninstall -g pi-context" + fi + fi + else + echo "==> WARNING: Pi's own pi-context package is missing. Leaving the global copy in place." + fi +fi + echo "==> Updating no-mistakes..." NO_MISTAKES_BIN="$HOME/.no-mistakes/bin/no-mistakes" if [ -x "$NO_MISTAKES_BIN" ]; then @@ -63,6 +184,19 @@ else echo "==> WARNING: no-mistakes not found. Skipping update." fi +# Hermes Agent is a mutable git clone at ~/.hermes/hermes-agent, so Nix and +# Homebrew never move it. Its own updater pulls the configured channel and +# restarts the services that run its new code; --yes keeps the rebuild +# non-interactive. A failure leaves the installed version in place. +echo "==> Updating Hermes Agent..." +if ! command -v hermes >/dev/null 2>&1; then + echo "==> WARNING: hermes not found. Skipping update." +elif hermes update --yes 2>&1; then + echo "==> hermes update complete" +else + echo "==> WARNING: hermes update failed. Keeping the installed version." +fi + stamp="$(date +%Y%m%d-%H%M%S)" # Paths home-manager manages via home.file (regular files become out-of-store symlinks). managed=( @@ -116,6 +250,42 @@ fi sudo darwin-rebuild switch --flake ~/.dotfiles#lt-mbp +# Update installed agent skills after the switch. The Skills CLI tracks most of +# ~/.agents/skills through its lock file; the pinned pstack skills are not in +# that lock, so they stay on the home.nix revision. security-audit is skipped on +# purpose: home.nix freezes it so a rebuild never pulls a new skill mid-session. +echo "==> Updating agent skills..." +NPX=/opt/homebrew/bin/npx +SKILL_LOCK="$HOME/.agents/.skill-lock.json" +if [ ! -x "$NPX" ]; then + echo "==> WARNING: $NPX not found. Skipping agent skill update." +elif [ ! -f "$SKILL_LOCK" ]; then + echo "==> WARNING: $SKILL_LOCK not found. Skipping agent skill update." +else + skill_names="$(/usr/bin/python3 - "$SKILL_LOCK" 2>/dev/null <<'PY' || true +import json +import sys + +with open(sys.argv[1]) as lock_file: + skills = json.load(lock_file).get("skills", {}) +for name in sorted(skills): + if name != "security-audit": + print(name) +PY +)" + if [ -z "$skill_names" ]; then + echo "==> WARNING: no tracked skills found in $SKILL_LOCK. Skipping agent skill update." + else + # Unquoted on purpose: each tracked name is a separate CLI argument. + # shellcheck disable=SC2086 + if "$NPX" --yes skills@latest update -g -y $skill_names 2>&1; then + echo "==> agent skill update complete" + else + echo "==> WARNING: agent skill update failed (network or Skills CLI issue). Skipping." + fi + fi +fi + # Update installed pi packages after the switch, because the Homebrew bundle # may have upgraded the pi binary. echo "==> Updating pi extensions..." diff --git a/tests/rebuild-update-steps.sh b/tests/rebuild-update-steps.sh new file mode 100755 index 0000000..cef377b --- /dev/null +++ b/tests/rebuild-update-steps.sh @@ -0,0 +1,64 @@ +#!/usr/bin/env bash +# Behavior check: rebuild.sh updates every installed component that is not +# declarative, and never relies on a bare `npm`. +# +# The check is static, so it runs without changing the machine: +# - the script parses as bash; +# - every npm global is updated through /opt/homebrew/bin/npm; +# - no bare npm invocation survives; +# - each component (Homebrew, npm globals, no-mistakes, Hermes, flake inputs, +# agent skills, Pi extensions) has a named step that warns instead of +# killing the rebuild; +# - the frozen security-audit skill is excluded from the skills update. +set -euo pipefail + +ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P) +REBUILD="$ROOT/rebuild.sh" + +[ -f "$REBUILD" ] || { echo "FAIL: missing $REBUILD" >&2; exit 1; } + +fail() { + echo "FAIL: $1" >&2 + exit 1 +} + +bash -n "$REBUILD" || fail "rebuild.sh does not parse" +echo "PASS: rebuild.sh parses" + +grep -qF 'NPM=/opt/homebrew/bin/npm' "$REBUILD" \ + || fail "rebuild.sh does not set NPM to Homebrew's npm" +echo "PASS: npm globals use /opt/homebrew/bin/npm" + +# A bare `npm install|uninstall|view|ls|root` would resolve Nix's npm under the +# activation PATH. Every call must go through $NPM. +if grep -nE '(^|[^/[:alnum:]_-])npm[[:space:]]+(install|uninstall|view|ls|root)' "$REBUILD"; then + fail "rebuild.sh calls bare npm; use \$NPM instead" +fi +echo "PASS: no bare npm invocation" + +for pkg in '@steipete/bird' acpx backpass chrome-devtools-axi defuddle forgejo-axi \ + gh-axi lavish-axi quota-axi tasks-axi; do + grep -qF "$pkg" "$REBUILD" || fail "rebuild.sh does not update npm global $pkg" +done +echo "PASS: every npm global has an update entry" + +for step in 'Updating Homebrew formulae and casks' 'Updating npm global tools' \ + 'Updating no-mistakes' 'Updating Hermes Agent' 'Updating flake inputs' \ + 'Updating agent skills' 'Updating pi extensions'; do + grep -qF "==> $step..." "$REBUILD" || fail "rebuild.sh has no step: $step" +done +echo "PASS: every update step is present" + +# Each update step reports a warning and returns instead of aborting the whole +# rebuild when its tool or network is missing. +[ "$(grep -cF '==> WARNING:' "$REBUILD")" -ge 7 ] \ + || fail "rebuild.sh is missing warning fallbacks" +grep -qF 'hermes update --yes' "$REBUILD" \ + || fail "rebuild.sh does not use the supported hermes updater" +grep -qF 'skills@latest update -g -y' "$REBUILD" \ + || fail "rebuild.sh does not use the supported Skills CLI updater" +grep -qF 'name != "security-audit"' "$REBUILD" \ + || fail "rebuild.sh does not exclude the frozen security-audit skill" +echo "PASS: update steps warn and skip instead of failing" + +echo "PASS: rebuild update steps" diff --git a/tests/run.sh b/tests/run.sh index 93cce49..6f2d91e 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -12,5 +12,6 @@ status=0 "$ROOT/tests/fm-launcher.sh" || status=1 "$ROOT/tests/crew-dispatch.sh" || status=1 +"$ROOT/tests/rebuild-update-steps.sh" || status=1 exit "$status" From 4a31495181490f90fc9528563ee6dea326370efc Mon Sep 17 00:00:00 2001 From: Lap Tran Date: Mon, 23 Nov 2026 13:10:09 -0500 Subject: [PATCH 2/4] no-mistakes(review): Fix updater ownership and behavioral coverage --- readme.md | 8 +- rebuild.sh | 25 +-- tests/rebuild-update-steps.py | 278 ++++++++++++++++++++++++++++++++++ tests/rebuild-update-steps.sh | 61 +------- 4 files changed, 291 insertions(+), 81 deletions(-) create mode 100644 tests/rebuild-update-steps.py diff --git a/readme.md b/readme.md index eca2a10..d9950ae 100644 --- a/readme.md +++ b/readme.md @@ -82,13 +82,17 @@ One `./rebuild.sh` run brings every installed component to its latest supported Before the switch: -- Homebrew formulae and casks, through `brew update` and `brew upgrade`. `configuration.nix` stays the declaration; `onActivation.upgrade` repeats the upgrade during the switch. -- npm globals through `/opt/homebrew/bin/npm`, never Nix's npm: `@steipete/bird`, `acpx`, `backpass`, `chrome-devtools-axi`, `defuddle`, `forgejo-axi`, `gh-axi`, `lavish-axi`, `quota-axi`, and `tasks-axi`. Each package is compared with the registry before an install. `tasks-axi` keeps its firstmate floor of 0.2.6 in `home.activation.axiTools`, which now installs only a missing or older copy, so the latest release survives the switch. +- Installed npm globals through `/opt/homebrew/bin/npm`, never Nix's npm: `@steipete/bird`, `chrome-devtools-axi`, `defuddle`, `forgejo-axi`, `gh-axi`, `lavish-axi`, `quota-axi`, and `tasks-axi`. The script skips absent packages and compares each installed package with the registry before an update. `tasks-axi` keeps its firstmate floor of 0.2.6 in `home.activation.axiTools`, which now installs only a missing or older copy, so the latest release survives the switch. - Retired npm packages are removed only while their evidence still holds: `@opencode-ai/cli`, `opencode-ai`, and the June `pi-cli`/`pi-coding-agent` placeholders. The global `pi-context` is removed only when Pi keeps its own copy under `~/.pi/agent/npm`. If `pi` resolves into npm's global tree, the script warns and leaves those packages in place. - `no-mistakes update`, using the binary at `~/.no-mistakes/bin/no-mistakes`. - `hermes update --yes`, which pulls the configured channel and restarts the services that run its new code. - `nix flake update`, so the switch builds from the newest locked inputs. Commit the resulting `flake.lock` change. +During the switch: + +- nix-darwin updates Homebrew formulae and casks through `configuration.nix`'s `onActivation.autoUpdate` and `onActivation.upgrade` settings. +- `home.activation.backpass` updates `acpx` and `backpass`. Other activation steps install their declared npm packages when absent. + After the switch: - The Skills CLI updates every skill tracked in `~/.agents/.skill-lock.json`. The pinned pstack skills are not in that lock, so they stay on the `home.nix` revision (see [pstack skills](#pstack-skills-pinned-on-every-rebuild)). `security-audit` is excluded on purpose, because `home.nix` freezes it so a rebuild never pulls a new skill mid-session; renew it by hand with the command in [security-audit skill](#security-audit-skill-agent-security-reviews). diff --git a/rebuild.sh b/rebuild.sh index 14a84a1..e9d5849 100755 --- a/rebuild.sh +++ b/rebuild.sh @@ -2,8 +2,8 @@ # Rebuild nix-darwin + home-manager from this checkout. # # Before the switch, update every installed component that is not declarative: -# Homebrew formulae and casks, npm globals (through Homebrew's node, never -# Nix's npm), no-mistakes, Hermes Agent, and the flake inputs. After the switch, +# npm globals (through Homebrew's node, never Nix's npm), no-mistakes, +# Hermes Agent, and the flake inputs. After the switch, # update the installed agent skills and Pi extensions against the upgraded # binaries. # @@ -16,18 +16,6 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" ln -sfn "$DIR" ~/.dotfiles NPM=/opt/homebrew/bin/npm -# Homebrew: configuration.nix declares the formulae and casks, and the nix-darwin -# activation upgrades them too. This explicit pass reports what moved before the -# switch and keeps the same warning-not-fail behaviour when the network is down. -echo "==> Updating Homebrew formulae and casks..." -if ! command -v brew >/dev/null 2>&1; then - echo "==> WARNING: brew not found. Skipping Homebrew update." -elif brew update 2>&1 && brew upgrade 2>&1; then - echo "==> Homebrew update complete" -else - echo "==> WARNING: Homebrew update failed (network or package issue). Continuing with installed versions." -fi - # npm globals are installed outside Nix and Homebrew, so no other step moves # them. Use /opt/homebrew/bin/npm explicitly: the activation PATH can resolve # Nix's npm, which cannot write the Homebrew prefix, and these packages belong to @@ -52,6 +40,9 @@ process.stdin.on("end", () => { } catch {} }); ' "$pkg" || true)" + if [ -z "$installed" ]; then + return 0 + fi latest="$("$NPM" view "$pkg" version --fetch-timeout=15000 --fetch-retries=1 2>/dev/null \ | tr -d '[:space:]' || true)" if [ -z "$latest" ]; then @@ -62,9 +53,7 @@ process.stdin.on("end", () => { echo "==> $pkg already at $latest" return 0 fi - current="$installed" - [ -n "$current" ] || current=none - echo "==> $pkg $current -> $latest" + echo "==> $pkg $installed -> $latest" if "$NPM" install -g "$pkg@$latest" >/dev/null 2>&1; then echo "==> $pkg installed at $latest" else @@ -76,8 +65,6 @@ process.stdin.on("end", () => { # here so it reaches the latest release; the activation only fills a gap. npm_globals=( "@steipete/bird" - acpx - backpass chrome-devtools-axi defuddle forgejo-axi diff --git a/tests/rebuild-update-steps.py b/tests/rebuild-update-steps.py new file mode 100644 index 0000000..98926d9 --- /dev/null +++ b/tests/rebuild-update-steps.py @@ -0,0 +1,278 @@ +"""Execute rebuild.sh against isolated external command boundaries. + +Oracles: installed-tool updates from the rebuild contract, activation ownership +from configuration.nix/home.nix, and the security-audit/pstack freeze policy. +Assertions reject dead update blocks, absent-package installs, duplicate owners, +failed-update aborts, and updates to frozen or untracked skills. +""" + +import json +import os +from pathlib import Path +import shutil +import subprocess +import sys +import tempfile +import unittest + + +ROOT = Path(__file__).resolve().parents[1] +GLOBALS = ( + "@steipete/bird", "chrome-devtools-axi", "defuddle", "forgejo-axi", + "gh-axi", "lavish-axi", "quota-axi", "tasks-axi", +) +ACTIVATION_GLOBALS = ("acpx", "backpass") + +BOUNDARIES = r''' +mock() { command "$TEST_PYTHON" "$TEST_DISPATCH" "$@"; } +function /opt/homebrew/bin/npm { mock npm "$@"; } +function /opt/homebrew/bin/node { command "$TEST_NODE" "$@"; } +function /opt/homebrew/bin/npx { mock npx "$@"; } +function /usr/bin/python3 { command "$TEST_PYTHON" "$@"; } +function [ { + if [[ $1 == '!' ]]; then + shift + ! '[' "$@" + return + fi + if [[ $1 == -x && $2 == /opt/homebrew/bin/* ]]; then + case "$2" in + /opt/homebrew/bin/npm) builtin [ "$TEST_NPM" = 1 ]; return ;; + /opt/homebrew/bin/npx) builtin [ "$TEST_NPX" = 1 ]; return ;; + esac + fi + builtin [ "$@" +} +readlink() { return 1; } +npm() { mock bare-npm "$@"; } +brew() { mock brew "$@"; } +sudo() { mock sudo "$@"; } +nix() { mock nix "$@"; } +hermes() { mock hermes "$@"; } +pi() { mock pi "$@"; } +no-mistakes() { mock no-mistakes "$@"; } +if [[ $TEST_MISSING_TOOLS == 1 ]]; then + unset -f hermes pi no-mistakes +fi +''' + +DISPATCH = r''' +import json +import os +from pathlib import Path +import sys + +kind, *args = sys.argv[1:] +root = Path(os.environ["TEST_ROOT"]) +with (root / "calls.jsonl").open("a") as log: + log.write(json.dumps([kind, *args]) + "\n") +state_path = root / "state.json" +state = json.loads(state_path.read_text()) + +def save(): + state_path.write_text(json.dumps(state)) + +if kind == "npm": + action = args[0] + if action == "ls": + if state.get("bad_inventory"): + print("invalid inventory") + sys.exit(1) + print(json.dumps({"dependencies": { + name: {"version": version} + for name, version in state["packages"].items() + }})) + elif action == "view": + if state.get("fail_lookup") == args[1]: + sys.exit(1) + print("2.0.0") + elif action == "install": + name, version = args[2].rsplit("@", 1) + if state.get("fail_install") == name: + sys.exit(1) + state["packages"][name] = version + save() + elif action == "root": + print(root / "global_modules") + else: + sys.exit("unexpected npm command: " + repr(args)) +elif kind in ("no-mistakes", "hermes", "nix", "npx", "pi"): + if state.get("fail_updaters"): + sys.exit(1) + if kind == "npx": + for name in args[5:]: + state["skills"][name] = "new" + else: + state["components"][kind] = "new" + save() +elif kind == "sudo": + sys.exit(state.get("switch_status", 0)) +else: + sys.exit("unexpected updater: " + kind) +''' + + +class RebuildUpdates(unittest.TestCase): + def setUp(self): + for tool in ("bash", "node"): + if shutil.which(tool) is None: + self.fail(f"Missing required test tool: {tool}") + self.scratch = tempfile.TemporaryDirectory(prefix=".rebuild-test-", dir=ROOT) + self.addCleanup(self.scratch.cleanup) + self.root = Path(self.scratch.name) + self.home = self.root / "home" + self.home.mkdir() + self.bin = self.root / "bin" + self.bin.mkdir() + for tool in ("dirname", "ln", "tr", "date", "mv"): + executable = shutil.which(tool) + self.assertIsNotNone(executable, f"Missing required test tool: {tool}") + (self.bin / tool).symlink_to(executable) + self.bash = shutil.which("bash") + self.env = { + "HOME": str(self.home), + "PATH": str(self.bin), + "BASH_ENV": str(self.root / "boundaries.bash"), + "TEST_ROOT": str(self.root), + "TEST_PYTHON": sys.executable, + "TEST_NODE": shutil.which("node"), + "TEST_DISPATCH": str(self.root / "dispatch.py"), + "TEST_NPM": "1", + "TEST_NPX": "1", + "TEST_MISSING_TOOLS": "0", + } + (self.root / "boundaries.bash").write_text(BOUNDARIES) + (self.root / "dispatch.py").write_text(DISPATCH) + direct = self.home / ".no-mistakes/bin/no-mistakes" + direct.parent.mkdir(parents=True) + direct.write_text(f'#!{self.bash}\nmock no-mistakes "$@"\n') + direct.chmod(0o755) + lock = self.home / ".agents/.skill-lock.json" + lock.parent.mkdir() + lock.write_text(json.dumps({"skills": { + "tdd": {}, "browser-harness": {}, "security-audit": {}, + }})) + self.state = { + "packages": {name: "1.0.0" for name in GLOBALS + ACTIVATION_GLOBALS}, + "skills": {name: "old" for name in ( + "tdd", "browser-harness", "security-audit", "codebase-design", + )}, + "components": {name: "old" for name in ( + "no-mistakes", "hermes", "nix", "pi", + )}, + } + + def execute(self): + (self.root / "state.json").write_text(json.dumps(self.state)) + (self.root / "calls.jsonl").write_text("") + result = subprocess.run( + [self.bash, str(ROOT / "rebuild.sh")], env=self.env, + cwd=ROOT, text=True, capture_output=True, timeout=30, + ) + self.assertEqual(result.returncode, self.state.get("switch_status", 0), + result.stdout + result.stderr) + self.state = json.loads((self.root / "state.json").read_text()) + self.calls = [json.loads(line) for line in + (self.root / "calls.jsonl").read_text().splitlines()] + self.assertFalse(any(call[0] in ("brew", "bare-npm") for call in self.calls)) + self.assertFalse(any(call[:2] == ["npm", "view"] and + call[2] in ACTIVATION_GLOBALS for call in self.calls)) + self.assertEqual(Path(os.readlink(self.home / ".dotfiles")), ROOT) + return result.stdout + + def assert_update_order(self): + flake = ["nix", "flake", "update", "--flake", str(self.home / ".dotfiles")] + switch = ["sudo", "darwin-rebuild", "switch", "--flake", + str(self.home / ".dotfiles") + "#lt-mbp"] + skills = ["npx", "--yes", "skills@latest", "update", "-g", "-y", + "browser-harness", "tdd"] + pi = ["pi", "update", "--extensions", "--no-approve"] + self.assertIn(["no-mistakes", "update"], self.calls) + self.assertIn(["hermes", "update", "--yes"], self.calls) + self.assertLess(self.calls.index(flake), self.calls.index(switch)) + self.assertLess(self.calls.index(switch), self.calls.index(skills)) + self.assertLess(self.calls.index(skills), self.calls.index(pi)) + + def test_updates_installed_tools_and_preserves_frozen_skills(self): + self.execute() + self.assert_update_order() + for name in GLOBALS: + self.assertIn(["npm", "install", "-g", name + "@2.0.0"], self.calls) + self.assertEqual(self.state["packages"][name], "2.0.0") + for name in ACTIVATION_GLOBALS: + self.assertEqual(self.state["packages"][name], "1.0.0") + self.assertEqual(self.state["skills"], { + "browser-harness": "new", "tdd": "new", + "security-audit": "old", "codebase-design": "old", + }) + self.assertTrue(all(version == "new" for version in + self.state["components"].values())) + self.execute() + self.assertFalse(any(call[:2] == ["npm", "install"] for call in self.calls)) + + def test_absent_packages_are_not_installed_or_queried(self): + self.state["packages"] = {} + self.execute() + self.assertEqual(self.state["packages"], {}) + self.assertFalse(any(call[:2] in (["npm", "install"], ["npm", "view"]) + for call in self.calls)) + self.assert_update_order() + + def test_registry_and_install_failures_preserve_versions_and_continue(self): + self.state["fail_lookup"] = "@steipete/bird" + self.state["fail_install"] = "defuddle" + output = self.execute() + self.assertIn("WARNING:", output) + self.assertEqual(self.state["packages"]["@steipete/bird"], "1.0.0") + self.assertEqual(self.state["packages"]["defuddle"], "1.0.0") + self.assertEqual(self.state["packages"]["tasks-axi"], "2.0.0") + self.assert_update_order() + + def test_bad_inventory_never_installs_packages(self): + self.state["bad_inventory"] = True + self.execute() + self.assertFalse(any(call[:2] == ["npm", "install"] for call in self.calls)) + self.assert_update_order() + + def test_updater_failures_do_not_abort_switch_or_later_updates(self): + self.state["fail_updaters"] = True + output = self.execute() + self.assert_update_order() + self.assertGreaterEqual(output.count("WARNING:"), 5) + self.assertTrue(all(version == "old" for version in + self.state["components"].values())) + self.assertTrue(all(version == "old" for version in self.state["skills"].values())) + + def test_missing_tools_warn_and_still_switch(self): + self.env.update(TEST_NPM="0", TEST_NPX="0", TEST_MISSING_TOOLS="1") + (self.home / ".no-mistakes/bin/no-mistakes").unlink() + output = self.execute() + self.assertGreaterEqual(output.count("WARNING:"), 5) + self.assertEqual([call[0] for call in self.calls], ["nix", "sudo"]) + + def test_no_mistakes_path_fallback(self): + (self.home / ".no-mistakes/bin/no-mistakes").unlink() + self.execute() + self.assertEqual(self.calls.count(["no-mistakes", "update"]), 1) + + def test_missing_empty_or_frozen_only_lock_never_updates_skills(self): + lock = self.home / ".agents/.skill-lock.json" + for skills in (None, {}, {"security-audit": {}}): + with self.subTest(skills=skills): + if skills is None: + lock.unlink() + else: + lock.write_text(json.dumps({"skills": skills})) + self.execute() + self.assertFalse(any(call[0] == "npx" for call in self.calls)) + self.assertEqual(self.state["skills"]["security-audit"], "old") + self.assertIn(["pi", "update", "--extensions", "--no-approve"], self.calls) + + def test_switch_failure_stops_post_switch_updates(self): + self.state["switch_status"] = 1 + self.execute() + self.assertFalse(any(call[0] in ("npx", "pi") for call in self.calls)) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/rebuild-update-steps.sh b/tests/rebuild-update-steps.sh index cef377b..676a4d4 100755 --- a/tests/rebuild-update-steps.sh +++ b/tests/rebuild-update-steps.sh @@ -1,64 +1,5 @@ #!/usr/bin/env bash -# Behavior check: rebuild.sh updates every installed component that is not -# declarative, and never relies on a bare `npm`. -# -# The check is static, so it runs without changing the machine: -# - the script parses as bash; -# - every npm global is updated through /opt/homebrew/bin/npm; -# - no bare npm invocation survives; -# - each component (Homebrew, npm globals, no-mistakes, Hermes, flake inputs, -# agent skills, Pi extensions) has a named step that warns instead of -# killing the rebuild; -# - the frozen security-audit skill is excluded from the skills update. set -euo pipefail ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P) -REBUILD="$ROOT/rebuild.sh" - -[ -f "$REBUILD" ] || { echo "FAIL: missing $REBUILD" >&2; exit 1; } - -fail() { - echo "FAIL: $1" >&2 - exit 1 -} - -bash -n "$REBUILD" || fail "rebuild.sh does not parse" -echo "PASS: rebuild.sh parses" - -grep -qF 'NPM=/opt/homebrew/bin/npm' "$REBUILD" \ - || fail "rebuild.sh does not set NPM to Homebrew's npm" -echo "PASS: npm globals use /opt/homebrew/bin/npm" - -# A bare `npm install|uninstall|view|ls|root` would resolve Nix's npm under the -# activation PATH. Every call must go through $NPM. -if grep -nE '(^|[^/[:alnum:]_-])npm[[:space:]]+(install|uninstall|view|ls|root)' "$REBUILD"; then - fail "rebuild.sh calls bare npm; use \$NPM instead" -fi -echo "PASS: no bare npm invocation" - -for pkg in '@steipete/bird' acpx backpass chrome-devtools-axi defuddle forgejo-axi \ - gh-axi lavish-axi quota-axi tasks-axi; do - grep -qF "$pkg" "$REBUILD" || fail "rebuild.sh does not update npm global $pkg" -done -echo "PASS: every npm global has an update entry" - -for step in 'Updating Homebrew formulae and casks' 'Updating npm global tools' \ - 'Updating no-mistakes' 'Updating Hermes Agent' 'Updating flake inputs' \ - 'Updating agent skills' 'Updating pi extensions'; do - grep -qF "==> $step..." "$REBUILD" || fail "rebuild.sh has no step: $step" -done -echo "PASS: every update step is present" - -# Each update step reports a warning and returns instead of aborting the whole -# rebuild when its tool or network is missing. -[ "$(grep -cF '==> WARNING:' "$REBUILD")" -ge 7 ] \ - || fail "rebuild.sh is missing warning fallbacks" -grep -qF 'hermes update --yes' "$REBUILD" \ - || fail "rebuild.sh does not use the supported hermes updater" -grep -qF 'skills@latest update -g -y' "$REBUILD" \ - || fail "rebuild.sh does not use the supported Skills CLI updater" -grep -qF 'name != "security-audit"' "$REBUILD" \ - || fail "rebuild.sh does not exclude the frozen security-audit skill" -echo "PASS: update steps warn and skip instead of failing" - -echo "PASS: rebuild update steps" +exec python3 "$ROOT/tests/rebuild-update-steps.py" From 022967e2775c29b80bccefd56ef456ad2c47684c Mon Sep 17 00:00:00 2001 From: Lap Tran Date: Mon, 23 Nov 2026 17:31:01 -0500 Subject: [PATCH 3/4] no-mistakes(review): Manage lint tools and preserve Pi packages --- home.nix | 8 +++++ readme.md | 5 +-- rebuild.sh | 48 ++--------------------------- tests/rebuild-update-steps.py | 57 +++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 48 deletions(-) diff --git a/home.nix b/home.nix index 6ed39da..bd14304 100644 --- a/home.nix +++ b/home.nix @@ -54,6 +54,14 @@ in ngrok # reverse TCP tunnel so the phone can SSH in over cellular (unfree) beets # music tagger / library organizer + navidrome sync plugin ] ++ [ ytTranscribe ]; + home.file.".local/bin/actionlint" = { + source = "${pkgs.actionlint}/bin/actionlint"; + force = true; + }; + home.file.".local/bin/shellcheck" = { + source = "${pkgs.shellcheck}/bin/shellcheck"; + force = true; + }; fonts.fontconfig.enable = true; home.sessionVariables.EDITOR = "nvim"; diff --git a/readme.md b/readme.md index d9950ae..7a277d7 100644 --- a/readme.md +++ b/readme.md @@ -83,7 +83,7 @@ One `./rebuild.sh` run brings every installed component to its latest supported Before the switch: - Installed npm globals through `/opt/homebrew/bin/npm`, never Nix's npm: `@steipete/bird`, `chrome-devtools-axi`, `defuddle`, `forgejo-axi`, `gh-axi`, `lavish-axi`, `quota-axi`, and `tasks-axi`. The script skips absent packages and compares each installed package with the registry before an update. `tasks-axi` keeps its firstmate floor of 0.2.6 in `home.activation.axiTools`, which now installs only a missing or older copy, so the latest release survives the switch. -- Retired npm packages are removed only while their evidence still holds: `@opencode-ai/cli`, `opencode-ai`, and the June `pi-cli`/`pi-coding-agent` placeholders. The global `pi-context` is removed only when Pi keeps its own copy under `~/.pi/agent/npm`. If `pi` resolves into npm's global tree, the script warns and leaves those packages in place. +- Retired npm OpenCode packages `@opencode-ai/cli` and `opencode-ai` are removed so their shims cannot conflict with the Homebrew formula. - `no-mistakes update`, using the binary at `~/.no-mistakes/bin/no-mistakes`. - `hermes update --yes`, which pulls the configured channel and restarts the services that run its new code. - `nix flake update`, so the switch builds from the newest locked inputs. Commit the resulting `flake.lock` change. @@ -92,13 +92,14 @@ During the switch: - nix-darwin updates Homebrew formulae and casks through `configuration.nix`'s `onActivation.autoUpdate` and `onActivation.upgrade` settings. - `home.activation.backpass` updates `acpx` and `backpass`. Other activation steps install their declared npm packages when absent. +- Home Manager replaces the standalone `~/.local/bin/actionlint` and `~/.local/bin/shellcheck` binaries with links to the packages selected by the updated flake. Later rebuilds update those links automatically. After the switch: - The Skills CLI updates every skill tracked in `~/.agents/.skill-lock.json`. The pinned pstack skills are not in that lock, so they stay on the `home.nix` revision (see [pstack skills](#pstack-skills-pinned-on-every-rebuild)). `security-audit` is excluded on purpose, because `home.nix` freezes it so a rebuild never pulls a new skill mid-session; renew it by hand with the command in [security-audit skill](#security-audit-skill-agent-security-reviews). - `pi update --extensions --no-approve`, run after the switch because the Homebrew bundle may have upgraded the `pi` binary. -Two tools have no supported updater: `actionlint` and `shellcheck` are standalone binaries in `~/.local/bin`, downloaded from their release pages. The rebuild does not replace them. Both were current on 2026-11-23 (actionlint 1.7.12, shellcheck 0.11.0); fetch a new release by hand when one is published. The pinned pstack tree also stays put; see its section for how to move it. +`actionlint` and `shellcheck` follow the versions available in the selected nixpkgs revision, rather than separate release downloads. The pinned pstack tree stays put; see its section for how to move it. ## security-audit skill (agent security reviews) diff --git a/rebuild.sh b/rebuild.sh index e9d5849..6c7bb97 100755 --- a/rebuild.sh +++ b/rebuild.sh @@ -107,52 +107,6 @@ for link in /opt/homebrew/bin/*; do esac done -# The npm placeholders pi-cli@0.0.0, pi-coding-agent@0.0.1, and pi-context@2.0.0 -# are leftovers from June. Evidence they are retired, not live tools: -# - pi-cli 0.0.0 is an unrelated 2022 package (gpio dependency) with no bin. -# - pi-coding-agent 0.0.1 is a name-reservation placeholder with no bin; the -# Homebrew formula owns /opt/homebrew/bin/pi. -# - pi-context is installed and updated by Pi itself (~/.pi/agent/npm), and the -# global copy has no bin. -# Remove each only while those proofs hold. When pi or Pi's own copy is missing, -# leave the global package alone and say why. -echo "==> Removing retired npm pi packages..." -if [ ! -x "$NPM" ]; then - echo "==> WARNING: $NPM not found. Skipping retired pi package cleanup." -else - npm_root="$("$NPM" root -g 2>/dev/null || true)" - pi_bin="$(command -v pi 2>/dev/null || true)" - case "$pi_bin" in - "$npm_root"/*) - echo "==> WARNING: pi resolves to npm's global tree ($pi_bin). Leaving the npm pi packages in place." - ;; - *) - if [ -n "$npm_root" ]; then - for pkg in pi-cli pi-coding-agent; do - if [ -d "$npm_root/$pkg" ]; then - if "$NPM" uninstall -g "$pkg" >/dev/null 2>&1; then - echo "==> Removed retired npm package $pkg" - else - echo "==> WARNING: $pkg removal failed. Remove it manually: $NPM uninstall -g $pkg" - fi - fi - done - fi - ;; - esac - if [ -d "$HOME/.pi/agent/npm/node_modules/pi-context" ]; then - if [ -d "$npm_root/pi-context" ]; then - if "$NPM" uninstall -g pi-context >/dev/null 2>&1; then - echo "==> Removed unused global pi-context (Pi keeps its own copy)" - else - echo "==> WARNING: pi-context removal failed. Remove it manually: $NPM uninstall -g pi-context" - fi - fi - else - echo "==> WARNING: Pi's own pi-context package is missing. Leaving the global copy in place." - fi -fi - echo "==> Updating no-mistakes..." NO_MISTAKES_BIN="$HOME/.no-mistakes/bin/no-mistakes" if [ -x "$NO_MISTAKES_BIN" ]; then @@ -198,6 +152,8 @@ managed=( "$HOME/.config/opencode/opencode.json" "$HOME/.config/opencode2/opencode.json" "$HOME/.config/opencode2/AGENTS.md" + "$HOME/.local/bin/actionlint" + "$HOME/.local/bin/shellcheck" "$HOME/.local/bin/oc2" "$HOME/.local/bin/opencode-go-token" "$HOME/.local/bin/opencode-go-key-sync" diff --git a/tests/rebuild-update-steps.py b/tests/rebuild-update-steps.py index 98926d9..00c8901 100644 --- a/tests/rebuild-update-steps.py +++ b/tests/rebuild-update-steps.py @@ -268,11 +268,68 @@ class RebuildUpdates(unittest.TestCase): self.assertEqual(self.state["skills"]["security-audit"], "old") self.assertIn(["pi", "update", "--extensions", "--no-approve"], self.calls) + def test_pi_packages_are_not_retired(self): + packages = ("pi-cli", "pi-coding-agent", "pi-context") + for name in packages: + (self.root / "global_modules" / name).mkdir(parents=True) + self.state["packages"][name] = "1.0.0" + for private_copy in (False, True): + with self.subTest(private_copy=private_copy): + if private_copy: + (self.home / ".pi/agent/npm/node_modules/pi-context").mkdir(parents=True) + self.execute() + self.assertFalse(any(call[:2] == ["npm", "uninstall"] and + call[-1] in packages for call in self.calls)) + for name in packages: + self.assertEqual(self.state["packages"][name], "1.0.0") + self.assertTrue((self.root / "global_modules" / name).is_dir()) + self.assertIn(["pi", "update", "--extensions", "--no-approve"], self.calls) + + def test_managed_lint_tool_backups_rotate(self): + for name in ("actionlint", "shellcheck"): + path = self.home / ".local/bin" / (name + ".backup") + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text("previous binary") + self.execute() + for name in ("actionlint", "shellcheck"): + path = self.home / ".local/bin" / (name + ".backup") + self.assertFalse(path.exists()) + rotated = list(path.parent.glob(name + ".backup.*")) + self.assertEqual(len(rotated), 1) + self.assertEqual(rotated[0].read_text(), "previous binary") + def test_switch_failure_stops_post_switch_updates(self): self.state["switch_status"] = 1 self.execute() self.assertFalse(any(call[0] in ("npx", "pi") for call in self.calls)) +class ManagedLintTools(unittest.TestCase): + def test_commands_follow_selected_nixpkgs_packages(self): + nix = shutil.which("nix") + self.assertIsNotNone(nix, "Missing required test tool: nix") + expression = ''' + let + system = (builtins.getFlake (toString ./.)).darwinConfigurations."lt-mbp"; + files = system.config.home-manager.users.laptran.home.file; + in builtins.map (name: { + inherit name; + source = toString files.${".local/bin/" + name}.source; + force = files.${".local/bin/" + name}.force; + package = toString system.pkgs.${name}; + }) [ "actionlint" "shellcheck" ] + ''' + result = subprocess.run( + [nix, "eval", "--json", "--impure", "--expr", expression], + cwd=ROOT, text=True, capture_output=True, timeout=120, + ) + self.assertEqual(result.returncode, 0, result.stderr) + for command in json.loads(result.stdout): + with self.subTest(name=command["name"]): + self.assertEqual(command["source"], + command["package"] + "/bin/" + command["name"]) + self.assertTrue(command["force"]) + + if __name__ == "__main__": unittest.main() From ad55229df8fceec9b570502f5123176ee45ef35c Mon Sep 17 00:00:00 2001 From: Lap Tran Date: Mon, 23 Nov 2026 17:57:16 -0500 Subject: [PATCH 4/4] no-mistakes(document): Clarify rebuild updates and check guidance --- home.nix | 2 +- readme.md | 14 ++++----- rebuild.sh | 25 ++++++++-------- tests/rebuild-update-steps.py | 54 +++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 22 deletions(-) diff --git a/home.nix b/home.nix index bd14304..022a48d 100644 --- a/home.nix +++ b/home.nix @@ -344,7 +344,7 @@ in # older. A newer copy is left alone so rebuild.sh's latest-release update # survives the next switch. want_tasks_axi="0.2.6" - have_tasks_axi="$(tasks-axi --version 2>/dev/null | head -1 | tr -d '[:space:]')" + have_tasks_axi="$(tasks-axi --version 2>/dev/null | head -1 | tr -d '[:space:]' || true)" if [ -z "$have_tasks_axi" ] \ || [ "$(printf '%s\n%s\n' "$want_tasks_axi" "$have_tasks_axi" | sort -V | head -1)" != "$want_tasks_axi" ]; then "$npm" install -g "tasks-axi@$want_tasks_axi" diff --git a/readme.md b/readme.md index 7a277d7..b010ab5 100644 --- a/readme.md +++ b/readme.md @@ -54,7 +54,7 @@ The captain confirmed the split on 2026-11-15. Leave it unchanged: ./tests/fm-launcher.sh --live # installed zshrc; fails while it still launches Pi ./tests/fm-launcher.sh # generated zshrc; must pass ./tests/crew-dispatch.sh # routing via firstmate, model IDs via opencode models -./tests/rebuild-update-steps.sh # static audit of rebuild.sh update steps +./tests/rebuild-update-steps.sh # isolated updater execution and activation checks ./tests/run.sh # all checks ``` @@ -78,13 +78,13 @@ This follows the NIST SP 800-128 Rev. 1 (2019) Section 3.3 "Controlling Configur ## What `rebuild.sh` updates -One `./rebuild.sh` run brings every installed component to its latest supported version. Each step is idempotent: a current copy is left alone, and a re-run repeats no install. When a tool or the network is absent, the step prints a warning and the rebuild continues. +`./rebuild.sh` updates the components below. The npm updater skips packages already at the registry version. Other tools use their own update commands on each run. Optional updater failures print warnings and allow the rebuild to continue. A failed switch stops the script before the post-switch updates. Before the switch: -- Installed npm globals through `/opt/homebrew/bin/npm`, never Nix's npm: `@steipete/bird`, `chrome-devtools-axi`, `defuddle`, `forgejo-axi`, `gh-axi`, `lavish-axi`, `quota-axi`, and `tasks-axi`. The script skips absent packages and compares each installed package with the registry before an update. `tasks-axi` keeps its firstmate floor of 0.2.6 in `home.activation.axiTools`, which now installs only a missing or older copy, so the latest release survives the switch. +- Installed npm globals listed in `rebuild.sh`'s `npm_globals` array, through `/opt/homebrew/bin/npm`, never Nix's npm. The script skips absent packages and compares each installed package with the registry before an update. `home.activation.axiTools` enforces the `tasks-axi` minimum without downgrades, so newer releases survive the switch. - Retired npm OpenCode packages `@opencode-ai/cli` and `opencode-ai` are removed so their shims cannot conflict with the Homebrew formula. -- `no-mistakes update`, using the binary at `~/.no-mistakes/bin/no-mistakes`. +- `no-mistakes update`, using `~/.no-mistakes/bin/no-mistakes`, or the command on `PATH` if that binary is absent. - `hermes update --yes`, which pulls the configured channel and restarts the services that run its new code. - `nix flake update`, so the switch builds from the newest locked inputs. Commit the resulting `flake.lock` change. @@ -92,15 +92,13 @@ During the switch: - nix-darwin updates Homebrew formulae and casks through `configuration.nix`'s `onActivation.autoUpdate` and `onActivation.upgrade` settings. - `home.activation.backpass` updates `acpx` and `backpass`. Other activation steps install their declared npm packages when absent. -- Home Manager replaces the standalone `~/.local/bin/actionlint` and `~/.local/bin/shellcheck` binaries with links to the packages selected by the updated flake. Later rebuilds update those links automatically. +- Home Manager replaces the standalone `~/.local/bin/actionlint` and `~/.local/bin/shellcheck` binaries with links to the selected nixpkgs packages. Later rebuilds update those links automatically, rather than downloading separate releases. After the switch: -- The Skills CLI updates every skill tracked in `~/.agents/.skill-lock.json`. The pinned pstack skills are not in that lock, so they stay on the `home.nix` revision (see [pstack skills](#pstack-skills-pinned-on-every-rebuild)). `security-audit` is excluded on purpose, because `home.nix` freezes it so a rebuild never pulls a new skill mid-session; renew it by hand with the command in [security-audit skill](#security-audit-skill-agent-security-reviews). +- The Skills CLI updates skills tracked in `~/.agents/.skill-lock.json`, except `security-audit`. See [security-audit skill](#security-audit-skill-agent-security-reviews) for its freeze policy and manual update command. Untracked skills receive no update here. See [pstack skills](#pstack-skills-pinned-on-every-rebuild) for the pinned skills and their update procedure. - `pi update --extensions --no-approve`, run after the switch because the Homebrew bundle may have upgraded the `pi` binary. -`actionlint` and `shellcheck` follow the versions available in the selected nixpkgs revision, rather than separate release downloads. The pinned pstack tree stays put; see its section for how to move it. - ## security-audit skill (agent security reviews) `home.activation.securityAuditSkill` installs Cloudflare's `security-audit` skill from `https://github.com/cloudflare/security-audit-skill` so the coding agents can run a structured vulnerability audit. The exact command: diff --git a/rebuild.sh b/rebuild.sh index 6c7bb97..44cb9c9 100755 --- a/rebuild.sh +++ b/rebuild.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Rebuild nix-darwin + home-manager from this checkout. # -# Before the switch, update every installed component that is not declarative: +# Before the switch, update the non-declarative tools listed below: # npm globals (through Homebrew's node, never Nix's npm), no-mistakes, # Hermes Agent, and the flake inputs. After the switch, # update the installed agent skills and Pi extensions against the upgraded @@ -9,15 +9,15 @@ # # Rotates stale home-manager *.backup files before the switch so a second switch # never fails with "would be clobbered". -# Every update step is idempotent and warns when its tool or network is absent, -# so one missing updater never aborts the rebuild. +# Optional updater failures warn and allow the rebuild to continue. +# A failed switch stops the script before post-switch updates. set -euo pipefail DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" ln -sfn "$DIR" ~/.dotfiles NPM=/opt/homebrew/bin/npm -# npm globals are installed outside Nix and Homebrew, so no other step moves -# them. Use /opt/homebrew/bin/npm explicitly: the activation PATH can resolve +# The npm globals listed below have no declarative updater. +# Use /opt/homebrew/bin/npm explicitly: the activation PATH can resolve # Nix's npm, which cannot write the Homebrew prefix, and these packages belong to # Homebrew's node. Each package is compared with the registry first, so a current # copy is left alone and a failed lookup or install only warns. @@ -61,8 +61,8 @@ process.stdin.on("end", () => { fi return 0 } - # tasks-axi is also gated by home.nix (firstmate needs >= 0.2.6). Update it - # here so it reaches the latest release; the activation only fills a gap. + # home.activation.axiTools enforces the tasks-axi minimum without downgrades, + # so a newer release installed here survives the switch. npm_globals=( "@steipete/bird" chrome-devtools-axi @@ -128,7 +128,7 @@ fi # Hermes Agent is a mutable git clone at ~/.hermes/hermes-agent, so Nix and # Homebrew never move it. Its own updater pulls the configured channel and # restarts the services that run its new code; --yes keeps the rebuild -# non-interactive. A failure leaves the installed version in place. +# non-interactive. echo "==> Updating Hermes Agent..." if ! command -v hermes >/dev/null 2>&1; then echo "==> WARNING: hermes not found. Skipping update." @@ -139,7 +139,7 @@ else fi stamp="$(date +%Y%m%d-%H%M%S)" -# Paths home-manager manages via home.file (regular files become out-of-store symlinks). +# Paths managed by home.file, including config links and Nix package binaries. managed=( "$HOME/.grok/config.toml" "$HOME/.grok/AGENTS.md" @@ -193,10 +193,9 @@ fi sudo darwin-rebuild switch --flake ~/.dotfiles#lt-mbp -# Update installed agent skills after the switch. The Skills CLI tracks most of -# ~/.agents/skills through its lock file; the pinned pstack skills are not in -# that lock, so they stay on the home.nix revision. security-audit is skipped on -# purpose: home.nix freezes it so a rebuild never pulls a new skill mid-session. +# Update tracked skills after activation. Exclude security-audit to preserve +# home.activation.securityAuditSkill's freeze policy. Untracked skills, +# including the pinned pstack copies, are outside this updater's scope. echo "==> Updating agent skills..." NPX=/opt/homebrew/bin/npx SKILL_LOCK="$HOME/.agents/.skill-lock.json" diff --git a/tests/rebuild-update-steps.py b/tests/rebuild-update-steps.py index 00c8901..367b819 100644 --- a/tests/rebuild-update-steps.py +++ b/tests/rebuild-update-steps.py @@ -331,5 +331,59 @@ class ManagedLintTools(unittest.TestCase): self.assertTrue(command["force"]) +class ActivationToolFloor(unittest.TestCase): + """The generated activation installs the floor without downgrading newer tools.""" + + @classmethod + def setUpClass(cls): + expression = ''' + (builtins.getFlake (toString ./.)).darwinConfigurations."lt-mbp" + .config.home-manager.users.laptran.home.activation.axiTools.data + ''' + result = subprocess.run( + ["nix", "eval", "--raw", "--impure", "--expr", expression], + cwd=ROOT, text=True, capture_output=True, timeout=120, + ) + if result.returncode: + raise AssertionError(result.stderr) + cls.activation = result.stdout + + def test_missing_old_current_and_newer_tasks_versions(self): + # Independent oracle: firstmate requires 0.2.6. A rebuild must retain + # a newer installed release instead of restoring that minimum. + boundaries = r''' +function /opt/homebrew/bin/npm { printf '%s\n' "$*" >> "$TEST_CALLS"; } +function [ { + if [[ $1 == -x && $2 == /opt/homebrew/bin/* ]]; then return 0; fi + builtin [ "$@" +} +tasks-axi() { + if [[ -z $TEST_HAVE ]]; then return 127; fi + printf '%s\n' "$TEST_HAVE" +} +''' + with tempfile.TemporaryDirectory(prefix=".activation-test-", dir=ROOT) as scratch: + root = Path(scratch) + script = root / "activation.sh" + script.write_text(boundaries + self.activation) + calls = root / "calls" + for have, installs in ( + ("", ["install -g tasks-axi@0.2.6"]), + ("0.2.5", ["install -g tasks-axi@0.2.6"]), + ("0.2.6", []), + ("2.0.0", []), + ): + with self.subTest(installed=have or "absent"): + calls.write_text("") + env = {"HOME": str(root), "PATH": "/usr/bin:/bin", + "TEST_HAVE": have, "TEST_CALLS": str(calls)} + result = subprocess.run( + [shutil.which("bash"), str(script)], cwd=ROOT, env=env, + text=True, capture_output=True, timeout=30, + ) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + self.assertEqual(calls.read_text().splitlines(), installs) + + if __name__ == "__main__": unittest.main()