Welcome to the final chapter of the PromptInput tutorial!
In the previous chapter, Notification & Feedback System, we learned how the system sends messages to the user. Now, we will focus on the messages the user is about to send to the system.
Imagine you are a manager assigning tasks to an employee. You write down 10 sticky notes and hand them over in a stack.
In an AI Agent terminal, things happen fast. Agents often generate their own sub-tasks, or you might paste a script that queues up 50 commands at once. If you can't see this queue, you are flying blind.
The Command Queue Preview acts like an email Outbox or a shopping cart. It sits above your input line and visualizes everything that is waiting to be executed.
!ls), or a task update. We need to format them so they all look like readable messages.Before rendering, the component has to clean up the raw data.
The logic for this feature is contained in PromptInputQueuedCommands.tsx. It acts as a gatekeeper between the raw data and the screen.
Not everything in the queue is meant for humans. Some items are "Idle Notifications" (internal system pings). We filter these out so the user only sees actionable items.
// Inside processQueuedCommands function
function processQueuedCommands(queuedCommands) {
// Remove items that are just internal system noise
const filteredCommands = queuedCommands.filter(cmd =>
typeof cmd.value !== 'string' ||
!isIdleNotification(cmd.value)
);
return filteredCommands;
}
Explanation: We look at every command. If isIdleNotification returns true, we throw it away. This keeps the UI clean.
If an agent generates 50 task notifications in one second, we don't want to scroll the user's chat history off the screen. We enforce a limit (e.g., 3 lines).
// Define the limit
const MAX_VISIBLE_NOTIFICATIONS = 3;
// Check if we have too many
if (taskNotifications.length > MAX_VISIBLE_NOTIFICATIONS) {
// Keep the first few
const visible = taskNotifications.slice(0, MAX_VISIBLE_NOTIFICATIONS - 1);
// Calculate how many are hidden
const overflowCount = taskNotifications.length - visible.length;
}
Explanation: We slice the array to get just the top items. We then do simple math to figure out how many items are being hidden.
If we hid items in Step 2, we need to generate a fake message that represents them. We use XML tags to style this message so it looks like a system summary.
// Creating the summary string
function createOverflowNotificationMessage(count: number) {
return `
<task-notification>
<summary>+${count} more tasks completed</summary>
<status>completed</status>
</task-notification>
`;
}
Explanation: We inject a formatted string into the queue. The rendering engine will see <summary> and know to draw it as a collapsed box, rather than a full chat message.
Finally, we map these processed commands to the screen. We use the same Message component used for the main chat, but with a special flag.
// Inside the Component Return
return (
<Box flexDirection="column">
{messages.map((msg, i) => (
<QueuedMessageProvider key={i} isFirst={i === 0}>
<Message
message={msg}
isStatic={true} // Important!
/>
</QueuedMessageProvider>
))}
</Box>
);
Explanation:
QueuedMessageProvider: Wraps the message to give it "Draft" styling (usually slightly transparent or dimmed).isStatic={true}: This tells the Message component, "Don't animate this text. Don't type it out character-by-character. Just show it immediately."There is one scenario where we hide the queue entirely.
If you are "Zoomed In" on a specific sub-agent (using the Identity Context from Chapter 3), you shouldn't see the Main Coordinator's queue. It would be confusing to see commands that don't belong to the agent you are watching.
const viewingAgent = useAppState(s => !!s.viewingAgentTaskId);
// If we are looking at a specific agent's history, hide the global queue
if (viewingAgent) {
return null;
}
Explanation: This follows the "Return Null" pattern. If the context isn't right, the component renders nothing, effectively disappearing from the DOM.
The Command Queue Preview is the final safety check in the interface.
By combining all the chapters:
You have now completed the PromptInput tutorial series! You have the knowledge to build a robust, user-friendly terminal interface for complex AI agents.
Generated by Code IQ