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