Skip to content

Commit a68fedd

Browse files
authored
chore: adjust way skill dirs are whitelisted (#12026)
1 parent 015cd40 commit a68fedd

File tree

2 files changed

+64
-3
lines changed

2 files changed

+64
-3
lines changed

packages/opencode/src/skill/skill.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export namespace Skill {
5050

5151
export const state = Instance.state(async () => {
5252
const skills: Record<string, Info> = {}
53+
const dirs = new Set<string>()
5354

5455
const addSkill = async (match: string) => {
5556
const md = await ConfigMarkdown.parse(match).catch((err) => {
@@ -75,6 +76,8 @@ export namespace Skill {
7576
})
7677
}
7778

79+
dirs.add(path.dirname(match))
80+
7881
skills[parsed.data.name] = {
7982
name: parsed.data.name,
8083
description: parsed.data.description,
@@ -148,11 +151,9 @@ export namespace Skill {
148151
}
149152
}
150153

151-
const dirs = Array.from(new Set(Object.values(skills).map((item) => path.dirname(item.location))))
152-
153154
return {
154155
skills,
155-
dirs,
156+
dirs: Array.from(dirs),
156157
}
157158
})
158159

packages/opencode/test/skill/skill.test.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,3 +326,63 @@ description: A skill in the .agents/skills directory.
326326
},
327327
})
328328
})
329+
330+
test("properly resolves directories that skills live in", async () => {
331+
await using tmp = await tmpdir({
332+
git: true,
333+
init: async (dir) => {
334+
const opencodeSkillDir = path.join(dir, ".opencode", "skill", "agent-skill")
335+
const opencodeSkillsDir = path.join(dir, ".opencode", "skills", "agent-skill")
336+
const claudeDir = path.join(dir, ".claude", "skills", "claude-skill")
337+
const agentDir = path.join(dir, ".agents", "skills", "agent-skill")
338+
await Bun.write(
339+
path.join(claudeDir, "SKILL.md"),
340+
`---
341+
name: claude-skill
342+
description: A skill in the .claude/skills directory.
343+
---
344+
345+
# Claude Skill
346+
`,
347+
)
348+
await Bun.write(
349+
path.join(agentDir, "SKILL.md"),
350+
`---
351+
name: agent-skill
352+
description: A skill in the .agents/skills directory.
353+
---
354+
355+
# Agent Skill
356+
`,
357+
)
358+
await Bun.write(
359+
path.join(opencodeSkillDir, "SKILL.md"),
360+
`---
361+
name: opencode-skill
362+
description: A skill in the .opencode/skill directory.
363+
---
364+
365+
# OpenCode Skill
366+
`,
367+
)
368+
await Bun.write(
369+
path.join(opencodeSkillsDir, "SKILL.md"),
370+
`---
371+
name: opencode-skill
372+
description: A skill in the .opencode/skills directory.
373+
---
374+
375+
# OpenCode Skill
376+
`,
377+
)
378+
},
379+
})
380+
381+
await Instance.provide({
382+
directory: tmp.path,
383+
fn: async () => {
384+
const dirs = await Skill.dirs()
385+
expect(dirs.length).toBe(4)
386+
},
387+
})
388+
})

0 commit comments

Comments
 (0)