Skip to content

Commit 0ed806d

Browse files
committed
fix: enforce skill deny pattern filtering
Fixes anomalyco#21793
1 parent fc36b7c commit 0ed806d

3 files changed

Lines changed: 61 additions & 28 deletions

File tree

‎packages/opencode/src/session/system.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export namespace SystemPrompt {
6464
if (Permission.disabled(["skill"], agent.permission).has("skill")) return
6565

6666
const list = await Skill.available(agent)
67+
if (list.length === 0) return
6768

6869
return [
6970
"Skills provide specialized instructions and workflows for specific tasks.",

‎packages/opencode/src/tool/skill.ts‎

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,24 @@ const Parameters = z.object({
1111
})
1212

1313
export const SkillTool = Tool.define("skill", async () => {
14-
const list = await Skill.available()
15-
16-
const description =
17-
list.length === 0
18-
? "Load a specialized skill that provides domain-specific instructions and workflows. No skills are currently available."
19-
: [
20-
"Load a specialized skill that provides domain-specific instructions and workflows.",
21-
"",
22-
"When you recognize that a task matches one of the available skills listed below, use this tool to load the full skill instructions.",
23-
"",
24-
"The skill will inject detailed instructions, workflows, and access to bundled resources (scripts, references, templates) into the conversation context.",
25-
"",
26-
'Tool output includes a `<skill_content name="...">` block with the loaded content.',
27-
"",
28-
"The following skills provide specialized sets of instructions for particular tasks",
29-
"Invoke this tool to load a skill when a task matches one of the available skills listed below:",
30-
"",
31-
Skill.fmt(list, { verbose: false }),
32-
].join("\n")
33-
3414
return {
35-
description,
15+
description: "",
3616
parameters: Parameters,
3717
async execute(params: z.infer<typeof Parameters>, ctx) {
38-
const skill = await Skill.get(params.name)
39-
40-
if (!skill) {
41-
const available = await Skill.all().then((x) => x.map((skill) => skill.name).join(", "))
42-
throw new Error(`Skill "${params.name}" not found. Available skills: ${available || "none"}`)
43-
}
44-
4518
await ctx.ask({
4619
permission: "skill",
4720
patterns: [params.name],
4821
always: [params.name],
4922
metadata: {},
5023
})
5124

25+
const skill = await Skill.get(params.name)
26+
27+
if (!skill) {
28+
const available = await Skill.all().then((x) => x.map((skill) => skill.name).join(", "))
29+
throw new Error(`Skill "${params.name}" not found. Available skills: ${available || "none"}`)
30+
}
31+
5232
const dir = path.dirname(skill.location)
5333
const base = pathToFileURL(dir).href
5434

‎packages/opencode/test/tool/skill.test.ts‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,58 @@ description: ${description}
120120
}
121121
})
122122

123+
test("description excludes denied skills by pattern", async () => {
124+
await using tmp = await tmpdir({
125+
git: true,
126+
init: async (dir) => {
127+
for (const [name, description] of [
128+
["lark-doc", "Lark doc skill."],
129+
["lark-mail", "Lark mail skill."],
130+
["safe-skill", "Safe skill."],
131+
]) {
132+
const skillDir = path.join(dir, ".opencode", "skill", name)
133+
await Bun.write(
134+
path.join(skillDir, "SKILL.md"),
135+
`---
136+
name: ${name}
137+
description: ${description}
138+
---
139+
140+
# ${name}
141+
`,
142+
)
143+
}
144+
},
145+
})
146+
147+
const home = process.env.OPENCODE_TEST_HOME
148+
process.env.OPENCODE_TEST_HOME = tmp.path
149+
150+
try {
151+
await Instance.provide({
152+
directory: tmp.path,
153+
fn: async () => {
154+
const desc = await ToolRegistry.tools({
155+
providerID: "opencode" as any,
156+
modelID: "gpt-5" as any,
157+
agent: {
158+
name: "build",
159+
mode: "primary" as const,
160+
permission: [{ permission: "skill", pattern: "lark-*", action: "deny" }],
161+
options: {},
162+
},
163+
}).then((tools) => tools.find((tool) => tool.id === SkillTool.id)?.description ?? "")
164+
165+
expect(desc).toContain("**safe-skill**: Safe skill.")
166+
expect(desc).not.toContain("**lark-doc**: Lark doc skill.")
167+
expect(desc).not.toContain("**lark-mail**: Lark mail skill.")
168+
},
169+
})
170+
} finally {
171+
process.env.OPENCODE_TEST_HOME = home
172+
}
173+
})
174+
123175
test("execute returns skill content block with files", async () => {
124176
await using tmp = await tmpdir({
125177
git: true,

0 commit comments

Comments
 (0)