diff --git a/packages/agent-office/CHANGELOG.md b/packages/agent-office/CHANGELOG.md
index c3cf745..c5a8bd5 100644
--- a/packages/agent-office/CHANGELOG.md
+++ b/packages/agent-office/CHANGELOG.md
@@ -1,5 +1,11 @@
# Changelog
+## 0.3.5 · 2026-11-10
+
+### Added
+
+- Cursor shows in the office: its editor's agent chats as "Cursor" and cursor-agent's as "Cursor CLI", read from `~/.cursor/projects/*/agent-transcripts` (`CURSOR_DATA_DIR`, and cursor-agent's `chats/*/*/meta.json` under `CURSOR_CONFIG_DIR`). What was asked, the tools it calls and its answer show; Cursor's requests go to Cursor's servers, so there are no token counts. The editor writes no end-of-turn line, so its chat counts as done 30 seconds after its last answer. Asked by WaiooT on X.
+
## 0.3.4 · 2026-11-06
### Fixed
diff --git a/packages/agent-office/README.md b/packages/agent-office/README.md
index 859f3ac..51d93be 100644
--- a/packages/agent-office/README.md
+++ b/packages/agent-office/README.md
@@ -65,8 +65,9 @@ bun bin/agent-office.mjs --json # 一次性快照,适合让 Agent 在聊天
| Pi · omp | `~/.pi/agent/sessions/*/*.jsonl`, `~/.omp/agent/sessions/*/*.jsonl`,以及 `~/.omp/profiles/*/agent/sessions` |
| Grok Build | `~/.grok/sessions/*/*/updates.jsonl` + `summary.json` |
| Qoder · WorkBuddy · CodeBuddy | 各自的 `projects/*/*.jsonl`(Claude Code 格式) |
+| Cursor(编辑器 · CLI) | `~/.cursor/projects/*/agent-transcripts/*/*.jsonl`;有 `chats/*/*/meta.json` 的是 Cursor CLI,其余是编辑器 |
-`*_HOME` / `*_CONFIG_DIR` 覆盖变量都支持。Claude 子 Agent、Kimi 子 Agent、Grok 子 Agent 会标为子 Agent,并带父会话;OMP profiles 带 profile 名。其他 Agent(Cursor、OpenCode、Copilot 等)在通过 magpie 的模型工作时,仍会由异步网关钩子看到。
+`*_HOME` / `*_CONFIG_DIR` 覆盖变量都支持。Claude 子 Agent、Kimi 子 Agent、Grok 子 Agent 会标为子 Agent,并带父会话;OMP profiles 带 profile 名。其他 Agent(OpenCode 等)在通过 magpie 的模型工作时,仍会由异步网关钩子看到。
## 状态与办公室
diff --git a/packages/agent-office/cli.test.mjs b/packages/agent-office/cli.test.mjs
index 757923c..72eae39 100644
--- a/packages/agent-office/cli.test.mjs
+++ b/packages/agent-office/cli.test.mjs
@@ -29,7 +29,7 @@ function homeWithSession() {
function envFor(home) {
const cfg = tmp()
const env = { ...process.env, HOME: home, XDG_CONFIG_HOME: cfg, XDG_CACHE_HOME: join(home, ".cache") }
- for (const k of ["CLAUDE_CONFIG_DIR", "CODEX_HOME", "DSH_HOME", "PI_CODING_AGENT_DIR", "OMP_HOME", "OMP_CONFIG_DIR", "KIMI_CODE_HOME", "KIMI_CONFIG_DIR", "GROK_HOME", "GROK_CONFIG_DIR", "COPILOT_HOME", "COPILOT_CONFIG_DIR", "QODER_CONFIG_DIR", "QODERCN_CONFIG_DIR", "WORKBUDDY_CONFIG_DIR", "CODEBUDDY_CONFIG_DIR", "MAGPIE_AGENT_OFFICE_PAGE", "WMAD_OMP_SESSIONS_DIR"]) delete env[k]
+ for (const k of ["CLAUDE_CONFIG_DIR", "CODEX_HOME", "DSH_HOME", "PI_CODING_AGENT_DIR", "OMP_HOME", "OMP_CONFIG_DIR", "KIMI_CODE_HOME", "KIMI_CONFIG_DIR", "GROK_HOME", "GROK_CONFIG_DIR", "COPILOT_HOME", "COPILOT_CONFIG_DIR", "QODER_CONFIG_DIR", "QODERCN_CONFIG_DIR", "WORKBUDDY_CONFIG_DIR", "CODEBUDDY_CONFIG_DIR", "CURSOR_DATA_DIR", "CURSOR_CONFIG_DIR", "MAGPIE_AGENT_OFFICE_PAGE", "WMAD_OMP_SESSIONS_DIR"]) delete env[k]
return env
}
@@ -119,7 +119,7 @@ test("the authenticated standalone page, bridge, live data and JSON options work
try {
const ping = await (await fetch(s.url + "api/ping")).json()
expect(ping.name).toBe("agent-office")
- expect(ping.version).toBe("0.3.4")
+ expect(ping.version).toBe("0.3.5")
const page = await fetch(s.url)
expect(page.status).toBe(200)
expect(await page.text()).toContain('src="_magpie/bridge.js"')
diff --git a/packages/agent-office/clients.test.mjs b/packages/agent-office/clients.test.mjs
index 34572a1..499982b 100644
--- a/packages/agent-office/clients.test.mjs
+++ b/packages/agent-office/clients.test.mjs
@@ -9,7 +9,7 @@ import { mkdirSync, mkdtempSync, rmSync, statSync, utimesSync, writeFileSync } f
import { tmpdir } from "node:os"
import { join } from "node:path"
import { createScanner, sources } from "./lib/scan.mjs"
-import { readClaude, readCodex, readGemini, readGrok, readKimi, MESSAGES_MAX, MESSAGE_TEXT_MAX } from "./lib/readers.mjs"
+import { cursorStamp, cursorTyped, readClaude, readCodex, readCursor, readGemini, readGrok, readKimi, MESSAGES_MAX, MESSAGE_TEXT_MAX } from "./lib/readers.mjs"
const dir = import.meta.dir
const tmps = []
@@ -21,6 +21,7 @@ const ENV_KEYS = [
"OMP_HOME", "OMP_CONFIG_DIR", "KIMI_CODE_HOME", "KIMI_CONFIG_DIR",
"GROK_HOME", "GROK_CONFIG_DIR", "COPILOT_HOME", "COPILOT_CONFIG_DIR",
"QODER_CONFIG_DIR", "QODERCN_CONFIG_DIR", "WORKBUDDY_CONFIG_DIR", "CODEBUDDY_CONFIG_DIR",
+ "CURSOR_DATA_DIR", "CURSOR_CONFIG_DIR", "XDG_CONFIG_HOME",
]
// run fn with exactly the environment given; every agent home is explicit so
@@ -442,3 +443,90 @@ test("Claude counts final usage once for interleaved blocks of the same response
const s = readClaude([row("a", 0, 1), row("b", 5, 2), row("a", 10, 3), row("b", 5, 4)].map(j).join("\n"), "claude", "c", { now: NOW })
expect(s).toMatchObject({ tokensToday: 255, context: 525 })
})
+
+// ---- Cursor ----------------------------------------------------------------
+// The bytes cursor-agent 2026.11 wrote in a sandbox (CURSOR_DATA_DIR and
+// CURSOR_CONFIG_DIR set), one run that read a file and lost its connection
+// and one that answered.
+const CURSOR_TOOL_RUN = [
+ String.raw`{"role":"user","message":{"content":[{"type":"text","text":"Tuesday, Nov 10, 2026, 1:18 PM (UTC+8)\n\nRead a.txt with a tool and tell me its contents in one word.\n"}]}}`,
+ String.raw`{"role":"assistant","message":{"content":[{"type":"tool_use","name":"Read","input":{"path":"/Users/yetone/workspace/projects/magpie-wt/office-cursor-scratch/proj/a.txt"}}]}}`,
+ String.raw`{"role":"assistant","message":{"content":[{"type":"text","text":"hello"}]}}`,
+ String.raw`{"role":"user","message":{"content":[{"type":"text","text":"Your previous response was interrupted. Continue from where you left off."}]}}`,
+ String.raw`{"role":"assistant","message":{"content":[{"type":"text","text":"hello"}]}}`,
+ String.raw`{"type":"turn_ended","status":"error","error":"WritableIterable is closed"}`,
+].join("\n") + "\n"
+const CURSOR_OK_RUN = [
+ String.raw`{"role":"user","message":{"content":[{"type":"text","text":"Tuesday, Nov 10, 2026, 1:19 PM (UTC+8)\n\nSay ok.\n"}]}}`,
+ String.raw`{"role":"assistant","message":{"content":[{"type":"text","text":"ok"}]}}`,
+ String.raw`{"type":"turn_ended","status":"success"}`,
+].join("\n") + "\n"
+const cursorSlug = (p) => p.replace(/[^a-zA-Z0-9]+/g, "-").replace(/^-+|-+$/g, "")
+
+test("Cursor: its timestamp and what was typed", () => {
+ expect(cursorStamp("Tuesday, Nov 10, 2026, 1:19 PM (UTC+8)")).toBe(Date.UTC(2026, 10, 10, 5, 19))
+ expect(cursorStamp("Monday, Dec 1, 2025, 12:05 AM (UTC-5:30)")).toBe(Date.UTC(2025, 11, 1, 5, 35))
+ expect(cursorStamp("no stamp")).toBe(0)
+ expect(cursorTyped("x\n\nSay ok.\n")).toBe("Say ok.")
+ expect(cursorTyped("Your previous response was interrupted. Continue from where you left off.")).toBe("")
+ expect(cursorTyped("OS\nfix the build")).toBe("fix the build")
+})
+
+test("Cursor: cursor-agent's chats show as Cursor CLI, the editor's as Cursor", () => {
+ const h = tmp()
+ const data = join(h, "cursor-data"), cfg = join(h, "cursor-cfg")
+ // a real folder, so the editor's slug reads back to it
+ const work = join(h, "work", "my app")
+ mkdirSync(work, { recursive: true })
+ const proj = cursorSlug("/Users/yetone/workspace/projects/magpie-wt/office-cursor-scratch/proj")
+ const cli1 = "a65e9061-fdc6-4140-a525-9d094cbaf4de", cli2 = "4d66b3de-e655-4cc6-bd00-dacdaf3f1cc3"
+ write(data, `projects/${proj}/agent-transcripts/${cli1}/${cli1}.jsonl`, CURSOR_TOOL_RUN)
+ write(data, `projects/${proj}/agent-transcripts/${cli2}/${cli2}.jsonl`, CURSOR_OK_RUN)
+ write(cfg, `chats/6a5609665901ab1559ed50a9701ee3ec/${cli1}/meta.json`, String.raw`{"schemaVersion":1,"createdAtMs":1794287842143,"hasConversation":true,"updatedAtMs":1794287956524,"cwd":"/Users/yetone/workspace/projects/magpie-wt/office-cursor-scratch/proj"}`)
+ write(cfg, `chats/6a5609665901ab1559ed50a9701ee3ec/${cli2}/meta.json`, String.raw`{"schemaVersion":1,"createdAtMs":1794287971240,"hasConversation":true,"updatedAtMs":1794287983979,"cwd":"/Users/yetone/workspace/projects/magpie-wt/office-cursor-scratch/proj"}`)
+ // the editor: the same lines without turn_ended, and no meta.json
+ const ed = write(data, `projects/${cursorSlug(work)}/agent-transcripts/ed-1/ed-1.jsonl`, CURSOR_OK_RUN.split("\n").slice(0, 2).join("\n") + "\n")
+ const old = write(data, `projects/${cursorSlug(work)}/agent-transcripts/ed-old.jsonl`, CURSOR_TOOL_RUN.split("\n").slice(0, 2).join("\n") + "\n")
+ // a file elsewhere in the folder is not a chat
+ write(data, `projects/${cursorSlug(work)}/agent-transcripts/ed-1/other.jsonl`, CURSOR_OK_RUN)
+
+ withEnv({ HOME: h, CURSOR_DATA_DIR: data, CURSOR_CONFIG_DIR: cfg }, () => {
+ const scan = () => createScanner({ sources: sources().filter((s) => s.kind === "cursor"), days: 2 }).scan(Date.now())
+ let got = scan()
+ const by = (id) => got.find((s) => s.id === id)
+ expect(got.map((s) => s.id).sort()).toEqual([cli2, cli1, "ed-1", "ed-old"].sort())
+
+ const failed = by(cli1)
+ expect(failed).toMatchObject({ agent: "cursor", phase: "error", error: "WritableIterable is closed", turns: 1,
+ cwd: "/Users/yetone/workspace/projects/magpie-wt/office-cursor-scratch/proj", project: "proj",
+ query: "Read a.txt with a tool and tell me its contents in one word.", pending: [] })
+ expect(failed.title.startsWith("Read a.txt with a tool")).toBe(true)
+ expect(failed.messages.map((m) => [m.role, m.text])).toEqual([["user", "Read a.txt with a tool and tell me its contents in one word."], ["tool", "Read"], ["assistant", "hello"], ["assistant", "hello"]])
+ expect(failed.started).toBe(1794287842143)
+ expect(by(cli2)).toMatchObject({ agent: "cursor", phase: "done", query: "Say ok.", reply: "ok" })
+
+ // the editor, written to just now: still at work
+ expect(by("ed-1")).toMatchObject({ agent: "cursor-app", phase: "thinking", reply: "ok", cwd: work, project: "my app" })
+ expect(by("ed-old")).toMatchObject({ agent: "cursor-app", phase: "tool", step: expect.stringContaining("a.txt") })
+
+ // quiet for a minute after its answer: done; a pending tool call is not
+ const ago = (Date.now() - 60e3) / 1000
+ utimesSync(ed, ago, ago)
+ utimesSync(old, ago, ago)
+ got = scan()
+ expect(by("ed-1").phase).toBe("done")
+ expect(by("ed-old").phase).toBe("tool")
+ })
+})
+
+test("Cursor: a chat whose folder is gone is named by its slug", () => {
+ const s = readCursor(CURSOR_OK_RUN.split("\n").slice(0, 2).join("\n"), "x", null, { mtime: 5 })
+ expect(s).toMatchObject({ agent: "cursor-app", phase: "thinking", query: "Say ok." })
+ const h = tmp()
+ const data = join(h, "d")
+ write(data, "projects/Users-nobody-gone-proj-x/agent-transcripts/c1/c1.jsonl", CURSOR_OK_RUN)
+ withEnv({ HOME: h, CURSOR_DATA_DIR: data, CURSOR_CONFIG_DIR: join(h, "c") }, () => {
+ const got = createScanner({ sources: sources().filter((s) => s.kind === "cursor"), days: 2 }).scan(Date.now())
+ expect(got[0]).toMatchObject({ agent: "cursor-app", phase: "done", cwd: "", project: "x" })
+ })
+})
diff --git a/packages/agent-office/lib/readers.mjs b/packages/agent-office/lib/readers.mjs
index f1f23a1..0a769e1 100644
--- a/packages/agent-office/lib/readers.mjs
+++ b/packages/agent-office/lib/readers.mjs
@@ -1,7 +1,7 @@
// What each agent is really doing, read from the session files the agents
// themselves write, as they write them: Claude Code's, Codex's, DeepSeek
// Harness's, Gemini CLI's, Qwen Code's, Pi's and omp's, GitHub Copilot CLI's,
-// Kimi Code's, Grok Build's, and any agent that keeps Claude Code's format
+// Kimi Code's, Grok Build's, Cursor's (editor and CLI), and any agent that keeps Claude Code's format
// (Qoder, WorkBuddy, CodeBuddy). Every agent's own record, whatever model it
// talks to: one that never passes magpie's gateway is seen as well as one
// that does.
@@ -725,10 +725,79 @@ function grokEvents(s, opts) {
}
}
+// ---- Cursor (cursor-agent and the editor's agent) --------------------------
+// /projects//agent-transcripts/
+// /.jsonl (older builds: agent-transcripts/.jsonl). One
+// line a message, {role, message: {content: [{type: "text"|"tool_use", …}]}},
+// with no time of its own and no tool results: the next assistant line is
+// the tool answered. A user line wraps what was typed in , after
+// a ("Tuesday, Nov 10, 2026, 1:18 PM (UTC+8)"). cursor-agent ends
+// each turn with {type: "turn_ended", status: "success"|"error", error}.
+// The requests go to Cursor's servers, which keep the tokens: none here.
+const MONTHS = { jan: 0, feb: 1, mar: 2, apr: 3, may: 4, jun: 5, jul: 6, aug: 7, sep: 8, oct: 9, nov: 10, dec: 11 }
+export function cursorStamp(text) {
+ const m = /[^<]*?([A-Z][a-z]{2})[a-z]* (\d{1,2}), (\d{4}),? (\d{1,2}):(\d{2})(?::(\d{2}))? ?([AP]M)?\s*\((?:UTC|GMT)(?:([+-])(\d{1,2})(?::?(\d{2}))?)?\)/.exec(String(text ?? ""))
+ if (!m) return 0
+ const month = MONTHS[m[1].toLowerCase()]
+ if (month === undefined) return 0
+ let h = Number(m[4]) % (m[7] ? 12 : 24)
+ if (m[7] === "PM") h += 12
+ const off = m[8] ? (m[8] === "-" ? -1 : 1) * (Number(m[9]) * 60 + Number(m[10] || 0)) : 0
+ return Date.UTC(Number(m[3]), month, Number(m[2]), h, Number(m[5]), Number(m[6] || 0)) - off * 60e3
+}
+// what was typed: the blocks, else the words outside Cursor's
+// own tags; "" for a line Cursor wrote itself
+export function cursorTyped(text) {
+ const all = String(text ?? "")
+ const qs = [...all.matchAll(/([\s\S]*?)<\/user_query>/g)].map((m) => m[1].trim()).filter(Boolean)
+ if (qs.length) return qs.join("\n")
+ const rest = all.replace(/<(timestamp|user_info|rules|system_reminder|attached_files|open_and_recently_viewed_files|git_status|project_layout)>[\s\S]*?<\/\1>/g, "").trim()
+ if (rest.startsWith("<") || /^Your previous response was interrupted/.test(rest)) return ""
+ return rest
+}
+function cursorEvents(s, opts) {
+ return (d) => {
+ // the file's own time when this part of it was read: lines carry none
+ const t = opts.at || 0
+ if (d.type === "turn_ended") {
+ s.cursorEnds = true
+ const st = String(d.status || "")
+ if (st === "success") s.phase = "done"
+ else if (st === "error") { s.phase = "error"; s.error = clip(d.error, 160) }
+ else s.phase = "aborted"
+ s.pending = []
+ touch(s, t)
+ return
+ }
+ const m = d.message
+ if (!m || (d.role !== "user" && d.role !== "assistant")) return
+ const blocks = typeof m.content === "string" ? [{ type: "text", text: m.content }] : Array.isArray(m.content) ? m.content : []
+ const txt = blocks.filter((b) => b?.type === "text").map((b) => b.text || "").join("\n")
+ if (d.role === "user") {
+ const at = cursorStamp(txt) || t
+ const typed = cursorTyped(txt)
+ if (typed) { prompted(s, typed, at); s.cursorLast = "user" }
+ else { s.phase = "thinking"; touch(s, at) }
+ return
+ }
+ // an assistant line after a tool call: the call has been answered
+ if (s.pending.length) answered(s, "", t)
+ s.pending = []
+ const said = txt.trim()
+ if (said) { s.reply = clip(said, TEXT_MAX); message(s, "assistant", said, t) }
+ const tools = blocks.filter((b) => b?.type === "tool_use")
+ for (const b of tools) called(s, b.id, b.name, b.input, t)
+ if (!tools.length) s.phase = "thinking"
+ s.cursorLast = tools.length ? "tool" : "text"
+ touch(s, t)
+ }
+}
+
// A reader owns only its live parsing state, bounded text, and usage/dedupe
// indexes. update receives newly appended complete lines, never a replay.
const PROCESSORS = { claude: claudeEvents, codex: codexEvents, dsh: dshEvents,
- gemini: geminiEvents, pi: piEvents, copilot: copilotEvents, kimi: kimiEvents, grok: grokEvents }
+ gemini: geminiEvents, pi: piEvents, copilot: copilotEvents, kimi: kimiEvents, grok: grokEvents,
+ cursor: cursorEvents }
function refreshMetadata(s, kind, meta) {
if (!meta || typeof meta !== "object") return
@@ -751,6 +820,13 @@ function refreshMetadata(s, kind, meta) {
s.subagent = meta.session_kind.startsWith("subagent")
s.parent = s.subagent && meta.parent_session_id ? String(meta.parent_session_id) : ""
}
+ } else if (kind === "cursor") {
+ // cursor-agent's chats///meta.json: the chat is the
+ // CLI's, not the editor's, and it names its folder and title
+ s.agent = "cursor"
+ if (typeof meta.cwd === "string" && meta.cwd) { s.cwd = meta.cwd; s.project = base(meta.cwd) }
+ if (typeof meta.title === "string" && meta.title.trim() && meta.title !== "New Agent") s.title = clip(meta.title.trim(), TITLE_MAX)
+ touch(s, ms(meta.createdAtMs))
}
}
@@ -760,7 +836,7 @@ export function createSessionReader(kind, agent = kind, id = "", opts = {}) {
const session = fresh(agent, id)
// Sidecars describe the current snapshot, not events. Keep their values out
// of parser state so removing them restores facts already read from the log.
- const exposed = kind === "kimi" || kind === "grok" ? fresh(agent, id) : session
+ const exposed = kind === "kimi" || kind === "grok" || kind === "cursor" ? fresh(agent, id) : session
const days = new Map()
BUCKETS.set(session, days)
BUCKETS.set(exposed, days) // cached scans finalize usage on the exposed object
@@ -800,6 +876,8 @@ export function createSessionReader(kind, agent = kind, id = "", opts = {}) {
function update(input, changes = {}) {
const { usage, now } = changes
if (Object.hasOwn(changes, "meta")) metadata = changes.meta
+ // the file's time for this read, for a format whose lines carry none
+ if (changes.mtime) state.at = changes.mtime
for (const d of lines(input)) {
if (kind === "gemini") {
if (d.sessionId && !session.id) session.id = d.sessionId
@@ -850,5 +928,9 @@ export function readGrok(text, id = "", meta = {}, opts = {}) {
return createSessionReader("grok", "grok", id, { ...opts, meta }).update(text)
}
-export const READERS = { claude: readClaude, codex: readCodex, dsh: readDsh, gemini: readGemini, pi: readPi,
+export function readCursor(text, id = "", meta = null, opts = {}) {
+ return createSessionReader("cursor", "cursor-app", id, { ...opts, meta }).update(text, { mtime: opts.mtime })
+}
+
+export const READERS = { cursor: readCursor, claude: readClaude, codex: readCodex, dsh: readDsh, gemini: readGemini, pi: readPi,
copilot: readCopilot, kimi: readKimi, grok: readGrok }
diff --git a/packages/agent-office/lib/scan.mjs b/packages/agent-office/lib/scan.mjs
index 7bfddef..29e495e 100644
--- a/packages/agent-office/lib/scan.mjs
+++ b/packages/agent-office/lib/scan.mjs
@@ -7,7 +7,7 @@ import { createHash } from "node:crypto"
import { homedir } from "node:os"
import { basename, dirname, join } from "node:path"
import { StringDecoder } from "node:string_decoder"
-import { createSessionReader, finalizeUsage, readClaude, readCodex, readCopilot, readDsh, readGemini, readGrok, readKimi, readPi } from "./readers.mjs"
+import { createSessionReader, finalizeUsage, readClaude, readCodex, readCopilot, readCursor, readDsh, readGemini, readGrok, readKimi, readPi } from "./readers.mjs"
const READ_CHUNK = 64 * 1024
const GUARD_BYTES = 64 // bounded prefix/end witnesses catch truncate-and-regrow between ticks
@@ -30,6 +30,9 @@ const RACY_MS = 2500
// ends before a turn-ending event: `claude -p` killed from another agent.
const GONE_AFTER = 10e3
const MIDTURN = new Set(["thinking", "tool", "approval", "ask"])
+// The Cursor editor's transcripts have no end-of-turn line (cursor-agent's
+// do): a chat whose last line is the agent's words, quiet this long, is done.
+const CURSOR_QUIET = 30e3
function env(k) { return (process.env[k] || "").trim() }
function home(...p) { return join(env("HOME") || homedir(), ...p) }
@@ -53,6 +56,71 @@ function ompProfiles(omp) {
return out
}
+// Cursor's CLI config folder, which keeps chats///meta.json:
+// $CURSOR_CONFIG_DIR, else cursor in $XDG_CONFIG_HOME, else ~/.cursor
+function cursorConfig() {
+ if (env("CURSOR_CONFIG_DIR")) return expand(env("CURSOR_CONFIG_DIR"))
+ if (env("XDG_CONFIG_HOME")) return join(expand(env("XDG_CONFIG_HOME")), "cursor")
+ return home(".cursor")
+}
+
+// a Cursor chat's meta.json, which only cursor-agent writes: found by the
+// chat's id under chats/*/, the folders listed again at most every 5s while
+// an id is missing (a chat's meta.json can come a moment after its transcript)
+function cursorMetas(config) {
+ const found = new Map()
+ let listed = 0
+ const missing = join(config, "chats", "-", "-", "meta.json")
+ return (p) => {
+ const id = cursorChat(p)
+ if (found.has(id)) return found.get(id)
+ if (Date.now() - listed >= 5000) {
+ listed = Date.now()
+ let dirs = []
+ try { dirs = readdirSync(join(config, "chats"), { withFileTypes: true }) } catch {}
+ for (const d of dirs) {
+ if (!d.isDirectory()) continue
+ let chats = []
+ try { chats = readdirSync(join(config, "chats", d.name)) } catch { continue }
+ for (const c of chats) if (!found.has(c) && existsSync(join(config, "chats", d.name, c, "meta.json"))) found.set(c, join(config, "chats", d.name, c, "meta.json"))
+ }
+ }
+ return found.get(id) || missing
+ }
+}
+
+// the chat a Cursor transcript is of: /.jsonl or .jsonl
+function cursorChat(p) { return basename(p).replace(/\.jsonl$/, "") }
+
+// A Cursor project folder is the cwd as a slug, every run of characters
+// other than letters and digits one "-" (/Users/me/my app -> Users-me-my-app),
+// which can't be read back alone: it is matched against the folders that
+// exist, a few hundred looked at at most. Remembered per slug.
+const SLUGS = new Map()
+const slugOf = (name) => String(name).replace(/[^a-zA-Z0-9]+/g, "-").replace(/^-+|-+$/g, "")
+export function cursorFolder(slug, root = "/") {
+ if (SLUGS.has(slug)) return SLUGS.get(slug)
+ let budget = 400
+ const find = (dir, rest) => {
+ if (--budget < 0) return ""
+ let names = []
+ try { names = readdirSync(dir, { withFileTypes: true }) } catch { return "" }
+ for (const e of names) {
+ if (!e.isDirectory() && !e.isSymbolicLink()) continue
+ const sl = slugOf(e.name)
+ if (!sl) continue
+ if (rest === sl) return join(dir, e.name)
+ if (rest.startsWith(sl + "-")) { const got = find(join(dir, e.name), rest.slice(sl.length + 1)); if (got) return got }
+ }
+ return ""
+ }
+ // Windows: C-Users-me-x is C:\Users\me\x
+ const drive = process.platform === "win32" && /^[a-zA-Z]-/.test(slug) ? slug[0] + ":\\" : ""
+ const got = drive ? find(drive, slug.slice(2)) : find(root, slug)
+ SLUGS.set(slug, got)
+ return got
+}
+
// where each agent keeps its sessions: { agent, kind, root, depth, match }
// depth: how many folders down from root the files sit
export function sources() {
@@ -69,6 +137,8 @@ export function sources() {
const qodercn = home(".qoder-cn")
const workbuddy = home(".workbuddy")
const codebuddy = home(".codebuddy")
+ const cursorData = agentHome("CURSOR_DATA_DIR", ".cursor")
+ const cursorMeta = cursorMetas(cursorConfig())
const jsonl = (n) => n.endsWith(".jsonl")
const srcs = [
{ agent: "claude", kind: "claude", root: join(claude, "projects"), depth: 1, match: jsonl, live: join(claude, "sessions") },
@@ -88,6 +158,10 @@ export function sources() {
{ 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") },
+ // Cursor: the editor's chats ("cursor-app") and cursor-agent's ("cursor",
+ // told by its meta.json) both write projects//agent-transcripts/
+ { agent: "cursor-app", kind: "cursor", root: join(cursorData, "projects"), depth: 3, match: (n, p) => n.endsWith(".jsonl") && basename(dirname(p)) === n.slice(0, -6) && basename(dirname(dirname(p))) === "agent-transcripts", meta: cursorMeta },
+ { agent: "cursor-app", kind: "cursor", root: join(cursorData, "projects"), depth: 2, match: (n, p) => n.endsWith(".jsonl") && basename(dirname(p)) === "agent-transcripts", meta: cursorMeta },
]
return srcs
}
@@ -274,6 +348,7 @@ function readerFor(kind, agent, src = {}) {
case "copilot": return (t, id, meta, now) => readCopilot(t, id, { now })
case "kimi": return (t, id, meta, now) => readKimi(t, id, meta, { now })
case "grok": return (t, id, meta, now, usage) => readGrok(t, id, meta, { now, usage })
+ case "cursor": return (t, id, meta, now) => readCursor(t, id, meta, { now })
}
}
@@ -283,6 +358,7 @@ function idOf(src, path) {
if (src.kind === "codex") { const m = /-([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?:_[^.]*)?\.jsonl$/i.exec(name); return m ? m[1] : name }
// the session folder names the session: ~/.grok/sessions//
if (src.kind === "grok" || src.kind === "copilot") return basename(dirname(path))
+ if (src.kind === "cursor") return cursorChat(path)
if (src.kind === "kimi") {
const child = basename(dirname(path)) // …//agents//wire.jsonl
const session = basename(dirname(dirname(dirname(path))))
@@ -432,6 +508,10 @@ export function createScanner(opts = {}) {
const ids = running.get(f.src.live)
if (ids && !ids.has(s.id)) { out.push({ ...s, phase: "aborted", pending: [], gone: true }); continue }
}
+ if (f.src.kind === "cursor" && s.agent === "cursor-app" && !s.cursorEnds && s.cursorLast === "text" && s.phase === "thinking" && now - f.mtime >= CURSOR_QUIET) {
+ out.push({ ...s, phase: "done" })
+ continue
+ }
out.push(s)
}
return out
@@ -458,7 +538,7 @@ export function createScanner(opts = {}) {
reader: createSessionReader(f.src.kind, f.src.agent, id, { subagent: !!f.src.subagent }),
cursor: cursor(),
}
- const changes = { now }
+ const changes = { now, mtime: f.mtime }
// Do not retain a whole usage.json snapshot or re-aggregate it on each
// append. The reader keeps its daily totals; re-read only a new revision.
if (!reusable || !sameSidecar(before?.[0], sig[0])) changes.meta = readMeta(f.src, f.path)
@@ -467,7 +547,7 @@ export function createScanner(opts = {}) {
catch (error) {
if (!(error instanceof ExtendedTail) || !reusable) throw error
c = { reader: createSessionReader(f.src.kind, f.src.agent, id, { subagent: !!f.src.subagent }), cursor: cursor() }
- c.reader.update(readAppended(f, c.cursor, readBytes), { meta: readMeta(f.src, f.path), usage: readMeta(f.src, f.path, "usage"), now })
+ c.reader.update(readAppended(f, c.cursor, readBytes), { meta: readMeta(f.src, f.path), usage: readMeta(f.src, f.path, "usage"), now, mtime: f.mtime })
}
Object.assign(c, { size: f.size, mtime: f.mtime, ctime: f.ctime, dev: f.dev, ino: f.ino, birthtime: f.birthtime, decodedAt: now })
c.session = finish({ ...c.reader.session, path: f.path }, f)
@@ -482,6 +562,15 @@ export function createScanner(opts = {}) {
}
if (f.src.kind === "kimi" && s.subagent && !s.parent) s.parent = parentOf(f.src, f.path, s.id)
if (f.src.profile) s.profile = f.src.profile
+ if (f.src.kind === "cursor" && !s.cwd) {
+ // projects//agent-transcripts/[/].jsonl
+ let d = dirname(f.path)
+ if (basename(d) !== "agent-transcripts") d = dirname(d)
+ const slug = basename(dirname(d))
+ const cwd = cursorFolder(slug)
+ if (cwd) { s.cwd = cwd; s.project = basename(cwd) }
+ else s.project = slug.slice(slug.lastIndexOf("-") + 1)
+ }
if (!s.updated) s.updated = f.mtime
// the file's own time: a line being written is the session at work
s.touched = f.mtime
diff --git a/packages/agent-office/office.hooks.mjs b/packages/agent-office/office.hooks.mjs
index 7e8d6b5..a6c0fe7 100644
--- a/packages/agent-office/office.hooks.mjs
+++ b/packages/agent-office/office.hooks.mjs
@@ -3,12 +3,13 @@
//
// 1. Every second and a half it reads the session files the agents write
// themselves — Claude Code's, Codex's, DeepSeek Harness's, Gemini CLI's,
-// Qwen Code's, Pi's, omp's, Qoder's, WorkBuddy's, CodeBuddy's — and so
+// Qwen Code's, Pi's, omp's, Qoder's, WorkBuddy's, CodeBuddy's, Cursor's
+// (its editor and cursor-agent) — and so
// knows what each one is really doing, whatever model it talks to:
// thinking, running a tool, waiting for an approval or an answer, done,
// stopped, failed (lib/scan.mjs, lib/readers.mjs).
// 2. As an asynchronous gateway hook it also sees the requests that pass
-// magpie, so an agent whose files it can't read (Cursor, OpenCode,
+// magpie, so an agent whose files it can't read (OpenCode,
// Copilot, Kimi, …) still shows while it works through magpie
// (lib/track.mjs). It returns no body: no request changes.
//
diff --git a/packages/agent-office/package.json b/packages/agent-office/package.json
index 89fc79f..2b8697d 100644
--- a/packages/agent-office/package.json
+++ b/packages/agent-office/package.json
@@ -1,7 +1,7 @@
{
"name": "@magpie-community/page-agent-office",
- "version": "0.3.4",
- "description": "我的 Agent 在干嘛:读取本机 Claude Code、Codex、Copilot CLI、Kimi Code、DeepSeek Harness、Gemini CLI、Qwen Code、Pi、omp、Qoder、WorkBuddy、CodeBuddy、Grok Build 的会话文件,把每个会话画成真 3D / 等距 / 2D 办公室里的小人,或分组工作台。Live agent activity dashboard for magpie, with a real WebGL office and eleven scenes.",
+ "version": "0.3.5",
+ "description": "我的 Agent 在干嘛:读取本机 Claude Code、Codex、Copilot CLI、Kimi Code、DeepSeek Harness、Gemini CLI、Qwen Code、Pi、omp、Qoder、WorkBuddy、CodeBuddy、Grok Build、Cursor 的会话文件,把每个会话画成真 3D / 等距 / 2D 办公室里的小人,或分组工作台。Live agent activity dashboard for magpie, with a real WebGL office and eleven scenes.",
"type": "module",
"files": [
"page/index.html",
diff --git a/packages/agent-office/page/agents.js b/packages/agent-office/page/agents.js
index 3aa8a69..485430d 100644
--- a/packages/agent-office/page/agents.js
+++ b/packages/agent-office/page/agents.js
@@ -92,6 +92,11 @@ globalThis.AgentOfficeAgents = {
"icon": "cursor.svg",
"color": "#334155"
},
+ "cursor-app": {
+ "name": "Cursor",
+ "icon": "cursor.svg",
+ "color": "#334155"
+ },
"devin": {
"name": "Devin",
"icon": "devin.svg",
diff --git a/packages/agent-office/page/index.html b/packages/agent-office/page/index.html
index 67e8583..610dde6 100644
--- a/packages/agent-office/page/index.html
+++ b/packages/agent-office/page/index.html
@@ -6,7 +6,7 @@
Agent Office
-
+
diff --git a/packages/agent-office/privacy.test.mjs b/packages/agent-office/privacy.test.mjs
index 14b79ea..5461598 100644
--- a/packages/agent-office/privacy.test.mjs
+++ b/packages/agent-office/privacy.test.mjs
@@ -43,7 +43,7 @@ function runHost(spec, options, after = "", where = "xdg") {
const code = `const h = await import(${JSON.stringify(mod + "?privacy=" + Math.random())}); h.start(); ${after} h.stop(); h.write();`
const env = { ...process.env, HOME: home, XDG_CONFIG_HOME: cfg, XDG_CACHE_HOME: join(home, ".cache"), MAGPIE_AGENT_OFFICE_PAGE: out }
// an agent's own home override must not reach the sessions of the real user
- for (const k of ["CLAUDE_CONFIG_DIR", "CODEX_HOME", "DSH_HOME", "PI_CODING_AGENT_DIR", "QODER_CONFIG_DIR", "QODERCN_CONFIG_DIR", "WORKBUDDY_CONFIG_DIR", "CODEBUDDY_CONFIG_DIR", "GROK_HOME", "FACTORY_HOME_OVERRIDE", "CURSOR_CONFIG_DIR", "KIMI_CODE_HOME", "MINIMAX_DATA_DIR", "CLINE_SESSION_DATA_DIR", "CLINE_DATA_DIR", "CLINE_DIR",
+ for (const k of ["CLAUDE_CONFIG_DIR", "CODEX_HOME", "DSH_HOME", "PI_CODING_AGENT_DIR", "QODER_CONFIG_DIR", "QODERCN_CONFIG_DIR", "WORKBUDDY_CONFIG_DIR", "CODEBUDDY_CONFIG_DIR", "CURSOR_DATA_DIR", "GROK_HOME", "FACTORY_HOME_OVERRIDE", "CURSOR_CONFIG_DIR", "KIMI_CODE_HOME", "MINIMAX_DATA_DIR", "CLINE_SESSION_DATA_DIR", "CLINE_DATA_DIR", "CLINE_DIR",
"COPILOT_HOME", "COPILOT_CONFIG_DIR", "KIMI_CODE_HOME", "KIMI_CONFIG_DIR", "GROK_HOME", "GROK_CONFIG_DIR", "OMP_HOME", "WMAD_OMP_SESSIONS_DIR"]) delete env[k]
const r = spawnSync(process.execPath, ["-e", code], { cwd: where === "cwd" ? work : dir, env, encoding: "utf8" })
if (r.status !== 0) throw new Error(`host run failed: ${r.stderr || r.stdout}`)