1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 19:46:05 +01:00

claude-code: added 'agentsDir' option to specify agents from filesystem

This commit is contained in:
Sewer56 2025-08-22 21:35:25 +01:00 committed by Austin Horstman
parent 343e555657
commit a641bbbb9b
6 changed files with 55 additions and 0 deletions

View file

@ -186,6 +186,16 @@ in
}; };
}; };
agentsDir = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
description = ''
Path to a directory containing agent files for Claude Code.
Agent files from this directory will be symlinked to .claude/agents/.
'';
example = lib.literalExpression "./agents";
};
mcpServers = lib.mkOption { mcpServers = lib.mkOption {
type = lib.types.attrsOf jsonFormat.type; type = lib.types.attrsOf jsonFormat.type;
default = { }; default = { };
@ -237,6 +247,10 @@ in
assertion = !(cfg.memory.text != null && cfg.memory.source != null); assertion = !(cfg.memory.text != null && cfg.memory.source != null);
message = "Cannot specify both `programs.claude-code.memory.text` and `programs.claude-code.memory.source`"; message = "Cannot specify both `programs.claude-code.memory.text` and `programs.claude-code.memory.source`";
} }
{
assertion = !(cfg.agents != { } && cfg.agentsDir != null);
message = "Cannot specify both `programs.claude-code.agents` and `programs.claude-code.agentsDir`";
}
]; ];
programs.claude-code.finalPackage = programs.claude-code.finalPackage =
@ -281,6 +295,11 @@ in
".claude/CLAUDE.md" = lib.mkIf (cfg.memory.text != null || cfg.memory.source != null) ( ".claude/CLAUDE.md" = lib.mkIf (cfg.memory.text != null || cfg.memory.source != null) (
if cfg.memory.text != null then { text = cfg.memory.text; } else { source = cfg.memory.source; } if cfg.memory.text != null then { text = cfg.memory.text; } else { source = cfg.memory.source; }
); );
".claude/agents" = lib.mkIf (cfg.agentsDir != null) {
source = cfg.agentsDir;
recursive = true;
};
} }
// lib.mapAttrs' ( // lib.mapAttrs' (
name: content: name: content:

View file

@ -0,0 +1,14 @@
{
programs.claude-code = {
enable = true;
agentsDir = ./agents;
};
nmt.script = ''
assertFileExists home-files/.claude/agents/test-agent.md
assertLinkExists home-files/.claude/agents/test-agent.md
assertFileContent \
home-files/.claude/agents/test-agent.md \
${./agents/test-agent.md}
'';
}

View file

@ -0,0 +1,6 @@
---
name: test-agent
description: Test agent for agentsDir functionality
---
This is a test agent to verify that agentsDir works correctly.

View file

@ -20,10 +20,17 @@
text = "Some text content"; text = "Some text content";
source = ./expected-memory.md; source = ./expected-memory.md;
}; };
# assert fail: cannot set agents and agentsDir at the same time.
agents = {
test-agent = "test content";
};
agentsDir = ./agents;
}; };
test.asserts.assertions.expected = [ test.asserts.assertions.expected = [
"`programs.claude-code.package` cannot be null when `mcpServers` is configured" "`programs.claude-code.package` cannot be null when `mcpServers` is configured"
"Cannot specify both `programs.claude-code.memory.text` and `programs.claude-code.memory.source`" "Cannot specify both `programs.claude-code.memory.text` and `programs.claude-code.memory.source`"
"Cannot specify both `programs.claude-code.agents` and `programs.claude-code.agentsDir`"
]; ];
} }

View file

@ -5,4 +5,5 @@
claude-code-assertion = ./assertion.nix; claude-code-assertion = ./assertion.nix;
claude-code-memory-management = ./memory-management.nix; claude-code-memory-management = ./memory-management.nix;
claude-code-memory-from-source = ./memory-from-source.nix; claude-code-memory-from-source = ./memory-from-source.nix;
claude-code-agents-dir = ./agents-dir.nix;
} }

View file

@ -0,0 +1,8 @@
# Claude Code Agents
## Current Configuration
Test implementation of agents directory management.
## Available Agents
- This is a test configuration
- AgentsDir should be created at ~/.claude/agents/README.md