MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / initialSessionState

Function initialSessionState

sdk/src/run-state.ts:481–610  ·  view source on GitHub ↗
(
  params: InitialSessionStateOptions,
)

Source from the content-addressed store, hash-verified

479}
480
481export async function initialSessionState(
482 params: InitialSessionStateOptions,
483): Promise<SessionState> {
484 const { cwd, maxAgentSteps, skillsDir } = params
485 let {
486 agentDefinitions,
487 customToolDefinitions,
488 projectFiles,
489 knowledgeFiles,
490 userKnowledgeFiles: providedUserKnowledgeFiles,
491 fs,
492 spawn,
493 logger,
494 } = params
495 if (!agentDefinitions) {
496 agentDefinitions = []
497 }
498 if (!customToolDefinitions) {
499 customToolDefinitions = []
500 }
501 if (!fs) {
502 fs = (require('fs') as typeof fsType).promises
503 }
504 if (!spawn) {
505 const { spawn: nodeSpawn } = require('child_process')
506 spawn = nodeSpawn as CodebuffSpawn
507 }
508 if (!logger) {
509 logger = {
510 debug: () => {},
511 info: () => {},
512 warn: () => {},
513 error: () => {},
514 }
515 }
516
517 let discoveredProject:
518 | { fileTree: FileTreeNode[]; filePaths: string[] }
519 | undefined
520
521 // Auto-discover project files if not provided and cwd is available
522 if (projectFiles === undefined && cwd) {
523 discoveredProject = await discoverProjectPaths({ cwd, fs })
524 }
525 if (knowledgeFiles === undefined) {
526 if (projectFiles) {
527 knowledgeFiles = deriveKnowledgeFiles(projectFiles)
528 } else if (cwd && discoveredProject) {
529 knowledgeFiles = await loadKnowledgeFilesFromPaths({
530 cwd,
531 filePaths: discoveredProject.filePaths,
532 fs,
533 logger,
534 })
535 } else {
536 knowledgeFiles = {}
537 }
538 }

Calls 13

loadLocalAgentsFunction · 0.90
loadSkillsFunction · 0.90
getInitialSessionStateFunction · 0.90
getSystemInfoFunction · 0.90
discoverProjectPathsFunction · 0.85
deriveKnowledgeFilesFunction · 0.85
processAgentDefinitionsFunction · 0.85
getProjectIndexInputFunction · 0.85
computeProjectIndexFunction · 0.85
getGitChangesFunction · 0.85

Tested by 1

runOnceFunction · 0.72