MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / processLine

Method processLine

source code/cli/structuredIO.ts:335–465  ·  view source on GitHub ↗
(
    line: string,
  )

Source from the content-addressed store, hash-verified

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

Callers 1

readMethod · 0.95

Calls 14

jsonParseFunction · 0.85
logForDebuggingFunction · 0.85
notifyCommandLifecycleFunction · 0.85
keysMethod · 0.80
entriesMethod · 0.80
deleteMethod · 0.80
rejectMethod · 0.80
resolveMethod · 0.80
exitWithMessageFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected