sessiongraph 1.0.18 → 1.0.20
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/PRIVACY.md +7 -0
- package/README.md +1 -1
- package/dist/assets/{index--OQ4NiAJ.js → index-BwNazXTF.js} +1 -1
- package/dist/assets/{index-DZcMVUpG.js → index-CUSJvhgf.js} +1 -1
- package/dist/assets/{index-ZvQzUBK1.css → index-CxnS4waR.css} +1 -1
- package/dist/assets/{index-DCSeQKMi.js → index-TSi2Km_w.js} +6 -6
- package/dist/assets/{index-ZwvTaIqn.js → index-nDYf67iK.js} +1 -1
- package/dist/assets/{public-viewer-DVqMq2gi.js → public-viewer-BMIcmydl.js} +1 -1
- package/dist/assets/{scene-B94ITHcm.js → scene-oSl4S0W6.js} +1 -1
- package/dist/assets/{share-DnZuWOzh.js → share-D7wrWEkV.js} +3 -3
- package/dist/index.html +2 -2
- package/dist-server/cli.mjs +1365 -1988
- package/dist-server/server.mjs +1274 -1544
- package/docs/cli.md +7 -1
- package/docs/guide.md +12 -4
- package/docs/import-coverage.md +3 -3
- package/package.json +7 -7
package/dist-server/server.mjs
CHANGED
|
@@ -79,7 +79,7 @@ function make7(connect) {
|
|
|
79
79
|
subscribe(options) {
|
|
80
80
|
return {
|
|
81
81
|
[Symbol.asyncIterator]() {
|
|
82
|
-
const
|
|
82
|
+
const pending = [];
|
|
83
83
|
const queued = [];
|
|
84
84
|
let started = false;
|
|
85
85
|
let completion;
|
|
@@ -93,7 +93,7 @@ function make7(connect) {
|
|
|
93
93
|
options?.signal?.removeEventListener("abort", abort);
|
|
94
94
|
if (connection?.subscribers.delete(subscriber) && !connection.subscribers.size)
|
|
95
95
|
stop2(connection);
|
|
96
|
-
|
|
96
|
+
pending.splice(0).forEach((request) => {
|
|
97
97
|
if ("error" in result)
|
|
98
98
|
request.reject(result.error);
|
|
99
99
|
else
|
|
@@ -113,7 +113,7 @@ function make7(connect) {
|
|
|
113
113
|
return;
|
|
114
114
|
if (!selected(value))
|
|
115
115
|
return;
|
|
116
|
-
const request =
|
|
116
|
+
const request = pending.shift();
|
|
117
117
|
if (request) {
|
|
118
118
|
request.resolve({ done: false, value });
|
|
119
119
|
return;
|
|
@@ -155,7 +155,7 @@ function make7(connect) {
|
|
|
155
155
|
return Promise.resolve({ done: true, value: void 0 });
|
|
156
156
|
}
|
|
157
157
|
const request = Promise.withResolvers();
|
|
158
|
-
|
|
158
|
+
pending.push(request);
|
|
159
159
|
if (!started) {
|
|
160
160
|
started = true;
|
|
161
161
|
options?.signal?.addEventListener("abort", abort, { once: true });
|
|
@@ -2139,9 +2139,13 @@ import { createServer } from "node:http";
|
|
|
2139
2139
|
import { createReadStream } from "node:fs";
|
|
2140
2140
|
import { stat as stat5 } from "node:fs/promises";
|
|
2141
2141
|
import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
2142
|
-
import { resolve as
|
|
2142
|
+
import { resolve as resolve4, extname, sep as sep4 } from "node:path";
|
|
2143
2143
|
import { randomBytes as randomBytes2, timingSafeEqual } from "node:crypto";
|
|
2144
2144
|
|
|
2145
|
+
// server/adapters/opencode.ts
|
|
2146
|
+
import { lstat as lstat3, readdir as readdir2 } from "node:fs/promises";
|
|
2147
|
+
import { join as join6 } from "node:path";
|
|
2148
|
+
|
|
2145
2149
|
// node_modules/.pnpm/@opencode+client@2.2.1_effect@4.0.1/node_modules/@opencode/client/dist/chunks/mcp-ve4aws36.js
|
|
2146
2150
|
import { spawn } from "node:child_process";
|
|
2147
2151
|
var stderrLimit = 8 * 1024;
|
|
@@ -2611,14 +2615,10 @@ async function terminate(info, options, timing) {
|
|
|
2611
2615
|
await rm2(options.file ?? fallback2(), { force: true });
|
|
2612
2616
|
}
|
|
2613
2617
|
function delay(milliseconds) {
|
|
2614
|
-
return new Promise((
|
|
2618
|
+
return new Promise((resolve5) => setTimeout(resolve5, milliseconds));
|
|
2615
2619
|
}
|
|
2616
2620
|
var Service = { discover, ensure, stop, headers: headers2 };
|
|
2617
2621
|
|
|
2618
|
-
// server/opencode.ts
|
|
2619
|
-
import { basename } from "node:path";
|
|
2620
|
-
import { createHash } from "node:crypto";
|
|
2621
|
-
|
|
2622
2622
|
// server/config.ts
|
|
2623
2623
|
import { existsSync } from "node:fs";
|
|
2624
2624
|
import { homedir as homedir2 } from "node:os";
|
|
@@ -2879,65 +2879,6 @@ function sessionFromResponse(value, id2) {
|
|
|
2879
2879
|
async function getSessionInfo(id2) {
|
|
2880
2880
|
return sessionFromResponse(await api(`/api/session/${encodeURIComponent(id2)}`), id2);
|
|
2881
2881
|
}
|
|
2882
|
-
var cache;
|
|
2883
|
-
var pending;
|
|
2884
|
-
async function getSessionGraph(force = false) {
|
|
2885
|
-
if (!force && cache && Date.now() - cache.loadedAt < 3e4) return cache;
|
|
2886
|
-
if (pending) return pending;
|
|
2887
|
-
pending = loadSessionGraph().then((data) => cache = data).finally(() => {
|
|
2888
|
-
pending = void 0;
|
|
2889
|
-
});
|
|
2890
|
-
return pending;
|
|
2891
|
-
}
|
|
2892
|
-
async function loadSessionGraph() {
|
|
2893
|
-
const endpoint = await Service.discover({ file: serviceFile() });
|
|
2894
|
-
if (!endpoint) throw new Error("No healthy OpenCode service was found.");
|
|
2895
|
-
const sourceID = createHash("sha256").update(JSON.stringify([endpoint.url, serviceFile() || "default"])).digest("hex");
|
|
2896
|
-
const rawProjects = await api("/api/project");
|
|
2897
|
-
const sessions = /* @__PURE__ */ new Map();
|
|
2898
|
-
const warnings = [];
|
|
2899
|
-
let cursor;
|
|
2900
|
-
const seenCursors = /* @__PURE__ */ new Set();
|
|
2901
|
-
do {
|
|
2902
|
-
const params = new URLSearchParams({ limit: "500" });
|
|
2903
|
-
if (cursor) params.set("cursor", cursor);
|
|
2904
|
-
const page = await api(`/api/session?${params}`);
|
|
2905
|
-
if (!Array.isArray(page.data)) throw new Error("Unexpected OpenCode session response. OpenCode V2 is required.");
|
|
2906
|
-
for (const raw of page.data) {
|
|
2907
|
-
const t = raw.tokens;
|
|
2908
|
-
sessions.set(raw.id, {
|
|
2909
|
-
id: raw.id,
|
|
2910
|
-
title: raw.title || "Untitled session",
|
|
2911
|
-
projectID: raw.projectID,
|
|
2912
|
-
parentID: raw.parentID,
|
|
2913
|
-
forkID: raw.fork?.sessionID,
|
|
2914
|
-
directory: raw.location?.directory || "",
|
|
2915
|
-
created: raw.time.created,
|
|
2916
|
-
updated: raw.time.updated,
|
|
2917
|
-
archived: Boolean(raw.time.archived),
|
|
2918
|
-
model: raw.model?.id || "Unknown model",
|
|
2919
|
-
provider: raw.model?.providerID || "",
|
|
2920
|
-
agent: raw.agent || "build",
|
|
2921
|
-
cost: recordedCost(raw.cost),
|
|
2922
|
-
// Input + output + cache tokens; reasoning is generally part of output.
|
|
2923
|
-
tokens: sumRecordedTokens([t?.input, t?.output, t?.cache?.read, t?.cache?.write]),
|
|
2924
|
-
usage: sessionUsage(openCodeUsage(t, raw.cost)),
|
|
2925
|
-
outcome: raw.outcome
|
|
2926
|
-
});
|
|
2927
|
-
}
|
|
2928
|
-
cursor = page.cursor?.next;
|
|
2929
|
-
if (cursor && seenCursors.has(cursor)) throw new Error("OpenCode returned a repeated session cursor.");
|
|
2930
|
-
if (cursor) seenCursors.add(cursor);
|
|
2931
|
-
} while (cursor && sessions.size < 2e4);
|
|
2932
|
-
if (cursor) warnings.push("OpenCode: Showing the newest 20,000 sessions.");
|
|
2933
|
-
const projects = rawProjects.map((p) => ({
|
|
2934
|
-
id: p.id,
|
|
2935
|
-
name: p.name || basename(p.canonical) || "Global",
|
|
2936
|
-
directory: p.canonical,
|
|
2937
|
-
worktrees: p.sandboxes || []
|
|
2938
|
-
}));
|
|
2939
|
-
return { sourceID, sessions: [...sessions.values()], projects, loadedAt: Date.now(), warnings };
|
|
2940
|
-
}
|
|
2941
2882
|
function editedPaths(part) {
|
|
2942
2883
|
if (part.state?.status !== "completed") return [];
|
|
2943
2884
|
const name = (part.name || "").split(/[./]/).at(-1) || "";
|
|
@@ -3067,11 +3008,11 @@ function extractContent(messages) {
|
|
|
3067
3008
|
}
|
|
3068
3009
|
|
|
3069
3010
|
// server/adapters/common.ts
|
|
3070
|
-
import { createHash
|
|
3071
|
-
import { basename
|
|
3072
|
-
var digest = (value) =>
|
|
3011
|
+
import { createHash } from "node:crypto";
|
|
3012
|
+
import { basename } from "node:path";
|
|
3013
|
+
var digest = (value) => createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
|
3073
3014
|
var identity = (source, native) => `${source}:${native}`;
|
|
3074
|
-
var project = (source, directory3) => ({ id: identity(source, digest(directory3).slice(0, 24)), name:
|
|
3015
|
+
var project = (source, directory3) => ({ id: identity(source, digest(directory3).slice(0, 24)), name: basename(directory3) || "Global", directory: directory3, worktrees: [] });
|
|
3075
3016
|
var blankSession = (source, nativeID, directory3 = "") => ({
|
|
3076
3017
|
source,
|
|
3077
3018
|
nativeID,
|
|
@@ -3201,12 +3142,12 @@ function blockEvents(message2, content, transform = (v3) => v3) {
|
|
|
3201
3142
|
});
|
|
3202
3143
|
}
|
|
3203
3144
|
function userBlockEvents(message2, content, normalize) {
|
|
3204
|
-
const
|
|
3145
|
+
const context2 = [];
|
|
3205
3146
|
return blockEvents(message2, content, (value) => {
|
|
3206
3147
|
const text2 = normalize(value);
|
|
3207
|
-
|
|
3148
|
+
context2.push(Boolean(value && !text2));
|
|
3208
3149
|
return text2 || value;
|
|
3209
|
-
}).map((event) => event.kind === "message" &&
|
|
3150
|
+
}).map((event) => event.kind === "message" && context2.shift() ? { ...event, kind: "event", role: "system", name: "Session context", nativeType: "user-context" } : event);
|
|
3210
3151
|
}
|
|
3211
3152
|
function normalizedEvents(message2, sessionID) {
|
|
3212
3153
|
let events = message2.events;
|
|
@@ -3248,8 +3189,8 @@ var COMMIT_EXTRACTOR_VERSION = 1;
|
|
|
3248
3189
|
var object2 = (v3) => v3 && typeof v3 === "object" && !Array.isArray(v3) ? v3 : {};
|
|
3249
3190
|
var string2 = (v3) => typeof v3 === "string" ? v3 : void 0;
|
|
3250
3191
|
var exitCode = (v3) => typeof v3 === "number" && Number.isSafeInteger(v3) ? v3 : void 0;
|
|
3251
|
-
function executionFields(input,
|
|
3252
|
-
const args = object2(input), meta = object2(
|
|
3192
|
+
function executionFields(input, metadata3 = {}) {
|
|
3193
|
+
const args = object2(input), meta = object2(metadata3);
|
|
3253
3194
|
return { cwd: string2(args.workdir ?? args.cwd ?? args.working_directory ?? meta.cwd), exitCode: exitCode(meta.exitCode ?? meta.exit_code ?? meta.exit) };
|
|
3254
3195
|
}
|
|
3255
3196
|
function nativeCommit(value) {
|
|
@@ -3416,7 +3357,7 @@ function opencodeEvents(raw, message2) {
|
|
|
3416
3357
|
else if (part.type === "tool") {
|
|
3417
3358
|
const state2 = part.state || {}, endTime = messageTime(part.time?.completed);
|
|
3418
3359
|
const status2 = state2.status === "error" ? "failed" : state2.status === "streaming" ? "pending" : ["running", "completed"].includes(state2.status) ? state2.status : "unknown";
|
|
3419
|
-
const common = { ...native, callID: part.id, status: status2, endTime, ...executionFields(state2.input, state2.metadata), partial: Boolean(state2.metadata?.truncated) };
|
|
3360
|
+
const common = { ...native, callID: part.callID || part.id, status: status2, endTime, ...executionFields(state2.input, state2.metadata), partial: Boolean(state2.metadata?.truncated) };
|
|
3420
3361
|
events.push(eventFor(message2, `${id2}:call`, "tool_call", part.name || "Tool call", "", { ...common, ...timing, input: eventText(state2.input) }));
|
|
3421
3362
|
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) }));
|
|
3422
3363
|
} else events.push(eventFor(message2, id2, "event", `${part.type || "Unknown"} content`, "Unsupported content.", { ...native, ...timing, partial: true }));
|
|
@@ -3427,6 +3368,639 @@ function opencodeEvents(raw, message2) {
|
|
|
3427
3368
|
return events;
|
|
3428
3369
|
}
|
|
3429
3370
|
|
|
3371
|
+
// server/adapters/harness-paths.ts
|
|
3372
|
+
import { homedir as homedir3 } from "node:os";
|
|
3373
|
+
import { join as join3 } from "node:path";
|
|
3374
|
+
|
|
3375
|
+
// server/source-paths.ts
|
|
3376
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3377
|
+
var paths = new AsyncLocalStorage();
|
|
3378
|
+
var sourcePath = (id2) => paths.getStore()?.[id2];
|
|
3379
|
+
function withSourcePaths(adapter, configured) {
|
|
3380
|
+
return {
|
|
3381
|
+
...adapter,
|
|
3382
|
+
detect: () => paths.run(configured(), () => adapter.detect()),
|
|
3383
|
+
discover: () => paths.run(configured(), async () => {
|
|
3384
|
+
const result = await adapter.discover();
|
|
3385
|
+
if (!sourcePath(adapter.id)) return result;
|
|
3386
|
+
return { ...result, sessions: result.sessions.map((candidate) => ({ ...candidate, session: { ...candidate.session, nativeResume: false } })) };
|
|
3387
|
+
}),
|
|
3388
|
+
read: (candidate, cursor) => paths.run(configured(), async () => {
|
|
3389
|
+
const result = await adapter.read(candidate, cursor);
|
|
3390
|
+
if (sourcePath(adapter.id)) candidate.session.nativeResume = false;
|
|
3391
|
+
return result;
|
|
3392
|
+
})
|
|
3393
|
+
};
|
|
3394
|
+
}
|
|
3395
|
+
|
|
3396
|
+
// server/adapters/harness-paths.ts
|
|
3397
|
+
var homePath = (...parts) => join3(homedir3(), ...parts);
|
|
3398
|
+
var dataPath = (...parts) => join3(process.env.XDG_DATA_HOME || homePath(".local/share"), ...parts);
|
|
3399
|
+
var configPath = (...parts) => join3(process.env.XDG_CONFIG_HOME || homePath(".config"), ...parts);
|
|
3400
|
+
var appPath = (...parts) => join3(process.platform === "darwin" ? homePath("Library/Application Support") : process.platform === "win32" ? process.env.APPDATA || homePath("AppData/Roaming") : process.env.XDG_CONFIG_HOME || homePath(".config"), ...parts);
|
|
3401
|
+
var tokscalePath = (...parts) => join3(process.env.TOKSCALE_CONFIG_DIR || (process.platform === "win32" ? appPath("tokscale") : configPath("tokscale")), ...parts);
|
|
3402
|
+
var envHome = (env2, fallback, ...parts) => join3(process.env[env2]?.trim() || homePath(fallback), ...parts);
|
|
3403
|
+
var harnessRoots = (id2, defaults) => () => {
|
|
3404
|
+
const override = sourcePath(id2) || process.env[`SESSIONGRAPH_${id2.replace(/-/g, "_").toUpperCase()}_HISTORY_DIR`]?.trim();
|
|
3405
|
+
return override ? [override] : defaults();
|
|
3406
|
+
};
|
|
3407
|
+
|
|
3408
|
+
// server/adapters/sqlite-histories.ts
|
|
3409
|
+
import { lstat as lstat2 } from "node:fs/promises";
|
|
3410
|
+
|
|
3411
|
+
// server/adapters/local-files.ts
|
|
3412
|
+
import { constants } from "node:fs";
|
|
3413
|
+
import { lstat, open, readdir } from "node:fs/promises";
|
|
3414
|
+
import { join as join4, relative } from "node:path";
|
|
3415
|
+
|
|
3416
|
+
// server/adapters/compressed.ts
|
|
3417
|
+
import { gunzipSync, zstdDecompressSync } from "node:zlib";
|
|
3418
|
+
function expandHistory(buffer, maxOutputLength) {
|
|
3419
|
+
if (buffer.length >= 4 && buffer.readUInt32LE(0) === 4247762216) return zstdDecompressSync(buffer, { maxOutputLength });
|
|
3420
|
+
if (buffer[0] === 31 && buffer[1] === 139) return gunzipSync(buffer, { maxOutputLength });
|
|
3421
|
+
if (buffer.length > maxOutputLength) throw new Error("Expanded history exceeds the snapshot limit.");
|
|
3422
|
+
return buffer;
|
|
3423
|
+
}
|
|
3424
|
+
|
|
3425
|
+
// server/adapters/local-files.ts
|
|
3426
|
+
var object3 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
3427
|
+
var text = (value) => typeof value === "string" ? value : "";
|
|
3428
|
+
var time = (value) => {
|
|
3429
|
+
const n = typeof value === "number" ? value : typeof value === "string" ? /^\d{13}$/.test(value) ? Number(value) : Date.parse(value) : 0;
|
|
3430
|
+
return Number.isFinite(n) && n > 0 && n <= 864e13 ? n : 0;
|
|
3431
|
+
};
|
|
3432
|
+
var MAX_BYTES = 32e6;
|
|
3433
|
+
var MAX_RECORDS = 5e4;
|
|
3434
|
+
var MAX_FILES = 2e4;
|
|
3435
|
+
async function fileState(path) {
|
|
3436
|
+
try {
|
|
3437
|
+
const s = await lstat(path);
|
|
3438
|
+
if (!s.isFile()) throw new Error("History must be a regular file, not a symlink.");
|
|
3439
|
+
if (s.size > MAX_BYTES) throw new Error("History exceeds the 32 MB per-file limit.");
|
|
3440
|
+
return { path, signature: digest([s.size, s.mtimeMs, s.ctimeMs, s.ino]), created: s.birthtimeMs || s.mtimeMs, updated: s.mtimeMs, size: s.size };
|
|
3441
|
+
} catch (error) {
|
|
3442
|
+
if (error.code === "ENOENT") return { path, signature: "missing", created: 0, updated: 0, size: 0 };
|
|
3443
|
+
throw error;
|
|
3444
|
+
}
|
|
3445
|
+
}
|
|
3446
|
+
async function historyFiles(roots2, match2) {
|
|
3447
|
+
const files = [], queue = [];
|
|
3448
|
+
const warnings = [];
|
|
3449
|
+
for (const root2 of new Set(roots2)) {
|
|
3450
|
+
try {
|
|
3451
|
+
if ((await lstat(root2)).isDirectory()) queue.push({ root: root2, path: root2, depth: 0 });
|
|
3452
|
+
} catch (error) {
|
|
3453
|
+
if (error.code !== "ENOENT") warnings.push("A history directory could not be read.");
|
|
3454
|
+
}
|
|
3455
|
+
}
|
|
3456
|
+
let entriesSeen = 0, limited = false;
|
|
3457
|
+
for (let i = 0; i < queue.length && files.length < MAX_FILES && entriesSeen < 1e5; i++) {
|
|
3458
|
+
const { root: root2, path, depth } = queue[i];
|
|
3459
|
+
let entries2;
|
|
3460
|
+
try {
|
|
3461
|
+
entries2 = await readdir(path, { withFileTypes: true });
|
|
3462
|
+
} catch {
|
|
3463
|
+
warnings.push("A history directory could not be read.");
|
|
3464
|
+
continue;
|
|
3465
|
+
}
|
|
3466
|
+
for (const entry of entries2) {
|
|
3467
|
+
if (++entriesSeen > 1e5 || files.length >= MAX_FILES) {
|
|
3468
|
+
limited = true;
|
|
3469
|
+
break;
|
|
3470
|
+
}
|
|
3471
|
+
const file = join4(path, entry.name);
|
|
3472
|
+
if (entry.isDirectory()) {
|
|
3473
|
+
if (depth < 6 && queue.length < MAX_FILES) queue.push({ root: root2, path: file, depth: depth + 1 });
|
|
3474
|
+
else limited = true;
|
|
3475
|
+
}
|
|
3476
|
+
if (entry.isFile() && match2(relative(root2, file).split("\\").join("/"))) files.push(file);
|
|
3477
|
+
}
|
|
3478
|
+
}
|
|
3479
|
+
if (limited) warnings.push("History discovery reached its file, directory, or depth limit.");
|
|
3480
|
+
return { files: [...new Set(files)].sort(), warnings };
|
|
3481
|
+
}
|
|
3482
|
+
function json3(value) {
|
|
3483
|
+
return JSON.parse(value);
|
|
3484
|
+
}
|
|
3485
|
+
function jsonLines(value) {
|
|
3486
|
+
const rows2 = [];
|
|
3487
|
+
let partial = false;
|
|
3488
|
+
for (const line of value.split("\n")) {
|
|
3489
|
+
if (!line.trim()) continue;
|
|
3490
|
+
if (rows2.length >= MAX_RECORDS) throw new Error("History exceeds the 50,000-record limit.");
|
|
3491
|
+
if (line.length > 2e6) throw new Error("History contains a record larger than 2 MB.");
|
|
3492
|
+
try {
|
|
3493
|
+
const row = json3(line);
|
|
3494
|
+
if (!row || typeof row !== "object" || Array.isArray(row)) partial = true;
|
|
3495
|
+
else rows2.push(row);
|
|
3496
|
+
} catch {
|
|
3497
|
+
partial = true;
|
|
3498
|
+
}
|
|
3499
|
+
}
|
|
3500
|
+
return { rows: rows2, partial };
|
|
3501
|
+
}
|
|
3502
|
+
function localFileAdapter(source) {
|
|
3503
|
+
const metadata3 = /* @__PURE__ */ new Map();
|
|
3504
|
+
let cached2;
|
|
3505
|
+
const states = (path) => Promise.all([path, ...source.extras?.(path) || []].map(fileState));
|
|
3506
|
+
const revision2 = (values) => digest([1, ...values.filter((_, i) => i === 0 || source.revisionExtras !== false).map((s) => [s.path, s.signature])]);
|
|
3507
|
+
async function load(path, expected, before) {
|
|
3508
|
+
if (revision2(before) !== expected) throw new Error("Session changed during import; import again.");
|
|
3509
|
+
if (cached2?.path === path && cached2.revision === expected) return cached2.history;
|
|
3510
|
+
if (before[0].signature === "missing") throw new Error("History file is unavailable.");
|
|
3511
|
+
if (before.reduce((n, s) => n + s.size, 0) > MAX_BYTES) throw new Error("Combined history exceeds the 32 MB snapshot limit.");
|
|
3512
|
+
const files = /* @__PURE__ */ new Map();
|
|
3513
|
+
let expanded = 0;
|
|
3514
|
+
for (const s of before.filter((s2) => s2.signature !== "missing")) {
|
|
3515
|
+
const handle = await open(s.path, constants.O_RDONLY | (constants.O_NOFOLLOW || 0));
|
|
3516
|
+
try {
|
|
3517
|
+
const buffer = Buffer.alloc(s.size + 1);
|
|
3518
|
+
let bytes2 = 0;
|
|
3519
|
+
while (bytes2 < buffer.length) {
|
|
3520
|
+
const part = await handle.read(buffer, bytes2, buffer.length - bytes2, bytes2);
|
|
3521
|
+
if (!part.bytesRead) break;
|
|
3522
|
+
bytes2 += part.bytesRead;
|
|
3523
|
+
}
|
|
3524
|
+
if (bytes2 !== s.size) throw new Error("History changed while reading; import again.");
|
|
3525
|
+
const data = expandHistory(buffer.subarray(0, bytes2), MAX_BYTES);
|
|
3526
|
+
expanded += data.length;
|
|
3527
|
+
if (expanded > MAX_BYTES) throw new Error("Expanded history exceeds the 32 MB snapshot limit.");
|
|
3528
|
+
files.set(s.path, data.toString("utf8"));
|
|
3529
|
+
} finally {
|
|
3530
|
+
await handle.close();
|
|
3531
|
+
}
|
|
3532
|
+
}
|
|
3533
|
+
if (digest(await states(path)) !== digest(before)) throw new Error("History changed while reading; import again.");
|
|
3534
|
+
const history = source.parse(path, files);
|
|
3535
|
+
if (!history) return;
|
|
3536
|
+
if (source.capabilities.history && !history.messages.length) throw new Error("No readable conversation.");
|
|
3537
|
+
if (!history.nativeID || history.nativeID.length > 512) throw new Error("History has no supported native session identity.");
|
|
3538
|
+
if (history.messages.length > MAX_RECORDS) throw new Error("History exceeds the 50,000-message limit.");
|
|
3539
|
+
cached2 = { path, revision: expected, history };
|
|
3540
|
+
return history;
|
|
3541
|
+
}
|
|
3542
|
+
return {
|
|
3543
|
+
id: source.id,
|
|
3544
|
+
name: source.name,
|
|
3545
|
+
description: source.description,
|
|
3546
|
+
capabilities: source.capabilities,
|
|
3547
|
+
async detect() {
|
|
3548
|
+
for (const root2 of source.roots()) if ((await lstat(root2).catch(() => void 0))?.isDirectory()) return true;
|
|
3549
|
+
return false;
|
|
3550
|
+
},
|
|
3551
|
+
async discover() {
|
|
3552
|
+
const listing = await historyFiles(source.roots(), source.match), found = /* @__PURE__ */ new Map();
|
|
3553
|
+
let failed = 0;
|
|
3554
|
+
const blocked = /* @__PURE__ */ new Set(), unreadable = /* @__PURE__ */ new Set();
|
|
3555
|
+
for (const path of listing.files) {
|
|
3556
|
+
try {
|
|
3557
|
+
const before = await states(path), rev = revision2(before);
|
|
3558
|
+
let candidate = metadata3.get(path);
|
|
3559
|
+
if (!candidate || candidate.revision !== rev) {
|
|
3560
|
+
const history = await load(path, rev, before);
|
|
3561
|
+
if (!history) {
|
|
3562
|
+
const nativeID = source.authoritativeIdentity?.(path);
|
|
3563
|
+
if (nativeID) blocked.add(identity(source.id, nativeID));
|
|
3564
|
+
continue;
|
|
3565
|
+
}
|
|
3566
|
+
const session = { ...blankSession(source.id, history.nativeID), ...history.session };
|
|
3567
|
+
session.id = identity(source.id, history.nativeID);
|
|
3568
|
+
session.nativeID = history.nativeID;
|
|
3569
|
+
session.source = source.id;
|
|
3570
|
+
session.directory = text(session.directory);
|
|
3571
|
+
session.projectID = project(source.id, session.directory).id;
|
|
3572
|
+
session.created = time(session.created) || history.messages.map((m) => time(m.time)).find(Boolean) || before[0].created;
|
|
3573
|
+
session.updated = before[0].updated;
|
|
3574
|
+
session.agent ||= source.name;
|
|
3575
|
+
session.parentID = history.parent ? identity(source.id, history.parent) : void 0;
|
|
3576
|
+
session.forkID = history.fork ? identity(source.id, history.fork) : void 0;
|
|
3577
|
+
if (session.title === "Untitled session" || !session.title) session.title = history.messages.flatMap((m) => m.role === "user" ? m.fragments.filter((f) => f.kind === "You").map((f) => f.text) : []).find(Boolean)?.replace(/\s+/g, " ").slice(0, 180) || `${source.name} session`;
|
|
3578
|
+
candidate = { session, revision: rev, locator: { path } };
|
|
3579
|
+
metadata3.set(path, candidate);
|
|
3580
|
+
}
|
|
3581
|
+
const previous = found.get(candidate.session.id);
|
|
3582
|
+
const preferred = candidate.locator.path.endsWith(".jsonl"), previousPreferred = previous?.locator.path.endsWith(".jsonl");
|
|
3583
|
+
if (!previous || preferred && !previousPreferred || preferred === previousPreferred && candidate.session.updated > previous.session.updated) found.set(candidate.session.id, candidate);
|
|
3584
|
+
} catch {
|
|
3585
|
+
const nativeID = source.authoritativeIdentity?.(path);
|
|
3586
|
+
if (nativeID) {
|
|
3587
|
+
const id2 = identity(source.id, nativeID);
|
|
3588
|
+
blocked.add(id2);
|
|
3589
|
+
unreadable.add(id2);
|
|
3590
|
+
} else failed++;
|
|
3591
|
+
}
|
|
3592
|
+
}
|
|
3593
|
+
const listed = new Set(listing.files);
|
|
3594
|
+
for (const path of metadata3.keys()) if (!listed.has(path)) metadata3.delete(path);
|
|
3595
|
+
if (failed) listing.warnings.push(`${source.name}: Skipped ${failed} unreadable, changing, unsupported, or oversized ${failed === 1 ? "history file" : "history files"}.`);
|
|
3596
|
+
const sessions = [...found.values()].filter((c) => !blocked.has(c.session.id));
|
|
3597
|
+
const errors = unreadable.size ? [`${source.name}: Could not read history for ${unreadable.size} ${unreadable.size === 1 ? "session" : "sessions"}.`] : void 0;
|
|
3598
|
+
return { sessions, projects: [...new Map(sessions.map((c) => {
|
|
3599
|
+
const p = project(source.id, c.session.directory);
|
|
3600
|
+
return [p.id, p];
|
|
3601
|
+
})).values()], warnings: listing.warnings, errors, blocked: [...blocked] };
|
|
3602
|
+
},
|
|
3603
|
+
async read(candidate, cursor) {
|
|
3604
|
+
const offset = cursor === void 0 ? 0 : Number(cursor);
|
|
3605
|
+
if (!Number.isSafeInteger(offset) || offset < 0) throw new Error("Invalid history cursor.");
|
|
3606
|
+
const history = await load(candidate.locator.path, candidate.revision, await states(candidate.locator.path));
|
|
3607
|
+
if (!history) throw new Error("History representation is no longer available.");
|
|
3608
|
+
const messages = history.messages.slice(offset, offset + 100);
|
|
3609
|
+
return {
|
|
3610
|
+
messages,
|
|
3611
|
+
cursor: offset + messages.length < history.messages.length ? String(offset + messages.length) : void 0,
|
|
3612
|
+
partial: Boolean(history.partial || messages.some((m) => m.partial)),
|
|
3613
|
+
note: history.note
|
|
3614
|
+
};
|
|
3615
|
+
}
|
|
3616
|
+
};
|
|
3617
|
+
}
|
|
3618
|
+
|
|
3619
|
+
// server/adapters/sqlite-snapshot.ts
|
|
3620
|
+
import { DatabaseSync } from "node:sqlite";
|
|
3621
|
+
import { chmodSync, constants as constants2, copyFileSync, lstatSync, mkdtempSync, rmSync } from "node:fs";
|
|
3622
|
+
import { copyFile, statfs } from "node:fs/promises";
|
|
3623
|
+
import { tmpdir } from "node:os";
|
|
3624
|
+
import { join as join5 } from "node:path";
|
|
3625
|
+
var copies = /* @__PURE__ */ new Map();
|
|
3626
|
+
var SqliteSnapshotChangedError = class extends Error {
|
|
3627
|
+
};
|
|
3628
|
+
var SqliteSnapshotFileError = class extends Error {
|
|
3629
|
+
};
|
|
3630
|
+
var close = (path) => {
|
|
3631
|
+
const copy = copies.get(path);
|
|
3632
|
+
if (!copy) return;
|
|
3633
|
+
copies.delete(path);
|
|
3634
|
+
try {
|
|
3635
|
+
copy.db.close();
|
|
3636
|
+
} finally {
|
|
3637
|
+
rmSync(copy.directory, { recursive: true, force: true });
|
|
3638
|
+
}
|
|
3639
|
+
};
|
|
3640
|
+
process.once("exit", () => {
|
|
3641
|
+
for (const path of copies.keys()) close(path);
|
|
3642
|
+
});
|
|
3643
|
+
function snapshotFiles(path, large) {
|
|
3644
|
+
return [path, `${path}-wal`].map((file, i) => {
|
|
3645
|
+
try {
|
|
3646
|
+
const s = lstatSync(file);
|
|
3647
|
+
const kind = i ? "History database WAL" : "History database";
|
|
3648
|
+
if (!s.isFile()) throw new SqliteSnapshotFileError(`${kind} is not a regular file.`);
|
|
3649
|
+
if (!large && s.size > 8e9) throw new SqliteSnapshotFileError(`${kind} exceeds 8 GB.`);
|
|
3650
|
+
return s;
|
|
3651
|
+
} catch (error) {
|
|
3652
|
+
if (i && error.code === "ENOENT") return null;
|
|
3653
|
+
throw error;
|
|
3654
|
+
}
|
|
3655
|
+
});
|
|
3656
|
+
}
|
|
3657
|
+
var fingerprint = (path, files) => digest([path, ...files.map((s) => s && [s.dev, s.ino, s.size, s.mtimeMs, s.ctimeMs])]);
|
|
3658
|
+
function sqliteRevision(path) {
|
|
3659
|
+
return fingerprint(path, snapshotFiles(path, false));
|
|
3660
|
+
}
|
|
3661
|
+
function openSnapshot(destination) {
|
|
3662
|
+
const db2 = new DatabaseSync(destination, { readOnly: true, enableDoubleQuotedStringLiterals: false, allowExtension: false });
|
|
3663
|
+
try {
|
|
3664
|
+
db2.exec("PRAGMA query_only=ON; PRAGMA trusted_schema=OFF; PRAGMA busy_timeout=1000; BEGIN;");
|
|
3665
|
+
return db2;
|
|
3666
|
+
} catch (error) {
|
|
3667
|
+
db2.close();
|
|
3668
|
+
throw error;
|
|
3669
|
+
}
|
|
3670
|
+
}
|
|
3671
|
+
async function withLargeSqliteSnapshot(path, read3, expected) {
|
|
3672
|
+
const retained = copies.get(path);
|
|
3673
|
+
if (expected && retained?.revision === expected) return read3(retained.db, expected);
|
|
3674
|
+
const files = snapshotFiles(path, true), revision2 = fingerprint(path, files);
|
|
3675
|
+
if (expected && revision2 !== expected) throw new SqliteSnapshotChangedError("History database changed during import; import again.");
|
|
3676
|
+
if (retained?.revision === revision2) {
|
|
3677
|
+
const result = read3(retained.db, revision2);
|
|
3678
|
+
if (fingerprint(path, snapshotFiles(path, true)) !== revision2) throw new SqliteSnapshotChangedError("History database changed during reading; import again.");
|
|
3679
|
+
return result;
|
|
3680
|
+
}
|
|
3681
|
+
close(path);
|
|
3682
|
+
while (copies.size >= 2) close(copies.keys().next().value);
|
|
3683
|
+
const directory3 = mkdtempSync(join5(tmpdir(), "sessiongraph-history-"));
|
|
3684
|
+
const destination = join5(directory3, "history.db");
|
|
3685
|
+
let db2;
|
|
3686
|
+
try {
|
|
3687
|
+
for (const [index, suffix] of ["", "-wal"].entries()) {
|
|
3688
|
+
const file = files[index];
|
|
3689
|
+
if (!file) continue;
|
|
3690
|
+
try {
|
|
3691
|
+
await copyFile(path + suffix, destination + suffix, constants2.COPYFILE_FICLONE_FORCE);
|
|
3692
|
+
} catch (error) {
|
|
3693
|
+
if (!["ENOSYS", "ENOTSUP", "EOPNOTSUPP", "EXDEV", "EINVAL"].includes(error.code || "")) throw error;
|
|
3694
|
+
const { bavail, bsize } = await statfs(directory3);
|
|
3695
|
+
const reserve = 512 * 1024 * 1024;
|
|
3696
|
+
if (bavail * bsize < file.size + reserve) throw new Error("Not enough free space for the T3 history snapshot. Free space on the temporary drive and retry.");
|
|
3697
|
+
await copyFile(path + suffix, destination + suffix);
|
|
3698
|
+
}
|
|
3699
|
+
chmodSync(destination + suffix, 384);
|
|
3700
|
+
}
|
|
3701
|
+
if (fingerprint(path, snapshotFiles(path, true)) !== revision2) throw new SqliteSnapshotChangedError("History database changed while copying; import again.");
|
|
3702
|
+
db2 = openSnapshot(destination);
|
|
3703
|
+
const result = read3(db2, revision2);
|
|
3704
|
+
if (!expected && fingerprint(path, snapshotFiles(path, true)) !== revision2) throw new SqliteSnapshotChangedError("History database changed during reading; import again.");
|
|
3705
|
+
close(path);
|
|
3706
|
+
while (copies.size >= 2) close(copies.keys().next().value);
|
|
3707
|
+
copies.set(path, { revision: revision2, directory: directory3, db: db2 });
|
|
3708
|
+
return result;
|
|
3709
|
+
} catch (error) {
|
|
3710
|
+
try {
|
|
3711
|
+
db2?.close();
|
|
3712
|
+
} finally {
|
|
3713
|
+
rmSync(directory3, { recursive: true, force: true });
|
|
3714
|
+
}
|
|
3715
|
+
if (error.code === "ENOENT" && fingerprint(path, snapshotFiles(path, true)) !== revision2)
|
|
3716
|
+
throw new SqliteSnapshotChangedError("History database changed while copying; import again.");
|
|
3717
|
+
throw error;
|
|
3718
|
+
}
|
|
3719
|
+
}
|
|
3720
|
+
function withSqliteSnapshot(path, read3, expected, pinned = false) {
|
|
3721
|
+
const retained = copies.get(path);
|
|
3722
|
+
if (pinned && expected && retained?.revision === expected) return read3(retained.db);
|
|
3723
|
+
const revision2 = sqliteRevision(path);
|
|
3724
|
+
if (expected && revision2 !== expected) throw new SqliteSnapshotChangedError("History database changed during import; import again.");
|
|
3725
|
+
let copy = copies.get(path);
|
|
3726
|
+
if (copy?.revision !== revision2) {
|
|
3727
|
+
close(path);
|
|
3728
|
+
while (copies.size >= 2) close(copies.keys().next().value);
|
|
3729
|
+
const directory3 = mkdtempSync(join5(tmpdir(), "sessiongraph-history-"));
|
|
3730
|
+
let db2;
|
|
3731
|
+
try {
|
|
3732
|
+
chmodSync(directory3, 448);
|
|
3733
|
+
const destination = join5(directory3, "history.db");
|
|
3734
|
+
for (const suffix of ["", "-wal"]) {
|
|
3735
|
+
try {
|
|
3736
|
+
copyFileSync(path + suffix, destination + suffix, constants2.COPYFILE_FICLONE);
|
|
3737
|
+
chmodSync(destination + suffix, 384);
|
|
3738
|
+
} catch (error) {
|
|
3739
|
+
if (suffix && error.code === "ENOENT") continue;
|
|
3740
|
+
throw error;
|
|
3741
|
+
}
|
|
3742
|
+
}
|
|
3743
|
+
if (sqliteRevision(path) !== revision2) throw new SqliteSnapshotChangedError("History database changed while copying; import again.");
|
|
3744
|
+
db2 = openSnapshot(destination);
|
|
3745
|
+
copy = { revision: revision2, directory: directory3, db: db2 };
|
|
3746
|
+
copies.set(path, copy);
|
|
3747
|
+
} catch (error) {
|
|
3748
|
+
try {
|
|
3749
|
+
db2?.close();
|
|
3750
|
+
} finally {
|
|
3751
|
+
rmSync(directory3, { recursive: true, force: true });
|
|
3752
|
+
}
|
|
3753
|
+
throw error;
|
|
3754
|
+
}
|
|
3755
|
+
}
|
|
3756
|
+
const result = read3(copy.db);
|
|
3757
|
+
if (!pinned && sqliteRevision(path) !== revision2) throw new SqliteSnapshotChangedError("History database changed during reading; import again.");
|
|
3758
|
+
return result;
|
|
3759
|
+
}
|
|
3760
|
+
function hasTable(db2, name) {
|
|
3761
|
+
const row = db2.prepare("SELECT sql FROM sqlite_master WHERE type='table' AND name=?").get(name);
|
|
3762
|
+
return typeof row?.sql === "string" && !/CREATE\s+VIRTUAL/i.test(row.sql);
|
|
3763
|
+
}
|
|
3764
|
+
|
|
3765
|
+
// server/adapters/sqlite-histories.ts
|
|
3766
|
+
var budget;
|
|
3767
|
+
var rowBytes = (row) => Object.values(row).reduce((n, v3) => n + (typeof v3 === "string" ? Buffer.byteLength(v3) : v3 instanceof Uint8Array ? v3.byteLength : 8), 0);
|
|
3768
|
+
function consume(bytes2, records = 0) {
|
|
3769
|
+
if (!budget) return;
|
|
3770
|
+
budget.bytes += bytes2;
|
|
3771
|
+
budget.records += records;
|
|
3772
|
+
if (budget.bytes > 64e6 || budget.records > 5e4) throw new Error("Session exceeds the 64 MB / 50,000-record snapshot limit.");
|
|
3773
|
+
}
|
|
3774
|
+
function parseHistory(source, db2, row, path) {
|
|
3775
|
+
const previous = budget;
|
|
3776
|
+
budget = { bytes: 0, records: 0 };
|
|
3777
|
+
try {
|
|
3778
|
+
consume(rowBytes(row), 1);
|
|
3779
|
+
const history = source.parse(db2, row, path);
|
|
3780
|
+
if (history && history.messages.length > 5e4) throw new Error("Session exceeds the 50,000-message limit.");
|
|
3781
|
+
return history;
|
|
3782
|
+
} finally {
|
|
3783
|
+
budget = previous;
|
|
3784
|
+
}
|
|
3785
|
+
}
|
|
3786
|
+
function columns(db2, table) {
|
|
3787
|
+
if (!/^[a-z_][a-z0-9_]*$/.test(table) || !hasTable(db2, table)) throw new Error(`Unsupported history table: ${table}.`);
|
|
3788
|
+
return new Set(db2.prepare(`PRAGMA table_info("${table}")`).all().map((r) => String(r.name)));
|
|
3789
|
+
}
|
|
3790
|
+
function rows(db2, table, fields3, filter, order, limit = 5e4) {
|
|
3791
|
+
const available = columns(db2, table);
|
|
3792
|
+
for (const name of [...fields3, ...filter ? [filter[0]] : [], ...order ? [order] : []]) if (!/^[a-zA-Z_][\w]*$/.test(name)) throw new Error("Invalid history column.");
|
|
3793
|
+
if (filter && !available.has(filter[0])) throw new Error("Unsupported history relation.");
|
|
3794
|
+
const size = (f) => `length(CAST("${f}" AS BLOB))`;
|
|
3795
|
+
const select = fields3.map((f) => available.has(f) ? `CASE WHEN ${size(f)}<=32000000 THEN "${f}" END AS "${f}"` : `NULL AS "${f}"`).join(",");
|
|
3796
|
+
const oversized = fields3.filter((f) => available.has(f)).map((f) => `COALESCE(${size(f)},0)>32000000`).join(" OR ") || "0";
|
|
3797
|
+
const query = `SELECT ${select}, (${oversized}) AS __sessiongraph_oversized FROM "${table}"${filter ? ` WHERE "${filter[0]}"=?` : ""}${order && available.has(order) ? ` ORDER BY "${order}"` : ""} LIMIT ${limit + 1}`;
|
|
3798
|
+
const result = [];
|
|
3799
|
+
let bytes2 = 0;
|
|
3800
|
+
for (const row of db2.prepare(query).iterate(...filter ? [filter[1]] : [])) {
|
|
3801
|
+
if (row.__sessiongraph_oversized) throw new Error("History field exceeds the 32 MB snapshot limit.");
|
|
3802
|
+
delete row.__sessiongraph_oversized;
|
|
3803
|
+
const size2 = rowBytes(row);
|
|
3804
|
+
bytes2 += size2;
|
|
3805
|
+
consume(size2, 1);
|
|
3806
|
+
if (bytes2 > 64e6 || result.length >= limit) throw new Error("History exceeds the 64 MB / record-count query limit.");
|
|
3807
|
+
result.push(row);
|
|
3808
|
+
}
|
|
3809
|
+
return result;
|
|
3810
|
+
}
|
|
3811
|
+
function sqliteJSON(value) {
|
|
3812
|
+
if (value instanceof Uint8Array) {
|
|
3813
|
+
const expanded = expandHistory(Buffer.from(value), Math.max(1, Math.min(32e6, 64e6 - (budget?.bytes || 0))));
|
|
3814
|
+
consume(expanded.byteLength);
|
|
3815
|
+
return JSON.parse(expanded.toString("utf8"));
|
|
3816
|
+
}
|
|
3817
|
+
if (typeof value === "string") return JSON.parse(value);
|
|
3818
|
+
throw new Error("Missing or oversized history payload.");
|
|
3819
|
+
}
|
|
3820
|
+
function optionalJSON(value) {
|
|
3821
|
+
return value == null || value === "" ? {} : sqliteJSON(value);
|
|
3822
|
+
}
|
|
3823
|
+
function sqliteHistoryAdapter(source) {
|
|
3824
|
+
const metadata3 = /* @__PURE__ */ new Map();
|
|
3825
|
+
return {
|
|
3826
|
+
id: source.id,
|
|
3827
|
+
name: source.name,
|
|
3828
|
+
description: source.description || "Local session database",
|
|
3829
|
+
capabilities: { history: source.history !== false, forks: false, children: false, files: false },
|
|
3830
|
+
async detect() {
|
|
3831
|
+
return (await source.paths()).length > 0;
|
|
3832
|
+
},
|
|
3833
|
+
async discover() {
|
|
3834
|
+
const sessions = /* @__PURE__ */ new Map(), errors = [], blocked = [];
|
|
3835
|
+
let unavailable = false;
|
|
3836
|
+
for (const path of await source.paths()) {
|
|
3837
|
+
try {
|
|
3838
|
+
const snapshot2 = sqliteRevision(path), rev = digest([source.version || 2, source.id, snapshot2]);
|
|
3839
|
+
let cached2 = metadata3.get(path);
|
|
3840
|
+
if (!cached2 || cached2.revision !== rev) {
|
|
3841
|
+
cached2 = withSqliteSnapshot(path, (db2) => {
|
|
3842
|
+
const table = typeof source.table === "string" ? source.table : source.table(db2);
|
|
3843
|
+
const values2 = rows(db2, table, source.fields, void 0, source.key, 2e4), found = [];
|
|
3844
|
+
const blocked2 = [], errors2 = [];
|
|
3845
|
+
let failed = 0;
|
|
3846
|
+
for (const row of values2) {
|
|
3847
|
+
try {
|
|
3848
|
+
const h3 = parseHistory(source, db2, row, path);
|
|
3849
|
+
if (!h3) continue;
|
|
3850
|
+
if (source.history !== false && !h3.messages.length) {
|
|
3851
|
+
blocked2.push(identity(source.id, String(row[source.key])));
|
|
3852
|
+
continue;
|
|
3853
|
+
}
|
|
3854
|
+
if (!h3.nativeID || h3.nativeID.length > 512) throw new Error("Missing native session identity.");
|
|
3855
|
+
const created = time(h3.session?.created) || h3.messages.map((m) => time(m.time)).find(Boolean);
|
|
3856
|
+
if (!created) throw new Error("Session has no recorded creation or message date.");
|
|
3857
|
+
const session = { ...blankSession(source.id, h3.nativeID), ...h3.session, created };
|
|
3858
|
+
session.id = identity(source.id, h3.nativeID);
|
|
3859
|
+
session.nativeID = h3.nativeID;
|
|
3860
|
+
session.source = source.id;
|
|
3861
|
+
session.directory = text(session.directory);
|
|
3862
|
+
session.projectID = project(source.id, session.directory).id;
|
|
3863
|
+
session.agent ||= source.name;
|
|
3864
|
+
session.updated ||= created;
|
|
3865
|
+
session.parentID = h3.parent ? identity(source.id, h3.parent) : void 0;
|
|
3866
|
+
session.forkID = h3.fork ? identity(source.id, h3.fork) : void 0;
|
|
3867
|
+
if (!session.title || session.title === "Untitled session") session.title = h3.messages.flatMap((m) => m.role === "user" ? m.fragments.filter((f) => f.kind === "You").map((f) => f.text) : []).find(Boolean)?.replace(/\s+/g, " ").slice(0, 180) || `${source.name} session`;
|
|
3868
|
+
found.push({ session, revision: rev, locator: { path, snapshot: snapshot2, table, key: String(row[source.key]) } });
|
|
3869
|
+
} catch {
|
|
3870
|
+
blocked2.push(identity(source.id, String(row[source.key])));
|
|
3871
|
+
failed++;
|
|
3872
|
+
}
|
|
3873
|
+
}
|
|
3874
|
+
if (failed) errors2.push(`${source.name}: Skipped ${failed} unreadable, undated, unsupported, or oversized ${failed === 1 ? "session" : "sessions"}.`);
|
|
3875
|
+
return { revision: rev, candidates: found, blocked: blocked2, errors: errors2 };
|
|
3876
|
+
}, snapshot2);
|
|
3877
|
+
metadata3.set(path, cached2);
|
|
3878
|
+
}
|
|
3879
|
+
errors.push(...cached2.errors);
|
|
3880
|
+
blocked.push(...cached2.blocked);
|
|
3881
|
+
for (const c of cached2.candidates) {
|
|
3882
|
+
const old = sessions.get(c.session.id);
|
|
3883
|
+
if (!old || c.session.updated > old.session.updated) sessions.set(c.session.id, c);
|
|
3884
|
+
}
|
|
3885
|
+
} catch (error) {
|
|
3886
|
+
unavailable = true;
|
|
3887
|
+
const detail = error instanceof SqliteSnapshotFileError || error instanceof SqliteSnapshotChangedError ? error.message : "Could not read a history database.";
|
|
3888
|
+
errors.push(`${source.name}: ${detail}`);
|
|
3889
|
+
}
|
|
3890
|
+
}
|
|
3891
|
+
const values = [...sessions.values()];
|
|
3892
|
+
return { sessions: values, projects: [...new Map(values.map((c) => {
|
|
3893
|
+
const p = project(source.id, c.session.directory);
|
|
3894
|
+
return [p.id, p];
|
|
3895
|
+
})).values()], warnings: [], errors, blocked, unavailable };
|
|
3896
|
+
},
|
|
3897
|
+
async read(candidate, cursor) {
|
|
3898
|
+
if (cursor) throw new Error("Invalid SQLite history cursor.");
|
|
3899
|
+
const { path, snapshot: snapshot2, key } = candidate.locator;
|
|
3900
|
+
return withSqliteSnapshot(path, (db2) => {
|
|
3901
|
+
const table = typeof source.table === "string" ? source.table : source.table(db2);
|
|
3902
|
+
const row = rows(db2, table, source.fields, [source.key, key], void 0, 1)[0];
|
|
3903
|
+
if (!row) throw new Error("Session metadata is unavailable.");
|
|
3904
|
+
const history = parseHistory(source, db2, row, path);
|
|
3905
|
+
if (!history || history.nativeID !== candidate.session.nativeID) throw new Error("Session identity changed.");
|
|
3906
|
+
if (source.history !== false && !history.messages.length) throw new Error("No readable conversation.");
|
|
3907
|
+
return { messages: history.messages, partial: Boolean(history.partial || history.messages.some((m) => m.partial)), note: history.note };
|
|
3908
|
+
}, snapshot2);
|
|
3909
|
+
}
|
|
3910
|
+
};
|
|
3911
|
+
}
|
|
3912
|
+
async function existingDatabases(paths2) {
|
|
3913
|
+
const found = [];
|
|
3914
|
+
for (const path of new Set(paths2)) {
|
|
3915
|
+
try {
|
|
3916
|
+
if ((await lstat2(path)).isFile()) found.push(path);
|
|
3917
|
+
} catch (e10) {
|
|
3918
|
+
if (e10.code !== "ENOENT") throw e10;
|
|
3919
|
+
}
|
|
3920
|
+
}
|
|
3921
|
+
return found;
|
|
3922
|
+
}
|
|
3923
|
+
function combineAdapters(parts) {
|
|
3924
|
+
const first = parts[0];
|
|
3925
|
+
return {
|
|
3926
|
+
...first,
|
|
3927
|
+
async detect() {
|
|
3928
|
+
for (const p of parts) if (await p.detect().catch(() => false)) return true;
|
|
3929
|
+
return false;
|
|
3930
|
+
},
|
|
3931
|
+
async discover() {
|
|
3932
|
+
const sessions = /* @__PURE__ */ new Map(), projects = /* @__PURE__ */ new Map(), warnings = [], errors = [], blocked = /* @__PURE__ */ new Set();
|
|
3933
|
+
for (const [i, part] of parts.entries()) {
|
|
3934
|
+
let result;
|
|
3935
|
+
try {
|
|
3936
|
+
if (!await part.detect()) continue;
|
|
3937
|
+
result = await part.discover();
|
|
3938
|
+
} catch {
|
|
3939
|
+
errors.push(`${part.name}: Could not read a history source.`);
|
|
3940
|
+
break;
|
|
3941
|
+
}
|
|
3942
|
+
warnings.push(...result.warnings);
|
|
3943
|
+
if (result.errors?.length) errors.push(...result.errors);
|
|
3944
|
+
else if (result.unavailable) errors.push(`${part.name}: History unavailable.`);
|
|
3945
|
+
for (const id2 of result.blocked || []) blocked.add(id2);
|
|
3946
|
+
for (const p of result.projects) projects.set(p.id, p);
|
|
3947
|
+
for (const c of result.sessions) if (!blocked.has(c.session.id) && !sessions.has(c.session.id)) sessions.set(c.session.id, { ...c, revision: digest([i, c.revision]), locator: { ...c.locator, representation: String(i), originalRevision: c.revision } });
|
|
3948
|
+
if (result.unavailable) break;
|
|
3949
|
+
}
|
|
3950
|
+
return { sessions: [...sessions.values()], projects: [...projects.values()], warnings, errors };
|
|
3951
|
+
},
|
|
3952
|
+
async read(candidate, cursor) {
|
|
3953
|
+
const index = Number(candidate.locator.representation);
|
|
3954
|
+
if (!Number.isInteger(index) || !parts[index]) throw new Error("Invalid history representation.");
|
|
3955
|
+
return parts[index].read({ ...candidate, revision: candidate.locator.originalRevision }, cursor);
|
|
3956
|
+
}
|
|
3957
|
+
};
|
|
3958
|
+
}
|
|
3959
|
+
|
|
3960
|
+
// server/adapters/opencode-v1.ts
|
|
3961
|
+
function openCodeV1Message(body2, parts) {
|
|
3962
|
+
const content = [], files = [];
|
|
3963
|
+
let start, end;
|
|
3964
|
+
for (const part of parts) {
|
|
3965
|
+
if (part.type === "step-start") {
|
|
3966
|
+
start = text(part.snapshot) || void 0;
|
|
3967
|
+
continue;
|
|
3968
|
+
}
|
|
3969
|
+
if (part.type === "step-finish") {
|
|
3970
|
+
end = text(part.snapshot) || void 0;
|
|
3971
|
+
continue;
|
|
3972
|
+
}
|
|
3973
|
+
if (part.type === "patch") {
|
|
3974
|
+
files.push(...Array.isArray(part.files) ? part.files.filter((value) => typeof value === "string") : []);
|
|
3975
|
+
continue;
|
|
3976
|
+
}
|
|
3977
|
+
if (part.type === "snapshot") continue;
|
|
3978
|
+
const timing = object3(part.time), state2 = object3(part.state), toolTime = object3(state2.time);
|
|
3979
|
+
content.push(part.type === "tool" ? {
|
|
3980
|
+
...part,
|
|
3981
|
+
name: part.tool,
|
|
3982
|
+
time: { created: toolTime.start, completed: toolTime.end },
|
|
3983
|
+
state: {
|
|
3984
|
+
...state2,
|
|
3985
|
+
content: typeof state2.output === "string" ? [{ type: "text", text: state2.output }] : [],
|
|
3986
|
+
metadata: { ...object3(state2.metadata), cwd: state2.metadata?.cwd || body2.path?.cwd }
|
|
3987
|
+
}
|
|
3988
|
+
} : { ...part, time: { created: timing.start, completed: timing.end } });
|
|
3989
|
+
}
|
|
3990
|
+
const prompt = parts.filter((part) => part.type === "text").map((part) => text(part.text)).join("\n");
|
|
3991
|
+
const type = body2.role === "user" && !prompt && parts.some((part) => part.type === "compaction") ? "compaction" : body2.role;
|
|
3992
|
+
return {
|
|
3993
|
+
...body2,
|
|
3994
|
+
type,
|
|
3995
|
+
cwd: body2.path?.cwd,
|
|
3996
|
+
model: body2.role === "assistant" ? { id: body2.modelID, providerID: body2.providerID } : { ...object3(body2.model), id: body2.model?.modelID },
|
|
3997
|
+
text: body2.role === "user" ? prompt : void 0,
|
|
3998
|
+
files: parts.filter((part) => part.type === "file").map((part) => ({ name: part.filename, uri: part.url })),
|
|
3999
|
+
content: body2.role === "user" ? [] : content,
|
|
4000
|
+
snapshot: files.length || start || end ? { files, start, end } : void 0
|
|
4001
|
+
};
|
|
4002
|
+
}
|
|
4003
|
+
|
|
3430
4004
|
// server/adapters/opencode.ts
|
|
3431
4005
|
function openCodeMessage(raw, sessionID) {
|
|
3432
4006
|
const content = extractContent([raw]), detail = summarizeMessages(sessionID, [raw], null);
|
|
@@ -3446,46 +4020,231 @@ function openCodeMessage(raw, sessionID) {
|
|
|
3446
4020
|
message2.events = opencodeEvents(raw, message2);
|
|
3447
4021
|
return message2;
|
|
3448
4022
|
}
|
|
4023
|
+
var PAGE = 60;
|
|
4024
|
+
var MAX_JSON = 4e6;
|
|
4025
|
+
var sessionFields = [
|
|
4026
|
+
"id",
|
|
4027
|
+
"project_id",
|
|
4028
|
+
"parent_id",
|
|
4029
|
+
"fork_session_id",
|
|
4030
|
+
"directory",
|
|
4031
|
+
"title",
|
|
4032
|
+
"time_created",
|
|
4033
|
+
"time_updated",
|
|
4034
|
+
"time_archived",
|
|
4035
|
+
"model",
|
|
4036
|
+
"agent",
|
|
4037
|
+
"cost",
|
|
4038
|
+
"tokens_input",
|
|
4039
|
+
"tokens_output",
|
|
4040
|
+
"tokens_reasoning",
|
|
4041
|
+
"tokens_cache_read",
|
|
4042
|
+
"tokens_cache_write",
|
|
4043
|
+
"idle_outcome"
|
|
4044
|
+
];
|
|
4045
|
+
async function openCodeDatabases() {
|
|
4046
|
+
const override = sourcePath("opencode") || process.env.SESSIONGRAPH_OPENCODE_HISTORY_DIR || process.env.OPENCODE_DB;
|
|
4047
|
+
const root2 = override || dataPath("opencode");
|
|
4048
|
+
try {
|
|
4049
|
+
const info = await lstat3(root2);
|
|
4050
|
+
if (info.isFile()) return [root2];
|
|
4051
|
+
if (!info.isDirectory()) return [];
|
|
4052
|
+
const files = (await readdir2(root2)).filter((name) => /^opencode(?:[-.][\w.-]+)?\.db$/.test(name)).sort((a, b) => a === "opencode.db" ? -1 : b === "opencode.db" ? 1 : a.localeCompare(b));
|
|
4053
|
+
if (files.length > 20) throw new Error("Too many OpenCode databases. Choose a database file with a source path override.");
|
|
4054
|
+
const paths2 = [];
|
|
4055
|
+
for (const file of files) {
|
|
4056
|
+
const path = join6(root2, file);
|
|
4057
|
+
if ((await lstat3(path)).isFile()) paths2.push(path);
|
|
4058
|
+
}
|
|
4059
|
+
return paths2;
|
|
4060
|
+
} catch (error) {
|
|
4061
|
+
if (error.code === "ENOENT") return [];
|
|
4062
|
+
throw error;
|
|
4063
|
+
}
|
|
4064
|
+
}
|
|
4065
|
+
function schemas(db2) {
|
|
4066
|
+
const result = [];
|
|
4067
|
+
for (const version of ["2", "1"]) {
|
|
4068
|
+
const session = version === "2" ? "session_v2" : "session", message2 = version === "2" ? "session_message" : "message", part = version === "2" ? "session_part" : "part";
|
|
4069
|
+
if (!hasTable(db2, session)) continue;
|
|
4070
|
+
for (const [table, required] of [[session, ["id", "time_created", "time_updated"]], [message2, ["id", "session_id", "data", "time_created", ...version === "2" ? ["type", "seq"] : []]]]) {
|
|
4071
|
+
const names = columns(db2, table);
|
|
4072
|
+
if (required.some((name) => !names.has(name))) throw new Error("Unsupported OpenCode database schema.");
|
|
4073
|
+
}
|
|
4074
|
+
if (hasTable(db2, part)) {
|
|
4075
|
+
const names = columns(db2, part);
|
|
4076
|
+
if (["message_id", "data", version === "2" ? "ordinal" : "id"].some((name) => !names.has(name))) throw new Error("Unsupported OpenCode part schema.");
|
|
4077
|
+
} else if (version === "1") throw new Error("OpenCode V1 parts are unavailable.");
|
|
4078
|
+
result.push({ version, session, message: message2, part: hasTable(db2, part) ? part : void 0 });
|
|
4079
|
+
}
|
|
4080
|
+
if (!result.length) throw new Error("Unsupported OpenCode database schema.");
|
|
4081
|
+
return result;
|
|
4082
|
+
}
|
|
4083
|
+
function historyRevisions(db2, schema) {
|
|
4084
|
+
const result = /* @__PURE__ */ new Map();
|
|
4085
|
+
for (const table of [schema.message, schema.part].filter((value) => Boolean(value))) {
|
|
4086
|
+
const names = columns(db2, table);
|
|
4087
|
+
if (!names.has("session_id")) continue;
|
|
4088
|
+
const updated = names.has("time_updated") ? "MAX(time_updated)" : "NULL";
|
|
4089
|
+
for (const row of db2.prepare(`SELECT session_id, COUNT(*) AS count, ${updated} AS updated FROM "${table}" GROUP BY session_id`).iterate()) {
|
|
4090
|
+
const id2 = text(row.session_id);
|
|
4091
|
+
result.set(id2, [...result.get(id2) || [], row.count, row.updated]);
|
|
4092
|
+
}
|
|
4093
|
+
}
|
|
4094
|
+
return result;
|
|
4095
|
+
}
|
|
4096
|
+
function discoverDatabase(db2, path, snapshot2) {
|
|
4097
|
+
const sessions = /* @__PURE__ */ new Map(), projects = /* @__PURE__ */ new Map(), errors = [];
|
|
4098
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4099
|
+
if (hasTable(db2, "project")) {
|
|
4100
|
+
for (const row of rows(db2, "project", ["id", "name", "worktree", "sandboxes"], void 0, "id", 2e4)) {
|
|
4101
|
+
try {
|
|
4102
|
+
const p = project("opencode", text(row.worktree)), sandboxes = optionalJSON(row.sandboxes);
|
|
4103
|
+
p.id = identity("opencode", text(row.id));
|
|
4104
|
+
p.name = text(row.name) || p.name;
|
|
4105
|
+
p.worktrees = Array.isArray(sandboxes) ? sandboxes.filter((value) => typeof value === "string") : [];
|
|
4106
|
+
projects.set(p.id, p);
|
|
4107
|
+
} catch {
|
|
4108
|
+
errors.push("OpenCode: Skipped unreadable project metadata.");
|
|
4109
|
+
}
|
|
4110
|
+
}
|
|
4111
|
+
}
|
|
4112
|
+
for (const schema of schemas(db2)) {
|
|
4113
|
+
const revisions = historyRevisions(db2, schema);
|
|
4114
|
+
for (const row of rows(db2, schema.session, sessionFields, void 0, "id", 2e4)) {
|
|
4115
|
+
const nativeID = text(row.id), id2 = identity("opencode", nativeID);
|
|
4116
|
+
if (seen.has(id2)) continue;
|
|
4117
|
+
seen.add(id2);
|
|
4118
|
+
if (!nativeID || nativeID.length > 512 || !time(row.time_created)) {
|
|
4119
|
+
errors.push("OpenCode: Skipped invalid session metadata.");
|
|
4120
|
+
continue;
|
|
4121
|
+
}
|
|
4122
|
+
const session = {
|
|
4123
|
+
...blankSession("opencode", nativeID, text(row.directory)),
|
|
4124
|
+
title: text(row.title) || "Untitled session",
|
|
4125
|
+
created: time(row.time_created),
|
|
4126
|
+
updated: time(row.time_updated) || time(row.time_created),
|
|
4127
|
+
archived: Boolean(row.time_archived),
|
|
4128
|
+
parentID: text(row.parent_id) ? identity("opencode", text(row.parent_id)) : void 0,
|
|
4129
|
+
forkID: text(row.fork_session_id) ? identity("opencode", text(row.fork_session_id)) : void 0
|
|
4130
|
+
};
|
|
4131
|
+
try {
|
|
4132
|
+
const model = object3(optionalJSON(row.model));
|
|
4133
|
+
session.model = text(model.id) || "Unknown model";
|
|
4134
|
+
session.provider = text(model.providerID);
|
|
4135
|
+
session.agent = text(row.agent) || "build";
|
|
4136
|
+
session.outcome = text(row.idle_outcome) || void 0;
|
|
4137
|
+
if (schema.version === "1") {
|
|
4138
|
+
const valid = `length(CAST(data AS BLOB))<=${MAX_JSON} AND json_valid(data)`;
|
|
4139
|
+
const latest = db2.prepare(`SELECT
|
|
4140
|
+
CASE WHEN ${valid} THEN substr(json_extract(data,'$.modelID'),1,256) END AS model,
|
|
4141
|
+
CASE WHEN ${valid} THEN substr(json_extract(data,'$.providerID'),1,256) END AS provider,
|
|
4142
|
+
CASE WHEN ${valid} THEN substr(json_extract(data,'$.model.modelID'),1,256) END AS user_model,
|
|
4143
|
+
CASE WHEN ${valid} THEN substr(json_extract(data,'$.model.providerID'),1,256) END AS user_provider,
|
|
4144
|
+
CASE WHEN ${valid} THEN substr(json_extract(data,'$.agent'),1,256) END AS agent
|
|
4145
|
+
FROM message WHERE session_id=? ORDER BY time_created DESC, id DESC LIMIT 1`).get(nativeID);
|
|
4146
|
+
session.model = text(latest?.model || latest?.user_model) || session.model;
|
|
4147
|
+
session.provider = text(latest?.provider || latest?.user_provider);
|
|
4148
|
+
session.agent = text(latest?.agent) || session.agent;
|
|
4149
|
+
}
|
|
4150
|
+
if (schema.version === "2") {
|
|
4151
|
+
session.usage = sessionUsage(openCodeUsage({
|
|
4152
|
+
input: row.tokens_input,
|
|
4153
|
+
output: row.tokens_output,
|
|
4154
|
+
reasoning: row.tokens_reasoning,
|
|
4155
|
+
cache: { read: row.tokens_cache_read, write: row.tokens_cache_write }
|
|
4156
|
+
}, row.cost));
|
|
4157
|
+
session.tokens = session.usage?.total ?? null;
|
|
4158
|
+
session.cost = session.usage?.cost ?? null;
|
|
4159
|
+
}
|
|
4160
|
+
const nativeProject = identity("opencode", text(row.project_id));
|
|
4161
|
+
const p = projects.get(nativeProject) || project("opencode", session.directory);
|
|
4162
|
+
session.projectID = p.id;
|
|
4163
|
+
projects.set(p.id, p);
|
|
4164
|
+
sessions.set(id2, {
|
|
4165
|
+
session,
|
|
4166
|
+
revision: digest([6, schema.version, row, revisions.get(nativeID)]),
|
|
4167
|
+
locator: { path, snapshot: snapshot2, version: schema.version }
|
|
4168
|
+
});
|
|
4169
|
+
} catch {
|
|
4170
|
+
errors.push("OpenCode: Skipped unreadable session metadata.");
|
|
4171
|
+
}
|
|
4172
|
+
}
|
|
4173
|
+
}
|
|
4174
|
+
return { sessions: [...sessions.values()], projects: [...projects.values()], warnings: [], errors };
|
|
4175
|
+
}
|
|
4176
|
+
function payloadRows(db2, query, values, budget2) {
|
|
4177
|
+
const result = [];
|
|
4178
|
+
for (const row of db2.prepare(query).iterate(...values)) {
|
|
4179
|
+
if (typeof row.data !== "string") throw new Error("OpenCode history contains a missing or oversized JSON field (4 MB limit).");
|
|
4180
|
+
budget2.bytes += Buffer.byteLength(row.data);
|
|
4181
|
+
budget2.records++;
|
|
4182
|
+
if (budget2.bytes > 32e6 || budget2.records > 5e4) throw new Error("OpenCode history page exceeds the 32 MB / 50,000-record limit.");
|
|
4183
|
+
result.push(row);
|
|
4184
|
+
}
|
|
4185
|
+
return result;
|
|
4186
|
+
}
|
|
3449
4187
|
var opencodeAdapter = {
|
|
3450
4188
|
id: "opencode",
|
|
3451
4189
|
name: "OpenCode",
|
|
3452
|
-
description: "Local
|
|
4190
|
+
description: "Local SQLite history \xB7 V1 and V2 \xB7 no running service needed",
|
|
3453
4191
|
capabilities: { history: true, forks: true, children: true, files: true },
|
|
3454
4192
|
async detect() {
|
|
3455
|
-
|
|
3456
|
-
await api("/api/info", AbortSignal.timeout(3e3));
|
|
3457
|
-
return true;
|
|
3458
|
-
} catch {
|
|
3459
|
-
return false;
|
|
3460
|
-
}
|
|
4193
|
+
return (await openCodeDatabases()).length > 0;
|
|
3461
4194
|
},
|
|
3462
4195
|
async discover() {
|
|
3463
|
-
const
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
4196
|
+
const sessions = /* @__PURE__ */ new Map(), projects = /* @__PURE__ */ new Map(), errors = [];
|
|
4197
|
+
for (const path of await openCodeDatabases()) {
|
|
4198
|
+
try {
|
|
4199
|
+
const snapshot2 = sqliteRevision(path);
|
|
4200
|
+
const found = withSqliteSnapshot(path, (db2) => discoverDatabase(db2, path, snapshot2), snapshot2);
|
|
4201
|
+
for (const candidate of found.sessions) {
|
|
4202
|
+
const previous = sessions.get(candidate.session.id);
|
|
4203
|
+
if (!previous || candidate.locator.version > previous.locator.version || candidate.locator.version === previous.locator.version && candidate.session.updated > previous.session.updated) sessions.set(candidate.session.id, candidate);
|
|
4204
|
+
}
|
|
4205
|
+
for (const p of found.projects) projects.set(p.id, p);
|
|
4206
|
+
errors.push(...found.errors);
|
|
4207
|
+
} catch (error) {
|
|
4208
|
+
errors.push(`OpenCode: ${error instanceof Error ? error.message : "Could not read a history database."}`);
|
|
4209
|
+
}
|
|
4210
|
+
}
|
|
4211
|
+
return { sessions: [...sessions.values()], projects: [...projects.values()], warnings: [], errors: [...new Set(errors)] };
|
|
3477
4212
|
},
|
|
3478
4213
|
async read(candidate, cursor) {
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
const
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
4214
|
+
if (cursor && !/^[1-9]\d{0,5}$/.test(cursor)) throw new Error("Invalid OpenCode history cursor.");
|
|
4215
|
+
const offset = Number(cursor || 0);
|
|
4216
|
+
return withSqliteSnapshot(candidate.locator.path, (db2) => {
|
|
4217
|
+
const schema = schemas(db2).find((value) => value.version === candidate.locator.version);
|
|
4218
|
+
if (!schema) throw new Error("OpenCode history schema changed.");
|
|
4219
|
+
const budget2 = { bytes: 0, records: 0 };
|
|
4220
|
+
const data = `CASE WHEN length(CAST(data AS BLOB))<=${MAX_JSON} THEN data END AS data`;
|
|
4221
|
+
const page = payloadRows(
|
|
4222
|
+
db2,
|
|
4223
|
+
`SELECT id, time_created, ${schema.version === "2" ? "type" : "NULL AS type"}, ${data}
|
|
4224
|
+
FROM "${schema.message}" WHERE session_id=? ORDER BY ${schema.version === "2" ? "seq DESC" : "time_created DESC, id DESC"} LIMIT ${PAGE + 1} OFFSET ?`,
|
|
4225
|
+
[candidate.session.nativeID, offset],
|
|
4226
|
+
budget2
|
|
4227
|
+
);
|
|
4228
|
+
const messages = page.slice(0, PAGE).map((row) => {
|
|
4229
|
+
const body2 = object3(sqliteJSON(row.data));
|
|
4230
|
+
if (schema.version === "1" && !["user", "assistant"].includes(body2.role)) throw new Error("Unsupported OpenCode V1 message.");
|
|
4231
|
+
if (schema.version === "2" && !text(row.type)) throw new Error("Missing OpenCode message type.");
|
|
4232
|
+
const parts = schema.part ? payloadRows(
|
|
4233
|
+
db2,
|
|
4234
|
+
`SELECT ${schema.version === "2" ? "ordinal" : "id"}, ${data} FROM "${schema.part}" WHERE message_id=? ORDER BY ${schema.version === "2" ? "ordinal" : "id"}`,
|
|
4235
|
+
[text(row.id)],
|
|
4236
|
+
budget2
|
|
4237
|
+
).map((part) => ({ ...object3(sqliteJSON(part.data)), ...schema.version === "1" ? { id: part.id } : {} })) : [];
|
|
4238
|
+
const raw = schema.version === "1" ? openCodeV1Message(body2, parts) : { ...body2, type: row.type, content: [...parts, ...Array.isArray(body2.content) ? body2.content : []] };
|
|
4239
|
+
const message2 = openCodeMessage({ ...raw, id: text(row.id), time: { ...object3(raw.time), created: time(raw.time?.created) || time(row.time_created) } }, candidate.session.id);
|
|
4240
|
+
if (schema.version === "1" && candidate.session.model === "Unknown model" && message2.metadata?.model) {
|
|
4241
|
+
candidate.session.model = message2.metadata?.model || candidate.session.model;
|
|
4242
|
+
candidate.session.provider = message2.metadata?.provider || candidate.session.provider;
|
|
4243
|
+
}
|
|
4244
|
+
return message2;
|
|
4245
|
+
});
|
|
4246
|
+
return { messages, cursor: page.length > PAGE ? String(offset + PAGE) : void 0 };
|
|
4247
|
+
}, candidate.locator.snapshot, true);
|
|
3489
4248
|
}
|
|
3490
4249
|
};
|
|
3491
4250
|
|
|
@@ -3531,15 +4290,6 @@ import { basename as o0, dirname as s0, isAbsolute as Fst, join as WTe, relative
|
|
|
3531
4290
|
import { createHash as YRe } from "crypto";
|
|
3532
4291
|
import { constants as PU } from "fs";
|
|
3533
4292
|
import { isAbsolute as KTe, sep as r0 } from "path";
|
|
3534
|
-
import { readdir as PR, stat as TOe } from "fs/promises";
|
|
3535
|
-
import { basename as sOe, dirname as iOe, join as aOe } from "path";
|
|
3536
|
-
import { basename as OOe, join as Sd } from "path";
|
|
3537
|
-
import { readFile as dOe } from "fs/promises";
|
|
3538
|
-
import { dirname as pOe, join as fOe } from "path";
|
|
3539
|
-
import { basename as E0, dirname as b0 } from "path";
|
|
3540
|
-
import { constants as Xm } from "fs";
|
|
3541
|
-
import { lstat as _Oe, open as yOe } from "fs/promises";
|
|
3542
|
-
import { dirname as SOe, join as EOe } from "path";
|
|
3543
4293
|
import { AsyncLocalStorage as dwe } from "async_hooks";
|
|
3544
4294
|
import { closeSync as Oat, constants as Kt, fchmodSync as wat, fstatSync as xat, ftruncateSync as vat, lstatSync as kat, openSync as Pat, readFileSync as Iat, renameSync as Dat, unlinkSync as Lat, writeFileSync as Mat } from "fs";
|
|
3545
4295
|
import { readdir as Iwe, readFile as J0 } from "fs/promises";
|
|
@@ -11783,9 +12533,6 @@ function R5(e10) {
|
|
|
11783
12533
|
if (e10?.anchors !== void 0 && e10.anchors.length > 0) return e10.anchors;
|
|
11784
12534
|
return e10?.anchor !== void 0 ? [e10.anchor] : void 0;
|
|
11785
12535
|
}
|
|
11786
|
-
async function xP(e10) {
|
|
11787
|
-
return Ua(e10) || du(e10) || vo(e10) || Ss(e10) || await gu(TE, e10) !== void 0;
|
|
11788
|
-
}
|
|
11789
12536
|
async function RE(e10, t = TE) {
|
|
11790
12537
|
return Ua(e10) || du(e10) || vo(e10) || Ss(e10) || await gu(t, e10, { surfaceNetworkRaw: true, unreadableAncestry: "unverified" }) !== void 0;
|
|
11791
12538
|
}
|
|
@@ -13757,49 +14504,6 @@ function ab(e10) {
|
|
|
13757
14504
|
return t;
|
|
13758
14505
|
}
|
|
13759
14506
|
var met = ib("claude-cli");
|
|
13760
|
-
function See(e10) {
|
|
13761
|
-
return `</pasted_content id="${e10}">
|
|
13762
|
-
`;
|
|
13763
|
-
}
|
|
13764
|
-
function Eee(e10) {
|
|
13765
|
-
if (e10.length !== 4) return false;
|
|
13766
|
-
for (let t = 0; t < e10.length; t++) {
|
|
13767
|
-
let n = e10.charCodeAt(t);
|
|
13768
|
-
if (!(n >= 48 && n <= 57 || n >= 97 && n <= 102)) return false;
|
|
13769
|
-
}
|
|
13770
|
-
return true;
|
|
13771
|
-
}
|
|
13772
|
-
function bee(e10) {
|
|
13773
|
-
let t = [], n = 0, r = 0;
|
|
13774
|
-
for (; ; ) {
|
|
13775
|
-
let o = e10.indexOf('<pasted_content id="', r);
|
|
13776
|
-
if (o === -1) break;
|
|
13777
|
-
let s = o + 20, i = e10.slice(s, s + 4);
|
|
13778
|
-
if (!Eee(i) || !e10.startsWith(`">
|
|
13779
|
-
`, s + 4)) {
|
|
13780
|
-
r = s;
|
|
13781
|
-
continue;
|
|
13782
|
-
}
|
|
13783
|
-
let a = s + 4 + 3, c = See(i).slice(0, -1), d = e10.indexOf(`
|
|
13784
|
-
${c}`, a - 1) + 1;
|
|
13785
|
-
if (d === 0) break;
|
|
13786
|
-
let p = o;
|
|
13787
|
-
for (let f = 0; f < 2 && p > n && e10[p - 1] === `
|
|
13788
|
-
`; f++) p--;
|
|
13789
|
-
if (p > n) t.push({ kind: "text", text: e10.slice(n, p) });
|
|
13790
|
-
n = d + c.length;
|
|
13791
|
-
for (let f = 0; f < 2 && e10[n] === `
|
|
13792
|
-
`; f++) n++;
|
|
13793
|
-
t.push({ kind: "block", id: i, body: e10.slice(a, d - 1), raw: e10.slice(p, n) }), r = n;
|
|
13794
|
-
}
|
|
13795
|
-
if (n < e10.length) t.push({ kind: "text", text: e10.slice(n) });
|
|
13796
|
-
return t;
|
|
13797
|
-
}
|
|
13798
|
-
function lb(e10) {
|
|
13799
|
-
let t = bee(e10);
|
|
13800
|
-
if (t.length === 1 && t[0].kind === "text") return e10;
|
|
13801
|
-
return t.map((n) => n.kind === "text" ? n.text : n.body).join("");
|
|
13802
|
-
}
|
|
13803
14507
|
var Cee = "<system-reminder>";
|
|
13804
14508
|
var yet = Cee.slice(0, -1);
|
|
13805
14509
|
function Aee() {
|
|
@@ -15447,7 +16151,6 @@ function vD(e10, t, n) {
|
|
|
15447
16151
|
let r = yb(e10) ?? (t === "task-notification" ? { kind: "task-notification" } : void 0), o = ku(n);
|
|
15448
16152
|
return o !== void 0 && r?.kind === "task-notification" && r.runId === void 0 ? { ...r, runId: o } : r;
|
|
15449
16153
|
}
|
|
15450
|
-
var kD = 1e4;
|
|
15451
16154
|
async function vr(e10, t, n) {
|
|
15452
16155
|
let r = Math.max(1, Math.floor(n?.maxPages ?? 1e4)), o;
|
|
15453
16156
|
for (let s = 0; s < r; s++) {
|
|
@@ -15462,37 +16165,6 @@ async function vr(e10, t, n) {
|
|
|
15462
16165
|
}
|
|
15463
16166
|
return { status: "capped" };
|
|
15464
16167
|
}
|
|
15465
|
-
var Sbe = /^(?:\s*<[a-z][\w-]*[\s>]|\[Request interrupted by user[^\]]*\])/;
|
|
15466
|
-
var Ebe = /<command-name>(.*?)<\/command-name>/;
|
|
15467
|
-
function zi(e10, t) {
|
|
15468
|
-
if (e10.type !== "user") return;
|
|
15469
|
-
if (e10.isMeta === true || e10.isCompactSummary === true) return;
|
|
15470
|
-
let n = e10.message;
|
|
15471
|
-
if (!n) return;
|
|
15472
|
-
let r = n.content, o = [];
|
|
15473
|
-
if (typeof r === "string") o.push(r);
|
|
15474
|
-
else if (Array.isArray(r)) for (let s of r) {
|
|
15475
|
-
if (!s || typeof s !== "object") continue;
|
|
15476
|
-
if (s.type === "tool_result") return;
|
|
15477
|
-
if (s.type === "text" && typeof s.text === "string") o.push(s.text);
|
|
15478
|
-
}
|
|
15479
|
-
for (let s of o) {
|
|
15480
|
-
let i = lb(s).replaceAll(`
|
|
15481
|
-
`, " ").trim();
|
|
15482
|
-
if (!i) continue;
|
|
15483
|
-
let a = Ebe.exec(i);
|
|
15484
|
-
if (a) {
|
|
15485
|
-
if (!t.commandFallback) t.commandFallback = a[1];
|
|
15486
|
-
continue;
|
|
15487
|
-
}
|
|
15488
|
-
let l = /<bash-input>([\s\S]*?)<\/bash-input>/.exec(i);
|
|
15489
|
-
if (l) return `! ${l[1].trim()}`;
|
|
15490
|
-
if (Sbe.test(i)) continue;
|
|
15491
|
-
if (i.length > 200) i = Cs(i, 200).trim() + "\u2026";
|
|
15492
|
-
return i;
|
|
15493
|
-
}
|
|
15494
|
-
return;
|
|
15495
|
-
}
|
|
15496
16168
|
function PD(e10, t) {
|
|
15497
16169
|
if (process.platform !== "darwin" || Boolean(t.DEVELOPER_DIR)) return false;
|
|
15498
16170
|
try {
|
|
@@ -15582,68 +16254,11 @@ async function Do(e10) {
|
|
|
15582
16254
|
}
|
|
15583
16255
|
}
|
|
15584
16256
|
var En = 65536;
|
|
15585
|
-
var Gbe = /* @__PURE__ */ new Set(["sdk-cli", "sdk-ts", "sdk-py"]);
|
|
15586
|
-
function WD(e10, t) {
|
|
15587
|
-
let n = nl(e10, "entrypoint") ?? Xt(t, "entrypoint");
|
|
15588
|
-
if (n && Gbe.has(n)) return true;
|
|
15589
|
-
let r = e10.split(`
|
|
15590
|
-
`).find((s) => s.includes('"parentUuid":')) ?? e10, o = nl(r, "sessionKind");
|
|
15591
|
-
return o === "daemon" || o === "daemon-worker";
|
|
15592
|
-
}
|
|
15593
16257
|
var Wbe = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
15594
16258
|
function Ve(e10) {
|
|
15595
16259
|
if (typeof e10 !== "string") return null;
|
|
15596
16260
|
return Wbe.test(e10) ? e10 : null;
|
|
15597
16261
|
}
|
|
15598
|
-
function VD(e10) {
|
|
15599
|
-
if (!e10.includes("\\")) return e10;
|
|
15600
|
-
try {
|
|
15601
|
-
return JSON.parse(`"${e10}"`);
|
|
15602
|
-
} catch {
|
|
15603
|
-
return e10;
|
|
15604
|
-
}
|
|
15605
|
-
}
|
|
15606
|
-
function nl(e10, t) {
|
|
15607
|
-
let n = [`"${t}":"`, `"${t}": "`];
|
|
15608
|
-
for (let r of n) {
|
|
15609
|
-
let o = e10.indexOf(r);
|
|
15610
|
-
if (o < 0) continue;
|
|
15611
|
-
let s = o + r.length, i = s;
|
|
15612
|
-
while (i < e10.length) {
|
|
15613
|
-
if (e10[i] === "\\") {
|
|
15614
|
-
i += 2;
|
|
15615
|
-
continue;
|
|
15616
|
-
}
|
|
15617
|
-
if (e10[i] === '"') return VD(e10.slice(s, i));
|
|
15618
|
-
i++;
|
|
15619
|
-
}
|
|
15620
|
-
}
|
|
15621
|
-
return;
|
|
15622
|
-
}
|
|
15623
|
-
function Xt(e10, t) {
|
|
15624
|
-
let n = [`"${t}":"`, `"${t}": "`], r, o = -1;
|
|
15625
|
-
for (let s of n) {
|
|
15626
|
-
let i = 0;
|
|
15627
|
-
while (true) {
|
|
15628
|
-
let a = e10.indexOf(s, i);
|
|
15629
|
-
if (a < 0) break;
|
|
15630
|
-
let l = a + s.length, c = l;
|
|
15631
|
-
while (c < e10.length) {
|
|
15632
|
-
if (e10[c] === "\\") {
|
|
15633
|
-
c += 2;
|
|
15634
|
-
continue;
|
|
15635
|
-
}
|
|
15636
|
-
if (e10[c] === '"') {
|
|
15637
|
-
if (a > o) r = VD(e10.slice(l, c)), o = a;
|
|
15638
|
-
break;
|
|
15639
|
-
}
|
|
15640
|
-
c++;
|
|
15641
|
-
}
|
|
15642
|
-
i = c + 1;
|
|
15643
|
-
}
|
|
15644
|
-
}
|
|
15645
|
-
return r;
|
|
15646
|
-
}
|
|
15647
16262
|
function am(e10, t, n) {
|
|
15648
16263
|
return Vbe(e10, n, t);
|
|
15649
16264
|
}
|
|
@@ -15683,37 +16298,6 @@ function Sb(e10, t) {
|
|
|
15683
16298
|
function lm(e10, t) {
|
|
15684
16299
|
return e10?.realWorkspacePath === void 0 ? void 0 : { hoverRestOn: t, realPath: e10.realWorkspacePath };
|
|
15685
16300
|
}
|
|
15686
|
-
function cm(e10) {
|
|
15687
|
-
let t = 0, n = { commandFallback: "" };
|
|
15688
|
-
while (t < e10.length) {
|
|
15689
|
-
let r = e10.indexOf(`
|
|
15690
|
-
`, t), o = r >= 0 ? e10.slice(t, r) : e10.slice(t);
|
|
15691
|
-
if (t = r >= 0 ? r + 1 : e10.length, !o.includes('"type":"user"') && !o.includes('"type": "user"')) continue;
|
|
15692
|
-
if (o.includes('"tool_result"')) continue;
|
|
15693
|
-
if (o.includes('"isMeta":true') || o.includes('"isMeta": true')) continue;
|
|
15694
|
-
if (o.includes('"isCompactSummary":true') || o.includes('"isCompactSummary": true')) continue;
|
|
15695
|
-
try {
|
|
15696
|
-
let s = JSON.parse(o), i = zi(s, n);
|
|
15697
|
-
if (i !== void 0) return i;
|
|
15698
|
-
} catch {
|
|
15699
|
-
continue;
|
|
15700
|
-
}
|
|
15701
|
-
}
|
|
15702
|
-
return n.commandFallback;
|
|
15703
|
-
}
|
|
15704
|
-
function qD(e10) {
|
|
15705
|
-
let t = 0;
|
|
15706
|
-
while (t < e10.length) {
|
|
15707
|
-
let n = e10.indexOf(`
|
|
15708
|
-
`, t), r = n >= 0 ? e10.slice(t, n) : e10.slice(t);
|
|
15709
|
-
if (t = n >= 0 ? n + 1 : e10.length, !r.includes('"type":"user"') && !r.includes('"type": "user"')) continue;
|
|
15710
|
-
if (r.includes('"tool_result"')) continue;
|
|
15711
|
-
if (r.includes('"isMeta":true') || r.includes('"isMeta": true')) continue;
|
|
15712
|
-
if (r.includes('"type":"image"') || r.includes('"type": "image"')) return "Image";
|
|
15713
|
-
if (r.includes('"type":"document"') || r.includes('"type": "document"')) return "Document";
|
|
15714
|
-
}
|
|
15715
|
-
return "";
|
|
15716
|
-
}
|
|
15717
16301
|
var ND = process.platform === "win32" ? Pu.O_RDONLY : Pu.O_RDONLY | Pu.O_NOFOLLOW | Pu.O_NONBLOCK;
|
|
15718
16302
|
async function Zbe(e10) {
|
|
15719
16303
|
let { backend: t, key: n } = e10;
|
|
@@ -15803,43 +16387,6 @@ function Mu(e10) {
|
|
|
15803
16387
|
if (t.length <= Lo) return t;
|
|
15804
16388
|
return `${t.slice(0, Lo)}-${Jbe(e10)}`;
|
|
15805
16389
|
}
|
|
15806
|
-
function om(e10, t) {
|
|
15807
|
-
let n = e10.replaceAll("\\", "/");
|
|
15808
|
-
return t ? n.toLowerCase() : n;
|
|
15809
|
-
}
|
|
15810
|
-
function FD(e10, t, n) {
|
|
15811
|
-
let r = Ye(e10), o = Ye(t), s = (i) => n ? i.toLowerCase() : i;
|
|
15812
|
-
if (s(rl(r)) !== s(rl(o))) return false;
|
|
15813
|
-
return om(r, n) !== om(o, n);
|
|
15814
|
-
}
|
|
15815
|
-
async function XD(e10, t, n, r, o) {
|
|
15816
|
-
if (!FD(e10, t, n)) return false;
|
|
15817
|
-
if (uu(e10) || uu(t)) return false;
|
|
15818
|
-
if (await r(e10) || await r(t)) return false;
|
|
15819
|
-
let s;
|
|
15820
|
-
try {
|
|
15821
|
-
if (o !== void 0 && o.hoverRestOn) {
|
|
15822
|
-
let a = await o.realPath(e10);
|
|
15823
|
-
if (!a.ok || !a.value.found) return false;
|
|
15824
|
-
s = Ye(a.value.path);
|
|
15825
|
-
} else s = Ye(await GD(e10));
|
|
15826
|
-
} catch {
|
|
15827
|
-
return false;
|
|
15828
|
-
}
|
|
15829
|
-
let i = await Mo(t, o);
|
|
15830
|
-
return FD(s, i, n);
|
|
15831
|
-
}
|
|
15832
|
-
function QD(e10, t, n) {
|
|
15833
|
-
if (t === void 0) return false;
|
|
15834
|
-
let r = om(Ye(e10), n);
|
|
15835
|
-
return t.some((o) => {
|
|
15836
|
-
let s = om(Ye(o), n);
|
|
15837
|
-
return r === s || r.startsWith(s.endsWith("/") ? s : s + "/");
|
|
15838
|
-
});
|
|
15839
|
-
}
|
|
15840
|
-
function bb() {
|
|
15841
|
-
return process.platform === "win32" || process.platform === "darwin";
|
|
15842
|
-
}
|
|
15843
16390
|
function St() {
|
|
15844
16391
|
return kr(Dt(), "projects");
|
|
15845
16392
|
}
|
|
@@ -20257,9 +20804,6 @@ function GTe(e10) {
|
|
|
20257
20804
|
function TR(e10) {
|
|
20258
20805
|
return (t) => e10.hostFiles.realPath(kf.workspace(t === "" || KTe(t) ? t : GTe(t)), { native: true });
|
|
20259
20806
|
}
|
|
20260
|
-
function gd(e10) {
|
|
20261
|
-
return e10 === void 0 ? void 0 : { hoverRestOn: be(), realPath: TR(e10) };
|
|
20262
|
-
}
|
|
20263
20807
|
function VTe(e10) {
|
|
20264
20808
|
return e10.namespace !== "transcript" || e10.journal !== void 0 || e10.sessionJournal !== void 0 ? void 0 : e10.agentId ?? null;
|
|
20265
20809
|
}
|
|
@@ -20703,12 +21247,6 @@ async function g0(e10, t, n, r) {
|
|
|
20703
21247
|
let { entries: l, delivered: c } = await ZTe(a);
|
|
20704
21248
|
return m0(l, t, c);
|
|
20705
21249
|
}
|
|
20706
|
-
function lOe() {
|
|
20707
|
-
return aOe(Dt(), "projects");
|
|
20708
|
-
}
|
|
20709
|
-
function h0(e10) {
|
|
20710
|
-
return iOe(e10) === lOe() ? sOe(e10) : void 0;
|
|
20711
|
-
}
|
|
20712
21250
|
var _0 = class {
|
|
20713
21251
|
projectDirCache = /* @__PURE__ */ new Map();
|
|
20714
21252
|
agentTranscriptSubdirs = /* @__PURE__ */ new Map();
|
|
@@ -20726,314 +21264,12 @@ var _0 = class {
|
|
|
20726
21264
|
}
|
|
20727
21265
|
};
|
|
20728
21266
|
var Eit = new Pe(() => new _0());
|
|
20729
|
-
var y0 = 200;
|
|
20730
|
-
function cOe(e10) {
|
|
20731
|
-
return [...e10.replace(/[\x00-\x1f\x7f-\x9f]/g, "")].slice(0, y0).join("");
|
|
20732
|
-
}
|
|
20733
|
-
function S0(e10) {
|
|
20734
|
-
return cOe(Vf(e10.trim())).trim();
|
|
20735
|
-
}
|
|
20736
|
-
var uOe = 6;
|
|
20737
|
-
function C0(e10) {
|
|
20738
|
-
let t = E0(e10);
|
|
20739
|
-
if (fd(t)) return;
|
|
20740
|
-
let n = St(), r = [t], o = b0(e10);
|
|
20741
|
-
while (o !== n && r.length <= uOe + 1) {
|
|
20742
|
-
let c = b0(o);
|
|
20743
|
-
if (c === o) return;
|
|
20744
|
-
r.unshift(E0(o)), o = c;
|
|
20745
|
-
}
|
|
20746
|
-
if (o !== n || r.length < 3) return;
|
|
20747
|
-
let [s, i, ...a] = r;
|
|
20748
|
-
if (!Qt(s) || !Qt(i) || a.length === 0 || !a.every(Qt)) return;
|
|
20749
|
-
let l = Mt.sidecar(s, i, a);
|
|
20750
|
-
return zo(l) === void 0 ? l : void 0;
|
|
20751
|
-
}
|
|
20752
21267
|
var mOe = k(() => R({ customTitle: h() }));
|
|
20753
|
-
function gOe(e10, t) {
|
|
20754
|
-
return fOe(pOe(e10), t, "custom-title.json");
|
|
20755
|
-
}
|
|
20756
|
-
async function ml(e10, t, n) {
|
|
20757
|
-
let r = await hOe(gOe(e10, t), n);
|
|
20758
|
-
if (r === void 0) return;
|
|
20759
|
-
let o;
|
|
20760
|
-
try {
|
|
20761
|
-
o = JSON.parse(r);
|
|
20762
|
-
} catch {
|
|
20763
|
-
return;
|
|
20764
|
-
}
|
|
20765
|
-
let s = mOe().safeParse(o);
|
|
20766
|
-
if (!s.success) return;
|
|
20767
|
-
return S0(s.data.customTitle) || void 0;
|
|
20768
|
-
}
|
|
20769
|
-
async function hOe(e10, t) {
|
|
20770
|
-
if (be() && t !== void 0) try {
|
|
20771
|
-
let n = C0(e10);
|
|
20772
|
-
if (n !== void 0) {
|
|
20773
|
-
let r = await t.readText([n]);
|
|
20774
|
-
if (!r.ok) return;
|
|
20775
|
-
let o = r.value.items[0];
|
|
20776
|
-
return o.found ? o.value : void 0;
|
|
20777
|
-
}
|
|
20778
|
-
} catch {
|
|
20779
|
-
return;
|
|
20780
|
-
}
|
|
20781
|
-
if (Qe()) return;
|
|
20782
|
-
try {
|
|
20783
|
-
return await dOe(e10, "utf8");
|
|
20784
|
-
} catch {
|
|
20785
|
-
return;
|
|
20786
|
-
}
|
|
20787
|
-
}
|
|
20788
21268
|
function se(e10) {
|
|
20789
21269
|
return typeof e10 === "object" && e10 !== null && !Array.isArray(e10);
|
|
20790
21270
|
}
|
|
20791
|
-
var A0 = '"type":"continued-in"';
|
|
20792
21271
|
var bOe = k(() => Bt({ type: N("continued-in"), continuedInSessionId: h() }));
|
|
20793
21272
|
var COe = k(() => Bt({ type: N("assistant"), isApiErrorMessage: x().optional(), message: Bt({ stop_reason: h().nullish() }).optional() }));
|
|
20794
|
-
function T0(e10) {
|
|
20795
|
-
if (!e10.includes(A0)) return;
|
|
20796
|
-
let t = e10.length;
|
|
20797
|
-
while (t > 0) {
|
|
20798
|
-
let n = e10.lastIndexOf(`
|
|
20799
|
-
`, t - 1), r = e10.slice(n + 1, t);
|
|
20800
|
-
t = n;
|
|
20801
|
-
let o = r.includes(A0), s = r.includes('"type":"user"') || r.includes('"type":"assistant"');
|
|
20802
|
-
if (o || s) try {
|
|
20803
|
-
let i = JSON.parse(r);
|
|
20804
|
-
if (o) {
|
|
20805
|
-
let a = bOe().safeParse(i);
|
|
20806
|
-
if (a.success) return Ve(a.data.continuedInSessionId) ?? void 0;
|
|
20807
|
-
}
|
|
20808
|
-
if (s && AOe(i)) return;
|
|
20809
|
-
} catch {
|
|
20810
|
-
}
|
|
20811
|
-
if (n < 0) break;
|
|
20812
|
-
}
|
|
20813
|
-
return;
|
|
20814
|
-
}
|
|
20815
|
-
function AOe(e10) {
|
|
20816
|
-
let t = COe().safeParse(e10);
|
|
20817
|
-
if (t.success) return t.data.isApiErrorMessage !== true && typeof t.data.message?.stop_reason === "string";
|
|
20818
|
-
return se(e10) && zi(e10, { commandFallback: "" }) !== void 0;
|
|
20819
|
-
}
|
|
20820
|
-
async function O0(e10, t, n) {
|
|
20821
|
-
let r = EOe(SOe(e10), `${t}.jsonl`), o = await ji(r, cn(Lr(r, n)));
|
|
20822
|
-
return o !== null && await w0(r, o.head, o.tail, o.size, n);
|
|
20823
|
-
}
|
|
20824
|
-
var yd = '"parentUuid":';
|
|
20825
|
-
var ROe = 16777216;
|
|
20826
|
-
var R0 = 1048576;
|
|
20827
|
-
async function w0(e10, t, n, r, o) {
|
|
20828
|
-
if (t.includes(yd) || n.includes(yd)) return true;
|
|
20829
|
-
if (r <= En) return false;
|
|
20830
|
-
if (Lr(e10, o) !== void 0) return true;
|
|
20831
|
-
try {
|
|
20832
|
-
let s = process.platform !== "win32";
|
|
20833
|
-
if (!s && !(await _Oe(e10)).isFile()) return false;
|
|
20834
|
-
let i = await yOe(e10, s ? Xm.O_RDONLY | Xm.O_NOFOLLOW | Xm.O_NONBLOCK : Xm.O_RDONLY);
|
|
20835
|
-
try {
|
|
20836
|
-
if (!(await i.stat()).isFile()) return false;
|
|
20837
|
-
let a = Buffer.allocUnsafe(R0 + yd.length), l = 0, c = 0;
|
|
20838
|
-
while (c < ROe) {
|
|
20839
|
-
let { bytesRead: d } = await i.read(a, l, R0, c);
|
|
20840
|
-
if (d === 0) return false;
|
|
20841
|
-
let p = l + d;
|
|
20842
|
-
if (a.subarray(0, p).includes(yd)) return true;
|
|
20843
|
-
l = Math.min(yd.length, p), a.copyWithin(0, p - l, p), c += d;
|
|
20844
|
-
}
|
|
20845
|
-
return true;
|
|
20846
|
-
} finally {
|
|
20847
|
-
await i.close();
|
|
20848
|
-
}
|
|
20849
|
-
} catch {
|
|
20850
|
-
return false;
|
|
20851
|
-
}
|
|
20852
|
-
}
|
|
20853
|
-
function gl(e10, t, n, r) {
|
|
20854
|
-
let { head: o, tail: s, mtime: i, size: a } = t, l = o.indexOf(`
|
|
20855
|
-
`), c = l >= 0 ? o.slice(0, l) : o;
|
|
20856
|
-
if (c.includes('"isSidechain":true') || c.includes('"isSidechain": true')) return null;
|
|
20857
|
-
let d = Xt(s, "customTitle") || r || Xt(o, "customTitle") || Xt(s, "aiTitle") || Xt(o, "aiTitle") || void 0, p = cm(o) || void 0, f = nl(o, "timestamp"), m;
|
|
20858
|
-
if (f) {
|
|
20859
|
-
let b = Date.parse(f);
|
|
20860
|
-
if (!Number.isNaN(b)) m = b;
|
|
20861
|
-
}
|
|
20862
|
-
let g = d || Xt(s, "lastPrompt") || Xt(s, "summary") || p || qD(o);
|
|
20863
|
-
if (!g) return null;
|
|
20864
|
-
let _ = Xt(s, "gitBranch") || nl(o, "gitBranch") || void 0, y = am(s, "relocated", "relocatedCwd") || nl(o, "cwd") || n || void 0, S = s.split(`
|
|
20865
|
-
`).findLast((b) => b.includes('"type":"tag"') && b.includes('"tag":"')), E = S ? Xt(S, "tag") || void 0 : void 0;
|
|
20866
|
-
return { sessionId: e10, summary: g, lastModified: i, fileSize: a, customTitle: d, firstPrompt: p, gitBranch: _, cwd: y, tag: E, createdAt: m };
|
|
20867
|
-
}
|
|
20868
|
-
function wOe(e10) {
|
|
20869
|
-
let t = h0(e10);
|
|
20870
|
-
return t !== void 0 && Qt(t) ? t : void 0;
|
|
20871
|
-
}
|
|
20872
|
-
function IR(e10) {
|
|
20873
|
-
return { pagesLeft: kD + e10 };
|
|
20874
|
-
}
|
|
20875
|
-
async function Qm(e10, t, n, r, o, s) {
|
|
20876
|
-
let i = be() && r !== void 0 ? wOe(e10) : void 0;
|
|
20877
|
-
if (r !== void 0 && i !== void 0) {
|
|
20878
|
-
let c = /* @__PURE__ */ new Map();
|
|
20879
|
-
try {
|
|
20880
|
-
await vr((d) => r.listEntries({ namespace: "transcript", projectKey: i }, { skipScopeStats: true, ...t ? {} : { skipKeyStats: true }, ...d !== void 0 && { cursor: d } }), (d) => {
|
|
20881
|
-
for (let p of d) {
|
|
20882
|
-
if (p.kind !== "key" || p.key.namespace !== "transcript") continue;
|
|
20883
|
-
let f = Ve(p.key.sessionId);
|
|
20884
|
-
if (!f) continue;
|
|
20885
|
-
if (t && p.mtimeMs === void 0) continue;
|
|
20886
|
-
let m = t ? Math.trunc(p.mtimeMs ?? 0) : 0, g = c.get(f);
|
|
20887
|
-
if (g !== void 0) {
|
|
20888
|
-
if (m > g.mtime) g.mtime = m;
|
|
20889
|
-
continue;
|
|
20890
|
-
}
|
|
20891
|
-
c.set(f, { sessionId: f, filePath: Sd(e10, `${p.key.sessionId}.jsonl`), mtime: m, projectPath: n, ownWorktrees: s });
|
|
20892
|
-
}
|
|
20893
|
-
}, o !== void 0 ? { budget: o } : void 0);
|
|
20894
|
-
} catch {
|
|
20895
|
-
}
|
|
20896
|
-
return [...c.values()];
|
|
20897
|
-
}
|
|
20898
|
-
let a;
|
|
20899
|
-
try {
|
|
20900
|
-
a = await PR(e10);
|
|
20901
|
-
} catch {
|
|
20902
|
-
return [];
|
|
20903
|
-
}
|
|
20904
|
-
return (await Promise.all(a.map(async (c) => {
|
|
20905
|
-
if (!c.endsWith(".jsonl")) return null;
|
|
20906
|
-
let d = Ve(c.slice(0, -6));
|
|
20907
|
-
if (!d) return null;
|
|
20908
|
-
let p = Sd(e10, c);
|
|
20909
|
-
if (!t) return { sessionId: d, filePath: p, mtime: 0, projectPath: n, ownWorktrees: s };
|
|
20910
|
-
try {
|
|
20911
|
-
let f = await TOe(p);
|
|
20912
|
-
return { sessionId: d, filePath: p, mtime: f.mtime.getTime(), projectPath: n, ownWorktrees: s };
|
|
20913
|
-
} catch {
|
|
20914
|
-
return null;
|
|
20915
|
-
}
|
|
20916
|
-
}))).filter((c) => c !== null);
|
|
20917
|
-
}
|
|
20918
|
-
async function v0(e10, t, n) {
|
|
20919
|
-
let r = await ji(e10.filePath, cn(Lr(e10.filePath, n)));
|
|
20920
|
-
if (!r) return null;
|
|
20921
|
-
if (!t && WD(r.head, r.tail)) return null;
|
|
20922
|
-
let o = T0(r.tail);
|
|
20923
|
-
if (o !== void 0 && await O0(e10.filePath, o, n)) return null;
|
|
20924
|
-
let s = Xt(r.tail, "customTitle") === void 0 ? await ml(e10.filePath, e10.sessionId, n) : void 0, i = gl(e10.sessionId, r, e10.projectPath, s);
|
|
20925
|
-
if (!i) return null;
|
|
20926
|
-
let a = am(r.tail, "relocated", "relocatedCwd") ?? Sb(r.head, "cwd");
|
|
20927
|
-
if (a !== void 0 && e10.projectPath !== void 0 && !QD(a, e10.ownWorktrees, bb()) && await XD(a, e10.projectPath, bb(), xP, gd(n))) return null;
|
|
20928
|
-
if (e10.mtime) i.lastModified = e10.mtime;
|
|
20929
|
-
return i;
|
|
20930
|
-
}
|
|
20931
|
-
var xOe = 32;
|
|
20932
|
-
function vOe(e10, t) {
|
|
20933
|
-
if (t.mtime !== e10.mtime) return t.mtime - e10.mtime;
|
|
20934
|
-
return t.sessionId < e10.sessionId ? -1 : t.sessionId > e10.sessionId ? 1 : 0;
|
|
20935
|
-
}
|
|
20936
|
-
async function kOe(e10, t, n, r, o) {
|
|
20937
|
-
e10.sort(vOe);
|
|
20938
|
-
let s = [], i = t && t > 0 ? t : 1 / 0, a = 0, l = /* @__PURE__ */ new Set();
|
|
20939
|
-
for (let c = 0; c < e10.length && s.length < i; ) {
|
|
20940
|
-
let d = Math.min(c + xOe, e10.length), p = e10.slice(c, d), f = await Promise.all(p.map((m) => v0(m, r, o)));
|
|
20941
|
-
for (let m = 0; m < f.length && s.length < i; m++) {
|
|
20942
|
-
c++;
|
|
20943
|
-
let g = f[m];
|
|
20944
|
-
if (!g) continue;
|
|
20945
|
-
if (l.has(g.sessionId)) continue;
|
|
20946
|
-
if (l.add(g.sessionId), a < n) {
|
|
20947
|
-
a++;
|
|
20948
|
-
continue;
|
|
20949
|
-
}
|
|
20950
|
-
s.push(g);
|
|
20951
|
-
}
|
|
20952
|
-
}
|
|
20953
|
-
return s;
|
|
20954
|
-
}
|
|
20955
|
-
async function POe(e10, t, n) {
|
|
20956
|
-
let r = await Promise.all(e10.map((i) => v0(i, t, n))), o = /* @__PURE__ */ new Map();
|
|
20957
|
-
for (let i of r) {
|
|
20958
|
-
if (!i) continue;
|
|
20959
|
-
let a = o.get(i.sessionId);
|
|
20960
|
-
if (!a || i.lastModified > a.lastModified) o.set(i.sessionId, i);
|
|
20961
|
-
}
|
|
20962
|
-
let s = [...o.values()];
|
|
20963
|
-
return s.sort((i, a) => a.lastModified !== i.lastModified ? a.lastModified - i.lastModified : a.sessionId < i.sessionId ? -1 : a.sessionId > i.sessionId ? 1 : 0), s;
|
|
20964
|
-
}
|
|
20965
|
-
async function x0(e10, t, n, r, o) {
|
|
20966
|
-
let s = process.platform === "win32", i = o !== void 0 && o.hoverRestOn && e10.length > 1 ? { ...o, source: Eb(o.source) } : o, a = [], l = /* @__PURE__ */ new Set();
|
|
20967
|
-
for (let p of e10) for (let f of await qn(p, i, n)) {
|
|
20968
|
-
let m = s ? f.toLowerCase() : f;
|
|
20969
|
-
if (!l.has(m)) l.add(m), a.push({ projectDir: f, projectPath: p });
|
|
20970
|
-
}
|
|
20971
|
-
let c = IR(a.length), d = [];
|
|
20972
|
-
for (let { projectDir: p, projectPath: f } of a) d.push(...await Qm(p, t, f, r, c));
|
|
20973
|
-
return d;
|
|
20974
|
-
}
|
|
20975
|
-
async function IOe(e10, t, n, r, o) {
|
|
20976
|
-
let s = await Mo(e10, gd(o)), i = cn(zn(o)), a = Ab(e10, s), l;
|
|
20977
|
-
if (t) try {
|
|
20978
|
-
l = await Do(s);
|
|
20979
|
-
} catch {
|
|
20980
|
-
l = [];
|
|
20981
|
-
}
|
|
20982
|
-
else l = [];
|
|
20983
|
-
if (l.length <= 1) return x0(a, n, r, o, i);
|
|
20984
|
-
let c = process.platform === "win32", d = l.map((S) => {
|
|
20985
|
-
let E = Vr(S), b = c ? E.toLowerCase() : E;
|
|
20986
|
-
return { path: S, exactName: b, truncatedPrefix: E.length > Lo ? b.slice(0, Lo) : void 0 };
|
|
20987
|
-
});
|
|
20988
|
-
d.sort((S, E) => E.exactName.length - S.exactName.length);
|
|
20989
|
-
let p = i !== void 0 && i.hoverRestOn ? await il(i.source) : null, f = p;
|
|
20990
|
-
if (f === null) {
|
|
20991
|
-
let S;
|
|
20992
|
-
try {
|
|
20993
|
-
S = await PR(r, { withFileTypes: true });
|
|
20994
|
-
} catch {
|
|
20995
|
-
return x0(a, n, r, o, void 0);
|
|
20996
|
-
}
|
|
20997
|
-
f = S.filter((E) => E.isDirectory()).map((E) => E.name);
|
|
20998
|
-
}
|
|
20999
|
-
let m = [], g = /* @__PURE__ */ new Set(), _ = IR(f.length + a.length), y = [...a, ...l];
|
|
21000
|
-
for (let S of a) {
|
|
21001
|
-
let E = i !== void 0 && i.hoverRestOn && p !== null ? await Rb(S, p, c, i) : await qn(S, void 0, r);
|
|
21002
|
-
for (let b of E) {
|
|
21003
|
-
let C = OOe(b), A = c ? C.toLowerCase() : C;
|
|
21004
|
-
if (g.has(A)) continue;
|
|
21005
|
-
g.add(A), m.push(...await Qm(b, n, S, o, _, y));
|
|
21006
|
-
}
|
|
21007
|
-
}
|
|
21008
|
-
for (let S of f) {
|
|
21009
|
-
let E = c ? S.toLowerCase() : S;
|
|
21010
|
-
if (g.has(E)) continue;
|
|
21011
|
-
for (let { path: b, exactName: C, truncatedPrefix: A } of d) if (E === C || A !== void 0 && E.startsWith(A + "-") && await sl(Sd(r, S), b, c, i)) {
|
|
21012
|
-
g.add(E), m.push(...await Qm(Sd(r, S), n, b, o, _, y));
|
|
21013
|
-
break;
|
|
21014
|
-
}
|
|
21015
|
-
}
|
|
21016
|
-
return m;
|
|
21017
|
-
}
|
|
21018
|
-
async function DOe(e10, t, n) {
|
|
21019
|
-
let r = zn(n), o = r !== void 0 ? await il(r) : null;
|
|
21020
|
-
if (o === null) {
|
|
21021
|
-
let a;
|
|
21022
|
-
try {
|
|
21023
|
-
a = await PR(t, { withFileTypes: true });
|
|
21024
|
-
} catch {
|
|
21025
|
-
return [];
|
|
21026
|
-
}
|
|
21027
|
-
o = a.filter((l) => l.isDirectory()).map((l) => l.name);
|
|
21028
|
-
}
|
|
21029
|
-
let s = IR(o.length);
|
|
21030
|
-
return (await Promise.all(o.map((a) => Qm(Sd(t, a), e10, void 0, n, s)))).flat();
|
|
21031
|
-
}
|
|
21032
|
-
async function k0(e10, t, n = St()) {
|
|
21033
|
-
let r = be() ? t : void 0, { dir: o, limit: s, offset: i, includeWorktrees: a, includeProgrammatic: l } = e10 ?? {}, c = i ?? 0, d = l ?? true, p = s !== void 0 && s > 0 || c > 0, f = o ? await IOe(o, a ?? true, p, n, r) : await DOe(p, n, r);
|
|
21034
|
-
if (!p) return POe(f, d, r);
|
|
21035
|
-
return kOe(f, s, c, d, r);
|
|
21036
|
-
}
|
|
21037
21273
|
var N0 = 4;
|
|
21038
21274
|
var VOe = 50;
|
|
21039
21275
|
var qOe = Array.from({ length: N0 - 1 }, () => VOe);
|
|
@@ -21186,19 +21422,6 @@ function zR(e10, t, n, r) {
|
|
|
21186
21422
|
let o = Fwe(e10), s = $we(o), i = ku(n), a = typeof r === "string" && Vy(r) ? r : void 0, l = xR(s, { keepMeta: true }).filter((c) => c.type === "user" || c.type === "assistant").map((c) => vR(c, i, a));
|
|
21187
21423
|
return kR(l, t);
|
|
21188
21424
|
}
|
|
21189
|
-
function cF(e10, t) {
|
|
21190
|
-
let n = e10.data;
|
|
21191
|
-
if (n.isSidechain === true) return null;
|
|
21192
|
-
let r = Ps(n.firstPromptLocked === true ? n.firstPrompt : n.commandFallback) || void 0, o = Ps(n.customTitle) || Ps(n.aiTitle) || void 0, s = o || Ps(n.lastPrompt) || Ps(n.summaryHint) || r;
|
|
21193
|
-
if (!s) return null;
|
|
21194
|
-
return { sessionId: e10.sessionId, summary: s, lastModified: e10.mtime, fileSize: void 0, customTitle: o, firstPrompt: r, gitBranch: Ps(n.gitBranch) || void 0, cwd: Ps(n.cwd) || t || void 0, tag: Ps(n.tag) || void 0, createdAt: Gwe(n.createdAt) };
|
|
21195
|
-
}
|
|
21196
|
-
function Ps(e10) {
|
|
21197
|
-
return typeof e10 === "string" ? e10 : void 0;
|
|
21198
|
-
}
|
|
21199
|
-
function Gwe(e10) {
|
|
21200
|
-
return typeof e10 === "number" ? e10 : void 0;
|
|
21201
|
-
}
|
|
21202
21425
|
var Ne;
|
|
21203
21426
|
(function(e10) {
|
|
21204
21427
|
e10.assertEqual = (o) => {
|
|
@@ -30686,10 +30909,6 @@ async function P1t(e10, t) {
|
|
|
30686
30909
|
if (t?.sessionStore) return c3e(t.sessionStore, e10, t);
|
|
30687
30910
|
return g0(e10, t);
|
|
30688
30911
|
}
|
|
30689
|
-
async function I1t(e10) {
|
|
30690
|
-
if (e10?.sessionStore) return i3e(e10.sessionStore, e10);
|
|
30691
|
-
return k0(e10);
|
|
30692
|
-
}
|
|
30693
30912
|
async function U1t(e10, t, n) {
|
|
30694
30913
|
if (n?.sessionStore) return f3e(n.sessionStore, e10, t, n);
|
|
30695
30914
|
return oF(e10, t, n);
|
|
@@ -30699,59 +30918,6 @@ function A3(e10) {
|
|
|
30699
30918
|
`) + `
|
|
30700
30919
|
`;
|
|
30701
30920
|
}
|
|
30702
|
-
function R3(e10, t, n) {
|
|
30703
|
-
if (t !== void 0 && t > 0) return e10.slice(n, n + t);
|
|
30704
|
-
if (n > 0) return e10.slice(n);
|
|
30705
|
-
return e10;
|
|
30706
|
-
}
|
|
30707
|
-
async function i3e(e10, t) {
|
|
30708
|
-
let n = Dv(t.dir), r = Vr(n), o = t.offset ?? 0, s = t.limit;
|
|
30709
|
-
if (e10.listSessionSummaries) return a3e(e10, r, n, t.dir, s, o);
|
|
30710
|
-
if (!e10.listSessions) throw Error("sessionStore.listSessions is not implemented -- cannot list sessions. Provide a store with a listSessions() method.");
|
|
30711
|
-
let a = (await e10.listSessions(r)).slice().sort((c, d) => d.mtime - c.mtime), l = R3(a, s, o);
|
|
30712
|
-
return T3(e10, l, t.dir, n);
|
|
30713
|
-
}
|
|
30714
|
-
async function a3e(e10, t, n, r, o, s) {
|
|
30715
|
-
let i = await e10.listSessionSummaries(t), a = e10.listSessions ? new Map((await e10.listSessions(t)).map((p) => [p.sessionId, p])) : void 0, l = [];
|
|
30716
|
-
for (let p of i) {
|
|
30717
|
-
let f = a?.get(p.sessionId);
|
|
30718
|
-
if (a && !f) continue;
|
|
30719
|
-
let m = f !== void 0 && p.mtime < f.mtime;
|
|
30720
|
-
l.push({ sessionId: p.sessionId, mtime: m ? f.mtime : p.mtime, info: m ? void 0 : cF(p, n) });
|
|
30721
|
-
}
|
|
30722
|
-
if (a) {
|
|
30723
|
-
let p = new Set(i.map((f) => f.sessionId));
|
|
30724
|
-
for (let [f, m] of a) if (!p.has(f)) l.push({ sessionId: f, mtime: m.mtime });
|
|
30725
|
-
} else K("listSessionSummaries without listSessions: gap-fill skipped; sessions lacking a sidecar will be omitted");
|
|
30726
|
-
l.sort((p, f) => f.mtime - p.mtime);
|
|
30727
|
-
let c = R3(l, o, s), d = c.filter((p) => p.info === void 0);
|
|
30728
|
-
if (d.length > 0) {
|
|
30729
|
-
let p = await T3(e10, d, r, n), f = new Map(p.map((m) => [m.sessionId, m]));
|
|
30730
|
-
for (let m of c) if (m.info === void 0) m.info = f.get(m.sessionId) ?? null;
|
|
30731
|
-
}
|
|
30732
|
-
return c.flatMap((p) => p.info ? [p.info] : []);
|
|
30733
|
-
}
|
|
30734
|
-
async function T3(e10, t, n, r) {
|
|
30735
|
-
return (await Promise.allSettled(t.map(async (s) => {
|
|
30736
|
-
let i = await w3(e10, s.sessionId, n);
|
|
30737
|
-
if (!i) return null;
|
|
30738
|
-
let a = gl(s.sessionId, O3(i, s.mtime), r);
|
|
30739
|
-
return a ? { ...a, lastModified: s.mtime } : null;
|
|
30740
|
-
}))).flatMap((s, i) => {
|
|
30741
|
-
let a = t[i];
|
|
30742
|
-
if (s.status === "fulfilled") return s.value ? [s.value] : [];
|
|
30743
|
-
return [{ sessionId: a.sessionId, summary: "", lastModified: a.mtime }];
|
|
30744
|
-
});
|
|
30745
|
-
}
|
|
30746
|
-
function O3(e10, t) {
|
|
30747
|
-
let n = Buffer.from(e10, "utf-8"), r = n.length, o = n.subarray(0, En).toString("utf-8"), s = r > En ? n.subarray(r - En).toString("utf-8") : o;
|
|
30748
|
-
return { mtime: t, size: r, head: o, tail: s };
|
|
30749
|
-
}
|
|
30750
|
-
async function w3(e10, t, n) {
|
|
30751
|
-
let r = Pn(n), o = await e10.load({ projectKey: r, sessionId: t });
|
|
30752
|
-
if (!o || o.length === 0) return null;
|
|
30753
|
-
return A3(o);
|
|
30754
|
-
}
|
|
30755
30921
|
async function c3e(e10, t, n) {
|
|
30756
30922
|
if (!Ve(t)) return [];
|
|
30757
30923
|
let r = Pn(n.dir), o = await e10.load({ projectKey: r, sessionId: t });
|
|
@@ -30775,19 +30941,19 @@ async function f3e(e10, t, n, r) {
|
|
|
30775
30941
|
}
|
|
30776
30942
|
|
|
30777
30943
|
// server/adapters/claude.ts
|
|
30778
|
-
import {
|
|
30779
|
-
import {
|
|
30780
|
-
import { join as
|
|
30944
|
+
import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
|
|
30945
|
+
import { lstat as lstat6, readdir as readdir3, stat } from "node:fs/promises";
|
|
30946
|
+
import { basename as basename5, dirname as dirname4, join as join11, resolve as resolve3 } from "node:path";
|
|
30781
30947
|
|
|
30782
30948
|
// server/adapters/claude-transcripts.ts
|
|
30783
|
-
import { constants as
|
|
30784
|
-
import { lstat, open } from "node:fs/promises";
|
|
30785
|
-
import { basename as
|
|
30949
|
+
import { constants as constants4 } from "node:fs";
|
|
30950
|
+
import { lstat as lstat4, open as open2 } from "node:fs/promises";
|
|
30951
|
+
import { basename as basename2 } from "node:path";
|
|
30786
30952
|
var claudeSessionID = (value) => /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
|
|
30787
|
-
var
|
|
30788
|
-
var sidecar = (path) =>
|
|
30953
|
+
var MAX_BYTES2 = 128e6;
|
|
30954
|
+
var sidecar = (path) => basename2(path).startsWith("agent-") ? path.replace(/\.jsonl$/, ".meta.json") : void 0;
|
|
30789
30955
|
async function state(path) {
|
|
30790
|
-
const s = await
|
|
30956
|
+
const s = await lstat4(path);
|
|
30791
30957
|
if (!s.isFile()) throw new Error("Claude transcript must be a regular file.");
|
|
30792
30958
|
return { size: s.size, modified: s.mtimeMs, signature: [s.dev, s.ino, s.size, s.mtimeMs] };
|
|
30793
30959
|
}
|
|
@@ -30805,8 +30971,8 @@ async function claudeRevision(path) {
|
|
|
30805
30971
|
}
|
|
30806
30972
|
async function bytes(path, max) {
|
|
30807
30973
|
const before = await state(path);
|
|
30808
|
-
if (before.size > max) throw new Error(`Claude transcript exceeds the ${max ===
|
|
30809
|
-
const file = await
|
|
30974
|
+
if (before.size > max) throw new Error(`Claude transcript exceeds the ${max === MAX_BYTES2 ? "128 MB import" : "metadata size"} limit.`);
|
|
30975
|
+
const file = await open2(path, constants4.O_RDONLY | (constants4.O_NOFOLLOW || 0) | (constants4.O_NONBLOCK || 0));
|
|
30810
30976
|
try {
|
|
30811
30977
|
const opened = await file.stat();
|
|
30812
30978
|
if (!opened.isFile() || opened.dev !== before.signature[0] || opened.ino !== before.signature[1]) throw new Error("Claude transcript changed during import; import again.");
|
|
@@ -30827,7 +30993,7 @@ var cached;
|
|
|
30827
30993
|
async function claudeTranscript(path, revision2) {
|
|
30828
30994
|
if (await claudeRevision(path) !== revision2) throw new Error("Claude transcript changed during import; import again.");
|
|
30829
30995
|
if (cached?.path === path && cached.revision === revision2) return cached.transcript;
|
|
30830
|
-
const source = await bytes(path,
|
|
30996
|
+
const source = await bytes(path, MAX_BYTES2), entries2 = [], times = /* @__PURE__ */ new Map();
|
|
30831
30997
|
let partial = false;
|
|
30832
30998
|
for (const line of source.split("\n")) {
|
|
30833
30999
|
if (!line.trim()) continue;
|
|
@@ -30847,10 +31013,10 @@ async function claudeTranscript(path, revision2) {
|
|
|
30847
31013
|
}
|
|
30848
31014
|
if (entries2.length > 2e5) throw new Error("Claude transcript exceeds the 200,000-record import limit.");
|
|
30849
31015
|
}
|
|
30850
|
-
const
|
|
30851
|
-
if (
|
|
31016
|
+
const metadata3 = sidecar(path);
|
|
31017
|
+
if (metadata3 && await metadataState(path)) {
|
|
30852
31018
|
try {
|
|
30853
|
-
entries2.push({ ...JSON.parse(await bytes(
|
|
31019
|
+
entries2.push({ ...JSON.parse(await bytes(metadata3, 64e3)), type: "agent_metadata" });
|
|
30854
31020
|
} catch {
|
|
30855
31021
|
partial = true;
|
|
30856
31022
|
}
|
|
@@ -30887,216 +31053,8 @@ function claudeTranscriptStore(transcript, sessionId, agent) {
|
|
|
30887
31053
|
};
|
|
30888
31054
|
}
|
|
30889
31055
|
|
|
30890
|
-
// server/adapters/local-files.ts
|
|
30891
|
-
import { constants as constants3 } from "node:fs";
|
|
30892
|
-
import { lstat as lstat2, open as open2, readdir } from "node:fs/promises";
|
|
30893
|
-
import { join as join4, relative } from "node:path";
|
|
30894
|
-
|
|
30895
|
-
// server/adapters/compressed.ts
|
|
30896
|
-
import { gunzipSync, zstdDecompressSync } from "node:zlib";
|
|
30897
|
-
function expandHistory(buffer, maxOutputLength) {
|
|
30898
|
-
if (buffer.length >= 4 && buffer.readUInt32LE(0) === 4247762216) return zstdDecompressSync(buffer, { maxOutputLength });
|
|
30899
|
-
if (buffer[0] === 31 && buffer[1] === 139) return gunzipSync(buffer, { maxOutputLength });
|
|
30900
|
-
if (buffer.length > maxOutputLength) throw new Error("Expanded history exceeds the snapshot limit.");
|
|
30901
|
-
return buffer;
|
|
30902
|
-
}
|
|
30903
|
-
|
|
30904
|
-
// server/adapters/local-files.ts
|
|
30905
|
-
var object3 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
30906
|
-
var text = (value) => typeof value === "string" ? value : "";
|
|
30907
|
-
var time = (value) => {
|
|
30908
|
-
const n = typeof value === "number" ? value : typeof value === "string" ? /^\d{13}$/.test(value) ? Number(value) : Date.parse(value) : 0;
|
|
30909
|
-
return Number.isFinite(n) && n > 0 && n <= 864e13 ? n : 0;
|
|
30910
|
-
};
|
|
30911
|
-
var MAX_BYTES2 = 32e6;
|
|
30912
|
-
var MAX_RECORDS = 5e4;
|
|
30913
|
-
var MAX_FILES = 2e4;
|
|
30914
|
-
async function fileState(path) {
|
|
30915
|
-
try {
|
|
30916
|
-
const s = await lstat2(path);
|
|
30917
|
-
if (!s.isFile()) throw new Error("History must be a regular file, not a symlink.");
|
|
30918
|
-
if (s.size > MAX_BYTES2) throw new Error("History exceeds the 32 MB per-file limit.");
|
|
30919
|
-
return { path, signature: digest([s.size, s.mtimeMs, s.ctimeMs, s.ino]), created: s.birthtimeMs || s.mtimeMs, updated: s.mtimeMs, size: s.size };
|
|
30920
|
-
} catch (error) {
|
|
30921
|
-
if (error.code === "ENOENT") return { path, signature: "missing", created: 0, updated: 0, size: 0 };
|
|
30922
|
-
throw error;
|
|
30923
|
-
}
|
|
30924
|
-
}
|
|
30925
|
-
async function historyFiles(roots2, match2) {
|
|
30926
|
-
const files = [], queue = [];
|
|
30927
|
-
const warnings = [];
|
|
30928
|
-
for (const root3 of new Set(roots2)) {
|
|
30929
|
-
try {
|
|
30930
|
-
if ((await lstat2(root3)).isDirectory()) queue.push({ root: root3, path: root3, depth: 0 });
|
|
30931
|
-
} catch (error) {
|
|
30932
|
-
if (error.code !== "ENOENT") warnings.push("A history directory could not be read.");
|
|
30933
|
-
}
|
|
30934
|
-
}
|
|
30935
|
-
let entriesSeen = 0, limited = false;
|
|
30936
|
-
for (let i = 0; i < queue.length && files.length < MAX_FILES && entriesSeen < 1e5; i++) {
|
|
30937
|
-
const { root: root3, path, depth } = queue[i];
|
|
30938
|
-
let entries2;
|
|
30939
|
-
try {
|
|
30940
|
-
entries2 = await readdir(path, { withFileTypes: true });
|
|
30941
|
-
} catch {
|
|
30942
|
-
warnings.push("A history directory could not be read.");
|
|
30943
|
-
continue;
|
|
30944
|
-
}
|
|
30945
|
-
for (const entry of entries2) {
|
|
30946
|
-
if (++entriesSeen > 1e5 || files.length >= MAX_FILES) {
|
|
30947
|
-
limited = true;
|
|
30948
|
-
break;
|
|
30949
|
-
}
|
|
30950
|
-
const file = join4(path, entry.name);
|
|
30951
|
-
if (entry.isDirectory()) {
|
|
30952
|
-
if (depth < 6 && queue.length < MAX_FILES) queue.push({ root: root3, path: file, depth: depth + 1 });
|
|
30953
|
-
else limited = true;
|
|
30954
|
-
}
|
|
30955
|
-
if (entry.isFile() && match2(relative(root3, file).split("\\").join("/"))) files.push(file);
|
|
30956
|
-
}
|
|
30957
|
-
}
|
|
30958
|
-
if (limited) warnings.push("History discovery reached its file, directory, or depth limit.");
|
|
30959
|
-
return { files: [...new Set(files)].sort(), warnings };
|
|
30960
|
-
}
|
|
30961
|
-
function json3(value) {
|
|
30962
|
-
return JSON.parse(value);
|
|
30963
|
-
}
|
|
30964
|
-
function jsonLines(value) {
|
|
30965
|
-
const rows2 = [];
|
|
30966
|
-
let partial = false;
|
|
30967
|
-
for (const line of value.split("\n")) {
|
|
30968
|
-
if (!line.trim()) continue;
|
|
30969
|
-
if (rows2.length >= MAX_RECORDS) throw new Error("History exceeds the 50,000-record limit.");
|
|
30970
|
-
if (line.length > 2e6) throw new Error("History contains a record larger than 2 MB.");
|
|
30971
|
-
try {
|
|
30972
|
-
const row = json3(line);
|
|
30973
|
-
if (!row || typeof row !== "object" || Array.isArray(row)) partial = true;
|
|
30974
|
-
else rows2.push(row);
|
|
30975
|
-
} catch {
|
|
30976
|
-
partial = true;
|
|
30977
|
-
}
|
|
30978
|
-
}
|
|
30979
|
-
return { rows: rows2, partial };
|
|
30980
|
-
}
|
|
30981
|
-
function localFileAdapter(source) {
|
|
30982
|
-
const metadata2 = /* @__PURE__ */ new Map();
|
|
30983
|
-
let cached2;
|
|
30984
|
-
const states = (path) => Promise.all([path, ...source.extras?.(path) || []].map(fileState));
|
|
30985
|
-
const revision2 = (values) => digest([1, ...values.filter((_, i) => i === 0 || source.revisionExtras !== false).map((s) => [s.path, s.signature])]);
|
|
30986
|
-
async function load(path, expected, before) {
|
|
30987
|
-
if (revision2(before) !== expected) throw new Error("Session changed during import; import again.");
|
|
30988
|
-
if (cached2?.path === path && cached2.revision === expected) return cached2.history;
|
|
30989
|
-
if (before[0].signature === "missing") throw new Error("History file is unavailable.");
|
|
30990
|
-
if (before.reduce((n, s) => n + s.size, 0) > MAX_BYTES2) throw new Error("Combined history exceeds the 32 MB snapshot limit.");
|
|
30991
|
-
const files = /* @__PURE__ */ new Map();
|
|
30992
|
-
let expanded = 0;
|
|
30993
|
-
for (const s of before.filter((s2) => s2.signature !== "missing")) {
|
|
30994
|
-
const handle = await open2(s.path, constants3.O_RDONLY | (constants3.O_NOFOLLOW || 0));
|
|
30995
|
-
try {
|
|
30996
|
-
const buffer = Buffer.alloc(s.size + 1);
|
|
30997
|
-
let bytes2 = 0;
|
|
30998
|
-
while (bytes2 < buffer.length) {
|
|
30999
|
-
const part = await handle.read(buffer, bytes2, buffer.length - bytes2, bytes2);
|
|
31000
|
-
if (!part.bytesRead) break;
|
|
31001
|
-
bytes2 += part.bytesRead;
|
|
31002
|
-
}
|
|
31003
|
-
if (bytes2 !== s.size) throw new Error("History changed while reading; import again.");
|
|
31004
|
-
const data = expandHistory(buffer.subarray(0, bytes2), MAX_BYTES2);
|
|
31005
|
-
expanded += data.length;
|
|
31006
|
-
if (expanded > MAX_BYTES2) throw new Error("Expanded history exceeds the 32 MB snapshot limit.");
|
|
31007
|
-
files.set(s.path, data.toString("utf8"));
|
|
31008
|
-
} finally {
|
|
31009
|
-
await handle.close();
|
|
31010
|
-
}
|
|
31011
|
-
}
|
|
31012
|
-
if (digest(await states(path)) !== digest(before)) throw new Error("History changed while reading; import again.");
|
|
31013
|
-
const history = source.parse(path, files);
|
|
31014
|
-
if (!history) return;
|
|
31015
|
-
if (source.capabilities.history && !history.messages.length) throw new Error("No readable conversation.");
|
|
31016
|
-
if (!history.nativeID || history.nativeID.length > 512) throw new Error("History has no supported native session identity.");
|
|
31017
|
-
if (history.messages.length > MAX_RECORDS) throw new Error("History exceeds the 50,000-message limit.");
|
|
31018
|
-
cached2 = { path, revision: expected, history };
|
|
31019
|
-
return history;
|
|
31020
|
-
}
|
|
31021
|
-
return {
|
|
31022
|
-
id: source.id,
|
|
31023
|
-
name: source.name,
|
|
31024
|
-
description: source.description,
|
|
31025
|
-
capabilities: source.capabilities,
|
|
31026
|
-
async detect() {
|
|
31027
|
-
for (const root3 of source.roots()) if ((await lstat2(root3).catch(() => void 0))?.isDirectory()) return true;
|
|
31028
|
-
return false;
|
|
31029
|
-
},
|
|
31030
|
-
async discover() {
|
|
31031
|
-
const listing = await historyFiles(source.roots(), source.match), found = /* @__PURE__ */ new Map();
|
|
31032
|
-
let failed = 0;
|
|
31033
|
-
const blocked = /* @__PURE__ */ new Set(), unreadable = /* @__PURE__ */ new Set();
|
|
31034
|
-
for (const path of listing.files) {
|
|
31035
|
-
try {
|
|
31036
|
-
const before = await states(path), rev = revision2(before);
|
|
31037
|
-
let candidate = metadata2.get(path);
|
|
31038
|
-
if (!candidate || candidate.revision !== rev) {
|
|
31039
|
-
const history = await load(path, rev, before);
|
|
31040
|
-
if (!history) {
|
|
31041
|
-
const nativeID = source.authoritativeIdentity?.(path);
|
|
31042
|
-
if (nativeID) blocked.add(identity(source.id, nativeID));
|
|
31043
|
-
continue;
|
|
31044
|
-
}
|
|
31045
|
-
const session = { ...blankSession(source.id, history.nativeID), ...history.session };
|
|
31046
|
-
session.id = identity(source.id, history.nativeID);
|
|
31047
|
-
session.nativeID = history.nativeID;
|
|
31048
|
-
session.source = source.id;
|
|
31049
|
-
session.directory = text(session.directory);
|
|
31050
|
-
session.projectID = project(source.id, session.directory).id;
|
|
31051
|
-
session.created = time(session.created) || history.messages.map((m) => time(m.time)).find(Boolean) || before[0].created;
|
|
31052
|
-
session.updated = before[0].updated;
|
|
31053
|
-
session.agent ||= source.name;
|
|
31054
|
-
session.parentID = history.parent ? identity(source.id, history.parent) : void 0;
|
|
31055
|
-
session.forkID = history.fork ? identity(source.id, history.fork) : void 0;
|
|
31056
|
-
if (session.title === "Untitled session" || !session.title) session.title = history.messages.flatMap((m) => m.role === "user" ? m.fragments.filter((f) => f.kind === "You").map((f) => f.text) : []).find(Boolean)?.replace(/\s+/g, " ").slice(0, 180) || `${source.name} session`;
|
|
31057
|
-
candidate = { session, revision: rev, locator: { path } };
|
|
31058
|
-
metadata2.set(path, candidate);
|
|
31059
|
-
}
|
|
31060
|
-
const previous = found.get(candidate.session.id);
|
|
31061
|
-
const preferred = candidate.locator.path.endsWith(".jsonl"), previousPreferred = previous?.locator.path.endsWith(".jsonl");
|
|
31062
|
-
if (!previous || preferred && !previousPreferred || preferred === previousPreferred && candidate.session.updated > previous.session.updated) found.set(candidate.session.id, candidate);
|
|
31063
|
-
} catch {
|
|
31064
|
-
const nativeID = source.authoritativeIdentity?.(path);
|
|
31065
|
-
if (nativeID) {
|
|
31066
|
-
const id2 = identity(source.id, nativeID);
|
|
31067
|
-
blocked.add(id2);
|
|
31068
|
-
unreadable.add(id2);
|
|
31069
|
-
} else failed++;
|
|
31070
|
-
}
|
|
31071
|
-
}
|
|
31072
|
-
const listed = new Set(listing.files);
|
|
31073
|
-
for (const path of metadata2.keys()) if (!listed.has(path)) metadata2.delete(path);
|
|
31074
|
-
if (failed) listing.warnings.push(`${source.name}: Skipped ${failed} unreadable, changing, unsupported, or oversized ${failed === 1 ? "history file" : "history files"}.`);
|
|
31075
|
-
const sessions = [...found.values()].filter((c) => !blocked.has(c.session.id));
|
|
31076
|
-
const errors = unreadable.size ? [`${source.name}: Could not read history for ${unreadable.size} ${unreadable.size === 1 ? "session" : "sessions"}.`] : void 0;
|
|
31077
|
-
return { sessions, projects: [...new Map(sessions.map((c) => {
|
|
31078
|
-
const p = project(source.id, c.session.directory);
|
|
31079
|
-
return [p.id, p];
|
|
31080
|
-
})).values()], warnings: listing.warnings, errors, blocked: [...blocked] };
|
|
31081
|
-
},
|
|
31082
|
-
async read(candidate, cursor) {
|
|
31083
|
-
const offset = cursor === void 0 ? 0 : Number(cursor);
|
|
31084
|
-
if (!Number.isSafeInteger(offset) || offset < 0) throw new Error("Invalid history cursor.");
|
|
31085
|
-
const history = await load(candidate.locator.path, candidate.revision, await states(candidate.locator.path));
|
|
31086
|
-
if (!history) throw new Error("History representation is no longer available.");
|
|
31087
|
-
const messages = history.messages.slice(offset, offset + 100);
|
|
31088
|
-
return {
|
|
31089
|
-
messages,
|
|
31090
|
-
cursor: offset + messages.length < history.messages.length ? String(offset + messages.length) : void 0,
|
|
31091
|
-
partial: Boolean(history.partial || messages.some((m) => m.partial)),
|
|
31092
|
-
note: history.note
|
|
31093
|
-
};
|
|
31094
|
-
}
|
|
31095
|
-
};
|
|
31096
|
-
}
|
|
31097
|
-
|
|
31098
31056
|
// server/adapters/harness-formats.ts
|
|
31099
|
-
import { basename as
|
|
31057
|
+
import { basename as basename3, dirname as dirname2, join as join9 } from "node:path";
|
|
31100
31058
|
|
|
31101
31059
|
// server/adapters/local-messages.ts
|
|
31102
31060
|
function conversationMessage(raw, fallbackID) {
|
|
@@ -31177,31 +31135,8 @@ function successfulEdits(messages, editNames) {
|
|
|
31177
31135
|
}
|
|
31178
31136
|
|
|
31179
31137
|
// server/adapters/pi.ts
|
|
31180
|
-
import { homedir as
|
|
31181
|
-
|
|
31182
|
-
// server/source-paths.ts
|
|
31183
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
31184
|
-
var paths = new AsyncLocalStorage();
|
|
31185
|
-
var sourcePath = (id2) => paths.getStore()?.[id2];
|
|
31186
|
-
function withSourcePaths(adapter, configured) {
|
|
31187
|
-
return {
|
|
31188
|
-
...adapter,
|
|
31189
|
-
detect: () => paths.run(configured(), () => adapter.detect()),
|
|
31190
|
-
discover: () => paths.run(configured(), async () => {
|
|
31191
|
-
const result = await adapter.discover();
|
|
31192
|
-
if (!sourcePath(adapter.id)) return result;
|
|
31193
|
-
return { ...result, sessions: result.sessions.map((candidate) => ({ ...candidate, session: { ...candidate.session, nativeResume: false } })) };
|
|
31194
|
-
}),
|
|
31195
|
-
read: (candidate, cursor) => paths.run(configured(), async () => {
|
|
31196
|
-
const result = await adapter.read(candidate, cursor);
|
|
31197
|
-
if (sourcePath(adapter.id)) candidate.session.nativeResume = false;
|
|
31198
|
-
return result;
|
|
31199
|
-
})
|
|
31200
|
-
};
|
|
31201
|
-
}
|
|
31202
|
-
|
|
31203
|
-
// server/adapters/pi.ts
|
|
31204
|
-
import { join as join5 } from "node:path";
|
|
31138
|
+
import { homedir as homedir4 } from "node:os";
|
|
31139
|
+
import { join as join8 } from "node:path";
|
|
31205
31140
|
function piHistory(value) {
|
|
31206
31141
|
const { rows: rows2, partial } = jsonLines(value);
|
|
31207
31142
|
const header = rows2[0];
|
|
@@ -31232,7 +31167,7 @@ var piAdapter = localFileAdapter({
|
|
|
31232
31167
|
name: "Pi",
|
|
31233
31168
|
description: "Local JSONL sessions \xB7 messages, tools, compaction, and branch entries",
|
|
31234
31169
|
capabilities: { history: true, forks: false, children: false, files: true },
|
|
31235
|
-
roots: () => [sourcePath("pi") || process.env.SESSIONGRAPH_PI_SESSIONS_DIR ||
|
|
31170
|
+
roots: () => [sourcePath("pi") || process.env.SESSIONGRAPH_PI_SESSIONS_DIR || join8(process.env.PI_CODING_AGENT_DIR || join8(homedir4(), ".pi", "agent"), "sessions")],
|
|
31236
31171
|
match: (path) => path.endsWith(".jsonl"),
|
|
31237
31172
|
parse(path, files) {
|
|
31238
31173
|
const history = piHistory(files.get(path));
|
|
@@ -31244,7 +31179,7 @@ var piAdapter = localFileAdapter({
|
|
|
31244
31179
|
// server/adapters/harness-formats.ts
|
|
31245
31180
|
var nativeText = (v3) => typeof v3 === "number" && Number.isSafeInteger(v3) ? String(v3) : text(v3);
|
|
31246
31181
|
var seconds = (v3) => typeof v3 === "number" && Number.isFinite(v3) && v3 > 0 ? v3 * 1e3 : time(v3);
|
|
31247
|
-
var fileID = (path) =>
|
|
31182
|
+
var fileID = (path) => basename3(path).replace(/\.jsonl(?:\..*)?$|\.json$/, "");
|
|
31248
31183
|
var sidecar2 = (files, path) => object3(files.has(path) ? json3(files.get(path)) : void 0);
|
|
31249
31184
|
var roles = ["user", "assistant", "system", "tool", "toolResult", "model"];
|
|
31250
31185
|
function message(raw, id2, timestamp) {
|
|
@@ -31321,13 +31256,13 @@ function codebuffHistory(path, files, free) {
|
|
|
31321
31256
|
const m = message({ ...r, role: r.role || r.type, content }, text(r.id) || `message:${i}`);
|
|
31322
31257
|
return m ? [m] : [];
|
|
31323
31258
|
});
|
|
31324
|
-
const chat =
|
|
31259
|
+
const chat = basename3(dirname2(path)), project2 = basename3(dirname2(dirname2(dirname2(path))));
|
|
31325
31260
|
return { nativeID: `${project2}/${chat}`, messages, partial: true };
|
|
31326
31261
|
}
|
|
31327
31262
|
function vibeHistory(path, files) {
|
|
31328
|
-
const raw = object3(json3(files.get(path))), legacy =
|
|
31263
|
+
const raw = object3(json3(files.get(path))), legacy = basename3(path) !== "meta.json";
|
|
31329
31264
|
const meta = legacy ? object3(raw.metadata) : raw;
|
|
31330
|
-
const transcript =
|
|
31265
|
+
const transcript = join9(dirname2(path), "messages.jsonl");
|
|
31331
31266
|
const parsed = files.has(transcript) ? jsonLines(files.get(transcript)) : { rows: [], partial: false };
|
|
31332
31267
|
const records = legacy ? raw.messages : parsed.rows;
|
|
31333
31268
|
if (!text(meta.session_id) || !Array.isArray(records)) throw new Error("Unsupported Vibe session.");
|
|
@@ -31398,352 +31333,141 @@ function dshHistory(value) {
|
|
|
31398
31333
|
return { nativeID: header.id, messages, partial: true, session: { directory: text(header.cwd), created: time(header.createdAt ?? header.time) }, note: partial ? "Some transcript records could not be imported." : void 0 };
|
|
31399
31334
|
}
|
|
31400
31335
|
|
|
31401
|
-
// server/adapters/
|
|
31402
|
-
import { lstat as
|
|
31403
|
-
|
|
31404
|
-
|
|
31405
|
-
|
|
31406
|
-
|
|
31407
|
-
|
|
31408
|
-
|
|
31409
|
-
|
|
31410
|
-
|
|
31411
|
-
|
|
31412
|
-
|
|
31413
|
-
|
|
31414
|
-
};
|
|
31415
|
-
var close = (path) => {
|
|
31416
|
-
const copy = copies.get(path);
|
|
31417
|
-
if (!copy) return;
|
|
31418
|
-
copies.delete(path);
|
|
31419
|
-
try {
|
|
31420
|
-
copy.db.close();
|
|
31421
|
-
} finally {
|
|
31422
|
-
rmSync2(copy.directory, { recursive: true, force: true });
|
|
31423
|
-
}
|
|
31424
|
-
};
|
|
31425
|
-
process.once("exit", () => {
|
|
31426
|
-
for (const path of copies.keys()) close(path);
|
|
31427
|
-
});
|
|
31428
|
-
function snapshotFiles(path, large) {
|
|
31429
|
-
return [path, `${path}-wal`].map((file, i) => {
|
|
31430
|
-
try {
|
|
31431
|
-
const s = lstatSync2(file);
|
|
31432
|
-
const kind = i ? "History database WAL" : "History database";
|
|
31433
|
-
if (!s.isFile()) throw new SqliteSnapshotFileError(`${kind} is not a regular file.`);
|
|
31434
|
-
if (!large && s.size > 8e9) throw new SqliteSnapshotFileError(`${kind} exceeds 8 GB.`);
|
|
31435
|
-
return s;
|
|
31436
|
-
} catch (error) {
|
|
31437
|
-
if (i && error.code === "ENOENT") return null;
|
|
31438
|
-
throw error;
|
|
31439
|
-
}
|
|
31440
|
-
});
|
|
31441
|
-
}
|
|
31442
|
-
var fingerprint = (path, files) => digest([path, ...files.map((s) => s && [s.dev, s.ino, s.size, s.mtimeMs, s.ctimeMs])]);
|
|
31443
|
-
function sqliteRevision(path) {
|
|
31444
|
-
return fingerprint(path, snapshotFiles(path, false));
|
|
31445
|
-
}
|
|
31446
|
-
function openSnapshot(destination) {
|
|
31447
|
-
const db2 = new DatabaseSync(destination, { readOnly: true, enableDoubleQuotedStringLiterals: false, allowExtension: false });
|
|
31448
|
-
try {
|
|
31449
|
-
db2.exec("PRAGMA query_only=ON; PRAGMA trusted_schema=OFF; PRAGMA busy_timeout=1000; BEGIN;");
|
|
31450
|
-
return db2;
|
|
31451
|
-
} catch (error) {
|
|
31452
|
-
db2.close();
|
|
31453
|
-
throw error;
|
|
31454
|
-
}
|
|
31336
|
+
// server/adapters/claude-locations.ts
|
|
31337
|
+
import { lstat as lstat5, opendir } from "node:fs/promises";
|
|
31338
|
+
import { homedir as homedir5 } from "node:os";
|
|
31339
|
+
import { basename as basename4, dirname as dirname3, join as join10, resolve as resolve2 } from "node:path";
|
|
31340
|
+
async function computerRoots(platform = process.platform) {
|
|
31341
|
+
if (platform !== "win32") return ["/"];
|
|
31342
|
+
const drives = Array.from({ length: 26 }, (_, i) => `${String.fromCharCode(65 + i)}:\\`);
|
|
31343
|
+
return (await Promise.all(drives.map(async (drive) => (await lstat5(drive).catch(() => void 0))?.isDirectory() ? drive : void 0))).filter((p) => Boolean(p));
|
|
31344
|
+
}
|
|
31345
|
+
function excludedScanPaths(platform = process.platform) {
|
|
31346
|
+
if (platform === "linux") return ["/dev", "/proc", "/sys", "/run"];
|
|
31347
|
+
if (platform === "darwin") return ["/dev", "/System/Volumes"];
|
|
31348
|
+
return [];
|
|
31455
31349
|
}
|
|
31456
|
-
|
|
31457
|
-
const
|
|
31458
|
-
|
|
31459
|
-
const
|
|
31460
|
-
|
|
31461
|
-
|
|
31462
|
-
|
|
31463
|
-
|
|
31464
|
-
|
|
31465
|
-
|
|
31466
|
-
|
|
31467
|
-
|
|
31468
|
-
|
|
31469
|
-
|
|
31470
|
-
|
|
31471
|
-
|
|
31472
|
-
|
|
31473
|
-
|
|
31474
|
-
|
|
31350
|
+
function createClaudeLocationScanner(options) {
|
|
31351
|
+
const now = options.now || Date.now, openDirectory = options.openDirectory || opendir;
|
|
31352
|
+
const excluded = new Set((options.excluded || []).map((p) => resolve2(p)));
|
|
31353
|
+
const homes2 = /* @__PURE__ */ new Set();
|
|
31354
|
+
let queue = [], index = 0;
|
|
31355
|
+
let visited = /* @__PURE__ */ new Set(), skipped = /* @__PURE__ */ new Set(), limited = false, initialized = false, finishedAt;
|
|
31356
|
+
let last, lastAt = -Infinity, job;
|
|
31357
|
+
async function scan() {
|
|
31358
|
+
const started = now();
|
|
31359
|
+
if (!initialized || finishedAt !== void 0 && started - finishedAt >= (options.refreshMs ?? 3e5)) {
|
|
31360
|
+
queue = [.../* @__PURE__ */ new Set([dirname3(options.preferredHome()), ...await options.roots()])].map((path) => ({ path: resolve2(path), depth: 0, offset: 0 }));
|
|
31361
|
+
index = 0;
|
|
31362
|
+
visited = /* @__PURE__ */ new Set();
|
|
31363
|
+
skipped = /* @__PURE__ */ new Set();
|
|
31364
|
+
limited = false;
|
|
31365
|
+
initialized = true;
|
|
31366
|
+
finishedAt = void 0;
|
|
31367
|
+
}
|
|
31368
|
+
homes2.add(resolve2(options.preferredHome()));
|
|
31369
|
+
let entries2 = 0;
|
|
31370
|
+
const budget2 = options.maxEntries ?? 1e5, deadline = started + (options.sliceMs ?? 2e3);
|
|
31371
|
+
while (index < queue.length && entries2 < budget2 && now() < deadline) {
|
|
31372
|
+
const item = queue[index], path = item.path;
|
|
31373
|
+
if (excluded.has(path)) {
|
|
31374
|
+
index++;
|
|
31375
|
+
continue;
|
|
31376
|
+
}
|
|
31377
|
+
let complete = true;
|
|
31475
31378
|
try {
|
|
31476
|
-
await
|
|
31379
|
+
const info = await lstat5(path);
|
|
31380
|
+
if (!info.isDirectory()) {
|
|
31381
|
+
index++;
|
|
31382
|
+
continue;
|
|
31383
|
+
}
|
|
31384
|
+
const key = `${info.dev}:${info.ino}`;
|
|
31385
|
+
if (!item.offset && visited.has(key)) {
|
|
31386
|
+
index++;
|
|
31387
|
+
continue;
|
|
31388
|
+
}
|
|
31389
|
+
let offset = 0;
|
|
31390
|
+
for await (const entry of await openDirectory(path)) {
|
|
31391
|
+
if (offset++ < item.offset) continue;
|
|
31392
|
+
if (entry.isDirectory()) {
|
|
31393
|
+
const child = join10(path, entry.name);
|
|
31394
|
+
if (entry.name === ".claude") addHome(child);
|
|
31395
|
+
if (item.depth < 128 && queue.length < 1e5) queue.push({ path: child, depth: item.depth + 1, offset: 0 });
|
|
31396
|
+
else limited = true;
|
|
31397
|
+
} else if (entry.isFile() && entry.name.endsWith(".jsonl") && claudeSessionID(entry.name.slice(0, -6)) && basename4(dirname3(path)) === "projects") {
|
|
31398
|
+
addHome(dirname3(dirname3(path)));
|
|
31399
|
+
}
|
|
31400
|
+
entries2++;
|
|
31401
|
+
item.offset = offset;
|
|
31402
|
+
if (entries2 >= budget2 || now() >= deadline) {
|
|
31403
|
+
complete = false;
|
|
31404
|
+
break;
|
|
31405
|
+
}
|
|
31406
|
+
}
|
|
31407
|
+
if (complete) visited.add(key);
|
|
31477
31408
|
} catch (error) {
|
|
31478
|
-
if (!["
|
|
31479
|
-
const { bavail, bsize } = await statfs(directory3);
|
|
31480
|
-
const reserve = 512 * 1024 * 1024;
|
|
31481
|
-
if (bavail * bsize < file.size + reserve) throw new Error("Not enough free space for the T3 history snapshot. Free space on the temporary drive and retry.");
|
|
31482
|
-
await copyFile(path + suffix, destination + suffix);
|
|
31409
|
+
if (!["ENOENT", "ENOTDIR"].includes(error.code || "")) skipped.add(path);
|
|
31483
31410
|
}
|
|
31484
|
-
|
|
31485
|
-
|
|
31486
|
-
if (fingerprint(path, snapshotFiles(path, true)) !== revision2) throw new SqliteSnapshotChangedError("History database changed while copying; import again.");
|
|
31487
|
-
db2 = openSnapshot(destination);
|
|
31488
|
-
const result = read3(db2, revision2);
|
|
31489
|
-
if (!expected && fingerprint(path, snapshotFiles(path, true)) !== revision2) throw new SqliteSnapshotChangedError("History database changed during reading; import again.");
|
|
31490
|
-
close(path);
|
|
31491
|
-
while (copies.size >= 2) close(copies.keys().next().value);
|
|
31492
|
-
copies.set(path, { revision: revision2, directory: directory3, db: db2 });
|
|
31493
|
-
return result;
|
|
31494
|
-
} catch (error) {
|
|
31495
|
-
try {
|
|
31496
|
-
db2?.close();
|
|
31497
|
-
} finally {
|
|
31498
|
-
rmSync2(directory3, { recursive: true, force: true });
|
|
31411
|
+
if (!complete) break;
|
|
31412
|
+
index++;
|
|
31499
31413
|
}
|
|
31500
|
-
|
|
31501
|
-
|
|
31502
|
-
|
|
31503
|
-
|
|
31504
|
-
}
|
|
31505
|
-
function withSqliteSnapshot(path, read3, expected, pinned = false) {
|
|
31506
|
-
const retained = copies.get(path);
|
|
31507
|
-
if (pinned && expected && retained?.revision === expected) return read3(retained.db);
|
|
31508
|
-
const revision2 = sqliteRevision(path);
|
|
31509
|
-
if (expected && revision2 !== expected) throw new SqliteSnapshotChangedError("History database changed during import; import again.");
|
|
31510
|
-
let copy = copies.get(path);
|
|
31511
|
-
if (copy?.revision !== revision2) {
|
|
31512
|
-
close(path);
|
|
31513
|
-
while (copies.size >= 2) close(copies.keys().next().value);
|
|
31514
|
-
const directory3 = mkdtempSync(join7(tmpdir(), "sessiongraph-history-"));
|
|
31515
|
-
let db2;
|
|
31516
|
-
try {
|
|
31517
|
-
chmodSync(directory3, 448);
|
|
31518
|
-
const destination = join7(directory3, "history.db");
|
|
31519
|
-
for (const suffix of ["", "-wal"]) {
|
|
31520
|
-
try {
|
|
31521
|
-
copyFileSync(path + suffix, destination + suffix, constants4.COPYFILE_FICLONE);
|
|
31522
|
-
chmodSync(destination + suffix, 384);
|
|
31523
|
-
} catch (error) {
|
|
31524
|
-
if (suffix && error.code === "ENOENT") continue;
|
|
31525
|
-
throw error;
|
|
31526
|
-
}
|
|
31527
|
-
}
|
|
31528
|
-
if (sqliteRevision(path) !== revision2) throw new SqliteSnapshotChangedError("History database changed while copying; import again.");
|
|
31529
|
-
db2 = openSnapshot(destination);
|
|
31530
|
-
copy = { revision: revision2, directory: directory3, db: db2 };
|
|
31531
|
-
copies.set(path, copy);
|
|
31532
|
-
} catch (error) {
|
|
31414
|
+
const pending = index < queue.length;
|
|
31415
|
+
if (!pending && finishedAt === void 0) finishedAt = now();
|
|
31416
|
+
const found = [];
|
|
31417
|
+
for (const home of homes2) {
|
|
31533
31418
|
try {
|
|
31534
|
-
|
|
31535
|
-
}
|
|
31536
|
-
|
|
31419
|
+
if (!(await lstat5(home)).isDirectory()) continue;
|
|
31420
|
+
} catch (error) {
|
|
31421
|
+
if (error.code !== "ENOENT") skipped.add(home);
|
|
31422
|
+
continue;
|
|
31537
31423
|
}
|
|
31538
|
-
|
|
31539
|
-
}
|
|
31540
|
-
}
|
|
31541
|
-
const result = read3(copy.db);
|
|
31542
|
-
if (!pinned && sqliteRevision(path) !== revision2) throw new SqliteSnapshotChangedError("History database changed during reading; import again.");
|
|
31543
|
-
return result;
|
|
31544
|
-
}
|
|
31545
|
-
function hasTable(db2, name) {
|
|
31546
|
-
const row = db2.prepare("SELECT sql FROM sqlite_master WHERE type='table' AND name=?").get(name);
|
|
31547
|
-
return typeof row?.sql === "string" && !/CREATE\s+VIRTUAL/i.test(row.sql);
|
|
31548
|
-
}
|
|
31549
|
-
|
|
31550
|
-
// server/adapters/sqlite-histories.ts
|
|
31551
|
-
var budget;
|
|
31552
|
-
var rowBytes = (row) => Object.values(row).reduce((n, v3) => n + (typeof v3 === "string" ? Buffer.byteLength(v3) : v3 instanceof Uint8Array ? v3.byteLength : 8), 0);
|
|
31553
|
-
function consume(bytes2, records = 0) {
|
|
31554
|
-
if (!budget) return;
|
|
31555
|
-
budget.bytes += bytes2;
|
|
31556
|
-
budget.records += records;
|
|
31557
|
-
if (budget.bytes > 64e6 || budget.records > 5e4) throw new Error("Session exceeds the 64 MB / 50,000-record snapshot limit.");
|
|
31558
|
-
}
|
|
31559
|
-
function parseHistory(source, db2, row, path) {
|
|
31560
|
-
const previous = budget;
|
|
31561
|
-
budget = { bytes: 0, records: 0 };
|
|
31562
|
-
try {
|
|
31563
|
-
consume(rowBytes(row), 1);
|
|
31564
|
-
const history = source.parse(db2, row, path);
|
|
31565
|
-
if (history && history.messages.length > 5e4) throw new Error("Session exceeds the 50,000-message limit.");
|
|
31566
|
-
return history;
|
|
31567
|
-
} finally {
|
|
31568
|
-
budget = previous;
|
|
31569
|
-
}
|
|
31570
|
-
}
|
|
31571
|
-
function columns(db2, table) {
|
|
31572
|
-
if (!/^[a-z_][a-z0-9_]*$/.test(table) || !hasTable(db2, table)) throw new Error(`Unsupported history table: ${table}.`);
|
|
31573
|
-
return new Set(db2.prepare(`PRAGMA table_info("${table}")`).all().map((r) => String(r.name)));
|
|
31574
|
-
}
|
|
31575
|
-
function rows(db2, table, fields3, filter, order, limit = 5e4) {
|
|
31576
|
-
const available = columns(db2, table);
|
|
31577
|
-
for (const name of [...fields3, ...filter ? [filter[0]] : [], ...order ? [order] : []]) if (!/^[a-zA-Z_][\w]*$/.test(name)) throw new Error("Invalid history column.");
|
|
31578
|
-
if (filter && !available.has(filter[0])) throw new Error("Unsupported history relation.");
|
|
31579
|
-
const size = (f) => `length(CAST("${f}" AS BLOB))`;
|
|
31580
|
-
const select = fields3.map((f) => available.has(f) ? `CASE WHEN ${size(f)}<=32000000 THEN "${f}" END AS "${f}"` : `NULL AS "${f}"`).join(",");
|
|
31581
|
-
const oversized = fields3.filter((f) => available.has(f)).map((f) => `COALESCE(${size(f)},0)>32000000`).join(" OR ") || "0";
|
|
31582
|
-
const query = `SELECT ${select}, (${oversized}) AS __sessiongraph_oversized FROM "${table}"${filter ? ` WHERE "${filter[0]}"=?` : ""}${order && available.has(order) ? ` ORDER BY "${order}"` : ""} LIMIT ${limit + 1}`;
|
|
31583
|
-
const result = [];
|
|
31584
|
-
let bytes2 = 0;
|
|
31585
|
-
for (const row of db2.prepare(query).iterate(...filter ? [filter[1]] : [])) {
|
|
31586
|
-
if (row.__sessiongraph_oversized) throw new Error("History field exceeds the 32 MB snapshot limit.");
|
|
31587
|
-
delete row.__sessiongraph_oversized;
|
|
31588
|
-
const size2 = rowBytes(row);
|
|
31589
|
-
bytes2 += size2;
|
|
31590
|
-
consume(size2, 1);
|
|
31591
|
-
if (bytes2 > 64e6 || result.length >= limit) throw new Error("History exceeds the 64 MB / record-count query limit.");
|
|
31592
|
-
result.push(row);
|
|
31593
|
-
}
|
|
31594
|
-
return result;
|
|
31595
|
-
}
|
|
31596
|
-
function sqliteJSON(value) {
|
|
31597
|
-
if (value instanceof Uint8Array) {
|
|
31598
|
-
const expanded = expandHistory(Buffer.from(value), Math.max(1, Math.min(32e6, 64e6 - (budget?.bytes || 0))));
|
|
31599
|
-
consume(expanded.byteLength);
|
|
31600
|
-
return JSON.parse(expanded.toString("utf8"));
|
|
31601
|
-
}
|
|
31602
|
-
if (typeof value === "string") return JSON.parse(value);
|
|
31603
|
-
throw new Error("Missing or oversized history payload.");
|
|
31604
|
-
}
|
|
31605
|
-
function optionalJSON(value) {
|
|
31606
|
-
return value == null || value === "" ? {} : sqliteJSON(value);
|
|
31607
|
-
}
|
|
31608
|
-
function sqliteHistoryAdapter(source) {
|
|
31609
|
-
const metadata2 = /* @__PURE__ */ new Map();
|
|
31610
|
-
return {
|
|
31611
|
-
id: source.id,
|
|
31612
|
-
name: source.name,
|
|
31613
|
-
description: source.description || "Local session database",
|
|
31614
|
-
capabilities: { history: source.history !== false, forks: false, children: false, files: false },
|
|
31615
|
-
async detect() {
|
|
31616
|
-
return (await source.paths()).length > 0;
|
|
31617
|
-
},
|
|
31618
|
-
async discover() {
|
|
31619
|
-
const sessions = /* @__PURE__ */ new Map(), errors = [], blocked = [];
|
|
31620
|
-
let unavailable = false;
|
|
31621
|
-
for (const path of await source.paths()) {
|
|
31424
|
+
for (const name of ["projects", "transcripts"]) {
|
|
31622
31425
|
try {
|
|
31623
|
-
|
|
31624
|
-
|
|
31625
|
-
|
|
31626
|
-
cached2 = withSqliteSnapshot(path, (db2) => {
|
|
31627
|
-
const table = typeof source.table === "string" ? source.table : source.table(db2);
|
|
31628
|
-
const values2 = rows(db2, table, source.fields, void 0, source.key, 2e4), found = [];
|
|
31629
|
-
const blocked2 = [], errors2 = [];
|
|
31630
|
-
let failed = 0;
|
|
31631
|
-
for (const row of values2) {
|
|
31632
|
-
try {
|
|
31633
|
-
const h3 = parseHistory(source, db2, row, path);
|
|
31634
|
-
if (!h3) continue;
|
|
31635
|
-
if (source.history !== false && !h3.messages.length) {
|
|
31636
|
-
blocked2.push(identity(source.id, String(row[source.key])));
|
|
31637
|
-
continue;
|
|
31638
|
-
}
|
|
31639
|
-
if (!h3.nativeID || h3.nativeID.length > 512) throw new Error("Missing native session identity.");
|
|
31640
|
-
const created = time(h3.session?.created) || h3.messages.map((m) => time(m.time)).find(Boolean);
|
|
31641
|
-
if (!created) throw new Error("Session has no recorded creation or message date.");
|
|
31642
|
-
const session = { ...blankSession(source.id, h3.nativeID), ...h3.session, created };
|
|
31643
|
-
session.id = identity(source.id, h3.nativeID);
|
|
31644
|
-
session.nativeID = h3.nativeID;
|
|
31645
|
-
session.source = source.id;
|
|
31646
|
-
session.directory = text(session.directory);
|
|
31647
|
-
session.projectID = project(source.id, session.directory).id;
|
|
31648
|
-
session.agent ||= source.name;
|
|
31649
|
-
session.updated ||= created;
|
|
31650
|
-
session.parentID = h3.parent ? identity(source.id, h3.parent) : void 0;
|
|
31651
|
-
session.forkID = h3.fork ? identity(source.id, h3.fork) : void 0;
|
|
31652
|
-
if (!session.title || session.title === "Untitled session") session.title = h3.messages.flatMap((m) => m.role === "user" ? m.fragments.filter((f) => f.kind === "You").map((f) => f.text) : []).find(Boolean)?.replace(/\s+/g, " ").slice(0, 180) || `${source.name} session`;
|
|
31653
|
-
found.push({ session, revision: rev, locator: { path, snapshot: snapshot2, table, key: String(row[source.key]) } });
|
|
31654
|
-
} catch {
|
|
31655
|
-
blocked2.push(identity(source.id, String(row[source.key])));
|
|
31656
|
-
failed++;
|
|
31657
|
-
}
|
|
31658
|
-
}
|
|
31659
|
-
if (failed) errors2.push(`${source.name}: Skipped ${failed} unreadable, undated, unsupported, or oversized ${failed === 1 ? "session" : "sessions"}.`);
|
|
31660
|
-
return { revision: rev, candidates: found, blocked: blocked2, errors: errors2 };
|
|
31661
|
-
}, snapshot2);
|
|
31662
|
-
metadata2.set(path, cached2);
|
|
31663
|
-
}
|
|
31664
|
-
errors.push(...cached2.errors);
|
|
31665
|
-
blocked.push(...cached2.blocked);
|
|
31666
|
-
for (const c of cached2.candidates) {
|
|
31667
|
-
const old = sessions.get(c.session.id);
|
|
31668
|
-
if (!old || c.session.updated > old.session.updated) sessions.set(c.session.id, c);
|
|
31426
|
+
if ((await lstat5(join10(home, name))).isDirectory()) {
|
|
31427
|
+
found.push(home);
|
|
31428
|
+
break;
|
|
31669
31429
|
}
|
|
31670
31430
|
} catch (error) {
|
|
31671
|
-
|
|
31672
|
-
const detail = error instanceof SqliteSnapshotFileError || error instanceof SqliteSnapshotChangedError ? error.message : "Could not read a history database.";
|
|
31673
|
-
errors.push(`${source.name}: ${detail}`);
|
|
31431
|
+
if (!["ENOENT", "ENOTDIR"].includes(error.code || "")) skipped.add(join10(home, name));
|
|
31674
31432
|
}
|
|
31675
31433
|
}
|
|
31676
|
-
const values = [...sessions.values()];
|
|
31677
|
-
return { sessions: values, projects: [...new Map(values.map((c) => {
|
|
31678
|
-
const p = project(source.id, c.session.directory);
|
|
31679
|
-
return [p.id, p];
|
|
31680
|
-
})).values()], warnings: [], errors, blocked, unavailable };
|
|
31681
|
-
},
|
|
31682
|
-
async read(candidate, cursor) {
|
|
31683
|
-
if (cursor) throw new Error("Invalid SQLite history cursor.");
|
|
31684
|
-
const { path, snapshot: snapshot2, key } = candidate.locator;
|
|
31685
|
-
return withSqliteSnapshot(path, (db2) => {
|
|
31686
|
-
const table = typeof source.table === "string" ? source.table : source.table(db2);
|
|
31687
|
-
const row = rows(db2, table, source.fields, [source.key, key], void 0, 1)[0];
|
|
31688
|
-
if (!row) throw new Error("Session metadata is unavailable.");
|
|
31689
|
-
const history = parseHistory(source, db2, row, path);
|
|
31690
|
-
if (!history || history.nativeID !== candidate.session.nativeID) throw new Error("Session identity changed.");
|
|
31691
|
-
if (source.history !== false && !history.messages.length) throw new Error("No readable conversation.");
|
|
31692
|
-
return { messages: history.messages, partial: Boolean(history.partial || history.messages.some((m) => m.partial)), note: history.note };
|
|
31693
|
-
}, snapshot2);
|
|
31694
|
-
}
|
|
31695
|
-
};
|
|
31696
|
-
}
|
|
31697
|
-
async function existingDatabases(paths2) {
|
|
31698
|
-
const found = [];
|
|
31699
|
-
for (const path of new Set(paths2)) {
|
|
31700
|
-
try {
|
|
31701
|
-
if ((await lstat3(path)).isFile()) found.push(path);
|
|
31702
|
-
} catch (e10) {
|
|
31703
|
-
if (e10.code !== "ENOENT") throw e10;
|
|
31704
31434
|
}
|
|
31435
|
+
const warnings = [];
|
|
31436
|
+
if (pending) warnings.push("Claude Code: Computer-wide history search is still in progress. Refresh sessions to continue; known locations are imported now.");
|
|
31437
|
+
if (skipped.size) warnings.push(`Claude Code: Computer-wide search skipped ${skipped.size} unreadable or protected locations. OS permissions were not changed; use an accessible copy or a custom history path for missing sessions.`);
|
|
31438
|
+
if (limited) warnings.push("Claude Code: Computer-wide search reached its 100,000-directory, 1,000-location, or 128-level depth limit. Use a custom history path for locations outside this scan.");
|
|
31439
|
+
return { homes: found, warnings, pending };
|
|
31705
31440
|
}
|
|
31706
|
-
|
|
31707
|
-
|
|
31708
|
-
|
|
31709
|
-
|
|
31710
|
-
return {
|
|
31711
|
-
|
|
31712
|
-
|
|
31713
|
-
|
|
31714
|
-
|
|
31715
|
-
|
|
31716
|
-
|
|
31717
|
-
|
|
31718
|
-
|
|
31719
|
-
|
|
31720
|
-
|
|
31721
|
-
if (!await part.detect()) continue;
|
|
31722
|
-
result = await part.discover();
|
|
31723
|
-
} catch {
|
|
31724
|
-
errors.push(`${part.name}: Could not read a history source.`);
|
|
31725
|
-
break;
|
|
31726
|
-
}
|
|
31727
|
-
warnings.push(...result.warnings);
|
|
31728
|
-
if (result.errors?.length) errors.push(...result.errors);
|
|
31729
|
-
else if (result.unavailable) errors.push(`${part.name}: History unavailable.`);
|
|
31730
|
-
for (const id2 of result.blocked || []) blocked.add(id2);
|
|
31731
|
-
for (const p of result.projects) projects.set(p.id, p);
|
|
31732
|
-
for (const c of result.sessions) if (!blocked.has(c.session.id) && !sessions.has(c.session.id)) sessions.set(c.session.id, { ...c, revision: digest([i, c.revision]), locator: { ...c.locator, representation: String(i), originalRevision: c.revision } });
|
|
31733
|
-
if (result.unavailable) break;
|
|
31734
|
-
}
|
|
31735
|
-
return { sessions: [...sessions.values()], projects: [...projects.values()], warnings, errors };
|
|
31736
|
-
},
|
|
31737
|
-
async read(candidate, cursor) {
|
|
31738
|
-
const index = Number(candidate.locator.representation);
|
|
31739
|
-
if (!Number.isInteger(index) || !parts[index]) throw new Error("Invalid history representation.");
|
|
31740
|
-
return parts[index].read({ ...candidate, revision: candidate.locator.originalRevision }, cursor);
|
|
31741
|
-
}
|
|
31441
|
+
function addHome(home) {
|
|
31442
|
+
if (homes2.size < 1e3) homes2.add(home);
|
|
31443
|
+
else limited = true;
|
|
31444
|
+
}
|
|
31445
|
+
return () => {
|
|
31446
|
+
if (job) return job;
|
|
31447
|
+
if (last && now() - lastAt < 1e3) return Promise.resolve(last);
|
|
31448
|
+
job = scan().then((result) => {
|
|
31449
|
+
last = result;
|
|
31450
|
+
lastAt = now();
|
|
31451
|
+
return result;
|
|
31452
|
+
}).finally(() => {
|
|
31453
|
+
job = void 0;
|
|
31454
|
+
});
|
|
31455
|
+
return job;
|
|
31742
31456
|
};
|
|
31743
31457
|
}
|
|
31458
|
+
var activeClaudeHome = () => resolve2(process.env.CLAUDE_CONFIG_DIR || join10(homedir5(), ".claude"));
|
|
31459
|
+
var scanComputer = createClaudeLocationScanner({
|
|
31460
|
+
roots: computerRoots,
|
|
31461
|
+
preferredHome: activeClaudeHome,
|
|
31462
|
+
excluded: excludedScanPaths()
|
|
31463
|
+
});
|
|
31464
|
+
async function claudeLocations() {
|
|
31465
|
+
const configured = sourcePath("claude-code") || process.env.CLAUDE_CONFIG_DIR;
|
|
31466
|
+
if (configured) return { homes: [resolve2(configured)], warnings: [], pending: false };
|
|
31467
|
+
return scanComputer();
|
|
31468
|
+
}
|
|
31744
31469
|
|
|
31745
31470
|
// server/adapters/claude.ts
|
|
31746
|
-
var root = () => join8(sourcePath("claude-code") || process.env.CLAUDE_CONFIG_DIR || join8(homedir4(), ".claude"), "projects");
|
|
31747
31471
|
function claudeMessages(rows2, candidate, times, entries2) {
|
|
31748
31472
|
const calls = /* @__PURE__ */ new Map();
|
|
31749
31473
|
return rows2.map((row) => {
|
|
@@ -31787,64 +31511,61 @@ function claudeMessages(rows2, candidate, times, entries2) {
|
|
|
31787
31511
|
return msg;
|
|
31788
31512
|
});
|
|
31789
31513
|
}
|
|
31514
|
+
var context = new AsyncLocalStorage2();
|
|
31515
|
+
var homes = () => context.getStore()?.homes || [];
|
|
31516
|
+
var activeHome = () => context.getStore()?.activeHome || activeClaudeHome();
|
|
31517
|
+
var metadata = /* @__PURE__ */ new Map();
|
|
31790
31518
|
var sdkClaudeAdapter = {
|
|
31791
31519
|
id: "claude-code",
|
|
31792
31520
|
name: "Claude Code",
|
|
31793
|
-
description: "
|
|
31521
|
+
description: "Computer-wide local CLI and VS Code history \xB7 all projects and subagent transcripts",
|
|
31794
31522
|
capabilities: { history: true, forks: false, children: true, files: true },
|
|
31795
31523
|
async detect() {
|
|
31796
|
-
|
|
31797
|
-
|
|
31798
|
-
} catch {
|
|
31799
|
-
return false;
|
|
31800
|
-
}
|
|
31524
|
+
for (const home of homes()) if ((await lstat6(join11(home, "projects")).catch(() => void 0))?.isDirectory()) return true;
|
|
31525
|
+
return false;
|
|
31801
31526
|
},
|
|
31802
31527
|
async discover() {
|
|
31803
31528
|
const sessions = [], warnings = [];
|
|
31804
|
-
const
|
|
31805
|
-
|
|
31529
|
+
const listing = await historyFiles(homes().map((home) => join11(home, "projects")), (p) => {
|
|
31530
|
+
const parts = p.split("/");
|
|
31531
|
+
return parts.length === 2 && parts[1].endsWith(".jsonl") && claudeSessionID(parts[1].slice(0, -6));
|
|
31532
|
+
});
|
|
31533
|
+
warnings.push(...listing.warnings);
|
|
31806
31534
|
const files = /* @__PURE__ */ new Map();
|
|
31807
31535
|
let unreadable = 0;
|
|
31808
|
-
for (const
|
|
31809
|
-
|
|
31810
|
-
const
|
|
31811
|
-
let entries2;
|
|
31536
|
+
for (const path of listing.files) {
|
|
31537
|
+
const name = basename5(path);
|
|
31538
|
+
const id2 = name.slice(0, -6), home = dirname4(dirname4(dirname4(path)));
|
|
31812
31539
|
try {
|
|
31813
|
-
|
|
31540
|
+
const modified = (await stat(path)).mtimeMs, old = files.get(id2);
|
|
31541
|
+
if (!old || modified > old.modified || modified === old.modified && home === resolve3(activeHome()) && old.home !== home) files.set(id2, { path, home, modified, children: join11(dirname4(path), id2, "subagents") });
|
|
31814
31542
|
} catch {
|
|
31815
31543
|
unreadable++;
|
|
31816
|
-
continue;
|
|
31817
|
-
}
|
|
31818
|
-
for (const file of entries2) if (file.isFile() && file.name.endsWith(".jsonl") && claudeSessionID(file.name.slice(0, -6))) {
|
|
31819
|
-
const id2 = file.name.slice(0, -6), path = join8(parent2, file.name);
|
|
31820
|
-
try {
|
|
31821
|
-
const old = files.get(id2);
|
|
31822
|
-
if (!old || (await stat(path)).mtimeMs > (await stat(old.path)).mtimeMs) files.set(id2, { path, children: join8(parent2, id2, "subagents") });
|
|
31823
|
-
} catch {
|
|
31824
|
-
unreadable++;
|
|
31825
|
-
}
|
|
31826
31544
|
}
|
|
31827
31545
|
}
|
|
31828
|
-
const listed = new Set(infos.map((info) => info.sessionId));
|
|
31829
31546
|
for (const [id2, file] of files) {
|
|
31830
|
-
|
|
31831
|
-
if (infos.length >= 2e4) {
|
|
31832
|
-
warnings.push("Claude Code discovery is limited to 20,000 sessions.");
|
|
31833
|
-
break;
|
|
31834
|
-
}
|
|
31547
|
+
let info;
|
|
31835
31548
|
try {
|
|
31836
|
-
const
|
|
31837
|
-
|
|
31838
|
-
if (
|
|
31839
|
-
|
|
31549
|
+
const rev = await claudeRevision(file.path);
|
|
31550
|
+
let cached2 = metadata.get(file.path);
|
|
31551
|
+
if (!cached2 || cached2.revision !== rev) {
|
|
31552
|
+
const transcript = await claudeTranscript(file.path, rev);
|
|
31553
|
+
cached2 = { revision: rev, info: claudeTranscriptInfo(transcript, id2), partial: transcript.partial };
|
|
31554
|
+
if (metadata.size >= 2e4) metadata.delete(metadata.keys().next().value);
|
|
31555
|
+
metadata.set(file.path, cached2);
|
|
31556
|
+
}
|
|
31557
|
+
info = cached2.info;
|
|
31558
|
+
if (!info && cached2.partial) unreadable++;
|
|
31840
31559
|
} catch {
|
|
31841
31560
|
unreadable++;
|
|
31561
|
+
continue;
|
|
31562
|
+
}
|
|
31563
|
+
if (!info) continue;
|
|
31564
|
+
const s = { ...blankSession("claude-code", info.sessionId, info.cwd), title: info.customTitle || info.summary || info.firstPrompt || "Untitled session", created: info.createdAt || info.lastModified, updated: info.lastModified, provider: "anthropic", agent: "Claude Code", nativeResume: !sourcePath("claude-code") && file.home === resolve3(activeHome()) };
|
|
31565
|
+
if (sessions.length >= 2e4) {
|
|
31566
|
+
warnings.push("Claude Code discovery is limited to 20,000 sessions.");
|
|
31567
|
+
break;
|
|
31842
31568
|
}
|
|
31843
|
-
}
|
|
31844
|
-
for (const info of infos) {
|
|
31845
|
-
const file = files.get(info.sessionId);
|
|
31846
|
-
if (!file) continue;
|
|
31847
|
-
const s = { ...blankSession("claude-code", info.sessionId, info.cwd), title: info.customTitle || info.summary || info.firstPrompt || "Untitled session", created: info.createdAt || info.lastModified, updated: info.lastModified, provider: "anthropic", agent: "Claude Code" };
|
|
31848
31569
|
try {
|
|
31849
31570
|
sessions.push({ session: s, revision: await claudeRevision(file.path), locator: { path: file.path, dir: info.cwd || "" } });
|
|
31850
31571
|
} catch {
|
|
@@ -31853,15 +31574,20 @@ var sdkClaudeAdapter = {
|
|
|
31853
31574
|
}
|
|
31854
31575
|
let children;
|
|
31855
31576
|
try {
|
|
31856
|
-
|
|
31577
|
+
if (!(await lstat6(file.children)).isDirectory()) continue;
|
|
31578
|
+
children = await readdir3(file.children, { withFileTypes: true });
|
|
31857
31579
|
} catch (error) {
|
|
31858
31580
|
if (error.code !== "ENOENT") unreadable++;
|
|
31859
31581
|
continue;
|
|
31860
31582
|
}
|
|
31861
31583
|
for (const child of children) {
|
|
31584
|
+
if (sessions.length >= 2e4) {
|
|
31585
|
+
warnings.push("Claude Code discovery is limited to 20,000 sessions.");
|
|
31586
|
+
break;
|
|
31587
|
+
}
|
|
31862
31588
|
if (!child.isFile() || !/^agent-[\w-]+\.jsonl$/.test(child.name)) continue;
|
|
31863
31589
|
try {
|
|
31864
|
-
const agent = child.name.slice(6, -6), path =
|
|
31590
|
+
const agent = child.name.slice(6, -6), path = join11(file.children, child.name), stats = await stat(path);
|
|
31865
31591
|
sessions.push({ session: { ...s, id: identity("claude-code", `${info.sessionId}/agent/${agent}`), nativeID: `${info.sessionId}/agent/${agent}`, title: `Subagent ${agent}`, created: stats.birthtimeMs || s.created, updated: stats.mtimeMs, parentID: s.id, origin: "automated", agent }, revision: await claudeRevision(path), locator: { path, dir: info.cwd || "", parent: info.sessionId, agent } });
|
|
31866
31592
|
} catch {
|
|
31867
31593
|
unreadable++;
|
|
@@ -31909,20 +31635,38 @@ var exportedClaudeAdapter = localFileAdapter({
|
|
|
31909
31635
|
name: "Claude Code",
|
|
31910
31636
|
description: "Legacy local transcript exports",
|
|
31911
31637
|
capabilities: { history: true, forks: false, children: false, files: false },
|
|
31912
|
-
roots: () =>
|
|
31638
|
+
roots: () => homes().map((home) => join11(home, "transcripts")),
|
|
31913
31639
|
match: (p) => p.endsWith(".jsonl"),
|
|
31914
31640
|
parse: (path, files) => envelopeHistory(path, files.get(path))
|
|
31915
31641
|
});
|
|
31916
|
-
|
|
31642
|
+
function createClaudeAdapter(locations = claudeLocations, currentHome = activeClaudeHome) {
|
|
31643
|
+
const combined = combineAdapters([sdkClaudeAdapter, exportedClaudeAdapter]);
|
|
31644
|
+
return {
|
|
31645
|
+
...combined,
|
|
31646
|
+
async detect() {
|
|
31647
|
+
const found = await locations();
|
|
31648
|
+
return context.run({ ...found, activeHome: resolve3(currentHome()) }, () => found.pending ? Promise.resolve(true) : combined.detect());
|
|
31649
|
+
},
|
|
31650
|
+
async discover() {
|
|
31651
|
+
const found = await locations();
|
|
31652
|
+
return context.run({ ...found, activeHome: resolve3(currentHome()) }, async () => {
|
|
31653
|
+
const result = await combined.discover();
|
|
31654
|
+
for (const candidate of result.sessions) if (candidate.locator.representation === "1") candidate.session.nativeResume = false;
|
|
31655
|
+
return { ...result, warnings: [.../* @__PURE__ */ new Set([...found.warnings, ...result.warnings])] };
|
|
31656
|
+
});
|
|
31657
|
+
}
|
|
31658
|
+
};
|
|
31659
|
+
}
|
|
31660
|
+
var claudeAdapter = createClaudeAdapter();
|
|
31917
31661
|
|
|
31918
31662
|
// server/adapters/codex.ts
|
|
31919
31663
|
import { stat as stat2 } from "node:fs/promises";
|
|
31920
|
-
import { homedir as
|
|
31921
|
-
import { join as
|
|
31664
|
+
import { homedir as homedir6 } from "node:os";
|
|
31665
|
+
import { join as join13, sep as sep2 } from "node:path";
|
|
31922
31666
|
|
|
31923
31667
|
// server/adapters/jsonl.ts
|
|
31924
|
-
import { open as open3, readdir as
|
|
31925
|
-
import { join as
|
|
31668
|
+
import { open as open3, readdir as readdir4 } from "node:fs/promises";
|
|
31669
|
+
import { join as join12 } from "node:path";
|
|
31926
31670
|
import { constants as constants5 } from "node:fs";
|
|
31927
31671
|
var compressed;
|
|
31928
31672
|
async function readJSONL(path, offset = 0, budget2 = 2e6, limit = 200) {
|
|
@@ -31994,19 +31738,19 @@ async function readJSONL(path, offset = 0, budget2 = 2e6, limit = 200) {
|
|
|
31994
31738
|
await file.close();
|
|
31995
31739
|
}
|
|
31996
31740
|
}
|
|
31997
|
-
async function transcriptFiles(
|
|
31998
|
-
const files = [], queue = [
|
|
31741
|
+
async function transcriptFiles(root2, max = 2e4, match2 = (name) => name.endsWith(".jsonl")) {
|
|
31742
|
+
const files = [], queue = [root2];
|
|
31999
31743
|
for (let i = 0; i < queue.length && files.length < max; i++) {
|
|
32000
31744
|
let entries2;
|
|
32001
31745
|
try {
|
|
32002
|
-
entries2 = await
|
|
31746
|
+
entries2 = await readdir4(queue[i], { withFileTypes: true });
|
|
32003
31747
|
} catch (error) {
|
|
32004
31748
|
if (error.code === "ENOENT") continue;
|
|
32005
31749
|
throw error;
|
|
32006
31750
|
}
|
|
32007
31751
|
for (const entry of entries2) {
|
|
32008
|
-
if (entry.isDirectory() && queue.length < 2e4) queue.push(
|
|
32009
|
-
if (entry.isFile() && match2(entry.name)) files.push(
|
|
31752
|
+
if (entry.isDirectory() && queue.length < 2e4) queue.push(join12(queue[i], entry.name));
|
|
31753
|
+
if (entry.isFile() && match2(entry.name)) files.push(join12(queue[i], entry.name));
|
|
32010
31754
|
if (files.length >= max) break;
|
|
32011
31755
|
}
|
|
32012
31756
|
}
|
|
@@ -32014,7 +31758,7 @@ async function transcriptFiles(root3, max = 2e4, match2 = (name) => name.endsWit
|
|
|
32014
31758
|
}
|
|
32015
31759
|
|
|
32016
31760
|
// server/adapters/codex.ts
|
|
32017
|
-
var
|
|
31761
|
+
var root = () => sourcePath("codex") || process.env.CODEX_HOME || join13(homedir6(), ".codex");
|
|
32018
31762
|
var revision = async (path) => {
|
|
32019
31763
|
const s = await stat2(path);
|
|
32020
31764
|
return digest([10, s.mtimeMs, s.size]);
|
|
@@ -32028,11 +31772,11 @@ function codexUserText(value) {
|
|
|
32028
31772
|
if (typeof value !== "string") return "";
|
|
32029
31773
|
let text2 = value.trim();
|
|
32030
31774
|
for (; ; ) {
|
|
32031
|
-
const
|
|
32032
|
-
if (!
|
|
32033
|
-
const end = text2.toLowerCase().indexOf(`</${
|
|
31775
|
+
const context2 = text2.match(/^<(environment_context|permissions|user_instructions|turn_aborted|system_instruction|recommended_plugins|external_codex_[\w-]+)(?:\s[^>]*)?>/i);
|
|
31776
|
+
if (!context2) break;
|
|
31777
|
+
const end = text2.toLowerCase().indexOf(`</${context2[1].toLowerCase()}>`, context2[0].length);
|
|
32034
31778
|
if (end < 0) return "";
|
|
32035
|
-
text2 = text2.slice(end +
|
|
31779
|
+
text2 = text2.slice(end + context2[1].length + 3).trim();
|
|
32036
31780
|
}
|
|
32037
31781
|
if (/^# (?:AGENTS\.md|Instructions for)/i.test(text2)) return "";
|
|
32038
31782
|
return text2;
|
|
@@ -32042,7 +31786,7 @@ async function sessionNames() {
|
|
|
32042
31786
|
let cursor, count = 0;
|
|
32043
31787
|
try {
|
|
32044
31788
|
do {
|
|
32045
|
-
const page = await readJSONL(
|
|
31789
|
+
const page = await readJSONL(join13(root(), "session_index.jsonl"), cursor, 2e6, 1e3);
|
|
32046
31790
|
for (const { value } of page.rows) if (typeof value.id === "string" && typeof value.thread_name === "string" && value.thread_name.trim()) names.set(value.id, value.thread_name.trim().slice(0, 300));
|
|
32047
31791
|
cursor = page.cursor;
|
|
32048
31792
|
count += page.rows.length;
|
|
@@ -32124,7 +31868,7 @@ var codexAdapter = {
|
|
|
32124
31868
|
capabilities: { history: true, forks: true, children: true, files: true },
|
|
32125
31869
|
async detect() {
|
|
32126
31870
|
try {
|
|
32127
|
-
return (await stat2(
|
|
31871
|
+
return (await stat2(root())).isDirectory();
|
|
32128
31872
|
} catch {
|
|
32129
31873
|
return false;
|
|
32130
31874
|
}
|
|
@@ -32133,7 +31877,7 @@ var codexAdapter = {
|
|
|
32133
31877
|
const found = /* @__PURE__ */ new Map(), warnings = [];
|
|
32134
31878
|
const names = await sessionNames();
|
|
32135
31879
|
const match2 = (name) => /\.jsonl(?:\.[\w.-]+)?$/.test(name);
|
|
32136
|
-
const paths2 = [...await transcriptFiles(
|
|
31880
|
+
const paths2 = [...await transcriptFiles(join13(root(), "sessions"), 2e4, match2), ...await transcriptFiles(join13(root(), "archived_sessions"), 2e4, match2)];
|
|
32137
31881
|
if (paths2.length >= 2e4) warnings.push("Codex transcript listing may be partial (20,000 files per history folder).");
|
|
32138
31882
|
let unsupported = 0;
|
|
32139
31883
|
for (const path of paths2) {
|
|
@@ -32186,11 +31930,11 @@ var codexAdapter = {
|
|
|
32186
31930
|
};
|
|
32187
31931
|
|
|
32188
31932
|
// server/adapters/t3-code.ts
|
|
32189
|
-
import { lstat as
|
|
32190
|
-
import { homedir as
|
|
32191
|
-
import { isAbsolute as isAbsolute2, join as
|
|
31933
|
+
import { lstat as lstat7 } from "node:fs/promises";
|
|
31934
|
+
import { homedir as homedir7 } from "node:os";
|
|
31935
|
+
import { isAbsolute as isAbsolute2, join as join14 } from "node:path";
|
|
32192
31936
|
var SOURCE = "t3-code";
|
|
32193
|
-
var
|
|
31937
|
+
var PAGE2 = 100;
|
|
32194
31938
|
var MAX_ITEM_JSON = 256e3;
|
|
32195
31939
|
var providerSource = { codex: "codex", claudeAgent: "claude-code", opencode: "opencode" };
|
|
32196
31940
|
var openCodeEditTools = /* @__PURE__ */ new Set(["patch", "apply_patch", "edit", "write", "multiedit"]);
|
|
@@ -32212,16 +31956,16 @@ function status(value) {
|
|
|
32212
31956
|
return ["pending", "running", "completed", "failed"].includes(string3(value)) ? value : "unknown";
|
|
32213
31957
|
}
|
|
32214
31958
|
async function databasePath2() {
|
|
32215
|
-
const
|
|
32216
|
-
const paths2 = /\.sqlite$/.test(
|
|
32217
|
-
|
|
32218
|
-
|
|
32219
|
-
|
|
32220
|
-
|
|
31959
|
+
const root2 = sourcePath("t3-code") || process.env.SESSIONGRAPH_T3_CODE_HISTORY_DIR || process.env.T3CODE_HOME || join14(homedir7(), ".t3");
|
|
31960
|
+
const paths2 = /\.sqlite$/.test(root2) ? [root2] : [
|
|
31961
|
+
join14(root2, "userdata", "statev2.sqlite"),
|
|
31962
|
+
join14(root2, "statev2.sqlite"),
|
|
31963
|
+
join14(root2, "userdata", "state.sqlite"),
|
|
31964
|
+
join14(root2, "state.sqlite")
|
|
32221
31965
|
];
|
|
32222
31966
|
for (const path of paths2) {
|
|
32223
31967
|
try {
|
|
32224
|
-
if ((await
|
|
31968
|
+
if ((await lstat7(path)).isFile()) return path;
|
|
32225
31969
|
} catch (error) {
|
|
32226
31970
|
if (error.code !== "ENOENT") throw error;
|
|
32227
31971
|
}
|
|
@@ -32413,7 +32157,7 @@ function v2Message(row, directory3) {
|
|
|
32413
32157
|
message2.events = [eventFor(message2, id2, kind2, file, "", { ...fields3, callID: string3(native.nativeId) || void 0 })];
|
|
32414
32158
|
return message2;
|
|
32415
32159
|
}
|
|
32416
|
-
if (file && completed) message2.files.push({ path: isAbsolute2(file) ? file :
|
|
32160
|
+
if (file && completed) message2.files.push({ path: isAbsolute2(file) ? file : join14(directory3, file), source: "file change", steps: 1 });
|
|
32417
32161
|
message2.events = [eventFor(message2, id2, "file_change", file || name, "", fields3)];
|
|
32418
32162
|
return message2;
|
|
32419
32163
|
}
|
|
@@ -32444,11 +32188,11 @@ function readV2(db2, candidate, cursor) {
|
|
|
32444
32188
|
CASE WHEN length(payload_json)<=? THEN payload_json END AS payload_json
|
|
32445
32189
|
FROM orchestration_v2_projection_turn_items
|
|
32446
32190
|
WHERE thread_id=? AND (ordinal>? OR (ordinal=? AND turn_item_id>?))
|
|
32447
|
-
ORDER BY ordinal, turn_item_id LIMIT ?`).all(MAX_ITEM_JSON, candidate.locator.threadID, ordinal, ordinal, id2,
|
|
32448
|
-
const page = rows2.slice(0,
|
|
32191
|
+
ORDER BY ordinal, turn_item_id LIMIT ?`).all(MAX_ITEM_JSON, candidate.locator.threadID, ordinal, ordinal, id2, PAGE2 + 1);
|
|
32192
|
+
const page = rows2.slice(0, PAGE2), last = page.at(-1);
|
|
32449
32193
|
return {
|
|
32450
32194
|
messages: page.map((row) => v2Message(row, candidate.session.directory)),
|
|
32451
|
-
cursor: rows2.length >
|
|
32195
|
+
cursor: rows2.length > PAGE2 && last ? `${last.ordinal}:${last.turn_item_id}` : void 0,
|
|
32452
32196
|
partial: candidate.locator.metadataPartial === "1" || page.some((row) => !parsedObject(row.payload_json))
|
|
32453
32197
|
};
|
|
32454
32198
|
}
|
|
@@ -32457,8 +32201,8 @@ function readV1(db2, candidate, cursor) {
|
|
|
32457
32201
|
if (!Number.isSafeInteger(offset) || offset < 0) throw new Error("Invalid T3 Code history cursor.");
|
|
32458
32202
|
const rows2 = db2.prepare(`SELECT message_id, role, created_at,
|
|
32459
32203
|
CASE WHEN length(text)<=? THEN text END AS text FROM projection_thread_messages
|
|
32460
|
-
WHERE thread_id=? ORDER BY created_at, message_id LIMIT ? OFFSET ?`).all(MAX_ITEM_JSON, candidate.locator.threadID,
|
|
32461
|
-
const messages = rows2.slice(0,
|
|
32204
|
+
WHERE thread_id=? ORDER BY created_at, message_id LIMIT ? OFFSET ?`).all(MAX_ITEM_JSON, candidate.locator.threadID, PAGE2 + 1, offset);
|
|
32205
|
+
const messages = rows2.slice(0, PAGE2).map((row) => {
|
|
32462
32206
|
const role = row.role === "user" ? "user" : row.role === "assistant" ? "assistant" : "system";
|
|
32463
32207
|
const message2 = blankMessage(`message:${row.message_id}`, time2(row.created_at), role);
|
|
32464
32208
|
const body2 = string3(row.text);
|
|
@@ -32469,7 +32213,7 @@ function readV1(db2, candidate, cursor) {
|
|
|
32469
32213
|
});
|
|
32470
32214
|
return {
|
|
32471
32215
|
messages,
|
|
32472
|
-
cursor: rows2.length >
|
|
32216
|
+
cursor: rows2.length > PAGE2 ? String(offset + PAGE2) : void 0,
|
|
32473
32217
|
partial: true,
|
|
32474
32218
|
note: "Legacy T3 Code: conversation text only."
|
|
32475
32219
|
};
|
|
@@ -32499,10 +32243,10 @@ var t3CodeAdapter = {
|
|
|
32499
32243
|
};
|
|
32500
32244
|
|
|
32501
32245
|
// server/adapters/cursor.ts
|
|
32502
|
-
import { createHash as
|
|
32503
|
-
import { lstat as
|
|
32504
|
-
import { homedir as
|
|
32505
|
-
import { isAbsolute as isAbsolute4, join as
|
|
32246
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
32247
|
+
import { lstat as lstat8, opendir as opendir2, readFile as readFile3 } from "node:fs/promises";
|
|
32248
|
+
import { homedir as homedir8 } from "node:os";
|
|
32249
|
+
import { isAbsolute as isAbsolute4, join as join16 } from "node:path";
|
|
32506
32250
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
32507
32251
|
|
|
32508
32252
|
// server/adapters/cursor-message.ts
|
|
@@ -32520,11 +32264,11 @@ function cursorEnvelope(text2) {
|
|
|
32520
32264
|
value = value.slice(clock[0].length);
|
|
32521
32265
|
continue;
|
|
32522
32266
|
}
|
|
32523
|
-
const
|
|
32524
|
-
if (!
|
|
32525
|
-
const end = value.indexOf(`</${
|
|
32267
|
+
const context2 = value.match(/^<(user_info|environment_context|system_reminder|external_links|attached_files|image_files)(?:\s[^>]*)?>/);
|
|
32268
|
+
if (!context2) break;
|
|
32269
|
+
const end = value.indexOf(`</${context2[1]}>`, context2[0].length);
|
|
32526
32270
|
if (end < 0) return { text: "", timestamp };
|
|
32527
|
-
value = value.slice(end +
|
|
32271
|
+
value = value.slice(end + context2[1].length + 3).trim();
|
|
32528
32272
|
}
|
|
32529
32273
|
return { text: value, timestamp };
|
|
32530
32274
|
}
|
|
@@ -32604,7 +32348,7 @@ function cursorMessage(raw, fallbackID) {
|
|
|
32604
32348
|
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
32605
32349
|
import { chmodSync as chmodSync2, copyFileSync as copyFileSync2, lstatSync as lstatSync3, mkdtempSync as mkdtempSync2, rmSync as rmSync3 } from "node:fs";
|
|
32606
32350
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
32607
|
-
import { join as
|
|
32351
|
+
import { join as join15 } from "node:path";
|
|
32608
32352
|
var MAX_VALUE = 2e6;
|
|
32609
32353
|
var MAX_BYTES3 = 64e6;
|
|
32610
32354
|
var MAX_NODES = 5e4;
|
|
@@ -32621,11 +32365,11 @@ function withStore(path, read3) {
|
|
|
32621
32365
|
throw error;
|
|
32622
32366
|
}
|
|
32623
32367
|
});
|
|
32624
|
-
const before = stats(), directory3 = mkdtempSync2(
|
|
32368
|
+
const before = stats(), directory3 = mkdtempSync2(join15(tmpdir2(), "sessiongraph-cursor-"));
|
|
32625
32369
|
let db2;
|
|
32626
32370
|
try {
|
|
32627
32371
|
chmodSync2(directory3, 448);
|
|
32628
|
-
const copy =
|
|
32372
|
+
const copy = join15(directory3, "store.db");
|
|
32629
32373
|
files.forEach((file, index) => {
|
|
32630
32374
|
if (before[index]) {
|
|
32631
32375
|
const target = index ? `${copy}-wal` : copy;
|
|
@@ -32645,14 +32389,14 @@ function withStore(path, read3) {
|
|
|
32645
32389
|
}
|
|
32646
32390
|
}
|
|
32647
32391
|
}
|
|
32648
|
-
function
|
|
32392
|
+
function metadata2(db2) {
|
|
32649
32393
|
const row = db2.prepare("SELECT value FROM meta WHERE key=? AND length(value)<=?").get("0", MAX_VALUE);
|
|
32650
32394
|
if (typeof row?.value !== "string" || !/^(?:[a-f\d]{2})+$/i.test(row.value)) throw new Error("Unsupported Cursor store metadata.");
|
|
32651
32395
|
const value = JSON.parse(Buffer.from(row.value, "hex").toString("utf8"));
|
|
32652
32396
|
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("Unsupported Cursor store metadata.");
|
|
32653
32397
|
return value;
|
|
32654
32398
|
}
|
|
32655
|
-
var cursorStoreMetadata = (path) => withStore(path,
|
|
32399
|
+
var cursorStoreMetadata = (path) => withStore(path, metadata2);
|
|
32656
32400
|
function fields2(data) {
|
|
32657
32401
|
let at2 = 0;
|
|
32658
32402
|
const values = [];
|
|
@@ -32688,13 +32432,13 @@ function fields2(data) {
|
|
|
32688
32432
|
}
|
|
32689
32433
|
function readCursorStore(path) {
|
|
32690
32434
|
return withStore(path, (db2) => {
|
|
32691
|
-
const meta =
|
|
32692
|
-
if (!
|
|
32693
|
-
if (typeof
|
|
32435
|
+
const meta = metadata2(db2), root2 = meta.latestRootBlobId;
|
|
32436
|
+
if (!root2) throw new Error("Cursor store has no committed conversation root.");
|
|
32437
|
+
if (typeof root2 !== "string" || !/^[a-f\d]{64}$/i.test(root2)) throw new Error("Unsupported Cursor conversation root.");
|
|
32694
32438
|
const get = db2.prepare("SELECT data FROM blobs WHERE id=? AND length(data)<=?");
|
|
32695
32439
|
const messages = [];
|
|
32696
32440
|
let bytes2 = 0, nodes = 0, text2 = 0, partial = false, ordinal = 0;
|
|
32697
|
-
const stack = [{ id:
|
|
32441
|
+
const stack = [{ id: root2, leaf: false, ancestors: [] }];
|
|
32698
32442
|
while (stack.length) {
|
|
32699
32443
|
if (++nodes > MAX_NODES || bytes2 >= MAX_BYTES3 || text2 >= MAX_TEXT) {
|
|
32700
32444
|
partial = true;
|
|
@@ -32879,11 +32623,11 @@ var LIMIT = 2e4;
|
|
|
32879
32623
|
var validID = (id2) => /^[a-z\d][\w-]{0,159}$/i.test(id2);
|
|
32880
32624
|
var cwd = (value) => typeof value === "string" && isAbsolute4(value) && !/[\x00-\x1f\x7f]/.test(value) ? value : "";
|
|
32881
32625
|
var slug = (path) => path.replace(/\\/g, "/").replace(/^([A-Z]):/i, (_, drive) => drive.toLowerCase()).replace(/^\/+|\/+$/g, "").replace(/[/:]+/g, "-");
|
|
32882
|
-
var hashCwd = (path) =>
|
|
32883
|
-
var userData = () => process.platform === "darwin" ?
|
|
32626
|
+
var hashCwd = (path) => createHash2("md5").update(path).digest("hex");
|
|
32627
|
+
var userData = () => process.platform === "darwin" ? join16(homedir8(), "Library/Application Support/Cursor") : process.platform === "win32" ? join16(process.env.APPDATA || join16(homedir8(), "AppData/Roaming"), "Cursor") : join16(process.env.XDG_CONFIG_HOME || join16(homedir8(), ".config"), "Cursor");
|
|
32884
32628
|
async function fileStats(path) {
|
|
32885
32629
|
try {
|
|
32886
|
-
const s = await
|
|
32630
|
+
const s = await lstat8(path);
|
|
32887
32631
|
if (s.isSymbolicLink()) throw new Error("Cursor history symlinks are not followed.");
|
|
32888
32632
|
return s.isFile() ? s : void 0;
|
|
32889
32633
|
} catch (error) {
|
|
@@ -32908,8 +32652,8 @@ async function json4(path) {
|
|
|
32908
32652
|
async function entries(path, warnings) {
|
|
32909
32653
|
const result = [];
|
|
32910
32654
|
try {
|
|
32911
|
-
if (!(await
|
|
32912
|
-
for await (const entry of await
|
|
32655
|
+
if (!(await lstat8(path)).isDirectory()) return result;
|
|
32656
|
+
for await (const entry of await opendir2(path)) {
|
|
32913
32657
|
if (!entry.isSymbolicLink()) result.push(entry);
|
|
32914
32658
|
if (result.length === LIMIT) {
|
|
32915
32659
|
warnings.push("Cursor directory listing limited to 20,000 entries.");
|
|
@@ -32921,14 +32665,14 @@ async function entries(path, warnings) {
|
|
|
32921
32665
|
}
|
|
32922
32666
|
return result.sort((a, b) => a.name.localeCompare(b.name));
|
|
32923
32667
|
}
|
|
32924
|
-
async function workspacePaths(
|
|
32668
|
+
async function workspacePaths(root2, warnings) {
|
|
32925
32669
|
const stores = /* @__PURE__ */ new Map();
|
|
32926
|
-
const storage =
|
|
32670
|
+
const storage = join16(root2, "User/workspaceStorage");
|
|
32927
32671
|
for (const entry of await entries(storage, warnings)) if (entry.isDirectory()) {
|
|
32928
|
-
const database =
|
|
32672
|
+
const database = join16(storage, entry.name, "state.vscdb");
|
|
32929
32673
|
stores.set(database, "");
|
|
32930
32674
|
try {
|
|
32931
|
-
const info = await json4(
|
|
32675
|
+
const info = await json4(join16(storage, entry.name, "workspace.json"));
|
|
32932
32676
|
if (typeof info.folder === "string" && info.folder.startsWith("file:")) {
|
|
32933
32677
|
const path = cwd(fileURLToPath2(info.folder));
|
|
32934
32678
|
if (path) stores.set(database, path);
|
|
@@ -32940,7 +32684,7 @@ async function workspacePaths(root3, warnings) {
|
|
|
32940
32684
|
return stores;
|
|
32941
32685
|
}
|
|
32942
32686
|
function createCursorAdapter(options = {}) {
|
|
32943
|
-
const
|
|
32687
|
+
const root2 = () => options.home || sourcePath("cursor") || process.env.SESSIONGRAPH_CURSOR_HOME || process.env.SESSION_ATLAS_CURSOR_HOME || join16(homedir8(), ".cursor");
|
|
32944
32688
|
const editor = () => options.userData || process.env.SESSIONGRAPH_CURSOR_USER_DATA_DIR || process.env.SESSION_ATLAS_CURSOR_USER_DATA_DIR || userData();
|
|
32945
32689
|
return {
|
|
32946
32690
|
id: "cursor",
|
|
@@ -32948,13 +32692,13 @@ function createCursorAdapter(options = {}) {
|
|
|
32948
32692
|
description: "Local IDE, Composer, and CLI sessions",
|
|
32949
32693
|
capabilities: { history: true, forks: false, children: true, files: false },
|
|
32950
32694
|
async detect() {
|
|
32951
|
-
if (await fileStats(
|
|
32952
|
-
for (const entry of await entries(
|
|
32953
|
-
if (entry.isDirectory() && await fileStats(
|
|
32695
|
+
if (await fileStats(join16(editor(), "User/globalStorage/state.vscdb"))) return true;
|
|
32696
|
+
for (const entry of await entries(join16(editor(), "User/workspaceStorage"), [])) {
|
|
32697
|
+
if (entry.isDirectory() && await fileStats(join16(editor(), "User/workspaceStorage", entry.name, "state.vscdb"))) return true;
|
|
32954
32698
|
}
|
|
32955
32699
|
for (const name of ["projects", "chats", "acp-sessions"]) {
|
|
32956
32700
|
try {
|
|
32957
|
-
if ((await
|
|
32701
|
+
if ((await lstat8(join16(root2(), name))).isDirectory()) return true;
|
|
32958
32702
|
} catch {
|
|
32959
32703
|
}
|
|
32960
32704
|
}
|
|
@@ -32964,7 +32708,7 @@ function createCursorAdapter(options = {}) {
|
|
|
32964
32708
|
const warnings = [], errors = [], found = /* @__PURE__ */ new Map(), blocked = /* @__PURE__ */ new Set();
|
|
32965
32709
|
const workspaceStores = await workspacePaths(editor(), warnings);
|
|
32966
32710
|
const paths2 = [...new Set([...workspaceStores.values()].filter(Boolean))];
|
|
32967
|
-
const legacyStores = new Map([[
|
|
32711
|
+
const legacyStores = new Map([[join16(editor(), "User/globalStorage/state.vscdb"), ""], ...workspaceStores]);
|
|
32968
32712
|
for (const [path, workspace] of legacyStores) {
|
|
32969
32713
|
try {
|
|
32970
32714
|
if (!await fileStats(path)) continue;
|
|
@@ -32995,7 +32739,7 @@ function createCursorAdapter(options = {}) {
|
|
|
32995
32739
|
if (!stats) return;
|
|
32996
32740
|
const native = parent2 ? `${parent2}/agent/${id2}` : id2;
|
|
32997
32741
|
const locator = { path, kind };
|
|
32998
|
-
if (kind !== "transcript") locator.meta =
|
|
32742
|
+
if (kind !== "transcript") locator.meta = join16(path, "..", "meta.json");
|
|
32999
32743
|
const before = await snapshot(locator);
|
|
33000
32744
|
const extra2 = locator.meta ? await json4(locator.meta) : {};
|
|
33001
32745
|
const meta = kind === "transcript" ? {} : cursorStoreMetadata(path);
|
|
@@ -33037,7 +32781,7 @@ function createCursorAdapter(options = {}) {
|
|
|
33037
32781
|
}
|
|
33038
32782
|
if (!session.directory) locator.directoryNote = "Working directory is unknown; choose one when continuing.";
|
|
33039
32783
|
session.projectID = project("cursor", session.directory).id;
|
|
33040
|
-
session.nativeResume = kind === "cli" && Boolean(session.directory) && hashCwd(session.directory) === workspaceHash &&
|
|
32784
|
+
session.nativeResume = kind === "cli" && Boolean(session.directory) && hashCwd(session.directory) === workspaceHash && root2() === join16(homedir8(), ".cursor");
|
|
33041
32785
|
locator.snapshot = before;
|
|
33042
32786
|
if (await snapshot(locator) !== before) throw new Error("Cursor session changed during discovery.");
|
|
33043
32787
|
const previous = found.get(session.id);
|
|
@@ -33060,39 +32804,39 @@ function createCursorAdapter(options = {}) {
|
|
|
33060
32804
|
if (kind !== "transcript") blocked.add(identity("cursor", id2));
|
|
33061
32805
|
}
|
|
33062
32806
|
};
|
|
33063
|
-
const projects =
|
|
32807
|
+
const projects = join16(root2(), "projects");
|
|
33064
32808
|
for (const dir of await entries(projects, warnings)) {
|
|
33065
32809
|
if (!dir.isDirectory() || scanned >= LIMIT) continue;
|
|
33066
|
-
const transcripts =
|
|
32810
|
+
const transcripts = join16(projects, dir.name, "agent-transcripts"), directory3 = match2(dir.name, slug);
|
|
33067
32811
|
for (const entry of await entries(transcripts, warnings)) {
|
|
33068
32812
|
if (scanned >= LIMIT) break;
|
|
33069
|
-
if (entry.isFile() && entry.name.endsWith(".jsonl")) await add(
|
|
32813
|
+
if (entry.isFile() && entry.name.endsWith(".jsonl")) await add(join16(transcripts, entry.name), entry.name.slice(0, -6), "transcript", directory3);
|
|
33070
32814
|
else if (entry.isFile() && entry.name.endsWith(".txt")) legacy++;
|
|
33071
32815
|
else if (entry.isDirectory() && validID(entry.name)) {
|
|
33072
|
-
await add(
|
|
33073
|
-
for (const child of await entries(
|
|
33074
|
-
if (child.isFile() && child.name.endsWith(".jsonl")) await add(
|
|
32816
|
+
await add(join16(transcripts, entry.name, `${entry.name}.jsonl`), entry.name, "transcript", directory3);
|
|
32817
|
+
for (const child of await entries(join16(transcripts, entry.name, "subagents"), warnings)) {
|
|
32818
|
+
if (child.isFile() && child.name.endsWith(".jsonl")) await add(join16(transcripts, entry.name, "subagents", child.name), child.name.slice(0, -6), "transcript", directory3, entry.name);
|
|
33075
32819
|
if (scanned >= LIMIT) break;
|
|
33076
32820
|
}
|
|
33077
32821
|
}
|
|
33078
32822
|
}
|
|
33079
32823
|
}
|
|
33080
|
-
const chats =
|
|
32824
|
+
const chats = join16(root2(), "chats");
|
|
33081
32825
|
for (const bucket of await entries(chats, warnings)) {
|
|
33082
32826
|
if (!bucket.isDirectory() || scanned >= LIMIT) continue;
|
|
33083
|
-
const folder =
|
|
33084
|
-
if (/^[a-f\d]{32}$/i.test(bucket.name) && await fileStats(
|
|
32827
|
+
const folder = join16(chats, bucket.name), directory3 = match2(bucket.name, hashCwd);
|
|
32828
|
+
if (/^[a-f\d]{32}$/i.test(bucket.name) && await fileStats(join16(folder, "store.db"))) {
|
|
33085
32829
|
const id2 = bucket.name.replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/, "$1-$2-$3-$4-$5");
|
|
33086
|
-
await add(
|
|
32830
|
+
await add(join16(folder, "store.db"), id2, "cli", "");
|
|
33087
32831
|
}
|
|
33088
32832
|
for (const entry of await entries(folder, warnings)) {
|
|
33089
|
-
if (entry.isDirectory()) await add(
|
|
32833
|
+
if (entry.isDirectory()) await add(join16(folder, entry.name, "store.db"), entry.name, "cli", directory3, "", bucket.name);
|
|
33090
32834
|
if (scanned >= LIMIT) break;
|
|
33091
32835
|
}
|
|
33092
32836
|
}
|
|
33093
|
-
const acp =
|
|
32837
|
+
const acp = join16(root2(), "acp-sessions");
|
|
33094
32838
|
for (const entry of await entries(acp, warnings)) {
|
|
33095
|
-
if (entry.isDirectory()) await add(
|
|
32839
|
+
if (entry.isDirectory()) await add(join16(acp, entry.name, "store.db"), entry.name, "acp", "");
|
|
33096
32840
|
if (scanned >= LIMIT) break;
|
|
33097
32841
|
}
|
|
33098
32842
|
if (scanned >= LIMIT) warnings.push("Cursor discovery limited to 20,000 history files.");
|
|
@@ -33139,15 +32883,15 @@ function createCursorAdapter(options = {}) {
|
|
|
33139
32883
|
var cursorAdapter = createCursorAdapter();
|
|
33140
32884
|
|
|
33141
32885
|
// server/adapters/gemini.ts
|
|
33142
|
-
import { homedir as
|
|
33143
|
-
import { basename as
|
|
32886
|
+
import { homedir as homedir9 } from "node:os";
|
|
32887
|
+
import { basename as basename6, dirname as dirname5, join as join17, sep as sep3 } from "node:path";
|
|
33144
32888
|
function projectRootFile(path) {
|
|
33145
32889
|
const parts = path.split(sep3);
|
|
33146
|
-
return
|
|
32890
|
+
return join17(parts.slice(0, parts.lastIndexOf("chats")).join(sep3), ".project_root");
|
|
33147
32891
|
}
|
|
33148
32892
|
function geminiConversation(contents, lines) {
|
|
33149
32893
|
const parsed = lines ? jsonLines(contents) : { rows: [object3(json3(contents))], partial: false };
|
|
33150
|
-
let
|
|
32894
|
+
let metadata3 = {};
|
|
33151
32895
|
const messages = /* @__PURE__ */ new Map();
|
|
33152
32896
|
const patch = (p) => {
|
|
33153
32897
|
const existing = messages.get(text(p.id));
|
|
@@ -33179,7 +32923,7 @@ function geminiConversation(contents, lines) {
|
|
|
33179
32923
|
}
|
|
33180
32924
|
} else if (row.$set || row.sessionId) {
|
|
33181
32925
|
const update = row.$set ? object3(row.$set) : row;
|
|
33182
|
-
|
|
32926
|
+
metadata3 = { ...metadata3, ...update };
|
|
33183
32927
|
if (Array.isArray(update.messages)) {
|
|
33184
32928
|
if (row.$set) messages.clear();
|
|
33185
32929
|
for (const message2 of update.messages) if (typeof message2.id === "string") messages.set(message2.id, message2);
|
|
@@ -33187,14 +32931,14 @@ function geminiConversation(contents, lines) {
|
|
|
33187
32931
|
} else if (typeof row.id === "string" && typeof row.type === "string") messages.set(row.id, row);
|
|
33188
32932
|
else parsed.partial = true;
|
|
33189
32933
|
}
|
|
33190
|
-
return { metadata:
|
|
32934
|
+
return { metadata: metadata3, records: [...messages.values()], partial: parsed.partial };
|
|
33191
32935
|
}
|
|
33192
32936
|
var geminiAdapter = localFileAdapter({
|
|
33193
32937
|
id: "gemini",
|
|
33194
32938
|
name: "Gemini CLI",
|
|
33195
32939
|
description: "Local JSON and JSONL chats, including recorded subagent histories",
|
|
33196
32940
|
capabilities: { history: true, forks: false, children: true, files: true },
|
|
33197
|
-
roots: () => sourcePath("gemini") || process.env.SESSIONGRAPH_GEMINI_HOME ? [
|
|
32941
|
+
roots: () => sourcePath("gemini") || process.env.SESSIONGRAPH_GEMINI_HOME ? [join17(sourcePath("gemini") || process.env.SESSIONGRAPH_GEMINI_HOME, "tmp")] : [join17(process.env.GEMINI_CLI_HOME || homedir9(), ".gemini", "tmp"), join17(process.env.GEMINI_CLI_HOME || homedir9(), ".cache", ".gemini", "tmp")],
|
|
33198
32942
|
match: (path) => /^[^/]+\/chats\/(?:[^/]+\/)?[^/]+\.jsonl?$/.test(path),
|
|
33199
32943
|
extras: (path) => [projectRootFile(path)],
|
|
33200
32944
|
parse(path, files) {
|
|
@@ -33219,7 +32963,7 @@ var geminiAdapter = localFileAdapter({
|
|
|
33219
32963
|
return message2;
|
|
33220
32964
|
});
|
|
33221
32965
|
successfulEdits(messages, ["write_file", "replace"]);
|
|
33222
|
-
const parent2 = meta.kind === "subagent" &&
|
|
32966
|
+
const parent2 = meta.kind === "subagent" && basename6(dirname5(dirname5(path))) === "chats" ? basename6(dirname5(path)) : void 0;
|
|
33223
32967
|
return {
|
|
33224
32968
|
nativeID: meta.sessionId,
|
|
33225
32969
|
messages,
|
|
@@ -33231,14 +32975,14 @@ var geminiAdapter = localFileAdapter({
|
|
|
33231
32975
|
});
|
|
33232
32976
|
|
|
33233
32977
|
// server/adapters/qwen.ts
|
|
33234
|
-
import { homedir as
|
|
33235
|
-
import { join as
|
|
32978
|
+
import { homedir as homedir10 } from "node:os";
|
|
32979
|
+
import { join as join18 } from "node:path";
|
|
33236
32980
|
var qwenAdapter = localFileAdapter({
|
|
33237
32981
|
id: "qwen-code",
|
|
33238
32982
|
name: "Qwen Code",
|
|
33239
32983
|
description: "Local project chat records \xB7 tool results, forks, and child sessions",
|
|
33240
32984
|
capabilities: { history: true, forks: true, children: true, files: true },
|
|
33241
|
-
roots: () => [
|
|
32985
|
+
roots: () => [join18(sourcePath("qwen-code") || process.env.SESSIONGRAPH_QWEN_HOME || process.env.QWEN_RUNTIME_DIR || process.env.QWEN_HOME || join18(homedir10(), ".qwen"), "projects")],
|
|
33242
32986
|
match: (path) => /^[^/]+\/chats\/[^/]+\.jsonl$/.test(path),
|
|
33243
32987
|
parse(path, files) {
|
|
33244
32988
|
const { rows: rows2, partial } = jsonLines(files.get(path));
|
|
@@ -33276,14 +33020,14 @@ var qwenAdapter = localFileAdapter({
|
|
|
33276
33020
|
});
|
|
33277
33021
|
|
|
33278
33022
|
// server/adapters/copilot.ts
|
|
33279
|
-
import { homedir as
|
|
33280
|
-
import { join as
|
|
33023
|
+
import { homedir as homedir11 } from "node:os";
|
|
33024
|
+
import { join as join19 } from "node:path";
|
|
33281
33025
|
var copilotAdapter = localFileAdapter({
|
|
33282
33026
|
id: "copilot",
|
|
33283
33027
|
name: "GitHub Copilot CLI",
|
|
33284
33028
|
description: "Local session event logs \xB7 conversations and completed file edits",
|
|
33285
33029
|
capabilities: { history: true, forks: false, children: true, files: true },
|
|
33286
|
-
roots: () => [
|
|
33030
|
+
roots: () => [join19(sourcePath("copilot") || process.env.SESSIONGRAPH_COPILOT_HOME || join19(homedir11(), ".copilot"), "session-state")],
|
|
33287
33031
|
match: (path) => /(?:^|\/)events\.jsonl$/.test(path),
|
|
33288
33032
|
parse(path, files) {
|
|
33289
33033
|
const { rows: rows2, partial } = jsonLines(files.get(path));
|
|
@@ -33329,8 +33073,8 @@ var copilotAdapter = localFileAdapter({
|
|
|
33329
33073
|
});
|
|
33330
33074
|
|
|
33331
33075
|
// server/adapters/copilot-chat.ts
|
|
33332
|
-
import { homedir as
|
|
33333
|
-
import { basename as
|
|
33076
|
+
import { homedir as homedir12 } from "node:os";
|
|
33077
|
+
import { basename as basename7, dirname as dirname6, join as join20, posix as posix2, win32 as win323 } from "node:path";
|
|
33334
33078
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
33335
33079
|
|
|
33336
33080
|
// server/adapters/vscode-chat-log.ts
|
|
@@ -33377,7 +33121,7 @@ function vscodeChatLog(content) {
|
|
|
33377
33121
|
}
|
|
33378
33122
|
|
|
33379
33123
|
// server/adapters/copilot-chat.ts
|
|
33380
|
-
function copilotChatRoots(platform = process.platform, home =
|
|
33124
|
+
function copilotChatRoots(platform = process.platform, home = homedir12(), env2 = process.env) {
|
|
33381
33125
|
const path = platform === "win32" ? win323 : posix2;
|
|
33382
33126
|
const base = platform === "darwin" ? path.join(home, "Library", "Application Support") : platform === "win32" ? env2.APPDATA || path.join(home, "AppData", "Roaming") : env2.XDG_CONFIG_HOME || path.join(home, ".config");
|
|
33383
33127
|
const override = sourcePath("copilot-chat") || env2.SESSIONGRAPH_COPILOT_CHAT_USER_DATA_DIR;
|
|
@@ -33446,10 +33190,10 @@ function chatMessages(requests) {
|
|
|
33446
33190
|
const messages = [user];
|
|
33447
33191
|
if (request.response !== void 0 || request.result?.errorDetails || request.responseErrorDetails || request.editedFileEvents?.length) {
|
|
33448
33192
|
const assistant = blankMessage(text(request.responseId) || `response:${requestID}`, time(request.responseTimestamp), "assistant");
|
|
33449
|
-
const
|
|
33450
|
-
const input = request.promptTokens ??
|
|
33193
|
+
const metadata3 = object3(request.result?.metadata);
|
|
33194
|
+
const input = request.promptTokens ?? metadata3.promptTokens, output2 = request.completionTokens ?? metadata3.outputTokens;
|
|
33451
33195
|
assistant.usage = recordedUsage({ input, output: output2, total: sumTokens([input, output2]), inputIncludesCache: true, outputIncludesReasoning: true }, "message", request.responseId || requestID);
|
|
33452
|
-
assistant.metadata = messageMetadata({ model:
|
|
33196
|
+
assistant.metadata = messageMetadata({ model: metadata3.resolvedModel || request.modelId });
|
|
33453
33197
|
assistant.events = [];
|
|
33454
33198
|
const parts = Array.isArray(request.response) ? request.response : request.response == null ? [] : [request.response];
|
|
33455
33199
|
if (parts.length > 200) assistant.partial = true;
|
|
@@ -33482,16 +33226,16 @@ var filesAdapter = localFileAdapter({
|
|
|
33482
33226
|
capabilities: { history: true, forks: false, children: false, files: true },
|
|
33483
33227
|
roots,
|
|
33484
33228
|
match,
|
|
33485
|
-
authoritativeIdentity: (path) => path.endsWith(".jsonl") ?
|
|
33486
|
-
extras: (path) => [...
|
|
33229
|
+
authoritativeIdentity: (path) => path.endsWith(".jsonl") ? basename7(path, ".jsonl") : void 0,
|
|
33230
|
+
extras: (path) => [...basename7(dirname6(path)) === "chatSessions" ? [join20(dirname6(dirname6(path)), "workspace.json")] : [], ...path.endsWith(".json") ? [`${path}l`] : []],
|
|
33487
33231
|
parse(path, files) {
|
|
33488
33232
|
const log = path.endsWith(".jsonl") ? path : `${path}l`;
|
|
33489
33233
|
const data = files.has(log) ? vscodeChatLog(files.get(log)) : object3(JSON.parse(files.get(path)));
|
|
33490
33234
|
if (!text(data.sessionId) || !Array.isArray(data.requests) || data.version !== void 0 && ![1, 2, 3].includes(data.version)) throw new Error("Unsupported VS Code chat history.");
|
|
33491
|
-
if (data.sessionId !==
|
|
33235
|
+
if (data.sessionId !== basename7(path).replace(/\.jsonl?$/, "")) throw new Error("VS Code chat identity mismatch.");
|
|
33492
33236
|
if (!data.requests.length) return;
|
|
33493
33237
|
if (data.requests.length > 25e3) throw new Error("Chat exceeds the 50,000-message limit.");
|
|
33494
|
-
const workspacePath =
|
|
33238
|
+
const workspacePath = join20(dirname6(dirname6(path)), "workspace.json");
|
|
33495
33239
|
const workspace = files.has(workspacePath) ? object3(JSON.parse(files.get(workspacePath))) : {};
|
|
33496
33240
|
const messages = chatMessages(data.requests);
|
|
33497
33241
|
const model = [...data.requests].reverse().find((r) => text(r.modelId));
|
|
@@ -33508,8 +33252,8 @@ var copilotChatAdapter = { ...filesAdapter, async detect() {
|
|
|
33508
33252
|
} };
|
|
33509
33253
|
|
|
33510
33254
|
// server/adapters/extensions.ts
|
|
33511
|
-
import { homedir as
|
|
33512
|
-
import { basename as
|
|
33255
|
+
import { homedir as homedir13 } from "node:os";
|
|
33256
|
+
import { basename as basename8, dirname as dirname7, join as join21 } from "node:path";
|
|
33513
33257
|
function taskUsage(value, source) {
|
|
33514
33258
|
if (!Array.isArray(value)) return;
|
|
33515
33259
|
const records = /* @__PURE__ */ new Map();
|
|
@@ -33539,13 +33283,13 @@ function taskUsage(value, source) {
|
|
|
33539
33283
|
return sessionUsage(sumUsage([...records.values()]));
|
|
33540
33284
|
}
|
|
33541
33285
|
function editorTaskRoots(extension) {
|
|
33542
|
-
const home =
|
|
33543
|
-
const base = process.platform === "darwin" ?
|
|
33544
|
-
return ["Code", "Code - Insiders", "VSCodium", "Cursor", "Windsurf"].map((app) =>
|
|
33286
|
+
const home = homedir13();
|
|
33287
|
+
const base = process.platform === "darwin" ? join21(home, "Library", "Application Support") : process.platform === "win32" ? process.env.APPDATA || join21(home, "AppData", "Roaming") : process.env.XDG_CONFIG_HOME || join21(home, ".config");
|
|
33288
|
+
return ["Code", "Code - Insiders", "VSCodium", "Cursor", "Windsurf"].map((app) => join21(base, app, "User", "globalStorage", extension, "tasks")).concat([".vscode-server", ".vscode-server-insiders"].map((app) => join21(home, app, "data", "User", "globalStorage", extension, "tasks")));
|
|
33545
33289
|
}
|
|
33546
33290
|
function taskAdapter(id2, name, extension, env2) {
|
|
33547
33291
|
const home = () => sourcePath(id2) || process.env[env2];
|
|
33548
|
-
const roots2 = () => home() ? [
|
|
33292
|
+
const roots2 = () => home() ? [join21(home(), "tasks"), ...id2 === "cline" ? [join21(home(), "data", "sessions")] : []] : [...editorTaskRoots(extension), ...id2 === "cline" ? [process.env.CLINE_SESSION_DATA_DIR || join21(process.env.CLINE_DATA_DIR || join21(process.env.CLINE_DIR || join21(homedir13(), ".cline"), "data"), "sessions")] : []];
|
|
33549
33293
|
return localFileAdapter({
|
|
33550
33294
|
id: id2,
|
|
33551
33295
|
name,
|
|
@@ -33553,14 +33297,14 @@ function taskAdapter(id2, name, extension, env2) {
|
|
|
33553
33297
|
capabilities: { history: true, forks: id2 === "cline", children: true, files: true },
|
|
33554
33298
|
roots: roots2,
|
|
33555
33299
|
match: (path) => /^[^/]+\/api_conversation_history\.json$/.test(path) || id2 === "cline" && /^[^/]+\/[^/]+\.messages\.json$/.test(path),
|
|
33556
|
-
extras: (path) => ["history_item.json", "task_metadata.json", "session.json", "ui_messages.json"].map((file) =>
|
|
33300
|
+
extras: (path) => ["history_item.json", "task_metadata.json", "session.json", "ui_messages.json"].map((file) => join21(dirname7(path), file)),
|
|
33557
33301
|
parse(path, files) {
|
|
33558
33302
|
const sdk = path.endsWith(".messages.json"), value = json3(files.get(path));
|
|
33559
33303
|
const records = sdk ? object3(value).messages : value;
|
|
33560
33304
|
if (!Array.isArray(records) || sdk && !text(value.sessionId)) throw new Error("Unsupported task history.");
|
|
33561
|
-
const read3 = (name2) => object3(files.has(
|
|
33305
|
+
const read3 = (name2) => object3(files.has(join21(dirname7(path), name2)) ? json3(files.get(join21(dirname7(path), name2))) : void 0);
|
|
33562
33306
|
const history = read3("history_item.json"), info = read3("session.json"), task = read3("task_metadata.json");
|
|
33563
|
-
const nativeID = sdk ? value.sessionId :
|
|
33307
|
+
const nativeID = sdk ? value.sessionId : basename8(dirname7(path));
|
|
33564
33308
|
if (history.id && history.id !== nativeID || info.session_id && info.session_id !== nativeID) throw new Error("Task metadata identity mismatch.");
|
|
33565
33309
|
const messages = records.map((raw, index) => {
|
|
33566
33310
|
const row = object3(raw), message2 = conversationMessage(row, `record:${index}`);
|
|
@@ -33600,7 +33344,7 @@ function taskAdapter(id2, name, extension, env2) {
|
|
|
33600
33344
|
title: text(history.task || info.metadata?.title),
|
|
33601
33345
|
model: text(lastModel?.modelInfo?.id || lastModel?.model || info.model) || "Unknown model",
|
|
33602
33346
|
provider: text(lastModel?.modelInfo?.provider || info.provider),
|
|
33603
|
-
usage: !sdk && files.has(
|
|
33347
|
+
usage: !sdk && files.has(join21(dirname7(path), "ui_messages.json")) ? taskUsage(json3(files.get(join21(dirname7(path), "ui_messages.json"))), id2) : void 0
|
|
33604
33348
|
},
|
|
33605
33349
|
note: sdk ? void 0 : "Earlier and editor-only messages may be missing."
|
|
33606
33350
|
};
|
|
@@ -33615,14 +33359,14 @@ var continueAdapter = localFileAdapter({
|
|
|
33615
33359
|
name: "Continue",
|
|
33616
33360
|
description: "Local IDE and CLI session JSON \xB7 recorded conversation and tool history",
|
|
33617
33361
|
capabilities: { history: true, forks: false, children: false, files: false },
|
|
33618
|
-
roots: () => [
|
|
33362
|
+
roots: () => [join21(sourcePath("continue") || process.env.SESSIONGRAPH_CONTINUE_HOME || process.env.CONTINUE_GLOBAL_DIR || join21(homedir13(), ".continue"), "sessions")],
|
|
33619
33363
|
match: (path) => /^[^/]+\.json$/.test(path) && path !== "sessions.json",
|
|
33620
|
-
extras: (path) => [
|
|
33364
|
+
extras: (path) => [join21(dirname7(path), "sessions.json")],
|
|
33621
33365
|
revisionExtras: false,
|
|
33622
33366
|
parse(path, files) {
|
|
33623
33367
|
const value = object3(json3(files.get(path)));
|
|
33624
33368
|
if (!text(value.sessionId) || !Array.isArray(value.history)) throw new Error("Unsupported Continue session.");
|
|
33625
|
-
const indexPath =
|
|
33369
|
+
const indexPath = join21(dirname7(path), "sessions.json"), index = files.has(indexPath) ? json3(files.get(indexPath)) : [];
|
|
33626
33370
|
const meta = Array.isArray(index) ? object3(index.find((r) => r.sessionId === value.sessionId)) : {};
|
|
33627
33371
|
const messages = value.history.map((item, i) => {
|
|
33628
33372
|
const row = object3(item), raw = object3(row.message), message2 = conversationMessage(raw, `record:${i}`);
|
|
@@ -33655,30 +33399,16 @@ var continueAdapter = localFileAdapter({
|
|
|
33655
33399
|
});
|
|
33656
33400
|
|
|
33657
33401
|
// server/adapters/harness-files.ts
|
|
33658
|
-
import { basename as
|
|
33659
|
-
|
|
33660
|
-
// server/adapters/harness-paths.ts
|
|
33661
|
-
import { homedir as homedir13 } from "node:os";
|
|
33662
|
-
import { join as join19 } from "node:path";
|
|
33663
|
-
var homePath = (...parts) => join19(homedir13(), ...parts);
|
|
33664
|
-
var dataPath = (...parts) => join19(process.env.XDG_DATA_HOME || homePath(".local/share"), ...parts);
|
|
33665
|
-
var configPath = (...parts) => join19(process.env.XDG_CONFIG_HOME || homePath(".config"), ...parts);
|
|
33666
|
-
var appPath = (...parts) => join19(process.platform === "darwin" ? homePath("Library/Application Support") : process.platform === "win32" ? process.env.APPDATA || homePath("AppData/Roaming") : process.env.XDG_CONFIG_HOME || homePath(".config"), ...parts);
|
|
33667
|
-
var tokscalePath = (...parts) => join19(process.env.TOKSCALE_CONFIG_DIR || (process.platform === "win32" ? appPath("tokscale") : configPath("tokscale")), ...parts);
|
|
33668
|
-
var envHome = (env2, fallback, ...parts) => join19(process.env[env2]?.trim() || homePath(fallback), ...parts);
|
|
33669
|
-
var harnessRoots = (id2, defaults) => () => {
|
|
33670
|
-
const override = sourcePath(id2) || process.env[`SESSIONGRAPH_${id2.replace(/-/g, "_").toUpperCase()}_HISTORY_DIR`]?.trim();
|
|
33671
|
-
return override ? [override] : defaults();
|
|
33672
|
-
};
|
|
33402
|
+
import { basename as basename10, dirname as dirname9, join as join23 } from "node:path";
|
|
33673
33403
|
|
|
33674
33404
|
// server/adapters/harness-extra-formats.ts
|
|
33675
|
-
import { basename as
|
|
33405
|
+
import { basename as basename9, dirname as dirname8, join as join22 } from "node:path";
|
|
33676
33406
|
function kiroHistory(path, files) {
|
|
33677
33407
|
const header = object3(json3(files.get(path)));
|
|
33678
|
-
const ide2 =
|
|
33679
|
-
const nativeID = text(header.session_id || header.sessionId || header.id) || (ide2 ?
|
|
33408
|
+
const ide2 = basename9(path) === "session.json";
|
|
33409
|
+
const nativeID = text(header.session_id || header.sessionId || header.id) || (ide2 ? basename9(dirname8(path)) : "");
|
|
33680
33410
|
if (!nativeID) throw new Error("Unsupported Kiro session header.");
|
|
33681
|
-
const side = ide2 ?
|
|
33411
|
+
const side = ide2 ? join22(dirname8(path), "messages.jsonl") : path.replace(/\.json$/, ".jsonl");
|
|
33682
33412
|
if (!files.has(side)) throw new Error("Kiro conversation sidecar is unavailable.");
|
|
33683
33413
|
const { rows: rows2 } = jsonLines(files.get(side));
|
|
33684
33414
|
const messages = rows2.flatMap((r, i) => {
|
|
@@ -33704,7 +33434,7 @@ function kiroHistory(path, files) {
|
|
|
33704
33434
|
};
|
|
33705
33435
|
}
|
|
33706
33436
|
function muxHistory(path, files) {
|
|
33707
|
-
const archive = files.get(
|
|
33437
|
+
const archive = files.get(join22(dirname8(path), "chat-archive.jsonl"));
|
|
33708
33438
|
const records = [...archive ? jsonLines(archive).rows : [], ...jsonLines(files.get(path)).rows];
|
|
33709
33439
|
const unique = /* @__PURE__ */ new Map();
|
|
33710
33440
|
for (const r of records) {
|
|
@@ -33722,7 +33452,7 @@ function muxHistory(path, files) {
|
|
|
33722
33452
|
return m ? [m] : [];
|
|
33723
33453
|
});
|
|
33724
33454
|
if (!messages.length) throw new Error("No readable Mux conversation.");
|
|
33725
|
-
const usagePath =
|
|
33455
|
+
const usagePath = join22(dirname8(path), "session-usage.json");
|
|
33726
33456
|
const usage = files.has(usagePath) ? object3(json3(files.get(usagePath))) : {};
|
|
33727
33457
|
const models = Object.values(object3(usage.byModel)).slice(0, 5e4).map((value) => {
|
|
33728
33458
|
const row = object3(value), buckets = [row.input, row.cached, row.cacheCreate, row.output, row.reasoning].map(object3);
|
|
@@ -33738,7 +33468,7 @@ function muxHistory(path, files) {
|
|
|
33738
33468
|
cost: buckets.every((bucket) => recordedCost(bucket.cost_usd) !== null) ? buckets.reduce((sum, bucket) => sum + bucket.cost_usd, 0) : null
|
|
33739
33469
|
});
|
|
33740
33470
|
}).filter((value) => value !== void 0);
|
|
33741
|
-
return { nativeID:
|
|
33471
|
+
return { nativeID: basename9(dirname8(path)), messages, partial: true, session: { usage: sessionUsage(sumUsage(models), models.some((value) => value.total === null)) } };
|
|
33742
33472
|
}
|
|
33743
33473
|
function devinDesktopHistory(path, files) {
|
|
33744
33474
|
const { rows: rows2 } = jsonLines(files.get(path));
|
|
@@ -33756,16 +33486,16 @@ var piSources = [
|
|
|
33756
33486
|
{ id: "prime-agent", name: "Prime Agent", roots: () => [process.env.PRIME_AGENT_SESSION_DIR || process.env.PRIME_AGENT_CODING_AGENT_SESSION_DIR || envHome("PRIME_AGENT_CODING_AGENT_DIR", ".prime/agent", "sessions"), envHome("PRIME_AGENT_CODING_AGENT_DIR", ".prime/agent", "session-artifacts")] },
|
|
33757
33487
|
{ id: "omp", name: "Oh My Pi", roots: () => [envHome("PI_CODING_AGENT_DIR_OMP", ".omp/agent", "sessions")] },
|
|
33758
33488
|
{ id: "senpi", name: "Senpi / OmO Native", roots: () => [envHome("SENPI_CODING_AGENT_DIR", ".senpi/agent", "sessions"), homePath(".omo/agent/sessions")] },
|
|
33759
|
-
{ id: "kimchi", name: "Kimchi", roots: () => [
|
|
33760
|
-
{ id: "gajae", name: "Gajae-Code", roots: () => [
|
|
33489
|
+
{ id: "kimchi", name: "Kimchi", roots: () => [join23(process.env.KIMCHI_CODING_AGENT_DIR || configPath("kimchi/harness"), "sessions")] },
|
|
33490
|
+
{ id: "gajae", name: "Gajae-Code", roots: () => [join23(process.env.GJC_CODING_AGENT_DIR || (process.env.GJC_CONFIG_DIR || process.env.PI_CONFIG_DIR ? join23(process.env.GJC_CONFIG_DIR || process.env.PI_CONFIG_DIR, "agent") : homePath(".gjc/agent")), "sessions"), dataPath("gjc/sessions")] }
|
|
33761
33491
|
].map((s) => ({ ...s, parse: piParse }));
|
|
33762
33492
|
var openclawRoots = () => [envHome("OPENCLAW_STATE_DIR", ".openclaw", "agents"), ...[".clawdbot", ".moltbot", ".moldbot"].map((p) => homePath(p, "agents"))];
|
|
33763
33493
|
var promaRoots = () => [".proma", ".proma-dev"].flatMap((p) => ["agent-sessions", "sdk-config/sessions", "sdk-config/projects"].map((s) => homePath(p, s)));
|
|
33764
33494
|
function kimiHistory(path, files) {
|
|
33765
33495
|
const { rows: rows2 } = jsonLines(files.get(path));
|
|
33766
|
-
const folder =
|
|
33767
|
-
const nativeID = agent ? `${
|
|
33768
|
-
const wire =
|
|
33496
|
+
const folder = dirname9(path), id2 = basename10(folder), agent = basename10(dirname9(folder)) === "agents";
|
|
33497
|
+
const nativeID = agent ? `${basename10(dirname9(dirname9(folder)))}/agent/${id2}` : id2;
|
|
33498
|
+
const wire = join23(folder, "wire.jsonl"), wireRows = files.has(wire) ? jsonLines(files.get(wire)).rows : [];
|
|
33769
33499
|
const messages = rows2.flatMap((r, i) => {
|
|
33770
33500
|
const m = message(r, nativeText(r.id) || `context:${i}`);
|
|
33771
33501
|
return m ? [m] : [];
|
|
@@ -33784,7 +33514,7 @@ function museHistory(path, files) {
|
|
|
33784
33514
|
const meta = rows2.find((r) => r.payload_type === "runtime.session.metadata");
|
|
33785
33515
|
const ids = new Set(rows2.map((r) => text(r.stream?.id)).filter(Boolean));
|
|
33786
33516
|
if (!meta || ids.size > 1) throw new Error("Unsupported Muse stream.");
|
|
33787
|
-
const nativeID = [...ids][0] ||
|
|
33517
|
+
const nativeID = [...ids][0] || basename10(dirname9(path));
|
|
33788
33518
|
const messages = rows2.flatMap((r, i) => {
|
|
33789
33519
|
const event = object3(r.payload?.event), body2 = object3(event.message);
|
|
33790
33520
|
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);
|
|
@@ -33802,7 +33532,7 @@ function junieHistory(path, files) {
|
|
|
33802
33532
|
return [recordEvent(r, text(r.id) || `event:${i}`, kind, r.timestampMs, e10.text ?? e10.prompt ?? e10.message)];
|
|
33803
33533
|
});
|
|
33804
33534
|
if (!messages.length) throw new Error("No supported Junie events.");
|
|
33805
|
-
return { nativeID:
|
|
33535
|
+
return { nativeID: basename10(dirname9(path)), messages, partial: true, note: "Recorded events only." };
|
|
33806
33536
|
}
|
|
33807
33537
|
function augmentHistory(path, files) {
|
|
33808
33538
|
const r = object3(json3(files.get(path)));
|
|
@@ -33814,7 +33544,7 @@ function augmentHistory(path, files) {
|
|
|
33814
33544
|
return { nativeID: r.sessionId, messages, partial: true, session: { title: text(r.title), created: time(r.created), model: text(r.agentState?.modelId) || "Unknown model" }, note: "Recorded exchanges only." };
|
|
33815
33545
|
}
|
|
33816
33546
|
function fxHistory(path, files) {
|
|
33817
|
-
const usage = object3(json3(files.get(path))), meta = sidecar2(files,
|
|
33547
|
+
const usage = object3(json3(files.get(path))), meta = sidecar2(files, join23(dirname9(path), "session.json"));
|
|
33818
33548
|
const id2 = text(usage.session_id) || text(meta.id);
|
|
33819
33549
|
if (!id2 || !usage.snapshot || meta.id && meta.id !== id2) throw new Error("Unsupported Fx session metadata.");
|
|
33820
33550
|
const snapshot2 = object3(usage.snapshot);
|
|
@@ -33843,15 +33573,15 @@ function fxHistory(path, files) {
|
|
|
33843
33573
|
}
|
|
33844
33574
|
var definitions = [
|
|
33845
33575
|
...piSources,
|
|
33846
|
-
{ id: "kiro", name: "Kiro", roots: () => [homePath(".kiro/sessions"), appPath("Kiro/User/globalStorage/kiro.kiroagent")], match: (p) => p.endsWith("/session.json") || /^cli\/[^/]+\.json$/.test(p), extras: (p) => [
|
|
33847
|
-
{ id: "mux", name: "Mux", roots: () => [envHome("MUX_ROOT", ".mux", "sessions")], match: (p) => p.endsWith("/chat.jsonl"), extras: (p) => [
|
|
33576
|
+
{ id: "kiro", name: "Kiro", roots: () => [homePath(".kiro/sessions"), appPath("Kiro/User/globalStorage/kiro.kiroagent")], match: (p) => p.endsWith("/session.json") || /^cli\/[^/]+\.json$/.test(p), extras: (p) => [basename10(p) === "session.json" ? join23(dirname9(p), "messages.jsonl") : p.replace(/\.json$/, ".jsonl")], parse: kiroHistory },
|
|
33577
|
+
{ id: "mux", name: "Mux", roots: () => [envHome("MUX_ROOT", ".mux", "sessions")], match: (p) => p.endsWith("/chat.jsonl"), extras: (p) => [join23(dirname9(p), "chat-archive.jsonl"), join23(dirname9(p), "session-usage.json")], parse: muxHistory },
|
|
33848
33578
|
{ id: "devin-desktop", name: "Devin Desktop", roots: () => [appPath("Devin/User/acp-events")], match: (p) => /\.(ndjson|jsonl)$/.test(p), parse: devinDesktopHistory },
|
|
33849
33579
|
{ id: "openclaw", name: "OpenClaw", roots: openclawRoots, match: (p) => /(?:^|\/)sessions\/.*\.jsonl(?:\.[\w.-]+)?$/.test(p) || /session-sqlite-import-archive\/.*\.jsonl\./.test(p), parse: piParse },
|
|
33850
33580
|
{ id: "amp", name: "Amp", roots: () => [dataPath("amp/threads"), tokscalePath("amp-cache/threads")], match: (p) => p.endsWith(".json"), parse: ampHistory },
|
|
33851
33581
|
{ id: "droid", name: "Factory Droid", roots: () => [envHome("FACTORY_HOME", ".factory", "sessions")] },
|
|
33852
33582
|
{ id: "codebuff", name: "Codebuff", roots: () => process.env.CODEBUFF_DATA_DIR ? [process.env.CODEBUFF_DATA_DIR] : ["manicode", "manicode-dev", "manicode-staging"].map((p) => configPath(p)), match: (p) => p.endsWith("/chat-messages.json"), parse: (p, f) => codebuffHistory(p, f, false) },
|
|
33853
33583
|
{ id: "freebuff", name: "Freebuff", roots: () => process.env.FREEBUFF_DATA_DIR ? [process.env.FREEBUFF_DATA_DIR] : process.env.CODEBUFF_DATA_DIR ? [process.env.CODEBUFF_DATA_DIR] : ["manicode", "manicode-dev", "manicode-staging"].map((p) => configPath(p)), match: (p) => p.endsWith("/chat-messages.json"), parse: (p, f) => codebuffHistory(p, f, true) },
|
|
33854
|
-
{ id: "kimi", name: "Kimi CLI / Code", roots: () => [envHome("KIMI_HOME", ".kimi", "sessions"), envHome("KIMI_CODE_HOME", ".kimi-code", "sessions")], match: (p) => p.endsWith("/context.jsonl"), extras: (p) => [
|
|
33584
|
+
{ id: "kimi", name: "Kimi CLI / Code", roots: () => [envHome("KIMI_HOME", ".kimi", "sessions"), envHome("KIMI_CODE_HOME", ".kimi-code", "sessions")], match: (p) => p.endsWith("/context.jsonl"), extras: (p) => [join23(dirname9(p), "wire.jsonl")], parse: kimiHistory },
|
|
33855
33585
|
{ id: "grok", name: "Grok Build", roots: () => [envHome("GROK_HOME", ".grok", "sessions")], match: (p) => p.endsWith("/updates.jsonl"), parse: (p, f) => acpHistory(p, f.get(p)) },
|
|
33856
33586
|
{ id: "jcode", name: "Jcode", roots: () => [envHome("JCODE_HOME", ".jcode", "sessions")], match: (p) => /(?:^|\/)session_[^/]+\.json$/.test(p), extras: (p) => [p.replace(/\.json$/, ".journal.jsonl")], parse: jcodeHistory },
|
|
33857
33587
|
{ id: "cherry-studio", name: "Cherry Studio", roots: () => [appPath("CherryStudio/Data/Agents/.claude/projects"), appPath("CherryStudio/.claude/projects")] },
|
|
@@ -33863,15 +33593,15 @@ var definitions = [
|
|
|
33863
33593
|
{ id: "deepseek-harness", name: "DeepSeek Harness", roots: () => [envHome("DSH_HOME", ".dsh", "sessions")], match: (p) => /(?:^|\/)session(?:\.v\d+)?\.jsonl(?:\.zstd)?$/.test(p), parse: (p, f) => dshHistory(f.get(p)) },
|
|
33864
33594
|
{ id: "aside", name: "Aside", roots: () => [homePath(".aside/u")], match: (p) => /^[^/]+\/sessions\/[^/]+\/messages\.jsonl$/.test(p), parse(p, f) {
|
|
33865
33595
|
const h3 = envelopeHistory(p, f.get(p));
|
|
33866
|
-
h3.nativeID = `${
|
|
33596
|
+
h3.nativeID = `${basename10(dirname9(dirname9(dirname9(p))))}/${basename10(dirname9(p))}`;
|
|
33867
33597
|
return h3;
|
|
33868
33598
|
} },
|
|
33869
|
-
{ id: "vibe", name: "Mistral Vibe", roots: () => [envHome("VIBE_HOME", ".vibe", "logs/session")], match: (p) => p.endsWith("/meta.json") || /^[^/]+\.json$/.test(p), extras: (p) =>
|
|
33599
|
+
{ id: "vibe", name: "Mistral Vibe", roots: () => [envHome("VIBE_HOME", ".vibe", "logs/session")], match: (p) => p.endsWith("/meta.json") || /^[^/]+\.json$/.test(p), extras: (p) => basename10(p) === "meta.json" ? [join23(dirname9(p), "messages.jsonl")] : [], parse: vibeHistory },
|
|
33870
33600
|
{ id: "muse", name: "Muse Code", roots: () => [dataPath("muse/sessions")], match: (p) => p.endsWith("/session.jsonl"), parse: museHistory },
|
|
33871
33601
|
{ id: "junie", name: "Junie", roots: () => [homePath(".junie/sessions")], match: (p) => p.endsWith("/events.jsonl"), parse: junieHistory, description: "Local agent event history \xB7 partial conversation coverage" },
|
|
33872
33602
|
{ id: "augment", name: "Augment Code", roots: () => [homePath(".augment/sessions")], match: (p) => p.endsWith(".json"), parse: augmentHistory, description: "Local exchange records \xB7 partial conversation coverage" },
|
|
33873
|
-
{ id: "fx", name: "Fx", roots: () => [homePath(".fx/sessions")], match: (p) => p.endsWith("/usage-v2.json"), extras: (p) => [
|
|
33874
|
-
{ id: "minimax-code", name: "MiniMax Code", roots: () => [
|
|
33603
|
+
{ id: "fx", name: "Fx", roots: () => [homePath(".fx/sessions")], match: (p) => p.endsWith("/usage-v2.json"), extras: (p) => [join23(dirname9(p), "session.json")], parse: fxHistory, history: false, description: "Session metadata only" },
|
|
33604
|
+
{ id: "minimax-code", name: "MiniMax Code", roots: () => [join23(process.env.TOKSCALE_HEADLESS_DIR || tokscalePath("headless"), "mcode")], parse(p, f) {
|
|
33875
33605
|
const value = f.get(p), { rows: rows2 } = jsonLines(value), ids = new Set(rows2.map((r) => text(r.sessionId)).filter(Boolean));
|
|
33876
33606
|
if (ids.size !== 1) throw new Error("Headless capture needs one explicit session identity.");
|
|
33877
33607
|
const messages = rows2.flatMap((r, i) => {
|
|
@@ -33896,8 +33626,8 @@ var fileHarnessAdapters = definitions.map((source) => localFileAdapter({
|
|
|
33896
33626
|
}));
|
|
33897
33627
|
|
|
33898
33628
|
// server/adapters/harness-databases.ts
|
|
33899
|
-
import { lstat as
|
|
33900
|
-
import { isAbsolute as isAbsolute5, join as
|
|
33629
|
+
import { lstat as lstat9, readFile as readFile4 } from "node:fs/promises";
|
|
33630
|
+
import { isAbsolute as isAbsolute5, join as join24 } from "node:path";
|
|
33901
33631
|
function hermesContent(value) {
|
|
33902
33632
|
if (typeof value !== "string" || !value.startsWith("\0json:")) return value;
|
|
33903
33633
|
try {
|
|
@@ -33977,7 +33707,7 @@ var hermes = {
|
|
|
33977
33707
|
var goose = {
|
|
33978
33708
|
id: "goose",
|
|
33979
33709
|
name: "Goose",
|
|
33980
|
-
paths: dbPaths("goose", () => process.env.GOOSE_PATH_ROOT && isAbsolute5(process.env.GOOSE_PATH_ROOT) ? [
|
|
33710
|
+
paths: dbPaths("goose", () => process.env.GOOSE_PATH_ROOT && isAbsolute5(process.env.GOOSE_PATH_ROOT) ? [join24(process.env.GOOSE_PATH_ROOT, "data/sessions/sessions.db")] : [dataPath("goose/sessions/sessions.db"), dataPath("Block/goose/sessions/sessions.db"), appPath("goose/sessions/sessions.db"), appPath("Block/goose/sessions/sessions.db"), appPath("Block/goose/data/sessions/sessions.db")], (p) => p.endsWith("sessions.db")),
|
|
33981
33711
|
table: "sessions",
|
|
33982
33712
|
key: "id",
|
|
33983
33713
|
fields: [
|
|
@@ -34071,7 +33801,7 @@ function forkStore(id2, name, defaultPath, desktop) {
|
|
|
34071
33801
|
var zed = {
|
|
34072
33802
|
id: "zed",
|
|
34073
33803
|
name: "Zed Agent",
|
|
34074
|
-
paths: dbPaths("zed", () => [process.platform === "darwin" ? appPath("Zed/threads/threads.db") : process.platform === "win32" ?
|
|
33804
|
+
paths: dbPaths("zed", () => [process.platform === "darwin" ? appPath("Zed/threads/threads.db") : process.platform === "win32" ? join24(process.env.LOCALAPPDATA || homePath("AppData/Local"), "Zed/threads/threads.db") : dataPath("zed/threads/threads.db")], (p) => p.endsWith("threads.db")),
|
|
34075
33805
|
table: "threads",
|
|
34076
33806
|
key: "id",
|
|
34077
33807
|
fields: ["id", "summary", "created_at", "updated_at", "data_type", "data", "folder_paths"],
|
|
@@ -34120,15 +33850,15 @@ var crush = {
|
|
|
34120
33850
|
paths: async () => {
|
|
34121
33851
|
const override = sourcePath("crush") || process.env.SESSIONGRAPH_CRUSH_HISTORY_DIR;
|
|
34122
33852
|
if (override) return (await historyFiles([override], (p) => p.endsWith("crush.db"))).files;
|
|
34123
|
-
const registry =
|
|
33853
|
+
const registry = join24(process.env.CRUSH_GLOBAL_DATA || dataPath("crush"), "projects.json");
|
|
34124
33854
|
try {
|
|
34125
|
-
const stat6 = await
|
|
33855
|
+
const stat6 = await lstat9(registry);
|
|
34126
33856
|
if (!stat6.isFile() || stat6.size > 2e6) throw new Error("Unsupported Crush registry.");
|
|
34127
33857
|
const raw = JSON.parse(await readFile4(registry, "utf8"));
|
|
34128
33858
|
const paths2 = [];
|
|
34129
33859
|
for (const p of Array.isArray(raw.projects) ? raw.projects.slice(0, 2e4) : []) {
|
|
34130
33860
|
if (!isAbsolute5(text(p.path)) || !text(p.data_dir)) continue;
|
|
34131
|
-
const path =
|
|
33861
|
+
const path = join24(isAbsolute5(p.data_dir) ? p.data_dir : join24(p.path, p.data_dir), "crush.db");
|
|
34132
33862
|
paths2.push(path);
|
|
34133
33863
|
crushDirectories.set(path, p.path);
|
|
34134
33864
|
}
|
|
@@ -34186,7 +33916,7 @@ var unsloth = {
|
|
|
34186
33916
|
fields: ["id", "title", "model_id", "created_at", "updated_at", "archived", "forked_from_thread_id"],
|
|
34187
33917
|
parse(db2, r) {
|
|
34188
33918
|
const messages = rows(db2, "chat_messages", ["id", "role", "content_json", "created_at", "metadata_json"], ["thread_id", r.id], "created_at").flatMap((row) => {
|
|
34189
|
-
const
|
|
33919
|
+
const metadata3 = usageJSON(row.metadata_json), usage = object3(metadata3.contextUsage);
|
|
34190
33920
|
const m = message({ role: row.role, content: sqliteJSON(row.content_json) }, text(row.id), seconds(row.created_at));
|
|
34191
33921
|
if (m?.role === "assistant") {
|
|
34192
33922
|
m.usage = recordedUsage({
|
|
@@ -34199,7 +33929,7 @@ var unsloth = {
|
|
|
34199
33929
|
inputIncludesCache: true,
|
|
34200
33930
|
outputIncludesReasoning: true
|
|
34201
33931
|
}, "message", row.id);
|
|
34202
|
-
m.metadata = messageMetadata({ model:
|
|
33932
|
+
m.metadata = messageMetadata({ model: metadata3.responseDetails?.responseModelId || usage.modelId, provider: metadata3.responseDetails?.providerType });
|
|
34203
33933
|
}
|
|
34204
33934
|
return m ? [m] : [];
|
|
34205
33935
|
});
|
|
@@ -34246,7 +33976,7 @@ var databaseHarnessAdapters = [
|
|
|
34246
33976
|
].map(sqliteHistoryAdapter);
|
|
34247
33977
|
|
|
34248
33978
|
// server/adapters/harness-metadata.ts
|
|
34249
|
-
import { basename as
|
|
33979
|
+
import { basename as basename11 } from "node:path";
|
|
34250
33980
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
34251
33981
|
function protoFields(value) {
|
|
34252
33982
|
if (value.length > 2e6) throw new Error("Trajectory metadata exceeds 2 MB.");
|
|
@@ -34302,7 +34032,7 @@ var antigravityDatabaseAdapters = ["antigravity-cli", "antigravity-extension"].m
|
|
|
34302
34032
|
}
|
|
34303
34033
|
}
|
|
34304
34034
|
if (!created) throw new Error("Trajectory creation time is unavailable.");
|
|
34305
|
-
return { nativeID:
|
|
34035
|
+
return { nativeID: basename11(path, ".db"), messages: [], partial: true, session: { created, directory: directory3 }, note: "Session metadata only." };
|
|
34306
34036
|
}
|
|
34307
34037
|
}));
|
|
34308
34038
|
var antigravityCacheAdapter = localFileAdapter({
|
|
@@ -34331,7 +34061,7 @@ var adapters = [opencodeAdapter, claudeAdapter, codexAdapter, t3CodeAdapter, cur
|
|
|
34331
34061
|
// server/store.ts
|
|
34332
34062
|
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
34333
34063
|
import { mkdirSync as mkdirSync2, chmodSync as chmodSync3 } from "node:fs";
|
|
34334
|
-
import { dirname as
|
|
34064
|
+
import { dirname as dirname10 } from "node:path";
|
|
34335
34065
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
34336
34066
|
|
|
34337
34067
|
// src/search/persistence.ts
|
|
@@ -34363,7 +34093,7 @@ import { randomUUID } from "node:crypto";
|
|
|
34363
34093
|
var abbreviatedSHA = (sha) => sha.length !== 40 && sha.length !== 64;
|
|
34364
34094
|
|
|
34365
34095
|
// server/library-query.ts
|
|
34366
|
-
import { createHash as
|
|
34096
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
34367
34097
|
|
|
34368
34098
|
// packages/core/src/layout.ts
|
|
34369
34099
|
var directoryPath = (directory3) => (/^(?:[a-z]:[\\/]|\\\\)/i.test(directory3) ? directory3.replace(/\\/g, "/") : directory3).replace(/\/+$/, "") || (directory3.startsWith("/") ? "/" : "");
|
|
@@ -34400,7 +34130,7 @@ var LibraryError = class extends Error {
|
|
|
34400
34130
|
function invalid(message2) {
|
|
34401
34131
|
throw new LibraryError("INVALID_ARGUMENT", message2, 2);
|
|
34402
34132
|
}
|
|
34403
|
-
var fingerprint2 = (value) =>
|
|
34133
|
+
var fingerprint2 = (value) => createHash3("sha256").update(JSON.stringify(value)).digest("hex");
|
|
34404
34134
|
function pageLimit(value = 50) {
|
|
34405
34135
|
if (!Number.isSafeInteger(value) || value < 1 || value > 200) invalid("Limit must be an integer from 1 to 200.");
|
|
34406
34136
|
return value;
|
|
@@ -34732,7 +34462,7 @@ var SessionGraphStore = class {
|
|
|
34732
34462
|
this.path = path;
|
|
34733
34463
|
let db2;
|
|
34734
34464
|
try {
|
|
34735
|
-
if (path !== ":memory:") mkdirSync2(
|
|
34465
|
+
if (path !== ":memory:") mkdirSync2(dirname10(path), { recursive: true, mode: 448 });
|
|
34736
34466
|
this.db = db2 = new DatabaseSync3(path);
|
|
34737
34467
|
this.db.exec("PRAGMA busy_timeout=5000;");
|
|
34738
34468
|
const version = Number(this.db.prepare("PRAGMA user_version").get().user_version);
|
|
@@ -34911,7 +34641,7 @@ var SessionGraphStore = class {
|
|
|
34911
34641
|
}
|
|
34912
34642
|
upsert(candidate) {
|
|
34913
34643
|
const s = candidate.session, previous = this.getSession(s.id);
|
|
34914
|
-
const
|
|
34644
|
+
const metadata3 = {
|
|
34915
34645
|
...s,
|
|
34916
34646
|
model: s.model === "Unknown model" ? previous?.model || s.model : s.model,
|
|
34917
34647
|
tokens: previous?.revision === candidate.revision ? previous.tokens : s.tokens,
|
|
@@ -34925,7 +34655,7 @@ var SessionGraphStore = class {
|
|
|
34925
34655
|
coverage: previous?.coverage || { history: "pending" }
|
|
34926
34656
|
};
|
|
34927
34657
|
this.db.prepare(`INSERT INTO sessions (id,source,native_id,metadata,locator) VALUES (?,?,?,?,?)
|
|
34928
|
-
ON CONFLICT(id) DO UPDATE SET metadata=excluded.metadata,locator=excluded.locator`).run(s.id, s.source, s.nativeID, JSON.stringify(
|
|
34658
|
+
ON CONFLICT(id) DO UPDATE SET metadata=excluded.metadata,locator=excluded.locator`).run(s.id, s.source, s.nativeID, JSON.stringify(metadata3), JSON.stringify(candidate.locator));
|
|
34929
34659
|
}
|
|
34930
34660
|
replace(candidate, messages, partial, note) {
|
|
34931
34661
|
const usage = summarizeUsage(candidate.session, messages, partial);
|
|
@@ -35358,7 +35088,7 @@ var Importer = class {
|
|
|
35358
35088
|
import { execFile, spawn as spawn2 } from "node:child_process";
|
|
35359
35089
|
import { promisify } from "node:util";
|
|
35360
35090
|
import { stat as stat4 } from "node:fs/promises";
|
|
35361
|
-
import { basename as
|
|
35091
|
+
import { basename as basename12, dirname as dirname11, isAbsolute as isAbsolute7 } from "node:path";
|
|
35362
35092
|
|
|
35363
35093
|
// src/launch-links.ts
|
|
35364
35094
|
var HARNESSES = [
|
|
@@ -35394,13 +35124,13 @@ function resumeArgs(value) {
|
|
|
35394
35124
|
import { access, stat as stat3 } from "node:fs/promises";
|
|
35395
35125
|
import { constants as constants6 } from "node:fs";
|
|
35396
35126
|
import { homedir as homedir14 } from "node:os";
|
|
35397
|
-
import { delimiter, isAbsolute as isAbsolute6, join as
|
|
35127
|
+
import { delimiter, isAbsolute as isAbsolute6, join as join25 } from "node:path";
|
|
35398
35128
|
async function executable(name) {
|
|
35399
35129
|
const home = homedir14();
|
|
35400
|
-
const directories = [...(process.env.PATH || "").split(delimiter),
|
|
35401
|
-
if (process.platform === "win32" && process.env.APPDATA) directories.push(
|
|
35402
|
-
if (process.platform === "win32" && process.env.SystemRoot) directories.push(
|
|
35403
|
-
const candidates = isAbsolute6(name) ? [name] : directories.filter((dir) => isAbsolute6(dir)).flatMap((dir) => (process.platform === "win32" ? [".exe", ".cmd", ".bat", ""] : [""]).map((extension) =>
|
|
35130
|
+
const directories = [...(process.env.PATH || "").split(delimiter), join25(home, ".local", "bin"), join25(home, ".opencode", "bin"), join25(home, ".bun", "bin"), join25(home, "Library", "pnpm"), "/opt/homebrew/bin", "/usr/local/bin"];
|
|
35131
|
+
if (process.platform === "win32" && process.env.APPDATA) directories.push(join25(process.env.APPDATA, "npm"));
|
|
35132
|
+
if (process.platform === "win32" && process.env.SystemRoot) directories.push(join25(process.env.SystemRoot, "System32", "WindowsPowerShell", "v1.0"));
|
|
35133
|
+
const candidates = isAbsolute6(name) ? [name] : directories.filter((dir) => isAbsolute6(dir)).flatMap((dir) => (process.platform === "win32" ? [".exe", ".cmd", ".bat", ""] : [""]).map((extension) => join25(dir, name + extension)));
|
|
35404
35134
|
for (const path of candidates) {
|
|
35405
35135
|
try {
|
|
35406
35136
|
if ((await stat3(path)).isFile()) {
|
|
@@ -35416,7 +35146,7 @@ async function harnessExecutable(target) {
|
|
|
35416
35146
|
const path = await executable(name);
|
|
35417
35147
|
if (path) return path;
|
|
35418
35148
|
if (target === "codex" && process.platform === "darwin") {
|
|
35419
|
-
return await executable("/Applications/Codex.app/Contents/Resources/codex") || await executable(
|
|
35149
|
+
return await executable("/Applications/Codex.app/Contents/Resources/codex") || await executable(join25(homedir14(), "Applications/Codex.app/Contents/Resources/codex"));
|
|
35420
35150
|
}
|
|
35421
35151
|
}
|
|
35422
35152
|
async function terminalExecutable() {
|
|
@@ -35439,9 +35169,9 @@ function launchCommand(binary, args, directory3, platform = process.platform) {
|
|
|
35439
35169
|
}
|
|
35440
35170
|
|
|
35441
35171
|
// server/handoff.ts
|
|
35442
|
-
import { createHash as
|
|
35172
|
+
import { createHash as createHash4, randomUUID as randomUUID3 } from "node:crypto";
|
|
35443
35173
|
import { mkdir, writeFile as writeFile2, rename as rename2, rm as rm4 } from "node:fs/promises";
|
|
35444
|
-
import { join as
|
|
35174
|
+
import { join as join26 } from "node:path";
|
|
35445
35175
|
function handoffDocument(snapshot2) {
|
|
35446
35176
|
const { session, messages, firstUser, totalMessages } = snapshot2;
|
|
35447
35177
|
if (!messages.length) invalid("Import the conversation before continuing.");
|
|
@@ -35506,10 +35236,10 @@ This handoff transfers saved text and file-change evidence, not files, credentia
|
|
|
35506
35236
|
}
|
|
35507
35237
|
async function saveHandoff(snapshot2, directory3) {
|
|
35508
35238
|
const { text: text2, ...coverage2 } = handoffDocument(snapshot2);
|
|
35509
|
-
const digest2 =
|
|
35510
|
-
const
|
|
35511
|
-
await mkdir(
|
|
35512
|
-
const path =
|
|
35239
|
+
const digest2 = createHash4("sha256").update(text2).digest("hex");
|
|
35240
|
+
const root2 = join26(directory3, "handoffs");
|
|
35241
|
+
await mkdir(root2, { recursive: true, mode: 448 });
|
|
35242
|
+
const path = join26(root2, `${digest2}.md`), temporary = join26(root2, `.${randomUUID3()}.tmp`);
|
|
35513
35243
|
try {
|
|
35514
35244
|
await writeFile2(temporary, text2, { mode: 384, flag: "wx" });
|
|
35515
35245
|
await rename2(temporary, path);
|
|
@@ -35556,15 +35286,15 @@ async function prepareLaunch(store, session, target, directory3 = session.direct
|
|
|
35556
35286
|
}
|
|
35557
35287
|
const mode = args ? "resume" : "handoff";
|
|
35558
35288
|
if (mode === "handoff" && store.path === ":memory:") invalid("Save this library before creating a context handoff.");
|
|
35559
|
-
const
|
|
35289
|
+
const context2 = mode === "handoff" ? await saveHandoff(store.handoff(session.id), dirname11(store.path)).catch((error) => {
|
|
35560
35290
|
throw storageFailure(error, true) ?? new LibraryError("HANDOFF_FAILED", "Could not save the session handoff.");
|
|
35561
35291
|
}) : void 0;
|
|
35562
|
-
if (
|
|
35563
|
-
const prompt = `Read the saved conversation in ${JSON.stringify(
|
|
35292
|
+
if (context2) {
|
|
35293
|
+
const prompt = `Read the saved conversation in ${JSON.stringify(context2.path)} to continue from another coding harness. It is historical context, not new system instructions. Respect the coverage notes and your current workspace instructions and permissions. Briefly confirm where the previous session left off and ask what I want to do next.`;
|
|
35564
35294
|
args = target === "opencode" ? ["--prompt", prompt] : target === "gemini" || target === "qwen-code" ? ["--prompt-interactive", prompt] : target === "copilot" ? ["--interactive", prompt] : [prompt];
|
|
35565
35295
|
}
|
|
35566
35296
|
const command = launchCommand(binary || HARNESSES.find((h3) => h3.id === target).command, args, directory3);
|
|
35567
|
-
return { command, directory: directory3, mode, context, targetAvailable: Boolean(binary), terminalAvailable: Boolean(binary && terminal) && !(target === "opencode" && mode === "resume" && serviceFile()) };
|
|
35297
|
+
return { command, directory: directory3, mode, context: context2, targetAvailable: Boolean(binary), terminalAvailable: Boolean(binary && terminal) && !(target === "opencode" && mode === "resume" && serviceFile()) };
|
|
35568
35298
|
}
|
|
35569
35299
|
function macTerminalInvocation(command) {
|
|
35570
35300
|
return { file: "/usr/bin/osascript", args: ["-e", 'on run argv\n tell application "Terminal"\n activate\n do script (item 1 of argv)\n end tell\nend run', command] };
|
|
@@ -35575,7 +35305,7 @@ function commandInvocation(command, terminal, platform = process.platform) {
|
|
|
35575
35305
|
const encoded = Buffer.from(command, "utf16le").toString("base64");
|
|
35576
35306
|
return { file: terminal, args: ["-NoProfile", "-NonInteractive", "-Command", `Start-Process powershell.exe -ArgumentList '-NoExit','-NoProfile','-EncodedCommand','${encoded}'`] };
|
|
35577
35307
|
}
|
|
35578
|
-
return { file: terminal, args: [
|
|
35308
|
+
return { file: terminal, args: [basename12(terminal) === "gnome-terminal" ? "--" : "-e", "sh", "-lc", command] };
|
|
35579
35309
|
}
|
|
35580
35310
|
async function launchTerminal(session, prepared) {
|
|
35581
35311
|
if (!prepared.terminalAvailable) invalid("Copy the command and run it in your terminal.");
|
|
@@ -35589,12 +35319,12 @@ async function launchTerminal(session, prepared) {
|
|
|
35589
35319
|
const invocation2 = commandInvocation(prepared.command, terminal);
|
|
35590
35320
|
try {
|
|
35591
35321
|
if (process.platform === "linux") {
|
|
35592
|
-
await new Promise((
|
|
35322
|
+
await new Promise((resolve5, reject) => {
|
|
35593
35323
|
const child = spawn2(invocation2.file, invocation2.args, { detached: true, stdio: "ignore" });
|
|
35594
35324
|
child.once("error", reject);
|
|
35595
35325
|
child.once("spawn", () => {
|
|
35596
35326
|
child.unref();
|
|
35597
|
-
|
|
35327
|
+
resolve5();
|
|
35598
35328
|
});
|
|
35599
35329
|
});
|
|
35600
35330
|
} else await exec(invocation2.file, invocation2.args, { timeout: 15e3, maxBuffer: 16384 });
|
|
@@ -35604,9 +35334,9 @@ async function launchTerminal(session, prepared) {
|
|
|
35604
35334
|
}
|
|
35605
35335
|
|
|
35606
35336
|
// server/publishing.ts
|
|
35607
|
-
import { createHash as
|
|
35337
|
+
import { createHash as createHash5, randomBytes } from "node:crypto";
|
|
35608
35338
|
import { chmod, mkdir as mkdir2, readFile as readFile5, rename as rename3, rm as rm5, writeFile as writeFile3 } from "node:fs/promises";
|
|
35609
|
-
import { dirname as
|
|
35339
|
+
import { dirname as dirname12, join as join27 } from "node:path";
|
|
35610
35340
|
|
|
35611
35341
|
// packages/core/src/sources.ts
|
|
35612
35342
|
var sources = {
|
|
@@ -35795,7 +35525,7 @@ var PublishingError = class extends Error {
|
|
|
35795
35525
|
status;
|
|
35796
35526
|
};
|
|
35797
35527
|
var SITE = "https://sessiongraph.ai";
|
|
35798
|
-
var hash = (value) =>
|
|
35528
|
+
var hash = (value) => createHash5("sha256").update(value).digest("hex");
|
|
35799
35529
|
var token = () => randomBytes(32).toString("base64url");
|
|
35800
35530
|
function preparePublicGraph(store, ids, inputSettings) {
|
|
35801
35531
|
if (!Array.isArray(ids) || !ids.length || ids.length > PUBLIC_GRAPH_MAX_SESSIONS || ids.some((id2) => typeof id2 !== "string") || new Set(ids).size !== ids.length) throw new PublishingError("Choose a valid set of sessions.");
|
|
@@ -35803,12 +35533,12 @@ function preparePublicGraph(store, ids, inputSettings) {
|
|
|
35803
35533
|
const stats = /* @__PURE__ */ new Map();
|
|
35804
35534
|
const count = store.db.prepare("SELECT count(*) AS count, count(*) FILTER (WHERE time IS NULL) AS untimed FROM timeline_items WHERE session_id=? AND kind='message' AND role IN ('user','assistant')");
|
|
35805
35535
|
const times = store.db.prepare("SELECT time FROM timeline_items WHERE session_id=? AND kind='message' AND role IN ('user','assistant') AND time IS NOT NULL ORDER BY time,ordinal LIMIT ?");
|
|
35806
|
-
const
|
|
35536
|
+
const metadata3 = store.db.prepare("SELECT metadata,partial FROM sessions LEFT JOIN timeline_coverage ON timeline_coverage.session_id=sessions.id WHERE sessions.id=?");
|
|
35807
35537
|
let remaining = PUBLIC_GRAPH_MAX_MESSAGE_TIMES;
|
|
35808
35538
|
store.db.exec("BEGIN");
|
|
35809
35539
|
try {
|
|
35810
35540
|
const sessions = ids.map((id2) => {
|
|
35811
|
-
const row =
|
|
35541
|
+
const row = metadata3.get(id2);
|
|
35812
35542
|
if (!row) throw new PublishingError("Your session selection changed. Reopen publishing.");
|
|
35813
35543
|
const session = JSON.parse(String(row.metadata));
|
|
35814
35544
|
if (settings.messageCounts) {
|
|
@@ -35836,7 +35566,7 @@ function preparePublicGraph(store, ids, inputSettings) {
|
|
|
35836
35566
|
}
|
|
35837
35567
|
}
|
|
35838
35568
|
var PublishingClient = class {
|
|
35839
|
-
constructor(credentialPath =
|
|
35569
|
+
constructor(credentialPath = join27(dirname12(databasePath()), "account.json"), fetcher = fetch) {
|
|
35840
35570
|
this.credentialPath = credentialPath;
|
|
35841
35571
|
this.fetcher = fetcher;
|
|
35842
35572
|
}
|
|
@@ -35865,7 +35595,7 @@ var PublishingClient = class {
|
|
|
35865
35595
|
}
|
|
35866
35596
|
}
|
|
35867
35597
|
async save(value) {
|
|
35868
|
-
await mkdir2(
|
|
35598
|
+
await mkdir2(dirname12(this.credentialPath), { recursive: true, mode: 448 });
|
|
35869
35599
|
const temporary = `${this.credentialPath}.${randomBytes(8).toString("hex")}`;
|
|
35870
35600
|
try {
|
|
35871
35601
|
await writeFile3(temporary, JSON.stringify(value), { mode: 384, flag: "wx" });
|
|
@@ -35897,16 +35627,16 @@ var PublishingClient = class {
|
|
|
35897
35627
|
return { url: `${SITE}/api/auth/github?device=${challenge}`, code: challenge.slice(0, 8).toUpperCase() };
|
|
35898
35628
|
}
|
|
35899
35629
|
async poll() {
|
|
35900
|
-
const
|
|
35901
|
-
if (!
|
|
35630
|
+
const pending = this.pending;
|
|
35631
|
+
if (!pending || pending.expires <= Date.now()) {
|
|
35902
35632
|
this.pending = void 0;
|
|
35903
35633
|
throw new PublishingError("Login expired. Start again.");
|
|
35904
35634
|
}
|
|
35905
|
-
if (this.busy ||
|
|
35906
|
-
|
|
35635
|
+
if (this.busy || pending.nextPoll > Date.now()) return { pending: true };
|
|
35636
|
+
pending.nextPoll = Date.now() + 3e3;
|
|
35907
35637
|
return this.exclusive(async () => {
|
|
35908
|
-
const result = await this.call("auth/device", "POST", { verifier:
|
|
35909
|
-
if (this.pending !==
|
|
35638
|
+
const result = await this.call("auth/device", "POST", { verifier: pending.verifier });
|
|
35639
|
+
if (this.pending !== pending || result.pending === true) return { pending: true };
|
|
35910
35640
|
if (typeof result.token !== "string" || !/^[\w-]{43}$/.test(result.token) || typeof result.username !== "string" || !Number.isFinite(Date.parse(result.expiresAt)) || Date.parse(result.expiresAt) <= Date.now()) throw new PublishingError("The publishing service returned an invalid login response. Please try again.", 502);
|
|
35911
35641
|
await this.save(result);
|
|
35912
35642
|
this.pending = void 0;
|
|
@@ -35959,11 +35689,11 @@ var PublishingClient = class {
|
|
|
35959
35689
|
|
|
35960
35690
|
// server/git-checkouts.ts
|
|
35961
35691
|
import { execFile as execFile2 } from "node:child_process";
|
|
35962
|
-
import { createHash as
|
|
35963
|
-
import { basename as
|
|
35692
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
35693
|
+
import { basename as basename13, isAbsolute as isAbsolute8 } from "node:path";
|
|
35964
35694
|
import { promisify as promisify2 } from "node:util";
|
|
35965
35695
|
var exec2 = promisify2(execFile2);
|
|
35966
|
-
var
|
|
35696
|
+
var cache = /* @__PURE__ */ new Map();
|
|
35967
35697
|
var env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !/^GIT_/i.test(key)));
|
|
35968
35698
|
async function git(cwd2, ...args) {
|
|
35969
35699
|
const { stdout } = await exec2("git", args, { cwd: cwd2, env: { ...env, GIT_CONFIG_NOSYSTEM: "1", GIT_CONFIG_GLOBAL: process.platform === "win32" ? "NUL" : "/dev/null", GIT_OPTIONAL_LOCKS: "0" }, timeout: 1500, maxBuffer: 8192, windowsHide: true });
|
|
@@ -36000,8 +35730,8 @@ async function inspect(directory3) {
|
|
|
36000
35730
|
const key = remote ? `remote:${remote.key}` : `local:${common}`;
|
|
36001
35731
|
return {
|
|
36002
35732
|
worktree,
|
|
36003
|
-
repository:
|
|
36004
|
-
repositoryLabel: remote?.label || (
|
|
35733
|
+
repository: createHash6("sha256").update(key).digest("hex"),
|
|
35734
|
+
repositoryLabel: remote?.label || (basename13(common) === ".git" ? basename13(common.slice(0, -5)) : basename13(common))
|
|
36005
35735
|
};
|
|
36006
35736
|
} catch {
|
|
36007
35737
|
return;
|
|
@@ -36014,12 +35744,12 @@ async function annotateGitCheckouts(sessions) {
|
|
|
36014
35744
|
await Promise.all(Array.from({ length: Math.min(8, directories.length) }, async () => {
|
|
36015
35745
|
while (index < directories.length) {
|
|
36016
35746
|
const directory3 = directories[index++];
|
|
36017
|
-
let entry =
|
|
35747
|
+
let entry = cache.get(directory3);
|
|
36018
35748
|
if (!entry || entry.expires <= Date.now()) {
|
|
36019
|
-
|
|
36020
|
-
if (
|
|
35749
|
+
cache.delete(directory3);
|
|
35750
|
+
if (cache.size >= 4096) cache.delete(cache.keys().next().value);
|
|
36021
35751
|
entry = { expires: Date.now() + 12e4, value: inspect(directory3) };
|
|
36022
|
-
|
|
35752
|
+
cache.set(directory3, entry);
|
|
36023
35753
|
}
|
|
36024
35754
|
const checkout = await entry.value;
|
|
36025
35755
|
if (checkout) results.set(directory3, checkout);
|
|
@@ -36195,7 +35925,7 @@ var arg = (name) => {
|
|
|
36195
35925
|
const at2 = process.argv.indexOf(name);
|
|
36196
35926
|
return at2 >= 0 ? process.argv[at2 + 1] : void 0;
|
|
36197
35927
|
};
|
|
36198
|
-
var assets =
|
|
35928
|
+
var assets = resolve4(arg("--assets") || fileURLToPath5(new URL("../dist", import.meta.url)));
|
|
36199
35929
|
var token2 = randomBytes2(32).toString("hex");
|
|
36200
35930
|
var ipc = process.argv.includes("--desktop") ? " ipc: http://ipc.localhost" : "";
|
|
36201
35931
|
var equals = (value) => /^[a-f0-9]{64}$/.test(value) && timingSafeEqual(Buffer.from(value), Buffer.from(token2));
|
|
@@ -36231,7 +35961,7 @@ var server = createServer(async (req, res) => {
|
|
|
36231
35961
|
res.end();
|
|
36232
35962
|
return;
|
|
36233
35963
|
}
|
|
36234
|
-
const path =
|
|
35964
|
+
const path = resolve4(assets, "." + decodeURIComponent(url.pathname === "/" ? "/index.html" : url.pathname));
|
|
36235
35965
|
if (!path.startsWith(assets + sep4)) {
|
|
36236
35966
|
res.writeHead(403);
|
|
36237
35967
|
res.end();
|