Skip to content

Agents: prune stale claude MCP servers, one Nix workflow per agent, enable toggles - #20

Merged
andrewthomaslee merged 5 commits into
mainfrom
agents-workflow-fixes
Nov 7, 2026
Merged

andrewthomaslee merged 5 commits into
mainfrom
agents-workflow-fixes

Conversation

@andrewthomaslee

@andrewthomaslee andrewthomaslee commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes and workflow improvements for homeModules.agents from a review of the agents config.

1. Stale claude MCP servers are removed. The activation merge into ~/.claude.json only ever added servers, so a server the module stopped managing (headroom) stayed there and failed to connect in every session.

 activation claudeMcpServers (runs even when the server set is empty)
-  .mcpServers = (.mcpServers // {}) * $servers
+  previous = $XDG_STATE_HOME/home-manager/claude-mcp-servers.json
+             or, on first run, every name the module ever managed
+  .mcpServers = (.mcpServers - previous) * $servers
+  write keys($servers) to the state file

Servers added by hand with claude mcp add, and every other key, are kept.

2. One Nix workflow for every agent (homeSpec.agents.nixWorkflow.{enable,formatOnEdit}, on by default). It is rendered per agent in _nix-workflow.nix, so every agent gets the same defaults and each still turns on and off on its own:

claude opencode v2 kimi pi
Nix commands, fmt, check without a prompt permissions.allow shell allow rules (after the base rules; last match wins) none, on purpose¹ never prompts
/nix/store additionalDirectories external_directory rule reads auto-allowed unrestricted
Long builds and VM tests BASH_*_TIMEOUT_MS 10/60 min no setting: machine-context advice [task] bash_task_timeout_s 60 min extension: default 10 min, cap 60 min
alejandra on .nix edits PostToolUse hook formatter.nixfmt PostToolUse hook extension (tool_result)
How it is written settings.json opencode.json merged into config.toml at activation² ~/.pi/agent/extensions/nix-workflow.ts

¹ kimi matches a rule against the whole command string without splitting it, so allowing nix build would also approve nix build . && rm -rf ~.
² kimi's /login writes providers, models and oauth into the same file. kimi-config-merge (tomlkit) swaps only the module's hook and keeps every other key and comment. A baked kimi.config gets the same keys at eval time instead.

The skills runtime env (NODE_PATH) also goes into claude's settings env, so it applies however claude is launched. opencode gains package, installPackage and settings, like the other agents.

3. The machine context says where builds run. It adds a line like Nix builds: local KVM; remote builders: euc-hel-0 (x86_64-linux, aarch64-linux, kvm). Hardware is now read from osConfig.hardware.facter.report.

4. Layout and checks:

flake-parts/homeModules/agents/
├── agents.nix            # options + config
├── _machine-context.nix  # pure function, called by the module and the tests
├── _claude.nix           # claude-mcp-sync
└── _nix-workflow.nix     # the workflow per agent, agent-format-nix, kimi-config-merge
tests/flake-module.nix    # + agents-wiring, agents-independent, agents-machine-context, agents-scripts

Breaking changes (no compat shims, by design):

Was Now
homeSpec.agents.{pi,kimi,claude,opencode}.enabled .enable
homeSpec.agents.skills.enabled skills.enable
machineContext.facterFile, machineContext.facterReport removed (read from osConfig.hardware.facter)
github-mcp-server-opencode wrapper github-mcp-server-pat

Smaller changes:

  • new opencode.model and opencode.titleModel options (previously hardcoded)
  • the github oauth/pat assertion now applies even when opencode is off
  • ~/.claude/settings.json no longer carries the mcpServers claude ignores there

Evidence

  • Before: ~/.claude.json on kamrui-h1 lists artifacthub, github, headroom, nixos; claude reports headroom (CONNECTION_CLOSED).
    After: claude-mcp-sync, run on a copy of that file with the current server set → ["artifacthub","github","nixos"], and every other key is identical (diff of del(.mcpServers) is empty).
  • checks.agents-independent: each agent enabled alone writes exactly its own files and activations, has skills, and gets the same machine context as with all four on.
  • Smoke tests against the real binaries:
    • kimi 2.5.2 accepts the merged config.toml with no warning; a malformed hook prints Ignored invalid config section 'hooks'.
    • pi 1.5.0 loads nix-workflow.ts (a broken extension fails with ParseError). The handlers themselves need a logged-in model and were not run.
    • opencode 2.2.6 loads the generated opencode.json without warnings.
  • checks.agents-scripts covers the kimi merge (it keeps /login's keys and comments and the user's own hook, replaces a stale module hook, removes it when the workflow is off, and creates no file when there is nothing to add) and these cases:
    • a managed server is replaced, not deep-merged
    • a stale server is pruned on first run
    • turning the last server off removes it, while a server added by hand stays
    • a symlinked file is left alone; .nix files are formatted and other files are not
  • checks.agents-machine-context compares the full rendered text for a synthetic machine (facter report, KVM, a remote builder), and checks a KubeVirt-like guest with no KVM and no report.
  • devenv shell -- fmt passes; devenv shell -- nix flake check → exit 0 (15 checks).

Merge Danger

Door: two-way

Blast Radius: consumers

Merge order: this PR → external-systems/pkgs#22 → external-systems/home#21. external-systems/skills#13 is merged; flake.lock pins skills to main (d6ffaf0).

🤖 Generated with Claude Code

claude-code's ~/.claude.json MCP merge only ever added servers, so one
the module stopped managing (headroom) stayed and failed to connect in
every session. The sync now remembers what it wrote and drops those
names first; it runs with an empty set too.

- claude.nixWorkflow (default on): /nix/store access, nix
  eval/build/log/flake check and fmt/check without a prompt, Bash
  timeouts long enough for closure builds and VM tests, and a
  PostToolUse hook that runs alejandra on edited .nix files. The skills
  runtime env goes into claude's settings env too.
- Machine context: a "Nix builds" line (local KVM, remote builders),
  hardware read from osConfig.hardware.facter.report. facterFile and
  the unused facterReport are gone (tests set the report inline).
- Breaking: <agent>.enabled and skills.enabled are now .enable.
- opencode.model and opencode.titleModel options; the github
  oauth/pat assertion applies without opencode; the PAT wrapper is
  github-mcp-server-pat; settings.json drops the ignored mcpServers.
- Split into flake-parts/homeModules/agents/ with _machine-context.nix
  and _claude.nix, and checks for the wiring, the machine context and
  the claude scripts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rges)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
andrewthomaslee and others added 2 commits November 7, 2026 12:29
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Nix workflow moves from claude.nixWorkflow to
homeSpec.agents.nixWorkflow and is rendered per agent, so each one is
configured alike and still turned on and off on its own:

- claude: permissions.allow, /nix/store, Bash timeouts, PostToolUse hook
- opencode v2: shell allow rules after the base rules (last match
  wins), alejandra as the .nix formatter
- kimi: PostToolUse hook and the background task timeout, merged into
  the config.toml /login also writes (tomlkit, at activation) or into a
  baked kimi.config. No allow rules: kimi matches the whole command
  string, so a nix prefix would also approve `nix build . && rm -rf ~`.
- pi: ~/.pi/agent/extensions/nix-workflow.ts (bash timeout default and
  cap, alejandra after edit/write); pi never prompts.
- The machine context tells every agent to give long Nix builds and VM
  tests a long timeout (opencode has no timeout setting).

opencode gets package, installPackage and settings like the others.
New checks: agents-independent (each agent alone writes exactly its own
files and gets the same machine context), and agents-scripts now runs
the kimi config.toml merge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@andrewthomaslee andrewthomaslee changed the title Agents: prune stale claude MCP servers, Nix workflow for claude, enable toggles Agents: prune stale claude MCP servers, one Nix workflow per agent, enable toggles Nov 7, 2026
andrewthomaslee added a commit to external-systems/pkgs that referenced this pull request Nov 7, 2026
…le (#22)

overlays.llm-agents (in overlays.default) builds llm-agents.nix's
packages against the org nixpkgs (its shared-nixpkgs overlay) and puts
them in place of the attrs consumers already read: claude-code,
pi-coding-agent (pi), kimi-code, and opencode, which is opencode v2
only (opencode2, linked as bin/opencode). The whole set stays at
pkgs.llm-agents. The kimi-code port in pkgs/ is gone: upstream carries
it, a release ahead.

The input follows our nixpkgs (one nixpkgs), so cache.numtide.com only
hits when the revisions match; otherwise the agents build locally or on
the remote builder.

The code-agent image follows external-systems/modules#20:
skills/pi/kimi/claude .enabled -> .enable. dev/flake.lock pins that PR
head until it merges.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
sync-locks pins devenv.yaml to the same revision.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@andrewthomaslee
andrewthomaslee merged commit 507a2b0 into main Nov 7, 2026
3 checks passed
andrewthomaslee added a commit to external-systems/home that referenced this pull request Nov 7, 2026
…gents.nix (#21)

## Summary

Uses the agents work from external-systems/modules#20 and the
llm-agents.nix overlay from external-systems/pkgs#22.
external-systems/skills#13 is already merged.

```diff
 users/netsa/default.nix, users/matt/default.nix
   homeSpec.agents = {
-    claude.enabled = true;   # likewise pi, kimi, opencode
+    claude.enable = true;
 flake.lock / devenv.yaml / devenv.lock (sync-locks)
-  modules   main e78b5b0
+  modules   main 507a2b0 (modules#20 merged)
-  org-pkgs  main af32ce7
+  org-pkgs  main c56f3a9 (pkgs#22 merged)
```

What netsa gets on kamrui-h1 (matt likewise, for claude and pi):

| | |
|---|---|
| Agent versions | claude-code 2.1.319, pi 1.5.0, kimi-code 2.5.2,
opencode 2.2.6 (v2) |
| Every agent | the same machine context, incl. `Nix builds: local KVM;
remote builders: euc-hel-0 (…)` and the long-timeout advice; the same
MCP servers and skills |
| claude | Nix commands and `/nix/store` without a prompt, 10/60 min
Bash timeouts, alejandra hook; the stale `headroom` entry is removed
from `~/.claude.json` |
| opencode | the same shell allow rules, and alejandra as the `.nix`
formatter |
| kimi | alejandra hook and a 60 min background task limit, merged into
`~/.kimi-code/config.toml` |
| pi | `~/.pi/agent/extensions/nix-workflow.ts` (timeout default and
cap, alejandra after edits) |

## Evidence

- `devenv shell -- fmt` passes; `devenv shell -- nix flake check` → exit
0 (every machine evaluates).
- `nix eval` of `kamrui-h1…users.netsa`: the packages are `pi-1.5.0,
kimi-code-2.5.2, claude-code-2.1.319, opencode-2.2.6`; the activations
are `claudeMcpServers` and `kimiNixWorkflow`;
`.pi/agent/extensions/nix-workflow.ts` is present.

## Merge Danger

**Door:** two-way

**Blast Radius:** netsa, matt

external-systems/modules#20 and external-systems/pkgs#22 are merged; the
lock is on main for both (`nix flake update modules org-pkgs &&
sync-locks`).

Deploy (owner): `clan machines update kamrui-h1` (and beelink). On first
activation, claude's `~/.claude.json` loses the stale `headroom` entry,
and kimi's `config.toml` gains the hook and the `[task]` timeout. Every
other key in both files is kept.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
andrewthomaslee added a commit that referenced this pull request Nov 14, 2026
Claude Code's Bash tool replaces `grep` with its bundled ugrep, so a
PCRE lookaround silently failed a check in the retro session. The note
goes only into ~/.claude/CLAUDE.md (pi, kimi and opencode do not have
the wrapper); agents-wiring asserts that CLAUDE.md is the shared machine
context plus that note. org-pkgs 2fa0b28 (pkgs#33: eval-warning gate,
vm-test --resume, runner self-test, grep -q lint) and skills d6f59bf
(#20); sync-locks in the same commit.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant