@@ -20,6 +20,172 @@ const writeSkill = Effect.fn(function* (
2020} ) ;
2121
2222it . layer ( NodeServices . layer ) ( "discoverClaudeSkills" , ( it ) => {
23+ it . effect (
24+ "discovers only enabled installed plugin skills with their namespace and metadata" ,
25+ ( ) =>
26+ Effect . gen ( function * ( ) {
27+ const fs = yield * FileSystem . FileSystem ;
28+ const path = yield * Path . Path ;
29+ const tempDir = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-claude-skills-" } ) ;
30+ const configDir = path . join ( tempDir , "claude-home" ) ;
31+ const plugin = path . join ( configDir , "plugins" , "cache" , "shop" , "plugin" , "1.0.0" ) ;
32+ yield * writeSkill ( path . join ( plugin , "skills" ) , "plain" , "# Plain" ) ;
33+ yield * writeSkill (
34+ path . join ( plugin , "skills" , "engineering" ) ,
35+ "review" ,
36+ "---\nname: ignored-alias\ndescription: Review changes.\ndisable-model-invocation: yes\nuser-invocable: no\n---\n" ,
37+ ) ;
38+ yield * writeSkill ( path . join ( plugin , "extra" ) , "deploy" , "# Deploy" ) ;
39+ yield * fs . makeDirectory ( path . join ( plugin , ".claude-plugin" ) , { recursive : true } ) ;
40+ yield * fs . writeFileString (
41+ path . join ( plugin , ".claude-plugin" , "plugin.json" ) ,
42+ '{"skills":["./skills/engineering/review","./extra","./skills/plain"]}' ,
43+ ) ;
44+ yield * fs . writeFileString (
45+ path . join ( configDir , "plugins" , "installed_plugins.json" ) ,
46+ `{"version":2,"plugins":{
47+ "plugin@shop":[null,{"scope":"user","installPath":"${ plugin . replaceAll ( "\\" , "/" ) } "}],
48+ "disabled@shop":[{"scope":"user","installPath":"${ plugin . replaceAll ( "\\" , "/" ) } "}],
49+ "unmentioned@shop":[{"scope":"user","installPath":"${ plugin . replaceAll ( "\\" , "/" ) } "}]
50+ }}` ,
51+ ) ;
52+ yield * fs . writeFileString (
53+ path . join ( configDir , "settings.json" ) ,
54+ '{ "enabledPlugins": { "plugin@shop": true, "disabled@shop": false, "uninstalled@shop": true }, "skillOverrides": { "plugin:review": "off" } }' ,
55+ ) ;
56+
57+ const skills = yield * discoverClaudeSkills ( { homePath : configDir } ) ;
58+ assert . deepEqual ( skills , [
59+ {
60+ name : "plugin:deploy" ,
61+ path : path . join ( plugin , "extra" , "deploy" , "SKILL.md" ) ,
62+ enabled : true ,
63+ scope : "user" ,
64+ } ,
65+ {
66+ name : "plugin:plain" ,
67+ path : path . join ( plugin , "skills" , "plain" , "SKILL.md" ) ,
68+ enabled : true ,
69+ scope : "user" ,
70+ } ,
71+ {
72+ name : "plugin:review" ,
73+ path : path . join ( plugin , "skills" , "engineering" , "review" , "SKILL.md" ) ,
74+ enabled : false ,
75+ scope : "user" ,
76+ description : "Review changes." ,
77+ userInvocationOnly : true ,
78+ userInvocable : false ,
79+ } ,
80+ ] ) ;
81+ } ) ,
82+ ) ;
83+
84+ it . effect (
85+ "keeps plugin installs in their workspace and prefers local then project over user" ,
86+ ( ) =>
87+ Effect . gen ( function * ( ) {
88+ const fs = yield * FileSystem . FileSystem ;
89+ const path = yield * Path . Path ;
90+ const tempDir = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-claude-skills-" } ) ;
91+ const configDir = path . join ( tempDir , "claude-home" ) ;
92+ const workspace = path . join ( tempDir , "workspace" ) ;
93+ const other = path . join ( tempDir , "other" ) ;
94+ const installs = [ "user" , "project" , "local" , "foreign" ] . map ( ( scope ) =>
95+ path . join ( configDir , "plugins" , scope ) ,
96+ ) ;
97+ for ( const install of installs )
98+ yield * writeSkill ( path . join ( install , "skills" ) , "review" , "# Review" ) ;
99+ yield * fs . writeFileString (
100+ path . join ( configDir , "plugins" , "installed_plugins.json" ) ,
101+ `{"version":2,"plugins":{
102+ "plugin@shop":[
103+ {"scope":"user","installPath":"${ installs [ 0 ] ! . replaceAll ( "\\" , "/" ) } "},
104+ {"scope":"project","projectPath":"${ workspace . replaceAll ( "\\" , "/" ) } ","installPath":"${ installs [ 1 ] ! . replaceAll ( "\\" , "/" ) } "},
105+ {"scope":"local","projectPath":"${ workspace . replaceAll ( "\\" , "/" ) } ","installPath":"${ installs [ 2 ] ! . replaceAll ( "\\" , "/" ) } "},
106+ {"scope":"local","projectPath":"${ other . replaceAll ( "\\" , "/" ) } ","installPath":"${ installs [ 3 ] ! . replaceAll ( "\\" , "/" ) } "}
107+ ],
108+ "foreign@shop":[{"scope":"project","projectPath":"${ other . replaceAll ( "\\" , "/" ) } ","installPath":"${ installs [ 3 ] ! . replaceAll ( "\\" , "/" ) } "}],
109+ "ownerless@shop":[{"scope":"project","installPath":"${ installs [ 3 ] ! . replaceAll ( "\\" , "/" ) } "}]
110+ }}` ,
111+ ) ;
112+ yield * fs . writeFileString (
113+ path . join ( configDir , "settings.json" ) ,
114+ '{"enabledPlugins":{"plugin@shop":true,"foreign@shop":true,"ownerless@shop":true}}' ,
115+ ) ;
116+
117+ const local = yield * discoverClaudeSkills ( { homePath : configDir } , workspace ) ;
118+ assert . deepEqual (
119+ local . map ( ( skill ) => [ skill . name , skill . scope , skill . path ] ) ,
120+ [ [ "plugin:review" , "project" , path . join ( installs [ 2 ] ! , "skills" , "review" , "SKILL.md" ) ] ] ,
121+ ) ;
122+ const user = yield * discoverClaudeSkills ( { homePath : configDir } ) ;
123+ assert . deepEqual (
124+ user . map ( ( skill ) => [ skill . name , skill . scope , skill . path ] ) ,
125+ [ [ "plugin:review" , "user" , path . join ( installs [ 0 ] ! , "skills" , "review" , "SKILL.md" ) ] ] ,
126+ ) ;
127+
128+ // Windows does not allow colon-bearing filesystem skill directories.
129+ if ( path . sep !== "\\" ) {
130+ yield * writeSkill (
131+ path . join ( workspace , ".claude" , "skills" ) ,
132+ "plugin:review" ,
133+ "# Project review" ,
134+ ) ;
135+ yield * writeSkill ( path . join ( configDir , "skills" ) , "plugin:review" , "# User review" ) ;
136+ const collision = yield * discoverClaudeSkills ( { homePath : configDir } , workspace ) ;
137+ assert . equal ( collision . length , 1 ) ;
138+ assert . equal (
139+ collision [ 0 ] ?. path ,
140+ path . join ( configDir , "skills" , "plugin:review" , "SKILL.md" ) ,
141+ ) ;
142+ }
143+ } ) ,
144+ ) ;
145+
146+ it . effect (
147+ "merges plugin enablement separately from overrides and honors explicit local disables" ,
148+ ( ) =>
149+ Effect . gen ( function * ( ) {
150+ const fs = yield * FileSystem . FileSystem ;
151+ const path = yield * Path . Path ;
152+ const tempDir = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-claude-skills-" } ) ;
153+ const configDir = path . join ( tempDir , "claude-home" ) ;
154+ const workspace = path . join ( tempDir , "workspace" ) ;
155+ const plugin = path . join ( configDir , "plugins" , "cached" ) ;
156+ yield * writeSkill ( path . join ( plugin , "skills" ) , "review" , "# Review" ) ;
157+ yield * fs . writeFileString (
158+ path . join ( configDir , "plugins" , "installed_plugins.json" ) ,
159+ `{"version":2,"plugins":{"plugin@shop":[{"scope":"user","installPath":"${ plugin . replaceAll ( "\\" , "/" ) } "}]}}` ,
160+ ) ;
161+ yield * fs . writeFileString (
162+ path . join ( configDir , "settings.json" ) ,
163+ '{"enabledPlugins":{"plugin@shop":false}}' ,
164+ ) ;
165+ yield * fs . makeDirectory ( path . join ( workspace , ".claude" ) , { recursive : true } ) ;
166+ yield * fs . writeFileString (
167+ path . join ( workspace , ".claude" , "settings.json" ) ,
168+ '// project enablement\n{"enabledPlugins":{"plugin@shop":true,},"skillOverrides":{"plugin:review":"invalid"}}' ,
169+ ) ;
170+ assert . equal ( ( yield * discoverClaudeSkills ( { homePath : configDir } , workspace ) ) . length , 1 ) ;
171+ yield * fs . writeFileString (
172+ path . join ( workspace , ".claude" , "settings.local.json" ) ,
173+ '{"enabledPlugins":{"plugin@shop":false}}' ,
174+ ) ;
175+ assert . deepEqual ( yield * discoverClaudeSkills ( { homePath : configDir } , workspace ) , [ ] ) ;
176+ yield * fs . writeFileString (
177+ path . join ( workspace , ".claude" , "settings.local.json" ) ,
178+ '{"enabledPlugins":{"plugin@shop":true}}' ,
179+ ) ;
180+ assert . equal ( ( yield * discoverClaudeSkills ( { homePath : configDir } , workspace ) ) . length , 1 ) ;
181+ yield * fs . writeFileString (
182+ path . join ( configDir , "plugins" , "installed_plugins.json" ) ,
183+ "not json" ,
184+ ) ;
185+ assert . deepEqual ( yield * discoverClaudeSkills ( { homePath : configDir } , workspace ) , [ ] ) ;
186+ } ) ,
187+ ) ;
188+
23189 it . effect ( "discovers user and project skills with frontmatter metadata" , ( ) =>
24190 Effect . gen ( function * ( ) {
25191 const fs = yield * FileSystem . FileSystem ;
0 commit comments