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): cua agent logs session:NAME shows what the agent did (#6243)
ddupont414ab83b3a44
diff --git a/docs/content/docs/spaces/guides/keep-an-agent-running.mdx b/docs/content/docs/spaces/guides/keep-an-agent-running.mdxindex 91d0ca2a5f..d8bfb1fa42 100644--- a/docs/content/docs/spaces/guides/keep-an-agent-running.mdx+++ b/docs/content/docs/spaces/guides/keep-an-agent-running.mdx@@ -91,8 +91,12 @@ the conversation or the working folder of the old one. Plan for it:within about a minute, with the same name and an empty disk; the old recordstays listed as offline until you delete it.-Known problems today: `cua agent logs-session:NAME` shows only the driver's heartbeat lines, not what the agent did.+`cua agent logs session:NAME` shows one short line for each event: the driver+and the agent's session starting, each turn starting and ending, the kind and+outcome of each tool call (`tool execute completed`, never the command or its+output), restarts and recovery notes, and errors. It never prints your prompt,+a tool's input or output, or the agent's text. It shows the latest drive's+output; `cua agent status` has the history of every drive.## What happens when it crashesdiff --git a/libs/cua/crates/cua-agents/runner/acp-runner.mjs b/libs/cua/crates/cua-agents/runner/acp-runner.mjsindex 1adf525f18..af6ff6f463 100644--- a/libs/cua/crates/cua-agents/runner/acp-runner.mjs+++ b/libs/cua/crates/cua-agents/runner/acp-runner.mjs@@ -315,6 +315,60 @@ function emit(type, fields = {}) {JSON.stringify({ seq, ts: Date.now(), turn: state.turn, ...(durable ? { epoch: durable.epoch } : {}), type, ...fields }),);appendJournal("events.jsonl", line, Boolean(durable) && SYNC_EVENTS.has(type));+ if (durable) logActivity({ turn: state.turn, epoch: durable.epoch, type, ...fields });+}++// A short readable line on stdout for what happens in a durable run, so+// `cua agent logs session:NAME` shows the agent's progress and not only the+// heartbeat. Only the kind of a tool (execute, read, edit, ...) and short+// notices: never the prompt, a tool's input or output, or the agent's text.+// (stdout growing also tells the coordinator the driver is alive.)+const toolSeen = new Map();+export function activityLine(ev, toolStatusSeen = toolSeen) {+ const c = (x, n) => clip(String(x ?? "").replace(/\s+/g, " ").trim(), n);+ switch (ev.type) {+ case "driver_start":+ return `driver: epoch ${ev.epoch} started${ev.journal ? ", continuing the journal of this session" : ""}`;+ case "session":+ return ev.resumed ? "agent: reloaded its session" : "agent: opened a session";+ case "degraded":+ return "agent: could not reload its conversation; the recovery note carries the journal's summary";+ case "turn_started":+ if (ev.recovery) return `turn ${ev.resumesTurn ?? ev.turn} resumed with a recovery note listing what already ran`;+ return `turn ${ev.turn} started${ev.noteAttached ? " (with a recovery note)" : ""}`;+ case "turn_ended":+ return `turn ${ev.turn} ended (${c(ev.stopReason ?? "no reason", 40)})`;+ case "update": {+ const u = ev.update ?? {};+ if (u.sessionUpdate !== "tool_call" && u.sessionUpdate !== "tool_call_update") return null;+ const id = u.toolCallId;+ const status = u.status ?? (u.sessionUpdate === "tool_call" ? "pending" : null);+ if (!status || status === "pending" || toolStatusSeen.get(id) === status) return null;+ toolStatusSeen.set(id, status);+ const kind = c(u.kind ?? toolInfo.get(id)?.toolKind ?? "tool", 20);+ return `tool ${kind} ${status === "in_progress" ? "started" : status}`;+ }+ case "permission":+ return ev.action === "deny" ? "tool call refused: it was already asked for and may have run" : null;+ case "agent_restart":+ return `agent restarted (${ev.n} of ${ev.of}): ${c(ev.reason, 100)}`;+ case "notice":+ return `notice: ${c(ev.message, 120)}`;+ case "error":+ return `error: ${c(String(ev.message ?? "").split("\n")[0], 160)}`;+ case "cancel_requested":+ return "cancel requested";+ case "run_exited":+ return `driver exiting (code ${ev.code}${ev.reason ? `, ${c(ev.reason, 100)}` : ""})`;+ default:+ return null;+ }+}+function logActivity(ev) {+ try {+ const line = activityLine(ev);+ if (line) process.stdout.write(`${new Date().toISOString().slice(11, 19)} ${redact(line)}\n`);+ } catch {}}function save(patch = {}) {diff --git a/libs/cua/crates/cua-agents/runner/test/durable.test.mjs b/libs/cua/crates/cua-agents/runner/test/durable.test.mjsindex e143648686..5f0c20e101 100644--- a/libs/cua/crates/cua-agents/runner/test/durable.test.mjs+++ b/libs/cua/crates/cua-agents/runner/test/durable.test.mjs@@ -504,6 +504,53 @@ t("CUA_SESSION_HEARTBEAT_SECS makes the runner print heartbeat lines on stdout;}});+// ---- the activity lines (CUA-2957) ----------------------------------------------------++t("a durable run prints a short line for each turn and tool call, never the prompt, a tool's input or the agent's text", async (box) => {+ box.script({ prompts: [{ match: ".", steps: [tool("secret-input-1"), { say: "the agent said something private" }] }] });+ box.config({ prompt: "private prompt text" });+ const r = await box.go({ epoch: 1, resume: false });+ assert.equal(r.code, 0, r.stderr);+ const lines = r.stdout.split("\n").filter(Boolean).map((l) => l.replace(/^\d\d:\d\d:\d\d /, ""));+ assert.ok(lines.includes("driver: epoch 1 started"), JSON.stringify(lines));+ assert.ok(lines.includes("turn 1 started"), JSON.stringify(lines));+ assert.ok(lines.includes("tool execute started") || lines.includes("tool execute completed"), JSON.stringify(lines));+ assert.ok(lines.includes("tool execute completed"), JSON.stringify(lines));+ assert.ok(lines.some((l) => /^turn 1 ended \(/.test(l)), JSON.stringify(lines));+ assert.ok(lines.some((l) => /^driver exiting \(code 0/.test(l)), JSON.stringify(lines));+ for (const l of lines) assert.match(r.stdout, /^\d\d:\d\d:\d\d /m, l);+ for (const secret of ["private prompt text", "secret-input-1", "something private"]) {+ assert.ok(!r.stdout.includes(secret), `${secret} leaked into the log: ${r.stdout}`);+ }+ // Each tool status once: a repeat of a status adds no line.+ assert.equal(lines.filter((l) => l === "tool execute completed").length, 1);+});++t("a restart prints that the driver continued the journal and that a recovery note listing what ran was sent", async (box) => {+ box.script({+ prompts: [+ { match: "recovery", steps: [{ say: "ok" }] },+ { match: ".", steps: [tool("done-1"), tool("sh-1", { killRunnerBeforeOutcome: true })] },+ ],+ });+ box.config();+ const first = await box.go({ epoch: 1, resume: false });+ assert.equal(first.signal, "SIGKILL");+ const r = await box.go({ epoch: 2 });+ assert.equal(r.code, 0, r.stderr);+ assert.match(r.stdout, /driver: epoch 2 started, continuing the journal of this session/);+ assert.match(r.stdout, /turn 1 resumed with a recovery note listing what already ran/);+ assert.match(r.stdout, /agent: reloaded its session/);+});++t("the heartbeat line is unchanged next to the activity lines", async (box) => {+ box.script({ prompts: [{ match: ".", steps: [{ say: "hi" }, { pause: 1500 }] }] });+ box.config();+ const r = await box.go({ epoch: 6, env: { CUA_SESSION_HEARTBEAT_SECS: "1" } });+ assert.ok(r.stdout.split("\n").some((l) => /^CUA-HEARTBEAT 6 \d{13}$/.test(l)), r.stdout);+ assert.ok(r.stdout.includes("turn 1 started"), r.stdout);+});+// ---- drift guards -------------------------------------------------------------------test("drift guard: the env contract and the ledger records match the design", () => {