diff --git a/box-image/Dockerfile b/box-image/Dockerfile index 59f33082..d578c0bb 100644 --- a/box-image/Dockerfile +++ b/box-image/Dockerfile @@ -154,7 +154,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends libicu78 \ # /usr/local. RUN npm install -g --prefix /usr/local \ @anthropic-ai/claude-code@^2 \ - @agentclientprotocol/claude-agent-acp@^0.81.0 \ + @agentclientprotocol/claude-agent-acp@^0.92.0 \ && npm cache clean --force # The Codex CLI and its ACP adapter, both pinned exactly. diff --git a/dashboard/src/components/assistant-ui/elements/thread.aui.tsx b/dashboard/src/components/assistant-ui/elements/thread.aui.tsx index 387dbd0d..284fd59e 100644 --- a/dashboard/src/components/assistant-ui/elements/thread.aui.tsx +++ b/dashboard/src/components/assistant-ui/elements/thread.aui.tsx @@ -47,6 +47,7 @@ import { type ImageMessagePartComponent, type ToolCallMessagePartComponent, unstable_useComposerInputHistory, + useAui, useAuiEvent, useAuiState, } from "@assistant-ui/react"; @@ -69,6 +70,7 @@ import { useState, type ComponentType, type FC, + type KeyboardEvent, type PropsWithChildren, type ReactNode, } from "react"; @@ -115,6 +117,11 @@ export type ThreadProps = { * that loads the older messages of a cut thread. */ aboveMessages?: ReactNode | undefined; + /** + * Boxes edit: the prompt that the agent expects the user to send next. The + * composer offers it in an empty draft. + */ + promptSuggestion?: string | null | undefined; }; /** The overrides when the caller gives none. */ @@ -179,12 +186,14 @@ const ThreadHistorySkeleton: FC = () => ( * @param autoFocus True to focus the composer on mount. * @param aboveComposer Boxes edit: content shown directly above the composer. * @param aboveMessages Boxes edit: content shown above the first message. + * @param promptSuggestion Boxes edit: the prompt that the agent expects next. */ export const Thread: FC = ({ components = EMPTY_COMPONENTS, autoFocus = true, aboveComposer, aboveMessages, + promptSuggestion, }) => { const isEmpty = useAuiState(isNewChatView); @@ -195,6 +204,7 @@ export const Thread: FC = ({ autoFocus={autoFocus} aboveComposer={aboveComposer} aboveMessages={aboveMessages} + promptSuggestion={promptSuggestion ?? null} /> ); @@ -207,6 +217,7 @@ export const Thread: FC = ({ * @param autoFocus True to focus the composer on mount. * @param aboveComposer Content shown directly above the composer. * @param aboveMessages Content shown above the first message. + * @param promptSuggestion The prompt that the agent expects next, or null. */ const ThreadRoot: FC<{ /** True while the thread shows as a new chat. */ @@ -217,7 +228,9 @@ const ThreadRoot: FC<{ aboveComposer?: ReactNode | undefined; /** Content shown above the first message. */ aboveMessages?: ReactNode | undefined; -}> = ({ isEmpty, autoFocus, aboveComposer, aboveMessages }) => { + /** The prompt that the agent expects next, or null. */ + promptSuggestion: string | null; +}> = ({ isEmpty, autoFocus, aboveComposer, aboveMessages, promptSuggestion }) => { const { Welcome = ThreadWelcome } = useContext(ThreadComponentsContext); // Boxes edit: keeps the newest output in view once a turn outgrows the // screen. The turn anchor alone holds the prompt at the top and follows nothing. @@ -285,7 +298,7 @@ const ThreadRoot: FC<{ {/* Boxes edit: the last thing read before typing. */} {aboveComposer} - + isNewChatView(s) && s.composer.isEmpty}> @@ -424,15 +437,30 @@ const ThreadSuggestionItem: FC = () => { * The message composer, with attachments and the slash-command list. * * @param autoFocus True to focus the input on mount. + * @param suggestion The prompt that the agent expects next, or null. */ const Composer: FC<{ /** True to focus the input on mount. */ autoFocus: boolean; -}> = ({ autoFocus }) => { + /** Boxes edit: the prompt that the agent expects next, or null. */ + suggestion: string | null; +}> = ({ autoFocus, suggestion }) => { // Boxes edit: ArrowUp on an empty draft walks back through sent messages, // and ArrowDown returns to the draft. const history = unstable_useComposerInputHistory(); const inputRef = useRef(null); + const aui = useAui(); + + // Boxes edit: the agent's predicted next prompt shows as the placeholder of + // an empty draft, and Tab takes it into the draft without sending it. + const onKeyDown = (e: KeyboardEvent) => { + history.onKeyDown(e); + if (e.defaultPrevented || e.key !== "Tab" || !suggestion) return; + if (e.shiftKey || e.ctrlKey || e.metaKey || e.altKey || e.nativeEvent.isComposing) return; + if (e.currentTarget.value !== "") return; + e.preventDefault(); + aui.composer.setText(suggestion); + }; // Boxes edit: keeps the caret in the composer after a send, so the next // prompt needs no tap. @@ -457,7 +485,7 @@ const Composer: FC<{ diff --git a/dashboard/src/stores/thread/acp-types.ts b/dashboard/src/stores/thread/acp-types.ts index 27acc96e..e6781489 100644 --- a/dashboard/src/stores/thread/acp-types.ts +++ b/dashboard/src/stores/thread/acp-types.ts @@ -160,6 +160,7 @@ export type ThreadUpdate = | { sessionUpdate: typeof UPDATE_KIND.currentMode; currentModeId: string } | { sessionUpdate: typeof UPDATE_KIND.availableCommands; availableCommands?: AvailableCommand[] } | { sessionUpdate: typeof UPDATE_KIND.configOption; configOptions?: ThreadConfigOption[] } + | { sessionUpdate: typeof UPDATE_KIND.sessionInfo; _meta?: Record | null } // Forward compatibility, because an adapter can send a kind that is newer than this build. | { sessionUpdate: string; [key: string]: unknown }; diff --git a/dashboard/src/stores/thread/thread-store.test.ts b/dashboard/src/stores/thread/thread-store.test.ts index c91aee7c..f5ad61ef 100644 --- a/dashboard/src/stores/thread/thread-store.test.ts +++ b/dashboard/src/stores/thread/thread-store.test.ts @@ -1040,3 +1040,15 @@ test('a refused full history leaves the thread as it was', async () => { assert.equal(snapshot.loadingHistory, false); assert.equal(snapshot.error, 'The agent is working on this thread.'); }); + +test('the store publishes the predicted next prompt and a send clears it', async () => { + const { store, client } = makeStore(); + push(client, { + sessionUpdate: 'session_info_update', + _meta: { promptSuggestions: { suggestions: [{ text: 'run the tests' }] } }, + } as ThreadUpdate); + assert.equal(store.getSnapshot().promptSuggestion, 'run the tests'); + + await store.send([{ type: 'text', text: 'deploy it' }]); + assert.equal(store.getSnapshot().promptSuggestion, null); +}); diff --git a/dashboard/src/stores/thread/thread-store.ts b/dashboard/src/stores/thread/thread-store.ts index b64807ce..ab6573f0 100644 --- a/dashboard/src/stores/thread/thread-store.ts +++ b/dashboard/src/stores/thread/thread-store.ts @@ -61,6 +61,8 @@ export interface ThreadSnapshot { plan: PlanEntry[] | null; /** The slash commands the adapter accepts, for the composer to complete. */ commands: AvailableCommand[]; + /** The prompt that the agent expects the user to send next, or null. */ + promptSuggestion: string | null; /** The last send or connection error, or null. */ error: string | null; /** @@ -94,6 +96,7 @@ export const INITIAL_SNAPSHOT: ThreadSnapshot = { configOptions: [], plan: null, commands: [], + promptSuggestion: null, error: null, loading: true, truncated: false, @@ -413,6 +416,7 @@ export class ThreadStore { messages: this.messageViews(null), plan: this.model.plan, commands: this.model.commands, + promptSuggestion: this.model.promptSuggestion, loading: false, truncated: this.truncated, rebuilds: this.rebuilds, @@ -463,13 +467,15 @@ export class ThreadStore { this.snapshot.modes !== this.model.modes || this.snapshot.configOptions !== this.model.configOptions || this.snapshot.plan !== this.model.plan || - this.snapshot.commands !== this.model.commands + this.snapshot.commands !== this.model.commands || + this.snapshot.promptSuggestion !== this.model.promptSuggestion ) { this.emit({ modes: this.model.modes, configOptions: this.model.configOptions, plan: this.model.plan, commands: this.model.commands, + promptSuggestion: this.model.promptSuggestion, }); } this.refreshMessages(touched); @@ -558,7 +564,9 @@ export class ThreadStore { if (!sessionId) throw new Error('no ACP thread yet'); if (blocks.length === 0) return; - this.emit({ error: null }); + // The prompt answers the suggestion, so the composer stops showing it. + this.model.promptSuggestion = null; + this.emit({ error: null, promptSuggestion: null }); try { await client.request(ACP_METHOD.sessionPrompt, { sessionId, diff --git a/dashboard/src/stores/thread/translate.test.ts b/dashboard/src/stores/thread/translate.test.ts index e184381f..665fc4af 100644 --- a/dashboard/src/stores/thread/translate.test.ts +++ b/dashboard/src/stores/thread/translate.test.ts @@ -521,3 +521,39 @@ test('a truncated model plus the rest is the model the whole thread builds', () // A reconnect can take the tail alone, because the result is the same. assert.deepEqual(resumed.messages, whole.messages); }); + +/** + * Builds a session_info_update that carries a predicted next prompt. + * + * @param texts The texts of the suggestions. + * @returns The update. + */ +function suggest(...texts: string[]): ThreadUpdate { + return { + sessionUpdate: 'session_info_update', + _meta: { promptSuggestions: { suggestions: texts.map((text) => ({ text })) } }, + } as ThreadUpdate; +} + +test('a session info update sets the predicted next prompt', () => { + const model = fold(chunk('agent_message_chunk', 'Done.'), suggest(' ', 'run the tests ')); + assert.equal(model.promptSuggestion, 'run the tests'); + assert.equal(model.unknown.size, 0); +}); + +test('an empty suggestion list clears the predicted prompt', () => { + assert.equal(fold(suggest('run the tests'), suggest()).promptSuggestion, null); +}); + +test('a session info update without a suggestion keeps the predicted prompt', () => { + const model = fold(suggest('run the tests'), { + sessionUpdate: 'session_info_update', + title: 'A title', + } as ThreadUpdate); + assert.equal(model.promptSuggestion, 'run the tests'); +}); + +test('a user message clears the predicted prompt', () => { + const model = fold(suggest('run the tests'), chunk('user_message_chunk', 'deploy it')); + assert.equal(model.promptSuggestion, null); +}); diff --git a/dashboard/src/stores/thread/translate.ts b/dashboard/src/stores/thread/translate.ts index 901d793b..e25843c0 100644 --- a/dashboard/src/stores/thread/translate.ts +++ b/dashboard/src/stores/thread/translate.ts @@ -152,6 +152,8 @@ export interface ThreadModel { plan: PlanEntry[] | null; /** The slash commands the adapter accepts, for the composer to complete. */ commands: AvailableCommand[]; + /** The prompt that the agent expects the user to send next, or null. */ + promptSuggestion: string | null; /** * Kinds of update this build does not know, by name. * @@ -180,6 +182,7 @@ export function emptyModel(): ThreadModel { configOptions: [], plan: null, commands: [], + promptSuggestion: null, unknown: new Set(), tools: new Map(), }; @@ -369,6 +372,8 @@ export function applyUpdate(model: ThreadModel, update: ThreadUpdate): Message | switch (update.sessionUpdate) { case UPDATE_KIND.userMessageChunk: { const u = update as UpdateOf; + // The user has answered, so the suggestion for this answer is old. + model.promptSuggestion = null; const message = messageFor(model, 'user', u.messageId); appendBlock(message, 'text', u.content); return message; @@ -420,12 +425,42 @@ export function applyUpdate(model: ThreadModel, update: ThreadUpdate): Message | if (model.modes) model.modes = { ...model.modes, currentModeId: u.currentModeId }; return null; } + case UPDATE_KIND.sessionInfo: { + const u = update as UpdateOf; + const suggestion = promptSuggestionOf(u._meta); + if (suggestion !== undefined) model.promptSuggestion = suggestion; + return null; + } default: model.unknown.add(update.sessionUpdate); return null; } } +/** The `_meta` key under which `claude-agent-acp` sends the predicted next prompt. */ +export const PROMPT_SUGGESTIONS_META_KEY = 'promptSuggestions'; + +/** + * Reads the predicted next prompt from the `_meta` of a session_info_update. + * + * The value is `{ suggestions: [{ text }] }`. An empty list clears the prediction. + * + * @param meta The `_meta` of the update. + * @returns The first text that is not blank, null when the update clears the prediction, or undefined when the + * update says nothing about it. + */ +function promptSuggestionOf( + meta: Record | null | undefined, +): string | null | undefined { + const value = meta?.[PROMPT_SUGGESTIONS_META_KEY] as { suggestions?: unknown } | undefined; + if (!value || !Array.isArray(value.suggestions)) return undefined; + for (const entry of value.suggestions) { + const text = (entry as { text?: unknown } | null)?.text; + if (typeof text === 'string' && text.trim()) return text.trim(); + } + return null; +} + /** * Folds a tool_call or a tool_call_update into the thread. The update merges * into its call, or starts a new card when the call does not exist yet. diff --git a/dashboard/src/views/BoxThread.tsx b/dashboard/src/views/BoxThread.tsx index c84804ac..d502c06c 100644 --- a/dashboard/src/views/BoxThread.tsx +++ b/dashboard/src/views/BoxThread.tsx @@ -377,6 +377,8 @@ export function BoxThread() { ) : (