diff --git a/packages/agent-office/CHANGELOG.md b/packages/agent-office/CHANGELOG.md index 18698b3..6e43ad5 100644 --- a/packages/agent-office/CHANGELOG.md +++ b/packages/agent-office/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 0.1.1 · 2026-10-31 + +### Fixed + +- An agent another agent ran and then interrupted from the shell (`claude -p` or `codex exec` killed by SIGTERM or SIGKILL) no longer stays in the office as at work, then stuck, until its session is deleted in magpie. A Claude Code session with no running process in Claude Code's `sessions/.json` files is stopped (also Qoder, WorkBuddy and CodeBuddy when their folder keeps such files). +- **Clear** (清除) in an agent's panel takes a stuck, failed, stopped, finished or waiting agent out of the office until its session moves again. Before, nothing could take one out but `hideAfter`, and a waiting one never left. + ## 0.1.0 · 2026-10-29 首个公开发布版本。First public release. diff --git a/packages/agent-office/README.md b/packages/agent-office/README.md index 13c4bec..091d815 100644 --- a/packages/agent-office/README.md +++ b/packages/agent-office/README.md @@ -2,7 +2,7 @@ [![Latest release](https://img.shields.io/github/v/release/QingJ01/magpie-agent-office)](https://github.com/QingJ01/magpie-agent-office/releases) [![magpie ≥ 0.1.1318](https://img.shields.io/badge/magpie-%E2%89%A5%200.1.1318-4f46e5)](https://usemagpie.ai) -[![Tests](https://img.shields.io/badge/tests-44%20passing-22a35a)](#test) +[![Tests](https://img.shields.io/badge/tests-54%20passing-22a35a)](#test) [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE) **一个住在 magpie 窗口里的实时 Agent 办公室。** 直接读取各 Agent 自己的会话记录,把正在思考、执行工具、等待批准或已经完成的工作,变成太空站里的小人。支持等距 3D、俯视 2D、实时列表和可拖动的悬浮小窗。 @@ -72,6 +72,8 @@ From each agent's **own session file**, as the agent writes it — not a guess f The `*_HOME` / `*_CONFIG_DIR` variables those agents honour are honoured here too. What each file says decides the status outright: a tool call with no result yet is **running**, an approval asked (Codex's `exec_approval_request`, DeepSeek Harness's `approval/asked`, Gemini's `awaiting_approval`) is **waiting for you**, a question tool is **asked you something**, the turn's end is **done**, an interruption is **stopped**, an error turn is **error**. A turn whose file hasn't moved for ten minutes is shown as stuck. +An agent killed mid-turn writes no end at all: one agent running another (`claude -p` or `codex exec` from a Bash tool) and interrupting it leaves the other's file mid-turn. Claude Code keeps a file per running process (`sessions/.json`), so a Claude Code session with no running process is **stopped**, at once. Codex and the other agents keep nothing a reader can check, so such a session shows as stuck. Any agent not at work — stuck, failed, stopped, done or waiting — can be taken out of the office with **Clear** (清除) in its panel; it comes back when its session moves again. + Every other agent (Cursor, OpenCode, Copilot, Kimi…) shows while it works through magpie: the module is also an [asynchronous gateway hook](https://usemagpie.ai/docs/plugins#gateway-request) that sees its requests. The hook returns no body, so no request changes. Both write `page/live.js` beside the page, which the page loads every second (a plugin page has no network; its own files it may load). The green **live** dot by the title turns grey if the host stops writing. diff --git a/packages/agent-office/killed.test.mjs b/packages/agent-office/killed.test.mjs new file mode 100644 index 0000000..71d6905 --- /dev/null +++ b/packages/agent-office/killed.test.mjs @@ -0,0 +1,135 @@ +// An agent another agent ran and then interrupted: `claude -p` or `codex +// exec` started by a Bash tool and killed from the shell. Its session file +// ends mid-turn, so it read as at work and then stuck for good. The files in +// test/killed are what Claude Code 2.1.314 and Codex 0.165.0 really wrote +// when killed (SIGTERM and SIGKILL), cut to the lines that matter. +import { afterAll, expect, test } from "bun:test" +import { mkdirSync, mkdtempSync, readFileSync, rmSync, utimesSync, writeFileSync } from "node:fs" +import { tmpdir } from "node:os" +import { join } from "node:path" +import { readClaude, readCodex } from "./lib/readers.mjs" +import { createScanner } from "./lib/scan.mjs" + +const dir = import.meta.dir +const fixture = (n) => readFileSync(join(dir, "test", "killed", n), "utf8") +const scope = {} +new Function("globalThis", readFileSync(join(dir, "page", "agents.js"), "utf8"))(scope) +new Function("globalThis", readFileSync(join(dir, "page", "model.js"), "utf8"))(scope) +const M = scope.AgentOfficeModel + +const tmps = [] +const tmp = () => { const d = mkdtempSync(join(tmpdir(), "agent-office-killed-")); tmps.push(d); return d } +afterAll(() => { for (const d of tmps) rmSync(d, { recursive: true, force: true }) }) + +const TERM_ID = "24b647af-dbc4-404b-a97e-c05d30681179" +const KILL_ID = "a6139a3c-e585-4b7e-8a69-f58fef09c87e" + +// a pid no process has: one that ran and ended +function deadPid() { + const p = Bun.spawnSync([process.execPath, "-e", ""]) + return p.pid +} + +// a Claude config folder with one session file, written `ago` ms before now, +// and the given process files +function claudeHome(file, id, procs, ago, now) { + const h = tmp() + const proj = join(h, "projects", "-Users-me-work") + mkdirSync(proj, { recursive: true }) + const f = join(proj, id + ".jsonl") + writeFileSync(f, fixture(file)) + const t = (now - ago) / 1000 + utimesSync(f, t, t) + if (procs) { + mkdirSync(join(h, "sessions"), { recursive: true }) + for (const p of procs) writeFileSync(join(h, "sessions", p.pid + ".json"), JSON.stringify({ pidDomain: process.platform, kind: "interactive", ...p })) + } + const src = [{ agent: "claude", kind: "claude", root: join(h, "projects"), depth: 1, match: (n) => n.endsWith(".jsonl"), live: join(h, "sessions") }] + return { h, src } +} + +test("the real files end mid-turn: on their own they read as at work", () => { + expect(readClaude(fixture("claude-sigterm.jsonl")).phase).toBe("thinking") + expect(readClaude(fixture("claude-sigkill.jsonl")).phase).toBe("tool") + expect(readCodex(fixture("codex-sigterm.jsonl")).phase).toBe("tool") +}) + +test("a Claude Code session SIGTERMed (its process file gone) is stopped, not stuck", () => { + const now = Date.now() + // another Claude Code still runs: the folder keeps process files + const { src } = claudeHome("claude-sigterm.jsonl", TERM_ID, [{ pid: process.pid, sessionId: "the-lead" }], 60e3, now) + const [s] = createScanner({ sources: src }).scan(now) + expect(s.id).toBe(TERM_ID) + expect(s.phase).toBe("aborted") + // hours later it is still stopped, on the sofa, never "stuck" + const later = { ...s, source: "files", touched: s.touched } + expect(M.state(later, now + 3600e3)).toEqual({ status: "done", sub: "stopped" }) +}) + +test("a Claude Code session SIGKILLed (its process file left, the pid gone) is stopped", () => { + const now = Date.now() + const { src } = claudeHome("claude-sigkill.jsonl", KILL_ID, [{ pid: deadPid(), sessionId: KILL_ID }], 60e3, now) + const [s] = createScanner({ sources: src }).scan(now) + expect(s.phase).toBe("aborted") + expect(s.pending).toEqual([]) +}) + +test("a session whose process runs stays at work, however quiet", () => { + const now = Date.now() + const { src } = claudeHome("claude-sigkill.jsonl", KILL_ID, [{ pid: process.pid, sessionId: KILL_ID }], 30 * 60e3, now) + const [s] = createScanner({ sources: src }).scan(now) + expect(s.phase).toBe("tool") +}) + +test("a turn written a moment ago is not judged: the process may be starting", () => { + const now = Date.now() + const { src } = claudeHome("claude-sigterm.jsonl", TERM_ID, [{ pid: process.pid, sessionId: "the-lead" }], 2e3, now) + expect(createScanner({ sources: src }).scan(now)[0].phase).toBe("thinking") +}) + +test("a folder that never held a process file says nothing (an agent that keeps none)", () => { + const now = Date.now() + for (const procs of [null, []]) { + const { src } = claudeHome("claude-sigterm.jsonl", TERM_ID, procs, 60e3, now) + expect(createScanner({ sources: src }).scan(now)[0].phase).toBe("thinking") + } +}) + +test("once the folder has held one, the last Claude Code ending empties it: still judged", () => { + const now = Date.now() + const { h, src } = claudeHome("claude-sigterm.jsonl", TERM_ID, [{ pid: process.pid, sessionId: TERM_ID }], 60e3, now) + const sc = createScanner({ sources: src }) + expect(sc.scan(now)[0].phase).toBe("thinking") + rmSync(join(h, "sessions", process.pid + ".json")) + expect(sc.scan(now + 1500)[0].phase).toBe("aborted") +}) + +test("a process file of another system's (WSL) is not asked about here", () => { + const now = Date.now() + const { src } = claudeHome("claude-sigkill.jsonl", KILL_ID, [{ pid: deadPid(), sessionId: KILL_ID, pidDomain: "elsewhere" }], 60e3, now) + expect(createScanner({ sources: src }).scan(now)[0].phase).toBe("tool") +}) + +test("a stuck session the user clears leaves the office until it moves again", () => { + const now = Date.now() + const c = readCodex(fixture("codex-sigterm.jsonl")) + const s = { ...c, key: "codex|" + c.id, source: "files", touched: now - 20 * 60e3, updated: now - 20 * 60e3 } + const snap = { sessions: [s] } + const [a] = M.agents(snap, now, {}) + expect([a.status, a.sub]).toEqual(["error", "stuck"]) + expect(M.clearable(a.status)).toBe(true) + expect(M.agents(snap, now, { cleared: { [a.key]: a.at } })).toEqual([]) + // its file moves: it is back + const moved = { sessions: [{ ...s, touched: now }] } + expect(M.agents(moved, now, { cleared: { [a.key]: a.at } }).map((x) => x.key)).toEqual([a.key]) +}) + +test("an agent at work can't be cleared", () => { + const now = Date.now() + const c = readCodex(fixture("codex-sigterm.jsonl")) + const s = { ...c, key: "codex|" + c.id, source: "files", touched: now - 1000, updated: now - 1000 } + const [a] = M.agents({ sessions: [s] }, now, {}) + expect(a.status).toBe("executing") + expect(M.clearable(a.status)).toBe(false) + expect(M.agents({ sessions: [s] }, now, { cleared: { [a.key]: a.at + 1 } }).length).toBe(1) +}) diff --git a/packages/agent-office/lib/scan.mjs b/packages/agent-office/lib/scan.mjs index 0800b48..46bc822 100644 --- a/packages/agent-office/lib/scan.mjs +++ b/packages/agent-office/lib/scan.mjs @@ -20,6 +20,16 @@ const TAIL = 512 * 1024 // what is read of a big file's end // is decoded at most once every ZSTD_EVERY: its last facts stand meanwhile. const ZSTD_MAX = 8 * 1024 * 1024 const ZSTD_EVERY = 4000 +// Claude Code keeps one file per running process, /sessions/.json +// ({pid, sessionId, …}). It takes the file away when it ends on SIGINT or +// SIGTERM and leaves it when SIGKILLed, so a session with no living process +// in that folder has stopped, whatever its last line says. That is the case +// of an agent another agent ran and interrupted (`claude -p` killed from the +// shell): its file ends mid-turn, and without this it read as at work and +// then stuck for good. A turn quiet less than GONE_AFTER is not judged: the +// process may be starting. +const GONE_AFTER = 10e3 +const MIDTURN = new Set(["thinking", "tool", "approval", "ask"]) function env(k) { return (process.env[k] || "").trim() } function home(...p) { return join(env("HOME") || homedir(), ...p) } @@ -38,17 +48,17 @@ export function sources() { const codebuddy = env("CODEBUDDY_CONFIG_DIR") ? expand(env("CODEBUDDY_CONFIG_DIR")) : home(".codebuddy") const jsonl = (n) => n.endsWith(".jsonl") return [ - { agent: "claude", kind: "claude", root: join(claude, "projects"), depth: 1, match: jsonl }, + { agent: "claude", kind: "claude", root: join(claude, "projects"), depth: 1, match: jsonl, live: join(claude, "sessions") }, { agent: "codex", kind: "codex", root: join(codex, "sessions"), depth: 3, match: (n) => n.startsWith("rollout-") && n.endsWith(".jsonl") }, { agent: "dsh", kind: "dsh", root: join(dsh, "sessions"), depth: 2, match: (n) => n === "session.v4.jsonl.zstd" || n === "session.v4.jsonl" }, { agent: "gemini", kind: "gemini", root: home(".gemini", "tmp"), depth: 2, match: (n) => n.startsWith("session-") && (n.endsWith(".json") || n.endsWith(".jsonl")) }, { agent: "qwen", kind: "gemini", root: home(".qwen", "tmp"), depth: 2, match: (n) => n.startsWith("session-") && (n.endsWith(".json") || n.endsWith(".jsonl")) }, { agent: "pi", kind: "pi", root: join(pi, "sessions"), depth: 1, match: jsonl }, { agent: "omp", kind: "pi", root: home(".omp", "agent", "sessions"), depth: 1, match: jsonl }, - { agent: "qoder", kind: "claude", root: join(qoder, "projects"), depth: 1, match: jsonl }, - { agent: "qoder-cn", kind: "claude", root: join(qodercn, "projects"), depth: 1, match: jsonl }, - { agent: "workbuddy", kind: "claude", root: join(workbuddy, "projects"), depth: 1, match: jsonl }, - { agent: "codebuddy", kind: "claude", root: join(codebuddy, "projects"), depth: 1, match: jsonl }, + { agent: "qoder", kind: "claude", root: join(qoder, "projects"), depth: 1, match: jsonl, live: join(qoder, "sessions") }, + { agent: "qoder-cn", kind: "claude", root: join(qodercn, "projects"), depth: 1, match: jsonl, live: join(qodercn, "sessions") }, + { agent: "workbuddy", kind: "claude", root: join(workbuddy, "projects"), depth: 1, match: jsonl, live: join(workbuddy, "sessions") }, + { agent: "codebuddy", kind: "claude", root: join(codebuddy, "projects"), depth: 1, match: jsonl, live: join(codebuddy, "sessions") }, ] } @@ -85,6 +95,53 @@ function zstd(path) { throw new Error("no zstd here") } +// whether a process with this pid is running: EPERM is someone else's, still +// running; only ESRCH says there is none +function pidAlive(pid) { + try { process.kill(pid, 0); return true } catch (e) { return e?.code !== "ESRCH" } +} + +// The sessions folder of a Claude-format agent: which session ids have a +// running process. null when it can't say: the folder has never been seen +// to hold such a file (an agent, or a version, that doesn't keep them), or +// can't be read. Once a folder has held one, an empty folder means no +// process runs. +export function createProcesses() { + const dirs = new Map() // dir -> { kept: bool, files: Map(name -> { mtime, pid, id, here }) } + function running(dir) { + let d = dirs.get(dir) + if (!d) { d = { kept: false, files: new Map() }; dirs.set(dir, d) } + let names + try { names = readdirSync(dir) } catch { return null } + const seen = new Set() + for (const n of names) { + if (!/^\d+\.json$/.test(n)) continue + seen.add(n) + const p = join(dir, n) + let st + try { st = statSync(p) } catch { continue } + let f = d.files.get(n) + if (!f || f.mtime !== st.mtimeMs) { + let j + try { j = JSON.parse(readFileSync(p, "utf8")) } catch { j = null } + if (!j) { d.files.delete(n); return null } // half-written: unknown this time + // a pid of another system's (Claude Code in WSL writing here) can't + // be asked about from this one + const here = !j.pidDomain || j.pidDomain === process.platform + f = { mtime: st.mtimeMs, pid: Number(j.pid), id: String(j.sessionId || ""), here } + d.files.set(n, f) + } + if (f.id && Number.isInteger(f.pid) && f.pid > 0) d.kept = true + } + for (const n of d.files.keys()) if (!seen.has(n)) d.files.delete(n) + if (!d.kept) return null + const ids = new Set() + for (const f of d.files.values()) if (f.id && (!f.here || pidAlive(f.pid))) ids.add(f.id) + return ids + } + return { running } +} + function readerFor(kind, agent) { switch (kind) { case "claude": return (t, id) => readClaude(t, agent, id) @@ -120,6 +177,7 @@ export function createScanner(opts = {}) { const o = { days: 2, max: 40, zstdMax: ZSTD_MAX, zstdEvery: ZSTD_EVERY, ...opts } const files = new Map() // path -> { size, mtime, head, session } let srcs = o.sources || sources() + const procs = o.processes || createProcesses() // one pass: every changed file read again; gives the sessions, latest first function scan(now = Date.now()) { @@ -137,6 +195,7 @@ export function createScanner(opts = {}) { for (const p of files.keys()) if (!live.has(p)) files.delete(p) const out = [] let titles = null + const running = new Map() // a sessions folder, read once a pass for (const f of keep) { let c = files.get(f.path) const changed = !c || c.size !== f.size || c.mtime !== f.mtime @@ -159,7 +218,13 @@ export function createScanner(opts = {}) { const t = titles.get(c.session.id) if (t) c.session.title = t.length > 48 ? t.slice(0, 47) + "…" : t } - out.push(c.session) + const s = c.session + if (f.src.live && MIDTURN.has(s.phase) && now - f.mtime >= GONE_AFTER) { + if (!running.has(f.src.live)) running.set(f.src.live, procs.running(f.src.live)) + const ids = running.get(f.src.live) + if (ids && !ids.has(s.id)) { out.push({ ...s, phase: "aborted", pending: [], gone: true }); continue } + } + out.push(s) } return out } diff --git a/packages/agent-office/package.json b/packages/agent-office/package.json index 031e9c8..0b3a77e 100644 --- a/packages/agent-office/package.json +++ b/packages/agent-office/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/page-agent-office", - "version": "0.1.0", + "version": "0.1.1", "description": "我的 Agent 在干嘛:读取本机 Claude Code、Codex、DeepSeek Harness、Gemini CLI、Qwen Code、Pi、omp、Qoder、WorkBuddy、CodeBuddy 的会话文件(提问、回复与工具命令,可用 text:false 关闭文本),把每个会话画成太空站办公室里的小人(3D/2D)或列表。Live agent activity dashboard for magpie that reads local agent session files.", "type": "module", "files": [ diff --git a/packages/agent-office/page/app.js b/packages/agent-office/page/app.js index 2928676..1a47840 100644 --- a/packages/agent-office/page/app.js +++ b/packages/agent-office/page/app.js @@ -25,6 +25,7 @@ hideAfter: M.HIDE[opts.hideAfter] !== undefined ? opts.hideAfter : M.DEFAULTS.hideAfter, text: opts.text !== false, approvalAfterSec: Number(opts.approvalAfterSec) > 0 ? Number(opts.approvalAfterSec) : M.DEFAULTS.approvalAfterSec, + cleared: opts.cleared && typeof opts.cleared === "object" && !Array.isArray(opts.cleared) ? { ...opts.cleared } : {}, } const state = { snap: null, loaded: false, list: [], open: "", hover: "", showText: true } let floatHome = null @@ -230,7 +231,10 @@ P.copy = el("button", "pc") P.copy.type = "button" P.copy.addEventListener("click", (e) => { e.stopPropagation(); showCommand(P.copy.dataset.value, P.copy) }) - foot.append(P.meta, P.copy) + P.clear = el("button", "pc pclr") + P.clear.type = "button" + P.clear.addEventListener("click", (e) => { e.stopPropagation(); clearAgent(state.open) }) + foot.append(P.meta, P.copy, P.clear) P.src = el("div", "psrc") panel.replaceChildren(head, P.title, P.status, P.query, P.step, P.err, P.reply, foot, P.src) })() @@ -267,9 +271,28 @@ P.copy.dataset.label = a.resume ? w.copyResume : w.copySession P.copy.textContent = P.copy.dataset.label } + P.clear.hidden = !M.clearable(a.status) + setText(P.clear, w.clear) + P.clear.title = w.clearTip setText(P.src, a.source === "files" ? w.fromFiles : w.via) } + // out of the office until its session moves again; kept in the options, + // only for sessions live.js still has + function clearAgent(key) { + const a = state.list.find((x) => x.key === key) + if (!a || !M.clearable(a.status)) return + const now = Date.now() + const known = new Set((snapshot(now)?.sessions || []).map((s) => s?.key)) + const next = {} + for (const [k, at] of Object.entries(view.cleared)) if (known.has(k)) next[k] = at + next[key] = a.at + view.cleared = next + close() + refresh() + save() + } + function open(key) { if (state.open === key) return close() const a = state.list.find((x) => x.key === key) @@ -408,7 +431,7 @@ let saved = JSON.stringify(opts) const textOn = () => $("optText").checked function wanted() { - return { ...opts, mode: view.mode, dim: view.dim, demo: view.demo, showDone: view.showDone, hideAfter: view.hideAfter, text: textOn() } + return { ...opts, mode: view.mode, dim: view.dim, demo: view.demo, showDone: view.showDone, hideAfter: view.hideAfter, text: textOn(), cleared: view.cleared } } function save() { clearTimeout(saving) diff --git a/packages/agent-office/page/model.js b/packages/agent-office/page/model.js index b8b2bd1..eab07a4 100644 --- a/packages/agent-office/page/model.js +++ b/packages/agent-office/page/model.js @@ -27,6 +27,7 @@ floating: "The office has its own window here: move it, reshape it, or ✕ it to put it back", pipOn: "Put it back", ran: "running {n}", via: "seen through magpie's gateway", fromFiles: "from its own session file", live: "live", stale: "Last update {n}", + clear: "Clear", clearTip: "Take it out of the office. It comes back when its session moves again.", }, zh: { title: "我的 Agent 在干嘛", needYou: "需要你", working: "工作中", doneN: "已完成", @@ -46,6 +47,7 @@ floating: "办公室在这里的小窗中:可拖动、可缩放,点 ✕ 放回去", pipOn: "放回去", ran: "已运行 {n}", via: "经 magpie 网关看到", fromFiles: "来自它自己的会话文件", live: "实时", stale: "最近更新 {n}", + clear: "清除", clearTip: "把它移出办公室;会话再有动静时会回来。", }, } // the six the page draws, in the legend's order @@ -106,6 +108,10 @@ } function status(s, now, opts) { return state(s, now, opts).status } + // what the user may clear: an agent not at work. A stuck one (error), a + // stopped or finished one, and one waiting on a process that may be gone. + function clearable(st) { return st === "done" || st === "error" || st === "waiting" } + function ago(ms, lang) { const t = text(lang) const s = Math.max(0, Math.round(ms / 1000)) @@ -153,6 +159,8 @@ function agents(snap, now, opts = {}) { const o = { ...DEFAULTS, ...opts } const hide = HIDE[o.hideAfter] ?? HIDE["6h"] + // { key: at } the user cleared; it stays out until its session moves + const cleared = o.cleared && typeof o.cleared === "object" ? o.cleared : {} const out = [] for (const s of Array.isArray(snap?.sessions) ? snap.sessions : []) { if (!s || typeof s.key !== "string") continue @@ -161,6 +169,8 @@ const quiet = now - at if ((st === "done" || st === "error") && quiet > hide) continue if (st === "done" && !o.showDone) continue + const c = Number(cleared[s.key]) + if (c && at <= c && clearable(st)) continue const b = brand(s.agent) // how long the current step has gone on const since = s.pendingSince ? now - s.pendingSince : quiet @@ -236,5 +246,5 @@ ] } } - globalThis.AgentOfficeModel = { TEXT, STATUSES, COLORS, DEFAULTS, HIDE, STUCK_MS, text, fill, hash, brand, state, status, ago, duration, resume, agents, counts, sorted, demo, merge, redact } + globalThis.AgentOfficeModel = { TEXT, STATUSES, COLORS, DEFAULTS, HIDE, STUCK_MS, text, fill, hash, brand, state, status, clearable, ago, duration, resume, agents, counts, sorted, demo, merge, redact } })() diff --git a/packages/agent-office/test/killed/claude-sigkill.jsonl b/packages/agent-office/test/killed/claude-sigkill.jsonl new file mode 100644 index 0000000..5361998 --- /dev/null +++ b/packages/agent-office/test/killed/claude-sigkill.jsonl @@ -0,0 +1,3 @@ +{"parentUuid":null,"isSidechain":false,"promptId":"a1721c3b-97fc-4dc4-95ca-f70ec0a826b6","type":"user","message":{"role":"user","content":"Use the Bash tool in the foreground (timeout 120000) to run exactly: ping -c 44 -i 1 127.0.0.1 ; then tell me done."},"uuid":"1f46299a-c1da-40c5-9ab4-f88e5f880995","timestamp":"2026-10-31T01:36:32.995Z","permissionMode":"bypassPermissions","promptSource":"sdk","turnOrigin":"sdk","turnPosition":{"promptIndex":0,"turnIndex":1},"userType":"external","entrypoint":"sdk-cli","cwd":"/Users/me/work","sessionId":"a6139a3c-e585-4b7e-8a69-f58fef09c87e","version":"2.1.314","gitBranch":"HEAD"} +{"type":"last-prompt","lastPrompt":"Use the Bash tool in the foreground (timeout 120000) to run exactly: ping -c 44 -i 1 127.0.0.1 ; then tell me done.","leafUuid":"2f9de307-f858-47e8-b9c9-bc959d3ef460","sessionId":"a6139a3c-e585-4b7e-8a69-f58fef09c87e"} +{"parentUuid":"2f9de307-f858-47e8-b9c9-bc959d3ef460","isSidechain":false,"message":{"container":null,"content":[{"caller":{"type":"direct"},"id":"toolu_01NY2TFeatBPJznX59cHZALt","input":{"command":"ping -c 44 -i 1 127.0.0.1","description":"Ping localhost 44 times","timeout":120000},"name":"Bash","type":"tool_use"}],"context_management":null,"diagnostics":null,"id":"msg_011CgZTWj9qMPbnJoe5m25Mx","model":"claude-sonnet-5-5","role":"assistant","stop_details":null,"stop_reason":"tool_use","stop_sequence":null,"type":"message","usage":{"input_tokens":2,"cache_creation_input_tokens":0,"cache_read_input_tokens":16569,"output_tokens":119,"output_tokens_details":{"thinking_tokens":0},"server_tool_use":{"web_search_requests":0,"web_fetch_requests":0},"service_tier":"standard","cache_creation":{"ephemeral_1h_input_tokens":0,"ephemeral_5m_input_tokens":0},"inference_geo":"global","iterations":[{"cache_creation":{"ephemeral_1h_input_tokens":0,"ephemeral_5m_input_tokens":0},"cache_creation_input_tokens":0,"cache_read_input_tokens":16569,"input_tokens":2,"output_tokens":119,"type":"message"}],"speed":"standard","fallback_credit":null}},"wireToolInputs":{"toolu_01NY2TFeatBPJznX59cHZALt":{"command":"ping -c 44 -i 1 127.0.0.1","timeout":120000,"description":"Ping localhost 44 times"}},"apiBlockIndex":0,"requestRef":"239d319e-207b-4c89-927b-d911797bc6bc","requestedModel":"auto/claude-sonnet-5-5","type":"assistant","uuid":"1206ef53-8cd2-45c7-bd92-81e5b5159d5b","timestamp":"2026-10-31T01:36:35.705Z","effort":"medium","perTurnEffort":"medium","userType":"external","entrypoint":"sdk-cli","cwd":"/Users/me/work","sessionId":"a6139a3c-e585-4b7e-8a69-f58fef09c87e","version":"2.1.314","gitBranch":"HEAD"} diff --git a/packages/agent-office/test/killed/claude-sigterm.jsonl b/packages/agent-office/test/killed/claude-sigterm.jsonl new file mode 100644 index 0000000..126a0ec --- /dev/null +++ b/packages/agent-office/test/killed/claude-sigterm.jsonl @@ -0,0 +1,6 @@ +{"parentUuid":null,"isSidechain":false,"promptId":"82e83027-09e9-490b-ad68-ef6bce3a6def","type":"user","message":{"role":"user","content":"Use the Bash tool in the foreground (timeout 120000) to run exactly: ping -c 44 -i 1 127.0.0.1 ; then tell me done."},"uuid":"9018dfeb-2412-4b10-8ff7-481c1d05fe98","timestamp":"2026-10-31T01:36:15.854Z","permissionMode":"bypassPermissions","promptSource":"sdk","turnOrigin":"sdk","turnPosition":{"promptIndex":0,"turnIndex":1},"userType":"external","entrypoint":"sdk-cli","cwd":"/Users/me/work","sessionId":"24b647af-dbc4-404b-a97e-c05d30681179","version":"2.1.314","gitBranch":"HEAD"} +{"type":"last-prompt","lastPrompt":"Use the Bash tool in the foreground (timeout 120000) to run exactly: ping -c 44 -i 1 127.0.0.1 ; then tell me done.","leafUuid":"b349f145-06b6-4516-ae15-f2d6ccfea8ca","sessionId":"24b647af-dbc4-404b-a97e-c05d30681179"} +{"parentUuid":"b349f145-06b6-4516-ae15-f2d6ccfea8ca","isSidechain":false,"message":{"container":null,"content":[{"caller":{"type":"direct"},"id":"toolu_011f5amsGnrgTHSoSLBhB8tr","input":{"command":"ping -c 44 -i 1 127.0.0.1","description":"Ping localhost 44 times","timeout":120000},"name":"Bash","type":"tool_use"}],"context_management":null,"diagnostics":null,"id":"msg_011CgZTVU2iXsCahqB1UknKu","model":"claude-sonnet-5-5","role":"assistant","stop_details":null,"stop_reason":"tool_use","stop_sequence":null,"type":"message","usage":{"input_tokens":2,"cache_creation_input_tokens":3572,"cache_read_input_tokens":12997,"output_tokens":119,"output_tokens_details":{"thinking_tokens":0},"server_tool_use":{"web_search_requests":0,"web_fetch_requests":0},"service_tier":"standard","cache_creation":{"ephemeral_1h_input_tokens":0,"ephemeral_5m_input_tokens":3572},"inference_geo":"global","iterations":[{"cache_creation":{"ephemeral_1h_input_tokens":0,"ephemeral_5m_input_tokens":3572},"cache_creation_input_tokens":3572,"cache_read_input_tokens":12997,"input_tokens":2,"output_tokens":119,"type":"message"}],"speed":"standard","fallback_credit":null}},"wireToolInputs":{"toolu_011f5amsGnrgTHSoSLBhB8tr":{"command":"ping -c 44 -i 1 127.0.0.1","timeout":120000,"description":"Ping localhost 44 times"}},"apiBlockIndex":0,"requestRef":"88e099a4-22bf-4155-a588-5d66d2a979ff","requestedModel":"auto/claude-sonnet-5-5","type":"assistant","uuid":"3c782aee-f625-4130-895f-a8811f1616ea","timestamp":"2026-10-31T01:36:18.634Z","effort":"medium","perTurnEffort":"medium","userType":"external","entrypoint":"sdk-cli","cwd":"/Users/me/work","sessionId":"24b647af-dbc4-404b-a97e-c05d30681179","version":"2.1.314","gitBranch":"HEAD"} +{"type":"last-prompt","lastPrompt":"Use the Bash tool in the foreground (timeout 120000) to run exactly: ping -c 44 -i 1 127.0.0.1 ; then tell me done.","leafUuid":"3c782aee-f625-4130-895f-a8811f1616ea","sessionId":"24b647af-dbc4-404b-a97e-c05d30681179"} +{"parentUuid":"3c782aee-f625-4130-895f-a8811f1616ea","isSidechain":false,"promptId":"82e83027-09e9-490b-ad68-ef6bce3a6def","type":"user","message":{"role":"user","content":[{"type":"tool_result","content":"Exit code 137\nPING 127.0.0.1 (127.0.0.1): 56 data bytes\n64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.059 ms\n64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.064 ms\n64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.058 ms\n64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.086 ms\n64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.072 ms\n64 bytes from 127.0.0.1: icmp_seq=5 ttl=64 time=0.070 ms\n64 bytes from 127.0.0.1: icmp_seq=6 ttl=64 time=0.083 ms\n64 bytes from 127.0.0.1: icmp_seq=7 ttl=64 time=0.083 ms\n64 bytes from 127.0.0.1: icmp_seq=8 ttl=64 time=0.074 ms\n64 bytes from 127.0.0.1: icmp_seq=9 ttl=64 time=0.062 ms\n64 bytes from 127.0.0.1: icmp_seq=10 ttl=64 time=0.067 ms\n64 bytes from 127.0.0.1: icmp_seq=11 ttl=64 time=0.092 ms","is_error":true,"tool_use_id":"toolu_011f5amsGnrgTHSoSLBhB8tr"}]},"uuid":"64ec9fe8-7ce4-4d50-a37d-217d919bfca6","timestamp":"2026-10-31T01:36:30.728Z","toolUseResult":"Error: Exit code 137\nPING 127.0.0.1 (127.0.0.1): 56 data bytes\n64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.059 ms\n64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.064 ms\n64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.058 ms\n64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.086 ms\n64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.072 ms\n64 bytes from 127.0.0.1: icmp_seq=5 ttl=64 time=0.070 ms\n64 bytes from 127.0.0.1: icmp_seq=6 ttl=64 time=0.083 ms\n64 bytes from 127.0.0.1: icmp_seq=7 ttl=64 time=0.083 ms\n64 bytes from 127.0.0.1: icmp_seq=8 ttl=64 time=0.074 ms\n64 bytes from 127.0.0.1: icmp_seq=9 ttl=64 time=0.062 ms\n64 bytes from 127.0.0.1: icmp_seq=10 ttl=64 time=0.067 ms\n64 bytes from 127.0.0.1: icmp_seq=11 ttl=64 time=0.092 ms","sandboxed":false,"sourceToolAssistantUUID":"3c782aee-f625-4130-895f-a8811f1616ea","permissionDecision":{"decision":"accept","source":"config","reasonType":"mode"},"userType":"external","entrypoint":"sdk-cli","cwd":"/Users/me/work","sessionId":"24b647af-dbc4-404b-a97e-c05d30681179","version":"2.1.314","gitBranch":"HEAD"} +{"type":"last-prompt","lastPrompt":"Use the Bash tool in the foreground (timeout 120000) to run exactly: ping -c 44 -i 1 127.0.0.1 ; then tell me done.","leafUuid":"1e3dcfa0-d2e9-4ee5-96c5-e6cd8075996f","sessionId":"24b647af-dbc4-404b-a97e-c05d30681179"} diff --git a/packages/agent-office/test/killed/codex-sigterm.jsonl b/packages/agent-office/test/killed/codex-sigterm.jsonl new file mode 100644 index 0000000..b711141 --- /dev/null +++ b/packages/agent-office/test/killed/codex-sigterm.jsonl @@ -0,0 +1,10 @@ +{"timestamp":"2026-10-31T01:32:32.309Z","ordinal":0,"type":"session_meta","payload":{"session_id":"01a18f96-44ac-7183-8ac9-36432fe6ff0e","id":"01a18f96-44ac-7183-8ac9-36432fe6ff0e","timestamp":"2026-10-31T01:32:32.301Z","cwd":"/Users/me/work","runtime_workspace_roots":["/Users/me/work"],"originator":"codex_exec","cli_version":"0.165.0","source":"exec","thread_source":"user","model_provider":"magpie","base_instructions":{"…":"…"},"history_mode":"paginated","context_window":{"window_id":"01a18f96-44ac-7183-8ac9-36703e26a556"}}} +{"timestamp":"2026-10-31T01:32:32.309Z","ordinal":1,"type":"event_msg","payload":{"type":"task_started","turn_attribution":{"turn_id":"01a18f96-44b3-7203-b1b7-feb222c5161d","turn_trigger":"exec","parent_turn_id":null,"initiating_agent_path":null,"root_turn_id":"01a18f96-44b3-7203-b1b7-feb222c5161d"},"turn_id":"01a18f96-44b3-7203-b1b7-feb222c5161d","root_turn_id":"01a18f96-44b3-7203-b1b7-feb222c5161d","started_at":1793410352,"model_context_window":258400,"collaboration_mode_kind":"default"}} +{"timestamp":"2026-10-31T01:32:32.314Z","ordinal":3,"type":"response_item","payload":{"type":"message","id":"msg_01a18f96-44b9-7c12-9f26-800c832ac44f","role":"user","content":[{"type":"input_text","text":"\n /Users/me/work\n zsh\n 2026-10-31\n Asia/Shanghai\n /Users/me/work\n"}],"internal_chat_message_metadata_passthrough":{"turn_id":"01a18f96-44b3-7203-b1b7-feb222c5161d","create_time":1793410352.313903,"content_item_kinds":["environments.environment_context"],"content_item_metadata":[{"provenance":{"type":"harness","hook":false}}]}}} +{"timestamp":"2026-10-31T01:32:32.314Z","ordinal":6,"type":"event_msg","payload":{"type":"thread_settings_applied","thread_id":"01a18f96-44ac-7183-8ac9-36432fe6ff0e","thread_settings":{"model":"auto/gpt-5.3-codex","model_provider_id":"magpie","approval_policy":"never","approvals_reviewer":"user","permission_profile":{"type":"disabled"},"cwd":"/Users/me/work","runtime_workspace_roots":["/Users/me/work"],"collaboration_mode":{"mode":"default","settings":{"model":"auto/gpt-5.3-codex","reasoning_effort":null,"developer_instructions":null}},"disabled_plugin_ids":[]}}} +{"timestamp":"2026-10-31T01:32:32.316Z","ordinal":7,"type":"response_item","payload":{"type":"message","id":"msg_01a18f96-44bc-72f1-af80-e3e3a7b30c46","role":"user","content":[{"type":"input_text","text":"Run the shell command: sleep 92 ; then tell me done."}],"internal_chat_message_metadata_passthrough":{"turn_id":"01a18f96-44b3-7203-b1b7-feb222c5161d","create_time":1793410352.316088,"content_item_kinds":["user.text"],"content_item_metadata":[{"provenance":{"type":"user"}}]}},"metadata":{"retained_source":{"id":{"message_id":"msg_01a18f96-44bc-72f1-af80-e3e3a7b30c46","turn_id":"01a18f96-44b3-7203-b1b7-feb222c5161d","role":"user"},"revision":"retained_01a18f96-44bc-72f1-af80-e40165b2e33f","complete":true},"client_authored":false,"user_input_order":0,"mcp_attribution":{"status":"none"}}} +{"timestamp":"2026-10-31T01:32:32.316Z","ordinal":8,"type":"event_msg","payload":{"type":"item_completed","thread_id":"01a18f96-44ac-7183-8ac9-36432fe6ff0e","turn_id":"01a18f96-44b3-7203-b1b7-feb222c5161d","item":{"type":"UserMessage","id":"01a18f96-44bc-72f1-af80-e3fbe244e5a4","content":[{"type":"text","text":"Run the shell command: sleep 92 ; then tell me done.","text_elements":[]}]},"started_at_ms":1793410352316,"completed_at_ms":1793410352316}} +{"timestamp":"2026-10-31T01:32:33.873Z","ordinal":9,"type":"event_msg","payload":{"type":"item_completed","thread_id":"01a18f96-44ac-7183-8ac9-36432fe6ff0e","turn_id":"01a18f96-44b3-7203-b1b7-feb222c5161d","item":{"type":"AgentMessage","id":"L6t3olkbFLLNqfZk2RmmogM1o0dYeMBO/EXQCRxaMk3cjaDMkYb0yBqzJStZTxKSO16XMZ0roAT7l7qv9gnUMHQICh3XSulUZpo/qPxY/mGIqBzDW93BJ8ZApVPNaRC6sj8aYPkm8uJp0WusMl+cLOAJyQwuAI9hsaoqGlQcPy3aetQ0eZb4U6/IbgkHD/SBlWlw5TP52XcVeKQG/rZEAMtw3jgSE8VoFMonT6tjvZSN4PdiCzcmWfgipI6FqIDffgzlAPncFZbk33zTP5jUTWXCqxMclEkn1eqkjWPu66EuoCQNBjffgOVYOH9B1On9Kq4jvfxfPg1QvE7Ud6WRNJm/RPE/A5PmQqWjMO1PQ7PMmdYjxFyI3AB7xeXdjtBUgErnMNN5LeDRh4iw+bmB6rl59TG40h+cIxvko0jAGL7NLMk=","content":[{"type":"Text","text":"Got it — I’ll run the sleep command now and report back when it finishes."}],"phase":"commentary"},"started_at_ms":1793410353620,"completed_at_ms":1793410353873}} +{"timestamp":"2026-10-31T01:32:33.874Z","ordinal":10,"type":"response_item","payload":{"type":"message","status":"completed","id":"L6t3olkbFLLNqfZk2RmmogM1o0dYeMBO/EXQCRxaMk3cjaDMkYb0yBqzJStZTxKSO16XMZ0roAT7l7qv9gnUMHQICh3XSulUZpo/qPxY/mGIqBzDW93BJ8ZApVPNaRC6sj8aYPkm8uJp0WusMl+cLOAJyQwuAI9hsaoqGlQcPy3aetQ0eZb4U6/IbgkHD/SBlWlw5TP52XcVeKQG/rZEAMtw3jgSE8VoFMonT6tjvZSN4PdiCzcmWfgipI6FqIDffgzlAPncFZbk33zTP5jUTWXCqxMclEkn1eqkjWPu66EuoCQNBjffgOVYOH9B1On9Kq4jvfxfPg1QvE7Ud6WRNJm/RPE/A5PmQqWjMO1PQ7PMmdYjxFyI3AB7xeXdjtBUgErnMNN5LeDRh4iw+bmB6rl59TG40h+cIxvko0jAGL7NLMk=","role":"assistant","content":[{"type":"output_text","text":"Got it — I’ll run the sleep command now and report back when it finishes.","annotations":[],"logprobs":[]}],"phase":"commentary","internal_chat_message_metadata_passthrough":{"turn_id":"01a18f96-44b3-7203-b1b7-feb222c5161d","content_item_kinds":["unknown"]}},"metadata":{"retained_source":{"id":{"message_id":"L6t3olkbFLLNqfZk2RmmogM1o0dYeMBO/EXQCRxaMk3cjaDMkYb0yBqzJStZTxKSO16XMZ0roAT7l7qv9gnUMHQICh3XSulUZpo/qPxY/mGIqBzDW93BJ8ZApVPNaRC6sj8aYPkm8uJp0WusMl+cLOAJyQwuAI9hsaoqGlQcPy3aetQ0eZb4U6/IbgkHD/SBlWlw5TP52XcVeKQG/rZEAMtw3jgSE8VoFMonT6tjvZSN4PdiCzcmWfgipI6FqIDffgzlAPncFZbk33zTP5jUTWXCqxMclEkn1eqkjWPu66EuoCQNBjffgOVYOH9B1On9Kq4jvfxfPg1QvE7Ud6WRNJm/RPE/A5PmQqWjMO1PQ7PMmdYjxFyI3AB7xeXdjtBUgErnMNN5LeDRh4iw+bmB6rl59TG40h+cIxvko0jAGL7NLMk=","turn_id":"01a18f96-44b3-7203-b1b7-feb222c5161d","role":"assistant"},"revision":"retained_01a18f96-4ad2-7573-ae1f-38bd43ab4727","complete":true},"client_authored":false,"user_input_order":1}} +{"timestamp":"2026-10-31T01:32:34.128Z","ordinal":11,"type":"response_item","payload":{"type":"function_call","status":"completed","id":"w4uzc4xHxEkuf0PBqSUG6MraWrKSyhWILXVKbXR8dnrju+nobcs01+h4f860b65dxurdKunBzn4o8MivCjHDlT3Lp6wbtJCa3vQ6trn6PsdRWLomJLSV8xhCVQdSEs/Cv7a8zaC2sg+PiLZOp7p0KHMBhyfc+iMb1yTz/zZXSJ/romT2gowPsNQwrtQdKKLv6zuVOsmAXJNyj/lTtwmIWji0USLfNmZkNy0+9ki6V/ZEEZYOplZkNEkuhjlb1mQ+5dg6sp0IzG206N5wQtF69YO+uRCNIJgKinxXnIU9rBgiBETpXcS1TyMhK+Ht8JXPK/pUmmpNhwzRULxAaTgWbSjld2uxzB6f35JbAHg2lCowQofH2pyOphnRuWEIH2fp9+Pth285sf3spa9DWiiB3jjZN8594XZonkWtcFKk9pTo3w==","name":"exec_command","arguments":"{\"cmd\":\"sleep 92\",\"yield_time_ms\":95000}","call_id":"call_z2AD1d1jlpzHpGJQpDzmrz1h","internal_chat_message_metadata_passthrough":{"turn_id":"01a18f96-44b3-7203-b1b7-feb222c5161d"}},"metadata":{"client_authored":false,"user_input_order":2}} +{"timestamp":"2026-10-31T01:32:34.135Z","ordinal":12,"type":"token_usage_record","payload":{"thread_id":"01a18f96-44ac-7183-8ac9-36432fe6ff0e","turn_id":"01a18f96-44b3-7203-b1b7-feb222c5161d","session_id":"01a18f96-44ac-7183-8ac9-36432fe6ff0e","root_turn_id":"01a18f96-44b3-7203-b1b7-feb222c5161d","response_id":"z8pEB8S4i4tWPKCku9OQ4wVsp20LF9a+nHHSENz+vLVEylTqTxVn/65bP6mQ9UhPJBrkcfOCTSpY2Uk2wEx1pkDMsWag33Onk/R8QnAxCYVibNXiR7EfbVDGaMIt2pRN8S2v2BZcKOUC7Iak+maA9K6JKUPBZ36ed+vsCazo4ETmFohc9BjbohTO7sh8byWG+I7M3fAljhXAnUQFLq2s7NMpLmn3SrBSBwJbAHo4vMBlMQv6A1OImOzhpDUZQbZvqznshWXlPSp8zY5xyrF8UBmAnHXUYmu39T4oB/Tgrghpeh8jc4LXIDiRN3k5neURXvejLROGUqIUOeUWTkmlzM+u/sefDnM839bLecnile8H9ubvPMxYNkoKj1L+ib0yi/GA/tA7EpIL02aexaY71+UMTpFg9Zh7WWlYbKWAnFGZdJ8m","usage":{"input_tokens":12059,"cached_input_tokens":12032,"cache_write_input_tokens":0,"output_tokens":51,"reasoning_output_tokens":0,"total_tokens":12110},"turn_token_usage":{"input_tokens":12059,"cached_input_tokens":12032,"cache_write_input_tokens":0,"output_tokens":51,"reasoning_output_tokens":0,"total_tokens":12110},"thread_token_usage":{"input_tokens":12059,"cached_input_tokens":12032,"cache_write_input_tokens":0,"output_tokens":51,"reasoning_output_tokens":0,"total_tokens":12110}}}