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
24 changes: 24 additions & 0 deletions dashboard/e2e/views.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,27 @@ test('a stopped box is started from its info view, and stopped again', async ()
await close();
}
});

test('a box is renamed from its info view, and the list shows the new name', async () => {
const { page, errors, close } = await openPage(stub.url, '/boxes/e5f6a7b8/info');
try {
const field = page.getByLabel('Name');
const button = page.getByRole('button', { name: 'Rename' });
await expect.poll(() => field.isVisible()).toBe(true);
// The button is off while the field shows the name of the box.
expect(await button.isDisabled()).toBe(true);

await field.fill('a renamed box');
await button.click();
await expect
.poll(() => page.getByRole('heading', { name: 'a renamed box' }).isVisible())
.toBe(true);
await expect.poll(() => button.isDisabled()).toBe(true);

await page.goto(`${stub.url}/`);
await expect.poll(() => page.getByText('a renamed box').isVisible()).toBe(true);
expect(errors).toEqual([]);
} finally {
await close();
}
});
12 changes: 12 additions & 0 deletions dashboard/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,18 @@ export const api = {
*/
deleteReview: (id: string) => request<void>(`/api/boxes/${id}/review`, { method: 'DELETE' }),

/**
* Changes the name of a box.
*
* @param id The id of the box.
* @param name The new name.
* @returns The box after the change.
*/
renameBox: (id: string, name: string) =>
request<BoxDetail>(`/api/boxes/${id}/name`, {
method: 'PUT',
body: JSON.stringify({ name }),
}),
/**
* Selects the agent sets of a box.
*
Expand Down
32 changes: 30 additions & 2 deletions dashboard/src/views/BoxInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useState } from 'react';
import { type FormEvent, useCallback, useEffect, useState } from 'react';
import { Link, useNavigate, useParams } from 'react-router';
import { AgentSetPicker } from '@/components/AgentSetPicker';
import { BackLink } from '@/components/BackLink';
Expand All @@ -10,6 +10,8 @@ import { Notice } from '@/components/Notice';
import { StatusBadge } from '@/components/StatusBadge';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import {
Select,
SelectContent,
Expand Down Expand Up @@ -62,6 +64,8 @@ export function BoxInfo() {
const [error, setError] = useState<string | null>(null);
const [busy, setBusy] = useState(false);
const [confirmDelete, setConfirmDelete] = useState(false);
/** The name in the name field. Null while the field shows the name of the box. */
const [nameDraft, setNameDraft] = useState<string | null>(null);
/** The named agent sets, for the picker. Null while loading or when the request failed. */
const [agentSets, setAgentSets] = useState<AgentSetSummary[] | null>(null);
/** The egress profiles, for the select. Null while loading or when the request failed. */
Expand Down Expand Up @@ -154,6 +158,16 @@ export function BoxInfo() {
}

const running = box.runtimeState === 'running';
const name = (nameDraft ?? box.name).trim();

/** Saves the name from the name field. */
const rename = async (e: FormEvent): Promise<void> => {
e.preventDefault();
await act(async () => {
await api.renameBox(id, name);
setNameDraft(null);
});
};

return (
<div className="flex flex-col gap-4">
Expand Down Expand Up @@ -181,7 +195,21 @@ export function BoxInfo() {
<CardHeader>
<CardTitle className="text-sm">Details</CardTitle>
</CardHeader>
<CardContent>
<CardContent className="flex flex-col gap-4">
<form className="flex items-end gap-2" onSubmit={(e) => void rename(e)}>
<div className="flex min-w-0 flex-1 flex-col gap-2">
<Label htmlFor="box-name">Name</Label>
<Input
id="box-name"
value={nameDraft ?? box.name}
maxLength={100}
onChange={(e) => setNameDraft(e.target.value)}
/>
</div>
<Button type="submit" disabled={busy || name === '' || name === box.name}>
Rename
</Button>
</form>
<dl className="grid grid-cols-[7rem_1fr] gap-x-3 gap-y-2">
<Meta label="Box" value={box.id} />
<Meta label="ACP thread" value={box.acpSessionId ?? 'not started'} />
Expand Down
4 changes: 2 additions & 2 deletions doc/boxes.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ The info icon on a card opens the box's details page.

The details page shows the box's identity and runtime state: the facts of the runtime (on Docker the container id, the
network name with its subnet, and the image id), last activity, disk use, and the ACP session id of the most recently
active thread. It shows the agent sets and the egress profile of the box, which the user can change there, and the
[refused hosts](egress-profiles.md#refused-hosts). It lists the dev tunnels the box hosts and the processes the
active thread. It shows the name, the agent sets and the egress profile of the box, which the user can change there, and
the [refused hosts](egress-profiles.md#refused-hosts). It lists the dev tunnels the box hosts and the processes the
orchestrator last read in the box.
For a running box whose network isolation is not complete, it shows a warning.

Expand Down
4 changes: 4 additions & 0 deletions doc/rest.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ adapter's last advertised modes and config options (when one has answered), and
| POST | `/api/boxes/:id/start` | `BoxDetail` |
| POST | `/api/boxes/:id/stop` | `BoxDetail` |
| DELETE | `/api/boxes/:id` | 204 |
| PUT | `/api/boxes/:id/name` | `BoxDetail` |
| PUT | `/api/boxes/:id/agent-sets` | `BoxDetail` |
| PUT | `/api/boxes/:id/egress-profile` | `BoxDetail` |
| GET | `/api/boxes/:id/denials` | `EgressDenial[]` |
Expand All @@ -56,6 +57,9 @@ adapter's last advertised modes and config options (when one has answered), and
Every [box](boxes.md) is created with one thread. `thread` selects its harness and its initial mode and config; absent,
it is Claude on its defaults. `profile` is accepted but ignored. An unknown `egressProfile` gets a 400.

The orchestrator trims the `name`. An empty name or a name of more than 100 characters gets a 400. `PUT …/name` accepts
`{ "name": "…" }` with the same rules.

`agentSets` lists the [agent sets](agent-sets.md) of the box in the order of the merge. An absent or empty list selects
the global set only. A list with the global set, an unknown set, or one set twice gets a 400.

Expand Down
36 changes: 36 additions & 0 deletions orchestrator/src/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,42 @@ test('a box changes its egress profile, and moves to the default when its profil
);
});

test('a box is renamed over the API', async () => {
insertBox('abc123');
fakeDocker();

const renamed = await orchestrator.app.inject({
method: 'PUT',
url: '/api/boxes/abc123/name',
payload: { name: ' new name ' },
});
assert.equal(renamed.statusCode, 200);
assert.equal(renamed.json().name, 'new name');
const list = await orchestrator.app.inject({ url: '/api/boxes' });
assert.deepEqual(
(list.json() as Array<{ name: string }>).map((b) => b.name),
['new name'],
);

for (const name of [' ', 'x'.repeat(101)]) {
const refused = await orchestrator.app.inject({
method: 'PUT',
url: '/api/boxes/abc123/name',
payload: { name },
});
assert.equal(refused.statusCode, 400);
}
const after = await orchestrator.app.inject({ url: '/api/boxes/abc123' });
assert.equal(after.json().name, 'new name');

const missingBox = await orchestrator.app.inject({
method: 'PUT',
url: '/api/boxes/nope/name',
payload: { name: 'new name' },
});
assert.equal(missingBox.statusCode, 404);
});

/** The fields of a pushed policy that the tests read. */
interface PushedPolicy {
/** The policy of each box. */
Expand Down
7 changes: 7 additions & 0 deletions orchestrator/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
backgroundStopBody,
boxAgentSetsBody,
boxEgressProfileBody,
boxNameBody,
createAgentSetBody,
createBoxBody,
createEgressProfileBody,
Expand Down Expand Up @@ -721,6 +722,12 @@ export function buildApp(cfg: Config, db: Db, opts: BuildOptions = {}): Orchestr
return reply.code(204).send();
});

app.put('/api/boxes/:id/name', async (req) => {
const { id } = req.params as { id: string };
const body = parseBody(boxNameBody, req.body);
return manager.rename(id, body.name);
});

app.put('/api/boxes/:id/agent-sets', async (req) => {
const { id } = req.params as { id: string };
const body = parseBody(boxAgentSetsBody, req.body);
Expand Down
5 changes: 5 additions & 0 deletions orchestrator/src/bodies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ export const createBoxBody = z.object({
thread: threadOptions.optional(),
});

/** The body of PUT /api/boxes/:id/name, with the new name of the box. */
export const boxNameBody = z.object({
name: z.string(),
});

/**
* The body of PUT /api/boxes/:id/egress-profile, with the profile of the box
* or null for the default profile.
Expand Down
32 changes: 29 additions & 3 deletions orchestrator/src/boxes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,7 @@ export class BoxManager {
* not available, or a 500 when a step of the create fails.
*/
async create(body: CreateBoxBody, owner: string): Promise<BoxDetail> {
const name = body.name?.trim();
if (!name) throw new HttpError(400, 'name is required');
if (name.length > 100) throw new HttpError(400, 'name must be 100 characters or fewer');
const name = boxName(body.name);

const agentSetIds = this.selectedAgentSets(owner, body.agentSets);
const egressProfileId = this.selectedProfile(owner, body.egressProfile);
Expand Down Expand Up @@ -587,6 +585,20 @@ export class BoxManager {
return this.detail(id);
}

/**
* Changes the display name of a box.
*
* @param id The id of the box.
* @param requested The new name.
* @returns The detail of the box.
* @throws {HttpError} A 404 when the box does not exist, or a 400 when the name is not valid.
*/
async rename(id: string, requested: string): Promise<BoxDetail> {
this.mustGet(id);
this.db.prepare('UPDATE boxes SET name = ? WHERE id = ?').run(boxName(requested), id);
return this.detail(id);
}

/**
* Checks the egress profile that a request selects for a box of a user.
*
Expand Down Expand Up @@ -1411,6 +1423,20 @@ function toThreadSummary(
};
}

/**
* Checks the display name of a box from a request.
*
* @param name The name from the request.
* @returns The name without the surrounding whitespace.
* @throws {HttpError} A 400 for an empty name or a name of more than 100 characters.
*/
function boxName(name: string | undefined): string {
const trimmed = name?.trim();
if (!trimmed) throw new HttpError(400, 'name is required');
if (trimmed.length > 100) throw new HttpError(400, 'name must be 100 characters or fewer');
return trimmed;
}

/**
* Checks the thread options of a request.
*
Expand Down