Skip to content
Merged
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
29 changes: 11 additions & 18 deletions box-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
# only after it names it again with a bare ARG.
ARG NODE_MAJOR=26
ARG NIX_VERSION=2.34.8
ARG CODEX_VERSION=0.156.1
ARG OPENCODE_VERSION=1.19.3
ARG CODEX_VERSION=0.169.0
ARG OPENCODE_VERSION=2.3.0

# The agent's own account, and the defaults of the orchestrator's BOX_UID and
# BOX_GID. 1020 keeps clear of the ubuntu user at 1000, which is often a
Expand Down Expand Up @@ -157,7 +157,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.108.0 \
&& npm cache clean --force

# The Codex CLI and its ACP adapter, both pinned exactly.
Expand All @@ -170,7 +170,7 @@ RUN npm install -g --prefix /usr/local \
ARG CODEX_VERSION
RUN npm install -g --prefix /usr/local @openai/codex@${CODEX_VERSION} \
&& npm install -g --prefix /usr/local --omit=optional \
@agentclientprotocol/codex-acp@1.13.0 \
@agentclientprotocol/codex-acp@2.7.0 \
&& npm cache clean --force
ENV CODEX_PATH=/usr/local/bin/codex

Expand All @@ -179,17 +179,11 @@ COPY box-image/codex-config.toml /etc/codex/config.toml

# opencode, pinned exactly. It is its own ACP adapter.
#
# The postinstall script of opencode-ai selects the platform binary by the CPU
# of the build host. The install skips the script. The start script selects
# the binary by the CPU of the host that runs the box.
#
# opencode installs @opencode-ai/plugin in its own version into
# ~/.config/opencode at its start, when the folder has no node_modules. The
# home seed holds that install, so a new box does not download it.
# The postinstall script of @opencode/cli selects the platform binary by the
# CPU of the build host. The install skips the script. The start script
# selects the binary by the CPU of the host that runs the box.
ARG OPENCODE_VERSION
RUN npm install -g --prefix /usr/local --ignore-scripts opencode-ai@${OPENCODE_VERSION} \
&& npm install --prefix /usr/local/share/boxes/home/.config/opencode --ignore-scripts --save-exact \
@opencode-ai/plugin@${OPENCODE_VERSION} \
RUN npm install -g --prefix /usr/local --ignore-scripts @opencode/cli@${OPENCODE_VERSION} \
&& npm cache clean --force
COPY box-image/opencode.sh /usr/local/bin/opencode
RUN chmod 0755 /usr/local/bin/opencode
Expand Down Expand Up @@ -328,11 +322,10 @@ RUN test "$(id -u)" = "${AGENT_UID}" \
&& test "$(command -v codex)" = "/usr/local/bin/codex" \
&& codex --version | grep -qF "${CODEX_VERSION}" \
&& test "$(command -v opencode)" = "/usr/local/bin/opencode" \
&& opencode --version | grep -qxF "${OPENCODE_VERSION}" \
&& opencode --version | grep -qxF "opencode v${OPENCODE_VERSION}" \
&& { test "$(dpkg --print-architecture)" != amd64 \
|| /usr/local/lib/node_modules/opencode-ai/node_modules/opencode-linux-x64-baseline/bin/opencode \
--version | grep -qxF "${OPENCODE_VERSION}"; } \
&& test -f /home/agent/.config/opencode/node_modules/@opencode-ai/plugin/package.json \
|| /usr/local/lib/node_modules/@opencode/cli/node_modules/@opencode/cli-linux-x64-baseline/bin/opencode \
--version | grep -qxF "opencode v${OPENCODE_VERSION}"; } \
&& test "$(command -v boxes-files)" = "/usr/local/bin/boxes-files" \
&& boxes-files </dev/null \
&& test -d /usr/local/share/boxes/skills \
Expand Down
3 changes: 0 additions & 3 deletions box-image/codex-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
# in every thread.
model_provider = "openai-https"

# No attribution trailer naming Codex in the commits an agent makes.
commit_attribution = ""

# Codex recognises its own provider by this name. No base URL is set, so the
# login decides the endpoint. The endpoint is api.openai.com for an API key and
# chatgpt.com for a subscription.
Expand Down
8 changes: 4 additions & 4 deletions box-image/opencode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
# the build host.
set -eu

builds=/usr/local/lib/node_modules/opencode-ai/node_modules
builds=/usr/local/lib/node_modules/@opencode/cli/node_modules/@opencode

case "$(uname -m)" in
x86_64)
if grep -qw avx2 /proc/cpuinfo 2>/dev/null; then
build=opencode-linux-x64
build=cli-linux-x64
else
build=opencode-linux-x64-baseline
build=cli-linux-x64-baseline
fi
;;
aarch64) build=opencode-linux-arm64 ;;
aarch64) build=cli-linux-arm64 ;;
*)
echo "opencode: no build for $(uname -m)" >&2
exit 1
Expand Down
40 changes: 23 additions & 17 deletions dashboard/e2e/stub-gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import type {
ThreadConfigOption,
ThreadModeState,
ThreadNotification,
ThreadUpdate,
} from '../src/stores/thread/acp-types.ts';

Expand Down Expand Up @@ -166,8 +167,9 @@ export interface StubGateway {
*
* @param update The update.
* @param threadId The ACP id of the thread. Defaults to the default thread.
* @param sessionId The session the update names, which is the thread or a sub agent of it.
*/
emit: (update: ThreadUpdate, threadId?: string) => void;
emit: (update: ThreadUpdate, threadId?: string, sessionId?: string) => void;
/** Closes every socket and the server. */
close: () => void;
}
Expand Down Expand Up @@ -234,7 +236,7 @@ export function attachStubGateway(
/** Every attached socket, each recording the thread it is pinned to. */
const sockets = new Map<WebSocket, string>();
/** One transcript per thread, which is what session/load replays. */
const threads = new Map<string, ThreadUpdate[]>([[THREAD_ID, []]]);
const threads = new Map<string, ThreadNotification[]>([[THREAD_ID, []]]);
/** The thread a socket naming none is pinned to. */
let current = THREAD_ID;
let nextThread = 2;
Expand All @@ -259,7 +261,7 @@ export function attachStubGateway(
* @param threadId The ACP id of the thread.
* @returns The transcript.
*/
const historyOf = (threadId: string): ThreadUpdate[] => {
const historyOf = (threadId: string): ThreadNotification[] => {
let found = threads.get(threadId);
if (!found) {
found = [];
Expand Down Expand Up @@ -304,15 +306,17 @@ export function attachStubGateway(
*
* @param update The update.
* @param threadId The ACP id of the thread. Defaults to the default thread.
* @param sessionId The session the update names, which is the thread or a sub agent of it.
*/
const emit = (update: ThreadUpdate, threadId: string = current): void => {
historyOf(threadId).push(update);
const emit = (
update: ThreadUpdate,
threadId: string = current,
sessionId: string = threadId,
): void => {
const params = { sessionId, update };
historyOf(threadId).push(params);
for (const ws of watchers(threadId)) {
send(ws, {
jsonrpc: '2.0',
method: 'session/update',
params: { sessionId: threadId, update },
});
send(ws, { jsonrpc: '2.0', method: 'session/update', params });
}
};

Expand All @@ -324,7 +328,13 @@ export function attachStubGateway(
*/
const mint = (from: string | null): string => {
const id = `acp-thread-${nextThread++}`;
threads.set(id, from ? [...historyOf(from)] : []);
// The fork's own updates name the fork, as the gateway replays them.
threads.set(
id,
from
? historyOf(from).map((p) => ({ ...p, sessionId: p.sessionId === from ? id : p.sessionId }))
: [],
);
// The new thread becomes the default. Sockets stay pinned to their threads.
current = id;
return id;
Expand Down Expand Up @@ -425,12 +435,8 @@ export function attachStubGateway(
send(ws, { jsonrpc: '2.0', method: REPLAY_METHOD, params: notice });
}
// The replay goes to this socket only.
for (const update of historyOf(threadId).slice(dropped)) {
send(ws, {
jsonrpc: '2.0',
method: 'session/update',
params: { sessionId: threadId, update },
});
for (const params of historyOf(threadId).slice(dropped)) {
send(ws, { jsonrpc: '2.0', method: 'session/update', params });
}
// The real gateway sends the turn state after the replay.
turnState(threadId, ws);
Expand Down
78 changes: 78 additions & 0 deletions dashboard/e2e/thread.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -858,3 +858,81 @@ test('a cut thread offers its full history at the top, and loads it in place', a
await close();
}
});

test('a sub agent is a closed card that shows its run when opened', async () => {
await start();

const { page, errors, close } = await openPage(
stub.url,
`/boxes/${BOX.id}/threads/${BOX.threadId}`,
'dark',
'desktop',
);
try {
await expect.poll(() => page.getByText('connected').isVisible()).toBe(true);

stub.gateway.emit({
sessionUpdate: 'agent_message_chunk',
content: { type: 'text', text: 'I ask a sub agent to read the file.' },
} as ThreadUpdate);
stub.gateway.emit({
sessionUpdate: 'subagent_spawned',
subagentSessionId: 'child-1',
name: 'Find the words',
task: 'Read words.txt and report the words in it.',
} as ThreadUpdate);
// The run of the sub agent arrives on its own session.
stub.gateway.emit(
{
sessionUpdate: 'tool_call',
toolCallId: 'tc-child',
title: 'Read words.txt',
kind: 'read',
status: 'completed',
content: [{ type: 'content', content: { type: 'text', text: 'alpha\nbeta\ngamma' } }],
} as ThreadUpdate,
undefined,
'child-1',
);
stub.gateway.emit(
{
sessionUpdate: 'agent_message_chunk',
content: { type: 'text', text: 'The file has three words.' },
} as ThreadUpdate,
undefined,
'child-1',
);

// The card names the sub agent and is closed, so the run inside is not shown.
const card = page.locator('[data-slot="tool-fallback-trigger"]', { hasText: 'Find the words' });
await expect.poll(() => card.isVisible()).toBe(true);
expect(await card.textContent()).toContain('Sub agent');
expect(await page.getByText('The file has three words.').isVisible()).toBe(false);

await card.click();
await expect.poll(() => page.getByText('The file has three words.').isVisible()).toBe(true);
await expect.poll(() => page.getByText('Read words.txt and report').isVisible()).toBe(true);
// The tool call of the sub agent is a card of its own inside, in a tool group like in the thread.
const run = page.locator('[data-slot="subagent-run"]');
await run.locator('[data-slot="tool-group-trigger"]').click();
const inner = run.locator('[data-slot="tool-fallback-trigger"]', {
hasText: 'Read words.txt',
});
await expect.poll(() => inner.isVisible()).toBe(true);
// The row shimmers while the sub agent runs, and stops when it ends.
const label = card.locator('[data-slot="tool-fallback-trigger-label"]');
const shimmers = () => label.evaluate((el) => el.classList.contains('shimmer'));
expect(await shimmers()).toBe(true);

stub.gateway.emit({
sessionUpdate: 'subagent_state_update',
subagentSessionId: 'child-1',
state: 'completed',
} as ThreadUpdate);
await expect.poll(shimmers).toBe(false);
await shoot(page, 'thread-subagent');
expect(errors).toEqual([]);
} finally {
await close();
}
});
Loading
Loading