perf(skill): implement lazy content loading

- Add LazyContentLoader interface to LoadedSkill type
- Defer skill body loading until first use
- Cache loaded content for subsequent calls
- Reduce startup time by not reading full file contents

🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
YeonGyu-Kim
2026-01-04 21:43:28 +09:00
parent 97e51c42dc
commit b1f36d61a8
3 changed files with 49 additions and 9 deletions

View File

@@ -40,7 +40,13 @@ function formatSkillsXml(skills: SkillInfo[]): string {
return `\n\n<available_skills>\n${skillsXml}\n</available_skills>`
}
function extractSkillBody(skill: LoadedSkill): string {
async function extractSkillBody(skill: LoadedSkill): Promise<string> {
if (skill.lazyContent) {
const fullTemplate = await skill.lazyContent.load()
const templateMatch = fullTemplate.match(/<skill-instruction>([\s\S]*?)<\/skill-instruction>/)
return templateMatch ? templateMatch[1].trim() : fullTemplate
}
if (skill.path) {
const content = readFileSync(skill.path, "utf-8")
const { body } = parseFrontmatter(content)
@@ -145,7 +151,7 @@ export function createSkillTool(options: SkillLoadOptions = {}): ToolDefinition
throw new Error(`Skill "${args.name}" not found. Available skills: ${available || "none"}`)
}
const body = extractSkillBody(skill)
const body = await extractSkillBody(skill)
const dir = skill.path ? dirname(skill.path) : skill.resolvedPath || process.cwd()
const output = [