Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
fix(agents): durable agents start again: give the harness an absolute working folder (#6220)
ddupontcba650dab5ad
diff --git a/libs/cua/crates/cua-agents/runner/acp-runner.mjs b/libs/cua/crates/cua-agents/runner/acp-runner.mjsindex 2a7bbe81da..2573488e29 100644--- a/libs/cua/crates/cua-agents/runner/acp-runner.mjs+++ b/libs/cua/crates/cua-agents/runner/acp-runner.mjs@@ -86,8 +86,8 @@ const expandVars = (s) =>typeof s !== "string"? s: s- .replace(/^~(?=\/|$)/, os.homedir())- .replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (m, k) => process.env[k] ?? cfg.env?.[k] ?? m);+ .replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (m, k) => process.env[k] ?? cfg.env?.[k] ?? m)+ .replace(/^~(?=\/|$)/, os.homedir());function loadDurable() {if (!cfg.durable) return null;@@ -133,7 +133,9 @@ if (durable) fs.mkdirSync(durable.stateDir, { recursive: true, mode: 0o700 });if (durable) {process.env.CUA_RUN_DIR ??= path.resolve(dir);- process.env.CUA_SESSION_STATE_DIR ||= durable.stateDir;+ // The expanded directory, never the `~/...` the session was given: `${CUA_SESSION_STATE_DIR}/work`+ // is the harness's cwd, and a harness refuses a cwd that is not absolute.+ process.env.CUA_SESSION_STATE_DIR = durable.stateDir;cfg.cwd = expandVars(cfg.cwd);cfg.agent = { ...cfg.agent, command: expandVars(cfg.agent.command), args: (cfg.agent.args ?? []).map(expandVars) };cfg.env = Object.fromEntries(Object.entries(cfg.env ?? {}).map(([k, v]) => [k, expandVars(v)]));diff --git a/libs/cua/crates/cua-agents/runner/test/durable.test.mjs b/libs/cua/crates/cua-agents/runner/test/durable.test.mjsindex adce87935f..5bf7fb09cc 100644--- a/libs/cua/crates/cua-agents/runner/test/durable.test.mjs+++ b/libs/cua/crates/cua-agents/runner/test/durable.test.mjs@@ -26,6 +26,19 @@ async function withBox(fn) {const tool = (id, extra = {}) => ({ tool: { id, title: `run ${id}`, kind: "execute", input: { cmd: id }, ...extra } });const floor = (box) => Number(fs.readFileSync(path.join(box.state, "epoch"), "utf8"));+// ---- the working folder ----------------------------------------------------++t("a state directory given as ~/... gives the harness an absolute working folder", async (box) => {+ box.script({ prompts: [{ match: ".", steps: [{ say: "hi" }] }] });+ // What `cua agent add --durable` sends: state dir `~/.cua/durable/NAME`, cwd `${CUA_SESSION_STATE_DIR}/work`.+ box.config({ cwd: "${CUA_SESSION_STATE_DIR}/work", durable: { stateDir: "~/.cua/durable/s1" } });+ const r = await box.go({ epoch: 1, resume: false, env: { HOME: box.root, CUA_SESSION_STATE_DIR: "~/.cua/durable/s1" } });+ assert.equal(r.code, 0, r.stderr);+ const cwd = box.agentLog().find((l) => l.ev === "session_new")?.cwd;+ assert.ok(path.isAbsolute(cwd), `cwd ${cwd} is not absolute`);+ assert.equal(cwd, path.join(box.root, ".cua/durable/s1/work"));+});+// ---- the fence -----------------------------------------------------------t("a stale epoch is refused: exit 75, nothing written, the agent never starts", async (box) => {diff --git a/libs/cua/crates/cua-agents/runner/test/mock-acp-agent.mjs b/libs/cua/crates/cua-agents/runner/test/mock-acp-agent.mjsindex a76fb8f930..7a09876b34 100644--- a/libs/cua/crates/cua-agents/runner/test/mock-acp-agent.mjs+++ b/libs/cua/crates/cua-agents/runner/test/mock-acp-agent.mjs@@ -124,10 +124,10 @@ agent},authMethods: [],}))- .onRequest("session/new", () => {+ .onRequest("session/new", (ctx) => {const id = `mock-${Math.random().toString(16).slice(2, 10)}`;fs.writeFileSync(sessionsFile, JSON.stringify({ ...sessions(), [id]: true }));- log({ ev: "session_new", id });+ log({ ev: "session_new", id, cwd: ctx?.params?.cwd });return {sessionId: id,modes: { currentModeId: "default", availableModes: [{ id: "default" }, { id: "ask", _meta: { kind: "standard" } }, { id: "full", _meta: { kind: "full_access" } }] },