Open History to see the last commit
1import * as NodeServices from "@effect/platform-node/NodeServices";
2import { assert, it } from "@effect/vitest";
3import * as Effect from "effect/Effect";
4import * as FileSystem from "effect/FileSystem";
5import * as Path from "effect/Path";
6
7import { discoverClaudeSkills } from "./ClaudeSkills.ts";
8import { planClaudeSkillDispatch } from "./ClaudeSkillDispatch.ts";
9
10const writeSkill = Effect.fn(function* (
11 skillsDir: string,
12 directoryName: string,
13 contents: string,
14) {
15 const fs = yield* FileSystem.FileSystem;
16 const path = yield* Path.Path;
17 const skillDir = path.join(skillsDir, directoryName);
18 yield* fs.makeDirectory(skillDir, { recursive: true });
19 yield* fs.writeFileString(path.join(skillDir, "SKILL.md"), contents);
20});
21
22it.layer(NodeServices.layer)("discoverClaudeSkills", (it) => {
23 it.effect("discovers enabled plugin skills with manifest names and ignores skill overrides", () =>
24 Effect.gen(function* () {
25 const fs = yield* FileSystem.FileSystem;
26 const path = yield* Path.Path;
27 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
28 const configDir = path.join(tempDir, "claude-home");
29 const plugin = path.join(configDir, "plugins", "cache", "shop", "plugin", "1.0.0");
30 const disabled = path.join(configDir, "plugins", "disabled");
31 yield* writeSkill(path.join(disabled, "skills"), "hidden", "# Hidden");
32 yield* writeSkill(path.join(plugin, "skills"), "plain", "# Plain");
33 yield* writeSkill(
34 path.join(plugin, "engineering"),
35 "review",
36 "---\nname: review-alias\ndescription: Review changes.\ndisable-model-invocation: true\nuser-invocable: false\n---\n",
37 );
38 yield* fs.makeDirectory(path.join(plugin, ".claude-plugin"), { recursive: true });
39 yield* fs.writeFileString(
40 path.join(plugin, ".claude-plugin", "plugin.json"),
41 '{"name":"manifest-plugin","skills":["./engineering/review"]}',
42 );
43 yield* fs.writeFileString(
44 path.join(configDir, "plugins", "installed_plugins.json"),
45 JSON.stringify({
46 plugins: {
47 "plugin@shop": [{ scope: "user", installPath: plugin }],
48 "disabled@shop": [{ scope: "user", installPath: disabled }],
49 "unconfigured@shop": [{ scope: "user", installPath: disabled }],
50 },
51 }),
52 );
53 yield* fs.writeFileString(
54 path.join(configDir, "settings.json"),
55 '{"enabledPlugins":{"plugin@shop":true,"disabled@shop":false,"uninstalled@shop":true,"other@shop":["^1.0.0"]},"skillOverrides":{"manifest-plugin:plain":"off"}}',
56 );
57
58 const skills = yield* discoverClaudeSkills({ homePath: configDir });
59 assert.deepEqual(skills, [
60 {
61 name: "manifest-plugin:plain",
62 path: path.join(plugin, "skills", "plain", "SKILL.md"),
63 enabled: true,
64 scope: "user",
65 },
66 {
67 name: "manifest-plugin:review-alias",
68 path: path.join(plugin, "engineering", "review", "SKILL.md"),
69 enabled: true,
70 scope: "user",
71 description: "Review changes.",
72 userInvocationOnly: true,
73 userInvocable: false,
74 },
75 ]);
76 }),
77 );
78
79 it.effect("merges plugin enablement and selects installs in native registry order", () =>
80 Effect.gen(function* () {
81 const fs = yield* FileSystem.FileSystem;
82 const path = yield* Path.Path;
83 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
84 const configDir = path.join(tempDir, "claude-home");
85 const workspace = path.join(tempDir, "workspace");
86 const nestedWorkspace = path.join(workspace, "packages", "app");
87 const aliasedWorkspace = path.join(tempDir, "aliased-workspace");
88 const userInstall = path.join(configDir, "plugins", "user");
89 const projectInstall = path.join(configDir, "plugins", "project");
90 const localInstall = path.join(configDir, "plugins", "local");
91 const managedInstall = path.join(configDir, "plugins", "managed");
92 yield* fs.makeDirectory(path.join(workspace, ".git"), { recursive: true });
93 yield* fs.makeDirectory(nestedWorkspace, { recursive: true });
94 yield* fs.symlink(workspace, aliasedWorkspace);
95 for (const install of [userInstall, projectInstall, localInstall, managedInstall]) {
96 yield* writeSkill(path.join(install, "skills"), "review", "# Review");
97 }
98 yield* fs.writeFileString(
99 path.join(configDir, "plugins", "installed_plugins.json"),
100 JSON.stringify({
101 plugins: {
102 "plugin@shop": [
103 { scope: "project", projectPath: aliasedWorkspace, installPath: localInstall },
104 { scope: "project", projectPath: workspace, installPath: projectInstall },
105 { scope: "user", installPath: userInstall },
106 { scope: "managed", installPath: managedInstall },
107 ],
108 "local@shop": [
109 { scope: "local", projectPath: workspace, installPath: localInstall },
110 { scope: "project", projectPath: workspace, installPath: projectInstall },
111 { scope: "managed", installPath: path.join(configDir, "plugins", "missing") },
112 { scope: "managed", installPath: managedInstall },
113 { scope: "user", installPath: userInstall },
114 ],
115 },
116 }),
117 );
118 yield* fs.writeFileString(
119 path.join(configDir, "settings.json"),
120 '{"enabledPlugins":{"plugin@shop":true,"local@shop":false}}',
121 );
122 yield* fs.makeDirectory(path.join(workspace, ".claude"), { recursive: true });
123 yield* fs.writeFileString(
124 path.join(workspace, ".claude", "settings.json"),
125 '{"enabledPlugins":{"plugin@shop":false,"local@shop":true,"other@shop":["^1.0.0"]}}',
126 );
127 const projectSettings = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
128 assert.deepEqual(
129 projectSettings.map((skill) => [skill.name, skill.scope, skill.path]),
130 [["local:review", "project", path.join(localInstall, "skills", "review", "SKILL.md")]],
131 );
132 assert.deepEqual(
133 (yield* discoverClaudeSkills({ homePath: configDir }, nestedWorkspace)).map((skill) => [
134 skill.name,
135 skill.scope,
136 skill.path,
137 ]),
138 [["plugin:review", "project", path.join(projectInstall, "skills", "review", "SKILL.md")]],
139 );
140 yield* fs.writeFileString(
141 path.join(workspace, ".claude", "settings.local.json"),
142 '{"enabledPlugins":{"plugin@shop":true,"local@shop":false},"skillOverrides":{"invalid":"bogus"}}',
143 );
144 assert.deepEqual(
145 yield* discoverClaudeSkills({ homePath: configDir }, workspace),
146 projectSettings,
147 );
148 yield* fs.writeFileString(
149 path.join(workspace, ".claude", "settings.local.json"),
150 '{"enabledPlugins":{"plugin@shop":true,"local@shop":true}}',
151 );
152 const localSettings = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
153 assert.deepEqual(
154 localSettings.map((skill) => [skill.name, skill.scope, skill.path]),
155 [
156 ["local:review", "project", path.join(localInstall, "skills", "review", "SKILL.md")],
157 ["plugin:review", "project", path.join(projectInstall, "skills", "review", "SKILL.md")],
158 ],
159 );
160 assert.deepEqual(
161 yield* discoverClaudeSkills({ homePath: configDir }, nestedWorkspace),
162 localSettings,
163 );
164 assert.deepEqual(
165 yield* discoverClaudeSkills({ homePath: configDir }, aliasedWorkspace),
166 localSettings,
167 );
168 yield* fs.writeFileString(
169 path.join(workspace, ".claude", "settings.local.json"),
170 '{"enabledPlugins":{"local@shop":["^1.0.0"]}}',
171 );
172 assert.deepEqual(yield* discoverClaudeSkills({ homePath: configDir }, workspace), []);
173 yield* fs.writeFileString(
174 path.join(configDir, "settings.json"),
175 '{"enabledPlugins":{"plugin@shop":true,"local@shop":true}}',
176 );
177 const separateRepository = path.join(workspace, "separate");
178 yield* fs.makeDirectory(path.join(separateRepository, ".git"), { recursive: true });
179 for (const cwd of [undefined, path.join(tempDir, "elsewhere"), separateRepository]) {
180 const elsewhere = yield* discoverClaudeSkills({ homePath: configDir }, cwd);
181 assert.deepEqual(
182 elsewhere.map((skill) => [skill.name, skill.scope, skill.path]),
183 [
184 ["local:review", "user", path.join(managedInstall, "skills", "review", "SKILL.md")],
185 ["plugin:review", "user", path.join(userInstall, "skills", "review", "SKILL.md")],
186 ],
187 );
188 }
189 const worktree = path.join(tempDir, "worktree");
190 const worktreeGitDirectory = path.join(workspace, ".git", "worktrees", "fixture");
191 yield* fs.makeDirectory(worktree);
192 yield* fs.makeDirectory(worktreeGitDirectory, { recursive: true });
193 yield* fs.writeFileString(path.join(worktree, ".git"), `gitdir: ${worktreeGitDirectory}\n`);
194 yield* fs.writeFileString(path.join(worktreeGitDirectory, "commondir"), "../..\n");
195 yield* fs.writeFileString(
196 path.join(worktreeGitDirectory, "gitdir"),
197 path.join(worktree, ".git"),
198 );
199 assert.deepEqual(
200 yield* discoverClaudeSkills({ homePath: configDir }, worktree),
201 localSettings,
202 );
203 const linkedWorktree = path.join(tempDir, "linked-worktree");
204 yield* fs.symlink(worktree, linkedWorktree);
205 assert.deepEqual(
206 yield* discoverClaudeSkills({ homePath: configDir }, linkedWorktree),
207 localSettings,
208 );
209 }),
210 );
211
212 it.effect("resolves each install record's project repository once per discovery", () =>
213 Effect.gen(function* () {
214 const fs = yield* FileSystem.FileSystem;
215 const path = yield* Path.Path;
216 // Real path: macOS temp dirs sit behind a /var -> /private/var symlink.
217 const tempDir = yield* fs.realPath(
218 yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" }),
219 );
220 const configDir = path.join(tempDir, "claude-home");
221 const workspace = path.join(tempDir, "workspace");
222 const otherProject = path.join(tempDir, "other", "packages", "app");
223 const sameRepoProject = path.join(workspace, "packages", "app");
224 yield* fs.makeDirectory(path.join(workspace, ".git"), { recursive: true });
225 yield* fs.makeDirectory(path.join(tempDir, "other", ".git"), { recursive: true });
226 yield* fs.makeDirectory(otherProject, { recursive: true });
227 yield* fs.makeDirectory(sameRepoProject, { recursive: true });
228 const elsewhereInstall = path.join(configDir, "plugins", "elsewhere");
229 const sameRepoInstall = path.join(configDir, "plugins", "same-repo");
230 yield* writeSkill(path.join(elsewhereInstall, "skills"), "elsewhere", "# Elsewhere");
231 yield* writeSkill(path.join(sameRepoInstall, "skills"), "same-repo", "# Same repo");
232 const records = Array.from({ length: 4 }, () => ({
233 scope: "project",
234 projectPath: otherProject,
235 installPath: elsewhereInstall,
236 }));
237 const plugins = ["a@shop", "b@shop", "c@shop"];
238 yield* fs.writeFileString(
239 path.join(configDir, "plugins", "installed_plugins.json"),
240 JSON.stringify({
241 plugins: {
242 ...Object.fromEntries(plugins.map((key) => [key, records])),
243 "d@shop": [
244 { scope: "project", projectPath: sameRepoProject, installPath: sameRepoInstall },
245 ],
246 },
247 }),
248 );
249 yield* fs.writeFileString(
250 path.join(configDir, "settings.json"),
251 JSON.stringify({
252 enabledPlugins: Object.fromEntries([...plugins, "d@shop"].map((key) => [key, true])),
253 }),
254 );
255
256 const probed: Array<string> = [];
257 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace).pipe(
258 Effect.provideService(FileSystem.FileSystem, {
259 ...fs,
260 exists: (target) => {
261 probed.push(target);
262 return fs.exists(target);
263 },
264 }),
265 );
266 assert.strictEqual(
267 probed.filter((target) => target === path.join(otherProject, ".git")).length,
268 1,
269 );
270 assert.deepEqual(
271 skills.map((skill) => skill.name),
272 ["d:same-repo"],
273 );
274 }),
275 );
276
277 it.effect("publishes and dispatches canonical plugin folder names regardless of aliases", () =>
278 Effect.gen(function* () {
279 const fs = yield* FileSystem.FileSystem;
280 const path = yield* Path.Path;
281 const configDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
282 const plugin = path.join(configDir, "plugins", "installed");
283 yield* writeSkill(path.join(plugin, "skills"), "review", "---\nname: review-alias\n---\n");
284 yield* writeSkill(path.join(plugin, "skills"), "alias", "---\nname: dot.alias\n---\n");
285 yield* fs.writeFileString(
286 path.join(configDir, "plugins", "installed_plugins.json"),
287 JSON.stringify({ plugins: { "plugin@shop": [{ scope: "user", installPath: plugin }] } }),
288 );
289 yield* fs.writeFileString(
290 path.join(configDir, "settings.json"),
291 '{"enabledPlugins":{"plugin@shop":true}}',
292 );
293
294 const skills = yield* discoverClaudeSkills({ homePath: configDir });
295 assert.deepEqual(
296 planClaudeSkillDispatch(
297 "$plugin:alias focus on auth",
298 new Map(skills.map((skill) => [skill.name, skill])),
299 ),
300 {
301 leadingText: undefined,
302 commandText: "/plugin:alias focus on auth",
303 },
304 );
305 assert.deepEqual(
306 skills.map((skill) => skill.name),
307 ["plugin:alias", "plugin:review"],
308 );
309 }),
310 );
311
312 it.effect("uses the native cache root, root-skill fallback and manifest path boundaries", () =>
313 Effect.gen(function* () {
314 const fs = yield* FileSystem.FileSystem;
315 const path = yield* Path.Path;
316 const workspace = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
317 const configDir = path.join(workspace, "config");
318 const pluginsDir = path.join(workspace, "plugin-cache");
319 const plugin = path.join(pluginsDir, "installed");
320 const outside = path.join(workspace, "outside");
321 yield* writeSkill(pluginsDir, "installed", "---\nname: plugin:root.alias\n---\n");
322 yield* fs.makeDirectory(configDir);
323 yield* fs.writeFileString(
324 path.join(configDir, "settings.json"),
325 '{"enabledPlugins":{"plugin@shop":true}}',
326 );
327 yield* fs.writeFileString(
328 path.join(pluginsDir, "installed_plugins.json"),
329 JSON.stringify({ plugins: { "plugin@shop": [{ scope: "user", installPath: plugin }] } }),
330 );
331 const environment = { CLAUDE_CODE_PLUGIN_CACHE_DIR: "plugin-cache" };
332 assert.deepEqual(
333 (yield* discoverClaudeSkills({ homePath: configDir }, workspace, environment)).map(
334 (skill) => skill.name,
335 ),
336 ["plugin:root-alias"],
337 );
338
339 yield* writeSkill(path.join(plugin, "skills"), "plain", "# Plain");
340 yield* writeSkill(plugin, "custom", "---\nname: custom.review\n---\n");
341 yield* writeSkill(outside, "escaped", "# Outside");
342 yield* fs.symlink(outside, path.join(plugin, "escape"));
343 yield* fs.makeDirectory(path.join(plugin, ".claude-plugin"));
344 yield* fs.writeFileString(
345 path.join(plugin, ".claude-plugin", "plugin.json"),
346 '{"skills":["./custom","./escape","../../outside"]}',
347 );
348 assert.deepEqual(
349 (yield* discoverClaudeSkills({ homePath: configDir }, workspace, environment)).map(
350 (skill) => skill.name,
351 ),
352 ["plugin:custom-review", "plugin:plain"],
353 );
354 }),
355 );
356
357 it.effect("discovers user and project skills with frontmatter metadata", () =>
358 Effect.gen(function* () {
359 const fs = yield* FileSystem.FileSystem;
360 const path = yield* Path.Path;
361 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
362 const configDir = path.join(tempDir, "claude-home");
363 const workspace = path.join(tempDir, "workspace");
364
365 yield* writeSkill(
366 path.join(configDir, "skills"),
367 "codex-review",
368 [
369 "---",
370 "name: codex-review",
371 "description: Ask Codex for a review.",
372 "---",
373 "",
374 "# Body",
375 ].join("\n"),
376 );
377 yield* writeSkill(
378 path.join(workspace, ".claude", "skills"),
379 "deploy",
380 ["---", "name: deploy", "description: Deploy the app.", "---", "", "# Deploy"].join("\n"),
381 );
382
383 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
384
385 assert.deepEqual(skills, [
386 {
387 name: "codex-review",
388 path: path.join(configDir, "skills", "codex-review", "SKILL.md"),
389 enabled: true,
390 scope: "user",
391 description: "Ask Codex for a review.",
392 },
393 {
394 name: "deploy",
395 path: path.join(workspace, ".claude", "skills", "deploy", "SKILL.md"),
396 enabled: true,
397 scope: "project",
398 description: "Deploy the app.",
399 },
400 ]);
401 }),
402 );
403
404 it.effect("discovers skills from the instance's --add-dir launch args", () =>
405 Effect.gen(function* () {
406 const fs = yield* FileSystem.FileSystem;
407 const path = yield* Path.Path;
408 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
409 const configDir = path.join(tempDir, "claude-home");
410 const workspace = path.join(tempDir, "workspace");
411 const extraDir = path.join(workspace, "extra skills");
412 yield* fs.makeDirectory(workspace, { recursive: true });
413 yield* writeSkill(
414 path.join(extraDir, ".claude", "skills"),
415 "demo",
416 ["---", "description: From an additional directory.", "---"].join("\n"),
417 );
418
419 assert.deepEqual(yield* discoverClaudeSkills({ homePath: configDir }, workspace), []);
420 for (const launchArgs of [
421 `--add-dir "${extraDir}"`,
422 `--add-dir="${extraDir}"`,
423 '--add-dir "extra skills"',
424 '--add-dir="extra skills"',
425 `--add-dir missing --add-dir "${extraDir}"`,
426 `--add-dir "${extraDir}" --add-dir missing`,
427 `--add-dir missing "${extraDir}"`,
428 ]) {
429 const settings = { homePath: configDir, launchArgs };
430 const skills = yield* discoverClaudeSkills(settings, workspace);
431 assert.deepEqual(skills, [
432 {
433 name: "demo",
434 path: path.join(extraDir, ".claude", "skills", "demo", "SKILL.md"),
435 enabled: true,
436 scope: "project",
437 description: "From an additional directory.",
438 },
439 ]);
440 }
441 const settings = { homePath: configDir, launchArgs: `--add-dir "${extraDir}"` };
442 const skills = yield* discoverClaudeSkills(settings, workspace);
443 assert.deepEqual(
444 planClaudeSkillDispatch(
445 "$demo",
446 new Map(skills.map((skill) => [skill.name, { path: skill.path }])),
447 ),
448 {
449 leadingText: undefined,
450 commandText: "/demo",
451 },
452 );
453 yield* writeSkill(
454 path.join(workspace, ".claude", "skills"),
455 "demo",
456 "---\ndescription: Project copy.\n---",
457 );
458 const projectSkills = yield* discoverClaudeSkills(settings, workspace);
459 assert.equal(projectSkills[0]?.description, "Project copy.");
460 for (const launchArgs of ["--add-dir", '--add-dir=""', '--add-dir "extra skills"']) {
461 const settings = { homePath: configDir, launchArgs };
462 assert.deepEqual(yield* discoverClaudeSkills(settings), []);
463 }
464 }),
465 );
466
467 it.effect("prefers user skills on name collisions even with a stray .agents copy", () =>
468 Effect.gen(function* () {
469 const fs = yield* FileSystem.FileSystem;
470 const path = yield* Path.Path;
471 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
472 const configDir = path.join(tempDir, "claude-home");
473 const workspace = path.join(tempDir, "workspace");
474
475 yield* writeSkill(
476 path.join(configDir, "skills"),
477 "deploy",
478 ["---", "name: deploy", "description: User deploy.", "---"].join("\n"),
479 );
480 yield* writeSkill(
481 path.join(workspace, ".agents", "skills"),
482 "deploy",
483 ["---", "name: deploy", "description: Agents deploy.", "---"].join("\n"),
484 );
485 yield* writeSkill(
486 path.join(workspace, ".claude", "skills"),
487 "deploy",
488 ["---", "name: deploy", "description: Claude deploy.", "---"].join("\n"),
489 );
490
491 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
492
493 assert.deepEqual(skills, [
494 {
495 name: "deploy",
496 path: path.join(configDir, "skills", "deploy", "SKILL.md"),
497 enabled: true,
498 scope: "user",
499 description: "User deploy.",
500 },
501 ]);
502 }),
503 );
504
505 it.effect("recovers colon-bearing descriptions with invocation metadata intact", () =>
506 Effect.gen(function* () {
507 const fs = yield* FileSystem.FileSystem;
508 const path = yield* Path.Path;
509 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
510 const configDir = path.join(tempDir, "claude-home");
511
512 for (const [description, comment] of [
513 ["Browser automation + AI test authoring via kane-cli: run browser objectives, ...", ""],
514 ['Read C:\\skills\\guide#tag: continue with "quoted".', " # trailing: comment"],
515 ] as const) {
516 yield* writeSkill(
517 path.join(configDir, "skills"),
518 "kane-cli",
519 [
520 "---",
521 "name: frontmatter-alias",
522 `description: ${description}${comment}`,
523 "allowed-tools: [Read, Write]",
524 "disable-model-invocation: yes",
525 "user-invocable: no",
526 "---",
527 ].join("\n"),
528 );
529
530 const skills = yield* discoverClaudeSkills({ homePath: configDir }, undefined);
531
532 assert.deepEqual(skills, [
533 {
534 name: "kane-cli",
535 path: path.join(configDir, "skills", "kane-cli", "SKILL.md"),
536 enabled: true,
537 scope: "user",
538 description,
539 userInvocationOnly: true,
540 userInvocable: false,
541 },
542 ]);
543 }
544 }),
545 );
546
547 it.effect("falls back to the directory name and skips malformed frontmatter", () =>
548 Effect.gen(function* () {
549 const fs = yield* FileSystem.FileSystem;
550 const path = yield* Path.Path;
551 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
552 const configDir = path.join(tempDir, "claude-home");
553 const skillsDir = path.join(configDir, "skills");
554
555 yield* writeSkill(skillsDir, "no-frontmatter", "# Just a heading\n");
556 for (const [directoryName, field] of [
557 ["broken-yaml", "name: [unclosed"],
558 ["broken-tools", "allowed-tools: [Read, Write"],
559 ["broken-quoted", 'name: "unclosed: text'],
560 ] as const) {
561 yield* writeSkill(
562 skillsDir,
563 directoryName,
564 ["---", "description: Run: browser objectives.", field, "---"].join("\n"),
565 );
566 }
567 yield* fs.makeDirectory(skillsDir, { recursive: true });
568 yield* fs.writeFileString(path.join(skillsDir, "README.md"), "not a skill");
569
570 const skills = yield* discoverClaudeSkills({ homePath: configDir }, undefined);
571
572 // Claude falls back to directory names without frontmatter, but skips malformed frontmatter.
573 assert.deepEqual(
574 skills.map((skill) => skill.name),
575 ["no-frontmatter"],
576 );
577 assert.equal(skills[0]?.description, undefined);
578 }),
579 );
580
581 it.effect("honors CLAUDE_CONFIG_DIR from the environment when homePath is unset", () =>
582 Effect.gen(function* () {
583 const fs = yield* FileSystem.FileSystem;
584 const path = yield* Path.Path;
585 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
586 const environmentConfigDir = path.join(tempDir, "env-config");
587
588 yield* writeSkill(
589 path.join(environmentConfigDir, "skills"),
590 "env-skill",
591 ["---", "name: env-skill", "description: From env config dir.", "---"].join("\n"),
592 );
593
594 const skills = yield* discoverClaudeSkills({ homePath: "" }, undefined, {
595 CLAUDE_CONFIG_DIR: environmentConfigDir,
596 });
597
598 assert.deepEqual(
599 skills.map((skill) => skill.name),
600 ["env-skill"],
601 );
602
603 const explicitHome = path.join(tempDir, "explicit-home");
604 yield* writeSkill(
605 path.join(explicitHome, "skills"),
606 "explicit-skill",
607 ["---", "name: explicit-skill", "---"].join("\n"),
608 );
609 const explicitSkills = yield* discoverClaudeSkills({ homePath: explicitHome }, undefined, {
610 CLAUDE_CONFIG_DIR: environmentConfigDir,
611 });
612 assert.deepEqual(
613 explicitSkills.map((skill) => skill.name),
614 ["explicit-skill"],
615 );
616 }),
617 );
618
619 it.effect("resolves a relative CLAUDE_CONFIG_DIR against the workspace cwd", () =>
620 Effect.gen(function* () {
621 const fs = yield* FileSystem.FileSystem;
622 const path = yield* Path.Path;
623 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
624 const workspace = path.join(tempDir, "workspace");
625 yield* fs.makeDirectory(workspace, { recursive: true });
626
627 // The CLI resolves relative CLAUDE_CONFIG_DIR against workspace cwd.
628 yield* writeSkill(
629 path.join(workspace, "relative-config", "skills"),
630 "relative-skill",
631 ["---", "name: relative-skill", "---"].join("\n"),
632 );
633
634 const skills = yield* discoverClaudeSkills({ homePath: "" }, workspace, {
635 CLAUDE_CONFIG_DIR: "relative-config",
636 });
637
638 assert.deepEqual(
639 skills.map((skill) => skill.name),
640 ["relative-skill"],
641 );
642 assert.equal(skills[0]?.scope, "user");
643 }),
644 );
645
646 it.effect("disables skills switched off by skillOverrides", () =>
647 Effect.gen(function* () {
648 const fs = yield* FileSystem.FileSystem;
649 const path = yield* Path.Path;
650 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
651 const configDir = path.join(tempDir, "claude-home");
652 const workspace = path.join(tempDir, "workspace");
653
654 for (const name of ["kept", "off-by-user", "off-by-project"]) {
655 yield* writeSkill(
656 path.join(configDir, "skills"),
657 name,
658 ["---", `name: ${name}`, "---", "", "# Body"].join("\n"),
659 );
660 }
661
662 yield* fs.makeDirectory(configDir, { recursive: true });
663 yield* fs.writeFileString(
664 path.join(configDir, "settings.json"),
665 '{ "skillOverrides": { "off-by-user": "off", "kept": "on" } }',
666 );
667 yield* fs.makeDirectory(path.join(workspace, ".claude"), { recursive: true });
668 yield* fs.writeFileString(
669 path.join(workspace, ".claude", "settings.json"),
670 '{ "skillOverrides": { "off-by-project": "off" } }',
671 );
672
673 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
674
675 assert.deepEqual(
676 skills.map((skill) => [skill.name, skill.enabled]),
677 [
678 ["kept", true],
679 ["off-by-project", false],
680 ["off-by-user", false],
681 ],
682 );
683 }),
684 );
685
686 it.effect("ignores unreadable settings when resolving skillOverrides", () =>
687 Effect.gen(function* () {
688 const fs = yield* FileSystem.FileSystem;
689 const path = yield* Path.Path;
690 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
691 const configDir = path.join(tempDir, "claude-home");
692
693 yield* writeSkill(
694 path.join(configDir, "skills"),
695 "kept",
696 ["---", "name: kept", "---", "", "# Body"].join("\n"),
697 );
698 yield* fs.writeFileString(path.join(configDir, "settings.json"), "{ not json");
699
700 const skills = yield* discoverClaudeSkills({ homePath: configDir });
701
702 assert.deepEqual(
703 skills.map((skill) => [skill.name, skill.enabled]),
704 [["kept", true]],
705 );
706 }),
707 );
708
709 it.effect("treats a user-invocable-only override like disable-model-invocation", () =>
710 Effect.gen(function* () {
711 const fs = yield* FileSystem.FileSystem;
712 const path = yield* Path.Path;
713 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
714 const configDir = path.join(tempDir, "claude-home");
715
716 yield* writeSkill(
717 path.join(configDir, "skills"),
718 "ask-matt",
719 ["---", "name: ask-matt", "---", "", "# Body"].join("\n"),
720 );
721 yield* fs.writeFileString(
722 path.join(configDir, "settings.json"),
723 '{ "skillOverrides": { "ask-matt": "user-invocable-only" } }',
724 );
725
726 const skills = yield* discoverClaudeSkills({ homePath: configDir });
727
728 assert.deepEqual(
729 skills.map((skill) => [skill.name, skill.enabled, skill.userInvocationOnly === true]),
730 [["ask-matt", true, true]],
731 );
732 }),
733 );
734
735 it.effect("drops every override in a file when one value is invalid, as Claude Code does", () =>
736 Effect.gen(function* () {
737 const fs = yield* FileSystem.FileSystem;
738 const path = yield* Path.Path;
739 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
740 const configDir = path.join(tempDir, "claude-home");
741
742 for (const name of ["unknown-mode", "boolean-false", "sibling-off"]) {
743 yield* writeSkill(
744 path.join(configDir, "skills"),
745 name,
746 ["---", `name: ${name}`, "---", "", "# Body"].join("\n"),
747 );
748 }
749 // Claude ignores the entire override map when any value is an unknown string or boolean.
750 yield* fs.writeFileString(
751 path.join(configDir, "settings.json"),
752 '{ "skillOverrides": { "unknown-mode": "some-future-mode", "boolean-false": false, "sibling-off": "off" } }',
753 );
754
755 const skills = yield* discoverClaudeSkills({ homePath: configDir });
756
757 assert.deepEqual(
758 skills.map((skill) => [skill.name, skill.enabled]),
759 [
760 ["boolean-false", true],
761 ["sibling-off", true],
762 ["unknown-mode", true],
763 ],
764 );
765 }),
766 );
767
768 it.effect("reads repository root settings from a nested workspace", () =>
769 Effect.gen(function* () {
770 const fs = yield* FileSystem.FileSystem;
771 const path = yield* Path.Path;
772 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
773 const configDir = path.join(tempDir, "claude-home");
774 const repo = path.join(tempDir, "repo");
775 const workspace = path.join(repo, "packages", "app");
776
777 for (const name of ["root-off", "root-off-cwd-on", "cwd-off-root-on"]) {
778 yield* writeSkill(
779 path.join(configDir, "skills"),
780 name,
781 ["---", `name: ${name}`, "---", "", "# Body"].join("\n"),
782 );
783 }
784 yield* fs.makeDirectory(path.join(repo, ".git"), { recursive: true });
785 yield* fs.makeDirectory(path.join(repo, ".claude"), { recursive: true });
786 yield* fs.makeDirectory(path.join(workspace, ".claude"), { recursive: true });
787 // The CLI ignores the root's plain settings.json from a nested cwd.
788 yield* fs.writeFileString(
789 path.join(repo, ".claude", "settings.json"),
790 '{ "skillOverrides": { "cwd-off-root-on": "off" } }',
791 );
792 // The root local file outranks the workspace local file, as in the CLI.
793 yield* fs.writeFileString(
794 path.join(repo, ".claude", "settings.local.json"),
795 '{ "skillOverrides": { "root-off": "off", "root-off-cwd-on": "off", "cwd-off-root-on": "on" } }',
796 );
797 yield* fs.writeFileString(
798 path.join(workspace, ".claude", "settings.local.json"),
799 '{ "skillOverrides": { "root-off-cwd-on": "on", "cwd-off-root-on": "off" } }',
800 );
801
802 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
803
804 assert.deepEqual(
805 skills.map((skill) => [skill.name, skill.enabled]),
806 [
807 ["cwd-off-root-on", true],
808 ["root-off", false],
809 ["root-off-cwd-on", false],
810 ],
811 );
812 }),
813 );
814
815 it.effect("ignores ancestor settings outside a repository", () =>
816 Effect.gen(function* () {
817 const fs = yield* FileSystem.FileSystem;
818 const path = yield* Path.Path;
819 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
820 const configDir = path.join(tempDir, "claude-home");
821 const parent = path.join(tempDir, "not-a-repo");
822 const workspace = path.join(parent, "workspace");
823
824 yield* writeSkill(
825 path.join(configDir, "skills"),
826 "kept",
827 ["---", "name: kept", "---", "", "# Body"].join("\n"),
828 );
829 yield* fs.makeDirectory(path.join(parent, ".claude"), { recursive: true });
830 yield* fs.makeDirectory(workspace, { recursive: true });
831 yield* fs.writeFileString(
832 path.join(parent, ".claude", "settings.local.json"),
833 '{ "skillOverrides": { "kept": "off" } }',
834 );
835
836 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
837
838 assert.deepEqual(
839 skills.map((skill) => [skill.name, skill.enabled]),
840 [["kept", true]],
841 );
842 }),
843 );
844
845 it.effect("identifies a skill by its directory, as Claude Code does", () =>
846 Effect.gen(function* () {
847 const fs = yield* FileSystem.FileSystem;
848 const path = yield* Path.Path;
849 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
850 const configDir = path.join(tempDir, "claude-home");
851
852 yield* writeSkill(
853 path.join(configDir, "skills"),
854 "probe-alias",
855 ["---", "name: probe-alias-frontmatter", "---", "", "# Body"].join("\n"),
856 );
857 yield* fs.writeFileString(
858 path.join(configDir, "settings.json"),
859 '{ "skillOverrides": { "probe-alias-frontmatter": "off" } }',
860 );
861
862 const skills = yield* discoverClaudeSkills({ homePath: configDir });
863
864 assert.deepEqual(
865 skills.map((skill) => [skill.name, skill.enabled]),
866 [["probe-alias", true]],
867 );
868 }),
869 );
870
871 // regression: #9128 skills picked from the composer did not run
872 it.effect("switches a skill off by its directory name", () =>
873 Effect.gen(function* () {
874 const fs = yield* FileSystem.FileSystem;
875 const path = yield* Path.Path;
876 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
877 const configDir = path.join(tempDir, "claude-home");
878
879 yield* writeSkill(
880 path.join(configDir, "skills"),
881 "probe-alias",
882 ["---", "name: probe-alias-frontmatter", "---", "", "# Body"].join("\n"),
883 );
884 yield* fs.writeFileString(
885 path.join(configDir, "settings.json"),
886 '{ "skillOverrides": { "probe-alias": "off" } }',
887 );
888
889 const skills = yield* discoverClaudeSkills({ homePath: configDir });
890
891 assert.deepEqual(
892 skills.map((skill) => [skill.name, skill.enabled]),
893 [["probe-alias", false]],
894 );
895 }),
896 );
897
898 it.effect("accepts the YAML 1.1 boolean spellings Claude Code allows", () =>
899 Effect.gen(function* () {
900 const fs = yield* FileSystem.FileSystem;
901 const path = yield* Path.Path;
902 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
903 const configDir = path.join(tempDir, "claude-home");
904 const skillsDir = path.join(configDir, "skills");
905
906 yield* writeSkill(
907 skillsDir,
908 "user-only-yes",
909 ["---", "disable-model-invocation: yes", "---", "", "# Body"].join("\n"),
910 );
911 yield* writeSkill(
912 skillsDir,
913 "agent-only-no",
914 ["---", "user-invocable: no", "---", "", "# Body"].join("\n"),
915 );
916 yield* writeSkill(
917 skillsDir,
918 "plain-off",
919 ["---", "disable-model-invocation: off", "---", "", "# Body"].join("\n"),
920 );
921
922 const skills = yield* discoverClaudeSkills({ homePath: configDir });
923
924 assert.deepEqual(
925 skills.map((skill) => [
926 skill.name,
927 skill.userInvocationOnly === true,
928 skill.userInvocable === false,
929 ]),
930 [
931 ["agent-only-no", false, true],
932 ["plain-off", false, false],
933 ["user-only-yes", true, false],
934 ],
935 );
936 }),
937 );
938});