Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ClaudeSkills.test.ts

873 lines33.3 KB

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 `--add-dir "${extraDir}" --add-dir missing`,
362 `--add-dir missing "${extraDir}"`,
363 ]) {
364 const settings = { homePath: configDir, launchArgs };
365 const skills = yield* discoverClaudeSkills(settings, workspace);
366 assert.deepEqual(skills, [
367 {
368 name: "demo",
369 path: path.join(extraDir, ".claude", "skills", "demo", "SKILL.md"),
370 enabled: true,
371 scope: "project",
372 description: "From an additional directory.",
373 },
374 ]);
375 }
376 const settings = { homePath: configDir, launchArgs: `--add-dir "${extraDir}"` };
377 const skills = yield* discoverClaudeSkills(settings, workspace);
378 assert.deepEqual(
379 planClaudeSkillDispatch(
380 "$demo",
381 new Map(skills.map((skill) => [skill.name, { path: skill.path }])),
382 ),
383 {
384 leadingText: undefined,
385 commandText: "/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 // Claude falls back to directory names without frontmatter, but skips malformed frontmatter.
508 assert.deepEqual(
509 skills.map((skill) => skill.name),
510 ["no-frontmatter"],
511 );
512 assert.equal(skills[0]?.description, undefined);
513 }),
514 );
515​
516 it.effect("honors CLAUDE_CONFIG_DIR from the environment when homePath is unset", () =>
517 Effect.gen(function* () {
518 const fs = yield* FileSystem.FileSystem;
519 const path = yield* Path.Path;
520 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
521 const environmentConfigDir = path.join(tempDir, "env-config");
522​
523 yield* writeSkill(
524 path.join(environmentConfigDir, "skills"),
525 "env-skill",
526 ["---", "name: env-skill", "description: From env config dir.", "---"].join("\n"),
527 );
528​
529 const skills = yield* discoverClaudeSkills({ homePath: "" }, undefined, {
530 CLAUDE_CONFIG_DIR: environmentConfigDir,
531 });
532​
533 assert.deepEqual(
534 skills.map((skill) => skill.name),
535 ["env-skill"],
536 );
537​
538 const explicitHome = path.join(tempDir, "explicit-home");
539 yield* writeSkill(
540 path.join(explicitHome, "skills"),
541 "explicit-skill",
542 ["---", "name: explicit-skill", "---"].join("\n"),
543 );
544 const explicitSkills = yield* discoverClaudeSkills({ homePath: explicitHome }, undefined, {
545 CLAUDE_CONFIG_DIR: environmentConfigDir,
546 });
547 assert.deepEqual(
548 explicitSkills.map((skill) => skill.name),
549 ["explicit-skill"],
550 );
551 }),
552 );
553​
554 it.effect("resolves a relative CLAUDE_CONFIG_DIR against the workspace cwd", () =>
555 Effect.gen(function* () {
556 const fs = yield* FileSystem.FileSystem;
557 const path = yield* Path.Path;
558 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
559 const workspace = path.join(tempDir, "workspace");
560 yield* fs.makeDirectory(workspace, { recursive: true });
561​
562 // The CLI resolves relative CLAUDE_CONFIG_DIR against workspace cwd.
563 yield* writeSkill(
564 path.join(workspace, "relative-config", "skills"),
565 "relative-skill",
566 ["---", "name: relative-skill", "---"].join("\n"),
567 );
568​
569 const skills = yield* discoverClaudeSkills({ homePath: "" }, workspace, {
570 CLAUDE_CONFIG_DIR: "relative-config",
571 });
572​
573 assert.deepEqual(
574 skills.map((skill) => skill.name),
575 ["relative-skill"],
576 );
577 assert.equal(skills[0]?.scope, "user");
578 }),
579 );
580​
581 it.effect("disables skills switched off by skillOverrides", () =>
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 configDir = path.join(tempDir, "claude-home");
587 const workspace = path.join(tempDir, "workspace");
588​
589 for (const name of ["kept", "off-by-user", "off-by-project"]) {
590 yield* writeSkill(
591 path.join(configDir, "skills"),
592 name,
593 ["---", `name: ${name}`, "---", "", "# Body"].join("\n"),
594 );
595 }
596​
597 yield* fs.makeDirectory(configDir, { recursive: true });
598 yield* fs.writeFileString(
599 path.join(configDir, "settings.json"),
600 '{ "skillOverrides": { "off-by-user": "off", "kept": "on" } }',
601 );
602 yield* fs.makeDirectory(path.join(workspace, ".claude"), { recursive: true });
603 yield* fs.writeFileString(
604 path.join(workspace, ".claude", "settings.json"),
605 '{ "skillOverrides": { "off-by-project": "off" } }',
606 );
607​
608 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
609​
610 assert.deepEqual(
611 skills.map((skill) => [skill.name, skill.enabled]),
612 [
613 ["kept", true],
614 ["off-by-project", false],
615 ["off-by-user", false],
616 ],
617 );
618 }),
619 );
620​
621 it.effect("ignores unreadable settings when resolving skillOverrides", () =>
622 Effect.gen(function* () {
623 const fs = yield* FileSystem.FileSystem;
624 const path = yield* Path.Path;
625 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
626 const configDir = path.join(tempDir, "claude-home");
627​
628 yield* writeSkill(
629 path.join(configDir, "skills"),
630 "kept",
631 ["---", "name: kept", "---", "", "# Body"].join("\n"),
632 );
633 yield* fs.writeFileString(path.join(configDir, "settings.json"), "{ not json");
634​
635 const skills = yield* discoverClaudeSkills({ homePath: configDir });
636​
637 assert.deepEqual(
638 skills.map((skill) => [skill.name, skill.enabled]),
639 [["kept", true]],
640 );
641 }),
642 );
643​
644 it.effect("treats a user-invocable-only override like disable-model-invocation", () =>
645 Effect.gen(function* () {
646 const fs = yield* FileSystem.FileSystem;
647 const path = yield* Path.Path;
648 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
649 const configDir = path.join(tempDir, "claude-home");
650​
651 yield* writeSkill(
652 path.join(configDir, "skills"),
653 "ask-matt",
654 ["---", "name: ask-matt", "---", "", "# Body"].join("\n"),
655 );
656 yield* fs.writeFileString(
657 path.join(configDir, "settings.json"),
658 '{ "skillOverrides": { "ask-matt": "user-invocable-only" } }',
659 );
660​
661 const skills = yield* discoverClaudeSkills({ homePath: configDir });
662​
663 assert.deepEqual(
664 skills.map((skill) => [skill.name, skill.enabled, skill.userInvocationOnly === true]),
665 [["ask-matt", true, true]],
666 );
667 }),
668 );
669​
670 it.effect("drops every override in a file when one value is invalid, as Claude Code does", () =>
671 Effect.gen(function* () {
672 const fs = yield* FileSystem.FileSystem;
673 const path = yield* Path.Path;
674 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
675 const configDir = path.join(tempDir, "claude-home");
676​
677 for (const name of ["unknown-mode", "boolean-false", "sibling-off"]) {
678 yield* writeSkill(
679 path.join(configDir, "skills"),
680 name,
681 ["---", `name: ${name}`, "---", "", "# Body"].join("\n"),
682 );
683 }
684 // Claude ignores the entire override map when any value is an unknown string or boolean.
685 yield* fs.writeFileString(
686 path.join(configDir, "settings.json"),
687 '{ "skillOverrides": { "unknown-mode": "some-future-mode", "boolean-false": false, "sibling-off": "off" } }',
688 );
689​
690 const skills = yield* discoverClaudeSkills({ homePath: configDir });
691​
692 assert.deepEqual(
693 skills.map((skill) => [skill.name, skill.enabled]),
694 [
695 ["boolean-false", true],
696 ["sibling-off", true],
697 ["unknown-mode", true],
698 ],
699 );
700 }),
701 );
702​
703 it.effect("reads repository root settings from a nested workspace", () =>
704 Effect.gen(function* () {
705 const fs = yield* FileSystem.FileSystem;
706 const path = yield* Path.Path;
707 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
708 const configDir = path.join(tempDir, "claude-home");
709 const repo = path.join(tempDir, "repo");
710 const workspace = path.join(repo, "packages", "app");
711​
712 for (const name of ["root-off", "root-off-cwd-on", "cwd-off-root-on"]) {
713 yield* writeSkill(
714 path.join(configDir, "skills"),
715 name,
716 ["---", `name: ${name}`, "---", "", "# Body"].join("\n"),
717 );
718 }
719 yield* fs.makeDirectory(path.join(repo, ".git"), { recursive: true });
720 yield* fs.makeDirectory(path.join(repo, ".claude"), { recursive: true });
721 yield* fs.makeDirectory(path.join(workspace, ".claude"), { recursive: true });
722 // The CLI ignores the root's plain settings.json from a nested cwd.
723 yield* fs.writeFileString(
724 path.join(repo, ".claude", "settings.json"),
725 '{ "skillOverrides": { "cwd-off-root-on": "off" } }',
726 );
727 // The root local file outranks the workspace local file, as in the CLI.
728 yield* fs.writeFileString(
729 path.join(repo, ".claude", "settings.local.json"),
730 '{ "skillOverrides": { "root-off": "off", "root-off-cwd-on": "off", "cwd-off-root-on": "on" } }',
731 );
732 yield* fs.writeFileString(
733 path.join(workspace, ".claude", "settings.local.json"),
734 '{ "skillOverrides": { "root-off-cwd-on": "on", "cwd-off-root-on": "off" } }',
735 );
736​
737 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
738​
739 assert.deepEqual(
740 skills.map((skill) => [skill.name, skill.enabled]),
741 [
742 ["cwd-off-root-on", true],
743 ["root-off", false],
744 ["root-off-cwd-on", false],
745 ],
746 );
747 }),
748 );
749​
750 it.effect("ignores ancestor settings outside a repository", () =>
751 Effect.gen(function* () {
752 const fs = yield* FileSystem.FileSystem;
753 const path = yield* Path.Path;
754 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
755 const configDir = path.join(tempDir, "claude-home");
756 const parent = path.join(tempDir, "not-a-repo");
757 const workspace = path.join(parent, "workspace");
758​
759 yield* writeSkill(
760 path.join(configDir, "skills"),
761 "kept",
762 ["---", "name: kept", "---", "", "# Body"].join("\n"),
763 );
764 yield* fs.makeDirectory(path.join(parent, ".claude"), { recursive: true });
765 yield* fs.makeDirectory(workspace, { recursive: true });
766 yield* fs.writeFileString(
767 path.join(parent, ".claude", "settings.local.json"),
768 '{ "skillOverrides": { "kept": "off" } }',
769 );
770​
771 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
772​
773 assert.deepEqual(
774 skills.map((skill) => [skill.name, skill.enabled]),
775 [["kept", true]],
776 );
777 }),
778 );
779​
780 it.effect("identifies a skill by its directory, as Claude Code does", () =>
781 Effect.gen(function* () {
782 const fs = yield* FileSystem.FileSystem;
783 const path = yield* Path.Path;
784 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
785 const configDir = path.join(tempDir, "claude-home");
786​
787 yield* writeSkill(
788 path.join(configDir, "skills"),
789 "probe-alias",
790 ["---", "name: probe-alias-frontmatter", "---", "", "# Body"].join("\n"),
791 );
792 yield* fs.writeFileString(
793 path.join(configDir, "settings.json"),
794 '{ "skillOverrides": { "probe-alias-frontmatter": "off" } }',
795 );
796​
797 const skills = yield* discoverClaudeSkills({ homePath: configDir });
798​
799 assert.deepEqual(
800 skills.map((skill) => [skill.name, skill.enabled]),
801 [["probe-alias", true]],
802 );
803 }),
804 );
805​
806 // regression: #9128 skills picked from the composer did not run
807 it.effect("switches a skill off by its directory name", () =>
808 Effect.gen(function* () {
809 const fs = yield* FileSystem.FileSystem;
810 const path = yield* Path.Path;
811 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
812 const configDir = path.join(tempDir, "claude-home");
813​
814 yield* writeSkill(
815 path.join(configDir, "skills"),
816 "probe-alias",
817 ["---", "name: probe-alias-frontmatter", "---", "", "# Body"].join("\n"),
818 );
819 yield* fs.writeFileString(
820 path.join(configDir, "settings.json"),
821 '{ "skillOverrides": { "probe-alias": "off" } }',
822 );
823​
824 const skills = yield* discoverClaudeSkills({ homePath: configDir });
825​
826 assert.deepEqual(
827 skills.map((skill) => [skill.name, skill.enabled]),
828 [["probe-alias", false]],
829 );
830 }),
831 );
832​
833 it.effect("accepts the YAML 1.1 boolean spellings Claude Code allows", () =>
834 Effect.gen(function* () {
835 const fs = yield* FileSystem.FileSystem;
836 const path = yield* Path.Path;
837 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
838 const configDir = path.join(tempDir, "claude-home");
839 const skillsDir = path.join(configDir, "skills");
840​
841 yield* writeSkill(
842 skillsDir,
843 "user-only-yes",
844 ["---", "disable-model-invocation: yes", "---", "", "# Body"].join("\n"),
845 );
846 yield* writeSkill(
847 skillsDir,
848 "agent-only-no",
849 ["---", "user-invocable: no", "---", "", "# Body"].join("\n"),
850 );
851 yield* writeSkill(
852 skillsDir,
853 "plain-off",
854 ["---", "disable-model-invocation: off", "---", "", "# Body"].join("\n"),
855 );
856​
857 const skills = yield* discoverClaudeSkills({ homePath: configDir });
858​
859 assert.deepEqual(
860 skills.map((skill) => [
861 skill.name,
862 skill.userInvocationOnly === true,
863 skill.userInvocable === false,
864 ]),
865 [
866 ["agent-only-no", false, true],
867 ["plain-off", false, false],
868 ["user-only-yes", true, false],
869 ],
870 );
871 }),
872 );
873});