@useavalon/caelence-agent 0.1.1-canary.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -127,6 +127,38 @@ Body here.
127
127
  }
128
128
  });
129
129
 
130
+ test("keeps user skills with the same YAML name when catalog refs differ", async () => {
131
+ const cwd = await mkdtemp(join(tmpdir(), "harness-sk-dup-"));
132
+ try {
133
+ const user = join(cwd, "user");
134
+ mkdirSync(join(user, "acme-pack-frontend-design"), { recursive: true });
135
+ mkdirSync(join(user, "other-ui-frontend-design"), { recursive: true });
136
+ writeFileSync(
137
+ join(user, "acme-pack-frontend-design", "SKILL.md"),
138
+ "---\nname: frontend-design\n---\n\n# Acme\n",
139
+ );
140
+ writeFileSync(
141
+ join(user, "acme-pack-frontend-design", ".catalog-ref"),
142
+ "acme/pack/frontend-design\n",
143
+ );
144
+ writeFileSync(
145
+ join(user, "other-ui-frontend-design", "SKILL.md"),
146
+ "---\nname: frontend-design\n---\n\n# Other\n",
147
+ );
148
+ writeFileSync(
149
+ join(user, "other-ui-frontend-design", ".catalog-ref"),
150
+ "other/ui/frontend-design\n",
151
+ );
152
+ const merged = loadMergedSkills(join(cwd, "host"), user);
153
+ const dupes = merged.filter((skill) => skill.name === "frontend-design");
154
+ expect(dupes).toHaveLength(2);
155
+ expect(skillCatalogPrompt(dupes)).toContain("acme/pack/frontend-design");
156
+ expect(skillCatalogPrompt(dupes)).toContain("other/ui/frontend-design");
157
+ } finally {
158
+ await rm(cwd, { recursive: true, force: true });
159
+ }
160
+ });
161
+
130
162
  test("skill catalog lists names only", () => {
131
163
  const catalog = skillCatalogPrompt([
132
164
  {
@@ -27,38 +27,56 @@ export function stripFrontmatter(md: string): { attrs: Record<string, string>; b
27
27
  return { attrs: parseFrontmatter(raw), body };
28
28
  }
29
29
 
30
+ function splitFrontmatterLine(line: string): { key: string; value: string } | undefined {
31
+ if (/^\s/.test(line)) return undefined;
32
+ const colon = line.indexOf(":");
33
+ if (colon <= 0) return undefined;
34
+ const key = line.slice(0, colon);
35
+ if (!/^[A-Za-z0-9_-]+$/.test(key)) return undefined;
36
+ return { key, value: line.slice(colon + 1).trim() };
37
+ }
38
+
39
+ function readFoldedFrontmatterValue(
40
+ lines: string[],
41
+ start: number,
42
+ ): { value: string; next: number } {
43
+ const folded: string[] = [];
44
+ let i = start;
45
+ while (i < lines.length) {
46
+ const next = lines[i] ?? "";
47
+ if (splitFrontmatterLine(next)) break;
48
+ folded.push(next.replace(/^\s{2,}/, ""));
49
+ i += 1;
50
+ }
51
+ return { value: folded.join(" ").replaceAll(/\s+/g, " ").trim(), next: i };
52
+ }
53
+
30
54
  function parseFrontmatter(raw: string): Record<string, string> {
31
55
  const attrs: Record<string, string> = {};
32
56
  const lines = raw.split("\n");
33
57
  let i = 0;
34
58
  while (i < lines.length) {
35
59
  const line = lines[i] ?? "";
36
- const match = /^([A-Za-z0-9_-]+):\s*(.*)$/.exec(line);
60
+ const match = splitFrontmatterLine(line);
37
61
  if (!match) {
38
62
  i += 1;
39
63
  continue;
40
64
  }
41
- const key = match[1] ?? "";
42
- let value = (match[2] ?? "").trim();
43
- if (value === ">" || value === ">|" || value === ">-" || value === "|" || value === "|-") {
44
- const folded: string[] = [];
45
- i += 1;
46
- while (i < lines.length) {
47
- const next = lines[i] ?? "";
48
- if (/^[A-Za-z0-9_-]+:\s*/.test(next) && !/^\s/.test(next)) break;
49
- folded.push(next.replace(/^\s{2,}/, ""));
50
- i += 1;
51
- }
52
- attrs[key] = folded.join(" ").replace(/\s+/g, " ").trim();
65
+ const foldedMarks = new Set([">", ">|", ">-", "|", "|-"]);
66
+ if (foldedMarks.has(match.value)) {
67
+ const folded = readFoldedFrontmatterValue(lines, i + 1);
68
+ attrs[match.key] = folded.value;
69
+ i = folded.next;
53
70
  continue;
54
71
  }
72
+ let value = match.value;
55
73
  if (
56
74
  (value.startsWith('"') && value.endsWith('"')) ||
57
75
  (value.startsWith("'") && value.endsWith("'"))
58
76
  ) {
59
77
  value = value.slice(1, -1);
60
78
  }
61
- attrs[key] = value;
79
+ attrs[match.key] = value;
62
80
  i += 1;
63
81
  }
64
82
  return attrs;
@@ -75,7 +93,7 @@ export function parseSkillMarkdown(md: string, absPath: string, root: string): S
75
93
  description,
76
94
  body,
77
95
  path: absPath,
78
- relPath: relative(root, absPath).split("\\").join("/"),
96
+ relPath: relative(root, absPath).replaceAll("\\", "/"),
79
97
  source: "host",
80
98
  };
81
99
  }
@@ -97,12 +115,18 @@ export function isBundledCatalogDir(abs: string): boolean {
97
115
  return resolve(abs) === resolve(bundled);
98
116
  }
99
117
 
118
+ function skillMergeKey(skill: Skill): string {
119
+ const ref = skill.catalogRef?.trim();
120
+ if (ref) return `ref:${ref.replaceAll("@", "/").toLowerCase()}`;
121
+ return `name:${skill.name.toLowerCase()}`;
122
+ }
123
+
100
124
  /** Later writers win. Used to overlay host skills on a catalog or user store. */
101
125
  export function mergeSkills(first: Skill[], host: Skill[]): Skill[] {
102
- const byName = new Map<string, Skill>();
103
- for (const skill of first) byName.set(skill.name.toLowerCase(), skill);
104
- for (const skill of host) byName.set(skill.name.toLowerCase(), { ...skill, source: "host" });
105
- return [...byName.values()].sort((a, b) => a.name.localeCompare(b.name));
126
+ const byKey = new Map<string, Skill>();
127
+ for (const skill of first) byKey.set(skillMergeKey(skill), skill);
128
+ for (const skill of host) byKey.set(skillMergeKey(skill), { ...skill, source: "host" });
129
+ return [...byKey.values()].sort((a, b) => a.name.localeCompare(b.name));
106
130
  }
107
131
 
108
132
  /** Skills shipped with the package. Not loaded until `/skill add`. */
@@ -131,18 +155,18 @@ export function resolveHostSkillDirs(cwd: string, configured: string): string[]
131
155
 
132
156
  export function loadMergedSkills(hostSkillsDir: string | string[], userDir?: string): Skill[] {
133
157
  const dirs = Array.isArray(hostSkillsDir) ? hostSkillsDir : [hostSkillsDir];
134
- const byName = new Map<string, Skill>();
158
+ const byKey = new Map<string, Skill>();
135
159
  if (userDir) {
136
160
  for (const skill of loadSkills(userDir)) {
137
- byName.set(skill.name.toLowerCase(), { ...skill, source: "user" });
161
+ byKey.set(skillMergeKey(skill), { ...skill, source: "user" });
138
162
  }
139
163
  }
140
164
  for (const dir of dirs) {
141
165
  for (const skill of loadSkills(dir)) {
142
- byName.set(skill.name.toLowerCase(), { ...skill, source: "host" });
166
+ byKey.set(skillMergeKey(skill), { ...skill, source: "host" });
143
167
  }
144
168
  }
145
- return [...byName.values()].sort((a, b) => a.name.localeCompare(b.name));
169
+ return [...byKey.values()].sort((a, b) => a.name.localeCompare(b.name));
146
170
  }
147
171
 
148
172
  export function loadSkills(skillsDir: string): Skill[] {
@@ -172,18 +196,25 @@ export function loadSkills(skillsDir: string): Skill[] {
172
196
 
173
197
  export function skillCatalogPrompt(skills: Skill[]): string {
174
198
  if (skills.length === 0) return "";
175
- const lines = skills.map((s) => `- ${s.name} (${s.source})`);
199
+ const lines = skills.map((s) => {
200
+ const origin = s.catalogRef || s.source;
201
+ return `- ${s.name} (${origin})`;
202
+ });
176
203
  return [
177
204
  "## Skills",
178
- "Skills are instruction files, not tools. When a task matches a name, read it with read_skill. Do not list or quote these unless the user asks.",
205
+ "Skills are instruction files, not tools. When a task matches a name, read it with read_skill. Do not list or quote these unless the user asks. If two skills share a name, pass the catalog id in parentheses.",
179
206
  ...lines,
180
207
  ].join("\n");
181
208
  }
182
209
 
183
210
  export function skillBodiesForNames(skills: Skill[], names: string[]): string {
184
- const wanted = new Set(names.map((n) => n.trim().toLowerCase()));
211
+ const wanted = new Set(names.map((n) => n.trim().toLowerCase().replaceAll("@", "/")));
185
212
  return skills
186
- .filter((s) => wanted.has(s.name.toLowerCase()))
213
+ .filter((s) => {
214
+ const name = s.name.toLowerCase();
215
+ const ref = s.catalogRef?.replaceAll("@", "/").toLowerCase();
216
+ return wanted.has(name) || (ref ? wanted.has(ref) : false);
217
+ })
187
218
  .map((s) => `# Skill: ${s.name}\n\n${s.body}`)
188
219
  .join("\n\n");
189
220
  }
@@ -1,4 +1,4 @@
1
- import { describe, expect, test } from "bun:test";
1
+ import { afterEach, describe, expect, test } from "bun:test";
2
2
  import { existsSync, mkdirSync, writeFileSync } from "node:fs";
3
3
  import { mkdtemp, readFile, rm } from "node:fs/promises";
4
4
  import { tmpdir } from "node:os";
@@ -6,6 +6,9 @@ import { join } from "node:path";
6
6
  import { loadMergedSkills } from "./loader.ts";
7
7
  import {
8
8
  bundledRegistryHits,
9
+ catalogNameFitsGithubFolders,
10
+ clearGithubSkillFolderCache,
11
+ dropUninstallableCatalogHits,
9
12
  formatRegistryHits,
10
13
  installBundledSkills,
11
14
  installSkillFromSource,
@@ -18,6 +21,10 @@ import {
18
21
  } from "./registry.ts";
19
22
  import { parseSkillCommand } from "./skill-command.ts";
20
23
 
24
+ afterEach(() => {
25
+ clearGithubSkillFolderCache();
26
+ });
27
+
21
28
  describe("parseSkillSource", () => {
22
29
  test("accepts owner/repo@skill and skills.sh urls", () => {
23
30
  expect(parseSkillSource("anthropics/skills@frontend-design")).toEqual({
@@ -31,6 +38,19 @@ describe("parseSkillSource", () => {
31
38
  repo: "skills",
32
39
  skill: "frontend-design",
33
40
  });
41
+ expect(parseSkillSource("anthropics/skills/frontend-design")).toMatchObject({
42
+ owner: "anthropics",
43
+ repo: "skills",
44
+ skill: "frontend-design",
45
+ });
46
+ expect(parseSkillSource("smithery.ai@frontend-design")).toMatchObject({
47
+ error:
48
+ "smithery.ai@frontend-design is listed on skills.sh but is not a GitHub repo, so it cannot be added.",
49
+ });
50
+ expect(parseSkillSource("smithery.ai/frontend-design")).toMatchObject({
51
+ error:
52
+ "smithery.ai/frontend-design is listed on skills.sh but is not a GitHub repo, so it cannot be added.",
53
+ });
34
54
  });
35
55
  });
36
56
 
@@ -84,6 +104,178 @@ describe("searchSkillsSh", () => {
84
104
  });
85
105
  expect(formatRegistryHits(hits)).toBe("anthropics/skills@frontend-design 10");
86
106
  });
107
+
108
+ test("drops skills.sh hosts that are not GitHub repos", async () => {
109
+ const hits = await searchSkillsSh(
110
+ "frontend-design",
111
+ async () =>
112
+ new Response(
113
+ JSON.stringify({
114
+ skills: [
115
+ {
116
+ id: "smithery.ai/frontend-design",
117
+ name: "frontend-design",
118
+ source: "smithery.ai",
119
+ installs: 6216,
120
+ },
121
+ {
122
+ id: "anthropics/skills/frontend-design",
123
+ name: "frontend-design",
124
+ source: "anthropics/skills",
125
+ installs: 10,
126
+ },
127
+ ],
128
+ }),
129
+ ),
130
+ );
131
+ expect(hits.map((hit) => hit.source)).toEqual(["anthropics/skills"]);
132
+ });
133
+
134
+ test("drops skills.sh names that are not in that GitHub repo", async () => {
135
+ const hits = await searchSkillsSh("frontend", async (url) => {
136
+ const href = String(url);
137
+ if (href.includes("/repos/openai/skills/git/trees/")) {
138
+ return Response.json({
139
+ tree: [
140
+ { path: "skills/aspnet-core/SKILL.md", type: "blob" },
141
+ { path: "skills/chatgpt-apps/SKILL.md", type: "blob" },
142
+ { path: "skills/skill-creator/SKILL.md", type: "blob" },
143
+ ],
144
+ });
145
+ }
146
+ if (href.includes("/repos/pbakaus/impeccable/git/trees/")) {
147
+ return Response.json({
148
+ tree: [{ path: "SKILL.md", type: "blob" }],
149
+ });
150
+ }
151
+ if (href.includes("/repos/anthropics/skills/git/trees/")) {
152
+ return Response.json({
153
+ tree: [{ path: "skills/frontend-design/SKILL.md", type: "blob" }],
154
+ });
155
+ }
156
+ return Response.json({
157
+ skills: [
158
+ {
159
+ id: "openai/skills/frontend-skill",
160
+ name: "frontend-skill",
161
+ source: "openai/skills",
162
+ installs: 1600,
163
+ },
164
+ {
165
+ id: "openai/skills/chatgpt-apps",
166
+ name: "chatgpt-apps",
167
+ source: "openai/skills",
168
+ installs: 12,
169
+ },
170
+ {
171
+ id: "pbakaus/impeccable/frontend-design",
172
+ name: "frontend-design",
173
+ source: "pbakaus/impeccable",
174
+ installs: 40,
175
+ },
176
+ {
177
+ id: "anthropics/skills/frontend-design",
178
+ name: "frontend-design",
179
+ source: "anthropics/skills",
180
+ installs: 10,
181
+ },
182
+ ],
183
+ });
184
+ });
185
+ expect(hits.map((hit) => `${hit.source}/${hit.name}`)).toEqual([
186
+ "openai/skills/chatgpt-apps",
187
+ "pbakaus/impeccable/frontend-design",
188
+ "anthropics/skills/frontend-design",
189
+ ]);
190
+ });
191
+ });
192
+
193
+ describe("catalogNameFitsGithubFolders", () => {
194
+ test("keeps YAML catalog names and drops generic ghosts", () => {
195
+ expect(
196
+ catalogNameFitsGithubFolders("frontend-skill", [
197
+ "aspnet-core",
198
+ "chatgpt-apps",
199
+ "skill-creator",
200
+ ]),
201
+ ).toBe(false);
202
+ expect(catalogNameFitsGithubFolders("chatgpt-apps", ["aspnet-core", "chatgpt-apps"])).toBe(
203
+ true,
204
+ );
205
+ expect(
206
+ catalogNameFitsGithubFolders("design-taste-frontend-v1", [
207
+ "brandkit",
208
+ "brutalist-skill",
209
+ "taste-skill",
210
+ "taste-skill-v1",
211
+ ]),
212
+ ).toBe(true);
213
+ expect(catalogNameFitsGithubFolders("frontend-design", ["impeccable"])).toBe(true);
214
+ });
215
+
216
+ test("hides a name after GitHub confirms it is not in the repo", async () => {
217
+ const home = await mkdtemp(join(tmpdir(), "harness-missing-"));
218
+ const dest = await mkdtemp(join(tmpdir(), "harness-user-skills-"));
219
+ const prev = process.env.HARNESS_HOME;
220
+ process.env.HARNESS_HOME = home;
221
+ clearGithubSkillFolderCache();
222
+ try {
223
+ const result = await installSkillFromSource({
224
+ source: "openai/skills@frontend-skill",
225
+ destRoot: dest,
226
+ fetchFn: async (url) => {
227
+ if (url.includes("/git/trees/")) {
228
+ return Response.json({
229
+ tree: [
230
+ { path: "skills/aspnet-core/SKILL.md", type: "blob" },
231
+ { path: "skills/chatgpt-apps/SKILL.md", type: "blob" },
232
+ ],
233
+ });
234
+ }
235
+ return new Response("missing", { status: 404 });
236
+ },
237
+ });
238
+ expect(result).toMatchObject({ error: 'No skill "frontend-skill" in openai/skills.' });
239
+ expect(
240
+ dropUninstallableCatalogHits([
241
+ {
242
+ id: "openai/skills/frontend-skill",
243
+ name: "frontend-skill",
244
+ source: "openai/skills",
245
+ },
246
+ {
247
+ id: "openai/skills/chatgpt-apps",
248
+ name: "chatgpt-apps",
249
+ source: "openai/skills",
250
+ },
251
+ ]).map((hit) => hit.name),
252
+ ).toEqual(["chatgpt-apps"]);
253
+ const hits = await searchSkillsSh("frontend", async (url) => {
254
+ if (String(url).includes("/git/trees/")) return new Response("no", { status: 403 });
255
+ return Response.json({
256
+ skills: [
257
+ {
258
+ id: "openai/skills/frontend-skill",
259
+ name: "frontend-skill",
260
+ source: "openai/skills",
261
+ },
262
+ {
263
+ id: "openai/skills/chatgpt-apps",
264
+ name: "chatgpt-apps",
265
+ source: "openai/skills",
266
+ },
267
+ ],
268
+ });
269
+ });
270
+ expect(hits.map((hit) => hit.name)).toEqual(["chatgpt-apps"]);
271
+ } finally {
272
+ clearGithubSkillFolderCache();
273
+ if (prev === undefined) delete process.env.HARNESS_HOME;
274
+ else process.env.HARNESS_HOME = prev;
275
+ await rm(home, { recursive: true, force: true });
276
+ await rm(dest, { recursive: true, force: true });
277
+ }
278
+ });
87
279
  });
88
280
 
89
281
  describe("installSkillFromSource", () => {
@@ -111,10 +303,12 @@ describe("installSkillFromSource", () => {
111
303
  return new Response("missing", { status: 404 });
112
304
  },
113
305
  });
114
- expect(result).toEqual({ name: "hello", rel: "hello/SKILL.md" });
115
- const body = await readFile(join(dest, "hello", "SKILL.md"), "utf8");
306
+ expect(result).toEqual({ name: "hello", rel: "acme-pack-hello/SKILL.md" });
307
+ const body = await readFile(join(dest, "acme-pack-hello", "SKILL.md"), "utf8");
116
308
  expect(body).toContain("# Hello");
117
- expect(await readFile(join(dest, "hello", ".catalog-ref"), "utf8")).toBe("acme/pack@hello\n");
309
+ expect(await readFile(join(dest, "acme-pack-hello", ".catalog-ref"), "utf8")).toBe(
310
+ "acme/pack@hello\n",
311
+ );
118
312
  } finally {
119
313
  await rm(dest, { recursive: true, force: true });
120
314
  }
@@ -150,11 +344,233 @@ describe("installSkillFromSource", () => {
150
344
  return new Response("missing", { status: 404 });
151
345
  },
152
346
  });
153
- expect(result).toEqual({ name: "frontend-design", rel: "frontend-design/SKILL.md" });
154
- const body = await readFile(join(dest, "frontend-design", "SKILL.md"), "utf8");
347
+ expect(result).toEqual({
348
+ name: "frontend-design",
349
+ rel: "acme-pack-frontend-design/SKILL.md",
350
+ });
351
+ const body = await readFile(join(dest, "acme-pack-frontend-design", "SKILL.md"), "utf8");
155
352
  expect(body).toContain("# Anthropic");
156
353
  expect(existsSync(join(dest, "xlsx"))).toBe(false);
157
- expect(existsSync(join(dest, "frontend-design", "xlsx"))).toBe(false);
354
+ expect(existsSync(join(dest, "frontend-design"))).toBe(false);
355
+ } finally {
356
+ await rm(dest, { recursive: true, force: true });
357
+ }
358
+ });
359
+
360
+ test("keeps two skills.sh rows with the same YAML name in separate folders", async () => {
361
+ const dest = await mkdtemp(join(tmpdir(), "harness-user-skills-"));
362
+ try {
363
+ const fetchFn = async (url: string) => {
364
+ if (url.includes("/repos/acme/pack/") && url.includes("/git/trees/")) {
365
+ return Response.json({ tree: [{ path: "frontend-design/SKILL.md", type: "blob" }] });
366
+ }
367
+ if (url.includes("/repos/other/ui/") && url.includes("/git/trees/")) {
368
+ return Response.json({ tree: [{ path: "frontend-design/SKILL.md", type: "blob" }] });
369
+ }
370
+ if (url.includes("/acme/pack/") && url.endsWith("frontend-design/SKILL.md")) {
371
+ return new Response("---\nname: frontend-design\n---\n\n# Acme\n");
372
+ }
373
+ if (url.includes("/other/ui/") && url.endsWith("frontend-design/SKILL.md")) {
374
+ return new Response("---\nname: frontend-design\n---\n\n# Other\n");
375
+ }
376
+ return new Response("missing", { status: 404 });
377
+ };
378
+ await installSkillFromSource({
379
+ source: "acme/pack/frontend-design",
380
+ destRoot: dest,
381
+ fetchFn,
382
+ });
383
+ await installSkillFromSource({ source: "other/ui/frontend-design", destRoot: dest, fetchFn });
384
+ expect(existsSync(join(dest, "acme-pack-frontend-design", "SKILL.md"))).toBe(true);
385
+ expect(existsSync(join(dest, "other-ui-frontend-design", "SKILL.md"))).toBe(true);
386
+ const merged = loadMergedSkills("/tmp/does-not-exist-host", dest);
387
+ expect(merged.filter((skill) => skill.name === "frontend-design")).toHaveLength(2);
388
+ const removed = removeSkillFromRoots("acme/pack/frontend-design", [dest]);
389
+ expect(removed.removed).toBe(true);
390
+ expect(existsSync(join(dest, "acme-pack-frontend-design"))).toBe(false);
391
+ expect(existsSync(join(dest, "other-ui-frontend-design"))).toBe(true);
392
+ } finally {
393
+ await rm(dest, { recursive: true, force: true });
394
+ }
395
+ });
396
+
397
+ test("installs a single-skill repo listed under a different catalog name", async () => {
398
+ const dest = await mkdtemp(join(tmpdir(), "harness-user-skills-"));
399
+ try {
400
+ const result = await installSkillFromSource({
401
+ source: "pbakaus/impeccable/frontend-design",
402
+ destRoot: dest,
403
+ fetchFn: async (url) => {
404
+ if (url.includes("/git/trees/")) {
405
+ return Response.json({
406
+ tree: [
407
+ { path: ".claude/skills/impeccable/SKILL.md", type: "blob" },
408
+ { path: ".cursor/skills/impeccable/SKILL.md", type: "blob" },
409
+ { path: ".cursor/skills/impeccable/scripts/run.sh", type: "blob" },
410
+ { path: "plugin/skills/impeccable/SKILL.md", type: "blob" },
411
+ {
412
+ path: "tests/oracle/workspaces/ctx-pin/.claude/skills/audit/SKILL.md",
413
+ type: "blob",
414
+ },
415
+ {
416
+ path: "tests/oracle/workspaces/ctx-pin/.claude/skills/impeccable/SKILL.md",
417
+ type: "blob",
418
+ },
419
+ ],
420
+ });
421
+ }
422
+ if (url.endsWith("impeccable/SKILL.md")) {
423
+ return new Response("---\nname: impeccable\ndescription: ui\n---\n\n# Impeccable\n");
424
+ }
425
+ return new Response("missing", { status: 404 });
426
+ },
427
+ });
428
+ expect(result).toEqual({
429
+ name: "impeccable",
430
+ rel: "pbakaus-impeccable-frontend-design/SKILL.md",
431
+ });
432
+ expect(existsSync(join(dest, "pbakaus-impeccable-frontend-design", "SKILL.md"))).toBe(true);
433
+ expect(existsSync(join(dest, "audit"))).toBe(false);
434
+ } finally {
435
+ await rm(dest, { recursive: true, force: true });
436
+ }
437
+ });
438
+
439
+ test("matches a YAML catalog name after more than 12 other folders", async () => {
440
+ const dest = await mkdtemp(join(tmpdir(), "harness-user-skills-"));
441
+ try {
442
+ const fillers = Array.from({ length: 12 }, (_, i) => `skills/alpha-${i}/SKILL.md`);
443
+ const result = await installSkillFromSource({
444
+ source: "leonxlnx/taste-skill@design-taste-frontend-v1",
445
+ destRoot: dest,
446
+ fetchFn: async (url) => {
447
+ if (url.includes("/git/trees/")) {
448
+ return Response.json({
449
+ tree: [
450
+ ...fillers.map((path) => ({ path, type: "blob" })),
451
+ { path: "skills/taste-skill-v1/SKILL.md", type: "blob" },
452
+ ],
453
+ });
454
+ }
455
+ if (url.endsWith("skills/taste-skill-v1/SKILL.md")) {
456
+ return new Response("---\nname: design-taste-frontend-v1\n---\n\n# Taste v1\n");
457
+ }
458
+ if (url.endsWith("SKILL.md")) {
459
+ return new Response("---\nname: filler\n---\n\n# Filler\n");
460
+ }
461
+ return new Response("missing", { status: 404 });
462
+ },
463
+ });
464
+ expect(result).toEqual({
465
+ name: "design-taste-frontend-v1",
466
+ rel: "leonxlnx-taste-skill-design-taste-frontend-v1/SKILL.md",
467
+ });
468
+ const body = await readFile(
469
+ join(dest, "leonxlnx-taste-skill-design-taste-frontend-v1", "SKILL.md"),
470
+ "utf8",
471
+ );
472
+ expect(body).toContain("# Taste v1");
473
+ } finally {
474
+ await rm(dest, { recursive: true, force: true });
475
+ }
476
+ });
477
+
478
+ test("installs a skill that has more than 40 reference files", async () => {
479
+ const dest = await mkdtemp(join(tmpdir(), "harness-user-skills-"));
480
+ try {
481
+ const tree = [
482
+ { path: ".github/skills/impeccable/SKILL.md", type: "blob" },
483
+ ...Array.from({ length: 40 }, (_, i) => ({
484
+ path: `.github/skills/impeccable/reference/n${i}.md`,
485
+ type: "blob",
486
+ })),
487
+ ];
488
+ const result = await installSkillFromSource({
489
+ source: "pbakaus/impeccable/frontend-design",
490
+ destRoot: dest,
491
+ fetchFn: async (url) => {
492
+ if (url.includes("/git/trees/")) return Response.json({ tree });
493
+ if (url.endsWith("SKILL.md")) {
494
+ return new Response("---\nname: impeccable\n---\n\n# Impeccable\n");
495
+ }
496
+ if (url.endsWith(".md")) return new Response("# ref\n");
497
+ return new Response("missing", { status: 404 });
498
+ },
499
+ });
500
+ expect(result).toMatchObject({ name: "impeccable" });
501
+ expect(existsSync(join(dest, "pbakaus-impeccable-frontend-design", "SKILL.md"))).toBe(true);
502
+ expect(
503
+ existsSync(join(dest, "pbakaus-impeccable-frontend-design", "reference", "n0.md")),
504
+ ).toBe(true);
505
+ } finally {
506
+ await rm(dest, { recursive: true, force: true });
507
+ }
508
+ });
509
+
510
+ test("matches a catalog name to YAML when the folder differs", async () => {
511
+ const dest = await mkdtemp(join(tmpdir(), "harness-user-skills-"));
512
+ try {
513
+ const result = await installSkillFromSource({
514
+ source: "acme/pack@frontend-design",
515
+ destRoot: dest,
516
+ fetchFn: async (url) => {
517
+ if (url.includes("/git/trees/")) {
518
+ return Response.json({
519
+ tree: [
520
+ { path: "skills/ui/SKILL.md", type: "blob" },
521
+ { path: "skills/xlsx/SKILL.md", type: "blob" },
522
+ ],
523
+ });
524
+ }
525
+ if (url.endsWith("skills/ui/SKILL.md")) {
526
+ return new Response("---\nname: frontend-design\n---\n\n# UI\n");
527
+ }
528
+ if (url.endsWith("skills/xlsx/SKILL.md")) {
529
+ return new Response("---\nname: xlsx\n---\n\n# Sheets\n");
530
+ }
531
+ return new Response("missing", { status: 404 });
532
+ },
533
+ });
534
+ expect(result).toEqual({
535
+ name: "frontend-design",
536
+ rel: "acme-pack-frontend-design/SKILL.md",
537
+ });
538
+ const body = await readFile(join(dest, "acme-pack-frontend-design", "SKILL.md"), "utf8");
539
+ expect(body).toContain("# UI");
540
+ } finally {
541
+ await rm(dest, { recursive: true, force: true });
542
+ }
543
+ });
544
+
545
+ test("lists unique skill folders when the catalog name is missing", async () => {
546
+ const dest = await mkdtemp(join(tmpdir(), "harness-user-skills-"));
547
+ try {
548
+ const result = await installSkillFromSource({
549
+ source: "acme/pack@frontend-design",
550
+ destRoot: dest,
551
+ fetchFn: async (url) => {
552
+ if (url.includes("/git/trees/")) {
553
+ return Response.json({
554
+ tree: [
555
+ { path: ".cursor/skills/impeccable/SKILL.md", type: "blob" },
556
+ { path: ".claude/skills/impeccable/SKILL.md", type: "blob" },
557
+ { path: "skills/audit/SKILL.md", type: "blob" },
558
+ ],
559
+ });
560
+ }
561
+ if (url.endsWith("impeccable/SKILL.md")) {
562
+ return new Response("---\nname: impeccable\n---\n\n# Impeccable\n");
563
+ }
564
+ if (url.endsWith("audit/SKILL.md")) {
565
+ return new Response("---\nname: audit\n---\n\n# Audit\n");
566
+ }
567
+ return new Response("missing", { status: 404 });
568
+ },
569
+ });
570
+ expect(result).toMatchObject({
571
+ error: 'No skill "frontend-design" in acme/pack.',
572
+ choices: ["audit", "impeccable"],
573
+ });
158
574
  } finally {
159
575
  await rm(dest, { recursive: true, force: true });
160
576
  }