Open History to see the last commit
1import * as NodePath from "@effect/platform-node/NodePath";
2import * as NodeServices from "@effect/platform-node/NodeServices";
3import { assert, it } from "@effect/vitest";
4import * as Effect from "effect/Effect";
5import * as FileSystem from "effect/FileSystem";
6import * as Path from "effect/Path";
7
8import { discoverClaudeSkills, skillOverrideSettingsPaths } from "./ClaudeSkills.ts";
9import { planClaudeSkillDispatch } from "./ClaudeSkillDispatch.ts";
10
11const writeSkill = Effect.fn(function* (
12 skillsDir: string,
13 directoryName: string,
14 contents: string,
15) {
16 const fs = yield* FileSystem.FileSystem;
17 const path = yield* Path.Path;
18 const skillDir = path.join(skillsDir, directoryName);
19 yield* fs.makeDirectory(skillDir, { recursive: true });
20 yield* fs.writeFileString(path.join(skillDir, "SKILL.md"), contents);
21});
22
23it.layer(NodeServices.layer)("discoverClaudeSkills", (it) => {
24 it.effect("discovers user and project skills with frontmatter metadata", () =>
25 Effect.gen(function* () {
26 const fs = yield* FileSystem.FileSystem;
27 const path = yield* Path.Path;
28 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
29 const configDir = path.join(tempDir, "claude-home");
30 const workspace = path.join(tempDir, "workspace");
31
32 yield* writeSkill(
33 path.join(configDir, "skills"),
34 "codex-review",
35 [
36 "---",
37 "name: codex-review",
38 "description: Ask Codex for a review.",
39 "---",
40 "",
41 "# Body",
42 ].join("\n"),
43 );
44 yield* writeSkill(
45 path.join(workspace, ".claude", "skills"),
46 "deploy",
47 ["---", "name: deploy", "description: Deploy the app.", "---", "", "# Deploy"].join("\n"),
48 );
49
50 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
51
52 assert.deepEqual(skills, [
53 {
54 name: "codex-review",
55 path: path.join(configDir, "skills", "codex-review", "SKILL.md"),
56 enabled: true,
57 scope: "user",
58 description: "Ask Codex for a review.",
59 },
60 {
61 name: "deploy",
62 path: path.join(workspace, ".claude", "skills", "deploy", "SKILL.md"),
63 enabled: true,
64 scope: "project",
65 description: "Deploy the app.",
66 },
67 ]);
68 }),
69 );
70
71 it.effect("discovers skills from the instance's --add-dir launch args", () =>
72 Effect.gen(function* () {
73 const fs = yield* FileSystem.FileSystem;
74 const path = yield* Path.Path;
75 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
76 const configDir = path.join(tempDir, "claude-home");
77 const workspace = path.join(tempDir, "workspace");
78 const extraDir = path.join(workspace, "extra skills");
79 yield* fs.makeDirectory(workspace, { recursive: true });
80 yield* writeSkill(
81 path.join(extraDir, ".claude", "skills"),
82 "demo",
83 ["---", "description: From an additional directory.", "---"].join("\n"),
84 );
85
86 assert.deepEqual(yield* discoverClaudeSkills({ homePath: configDir }, workspace), []);
87 for (const launchArgs of [
88 `--add-dir "${extraDir}"`,
89 `--add-dir="${extraDir}"`,
90 '--add-dir "extra skills"',
91 '--add-dir="extra skills"',
92 `--add-dir missing --add-dir "${extraDir}"`,
93 ]) {
94 const settings = { homePath: configDir, launchArgs };
95 const skills = yield* discoverClaudeSkills(settings, workspace);
96 assert.deepEqual(skills, [
97 {
98 name: "demo",
99 path: path.join(extraDir, ".claude", "skills", "demo", "SKILL.md"),
100 enabled: true,
101 scope: "project",
102 description: "From an additional directory.",
103 },
104 ]);
105 }
106 const settings = { homePath: configDir, launchArgs: `--add-dir "${extraDir}"` };
107 const skills = yield* discoverClaudeSkills(settings, workspace);
108 assert.deepEqual(
109 planClaudeSkillDispatch("$demo", new Set(skills.map((skill) => skill.name))),
110 {
111 leadingText: undefined,
112 commandText: "/demo",
113 skillName: "demo",
114 },
115 );
116 yield* writeSkill(
117 path.join(workspace, ".claude", "skills"),
118 "demo",
119 "---\ndescription: Project copy.\n---",
120 );
121 const projectSkills = yield* discoverClaudeSkills(settings, workspace);
122 assert.equal(projectSkills[0]?.description, "Project copy.");
123 for (const launchArgs of ["--add-dir", '--add-dir=""', '--add-dir "extra skills"']) {
124 const settings = { homePath: configDir, launchArgs };
125 assert.deepEqual(yield* discoverClaudeSkills(settings), []);
126 }
127 }),
128 );
129
130 it.effect("ignores .agents/skills, which Claude Code does not load", () =>
131 Effect.gen(function* () {
132 const fs = yield* FileSystem.FileSystem;
133 const path = yield* Path.Path;
134 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
135 const configDir = path.join(tempDir, "claude-home");
136 const workspace = path.join(tempDir, "workspace");
137
138 // Verified against the CLI: `/review` here is answered with
139 // `Unknown command`, so offering it would dispatch a dead command.
140 yield* writeSkill(
141 path.join(workspace, ".agents", "skills"),
142 "review",
143 ["---", "name: review", "description: Review the changes.", "---"].join("\n"),
144 );
145
146 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
147
148 assert.deepEqual(skills, []);
149 }),
150 );
151
152 it.effect("prefers user skills on name collisions even with a stray .agents copy", () =>
153 Effect.gen(function* () {
154 const fs = yield* FileSystem.FileSystem;
155 const path = yield* Path.Path;
156 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
157 const configDir = path.join(tempDir, "claude-home");
158 const workspace = path.join(tempDir, "workspace");
159
160 yield* writeSkill(
161 path.join(configDir, "skills"),
162 "deploy",
163 ["---", "name: deploy", "description: User deploy.", "---"].join("\n"),
164 );
165 yield* writeSkill(
166 path.join(workspace, ".agents", "skills"),
167 "deploy",
168 ["---", "name: deploy", "description: Agents deploy.", "---"].join("\n"),
169 );
170 yield* writeSkill(
171 path.join(workspace, ".claude", "skills"),
172 "deploy",
173 ["---", "name: deploy", "description: Claude deploy.", "---"].join("\n"),
174 );
175
176 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
177
178 assert.deepEqual(skills, [
179 {
180 name: "deploy",
181 path: path.join(configDir, "skills", "deploy", "SKILL.md"),
182 enabled: true,
183 scope: "user",
184 description: "User deploy.",
185 },
186 ]);
187 }),
188 );
189
190 it.effect("prefers user skills over project skills on name collisions", () =>
191 Effect.gen(function* () {
192 const fs = yield* FileSystem.FileSystem;
193 const path = yield* Path.Path;
194 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
195 const configDir = path.join(tempDir, "claude-home");
196 const workspace = path.join(tempDir, "workspace");
197
198 yield* writeSkill(
199 path.join(configDir, "skills"),
200 "deploy",
201 ["---", "name: deploy", "description: User deploy.", "---"].join("\n"),
202 );
203 yield* writeSkill(
204 path.join(workspace, ".claude", "skills"),
205 "deploy",
206 ["---", "name: deploy", "description: Project deploy.", "---"].join("\n"),
207 );
208
209 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
210
211 assert.equal(skills.length, 1);
212 assert.equal(skills[0]?.scope, "user");
213 assert.equal(skills[0]?.description, "User deploy.");
214 }),
215 );
216
217 it.effect("recovers colon-bearing descriptions with invocation metadata intact", () =>
218 Effect.gen(function* () {
219 const fs = yield* FileSystem.FileSystem;
220 const path = yield* Path.Path;
221 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
222 const configDir = path.join(tempDir, "claude-home");
223
224 for (const [description, comment] of [
225 ["Browser automation + AI test authoring via kane-cli: run browser objectives, ...", ""],
226 ['Read C:\\skills\\guide#tag: continue with "quoted".', " # trailing: comment"],
227 ] as const) {
228 yield* writeSkill(
229 path.join(configDir, "skills"),
230 "kane-cli",
231 [
232 "---",
233 "name: frontmatter-alias",
234 `description: ${description}${comment}`,
235 "allowed-tools: [Read, Write]",
236 "disable-model-invocation: yes",
237 "user-invocable: no",
238 "---",
239 ].join("\n"),
240 );
241
242 const skills = yield* discoverClaudeSkills({ homePath: configDir }, undefined);
243
244 assert.deepEqual(skills, [
245 {
246 name: "kane-cli",
247 path: path.join(configDir, "skills", "kane-cli", "SKILL.md"),
248 enabled: true,
249 scope: "user",
250 description,
251 userInvocationOnly: true,
252 userInvocable: false,
253 },
254 ]);
255 }
256 }),
257 );
258
259 it.effect("falls back to the directory name and skips malformed frontmatter", () =>
260 Effect.gen(function* () {
261 const fs = yield* FileSystem.FileSystem;
262 const path = yield* Path.Path;
263 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
264 const configDir = path.join(tempDir, "claude-home");
265 const skillsDir = path.join(configDir, "skills");
266
267 yield* writeSkill(skillsDir, "no-frontmatter", "# Just a heading\n");
268 for (const [directoryName, field] of [
269 ["broken-yaml", "name: [unclosed"],
270 ["broken-tools", "allowed-tools: [Read, Write"],
271 ["broken-quoted", 'name: "unclosed: text'],
272 ] as const) {
273 yield* writeSkill(
274 skillsDir,
275 directoryName,
276 ["---", "description: Run: browser objectives.", field, "---"].join("\n"),
277 );
278 }
279 yield* fs.makeDirectory(skillsDir, { recursive: true });
280 yield* fs.writeFileString(path.join(skillsDir, "README.md"), "not a skill");
281
282 const skills = yield* discoverClaudeSkills({ homePath: configDir }, undefined);
283
284 // A skill with no frontmatter falls back to its directory name; a skill
285 // whose frontmatter fails to parse is skipped entirely (Claude Code
286 // won't load it either).
287 assert.deepEqual(
288 skills.map((skill) => skill.name),
289 ["no-frontmatter"],
290 );
291 assert.equal(skills[0]?.description, undefined);
292 }),
293 );
294
295 it.effect("honors CLAUDE_CONFIG_DIR from the environment when homePath is unset", () =>
296 Effect.gen(function* () {
297 const fs = yield* FileSystem.FileSystem;
298 const path = yield* Path.Path;
299 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
300 const environmentConfigDir = path.join(tempDir, "env-config");
301
302 yield* writeSkill(
303 path.join(environmentConfigDir, "skills"),
304 "env-skill",
305 ["---", "name: env-skill", "description: From env config dir.", "---"].join("\n"),
306 );
307
308 const skills = yield* discoverClaudeSkills({ homePath: "" }, undefined, {
309 CLAUDE_CONFIG_DIR: environmentConfigDir,
310 });
311
312 assert.deepEqual(
313 skills.map((skill) => skill.name),
314 ["env-skill"],
315 );
316
317 const explicitHome = path.join(tempDir, "explicit-home");
318 yield* writeSkill(
319 path.join(explicitHome, "skills"),
320 "explicit-skill",
321 ["---", "name: explicit-skill", "---"].join("\n"),
322 );
323 const explicitSkills = yield* discoverClaudeSkills({ homePath: explicitHome }, undefined, {
324 CLAUDE_CONFIG_DIR: environmentConfigDir,
325 });
326 assert.deepEqual(
327 explicitSkills.map((skill) => skill.name),
328 ["explicit-skill"],
329 );
330 }),
331 );
332
333 it.effect("resolves a relative CLAUDE_CONFIG_DIR against the workspace cwd", () =>
334 Effect.gen(function* () {
335 const fs = yield* FileSystem.FileSystem;
336 const path = yield* Path.Path;
337 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
338 const workspace = path.join(tempDir, "workspace");
339 yield* fs.makeDirectory(workspace, { recursive: true });
340
341 // The spawned CLI resolves a relative CLAUDE_CONFIG_DIR against its own
342 // cwd (the workspace), so discovery must do the same.
343 yield* writeSkill(
344 path.join(workspace, "relative-config", "skills"),
345 "relative-skill",
346 ["---", "name: relative-skill", "---"].join("\n"),
347 );
348
349 const skills = yield* discoverClaudeSkills({ homePath: "" }, workspace, {
350 CLAUDE_CONFIG_DIR: "relative-config",
351 });
352
353 assert.deepEqual(
354 skills.map((skill) => skill.name),
355 ["relative-skill"],
356 );
357 assert.equal(skills[0]?.scope, "user");
358 }),
359 );
360
361 it.effect("marks skills that only the user can invoke", () =>
362 Effect.gen(function* () {
363 const fs = yield* FileSystem.FileSystem;
364 const path = yield* Path.Path;
365 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
366 const configDir = path.join(tempDir, "claude-home");
367 const workspace = path.join(tempDir, "workspace");
368
369 yield* writeSkill(
370 path.join(workspace, ".claude", "skills"),
371 "re-release-version",
372 [
373 "---",
374 "name: re-release-version",
375 "description: Move the current tag forward.",
376 "disable-model-invocation: true",
377 "---",
378 "",
379 "# Body",
380 ].join("\n"),
381 );
382 yield* writeSkill(
383 path.join(workspace, ".claude", "skills"),
384 "release-version",
385 ["---", "name: release-version", "description: Cut a release.", "---", "", "# Body"].join(
386 "\n",
387 ),
388 );
389
390 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
391
392 assert.equal(
393 skills.find((skill) => skill.name === "re-release-version")?.userInvocationOnly,
394 true,
395 );
396 assert.equal(
397 skills.find((skill) => skill.name === "release-version")?.userInvocationOnly,
398 undefined,
399 );
400 }),
401 );
402
403 it.effect("disables skills switched off by skillOverrides", () =>
404 Effect.gen(function* () {
405 const fs = yield* FileSystem.FileSystem;
406 const path = yield* Path.Path;
407 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
408 const configDir = path.join(tempDir, "claude-home");
409 const workspace = path.join(tempDir, "workspace");
410
411 for (const name of ["kept", "off-by-user", "off-by-project"]) {
412 yield* writeSkill(
413 path.join(configDir, "skills"),
414 name,
415 ["---", `name: ${name}`, "---", "", "# Body"].join("\n"),
416 );
417 }
418
419 yield* fs.makeDirectory(configDir, { recursive: true });
420 yield* fs.writeFileString(
421 path.join(configDir, "settings.json"),
422 '{ "skillOverrides": { "off-by-user": "off", "kept": "on" } }',
423 );
424 yield* fs.makeDirectory(path.join(workspace, ".claude"), { recursive: true });
425 yield* fs.writeFileString(
426 path.join(workspace, ".claude", "settings.json"),
427 '{ "skillOverrides": { "off-by-project": "off" } }',
428 );
429
430 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
431
432 assert.deepEqual(
433 skills.map((skill) => [skill.name, skill.enabled]),
434 [
435 ["kept", true],
436 ["off-by-project", false],
437 ["off-by-user", false],
438 ],
439 );
440 }),
441 );
442
443 it.effect("ignores unreadable settings when resolving skillOverrides", () =>
444 Effect.gen(function* () {
445 const fs = yield* FileSystem.FileSystem;
446 const path = yield* Path.Path;
447 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
448 const configDir = path.join(tempDir, "claude-home");
449
450 yield* writeSkill(
451 path.join(configDir, "skills"),
452 "kept",
453 ["---", "name: kept", "---", "", "# Body"].join("\n"),
454 );
455 yield* fs.writeFileString(path.join(configDir, "settings.json"), "{ not json");
456
457 const skills = yield* discoverClaudeSkills({ homePath: configDir });
458
459 assert.deepEqual(
460 skills.map((skill) => [skill.name, skill.enabled]),
461 [["kept", true]],
462 );
463 }),
464 );
465
466 it.effect("treats a user-invocable-only override like disable-model-invocation", () =>
467 Effect.gen(function* () {
468 const fs = yield* FileSystem.FileSystem;
469 const path = yield* Path.Path;
470 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
471 const configDir = path.join(tempDir, "claude-home");
472
473 yield* writeSkill(
474 path.join(configDir, "skills"),
475 "ask-matt",
476 ["---", "name: ask-matt", "---", "", "# Body"].join("\n"),
477 );
478 yield* fs.writeFileString(
479 path.join(configDir, "settings.json"),
480 '{ "skillOverrides": { "ask-matt": "user-invocable-only" } }',
481 );
482
483 const skills = yield* discoverClaudeSkills({ homePath: configDir });
484
485 assert.deepEqual(
486 skills.map((skill) => [skill.name, skill.enabled, skill.userInvocationOnly === true]),
487 [["ask-matt", true, true]],
488 );
489 }),
490 );
491
492 it.effect("drops every override in a file when one value is invalid, as Claude Code does", () =>
493 Effect.gen(function* () {
494 const fs = yield* FileSystem.FileSystem;
495 const path = yield* Path.Path;
496 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
497 const configDir = path.join(tempDir, "claude-home");
498
499 for (const name of ["unknown-mode", "boolean-false", "sibling-off"]) {
500 yield* writeSkill(
501 path.join(configDir, "skills"),
502 name,
503 ["---", `name: ${name}`, "---", "", "# Body"].join("\n"),
504 );
505 }
506 // Verified against the CLI: with an unknown string or a boolean in the
507 // map, the valid "off" sibling is ignored too and every skill runs.
508 yield* fs.writeFileString(
509 path.join(configDir, "settings.json"),
510 '{ "skillOverrides": { "unknown-mode": "some-future-mode", "boolean-false": false, "sibling-off": "off" } }',
511 );
512
513 const skills = yield* discoverClaudeSkills({ homePath: configDir });
514
515 assert.deepEqual(
516 skills.map((skill) => [skill.name, skill.enabled]),
517 [
518 ["boolean-false", true],
519 ["sibling-off", true],
520 ["unknown-mode", true],
521 ],
522 );
523 }),
524 );
525
526 it.effect("reads repository root settings from a nested workspace", () =>
527 Effect.gen(function* () {
528 const fs = yield* FileSystem.FileSystem;
529 const path = yield* Path.Path;
530 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
531 const configDir = path.join(tempDir, "claude-home");
532 const repo = path.join(tempDir, "repo");
533 const workspace = path.join(repo, "packages", "app");
534
535 for (const name of ["root-off", "root-off-cwd-on", "cwd-off-root-on"]) {
536 yield* writeSkill(
537 path.join(configDir, "skills"),
538 name,
539 ["---", `name: ${name}`, "---", "", "# Body"].join("\n"),
540 );
541 }
542 yield* fs.makeDirectory(path.join(repo, ".git"), { recursive: true });
543 yield* fs.makeDirectory(path.join(repo, ".claude"), { recursive: true });
544 yield* fs.makeDirectory(path.join(workspace, ".claude"), { recursive: true });
545 // The CLI ignores the root's plain settings.json from a nested cwd.
546 yield* fs.writeFileString(
547 path.join(repo, ".claude", "settings.json"),
548 '{ "skillOverrides": { "cwd-off-root-on": "off" } }',
549 );
550 // The root local file outranks the workspace local file, as in the CLI.
551 yield* fs.writeFileString(
552 path.join(repo, ".claude", "settings.local.json"),
553 '{ "skillOverrides": { "root-off": "off", "root-off-cwd-on": "off", "cwd-off-root-on": "on" } }',
554 );
555 yield* fs.writeFileString(
556 path.join(workspace, ".claude", "settings.local.json"),
557 '{ "skillOverrides": { "root-off-cwd-on": "on", "cwd-off-root-on": "off" } }',
558 );
559
560 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
561
562 assert.deepEqual(
563 skills.map((skill) => [skill.name, skill.enabled]),
564 [
565 ["cwd-off-root-on", true],
566 ["root-off", false],
567 ["root-off-cwd-on", false],
568 ],
569 );
570 }),
571 );
572
573 it.effect("ignores ancestor settings outside a repository", () =>
574 Effect.gen(function* () {
575 const fs = yield* FileSystem.FileSystem;
576 const path = yield* Path.Path;
577 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
578 const configDir = path.join(tempDir, "claude-home");
579 const parent = path.join(tempDir, "not-a-repo");
580 const workspace = path.join(parent, "workspace");
581
582 yield* writeSkill(
583 path.join(configDir, "skills"),
584 "kept",
585 ["---", "name: kept", "---", "", "# Body"].join("\n"),
586 );
587 yield* fs.makeDirectory(path.join(parent, ".claude"), { recursive: true });
588 yield* fs.makeDirectory(workspace, { recursive: true });
589 yield* fs.writeFileString(
590 path.join(parent, ".claude", "settings.local.json"),
591 '{ "skillOverrides": { "kept": "off" } }',
592 );
593
594 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
595
596 assert.deepEqual(
597 skills.map((skill) => [skill.name, skill.enabled]),
598 [["kept", true]],
599 );
600 }),
601 );
602
603 it.effect("lets the administrator's managed policy outrank every other settings file", () =>
604 Effect.gen(function* () {
605 const path = yield* Path.Path.pipe(Effect.provide(NodePath.layerPosix));
606 const win32Path = yield* Path.Path.pipe(Effect.provide(NodePath.layerWin32));
607
608 for (const [platform, expected] of [
609 ["darwin", "/Library/Application Support/ClaudeCode/managed-settings.json"],
610 ["linux", "/etc/claude-code/managed-settings.json"],
611 ] as const) {
612 const paths = skillOverrideSettingsPaths(path, "/home/.claude", "/workspace", platform, {});
613 assert.deepEqual(paths, [
614 "/home/.claude/settings.json",
615 "/workspace/.claude/settings.json",
616 "/workspace/.claude/settings.local.json",
617 expected,
618 ]);
619 }
620
621 assert.deepEqual(
622 skillOverrideSettingsPaths(win32Path, "C:\\Users\\me\\.claude", undefined, "win32", {
623 PROGRAMDATA: "C:\\ProgramData",
624 }).at(-1),
625 "C:\\ProgramData\\ClaudeCode\\managed-settings.json",
626 );
627 assert.deepEqual(
628 skillOverrideSettingsPaths(win32Path, "C:\\Users\\me\\.claude", undefined, "win32", {}),
629 ["C:\\Users\\me\\.claude\\settings.json"],
630 );
631
632 assert.deepEqual(
633 skillOverrideSettingsPaths(
634 path,
635 "/home/.claude",
636 "/repo/packages/app",
637 "linux",
638 {},
639 "/repo",
640 ),
641 [
642 "/home/.claude/settings.json",
643 "/repo/packages/app/.claude/settings.json",
644 "/repo/packages/app/.claude/settings.local.json",
645 "/repo/.claude/settings.local.json",
646 "/etc/claude-code/managed-settings.json",
647 ],
648 );
649 assert.deepEqual(
650 skillOverrideSettingsPaths(path, "/home/.claude", "/repo", "linux", {}, "/repo"),
651 [
652 "/home/.claude/settings.json",
653 "/repo/.claude/settings.json",
654 "/repo/.claude/settings.local.json",
655 "/etc/claude-code/managed-settings.json",
656 ],
657 );
658 }),
659 );
660
661 it.effect("records a skill Claude Code keeps out of its own slash commands", () =>
662 Effect.gen(function* () {
663 const fs = yield* FileSystem.FileSystem;
664 const path = yield* Path.Path;
665 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
666 const configDir = path.join(tempDir, "claude-home");
667
668 yield* writeSkill(
669 path.join(configDir, "skills"),
670 "agent-only",
671 ["---", "name: agent-only", "user-invocable: false", "---", "", "# Body"].join("\n"),
672 );
673
674 const skills = yield* discoverClaudeSkills({ homePath: configDir });
675
676 assert.deepEqual(
677 skills.map((skill) => [skill.name, skill.userInvocable]),
678 [["agent-only", false]],
679 );
680 }),
681 );
682
683 it.effect("identifies a skill by its directory, as Claude Code does", () =>
684 Effect.gen(function* () {
685 const fs = yield* FileSystem.FileSystem;
686 const path = yield* Path.Path;
687 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
688 const configDir = path.join(tempDir, "claude-home");
689
690 yield* writeSkill(
691 path.join(configDir, "skills"),
692 "probe-alias",
693 ["---", "name: probe-alias-frontmatter", "---", "", "# Body"].join("\n"),
694 );
695 yield* fs.writeFileString(
696 path.join(configDir, "settings.json"),
697 '{ "skillOverrides": { "probe-alias-frontmatter": "off" } }',
698 );
699
700 const skills = yield* discoverClaudeSkills({ homePath: configDir });
701
702 assert.deepEqual(
703 skills.map((skill) => [skill.name, skill.enabled]),
704 [["probe-alias", true]],
705 );
706 }),
707 );
708
709 it.effect("switches a skill off by its directory name", () =>
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 "probe-alias",
719 ["---", "name: probe-alias-frontmatter", "---", "", "# Body"].join("\n"),
720 );
721 yield* fs.writeFileString(
722 path.join(configDir, "settings.json"),
723 '{ "skillOverrides": { "probe-alias": "off" } }',
724 );
725
726 const skills = yield* discoverClaudeSkills({ homePath: configDir });
727
728 assert.deepEqual(
729 skills.map((skill) => [skill.name, skill.enabled]),
730 [["probe-alias", false]],
731 );
732 }),
733 );
734
735 it.effect("accepts the YAML 1.1 boolean spellings Claude Code allows", () =>
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 const skillsDir = path.join(configDir, "skills");
742
743 yield* writeSkill(
744 skillsDir,
745 "user-only-yes",
746 ["---", "disable-model-invocation: yes", "---", "", "# Body"].join("\n"),
747 );
748 yield* writeSkill(
749 skillsDir,
750 "agent-only-no",
751 ["---", "user-invocable: no", "---", "", "# Body"].join("\n"),
752 );
753 yield* writeSkill(
754 skillsDir,
755 "plain-off",
756 ["---", "disable-model-invocation: off", "---", "", "# Body"].join("\n"),
757 );
758
759 const skills = yield* discoverClaudeSkills({ homePath: configDir });
760
761 assert.deepEqual(
762 skills.map((skill) => [
763 skill.name,
764 skill.userInvocationOnly === true,
765 skill.userInvocable === false,
766 ]),
767 [
768 ["agent-only-no", false, true],
769 ["plain-off", false, false],
770 ["user-only-yes", true, false],
771 ],
772 );
773 }),
774 );
775
776 it.effect("returns an empty list when no skill roots exist", () =>
777 Effect.gen(function* () {
778 const fs = yield* FileSystem.FileSystem;
779 const path = yield* Path.Path;
780 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
781
782 const skills = yield* discoverClaudeSkills(
783 { homePath: path.join(tempDir, "missing-home") },
784 path.join(tempDir, "missing-workspace"),
785 );
786
787 assert.deepEqual(skills, []);
788 }),
789 );
790});