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