From c104ee92bf1cf4c9b4ccaa773fd108627a83bbf3 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Tue, 16 Sep 2025 21:28:43 -0500 Subject: [PATCH] opencode: path support for agents/commands Support paths for the commands/agents since we are linking files. Signed-off-by: Austin Horstman --- modules/programs/opencode.nix | 96 ++++++++++++++++------------------- 1 file changed, 44 insertions(+), 52 deletions(-) diff --git a/modules/programs/opencode.nix b/modules/programs/opencode.nix index 418202ad3..040743ee0 100644 --- a/modules/programs/opencode.nix +++ b/modules/programs/opencode.nix @@ -80,69 +80,61 @@ in }; commands = lib.mkOption { - type = lib.types.attrsOf lib.types.lines; + type = lib.types.attrsOf (lib.types.either lib.types.lines lib.types.path); default = { }; description = '' Custom commands for opencode. - The attribute name becomes the command filename, and the value is the file content. + The attribute name becomes the command filename, and the value is either: + - Inline content as a string + - A path to a file containing the command content Commands are stored in ~/.config/opencode/command/ directory. ''; - example = { - changelog = '' - # Update Changelog Command + example = lib.literalExpression '' + { + changelog = ''' + # Update Changelog Command - Update CHANGELOG.md with a new entry for the specified version. - Usage: /changelog [version] [change-type] [message] - ''; - fix-issue = '' - # Fix Issue Command + Update CHANGELOG.md with a new entry for the specified version. + Usage: /changelog [version] [change-type] [message] + '''; + fix-issue = ./commands/fix-issue.md; + commit = ''' + # Commit Command - Fix a GitHub issue following coding standards. - Usage: /fix-issue [issue-number] - ''; - commit = '' - # Commit Command - - Create a git commit with proper message formatting. - Usage: /commit [message] - ''; - }; + Create a git commit with proper message formatting. + Usage: /commit [message] + '''; + } + ''; }; agents = lib.mkOption { - type = lib.types.attrsOf lib.types.lines; + type = lib.types.attrsOf (lib.types.either lib.types.lines lib.types.path); default = { }; description = '' Custom agents for opencode. - The attribute name becomes the agent filename, and the value is the file content. + The attribute name becomes the agent filename, and the value is either: + - Inline content as a string + - A path to a file containing the agent content Agents are stored in ~/.config/opencode/agent/ directory. ''; - example = { - code-reviewer = '' - # Code Reviewer Agent + example = lib.literalExpression '' + { + code-reviewer = ''' + # Code Reviewer Agent - You are a senior software engineer specializing in code reviews. - Focus on code quality, security, and maintainability. + You are a senior software engineer specializing in code reviews. + Focus on code quality, security, and maintainability. - ## Guidelines - - Review for potential bugs and edge cases - - Check for security vulnerabilities - - Ensure code follows best practices - - Suggest improvements for readability and performance - ''; - documentation = '' - # Documentation Agent - - You are a technical writer who creates clear, comprehensive documentation. - Focus on user-friendly explanations and examples. - - ## Guidelines - - Write clear, concise documentation - - Include practical examples - - Use proper formatting and structure - - Consider the target audience - ''; - }; + ## Guidelines + - Review for potential bugs and edge cases + - Check for security vulnerabilities + - Ensure code follows best practices + - Suggest improvements for readability and performance + '''; + documentation = ./agents/documentation.md; + } + ''; }; }; @@ -166,15 +158,15 @@ in } // lib.mapAttrs' ( name: content: - lib.nameValuePair "opencode/command/${name}.md" { - text = content; - } + lib.nameValuePair "opencode/command/${name}.md" ( + if lib.isPath content then { source = content; } else { text = content; } + ) ) cfg.commands // lib.mapAttrs' ( name: content: - lib.nameValuePair "opencode/agent/${name}.md" { - text = content; - } + lib.nameValuePair "opencode/agent/${name}.md" ( + if lib.isPath content then { source = content; } else { text = content; } + ) ) cfg.agents; }; }