opencode: support directory-based configuration for commands, agents, and themes

The `commands`, `agents`, and `themes` options now accept either an
attribute set (existing behavior) or a path to a directory containing
multiple files. When a directory path is provided, it is symlinked to
the appropriate `$XDG_CONFIG_HOME/opencode/` subdirectory.

This change aligns with the existing `skills` option implementation and
provides a more convenient way to manage multiple configuration files
without needing to define each one individually in Nix.
This commit is contained in:
Thierry Delafontaine 2026-01-04 12:59:22 +01:00 committed by Austin Horstman
parent 2be878259a
commit 081234b704
18 changed files with 246 additions and 56 deletions

View file

@ -0,0 +1,15 @@
{
programs.opencode = {
enable = true;
agents = ./agents-bulk;
};
nmt.script = ''
assertFileExists home-files/.config/opencode/agent/code-reviewer.md
assertFileExists home-files/.config/opencode/agent/documentation.md
assertFileContent home-files/.config/opencode/agent/code-reviewer.md \
${./agents-bulk/code-reviewer.md}
assertFileContent home-files/.config/opencode/agent/documentation.md \
${./agents-bulk/documentation.md}
'';
}

View file

@ -0,0 +1,4 @@
# Code Reviewer Agent
You are a senior software engineer specializing in code reviews.
Focus on code quality, security, and maintainability.

View file

@ -0,0 +1,3 @@
# Documentation Agent
You are a technical writer specializing in creating clear, comprehensive documentation.

View file

@ -12,7 +12,8 @@
- Review for potential bugs and edge cases
- Check for security vulnerabilities
- Ensure code follows best practices
- Suggest improvements for readability and performance'';
- Suggest improvements for readability and performance
'';
documentation = ''
# Documentation Agent
@ -23,7 +24,8 @@
- Write clear, concise documentation
- Include practical examples
- Use proper formatting and structure
- Consider the target audience'';
- Consider the target audience
'';
};
};
nmt.script = ''

View file

@ -1,4 +1,4 @@
# Update Changelog Command
Update CHANGELOG.md with a new entry for the specified version.
Usage: /changelog [version] [change-type] [message]
Usage: /changelog [version] [change-type] [message]

View file

@ -7,4 +7,4 @@ Focus on code quality, security, and maintainability.
- Review for potential bugs and edge cases
- Check for security vulnerabilities
- Ensure code follows best practices
- Suggest improvements for readability and performance
- Suggest improvements for readability and performance

View file

@ -0,0 +1,15 @@
{
programs.opencode = {
enable = true;
commands = ./commands-bulk;
};
nmt.script = ''
assertFileExists home-files/.config/opencode/command/changelog.md
assertFileExists home-files/.config/opencode/command/commit.md
assertFileContent home-files/.config/opencode/command/changelog.md \
${./commands-bulk/changelog.md}
assertFileContent home-files/.config/opencode/command/commit.md \
${./commands-bulk/commit.md}
'';
}

View file

@ -0,0 +1,4 @@
# Update Changelog Command
Update CHANGELOG.md with a new entry for the specified version.
Usage: /changelog [version] [change-type] [message]

View file

@ -0,0 +1,4 @@
# Commit Command
Create a git commit with proper message formatting.
Usage: /commit [message]

View file

@ -6,12 +6,14 @@
# Update Changelog Command
Update CHANGELOG.md with a new entry for the specified version.
Usage: /changelog [version] [change-type] [message]'';
Usage: /changelog [version] [change-type] [message]
'';
commit = ''
# Commit Command
Create a git commit with proper message formatting.
Usage: /commit [message]'';
Usage: /commit [message]
'';
};
};
nmt.script = ''

View file

@ -1,4 +1,4 @@
# Commit Command
Create a git commit with proper message formatting.
Usage: /commit [message]
Usage: /commit [message]

View file

@ -8,6 +8,8 @@
opencode-commands-inline = ./commands-inline.nix;
opencode-agents-path = ./agents-path.nix;
opencode-commands-path = ./commands-path.nix;
opencode-agents-bulk-directory = ./agents-bulk-directory.nix;
opencode-commands-bulk-directory = ./commands-bulk-directory.nix;
opencode-mixed-content = ./mixed-content.nix;
opencode-skills-inline = ./skills-inline.nix;
opencode-skills-path = ./skills-path.nix;
@ -15,6 +17,7 @@
opencode-skills-bulk-directory = ./skills-bulk-directory.nix;
opencode-themes-inline = ./themes-inline.nix;
opencode-themes-path = ./themes-path.nix;
opencode-themes-bulk-directory = ./themes-bulk-directory.nix;
opencode-mcp-integration = ./mcp-integration.nix;
opencode-mcp-integration-with-override = ./mcp-integration-with-override.nix;
}

View file

@ -7,4 +7,4 @@ Focus on user-friendly explanations and examples.
- Write clear, concise documentation
- Include practical examples
- Use proper formatting and structure
- Consider the target audience
- Consider the target audience

View file

@ -15,16 +15,65 @@
'';
path-agent = ./test-agent.md;
};
skills = {
inline-skill = ''
---
name: inline-skill
description: An inline skill definition
---
## What I do
This skill is defined inline.
'';
path-skill = ./git-release-SKILL.md;
dir-skill = ./skill-dir/data-analysis;
};
themes = {
inline-theme = {
name = "inline-theme";
colors = {
primary = "#000000";
secondary = "#ffffff";
};
};
path-theme = ./my-theme.json;
};
};
nmt.script = ''
# Commands
assertFileExists home-files/.config/opencode/command/inline-command.md
assertFileExists home-files/.config/opencode/command/path-command.md
assertFileExists home-files/.config/opencode/agent/inline-agent.md
assertFileExists home-files/.config/opencode/agent/path-agent.md
assertFileContent home-files/.config/opencode/command/path-command.md \
${./test-command.md}
# Agents
assertFileExists home-files/.config/opencode/agent/inline-agent.md
assertFileExists home-files/.config/opencode/agent/path-agent.md
assertFileContent home-files/.config/opencode/agent/path-agent.md \
${./test-agent.md}
# Skills
assertFileExists home-files/.config/opencode/skill/inline-skill/SKILL.md
assertFileExists home-files/.config/opencode/skill/path-skill/SKILL.md
assertFileExists home-files/.config/opencode/skill/dir-skill/SKILL.md
assertFileExists home-files/.config/opencode/skill/dir-skill/notes.txt
assertFileContent home-files/.config/opencode/skill/path-skill/SKILL.md \
${./git-release-SKILL.md}
assertFileContent home-files/.config/opencode/skill/dir-skill/SKILL.md \
${./skill-dir/data-analysis/SKILL.md}
# Themes
assertFileExists home-files/.config/opencode/themes/inline-theme.json
assertFileExists home-files/.config/opencode/themes/path-theme.json
assertFileContent home-files/.config/opencode/themes/path-theme.json \
${./my-theme.json}
# Verify inline-theme has the schema
assertFileContains home-files/.config/opencode/themes/inline-theme.json \
'"$schema": "https://opencode.ai/theme.json"'
'';
}

View file

@ -0,0 +1,15 @@
{
programs.opencode = {
enable = true;
themes = ./themes-bulk;
};
nmt.script = ''
assertFileExists home-files/.config/opencode/themes/dark-theme.json
assertFileExists home-files/.config/opencode/themes/light-theme.json
assertFileContent home-files/.config/opencode/themes/dark-theme.json \
${./themes-bulk/dark-theme.json}
assertFileContent home-files/.config/opencode/themes/light-theme.json \
${./themes-bulk/light-theme.json}
'';
}

View file

@ -0,0 +1,8 @@
{
"$schema": "https://opencode.ai/theme.json",
"name": "dark-theme",
"colors": {
"primary": "#1e1e1e",
"secondary": "#252526"
}
}

View file

@ -0,0 +1,8 @@
{
"$schema": "https://opencode.ai/theme.json",
"name": "light-theme",
"colors": {
"primary": "#ffffff",
"secondary": "#f3f3f3"
}
}