@@ -62,7 +62,7 @@ export namespace Config {
6262 ]
6363
6464 for ( const dir of directories ) {
65- await assertValid ( dir ) . catch ( ( ) => { } )
65+ await assertValid ( dir )
6666 installDependencies ( dir )
6767 result . command = mergeDeep ( result . command ?? { } , await loadCommand ( dir ) )
6868 result . agent = mergeDeep ( result . agent , await loadAgent ( dir ) )
@@ -120,23 +120,20 @@ export namespace Config {
120120 }
121121 } )
122122
123+ const INVALID_DIRS = new Bun . Glob ( `{${ [ "agents" , "commands" , "plugins" , "tools" ] . join ( "," ) } }/` )
123124 async function assertValid ( dir : string ) {
124- const ALLOWED_DIRS = new Set ( [ "agent" , "command" , "mode" , "plugin" , "tool" , "themes" ] )
125- const UNEXPECTED_DIR_GLOB = new Bun . Glob ( "*/" )
126- for await ( const item of UNEXPECTED_DIR_GLOB . scan ( {
127- absolute : true ,
128- followSymlinks : true ,
129- dot : true ,
130- cwd : dir ,
131- onlyFiles : false ,
132- } ) ) {
133- const dirname = path . basename ( item )
134- if ( ! ALLOWED_DIRS . has ( dirname ) ) {
135- throw new InvalidError ( {
136- path : dir ,
137- message : `Unexpected directory "${ dirname } " found in "${ dir } ". Only ${ ALLOWED_DIRS . values ( ) . toArray ( ) . join ( ", " ) } directories are allowed.` ,
138- } )
139- }
125+ const invalid = await Array . fromAsync (
126+ INVALID_DIRS . scan ( {
127+ onlyFiles : false ,
128+ cwd : dir ,
129+ } ) ,
130+ )
131+ for ( const item of invalid ) {
132+ throw new DirectoryError ( {
133+ path : dir ,
134+ dir : item ,
135+ suggestion : item . substring ( 0 , item . length - 1 ) ,
136+ } )
140137 }
141138 }
142139
@@ -714,6 +711,15 @@ export namespace Config {
714711 } ) ,
715712 )
716713
714+ export const DirectoryError = NamedError . create (
715+ "ConfigDirectoryError" ,
716+ z . object ( {
717+ path : z . string ( ) ,
718+ dir : z . string ( ) ,
719+ suggestion : z . string ( ) ,
720+ } ) ,
721+ )
722+
717723 export const InvalidError = NamedError . create (
718724 "ConfigInvalidError" ,
719725 z . object ( {
0 commit comments