@@ -82,6 +82,67 @@ function readProfileMode() {
8282 return String ( cfg ?. mode ?? 'prod' ) . trim ( ) . toLowerCase ( ) === 'dev' ? 'dev' : 'prod'
8383}
8484
85+ function readProjectProfileConfig ( state ) {
86+ const projectRoot = getActiveProjectRoot ( state )
87+ return readJsonFile ( path . join ( projectRoot , '.devcodex' , 'profile' , 'config.json' ) ) || null
88+ }
89+
90+ function listMemoryAgents ( state ) {
91+ const clientsDir = path . join ( getActiveProjectRoot ( state ) , '.devcodex' , '.memory' , 'clients' )
92+ if ( ! fs . existsSync ( clientsDir ) ) return [ ]
93+ try {
94+ return fs . readdirSync ( clientsDir , { withFileTypes : true } )
95+ . filter ( entry => entry . isDirectory ( ) )
96+ . map ( entry => String ( entry . name || '' ) . trim ( ) . toLowerCase ( ) )
97+ . filter ( Boolean )
98+ } catch {
99+ return [ ]
100+ }
101+ }
102+
103+ function inferBootstrapAgent ( state , payload ) {
104+ const existingAgents = new Set ( listMemoryAgents ( state ) )
105+ const platform = detectPlatform ( payload || { } )
106+
107+ if ( platform === 'claude' ) return 'claude-code'
108+ if ( platform === 'jetbrains-copilot' ) return 'jetbrains-copilot'
109+ if ( platform === 'vscode-copilot' ) {
110+ if ( existingAgents . has ( 'vscode-copilot' ) ) return 'vscode-copilot'
111+ if ( existingAgents . has ( 'copilot' ) ) return 'copilot'
112+ return 'vscode-copilot'
113+ }
114+ if ( platform === 'copilot' ) {
115+ if ( existingAgents . has ( 'copilot' ) ) return 'copilot'
116+ if ( existingAgents . has ( 'vscode-copilot' ) ) return 'vscode-copilot'
117+ return 'copilot'
118+ }
119+ return 'unknown-agent'
120+ }
121+
122+ function getBootstrapAgent ( state , payload ) {
123+ const configuredAgent = String ( readProjectProfileConfig ( state ) ?. agent || '' ) . trim ( ) . toLowerCase ( )
124+ return configuredAgent || inferBootstrapAgent ( state , payload )
125+ }
126+
127+ function formatDateStamp ( date ) {
128+ const year = String ( date . getFullYear ( ) )
129+ const month = String ( date . getMonth ( ) + 1 ) . padStart ( 2 , '0' )
130+ const day = String ( date . getDate ( ) ) . padStart ( 2 , '0' )
131+ return `${ year } ${ month } ${ day } `
132+ }
133+
134+ function getRecentBootstrapTaskStamps ( ) {
135+ const today = new Date ( )
136+ const yesterday = new Date ( today )
137+ yesterday . setDate ( today . getDate ( ) - 1 )
138+ return [ formatDateStamp ( today ) , formatDateStamp ( yesterday ) ]
139+ }
140+
141+ function isRecentBootstrapTaskPath ( input ) {
142+ const normalized = normalizeText ( input )
143+ return getRecentBootstrapTaskStamps ( ) . some ( stamp => normalized . endsWith ( `/tasks/${ stamp } .md` ) )
144+ }
145+
85146function normalizeText ( v ) {
86147 return String ( v || '' ) . replace ( / \\ / g, '/' ) . trim ( ) . toLowerCase ( )
87148}
@@ -268,11 +329,27 @@ function buildProjectScopedNeedles(projectRoot, segments) {
268329 return [ absolute , relative ]
269330}
270331
271- function getBootstrapScopes ( state ) {
332+ function getBootstrapScopes ( state , payload ) {
272333 const projectRoot = getActiveProjectRoot ( state )
334+ const bootstrapAgent = getBootstrapAgent ( state , payload )
335+ const memorySegments = [ '.devcodex' , '.memory' , 'clients' ]
336+ const memoryNeedles = bootstrapAgent
337+ ? buildProjectScopedNeedles ( projectRoot , [ ...memorySegments , bootstrapAgent ] )
338+ : buildProjectScopedNeedles ( projectRoot , memorySegments )
339+ const summaryNeedles = bootstrapAgent
340+ ? buildProjectScopedNeedles ( projectRoot , [ ...memorySegments , bootstrapAgent , 'SUMMARY.md' ] )
341+ : [ ]
342+ const taskNeedles = bootstrapAgent
343+ ? getRecentBootstrapTaskStamps ( ) . flatMap ( stamp => buildProjectScopedNeedles (
344+ projectRoot ,
345+ [ ...memorySegments , bootstrapAgent , 'tasks' , `${ stamp } .md` ]
346+ ) )
347+ : [ ]
273348 return {
274349 profileNeedles : buildProjectScopedNeedles ( projectRoot , [ '.devcodex' , 'profile' ] ) ,
275- memoryNeedles : buildProjectScopedNeedles ( projectRoot , [ '.devcodex' , '.memory' , 'clients' ] )
350+ memoryNeedles,
351+ summaryNeedles,
352+ taskNeedles
276353 }
277354}
278355
@@ -325,7 +402,7 @@ function resetState(mode, previousState) {
325402
326403function isBootstrapReadTool ( payload , state ) {
327404 const tn = getToolName ( payload ) . toLowerCase ( )
328- const scopes = getBootstrapScopes ( state )
405+ const scopes = getBootstrapScopes ( state , payload )
329406 // Copilot: read_file/list_dir/file_search/grep_search/semantic_search
330407 // Claude Code: Read/Glob/Grep (PascalCase → lowercased above)
331408 const readPatterns = [
@@ -339,13 +416,21 @@ function isBootstrapReadTool(payload, state) {
339416}
340417
341418function updateBootstrapState ( state , payload ) {
342- const scopes = getBootstrapScopes ( state )
419+ const scopes = getBootstrapScopes ( state , payload )
420+ const inputStrings = getToolInputStrings ( payload )
343421 if ( touchesPath ( payload , ...scopes . profileNeedles ) ) state . bootstrap . profileRead = true
344- if ( touchesPath ( payload , ...scopes . memoryNeedles ) &&
345- getToolInputStrings ( payload ) . some ( s => s . includes ( '/summary.md' ) ) ) state . bootstrap . summaryRead = true
346- if ( touchesPath ( payload , ...scopes . memoryNeedles ) &&
347- getToolInputStrings ( payload ) . some ( s => s . includes ( '/tasks/' ) && s . endsWith ( '.md' ) ) )
422+ if ( ( scopes . summaryNeedles . length && touchesPath ( payload , ...scopes . summaryNeedles ) ) ||
423+ ( ! scopes . summaryNeedles . length &&
424+ touchesPath ( payload , ...scopes . memoryNeedles ) &&
425+ inputStrings . some ( s => s . includes ( '/summary.md' ) ) ) ) {
426+ state . bootstrap . summaryRead = true
427+ }
428+ if ( ( scopes . taskNeedles . length && touchesPath ( payload , ...scopes . taskNeedles ) ) ||
429+ ( ! scopes . taskNeedles . length &&
430+ touchesPath ( payload , ...scopes . memoryNeedles ) &&
431+ inputStrings . some ( isRecentBootstrapTaskPath ) ) ) {
348432 state . bootstrap . tasksRead = true
433+ }
349434 state . bootstrapComplete = ! ! (
350435 state . bootstrap . profileRead && state . bootstrap . summaryRead && state . bootstrap . tasksRead
351436 )
0 commit comments