MCPcopy Index your code
hub / github.com/Noumena-Network/code / processLine

Method processLine

src/cli/structuredIO.ts:334–462  ·  view source on GitHub ↗
(
    line: string,
  )

Source from the content-addressed store, hash-verified

332 }
333
334 private async processLine(
335 line: string,
336 ): Promise<StdinMessage | SDKMessage | undefined> {
337 // Skip empty lines (e.g. from double newlines in piped stdin)
338 if (!line) {
339 return undefined
340 }
341 try {
342 const message = normalizeControlMessageKeys(jsonParse(line)) as
343 | StdinMessage
344 | SDKMessage
345 if (message.type === 'keep_alive') {
346 // Silently ignore keep-alive messages
347 return undefined
348 }
349 if (message.type === 'update_environment_variables') {
350 // Apply environment variable updates directly to process.env.
351 // Used by bridge session runner for auth token refresh
352 // (CLAUDE_CODE_SESSION_ACCESS_TOKEN) which must be readable
353 // by the REPL process itself, not just child Bash commands.
354 const keys = Object.keys(message.variables)
355 for (const [key, value] of Object.entries(message.variables)) {
356 process.env[key] = value
357 }
358 logForDebugging(
359 `[structuredIO] applied update_environment_variables: ${keys.join(', ')}`,
360 )
361 return undefined
362 }
363 if (message.type === 'control_response') {
364 // Close lifecycle for every control_response, including duplicates
365 // and orphans — orphans don't yield to print.ts's main loop, so this
366 // is the only path that sees them. uuid is server-injected into the
367 // payload.
368 const uuid =
369 'uuid' in message && typeof message.uuid === 'string'
370 ? message.uuid
371 : undefined
372 if (uuid) {
373 notifyCommandLifecycle(uuid, 'completed')
374 }
375 const request = this.pendingRequests.get(message.response.request_id)
376 if (!request) {
377 // Check if this tool_use was already resolved through the normal
378 // permission flow. Duplicate control_response deliveries (e.g. from
379 // WebSocket reconnects) arrive after the original was handled, and
380 // re-processing them would push duplicate assistant messages into
381 // the conversation, causing API 400 errors.
382 const responsePayload =
383 message.response.subtype === 'success'
384 ? message.response.response
385 : undefined
386 const toolUseID = responsePayload?.toolUseID
387 if (
388 typeof toolUseID === 'string' &&
389 this.resolvedToolUseIds.has(toolUseID)
390 ) {
391 logForDebugging(

Callers 1

readMethod · 0.95

Calls 14

jsonParseFunction · 0.85
notifyCommandLifecycleFunction · 0.85
cliErrorFunction · 0.85
keysMethod · 0.80
entriesMethod · 0.80
deleteMethod · 0.80
rejectMethod · 0.80
resolveMethod · 0.80
logForDebuggingFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected