sessiongraph-app-darwin-arm64 1.0.21 → 1.0.23
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-launcher.mjs +2 -1
- package/payload/SessionGraph.app/Contents/Resources/resources/cli-package.json +1 -1
- package/payload/SessionGraph.app/Contents/Resources/resources/cli.mjs +399 -211
- package/payload/SessionGraph.app/Contents/Resources/resources/server.mjs +182 -19
- package/payload/SessionGraph.app/Contents/_CodeSignature/CodeResources +8 -8
|
@@ -2833,12 +2833,12 @@ function summarizeUsage(session, messages, historyPartial) {
|
|
|
2833
2833
|
const lastSnapshot = cumulative.at(-1);
|
|
2834
2834
|
if (lastSnapshot?.usage) return sessionUsage(lastSnapshot.usage, true);
|
|
2835
2835
|
const unique = /* @__PURE__ */ new Map();
|
|
2836
|
-
let
|
|
2836
|
+
let missing2 = 0;
|
|
2837
2837
|
for (const message2 of messages) {
|
|
2838
2838
|
if (message2.usage?.scope === "message") {
|
|
2839
2839
|
const key = message2.usage.id || message2.id, previous = unique.get(key);
|
|
2840
2840
|
unique.set(key, previous ? mergeUsage(previous, message2.usage) : message2.usage);
|
|
2841
|
-
} else if (message2.role === "assistant")
|
|
2841
|
+
} else if (message2.role === "assistant") missing2++;
|
|
2842
2842
|
}
|
|
2843
2843
|
const records = [...unique.values()], known = records.filter((value) => value.total !== null);
|
|
2844
2844
|
if (!known.length && native) return { ...native, partial: true };
|
|
@@ -2852,8 +2852,8 @@ function summarizeUsage(session, messages, historyPartial) {
|
|
|
2852
2852
|
costEstimated: totals.cost !== null ? totals.costEstimated : native?.cost != null ? native.costEstimated : void 0,
|
|
2853
2853
|
source: records.length ? "messages" : "unavailable",
|
|
2854
2854
|
reportedMessages: known.length,
|
|
2855
|
-
missingMessages:
|
|
2856
|
-
partial: historyPartial || total === null ||
|
|
2855
|
+
missingMessages: missing2 + records.length - known.length,
|
|
2856
|
+
partial: historyPartial || total === null || missing2 > 0 || known.length !== records.length || !records.length
|
|
2857
2857
|
};
|
|
2858
2858
|
}
|
|
2859
2859
|
|
|
@@ -3781,6 +3781,12 @@ function hasTable(db2, name) {
|
|
|
3781
3781
|
return typeof row?.sql === "string" && !/CREATE\s+VIRTUAL/i.test(row.sql);
|
|
3782
3782
|
}
|
|
3783
3783
|
|
|
3784
|
+
// server/sqlite.ts
|
|
3785
|
+
function iterate(db2, sql, ...values) {
|
|
3786
|
+
const statement = db2.prepare(sql);
|
|
3787
|
+
return Object.assign(statement.iterate(...values), { retainedStatement: statement });
|
|
3788
|
+
}
|
|
3789
|
+
|
|
3784
3790
|
// server/adapters/sqlite-histories.ts
|
|
3785
3791
|
var budget;
|
|
3786
3792
|
var rowBytes = (row) => Object.values(row).reduce((n, v3) => n + (typeof v3 === "string" ? Buffer.byteLength(v3) : v3 instanceof Uint8Array ? v3.byteLength : 8), 0);
|
|
@@ -3811,14 +3817,18 @@ function rows(db2, table, fields3, filter, order, limit = 5e4) {
|
|
|
3811
3817
|
for (const name of [...fields3, ...filter ? [filter[0]] : [], ...order ? [order] : []]) if (!/^[a-zA-Z_][\w]*$/.test(name)) throw new Error("Invalid history column.");
|
|
3812
3818
|
if (filter && !available.has(filter[0])) throw new Error("Unsupported history relation.");
|
|
3813
3819
|
const size = (f) => `length(CAST("${f}" AS BLOB))`;
|
|
3814
|
-
const select = fields3.map((f) => available.has(f) ? `CASE WHEN ${size(f)}<=32000000 THEN "${f}" END AS "${f}"` : `NULL AS "${f}"`).join(",");
|
|
3820
|
+
const select = fields3.map((f) => available.has(f) ? `CASE WHEN ${size(f)}<=32000000 THEN CASE WHEN typeof("${f}")='text' THEN CAST("${f}" AS BLOB) ELSE "${f}" END END AS "${f}", typeof("${f}")='text' AS "__sessiongraph_text_${f}"` : `NULL AS "${f}"`).join(",");
|
|
3815
3821
|
const oversized = fields3.filter((f) => available.has(f)).map((f) => `COALESCE(${size(f)},0)>32000000`).join(" OR ") || "0";
|
|
3816
3822
|
const query = `SELECT ${select}, (${oversized}) AS __sessiongraph_oversized FROM "${table}"${filter ? ` WHERE "${filter[0]}"=?` : ""}${order && available.has(order) ? ` ORDER BY "${order}"` : ""} LIMIT ${limit + 1}`;
|
|
3817
3823
|
const result = [];
|
|
3818
3824
|
let bytes2 = 0;
|
|
3819
|
-
for (const row of db2
|
|
3825
|
+
for (const row of iterate(db2, query, ...filter ? [filter[1]] : [])) {
|
|
3820
3826
|
if (row.__sessiongraph_oversized) throw new Error("History field exceeds the 32 MB snapshot limit.");
|
|
3821
3827
|
delete row.__sessiongraph_oversized;
|
|
3828
|
+
for (const field of fields3) {
|
|
3829
|
+
if (row[`__sessiongraph_text_${field}`] && row[field] instanceof Uint8Array) row[field] = Buffer.from(row[field]).toString("utf8");
|
|
3830
|
+
delete row[`__sessiongraph_text_${field}`];
|
|
3831
|
+
}
|
|
3822
3832
|
const size2 = rowBytes(row);
|
|
3823
3833
|
bytes2 += size2;
|
|
3824
3834
|
consume(size2, 1);
|
|
@@ -4105,7 +4115,7 @@ function historyRevisions(db2, schema) {
|
|
|
4105
4115
|
const names = columns(db2, table);
|
|
4106
4116
|
if (!names.has("session_id")) continue;
|
|
4107
4117
|
const updated = names.has("time_updated") ? "MAX(time_updated)" : "NULL";
|
|
4108
|
-
for (const row of db2
|
|
4118
|
+
for (const row of iterate(db2, `SELECT session_id, COUNT(*) AS count, ${updated} AS updated FROM "${table}" GROUP BY session_id`)) {
|
|
4109
4119
|
const id2 = text(row.session_id);
|
|
4110
4120
|
result.set(id2, [...result.get(id2) || [], row.count, row.updated]);
|
|
4111
4121
|
}
|
|
@@ -4194,7 +4204,7 @@ function discoverDatabase(db2, path, snapshot2) {
|
|
|
4194
4204
|
}
|
|
4195
4205
|
function payloadRows(db2, query, values, budget2) {
|
|
4196
4206
|
const result = [];
|
|
4197
|
-
for (const row of db2
|
|
4207
|
+
for (const row of iterate(db2, query, ...values)) {
|
|
4198
4208
|
if (typeof row.data !== "string") throw new Error("OpenCode history contains a missing or oversized JSON field (4 MB limit).");
|
|
4199
4209
|
budget2.bytes += Buffer.byteLength(row.data);
|
|
4200
4210
|
budget2.records++;
|
|
@@ -4206,7 +4216,7 @@ function payloadRows(db2, query, values, budget2) {
|
|
|
4206
4216
|
var opencodeAdapter = {
|
|
4207
4217
|
id: "opencode",
|
|
4208
4218
|
name: "OpenCode",
|
|
4209
|
-
description: "Local SQLite history \xB7 V1 and V2
|
|
4219
|
+
description: "Local SQLite history \xB7 V1 and V2",
|
|
4210
4220
|
capabilities: { history: true, forks: true, children: true, files: true },
|
|
4211
4221
|
async detect() {
|
|
4212
4222
|
return (await openCodeDatabases()).length > 0;
|
|
@@ -32549,7 +32559,7 @@ function discoverComposers(path, workspace = "") {
|
|
|
32549
32559
|
for (const table of ["cursorDiskKV", "ItemTable"]) {
|
|
32550
32560
|
if (!hasTable(db2, table)) continue;
|
|
32551
32561
|
let failed = 0, count = 0;
|
|
32552
|
-
const rows2 = db2
|
|
32562
|
+
const rows2 = iterate(db2, `SELECT key, CASE WHEN length(value)<=? THEN value END AS value FROM ${table} WHERE key LIKE 'composerData:%' AND value IS NOT NULL ORDER BY key LIMIT 20001`, MAX_VALUE2);
|
|
32553
32563
|
for (const row of rows2) {
|
|
32554
32564
|
if (++count > 2e4) {
|
|
32555
32565
|
warnings.push("Cursor Composer listing reached its 20,000-session limit.");
|
|
@@ -34345,7 +34355,7 @@ function writeCommits(db2, session) {
|
|
|
34345
34355
|
if (!supported.has(session.source || "")) return { ...base, state: "unavailable", count: null, note: "Commit history unavailable for this source." };
|
|
34346
34356
|
const calls = /* @__PURE__ */ new Map();
|
|
34347
34357
|
const results = /* @__PURE__ */ new Map();
|
|
34348
|
-
const rows2 = () => db2
|
|
34358
|
+
const rows2 = () => iterate(db2, "SELECT data FROM timeline_items WHERE session_id=? AND kind IN ('tool_call','tool_result') ORDER BY ordinal", session.id);
|
|
34349
34359
|
let tools = 0, partial = session.coverage?.history !== "complete" || Boolean(db2.prepare("SELECT partial FROM timeline_coverage WHERE session_id=?").get(session.id)?.partial);
|
|
34350
34360
|
for (const row of rows2()) {
|
|
34351
34361
|
const item = JSON.parse(String(row.data));
|
|
@@ -34700,7 +34710,7 @@ var SessionGraphStore = class {
|
|
|
34700
34710
|
try {
|
|
34701
34711
|
this.db.exec(EVENT_SCHEMA);
|
|
34702
34712
|
for (const { id: id2 } of this.db.prepare("SELECT id FROM sessions").all()) {
|
|
34703
|
-
writeEvents(this.db, String(id2), this.db
|
|
34713
|
+
writeEvents(this.db, String(id2), iterate(this.db, "SELECT data FROM messages WHERE session_id=? ORDER BY ordinal", id2));
|
|
34704
34714
|
}
|
|
34705
34715
|
this.db.exec("PRAGMA user_version=4; COMMIT;");
|
|
34706
34716
|
} catch (error) {
|
|
@@ -34773,6 +34783,40 @@ var SessionGraphStore = class {
|
|
|
34773
34783
|
autoImportEnabled() {
|
|
34774
34784
|
return this.setting("autoImport") === true;
|
|
34775
34785
|
}
|
|
34786
|
+
savedSources() {
|
|
34787
|
+
return [.../* @__PURE__ */ new Set([
|
|
34788
|
+
...this.selected(),
|
|
34789
|
+
...Object.keys(this.setting("sourcePaths") || {}),
|
|
34790
|
+
...this.db.prepare("SELECT source FROM sessions UNION SELECT source FROM projects UNION SELECT id AS source FROM sources").all().map((row) => String(row.source))
|
|
34791
|
+
])];
|
|
34792
|
+
}
|
|
34793
|
+
/** Called under the import lock and a caller-owned IMMEDIATE transaction.
|
|
34794
|
+
* Match native source ownership, never linked-provider display filters. */
|
|
34795
|
+
purgeSources(sources2, dryRun) {
|
|
34796
|
+
const ids = JSON.stringify(sources2), selected = "SELECT value FROM json_each(?)";
|
|
34797
|
+
const sessions = `SELECT id FROM sessions WHERE source IN (${selected})`;
|
|
34798
|
+
const count = (table, column) => Number(this.db.prepare(`SELECT COUNT(*) AS n FROM ${table} WHERE ${column} IN (${sessions})`).get(ids).n);
|
|
34799
|
+
const orphanProjects = `source IN (${selected}) AND NOT EXISTS (
|
|
34800
|
+
SELECT 1 FROM sessions WHERE json_extract(metadata,'$.projectID')=projects.id AND source NOT IN (${selected}))`;
|
|
34801
|
+
const deleted = {
|
|
34802
|
+
sessions: Number(this.db.prepare(`SELECT COUNT(*) AS n FROM sessions WHERE source IN (${selected})`).get(ids).n),
|
|
34803
|
+
messages: count("messages", "session_id"),
|
|
34804
|
+
events: count("timeline_items", "session_id"),
|
|
34805
|
+
commits: count("session_commits", "session_id"),
|
|
34806
|
+
pullRequests: count("session_pull_requests", "session_id"),
|
|
34807
|
+
searchCheckpoints: count("search_cache", "id"),
|
|
34808
|
+
projects: Number(this.db.prepare(`SELECT COUNT(*) AS n FROM projects WHERE ${orphanProjects}`).get(ids, ids).n)
|
|
34809
|
+
};
|
|
34810
|
+
if (!dryRun) {
|
|
34811
|
+
this.setting("selected", this.selected().filter((source) => !sources2.includes(source)));
|
|
34812
|
+
this.setting("sourcePaths", Object.fromEntries(Object.entries(this.setting("sourcePaths") || {}).filter(([source]) => !sources2.includes(source))));
|
|
34813
|
+
this.db.prepare(`DELETE FROM sessions WHERE source IN (${selected})`).run(ids);
|
|
34814
|
+
this.db.prepare(`DELETE FROM projects WHERE ${orphanProjects}`).run(ids, ids);
|
|
34815
|
+
this.db.prepare(`DELETE FROM sources WHERE id IN (${selected})`).run(ids);
|
|
34816
|
+
this.setting("indexEpoch", (this.setting("indexEpoch") || 0) + 1);
|
|
34817
|
+
}
|
|
34818
|
+
return deleted;
|
|
34819
|
+
}
|
|
34776
34820
|
acquireImport() {
|
|
34777
34821
|
this.db.exec("BEGIN IMMEDIATE");
|
|
34778
34822
|
try {
|
|
@@ -34852,7 +34896,7 @@ var SessionGraphStore = class {
|
|
|
34852
34896
|
this.db.prepare("DELETE FROM messages WHERE session_id=?").run(s.id);
|
|
34853
34897
|
const insert = this.db.prepare("INSERT INTO messages (session_id,id,ordinal,data,time,is_user) VALUES (?,?,?,?,?,?) ON CONFLICT(session_id,id) DO UPDATE SET ordinal=excluded.ordinal,data=excluded.data,time=excluded.time,is_user=excluded.is_user");
|
|
34854
34898
|
messages.forEach((message2, i) => insert.run(s.id, message2.id, i, JSON.stringify(message2), message2.eventOnly ? null : messageTime(message2.time), Number(isUserMessage(message2))));
|
|
34855
|
-
writeEvents(this.db, s.id, this.db
|
|
34899
|
+
writeEvents(this.db, s.id, iterate(this.db, "SELECT data FROM messages WHERE session_id=? ORDER BY ordinal", s.id));
|
|
34856
34900
|
const commits = writeCommits(this.db, s);
|
|
34857
34901
|
if (candidate.pullRequests !== void 0) {
|
|
34858
34902
|
this.db.prepare("DELETE FROM session_pull_requests WHERE session_id=?").run(s.id);
|
|
@@ -35350,6 +35394,7 @@ function launchCommand(binary, args, directory3, platform = process.platform) {
|
|
|
35350
35394
|
// server/handoff.ts
|
|
35351
35395
|
import { createHash as createHash4, randomUUID as randomUUID3 } from "node:crypto";
|
|
35352
35396
|
import { mkdir, writeFile as writeFile2, rename as rename2, rm as rm4 } from "node:fs/promises";
|
|
35397
|
+
import { renameSync as renameSync2 } from "node:fs";
|
|
35353
35398
|
import { join as join26 } from "node:path";
|
|
35354
35399
|
function handoffDocument(snapshot2) {
|
|
35355
35400
|
const { session, messages, firstUser, totalMessages } = snapshot2;
|
|
@@ -35413,7 +35458,8 @@ This handoff transfers saved text and file-change evidence, not files, credentia
|
|
|
35413
35458
|
` + chunks.map((c) => c.text).join("\n");
|
|
35414
35459
|
return { text: text2, messages: chunks.length, totalMessages, partial, note };
|
|
35415
35460
|
}
|
|
35416
|
-
async function saveHandoff(snapshot2, directory3) {
|
|
35461
|
+
async function saveHandoff(snapshot2, directory3, store) {
|
|
35462
|
+
const epoch = store?.setting("indexEpoch") || 0;
|
|
35417
35463
|
const { text: text2, ...coverage2 } = handoffDocument(snapshot2);
|
|
35418
35464
|
const digest2 = createHash4("sha256").update(text2).digest("hex");
|
|
35419
35465
|
const root2 = join26(directory3, "handoffs");
|
|
@@ -35421,7 +35467,17 @@ async function saveHandoff(snapshot2, directory3) {
|
|
|
35421
35467
|
const path = join26(root2, `${digest2}.md`), temporary = join26(root2, `.${randomUUID3()}.tmp`);
|
|
35422
35468
|
try {
|
|
35423
35469
|
await writeFile2(temporary, text2, { mode: 384, flag: "wx" });
|
|
35424
|
-
|
|
35470
|
+
if (store) {
|
|
35471
|
+
store.db.exec("BEGIN IMMEDIATE");
|
|
35472
|
+
try {
|
|
35473
|
+
if (!store.getSession(snapshot2.session.id) || epoch !== (store.setting("indexEpoch") || 0)) throw new LibraryError("STALE_CURSOR", "Saved history changed. Reload the session before preparing a handoff.");
|
|
35474
|
+
renameSync2(temporary, path);
|
|
35475
|
+
store.db.exec("COMMIT");
|
|
35476
|
+
} catch (error) {
|
|
35477
|
+
store.db.exec("ROLLBACK");
|
|
35478
|
+
throw error;
|
|
35479
|
+
}
|
|
35480
|
+
} else await rename2(temporary, path);
|
|
35425
35481
|
} finally {
|
|
35426
35482
|
await rm4(temporary, { force: true });
|
|
35427
35483
|
}
|
|
@@ -35465,7 +35521,7 @@ async function prepareLaunch(store, session, target, directory3 = session.direct
|
|
|
35465
35521
|
}
|
|
35466
35522
|
const mode = args ? "resume" : "handoff";
|
|
35467
35523
|
if (mode === "handoff" && store.path === ":memory:") invalid("Save this library before creating a context handoff.");
|
|
35468
|
-
const context2 = mode === "handoff" ? await saveHandoff(store.handoff(session.id), dirname11(store.path)).catch((error) => {
|
|
35524
|
+
const context2 = mode === "handoff" ? await saveHandoff(store.handoff(session.id), dirname11(store.path), store).catch((error) => {
|
|
35469
35525
|
throw storageFailure(error, true) ?? new LibraryError("HANDOFF_FAILED", "Could not save the session handoff.");
|
|
35470
35526
|
}) : void 0;
|
|
35471
35527
|
if (context2) {
|
|
@@ -35938,7 +35994,7 @@ async function annotateGitCheckouts(sessions) {
|
|
|
35938
35994
|
}
|
|
35939
35995
|
|
|
35940
35996
|
// server/library-service.ts
|
|
35941
|
-
import { basename as
|
|
35997
|
+
import { basename as basename15, dirname as dirname13, isAbsolute as isAbsolute10 } from "node:path";
|
|
35942
35998
|
|
|
35943
35999
|
// node_modules/.pnpm/minisearch@7.2.0/node_modules/minisearch/dist/es/index.js
|
|
35944
36000
|
var ENTRIES = "ENTRIES";
|
|
@@ -37925,6 +37981,73 @@ function sampleContent(page2, budget2) {
|
|
|
37925
37981
|
return { fragments, characters: Math.max(0, budget2) - remaining, partial: page2.truncated || sampled };
|
|
37926
37982
|
}
|
|
37927
37983
|
|
|
37984
|
+
// server/purge-handoffs.ts
|
|
37985
|
+
import { closeSync as closeSync2, constants as constants7, fstatSync, lstatSync as lstatSync4, openSync as openSync2, opendirSync, readSync as readSync2, unlinkSync as unlinkSync2 } from "node:fs";
|
|
37986
|
+
import { basename as basename14, join as join28 } from "node:path";
|
|
37987
|
+
var MAX_ENTRIES = 2e4;
|
|
37988
|
+
var HEADER_BYTES = 64 * 1024;
|
|
37989
|
+
var generatedName = /^(?:[a-f0-9]{64}\.md|\.[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}\.tmp)$/;
|
|
37990
|
+
var missing = (error) => error.code === "ENOENT";
|
|
37991
|
+
function findPurgeHandoffs(directory3, sources2, all = false) {
|
|
37992
|
+
const root2 = join28(directory3, "handoffs"), paths2 = [], warnings = [], foundSources = /* @__PURE__ */ new Set();
|
|
37993
|
+
try {
|
|
37994
|
+
if (!lstatSync4(root2).isDirectory()) return { paths: paths2, sources: [], warnings: ["Handoff cleanup skipped: handoffs is not a regular directory."] };
|
|
37995
|
+
const entries2 = opendirSync(root2);
|
|
37996
|
+
try {
|
|
37997
|
+
let count = 0;
|
|
37998
|
+
for (let entry = entries2.readSync(); entry; entry = entries2.readSync()) {
|
|
37999
|
+
if (++count > MAX_ENTRIES) {
|
|
38000
|
+
warnings.push("Handoff scan limited to 20,000 entries. Retry purge after cleaning this directory.");
|
|
38001
|
+
break;
|
|
38002
|
+
}
|
|
38003
|
+
if (!generatedName.test(entry.name)) continue;
|
|
38004
|
+
if (!entry.isFile()) {
|
|
38005
|
+
warnings.push(`Handoff cleanup skipped non-regular file ${entry.name}.`);
|
|
38006
|
+
continue;
|
|
38007
|
+
}
|
|
38008
|
+
const path = join28(root2, entry.name);
|
|
38009
|
+
let fd2;
|
|
38010
|
+
try {
|
|
38011
|
+
fd2 = openSync2(path, constants7.O_RDONLY | (constants7.O_NOFOLLOW || 0) | (constants7.O_NONBLOCK || 0));
|
|
38012
|
+
if (!fstatSync(fd2).isFile()) throw new Error("Not a regular file");
|
|
38013
|
+
const buffer = Buffer.alloc(HEADER_BYTES);
|
|
38014
|
+
const header = buffer.subarray(0, readSync2(fd2, buffer, 0, buffer.length, 0)).toString("utf8");
|
|
38015
|
+
const match2 = header.startsWith("# SessionGraph handoff\n\n") && /\nTitle: [^\n]*\nSource: ([^\n]+)\nNative session: /.exec(header);
|
|
38016
|
+
const source = match2 ? JSON.parse(match2[1]) : void 0;
|
|
38017
|
+
if (typeof source !== "string") {
|
|
38018
|
+
warnings.push(`Could not identify handoff ${entry.name}; it was not removed.`);
|
|
38019
|
+
continue;
|
|
38020
|
+
}
|
|
38021
|
+
foundSources.add(source);
|
|
38022
|
+
if (all || sources2.includes(source)) paths2.push(path);
|
|
38023
|
+
} catch (error) {
|
|
38024
|
+
if (!missing(error)) warnings.push(`Could not inspect handoff ${entry.name}; it was not removed.`);
|
|
38025
|
+
} finally {
|
|
38026
|
+
if (fd2 !== void 0) closeSync2(fd2);
|
|
38027
|
+
}
|
|
38028
|
+
}
|
|
38029
|
+
} finally {
|
|
38030
|
+
entries2.closeSync();
|
|
38031
|
+
}
|
|
38032
|
+
} catch (error) {
|
|
38033
|
+
if (!missing(error)) warnings.push("Could not inspect the handoffs directory. Check permissions and retry purge.");
|
|
38034
|
+
}
|
|
38035
|
+
return { paths: paths2, sources: [...foundSources], warnings };
|
|
38036
|
+
}
|
|
38037
|
+
function removePurgeHandoffs(paths2) {
|
|
38038
|
+
let removed = 0;
|
|
38039
|
+
const warnings = [];
|
|
38040
|
+
for (const path of paths2) {
|
|
38041
|
+
try {
|
|
38042
|
+
unlinkSync2(path);
|
|
38043
|
+
removed++;
|
|
38044
|
+
} catch (error) {
|
|
38045
|
+
if (!missing(error)) warnings.push(`Could not delete handoff ${basename14(path)}. Check permissions and retry purge.`);
|
|
38046
|
+
}
|
|
38047
|
+
}
|
|
38048
|
+
return { removed, warnings };
|
|
38049
|
+
}
|
|
38050
|
+
|
|
37928
38051
|
// server/library-service.ts
|
|
37929
38052
|
var utc = (ms) => ms > 0 && ms <= 864e13 ? new Date(ms).toISOString() : null;
|
|
37930
38053
|
var LibraryService = class {
|
|
@@ -38028,6 +38151,37 @@ var LibraryService = class {
|
|
|
38028
38151
|
this.store.setting("sourcePaths", paths2);
|
|
38029
38152
|
});
|
|
38030
38153
|
}
|
|
38154
|
+
purgeSources(ids, options = {}) {
|
|
38155
|
+
if (!!options.all === !!ids.length) invalid("Choose source IDs or --all.");
|
|
38156
|
+
if (options.dryRun && options.confirmed) invalid("Choose a dry run or a confirmed purge, not both.");
|
|
38157
|
+
if (!options.dryRun && options.confirmed !== true) invalid("Purging saved history requires confirmation. Use --dry-run to preview, or --yes to delete.");
|
|
38158
|
+
if (this.importer.status.running || !this.store.acquireImport()) throw new LibraryError("IMPORT_BUSY", "Another import is running. Try again when it finishes.");
|
|
38159
|
+
try {
|
|
38160
|
+
this.store.db.exec("BEGIN IMMEDIATE");
|
|
38161
|
+
let result;
|
|
38162
|
+
try {
|
|
38163
|
+
const handoffs = this.store.path === ":memory:" ? { paths: [], sources: [], warnings: [] } : findPurgeHandoffs(dirname13(this.store.path), ids, options.all);
|
|
38164
|
+
const known = [.../* @__PURE__ */ new Set([...this.importer.adapters.map((adapter) => adapter.id), ...this.store.savedSources(), ...handoffs.sources])];
|
|
38165
|
+
for (const id2 of ids) if (!known.includes(id2)) invalid(`Unknown source "${id2}". Run sessiongraph sources list.`);
|
|
38166
|
+
const sources2 = [...new Set(options.all ? known : ids)];
|
|
38167
|
+
result = { sources: sources2, handoffs, deleted: this.store.purgeSources(sources2, options.dryRun === true) };
|
|
38168
|
+
this.store.db.exec("COMMIT");
|
|
38169
|
+
} catch (error) {
|
|
38170
|
+
this.store.db.exec("ROLLBACK");
|
|
38171
|
+
throw error;
|
|
38172
|
+
}
|
|
38173
|
+
const cleanup2 = options.dryRun ? { removed: result.handoffs.paths.length, warnings: [] } : removePurgeHandoffs(result.handoffs.paths);
|
|
38174
|
+
if (!options.dryRun) this.searchCache = void 0;
|
|
38175
|
+
return {
|
|
38176
|
+
dryRun: options.dryRun === true,
|
|
38177
|
+
sources: result.sources,
|
|
38178
|
+
deleted: { ...result.deleted, handoffFiles: cleanup2.removed },
|
|
38179
|
+
warnings: [...result.handoffs.warnings, ...cleanup2.warnings]
|
|
38180
|
+
};
|
|
38181
|
+
} finally {
|
|
38182
|
+
this.store.releaseImport();
|
|
38183
|
+
}
|
|
38184
|
+
}
|
|
38031
38185
|
async importSessions(ids) {
|
|
38032
38186
|
const selected = this.store.selected(), sources2 = ids?.length ? ids : selected;
|
|
38033
38187
|
this.validateSources(sources2);
|
|
@@ -38053,7 +38207,7 @@ var LibraryService = class {
|
|
|
38053
38207
|
title: s.title,
|
|
38054
38208
|
source: s.source,
|
|
38055
38209
|
projectID: s.projectID,
|
|
38056
|
-
projectLabel: names.get(s.projectID) ||
|
|
38210
|
+
projectLabel: names.get(s.projectID) || basename15(s.directory) || "Unknown project",
|
|
38057
38211
|
created: utc(s.created),
|
|
38058
38212
|
lastActivity: utc(sessionEnd(s)),
|
|
38059
38213
|
relationship: relationshipOf(s),
|
|
@@ -38180,7 +38334,7 @@ var LibraryService = class {
|
|
|
38180
38334
|
}
|
|
38181
38335
|
const groups = [...grouped2].sort(([a], [b]) => a.localeCompare(b)).map(([key, values]) => ({
|
|
38182
38336
|
key,
|
|
38183
|
-
label: groupBy === "project" ? names.get(key) ||
|
|
38337
|
+
label: groupBy === "project" ? names.get(key) || basename15(values[0].directory) || "Unknown project" : groupBy === "repository" ? values[0].checkout?.repositoryLabel || "Unverified repository" : key,
|
|
38184
38338
|
...groupBy === "repository" ? { worktrees: [...new Set(values.flatMap((s) => s.checkout?.worktree || []))].sort() } : {},
|
|
38185
38339
|
...groupBy === "relationship" ? { origins: values.reduce((counts, s) => {
|
|
38186
38340
|
counts[s.origin ?? "unknown"]++;
|
|
@@ -38333,6 +38487,15 @@ async function sessionGraphMiddleware(req, res, next) {
|
|
|
38333
38487
|
const result = await service.discoverSources([value.source]);
|
|
38334
38488
|
return json5(200, { saved: true, source: result.sources[0] });
|
|
38335
38489
|
}
|
|
38490
|
+
if (url.pathname === "/api/sessiongraph/sources/purge") {
|
|
38491
|
+
if (req.method !== "POST") {
|
|
38492
|
+
res.setHeader("Allow", "POST");
|
|
38493
|
+
return json5(405, { error: "Method not allowed." });
|
|
38494
|
+
}
|
|
38495
|
+
const value = await body(req);
|
|
38496
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || Object.keys(value).some((key) => !["sources", "all", "dryRun", "confirmed"].includes(key)) || value.sources !== void 0 && (!Array.isArray(value.sources) || value.sources.some((source) => typeof source !== "string")) || ["all", "dryRun", "confirmed"].some((key) => value[key] !== void 0 && typeof value[key] !== "boolean")) return json5(400, { error: "Choose source IDs or all, and a dry run or confirmed purge." });
|
|
38497
|
+
return json5(200, new LibraryService(store, importer).purgeSources(value.sources || [], { all: value.all, dryRun: value.dryRun, confirmed: value.confirmed }));
|
|
38498
|
+
}
|
|
38336
38499
|
if (url.pathname === "/api/sessiongraph/import") {
|
|
38337
38500
|
if (req.method === "GET") return json5(200, importer.status);
|
|
38338
38501
|
if (req.method === "POST") {
|
|
@@ -14,15 +14,15 @@
|
|
|
14
14
|
</data>
|
|
15
15
|
<key>Resources/resources/cli-launcher.mjs</key>
|
|
16
16
|
<data>
|
|
17
|
-
|
|
17
|
+
+ZmgFt8JbdM/8Tb+MjaxZoDQFmQ=
|
|
18
18
|
</data>
|
|
19
19
|
<key>Resources/resources/cli-package.json</key>
|
|
20
20
|
<data>
|
|
21
|
-
|
|
21
|
+
s28hq2O7ILA2UtcLcLF6U1etYS0=
|
|
22
22
|
</data>
|
|
23
23
|
<key>Resources/resources/cli.mjs</key>
|
|
24
24
|
<data>
|
|
25
|
-
|
|
25
|
+
DAdCXOJsfrlsXTNOSfUpibhOO1w=
|
|
26
26
|
</data>
|
|
27
27
|
<key>Resources/resources/install-cli.mjs</key>
|
|
28
28
|
<data>
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
</data>
|
|
35
35
|
<key>Resources/resources/server.mjs</key>
|
|
36
36
|
<data>
|
|
37
|
-
|
|
37
|
+
vwkz/tVBAART4vfjlyPavHsAmI8=
|
|
38
38
|
</data>
|
|
39
39
|
<key>Resources/resources/web/apple-touch-icon.png</key>
|
|
40
40
|
<data>
|
|
@@ -409,21 +409,21 @@
|
|
|
409
409
|
<dict>
|
|
410
410
|
<key>hash2</key>
|
|
411
411
|
<data>
|
|
412
|
-
|
|
412
|
+
r7aI8PqhOMmqRapnBgPj6ZF/LWpSwxwZS/IiqhprfBg=
|
|
413
413
|
</data>
|
|
414
414
|
</dict>
|
|
415
415
|
<key>Resources/resources/cli-package.json</key>
|
|
416
416
|
<dict>
|
|
417
417
|
<key>hash2</key>
|
|
418
418
|
<data>
|
|
419
|
-
|
|
419
|
+
ssz2kat1NginI7VJe9dAgSQpWrKaj64JGZOAt7br0VA=
|
|
420
420
|
</data>
|
|
421
421
|
</dict>
|
|
422
422
|
<key>Resources/resources/cli.mjs</key>
|
|
423
423
|
<dict>
|
|
424
424
|
<key>hash2</key>
|
|
425
425
|
<data>
|
|
426
|
-
|
|
426
|
+
mDgqbjSTKQfu42/G2oiWKf7UMaCj+QMnFJlbfrLyd2Q=
|
|
427
427
|
</data>
|
|
428
428
|
</dict>
|
|
429
429
|
<key>Resources/resources/install-cli.mjs</key>
|
|
@@ -444,7 +444,7 @@
|
|
|
444
444
|
<dict>
|
|
445
445
|
<key>hash2</key>
|
|
446
446
|
<data>
|
|
447
|
-
|
|
447
|
+
LwxoI7U+bNl9PKdkK7X+2dGO/Fpe91eDMeJX2UZExUo=
|
|
448
448
|
</data>
|
|
449
449
|
</dict>
|
|
450
450
|
<key>Resources/resources/web/apple-touch-icon.png</key>
|