mirror of
https://github.com/morluto/rea.git
synced 2026-11-08 07:46:28 +00:00
* feat(desktop): keep an agentenv computer up and drive it through REA's MCP tools - A Python helper keeps one agentenv computer up per build with run_bundle(keep=True) and reports its address, MCP URL, control token and sandbox id; it tears the computer down when stdin closes. - AgentEnvComputer owns the helper, waits for readiness, holds one MCP session to the computer's computer_* tools, records through the computer-recording routes, and removes the sandbox's containers by label when agentenv cannot confirm teardown. The token never leaves it. - start_build_computer starts a computer from a request (archive package, apt repository or .deb, opened on demand with REA in /opt/rea) or from a bundle folder; act_on_build_computer forwards screenshot, click, drag, scroll, type, key and wait and returns the driver's images unchanged; close_build_computer tears it down. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(desktop): remove a build computer's container by name when agentenv cannot confirm teardown agentenv's local provider runs an ordinary computer as agent-<sandbox id> without the agentenv.sandbox label, so the label-only fallback found nothing and reported a running computer as removed. The fallback now lists containers by exact name and by label. The real test holds its recording open long enough for a first frame, checks the container by name, and runs rea inside the computer; the guide and tool descriptions say the app opens from the Applications menu and that a screenshot after opening a menu should come from a wait. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(desktop): own failed build-computer starts, keep ids past oversized screenshots, bound recordings - A start is owned from the helper's spawn. One that fails and whose teardown is unconfirmed stays held under a computer_id close can retry; closeAll refuses new starts, cancels and joins starts in progress, then closes every held computer. - When the first screenshot is too large, the error carries REA's result with the computer_id, and start_build_computer takes screenshot region, format and quality. - Recordings are refused before reading when the manifest's total exceeds the allowance, then fetched one segment at a time, each read bounded and checked against its size and sha256. - The helper keeps the tail of its output (a new tail retention mode in ProviderProcessSupervisor), so a build's own error is not crowded out. - A helper that reported no computer exits on its own before SIGTERM, so no phantom owner is kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(desktop): bound a build computer's action log Every action kept its full arguments for the computer's whole life, so a long session grew REA's memory without limit. The log now keeps the latest 256 actions within 256 KiB, cuts each string to 1 KiB and each list to 64 items (naming what it cut), and keeps the total and the last applied index of each kind of action, so rules over the whole session hold after entries drop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
140 lines
5.2 KiB
TypeScript
140 lines
5.2 KiB
TypeScript
import { expect, it, onTestFinished } from "vitest";
|
|
|
|
import {
|
|
LOGGED_ACTIONS,
|
|
LOGGED_BYTES,
|
|
LOGGED_LIST_ITEMS,
|
|
LOGGED_TEXT_BYTES,
|
|
} from "../../../src/application/desktop/DesktopBuildActionLog.js";
|
|
import {
|
|
FAKE_SEGMENTS,
|
|
type FakeComputerOptions,
|
|
fakeBuildComputers,
|
|
} from "../../fixtures/fakeAgentEnvComputer.js";
|
|
|
|
/** A build computer held up by REA's real helper over a fake runner and driver. */
|
|
const startComputer = async (options: FakeComputerOptions = {}) => {
|
|
const { computer, computers, start } = await fakeBuildComputers(options);
|
|
onTestFinished(() => computers.closeAll());
|
|
const started = await start();
|
|
if (!started.ok) throw started.error;
|
|
const id = started.value.value.computer_id;
|
|
const session = computers.session(id);
|
|
if (session === undefined) throw new Error("the started computer is held");
|
|
return { computer, computers, id, session };
|
|
};
|
|
|
|
it("records a build session under REA's request id and fetches its segments before teardown", async () => {
|
|
const { computer, computers, id, session } = await startComputer();
|
|
const recording = await session.startRecording("rea-build:1");
|
|
const acted = await computers.act(
|
|
{ computer_id: id, action: "type", text: "buy milk\n" },
|
|
new AbortController().signal,
|
|
);
|
|
expect(acted.ok).toBe(true);
|
|
const manifest = await session.endRecording(recording.recording_id);
|
|
expect(await session.recordingSegments(manifest)).toEqual([
|
|
{ path: "rec-000000000001/0000.mp4", bytes: FAKE_SEGMENTS[0] },
|
|
{ path: "rec-000000000001/0001.mp4", bytes: FAKE_SEGMENTS[1] },
|
|
]);
|
|
// One segment per request, so only one segment's body is held at a time.
|
|
expect(computer.dataRequests).toEqual([
|
|
[".agentenv-recordings/rec-000000000001/0000.mp4"],
|
|
[".agentenv-recordings/rec-000000000001/0001.mp4"],
|
|
]);
|
|
expect(computer.recordingRequests).toEqual([
|
|
{
|
|
path: "/agentenv/ext/computer-recording/start",
|
|
body: { request_id: "rea-build:1" },
|
|
},
|
|
{
|
|
path: "/agentenv/ext/computer-recording/end",
|
|
body: { recording_id: "rec-000000000001" },
|
|
},
|
|
]);
|
|
// The witness reads what was done, in order, with the driver's arguments.
|
|
expect(session.actions.entries).toMatchObject([
|
|
{
|
|
index: 0,
|
|
action: "type",
|
|
tool: "computer_type",
|
|
arguments: { text: "buy milk\n" },
|
|
outcome: "applied",
|
|
},
|
|
]);
|
|
expect(computer.unauthorized).toEqual([]);
|
|
expect((await computers.close(id)).ok).toBe(true);
|
|
});
|
|
|
|
it("keeps a long session's action log within its allowance while the driver gets each action whole", async () => {
|
|
const { computer, computers, id, session } = await startComputer();
|
|
const signal = new AbortController().signal;
|
|
const path = Array.from(
|
|
{ length: 2 * LOGGED_LIST_ITEMS },
|
|
(_, at): [number, number] => [at, at],
|
|
);
|
|
expect(
|
|
(await computers.act({ computer_id: id, action: "drag", path }, signal)).ok,
|
|
).toBe(true);
|
|
const text = "buy milk ".repeat(LOGGED_TEXT_BYTES);
|
|
const typed = LOGGED_ACTIONS;
|
|
for (let index = 0; index < typed; index += 1)
|
|
expect(
|
|
(await computers.act({ computer_id: id, action: "type", text }, signal))
|
|
.ok,
|
|
).toBe(true);
|
|
expect(computer.calls.at(1)?.arguments).toEqual({ path });
|
|
expect(computer.calls.at(-1)?.arguments).toEqual({ text });
|
|
const { entries } = session.actions;
|
|
expect(
|
|
entries.reduce(
|
|
(bytes, entry) => bytes + Buffer.byteLength(JSON.stringify(entry)),
|
|
0,
|
|
),
|
|
).toBeLessThanOrEqual(LOGGED_BYTES);
|
|
expect(session.actions.total).toBe(typed + 1);
|
|
expect(session.actions.dropped).toBe(typed + 1 - entries.length);
|
|
expect(session.actions.dropped).toBeGreaterThan(0);
|
|
expect(entries.at(-1)).toMatchObject({
|
|
index: typed,
|
|
action: "type",
|
|
arguments: { text: text.slice(0, LOGGED_TEXT_BYTES) },
|
|
truncated_arguments: ["text"],
|
|
outcome: "applied",
|
|
});
|
|
// The drag is no longer kept, but that it was applied is.
|
|
expect(session.actions.lastApplied).toEqual({ drag: 0, type: typed });
|
|
});
|
|
|
|
it("refuses a segment whose bytes differ from the recording's manifest", async () => {
|
|
const { session } = await startComputer();
|
|
const manifest = await session.endRecording("rec-000000000001");
|
|
await expect(
|
|
session.recordingSegments({
|
|
...manifest,
|
|
segments: manifest.segments.map((segment) => ({
|
|
...segment,
|
|
sha256: "0".repeat(64),
|
|
})),
|
|
}),
|
|
).rejects.toThrow(/rec-000000000001\/0000\.mp4/u);
|
|
});
|
|
|
|
it("refuses a recording larger than the allowance before reading any segment", async () => {
|
|
const { computer, session } = await startComputer();
|
|
const manifest = await session.endRecording("rec-000000000001");
|
|
const total = FAKE_SEGMENTS.reduce((sum, bytes) => sum + bytes.length, 0);
|
|
await expect(
|
|
session.recordingSegments(manifest, undefined, total - 1),
|
|
).rejects.toThrow(String(total));
|
|
expect(computer.dataRequests).toEqual([]);
|
|
});
|
|
|
|
it("stops reading a segment whose answer outgrows its manifest size", async () => {
|
|
const { session } = await startComputer({ segmentPadding: 1024 * 1024 });
|
|
const manifest = await session.endRecording("rec-000000000001");
|
|
await expect(session.recordingSegments(manifest)).rejects.toThrow(
|
|
/rec-000000000001\/0000\.mp4.*more than/u,
|
|
);
|
|
});
|