sessiongraph-app-darwin-arm64 1.0.17 → 1.0.19
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.app/Contents/Info.plist +2 -2
- package/payload/SessionGraph.app/Contents/MacOS/sessiongraph +0 -0
- package/payload/SessionGraph.app/Contents/Resources/resources/cli-package.json +1 -1
- package/payload/SessionGraph.app/Contents/Resources/resources/cli.mjs +1073 -1265
- package/payload/SessionGraph.app/Contents/Resources/resources/server.mjs +1050 -880
- package/payload/SessionGraph.app/Contents/Resources/resources/web/assets/{index-BcuycrLl.js → index--OQ4NiAJ.js} +1 -1
- package/payload/SessionGraph.app/Contents/Resources/resources/web/assets/{index-Dm6VCxBu.js → index-DCSeQKMi.js} +5 -5
- package/payload/SessionGraph.app/Contents/Resources/resources/web/assets/{index-CxNvtrVy.js → index-DZcMVUpG.js} +1 -1
- package/payload/SessionGraph.app/Contents/Resources/resources/web/assets/{index-DHztibvv.js → index-ZwvTaIqn.js} +1 -1
- package/payload/SessionGraph.app/Contents/Resources/resources/web/assets/{public-viewer-B3t-LR4T.js → public-viewer-DVqMq2gi.js} +1 -1
- package/payload/SessionGraph.app/Contents/Resources/resources/web/assets/{scene-CnihjOu5.js → scene-B94ITHcm.js} +1 -1
- package/payload/SessionGraph.app/Contents/Resources/resources/web/assets/{share-BWJVjZdG.js → share-DnZuWOzh.js} +3 -3
- package/payload/SessionGraph.app/Contents/Resources/resources/web/index.html +1 -1
- package/payload/SessionGraph.app/Contents/_CodeSignature/CodeResources +44 -44
|
@@ -55,11 +55,9 @@ function databasePath(env2 = process.env, platform = process.platform, home = ho
|
|
|
55
55
|
];
|
|
56
56
|
return paths2.find((path) => existsSync(path)) || paths2[0];
|
|
57
57
|
}
|
|
58
|
-
var serviceFile;
|
|
59
58
|
var init_config = __esm({
|
|
60
59
|
"server/config.ts"() {
|
|
61
60
|
"use strict";
|
|
62
|
-
serviceFile = (env2 = process.env) => env2.SESSIONGRAPH_SERVICE_FILE || env2.SESSION_ATLAS_SERVICE_FILE || env2.ATLAS_SERVICE_FILE;
|
|
63
61
|
}
|
|
64
62
|
});
|
|
65
63
|
|
|
@@ -1153,7 +1151,7 @@ function withSourcePaths(adapter, configured) {
|
|
|
1153
1151
|
}
|
|
1154
1152
|
function sourcePathHint(id3) {
|
|
1155
1153
|
const hints = {
|
|
1156
|
-
opencode: "
|
|
1154
|
+
opencode: "OpenCode data directory or SQLite file (normally ~/.local/share/opencode/opencode.db). Supports V1 and V2 offline.",
|
|
1157
1155
|
"claude-code": "Claude home containing projects/ and transcripts/ (normally ~/.claude).",
|
|
1158
1156
|
codex: "Codex home containing sessions/ and archived_sessions/ (normally ~/.codex).",
|
|
1159
1157
|
"t3-code": "T3 home containing its local server history (normally ~/.t3).",
|
|
@@ -17404,7 +17402,7 @@ function toJSONSchema(input2, params) {
|
|
|
17404
17402
|
const [_, schema] = entry;
|
|
17405
17403
|
processSchema(schema, ctx2);
|
|
17406
17404
|
}
|
|
17407
|
-
const
|
|
17405
|
+
const schemas2 = {};
|
|
17408
17406
|
const external = {
|
|
17409
17407
|
registry: registry2,
|
|
17410
17408
|
uri: params?.uri,
|
|
@@ -17414,15 +17412,15 @@ function toJSONSchema(input2, params) {
|
|
|
17414
17412
|
for (const entry of registry2._idmap.entries()) {
|
|
17415
17413
|
const [key, schema] = entry;
|
|
17416
17414
|
extractDefs(ctx2, schema);
|
|
17417
|
-
assignProp(
|
|
17415
|
+
assignProp(schemas2, key, finalize(ctx2, schema));
|
|
17418
17416
|
}
|
|
17419
17417
|
if (Object.keys(defs).length > 0) {
|
|
17420
17418
|
const defsSegment = ctx2.target === "draft-2020-12" ? "$defs" : "definitions";
|
|
17421
|
-
|
|
17419
|
+
schemas2.__shared = {
|
|
17422
17420
|
[defsSegment]: defs
|
|
17423
17421
|
};
|
|
17424
17422
|
}
|
|
17425
|
-
return { schemas };
|
|
17423
|
+
return { schemas: schemas2 };
|
|
17426
17424
|
}
|
|
17427
17425
|
const ctx = initializeContext({ ...params, processors: allProcessors });
|
|
17428
17426
|
processSchema(input2, ctx);
|
|
@@ -17887,13 +17885,13 @@ var init_json_schema_processors = __esm({
|
|
|
17887
17885
|
...params,
|
|
17888
17886
|
path: [...params.path, "propertyNames"]
|
|
17889
17887
|
});
|
|
17890
|
-
let
|
|
17891
|
-
if (!
|
|
17892
|
-
|
|
17893
|
-
pendingRecords.set(ctx,
|
|
17888
|
+
let pending = pendingRecords.get(ctx);
|
|
17889
|
+
if (!pending) {
|
|
17890
|
+
pending = [];
|
|
17891
|
+
pendingRecords.set(ctx, pending);
|
|
17894
17892
|
ctx.deferred.push(() => rewriteKeyNames(ctx));
|
|
17895
17893
|
}
|
|
17896
|
-
|
|
17894
|
+
pending.push(schema);
|
|
17897
17895
|
}
|
|
17898
17896
|
json6.additionalProperties = processSchema(def.valueType, ctx, {
|
|
17899
17897
|
...params,
|
|
@@ -21055,21 +21053,21 @@ function visit(schema, fnOrHandlers) {
|
|
|
21055
21053
|
const h3 = fnOrHandlers[node2._zod.def.type];
|
|
21056
21054
|
return h3 ? h3(node2, rewritten) : node2;
|
|
21057
21055
|
};
|
|
21058
|
-
const
|
|
21056
|
+
const cache2 = /* @__PURE__ */ new Map();
|
|
21059
21057
|
function run(s) {
|
|
21060
|
-
const cached3 =
|
|
21058
|
+
const cached3 = cache2.get(s);
|
|
21061
21059
|
if (cached3 === RESOLVING) {
|
|
21062
21060
|
return new $ZodLazy({
|
|
21063
21061
|
type: "lazy",
|
|
21064
|
-
getter: () =>
|
|
21062
|
+
getter: () => cache2.get(s)
|
|
21065
21063
|
});
|
|
21066
21064
|
}
|
|
21067
21065
|
if (cached3 !== void 0)
|
|
21068
21066
|
return cached3;
|
|
21069
|
-
|
|
21067
|
+
cache2.set(s, RESOLVING);
|
|
21070
21068
|
const inner = mapInner(s);
|
|
21071
21069
|
const mapped = fn(inner, inner !== s);
|
|
21072
|
-
|
|
21070
|
+
cache2.set(s, mapped);
|
|
21073
21071
|
return mapped;
|
|
21074
21072
|
}
|
|
21075
21073
|
function mapInner(s) {
|
|
@@ -21742,18 +21740,18 @@ async function startAgentHttp(library, port, credential, version2) {
|
|
|
21742
21740
|
if (!Number.isInteger(port) || port < 0 || port > 65535) invalid("Port must be 0\u201365535.");
|
|
21743
21741
|
const server = createServer(async (req, res) => {
|
|
21744
21742
|
const authority = `127.0.0.1:${server.address().port}`;
|
|
21745
|
-
const
|
|
21743
|
+
const fail = (status2, code, message2) => send(res, status2, { schemaVersion: 1, error: { code, message: message2 } });
|
|
21746
21744
|
if (req.headers.host !== authority || req.headers.origin !== void 0 && req.headers.origin !== `http://${authority}`) {
|
|
21747
|
-
return
|
|
21745
|
+
return fail(403, "FORBIDDEN", "Invalid host or origin.");
|
|
21748
21746
|
}
|
|
21749
21747
|
const basic = /^Basic ([A-Za-z0-9+/=]+)$/i.exec(req.headers.authorization || "");
|
|
21750
21748
|
if (!basic || !timingSafeEqual(credential, digest2(basic[1]))) {
|
|
21751
21749
|
res.setHeader("WWW-Authenticate", 'Basic realm="SessionGraph", charset="UTF-8"');
|
|
21752
|
-
return
|
|
21750
|
+
return fail(401, "UNAUTHORIZED", "Credentials required.");
|
|
21753
21751
|
}
|
|
21754
21752
|
if (req.method !== "GET") {
|
|
21755
21753
|
res.setHeader("Allow", "GET");
|
|
21756
|
-
return
|
|
21754
|
+
return fail(405, "METHOD_NOT_ALLOWED", "Use GET.");
|
|
21757
21755
|
}
|
|
21758
21756
|
try {
|
|
21759
21757
|
const url2 = new URL(req.url || "/", `http://${authority}`);
|
|
@@ -21776,10 +21774,10 @@ async function startAgentHttp(library, port, credential, version2) {
|
|
|
21776
21774
|
}
|
|
21777
21775
|
return send(res, 200, { schemaVersion: 1, data: await q4.call(library, args) });
|
|
21778
21776
|
}
|
|
21779
|
-
return
|
|
21777
|
+
return fail(404, "NOT_FOUND", "Unknown endpoint.");
|
|
21780
21778
|
} catch (error62) {
|
|
21781
21779
|
const e10 = queryError(error62);
|
|
21782
|
-
return
|
|
21780
|
+
return fail(e10.status, e10.code, e10.message);
|
|
21783
21781
|
}
|
|
21784
21782
|
});
|
|
21785
21783
|
await new Promise((resolve3, reject) => {
|
|
@@ -21804,105 +21802,6 @@ var init_agent_http = __esm({
|
|
|
21804
21802
|
});
|
|
21805
21803
|
|
|
21806
21804
|
// node_modules/.pnpm/@opencode+client@2.2.1_effect@4.0.1/node_modules/@opencode/client/dist/chunks/mcp-ve4aws36.js
|
|
21807
|
-
import { spawn } from "node:child_process";
|
|
21808
|
-
function spawnServiceContender2(command, args, env2) {
|
|
21809
|
-
const child = spawn(command, args, {
|
|
21810
|
-
detached: true,
|
|
21811
|
-
windowsHide: true,
|
|
21812
|
-
stdio: ["ignore", "ignore", "pipe"],
|
|
21813
|
-
env: { ...process.env, ...env2 }
|
|
21814
|
-
});
|
|
21815
|
-
let error62;
|
|
21816
|
-
let closed = false;
|
|
21817
|
-
let stderr = Buffer.alloc(0);
|
|
21818
|
-
const onStderr = (chunk) => {
|
|
21819
|
-
const tail = chunk.subarray(-stderrLimit);
|
|
21820
|
-
stderr = tail.length === stderrLimit ? Buffer.from(tail) : Buffer.concat([stderr.subarray(-(stderrLimit - tail.length)), tail]);
|
|
21821
|
-
};
|
|
21822
|
-
child.stderr?.on("data", onStderr);
|
|
21823
|
-
if (child.stderr !== null && "unref" in child.stderr && typeof child.stderr.unref === "function")
|
|
21824
|
-
child.stderr.unref();
|
|
21825
|
-
child.once("error", (cause) => {
|
|
21826
|
-
error62 = new Error("Failed to start server", { cause });
|
|
21827
|
-
});
|
|
21828
|
-
child.once("close", () => {
|
|
21829
|
-
closed = true;
|
|
21830
|
-
});
|
|
21831
|
-
child.unref();
|
|
21832
|
-
return {
|
|
21833
|
-
child,
|
|
21834
|
-
error: () => error62,
|
|
21835
|
-
closed: () => closed,
|
|
21836
|
-
stderr: () => stderr.toString("utf8").trim(),
|
|
21837
|
-
release: () => {
|
|
21838
|
-
child.stderr?.off("data", onStderr);
|
|
21839
|
-
child.stderr?.resume();
|
|
21840
|
-
stderr = Buffer.alloc(0);
|
|
21841
|
-
}
|
|
21842
|
-
};
|
|
21843
|
-
}
|
|
21844
|
-
function contenderPool2(timing) {
|
|
21845
|
-
const contenders = /* @__PURE__ */ new Set();
|
|
21846
|
-
let failure2;
|
|
21847
|
-
let spawnDelay = timing.spawnDelay;
|
|
21848
|
-
let lastSpawn = 0;
|
|
21849
|
-
return {
|
|
21850
|
-
failure: () => failure2,
|
|
21851
|
-
serviceAnswered() {
|
|
21852
|
-
spawnDelay = timing.spawnDelay;
|
|
21853
|
-
},
|
|
21854
|
-
evict(pid) {
|
|
21855
|
-
for (const item of contenders) {
|
|
21856
|
-
if (item.child.pid === pid || contenderFinished2(item)) {
|
|
21857
|
-
item.release();
|
|
21858
|
-
contenders.delete(item);
|
|
21859
|
-
}
|
|
21860
|
-
}
|
|
21861
|
-
failure2 = void 0;
|
|
21862
|
-
lastSpawn = 0;
|
|
21863
|
-
},
|
|
21864
|
-
recruitNow() {
|
|
21865
|
-
lastSpawn = Date.now() - spawnDelay;
|
|
21866
|
-
},
|
|
21867
|
-
reap() {
|
|
21868
|
-
const finished = [...contenders].filter(contenderFinished2);
|
|
21869
|
-
failure2 ??= finished.map(contenderFailure).find((error62) => error62 !== void 0);
|
|
21870
|
-
if (finished.some((item) => item.child.exitCode === 0))
|
|
21871
|
-
spawnDelay = Math.min(spawnDelay * 2, timing.maxSpawnDelay);
|
|
21872
|
-
finished.forEach((item) => contenders.delete(item));
|
|
21873
|
-
return contenders.size === 0 ? failure2 : void 0;
|
|
21874
|
-
},
|
|
21875
|
-
shouldRecruit(registered2) {
|
|
21876
|
-
if (lastSpawn === 0 && registered2)
|
|
21877
|
-
lastSpawn = Date.now();
|
|
21878
|
-
return failure2 === void 0 && contenders.size < 2 && Date.now() - lastSpawn >= spawnDelay;
|
|
21879
|
-
},
|
|
21880
|
-
add(contender) {
|
|
21881
|
-
contenders.add(contender);
|
|
21882
|
-
lastSpawn = Date.now();
|
|
21883
|
-
},
|
|
21884
|
-
releaseAll() {
|
|
21885
|
-
contenders.forEach((contender) => contender.release());
|
|
21886
|
-
}
|
|
21887
|
-
};
|
|
21888
|
-
}
|
|
21889
|
-
function contenderFailure(contender) {
|
|
21890
|
-
const error62 = contender.error();
|
|
21891
|
-
if (error62 !== void 0)
|
|
21892
|
-
return error62;
|
|
21893
|
-
if (contender.child.exitCode !== null && contender.child.exitCode !== 0)
|
|
21894
|
-
return startupError(`Server process exited with code ${contender.child.exitCode}`, contender.stderr());
|
|
21895
|
-
if (contender.child.signalCode !== null)
|
|
21896
|
-
return startupError(`Server process terminated by ${contender.child.signalCode}`, contender.stderr());
|
|
21897
|
-
return;
|
|
21898
|
-
}
|
|
21899
|
-
function contenderFinished2(contender) {
|
|
21900
|
-
return contender.error() !== void 0 || contender.closed();
|
|
21901
|
-
}
|
|
21902
|
-
function startupError(message2, stderr) {
|
|
21903
|
-
return new Error(stderr ? `${message2}
|
|
21904
|
-
${stderr}` : message2);
|
|
21905
|
-
}
|
|
21906
21805
|
var stderrLimit;
|
|
21907
21806
|
var init_mcp_ve4aws36 = __esm({
|
|
21908
21807
|
"node_modules/.pnpm/@opencode+client@2.2.1_effect@4.0.1/node_modules/@opencode/client/dist/chunks/mcp-ve4aws36.js"() {
|
|
@@ -21911,107 +21810,18 @@ var init_mcp_ve4aws36 = __esm({
|
|
|
21911
21810
|
});
|
|
21912
21811
|
|
|
21913
21812
|
// node_modules/.pnpm/@opencode+client@2.2.1_effect@4.0.1/node_modules/@opencode/client/dist/chunks/mcp-xgnj2w4v.js
|
|
21914
|
-
function ensureTiming2(options) {
|
|
21915
|
-
return timings.get(options) ?? defaultEnsureTiming2;
|
|
21916
|
-
}
|
|
21917
|
-
var timings, defaultEnsureTiming2;
|
|
21918
21813
|
var init_mcp_xgnj2w4v = __esm({
|
|
21919
21814
|
"node_modules/.pnpm/@opencode+client@2.2.1_effect@4.0.1/node_modules/@opencode/client/dist/chunks/mcp-xgnj2w4v.js"() {
|
|
21920
|
-
timings = /* @__PURE__ */ new WeakMap();
|
|
21921
|
-
defaultEnsureTiming2 = {
|
|
21922
|
-
pollInterval: 25,
|
|
21923
|
-
requestTimeout: 2e3,
|
|
21924
|
-
spawnDelay: 5e3,
|
|
21925
|
-
maxSpawnDelay: 3e4,
|
|
21926
|
-
promiseTimeout: 12e4,
|
|
21927
|
-
stopPollInterval: 50,
|
|
21928
|
-
stopPollAttempts: 100
|
|
21929
|
-
};
|
|
21930
21815
|
}
|
|
21931
21816
|
});
|
|
21932
21817
|
|
|
21933
21818
|
// node_modules/.pnpm/@opencode+client@2.2.1_effect@4.0.1/node_modules/@opencode/client/dist/chunks/mcp-sxt88q69.js
|
|
21934
|
-
function matchesVersion2(version2, options) {
|
|
21935
|
-
if (options.version === void 0)
|
|
21936
|
-
return true;
|
|
21937
|
-
if (version2 === void 0)
|
|
21938
|
-
return false;
|
|
21939
|
-
if (typeof options.version === "function")
|
|
21940
|
-
return options.version(version2);
|
|
21941
|
-
return version2 === options.version;
|
|
21942
|
-
}
|
|
21943
21819
|
var init_mcp_sxt88q69 = __esm({
|
|
21944
21820
|
"node_modules/.pnpm/@opencode+client@2.2.1_effect@4.0.1/node_modules/@opencode/client/dist/chunks/mcp-sxt88q69.js"() {
|
|
21945
21821
|
}
|
|
21946
21822
|
});
|
|
21947
21823
|
|
|
21948
21824
|
// node_modules/.pnpm/@opencode+client@2.2.1_effect@4.0.1/node_modules/@opencode/client/dist/chunks/mcp-8ye1ye6f.js
|
|
21949
|
-
import { homedir as homedir3 } from "node:os";
|
|
21950
|
-
import { join as join2 } from "node:path";
|
|
21951
|
-
function decide2(service, options) {
|
|
21952
|
-
if (!matchesVersion2(service.version, options))
|
|
21953
|
-
return { _tag: "replace", pty: service.state === "ready" ? "handoff" : "clear" };
|
|
21954
|
-
if (!service.compatible)
|
|
21955
|
-
return fail("Background service uses an incompatible health protocol. Update this client or explicitly restart the service.");
|
|
21956
|
-
if (service.state === "ready")
|
|
21957
|
-
return { _tag: "reuse" };
|
|
21958
|
-
if (service.state === "failed")
|
|
21959
|
-
return fail("Background service failed to start");
|
|
21960
|
-
return { _tag: "wait" };
|
|
21961
|
-
}
|
|
21962
|
-
function fail(message2) {
|
|
21963
|
-
return { _tag: "fail", error: new Error(message2) };
|
|
21964
|
-
}
|
|
21965
|
-
function fallback2() {
|
|
21966
|
-
return join2(process.env["XDG_STATE_HOME"] ?? join2(homedir3(), ".local", "state"), "opencode", "service.json");
|
|
21967
|
-
}
|
|
21968
|
-
function same2(left, right) {
|
|
21969
|
-
return left.id === right.id && left.version === right.version && left.url === right.url && left.pid === right.pid;
|
|
21970
|
-
}
|
|
21971
|
-
async function probeResult2(info, timeout = defaultEnsureTiming2.requestTimeout) {
|
|
21972
|
-
const endpoint = {
|
|
21973
|
-
url: info.url,
|
|
21974
|
-
auth: info.password === void 0 ? void 0 : { type: "basic", username: "opencode", password: info.password }
|
|
21975
|
-
};
|
|
21976
|
-
const signal2 = AbortSignal.timeout(timeout);
|
|
21977
|
-
const result = await fetch(new URL("/api/info", info.url), { headers: headers2(endpoint), signal: signal2 }).then(async (response2) => ({
|
|
21978
|
-
response: response2,
|
|
21979
|
-
body: response2.status === 404 ? void 0 : await response2.json()
|
|
21980
|
-
})).catch(() => {
|
|
21981
|
-
return;
|
|
21982
|
-
});
|
|
21983
|
-
if (result === void 0)
|
|
21984
|
-
return { service: void 0, timedOut: signal2.aborted };
|
|
21985
|
-
const response = result.response;
|
|
21986
|
-
if (response.status === 404)
|
|
21987
|
-
return {
|
|
21988
|
-
service: {
|
|
21989
|
-
info,
|
|
21990
|
-
endpoint,
|
|
21991
|
-
version: info.version,
|
|
21992
|
-
state: "ready",
|
|
21993
|
-
compatible: false
|
|
21994
|
-
},
|
|
21995
|
-
timedOut: false
|
|
21996
|
-
};
|
|
21997
|
-
const serverInfo = decodeInfo(result.body);
|
|
21998
|
-
if (serverInfo === void 0)
|
|
21999
|
-
return { service: void 0, timedOut: false };
|
|
22000
|
-
if (serverInfo.pid !== info.pid)
|
|
22001
|
-
return { service: void 0, timedOut: false };
|
|
22002
|
-
if (info.version !== void 0 && serverInfo.version !== info.version)
|
|
22003
|
-
return { service: void 0, timedOut: false };
|
|
22004
|
-
return {
|
|
22005
|
-
service: {
|
|
22006
|
-
info,
|
|
22007
|
-
endpoint,
|
|
22008
|
-
version: serverInfo.version,
|
|
22009
|
-
state: response.ok ? "ready" : response.status === 500 ? "failed" : "waiting",
|
|
22010
|
-
compatible: true
|
|
22011
|
-
},
|
|
22012
|
-
timedOut: false
|
|
22013
|
-
};
|
|
22014
|
-
}
|
|
22015
21825
|
function headers2(endpoint) {
|
|
22016
21826
|
if (endpoint.auth === void 0)
|
|
22017
21827
|
return;
|
|
@@ -22019,15 +21829,6 @@ function headers2(endpoint) {
|
|
|
22019
21829
|
authorization: "Basic " + Buffer.from(endpoint.auth.username + ":" + endpoint.auth.password).toString("base64")
|
|
22020
21830
|
};
|
|
22021
21831
|
}
|
|
22022
|
-
function decodeInfo(input2) {
|
|
22023
|
-
if (typeof input2 !== "object" || input2 === null)
|
|
22024
|
-
return;
|
|
22025
|
-
if (!("version" in input2) || typeof input2.version !== "string")
|
|
22026
|
-
return;
|
|
22027
|
-
if (!("pid" in input2) || typeof input2.pid !== "number" || !Number.isInteger(input2.pid) || input2.pid < 0)
|
|
22028
|
-
return;
|
|
22029
|
-
return { version: input2.version, pid: input2.pid };
|
|
22030
|
-
}
|
|
22031
21832
|
var init_mcp_8ye1ye6f = __esm({
|
|
22032
21833
|
"node_modules/.pnpm/@opencode+client@2.2.1_effect@4.0.1/node_modules/@opencode/client/dist/chunks/mcp-8ye1ye6f.js"() {
|
|
22033
21834
|
init_mcp_xgnj2w4v();
|
|
@@ -22060,7 +21861,7 @@ var init_mcp_9rqn6x4v = __esm({
|
|
|
22060
21861
|
function make7(connect) {
|
|
22061
21862
|
let current;
|
|
22062
21863
|
const capacity = 4096;
|
|
22063
|
-
function
|
|
21864
|
+
function stop(connection) {
|
|
22064
21865
|
connection.connected = void 0;
|
|
22065
21866
|
connection.controller.abort();
|
|
22066
21867
|
if (current === connection)
|
|
@@ -22086,7 +21887,7 @@ function make7(connect) {
|
|
|
22086
21887
|
} catch (error62) {
|
|
22087
21888
|
completion = { error: error62 };
|
|
22088
21889
|
} finally {
|
|
22089
|
-
|
|
21890
|
+
stop(connection);
|
|
22090
21891
|
try {
|
|
22091
21892
|
await iterator?.return?.();
|
|
22092
21893
|
} catch (error62) {
|
|
@@ -22100,7 +21901,7 @@ function make7(connect) {
|
|
|
22100
21901
|
subscribe(options) {
|
|
22101
21902
|
return {
|
|
22102
21903
|
[Symbol.asyncIterator]() {
|
|
22103
|
-
const
|
|
21904
|
+
const pending = [];
|
|
22104
21905
|
const queued = [];
|
|
22105
21906
|
let started = false;
|
|
22106
21907
|
let completion;
|
|
@@ -22113,8 +21914,8 @@ function make7(connect) {
|
|
|
22113
21914
|
queued.length = 0;
|
|
22114
21915
|
options?.signal?.removeEventListener("abort", abort);
|
|
22115
21916
|
if (connection?.subscribers.delete(subscriber) && !connection.subscribers.size)
|
|
22116
|
-
|
|
22117
|
-
|
|
21917
|
+
stop(connection);
|
|
21918
|
+
pending.splice(0).forEach((request) => {
|
|
22118
21919
|
if ("error" in result)
|
|
22119
21920
|
request.reject(result.error);
|
|
22120
21921
|
else
|
|
@@ -22134,7 +21935,7 @@ function make7(connect) {
|
|
|
22134
21935
|
return;
|
|
22135
21936
|
if (!selected(value))
|
|
22136
21937
|
return;
|
|
22137
|
-
const request =
|
|
21938
|
+
const request = pending.shift();
|
|
22138
21939
|
if (request) {
|
|
22139
21940
|
request.resolve({ done: false, value });
|
|
22140
21941
|
return;
|
|
@@ -22176,7 +21977,7 @@ function make7(connect) {
|
|
|
22176
21977
|
return Promise.resolve({ done: true, value: void 0 });
|
|
22177
21978
|
}
|
|
22178
21979
|
const request = Promise.withResolvers();
|
|
22179
|
-
|
|
21980
|
+
pending.push(request);
|
|
22180
21981
|
if (!started) {
|
|
22181
21982
|
started = true;
|
|
22182
21983
|
options?.signal?.addEventListener("abort", abort, { once: true });
|
|
@@ -24004,18 +23805,18 @@ function makeRpc2(raw, events) {
|
|
|
24004
23805
|
return {
|
|
24005
23806
|
[Symbol.asyncIterator]() {
|
|
24006
23807
|
const controller = new AbortController();
|
|
24007
|
-
const
|
|
23808
|
+
const signal = options?.signal ? AbortSignal.any([controller.signal, options.signal]) : controller.signal;
|
|
24008
23809
|
const iterator = (async function* () {
|
|
24009
23810
|
try {
|
|
24010
|
-
for await (const published of events.subscribe({ signal
|
|
24011
|
-
if (
|
|
23811
|
+
for await (const published of events.subscribe({ signal })) {
|
|
23812
|
+
if (signal.aborted)
|
|
24012
23813
|
return;
|
|
24013
23814
|
if (published.type !== type)
|
|
24014
23815
|
continue;
|
|
24015
23816
|
yield published;
|
|
24016
23817
|
}
|
|
24017
23818
|
} catch (error62) {
|
|
24018
|
-
if (!
|
|
23819
|
+
if (!signal.aborted)
|
|
24019
23820
|
throw error62;
|
|
24020
23821
|
} finally {
|
|
24021
23822
|
controller.abort();
|
|
@@ -24053,8 +23854,8 @@ function makeRpc2(raw, events) {
|
|
|
24053
23854
|
subscribe,
|
|
24054
23855
|
on: (name, handler, options) => {
|
|
24055
23856
|
const controller = new AbortController();
|
|
24056
|
-
const
|
|
24057
|
-
const source = subscribe(name, { signal
|
|
23857
|
+
const signal = options?.signal ? AbortSignal.any([controller.signal, options.signal]) : controller.signal;
|
|
23858
|
+
const source = subscribe(name, { signal });
|
|
24058
23859
|
(async () => {
|
|
24059
23860
|
for await (const event of source)
|
|
24060
23861
|
await handler(event);
|
|
@@ -24077,7 +23878,7 @@ var init_mcp_kdshn947 = __esm({
|
|
|
24077
23878
|
// node_modules/.pnpm/@opencode+client@2.2.1_effect@4.0.1/node_modules/@opencode/client/dist/chunks/mcp-6v8v0sqq.js
|
|
24078
23879
|
function make5(options) {
|
|
24079
23880
|
const raw = make6(options);
|
|
24080
|
-
const events = make7((
|
|
23881
|
+
const events = make7((signal, onActivity) => raw.event.subscribe(void 0, { signal, onActivity }));
|
|
24081
23882
|
return {
|
|
24082
23883
|
...raw,
|
|
24083
23884
|
rpc: Object.assign(makeRpc2(raw, events), raw.rpc),
|
|
@@ -24267,160 +24068,6 @@ var init_mcp_qhd5h5hk = __esm({
|
|
|
24267
24068
|
});
|
|
24268
24069
|
|
|
24269
24070
|
// node_modules/.pnpm/@opencode+client@2.2.1_effect@4.0.1/node_modules/@opencode/client/dist/promise/service.js
|
|
24270
|
-
import { readFile as readFile2, rm as rm2 } from "node:fs/promises";
|
|
24271
|
-
async function discover(options = {}) {
|
|
24272
|
-
const found = (await registered(options.file)).service;
|
|
24273
|
-
if (found?.state !== "ready")
|
|
24274
|
-
return;
|
|
24275
|
-
if (!found.compatible)
|
|
24276
|
-
return;
|
|
24277
|
-
if (!matchesVersion2(found.version, options))
|
|
24278
|
-
return;
|
|
24279
|
-
return found.endpoint;
|
|
24280
|
-
}
|
|
24281
|
-
async function ensure(options = {}) {
|
|
24282
|
-
const timing = ensureTiming2(options);
|
|
24283
|
-
const deadline = Date.now() + timing.promiseTimeout;
|
|
24284
|
-
const pool = contenderPool2(timing);
|
|
24285
|
-
let timeouts;
|
|
24286
|
-
let announced = false;
|
|
24287
|
-
const announce = (reason, previousVersion) => {
|
|
24288
|
-
if (announced)
|
|
24289
|
-
return;
|
|
24290
|
-
announced = true;
|
|
24291
|
-
options.onStart?.(reason, previousVersion);
|
|
24292
|
-
};
|
|
24293
|
-
const spawnContender = async () => {
|
|
24294
|
-
const [command, ...args] = options.command ?? ["opencode", "serve", "--service"];
|
|
24295
|
-
if (command === void 0)
|
|
24296
|
-
throw new Error("Missing service command");
|
|
24297
|
-
try {
|
|
24298
|
-
return spawnServiceContender2(command, args, await environment2(options.file ?? fallback2(), options.env));
|
|
24299
|
-
} catch (cause) {
|
|
24300
|
-
throw new Error("Failed to start server", { cause });
|
|
24301
|
-
}
|
|
24302
|
-
};
|
|
24303
|
-
try {
|
|
24304
|
-
while (true) {
|
|
24305
|
-
if (Date.now() >= deadline)
|
|
24306
|
-
throw pool.failure() ?? new Error("Timed out waiting for the background service to start");
|
|
24307
|
-
const registration = await registered(options.file, timing.requestTimeout);
|
|
24308
|
-
if (registration.timedOut && registration.info !== void 0) {
|
|
24309
|
-
timeouts = {
|
|
24310
|
-
info: registration.info,
|
|
24311
|
-
count: timeouts !== void 0 && same2(timeouts.info, registration.info) ? timeouts.count + 1 : 1
|
|
24312
|
-
};
|
|
24313
|
-
if (timeouts.count >= 3) {
|
|
24314
|
-
announce("missing");
|
|
24315
|
-
console.warn("Background service is unresponsive; recovery cannot preserve persistent terminals");
|
|
24316
|
-
await clear2(options.file ?? fallback2());
|
|
24317
|
-
await terminate(registration.info, options, timing);
|
|
24318
|
-
pool.evict(registration.info.pid);
|
|
24319
|
-
pool.recruitNow();
|
|
24320
|
-
timeouts = void 0;
|
|
24321
|
-
}
|
|
24322
|
-
} else
|
|
24323
|
-
timeouts = void 0;
|
|
24324
|
-
if (registration.service !== void 0) {
|
|
24325
|
-
pool.serviceAnswered();
|
|
24326
|
-
const service2 = registration.service;
|
|
24327
|
-
const decision = decide2(service2, options);
|
|
24328
|
-
if (decision._tag === "fail")
|
|
24329
|
-
throw decision.error;
|
|
24330
|
-
if (decision._tag === "reuse") {
|
|
24331
|
-
await complete2(options.file ?? fallback2(), service2.info);
|
|
24332
|
-
return service2.endpoint;
|
|
24333
|
-
}
|
|
24334
|
-
if (decision._tag === "replace") {
|
|
24335
|
-
announce("version-mismatch", service2.version);
|
|
24336
|
-
if (service2.state !== "ready")
|
|
24337
|
-
console.warn("Background service is not ready; replacement cannot preserve persistent terminals");
|
|
24338
|
-
await stop({ file: options.file, pty: decision.pty }).catch(() => {
|
|
24339
|
-
return;
|
|
24340
|
-
});
|
|
24341
|
-
pool.evict(service2.info.pid);
|
|
24342
|
-
}
|
|
24343
|
-
} else {
|
|
24344
|
-
const failed = pool.reap();
|
|
24345
|
-
if (failed !== void 0)
|
|
24346
|
-
throw failed;
|
|
24347
|
-
if (pool.shouldRecruit(registration.info !== void 0)) {
|
|
24348
|
-
announce("missing");
|
|
24349
|
-
pool.add(await spawnContender());
|
|
24350
|
-
}
|
|
24351
|
-
}
|
|
24352
|
-
await delay(timing.pollInterval);
|
|
24353
|
-
}
|
|
24354
|
-
} finally {
|
|
24355
|
-
pool.releaseAll();
|
|
24356
|
-
}
|
|
24357
|
-
}
|
|
24358
|
-
async function stop(options = {}) {
|
|
24359
|
-
const info = await read2(options.file);
|
|
24360
|
-
await (options.pty === "handoff" && info !== void 0 ? prepare2(options.file ?? fallback2(), info, defaultEnsureTiming2.requestTimeout) : clear2(options.file ?? fallback2())).catch((cause) => console.warn("Failed to prepare persistent terminals for replacement", cause));
|
|
24361
|
-
if (info !== void 0)
|
|
24362
|
-
await terminate(info, options, ensureTiming2(options));
|
|
24363
|
-
}
|
|
24364
|
-
async function read2(file2) {
|
|
24365
|
-
const text4 = await readFile2(file2 ?? fallback2(), "utf8").catch(() => {
|
|
24366
|
-
return;
|
|
24367
|
-
});
|
|
24368
|
-
if (text4 === void 0)
|
|
24369
|
-
return;
|
|
24370
|
-
try {
|
|
24371
|
-
return JSON.parse(text4);
|
|
24372
|
-
} catch {
|
|
24373
|
-
return;
|
|
24374
|
-
}
|
|
24375
|
-
}
|
|
24376
|
-
async function registered(file2, timeout) {
|
|
24377
|
-
const info = await read2(file2);
|
|
24378
|
-
if (info === void 0)
|
|
24379
|
-
return { info: void 0, service: void 0, timedOut: false };
|
|
24380
|
-
return { info, ...await probeResult2(info, timeout) };
|
|
24381
|
-
}
|
|
24382
|
-
function signal(pid, name) {
|
|
24383
|
-
try {
|
|
24384
|
-
process.kill(pid, name);
|
|
24385
|
-
} catch {
|
|
24386
|
-
}
|
|
24387
|
-
}
|
|
24388
|
-
function stopped(pid) {
|
|
24389
|
-
try {
|
|
24390
|
-
process.kill(pid, 0);
|
|
24391
|
-
return false;
|
|
24392
|
-
} catch {
|
|
24393
|
-
return true;
|
|
24394
|
-
}
|
|
24395
|
-
}
|
|
24396
|
-
async function waitUntilStopped(pid, timing) {
|
|
24397
|
-
for (let attempt = 0; attempt <= timing.stopPollAttempts; attempt++) {
|
|
24398
|
-
if (stopped(pid))
|
|
24399
|
-
return true;
|
|
24400
|
-
if (attempt < timing.stopPollAttempts)
|
|
24401
|
-
await delay(timing.stopPollInterval);
|
|
24402
|
-
}
|
|
24403
|
-
return false;
|
|
24404
|
-
}
|
|
24405
|
-
async function terminate(info, options, timing) {
|
|
24406
|
-
const current = await read2(options.file);
|
|
24407
|
-
if (current === void 0 || !same2(current, info))
|
|
24408
|
-
return;
|
|
24409
|
-
signal(info.pid, "SIGTERM");
|
|
24410
|
-
if (!await waitUntilStopped(info.pid, timing)) {
|
|
24411
|
-
signal(info.pid, "SIGKILL");
|
|
24412
|
-
if (!await waitUntilStopped(info.pid, timing))
|
|
24413
|
-
throw new Error(`Server process ${info.pid} is still running`);
|
|
24414
|
-
}
|
|
24415
|
-
const latest = await read2(options.file);
|
|
24416
|
-
if (latest === void 0 || !same2(latest, info))
|
|
24417
|
-
return;
|
|
24418
|
-
await rm2(options.file ?? fallback2(), { force: true });
|
|
24419
|
-
}
|
|
24420
|
-
function delay(milliseconds) {
|
|
24421
|
-
return new Promise((resolve3) => setTimeout(resolve3, milliseconds));
|
|
24422
|
-
}
|
|
24423
|
-
var Service;
|
|
24424
24071
|
var init_service = __esm({
|
|
24425
24072
|
"node_modules/.pnpm/@opencode+client@2.2.1_effect@4.0.1/node_modules/@opencode/client/dist/promise/service.js"() {
|
|
24426
24073
|
init_mcp_ve4aws36();
|
|
@@ -24428,7 +24075,6 @@ var init_service = __esm({
|
|
|
24428
24075
|
init_mcp_sxt88q69();
|
|
24429
24076
|
init_mcp_8ye1ye6f();
|
|
24430
24077
|
init_mcp_qhd5h5hk();
|
|
24431
|
-
Service = { discover, ensure, stop, headers: headers2 };
|
|
24432
24078
|
}
|
|
24433
24079
|
});
|
|
24434
24080
|
|
|
@@ -24455,86 +24101,6 @@ var init_playback_tokens2 = __esm({
|
|
|
24455
24101
|
});
|
|
24456
24102
|
|
|
24457
24103
|
// server/opencode.ts
|
|
24458
|
-
import { basename as basename4 } from "node:path";
|
|
24459
|
-
import { createHash as createHash5 } from "node:crypto";
|
|
24460
|
-
async function api(path, signal2) {
|
|
24461
|
-
const endpoint = await Service.discover({ file: serviceFile() });
|
|
24462
|
-
if (!endpoint) throw new Error("No healthy OpenCode service was found.");
|
|
24463
|
-
const origin = new URL(endpoint.url);
|
|
24464
|
-
if (!["127.0.0.1", "localhost", "[::1]"].includes(origin.hostname) || !["http:", "https:"].includes(origin.protocol)) throw new Error("SessionGraph only imports from a loopback OpenCode service.");
|
|
24465
|
-
const response = await fetch(new URL(path, endpoint.url), {
|
|
24466
|
-
headers: Service.headers(endpoint),
|
|
24467
|
-
redirect: "error",
|
|
24468
|
-
signal: signal2 ? AbortSignal.any([signal2, AbortSignal.timeout(45e3)]) : AbortSignal.timeout(45e3)
|
|
24469
|
-
});
|
|
24470
|
-
if (!response.ok) throw new Error(`OpenCode request failed (${response.status}).`);
|
|
24471
|
-
return await response.json();
|
|
24472
|
-
}
|
|
24473
|
-
function sessionFromResponse(value, id3) {
|
|
24474
|
-
const session = "data" in value ? value.data : value;
|
|
24475
|
-
if (session?.id !== id3 || !Number.isFinite(session.time?.updated)) throw new Error("Unexpected OpenCode session response.");
|
|
24476
|
-
return session;
|
|
24477
|
-
}
|
|
24478
|
-
async function getSessionInfo(id3) {
|
|
24479
|
-
return sessionFromResponse(await api(`/api/session/${encodeURIComponent(id3)}`), id3);
|
|
24480
|
-
}
|
|
24481
|
-
async function getSessionGraph(force = false) {
|
|
24482
|
-
if (!force && cache2 && Date.now() - cache2.loadedAt < 3e4) return cache2;
|
|
24483
|
-
if (pending) return pending;
|
|
24484
|
-
pending = loadSessionGraph().then((data) => cache2 = data).finally(() => {
|
|
24485
|
-
pending = void 0;
|
|
24486
|
-
});
|
|
24487
|
-
return pending;
|
|
24488
|
-
}
|
|
24489
|
-
async function loadSessionGraph() {
|
|
24490
|
-
const endpoint = await Service.discover({ file: serviceFile() });
|
|
24491
|
-
if (!endpoint) throw new Error("No healthy OpenCode service was found.");
|
|
24492
|
-
const sourceID = createHash5("sha256").update(JSON.stringify([endpoint.url, serviceFile() || "default"])).digest("hex");
|
|
24493
|
-
const rawProjects = await api("/api/project");
|
|
24494
|
-
const sessions = /* @__PURE__ */ new Map();
|
|
24495
|
-
const warnings = [];
|
|
24496
|
-
let cursor2;
|
|
24497
|
-
const seenCursors = /* @__PURE__ */ new Set();
|
|
24498
|
-
do {
|
|
24499
|
-
const params = new URLSearchParams({ limit: "500" });
|
|
24500
|
-
if (cursor2) params.set("cursor", cursor2);
|
|
24501
|
-
const page3 = await api(`/api/session?${params}`);
|
|
24502
|
-
if (!Array.isArray(page3.data)) throw new Error("Unexpected OpenCode session response. OpenCode V2 is required.");
|
|
24503
|
-
for (const raw of page3.data) {
|
|
24504
|
-
const t = raw.tokens;
|
|
24505
|
-
sessions.set(raw.id, {
|
|
24506
|
-
id: raw.id,
|
|
24507
|
-
title: raw.title || "Untitled session",
|
|
24508
|
-
projectID: raw.projectID,
|
|
24509
|
-
parentID: raw.parentID,
|
|
24510
|
-
forkID: raw.fork?.sessionID,
|
|
24511
|
-
directory: raw.location?.directory || "",
|
|
24512
|
-
created: raw.time.created,
|
|
24513
|
-
updated: raw.time.updated,
|
|
24514
|
-
archived: Boolean(raw.time.archived),
|
|
24515
|
-
model: raw.model?.id || "Unknown model",
|
|
24516
|
-
provider: raw.model?.providerID || "",
|
|
24517
|
-
agent: raw.agent || "build",
|
|
24518
|
-
cost: recordedCost(raw.cost),
|
|
24519
|
-
// Input + output + cache tokens; reasoning is generally part of output.
|
|
24520
|
-
tokens: sumRecordedTokens([t?.input, t?.output, t?.cache?.read, t?.cache?.write]),
|
|
24521
|
-
usage: sessionUsage(openCodeUsage(t, raw.cost)),
|
|
24522
|
-
outcome: raw.outcome
|
|
24523
|
-
});
|
|
24524
|
-
}
|
|
24525
|
-
cursor2 = page3.cursor?.next;
|
|
24526
|
-
if (cursor2 && seenCursors.has(cursor2)) throw new Error("OpenCode returned a repeated session cursor.");
|
|
24527
|
-
if (cursor2) seenCursors.add(cursor2);
|
|
24528
|
-
} while (cursor2 && sessions.size < 2e4);
|
|
24529
|
-
if (cursor2) warnings.push("OpenCode: Showing the newest 20,000 sessions.");
|
|
24530
|
-
const projects = rawProjects.map((p) => ({
|
|
24531
|
-
id: p.id,
|
|
24532
|
-
name: p.name || basename4(p.canonical) || "Global",
|
|
24533
|
-
directory: p.canonical,
|
|
24534
|
-
worktrees: p.sandboxes || []
|
|
24535
|
-
}));
|
|
24536
|
-
return { sourceID, sessions: [...sessions.values()], projects, loadedAt: Date.now(), warnings };
|
|
24537
|
-
}
|
|
24538
24104
|
function editedPaths(part) {
|
|
24539
24105
|
if (part.state?.status !== "completed") return [];
|
|
24540
24106
|
const name = (part.name || "").split(/[./]/).at(-1) || "";
|
|
@@ -24587,7 +24153,6 @@ function summarizeMessages(id3, messages, nextCursor2) {
|
|
|
24587
24153
|
loadedAt: Date.now()
|
|
24588
24154
|
};
|
|
24589
24155
|
}
|
|
24590
|
-
var cache2, pending;
|
|
24591
24156
|
var init_opencode = __esm({
|
|
24592
24157
|
"server/opencode.ts"() {
|
|
24593
24158
|
"use strict";
|
|
@@ -24698,7 +24263,7 @@ function opencodeEvents(raw, message2) {
|
|
|
24698
24263
|
else if (part.type === "tool") {
|
|
24699
24264
|
const state2 = part.state || {}, endTime = messageTime(part.time?.completed);
|
|
24700
24265
|
const status2 = state2.status === "error" ? "failed" : state2.status === "streaming" ? "pending" : ["running", "completed"].includes(state2.status) ? state2.status : "unknown";
|
|
24701
|
-
const common = { ...native, callID: part.id, status: status2, endTime, ...executionFields(state2.input, state2.metadata), partial: Boolean(state2.metadata?.truncated) };
|
|
24266
|
+
const common = { ...native, callID: part.callID || part.id, status: status2, endTime, ...executionFields(state2.input, state2.metadata), partial: Boolean(state2.metadata?.truncated) };
|
|
24702
24267
|
events.push(eventFor(message2, `${id3}:call`, "tool_call", part.name || "Tool call", "", { ...common, ...timing, input: eventText(state2.input) }));
|
|
24703
24268
|
if (["completed", "error"].includes(state2.status)) events.push(eventFor(message2, `${id3}:result`, "tool_result", part.name || "Tool result", "", { ...common, role: "tool", ...endTime ? { time: endTime, timeSource: "recorded" } : {}, output: eventText(state2.error ?? state2.content, 64e3) }));
|
|
24704
24269
|
} else events.push(eventFor(message2, id3, "event", `${part.type || "Unknown"} content`, "Unsupported content.", { ...native, ...timing, partial: true }));
|
|
@@ -24717,7 +24282,657 @@ var init_opencode_events = __esm({
|
|
|
24717
24282
|
}
|
|
24718
24283
|
});
|
|
24719
24284
|
|
|
24285
|
+
// server/adapters/harness-paths.ts
|
|
24286
|
+
import { homedir as homedir3 } from "node:os";
|
|
24287
|
+
import { join as join2 } from "node:path";
|
|
24288
|
+
var homePath, dataPath, configPath, appPath, tokscalePath, envHome, harnessRoots;
|
|
24289
|
+
var init_harness_paths = __esm({
|
|
24290
|
+
"server/adapters/harness-paths.ts"() {
|
|
24291
|
+
"use strict";
|
|
24292
|
+
init_source_paths();
|
|
24293
|
+
homePath = (...parts) => join2(homedir3(), ...parts);
|
|
24294
|
+
dataPath = (...parts) => join2(process.env.XDG_DATA_HOME || homePath(".local/share"), ...parts);
|
|
24295
|
+
configPath = (...parts) => join2(process.env.XDG_CONFIG_HOME || homePath(".config"), ...parts);
|
|
24296
|
+
appPath = (...parts) => join2(process.platform === "darwin" ? homePath("Library/Application Support") : process.platform === "win32" ? process.env.APPDATA || homePath("AppData/Roaming") : process.env.XDG_CONFIG_HOME || homePath(".config"), ...parts);
|
|
24297
|
+
tokscalePath = (...parts) => join2(process.env.TOKSCALE_CONFIG_DIR || (process.platform === "win32" ? appPath("tokscale") : configPath("tokscale")), ...parts);
|
|
24298
|
+
envHome = (env2, fallback, ...parts) => join2(process.env[env2]?.trim() || homePath(fallback), ...parts);
|
|
24299
|
+
harnessRoots = (id3, defaults) => () => {
|
|
24300
|
+
const override = sourcePath(id3) || process.env[`SESSIONGRAPH_${id3.replace(/-/g, "_").toUpperCase()}_HISTORY_DIR`]?.trim();
|
|
24301
|
+
return override ? [override] : defaults();
|
|
24302
|
+
};
|
|
24303
|
+
}
|
|
24304
|
+
});
|
|
24305
|
+
|
|
24306
|
+
// server/adapters/compressed.ts
|
|
24307
|
+
import { gunzipSync, zstdDecompressSync } from "node:zlib";
|
|
24308
|
+
function expandHistory(buffer, maxOutputLength) {
|
|
24309
|
+
if (buffer.length >= 4 && buffer.readUInt32LE(0) === 4247762216) return zstdDecompressSync(buffer, { maxOutputLength });
|
|
24310
|
+
if (buffer[0] === 31 && buffer[1] === 139) return gunzipSync(buffer, { maxOutputLength });
|
|
24311
|
+
if (buffer.length > maxOutputLength) throw new Error("Expanded history exceeds the snapshot limit.");
|
|
24312
|
+
return buffer;
|
|
24313
|
+
}
|
|
24314
|
+
var init_compressed = __esm({
|
|
24315
|
+
"server/adapters/compressed.ts"() {
|
|
24316
|
+
"use strict";
|
|
24317
|
+
}
|
|
24318
|
+
});
|
|
24319
|
+
|
|
24320
|
+
// server/adapters/local-files.ts
|
|
24321
|
+
import { constants } from "node:fs";
|
|
24322
|
+
import { lstat, open as open2, readdir } from "node:fs/promises";
|
|
24323
|
+
import { join as join3, relative as relative2 } from "node:path";
|
|
24324
|
+
async function fileState(path) {
|
|
24325
|
+
try {
|
|
24326
|
+
const s = await lstat(path);
|
|
24327
|
+
if (!s.isFile()) throw new Error("History must be a regular file, not a symlink.");
|
|
24328
|
+
if (s.size > MAX_BYTES) throw new Error("History exceeds the 32 MB per-file limit.");
|
|
24329
|
+
return { path, signature: digest([s.size, s.mtimeMs, s.ctimeMs, s.ino]), created: s.birthtimeMs || s.mtimeMs, updated: s.mtimeMs, size: s.size };
|
|
24330
|
+
} catch (error62) {
|
|
24331
|
+
if (error62.code === "ENOENT") return { path, signature: "missing", created: 0, updated: 0, size: 0 };
|
|
24332
|
+
throw error62;
|
|
24333
|
+
}
|
|
24334
|
+
}
|
|
24335
|
+
async function historyFiles(roots2, match2) {
|
|
24336
|
+
const files = [], queue = [];
|
|
24337
|
+
const warnings = [];
|
|
24338
|
+
for (const root3 of new Set(roots2)) {
|
|
24339
|
+
try {
|
|
24340
|
+
if ((await lstat(root3)).isDirectory()) queue.push({ root: root3, path: root3, depth: 0 });
|
|
24341
|
+
} catch (error62) {
|
|
24342
|
+
if (error62.code !== "ENOENT") warnings.push("A history directory could not be read.");
|
|
24343
|
+
}
|
|
24344
|
+
}
|
|
24345
|
+
let entriesSeen = 0, limited = false;
|
|
24346
|
+
for (let i = 0; i < queue.length && files.length < MAX_FILES && entriesSeen < 1e5; i++) {
|
|
24347
|
+
const { root: root3, path, depth } = queue[i];
|
|
24348
|
+
let entries2;
|
|
24349
|
+
try {
|
|
24350
|
+
entries2 = await readdir(path, { withFileTypes: true });
|
|
24351
|
+
} catch {
|
|
24352
|
+
warnings.push("A history directory could not be read.");
|
|
24353
|
+
continue;
|
|
24354
|
+
}
|
|
24355
|
+
for (const entry of entries2) {
|
|
24356
|
+
if (++entriesSeen > 1e5 || files.length >= MAX_FILES) {
|
|
24357
|
+
limited = true;
|
|
24358
|
+
break;
|
|
24359
|
+
}
|
|
24360
|
+
const file2 = join3(path, entry.name);
|
|
24361
|
+
if (entry.isDirectory()) {
|
|
24362
|
+
if (depth < 6 && queue.length < MAX_FILES) queue.push({ root: root3, path: file2, depth: depth + 1 });
|
|
24363
|
+
else limited = true;
|
|
24364
|
+
}
|
|
24365
|
+
if (entry.isFile() && match2(relative2(root3, file2).split("\\").join("/"))) files.push(file2);
|
|
24366
|
+
}
|
|
24367
|
+
}
|
|
24368
|
+
if (limited) warnings.push("History discovery reached its file, directory, or depth limit.");
|
|
24369
|
+
return { files: [...new Set(files)].sort(), warnings };
|
|
24370
|
+
}
|
|
24371
|
+
function json4(value) {
|
|
24372
|
+
return JSON.parse(value);
|
|
24373
|
+
}
|
|
24374
|
+
function jsonLines(value) {
|
|
24375
|
+
const rows2 = [];
|
|
24376
|
+
let partial2 = false;
|
|
24377
|
+
for (const line of value.split("\n")) {
|
|
24378
|
+
if (!line.trim()) continue;
|
|
24379
|
+
if (rows2.length >= MAX_RECORDS) throw new Error("History exceeds the 50,000-record limit.");
|
|
24380
|
+
if (line.length > 2e6) throw new Error("History contains a record larger than 2 MB.");
|
|
24381
|
+
try {
|
|
24382
|
+
const row = json4(line);
|
|
24383
|
+
if (!row || typeof row !== "object" || Array.isArray(row)) partial2 = true;
|
|
24384
|
+
else rows2.push(row);
|
|
24385
|
+
} catch {
|
|
24386
|
+
partial2 = true;
|
|
24387
|
+
}
|
|
24388
|
+
}
|
|
24389
|
+
return { rows: rows2, partial: partial2 };
|
|
24390
|
+
}
|
|
24391
|
+
function localFileAdapter(source) {
|
|
24392
|
+
const metadata2 = /* @__PURE__ */ new Map();
|
|
24393
|
+
let cached3;
|
|
24394
|
+
const states = (path) => Promise.all([path, ...source.extras?.(path) || []].map(fileState));
|
|
24395
|
+
const revision2 = (values) => digest([1, ...values.filter((_, i) => i === 0 || source.revisionExtras !== false).map((s) => [s.path, s.signature])]);
|
|
24396
|
+
async function load(path, expected, before) {
|
|
24397
|
+
if (revision2(before) !== expected) throw new Error("Session changed during import; import again.");
|
|
24398
|
+
if (cached3?.path === path && cached3.revision === expected) return cached3.history;
|
|
24399
|
+
if (before[0].signature === "missing") throw new Error("History file is unavailable.");
|
|
24400
|
+
if (before.reduce((n, s) => n + s.size, 0) > MAX_BYTES) throw new Error("Combined history exceeds the 32 MB snapshot limit.");
|
|
24401
|
+
const files = /* @__PURE__ */ new Map();
|
|
24402
|
+
let expanded = 0;
|
|
24403
|
+
for (const s of before.filter((s2) => s2.signature !== "missing")) {
|
|
24404
|
+
const handle = await open2(s.path, constants.O_RDONLY | (constants.O_NOFOLLOW || 0));
|
|
24405
|
+
try {
|
|
24406
|
+
const buffer = Buffer.alloc(s.size + 1);
|
|
24407
|
+
let bytes2 = 0;
|
|
24408
|
+
while (bytes2 < buffer.length) {
|
|
24409
|
+
const part = await handle.read(buffer, bytes2, buffer.length - bytes2, bytes2);
|
|
24410
|
+
if (!part.bytesRead) break;
|
|
24411
|
+
bytes2 += part.bytesRead;
|
|
24412
|
+
}
|
|
24413
|
+
if (bytes2 !== s.size) throw new Error("History changed while reading; import again.");
|
|
24414
|
+
const data = expandHistory(buffer.subarray(0, bytes2), MAX_BYTES);
|
|
24415
|
+
expanded += data.length;
|
|
24416
|
+
if (expanded > MAX_BYTES) throw new Error("Expanded history exceeds the 32 MB snapshot limit.");
|
|
24417
|
+
files.set(s.path, data.toString("utf8"));
|
|
24418
|
+
} finally {
|
|
24419
|
+
await handle.close();
|
|
24420
|
+
}
|
|
24421
|
+
}
|
|
24422
|
+
if (digest(await states(path)) !== digest(before)) throw new Error("History changed while reading; import again.");
|
|
24423
|
+
const history = source.parse(path, files);
|
|
24424
|
+
if (!history) return;
|
|
24425
|
+
if (source.capabilities.history && !history.messages.length) throw new Error("No readable conversation.");
|
|
24426
|
+
if (!history.nativeID || history.nativeID.length > 512) throw new Error("History has no supported native session identity.");
|
|
24427
|
+
if (history.messages.length > MAX_RECORDS) throw new Error("History exceeds the 50,000-message limit.");
|
|
24428
|
+
cached3 = { path, revision: expected, history };
|
|
24429
|
+
return history;
|
|
24430
|
+
}
|
|
24431
|
+
return {
|
|
24432
|
+
id: source.id,
|
|
24433
|
+
name: source.name,
|
|
24434
|
+
description: source.description,
|
|
24435
|
+
capabilities: source.capabilities,
|
|
24436
|
+
async detect() {
|
|
24437
|
+
for (const root3 of source.roots()) if ((await lstat(root3).catch(() => void 0))?.isDirectory()) return true;
|
|
24438
|
+
return false;
|
|
24439
|
+
},
|
|
24440
|
+
async discover() {
|
|
24441
|
+
const listing = await historyFiles(source.roots(), source.match), found = /* @__PURE__ */ new Map();
|
|
24442
|
+
let failed = 0;
|
|
24443
|
+
const blocked = /* @__PURE__ */ new Set(), unreadable = /* @__PURE__ */ new Set();
|
|
24444
|
+
for (const path of listing.files) {
|
|
24445
|
+
try {
|
|
24446
|
+
const before = await states(path), rev = revision2(before);
|
|
24447
|
+
let candidate = metadata2.get(path);
|
|
24448
|
+
if (!candidate || candidate.revision !== rev) {
|
|
24449
|
+
const history = await load(path, rev, before);
|
|
24450
|
+
if (!history) {
|
|
24451
|
+
const nativeID = source.authoritativeIdentity?.(path);
|
|
24452
|
+
if (nativeID) blocked.add(identity(source.id, nativeID));
|
|
24453
|
+
continue;
|
|
24454
|
+
}
|
|
24455
|
+
const session = { ...blankSession(source.id, history.nativeID), ...history.session };
|
|
24456
|
+
session.id = identity(source.id, history.nativeID);
|
|
24457
|
+
session.nativeID = history.nativeID;
|
|
24458
|
+
session.source = source.id;
|
|
24459
|
+
session.directory = text3(session.directory);
|
|
24460
|
+
session.projectID = project(source.id, session.directory).id;
|
|
24461
|
+
session.created = time3(session.created) || history.messages.map((m) => time3(m.time)).find(Boolean) || before[0].created;
|
|
24462
|
+
session.updated = before[0].updated;
|
|
24463
|
+
session.agent ||= source.name;
|
|
24464
|
+
session.parentID = history.parent ? identity(source.id, history.parent) : void 0;
|
|
24465
|
+
session.forkID = history.fork ? identity(source.id, history.fork) : void 0;
|
|
24466
|
+
if (session.title === "Untitled session" || !session.title) session.title = history.messages.flatMap((m) => m.role === "user" ? m.fragments.filter((f) => f.kind === "You").map((f) => f.text) : []).find(Boolean)?.replace(/\s+/g, " ").slice(0, 180) || `${source.name} session`;
|
|
24467
|
+
candidate = { session, revision: rev, locator: { path } };
|
|
24468
|
+
metadata2.set(path, candidate);
|
|
24469
|
+
}
|
|
24470
|
+
const previous = found.get(candidate.session.id);
|
|
24471
|
+
const preferred = candidate.locator.path.endsWith(".jsonl"), previousPreferred = previous?.locator.path.endsWith(".jsonl");
|
|
24472
|
+
if (!previous || preferred && !previousPreferred || preferred === previousPreferred && candidate.session.updated > previous.session.updated) found.set(candidate.session.id, candidate);
|
|
24473
|
+
} catch {
|
|
24474
|
+
const nativeID = source.authoritativeIdentity?.(path);
|
|
24475
|
+
if (nativeID) {
|
|
24476
|
+
const id3 = identity(source.id, nativeID);
|
|
24477
|
+
blocked.add(id3);
|
|
24478
|
+
unreadable.add(id3);
|
|
24479
|
+
} else failed++;
|
|
24480
|
+
}
|
|
24481
|
+
}
|
|
24482
|
+
const listed = new Set(listing.files);
|
|
24483
|
+
for (const path of metadata2.keys()) if (!listed.has(path)) metadata2.delete(path);
|
|
24484
|
+
if (failed) listing.warnings.push(`${source.name}: Skipped ${failed} unreadable, changing, unsupported, or oversized ${failed === 1 ? "history file" : "history files"}.`);
|
|
24485
|
+
const sessions = [...found.values()].filter((c) => !blocked.has(c.session.id));
|
|
24486
|
+
const errors = unreadable.size ? [`${source.name}: Could not read history for ${unreadable.size} ${unreadable.size === 1 ? "session" : "sessions"}.`] : void 0;
|
|
24487
|
+
return { sessions, projects: [...new Map(sessions.map((c) => {
|
|
24488
|
+
const p = project(source.id, c.session.directory);
|
|
24489
|
+
return [p.id, p];
|
|
24490
|
+
})).values()], warnings: listing.warnings, errors, blocked: [...blocked] };
|
|
24491
|
+
},
|
|
24492
|
+
async read(candidate, cursor2) {
|
|
24493
|
+
const offset = cursor2 === void 0 ? 0 : Number(cursor2);
|
|
24494
|
+
if (!Number.isSafeInteger(offset) || offset < 0) throw new Error("Invalid history cursor.");
|
|
24495
|
+
const history = await load(candidate.locator.path, candidate.revision, await states(candidate.locator.path));
|
|
24496
|
+
if (!history) throw new Error("History representation is no longer available.");
|
|
24497
|
+
const messages = history.messages.slice(offset, offset + 100);
|
|
24498
|
+
return {
|
|
24499
|
+
messages,
|
|
24500
|
+
cursor: offset + messages.length < history.messages.length ? String(offset + messages.length) : void 0,
|
|
24501
|
+
partial: Boolean(history.partial || messages.some((m) => m.partial)),
|
|
24502
|
+
note: history.note
|
|
24503
|
+
};
|
|
24504
|
+
}
|
|
24505
|
+
};
|
|
24506
|
+
}
|
|
24507
|
+
var object4, text3, time3, MAX_BYTES, MAX_RECORDS, MAX_FILES;
|
|
24508
|
+
var init_local_files = __esm({
|
|
24509
|
+
"server/adapters/local-files.ts"() {
|
|
24510
|
+
"use strict";
|
|
24511
|
+
init_common();
|
|
24512
|
+
init_compressed();
|
|
24513
|
+
object4 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
24514
|
+
text3 = (value) => typeof value === "string" ? value : "";
|
|
24515
|
+
time3 = (value) => {
|
|
24516
|
+
const n = typeof value === "number" ? value : typeof value === "string" ? /^\d{13}$/.test(value) ? Number(value) : Date.parse(value) : 0;
|
|
24517
|
+
return Number.isFinite(n) && n > 0 && n <= 864e13 ? n : 0;
|
|
24518
|
+
};
|
|
24519
|
+
MAX_BYTES = 32e6;
|
|
24520
|
+
MAX_RECORDS = 5e4;
|
|
24521
|
+
MAX_FILES = 2e4;
|
|
24522
|
+
}
|
|
24523
|
+
});
|
|
24524
|
+
|
|
24525
|
+
// server/adapters/sqlite-snapshot.ts
|
|
24526
|
+
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
24527
|
+
import { chmodSync as chmodSync2, constants as constants2, copyFileSync, lstatSync, mkdtempSync, rmSync } from "node:fs";
|
|
24528
|
+
import { copyFile, statfs } from "node:fs/promises";
|
|
24529
|
+
import { tmpdir } from "node:os";
|
|
24530
|
+
import { join as join4 } from "node:path";
|
|
24531
|
+
function snapshotFiles(path, large) {
|
|
24532
|
+
return [path, `${path}-wal`].map((file2, i) => {
|
|
24533
|
+
try {
|
|
24534
|
+
const s = lstatSync(file2);
|
|
24535
|
+
const kind = i ? "History database WAL" : "History database";
|
|
24536
|
+
if (!s.isFile()) throw new SqliteSnapshotFileError(`${kind} is not a regular file.`);
|
|
24537
|
+
if (!large && s.size > 8e9) throw new SqliteSnapshotFileError(`${kind} exceeds 8 GB.`);
|
|
24538
|
+
return s;
|
|
24539
|
+
} catch (error62) {
|
|
24540
|
+
if (i && error62.code === "ENOENT") return null;
|
|
24541
|
+
throw error62;
|
|
24542
|
+
}
|
|
24543
|
+
});
|
|
24544
|
+
}
|
|
24545
|
+
function sqliteRevision(path) {
|
|
24546
|
+
return fingerprint2(path, snapshotFiles(path, false));
|
|
24547
|
+
}
|
|
24548
|
+
function openSnapshot(destination) {
|
|
24549
|
+
const db2 = new DatabaseSync2(destination, { readOnly: true, enableDoubleQuotedStringLiterals: false, allowExtension: false });
|
|
24550
|
+
try {
|
|
24551
|
+
db2.exec("PRAGMA query_only=ON; PRAGMA trusted_schema=OFF; PRAGMA busy_timeout=1000; BEGIN;");
|
|
24552
|
+
return db2;
|
|
24553
|
+
} catch (error62) {
|
|
24554
|
+
db2.close();
|
|
24555
|
+
throw error62;
|
|
24556
|
+
}
|
|
24557
|
+
}
|
|
24558
|
+
async function withLargeSqliteSnapshot(path, read2, expected) {
|
|
24559
|
+
const retained = copies.get(path);
|
|
24560
|
+
if (expected && retained?.revision === expected) return read2(retained.db, expected);
|
|
24561
|
+
const files = snapshotFiles(path, true), revision2 = fingerprint2(path, files);
|
|
24562
|
+
if (expected && revision2 !== expected) throw new SqliteSnapshotChangedError("History database changed during import; import again.");
|
|
24563
|
+
if (retained?.revision === revision2) {
|
|
24564
|
+
const result = read2(retained.db, revision2);
|
|
24565
|
+
if (fingerprint2(path, snapshotFiles(path, true)) !== revision2) throw new SqliteSnapshotChangedError("History database changed during reading; import again.");
|
|
24566
|
+
return result;
|
|
24567
|
+
}
|
|
24568
|
+
close(path);
|
|
24569
|
+
while (copies.size >= 2) close(copies.keys().next().value);
|
|
24570
|
+
const directory3 = mkdtempSync(join4(tmpdir(), "sessiongraph-history-"));
|
|
24571
|
+
const destination = join4(directory3, "history.db");
|
|
24572
|
+
let db2;
|
|
24573
|
+
try {
|
|
24574
|
+
for (const [index, suffix] of ["", "-wal"].entries()) {
|
|
24575
|
+
const file2 = files[index];
|
|
24576
|
+
if (!file2) continue;
|
|
24577
|
+
try {
|
|
24578
|
+
await copyFile(path + suffix, destination + suffix, constants2.COPYFILE_FICLONE_FORCE);
|
|
24579
|
+
} catch (error62) {
|
|
24580
|
+
if (!["ENOSYS", "ENOTSUP", "EOPNOTSUPP", "EXDEV", "EINVAL"].includes(error62.code || "")) throw error62;
|
|
24581
|
+
const { bavail, bsize } = await statfs(directory3);
|
|
24582
|
+
const reserve = 512 * 1024 * 1024;
|
|
24583
|
+
if (bavail * bsize < file2.size + reserve) throw new Error("Not enough free space for the T3 history snapshot. Free space on the temporary drive and retry.");
|
|
24584
|
+
await copyFile(path + suffix, destination + suffix);
|
|
24585
|
+
}
|
|
24586
|
+
chmodSync2(destination + suffix, 384);
|
|
24587
|
+
}
|
|
24588
|
+
if (fingerprint2(path, snapshotFiles(path, true)) !== revision2) throw new SqliteSnapshotChangedError("History database changed while copying; import again.");
|
|
24589
|
+
db2 = openSnapshot(destination);
|
|
24590
|
+
const result = read2(db2, revision2);
|
|
24591
|
+
if (!expected && fingerprint2(path, snapshotFiles(path, true)) !== revision2) throw new SqliteSnapshotChangedError("History database changed during reading; import again.");
|
|
24592
|
+
close(path);
|
|
24593
|
+
while (copies.size >= 2) close(copies.keys().next().value);
|
|
24594
|
+
copies.set(path, { revision: revision2, directory: directory3, db: db2 });
|
|
24595
|
+
return result;
|
|
24596
|
+
} catch (error62) {
|
|
24597
|
+
try {
|
|
24598
|
+
db2?.close();
|
|
24599
|
+
} finally {
|
|
24600
|
+
rmSync(directory3, { recursive: true, force: true });
|
|
24601
|
+
}
|
|
24602
|
+
if (error62.code === "ENOENT" && fingerprint2(path, snapshotFiles(path, true)) !== revision2)
|
|
24603
|
+
throw new SqliteSnapshotChangedError("History database changed while copying; import again.");
|
|
24604
|
+
throw error62;
|
|
24605
|
+
}
|
|
24606
|
+
}
|
|
24607
|
+
function withSqliteSnapshot(path, read2, expected, pinned = false) {
|
|
24608
|
+
const retained = copies.get(path);
|
|
24609
|
+
if (pinned && expected && retained?.revision === expected) return read2(retained.db);
|
|
24610
|
+
const revision2 = sqliteRevision(path);
|
|
24611
|
+
if (expected && revision2 !== expected) throw new SqliteSnapshotChangedError("History database changed during import; import again.");
|
|
24612
|
+
let copy = copies.get(path);
|
|
24613
|
+
if (copy?.revision !== revision2) {
|
|
24614
|
+
close(path);
|
|
24615
|
+
while (copies.size >= 2) close(copies.keys().next().value);
|
|
24616
|
+
const directory3 = mkdtempSync(join4(tmpdir(), "sessiongraph-history-"));
|
|
24617
|
+
let db2;
|
|
24618
|
+
try {
|
|
24619
|
+
chmodSync2(directory3, 448);
|
|
24620
|
+
const destination = join4(directory3, "history.db");
|
|
24621
|
+
for (const suffix of ["", "-wal"]) {
|
|
24622
|
+
try {
|
|
24623
|
+
copyFileSync(path + suffix, destination + suffix, constants2.COPYFILE_FICLONE);
|
|
24624
|
+
chmodSync2(destination + suffix, 384);
|
|
24625
|
+
} catch (error62) {
|
|
24626
|
+
if (suffix && error62.code === "ENOENT") continue;
|
|
24627
|
+
throw error62;
|
|
24628
|
+
}
|
|
24629
|
+
}
|
|
24630
|
+
if (sqliteRevision(path) !== revision2) throw new SqliteSnapshotChangedError("History database changed while copying; import again.");
|
|
24631
|
+
db2 = openSnapshot(destination);
|
|
24632
|
+
copy = { revision: revision2, directory: directory3, db: db2 };
|
|
24633
|
+
copies.set(path, copy);
|
|
24634
|
+
} catch (error62) {
|
|
24635
|
+
try {
|
|
24636
|
+
db2?.close();
|
|
24637
|
+
} finally {
|
|
24638
|
+
rmSync(directory3, { recursive: true, force: true });
|
|
24639
|
+
}
|
|
24640
|
+
throw error62;
|
|
24641
|
+
}
|
|
24642
|
+
}
|
|
24643
|
+
const result = read2(copy.db);
|
|
24644
|
+
if (!pinned && sqliteRevision(path) !== revision2) throw new SqliteSnapshotChangedError("History database changed during reading; import again.");
|
|
24645
|
+
return result;
|
|
24646
|
+
}
|
|
24647
|
+
function hasTable(db2, name) {
|
|
24648
|
+
const row = db2.prepare("SELECT sql FROM sqlite_master WHERE type='table' AND name=?").get(name);
|
|
24649
|
+
return typeof row?.sql === "string" && !/CREATE\s+VIRTUAL/i.test(row.sql);
|
|
24650
|
+
}
|
|
24651
|
+
var copies, SqliteSnapshotChangedError, SqliteSnapshotFileError, close, fingerprint2;
|
|
24652
|
+
var init_sqlite_snapshot = __esm({
|
|
24653
|
+
"server/adapters/sqlite-snapshot.ts"() {
|
|
24654
|
+
"use strict";
|
|
24655
|
+
init_common();
|
|
24656
|
+
copies = /* @__PURE__ */ new Map();
|
|
24657
|
+
SqliteSnapshotChangedError = class extends Error {
|
|
24658
|
+
};
|
|
24659
|
+
SqliteSnapshotFileError = class extends Error {
|
|
24660
|
+
};
|
|
24661
|
+
close = (path) => {
|
|
24662
|
+
const copy = copies.get(path);
|
|
24663
|
+
if (!copy) return;
|
|
24664
|
+
copies.delete(path);
|
|
24665
|
+
try {
|
|
24666
|
+
copy.db.close();
|
|
24667
|
+
} finally {
|
|
24668
|
+
rmSync(copy.directory, { recursive: true, force: true });
|
|
24669
|
+
}
|
|
24670
|
+
};
|
|
24671
|
+
process.once("exit", () => {
|
|
24672
|
+
for (const path of copies.keys()) close(path);
|
|
24673
|
+
});
|
|
24674
|
+
fingerprint2 = (path, files) => digest([path, ...files.map((s) => s && [s.dev, s.ino, s.size, s.mtimeMs, s.ctimeMs])]);
|
|
24675
|
+
}
|
|
24676
|
+
});
|
|
24677
|
+
|
|
24678
|
+
// server/adapters/sqlite-histories.ts
|
|
24679
|
+
import { lstat as lstat2 } from "node:fs/promises";
|
|
24680
|
+
function consume(bytes2, records = 0) {
|
|
24681
|
+
if (!budget) return;
|
|
24682
|
+
budget.bytes += bytes2;
|
|
24683
|
+
budget.records += records;
|
|
24684
|
+
if (budget.bytes > 64e6 || budget.records > 5e4) throw new Error("Session exceeds the 64 MB / 50,000-record snapshot limit.");
|
|
24685
|
+
}
|
|
24686
|
+
function parseHistory(source, db2, row, path) {
|
|
24687
|
+
const previous = budget;
|
|
24688
|
+
budget = { bytes: 0, records: 0 };
|
|
24689
|
+
try {
|
|
24690
|
+
consume(rowBytes(row), 1);
|
|
24691
|
+
const history = source.parse(db2, row, path);
|
|
24692
|
+
if (history && history.messages.length > 5e4) throw new Error("Session exceeds the 50,000-message limit.");
|
|
24693
|
+
return history;
|
|
24694
|
+
} finally {
|
|
24695
|
+
budget = previous;
|
|
24696
|
+
}
|
|
24697
|
+
}
|
|
24698
|
+
function columns(db2, table2) {
|
|
24699
|
+
if (!/^[a-z_][a-z0-9_]*$/.test(table2) || !hasTable(db2, table2)) throw new Error(`Unsupported history table: ${table2}.`);
|
|
24700
|
+
return new Set(db2.prepare(`PRAGMA table_info("${table2}")`).all().map((r) => String(r.name)));
|
|
24701
|
+
}
|
|
24702
|
+
function rows(db2, table2, fields3, filter, order, limit = 5e4) {
|
|
24703
|
+
const available = columns(db2, table2);
|
|
24704
|
+
for (const name of [...fields3, ...filter ? [filter[0]] : [], ...order ? [order] : []]) if (!/^[a-zA-Z_][\w]*$/.test(name)) throw new Error("Invalid history column.");
|
|
24705
|
+
if (filter && !available.has(filter[0])) throw new Error("Unsupported history relation.");
|
|
24706
|
+
const size = (f) => `length(CAST("${f}" AS BLOB))`;
|
|
24707
|
+
const select = fields3.map((f) => available.has(f) ? `CASE WHEN ${size(f)}<=32000000 THEN "${f}" END AS "${f}"` : `NULL AS "${f}"`).join(",");
|
|
24708
|
+
const oversized = fields3.filter((f) => available.has(f)).map((f) => `COALESCE(${size(f)},0)>32000000`).join(" OR ") || "0";
|
|
24709
|
+
const query2 = `SELECT ${select}, (${oversized}) AS __sessiongraph_oversized FROM "${table2}"${filter ? ` WHERE "${filter[0]}"=?` : ""}${order && available.has(order) ? ` ORDER BY "${order}"` : ""} LIMIT ${limit + 1}`;
|
|
24710
|
+
const result = [];
|
|
24711
|
+
let bytes2 = 0;
|
|
24712
|
+
for (const row of db2.prepare(query2).iterate(...filter ? [filter[1]] : [])) {
|
|
24713
|
+
if (row.__sessiongraph_oversized) throw new Error("History field exceeds the 32 MB snapshot limit.");
|
|
24714
|
+
delete row.__sessiongraph_oversized;
|
|
24715
|
+
const size2 = rowBytes(row);
|
|
24716
|
+
bytes2 += size2;
|
|
24717
|
+
consume(size2, 1);
|
|
24718
|
+
if (bytes2 > 64e6 || result.length >= limit) throw new Error("History exceeds the 64 MB / record-count query limit.");
|
|
24719
|
+
result.push(row);
|
|
24720
|
+
}
|
|
24721
|
+
return result;
|
|
24722
|
+
}
|
|
24723
|
+
function sqliteJSON(value) {
|
|
24724
|
+
if (value instanceof Uint8Array) {
|
|
24725
|
+
const expanded = expandHistory(Buffer.from(value), Math.max(1, Math.min(32e6, 64e6 - (budget?.bytes || 0))));
|
|
24726
|
+
consume(expanded.byteLength);
|
|
24727
|
+
return JSON.parse(expanded.toString("utf8"));
|
|
24728
|
+
}
|
|
24729
|
+
if (typeof value === "string") return JSON.parse(value);
|
|
24730
|
+
throw new Error("Missing or oversized history payload.");
|
|
24731
|
+
}
|
|
24732
|
+
function optionalJSON(value) {
|
|
24733
|
+
return value == null || value === "" ? {} : sqliteJSON(value);
|
|
24734
|
+
}
|
|
24735
|
+
function sqliteHistoryAdapter(source) {
|
|
24736
|
+
const metadata2 = /* @__PURE__ */ new Map();
|
|
24737
|
+
return {
|
|
24738
|
+
id: source.id,
|
|
24739
|
+
name: source.name,
|
|
24740
|
+
description: source.description || "Local session database",
|
|
24741
|
+
capabilities: { history: source.history !== false, forks: false, children: false, files: false },
|
|
24742
|
+
async detect() {
|
|
24743
|
+
return (await source.paths()).length > 0;
|
|
24744
|
+
},
|
|
24745
|
+
async discover() {
|
|
24746
|
+
const sessions = /* @__PURE__ */ new Map(), errors = [], blocked = [];
|
|
24747
|
+
let unavailable = false;
|
|
24748
|
+
for (const path of await source.paths()) {
|
|
24749
|
+
try {
|
|
24750
|
+
const snapshot2 = sqliteRevision(path), rev = digest([source.version || 2, source.id, snapshot2]);
|
|
24751
|
+
let cached3 = metadata2.get(path);
|
|
24752
|
+
if (!cached3 || cached3.revision !== rev) {
|
|
24753
|
+
cached3 = withSqliteSnapshot(path, (db2) => {
|
|
24754
|
+
const table2 = typeof source.table === "string" ? source.table : source.table(db2);
|
|
24755
|
+
const values2 = rows(db2, table2, source.fields, void 0, source.key, 2e4), found = [];
|
|
24756
|
+
const blocked2 = [], errors2 = [];
|
|
24757
|
+
let failed = 0;
|
|
24758
|
+
for (const row of values2) {
|
|
24759
|
+
try {
|
|
24760
|
+
const h3 = parseHistory(source, db2, row, path);
|
|
24761
|
+
if (!h3) continue;
|
|
24762
|
+
if (source.history !== false && !h3.messages.length) {
|
|
24763
|
+
blocked2.push(identity(source.id, String(row[source.key])));
|
|
24764
|
+
continue;
|
|
24765
|
+
}
|
|
24766
|
+
if (!h3.nativeID || h3.nativeID.length > 512) throw new Error("Missing native session identity.");
|
|
24767
|
+
const created = time3(h3.session?.created) || h3.messages.map((m) => time3(m.time)).find(Boolean);
|
|
24768
|
+
if (!created) throw new Error("Session has no recorded creation or message date.");
|
|
24769
|
+
const session = { ...blankSession(source.id, h3.nativeID), ...h3.session, created };
|
|
24770
|
+
session.id = identity(source.id, h3.nativeID);
|
|
24771
|
+
session.nativeID = h3.nativeID;
|
|
24772
|
+
session.source = source.id;
|
|
24773
|
+
session.directory = text3(session.directory);
|
|
24774
|
+
session.projectID = project(source.id, session.directory).id;
|
|
24775
|
+
session.agent ||= source.name;
|
|
24776
|
+
session.updated ||= created;
|
|
24777
|
+
session.parentID = h3.parent ? identity(source.id, h3.parent) : void 0;
|
|
24778
|
+
session.forkID = h3.fork ? identity(source.id, h3.fork) : void 0;
|
|
24779
|
+
if (!session.title || session.title === "Untitled session") session.title = h3.messages.flatMap((m) => m.role === "user" ? m.fragments.filter((f) => f.kind === "You").map((f) => f.text) : []).find(Boolean)?.replace(/\s+/g, " ").slice(0, 180) || `${source.name} session`;
|
|
24780
|
+
found.push({ session, revision: rev, locator: { path, snapshot: snapshot2, table: table2, key: String(row[source.key]) } });
|
|
24781
|
+
} catch {
|
|
24782
|
+
blocked2.push(identity(source.id, String(row[source.key])));
|
|
24783
|
+
failed++;
|
|
24784
|
+
}
|
|
24785
|
+
}
|
|
24786
|
+
if (failed) errors2.push(`${source.name}: Skipped ${failed} unreadable, undated, unsupported, or oversized ${failed === 1 ? "session" : "sessions"}.`);
|
|
24787
|
+
return { revision: rev, candidates: found, blocked: blocked2, errors: errors2 };
|
|
24788
|
+
}, snapshot2);
|
|
24789
|
+
metadata2.set(path, cached3);
|
|
24790
|
+
}
|
|
24791
|
+
errors.push(...cached3.errors);
|
|
24792
|
+
blocked.push(...cached3.blocked);
|
|
24793
|
+
for (const c of cached3.candidates) {
|
|
24794
|
+
const old = sessions.get(c.session.id);
|
|
24795
|
+
if (!old || c.session.updated > old.session.updated) sessions.set(c.session.id, c);
|
|
24796
|
+
}
|
|
24797
|
+
} catch (error62) {
|
|
24798
|
+
unavailable = true;
|
|
24799
|
+
const detail = error62 instanceof SqliteSnapshotFileError || error62 instanceof SqliteSnapshotChangedError ? error62.message : "Could not read a history database.";
|
|
24800
|
+
errors.push(`${source.name}: ${detail}`);
|
|
24801
|
+
}
|
|
24802
|
+
}
|
|
24803
|
+
const values = [...sessions.values()];
|
|
24804
|
+
return { sessions: values, projects: [...new Map(values.map((c) => {
|
|
24805
|
+
const p = project(source.id, c.session.directory);
|
|
24806
|
+
return [p.id, p];
|
|
24807
|
+
})).values()], warnings: [], errors, blocked, unavailable };
|
|
24808
|
+
},
|
|
24809
|
+
async read(candidate, cursor2) {
|
|
24810
|
+
if (cursor2) throw new Error("Invalid SQLite history cursor.");
|
|
24811
|
+
const { path, snapshot: snapshot2, key } = candidate.locator;
|
|
24812
|
+
return withSqliteSnapshot(path, (db2) => {
|
|
24813
|
+
const table2 = typeof source.table === "string" ? source.table : source.table(db2);
|
|
24814
|
+
const row = rows(db2, table2, source.fields, [source.key, key], void 0, 1)[0];
|
|
24815
|
+
if (!row) throw new Error("Session metadata is unavailable.");
|
|
24816
|
+
const history = parseHistory(source, db2, row, path);
|
|
24817
|
+
if (!history || history.nativeID !== candidate.session.nativeID) throw new Error("Session identity changed.");
|
|
24818
|
+
if (source.history !== false && !history.messages.length) throw new Error("No readable conversation.");
|
|
24819
|
+
return { messages: history.messages, partial: Boolean(history.partial || history.messages.some((m) => m.partial)), note: history.note };
|
|
24820
|
+
}, snapshot2);
|
|
24821
|
+
}
|
|
24822
|
+
};
|
|
24823
|
+
}
|
|
24824
|
+
async function existingDatabases(paths2) {
|
|
24825
|
+
const found = [];
|
|
24826
|
+
for (const path of new Set(paths2)) {
|
|
24827
|
+
try {
|
|
24828
|
+
if ((await lstat2(path)).isFile()) found.push(path);
|
|
24829
|
+
} catch (e10) {
|
|
24830
|
+
if (e10.code !== "ENOENT") throw e10;
|
|
24831
|
+
}
|
|
24832
|
+
}
|
|
24833
|
+
return found;
|
|
24834
|
+
}
|
|
24835
|
+
function combineAdapters(parts) {
|
|
24836
|
+
const first = parts[0];
|
|
24837
|
+
return {
|
|
24838
|
+
...first,
|
|
24839
|
+
async detect() {
|
|
24840
|
+
for (const p of parts) if (await p.detect().catch(() => false)) return true;
|
|
24841
|
+
return false;
|
|
24842
|
+
},
|
|
24843
|
+
async discover() {
|
|
24844
|
+
const sessions = /* @__PURE__ */ new Map(), projects = /* @__PURE__ */ new Map(), warnings = [], errors = [], blocked = /* @__PURE__ */ new Set();
|
|
24845
|
+
for (const [i, part] of parts.entries()) {
|
|
24846
|
+
let result;
|
|
24847
|
+
try {
|
|
24848
|
+
if (!await part.detect()) continue;
|
|
24849
|
+
result = await part.discover();
|
|
24850
|
+
} catch {
|
|
24851
|
+
errors.push(`${part.name}: Could not read a history source.`);
|
|
24852
|
+
break;
|
|
24853
|
+
}
|
|
24854
|
+
warnings.push(...result.warnings);
|
|
24855
|
+
if (result.errors?.length) errors.push(...result.errors);
|
|
24856
|
+
else if (result.unavailable) errors.push(`${part.name}: History unavailable.`);
|
|
24857
|
+
for (const id3 of result.blocked || []) blocked.add(id3);
|
|
24858
|
+
for (const p of result.projects) projects.set(p.id, p);
|
|
24859
|
+
for (const c of result.sessions) if (!blocked.has(c.session.id) && !sessions.has(c.session.id)) sessions.set(c.session.id, { ...c, revision: digest([i, c.revision]), locator: { ...c.locator, representation: String(i), originalRevision: c.revision } });
|
|
24860
|
+
if (result.unavailable) break;
|
|
24861
|
+
}
|
|
24862
|
+
return { sessions: [...sessions.values()], projects: [...projects.values()], warnings, errors };
|
|
24863
|
+
},
|
|
24864
|
+
async read(candidate, cursor2) {
|
|
24865
|
+
const index = Number(candidate.locator.representation);
|
|
24866
|
+
if (!Number.isInteger(index) || !parts[index]) throw new Error("Invalid history representation.");
|
|
24867
|
+
return parts[index].read({ ...candidate, revision: candidate.locator.originalRevision }, cursor2);
|
|
24868
|
+
}
|
|
24869
|
+
};
|
|
24870
|
+
}
|
|
24871
|
+
var budget, rowBytes;
|
|
24872
|
+
var init_sqlite_histories = __esm({
|
|
24873
|
+
"server/adapters/sqlite-histories.ts"() {
|
|
24874
|
+
"use strict";
|
|
24875
|
+
init_common();
|
|
24876
|
+
init_local_files();
|
|
24877
|
+
init_sqlite_snapshot();
|
|
24878
|
+
init_compressed();
|
|
24879
|
+
rowBytes = (row) => Object.values(row).reduce((n, v3) => n + (typeof v3 === "string" ? Buffer.byteLength(v3) : v3 instanceof Uint8Array ? v3.byteLength : 8), 0);
|
|
24880
|
+
}
|
|
24881
|
+
});
|
|
24882
|
+
|
|
24883
|
+
// server/adapters/opencode-v1.ts
|
|
24884
|
+
function openCodeV1Message(body, parts) {
|
|
24885
|
+
const content = [], files = [];
|
|
24886
|
+
let start, end;
|
|
24887
|
+
for (const part of parts) {
|
|
24888
|
+
if (part.type === "step-start") {
|
|
24889
|
+
start = text3(part.snapshot) || void 0;
|
|
24890
|
+
continue;
|
|
24891
|
+
}
|
|
24892
|
+
if (part.type === "step-finish") {
|
|
24893
|
+
end = text3(part.snapshot) || void 0;
|
|
24894
|
+
continue;
|
|
24895
|
+
}
|
|
24896
|
+
if (part.type === "patch") {
|
|
24897
|
+
files.push(...Array.isArray(part.files) ? part.files.filter((value) => typeof value === "string") : []);
|
|
24898
|
+
continue;
|
|
24899
|
+
}
|
|
24900
|
+
if (part.type === "snapshot") continue;
|
|
24901
|
+
const timing = object4(part.time), state2 = object4(part.state), toolTime = object4(state2.time);
|
|
24902
|
+
content.push(part.type === "tool" ? {
|
|
24903
|
+
...part,
|
|
24904
|
+
name: part.tool,
|
|
24905
|
+
time: { created: toolTime.start, completed: toolTime.end },
|
|
24906
|
+
state: {
|
|
24907
|
+
...state2,
|
|
24908
|
+
content: typeof state2.output === "string" ? [{ type: "text", text: state2.output }] : [],
|
|
24909
|
+
metadata: { ...object4(state2.metadata), cwd: state2.metadata?.cwd || body.path?.cwd }
|
|
24910
|
+
}
|
|
24911
|
+
} : { ...part, time: { created: timing.start, completed: timing.end } });
|
|
24912
|
+
}
|
|
24913
|
+
const prompt = parts.filter((part) => part.type === "text").map((part) => text3(part.text)).join("\n");
|
|
24914
|
+
const type = body.role === "user" && !prompt && parts.some((part) => part.type === "compaction") ? "compaction" : body.role;
|
|
24915
|
+
return {
|
|
24916
|
+
...body,
|
|
24917
|
+
type,
|
|
24918
|
+
cwd: body.path?.cwd,
|
|
24919
|
+
model: body.role === "assistant" ? { id: body.modelID, providerID: body.providerID } : { ...object4(body.model), id: body.model?.modelID },
|
|
24920
|
+
text: body.role === "user" ? prompt : void 0,
|
|
24921
|
+
files: parts.filter((part) => part.type === "file").map((part) => ({ name: part.filename, uri: part.url })),
|
|
24922
|
+
content: body.role === "user" ? [] : content,
|
|
24923
|
+
snapshot: files.length || start || end ? { files, start, end } : void 0
|
|
24924
|
+
};
|
|
24925
|
+
}
|
|
24926
|
+
var init_opencode_v1 = __esm({
|
|
24927
|
+
"server/adapters/opencode-v1.ts"() {
|
|
24928
|
+
"use strict";
|
|
24929
|
+
init_local_files();
|
|
24930
|
+
}
|
|
24931
|
+
});
|
|
24932
|
+
|
|
24720
24933
|
// server/adapters/opencode.ts
|
|
24934
|
+
import { lstat as lstat3, readdir as readdir2 } from "node:fs/promises";
|
|
24935
|
+
import { join as join5 } from "node:path";
|
|
24721
24936
|
function openCodeMessage(raw, sessionID) {
|
|
24722
24937
|
const content = extractContent([raw]), detail = summarizeMessages(sessionID, [raw], null);
|
|
24723
24938
|
const message2 = {
|
|
@@ -24736,7 +24951,149 @@ function openCodeMessage(raw, sessionID) {
|
|
|
24736
24951
|
message2.events = opencodeEvents(raw, message2);
|
|
24737
24952
|
return message2;
|
|
24738
24953
|
}
|
|
24739
|
-
|
|
24954
|
+
async function openCodeDatabases() {
|
|
24955
|
+
const override = sourcePath("opencode") || process.env.SESSIONGRAPH_OPENCODE_HISTORY_DIR || process.env.OPENCODE_DB;
|
|
24956
|
+
const root3 = override || dataPath("opencode");
|
|
24957
|
+
try {
|
|
24958
|
+
const info = await lstat3(root3);
|
|
24959
|
+
if (info.isFile()) return [root3];
|
|
24960
|
+
if (!info.isDirectory()) return [];
|
|
24961
|
+
const files = (await readdir2(root3)).filter((name) => /^opencode(?:[-.][\w.-]+)?\.db$/.test(name)).sort((a, b) => a === "opencode.db" ? -1 : b === "opencode.db" ? 1 : a.localeCompare(b));
|
|
24962
|
+
if (files.length > 20) throw new Error("Too many OpenCode databases. Choose a database file with a source path override.");
|
|
24963
|
+
const paths2 = [];
|
|
24964
|
+
for (const file2 of files) {
|
|
24965
|
+
const path = join5(root3, file2);
|
|
24966
|
+
if ((await lstat3(path)).isFile()) paths2.push(path);
|
|
24967
|
+
}
|
|
24968
|
+
return paths2;
|
|
24969
|
+
} catch (error62) {
|
|
24970
|
+
if (error62.code === "ENOENT") return [];
|
|
24971
|
+
throw error62;
|
|
24972
|
+
}
|
|
24973
|
+
}
|
|
24974
|
+
function schemas(db2) {
|
|
24975
|
+
const result = [];
|
|
24976
|
+
for (const version2 of ["2", "1"]) {
|
|
24977
|
+
const session = version2 === "2" ? "session_v2" : "session", message2 = version2 === "2" ? "session_message" : "message", part = version2 === "2" ? "session_part" : "part";
|
|
24978
|
+
if (!hasTable(db2, session)) continue;
|
|
24979
|
+
for (const [table2, required2] of [[session, ["id", "time_created", "time_updated"]], [message2, ["id", "session_id", "data", "time_created", ...version2 === "2" ? ["type", "seq"] : []]]]) {
|
|
24980
|
+
const names = columns(db2, table2);
|
|
24981
|
+
if (required2.some((name) => !names.has(name))) throw new Error("Unsupported OpenCode database schema.");
|
|
24982
|
+
}
|
|
24983
|
+
if (hasTable(db2, part)) {
|
|
24984
|
+
const names = columns(db2, part);
|
|
24985
|
+
if (["message_id", "data", version2 === "2" ? "ordinal" : "id"].some((name) => !names.has(name))) throw new Error("Unsupported OpenCode part schema.");
|
|
24986
|
+
} else if (version2 === "1") throw new Error("OpenCode V1 parts are unavailable.");
|
|
24987
|
+
result.push({ version: version2, session, message: message2, part: hasTable(db2, part) ? part : void 0 });
|
|
24988
|
+
}
|
|
24989
|
+
if (!result.length) throw new Error("Unsupported OpenCode database schema.");
|
|
24990
|
+
return result;
|
|
24991
|
+
}
|
|
24992
|
+
function historyRevisions(db2, schema) {
|
|
24993
|
+
const result = /* @__PURE__ */ new Map();
|
|
24994
|
+
for (const table2 of [schema.message, schema.part].filter((value) => Boolean(value))) {
|
|
24995
|
+
const names = columns(db2, table2);
|
|
24996
|
+
if (!names.has("session_id")) continue;
|
|
24997
|
+
const updated = names.has("time_updated") ? "MAX(time_updated)" : "NULL";
|
|
24998
|
+
for (const row of db2.prepare(`SELECT session_id, COUNT(*) AS count, ${updated} AS updated FROM "${table2}" GROUP BY session_id`).iterate()) {
|
|
24999
|
+
const id3 = text3(row.session_id);
|
|
25000
|
+
result.set(id3, [...result.get(id3) || [], row.count, row.updated]);
|
|
25001
|
+
}
|
|
25002
|
+
}
|
|
25003
|
+
return result;
|
|
25004
|
+
}
|
|
25005
|
+
function discoverDatabase(db2, path, snapshot2) {
|
|
25006
|
+
const sessions = /* @__PURE__ */ new Map(), projects = /* @__PURE__ */ new Map(), errors = [];
|
|
25007
|
+
const seen = /* @__PURE__ */ new Set();
|
|
25008
|
+
if (hasTable(db2, "project")) {
|
|
25009
|
+
for (const row of rows(db2, "project", ["id", "name", "worktree", "sandboxes"], void 0, "id", 2e4)) {
|
|
25010
|
+
try {
|
|
25011
|
+
const p = project("opencode", text3(row.worktree)), sandboxes = optionalJSON(row.sandboxes);
|
|
25012
|
+
p.id = identity("opencode", text3(row.id));
|
|
25013
|
+
p.name = text3(row.name) || p.name;
|
|
25014
|
+
p.worktrees = Array.isArray(sandboxes) ? sandboxes.filter((value) => typeof value === "string") : [];
|
|
25015
|
+
projects.set(p.id, p);
|
|
25016
|
+
} catch {
|
|
25017
|
+
errors.push("OpenCode: Skipped unreadable project metadata.");
|
|
25018
|
+
}
|
|
25019
|
+
}
|
|
25020
|
+
}
|
|
25021
|
+
for (const schema of schemas(db2)) {
|
|
25022
|
+
const revisions = historyRevisions(db2, schema);
|
|
25023
|
+
for (const row of rows(db2, schema.session, sessionFields, void 0, "id", 2e4)) {
|
|
25024
|
+
const nativeID = text3(row.id), id3 = identity("opencode", nativeID);
|
|
25025
|
+
if (seen.has(id3)) continue;
|
|
25026
|
+
seen.add(id3);
|
|
25027
|
+
if (!nativeID || nativeID.length > 512 || !time3(row.time_created)) {
|
|
25028
|
+
errors.push("OpenCode: Skipped invalid session metadata.");
|
|
25029
|
+
continue;
|
|
25030
|
+
}
|
|
25031
|
+
const session = {
|
|
25032
|
+
...blankSession("opencode", nativeID, text3(row.directory)),
|
|
25033
|
+
title: text3(row.title) || "Untitled session",
|
|
25034
|
+
created: time3(row.time_created),
|
|
25035
|
+
updated: time3(row.time_updated) || time3(row.time_created),
|
|
25036
|
+
archived: Boolean(row.time_archived),
|
|
25037
|
+
parentID: text3(row.parent_id) ? identity("opencode", text3(row.parent_id)) : void 0,
|
|
25038
|
+
forkID: text3(row.fork_session_id) ? identity("opencode", text3(row.fork_session_id)) : void 0
|
|
25039
|
+
};
|
|
25040
|
+
try {
|
|
25041
|
+
const model = object4(optionalJSON(row.model));
|
|
25042
|
+
session.model = text3(model.id) || "Unknown model";
|
|
25043
|
+
session.provider = text3(model.providerID);
|
|
25044
|
+
session.agent = text3(row.agent) || "build";
|
|
25045
|
+
session.outcome = text3(row.idle_outcome) || void 0;
|
|
25046
|
+
if (schema.version === "1") {
|
|
25047
|
+
const valid = `length(CAST(data AS BLOB))<=${MAX_JSON} AND json_valid(data)`;
|
|
25048
|
+
const latest = db2.prepare(`SELECT
|
|
25049
|
+
CASE WHEN ${valid} THEN substr(json_extract(data,'$.modelID'),1,256) END AS model,
|
|
25050
|
+
CASE WHEN ${valid} THEN substr(json_extract(data,'$.providerID'),1,256) END AS provider,
|
|
25051
|
+
CASE WHEN ${valid} THEN substr(json_extract(data,'$.model.modelID'),1,256) END AS user_model,
|
|
25052
|
+
CASE WHEN ${valid} THEN substr(json_extract(data,'$.model.providerID'),1,256) END AS user_provider,
|
|
25053
|
+
CASE WHEN ${valid} THEN substr(json_extract(data,'$.agent'),1,256) END AS agent
|
|
25054
|
+
FROM message WHERE session_id=? ORDER BY time_created DESC, id DESC LIMIT 1`).get(nativeID);
|
|
25055
|
+
session.model = text3(latest?.model || latest?.user_model) || session.model;
|
|
25056
|
+
session.provider = text3(latest?.provider || latest?.user_provider);
|
|
25057
|
+
session.agent = text3(latest?.agent) || session.agent;
|
|
25058
|
+
}
|
|
25059
|
+
if (schema.version === "2") {
|
|
25060
|
+
session.usage = sessionUsage(openCodeUsage({
|
|
25061
|
+
input: row.tokens_input,
|
|
25062
|
+
output: row.tokens_output,
|
|
25063
|
+
reasoning: row.tokens_reasoning,
|
|
25064
|
+
cache: { read: row.tokens_cache_read, write: row.tokens_cache_write }
|
|
25065
|
+
}, row.cost));
|
|
25066
|
+
session.tokens = session.usage?.total ?? null;
|
|
25067
|
+
session.cost = session.usage?.cost ?? null;
|
|
25068
|
+
}
|
|
25069
|
+
const nativeProject = identity("opencode", text3(row.project_id));
|
|
25070
|
+
const p = projects.get(nativeProject) || project("opencode", session.directory);
|
|
25071
|
+
session.projectID = p.id;
|
|
25072
|
+
projects.set(p.id, p);
|
|
25073
|
+
sessions.set(id3, {
|
|
25074
|
+
session,
|
|
25075
|
+
revision: digest([6, schema.version, row, revisions.get(nativeID)]),
|
|
25076
|
+
locator: { path, snapshot: snapshot2, version: schema.version }
|
|
25077
|
+
});
|
|
25078
|
+
} catch {
|
|
25079
|
+
errors.push("OpenCode: Skipped unreadable session metadata.");
|
|
25080
|
+
}
|
|
25081
|
+
}
|
|
25082
|
+
}
|
|
25083
|
+
return { sessions: [...sessions.values()], projects: [...projects.values()], warnings: [], errors };
|
|
25084
|
+
}
|
|
25085
|
+
function payloadRows(db2, query2, values, budget2) {
|
|
25086
|
+
const result = [];
|
|
25087
|
+
for (const row of db2.prepare(query2).iterate(...values)) {
|
|
25088
|
+
if (typeof row.data !== "string") throw new Error("OpenCode history contains a missing or oversized JSON field (4 MB limit).");
|
|
25089
|
+
budget2.bytes += Buffer.byteLength(row.data);
|
|
25090
|
+
budget2.records++;
|
|
25091
|
+
if (budget2.bytes > 32e6 || budget2.records > 5e4) throw new Error("OpenCode history page exceeds the 32 MB / 50,000-record limit.");
|
|
25092
|
+
result.push(row);
|
|
25093
|
+
}
|
|
25094
|
+
return result;
|
|
25095
|
+
}
|
|
25096
|
+
var PAGE, MAX_JSON, sessionFields, opencodeAdapter;
|
|
24740
25097
|
var init_opencode2 = __esm({
|
|
24741
25098
|
"server/adapters/opencode.ts"() {
|
|
24742
25099
|
"use strict";
|
|
@@ -24745,46 +25102,95 @@ var init_opencode2 = __esm({
|
|
|
24745
25102
|
init_common();
|
|
24746
25103
|
init_opencode_events();
|
|
24747
25104
|
init_usage();
|
|
25105
|
+
init_harness_paths();
|
|
25106
|
+
init_source_paths();
|
|
25107
|
+
init_sqlite_histories();
|
|
25108
|
+
init_sqlite_snapshot();
|
|
25109
|
+
init_local_files();
|
|
25110
|
+
init_opencode_v1();
|
|
25111
|
+
PAGE = 60;
|
|
25112
|
+
MAX_JSON = 4e6;
|
|
25113
|
+
sessionFields = [
|
|
25114
|
+
"id",
|
|
25115
|
+
"project_id",
|
|
25116
|
+
"parent_id",
|
|
25117
|
+
"fork_session_id",
|
|
25118
|
+
"directory",
|
|
25119
|
+
"title",
|
|
25120
|
+
"time_created",
|
|
25121
|
+
"time_updated",
|
|
25122
|
+
"time_archived",
|
|
25123
|
+
"model",
|
|
25124
|
+
"agent",
|
|
25125
|
+
"cost",
|
|
25126
|
+
"tokens_input",
|
|
25127
|
+
"tokens_output",
|
|
25128
|
+
"tokens_reasoning",
|
|
25129
|
+
"tokens_cache_read",
|
|
25130
|
+
"tokens_cache_write",
|
|
25131
|
+
"idle_outcome"
|
|
25132
|
+
];
|
|
24748
25133
|
opencodeAdapter = {
|
|
24749
25134
|
id: "opencode",
|
|
24750
25135
|
name: "OpenCode",
|
|
24751
|
-
description: "Local
|
|
25136
|
+
description: "Local SQLite history \xB7 V1 and V2 \xB7 no running service needed",
|
|
24752
25137
|
capabilities: { history: true, forks: true, children: true, files: true },
|
|
24753
25138
|
async detect() {
|
|
24754
|
-
|
|
24755
|
-
await api("/api/info", AbortSignal.timeout(3e3));
|
|
24756
|
-
return true;
|
|
24757
|
-
} catch {
|
|
24758
|
-
return false;
|
|
24759
|
-
}
|
|
25139
|
+
return (await openCodeDatabases()).length > 0;
|
|
24760
25140
|
},
|
|
24761
25141
|
async discover() {
|
|
24762
|
-
const
|
|
24763
|
-
|
|
24764
|
-
|
|
24765
|
-
|
|
24766
|
-
|
|
24767
|
-
|
|
24768
|
-
|
|
24769
|
-
|
|
24770
|
-
|
|
24771
|
-
|
|
24772
|
-
|
|
24773
|
-
|
|
24774
|
-
|
|
24775
|
-
|
|
25142
|
+
const sessions = /* @__PURE__ */ new Map(), projects = /* @__PURE__ */ new Map(), errors = [];
|
|
25143
|
+
for (const path of await openCodeDatabases()) {
|
|
25144
|
+
try {
|
|
25145
|
+
const snapshot2 = sqliteRevision(path);
|
|
25146
|
+
const found = withSqliteSnapshot(path, (db2) => discoverDatabase(db2, path, snapshot2), snapshot2);
|
|
25147
|
+
for (const candidate of found.sessions) {
|
|
25148
|
+
const previous = sessions.get(candidate.session.id);
|
|
25149
|
+
if (!previous || candidate.locator.version > previous.locator.version || candidate.locator.version === previous.locator.version && candidate.session.updated > previous.session.updated) sessions.set(candidate.session.id, candidate);
|
|
25150
|
+
}
|
|
25151
|
+
for (const p of found.projects) projects.set(p.id, p);
|
|
25152
|
+
errors.push(...found.errors);
|
|
25153
|
+
} catch (error62) {
|
|
25154
|
+
errors.push(`OpenCode: ${error62 instanceof Error ? error62.message : "Could not read a history database."}`);
|
|
25155
|
+
}
|
|
25156
|
+
}
|
|
25157
|
+
return { sessions: [...sessions.values()], projects: [...projects.values()], warnings: [], errors: [...new Set(errors)] };
|
|
24776
25158
|
},
|
|
24777
25159
|
async read(candidate, cursor2) {
|
|
24778
|
-
|
|
24779
|
-
|
|
24780
|
-
|
|
24781
|
-
|
|
24782
|
-
|
|
24783
|
-
|
|
24784
|
-
const
|
|
24785
|
-
|
|
24786
|
-
|
|
24787
|
-
|
|
25160
|
+
if (cursor2 && !/^[1-9]\d{0,5}$/.test(cursor2)) throw new Error("Invalid OpenCode history cursor.");
|
|
25161
|
+
const offset = Number(cursor2 || 0);
|
|
25162
|
+
return withSqliteSnapshot(candidate.locator.path, (db2) => {
|
|
25163
|
+
const schema = schemas(db2).find((value) => value.version === candidate.locator.version);
|
|
25164
|
+
if (!schema) throw new Error("OpenCode history schema changed.");
|
|
25165
|
+
const budget2 = { bytes: 0, records: 0 };
|
|
25166
|
+
const data = `CASE WHEN length(CAST(data AS BLOB))<=${MAX_JSON} THEN data END AS data`;
|
|
25167
|
+
const page3 = payloadRows(
|
|
25168
|
+
db2,
|
|
25169
|
+
`SELECT id, time_created, ${schema.version === "2" ? "type" : "NULL AS type"}, ${data}
|
|
25170
|
+
FROM "${schema.message}" WHERE session_id=? ORDER BY ${schema.version === "2" ? "seq DESC" : "time_created DESC, id DESC"} LIMIT ${PAGE + 1} OFFSET ?`,
|
|
25171
|
+
[candidate.session.nativeID, offset],
|
|
25172
|
+
budget2
|
|
25173
|
+
);
|
|
25174
|
+
const messages = page3.slice(0, PAGE).map((row) => {
|
|
25175
|
+
const body = object4(sqliteJSON(row.data));
|
|
25176
|
+
if (schema.version === "1" && !["user", "assistant"].includes(body.role)) throw new Error("Unsupported OpenCode V1 message.");
|
|
25177
|
+
if (schema.version === "2" && !text3(row.type)) throw new Error("Missing OpenCode message type.");
|
|
25178
|
+
const parts = schema.part ? payloadRows(
|
|
25179
|
+
db2,
|
|
25180
|
+
`SELECT ${schema.version === "2" ? "ordinal" : "id"}, ${data} FROM "${schema.part}" WHERE message_id=? ORDER BY ${schema.version === "2" ? "ordinal" : "id"}`,
|
|
25181
|
+
[text3(row.id)],
|
|
25182
|
+
budget2
|
|
25183
|
+
).map((part) => ({ ...object4(sqliteJSON(part.data)), ...schema.version === "1" ? { id: part.id } : {} })) : [];
|
|
25184
|
+
const raw = schema.version === "1" ? openCodeV1Message(body, parts) : { ...body, type: row.type, content: [...parts, ...Array.isArray(body.content) ? body.content : []] };
|
|
25185
|
+
const message2 = openCodeMessage({ ...raw, id: text3(row.id), time: { ...object4(raw.time), created: time3(raw.time?.created) || time3(row.time_created) } }, candidate.session.id);
|
|
25186
|
+
if (schema.version === "1" && candidate.session.model === "Unknown model" && message2.metadata?.model) {
|
|
25187
|
+
candidate.session.model = message2.metadata?.model || candidate.session.model;
|
|
25188
|
+
candidate.session.provider = message2.metadata?.provider || candidate.session.provider;
|
|
25189
|
+
}
|
|
25190
|
+
return message2;
|
|
25191
|
+
});
|
|
25192
|
+
return { messages, cursor: page3.length > PAGE ? String(offset + PAGE) : void 0 };
|
|
25193
|
+
}, candidate.locator.snapshot, true);
|
|
24788
25194
|
}
|
|
24789
25195
|
};
|
|
24790
25196
|
}
|
|
@@ -27026,18 +27432,18 @@ function xD(e10, t, n) {
|
|
|
27026
27432
|
return o;
|
|
27027
27433
|
};
|
|
27028
27434
|
}
|
|
27029
|
-
function
|
|
27435
|
+
function rm2(e10, t) {
|
|
27030
27436
|
return typeof t === "string" && Object.hasOwn(e10, t);
|
|
27031
27437
|
}
|
|
27032
27438
|
function gbe(e10, t) {
|
|
27033
27439
|
let n = new Proxy(Object.create(t && Object.getPrototypeOf(t)), { get: (i, a, l) => {
|
|
27034
|
-
if (!
|
|
27440
|
+
if (!rm2(e10, a)) return Reflect.get(i, a, l);
|
|
27035
27441
|
let c = xD(a, e10[a], s);
|
|
27036
27442
|
if (l === s) Object.defineProperty(s, a, { get: c, configurable: true });
|
|
27037
27443
|
return c();
|
|
27038
|
-
}, set: (i, a, l, c) => !
|
|
27444
|
+
}, set: (i, a, l, c) => !rm2(e10, a) && Reflect.set(i, a, l, c), has: (i, a) => rm2(e10, a) || Reflect.has(i, a) }), r = Object.create(n), o = t === null ? {} : Object.getOwnPropertyDescriptors(t);
|
|
27039
27445
|
for (let [i, a] of Object.entries(o)) {
|
|
27040
|
-
if (
|
|
27446
|
+
if (rm2(e10, i)) continue;
|
|
27041
27447
|
Object.defineProperty(r, i, typeof a.value === "function" ? { ...a, value: { [i](...l) {
|
|
27042
27448
|
return Reflect.apply(Reflect.get(t, i), this, l);
|
|
27043
27449
|
} }[i] } : a);
|
|
@@ -52056,11 +52462,11 @@ ${n.join(`
|
|
|
52056
52462
|
});
|
|
52057
52463
|
|
|
52058
52464
|
// server/adapters/claude-transcripts.ts
|
|
52059
|
-
import { constants as
|
|
52060
|
-
import { lstat, open as
|
|
52061
|
-
import { basename as
|
|
52465
|
+
import { constants as constants4 } from "node:fs";
|
|
52466
|
+
import { lstat as lstat4, open as open3 } from "node:fs/promises";
|
|
52467
|
+
import { basename as basename4 } from "node:path";
|
|
52062
52468
|
async function state(path) {
|
|
52063
|
-
const s = await
|
|
52469
|
+
const s = await lstat4(path);
|
|
52064
52470
|
if (!s.isFile()) throw new Error("Claude transcript must be a regular file.");
|
|
52065
52471
|
return { size: s.size, modified: s.mtimeMs, signature: [s.dev, s.ino, s.size, s.mtimeMs] };
|
|
52066
52472
|
}
|
|
@@ -52078,8 +52484,8 @@ async function claudeRevision(path) {
|
|
|
52078
52484
|
}
|
|
52079
52485
|
async function bytes(path, max) {
|
|
52080
52486
|
const before = await state(path);
|
|
52081
|
-
if (before.size > max) throw new Error(`Claude transcript exceeds the ${max ===
|
|
52082
|
-
const file2 = await
|
|
52487
|
+
if (before.size > max) throw new Error(`Claude transcript exceeds the ${max === MAX_BYTES2 ? "128 MB import" : "metadata size"} limit.`);
|
|
52488
|
+
const file2 = await open3(path, constants4.O_RDONLY | (constants4.O_NOFOLLOW || 0) | (constants4.O_NONBLOCK || 0));
|
|
52083
52489
|
try {
|
|
52084
52490
|
const opened = await file2.stat();
|
|
52085
52491
|
if (!opened.isFile() || opened.dev !== before.signature[0] || opened.ino !== before.signature[1]) throw new Error("Claude transcript changed during import; import again.");
|
|
@@ -52099,7 +52505,7 @@ async function bytes(path, max) {
|
|
|
52099
52505
|
async function claudeTranscript(path, revision2) {
|
|
52100
52506
|
if (await claudeRevision(path) !== revision2) throw new Error("Claude transcript changed during import; import again.");
|
|
52101
52507
|
if (cached2?.path === path && cached2.revision === revision2) return cached2.transcript;
|
|
52102
|
-
const source = await bytes(path,
|
|
52508
|
+
const source = await bytes(path, MAX_BYTES2), entries2 = [], times = /* @__PURE__ */ new Map();
|
|
52103
52509
|
let partial2 = false;
|
|
52104
52510
|
for (const line of source.split("\n")) {
|
|
52105
52511
|
if (!line.trim()) continue;
|
|
@@ -52158,233 +52564,14 @@ function claudeTranscriptStore(transcript, sessionId, agent) {
|
|
|
52158
52564
|
}
|
|
52159
52565
|
};
|
|
52160
52566
|
}
|
|
52161
|
-
var claudeSessionID,
|
|
52567
|
+
var claudeSessionID, MAX_BYTES2, sidecar, cached2;
|
|
52162
52568
|
var init_claude_transcripts = __esm({
|
|
52163
52569
|
"server/adapters/claude-transcripts.ts"() {
|
|
52164
52570
|
"use strict";
|
|
52165
52571
|
init_common();
|
|
52166
52572
|
claudeSessionID = (value) => /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
|
|
52167
|
-
|
|
52168
|
-
sidecar = (path) =>
|
|
52169
|
-
}
|
|
52170
|
-
});
|
|
52171
|
-
|
|
52172
|
-
// server/adapters/compressed.ts
|
|
52173
|
-
import { gunzipSync, zstdDecompressSync } from "node:zlib";
|
|
52174
|
-
function expandHistory(buffer, maxOutputLength) {
|
|
52175
|
-
if (buffer.length >= 4 && buffer.readUInt32LE(0) === 4247762216) return zstdDecompressSync(buffer, { maxOutputLength });
|
|
52176
|
-
if (buffer[0] === 31 && buffer[1] === 139) return gunzipSync(buffer, { maxOutputLength });
|
|
52177
|
-
if (buffer.length > maxOutputLength) throw new Error("Expanded history exceeds the snapshot limit.");
|
|
52178
|
-
return buffer;
|
|
52179
|
-
}
|
|
52180
|
-
var init_compressed = __esm({
|
|
52181
|
-
"server/adapters/compressed.ts"() {
|
|
52182
|
-
"use strict";
|
|
52183
|
-
}
|
|
52184
|
-
});
|
|
52185
|
-
|
|
52186
|
-
// server/adapters/local-files.ts
|
|
52187
|
-
import { constants as constants3 } from "node:fs";
|
|
52188
|
-
import { lstat as lstat2, open as open3, readdir } from "node:fs/promises";
|
|
52189
|
-
import { join as join4, relative as relative2 } from "node:path";
|
|
52190
|
-
async function fileState(path) {
|
|
52191
|
-
try {
|
|
52192
|
-
const s = await lstat2(path);
|
|
52193
|
-
if (!s.isFile()) throw new Error("History must be a regular file, not a symlink.");
|
|
52194
|
-
if (s.size > MAX_BYTES2) throw new Error("History exceeds the 32 MB per-file limit.");
|
|
52195
|
-
return { path, signature: digest([s.size, s.mtimeMs, s.ctimeMs, s.ino]), created: s.birthtimeMs || s.mtimeMs, updated: s.mtimeMs, size: s.size };
|
|
52196
|
-
} catch (error62) {
|
|
52197
|
-
if (error62.code === "ENOENT") return { path, signature: "missing", created: 0, updated: 0, size: 0 };
|
|
52198
|
-
throw error62;
|
|
52199
|
-
}
|
|
52200
|
-
}
|
|
52201
|
-
async function historyFiles(roots2, match2) {
|
|
52202
|
-
const files = [], queue = [];
|
|
52203
|
-
const warnings = [];
|
|
52204
|
-
for (const root3 of new Set(roots2)) {
|
|
52205
|
-
try {
|
|
52206
|
-
if ((await lstat2(root3)).isDirectory()) queue.push({ root: root3, path: root3, depth: 0 });
|
|
52207
|
-
} catch (error62) {
|
|
52208
|
-
if (error62.code !== "ENOENT") warnings.push("A history directory could not be read.");
|
|
52209
|
-
}
|
|
52210
|
-
}
|
|
52211
|
-
let entriesSeen = 0, limited = false;
|
|
52212
|
-
for (let i = 0; i < queue.length && files.length < MAX_FILES && entriesSeen < 1e5; i++) {
|
|
52213
|
-
const { root: root3, path, depth } = queue[i];
|
|
52214
|
-
let entries2;
|
|
52215
|
-
try {
|
|
52216
|
-
entries2 = await readdir(path, { withFileTypes: true });
|
|
52217
|
-
} catch {
|
|
52218
|
-
warnings.push("A history directory could not be read.");
|
|
52219
|
-
continue;
|
|
52220
|
-
}
|
|
52221
|
-
for (const entry of entries2) {
|
|
52222
|
-
if (++entriesSeen > 1e5 || files.length >= MAX_FILES) {
|
|
52223
|
-
limited = true;
|
|
52224
|
-
break;
|
|
52225
|
-
}
|
|
52226
|
-
const file2 = join4(path, entry.name);
|
|
52227
|
-
if (entry.isDirectory()) {
|
|
52228
|
-
if (depth < 6 && queue.length < MAX_FILES) queue.push({ root: root3, path: file2, depth: depth + 1 });
|
|
52229
|
-
else limited = true;
|
|
52230
|
-
}
|
|
52231
|
-
if (entry.isFile() && match2(relative2(root3, file2).split("\\").join("/"))) files.push(file2);
|
|
52232
|
-
}
|
|
52233
|
-
}
|
|
52234
|
-
if (limited) warnings.push("History discovery reached its file, directory, or depth limit.");
|
|
52235
|
-
return { files: [...new Set(files)].sort(), warnings };
|
|
52236
|
-
}
|
|
52237
|
-
function json4(value) {
|
|
52238
|
-
return JSON.parse(value);
|
|
52239
|
-
}
|
|
52240
|
-
function jsonLines(value) {
|
|
52241
|
-
const rows2 = [];
|
|
52242
|
-
let partial2 = false;
|
|
52243
|
-
for (const line of value.split("\n")) {
|
|
52244
|
-
if (!line.trim()) continue;
|
|
52245
|
-
if (rows2.length >= MAX_RECORDS) throw new Error("History exceeds the 50,000-record limit.");
|
|
52246
|
-
if (line.length > 2e6) throw new Error("History contains a record larger than 2 MB.");
|
|
52247
|
-
try {
|
|
52248
|
-
const row = json4(line);
|
|
52249
|
-
if (!row || typeof row !== "object" || Array.isArray(row)) partial2 = true;
|
|
52250
|
-
else rows2.push(row);
|
|
52251
|
-
} catch {
|
|
52252
|
-
partial2 = true;
|
|
52253
|
-
}
|
|
52254
|
-
}
|
|
52255
|
-
return { rows: rows2, partial: partial2 };
|
|
52256
|
-
}
|
|
52257
|
-
function localFileAdapter(source) {
|
|
52258
|
-
const metadata2 = /* @__PURE__ */ new Map();
|
|
52259
|
-
let cached3;
|
|
52260
|
-
const states = (path) => Promise.all([path, ...source.extras?.(path) || []].map(fileState));
|
|
52261
|
-
const revision2 = (values) => digest([1, ...values.filter((_, i) => i === 0 || source.revisionExtras !== false).map((s) => [s.path, s.signature])]);
|
|
52262
|
-
async function load(path, expected, before) {
|
|
52263
|
-
if (revision2(before) !== expected) throw new Error("Session changed during import; import again.");
|
|
52264
|
-
if (cached3?.path === path && cached3.revision === expected) return cached3.history;
|
|
52265
|
-
if (before[0].signature === "missing") throw new Error("History file is unavailable.");
|
|
52266
|
-
if (before.reduce((n, s) => n + s.size, 0) > MAX_BYTES2) throw new Error("Combined history exceeds the 32 MB snapshot limit.");
|
|
52267
|
-
const files = /* @__PURE__ */ new Map();
|
|
52268
|
-
let expanded = 0;
|
|
52269
|
-
for (const s of before.filter((s2) => s2.signature !== "missing")) {
|
|
52270
|
-
const handle = await open3(s.path, constants3.O_RDONLY | (constants3.O_NOFOLLOW || 0));
|
|
52271
|
-
try {
|
|
52272
|
-
const buffer = Buffer.alloc(s.size + 1);
|
|
52273
|
-
let bytes2 = 0;
|
|
52274
|
-
while (bytes2 < buffer.length) {
|
|
52275
|
-
const part = await handle.read(buffer, bytes2, buffer.length - bytes2, bytes2);
|
|
52276
|
-
if (!part.bytesRead) break;
|
|
52277
|
-
bytes2 += part.bytesRead;
|
|
52278
|
-
}
|
|
52279
|
-
if (bytes2 !== s.size) throw new Error("History changed while reading; import again.");
|
|
52280
|
-
const data = expandHistory(buffer.subarray(0, bytes2), MAX_BYTES2);
|
|
52281
|
-
expanded += data.length;
|
|
52282
|
-
if (expanded > MAX_BYTES2) throw new Error("Expanded history exceeds the 32 MB snapshot limit.");
|
|
52283
|
-
files.set(s.path, data.toString("utf8"));
|
|
52284
|
-
} finally {
|
|
52285
|
-
await handle.close();
|
|
52286
|
-
}
|
|
52287
|
-
}
|
|
52288
|
-
if (digest(await states(path)) !== digest(before)) throw new Error("History changed while reading; import again.");
|
|
52289
|
-
const history = source.parse(path, files);
|
|
52290
|
-
if (!history) return;
|
|
52291
|
-
if (source.capabilities.history && !history.messages.length) throw new Error("No readable conversation.");
|
|
52292
|
-
if (!history.nativeID || history.nativeID.length > 512) throw new Error("History has no supported native session identity.");
|
|
52293
|
-
if (history.messages.length > MAX_RECORDS) throw new Error("History exceeds the 50,000-message limit.");
|
|
52294
|
-
cached3 = { path, revision: expected, history };
|
|
52295
|
-
return history;
|
|
52296
|
-
}
|
|
52297
|
-
return {
|
|
52298
|
-
id: source.id,
|
|
52299
|
-
name: source.name,
|
|
52300
|
-
description: source.description,
|
|
52301
|
-
capabilities: source.capabilities,
|
|
52302
|
-
async detect() {
|
|
52303
|
-
for (const root3 of source.roots()) if ((await lstat2(root3).catch(() => void 0))?.isDirectory()) return true;
|
|
52304
|
-
return false;
|
|
52305
|
-
},
|
|
52306
|
-
async discover() {
|
|
52307
|
-
const listing = await historyFiles(source.roots(), source.match), found = /* @__PURE__ */ new Map();
|
|
52308
|
-
let failed = 0;
|
|
52309
|
-
const blocked = /* @__PURE__ */ new Set(), unreadable = /* @__PURE__ */ new Set();
|
|
52310
|
-
for (const path of listing.files) {
|
|
52311
|
-
try {
|
|
52312
|
-
const before = await states(path), rev = revision2(before);
|
|
52313
|
-
let candidate = metadata2.get(path);
|
|
52314
|
-
if (!candidate || candidate.revision !== rev) {
|
|
52315
|
-
const history = await load(path, rev, before);
|
|
52316
|
-
if (!history) {
|
|
52317
|
-
const nativeID = source.authoritativeIdentity?.(path);
|
|
52318
|
-
if (nativeID) blocked.add(identity(source.id, nativeID));
|
|
52319
|
-
continue;
|
|
52320
|
-
}
|
|
52321
|
-
const session = { ...blankSession(source.id, history.nativeID), ...history.session };
|
|
52322
|
-
session.id = identity(source.id, history.nativeID);
|
|
52323
|
-
session.nativeID = history.nativeID;
|
|
52324
|
-
session.source = source.id;
|
|
52325
|
-
session.directory = text3(session.directory);
|
|
52326
|
-
session.projectID = project(source.id, session.directory).id;
|
|
52327
|
-
session.created = time3(session.created) || history.messages.map((m) => time3(m.time)).find(Boolean) || before[0].created;
|
|
52328
|
-
session.updated = before[0].updated;
|
|
52329
|
-
session.agent ||= source.name;
|
|
52330
|
-
session.parentID = history.parent ? identity(source.id, history.parent) : void 0;
|
|
52331
|
-
session.forkID = history.fork ? identity(source.id, history.fork) : void 0;
|
|
52332
|
-
if (session.title === "Untitled session" || !session.title) session.title = history.messages.flatMap((m) => m.role === "user" ? m.fragments.filter((f) => f.kind === "You").map((f) => f.text) : []).find(Boolean)?.replace(/\s+/g, " ").slice(0, 180) || `${source.name} session`;
|
|
52333
|
-
candidate = { session, revision: rev, locator: { path } };
|
|
52334
|
-
metadata2.set(path, candidate);
|
|
52335
|
-
}
|
|
52336
|
-
const previous = found.get(candidate.session.id);
|
|
52337
|
-
const preferred = candidate.locator.path.endsWith(".jsonl"), previousPreferred = previous?.locator.path.endsWith(".jsonl");
|
|
52338
|
-
if (!previous || preferred && !previousPreferred || preferred === previousPreferred && candidate.session.updated > previous.session.updated) found.set(candidate.session.id, candidate);
|
|
52339
|
-
} catch {
|
|
52340
|
-
const nativeID = source.authoritativeIdentity?.(path);
|
|
52341
|
-
if (nativeID) {
|
|
52342
|
-
const id3 = identity(source.id, nativeID);
|
|
52343
|
-
blocked.add(id3);
|
|
52344
|
-
unreadable.add(id3);
|
|
52345
|
-
} else failed++;
|
|
52346
|
-
}
|
|
52347
|
-
}
|
|
52348
|
-
const listed = new Set(listing.files);
|
|
52349
|
-
for (const path of metadata2.keys()) if (!listed.has(path)) metadata2.delete(path);
|
|
52350
|
-
if (failed) listing.warnings.push(`${source.name}: Skipped ${failed} unreadable, changing, unsupported, or oversized ${failed === 1 ? "history file" : "history files"}.`);
|
|
52351
|
-
const sessions = [...found.values()].filter((c) => !blocked.has(c.session.id));
|
|
52352
|
-
const errors = unreadable.size ? [`${source.name}: Could not read history for ${unreadable.size} ${unreadable.size === 1 ? "session" : "sessions"}.`] : void 0;
|
|
52353
|
-
return { sessions, projects: [...new Map(sessions.map((c) => {
|
|
52354
|
-
const p = project(source.id, c.session.directory);
|
|
52355
|
-
return [p.id, p];
|
|
52356
|
-
})).values()], warnings: listing.warnings, errors, blocked: [...blocked] };
|
|
52357
|
-
},
|
|
52358
|
-
async read(candidate, cursor2) {
|
|
52359
|
-
const offset = cursor2 === void 0 ? 0 : Number(cursor2);
|
|
52360
|
-
if (!Number.isSafeInteger(offset) || offset < 0) throw new Error("Invalid history cursor.");
|
|
52361
|
-
const history = await load(candidate.locator.path, candidate.revision, await states(candidate.locator.path));
|
|
52362
|
-
if (!history) throw new Error("History representation is no longer available.");
|
|
52363
|
-
const messages = history.messages.slice(offset, offset + 100);
|
|
52364
|
-
return {
|
|
52365
|
-
messages,
|
|
52366
|
-
cursor: offset + messages.length < history.messages.length ? String(offset + messages.length) : void 0,
|
|
52367
|
-
partial: Boolean(history.partial || messages.some((m) => m.partial)),
|
|
52368
|
-
note: history.note
|
|
52369
|
-
};
|
|
52370
|
-
}
|
|
52371
|
-
};
|
|
52372
|
-
}
|
|
52373
|
-
var object4, text3, time3, MAX_BYTES2, MAX_RECORDS, MAX_FILES;
|
|
52374
|
-
var init_local_files = __esm({
|
|
52375
|
-
"server/adapters/local-files.ts"() {
|
|
52376
|
-
"use strict";
|
|
52377
|
-
init_common();
|
|
52378
|
-
init_compressed();
|
|
52379
|
-
object4 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
52380
|
-
text3 = (value) => typeof value === "string" ? value : "";
|
|
52381
|
-
time3 = (value) => {
|
|
52382
|
-
const n = typeof value === "number" ? value : typeof value === "string" ? /^\d{13}$/.test(value) ? Number(value) : Date.parse(value) : 0;
|
|
52383
|
-
return Number.isFinite(n) && n > 0 && n <= 864e13 ? n : 0;
|
|
52384
|
-
};
|
|
52385
|
-
MAX_BYTES2 = 32e6;
|
|
52386
|
-
MAX_RECORDS = 5e4;
|
|
52387
|
-
MAX_FILES = 2e4;
|
|
52573
|
+
MAX_BYTES2 = 128e6;
|
|
52574
|
+
sidecar = (path) => basename4(path).startsWith("agent-") ? path.replace(/\.jsonl$/, ".meta.json") : void 0;
|
|
52388
52575
|
}
|
|
52389
52576
|
});
|
|
52390
52577
|
|
|
@@ -52477,7 +52664,7 @@ var init_local_messages = __esm({
|
|
|
52477
52664
|
|
|
52478
52665
|
// server/adapters/pi.ts
|
|
52479
52666
|
import { homedir as homedir4 } from "node:os";
|
|
52480
|
-
import { join as
|
|
52667
|
+
import { join as join7 } from "node:path";
|
|
52481
52668
|
function piHistory(value) {
|
|
52482
52669
|
const { rows: rows2, partial: partial2 } = jsonLines(value);
|
|
52483
52670
|
const header = rows2[0];
|
|
@@ -52517,7 +52704,7 @@ var init_pi = __esm({
|
|
|
52517
52704
|
name: "Pi",
|
|
52518
52705
|
description: "Local JSONL sessions \xB7 messages, tools, compaction, and branch entries",
|
|
52519
52706
|
capabilities: { history: true, forks: false, children: false, files: true },
|
|
52520
|
-
roots: () => [sourcePath("pi") || process.env.SESSIONGRAPH_PI_SESSIONS_DIR ||
|
|
52707
|
+
roots: () => [sourcePath("pi") || process.env.SESSIONGRAPH_PI_SESSIONS_DIR || join7(process.env.PI_CODING_AGENT_DIR || join7(homedir4(), ".pi", "agent"), "sessions")],
|
|
52521
52708
|
match: (path) => path.endsWith(".jsonl"),
|
|
52522
52709
|
parse(path, files) {
|
|
52523
52710
|
const history = piHistory(files.get(path));
|
|
@@ -52529,7 +52716,7 @@ var init_pi = __esm({
|
|
|
52529
52716
|
});
|
|
52530
52717
|
|
|
52531
52718
|
// server/adapters/harness-formats.ts
|
|
52532
|
-
import { basename as
|
|
52719
|
+
import { basename as basename5, dirname as dirname3, join as join8 } from "node:path";
|
|
52533
52720
|
function message(raw, id3, timestamp) {
|
|
52534
52721
|
if (!roles.includes(raw.role)) return;
|
|
52535
52722
|
if (raw.content == null && !Array.isArray(raw.toolCalls ?? raw.tool_calls)) return;
|
|
@@ -52604,13 +52791,13 @@ function codebuffHistory(path, files, free) {
|
|
|
52604
52791
|
const m = message({ ...r, role: r.role || r.type, content }, text3(r.id) || `message:${i}`);
|
|
52605
52792
|
return m ? [m] : [];
|
|
52606
52793
|
});
|
|
52607
|
-
const chat =
|
|
52794
|
+
const chat = basename5(dirname3(path)), project2 = basename5(dirname3(dirname3(dirname3(path))));
|
|
52608
52795
|
return { nativeID: `${project2}/${chat}`, messages, partial: true };
|
|
52609
52796
|
}
|
|
52610
52797
|
function vibeHistory(path, files) {
|
|
52611
|
-
const raw = object4(json4(files.get(path))), legacy =
|
|
52798
|
+
const raw = object4(json4(files.get(path))), legacy = basename5(path) !== "meta.json";
|
|
52612
52799
|
const meta3 = legacy ? object4(raw.metadata) : raw;
|
|
52613
|
-
const transcript =
|
|
52800
|
+
const transcript = join8(dirname3(path), "messages.jsonl");
|
|
52614
52801
|
const parsed = files.has(transcript) ? jsonLines(files.get(transcript)) : { rows: [], partial: false };
|
|
52615
52802
|
const records = legacy ? raw.messages : parsed.rows;
|
|
52616
52803
|
if (!text3(meta3.session_id) || !Array.isArray(records)) throw new Error("Unsupported Vibe session.");
|
|
@@ -52692,374 +52879,16 @@ var init_harness_formats = __esm({
|
|
|
52692
52879
|
init_usage();
|
|
52693
52880
|
nativeText = (v3) => typeof v3 === "number" && Number.isSafeInteger(v3) ? String(v3) : text3(v3);
|
|
52694
52881
|
seconds = (v3) => typeof v3 === "number" && Number.isFinite(v3) && v3 > 0 ? v3 * 1e3 : time3(v3);
|
|
52695
|
-
fileID = (path) =>
|
|
52882
|
+
fileID = (path) => basename5(path).replace(/\.jsonl(?:\..*)?$|\.json$/, "");
|
|
52696
52883
|
sidecar2 = (files, path) => object4(files.has(path) ? json4(files.get(path)) : void 0);
|
|
52697
52884
|
roles = ["user", "assistant", "system", "tool", "toolResult", "model"];
|
|
52698
52885
|
}
|
|
52699
52886
|
});
|
|
52700
52887
|
|
|
52701
|
-
// server/adapters/sqlite-snapshot.ts
|
|
52702
|
-
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
52703
|
-
import { chmodSync as chmodSync2, constants as constants4, copyFileSync, lstatSync as lstatSync2, mkdtempSync, rmSync as rmSync2 } from "node:fs";
|
|
52704
|
-
import { copyFile, statfs } from "node:fs/promises";
|
|
52705
|
-
import { tmpdir } from "node:os";
|
|
52706
|
-
import { join as join7 } from "node:path";
|
|
52707
|
-
function snapshotFiles(path, large) {
|
|
52708
|
-
return [path, `${path}-wal`].map((file2, i) => {
|
|
52709
|
-
try {
|
|
52710
|
-
const s = lstatSync2(file2);
|
|
52711
|
-
const kind = i ? "History database WAL" : "History database";
|
|
52712
|
-
if (!s.isFile()) throw new SqliteSnapshotFileError(`${kind} is not a regular file.`);
|
|
52713
|
-
if (!large && s.size > 8e9) throw new SqliteSnapshotFileError(`${kind} exceeds 8 GB.`);
|
|
52714
|
-
return s;
|
|
52715
|
-
} catch (error62) {
|
|
52716
|
-
if (i && error62.code === "ENOENT") return null;
|
|
52717
|
-
throw error62;
|
|
52718
|
-
}
|
|
52719
|
-
});
|
|
52720
|
-
}
|
|
52721
|
-
function sqliteRevision(path) {
|
|
52722
|
-
return fingerprint2(path, snapshotFiles(path, false));
|
|
52723
|
-
}
|
|
52724
|
-
function openSnapshot(destination) {
|
|
52725
|
-
const db2 = new DatabaseSync2(destination, { readOnly: true, enableDoubleQuotedStringLiterals: false, allowExtension: false });
|
|
52726
|
-
try {
|
|
52727
|
-
db2.exec("PRAGMA query_only=ON; PRAGMA trusted_schema=OFF; PRAGMA busy_timeout=1000; BEGIN;");
|
|
52728
|
-
return db2;
|
|
52729
|
-
} catch (error62) {
|
|
52730
|
-
db2.close();
|
|
52731
|
-
throw error62;
|
|
52732
|
-
}
|
|
52733
|
-
}
|
|
52734
|
-
async function withLargeSqliteSnapshot(path, read3, expected) {
|
|
52735
|
-
const retained = copies.get(path);
|
|
52736
|
-
if (expected && retained?.revision === expected) return read3(retained.db, expected);
|
|
52737
|
-
const files = snapshotFiles(path, true), revision2 = fingerprint2(path, files);
|
|
52738
|
-
if (expected && revision2 !== expected) throw new SqliteSnapshotChangedError("History database changed during import; import again.");
|
|
52739
|
-
if (retained?.revision === revision2) {
|
|
52740
|
-
const result = read3(retained.db, revision2);
|
|
52741
|
-
if (fingerprint2(path, snapshotFiles(path, true)) !== revision2) throw new SqliteSnapshotChangedError("History database changed during reading; import again.");
|
|
52742
|
-
return result;
|
|
52743
|
-
}
|
|
52744
|
-
close(path);
|
|
52745
|
-
while (copies.size >= 2) close(copies.keys().next().value);
|
|
52746
|
-
const directory3 = mkdtempSync(join7(tmpdir(), "sessiongraph-history-"));
|
|
52747
|
-
const destination = join7(directory3, "history.db");
|
|
52748
|
-
let db2;
|
|
52749
|
-
try {
|
|
52750
|
-
for (const [index, suffix] of ["", "-wal"].entries()) {
|
|
52751
|
-
const file2 = files[index];
|
|
52752
|
-
if (!file2) continue;
|
|
52753
|
-
try {
|
|
52754
|
-
await copyFile(path + suffix, destination + suffix, constants4.COPYFILE_FICLONE_FORCE);
|
|
52755
|
-
} catch (error62) {
|
|
52756
|
-
if (!["ENOSYS", "ENOTSUP", "EOPNOTSUPP", "EXDEV", "EINVAL"].includes(error62.code || "")) throw error62;
|
|
52757
|
-
const { bavail, bsize } = await statfs(directory3);
|
|
52758
|
-
const reserve = 512 * 1024 * 1024;
|
|
52759
|
-
if (bavail * bsize < file2.size + reserve) throw new Error("Not enough free space for the T3 history snapshot. Free space on the temporary drive and retry.");
|
|
52760
|
-
await copyFile(path + suffix, destination + suffix);
|
|
52761
|
-
}
|
|
52762
|
-
chmodSync2(destination + suffix, 384);
|
|
52763
|
-
}
|
|
52764
|
-
if (fingerprint2(path, snapshotFiles(path, true)) !== revision2) throw new SqliteSnapshotChangedError("History database changed while copying; import again.");
|
|
52765
|
-
db2 = openSnapshot(destination);
|
|
52766
|
-
const result = read3(db2, revision2);
|
|
52767
|
-
if (!expected && fingerprint2(path, snapshotFiles(path, true)) !== revision2) throw new SqliteSnapshotChangedError("History database changed during reading; import again.");
|
|
52768
|
-
close(path);
|
|
52769
|
-
while (copies.size >= 2) close(copies.keys().next().value);
|
|
52770
|
-
copies.set(path, { revision: revision2, directory: directory3, db: db2 });
|
|
52771
|
-
return result;
|
|
52772
|
-
} catch (error62) {
|
|
52773
|
-
try {
|
|
52774
|
-
db2?.close();
|
|
52775
|
-
} finally {
|
|
52776
|
-
rmSync2(directory3, { recursive: true, force: true });
|
|
52777
|
-
}
|
|
52778
|
-
if (error62.code === "ENOENT" && fingerprint2(path, snapshotFiles(path, true)) !== revision2)
|
|
52779
|
-
throw new SqliteSnapshotChangedError("History database changed while copying; import again.");
|
|
52780
|
-
throw error62;
|
|
52781
|
-
}
|
|
52782
|
-
}
|
|
52783
|
-
function withSqliteSnapshot(path, read3, expected, pinned = false) {
|
|
52784
|
-
const retained = copies.get(path);
|
|
52785
|
-
if (pinned && expected && retained?.revision === expected) return read3(retained.db);
|
|
52786
|
-
const revision2 = sqliteRevision(path);
|
|
52787
|
-
if (expected && revision2 !== expected) throw new SqliteSnapshotChangedError("History database changed during import; import again.");
|
|
52788
|
-
let copy = copies.get(path);
|
|
52789
|
-
if (copy?.revision !== revision2) {
|
|
52790
|
-
close(path);
|
|
52791
|
-
while (copies.size >= 2) close(copies.keys().next().value);
|
|
52792
|
-
const directory3 = mkdtempSync(join7(tmpdir(), "sessiongraph-history-"));
|
|
52793
|
-
let db2;
|
|
52794
|
-
try {
|
|
52795
|
-
chmodSync2(directory3, 448);
|
|
52796
|
-
const destination = join7(directory3, "history.db");
|
|
52797
|
-
for (const suffix of ["", "-wal"]) {
|
|
52798
|
-
try {
|
|
52799
|
-
copyFileSync(path + suffix, destination + suffix, constants4.COPYFILE_FICLONE);
|
|
52800
|
-
chmodSync2(destination + suffix, 384);
|
|
52801
|
-
} catch (error62) {
|
|
52802
|
-
if (suffix && error62.code === "ENOENT") continue;
|
|
52803
|
-
throw error62;
|
|
52804
|
-
}
|
|
52805
|
-
}
|
|
52806
|
-
if (sqliteRevision(path) !== revision2) throw new SqliteSnapshotChangedError("History database changed while copying; import again.");
|
|
52807
|
-
db2 = openSnapshot(destination);
|
|
52808
|
-
copy = { revision: revision2, directory: directory3, db: db2 };
|
|
52809
|
-
copies.set(path, copy);
|
|
52810
|
-
} catch (error62) {
|
|
52811
|
-
try {
|
|
52812
|
-
db2?.close();
|
|
52813
|
-
} finally {
|
|
52814
|
-
rmSync2(directory3, { recursive: true, force: true });
|
|
52815
|
-
}
|
|
52816
|
-
throw error62;
|
|
52817
|
-
}
|
|
52818
|
-
}
|
|
52819
|
-
const result = read3(copy.db);
|
|
52820
|
-
if (!pinned && sqliteRevision(path) !== revision2) throw new SqliteSnapshotChangedError("History database changed during reading; import again.");
|
|
52821
|
-
return result;
|
|
52822
|
-
}
|
|
52823
|
-
function hasTable(db2, name) {
|
|
52824
|
-
const row = db2.prepare("SELECT sql FROM sqlite_master WHERE type='table' AND name=?").get(name);
|
|
52825
|
-
return typeof row?.sql === "string" && !/CREATE\s+VIRTUAL/i.test(row.sql);
|
|
52826
|
-
}
|
|
52827
|
-
var copies, SqliteSnapshotChangedError, SqliteSnapshotFileError, close, fingerprint2;
|
|
52828
|
-
var init_sqlite_snapshot = __esm({
|
|
52829
|
-
"server/adapters/sqlite-snapshot.ts"() {
|
|
52830
|
-
"use strict";
|
|
52831
|
-
init_common();
|
|
52832
|
-
copies = /* @__PURE__ */ new Map();
|
|
52833
|
-
SqliteSnapshotChangedError = class extends Error {
|
|
52834
|
-
};
|
|
52835
|
-
SqliteSnapshotFileError = class extends Error {
|
|
52836
|
-
};
|
|
52837
|
-
close = (path) => {
|
|
52838
|
-
const copy = copies.get(path);
|
|
52839
|
-
if (!copy) return;
|
|
52840
|
-
copies.delete(path);
|
|
52841
|
-
try {
|
|
52842
|
-
copy.db.close();
|
|
52843
|
-
} finally {
|
|
52844
|
-
rmSync2(copy.directory, { recursive: true, force: true });
|
|
52845
|
-
}
|
|
52846
|
-
};
|
|
52847
|
-
process.once("exit", () => {
|
|
52848
|
-
for (const path of copies.keys()) close(path);
|
|
52849
|
-
});
|
|
52850
|
-
fingerprint2 = (path, files) => digest([path, ...files.map((s) => s && [s.dev, s.ino, s.size, s.mtimeMs, s.ctimeMs])]);
|
|
52851
|
-
}
|
|
52852
|
-
});
|
|
52853
|
-
|
|
52854
|
-
// server/adapters/sqlite-histories.ts
|
|
52855
|
-
import { lstat as lstat3 } from "node:fs/promises";
|
|
52856
|
-
function consume(bytes2, records = 0) {
|
|
52857
|
-
if (!budget) return;
|
|
52858
|
-
budget.bytes += bytes2;
|
|
52859
|
-
budget.records += records;
|
|
52860
|
-
if (budget.bytes > 64e6 || budget.records > 5e4) throw new Error("Session exceeds the 64 MB / 50,000-record snapshot limit.");
|
|
52861
|
-
}
|
|
52862
|
-
function parseHistory(source, db2, row, path) {
|
|
52863
|
-
const previous = budget;
|
|
52864
|
-
budget = { bytes: 0, records: 0 };
|
|
52865
|
-
try {
|
|
52866
|
-
consume(rowBytes(row), 1);
|
|
52867
|
-
const history = source.parse(db2, row, path);
|
|
52868
|
-
if (history && history.messages.length > 5e4) throw new Error("Session exceeds the 50,000-message limit.");
|
|
52869
|
-
return history;
|
|
52870
|
-
} finally {
|
|
52871
|
-
budget = previous;
|
|
52872
|
-
}
|
|
52873
|
-
}
|
|
52874
|
-
function columns(db2, table2) {
|
|
52875
|
-
if (!/^[a-z_][a-z0-9_]*$/.test(table2) || !hasTable(db2, table2)) throw new Error(`Unsupported history table: ${table2}.`);
|
|
52876
|
-
return new Set(db2.prepare(`PRAGMA table_info("${table2}")`).all().map((r) => String(r.name)));
|
|
52877
|
-
}
|
|
52878
|
-
function rows(db2, table2, fields3, filter, order, limit = 5e4) {
|
|
52879
|
-
const available = columns(db2, table2);
|
|
52880
|
-
for (const name of [...fields3, ...filter ? [filter[0]] : [], ...order ? [order] : []]) if (!/^[a-zA-Z_][\w]*$/.test(name)) throw new Error("Invalid history column.");
|
|
52881
|
-
if (filter && !available.has(filter[0])) throw new Error("Unsupported history relation.");
|
|
52882
|
-
const size = (f) => `length(CAST("${f}" AS BLOB))`;
|
|
52883
|
-
const select = fields3.map((f) => available.has(f) ? `CASE WHEN ${size(f)}<=32000000 THEN "${f}" END AS "${f}"` : `NULL AS "${f}"`).join(",");
|
|
52884
|
-
const oversized = fields3.filter((f) => available.has(f)).map((f) => `COALESCE(${size(f)},0)>32000000`).join(" OR ") || "0";
|
|
52885
|
-
const query2 = `SELECT ${select}, (${oversized}) AS __sessiongraph_oversized FROM "${table2}"${filter ? ` WHERE "${filter[0]}"=?` : ""}${order && available.has(order) ? ` ORDER BY "${order}"` : ""} LIMIT ${limit + 1}`;
|
|
52886
|
-
const result = [];
|
|
52887
|
-
let bytes2 = 0;
|
|
52888
|
-
for (const row of db2.prepare(query2).iterate(...filter ? [filter[1]] : [])) {
|
|
52889
|
-
if (row.__sessiongraph_oversized) throw new Error("History field exceeds the 32 MB snapshot limit.");
|
|
52890
|
-
delete row.__sessiongraph_oversized;
|
|
52891
|
-
const size2 = rowBytes(row);
|
|
52892
|
-
bytes2 += size2;
|
|
52893
|
-
consume(size2, 1);
|
|
52894
|
-
if (bytes2 > 64e6 || result.length >= limit) throw new Error("History exceeds the 64 MB / record-count query limit.");
|
|
52895
|
-
result.push(row);
|
|
52896
|
-
}
|
|
52897
|
-
return result;
|
|
52898
|
-
}
|
|
52899
|
-
function sqliteJSON(value) {
|
|
52900
|
-
if (value instanceof Uint8Array) {
|
|
52901
|
-
const expanded = expandHistory(Buffer.from(value), Math.max(1, Math.min(32e6, 64e6 - (budget?.bytes || 0))));
|
|
52902
|
-
consume(expanded.byteLength);
|
|
52903
|
-
return JSON.parse(expanded.toString("utf8"));
|
|
52904
|
-
}
|
|
52905
|
-
if (typeof value === "string") return JSON.parse(value);
|
|
52906
|
-
throw new Error("Missing or oversized history payload.");
|
|
52907
|
-
}
|
|
52908
|
-
function optionalJSON(value) {
|
|
52909
|
-
return value == null || value === "" ? {} : sqliteJSON(value);
|
|
52910
|
-
}
|
|
52911
|
-
function sqliteHistoryAdapter(source) {
|
|
52912
|
-
const metadata2 = /* @__PURE__ */ new Map();
|
|
52913
|
-
return {
|
|
52914
|
-
id: source.id,
|
|
52915
|
-
name: source.name,
|
|
52916
|
-
description: source.description || "Local session database",
|
|
52917
|
-
capabilities: { history: source.history !== false, forks: false, children: false, files: false },
|
|
52918
|
-
async detect() {
|
|
52919
|
-
return (await source.paths()).length > 0;
|
|
52920
|
-
},
|
|
52921
|
-
async discover() {
|
|
52922
|
-
const sessions = /* @__PURE__ */ new Map(), errors = [], blocked = [];
|
|
52923
|
-
let unavailable = false;
|
|
52924
|
-
for (const path of await source.paths()) {
|
|
52925
|
-
try {
|
|
52926
|
-
const snapshot2 = sqliteRevision(path), rev = digest([source.version || 2, source.id, snapshot2]);
|
|
52927
|
-
let cached3 = metadata2.get(path);
|
|
52928
|
-
if (!cached3 || cached3.revision !== rev) {
|
|
52929
|
-
cached3 = withSqliteSnapshot(path, (db2) => {
|
|
52930
|
-
const table2 = typeof source.table === "string" ? source.table : source.table(db2);
|
|
52931
|
-
const values2 = rows(db2, table2, source.fields, void 0, source.key, 2e4), found = [];
|
|
52932
|
-
const blocked2 = [], errors2 = [];
|
|
52933
|
-
let failed = 0;
|
|
52934
|
-
for (const row of values2) {
|
|
52935
|
-
try {
|
|
52936
|
-
const h3 = parseHistory(source, db2, row, path);
|
|
52937
|
-
if (!h3) continue;
|
|
52938
|
-
if (source.history !== false && !h3.messages.length) {
|
|
52939
|
-
blocked2.push(identity(source.id, String(row[source.key])));
|
|
52940
|
-
continue;
|
|
52941
|
-
}
|
|
52942
|
-
if (!h3.nativeID || h3.nativeID.length > 512) throw new Error("Missing native session identity.");
|
|
52943
|
-
const created = time3(h3.session?.created) || h3.messages.map((m) => time3(m.time)).find(Boolean);
|
|
52944
|
-
if (!created) throw new Error("Session has no recorded creation or message date.");
|
|
52945
|
-
const session = { ...blankSession(source.id, h3.nativeID), ...h3.session, created };
|
|
52946
|
-
session.id = identity(source.id, h3.nativeID);
|
|
52947
|
-
session.nativeID = h3.nativeID;
|
|
52948
|
-
session.source = source.id;
|
|
52949
|
-
session.directory = text3(session.directory);
|
|
52950
|
-
session.projectID = project(source.id, session.directory).id;
|
|
52951
|
-
session.agent ||= source.name;
|
|
52952
|
-
session.updated ||= created;
|
|
52953
|
-
session.parentID = h3.parent ? identity(source.id, h3.parent) : void 0;
|
|
52954
|
-
session.forkID = h3.fork ? identity(source.id, h3.fork) : void 0;
|
|
52955
|
-
if (!session.title || session.title === "Untitled session") session.title = h3.messages.flatMap((m) => m.role === "user" ? m.fragments.filter((f) => f.kind === "You").map((f) => f.text) : []).find(Boolean)?.replace(/\s+/g, " ").slice(0, 180) || `${source.name} session`;
|
|
52956
|
-
found.push({ session, revision: rev, locator: { path, snapshot: snapshot2, table: table2, key: String(row[source.key]) } });
|
|
52957
|
-
} catch {
|
|
52958
|
-
blocked2.push(identity(source.id, String(row[source.key])));
|
|
52959
|
-
failed++;
|
|
52960
|
-
}
|
|
52961
|
-
}
|
|
52962
|
-
if (failed) errors2.push(`${source.name}: Skipped ${failed} unreadable, undated, unsupported, or oversized ${failed === 1 ? "session" : "sessions"}.`);
|
|
52963
|
-
return { revision: rev, candidates: found, blocked: blocked2, errors: errors2 };
|
|
52964
|
-
}, snapshot2);
|
|
52965
|
-
metadata2.set(path, cached3);
|
|
52966
|
-
}
|
|
52967
|
-
errors.push(...cached3.errors);
|
|
52968
|
-
blocked.push(...cached3.blocked);
|
|
52969
|
-
for (const c of cached3.candidates) {
|
|
52970
|
-
const old = sessions.get(c.session.id);
|
|
52971
|
-
if (!old || c.session.updated > old.session.updated) sessions.set(c.session.id, c);
|
|
52972
|
-
}
|
|
52973
|
-
} catch (error62) {
|
|
52974
|
-
unavailable = true;
|
|
52975
|
-
const detail = error62 instanceof SqliteSnapshotFileError || error62 instanceof SqliteSnapshotChangedError ? error62.message : "Could not read a history database.";
|
|
52976
|
-
errors.push(`${source.name}: ${detail}`);
|
|
52977
|
-
}
|
|
52978
|
-
}
|
|
52979
|
-
const values = [...sessions.values()];
|
|
52980
|
-
return { sessions: values, projects: [...new Map(values.map((c) => {
|
|
52981
|
-
const p = project(source.id, c.session.directory);
|
|
52982
|
-
return [p.id, p];
|
|
52983
|
-
})).values()], warnings: [], errors, blocked, unavailable };
|
|
52984
|
-
},
|
|
52985
|
-
async read(candidate, cursor2) {
|
|
52986
|
-
if (cursor2) throw new Error("Invalid SQLite history cursor.");
|
|
52987
|
-
const { path, snapshot: snapshot2, key } = candidate.locator;
|
|
52988
|
-
return withSqliteSnapshot(path, (db2) => {
|
|
52989
|
-
const table2 = typeof source.table === "string" ? source.table : source.table(db2);
|
|
52990
|
-
const row = rows(db2, table2, source.fields, [source.key, key], void 0, 1)[0];
|
|
52991
|
-
if (!row) throw new Error("Session metadata is unavailable.");
|
|
52992
|
-
const history = parseHistory(source, db2, row, path);
|
|
52993
|
-
if (!history || history.nativeID !== candidate.session.nativeID) throw new Error("Session identity changed.");
|
|
52994
|
-
if (source.history !== false && !history.messages.length) throw new Error("No readable conversation.");
|
|
52995
|
-
return { messages: history.messages, partial: Boolean(history.partial || history.messages.some((m) => m.partial)), note: history.note };
|
|
52996
|
-
}, snapshot2);
|
|
52997
|
-
}
|
|
52998
|
-
};
|
|
52999
|
-
}
|
|
53000
|
-
async function existingDatabases(paths2) {
|
|
53001
|
-
const found = [];
|
|
53002
|
-
for (const path of new Set(paths2)) {
|
|
53003
|
-
try {
|
|
53004
|
-
if ((await lstat3(path)).isFile()) found.push(path);
|
|
53005
|
-
} catch (e10) {
|
|
53006
|
-
if (e10.code !== "ENOENT") throw e10;
|
|
53007
|
-
}
|
|
53008
|
-
}
|
|
53009
|
-
return found;
|
|
53010
|
-
}
|
|
53011
|
-
function combineAdapters(parts) {
|
|
53012
|
-
const first = parts[0];
|
|
53013
|
-
return {
|
|
53014
|
-
...first,
|
|
53015
|
-
async detect() {
|
|
53016
|
-
for (const p of parts) if (await p.detect().catch(() => false)) return true;
|
|
53017
|
-
return false;
|
|
53018
|
-
},
|
|
53019
|
-
async discover() {
|
|
53020
|
-
const sessions = /* @__PURE__ */ new Map(), projects = /* @__PURE__ */ new Map(), warnings = [], errors = [], blocked = /* @__PURE__ */ new Set();
|
|
53021
|
-
for (const [i, part] of parts.entries()) {
|
|
53022
|
-
let result;
|
|
53023
|
-
try {
|
|
53024
|
-
if (!await part.detect()) continue;
|
|
53025
|
-
result = await part.discover();
|
|
53026
|
-
} catch {
|
|
53027
|
-
errors.push(`${part.name}: Could not read a history source.`);
|
|
53028
|
-
break;
|
|
53029
|
-
}
|
|
53030
|
-
warnings.push(...result.warnings);
|
|
53031
|
-
if (result.errors?.length) errors.push(...result.errors);
|
|
53032
|
-
else if (result.unavailable) errors.push(`${part.name}: History unavailable.`);
|
|
53033
|
-
for (const id3 of result.blocked || []) blocked.add(id3);
|
|
53034
|
-
for (const p of result.projects) projects.set(p.id, p);
|
|
53035
|
-
for (const c of result.sessions) if (!blocked.has(c.session.id) && !sessions.has(c.session.id)) sessions.set(c.session.id, { ...c, revision: digest([i, c.revision]), locator: { ...c.locator, representation: String(i), originalRevision: c.revision } });
|
|
53036
|
-
if (result.unavailable) break;
|
|
53037
|
-
}
|
|
53038
|
-
return { sessions: [...sessions.values()], projects: [...projects.values()], warnings, errors };
|
|
53039
|
-
},
|
|
53040
|
-
async read(candidate, cursor2) {
|
|
53041
|
-
const index = Number(candidate.locator.representation);
|
|
53042
|
-
if (!Number.isInteger(index) || !parts[index]) throw new Error("Invalid history representation.");
|
|
53043
|
-
return parts[index].read({ ...candidate, revision: candidate.locator.originalRevision }, cursor2);
|
|
53044
|
-
}
|
|
53045
|
-
};
|
|
53046
|
-
}
|
|
53047
|
-
var budget, rowBytes;
|
|
53048
|
-
var init_sqlite_histories = __esm({
|
|
53049
|
-
"server/adapters/sqlite-histories.ts"() {
|
|
53050
|
-
"use strict";
|
|
53051
|
-
init_common();
|
|
53052
|
-
init_local_files();
|
|
53053
|
-
init_sqlite_snapshot();
|
|
53054
|
-
init_compressed();
|
|
53055
|
-
rowBytes = (row) => Object.values(row).reduce((n, v3) => n + (typeof v3 === "string" ? Buffer.byteLength(v3) : v3 instanceof Uint8Array ? v3.byteLength : 8), 0);
|
|
53056
|
-
}
|
|
53057
|
-
});
|
|
53058
|
-
|
|
53059
52888
|
// server/adapters/claude.ts
|
|
53060
|
-
import { readdir as
|
|
52889
|
+
import { readdir as readdir3, stat } from "node:fs/promises";
|
|
53061
52890
|
import { homedir as homedir5 } from "node:os";
|
|
53062
|
-
import { join as
|
|
52891
|
+
import { join as join9 } from "node:path";
|
|
53063
52892
|
function claudeMessages(rows2, candidate, times, entries2) {
|
|
53064
52893
|
const calls = /* @__PURE__ */ new Map();
|
|
53065
52894
|
return rows2.map((row) => {
|
|
@@ -53117,7 +52946,7 @@ var init_claude = __esm({
|
|
|
53117
52946
|
init_source_paths();
|
|
53118
52947
|
init_commit_extraction();
|
|
53119
52948
|
init_usage();
|
|
53120
|
-
root = () =>
|
|
52949
|
+
root = () => join9(sourcePath("claude-code") || process.env.CLAUDE_CONFIG_DIR || join9(homedir5(), ".claude"), "projects");
|
|
53121
52950
|
sdkClaudeAdapter = {
|
|
53122
52951
|
id: "claude-code",
|
|
53123
52952
|
name: "Claude Code",
|
|
@@ -53136,21 +52965,21 @@ var init_claude = __esm({
|
|
|
53136
52965
|
if (infos.length === 2e4) warnings.push("Claude Code listing is limited to 20,000 sessions.");
|
|
53137
52966
|
const files = /* @__PURE__ */ new Map();
|
|
53138
52967
|
let unreadable = 0;
|
|
53139
|
-
for (const dir of await
|
|
52968
|
+
for (const dir of await readdir3(root(), { withFileTypes: true })) {
|
|
53140
52969
|
if (!dir.isDirectory()) continue;
|
|
53141
|
-
const parent =
|
|
52970
|
+
const parent = join9(root(), dir.name);
|
|
53142
52971
|
let entries2;
|
|
53143
52972
|
try {
|
|
53144
|
-
entries2 = await
|
|
52973
|
+
entries2 = await readdir3(parent, { withFileTypes: true });
|
|
53145
52974
|
} catch {
|
|
53146
52975
|
unreadable++;
|
|
53147
52976
|
continue;
|
|
53148
52977
|
}
|
|
53149
52978
|
for (const file2 of entries2) if (file2.isFile() && file2.name.endsWith(".jsonl") && claudeSessionID(file2.name.slice(0, -6))) {
|
|
53150
|
-
const id3 = file2.name.slice(0, -6), path =
|
|
52979
|
+
const id3 = file2.name.slice(0, -6), path = join9(parent, file2.name);
|
|
53151
52980
|
try {
|
|
53152
52981
|
const old = files.get(id3);
|
|
53153
|
-
if (!old || (await stat(path)).mtimeMs > (await stat(old.path)).mtimeMs) files.set(id3, { path, children:
|
|
52982
|
+
if (!old || (await stat(path)).mtimeMs > (await stat(old.path)).mtimeMs) files.set(id3, { path, children: join9(parent, id3, "subagents") });
|
|
53154
52983
|
} catch {
|
|
53155
52984
|
unreadable++;
|
|
53156
52985
|
}
|
|
@@ -53184,7 +53013,7 @@ var init_claude = __esm({
|
|
|
53184
53013
|
}
|
|
53185
53014
|
let children;
|
|
53186
53015
|
try {
|
|
53187
|
-
children = await
|
|
53016
|
+
children = await readdir3(file2.children, { withFileTypes: true });
|
|
53188
53017
|
} catch (error62) {
|
|
53189
53018
|
if (error62.code !== "ENOENT") unreadable++;
|
|
53190
53019
|
continue;
|
|
@@ -53192,7 +53021,7 @@ var init_claude = __esm({
|
|
|
53192
53021
|
for (const child of children) {
|
|
53193
53022
|
if (!child.isFile() || !/^agent-[\w-]+\.jsonl$/.test(child.name)) continue;
|
|
53194
53023
|
try {
|
|
53195
|
-
const agent = child.name.slice(6, -6), path =
|
|
53024
|
+
const agent = child.name.slice(6, -6), path = join9(file2.children, child.name), stats = await stat(path);
|
|
53196
53025
|
sessions.push({ session: { ...s, id: identity("claude-code", `${info.sessionId}/agent/${agent}`), nativeID: `${info.sessionId}/agent/${agent}`, title: `Subagent ${agent}`, created: stats.birthtimeMs || s.created, updated: stats.mtimeMs, parentID: s.id, origin: "automated", agent }, revision: await claudeRevision(path), locator: { path, dir: info.cwd || "", parent: info.sessionId, agent } });
|
|
53197
53026
|
} catch {
|
|
53198
53027
|
unreadable++;
|
|
@@ -53240,7 +53069,7 @@ var init_claude = __esm({
|
|
|
53240
53069
|
name: "Claude Code",
|
|
53241
53070
|
description: "Legacy local transcript exports",
|
|
53242
53071
|
capabilities: { history: true, forks: false, children: false, files: false },
|
|
53243
|
-
roots: () => [
|
|
53072
|
+
roots: () => [join9(sourcePath("claude-code") || process.env.CLAUDE_CONFIG_DIR || join9(homedir5(), ".claude"), "transcripts")],
|
|
53244
53073
|
match: (p) => p.endsWith(".jsonl"),
|
|
53245
53074
|
parse: (path, files) => envelopeHistory(path, files.get(path))
|
|
53246
53075
|
});
|
|
@@ -53249,8 +53078,8 @@ var init_claude = __esm({
|
|
|
53249
53078
|
});
|
|
53250
53079
|
|
|
53251
53080
|
// server/adapters/jsonl.ts
|
|
53252
|
-
import { open as open4, readdir as
|
|
53253
|
-
import { join as
|
|
53081
|
+
import { open as open4, readdir as readdir4 } from "node:fs/promises";
|
|
53082
|
+
import { join as join10 } from "node:path";
|
|
53254
53083
|
import { constants as constants5 } from "node:fs";
|
|
53255
53084
|
async function readJSONL(path, offset = 0, budget2 = 2e6, limit = 200) {
|
|
53256
53085
|
if (!Number.isSafeInteger(offset) || offset < 0) throw new Error("Invalid transcript cursor.");
|
|
@@ -53326,14 +53155,14 @@ async function transcriptFiles(root3, max = 2e4, match2 = (name) => name.endsWit
|
|
|
53326
53155
|
for (let i = 0; i < queue.length && files.length < max; i++) {
|
|
53327
53156
|
let entries2;
|
|
53328
53157
|
try {
|
|
53329
|
-
entries2 = await
|
|
53158
|
+
entries2 = await readdir4(queue[i], { withFileTypes: true });
|
|
53330
53159
|
} catch (error62) {
|
|
53331
53160
|
if (error62.code === "ENOENT") continue;
|
|
53332
53161
|
throw error62;
|
|
53333
53162
|
}
|
|
53334
53163
|
for (const entry of entries2) {
|
|
53335
|
-
if (entry.isDirectory() && queue.length < 2e4) queue.push(
|
|
53336
|
-
if (entry.isFile() && match2(entry.name)) files.push(
|
|
53164
|
+
if (entry.isDirectory() && queue.length < 2e4) queue.push(join10(queue[i], entry.name));
|
|
53165
|
+
if (entry.isFile() && match2(entry.name)) files.push(join10(queue[i], entry.name));
|
|
53337
53166
|
if (files.length >= max) break;
|
|
53338
53167
|
}
|
|
53339
53168
|
}
|
|
@@ -53350,7 +53179,7 @@ var init_jsonl = __esm({
|
|
|
53350
53179
|
// server/adapters/codex.ts
|
|
53351
53180
|
import { stat as stat2 } from "node:fs/promises";
|
|
53352
53181
|
import { homedir as homedir6 } from "node:os";
|
|
53353
|
-
import { join as
|
|
53182
|
+
import { join as join11, sep as sep3 } from "node:path";
|
|
53354
53183
|
function changedPaths(value) {
|
|
53355
53184
|
if (!value || typeof value !== "object") return [];
|
|
53356
53185
|
const changes = Array.isArray(value) ? value : Object.entries(value).map(([path, change]) => ({ ...change && typeof change === "object" ? change : {}, path }));
|
|
@@ -53374,7 +53203,7 @@ async function sessionNames() {
|
|
|
53374
53203
|
let cursor2, count = 0;
|
|
53375
53204
|
try {
|
|
53376
53205
|
do {
|
|
53377
|
-
const page3 = await readJSONL(
|
|
53206
|
+
const page3 = await readJSONL(join11(root2(), "session_index.jsonl"), cursor2, 2e6, 1e3);
|
|
53378
53207
|
for (const { value } of page3.rows) if (typeof value.id === "string" && typeof value.thread_name === "string" && value.thread_name.trim()) names.set(value.id, value.thread_name.trim().slice(0, 300));
|
|
53379
53208
|
cursor2 = page3.cursor;
|
|
53380
53209
|
count += page3.rows.length;
|
|
@@ -53459,7 +53288,7 @@ var init_codex = __esm({
|
|
|
53459
53288
|
init_source_paths();
|
|
53460
53289
|
init_commit_extraction();
|
|
53461
53290
|
init_usage();
|
|
53462
|
-
root2 = () => sourcePath("codex") || process.env.CODEX_HOME ||
|
|
53291
|
+
root2 = () => sourcePath("codex") || process.env.CODEX_HOME || join11(homedir6(), ".codex");
|
|
53463
53292
|
revision = async (path) => {
|
|
53464
53293
|
const s = await stat2(path);
|
|
53465
53294
|
return digest([10, s.mtimeMs, s.size]);
|
|
@@ -53480,7 +53309,7 @@ var init_codex = __esm({
|
|
|
53480
53309
|
const found = /* @__PURE__ */ new Map(), warnings = [];
|
|
53481
53310
|
const names = await sessionNames();
|
|
53482
53311
|
const match2 = (name) => /\.jsonl(?:\.[\w.-]+)?$/.test(name);
|
|
53483
|
-
const paths2 = [...await transcriptFiles(
|
|
53312
|
+
const paths2 = [...await transcriptFiles(join11(root2(), "sessions"), 2e4, match2), ...await transcriptFiles(join11(root2(), "archived_sessions"), 2e4, match2)];
|
|
53484
53313
|
if (paths2.length >= 2e4) warnings.push("Codex transcript listing may be partial (20,000 files per history folder).");
|
|
53485
53314
|
let unsupported = 0;
|
|
53486
53315
|
for (const path of paths2) {
|
|
@@ -53535,9 +53364,9 @@ var init_codex = __esm({
|
|
|
53535
53364
|
});
|
|
53536
53365
|
|
|
53537
53366
|
// server/adapters/t3-code.ts
|
|
53538
|
-
import { lstat as
|
|
53367
|
+
import { lstat as lstat5 } from "node:fs/promises";
|
|
53539
53368
|
import { homedir as homedir7 } from "node:os";
|
|
53540
|
-
import { isAbsolute as isAbsolute4, join as
|
|
53369
|
+
import { isAbsolute as isAbsolute4, join as join12 } from "node:path";
|
|
53541
53370
|
function parsedObject(value) {
|
|
53542
53371
|
if (typeof value !== "string") return;
|
|
53543
53372
|
try {
|
|
@@ -53555,16 +53384,16 @@ function status(value) {
|
|
|
53555
53384
|
return ["pending", "running", "completed", "failed"].includes(string6(value)) ? value : "unknown";
|
|
53556
53385
|
}
|
|
53557
53386
|
async function databasePath2() {
|
|
53558
|
-
const root3 = sourcePath("t3-code") || process.env.SESSIONGRAPH_T3_CODE_HISTORY_DIR || process.env.T3CODE_HOME ||
|
|
53387
|
+
const root3 = sourcePath("t3-code") || process.env.SESSIONGRAPH_T3_CODE_HISTORY_DIR || process.env.T3CODE_HOME || join12(homedir7(), ".t3");
|
|
53559
53388
|
const paths2 = /\.sqlite$/.test(root3) ? [root3] : [
|
|
53560
|
-
|
|
53561
|
-
|
|
53562
|
-
|
|
53563
|
-
|
|
53389
|
+
join12(root3, "userdata", "statev2.sqlite"),
|
|
53390
|
+
join12(root3, "statev2.sqlite"),
|
|
53391
|
+
join12(root3, "userdata", "state.sqlite"),
|
|
53392
|
+
join12(root3, "state.sqlite")
|
|
53564
53393
|
];
|
|
53565
53394
|
for (const path of paths2) {
|
|
53566
53395
|
try {
|
|
53567
|
-
if ((await
|
|
53396
|
+
if ((await lstat5(path)).isFile()) return path;
|
|
53568
53397
|
} catch (error62) {
|
|
53569
53398
|
if (error62.code !== "ENOENT") throw error62;
|
|
53570
53399
|
}
|
|
@@ -53756,7 +53585,7 @@ function v2Message(row, directory3) {
|
|
|
53756
53585
|
message2.events = [eventFor(message2, id3, kind2, file2, "", { ...fields3, callID: string6(native.nativeId) || void 0 })];
|
|
53757
53586
|
return message2;
|
|
53758
53587
|
}
|
|
53759
|
-
if (file2 && completed) message2.files.push({ path: isAbsolute4(file2) ? file2 :
|
|
53588
|
+
if (file2 && completed) message2.files.push({ path: isAbsolute4(file2) ? file2 : join12(directory3, file2), source: "file change", steps: 1 });
|
|
53760
53589
|
message2.events = [eventFor(message2, id3, "file_change", file2 || name, "", fields3)];
|
|
53761
53590
|
return message2;
|
|
53762
53591
|
}
|
|
@@ -53787,11 +53616,11 @@ function readV2(db2, candidate, cursor2) {
|
|
|
53787
53616
|
CASE WHEN length(payload_json)<=? THEN payload_json END AS payload_json
|
|
53788
53617
|
FROM orchestration_v2_projection_turn_items
|
|
53789
53618
|
WHERE thread_id=? AND (ordinal>? OR (ordinal=? AND turn_item_id>?))
|
|
53790
|
-
ORDER BY ordinal, turn_item_id LIMIT ?`).all(MAX_ITEM_JSON, candidate.locator.threadID, ordinal, ordinal, id3,
|
|
53791
|
-
const page3 = rows2.slice(0,
|
|
53619
|
+
ORDER BY ordinal, turn_item_id LIMIT ?`).all(MAX_ITEM_JSON, candidate.locator.threadID, ordinal, ordinal, id3, PAGE2 + 1);
|
|
53620
|
+
const page3 = rows2.slice(0, PAGE2), last2 = page3.at(-1);
|
|
53792
53621
|
return {
|
|
53793
53622
|
messages: page3.map((row) => v2Message(row, candidate.session.directory)),
|
|
53794
|
-
cursor: rows2.length >
|
|
53623
|
+
cursor: rows2.length > PAGE2 && last2 ? `${last2.ordinal}:${last2.turn_item_id}` : void 0,
|
|
53795
53624
|
partial: candidate.locator.metadataPartial === "1" || page3.some((row) => !parsedObject(row.payload_json))
|
|
53796
53625
|
};
|
|
53797
53626
|
}
|
|
@@ -53800,8 +53629,8 @@ function readV1(db2, candidate, cursor2) {
|
|
|
53800
53629
|
if (!Number.isSafeInteger(offset) || offset < 0) throw new Error("Invalid T3 Code history cursor.");
|
|
53801
53630
|
const rows2 = db2.prepare(`SELECT message_id, role, created_at,
|
|
53802
53631
|
CASE WHEN length(text)<=? THEN text END AS text FROM projection_thread_messages
|
|
53803
|
-
WHERE thread_id=? ORDER BY created_at, message_id LIMIT ? OFFSET ?`).all(MAX_ITEM_JSON, candidate.locator.threadID,
|
|
53804
|
-
const messages = rows2.slice(0,
|
|
53632
|
+
WHERE thread_id=? ORDER BY created_at, message_id LIMIT ? OFFSET ?`).all(MAX_ITEM_JSON, candidate.locator.threadID, PAGE2 + 1, offset);
|
|
53633
|
+
const messages = rows2.slice(0, PAGE2).map((row) => {
|
|
53805
53634
|
const role = row.role === "user" ? "user" : row.role === "assistant" ? "assistant" : "system";
|
|
53806
53635
|
const message2 = blankMessage(`message:${row.message_id}`, time4(row.created_at), role);
|
|
53807
53636
|
const body = string6(row.text);
|
|
@@ -53812,12 +53641,12 @@ function readV1(db2, candidate, cursor2) {
|
|
|
53812
53641
|
});
|
|
53813
53642
|
return {
|
|
53814
53643
|
messages,
|
|
53815
|
-
cursor: rows2.length >
|
|
53644
|
+
cursor: rows2.length > PAGE2 ? String(offset + PAGE2) : void 0,
|
|
53816
53645
|
partial: true,
|
|
53817
53646
|
note: "Legacy T3 Code: conversation text only."
|
|
53818
53647
|
};
|
|
53819
53648
|
}
|
|
53820
|
-
var SOURCE,
|
|
53649
|
+
var SOURCE, PAGE2, MAX_ITEM_JSON, providerSource, openCodeEditTools, string6, t3CodeAdapter;
|
|
53821
53650
|
var init_t3_code = __esm({
|
|
53822
53651
|
"server/adapters/t3-code.ts"() {
|
|
53823
53652
|
"use strict";
|
|
@@ -53828,7 +53657,7 @@ var init_t3_code = __esm({
|
|
|
53828
53657
|
init_commit_extraction();
|
|
53829
53658
|
init_usage();
|
|
53830
53659
|
SOURCE = "t3-code";
|
|
53831
|
-
|
|
53660
|
+
PAGE2 = 100;
|
|
53832
53661
|
MAX_ITEM_JSON = 256e3;
|
|
53833
53662
|
providerSource = { codex: "codex", claudeAgent: "claude-code", opencode: "opencode" };
|
|
53834
53663
|
openCodeEditTools = /* @__PURE__ */ new Set(["patch", "apply_patch", "edit", "write", "multiedit"]);
|
|
@@ -53966,8 +53795,8 @@ var init_cursor_message = __esm({
|
|
|
53966
53795
|
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
53967
53796
|
import { chmodSync as chmodSync3, copyFileSync as copyFileSync2, lstatSync as lstatSync3, mkdtempSync as mkdtempSync2, rmSync as rmSync3 } from "node:fs";
|
|
53968
53797
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
53969
|
-
import { join as
|
|
53970
|
-
function withStore(path,
|
|
53798
|
+
import { join as join13 } from "node:path";
|
|
53799
|
+
function withStore(path, read2) {
|
|
53971
53800
|
const files = [path, `${path}-wal`];
|
|
53972
53801
|
const stats = () => files.map((file2) => {
|
|
53973
53802
|
try {
|
|
@@ -53979,11 +53808,11 @@ function withStore(path, read3) {
|
|
|
53979
53808
|
throw error62;
|
|
53980
53809
|
}
|
|
53981
53810
|
});
|
|
53982
|
-
const before = stats(), directory3 = mkdtempSync2(
|
|
53811
|
+
const before = stats(), directory3 = mkdtempSync2(join13(tmpdir2(), "sessiongraph-cursor-"));
|
|
53983
53812
|
let db2;
|
|
53984
53813
|
try {
|
|
53985
53814
|
chmodSync3(directory3, 448);
|
|
53986
|
-
const copy =
|
|
53815
|
+
const copy = join13(directory3, "store.db");
|
|
53987
53816
|
files.forEach((file2, index) => {
|
|
53988
53817
|
if (before[index]) {
|
|
53989
53818
|
const target = index ? `${copy}-wal` : copy;
|
|
@@ -53994,7 +53823,7 @@ function withStore(path, read3) {
|
|
|
53994
53823
|
if (JSON.stringify(stats()) !== JSON.stringify(before)) throw new Error("Cursor store changed while copying; re-import to retry.");
|
|
53995
53824
|
db2 = new DatabaseSync3(copy, { readOnly: true, enableDoubleQuotedStringLiterals: false, allowExtension: false });
|
|
53996
53825
|
db2.exec("PRAGMA query_only=ON; PRAGMA trusted_schema=OFF; PRAGMA busy_timeout=1000; BEGIN;");
|
|
53997
|
-
return
|
|
53826
|
+
return read2(db2);
|
|
53998
53827
|
} finally {
|
|
53999
53828
|
try {
|
|
54000
53829
|
db2?.close();
|
|
@@ -54255,14 +54084,14 @@ var init_cursor_composer = __esm({
|
|
|
54255
54084
|
});
|
|
54256
54085
|
|
|
54257
54086
|
// server/adapters/cursor.ts
|
|
54258
|
-
import { createHash as
|
|
54259
|
-
import { lstat as
|
|
54087
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
54088
|
+
import { lstat as lstat6, opendir, readFile as readFile2 } from "node:fs/promises";
|
|
54260
54089
|
import { homedir as homedir8 } from "node:os";
|
|
54261
|
-
import { isAbsolute as isAbsolute6, join as
|
|
54090
|
+
import { isAbsolute as isAbsolute6, join as join14 } from "node:path";
|
|
54262
54091
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
54263
54092
|
async function fileStats(path) {
|
|
54264
54093
|
try {
|
|
54265
|
-
const s = await
|
|
54094
|
+
const s = await lstat6(path);
|
|
54266
54095
|
if (s.isSymbolicLink()) throw new Error("Cursor history symlinks are not followed.");
|
|
54267
54096
|
return s.isFile() ? s : void 0;
|
|
54268
54097
|
} catch (error62) {
|
|
@@ -54281,13 +54110,13 @@ async function json5(path) {
|
|
|
54281
54110
|
const s = await fileStats(path);
|
|
54282
54111
|
if (!s) return {};
|
|
54283
54112
|
if (s.size > 128e3) throw new Error("Cursor metadata exceeds the 128 KB limit.");
|
|
54284
|
-
const value = JSON.parse(await
|
|
54113
|
+
const value = JSON.parse(await readFile2(path, "utf8"));
|
|
54285
54114
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
54286
54115
|
}
|
|
54287
54116
|
async function entries(path, warnings) {
|
|
54288
54117
|
const result = [];
|
|
54289
54118
|
try {
|
|
54290
|
-
if (!(await
|
|
54119
|
+
if (!(await lstat6(path)).isDirectory()) return result;
|
|
54291
54120
|
for await (const entry of await opendir(path)) {
|
|
54292
54121
|
if (!entry.isSymbolicLink()) result.push(entry);
|
|
54293
54122
|
if (result.length === LIMIT) {
|
|
@@ -54302,12 +54131,12 @@ async function entries(path, warnings) {
|
|
|
54302
54131
|
}
|
|
54303
54132
|
async function workspacePaths(root3, warnings) {
|
|
54304
54133
|
const stores = /* @__PURE__ */ new Map();
|
|
54305
|
-
const storage =
|
|
54134
|
+
const storage = join14(root3, "User/workspaceStorage");
|
|
54306
54135
|
for (const entry of await entries(storage, warnings)) if (entry.isDirectory()) {
|
|
54307
|
-
const database =
|
|
54136
|
+
const database = join14(storage, entry.name, "state.vscdb");
|
|
54308
54137
|
stores.set(database, "");
|
|
54309
54138
|
try {
|
|
54310
|
-
const info = await json5(
|
|
54139
|
+
const info = await json5(join14(storage, entry.name, "workspace.json"));
|
|
54311
54140
|
if (typeof info.folder === "string" && info.folder.startsWith("file:")) {
|
|
54312
54141
|
const path = cwd(fileURLToPath2(info.folder));
|
|
54313
54142
|
if (path) stores.set(database, path);
|
|
@@ -54319,7 +54148,7 @@ async function workspacePaths(root3, warnings) {
|
|
|
54319
54148
|
return stores;
|
|
54320
54149
|
}
|
|
54321
54150
|
function createCursorAdapter(options = {}) {
|
|
54322
|
-
const root3 = () => options.home || sourcePath("cursor") || process.env.SESSIONGRAPH_CURSOR_HOME || process.env.SESSION_ATLAS_CURSOR_HOME ||
|
|
54151
|
+
const root3 = () => options.home || sourcePath("cursor") || process.env.SESSIONGRAPH_CURSOR_HOME || process.env.SESSION_ATLAS_CURSOR_HOME || join14(homedir8(), ".cursor");
|
|
54323
54152
|
const editor = () => options.userData || process.env.SESSIONGRAPH_CURSOR_USER_DATA_DIR || process.env.SESSION_ATLAS_CURSOR_USER_DATA_DIR || userData();
|
|
54324
54153
|
return {
|
|
54325
54154
|
id: "cursor",
|
|
@@ -54327,13 +54156,13 @@ function createCursorAdapter(options = {}) {
|
|
|
54327
54156
|
description: "Local IDE, Composer, and CLI sessions",
|
|
54328
54157
|
capabilities: { history: true, forks: false, children: true, files: false },
|
|
54329
54158
|
async detect() {
|
|
54330
|
-
if (await fileStats(
|
|
54331
|
-
for (const entry of await entries(
|
|
54332
|
-
if (entry.isDirectory() && await fileStats(
|
|
54159
|
+
if (await fileStats(join14(editor(), "User/globalStorage/state.vscdb"))) return true;
|
|
54160
|
+
for (const entry of await entries(join14(editor(), "User/workspaceStorage"), [])) {
|
|
54161
|
+
if (entry.isDirectory() && await fileStats(join14(editor(), "User/workspaceStorage", entry.name, "state.vscdb"))) return true;
|
|
54333
54162
|
}
|
|
54334
54163
|
for (const name of ["projects", "chats", "acp-sessions"]) {
|
|
54335
54164
|
try {
|
|
54336
|
-
if ((await
|
|
54165
|
+
if ((await lstat6(join14(root3(), name))).isDirectory()) return true;
|
|
54337
54166
|
} catch {
|
|
54338
54167
|
}
|
|
54339
54168
|
}
|
|
@@ -54343,7 +54172,7 @@ function createCursorAdapter(options = {}) {
|
|
|
54343
54172
|
const warnings = [], errors = [], found = /* @__PURE__ */ new Map(), blocked = /* @__PURE__ */ new Set();
|
|
54344
54173
|
const workspaceStores = await workspacePaths(editor(), warnings);
|
|
54345
54174
|
const paths2 = [...new Set([...workspaceStores.values()].filter(Boolean))];
|
|
54346
|
-
const legacyStores = new Map([[
|
|
54175
|
+
const legacyStores = new Map([[join14(editor(), "User/globalStorage/state.vscdb"), ""], ...workspaceStores]);
|
|
54347
54176
|
for (const [path, workspace] of legacyStores) {
|
|
54348
54177
|
try {
|
|
54349
54178
|
if (!await fileStats(path)) continue;
|
|
@@ -54374,7 +54203,7 @@ function createCursorAdapter(options = {}) {
|
|
|
54374
54203
|
if (!stats) return;
|
|
54375
54204
|
const native = parent ? `${parent}/agent/${id3}` : id3;
|
|
54376
54205
|
const locator = { path, kind };
|
|
54377
|
-
if (kind !== "transcript") locator.meta =
|
|
54206
|
+
if (kind !== "transcript") locator.meta = join14(path, "..", "meta.json");
|
|
54378
54207
|
const before = await snapshot(locator);
|
|
54379
54208
|
const extra2 = locator.meta ? await json5(locator.meta) : {};
|
|
54380
54209
|
const meta3 = kind === "transcript" ? {} : cursorStoreMetadata(path);
|
|
@@ -54416,7 +54245,7 @@ function createCursorAdapter(options = {}) {
|
|
|
54416
54245
|
}
|
|
54417
54246
|
if (!session.directory) locator.directoryNote = "Working directory is unknown; choose one when continuing.";
|
|
54418
54247
|
session.projectID = project("cursor", session.directory).id;
|
|
54419
|
-
session.nativeResume = kind === "cli" && Boolean(session.directory) && hashCwd(session.directory) === workspaceHash && root3() ===
|
|
54248
|
+
session.nativeResume = kind === "cli" && Boolean(session.directory) && hashCwd(session.directory) === workspaceHash && root3() === join14(homedir8(), ".cursor");
|
|
54420
54249
|
locator.snapshot = before;
|
|
54421
54250
|
if (await snapshot(locator) !== before) throw new Error("Cursor session changed during discovery.");
|
|
54422
54251
|
const previous = found.get(session.id);
|
|
@@ -54439,39 +54268,39 @@ function createCursorAdapter(options = {}) {
|
|
|
54439
54268
|
if (kind !== "transcript") blocked.add(identity("cursor", id3));
|
|
54440
54269
|
}
|
|
54441
54270
|
};
|
|
54442
|
-
const projects =
|
|
54271
|
+
const projects = join14(root3(), "projects");
|
|
54443
54272
|
for (const dir of await entries(projects, warnings)) {
|
|
54444
54273
|
if (!dir.isDirectory() || scanned >= LIMIT) continue;
|
|
54445
|
-
const transcripts =
|
|
54274
|
+
const transcripts = join14(projects, dir.name, "agent-transcripts"), directory3 = match2(dir.name, slug);
|
|
54446
54275
|
for (const entry of await entries(transcripts, warnings)) {
|
|
54447
54276
|
if (scanned >= LIMIT) break;
|
|
54448
|
-
if (entry.isFile() && entry.name.endsWith(".jsonl")) await add(
|
|
54277
|
+
if (entry.isFile() && entry.name.endsWith(".jsonl")) await add(join14(transcripts, entry.name), entry.name.slice(0, -6), "transcript", directory3);
|
|
54449
54278
|
else if (entry.isFile() && entry.name.endsWith(".txt")) legacy++;
|
|
54450
54279
|
else if (entry.isDirectory() && validID(entry.name)) {
|
|
54451
|
-
await add(
|
|
54452
|
-
for (const child of await entries(
|
|
54453
|
-
if (child.isFile() && child.name.endsWith(".jsonl")) await add(
|
|
54280
|
+
await add(join14(transcripts, entry.name, `${entry.name}.jsonl`), entry.name, "transcript", directory3);
|
|
54281
|
+
for (const child of await entries(join14(transcripts, entry.name, "subagents"), warnings)) {
|
|
54282
|
+
if (child.isFile() && child.name.endsWith(".jsonl")) await add(join14(transcripts, entry.name, "subagents", child.name), child.name.slice(0, -6), "transcript", directory3, entry.name);
|
|
54454
54283
|
if (scanned >= LIMIT) break;
|
|
54455
54284
|
}
|
|
54456
54285
|
}
|
|
54457
54286
|
}
|
|
54458
54287
|
}
|
|
54459
|
-
const chats =
|
|
54288
|
+
const chats = join14(root3(), "chats");
|
|
54460
54289
|
for (const bucket of await entries(chats, warnings)) {
|
|
54461
54290
|
if (!bucket.isDirectory() || scanned >= LIMIT) continue;
|
|
54462
|
-
const folder =
|
|
54463
|
-
if (/^[a-f\d]{32}$/i.test(bucket.name) && await fileStats(
|
|
54291
|
+
const folder = join14(chats, bucket.name), directory3 = match2(bucket.name, hashCwd);
|
|
54292
|
+
if (/^[a-f\d]{32}$/i.test(bucket.name) && await fileStats(join14(folder, "store.db"))) {
|
|
54464
54293
|
const id3 = bucket.name.replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/, "$1-$2-$3-$4-$5");
|
|
54465
|
-
await add(
|
|
54294
|
+
await add(join14(folder, "store.db"), id3, "cli", "");
|
|
54466
54295
|
}
|
|
54467
54296
|
for (const entry of await entries(folder, warnings)) {
|
|
54468
|
-
if (entry.isDirectory()) await add(
|
|
54297
|
+
if (entry.isDirectory()) await add(join14(folder, entry.name, "store.db"), entry.name, "cli", directory3, "", bucket.name);
|
|
54469
54298
|
if (scanned >= LIMIT) break;
|
|
54470
54299
|
}
|
|
54471
54300
|
}
|
|
54472
|
-
const acp =
|
|
54301
|
+
const acp = join14(root3(), "acp-sessions");
|
|
54473
54302
|
for (const entry of await entries(acp, warnings)) {
|
|
54474
|
-
if (entry.isDirectory()) await add(
|
|
54303
|
+
if (entry.isDirectory()) await add(join14(acp, entry.name, "store.db"), entry.name, "acp", "");
|
|
54475
54304
|
if (scanned >= LIMIT) break;
|
|
54476
54305
|
}
|
|
54477
54306
|
if (scanned >= LIMIT) warnings.push("Cursor discovery limited to 20,000 history files.");
|
|
@@ -54530,18 +54359,18 @@ var init_cursor = __esm({
|
|
|
54530
54359
|
validID = (id3) => /^[a-z\d][\w-]{0,159}$/i.test(id3);
|
|
54531
54360
|
cwd = (value) => typeof value === "string" && isAbsolute6(value) && !/[\x00-\x1f\x7f]/.test(value) ? value : "";
|
|
54532
54361
|
slug = (path) => path.replace(/\\/g, "/").replace(/^([A-Z]):/i, (_, drive) => drive.toLowerCase()).replace(/^\/+|\/+$/g, "").replace(/[/:]+/g, "-");
|
|
54533
|
-
hashCwd = (path) =>
|
|
54534
|
-
userData = () => process.platform === "darwin" ?
|
|
54362
|
+
hashCwd = (path) => createHash5("md5").update(path).digest("hex");
|
|
54363
|
+
userData = () => process.platform === "darwin" ? join14(homedir8(), "Library/Application Support/Cursor") : process.platform === "win32" ? join14(process.env.APPDATA || join14(homedir8(), "AppData/Roaming"), "Cursor") : join14(process.env.XDG_CONFIG_HOME || join14(homedir8(), ".config"), "Cursor");
|
|
54535
54364
|
cursorAdapter = createCursorAdapter();
|
|
54536
54365
|
}
|
|
54537
54366
|
});
|
|
54538
54367
|
|
|
54539
54368
|
// server/adapters/gemini.ts
|
|
54540
54369
|
import { homedir as homedir9 } from "node:os";
|
|
54541
|
-
import { basename as
|
|
54370
|
+
import { basename as basename6, dirname as dirname4, join as join15, sep as sep4 } from "node:path";
|
|
54542
54371
|
function projectRootFile(path) {
|
|
54543
54372
|
const parts = path.split(sep4);
|
|
54544
|
-
return
|
|
54373
|
+
return join15(parts.slice(0, parts.lastIndexOf("chats")).join(sep4), ".project_root");
|
|
54545
54374
|
}
|
|
54546
54375
|
function geminiConversation(contents, lines) {
|
|
54547
54376
|
const parsed = lines ? jsonLines(contents) : { rows: [object4(json4(contents))], partial: false };
|
|
@@ -54602,7 +54431,7 @@ var init_gemini = __esm({
|
|
|
54602
54431
|
name: "Gemini CLI",
|
|
54603
54432
|
description: "Local JSON and JSONL chats, including recorded subagent histories",
|
|
54604
54433
|
capabilities: { history: true, forks: false, children: true, files: true },
|
|
54605
|
-
roots: () => sourcePath("gemini") || process.env.SESSIONGRAPH_GEMINI_HOME ? [
|
|
54434
|
+
roots: () => sourcePath("gemini") || process.env.SESSIONGRAPH_GEMINI_HOME ? [join15(sourcePath("gemini") || process.env.SESSIONGRAPH_GEMINI_HOME, "tmp")] : [join15(process.env.GEMINI_CLI_HOME || homedir9(), ".gemini", "tmp"), join15(process.env.GEMINI_CLI_HOME || homedir9(), ".cache", ".gemini", "tmp")],
|
|
54606
54435
|
match: (path) => /^[^/]+\/chats\/(?:[^/]+\/)?[^/]+\.jsonl?$/.test(path),
|
|
54607
54436
|
extras: (path) => [projectRootFile(path)],
|
|
54608
54437
|
parse(path, files) {
|
|
@@ -54627,7 +54456,7 @@ var init_gemini = __esm({
|
|
|
54627
54456
|
return message2;
|
|
54628
54457
|
});
|
|
54629
54458
|
successfulEdits(messages, ["write_file", "replace"]);
|
|
54630
|
-
const parent = meta3.kind === "subagent" &&
|
|
54459
|
+
const parent = meta3.kind === "subagent" && basename6(dirname4(dirname4(path))) === "chats" ? basename6(dirname4(path)) : void 0;
|
|
54631
54460
|
return {
|
|
54632
54461
|
nativeID: meta3.sessionId,
|
|
54633
54462
|
messages,
|
|
@@ -54642,7 +54471,7 @@ var init_gemini = __esm({
|
|
|
54642
54471
|
|
|
54643
54472
|
// server/adapters/qwen.ts
|
|
54644
54473
|
import { homedir as homedir10 } from "node:os";
|
|
54645
|
-
import { join as
|
|
54474
|
+
import { join as join16 } from "node:path";
|
|
54646
54475
|
var qwenAdapter;
|
|
54647
54476
|
var init_qwen = __esm({
|
|
54648
54477
|
"server/adapters/qwen.ts"() {
|
|
@@ -54658,7 +54487,7 @@ var init_qwen = __esm({
|
|
|
54658
54487
|
name: "Qwen Code",
|
|
54659
54488
|
description: "Local project chat records \xB7 tool results, forks, and child sessions",
|
|
54660
54489
|
capabilities: { history: true, forks: true, children: true, files: true },
|
|
54661
|
-
roots: () => [
|
|
54490
|
+
roots: () => [join16(sourcePath("qwen-code") || process.env.SESSIONGRAPH_QWEN_HOME || process.env.QWEN_RUNTIME_DIR || process.env.QWEN_HOME || join16(homedir10(), ".qwen"), "projects")],
|
|
54662
54491
|
match: (path) => /^[^/]+\/chats\/[^/]+\.jsonl$/.test(path),
|
|
54663
54492
|
parse(path, files) {
|
|
54664
54493
|
const { rows: rows2, partial: partial2 } = jsonLines(files.get(path));
|
|
@@ -54699,7 +54528,7 @@ var init_qwen = __esm({
|
|
|
54699
54528
|
|
|
54700
54529
|
// server/adapters/copilot.ts
|
|
54701
54530
|
import { homedir as homedir11 } from "node:os";
|
|
54702
|
-
import { join as
|
|
54531
|
+
import { join as join17 } from "node:path";
|
|
54703
54532
|
var copilotAdapter;
|
|
54704
54533
|
var init_copilot = __esm({
|
|
54705
54534
|
"server/adapters/copilot.ts"() {
|
|
@@ -54713,7 +54542,7 @@ var init_copilot = __esm({
|
|
|
54713
54542
|
name: "GitHub Copilot CLI",
|
|
54714
54543
|
description: "Local session event logs \xB7 conversations and completed file edits",
|
|
54715
54544
|
capabilities: { history: true, forks: false, children: true, files: true },
|
|
54716
|
-
roots: () => [
|
|
54545
|
+
roots: () => [join17(sourcePath("copilot") || process.env.SESSIONGRAPH_COPILOT_HOME || join17(homedir11(), ".copilot"), "session-state")],
|
|
54717
54546
|
match: (path) => /(?:^|\/)events\.jsonl$/.test(path),
|
|
54718
54547
|
parse(path, files) {
|
|
54719
54548
|
const { rows: rows2, partial: partial2 } = jsonLines(files.get(path));
|
|
@@ -54811,7 +54640,7 @@ var init_vscode_chat_log = __esm({
|
|
|
54811
54640
|
|
|
54812
54641
|
// server/adapters/copilot-chat.ts
|
|
54813
54642
|
import { homedir as homedir12 } from "node:os";
|
|
54814
|
-
import { basename as
|
|
54643
|
+
import { basename as basename7, dirname as dirname5, join as join18, posix as posix2, win32 as win323 } from "node:path";
|
|
54815
54644
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
54816
54645
|
function copilotChatRoots(platform = process.platform, home = homedir12(), env2 = process.env) {
|
|
54817
54646
|
const path = platform === "win32" ? win323 : posix2;
|
|
@@ -54928,16 +54757,16 @@ var init_copilot_chat = __esm({
|
|
|
54928
54757
|
capabilities: { history: true, forks: false, children: false, files: true },
|
|
54929
54758
|
roots,
|
|
54930
54759
|
match,
|
|
54931
|
-
authoritativeIdentity: (path) => path.endsWith(".jsonl") ?
|
|
54932
|
-
extras: (path) => [...
|
|
54760
|
+
authoritativeIdentity: (path) => path.endsWith(".jsonl") ? basename7(path, ".jsonl") : void 0,
|
|
54761
|
+
extras: (path) => [...basename7(dirname5(path)) === "chatSessions" ? [join18(dirname5(dirname5(path)), "workspace.json")] : [], ...path.endsWith(".json") ? [`${path}l`] : []],
|
|
54933
54762
|
parse(path, files) {
|
|
54934
54763
|
const log = path.endsWith(".jsonl") ? path : `${path}l`;
|
|
54935
54764
|
const data = files.has(log) ? vscodeChatLog(files.get(log)) : object4(JSON.parse(files.get(path)));
|
|
54936
54765
|
if (!text3(data.sessionId) || !Array.isArray(data.requests) || data.version !== void 0 && ![1, 2, 3].includes(data.version)) throw new Error("Unsupported VS Code chat history.");
|
|
54937
|
-
if (data.sessionId !==
|
|
54766
|
+
if (data.sessionId !== basename7(path).replace(/\.jsonl?$/, "")) throw new Error("VS Code chat identity mismatch.");
|
|
54938
54767
|
if (!data.requests.length) return;
|
|
54939
54768
|
if (data.requests.length > 25e3) throw new Error("Chat exceeds the 50,000-message limit.");
|
|
54940
|
-
const workspacePath =
|
|
54769
|
+
const workspacePath = join18(dirname5(dirname5(path)), "workspace.json");
|
|
54941
54770
|
const workspace = files.has(workspacePath) ? object4(JSON.parse(files.get(workspacePath))) : {};
|
|
54942
54771
|
const messages = chatMessages(data.requests);
|
|
54943
54772
|
const model = [...data.requests].reverse().find((r) => text3(r.modelId));
|
|
@@ -54957,7 +54786,7 @@ var init_copilot_chat = __esm({
|
|
|
54957
54786
|
|
|
54958
54787
|
// server/adapters/extensions.ts
|
|
54959
54788
|
import { homedir as homedir13 } from "node:os";
|
|
54960
|
-
import { basename as
|
|
54789
|
+
import { basename as basename8, dirname as dirname6, join as join19 } from "node:path";
|
|
54961
54790
|
function taskUsage(value, source) {
|
|
54962
54791
|
if (!Array.isArray(value)) return;
|
|
54963
54792
|
const records = /* @__PURE__ */ new Map();
|
|
@@ -54988,12 +54817,12 @@ function taskUsage(value, source) {
|
|
|
54988
54817
|
}
|
|
54989
54818
|
function editorTaskRoots(extension) {
|
|
54990
54819
|
const home = homedir13();
|
|
54991
|
-
const base = process.platform === "darwin" ?
|
|
54992
|
-
return ["Code", "Code - Insiders", "VSCodium", "Cursor", "Windsurf"].map((app) =>
|
|
54820
|
+
const base = process.platform === "darwin" ? join19(home, "Library", "Application Support") : process.platform === "win32" ? process.env.APPDATA || join19(home, "AppData", "Roaming") : process.env.XDG_CONFIG_HOME || join19(home, ".config");
|
|
54821
|
+
return ["Code", "Code - Insiders", "VSCodium", "Cursor", "Windsurf"].map((app) => join19(base, app, "User", "globalStorage", extension, "tasks")).concat([".vscode-server", ".vscode-server-insiders"].map((app) => join19(home, app, "data", "User", "globalStorage", extension, "tasks")));
|
|
54993
54822
|
}
|
|
54994
54823
|
function taskAdapter(id3, name, extension, env2) {
|
|
54995
54824
|
const home = () => sourcePath(id3) || process.env[env2];
|
|
54996
|
-
const roots2 = () => home() ? [
|
|
54825
|
+
const roots2 = () => home() ? [join19(home(), "tasks"), ...id3 === "cline" ? [join19(home(), "data", "sessions")] : []] : [...editorTaskRoots(extension), ...id3 === "cline" ? [process.env.CLINE_SESSION_DATA_DIR || join19(process.env.CLINE_DATA_DIR || join19(process.env.CLINE_DIR || join19(homedir13(), ".cline"), "data"), "sessions")] : []];
|
|
54997
54826
|
return localFileAdapter({
|
|
54998
54827
|
id: id3,
|
|
54999
54828
|
name,
|
|
@@ -55001,14 +54830,14 @@ function taskAdapter(id3, name, extension, env2) {
|
|
|
55001
54830
|
capabilities: { history: true, forks: id3 === "cline", children: true, files: true },
|
|
55002
54831
|
roots: roots2,
|
|
55003
54832
|
match: (path) => /^[^/]+\/api_conversation_history\.json$/.test(path) || id3 === "cline" && /^[^/]+\/[^/]+\.messages\.json$/.test(path),
|
|
55004
|
-
extras: (path) => ["history_item.json", "task_metadata.json", "session.json", "ui_messages.json"].map((file2) =>
|
|
54833
|
+
extras: (path) => ["history_item.json", "task_metadata.json", "session.json", "ui_messages.json"].map((file2) => join19(dirname6(path), file2)),
|
|
55005
54834
|
parse(path, files) {
|
|
55006
54835
|
const sdk = path.endsWith(".messages.json"), value = json4(files.get(path));
|
|
55007
54836
|
const records = sdk ? object4(value).messages : value;
|
|
55008
54837
|
if (!Array.isArray(records) || sdk && !text3(value.sessionId)) throw new Error("Unsupported task history.");
|
|
55009
|
-
const
|
|
55010
|
-
const history =
|
|
55011
|
-
const nativeID = sdk ? value.sessionId :
|
|
54838
|
+
const read2 = (name2) => object4(files.has(join19(dirname6(path), name2)) ? json4(files.get(join19(dirname6(path), name2))) : void 0);
|
|
54839
|
+
const history = read2("history_item.json"), info = read2("session.json"), task = read2("task_metadata.json");
|
|
54840
|
+
const nativeID = sdk ? value.sessionId : basename8(dirname6(path));
|
|
55012
54841
|
if (history.id && history.id !== nativeID || info.session_id && info.session_id !== nativeID) throw new Error("Task metadata identity mismatch.");
|
|
55013
54842
|
const messages = records.map((raw, index) => {
|
|
55014
54843
|
const row = object4(raw), message2 = conversationMessage(row, `record:${index}`);
|
|
@@ -55048,7 +54877,7 @@ function taskAdapter(id3, name, extension, env2) {
|
|
|
55048
54877
|
title: text3(history.task || info.metadata?.title),
|
|
55049
54878
|
model: text3(lastModel?.modelInfo?.id || lastModel?.model || info.model) || "Unknown model",
|
|
55050
54879
|
provider: text3(lastModel?.modelInfo?.provider || info.provider),
|
|
55051
|
-
usage: !sdk && files.has(
|
|
54880
|
+
usage: !sdk && files.has(join19(dirname6(path), "ui_messages.json")) ? taskUsage(json4(files.get(join19(dirname6(path), "ui_messages.json"))), id3) : void 0
|
|
55052
54881
|
},
|
|
55053
54882
|
note: sdk ? void 0 : "Earlier and editor-only messages may be missing."
|
|
55054
54883
|
};
|
|
@@ -55073,14 +54902,14 @@ var init_extensions = __esm({
|
|
|
55073
54902
|
name: "Continue",
|
|
55074
54903
|
description: "Local IDE and CLI session JSON \xB7 recorded conversation and tool history",
|
|
55075
54904
|
capabilities: { history: true, forks: false, children: false, files: false },
|
|
55076
|
-
roots: () => [
|
|
54905
|
+
roots: () => [join19(sourcePath("continue") || process.env.SESSIONGRAPH_CONTINUE_HOME || process.env.CONTINUE_GLOBAL_DIR || join19(homedir13(), ".continue"), "sessions")],
|
|
55077
54906
|
match: (path) => /^[^/]+\.json$/.test(path) && path !== "sessions.json",
|
|
55078
|
-
extras: (path) => [
|
|
54907
|
+
extras: (path) => [join19(dirname6(path), "sessions.json")],
|
|
55079
54908
|
revisionExtras: false,
|
|
55080
54909
|
parse(path, files) {
|
|
55081
54910
|
const value = object4(json4(files.get(path)));
|
|
55082
54911
|
if (!text3(value.sessionId) || !Array.isArray(value.history)) throw new Error("Unsupported Continue session.");
|
|
55083
|
-
const indexPath =
|
|
54912
|
+
const indexPath = join19(dirname6(path), "sessions.json"), index = files.has(indexPath) ? json4(files.get(indexPath)) : [];
|
|
55084
54913
|
const meta3 = Array.isArray(index) ? object4(index.find((r) => r.sessionId === value.sessionId)) : {};
|
|
55085
54914
|
const messages = value.history.map((item, i) => {
|
|
55086
54915
|
const row = object4(item), raw = object4(row.message), message2 = conversationMessage(raw, `record:${i}`);
|
|
@@ -55114,33 +54943,12 @@ var init_extensions = __esm({
|
|
|
55114
54943
|
}
|
|
55115
54944
|
});
|
|
55116
54945
|
|
|
55117
|
-
// server/adapters/harness-paths.ts
|
|
55118
|
-
import { homedir as homedir14 } from "node:os";
|
|
55119
|
-
import { join as join19 } from "node:path";
|
|
55120
|
-
var homePath, dataPath, configPath, appPath, tokscalePath, envHome, harnessRoots;
|
|
55121
|
-
var init_harness_paths = __esm({
|
|
55122
|
-
"server/adapters/harness-paths.ts"() {
|
|
55123
|
-
"use strict";
|
|
55124
|
-
init_source_paths();
|
|
55125
|
-
homePath = (...parts) => join19(homedir14(), ...parts);
|
|
55126
|
-
dataPath = (...parts) => join19(process.env.XDG_DATA_HOME || homePath(".local/share"), ...parts);
|
|
55127
|
-
configPath = (...parts) => join19(process.env.XDG_CONFIG_HOME || homePath(".config"), ...parts);
|
|
55128
|
-
appPath = (...parts) => join19(process.platform === "darwin" ? homePath("Library/Application Support") : process.platform === "win32" ? process.env.APPDATA || homePath("AppData/Roaming") : process.env.XDG_CONFIG_HOME || homePath(".config"), ...parts);
|
|
55129
|
-
tokscalePath = (...parts) => join19(process.env.TOKSCALE_CONFIG_DIR || (process.platform === "win32" ? appPath("tokscale") : configPath("tokscale")), ...parts);
|
|
55130
|
-
envHome = (env2, fallback, ...parts) => join19(process.env[env2]?.trim() || homePath(fallback), ...parts);
|
|
55131
|
-
harnessRoots = (id3, defaults) => () => {
|
|
55132
|
-
const override = sourcePath(id3) || process.env[`SESSIONGRAPH_${id3.replace(/-/g, "_").toUpperCase()}_HISTORY_DIR`]?.trim();
|
|
55133
|
-
return override ? [override] : defaults();
|
|
55134
|
-
};
|
|
55135
|
-
}
|
|
55136
|
-
});
|
|
55137
|
-
|
|
55138
54946
|
// server/adapters/harness-extra-formats.ts
|
|
55139
|
-
import { basename as
|
|
54947
|
+
import { basename as basename9, dirname as dirname7, join as join20 } from "node:path";
|
|
55140
54948
|
function kiroHistory(path, files) {
|
|
55141
54949
|
const header = object4(json4(files.get(path)));
|
|
55142
|
-
const ide2 =
|
|
55143
|
-
const nativeID = text3(header.session_id || header.sessionId || header.id) || (ide2 ?
|
|
54950
|
+
const ide2 = basename9(path) === "session.json";
|
|
54951
|
+
const nativeID = text3(header.session_id || header.sessionId || header.id) || (ide2 ? basename9(dirname7(path)) : "");
|
|
55144
54952
|
if (!nativeID) throw new Error("Unsupported Kiro session header.");
|
|
55145
54953
|
const side = ide2 ? join20(dirname7(path), "messages.jsonl") : path.replace(/\.json$/, ".jsonl");
|
|
55146
54954
|
if (!files.has(side)) throw new Error("Kiro conversation sidecar is unavailable.");
|
|
@@ -55202,7 +55010,7 @@ function muxHistory(path, files) {
|
|
|
55202
55010
|
cost: buckets.every((bucket) => recordedCost(bucket.cost_usd) !== null) ? buckets.reduce((sum, bucket) => sum + bucket.cost_usd, 0) : null
|
|
55203
55011
|
});
|
|
55204
55012
|
}).filter((value) => value !== void 0);
|
|
55205
|
-
return { nativeID:
|
|
55013
|
+
return { nativeID: basename9(dirname7(path)), messages, partial: true, session: { usage: sessionUsage(sumUsage(models), models.some((value) => value.total === null)) } };
|
|
55206
55014
|
}
|
|
55207
55015
|
function devinDesktopHistory(path, files) {
|
|
55208
55016
|
const { rows: rows2 } = jsonLines(files.get(path));
|
|
@@ -55222,11 +55030,11 @@ var init_harness_extra_formats = __esm({
|
|
|
55222
55030
|
});
|
|
55223
55031
|
|
|
55224
55032
|
// server/adapters/harness-files.ts
|
|
55225
|
-
import { basename as
|
|
55033
|
+
import { basename as basename10, dirname as dirname8, join as join21 } from "node:path";
|
|
55226
55034
|
function kimiHistory(path, files) {
|
|
55227
55035
|
const { rows: rows2 } = jsonLines(files.get(path));
|
|
55228
|
-
const folder = dirname8(path), id3 =
|
|
55229
|
-
const nativeID = agent ? `${
|
|
55036
|
+
const folder = dirname8(path), id3 = basename10(folder), agent = basename10(dirname8(folder)) === "agents";
|
|
55037
|
+
const nativeID = agent ? `${basename10(dirname8(dirname8(folder)))}/agent/${id3}` : id3;
|
|
55230
55038
|
const wire = join21(folder, "wire.jsonl"), wireRows = files.has(wire) ? jsonLines(files.get(wire)).rows : [];
|
|
55231
55039
|
const messages = rows2.flatMap((r, i) => {
|
|
55232
55040
|
const m = message(r, nativeText(r.id) || `context:${i}`);
|
|
@@ -55246,7 +55054,7 @@ function museHistory(path, files) {
|
|
|
55246
55054
|
const meta3 = rows2.find((r) => r.payload_type === "runtime.session.metadata");
|
|
55247
55055
|
const ids = new Set(rows2.map((r) => text3(r.stream?.id)).filter(Boolean));
|
|
55248
55056
|
if (!meta3 || ids.size > 1) throw new Error("Unsupported Muse stream.");
|
|
55249
|
-
const nativeID = [...ids][0] ||
|
|
55057
|
+
const nativeID = [...ids][0] || basename10(dirname8(path));
|
|
55250
55058
|
const messages = rows2.flatMap((r, i) => {
|
|
55251
55059
|
const event = object4(r.payload?.event), body = object4(event.message);
|
|
55252
55060
|
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) : time3(r.recorded_at);
|
|
@@ -55264,7 +55072,7 @@ function junieHistory(path, files) {
|
|
|
55264
55072
|
return [recordEvent(r, text3(r.id) || `event:${i}`, kind, r.timestampMs, e10.text ?? e10.prompt ?? e10.message)];
|
|
55265
55073
|
});
|
|
55266
55074
|
if (!messages.length) throw new Error("No supported Junie events.");
|
|
55267
|
-
return { nativeID:
|
|
55075
|
+
return { nativeID: basename10(dirname8(path)), messages, partial: true, note: "Recorded events only." };
|
|
55268
55076
|
}
|
|
55269
55077
|
function augmentHistory(path, files) {
|
|
55270
55078
|
const r = object4(json4(files.get(path)));
|
|
@@ -55326,7 +55134,7 @@ var init_harness_files = __esm({
|
|
|
55326
55134
|
promaRoots = () => [".proma", ".proma-dev"].flatMap((p) => ["agent-sessions", "sdk-config/sessions", "sdk-config/projects"].map((s) => homePath(p, s)));
|
|
55327
55135
|
definitions = [
|
|
55328
55136
|
...piSources,
|
|
55329
|
-
{ id: "kiro", name: "Kiro", roots: () => [homePath(".kiro/sessions"), appPath("Kiro/User/globalStorage/kiro.kiroagent")], match: (p) => p.endsWith("/session.json") || /^cli\/[^/]+\.json$/.test(p), extras: (p) => [
|
|
55137
|
+
{ id: "kiro", name: "Kiro", roots: () => [homePath(".kiro/sessions"), appPath("Kiro/User/globalStorage/kiro.kiroagent")], match: (p) => p.endsWith("/session.json") || /^cli\/[^/]+\.json$/.test(p), extras: (p) => [basename10(p) === "session.json" ? join21(dirname8(p), "messages.jsonl") : p.replace(/\.json$/, ".jsonl")], parse: kiroHistory },
|
|
55330
55138
|
{ id: "mux", name: "Mux", roots: () => [envHome("MUX_ROOT", ".mux", "sessions")], match: (p) => p.endsWith("/chat.jsonl"), extras: (p) => [join21(dirname8(p), "chat-archive.jsonl"), join21(dirname8(p), "session-usage.json")], parse: muxHistory },
|
|
55331
55139
|
{ id: "devin-desktop", name: "Devin Desktop", roots: () => [appPath("Devin/User/acp-events")], match: (p) => /\.(ndjson|jsonl)$/.test(p), parse: devinDesktopHistory },
|
|
55332
55140
|
{ id: "openclaw", name: "OpenClaw", roots: openclawRoots, match: (p) => /(?:^|\/)sessions\/.*\.jsonl(?:\.[\w.-]+)?$/.test(p) || /session-sqlite-import-archive\/.*\.jsonl\./.test(p), parse: piParse },
|
|
@@ -55346,10 +55154,10 @@ var init_harness_files = __esm({
|
|
|
55346
55154
|
{ id: "deepseek-harness", name: "DeepSeek Harness", roots: () => [envHome("DSH_HOME", ".dsh", "sessions")], match: (p) => /(?:^|\/)session(?:\.v\d+)?\.jsonl(?:\.zstd)?$/.test(p), parse: (p, f) => dshHistory(f.get(p)) },
|
|
55347
55155
|
{ id: "aside", name: "Aside", roots: () => [homePath(".aside/u")], match: (p) => /^[^/]+\/sessions\/[^/]+\/messages\.jsonl$/.test(p), parse(p, f) {
|
|
55348
55156
|
const h3 = envelopeHistory(p, f.get(p));
|
|
55349
|
-
h3.nativeID = `${
|
|
55157
|
+
h3.nativeID = `${basename10(dirname8(dirname8(dirname8(p))))}/${basename10(dirname8(p))}`;
|
|
55350
55158
|
return h3;
|
|
55351
55159
|
} },
|
|
55352
|
-
{ id: "vibe", name: "Mistral Vibe", roots: () => [envHome("VIBE_HOME", ".vibe", "logs/session")], match: (p) => p.endsWith("/meta.json") || /^[^/]+\.json$/.test(p), extras: (p) =>
|
|
55160
|
+
{ id: "vibe", name: "Mistral Vibe", roots: () => [envHome("VIBE_HOME", ".vibe", "logs/session")], match: (p) => p.endsWith("/meta.json") || /^[^/]+\.json$/.test(p), extras: (p) => basename10(p) === "meta.json" ? [join21(dirname8(p), "messages.jsonl")] : [], parse: vibeHistory },
|
|
55353
55161
|
{ id: "muse", name: "Muse Code", roots: () => [dataPath("muse/sessions")], match: (p) => p.endsWith("/session.jsonl"), parse: museHistory },
|
|
55354
55162
|
{ id: "junie", name: "Junie", roots: () => [homePath(".junie/sessions")], match: (p) => p.endsWith("/events.jsonl"), parse: junieHistory, description: "Local agent event history \xB7 partial conversation coverage" },
|
|
55355
55163
|
{ id: "augment", name: "Augment Code", roots: () => [homePath(".augment/sessions")], match: (p) => p.endsWith(".json"), parse: augmentHistory, description: "Local exchange records \xB7 partial conversation coverage" },
|
|
@@ -55381,7 +55189,7 @@ var init_harness_files = __esm({
|
|
|
55381
55189
|
});
|
|
55382
55190
|
|
|
55383
55191
|
// server/adapters/harness-databases.ts
|
|
55384
|
-
import { lstat as
|
|
55192
|
+
import { lstat as lstat7, readFile as readFile3 } from "node:fs/promises";
|
|
55385
55193
|
import { isAbsolute as isAbsolute7, join as join22 } from "node:path";
|
|
55386
55194
|
function hermesContent(value) {
|
|
55387
55195
|
if (typeof value !== "string" || !value.startsWith("\0json:")) return value;
|
|
@@ -55620,9 +55428,9 @@ var init_harness_databases = __esm({
|
|
|
55620
55428
|
if (override) return (await historyFiles([override], (p) => p.endsWith("crush.db"))).files;
|
|
55621
55429
|
const registry2 = join22(process.env.CRUSH_GLOBAL_DATA || dataPath("crush"), "projects.json");
|
|
55622
55430
|
try {
|
|
55623
|
-
const stat3 = await
|
|
55431
|
+
const stat3 = await lstat7(registry2);
|
|
55624
55432
|
if (!stat3.isFile() || stat3.size > 2e6) throw new Error("Unsupported Crush registry.");
|
|
55625
|
-
const raw = JSON.parse(await
|
|
55433
|
+
const raw = JSON.parse(await readFile3(registry2, "utf8"));
|
|
55626
55434
|
const paths2 = [];
|
|
55627
55435
|
for (const p of Array.isArray(raw.projects) ? raw.projects.slice(0, 2e4) : []) {
|
|
55628
55436
|
if (!isAbsolute7(text3(p.path)) || !text3(p.data_dir)) continue;
|
|
@@ -55746,7 +55554,7 @@ var init_harness_databases = __esm({
|
|
|
55746
55554
|
});
|
|
55747
55555
|
|
|
55748
55556
|
// server/adapters/harness-metadata.ts
|
|
55749
|
-
import { basename as
|
|
55557
|
+
import { basename as basename11 } from "node:path";
|
|
55750
55558
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
55751
55559
|
function protoFields(value) {
|
|
55752
55560
|
if (value.length > 2e6) throw new Error("Trajectory metadata exceeds 2 MB.");
|
|
@@ -55809,7 +55617,7 @@ var init_harness_metadata = __esm({
|
|
|
55809
55617
|
}
|
|
55810
55618
|
}
|
|
55811
55619
|
if (!created) throw new Error("Trajectory creation time is unavailable.");
|
|
55812
|
-
return { nativeID:
|
|
55620
|
+
return { nativeID: basename11(path, ".db"), messages: [], partial: true, session: { created, directory: directory3 }, note: "Session metadata only." };
|
|
55813
55621
|
}
|
|
55814
55622
|
}));
|
|
55815
55623
|
antigravityCacheAdapter = localFileAdapter({
|
|
@@ -58799,7 +58607,7 @@ var init_protocol = __esm({
|
|
|
58799
58607
|
* @param sessionId Session of the request that waits, passed to the task store
|
|
58800
58608
|
* @returns Promise that resolves when an update occurs or rejects if aborted
|
|
58801
58609
|
*/
|
|
58802
|
-
async _waitForTaskUpdate(taskId,
|
|
58610
|
+
async _waitForTaskUpdate(taskId, signal, sessionId) {
|
|
58803
58611
|
let interval = this._options?.defaultTaskPollInterval ?? 1e3;
|
|
58804
58612
|
try {
|
|
58805
58613
|
const task = await this._taskStore?.getTask(taskId, sessionId);
|
|
@@ -58809,12 +58617,12 @@ var init_protocol = __esm({
|
|
|
58809
58617
|
} catch {
|
|
58810
58618
|
}
|
|
58811
58619
|
return new Promise((resolve3, reject) => {
|
|
58812
|
-
if (
|
|
58620
|
+
if (signal.aborted) {
|
|
58813
58621
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
58814
58622
|
return;
|
|
58815
58623
|
}
|
|
58816
58624
|
const timeoutId = setTimeout(resolve3, interval);
|
|
58817
|
-
|
|
58625
|
+
signal.addEventListener("abort", () => {
|
|
58818
58626
|
clearTimeout(timeoutId);
|
|
58819
58627
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
58820
58628
|
}, { once: true });
|
|
@@ -63559,15 +63367,15 @@ var require_core = __commonJS({
|
|
|
63559
63367
|
}
|
|
63560
63368
|
return metaSchema;
|
|
63561
63369
|
}
|
|
63562
|
-
_removeAllSchemas(
|
|
63563
|
-
for (const keyRef in
|
|
63564
|
-
const sch =
|
|
63370
|
+
_removeAllSchemas(schemas2, regex) {
|
|
63371
|
+
for (const keyRef in schemas2) {
|
|
63372
|
+
const sch = schemas2[keyRef];
|
|
63565
63373
|
if (!regex || regex.test(keyRef)) {
|
|
63566
63374
|
if (typeof sch == "string") {
|
|
63567
|
-
delete
|
|
63375
|
+
delete schemas2[keyRef];
|
|
63568
63376
|
} else if (sch && !sch.meta) {
|
|
63569
63377
|
this._cache.delete(sch.schema);
|
|
63570
|
-
delete
|
|
63378
|
+
delete schemas2[keyRef];
|
|
63571
63379
|
}
|
|
63572
63380
|
}
|
|
63573
63381
|
}
|
|
@@ -66973,19 +66781,19 @@ async function runAgentMcp(library, version2) {
|
|
|
66973
66781
|
const closed = new Promise((resolve3) => {
|
|
66974
66782
|
server.onclose = resolve3;
|
|
66975
66783
|
});
|
|
66976
|
-
const
|
|
66784
|
+
const stop = () => {
|
|
66977
66785
|
void server.close();
|
|
66978
66786
|
};
|
|
66979
|
-
process.stdin.once("end",
|
|
66980
|
-
process.once("SIGTERM",
|
|
66981
|
-
process.once("SIGINT",
|
|
66787
|
+
process.stdin.once("end", stop);
|
|
66788
|
+
process.once("SIGTERM", stop);
|
|
66789
|
+
process.once("SIGINT", stop);
|
|
66982
66790
|
try {
|
|
66983
66791
|
await server.connect(new StdioServerTransport());
|
|
66984
66792
|
await closed;
|
|
66985
66793
|
} finally {
|
|
66986
|
-
process.stdin.off("end",
|
|
66987
|
-
process.off("SIGTERM",
|
|
66988
|
-
process.off("SIGINT",
|
|
66794
|
+
process.stdin.off("end", stop);
|
|
66795
|
+
process.off("SIGTERM", stop);
|
|
66796
|
+
process.off("SIGINT", stop);
|
|
66989
66797
|
await server.close();
|
|
66990
66798
|
}
|
|
66991
66799
|
}
|
|
@@ -67459,12 +67267,12 @@ var SessionGraphStore = class {
|
|
|
67459
67267
|
commits(id3, options = {}) {
|
|
67460
67268
|
return this.readSnapshot(id3, (session) => readCommits(this.db, session, options));
|
|
67461
67269
|
}
|
|
67462
|
-
readSnapshot(id3,
|
|
67270
|
+
readSnapshot(id3, read2) {
|
|
67463
67271
|
this.db.exec("BEGIN");
|
|
67464
67272
|
try {
|
|
67465
67273
|
const session = this.getSession(id3);
|
|
67466
67274
|
if (!session) throw new Error("Session not imported.");
|
|
67467
|
-
const result =
|
|
67275
|
+
const result = read2(session);
|
|
67468
67276
|
this.db.exec("COMMIT");
|
|
67469
67277
|
return result;
|
|
67470
67278
|
} catch (error62) {
|
|
@@ -69855,10 +69663,10 @@ var LibraryService = class {
|
|
|
69855
69663
|
validateSources(ids) {
|
|
69856
69664
|
for (const id3 of ids) if (!this.importer.adapters.some((a) => a.id === id3)) invalid(`Unknown source "${id3}". Run sessiongraph sources list.`);
|
|
69857
69665
|
}
|
|
69858
|
-
snapshot(
|
|
69666
|
+
snapshot(read2) {
|
|
69859
69667
|
this.store.db.exec("BEGIN");
|
|
69860
69668
|
try {
|
|
69861
|
-
const result =
|
|
69669
|
+
const result = read2();
|
|
69862
69670
|
this.store.db.exec("COMMIT");
|
|
69863
69671
|
return result;
|
|
69864
69672
|
} catch (error62) {
|
|
@@ -69883,7 +69691,7 @@ var LibraryService = class {
|
|
|
69883
69691
|
async discoverSources() {
|
|
69884
69692
|
const paths2 = this.store.setting("sourcePaths") || {};
|
|
69885
69693
|
return {
|
|
69886
|
-
sources: (await this.importer.sources()).map((source) => ({ ...source, path: paths2[source.id] || null, pathSupported:
|
|
69694
|
+
sources: (await this.importer.sources()).map((source) => ({ ...source, path: paths2[source.id] || null, pathSupported: true, pathHint: sourcePathHint(source.id) })),
|
|
69887
69695
|
configured: this.store.setting("selected") !== void 0,
|
|
69888
69696
|
autoImport: this.store.autoImportEnabled()
|
|
69889
69697
|
};
|
|
@@ -69909,7 +69717,7 @@ var LibraryService = class {
|
|
|
69909
69717
|
if (options.detected && ids.length) invalid("Choose source IDs or --detected, not both.");
|
|
69910
69718
|
if (options.path !== void 0 && options.defaultPath) invalid("Choose --path or --default-path, not both.");
|
|
69911
69719
|
if (options.path !== void 0 || options.defaultPath) {
|
|
69912
|
-
if (ids.length !== 1
|
|
69720
|
+
if (ids.length !== 1) invalid("A path override requires exactly one filesystem source.");
|
|
69913
69721
|
if (options.path !== void 0 && (!options.path.trim() || options.path.includes("\0"))) invalid("Choose a nonempty local source directory.");
|
|
69914
69722
|
}
|
|
69915
69723
|
if (options.detected) ids = (await this.discoverSources()).sources.filter((s) => s.available).map((s) => s.id);
|
|
@@ -70116,7 +69924,7 @@ var LibraryService = class {
|
|
|
70116
69924
|
const sources = await this.discoverSources(), checks = [];
|
|
70117
69925
|
const integrity = this.store.db.prepare("PRAGMA quick_check").all();
|
|
70118
69926
|
checks.push({ name: "database", ok: integrity.every((row) => row.quick_check === "ok"), message: integrity.map((row) => String(row.quick_check)).join("; ") });
|
|
70119
|
-
for (const source of sources.sources.filter((s) => s.selected)) checks.push({ name: source.id, ok: source.available && !source.error, message: source.error || (source.available ? "Available" :
|
|
69927
|
+
for (const source of sources.sources.filter((s) => s.selected)) checks.push({ name: source.id, ok: source.available && !source.error, message: source.error || (source.available ? "Available" : "History unavailable. Check the source path and permissions.") });
|
|
70120
69928
|
const lock = this.store.db.prepare("SELECT pid,heartbeat FROM import_lock WHERE id=1").get();
|
|
70121
69929
|
return {
|
|
70122
69930
|
ok: checks.every((c) => c.ok),
|
|
@@ -70393,20 +70201,20 @@ async function runCli(argv, io = {}) {
|
|
|
70393
70201
|
const server = await http.startAgentHttp(library, port, credential, version2);
|
|
70394
70202
|
const url2 = `http://127.0.0.1:${server.address().port}`;
|
|
70395
70203
|
const closed = new Promise((resolve3) => server.once("close", resolve3));
|
|
70396
|
-
const
|
|
70204
|
+
const stop = () => {
|
|
70397
70205
|
server.close();
|
|
70398
70206
|
server.closeAllConnections();
|
|
70399
70207
|
};
|
|
70400
|
-
process.once("SIGINT",
|
|
70401
|
-
process.once("SIGTERM",
|
|
70208
|
+
process.once("SIGINT", stop);
|
|
70209
|
+
process.once("SIGTERM", stop);
|
|
70402
70210
|
try {
|
|
70403
70211
|
if (json6) emit({ url: url2 });
|
|
70404
70212
|
else stderr(`Listening on ${url2}
|
|
70405
70213
|
`);
|
|
70406
70214
|
await closed;
|
|
70407
70215
|
} finally {
|
|
70408
|
-
process.off("SIGINT",
|
|
70409
|
-
process.off("SIGTERM",
|
|
70216
|
+
process.off("SIGINT", stop);
|
|
70217
|
+
process.off("SIGTERM", stop);
|
|
70410
70218
|
}
|
|
70411
70219
|
} else await (await Promise.resolve().then(() => (init_agent_mcp(), agent_mcp_exports))).runAgentMcp(library, version2);
|
|
70412
70220
|
return 0;
|