@@ -119,6 +119,11 @@ export class Directory extends Schema.Class<Directory>("Config.Directory")({
119119 path : AbsolutePath ,
120120} ) { }
121121
122+ export class File extends Schema . Class < File > ( "Config.File" ) ( {
123+ type : Schema . Literal ( "file" ) ,
124+ path : AbsolutePath ,
125+ } ) { }
126+
122127export class AgentsDirectory extends Schema . Class < AgentsDirectory > ( "Config.AgentsDirectory" ) ( {
123128 type : Schema . Literal ( "agents" ) ,
124129 path : AbsolutePath ,
@@ -129,7 +134,7 @@ export class ClaudeDirectory extends Schema.Class<ClaudeDirectory>("Config.Claud
129134 path : AbsolutePath ,
130135} ) { }
131136
132- export type Entry = Document | Directory | AgentsDirectory | ClaudeDirectory
137+ export type Entry = Document | Directory | File | AgentsDirectory | ClaudeDirectory
133138
134139export function latest < K extends keyof Info > ( entries : readonly Entry [ ] , key : K ) : Info [ K ] | undefined {
135140 return entries
@@ -138,7 +143,7 @@ export function latest<K extends keyof Info>(entries: readonly Entry[], key: K):
138143}
139144
140145export interface Interface {
141- /** Returns location config documents and supplemental directories from lowest to highest priority. */
146+ /** Returns location config documents and discovery sources from lowest to highest priority. */
142147 readonly entries : ( ) => Effect . Effect < Entry [ ] >
143148}
144149
@@ -227,31 +232,36 @@ const layer = Layer.effect(
227232 const directPaths = discovered
228233 . filter ( ( item ) => ! [ ".agents" , ".claude" , ".opencode" ] . includes ( path . basename ( item ) ) )
229234 . toReversed ( )
230- const direct = yield * Effect . forEach ( directPaths , loadFile ) . pipe (
235+ const direct = yield * Effect . forEach ( directPaths , ( filepath ) =>
236+ loadFile ( filepath ) . pipe (
237+ Effect . map ( ( config ) => [
238+ ...( config ? [ config ] : [ ] ) ,
239+ new File ( { type : "file" , path : AbsolutePath . make ( filepath ) } ) ,
240+ ] ) ,
241+ ) ,
242+ ) . pipe (
231243 Effect . orDie ,
232- Effect . map ( ( configs ) => configs . filter ( ( config ) : config is Document => config !== undefined ) ) ,
244+ Effect . map ( ( entries ) => entries . flat ( ) ) ,
233245 )
234246
235247 const supplementary = yield * Effect . forEach ( directories , loadDirectory ) . pipe ( Effect . orDie )
236- return {
237- entries : [ ...claude , ...agents , ...( supplementary [ 0 ] ?? [ ] ) , ...direct , ...supplementary . slice ( 1 ) . flat ( ) ] ,
238- directories : [ ...directories , ...claude . map ( ( entry ) => entry . path ) , ...agents . map ( ( entry ) => entry . path ) ] ,
239- files : directPaths ,
240- }
248+ return [ ...claude , ...agents , ...( supplementary [ 0 ] ?? [ ] ) , ...direct , ...supplementary . slice ( 1 ) . flat ( ) ]
241249 } )
242250
243251 const initial = yield * discover ( )
244- let configs = initial . entries
252+ let configs = initial
245253 const updates = yield * PubSub . unbounded < Watcher . Update > ( )
246254 const subscriptions = new Map < string , Effect . Effect < unknown > > ( )
247- const targets = ( snapshot : typeof initial ) => [
248- ...snapshot . directories . map ( ( path ) => ( { path, type : "directory" as const } ) ) ,
249- ...snapshot . files
250- . filter ( ( file ) => ! snapshot . directories . some ( ( directory ) => FSUtil . contains ( directory , file ) ) )
251- . map ( ( path ) => ( { path, type : "file" as const } ) ) ,
252- ]
253- const reconcile = Effect . fn ( "Config.reconcileWatches" ) ( function * ( snapshot : typeof initial ) {
254- const next = new Map ( targets ( snapshot ) . map ( ( target ) => [ JSON . stringify ( target ) , target ] ) )
255+ const reconcile = Effect . fn ( "Config.reconcileWatches" ) ( function * ( entries : readonly Entry [ ] ) {
256+ const directories = entries . flatMap ( ( entry ) => ( entry . type === "directory" ? [ entry . path ] : [ ] ) )
257+ const files = entries . flatMap ( ( entry ) => ( entry . type === "file" ? [ entry . path ] : [ ] ) )
258+ const targets = [
259+ ...directories . map ( ( path ) => ( { path, type : "directory" as const } ) ) ,
260+ ...files
261+ . filter ( ( file ) => ! directories . some ( ( directory ) => FSUtil . contains ( directory , file ) ) )
262+ . map ( ( path ) => ( { path, type : "file" as const } ) ) ,
263+ ]
264+ const next = new Map ( targets . map ( ( target ) => [ JSON . stringify ( target ) , target ] ) )
255265 for ( const [ key , stop ] of subscriptions ) {
256266 if ( next . has ( key ) ) continue
257267 yield * stop
@@ -272,7 +282,7 @@ const layer = Layer.effect(
272282 Stream . runForEach ( ( update ) =>
273283 Effect . gen ( function * ( ) {
274284 const next = yield * discover ( )
275- configs = next . entries
285+ configs = next
276286 yield * reconcile ( next )
277287 yield * events . publish ( ConfigSchema . Event . Updated , { } )
278288 } ) . pipe ( Effect . catchCause ( ( cause ) => Effect . logError ( "failed to reload config" , { path : update . path , cause } ) ) ) ,
0 commit comments