chat-recall 0.7.59 → 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 +425 -183
- package/dist/mcp.js +409 -169
- package/dist/scan-worker.js +54 -0
- package/dist/session-file-scan.d.ts +31 -0
- package/dist/session-file-scan.d.ts.map +1 -0
- package/dist/session-file-scan.js +149 -0
- package/dist/session-file-scan.js.map +1 -0
- package/dist/sync-client.d.ts +0 -7
- package/dist/sync-client.d.ts.map +1 -1
- package/dist/sync-client.js +46 -22
- package/dist/sync-client.js.map +1 -1
- package/dist/watch.js +421 -179
- package/package.json +1 -1
package/dist/mcp.js
CHANGED
|
@@ -7501,6 +7501,52 @@ var init_opencode = __esm({
|
|
|
7501
7501
|
getCommits(id, files, startMs, endMs, bufferMinutes) {
|
|
7502
7502
|
return getSessionCommits(this.toPrefixedId(id), files, startMs, endMs, bufferMinutes);
|
|
7503
7503
|
}
|
|
7504
|
+
/** The bytes of the dump of a session, summed in SQLite: no row is read into the process. */
|
|
7505
|
+
rawSessionBytes(id) {
|
|
7506
|
+
const dbPath = this.dbPath();
|
|
7507
|
+
if (!existsSync7(dbPath))
|
|
7508
|
+
return 0;
|
|
7509
|
+
const realId = this.toRawId(id);
|
|
7510
|
+
const db = openOpencodeDbOrThrow(dbPath);
|
|
7511
|
+
try {
|
|
7512
|
+
const row = db.prepare(`
|
|
7513
|
+
SELECT COALESCE(SUM(LENGTH(CAST(p.data AS BLOB)) + LENGTH(CAST(m.data AS BLOB))), 0) AS bytes
|
|
7514
|
+
FROM part p JOIN (SELECT id, data FROM message WHERE session_id = ?) m ON p.message_id = m.id
|
|
7515
|
+
WHERE p.session_id = ?
|
|
7516
|
+
`).get(realId, realId);
|
|
7517
|
+
return Number(row?.bytes ?? 0);
|
|
7518
|
+
} catch {
|
|
7519
|
+
return 0;
|
|
7520
|
+
} finally {
|
|
7521
|
+
db.close();
|
|
7522
|
+
}
|
|
7523
|
+
}
|
|
7524
|
+
/** The lines of the dump, one row at a time. Every line ends with a newline. */
|
|
7525
|
+
*iterateRawSessionLines(id) {
|
|
7526
|
+
const dbPath = this.dbPath();
|
|
7527
|
+
if (!existsSync7(dbPath))
|
|
7528
|
+
return;
|
|
7529
|
+
const realId = this.toRawId(id);
|
|
7530
|
+
const db = openOpencodeDbOrThrow(dbPath);
|
|
7531
|
+
try {
|
|
7532
|
+
const session = db.prepare(`SELECT * FROM session WHERE id = ?`).get(realId);
|
|
7533
|
+
if (!session)
|
|
7534
|
+
return;
|
|
7535
|
+
yield `${JSON.stringify({ kind: "session", row: session })}
|
|
7536
|
+
`;
|
|
7537
|
+
const rows = db.prepare(`
|
|
7538
|
+
SELECT m.id AS message_id, m.data AS message_data, p.id AS part_id, p.data AS part_data, p.time_created
|
|
7539
|
+
FROM part p JOIN (SELECT id, data FROM message WHERE session_id = ?) m ON p.message_id = m.id
|
|
7540
|
+
WHERE p.session_id = ?
|
|
7541
|
+
ORDER BY p.time_created ASC, p.id ASC
|
|
7542
|
+
`);
|
|
7543
|
+
for (const r of rows.iterate(realId, realId))
|
|
7544
|
+
yield `${JSON.stringify({ kind: "part", row: r })}
|
|
7545
|
+
`;
|
|
7546
|
+
} finally {
|
|
7547
|
+
db.close();
|
|
7548
|
+
}
|
|
7549
|
+
}
|
|
7504
7550
|
exportRawSession(id) {
|
|
7505
7551
|
const dbPath = this.dbPath();
|
|
7506
7552
|
if (!existsSync7(dbPath))
|
|
@@ -12917,6 +12963,42 @@ var init_session = __esm({
|
|
|
12917
12963
|
}
|
|
12918
12964
|
});
|
|
12919
12965
|
|
|
12966
|
+
// ../engine/dist/transcript/trim.js
|
|
12967
|
+
function detach(s) {
|
|
12968
|
+
return JSON.parse(JSON.stringify(s));
|
|
12969
|
+
}
|
|
12970
|
+
function capPayload(v, capChars = SYNC_PAYLOAD_CAP) {
|
|
12971
|
+
if (v === void 0)
|
|
12972
|
+
return void 0;
|
|
12973
|
+
if (typeof v === "string") {
|
|
12974
|
+
return v.length > capChars ? detach(v.slice(0, capChars)) + `\u2026 [+${v.length - capChars} chars]` : v;
|
|
12975
|
+
}
|
|
12976
|
+
let s = "";
|
|
12977
|
+
try {
|
|
12978
|
+
s = JSON.stringify(v) ?? "";
|
|
12979
|
+
} catch {
|
|
12980
|
+
return void 0;
|
|
12981
|
+
}
|
|
12982
|
+
if (s.length <= capChars * 4)
|
|
12983
|
+
return v;
|
|
12984
|
+
if (Array.isArray(v))
|
|
12985
|
+
return detach(s.slice(0, capChars)) + `\u2026 [+${s.length - capChars} chars]`;
|
|
12986
|
+
if (v && typeof v === "object") {
|
|
12987
|
+
const o = {};
|
|
12988
|
+
for (const [k, val] of Object.entries(v))
|
|
12989
|
+
o[k] = capPayload(val, capChars);
|
|
12990
|
+
return o;
|
|
12991
|
+
}
|
|
12992
|
+
return v;
|
|
12993
|
+
}
|
|
12994
|
+
var SYNC_PAYLOAD_CAP;
|
|
12995
|
+
var init_trim = __esm({
|
|
12996
|
+
"../engine/dist/transcript/trim.js"() {
|
|
12997
|
+
"use strict";
|
|
12998
|
+
SYNC_PAYLOAD_CAP = 2e3;
|
|
12999
|
+
}
|
|
13000
|
+
});
|
|
13001
|
+
|
|
12920
13002
|
// ../engine/dist/transcript/claude.js
|
|
12921
13003
|
import { open, readdir, readFile, stat } from "fs/promises";
|
|
12922
13004
|
import { dirname as dirname11, join as join18, basename as basename11 } from "path";
|
|
@@ -12926,124 +13008,47 @@ function stripBanners2(text) {
|
|
|
12926
13008
|
out = out.replace(re, " ");
|
|
12927
13009
|
return out.replace(/[ \t]{2,}/g, " ").trim();
|
|
12928
13010
|
}
|
|
12929
|
-
function parseClaudeTranscriptText(text) {
|
|
12930
|
-
const
|
|
13011
|
+
function parseClaudeTranscriptText(text, opts = {}) {
|
|
13012
|
+
const builder = new MessageBuilder(opts.payloadCap);
|
|
12931
13013
|
let lineNumber = 0;
|
|
12932
13014
|
for (const line of text.split("\n")) {
|
|
12933
13015
|
lineNumber++;
|
|
12934
13016
|
if (!line.trim())
|
|
12935
13017
|
continue;
|
|
13018
|
+
let obj2;
|
|
12936
13019
|
try {
|
|
12937
|
-
|
|
13020
|
+
obj2 = JSON.parse(line);
|
|
12938
13021
|
} catch {
|
|
13022
|
+
continue;
|
|
12939
13023
|
}
|
|
13024
|
+
builder.add(lineNumber, obj2);
|
|
12940
13025
|
}
|
|
12941
|
-
return
|
|
13026
|
+
return builder.messages;
|
|
12942
13027
|
}
|
|
12943
|
-
async function parseMessagesFromFile(sessionPath) {
|
|
13028
|
+
async function parseMessagesFromFile(sessionPath, opts) {
|
|
12944
13029
|
const file = await open(sessionPath);
|
|
12945
|
-
const
|
|
13030
|
+
const builder = new MessageBuilder(opts.payloadCap);
|
|
12946
13031
|
try {
|
|
12947
13032
|
let lineNumber = 0;
|
|
12948
13033
|
for await (const line of file.readLines()) {
|
|
12949
13034
|
lineNumber++;
|
|
12950
13035
|
if (!line.trim())
|
|
12951
13036
|
continue;
|
|
13037
|
+
let obj2;
|
|
12952
13038
|
try {
|
|
12953
|
-
|
|
13039
|
+
obj2 = JSON.parse(line);
|
|
12954
13040
|
} catch {
|
|
12955
13041
|
log2.debug({ line: lineNumber, file: sessionPath }, "skipped malformed transcript line");
|
|
13042
|
+
continue;
|
|
12956
13043
|
}
|
|
13044
|
+
builder.add(lineNumber, obj2);
|
|
12957
13045
|
}
|
|
12958
13046
|
} finally {
|
|
12959
13047
|
await file.close();
|
|
12960
13048
|
}
|
|
12961
|
-
return
|
|
13049
|
+
return builder.messages;
|
|
12962
13050
|
}
|
|
12963
|
-
function
|
|
12964
|
-
const toolResults = /* @__PURE__ */ new Map();
|
|
12965
|
-
for (const { obj: obj2 } of raw) {
|
|
12966
|
-
if (obj2?.type !== "user")
|
|
12967
|
-
continue;
|
|
12968
|
-
const content = obj2.message?.content;
|
|
12969
|
-
if (!Array.isArray(content))
|
|
12970
|
-
continue;
|
|
12971
|
-
for (const block of content) {
|
|
12972
|
-
if (block?.type === "tool_result" && block.tool_use_id) {
|
|
12973
|
-
toolResults.set(block.tool_use_id, {
|
|
12974
|
-
content: block.content,
|
|
12975
|
-
isError: block.is_error === true
|
|
12976
|
-
});
|
|
12977
|
-
}
|
|
12978
|
-
}
|
|
12979
|
-
}
|
|
12980
|
-
const messages = [];
|
|
12981
|
-
for (const { line, obj: obj2 } of raw) {
|
|
12982
|
-
if (!obj2 || typeof obj2 !== "object")
|
|
12983
|
-
continue;
|
|
12984
|
-
const timestamp = typeof obj2.timestamp === "string" ? obj2.timestamp : void 0;
|
|
12985
|
-
if (obj2.type === "user") {
|
|
12986
|
-
const content = obj2.message?.content;
|
|
12987
|
-
let text = "";
|
|
12988
|
-
if (typeof content === "string") {
|
|
12989
|
-
text = content;
|
|
12990
|
-
} else if (Array.isArray(content)) {
|
|
12991
|
-
text = content.filter((c) => c?.type === "text" && typeof c.text === "string").map((c) => c.text).join("\n");
|
|
12992
|
-
}
|
|
12993
|
-
if (!text.trim())
|
|
12994
|
-
continue;
|
|
12995
|
-
const cleaned = stripBanners2(text);
|
|
12996
|
-
if (!cleaned)
|
|
12997
|
-
continue;
|
|
12998
|
-
const origin = userRecordOrigin(obj2, cleaned);
|
|
12999
|
-
messages.push({ line, role: "user", content: cleaned, timestamp, ...origin === "human" ? {} : { origin } });
|
|
13000
|
-
} else if (obj2.type === "attachment") {
|
|
13001
|
-
const queued = queuedCommandPrompt(obj2);
|
|
13002
|
-
if (!queued)
|
|
13003
|
-
continue;
|
|
13004
|
-
const cleaned = stripBanners2(queued.text);
|
|
13005
|
-
if (!cleaned)
|
|
13006
|
-
continue;
|
|
13007
|
-
messages.push({ line, role: "user", content: cleaned, timestamp, ...queued.origin === "human" ? {} : { origin: queued.origin } });
|
|
13008
|
-
} else if (obj2.type === "assistant") {
|
|
13009
|
-
const blocks = Array.isArray(obj2.message?.content) ? obj2.message.content : [];
|
|
13010
|
-
const thinkingBlock = blocks.find((c) => c?.type === "thinking");
|
|
13011
|
-
const textBlock = blocks.find((c) => c?.type === "text");
|
|
13012
|
-
const toolUses = blocks.filter((c) => c?.type === "tool_use");
|
|
13013
|
-
const toolCalls = toolUses.map((toolUse) => {
|
|
13014
|
-
const result = toolUse.id ? toolResults.get(toolUse.id) : void 0;
|
|
13015
|
-
return {
|
|
13016
|
-
name: toolUse.name || "unknown",
|
|
13017
|
-
input: toolUse.input,
|
|
13018
|
-
result: result?.content,
|
|
13019
|
-
isError: result?.isError
|
|
13020
|
-
};
|
|
13021
|
-
});
|
|
13022
|
-
const hasThinking = thinkingBlock !== void 0;
|
|
13023
|
-
const text = textBlock?.text ?? "";
|
|
13024
|
-
const thinking = thinkingBlock?.thinking ?? (hasThinking ? "" : void 0);
|
|
13025
|
-
if (!text && !hasThinking && toolCalls.length === 0)
|
|
13026
|
-
continue;
|
|
13027
|
-
messages.push({
|
|
13028
|
-
line,
|
|
13029
|
-
role: "assistant",
|
|
13030
|
-
content: text,
|
|
13031
|
-
thinking,
|
|
13032
|
-
toolCalls: toolCalls.length > 0 ? toolCalls : void 0,
|
|
13033
|
-
timestamp
|
|
13034
|
-
});
|
|
13035
|
-
} else if (obj2.type === "summary" && typeof obj2.summary === "string") {
|
|
13036
|
-
messages.push({ line, role: "summary", content: obj2.summary });
|
|
13037
|
-
} else if (obj2.type === "system" && obj2.subtype === "away_summary") {
|
|
13038
|
-
const c = obj2.content;
|
|
13039
|
-
const text = typeof c === "string" ? c : Array.isArray(c) ? c.filter((b) => b?.type === "text" && typeof b.text === "string").map((b) => b.text).join("\n") : "";
|
|
13040
|
-
if (text.trim())
|
|
13041
|
-
messages.push({ line, role: "summary", content: stripBanners2(text), timestamp });
|
|
13042
|
-
}
|
|
13043
|
-
}
|
|
13044
|
-
return messages;
|
|
13045
|
-
}
|
|
13046
|
-
async function parseClaudeSubagents(sessionPath) {
|
|
13051
|
+
async function parseClaudeSubagents(sessionPath, opts = {}) {
|
|
13047
13052
|
const sessionId = basename11(sessionPath).replace(/\.jsonl$/i, "");
|
|
13048
13053
|
const subagentsDir = join18(dirname11(sessionPath), sessionId, "subagents");
|
|
13049
13054
|
let entries;
|
|
@@ -13070,7 +13075,7 @@ async function parseClaudeSubagents(sessionPath) {
|
|
|
13070
13075
|
}
|
|
13071
13076
|
let messages = [];
|
|
13072
13077
|
try {
|
|
13073
|
-
messages = await parseMessagesFromFile(filePath);
|
|
13078
|
+
messages = await parseMessagesFromFile(filePath, opts);
|
|
13074
13079
|
} catch (e) {
|
|
13075
13080
|
log2.error({ err: e, filePath }, "Failed to parse subagent");
|
|
13076
13081
|
}
|
|
@@ -13095,12 +13100,13 @@ async function parseClaudeSubagents(sessionPath) {
|
|
|
13095
13100
|
}));
|
|
13096
13101
|
return subagents.map((s, i) => ({ s, mtime: stats[i] })).sort((a, b) => a.mtime - b.mtime).map(({ s }) => s);
|
|
13097
13102
|
}
|
|
13098
|
-
var log2, INJECTED_BANNERS2;
|
|
13103
|
+
var log2, INJECTED_BANNERS2, MessageBuilder;
|
|
13099
13104
|
var init_claude2 = __esm({
|
|
13100
13105
|
"../engine/dist/transcript/claude.js"() {
|
|
13101
13106
|
"use strict";
|
|
13102
13107
|
init_logger();
|
|
13103
13108
|
init_claude_prompt_origin();
|
|
13109
|
+
init_trim();
|
|
13104
13110
|
log2 = createLogger("transcript-claude");
|
|
13105
13111
|
INJECTED_BANNERS2 = [
|
|
13106
13112
|
/MCP issues detected\. ?Run \/mcp list for status\.?/g,
|
|
@@ -13119,6 +13125,104 @@ var init_claude2 = __esm({
|
|
|
13119
13125
|
// eslint-disable-next-line no-control-regex
|
|
13120
13126
|
/\[[0-9;]*m/g
|
|
13121
13127
|
];
|
|
13128
|
+
MessageBuilder = class {
|
|
13129
|
+
messages = [];
|
|
13130
|
+
cap;
|
|
13131
|
+
/** The calls of each tool_use id. */
|
|
13132
|
+
calls = /* @__PURE__ */ new Map();
|
|
13133
|
+
/** The last result of each tool_use id. */
|
|
13134
|
+
results = /* @__PURE__ */ new Map();
|
|
13135
|
+
constructor(payloadCap) {
|
|
13136
|
+
this.cap = payloadCap ? (v) => capPayload(v, payloadCap) : (v) => v;
|
|
13137
|
+
}
|
|
13138
|
+
add(line, obj2) {
|
|
13139
|
+
if (!obj2 || typeof obj2 !== "object")
|
|
13140
|
+
return;
|
|
13141
|
+
const timestamp = typeof obj2.timestamp === "string" ? obj2.timestamp : void 0;
|
|
13142
|
+
if (obj2.type === "user") {
|
|
13143
|
+
const content = obj2.message?.content;
|
|
13144
|
+
if (Array.isArray(content)) {
|
|
13145
|
+
for (const block of content) {
|
|
13146
|
+
if (block?.type === "tool_result" && block.tool_use_id) {
|
|
13147
|
+
this.addResult(block.tool_use_id, this.cap(block.content), block.is_error === true);
|
|
13148
|
+
}
|
|
13149
|
+
}
|
|
13150
|
+
}
|
|
13151
|
+
let text = "";
|
|
13152
|
+
if (typeof content === "string") {
|
|
13153
|
+
text = content;
|
|
13154
|
+
} else if (Array.isArray(content)) {
|
|
13155
|
+
text = content.filter((c) => c?.type === "text" && typeof c.text === "string").map((c) => c.text).join("\n");
|
|
13156
|
+
}
|
|
13157
|
+
if (!text.trim())
|
|
13158
|
+
return;
|
|
13159
|
+
const cleaned = stripBanners2(text);
|
|
13160
|
+
if (!cleaned)
|
|
13161
|
+
return;
|
|
13162
|
+
const origin = userRecordOrigin(obj2, cleaned);
|
|
13163
|
+
this.messages.push({ line, role: "user", content: cleaned, timestamp, ...origin === "human" ? {} : { origin } });
|
|
13164
|
+
} else if (obj2.type === "attachment") {
|
|
13165
|
+
const queued = queuedCommandPrompt(obj2);
|
|
13166
|
+
if (!queued)
|
|
13167
|
+
return;
|
|
13168
|
+
const cleaned = stripBanners2(queued.text);
|
|
13169
|
+
if (!cleaned)
|
|
13170
|
+
return;
|
|
13171
|
+
this.messages.push({ line, role: "user", content: cleaned, timestamp, ...queued.origin === "human" ? {} : { origin: queued.origin } });
|
|
13172
|
+
} else if (obj2.type === "assistant") {
|
|
13173
|
+
const blocks = Array.isArray(obj2.message?.content) ? obj2.message.content : [];
|
|
13174
|
+
const thinkingBlock = blocks.find((c) => c?.type === "thinking");
|
|
13175
|
+
const textBlock = blocks.find((c) => c?.type === "text");
|
|
13176
|
+
const toolUses = blocks.filter((c) => c?.type === "tool_use");
|
|
13177
|
+
const toolCalls = toolUses.map((toolUse) => {
|
|
13178
|
+
const known = toolUse.id ? this.results.get(toolUse.id) : void 0;
|
|
13179
|
+
const call2 = {
|
|
13180
|
+
name: toolUse.name || "unknown",
|
|
13181
|
+
input: this.cap(toolUse.input),
|
|
13182
|
+
result: known?.content,
|
|
13183
|
+
isError: known?.isError
|
|
13184
|
+
};
|
|
13185
|
+
if (toolUse.id) {
|
|
13186
|
+
const list = this.calls.get(toolUse.id);
|
|
13187
|
+
if (list)
|
|
13188
|
+
list.push(call2);
|
|
13189
|
+
else
|
|
13190
|
+
this.calls.set(toolUse.id, [call2]);
|
|
13191
|
+
}
|
|
13192
|
+
return call2;
|
|
13193
|
+
});
|
|
13194
|
+
const hasThinking = thinkingBlock !== void 0;
|
|
13195
|
+
const text = textBlock?.text ?? "";
|
|
13196
|
+
const thinking = thinkingBlock?.thinking != null ? this.cap(thinkingBlock.thinking) : hasThinking ? "" : void 0;
|
|
13197
|
+
if (!text && !hasThinking && toolCalls.length === 0)
|
|
13198
|
+
return;
|
|
13199
|
+
this.messages.push({
|
|
13200
|
+
line,
|
|
13201
|
+
role: "assistant",
|
|
13202
|
+
content: text,
|
|
13203
|
+
thinking,
|
|
13204
|
+
toolCalls: toolCalls.length > 0 ? toolCalls : void 0,
|
|
13205
|
+
timestamp
|
|
13206
|
+
});
|
|
13207
|
+
} else if (obj2.type === "summary" && typeof obj2.summary === "string") {
|
|
13208
|
+
this.messages.push({ line, role: "summary", content: obj2.summary });
|
|
13209
|
+
} else if (obj2.type === "system" && obj2.subtype === "away_summary") {
|
|
13210
|
+
const c = obj2.content;
|
|
13211
|
+
const text = typeof c === "string" ? c : Array.isArray(c) ? c.filter((b) => b?.type === "text" && typeof b.text === "string").map((b) => b.text).join("\n") : "";
|
|
13212
|
+
if (text.trim())
|
|
13213
|
+
this.messages.push({ line, role: "summary", content: stripBanners2(text), timestamp });
|
|
13214
|
+
}
|
|
13215
|
+
}
|
|
13216
|
+
addResult(id, content, isError) {
|
|
13217
|
+
this.results.set(id, { content, isError });
|
|
13218
|
+
const list = this.calls.get(id);
|
|
13219
|
+
if (list)
|
|
13220
|
+
for (const call2 of list) {
|
|
13221
|
+
call2.result = content;
|
|
13222
|
+
call2.isError = isError;
|
|
13223
|
+
}
|
|
13224
|
+
}
|
|
13225
|
+
};
|
|
13122
13226
|
}
|
|
13123
13227
|
});
|
|
13124
13228
|
|
|
@@ -14301,7 +14405,7 @@ var init_types = __esm({
|
|
|
14301
14405
|
});
|
|
14302
14406
|
|
|
14303
14407
|
// ../engine/dist/transcript/opencode.js
|
|
14304
|
-
async function parseOpenCodeSubagents(parentSessionId) {
|
|
14408
|
+
async function parseOpenCodeSubagents(parentSessionId, opts = {}) {
|
|
14305
14409
|
const { existsSync: existsSync54 } = await import("fs");
|
|
14306
14410
|
const { opencodeBackend: opencodeBackend2 } = await Promise.resolve().then(() => (init_opencode(), opencode_exports));
|
|
14307
14411
|
const dbPath = opencodeBackend2.dbPath();
|
|
@@ -14321,7 +14425,7 @@ async function parseOpenCodeSubagents(parentSessionId) {
|
|
|
14321
14425
|
const childId = `opencode_${c.id}`;
|
|
14322
14426
|
let messages = [];
|
|
14323
14427
|
try {
|
|
14324
|
-
messages = await parseOpenCodeTranscript(childId);
|
|
14428
|
+
messages = await parseOpenCodeTranscript(childId, opts);
|
|
14325
14429
|
} catch (e) {
|
|
14326
14430
|
log4.error({ err: e, sessionId: c.id }, "Failed to parse OpenCode sub-session");
|
|
14327
14431
|
}
|
|
@@ -14345,7 +14449,7 @@ async function parseOpenCodeSubagents(parentSessionId) {
|
|
|
14345
14449
|
db.close();
|
|
14346
14450
|
}
|
|
14347
14451
|
}
|
|
14348
|
-
async function parseOpenCodeTranscript(sessionId) {
|
|
14452
|
+
async function parseOpenCodeTranscript(sessionId, opts = {}) {
|
|
14349
14453
|
const { existsSync: existsSync54 } = await import("fs");
|
|
14350
14454
|
const { opencodeBackend: opencodeBackend2 } = await Promise.resolve().then(() => (init_opencode(), opencode_exports));
|
|
14351
14455
|
const dbPath = opencodeBackend2.dbPath();
|
|
@@ -14361,13 +14465,19 @@ async function parseOpenCodeTranscript(sessionId) {
|
|
|
14361
14465
|
JOIN (SELECT id, data FROM message WHERE session_id = ?) m ON p.message_id = m.id
|
|
14362
14466
|
WHERE p.session_id = ?
|
|
14363
14467
|
ORDER BY p.time_created ASC
|
|
14364
|
-
`).
|
|
14468
|
+
`).iterate(realId, realId);
|
|
14469
|
+
const cap = opts.payloadCap ? (v) => capPayload(v, opts.payloadCap) : (v) => v;
|
|
14470
|
+
let lastMsgData = "";
|
|
14471
|
+
let lastRole = "assistant";
|
|
14365
14472
|
let lineNum = 0;
|
|
14366
14473
|
for (const part of parts) {
|
|
14367
14474
|
try {
|
|
14368
14475
|
const partData = JSON.parse(part.data);
|
|
14369
|
-
|
|
14370
|
-
|
|
14476
|
+
if (part.msg_data !== lastMsgData) {
|
|
14477
|
+
lastRole = JSON.parse(part.msg_data).role === "user" ? "user" : "assistant";
|
|
14478
|
+
lastMsgData = part.msg_data;
|
|
14479
|
+
}
|
|
14480
|
+
const role = lastRole;
|
|
14371
14481
|
if (partData.type === "text" && partData.text?.trim()) {
|
|
14372
14482
|
lineNum++;
|
|
14373
14483
|
messages.push({ line: lineNum, role, content: partData.text });
|
|
@@ -14377,7 +14487,7 @@ async function parseOpenCodeTranscript(sessionId) {
|
|
|
14377
14487
|
line: lineNum,
|
|
14378
14488
|
role: "assistant",
|
|
14379
14489
|
content: `Tool: ${partData.tool}`,
|
|
14380
|
-
toolCalls: [{ name: partData.tool, input: partData.state || {} }]
|
|
14490
|
+
toolCalls: [{ name: partData.tool, input: cap(partData.state || {}) }]
|
|
14381
14491
|
});
|
|
14382
14492
|
}
|
|
14383
14493
|
} catch {
|
|
@@ -14394,13 +14504,21 @@ var init_opencode2 = __esm({
|
|
|
14394
14504
|
"use strict";
|
|
14395
14505
|
init_opencode_v2();
|
|
14396
14506
|
init_logger();
|
|
14507
|
+
init_trim();
|
|
14397
14508
|
log4 = createLogger("transcript-opencode");
|
|
14398
14509
|
}
|
|
14399
14510
|
});
|
|
14400
14511
|
|
|
14401
14512
|
// ../engine/dist/transcript/index.js
|
|
14402
14513
|
import { statSync as statSync17 } from "fs";
|
|
14403
|
-
async function parseTranscript(sessionId) {
|
|
14514
|
+
async function parseTranscript(sessionId, opts = {}) {
|
|
14515
|
+
const t = await parseTranscriptUncut(sessionId, opts);
|
|
14516
|
+
const cap = opts.payloadCap;
|
|
14517
|
+
if (!t || !cap || t.payloadCap === cap)
|
|
14518
|
+
return t;
|
|
14519
|
+
return { ...t, ...trimTranscriptForSync(t, cap), payloadCap: cap };
|
|
14520
|
+
}
|
|
14521
|
+
async function parseTranscriptUncut(sessionId, opts) {
|
|
14404
14522
|
const tool = detectTool(sessionId);
|
|
14405
14523
|
if (tool === "claude") {
|
|
14406
14524
|
const groups = resolveSessionContentGroups(sessionId);
|
|
@@ -14411,9 +14529,10 @@ async function parseTranscript(sessionId) {
|
|
|
14411
14529
|
return null;
|
|
14412
14530
|
const primaryPath = mainGroup.paths[0];
|
|
14413
14531
|
const merged = readSessionGroupText(mainGroup);
|
|
14532
|
+
const cut = opts.payloadCap ? { payloadCap: opts.payloadCap } : {};
|
|
14414
14533
|
const [tail, allSubagents] = await Promise.all([
|
|
14415
|
-
Promise.resolve(parseClaudeTranscriptText(merged.text)),
|
|
14416
|
-
parseClaudeSubagents(primaryPath)
|
|
14534
|
+
Promise.resolve(parseClaudeTranscriptText(merged.text, cut)),
|
|
14535
|
+
parseClaudeSubagents(primaryPath, cut)
|
|
14417
14536
|
]);
|
|
14418
14537
|
const compacts = allSubagents.filter((s) => s.kind === "compact");
|
|
14419
14538
|
const subagents = allSubagents.filter((s) => s.kind !== "compact");
|
|
@@ -14430,15 +14549,16 @@ async function parseTranscript(sessionId) {
|
|
|
14430
14549
|
}
|
|
14431
14550
|
messages = [...stitched, ...tail].map((m, i) => ({ ...m, line: i + 1 }));
|
|
14432
14551
|
}
|
|
14433
|
-
return { messages, subagents, mtime: merged.mtime || safeMtime(primaryPath) };
|
|
14552
|
+
return { messages, subagents, mtime: merged.mtime || safeMtime(primaryPath), ...opts.payloadCap ? { payloadCap: opts.payloadCap } : {} };
|
|
14434
14553
|
}
|
|
14435
14554
|
if (tool === "opencode") {
|
|
14436
|
-
const
|
|
14555
|
+
const cut = opts.payloadCap ? { payloadCap: opts.payloadCap } : {};
|
|
14556
|
+
const messages = await parseOpenCodeTranscript(sessionId, cut);
|
|
14437
14557
|
if (messages.length === 0)
|
|
14438
14558
|
return null;
|
|
14439
|
-
const subagents = await parseOpenCodeSubagents(sessionId);
|
|
14559
|
+
const subagents = await parseOpenCodeSubagents(sessionId, cut);
|
|
14440
14560
|
const loc = getBackend("opencode").findSession(sessionId);
|
|
14441
|
-
return { messages, subagents, mtime: loc?.mtime || 0 };
|
|
14561
|
+
return { messages, subagents, mtime: loc?.mtime || 0, ...opts.payloadCap ? { payloadCap: opts.payloadCap } : {} };
|
|
14442
14562
|
}
|
|
14443
14563
|
if (tool === "codex") {
|
|
14444
14564
|
const loc = getBackend("codex").findSession(sessionId);
|
|
@@ -14472,31 +14592,8 @@ function safeMtime(path2) {
|
|
|
14472
14592
|
return 0;
|
|
14473
14593
|
}
|
|
14474
14594
|
}
|
|
14475
|
-
function trimTranscriptForSync(t, capChars =
|
|
14476
|
-
const cap = (v) =>
|
|
14477
|
-
if (v === void 0)
|
|
14478
|
-
return void 0;
|
|
14479
|
-
if (typeof v === "string") {
|
|
14480
|
-
return v.length > capChars ? v.slice(0, capChars) + `\u2026 [+${v.length - capChars} chars]` : v;
|
|
14481
|
-
}
|
|
14482
|
-
let s = "";
|
|
14483
|
-
try {
|
|
14484
|
-
s = JSON.stringify(v) ?? "";
|
|
14485
|
-
} catch {
|
|
14486
|
-
return void 0;
|
|
14487
|
-
}
|
|
14488
|
-
if (s.length <= capChars * 4)
|
|
14489
|
-
return v;
|
|
14490
|
-
if (Array.isArray(v))
|
|
14491
|
-
return s.slice(0, capChars) + `\u2026 [+${s.length - capChars} chars]`;
|
|
14492
|
-
if (v && typeof v === "object") {
|
|
14493
|
-
const o = {};
|
|
14494
|
-
for (const [k, val] of Object.entries(v))
|
|
14495
|
-
o[k] = cap(val);
|
|
14496
|
-
return o;
|
|
14497
|
-
}
|
|
14498
|
-
return v;
|
|
14499
|
-
};
|
|
14595
|
+
function trimTranscriptForSync(t, capChars = SYNC_PAYLOAD_CAP) {
|
|
14596
|
+
const cap = (v) => capPayload(v, capChars);
|
|
14500
14597
|
const trimMsg = (m) => ({
|
|
14501
14598
|
...m,
|
|
14502
14599
|
thinking: m.thinking !== void 0 ? cap(m.thinking) : void 0,
|
|
@@ -14521,7 +14618,9 @@ var init_transcript = __esm({
|
|
|
14521
14618
|
init_opencode2();
|
|
14522
14619
|
init_codex2();
|
|
14523
14620
|
init_from_events();
|
|
14621
|
+
init_trim();
|
|
14524
14622
|
init_types();
|
|
14623
|
+
init_trim();
|
|
14525
14624
|
init_raw();
|
|
14526
14625
|
init_shadow();
|
|
14527
14626
|
init_claude2();
|
|
@@ -30170,8 +30269,134 @@ var init_telemetry = __esm({
|
|
|
30170
30269
|
}
|
|
30171
30270
|
});
|
|
30172
30271
|
|
|
30272
|
+
// src/session-file-scan.ts
|
|
30273
|
+
import { open as open3 } from "node:fs/promises";
|
|
30274
|
+
import { statSync as statSync43 } from "node:fs";
|
|
30275
|
+
function sessionGroupsBytes(groups) {
|
|
30276
|
+
let total = 0;
|
|
30277
|
+
for (const g of groups) {
|
|
30278
|
+
for (const p of g.paths) {
|
|
30279
|
+
try {
|
|
30280
|
+
total += statSync43(p).size;
|
|
30281
|
+
} catch {
|
|
30282
|
+
}
|
|
30283
|
+
}
|
|
30284
|
+
}
|
|
30285
|
+
return total;
|
|
30286
|
+
}
|
|
30287
|
+
async function* readLinePieces(path2, pieceBytes = SCAN_PIECE_BYTES) {
|
|
30288
|
+
const fh = await open3(path2, "r");
|
|
30289
|
+
try {
|
|
30290
|
+
const buf = Buffer.allocUnsafe(pieceBytes);
|
|
30291
|
+
let carry = Buffer.alloc(0);
|
|
30292
|
+
for (; ; ) {
|
|
30293
|
+
const { bytesRead } = await fh.read(buf, 0, pieceBytes, null);
|
|
30294
|
+
if (bytesRead === 0) break;
|
|
30295
|
+
const joined = carry.length ? Buffer.concat([carry, buf.subarray(0, bytesRead)]) : buf.subarray(0, bytesRead);
|
|
30296
|
+
const cut = joined.lastIndexOf(NEWLINE);
|
|
30297
|
+
if (cut < 0) {
|
|
30298
|
+
carry = Buffer.from(joined);
|
|
30299
|
+
continue;
|
|
30300
|
+
}
|
|
30301
|
+
const piece = joined.subarray(0, cut + 1);
|
|
30302
|
+
carry = Buffer.from(joined.subarray(cut + 1));
|
|
30303
|
+
yield { text: piece.toString("utf8"), newlines: countNewlines(piece) };
|
|
30304
|
+
}
|
|
30305
|
+
if (carry.length) yield { text: carry.toString("utf8"), newlines: 0 };
|
|
30306
|
+
} finally {
|
|
30307
|
+
await fh.close();
|
|
30308
|
+
}
|
|
30309
|
+
}
|
|
30310
|
+
function countNewlines(b) {
|
|
30311
|
+
let n = 0;
|
|
30312
|
+
for (let i = b.indexOf(NEWLINE); i >= 0; i = b.indexOf(NEWLINE, i + 1)) n++;
|
|
30313
|
+
return n;
|
|
30314
|
+
}
|
|
30315
|
+
async function scanSessionGroupsChunked(sessionId, groups, tenantRules, pieceBytes = SCAN_PIECE_BYTES) {
|
|
30316
|
+
const findings = [];
|
|
30317
|
+
let lineBase = 0;
|
|
30318
|
+
const scan = (text) => {
|
|
30319
|
+
try {
|
|
30320
|
+
for (const x of scanTextForFindings(text)) {
|
|
30321
|
+
findings.push({ session_id: sessionId, detector: "builtin", rule: x.rule, line: x.line + lineBase, preview: x.preview });
|
|
30322
|
+
}
|
|
30323
|
+
} catch {
|
|
30324
|
+
}
|
|
30325
|
+
if (tenantRules && tenantRules.length > 0) {
|
|
30326
|
+
try {
|
|
30327
|
+
for (const x of scanTenantRules(text, tenantRules)) {
|
|
30328
|
+
findings.push({ session_id: sessionId, detector: x.detector, rule: x.rule, line: x.line + lineBase, preview: x.preview });
|
|
30329
|
+
}
|
|
30330
|
+
} catch {
|
|
30331
|
+
}
|
|
30332
|
+
}
|
|
30333
|
+
};
|
|
30334
|
+
for (const group of groups) {
|
|
30335
|
+
if (group.paths.length === 1) {
|
|
30336
|
+
let any = false;
|
|
30337
|
+
for await (const piece of readLinePieces(group.paths[0], pieceBytes)) {
|
|
30338
|
+
any = true;
|
|
30339
|
+
scan(piece.text);
|
|
30340
|
+
lineBase += piece.newlines;
|
|
30341
|
+
}
|
|
30342
|
+
if (any) lineBase += 1;
|
|
30343
|
+
} else {
|
|
30344
|
+
const { text } = readSessionGroupText(group);
|
|
30345
|
+
if (!text) continue;
|
|
30346
|
+
scan(text);
|
|
30347
|
+
lineBase += (text.match(/\n/g)?.length ?? 0) + 1;
|
|
30348
|
+
}
|
|
30349
|
+
}
|
|
30350
|
+
return findings;
|
|
30351
|
+
}
|
|
30352
|
+
function scanLinesChunked(sessionId, lines, tenantRules, pieceBytes = SCAN_PIECE_BYTES) {
|
|
30353
|
+
const findings = [];
|
|
30354
|
+
let lineBase = 0;
|
|
30355
|
+
let piece = [];
|
|
30356
|
+
let bytes = 0;
|
|
30357
|
+
const flush2 = () => {
|
|
30358
|
+
if (piece.length === 0) return;
|
|
30359
|
+
const text = piece.join("");
|
|
30360
|
+
try {
|
|
30361
|
+
for (const x of scanTextForFindings(text)) {
|
|
30362
|
+
findings.push({ session_id: sessionId, detector: "builtin", rule: x.rule, line: x.line + lineBase, preview: x.preview });
|
|
30363
|
+
}
|
|
30364
|
+
} catch {
|
|
30365
|
+
}
|
|
30366
|
+
if (tenantRules && tenantRules.length > 0) {
|
|
30367
|
+
try {
|
|
30368
|
+
for (const x of scanTenantRules(text, tenantRules)) {
|
|
30369
|
+
findings.push({ session_id: sessionId, detector: x.detector, rule: x.rule, line: x.line + lineBase, preview: x.preview });
|
|
30370
|
+
}
|
|
30371
|
+
} catch {
|
|
30372
|
+
}
|
|
30373
|
+
}
|
|
30374
|
+
lineBase += piece.length;
|
|
30375
|
+
piece = [];
|
|
30376
|
+
bytes = 0;
|
|
30377
|
+
};
|
|
30378
|
+
for (const line of lines) {
|
|
30379
|
+
piece.push(line);
|
|
30380
|
+
bytes += line.length;
|
|
30381
|
+
if (bytes >= pieceBytes) flush2();
|
|
30382
|
+
}
|
|
30383
|
+
flush2();
|
|
30384
|
+
return findings;
|
|
30385
|
+
}
|
|
30386
|
+
var SCAN_PIECE_BYTES, NEWLINE;
|
|
30387
|
+
var init_session_file_scan = __esm({
|
|
30388
|
+
"src/session-file-scan.ts"() {
|
|
30389
|
+
"use strict";
|
|
30390
|
+
init_secret_redactor();
|
|
30391
|
+
init_secret_scanner();
|
|
30392
|
+
init_live_session_scan();
|
|
30393
|
+
SCAN_PIECE_BYTES = 1024 * 1024;
|
|
30394
|
+
NEWLINE = 10;
|
|
30395
|
+
}
|
|
30396
|
+
});
|
|
30397
|
+
|
|
30173
30398
|
// src/raw-archive-parts.ts
|
|
30174
|
-
import { createReadStream as createReadStream4, createWriteStream as createWriteStream2, openSync as openSync11, readSync as readSync9, closeSync as closeSync11, rmSync as rmSync5, statSync as
|
|
30399
|
+
import { createReadStream as createReadStream4, createWriteStream as createWriteStream2, openSync as openSync11, readSync as readSync9, closeSync as closeSync11, rmSync as rmSync5, statSync as statSync44 } from "node:fs";
|
|
30175
30400
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
30176
30401
|
import { join as join54 } from "node:path";
|
|
30177
30402
|
import { randomBytes } from "node:crypto";
|
|
@@ -30239,7 +30464,7 @@ async function writeArchiveFile(source, meta, redact, dir = tmpdir2()) {
|
|
|
30239
30464
|
rmSync5(path2, { force: true });
|
|
30240
30465
|
throw err;
|
|
30241
30466
|
}
|
|
30242
|
-
return { path: path2, gzSize:
|
|
30467
|
+
return { path: path2, gzSize: statSync44(path2).size, size };
|
|
30243
30468
|
}
|
|
30244
30469
|
async function putPart(url, body2) {
|
|
30245
30470
|
let last;
|
|
@@ -30477,7 +30702,7 @@ __export(auto_update_exports, {
|
|
|
30477
30702
|
import { execSync as execSync4, execFileSync as execFileSync3 } from "node:child_process";
|
|
30478
30703
|
import { readFileSync as readFileSync47, existsSync as existsSync47 } from "node:fs";
|
|
30479
30704
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
30480
|
-
import { writeFileSync as writeFileSync11, mkdtempSync as mkdtempSync3, rmSync as rmSync6, readdirSync as readdirSync33, statSync as
|
|
30705
|
+
import { writeFileSync as writeFileSync11, mkdtempSync as mkdtempSync3, rmSync as rmSync6, readdirSync as readdirSync33, statSync as statSync45, mkdirSync as mkdirSync12 } from "node:fs";
|
|
30481
30706
|
import { join as join55, dirname as dirname18, sep as sep3, posix as pathPosix, win32 as pathWin32 } from "node:path";
|
|
30482
30707
|
import { tmpdir as tmpdir3, homedir as homedir18 } from "node:os";
|
|
30483
30708
|
import { createHash as createHash11 } from "node:crypto";
|
|
@@ -30530,7 +30755,7 @@ function sweepStaleStaging(root = tmpdir3(), now = Date.now()) {
|
|
|
30530
30755
|
if (!MKDTEMP_SUFFIX.test(name)) continue;
|
|
30531
30756
|
const dir = join55(root, name);
|
|
30532
30757
|
try {
|
|
30533
|
-
const st =
|
|
30758
|
+
const st = statSync45(dir);
|
|
30534
30759
|
if (!st.isDirectory() || now - st.mtimeMs < COLD_MS) continue;
|
|
30535
30760
|
const inside = readdirSync33(dir);
|
|
30536
30761
|
if (inside.length > 1 || inside.length === 1 && inside[0] !== "chat-recall.tgz") continue;
|
|
@@ -30814,7 +31039,7 @@ __export(sync_client_exports, {
|
|
|
30814
31039
|
syncSessions: () => syncSessions
|
|
30815
31040
|
});
|
|
30816
31041
|
import { join as join56, dirname as dirname19, basename as basename24 } from "node:path";
|
|
30817
|
-
import { readFileSync as readFileSync48, writeFileSync as writeFileSync12, mkdirSync as mkdirSync13, mkdtempSync as mkdtempSync4, rmSync as rmSync7, chmodSync as chmodSync6, unlinkSync as unlinkSync3, readdirSync as readdirSync34, statSync as
|
|
31042
|
+
import { readFileSync as readFileSync48, writeFileSync as writeFileSync12, mkdirSync as mkdirSync13, mkdtempSync as mkdtempSync4, rmSync as rmSync7, chmodSync as chmodSync6, unlinkSync as unlinkSync3, readdirSync as readdirSync34, statSync as statSync46 } from "node:fs";
|
|
30818
31043
|
import { tmpdir as tmpdir4, hostname as hostname2 } from "node:os";
|
|
30819
31044
|
import { createHash as createHash12 } from "node:crypto";
|
|
30820
31045
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
@@ -31291,7 +31516,7 @@ function reapStaleScanDirs(dir = tmpdir4(), maxAgeMs = 6 * 36e5, now = Date.now(
|
|
|
31291
31516
|
if (!name.startsWith("cr-batchscan-")) continue;
|
|
31292
31517
|
const p = join56(dir, name);
|
|
31293
31518
|
try {
|
|
31294
|
-
if (now -
|
|
31519
|
+
if (now - statSync46(p).mtimeMs < maxAgeMs) continue;
|
|
31295
31520
|
rmSync7(p, { recursive: true, force: true });
|
|
31296
31521
|
reaped++;
|
|
31297
31522
|
} catch {
|
|
@@ -32195,6 +32420,10 @@ function sessionFileBytes(ref) {
|
|
|
32195
32420
|
if (!backend?.isAppendOnly?.()) return 0;
|
|
32196
32421
|
return backend.fileSize?.(ref.prefixedId) ?? 0;
|
|
32197
32422
|
}
|
|
32423
|
+
function syncTranscript(t) {
|
|
32424
|
+
const cut = t.payloadCap ? { messages: t.messages, subagents: t.subagents } : trimTranscriptForSync(t);
|
|
32425
|
+
return { messages: cut.messages, subagents: cut.subagents.map((s) => ({ ...s, filePath: "" })) };
|
|
32426
|
+
}
|
|
32198
32427
|
function sessionBuildBytes(ref) {
|
|
32199
32428
|
const main2 = sessionFileBytes(ref);
|
|
32200
32429
|
if (main2 === 0) return 0;
|
|
@@ -32231,11 +32460,15 @@ async function buildConversationSync(ref, mtime, opts = {}) {
|
|
|
32231
32460
|
} else {
|
|
32232
32461
|
try {
|
|
32233
32462
|
const backend = getBackendForId(ref.prefixedId) ?? getBackend("claude");
|
|
32234
|
-
const
|
|
32463
|
+
const streamGroups = ref.toolId === "claude" ? resolveSessionContentGroups(ref.rawId) : [];
|
|
32464
|
+
const streamsLines = ref.toolId !== "claude" && !!backend.rawSessionBytes && !!backend.iterateRawSessionLines;
|
|
32465
|
+
const streamedBytes = ref.toolId === "claude" ? sessionGroupsBytes(streamGroups) : streamsLines ? backend.rawSessionBytes(ref.prefixedId) : 0;
|
|
32466
|
+
const streamed = streamedBytes > FULL_BUILD_MAX_BYTES;
|
|
32467
|
+
const exp = streamed ? null : backend.exportRawSession(ref.prefixedId);
|
|
32235
32468
|
let built;
|
|
32236
|
-
const exportBytes = exportByteLength(exp);
|
|
32469
|
+
const exportBytes = streamed ? streamedBytes : exportByteLength(exp);
|
|
32237
32470
|
const overCeiling = exportBytes > FULL_BUILD_MAX_BYTES;
|
|
32238
|
-
if (exp && overCeiling) {
|
|
32471
|
+
if ((exp || streamed) && overCeiling) {
|
|
32239
32472
|
console.error(`[sync] ${ref.prefixedId} export is ${(exportBytes / 1048576).toFixed(0)}MB (over the ${(FULL_BUILD_MAX_BYTES / 1048576).toFixed(0)}MB ceiling) \u2014 parsing it in place, no container copy, no shadow merge, no raw archive`);
|
|
32240
32473
|
record({
|
|
32241
32474
|
kind: "oversized_session",
|
|
@@ -32246,25 +32479,29 @@ async function buildConversationSync(ref, mtime, opts = {}) {
|
|
|
32246
32479
|
includeRaw = false;
|
|
32247
32480
|
includeMeta = false;
|
|
32248
32481
|
exportOverCeiling = true;
|
|
32249
|
-
|
|
32250
|
-
|
|
32251
|
-
|
|
32252
|
-
|
|
32253
|
-
|
|
32254
|
-
|
|
32255
|
-
|
|
32256
|
-
}
|
|
32257
|
-
} catch {
|
|
32258
|
-
}
|
|
32259
|
-
if (opts.tenantRules && opts.tenantRules.length > 0) {
|
|
32482
|
+
if (streamed) {
|
|
32483
|
+
overCeilingFindings = ref.toolId === "claude" ? await scanSessionGroupsChunked(ref.prefixedId, streamGroups, opts.tenantRules) : scanLinesChunked(ref.prefixedId, backend.iterateRawSessionLines(ref.prefixedId), opts.tenantRules);
|
|
32484
|
+
} else if (exp) {
|
|
32485
|
+
overCeilingFindings = [];
|
|
32486
|
+
let lineBase = 0;
|
|
32487
|
+
for (const f of exp.files) {
|
|
32488
|
+
const text = f.bytes.toString("utf8");
|
|
32260
32489
|
try {
|
|
32261
|
-
for (const x of
|
|
32262
|
-
overCeilingFindings.push({ session_id: ref.prefixedId, detector:
|
|
32490
|
+
for (const x of scanTextForFindings(text)) {
|
|
32491
|
+
overCeilingFindings.push({ session_id: ref.prefixedId, detector: "builtin", rule: x.rule, line: x.line + lineBase, preview: x.preview });
|
|
32263
32492
|
}
|
|
32264
32493
|
} catch {
|
|
32265
32494
|
}
|
|
32495
|
+
if (opts.tenantRules && opts.tenantRules.length > 0) {
|
|
32496
|
+
try {
|
|
32497
|
+
for (const x of scanTenantRules(text, opts.tenantRules)) {
|
|
32498
|
+
overCeilingFindings.push({ session_id: ref.prefixedId, detector: x.detector, rule: x.rule, line: x.line + lineBase, preview: x.preview });
|
|
32499
|
+
}
|
|
32500
|
+
} catch {
|
|
32501
|
+
}
|
|
32502
|
+
}
|
|
32503
|
+
lineBase += (text.match(/\n/g)?.length ?? 0) + 1;
|
|
32266
32504
|
}
|
|
32267
|
-
lineBase += (text.match(/\n/g)?.length ?? 0) + 1;
|
|
32268
32505
|
}
|
|
32269
32506
|
}
|
|
32270
32507
|
if (exp && !overCeiling) {
|
|
@@ -32304,7 +32541,7 @@ async function buildConversationSync(ref, mtime, opts = {}) {
|
|
|
32304
32541
|
}
|
|
32305
32542
|
if (!transcript) {
|
|
32306
32543
|
try {
|
|
32307
|
-
const t = await parseTranscript(ref.prefixedId);
|
|
32544
|
+
const t = await parseTranscript(ref.prefixedId, { payloadCap: SYNC_PAYLOAD_CAP });
|
|
32308
32545
|
if (t && (t.messages.length > 0 || t.subagents.length > 0)) transcript = t;
|
|
32309
32546
|
} catch {
|
|
32310
32547
|
}
|
|
@@ -32317,7 +32554,9 @@ async function buildConversationSync(ref, mtime, opts = {}) {
|
|
|
32317
32554
|
if (isInternalToolPrompt(firstUser?.content)) return null;
|
|
32318
32555
|
const count = { redactions: 0 };
|
|
32319
32556
|
const envelope = redactDeep(
|
|
32320
|
-
|
|
32557
|
+
// A transcript the parser already cut is not cut again: the cut is not idempotent.
|
|
32558
|
+
// The path of a subagent file on this machine does not leave it: the container parse gives ''.
|
|
32559
|
+
{ v: TRANSCRIPT_VERSION, ...syncTranscript(transcript) },
|
|
32321
32560
|
count
|
|
32322
32561
|
);
|
|
32323
32562
|
let projectPath = ref.projectPath;
|
|
@@ -32689,6 +32928,7 @@ var init_sync_client = __esm({
|
|
|
32689
32928
|
init_telemetry();
|
|
32690
32929
|
init_collector_health();
|
|
32691
32930
|
init_live_session_scan();
|
|
32931
|
+
init_session_file_scan();
|
|
32692
32932
|
init_raw_archive_parts();
|
|
32693
32933
|
init_backends();
|
|
32694
32934
|
ownVersion = "0.0.0";
|
|
@@ -33264,7 +33504,7 @@ __export(install_skills_exports, {
|
|
|
33264
33504
|
skillsSourceDir: () => skillsSourceDir,
|
|
33265
33505
|
uninstallSkills: () => uninstallSkills
|
|
33266
33506
|
});
|
|
33267
|
-
import { readdirSync as readdirSync36, existsSync as existsSync49, mkdirSync as mkdirSync16, rmSync as rmSync9, cpSync, writeFileSync as writeFileSync16, readFileSync as readFileSync54, statSync as
|
|
33507
|
+
import { readdirSync as readdirSync36, existsSync as existsSync49, mkdirSync as mkdirSync16, rmSync as rmSync9, cpSync, writeFileSync as writeFileSync16, readFileSync as readFileSync54, statSync as statSync48, realpathSync as realpathSync5 } from "fs";
|
|
33268
33508
|
import { createHash as createHash13 } from "crypto";
|
|
33269
33509
|
import { join as join60, basename as basename25 } from "path";
|
|
33270
33510
|
function skillsSourceDir() {
|
|
@@ -34944,14 +35184,14 @@ var init_opencode_tui_config = __esm({
|
|
|
34944
35184
|
return this.array(t);
|
|
34945
35185
|
throw new SyntaxError(`unexpected "${t.v}" at ${t.start}`);
|
|
34946
35186
|
}
|
|
34947
|
-
object(
|
|
35187
|
+
object(open4) {
|
|
34948
35188
|
this.i += 1;
|
|
34949
35189
|
const props = [];
|
|
34950
35190
|
for (; ; ) {
|
|
34951
35191
|
const k = this.at();
|
|
34952
35192
|
if (this.isP(k, "}")) {
|
|
34953
35193
|
this.i += 1;
|
|
34954
|
-
return { k: "obj", start:
|
|
35194
|
+
return { k: "obj", start: open4.start, end: k.end, closeStart: k.start, props };
|
|
34955
35195
|
}
|
|
34956
35196
|
if (!k || k.t !== "s")
|
|
34957
35197
|
throw new SyntaxError(`expected a key at ${k ? k.start : "end"}`);
|
|
@@ -34970,7 +35210,7 @@ var init_opencode_tui_config = __esm({
|
|
|
34970
35210
|
throw new SyntaxError(`expected "," or "}" at ${n ? n.start : "end"}`);
|
|
34971
35211
|
}
|
|
34972
35212
|
}
|
|
34973
|
-
array(
|
|
35213
|
+
array(open4) {
|
|
34974
35214
|
this.i += 1;
|
|
34975
35215
|
const items = [];
|
|
34976
35216
|
const commas = [];
|
|
@@ -34978,7 +35218,7 @@ var init_opencode_tui_config = __esm({
|
|
|
34978
35218
|
const n = this.at();
|
|
34979
35219
|
if (this.isP(n, "]")) {
|
|
34980
35220
|
this.i += 1;
|
|
34981
|
-
return { k: "arr", start:
|
|
35221
|
+
return { k: "arr", start: open4.start, end: n.end, closeStart: n.start, items, commas };
|
|
34982
35222
|
}
|
|
34983
35223
|
items.push(this.value());
|
|
34984
35224
|
const c = this.at();
|
|
@@ -40953,9 +41193,9 @@ ${lines.join("\n")}
|
|
|
40953
41193
|
|
|
40954
41194
|
_Call again with \`detail: true\` for the full brief (fix, locations, agent prompt) so you can start work._` }] };
|
|
40955
41195
|
}
|
|
40956
|
-
const
|
|
40957
|
-
const claimed =
|
|
40958
|
-
const blocks =
|
|
41196
|
+
const open4 = tasks.filter((t) => t.status !== "done" && t.status !== "rejected");
|
|
41197
|
+
const claimed = open4.filter((t) => t.status === "in_progress");
|
|
41198
|
+
const blocks = open4.map((t, i) => {
|
|
40959
41199
|
const head = `## ${i + 1}. ${t.title}
|
|
40960
41200
|
|
|
40961
41201
|
- id: \`${t.id}\` \xB7 status: ${t.status}${t.projectId ? ` \xB7 project: ${t.projectId}` : ""}${t.linkedSessionId ? ` \xB7 already claimed by session ${t.linkedSessionId.slice(0, 8)}` : ""}`;
|
|
@@ -40985,7 +41225,7 @@ ${body2}` : head;
|
|
|
40985
41225
|
"Auto-filed cards also close themselves once a re-index no longer reports their finding, so a",
|
|
40986
41226
|
"real fix ends the task either way."
|
|
40987
41227
|
].join("\n");
|
|
40988
|
-
const header = `# Tasks ready to work (${
|
|
41228
|
+
const header = `# Tasks ready to work (${open4.length}${tasks.length !== open4.length ? ` of ${tasks.length}` : ""})${params.project ? ` \xB7 ${params.project}` : ""}${claimed.length ? `
|
|
40989
41229
|
|
|
40990
41230
|
_${claimed.length} already in progress \u2014 check the session link before starting one of those._` : ""}`;
|
|
40991
41231
|
return { content: [{ type: "text", text: `${header}
|
|
@@ -42673,7 +42913,7 @@ function channelDecision(env = process.env, args = process.argv.slice(2), ancest
|
|
|
42673
42913
|
// src/channel-state.ts
|
|
42674
42914
|
init_data_dir();
|
|
42675
42915
|
import { execFileSync as execFileSync5 } from "node:child_process";
|
|
42676
|
-
import { mkdirSync as mkdirSync14, readFileSync as readFileSync52, readdirSync as readdirSync35, statSync as
|
|
42916
|
+
import { mkdirSync as mkdirSync14, readFileSync as readFileSync52, readdirSync as readdirSync35, statSync as statSync47, unlinkSync as unlinkSync4, writeFileSync as writeFileSync14 } from "node:fs";
|
|
42677
42917
|
import { join as join58 } from "node:path";
|
|
42678
42918
|
function channelStateDir() {
|
|
42679
42919
|
return join58(getDataDir(), "hook-state", "messages");
|
|
@@ -42743,7 +42983,7 @@ function readMarker(sessionId) {
|
|
|
42743
42983
|
const [pidText, started] = readFileSync52(path2, "utf-8").trim().split(" ");
|
|
42744
42984
|
const pid = Number(pidText);
|
|
42745
42985
|
if (!Number.isInteger(pid) || pid <= 1) return null;
|
|
42746
|
-
return { pid, started, mtime:
|
|
42986
|
+
return { pid, started, mtime: statSync47(path2).mtimeMs };
|
|
42747
42987
|
} catch {
|
|
42748
42988
|
return null;
|
|
42749
42989
|
}
|