feat: tool-dispatch skill commands
This commit is contained in:
@@ -89,4 +89,18 @@ describe("buildWorkspaceSkillCommandSpecs", () => {
|
||||
expect(longCmd?.description.endsWith("…")).toBe(true);
|
||||
expect(shortCmd?.description).toBe("Short description");
|
||||
});
|
||||
|
||||
it("includes tool-dispatch metadata from frontmatter", async () => {
|
||||
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-"));
|
||||
await writeSkill({
|
||||
dir: path.join(workspaceDir, "skills", "tool-dispatch"),
|
||||
name: "tool-dispatch",
|
||||
description: "Dispatch to a tool",
|
||||
frontmatterExtra: "command-dispatch: tool\ncommand-tool: sessions_send",
|
||||
});
|
||||
|
||||
const commands = buildWorkspaceSkillCommandSpecs(workspaceDir);
|
||||
const cmd = commands.find((entry) => entry.skillName === "tool-dispatch");
|
||||
expect(cmd?.dispatch).toEqual({ kind: "tool", toolName: "sessions_send", argMode: "raw" });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -31,10 +31,23 @@ export type SkillInvocationPolicy = {
|
||||
disableModelInvocation: boolean;
|
||||
};
|
||||
|
||||
export type SkillCommandDispatchSpec = {
|
||||
kind: "tool";
|
||||
/** Name of the tool to invoke (AnyAgentTool.name). */
|
||||
toolName: string;
|
||||
/**
|
||||
* How to forward user-provided args to the tool.
|
||||
* - raw: forward the raw args string (no core parsing).
|
||||
*/
|
||||
argMode?: "raw";
|
||||
};
|
||||
|
||||
export type SkillCommandSpec = {
|
||||
name: string;
|
||||
skillName: string;
|
||||
description: string;
|
||||
/** Optional deterministic dispatch behavior for this command. */
|
||||
dispatch?: SkillCommandDispatchSpec;
|
||||
};
|
||||
|
||||
export type SkillsInstallPreferences = {
|
||||
|
||||
@@ -357,10 +357,55 @@ export function buildWorkspaceSkillCommandSpecs(
|
||||
rawDescription.length > SKILL_COMMAND_DESCRIPTION_MAX_LENGTH
|
||||
? rawDescription.slice(0, SKILL_COMMAND_DESCRIPTION_MAX_LENGTH - 1) + "…"
|
||||
: rawDescription;
|
||||
const dispatch = (() => {
|
||||
const kindRaw = (
|
||||
entry.frontmatter?.["command-dispatch"] ??
|
||||
entry.frontmatter?.["command_dispatch"] ??
|
||||
""
|
||||
)
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
if (!kindRaw) return undefined;
|
||||
if (kindRaw !== "tool") return undefined;
|
||||
|
||||
const toolName = (
|
||||
entry.frontmatter?.["command-tool"] ??
|
||||
entry.frontmatter?.["command_tool"] ??
|
||||
""
|
||||
).trim();
|
||||
if (!toolName) {
|
||||
debugSkillCommandOnce(
|
||||
`dispatch:missingTool:${rawName}`,
|
||||
`Skill command "/${unique}" requested tool dispatch but did not provide command-tool. Ignoring dispatch.`,
|
||||
{ skillName: rawName, command: unique },
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const argModeRaw = (
|
||||
entry.frontmatter?.["command-arg-mode"] ??
|
||||
entry.frontmatter?.["command_arg_mode"] ??
|
||||
""
|
||||
)
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
const argMode = !argModeRaw || argModeRaw === "raw" ? "raw" : null;
|
||||
if (!argMode) {
|
||||
debugSkillCommandOnce(
|
||||
`dispatch:badArgMode:${rawName}:${argModeRaw}`,
|
||||
`Skill command "/${unique}" requested tool dispatch but has unknown command-arg-mode. Falling back to raw.`,
|
||||
{ skillName: rawName, command: unique, argMode: argModeRaw },
|
||||
);
|
||||
}
|
||||
|
||||
return { kind: "tool", toolName, argMode: "raw" } as const;
|
||||
})();
|
||||
|
||||
specs.push({
|
||||
name: unique,
|
||||
skillName: rawName,
|
||||
description,
|
||||
...(dispatch ? { dispatch } : {}),
|
||||
});
|
||||
}
|
||||
return specs;
|
||||
|
||||
Reference in New Issue
Block a user