@@ -23,6 +23,7 @@ import type {
2323 CustomToolDefinitions ,
2424 FileTreeNode ,
2525} from '@codebuff/common/util/file'
26+ import type * as fsType from 'fs'
2627
2728export type RunState = {
2829 sessionState : SessionState
@@ -149,13 +150,13 @@ async function discoverProjectFiles(params: {
149150 )
150151 }
151152
152- const projectFilesRecord : Record < string , string > = { }
153+ const projectFilesResolved : Record < string , string > = { }
153154 for ( const [ filePath , contentPromise ] of Object . entries (
154155 projectFilePromises ,
155156 ) ) {
156- projectFilesRecord [ filePath ] = await contentPromise
157+ projectFilesResolved [ filePath ] = await contentPromise
157158 }
158- return projectFilesRecord
159+ return projectFilesResolved
159160}
160161
161162/**
@@ -180,37 +181,48 @@ function deriveKnowledgeFiles(
180181export async function initialSessionState (
181182 params : InitialSessionStateOptions ,
182183) : Promise < SessionState > {
183- const withDefaults = {
184- agentDefinitions : [ ] ,
185- customToolDefinitions : [ ] ,
186- logger : {
187- debug : ( ) => { } ,
188- info : ( ) => { } ,
189- warn : ( ) => { } ,
190- error : ( ) => { } ,
191- } ,
192- ...params ,
193- }
194- const {
195- cwd,
184+ const { cwd, maxAgentSteps } = params
185+ let {
196186 agentDefinitions,
197187 customToolDefinitions,
198- maxAgentSteps,
188+ projectFiles,
189+ knowledgeFiles,
190+ fs,
199191 logger,
200- } = withDefaults
201- let { projectFiles, knowledgeFiles, fs } = withDefaults
202-
192+ } = params
193+ if ( ! agentDefinitions ) {
194+ agentDefinitions = [ ]
195+ }
196+ if ( ! customToolDefinitions ) {
197+ customToolDefinitions = [ ]
198+ }
199+ if ( ! projectFiles ) {
200+ projectFiles = { }
201+ }
202+ if ( ! knowledgeFiles ) {
203+ knowledgeFiles = { }
204+ }
203205 if ( ! fs ) {
204- fs = ( await import ( 'fs' ) ) as unknown as CodebuffFileSystem
206+ fs = ( require ( 'fs' ) as typeof fsType ) . promises
207+ }
208+ if ( ! logger ) {
209+ logger = {
210+ debug : ( ) => { } ,
211+ info : ( ) => { } ,
212+ warn : ( ) => { } ,
213+ error : ( ) => { } ,
214+ }
205215 }
206216
207217 // Auto-discover project files if not provided and cwd is available
208218 if ( projectFiles === undefined && cwd ) {
209219 projectFiles = await discoverProjectFiles ( { cwd, fs, logger } )
210220 }
221+ logger . info ( { projectFiles } , 'asdf' )
211222 if ( knowledgeFiles === undefined ) {
212223 knowledgeFiles = projectFiles ? deriveKnowledgeFiles ( projectFiles ) : { }
213224 }
225+ logger . info ( { knowledgeFiles } , 'asdf' )
214226
215227 const processedAgentTemplates = processAgentDefinitions ( agentDefinitions )
216228 const processedCustomToolDefinitions = processCustomToolDefinitions (
0 commit comments