Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion box-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
38 changes: 33 additions & 5 deletions dashboard/src/components/assistant-ui/elements/thread.aui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
type ImageMessagePartComponent,
type ToolCallMessagePartComponent,
unstable_useComposerInputHistory,
useAui,
useAuiEvent,
useAuiState,
} from "@assistant-ui/react";
Expand All @@ -69,6 +70,7 @@ import {
useState,
type ComponentType,
type FC,
type KeyboardEvent,
type PropsWithChildren,
type ReactNode,
} from "react";
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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<ThreadProps> = ({
components = EMPTY_COMPONENTS,
autoFocus = true,
aboveComposer,
aboveMessages,
promptSuggestion,
}) => {
const isEmpty = useAuiState(isNewChatView);

Expand All @@ -195,6 +204,7 @@ export const Thread: FC<ThreadProps> = ({
autoFocus={autoFocus}
aboveComposer={aboveComposer}
aboveMessages={aboveMessages}
promptSuggestion={promptSuggestion ?? null}
/>
</ThreadComponentsContext.Provider>
);
Expand All @@ -207,6 +217,7 @@ export const Thread: FC<ThreadProps> = ({
* @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. */
Expand All @@ -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.
Expand Down Expand Up @@ -285,7 +298,7 @@ const ThreadRoot: FC<{
<ThreadFollowupSuggestions />
{/* Boxes edit: the last thing read before typing. */}
{aboveComposer}
<Composer autoFocus={autoFocus} />
<Composer autoFocus={autoFocus} suggestion={promptSuggestion} />
<AuiIf condition={(s) => isNewChatView(s) && s.composer.isEmpty}>
<ThreadSuggestions />
</AuiIf>
Expand Down Expand Up @@ -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<HTMLTextAreaElement>(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<HTMLTextAreaElement>) => {
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.
Expand All @@ -457,7 +485,7 @@ const Composer: FC<{
<ComposerAttachments />
<ComposerPrimitive.Input
ref={inputRef}
placeholder="Send a message..."
placeholder={suggestion ? `${suggestion} (Tab)` : "Send a message..."}
className="aui-composer-input caret-primary placeholder:text-muted-foreground/60 max-h-48 min-h-10 w-full resize-none bg-transparent px-2.5 py-1 text-base leading-6 outline-none"
rows={1}
autoFocus={autoFocus}
Expand All @@ -467,7 +495,7 @@ const Composer: FC<{
submitMode="ctrlEnter"
enterKeyHint="enter"
aria-label="Message input"
onKeyDown={history.onKeyDown}
onKeyDown={onKeyDown}
/>
<ComposerAction />
</div>
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/stores/thread/acp-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown> | null }
// Forward compatibility, because an adapter can send a kind that is newer than this build.
| { sessionUpdate: string; [key: string]: unknown };

Expand Down
12 changes: 12 additions & 0 deletions dashboard/src/stores/thread/thread-store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
12 changes: 10 additions & 2 deletions dashboard/src/stores/thread/thread-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/**
Expand Down Expand Up @@ -94,6 +96,7 @@ export const INITIAL_SNAPSHOT: ThreadSnapshot = {
configOptions: [],
plan: null,
commands: [],
promptSuggestion: null,
error: null,
loading: true,
truncated: false,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
36 changes: 36 additions & 0 deletions dashboard/src/stores/thread/translate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
35 changes: 35 additions & 0 deletions dashboard/src/stores/thread/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -180,6 +182,7 @@ export function emptyModel(): ThreadModel {
configOptions: [],
plan: null,
commands: [],
promptSuggestion: null,
unknown: new Set(),
tools: new Map(),
};
Expand Down Expand Up @@ -369,6 +372,8 @@ export function applyUpdate(model: ThreadModel, update: ThreadUpdate): Message |
switch (update.sessionUpdate) {
case UPDATE_KIND.userMessageChunk: {
const u = update as UpdateOf<typeof UPDATE_KIND.userMessageChunk>;
// 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;
Expand Down Expand Up @@ -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<typeof UPDATE_KIND.sessionInfo>;
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<string, unknown> | 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.
Expand Down
2 changes: 2 additions & 0 deletions dashboard/src/views/BoxThread.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ export function BoxThread() {
<ThreadLoading />
) : (
<Thread
// A suggestion is for the next prompt, so a running turn shows none.
promptSuggestion={state.isRunning ? null : state.promptSuggestion}
aboveMessages={
state.truncated ? (
<FullHistoryButton
Expand Down
4 changes: 4 additions & 0 deletions doc/threads.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ are uploaded to the box's workspace when the prompt is sent; the agent receives
While the agent works, a stop button replaces the send button. It cancels the turn. A command the turn left running in
the background is not cancelled by this; see "Background work" below.

After a turn, Claude Code can predict the next prompt. The empty text area then shows that prompt in gray. Tab writes it
into the text area without sending it. Claude Code sends no prediction for the first turn of a thread and in the plan
mode.

### Slash commands

Type `/` at the start of the text area to list the slash commands the agent's adapter accepts. The list filters as you
Expand Down
Loading