feat(rebuild): update every installed component from one rebuild
This commit is contained in:
1 parent
cff3c8873e
commit
4e1b65b5d2
6 files changed
+280
-20
No files matched your search
+181
-11
@@ -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..."
|
||||
|
||||
Reference in new issue
Block a user