Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions flake-parts/homeModules/agents/agents.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
# appended after the preset (inputs.skills.lib.selections).
# homeSpec.agents.<agent>.enable — install pi / kimi / claude /
# opencode and point the agent's skills dir at the shared tree.
# homeSpec.agents.claude.autoMode — claude's auto mode classifier
# rules (environment, allow, softDeny, hardDeny), concatenated
# across modules and led by "$defaults".
# homeSpec.agents.claude.desktop — Claude Desktop next to claude
# (on with it), Cowork's QEMU when the machine has KVM; the host
# side (kvm group, vhost_vsock) is nixosModules.claude-desktop.
Expand Down Expand Up @@ -276,8 +279,21 @@
})
(lib.optionalAttrs skillsRuntimeEnabled {inherit (skillsRuntime) env;})
(lib.optionalAttrs (claudeInstructions.mode == "replace") {outputStyle = claudeOutputStyle;})
(lib.optionalAttrs (claudeAutoMode != {}) {autoMode = claudeAutoMode;})
cfg.claude.settings
];

# settings.json autoMode from homeSpec.agents.claude.autoMode: only
# the non-empty lists, each led by "$defaults" unless opted out.
claudeAutoMode = let
am = cfg.claude.autoMode;
lists = lib.filterAttrs (_: rules: rules != []) {
inherit (am) environment allow;
soft_deny = am.softDeny;
hard_deny = am.hardDeny;
};
in
lib.mapAttrs (_: rules: lib.optional am.includeDefaults "$defaults" ++ rules) lists;
in {
imports = [
(lib.mkRemovedOptionModule ["homeSpec" "agents" "claude" "claudeMd"] "Use homeSpec.agents.instructions (or homeSpec.agents.claude.instructions) instead; its text is added to the machine context and ground rules, and mode = \"replace\" replaces the system prompt.")
Expand Down Expand Up @@ -548,6 +564,29 @@
default = {};
description = "Extra claude-code settings.json attrs, merged over the homeSpec.agents.nixWorkflow defaults (these win key by key).";
};
# Auto mode's classifier rules (settings.json autoMode.*). Typed
# lists, not claude.settings: settings is merged with
# recursiveUpdate, which replaces lists, so two modules could not
# each add rules there. claude reads autoMode only from user,
# flag and policy settings, never a project's .claude/.
autoMode = let
rules = section:
lib.mkOption {
type = with lib.types; listOf str;
default = [];
description = "Prose rules for auto mode's ${section}. Definitions from several modules are concatenated.";
};
in {
includeDefaults = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Start every non-empty list with \"$defaults\", so claude's built-in rules stay in force and these rules add to them.";
};
environment = rules "environment (the trusted context: org, repos, domains, providers)";
allow = rules "allow section (actions that need no prompt)";
softDeny = rules "SOFT BLOCK section (destructive or irreversible actions the user's intent can clear)";
hardDeny = rules "HARD BLOCK section (security boundaries the user's intent never clears)";
};
# The sandbox bakes ~/.claude.json too (claude merges either
# file) so the onboarding skip survives claude rewriting its
# mutable state file.
Expand Down
8 changes: 7 additions & 1 deletion tests/fixtures/nixos.nix
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,13 @@
};
pi.enable = true;
kimi.enable = true;
claude.enable = true;
claude = {
enable = true;
autoMode = {
environment = ["Trusted org: example"];
softDeny = ["Deploying a machine"];
};
};
mcp.github.auth = "pat";
skills = {
preset = "full";
Expand Down
3 changes: 3 additions & 0 deletions tests/flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@
assert expect (lib.length claude.hooks.PostToolUse == 1) "no .nix format hook";
assert expect (lib.length claude.hooks.PreToolUse == 1) "no git hook guard";
assert expect (!(claude ? mcpServers)) "settings.json carries mcpServers";
assert expect (claude.autoMode.environment == ["$defaults" "Trusted org: example"]) "autoMode.environment does not keep the built-in rules first";
assert expect (claude.autoMode.soft_deny == ["$defaults" "Deploying a machine"]) "autoMode.softDeny not rendered as soft_deny";
assert expect (!(claude.autoMode ? allow || claude.autoMode ? hard_deny)) "empty autoMode lists are written";
assert expect (hm.home.activation ? claudeMcpServers) "no ~/.claude.json MCP sync";
assert expect (hm.programs.opencode.settings.mcp.servers.github.type == "local") "opencode github not on the pat server";
assert expect ((json ".kimi-code/mcp.json").mcpServers ? github) "kimi has no github server";
Expand Down