2026-02-08 16:25:25 +09:00
|
|
|
import type { OhMyOpenCodeConfig } from "../config";
|
2026-04-08 16:00:47 +09:00
|
|
|
import {
|
|
|
|
|
getAgentConfigKey,
|
2026-04-11 22:01:42 +09:00
|
|
|
getAgentListDisplayName,
|
2026-04-08 16:00:47 +09:00
|
|
|
} from "../shared/agent-display-names";
|
2026-02-08 16:25:25 +09:00
|
|
|
import {
|
|
|
|
|
loadUserCommands,
|
|
|
|
|
loadProjectCommands,
|
|
|
|
|
loadOpencodeGlobalCommands,
|
|
|
|
|
loadOpencodeProjectCommands,
|
|
|
|
|
} from "../features/claude-code-command-loader";
|
|
|
|
|
import { loadBuiltinCommands } from "../features/builtin-commands";
|
|
|
|
|
import {
|
2026-02-13 11:08:22 +09:00
|
|
|
discoverConfigSourceSkills,
|
2026-03-26 12:15:47 +09:00
|
|
|
loadGlobalAgentsSkills,
|
|
|
|
|
loadProjectAgentsSkills,
|
2026-02-08 16:25:25 +09:00
|
|
|
loadUserSkills,
|
|
|
|
|
loadProjectSkills,
|
|
|
|
|
loadOpencodeGlobalSkills,
|
|
|
|
|
loadOpencodeProjectSkills,
|
2026-02-13 11:08:22 +09:00
|
|
|
skillsToCommandDefinitionRecord,
|
2026-02-08 16:25:25 +09:00
|
|
|
} from "../features/opencode-skill-loader";
|
2026-03-27 13:26:19 +01:00
|
|
|
import {
|
|
|
|
|
detectExternalSkillPlugin,
|
|
|
|
|
getSkillPluginConflictWarning,
|
|
|
|
|
log,
|
|
|
|
|
} from "../shared";
|
2026-02-08 16:25:25 +09:00
|
|
|
import type { PluginComponents } from "./plugin-components-loader";
|
2026-05-18 13:43:56 +09:00
|
|
|
import { adaptHostSkillConfig } from "../shared/host-skill-config";
|
2026-02-08 16:25:25 +09:00
|
|
|
|
|
|
|
|
export async function applyCommandConfig(params: {
|
|
|
|
|
config: Record<string, unknown>;
|
|
|
|
|
pluginConfig: OhMyOpenCodeConfig;
|
2026-02-13 11:08:22 +09:00
|
|
|
ctx: { directory: string };
|
2026-02-08 16:25:25 +09:00
|
|
|
pluginComponents: PluginComponents;
|
|
|
|
|
}): Promise<void> {
|
2026-04-01 17:32:46 -07:00
|
|
|
const builtinCommands = loadBuiltinCommands(params.pluginConfig.disabled_commands, {
|
|
|
|
|
useRegisteredAgents: true,
|
2026-04-28 10:47:31 +09:00
|
|
|
teamModeEnabled: params.pluginConfig.team_mode?.enabled ?? false,
|
2026-04-01 17:32:46 -07:00
|
|
|
});
|
2026-02-08 16:25:25 +09:00
|
|
|
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;
|
|
|
|
|
|
2026-03-27 13:26:19 +01:00
|
|
|
const externalSkillPlugin = detectExternalSkillPlugin(params.ctx.directory);
|
2026-05-15 16:31:13 +09:00
|
|
|
if (includeClaudeSkills && externalSkillPlugin.detected && externalSkillPlugin.pluginName) {
|
|
|
|
|
log(getSkillPluginConflictWarning(externalSkillPlugin.pluginName));
|
2026-03-27 13:26:19 +01:00
|
|
|
}
|
|
|
|
|
|
2026-05-18 13:43:56 +09:00
|
|
|
const hostSkillConfig = adaptHostSkillConfig(params.config.skills);
|
2026-02-08 16:25:25 +09:00
|
|
|
const [
|
2026-02-13 11:08:22 +09:00
|
|
|
configSourceSkills,
|
2026-05-18 13:43:56 +09:00
|
|
|
hostConfigSkills,
|
2026-02-08 16:25:25 +09:00
|
|
|
userCommands,
|
|
|
|
|
projectCommands,
|
|
|
|
|
opencodeGlobalCommands,
|
|
|
|
|
opencodeProjectCommands,
|
|
|
|
|
userSkills,
|
2026-03-26 12:15:47 +09:00
|
|
|
globalAgentsSkills,
|
2026-02-08 16:25:25 +09:00
|
|
|
projectSkills,
|
2026-03-26 12:15:47 +09:00
|
|
|
projectAgentsSkills,
|
2026-02-08 16:25:25 +09:00
|
|
|
opencodeGlobalSkills,
|
|
|
|
|
opencodeProjectSkills,
|
|
|
|
|
] = await Promise.all([
|
2026-02-13 11:08:22 +09:00
|
|
|
discoverConfigSourceSkills({
|
|
|
|
|
config: params.pluginConfig.skills,
|
|
|
|
|
configDir: params.ctx.directory,
|
|
|
|
|
}),
|
2026-05-18 13:43:56 +09:00
|
|
|
discoverConfigSourceSkills({
|
|
|
|
|
config: hostSkillConfig,
|
|
|
|
|
configDir: params.ctx.directory,
|
|
|
|
|
}),
|
2026-02-08 16:25:25 +09:00
|
|
|
includeClaudeCommands ? loadUserCommands() : Promise.resolve({}),
|
2026-02-13 11:09:35 +08:00
|
|
|
includeClaudeCommands ? loadProjectCommands(params.ctx.directory) : Promise.resolve({}),
|
2026-02-08 16:25:25 +09:00
|
|
|
loadOpencodeGlobalCommands(),
|
2026-02-13 11:09:35 +08:00
|
|
|
loadOpencodeProjectCommands(params.ctx.directory),
|
2026-02-08 16:25:25 +09:00
|
|
|
includeClaudeSkills ? loadUserSkills() : Promise.resolve({}),
|
2026-03-26 12:15:47 +09:00
|
|
|
includeClaudeSkills ? loadGlobalAgentsSkills() : Promise.resolve({}),
|
2026-02-13 11:09:35 +08:00
|
|
|
includeClaudeSkills ? loadProjectSkills(params.ctx.directory) : Promise.resolve({}),
|
2026-03-26 12:15:47 +09:00
|
|
|
includeClaudeSkills ? loadProjectAgentsSkills(params.ctx.directory) : Promise.resolve({}),
|
2026-02-08 16:25:25 +09:00
|
|
|
loadOpencodeGlobalSkills(),
|
2026-02-13 11:09:35 +08:00
|
|
|
loadOpencodeProjectSkills(params.ctx.directory),
|
2026-02-08 16:25:25 +09:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
params.config.command = {
|
|
|
|
|
...builtinCommands,
|
2026-02-13 11:08:22 +09:00
|
|
|
...skillsToCommandDefinitionRecord(configSourceSkills),
|
2026-05-18 13:43:56 +09:00
|
|
|
...skillsToCommandDefinitionRecord(hostConfigSkills),
|
2026-02-08 16:25:25 +09:00
|
|
|
...userCommands,
|
|
|
|
|
...userSkills,
|
2026-03-26 12:15:47 +09:00
|
|
|
...globalAgentsSkills,
|
2026-02-08 16:25:25 +09:00
|
|
|
...opencodeGlobalCommands,
|
|
|
|
|
...opencodeGlobalSkills,
|
|
|
|
|
...systemCommands,
|
|
|
|
|
...projectCommands,
|
|
|
|
|
...projectSkills,
|
2026-03-26 12:15:47 +09:00
|
|
|
...projectAgentsSkills,
|
2026-02-08 16:25:25 +09:00
|
|
|
...opencodeProjectCommands,
|
|
|
|
|
...opencodeProjectSkills,
|
|
|
|
|
...params.pluginComponents.commands,
|
|
|
|
|
...params.pluginComponents.skills,
|
|
|
|
|
};
|
2026-02-16 21:32:33 +09:00
|
|
|
|
|
|
|
|
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") {
|
2026-04-11 22:01:42 +09:00
|
|
|
cmd.agent = getAgentListDisplayName(getAgentConfigKey(cmd.agent));
|
2026-02-16 21:32:33 +09:00
|
|
|
}
|
|
|
|
|
}
|
2026-02-08 16:25:25 +09:00
|
|
|
}
|