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"; export async function applyCommandConfig(params: { config: Record; pluginConfig: OhMyOpenCodeConfig; ctx: { directory: string }; pluginComponents: PluginComponents; }): Promise { const builtinCommands = loadBuiltinCommands(params.pluginConfig.disabled_commands, { useRegisteredAgents: true, teamModeEnabled: params.pluginConfig.team_mode?.enabled ?? false, }); const systemCommands = (params.config.command as Record) ?? {}; const includeClaudeCommands = params.pluginConfig.claude_code?.commands ?? true; const includeClaudeSkills = params.pluginConfig.claude_code?.skills ?? true; const externalSkillPlugin = detectExternalSkillPlugin(params.ctx.directory); if (includeClaudeSkills && externalSkillPlugin.detected && externalSkillPlugin.pluginName) { log(getSkillPluginConflictWarning(externalSkillPlugin.pluginName)); } const [ configSourceSkills, userCommands, projectCommands, opencodeGlobalCommands, opencodeProjectCommands, userSkills, globalAgentsSkills, projectSkills, projectAgentsSkills, opencodeGlobalSkills, opencodeProjectSkills, ] = await Promise.all([ discoverConfigSourceSkills({ config: params.pluginConfig.skills, 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), ...userCommands, ...userSkills, ...globalAgentsSkills, ...opencodeGlobalCommands, ...opencodeGlobalSkills, ...systemCommands, ...projectCommands, ...projectSkills, ...projectAgentsSkills, ...opencodeProjectCommands, ...opencodeProjectSkills, ...params.pluginComponents.commands, ...params.pluginComponents.skills, }; remapCommandAgentFields(params.config.command as Record>); } function remapCommandAgentFields(commands: Record>): void { for (const cmd of Object.values(commands)) { if (cmd?.agent && typeof cmd.agent === "string") { cmd.agent = getAgentListDisplayName(getAgentConfigKey(cmd.agent)); } } }