Skip to content

Commit 18163ba

Browse files
authored
feat(skills): resolve explicit $skill references on every channel (#123387)
* feat(skills): resolve explicit $skill references on every channel Explicit $skill-name references from authorized senders now resolve on all channels, not only WebChat/Control UI, and explicitly referenced skills are always invoked: disable-model-invocation keeps a skill out of model-initiated selection but no longer blocks user-initiated explicit references. Hidden skills carry their SKILL.md path in the injected instruction since the model cannot discover them from the available-skills prompt. Part of #123367 * fix(ci): dedupe run-attempt-state vitest lane ownership Main is red on the full-suite ownership audit from the #123235 x #123363 double-registration race. Keep run-attempt-state.test.ts beside its run-attempt siblings in the extra lane and heal the audit here per the land-onto-red-main policy.
1 parent 438d035 commit 18163ba

5 files changed

Lines changed: 36 additions & 25 deletions

File tree

‎docs/tools/skills.md‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,22 +155,21 @@ reference more than one skill:
155155
Use $github and $release_notes to summarize this change for the release.
156156
```
157157

158-
OpenClaw resolves these references against the current agent's eligible,
159-
user-invocable, model-visible skills and tells the model to read each referenced `SKILL.md`
160-
before acting. A single message can reference up to eight distinct skills;
158+
OpenClaw resolves explicit references from authorized senders on every channel
159+
against the current agent's eligible, user-invocable skills and tells the model
160+
to read each referenced `SKILL.md` before acting. A single message can reference up to eight distinct skills;
161161
OpenClaw returns a visible error instead of ignoring extra references. The `$`
162162
form is composable prompt text; `/release_notes ...`
163163
remains the standalone command form and may use direct tool dispatch when the
164164
skill declares `command-dispatch: tool`. Common uppercase shell variables such
165165
as `$HOME`, `$PATH`, and `$EDITOR` remain ordinary text; use lowercase
166-
`$home`, `$path`, or `$editor` to reference skills with those names.
166+
`$home`, `$path`, or `$editor` to reference skills with those names. Escape a
167+
reference as `\$name` when it should stay literal.
167168

168-
Skills with `disable-model-invocation: true` stay out of the `$` picker because
169-
their instructions are intentionally absent from the model's prompt. Invoke
170-
those explicitly with their standalone slash command instead.
171-
172-
`$` references are interpreted on WebChat/Control UI turns. Other messaging
173-
channels keep `$name` as ordinary text; use the skill's slash command there.
169+
Skills with `disable-model-invocation: true` stay out of the `$` picker and the
170+
model's normal prompt, so the model cannot select them on its own. An authorized
171+
explicit `$skill-name` reference still invokes them; the flag only hides the
172+
skill from model-initiated selection.
174173

175174
## Skill Workshop
176175

‎src/auto-reply/reply/get-reply-inline-actions.skip-when-config-empty.test.ts‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ describe("handleInlineActions", () => {
889889
expect(handleCommandsMock).not.toHaveBeenCalled();
890890
});
891891

892-
it("keeps $ skill references literal on message channels", async () => {
892+
it("resolves authorized $ skill references on message channels", async () => {
893893
const typing = createTypingController();
894894
const original = "Review with $office_hours.";
895895
const ctx = buildTestCtx({ Body: original, CommandBody: original });
@@ -911,18 +911,27 @@ describe("handleInlineActions", () => {
911911
name: "office_hours",
912912
skillName: "office-hours",
913913
description: "Engineering office hours",
914-
modelVisible: true,
914+
modelVisible: false,
915+
skillFile: "/tmp/skills/office-hours/SKILL.md",
915916
},
916917
],
917918
},
918919
});
919920

920921
expect(result.kind).toBe("continue");
921922
if (result.kind !== "continue") {
922-
throw new Error("expected message-channel text to continue unchanged");
923+
throw new Error("expected referenced skill to continue to the model");
923924
}
924-
expect(result.cleanedBody).toBe(original);
925-
expect(ctx.Body).toBe(original);
925+
expect(result.cleanedBody).toBe(
926+
[
927+
"Use the following explicitly referenced skills for this request. Read each skill's SKILL.md before acting:",
928+
"- office-hours (SKILL.md: /tmp/skills/office-hours/SKILL.md)",
929+
"",
930+
"User request:",
931+
original,
932+
].join("\n"),
933+
);
934+
expect(ctx.Body).toBe(result.cleanedBody);
926935
});
927936

928937
it("reloads preloaded skill commands when final exec overrides are present", async () => {

‎src/auto-reply/reply/get-reply-inline-actions.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
resolveSkillReferenceInvocations,
2121
} from "../../skills/discovery/chat-commands.js";
2222
import type { SkillCommandSpec } from "../../skills/types.js";
23-
import { INTERNAL_MESSAGE_CHANNEL } from "../../utils/message-channel.js";
2423
import {
2524
copyReplyPayloadMetadata,
2625
markCommandReplyForDelivery,
@@ -134,7 +133,13 @@ function applyExplicitSkillReferences(
134133
}
135134
const instruction = [
136135
"Use the following explicitly referenced skills for this request. Read each skill's SKILL.md before acting:",
137-
...skills.map((skill) => `- ${skill.skillName}`),
136+
// Hidden skills are absent from the available-skills prompt, so explicit invocation
137+
// carries the SKILL.md path the model needs to load them.
138+
...skills.map((skill) =>
139+
skill.modelVisible === false && skill.skillFile
140+
? `- ${skill.skillName} (SKILL.md: ${skill.skillFile})`
141+
: `- ${skill.skillName}`,
142+
),
138143
"",
139144
"User request:",
140145
body,
@@ -352,9 +357,7 @@ export async function handleInlineActions(params: {
352357

353358
const slashCommandName = resolveSlashCommandName(command.commandBodyNormalized);
354359
const hasSkillReferences =
355-
command.isAuthorizedSender &&
356-
ctx.Surface === INTERNAL_MESSAGE_CHANNEL &&
357-
hasSkillReferenceCandidate(initialCleanedBody);
360+
command.isAuthorizedSender && hasSkillReferenceCandidate(initialCleanedBody);
358361
const shouldLoadSkillCommands =
359362
allowTextCommands &&
360363
(hasSkillReferences ||

‎src/skills/discovery/chat-command-invocation.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export function resolveSkillReferenceInvocations(params: {
111111
continue;
112112
}
113113
const command = findSkillCommand(params.skillCommands, name);
114-
if (!command || command.modelVisible === false || seen.has(command.name)) {
114+
if (!command || seen.has(command.name)) {
115115
continue;
116116
}
117117
seen.add(command.name);

‎src/skills/discovery/chat-commands.test.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ describe("resolveSkillReferenceInvocations", () => {
264264
it("ignores common shell variables, escaped references, and unknown names", () => {
265265
expect(
266266
resolveSkillReferenceInvocations({
267-
text: String.raw`Keep $HOME and \$demo_skill literal; $unknown is not installed.`,
267+
text: String.raw`Keep $PATH and \$demo_skill literal; $unknown is not installed.`,
268268
skillCommands,
269269
}),
270270
).toEqual([]);
@@ -288,7 +288,7 @@ describe("resolveSkillReferenceInvocations", () => {
288288
).toEqual(["demo_skill"]);
289289
});
290290

291-
it("excludes slash-only skills that are hidden from the model prompt", () => {
291+
it("resolves explicitly referenced skills hidden from the model prompt", () => {
292292
expect(
293293
resolveSkillReferenceInvocations({
294294
text: "Use $hidden_skill.",
@@ -300,8 +300,8 @@ describe("resolveSkillReferenceInvocations", () => {
300300
modelVisible: false,
301301
},
302302
],
303-
}),
304-
).toEqual([]);
303+
}).map((command) => command.name),
304+
).toEqual(["hidden_skill"]);
305305
});
306306
});
307307

0 commit comments

Comments
 (0)