fix: keep herdr runtime state out of the dotfiles working tree #3

Merged
hermes merged 8 commits from fm/fm-clone-runtime-dirt-dotfiles into main 2026-10-06 10:25:47 -04:00
3 changed files with 45 additions and 3 deletions

No files matched your search

+1
View File
@@ -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.
+43 -2
View File
@@ -81,11 +81,52 @@ 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 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;
};
# 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 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"
fi
repoHerdr="${dotfiles}/home/.config/herdr"
if [ -d "$repoHerdr" ]; then
run ${pkgs.coreutils}/bin/rm -rf \
"$repoHerdr/herdr.sock" \
"$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/sessions"
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";
+1 -1
View File
@@ -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"