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

Function runOnce

sdk/src/run.ts:193–577  ·  view source on GitHub ↗
({
  apiKey,
  fingerprintId,

  cwd,
  skillsDir,
  projectFiles,
  knowledgeFiles,
  agentDefinitions,
  maxAgentSteps = MAX_AGENT_STEPS_DEFAULT,
  env,

  handleEvent,
  handleStreamChunk,

  fileFilter,
  overrideTools,
  customToolDefinitions,

  fsSource = () => require('fs').promises,
  spawnSource,
  logger,

  agent,
  prompt,
  content,
  params,
  previousRun,
  extraToolResults,
  signal,
  costMode,
  extraCodebuffMetadata,
}: RunExecutionOptions)

Source from the content-addressed store, hash-verified

191}
192
193async function runOnce({
194 apiKey,
195 fingerprintId,
196
197 cwd,
198 skillsDir,
199 projectFiles,
200 knowledgeFiles,
201 agentDefinitions,
202 maxAgentSteps = MAX_AGENT_STEPS_DEFAULT,
203 env,
204
205 handleEvent,
206 handleStreamChunk,
207
208 fileFilter,
209 overrideTools,
210 customToolDefinitions,
211
212 fsSource = () => require('fs').promises,
213 spawnSource,
214 logger,
215
216 agent,
217 prompt,
218 content,
219 params,
220 previousRun,
221 extraToolResults,
222 signal,
223 costMode,
224 extraCodebuffMetadata,
225}: RunExecutionOptions): Promise<RunState> {
226 const fsSourceValue = typeof fsSource === 'function' ? fsSource() : fsSource
227 const fs = await fsSourceValue
228 let spawn: CodebuffSpawn
229 if (spawnSource) {
230 const spawnSourceValue = await spawnSource
231 spawn = spawnSourceValue as CodebuffSpawn
232 } else {
233 spawn = require('child_process').spawn as CodebuffSpawn
234 }
235 const preparedContent = wrapContentForUserMessage(content)
236
237 // Init session state
238 let agentId
239 if (typeof agent !== 'string') {
240 const clonedDefs = agentDefinitions ? cloneDeep(agentDefinitions) : []
241 agentDefinitions = [...clonedDefs, agent]
242 agentId = agent.id
243 } else {
244 agentId = agent
245 }
246 let sessionState: SessionState
247 if (previousRun?.sessionState) {
248 // applyOverridesToSessionState handles deep cloning and applying any provided overrides
249 sessionState = await applyOverridesToSessionState(
250 cwd,

Callers 1

runFunction · 0.70

Calls 15

initialSessionStateFunction · 0.90
getAgentRuntimeImplFunction · 0.90
getMCPClientFunction · 0.90
listMCPToolsFunction · 0.90
getProjectPathLookupKeysFunction · 0.90
toOptionalFileFunction · 0.90
getUserInfoFromApiKeyFunction · 0.90
callMainPromptFunction · 0.90
extractApiErrorDetailsFunction · 0.90
getErrorStatusCodeFunction · 0.90

Tested by

no test coverage detected