diff --git a/modules/programs/claude-code.nix b/modules/programs/claude-code.nix index e8644394..6464ea15 100644 --- a/modules/programs/claude-code.nix +++ b/modules/programs/claude-code.nix @@ -156,6 +156,36 @@ in }; }; + memory = { + text = lib.mkOption { + type = lib.types.nullOr lib.types.lines; + default = null; + description = '' + Inline memory content for CLAUDE.md. + This option is mutually exclusive with memory.source. + ''; + example = '' + # Project Memory + + ## Current Task + Implementing enhanced claude-code module for home-manager. + + ## Key Files + - claude-code.nix: Main module implementation + ''; + }; + + source = lib.mkOption { + type = lib.types.nullOr lib.types.path; + default = null; + description = '' + Path to a file containing memory content for CLAUDE.md. + This option is mutually exclusive with memory.text. + ''; + example = lib.literalExpression "./claude-memory.md"; + }; + }; + mcpServers = lib.mkOption { type = lib.types.attrsOf jsonFormat.type; default = { }; @@ -203,6 +233,10 @@ in assertion = cfg.mcpServers == { } || cfg.package != null; message = "`programs.claude-code.package` cannot be null when `mcpServers` is configured"; } + { + assertion = !(cfg.memory.text != null && cfg.memory.source != null); + message = "Cannot specify both `programs.claude-code.memory.text` and `programs.claude-code.memory.source`"; + } ]; programs.claude-code.finalPackage = @@ -243,6 +277,10 @@ in } ); }; + + ".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; } + ); } // lib.mapAttrs' ( name: content: diff --git a/tests/modules/programs/claude-code/assertion.nix b/tests/modules/programs/claude-code/assertion.nix index b1d5f042..5e343e40 100644 --- a/tests/modules/programs/claude-code/assertion.nix +++ b/tests/modules/programs/claude-code/assertion.nix @@ -14,9 +14,16 @@ ]; }; }; + + # assert fail: cannot set text and source at the same time. + memory = { + text = "Some text content"; + source = ./expected-memory.md; + }; }; test.asserts.assertions.expected = [ "`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`" ]; } diff --git a/tests/modules/programs/claude-code/default.nix b/tests/modules/programs/claude-code/default.nix index 3c98cad8..6ec0ef97 100644 --- a/tests/modules/programs/claude-code/default.nix +++ b/tests/modules/programs/claude-code/default.nix @@ -3,4 +3,6 @@ claude-code-full-config = ./full-config.nix; claude-code-mcp = ./mcp.nix; claude-code-assertion = ./assertion.nix; + claude-code-memory-management = ./memory-management.nix; + claude-code-memory-from-source = ./memory-from-source.nix; } diff --git a/tests/modules/programs/claude-code/expected-memory.md b/tests/modules/programs/claude-code/expected-memory.md new file mode 100644 index 00000000..e6daa429 --- /dev/null +++ b/tests/modules/programs/claude-code/expected-memory.md @@ -0,0 +1,8 @@ +# Project Memory + +## Current Task +Test implementation of memory management. + +## Key Context +- This is a test configuration +- Memory should be created at ~/.claude/CLAUDE.md diff --git a/tests/modules/programs/claude-code/memory-from-source.nix b/tests/modules/programs/claude-code/memory-from-source.nix new file mode 100644 index 00000000..0a188018 --- /dev/null +++ b/tests/modules/programs/claude-code/memory-from-source.nix @@ -0,0 +1,13 @@ +{ + programs.claude-code = { + enable = true; + memory = { + source = ./expected-memory.md; + }; + }; + + nmt.script = '' + assertFileExists home-files/.claude/CLAUDE.md + assertFileContent home-files/.claude/CLAUDE.md ${./expected-memory.md} + ''; +} diff --git a/tests/modules/programs/claude-code/memory-management.nix b/tests/modules/programs/claude-code/memory-management.nix new file mode 100644 index 00000000..10c7b3e3 --- /dev/null +++ b/tests/modules/programs/claude-code/memory-management.nix @@ -0,0 +1,22 @@ +{ + programs.claude-code = { + enable = true; + memory = { + text = '' + # Project Memory + + ## Current Task + Test implementation of memory management. + + ## Key Context + - This is a test configuration + - Memory should be created at ~/.claude/CLAUDE.md + ''; + }; + }; + + nmt.script = '' + assertFileExists home-files/.claude/CLAUDE.md + assertFileContent home-files/.claude/CLAUDE.md ${./expected-memory.md} + ''; +}