sessiongraph 1.0.12 → 1.0.14
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 +1 -1
- package/dist/assets/external-links-BmBkCsrt.js +1 -0
- package/dist/assets/index-B1kyvo41.js +175 -0
- package/dist/assets/index-BLM-0yG6.js +1 -0
- package/dist/assets/{index-BS2Voifb.js → index-D4P4hbvc.js} +1 -1
- package/dist/assets/index-Du0_nVjH.css +1 -0
- package/dist/assets/{index-GTrhxXlP.js → index-Kotmn42s.js} +1 -1
- package/dist/assets/publishing-CEvQPkO1.css +1 -0
- package/dist/assets/publishing-D9CqkbeB.js +23 -0
- package/dist/assets/scene-CTHyYtma.js +139 -0
- package/dist/assets/share-Cw1E-ED9.js +7 -0
- package/dist/index.html +2 -2
- package/dist/sources/NOTICE.txt +4 -4
- package/dist-server/cli.mjs +858 -472
- package/dist-server/server.mjs +719 -346
- package/docs/cli.md +16 -0
- package/docs/guide.md +17 -4
- package/docs/import-coverage.md +86 -4
- package/docs/importer-comparison.md +48 -0
- package/docs/session-artifacts-audit.md +176 -0
- package/package.json +7 -7
- package/dist/assets/external-links-D0O8IeG0.js +0 -1
- package/dist/assets/index-CIhs02tq.js +0 -169
- package/dist/assets/index-Vq4WYmzW.js +0 -1
- package/dist/assets/index-cVgPCrFV.css +0 -1
- package/dist/assets/publishing-VJhUmdPH.css +0 -1
- package/dist/assets/publishing-ofssf6d6.js +0 -25
- package/dist/assets/scene-KCDTPCOD.js +0 -139
- package/dist/assets/share-DKeJCFAo.js +0 -7
- package/dist/sources/hindsight.svg +0 -1
- package/dist/sources/lmstudio.svg +0 -1
- package/dist/sources/reasonix.svg +0 -1
- package/dist/sources/trae.svg +0 -1
- package/dist/sources/warp.svg +0 -1
package/dist-server/cli.mjs
CHANGED
|
@@ -80,13 +80,13 @@ var init_common = __esm({
|
|
|
80
80
|
"use strict";
|
|
81
81
|
digest = (value) => createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
|
82
82
|
identity = (source, native) => `${source}:${native}`;
|
|
83
|
-
project = (source,
|
|
84
|
-
blankSession = (source, nativeID,
|
|
83
|
+
project = (source, directory3) => ({ id: identity(source, digest(directory3).slice(0, 24)), name: basename(directory3) || "Global", directory: directory3, worktrees: [] });
|
|
84
|
+
blankSession = (source, nativeID, directory3 = "") => ({
|
|
85
85
|
source,
|
|
86
86
|
nativeID,
|
|
87
87
|
id: identity(source, nativeID),
|
|
88
|
-
projectID: project(source,
|
|
89
|
-
directory:
|
|
88
|
+
projectID: project(source, directory3).id,
|
|
89
|
+
directory: directory3,
|
|
90
90
|
title: "Untitled session",
|
|
91
91
|
created: 0,
|
|
92
92
|
updated: 0,
|
|
@@ -151,9 +151,9 @@ function boundEventPayloads(message2, budget2) {
|
|
|
151
151
|
return [];
|
|
152
152
|
}
|
|
153
153
|
const bounded = { ...event };
|
|
154
|
-
for (const key of ["text", "input", "output", "name", "id", "nativeID", "nativeType", "callID", "parentID"]) {
|
|
154
|
+
for (const key of ["text", "input", "output", "name", "id", "nativeID", "nativeType", "callID", "parentID", "cwd"]) {
|
|
155
155
|
if (bounded[key] === void 0) continue;
|
|
156
|
-
const value = String(bounded[key]), size = key === "text" || key === "output" ? 64e3 : key === "input" ? 32e3 : 512;
|
|
156
|
+
const value = String(bounded[key]), size = key === "text" || key === "output" ? 64e3 : key === "input" ? 32e3 : key === "cwd" ? 4096 : 512;
|
|
157
157
|
bounded[key] = value.slice(0, Math.max(0, Math.min(remaining, size)));
|
|
158
158
|
remaining -= bounded[key].length;
|
|
159
159
|
if (bounded[key].length < value.length) {
|
|
@@ -182,6 +182,14 @@ function blockEvents(message2, content, transform = (v3) => v3) {
|
|
|
182
182
|
return [eventFor(message2, id2, "event", `${part.type || "Unknown"} content`, "This content type is not represented as text.", { ...fields2, partial: true })];
|
|
183
183
|
});
|
|
184
184
|
}
|
|
185
|
+
function userBlockEvents(message2, content, normalize2) {
|
|
186
|
+
const context = [];
|
|
187
|
+
return blockEvents(message2, content, (value) => {
|
|
188
|
+
const text3 = normalize2(value);
|
|
189
|
+
context.push(Boolean(value && !text3));
|
|
190
|
+
return text3 || value;
|
|
191
|
+
}).map((event) => event.kind === "message" && context.shift() ? { ...event, kind: "event", role: "system", name: "Session context", nativeType: "user-context" } : event);
|
|
192
|
+
}
|
|
185
193
|
function normalizedEvents(message2, sessionID) {
|
|
186
194
|
let events = message2.events;
|
|
187
195
|
if (!events) {
|
|
@@ -193,7 +201,7 @@ function normalizedEvents(message2, sessionID) {
|
|
|
193
201
|
}
|
|
194
202
|
const files = message2.files.map((file, i) => eventFor(message2, `file:${i}`, "file_change", file.path, `${file.source} \xB7 ${file.steps} recorded step(s)`, { nativeType: file.source }));
|
|
195
203
|
return [...events, ...files].slice(0, 200).map((event) => {
|
|
196
|
-
const text3 = String(event.text || "").slice(0, 64e3), input = event.input?.slice(0, 32e3),
|
|
204
|
+
const text3 = String(event.text || "").slice(0, 64e3), input = event.input?.slice(0, 32e3), output2 = event.output?.slice(0, 64e3);
|
|
197
205
|
const time3 = messageTime(event.time || 0);
|
|
198
206
|
return {
|
|
199
207
|
...event,
|
|
@@ -210,8 +218,8 @@ function normalizedEvents(message2, sessionID) {
|
|
|
210
218
|
timeSource: time3 ? event.timeSource : "unknown",
|
|
211
219
|
text: text3,
|
|
212
220
|
input,
|
|
213
|
-
output,
|
|
214
|
-
partial: Boolean(event.partial || message2.partial || text3.length < (event.text?.length || 0) || input?.length !== event.input?.length ||
|
|
221
|
+
output: output2,
|
|
222
|
+
partial: Boolean(event.partial || message2.partial || text3.length < (event.text?.length || 0) || input?.length !== event.input?.length || output2?.length !== event.output?.length || events.length + files.length > 200)
|
|
215
223
|
};
|
|
216
224
|
});
|
|
217
225
|
}
|
|
@@ -223,6 +231,167 @@ var init_events = __esm({
|
|
|
223
231
|
}
|
|
224
232
|
});
|
|
225
233
|
|
|
234
|
+
// server/commit-extraction.ts
|
|
235
|
+
import { posix, win32 } from "node:path";
|
|
236
|
+
function executionFields(input, metadata2 = {}) {
|
|
237
|
+
const args = object(input), meta = object(metadata2);
|
|
238
|
+
return { cwd: string(args.workdir ?? args.cwd ?? args.working_directory ?? meta.cwd), exitCode: exitCode(meta.exitCode ?? meta.exit_code ?? meta.exit) };
|
|
239
|
+
}
|
|
240
|
+
function nativeCommit(value) {
|
|
241
|
+
const v3 = object(value), operation2 = v3.kind === "committed" ? "created" : v3.kind === "amended" ? "amended" : v3.kind === "cherry-picked" ? "cherry-picked" : void 0;
|
|
242
|
+
return operation2 && typeof v3.sha === "string" && /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i.test(v3.sha) ? { sha: v3.sha.toLowerCase(), operation: operation2 } : void 0;
|
|
243
|
+
}
|
|
244
|
+
function json(value) {
|
|
245
|
+
try {
|
|
246
|
+
return JSON.parse(value);
|
|
247
|
+
} catch {
|
|
248
|
+
return value;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
function absolute(path) {
|
|
252
|
+
if (!path || /[\0\r\n]/.test(path)) return;
|
|
253
|
+
return posix.isAbsolute(path) ? posix : win32.isAbsolute(path) && /^[a-z]:[\\/]/i.test(path) ? win32 : void 0;
|
|
254
|
+
}
|
|
255
|
+
function directory(path, base) {
|
|
256
|
+
if (!path || /[\0\r\n$`~]/.test(path)) return;
|
|
257
|
+
const flavor = absolute(path) || absolute(base);
|
|
258
|
+
return flavor ? flavor.resolve(base || path, path) : void 0;
|
|
259
|
+
}
|
|
260
|
+
function commands(command) {
|
|
261
|
+
const result = [], words2 = [];
|
|
262
|
+
let word = "", active = false, quote = "";
|
|
263
|
+
const flush = () => {
|
|
264
|
+
if (active) words2.push(word);
|
|
265
|
+
word = "";
|
|
266
|
+
active = false;
|
|
267
|
+
};
|
|
268
|
+
for (let i = 0; i < command.length; i++) {
|
|
269
|
+
const c = command[i];
|
|
270
|
+
if (quote) {
|
|
271
|
+
if (c === quote) {
|
|
272
|
+
quote = "";
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
if (quote === '"' && /[$`\\]/.test(c)) return;
|
|
276
|
+
word += c;
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
if (c === '"' || c === "'") {
|
|
280
|
+
quote = c;
|
|
281
|
+
active = true;
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
if (/[|<>$`(){}\\#\0;\n\r*?\[\]]/.test(c)) return;
|
|
285
|
+
if (c === "&" && command[i + 1] !== "&") return;
|
|
286
|
+
if (c === "&") {
|
|
287
|
+
flush();
|
|
288
|
+
if (!words2.length) return;
|
|
289
|
+
result.push(words2.splice(0));
|
|
290
|
+
i++;
|
|
291
|
+
} else if (/\s/.test(c)) flush();
|
|
292
|
+
else {
|
|
293
|
+
word += c;
|
|
294
|
+
active = true;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (quote) return;
|
|
298
|
+
flush();
|
|
299
|
+
if (!words2.length && result.length) return;
|
|
300
|
+
if (words2.length) result.push(words2);
|
|
301
|
+
return result;
|
|
302
|
+
}
|
|
303
|
+
function invocation(input, cwd2) {
|
|
304
|
+
const value = json(input || ""), args = object(value);
|
|
305
|
+
const command = typeof value === "string" ? value : string(args.command ?? args.cmd);
|
|
306
|
+
const explicit = string(args.workdir ?? args.cwd ?? args.working_directory);
|
|
307
|
+
return { command, cwd: explicit !== void 0 ? directory(explicit) : directory(cwd2) };
|
|
308
|
+
}
|
|
309
|
+
function operation(words2) {
|
|
310
|
+
const [verb, ...args] = words2;
|
|
311
|
+
if (verb === "commit") {
|
|
312
|
+
let amend = false;
|
|
313
|
+
for (let i = 0; i < args.length; i++) {
|
|
314
|
+
const arg = args[i];
|
|
315
|
+
if (["-m", "--message", "-F", "--file", "--author", "--date", "--fixup", "--squash", "-C", "--reuse-message", "-c", "--reedit-message"].includes(arg)) {
|
|
316
|
+
if (++i >= args.length) return;
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
if (/^--(?:message|file|author|date|fixup|squash|reuse-message|reedit-message)=/.test(arg) || /^-m.+/.test(arg)) continue;
|
|
320
|
+
if (arg === "--amend") {
|
|
321
|
+
amend = true;
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
if (["-a", "--all", "--no-edit", "--allow-empty", "--allow-empty-message", "-n", "--no-verify", "-s", "--signoff", "-q", "--quiet", "--no-gpg-sign", "--gpg-sign", "-S"].includes(arg)) continue;
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
return amend ? "amended" : "created";
|
|
328
|
+
}
|
|
329
|
+
if (verb === "cherry-pick" && args.length && args.every((arg) => /^(?:[a-f0-9]{7,64}|-x|--continue)$/i.test(arg))) return "cherry-picked";
|
|
330
|
+
}
|
|
331
|
+
function plan(command, cwd2) {
|
|
332
|
+
const parts = commands(command);
|
|
333
|
+
if (!parts?.length) return;
|
|
334
|
+
let found;
|
|
335
|
+
for (const part of parts) {
|
|
336
|
+
const [program, ...args] = part;
|
|
337
|
+
if (program === "cd" && args.length === 1 && !/^[+-]/.test(args[0]) && !found) {
|
|
338
|
+
cwd2 = directory(args[0], cwd2);
|
|
339
|
+
if (!cwd2) return;
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
if (program !== "git") return;
|
|
343
|
+
let path = cwd2;
|
|
344
|
+
while (args[0] === "-C") {
|
|
345
|
+
args.shift();
|
|
346
|
+
path = directory(args.shift(), path);
|
|
347
|
+
if (!path) return;
|
|
348
|
+
}
|
|
349
|
+
const op = operation(args);
|
|
350
|
+
if (op) {
|
|
351
|
+
if (found || !path) return;
|
|
352
|
+
found = { operation: op, repositoryPath: path, trailing: false };
|
|
353
|
+
} else if (!["add", "push"].includes(args[0]) || args.some((arg) => /^(?:--exec-path|--git-dir|--work-tree|--config-env)/.test(arg))) return;
|
|
354
|
+
else if (found) found.trailing = true;
|
|
355
|
+
}
|
|
356
|
+
return found;
|
|
357
|
+
}
|
|
358
|
+
function output(value) {
|
|
359
|
+
const parsed = json(value || "");
|
|
360
|
+
if (typeof parsed === "string") {
|
|
361
|
+
const code = parsed.match(/(?:^|\n)Process exited with code (-?\d+)\r?\n/);
|
|
362
|
+
return { text: parsed, code: code ? Number(code[1]) : void 0 };
|
|
363
|
+
}
|
|
364
|
+
if (Array.isArray(parsed)) return { text: parsed.filter((p) => p?.type === "text" && typeof p.text === "string").map((p) => p.text).join("\n") };
|
|
365
|
+
const obj = object(parsed);
|
|
366
|
+
return { text: string(obj.stdout) ?? string(obj.output) ?? "", code: exitCode(obj.exit_code ?? obj.exitCode ?? obj.metadata?.exit_code) };
|
|
367
|
+
}
|
|
368
|
+
function extractCommit(call, result) {
|
|
369
|
+
const shell = /^(?:shell|bash|exec_command|shell_command|run_shell_command|terminal|command execution)$/i.test(call.name) || call.nativeType === "command_execution";
|
|
370
|
+
const input = invocation(call.input, call.cwd ?? result.cwd);
|
|
371
|
+
const candidate = Boolean(result.gitCommit || shell && /\bgit\b[\s\S]*\b(?:commit|cherry-pick)\b/.test(input.command || ""));
|
|
372
|
+
if (!candidate) return { candidate: false };
|
|
373
|
+
if (call.partial || result.partial || !input.command || !shell || ["running", "pending"].includes(result.status || "")) return { candidate };
|
|
374
|
+
const parsed = plan(input.command, input.cwd);
|
|
375
|
+
if (!parsed) return { candidate };
|
|
376
|
+
const recorded = output(result.output), code = result.exitCode ?? recorded.code;
|
|
377
|
+
if (code !== void 0 && code !== 0 && !parsed.trailing || result.status === "failed" && !parsed.trailing) return { candidate };
|
|
378
|
+
const summary = [...recorded.text.matchAll(/^\[(?:[^\]\r\n]+ )([a-f0-9]{7,64})\] [^\r\n]*$/gmi)];
|
|
379
|
+
const native = result.gitCommit;
|
|
380
|
+
if (native && native.operation !== parsed.operation) return { candidate };
|
|
381
|
+
const sha = native && native.operation === parsed.operation ? native.sha : summary.length === 1 && (code !== void 0 || ["completed", "failed"].includes(result.status || "")) ? summary[0][1].toLowerCase() : void 0;
|
|
382
|
+
return { candidate, commit: sha ? { sha, repositoryPath: parsed.repositoryPath, operation: parsed.operation } : void 0 };
|
|
383
|
+
}
|
|
384
|
+
var COMMIT_EXTRACTOR_VERSION, object, string, exitCode;
|
|
385
|
+
var init_commit_extraction = __esm({
|
|
386
|
+
"server/commit-extraction.ts"() {
|
|
387
|
+
"use strict";
|
|
388
|
+
COMMIT_EXTRACTOR_VERSION = 1;
|
|
389
|
+
object = (v3) => v3 && typeof v3 === "object" && !Array.isArray(v3) ? v3 : {};
|
|
390
|
+
string = (v3) => typeof v3 === "string" ? v3 : void 0;
|
|
391
|
+
exitCode = (v3) => typeof v3 === "number" && Number.isSafeInteger(v3) ? v3 : void 0;
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
|
|
226
395
|
// server/source-paths.ts
|
|
227
396
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
228
397
|
function withSourcePaths(adapter, configured) {
|
|
@@ -727,7 +896,7 @@ function make6(options) {
|
|
|
727
896
|
};
|
|
728
897
|
const responseError = async (response, descriptor) => {
|
|
729
898
|
if (descriptor.declaredStatuses.includes(response.status))
|
|
730
|
-
throw declared(await
|
|
899
|
+
throw declared(await json2(response));
|
|
731
900
|
try {
|
|
732
901
|
await response.body?.cancel();
|
|
733
902
|
} catch {
|
|
@@ -747,7 +916,7 @@ function make6(options) {
|
|
|
747
916
|
}
|
|
748
917
|
return;
|
|
749
918
|
}
|
|
750
|
-
return await
|
|
919
|
+
return await json2(response);
|
|
751
920
|
};
|
|
752
921
|
const sse2 = (descriptor, requestOptions) => ({
|
|
753
922
|
async *[Symbol.asyncIterator]() {
|
|
@@ -2370,7 +2539,7 @@ function appendQuery(params, key, value) {
|
|
|
2370
2539
|
}
|
|
2371
2540
|
params.append(key, String(value));
|
|
2372
2541
|
}
|
|
2373
|
-
async function
|
|
2542
|
+
async function json2(response) {
|
|
2374
2543
|
if (!isContentType(response, "application/json") && !response.headers.get("content-type")?.includes("+json")) {
|
|
2375
2544
|
try {
|
|
2376
2545
|
await response.body?.cancel();
|
|
@@ -2898,7 +3067,7 @@ var init_service = __esm({
|
|
|
2898
3067
|
}
|
|
2899
3068
|
});
|
|
2900
3069
|
|
|
2901
|
-
// src/playback-tokens.ts
|
|
3070
|
+
// packages/core/src/playback-tokens.ts
|
|
2902
3071
|
function sumRecordedTokens(values) {
|
|
2903
3072
|
if (!values.length || !values.every(validTokenCount)) return null;
|
|
2904
3073
|
const total = values.reduce((sum, value) => sum + value, 0);
|
|
@@ -2906,12 +3075,20 @@ function sumRecordedTokens(values) {
|
|
|
2906
3075
|
}
|
|
2907
3076
|
var validTokenCount;
|
|
2908
3077
|
var init_playback_tokens = __esm({
|
|
2909
|
-
"src/playback-tokens.ts"() {
|
|
3078
|
+
"packages/core/src/playback-tokens.ts"() {
|
|
2910
3079
|
"use strict";
|
|
2911
3080
|
validTokenCount = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
2912
3081
|
}
|
|
2913
3082
|
});
|
|
2914
3083
|
|
|
3084
|
+
// src/playback-tokens.ts
|
|
3085
|
+
var init_playback_tokens2 = __esm({
|
|
3086
|
+
"src/playback-tokens.ts"() {
|
|
3087
|
+
"use strict";
|
|
3088
|
+
init_playback_tokens();
|
|
3089
|
+
}
|
|
3090
|
+
});
|
|
3091
|
+
|
|
2915
3092
|
// server/opencode.ts
|
|
2916
3093
|
import { basename as basename2 } from "node:path";
|
|
2917
3094
|
import { createHash as createHash3 } from "node:crypto";
|
|
@@ -3050,7 +3227,7 @@ var init_opencode = __esm({
|
|
|
3050
3227
|
"use strict";
|
|
3051
3228
|
init_service();
|
|
3052
3229
|
init_config();
|
|
3053
|
-
|
|
3230
|
+
init_playback_tokens2();
|
|
3054
3231
|
}
|
|
3055
3232
|
});
|
|
3056
3233
|
|
|
@@ -3154,7 +3331,7 @@ function opencodeEvents(raw, message2) {
|
|
|
3154
3331
|
else if (part.type === "tool") {
|
|
3155
3332
|
const state2 = part.state || {}, endTime = messageTime(part.time?.completed);
|
|
3156
3333
|
const status2 = state2.status === "error" ? "failed" : state2.status === "streaming" ? "pending" : ["running", "completed"].includes(state2.status) ? state2.status : "unknown";
|
|
3157
|
-
const common = { ...native, callID: part.id, status: status2, endTime };
|
|
3334
|
+
const common = { ...native, callID: part.id, status: status2, endTime, ...executionFields(state2.input, state2.metadata), partial: Boolean(state2.metadata?.truncated) };
|
|
3158
3335
|
events.push(eventFor(message2, `${id2}:call`, "tool_call", part.name || "Tool call", "", { ...common, ...timing, input: eventText(state2.input) }));
|
|
3159
3336
|
if (["completed", "error"].includes(state2.status)) events.push(eventFor(message2, `${id2}:result`, "tool_result", part.name || "Tool result", "", { ...common, role: "tool", ...endTime ? { time: endTime, timeSource: "recorded" } : {}, output: eventText(state2.error ?? state2.content, 64e3) }));
|
|
3160
3337
|
} else events.push(eventFor(message2, id2, "event", `${part.type || "Unknown"} content`, "Unsupported content.", { ...native, ...timing, partial: true }));
|
|
@@ -3169,6 +3346,7 @@ var init_opencode_events = __esm({
|
|
|
3169
3346
|
"use strict";
|
|
3170
3347
|
init_events();
|
|
3171
3348
|
init_activity();
|
|
3349
|
+
init_commit_extraction();
|
|
3172
3350
|
}
|
|
3173
3351
|
});
|
|
3174
3352
|
|
|
@@ -3199,7 +3377,7 @@ var init_opencode2 = __esm({
|
|
|
3199
3377
|
return {
|
|
3200
3378
|
projects: data.projects.map((p) => ({ ...p, id: identity("opencode", p.id) })),
|
|
3201
3379
|
warnings: data.warnings,
|
|
3202
|
-
sessions: data.sessions.map((s) => ({ locator: {}, revision: digest([
|
|
3380
|
+
sessions: data.sessions.map((s) => ({ locator: {}, revision: digest([4, s.updated, s.created, s.directory]), session: {
|
|
3203
3381
|
...s,
|
|
3204
3382
|
source: "opencode",
|
|
3205
3383
|
nativeID: s.id,
|
|
@@ -30516,7 +30694,7 @@ async function metadataState(path) {
|
|
|
30516
30694
|
}
|
|
30517
30695
|
}
|
|
30518
30696
|
async function claudeRevision(path) {
|
|
30519
|
-
return digest([
|
|
30697
|
+
return digest([7, (await state(path)).signature, (await metadataState(path))?.signature]);
|
|
30520
30698
|
}
|
|
30521
30699
|
async function bytes(path, max) {
|
|
30522
30700
|
const before = await state(path);
|
|
@@ -30570,7 +30748,8 @@ async function claudeTranscript(path, revision2) {
|
|
|
30570
30748
|
}
|
|
30571
30749
|
}
|
|
30572
30750
|
if (await claudeRevision(path) !== revision2) throw new Error("Claude transcript changed during import; import again.");
|
|
30573
|
-
const
|
|
30751
|
+
const byID = new Map(entries2.filter((row) => typeof row.uuid === "string").map((row) => [String(row.uuid), row]));
|
|
30752
|
+
const { size, modified } = await state(path), transcript = { entries: entries2, times, byID, partial, size, modified };
|
|
30574
30753
|
cached = { path, revision: revision2, transcript };
|
|
30575
30754
|
return transcript;
|
|
30576
30755
|
}
|
|
@@ -30675,7 +30854,7 @@ async function historyFiles(roots2, match2) {
|
|
|
30675
30854
|
if (limited) warnings.push("History discovery reached its file, directory, or depth limit.");
|
|
30676
30855
|
return { files: [...new Set(files)].sort(), warnings };
|
|
30677
30856
|
}
|
|
30678
|
-
function
|
|
30857
|
+
function json3(value) {
|
|
30679
30858
|
return JSON.parse(value);
|
|
30680
30859
|
}
|
|
30681
30860
|
function jsonLines(value) {
|
|
@@ -30686,7 +30865,7 @@ function jsonLines(value) {
|
|
|
30686
30865
|
if (rows2.length >= MAX_RECORDS) throw new Error("History exceeds the 50,000-record limit.");
|
|
30687
30866
|
if (line.length > 2e6) throw new Error("History contains a record larger than 2 MB.");
|
|
30688
30867
|
try {
|
|
30689
|
-
const row =
|
|
30868
|
+
const row = json3(line);
|
|
30690
30869
|
if (!row || typeof row !== "object" || Array.isArray(row)) partial = true;
|
|
30691
30870
|
else rows2.push(row);
|
|
30692
30871
|
} catch {
|
|
@@ -30804,13 +30983,13 @@ function localFileAdapter(source) {
|
|
|
30804
30983
|
}
|
|
30805
30984
|
};
|
|
30806
30985
|
}
|
|
30807
|
-
var
|
|
30986
|
+
var object2, text2, time, MAX_BYTES2, MAX_RECORDS, MAX_FILES;
|
|
30808
30987
|
var init_local_files = __esm({
|
|
30809
30988
|
"server/adapters/local-files.ts"() {
|
|
30810
30989
|
"use strict";
|
|
30811
30990
|
init_common();
|
|
30812
30991
|
init_compressed();
|
|
30813
|
-
|
|
30992
|
+
object2 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
30814
30993
|
text2 = (value) => typeof value === "string" ? value : "";
|
|
30815
30994
|
time = (value) => {
|
|
30816
30995
|
const n = typeof value === "number" ? value : typeof value === "string" ? /^\d{13}$/.test(value) ? Number(value) : Date.parse(value) : 0;
|
|
@@ -30828,7 +31007,7 @@ function conversationMessage(raw, fallbackID) {
|
|
|
30828
31007
|
const message2 = blankMessage(text2(raw.id) || fallbackID, time(raw.timestamp ?? raw.ts), role);
|
|
30829
31008
|
let content = raw.content;
|
|
30830
31009
|
if (Array.isArray(content)) content = content.map((part) => {
|
|
30831
|
-
const p =
|
|
31010
|
+
const p = object2(part);
|
|
30832
31011
|
return p.type === "toolCall" ? { ...p, type: "tool_use", input: p.arguments } : p.type === "reasoning" ? { ...p, type: "thinking", thinking: p.text } : p;
|
|
30833
31012
|
});
|
|
30834
31013
|
if (raw.role === "thinking") content = [{ type: "thinking", thinking: raw.content }];
|
|
@@ -30849,7 +31028,7 @@ function conversationMessage(raw, fallbackID) {
|
|
|
30849
31028
|
else if (event.kind === "reasoning") addText(message2, event.text, "Assistant");
|
|
30850
31029
|
}
|
|
30851
31030
|
for (const call of Array.isArray(raw.toolCalls) ? raw.toolCalls : []) {
|
|
30852
|
-
const f =
|
|
31031
|
+
const f = object2(call.function);
|
|
30853
31032
|
if (!text2(f.name)) continue;
|
|
30854
31033
|
message2.tools.push(f.name);
|
|
30855
31034
|
message2.events.push(eventFor(message2, `call:${text2(call.id) || message2.events.length}`, "tool_call", f.name, "", { callID: text2(call.id) || void 0, input: eventText(f.arguments), status: "unknown" }));
|
|
@@ -30863,7 +31042,7 @@ function googleMessage(raw, fallbackID) {
|
|
|
30863
31042
|
const parts = Array.isArray(raw.content) ? raw.content : raw.content != null ? [raw.content] : [];
|
|
30864
31043
|
const content = parts.map((part) => {
|
|
30865
31044
|
if (typeof part === "string") return { type: "text", text: part };
|
|
30866
|
-
const p =
|
|
31045
|
+
const p = object2(part);
|
|
30867
31046
|
if (typeof p.text === "string") return p.thought ? { type: "thinking", thinking: p.text } : { type: "text", text: p.text };
|
|
30868
31047
|
if (p.functionCall) return { type: "tool_use", ...p.functionCall, input: p.functionCall.args };
|
|
30869
31048
|
if (p.functionResponse) return { type: "tool_result", tool_use_id: p.functionResponse.id || raw.toolCallId, name: p.functionResponse.name, content: p.functionResponse.response, is_error: p.functionResponse.response?.error != null };
|
|
@@ -30877,7 +31056,7 @@ function successfulEdits(messages, editNames) {
|
|
|
30877
31056
|
if (event.kind === "tool_call" && event.callID) {
|
|
30878
31057
|
let input = {};
|
|
30879
31058
|
try {
|
|
30880
|
-
input =
|
|
31059
|
+
input = object2(JSON.parse(event.input || "{}"));
|
|
30881
31060
|
} catch {
|
|
30882
31061
|
}
|
|
30883
31062
|
calls.set(event.callID, { name: event.name, input });
|
|
@@ -30980,7 +31159,7 @@ function envelopeHistory(path, value) {
|
|
|
30980
31159
|
const header = rows2.find((r) => r.type === "session" || r.type === "session_start" || r.type === "session_startup") || {};
|
|
30981
31160
|
const nativeID = [...nativeIDs][0] || text2(header.id || header.sessionId) || fileID(path);
|
|
30982
31161
|
const messages = rows2.flatMap((r, i) => {
|
|
30983
|
-
const body =
|
|
31162
|
+
const body = object2(r.message), role = body.role || r.role || (["user", "assistant", "system"].includes(r.type) ? r.type : void 0);
|
|
30984
31163
|
const m = message({ ...body, id: text2(r.uuid || r.id) || body.id, role, content: body.content ?? r.content ?? r.text }, `record:${i}`, r.timestamp ?? body.timestamp);
|
|
30985
31164
|
return m ? [m] : [];
|
|
30986
31165
|
});
|
|
@@ -30996,7 +31175,7 @@ function envelopeHistory(path, value) {
|
|
|
30996
31175
|
};
|
|
30997
31176
|
}
|
|
30998
31177
|
function ampHistory(path, files) {
|
|
30999
|
-
const raw =
|
|
31178
|
+
const raw = object2(json3(files.get(path)));
|
|
31000
31179
|
if (!text2(raw.id) || !Array.isArray(raw.messages)) throw new Error("Unsupported Amp thread.");
|
|
31001
31180
|
const messages = raw.messages.flatMap((m, i) => {
|
|
31002
31181
|
const result = message(m, nativeText(m.messageId) || `message:${i}`, m.timestamp ?? m.usage?.timestamp);
|
|
@@ -31005,14 +31184,14 @@ function ampHistory(path, files) {
|
|
|
31005
31184
|
return { nativeID: raw.id, messages, partial: true, session: { created: time(raw.created), title: text2(raw.title), directory: text2(raw.cwd) }, note: "Amp local/exported thread messages. Usage-ledger ranges are not message timestamps. Export-only and missing content remain partial." };
|
|
31006
31185
|
}
|
|
31007
31186
|
function jcodeHistory(path, files) {
|
|
31008
|
-
const raw =
|
|
31187
|
+
const raw = object2(json3(files.get(path)));
|
|
31009
31188
|
if (!text2(raw.id) || !Array.isArray(raw.messages)) throw new Error("Unsupported Jcode session.");
|
|
31010
31189
|
const journal = path.replace(/\.json$/, ".journal.jsonl");
|
|
31011
31190
|
const appended = files.has(journal) ? jsonLines(files.get(journal)) : { rows: [], partial: false };
|
|
31012
31191
|
const records = [...raw.messages];
|
|
31013
31192
|
for (const row of appended.rows) {
|
|
31014
31193
|
if (Array.isArray(row.append_messages)) records.push(...row.append_messages);
|
|
31015
|
-
if (row.meta) Object.assign(raw,
|
|
31194
|
+
if (row.meta) Object.assign(raw, object2(row.meta));
|
|
31016
31195
|
}
|
|
31017
31196
|
const seen = /* @__PURE__ */ new Set();
|
|
31018
31197
|
const messages = records.flatMap((r, i) => {
|
|
@@ -31025,7 +31204,7 @@ function jcodeHistory(path, files) {
|
|
|
31025
31204
|
return { nativeID: raw.id, messages, partial: appended.partial, session: { title: text2(raw.title), directory: text2(raw.working_dir), created: time(raw.created_at), model: text2(raw.model) || "Unknown model", provider: text2(raw.provider_key) }, note: "Jcode session snapshot and append journal; replayed native message IDs count once. Absent message times remain unknown." };
|
|
31026
31205
|
}
|
|
31027
31206
|
function codebuffHistory(path, files, free) {
|
|
31028
|
-
const records =
|
|
31207
|
+
const records = json3(files.get(path));
|
|
31029
31208
|
if (!Array.isArray(records)) throw new Error("Unsupported Codebuff chat.");
|
|
31030
31209
|
const isFree = records.some((m) => text2(m.metadata?.runState?.sessionState?.mainAgentState?.agentType).startsWith("base2-free"));
|
|
31031
31210
|
if (isFree !== free) return;
|
|
@@ -31038,8 +31217,8 @@ function codebuffHistory(path, files, free) {
|
|
|
31038
31217
|
return { nativeID: `${project2}/${chat}`, messages, partial: true, note: "Codebuff/Freebuff persisted chat messages. Freebuff requires a recorded base2-free root-agent marker. Shared storage is attributed once; token counts are not estimated from text." };
|
|
31039
31218
|
}
|
|
31040
31219
|
function vibeHistory(path, files) {
|
|
31041
|
-
const raw =
|
|
31042
|
-
const meta = legacy ?
|
|
31220
|
+
const raw = object2(json3(files.get(path))), legacy = basename4(path) !== "meta.json";
|
|
31221
|
+
const meta = legacy ? object2(raw.metadata) : raw;
|
|
31043
31222
|
const transcript = join6(dirname3(path), "messages.jsonl");
|
|
31044
31223
|
const parsed = files.has(transcript) ? jsonLines(files.get(transcript)) : { rows: [], partial: false };
|
|
31045
31224
|
const records = legacy ? raw.messages : parsed.rows;
|
|
@@ -31066,7 +31245,7 @@ function acpHistory(path, value) {
|
|
|
31066
31245
|
}
|
|
31067
31246
|
};
|
|
31068
31247
|
for (const [i, row] of rows2.entries()) {
|
|
31069
|
-
const p =
|
|
31248
|
+
const p = object2(row.params), u2 = object2(p.update), kind = text2(u2.sessionUpdate);
|
|
31070
31249
|
if (text2(p.sessionId)) ids.add(p.sessionId);
|
|
31071
31250
|
const timestamp = time(p._meta?.agentTimestampMs) || time(row.timestamp);
|
|
31072
31251
|
const role = kind === "user_message_chunk" ? "user" : kind === "agent_message_chunk" ? "assistant" : "";
|
|
@@ -31092,7 +31271,7 @@ function dshHistory(value) {
|
|
|
31092
31271
|
if (!text2(header?.id)) throw new Error("Unsupported DeepSeek Harness session.");
|
|
31093
31272
|
const messages = rows2.flatMap((r, i) => {
|
|
31094
31273
|
if (!["user/message", "assistant/message", "tool/message"].includes(r.type)) return [];
|
|
31095
|
-
const body =
|
|
31274
|
+
const body = object2(r.data?.message);
|
|
31096
31275
|
const m = message({ ...body, role: body.role || r.type.split("/")[0] }, text2(body.id) || `record:${i}`, r.time);
|
|
31097
31276
|
return m ? [m] : [];
|
|
31098
31277
|
});
|
|
@@ -31110,7 +31289,7 @@ var init_harness_formats = __esm({
|
|
|
31110
31289
|
nativeText = (v3) => typeof v3 === "number" && Number.isSafeInteger(v3) ? String(v3) : text2(v3);
|
|
31111
31290
|
seconds = (v3) => typeof v3 === "number" && Number.isFinite(v3) && v3 > 0 ? v3 * 1e3 : time(v3);
|
|
31112
31291
|
fileID = (path) => basename4(path).replace(/\.jsonl(?:\..*)?$|\.json$/, "");
|
|
31113
|
-
sidecar2 = (files, path) =>
|
|
31292
|
+
sidecar2 = (files, path) => object2(files.has(path) ? json3(files.get(path)) : void 0);
|
|
31114
31293
|
roles = ["user", "assistant", "system", "tool", "toolResult", "model"];
|
|
31115
31294
|
}
|
|
31116
31295
|
});
|
|
@@ -31136,16 +31315,16 @@ function withSqliteSnapshot(path, read3, expected, pinned = false) {
|
|
|
31136
31315
|
const retained = copies.get(path);
|
|
31137
31316
|
if (pinned && expected && retained?.revision === expected) return read3(retained.db);
|
|
31138
31317
|
const revision2 = sqliteRevision(path);
|
|
31139
|
-
if (expected && revision2 !== expected) throw new
|
|
31318
|
+
if (expected && revision2 !== expected) throw new SqliteSnapshotChangedError("History database changed during import; import again.");
|
|
31140
31319
|
let copy = copies.get(path);
|
|
31141
31320
|
if (copy?.revision !== revision2) {
|
|
31142
31321
|
close(path);
|
|
31143
31322
|
while (copies.size >= 2) close(copies.keys().next().value);
|
|
31144
|
-
const
|
|
31323
|
+
const directory3 = mkdtempSync(join7(tmpdir(), "sessiongraph-history-"));
|
|
31145
31324
|
let db2;
|
|
31146
31325
|
try {
|
|
31147
|
-
chmodSync2(
|
|
31148
|
-
const destination = join7(
|
|
31326
|
+
chmodSync2(directory3, 448);
|
|
31327
|
+
const destination = join7(directory3, "history.db");
|
|
31149
31328
|
for (const suffix of ["", "-wal"]) {
|
|
31150
31329
|
try {
|
|
31151
31330
|
copyFileSync(path + suffix, destination + suffix, constants4.COPYFILE_FICLONE);
|
|
@@ -31155,34 +31334,36 @@ function withSqliteSnapshot(path, read3, expected, pinned = false) {
|
|
|
31155
31334
|
throw error;
|
|
31156
31335
|
}
|
|
31157
31336
|
}
|
|
31158
|
-
if (sqliteRevision(path) !== revision2) throw new
|
|
31337
|
+
if (sqliteRevision(path) !== revision2) throw new SqliteSnapshotChangedError("History database changed while copying; import again.");
|
|
31159
31338
|
db2 = new DatabaseSync2(destination, { readOnly: true, enableDoubleQuotedStringLiterals: false, allowExtension: false });
|
|
31160
31339
|
db2.exec("PRAGMA query_only=ON; PRAGMA trusted_schema=OFF; PRAGMA busy_timeout=1000; BEGIN;");
|
|
31161
|
-
copy = { revision: revision2, directory:
|
|
31340
|
+
copy = { revision: revision2, directory: directory3, db: db2 };
|
|
31162
31341
|
copies.set(path, copy);
|
|
31163
31342
|
} catch (error) {
|
|
31164
31343
|
try {
|
|
31165
31344
|
db2?.close();
|
|
31166
31345
|
} finally {
|
|
31167
|
-
rmSync2(
|
|
31346
|
+
rmSync2(directory3, { recursive: true, force: true });
|
|
31168
31347
|
}
|
|
31169
31348
|
throw error;
|
|
31170
31349
|
}
|
|
31171
31350
|
}
|
|
31172
31351
|
const result = read3(copy.db);
|
|
31173
|
-
if (!pinned && sqliteRevision(path) !== revision2) throw new
|
|
31352
|
+
if (!pinned && sqliteRevision(path) !== revision2) throw new SqliteSnapshotChangedError("History database changed during reading; import again.");
|
|
31174
31353
|
return result;
|
|
31175
31354
|
}
|
|
31176
31355
|
function hasTable(db2, name) {
|
|
31177
31356
|
const row = db2.prepare("SELECT sql FROM sqlite_master WHERE type='table' AND name=?").get(name);
|
|
31178
31357
|
return typeof row?.sql === "string" && !/CREATE\s+VIRTUAL/i.test(row.sql);
|
|
31179
31358
|
}
|
|
31180
|
-
var copies, close;
|
|
31359
|
+
var copies, SqliteSnapshotChangedError, close;
|
|
31181
31360
|
var init_sqlite_snapshot = __esm({
|
|
31182
31361
|
"server/adapters/sqlite-snapshot.ts"() {
|
|
31183
31362
|
"use strict";
|
|
31184
31363
|
init_common();
|
|
31185
31364
|
copies = /* @__PURE__ */ new Map();
|
|
31365
|
+
SqliteSnapshotChangedError = class extends Error {
|
|
31366
|
+
};
|
|
31186
31367
|
close = (path) => {
|
|
31187
31368
|
const copy = copies.get(path);
|
|
31188
31369
|
if (!copy) return;
|
|
@@ -31271,18 +31452,23 @@ function sqliteHistoryAdapter(source) {
|
|
|
31271
31452
|
let unavailable = false;
|
|
31272
31453
|
for (const path of await source.paths()) {
|
|
31273
31454
|
try {
|
|
31274
|
-
const snapshot2 = sqliteRevision(path), rev = digest([2, source.id, snapshot2]);
|
|
31455
|
+
const snapshot2 = sqliteRevision(path), rev = digest([source.version || 2, source.id, snapshot2]);
|
|
31275
31456
|
let cached2 = metadata2.get(path);
|
|
31276
31457
|
if (!cached2 || cached2.revision !== rev) {
|
|
31277
31458
|
cached2 = withSqliteSnapshot(path, (db2) => {
|
|
31278
31459
|
const table2 = typeof source.table === "string" ? source.table : source.table(db2);
|
|
31279
31460
|
const values2 = rows(db2, table2, source.fields, void 0, source.key, 2e4), found = [];
|
|
31280
31461
|
const blocked2 = [], warnings2 = [];
|
|
31462
|
+
let empty = 0;
|
|
31281
31463
|
for (const row of values2) {
|
|
31282
31464
|
try {
|
|
31283
31465
|
const h3 = parseHistory(source, db2, row, path);
|
|
31284
31466
|
if (!h3) continue;
|
|
31285
|
-
if (source.history !== false && !h3.messages.length)
|
|
31467
|
+
if (source.history !== false && !h3.messages.length) {
|
|
31468
|
+
blocked2.push(identity(source.id, String(row[source.key])));
|
|
31469
|
+
empty++;
|
|
31470
|
+
continue;
|
|
31471
|
+
}
|
|
31286
31472
|
if (!h3.nativeID || h3.nativeID.length > 512) throw new Error("Missing native session identity.");
|
|
31287
31473
|
const created = time(h3.session?.created) || h3.messages.map((m) => time(m.time)).find(Boolean);
|
|
31288
31474
|
if (!created) throw new Error("Session has no recorded creation or message date.");
|
|
@@ -31302,7 +31488,8 @@ function sqliteHistoryAdapter(source) {
|
|
|
31302
31488
|
blocked2.push(identity(source.id, String(row[source.key])));
|
|
31303
31489
|
}
|
|
31304
31490
|
}
|
|
31305
|
-
if (blocked2.length) warnings2.push(`${blocked2.length} ${source.name} sessions had unsupported, undated, missing, or oversized history; saved imports are kept.`);
|
|
31491
|
+
if (blocked2.length > empty) warnings2.push(`${blocked2.length - empty} ${source.name} sessions had unsupported, undated, missing, or oversized history; saved imports are kept.`);
|
|
31492
|
+
if (empty) warnings2.push(`${empty} empty ${source.name} sessions had no saved messages; previous imports are kept.`);
|
|
31306
31493
|
return { revision: rev, candidates: found, blocked: blocked2, warnings: warnings2 };
|
|
31307
31494
|
}, snapshot2);
|
|
31308
31495
|
metadata2.set(path, cached2);
|
|
@@ -31400,7 +31587,7 @@ var init_sqlite_histories = __esm({
|
|
|
31400
31587
|
import { readdir as readdir2, stat } from "node:fs/promises";
|
|
31401
31588
|
import { homedir as homedir5 } from "node:os";
|
|
31402
31589
|
import { join as join8 } from "node:path";
|
|
31403
|
-
function claudeMessages(rows2, candidate, times) {
|
|
31590
|
+
function claudeMessages(rows2, candidate, times, entries2) {
|
|
31404
31591
|
const calls = /* @__PURE__ */ new Map();
|
|
31405
31592
|
return rows2.map((row) => {
|
|
31406
31593
|
const raw = row.message;
|
|
@@ -31425,7 +31612,18 @@ function claudeMessages(rows2, candidate, times) {
|
|
|
31425
31612
|
}
|
|
31426
31613
|
}
|
|
31427
31614
|
}
|
|
31428
|
-
|
|
31615
|
+
const entry = entries2?.get(row.uuid), structured = entry?.tool_use_result ?? entry?.toolUseResult;
|
|
31616
|
+
const results = Array.isArray(raw?.content) ? raw.content.filter((p) => p.type === "tool_result") : [];
|
|
31617
|
+
msg.events = blockEvents(msg, raw?.content).map((event) => {
|
|
31618
|
+
const result = event.kind === "tool_result" && results.length === 1 ? structured : void 0;
|
|
31619
|
+
return {
|
|
31620
|
+
...event,
|
|
31621
|
+
parentID: row.parent_tool_use_id || void 0,
|
|
31622
|
+
...executionFields({}, { ...result, cwd: entry?.cwd }),
|
|
31623
|
+
gitCommit: nativeCommit(result?.gitOperation?.commit),
|
|
31624
|
+
partial: Boolean(event.partial || result?.interrupted || result?.backgroundTaskId || result?.backgroundedByUser || result?.timedOutAfterMs || entry?.sessionId && entry.sessionId !== (candidate.locator.parent || candidate.session.nativeID))
|
|
31625
|
+
};
|
|
31626
|
+
});
|
|
31429
31627
|
if (!msg.events.length) msg.events = [eventFor(msg, "event", raw?.subtype === "compact_boundary" ? "compaction" : "event", raw?.subtype || `${row.type} event`, eventText(raw), { nativeType: raw?.subtype || row.type, partial: true })];
|
|
31430
31628
|
return msg;
|
|
31431
31629
|
});
|
|
@@ -31442,6 +31640,7 @@ var init_claude = __esm({
|
|
|
31442
31640
|
init_harness_formats();
|
|
31443
31641
|
init_sqlite_histories();
|
|
31444
31642
|
init_source_paths();
|
|
31643
|
+
init_commit_extraction();
|
|
31445
31644
|
root = () => join8(sourcePath("claude-code") || process.env.CLAUDE_CONFIG_DIR || join8(homedir5(), ".claude"), "projects");
|
|
31446
31645
|
sdkClaudeAdapter = {
|
|
31447
31646
|
id: "claude-code",
|
|
@@ -31539,7 +31738,7 @@ var init_claude = __esm({
|
|
|
31539
31738
|
const options = { dir: candidate.locator.dir || void 0, offset: start, limit: count + 1, sessionStore: claudeTranscriptStore(transcript, sessionId, candidate.locator.agent) };
|
|
31540
31739
|
const rows2 = candidate.locator.parent ? await U1t(candidate.locator.parent, candidate.locator.agent, options) : await P1t(candidate.session.nativeID, options);
|
|
31541
31740
|
const more = rows2.length > count;
|
|
31542
|
-
const messages = claudeMessages(rows2.slice(0, count), candidate, transcript.times).slice(offset - start);
|
|
31741
|
+
const messages = claudeMessages(rows2.slice(0, count), candidate, transcript.times, transcript.byID).slice(offset - start);
|
|
31543
31742
|
if (!offset && !messages.length && transcript.size > 100) throw new Error("SDK returned no readable conversation for this transcript.");
|
|
31544
31743
|
if (!more && await claudeRevision(candidate.locator.path) !== candidate.revision) throw new Error("Session changed during import; import again to capture the latest messages.");
|
|
31545
31744
|
return { messages, cursor: more ? String(offset + 120) : void 0, partial: transcript.partial, note: `SDK-visible conversation chain from the local CLI/VS Code transcript; pre-compaction text and unsupported message types may be absent. Fork ancestry is unavailable.${transcript.partial ? " Some transcript records or subagent metadata were unreadable." : ""}` };
|
|
@@ -31669,9 +31868,14 @@ function changedPaths(value) {
|
|
|
31669
31868
|
function codexUserText(value) {
|
|
31670
31869
|
if (typeof value !== "string") return "";
|
|
31671
31870
|
let text3 = value.trim();
|
|
31871
|
+
for (; ; ) {
|
|
31872
|
+
const context = text3.match(/^<(environment_context|permissions|user_instructions|turn_aborted|system_instruction|recommended_plugins|external_codex_[\w-]+)(?:\s[^>]*)?>/i);
|
|
31873
|
+
if (!context) break;
|
|
31874
|
+
const end = text3.toLowerCase().indexOf(`</${context[1].toLowerCase()}>`, context[0].length);
|
|
31875
|
+
if (end < 0) return "";
|
|
31876
|
+
text3 = text3.slice(end + context[1].length + 3).trim();
|
|
31877
|
+
}
|
|
31672
31878
|
if (/^# (?:AGENTS\.md|Instructions for)/i.test(text3)) return "";
|
|
31673
|
-
text3 = text3.replace(/<(environment_context|permissions|user_instructions|turn_aborted|external_codex_[\w-]+)>[\s\S]*?<\/\1>/g, "").trim();
|
|
31674
|
-
if (/^<(?:environment_context|permissions|user_instructions|turn_aborted|external_codex_[\w-]+)(?:>|\s)/.test(text3)) return "";
|
|
31675
31879
|
return text3;
|
|
31676
31880
|
}
|
|
31677
31881
|
async function sessionNames() {
|
|
@@ -31692,6 +31896,7 @@ async function sessionNames() {
|
|
|
31692
31896
|
function codexRecord(raw, offset, candidate) {
|
|
31693
31897
|
const p = raw.payload;
|
|
31694
31898
|
if (!p || typeof p !== "object") return;
|
|
31899
|
+
if (raw.type === "session_meta" || raw.type === "turn_context") candidate.locator.executionCwd = typeof p.cwd === "string" ? p.cwd : "";
|
|
31695
31900
|
if (raw.type === "turn_context" && typeof p.model === "string") candidate.session.model = p.model;
|
|
31696
31901
|
if (raw.type === "event_msg" && p.type === "item_completed" && ["FileChange", "fileChange"].includes(p.item?.type)) {
|
|
31697
31902
|
const msg2 = blankMessage(`event:${p.item.id || raw.ordinal || offset}`, p.completed_at_ms || Date.parse(raw.timestamp) || 0, "tool");
|
|
@@ -31723,9 +31928,15 @@ function codexRecord(raw, offset, candidate) {
|
|
|
31723
31928
|
}
|
|
31724
31929
|
const role = p.role === "user" ? "user" : p.role === "assistant" ? "assistant" : p.type === "message" ? "system" : "tool";
|
|
31725
31930
|
const msg = blankMessage(`item:${raw.ordinal ?? offset}`, Date.parse(raw.timestamp) || 0, role);
|
|
31726
|
-
|
|
31727
|
-
|
|
31728
|
-
|
|
31931
|
+
let input = p.arguments ?? p.input;
|
|
31932
|
+
if (typeof input === "string") {
|
|
31933
|
+
try {
|
|
31934
|
+
input = JSON.parse(input);
|
|
31935
|
+
} catch {
|
|
31936
|
+
}
|
|
31937
|
+
}
|
|
31938
|
+
const fields2 = { nativeID: p.id, nativeType: p.type, callID: p.call_id, ...executionFields(input, { cwd: candidate.locator.executionCwd }) };
|
|
31939
|
+
msg.events = p.type === "message" ? role === "user" ? userBlockEvents(msg, p.content, codexUserText) : blockEvents(msg, p.content) : ["function_call", "custom_tool_call"].includes(p.type) ? [eventFor(msg, "call", "tool_call", p.name || "Tool call", "", { ...fields2, role: "assistant", input: eventText(p.arguments ?? p.input), status: "unknown" })] : ["function_call_output", "custom_tool_call_output"].includes(p.type) ? [eventFor(msg, "result", "tool_result", "Tool result", "", { ...fields2, output: eventText(p.output, 64e3), status: "unknown" })] : [eventFor(msg, "event", p.type === "reasoning" ? "reasoning" : "event", p.type === "reasoning" ? "Recorded reasoning summary" : p.type || "Unknown event", eventText(p.type === "reasoning" ? p.summary : p), { ...fields2, partial: p.type === "reasoning" })];
|
|
31729
31940
|
if (p.type === "message") {
|
|
31730
31941
|
for (const part of Array.isArray(p.content) ? p.content : []) if (["input_text", "output_text", "text"].includes(part.type)) addText(msg, role === "user" ? codexUserText(part.text) : part.text, role === "user" ? "You" : "Assistant");
|
|
31731
31942
|
} else if (["function_call", "custom_tool_call"].includes(p.type)) {
|
|
@@ -31749,10 +31960,11 @@ var init_codex = __esm({
|
|
|
31749
31960
|
init_jsonl();
|
|
31750
31961
|
init_events();
|
|
31751
31962
|
init_source_paths();
|
|
31963
|
+
init_commit_extraction();
|
|
31752
31964
|
root2 = () => sourcePath("codex") || process.env.CODEX_HOME || join10(homedir6(), ".codex");
|
|
31753
31965
|
revision = async (path) => {
|
|
31754
31966
|
const s = await stat2(path);
|
|
31755
|
-
return digest([
|
|
31967
|
+
return digest([10, s.mtimeMs, s.size]);
|
|
31756
31968
|
};
|
|
31757
31969
|
codexAdapter = {
|
|
31758
31970
|
id: "codex",
|
|
@@ -31812,6 +32024,7 @@ var init_codex = __esm({
|
|
|
31812
32024
|
})).values()], warnings };
|
|
31813
32025
|
},
|
|
31814
32026
|
async read(candidate, cursor) {
|
|
32027
|
+
if (!cursor) candidate.locator.executionCwd = "";
|
|
31815
32028
|
const page2 = await readJSONL(candidate.locator.path, Number(cursor || 0));
|
|
31816
32029
|
if (page2.cursor === void 0 && await revision(candidate.locator.path) !== candidate.revision) throw new Error("Session changed during import; import again to capture the latest messages.");
|
|
31817
32030
|
return { messages: page2.rows.flatMap((r) => {
|
|
@@ -31841,7 +32054,7 @@ function time2(value) {
|
|
|
31841
32054
|
return Number.isFinite(parsed) && parsed > 0 && parsed <= 864e13 ? parsed : 0;
|
|
31842
32055
|
}
|
|
31843
32056
|
function status(value) {
|
|
31844
|
-
return ["pending", "running", "completed", "failed"].includes(
|
|
32057
|
+
return ["pending", "running", "completed", "failed"].includes(string2(value)) ? value : "unknown";
|
|
31845
32058
|
}
|
|
31846
32059
|
async function databasePath2() {
|
|
31847
32060
|
const root3 = sourcePath("t3-code") || process.env.SESSIONGRAPH_T3_CODE_HISTORY_DIR || process.env.T3CODE_HOME || join11(homedir7(), ".t3");
|
|
@@ -31870,7 +32083,7 @@ function projectRoots(db2, ids) {
|
|
|
31870
32083
|
for (const batch of batches([...new Set(ids.filter(Boolean))])) {
|
|
31871
32084
|
const placeholders = batch.map(() => "?").join(",");
|
|
31872
32085
|
for (const row of db2.prepare(`SELECT project_id, substr(workspace_root,1,4096) AS workspace_root FROM projection_projects WHERE deleted_at IS NULL AND project_id IN (${placeholders})`).all(...batch))
|
|
31873
|
-
roots2.set(
|
|
32086
|
+
roots2.set(string2(row.project_id), string2(row.workspace_root));
|
|
31874
32087
|
}
|
|
31875
32088
|
return roots2;
|
|
31876
32089
|
}
|
|
@@ -31880,7 +32093,7 @@ function aggregates(db2, table2, ids) {
|
|
|
31880
32093
|
for (const batch of batches(ids)) {
|
|
31881
32094
|
const placeholders = batch.map(() => "?").join(",");
|
|
31882
32095
|
for (const row of db2.prepare(`SELECT thread_id, COUNT(*) AS n, MAX(updated_at) AS latest FROM ${table2} WHERE thread_id IN (${placeholders}) GROUP BY thread_id`).all(...batch))
|
|
31883
|
-
result.set(
|
|
32096
|
+
result.set(string2(row.thread_id), [Number(row.n), string2(row.latest)]);
|
|
31884
32097
|
}
|
|
31885
32098
|
return result;
|
|
31886
32099
|
}
|
|
@@ -31894,10 +32107,10 @@ function linkedSessions(db2, ids) {
|
|
|
31894
32107
|
CASE WHEN json_valid(payload_json) THEN json_extract(payload_json,'$.nativeThreadRef.strength') END AS strength,
|
|
31895
32108
|
CASE WHEN json_valid(payload_json) THEN json_extract(payload_json,'$.nativeThreadRef.driver') END AS driver
|
|
31896
32109
|
FROM orchestration_v2_projection_provider_threads WHERE thread_id IN (${placeholders})`).all(...batch)) {
|
|
31897
|
-
const source = providerSource[
|
|
31898
|
-
const nativeID =
|
|
32110
|
+
const source = providerSource[string2(row.provider)];
|
|
32111
|
+
const nativeID = string2(row.native_id);
|
|
31899
32112
|
if (!source || row.strength !== "strong" || row.driver && row.driver !== row.provider || !nativeID || nativeID.length > 512) continue;
|
|
31900
|
-
const id2 =
|
|
32113
|
+
const id2 = string2(row.thread_id);
|
|
31901
32114
|
links.set(id2, [.../* @__PURE__ */ new Set([...links.get(id2) || [], identity(source, nativeID)])]);
|
|
31902
32115
|
}
|
|
31903
32116
|
}
|
|
@@ -31912,8 +32125,8 @@ function discoverV2(db2, path, databaseRevision) {
|
|
|
31912
32125
|
CASE WHEN json_valid(payload_json) THEN json_extract(payload_json,'$.lineage.relationshipToParent') END AS relationship,
|
|
31913
32126
|
json_valid(payload_json) AS valid_payload
|
|
31914
32127
|
FROM orchestration_v2_projection_threads WHERE deleted_at IS NULL ORDER BY created_at, thread_id LIMIT ?`).all(MAX_THREADS + 1);
|
|
31915
|
-
const selected = rows2.slice(0, MAX_THREADS), ids = selected.map((row) =>
|
|
31916
|
-
const roots2 = projectRoots(db2, selected.map((row) =>
|
|
32128
|
+
const selected = rows2.slice(0, MAX_THREADS), ids = selected.map((row) => string2(row.thread_id));
|
|
32129
|
+
const roots2 = projectRoots(db2, selected.map((row) => string2(row.project_id)));
|
|
31917
32130
|
const counts = aggregates(db2, "orchestration_v2_projection_messages", ids);
|
|
31918
32131
|
const items = aggregates(db2, "orchestration_v2_projection_turn_items", ids);
|
|
31919
32132
|
const links = linkedSessions(db2, ids);
|
|
@@ -31921,28 +32134,28 @@ function discoverV2(db2, path, databaseRevision) {
|
|
|
31921
32134
|
if (rows2.length > MAX_THREADS) warnings.push(`T3 Code discovery is limited to ${MAX_THREADS.toLocaleString()} threads.`);
|
|
31922
32135
|
let unreadableMetadata = 0;
|
|
31923
32136
|
for (const row of selected) {
|
|
31924
|
-
const nativeID =
|
|
32137
|
+
const nativeID = string2(row.thread_id), created = time2(row.created_at);
|
|
31925
32138
|
if (!nativeID || nativeID.length > 512 || !created) continue;
|
|
31926
32139
|
if (!row.valid_payload) unreadableMetadata++;
|
|
31927
|
-
const
|
|
31928
|
-
const p = project(SOURCE,
|
|
32140
|
+
const directory3 = string2(row.worktree_path) || roots2.get(string2(row.project_id)) || "";
|
|
32141
|
+
const p = project(SOURCE, directory3);
|
|
31929
32142
|
projects.set(p.id, p);
|
|
31930
|
-
const session = blankSession(SOURCE, nativeID,
|
|
31931
|
-
const parent =
|
|
32143
|
+
const session = blankSession(SOURCE, nativeID, directory3);
|
|
32144
|
+
const parent = string2(row.parent_thread_id);
|
|
31932
32145
|
session.parentID = row.relationship === "subagent" && parent ? identity(SOURCE, parent) : void 0;
|
|
31933
32146
|
session.forkID = row.relationship === "fork" && parent ? identity(SOURCE, parent) : void 0;
|
|
31934
32147
|
Object.assign(session, {
|
|
31935
|
-
title:
|
|
32148
|
+
title: string2(row.title) || "T3 Code thread",
|
|
31936
32149
|
projectID: p.id,
|
|
31937
32150
|
created,
|
|
31938
32151
|
updated: time2(row.updated_at) || created,
|
|
31939
32152
|
archived: Boolean(row.archived_at),
|
|
31940
|
-
model:
|
|
31941
|
-
provider:
|
|
32153
|
+
model: string2(row.model) || "Unknown model",
|
|
32154
|
+
provider: string2(row.default_provider),
|
|
31942
32155
|
agent: "T3 Code",
|
|
31943
32156
|
linkedSessionIDs: links.get(nativeID) || []
|
|
31944
32157
|
});
|
|
31945
|
-
const revision2 = digest([row.updated_at, counts.get(nativeID), items.get(nativeID), links.get(nativeID)]);
|
|
32158
|
+
const revision2 = digest([3, row.updated_at, counts.get(nativeID), items.get(nativeID), links.get(nativeID)]);
|
|
31946
32159
|
sessions.push({ session, revision: revision2, locator: { path, databaseRevision, threadID: nativeID, format: "v2", metadataPartial: row.valid_payload ? "" : "1" } });
|
|
31947
32160
|
}
|
|
31948
32161
|
if (unreadableMetadata) warnings.push(`${unreadableMetadata} T3 Code threads had unreadable metadata; model or lineage may be unavailable.`);
|
|
@@ -31955,23 +32168,23 @@ function discoverV1(db2, path, databaseRevision) {
|
|
|
31955
32168
|
CASE WHEN json_valid(model_selection_json) THEN substr(json_extract(model_selection_json,'$.model'),1,200) END AS model
|
|
31956
32169
|
FROM projection_threads WHERE deleted_at IS NULL ORDER BY created_at, thread_id LIMIT ?`).all(MAX_THREADS + 1);
|
|
31957
32170
|
const selected = rows2.slice(0, MAX_THREADS);
|
|
31958
|
-
const roots2 = projectRoots(db2, selected.map((row) =>
|
|
31959
|
-
const counts = aggregates(db2, "projection_thread_messages", selected.map((row) =>
|
|
32171
|
+
const roots2 = projectRoots(db2, selected.map((row) => string2(row.project_id)));
|
|
32172
|
+
const counts = aggregates(db2, "projection_thread_messages", selected.map((row) => string2(row.thread_id)));
|
|
31960
32173
|
const sessions = [], projects = /* @__PURE__ */ new Map();
|
|
31961
32174
|
for (const row of selected) {
|
|
31962
|
-
const nativeID =
|
|
32175
|
+
const nativeID = string2(row.thread_id), created = time2(row.created_at);
|
|
31963
32176
|
if (!nativeID || nativeID.length > 512 || !created) continue;
|
|
31964
|
-
const
|
|
31965
|
-
const p = project(SOURCE,
|
|
32177
|
+
const directory3 = string2(row.worktree_path) || roots2.get(string2(row.project_id)) || "";
|
|
32178
|
+
const p = project(SOURCE, directory3);
|
|
31966
32179
|
projects.set(p.id, p);
|
|
31967
|
-
const session = blankSession(SOURCE, nativeID,
|
|
32180
|
+
const session = blankSession(SOURCE, nativeID, directory3);
|
|
31968
32181
|
Object.assign(session, {
|
|
31969
|
-
title:
|
|
32182
|
+
title: string2(row.title) || "T3 Code thread",
|
|
31970
32183
|
projectID: p.id,
|
|
31971
32184
|
created,
|
|
31972
32185
|
updated: time2(row.updated_at) || created,
|
|
31973
32186
|
archived: Boolean(row.archived_at),
|
|
31974
|
-
model:
|
|
32187
|
+
model: string2(row.model) || "Unknown model",
|
|
31975
32188
|
agent: "T3 Code"
|
|
31976
32189
|
});
|
|
31977
32190
|
sessions.push({ session, revision: digest([row.updated_at, counts.get(nativeID)]), locator: { path, databaseRevision, threadID: nativeID, format: "v1" } });
|
|
@@ -31980,15 +32193,15 @@ function discoverV1(db2, path, databaseRevision) {
|
|
|
31980
32193
|
if (rows2.length > MAX_THREADS) warnings.push(`T3 Code discovery is limited to ${MAX_THREADS.toLocaleString()} threads.`);
|
|
31981
32194
|
return { sessions, projects: [...projects.values()], warnings };
|
|
31982
32195
|
}
|
|
31983
|
-
function v2Message(row,
|
|
31984
|
-
const parsed = parsedObject(row.payload_json), item = parsed || {}, type =
|
|
32196
|
+
function v2Message(row, directory3) {
|
|
32197
|
+
const parsed = parsedObject(row.payload_json), item = parsed || {}, type = string2(row.type), id2 = string2(row.turn_item_id);
|
|
31985
32198
|
const role = type === "user_message" ? "user" : type === "assistant_message" ? "assistant" : type === "reasoning" ? "assistant" : "tool";
|
|
31986
32199
|
const message2 = blankMessage(`item:${id2}`, time2(item.startedAt || item.createdAt), role);
|
|
31987
|
-
const recorded = Boolean(message2.time), name =
|
|
32200
|
+
const recorded = Boolean(message2.time), name = string2(item.title || item.toolName) || type.replaceAll("_", " ");
|
|
31988
32201
|
const fields2 = {
|
|
31989
32202
|
nativeID: id2,
|
|
31990
32203
|
nativeType: type,
|
|
31991
|
-
parentID:
|
|
32204
|
+
parentID: string2(item.parentItemId) || void 0,
|
|
31992
32205
|
status: status(row.status),
|
|
31993
32206
|
endTime: time2(item.completedAt) || null,
|
|
31994
32207
|
timeSource: recorded ? "recorded" : "unknown"
|
|
@@ -31999,34 +32212,42 @@ function v2Message(row, directory2) {
|
|
|
31999
32212
|
return message2;
|
|
32000
32213
|
}
|
|
32001
32214
|
if (type === "user_message" || type === "assistant_message") {
|
|
32002
|
-
const body =
|
|
32215
|
+
const body = string2(item.text);
|
|
32003
32216
|
if (body) addText(message2, body, role === "user" ? "You" : "Assistant");
|
|
32004
32217
|
message2.events = [{ ...messageEvent(message2, body, id2), ...fields2 }];
|
|
32005
32218
|
if (Array.isArray(item.attachments) && item.attachments.length) message2.partial = true;
|
|
32006
32219
|
return message2;
|
|
32007
32220
|
}
|
|
32008
32221
|
if (type === "reasoning") {
|
|
32009
|
-
message2.events = [eventFor(message2, id2, "reasoning", "Recorded reasoning",
|
|
32222
|
+
message2.events = [eventFor(message2, id2, "reasoning", "Recorded reasoning", string2(item.text), fields2)];
|
|
32010
32223
|
return message2;
|
|
32011
32224
|
}
|
|
32012
32225
|
if (type === "file_change") {
|
|
32013
|
-
const file =
|
|
32014
|
-
|
|
32226
|
+
const file = string2(item.fileName), completed = status(row.status) === "completed";
|
|
32227
|
+
const native = item.nativeItemRef;
|
|
32228
|
+
if (native?.driver === "opencode" && openCodeEditTools.has(file.toLowerCase())) {
|
|
32229
|
+
message2.tools.push(file);
|
|
32230
|
+
const kind2 = completed || fields2.status === "failed" ? "tool_result" : "tool_call";
|
|
32231
|
+
message2.events = [eventFor(message2, id2, kind2, file, "", { ...fields2, callID: string2(native.nativeId) || void 0 })];
|
|
32232
|
+
return message2;
|
|
32233
|
+
}
|
|
32234
|
+
if (file && completed) message2.files.push({ path: isAbsolute3(file) ? file : join11(directory3, file), source: "file change", steps: 1 });
|
|
32015
32235
|
message2.events = [eventFor(message2, id2, "file_change", file || name, "", fields2)];
|
|
32016
32236
|
return message2;
|
|
32017
32237
|
}
|
|
32018
32238
|
if (["command_execution", "dynamic_tool", "file_search", "web_search"].includes(type)) {
|
|
32019
32239
|
const input = eventText(item.input ?? item.pattern ?? item.patterns, 32e3);
|
|
32020
|
-
const
|
|
32240
|
+
const output2 = eventText(item.output ?? item.results, 64e3);
|
|
32021
32241
|
const kind2 = fields2.status === "completed" || fields2.status === "failed" ? "tool_result" : "tool_call";
|
|
32022
32242
|
message2.tools.push(name);
|
|
32023
32243
|
if (input) addText(message2, input, "Tool");
|
|
32024
|
-
if (
|
|
32025
|
-
|
|
32244
|
+
if (output2) addText(message2, output2, "Tool");
|
|
32245
|
+
const native = item.nativeItemRef;
|
|
32246
|
+
message2.events = [eventFor(message2, id2, kind2, name, "", { ...fields2, input, output: output2, ...executionFields(parsedObject(item.input) || item.input, item), callID: string2(native?.nativeId) || void 0 })];
|
|
32026
32247
|
return message2;
|
|
32027
32248
|
}
|
|
32028
32249
|
const kind = type === "compaction" ? "compaction" : type === "error" ? "error" : "event";
|
|
32029
|
-
message2.events = [eventFor(message2, id2, kind, name,
|
|
32250
|
+
message2.events = [eventFor(message2, id2, kind, name, string2(item.text), fields2)];
|
|
32030
32251
|
return message2;
|
|
32031
32252
|
}
|
|
32032
32253
|
function readV2(db2, candidate, cursor) {
|
|
@@ -32059,9 +32280,9 @@ function readV1(db2, candidate, cursor) {
|
|
|
32059
32280
|
const messages = rows2.slice(0, PAGE).map((row) => {
|
|
32060
32281
|
const role = row.role === "user" ? "user" : row.role === "assistant" ? "assistant" : "system";
|
|
32061
32282
|
const message2 = blankMessage(`message:${row.message_id}`, time2(row.created_at), role);
|
|
32062
|
-
const body =
|
|
32283
|
+
const body = string2(row.text);
|
|
32063
32284
|
if (body) addText(message2, body, role === "user" ? "You" : "Assistant");
|
|
32064
|
-
message2.events = [{ ...messageEvent(message2, body), nativeID:
|
|
32285
|
+
message2.events = [{ ...messageEvent(message2, body), nativeID: string2(row.message_id), nativeType: "legacy-message" }];
|
|
32065
32286
|
message2.partial = row.text == null;
|
|
32066
32287
|
return message2;
|
|
32067
32288
|
});
|
|
@@ -32072,7 +32293,7 @@ function readV1(db2, candidate, cursor) {
|
|
|
32072
32293
|
note: "Legacy T3 Code text messages only. Tool activity, attachments, and provider links are unavailable."
|
|
32073
32294
|
};
|
|
32074
32295
|
}
|
|
32075
|
-
var SOURCE, PAGE, MAX_THREADS, MAX_ITEM_JSON, providerSource,
|
|
32296
|
+
var SOURCE, PAGE, MAX_THREADS, MAX_ITEM_JSON, providerSource, openCodeEditTools, string2, t3CodeAdapter;
|
|
32076
32297
|
var init_t3_code = __esm({
|
|
32077
32298
|
"server/adapters/t3-code.ts"() {
|
|
32078
32299
|
"use strict";
|
|
@@ -32080,12 +32301,14 @@ var init_t3_code = __esm({
|
|
|
32080
32301
|
init_common();
|
|
32081
32302
|
init_sqlite_snapshot();
|
|
32082
32303
|
init_events();
|
|
32304
|
+
init_commit_extraction();
|
|
32083
32305
|
SOURCE = "t3-code";
|
|
32084
32306
|
PAGE = 100;
|
|
32085
32307
|
MAX_THREADS = 2e4;
|
|
32086
32308
|
MAX_ITEM_JSON = 256e3;
|
|
32087
32309
|
providerSource = { codex: "codex", claudeAgent: "claude-code", opencode: "opencode" };
|
|
32088
|
-
|
|
32310
|
+
openCodeEditTools = /* @__PURE__ */ new Set(["patch", "apply_patch", "edit", "write", "multiedit"]);
|
|
32311
|
+
string2 = (value) => typeof value === "string" ? value : "";
|
|
32089
32312
|
t3CodeAdapter = {
|
|
32090
32313
|
id: SOURCE,
|
|
32091
32314
|
name: "T3 Code",
|
|
@@ -32097,8 +32320,14 @@ var init_t3_code = __esm({
|
|
|
32097
32320
|
async discover() {
|
|
32098
32321
|
const path = await databasePath2();
|
|
32099
32322
|
if (!path) return { sessions: [], projects: [], warnings: ["T3 Code database is unavailable. Saved history is retained."] };
|
|
32100
|
-
|
|
32101
|
-
|
|
32323
|
+
for (let attempt = 0; ; attempt++) {
|
|
32324
|
+
const databaseRevision = sqliteRevision(path);
|
|
32325
|
+
try {
|
|
32326
|
+
return withSqliteSnapshot(path, (db2) => hasTable(db2, "orchestration_v2_projection_threads") ? discoverV2(db2, path, databaseRevision) : discoverV1(db2, path, databaseRevision), databaseRevision);
|
|
32327
|
+
} catch (error) {
|
|
32328
|
+
if (!(error instanceof SqliteSnapshotChangedError) || attempt >= 2) throw error;
|
|
32329
|
+
}
|
|
32330
|
+
}
|
|
32102
32331
|
},
|
|
32103
32332
|
async read(candidate, cursor) {
|
|
32104
32333
|
return withSqliteSnapshot(candidate.locator.path, (db2) => candidate.locator.format === "v2" ? readV2(db2, candidate, cursor) : readV1(db2, candidate, cursor), candidate.locator.databaseRevision, true);
|
|
@@ -32112,8 +32341,26 @@ function cursorTime(value) {
|
|
|
32112
32341
|
const time3 = typeof value === "number" ? value : typeof value === "string" && /(?:Z|[+-]\d\d:\d\d)$/.test(value) ? Date.parse(value) : 0;
|
|
32113
32342
|
return Number.isFinite(time3) && time3 > 0 && time3 <= 864e13 ? time3 : 0;
|
|
32114
32343
|
}
|
|
32344
|
+
function cursorEnvelope(text3) {
|
|
32345
|
+
let value = text3.trim(), timestamp;
|
|
32346
|
+
for (; ; ) {
|
|
32347
|
+
value = value.replace(/^(?:\[Image\]\s*)+(?=<image_files>)/, "");
|
|
32348
|
+
const clock = value.match(/^<timestamp>([^<]+)<\/timestamp>\s*/);
|
|
32349
|
+
if (clock) {
|
|
32350
|
+
timestamp ??= clock[1];
|
|
32351
|
+
value = value.slice(clock[0].length);
|
|
32352
|
+
continue;
|
|
32353
|
+
}
|
|
32354
|
+
const context = value.match(/^<(user_info|environment_context|system_reminder|external_links|attached_files|image_files)(?:\s[^>]*)?>/);
|
|
32355
|
+
if (!context) break;
|
|
32356
|
+
const end = value.indexOf(`</${context[1]}>`, context[0].length);
|
|
32357
|
+
if (end < 0) return { text: "", timestamp };
|
|
32358
|
+
value = value.slice(end + context[1].length + 3).trim();
|
|
32359
|
+
}
|
|
32360
|
+
return { text: value, timestamp };
|
|
32361
|
+
}
|
|
32115
32362
|
function cursorEnvelopeTime(text3) {
|
|
32116
|
-
const value = text3.
|
|
32363
|
+
const value = cursorEnvelope(text3).timestamp;
|
|
32117
32364
|
if (!value) return 0;
|
|
32118
32365
|
const iso = cursorTime(value);
|
|
32119
32366
|
if (iso) return iso;
|
|
@@ -32122,17 +32369,21 @@ function cursorEnvelopeTime(text3) {
|
|
|
32122
32369
|
return cursorTime(Date.parse(`${match2[1]} ${match2[2]} GMT${match2[3]}${match2[4].padStart(2, "0")}${match2[5] || "00"}`));
|
|
32123
32370
|
}
|
|
32124
32371
|
function cursorUserText(text3) {
|
|
32125
|
-
|
|
32126
|
-
for (; ; ) {
|
|
32127
|
-
const stripped = value.replace(/^<(user_info|environment_context|system_reminder)>[\s\S]*?<\/\1>\s*/, "");
|
|
32128
|
-
if (stripped === value) break;
|
|
32129
|
-
value = stripped;
|
|
32130
|
-
}
|
|
32372
|
+
const value = cursorEnvelope(text3).text;
|
|
32131
32373
|
const query = value.match(/^<user_query>([\s\S]*?)<\/user_query>(?:\s*<system_reminder>[\s\S]*?<\/system_reminder>)*\s*$/);
|
|
32132
32374
|
return (query ? query[1] : value).trim();
|
|
32133
32375
|
}
|
|
32134
32376
|
function cursorMessage(raw, fallbackID) {
|
|
32135
32377
|
if (!raw || typeof raw !== "object") return;
|
|
32378
|
+
if (raw.type === "turn_ended") {
|
|
32379
|
+
const message2 = blankMessage(typeof raw.id === "string" && raw.id.length <= 512 ? raw.id : fallbackID, cursorTime(raw.timestamp), "system");
|
|
32380
|
+
const failed = raw.status === "error" || raw.status === "failed";
|
|
32381
|
+
message2.events = [eventFor(message2, "turn-ended", failed ? "error" : "event", failed ? "Cursor turn failed" : "Cursor turn ended", eventText(raw.error), {
|
|
32382
|
+
nativeType: "turn_ended",
|
|
32383
|
+
status: failed ? "failed" : raw.status === "completed" || raw.status === "success" ? "completed" : "unknown"
|
|
32384
|
+
})];
|
|
32385
|
+
return message2;
|
|
32386
|
+
}
|
|
32136
32387
|
const body = raw.message && typeof raw.message === "object" ? raw.message : raw;
|
|
32137
32388
|
const role = raw.role || body.role;
|
|
32138
32389
|
if (!["user", "assistant", "tool", "system"].includes(role)) return;
|
|
@@ -32141,7 +32392,7 @@ function cursorMessage(raw, fallbackID) {
|
|
|
32141
32392
|
const time3 = cursorTime(raw.timestamp) || cursorTime(body.timestamp) || cursorTime(body.createdAt) || (role === "user" && typeof firstText === "string" ? cursorEnvelopeTime(firstText) : 0);
|
|
32142
32393
|
const native = [raw.uuid, raw.id, body.uuid, body.id].find((id2) => typeof id2 === "string" && id2.length && id2.length <= 512);
|
|
32143
32394
|
const msg = blankMessage(native || fallbackID, time3, role);
|
|
32144
|
-
msg.events = role === "tool" ? [eventFor(msg, "result", "tool_result", body.name || "Tool result", "", { callID: body.tool_call_id, output: eventText(content, 64e3), status: "unknown" })] : blockEvents(msg, content);
|
|
32395
|
+
msg.events = role === "tool" ? [eventFor(msg, "result", "tool_result", body.name || "Tool result", "", { callID: body.tool_call_id, output: eventText(content, 64e3), status: "unknown" })] : role === "user" ? userBlockEvents(msg, content, cursorUserText) : blockEvents(msg, content);
|
|
32145
32396
|
const kind = role === "user" ? "You" : role === "assistant" ? "Assistant" : "Tool";
|
|
32146
32397
|
const text3 = (value) => addText(msg, role === "user" && typeof value === "string" ? cursorUserText(value) : value, kind);
|
|
32147
32398
|
if (typeof content === "string") text3(content);
|
|
@@ -32202,11 +32453,11 @@ function withStore(path, read3) {
|
|
|
32202
32453
|
throw error;
|
|
32203
32454
|
}
|
|
32204
32455
|
});
|
|
32205
|
-
const before = stats(),
|
|
32456
|
+
const before = stats(), directory3 = mkdtempSync2(join12(tmpdir2(), "sessiongraph-cursor-"));
|
|
32206
32457
|
let db2;
|
|
32207
32458
|
try {
|
|
32208
|
-
chmodSync3(
|
|
32209
|
-
const copy = join12(
|
|
32459
|
+
chmodSync3(directory3, 448);
|
|
32460
|
+
const copy = join12(directory3, "store.db");
|
|
32210
32461
|
files.forEach((file, index) => {
|
|
32211
32462
|
if (before[index]) {
|
|
32212
32463
|
const target = index ? `${copy}-wal` : copy;
|
|
@@ -32222,7 +32473,7 @@ function withStore(path, read3) {
|
|
|
32222
32473
|
try {
|
|
32223
32474
|
db2?.close();
|
|
32224
32475
|
} finally {
|
|
32225
|
-
rmSync3(
|
|
32476
|
+
rmSync3(directory3, { recursive: true, force: true });
|
|
32226
32477
|
}
|
|
32227
32478
|
}
|
|
32228
32479
|
}
|
|
@@ -32294,12 +32545,12 @@ function readCursorStore(path) {
|
|
|
32294
32545
|
bytes2 += data.length;
|
|
32295
32546
|
try {
|
|
32296
32547
|
if (item.leaf) {
|
|
32297
|
-
const
|
|
32298
|
-
if (!
|
|
32548
|
+
const json5 = data[0] === 123 ? data : fields(data).find((v3) => v3.field === 4)?.data;
|
|
32549
|
+
if (!json5) {
|
|
32299
32550
|
partial = true;
|
|
32300
32551
|
continue;
|
|
32301
32552
|
}
|
|
32302
|
-
const raw = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(
|
|
32553
|
+
const raw = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(json5));
|
|
32303
32554
|
const msg = cursorMessage(raw, `blob:${item.id}:${ordinal++}`);
|
|
32304
32555
|
if (!msg) {
|
|
32305
32556
|
partial = true;
|
|
@@ -32358,9 +32609,9 @@ var init_cursor_store = __esm({
|
|
|
32358
32609
|
import { isAbsolute as isAbsolute4 } from "node:path";
|
|
32359
32610
|
import { fileURLToPath } from "node:url";
|
|
32360
32611
|
function decode(value) {
|
|
32361
|
-
return
|
|
32612
|
+
return object2(JSON.parse(typeof value === "string" ? value : value instanceof Uint8Array ? Buffer.from(value).toString("utf8") : "{}"));
|
|
32362
32613
|
}
|
|
32363
|
-
function
|
|
32614
|
+
function directory2(raw) {
|
|
32364
32615
|
const value = text2(raw.workspaceIdentifier?.uri?.path) || text2(raw.workspaceIdentifier?.uri) || text2(raw.cwd);
|
|
32365
32616
|
try {
|
|
32366
32617
|
return value.startsWith("file:") ? fileURLToPath(value) : isAbsolute4(value) ? value : "";
|
|
@@ -32375,7 +32626,7 @@ function discoverComposers(path, workspace = "") {
|
|
|
32375
32626
|
for (const table2 of ["cursorDiskKV", "ItemTable"]) {
|
|
32376
32627
|
if (!hasTable(db2, table2)) continue;
|
|
32377
32628
|
let failed = 0, count = 0;
|
|
32378
|
-
const rows2 = db2.prepare(`SELECT key, CASE WHEN length(value)<=? THEN value END AS value FROM ${table2} WHERE key LIKE 'composerData:%' ORDER BY key LIMIT 20001`).iterate(MAX_VALUE2);
|
|
32629
|
+
const rows2 = db2.prepare(`SELECT key, CASE WHEN length(value)<=? THEN value END AS value FROM ${table2} WHERE key LIKE 'composerData:%' AND value IS NOT NULL ORDER BY key LIMIT 20001`).iterate(MAX_VALUE2);
|
|
32379
32630
|
for (const row of rows2) {
|
|
32380
32631
|
if (++count > 2e4) {
|
|
32381
32632
|
warnings.push("Cursor Composer listing reached its 20,000-session limit.");
|
|
@@ -32387,7 +32638,7 @@ function discoverComposers(path, workspace = "") {
|
|
|
32387
32638
|
if (!nativeID || row.key !== `composerData:${nativeID}`) throw new Error("Composer identity mismatch.");
|
|
32388
32639
|
const headers = Array.isArray(data.fullConversationHeadersOnly) ? data.fullConversationHeadersOnly : Array.isArray(data.conversation) ? data.conversation : [];
|
|
32389
32640
|
if (!headers.length) continue;
|
|
32390
|
-
const session = blankSession("cursor", nativeID,
|
|
32641
|
+
const session = blankSession("cursor", nativeID, directory2(data) || workspace);
|
|
32391
32642
|
session.created = cursorTime(data.createdAt);
|
|
32392
32643
|
if (!session.created) continue;
|
|
32393
32644
|
session.updated = cursorTime(data.lastUpdatedAt) || session.created;
|
|
@@ -32396,7 +32647,7 @@ function discoverComposers(path, workspace = "") {
|
|
|
32396
32647
|
session.model = text2(data.modelConfig?.modelName) || "Unknown model";
|
|
32397
32648
|
session.archived = data.isArchived === true;
|
|
32398
32649
|
const children = Array.isArray(data.subagentComposerIds) ? data.subagentComposerIds.filter((id2) => typeof id2 === "string") : [];
|
|
32399
|
-
sessions.push({ session, revision: digest([
|
|
32650
|
+
sessions.push({ session, revision: digest([2, snapshot2, table2, nativeID]), locator: { path, kind: "composer", table: table2, snapshot: snapshot2, nativeID, children: JSON.stringify(children) } });
|
|
32400
32651
|
} catch {
|
|
32401
32652
|
failed++;
|
|
32402
32653
|
}
|
|
@@ -32438,7 +32689,7 @@ function readComposer(candidate) {
|
|
|
32438
32689
|
const id2 = text2(header.bubbleId);
|
|
32439
32690
|
const stored = id2 ? get.get(`bubbleId:${nativeID}:${id2}`, MAX_BUBBLE) : void 0;
|
|
32440
32691
|
if (stored) bytes2 += typeof stored.value === "string" ? Buffer.byteLength(stored.value) : stored.value.byteLength;
|
|
32441
|
-
const raw = stored ? { ...header, ...decode(stored.value) } : { ...header, ...
|
|
32692
|
+
const raw = stored ? { ...header, ...decode(stored.value) } : { ...header, ...object2(data.conversationMap?.[id2]) };
|
|
32442
32693
|
if (![1, 2].includes(raw.type)) {
|
|
32443
32694
|
partial = true;
|
|
32444
32695
|
continue;
|
|
@@ -32497,7 +32748,7 @@ async function stamp(path) {
|
|
|
32497
32748
|
async function snapshot(locator) {
|
|
32498
32749
|
return digest(await Promise.all([stamp(locator.path), locator.kind === "transcript" ? null : stamp(`${locator.path}-wal`), locator.meta ? stamp(locator.meta) : null]));
|
|
32499
32750
|
}
|
|
32500
|
-
async function
|
|
32751
|
+
async function json4(path) {
|
|
32501
32752
|
const s = await fileStats(path);
|
|
32502
32753
|
if (!s) return {};
|
|
32503
32754
|
if (s.size > 128e3) throw new Error("Cursor metadata exceeds the 128 KB limit.");
|
|
@@ -32527,7 +32778,7 @@ async function workspacePaths(root3, warnings) {
|
|
|
32527
32778
|
const database = join13(storage, entry.name, "state.vscdb");
|
|
32528
32779
|
stores.set(database, "");
|
|
32529
32780
|
try {
|
|
32530
|
-
const info = await
|
|
32781
|
+
const info = await json4(join13(storage, entry.name, "workspace.json"));
|
|
32531
32782
|
if (typeof info.folder === "string" && info.folder.startsWith("file:")) {
|
|
32532
32783
|
const path = cwd(fileURLToPath2(info.folder));
|
|
32533
32784
|
if (path) stores.set(database, path);
|
|
@@ -32587,7 +32838,7 @@ function createCursorAdapter(options = {}) {
|
|
|
32587
32838
|
return matches.length === 1 ? matches[0] : "";
|
|
32588
32839
|
};
|
|
32589
32840
|
let unreadable = 0, legacy = 0, scanned = 0;
|
|
32590
|
-
const add = async (path, id2, kind,
|
|
32841
|
+
const add = async (path, id2, kind, directory3, parent = "", workspaceHash = "") => {
|
|
32591
32842
|
if (!validID(id2) || ++scanned > LIMIT) return;
|
|
32592
32843
|
try {
|
|
32593
32844
|
const stats = await fileStats(path);
|
|
@@ -32596,11 +32847,11 @@ function createCursorAdapter(options = {}) {
|
|
|
32596
32847
|
const locator = { path, kind };
|
|
32597
32848
|
if (kind !== "transcript") locator.meta = join13(path, "..", "meta.json");
|
|
32598
32849
|
const before = await snapshot(locator);
|
|
32599
|
-
const extra2 = locator.meta ? await
|
|
32850
|
+
const extra2 = locator.meta ? await json4(locator.meta) : {};
|
|
32600
32851
|
const meta = kind === "transcript" ? {} : cursorStoreMetadata(path);
|
|
32601
32852
|
if (meta.agentId && meta.agentId !== id2) throw new Error("Cursor native identity mismatch.");
|
|
32602
32853
|
if (kind !== "transcript" && !meta.latestRootBlobId) return;
|
|
32603
|
-
const session = blankSession("cursor", native, cwd(meta.cwd) || cwd(extra2.cwd) ||
|
|
32854
|
+
const session = blankSession("cursor", native, cwd(meta.cwd) || cwd(extra2.cwd) || directory3);
|
|
32604
32855
|
session.agent = kind === "cli" ? "Cursor Agent" : kind === "acp" ? "Cursor ACP" : parent ? "Cursor subagent" : "Cursor IDE";
|
|
32605
32856
|
if (parent) session.parentID = identity("cursor", parent);
|
|
32606
32857
|
session.title = typeof meta.name === "string" && meta.name.trim() ? meta.name : typeof extra2.title === "string" && extra2.title.trim() ? extra2.title : "Cursor session";
|
|
@@ -32647,7 +32898,7 @@ function createCursorAdapter(options = {}) {
|
|
|
32647
32898
|
session.projectID = project("cursor", session.directory).id;
|
|
32648
32899
|
if (session.directory) delete locator.directoryNote;
|
|
32649
32900
|
}
|
|
32650
|
-
const candidate = { session, locator, revision: digest([
|
|
32901
|
+
const candidate = { session, locator, revision: digest([5, kind, path, before, session.created, session.directory, session.parentID]) };
|
|
32651
32902
|
if (!previous || rank(candidate) > rank(previous) || rank(candidate) === rank(previous) && session.updated > previous.session.updated) found.set(session.id, candidate);
|
|
32652
32903
|
} catch {
|
|
32653
32904
|
unreadable++;
|
|
@@ -32657,15 +32908,15 @@ function createCursorAdapter(options = {}) {
|
|
|
32657
32908
|
const projects = join13(root3(), "projects");
|
|
32658
32909
|
for (const dir of await entries(projects, warnings)) {
|
|
32659
32910
|
if (!dir.isDirectory() || scanned >= LIMIT) continue;
|
|
32660
|
-
const transcripts = join13(projects, dir.name, "agent-transcripts"),
|
|
32911
|
+
const transcripts = join13(projects, dir.name, "agent-transcripts"), directory3 = match2(dir.name, slug);
|
|
32661
32912
|
for (const entry of await entries(transcripts, warnings)) {
|
|
32662
32913
|
if (scanned >= LIMIT) break;
|
|
32663
|
-
if (entry.isFile() && entry.name.endsWith(".jsonl")) await add(join13(transcripts, entry.name), entry.name.slice(0, -6), "transcript",
|
|
32914
|
+
if (entry.isFile() && entry.name.endsWith(".jsonl")) await add(join13(transcripts, entry.name), entry.name.slice(0, -6), "transcript", directory3);
|
|
32664
32915
|
else if (entry.isFile() && entry.name.endsWith(".txt")) legacy++;
|
|
32665
32916
|
else if (entry.isDirectory() && validID(entry.name)) {
|
|
32666
|
-
await add(join13(transcripts, entry.name, `${entry.name}.jsonl`), entry.name, "transcript",
|
|
32917
|
+
await add(join13(transcripts, entry.name, `${entry.name}.jsonl`), entry.name, "transcript", directory3);
|
|
32667
32918
|
for (const child of await entries(join13(transcripts, entry.name, "subagents"), warnings)) {
|
|
32668
|
-
if (child.isFile() && child.name.endsWith(".jsonl")) await add(join13(transcripts, entry.name, "subagents", child.name), child.name.slice(0, -6), "transcript",
|
|
32919
|
+
if (child.isFile() && child.name.endsWith(".jsonl")) await add(join13(transcripts, entry.name, "subagents", child.name), child.name.slice(0, -6), "transcript", directory3, entry.name);
|
|
32669
32920
|
if (scanned >= LIMIT) break;
|
|
32670
32921
|
}
|
|
32671
32922
|
}
|
|
@@ -32674,13 +32925,13 @@ function createCursorAdapter(options = {}) {
|
|
|
32674
32925
|
const chats = join13(root3(), "chats");
|
|
32675
32926
|
for (const bucket of await entries(chats, warnings)) {
|
|
32676
32927
|
if (!bucket.isDirectory() || scanned >= LIMIT) continue;
|
|
32677
|
-
const folder = join13(chats, bucket.name),
|
|
32928
|
+
const folder = join13(chats, bucket.name), directory3 = match2(bucket.name, hashCwd);
|
|
32678
32929
|
if (/^[a-f\d]{32}$/i.test(bucket.name) && await fileStats(join13(folder, "store.db"))) {
|
|
32679
32930
|
const id2 = bucket.name.replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/, "$1-$2-$3-$4-$5");
|
|
32680
32931
|
await add(join13(folder, "store.db"), id2, "cli", "");
|
|
32681
32932
|
}
|
|
32682
32933
|
for (const entry of await entries(folder, warnings)) {
|
|
32683
|
-
if (entry.isDirectory()) await add(join13(folder, entry.name, "store.db"), entry.name, "cli",
|
|
32934
|
+
if (entry.isDirectory()) await add(join13(folder, entry.name, "store.db"), entry.name, "cli", directory3, "", bucket.name);
|
|
32684
32935
|
if (scanned >= LIMIT) break;
|
|
32685
32936
|
}
|
|
32686
32937
|
}
|
|
@@ -32727,7 +32978,7 @@ function createCursorAdapter(options = {}) {
|
|
|
32727
32978
|
const messages = page2.rows.flatMap((row) => {
|
|
32728
32979
|
const message2 = cursorMessage(row.value, `offset:${row.offset}`);
|
|
32729
32980
|
if (!message2) page2.partial = true;
|
|
32730
|
-
return message2 && message2.role !== "system" ? [message2] : [];
|
|
32981
|
+
return message2 && (message2.role !== "system" || row.value?.type === "turn_ended") ? [message2] : [];
|
|
32731
32982
|
});
|
|
32732
32983
|
await verify();
|
|
32733
32984
|
if (!offset && page2.cursor === void 0 && !messages.length) throw new Error("Cursor transcript has no readable conversation. Previous imports are retained.");
|
|
@@ -32763,7 +33014,7 @@ function projectRootFile(path) {
|
|
|
32763
33014
|
return join14(parts.slice(0, parts.lastIndexOf("chats")).join(sep4), ".project_root");
|
|
32764
33015
|
}
|
|
32765
33016
|
function geminiConversation(contents, lines) {
|
|
32766
|
-
const parsed = lines ? jsonLines(contents) : { rows: [
|
|
33017
|
+
const parsed = lines ? jsonLines(contents) : { rows: [object2(json3(contents))], partial: false };
|
|
32767
33018
|
let metadata2 = {};
|
|
32768
33019
|
const messages = /* @__PURE__ */ new Map();
|
|
32769
33020
|
const patch = (p) => {
|
|
@@ -32780,9 +33031,9 @@ function geminiConversation(contents, lines) {
|
|
|
32780
33031
|
const ids = [...messages.keys()], index = ids.indexOf(row.$rewindTo);
|
|
32781
33032
|
for (const id2 of index < 0 ? ids : ids.slice(index)) messages.delete(id2);
|
|
32782
33033
|
} else if (row.$patch) {
|
|
32783
|
-
const p =
|
|
33034
|
+
const p = object2(row.$patch);
|
|
32784
33035
|
if (p.id) patch(p);
|
|
32785
|
-
for (const update of Array.isArray(p.updates) ? p.updates : []) patch(
|
|
33036
|
+
for (const update of Array.isArray(p.updates) ? p.updates : []) patch(object2(update));
|
|
32786
33037
|
for (const id2 of Array.isArray(p.removeIds) ? p.removeIds : []) messages.delete(id2);
|
|
32787
33038
|
for (const id2 of Array.isArray(p.orderIds) ? p.orderIds : []) {
|
|
32788
33039
|
const value = messages.get(id2);
|
|
@@ -32792,7 +33043,7 @@ function geminiConversation(contents, lines) {
|
|
|
32792
33043
|
}
|
|
32793
33044
|
}
|
|
32794
33045
|
} else if (row.$set || row.sessionId) {
|
|
32795
|
-
const update = row.$set ?
|
|
33046
|
+
const update = row.$set ? object2(row.$set) : row;
|
|
32796
33047
|
metadata2 = { ...metadata2, ...update };
|
|
32797
33048
|
if (Array.isArray(update.messages)) {
|
|
32798
33049
|
if (row.$set) messages.clear();
|
|
@@ -32823,7 +33074,7 @@ var init_gemini = __esm({
|
|
|
32823
33074
|
parse(path, files) {
|
|
32824
33075
|
const { metadata: meta, records, partial } = geminiConversation(files.get(path), path.endsWith(".jsonl"));
|
|
32825
33076
|
if (!text2(meta.sessionId)) throw new Error("Unsupported Gemini history.");
|
|
32826
|
-
const
|
|
33077
|
+
const directory3 = (files.get(projectRootFile(path)) || "").trim().slice(0, 4096);
|
|
32827
33078
|
const messages = records.map((raw, index) => {
|
|
32828
33079
|
const message2 = googleMessage({ id: raw.id, timestamp: raw.timestamp, role: raw.type === "user" ? "user" : raw.type === "gemini" ? "assistant" : "system", content: raw.content }, `record:${index}`);
|
|
32829
33080
|
for (const [i, thought] of (Array.isArray(raw.thoughts) ? raw.thoughts : []).entries()) message2.events.push(eventFor(message2, `thought:${i}`, "reasoning", text2(thought.subject) || "Recorded reasoning", text2(thought.description), { time: time(thought.timestamp) || null, timeSource: time(thought.timestamp) ? "recorded" : "unknown" }));
|
|
@@ -32832,9 +33083,9 @@ var init_gemini = __esm({
|
|
|
32832
33083
|
message2.tools.push(name);
|
|
32833
33084
|
message2.events.push(eventFor(message2, `call:${id2}`, "tool_call", name, "", { callID: id2, input: eventText(call.args), status: "unknown" }));
|
|
32834
33085
|
if (call.result != null || ["success", "error", "cancelled"].includes(call.status)) {
|
|
32835
|
-
const
|
|
32836
|
-
message2.events.push(eventFor(message2, `result:${id2}`, "tool_result", name, "", { role: "tool", callID: id2, output, nativeType: text2(call.status), time: time(call.timestamp) || null, timeSource: time(call.timestamp) ? "recorded" : "unknown", status: call.status === "success" ? "completed" : call.status === "error" ? "failed" : "unknown" }));
|
|
32837
|
-
addText(message2,
|
|
33086
|
+
const output2 = eventText(call.result);
|
|
33087
|
+
message2.events.push(eventFor(message2, `result:${id2}`, "tool_result", name, "", { role: "tool", callID: id2, output: output2, nativeType: text2(call.status), time: time(call.timestamp) || null, timeSource: time(call.timestamp) ? "recorded" : "unknown", status: call.status === "success" ? "completed" : call.status === "error" ? "failed" : "unknown" }));
|
|
33088
|
+
addText(message2, output2, "Tool");
|
|
32838
33089
|
}
|
|
32839
33090
|
}
|
|
32840
33091
|
return message2;
|
|
@@ -32846,7 +33097,7 @@ var init_gemini = __esm({
|
|
|
32846
33097
|
messages,
|
|
32847
33098
|
parent,
|
|
32848
33099
|
partial,
|
|
32849
|
-
session: { directory:
|
|
33100
|
+
session: { directory: directory3, created: time(meta.startTime), title: text2(meta.summary), model: text2([...records].reverse().find((r) => r.model)?.model) || "Unknown model", provider: "Google", nativeResume: !parent && Boolean(directory3) && !sourcePath("gemini") && !process.env.SESSIONGRAPH_GEMINI_HOME && !path.includes(`${sep4}.cache${sep4}`) },
|
|
32850
33101
|
note: "Local Gemini chat records with rewind and patch reconstruction. Only explicit subagent directories form parent links; workspace paths come from the project-root marker. Binary content is omitted."
|
|
32851
33102
|
};
|
|
32852
33103
|
}
|
|
@@ -32881,7 +33132,7 @@ var init_qwen = __esm({
|
|
|
32881
33132
|
const messages = rows2.map((raw, index) => {
|
|
32882
33133
|
const id2 = text2(raw.uuid) || `record:${index}`;
|
|
32883
33134
|
if (raw.message && !["agent_message", "agent_mention", "notification"].includes(raw.subtype)) {
|
|
32884
|
-
const message3 = googleMessage({ id: id2, timestamp: raw.timestamp, role: raw.type === "assistant" ? "assistant" : raw.type === "user" ? "user" : "tool", toolCallId: raw.toolCallResult?.callId, content:
|
|
33135
|
+
const message3 = googleMessage({ id: id2, timestamp: raw.timestamp, role: raw.type === "assistant" ? "assistant" : raw.type === "user" ? "user" : "tool", toolCallId: raw.toolCallResult?.callId, content: object2(raw.message).parts }, id2);
|
|
32885
33136
|
for (const event of message3.events || []) if (event.kind === "tool_result") {
|
|
32886
33137
|
event.status = raw.toolCallResult?.status === "success" ? "completed" : raw.toolCallResult?.status === "error" ? "failed" : "unknown";
|
|
32887
33138
|
event.nativeType = text2(raw.toolCallResult?.status);
|
|
@@ -32929,11 +33180,11 @@ var init_copilot = __esm({
|
|
|
32929
33180
|
match: (path) => /(?:^|\/)events\.jsonl$/.test(path),
|
|
32930
33181
|
parse(path, files) {
|
|
32931
33182
|
const { rows: rows2, partial } = jsonLines(files.get(path));
|
|
32932
|
-
const start = rows2.find((r) => r.type === "session.start"), meta =
|
|
33183
|
+
const start = rows2.find((r) => r.type === "session.start"), meta = object2(start?.data);
|
|
32933
33184
|
if (!text2(meta.sessionId)) throw new Error("Unsupported Copilot event log.");
|
|
32934
33185
|
const toolNames = new Map(rows2.filter((r) => r.type === "tool.execution_start").map((r) => [r.data?.toolCallId, text2(r.data?.toolName)]));
|
|
32935
33186
|
const messages = rows2.filter((r) => !r.ephemeral && !["assistant.message_delta", "assistant.reasoning_delta"].includes(r.type)).map((raw, index) => {
|
|
32936
|
-
const data =
|
|
33187
|
+
const data = object2(raw.data), kind = text2(raw.type), human2 = kind === "user.message" && !data.isAutopilotContinuation && !data.source;
|
|
32937
33188
|
const message2 = blankMessage(text2(raw.id) || `record:${index}`, time(raw.timestamp), human2 ? "user" : kind === "assistant.message" ? "assistant" : kind.startsWith("tool.") ? "tool" : "system");
|
|
32938
33189
|
if (["user.message", "assistant.message"].includes(kind)) {
|
|
32939
33190
|
const content = text2(data.content);
|
|
@@ -32979,7 +33230,7 @@ function vscodeChatLog(content) {
|
|
|
32979
33230
|
for (const line of content.split("\n")) {
|
|
32980
33231
|
if (!line.trim()) continue;
|
|
32981
33232
|
if (++records > 5e4) throw new Error("Chat log exceeds the 50,000-operation limit.");
|
|
32982
|
-
const entry =
|
|
33233
|
+
const entry = object2(JSON.parse(line));
|
|
32983
33234
|
if (entry.kind === 0) {
|
|
32984
33235
|
if (records !== 1 || !entry.v || typeof entry.v !== "object" || Array.isArray(entry.v)) throw new Error("Invalid chat log initial state.");
|
|
32985
33236
|
state2 = entry.v;
|
|
@@ -33024,17 +33275,17 @@ var init_vscode_chat_log = __esm({
|
|
|
33024
33275
|
|
|
33025
33276
|
// server/adapters/copilot-chat.ts
|
|
33026
33277
|
import { homedir as homedir12 } from "node:os";
|
|
33027
|
-
import { basename as basename6, dirname as dirname5, join as join17, posix, win32 as
|
|
33278
|
+
import { basename as basename6, dirname as dirname5, join as join17, posix as posix2, win32 as win323 } from "node:path";
|
|
33028
33279
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
33029
33280
|
function copilotChatRoots(platform = process.platform, home = homedir12(), env = process.env) {
|
|
33030
|
-
const path = platform === "win32" ?
|
|
33281
|
+
const path = platform === "win32" ? win323 : posix2;
|
|
33031
33282
|
const base = platform === "darwin" ? path.join(home, "Library", "Application Support") : platform === "win32" ? env.APPDATA || path.join(home, "AppData", "Roaming") : env.XDG_CONFIG_HOME || path.join(home, ".config");
|
|
33032
33283
|
const override = sourcePath("copilot-chat") || env.SESSIONGRAPH_COPILOT_CHAT_USER_DATA_DIR;
|
|
33033
33284
|
const users = override ? [path.join(override, "User")] : [...["Code", "Code - Insiders"].map((app) => path.join(base, app, "User")), ...[".vscode-server", ".vscode-server-insiders"].map((app) => path.join(home, app, "data", "User"))];
|
|
33034
33285
|
return users.flatMap((user) => [path.join(user, "workspaceStorage"), path.join(user, "globalStorage", "emptyWindowChatSessions")]);
|
|
33035
33286
|
}
|
|
33036
33287
|
function vscodeChatPath(value) {
|
|
33037
|
-
const raw =
|
|
33288
|
+
const raw = object2(value);
|
|
33038
33289
|
if (raw.scheme) {
|
|
33039
33290
|
if (raw.scheme !== "file") return `${text2(raw.scheme)}://${text2(raw.authority)}${text2(raw.path)}`;
|
|
33040
33291
|
const path = text2(raw.path);
|
|
@@ -33050,7 +33301,7 @@ function vscodeChatPath(value) {
|
|
|
33050
33301
|
}
|
|
33051
33302
|
}
|
|
33052
33303
|
function responsePart(message2, value, index) {
|
|
33053
|
-
const part =
|
|
33304
|
+
const part = object2(value), kind = text2(part.kind), id2 = `part:${index}`;
|
|
33054
33305
|
const fields2 = { nativeType: kind || "markdown", nativeID: text2(part.id) || void 0 };
|
|
33055
33306
|
if (typeof value === "string" || !kind && typeof part.value === "string" || kind === "markdownContent" || kind === "markdownVuln") {
|
|
33056
33307
|
const content = markdown(kind ? part.content : value);
|
|
@@ -33061,19 +33312,19 @@ function responsePart(message2, value, index) {
|
|
|
33061
33312
|
message2.events.push(eventFor(message2, id2, "reasoning", "Recorded reasoning", content, { ...fields2, ...recordedTime(part.reasoningStartedAt) }));
|
|
33062
33313
|
addText(message2, content, "Tool");
|
|
33063
33314
|
} else if (kind === "toolInvocationSerialized") {
|
|
33064
|
-
const data =
|
|
33315
|
+
const data = object2(part.toolSpecificData), command = object2(data.commandLine), details = object2(part.resultDetails);
|
|
33065
33316
|
const name = text2(part.toolId) || "Tool", callID = text2(part.toolCallId) || void 0;
|
|
33066
33317
|
const input = eventText(data.rawInput ?? command.userEdited ?? command.toolEdited ?? command.original ?? details.input);
|
|
33067
|
-
const denied = part.isConfirmed === false || [0, 5].includes(
|
|
33318
|
+
const denied = part.isConfirmed === false || [0, 5].includes(object2(part.isConfirmed).type);
|
|
33068
33319
|
const status2 = denied || part.resultError ? "failed" : part.isComplete === true ? "completed" : "unknown";
|
|
33069
33320
|
const correlation = { ...fields2, callID, parentID: text2(part.subAgentInvocationId) || void 0 };
|
|
33070
33321
|
message2.events.push(eventFor(message2, `${id2}:call`, "tool_call", name, markdown(part.invocationMessage), { ...correlation, ...recordedTime(part.startedAt), input, status: "unknown" }));
|
|
33071
33322
|
message2.tools.push(name);
|
|
33072
33323
|
addText(message2, input, "Tool");
|
|
33073
33324
|
if (part.isComplete || part.resultError || denied) {
|
|
33074
|
-
const
|
|
33075
|
-
message2.events.push(eventFor(message2, `${id2}:result`, "tool_result", name, markdown(part.pastTenseMessage), { ...correlation, ...recordedTime(part.completedAt), role: "tool", output, status: status2 }));
|
|
33076
|
-
addText(message2,
|
|
33325
|
+
const output2 = eventText(part.resultError || (denied ? "Tool invocation was denied or skipped." : details.output ?? part.resultDetails ?? markdown(part.pastTenseMessage)));
|
|
33326
|
+
message2.events.push(eventFor(message2, `${id2}:result`, "tool_result", name, markdown(part.pastTenseMessage), { ...correlation, ...recordedTime(part.completedAt), role: "tool", output: output2, status: status2 }));
|
|
33327
|
+
addText(message2, output2, "Tool");
|
|
33077
33328
|
} else message2.partial = true;
|
|
33078
33329
|
} else {
|
|
33079
33330
|
message2.events.push(eventFor(message2, id2, "event", kind || "Unsupported chat content", eventText(part), { ...fields2, partial: true }));
|
|
@@ -33086,7 +33337,7 @@ function chatMessages(requests) {
|
|
|
33086
33337
|
const requestID = text2(request.requestId) || `request:${index}`;
|
|
33087
33338
|
const injected = Boolean(request.isSystemInitiated || request.hiddenFromTranscript || request.requestHiddenFromTranscript);
|
|
33088
33339
|
const user = blankMessage(requestID, time(request.timestamp), injected ? "system" : "user");
|
|
33089
|
-
const content = typeof request.message === "string" ? request.message : text2(
|
|
33340
|
+
const content = typeof request.message === "string" ? request.message : text2(object2(request.message).text);
|
|
33090
33341
|
user.events = [eventFor(user, "message", injected ? "event" : "message", injected ? "Injected message" : "User message", content, { nativeID: requestID, ...recordedTime(request.timestamp) })];
|
|
33091
33342
|
addText(user, content, injected ? "Tool" : "You");
|
|
33092
33343
|
if (request.variableData?.variables?.length) user.partial = true;
|
|
@@ -33125,7 +33376,7 @@ var init_copilot_chat = __esm({
|
|
|
33125
33376
|
init_local_files();
|
|
33126
33377
|
init_vscode_chat_log();
|
|
33127
33378
|
init_source_paths();
|
|
33128
|
-
markdown = (value) => typeof value === "string" ? value : text2(
|
|
33379
|
+
markdown = (value) => typeof value === "string" ? value : text2(object2(value).value);
|
|
33129
33380
|
recordedTime = (value) => ({ time: time(value) || null, timeSource: time(value) ? "recorded" : "unknown" });
|
|
33130
33381
|
match = (path) => /^(?:[^/]+\/chatSessions\/)?[^/]+\.jsonl?$/.test(path) && !["index.json", "workspace.json"].includes(path);
|
|
33131
33382
|
roots = () => copilotChatRoots();
|
|
@@ -33140,13 +33391,13 @@ var init_copilot_chat = __esm({
|
|
|
33140
33391
|
extras: (path) => [...basename6(dirname5(path)) === "chatSessions" ? [join17(dirname5(dirname5(path)), "workspace.json")] : [], ...path.endsWith(".json") ? [`${path}l`] : []],
|
|
33141
33392
|
parse(path, files) {
|
|
33142
33393
|
const log = path.endsWith(".jsonl") ? path : `${path}l`;
|
|
33143
|
-
const data = files.has(log) ? vscodeChatLog(files.get(log)) :
|
|
33394
|
+
const data = files.has(log) ? vscodeChatLog(files.get(log)) : object2(JSON.parse(files.get(path)));
|
|
33144
33395
|
if (!text2(data.sessionId) || !Array.isArray(data.requests) || data.version !== void 0 && ![1, 2, 3].includes(data.version)) throw new Error("Unsupported VS Code chat history.");
|
|
33145
33396
|
if (data.sessionId !== basename6(path).replace(/\.jsonl?$/, "")) throw new Error("VS Code chat identity mismatch.");
|
|
33146
33397
|
if (!data.requests.length) return;
|
|
33147
33398
|
if (data.requests.length > 25e3) throw new Error("Chat exceeds the 50,000-message limit.");
|
|
33148
33399
|
const workspacePath = join17(dirname5(dirname5(path)), "workspace.json");
|
|
33149
|
-
const workspace = files.has(workspacePath) ?
|
|
33400
|
+
const workspace = files.has(workspacePath) ? object2(JSON.parse(files.get(workspacePath))) : {};
|
|
33150
33401
|
const messages = chatMessages(data.requests);
|
|
33151
33402
|
const model = [...data.requests].reverse().find((r) => text2(r.modelId));
|
|
33152
33403
|
return {
|
|
@@ -33183,15 +33434,15 @@ function taskAdapter(id2, name, extension, env) {
|
|
|
33183
33434
|
match: (path) => /^[^/]+\/api_conversation_history\.json$/.test(path) || id2 === "cline" && /^[^/]+\/[^/]+\.messages\.json$/.test(path),
|
|
33184
33435
|
extras: (path) => ["history_item.json", "task_metadata.json", "session.json"].map((file) => join18(dirname6(path), file)),
|
|
33185
33436
|
parse(path, files) {
|
|
33186
|
-
const sdk = path.endsWith(".messages.json"), value =
|
|
33187
|
-
const records = sdk ?
|
|
33437
|
+
const sdk = path.endsWith(".messages.json"), value = json3(files.get(path));
|
|
33438
|
+
const records = sdk ? object2(value).messages : value;
|
|
33188
33439
|
if (!Array.isArray(records) || sdk && !text2(value.sessionId)) throw new Error("Unsupported task history.");
|
|
33189
|
-
const read3 = (name2) =>
|
|
33440
|
+
const read3 = (name2) => object2(files.has(join18(dirname6(path), name2)) ? json3(files.get(join18(dirname6(path), name2))) : void 0);
|
|
33190
33441
|
const history = read3("history_item.json"), info = read3("session.json"), task = read3("task_metadata.json");
|
|
33191
33442
|
const nativeID = sdk ? value.sessionId : basename7(dirname6(path));
|
|
33192
33443
|
if (history.id && history.id !== nativeID || info.session_id && info.session_id !== nativeID) throw new Error("Task metadata identity mismatch.");
|
|
33193
33444
|
const messages = records.map((raw, index) => {
|
|
33194
|
-
const row =
|
|
33445
|
+
const row = object2(raw), message2 = conversationMessage(row, `record:${index}`);
|
|
33195
33446
|
if (row.isSummary || row.isTruncationMarker || row.type === "reasoning") {
|
|
33196
33447
|
message2.role = "system";
|
|
33197
33448
|
message2.events = [eventFor(message2, "summary", row.type === "reasoning" ? "reasoning" : "compaction", row.type === "reasoning" ? "Recorded reasoning" : "Context checkpoint", eventText(row.summary ?? row.content ?? row.text), { partial: Boolean(row.encrypted_content), nativeType: row.type || "summary" })];
|
|
@@ -33221,7 +33472,7 @@ var init_extensions = __esm({
|
|
|
33221
33472
|
init_events();
|
|
33222
33473
|
init_local_files();
|
|
33223
33474
|
init_local_messages();
|
|
33224
|
-
|
|
33475
|
+
init_playback_tokens2();
|
|
33225
33476
|
init_source_paths();
|
|
33226
33477
|
clineAdapter = taskAdapter("cline", "Cline", "saoudrizwan.claude-dev", "SESSIONGRAPH_CLINE_HOME");
|
|
33227
33478
|
rooAdapter = taskAdapter("roo-code", "Roo Code", "rooveterinaryinc.roo-cline", "SESSIONGRAPH_ROO_HOME");
|
|
@@ -33236,17 +33487,17 @@ var init_extensions = __esm({
|
|
|
33236
33487
|
extras: (path) => [join18(dirname6(path), "sessions.json")],
|
|
33237
33488
|
revisionExtras: false,
|
|
33238
33489
|
parse(path, files) {
|
|
33239
|
-
const value =
|
|
33490
|
+
const value = object2(json3(files.get(path)));
|
|
33240
33491
|
if (!text2(value.sessionId) || !Array.isArray(value.history)) throw new Error("Unsupported Continue session.");
|
|
33241
|
-
const indexPath = join18(dirname6(path), "sessions.json"), index = files.has(indexPath) ?
|
|
33242
|
-
const meta = Array.isArray(index) ?
|
|
33492
|
+
const indexPath = join18(dirname6(path), "sessions.json"), index = files.has(indexPath) ? json3(files.get(indexPath)) : [];
|
|
33493
|
+
const meta = Array.isArray(index) ? object2(index.find((r) => r.sessionId === value.sessionId)) : {};
|
|
33243
33494
|
const messages = value.history.map((item, i) => {
|
|
33244
|
-
const row =
|
|
33495
|
+
const row = object2(item), raw = object2(row.message), message2 = conversationMessage(raw, `record:${i}`);
|
|
33245
33496
|
if (row.reasoning?.text) message2.events.push(eventFor(message2, "reasoning", "reasoning", "Recorded reasoning", text2(row.reasoning.text), { time: time(row.reasoning.startAt) || null, timeSource: time(row.reasoning.startAt) ? "recorded" : "unknown" }));
|
|
33246
33497
|
if (row.conversationSummary) message2.events.push(eventFor(message2, "summary", "compaction", "Conversation summary", text2(row.conversationSummary)));
|
|
33247
33498
|
return message2;
|
|
33248
33499
|
});
|
|
33249
|
-
const usage =
|
|
33500
|
+
const usage = object2(value.usage);
|
|
33250
33501
|
return {
|
|
33251
33502
|
nativeID: value.sessionId,
|
|
33252
33503
|
messages,
|
|
@@ -33282,7 +33533,7 @@ var init_harness_paths = __esm({
|
|
|
33282
33533
|
// server/adapters/harness-extra-formats.ts
|
|
33283
33534
|
import { basename as basename8, dirname as dirname7, join as join20 } from "node:path";
|
|
33284
33535
|
function kiroHistory(path, files) {
|
|
33285
|
-
const header =
|
|
33536
|
+
const header = object2(json3(files.get(path)));
|
|
33286
33537
|
const ide2 = basename8(path) === "session.json";
|
|
33287
33538
|
const nativeID = text2(header.session_id || header.sessionId || header.id) || (ide2 ? basename8(dirname7(path)) : "");
|
|
33288
33539
|
if (!nativeID) throw new Error("Unsupported Kiro session header.");
|
|
@@ -33291,12 +33542,12 @@ function kiroHistory(path, files) {
|
|
|
33291
33542
|
const { rows: rows2 } = jsonLines(files.get(side));
|
|
33292
33543
|
const messages = rows2.flatMap((r, i) => {
|
|
33293
33544
|
if (ide2) {
|
|
33294
|
-
const p =
|
|
33545
|
+
const p = object2(r.payload || r);
|
|
33295
33546
|
const role2 = p.type === "human" ? "user" : p.type === "ai" ? "assistant" : p.role || p.type;
|
|
33296
33547
|
const m3 = message({ ...p, role: role2 }, text2(p.id) || `message:${i}`, r.timestamp);
|
|
33297
33548
|
return m3 ? [m3] : [recordEvent(r, `event:${i}`, text2(p.type) || "Kiro event", r.timestamp, p.text)];
|
|
33298
33549
|
}
|
|
33299
|
-
const data =
|
|
33550
|
+
const data = object2(r.data), role = r.kind === "Prompt" ? "user" : r.kind === "AssistantMessage" ? "assistant" : r.kind === "ToolResults" ? "tool" : "";
|
|
33300
33551
|
if (!role) return [];
|
|
33301
33552
|
const content = Array.isArray(data.content) ? data.content.map((p) => p.kind === "text" ? { type: "text", text: p.data } : { type: "unsupported" }) : void 0;
|
|
33302
33553
|
const m = message({ role, content }, text2(data.message_id) || `message:${i}`, seconds(data.meta?.timestamp));
|
|
@@ -33340,7 +33591,7 @@ function muxHistory(path, files) {
|
|
|
33340
33591
|
function devinDesktopHistory(path, files) {
|
|
33341
33592
|
const { rows: rows2 } = jsonLines(files.get(path));
|
|
33342
33593
|
const normalized = rows2.flatMap((r) => {
|
|
33343
|
-
const n =
|
|
33594
|
+
const n = object2(r.notification);
|
|
33344
33595
|
return n.sessionUpdate ? [{ params: { sessionId: text2(r.sessionId || n.sessionId) || fileID(path).replace(/\.ndjson$/, ""), update: n }, timestamp: n.content?.metadata?.created_at ?? n.metadata?.created_at ?? n.timestamp ?? r.timestamp }] : [];
|
|
33345
33596
|
});
|
|
33346
33597
|
const history = acpHistory(path, normalized.map((r) => JSON.stringify(r)).join("\n"));
|
|
@@ -33382,7 +33633,7 @@ function museHistory(path, files) {
|
|
|
33382
33633
|
if (!meta || ids.size > 1) throw new Error("Unsupported Muse stream.");
|
|
33383
33634
|
const nativeID = [...ids][0] || basename9(dirname8(path));
|
|
33384
33635
|
const messages = rows2.flatMap((r, i) => {
|
|
33385
|
-
const event =
|
|
33636
|
+
const event = object2(r.payload?.event), body = object2(event.message);
|
|
33386
33637
|
const at2 = typeof r.recorded_at === "number" && r.recorded_at >= 1e15 ? r.recorded_at / 1e3 : typeof r.recorded_at === "number" && r.recorded_at < 1e12 ? seconds(r.recorded_at) : time(r.recorded_at);
|
|
33387
33638
|
const m = message(body, nativeText(r.sequence) || `record:${i}`, at2);
|
|
33388
33639
|
if (m) return [m];
|
|
@@ -33399,7 +33650,7 @@ function museHistory(path, files) {
|
|
|
33399
33650
|
function junieHistory(path, files) {
|
|
33400
33651
|
const { rows: rows2 } = jsonLines(files.get(path));
|
|
33401
33652
|
const messages = rows2.flatMap((r, i) => {
|
|
33402
|
-
const e10 =
|
|
33653
|
+
const e10 = object2(r.event?.agentEvent || r.event), kind = text2(e10.kind);
|
|
33403
33654
|
if (!kind || /State|Snapshot/.test(kind)) return [];
|
|
33404
33655
|
return [recordEvent(r, text2(r.id) || `event:${i}`, kind, r.timestampMs, e10.text ?? e10.prompt ?? e10.message)];
|
|
33405
33656
|
});
|
|
@@ -33407,16 +33658,16 @@ function junieHistory(path, files) {
|
|
|
33407
33658
|
return { nativeID: basename9(dirname8(path)), messages, partial: true, note: "Junie recorded agent events. State snapshots and opaque event bodies are omitted; events without an authoritative message role are not counted as user turns." };
|
|
33408
33659
|
}
|
|
33409
33660
|
function augmentHistory(path, files) {
|
|
33410
|
-
const r =
|
|
33661
|
+
const r = object2(json3(files.get(path)));
|
|
33411
33662
|
if (!text2(r.sessionId) || !Array.isArray(r.chatHistory)) throw new Error("Unsupported Augment session.");
|
|
33412
33663
|
const messages = r.chatHistory.flatMap((turn, i) => {
|
|
33413
|
-
const exchange =
|
|
33664
|
+
const exchange = object2(turn.exchange), id2 = nativeText(turn.sequenceId) || `turn:${i}`;
|
|
33414
33665
|
return [recordEvent(turn, id2, turn.completed === true ? "Completed exchange" : "Incomplete exchange", turn.finishedAt, exchange.response_text)];
|
|
33415
33666
|
});
|
|
33416
33667
|
return { nativeID: r.sessionId, messages, partial: true, session: { title: text2(r.title), created: time(r.created), model: text2(r.agentState?.modelId) || "Unknown model" }, note: "Augment saved exchange records. Typed response-node payloads and absent prompts are not reconstructed into conversations." };
|
|
33417
33668
|
}
|
|
33418
33669
|
function fxHistory(path, files) {
|
|
33419
|
-
const usage =
|
|
33670
|
+
const usage = object2(json3(files.get(path))), meta = sidecar2(files, join21(dirname8(path), "session.json"));
|
|
33420
33671
|
const id2 = text2(usage.session_id) || text2(meta.id);
|
|
33421
33672
|
if (!id2 || !usage.snapshot || meta.id && meta.id !== id2) throw new Error("Unsupported Fx session metadata.");
|
|
33422
33673
|
return {
|
|
@@ -33481,7 +33732,7 @@ var init_harness_files = __esm({
|
|
|
33481
33732
|
const value = f.get(p), { rows: rows2 } = jsonLines(value), ids = new Set(rows2.map((r) => text2(r.sessionId)).filter(Boolean));
|
|
33482
33733
|
if (ids.size !== 1) throw new Error("Headless capture needs one explicit session identity.");
|
|
33483
33734
|
const messages = rows2.flatMap((r, i) => {
|
|
33484
|
-
const m = message(
|
|
33735
|
+
const m = message(object2(r.message), text2(r.message?.id) || `record:${i}`);
|
|
33485
33736
|
return m ? [m] : [];
|
|
33486
33737
|
});
|
|
33487
33738
|
return { nativeID: [...ids][0], messages, partial: true, note: "Previously captured MiniMax stream JSON only; no command is executed. User input and transient streaming records may be absent." };
|
|
@@ -33506,6 +33757,14 @@ var init_harness_files = __esm({
|
|
|
33506
33757
|
// server/adapters/harness-databases.ts
|
|
33507
33758
|
import { lstat as lstat6, readFile as readFile4 } from "node:fs/promises";
|
|
33508
33759
|
import { isAbsolute as isAbsolute6, join as join22 } from "node:path";
|
|
33760
|
+
function hermesContent(value) {
|
|
33761
|
+
if (typeof value !== "string" || !value.startsWith("\0json:")) return value;
|
|
33762
|
+
try {
|
|
33763
|
+
return JSON.parse(value.slice(6));
|
|
33764
|
+
} catch {
|
|
33765
|
+
return value;
|
|
33766
|
+
}
|
|
33767
|
+
}
|
|
33509
33768
|
function dbPaths(id2, defaults, match2) {
|
|
33510
33769
|
return async () => {
|
|
33511
33770
|
const override = sourcePath(id2) || process.env[`SESSIONGRAPH_${id2.replace(/-/g, "_").toUpperCase()}_HISTORY_DIR`];
|
|
@@ -33532,7 +33791,7 @@ function forkStore(id2, name, defaultPath, desktop) {
|
|
|
33532
33791
|
parse(db2, r) {
|
|
33533
33792
|
if (desktop !== void 0 && text2(r.version).startsWith("desktop-") !== desktop) return;
|
|
33534
33793
|
const messages = rows(db2, "message", ["id", "data", "time_created"], ["session_id", r.id], "time_created").map((m) => {
|
|
33535
|
-
const body =
|
|
33794
|
+
const body = object2(sqliteJSON(m.data));
|
|
33536
33795
|
let content = body.parts ?? body.content;
|
|
33537
33796
|
if (hasTable(db2, "part")) content = rows(db2, "part", ["id", "data"], ["message_id", m.id], "id").map((p) => sqliteJSON(p.data));
|
|
33538
33797
|
if (Array.isArray(content)) content = content.flatMap((p) => {
|
|
@@ -33548,7 +33807,7 @@ function forkStore(id2, name, defaultPath, desktop) {
|
|
|
33548
33807
|
}
|
|
33549
33808
|
};
|
|
33550
33809
|
}
|
|
33551
|
-
var
|
|
33810
|
+
var millisOrSeconds, hermes, goose, openclaw, zed, devin, crushDirectories, crush, octofriend, unsloth, kiro, databaseHarnessAdapters;
|
|
33552
33811
|
var init_harness_databases = __esm({
|
|
33553
33812
|
"server/adapters/harness-databases.ts"() {
|
|
33554
33813
|
"use strict";
|
|
@@ -33560,11 +33819,11 @@ var init_harness_databases = __esm({
|
|
|
33560
33819
|
init_harness_paths();
|
|
33561
33820
|
init_harness_files();
|
|
33562
33821
|
init_source_paths();
|
|
33563
|
-
parsedContent = (v3) => typeof v3 === "string" && /^[\[{]/.test(v3.trim()) ? optionalJSON(v3) : v3;
|
|
33564
33822
|
millisOrSeconds = (v3) => typeof v3 === "number" && v3 > 0 && v3 < 1e10 ? seconds(v3) : time(v3);
|
|
33565
33823
|
hermes = {
|
|
33566
33824
|
id: "hermes",
|
|
33567
33825
|
name: "Hermes Agent",
|
|
33826
|
+
version: 3,
|
|
33568
33827
|
paths: async () => (await historyFiles(harnessRoots("hermes", () => [envHome("HERMES_HOME", ".hermes")])(), (p) => p === "state.db" || /^profiles\/[^/]+\/state\.db$/.test(p))).files,
|
|
33569
33828
|
table: "sessions",
|
|
33570
33829
|
key: "id",
|
|
@@ -33572,7 +33831,7 @@ var init_harness_databases = __esm({
|
|
|
33572
33831
|
parse(db2, r) {
|
|
33573
33832
|
const messages = rows(db2, "messages", ["id", "message_uid", "role", "content", "timestamp", "tool_call_id", "tool_calls", "tool_name", "_compressed_summary"], ["session_id", r.id], "id").map((m) => {
|
|
33574
33833
|
if (m._compressed_summary) return recordEvent(m, text2(m.message_uid) || nativeText(m.id), "Context summary", seconds(m.timestamp), m.content);
|
|
33575
|
-
return conversationMessage({ role: m.role, content:
|
|
33834
|
+
return conversationMessage({ role: m.role, content: hermesContent(m.content), timestamp: seconds(m.timestamp), tool_call_id: m.tool_call_id, toolCalls: optionalJSON(m.tool_calls), toolName: m.tool_name }, text2(m.message_uid) || nativeText(m.id));
|
|
33576
33835
|
});
|
|
33577
33836
|
const h3 = sessionHistory({ ...r, created_at: seconds(r.started_at), updated_at: seconds(r.last_activity_at), provider: r.billing_provider }, messages, "Hermes saved message rows, including retained summaries. Compression/reset parent links are not subagent ancestry. Session usage aggregates are not used as message times.");
|
|
33578
33837
|
if (r.source === "subagent") h3.parent = text2(r.parent_session_id) || void 0;
|
|
@@ -33609,9 +33868,9 @@ var init_harness_databases = __esm({
|
|
|
33609
33868
|
parse(db2, r) {
|
|
33610
33869
|
const events = rows(db2, "transcript_events", ["seq", "event_json", "event_zstd"], ["session_id", r.session_id], "seq");
|
|
33611
33870
|
const messages = events.flatMap((e10) => {
|
|
33612
|
-
const raw =
|
|
33871
|
+
const raw = object2(sqliteJSON(e10.event_json ?? e10.event_zstd));
|
|
33613
33872
|
if (raw.type !== "message") return [];
|
|
33614
|
-
const m = message(
|
|
33873
|
+
const m = message(object2(raw.message), text2(raw.id) || `event:${e10.seq}`, raw.timestamp ?? raw.message?.timestamp);
|
|
33615
33874
|
return m ? [m] : [];
|
|
33616
33875
|
});
|
|
33617
33876
|
return sessionHistory({ ...r, id: r.session_id, provider: r.model_provider }, messages, "OpenClaw authoritative transcript events, including zstd payloads. Database sessions take precedence over migrated JSONL copies. Session rollover and event-parent links are not session ancestry.");
|
|
@@ -33626,11 +33885,11 @@ var init_harness_databases = __esm({
|
|
|
33626
33885
|
fields: ["id", "summary", "created_at", "updated_at", "data_type", "data", "folder_paths"],
|
|
33627
33886
|
parse(db2, r) {
|
|
33628
33887
|
if (!["json", "zstd"].includes(r.data_type)) throw new Error("Unsupported Zed encoding.");
|
|
33629
|
-
const body =
|
|
33888
|
+
const body = object2(sqliteJSON(r.data));
|
|
33630
33889
|
if (body.imported === true) return;
|
|
33631
33890
|
if (!Array.isArray(body.messages)) throw new Error("Unsupported Zed thread.");
|
|
33632
33891
|
const messages = body.messages.map((raw, i) => {
|
|
33633
|
-
const user =
|
|
33892
|
+
const user = object2(raw.User), agent = object2(raw.Agent), b = raw.User ? user : agent;
|
|
33634
33893
|
if (!raw.User && !raw.Agent) return recordEvent(raw, `message:${i}`, "Context checkpoint", 0, raw.Compaction?.Summary);
|
|
33635
33894
|
const content = (Array.isArray(b.content) ? b.content : []).map((p) => typeof p.Text === "string" ? { type: "text", text: p.Text } : p.Thinking ? { type: "thinking", thinking: p.Thinking.text } : p.ToolUse ? { type: "tool_use", ...p.ToolUse } : { type: "unsupported" });
|
|
33636
33895
|
return conversationMessage({ role: raw.User ? "user" : "assistant", content }, text2(b.id) || `message:${i}`);
|
|
@@ -33648,7 +33907,7 @@ var init_harness_databases = __esm({
|
|
|
33648
33907
|
fields: ["id", "working_directory", "model", "title", "created_at", "last_activity_at"],
|
|
33649
33908
|
parse(db2, r) {
|
|
33650
33909
|
const messages = rows(db2, "message_nodes", ["node_id", "chat_message", "created_at"], ["session_id", r.id], "row_id").flatMap((m) => {
|
|
33651
|
-
const raw =
|
|
33910
|
+
const raw = object2(sqliteJSON(m.chat_message)), result = message(raw, nativeText(m.node_id), millisOrSeconds(m.created_at));
|
|
33652
33911
|
return result ? [result] : [recordEvent(raw, nativeText(m.node_id), "Devin message node", millisOrSeconds(m.created_at))];
|
|
33653
33912
|
});
|
|
33654
33913
|
return sessionHistory({ ...r, created_at: millisOrSeconds(r.created_at), updated_at: millisOrSeconds(r.last_activity_at) }, messages, "Devin saved message nodes. All retained in-session branches are included; node-parent edges are not session ancestry.");
|
|
@@ -33711,9 +33970,9 @@ var init_harness_databases = __esm({
|
|
|
33711
33970
|
const row = rows(db2, "llm_irs", ["json"], ["id", item.llm_ir_id], void 0, 1)[0];
|
|
33712
33971
|
bytes2 += text2(row?.json).length;
|
|
33713
33972
|
if (bytes2 > 32e6) throw new Error("Octofriend session exceeds the snapshot limit.");
|
|
33714
|
-
const payload =
|
|
33973
|
+
const payload = object2(sqliteJSON(row?.json));
|
|
33715
33974
|
if (payload.version !== "octo-llm-ir/v1") throw new Error("Unsupported Octofriend IR version.");
|
|
33716
|
-
const ir =
|
|
33975
|
+
const ir = object2(payload.ir), content = Array.isArray(ir.content) ? ir.content.map((p) => p.type === "text" ? { type: "text", text: p.content } : p) : ir.content;
|
|
33717
33976
|
const m = message({ ...ir, content, role: ir.role === "tool-output" ? "tool" : ir.role }, nativeText(node.id), node.created_at);
|
|
33718
33977
|
messages.push(m || recordEvent(ir, nativeText(node.id), text2(ir.role), node.created_at));
|
|
33719
33978
|
}
|
|
@@ -33747,13 +34006,13 @@ var init_harness_databases = __esm({
|
|
|
33747
34006
|
key: "conversation_id",
|
|
33748
34007
|
fields: ["key", "conversation_id", "value"],
|
|
33749
34008
|
parse(db2, r) {
|
|
33750
|
-
const body =
|
|
34009
|
+
const body = object2(sqliteJSON(r.value));
|
|
33751
34010
|
if (!Array.isArray(body.history)) throw new Error("Unsupported Kiro conversation.");
|
|
33752
34011
|
const messages = body.history.flatMap((turn, i) => {
|
|
33753
|
-
const result = [], input =
|
|
34012
|
+
const result = [], input = object2(turn.user?.content), output2 = object2(turn.assistant?.Response || turn.assistant?.ToolUse);
|
|
33754
34013
|
if (typeof input.Prompt?.prompt === "string") result.push(conversationMessage({ role: "user", content: input.Prompt.prompt }, `turn:${i}:user`));
|
|
33755
34014
|
if (input.ToolUseResults) result.push(conversationMessage({ role: "tool", content: input.ToolUseResults }, `turn:${i}:tool`));
|
|
33756
|
-
if (typeof
|
|
34015
|
+
if (typeof output2.content === "string") result.push(conversationMessage({ role: "assistant", content: output2.content, timestamp: turn.request_metadata?.stream_end_timestamp_ms }, `turn:${i}:assistant`));
|
|
33757
34016
|
return result;
|
|
33758
34017
|
});
|
|
33759
34018
|
const created = body.history.map((t) => time(t.request_metadata?.request_start_timestamp_ms)).find(Boolean);
|
|
@@ -33780,7 +34039,6 @@ var init_harness_databases = __esm({
|
|
|
33780
34039
|
// server/adapters/harness-metadata.ts
|
|
33781
34040
|
import { basename as basename10 } from "node:path";
|
|
33782
34041
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
33783
|
-
import { lstat as lstat7 } from "node:fs/promises";
|
|
33784
34042
|
function protoFields(value) {
|
|
33785
34043
|
if (value.length > 2e6) throw new Error("Trajectory metadata exceeds 2 MB.");
|
|
33786
34044
|
const fields2 = /* @__PURE__ */ new Map();
|
|
@@ -33811,7 +34069,7 @@ function protoFields(value) {
|
|
|
33811
34069
|
}
|
|
33812
34070
|
return fields2;
|
|
33813
34071
|
}
|
|
33814
|
-
var nested, antigravityDatabaseAdapters, antigravityCacheAdapter
|
|
34072
|
+
var nested, antigravityDatabaseAdapters, antigravityCacheAdapter;
|
|
33815
34073
|
var init_harness_metadata = __esm({
|
|
33816
34074
|
"server/adapters/harness-metadata.ts"() {
|
|
33817
34075
|
"use strict";
|
|
@@ -33834,15 +34092,15 @@ var init_harness_metadata = __esm({
|
|
|
33834
34092
|
const sec = timestamp.get(1), nano = timestamp.get(2);
|
|
33835
34093
|
const created = typeof sec === "bigint" && sec > 0n && sec < 8640000000000n ? time(Number(sec) * 1e3 + (typeof nano === "bigint" && nano < 1000000000n ? Number(nano) / 1e6 : 0)) : 0;
|
|
33836
34094
|
const uri = nested(fields2.get(1)).get(1);
|
|
33837
|
-
let
|
|
34095
|
+
let directory3 = "";
|
|
33838
34096
|
if (uri instanceof Uint8Array) {
|
|
33839
34097
|
try {
|
|
33840
|
-
|
|
34098
|
+
directory3 = fileURLToPath4(Buffer.from(uri).toString("utf8"));
|
|
33841
34099
|
} catch {
|
|
33842
34100
|
}
|
|
33843
34101
|
}
|
|
33844
34102
|
if (!created) throw new Error("Trajectory creation time is unavailable.");
|
|
33845
|
-
return { nativeID: basename10(path, ".db"), messages: [], partial: true, session: { created, directory:
|
|
34103
|
+
return { nativeID: basename10(path, ".db"), messages: [], partial: true, session: { created, directory: directory3 }, note: "Native Antigravity trajectory identity and creation metadata only. Protobuf conversation/step bodies are opaque; no message text, generation-time guesses, or usage-derived turns are imported." };
|
|
33846
34104
|
}
|
|
33847
34105
|
}));
|
|
33848
34106
|
antigravityCacheAdapter = localFileAdapter({
|
|
@@ -33861,28 +34119,6 @@ var init_harness_metadata = __esm({
|
|
|
33861
34119
|
return { nativeID: [...ids][0], messages: [], partial: true, session: { created, model: text2(rows2.find((r) => r.modelId)?.modelId) || "Unknown model" }, note: "Previously synced Antigravity session identity; placement uses earliest recorded usage date. This cache has no conversation bodies. SessionGraph never runs sync or contacts the language server." };
|
|
33862
34120
|
}
|
|
33863
34121
|
});
|
|
33864
|
-
usageOnlyAdapters = [
|
|
33865
|
-
{ id: "reasonix", name: "Reasonix", roots: () => [envHome("REASONIX_STATE_HOME", ".reasonix", "stats"), envHome("REASONIX_HOME", ".reasonix", "stats")], note: "Request statistics lack conversation identities and text. Reasonix transcript import is not yet supported." },
|
|
33866
|
-
{ id: "trae", name: "Trae / Trae Solo", roots: () => [tokscalePath("trae-cache/sessions")], note: "The Tokscale cache contains account usage, not local conversations." },
|
|
33867
|
-
{ id: "warp", name: "Warp / Oz", roots: () => [tokscalePath("warp-cache")], note: "The Tokscale cache contains aggregate requests and spend, not local conversations." },
|
|
33868
|
-
{ id: "lm-studio", name: "LM Studio", roots: () => [envHome("LM_STUDIO_HOME", ".lmstudio", "server-logs")], note: "Server logs contain final-response usage, not retained prompts or responses." },
|
|
33869
|
-
{ id: "hindsight", name: "Hindsight", roots: () => [envHome("HINDSIGHT_HOME", ".hindsight", "usage")], note: "Synced memory-operation usage is not agent conversation history." }
|
|
33870
|
-
].map((source) => ({
|
|
33871
|
-
id: source.id,
|
|
33872
|
-
name: source.name,
|
|
33873
|
-
description: `Detection only \xB7 ${source.note}`,
|
|
33874
|
-
capabilities: { history: false, forks: false, children: false, files: false },
|
|
33875
|
-
async detect() {
|
|
33876
|
-
for (const p of harnessRoots(source.id, source.roots)()) if ((await lstat7(p).catch(() => void 0))?.isDirectory()) return true;
|
|
33877
|
-
return false;
|
|
33878
|
-
},
|
|
33879
|
-
async discover() {
|
|
33880
|
-
return { sessions: [], projects: [], warnings: [source.note] };
|
|
33881
|
-
},
|
|
33882
|
-
async read() {
|
|
33883
|
-
throw new Error(source.note);
|
|
33884
|
-
}
|
|
33885
|
-
}));
|
|
33886
34122
|
}
|
|
33887
34123
|
});
|
|
33888
34124
|
|
|
@@ -33910,7 +34146,7 @@ var init_adapters = __esm({
|
|
|
33910
34146
|
init_harness_databases();
|
|
33911
34147
|
init_harness_metadata();
|
|
33912
34148
|
init_sqlite_histories();
|
|
33913
|
-
extra = [...databaseHarnessAdapters, ...fileHarnessAdapters, antigravityCacheAdapter, ...antigravityDatabaseAdapters
|
|
34149
|
+
extra = [...databaseHarnessAdapters, ...fileHarnessAdapters, antigravityCacheAdapter, ...antigravityDatabaseAdapters];
|
|
33914
34150
|
grouped = /* @__PURE__ */ new Map();
|
|
33915
34151
|
for (const adapter of extra) grouped.set(adapter.id, [...grouped.get(adapter.id) || [], adapter]);
|
|
33916
34152
|
adapters = [opencodeAdapter, claudeAdapter, codexAdapter, t3CodeAdapter, cursorAdapter, geminiAdapter, qwenAdapter, piAdapter, copilotAdapter, copilotChatAdapter, clineAdapter, rooAdapter, kiloAdapter, continueAdapter, ...[...grouped.values()].map((parts) => parts.length === 1 ? parts[0] : combineAdapters(parts))];
|
|
@@ -33955,194 +34191,12 @@ init_activity();
|
|
|
33955
34191
|
// server/event-store.ts
|
|
33956
34192
|
init_events();
|
|
33957
34193
|
import { randomUUID } from "node:crypto";
|
|
33958
|
-
var EVENT_SCHEMA = `CREATE TABLE IF NOT EXISTS timeline_items (
|
|
33959
|
-
session_id TEXT NOT NULL REFERENCES sessions(id) ON DELETE CASCADE, id TEXT NOT NULL, message_id TEXT NOT NULL,
|
|
33960
|
-
ordinal INTEGER NOT NULL, kind TEXT NOT NULL, role TEXT, time REAL, call_id TEXT, name TEXT NOT NULL, preview TEXT NOT NULL, data TEXT NOT NULL,
|
|
33961
|
-
PRIMARY KEY(session_id,id));
|
|
33962
|
-
CREATE INDEX IF NOT EXISTS timeline_order ON timeline_items(session_id,ordinal);
|
|
33963
|
-
CREATE INDEX IF NOT EXISTS timeline_time ON timeline_items(session_id,time);
|
|
33964
|
-
CREATE INDEX IF NOT EXISTS timeline_calls ON timeline_items(session_id,call_id);
|
|
33965
|
-
CREATE TABLE IF NOT EXISTS timeline_coverage (session_id TEXT PRIMARY KEY REFERENCES sessions(id) ON DELETE CASCADE, partial INTEGER NOT NULL, note TEXT, revision TEXT NOT NULL);`;
|
|
33966
|
-
function writeEvents(db2, id2, rows2) {
|
|
33967
|
-
db2.prepare("DELETE FROM timeline_items WHERE session_id=?").run(id2);
|
|
33968
|
-
const insert = db2.prepare("INSERT OR IGNORE INTO timeline_items VALUES (?,?,?,?,?,?,?,?,?,?,?)");
|
|
33969
|
-
let ordinal = 0, bytes2 = 0, partial = false, legacy = false, limited = false;
|
|
33970
|
-
for (const row of rows2) {
|
|
33971
|
-
const message2 = JSON.parse(String(row.data));
|
|
33972
|
-
legacy ||= !message2.events;
|
|
33973
|
-
for (const event of normalizedEvents(message2, id2)) {
|
|
33974
|
-
const item = { ...event, ordinal: ordinal++ }, data = JSON.stringify(item);
|
|
33975
|
-
bytes2 += Buffer.byteLength(data);
|
|
33976
|
-
if (ordinal > 2e5 || bytes2 > 32e6) {
|
|
33977
|
-
limited = true;
|
|
33978
|
-
break;
|
|
33979
|
-
}
|
|
33980
|
-
partial ||= Boolean(item.partial);
|
|
33981
|
-
const preview = (item.text || item.input || item.output || item.name).replace(/\s+/g, " ").slice(0, 180);
|
|
33982
|
-
insert.run(id2, item.id, item.messageID, item.ordinal, item.kind, item.role || null, item.time, item.callID || null, item.name, preview, data);
|
|
33983
|
-
}
|
|
33984
|
-
if (limited) break;
|
|
33985
|
-
}
|
|
33986
|
-
const note = [legacy ? "Some items were reconstructed from an older flattened import; tool inputs/results cannot be paired there. Refresh sources to import structured events." : "", limited ? "Event history limited to 200,000 items / 32 MB per session." : "", partial ? "Some event content is missing, unsupported, or shortened." : ""].filter(Boolean).join(" ");
|
|
33987
|
-
db2.prepare("INSERT OR REPLACE INTO timeline_coverage VALUES (?,?,?,?)").run(id2, Number(partial || legacy || limited), note || null, randomUUID());
|
|
33988
|
-
}
|
|
33989
|
-
var summaryColumns = "id,kind,role,name,time,ordinal,preview,json_extract(data,'$.timeSource') AS timeSource,json_extract(data,'$.status') AS status,json_extract(data,'$.partial') AS partial";
|
|
33990
|
-
function eventSummary(row) {
|
|
33991
|
-
return { id: String(row.id), kind: row.kind, role: row.role, name: String(row.name), time: row.time === null ? null : Number(row.time), timeSource: row.timeSource, ordinal: Number(row.ordinal), preview: String(row.preview), status: row.status, partial: Boolean(row.partial) };
|
|
33992
|
-
}
|
|
33993
|
-
var EventReadError = class extends Error {
|
|
33994
|
-
constructor(message2, status2) {
|
|
33995
|
-
super(message2);
|
|
33996
|
-
this.status = status2;
|
|
33997
|
-
}
|
|
33998
|
-
status;
|
|
33999
|
-
};
|
|
34000
|
-
var filters = { all: "1", messages: "kind='message' AND role IN ('user','assistant')", tools: "kind IN ('tool_call','tool_result')", events: "kind NOT IN ('message','tool_call','tool_result')", untimed: "time IS NULL" };
|
|
34001
|
-
function coverage(db2, session) {
|
|
34002
|
-
const row = db2.prepare("SELECT * FROM timeline_coverage WHERE session_id=?").get(session.id);
|
|
34003
|
-
return { revision: String(row?.revision || "pending"), partial: Boolean(row?.partial) || session.coverage?.history !== "complete", note: [row?.note, session.coverage?.note].filter(Boolean).join(" ") || void 0 };
|
|
34004
|
-
}
|
|
34005
|
-
function readEventMarkers(db2, session) {
|
|
34006
|
-
const end = Math.max(session.created, session.activity?.lastMessageAt || session.created);
|
|
34007
|
-
const totals = db2.prepare(`SELECT count(*) AS total, count(*) FILTER (WHERE time IS NULL) AS untimed, count(*) FILTER (WHERE time<? OR time>?) AS outside FROM timeline_items WHERE session_id=? AND (${filters.messages})`).get(session.created, end, session.id);
|
|
34008
|
-
const rows2 = db2.prepare(`SELECT ${summaryColumns} FROM timeline_items WHERE session_id=? AND (${filters.messages}) AND time>=? AND time<=? ORDER BY time DESC,ordinal DESC`).all(session.id, session.created, end);
|
|
34009
|
-
return { sessionID: session.id, ...coverage(db2, session), items: rows2.reverse().map(eventSummary), total: Number(totals.total), untimed: Number(totals.untimed), outsideLifetime: Number(totals.outside), limited: Number(totals.total) - Number(totals.untimed) - Number(totals.outside) > rows2.length };
|
|
34010
|
-
}
|
|
34011
|
-
function readEvents(db2, session, options = {}) {
|
|
34012
|
-
const state2 = coverage(db2, session), filter = options.filter || "all", size = 60;
|
|
34013
|
-
if (!Object.hasOwn(filters, filter)) throw new EventReadError("Invalid event filter.", 400);
|
|
34014
|
-
const where = filters[filter];
|
|
34015
|
-
if (options.revision && options.revision !== state2.revision) throw new EventReadError("Saved history changed. Reload the event explorer.", 409);
|
|
34016
|
-
let offset = 0;
|
|
34017
|
-
if (options.cursor) {
|
|
34018
|
-
try {
|
|
34019
|
-
if (options.cursor.length > 512) throw new Error();
|
|
34020
|
-
const cursor2 = JSON.parse(Buffer.from(options.cursor, "base64url").toString());
|
|
34021
|
-
if (!Number.isSafeInteger(cursor2.offset) || cursor2.offset < 0 || cursor2.offset > 2e5 || cursor2.filter !== filter || typeof cursor2.revision !== "string") throw new Error();
|
|
34022
|
-
if (cursor2.revision !== state2.revision) throw new EventReadError("Saved history changed. Reload the event explorer.", 409);
|
|
34023
|
-
offset = cursor2.offset;
|
|
34024
|
-
} catch (error) {
|
|
34025
|
-
if (error instanceof EventReadError) throw error;
|
|
34026
|
-
throw new EventReadError("Invalid event cursor.", 400);
|
|
34027
|
-
}
|
|
34028
|
-
}
|
|
34029
|
-
let selected;
|
|
34030
|
-
if (options.item) {
|
|
34031
|
-
const row = db2.prepare(`SELECT data FROM timeline_items WHERE session_id=? AND id=? AND (${where})`).get(session.id, options.item);
|
|
34032
|
-
if (!row) throw new EventReadError("This event is not in the saved session or current filter.", 404);
|
|
34033
|
-
selected = JSON.parse(String(row.data));
|
|
34034
|
-
const before = Number(db2.prepare(`SELECT count(*) AS n FROM timeline_items WHERE session_id=? AND ordinal<? AND (${where})`).get(session.id, selected.ordinal).n);
|
|
34035
|
-
offset = Math.floor(before / size) * size;
|
|
34036
|
-
}
|
|
34037
|
-
const total = Number(db2.prepare(`SELECT count(*) AS n FROM timeline_items WHERE session_id=? AND (${where})`).get(session.id).n);
|
|
34038
|
-
const items = db2.prepare(`SELECT ${summaryColumns} FROM timeline_items WHERE session_id=? AND (${where}) ORDER BY ordinal LIMIT ? OFFSET ?`).all(session.id, size, offset).map(eventSummary);
|
|
34039
|
-
if (!selected && items.length) selected = JSON.parse(String(db2.prepare("SELECT data FROM timeline_items WHERE session_id=? AND id=?").get(session.id, items[0].id).data));
|
|
34040
|
-
const related = selected?.callID ? db2.prepare(`SELECT ${summaryColumns} FROM timeline_items WHERE session_id=? AND call_id=? AND id<>? ORDER BY ordinal LIMIT 21`).all(session.id, selected.callID, selected.id).map(eventSummary) : [];
|
|
34041
|
-
const previousItem = selected ? db2.prepare(`SELECT id FROM timeline_items WHERE session_id=? AND ordinal<? AND (${where}) ORDER BY ordinal DESC LIMIT 1`).get(session.id, selected.ordinal)?.id : void 0;
|
|
34042
|
-
const nextItem = selected ? db2.prepare(`SELECT id FROM timeline_items WHERE session_id=? AND ordinal>? AND (${where}) ORDER BY ordinal LIMIT 1`).get(session.id, selected.ordinal)?.id : void 0;
|
|
34043
|
-
const cursor = (position) => Buffer.from(JSON.stringify({ revision: state2.revision, filter, offset: position })).toString("base64url");
|
|
34044
|
-
return {
|
|
34045
|
-
sessionID: session.id,
|
|
34046
|
-
...state2,
|
|
34047
|
-
items,
|
|
34048
|
-
total,
|
|
34049
|
-
offset,
|
|
34050
|
-
selected,
|
|
34051
|
-
related: related.slice(0, 20),
|
|
34052
|
-
relatedPartial: related.length > 20,
|
|
34053
|
-
previousItem: previousItem ? String(previousItem) : void 0,
|
|
34054
|
-
nextItem: nextItem ? String(nextItem) : void 0,
|
|
34055
|
-
nextCursor: offset + size < total ? cursor(offset + size) : null,
|
|
34056
|
-
previousCursor: offset > 0 ? cursor(Math.max(0, offset - size)) : null
|
|
34057
|
-
};
|
|
34058
|
-
}
|
|
34059
34194
|
|
|
34060
|
-
// packages/core/src/
|
|
34061
|
-
var
|
|
34062
|
-
autoImport: true,
|
|
34063
|
-
muted: false,
|
|
34064
|
-
clickSounds: true,
|
|
34065
|
-
clickVolume: 35,
|
|
34066
|
-
motion: "system",
|
|
34067
|
-
view: "3d",
|
|
34068
|
-
density: "comfortable",
|
|
34069
|
-
panelOpacity: 90,
|
|
34070
|
-
quality: "balanced",
|
|
34071
|
-
bloom: 32,
|
|
34072
|
-
stars: true,
|
|
34073
|
-
labels: true,
|
|
34074
|
-
nodeScale: 100,
|
|
34075
|
-
focusDimming: true,
|
|
34076
|
-
trails: "all",
|
|
34077
|
-
trailOpacity: 34,
|
|
34078
|
-
trailFlow: false,
|
|
34079
|
-
trailSpeed: 25,
|
|
34080
|
-
relationships: true,
|
|
34081
|
-
messageDots: true,
|
|
34082
|
-
playbackSpeed: 1
|
|
34083
|
-
});
|
|
34084
|
-
var choices = { motion: ["system", "on", "off"], view: ["3d", "2d"], density: ["comfortable", "compact"], quality: ["performance", "balanced", "high"], trails: ["all", "selected", "off"] };
|
|
34085
|
-
var ranges = { clickVolume: [0, 100], panelOpacity: [55, 100], bloom: [0, 75], nodeScale: [60, 180], trailOpacity: [0, 100], trailSpeed: [10, 100], playbackSpeed: [0.25, 3] };
|
|
34086
|
-
function normalizePreferences(value) {
|
|
34087
|
-
const result = { ...DEFAULT_PREFERENCES };
|
|
34088
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return result;
|
|
34089
|
-
const input = value;
|
|
34090
|
-
for (const key of Object.keys(result)) {
|
|
34091
|
-
const item = input[key];
|
|
34092
|
-
if (key in choices) {
|
|
34093
|
-
if (choices[key].includes(item)) Object.assign(result, { [key]: item });
|
|
34094
|
-
} else if (key in ranges) {
|
|
34095
|
-
const [min, max] = ranges[key];
|
|
34096
|
-
if (typeof item === "number" && Number.isFinite(item)) Object.assign(result, { [key]: Math.max(min, Math.min(max, item)) });
|
|
34097
|
-
} else if (typeof item === "boolean") Object.assign(result, { [key]: item });
|
|
34098
|
-
}
|
|
34099
|
-
return result;
|
|
34100
|
-
}
|
|
34101
|
-
|
|
34102
|
-
// packages/core/src/view-state.ts
|
|
34103
|
-
var DEFAULT_VIEW_STATE = Object.freeze({
|
|
34104
|
-
sourceID: "",
|
|
34105
|
-
projectID: "",
|
|
34106
|
-
directory: "",
|
|
34107
|
-
days: 0,
|
|
34108
|
-
fromDate: "",
|
|
34109
|
-
toDate: "",
|
|
34110
|
-
includeChildren: true,
|
|
34111
|
-
includeArchived: false
|
|
34112
|
-
});
|
|
34113
|
-
var validDate = (value) => typeof value === "string" && /^\d{4}-\d{2}-\d{2}$/.test(value) && Number.isFinite(Date.parse(value)) && new Date(value).toISOString().slice(0, 10) === value;
|
|
34114
|
-
function normalizeViewState(value) {
|
|
34115
|
-
const result = { ...DEFAULT_VIEW_STATE };
|
|
34116
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return result;
|
|
34117
|
-
const input = value;
|
|
34118
|
-
for (const key of ["sourceID", "projectID", "directory"]) if (typeof input[key] === "string" && input[key].length <= 4096) result[key] = input[key];
|
|
34119
|
-
if ([0, 7, 30, 90].includes(input.days)) result.days = input.days;
|
|
34120
|
-
for (const key of ["includeChildren", "includeArchived"]) if (typeof input[key] === "boolean") result[key] = input[key];
|
|
34121
|
-
for (const key of ["fromDate", "toDate"]) if (validDate(input[key])) result[key] = input[key];
|
|
34122
|
-
if (result.fromDate && result.toDate && result.fromDate > result.toDate) {
|
|
34123
|
-
result.fromDate = "";
|
|
34124
|
-
result.toDate = "";
|
|
34125
|
-
}
|
|
34126
|
-
return result;
|
|
34127
|
-
}
|
|
34195
|
+
// packages/core/src/commits.ts
|
|
34196
|
+
var abbreviatedSHA = (sha) => sha.length !== 40 && sha.length !== 64;
|
|
34128
34197
|
|
|
34129
|
-
//
|
|
34130
|
-
|
|
34131
|
-
const owners = /* @__PURE__ */ new Map();
|
|
34132
|
-
for (const session of sessions) {
|
|
34133
|
-
if (session.source !== "t3-code" || session.coverage?.history !== "complete" || !session.activity?.userMessages) continue;
|
|
34134
|
-
for (const id2 of session.linkedSessionIDs || []) owners.set(id2, [...owners.get(id2) || [], session.id]);
|
|
34135
|
-
}
|
|
34136
|
-
const unique = new Map([...owners].flatMap(([native, ids]) => ids.length === 1 ? [[native, ids[0]]] : []));
|
|
34137
|
-
return sessions.filter((session) => !unique.has(session.id)).map((session) => ({
|
|
34138
|
-
...session,
|
|
34139
|
-
parentID: session.parentID ? unique.get(session.parentID) || session.parentID : void 0,
|
|
34140
|
-
forkID: session.forkID ? unique.get(session.forkID) || session.forkID : void 0
|
|
34141
|
-
}));
|
|
34142
|
-
}
|
|
34143
|
-
function sessionMatchesSource(session, source) {
|
|
34144
|
-
return !source || session.source === source || Boolean(session.source === "t3-code" && session.linkedSessionIDs?.some((id2) => id2.startsWith(`${source}:`)));
|
|
34145
|
-
}
|
|
34198
|
+
// server/commit-store.ts
|
|
34199
|
+
init_commit_extraction();
|
|
34146
34200
|
|
|
34147
34201
|
// server/library-query.ts
|
|
34148
34202
|
import { createHash as createHash2 } from "node:crypto";
|
|
@@ -34159,10 +34213,10 @@ function hash(text3) {
|
|
|
34159
34213
|
value ^= value >>> 16;
|
|
34160
34214
|
return (value >>> 0) / 4294967295;
|
|
34161
34215
|
}
|
|
34162
|
-
function directoryLabel(
|
|
34163
|
-
return directoryPath(
|
|
34216
|
+
function directoryLabel(directory3) {
|
|
34217
|
+
return directoryPath(directory3).split("/").at(-1) || "/";
|
|
34164
34218
|
}
|
|
34165
|
-
var directoryPath = (
|
|
34219
|
+
var directoryPath = (directory3) => (/^(?:[a-z]:[\\/]|\\\\)/i.test(directory3) ? directory3.replace(/\\/g, "/") : directory3).replace(/\/+$/, "") || (directory3.startsWith("/") ? "/" : "");
|
|
34166
34220
|
var laneKey = (session) => session.directory ? JSON.stringify(["directory", directoryPath(session.directory)]) : JSON.stringify(["project", session.source || "opencode", session.projectID || session.id]);
|
|
34167
34221
|
var sessionEnd = (session) => Math.max(session.created, session.activity?.lastMessageAt || session.created);
|
|
34168
34222
|
var timeX = (time3, graph) => {
|
|
@@ -34199,13 +34253,13 @@ function makeGraph(sessions, projects, previous) {
|
|
|
34199
34253
|
const z4 = Math.sin(angle) * distance * 0.7;
|
|
34200
34254
|
const color = PALETTE[index % PALETTE.length];
|
|
34201
34255
|
const project2 = projects.find((p) => p.id === group[0].projectID);
|
|
34202
|
-
const
|
|
34256
|
+
const directory3 = group[0].directory;
|
|
34203
34257
|
const lane = {
|
|
34204
34258
|
key,
|
|
34205
34259
|
slot: index,
|
|
34206
|
-
label:
|
|
34260
|
+
label: directory3 ? directoryLabel(directory3) : project2?.name || group[0].projectID || "Unknown directory",
|
|
34207
34261
|
color,
|
|
34208
|
-
kind:
|
|
34262
|
+
kind: directory3 && worktrees.has(directoryPath(directory3)) ? "worktree" : "directory",
|
|
34209
34263
|
y,
|
|
34210
34264
|
z: z4,
|
|
34211
34265
|
nodes: []
|
|
@@ -34276,12 +34330,33 @@ function makeGraph(sessions, projects, previous) {
|
|
|
34276
34330
|
return { nodes, edges, lanes, start, end, timeFrame };
|
|
34277
34331
|
}
|
|
34278
34332
|
|
|
34333
|
+
// src/session-links.ts
|
|
34334
|
+
function visibleSessions(sessions) {
|
|
34335
|
+
const owners = /* @__PURE__ */ new Map();
|
|
34336
|
+
for (const session of sessions) {
|
|
34337
|
+
if (session.source !== "t3-code") continue;
|
|
34338
|
+
for (const id2 of new Set(session.linkedSessionIDs || [])) owners.set(id2, [...owners.get(id2) || [], session]);
|
|
34339
|
+
}
|
|
34340
|
+
const unique = new Map([...owners].flatMap(([native, claims]) => {
|
|
34341
|
+
const owner = claims[0];
|
|
34342
|
+
return claims.length === 1 && ["complete", "partial"].includes(owner.coverage?.history || "") && owner.activity?.userMessages ? [[native, owner.id]] : [];
|
|
34343
|
+
}));
|
|
34344
|
+
return sessions.filter((session) => !unique.has(session.id)).map((session) => ({
|
|
34345
|
+
...session,
|
|
34346
|
+
parentID: session.parentID ? unique.get(session.parentID) || session.parentID : void 0,
|
|
34347
|
+
forkID: session.forkID ? unique.get(session.forkID) || session.forkID : void 0
|
|
34348
|
+
}));
|
|
34349
|
+
}
|
|
34350
|
+
function sessionMatchesSource(session, source) {
|
|
34351
|
+
return !source || session.source === source || Boolean(session.source === "t3-code" && session.linkedSessionIDs?.some((id2) => id2.startsWith(`${source}:`)));
|
|
34352
|
+
}
|
|
34353
|
+
|
|
34279
34354
|
// server/library-query.ts
|
|
34280
34355
|
var LibraryError = class extends Error {
|
|
34281
|
-
constructor(code, message2,
|
|
34356
|
+
constructor(code, message2, exitCode2 = 1) {
|
|
34282
34357
|
super(message2);
|
|
34283
34358
|
this.code = code;
|
|
34284
|
-
this.exitCode =
|
|
34359
|
+
this.exitCode = exitCode2;
|
|
34285
34360
|
}
|
|
34286
34361
|
code;
|
|
34287
34362
|
exitCode;
|
|
@@ -34347,7 +34422,272 @@ function parseDate(value, now, endOfDay = false) {
|
|
|
34347
34422
|
return time3 + (dateOnly && endOfDay ? 864e5 - 1 : 0);
|
|
34348
34423
|
}
|
|
34349
34424
|
|
|
34425
|
+
// server/commit-store.ts
|
|
34426
|
+
var COMMIT_SCHEMA = `CREATE TABLE IF NOT EXISTS session_commits (
|
|
34427
|
+
session_id TEXT NOT NULL REFERENCES sessions(id) ON DELETE CASCADE,
|
|
34428
|
+
sha TEXT NOT NULL, repository_path TEXT NOT NULL, operation TEXT NOT NULL,
|
|
34429
|
+
occurred_at REAL, evidence_event_id TEXT NOT NULL,
|
|
34430
|
+
PRIMARY KEY(session_id,repository_path,sha,operation),
|
|
34431
|
+
FOREIGN KEY(session_id,evidence_event_id) REFERENCES timeline_items(session_id,id) ON DELETE CASCADE);
|
|
34432
|
+
CREATE INDEX IF NOT EXISTS session_commits_time ON session_commits(session_id,occurred_at);`;
|
|
34433
|
+
var supported = /* @__PURE__ */ new Set(["opencode", "t3-code", "codex", "claude-code"]);
|
|
34434
|
+
var pendingCommits = () => ({ version: 0, state: "pending", count: null, note: "Refresh sources to index recorded commit operations." });
|
|
34435
|
+
function writeCommits(db2, session) {
|
|
34436
|
+
db2.prepare("DELETE FROM session_commits WHERE session_id=?").run(session.id);
|
|
34437
|
+
const base = { version: COMMIT_EXTRACTOR_VERSION, indexedAt: Date.now() };
|
|
34438
|
+
if (!supported.has(session.source || "")) return { ...base, state: "unavailable", count: null, note: "Commit attribution is not validated for this source format." };
|
|
34439
|
+
const calls = /* @__PURE__ */ new Map();
|
|
34440
|
+
const results = /* @__PURE__ */ new Map();
|
|
34441
|
+
const rows2 = () => db2.prepare("SELECT data FROM timeline_items WHERE session_id=? AND kind IN ('tool_call','tool_result') ORDER BY ordinal").iterate(session.id);
|
|
34442
|
+
let tools = 0, partial = session.coverage?.history !== "complete" || Boolean(db2.prepare("SELECT partial FROM timeline_coverage WHERE session_id=?").get(session.id)?.partial);
|
|
34443
|
+
for (const row of rows2()) {
|
|
34444
|
+
const item = JSON.parse(String(row.data));
|
|
34445
|
+
tools++;
|
|
34446
|
+
if (item.kind === "tool_result" && item.callID) {
|
|
34447
|
+
const signature = fingerprint([item.output, item.exitCode, item.status, item.gitCommit]);
|
|
34448
|
+
results.set(item.callID, results.has(item.callID) && results.get(item.callID) !== signature ? null : signature);
|
|
34449
|
+
}
|
|
34450
|
+
if (item.kind !== "tool_call" || !item.callID) continue;
|
|
34451
|
+
calls.set(item.callID, calls.has(item.callID) ? null : item);
|
|
34452
|
+
}
|
|
34453
|
+
const completed = /* @__PURE__ */ new Set();
|
|
34454
|
+
const insert = db2.prepare("INSERT OR IGNORE INTO session_commits VALUES (?,?,?,?,?,?)");
|
|
34455
|
+
for (const row of rows2()) {
|
|
34456
|
+
const item = JSON.parse(String(row.data));
|
|
34457
|
+
if (item.kind !== "tool_result") continue;
|
|
34458
|
+
const call = item.input ? item : item.callID ? calls.get(item.callID) : void 0;
|
|
34459
|
+
if (!call || call !== item && call.ordinal >= item.ordinal || item.callID && results.get(item.callID) === null) {
|
|
34460
|
+
partial = true;
|
|
34461
|
+
continue;
|
|
34462
|
+
}
|
|
34463
|
+
if (item.callID) completed.add(item.callID);
|
|
34464
|
+
const extracted = extractCommit(call, item);
|
|
34465
|
+
if (!extracted.candidate) continue;
|
|
34466
|
+
const time3 = item.endTime ?? item.time;
|
|
34467
|
+
if (time3 !== null && time3 < session.created || session.forkID && (time3 === null || time3 <= session.created || call.time === null || call.time < session.created)) {
|
|
34468
|
+
partial = true;
|
|
34469
|
+
continue;
|
|
34470
|
+
}
|
|
34471
|
+
if (!extracted.commit) {
|
|
34472
|
+
partial = true;
|
|
34473
|
+
continue;
|
|
34474
|
+
}
|
|
34475
|
+
const { sha, repositoryPath, operation: operation2 } = extracted.commit;
|
|
34476
|
+
insert.run(session.id, sha, repositoryPath, operation2, time3, item.id);
|
|
34477
|
+
}
|
|
34478
|
+
for (const [id2, call] of calls) if (call && !completed.has(id2) && /\bgit\b[\s\S]*\b(?:commit|cherry-pick)\b/.test(call.input || "")) partial = true;
|
|
34479
|
+
const count = Number(db2.prepare("SELECT count(*) AS n FROM session_commits WHERE session_id=?").get(session.id).n);
|
|
34480
|
+
return {
|
|
34481
|
+
...base,
|
|
34482
|
+
state: !tools ? "unavailable" : partial ? "partial" : "indexed",
|
|
34483
|
+
count: !tools ? null : count,
|
|
34484
|
+
note: !tools ? "No usable tool executions recorded; commit history is unknown." : `${partial ? "Some execution evidence is missing, ambiguous, inherited, or unsupported. " : ""}Confirmed recorded operations only; absence is not proof that no commits occurred. Paths are execution directories; abbreviated SHAs remain unresolved. Linked provider histories retain their own attribution.`
|
|
34485
|
+
};
|
|
34486
|
+
}
|
|
34487
|
+
function commit(row) {
|
|
34488
|
+
return { sessionID: String(row.session_id), sha: String(row.sha), repositoryPath: String(row.repository_path), operation: row.operation, occurredAt: row.occurred_at === null ? null : Number(row.occurred_at), evidenceEventID: String(row.evidence_event_id) };
|
|
34489
|
+
}
|
|
34490
|
+
function readCommits(db2, session, options = {}) {
|
|
34491
|
+
let coverage2 = session.commits || pendingCommits();
|
|
34492
|
+
if (session.coverage?.note?.startsWith("Latest import failed:")) coverage2 = { ...coverage2, state: coverage2.count === null ? coverage2.state : "partial", note: `${session.coverage.note} ${coverage2.note}` };
|
|
34493
|
+
const revision2 = String(db2.prepare("SELECT revision FROM timeline_coverage WHERE session_id=?").get(session.id)?.revision || "pending");
|
|
34494
|
+
const key = fingerprint(["commits", session.id, revision2, coverage2]), offset = pageOffset(options.cursor, key), limit = pageLimit(options.limit);
|
|
34495
|
+
const total = Number(db2.prepare("SELECT count(*) AS n FROM session_commits WHERE session_id=?").get(session.id).n);
|
|
34496
|
+
const items = db2.prepare("SELECT * FROM session_commits WHERE session_id=? ORDER BY occurred_at IS NULL,occurred_at,repository_path,sha,operation LIMIT ? OFFSET ?").all(session.id, limit, offset).map(commit);
|
|
34497
|
+
return { sessionID: session.id, revision: revision2, coverage: coverage2, items, total, nextCursor: offset + limit < total ? nextCursor(key, offset + limit) : null };
|
|
34498
|
+
}
|
|
34499
|
+
function commitMarkers(db2, session) {
|
|
34500
|
+
const end = Math.max(session.created, session.activity?.lastMessageAt || session.created);
|
|
34501
|
+
return db2.prepare("SELECT * FROM session_commits WHERE session_id=? AND occurred_at>=? AND occurred_at<=? ORDER BY occurred_at,sha LIMIT 2000").all(session.id, session.created, end).map((row, ordinal) => {
|
|
34502
|
+
const value = commit(row);
|
|
34503
|
+
return {
|
|
34504
|
+
id: value.evidenceEventID,
|
|
34505
|
+
kind: "commit",
|
|
34506
|
+
name: `${value.operation} ${value.sha}`,
|
|
34507
|
+
time: value.occurredAt,
|
|
34508
|
+
timeSource: "recorded",
|
|
34509
|
+
ordinal,
|
|
34510
|
+
preview: `${value.repositoryPath}
|
|
34511
|
+
${abbreviatedSHA(value.sha) ? "Abbreviated SHA \xB7 " : ""}Open recorded execution evidence`
|
|
34512
|
+
};
|
|
34513
|
+
});
|
|
34514
|
+
}
|
|
34515
|
+
|
|
34516
|
+
// server/event-store.ts
|
|
34517
|
+
var EVENT_SCHEMA = `CREATE TABLE IF NOT EXISTS timeline_items (
|
|
34518
|
+
session_id TEXT NOT NULL REFERENCES sessions(id) ON DELETE CASCADE, id TEXT NOT NULL, message_id TEXT NOT NULL,
|
|
34519
|
+
ordinal INTEGER NOT NULL, kind TEXT NOT NULL, role TEXT, time REAL, call_id TEXT, name TEXT NOT NULL, preview TEXT NOT NULL, data TEXT NOT NULL,
|
|
34520
|
+
PRIMARY KEY(session_id,id));
|
|
34521
|
+
CREATE INDEX IF NOT EXISTS timeline_order ON timeline_items(session_id,ordinal);
|
|
34522
|
+
CREATE INDEX IF NOT EXISTS timeline_time ON timeline_items(session_id,time);
|
|
34523
|
+
CREATE INDEX IF NOT EXISTS timeline_calls ON timeline_items(session_id,call_id);
|
|
34524
|
+
CREATE TABLE IF NOT EXISTS timeline_coverage (session_id TEXT PRIMARY KEY REFERENCES sessions(id) ON DELETE CASCADE, partial INTEGER NOT NULL, note TEXT, revision TEXT NOT NULL);`;
|
|
34525
|
+
function writeEvents(db2, id2, rows2) {
|
|
34526
|
+
db2.prepare("DELETE FROM timeline_items WHERE session_id=?").run(id2);
|
|
34527
|
+
const insert = db2.prepare("INSERT OR IGNORE INTO timeline_items VALUES (?,?,?,?,?,?,?,?,?,?,?)");
|
|
34528
|
+
let ordinal = 0, bytes2 = 0, partial = false, legacy = false, limited = false;
|
|
34529
|
+
for (const row of rows2) {
|
|
34530
|
+
const message2 = JSON.parse(String(row.data));
|
|
34531
|
+
legacy ||= !message2.events;
|
|
34532
|
+
for (const event of normalizedEvents(message2, id2)) {
|
|
34533
|
+
const item = { ...event, ordinal: ordinal++ }, data = JSON.stringify(item);
|
|
34534
|
+
bytes2 += Buffer.byteLength(data);
|
|
34535
|
+
if (ordinal > 2e5 || bytes2 > 32e6) {
|
|
34536
|
+
limited = true;
|
|
34537
|
+
break;
|
|
34538
|
+
}
|
|
34539
|
+
partial ||= Boolean(item.partial);
|
|
34540
|
+
const preview = (item.text || item.input || item.output || item.name).replace(/\s+/g, " ").slice(0, 180);
|
|
34541
|
+
insert.run(id2, item.id, item.messageID, item.ordinal, item.kind, item.role || null, item.time, item.callID || null, item.name, preview, data);
|
|
34542
|
+
}
|
|
34543
|
+
if (limited) break;
|
|
34544
|
+
}
|
|
34545
|
+
const note = [legacy ? "Some items were reconstructed from an older flattened import; tool inputs/results cannot be paired there. Refresh sources to import structured events." : "", limited ? "Event history limited to 200,000 items / 32 MB per session." : "", partial ? "Some event content is missing, unsupported, or shortened." : ""].filter(Boolean).join(" ");
|
|
34546
|
+
db2.prepare("INSERT OR REPLACE INTO timeline_coverage VALUES (?,?,?,?)").run(id2, Number(partial || legacy || limited), note || null, randomUUID());
|
|
34547
|
+
}
|
|
34548
|
+
var summaryColumns = "id,kind,role,name,time,ordinal,preview,json_extract(data,'$.timeSource') AS timeSource,json_extract(data,'$.status') AS status,json_extract(data,'$.partial') AS partial";
|
|
34549
|
+
function eventSummary(row) {
|
|
34550
|
+
return { id: String(row.id), kind: row.kind, role: row.role, name: String(row.name), time: row.time === null ? null : Number(row.time), timeSource: row.timeSource, ordinal: Number(row.ordinal), preview: String(row.preview), status: row.status, partial: Boolean(row.partial) };
|
|
34551
|
+
}
|
|
34552
|
+
var EventReadError = class extends Error {
|
|
34553
|
+
constructor(message2, status2) {
|
|
34554
|
+
super(message2);
|
|
34555
|
+
this.status = status2;
|
|
34556
|
+
}
|
|
34557
|
+
status;
|
|
34558
|
+
};
|
|
34559
|
+
var filters = { all: "1", messages: "kind='message' AND role IN ('user','assistant')", tools: "kind IN ('tool_call','tool_result')", events: "kind NOT IN ('message','tool_call','tool_result')", untimed: "time IS NULL" };
|
|
34560
|
+
function coverage(db2, session) {
|
|
34561
|
+
const row = db2.prepare("SELECT * FROM timeline_coverage WHERE session_id=?").get(session.id);
|
|
34562
|
+
return { revision: String(row?.revision || "pending"), partial: Boolean(row?.partial) || session.coverage?.history !== "complete", note: [row?.note, session.coverage?.note].filter(Boolean).join(" ") || void 0 };
|
|
34563
|
+
}
|
|
34564
|
+
function readEventMarkers(db2, session) {
|
|
34565
|
+
const end = Math.max(session.created, session.activity?.lastMessageAt || session.created);
|
|
34566
|
+
const totals = db2.prepare(`SELECT count(*) AS total, count(*) FILTER (WHERE time IS NULL) AS untimed, count(*) FILTER (WHERE time<? OR time>?) AS outside FROM timeline_items WHERE session_id=? AND (${filters.messages})`).get(session.created, end, session.id);
|
|
34567
|
+
const rows2 = db2.prepare(`SELECT ${summaryColumns} FROM timeline_items WHERE session_id=? AND (${filters.messages}) AND time>=? AND time<=? ORDER BY time DESC,ordinal DESC`).all(session.id, session.created, end);
|
|
34568
|
+
const commits = commitMarkers(db2, session);
|
|
34569
|
+
return { sessionID: session.id, ...coverage(db2, session), commits: session.commits, items: [...rows2.reverse().map(eventSummary), ...commits].sort((a, b) => a.time - b.time || a.ordinal - b.ordinal), total: Number(totals.total), untimed: Number(totals.untimed), outsideLifetime: Number(totals.outside), limited: Number(totals.total) - Number(totals.untimed) - Number(totals.outside) > rows2.length || commits.length === 2e3 };
|
|
34570
|
+
}
|
|
34571
|
+
function readEvents(db2, session, options = {}) {
|
|
34572
|
+
const state2 = coverage(db2, session), filter = options.filter || "all", size = 60;
|
|
34573
|
+
if (!Object.hasOwn(filters, filter)) throw new EventReadError("Invalid event filter.", 400);
|
|
34574
|
+
const where = filters[filter];
|
|
34575
|
+
if (options.revision && options.revision !== state2.revision) throw new EventReadError("Saved history changed. Reload the event explorer.", 409);
|
|
34576
|
+
let offset = 0;
|
|
34577
|
+
if (options.cursor) {
|
|
34578
|
+
try {
|
|
34579
|
+
if (options.cursor.length > 512) throw new Error();
|
|
34580
|
+
const cursor2 = JSON.parse(Buffer.from(options.cursor, "base64url").toString());
|
|
34581
|
+
if (!Number.isSafeInteger(cursor2.offset) || cursor2.offset < 0 || cursor2.offset > 2e5 || cursor2.filter !== filter || typeof cursor2.revision !== "string") throw new Error();
|
|
34582
|
+
if (cursor2.revision !== state2.revision) throw new EventReadError("Saved history changed. Reload the event explorer.", 409);
|
|
34583
|
+
offset = cursor2.offset;
|
|
34584
|
+
} catch (error) {
|
|
34585
|
+
if (error instanceof EventReadError) throw error;
|
|
34586
|
+
throw new EventReadError("Invalid event cursor.", 400);
|
|
34587
|
+
}
|
|
34588
|
+
}
|
|
34589
|
+
let selected;
|
|
34590
|
+
if (options.item) {
|
|
34591
|
+
const row = db2.prepare(`SELECT data FROM timeline_items WHERE session_id=? AND id=? AND (${where})`).get(session.id, options.item);
|
|
34592
|
+
if (!row) throw new EventReadError("This event is not in the saved session or current filter.", 404);
|
|
34593
|
+
selected = JSON.parse(String(row.data));
|
|
34594
|
+
const before = Number(db2.prepare(`SELECT count(*) AS n FROM timeline_items WHERE session_id=? AND ordinal<? AND (${where})`).get(session.id, selected.ordinal).n);
|
|
34595
|
+
offset = Math.floor(before / size) * size;
|
|
34596
|
+
}
|
|
34597
|
+
const total = Number(db2.prepare(`SELECT count(*) AS n FROM timeline_items WHERE session_id=? AND (${where})`).get(session.id).n);
|
|
34598
|
+
const items = db2.prepare(`SELECT ${summaryColumns} FROM timeline_items WHERE session_id=? AND (${where}) ORDER BY ordinal LIMIT ? OFFSET ?`).all(session.id, size, offset).map(eventSummary);
|
|
34599
|
+
if (!selected && items.length) selected = JSON.parse(String(db2.prepare("SELECT data FROM timeline_items WHERE session_id=? AND id=?").get(session.id, items[0].id).data));
|
|
34600
|
+
const related = selected?.callID ? db2.prepare(`SELECT ${summaryColumns} FROM timeline_items WHERE session_id=? AND call_id=? AND id<>? ORDER BY ordinal LIMIT 21`).all(session.id, selected.callID, selected.id).map(eventSummary) : [];
|
|
34601
|
+
const previousItem = selected ? db2.prepare(`SELECT id FROM timeline_items WHERE session_id=? AND ordinal<? AND (${where}) ORDER BY ordinal DESC LIMIT 1`).get(session.id, selected.ordinal)?.id : void 0;
|
|
34602
|
+
const nextItem = selected ? db2.prepare(`SELECT id FROM timeline_items WHERE session_id=? AND ordinal>? AND (${where}) ORDER BY ordinal LIMIT 1`).get(session.id, selected.ordinal)?.id : void 0;
|
|
34603
|
+
const cursor = (position) => Buffer.from(JSON.stringify({ revision: state2.revision, filter, offset: position })).toString("base64url");
|
|
34604
|
+
return {
|
|
34605
|
+
sessionID: session.id,
|
|
34606
|
+
...state2,
|
|
34607
|
+
items,
|
|
34608
|
+
total,
|
|
34609
|
+
offset,
|
|
34610
|
+
selected,
|
|
34611
|
+
related: related.slice(0, 20),
|
|
34612
|
+
relatedPartial: related.length > 20,
|
|
34613
|
+
previousItem: previousItem ? String(previousItem) : void 0,
|
|
34614
|
+
nextItem: nextItem ? String(nextItem) : void 0,
|
|
34615
|
+
nextCursor: offset + size < total ? cursor(offset + size) : null,
|
|
34616
|
+
previousCursor: offset > 0 ? cursor(Math.max(0, offset - size)) : null
|
|
34617
|
+
};
|
|
34618
|
+
}
|
|
34619
|
+
|
|
34620
|
+
// packages/core/src/preferences.ts
|
|
34621
|
+
var DEFAULT_PREFERENCES = Object.freeze({
|
|
34622
|
+
autoImport: true,
|
|
34623
|
+
muted: false,
|
|
34624
|
+
clickSounds: true,
|
|
34625
|
+
clickVolume: 35,
|
|
34626
|
+
motion: "system",
|
|
34627
|
+
view: "3d",
|
|
34628
|
+
density: "comfortable",
|
|
34629
|
+
panelOpacity: 90,
|
|
34630
|
+
quality: "balanced",
|
|
34631
|
+
bloom: 32,
|
|
34632
|
+
stars: true,
|
|
34633
|
+
labels: true,
|
|
34634
|
+
nodeScale: 100,
|
|
34635
|
+
focusDimming: true,
|
|
34636
|
+
trails: "all",
|
|
34637
|
+
trailOpacity: 34,
|
|
34638
|
+
trailFlow: false,
|
|
34639
|
+
trailSpeed: 25,
|
|
34640
|
+
relationships: true,
|
|
34641
|
+
messageDots: true,
|
|
34642
|
+
playbackSpeed: 1
|
|
34643
|
+
});
|
|
34644
|
+
var choices = { motion: ["system", "on", "off"], view: ["3d", "2d"], density: ["comfortable", "compact"], quality: ["performance", "balanced", "high"], trails: ["all", "selected", "off"] };
|
|
34645
|
+
var ranges = { clickVolume: [0, 100], panelOpacity: [55, 100], bloom: [0, 75], nodeScale: [60, 180], trailOpacity: [0, 100], trailSpeed: [10, 100], playbackSpeed: [0.25, 3] };
|
|
34646
|
+
function normalizePreferences(value) {
|
|
34647
|
+
const result = { ...DEFAULT_PREFERENCES };
|
|
34648
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return result;
|
|
34649
|
+
const input = value;
|
|
34650
|
+
for (const key of Object.keys(result)) {
|
|
34651
|
+
const item = input[key];
|
|
34652
|
+
if (key in choices) {
|
|
34653
|
+
if (choices[key].includes(item)) Object.assign(result, { [key]: item });
|
|
34654
|
+
} else if (key in ranges) {
|
|
34655
|
+
const [min, max] = ranges[key];
|
|
34656
|
+
if (typeof item === "number" && Number.isFinite(item)) Object.assign(result, { [key]: Math.max(min, Math.min(max, item)) });
|
|
34657
|
+
} else if (typeof item === "boolean") Object.assign(result, { [key]: item });
|
|
34658
|
+
}
|
|
34659
|
+
return result;
|
|
34660
|
+
}
|
|
34661
|
+
|
|
34662
|
+
// packages/core/src/view-state.ts
|
|
34663
|
+
var DEFAULT_VIEW_STATE = Object.freeze({
|
|
34664
|
+
sourceID: "",
|
|
34665
|
+
projectID: "",
|
|
34666
|
+
directory: "",
|
|
34667
|
+
days: 0,
|
|
34668
|
+
fromDate: "",
|
|
34669
|
+
toDate: "",
|
|
34670
|
+
includeChildren: true,
|
|
34671
|
+
includeArchived: false
|
|
34672
|
+
});
|
|
34673
|
+
var validDate = (value) => typeof value === "string" && /^\d{4}-\d{2}-\d{2}$/.test(value) && Number.isFinite(Date.parse(value)) && new Date(value).toISOString().slice(0, 10) === value;
|
|
34674
|
+
function normalizeViewState(value) {
|
|
34675
|
+
const result = { ...DEFAULT_VIEW_STATE };
|
|
34676
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return result;
|
|
34677
|
+
const input = value;
|
|
34678
|
+
for (const key of ["sourceID", "projectID", "directory"]) if (typeof input[key] === "string" && input[key].length <= 4096) result[key] = input[key];
|
|
34679
|
+
if ([0, 7, 30, 90].includes(input.days)) result.days = input.days;
|
|
34680
|
+
for (const key of ["includeChildren", "includeArchived"]) if (typeof input[key] === "boolean") result[key] = input[key];
|
|
34681
|
+
for (const key of ["fromDate", "toDate"]) if (validDate(input[key])) result[key] = input[key];
|
|
34682
|
+
if (result.fromDate && result.toDate && result.fromDate > result.toDate) {
|
|
34683
|
+
result.fromDate = "";
|
|
34684
|
+
result.toDate = "";
|
|
34685
|
+
}
|
|
34686
|
+
return result;
|
|
34687
|
+
}
|
|
34688
|
+
|
|
34350
34689
|
// server/store.ts
|
|
34690
|
+
init_commit_extraction();
|
|
34351
34691
|
var SessionGraphStore = class {
|
|
34352
34692
|
constructor(path = databasePath()) {
|
|
34353
34693
|
this.path = path;
|
|
@@ -34356,7 +34696,7 @@ var SessionGraphStore = class {
|
|
|
34356
34696
|
if (path !== ":memory:") chmodSync(path, 384);
|
|
34357
34697
|
this.db.exec("PRAGMA journal_mode=WAL; PRAGMA foreign_keys=ON; PRAGMA busy_timeout=5000;");
|
|
34358
34698
|
const version = Number(this.db.prepare("PRAGMA user_version").get().user_version);
|
|
34359
|
-
if (version >
|
|
34699
|
+
if (version > 6) throw new Error("This SessionGraph database requires a newer version of the app.");
|
|
34360
34700
|
this.db.exec(`
|
|
34361
34701
|
CREATE TABLE IF NOT EXISTS settings (key TEXT PRIMARY KEY, value TEXT NOT NULL);
|
|
34362
34702
|
CREATE TABLE IF NOT EXISTS sources (id TEXT PRIMARY KEY, last_import INTEGER, error TEXT);
|
|
@@ -34404,6 +34744,35 @@ var SessionGraphStore = class {
|
|
|
34404
34744
|
throw error;
|
|
34405
34745
|
}
|
|
34406
34746
|
}
|
|
34747
|
+
if (version < 5) {
|
|
34748
|
+
this.db.exec("BEGIN IMMEDIATE");
|
|
34749
|
+
try {
|
|
34750
|
+
this.db.exec(COMMIT_SCHEMA);
|
|
34751
|
+
this.db.prepare("UPDATE sessions SET metadata=json_set(metadata,'$.commits',json(?))").run(JSON.stringify(pendingCommits()));
|
|
34752
|
+
this.db.exec("PRAGMA user_version=5; COMMIT");
|
|
34753
|
+
} catch (error) {
|
|
34754
|
+
this.db.exec("ROLLBACK");
|
|
34755
|
+
throw error;
|
|
34756
|
+
}
|
|
34757
|
+
}
|
|
34758
|
+
if (version < 6) {
|
|
34759
|
+
this.db.exec("BEGIN IMMEDIATE");
|
|
34760
|
+
try {
|
|
34761
|
+
const retired = /* @__PURE__ */ new Set(["reasonix", "trae", "warp", "lm-studio", "hindsight"]);
|
|
34762
|
+
const selected = this.setting("selected");
|
|
34763
|
+
if (selected) this.setting("selected", selected.filter((id2) => !retired.has(id2)));
|
|
34764
|
+
const paths2 = this.setting("sourcePaths");
|
|
34765
|
+
if (paths2) this.setting("sourcePaths", Object.fromEntries(Object.entries(paths2).filter(([id2]) => !retired.has(id2))));
|
|
34766
|
+
const view = this.setting("viewState");
|
|
34767
|
+
if (view && typeof view.sourceID === "string" && retired.has(view.sourceID)) this.setting("viewState", { ...view, sourceID: "" });
|
|
34768
|
+
const remove2 = this.db.prepare("DELETE FROM sources WHERE id=?");
|
|
34769
|
+
for (const id2 of retired) remove2.run(id2);
|
|
34770
|
+
this.db.exec("PRAGMA user_version=6; COMMIT");
|
|
34771
|
+
} catch (error) {
|
|
34772
|
+
this.db.exec("ROLLBACK");
|
|
34773
|
+
throw error;
|
|
34774
|
+
}
|
|
34775
|
+
}
|
|
34407
34776
|
if (!this.setting("libraryID")) this.setting("libraryID", randomUUID2());
|
|
34408
34777
|
}
|
|
34409
34778
|
path;
|
|
@@ -34457,6 +34826,9 @@ var SessionGraphStore = class {
|
|
|
34457
34826
|
revision(id2) {
|
|
34458
34827
|
return this.db.prepare("SELECT imported_revision FROM sessions WHERE id=?").get(id2)?.imported_revision;
|
|
34459
34828
|
}
|
|
34829
|
+
commitsCurrent(id2) {
|
|
34830
|
+
return this.getSession(id2)?.commits?.version === COMMIT_EXTRACTOR_VERSION;
|
|
34831
|
+
}
|
|
34460
34832
|
upsert(candidate) {
|
|
34461
34833
|
const s = candidate.session, previous = this.getSession(s.id);
|
|
34462
34834
|
const metadata2 = {
|
|
@@ -34464,6 +34836,7 @@ var SessionGraphStore = class {
|
|
|
34464
34836
|
model: s.model === "Unknown model" ? previous?.model || s.model : s.model,
|
|
34465
34837
|
parentID: previous?.parentID && candidate.locator.agent ? previous.parentID : s.parentID,
|
|
34466
34838
|
activity: previous?.activity,
|
|
34839
|
+
commits: previous?.commits || pendingCommits(),
|
|
34467
34840
|
revision: previous?.revision || "",
|
|
34468
34841
|
coverage: previous?.coverage || { history: "pending" }
|
|
34469
34842
|
};
|
|
@@ -34478,8 +34851,9 @@ var SessionGraphStore = class {
|
|
|
34478
34851
|
const insert = this.db.prepare("INSERT INTO messages (session_id,id,ordinal,data,time,is_user) VALUES (?,?,?,?,?,?) ON CONFLICT(session_id,id) DO UPDATE SET ordinal=excluded.ordinal,data=excluded.data,time=excluded.time,is_user=excluded.is_user");
|
|
34479
34852
|
messages.forEach((message2, i) => insert.run(s.id, message2.id, i, JSON.stringify(message2), messageTime(message2.time), Number(isUserMessage(message2))));
|
|
34480
34853
|
writeEvents(this.db, s.id, this.db.prepare("SELECT data FROM messages WHERE session_id=? ORDER BY ordinal").iterate(s.id));
|
|
34854
|
+
const commits = writeCommits(this.db, s);
|
|
34481
34855
|
const activity = this.db.prepare(activitySQL).get(s.id);
|
|
34482
|
-
this.db.prepare("UPDATE sessions SET metadata=?, imported_revision=? WHERE id=?").run(JSON.stringify({ ...s, activity }), candidate.revision, s.id);
|
|
34856
|
+
this.db.prepare("UPDATE sessions SET metadata=?, imported_revision=? WHERE id=?").run(JSON.stringify({ ...s, activity, commits }), candidate.revision, s.id);
|
|
34483
34857
|
this.db.prepare("DELETE FROM search_cache WHERE id=?").run(s.id);
|
|
34484
34858
|
this.db.exec("COMMIT");
|
|
34485
34859
|
} catch (error) {
|
|
@@ -34568,6 +34942,9 @@ var SessionGraphStore = class {
|
|
|
34568
34942
|
eventMarkers(id2) {
|
|
34569
34943
|
return this.readSnapshot(id2, (session) => readEventMarkers(this.db, session));
|
|
34570
34944
|
}
|
|
34945
|
+
commits(id2, options = {}) {
|
|
34946
|
+
return this.readSnapshot(id2, (session) => readCommits(this.db, session, options));
|
|
34947
|
+
}
|
|
34571
34948
|
readSnapshot(id2, read3) {
|
|
34572
34949
|
this.db.exec("BEGIN");
|
|
34573
34950
|
try {
|
|
@@ -34773,7 +35150,7 @@ var Importer = class {
|
|
|
34773
35150
|
for (const candidate of seen.values()) {
|
|
34774
35151
|
this.store.upsert(candidate);
|
|
34775
35152
|
const saved = this.store.getSession(candidate.session.id);
|
|
34776
|
-
const retry = !saved?.coverage?.importedAt || saved.coverage.note?.startsWith("Latest import failed:");
|
|
35153
|
+
const retry = !saved?.coverage?.importedAt || saved.coverage.note?.startsWith("Latest import failed:") || !this.store.commitsCurrent(candidate.session.id);
|
|
34777
35154
|
if (!retry && saved?.revision === candidate.revision && this.store.revision(candidate.session.id) === candidate.revision) {
|
|
34778
35155
|
this.status.unchanged++;
|
|
34779
35156
|
continue;
|
|
@@ -34817,6 +35194,7 @@ var Importer = class {
|
|
|
34817
35194
|
} while (cursor);
|
|
34818
35195
|
const values = [...messages.values()];
|
|
34819
35196
|
if (adapter.id === "opencode") values.reverse();
|
|
35197
|
+
if (saved?.activity?.userMessages && values.every((message2) => message2.role === "system")) throw new Error("Source has no readable conversation. Previous imports are retained.");
|
|
34820
35198
|
this.store.replace(candidate, values, partial, note);
|
|
34821
35199
|
this.status.imported++;
|
|
34822
35200
|
} catch (error) {
|
|
@@ -35219,8 +35597,8 @@ var SearchableMap = class _SearchableMap {
|
|
|
35219
35597
|
* @param object Object of entries for the {@link SearchableMap}
|
|
35220
35598
|
* @return A new {@link SearchableMap} with the given entries
|
|
35221
35599
|
*/
|
|
35222
|
-
static fromObject(
|
|
35223
|
-
return _SearchableMap.from(Object.entries(
|
|
35600
|
+
static fromObject(object3) {
|
|
35601
|
+
return _SearchableMap.from(Object.entries(object3));
|
|
35224
35602
|
}
|
|
35225
35603
|
};
|
|
35226
35604
|
var trackDown = (tree, key, path = []) => {
|
|
@@ -36112,11 +36490,11 @@ var MiniSearch = class _MiniSearch {
|
|
|
36112
36490
|
* @param options configuration options, same as the constructor
|
|
36113
36491
|
* @return An instance of MiniSearch deserialized from the given JSON.
|
|
36114
36492
|
*/
|
|
36115
|
-
static loadJSON(
|
|
36493
|
+
static loadJSON(json5, options) {
|
|
36116
36494
|
if (options == null) {
|
|
36117
36495
|
throw new Error("MiniSearch: loadJSON should be given the same options used when serializing the index");
|
|
36118
36496
|
}
|
|
36119
|
-
return this.loadJS(JSON.parse(
|
|
36497
|
+
return this.loadJS(JSON.parse(json5), options);
|
|
36120
36498
|
}
|
|
36121
36499
|
/**
|
|
36122
36500
|
* Async equivalent of {@link MiniSearch.loadJSON}
|
|
@@ -36131,11 +36509,11 @@ var MiniSearch = class _MiniSearch {
|
|
|
36131
36509
|
* @param options configuration options, same as the constructor
|
|
36132
36510
|
* @return A Promise that will resolve to an instance of MiniSearch deserialized from the given JSON.
|
|
36133
36511
|
*/
|
|
36134
|
-
static async loadJSONAsync(
|
|
36512
|
+
static async loadJSONAsync(json5, options) {
|
|
36135
36513
|
if (options == null) {
|
|
36136
36514
|
throw new Error("MiniSearch: loadJSON should be given the same options used when serializing the index");
|
|
36137
36515
|
}
|
|
36138
|
-
return this.loadJSAsync(JSON.parse(
|
|
36516
|
+
return this.loadJSAsync(JSON.parse(json5), options);
|
|
36139
36517
|
}
|
|
36140
36518
|
/**
|
|
36141
36519
|
* Returns the default value of an option. It will throw an error if no option
|
|
@@ -36536,7 +36914,7 @@ var MiniSearch = class _MiniSearch {
|
|
|
36536
36914
|
}
|
|
36537
36915
|
};
|
|
36538
36916
|
MiniSearch.wildcard = /* @__PURE__ */ Symbol("*");
|
|
36539
|
-
var getOwnProperty = (
|
|
36917
|
+
var getOwnProperty = (object3, property) => Object.prototype.hasOwnProperty.call(object3, property) ? object3[property] : void 0;
|
|
36540
36918
|
var combinators = {
|
|
36541
36919
|
[OR]: (a, b) => {
|
|
36542
36920
|
for (const docId of b.keys()) {
|
|
@@ -36629,18 +37007,18 @@ var assignUniqueTerms = (target, source) => {
|
|
|
36629
37007
|
};
|
|
36630
37008
|
var byScore = ({ score: a }, { score: b }) => b - a;
|
|
36631
37009
|
var createMap = () => /* @__PURE__ */ new Map();
|
|
36632
|
-
var objectToNumericMap = (
|
|
37010
|
+
var objectToNumericMap = (object3) => {
|
|
36633
37011
|
const map = /* @__PURE__ */ new Map();
|
|
36634
|
-
for (const key of Object.keys(
|
|
36635
|
-
map.set(parseInt(key, 10),
|
|
37012
|
+
for (const key of Object.keys(object3)) {
|
|
37013
|
+
map.set(parseInt(key, 10), object3[key]);
|
|
36636
37014
|
}
|
|
36637
37015
|
return map;
|
|
36638
37016
|
};
|
|
36639
|
-
var objectToNumericMapAsync = async (
|
|
37017
|
+
var objectToNumericMapAsync = async (object3) => {
|
|
36640
37018
|
const map = /* @__PURE__ */ new Map();
|
|
36641
37019
|
let count = 0;
|
|
36642
|
-
for (const key of Object.keys(
|
|
36643
|
-
map.set(parseInt(key, 10),
|
|
37020
|
+
for (const key of Object.keys(object3)) {
|
|
37021
|
+
map.set(parseInt(key, 10), object3[key]);
|
|
36644
37022
|
if (++count % 1e3 === 0) {
|
|
36645
37023
|
await wait(0);
|
|
36646
37024
|
}
|
|
@@ -36655,7 +37033,7 @@ var normalize = (text3) => text3.normalize("NFKD").replace(new RegExp("\\p{M}",
|
|
|
36655
37033
|
var words = (text3) => normalize(text3).match(/[\p{L}\p{N}]+/gu) || [];
|
|
36656
37034
|
var phrase = (text3) => words(text3).join(" ");
|
|
36657
37035
|
function parseQuery(input) {
|
|
36658
|
-
const
|
|
37036
|
+
const plan2 = { text: "", terms: [], phrases: [], filters: [] };
|
|
36659
37037
|
const parts = [];
|
|
36660
37038
|
for (const token of input.slice(0, 300).match(/(?:[^\s"]+|"[^"]*")+/g) || []) {
|
|
36661
37039
|
const filter = /^(source|project|dir|model|is|after|before|in):(.+)$/i.exec(token);
|
|
@@ -36663,21 +37041,21 @@ function parseQuery(input) {
|
|
|
36663
37041
|
const key = filter[1].toLowerCase(), value2 = normalize(filter[2].replace(/^"|"$/g, ""));
|
|
36664
37042
|
if (key === "in") {
|
|
36665
37043
|
const fields2 = { title: ["title"], files: ["files"], messages: ["body"], tools: ["tools"] };
|
|
36666
|
-
|
|
36667
|
-
if (!
|
|
36668
|
-
} else if (key === "is" && !["fork", "child", "root", "archived"].includes(value2))
|
|
36669
|
-
else if (["after", "before"].includes(key) && (!/^\d{4}-\d{2}-\d{2}$/.test(value2) || !Number.isFinite(Date.parse(value2)) || new Date(value2).toISOString().slice(0, 10) !== value2))
|
|
36670
|
-
else
|
|
37044
|
+
plan2.fields = fields2[value2];
|
|
37045
|
+
if (!plan2.fields) plan2.error = "Use in:title, in:files, in:messages, or in:tools.";
|
|
37046
|
+
} else if (key === "is" && !["fork", "child", "root", "archived"].includes(value2)) plan2.error = "Use is:fork, is:child, is:root, or is:archived.";
|
|
37047
|
+
else if (["after", "before"].includes(key) && (!/^\d{4}-\d{2}-\d{2}$/.test(value2) || !Number.isFinite(Date.parse(value2)) || new Date(value2).toISOString().slice(0, 10) !== value2)) plan2.error = "Use a valid date in YYYY-MM-DD format.";
|
|
37048
|
+
else plan2.filters.push([key, value2]);
|
|
36671
37049
|
continue;
|
|
36672
37050
|
}
|
|
36673
37051
|
const value = token.replace(/^"|"$/g, "");
|
|
36674
|
-
if (token.startsWith('"') && token.endsWith('"'))
|
|
37052
|
+
if (token.startsWith('"') && token.endsWith('"')) plan2.phrases.push(phrase(value));
|
|
36675
37053
|
parts.push(value);
|
|
36676
37054
|
}
|
|
36677
|
-
|
|
36678
|
-
|
|
36679
|
-
|
|
36680
|
-
return
|
|
37055
|
+
plan2.text = parts.join(" ");
|
|
37056
|
+
plan2.terms = words(plan2.text).slice(0, 12);
|
|
37057
|
+
plan2.text = plan2.terms.join(" ");
|
|
37058
|
+
return plan2;
|
|
36681
37059
|
}
|
|
36682
37060
|
function excerpt(text3, terms, length = 220) {
|
|
36683
37061
|
const value = normalize(text3);
|
|
@@ -36745,12 +37123,12 @@ ${fragment.text}`;
|
|
|
36745
37123
|
const key = `${input}\0${viewOnly}\0${limit}\0${offset}`;
|
|
36746
37124
|
const cached2 = this.cache.get(key);
|
|
36747
37125
|
if (cached2) return cached2;
|
|
36748
|
-
const
|
|
36749
|
-
if (
|
|
37126
|
+
const plan2 = parseQuery(input);
|
|
37127
|
+
if (plan2.error) return { hits: [], total: 0, error: plan2.error };
|
|
36750
37128
|
const accepts = (entry) => {
|
|
36751
37129
|
const { session, doc } = entry;
|
|
36752
37130
|
if (viewOnly && !this.scope.has(session.id)) return false;
|
|
36753
|
-
for (const [key2, value] of
|
|
37131
|
+
for (const [key2, value] of plan2.filters) {
|
|
36754
37132
|
if (key2 === "source" && ![session.source || "opencode", ...(session.linkedSessionIDs || []).map((id2) => id2.split(":")[0])].some((source) => normalize(source).includes(value))) return false;
|
|
36755
37133
|
if (key2 === "project" && !normalize(doc.project).includes(value) && !normalize(session.projectID).includes(value)) return false;
|
|
36756
37134
|
if (key2 === "dir" && !normalize(session.directory).includes(value)) return false;
|
|
@@ -36764,14 +37142,14 @@ ${fragment.text}`;
|
|
|
36764
37142
|
if (value === "archived" && !session.archived) return false;
|
|
36765
37143
|
}
|
|
36766
37144
|
}
|
|
36767
|
-
if (
|
|
36768
|
-
const fields2 =
|
|
36769
|
-
if (!
|
|
37145
|
+
if (plan2.phrases.length) {
|
|
37146
|
+
const fields2 = plan2.fields || ["title", "body", "files", "tools", "project", "directory", "model"];
|
|
37147
|
+
if (!plan2.phrases.every((p) => fields2.some((field) => phrase(doc[field]).includes(p)))) return false;
|
|
36770
37148
|
}
|
|
36771
37149
|
return true;
|
|
36772
37150
|
};
|
|
36773
|
-
const matches =
|
|
36774
|
-
fields:
|
|
37151
|
+
const matches = plan2.terms.length ? this.index.search(plan2.text, {
|
|
37152
|
+
fields: plan2.fields,
|
|
36775
37153
|
fuzzy: (term) => term.length < 4 ? false : term.length > 7 ? 2 : 1,
|
|
36776
37154
|
filter: (result2) => accepts(this.entries.get(String(result2.id)))
|
|
36777
37155
|
}) : [...this.entries.values()].filter(accepts).map((entry) => ({ id: entry.session.id, score: 0, terms: [], match: {} }));
|
|
@@ -36779,12 +37157,12 @@ ${fragment.text}`;
|
|
|
36779
37157
|
const entry = this.entries.get(String(match2.id));
|
|
36780
37158
|
const title = phrase(entry.doc.title);
|
|
36781
37159
|
const fields2 = new Set(Object.values(match2.match).flat());
|
|
36782
|
-
const tier = !
|
|
37160
|
+
const tier = !plan2.text ? 0 : title.includes(plan2.text) && (!plan2.fields || plan2.fields.includes("title")) ? 5 : fields2.has("title") ? 4 : fields2.has("sessionID") ? 4 : fields2.has("files") ? 3 : fields2.has("body") ? 2 : 1;
|
|
36783
37161
|
return { match: match2, entry, tier };
|
|
36784
37162
|
}).sort((a, b) => b.tier - a.tier || b.match.score - a.match.score || b.entry.session.updated - a.entry.session.updated || a.entry.session.id.localeCompare(b.entry.session.id));
|
|
36785
37163
|
const hits = ranked.slice(offset, offset + Math.min(250, Math.max(1, limit))).map(({ match: match2, entry, tier }) => {
|
|
36786
|
-
const terms = match2.terms.length ? match2.terms :
|
|
36787
|
-
const candidates = entry.fragments.filter((f) => !
|
|
37164
|
+
const terms = match2.terms.length ? match2.terms : plan2.terms;
|
|
37165
|
+
const candidates = entry.fragments.filter((f) => !plan2.fields || plan2.fields.includes(f.kind === "File" ? "files" : f.kind === "Tool" ? "tools" : "body"));
|
|
36788
37166
|
let best, bestCount = 0;
|
|
36789
37167
|
for (const fragment of candidates) {
|
|
36790
37168
|
const text3 = normalize(fragment.text);
|
|
@@ -36796,7 +37174,7 @@ ${fragment.text}`;
|
|
|
36796
37174
|
if (count === terms.length && count > 0) break;
|
|
36797
37175
|
}
|
|
36798
37176
|
const fields2 = new Set(Object.values(match2.match).flat());
|
|
36799
|
-
const source = tier >= 4 ? fields2.has("sessionID") && !fields2.has("title") ? "Session ID" : "Title" : best ? best.kind === "File" ? "File" : best.kind === "Tool" ? "Tool" : "Message" :
|
|
37177
|
+
const source = tier >= 4 ? fields2.has("sessionID") && !fields2.has("title") ? "Session ID" : "Title" : best ? best.kind === "File" ? "File" : best.kind === "Tool" ? "Tool" : "Message" : plan2.text ? "Metadata" : "Recent";
|
|
36800
37178
|
return { id: entry.session.id, score: match2.score, source, excerpt: best ? excerpt(best.text, terms) : "", terms };
|
|
36801
37179
|
});
|
|
36802
37180
|
const result = { hits, total: ranked.length };
|
|
@@ -36943,6 +37321,10 @@ var LibraryService = class {
|
|
|
36943
37321
|
this.getSession(id2);
|
|
36944
37322
|
return this.store.timeline(id2);
|
|
36945
37323
|
}
|
|
37324
|
+
getCommits(id2, options = {}) {
|
|
37325
|
+
this.getSession(id2);
|
|
37326
|
+
return this.store.commits(id2, options);
|
|
37327
|
+
}
|
|
36946
37328
|
getEvents(id2, options = {}) {
|
|
36947
37329
|
this.getSession(id2);
|
|
36948
37330
|
return this.store.events(id2, options);
|
|
@@ -36971,8 +37353,8 @@ var LibraryService = class {
|
|
|
36971
37353
|
}
|
|
36972
37354
|
searchSessions(query, filters3 = {}, options = {}) {
|
|
36973
37355
|
if (!query.trim() || query.length > 300) invalid("Search query must contain 1\u2013300 characters.");
|
|
36974
|
-
const
|
|
36975
|
-
if (
|
|
37356
|
+
const plan2 = parseQuery(query);
|
|
37357
|
+
if (plan2.error) invalid(plan2.error);
|
|
36976
37358
|
return this.snapshot(() => {
|
|
36977
37359
|
const { sessions, projects } = this.sessions(filters3);
|
|
36978
37360
|
const index = new SessionSearchIndex();
|
|
@@ -37082,7 +37464,7 @@ var filters2 = [
|
|
|
37082
37464
|
];
|
|
37083
37465
|
var globalOptions = [flag("help", "Show command help without opening the library (-h)."), flag("json", "Emit one versioned JSON envelope on stdout. No interactive prompts."), text("data-dir", "Use a separate library directory; otherwise use SESSIONGRAPH_DATA_DIR and existing storage precedence.")];
|
|
37084
37466
|
var sessionArg = { name: "session-id", required: true };
|
|
37085
|
-
var
|
|
37467
|
+
var commands2 = [
|
|
37086
37468
|
{ name: "sources list", aliases: ["sources"], summary: "Discover supported sources, saved selection, custom paths, and import coverage.", options: [], effect: "read", result: "{ sources: SourceStatus[] with path/pathHint, configured, autoImport }", examples: ["sources --json"] },
|
|
37087
37469
|
{ name: "sources setup", summary: "Enable import sources and optionally set a persistent history path. Does not import.", args: { name: "source", variadic: true }, options: [flag("detected", "Add all currently detected sources to the saved selection."), text("path", "Persist a custom source directory; requires exactly one filesystem source. Overrides environment/default paths."), flag("default-path", "Clear the saved path for one source and use environment/default detection."), text("auto-import", "Enable/disable the app\u2019s automatic refresh. No background daemon is installed.", { values: ["on", "off"] })], effect: "configure", result: "{ selected, paths, autoImport, historyRetained }", examples: ["sources setup claude-code codex", "sources setup codex --path ~/.codex", "sources setup --detected", "sources setup --auto-import off"] },
|
|
37088
37470
|
{ name: "sources remove", summary: "Disable sources and clear their saved paths. Keep all previously imported history.", args: { name: "source", variadic: true }, options: [flag("all", "Disable all sources.")], effect: "configure", result: "{ selected, paths, autoImport, historyRetained }", examples: ["sources remove codex", "sources remove --all"] },
|
|
@@ -37094,6 +37476,7 @@ var commands = [
|
|
|
37094
37476
|
{ name: "timeline", summary: "Read recorded user-message times and untimed/partial coverage (up to 2,000 markers).", args: sessionArg, options: [], effect: "read", result: "SessionTimeline { id, userMessages, totalUserMessages, untimedUserMessages, earlierUserMessages, partial, note }", examples: ["timeline codex:SESSION_ID --json"] },
|
|
37095
37477
|
{ name: "events", summary: "Inspect structured messages, tool calls/results, and events with revision-bound pagination.", args: sessionArg, options: [text("filter", "Event category.", { values: ["all", "messages", "tools", "events", "untimed"], default: "all" }), text("cursor", "Event nextCursor; pages contain up to 60 summaries."), text("item", "Select an event ID to retrieve its bounded full payload."), text("revision", "Require the saved event revision from a previous response.")], effect: "read", result: "TimelinePage { sessionID, revision, items, selected, related, total, nextCursor, previousCursor, partial, note }", examples: ["events codex:SESSION_ID --filter tools --json", "events codex:SESSION_ID --item EVENT_ID --json"] },
|
|
37096
37478
|
{ name: "files", summary: "Read verified file-change evidence and tool counts from 120 saved messages per page.", args: sessionArg, options: [text("cursor", "Numeric nextCursor from the previous file-evidence page.")], effect: "read", result: "SessionDetail { id, revision, files, tools, messagesScanned, snapshotSteps, nextCursor, partial, note }. Not a diff or file snapshot.", examples: ["files codex:SESSION_ID --json"] },
|
|
37479
|
+
{ name: "commits", summary: "Read indexed, evidence-linked commit creation actions without scanning messages. SHAs may be abbreviated.", args: sessionArg, options: paging, effect: "read", result: "SessionCommits { sessionID, revision, coverage, items: [{ sessionID, sha, repositoryPath, operation, occurredAt, evidenceEventID }], total, nextCursor }. Paths are recorded execution directories; unknown coverage is not zero commits.", examples: ["commits codex:SESSION_ID --json", "events codex:SESSION_ID --item EVIDENCE_EVENT_ID --json"] },
|
|
37097
37480
|
{ name: "relationships", summary: "Read explicit parents, forks, children, and provider links; no inferred ancestry.", args: sessionArg, options: paging, effect: "read", result: "{ sessionID, items: [{ id, kind, direction, imported }], total, nextCursor }", examples: ["relationships codex:SESSION_ID --json"] },
|
|
37098
37481
|
{ name: "stats", summary: "Summarize saved sessions and known lifetime usage, with unknown/partial coverage.", options: [...filters2, text("group-by", "Group by one recorded field.", { values: ["source", "model", "project", "directory"], default: "source" }), ...paging], effect: "read", result: "{ totals, groupBy, groups: { items, total, nextCursor }, filters, note }. Usage: { knownTotal, knownSessions, unknownSessions }.", examples: ["stats --since 7d --group-by source --json"] },
|
|
37099
37482
|
{ name: "graph", summary: "Return the shared graph layout for up to 5,000 filtered sessions.", options: filters2, effect: "read", result: "{ graph: { nodes, edges, lanes, start, end }, filters }. Contains local metadata, not an anonymized publication.", examples: ["graph --directory . --json"] },
|
|
@@ -37102,14 +37485,14 @@ var commands = [
|
|
|
37102
37485
|
{ name: "docs", summary: "Print the full command reference or one command as Markdown.", args: { name: "command", variadic: true }, options: [], effect: "read", result: "Markdown documentation; with --json: { markdown }.", examples: ["docs", "docs sources setup"] },
|
|
37103
37486
|
{ name: "help", summary: "Show general or command-specific help; --json returns the command schema.", args: { name: "command", variadic: true }, options: [], effect: "read", result: "Help text or command manifest. No library access.", examples: ["help sources setup", "help search --json"] }
|
|
37104
37487
|
];
|
|
37105
|
-
var resolveCommand = (name) =>
|
|
37488
|
+
var resolveCommand = (name) => commands2.find((command) => command.name === name || command.aliases?.includes(name));
|
|
37106
37489
|
function manifest(command) {
|
|
37107
37490
|
return {
|
|
37108
37491
|
schemaVersion: 1,
|
|
37109
37492
|
executable: "sessiongraph",
|
|
37110
37493
|
node: ">=24",
|
|
37111
37494
|
globalOptions,
|
|
37112
|
-
commands: command ? [command] :
|
|
37495
|
+
commands: command ? [command] : commands2,
|
|
37113
37496
|
launch: { desktop: "sessiongraph", browser: "sessiongraph --browser" },
|
|
37114
37497
|
output: { success: "{ schemaVersion: 1, command, data }", failure: "{ schemaVersion: 1, command, error: { code, message } }", pagination: "Follow nextCursor with identical filters; stale cursors fail. Empty results are successful." },
|
|
37115
37498
|
exitCodes: { 0: "Success (including no matches)", 1: "Operation failed, unhealthy doctor checks, or import with failures; inspect data/errors", 2: "Invalid command or arguments", 130: "Interrupted" },
|
|
@@ -37125,7 +37508,7 @@ Usage: sessiongraph <command> [options]
|
|
|
37125
37508
|
sessiongraph --version
|
|
37126
37509
|
|
|
37127
37510
|
Commands:
|
|
37128
|
-
${
|
|
37511
|
+
${commands2.map((c) => ` ${c.name.padEnd(18)} ${c.summary}`).join("\n")}
|
|
37129
37512
|
|
|
37130
37513
|
Options: --help (-h), --json, --data-dir <directory>
|
|
37131
37514
|
|
|
@@ -37159,14 +37542,14 @@ Node.js 24+. Local, noninteractive data commands. Use \`--json\` for structured
|
|
|
37159
37542
|
|
|
37160
37543
|
${manifest().rules.map((rule) => `- ${rule}`).join("\n")}
|
|
37161
37544
|
|
|
37162
|
-
${(command ? [command] :
|
|
37545
|
+
${(command ? [command] : commands2).map((c) => `## ${c.name}
|
|
37163
37546
|
|
|
37164
37547
|
\`\`\`text
|
|
37165
37548
|
${help(c)}\`\`\``).join("\n\n")}
|
|
37166
37549
|
`;
|
|
37167
37550
|
function parseCLI(argv) {
|
|
37168
37551
|
const options = {}, positionals = [];
|
|
37169
|
-
const known = new Map([...globalOptions, ...
|
|
37552
|
+
const known = new Map([...globalOptions, ...commands2.flatMap((c) => c.options), flag("version", "Version")].map((o) => [o.name, o]));
|
|
37170
37553
|
let literal = false;
|
|
37171
37554
|
for (let i = 0; i < argv.length; i++) {
|
|
37172
37555
|
let token = argv[i];
|
|
@@ -37253,7 +37636,7 @@ ${m.fragments.map((f) => `${cell(f.kind)}: ${cell(f.text)}${f.truncated ? " [tru
|
|
|
37253
37636
|
if (command === "doctor") return `${data.ok ? "OK" : "Needs attention"} \u2014 ${cell(data.database)}
|
|
37254
37637
|
${table(["CHECK", "STATUS", "DETAIL"], data.checks.map((c) => [c.name, c.ok ? "ok" : "failed", c.message]))}
|
|
37255
37638
|
${data.next}`;
|
|
37256
|
-
if (command === "commands") return table(["COMMAND", "EFFECT", "DESCRIPTION"],
|
|
37639
|
+
if (command === "commands") return table(["COMMAND", "EFFECT", "DESCRIPTION"], commands2.map((c) => [c.name, c.effect, c.summary]));
|
|
37257
37640
|
return JSON.stringify(data, null, 2).replace(/[\u007f-\u009f\u202a-\u202e\u2066-\u2069]/g, cell);
|
|
37258
37641
|
}
|
|
37259
37642
|
async function runCli(argv, io = {}) {
|
|
@@ -37262,11 +37645,11 @@ async function runCli(argv, io = {}) {
|
|
|
37262
37645
|
}), stderr = io.stderr || ((text3) => {
|
|
37263
37646
|
process.stderr.write(text3);
|
|
37264
37647
|
});
|
|
37265
|
-
let command = "cli",
|
|
37266
|
-
const emit = (data, text3) => stdout((
|
|
37648
|
+
let command = "cli", json5 = argv.includes("--json"), library;
|
|
37649
|
+
const emit = (data, text3) => stdout((json5 ? JSON.stringify({ schemaVersion: 1, command, data }) : text3 ?? human(command, data)) + "\n");
|
|
37267
37650
|
try {
|
|
37268
37651
|
const parsed = parseCLI(argv), options = parsed.options, args = parsed.args;
|
|
37269
|
-
|
|
37652
|
+
json5 = options.json === true;
|
|
37270
37653
|
const definition = parsed.command;
|
|
37271
37654
|
command = definition?.name || (options.version ? "version" : "help");
|
|
37272
37655
|
if (options.version) {
|
|
@@ -37316,8 +37699,8 @@ async function runCli(argv, io = {}) {
|
|
|
37316
37699
|
};
|
|
37317
37700
|
if (filters3.since !== void 0 && filters3.until !== void 0 && filters3.since > filters3.until) invalid("--since must not be later than --until.");
|
|
37318
37701
|
const paging2 = { limit: text3("limit") ? pageLimit(Number(text3("limit"))) : void 0, cursor };
|
|
37319
|
-
const
|
|
37320
|
-
const path = databasePath(
|
|
37702
|
+
const directory3 = text3("data-dir");
|
|
37703
|
+
const path = databasePath(directory3 ? { ...process.env, SESSIONGRAPH_DATA_DIR: localPath(directory3) } : process.env);
|
|
37321
37704
|
library = io.openLibrary ? await io.openLibrary(path) : new LibraryService(new SessionGraphStore(path), (await Promise.resolve().then(() => (init_adapters(), adapters_exports))).adapters);
|
|
37322
37705
|
let data;
|
|
37323
37706
|
switch (command) {
|
|
@@ -37331,7 +37714,7 @@ async function runCli(argv, io = {}) {
|
|
|
37331
37714
|
data = library.removeSources(args, options.all === true);
|
|
37332
37715
|
break;
|
|
37333
37716
|
case "sources sync":
|
|
37334
|
-
if (!
|
|
37717
|
+
if (!json5) stderr("Syncing local sources\u2026\n");
|
|
37335
37718
|
data = await library.importSessions(args);
|
|
37336
37719
|
break;
|
|
37337
37720
|
case "sessions":
|
|
@@ -37349,6 +37732,9 @@ async function runCli(argv, io = {}) {
|
|
|
37349
37732
|
case "timeline":
|
|
37350
37733
|
data = library.getTimeline(args[0]);
|
|
37351
37734
|
break;
|
|
37735
|
+
case "commits":
|
|
37736
|
+
data = library.getCommits(args[0], paging2);
|
|
37737
|
+
break;
|
|
37352
37738
|
case "events":
|
|
37353
37739
|
data = library.getEvents(args[0], { cursor: text3("cursor"), item: text3("item"), filter: text3("filter"), revision: text3("revision") });
|
|
37354
37740
|
break;
|
|
@@ -37378,7 +37764,7 @@ async function runCli(argv, io = {}) {
|
|
|
37378
37764
|
return command === "sources sync" && data.failed > 0 || command === "doctor" && !data.ok ? 1 : 0;
|
|
37379
37765
|
} catch (error) {
|
|
37380
37766
|
const failure = error instanceof LibraryError ? error : error instanceof EventReadError ? new LibraryError(error.status === 409 ? "STALE_CURSOR" : error.status === 404 ? "NOT_FOUND" : "INVALID_ARGUMENT", error.message, error.status === 400 ? 2 : 1) : new LibraryError("OPERATION_FAILED", error instanceof Error ? error.message : "Local operation failed.");
|
|
37381
|
-
if (
|
|
37767
|
+
if (json5) stdout(JSON.stringify({ schemaVersion: 1, command, error: { code: failure.code, message: failure.message } }) + "\n");
|
|
37382
37768
|
else stderr(`sessiongraph: ${cell(failure.message)}
|
|
37383
37769
|
`);
|
|
37384
37770
|
return failure.exitCode;
|