refactor: centralize agent skills at ~/.agents/skills

This commit is contained in:
sascha.koenig
2026-04-20 08:58:15 +02:00
parent bc41c9a428
commit 35f4821bc5
3 changed files with 48 additions and 39 deletions

View File

@@ -1,10 +1,39 @@
# Per-tool agent sub-modules # Per-tool agent sub-modules
# Each module handles rendering canonical agent.toml definitions # Each module handles rendering canonical agent.toml definitions
# for a specific AI coding tool. # for a specific AI coding tool.
#
# Also provides the shared coding.agents.skills submodule that writes
# ~/.agents/skills — the central skills directory used by Pi, OpenCode, etc.
{ {
config,
lib,
pkgs,
...
}: let
shared = import ./shared-options.nix {inherit lib;};
cfg = config.coding.agents.skills;
mkIf = lib.mkIf;
in {
imports = [ imports = [
./opencode.nix ./opencode.nix
./claude-code.nix ./claude-code.nix
./pi.nix ./pi.nix
]; ];
options.coding.agents.skills = {
agentsInput = shared.mkAgentsInputOption ''
The `agents` flake input (your personal AGENTS repo).
When set, skills are symlinked to ~/.agents/skills.
'';
externalSkills = shared.externalSkillsOption;
};
config = mkIf (cfg.agentsInput != null) {
home.file.".agents/skills".source = cfg.agentsInput.lib.mkOpencodeSkills {
inherit pkgs;
customSkills = "${cfg.agentsInput}/skills";
externalSkills = shared.mapExternalSkills cfg.externalSkills;
};
};
} }

View File

@@ -17,8 +17,6 @@ in
''; '';
modelOverrides = shared.mkModelOverridesOption; modelOverrides = shared.mkModelOverridesOption;
externalSkills = shared.externalSkillsOption;
}; };
config = mkIf config.coding.agents.opencode.enable { config = mkIf config.coding.agents.opencode.enable {
@@ -34,18 +32,6 @@ in
}; };
}; };
# Skills (merged from personal AGENTS repo + optional external skills)
xdg.configFile."opencode/skills" = let
cfg = config.coding.agents.opencode;
in
mkIf (cfg.agentsInput != null) {
source = cfg.agentsInput.lib.mkOpencodeSkills {
inherit pkgs;
customSkills = "${cfg.agentsInput}/skills";
externalSkills = shared.mapExternalSkills cfg.externalSkills;
};
};
# Static config dirs from AGENTS repo # Static config dirs from AGENTS repo
xdg.configFile."opencode/context" = let xdg.configFile."opencode/context" = let
cfg = config.coding.agents.opencode; cfg = config.coding.agents.opencode;

View File

@@ -15,7 +15,10 @@ in
mcpServers = mkOption { mcpServers = mkOption {
type = types.attrsOf types.anything; type = types.attrsOf types.anything;
default = if mcpCfg != null then mcpCfg.servers else {}; default =
if mcpCfg != null
then mcpCfg.servers
else {};
defaultText = literalExpression "config.programs.mcp.servers"; defaultText = literalExpression "config.programs.mcp.servers";
description = '' description = ''
MCP server configurations for Pi (pi-mcp-adapter). MCP server configurations for Pi (pi-mcp-adapter).
@@ -41,8 +44,6 @@ in
''; '';
}; };
externalSkills = shared.externalSkillsOption;
settings = mkOption { settings = mkOption {
type = types.submodule { type = types.submodule {
freeformType = types.attrsOf types.anything; freeformType = types.attrsOf types.anything;
@@ -156,8 +157,11 @@ in
then let then let
filtered = filterNulls v; filtered = filterNulls v;
in in
if filtered == {} then null else filtered if filtered == {}
else v) attrs then null
else filtered
else v)
attrs
); );
piSettings = filterNulls cfg.settings; piSettings = filterNulls cfg.settings;
@@ -177,8 +181,7 @@ in
# Dynamic home.file entries for agent .md files # Dynamic home.file entries for agent .md files
agentFiles = agentFiles =
if cfg.agentsInput != null if cfg.agentsInput != null
then then let
let
agentNames = builtins.attrNames cfg.agentsInput.lib.loadAgents; agentNames = builtins.attrNames cfg.agentsInput.lib.loadAgents;
in in
builtins.listToAttrs ( builtins.listToAttrs (
@@ -213,15 +216,6 @@ in
# ── Agents — pi-subagents .md files ──────────────────────────── # ── Agents — pi-subagents .md files ────────────────────────────
agentFiles agentFiles
# ── Skills symlinked from AGENTS repo + external skills ────────
(mkIf (cfg.agentsInput != null) {
".pi/agent/skills".source = cfg.agentsInput.lib.mkOpencodeSkills {
inherit pkgs;
customSkills = "${cfg.agentsInput}/skills";
externalSkills = shared.mapExternalSkills cfg.externalSkills;
};
})
]; ];
}); });
} }