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("publishes and dispatches canonical plugin folder names regardless of aliases", () =>
213 Effect.gen(function* () {
214 const fs = yield* FileSystem.FileSystem;
215 const path = yield* Path.Path;
216 const configDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
217 const plugin = path.join(configDir, "plugins", "installed");
218 yield* writeSkill(path.join(plugin, "skills"), "review", "---\nname: review-alias\n---\n");
219 yield* writeSkill(path.join(plugin, "skills"), "alias", "---\nname: dot.alias\n---\n");
220 yield* fs.writeFileString(
221 path.join(configDir, "plugins", "installed_plugins.json"),
222 JSON.stringify({ plugins: { "plugin@shop": [{ scope: "user", installPath: plugin }] } }),
223 );
224 yield* fs.writeFileString(
225 path.join(configDir, "settings.json"),
226 '{"enabledPlugins":{"plugin@shop":true}}',
227 );
228
229 const skills = yield* discoverClaudeSkills({ homePath: configDir });
230 assert.deepEqual(
231 planClaudeSkillDispatch(
232 "$plugin:alias focus on auth",
233 new Map(skills.map((skill) => [skill.name, skill])),
234 ),
235 {
236 leadingText: undefined,
237 commandText: "/plugin:alias focus on auth",
238 skillName: "plugin:alias",
239 },
240 );
241 assert.deepEqual(
242 skills.map((skill) => skill.name),
243 ["plugin:alias", "plugin:review"],
244 );
245 }),
246 );
247
248 it.effect("uses the native cache root, root-skill fallback and manifest path boundaries", () =>
249 Effect.gen(function* () {
250 const fs = yield* FileSystem.FileSystem;
251 const path = yield* Path.Path;
252 const workspace = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
253 const configDir = path.join(workspace, "config");
254 const pluginsDir = path.join(workspace, "plugin-cache");
255 const plugin = path.join(pluginsDir, "installed");
256 const outside = path.join(workspace, "outside");
257 yield* writeSkill(pluginsDir, "installed", "---\nname: plugin:root.alias\n---\n");
258 yield* fs.makeDirectory(configDir);
259 yield* fs.writeFileString(
260 path.join(configDir, "settings.json"),
261 '{"enabledPlugins":{"plugin@shop":true}}',
262 );
263 yield* fs.writeFileString(
264 path.join(pluginsDir, "installed_plugins.json"),
265 JSON.stringify({ plugins: { "plugin@shop": [{ scope: "user", installPath: plugin }] } }),
266 );
267 const environment = { CLAUDE_CODE_PLUGIN_CACHE_DIR: "plugin-cache" };
268 assert.deepEqual(
269 (yield* discoverClaudeSkills({ homePath: configDir }, workspace, environment)).map(
270 (skill) => skill.name,
271 ),
272 ["plugin:root-alias"],
273 );
274
275 yield* writeSkill(path.join(plugin, "skills"), "plain", "# Plain");
276 yield* writeSkill(plugin, "custom", "---\nname: custom.review\n---\n");
277 yield* writeSkill(outside, "escaped", "# Outside");
278 yield* fs.symlink(outside, path.join(plugin, "escape"));
279 yield* fs.makeDirectory(path.join(plugin, ".claude-plugin"));
280 yield* fs.writeFileString(
281 path.join(plugin, ".claude-plugin", "plugin.json"),
282 '{"skills":["./custom","./escape","../../outside"]}',
283 );
284 assert.deepEqual(
285 (yield* discoverClaudeSkills({ homePath: configDir }, workspace, environment)).map(
286 (skill) => skill.name,
287 ),
288 ["plugin:custom-review", "plugin:plain"],
289 );
290 }),
291 );
292
293 it.effect("discovers user and project skills with frontmatter metadata", () =>
294 Effect.gen(function* () {
295 const fs = yield* FileSystem.FileSystem;
296 const path = yield* Path.Path;
297 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
298 const configDir = path.join(tempDir, "claude-home");
299 const workspace = path.join(tempDir, "workspace");
300
301 yield* writeSkill(
302 path.join(configDir, "skills"),
303 "codex-review",
304 [
305 "---",
306 "name: codex-review",
307 "description: Ask Codex for a review.",
308 "---",
309 "",
310 "# Body",
311 ].join("\n"),
312 );
313 yield* writeSkill(
314 path.join(workspace, ".claude", "skills"),
315 "deploy",
316 ["---", "name: deploy", "description: Deploy the app.", "---", "", "# Deploy"].join("\n"),
317 );
318
319 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
320
321 assert.deepEqual(skills, [
322 {
323 name: "codex-review",
324 path: path.join(configDir, "skills", "codex-review", "SKILL.md"),
325 enabled: true,
326 scope: "user",
327 description: "Ask Codex for a review.",
328 },
329 {
330 name: "deploy",
331 path: path.join(workspace, ".claude", "skills", "deploy", "SKILL.md"),
332 enabled: true,
333 scope: "project",
334 description: "Deploy the app.",
335 },
336 ]);
337 }),
338 );
339
340 it.effect("discovers skills from the instance's --add-dir launch args", () =>
341 Effect.gen(function* () {
342 const fs = yield* FileSystem.FileSystem;
343 const path = yield* Path.Path;
344 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
345 const configDir = path.join(tempDir, "claude-home");
346 const workspace = path.join(tempDir, "workspace");
347 const extraDir = path.join(workspace, "extra skills");
348 yield* fs.makeDirectory(workspace, { recursive: true });
349 yield* writeSkill(
350 path.join(extraDir, ".claude", "skills"),
351 "demo",
352 ["---", "description: From an additional directory.", "---"].join("\n"),
353 );
354
355 assert.deepEqual(yield* discoverClaudeSkills({ homePath: configDir }, workspace), []);
356 for (const launchArgs of [
357 `--add-dir "${extraDir}"`,
358 `--add-dir="${extraDir}"`,
359 '--add-dir "extra skills"',
360 '--add-dir="extra skills"',
361 `--add-dir missing --add-dir "${extraDir}"`,
362 ]) {
363 const settings = { homePath: configDir, launchArgs };
364 const skills = yield* discoverClaudeSkills(settings, workspace);
365 assert.deepEqual(skills, [
366 {
367 name: "demo",
368 path: path.join(extraDir, ".claude", "skills", "demo", "SKILL.md"),
369 enabled: true,
370 scope: "project",
371 description: "From an additional directory.",
372 },
373 ]);
374 }
375 const settings = { homePath: configDir, launchArgs: `--add-dir "${extraDir}"` };
376 const skills = yield* discoverClaudeSkills(settings, workspace);
377 assert.deepEqual(
378 planClaudeSkillDispatch(
379 "$demo",
380 new Map(skills.map((skill) => [skill.name, { path: skill.path }])),
381 ),
382 {
383 leadingText: undefined,
384 commandText: "/demo",
385 skillName: "demo",
386 },
387 );
388 yield* writeSkill(
389 path.join(workspace, ".claude", "skills"),
390 "demo",
391 "---\ndescription: Project copy.\n---",
392 );
393 const projectSkills = yield* discoverClaudeSkills(settings, workspace);
394 assert.equal(projectSkills[0]?.description, "Project copy.");
395 for (const launchArgs of ["--add-dir", '--add-dir=""', '--add-dir "extra skills"']) {
396 const settings = { homePath: configDir, launchArgs };
397 assert.deepEqual(yield* discoverClaudeSkills(settings), []);
398 }
399 }),
400 );
401
402 it.effect("prefers user skills on name collisions even with a stray .agents copy", () =>
403 Effect.gen(function* () {
404 const fs = yield* FileSystem.FileSystem;
405 const path = yield* Path.Path;
406 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
407 const configDir = path.join(tempDir, "claude-home");
408 const workspace = path.join(tempDir, "workspace");
409
410 yield* writeSkill(
411 path.join(configDir, "skills"),
412 "deploy",
413 ["---", "name: deploy", "description: User deploy.", "---"].join("\n"),
414 );
415 yield* writeSkill(
416 path.join(workspace, ".agents", "skills"),
417 "deploy",
418 ["---", "name: deploy", "description: Agents deploy.", "---"].join("\n"),
419 );
420 yield* writeSkill(
421 path.join(workspace, ".claude", "skills"),
422 "deploy",
423 ["---", "name: deploy", "description: Claude deploy.", "---"].join("\n"),
424 );
425
426 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
427
428 assert.deepEqual(skills, [
429 {
430 name: "deploy",
431 path: path.join(configDir, "skills", "deploy", "SKILL.md"),
432 enabled: true,
433 scope: "user",
434 description: "User deploy.",
435 },
436 ]);
437 }),
438 );
439
440 it.effect("recovers colon-bearing descriptions with invocation metadata intact", () =>
441 Effect.gen(function* () {
442 const fs = yield* FileSystem.FileSystem;
443 const path = yield* Path.Path;
444 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
445 const configDir = path.join(tempDir, "claude-home");
446
447 for (const [description, comment] of [
448 ["Browser automation + AI test authoring via kane-cli: run browser objectives, ...", ""],
449 ['Read C:\\skills\\guide#tag: continue with "quoted".', " # trailing: comment"],
450 ] as const) {
451 yield* writeSkill(
452 path.join(configDir, "skills"),
453 "kane-cli",
454 [
455 "---",
456 "name: frontmatter-alias",
457 `description: ${description}${comment}`,
458 "allowed-tools: [Read, Write]",
459 "disable-model-invocation: yes",
460 "user-invocable: no",
461 "---",
462 ].join("\n"),
463 );
464
465 const skills = yield* discoverClaudeSkills({ homePath: configDir }, undefined);
466
467 assert.deepEqual(skills, [
468 {
469 name: "kane-cli",
470 path: path.join(configDir, "skills", "kane-cli", "SKILL.md"),
471 enabled: true,
472 scope: "user",
473 description,
474 userInvocationOnly: true,
475 userInvocable: false,
476 },
477 ]);
478 }
479 }),
480 );
481
482 it.effect("falls back to the directory name and skips malformed frontmatter", () =>
483 Effect.gen(function* () {
484 const fs = yield* FileSystem.FileSystem;
485 const path = yield* Path.Path;
486 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
487 const configDir = path.join(tempDir, "claude-home");
488 const skillsDir = path.join(configDir, "skills");
489
490 yield* writeSkill(skillsDir, "no-frontmatter", "# Just a heading\n");
491 for (const [directoryName, field] of [
492 ["broken-yaml", "name: [unclosed"],
493 ["broken-tools", "allowed-tools: [Read, Write"],
494 ["broken-quoted", 'name: "unclosed: text'],
495 ] as const) {
496 yield* writeSkill(
497 skillsDir,
498 directoryName,
499 ["---", "description: Run: browser objectives.", field, "---"].join("\n"),
500 );
501 }
502 yield* fs.makeDirectory(skillsDir, { recursive: true });
503 yield* fs.writeFileString(path.join(skillsDir, "README.md"), "not a skill");
504
505 const skills = yield* discoverClaudeSkills({ homePath: configDir }, undefined);
506
507 // A skill with no frontmatter falls back to its directory name; a skill
508 // whose frontmatter fails to parse is skipped entirely (Claude Code
509 // won't load it either).
510 assert.deepEqual(
511 skills.map((skill) => skill.name),
512 ["no-frontmatter"],
513 );
514 assert.equal(skills[0]?.description, undefined);
515 }),
516 );
517
518 it.effect("honors CLAUDE_CONFIG_DIR from the environment when homePath is unset", () =>
519 Effect.gen(function* () {
520 const fs = yield* FileSystem.FileSystem;
521 const path = yield* Path.Path;
522 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
523 const environmentConfigDir = path.join(tempDir, "env-config");
524
525 yield* writeSkill(
526 path.join(environmentConfigDir, "skills"),
527 "env-skill",
528 ["---", "name: env-skill", "description: From env config dir.", "---"].join("\n"),
529 );
530
531 const skills = yield* discoverClaudeSkills({ homePath: "" }, undefined, {
532 CLAUDE_CONFIG_DIR: environmentConfigDir,
533 });
534
535 assert.deepEqual(
536 skills.map((skill) => skill.name),
537 ["env-skill"],
538 );
539
540 const explicitHome = path.join(tempDir, "explicit-home");
541 yield* writeSkill(
542 path.join(explicitHome, "skills"),
543 "explicit-skill",
544 ["---", "name: explicit-skill", "---"].join("\n"),
545 );
546 const explicitSkills = yield* discoverClaudeSkills({ homePath: explicitHome }, undefined, {
547 CLAUDE_CONFIG_DIR: environmentConfigDir,
548 });
549 assert.deepEqual(
550 explicitSkills.map((skill) => skill.name),
551 ["explicit-skill"],
552 );
553 }),
554 );
555
556 it.effect("resolves a relative CLAUDE_CONFIG_DIR against the workspace cwd", () =>
557 Effect.gen(function* () {
558 const fs = yield* FileSystem.FileSystem;
559 const path = yield* Path.Path;
560 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
561 const workspace = path.join(tempDir, "workspace");
562 yield* fs.makeDirectory(workspace, { recursive: true });
563
564 // The spawned CLI resolves a relative CLAUDE_CONFIG_DIR against its own
565 // cwd (the workspace), so discovery must do the same.
566 yield* writeSkill(
567 path.join(workspace, "relative-config", "skills"),
568 "relative-skill",
569 ["---", "name: relative-skill", "---"].join("\n"),
570 );
571
572 const skills = yield* discoverClaudeSkills({ homePath: "" }, workspace, {
573 CLAUDE_CONFIG_DIR: "relative-config",
574 });
575
576 assert.deepEqual(
577 skills.map((skill) => skill.name),
578 ["relative-skill"],
579 );
580 assert.equal(skills[0]?.scope, "user");
581 }),
582 );
583
584 it.effect("disables skills switched off by skillOverrides", () =>
585 Effect.gen(function* () {
586 const fs = yield* FileSystem.FileSystem;
587 const path = yield* Path.Path;
588 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
589 const configDir = path.join(tempDir, "claude-home");
590 const workspace = path.join(tempDir, "workspace");
591
592 for (const name of ["kept", "off-by-user", "off-by-project"]) {
593 yield* writeSkill(
594 path.join(configDir, "skills"),
595 name,
596 ["---", `name: ${name}`, "---", "", "# Body"].join("\n"),
597 );
598 }
599
600 yield* fs.makeDirectory(configDir, { recursive: true });
601 yield* fs.writeFileString(
602 path.join(configDir, "settings.json"),
603 '{ "skillOverrides": { "off-by-user": "off", "kept": "on" } }',
604 );
605 yield* fs.makeDirectory(path.join(workspace, ".claude"), { recursive: true });
606 yield* fs.writeFileString(
607 path.join(workspace, ".claude", "settings.json"),
608 '{ "skillOverrides": { "off-by-project": "off" } }',
609 );
610
611 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
612
613 assert.deepEqual(
614 skills.map((skill) => [skill.name, skill.enabled]),
615 [
616 ["kept", true],
617 ["off-by-project", false],
618 ["off-by-user", false],
619 ],
620 );
621 }),
622 );
623
624 it.effect("ignores unreadable settings when resolving skillOverrides", () =>
625 Effect.gen(function* () {
626 const fs = yield* FileSystem.FileSystem;
627 const path = yield* Path.Path;
628 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
629 const configDir = path.join(tempDir, "claude-home");
630
631 yield* writeSkill(
632 path.join(configDir, "skills"),
633 "kept",
634 ["---", "name: kept", "---", "", "# Body"].join("\n"),
635 );
636 yield* fs.writeFileString(path.join(configDir, "settings.json"), "{ not json");
637
638 const skills = yield* discoverClaudeSkills({ homePath: configDir });
639
640 assert.deepEqual(
641 skills.map((skill) => [skill.name, skill.enabled]),
642 [["kept", true]],
643 );
644 }),
645 );
646
647 it.effect("treats a user-invocable-only override like disable-model-invocation", () =>
648 Effect.gen(function* () {
649 const fs = yield* FileSystem.FileSystem;
650 const path = yield* Path.Path;
651 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
652 const configDir = path.join(tempDir, "claude-home");
653
654 yield* writeSkill(
655 path.join(configDir, "skills"),
656 "ask-matt",
657 ["---", "name: ask-matt", "---", "", "# Body"].join("\n"),
658 );
659 yield* fs.writeFileString(
660 path.join(configDir, "settings.json"),
661 '{ "skillOverrides": { "ask-matt": "user-invocable-only" } }',
662 );
663
664 const skills = yield* discoverClaudeSkills({ homePath: configDir });
665
666 assert.deepEqual(
667 skills.map((skill) => [skill.name, skill.enabled, skill.userInvocationOnly === true]),
668 [["ask-matt", true, true]],
669 );
670 }),
671 );
672
673 it.effect("drops every override in a file when one value is invalid, as Claude Code does", () =>
674 Effect.gen(function* () {
675 const fs = yield* FileSystem.FileSystem;
676 const path = yield* Path.Path;
677 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
678 const configDir = path.join(tempDir, "claude-home");
679
680 for (const name of ["unknown-mode", "boolean-false", "sibling-off"]) {
681 yield* writeSkill(
682 path.join(configDir, "skills"),
683 name,
684 ["---", `name: ${name}`, "---", "", "# Body"].join("\n"),
685 );
686 }
687 // Verified against the CLI: with an unknown string or a boolean in the
688 // map, the valid "off" sibling is ignored too and every skill runs.
689 yield* fs.writeFileString(
690 path.join(configDir, "settings.json"),
691 '{ "skillOverrides": { "unknown-mode": "some-future-mode", "boolean-false": false, "sibling-off": "off" } }',
692 );
693
694 const skills = yield* discoverClaudeSkills({ homePath: configDir });
695
696 assert.deepEqual(
697 skills.map((skill) => [skill.name, skill.enabled]),
698 [
699 ["boolean-false", true],
700 ["sibling-off", true],
701 ["unknown-mode", true],
702 ],
703 );
704 }),
705 );
706
707 it.effect("reads repository root settings from a nested workspace", () =>
708 Effect.gen(function* () {
709 const fs = yield* FileSystem.FileSystem;
710 const path = yield* Path.Path;
711 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
712 const configDir = path.join(tempDir, "claude-home");
713 const repo = path.join(tempDir, "repo");
714 const workspace = path.join(repo, "packages", "app");
715
716 for (const name of ["root-off", "root-off-cwd-on", "cwd-off-root-on"]) {
717 yield* writeSkill(
718 path.join(configDir, "skills"),
719 name,
720 ["---", `name: ${name}`, "---", "", "# Body"].join("\n"),
721 );
722 }
723 yield* fs.makeDirectory(path.join(repo, ".git"), { recursive: true });
724 yield* fs.makeDirectory(path.join(repo, ".claude"), { recursive: true });
725 yield* fs.makeDirectory(path.join(workspace, ".claude"), { recursive: true });
726 // The CLI ignores the root's plain settings.json from a nested cwd.
727 yield* fs.writeFileString(
728 path.join(repo, ".claude", "settings.json"),
729 '{ "skillOverrides": { "cwd-off-root-on": "off" } }',
730 );
731 // The root local file outranks the workspace local file, as in the CLI.
732 yield* fs.writeFileString(
733 path.join(repo, ".claude", "settings.local.json"),
734 '{ "skillOverrides": { "root-off": "off", "root-off-cwd-on": "off", "cwd-off-root-on": "on" } }',
735 );
736 yield* fs.writeFileString(
737 path.join(workspace, ".claude", "settings.local.json"),
738 '{ "skillOverrides": { "root-off-cwd-on": "on", "cwd-off-root-on": "off" } }',
739 );
740
741 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
742
743 assert.deepEqual(
744 skills.map((skill) => [skill.name, skill.enabled]),
745 [
746 ["cwd-off-root-on", true],
747 ["root-off", false],
748 ["root-off-cwd-on", false],
749 ],
750 );
751 }),
752 );
753
754 it.effect("ignores ancestor settings outside a repository", () =>
755 Effect.gen(function* () {
756 const fs = yield* FileSystem.FileSystem;
757 const path = yield* Path.Path;
758 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
759 const configDir = path.join(tempDir, "claude-home");
760 const parent = path.join(tempDir, "not-a-repo");
761 const workspace = path.join(parent, "workspace");
762
763 yield* writeSkill(
764 path.join(configDir, "skills"),
765 "kept",
766 ["---", "name: kept", "---", "", "# Body"].join("\n"),
767 );
768 yield* fs.makeDirectory(path.join(parent, ".claude"), { recursive: true });
769 yield* fs.makeDirectory(workspace, { recursive: true });
770 yield* fs.writeFileString(
771 path.join(parent, ".claude", "settings.local.json"),
772 '{ "skillOverrides": { "kept": "off" } }',
773 );
774
775 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
776
777 assert.deepEqual(
778 skills.map((skill) => [skill.name, skill.enabled]),
779 [["kept", true]],
780 );
781 }),
782 );
783
784 it.effect("identifies a skill by its directory, as Claude Code does", () =>
785 Effect.gen(function* () {
786 const fs = yield* FileSystem.FileSystem;
787 const path = yield* Path.Path;
788 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
789 const configDir = path.join(tempDir, "claude-home");
790
791 yield* writeSkill(
792 path.join(configDir, "skills"),
793 "probe-alias",
794 ["---", "name: probe-alias-frontmatter", "---", "", "# Body"].join("\n"),
795 );
796 yield* fs.writeFileString(
797 path.join(configDir, "settings.json"),
798 '{ "skillOverrides": { "probe-alias-frontmatter": "off" } }',
799 );
800
801 const skills = yield* discoverClaudeSkills({ homePath: configDir });
802
803 assert.deepEqual(
804 skills.map((skill) => [skill.name, skill.enabled]),
805 [["probe-alias", true]],
806 );
807 }),
808 );
809
810 // regression: #9128 skills picked from the composer did not run
811 it.effect("switches a skill off by its directory name", () =>
812 Effect.gen(function* () {
813 const fs = yield* FileSystem.FileSystem;
814 const path = yield* Path.Path;
815 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
816 const configDir = path.join(tempDir, "claude-home");
817
818 yield* writeSkill(
819 path.join(configDir, "skills"),
820 "probe-alias",
821 ["---", "name: probe-alias-frontmatter", "---", "", "# Body"].join("\n"),
822 );
823 yield* fs.writeFileString(
824 path.join(configDir, "settings.json"),
825 '{ "skillOverrides": { "probe-alias": "off" } }',
826 );
827
828 const skills = yield* discoverClaudeSkills({ homePath: configDir });
829
830 assert.deepEqual(
831 skills.map((skill) => [skill.name, skill.enabled]),
832 [["probe-alias", false]],
833 );
834 }),
835 );
836
837 it.effect("accepts the YAML 1.1 boolean spellings Claude Code allows", () =>
838 Effect.gen(function* () {
839 const fs = yield* FileSystem.FileSystem;
840 const path = yield* Path.Path;
841 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
842 const configDir = path.join(tempDir, "claude-home");
843 const skillsDir = path.join(configDir, "skills");
844
845 yield* writeSkill(
846 skillsDir,
847 "user-only-yes",
848 ["---", "disable-model-invocation: yes", "---", "", "# Body"].join("\n"),
849 );
850 yield* writeSkill(
851 skillsDir,
852 "agent-only-no",
853 ["---", "user-invocable: no", "---", "", "# Body"].join("\n"),
854 );
855 yield* writeSkill(
856 skillsDir,
857 "plain-off",
858 ["---", "disable-model-invocation: off", "---", "", "# Body"].join("\n"),
859 );
860
861 const skills = yield* discoverClaudeSkills({ homePath: configDir });
862
863 assert.deepEqual(
864 skills.map((skill) => [
865 skill.name,
866 skill.userInvocationOnly === true,
867 skill.userInvocable === false,
868 ]),
869 [
870 ["agent-only-no", false, true],
871 ["plain-off", false, false],
872 ["user-only-yes", true, false],
873 ],
874 );
875 }),
876 );
877});