Skip to content

Commit 94cdf50

Browse files
feat: respect disable-model-invocation in SKILL.md frontmatter
Skills that set `disable-model-invocation: true` stay installed and manually invocable, but are no longer advertised to the model or loadable through the `skill` tool. - Add optional `disableModelInvocation` to the v1 and `SkillV2.Info` HTTP payloads and generated SDK skill lists, parsed from `disable-model-invocation` in `SKILL.md` frontmatter. - Omit flagged skills from the system prompt / skill guidance and reject them from the model-facing `skill` tool; they stay listed so users can still invoke them as slash commands. - No durable data or migration is affected; the field is optional and unset for existing skills. Closes anomalyco#34498
1 parent 2f17fc9 commit 94cdf50

15 files changed

Lines changed: 204 additions & 5 deletions

File tree

‎packages/client/src/generated/types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2533,6 +2533,7 @@ export type SkillsListOutput = {
25332533
readonly name: string
25342534
readonly description?: string
25352535
readonly slash?: boolean
2536+
readonly disableModelInvocation?: boolean
25362537
readonly location: string
25372538
readonly content: string
25382539
}>

‎packages/core/src/skill.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,19 @@ export type Source = typeof Source.Type
2727
export const Info = Skill.Info
2828
export type Info = Skill.Info
2929

30+
// Skills with `disable-model-invocation` stay in `list()` so they remain
31+
// reachable as slash commands, but never reach the model.
3032
export const available = (skills: ReadonlyArray<Info>, agent: AgentV2.Info) =>
31-
skills.filter((skill) => PermissionV2.evaluate("skill", skill.name, agent.permissions).effect !== "deny")
33+
skills.filter(
34+
(skill) =>
35+
!skill.disableModelInvocation && PermissionV2.evaluate("skill", skill.name, agent.permissions).effect !== "deny",
36+
)
3237

3338
const Frontmatter = Schema.Struct({
3439
name: Schema.String.pipe(Schema.optional),
3540
description: Schema.String.pipe(Schema.optional),
3641
slash: Schema.Boolean.pipe(Schema.optional),
42+
"disable-model-invocation": Schema.Boolean.pipe(Schema.optional),
3743
})
3844
const decodeFrontmatter = Schema.decodeUnknownOption(Frontmatter)
3945

@@ -96,6 +102,7 @@ const layer = Layer.effect(
96102
name,
97103
description: frontmatter.description,
98104
slash: frontmatter.slash,
105+
disableModelInvocation: frontmatter["disable-model-invocation"],
99106
location: AbsolutePath.make(filepath),
100107
content: markdown.content,
101108
})

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const layer = Layer.effectDiscard(
7171
Effect.gen(function* () {
7272
const current = yield* skills.list()
7373
const skill = current.find((skill) => skill.name === input.name)
74-
if (!skill) return yield* unableToLoad(input.name)
74+
if (!skill || skill.disableModelInvocation) return yield* unableToLoad(input.name)
7575
return yield* Effect.gen(function* () {
7676
yield* permission.assert({
7777
action: name,

‎packages/core/test/skill.test.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,39 @@ describe("SkillV2", () => {
122122
),
123123
),
124124
)
125+
126+
it.live("hides skills with disable-model-invocation from agents", () =>
127+
Effect.acquireRelease(
128+
Effect.promise(() => tmpdir()),
129+
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
130+
).pipe(
131+
Effect.flatMap((tmp) =>
132+
Effect.gen(function* () {
133+
yield* Effect.promise(async () => {
134+
await fs.mkdir(path.join(tmp.path, "internal"), { recursive: true })
135+
await fs.writeFile(
136+
path.join(tmp.path, "internal", "SKILL.md"),
137+
`---
138+
name: internal
139+
description: Only run this when invoked manually
140+
disable-model-invocation: true
141+
---
142+
# internal`,
143+
)
144+
})
145+
146+
const agents = yield* AgentV2.Service
147+
yield* agents.transform((editor) => editor.update(AgentV2.ID.make("build"), () => {}))
148+
149+
const skill = yield* SkillV2.Service
150+
yield* skill.transform((editor) => editor.source({ type: "directory", path: AbsolutePath.make(tmp.path) }))
151+
152+
const list = yield* skill.list()
153+
expect(list.map((item) => item.name)).toEqual(["internal"])
154+
expect(list[0].disableModelInvocation).toBe(true)
155+
expect(SkillV2.available(list, (yield* agents.get(AgentV2.ID.make("build")))!)).toEqual([])
156+
}),
157+
),
158+
),
159+
)
125160
})

‎packages/core/test/skill/guidance.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ const denied = SkillV2.Info.make({
2727
location: AbsolutePath.make(path.resolve("/skills/denied/SKILL.md")),
2828
content: "Denied guidance",
2929
})
30+
const manual = SkillV2.Info.make({
31+
name: "manual",
32+
description: "Only invoked by the user",
33+
disableModelInvocation: true,
34+
location: AbsolutePath.make(path.resolve("/skills/manual/SKILL.md")),
35+
content: "Manual guidance",
36+
})
3037

3138
const layer = (list: () => SkillV2.Info[]) =>
3239
AppNodeBuilder.build(SkillGuidance.node, [
@@ -71,6 +78,19 @@ describe("SkillGuidance", () => {
7178
}).pipe(Effect.provide(layer(() => skills)))
7279
})
7380

81+
it.effect("omits skills that disable model invocation", () => {
82+
const agent = AgentV2.Info.make(AgentV2.Info.empty(build))
83+
return Effect.gen(function* () {
84+
const guidance = yield* SkillGuidance.Service
85+
const baseline = (yield* guidance
86+
.load({ id: agent.id, info: agent })
87+
.pipe(Effect.flatMap(SystemContext.initialize))).baseline
88+
89+
expect(baseline).toContain("<name>effect</name>")
90+
expect(baseline).not.toContain("<name>manual</name>")
91+
}).pipe(Effect.provide(layer(() => [manual, effect])))
92+
})
93+
7494
it.effect("omits guidance when the selected agent denies all skills", () => {
7595
const agent = AgentV2.Info.make({
7696
...AgentV2.Info.empty(build),

‎packages/core/test/tool-skill.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,14 @@ describe("SkillTool", () => {
141141
call: { type: "tool-call", id: "call-flat-skill", name: "skill", input: { name: "public" } },
142142
}),
143143
).toEqual({ type: "text", value: SkillTool.toModelOutput(flat, []) })
144+
current = [{ ...info, disableModelInvocation: true }]
145+
expect(
146+
yield* executeTool(registry, {
147+
sessionID,
148+
...toolIdentity,
149+
call: { type: "tool-call", id: "call-manual-skill", name: "skill", input: { name: "effect" } },
150+
}),
151+
).toEqual({ type: "error", value: "Unable to load skill effect" })
144152
}).pipe(Effect.provide(skillToolLayer))
145153
}),
146154
),

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const CUSTOMIZE_OPENCODE_SKILL_BODY = SkillPlugin.CustomizeOpencodeContent
3737
export const Info = Schema.Struct({
3838
name: Schema.String,
3939
description: Schema.optional(Schema.String),
40+
disableModelInvocation: Schema.optional(Schema.Boolean),
4041
location: Schema.String,
4142
content: Schema.String,
4243
})
@@ -50,11 +51,14 @@ const Issue = Schema.StructWithRest(
5051
[Schema.Record(Schema.String, Schema.Unknown)],
5152
)
5253

53-
function isSkillFrontmatter(data: unknown): data is { name: string; description?: string } {
54+
function isSkillFrontmatter(
55+
data: unknown,
56+
): data is { name: string; description?: string; "disable-model-invocation"?: boolean } {
5457
return (
5558
isRecord(data) &&
5659
typeof data.name === "string" &&
57-
(data.description === undefined || typeof data.description === "string")
60+
(data.description === undefined || typeof data.description === "string") &&
61+
(data["disable-model-invocation"] === undefined || typeof data["disable-model-invocation"] === "boolean")
5862
)
5963
}
6064

@@ -134,6 +138,7 @@ const add = Effect.fnUntraced(function* (state: State, match: string, events: Ev
134138
state.skills[md.data.name] = {
135139
name: md.data.name,
136140
description: md.data.description,
141+
disableModelInvocation: md.data["disable-model-invocation"],
137142
location: match,
138143
content: md.content,
139144
}
@@ -307,9 +312,13 @@ const layer = Layer.effect(
307312
return (yield* InstanceState.get(discovered)).dirs
308313
})
309314

315+
// Skills with `disable-model-invocation` stay in `all()` so they remain
316+
// reachable as slash commands, but never reach the model.
310317
const available = Effect.fn("Skill.available")(function* (agent?: Agent.Info) {
311318
const s = yield* InstanceState.get(state)
312-
const list = Object.values(s.skills).toSorted((a, b) => a.name.localeCompare(b.name))
319+
const list = Object.values(s.skills)
320+
.filter((skill) => !skill.disableModelInvocation)
321+
.toSorted((a, b) => a.name.localeCompare(b.name))
313322
if (!agent) return list
314323
return list.filter((skill) => Permission.evaluate("skill", skill.name, agent.permission).action !== "deny")
315324
})

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ export const SkillTool = Tool.define(
2424
.require(params.name)
2525
.pipe(Effect.catchTag("Skill.NotFoundError", (error) => Effect.die(new Error(error.message))))
2626

27+
if (info.disableModelInvocation)
28+
return yield* Effect.die(
29+
new Error(`Skill "${info.name}" can only be invoked by the user and cannot be loaded with this tool.`),
30+
)
31+
2732
yield* ctx.ask({
2833
permission: "skill",
2934
patterns: [params.name],

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,34 @@ Instructions here.
242242
),
243243
)
244244

245+
it.live("hides skills with disable-model-invocation from agents", () =>
246+
provideTmpdirInstance(
247+
(dir) =>
248+
Effect.gen(function* () {
249+
yield* Effect.promise(() =>
250+
Bun.write(
251+
path.join(dir, ".opencode", "skill", "internal-skill", "SKILL.md"),
252+
`---
253+
name: internal-skill
254+
description: Only run this when invoked manually.
255+
disable-model-invocation: true
256+
---
257+
258+
# Internal Skill
259+
`,
260+
),
261+
)
262+
263+
const skill = yield* Skill.Service
264+
const all = (yield* skill.all()).filter((s) => s.location !== "<built-in>")
265+
expect(all.map((s) => s.name)).toEqual(["internal-skill"])
266+
expect(all[0].disableModelInvocation).toBe(true)
267+
expect((yield* skill.available()).map((s) => s.name)).not.toContain("internal-skill")
268+
}),
269+
{ git: true },
270+
),
271+
)
272+
245273
it.live("discovers skills from .claude/skills/ directory", () =>
246274
provideTmpdirInstance(
247275
(dir) =>

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,59 @@ Use this skill.
9393
}),
9494
)
9595

96+
it.instance("execute rejects skills with disable-model-invocation", () =>
97+
Effect.gen(function* () {
98+
const dir = (yield* TestInstance).directory
99+
yield* Effect.promise(() =>
100+
Bun.write(
101+
path.join(dir, ".opencode", "skill", "manual-skill", "SKILL.md"),
102+
`---
103+
name: manual-skill
104+
description: Only run this when invoked manually.
105+
disable-model-invocation: true
106+
---
107+
108+
# Manual Skill
109+
`,
110+
),
111+
)
112+
113+
const home = process.env.OPENCODE_TEST_HOME
114+
process.env.OPENCODE_TEST_HOME = dir
115+
yield* Effect.addFinalizer(() =>
116+
Effect.sync(() => {
117+
process.env.OPENCODE_TEST_HOME = home
118+
}),
119+
)
120+
121+
const registry = yield* ToolRegistry.Service
122+
const agent = { name: "build", mode: "primary" as const, permission: [], options: {} }
123+
const tool = (yield* registry.tools({
124+
providerID: "opencode" as any,
125+
modelID: "gpt-5" as any,
126+
agent,
127+
})).find((tool) => tool.id === SkillTool.id)
128+
if (!tool) throw new Error("Skill tool not found")
129+
130+
const exit = yield* tool
131+
.execute(
132+
{ name: "manual-skill" },
133+
{
134+
...baseCtx,
135+
ask: () => Effect.void,
136+
},
137+
)
138+
.pipe(Effect.exit)
139+
140+
expect(Exit.isFailure(exit)).toBe(true)
141+
if (Exit.isFailure(exit)) {
142+
const error = Cause.squash(exit.cause)
143+
expect(error).toBeInstanceOf(Error)
144+
if (error instanceof Error) expect(error.message).toContain('Skill "manual-skill" can only be invoked')
145+
}
146+
}),
147+
)
148+
96149
it.instance("execute preserves not found message", () =>
97150
Effect.gen(function* () {
98151
const dir = (yield* TestInstance).directory

0 commit comments

Comments
 (0)