From 6e1ee6ef676bbfd17e0e6fd531db0f5ba2be7092 Mon Sep 17 00:00:00 2001 From: Lap Tran Date: Mon, 5 Oct 2026 21:25:29 -0400 Subject: [PATCH 1/8] fix(home): stop herdr writing runtime state into the repo herdr resolves its config directory as ~/.config/herdr and writes all of its runtime state beside config.toml: herdr.sock, herdr-client.sock, herdr-server.log, .plugins.lock, session.json and session-snapshots/. It offers no option to relocate that directory, so linking the whole directory into this repo made ~/.config/herdr resolve into the tracked tree and left every clone permanently dirty with herdr's live sockets and snapshots. Link only config.toml and let ~/.config/herdr be a real directory, so herdr's state lands in $HOME instead of the working tree. home-manager links a file by resolving the existing directory symlink, which would move this repo's own tracked config.toml to config.toml.backup and leave a symlink inside the tree. Add a one-time activation step that drops the stale symlink before home-manager checks link targets; it is a no-op once ~/.config/herdr is a real directory. --- home.nix | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/home.nix b/home.nix index 1497fc6..68cb91b 100644 --- a/home.nix +++ b/home.nix @@ -81,11 +81,31 @@ in source = config.lib.file.mkOutOfStoreSymlink "${dotfiles}/home/.config/nvim"; force = true; }; - home.file.".config/herdr" = { - source = config.lib.file.mkOutOfStoreSymlink "${dotfiles}/home/.config/herdr"; + # herdr treats ~/.config/herdr as both its config directory and its state + # directory: it writes herdr.sock, herdr-client.sock, herdr-server.log, + # .plugins.lock, session.json and session-snapshots/ beside config.toml, and it + # offers no option to relocate them. Keep that directory a real directory and + # link only the config file - a whole-directory symlink into this repo makes + # every running herdr server dirty the working tree. + home.file.".config/herdr/config.toml" = { + source = config.lib.file.mkOutOfStoreSymlink "${dotfiles}/home/.config/herdr/config.toml"; force = true; }; + # Migration from the previous whole-directory symlink at ~/.config/herdr. + # home-manager links ~/.config/herdr/config.toml by following the existing + # ~/.config/herdr symlink, which would move this repo's own tracked config.toml + # to config.toml.backup and leave a symlink inside the tree. Drop the stale + # symlink before home-manager checks link targets; linkGeneration then creates + # the real directory. A real directory (the post-migration state) is left + # untouched, so this is idempotent. + home.activation.herdrConfigDir = lib.hm.dag.entryBefore [ "checkLinkTargets" ] '' + set -euo pipefail + if [ -L "$HOME/.config/herdr" ]; then + rm "$HOME/.config/herdr" + fi + ''; + # Beets music library manager - managed by nixpkgs package, config symlinked below. home.file.".config/beets" = { source = config.lib.file.mkOutOfStoreSymlink "${dotfiles}/home/.config/beets"; -- 2.54.0 From d5eb744fb402ca43d1fbca76fc2457c39f970466 Mon Sep 17 00:00:00 2001 From: Lap Tran Date: Mon, 5 Oct 2026 22:00:15 -0400 Subject: [PATCH 2/8] no-mistakes(review): Purge leaked herdr runtime files from dotfiles repo on activation --- home.nix | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/home.nix b/home.nix index 68cb91b..1ab8ed9 100644 --- a/home.nix +++ b/home.nix @@ -98,12 +98,21 @@ in # to config.toml.backup and leave a symlink inside the tree. Drop the stale # symlink before home-manager checks link targets; linkGeneration then creates # the real directory. A real directory (the post-migration state) is left - # untouched, so this is idempotent. + # untouched, so this is idempotent. The old whole-directory symlink also left + # herdr runtime state (sockets, logs, session.json, session-snapshots/, ...) in + # this repo; that state now resolves to the real directory, so clear every + # leftover except the tracked config.toml. Unlinking a live socket or log only + # drops the path - the running herdr server keeps its own file handles. home.activation.herdrConfigDir = lib.hm.dag.entryBefore [ "checkLinkTargets" ] '' set -euo pipefail if [ -L "$HOME/.config/herdr" ]; then rm "$HOME/.config/herdr" fi + repoHerdr="${dotfiles}/home/.config/herdr" + if [ -d "$repoHerdr" ]; then + ${pkgs.findutils}/bin/find "$repoHerdr" -mindepth 1 -maxdepth 1 \ + ! -name config.toml -exec ${pkgs.coreutils}/bin/rm -rf {} + + fi ''; # Beets music library manager - managed by nixpkgs package, config symlinked below. -- 2.54.0 From bafec48ceb9e4ed04a428271cb42441966d2dede Mon Sep 17 00:00:00 2001 From: Lap Tran Date: Mon, 5 Oct 2026 22:14:44 -0400 Subject: [PATCH 3/8] no-mistakes(review): home: narrow herdr cleanup and respect DRY_RUN via run --- home.nix | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/home.nix b/home.nix index 1ab8ed9..cd8b3d1 100644 --- a/home.nix +++ b/home.nix @@ -100,18 +100,26 @@ in # the real directory. A real directory (the post-migration state) is left # untouched, so this is idempotent. The old whole-directory symlink also left # herdr runtime state (sockets, logs, session.json, session-snapshots/, ...) in - # this repo; that state now resolves to the real directory, so clear every - # leftover except the tracked config.toml. Unlinking a live socket or log only - # drops the path - the running herdr server keeps its own file handles. + # this repo; that state now resolves to the real directory, so remove the known + # runtime artifacts by name. config.toml and any other repo content in that + # directory are never touched. Removing a live socket or log only drops the + # path - the running herdr server keeps its own file handles. home.activation.herdrConfigDir = lib.hm.dag.entryBefore [ "checkLinkTargets" ] '' set -euo pipefail if [ -L "$HOME/.config/herdr" ]; then - rm "$HOME/.config/herdr" + run ${pkgs.coreutils}/bin/rm "$HOME/.config/herdr" fi repoHerdr="${dotfiles}/home/.config/herdr" if [ -d "$repoHerdr" ]; then - ${pkgs.findutils}/bin/find "$repoHerdr" -mindepth 1 -maxdepth 1 \ - ! -name config.toml -exec ${pkgs.coreutils}/bin/rm -rf {} + + run ${pkgs.coreutils}/bin/rm -rf \ + "$repoHerdr/herdr.sock" \ + "$repoHerdr/herdr-client.sock" \ + "$repoHerdr/herdr.sock.agent" \ + "$repoHerdr/herdr-server.log" \ + "$repoHerdr/.plugins.lock" \ + "$repoHerdr/session.json" \ + "$repoHerdr/release-notes.json" \ + "$repoHerdr/session-snapshots" fi ''; -- 2.54.0 From d5fc8758a5c7891f50ad596db132f33d150acd89 Mon Sep 17 00:00:00 2001 From: Lap Tran Date: Mon, 5 Oct 2026 22:24:32 -0400 Subject: [PATCH 4/8] no-mistakes(review): home: move herdr migration after writeBoundary before linkGeneration --- home.nix | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/home.nix b/home.nix index cd8b3d1..a5ed090 100644 --- a/home.nix +++ b/home.nix @@ -96,15 +96,17 @@ in # home-manager links ~/.config/herdr/config.toml by following the existing # ~/.config/herdr symlink, which would move this repo's own tracked config.toml # to config.toml.backup and leave a symlink inside the tree. Drop the stale - # symlink before home-manager checks link targets; linkGeneration then creates - # the real directory. A real directory (the post-migration state) is left - # untouched, so this is idempotent. The old whole-directory symlink also left - # herdr runtime state (sockets, logs, session.json, session-snapshots/, ...) in - # this repo; that state now resolves to the real directory, so remove the known - # runtime artifacts by name. config.toml and any other repo content in that - # directory are never touched. Removing a live socket or log only drops the - # path - the running herdr server keeps its own file handles. - home.activation.herdrConfigDir = lib.hm.dag.entryBefore [ "checkLinkTargets" ] '' + # symlink in the write phase, after writeBoundary and before linkGeneration: + # checkLinkTargets already skips this target because the file is force = true, + # and linkGeneration then creates the real directory. A real directory (the + # post-migration state) is left untouched, so this is idempotent. The old + # whole-directory symlink also left herdr runtime state (sockets, logs, + # session.json, session-snapshots/, ...) in this repo; that state now resolves + # to the real directory, so remove the known runtime artifacts by name. + # config.toml and any other repo content in that directory are never touched. + # Removing a live socket or log only drops the path - the running herdr server + # keeps its own file handles. + home.activation.herdrConfigDir = lib.hm.dag.entryBetween [ "linkGeneration" ] [ "writeBoundary" ] '' set -euo pipefail if [ -L "$HOME/.config/herdr" ]; then run ${pkgs.coreutils}/bin/rm "$HOME/.config/herdr" -- 2.54.0 From b6095c8a2042d05abc6f1969fa2bca702026cda1 Mon Sep 17 00:00:00 2001 From: Lap Tran Date: Mon, 5 Oct 2026 22:32:40 -0400 Subject: [PATCH 5/8] no-mistakes(review): home: add herdr-client.log and sessions to herdr cleanup --- home.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/home.nix b/home.nix index a5ed090..93bf0c5 100644 --- a/home.nix +++ b/home.nix @@ -118,10 +118,12 @@ in "$repoHerdr/herdr-client.sock" \ "$repoHerdr/herdr.sock.agent" \ "$repoHerdr/herdr-server.log" \ + "$repoHerdr/herdr-client.log" \ "$repoHerdr/.plugins.lock" \ "$repoHerdr/session.json" \ "$repoHerdr/release-notes.json" \ - "$repoHerdr/session-snapshots" + "$repoHerdr/session-snapshots" \ + "$repoHerdr/sessions" fi ''; -- 2.54.0 From 1eb147f3d34d892954b28e0c41d0e028ca6e2159 Mon Sep 17 00:00:00 2001 From: Lap Tran Date: Mon, 5 Oct 2026 22:49:57 -0400 Subject: [PATCH 6/8] no-mistakes(document): Record herdr config-dir invariant; flag stale rebuild.sh rotation --- AGENTS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AGENTS.md b/AGENTS.md index f69cfc5..2d38feb 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -6,6 +6,7 @@ Deliberate decisions in this repo - do NOT silently revert them: - Agent configs under `home/` are the source of truth. `home.nix` installs them with `mkOutOfStoreSymlink` + `force = true`, so edits to files in `home/` apply live after the first rebuild that creates the symlink. Prefer editing those paths, not the live `~/.claude` / `~/.grok` / `~/.pi` copies. `rebuild.sh` rotates stale `*.backup` files before switch so home-manager never fails with "would be clobbered". - Grok Build is first-class here: `home/.grok/config.toml` and `home/AGENTS.md` (linked as `~/.grok/AGENTS.md`). Claude, Codex, opencode, and Pi share the same `home/AGENTS.md` for multi-agent work. - 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. Launch with shell alias `fm` (`cd` + OpenCode 2 via `~/.local/bin/oc2`). Self-update via `/updatefirstmate`, not rebuild. - OpenCode 2 is the firstmate primary. It is not a Homebrew formula: install `@opencode-ai/cli@beta` with Homebrew's npm (`home.activation.opencode2`). Launch through `home/bin/oc2` so `OPENCODE_CONFIG` stays at `home/.config/opencode2/opencode.json` and cannot rewrite OpenCode 1.x's `~/.config/opencode`. Do not add a brew `opencode` / `opencode2` formula; `zap` would fight the npm install. firstmate harness detection matches `*opencode*`, so the `opencode2` process name still classifies as OpenCode. -- 2.54.0 From b0d7087a46f0cbcfec2ec8254301833fd52e0576 Mon Sep 17 00:00:00 2001 From: Lap Tran Date: Mon, 5 Oct 2026 22:58:29 -0400 Subject: [PATCH 7/8] fix(rebuild): rotate herdr config.toml backup as a file target ~/.config/herdr moved from a whole-directory home.file target to a file target, so rebuild.sh must follow. Treat ~/.config/herdr/config.toml as a managed file backup target and stop listing ~/.config/herdr as a directory target, otherwise a real config.toml backed up to config.toml.backup would fail the next switch with "would be clobbered". --- rebuild.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rebuild.sh b/rebuild.sh index 21e98db..bc4f63d 100755 --- a/rebuild.sh +++ b/rebuild.sh @@ -40,6 +40,7 @@ managed=( "$HOME/.claude/CLAUDE.md" "$HOME/.codex/AGENTS.md" "$HOME/.codex/luna.config.toml" + "$HOME/.config/herdr/config.toml" "$HOME/.config/opencode/AGENTS.md" "$HOME/.config/opencode/opencode.json" "$HOME/.config/opencode2/opencode.json" @@ -62,7 +63,6 @@ done for path in \ "$HOME/.config/wezterm" \ "$HOME/.config/nvim" \ - "$HOME/.config/herdr" \ "$HOME/.config/opencode/skills" \ "$HOME/.pi/agent/themes" \ "$HOME/.pi/agent/extensions/calm" -- 2.54.0 From 2bcaf5fd32e30e6aceea0dd89151c764c97abeee Mon Sep 17 00:00:00 2001 From: Lap Tran Date: Mon, 5 Oct 2026 23:19:25 -0400 Subject: [PATCH 8/8] no-mistakes(document): Point herdr state-file rationale at the cleanup list --- home.nix | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/home.nix b/home.nix index 93bf0c5..f14036f 100644 --- a/home.nix +++ b/home.nix @@ -82,11 +82,11 @@ in force = true; }; # herdr treats ~/.config/herdr as both its config directory and its state - # directory: it writes herdr.sock, herdr-client.sock, herdr-server.log, - # .plugins.lock, session.json and session-snapshots/ beside config.toml, and it - # offers no option to relocate them. Keep that directory a real directory and - # link only the config file - a whole-directory symlink into this repo makes - # every running herdr server dirty the working tree. + # directory: it writes its sockets, logs, lock files and session state beside + # config.toml, and it offers no option to relocate them. Keep that directory a + # real directory and link only the config file - a whole-directory symlink into + # this repo makes every running herdr server dirty the working tree. The exact + # artifact list is the cleanup below, so it cannot drift from the code. home.file.".config/herdr/config.toml" = { source = config.lib.file.mkOutOfStoreSymlink "${dotfiles}/home/.config/herdr/config.toml"; force = true; -- 2.54.0