feat: add skill filter + group system prompt plumbing

This commit is contained in:
Peter Steinberger
2026-01-07 11:22:55 +01:00
parent 9bf6684366
commit 61f720b945
6 changed files with 81 additions and 6 deletions

View File

@@ -165,6 +165,33 @@ describe("buildWorkspaceSkillsPrompt", () => {
}
});
it("applies skill filters, including empty lists", async () => {
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-"));
await writeSkill({
dir: path.join(workspaceDir, "skills", "alpha"),
name: "alpha",
description: "Alpha skill",
});
await writeSkill({
dir: path.join(workspaceDir, "skills", "beta"),
name: "beta",
description: "Beta skill",
});
const filteredPrompt = buildWorkspaceSkillsPrompt(workspaceDir, {
managedSkillsDir: path.join(workspaceDir, ".managed"),
skillFilter: ["alpha"],
});
expect(filteredPrompt).toContain("alpha");
expect(filteredPrompt).not.toContain("beta");
const emptyPrompt = buildWorkspaceSkillsPrompt(workspaceDir, {
managedSkillsDir: path.join(workspaceDir, ".managed"),
skillFilter: [],
});
expect(emptyPrompt).toBe("");
});
it("prefers workspace skills over managed skills", async () => {
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-"));
const managedDir = path.join(workspaceDir, ".managed");

View File

@@ -382,8 +382,27 @@ function shouldIncludeSkill(params: {
function filterSkillEntries(
entries: SkillEntry[],
config?: ClawdbotConfig,
skillFilter?: string[],
): SkillEntry[] {
return entries.filter((entry) => shouldIncludeSkill({ entry, config }));
let filtered = entries.filter((entry) =>
shouldIncludeSkill({ entry, config }),
);
// If skillFilter is provided, only include skills in the filter list.
if (skillFilter !== undefined) {
const normalized = skillFilter
.map((entry) => String(entry).trim())
.filter(Boolean);
const label = normalized.length > 0 ? normalized.join(", ") : "(none)";
console.log(`[skills] Applying skill filter: ${label}`);
filtered =
normalized.length > 0
? filtered.filter((entry) => normalized.includes(entry.skill.name))
: [];
console.log(
`[skills] After filter: ${filtered.map((entry) => entry.skill.name).join(", ")}`,
);
}
return filtered;
}
export function applySkillEnvOverrides(params: {
@@ -548,10 +567,16 @@ export function buildWorkspaceSkillSnapshot(
managedSkillsDir?: string;
bundledSkillsDir?: string;
entries?: SkillEntry[];
/** If provided, only include skills with these names */
skillFilter?: string[];
},
): SkillSnapshot {
const skillEntries = opts?.entries ?? loadSkillEntries(workspaceDir, opts);
const eligible = filterSkillEntries(skillEntries, opts?.config);
const eligible = filterSkillEntries(
skillEntries,
opts?.config,
opts?.skillFilter,
);
const resolvedSkills = eligible.map((entry) => entry.skill);
return {
prompt: formatSkillsForPrompt(resolvedSkills),
@@ -570,10 +595,16 @@ export function buildWorkspaceSkillsPrompt(
managedSkillsDir?: string;
bundledSkillsDir?: string;
entries?: SkillEntry[];
/** If provided, only include skills with these names */
skillFilter?: string[];
},
): string {
const skillEntries = opts?.entries ?? loadSkillEntries(workspaceDir, opts);
const eligible = filterSkillEntries(skillEntries, opts?.config);
const eligible = filterSkillEntries(
skillEntries,
opts?.config,
opts?.skillFilter,
);
return formatSkillsForPrompt(eligible.map((entry) => entry.skill));
}