feat(skills): load bundled skills
This commit is contained in:
@@ -40,11 +40,33 @@ describe("buildWorkspaceSkillsPrompt", () => {
|
||||
|
||||
const prompt = buildWorkspaceSkillsPrompt(workspaceDir, {
|
||||
managedSkillsDir: path.join(workspaceDir, ".managed"),
|
||||
bundledSkillsDir: path.join(workspaceDir, ".bundled"),
|
||||
});
|
||||
|
||||
expect(prompt).toBe("");
|
||||
});
|
||||
|
||||
it("loads bundled skills when present", async () => {
|
||||
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdis-"));
|
||||
const bundledDir = path.join(workspaceDir, ".bundled");
|
||||
const bundledSkillDir = path.join(bundledDir, "peekaboo");
|
||||
|
||||
await writeSkill({
|
||||
dir: bundledSkillDir,
|
||||
name: "peekaboo",
|
||||
description: "Capture UI",
|
||||
body: "# Peekaboo\n",
|
||||
});
|
||||
|
||||
const prompt = buildWorkspaceSkillsPrompt(workspaceDir, {
|
||||
managedSkillsDir: path.join(workspaceDir, ".managed"),
|
||||
bundledSkillsDir: bundledDir,
|
||||
});
|
||||
expect(prompt).toContain("peekaboo");
|
||||
expect(prompt).toContain("Capture UI");
|
||||
expect(prompt).toContain(path.join(bundledSkillDir, "SKILL.md"));
|
||||
});
|
||||
|
||||
it("loads skills from workspace skills/", async () => {
|
||||
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdis-"));
|
||||
const skillDir = path.join(workspaceDir, "skills", "demo-skill");
|
||||
@@ -100,9 +122,17 @@ describe("buildWorkspaceSkillsPrompt", () => {
|
||||
it("prefers workspace skills over managed skills", async () => {
|
||||
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdis-"));
|
||||
const managedDir = path.join(workspaceDir, ".managed");
|
||||
const bundledDir = path.join(workspaceDir, ".bundled");
|
||||
const managedSkillDir = path.join(managedDir, "demo-skill");
|
||||
const bundledSkillDir = path.join(bundledDir, "demo-skill");
|
||||
const workspaceSkillDir = path.join(workspaceDir, "skills", "demo-skill");
|
||||
|
||||
await writeSkill({
|
||||
dir: bundledSkillDir,
|
||||
name: "demo-skill",
|
||||
description: "Bundled version",
|
||||
body: "# Bundled\n",
|
||||
});
|
||||
await writeSkill({
|
||||
dir: managedSkillDir,
|
||||
name: "demo-skill",
|
||||
@@ -118,11 +148,13 @@ describe("buildWorkspaceSkillsPrompt", () => {
|
||||
|
||||
const prompt = buildWorkspaceSkillsPrompt(workspaceDir, {
|
||||
managedSkillsDir: managedDir,
|
||||
bundledSkillsDir: bundledDir,
|
||||
});
|
||||
|
||||
expect(prompt).toContain("Workspace version");
|
||||
expect(prompt).toContain(path.join(workspaceSkillDir, "SKILL.md"));
|
||||
expect(prompt).not.toContain(path.join(managedSkillDir, "SKILL.md"));
|
||||
expect(prompt).not.toContain(path.join(bundledSkillDir, "SKILL.md"));
|
||||
});
|
||||
|
||||
it("gates by bins, config, and always", async () => {
|
||||
@@ -212,6 +244,7 @@ describe("buildWorkspaceSkillSnapshot", () => {
|
||||
|
||||
const snapshot = buildWorkspaceSkillSnapshot(workspaceDir, {
|
||||
managedSkillsDir: path.join(workspaceDir, ".managed"),
|
||||
bundledSkillsDir: path.join(workspaceDir, ".bundled"),
|
||||
});
|
||||
|
||||
expect(snapshot.prompt).toBe("");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import {
|
||||
formatSkillsForPrompt,
|
||||
@@ -50,6 +51,32 @@ export type SkillSnapshot = {
|
||||
skills: Array<{ name: string; primaryEnv?: string }>;
|
||||
};
|
||||
|
||||
function resolveBundledSkillsDir(): string | undefined {
|
||||
const override = process.env.CLAWDIS_BUNDLED_SKILLS_DIR?.trim();
|
||||
if (override) return override;
|
||||
|
||||
// bun --compile: ship a sibling `skills/` next to the executable.
|
||||
try {
|
||||
const execDir = path.dirname(process.execPath);
|
||||
const sibling = path.join(execDir, "skills");
|
||||
if (fs.existsSync(sibling)) return sibling;
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
|
||||
// npm/dev: resolve `<packageRoot>/skills` relative to this module.
|
||||
try {
|
||||
const moduleDir = path.dirname(fileURLToPath(import.meta.url));
|
||||
const root = path.resolve(moduleDir, "..", "..");
|
||||
const candidate = path.join(root, "skills");
|
||||
if (fs.existsSync(candidate)) return candidate;
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function getFrontmatterValue(
|
||||
frontmatter: ParsedSkillFrontmatter,
|
||||
key: string,
|
||||
@@ -380,12 +407,20 @@ function loadSkillEntries(
|
||||
opts?: {
|
||||
config?: ClawdisConfig;
|
||||
managedSkillsDir?: string;
|
||||
bundledSkillsDir?: string;
|
||||
},
|
||||
): SkillEntry[] {
|
||||
const managedSkillsDir =
|
||||
opts?.managedSkillsDir ?? path.join(CONFIG_DIR, "skills");
|
||||
const workspaceSkillsDir = path.join(workspaceDir, "skills");
|
||||
const bundledSkillsDir = opts?.bundledSkillsDir ?? resolveBundledSkillsDir();
|
||||
|
||||
const bundledSkills = bundledSkillsDir
|
||||
? loadSkillsFromDir({
|
||||
dir: bundledSkillsDir,
|
||||
source: "clawdis-bundled",
|
||||
})
|
||||
: [];
|
||||
const managedSkills = loadSkillsFromDir({
|
||||
dir: managedSkillsDir,
|
||||
source: "clawdis-managed",
|
||||
@@ -396,6 +431,8 @@ function loadSkillEntries(
|
||||
});
|
||||
|
||||
const merged = new Map<string, Skill>();
|
||||
// Precedence: bundled < managed < workspace
|
||||
for (const skill of bundledSkills) merged.set(skill.name, skill);
|
||||
for (const skill of managedSkills) merged.set(skill.name, skill);
|
||||
for (const skill of workspaceSkills) merged.set(skill.name, skill);
|
||||
|
||||
@@ -423,6 +460,7 @@ export function buildWorkspaceSkillSnapshot(
|
||||
opts?: {
|
||||
config?: ClawdisConfig;
|
||||
managedSkillsDir?: string;
|
||||
bundledSkillsDir?: string;
|
||||
entries?: SkillEntry[];
|
||||
},
|
||||
): SkillSnapshot {
|
||||
@@ -442,6 +480,7 @@ export function buildWorkspaceSkillsPrompt(
|
||||
opts?: {
|
||||
config?: ClawdisConfig;
|
||||
managedSkillsDir?: string;
|
||||
bundledSkillsDir?: string;
|
||||
entries?: SkillEntry[];
|
||||
},
|
||||
): string {
|
||||
@@ -455,6 +494,7 @@ export function loadWorkspaceSkillEntries(
|
||||
opts?: {
|
||||
config?: ClawdisConfig;
|
||||
managedSkillsDir?: string;
|
||||
bundledSkillsDir?: string;
|
||||
},
|
||||
): SkillEntry[] {
|
||||
return loadSkillEntries(workspaceDir, opts);
|
||||
|
||||
Reference in New Issue
Block a user