@@ -47,15 +47,17 @@ const decodeSkillFrontmatter = Schema.decodeUnknownSync(SkillFrontmatter);
4747export class AntigravitySkillsProbeError extends Schema . TaggedError < AntigravitySkillsProbeError > ( ) (
4848 "AntigravitySkillsProbeError" ,
4949 {
50- reason : Schema . Literals ( [ "scan-budget-exhausted" , "filesystem-error" ] ) ,
50+ reason : Schema . Literals ( [ "scan-budget-exhausted" , "filesystem-error" , "invalid-config" ] ) ,
5151 path : Schema . String ,
5252 cause : Schema . optional ( Schema . Defect ( ) ) ,
5353 } ,
5454) {
5555 override get message ( ) : string {
5656 return this . reason === "scan-budget-exhausted"
5757 ? `Antigravity skill discovery exceeded its scan limit at '${ this . path } '.`
58- : `Antigravity could not read skills at '${ this . path } '.` ;
58+ : this . reason === "invalid-config"
59+ ? `Antigravity could not parse plugin configuration at '${ this . path } '.`
60+ : `Antigravity could not read skills at '${ this . path } '.` ;
5961 }
6062}
6163
@@ -137,32 +139,17 @@ const readSkill = Effect.fn("readAntigravitySkill")(function* (
137139 return bytes . toString ( "utf8" ) ;
138140} ) ;
139141
140- /** Keep read errors typed so workspace snapshots cannot cache partial results. */
141- export const discoverAntigravitySkills = Effect . fn ( "discoverAntigravitySkills" ) ( function * ( input : {
142- readonly cwd : string ;
143- readonly userHome : string ;
144- } ) : Effect . fn . Return <
145- ReadonlyArray < ServerProviderSkill > ,
146- AntigravitySkillsProbeError ,
147- FileSystem . FileSystem | Path . Path
148- > {
142+ interface SkillRoot {
143+ readonly directory : string ;
144+ readonly scope : string ;
145+ }
146+
147+ const scanSkillDirectories = Effect . fn ( "scanAntigravitySkillDirectories" ) ( function * (
148+ roots : ReadonlyArray < SkillRoot > ,
149+ budget : ScanBudget ,
150+ ) {
149151 const fileSystem = yield * FileSystem . FileSystem ;
150152 const path = yield * Path . Path ;
151- const [ configSkills , cliSkills ] = antigravityUserSkillDirectories (
152- path ,
153- path . join ( input . userHome , ".gemini" ) ,
154- ) ;
155- const roots = [
156- { directory : configSkills , scope : "user" } ,
157- { directory : path . resolve ( input . cwd , ".gemini" , "skills" ) , scope : "project" } ,
158- { directory : cliSkills , scope : "user" } ,
159- { directory : path . resolve ( input . cwd , ".agents" , "skills" ) , scope : "project" } ,
160- { directory : path . resolve ( input . cwd , ".agent" , "skills" ) , scope : "project" } ,
161- ] ;
162- const budget : ScanBudget = {
163- remainingBytes : MAX_SCAN_BYTES ,
164- remainingEntries : MAX_SCAN_ENTRIES ,
165- } ;
166153 const skillsByName = new Map < string , ServerProviderSkill > ( ) ;
167154
168155 const scanDirectory = Effect . fn ( "scanAntigravitySkillDirectory" ) ( function * (
@@ -216,3 +203,142 @@ export const discoverAntigravitySkills = Effect.fn("discoverAntigravitySkills")(
216203 }
217204 return [ ...skillsByName . values ( ) ] . sort ( ( left , right ) => left . name . localeCompare ( right . name ) ) ;
218205} ) ;
206+
207+ const PluginManifest = Schema . fromJsonString (
208+ Schema . Struct ( { disabled : Schema . optional ( Schema . Boolean ) } ) ,
209+ ) ;
210+ const PluginPreferences = Schema . fromJsonString (
211+ Schema . Struct ( {
212+ plugins : Schema . optional (
213+ Schema . Record ( Schema . String , Schema . Struct ( { enabled : Schema . optional ( Schema . Boolean ) } ) ) ,
214+ ) ,
215+ } ) ,
216+ ) ;
217+
218+ const decodePluginManifest = Schema . decodeEffect ( PluginManifest ) ;
219+ const decodePluginPreferences = Schema . decodeEffect ( PluginPreferences ) ;
220+ const encodeString = Schema . encodeSync ( Schema . fromJsonString ( Schema . String ) ) ;
221+
222+ const discoverAntigravityPlugins = Effect . fn ( "discoverAntigravityPlugins" ) ( function * (
223+ userHome : string ,
224+ ) {
225+ const fileSystem = yield * FileSystem . FileSystem ;
226+ const path = yield * Path . Path ;
227+ const config = path . join ( userHome , ".gemini" , "config" ) ;
228+ const directory = path . join ( config , "plugins" ) ;
229+ const entries = yield * readIfPresent ( fileSystem . readDirectory ( directory ) , directory ) ;
230+ if ( entries === undefined ) return [ ] ;
231+ const budget : ScanBudget = {
232+ remainingBytes : MAX_SCAN_BYTES ,
233+ remainingEntries : MAX_SCAN_ENTRIES ,
234+ } ;
235+ if ( entries . length > budget . remainingEntries ) {
236+ return yield * new AntigravitySkillsProbeError ( {
237+ reason : "scan-budget-exhausted" ,
238+ path : directory ,
239+ } ) ;
240+ }
241+ budget . remainingEntries -= entries . length ;
242+ const preferencesPath = path . join ( config , "config.json" ) ;
243+ const preferencesContents = yield * readSkill ( preferencesPath , budget ) ;
244+ const preferences =
245+ preferencesContents === undefined
246+ ? { plugins : { } }
247+ : yield * decodePluginPreferences ( preferencesContents ) . pipe (
248+ Effect . mapError (
249+ ( cause ) =>
250+ new AntigravitySkillsProbeError ( {
251+ reason : "invalid-config" ,
252+ path : preferencesPath ,
253+ cause,
254+ } ) ,
255+ ) ,
256+ ) ;
257+ const plugins = [ ] ;
258+ for ( const entry of entries . toSorted ( ) ) {
259+ const pluginDirectory = path . join ( directory , entry ) ;
260+ if (
261+ ( yield * readIfPresent ( fileSystem . stat ( pluginDirectory ) , pluginDirectory ) ) ?. type !==
262+ "Directory"
263+ )
264+ continue ;
265+ const manifestPath = path . join ( pluginDirectory , "plugin.json" ) ;
266+ const contents = yield * readSkill ( manifestPath , budget ) ;
267+ if ( contents === undefined ) continue ;
268+ const manifest = yield * decodePluginManifest ( contents ) . pipe (
269+ Effect . mapError (
270+ ( cause ) =>
271+ new AntigravitySkillsProbeError ( { reason : "invalid-config" , path : manifestPath , cause } ) ,
272+ ) ,
273+ ) ;
274+ if ( ! ( preferences . plugins ?. [ entry ] ?. enabled ?? ! manifest . disabled ) ) continue ;
275+ const skills = yield * scanSkillDirectories (
276+ [ { directory : path . join ( pluginDirectory , "skills" ) , scope : "user" } ] ,
277+ budget ,
278+ ) ;
279+ if ( skills . length === 0 ) continue ;
280+ const namespace = / ^ [ a - z A - Z 0 - 9 ] / . test ( entry ) ? entry : `plugin${ entry } ` ;
281+ plugins . push ( {
282+ directory : pluginDirectory ,
283+ skills : skills . map ( ( skill ) => ( { ...skill , name : `${ namespace } :${ skill . name } ` } ) ) ,
284+ } ) ;
285+ }
286+ return plugins ;
287+ } ) ;
288+
289+ /** Keep read errors typed so workspace snapshots cannot cache partial results. */
290+ export const discoverAntigravitySkills = Effect . fn ( "discoverAntigravitySkills" ) ( function * ( input : {
291+ readonly cwd : string ;
292+ readonly userHome : string ;
293+ } ) : Effect . fn . Return <
294+ ReadonlyArray < ServerProviderSkill > ,
295+ AntigravitySkillsProbeError ,
296+ FileSystem . FileSystem | Path . Path
297+ > {
298+ const path = yield * Path . Path ;
299+ const [ configSkills , cliSkills ] = antigravityUserSkillDirectories (
300+ path ,
301+ path . join ( input . userHome , ".gemini" ) ,
302+ ) ;
303+ const skills = yield * scanSkillDirectories (
304+ [
305+ { directory : configSkills , scope : "user" } ,
306+ { directory : path . resolve ( input . cwd , ".gemini" , "skills" ) , scope : "project" } ,
307+ { directory : cliSkills , scope : "user" } ,
308+ { directory : path . resolve ( input . cwd , ".agents" , "skills" ) , scope : "project" } ,
309+ { directory : path . resolve ( input . cwd , ".agent" , "skills" ) , scope : "project" } ,
310+ ] ,
311+ { remainingBytes : MAX_SCAN_BYTES , remainingEntries : MAX_SCAN_ENTRIES } ,
312+ ) ;
313+ const plugins = yield * discoverAntigravityPlugins ( input . userHome ) ;
314+ return [ ...skills , ...plugins . flatMap ( ( plugin ) => plugin . skills ) ] . sort ( ( left , right ) =>
315+ left . name . localeCompare ( right . name ) ,
316+ ) ;
317+ } ) ;
318+
319+ // ACP accepts standalone skills, so plugin entries use a process-owned native catalog.
320+ export const prepareAntigravityPluginSkills = Effect . fn ( "prepareAntigravityPluginSkills" ) (
321+ function * ( input : { readonly userHome : string ; readonly runtimeTempDirectory : string } ) {
322+ const fileSystem = yield * FileSystem . FileSystem ;
323+ const path = yield * Path . Path ;
324+ const plugins = yield * discoverAntigravityPlugins ( input . userHome ) ;
325+ if ( plugins . length === 0 ) return [ ] ;
326+ const directory = path . join ( input . runtimeTempDirectory , "plugin-skills" ) ;
327+ yield * Effect . forEach (
328+ plugins . flatMap ( ( plugin ) =>
329+ plugin . skills . map ( ( skill ) => ( { pluginDirectory : plugin . directory , skill } ) ) ,
330+ ) ,
331+ ( { pluginDirectory, skill } , index ) =>
332+ Effect . gen ( function * ( ) {
333+ const skillDirectory = path . join ( directory , ".agents" , "skills" , String ( index ) ) ;
334+ yield * fileSystem . makeDirectory ( skillDirectory , { recursive : true } ) ;
335+ yield * fileSystem . writeFileString (
336+ path . join ( skillDirectory , "SKILL.md" ) ,
337+ `---\nname: ${ encodeString ( skill . name ) } \ndescription: ${ encodeString ( skill . description ?? "" ) } \n---\n\nRead and follow the skill at ${ encodeString ( skill . path ) } . Resolve its relative paths from ${ encodeString ( path . dirname ( skill . path ) ) } . The plugin root is ${ encodeString ( pluginDirectory ) } .\n` ,
338+ ) ;
339+ } ) ,
340+ { concurrency : 8 , discard : true } ,
341+ ) ;
342+ return [ directory , ...plugins . map ( ( plugin ) => plugin . directory ) ] ;
343+ } ,
344+ ) ;
0 commit comments