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";
6import * as HostProcess from "@t3tools/shared/HostProcess";
7
8import { discoverClaudeSkills as discoverSkills } from "./ClaudeSkills.ts";
9import { planClaudeSkillDispatch } from "./ClaudeSkillDispatch.ts";
10
11// Windows makes the managed directory fixture-controlled without reading host policy or skills.
12const discoverClaudeSkills = (
13 ...[config, cwd, environment = {}]: Parameters<typeof discoverSkills>
14) =>
15 discoverSkills(config, cwd, environment).pipe(
16 Effect.provideService(HostProcess.Platform, "win32"),
17 );
18
19const writeSkill = Effect.fn(function* (
20 skillsDir: string,
21 directoryName: string,
22 contents: string,
23) {
24 const fs = yield* FileSystem.FileSystem;
25 const path = yield* Path.Path;
26 const skillDir = path.join(skillsDir, directoryName);
27 yield* fs.makeDirectory(skillDir, { recursive: true });
28 yield* fs.writeFileString(path.join(skillDir, "SKILL.md"), contents);
29});
30
31it.layer(NodeServices.layer)("discoverClaudeSkills", (it) => {
32 it.effect("discovers enabled plugin skills with manifest names and ignores skill overrides", () =>
33 Effect.gen(function* () {
34 const fs = yield* FileSystem.FileSystem;
35 const path = yield* Path.Path;
36 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
37 const configDir = path.join(tempDir, "claude-home");
38 const plugin = path.join(configDir, "plugins", "cache", "shop", "plugin", "1.0.0");
39 const disabled = path.join(configDir, "plugins", "disabled");
40 yield* writeSkill(path.join(disabled, "skills"), "hidden", "# Hidden");
41 yield* writeSkill(path.join(plugin, "skills"), "plain", "# Plain");
42 yield* writeSkill(
43 path.join(plugin, "engineering"),
44 "review",
45 "---\nname: review-alias\ndescription: Review changes.\ndisable-model-invocation: true\nuser-invocable: false\n---\n",
46 );
47 yield* fs.makeDirectory(path.join(plugin, ".claude-plugin"), { recursive: true });
48 yield* fs.writeFileString(
49 path.join(plugin, ".claude-plugin", "plugin.json"),
50 '{"name":"manifest-plugin","skills":["./engineering/review"]}',
51 );
52 yield* fs.writeFileString(
53 path.join(configDir, "plugins", "installed_plugins.json"),
54 JSON.stringify({
55 plugins: {
56 "plugin@shop": [{ scope: "user", installPath: plugin }],
57 "disabled@shop": [{ scope: "user", installPath: disabled }],
58 "unconfigured@shop": [{ scope: "user", installPath: disabled }],
59 },
60 }),
61 );
62 yield* fs.writeFileString(
63 path.join(configDir, "settings.json"),
64 '{"enabledPlugins":{"plugin@shop":true,"disabled@shop":false,"uninstalled@shop":true,"other@shop":["^1.0.0"]},"skillOverrides":{"manifest-plugin:plain":"off"}}',
65 );
66
67 const skills = yield* discoverClaudeSkills({ homePath: configDir });
68 assert.deepEqual(skills, [
69 {
70 name: "manifest-plugin:plain",
71 path: path.join(plugin, "skills", "plain", "SKILL.md"),
72 enabled: true,
73 scope: "user",
74 },
75 {
76 name: "manifest-plugin:review-alias",
77 path: path.join(plugin, "engineering", "review", "SKILL.md"),
78 enabled: true,
79 scope: "user",
80 description: "Review changes.",
81 userInvocationOnly: true,
82 userInvocable: false,
83 },
84 ]);
85 }),
86 );
87
88 it.effect("merges plugin enablement and selects installs in native registry order", () =>
89 Effect.gen(function* () {
90 const fs = yield* FileSystem.FileSystem;
91 const path = yield* Path.Path;
92 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
93 const configDir = path.join(tempDir, "claude-home");
94 const workspace = path.join(tempDir, "workspace");
95 const nestedWorkspace = path.join(workspace, "packages", "app");
96 const aliasedWorkspace = path.join(tempDir, "aliased-workspace");
97 const userInstall = path.join(configDir, "plugins", "user");
98 const projectInstall = path.join(configDir, "plugins", "project");
99 const localInstall = path.join(configDir, "plugins", "local");
100 const managedInstall = path.join(configDir, "plugins", "managed");
101 yield* fs.makeDirectory(path.join(workspace, ".git"), { recursive: true });
102 yield* fs.makeDirectory(nestedWorkspace, { recursive: true });
103 yield* fs.symlink(workspace, aliasedWorkspace);
104 for (const install of [userInstall, projectInstall, localInstall, managedInstall]) {
105 yield* writeSkill(path.join(install, "skills"), "review", "# Review");
106 }
107 yield* fs.writeFileString(
108 path.join(configDir, "plugins", "installed_plugins.json"),
109 JSON.stringify({
110 plugins: {
111 "plugin@shop": [
112 { scope: "project", projectPath: aliasedWorkspace, installPath: localInstall },
113 { scope: "project", projectPath: workspace, installPath: projectInstall },
114 { scope: "user", installPath: userInstall },
115 { scope: "managed", installPath: managedInstall },
116 ],
117 "local@shop": [
118 { scope: "local", projectPath: workspace, installPath: localInstall },
119 { scope: "project", projectPath: workspace, installPath: projectInstall },
120 { scope: "managed", installPath: path.join(configDir, "plugins", "missing") },
121 { scope: "managed", installPath: managedInstall },
122 { scope: "user", installPath: userInstall },
123 ],
124 },
125 }),
126 );
127 yield* fs.writeFileString(
128 path.join(configDir, "settings.json"),
129 '{"enabledPlugins":{"plugin@shop":true,"local@shop":false}}',
130 );
131 yield* fs.makeDirectory(path.join(workspace, ".claude"), { recursive: true });
132 yield* fs.writeFileString(
133 path.join(workspace, ".claude", "settings.json"),
134 '{"enabledPlugins":{"plugin@shop":false,"local@shop":true,"other@shop":["^1.0.0"]}}',
135 );
136 const projectSettings = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
137 assert.deepEqual(
138 projectSettings.map((skill) => [skill.name, skill.scope, skill.path]),
139 [["local:review", "project", path.join(localInstall, "skills", "review", "SKILL.md")]],
140 );
141 assert.deepEqual(
142 (yield* discoverClaudeSkills({ homePath: configDir }, nestedWorkspace)).map((skill) => [
143 skill.name,
144 skill.scope,
145 skill.path,
146 ]),
147 [["plugin:review", "project", path.join(projectInstall, "skills", "review", "SKILL.md")]],
148 );
149 yield* fs.writeFileString(
150 path.join(workspace, ".claude", "settings.local.json"),
151 '{"enabledPlugins":{"plugin@shop":true,"local@shop":false},"skillOverrides":{"invalid":"bogus"}}',
152 );
153 assert.deepEqual(
154 yield* discoverClaudeSkills({ homePath: configDir }, workspace),
155 projectSettings,
156 );
157 yield* fs.writeFileString(
158 path.join(workspace, ".claude", "settings.local.json"),
159 '{"enabledPlugins":{"plugin@shop":true,"local@shop":true}}',
160 );
161 const localSettings = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
162 assert.deepEqual(
163 localSettings.map((skill) => [skill.name, skill.scope, skill.path]),
164 [
165 ["local:review", "project", path.join(localInstall, "skills", "review", "SKILL.md")],
166 ["plugin:review", "project", path.join(projectInstall, "skills", "review", "SKILL.md")],
167 ],
168 );
169 assert.deepEqual(
170 yield* discoverClaudeSkills({ homePath: configDir }, nestedWorkspace),
171 localSettings,
172 );
173 assert.deepEqual(
174 yield* discoverClaudeSkills({ homePath: configDir }, aliasedWorkspace),
175 localSettings,
176 );
177 yield* fs.writeFileString(
178 path.join(workspace, ".claude", "settings.local.json"),
179 '{"enabledPlugins":{"local@shop":["^1.0.0"]}}',
180 );
181 assert.deepEqual(yield* discoverClaudeSkills({ homePath: configDir }, workspace), []);
182 yield* fs.writeFileString(
183 path.join(configDir, "settings.json"),
184 '{"enabledPlugins":{"plugin@shop":true,"local@shop":true}}',
185 );
186 const separateRepository = path.join(workspace, "separate");
187 yield* fs.makeDirectory(path.join(separateRepository, ".git"), { recursive: true });
188 for (const cwd of [undefined, path.join(tempDir, "elsewhere"), separateRepository]) {
189 const elsewhere = yield* discoverClaudeSkills({ homePath: configDir }, cwd);
190 assert.deepEqual(
191 elsewhere.map((skill) => [skill.name, skill.scope, skill.path]),
192 [
193 ["local:review", "user", path.join(managedInstall, "skills", "review", "SKILL.md")],
194 ["plugin:review", "user", path.join(userInstall, "skills", "review", "SKILL.md")],
195 ],
196 );
197 }
198 const worktree = path.join(tempDir, "worktree");
199 const worktreeGitDirectory = path.join(workspace, ".git", "worktrees", "fixture");
200 yield* fs.makeDirectory(worktree);
201 yield* fs.makeDirectory(worktreeGitDirectory, { recursive: true });
202 yield* fs.writeFileString(path.join(worktree, ".git"), `gitdir: ${worktreeGitDirectory}\n`);
203 yield* fs.writeFileString(path.join(worktreeGitDirectory, "commondir"), "../..\n");
204 yield* fs.writeFileString(
205 path.join(worktreeGitDirectory, "gitdir"),
206 path.join(worktree, ".git"),
207 );
208 assert.deepEqual(
209 yield* discoverClaudeSkills({ homePath: configDir }, worktree),
210 localSettings,
211 );
212 const linkedWorktree = path.join(tempDir, "linked-worktree");
213 yield* fs.symlink(worktree, linkedWorktree);
214 assert.deepEqual(
215 yield* discoverClaudeSkills({ homePath: configDir }, linkedWorktree),
216 localSettings,
217 );
218 }),
219 );
220
221 it.effect("resolves each install record's project repository once per discovery", () =>
222 Effect.gen(function* () {
223 const fs = yield* FileSystem.FileSystem;
224 const path = yield* Path.Path;
225 // Real path: macOS temp dirs sit behind a /var -> /private/var symlink.
226 const tempDir = yield* fs.realPath(
227 yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" }),
228 );
229 const configDir = path.join(tempDir, "claude-home");
230 const workspace = path.join(tempDir, "workspace");
231 const otherProject = path.join(tempDir, "other", "packages", "app");
232 const sameRepoProject = path.join(workspace, "packages", "app");
233 yield* fs.makeDirectory(path.join(workspace, ".git"), { recursive: true });
234 yield* fs.makeDirectory(path.join(tempDir, "other", ".git"), { recursive: true });
235 yield* fs.makeDirectory(otherProject, { recursive: true });
236 yield* fs.makeDirectory(sameRepoProject, { recursive: true });
237 const elsewhereInstall = path.join(configDir, "plugins", "elsewhere");
238 const sameRepoInstall = path.join(configDir, "plugins", "same-repo");
239 yield* writeSkill(path.join(elsewhereInstall, "skills"), "elsewhere", "# Elsewhere");
240 yield* writeSkill(path.join(sameRepoInstall, "skills"), "same-repo", "# Same repo");
241 const records = Array.from({ length: 4 }, () => ({
242 scope: "project",
243 projectPath: otherProject,
244 installPath: elsewhereInstall,
245 }));
246 const plugins = ["a@shop", "b@shop", "c@shop"];
247 yield* fs.writeFileString(
248 path.join(configDir, "plugins", "installed_plugins.json"),
249 JSON.stringify({
250 plugins: {
251 ...Object.fromEntries(plugins.map((key) => [key, records])),
252 "d@shop": [
253 { scope: "project", projectPath: sameRepoProject, installPath: sameRepoInstall },
254 ],
255 },
256 }),
257 );
258 yield* fs.writeFileString(
259 path.join(configDir, "settings.json"),
260 JSON.stringify({
261 enabledPlugins: Object.fromEntries([...plugins, "d@shop"].map((key) => [key, true])),
262 }),
263 );
264
265 const probed: Array<string> = [];
266 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace).pipe(
267 Effect.provideService(FileSystem.FileSystem, {
268 ...fs,
269 exists: (target) => {
270 probed.push(target);
271 return fs.exists(target);
272 },
273 }),
274 );
275 assert.strictEqual(
276 probed.filter((target) => target === path.join(otherProject, ".git")).length,
277 1,
278 );
279 assert.deepEqual(
280 skills.map((skill) => skill.name),
281 ["d:same-repo"],
282 );
283 }),
284 );
285
286 it.effect("publishes and dispatches canonical plugin folder names regardless of aliases", () =>
287 Effect.gen(function* () {
288 const fs = yield* FileSystem.FileSystem;
289 const path = yield* Path.Path;
290 const configDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
291 const plugin = path.join(configDir, "plugins", "installed");
292 yield* writeSkill(path.join(plugin, "skills"), "review", "---\nname: review-alias\n---\n");
293 yield* writeSkill(path.join(plugin, "skills"), "alias", "---\nname: dot.alias\n---\n");
294 yield* fs.writeFileString(
295 path.join(configDir, "plugins", "installed_plugins.json"),
296 JSON.stringify({ plugins: { "plugin@shop": [{ scope: "user", installPath: plugin }] } }),
297 );
298 yield* fs.writeFileString(
299 path.join(configDir, "settings.json"),
300 '{"enabledPlugins":{"plugin@shop":true}}',
301 );
302
303 const skills = yield* discoverClaudeSkills({ homePath: configDir });
304 assert.deepEqual(
305 planClaudeSkillDispatch(
306 "$plugin:alias focus on auth",
307 new Map(skills.map((skill) => [skill.name, skill])),
308 ),
309 {
310 leadingText: undefined,
311 commandText: "/plugin:alias focus on auth",
312 },
313 );
314 assert.deepEqual(
315 skills.map((skill) => skill.name),
316 ["plugin:alias", "plugin:review"],
317 );
318 }),
319 );
320
321 it.effect("uses the native cache root, root-skill fallback and manifest path boundaries", () =>
322 Effect.gen(function* () {
323 const fs = yield* FileSystem.FileSystem;
324 const path = yield* Path.Path;
325 const workspace = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
326 const configDir = path.join(workspace, "config");
327 const pluginsDir = path.join(workspace, "plugin-cache");
328 const plugin = path.join(pluginsDir, "installed");
329 const outside = path.join(workspace, "outside");
330 yield* writeSkill(pluginsDir, "installed", "---\nname: plugin:root.alias\n---\n");
331 yield* fs.makeDirectory(configDir);
332 yield* fs.writeFileString(
333 path.join(configDir, "settings.json"),
334 '{"enabledPlugins":{"plugin@shop":true}}',
335 );
336 yield* fs.writeFileString(
337 path.join(pluginsDir, "installed_plugins.json"),
338 JSON.stringify({ plugins: { "plugin@shop": [{ scope: "user", installPath: plugin }] } }),
339 );
340 const environment = { CLAUDE_CODE_PLUGIN_CACHE_DIR: "plugin-cache" };
341 assert.deepEqual(
342 (yield* discoverClaudeSkills({ homePath: configDir }, workspace, environment)).map(
343 (skill) => skill.name,
344 ),
345 ["plugin:root-alias"],
346 );
347
348 yield* writeSkill(path.join(plugin, "skills"), "plain", "# Plain");
349 yield* writeSkill(plugin, "custom", "---\nname: custom.review\n---\n");
350 yield* writeSkill(outside, "escaped", "# Outside");
351 yield* fs.symlink(outside, path.join(plugin, "escape"));
352 yield* fs.makeDirectory(path.join(plugin, ".claude-plugin"));
353 yield* fs.writeFileString(
354 path.join(plugin, ".claude-plugin", "plugin.json"),
355 '{"skills":["./custom","./escape","../../outside"]}',
356 );
357 assert.deepEqual(
358 (yield* discoverClaudeSkills({ homePath: configDir }, workspace, environment)).map(
359 (skill) => skill.name,
360 ),
361 ["plugin:custom-review", "plugin:plain"],
362 );
363 }),
364 );
365
366 it.effect("discovers skills from the current account's claude.ai synced plugins", () =>
367 Effect.gen(function* () {
368 const fs = yield* FileSystem.FileSystem;
369 const path = yield* Path.Path;
370 const configDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
371 const synced = path.join(configDir, "plugins", "synced");
372 const organization = "11111111-2222-4333-8444-555555555555";
373 const writeBucket = Effect.fn(function* (account: string, skillSuffix = "") {
374 const bucket = path.join(synced, `${organization}_${account}`);
375 const plugins = [
376 {
377 pluginId: "plugin_01pstack",
378 name: "pstack",
379 directory: "pstack",
380 skill: "poteto-mode",
381 },
382 {
383 pluginId: "plugin_01design",
384 name: "0f6a7c9e-1111-4222-8333-444444444444",
385 generation: 2,
386 directory: "0f6a7c9e-1111-4222-8333-444444444444~g2",
387 prefix: "design",
388 skill: "design-critique",
389 },
390 ];
391 for (const plugin of plugins) {
392 const pluginDir = path.join(bucket, plugin.directory);
393 yield* writeSkill(path.join(pluginDir, "skills"), plugin.skill + skillSuffix, "# Synced");
394 yield* fs.makeDirectory(path.join(pluginDir, ".claude-plugin"));
395 yield* fs.writeFileString(
396 path.join(pluginDir, ".claude-plugin", "plugin.json"),
397 JSON.stringify({ name: plugin.prefix ?? plugin.name }),
398 );
399 }
400 yield* fs.writeFileString(
401 path.join(bucket, "manifest.json"),
402 JSON.stringify({
403 lastUpdated: 1761990000000,
404 plugins: plugins.map(({ pluginId, name, generation }) => ({
405 pluginId,
406 name,
407 ...(generation ? { generation } : {}),
408 })),
409 }),
410 );
411 yield* fs.writeFileString(path.join(synced, `.bucket-${organization}_${account}`), "");
412 return bucket;
413 });
414 const bucket = yield* writeBucket("66666666-7777-4888-9999-aaaaaaaaaaaa");
415 yield* writeBucket("77777777-8888-4999-aaaa-bbbbbbbbbbbb", "-other-account");
416 yield* fs.writeFileString(
417 path.join(configDir, ".claude.json"),
418 JSON.stringify({
419 oauthAccount: {
420 organizationUuid: organization,
421 accountUuid: "66666666-7777-4888-9999-aaaaaaaaaaaa",
422 },
423 }),
424 );
425
426 assert.deepEqual(
427 (yield* discoverClaudeSkills({ homePath: configDir }, undefined, {})).map((skill) => [
428 skill.name,
429 skill.path,
430 ]),
431 [
432 [
433 "design:design-critique",
434 path.join(
435 bucket,
436 "0f6a7c9e-1111-4222-8333-444444444444~g2",
437 "skills",
438 "design-critique",
439 "SKILL.md",
440 ),
441 ],
442 ["pstack:poteto-mode", path.join(bucket, "pstack", "skills", "poteto-mode", "SKILL.md")],
443 ],
444 );
445 assert.deepEqual(
446 (yield* discoverClaudeSkills({ homePath: configDir }, undefined, {
447 CLAUDE_CODE_PLUGIN_CACHE_DIR: path.join(configDir, "relocated-cache"),
448 })).map((skill) => skill.name),
449 ["design:design-critique", "pstack:poteto-mode"],
450 );
451 assert.deepEqual(
452 (yield* discoverClaudeSkills({ homePath: configDir }, undefined, {
453 CLAUDE_CODE_OAUTH_TOKEN: "token",
454 CLAUDE_CODE_ACCOUNT_UUID: "77777777-8888-4999-aaaa-bbbbbbbbbbbb",
455 })).map((skill) => skill.name),
456 ["design:design-critique-other-account", "pstack:poteto-mode-other-account"],
457 );
458 yield* fs.writeFileString(
459 path.join(configDir, "settings.json"),
460 '{"enabledPlugins":{"pstack@synced":false}}',
461 );
462 assert.deepEqual(
463 (yield* discoverClaudeSkills({ homePath: configDir }, undefined, {})).map(
464 (skill) => skill.name,
465 ),
466 ["design:design-critique"],
467 );
468 yield* fs.writeFileString(
469 path.join(configDir, "settings.json"),
470 '{"syncClaudeAiPlugins":false}',
471 );
472 assert.deepEqual(yield* discoverClaudeSkills({ homePath: configDir }, undefined, {}), []);
473 }),
474 );
475
476 it.effect("gives a synced namespace to an installed plugin, then the first synced row", () =>
477 Effect.gen(function* () {
478 const fs = yield* FileSystem.FileSystem;
479 const path = yield* Path.Path;
480 const configDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
481 const bucketName = "11111111-2222-4333-8444-555555555555_unbound";
482 const synced = path.join(configDir, "plugins", "synced");
483 const bucket = path.join(synced, bucketName);
484 for (const [directory, prefix, skill] of [
485 ["pstack", "pstack", "poteto-mode"],
486 ["pstack-copy", "pstack", "copied"],
487 ["tools", "tools", "synced-tool"],
488 ["a_b", undefined, "renamed"],
489 ["PSTACK", "PSTACK", "shouted"],
490 ] as const) {
491 yield* writeSkill(path.join(bucket, directory, "skills"), skill, "# Synced");
492 if (prefix === undefined) continue;
493 yield* fs.makeDirectory(path.join(bucket, directory, ".claude-plugin"));
494 yield* fs.writeFileString(
495 path.join(bucket, directory, ".claude-plugin", "plugin.json"),
496 JSON.stringify({ name: prefix }),
497 );
498 }
499 yield* fs.writeFileString(
500 path.join(bucket, "manifest.json"),
501 JSON.stringify({
502 plugins: ["pstack", "pstack-copy", "tools", "a:b. ", "PSTACK", "no-id"].map(
503 (name, index) => (name === "no-id" ? { name } : { pluginId: `plugin_0${index}`, name }),
504 ),
505 }),
506 );
507 yield* fs.writeFileString(path.join(synced, `.bucket-${bucketName}`), "");
508 const installed = path.join(configDir, "plugins", "cache", "shop", "tools");
509 yield* writeSkill(path.join(installed, "skills"), "installed-tool", "# Installed");
510 yield* fs.writeFileString(
511 path.join(configDir, "plugins", "installed_plugins.json"),
512 JSON.stringify({
513 plugins: {
514 "tools@shop": [{ scope: "user", installPath: installed }],
515 "pstack@shop": [{ scope: "user", installPath: path.join(configDir, "missing") }],
516 },
517 }),
518 );
519 const names = (enabled: boolean) =>
520 Effect.gen(function* () {
521 yield* fs.writeFileString(
522 path.join(configDir, "settings.json"),
523 JSON.stringify({ enabledPlugins: { "tools@shop": enabled, "pstack@shop": true } }),
524 );
525 const skills = yield* discoverClaudeSkills({ homePath: configDir }, undefined, {
526 CLAUDE_CODE_ORGANIZATION_UUID: "11111111-2222-4333-8444-555555555555",
527 CLAUDE_CODE_ACCOUNT_UUID: "not-a-uuid",
528 });
529 return skills.map((skill) => skill.name);
530 });
531
532 assert.deepEqual(yield* names(true), [
533 "a_b:renamed",
534 "pstack:poteto-mode",
535 "tools:installed-tool",
536 ]);
537 assert.deepEqual(yield* names(false), [
538 "a_b:renamed",
539 "pstack:poteto-mode",
540 "tools:synced-tool",
541 ]);
542 yield* writeSkill(path.join(bucket, "no-id", "skills"), "unlisted", "# Synced");
543 assert.notInclude(
544 (yield* discoverClaudeSkills({ homePath: configDir }, undefined, {
545 CLAUDE_CODE_ORGANIZATION_UUID: "11111111-2222-4333-8444-555555555555",
546 })).map((skill) => skill.name),
547 "no-id:unlisted",
548 );
549 }),
550 );
551
552 it.effect("hides synced plugins from local settings but not shared project settings", () =>
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 configDir = path.join(tempDir, "claude-home");
558 const workspace = path.join(tempDir, "workspace");
559 const bucketName =
560 "11111111-2222-4333-8444-555555555555_66666666-7777-4888-9999-aaaaaaaaaaaa";
561 const synced = path.join(configDir, "plugins", "synced");
562 yield* writeSkill(path.join(synced, bucketName, "pstack", "skills"), "poteto-mode", "# S");
563 yield* fs.writeFileString(
564 path.join(synced, bucketName, "manifest.json"),
565 '{"plugins":[{"pluginId":"plugin_01pstack","name":"pstack"}]}',
566 );
567 yield* fs.writeFileString(path.join(synced, `.bucket-${bucketName}`), "");
568 yield* fs.makeDirectory(path.join(workspace, ".claude"), { recursive: true });
569 yield* fs.writeFileString(
570 path.join(workspace, ".claude", "settings.json"),
571 '{"syncClaudeAiPlugins":false}',
572 );
573 const environment = {
574 CLAUDE_CODE_ORGANIZATION_UUID: "11111111-2222-4333-8444-555555555555",
575 CLAUDE_CODE_ACCOUNT_UUID: "66666666-7777-4888-9999-AAAAAAAAAAAA",
576 };
577 const names = Effect.map(
578 discoverClaudeSkills({ homePath: configDir }, workspace, environment),
579 (skills) => skills.map((skill) => skill.name),
580 );
581 assert.deepEqual(yield* names, ["pstack:poteto-mode"]);
582 yield* fs.writeFileString(
583 path.join(workspace, ".claude", "settings.local.json"),
584 '{"syncClaudeAiPlugins":false}',
585 );
586 assert.deepEqual(yield* names, []);
587 }),
588 );
589
590 it.effect("discovers inline plugins from CLAUDE_CODE_PLUGIN_DIRS over installed namesakes", () =>
591 Effect.gen(function* () {
592 const fs = yield* FileSystem.FileSystem;
593 const path = yield* Path.Path;
594 const workspace = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
595 const configDir = path.join(workspace, "config");
596 const named = path.join(workspace, "named");
597 const unnamed = path.join(workspace, "unnamed");
598 const inherited = path.join(workspace, "inherited");
599 const muted = path.join(workspace, "muted");
600 const installed = path.join(workspace, "installed-acme");
601 yield* fs.makeDirectory(path.join(named, ".claude-plugin"), { recursive: true });
602 yield* fs.writeFileString(
603 path.join(named, ".claude-plugin", "plugin.json"),
604 '{"name":"acme"}',
605 );
606 yield* writeSkill(path.join(named, "skills"), "qa", "---\ndescription: QA a ticket\n---\n");
607 yield* writeSkill(path.join(installed, "skills"), "old", "# Old");
608 yield* writeSkill(path.join(unnamed, "skills"), "lint", "# Lint");
609 yield* writeSkill(path.join(muted, "skills"), "hidden", "# Hidden");
610 const quiet = path.join(workspace, "quiet");
611 yield* fs.makeDirectory(path.join(quiet, ".claude-plugin"), { recursive: true });
612 yield* fs.writeFileString(
613 path.join(quiet, ".claude-plugin", "plugin.json"),
614 '{"name":"quiet","defaultEnabled":false}',
615 );
616 yield* writeSkill(path.join(quiet, "skills"), "hush", "# Hush");
617 const bundle = path.join(workspace, "bundle");
618 yield* fs.makeDirectory(path.join(bundle, "tools", ".claude-plugin"), { recursive: true });
619 yield* fs.writeFileString(
620 path.join(bundle, "tools", ".claude-plugin", "plugin.json"),
621 '{"name":"tools"}',
622 );
623 yield* writeSkill(path.join(bundle, "tools", "skills"), "fmt", "# Fmt");
624 yield* writeSkill(path.join(bundle, "loose", "skills"), "ignored", "# Ignored");
625 yield* writeSkill(path.join(inherited, "skills"), "stale", "# Stale");
626 yield* writeSkill(path.join(workspace, "relative", "skills"), "skipped", "# Skipped");
627 yield* fs.makeDirectory(path.join(configDir, "plugins"), { recursive: true });
628 yield* fs.writeFileString(
629 path.join(configDir, "plugins", "installed_plugins.json"),
630 JSON.stringify({ plugins: { "acme@shop": [{ scope: "user", installPath: installed }] } }),
631 );
632 yield* fs.writeFileString(
633 path.join(configDir, "settings.json"),
634 JSON.stringify({
635 enabledPlugins: { "acme@shop": true, "muted@inline": false },
636 env: {
637 CLAUDE_CODE_PLUGIN_DIRS: [named, "relative", ` ${unnamed} `, muted, quiet, bundle].join(
638 ";",
639 ),
640 },
641 }),
642 );
643
644 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace, {
645 CLAUDE_CODE_PLUGIN_DIRS: inherited,
646 });
647 assert.deepEqual(
648 skills.map(({ name, scope, description }) => ({ name, scope, description })),
649 [
650 { name: "acme:qa", scope: "user", description: "QA a ticket" },
651 { name: "tools:fmt", scope: "user", description: undefined },
652 { name: "unnamed:lint", scope: "user", description: undefined },
653 ],
654 );
655
656 // Managed enabledPlugins entries lock their plugin name against inline copies.
657 const programFiles = path.join(workspace, "program-files");
658 yield* fs.makeDirectory(path.join(programFiles, "ClaudeCode"), { recursive: true });
659 yield* fs.writeFileString(
660 path.join(programFiles, "ClaudeCode", "managed-settings.json"),
661 '{"enabledPlugins":{"acme@shop":true}}',
662 );
663 assert.deepEqual(
664 (yield* discoverClaudeSkills({ homePath: path.join(workspace, "empty") }, workspace, {
665 CLAUDE_CODE_PLUGIN_DIRS: [named, unnamed].join(";"),
666 ProgramFiles: programFiles,
667 })).map((skill) => skill.name),
668 ["unnamed:lint"],
669 );
670
671 assert.deepEqual(
672 (yield* discoverClaudeSkills({ homePath: path.join(workspace, "empty") }, workspace, {
673 CLAUDE_CODE_PLUGIN_DIRS: inherited,
674 })).map((skill) => skill.name),
675 ["inherited:stale"],
676 );
677 }),
678 );
679
680 it.effect("discovers user and project skills with frontmatter metadata", () =>
681 Effect.gen(function* () {
682 const fs = yield* FileSystem.FileSystem;
683 const path = yield* Path.Path;
684 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
685 const configDir = path.join(tempDir, "claude-home");
686 const workspace = path.join(tempDir, "workspace");
687
688 yield* writeSkill(
689 path.join(configDir, "skills"),
690 "codex-review",
691 [
692 "---",
693 "name: codex-review",
694 "description: Ask Codex for a review.",
695 "---",
696 "",
697 "# Body",
698 ].join("\n"),
699 );
700 yield* writeSkill(
701 path.join(workspace, ".claude", "skills"),
702 "deploy",
703 ["---", "name: deploy", "description: Deploy the app.", "---", "", "# Deploy"].join("\n"),
704 );
705
706 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
707
708 assert.deepEqual(skills, [
709 {
710 name: "codex-review",
711 path: path.join(configDir, "skills", "codex-review", "SKILL.md"),
712 enabled: true,
713 scope: "user",
714 description: "Ask Codex for a review.",
715 },
716 {
717 name: "deploy",
718 path: path.join(workspace, ".claude", "skills", "deploy", "SKILL.md"),
719 enabled: true,
720 scope: "project",
721 description: "Deploy the app.",
722 },
723 ]);
724 }),
725 );
726
727 it.effect("discovers skills from the instance's --add-dir launch args", () =>
728 Effect.gen(function* () {
729 const fs = yield* FileSystem.FileSystem;
730 const path = yield* Path.Path;
731 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
732 const configDir = path.join(tempDir, "claude-home");
733 const workspace = path.join(tempDir, "workspace");
734 const extraDir = path.join(workspace, "extra skills");
735 yield* fs.makeDirectory(workspace, { recursive: true });
736 yield* writeSkill(
737 path.join(extraDir, ".claude", "skills"),
738 "demo",
739 ["---", "description: From an additional directory.", "---"].join("\n"),
740 );
741
742 assert.deepEqual(yield* discoverClaudeSkills({ homePath: configDir }, workspace), []);
743 for (const launchArgs of [
744 `--add-dir "${extraDir}"`,
745 `--add-dir="${extraDir}"`,
746 '--add-dir "extra skills"',
747 '--add-dir="extra skills"',
748 `--add-dir missing --add-dir "${extraDir}"`,
749 `--add-dir "${extraDir}" --add-dir missing`,
750 `--add-dir missing "${extraDir}"`,
751 ]) {
752 const settings = { homePath: configDir, launchArgs };
753 const skills = yield* discoverClaudeSkills(settings, workspace);
754 assert.deepEqual(skills, [
755 {
756 name: "demo",
757 path: path.join(extraDir, ".claude", "skills", "demo", "SKILL.md"),
758 enabled: true,
759 scope: "project",
760 description: "From an additional directory.",
761 },
762 ]);
763 }
764 const settings = { homePath: configDir, launchArgs: `--add-dir "${extraDir}"` };
765 const skills = yield* discoverClaudeSkills(settings, workspace);
766 assert.deepEqual(
767 planClaudeSkillDispatch(
768 "$demo",
769 new Map(skills.map((skill) => [skill.name, { path: skill.path }])),
770 ),
771 {
772 leadingText: undefined,
773 commandText: "/demo",
774 },
775 );
776 yield* writeSkill(
777 path.join(workspace, ".claude", "skills"),
778 "demo",
779 "---\ndescription: Project copy.\n---",
780 );
781 const projectSkills = yield* discoverClaudeSkills(settings, workspace);
782 assert.equal(projectSkills[0]?.description, "Project copy.");
783 for (const launchArgs of ["--add-dir", '--add-dir=""', '--add-dir "extra skills"']) {
784 const settings = { homePath: configDir, launchArgs };
785 assert.deepEqual(yield* discoverClaudeSkills(settings), []);
786 }
787 }),
788 );
789
790 it.effect("prefers managed then user skills on collisions, even with a stray .agents copy", () =>
791 Effect.gen(function* () {
792 const fs = yield* FileSystem.FileSystem;
793 const path = yield* Path.Path;
794 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
795 const configDir = path.join(tempDir, "claude-home");
796 const workspace = path.join(tempDir, "workspace");
797
798 yield* writeSkill(
799 path.join(configDir, "skills"),
800 "deploy",
801 ["---", "name: deploy", "description: User deploy.", "---"].join("\n"),
802 );
803 yield* writeSkill(
804 path.join(workspace, ".agents", "skills"),
805 "deploy",
806 ["---", "name: deploy", "description: Agents deploy.", "---"].join("\n"),
807 );
808 yield* writeSkill(
809 path.join(workspace, ".claude", "skills"),
810 "deploy",
811 ["---", "name: deploy", "description: Claude deploy.", "---"].join("\n"),
812 );
813
814 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
815
816 assert.deepEqual(skills, [
817 {
818 name: "deploy",
819 path: path.join(configDir, "skills", "deploy", "SKILL.md"),
820 enabled: true,
821 scope: "user",
822 description: "User deploy.",
823 },
824 ]);
825
826 const programFiles = path.join(tempDir, "Program Files");
827 const programData = path.join(tempDir, "ProgramData");
828 yield* writeSkill(
829 path.join(programData, "ClaudeCode", ".claude", "skills"),
830 "legacy-only",
831 "# Legacy skills must not be discovered",
832 );
833 yield* fs.writeFileString(
834 path.join(programData, "ClaudeCode", "managed-settings.json"),
835 '{"skillOverrides":{"deploy":"off"}}',
836 );
837 for (const ProgramFiles of [undefined, "", programFiles]) {
838 const legacySkills = yield* discoverClaudeSkills({ homePath: configDir }, workspace, {
839 PROGRAMDATA: programData,
840 ...(ProgramFiles !== undefined ? { ProgramFiles } : {}),
841 });
842 assert.deepEqual(
843 legacySkills,
844 skills.map((skill) => ({ ...skill, enabled: false })),
845 );
846 }
847 yield* writeSkill(
848 path.join(programFiles, "ClaudeCode", ".claude", "skills"),
849 "deploy",
850 ["---", "name: deploy", "description: Managed deploy.", "---"].join("\n"),
851 );
852 yield* fs.writeFileString(
853 path.join(configDir, "settings.json"),
854 '{"skillOverrides":{"deploy":"off"}}',
855 );
856 yield* fs.writeFileString(
857 path.join(programFiles, "ClaudeCode", "managed-settings.json"),
858 '{"skillOverrides":{"deploy":"on"}}',
859 );
860 const managedSkills = yield* discoverClaudeSkills({ homePath: configDir }, workspace, {
861 ProgramFiles: programFiles,
862 PROGRAMDATA: programData,
863 });
864
865 assert.deepEqual(managedSkills, [
866 {
867 name: "deploy",
868 path: path.join(programFiles, "ClaudeCode", ".claude", "skills", "deploy", "SKILL.md"),
869 enabled: true,
870 scope: "user",
871 description: "Managed deploy.",
872 },
873 ]);
874 assert.deepEqual(
875 yield* discoverClaudeSkills({ homePath: configDir }, workspace, {
876 PROGRAMFILES: ` ${programFiles} `,
877 PROGRAMDATA: programData,
878 }),
879 managedSkills,
880 );
881 }),
882 );
883
884 it.effect("recovers colon-bearing descriptions with invocation metadata intact", () =>
885 Effect.gen(function* () {
886 const fs = yield* FileSystem.FileSystem;
887 const path = yield* Path.Path;
888 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
889 const configDir = path.join(tempDir, "claude-home");
890
891 for (const [description, comment] of [
892 ["Browser automation + AI test authoring via kane-cli: run browser objectives, ...", ""],
893 ['Read C:\\skills\\guide#tag: continue with "quoted".', " # trailing: comment"],
894 ] as const) {
895 yield* writeSkill(
896 path.join(configDir, "skills"),
897 "kane-cli",
898 [
899 "---",
900 "name: frontmatter-alias",
901 `description: ${description}${comment}`,
902 "allowed-tools: [Read, Write]",
903 "disable-model-invocation: yes",
904 "user-invocable: no",
905 "---",
906 ].join("\n"),
907 );
908
909 const skills = yield* discoverClaudeSkills({ homePath: configDir }, undefined);
910
911 assert.deepEqual(skills, [
912 {
913 name: "kane-cli",
914 path: path.join(configDir, "skills", "kane-cli", "SKILL.md"),
915 enabled: true,
916 scope: "user",
917 description,
918 userInvocationOnly: true,
919 userInvocable: false,
920 },
921 ]);
922 }
923 }),
924 );
925
926 it.effect("falls back to the directory name and skips malformed frontmatter", () =>
927 Effect.gen(function* () {
928 const fs = yield* FileSystem.FileSystem;
929 const path = yield* Path.Path;
930 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
931 const configDir = path.join(tempDir, "claude-home");
932 const skillsDir = path.join(configDir, "skills");
933
934 yield* writeSkill(skillsDir, "no-frontmatter", "# Just a heading\n");
935 for (const [directoryName, field] of [
936 ["broken-yaml", "name: [unclosed"],
937 ["broken-tools", "allowed-tools: [Read, Write"],
938 ["broken-quoted", 'name: "unclosed: text'],
939 ] as const) {
940 yield* writeSkill(
941 skillsDir,
942 directoryName,
943 ["---", "description: Run: browser objectives.", field, "---"].join("\n"),
944 );
945 }
946 yield* fs.makeDirectory(skillsDir, { recursive: true });
947 yield* fs.writeFileString(path.join(skillsDir, "README.md"), "not a skill");
948
949 const skills = yield* discoverClaudeSkills({ homePath: configDir }, undefined);
950
951 // Claude falls back to directory names without frontmatter, but skips malformed frontmatter.
952 assert.deepEqual(
953 skills.map((skill) => skill.name),
954 ["no-frontmatter"],
955 );
956 assert.equal(skills[0]?.description, undefined);
957 }),
958 );
959
960 it.effect("honors CLAUDE_CONFIG_DIR from the environment when homePath is unset", () =>
961 Effect.gen(function* () {
962 const fs = yield* FileSystem.FileSystem;
963 const path = yield* Path.Path;
964 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
965 const environmentConfigDir = path.join(tempDir, "env-config");
966
967 yield* writeSkill(
968 path.join(environmentConfigDir, "skills"),
969 "env-skill",
970 ["---", "name: env-skill", "description: From env config dir.", "---"].join("\n"),
971 );
972
973 const skills = yield* discoverClaudeSkills({ homePath: "" }, undefined, {
974 CLAUDE_CONFIG_DIR: environmentConfigDir,
975 });
976
977 assert.deepEqual(
978 skills.map((skill) => skill.name),
979 ["env-skill"],
980 );
981
982 const explicitHome = path.join(tempDir, "explicit-home");
983 yield* writeSkill(
984 path.join(explicitHome, "skills"),
985 "explicit-skill",
986 ["---", "name: explicit-skill", "---"].join("\n"),
987 );
988 const explicitSkills = yield* discoverClaudeSkills({ homePath: explicitHome }, undefined, {
989 CLAUDE_CONFIG_DIR: environmentConfigDir,
990 });
991 assert.deepEqual(
992 explicitSkills.map((skill) => skill.name),
993 ["explicit-skill"],
994 );
995 }),
996 );
997
998 it.effect("resolves a relative CLAUDE_CONFIG_DIR against the workspace cwd", () =>
999 Effect.gen(function* () {
1000 const fs = yield* FileSystem.FileSystem;
1001 const path = yield* Path.Path;
1002 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
1003 const workspace = path.join(tempDir, "workspace");
1004 yield* fs.makeDirectory(workspace, { recursive: true });
1005
1006 // The CLI resolves relative CLAUDE_CONFIG_DIR against workspace cwd.
1007 yield* writeSkill(
1008 path.join(workspace, "relative-config", "skills"),
1009 "relative-skill",
1010 ["---", "name: relative-skill", "---"].join("\n"),
1011 );
1012
1013 const skills = yield* discoverClaudeSkills({ homePath: "" }, workspace, {
1014 CLAUDE_CONFIG_DIR: "relative-config",
1015 });
1016
1017 assert.deepEqual(
1018 skills.map((skill) => skill.name),
1019 ["relative-skill"],
1020 );
1021 assert.equal(skills[0]?.scope, "user");
1022 }),
1023 );
1024
1025 it.effect("disables skills switched off by skillOverrides", () =>
1026 Effect.gen(function* () {
1027 const fs = yield* FileSystem.FileSystem;
1028 const path = yield* Path.Path;
1029 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
1030 const configDir = path.join(tempDir, "claude-home");
1031 const workspace = path.join(tempDir, "workspace");
1032
1033 for (const name of ["kept", "off-by-user", "off-by-project"]) {
1034 yield* writeSkill(
1035 path.join(configDir, "skills"),
1036 name,
1037 ["---", `name: ${name}`, "---", "", "# Body"].join("\n"),
1038 );
1039 }
1040
1041 yield* fs.makeDirectory(configDir, { recursive: true });
1042 yield* fs.writeFileString(
1043 path.join(configDir, "settings.json"),
1044 '{ "skillOverrides": { "off-by-user": "off", "kept": "on" } }',
1045 );
1046 yield* fs.makeDirectory(path.join(workspace, ".claude"), { recursive: true });
1047 yield* fs.writeFileString(
1048 path.join(workspace, ".claude", "settings.json"),
1049 '{ "skillOverrides": { "off-by-project": "off" } }',
1050 );
1051
1052 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
1053
1054 assert.deepEqual(
1055 skills.map((skill) => [skill.name, skill.enabled]),
1056 [
1057 ["kept", true],
1058 ["off-by-project", false],
1059 ["off-by-user", false],
1060 ],
1061 );
1062 }),
1063 );
1064
1065 it.effect("ignores unreadable settings when resolving skillOverrides", () =>
1066 Effect.gen(function* () {
1067 const fs = yield* FileSystem.FileSystem;
1068 const path = yield* Path.Path;
1069 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
1070 const configDir = path.join(tempDir, "claude-home");
1071
1072 yield* writeSkill(
1073 path.join(configDir, "skills"),
1074 "kept",
1075 ["---", "name: kept", "---", "", "# Body"].join("\n"),
1076 );
1077 yield* fs.writeFileString(path.join(configDir, "settings.json"), "{ not json");
1078
1079 const skills = yield* discoverClaudeSkills({ homePath: configDir });
1080
1081 assert.deepEqual(
1082 skills.map((skill) => [skill.name, skill.enabled]),
1083 [["kept", true]],
1084 );
1085 }),
1086 );
1087
1088 it.effect("treats a user-invocable-only override like disable-model-invocation", () =>
1089 Effect.gen(function* () {
1090 const fs = yield* FileSystem.FileSystem;
1091 const path = yield* Path.Path;
1092 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
1093 const configDir = path.join(tempDir, "claude-home");
1094
1095 yield* writeSkill(
1096 path.join(configDir, "skills"),
1097 "ask-matt",
1098 ["---", "name: ask-matt", "---", "", "# Body"].join("\n"),
1099 );
1100 yield* fs.writeFileString(
1101 path.join(configDir, "settings.json"),
1102 '{ "skillOverrides": { "ask-matt": "user-invocable-only" } }',
1103 );
1104
1105 const skills = yield* discoverClaudeSkills({ homePath: configDir });
1106
1107 assert.deepEqual(
1108 skills.map((skill) => [skill.name, skill.enabled, skill.userInvocationOnly === true]),
1109 [["ask-matt", true, true]],
1110 );
1111 }),
1112 );
1113
1114 it.effect("drops every override in a file when one value is invalid, as Claude Code does", () =>
1115 Effect.gen(function* () {
1116 const fs = yield* FileSystem.FileSystem;
1117 const path = yield* Path.Path;
1118 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
1119 const configDir = path.join(tempDir, "claude-home");
1120
1121 for (const name of ["unknown-mode", "boolean-false", "sibling-off"]) {
1122 yield* writeSkill(
1123 path.join(configDir, "skills"),
1124 name,
1125 ["---", `name: ${name}`, "---", "", "# Body"].join("\n"),
1126 );
1127 }
1128 // Claude ignores the entire override map when any value is an unknown string or boolean.
1129 yield* fs.writeFileString(
1130 path.join(configDir, "settings.json"),
1131 '{ "skillOverrides": { "unknown-mode": "some-future-mode", "boolean-false": false, "sibling-off": "off" } }',
1132 );
1133
1134 const skills = yield* discoverClaudeSkills({ homePath: configDir });
1135
1136 assert.deepEqual(
1137 skills.map((skill) => [skill.name, skill.enabled]),
1138 [
1139 ["boolean-false", true],
1140 ["sibling-off", true],
1141 ["unknown-mode", true],
1142 ],
1143 );
1144 }),
1145 );
1146
1147 it.effect("reads repository root settings from a nested workspace", () =>
1148 Effect.gen(function* () {
1149 const fs = yield* FileSystem.FileSystem;
1150 const path = yield* Path.Path;
1151 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
1152 const configDir = path.join(tempDir, "claude-home");
1153 const repo = path.join(tempDir, "repo");
1154 const workspace = path.join(repo, "packages", "app");
1155
1156 for (const name of ["root-off", "root-off-cwd-on", "cwd-off-root-on"]) {
1157 yield* writeSkill(
1158 path.join(configDir, "skills"),
1159 name,
1160 ["---", `name: ${name}`, "---", "", "# Body"].join("\n"),
1161 );
1162 }
1163 yield* fs.makeDirectory(path.join(repo, ".git"), { recursive: true });
1164 yield* fs.makeDirectory(path.join(repo, ".claude"), { recursive: true });
1165 yield* fs.makeDirectory(path.join(workspace, ".claude"), { recursive: true });
1166 // The CLI ignores the root's plain settings.json from a nested cwd.
1167 yield* fs.writeFileString(
1168 path.join(repo, ".claude", "settings.json"),
1169 '{ "skillOverrides": { "cwd-off-root-on": "off" } }',
1170 );
1171 // The root local file outranks the workspace local file, as in the CLI.
1172 yield* fs.writeFileString(
1173 path.join(repo, ".claude", "settings.local.json"),
1174 '{ "skillOverrides": { "root-off": "off", "root-off-cwd-on": "off", "cwd-off-root-on": "on" } }',
1175 );
1176 yield* fs.writeFileString(
1177 path.join(workspace, ".claude", "settings.local.json"),
1178 '{ "skillOverrides": { "root-off-cwd-on": "on", "cwd-off-root-on": "off" } }',
1179 );
1180
1181 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
1182
1183 assert.deepEqual(
1184 skills.map((skill) => [skill.name, skill.enabled]),
1185 [
1186 ["cwd-off-root-on", true],
1187 ["root-off", false],
1188 ["root-off-cwd-on", false],
1189 ],
1190 );
1191 }),
1192 );
1193
1194 it.effect("ignores ancestor settings outside a repository", () =>
1195 Effect.gen(function* () {
1196 const fs = yield* FileSystem.FileSystem;
1197 const path = yield* Path.Path;
1198 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
1199 const configDir = path.join(tempDir, "claude-home");
1200 const parent = path.join(tempDir, "not-a-repo");
1201 const workspace = path.join(parent, "workspace");
1202
1203 yield* writeSkill(
1204 path.join(configDir, "skills"),
1205 "kept",
1206 ["---", "name: kept", "---", "", "# Body"].join("\n"),
1207 );
1208 yield* fs.makeDirectory(path.join(parent, ".claude"), { recursive: true });
1209 yield* fs.makeDirectory(workspace, { recursive: true });
1210 yield* fs.writeFileString(
1211 path.join(parent, ".claude", "settings.local.json"),
1212 '{ "skillOverrides": { "kept": "off" } }',
1213 );
1214
1215 const skills = yield* discoverClaudeSkills({ homePath: configDir }, workspace);
1216
1217 assert.deepEqual(
1218 skills.map((skill) => [skill.name, skill.enabled]),
1219 [["kept", true]],
1220 );
1221 }),
1222 );
1223
1224 it.effect("identifies a skill by its directory, as Claude Code does", () =>
1225 Effect.gen(function* () {
1226 const fs = yield* FileSystem.FileSystem;
1227 const path = yield* Path.Path;
1228 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
1229 const configDir = path.join(tempDir, "claude-home");
1230
1231 yield* writeSkill(
1232 path.join(configDir, "skills"),
1233 "probe-alias",
1234 ["---", "name: probe-alias-frontmatter", "---", "", "# Body"].join("\n"),
1235 );
1236 yield* fs.writeFileString(
1237 path.join(configDir, "settings.json"),
1238 '{ "skillOverrides": { "probe-alias-frontmatter": "off" } }',
1239 );
1240
1241 const skills = yield* discoverClaudeSkills({ homePath: configDir });
1242
1243 assert.deepEqual(
1244 skills.map((skill) => [skill.name, skill.enabled]),
1245 [["probe-alias", true]],
1246 );
1247 }),
1248 );
1249
1250 // regression: #9128 skills picked from the composer did not run
1251 it.effect("switches a skill off by its directory name", () =>
1252 Effect.gen(function* () {
1253 const fs = yield* FileSystem.FileSystem;
1254 const path = yield* Path.Path;
1255 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
1256 const configDir = path.join(tempDir, "claude-home");
1257
1258 yield* writeSkill(
1259 path.join(configDir, "skills"),
1260 "probe-alias",
1261 ["---", "name: probe-alias-frontmatter", "---", "", "# Body"].join("\n"),
1262 );
1263 yield* fs.writeFileString(
1264 path.join(configDir, "settings.json"),
1265 '{ "skillOverrides": { "probe-alias": "off" } }',
1266 );
1267
1268 const skills = yield* discoverClaudeSkills({ homePath: configDir });
1269
1270 assert.deepEqual(
1271 skills.map((skill) => [skill.name, skill.enabled]),
1272 [["probe-alias", false]],
1273 );
1274 }),
1275 );
1276
1277 it.effect("accepts the YAML 1.1 boolean spellings Claude Code allows", () =>
1278 Effect.gen(function* () {
1279 const fs = yield* FileSystem.FileSystem;
1280 const path = yield* Path.Path;
1281 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skills-" });
1282 const configDir = path.join(tempDir, "claude-home");
1283 const skillsDir = path.join(configDir, "skills");
1284
1285 yield* writeSkill(
1286 skillsDir,
1287 "user-only-yes",
1288 ["---", "disable-model-invocation: yes", "---", "", "# Body"].join("\n"),
1289 );
1290 yield* writeSkill(
1291 skillsDir,
1292 "agent-only-no",
1293 ["---", "user-invocable: no", "---", "", "# Body"].join("\n"),
1294 );
1295 yield* writeSkill(
1296 skillsDir,
1297 "plain-off",
1298 ["---", "disable-model-invocation: off", "---", "", "# Body"].join("\n"),
1299 );
1300
1301 const skills = yield* discoverClaudeSkills({ homePath: configDir });
1302
1303 assert.deepEqual(
1304 skills.map((skill) => [
1305 skill.name,
1306 skill.userInvocationOnly === true,
1307 skill.userInvocable === false,
1308 ]),
1309 [
1310 ["agent-only-no", false, true],
1311 ["plain-off", false, false],
1312 ["user-only-yes", true, false],
1313 ],
1314 );
1315 }),
1316 );
1317});