Skip to content

Commit 4ce2ca7

Browse files
committed
fix(codex): command as skills proper creation
Need to properly create the files so that codex actually picks them up.
1 parent 0fec6c2 commit 4ce2ca7

2 files changed

Lines changed: 37 additions & 10 deletions

File tree

modules/common/ai-tools/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ in
169169
commandSkillFiles = aiCommands.toCodexSkillFiles;
170170
contextOverride = codexContextOverride;
171171
skills = skillsForHarness "codex";
172+
skillSources = skillsAttrsForHarness "codex";
172173
};
173174

174175
githubCopilotCli = {

modules/home/programs/terminal/tools/codex/default.nix

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,44 @@ let
2929
path = "${codexConfigPath}/skills/.system/${name}/SKILL.md";
3030
enabled = false;
3131
}) aiTools.codex.disabledSystemSkills;
32+
codexCommandSkillNames = builtins.attrNames aiTools.codex.commandSkillFiles;
3233
codexAgentFiles = lib.mapAttrs' (
3334
name: agentSettings:
3435
lib.nameValuePair "${codexConfigDir}/agents/${name}.toml" {
3536
source = tomlFormat.generate "codex-agent-${name}" agentSettings;
3637
}
3738
) aiTools.codex.agents;
38-
codexCommandFiles = lib.concatMapAttrs (
39+
codexCommandSkillDirs = lib.mapAttrs (
3940
name: commandFiles:
40-
lib.mapAttrs' (
41-
relativePath: fileText:
42-
lib.nameValuePair "${codexConfigDir}/skills/${name}/${relativePath}" {
43-
text = fileText;
44-
}
45-
) commandFiles
41+
pkgs.runCommandLocal "codex-command-skill-${name}" { } (
42+
lib.concatStringsSep "\n" (
43+
lib.mapAttrsToList (
44+
relativePath: fileText:
45+
let
46+
file = builtins.toFile "codex-command-${name}-${lib.replaceStrings [ "/" ] [ "-" ] relativePath}" fileText;
47+
in
48+
''
49+
install -Dm0644 ${file} "$out/${relativePath}"
50+
''
51+
) commandFiles
52+
)
53+
)
4654
) aiTools.codex.commandSkillFiles;
55+
codexSkills = aiTools.codex.skillSources // codexCommandSkillDirs;
56+
codexCommandSkillCleanup = lib.concatMapStringsSep "\n" (
57+
name:
58+
let
59+
target = "${codexConfigPath}/skills/${name}";
60+
in
61+
''
62+
if [ -d ${lib.escapeShellArg target} ] && [ ! -L ${lib.escapeShellArg target} ]; then
63+
[ ! -L ${lib.escapeShellArg "${target}/SKILL.md"} ] || rm -f ${lib.escapeShellArg "${target}/SKILL.md"}
64+
[ ! -L ${lib.escapeShellArg "${target}/agents/openai.yaml"} ] || rm -f ${lib.escapeShellArg "${target}/agents/openai.yaml"}
65+
rmdir ${lib.escapeShellArg "${target}/agents"} 2>/dev/null || true
66+
rmdir ${lib.escapeShellArg target} 2>/dev/null || true
67+
fi
68+
''
69+
) codexCommandSkillNames;
4770
codexProfiles = {
4871
# Deep analysis and live-research mode. Intentionally expensive:
4972
# benchmark preference is GPT-5.5 xhigh for best pass rate.
@@ -124,7 +147,10 @@ in
124147
# codex bump does not block activation. The native-messaging manifest and
125148
# node_repl MCP server are managed declaratively below, so the installer's
126149
# manifest writes are redirected to a scratch root it may own.
127-
activation = lib.mkIf pkgs.stdenv.hostPlatform.isLinux {
150+
activation = {
151+
codexCommandSkillShape = lib.hm.dag.entryBefore [ "checkLinkTargets" ] codexCommandSkillCleanup;
152+
}
153+
// lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
128154
codexBrowserUseInstall = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
129155
run ${lib.getExe pkgs.khanelinix.codex-browser-use-linux-chromium} install \
130156
--codex-home ${codexConfigPath} \
@@ -134,7 +160,7 @@ in
134160
|| verboseEcho "codex-browser-use-linux-chromium install failed (non-fatal); run codex-browser-doctor"
135161
'';
136162
};
137-
file = codexAgentFiles // codexCommandFiles;
163+
file = codexAgentFiles;
138164
packages = lib.optionals pkgs.stdenv.hostPlatform.isLinux [
139165
pkgs.khanelinix.codex-browser-use-linux-chromium
140166
];
@@ -377,7 +403,7 @@ in
377403

378404
context = builtins.readFile aiTools.base;
379405
contextOverride = aiTools.codex.contextOverride;
380-
inherit (aiTools.codex) skills;
406+
skills = codexSkills;
381407
rules = import ./rules.nix;
382408
};
383409
};

0 commit comments

Comments
 (0)