feat: expand skill command registration
This commit is contained in:
@@ -1,5 +1,24 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { resolveSkillCommandInvocation } from "./skill-commands.js";
|
||||
import { listSkillCommandsForAgents, resolveSkillCommandInvocation } from "./skill-commands.js";
|
||||
|
||||
async function writeSkill(params: {
|
||||
workspaceDir: string;
|
||||
dirName: string;
|
||||
name: string;
|
||||
description: string;
|
||||
}) {
|
||||
const { workspaceDir, dirName, name, description } = params;
|
||||
const skillDir = path.join(workspaceDir, "skills", dirName);
|
||||
await fs.mkdir(skillDir, { recursive: true });
|
||||
await fs.writeFile(
|
||||
path.join(skillDir, "SKILL.md"),
|
||||
`---\nname: ${name}\ndescription: ${description}\n---\n\n# ${name}\n`,
|
||||
"utf-8",
|
||||
);
|
||||
}
|
||||
|
||||
describe("resolveSkillCommandInvocation", () => {
|
||||
it("matches skill commands and parses args", () => {
|
||||
@@ -19,3 +38,44 @@ describe("resolveSkillCommandInvocation", () => {
|
||||
expect(invocation).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("listSkillCommandsForAgents", () => {
|
||||
it("merges command names across agents and de-duplicates", async () => {
|
||||
const baseDir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-skills-"));
|
||||
const mainWorkspace = path.join(baseDir, "main");
|
||||
const researchWorkspace = path.join(baseDir, "research");
|
||||
await writeSkill({
|
||||
workspaceDir: mainWorkspace,
|
||||
dirName: "demo",
|
||||
name: "demo-skill",
|
||||
description: "Demo skill",
|
||||
});
|
||||
await writeSkill({
|
||||
workspaceDir: researchWorkspace,
|
||||
dirName: "demo2",
|
||||
name: "demo-skill",
|
||||
description: "Demo skill 2",
|
||||
});
|
||||
await writeSkill({
|
||||
workspaceDir: researchWorkspace,
|
||||
dirName: "extra",
|
||||
name: "extra-skill",
|
||||
description: "Extra skill",
|
||||
});
|
||||
|
||||
const commands = listSkillCommandsForAgents({
|
||||
cfg: {
|
||||
agents: {
|
||||
list: [
|
||||
{ id: "main", workspace: mainWorkspace },
|
||||
{ id: "research", workspace: researchWorkspace },
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
const names = commands.map((entry) => entry.name);
|
||||
expect(names).toContain("demo_skill");
|
||||
expect(names).toContain("demo_skill_2");
|
||||
expect(names).toContain("extra_skill");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user