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