@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

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