refactor(loaders): migrate to async-first pattern for commands and skills
- Remove all sync functions from command loader (async now default) - Remove sync load functions from skill loader (async now default) - Add resolveSymlinkAsync to file-utils.ts - Update all callers to use async versions: - config-handler.ts - index.ts - tools/slashcommand/tools.ts - tools/skill/tools.ts - hooks/auto-slash-command/executor.ts - loader.test.ts - All 607 tests pass, build succeeds Generated with assistance of 🤖 [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
@@ -129,22 +129,38 @@ async function formatMcpCapabilities(
|
||||
}
|
||||
|
||||
export function createSkillTool(options: SkillLoadOptions = {}): ToolDefinition {
|
||||
const skills = options.skills ?? discoverSkills({ includeClaudeCodePaths: !options.opencodeOnly })
|
||||
const skillInfos = skills.map(loadedSkillToInfo)
|
||||
let cachedSkills: LoadedSkill[] | null = null
|
||||
let cachedDescription: string | null = null
|
||||
|
||||
const description = skillInfos.length === 0
|
||||
? TOOL_DESCRIPTION_NO_SKILLS
|
||||
: TOOL_DESCRIPTION_PREFIX + formatSkillsXml(skillInfos)
|
||||
const getSkills = async (): Promise<LoadedSkill[]> => {
|
||||
if (options.skills) return options.skills
|
||||
if (cachedSkills) return cachedSkills
|
||||
cachedSkills = await discoverSkills({ includeClaudeCodePaths: !options.opencodeOnly })
|
||||
return cachedSkills
|
||||
}
|
||||
|
||||
const getDescription = async (): Promise<string> => {
|
||||
if (cachedDescription) return cachedDescription
|
||||
const skills = await getSkills()
|
||||
const skillInfos = skills.map(loadedSkillToInfo)
|
||||
cachedDescription = skillInfos.length === 0
|
||||
? TOOL_DESCRIPTION_NO_SKILLS
|
||||
: TOOL_DESCRIPTION_PREFIX + formatSkillsXml(skillInfos)
|
||||
return cachedDescription
|
||||
}
|
||||
|
||||
getDescription()
|
||||
|
||||
return tool({
|
||||
description,
|
||||
get description() {
|
||||
return cachedDescription ?? TOOL_DESCRIPTION_PREFIX
|
||||
},
|
||||
args: {
|
||||
name: tool.schema.string().describe("The skill identifier from available_skills (e.g., 'code-review')"),
|
||||
},
|
||||
async execute(args: SkillArgs) {
|
||||
const skill = options.skills
|
||||
? skills.find(s => s.name === args.name)
|
||||
: skills.find(s => s.name === args.name)
|
||||
const skills = await getSkills()
|
||||
const skill = skills.find(s => s.name === args.name)
|
||||
|
||||
if (!skill) {
|
||||
const available = skills.map(s => s.name).join(", ")
|
||||
|
||||
@@ -83,19 +83,6 @@ function skillToCommandInfo(skill: LoadedSkill): CommandInfo {
|
||||
}
|
||||
}
|
||||
|
||||
const availableCommands = discoverCommandsSync()
|
||||
const availableSkills = discoverAllSkills()
|
||||
const availableItems = [
|
||||
...availableCommands,
|
||||
...availableSkills.map(skillToCommandInfo),
|
||||
]
|
||||
const commandListForDescription = availableItems
|
||||
.map((cmd) => {
|
||||
const hint = cmd.metadata.argumentHint ? ` ${cmd.metadata.argumentHint}` : ""
|
||||
return `- /${cmd.name}${hint}: ${cmd.metadata.description} (${cmd.scope})`
|
||||
})
|
||||
.join("\n")
|
||||
|
||||
async function formatLoadedCommand(cmd: CommandInfo): Promise<string> {
|
||||
const sections: string[] = []
|
||||
|
||||
@@ -151,15 +138,40 @@ function formatCommandList(items: CommandInfo[]): string {
|
||||
return lines.join("\n")
|
||||
}
|
||||
|
||||
export const slashcommand: ToolDefinition = tool({
|
||||
description: `Load a skill to get detailed instructions for a specific task.
|
||||
async function buildDescription(): Promise<string> {
|
||||
const availableCommands = discoverCommandsSync()
|
||||
const availableSkills = await discoverAllSkills()
|
||||
const availableItems = [
|
||||
...availableCommands,
|
||||
...availableSkills.map(skillToCommandInfo),
|
||||
]
|
||||
const commandListForDescription = availableItems
|
||||
.map((cmd) => {
|
||||
const hint = cmd.metadata.argumentHint ? ` ${cmd.metadata.argumentHint}` : ""
|
||||
return `- /${cmd.name}${hint}: ${cmd.metadata.description} (${cmd.scope})`
|
||||
})
|
||||
.join("\n")
|
||||
|
||||
return `Load a skill to get detailed instructions for a specific task.
|
||||
|
||||
Skills provide specialized knowledge and step-by-step guidance.
|
||||
Use this when a task matches an available skill's description.
|
||||
|
||||
<available_skills>
|
||||
${commandListForDescription}
|
||||
</available_skills>`,
|
||||
</available_skills>`
|
||||
}
|
||||
|
||||
let cachedDescription: string | null = null
|
||||
|
||||
export const slashcommand: ToolDefinition = tool({
|
||||
get description() {
|
||||
if (!cachedDescription) {
|
||||
cachedDescription = "Loading available commands and skills..."
|
||||
buildDescription().then(desc => { cachedDescription = desc })
|
||||
}
|
||||
return cachedDescription
|
||||
},
|
||||
|
||||
args: {
|
||||
command: tool.schema
|
||||
@@ -171,7 +183,7 @@ ${commandListForDescription}
|
||||
|
||||
async execute(args) {
|
||||
const commands = discoverCommandsSync()
|
||||
const skills = discoverAllSkills()
|
||||
const skills = await discoverAllSkills()
|
||||
const allItems = [
|
||||
...commands,
|
||||
...skills.map(skillToCommandInfo),
|
||||
|
||||
Reference in New Issue
Block a user