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

Function processQueueIfReady

source code/utils/queueProcessor.ts:54–89  ·  view source on GitHub ↗
({
  executeInput,
}: ProcessQueueParams)

Source from the content-addressed store, hash-verified

52 * @returns result with processed status
53 */
54export function processQueueIfReady({
55 executeInput,
56}: ProcessQueueParams): ProcessQueueResult {
57 // This processor runs on the REPL main thread between turns. Skip anything
58 // addressed to a subagent — an unfiltered peek() returning a subagent
59 // notification would set targetMode, dequeueAllMatching would find nothing
60 // matching that mode with agentId===undefined, and we'd return processed:
61 // false with the queue unchanged → the React effect never re-fires and any
62 // queued user prompt stalls permanently.
63 const isMainThread = (cmd: QueuedCommand) => cmd.agentId === undefined
64
65 const next = peek(isMainThread)
66 if (!next) {
67 return { processed: false }
68 }
69
70 // Slash commands and bash-mode commands are processed individually.
71 // Bash commands need per-command error isolation, exit codes, and progress UI.
72 if (isSlashCommand(next) || next.mode === 'bash') {
73 const cmd = dequeue(isMainThread)!
74 void executeInput([cmd])
75 return { processed: true }
76 }
77
78 // Drain all non-slash-command items with the same mode at once.
79 const targetMode = next.mode
80 const commands = dequeueAllMatching(
81 cmd => isMainThread(cmd) && !isSlashCommand(cmd) && cmd.mode === targetMode,
82 )
83 if (commands.length === 0) {
84 return { processed: false }
85 }
86
87 void executeInput(commands)
88 return { processed: true }
89}
90
91/**
92 * Checks if the queue has pending commands.

Callers 1

useQueueProcessorFunction · 0.85

Calls 5

dequeueFunction · 0.85
dequeueAllMatchingFunction · 0.85
isSlashCommandFunction · 0.70
isMainThreadFunction · 0.70
peekFunction · 0.50

Tested by

no test coverage detected