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

Function applyOverridesToSessionState

sdk/src/run-state.ts:690–768  ·  view source on GitHub ↗
(
  cwd: string | undefined,
  baseSessionState: SessionState,
  overrides: {
    projectFiles?: Record<string, string>
    knowledgeFiles?: Record<string, string>
    agentDefinitions?: AgentDefinition[]
    customToolDefinitions?: CustomToolDefinition[]
    maxAgentSteps?: number
  },
)

Source from the content-addressed store, hash-verified

688 * even when continuing from a previous run.
689 */
690export async function applyOverridesToSessionState(
691 cwd: string | undefined,
692 baseSessionState: SessionState,
693 overrides: {
694 projectFiles?: Record<string, string>
695 knowledgeFiles?: Record<string, string>
696 agentDefinitions?: AgentDefinition[]
697 customToolDefinitions?: CustomToolDefinition[]
698 maxAgentSteps?: number
699 },
700): Promise<SessionState> {
701 // Deep clone to avoid mutating the original session state
702 const sessionState = JSON.parse(
703 JSON.stringify(baseSessionState),
704 ) as SessionState
705
706 // Apply maxAgentSteps override
707 if (overrides.maxAgentSteps !== undefined) {
708 sessionState.mainAgentState.stepsRemaining = overrides.maxAgentSteps
709 }
710
711 // Apply projectFiles override (recomputes file tree and token scores)
712 if (overrides.projectFiles !== undefined) {
713 if (cwd) {
714 const projectIndex = getProjectIndexInput({
715 cwd,
716 projectFiles: overrides.projectFiles,
717 })
718 if (projectIndex) {
719 const { fileTree, fileTokenScores, tokenCallers } =
720 await computeProjectIndex(projectIndex)
721 sessionState.fileContext.fileTree = fileTree
722 sessionState.fileContext.fileTokenScores = fileTokenScores
723 sessionState.fileContext.tokenCallers = tokenCallers
724 }
725 } else {
726 // If projectFiles are provided but no cwd, reset file context fields
727 sessionState.fileContext.fileTree = []
728 sessionState.fileContext.fileTokenScores = {}
729 sessionState.fileContext.tokenCallers = {}
730 }
731
732 // Auto-derive knowledgeFiles if not explicitly provided
733 if (overrides.knowledgeFiles === undefined) {
734 sessionState.fileContext.knowledgeFiles = deriveKnowledgeFiles(
735 overrides.projectFiles,
736 )
737 }
738 }
739
740 // Apply knowledgeFiles override
741 if (overrides.knowledgeFiles !== undefined) {
742 sessionState.fileContext.knowledgeFiles = overrides.knowledgeFiles
743 }
744
745 // Apply agentDefinitions override (merge by id, last-in wins)
746 if (overrides.agentDefinitions !== undefined) {
747 const processedAgentTemplates = processAgentDefinitions(

Callers 1

runOnceFunction · 0.90

Calls 6

getProjectIndexInputFunction · 0.85
computeProjectIndexFunction · 0.85
deriveKnowledgeFilesFunction · 0.85
processAgentDefinitionsFunction · 0.85
parseMethod · 0.80

Tested by

no test coverage detected