Input flow
PromptInput local submit
validate visible state and suggestion state
route direct member message or leader submit
handlePromptSubmit
execute local JSX commands immediately when possible
queue input if model or external loading is active
reserve query guard
process queued commands in order
processUserInput
normalize content
load files and images
run slash command or bash path
produce user message and shouldQuery flag
REPL.onQueryImpl
build tool context
collect prompt context
call query()
PromptInput is the first gate
PromptInput is a UI component, but its submit handler already has workflow responsibilities. It trims input, checks whether a footer or selection state should intercept the action, accepts prompt suggestions, handles direct member messages, blocks empty input, and routes either to an active agent or the leader submit handler.
The submit handler owns queue safety
handlePromptSubmit turns raw input into controlled work. It validates exit commands and pasted text, runs local JSX slash commands while a query is active, queues normal input if the model is already busy, and reserves the query guard before the main processing loop starts.
The important design is that direct input is converted into a QueuedCommand. That means typed prompts and command-triggered prompts share the same execution path and preserve order.
Queue processor drains when safe
useQueueProcessor subscribes to the external query guard and command queue. It drains queued work only when the app is not already querying and there is no local JSX command UI blocking progress.
This keeps queued prompts from interleaving with unfinished tool results or permission screens.
Code reference: queue processor subscription and drain condition
processUserInput normalizes the request
The processor accepts strings and content blocks, resizes image inputs, loads file attachments, respects bridge-safe slash command overrides, and dispatches to bash, slash command, or text prompt handling.
Regular text goes to processTextPrompt, which creates a user message, includes images and attachments, and returns shouldQuery: true. Slash commands can be local, local JSX, or prompt-based commands that load prompt text, allowed tools, attachments, and command permissions.
REPL builds fresh execution context
When onQueryImpl runs, the REPL computes tools from current state, not stale props. It assembles the tool pool, merges and filters tools, resolves agent tools, and builds ToolUseContext with current MCP clients, resources, permissions, app state accessors, UI callbacks, and file read state.
Then it gathers diagnostics, title state, allowed-tool overrides, user context, system context, and command-generated settings before calling query(...). Returned events are passed to onQueryEvent, then the REPL resets per-turn state and runs onTurnComplete.