sessiongraph-app-win32-x64 1.0.12 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/payload/SessionGraph.exe +0 -0
- package/payload/resources/server.mjs +719 -346
- package/payload/resources/web/assets/external-links-BmBkCsrt.js +1 -0
- package/payload/resources/web/assets/index-B1kyvo41.js +175 -0
- package/payload/resources/web/assets/index-BLM-0yG6.js +1 -0
- package/payload/resources/web/assets/{index-BS2Voifb.js → index-D4P4hbvc.js} +1 -1
- package/payload/resources/web/assets/index-Du0_nVjH.css +1 -0
- package/payload/resources/web/assets/{index-GTrhxXlP.js → index-Kotmn42s.js} +1 -1
- package/payload/resources/web/assets/publishing-CEvQPkO1.css +1 -0
- package/payload/resources/web/assets/publishing-D9CqkbeB.js +23 -0
- package/payload/resources/web/assets/scene-CTHyYtma.js +139 -0
- package/payload/resources/web/assets/share-Cw1E-ED9.js +7 -0
- package/payload/resources/web/index.html +2 -2
- package/payload/resources/web/sources/NOTICE.txt +4 -4
- package/payload/resources/web/assets/external-links-D0O8IeG0.js +0 -1
- package/payload/resources/web/assets/index-CIhs02tq.js +0 -169
- package/payload/resources/web/assets/index-Vq4WYmzW.js +0 -1
- package/payload/resources/web/assets/index-cVgPCrFV.css +0 -1
- package/payload/resources/web/assets/publishing-VJhUmdPH.css +0 -1
- package/payload/resources/web/assets/publishing-ofssf6d6.js +0 -25
- package/payload/resources/web/assets/scene-KCDTPCOD.js +0 -139
- package/payload/resources/web/assets/share-DKeJCFAo.js +0 -7
- package/payload/resources/web/sources/hindsight.svg +0 -1
- package/payload/resources/web/sources/lmstudio.svg +0 -1
- package/payload/resources/web/sources/reasonix.svg +0 -1
- package/payload/resources/web/sources/trae.svg +0 -1
- package/payload/resources/web/sources/warp.svg +0 -1
|
@@ -2635,7 +2635,7 @@ function databasePath(env = process.env, platform = process.platform, home = hom
|
|
|
2635
2635
|
return paths2.find((path) => existsSync(path)) || paths2[0];
|
|
2636
2636
|
}
|
|
2637
2637
|
|
|
2638
|
-
// src/playback-tokens.ts
|
|
2638
|
+
// packages/core/src/playback-tokens.ts
|
|
2639
2639
|
var validTokenCount = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
2640
2640
|
function sumRecordedTokens(values) {
|
|
2641
2641
|
if (!values.length || !values.every(validTokenCount)) return null;
|
|
@@ -2856,13 +2856,13 @@ import { createHash as createHash2 } from "node:crypto";
|
|
|
2856
2856
|
import { basename as basename2 } from "node:path";
|
|
2857
2857
|
var digest = (value) => createHash2("sha256").update(JSON.stringify(value)).digest("hex");
|
|
2858
2858
|
var identity = (source, native) => `${source}:${native}`;
|
|
2859
|
-
var project = (source,
|
|
2860
|
-
var blankSession = (source, nativeID,
|
|
2859
|
+
var project = (source, directory3) => ({ id: identity(source, digest(directory3).slice(0, 24)), name: basename2(directory3) || "Global", directory: directory3, worktrees: [] });
|
|
2860
|
+
var blankSession = (source, nativeID, directory3 = "") => ({
|
|
2861
2861
|
source,
|
|
2862
2862
|
nativeID,
|
|
2863
2863
|
id: identity(source, nativeID),
|
|
2864
|
-
projectID: project(source,
|
|
2865
|
-
directory:
|
|
2864
|
+
projectID: project(source, directory3).id,
|
|
2865
|
+
directory: directory3,
|
|
2866
2866
|
title: "Untitled session",
|
|
2867
2867
|
created: 0,
|
|
2868
2868
|
updated: 0,
|
|
@@ -2954,9 +2954,9 @@ function boundEventPayloads(message2, budget2) {
|
|
|
2954
2954
|
return [];
|
|
2955
2955
|
}
|
|
2956
2956
|
const bounded = { ...event };
|
|
2957
|
-
for (const key of ["text", "input", "output", "name", "id", "nativeID", "nativeType", "callID", "parentID"]) {
|
|
2957
|
+
for (const key of ["text", "input", "output", "name", "id", "nativeID", "nativeType", "callID", "parentID", "cwd"]) {
|
|
2958
2958
|
if (bounded[key] === void 0) continue;
|
|
2959
|
-
const value = String(bounded[key]), size = key === "text" || key === "output" ? 64e3 : key === "input" ? 32e3 : 512;
|
|
2959
|
+
const value = String(bounded[key]), size = key === "text" || key === "output" ? 64e3 : key === "input" ? 32e3 : key === "cwd" ? 4096 : 512;
|
|
2960
2960
|
bounded[key] = value.slice(0, Math.max(0, Math.min(remaining, size)));
|
|
2961
2961
|
remaining -= bounded[key].length;
|
|
2962
2962
|
if (bounded[key].length < value.length) {
|
|
@@ -2985,6 +2985,14 @@ function blockEvents(message2, content, transform = (v3) => v3) {
|
|
|
2985
2985
|
return [eventFor(message2, id2, "event", `${part.type || "Unknown"} content`, "This content type is not represented as text.", { ...fields2, partial: true })];
|
|
2986
2986
|
});
|
|
2987
2987
|
}
|
|
2988
|
+
function userBlockEvents(message2, content, normalize) {
|
|
2989
|
+
const context = [];
|
|
2990
|
+
return blockEvents(message2, content, (value) => {
|
|
2991
|
+
const text2 = normalize(value);
|
|
2992
|
+
context.push(Boolean(value && !text2));
|
|
2993
|
+
return text2 || value;
|
|
2994
|
+
}).map((event) => event.kind === "message" && context.shift() ? { ...event, kind: "event", role: "system", name: "Session context", nativeType: "user-context" } : event);
|
|
2995
|
+
}
|
|
2988
2996
|
function normalizedEvents(message2, sessionID) {
|
|
2989
2997
|
let events = message2.events;
|
|
2990
2998
|
if (!events) {
|
|
@@ -2996,7 +3004,7 @@ function normalizedEvents(message2, sessionID) {
|
|
|
2996
3004
|
}
|
|
2997
3005
|
const files = message2.files.map((file, i) => eventFor(message2, `file:${i}`, "file_change", file.path, `${file.source} \xB7 ${file.steps} recorded step(s)`, { nativeType: file.source }));
|
|
2998
3006
|
return [...events, ...files].slice(0, 200).map((event) => {
|
|
2999
|
-
const text2 = String(event.text || "").slice(0, 64e3), input = event.input?.slice(0, 32e3),
|
|
3007
|
+
const text2 = String(event.text || "").slice(0, 64e3), input = event.input?.slice(0, 32e3), output2 = event.output?.slice(0, 64e3);
|
|
3000
3008
|
const time4 = messageTime(event.time || 0);
|
|
3001
3009
|
return {
|
|
3002
3010
|
...event,
|
|
@@ -3013,12 +3021,167 @@ function normalizedEvents(message2, sessionID) {
|
|
|
3013
3021
|
timeSource: time4 ? event.timeSource : "unknown",
|
|
3014
3022
|
text: text2,
|
|
3015
3023
|
input,
|
|
3016
|
-
output,
|
|
3017
|
-
partial: Boolean(event.partial || message2.partial || text2.length < (event.text?.length || 0) || input?.length !== event.input?.length ||
|
|
3024
|
+
output: output2,
|
|
3025
|
+
partial: Boolean(event.partial || message2.partial || text2.length < (event.text?.length || 0) || input?.length !== event.input?.length || output2?.length !== event.output?.length || events.length + files.length > 200)
|
|
3018
3026
|
};
|
|
3019
3027
|
});
|
|
3020
3028
|
}
|
|
3021
3029
|
|
|
3030
|
+
// server/commit-extraction.ts
|
|
3031
|
+
import { posix, win32 } from "node:path";
|
|
3032
|
+
var COMMIT_EXTRACTOR_VERSION = 1;
|
|
3033
|
+
var object = (v3) => v3 && typeof v3 === "object" && !Array.isArray(v3) ? v3 : {};
|
|
3034
|
+
var string = (v3) => typeof v3 === "string" ? v3 : void 0;
|
|
3035
|
+
var exitCode = (v3) => typeof v3 === "number" && Number.isSafeInteger(v3) ? v3 : void 0;
|
|
3036
|
+
function executionFields(input, metadata2 = {}) {
|
|
3037
|
+
const args = object(input), meta = object(metadata2);
|
|
3038
|
+
return { cwd: string(args.workdir ?? args.cwd ?? args.working_directory ?? meta.cwd), exitCode: exitCode(meta.exitCode ?? meta.exit_code ?? meta.exit) };
|
|
3039
|
+
}
|
|
3040
|
+
function nativeCommit(value) {
|
|
3041
|
+
const v3 = object(value), operation2 = v3.kind === "committed" ? "created" : v3.kind === "amended" ? "amended" : v3.kind === "cherry-picked" ? "cherry-picked" : void 0;
|
|
3042
|
+
return operation2 && typeof v3.sha === "string" && /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i.test(v3.sha) ? { sha: v3.sha.toLowerCase(), operation: operation2 } : void 0;
|
|
3043
|
+
}
|
|
3044
|
+
function json2(value) {
|
|
3045
|
+
try {
|
|
3046
|
+
return JSON.parse(value);
|
|
3047
|
+
} catch {
|
|
3048
|
+
return value;
|
|
3049
|
+
}
|
|
3050
|
+
}
|
|
3051
|
+
function absolute(path) {
|
|
3052
|
+
if (!path || /[\0\r\n]/.test(path)) return;
|
|
3053
|
+
return posix.isAbsolute(path) ? posix : win32.isAbsolute(path) && /^[a-z]:[\\/]/i.test(path) ? win32 : void 0;
|
|
3054
|
+
}
|
|
3055
|
+
function directory(path, base) {
|
|
3056
|
+
if (!path || /[\0\r\n$`~]/.test(path)) return;
|
|
3057
|
+
const flavor = absolute(path) || absolute(base);
|
|
3058
|
+
return flavor ? flavor.resolve(base || path, path) : void 0;
|
|
3059
|
+
}
|
|
3060
|
+
function commands(command) {
|
|
3061
|
+
const result = [], words = [];
|
|
3062
|
+
let word = "", active = false, quote = "";
|
|
3063
|
+
const flush = () => {
|
|
3064
|
+
if (active) words.push(word);
|
|
3065
|
+
word = "";
|
|
3066
|
+
active = false;
|
|
3067
|
+
};
|
|
3068
|
+
for (let i = 0; i < command.length; i++) {
|
|
3069
|
+
const c = command[i];
|
|
3070
|
+
if (quote) {
|
|
3071
|
+
if (c === quote) {
|
|
3072
|
+
quote = "";
|
|
3073
|
+
continue;
|
|
3074
|
+
}
|
|
3075
|
+
if (quote === '"' && /[$`\\]/.test(c)) return;
|
|
3076
|
+
word += c;
|
|
3077
|
+
continue;
|
|
3078
|
+
}
|
|
3079
|
+
if (c === '"' || c === "'") {
|
|
3080
|
+
quote = c;
|
|
3081
|
+
active = true;
|
|
3082
|
+
continue;
|
|
3083
|
+
}
|
|
3084
|
+
if (/[|<>$`(){}\\#\0;\n\r*?\[\]]/.test(c)) return;
|
|
3085
|
+
if (c === "&" && command[i + 1] !== "&") return;
|
|
3086
|
+
if (c === "&") {
|
|
3087
|
+
flush();
|
|
3088
|
+
if (!words.length) return;
|
|
3089
|
+
result.push(words.splice(0));
|
|
3090
|
+
i++;
|
|
3091
|
+
} else if (/\s/.test(c)) flush();
|
|
3092
|
+
else {
|
|
3093
|
+
word += c;
|
|
3094
|
+
active = true;
|
|
3095
|
+
}
|
|
3096
|
+
}
|
|
3097
|
+
if (quote) return;
|
|
3098
|
+
flush();
|
|
3099
|
+
if (!words.length && result.length) return;
|
|
3100
|
+
if (words.length) result.push(words);
|
|
3101
|
+
return result;
|
|
3102
|
+
}
|
|
3103
|
+
function invocation(input, cwd2) {
|
|
3104
|
+
const value = json2(input || ""), args = object(value);
|
|
3105
|
+
const command = typeof value === "string" ? value : string(args.command ?? args.cmd);
|
|
3106
|
+
const explicit = string(args.workdir ?? args.cwd ?? args.working_directory);
|
|
3107
|
+
return { command, cwd: explicit !== void 0 ? directory(explicit) : directory(cwd2) };
|
|
3108
|
+
}
|
|
3109
|
+
function operation(words) {
|
|
3110
|
+
const [verb, ...args] = words;
|
|
3111
|
+
if (verb === "commit") {
|
|
3112
|
+
let amend = false;
|
|
3113
|
+
for (let i = 0; i < args.length; i++) {
|
|
3114
|
+
const arg2 = args[i];
|
|
3115
|
+
if (["-m", "--message", "-F", "--file", "--author", "--date", "--fixup", "--squash", "-C", "--reuse-message", "-c", "--reedit-message"].includes(arg2)) {
|
|
3116
|
+
if (++i >= args.length) return;
|
|
3117
|
+
continue;
|
|
3118
|
+
}
|
|
3119
|
+
if (/^--(?:message|file|author|date|fixup|squash|reuse-message|reedit-message)=/.test(arg2) || /^-m.+/.test(arg2)) continue;
|
|
3120
|
+
if (arg2 === "--amend") {
|
|
3121
|
+
amend = true;
|
|
3122
|
+
continue;
|
|
3123
|
+
}
|
|
3124
|
+
if (["-a", "--all", "--no-edit", "--allow-empty", "--allow-empty-message", "-n", "--no-verify", "-s", "--signoff", "-q", "--quiet", "--no-gpg-sign", "--gpg-sign", "-S"].includes(arg2)) continue;
|
|
3125
|
+
return;
|
|
3126
|
+
}
|
|
3127
|
+
return amend ? "amended" : "created";
|
|
3128
|
+
}
|
|
3129
|
+
if (verb === "cherry-pick" && args.length && args.every((arg2) => /^(?:[a-f0-9]{7,64}|-x|--continue)$/i.test(arg2))) return "cherry-picked";
|
|
3130
|
+
}
|
|
3131
|
+
function plan(command, cwd2) {
|
|
3132
|
+
const parts = commands(command);
|
|
3133
|
+
if (!parts?.length) return;
|
|
3134
|
+
let found;
|
|
3135
|
+
for (const part of parts) {
|
|
3136
|
+
const [program, ...args] = part;
|
|
3137
|
+
if (program === "cd" && args.length === 1 && !/^[+-]/.test(args[0]) && !found) {
|
|
3138
|
+
cwd2 = directory(args[0], cwd2);
|
|
3139
|
+
if (!cwd2) return;
|
|
3140
|
+
continue;
|
|
3141
|
+
}
|
|
3142
|
+
if (program !== "git") return;
|
|
3143
|
+
let path = cwd2;
|
|
3144
|
+
while (args[0] === "-C") {
|
|
3145
|
+
args.shift();
|
|
3146
|
+
path = directory(args.shift(), path);
|
|
3147
|
+
if (!path) return;
|
|
3148
|
+
}
|
|
3149
|
+
const op = operation(args);
|
|
3150
|
+
if (op) {
|
|
3151
|
+
if (found || !path) return;
|
|
3152
|
+
found = { operation: op, repositoryPath: path, trailing: false };
|
|
3153
|
+
} else if (!["add", "push"].includes(args[0]) || args.some((arg2) => /^(?:--exec-path|--git-dir|--work-tree|--config-env)/.test(arg2))) return;
|
|
3154
|
+
else if (found) found.trailing = true;
|
|
3155
|
+
}
|
|
3156
|
+
return found;
|
|
3157
|
+
}
|
|
3158
|
+
function output(value) {
|
|
3159
|
+
const parsed = json2(value || "");
|
|
3160
|
+
if (typeof parsed === "string") {
|
|
3161
|
+
const code = parsed.match(/(?:^|\n)Process exited with code (-?\d+)\r?\n/);
|
|
3162
|
+
return { text: parsed, code: code ? Number(code[1]) : void 0 };
|
|
3163
|
+
}
|
|
3164
|
+
if (Array.isArray(parsed)) return { text: parsed.filter((p) => p?.type === "text" && typeof p.text === "string").map((p) => p.text).join("\n") };
|
|
3165
|
+
const obj = object(parsed);
|
|
3166
|
+
return { text: string(obj.stdout) ?? string(obj.output) ?? "", code: exitCode(obj.exit_code ?? obj.exitCode ?? obj.metadata?.exit_code) };
|
|
3167
|
+
}
|
|
3168
|
+
function extractCommit(call, result) {
|
|
3169
|
+
const shell = /^(?:shell|bash|exec_command|shell_command|run_shell_command|terminal|command execution)$/i.test(call.name) || call.nativeType === "command_execution";
|
|
3170
|
+
const input = invocation(call.input, call.cwd ?? result.cwd);
|
|
3171
|
+
const candidate = Boolean(result.gitCommit || shell && /\bgit\b[\s\S]*\b(?:commit|cherry-pick)\b/.test(input.command || ""));
|
|
3172
|
+
if (!candidate) return { candidate: false };
|
|
3173
|
+
if (call.partial || result.partial || !input.command || !shell || ["running", "pending"].includes(result.status || "")) return { candidate };
|
|
3174
|
+
const parsed = plan(input.command, input.cwd);
|
|
3175
|
+
if (!parsed) return { candidate };
|
|
3176
|
+
const recorded = output(result.output), code = result.exitCode ?? recorded.code;
|
|
3177
|
+
if (code !== void 0 && code !== 0 && !parsed.trailing || result.status === "failed" && !parsed.trailing) return { candidate };
|
|
3178
|
+
const summary = [...recorded.text.matchAll(/^\[(?:[^\]\r\n]+ )([a-f0-9]{7,64})\] [^\r\n]*$/gmi)];
|
|
3179
|
+
const native = result.gitCommit;
|
|
3180
|
+
if (native && native.operation !== parsed.operation) return { candidate };
|
|
3181
|
+
const sha = native && native.operation === parsed.operation ? native.sha : summary.length === 1 && (code !== void 0 || ["completed", "failed"].includes(result.status || "")) ? summary[0][1].toLowerCase() : void 0;
|
|
3182
|
+
return { candidate, commit: sha ? { sha, repositoryPath: parsed.repositoryPath, operation: parsed.operation } : void 0 };
|
|
3183
|
+
}
|
|
3184
|
+
|
|
3022
3185
|
// server/adapters/opencode-events.ts
|
|
3023
3186
|
function opencodeEvents(raw, message2) {
|
|
3024
3187
|
const fields2 = { nativeID: message2.id, nativeType: String(raw.type), timeSource: message2.time ? "recorded" : "unknown" };
|
|
@@ -3038,7 +3201,7 @@ function opencodeEvents(raw, message2) {
|
|
|
3038
3201
|
else if (part.type === "tool") {
|
|
3039
3202
|
const state2 = part.state || {}, endTime = messageTime(part.time?.completed);
|
|
3040
3203
|
const status2 = state2.status === "error" ? "failed" : state2.status === "streaming" ? "pending" : ["running", "completed"].includes(state2.status) ? state2.status : "unknown";
|
|
3041
|
-
const common = { ...native, callID: part.id, status: status2, endTime };
|
|
3204
|
+
const common = { ...native, callID: part.id, status: status2, endTime, ...executionFields(state2.input, state2.metadata), partial: Boolean(state2.metadata?.truncated) };
|
|
3042
3205
|
events.push(eventFor(message2, `${id2}:call`, "tool_call", part.name || "Tool call", "", { ...common, ...timing, input: eventText(state2.input) }));
|
|
3043
3206
|
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) }));
|
|
3044
3207
|
} else events.push(eventFor(message2, id2, "event", `${part.type || "Unknown"} content`, "Unsupported content.", { ...native, ...timing, partial: true }));
|
|
@@ -3068,7 +3231,7 @@ var opencodeAdapter = {
|
|
|
3068
3231
|
return {
|
|
3069
3232
|
projects: data.projects.map((p) => ({ ...p, id: identity("opencode", p.id) })),
|
|
3070
3233
|
warnings: data.warnings,
|
|
3071
|
-
sessions: data.sessions.map((s) => ({ locator: {}, revision: digest([
|
|
3234
|
+
sessions: data.sessions.map((s) => ({ locator: {}, revision: digest([4, s.updated, s.created, s.directory]), session: {
|
|
3072
3235
|
...s,
|
|
3073
3236
|
source: "opencode",
|
|
3074
3237
|
nativeID: s.id,
|
|
@@ -30411,7 +30574,7 @@ async function metadataState(path) {
|
|
|
30411
30574
|
}
|
|
30412
30575
|
}
|
|
30413
30576
|
async function claudeRevision(path) {
|
|
30414
|
-
return digest([
|
|
30577
|
+
return digest([7, (await state(path)).signature, (await metadataState(path))?.signature]);
|
|
30415
30578
|
}
|
|
30416
30579
|
async function bytes(path, max) {
|
|
30417
30580
|
const before = await state(path);
|
|
@@ -30466,7 +30629,8 @@ async function claudeTranscript(path, revision2) {
|
|
|
30466
30629
|
}
|
|
30467
30630
|
}
|
|
30468
30631
|
if (await claudeRevision(path) !== revision2) throw new Error("Claude transcript changed during import; import again.");
|
|
30469
|
-
const
|
|
30632
|
+
const byID = new Map(entries2.filter((row) => typeof row.uuid === "string").map((row) => [String(row.uuid), row]));
|
|
30633
|
+
const { size, modified } = await state(path), transcript = { entries: entries2, times, byID, partial, size, modified };
|
|
30470
30634
|
cached = { path, revision: revision2, transcript };
|
|
30471
30635
|
return transcript;
|
|
30472
30636
|
}
|
|
@@ -30511,7 +30675,7 @@ function expandHistory(buffer, maxOutputLength) {
|
|
|
30511
30675
|
}
|
|
30512
30676
|
|
|
30513
30677
|
// server/adapters/local-files.ts
|
|
30514
|
-
var
|
|
30678
|
+
var object2 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
30515
30679
|
var text = (value) => typeof value === "string" ? value : "";
|
|
30516
30680
|
var time = (value) => {
|
|
30517
30681
|
const n = typeof value === "number" ? value : typeof value === "string" ? /^\d{13}$/.test(value) ? Number(value) : Date.parse(value) : 0;
|
|
@@ -30567,7 +30731,7 @@ async function historyFiles(roots2, match2) {
|
|
|
30567
30731
|
if (limited) warnings.push("History discovery reached its file, directory, or depth limit.");
|
|
30568
30732
|
return { files: [...new Set(files)].sort(), warnings };
|
|
30569
30733
|
}
|
|
30570
|
-
function
|
|
30734
|
+
function json3(value) {
|
|
30571
30735
|
return JSON.parse(value);
|
|
30572
30736
|
}
|
|
30573
30737
|
function jsonLines(value) {
|
|
@@ -30578,7 +30742,7 @@ function jsonLines(value) {
|
|
|
30578
30742
|
if (rows2.length >= MAX_RECORDS) throw new Error("History exceeds the 50,000-record limit.");
|
|
30579
30743
|
if (line.length > 2e6) throw new Error("History contains a record larger than 2 MB.");
|
|
30580
30744
|
try {
|
|
30581
|
-
const row =
|
|
30745
|
+
const row = json3(line);
|
|
30582
30746
|
if (!row || typeof row !== "object" || Array.isArray(row)) partial = true;
|
|
30583
30747
|
else rows2.push(row);
|
|
30584
30748
|
} catch {
|
|
@@ -30706,7 +30870,7 @@ function conversationMessage(raw, fallbackID) {
|
|
|
30706
30870
|
const message2 = blankMessage(text(raw.id) || fallbackID, time(raw.timestamp ?? raw.ts), role);
|
|
30707
30871
|
let content = raw.content;
|
|
30708
30872
|
if (Array.isArray(content)) content = content.map((part) => {
|
|
30709
|
-
const p =
|
|
30873
|
+
const p = object2(part);
|
|
30710
30874
|
return p.type === "toolCall" ? { ...p, type: "tool_use", input: p.arguments } : p.type === "reasoning" ? { ...p, type: "thinking", thinking: p.text } : p;
|
|
30711
30875
|
});
|
|
30712
30876
|
if (raw.role === "thinking") content = [{ type: "thinking", thinking: raw.content }];
|
|
@@ -30727,7 +30891,7 @@ function conversationMessage(raw, fallbackID) {
|
|
|
30727
30891
|
else if (event.kind === "reasoning") addText(message2, event.text, "Assistant");
|
|
30728
30892
|
}
|
|
30729
30893
|
for (const call of Array.isArray(raw.toolCalls) ? raw.toolCalls : []) {
|
|
30730
|
-
const f =
|
|
30894
|
+
const f = object2(call.function);
|
|
30731
30895
|
if (!text(f.name)) continue;
|
|
30732
30896
|
message2.tools.push(f.name);
|
|
30733
30897
|
message2.events.push(eventFor(message2, `call:${text(call.id) || message2.events.length}`, "tool_call", f.name, "", { callID: text(call.id) || void 0, input: eventText(f.arguments), status: "unknown" }));
|
|
@@ -30741,7 +30905,7 @@ function googleMessage(raw, fallbackID) {
|
|
|
30741
30905
|
const parts = Array.isArray(raw.content) ? raw.content : raw.content != null ? [raw.content] : [];
|
|
30742
30906
|
const content = parts.map((part) => {
|
|
30743
30907
|
if (typeof part === "string") return { type: "text", text: part };
|
|
30744
|
-
const p =
|
|
30908
|
+
const p = object2(part);
|
|
30745
30909
|
if (typeof p.text === "string") return p.thought ? { type: "thinking", thinking: p.text } : { type: "text", text: p.text };
|
|
30746
30910
|
if (p.functionCall) return { type: "tool_use", ...p.functionCall, input: p.functionCall.args };
|
|
30747
30911
|
if (p.functionResponse) return { type: "tool_result", tool_use_id: p.functionResponse.id || raw.toolCallId, name: p.functionResponse.name, content: p.functionResponse.response, is_error: p.functionResponse.response?.error != null };
|
|
@@ -30755,7 +30919,7 @@ function successfulEdits(messages, editNames) {
|
|
|
30755
30919
|
if (event.kind === "tool_call" && event.callID) {
|
|
30756
30920
|
let input = {};
|
|
30757
30921
|
try {
|
|
30758
|
-
input =
|
|
30922
|
+
input = object2(JSON.parse(event.input || "{}"));
|
|
30759
30923
|
} catch {
|
|
30760
30924
|
}
|
|
30761
30925
|
calls.set(event.callID, { name: event.name, input });
|
|
@@ -30845,7 +31009,7 @@ var piAdapter = localFileAdapter({
|
|
|
30845
31009
|
var nativeText = (v3) => typeof v3 === "number" && Number.isSafeInteger(v3) ? String(v3) : text(v3);
|
|
30846
31010
|
var seconds = (v3) => typeof v3 === "number" && Number.isFinite(v3) && v3 > 0 ? v3 * 1e3 : time(v3);
|
|
30847
31011
|
var fileID = (path) => basename4(path).replace(/\.jsonl(?:\..*)?$|\.json$/, "");
|
|
30848
|
-
var sidecar2 = (files, path) =>
|
|
31012
|
+
var sidecar2 = (files, path) => object2(files.has(path) ? json3(files.get(path)) : void 0);
|
|
30849
31013
|
var roles = ["user", "assistant", "system", "tool", "toolResult", "model"];
|
|
30850
31014
|
function message(raw, id2, timestamp) {
|
|
30851
31015
|
if (!roles.includes(raw.role)) return;
|
|
@@ -30866,7 +31030,7 @@ function envelopeHistory(path, value) {
|
|
|
30866
31030
|
const header = rows2.find((r) => r.type === "session" || r.type === "session_start" || r.type === "session_startup") || {};
|
|
30867
31031
|
const nativeID = [...nativeIDs][0] || text(header.id || header.sessionId) || fileID(path);
|
|
30868
31032
|
const messages = rows2.flatMap((r, i) => {
|
|
30869
|
-
const body2 =
|
|
31033
|
+
const body2 = object2(r.message), role = body2.role || r.role || (["user", "assistant", "system"].includes(r.type) ? r.type : void 0);
|
|
30870
31034
|
const m = message({ ...body2, id: text(r.uuid || r.id) || body2.id, role, content: body2.content ?? r.content ?? r.text }, `record:${i}`, r.timestamp ?? body2.timestamp);
|
|
30871
31035
|
return m ? [m] : [];
|
|
30872
31036
|
});
|
|
@@ -30882,7 +31046,7 @@ function envelopeHistory(path, value) {
|
|
|
30882
31046
|
};
|
|
30883
31047
|
}
|
|
30884
31048
|
function ampHistory(path, files) {
|
|
30885
|
-
const raw =
|
|
31049
|
+
const raw = object2(json3(files.get(path)));
|
|
30886
31050
|
if (!text(raw.id) || !Array.isArray(raw.messages)) throw new Error("Unsupported Amp thread.");
|
|
30887
31051
|
const messages = raw.messages.flatMap((m, i) => {
|
|
30888
31052
|
const result = message(m, nativeText(m.messageId) || `message:${i}`, m.timestamp ?? m.usage?.timestamp);
|
|
@@ -30891,14 +31055,14 @@ function ampHistory(path, files) {
|
|
|
30891
31055
|
return { nativeID: raw.id, messages, partial: true, session: { created: time(raw.created), title: text(raw.title), directory: text(raw.cwd) }, note: "Amp local/exported thread messages. Usage-ledger ranges are not message timestamps. Export-only and missing content remain partial." };
|
|
30892
31056
|
}
|
|
30893
31057
|
function jcodeHistory(path, files) {
|
|
30894
|
-
const raw =
|
|
31058
|
+
const raw = object2(json3(files.get(path)));
|
|
30895
31059
|
if (!text(raw.id) || !Array.isArray(raw.messages)) throw new Error("Unsupported Jcode session.");
|
|
30896
31060
|
const journal = path.replace(/\.json$/, ".journal.jsonl");
|
|
30897
31061
|
const appended = files.has(journal) ? jsonLines(files.get(journal)) : { rows: [], partial: false };
|
|
30898
31062
|
const records = [...raw.messages];
|
|
30899
31063
|
for (const row of appended.rows) {
|
|
30900
31064
|
if (Array.isArray(row.append_messages)) records.push(...row.append_messages);
|
|
30901
|
-
if (row.meta) Object.assign(raw,
|
|
31065
|
+
if (row.meta) Object.assign(raw, object2(row.meta));
|
|
30902
31066
|
}
|
|
30903
31067
|
const seen = /* @__PURE__ */ new Set();
|
|
30904
31068
|
const messages = records.flatMap((r, i) => {
|
|
@@ -30911,7 +31075,7 @@ function jcodeHistory(path, files) {
|
|
|
30911
31075
|
return { nativeID: raw.id, messages, partial: appended.partial, session: { title: text(raw.title), directory: text(raw.working_dir), created: time(raw.created_at), model: text(raw.model) || "Unknown model", provider: text(raw.provider_key) }, note: "Jcode session snapshot and append journal; replayed native message IDs count once. Absent message times remain unknown." };
|
|
30912
31076
|
}
|
|
30913
31077
|
function codebuffHistory(path, files, free) {
|
|
30914
|
-
const records =
|
|
31078
|
+
const records = json3(files.get(path));
|
|
30915
31079
|
if (!Array.isArray(records)) throw new Error("Unsupported Codebuff chat.");
|
|
30916
31080
|
const isFree = records.some((m) => text(m.metadata?.runState?.sessionState?.mainAgentState?.agentType).startsWith("base2-free"));
|
|
30917
31081
|
if (isFree !== free) return;
|
|
@@ -30924,8 +31088,8 @@ function codebuffHistory(path, files, free) {
|
|
|
30924
31088
|
return { nativeID: `${project2}/${chat}`, messages, partial: true, note: "Codebuff/Freebuff persisted chat messages. Freebuff requires a recorded base2-free root-agent marker. Shared storage is attributed once; token counts are not estimated from text." };
|
|
30925
31089
|
}
|
|
30926
31090
|
function vibeHistory(path, files) {
|
|
30927
|
-
const raw =
|
|
30928
|
-
const meta = legacy ?
|
|
31091
|
+
const raw = object2(json3(files.get(path))), legacy = basename4(path) !== "meta.json";
|
|
31092
|
+
const meta = legacy ? object2(raw.metadata) : raw;
|
|
30929
31093
|
const transcript = join6(dirname2(path), "messages.jsonl");
|
|
30930
31094
|
const parsed = files.has(transcript) ? jsonLines(files.get(transcript)) : { rows: [], partial: false };
|
|
30931
31095
|
const records = legacy ? raw.messages : parsed.rows;
|
|
@@ -30952,7 +31116,7 @@ function acpHistory(path, value) {
|
|
|
30952
31116
|
}
|
|
30953
31117
|
};
|
|
30954
31118
|
for (const [i, row] of rows2.entries()) {
|
|
30955
|
-
const p =
|
|
31119
|
+
const p = object2(row.params), u2 = object2(p.update), kind = text(u2.sessionUpdate);
|
|
30956
31120
|
if (text(p.sessionId)) ids.add(p.sessionId);
|
|
30957
31121
|
const timestamp = time(p._meta?.agentTimestampMs) || time(row.timestamp);
|
|
30958
31122
|
const role = kind === "user_message_chunk" ? "user" : kind === "agent_message_chunk" ? "assistant" : "";
|
|
@@ -30978,7 +31142,7 @@ function dshHistory(value) {
|
|
|
30978
31142
|
if (!text(header?.id)) throw new Error("Unsupported DeepSeek Harness session.");
|
|
30979
31143
|
const messages = rows2.flatMap((r, i) => {
|
|
30980
31144
|
if (!["user/message", "assistant/message", "tool/message"].includes(r.type)) return [];
|
|
30981
|
-
const body2 =
|
|
31145
|
+
const body2 = object2(r.data?.message);
|
|
30982
31146
|
const m = message({ ...body2, role: body2.role || r.type.split("/")[0] }, text(body2.id) || `record:${i}`, r.time);
|
|
30983
31147
|
return m ? [m] : [];
|
|
30984
31148
|
});
|
|
@@ -30994,6 +31158,8 @@ import { chmodSync, constants as constants4, copyFileSync, lstatSync as lstatSyn
|
|
|
30994
31158
|
import { tmpdir } from "node:os";
|
|
30995
31159
|
import { join as join7 } from "node:path";
|
|
30996
31160
|
var copies = /* @__PURE__ */ new Map();
|
|
31161
|
+
var SqliteSnapshotChangedError = class extends Error {
|
|
31162
|
+
};
|
|
30997
31163
|
var close = (path) => {
|
|
30998
31164
|
const copy = copies.get(path);
|
|
30999
31165
|
if (!copy) return;
|
|
@@ -31023,16 +31189,16 @@ function withSqliteSnapshot(path, read3, expected, pinned = false) {
|
|
|
31023
31189
|
const retained = copies.get(path);
|
|
31024
31190
|
if (pinned && expected && retained?.revision === expected) return read3(retained.db);
|
|
31025
31191
|
const revision2 = sqliteRevision(path);
|
|
31026
|
-
if (expected && revision2 !== expected) throw new
|
|
31192
|
+
if (expected && revision2 !== expected) throw new SqliteSnapshotChangedError("History database changed during import; import again.");
|
|
31027
31193
|
let copy = copies.get(path);
|
|
31028
31194
|
if (copy?.revision !== revision2) {
|
|
31029
31195
|
close(path);
|
|
31030
31196
|
while (copies.size >= 2) close(copies.keys().next().value);
|
|
31031
|
-
const
|
|
31197
|
+
const directory3 = mkdtempSync(join7(tmpdir(), "sessiongraph-history-"));
|
|
31032
31198
|
let db2;
|
|
31033
31199
|
try {
|
|
31034
|
-
chmodSync(
|
|
31035
|
-
const destination = join7(
|
|
31200
|
+
chmodSync(directory3, 448);
|
|
31201
|
+
const destination = join7(directory3, "history.db");
|
|
31036
31202
|
for (const suffix of ["", "-wal"]) {
|
|
31037
31203
|
try {
|
|
31038
31204
|
copyFileSync(path + suffix, destination + suffix, constants4.COPYFILE_FICLONE);
|
|
@@ -31042,22 +31208,22 @@ function withSqliteSnapshot(path, read3, expected, pinned = false) {
|
|
|
31042
31208
|
throw error;
|
|
31043
31209
|
}
|
|
31044
31210
|
}
|
|
31045
|
-
if (sqliteRevision(path) !== revision2) throw new
|
|
31211
|
+
if (sqliteRevision(path) !== revision2) throw new SqliteSnapshotChangedError("History database changed while copying; import again.");
|
|
31046
31212
|
db2 = new DatabaseSync(destination, { readOnly: true, enableDoubleQuotedStringLiterals: false, allowExtension: false });
|
|
31047
31213
|
db2.exec("PRAGMA query_only=ON; PRAGMA trusted_schema=OFF; PRAGMA busy_timeout=1000; BEGIN;");
|
|
31048
|
-
copy = { revision: revision2, directory:
|
|
31214
|
+
copy = { revision: revision2, directory: directory3, db: db2 };
|
|
31049
31215
|
copies.set(path, copy);
|
|
31050
31216
|
} catch (error) {
|
|
31051
31217
|
try {
|
|
31052
31218
|
db2?.close();
|
|
31053
31219
|
} finally {
|
|
31054
|
-
rmSync2(
|
|
31220
|
+
rmSync2(directory3, { recursive: true, force: true });
|
|
31055
31221
|
}
|
|
31056
31222
|
throw error;
|
|
31057
31223
|
}
|
|
31058
31224
|
}
|
|
31059
31225
|
const result = read3(copy.db);
|
|
31060
|
-
if (!pinned && sqliteRevision(path) !== revision2) throw new
|
|
31226
|
+
if (!pinned && sqliteRevision(path) !== revision2) throw new SqliteSnapshotChangedError("History database changed during reading; import again.");
|
|
31061
31227
|
return result;
|
|
31062
31228
|
}
|
|
31063
31229
|
function hasTable(db2, name) {
|
|
@@ -31138,18 +31304,23 @@ function sqliteHistoryAdapter(source) {
|
|
|
31138
31304
|
let unavailable = false;
|
|
31139
31305
|
for (const path of await source.paths()) {
|
|
31140
31306
|
try {
|
|
31141
|
-
const snapshot2 = sqliteRevision(path), rev = digest([2, source.id, snapshot2]);
|
|
31307
|
+
const snapshot2 = sqliteRevision(path), rev = digest([source.version || 2, source.id, snapshot2]);
|
|
31142
31308
|
let cached2 = metadata2.get(path);
|
|
31143
31309
|
if (!cached2 || cached2.revision !== rev) {
|
|
31144
31310
|
cached2 = withSqliteSnapshot(path, (db2) => {
|
|
31145
31311
|
const table = typeof source.table === "string" ? source.table : source.table(db2);
|
|
31146
31312
|
const values2 = rows(db2, table, source.fields, void 0, source.key, 2e4), found = [];
|
|
31147
31313
|
const blocked2 = [], warnings2 = [];
|
|
31314
|
+
let empty = 0;
|
|
31148
31315
|
for (const row of values2) {
|
|
31149
31316
|
try {
|
|
31150
31317
|
const h3 = parseHistory(source, db2, row, path);
|
|
31151
31318
|
if (!h3) continue;
|
|
31152
|
-
if (source.history !== false && !h3.messages.length)
|
|
31319
|
+
if (source.history !== false && !h3.messages.length) {
|
|
31320
|
+
blocked2.push(identity(source.id, String(row[source.key])));
|
|
31321
|
+
empty++;
|
|
31322
|
+
continue;
|
|
31323
|
+
}
|
|
31153
31324
|
if (!h3.nativeID || h3.nativeID.length > 512) throw new Error("Missing native session identity.");
|
|
31154
31325
|
const created = time(h3.session?.created) || h3.messages.map((m) => time(m.time)).find(Boolean);
|
|
31155
31326
|
if (!created) throw new Error("Session has no recorded creation or message date.");
|
|
@@ -31169,7 +31340,8 @@ function sqliteHistoryAdapter(source) {
|
|
|
31169
31340
|
blocked2.push(identity(source.id, String(row[source.key])));
|
|
31170
31341
|
}
|
|
31171
31342
|
}
|
|
31172
|
-
if (blocked2.length) warnings2.push(`${blocked2.length} ${source.name} sessions had unsupported, undated, missing, or oversized history; saved imports are kept.`);
|
|
31343
|
+
if (blocked2.length > empty) warnings2.push(`${blocked2.length - empty} ${source.name} sessions had unsupported, undated, missing, or oversized history; saved imports are kept.`);
|
|
31344
|
+
if (empty) warnings2.push(`${empty} empty ${source.name} sessions had no saved messages; previous imports are kept.`);
|
|
31173
31345
|
return { revision: rev, candidates: found, blocked: blocked2, warnings: warnings2 };
|
|
31174
31346
|
}, snapshot2);
|
|
31175
31347
|
metadata2.set(path, cached2);
|
|
@@ -31254,7 +31426,7 @@ function combineAdapters(parts) {
|
|
|
31254
31426
|
|
|
31255
31427
|
// server/adapters/claude.ts
|
|
31256
31428
|
var root = () => join8(sourcePath("claude-code") || process.env.CLAUDE_CONFIG_DIR || join8(homedir4(), ".claude"), "projects");
|
|
31257
|
-
function claudeMessages(rows2, candidate, times) {
|
|
31429
|
+
function claudeMessages(rows2, candidate, times, entries2) {
|
|
31258
31430
|
const calls = /* @__PURE__ */ new Map();
|
|
31259
31431
|
return rows2.map((row) => {
|
|
31260
31432
|
const raw = row.message;
|
|
@@ -31279,7 +31451,18 @@ function claudeMessages(rows2, candidate, times) {
|
|
|
31279
31451
|
}
|
|
31280
31452
|
}
|
|
31281
31453
|
}
|
|
31282
|
-
|
|
31454
|
+
const entry = entries2?.get(row.uuid), structured = entry?.tool_use_result ?? entry?.toolUseResult;
|
|
31455
|
+
const results = Array.isArray(raw?.content) ? raw.content.filter((p) => p.type === "tool_result") : [];
|
|
31456
|
+
msg.events = blockEvents(msg, raw?.content).map((event) => {
|
|
31457
|
+
const result = event.kind === "tool_result" && results.length === 1 ? structured : void 0;
|
|
31458
|
+
return {
|
|
31459
|
+
...event,
|
|
31460
|
+
parentID: row.parent_tool_use_id || void 0,
|
|
31461
|
+
...executionFields({}, { ...result, cwd: entry?.cwd }),
|
|
31462
|
+
gitCommit: nativeCommit(result?.gitOperation?.commit),
|
|
31463
|
+
partial: Boolean(event.partial || result?.interrupted || result?.backgroundTaskId || result?.backgroundedByUser || result?.timedOutAfterMs || entry?.sessionId && entry.sessionId !== (candidate.locator.parent || candidate.session.nativeID))
|
|
31464
|
+
};
|
|
31465
|
+
});
|
|
31283
31466
|
if (!msg.events.length) msg.events = [eventFor(msg, "event", raw?.subtype === "compact_boundary" ? "compaction" : "event", raw?.subtype || `${row.type} event`, eventText(raw), { nativeType: raw?.subtype || row.type, partial: true })];
|
|
31284
31467
|
return msg;
|
|
31285
31468
|
});
|
|
@@ -31380,7 +31563,7 @@ var sdkClaudeAdapter = {
|
|
|
31380
31563
|
const options = { dir: candidate.locator.dir || void 0, offset: start, limit: count + 1, sessionStore: claudeTranscriptStore(transcript, sessionId, candidate.locator.agent) };
|
|
31381
31564
|
const rows2 = candidate.locator.parent ? await U1t(candidate.locator.parent, candidate.locator.agent, options) : await P1t(candidate.session.nativeID, options);
|
|
31382
31565
|
const more = rows2.length > count;
|
|
31383
|
-
const messages = claudeMessages(rows2.slice(0, count), candidate, transcript.times).slice(offset - start);
|
|
31566
|
+
const messages = claudeMessages(rows2.slice(0, count), candidate, transcript.times, transcript.byID).slice(offset - start);
|
|
31384
31567
|
if (!offset && !messages.length && transcript.size > 100) throw new Error("SDK returned no readable conversation for this transcript.");
|
|
31385
31568
|
if (!more && await claudeRevision(candidate.locator.path) !== candidate.revision) throw new Error("Session changed during import; import again to capture the latest messages.");
|
|
31386
31569
|
return { messages, cursor: more ? String(offset + 120) : void 0, partial: transcript.partial, note: `SDK-visible conversation chain from the local CLI/VS Code transcript; pre-compaction text and unsupported message types may be absent. Fork ancestry is unavailable.${transcript.partial ? " Some transcript records or subagent metadata were unreadable." : ""}` };
|
|
@@ -31499,7 +31682,7 @@ async function transcriptFiles(root3, max = 2e4, match2 = (name) => name.endsWit
|
|
|
31499
31682
|
var root2 = () => sourcePath("codex") || process.env.CODEX_HOME || join10(homedir5(), ".codex");
|
|
31500
31683
|
var revision = async (path) => {
|
|
31501
31684
|
const s = await stat2(path);
|
|
31502
|
-
return digest([
|
|
31685
|
+
return digest([10, s.mtimeMs, s.size]);
|
|
31503
31686
|
};
|
|
31504
31687
|
function changedPaths(value) {
|
|
31505
31688
|
if (!value || typeof value !== "object") return [];
|
|
@@ -31509,9 +31692,14 @@ function changedPaths(value) {
|
|
|
31509
31692
|
function codexUserText(value) {
|
|
31510
31693
|
if (typeof value !== "string") return "";
|
|
31511
31694
|
let text2 = value.trim();
|
|
31695
|
+
for (; ; ) {
|
|
31696
|
+
const context = text2.match(/^<(environment_context|permissions|user_instructions|turn_aborted|system_instruction|recommended_plugins|external_codex_[\w-]+)(?:\s[^>]*)?>/i);
|
|
31697
|
+
if (!context) break;
|
|
31698
|
+
const end = text2.toLowerCase().indexOf(`</${context[1].toLowerCase()}>`, context[0].length);
|
|
31699
|
+
if (end < 0) return "";
|
|
31700
|
+
text2 = text2.slice(end + context[1].length + 3).trim();
|
|
31701
|
+
}
|
|
31512
31702
|
if (/^# (?:AGENTS\.md|Instructions for)/i.test(text2)) return "";
|
|
31513
|
-
text2 = text2.replace(/<(environment_context|permissions|user_instructions|turn_aborted|external_codex_[\w-]+)>[\s\S]*?<\/\1>/g, "").trim();
|
|
31514
|
-
if (/^<(?:environment_context|permissions|user_instructions|turn_aborted|external_codex_[\w-]+)(?:>|\s)/.test(text2)) return "";
|
|
31515
31703
|
return text2;
|
|
31516
31704
|
}
|
|
31517
31705
|
async function sessionNames() {
|
|
@@ -31532,6 +31720,7 @@ async function sessionNames() {
|
|
|
31532
31720
|
function codexRecord(raw, offset, candidate) {
|
|
31533
31721
|
const p = raw.payload;
|
|
31534
31722
|
if (!p || typeof p !== "object") return;
|
|
31723
|
+
if (raw.type === "session_meta" || raw.type === "turn_context") candidate.locator.executionCwd = typeof p.cwd === "string" ? p.cwd : "";
|
|
31535
31724
|
if (raw.type === "turn_context" && typeof p.model === "string") candidate.session.model = p.model;
|
|
31536
31725
|
if (raw.type === "event_msg" && p.type === "item_completed" && ["FileChange", "fileChange"].includes(p.item?.type)) {
|
|
31537
31726
|
const msg2 = blankMessage(`event:${p.item.id || raw.ordinal || offset}`, p.completed_at_ms || Date.parse(raw.timestamp) || 0, "tool");
|
|
@@ -31563,9 +31752,15 @@ function codexRecord(raw, offset, candidate) {
|
|
|
31563
31752
|
}
|
|
31564
31753
|
const role = p.role === "user" ? "user" : p.role === "assistant" ? "assistant" : p.type === "message" ? "system" : "tool";
|
|
31565
31754
|
const msg = blankMessage(`item:${raw.ordinal ?? offset}`, Date.parse(raw.timestamp) || 0, role);
|
|
31566
|
-
|
|
31567
|
-
|
|
31568
|
-
|
|
31755
|
+
let input = p.arguments ?? p.input;
|
|
31756
|
+
if (typeof input === "string") {
|
|
31757
|
+
try {
|
|
31758
|
+
input = JSON.parse(input);
|
|
31759
|
+
} catch {
|
|
31760
|
+
}
|
|
31761
|
+
}
|
|
31762
|
+
const fields2 = { nativeID: p.id, nativeType: p.type, callID: p.call_id, ...executionFields(input, { cwd: candidate.locator.executionCwd }) };
|
|
31763
|
+
msg.events = p.type === "message" ? role === "user" ? userBlockEvents(msg, p.content, codexUserText) : blockEvents(msg, p.content) : ["function_call", "custom_tool_call"].includes(p.type) ? [eventFor(msg, "call", "tool_call", p.name || "Tool call", "", { ...fields2, role: "assistant", input: eventText(p.arguments ?? p.input), status: "unknown" })] : ["function_call_output", "custom_tool_call_output"].includes(p.type) ? [eventFor(msg, "result", "tool_result", "Tool result", "", { ...fields2, output: eventText(p.output, 64e3), status: "unknown" })] : [eventFor(msg, "event", p.type === "reasoning" ? "reasoning" : "event", p.type === "reasoning" ? "Recorded reasoning summary" : p.type || "Unknown event", eventText(p.type === "reasoning" ? p.summary : p), { ...fields2, partial: p.type === "reasoning" })];
|
|
31569
31764
|
if (p.type === "message") {
|
|
31570
31765
|
for (const part of Array.isArray(p.content) ? p.content : []) if (["input_text", "output_text", "text"].includes(part.type)) addText(msg, role === "user" ? codexUserText(part.text) : part.text, role === "user" ? "You" : "Assistant");
|
|
31571
31766
|
} else if (["function_call", "custom_tool_call"].includes(p.type)) {
|
|
@@ -31639,6 +31834,7 @@ var codexAdapter = {
|
|
|
31639
31834
|
})).values()], warnings };
|
|
31640
31835
|
},
|
|
31641
31836
|
async read(candidate, cursor) {
|
|
31837
|
+
if (!cursor) candidate.locator.executionCwd = "";
|
|
31642
31838
|
const page = await readJSONL(candidate.locator.path, Number(cursor || 0));
|
|
31643
31839
|
if (page.cursor === void 0 && await revision(candidate.locator.path) !== candidate.revision) throw new Error("Session changed during import; import again to capture the latest messages.");
|
|
31644
31840
|
return { messages: page.rows.flatMap((r) => {
|
|
@@ -31657,7 +31853,8 @@ var PAGE = 100;
|
|
|
31657
31853
|
var MAX_THREADS = 2e4;
|
|
31658
31854
|
var MAX_ITEM_JSON = 256e3;
|
|
31659
31855
|
var providerSource = { codex: "codex", claudeAgent: "claude-code", opencode: "opencode" };
|
|
31660
|
-
var
|
|
31856
|
+
var openCodeEditTools = /* @__PURE__ */ new Set(["patch", "apply_patch", "edit", "write", "multiedit"]);
|
|
31857
|
+
var string2 = (value) => typeof value === "string" ? value : "";
|
|
31661
31858
|
function parsedObject(value) {
|
|
31662
31859
|
if (typeof value !== "string") return;
|
|
31663
31860
|
try {
|
|
@@ -31672,7 +31869,7 @@ function time2(value) {
|
|
|
31672
31869
|
return Number.isFinite(parsed) && parsed > 0 && parsed <= 864e13 ? parsed : 0;
|
|
31673
31870
|
}
|
|
31674
31871
|
function status(value) {
|
|
31675
|
-
return ["pending", "running", "completed", "failed"].includes(
|
|
31872
|
+
return ["pending", "running", "completed", "failed"].includes(string2(value)) ? value : "unknown";
|
|
31676
31873
|
}
|
|
31677
31874
|
async function databasePath2() {
|
|
31678
31875
|
const root3 = sourcePath("t3-code") || process.env.SESSIONGRAPH_T3_CODE_HISTORY_DIR || process.env.T3CODE_HOME || join11(homedir6(), ".t3");
|
|
@@ -31701,7 +31898,7 @@ function projectRoots(db2, ids) {
|
|
|
31701
31898
|
for (const batch of batches([...new Set(ids.filter(Boolean))])) {
|
|
31702
31899
|
const placeholders = batch.map(() => "?").join(",");
|
|
31703
31900
|
for (const row of db2.prepare(`SELECT project_id, substr(workspace_root,1,4096) AS workspace_root FROM projection_projects WHERE deleted_at IS NULL AND project_id IN (${placeholders})`).all(...batch))
|
|
31704
|
-
roots2.set(
|
|
31901
|
+
roots2.set(string2(row.project_id), string2(row.workspace_root));
|
|
31705
31902
|
}
|
|
31706
31903
|
return roots2;
|
|
31707
31904
|
}
|
|
@@ -31711,7 +31908,7 @@ function aggregates(db2, table, ids) {
|
|
|
31711
31908
|
for (const batch of batches(ids)) {
|
|
31712
31909
|
const placeholders = batch.map(() => "?").join(",");
|
|
31713
31910
|
for (const row of db2.prepare(`SELECT thread_id, COUNT(*) AS n, MAX(updated_at) AS latest FROM ${table} WHERE thread_id IN (${placeholders}) GROUP BY thread_id`).all(...batch))
|
|
31714
|
-
result.set(
|
|
31911
|
+
result.set(string2(row.thread_id), [Number(row.n), string2(row.latest)]);
|
|
31715
31912
|
}
|
|
31716
31913
|
return result;
|
|
31717
31914
|
}
|
|
@@ -31725,10 +31922,10 @@ function linkedSessions(db2, ids) {
|
|
|
31725
31922
|
CASE WHEN json_valid(payload_json) THEN json_extract(payload_json,'$.nativeThreadRef.strength') END AS strength,
|
|
31726
31923
|
CASE WHEN json_valid(payload_json) THEN json_extract(payload_json,'$.nativeThreadRef.driver') END AS driver
|
|
31727
31924
|
FROM orchestration_v2_projection_provider_threads WHERE thread_id IN (${placeholders})`).all(...batch)) {
|
|
31728
|
-
const source = providerSource[
|
|
31729
|
-
const nativeID =
|
|
31925
|
+
const source = providerSource[string2(row.provider)];
|
|
31926
|
+
const nativeID = string2(row.native_id);
|
|
31730
31927
|
if (!source || row.strength !== "strong" || row.driver && row.driver !== row.provider || !nativeID || nativeID.length > 512) continue;
|
|
31731
|
-
const id2 =
|
|
31928
|
+
const id2 = string2(row.thread_id);
|
|
31732
31929
|
links.set(id2, [.../* @__PURE__ */ new Set([...links.get(id2) || [], identity(source, nativeID)])]);
|
|
31733
31930
|
}
|
|
31734
31931
|
}
|
|
@@ -31743,8 +31940,8 @@ function discoverV2(db2, path, databaseRevision) {
|
|
|
31743
31940
|
CASE WHEN json_valid(payload_json) THEN json_extract(payload_json,'$.lineage.relationshipToParent') END AS relationship,
|
|
31744
31941
|
json_valid(payload_json) AS valid_payload
|
|
31745
31942
|
FROM orchestration_v2_projection_threads WHERE deleted_at IS NULL ORDER BY created_at, thread_id LIMIT ?`).all(MAX_THREADS + 1);
|
|
31746
|
-
const selected = rows2.slice(0, MAX_THREADS), ids = selected.map((row) =>
|
|
31747
|
-
const roots2 = projectRoots(db2, selected.map((row) =>
|
|
31943
|
+
const selected = rows2.slice(0, MAX_THREADS), ids = selected.map((row) => string2(row.thread_id));
|
|
31944
|
+
const roots2 = projectRoots(db2, selected.map((row) => string2(row.project_id)));
|
|
31748
31945
|
const counts = aggregates(db2, "orchestration_v2_projection_messages", ids);
|
|
31749
31946
|
const items = aggregates(db2, "orchestration_v2_projection_turn_items", ids);
|
|
31750
31947
|
const links = linkedSessions(db2, ids);
|
|
@@ -31752,28 +31949,28 @@ function discoverV2(db2, path, databaseRevision) {
|
|
|
31752
31949
|
if (rows2.length > MAX_THREADS) warnings.push(`T3 Code discovery is limited to ${MAX_THREADS.toLocaleString()} threads.`);
|
|
31753
31950
|
let unreadableMetadata = 0;
|
|
31754
31951
|
for (const row of selected) {
|
|
31755
|
-
const nativeID =
|
|
31952
|
+
const nativeID = string2(row.thread_id), created = time2(row.created_at);
|
|
31756
31953
|
if (!nativeID || nativeID.length > 512 || !created) continue;
|
|
31757
31954
|
if (!row.valid_payload) unreadableMetadata++;
|
|
31758
|
-
const
|
|
31759
|
-
const p = project(SOURCE,
|
|
31955
|
+
const directory3 = string2(row.worktree_path) || roots2.get(string2(row.project_id)) || "";
|
|
31956
|
+
const p = project(SOURCE, directory3);
|
|
31760
31957
|
projects.set(p.id, p);
|
|
31761
|
-
const session = blankSession(SOURCE, nativeID,
|
|
31762
|
-
const parent2 =
|
|
31958
|
+
const session = blankSession(SOURCE, nativeID, directory3);
|
|
31959
|
+
const parent2 = string2(row.parent_thread_id);
|
|
31763
31960
|
session.parentID = row.relationship === "subagent" && parent2 ? identity(SOURCE, parent2) : void 0;
|
|
31764
31961
|
session.forkID = row.relationship === "fork" && parent2 ? identity(SOURCE, parent2) : void 0;
|
|
31765
31962
|
Object.assign(session, {
|
|
31766
|
-
title:
|
|
31963
|
+
title: string2(row.title) || "T3 Code thread",
|
|
31767
31964
|
projectID: p.id,
|
|
31768
31965
|
created,
|
|
31769
31966
|
updated: time2(row.updated_at) || created,
|
|
31770
31967
|
archived: Boolean(row.archived_at),
|
|
31771
|
-
model:
|
|
31772
|
-
provider:
|
|
31968
|
+
model: string2(row.model) || "Unknown model",
|
|
31969
|
+
provider: string2(row.default_provider),
|
|
31773
31970
|
agent: "T3 Code",
|
|
31774
31971
|
linkedSessionIDs: links.get(nativeID) || []
|
|
31775
31972
|
});
|
|
31776
|
-
const revision2 = digest([row.updated_at, counts.get(nativeID), items.get(nativeID), links.get(nativeID)]);
|
|
31973
|
+
const revision2 = digest([3, row.updated_at, counts.get(nativeID), items.get(nativeID), links.get(nativeID)]);
|
|
31777
31974
|
sessions.push({ session, revision: revision2, locator: { path, databaseRevision, threadID: nativeID, format: "v2", metadataPartial: row.valid_payload ? "" : "1" } });
|
|
31778
31975
|
}
|
|
31779
31976
|
if (unreadableMetadata) warnings.push(`${unreadableMetadata} T3 Code threads had unreadable metadata; model or lineage may be unavailable.`);
|
|
@@ -31786,23 +31983,23 @@ function discoverV1(db2, path, databaseRevision) {
|
|
|
31786
31983
|
CASE WHEN json_valid(model_selection_json) THEN substr(json_extract(model_selection_json,'$.model'),1,200) END AS model
|
|
31787
31984
|
FROM projection_threads WHERE deleted_at IS NULL ORDER BY created_at, thread_id LIMIT ?`).all(MAX_THREADS + 1);
|
|
31788
31985
|
const selected = rows2.slice(0, MAX_THREADS);
|
|
31789
|
-
const roots2 = projectRoots(db2, selected.map((row) =>
|
|
31790
|
-
const counts = aggregates(db2, "projection_thread_messages", selected.map((row) =>
|
|
31986
|
+
const roots2 = projectRoots(db2, selected.map((row) => string2(row.project_id)));
|
|
31987
|
+
const counts = aggregates(db2, "projection_thread_messages", selected.map((row) => string2(row.thread_id)));
|
|
31791
31988
|
const sessions = [], projects = /* @__PURE__ */ new Map();
|
|
31792
31989
|
for (const row of selected) {
|
|
31793
|
-
const nativeID =
|
|
31990
|
+
const nativeID = string2(row.thread_id), created = time2(row.created_at);
|
|
31794
31991
|
if (!nativeID || nativeID.length > 512 || !created) continue;
|
|
31795
|
-
const
|
|
31796
|
-
const p = project(SOURCE,
|
|
31992
|
+
const directory3 = string2(row.worktree_path) || roots2.get(string2(row.project_id)) || "";
|
|
31993
|
+
const p = project(SOURCE, directory3);
|
|
31797
31994
|
projects.set(p.id, p);
|
|
31798
|
-
const session = blankSession(SOURCE, nativeID,
|
|
31995
|
+
const session = blankSession(SOURCE, nativeID, directory3);
|
|
31799
31996
|
Object.assign(session, {
|
|
31800
|
-
title:
|
|
31997
|
+
title: string2(row.title) || "T3 Code thread",
|
|
31801
31998
|
projectID: p.id,
|
|
31802
31999
|
created,
|
|
31803
32000
|
updated: time2(row.updated_at) || created,
|
|
31804
32001
|
archived: Boolean(row.archived_at),
|
|
31805
|
-
model:
|
|
32002
|
+
model: string2(row.model) || "Unknown model",
|
|
31806
32003
|
agent: "T3 Code"
|
|
31807
32004
|
});
|
|
31808
32005
|
sessions.push({ session, revision: digest([row.updated_at, counts.get(nativeID)]), locator: { path, databaseRevision, threadID: nativeID, format: "v1" } });
|
|
@@ -31811,15 +32008,15 @@ function discoverV1(db2, path, databaseRevision) {
|
|
|
31811
32008
|
if (rows2.length > MAX_THREADS) warnings.push(`T3 Code discovery is limited to ${MAX_THREADS.toLocaleString()} threads.`);
|
|
31812
32009
|
return { sessions, projects: [...projects.values()], warnings };
|
|
31813
32010
|
}
|
|
31814
|
-
function v2Message(row,
|
|
31815
|
-
const parsed = parsedObject(row.payload_json), item = parsed || {}, type =
|
|
32011
|
+
function v2Message(row, directory3) {
|
|
32012
|
+
const parsed = parsedObject(row.payload_json), item = parsed || {}, type = string2(row.type), id2 = string2(row.turn_item_id);
|
|
31816
32013
|
const role = type === "user_message" ? "user" : type === "assistant_message" ? "assistant" : type === "reasoning" ? "assistant" : "tool";
|
|
31817
32014
|
const message2 = blankMessage(`item:${id2}`, time2(item.startedAt || item.createdAt), role);
|
|
31818
|
-
const recorded = Boolean(message2.time), name =
|
|
32015
|
+
const recorded = Boolean(message2.time), name = string2(item.title || item.toolName) || type.replaceAll("_", " ");
|
|
31819
32016
|
const fields2 = {
|
|
31820
32017
|
nativeID: id2,
|
|
31821
32018
|
nativeType: type,
|
|
31822
|
-
parentID:
|
|
32019
|
+
parentID: string2(item.parentItemId) || void 0,
|
|
31823
32020
|
status: status(row.status),
|
|
31824
32021
|
endTime: time2(item.completedAt) || null,
|
|
31825
32022
|
timeSource: recorded ? "recorded" : "unknown"
|
|
@@ -31830,34 +32027,42 @@ function v2Message(row, directory2) {
|
|
|
31830
32027
|
return message2;
|
|
31831
32028
|
}
|
|
31832
32029
|
if (type === "user_message" || type === "assistant_message") {
|
|
31833
|
-
const body2 =
|
|
32030
|
+
const body2 = string2(item.text);
|
|
31834
32031
|
if (body2) addText(message2, body2, role === "user" ? "You" : "Assistant");
|
|
31835
32032
|
message2.events = [{ ...messageEvent(message2, body2, id2), ...fields2 }];
|
|
31836
32033
|
if (Array.isArray(item.attachments) && item.attachments.length) message2.partial = true;
|
|
31837
32034
|
return message2;
|
|
31838
32035
|
}
|
|
31839
32036
|
if (type === "reasoning") {
|
|
31840
|
-
message2.events = [eventFor(message2, id2, "reasoning", "Recorded reasoning",
|
|
32037
|
+
message2.events = [eventFor(message2, id2, "reasoning", "Recorded reasoning", string2(item.text), fields2)];
|
|
31841
32038
|
return message2;
|
|
31842
32039
|
}
|
|
31843
32040
|
if (type === "file_change") {
|
|
31844
|
-
const file =
|
|
31845
|
-
|
|
32041
|
+
const file = string2(item.fileName), completed = status(row.status) === "completed";
|
|
32042
|
+
const native = item.nativeItemRef;
|
|
32043
|
+
if (native?.driver === "opencode" && openCodeEditTools.has(file.toLowerCase())) {
|
|
32044
|
+
message2.tools.push(file);
|
|
32045
|
+
const kind2 = completed || fields2.status === "failed" ? "tool_result" : "tool_call";
|
|
32046
|
+
message2.events = [eventFor(message2, id2, kind2, file, "", { ...fields2, callID: string2(native.nativeId) || void 0 })];
|
|
32047
|
+
return message2;
|
|
32048
|
+
}
|
|
32049
|
+
if (file && completed) message2.files.push({ path: isAbsolute2(file) ? file : join11(directory3, file), source: "file change", steps: 1 });
|
|
31846
32050
|
message2.events = [eventFor(message2, id2, "file_change", file || name, "", fields2)];
|
|
31847
32051
|
return message2;
|
|
31848
32052
|
}
|
|
31849
32053
|
if (["command_execution", "dynamic_tool", "file_search", "web_search"].includes(type)) {
|
|
31850
32054
|
const input = eventText(item.input ?? item.pattern ?? item.patterns, 32e3);
|
|
31851
|
-
const
|
|
32055
|
+
const output2 = eventText(item.output ?? item.results, 64e3);
|
|
31852
32056
|
const kind2 = fields2.status === "completed" || fields2.status === "failed" ? "tool_result" : "tool_call";
|
|
31853
32057
|
message2.tools.push(name);
|
|
31854
32058
|
if (input) addText(message2, input, "Tool");
|
|
31855
|
-
if (
|
|
31856
|
-
|
|
32059
|
+
if (output2) addText(message2, output2, "Tool");
|
|
32060
|
+
const native = item.nativeItemRef;
|
|
32061
|
+
message2.events = [eventFor(message2, id2, kind2, name, "", { ...fields2, input, output: output2, ...executionFields(parsedObject(item.input) || item.input, item), callID: string2(native?.nativeId) || void 0 })];
|
|
31857
32062
|
return message2;
|
|
31858
32063
|
}
|
|
31859
32064
|
const kind = type === "compaction" ? "compaction" : type === "error" ? "error" : "event";
|
|
31860
|
-
message2.events = [eventFor(message2, id2, kind, name,
|
|
32065
|
+
message2.events = [eventFor(message2, id2, kind, name, string2(item.text), fields2)];
|
|
31861
32066
|
return message2;
|
|
31862
32067
|
}
|
|
31863
32068
|
function readV2(db2, candidate, cursor) {
|
|
@@ -31890,9 +32095,9 @@ function readV1(db2, candidate, cursor) {
|
|
|
31890
32095
|
const messages = rows2.slice(0, PAGE).map((row) => {
|
|
31891
32096
|
const role = row.role === "user" ? "user" : row.role === "assistant" ? "assistant" : "system";
|
|
31892
32097
|
const message2 = blankMessage(`message:${row.message_id}`, time2(row.created_at), role);
|
|
31893
|
-
const body2 =
|
|
32098
|
+
const body2 = string2(row.text);
|
|
31894
32099
|
if (body2) addText(message2, body2, role === "user" ? "You" : "Assistant");
|
|
31895
|
-
message2.events = [{ ...messageEvent(message2, body2), nativeID:
|
|
32100
|
+
message2.events = [{ ...messageEvent(message2, body2), nativeID: string2(row.message_id), nativeType: "legacy-message" }];
|
|
31896
32101
|
message2.partial = row.text == null;
|
|
31897
32102
|
return message2;
|
|
31898
32103
|
});
|
|
@@ -31914,8 +32119,14 @@ var t3CodeAdapter = {
|
|
|
31914
32119
|
async discover() {
|
|
31915
32120
|
const path = await databasePath2();
|
|
31916
32121
|
if (!path) return { sessions: [], projects: [], warnings: ["T3 Code database is unavailable. Saved history is retained."] };
|
|
31917
|
-
|
|
31918
|
-
|
|
32122
|
+
for (let attempt = 0; ; attempt++) {
|
|
32123
|
+
const databaseRevision = sqliteRevision(path);
|
|
32124
|
+
try {
|
|
32125
|
+
return withSqliteSnapshot(path, (db2) => hasTable(db2, "orchestration_v2_projection_threads") ? discoverV2(db2, path, databaseRevision) : discoverV1(db2, path, databaseRevision), databaseRevision);
|
|
32126
|
+
} catch (error) {
|
|
32127
|
+
if (!(error instanceof SqliteSnapshotChangedError) || attempt >= 2) throw error;
|
|
32128
|
+
}
|
|
32129
|
+
}
|
|
31919
32130
|
},
|
|
31920
32131
|
async read(candidate, cursor) {
|
|
31921
32132
|
return withSqliteSnapshot(candidate.locator.path, (db2) => candidate.locator.format === "v2" ? readV2(db2, candidate, cursor) : readV1(db2, candidate, cursor), candidate.locator.databaseRevision, true);
|
|
@@ -31934,8 +32145,26 @@ function cursorTime(value) {
|
|
|
31934
32145
|
const time4 = typeof value === "number" ? value : typeof value === "string" && /(?:Z|[+-]\d\d:\d\d)$/.test(value) ? Date.parse(value) : 0;
|
|
31935
32146
|
return Number.isFinite(time4) && time4 > 0 && time4 <= 864e13 ? time4 : 0;
|
|
31936
32147
|
}
|
|
32148
|
+
function cursorEnvelope(text2) {
|
|
32149
|
+
let value = text2.trim(), timestamp;
|
|
32150
|
+
for (; ; ) {
|
|
32151
|
+
value = value.replace(/^(?:\[Image\]\s*)+(?=<image_files>)/, "");
|
|
32152
|
+
const clock = value.match(/^<timestamp>([^<]+)<\/timestamp>\s*/);
|
|
32153
|
+
if (clock) {
|
|
32154
|
+
timestamp ??= clock[1];
|
|
32155
|
+
value = value.slice(clock[0].length);
|
|
32156
|
+
continue;
|
|
32157
|
+
}
|
|
32158
|
+
const context = value.match(/^<(user_info|environment_context|system_reminder|external_links|attached_files|image_files)(?:\s[^>]*)?>/);
|
|
32159
|
+
if (!context) break;
|
|
32160
|
+
const end = value.indexOf(`</${context[1]}>`, context[0].length);
|
|
32161
|
+
if (end < 0) return { text: "", timestamp };
|
|
32162
|
+
value = value.slice(end + context[1].length + 3).trim();
|
|
32163
|
+
}
|
|
32164
|
+
return { text: value, timestamp };
|
|
32165
|
+
}
|
|
31937
32166
|
function cursorEnvelopeTime(text2) {
|
|
31938
|
-
const value = text2.
|
|
32167
|
+
const value = cursorEnvelope(text2).timestamp;
|
|
31939
32168
|
if (!value) return 0;
|
|
31940
32169
|
const iso = cursorTime(value);
|
|
31941
32170
|
if (iso) return iso;
|
|
@@ -31944,17 +32173,21 @@ function cursorEnvelopeTime(text2) {
|
|
|
31944
32173
|
return cursorTime(Date.parse(`${match2[1]} ${match2[2]} GMT${match2[3]}${match2[4].padStart(2, "0")}${match2[5] || "00"}`));
|
|
31945
32174
|
}
|
|
31946
32175
|
function cursorUserText(text2) {
|
|
31947
|
-
|
|
31948
|
-
for (; ; ) {
|
|
31949
|
-
const stripped = value.replace(/^<(user_info|environment_context|system_reminder)>[\s\S]*?<\/\1>\s*/, "");
|
|
31950
|
-
if (stripped === value) break;
|
|
31951
|
-
value = stripped;
|
|
31952
|
-
}
|
|
32176
|
+
const value = cursorEnvelope(text2).text;
|
|
31953
32177
|
const query = value.match(/^<user_query>([\s\S]*?)<\/user_query>(?:\s*<system_reminder>[\s\S]*?<\/system_reminder>)*\s*$/);
|
|
31954
32178
|
return (query ? query[1] : value).trim();
|
|
31955
32179
|
}
|
|
31956
32180
|
function cursorMessage(raw, fallbackID) {
|
|
31957
32181
|
if (!raw || typeof raw !== "object") return;
|
|
32182
|
+
if (raw.type === "turn_ended") {
|
|
32183
|
+
const message2 = blankMessage(typeof raw.id === "string" && raw.id.length <= 512 ? raw.id : fallbackID, cursorTime(raw.timestamp), "system");
|
|
32184
|
+
const failed = raw.status === "error" || raw.status === "failed";
|
|
32185
|
+
message2.events = [eventFor(message2, "turn-ended", failed ? "error" : "event", failed ? "Cursor turn failed" : "Cursor turn ended", eventText(raw.error), {
|
|
32186
|
+
nativeType: "turn_ended",
|
|
32187
|
+
status: failed ? "failed" : raw.status === "completed" || raw.status === "success" ? "completed" : "unknown"
|
|
32188
|
+
})];
|
|
32189
|
+
return message2;
|
|
32190
|
+
}
|
|
31958
32191
|
const body2 = raw.message && typeof raw.message === "object" ? raw.message : raw;
|
|
31959
32192
|
const role = raw.role || body2.role;
|
|
31960
32193
|
if (!["user", "assistant", "tool", "system"].includes(role)) return;
|
|
@@ -31963,7 +32196,7 @@ function cursorMessage(raw, fallbackID) {
|
|
|
31963
32196
|
const time4 = cursorTime(raw.timestamp) || cursorTime(body2.timestamp) || cursorTime(body2.createdAt) || (role === "user" && typeof firstText === "string" ? cursorEnvelopeTime(firstText) : 0);
|
|
31964
32197
|
const native = [raw.uuid, raw.id, body2.uuid, body2.id].find((id2) => typeof id2 === "string" && id2.length && id2.length <= 512);
|
|
31965
32198
|
const msg = blankMessage(native || fallbackID, time4, role);
|
|
31966
|
-
msg.events = role === "tool" ? [eventFor(msg, "result", "tool_result", body2.name || "Tool result", "", { callID: body2.tool_call_id, output: eventText(content, 64e3), status: "unknown" })] : blockEvents(msg, content);
|
|
32199
|
+
msg.events = role === "tool" ? [eventFor(msg, "result", "tool_result", body2.name || "Tool result", "", { callID: body2.tool_call_id, output: eventText(content, 64e3), status: "unknown" })] : role === "user" ? userBlockEvents(msg, content, cursorUserText) : blockEvents(msg, content);
|
|
31967
32200
|
const kind = role === "user" ? "You" : role === "assistant" ? "Assistant" : "Tool";
|
|
31968
32201
|
const text2 = (value) => addText(msg, role === "user" && typeof value === "string" ? cursorUserText(value) : value, kind);
|
|
31969
32202
|
if (typeof content === "string") text2(content);
|
|
@@ -32021,11 +32254,11 @@ function withStore(path, read3) {
|
|
|
32021
32254
|
throw error;
|
|
32022
32255
|
}
|
|
32023
32256
|
});
|
|
32024
|
-
const before = stats(),
|
|
32257
|
+
const before = stats(), directory3 = mkdtempSync2(join12(tmpdir2(), "sessiongraph-cursor-"));
|
|
32025
32258
|
let db2;
|
|
32026
32259
|
try {
|
|
32027
|
-
chmodSync2(
|
|
32028
|
-
const copy = join12(
|
|
32260
|
+
chmodSync2(directory3, 448);
|
|
32261
|
+
const copy = join12(directory3, "store.db");
|
|
32029
32262
|
files.forEach((file, index) => {
|
|
32030
32263
|
if (before[index]) {
|
|
32031
32264
|
const target = index ? `${copy}-wal` : copy;
|
|
@@ -32041,7 +32274,7 @@ function withStore(path, read3) {
|
|
|
32041
32274
|
try {
|
|
32042
32275
|
db2?.close();
|
|
32043
32276
|
} finally {
|
|
32044
|
-
rmSync3(
|
|
32277
|
+
rmSync3(directory3, { recursive: true, force: true });
|
|
32045
32278
|
}
|
|
32046
32279
|
}
|
|
32047
32280
|
}
|
|
@@ -32114,12 +32347,12 @@ function readCursorStore(path) {
|
|
|
32114
32347
|
bytes2 += data.length;
|
|
32115
32348
|
try {
|
|
32116
32349
|
if (item.leaf) {
|
|
32117
|
-
const
|
|
32118
|
-
if (!
|
|
32350
|
+
const json5 = data[0] === 123 ? data : fields(data).find((v3) => v3.field === 4)?.data;
|
|
32351
|
+
if (!json5) {
|
|
32119
32352
|
partial = true;
|
|
32120
32353
|
continue;
|
|
32121
32354
|
}
|
|
32122
|
-
const raw = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(
|
|
32355
|
+
const raw = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(json5));
|
|
32123
32356
|
const msg = cursorMessage(raw, `blob:${item.id}:${ordinal++}`);
|
|
32124
32357
|
if (!msg) {
|
|
32125
32358
|
partial = true;
|
|
@@ -32169,9 +32402,9 @@ var MAX_BUBBLE = 8e6;
|
|
|
32169
32402
|
var MAX_MESSAGES = 5e4;
|
|
32170
32403
|
var MAX_BYTES4 = 64e6;
|
|
32171
32404
|
function decode(value) {
|
|
32172
|
-
return
|
|
32405
|
+
return object2(JSON.parse(typeof value === "string" ? value : value instanceof Uint8Array ? Buffer.from(value).toString("utf8") : "{}"));
|
|
32173
32406
|
}
|
|
32174
|
-
function
|
|
32407
|
+
function directory2(raw) {
|
|
32175
32408
|
const value = text(raw.workspaceIdentifier?.uri?.path) || text(raw.workspaceIdentifier?.uri) || text(raw.cwd);
|
|
32176
32409
|
try {
|
|
32177
32410
|
return value.startsWith("file:") ? fileURLToPath(value) : isAbsolute3(value) ? value : "";
|
|
@@ -32186,7 +32419,7 @@ function discoverComposers(path, workspace = "") {
|
|
|
32186
32419
|
for (const table of ["cursorDiskKV", "ItemTable"]) {
|
|
32187
32420
|
if (!hasTable(db2, table)) continue;
|
|
32188
32421
|
let failed = 0, count = 0;
|
|
32189
|
-
const rows2 = db2.prepare(`SELECT key, CASE WHEN length(value)<=? THEN value END AS value FROM ${table} WHERE key LIKE 'composerData:%' ORDER BY key LIMIT 20001`).iterate(MAX_VALUE2);
|
|
32422
|
+
const rows2 = db2.prepare(`SELECT key, CASE WHEN length(value)<=? THEN value END AS value FROM ${table} WHERE key LIKE 'composerData:%' AND value IS NOT NULL ORDER BY key LIMIT 20001`).iterate(MAX_VALUE2);
|
|
32190
32423
|
for (const row of rows2) {
|
|
32191
32424
|
if (++count > 2e4) {
|
|
32192
32425
|
warnings.push("Cursor Composer listing reached its 20,000-session limit.");
|
|
@@ -32198,7 +32431,7 @@ function discoverComposers(path, workspace = "") {
|
|
|
32198
32431
|
if (!nativeID || row.key !== `composerData:${nativeID}`) throw new Error("Composer identity mismatch.");
|
|
32199
32432
|
const headers = Array.isArray(data.fullConversationHeadersOnly) ? data.fullConversationHeadersOnly : Array.isArray(data.conversation) ? data.conversation : [];
|
|
32200
32433
|
if (!headers.length) continue;
|
|
32201
|
-
const session = blankSession("cursor", nativeID,
|
|
32434
|
+
const session = blankSession("cursor", nativeID, directory2(data) || workspace);
|
|
32202
32435
|
session.created = cursorTime(data.createdAt);
|
|
32203
32436
|
if (!session.created) continue;
|
|
32204
32437
|
session.updated = cursorTime(data.lastUpdatedAt) || session.created;
|
|
@@ -32207,7 +32440,7 @@ function discoverComposers(path, workspace = "") {
|
|
|
32207
32440
|
session.model = text(data.modelConfig?.modelName) || "Unknown model";
|
|
32208
32441
|
session.archived = data.isArchived === true;
|
|
32209
32442
|
const children = Array.isArray(data.subagentComposerIds) ? data.subagentComposerIds.filter((id2) => typeof id2 === "string") : [];
|
|
32210
|
-
sessions.push({ session, revision: digest([
|
|
32443
|
+
sessions.push({ session, revision: digest([2, snapshot2, table, nativeID]), locator: { path, kind: "composer", table, snapshot: snapshot2, nativeID, children: JSON.stringify(children) } });
|
|
32211
32444
|
} catch {
|
|
32212
32445
|
failed++;
|
|
32213
32446
|
}
|
|
@@ -32249,7 +32482,7 @@ function readComposer(candidate) {
|
|
|
32249
32482
|
const id2 = text(header.bubbleId);
|
|
32250
32483
|
const stored = id2 ? get.get(`bubbleId:${nativeID}:${id2}`, MAX_BUBBLE) : void 0;
|
|
32251
32484
|
if (stored) bytes2 += typeof stored.value === "string" ? Buffer.byteLength(stored.value) : stored.value.byteLength;
|
|
32252
|
-
const raw = stored ? { ...header, ...decode(stored.value) } : { ...header, ...
|
|
32485
|
+
const raw = stored ? { ...header, ...decode(stored.value) } : { ...header, ...object2(data.conversationMap?.[id2]) };
|
|
32253
32486
|
if (![1, 2].includes(raw.type)) {
|
|
32254
32487
|
partial = true;
|
|
32255
32488
|
continue;
|
|
@@ -32295,7 +32528,7 @@ async function stamp(path) {
|
|
|
32295
32528
|
async function snapshot(locator) {
|
|
32296
32529
|
return digest(await Promise.all([stamp(locator.path), locator.kind === "transcript" ? null : stamp(`${locator.path}-wal`), locator.meta ? stamp(locator.meta) : null]));
|
|
32297
32530
|
}
|
|
32298
|
-
async function
|
|
32531
|
+
async function json4(path) {
|
|
32299
32532
|
const s = await fileStats(path);
|
|
32300
32533
|
if (!s) return {};
|
|
32301
32534
|
if (s.size > 128e3) throw new Error("Cursor metadata exceeds the 128 KB limit.");
|
|
@@ -32325,7 +32558,7 @@ async function workspacePaths(root3, warnings) {
|
|
|
32325
32558
|
const database = join13(storage, entry.name, "state.vscdb");
|
|
32326
32559
|
stores.set(database, "");
|
|
32327
32560
|
try {
|
|
32328
|
-
const info = await
|
|
32561
|
+
const info = await json4(join13(storage, entry.name, "workspace.json"));
|
|
32329
32562
|
if (typeof info.folder === "string" && info.folder.startsWith("file:")) {
|
|
32330
32563
|
const path = cwd(fileURLToPath2(info.folder));
|
|
32331
32564
|
if (path) stores.set(database, path);
|
|
@@ -32385,7 +32618,7 @@ function createCursorAdapter(options = {}) {
|
|
|
32385
32618
|
return matches.length === 1 ? matches[0] : "";
|
|
32386
32619
|
};
|
|
32387
32620
|
let unreadable = 0, legacy = 0, scanned = 0;
|
|
32388
|
-
const add = async (path, id2, kind,
|
|
32621
|
+
const add = async (path, id2, kind, directory3, parent2 = "", workspaceHash = "") => {
|
|
32389
32622
|
if (!validID(id2) || ++scanned > LIMIT) return;
|
|
32390
32623
|
try {
|
|
32391
32624
|
const stats = await fileStats(path);
|
|
@@ -32394,11 +32627,11 @@ function createCursorAdapter(options = {}) {
|
|
|
32394
32627
|
const locator = { path, kind };
|
|
32395
32628
|
if (kind !== "transcript") locator.meta = join13(path, "..", "meta.json");
|
|
32396
32629
|
const before = await snapshot(locator);
|
|
32397
|
-
const extra2 = locator.meta ? await
|
|
32630
|
+
const extra2 = locator.meta ? await json4(locator.meta) : {};
|
|
32398
32631
|
const meta = kind === "transcript" ? {} : cursorStoreMetadata(path);
|
|
32399
32632
|
if (meta.agentId && meta.agentId !== id2) throw new Error("Cursor native identity mismatch.");
|
|
32400
32633
|
if (kind !== "transcript" && !meta.latestRootBlobId) return;
|
|
32401
|
-
const session = blankSession("cursor", native, cwd(meta.cwd) || cwd(extra2.cwd) ||
|
|
32634
|
+
const session = blankSession("cursor", native, cwd(meta.cwd) || cwd(extra2.cwd) || directory3);
|
|
32402
32635
|
session.agent = kind === "cli" ? "Cursor Agent" : kind === "acp" ? "Cursor ACP" : parent2 ? "Cursor subagent" : "Cursor IDE";
|
|
32403
32636
|
if (parent2) session.parentID = identity("cursor", parent2);
|
|
32404
32637
|
session.title = typeof meta.name === "string" && meta.name.trim() ? meta.name : typeof extra2.title === "string" && extra2.title.trim() ? extra2.title : "Cursor session";
|
|
@@ -32445,7 +32678,7 @@ function createCursorAdapter(options = {}) {
|
|
|
32445
32678
|
session.projectID = project("cursor", session.directory).id;
|
|
32446
32679
|
if (session.directory) delete locator.directoryNote;
|
|
32447
32680
|
}
|
|
32448
|
-
const candidate = { session, locator, revision: digest([
|
|
32681
|
+
const candidate = { session, locator, revision: digest([5, kind, path, before, session.created, session.directory, session.parentID]) };
|
|
32449
32682
|
if (!previous || rank(candidate) > rank(previous) || rank(candidate) === rank(previous) && session.updated > previous.session.updated) found.set(session.id, candidate);
|
|
32450
32683
|
} catch {
|
|
32451
32684
|
unreadable++;
|
|
@@ -32455,15 +32688,15 @@ function createCursorAdapter(options = {}) {
|
|
|
32455
32688
|
const projects = join13(root3(), "projects");
|
|
32456
32689
|
for (const dir of await entries(projects, warnings)) {
|
|
32457
32690
|
if (!dir.isDirectory() || scanned >= LIMIT) continue;
|
|
32458
|
-
const transcripts = join13(projects, dir.name, "agent-transcripts"),
|
|
32691
|
+
const transcripts = join13(projects, dir.name, "agent-transcripts"), directory3 = match2(dir.name, slug);
|
|
32459
32692
|
for (const entry of await entries(transcripts, warnings)) {
|
|
32460
32693
|
if (scanned >= LIMIT) break;
|
|
32461
|
-
if (entry.isFile() && entry.name.endsWith(".jsonl")) await add(join13(transcripts, entry.name), entry.name.slice(0, -6), "transcript",
|
|
32694
|
+
if (entry.isFile() && entry.name.endsWith(".jsonl")) await add(join13(transcripts, entry.name), entry.name.slice(0, -6), "transcript", directory3);
|
|
32462
32695
|
else if (entry.isFile() && entry.name.endsWith(".txt")) legacy++;
|
|
32463
32696
|
else if (entry.isDirectory() && validID(entry.name)) {
|
|
32464
|
-
await add(join13(transcripts, entry.name, `${entry.name}.jsonl`), entry.name, "transcript",
|
|
32697
|
+
await add(join13(transcripts, entry.name, `${entry.name}.jsonl`), entry.name, "transcript", directory3);
|
|
32465
32698
|
for (const child of await entries(join13(transcripts, entry.name, "subagents"), warnings)) {
|
|
32466
|
-
if (child.isFile() && child.name.endsWith(".jsonl")) await add(join13(transcripts, entry.name, "subagents", child.name), child.name.slice(0, -6), "transcript",
|
|
32699
|
+
if (child.isFile() && child.name.endsWith(".jsonl")) await add(join13(transcripts, entry.name, "subagents", child.name), child.name.slice(0, -6), "transcript", directory3, entry.name);
|
|
32467
32700
|
if (scanned >= LIMIT) break;
|
|
32468
32701
|
}
|
|
32469
32702
|
}
|
|
@@ -32472,13 +32705,13 @@ function createCursorAdapter(options = {}) {
|
|
|
32472
32705
|
const chats = join13(root3(), "chats");
|
|
32473
32706
|
for (const bucket of await entries(chats, warnings)) {
|
|
32474
32707
|
if (!bucket.isDirectory() || scanned >= LIMIT) continue;
|
|
32475
|
-
const folder = join13(chats, bucket.name),
|
|
32708
|
+
const folder = join13(chats, bucket.name), directory3 = match2(bucket.name, hashCwd);
|
|
32476
32709
|
if (/^[a-f\d]{32}$/i.test(bucket.name) && await fileStats(join13(folder, "store.db"))) {
|
|
32477
32710
|
const id2 = bucket.name.replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/, "$1-$2-$3-$4-$5");
|
|
32478
32711
|
await add(join13(folder, "store.db"), id2, "cli", "");
|
|
32479
32712
|
}
|
|
32480
32713
|
for (const entry of await entries(folder, warnings)) {
|
|
32481
|
-
if (entry.isDirectory()) await add(join13(folder, entry.name, "store.db"), entry.name, "cli",
|
|
32714
|
+
if (entry.isDirectory()) await add(join13(folder, entry.name, "store.db"), entry.name, "cli", directory3, "", bucket.name);
|
|
32482
32715
|
if (scanned >= LIMIT) break;
|
|
32483
32716
|
}
|
|
32484
32717
|
}
|
|
@@ -32525,7 +32758,7 @@ function createCursorAdapter(options = {}) {
|
|
|
32525
32758
|
const messages = page.rows.flatMap((row) => {
|
|
32526
32759
|
const message2 = cursorMessage(row.value, `offset:${row.offset}`);
|
|
32527
32760
|
if (!message2) page.partial = true;
|
|
32528
|
-
return message2 && message2.role !== "system" ? [message2] : [];
|
|
32761
|
+
return message2 && (message2.role !== "system" || row.value?.type === "turn_ended") ? [message2] : [];
|
|
32529
32762
|
});
|
|
32530
32763
|
await verify();
|
|
32531
32764
|
if (!offset && page.cursor === void 0 && !messages.length) throw new Error("Cursor transcript has no readable conversation. Previous imports are retained.");
|
|
@@ -32543,7 +32776,7 @@ function projectRootFile(path) {
|
|
|
32543
32776
|
return join14(parts.slice(0, parts.lastIndexOf("chats")).join(sep3), ".project_root");
|
|
32544
32777
|
}
|
|
32545
32778
|
function geminiConversation(contents, lines) {
|
|
32546
|
-
const parsed = lines ? jsonLines(contents) : { rows: [
|
|
32779
|
+
const parsed = lines ? jsonLines(contents) : { rows: [object2(json3(contents))], partial: false };
|
|
32547
32780
|
let metadata2 = {};
|
|
32548
32781
|
const messages = /* @__PURE__ */ new Map();
|
|
32549
32782
|
const patch = (p) => {
|
|
@@ -32560,9 +32793,9 @@ function geminiConversation(contents, lines) {
|
|
|
32560
32793
|
const ids = [...messages.keys()], index = ids.indexOf(row.$rewindTo);
|
|
32561
32794
|
for (const id2 of index < 0 ? ids : ids.slice(index)) messages.delete(id2);
|
|
32562
32795
|
} else if (row.$patch) {
|
|
32563
|
-
const p =
|
|
32796
|
+
const p = object2(row.$patch);
|
|
32564
32797
|
if (p.id) patch(p);
|
|
32565
|
-
for (const update of Array.isArray(p.updates) ? p.updates : []) patch(
|
|
32798
|
+
for (const update of Array.isArray(p.updates) ? p.updates : []) patch(object2(update));
|
|
32566
32799
|
for (const id2 of Array.isArray(p.removeIds) ? p.removeIds : []) messages.delete(id2);
|
|
32567
32800
|
for (const id2 of Array.isArray(p.orderIds) ? p.orderIds : []) {
|
|
32568
32801
|
const value = messages.get(id2);
|
|
@@ -32572,7 +32805,7 @@ function geminiConversation(contents, lines) {
|
|
|
32572
32805
|
}
|
|
32573
32806
|
}
|
|
32574
32807
|
} else if (row.$set || row.sessionId) {
|
|
32575
|
-
const update = row.$set ?
|
|
32808
|
+
const update = row.$set ? object2(row.$set) : row;
|
|
32576
32809
|
metadata2 = { ...metadata2, ...update };
|
|
32577
32810
|
if (Array.isArray(update.messages)) {
|
|
32578
32811
|
if (row.$set) messages.clear();
|
|
@@ -32594,7 +32827,7 @@ var geminiAdapter = localFileAdapter({
|
|
|
32594
32827
|
parse(path, files) {
|
|
32595
32828
|
const { metadata: meta, records, partial } = geminiConversation(files.get(path), path.endsWith(".jsonl"));
|
|
32596
32829
|
if (!text(meta.sessionId)) throw new Error("Unsupported Gemini history.");
|
|
32597
|
-
const
|
|
32830
|
+
const directory3 = (files.get(projectRootFile(path)) || "").trim().slice(0, 4096);
|
|
32598
32831
|
const messages = records.map((raw, index) => {
|
|
32599
32832
|
const message2 = googleMessage({ id: raw.id, timestamp: raw.timestamp, role: raw.type === "user" ? "user" : raw.type === "gemini" ? "assistant" : "system", content: raw.content }, `record:${index}`);
|
|
32600
32833
|
for (const [i, thought] of (Array.isArray(raw.thoughts) ? raw.thoughts : []).entries()) message2.events.push(eventFor(message2, `thought:${i}`, "reasoning", text(thought.subject) || "Recorded reasoning", text(thought.description), { time: time(thought.timestamp) || null, timeSource: time(thought.timestamp) ? "recorded" : "unknown" }));
|
|
@@ -32603,9 +32836,9 @@ var geminiAdapter = localFileAdapter({
|
|
|
32603
32836
|
message2.tools.push(name);
|
|
32604
32837
|
message2.events.push(eventFor(message2, `call:${id2}`, "tool_call", name, "", { callID: id2, input: eventText(call.args), status: "unknown" }));
|
|
32605
32838
|
if (call.result != null || ["success", "error", "cancelled"].includes(call.status)) {
|
|
32606
|
-
const
|
|
32607
|
-
message2.events.push(eventFor(message2, `result:${id2}`, "tool_result", name, "", { role: "tool", callID: id2, output, nativeType: text(call.status), time: time(call.timestamp) || null, timeSource: time(call.timestamp) ? "recorded" : "unknown", status: call.status === "success" ? "completed" : call.status === "error" ? "failed" : "unknown" }));
|
|
32608
|
-
addText(message2,
|
|
32839
|
+
const output2 = eventText(call.result);
|
|
32840
|
+
message2.events.push(eventFor(message2, `result:${id2}`, "tool_result", name, "", { role: "tool", callID: id2, output: output2, nativeType: text(call.status), time: time(call.timestamp) || null, timeSource: time(call.timestamp) ? "recorded" : "unknown", status: call.status === "success" ? "completed" : call.status === "error" ? "failed" : "unknown" }));
|
|
32841
|
+
addText(message2, output2, "Tool");
|
|
32609
32842
|
}
|
|
32610
32843
|
}
|
|
32611
32844
|
return message2;
|
|
@@ -32617,7 +32850,7 @@ var geminiAdapter = localFileAdapter({
|
|
|
32617
32850
|
messages,
|
|
32618
32851
|
parent: parent2,
|
|
32619
32852
|
partial,
|
|
32620
|
-
session: { directory:
|
|
32853
|
+
session: { directory: directory3, created: time(meta.startTime), title: text(meta.summary), model: text([...records].reverse().find((r) => r.model)?.model) || "Unknown model", provider: "Google", nativeResume: !parent2 && Boolean(directory3) && !sourcePath("gemini") && !process.env.SESSIONGRAPH_GEMINI_HOME && !path.includes(`${sep3}.cache${sep3}`) },
|
|
32621
32854
|
note: "Local Gemini chat records with rewind and patch reconstruction. Only explicit subagent directories form parent links; workspace paths come from the project-root marker. Binary content is omitted."
|
|
32622
32855
|
};
|
|
32623
32856
|
}
|
|
@@ -32641,7 +32874,7 @@ var qwenAdapter = localFileAdapter({
|
|
|
32641
32874
|
const messages = rows2.map((raw, index) => {
|
|
32642
32875
|
const id2 = text(raw.uuid) || `record:${index}`;
|
|
32643
32876
|
if (raw.message && !["agent_message", "agent_mention", "notification"].includes(raw.subtype)) {
|
|
32644
|
-
const message3 = googleMessage({ id: id2, timestamp: raw.timestamp, role: raw.type === "assistant" ? "assistant" : raw.type === "user" ? "user" : "tool", toolCallId: raw.toolCallResult?.callId, content:
|
|
32877
|
+
const message3 = googleMessage({ id: id2, timestamp: raw.timestamp, role: raw.type === "assistant" ? "assistant" : raw.type === "user" ? "user" : "tool", toolCallId: raw.toolCallResult?.callId, content: object2(raw.message).parts }, id2);
|
|
32645
32878
|
for (const event of message3.events || []) if (event.kind === "tool_result") {
|
|
32646
32879
|
event.status = raw.toolCallResult?.status === "success" ? "completed" : raw.toolCallResult?.status === "error" ? "failed" : "unknown";
|
|
32647
32880
|
event.nativeType = text(raw.toolCallResult?.status);
|
|
@@ -32679,11 +32912,11 @@ var copilotAdapter = localFileAdapter({
|
|
|
32679
32912
|
match: (path) => /(?:^|\/)events\.jsonl$/.test(path),
|
|
32680
32913
|
parse(path, files) {
|
|
32681
32914
|
const { rows: rows2, partial } = jsonLines(files.get(path));
|
|
32682
|
-
const start = rows2.find((r) => r.type === "session.start"), meta =
|
|
32915
|
+
const start = rows2.find((r) => r.type === "session.start"), meta = object2(start?.data);
|
|
32683
32916
|
if (!text(meta.sessionId)) throw new Error("Unsupported Copilot event log.");
|
|
32684
32917
|
const toolNames = new Map(rows2.filter((r) => r.type === "tool.execution_start").map((r) => [r.data?.toolCallId, text(r.data?.toolName)]));
|
|
32685
32918
|
const messages = rows2.filter((r) => !r.ephemeral && !["assistant.message_delta", "assistant.reasoning_delta"].includes(r.type)).map((raw, index) => {
|
|
32686
|
-
const data =
|
|
32919
|
+
const data = object2(raw.data), kind = text(raw.type), human = kind === "user.message" && !data.isAutopilotContinuation && !data.source;
|
|
32687
32920
|
const message2 = blankMessage(text(raw.id) || `record:${index}`, time(raw.timestamp), human ? "user" : kind === "assistant.message" ? "assistant" : kind.startsWith("tool.") ? "tool" : "system");
|
|
32688
32921
|
if (["user.message", "assistant.message"].includes(kind)) {
|
|
32689
32922
|
const content = text(data.content);
|
|
@@ -32723,7 +32956,7 @@ var copilotAdapter = localFileAdapter({
|
|
|
32723
32956
|
|
|
32724
32957
|
// server/adapters/copilot-chat.ts
|
|
32725
32958
|
import { homedir as homedir11 } from "node:os";
|
|
32726
|
-
import { basename as basename6, dirname as dirname4, join as join17, posix, win32 as
|
|
32959
|
+
import { basename as basename6, dirname as dirname4, join as join17, posix as posix2, win32 as win323 } from "node:path";
|
|
32727
32960
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
32728
32961
|
|
|
32729
32962
|
// server/adapters/vscode-chat-log.ts
|
|
@@ -32732,7 +32965,7 @@ function vscodeChatLog(content) {
|
|
|
32732
32965
|
for (const line of content.split("\n")) {
|
|
32733
32966
|
if (!line.trim()) continue;
|
|
32734
32967
|
if (++records > 5e4) throw new Error("Chat log exceeds the 50,000-operation limit.");
|
|
32735
|
-
const entry =
|
|
32968
|
+
const entry = object2(JSON.parse(line));
|
|
32736
32969
|
if (entry.kind === 0) {
|
|
32737
32970
|
if (records !== 1 || !entry.v || typeof entry.v !== "object" || Array.isArray(entry.v)) throw new Error("Invalid chat log initial state.");
|
|
32738
32971
|
state2 = entry.v;
|
|
@@ -32771,14 +33004,14 @@ function vscodeChatLog(content) {
|
|
|
32771
33004
|
|
|
32772
33005
|
// server/adapters/copilot-chat.ts
|
|
32773
33006
|
function copilotChatRoots(platform = process.platform, home = homedir11(), env = process.env) {
|
|
32774
|
-
const path = platform === "win32" ?
|
|
33007
|
+
const path = platform === "win32" ? win323 : posix2;
|
|
32775
33008
|
const base = platform === "darwin" ? path.join(home, "Library", "Application Support") : platform === "win32" ? env.APPDATA || path.join(home, "AppData", "Roaming") : env.XDG_CONFIG_HOME || path.join(home, ".config");
|
|
32776
33009
|
const override = sourcePath("copilot-chat") || env.SESSIONGRAPH_COPILOT_CHAT_USER_DATA_DIR;
|
|
32777
33010
|
const users = override ? [path.join(override, "User")] : [...["Code", "Code - Insiders"].map((app) => path.join(base, app, "User")), ...[".vscode-server", ".vscode-server-insiders"].map((app) => path.join(home, app, "data", "User"))];
|
|
32778
33011
|
return users.flatMap((user) => [path.join(user, "workspaceStorage"), path.join(user, "globalStorage", "emptyWindowChatSessions")]);
|
|
32779
33012
|
}
|
|
32780
33013
|
function vscodeChatPath(value) {
|
|
32781
|
-
const raw =
|
|
33014
|
+
const raw = object2(value);
|
|
32782
33015
|
if (raw.scheme) {
|
|
32783
33016
|
if (raw.scheme !== "file") return `${text(raw.scheme)}://${text(raw.authority)}${text(raw.path)}`;
|
|
32784
33017
|
const path = text(raw.path);
|
|
@@ -32793,10 +33026,10 @@ function vscodeChatPath(value) {
|
|
|
32793
33026
|
return "";
|
|
32794
33027
|
}
|
|
32795
33028
|
}
|
|
32796
|
-
var markdown = (value) => typeof value === "string" ? value : text(
|
|
33029
|
+
var markdown = (value) => typeof value === "string" ? value : text(object2(value).value);
|
|
32797
33030
|
var recordedTime = (value) => ({ time: time(value) || null, timeSource: time(value) ? "recorded" : "unknown" });
|
|
32798
33031
|
function responsePart(message2, value, index) {
|
|
32799
|
-
const part =
|
|
33032
|
+
const part = object2(value), kind = text(part.kind), id2 = `part:${index}`;
|
|
32800
33033
|
const fields2 = { nativeType: kind || "markdown", nativeID: text(part.id) || void 0 };
|
|
32801
33034
|
if (typeof value === "string" || !kind && typeof part.value === "string" || kind === "markdownContent" || kind === "markdownVuln") {
|
|
32802
33035
|
const content = markdown(kind ? part.content : value);
|
|
@@ -32807,19 +33040,19 @@ function responsePart(message2, value, index) {
|
|
|
32807
33040
|
message2.events.push(eventFor(message2, id2, "reasoning", "Recorded reasoning", content, { ...fields2, ...recordedTime(part.reasoningStartedAt) }));
|
|
32808
33041
|
addText(message2, content, "Tool");
|
|
32809
33042
|
} else if (kind === "toolInvocationSerialized") {
|
|
32810
|
-
const data =
|
|
33043
|
+
const data = object2(part.toolSpecificData), command = object2(data.commandLine), details = object2(part.resultDetails);
|
|
32811
33044
|
const name = text(part.toolId) || "Tool", callID = text(part.toolCallId) || void 0;
|
|
32812
33045
|
const input = eventText(data.rawInput ?? command.userEdited ?? command.toolEdited ?? command.original ?? details.input);
|
|
32813
|
-
const denied = part.isConfirmed === false || [0, 5].includes(
|
|
33046
|
+
const denied = part.isConfirmed === false || [0, 5].includes(object2(part.isConfirmed).type);
|
|
32814
33047
|
const status2 = denied || part.resultError ? "failed" : part.isComplete === true ? "completed" : "unknown";
|
|
32815
33048
|
const correlation = { ...fields2, callID, parentID: text(part.subAgentInvocationId) || void 0 };
|
|
32816
33049
|
message2.events.push(eventFor(message2, `${id2}:call`, "tool_call", name, markdown(part.invocationMessage), { ...correlation, ...recordedTime(part.startedAt), input, status: "unknown" }));
|
|
32817
33050
|
message2.tools.push(name);
|
|
32818
33051
|
addText(message2, input, "Tool");
|
|
32819
33052
|
if (part.isComplete || part.resultError || denied) {
|
|
32820
|
-
const
|
|
32821
|
-
message2.events.push(eventFor(message2, `${id2}:result`, "tool_result", name, markdown(part.pastTenseMessage), { ...correlation, ...recordedTime(part.completedAt), role: "tool", output, status: status2 }));
|
|
32822
|
-
addText(message2,
|
|
33053
|
+
const output2 = eventText(part.resultError || (denied ? "Tool invocation was denied or skipped." : details.output ?? part.resultDetails ?? markdown(part.pastTenseMessage)));
|
|
33054
|
+
message2.events.push(eventFor(message2, `${id2}:result`, "tool_result", name, markdown(part.pastTenseMessage), { ...correlation, ...recordedTime(part.completedAt), role: "tool", output: output2, status: status2 }));
|
|
33055
|
+
addText(message2, output2, "Tool");
|
|
32823
33056
|
} else message2.partial = true;
|
|
32824
33057
|
} else {
|
|
32825
33058
|
message2.events.push(eventFor(message2, id2, "event", kind || "Unsupported chat content", eventText(part), { ...fields2, partial: true }));
|
|
@@ -32832,7 +33065,7 @@ function chatMessages(requests) {
|
|
|
32832
33065
|
const requestID = text(request.requestId) || `request:${index}`;
|
|
32833
33066
|
const injected = Boolean(request.isSystemInitiated || request.hiddenFromTranscript || request.requestHiddenFromTranscript);
|
|
32834
33067
|
const user = blankMessage(requestID, time(request.timestamp), injected ? "system" : "user");
|
|
32835
|
-
const content = typeof request.message === "string" ? request.message : text(
|
|
33068
|
+
const content = typeof request.message === "string" ? request.message : text(object2(request.message).text);
|
|
32836
33069
|
user.events = [eventFor(user, "message", injected ? "event" : "message", injected ? "Injected message" : "User message", content, { nativeID: requestID, ...recordedTime(request.timestamp) })];
|
|
32837
33070
|
addText(user, content, injected ? "Tool" : "You");
|
|
32838
33071
|
if (request.variableData?.variables?.length) user.partial = true;
|
|
@@ -32875,13 +33108,13 @@ var filesAdapter = localFileAdapter({
|
|
|
32875
33108
|
extras: (path) => [...basename6(dirname4(path)) === "chatSessions" ? [join17(dirname4(dirname4(path)), "workspace.json")] : [], ...path.endsWith(".json") ? [`${path}l`] : []],
|
|
32876
33109
|
parse(path, files) {
|
|
32877
33110
|
const log = path.endsWith(".jsonl") ? path : `${path}l`;
|
|
32878
|
-
const data = files.has(log) ? vscodeChatLog(files.get(log)) :
|
|
33111
|
+
const data = files.has(log) ? vscodeChatLog(files.get(log)) : object2(JSON.parse(files.get(path)));
|
|
32879
33112
|
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.");
|
|
32880
33113
|
if (data.sessionId !== basename6(path).replace(/\.jsonl?$/, "")) throw new Error("VS Code chat identity mismatch.");
|
|
32881
33114
|
if (!data.requests.length) return;
|
|
32882
33115
|
if (data.requests.length > 25e3) throw new Error("Chat exceeds the 50,000-message limit.");
|
|
32883
33116
|
const workspacePath = join17(dirname4(dirname4(path)), "workspace.json");
|
|
32884
|
-
const workspace = files.has(workspacePath) ?
|
|
33117
|
+
const workspace = files.has(workspacePath) ? object2(JSON.parse(files.get(workspacePath))) : {};
|
|
32885
33118
|
const messages = chatMessages(data.requests);
|
|
32886
33119
|
const model = [...data.requests].reverse().find((r) => text(r.modelId));
|
|
32887
33120
|
return {
|
|
@@ -32916,15 +33149,15 @@ function taskAdapter(id2, name, extension, env) {
|
|
|
32916
33149
|
match: (path) => /^[^/]+\/api_conversation_history\.json$/.test(path) || id2 === "cline" && /^[^/]+\/[^/]+\.messages\.json$/.test(path),
|
|
32917
33150
|
extras: (path) => ["history_item.json", "task_metadata.json", "session.json"].map((file) => join18(dirname5(path), file)),
|
|
32918
33151
|
parse(path, files) {
|
|
32919
|
-
const sdk = path.endsWith(".messages.json"), value =
|
|
32920
|
-
const records = sdk ?
|
|
33152
|
+
const sdk = path.endsWith(".messages.json"), value = json3(files.get(path));
|
|
33153
|
+
const records = sdk ? object2(value).messages : value;
|
|
32921
33154
|
if (!Array.isArray(records) || sdk && !text(value.sessionId)) throw new Error("Unsupported task history.");
|
|
32922
|
-
const read3 = (name2) =>
|
|
33155
|
+
const read3 = (name2) => object2(files.has(join18(dirname5(path), name2)) ? json3(files.get(join18(dirname5(path), name2))) : void 0);
|
|
32923
33156
|
const history = read3("history_item.json"), info = read3("session.json"), task = read3("task_metadata.json");
|
|
32924
33157
|
const nativeID = sdk ? value.sessionId : basename7(dirname5(path));
|
|
32925
33158
|
if (history.id && history.id !== nativeID || info.session_id && info.session_id !== nativeID) throw new Error("Task metadata identity mismatch.");
|
|
32926
33159
|
const messages = records.map((raw, index) => {
|
|
32927
|
-
const row =
|
|
33160
|
+
const row = object2(raw), message2 = conversationMessage(row, `record:${index}`);
|
|
32928
33161
|
if (row.isSummary || row.isTruncationMarker || row.type === "reasoning") {
|
|
32929
33162
|
message2.role = "system";
|
|
32930
33163
|
message2.events = [eventFor(message2, "summary", row.type === "reasoning" ? "reasoning" : "compaction", row.type === "reasoning" ? "Recorded reasoning" : "Context checkpoint", eventText(row.summary ?? row.content ?? row.text), { partial: Boolean(row.encrypted_content), nativeType: row.type || "summary" })];
|
|
@@ -32960,17 +33193,17 @@ var continueAdapter = localFileAdapter({
|
|
|
32960
33193
|
extras: (path) => [join18(dirname5(path), "sessions.json")],
|
|
32961
33194
|
revisionExtras: false,
|
|
32962
33195
|
parse(path, files) {
|
|
32963
|
-
const value =
|
|
33196
|
+
const value = object2(json3(files.get(path)));
|
|
32964
33197
|
if (!text(value.sessionId) || !Array.isArray(value.history)) throw new Error("Unsupported Continue session.");
|
|
32965
|
-
const indexPath = join18(dirname5(path), "sessions.json"), index = files.has(indexPath) ?
|
|
32966
|
-
const meta = Array.isArray(index) ?
|
|
33198
|
+
const indexPath = join18(dirname5(path), "sessions.json"), index = files.has(indexPath) ? json3(files.get(indexPath)) : [];
|
|
33199
|
+
const meta = Array.isArray(index) ? object2(index.find((r) => r.sessionId === value.sessionId)) : {};
|
|
32967
33200
|
const messages = value.history.map((item, i) => {
|
|
32968
|
-
const row =
|
|
33201
|
+
const row = object2(item), raw = object2(row.message), message2 = conversationMessage(raw, `record:${i}`);
|
|
32969
33202
|
if (row.reasoning?.text) message2.events.push(eventFor(message2, "reasoning", "reasoning", "Recorded reasoning", text(row.reasoning.text), { time: time(row.reasoning.startAt) || null, timeSource: time(row.reasoning.startAt) ? "recorded" : "unknown" }));
|
|
32970
33203
|
if (row.conversationSummary) message2.events.push(eventFor(message2, "summary", "compaction", "Conversation summary", text(row.conversationSummary)));
|
|
32971
33204
|
return message2;
|
|
32972
33205
|
});
|
|
32973
|
-
const usage =
|
|
33206
|
+
const usage = object2(value.usage);
|
|
32974
33207
|
return {
|
|
32975
33208
|
nativeID: value.sessionId,
|
|
32976
33209
|
messages,
|
|
@@ -33000,7 +33233,7 @@ var harnessRoots = (id2, defaults) => () => {
|
|
|
33000
33233
|
// server/adapters/harness-extra-formats.ts
|
|
33001
33234
|
import { basename as basename8, dirname as dirname6, join as join20 } from "node:path";
|
|
33002
33235
|
function kiroHistory(path, files) {
|
|
33003
|
-
const header =
|
|
33236
|
+
const header = object2(json3(files.get(path)));
|
|
33004
33237
|
const ide2 = basename8(path) === "session.json";
|
|
33005
33238
|
const nativeID = text(header.session_id || header.sessionId || header.id) || (ide2 ? basename8(dirname6(path)) : "");
|
|
33006
33239
|
if (!nativeID) throw new Error("Unsupported Kiro session header.");
|
|
@@ -33009,12 +33242,12 @@ function kiroHistory(path, files) {
|
|
|
33009
33242
|
const { rows: rows2 } = jsonLines(files.get(side));
|
|
33010
33243
|
const messages = rows2.flatMap((r, i) => {
|
|
33011
33244
|
if (ide2) {
|
|
33012
|
-
const p =
|
|
33245
|
+
const p = object2(r.payload || r);
|
|
33013
33246
|
const role2 = p.type === "human" ? "user" : p.type === "ai" ? "assistant" : p.role || p.type;
|
|
33014
33247
|
const m3 = message({ ...p, role: role2 }, text(p.id) || `message:${i}`, r.timestamp);
|
|
33015
33248
|
return m3 ? [m3] : [recordEvent(r, `event:${i}`, text(p.type) || "Kiro event", r.timestamp, p.text)];
|
|
33016
33249
|
}
|
|
33017
|
-
const data =
|
|
33250
|
+
const data = object2(r.data), role = r.kind === "Prompt" ? "user" : r.kind === "AssistantMessage" ? "assistant" : r.kind === "ToolResults" ? "tool" : "";
|
|
33018
33251
|
if (!role) return [];
|
|
33019
33252
|
const content = Array.isArray(data.content) ? data.content.map((p) => p.kind === "text" ? { type: "text", text: p.data } : { type: "unsupported" }) : void 0;
|
|
33020
33253
|
const m = message({ role, content }, text(data.message_id) || `message:${i}`, seconds(data.meta?.timestamp));
|
|
@@ -33058,7 +33291,7 @@ function muxHistory(path, files) {
|
|
|
33058
33291
|
function devinDesktopHistory(path, files) {
|
|
33059
33292
|
const { rows: rows2 } = jsonLines(files.get(path));
|
|
33060
33293
|
const normalized = rows2.flatMap((r) => {
|
|
33061
|
-
const n =
|
|
33294
|
+
const n = object2(r.notification);
|
|
33062
33295
|
return n.sessionUpdate ? [{ params: { sessionId: text(r.sessionId || n.sessionId) || fileID(path).replace(/\.ndjson$/, ""), update: n }, timestamp: n.content?.metadata?.created_at ?? n.metadata?.created_at ?? n.timestamp ?? r.timestamp }] : [];
|
|
33063
33296
|
});
|
|
33064
33297
|
const history = acpHistory(path, normalized.map((r) => JSON.stringify(r)).join("\n"));
|
|
@@ -33103,7 +33336,7 @@ function museHistory(path, files) {
|
|
|
33103
33336
|
if (!meta || ids.size > 1) throw new Error("Unsupported Muse stream.");
|
|
33104
33337
|
const nativeID = [...ids][0] || basename9(dirname7(path));
|
|
33105
33338
|
const messages = rows2.flatMap((r, i) => {
|
|
33106
|
-
const event =
|
|
33339
|
+
const event = object2(r.payload?.event), body2 = object2(event.message);
|
|
33107
33340
|
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);
|
|
33108
33341
|
const m = message(body2, nativeText(r.sequence) || `record:${i}`, at2);
|
|
33109
33342
|
if (m) return [m];
|
|
@@ -33120,7 +33353,7 @@ function museHistory(path, files) {
|
|
|
33120
33353
|
function junieHistory(path, files) {
|
|
33121
33354
|
const { rows: rows2 } = jsonLines(files.get(path));
|
|
33122
33355
|
const messages = rows2.flatMap((r, i) => {
|
|
33123
|
-
const e10 =
|
|
33356
|
+
const e10 = object2(r.event?.agentEvent || r.event), kind = text(e10.kind);
|
|
33124
33357
|
if (!kind || /State|Snapshot/.test(kind)) return [];
|
|
33125
33358
|
return [recordEvent(r, text(r.id) || `event:${i}`, kind, r.timestampMs, e10.text ?? e10.prompt ?? e10.message)];
|
|
33126
33359
|
});
|
|
@@ -33128,16 +33361,16 @@ function junieHistory(path, files) {
|
|
|
33128
33361
|
return { nativeID: basename9(dirname7(path)), messages, partial: true, note: "Junie recorded agent events. State snapshots and opaque event bodies are omitted; events without an authoritative message role are not counted as user turns." };
|
|
33129
33362
|
}
|
|
33130
33363
|
function augmentHistory(path, files) {
|
|
33131
|
-
const r =
|
|
33364
|
+
const r = object2(json3(files.get(path)));
|
|
33132
33365
|
if (!text(r.sessionId) || !Array.isArray(r.chatHistory)) throw new Error("Unsupported Augment session.");
|
|
33133
33366
|
const messages = r.chatHistory.flatMap((turn, i) => {
|
|
33134
|
-
const exchange =
|
|
33367
|
+
const exchange = object2(turn.exchange), id2 = nativeText(turn.sequenceId) || `turn:${i}`;
|
|
33135
33368
|
return [recordEvent(turn, id2, turn.completed === true ? "Completed exchange" : "Incomplete exchange", turn.finishedAt, exchange.response_text)];
|
|
33136
33369
|
});
|
|
33137
33370
|
return { nativeID: r.sessionId, messages, partial: true, session: { title: text(r.title), created: time(r.created), model: text(r.agentState?.modelId) || "Unknown model" }, note: "Augment saved exchange records. Typed response-node payloads and absent prompts are not reconstructed into conversations." };
|
|
33138
33371
|
}
|
|
33139
33372
|
function fxHistory(path, files) {
|
|
33140
|
-
const usage =
|
|
33373
|
+
const usage = object2(json3(files.get(path))), meta = sidecar2(files, join21(dirname7(path), "session.json"));
|
|
33141
33374
|
const id2 = text(usage.session_id) || text(meta.id);
|
|
33142
33375
|
if (!id2 || !usage.snapshot || meta.id && meta.id !== id2) throw new Error("Unsupported Fx session metadata.");
|
|
33143
33376
|
return {
|
|
@@ -33182,7 +33415,7 @@ var definitions = [
|
|
|
33182
33415
|
const value = f.get(p), { rows: rows2 } = jsonLines(value), ids = new Set(rows2.map((r) => text(r.sessionId)).filter(Boolean));
|
|
33183
33416
|
if (ids.size !== 1) throw new Error("Headless capture needs one explicit session identity.");
|
|
33184
33417
|
const messages = rows2.flatMap((r, i) => {
|
|
33185
|
-
const m = message(
|
|
33418
|
+
const m = message(object2(r.message), text(r.message?.id) || `record:${i}`);
|
|
33186
33419
|
return m ? [m] : [];
|
|
33187
33420
|
});
|
|
33188
33421
|
return { nativeID: [...ids][0], messages, partial: true, note: "Previously captured MiniMax stream JSON only; no command is executed. User input and transient streaming records may be absent." };
|
|
@@ -33205,7 +33438,14 @@ var fileHarnessAdapters = definitions.map((source) => localFileAdapter({
|
|
|
33205
33438
|
// server/adapters/harness-databases.ts
|
|
33206
33439
|
import { lstat as lstat6, readFile as readFile4 } from "node:fs/promises";
|
|
33207
33440
|
import { isAbsolute as isAbsolute5, join as join22 } from "node:path";
|
|
33208
|
-
|
|
33441
|
+
function hermesContent(value) {
|
|
33442
|
+
if (typeof value !== "string" || !value.startsWith("\0json:")) return value;
|
|
33443
|
+
try {
|
|
33444
|
+
return JSON.parse(value.slice(6));
|
|
33445
|
+
} catch {
|
|
33446
|
+
return value;
|
|
33447
|
+
}
|
|
33448
|
+
}
|
|
33209
33449
|
var millisOrSeconds = (v3) => typeof v3 === "number" && v3 > 0 && v3 < 1e10 ? seconds(v3) : time(v3);
|
|
33210
33450
|
function dbPaths(id2, defaults, match2) {
|
|
33211
33451
|
return async () => {
|
|
@@ -33225,6 +33465,7 @@ function sessionHistory(r, messages, note) {
|
|
|
33225
33465
|
var hermes = {
|
|
33226
33466
|
id: "hermes",
|
|
33227
33467
|
name: "Hermes Agent",
|
|
33468
|
+
version: 3,
|
|
33228
33469
|
paths: async () => (await historyFiles(harnessRoots("hermes", () => [envHome("HERMES_HOME", ".hermes")])(), (p) => p === "state.db" || /^profiles\/[^/]+\/state\.db$/.test(p))).files,
|
|
33229
33470
|
table: "sessions",
|
|
33230
33471
|
key: "id",
|
|
@@ -33232,7 +33473,7 @@ var hermes = {
|
|
|
33232
33473
|
parse(db2, r) {
|
|
33233
33474
|
const messages = rows(db2, "messages", ["id", "message_uid", "role", "content", "timestamp", "tool_call_id", "tool_calls", "tool_name", "_compressed_summary"], ["session_id", r.id], "id").map((m) => {
|
|
33234
33475
|
if (m._compressed_summary) return recordEvent(m, text(m.message_uid) || nativeText(m.id), "Context summary", seconds(m.timestamp), m.content);
|
|
33235
|
-
return conversationMessage({ role: m.role, content:
|
|
33476
|
+
return conversationMessage({ role: m.role, content: hermesContent(m.content), timestamp: seconds(m.timestamp), tool_call_id: m.tool_call_id, toolCalls: optionalJSON(m.tool_calls), toolName: m.tool_name }, text(m.message_uid) || nativeText(m.id));
|
|
33236
33477
|
});
|
|
33237
33478
|
const h3 = sessionHistory({ ...r, created_at: seconds(r.started_at), updated_at: seconds(r.last_activity_at), provider: r.billing_provider }, messages, "Hermes saved message rows, including retained summaries. Compression/reset parent links are not subagent ancestry. Session usage aggregates are not used as message times.");
|
|
33238
33479
|
if (r.source === "subagent") h3.parent = text(r.parent_session_id) || void 0;
|
|
@@ -33269,9 +33510,9 @@ var openclaw = {
|
|
|
33269
33510
|
parse(db2, r) {
|
|
33270
33511
|
const events = rows(db2, "transcript_events", ["seq", "event_json", "event_zstd"], ["session_id", r.session_id], "seq");
|
|
33271
33512
|
const messages = events.flatMap((e10) => {
|
|
33272
|
-
const raw =
|
|
33513
|
+
const raw = object2(sqliteJSON(e10.event_json ?? e10.event_zstd));
|
|
33273
33514
|
if (raw.type !== "message") return [];
|
|
33274
|
-
const m = message(
|
|
33515
|
+
const m = message(object2(raw.message), text(raw.id) || `event:${e10.seq}`, raw.timestamp ?? raw.message?.timestamp);
|
|
33275
33516
|
return m ? [m] : [];
|
|
33276
33517
|
});
|
|
33277
33518
|
return sessionHistory({ ...r, id: r.session_id, provider: r.model_provider }, messages, "OpenClaw authoritative transcript events, including zstd payloads. Database sessions take precedence over migrated JSONL copies. Session rollover and event-parent links are not session ancestry.");
|
|
@@ -33288,7 +33529,7 @@ function forkStore(id2, name, defaultPath, desktop) {
|
|
|
33288
33529
|
parse(db2, r) {
|
|
33289
33530
|
if (desktop !== void 0 && text(r.version).startsWith("desktop-") !== desktop) return;
|
|
33290
33531
|
const messages = rows(db2, "message", ["id", "data", "time_created"], ["session_id", r.id], "time_created").map((m) => {
|
|
33291
|
-
const body2 =
|
|
33532
|
+
const body2 = object2(sqliteJSON(m.data));
|
|
33292
33533
|
let content = body2.parts ?? body2.content;
|
|
33293
33534
|
if (hasTable(db2, "part")) content = rows(db2, "part", ["id", "data"], ["message_id", m.id], "id").map((p) => sqliteJSON(p.data));
|
|
33294
33535
|
if (Array.isArray(content)) content = content.flatMap((p) => {
|
|
@@ -33313,11 +33554,11 @@ var zed = {
|
|
|
33313
33554
|
fields: ["id", "summary", "created_at", "updated_at", "data_type", "data", "folder_paths"],
|
|
33314
33555
|
parse(db2, r) {
|
|
33315
33556
|
if (!["json", "zstd"].includes(r.data_type)) throw new Error("Unsupported Zed encoding.");
|
|
33316
|
-
const body2 =
|
|
33557
|
+
const body2 = object2(sqliteJSON(r.data));
|
|
33317
33558
|
if (body2.imported === true) return;
|
|
33318
33559
|
if (!Array.isArray(body2.messages)) throw new Error("Unsupported Zed thread.");
|
|
33319
33560
|
const messages = body2.messages.map((raw, i) => {
|
|
33320
|
-
const user =
|
|
33561
|
+
const user = object2(raw.User), agent = object2(raw.Agent), b = raw.User ? user : agent;
|
|
33321
33562
|
if (!raw.User && !raw.Agent) return recordEvent(raw, `message:${i}`, "Context checkpoint", 0, raw.Compaction?.Summary);
|
|
33322
33563
|
const content = (Array.isArray(b.content) ? b.content : []).map((p) => typeof p.Text === "string" ? { type: "text", text: p.Text } : p.Thinking ? { type: "thinking", thinking: p.Thinking.text } : p.ToolUse ? { type: "tool_use", ...p.ToolUse } : { type: "unsupported" });
|
|
33323
33564
|
return conversationMessage({ role: raw.User ? "user" : "assistant", content }, text(b.id) || `message:${i}`);
|
|
@@ -33335,7 +33576,7 @@ var devin = {
|
|
|
33335
33576
|
fields: ["id", "working_directory", "model", "title", "created_at", "last_activity_at"],
|
|
33336
33577
|
parse(db2, r) {
|
|
33337
33578
|
const messages = rows(db2, "message_nodes", ["node_id", "chat_message", "created_at"], ["session_id", r.id], "row_id").flatMap((m) => {
|
|
33338
|
-
const raw =
|
|
33579
|
+
const raw = object2(sqliteJSON(m.chat_message)), result = message(raw, nativeText(m.node_id), millisOrSeconds(m.created_at));
|
|
33339
33580
|
return result ? [result] : [recordEvent(raw, nativeText(m.node_id), "Devin message node", millisOrSeconds(m.created_at))];
|
|
33340
33581
|
});
|
|
33341
33582
|
return sessionHistory({ ...r, created_at: millisOrSeconds(r.created_at), updated_at: millisOrSeconds(r.last_activity_at) }, messages, "Devin saved message nodes. All retained in-session branches are included; node-parent edges are not session ancestry.");
|
|
@@ -33398,9 +33639,9 @@ var octofriend = {
|
|
|
33398
33639
|
const row = rows(db2, "llm_irs", ["json"], ["id", item.llm_ir_id], void 0, 1)[0];
|
|
33399
33640
|
bytes2 += text(row?.json).length;
|
|
33400
33641
|
if (bytes2 > 32e6) throw new Error("Octofriend session exceeds the snapshot limit.");
|
|
33401
|
-
const payload =
|
|
33642
|
+
const payload = object2(sqliteJSON(row?.json));
|
|
33402
33643
|
if (payload.version !== "octo-llm-ir/v1") throw new Error("Unsupported Octofriend IR version.");
|
|
33403
|
-
const ir =
|
|
33644
|
+
const ir = object2(payload.ir), content = Array.isArray(ir.content) ? ir.content.map((p) => p.type === "text" ? { type: "text", text: p.content } : p) : ir.content;
|
|
33404
33645
|
const m = message({ ...ir, content, role: ir.role === "tool-output" ? "tool" : ir.role }, nativeText(node.id), node.created_at);
|
|
33405
33646
|
messages.push(m || recordEvent(ir, nativeText(node.id), text(ir.role), node.created_at));
|
|
33406
33647
|
}
|
|
@@ -33434,13 +33675,13 @@ var kiro = {
|
|
|
33434
33675
|
key: "conversation_id",
|
|
33435
33676
|
fields: ["key", "conversation_id", "value"],
|
|
33436
33677
|
parse(db2, r) {
|
|
33437
|
-
const body2 =
|
|
33678
|
+
const body2 = object2(sqliteJSON(r.value));
|
|
33438
33679
|
if (!Array.isArray(body2.history)) throw new Error("Unsupported Kiro conversation.");
|
|
33439
33680
|
const messages = body2.history.flatMap((turn, i) => {
|
|
33440
|
-
const result = [], input =
|
|
33681
|
+
const result = [], input = object2(turn.user?.content), output2 = object2(turn.assistant?.Response || turn.assistant?.ToolUse);
|
|
33441
33682
|
if (typeof input.Prompt?.prompt === "string") result.push(conversationMessage({ role: "user", content: input.Prompt.prompt }, `turn:${i}:user`));
|
|
33442
33683
|
if (input.ToolUseResults) result.push(conversationMessage({ role: "tool", content: input.ToolUseResults }, `turn:${i}:tool`));
|
|
33443
|
-
if (typeof
|
|
33684
|
+
if (typeof output2.content === "string") result.push(conversationMessage({ role: "assistant", content: output2.content, timestamp: turn.request_metadata?.stream_end_timestamp_ms }, `turn:${i}:assistant`));
|
|
33444
33685
|
return result;
|
|
33445
33686
|
});
|
|
33446
33687
|
const created = body2.history.map((t) => time(t.request_metadata?.request_start_timestamp_ms)).find(Boolean);
|
|
@@ -33465,7 +33706,6 @@ var databaseHarnessAdapters = [
|
|
|
33465
33706
|
// server/adapters/harness-metadata.ts
|
|
33466
33707
|
import { basename as basename10 } from "node:path";
|
|
33467
33708
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
33468
|
-
import { lstat as lstat7 } from "node:fs/promises";
|
|
33469
33709
|
function protoFields(value) {
|
|
33470
33710
|
if (value.length > 2e6) throw new Error("Trajectory metadata exceeds 2 MB.");
|
|
33471
33711
|
const fields2 = /* @__PURE__ */ new Map();
|
|
@@ -33512,15 +33752,15 @@ var antigravityDatabaseAdapters = ["antigravity-cli", "antigravity-extension"].m
|
|
|
33512
33752
|
const sec = timestamp.get(1), nano = timestamp.get(2);
|
|
33513
33753
|
const created = typeof sec === "bigint" && sec > 0n && sec < 8640000000000n ? time(Number(sec) * 1e3 + (typeof nano === "bigint" && nano < 1000000000n ? Number(nano) / 1e6 : 0)) : 0;
|
|
33514
33754
|
const uri = nested(fields2.get(1)).get(1);
|
|
33515
|
-
let
|
|
33755
|
+
let directory3 = "";
|
|
33516
33756
|
if (uri instanceof Uint8Array) {
|
|
33517
33757
|
try {
|
|
33518
|
-
|
|
33758
|
+
directory3 = fileURLToPath4(Buffer.from(uri).toString("utf8"));
|
|
33519
33759
|
} catch {
|
|
33520
33760
|
}
|
|
33521
33761
|
}
|
|
33522
33762
|
if (!created) throw new Error("Trajectory creation time is unavailable.");
|
|
33523
|
-
return { nativeID: basename10(path, ".db"), messages: [], partial: true, session: { created, directory:
|
|
33763
|
+
return { nativeID: basename10(path, ".db"), messages: [], partial: true, session: { created, directory: directory3 }, note: "Native Antigravity trajectory identity and creation metadata only. Protobuf conversation/step bodies are opaque; no message text, generation-time guesses, or usage-derived turns are imported." };
|
|
33524
33764
|
}
|
|
33525
33765
|
}));
|
|
33526
33766
|
var antigravityCacheAdapter = localFileAdapter({
|
|
@@ -33539,31 +33779,9 @@ var antigravityCacheAdapter = localFileAdapter({
|
|
|
33539
33779
|
return { nativeID: [...ids][0], messages: [], partial: true, session: { created, model: text(rows2.find((r) => r.modelId)?.modelId) || "Unknown model" }, note: "Previously synced Antigravity session identity; placement uses earliest recorded usage date. This cache has no conversation bodies. SessionGraph never runs sync or contacts the language server." };
|
|
33540
33780
|
}
|
|
33541
33781
|
});
|
|
33542
|
-
var usageOnlyAdapters = [
|
|
33543
|
-
{ id: "reasonix", name: "Reasonix", roots: () => [envHome("REASONIX_STATE_HOME", ".reasonix", "stats"), envHome("REASONIX_HOME", ".reasonix", "stats")], note: "Request statistics lack conversation identities and text. Reasonix transcript import is not yet supported." },
|
|
33544
|
-
{ id: "trae", name: "Trae / Trae Solo", roots: () => [tokscalePath("trae-cache/sessions")], note: "The Tokscale cache contains account usage, not local conversations." },
|
|
33545
|
-
{ id: "warp", name: "Warp / Oz", roots: () => [tokscalePath("warp-cache")], note: "The Tokscale cache contains aggregate requests and spend, not local conversations." },
|
|
33546
|
-
{ id: "lm-studio", name: "LM Studio", roots: () => [envHome("LM_STUDIO_HOME", ".lmstudio", "server-logs")], note: "Server logs contain final-response usage, not retained prompts or responses." },
|
|
33547
|
-
{ id: "hindsight", name: "Hindsight", roots: () => [envHome("HINDSIGHT_HOME", ".hindsight", "usage")], note: "Synced memory-operation usage is not agent conversation history." }
|
|
33548
|
-
].map((source) => ({
|
|
33549
|
-
id: source.id,
|
|
33550
|
-
name: source.name,
|
|
33551
|
-
description: `Detection only \xB7 ${source.note}`,
|
|
33552
|
-
capabilities: { history: false, forks: false, children: false, files: false },
|
|
33553
|
-
async detect() {
|
|
33554
|
-
for (const p of harnessRoots(source.id, source.roots)()) if ((await lstat7(p).catch(() => void 0))?.isDirectory()) return true;
|
|
33555
|
-
return false;
|
|
33556
|
-
},
|
|
33557
|
-
async discover() {
|
|
33558
|
-
return { sessions: [], projects: [], warnings: [source.note] };
|
|
33559
|
-
},
|
|
33560
|
-
async read() {
|
|
33561
|
-
throw new Error(source.note);
|
|
33562
|
-
}
|
|
33563
|
-
}));
|
|
33564
33782
|
|
|
33565
33783
|
// server/adapters/index.ts
|
|
33566
|
-
var extra = [...databaseHarnessAdapters, ...fileHarnessAdapters, antigravityCacheAdapter, ...antigravityDatabaseAdapters
|
|
33784
|
+
var extra = [...databaseHarnessAdapters, ...fileHarnessAdapters, antigravityCacheAdapter, ...antigravityDatabaseAdapters];
|
|
33567
33785
|
var grouped = /* @__PURE__ */ new Map();
|
|
33568
33786
|
for (const adapter of extra) grouped.set(adapter.id, [...grouped.get(adapter.id) || [], adapter]);
|
|
33569
33787
|
var adapters = [opencodeAdapter, claudeAdapter, codexAdapter, t3CodeAdapter, cursorAdapter, geminiAdapter, qwenAdapter, piAdapter, copilotAdapter, copilotChatAdapter, clineAdapter, rooAdapter, kiloAdapter, continueAdapter, ...[...grouped.values()].map((parts) => parts.length === 1 ? parts[0] : combineAdapters(parts))];
|
|
@@ -33598,6 +33816,160 @@ function validRecord(value, session) {
|
|
|
33598
33816
|
|
|
33599
33817
|
// server/event-store.ts
|
|
33600
33818
|
import { randomUUID } from "node:crypto";
|
|
33819
|
+
|
|
33820
|
+
// packages/core/src/commits.ts
|
|
33821
|
+
var abbreviatedSHA = (sha) => sha.length !== 40 && sha.length !== 64;
|
|
33822
|
+
|
|
33823
|
+
// server/library-query.ts
|
|
33824
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
33825
|
+
|
|
33826
|
+
// packages/core/src/layout.ts
|
|
33827
|
+
var directoryPath = (directory3) => (/^(?:[a-z]:[\\/]|\\\\)/i.test(directory3) ? directory3.replace(/\\/g, "/") : directory3).replace(/\/+$/, "") || (directory3.startsWith("/") ? "/" : "");
|
|
33828
|
+
var laneKey = (session) => session.directory ? JSON.stringify(["directory", directoryPath(session.directory)]) : JSON.stringify(["project", session.source || "opencode", session.projectID || session.id]);
|
|
33829
|
+
|
|
33830
|
+
// src/session-links.ts
|
|
33831
|
+
function visibleSessions(sessions) {
|
|
33832
|
+
const owners = /* @__PURE__ */ new Map();
|
|
33833
|
+
for (const session of sessions) {
|
|
33834
|
+
if (session.source !== "t3-code") continue;
|
|
33835
|
+
for (const id2 of new Set(session.linkedSessionIDs || [])) owners.set(id2, [...owners.get(id2) || [], session]);
|
|
33836
|
+
}
|
|
33837
|
+
const unique = new Map([...owners].flatMap(([native, claims]) => {
|
|
33838
|
+
const owner = claims[0];
|
|
33839
|
+
return claims.length === 1 && ["complete", "partial"].includes(owner.coverage?.history || "") && owner.activity?.userMessages ? [[native, owner.id]] : [];
|
|
33840
|
+
}));
|
|
33841
|
+
return sessions.filter((session) => !unique.has(session.id)).map((session) => ({
|
|
33842
|
+
...session,
|
|
33843
|
+
parentID: session.parentID ? unique.get(session.parentID) || session.parentID : void 0,
|
|
33844
|
+
forkID: session.forkID ? unique.get(session.forkID) || session.forkID : void 0
|
|
33845
|
+
}));
|
|
33846
|
+
}
|
|
33847
|
+
|
|
33848
|
+
// server/library-query.ts
|
|
33849
|
+
var LibraryError = class extends Error {
|
|
33850
|
+
constructor(code, message2, exitCode2 = 1) {
|
|
33851
|
+
super(message2);
|
|
33852
|
+
this.code = code;
|
|
33853
|
+
this.exitCode = exitCode2;
|
|
33854
|
+
}
|
|
33855
|
+
code;
|
|
33856
|
+
exitCode;
|
|
33857
|
+
};
|
|
33858
|
+
function invalid(message2) {
|
|
33859
|
+
throw new LibraryError("INVALID_ARGUMENT", message2, 2);
|
|
33860
|
+
}
|
|
33861
|
+
var fingerprint = (value) => createHash4("sha256").update(JSON.stringify(value)).digest("hex");
|
|
33862
|
+
function pageLimit(value = 50) {
|
|
33863
|
+
if (!Number.isSafeInteger(value) || value < 1 || value > 200) invalid("Limit must be an integer from 1 to 200.");
|
|
33864
|
+
return value;
|
|
33865
|
+
}
|
|
33866
|
+
function pageOffset(cursor, key) {
|
|
33867
|
+
if (!cursor) return 0;
|
|
33868
|
+
let parsed;
|
|
33869
|
+
try {
|
|
33870
|
+
if (cursor.length > 512 || !/^[\w-]+$/.test(cursor)) throw new Error();
|
|
33871
|
+
parsed = JSON.parse(Buffer.from(cursor, "base64url").toString());
|
|
33872
|
+
if (!parsed || !Number.isSafeInteger(parsed.offset) || parsed.offset < 0 || typeof parsed.key !== "string") throw new Error();
|
|
33873
|
+
} catch {
|
|
33874
|
+
return invalid("Invalid cursor. Use nextCursor from the previous response.");
|
|
33875
|
+
}
|
|
33876
|
+
if (parsed.key !== key) throw new LibraryError("STALE_CURSOR", "Saved history or query changed. Restart without --cursor.");
|
|
33877
|
+
return parsed.offset;
|
|
33878
|
+
}
|
|
33879
|
+
var nextCursor = (key, offset) => Buffer.from(JSON.stringify({ key, offset })).toString("base64url");
|
|
33880
|
+
|
|
33881
|
+
// server/commit-store.ts
|
|
33882
|
+
var COMMIT_SCHEMA = `CREATE TABLE IF NOT EXISTS session_commits (
|
|
33883
|
+
session_id TEXT NOT NULL REFERENCES sessions(id) ON DELETE CASCADE,
|
|
33884
|
+
sha TEXT NOT NULL, repository_path TEXT NOT NULL, operation TEXT NOT NULL,
|
|
33885
|
+
occurred_at REAL, evidence_event_id TEXT NOT NULL,
|
|
33886
|
+
PRIMARY KEY(session_id,repository_path,sha,operation),
|
|
33887
|
+
FOREIGN KEY(session_id,evidence_event_id) REFERENCES timeline_items(session_id,id) ON DELETE CASCADE);
|
|
33888
|
+
CREATE INDEX IF NOT EXISTS session_commits_time ON session_commits(session_id,occurred_at);`;
|
|
33889
|
+
var supported = /* @__PURE__ */ new Set(["opencode", "t3-code", "codex", "claude-code"]);
|
|
33890
|
+
var pendingCommits = () => ({ version: 0, state: "pending", count: null, note: "Refresh sources to index recorded commit operations." });
|
|
33891
|
+
function writeCommits(db2, session) {
|
|
33892
|
+
db2.prepare("DELETE FROM session_commits WHERE session_id=?").run(session.id);
|
|
33893
|
+
const base = { version: COMMIT_EXTRACTOR_VERSION, indexedAt: Date.now() };
|
|
33894
|
+
if (!supported.has(session.source || "")) return { ...base, state: "unavailable", count: null, note: "Commit attribution is not validated for this source format." };
|
|
33895
|
+
const calls = /* @__PURE__ */ new Map();
|
|
33896
|
+
const results = /* @__PURE__ */ new Map();
|
|
33897
|
+
const rows2 = () => db2.prepare("SELECT data FROM timeline_items WHERE session_id=? AND kind IN ('tool_call','tool_result') ORDER BY ordinal").iterate(session.id);
|
|
33898
|
+
let tools = 0, partial = session.coverage?.history !== "complete" || Boolean(db2.prepare("SELECT partial FROM timeline_coverage WHERE session_id=?").get(session.id)?.partial);
|
|
33899
|
+
for (const row of rows2()) {
|
|
33900
|
+
const item = JSON.parse(String(row.data));
|
|
33901
|
+
tools++;
|
|
33902
|
+
if (item.kind === "tool_result" && item.callID) {
|
|
33903
|
+
const signature = fingerprint([item.output, item.exitCode, item.status, item.gitCommit]);
|
|
33904
|
+
results.set(item.callID, results.has(item.callID) && results.get(item.callID) !== signature ? null : signature);
|
|
33905
|
+
}
|
|
33906
|
+
if (item.kind !== "tool_call" || !item.callID) continue;
|
|
33907
|
+
calls.set(item.callID, calls.has(item.callID) ? null : item);
|
|
33908
|
+
}
|
|
33909
|
+
const completed = /* @__PURE__ */ new Set();
|
|
33910
|
+
const insert = db2.prepare("INSERT OR IGNORE INTO session_commits VALUES (?,?,?,?,?,?)");
|
|
33911
|
+
for (const row of rows2()) {
|
|
33912
|
+
const item = JSON.parse(String(row.data));
|
|
33913
|
+
if (item.kind !== "tool_result") continue;
|
|
33914
|
+
const call = item.input ? item : item.callID ? calls.get(item.callID) : void 0;
|
|
33915
|
+
if (!call || call !== item && call.ordinal >= item.ordinal || item.callID && results.get(item.callID) === null) {
|
|
33916
|
+
partial = true;
|
|
33917
|
+
continue;
|
|
33918
|
+
}
|
|
33919
|
+
if (item.callID) completed.add(item.callID);
|
|
33920
|
+
const extracted = extractCommit(call, item);
|
|
33921
|
+
if (!extracted.candidate) continue;
|
|
33922
|
+
const time4 = item.endTime ?? item.time;
|
|
33923
|
+
if (time4 !== null && time4 < session.created || session.forkID && (time4 === null || time4 <= session.created || call.time === null || call.time < session.created)) {
|
|
33924
|
+
partial = true;
|
|
33925
|
+
continue;
|
|
33926
|
+
}
|
|
33927
|
+
if (!extracted.commit) {
|
|
33928
|
+
partial = true;
|
|
33929
|
+
continue;
|
|
33930
|
+
}
|
|
33931
|
+
const { sha, repositoryPath, operation: operation2 } = extracted.commit;
|
|
33932
|
+
insert.run(session.id, sha, repositoryPath, operation2, time4, item.id);
|
|
33933
|
+
}
|
|
33934
|
+
for (const [id2, call] of calls) if (call && !completed.has(id2) && /\bgit\b[\s\S]*\b(?:commit|cherry-pick)\b/.test(call.input || "")) partial = true;
|
|
33935
|
+
const count = Number(db2.prepare("SELECT count(*) AS n FROM session_commits WHERE session_id=?").get(session.id).n);
|
|
33936
|
+
return {
|
|
33937
|
+
...base,
|
|
33938
|
+
state: !tools ? "unavailable" : partial ? "partial" : "indexed",
|
|
33939
|
+
count: !tools ? null : count,
|
|
33940
|
+
note: !tools ? "No usable tool executions recorded; commit history is unknown." : `${partial ? "Some execution evidence is missing, ambiguous, inherited, or unsupported. " : ""}Confirmed recorded operations only; absence is not proof that no commits occurred. Paths are execution directories; abbreviated SHAs remain unresolved. Linked provider histories retain their own attribution.`
|
|
33941
|
+
};
|
|
33942
|
+
}
|
|
33943
|
+
function commit(row) {
|
|
33944
|
+
return { sessionID: String(row.session_id), sha: String(row.sha), repositoryPath: String(row.repository_path), operation: row.operation, occurredAt: row.occurred_at === null ? null : Number(row.occurred_at), evidenceEventID: String(row.evidence_event_id) };
|
|
33945
|
+
}
|
|
33946
|
+
function readCommits(db2, session, options = {}) {
|
|
33947
|
+
let coverage2 = session.commits || pendingCommits();
|
|
33948
|
+
if (session.coverage?.note?.startsWith("Latest import failed:")) coverage2 = { ...coverage2, state: coverage2.count === null ? coverage2.state : "partial", note: `${session.coverage.note} ${coverage2.note}` };
|
|
33949
|
+
const revision2 = String(db2.prepare("SELECT revision FROM timeline_coverage WHERE session_id=?").get(session.id)?.revision || "pending");
|
|
33950
|
+
const key = fingerprint(["commits", session.id, revision2, coverage2]), offset = pageOffset(options.cursor, key), limit = pageLimit(options.limit);
|
|
33951
|
+
const total = Number(db2.prepare("SELECT count(*) AS n FROM session_commits WHERE session_id=?").get(session.id).n);
|
|
33952
|
+
const items = db2.prepare("SELECT * FROM session_commits WHERE session_id=? ORDER BY occurred_at IS NULL,occurred_at,repository_path,sha,operation LIMIT ? OFFSET ?").all(session.id, limit, offset).map(commit);
|
|
33953
|
+
return { sessionID: session.id, revision: revision2, coverage: coverage2, items, total, nextCursor: offset + limit < total ? nextCursor(key, offset + limit) : null };
|
|
33954
|
+
}
|
|
33955
|
+
function commitMarkers(db2, session) {
|
|
33956
|
+
const end = Math.max(session.created, session.activity?.lastMessageAt || session.created);
|
|
33957
|
+
return db2.prepare("SELECT * FROM session_commits WHERE session_id=? AND occurred_at>=? AND occurred_at<=? ORDER BY occurred_at,sha LIMIT 2000").all(session.id, session.created, end).map((row, ordinal) => {
|
|
33958
|
+
const value = commit(row);
|
|
33959
|
+
return {
|
|
33960
|
+
id: value.evidenceEventID,
|
|
33961
|
+
kind: "commit",
|
|
33962
|
+
name: `${value.operation} ${value.sha}`,
|
|
33963
|
+
time: value.occurredAt,
|
|
33964
|
+
timeSource: "recorded",
|
|
33965
|
+
ordinal,
|
|
33966
|
+
preview: `${value.repositoryPath}
|
|
33967
|
+
${abbreviatedSHA(value.sha) ? "Abbreviated SHA \xB7 " : ""}Open recorded execution evidence`
|
|
33968
|
+
};
|
|
33969
|
+
});
|
|
33970
|
+
}
|
|
33971
|
+
|
|
33972
|
+
// server/event-store.ts
|
|
33601
33973
|
var EVENT_SCHEMA = `CREATE TABLE IF NOT EXISTS timeline_items (
|
|
33602
33974
|
session_id TEXT NOT NULL REFERENCES sessions(id) ON DELETE CASCADE, id TEXT NOT NULL, message_id TEXT NOT NULL,
|
|
33603
33975
|
ordinal INTEGER NOT NULL, kind TEXT NOT NULL, role TEXT, time REAL, call_id TEXT, name TEXT NOT NULL, preview TEXT NOT NULL, data TEXT NOT NULL,
|
|
@@ -33649,7 +34021,8 @@ function readEventMarkers(db2, session) {
|
|
|
33649
34021
|
const end = Math.max(session.created, session.activity?.lastMessageAt || session.created);
|
|
33650
34022
|
const totals = db2.prepare(`SELECT count(*) AS total, count(*) FILTER (WHERE time IS NULL) AS untimed, count(*) FILTER (WHERE time<? OR time>?) AS outside FROM timeline_items WHERE session_id=? AND (${filters.messages})`).get(session.created, end, session.id);
|
|
33651
34023
|
const rows2 = db2.prepare(`SELECT ${summaryColumns} FROM timeline_items WHERE session_id=? AND (${filters.messages}) AND time>=? AND time<=? ORDER BY time DESC,ordinal DESC`).all(session.id, session.created, end);
|
|
33652
|
-
|
|
34024
|
+
const commits = commitMarkers(db2, session);
|
|
34025
|
+
return { sessionID: session.id, ...coverage(db2, session), commits: session.commits, items: [...rows2.reverse().map(eventSummary), ...commits].sort((a, b) => a.time - b.time || a.ordinal - b.ordinal), total: Number(totals.total), untimed: Number(totals.untimed), outsideLifetime: Number(totals.outside), limited: Number(totals.total) - Number(totals.untimed) - Number(totals.outside) > rows2.length || commits.length === 2e3 };
|
|
33653
34026
|
}
|
|
33654
34027
|
function readEvents(db2, session, options = {}) {
|
|
33655
34028
|
const state2 = coverage(db2, session), filter = options.filter || "all", size = 60;
|
|
@@ -33769,61 +34142,6 @@ function normalizeViewState(value) {
|
|
|
33769
34142
|
return result;
|
|
33770
34143
|
}
|
|
33771
34144
|
|
|
33772
|
-
// src/session-links.ts
|
|
33773
|
-
function visibleSessions(sessions) {
|
|
33774
|
-
const owners = /* @__PURE__ */ new Map();
|
|
33775
|
-
for (const session of sessions) {
|
|
33776
|
-
if (session.source !== "t3-code" || session.coverage?.history !== "complete" || !session.activity?.userMessages) continue;
|
|
33777
|
-
for (const id2 of session.linkedSessionIDs || []) owners.set(id2, [...owners.get(id2) || [], session.id]);
|
|
33778
|
-
}
|
|
33779
|
-
const unique = new Map([...owners].flatMap(([native, ids]) => ids.length === 1 ? [[native, ids[0]]] : []));
|
|
33780
|
-
return sessions.filter((session) => !unique.has(session.id)).map((session) => ({
|
|
33781
|
-
...session,
|
|
33782
|
-
parentID: session.parentID ? unique.get(session.parentID) || session.parentID : void 0,
|
|
33783
|
-
forkID: session.forkID ? unique.get(session.forkID) || session.forkID : void 0
|
|
33784
|
-
}));
|
|
33785
|
-
}
|
|
33786
|
-
|
|
33787
|
-
// server/library-query.ts
|
|
33788
|
-
import { createHash as createHash4 } from "node:crypto";
|
|
33789
|
-
|
|
33790
|
-
// packages/core/src/layout.ts
|
|
33791
|
-
var directoryPath = (directory2) => (/^(?:[a-z]:[\\/]|\\\\)/i.test(directory2) ? directory2.replace(/\\/g, "/") : directory2).replace(/\/+$/, "") || (directory2.startsWith("/") ? "/" : "");
|
|
33792
|
-
var laneKey = (session) => session.directory ? JSON.stringify(["directory", directoryPath(session.directory)]) : JSON.stringify(["project", session.source || "opencode", session.projectID || session.id]);
|
|
33793
|
-
|
|
33794
|
-
// server/library-query.ts
|
|
33795
|
-
var LibraryError = class extends Error {
|
|
33796
|
-
constructor(code, message2, exitCode = 1) {
|
|
33797
|
-
super(message2);
|
|
33798
|
-
this.code = code;
|
|
33799
|
-
this.exitCode = exitCode;
|
|
33800
|
-
}
|
|
33801
|
-
code;
|
|
33802
|
-
exitCode;
|
|
33803
|
-
};
|
|
33804
|
-
function invalid(message2) {
|
|
33805
|
-
throw new LibraryError("INVALID_ARGUMENT", message2, 2);
|
|
33806
|
-
}
|
|
33807
|
-
var fingerprint = (value) => createHash4("sha256").update(JSON.stringify(value)).digest("hex");
|
|
33808
|
-
function pageLimit(value = 50) {
|
|
33809
|
-
if (!Number.isSafeInteger(value) || value < 1 || value > 200) invalid("Limit must be an integer from 1 to 200.");
|
|
33810
|
-
return value;
|
|
33811
|
-
}
|
|
33812
|
-
function pageOffset(cursor, key) {
|
|
33813
|
-
if (!cursor) return 0;
|
|
33814
|
-
let parsed;
|
|
33815
|
-
try {
|
|
33816
|
-
if (cursor.length > 512 || !/^[\w-]+$/.test(cursor)) throw new Error();
|
|
33817
|
-
parsed = JSON.parse(Buffer.from(cursor, "base64url").toString());
|
|
33818
|
-
if (!parsed || !Number.isSafeInteger(parsed.offset) || parsed.offset < 0 || typeof parsed.key !== "string") throw new Error();
|
|
33819
|
-
} catch {
|
|
33820
|
-
return invalid("Invalid cursor. Use nextCursor from the previous response.");
|
|
33821
|
-
}
|
|
33822
|
-
if (parsed.key !== key) throw new LibraryError("STALE_CURSOR", "Saved history or query changed. Restart without --cursor.");
|
|
33823
|
-
return parsed.offset;
|
|
33824
|
-
}
|
|
33825
|
-
var nextCursor = (key, offset) => Buffer.from(JSON.stringify({ key, offset })).toString("base64url");
|
|
33826
|
-
|
|
33827
34145
|
// server/store.ts
|
|
33828
34146
|
var SessionGraphStore = class {
|
|
33829
34147
|
constructor(path = databasePath()) {
|
|
@@ -33833,7 +34151,7 @@ var SessionGraphStore = class {
|
|
|
33833
34151
|
if (path !== ":memory:") chmodSync3(path, 384);
|
|
33834
34152
|
this.db.exec("PRAGMA journal_mode=WAL; PRAGMA foreign_keys=ON; PRAGMA busy_timeout=5000;");
|
|
33835
34153
|
const version = Number(this.db.prepare("PRAGMA user_version").get().user_version);
|
|
33836
|
-
if (version >
|
|
34154
|
+
if (version > 6) throw new Error("This SessionGraph database requires a newer version of the app.");
|
|
33837
34155
|
this.db.exec(`
|
|
33838
34156
|
CREATE TABLE IF NOT EXISTS settings (key TEXT PRIMARY KEY, value TEXT NOT NULL);
|
|
33839
34157
|
CREATE TABLE IF NOT EXISTS sources (id TEXT PRIMARY KEY, last_import INTEGER, error TEXT);
|
|
@@ -33881,6 +34199,35 @@ var SessionGraphStore = class {
|
|
|
33881
34199
|
throw error;
|
|
33882
34200
|
}
|
|
33883
34201
|
}
|
|
34202
|
+
if (version < 5) {
|
|
34203
|
+
this.db.exec("BEGIN IMMEDIATE");
|
|
34204
|
+
try {
|
|
34205
|
+
this.db.exec(COMMIT_SCHEMA);
|
|
34206
|
+
this.db.prepare("UPDATE sessions SET metadata=json_set(metadata,'$.commits',json(?))").run(JSON.stringify(pendingCommits()));
|
|
34207
|
+
this.db.exec("PRAGMA user_version=5; COMMIT");
|
|
34208
|
+
} catch (error) {
|
|
34209
|
+
this.db.exec("ROLLBACK");
|
|
34210
|
+
throw error;
|
|
34211
|
+
}
|
|
34212
|
+
}
|
|
34213
|
+
if (version < 6) {
|
|
34214
|
+
this.db.exec("BEGIN IMMEDIATE");
|
|
34215
|
+
try {
|
|
34216
|
+
const retired = /* @__PURE__ */ new Set(["reasonix", "trae", "warp", "lm-studio", "hindsight"]);
|
|
34217
|
+
const selected = this.setting("selected");
|
|
34218
|
+
if (selected) this.setting("selected", selected.filter((id2) => !retired.has(id2)));
|
|
34219
|
+
const paths2 = this.setting("sourcePaths");
|
|
34220
|
+
if (paths2) this.setting("sourcePaths", Object.fromEntries(Object.entries(paths2).filter(([id2]) => !retired.has(id2))));
|
|
34221
|
+
const view = this.setting("viewState");
|
|
34222
|
+
if (view && typeof view.sourceID === "string" && retired.has(view.sourceID)) this.setting("viewState", { ...view, sourceID: "" });
|
|
34223
|
+
const remove = this.db.prepare("DELETE FROM sources WHERE id=?");
|
|
34224
|
+
for (const id2 of retired) remove.run(id2);
|
|
34225
|
+
this.db.exec("PRAGMA user_version=6; COMMIT");
|
|
34226
|
+
} catch (error) {
|
|
34227
|
+
this.db.exec("ROLLBACK");
|
|
34228
|
+
throw error;
|
|
34229
|
+
}
|
|
34230
|
+
}
|
|
33884
34231
|
if (!this.setting("libraryID")) this.setting("libraryID", randomUUID2());
|
|
33885
34232
|
}
|
|
33886
34233
|
path;
|
|
@@ -33934,6 +34281,9 @@ var SessionGraphStore = class {
|
|
|
33934
34281
|
revision(id2) {
|
|
33935
34282
|
return this.db.prepare("SELECT imported_revision FROM sessions WHERE id=?").get(id2)?.imported_revision;
|
|
33936
34283
|
}
|
|
34284
|
+
commitsCurrent(id2) {
|
|
34285
|
+
return this.getSession(id2)?.commits?.version === COMMIT_EXTRACTOR_VERSION;
|
|
34286
|
+
}
|
|
33937
34287
|
upsert(candidate) {
|
|
33938
34288
|
const s = candidate.session, previous = this.getSession(s.id);
|
|
33939
34289
|
const metadata2 = {
|
|
@@ -33941,6 +34291,7 @@ var SessionGraphStore = class {
|
|
|
33941
34291
|
model: s.model === "Unknown model" ? previous?.model || s.model : s.model,
|
|
33942
34292
|
parentID: previous?.parentID && candidate.locator.agent ? previous.parentID : s.parentID,
|
|
33943
34293
|
activity: previous?.activity,
|
|
34294
|
+
commits: previous?.commits || pendingCommits(),
|
|
33944
34295
|
revision: previous?.revision || "",
|
|
33945
34296
|
coverage: previous?.coverage || { history: "pending" }
|
|
33946
34297
|
};
|
|
@@ -33955,8 +34306,9 @@ var SessionGraphStore = class {
|
|
|
33955
34306
|
const insert = this.db.prepare("INSERT INTO messages (session_id,id,ordinal,data,time,is_user) VALUES (?,?,?,?,?,?) ON CONFLICT(session_id,id) DO UPDATE SET ordinal=excluded.ordinal,data=excluded.data,time=excluded.time,is_user=excluded.is_user");
|
|
33956
34307
|
messages.forEach((message2, i) => insert.run(s.id, message2.id, i, JSON.stringify(message2), messageTime(message2.time), Number(isUserMessage(message2))));
|
|
33957
34308
|
writeEvents(this.db, s.id, this.db.prepare("SELECT data FROM messages WHERE session_id=? ORDER BY ordinal").iterate(s.id));
|
|
34309
|
+
const commits = writeCommits(this.db, s);
|
|
33958
34310
|
const activity = this.db.prepare(activitySQL).get(s.id);
|
|
33959
|
-
this.db.prepare("UPDATE sessions SET metadata=?, imported_revision=? WHERE id=?").run(JSON.stringify({ ...s, activity }), candidate.revision, s.id);
|
|
34311
|
+
this.db.prepare("UPDATE sessions SET metadata=?, imported_revision=? WHERE id=?").run(JSON.stringify({ ...s, activity, commits }), candidate.revision, s.id);
|
|
33960
34312
|
this.db.prepare("DELETE FROM search_cache WHERE id=?").run(s.id);
|
|
33961
34313
|
this.db.exec("COMMIT");
|
|
33962
34314
|
} catch (error) {
|
|
@@ -34045,6 +34397,9 @@ var SessionGraphStore = class {
|
|
|
34045
34397
|
eventMarkers(id2) {
|
|
34046
34398
|
return this.readSnapshot(id2, (session) => readEventMarkers(this.db, session));
|
|
34047
34399
|
}
|
|
34400
|
+
commits(id2, options = {}) {
|
|
34401
|
+
return this.readSnapshot(id2, (session) => readCommits(this.db, session, options));
|
|
34402
|
+
}
|
|
34048
34403
|
readSnapshot(id2, read3) {
|
|
34049
34404
|
this.db.exec("BEGIN");
|
|
34050
34405
|
try {
|
|
@@ -34248,7 +34603,7 @@ var Importer = class {
|
|
|
34248
34603
|
for (const candidate of seen.values()) {
|
|
34249
34604
|
this.store.upsert(candidate);
|
|
34250
34605
|
const saved = this.store.getSession(candidate.session.id);
|
|
34251
|
-
const retry = !saved?.coverage?.importedAt || saved.coverage.note?.startsWith("Latest import failed:");
|
|
34606
|
+
const retry = !saved?.coverage?.importedAt || saved.coverage.note?.startsWith("Latest import failed:") || !this.store.commitsCurrent(candidate.session.id);
|
|
34252
34607
|
if (!retry && saved?.revision === candidate.revision && this.store.revision(candidate.session.id) === candidate.revision) {
|
|
34253
34608
|
this.status.unchanged++;
|
|
34254
34609
|
continue;
|
|
@@ -34292,6 +34647,7 @@ var Importer = class {
|
|
|
34292
34647
|
} while (cursor);
|
|
34293
34648
|
const values = [...messages.values()];
|
|
34294
34649
|
if (adapter.id === "opencode") values.reverse();
|
|
34650
|
+
if (saved?.activity?.userMessages && values.every((message2) => message2.role === "system")) throw new Error("Source has no readable conversation. Previous imports are retained.");
|
|
34295
34651
|
this.store.replace(candidate, values, partial, note);
|
|
34296
34652
|
this.status.imported++;
|
|
34297
34653
|
} catch (error) {
|
|
@@ -34390,10 +34746,10 @@ function shellQuote(value, platform = process.platform) {
|
|
|
34390
34746
|
if (/[\x00-\x1f\x7f]/.test(value)) throw new Error("Paths and launch arguments must not contain control characters.");
|
|
34391
34747
|
return `'${value.replaceAll("'", platform === "win32" ? "''" : "'\\''")}'`;
|
|
34392
34748
|
}
|
|
34393
|
-
function launchCommand(binary, args,
|
|
34749
|
+
function launchCommand(binary, args, directory3, platform = process.platform) {
|
|
34394
34750
|
const quote = (value) => shellQuote(value, platform);
|
|
34395
|
-
const
|
|
34396
|
-
return platform === "win32" ? `Set-Location -LiteralPath ${quote(
|
|
34751
|
+
const invocation2 = [binary, ...args].map(quote).join(" ");
|
|
34752
|
+
return platform === "win32" ? `Set-Location -LiteralPath ${quote(directory3)}; if ($?) { & ${invocation2} }` : `cd -- ${quote(directory3)} && ${invocation2}`;
|
|
34397
34753
|
}
|
|
34398
34754
|
|
|
34399
34755
|
// server/handoff.ts
|
|
@@ -34462,10 +34818,10 @@ This handoff transfers saved text and file-change evidence, not files, credentia
|
|
|
34462
34818
|
` + chunks.map((c) => c.text).join("\n");
|
|
34463
34819
|
return { text: text2, messages: chunks.length, totalMessages, partial, note };
|
|
34464
34820
|
}
|
|
34465
|
-
async function saveHandoff(snapshot2,
|
|
34821
|
+
async function saveHandoff(snapshot2, directory3) {
|
|
34466
34822
|
const { text: text2, ...coverage2 } = handoffDocument(snapshot2);
|
|
34467
34823
|
const digest2 = createHash5("sha256").update(text2).digest("hex");
|
|
34468
|
-
const root3 = join24(
|
|
34824
|
+
const root3 = join24(directory3, "handoffs");
|
|
34469
34825
|
await mkdir(root3, { recursive: true, mode: 448 });
|
|
34470
34826
|
const path = join24(root3, `${digest2}.md`), temporary = join24(root3, `.${randomUUID3()}.tmp`);
|
|
34471
34827
|
try {
|
|
@@ -34497,14 +34853,14 @@ async function getLaunchConnection(session) {
|
|
|
34497
34853
|
}
|
|
34498
34854
|
return { webBaseUrl, terminalAvailable: Boolean(terminal), targets };
|
|
34499
34855
|
}
|
|
34500
|
-
async function prepareLaunch(store, session, target,
|
|
34856
|
+
async function prepareLaunch(store, session, target, directory3 = session.directory) {
|
|
34501
34857
|
if (!isHarness(target)) throw new Error("Choose a supported destination app.");
|
|
34502
|
-
if (typeof
|
|
34503
|
-
if (!(await stat4(
|
|
34858
|
+
if (typeof directory3 !== "string" || !isAbsolute7(directory3) || /[\x00-\x1f\x7f]/.test(directory3)) throw new Error("Choose an absolute working directory.");
|
|
34859
|
+
if (!(await stat4(directory3).catch(() => void 0))?.isDirectory()) throw new Error("Working directory is unavailable. Choose an existing directory.");
|
|
34504
34860
|
const [binary, terminal] = await Promise.all([harnessExecutable(target), terminalExecutable()]);
|
|
34505
34861
|
let args;
|
|
34506
34862
|
const subagent = session.source === "claude-code" && Boolean(session.parentID) && /^[\w-]+\/agent\/[\w-]+$/.test(session.nativeID || "");
|
|
34507
|
-
const localHandoff = session.nativeResume === false || ["cursor", "gemini", "qwen-code", "pi", "copilot"].includes(session.source || "") && (!session.nativeResume ||
|
|
34863
|
+
const localHandoff = session.nativeResume === false || ["cursor", "gemini", "qwen-code", "pi", "copilot"].includes(session.source || "") && (!session.nativeResume || directory3 !== session.directory);
|
|
34508
34864
|
if (target === (session.source || "opencode") && !subagent && !localHandoff) args = resumeArgs(session);
|
|
34509
34865
|
const mode = args ? "resume" : "handoff";
|
|
34510
34866
|
if (mode === "handoff" && store.path === ":memory:") throw new Error("Save this library before creating a context handoff.");
|
|
@@ -34513,8 +34869,8 @@ async function prepareLaunch(store, session, target, directory2 = session.direct
|
|
|
34513
34869
|
const prompt = `Read the saved conversation in ${JSON.stringify(context.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.`;
|
|
34514
34870
|
args = target === "opencode" ? ["--prompt", prompt] : target === "gemini" || target === "qwen-code" ? ["--prompt-interactive", prompt] : target === "copilot" ? ["--interactive", prompt] : [prompt];
|
|
34515
34871
|
}
|
|
34516
|
-
const command = launchCommand(binary || HARNESSES.find((h3) => h3.id === target).command, args,
|
|
34517
|
-
return { command, directory:
|
|
34872
|
+
const command = launchCommand(binary || HARNESSES.find((h3) => h3.id === target).command, args, directory3);
|
|
34873
|
+
return { command, directory: directory3, mode, context, targetAvailable: Boolean(binary), terminalAvailable: Boolean(binary && terminal) && !(target === "opencode" && mode === "resume" && serviceFile()) };
|
|
34518
34874
|
}
|
|
34519
34875
|
function macTerminalInvocation(command) {
|
|
34520
34876
|
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] };
|
|
@@ -34536,17 +34892,17 @@ async function launchTerminal(session, prepared) {
|
|
|
34536
34892
|
}
|
|
34537
34893
|
const terminal = await terminalExecutable();
|
|
34538
34894
|
if (!terminal) throw new Error("No supported terminal was found. Copy the command instead.");
|
|
34539
|
-
const
|
|
34895
|
+
const invocation2 = commandInvocation(prepared.command, terminal);
|
|
34540
34896
|
if (process.platform === "linux") {
|
|
34541
34897
|
await new Promise((resolve3, reject) => {
|
|
34542
|
-
const child = spawn2(
|
|
34898
|
+
const child = spawn2(invocation2.file, invocation2.args, { detached: true, stdio: "ignore" });
|
|
34543
34899
|
child.once("error", reject);
|
|
34544
34900
|
child.once("spawn", () => {
|
|
34545
34901
|
child.unref();
|
|
34546
34902
|
resolve3();
|
|
34547
34903
|
});
|
|
34548
34904
|
});
|
|
34549
|
-
} else await exec(
|
|
34905
|
+
} else await exec(invocation2.file, invocation2.args, { timeout: 15e3, maxBuffer: 16384 });
|
|
34550
34906
|
}
|
|
34551
34907
|
|
|
34552
34908
|
// server/publishing.ts
|
|
@@ -34613,20 +34969,19 @@ var sources = {
|
|
|
34613
34969
|
mux: { name: "Mux", icon: "mux" },
|
|
34614
34970
|
antigravity: { name: "Antigravity", icon: "antigravity" },
|
|
34615
34971
|
"antigravity-cli": { name: "Antigravity CLI", icon: "antigravity" },
|
|
34616
|
-
"antigravity-extension": { name: "Antigravity IDE Extension", icon: "antigravity" }
|
|
34617
|
-
reasonix: { name: "Reasonix", icon: "reasonix" },
|
|
34618
|
-
trae: { name: "Trae / Trae Solo", icon: "trae" },
|
|
34619
|
-
warp: { name: "Warp / Oz", icon: "warp" },
|
|
34620
|
-
"lm-studio": { name: "LM Studio", icon: "lmstudio" },
|
|
34621
|
-
hindsight: { name: "Hindsight", icon: "hindsight" }
|
|
34972
|
+
"antigravity-extension": { name: "Antigravity IDE Extension", icon: "antigravity" }
|
|
34622
34973
|
};
|
|
34623
34974
|
var isKnownSource = (id2) => typeof id2 === "string" && Object.hasOwn(sources, id2);
|
|
34624
34975
|
|
|
34976
|
+
// packages/core/src/anonymous-projects.ts
|
|
34977
|
+
var adjectives = "Cosmic Wobbly Disco Sneaky Bouncy Galactic Crispy Dizzy Fuzzy Noodle Groovy Sleepy Spicy Jolly Loopy Squishy Turbo Giggly Velvet Soggy Zippy Fluffy Moonwalking Wiggly Fizzy Snazzy Goofy Jazzy Tiny Chunky Dapper Wacky".split(" ");
|
|
34978
|
+
var nouns = "Wombat Pickle Pancake Badger Potato Narwhal Noodle Goblin Otter Turnip Hamster Comet Dumpling Goose Biscuit Llama Muffin Squid Raccoon Toaster Waffle Penguin Yeti Pudding Walrus Taco Jellybean Platypus Sloth Cactus Donut Mongoose".split(" ");
|
|
34979
|
+
|
|
34625
34980
|
// packages/core/src/public-graph.ts
|
|
34626
34981
|
var DEFAULT_PUBLISHING = { tokens: true, timestamps: true, messageCounts: true, messageTimestamps: true, model: true, harness: true };
|
|
34627
34982
|
function publishingSettings(value) {
|
|
34628
34983
|
const result = { ...DEFAULT_PUBLISHING };
|
|
34629
|
-
if (
|
|
34984
|
+
if (object3(value)) {
|
|
34630
34985
|
for (const key of Object.keys(result)) if (typeof value[key] === "boolean") result[key] = value[key];
|
|
34631
34986
|
}
|
|
34632
34987
|
if (!result.timestamps || !result.messageCounts) result.messageTimestamps = false;
|
|
@@ -34645,7 +35000,7 @@ function publishableGraph(sessions, settings, messages = /* @__PURE__ */ new Map
|
|
|
34645
35000
|
const ordered = [...sessions].sort((a, b) => a.created - b.created || a.id.localeCompare(b.id));
|
|
34646
35001
|
const ids = new Map(ordered.map((session, index) => [session.id, index]));
|
|
34647
35002
|
const groups = /* @__PURE__ */ new Map();
|
|
34648
|
-
|
|
35003
|
+
const graph = { version: 1, settings: fields2, sessions: ordered.map((session) => {
|
|
34649
35004
|
const key = laneKey(session);
|
|
34650
35005
|
if (!groups.has(key)) groups.set(key, groups.size);
|
|
34651
35006
|
const result = {
|
|
@@ -34654,18 +35009,34 @@ function publishableGraph(sessions, settings, messages = /* @__PURE__ */ new Map
|
|
|
34654
35009
|
parent: session.parentID ? ids.get(session.parentID) ?? null : null,
|
|
34655
35010
|
fork: session.forkID ? ids.get(session.forkID) ?? null : null
|
|
34656
35011
|
};
|
|
34657
|
-
if (fields2.timestamps) result.timestamps = { created: session.created, lastMessageAt: session.activity?.lastMessageAt
|
|
35012
|
+
if (fields2.timestamps) result.timestamps = { created: Math.trunc(session.created), lastMessageAt: session.activity?.lastMessageAt == null ? null : Math.trunc(session.activity.lastMessageAt) };
|
|
34658
35013
|
if (fields2.tokens) result.tokens = session.tokens;
|
|
34659
35014
|
const stats = messages.get(session.id);
|
|
34660
35015
|
if (fields2.messageCounts) result.messages = { count: stats?.count ?? null, untimed: stats?.untimed ?? null, partial: stats?.partial ?? true };
|
|
34661
|
-
if (fields2.messageTimestamps) result.messageTimes = { values:
|
|
35016
|
+
if (fields2.messageTimestamps) result.messageTimes = { values: [], limited: stats?.timesLimited ?? true };
|
|
34662
35017
|
if (fields2.model) result.model = publicModel(session.model);
|
|
34663
35018
|
if (fields2.harness) result.harness = isKnownSource(session.source) ? session.source : null;
|
|
34664
35019
|
return result;
|
|
34665
|
-
}) }
|
|
34666
|
-
|
|
34667
|
-
|
|
34668
|
-
|
|
35020
|
+
}) };
|
|
35021
|
+
if (fields2.messageTimestamps) {
|
|
35022
|
+
let bytes2 = PUBLIC_GRAPH_MAX_BYTES - new TextEncoder().encode(JSON.stringify(graph)).length;
|
|
35023
|
+
let remaining = PUBLIC_GRAPH_MAX_MESSAGE_TIMES;
|
|
35024
|
+
for (let index = 0; index < ordered.length; index++) {
|
|
35025
|
+
const times = messages.get(ordered[index].id)?.times ?? [], output2 = graph.sessions[index].messageTimes;
|
|
35026
|
+
for (const native of times) {
|
|
35027
|
+
const time4 = Math.trunc(native), size = String(time4).length + (output2.values.length ? 1 : 0);
|
|
35028
|
+
if (!remaining || output2.values.length === 2e3 || size > bytes2) break;
|
|
35029
|
+
output2.values.push(time4);
|
|
35030
|
+
bytes2 -= size;
|
|
35031
|
+
remaining--;
|
|
35032
|
+
}
|
|
35033
|
+
if (output2.values.length < times.length) output2.limited = true;
|
|
35034
|
+
}
|
|
35035
|
+
}
|
|
35036
|
+
return validatePublicGraph(graph);
|
|
35037
|
+
}
|
|
35038
|
+
var object3 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
35039
|
+
var exact = (value, keys) => object3(value) && Object.keys(value).length === keys.length && keys.every((key) => Object.hasOwn(value, key));
|
|
34669
35040
|
var integer = (value, max = Number.MAX_SAFE_INTEGER) => Number.isSafeInteger(value) && value >= 0 && value <= max;
|
|
34670
35041
|
var time3 = (value) => integer(value, Date.UTC(2100, 0, 1));
|
|
34671
35042
|
var nullableCount = (value) => value === null || integer(value);
|
|
@@ -34924,46 +35295,46 @@ async function sessionGraphMiddleware(req, res, next) {
|
|
|
34924
35295
|
res.setHeader("Content-Type", "application/json");
|
|
34925
35296
|
res.setHeader("Cache-Control", "no-store");
|
|
34926
35297
|
res.setHeader("X-Content-Type-Options", "nosniff");
|
|
34927
|
-
const
|
|
35298
|
+
const json5 = (status2, value) => {
|
|
34928
35299
|
if (!res.writableEnded) {
|
|
34929
35300
|
res.statusCode = status2;
|
|
34930
35301
|
res.end(JSON.stringify(value));
|
|
34931
35302
|
}
|
|
34932
35303
|
};
|
|
34933
|
-
if (req.headers["sec-fetch-site"] === "cross-site") return
|
|
35304
|
+
if (req.headers["sec-fetch-site"] === "cross-site") return json5(403, { error: "Cross-site requests are not allowed." });
|
|
34934
35305
|
if (req.headers.origin) {
|
|
34935
35306
|
try {
|
|
34936
|
-
if (new URL(req.headers.origin).host !== req.headers.host) return
|
|
35307
|
+
if (new URL(req.headers.origin).host !== req.headers.host) return json5(403, { error: "Origin mismatch." });
|
|
34937
35308
|
} catch {
|
|
34938
|
-
return
|
|
35309
|
+
return json5(403, { error: "Invalid origin." });
|
|
34939
35310
|
}
|
|
34940
35311
|
}
|
|
34941
|
-
if (req.method !== "GET" && typeof req.headers["x-sessiongraph-action"] !== "string") return
|
|
35312
|
+
if (req.method !== "GET" && typeof req.headers["x-sessiongraph-action"] !== "string") return json5(403, { error: "Use the SessionGraph application." });
|
|
34942
35313
|
try {
|
|
34943
35314
|
const { store, importer } = library();
|
|
34944
35315
|
if (url.pathname.startsWith("/api/sessiongraph/publishing")) {
|
|
34945
35316
|
const action = url.pathname.slice("/api/sessiongraph/publishing".length);
|
|
34946
|
-
if (action === "/settings" && req.method === "GET") return
|
|
34947
|
-
if (action === "/status" && req.method === "GET") return
|
|
34948
|
-
if (action === "/login" && req.method === "POST") return
|
|
34949
|
-
if (action === "/poll" && req.method === "POST") return
|
|
34950
|
-
if (action === "/logout" && req.method === "POST") return
|
|
35317
|
+
if (action === "/settings" && req.method === "GET") return json5(200, publishingSettings(store.setting("publishing")));
|
|
35318
|
+
if (action === "/status" && req.method === "GET") return json5(200, await publishing.status());
|
|
35319
|
+
if (action === "/login" && req.method === "POST") return json5(200, publishing.login());
|
|
35320
|
+
if (action === "/poll" && req.method === "POST") return json5(200, await publishing.poll());
|
|
35321
|
+
if (action === "/logout" && req.method === "POST") return json5(200, await publishing.logout());
|
|
34951
35322
|
if (action === "/preview" && req.method === "POST") {
|
|
34952
35323
|
const value = await body(req);
|
|
34953
|
-
return
|
|
35324
|
+
return json5(200, publishing.prepare(store, value?.ids, value?.settings));
|
|
34954
35325
|
}
|
|
34955
35326
|
if (action === "/publish" && req.method === "POST") {
|
|
34956
35327
|
const value = await body(req);
|
|
34957
|
-
return
|
|
35328
|
+
return json5(200, await publishing.publish(value?.id, value?.confirmed));
|
|
34958
35329
|
}
|
|
34959
|
-
if (action === "/unpublish" && req.method === "POST") return
|
|
34960
|
-
return
|
|
35330
|
+
if (action === "/unpublish" && req.method === "POST") return json5(200, await publishing.unpublish());
|
|
35331
|
+
return json5(405, { error: "Method not allowed." });
|
|
34961
35332
|
}
|
|
34962
35333
|
if (url.pathname === "/api/sessiongraph/settings" && req.method === "POST") {
|
|
34963
35334
|
const value = await body(req);
|
|
34964
|
-
if (!value || typeof value !== "object" || Array.isArray(value) || !["autoImport", "preferences", "viewState"].some((key) => value[key] !== void 0)) return
|
|
34965
|
-
if (value.autoImport !== void 0 && typeof value.autoImport !== "boolean") return
|
|
34966
|
-
for (const key of ["preferences", "viewState"]) if (value[key] !== void 0 && (!value[key] || typeof value[key] !== "object" || Array.isArray(value[key]))) return
|
|
35335
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || !["autoImport", "preferences", "viewState"].some((key) => value[key] !== void 0)) return json5(400, { error: "Choose valid settings." });
|
|
35336
|
+
if (value.autoImport !== void 0 && typeof value.autoImport !== "boolean") return json5(400, { error: "Choose a valid auto-import setting." });
|
|
35337
|
+
for (const key of ["preferences", "viewState"]) if (value[key] !== void 0 && (!value[key] || typeof value[key] !== "object" || Array.isArray(value[key]))) return json5(400, { error: "Choose valid view preferences." });
|
|
34967
35338
|
store.db.exec("BEGIN IMMEDIATE");
|
|
34968
35339
|
try {
|
|
34969
35340
|
if (value.autoImport !== void 0) store.setting("autoImport", value.autoImport);
|
|
@@ -34974,69 +35345,71 @@ async function sessionGraphMiddleware(req, res, next) {
|
|
|
34974
35345
|
store.db.exec("ROLLBACK");
|
|
34975
35346
|
throw error;
|
|
34976
35347
|
}
|
|
34977
|
-
return
|
|
35348
|
+
return json5(200, { saved: true, autoImport: store.autoImportEnabled() });
|
|
34978
35349
|
}
|
|
34979
|
-
if (url.pathname === "/api/sessiongraph/sources" && req.method === "GET") return
|
|
35350
|
+
if (url.pathname === "/api/sessiongraph/sources" && req.method === "GET") return json5(200, { sources: await importer.sources(), onboarding: store.setting("selected") === void 0 });
|
|
34980
35351
|
if (url.pathname === "/api/sessiongraph/import") {
|
|
34981
|
-
if (req.method === "GET") return
|
|
35352
|
+
if (req.method === "GET") return json5(200, importer.status);
|
|
34982
35353
|
if (req.method === "POST") {
|
|
34983
35354
|
const value = await body(req);
|
|
34984
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return
|
|
34985
|
-
if (value.sources !== void 0 && (!Array.isArray(value.sources) || value.sources.some((s) => typeof s !== "string"))) return
|
|
34986
|
-
if (value.automatic !== void 0 && (typeof value.automatic !== "boolean" || value.sources !== void 0)) return
|
|
34987
|
-
if (importer.status.running) return
|
|
34988
|
-
return
|
|
35355
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return json5(400, { error: "Invalid import request." });
|
|
35356
|
+
if (value.sources !== void 0 && (!Array.isArray(value.sources) || value.sources.some((s) => typeof s !== "string"))) return json5(400, { error: "Choose valid sources." });
|
|
35357
|
+
if (value.automatic !== void 0 && (typeof value.automatic !== "boolean" || value.sources !== void 0)) return json5(400, { error: "Automatic imports use saved sources." });
|
|
35358
|
+
if (importer.status.running) return json5(409, { error: "An import is already running." });
|
|
35359
|
+
return json5(202, importer.start(value.sources, value.automatic));
|
|
34989
35360
|
}
|
|
34990
35361
|
}
|
|
34991
35362
|
if (url.pathname === "/api/sessiongraph/index") {
|
|
34992
|
-
if (req.method === "GET") return
|
|
35363
|
+
if (req.method === "GET") return json5(200, store.checkpoints(url.searchParams.get("after") || ""));
|
|
34993
35364
|
if (req.method === "POST") {
|
|
34994
35365
|
const value = await body(req);
|
|
34995
|
-
return value.record && store.saveCheckpoint(value.record, value.epoch) ?
|
|
35366
|
+
return value.record && store.saveCheckpoint(value.record, value.epoch) ? json5(200, { saved: true }) : json5(409, { error: "Index snapshot is stale." });
|
|
34996
35367
|
}
|
|
34997
35368
|
if (req.method === "DELETE") {
|
|
34998
35369
|
store.clearIndex();
|
|
34999
|
-
return
|
|
35370
|
+
return json5(200, { cleared: true });
|
|
35000
35371
|
}
|
|
35001
35372
|
}
|
|
35002
35373
|
if (url.pathname === "/api/sessiongraph" && req.method === "GET") {
|
|
35003
35374
|
const sources2 = adapters.map((a) => ({ id: a.id, name: a.name, description: a.description, capabilities: a.capabilities, selected: store.selected().includes(a.id), available: false, ...store.sourceInfo(a.id) }));
|
|
35004
|
-
return
|
|
35375
|
+
return json5(200, store.library(sources2, importer.status.running));
|
|
35005
35376
|
}
|
|
35006
|
-
const match2 = /^\/api\/sessiongraph\/session\/([^/]+)(?:\/(content|timeline|events|event-markers|connection|prepare-launch|open-terminal))?$/.exec(url.pathname);
|
|
35377
|
+
const match2 = /^\/api\/sessiongraph\/session\/([^/]+)(?:\/(content|timeline|commits|events|event-markers|connection|prepare-launch|open-terminal))?$/.exec(url.pathname);
|
|
35007
35378
|
if (match2) {
|
|
35008
35379
|
const id2 = decodeURIComponent(match2[1]);
|
|
35009
35380
|
const session = store.getSession(id2);
|
|
35010
|
-
if (!session) return
|
|
35381
|
+
if (!session) return json5(404, { error: "Session not imported." });
|
|
35011
35382
|
if (["prepare-launch", "open-terminal"].includes(match2[2]) && req.method === "POST") {
|
|
35012
35383
|
const value = await body(req);
|
|
35013
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return
|
|
35384
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return json5(400, { error: "Invalid launch request." });
|
|
35014
35385
|
const target = value.target ?? session.source ?? "opencode";
|
|
35015
|
-
if (!isHarness(target)) return
|
|
35386
|
+
if (!isHarness(target)) return json5(400, { error: "Choose a supported destination app." });
|
|
35016
35387
|
try {
|
|
35017
35388
|
const prepared = await prepareLaunch(store, session, target, value.directory);
|
|
35018
35389
|
if (match2[2] === "open-terminal") await launchTerminal(session, prepared);
|
|
35019
|
-
return
|
|
35390
|
+
return json5(200, prepared);
|
|
35020
35391
|
} catch (error) {
|
|
35021
|
-
return
|
|
35392
|
+
return json5(400, { error: error instanceof Error ? error.message : "Could not prepare this session." });
|
|
35022
35393
|
}
|
|
35023
35394
|
}
|
|
35024
|
-
if (req.method !== "GET") return
|
|
35025
|
-
if (["prepare-launch", "open-terminal"].includes(match2[2])) return
|
|
35026
|
-
if (match2[2] === "timeline") return
|
|
35027
|
-
if (match2[2] === "
|
|
35028
|
-
if (match2[2] === "
|
|
35029
|
-
if (match2[2] === "
|
|
35395
|
+
if (req.method !== "GET") return json5(405, { error: "Method not allowed." });
|
|
35396
|
+
if (["prepare-launch", "open-terminal"].includes(match2[2])) return json5(405, { error: "Method not allowed." });
|
|
35397
|
+
if (match2[2] === "timeline") return json5(200, store.timeline(id2));
|
|
35398
|
+
if (match2[2] === "commits") return json5(200, store.commits(id2, { cursor: url.searchParams.get("cursor") || void 0, limit: url.searchParams.has("limit") ? Number(url.searchParams.get("limit")) : void 0 }));
|
|
35399
|
+
if (match2[2] === "event-markers") return json5(200, store.eventMarkers(id2));
|
|
35400
|
+
if (match2[2] === "events") return json5(200, store.events(id2, Object.fromEntries(["cursor", "item", "filter", "revision"].flatMap((key) => url.searchParams.has(key) ? [[key, url.searchParams.get(key)]] : []))));
|
|
35401
|
+
if (match2[2] === "connection") return json5(200, await getLaunchConnection(session));
|
|
35030
35402
|
const cursor = url.searchParams.get("cursor") || void 0;
|
|
35031
|
-
if (cursor && (!/^\d{1,9}$/.test(cursor) || Number(cursor) > 5e4)) return
|
|
35032
|
-
return
|
|
35403
|
+
if (cursor && (!/^\d{1,9}$/.test(cursor) || Number(cursor) > 5e4)) return json5(400, { error: "Invalid cursor." });
|
|
35404
|
+
return json5(200, match2[2] === "content" ? store.content(id2, cursor) : store.detail(id2, cursor));
|
|
35033
35405
|
}
|
|
35034
|
-
return
|
|
35406
|
+
return json5(404, { error: "Not found." });
|
|
35035
35407
|
} catch (error) {
|
|
35036
|
-
if (error instanceof PublishingError) return
|
|
35037
|
-
if (error instanceof EventReadError) return
|
|
35408
|
+
if (error instanceof PublishingError) return json5(error.status, { error: error.message });
|
|
35409
|
+
if (error instanceof EventReadError) return json5(error.status, { error: error.message });
|
|
35410
|
+
if (error instanceof LibraryError) return json5(error.code === "STALE_CURSOR" ? 409 : 400, { error: error.message });
|
|
35038
35411
|
console.error("[sessiongraph] Local operation failed:", error instanceof Error ? error.name : "Unknown error");
|
|
35039
|
-
return
|
|
35412
|
+
return json5(500, { error: "Local operation failed. Check the import status or retry." });
|
|
35040
35413
|
}
|
|
35041
35414
|
}
|
|
35042
35415
|
|