chat-recall 0.7.60 → 0.7.61
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/dist/cli.js +102 -13
- package/dist/mcp.js +102 -13
- package/dist/scan-worker.js +46 -0
- package/dist/session-file-scan.d.ts +9 -0
- package/dist/session-file-scan.d.ts.map +1 -1
- package/dist/session-file-scan.js +42 -1
- package/dist/session-file-scan.js.map +1 -1
- package/dist/sync-client.d.ts.map +1 -1
- package/dist/sync-client.js +8 -3
- package/dist/sync-client.js.map +1 -1
- package/dist/watch.js +102 -13
- package/package.json +1 -1
package/dist/watch.js
CHANGED
|
@@ -10280,6 +10280,52 @@ var init_opencode = __esm({
|
|
|
10280
10280
|
getCommits(id, files, startMs, endMs, bufferMinutes) {
|
|
10281
10281
|
return getSessionCommits(this.toPrefixedId(id), files, startMs, endMs, bufferMinutes);
|
|
10282
10282
|
}
|
|
10283
|
+
/** The bytes of the dump of a session, summed in SQLite: no row is read into the process. */
|
|
10284
|
+
rawSessionBytes(id) {
|
|
10285
|
+
const dbPath = this.dbPath();
|
|
10286
|
+
if (!existsSync11(dbPath))
|
|
10287
|
+
return 0;
|
|
10288
|
+
const realId = this.toRawId(id);
|
|
10289
|
+
const db = openOpencodeDbOrThrow(dbPath);
|
|
10290
|
+
try {
|
|
10291
|
+
const row = db.prepare(`
|
|
10292
|
+
SELECT COALESCE(SUM(LENGTH(CAST(p.data AS BLOB)) + LENGTH(CAST(m.data AS BLOB))), 0) AS bytes
|
|
10293
|
+
FROM part p JOIN (SELECT id, data FROM message WHERE session_id = ?) m ON p.message_id = m.id
|
|
10294
|
+
WHERE p.session_id = ?
|
|
10295
|
+
`).get(realId, realId);
|
|
10296
|
+
return Number(row?.bytes ?? 0);
|
|
10297
|
+
} catch {
|
|
10298
|
+
return 0;
|
|
10299
|
+
} finally {
|
|
10300
|
+
db.close();
|
|
10301
|
+
}
|
|
10302
|
+
}
|
|
10303
|
+
/** The lines of the dump, one row at a time. Every line ends with a newline. */
|
|
10304
|
+
*iterateRawSessionLines(id) {
|
|
10305
|
+
const dbPath = this.dbPath();
|
|
10306
|
+
if (!existsSync11(dbPath))
|
|
10307
|
+
return;
|
|
10308
|
+
const realId = this.toRawId(id);
|
|
10309
|
+
const db = openOpencodeDbOrThrow(dbPath);
|
|
10310
|
+
try {
|
|
10311
|
+
const session = db.prepare(`SELECT * FROM session WHERE id = ?`).get(realId);
|
|
10312
|
+
if (!session)
|
|
10313
|
+
return;
|
|
10314
|
+
yield `${JSON.stringify({ kind: "session", row: session })}
|
|
10315
|
+
`;
|
|
10316
|
+
const rows = db.prepare(`
|
|
10317
|
+
SELECT m.id AS message_id, m.data AS message_data, p.id AS part_id, p.data AS part_data, p.time_created
|
|
10318
|
+
FROM part p JOIN (SELECT id, data FROM message WHERE session_id = ?) m ON p.message_id = m.id
|
|
10319
|
+
WHERE p.session_id = ?
|
|
10320
|
+
ORDER BY p.time_created ASC, p.id ASC
|
|
10321
|
+
`);
|
|
10322
|
+
for (const r of rows.iterate(realId, realId))
|
|
10323
|
+
yield `${JSON.stringify({ kind: "part", row: r })}
|
|
10324
|
+
`;
|
|
10325
|
+
} finally {
|
|
10326
|
+
db.close();
|
|
10327
|
+
}
|
|
10328
|
+
}
|
|
10283
10329
|
exportRawSession(id) {
|
|
10284
10330
|
const dbPath = this.dbPath();
|
|
10285
10331
|
if (!existsSync11(dbPath))
|
|
@@ -16049,7 +16095,7 @@ var init_types = __esm({
|
|
|
16049
16095
|
});
|
|
16050
16096
|
|
|
16051
16097
|
// ../engine/dist/transcript/opencode.js
|
|
16052
|
-
async function parseOpenCodeSubagents(parentSessionId) {
|
|
16098
|
+
async function parseOpenCodeSubagents(parentSessionId, opts = {}) {
|
|
16053
16099
|
const { existsSync: existsSync53 } = await import("fs");
|
|
16054
16100
|
const { opencodeBackend: opencodeBackend2 } = await Promise.resolve().then(() => (init_opencode(), opencode_exports));
|
|
16055
16101
|
const dbPath = opencodeBackend2.dbPath();
|
|
@@ -16069,7 +16115,7 @@ async function parseOpenCodeSubagents(parentSessionId) {
|
|
|
16069
16115
|
const childId = `opencode_${c.id}`;
|
|
16070
16116
|
let messages = [];
|
|
16071
16117
|
try {
|
|
16072
|
-
messages = await parseOpenCodeTranscript(childId);
|
|
16118
|
+
messages = await parseOpenCodeTranscript(childId, opts);
|
|
16073
16119
|
} catch (e) {
|
|
16074
16120
|
log5.error({ err: e, sessionId: c.id }, "Failed to parse OpenCode sub-session");
|
|
16075
16121
|
}
|
|
@@ -16093,7 +16139,7 @@ async function parseOpenCodeSubagents(parentSessionId) {
|
|
|
16093
16139
|
db.close();
|
|
16094
16140
|
}
|
|
16095
16141
|
}
|
|
16096
|
-
async function parseOpenCodeTranscript(sessionId) {
|
|
16142
|
+
async function parseOpenCodeTranscript(sessionId, opts = {}) {
|
|
16097
16143
|
const { existsSync: existsSync53 } = await import("fs");
|
|
16098
16144
|
const { opencodeBackend: opencodeBackend2 } = await Promise.resolve().then(() => (init_opencode(), opencode_exports));
|
|
16099
16145
|
const dbPath = opencodeBackend2.dbPath();
|
|
@@ -16109,13 +16155,19 @@ async function parseOpenCodeTranscript(sessionId) {
|
|
|
16109
16155
|
JOIN (SELECT id, data FROM message WHERE session_id = ?) m ON p.message_id = m.id
|
|
16110
16156
|
WHERE p.session_id = ?
|
|
16111
16157
|
ORDER BY p.time_created ASC
|
|
16112
|
-
`).
|
|
16158
|
+
`).iterate(realId, realId);
|
|
16159
|
+
const cap = opts.payloadCap ? (v) => capPayload(v, opts.payloadCap) : (v) => v;
|
|
16160
|
+
let lastMsgData = "";
|
|
16161
|
+
let lastRole = "assistant";
|
|
16113
16162
|
let lineNum = 0;
|
|
16114
16163
|
for (const part of parts) {
|
|
16115
16164
|
try {
|
|
16116
16165
|
const partData = JSON.parse(part.data);
|
|
16117
|
-
|
|
16118
|
-
|
|
16166
|
+
if (part.msg_data !== lastMsgData) {
|
|
16167
|
+
lastRole = JSON.parse(part.msg_data).role === "user" ? "user" : "assistant";
|
|
16168
|
+
lastMsgData = part.msg_data;
|
|
16169
|
+
}
|
|
16170
|
+
const role = lastRole;
|
|
16119
16171
|
if (partData.type === "text" && partData.text?.trim()) {
|
|
16120
16172
|
lineNum++;
|
|
16121
16173
|
messages.push({ line: lineNum, role, content: partData.text });
|
|
@@ -16125,7 +16177,7 @@ async function parseOpenCodeTranscript(sessionId) {
|
|
|
16125
16177
|
line: lineNum,
|
|
16126
16178
|
role: "assistant",
|
|
16127
16179
|
content: `Tool: ${partData.tool}`,
|
|
16128
|
-
toolCalls: [{ name: partData.tool, input: partData.state || {} }]
|
|
16180
|
+
toolCalls: [{ name: partData.tool, input: cap(partData.state || {}) }]
|
|
16129
16181
|
});
|
|
16130
16182
|
}
|
|
16131
16183
|
} catch {
|
|
@@ -16142,6 +16194,7 @@ var init_opencode2 = __esm({
|
|
|
16142
16194
|
"use strict";
|
|
16143
16195
|
init_opencode_v2();
|
|
16144
16196
|
init_logger();
|
|
16197
|
+
init_trim();
|
|
16145
16198
|
log5 = createLogger("transcript-opencode");
|
|
16146
16199
|
}
|
|
16147
16200
|
});
|
|
@@ -16231,12 +16284,13 @@ async function parseTranscriptUncut(sessionId, opts) {
|
|
|
16231
16284
|
return { messages, subagents, mtime: merged.mtime || safeMtime(primaryPath), ...opts.payloadCap ? { payloadCap: opts.payloadCap } : {} };
|
|
16232
16285
|
}
|
|
16233
16286
|
if (tool === "opencode") {
|
|
16234
|
-
const
|
|
16287
|
+
const cut = opts.payloadCap ? { payloadCap: opts.payloadCap } : {};
|
|
16288
|
+
const messages = await parseOpenCodeTranscript(sessionId, cut);
|
|
16235
16289
|
if (messages.length === 0)
|
|
16236
16290
|
return null;
|
|
16237
|
-
const subagents = await parseOpenCodeSubagents(sessionId);
|
|
16291
|
+
const subagents = await parseOpenCodeSubagents(sessionId, cut);
|
|
16238
16292
|
const loc = getBackend("opencode").findSession(sessionId);
|
|
16239
|
-
return { messages, subagents, mtime: loc?.mtime || 0 };
|
|
16293
|
+
return { messages, subagents, mtime: loc?.mtime || 0, ...opts.payloadCap ? { payloadCap: opts.payloadCap } : {} };
|
|
16240
16294
|
}
|
|
16241
16295
|
if (tool === "codex") {
|
|
16242
16296
|
const loc = getBackend("codex").findSession(sessionId);
|
|
@@ -28821,6 +28875,40 @@ async function scanSessionGroupsChunked(sessionId, groups, tenantRules, pieceByt
|
|
|
28821
28875
|
}
|
|
28822
28876
|
return findings;
|
|
28823
28877
|
}
|
|
28878
|
+
function scanLinesChunked(sessionId, lines, tenantRules, pieceBytes = SCAN_PIECE_BYTES) {
|
|
28879
|
+
const findings = [];
|
|
28880
|
+
let lineBase = 0;
|
|
28881
|
+
let piece = [];
|
|
28882
|
+
let bytes = 0;
|
|
28883
|
+
const flush2 = () => {
|
|
28884
|
+
if (piece.length === 0) return;
|
|
28885
|
+
const text = piece.join("");
|
|
28886
|
+
try {
|
|
28887
|
+
for (const x of scanTextForFindings(text)) {
|
|
28888
|
+
findings.push({ session_id: sessionId, detector: "builtin", rule: x.rule, line: x.line + lineBase, preview: x.preview });
|
|
28889
|
+
}
|
|
28890
|
+
} catch {
|
|
28891
|
+
}
|
|
28892
|
+
if (tenantRules && tenantRules.length > 0) {
|
|
28893
|
+
try {
|
|
28894
|
+
for (const x of scanTenantRules(text, tenantRules)) {
|
|
28895
|
+
findings.push({ session_id: sessionId, detector: x.detector, rule: x.rule, line: x.line + lineBase, preview: x.preview });
|
|
28896
|
+
}
|
|
28897
|
+
} catch {
|
|
28898
|
+
}
|
|
28899
|
+
}
|
|
28900
|
+
lineBase += piece.length;
|
|
28901
|
+
piece = [];
|
|
28902
|
+
bytes = 0;
|
|
28903
|
+
};
|
|
28904
|
+
for (const line of lines) {
|
|
28905
|
+
piece.push(line);
|
|
28906
|
+
bytes += line.length;
|
|
28907
|
+
if (bytes >= pieceBytes) flush2();
|
|
28908
|
+
}
|
|
28909
|
+
flush2();
|
|
28910
|
+
return findings;
|
|
28911
|
+
}
|
|
28824
28912
|
var SCAN_PIECE_BYTES, NEWLINE;
|
|
28825
28913
|
var init_session_file_scan = __esm({
|
|
28826
28914
|
"src/session-file-scan.ts"() {
|
|
@@ -28828,7 +28916,7 @@ var init_session_file_scan = __esm({
|
|
|
28828
28916
|
init_secret_redactor();
|
|
28829
28917
|
init_secret_scanner();
|
|
28830
28918
|
init_live_session_scan();
|
|
28831
|
-
SCAN_PIECE_BYTES =
|
|
28919
|
+
SCAN_PIECE_BYTES = 1024 * 1024;
|
|
28832
28920
|
NEWLINE = 10;
|
|
28833
28921
|
}
|
|
28834
28922
|
});
|
|
@@ -30857,7 +30945,8 @@ async function buildConversationSync(ref, mtime, opts = {}) {
|
|
|
30857
30945
|
try {
|
|
30858
30946
|
const backend = getBackendForId(ref.prefixedId) ?? getBackend("claude");
|
|
30859
30947
|
const streamGroups = ref.toolId === "claude" ? resolveSessionContentGroups(ref.rawId) : [];
|
|
30860
|
-
const
|
|
30948
|
+
const streamsLines = ref.toolId !== "claude" && !!backend.rawSessionBytes && !!backend.iterateRawSessionLines;
|
|
30949
|
+
const streamedBytes = ref.toolId === "claude" ? sessionGroupsBytes(streamGroups) : streamsLines ? backend.rawSessionBytes(ref.prefixedId) : 0;
|
|
30861
30950
|
const streamed = streamedBytes > FULL_BUILD_MAX_BYTES;
|
|
30862
30951
|
const exp = streamed ? null : backend.exportRawSession(ref.prefixedId);
|
|
30863
30952
|
let built;
|
|
@@ -30875,7 +30964,7 @@ async function buildConversationSync(ref, mtime, opts = {}) {
|
|
|
30875
30964
|
includeMeta = false;
|
|
30876
30965
|
exportOverCeiling = true;
|
|
30877
30966
|
if (streamed) {
|
|
30878
|
-
overCeilingFindings = await scanSessionGroupsChunked(ref.prefixedId, streamGroups, opts.tenantRules);
|
|
30967
|
+
overCeilingFindings = ref.toolId === "claude" ? await scanSessionGroupsChunked(ref.prefixedId, streamGroups, opts.tenantRules) : scanLinesChunked(ref.prefixedId, backend.iterateRawSessionLines(ref.prefixedId), opts.tenantRules);
|
|
30879
30968
|
} else if (exp) {
|
|
30880
30969
|
overCeilingFindings = [];
|
|
30881
30970
|
let lineBase = 0;
|