Compare commits
28
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd96dc6dc0 | ||
|
|
ad55229df8 | ||
|
|
022967e277 | ||
|
|
4a31495181 | ||
|
|
4e1b65b5d2 | ||
|
|
cff3c8873e | ||
|
|
2e2578ead8 | ||
|
|
208e6741f3 | ||
|
|
53206f0a7b | ||
|
|
055c2eed91 | ||
|
|
0aa25b27f0 | ||
|
|
5566b982c2 | ||
|
|
f905570156 | ||
|
|
8b3aa7ef3b | ||
|
|
5bf1e05091 | ||
|
|
9598499dcf | ||
|
|
9addc502fa | ||
|
|
d4e8c24b2f | ||
|
|
f21d20e1f7 | ||
|
|
a2c6ef7152 | ||
|
|
cdceb1eb09 | ||
|
|
5becfd69aa | ||
|
|
78f2928132 | ||
|
|
877ee5d163 | ||
|
|
ac7888c9a5 | ||
|
|
2787bcc9ac | ||
|
|
3c7d2662a4 | ||
|
|
b03d71dc81 |
No files matched your search
@@ -8,9 +8,9 @@ Deliberate decisions in this repo - do NOT silently revert them:
|
||||
- Pi is managed the same way: `home/.pi/agent/{settings,models}.json`, `themes/`, and custom extensions (`terminal-status-title`, `calm`). Do not symlink the whole `~/.pi/agent` tree - sessions, auth, npm cache, and herdr's `extensions/herdr-agent-state.ts` stay live.
|
||||
- herdr stores runtime state beside its config, so `~/.config/herdr` stays a real directory and only `config.toml` is symlinked; `home.activation.herdrConfigDir` migrates the old whole-directory symlink and clears leaked artifacts. Do not symlink the whole directory - rationale and artifact list are in `home.nix`.
|
||||
- Codex runs on the OpenCode Go subscription. The ChatGPT app owns and rewrites the live `~/.codex/config.toml`, so it is NOT symlinked; `home.activation.codexOpenCodeGo` merges the repo fragment `home/.codex/config.toml` into it on every rebuild, and the app's own sections (`[desktop]`, `[plugins]`, `[mcp_servers]`, ...) survive. Auth is command-backed via `~/.local/bin/opencode-go-token` (prints the key from the opencode store), so `~/.codex/auth.json` stays in ChatGPT mode and ChatGPT sign-in coexists with Go. Only Go models that speak the Responses API work (`deepseek-v4.1-flash`, `gpt-6-luna`, `gpt-5.6-luna`, `grok-4.7/4.6`); GLM/Kimi/MiMo/LongCat are chat-completions-only and need a proxy. Desktop Codex is now the `chatgpt` cask - do not use the deprecated `codex-app` cask.
|
||||
- firstmate lives at `~/Documents/firstmate` as a mutable git clone (not in the Nix store). `home.activation.firstmate` clones it if missing and seeds `config/backend=herdr` + `config/crew-harness=opencode` only when those files are absent. Crew routing is `home/.config/firstmate/crew-dispatch.json` (symlinked in): per the captain's order 2026-10-21, coding crewmates and scouts use `opencode` + `opencode-go/deepseek-v4.1-flash` through the OpenCode CLI. Design, architecture, and design-review tasks are the exception: the file's first rule sends them to Pi with `openai-codex/gpt-6.1-sol` at `xhigh`, and implementation tasks re-resolve their profile instead of keeping that model. The free `deepseek-v4.1-flash-free` order of 2026-10-20 resumes when that lane resets. The validation pipeline stays on Pi with `opencode-go/deepseek-v4.1-flash` steps and the `opencode-go/glm-5.3-flash` reviewer. Avoid the `muse-spark-*-contributor` models, which train on prompts, and the `exo-free`, `mimo-*-free`, and `nemotron-*-free` models, whose data may be used to improve the model. `cat-jam-free` retains for 30 days. Crews inherit the primary's OpenCode login through the spawn-owned symlink (the isolated worker data root links the primary `<XDG_DATA_HOME>/opencode/auth.json`; no `~/.pi/agent/auth.json` reliance). Launch with shell alias `fm` (`cd` + `pi` with the two firstmate primary extensions); the primary runs Pi on the OpenCode Go subscription, while crews run on the opencode harness unless a dispatch rule selects another harness. `oc2` remains the isolated OpenCode 2 fallback. Self-update via `/updatefirstmate`, not rebuild.
|
||||
- OpenCode 2 is the isolated OpenCode harness behind `oc2`, not the firstmate primary. It is the stable Homebrew `opencode` formula, installed with `link = false` so the OpenCode 1.x CLI keeps `/opt/homebrew/bin/opencode`, and launched only through `home/bin/oc2` so `OPENCODE_CONFIG` stays at `home/.config/opencode2/opencode.json` and cannot rewrite OpenCode 1.x's `~/.config/opencode`. Switching between builds needs `opencode service restart`, because the client refuses a background service left over from the other build with `Background service uses an incompatible health protocol`. The npm beta package `@opencode-ai/cli` that `home.activation.opencode2` used to install is removed by `rebuild.sh` at rebuild time, so the stable formula is the only OpenCode 2 install. firstmate harness detection matches `*opencode*`, so it still classifies as OpenCode.
|
||||
- Shell aliases: `cc` (Claude skip-permissions), `co` (Codex full-auto), `gb` (Grok --yolo), `fm` (firstmate via Pi), `oc2` (OpenCode 2, isolated). They are intentional high-agency shortcuts.
|
||||
- firstmate lives at `~/Documents/firstmate` as a mutable git clone (not in the Nix store). `home.activation.firstmate` clones it if missing and seeds `config/backend=herdr` + `config/crew-harness=opencode` only when those files are absent. Crew routing is `home/.config/firstmate/crew-dispatch.json` (symlinked in): per the captain's order 2026-10-21, coding crewmates and scouts use `opencode` + `opencode-go/deepseek-v4.1-flash` through the OpenCode CLI. Design, architecture, and design-review tasks are the exception: the file's first rule sends them to Pi with `openai-codex/gpt-6.1-sol` at `xhigh`, and implementation tasks re-resolve their profile instead of keeping that model. The free `deepseek-v4.1-flash-free` order of 2026-10-20 resumes when that lane resets. The validation pipeline stays on Pi with `opencode-go/deepseek-v4.1-flash` steps and the `opencode-go/glm-5.3-flash` reviewer. Avoid the `muse-spark-*-contributor` models, which train on prompts, and the `exo-free`, `mimo-*-free`, and `nemotron-*-free` models, whose data may be used to improve the model. `cat-jam-free` retains for 30 days. Crews inherit the primary's OpenCode login through the spawn-owned symlink (the isolated worker data root links the primary `<XDG_DATA_HOME>/opencode/auth.json`; no `~/.pi/agent/auth.json` reliance). Launch with shell alias `fm` (`cd` + the `oc2` wrapper, so the primary runs OpenCode 2 on the OpenCode Go subscription and loads firstmate's `.opencode/plugins` by working directory), while crews run on the opencode harness unless a dispatch rule selects another harness. `oc2` remains the isolated-config OpenCode launcher, and `fm-pi` stays only as the explicit Pi fallback now that the OpenCode 2 launcher is the confirmed default. Self-update via `/updatefirstmate`, not rebuild.
|
||||
- OpenCode is one install: the stable Homebrew `opencode` formula, linked so `/opt/homebrew/bin/opencode` is that build. It is both the firstmate crew harness and the `oc2` binary. `oc2` only isolates the config: `OPENCODE_CONFIG` stays at `home/.config/opencode2/opencode.json` and cannot rewrite `~/.config/opencode`, and `OPENCODE2_BIN` overrides the binary. firstmate harness detection matches `*opencode*`, so it still classifies as OpenCode.
|
||||
- Shell aliases: `cc` (Claude skip-permissions), `co` (Codex full-auto), `gb` (Grok --yolo), `fm` / `fm-oc2` (firstmate via OpenCode 2), `fm-pi` (firstmate via Pi fallback), `oc2` (OpenCode with isolated config). They are intentional high-agency shortcuts.
|
||||
- OpenSuperWhisper is installed by the `opensuperwhisper` cask, and `home.activation.openSuperWhisper` downloads its Whisper model (`ggml-large-v3-turbo.bin` under the app's Application Support directory, never the Nix store) and seeds the model selection only when it is missing or dangling. All other app settings (trigger, language, paste behavior) belong to the app and must not be rewritten by a rebuild, so `modifierOnlyHotkey = rightOption` on this machine stays the effective trigger. Microphone/Accessibility/Input Monitoring grants stay manual because macOS TCC cannot be declarative; do not kill a running app to apply defaults. The model is local-only.
|
||||
|
||||
## Maintaining this file
|
||||
|
||||
+5
-7
@@ -54,18 +54,16 @@
|
||||
# resolves on the normal PATH. No server, service, database, or
|
||||
# connection is configured.
|
||||
{ name = "libpq"; link = true; }
|
||||
"node" # required: opencode-ai, backpass, and acpx are npm globals,
|
||||
# not formulae
|
||||
# OpenCode 2 stable. Installed unlinked so it never replaces the
|
||||
# npm-installed OpenCode 1.x CLI at /opt/homebrew/bin/opencode (the crew
|
||||
# harness); home/bin/oc2 runs this keg binary directly. `link = false`
|
||||
# makes brew bundle unlink after install, which is deterministic.
|
||||
{ name = "opencode"; link = false; }
|
||||
"node" # required: backpass and acpx are npm globals, not formulae
|
||||
# Unpinned: onActivation.upgrade refreshes formulae each rebuild, so the
|
||||
# linked binary tracks the latest opencode release. Crew harness and oc2.
|
||||
"opencode"
|
||||
"pi-coding-agent"
|
||||
"tea" # Gitea CLI - PRs for firstmate crewmates on unraid.local:3003
|
||||
"tmux"
|
||||
"treehouse"
|
||||
"whisper-cpp" # whisper-cli for yt-transcribe (reuses OpenSuperWhisper's model)
|
||||
"wimlib" # wimlib-imagex: split install.wim to fit FAT32 for Windows USB media
|
||||
"yt-dlp" # yt-transcribe engine; same engine reclip runs in its container
|
||||
];
|
||||
casks = [
|
||||
|
||||
Generated
+6
-6
@@ -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": {
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -80,8 +88,14 @@ in
|
||||
cc = "claude --dangerously-skip-permissions";
|
||||
co = "codex --full-auto";
|
||||
gb = "grok --yolo";
|
||||
# firstmate primary session via Pi on the OpenCode Go subscription; crewmates = OpenCode by default
|
||||
fm = "cd ${firstmateHome} && exec pi";
|
||||
# firstmate primary session in OpenCode 2 on the OpenCode Go subscription,
|
||||
# launched through the isolated-config oc2 wrapper; crewmates = OpenCode by
|
||||
# default. Permanent since 2026-11-15: fm-pi stays only as the explicit Pi
|
||||
# fallback, never as the default launcher. fm-oc2 is the explicit
|
||||
# OpenCode 2 name and stays byte-identical to fm.
|
||||
fm = "cd ${firstmateHome} && exec ${home}/.local/bin/oc2";
|
||||
fm-oc2 = "cd ${firstmateHome} && exec ${home}/.local/bin/oc2";
|
||||
fm-pi = "cd ${firstmateHome} && exec pi";
|
||||
oc2 = "${home}/.local/bin/oc2";
|
||||
# Sync ~/Music into the beets library on Unraid (requires NAS mounted).
|
||||
sync-music = "~/.local/bin/sync-music";
|
||||
@@ -219,7 +233,7 @@ in
|
||||
source = config.lib.file.mkOutOfStoreSymlink "${dotfiles}/home/.config/opencode/skills";
|
||||
force = true;
|
||||
};
|
||||
# OpenCode 2 isolated config - never share ~/.config/opencode with 1.x
|
||||
# OpenCode isolated config - keep it separate from ~/.config/opencode
|
||||
home.file.".config/opencode2/opencode.json" = {
|
||||
source = config.lib.file.mkOutOfStoreSymlink "${dotfiles}/home/.config/opencode2/opencode.json";
|
||||
force = true;
|
||||
@@ -313,7 +327,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`
|
||||
@@ -325,10 +340,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
|
||||
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"
|
||||
fi
|
||||
# Companion CLIs without a firstmate-enforced version floor: install once.
|
||||
@@ -369,8 +387,9 @@ in
|
||||
"$HOME/.codex/config.toml"
|
||||
'';
|
||||
|
||||
# OpenCode 2 is the stable Homebrew `opencode` formula, declared unlinked in
|
||||
# configuration.nix; home/bin/oc2 runs its keg binary. Nothing to install here.
|
||||
# OpenCode is the stable Homebrew `opencode` formula, linked in
|
||||
# configuration.nix; home/bin/oc2 runs its keg binary with an isolated config.
|
||||
# Nothing to install here.
|
||||
|
||||
# backpass (kunchenguid/backpass) - gradient descent for agent memory: reads
|
||||
# the transcript stores of the harnesses this config already declares
|
||||
@@ -379,9 +398,15 @@ in
|
||||
# to a harness you already authenticated, so acpx is a hard runtime dep and
|
||||
# must be on PATH. Homebrew node v26 satisfies backpass (>= 22.5) and acpx
|
||||
# (>= 22.13). Neither is a Homebrew formula: install via Homebrew's npm,
|
||||
# never Nix's npm (EACCES on the store). Skip-if-present so a rebuild never
|
||||
# pulls a new version mid-session; refresh manually with
|
||||
# /opt/homebrew/bin/npm update -g backpass acpx
|
||||
# never Nix's npm (EACCES on the store). Both track the registry's latest on
|
||||
# every rebuild: for each package the installed version is compared with the
|
||||
# published one, and an install runs only when they differ, so a current copy
|
||||
# is left alone and a stale one converges. The switch therefore always brings
|
||||
# both packages to the latest published version, whether or not a process of
|
||||
# that package is running: a running process keeps the code it already loaded
|
||||
# and picks the new version up at its next start, so the switch prints that as
|
||||
# a notice and still installs. The registry lookup and the install are optional
|
||||
# steps - a failure there warns and the switch continues.
|
||||
home.activation.backpass = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
|
||||
set -euo pipefail
|
||||
# Activation PATH lacks /opt/homebrew/bin, so npm's `#!/usr/bin/env node`
|
||||
@@ -393,12 +418,45 @@ in
|
||||
echo "backpass: /opt/homebrew/bin/npm missing (declare node in homebrew.brews)" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -x /opt/homebrew/bin/acpx ]; then
|
||||
"$npm" install -g acpx@latest
|
||||
fi
|
||||
if [ ! -x /opt/homebrew/bin/backpass ]; then
|
||||
"$npm" install -g backpass
|
||||
fi
|
||||
# Converge one npm global to the registry's latest. $1 is the package name,
|
||||
# $2 is the pgrep pattern matching that package's command line as launched
|
||||
# from the global bin, used only to explain that a live process keeps its
|
||||
# loaded code. Every optional failure returns 0, so `set -e` never aborts the
|
||||
# switch and later blocks still run.
|
||||
converge_npm_global() {
|
||||
pkg="$1"
|
||||
live="$2"
|
||||
# Installed version from npm's own global record; empty means absent. The
|
||||
# `|| true` keeps `set -e` quiet when npm exits non-zero over extraneous
|
||||
# packages.
|
||||
installed="$("$npm" ls -g --depth=0 2>/dev/null | sed -n "s/.*[[:space:]]$pkg@\([^[:space:]]*\).*/\1/p" | head -n 1 || true)"
|
||||
# Registry lookup is optional: an offline or timed-out lookup warns and
|
||||
# keeps the installed copy.
|
||||
latest="$("$npm" view "$pkg" version --fetch-timeout=15000 --fetch-retries=1 2>/dev/null | tr -d "[:space:]" || true)"
|
||||
if [ -z "$latest" ]; then
|
||||
echo "$pkg: cannot read the latest version from the npm registry (offline?) - keeping the installed copy, rebuild continues" >&2
|
||||
return 0
|
||||
fi
|
||||
if [ "$installed" = "$latest" ]; then
|
||||
echo "$pkg: already at $latest"
|
||||
else
|
||||
current="$installed"
|
||||
[ -n "$current" ] || current=none
|
||||
echo "$pkg: updating $current -> $latest"
|
||||
# Install failure is optional too: warn and keep the old copy.
|
||||
if "$npm" install -g "$pkg@$latest"; then
|
||||
echo "$pkg: installed $latest"
|
||||
else
|
||||
echo "$pkg: install of $latest failed - keeping the installed copy, rebuild continues" >&2
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
if pgrep -f "$live" >/dev/null 2>&1; then
|
||||
echo "$pkg: a running process keeps the code it already loaded - $latest takes effect at its next start" >&2
|
||||
fi
|
||||
}
|
||||
converge_npm_global backpass "/opt/homebrew/bin/backpass"
|
||||
converge_npm_global acpx "/opt/homebrew/bin/acpx"
|
||||
'';
|
||||
|
||||
# kunchenguid/no-mistakes gate (git push no-mistakes) - declarative install + daemon + global config
|
||||
@@ -453,11 +511,12 @@ in
|
||||
# ~/.config/opencode/skills: home-manager owns that path with force = true and
|
||||
# mkOutOfStoreSymlink into the mutable dotfiles checkout, so a rebuild would
|
||||
# clobber the CLI's link and CLI writes would land in the git checkout. Skip
|
||||
# when installed, like backpass, so a rebuild never pulls a new skill
|
||||
# version mid-session. The skill's own README still requires an OS-enforced
|
||||
# sandbox before it may run target-controlled builds, tests, browsers, or
|
||||
# fuzzers. That sandbox is home/bin/security-audit-sandbox; without it, those
|
||||
# leads stay `needs_validation`.
|
||||
# when installed, unlike backpass which tracks the latest release, so a
|
||||
# rebuild never pulls a new skill version mid-session. The skill's own README
|
||||
# still requires an OS-enforced sandbox before it may run target-controlled
|
||||
# builds, tests, browsers, or fuzzers. That sandbox is
|
||||
# home/bin/security-audit-sandbox; without it, those leads stay
|
||||
# `needs_validation`.
|
||||
# Install and refresh commands, plus the sandbox docs, are in readme.md.
|
||||
home.activation.securityAuditSkill = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
|
||||
set -euo pipefail
|
||||
|
||||
@@ -20,6 +20,15 @@
|
||||
}
|
||||
],
|
||||
"why": "Captain's order 2026-10-21: paid Go for every crewmate and scout after the free lane hit 'Free usage exceeded' with a 10.5 hour retry, which ended five sessions in forty minutes. The free deepseek-v4.1-flash-free order of 2026-10-20 resumes when that lane resets; paid Go had 5 percent of its monthly window left, projected empty 2026-10-22T05:43Z."
|
||||
},
|
||||
{
|
||||
"when": "Documentation tasks: writing, updating, or reviewing documentation, docs, READMEs, or technical writing.",
|
||||
"use": {
|
||||
"harness": "opencode",
|
||||
"model": "opencode-go/beam-free",
|
||||
"provider": "opencode-go"
|
||||
},
|
||||
"why": "Captain's order 2026-11-15: documentation tasks use the free beam-free model to conserve paid quota."
|
||||
}
|
||||
],
|
||||
"default": [
|
||||
|
||||
@@ -80,7 +80,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"plugin": ["/Users/laptran/.automaton/plugins/automaton-guard"],
|
||||
"command": {
|
||||
"no-mistakes": {
|
||||
"description": "Validate code changes through the no-mistakes pipeline",
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# Launch OpenCode 2 with an isolated config so it cannot rewrite
|
||||
# ~/.config/opencode/opencode.json (OpenCode 1 / firstmate).
|
||||
# Launch OpenCode with an isolated config so it cannot rewrite
|
||||
# ~/.config/opencode/opencode.json (firstmate).
|
||||
set -euo pipefail
|
||||
|
||||
bin="${OPENCODE2_BIN:-/opt/homebrew/opt/opencode/bin/opencode}"
|
||||
@@ -8,7 +8,7 @@ cfg="${OPENCODE_CONFIG:-$HOME/.config/opencode2/opencode.json}"
|
||||
|
||||
if [ ! -x "$bin" ]; then
|
||||
echo "oc2: stable opencode not installed. Rebuild, or run:" >&2
|
||||
echo " brew install opencode && brew unlink opencode" >&2
|
||||
echo " brew install opencode" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -e "$cfg" ]; then
|
||||
|
||||
@@ -13,7 +13,91 @@ The firstmate crew dispatch + Gitea PR helper are wired by `darwin-rebuild`, but
|
||||
cd ~/Documents/investor-flow
|
||||
git remote set-url origin http://unraid.local:3003/transnet/investor-flow
|
||||
|
||||
Verify: `fm` launches Pi as the first mate (accept project trust once); `oc2 --version` prints an OpenCode 2 version; `pi --list-models mimo` shows `opencode-go/mimo-v2.5-pro`; `tea pulls list --repo transnet/investor-flow` works.
|
||||
Verify: `fm` and `fm-oc2` launch OpenCode 2 as the first mate and `fm-pi` is the explicit Pi fallback; `oc2 --version` prints the Homebrew opencode version; `pi --list-models mimo` shows `opencode-go/mimo-v2.5-pro`; `tea pulls list --repo transnet/investor-flow` works.
|
||||
|
||||
## firstmate launcher and crew model routing
|
||||
|
||||
`fm` is the permanent firstmate launcher. `fm-oc2` is the same launcher under its explicit OpenCode 2 name, so both aliases expand to the same command. They change to `~/Documents/firstmate` and execute `~/.local/bin/oc2`, which runs the Homebrew OpenCode build with the isolated `~/.config/opencode2/opencode.json` config. `fm-pi` starts Pi instead and remains only an explicit fallback. Never make Pi the default launcher.
|
||||
|
||||
The three aliases share one firstmate home. They read the same task records, inbox, and state. Each tool keeps its own chat history, so a conversation in OpenCode 2 does not appear in Pi, and the reverse. Quit the running primary before you start the other one. A single firstmate home serves one primary at a time.
|
||||
|
||||
`home.nix` owns all three aliases, so a rebuild regenerates them. The installed `~/.zshrc` changes only at the next activation.
|
||||
|
||||
Worker routing lives in `home/.config/firstmate/crew-dispatch.json`, which is symlinked to `~/Documents/firstmate/config/crew-dispatch.json`:
|
||||
|
||||
| Task | Harness | Model |
|
||||
| --- | --- | --- |
|
||||
| Default crewmates and scouts | opencode | opencode-go/deepseek-v4.1-flash |
|
||||
| Documentation writing, updating, or review | opencode | opencode-go/beam-free |
|
||||
| UI work with image context | opencode | opencode-go/deepseek-v4.1-flash |
|
||||
| Design, architecture, and design review (preserved exception) | pi | openai-codex/gpt-6.1-sol at xhigh |
|
||||
|
||||
Firstmate matches the `when` text with judgment. It then passes concrete `--harness` and `--model` flags to `fm-spawn.sh`. The file has no Pi default.
|
||||
|
||||
`~/Documents/firstmate/config/crew-harness` stays `opencode`. `home.activation.firstmate` seeds it only when the file is absent, so a captain edit survives a rebuild.
|
||||
|
||||
The model IDs above were listed from a neutral directory with `OPENCODE_CONFIG=~/.config/opencode2/opencode.json opencode models`. Both `opencode-go/deepseek-v4.1-flash` and `opencode-go/beam-free` are exact IDs.
|
||||
|
||||
### no-mistakes pipeline models
|
||||
|
||||
The captain confirmed the split on 2026-11-15. Leave it unchanged:
|
||||
|
||||
- execution tool: Pi (`agent: [pi]`)
|
||||
- general steps and fixers: `opencode-go/deepseek-v4.1-flash`
|
||||
- reviewer: `opencode-go/glm-5.3-flash`
|
||||
|
||||
`home.activation.noMistakes` adds `agent_config` and `review_agents` only when those keys are absent. The live `~/.no-mistakes/config.yaml` also sets `agent_path_override.opencode`, which stays inactive while the execution tool is Pi. This repository has no `.no-mistakes.yaml`, so no repo-level override applies. Firstmate's own `.no-mistakes.yaml` applies only to the firstmate repository. Do not edit the live no-mistakes config by hand.
|
||||
|
||||
### Checks
|
||||
|
||||
```bash
|
||||
./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 # isolated updater execution and activation checks
|
||||
./tests/run.sh # all checks
|
||||
```
|
||||
|
||||
The launcher check sources the real generated zshrc in an interactive zsh. A `pi` spy on PATH and an `OPENCODE2_BIN` spy capture the launch of `fm`, `fm-oc2`, and `fm-pi`, record the working directory, and exit at once, so no firstmate session starts.
|
||||
|
||||
### Install after merge
|
||||
|
||||
The Nix sources in this repository are the durable record. The live files are generated, so do not edit them.
|
||||
|
||||
1. Merge the reviewed branch into the default branch.
|
||||
2. Confirm `readlink ~/.dotfiles` names the checkout that holds the merged commit.
|
||||
3. Run `./rebuild.sh` from that checkout.
|
||||
4. Run `./tests/fm-launcher.sh --live` and `./tests/crew-dispatch.sh`.
|
||||
5. Open a fresh shell and run `alias fm fm-oc2 fm-pi`. `fm` and `fm-oc2` must show `exec /Users/laptran/.local/bin/oc2`, and `fm-pi` must show `exec pi`.
|
||||
|
||||
### Checkout topology and safe installation
|
||||
|
||||
`rebuild.sh` points `~/.dotfiles` at its own directory and then builds `~/.dotfiles#lt-mbp`. On 2026-11-15, `~/.dotfiles` resolved to `/Users/laptran/Documents/firstmate/projects/dotfiles`. A second checkout at `/Users/laptran/Documents/dotfiles` carried an uncommitted `home.nix` that changed `fm` back to `pi` and seeded `crew-harness` as `pi`. A rebuild from that checkout would restore the Pi default. Do not run `rebuild.sh` from a checkout with that edit, and do not repoint `~/.dotfiles` by hand.
|
||||
|
||||
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
|
||||
|
||||
`./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 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 `~/.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.
|
||||
|
||||
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 selected nixpkgs packages. Later rebuilds update those links automatically, rather than downloading separate releases.
|
||||
|
||||
After the switch:
|
||||
|
||||
- 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.
|
||||
|
||||
## security-audit skill (agent security reviews)
|
||||
|
||||
|
||||
+153
-44
@@ -1,53 +1,112 @@
|
||||
#!/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, installs OpenCode 1.x
|
||||
# (stable CLI for free-tier), removes the retired OpenCode 2 npm beta, updates
|
||||
# no-mistakes, and updates pi extensions.
|
||||
# Rebuild nix-darwin + home-manager from this checkout.
|
||||
#
|
||||
# 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
|
||||
# binaries.
|
||||
#
|
||||
# Rotates stale home-manager *.backup files before the switch so a second switch
|
||||
# never fails with "would be clobbered".
|
||||
# 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
|
||||
|
||||
# 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"
|
||||
else
|
||||
echo "==> WARNING: grok-build upgrade failed (network issue). Skipping."
|
||||
fi
|
||||
|
||||
# Install OpenCode 1.x (stable CLI, binary "opencode") if absent.
|
||||
# Required for free-tier models; OpenCode 2 is the separate stable `oc2` build.
|
||||
# Uses Homebrew's npm (not Nix's npm) to avoid EACCES on the store.
|
||||
# Skip if npm is unavailable (e.g., network issues preventing fetch).
|
||||
OPENCODE_BIN=/opt/homebrew/bin/opencode
|
||||
if [ ! -x "$OPENCODE_BIN" ]; then
|
||||
echo "==> Installing OpenCode 1.x (stable) via Homebrew npm..."
|
||||
if /opt/homebrew/bin/npm install -g --allow-scripts=opencode-ai opencode-ai@1.18 2>&1; then
|
||||
echo "==> OpenCode 1.x installed successfully"
|
||||
else
|
||||
echo "==> WARNING: OpenCode 1.x installation failed (network issue). Skipping."
|
||||
fi
|
||||
else
|
||||
echo "==> OpenCode 1.x already installed: $(${OPENCODE_BIN} --version)"
|
||||
fi
|
||||
|
||||
# Remove the retired OpenCode 2 beta (@opencode-ai/cli, binary "opencode2") if
|
||||
# an older rebuild installed it. The stable Homebrew `opencode` formula declared
|
||||
# in configuration.nix is now the only OpenCode 2 install. Local check only, so
|
||||
# an offline rebuild skips this instead of failing.
|
||||
NPM=/opt/homebrew/bin/npm
|
||||
if [ -x "$NPM" ] && beta_root="$("$NPM" root -g 2>/dev/null)" && [ -d "$beta_root/@opencode-ai/cli" ]; then
|
||||
echo "==> Removing retired OpenCode 2 beta (@opencode-ai/cli)..."
|
||||
if "$NPM" uninstall -g @opencode-ai/cli 2>&1; then
|
||||
echo "==> OpenCode 2 beta removed"
|
||||
else
|
||||
echo "==> WARNING: OpenCode 2 beta removal failed. Remove it manually:"
|
||||
echo " $NPM uninstall -g @opencode-ai/cli"
|
||||
fi
|
||||
|
||||
# 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.
|
||||
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)"
|
||||
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
|
||||
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
|
||||
echo "==> $pkg $installed -> $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
|
||||
}
|
||||
# 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
|
||||
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:
|
||||
# the `@opencode-ai/cli` beta and the older `opencode-ai` CLI. The Homebrew
|
||||
# `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.
|
||||
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
|
||||
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
|
||||
# `opencode` links without --overwrite, so any npm shim left in the Homebrew
|
||||
# prefix aborts the switch's brew bundle link step. Drop the retired packages'
|
||||
# shims directly, which also covers a failed uninstall and a missing npm.
|
||||
for link in /opt/homebrew/bin/*; do
|
||||
case "$(readlink "$link" 2>/dev/null || true)" in
|
||||
*/node_modules/@opencode-ai/cli/* | */node_modules/opencode-ai/*)
|
||||
rm -f "$link"
|
||||
echo "==> Removed stale OpenCode npm shim $link"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
echo "==> Updating no-mistakes..."
|
||||
NO_MISTAKES_BIN="$HOME/.no-mistakes/bin/no-mistakes"
|
||||
if [ -x "$NO_MISTAKES_BIN" ]; then
|
||||
@@ -66,8 +125,21 @@ 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.
|
||||
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).
|
||||
# Paths managed by home.file, including config links and Nix package binaries.
|
||||
managed=(
|
||||
"$HOME/.grok/config.toml"
|
||||
"$HOME/.grok/AGENTS.md"
|
||||
@@ -80,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"
|
||||
@@ -119,6 +193,41 @@ fi
|
||||
|
||||
sudo darwin-rebuild switch --flake ~/.dotfiles#lt-mbp
|
||||
|
||||
# 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"
|
||||
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..."
|
||||
|
||||
Executable
+120
@@ -0,0 +1,120 @@
|
||||
#!/usr/bin/env bash
|
||||
# Behavior check: the dotfiles crew dispatch sends ordinary workers to
|
||||
# DeepSeek v4.1 Flash on OpenCode, documentation tasks to Beam Free, and keeps
|
||||
# the design exception. It reads the config through firstmate's own bootstrap
|
||||
# validator and verbose facts, which is the supported surface that reports the
|
||||
# effective dispatch profile.
|
||||
#
|
||||
# Firstmate matches the natural-language `when` text with its own judgment, so
|
||||
# this check pins the declared routing and the schema, not a model call. It then
|
||||
# confirms every OpenCode-harness model ID against OpenCode's own catalog, so a
|
||||
# mistyped ID fails here instead of when a crew spawns.
|
||||
# It skips the parts that need firstmate or OpenCode when they are not installed.
|
||||
set -euo pipefail
|
||||
|
||||
ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)
|
||||
CONFIG="$ROOT/home/.config/firstmate/crew-dispatch.json"
|
||||
FM_ROOT=${FM_ROOT:-"$HOME/Documents/firstmate"}
|
||||
BOOTSTRAP="$FM_ROOT/bin/fm-bootstrap.sh"
|
||||
|
||||
[ -f "$CONFIG" ] || { echo "FAIL: missing $CONFIG" >&2; exit 1; }
|
||||
if [ ! -x "$BOOTSTRAP" ]; then
|
||||
echo "SKIP: firstmate bootstrap not found at $BOOTSTRAP"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
TMP=$(mktemp -d "${TMPDIR:-/tmp}/crew-dispatch.XXXXXX")
|
||||
cleanup() { rm -rf "$TMP"; }
|
||||
trap cleanup EXIT
|
||||
|
||||
mkdir -p "$TMP/home/config"
|
||||
cp "$CONFIG" "$TMP/home/config/crew-dispatch.json"
|
||||
printf 'manual\n' > "$TMP/home/config/backlog-backend"
|
||||
|
||||
out=$(FM_HOME="$TMP/home" FM_ROOT_OVERRIDE="$TMP/home" FM_BOOTSTRAP_VERBOSE_FACTS=1 \
|
||||
"$BOOTSTRAP" 2>"$TMP/stderr")
|
||||
|
||||
fail() {
|
||||
echo "FAIL: $1"
|
||||
printf '%s\n' "$out" | sed 's/^/ /'
|
||||
sed 's/^/ /' "$TMP/stderr"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if printf '%s\n' "$out" | grep -q '^CREW_DISPATCH: invalid'; then
|
||||
fail "firstmate rejected the crew dispatch config"
|
||||
fi
|
||||
|
||||
default=$(printf '%s\n' "$out" | grep '^BOOTSTRAP_INFO: crew dispatch default: ' || true)
|
||||
[ -n "$default" ] || fail "firstmate reported no default dispatch profile"
|
||||
|
||||
case "$default" in
|
||||
*opencode/opencode-go/deepseek-v4.1-flash*) ;;
|
||||
*) fail "default workers are not OpenCode + DeepSeek v4.1 Flash" ;;
|
||||
esac
|
||||
case "$default" in
|
||||
*pi/*|*codex/*) fail "default workers still resolve to a Pi/Codex profile" ;;
|
||||
esac
|
||||
|
||||
docs=$(printf '%s\n' "$out" | grep '^BOOTSTRAP_INFO: crew dispatch rule: Documentation tasks' || true)
|
||||
[ -n "$docs" ] || fail "no documentation dispatch rule"
|
||||
case "$docs" in
|
||||
*'-> opencode/opencode-go/beam-free') ;;
|
||||
*) fail "documentation tasks do not resolve to opencode/opencode-go/beam-free" ;;
|
||||
esac
|
||||
|
||||
design=$(printf '%s\n' "$out" | grep '^BOOTSTRAP_INFO: crew dispatch rule: Design, architecture' || true)
|
||||
[ -n "$design" ] || fail "the preserved design rule is missing"
|
||||
case "$design" in
|
||||
*'-> pi/openai-codex/gpt-6.1-sol/xhigh') ;;
|
||||
*) fail "the design exception no longer resolves to Pi + GPT-6.1 Sol" ;;
|
||||
esac
|
||||
|
||||
ui=$(printf '%s\n' "$out" | grep '^BOOTSTRAP_INFO: crew dispatch rule: UI work' || true)
|
||||
[ -n "$ui" ] || fail "the UI image-context rule is missing"
|
||||
case "$ui" in
|
||||
*opencode-go/deepseek-v4.1-flash*) ;;
|
||||
*) fail "the UI rule no longer resolves to DeepSeek v4.1 Flash" ;;
|
||||
esac
|
||||
|
||||
# The model IDs above come from the same file the routing check reads, so a
|
||||
# typo would still pass them. OpenCode's own catalog is the independent oracle:
|
||||
# a model it does not list fails only when a crew spawns. Confirm each
|
||||
# OpenCode-harness model against that catalog.
|
||||
OPENCODE_JSON=${OPENCODE_CONFIG:-$HOME/.config/opencode2/opencode.json}
|
||||
if ! command -v opencode >/dev/null 2>&1 || ! command -v python3 >/dev/null 2>&1; then
|
||||
echo "SKIP: opencode or python3 not on PATH, cannot confirm the model IDs"
|
||||
elif [ ! -e "$OPENCODE_JSON" ]; then
|
||||
echo "SKIP: no isolated OpenCode config at $OPENCODE_JSON, cannot confirm the model IDs"
|
||||
else
|
||||
catalog=$(OPENCODE_CONFIG="$OPENCODE_JSON" timeout 120 opencode models 2>/dev/null || true)
|
||||
if [ -z "$catalog" ]; then
|
||||
echo "SKIP: opencode models printed nothing, cannot confirm the model IDs"
|
||||
else
|
||||
models=$(python3 - "$CONFIG" <<'PY'
|
||||
import json, sys
|
||||
|
||||
config = json.load(open(sys.argv[1]))
|
||||
uses = list(config.get("default") or [])
|
||||
for rule in config.get("rules") or []:
|
||||
use = rule.get("use")
|
||||
uses.extend(use if isinstance(use, list) else [use])
|
||||
for use in uses:
|
||||
if isinstance(use, dict) and use.get("harness") == "opencode" and use.get("model"):
|
||||
print(use["model"])
|
||||
PY
|
||||
)
|
||||
# Deduplicate so a model named by two profiles is confirmed once.
|
||||
models=$(printf '%s\n' "$models" | awk 'NF && !seen[$0]++')
|
||||
while IFS= read -r model; do
|
||||
[ -n "$model" ] || continue
|
||||
printf '%s\n' "$catalog" | grep -qxF "$model" \
|
||||
|| fail "$model is not in the OpenCode catalog (opencode models)"
|
||||
echo "PASS: $model exists in the OpenCode catalog"
|
||||
done <<< "$models"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "PASS: default workers -> opencode/opencode-go/deepseek-v4.1-flash"
|
||||
echo "PASS: documentation -> opencode/opencode-go/beam-free"
|
||||
echo "PASS: design exception preserved -> pi/openai-codex/gpt-6.1-sol/xhigh"
|
||||
Executable
+171
@@ -0,0 +1,171 @@
|
||||
#!/usr/bin/env bash
|
||||
# Behavior check: a fresh interactive zsh runs the firstmate launchers and each
|
||||
# one starts the tool its name promises, from the firstmate home directory.
|
||||
#
|
||||
# fm -> OpenCode 2 through ~/.local/bin/oc2
|
||||
# fm-oc2 -> OpenCode 2 through ~/.local/bin/oc2, identical to fm
|
||||
# fm-pi -> Pi
|
||||
#
|
||||
# The check reads the zshrc that the real home-manager configuration generates
|
||||
# (the same file a rebuild installs), sources it in an interactive zsh, and runs
|
||||
# each launcher with three harmless spies:
|
||||
# - a `pi` spy first on PATH, which catches a Pi launch;
|
||||
# - a spy named by OPENCODE2_BIN, which the real ~/.local/bin/oc2 wrapper
|
||||
# execs instead of the OpenCode binary;
|
||||
# - the spies record their working directory, so a launcher that forgets the
|
||||
# `cd` into the firstmate home fails here.
|
||||
# Nothing here launches a real firstmate primary, Pi, or OpenCode, and the spies
|
||||
# exit at once, so no session lock is taken and the primary stays alive.
|
||||
#
|
||||
# Usage:
|
||||
# tests/fm-launcher.sh # check the configuration source (default)
|
||||
# tests/fm-launcher.sh --live # check the installed ~/.zshrc
|
||||
# tests/fm-launcher.sh --zshrc F # check a specific generated zshrc
|
||||
set -euo pipefail
|
||||
|
||||
ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)
|
||||
MODE=source
|
||||
ZSHRC=''
|
||||
LAUNCHERS='fm:oc2 fm-oc2:oc2 fm-pi:pi'
|
||||
FM_HOME=${FM_HOME:-"$HOME/Documents/firstmate"}
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--live) MODE=live; shift ;;
|
||||
--zshrc)
|
||||
[ $# -ge 2 ] || { echo "fm-launcher: --zshrc needs a path" >&2; exit 2; }
|
||||
MODE="file"; ZSHRC=$2; shift 2 ;;
|
||||
-h|--help)
|
||||
awk 'NR == 1 { next } /^#/ { sub(/^# ?/, ""); print; next } { exit }' "$0"
|
||||
exit 0 ;;
|
||||
*) echo "fm-launcher: unknown argument $1" >&2; exit 2 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
TMP=$(mktemp -d "${TMPDIR:-/tmp}/fm-launcher.XXXXXX")
|
||||
cleanup() { rm -rf "$TMP"; }
|
||||
trap cleanup EXIT
|
||||
|
||||
mkdir -p "$TMP/bin"
|
||||
cat > "$TMP/bin/pi" <<'SH'
|
||||
#!/usr/bin/env bash
|
||||
printf 'pi|%s' "$PWD" >> "$FM_TEST_SPY_LOG"
|
||||
for arg in "$@"; do printf '|%s' "$arg" >> "$FM_TEST_SPY_LOG"; done
|
||||
printf '\n' >> "$FM_TEST_SPY_LOG"
|
||||
exit 0
|
||||
SH
|
||||
cat > "$TMP/bin/opencode2-spy" <<'SH'
|
||||
#!/usr/bin/env bash
|
||||
printf 'oc2|%s' "$PWD" >> "$FM_TEST_SPY_LOG"
|
||||
for arg in "$@"; do printf '|%s' "$arg" >> "$FM_TEST_SPY_LOG"; done
|
||||
printf '\n' >> "$FM_TEST_SPY_LOG"
|
||||
exit 0
|
||||
SH
|
||||
chmod +x "$TMP/bin/pi" "$TMP/bin/opencode2-spy"
|
||||
printf '{}\n' > "$TMP/opencode.json"
|
||||
|
||||
case "$MODE" in
|
||||
live)
|
||||
ZSHRC="$HOME/.zshrc"
|
||||
LABEL="installed ~/.zshrc"
|
||||
;;
|
||||
file)
|
||||
LABEL="$ZSHRC"
|
||||
;;
|
||||
source)
|
||||
command -v nix >/dev/null 2>&1 \
|
||||
|| { echo "fm-launcher: nix is required to build the configured zshrc" >&2; exit 2; }
|
||||
ZSHRC="$TMP/zshrc"
|
||||
nix eval --raw --impure --expr \
|
||||
"(builtins.getFlake (toString $ROOT)).darwinConfigurations.\"lt-mbp\".config.home-manager.users.laptran.home.file.\"./.zshrc\".text" \
|
||||
> "$ZSHRC"
|
||||
LABEL="home-manager zshrc generated from $ROOT"
|
||||
;;
|
||||
esac
|
||||
|
||||
[ -r "$ZSHRC" ] || { echo "fm-launcher: cannot read $ZSHRC" >&2; exit 2; }
|
||||
|
||||
# Run one launcher in a fresh interactive zsh and print what the spies saw.
|
||||
launch() {
|
||||
local launcher=$1
|
||||
: > "$TMP/spy.log"
|
||||
: > "$TMP/stderr"
|
||||
|
||||
set +e
|
||||
# shellcheck disable=SC2016 # the snippet expands inside the interactive zsh
|
||||
FM_TEST_ZSHRC="$ZSHRC" \
|
||||
FM_TEST_LAUNCHER="$launcher" \
|
||||
FM_TEST_SPY_LOG="$TMP/spy.log" \
|
||||
OPENCODE2_BIN="$TMP/bin/opencode2-spy" \
|
||||
OPENCODE_CONFIG="$TMP/opencode.json" \
|
||||
PATH="$TMP/bin:$PATH" \
|
||||
timeout 60 zsh -f -i -c '
|
||||
source "$FM_TEST_ZSHRC" || exit 4
|
||||
if ! alias "$FM_TEST_LAUNCHER" >/dev/null 2>&1; then
|
||||
echo "fm-launcher: no $FM_TEST_LAUNCHER alias in the sourced zshrc" >&2
|
||||
exit 3
|
||||
fi
|
||||
eval "$FM_TEST_LAUNCHER"
|
||||
' >/dev/null 2>"$TMP/stderr"
|
||||
LAUNCH_STATUS=$?
|
||||
set -e
|
||||
}
|
||||
|
||||
for pair in $LAUNCHERS; do
|
||||
launcher=${pair%%:*}
|
||||
expected=${pair##*:}
|
||||
|
||||
launch "$launcher"
|
||||
status=$LAUNCH_STATUS
|
||||
|
||||
if [ "$status" -eq 3 ]; then
|
||||
echo "FAIL: $LABEL does not define a $launcher alias"
|
||||
exit 1
|
||||
fi
|
||||
if [ "$status" -ne 0 ]; then
|
||||
echo "FAIL: $launcher from $LABEL exited $status"
|
||||
sed 's/^/ /' "$TMP/stderr"
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -s "$TMP/spy.log" ]; then
|
||||
echo "FAIL: $launcher from $LABEL launched nothing the spies could see"
|
||||
sed 's/^/ /' "$TMP/stderr"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
record=$(head -n 1 "$TMP/spy.log")
|
||||
tool=${record%%|*}
|
||||
dir=$(printf '%s' "${record#*|}" | cut -d'|' -f1)
|
||||
|
||||
if [ "$tool" != "$expected" ]; then
|
||||
echo "FAIL: $launcher from $LABEL launched $tool instead of $expected"
|
||||
echo " recorded launch: $record"
|
||||
exit 1
|
||||
fi
|
||||
if [ "$dir" != "$FM_HOME" ]; then
|
||||
echo "FAIL: $launcher from $LABEL ran in $dir instead of the firstmate home $FM_HOME"
|
||||
echo " recorded launch: $record"
|
||||
exit 1
|
||||
fi
|
||||
if [ "$expected" = oc2 ] && grep -q '^pi' "$TMP/spy.log"; then
|
||||
echo "FAIL: $launcher from $LABEL also launched Pi"
|
||||
sed 's/^/ /' "$TMP/spy.log"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case "$launcher" in
|
||||
fm) fm_record=$record ;;
|
||||
fm-oc2) fm_oc2_record=$record ;;
|
||||
esac
|
||||
|
||||
echo "PASS: $launcher from $LABEL launched $expected in $dir ($record)"
|
||||
done
|
||||
|
||||
if [ "$fm_record" != "$fm_oc2_record" ]; then
|
||||
echo "FAIL: fm and fm-oc2 are not identical launchers"
|
||||
echo " fm: $fm_record"
|
||||
echo " fm-oc2: $fm_oc2_record"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "PASS: fm and fm-oc2 are identical launchers"
|
||||
@@ -0,0 +1,389 @@
|
||||
"""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_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"])
|
||||
|
||||
|
||||
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()
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)
|
||||
exec python3 "$ROOT/tests/rebuild-update-steps.py"
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
# Run the dotfiles configuration checks that need the live machine.
|
||||
#
|
||||
# The launcher check builds the zshrc from the home-manager configuration and
|
||||
# runs `fm`, `fm-oc2`, and `fm-pi` with spies. The dispatch check reads the crew
|
||||
# dispatch config through firstmate's bootstrap validator. Neither starts a real
|
||||
# agent session.
|
||||
set -euo pipefail
|
||||
|
||||
ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)
|
||||
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"
|
||||
Reference in new issue
Block a user