@parcha/agentrun-import 0.1.0-beta.67 → 0.1.0-beta.68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -3
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/readers/cursor.d.ts +4 -0
- package/dist/readers/cursor.js +307 -0
- package/dist/readers/index.d.ts +1 -0
- package/dist/readers/index.js +2 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @parcha/agentrun-import
|
|
2
2
|
|
|
3
|
-
Reads the coding-agent sessions under a home (Claude Code, Codex, pi, OpenCode, GitHub Copilot CLI) into one Session shape: normalized token
|
|
3
|
+
Reads the coding-agent sessions under a home (Claude Code, Codex, pi, OpenCode, GitHub Copilot CLI, Cursor's CLI) into one Session shape: normalized token
|
|
4
4
|
usage, subagents counted under their parent, and cursors so a second pass reads only what changed. AgentRun's server
|
|
5
5
|
imports past sessions through it.
|
|
6
6
|
|
|
@@ -30,7 +30,7 @@ const sessions = await parseHome(homedir(), { sources: ["claude-code", "codex"]
|
|
|
30
30
|
that does not open, for each session it lists or as itself when it lists none) while the rest are totalled; without
|
|
31
31
|
it, parseHome throws `ReadFailures`. An unreadable file is never taken for an empty one.
|
|
32
32
|
- `env` names where a source keeps its own directory (`CLAUDE_CONFIG_DIR`, `CODEX_HOME`, `COPILOT_HOME`, OpenCode's `XDG_DATA_HOME` and
|
|
33
|
-
`OPENCODE_DB`); without it the home's.
|
|
33
|
+
`OPENCODE_DB`, `CURSOR_CONFIG_DIR` or `XDG_CONFIG_HOME` for Cursor); without it the home's.
|
|
34
34
|
- `threads` reads the files on that many worker threads (default: the cores the process may run on less one, two on
|
|
35
35
|
two, at most 16, and no more than the workers whose heaps, 80 MiB each at the default `workerOldMb`, fit in the memory
|
|
36
36
|
still free (the machine's, page cache counted as free, at most its container's limit) once `readAhead` is set aside;
|
|
@@ -76,7 +76,7 @@ calls at once hold two pools' memory.
|
|
|
76
76
|
## Known answer
|
|
77
77
|
|
|
78
78
|
```sh
|
|
79
|
-
node dist/cli.js <home> [--sources claude-code,codex,pi,opencode,copilot] [--threads N] [--read-ahead BYTES[k|m|g]] --known-answer
|
|
79
|
+
node dist/cli.js <home> [--sources claude-code,codex,pi,opencode,copilot,cursor] [--threads N] [--read-ahead BYTES[k|m|g]] --known-answer
|
|
80
80
|
```
|
|
81
81
|
|
|
82
82
|
One JSONL line per session, sorted by key: `{key, source, tokens: {input, output, cacheRead, cacheWrite, cacheWrite1h},
|
|
@@ -189,6 +189,19 @@ it: zeros, known, never unknown. So:
|
|
|
189
189
|
`history-session-state` folder are not read. A rotated session's tokens still come whole from its last shutdown;
|
|
190
190
|
the requests in its archives are not counted.
|
|
191
191
|
|
|
192
|
+
Cursor's CLI (`cursor-agent`) keeps each chat in a SQLite store of its own, `~/.cursor/chats/<workspace hash>/<agent
|
|
193
|
+
id>/store.db` (an ACP session's under `~/.cursor/acp-sessions/<id>/`), with a `meta.json` beside it. The store is read
|
|
194
|
+
once, whole and read-only, and no cursor is kept: each read reads it all again. A chat's id is its folder's name
|
|
195
|
+
(`cursorSessionId(file)`).
|
|
196
|
+
|
|
197
|
+
Cursor's CLI keeps no token usage on the machine: no tokens, cost or error for a request, and each turn's model only
|
|
198
|
+
encrypted. Its usage is on Cursor's server (tokscale reads it from Cursor's usage CSV export; that is out of scope here).
|
|
199
|
+
So each answer counts as one request of unknown tokens on an unknown model, keyed by Cursor's `requestId` where the
|
|
200
|
+
message names one (a later message of the same request adds to it), else by its message id. A chat's cost is `null`.
|
|
201
|
+
No message has a time of its own, so every turn is at the chat's start (the agent's `createdAt`) and the chat ends at
|
|
202
|
+
`meta.json`'s `updatedAtMs`. The messages are JSON; only their order needs the root blob, a protobuf of which the reader
|
|
203
|
+
reads one field.
|
|
204
|
+
|
|
192
205
|
## Readers
|
|
193
206
|
|
|
194
207
|
A source is a `Reader` in the registry (`READERS`), with the harness that runs what it ran and the name a person reads:
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// The known answer for a home: one JSONL line per session, sorted by key, numbers only (no content, title, directory or
|
|
3
3
|
// path), so two readers of the same home can be compared line for line.
|
|
4
|
-
// node dist/cli.js <home> [--sources claude-code,codex,pi,opencode,copilot] [--threads N] [--read-ahead BYTES] --known-answer
|
|
4
|
+
// node dist/cli.js <home> [--sources claude-code,codex,pi,opencode,copilot,cursor] [--threads N] [--read-ahead BYTES] --known-answer
|
|
5
5
|
// A line: {key, source, tokens: {input, output, cacheRead, cacheWrite, cacheWrite1h}, cost, turns, calls}. key is the
|
|
6
6
|
// sha256 of the session file's path relative to <home>, with "#<session id>" after it for a file of many sessions (an
|
|
7
7
|
// OpenCode database); turns, the person's user messages; calls, model requests (its subagents' with them); cost, USD,
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { type Env, type Locator, type LocatorSize, locatorKey, type OrderKey, ty
|
|
|
7
7
|
export { type FileCursor, type LineSource, lineReader, type ReadContext, type ReadState } from "./lines.js";
|
|
8
8
|
export { HARNESS_OF, READERS, SOURCE_NAMES, SOURCES, type Source } from "./readers/index.js";
|
|
9
9
|
export { copilotSessionId } from "./readers/copilot.js";
|
|
10
|
+
export { cursorSessionId } from "./readers/cursor.js";
|
|
10
11
|
export { childrenOf, inOrder, locatorOf, locatorParent, locatorSize, type Readers, readerOf, readSession, type Session, sessionLocators } from "./read.js";
|
|
11
12
|
export { builtinCatalog, type CalculateCost, type Catalog, catalogOf, type Listed, type ModelCost, type Priced, priceRequests } from "./price.js";
|
|
12
13
|
export { mirroredIn, ownRequests, sessionKey } from "./mirror.js";
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export { locatorKey } from "./reader.js";
|
|
|
6
6
|
export { lineReader } from "./lines.js";
|
|
7
7
|
export { HARNESS_OF, READERS, SOURCE_NAMES, SOURCES } from "./readers/index.js";
|
|
8
8
|
export { copilotSessionId } from "./readers/copilot.js";
|
|
9
|
+
export { cursorSessionId } from "./readers/cursor.js";
|
|
9
10
|
export { childrenOf, inOrder, locatorOf, locatorParent, locatorSize, readerOf, readSession, sessionLocators } from "./read.js";
|
|
10
11
|
export { builtinCatalog, catalogOf, priceRequests } from "./price.js";
|
|
11
12
|
export { mirroredIn, ownRequests, sessionKey } from "./mirror.js";
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
// Cursor's CLI (cursor-agent): each chat a SQLite store of its own, <config>/chats/<md5 of the workspace>/<agent id>/store.db
|
|
2
|
+
// (an ACP session's in <config>/acp-sessions/<id>/store.db), with a meta.json beside it (the workspace, when the chat was
|
|
3
|
+
// made and last written). The store is content-addressed: blobs(id, data), each id the sha256 of its bytes, and
|
|
4
|
+
// meta(key, value), whose key "0" holds the agent's metadata as hex-encoded JSON (its latest root blob, its name, when it
|
|
5
|
+
// was made, the agent it ran under when it is a subagent). The messages are AI SDK messages as JSON blobs; their order is
|
|
6
|
+
// only in the root, a protobuf (rootOf). Cursor keeps no tokens, cost or error of a request here (its usage is on
|
|
7
|
+
// Cursor's server), no model a person can read (each turn's is encrypted, and is never read), nor a message's time: each
|
|
8
|
+
// answer is a request of unknown tokens on an unknown model, and every turn is at the chat's start. A store is read once,
|
|
9
|
+
// whole, read-only: no cursor to go on from. A store no cursor-agent has open is opened immutable, so the read writes
|
|
10
|
+
// no -wal or -shm into Cursor's folder; a writer that comes mid-read fails the read (openDb). An open chat writes its
|
|
11
|
+
// store's write-ahead log, store.db's mtime unchanged until a checkpoint: a chat's size and last write take the log and
|
|
12
|
+
// meta.json with the store (chatStat).
|
|
13
|
+
import { readFile, stat } from "node:fs/promises";
|
|
14
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
15
|
+
import { pathToFileURL } from "node:url";
|
|
16
|
+
import { entries, rememberUser } from "../reader.js";
|
|
17
|
+
import { argsOf, isObject, str, textOf } from "../text.js";
|
|
18
|
+
import { ACTIVE_GAP_MS } from "../types.js";
|
|
19
|
+
/** A chat's id: its folder's name, the agent id Cursor names it by (an ACP session's id). */
|
|
20
|
+
export const cursorSessionId = (file) => basename(dirname(file));
|
|
21
|
+
/** Cursor's config directory: CURSOR_CONFIG_DIR, else XDG_CONFIG_HOME's cursor, else ~/.cursor. */
|
|
22
|
+
const configDir = (home, env) => env.CURSOR_CONFIG_DIR || (env.XDG_CONFIG_HOME ? join(env.XDG_CONFIG_HOME, "cursor") : join(home, ".cursor"));
|
|
23
|
+
/** Each chat's store under `config`: chats/<workspace>/<agent>/store.db and acp-sessions/<id>/store.db. */
|
|
24
|
+
async function storesIn(config) {
|
|
25
|
+
const out = [];
|
|
26
|
+
const chats = join(config, "chats");
|
|
27
|
+
for (const workspace of await entries(chats)) {
|
|
28
|
+
if (!workspace.isDirectory())
|
|
29
|
+
continue;
|
|
30
|
+
for (const agent of await entries(join(chats, workspace.name)))
|
|
31
|
+
if (agent.isDirectory())
|
|
32
|
+
out.push(join(chats, workspace.name, agent.name, "store.db"));
|
|
33
|
+
}
|
|
34
|
+
const acp = join(config, "acp-sessions");
|
|
35
|
+
for (const session of await entries(acp))
|
|
36
|
+
if (session.isDirectory())
|
|
37
|
+
out.push(join(acp, session.name, "store.db"));
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
// Read through a variable: a Bun build bundles node:sqlite as missing, and Node has no bun:sqlite.
|
|
41
|
+
const BUN_SQLITE = "bun:sqlite";
|
|
42
|
+
const NODE_SQLITE = "node:sqlite";
|
|
43
|
+
/** How long a read waits on Cursor's own write (a lock it holds) before it fails, ms. */
|
|
44
|
+
const BUSY_MS = 5000;
|
|
45
|
+
const BUSY_PRAGMA = "PRAGMA busy_timeout = 5000";
|
|
46
|
+
// SQLite's open flags: read-only, and the name a URI (file:…?immutable=1).
|
|
47
|
+
const SQLITE_OPEN_READONLY = 0x01;
|
|
48
|
+
const SQLITE_OPEN_URI = 0x40;
|
|
49
|
+
/** A store's size and last write, and whether a writer has it open: its -wal or -shm beside it. */
|
|
50
|
+
async function storeState(file) {
|
|
51
|
+
const [db, wal, shm] = await Promise.all([file, `${file}-wal`, `${file}-shm`].map((path) => stat(path).catch(() => null)));
|
|
52
|
+
return { size: db?.size, mtimeMs: db?.mtimeMs, open: wal !== null || shm !== null };
|
|
53
|
+
}
|
|
54
|
+
/** `file` opened read-only, waiting BUSY_MS on a lock: with Node's node:sqlite, or Bun's bun:sqlite under Bun (Bun 1.3
|
|
55
|
+
* has no node:sqlite, and its opener takes no timeout: the connection's busy_timeout, which writes nothing). A store
|
|
56
|
+
* no writer has open (no -wal or -shm beside it) is opened immutable (a URI's immutable=1): SQLite's read-only open of
|
|
57
|
+
* a WAL store makes its -wal and -shm and leaves them after close, a write into Cursor's folder that would also make
|
|
58
|
+
* the chat look written to. An immutable open takes no lock, so `changed` looks again after the read: a -wal or -shm
|
|
59
|
+
* now, or the store's size or mtime moved. A store a writer has open is opened read-only, through its locks. */
|
|
60
|
+
async function openDb(file) {
|
|
61
|
+
const before = await storeState(file);
|
|
62
|
+
const immutable = !before.open;
|
|
63
|
+
const uri = pathToFileURL(resolve(file));
|
|
64
|
+
uri.searchParams.set("immutable", "1");
|
|
65
|
+
let query;
|
|
66
|
+
let close;
|
|
67
|
+
if (process.versions.bun) {
|
|
68
|
+
const { Database } = (await import(BUN_SQLITE));
|
|
69
|
+
// bun:sqlite reads a URI only through its flags form, with SQLITE_OPEN_URI.
|
|
70
|
+
const db = immutable ? new Database(uri.href, SQLITE_OPEN_READONLY | SQLITE_OPEN_URI) : new Database(file, { readonly: true });
|
|
71
|
+
db.query(BUSY_PRAGMA).all();
|
|
72
|
+
query = (sql, params) => db.query(sql).all(...params);
|
|
73
|
+
close = () => db.close();
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
const { DatabaseSync } = (await import(NODE_SQLITE));
|
|
77
|
+
const db = new DatabaseSync(immutable ? uri : file, { readOnly: true, timeout: BUSY_MS });
|
|
78
|
+
query = (sql, params) => db.prepare(sql).all(...params);
|
|
79
|
+
close = () => db.close();
|
|
80
|
+
}
|
|
81
|
+
let bytes = 0;
|
|
82
|
+
return {
|
|
83
|
+
all(sql, ...params) {
|
|
84
|
+
const rows = query(sql, params);
|
|
85
|
+
for (const row of rows)
|
|
86
|
+
if (row.data instanceof Uint8Array)
|
|
87
|
+
bytes += row.data.byteLength;
|
|
88
|
+
return rows;
|
|
89
|
+
},
|
|
90
|
+
close,
|
|
91
|
+
read: () => bytes,
|
|
92
|
+
async changed() {
|
|
93
|
+
if (!immutable)
|
|
94
|
+
return false;
|
|
95
|
+
const after = await storeState(file);
|
|
96
|
+
return after.open || after.size !== before.size || after.mtimeMs !== before.mtimeMs;
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/** The ids of a chat's messages, in order: the root's field 1. The root is agent.v1.ConversationStateStructure (as
|
|
101
|
+
* cursor-agent 2026.07.09-a3815c0 declares it), and field 1, root_prompt_messages_json, its repeated message blob ids,
|
|
102
|
+
* each stored as the 32 raw bytes of the blob's sha256. Every other field is passed over by its wire type; nothing is
|
|
103
|
+
* generated from Cursor's schema. A root that is no protobuf throws. */
|
|
104
|
+
function rootOf(bytes) {
|
|
105
|
+
const ids = [];
|
|
106
|
+
let at = 0;
|
|
107
|
+
const varint = () => {
|
|
108
|
+
let value = 0;
|
|
109
|
+
for (let scale = 1;; scale *= 128) {
|
|
110
|
+
if (at >= bytes.length || scale > 2 ** 63)
|
|
111
|
+
throw new Error("not a Cursor chat root: a varint runs past its end");
|
|
112
|
+
const byte = bytes[at++];
|
|
113
|
+
value += (byte & 0x7f) * scale;
|
|
114
|
+
if (byte < 0x80)
|
|
115
|
+
return value;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
while (at < bytes.length) {
|
|
119
|
+
const tag = varint();
|
|
120
|
+
const field = Math.floor(tag / 8);
|
|
121
|
+
const wire = tag % 8;
|
|
122
|
+
if (wire === 0)
|
|
123
|
+
varint();
|
|
124
|
+
else if (wire === 2) {
|
|
125
|
+
const length = varint();
|
|
126
|
+
if (at + length > bytes.length)
|
|
127
|
+
throw new Error("not a Cursor chat root: a field runs past its end");
|
|
128
|
+
if (field === 1 && length === 32)
|
|
129
|
+
ids.push(Buffer.from(bytes.subarray(at, at + length)).toString("hex"));
|
|
130
|
+
at += length;
|
|
131
|
+
}
|
|
132
|
+
else if (wire === 1)
|
|
133
|
+
at += 8;
|
|
134
|
+
else if (wire === 5)
|
|
135
|
+
at += 4;
|
|
136
|
+
else
|
|
137
|
+
throw new Error(`not a Cursor chat root: wire type ${wire}`);
|
|
138
|
+
}
|
|
139
|
+
if (at > bytes.length)
|
|
140
|
+
throw new Error("not a Cursor chat root: a field runs past its end");
|
|
141
|
+
return ids;
|
|
142
|
+
}
|
|
143
|
+
/** The agent's metadata (meta key "0"): hex-encoded JSON, as cursor-agent writes it. */
|
|
144
|
+
function agentOf(db) {
|
|
145
|
+
const value = db.all("SELECT value FROM meta WHERE key = ?", "0")[0]?.value;
|
|
146
|
+
if (typeof value !== "string")
|
|
147
|
+
throw new Error("not a Cursor chat: no agent metadata");
|
|
148
|
+
const parsed = JSON.parse(/^(?:[0-9a-f]{2})+$/i.test(value) ? Buffer.from(value, "hex").toString("utf8") : value);
|
|
149
|
+
if (!isObject(parsed))
|
|
150
|
+
throw new Error("not a Cursor chat: its agent metadata is no object");
|
|
151
|
+
return parsed;
|
|
152
|
+
}
|
|
153
|
+
/** meta.json beside the store: the workspace, and when the chat was made and last written. None when it is not there. */
|
|
154
|
+
async function chatOf(file) {
|
|
155
|
+
try {
|
|
156
|
+
const parsed = JSON.parse(await readFile(join(dirname(file), "meta.json"), "utf8"));
|
|
157
|
+
return isObject(parsed) ? parsed : {};
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
return {};
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const num = (value) => (typeof value === "number" && Number.isFinite(value) ? value : undefined);
|
|
164
|
+
const parts = (content) => (Array.isArray(content) ? content.filter(isObject) : []);
|
|
165
|
+
const cursorOptions = (value) => (isObject(value.providerOptions) && isObject(value.providerOptions.cursor) ? value.providerOptions.cursor : undefined);
|
|
166
|
+
/** One chat's store, read whole. */
|
|
167
|
+
async function readChat(file, { turns: keep = true }) {
|
|
168
|
+
const [db, chat] = [await openDb(file), await chatOf(file)];
|
|
169
|
+
try {
|
|
170
|
+
const agent = agentOf(db);
|
|
171
|
+
const blob = (id) => {
|
|
172
|
+
const data = db.all("SELECT data FROM blobs WHERE id = ?", id)[0]?.data;
|
|
173
|
+
return data instanceof Uint8Array ? data : undefined;
|
|
174
|
+
};
|
|
175
|
+
const rootId = str(agent.latestRootBlobId);
|
|
176
|
+
const root = rootId ? blob(rootId) : undefined;
|
|
177
|
+
const ids = root ? rootOf(root) : [];
|
|
178
|
+
const first = num(agent.createdAt) ?? num(chat.createdAtMs);
|
|
179
|
+
const last = Math.max(num(chat.updatedAtMs) ?? first ?? 0, first ?? 0);
|
|
180
|
+
const at = first ?? last;
|
|
181
|
+
const subagent = isObject(agent.subagentInfo) ? agent.subagentInfo : undefined;
|
|
182
|
+
const name = str(agent.name);
|
|
183
|
+
const session = {
|
|
184
|
+
source: "cursor",
|
|
185
|
+
id: cursorSessionId(file),
|
|
186
|
+
file,
|
|
187
|
+
...(str(chat.cwd) ? { cwd: chat.cwd } : {}),
|
|
188
|
+
...(first !== undefined ? { startedAt: new Date(first).toISOString(), endedAt: new Date(last).toISOString() } : {}),
|
|
189
|
+
state: "completed",
|
|
190
|
+
...(name && name !== "New Agent" ? { sourceTitle: name } : {}),
|
|
191
|
+
child: subagent !== undefined,
|
|
192
|
+
...(subagent && str(subagent.parentAgentId) ? { parent: subagent.parentAgentId } : {}),
|
|
193
|
+
turns: [],
|
|
194
|
+
users: 0,
|
|
195
|
+
activeMs: first !== undefined && last - first <= ACTIVE_GAP_MS ? last - first : 0,
|
|
196
|
+
copies: 0,
|
|
197
|
+
};
|
|
198
|
+
const requests = [];
|
|
199
|
+
/** Each request by its key: Cursor's requestId where the message names one, else the message's id. */
|
|
200
|
+
const byKey = new Map();
|
|
201
|
+
const add = (turn) => {
|
|
202
|
+
rememberUser(session, turn);
|
|
203
|
+
if (keep)
|
|
204
|
+
session.turns.push(turn);
|
|
205
|
+
if (turn.role === "assistant")
|
|
206
|
+
requests.push(turn);
|
|
207
|
+
};
|
|
208
|
+
for (const id of ids) {
|
|
209
|
+
const data = blob(id);
|
|
210
|
+
if (!data)
|
|
211
|
+
continue;
|
|
212
|
+
let message;
|
|
213
|
+
try {
|
|
214
|
+
message = JSON.parse(Buffer.from(data).toString("utf8"));
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
if (!isObject(message))
|
|
220
|
+
continue;
|
|
221
|
+
if (message.role === "user")
|
|
222
|
+
add({ role: "user", text: textOf(message.content), at });
|
|
223
|
+
else if (message.role === "assistant") {
|
|
224
|
+
const content = parts(message.content);
|
|
225
|
+
const calls = content
|
|
226
|
+
.filter((part) => part.type === "tool-call")
|
|
227
|
+
.map((part) => ({ type: "toolCall", id: String(part.toolCallId ?? ""), name: String(part.toolName ?? ""), arguments: keep ? argsOf(part.args) : {} }));
|
|
228
|
+
const text = typeof message.content === "string" ? message.content : content.filter((part) => part.type === "text" && typeof part.text === "string").map((part) => part.text).join("\n");
|
|
229
|
+
const key = str(cursorOptions(message)?.requestId) ?? str(message.id);
|
|
230
|
+
const held = key === undefined ? undefined : byKey.get(key);
|
|
231
|
+
// A later message of a request read already is more of it: its text and calls join the first, which counts once.
|
|
232
|
+
if (held) {
|
|
233
|
+
if (keep && text)
|
|
234
|
+
held.text = held.text ? `${held.text}\n${text}` : text;
|
|
235
|
+
held.calls.push(...calls);
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
const answer = { role: "assistant", text: keep ? text : "", calls, at, ...(key !== undefined ? { key } : {}) };
|
|
239
|
+
if (key !== undefined)
|
|
240
|
+
byKey.set(key, answer);
|
|
241
|
+
add(answer);
|
|
242
|
+
}
|
|
243
|
+
else if (message.role === "tool") {
|
|
244
|
+
const outcome = cursorOptions(message)?.highLevelToolCallResult;
|
|
245
|
+
for (const part of parts(message.content)) {
|
|
246
|
+
if (part.type !== "tool-result")
|
|
247
|
+
continue;
|
|
248
|
+
add({
|
|
249
|
+
role: "toolResult",
|
|
250
|
+
callId: String(part.toolCallId ?? ""),
|
|
251
|
+
name: String(part.toolName ?? ""),
|
|
252
|
+
text: typeof part.result === "string" ? part.result : textOf(part.experimental_content),
|
|
253
|
+
isError: isObject(outcome) && outcome.isError === true,
|
|
254
|
+
at,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (await db.changed())
|
|
260
|
+
throw new Error("Cursor wrote the chat while it was read: read it again");
|
|
261
|
+
return { sessions: [{ locator: { file }, session, requests }], cursor: null, read: db.read(), resumed: false };
|
|
262
|
+
}
|
|
263
|
+
finally {
|
|
264
|
+
db.close();
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/** A chat's size and last write: its store's with its write-ahead log's (an open chat writes store.db-wal, store.db's
|
|
268
|
+
* mtime unchanged until a checkpoint) and meta.json's last write. null: the store is gone. */
|
|
269
|
+
async function chatStat({ file }) {
|
|
270
|
+
const gone = (error) => {
|
|
271
|
+
const code = error.code;
|
|
272
|
+
if (code === "ENOENT" || code === "ENOTDIR")
|
|
273
|
+
return undefined;
|
|
274
|
+
throw error;
|
|
275
|
+
};
|
|
276
|
+
const [db, wal, meta] = await Promise.all([file, `${file}-wal`, join(dirname(file), "meta.json")].map((path) => stat(path).catch(gone)));
|
|
277
|
+
if (!db)
|
|
278
|
+
return null;
|
|
279
|
+
return { bytes: db.size + (wal?.size ?? 0), mtimeMs: Math.max(db.mtimeMs, wal?.mtimeMs ?? 0, meta?.mtimeMs ?? 0) };
|
|
280
|
+
}
|
|
281
|
+
/** The agent a subagent's chat ran under (its metadata's subagentInfo.parentAgentId), from the store's meta row alone,
|
|
282
|
+
* never its messages: what ties a chat over a caller's cap to its run. None for a top chat, or a store that cannot be
|
|
283
|
+
* read. */
|
|
284
|
+
async function parentOf({ file }) {
|
|
285
|
+
let db;
|
|
286
|
+
try {
|
|
287
|
+
db = await openDb(file);
|
|
288
|
+
const info = agentOf(db).subagentInfo;
|
|
289
|
+
return isObject(info) ? str(info.parentAgentId) : undefined;
|
|
290
|
+
}
|
|
291
|
+
catch {
|
|
292
|
+
return undefined;
|
|
293
|
+
}
|
|
294
|
+
finally {
|
|
295
|
+
db?.close();
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
export const cursor = {
|
|
299
|
+
source: "cursor",
|
|
300
|
+
name: "Cursor",
|
|
301
|
+
harness: "cursor",
|
|
302
|
+
discover: async (home, env = {}) => (await storesIn(configDir(home, env))).map((file) => ({ file })),
|
|
303
|
+
read: (locator, _cursor, options = {}) => readChat(locator.file, options),
|
|
304
|
+
idOf: ({ file }) => cursorSessionId(file),
|
|
305
|
+
stat: chatStat,
|
|
306
|
+
parentOf,
|
|
307
|
+
};
|
package/dist/readers/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare const READERS: {
|
|
|
5
5
|
readonly pi: Reader<"pi", import("../lines.js").FileCursor>;
|
|
6
6
|
readonly opencode: Reader<"opencode", import("./opencode.js").OpenCodeCursor>;
|
|
7
7
|
readonly copilot: Reader<"copilot", import("../lines.js").FileCursor>;
|
|
8
|
+
readonly cursor: Reader<"cursor", null>;
|
|
8
9
|
};
|
|
9
10
|
export type Source = keyof typeof READERS;
|
|
10
11
|
export declare const SOURCES: Source[];
|
package/dist/readers/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { claudeCode } from "./claude-code.js";
|
|
|
2
2
|
import { codex } from "./codex.js";
|
|
3
3
|
import { opencode } from "./opencode.js";
|
|
4
4
|
import { copilot } from "./copilot.js";
|
|
5
|
+
import { cursor } from "./cursor.js";
|
|
5
6
|
import { pi } from "./pi.js";
|
|
6
7
|
export const READERS = {
|
|
7
8
|
"claude-code": claudeCode,
|
|
@@ -9,6 +10,7 @@ export const READERS = {
|
|
|
9
10
|
pi,
|
|
10
11
|
opencode,
|
|
11
12
|
copilot,
|
|
13
|
+
cursor,
|
|
12
14
|
};
|
|
13
15
|
export const SOURCES = Object.keys(READERS);
|
|
14
16
|
/** The harness of serve that runs what each source ran. */
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcha/agentrun-import",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
4
|
-
"description": "Reads the coding-agent sessions under a home (Claude Code, Codex, pi, OpenCode, GitHub Copilot CLI) into one Session shape, with normalized token usage, subagents under their parent, byte-offset cursors for re-reads, and per-session totals.",
|
|
3
|
+
"version": "0.1.0-beta.68",
|
|
4
|
+
"description": "Reads the coding-agent sessions under a home (Claude Code, Codex, pi, OpenCode, GitHub Copilot CLI, Cursor) into one Session shape, with normalized token usage, subagents under their parent, byte-offset cursors for re-reads, and per-session totals.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentrun",
|
|
7
7
|
"claude-code",
|
|
8
8
|
"codex",
|
|
9
9
|
"copilot",
|
|
10
10
|
"pi",
|
|
11
|
+
"cursor",
|
|
11
12
|
"opencode",
|
|
12
13
|
"sessions",
|
|
13
14
|
"usage"
|