MCPcopy Create free account
hub / github.com/Noumena-Network/code / handleInitializeRequest

Function handleInitializeRequest

src/cli/print.ts:4370–4552  ·  view source on GitHub ↗
(
  request: SDKControlInitializeRequest,
  requestId: string,
  initialized: boolean,
  output: Stream<StdoutMessage>,
  commands: Command[],
  modelInfos: ModelInfo[],
  structuredIO: StructuredIO,
  enableAuthStatus: boolean,
  options: {
    systemPrompt: string | undefined
    appendSystemPrompt: string | undefined
    agent?: string | undefined
    userSpecifiedModel?: string | undefined
    [key: string]: unknown
  },
  agents: AgentDefinition[],
  getAppState: () => AppState,
)

Source from the content-addressed store, hash-verified

4368}
4369
4370async function handleInitializeRequest(
4371 request: SDKControlInitializeRequest,
4372 requestId: string,
4373 initialized: boolean,
4374 output: Stream<StdoutMessage>,
4375 commands: Command[],
4376 modelInfos: ModelInfo[],
4377 structuredIO: StructuredIO,
4378 enableAuthStatus: boolean,
4379 options: {
4380 systemPrompt: string | undefined
4381 appendSystemPrompt: string | undefined
4382 agent?: string | undefined
4383 userSpecifiedModel?: string | undefined
4384 [key: string]: unknown
4385 },
4386 agents: AgentDefinition[],
4387 getAppState: () => AppState,
4388): Promise<void> {
4389 if (initialized) {
4390 output.enqueue({
4391 type: 'control_response',
4392 response: {
4393 subtype: 'error',
4394 error: 'Already initialized',
4395 request_id: requestId,
4396 pending_permission_requests:
4397 structuredIO.getPendingPermissionRequests(),
4398 },
4399 })
4400 return
4401 }
4402
4403 // Apply systemPrompt/appendSystemPrompt from stdin to avoid ARG_MAX limits
4404 if (request.systemPrompt !== undefined) {
4405 options.systemPrompt = request.systemPrompt
4406 }
4407 if (request.appendSystemPrompt !== undefined) {
4408 options.appendSystemPrompt = request.appendSystemPrompt
4409 }
4410 if (request.promptSuggestions !== undefined) {
4411 options.promptSuggestions = request.promptSuggestions
4412 }
4413
4414 // Merge agents from stdin to avoid ARG_MAX limits
4415 if (request.agents) {
4416 const stdinAgents = parseAgentsFromJson(request.agents, 'flagSettings')
4417 agents.push(...stdinAgents)
4418 }
4419
4420 // Re-evaluate main thread agent after SDK agents are merged
4421 // This allows --agent to reference agents defined via SDK
4422 if (options.agent) {
4423 // If main.tsx already found this agent (filesystem-defined), it already
4424 // applied systemPrompt/model/initialPrompt. Skip to avoid double-apply.
4425 const alreadyResolved = getMainThreadAgentType() === options.agent
4426 const mainThreadAgent = agents.find(a => a.agentType === options.agent)
4427 if (mainThreadAgent && !alreadyResolved) {

Callers 1

runHeadlessStreamingFunction · 0.85

Calls 15

randomUUIDFunction · 0.90
parseAgentsFromJsonFunction · 0.85
getMainThreadAgentTypeFunction · 0.85
setMainThreadAgentTypeFunction · 0.85
isBuiltInAgentFunction · 0.85
parseUserSpecifiedModelFunction · 0.85
setMainLoopModelOverrideFunction · 0.85
getCwdFunction · 0.85
getCurrentSdkAccountInfoFunction · 0.85
registerHookCallbacksFunction · 0.85
setInitJsonSchemaFunction · 0.85

Tested by

no test coverage detected