-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Expand file tree
/
Copy pathcommand-config-handler.ts
More file actions
113 lines (106 loc) · 3.8 KB
/
command-config-handler.ts
File metadata and controls
113 lines (106 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import type { OhMyOpenCodeConfig } from "../config";
import {
getAgentConfigKey,
getAgentListDisplayName,
} from "../shared/agent-display-names";
import {
loadUserCommands,
loadProjectCommands,
loadOpencodeGlobalCommands,
loadOpencodeProjectCommands,
} from "../features/claude-code-command-loader";
import { loadBuiltinCommands } from "../features/builtin-commands";
import {
discoverConfigSourceSkills,
loadGlobalAgentsSkills,
loadProjectAgentsSkills,
loadUserSkills,
loadProjectSkills,
loadOpencodeGlobalSkills,
loadOpencodeProjectSkills,
skillsToCommandDefinitionRecord,
} from "../features/opencode-skill-loader";
import {
detectExternalSkillPlugin,
getSkillPluginConflictWarning,
log,
} from "../shared";
import type { PluginComponents } from "./plugin-components-loader";
import { adaptHostSkillConfig } from "../shared/host-skill-config";
export async function applyCommandConfig(params: {
config: Record<string, unknown>;
pluginConfig: OhMyOpenCodeConfig;
ctx: { directory: string };
pluginComponents: PluginComponents;
}): Promise<void> {
const builtinCommands = loadBuiltinCommands(params.pluginConfig.disabled_commands, {
useRegisteredAgents: true,
});
const systemCommands = (params.config.command as Record<string, unknown>) ?? {};
const includeClaudeCommands = params.pluginConfig.claude_code?.commands ?? true;
const includeClaudeSkills = params.pluginConfig.claude_code?.skills ?? true;
const hostSkillConfig = adaptHostSkillConfig(params.config.skills);
const externalSkillPlugin = detectExternalSkillPlugin(params.ctx.directory);
if (includeClaudeSkills && externalSkillPlugin.detected) {
log(getSkillPluginConflictWarning(externalSkillPlugin.pluginName!));
}
const [
configSourceSkills,
hostConfigSourceSkills,
userCommands,
projectCommands,
opencodeGlobalCommands,
opencodeProjectCommands,
userSkills,
globalAgentsSkills,
projectSkills,
projectAgentsSkills,
opencodeGlobalSkills,
opencodeProjectSkills,
] = await Promise.all([
discoverConfigSourceSkills({
config: params.pluginConfig.skills,
configDir: params.ctx.directory,
}),
discoverConfigSourceSkills({
config: hostSkillConfig,
configDir: params.ctx.directory,
}),
includeClaudeCommands ? loadUserCommands() : Promise.resolve({}),
includeClaudeCommands ? loadProjectCommands(params.ctx.directory) : Promise.resolve({}),
loadOpencodeGlobalCommands(),
loadOpencodeProjectCommands(params.ctx.directory),
includeClaudeSkills ? loadUserSkills() : Promise.resolve({}),
includeClaudeSkills ? loadGlobalAgentsSkills() : Promise.resolve({}),
includeClaudeSkills ? loadProjectSkills(params.ctx.directory) : Promise.resolve({}),
includeClaudeSkills ? loadProjectAgentsSkills(params.ctx.directory) : Promise.resolve({}),
loadOpencodeGlobalSkills(),
loadOpencodeProjectSkills(params.ctx.directory),
]);
params.config.command = {
...builtinCommands,
...skillsToCommandDefinitionRecord(configSourceSkills),
...skillsToCommandDefinitionRecord(hostConfigSourceSkills),
...userCommands,
...userSkills,
...globalAgentsSkills,
...opencodeGlobalCommands,
...opencodeGlobalSkills,
...systemCommands,
...projectCommands,
...projectSkills,
...projectAgentsSkills,
...opencodeProjectCommands,
...opencodeProjectSkills,
...params.pluginComponents.commands,
...params.pluginComponents.skills,
};
remapCommandAgentFields(params.config.command as Record<string, Record<string, unknown>>);
}
function remapCommandAgentFields(commands: Record<string, Record<string, unknown>>): void {
for (const cmd of Object.values(commands)) {
if (cmd?.agent && typeof cmd.agent === "string") {
cmd.agent = getAgentListDisplayName(getAgentConfigKey(cmd.agent));
}
}
}