@threadbase-sh/scanner 0.14.7 → 0.16.0
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 +87 -15
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +98 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +97 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -50,6 +50,7 @@ __export(index_exports, {
|
|
|
50
50
|
getLogger: () => getLogger,
|
|
51
51
|
getProjectsDir: () => getProjectsDir,
|
|
52
52
|
loadProfiles: () => loadProfiles,
|
|
53
|
+
parseCodexJsonlLine: () => parseCodexJsonlLine,
|
|
53
54
|
parseJsonlLine: () => parseJsonlLine,
|
|
54
55
|
readGitBranch: () => readGitBranch,
|
|
55
56
|
readSidecar: () => readSidecar,
|
|
@@ -439,6 +440,8 @@ function initialReducerState() {
|
|
|
439
440
|
model: null,
|
|
440
441
|
messageCount: 0,
|
|
441
442
|
lastMessageSender: "user",
|
|
443
|
+
agentId: "",
|
|
444
|
+
isSidechain: false,
|
|
442
445
|
isTeammate: false,
|
|
443
446
|
firstUserSeen: false,
|
|
444
447
|
firstMessage: null,
|
|
@@ -458,6 +461,8 @@ function reduceLine(state, entry, tier) {
|
|
|
458
461
|
if (entry.sessionId && !state.sessionId) state.sessionId = entry.sessionId;
|
|
459
462
|
if (entry.slug && !state.sessionName) state.sessionName = entry.slug;
|
|
460
463
|
if (entry.teamName && !state.teamName) state.teamName = entry.teamName;
|
|
464
|
+
if (entry.agentId && !state.agentId) state.agentId = entry.agentId;
|
|
465
|
+
if (entry.isSidechain === true) state.isSidechain = true;
|
|
461
466
|
if (entry.timestamp) {
|
|
462
467
|
const ts = entry.timestamp;
|
|
463
468
|
if (!state.latestTimestamp || ts > state.latestTimestamp) state.latestTimestamp = ts;
|
|
@@ -509,9 +514,11 @@ function reduceLine(state, entry, tier) {
|
|
|
509
514
|
}
|
|
510
515
|
function finalizeMeta(state, filePath, account, tier) {
|
|
511
516
|
if (state.messageCount === 0) return null;
|
|
512
|
-
const
|
|
517
|
+
const isSidechain = state.isSidechain && !!state.agentId;
|
|
518
|
+
const isSubagentPath = SUBAGENT_PATH_RE.test(filePath);
|
|
519
|
+
const isSubagent = isSidechain || isSubagentPath;
|
|
513
520
|
let parentSessionId = null;
|
|
514
|
-
if (
|
|
521
|
+
if (isSubagentPath) {
|
|
515
522
|
const uuidDir = (0, import_path2.dirname)((0, import_path2.dirname)(filePath));
|
|
516
523
|
parentSessionId = (0, import_path2.join)((0, import_path2.dirname)(uuidDir), `${(0, import_path2.basename)(uuidDir)}.jsonl`);
|
|
517
524
|
}
|
|
@@ -534,6 +541,10 @@ function finalizeMeta(state, filePath, account, tier) {
|
|
|
534
541
|
model: state.model,
|
|
535
542
|
isSubagent,
|
|
536
543
|
parentSessionId,
|
|
544
|
+
subagentId: isSidechain ? state.agentId : void 0,
|
|
545
|
+
// A sidechain line's `sessionId` IS the parent's id — that is exactly the
|
|
546
|
+
// conflation `subagentId` exists to undo, so it is the parent UUID here.
|
|
547
|
+
parentSessionUuid: isSidechain && state.sessionId ? state.sessionId : void 0,
|
|
537
548
|
isTeammate: state.isTeammate,
|
|
538
549
|
teamName: state.teamName || null,
|
|
539
550
|
toolNames: state.toolNames,
|
|
@@ -542,6 +553,7 @@ function finalizeMeta(state, filePath, account, tier) {
|
|
|
542
553
|
lastPrompt: state.lastPrompt || void 0
|
|
543
554
|
};
|
|
544
555
|
}
|
|
556
|
+
var SUBAGENT_PATH_RE = /[\\/]subagents[\\/]/;
|
|
545
557
|
function deriveSessionNameFromFirstMessage(firstMessage) {
|
|
546
558
|
const firstLine = firstMessage?.text.split("\n", 1)[0]?.trim() ?? "";
|
|
547
559
|
return firstLine.slice(0, 80);
|
|
@@ -1027,6 +1039,8 @@ var CodexCliProvider = class {
|
|
|
1027
1039
|
latestTimestamp: "",
|
|
1028
1040
|
messageCount: 0,
|
|
1029
1041
|
lastMessageSender: "user",
|
|
1042
|
+
isSubagent: false,
|
|
1043
|
+
parentSessionUuid: null,
|
|
1030
1044
|
firstUser: null,
|
|
1031
1045
|
lastUser: null,
|
|
1032
1046
|
lastAssistant: null,
|
|
@@ -1057,6 +1071,26 @@ function extractCodexText(content) {
|
|
|
1057
1071
|
return "";
|
|
1058
1072
|
}).filter(Boolean).map(cleanSystemTags).join(" ");
|
|
1059
1073
|
}
|
|
1074
|
+
function parseCodexJsonlLine(line) {
|
|
1075
|
+
if (!line.trim()) return null;
|
|
1076
|
+
let entry;
|
|
1077
|
+
try {
|
|
1078
|
+
entry = JSON.parse(line);
|
|
1079
|
+
} catch {
|
|
1080
|
+
return null;
|
|
1081
|
+
}
|
|
1082
|
+
return codexEntryToMessage(entry);
|
|
1083
|
+
}
|
|
1084
|
+
function codexEntryToMessage(entry) {
|
|
1085
|
+
const payload = entry.payload;
|
|
1086
|
+
if (!payload || typeof payload !== "object") return null;
|
|
1087
|
+
if (entry.type !== "response_item" || payload.type !== "message") return null;
|
|
1088
|
+
const role = payload.role;
|
|
1089
|
+
if (role !== "user" && role !== "assistant") return null;
|
|
1090
|
+
const text = extractCodexText(payload.content);
|
|
1091
|
+
if (!text) return null;
|
|
1092
|
+
return { role, text, timestamp: asString(entry.timestamp) };
|
|
1093
|
+
}
|
|
1060
1094
|
function reduceCodexEntry(acc, entry, tier) {
|
|
1061
1095
|
const ts = asString(entry.timestamp);
|
|
1062
1096
|
if (ts && (!acc.latestTimestamp || ts > acc.latestTimestamp)) acc.latestTimestamp = ts;
|
|
@@ -1068,6 +1102,10 @@ function reduceCodexEntry(acc, entry, tier) {
|
|
|
1068
1102
|
if (!acc.cwd) acc.cwd = asString(payload.cwd);
|
|
1069
1103
|
const git = payload.git;
|
|
1070
1104
|
if (acc.gitBranch === null && git?.branch) acc.gitBranch = asString(git.branch) || null;
|
|
1105
|
+
if (!acc.isSubagent && isSubagentSource(payload.source)) {
|
|
1106
|
+
acc.isSubagent = true;
|
|
1107
|
+
acc.parentSessionUuid = parentThreadId(payload.source);
|
|
1108
|
+
}
|
|
1071
1109
|
return;
|
|
1072
1110
|
}
|
|
1073
1111
|
if (acc.model === null && payload.model) acc.model = asString(payload.model) || null;
|
|
@@ -1127,8 +1165,10 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
|
|
|
1127
1165
|
contentSnippet: acc.snippetParts.join(" "),
|
|
1128
1166
|
gitBranch: acc.gitBranch,
|
|
1129
1167
|
model: acc.model,
|
|
1130
|
-
isSubagent:
|
|
1168
|
+
isSubagent: acc.isSubagent,
|
|
1169
|
+
// Codex exposes no path-shaped parent, and no per-child id of its own.
|
|
1131
1170
|
parentSessionId: null,
|
|
1171
|
+
parentSessionUuid: acc.parentSessionUuid ?? void 0,
|
|
1132
1172
|
isTeammate: false,
|
|
1133
1173
|
teamName: null,
|
|
1134
1174
|
toolNames: acc.toolNames,
|
|
@@ -1140,6 +1180,17 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
|
|
|
1140
1180
|
function getShortProjectName3(fullPath) {
|
|
1141
1181
|
return fullPath.split("/").filter(Boolean).slice(-3).join("/");
|
|
1142
1182
|
}
|
|
1183
|
+
function isSubagentSource(source) {
|
|
1184
|
+
return typeof source === "object" && source !== null && "subagent" in source;
|
|
1185
|
+
}
|
|
1186
|
+
function parentThreadId(source) {
|
|
1187
|
+
if (!isSubagentSource(source)) return null;
|
|
1188
|
+
const subagent = source.subagent;
|
|
1189
|
+
if (typeof subagent !== "object" || subagent === null) return null;
|
|
1190
|
+
const spawn = subagent.thread_spawn;
|
|
1191
|
+
if (typeof spawn !== "object" || spawn === null) return null;
|
|
1192
|
+
return asString(spawn.parent_thread_id) || null;
|
|
1193
|
+
}
|
|
1143
1194
|
async function parseCodexConversation(filePath, account) {
|
|
1144
1195
|
const log = getLogger();
|
|
1145
1196
|
const messages = [];
|
|
@@ -1167,14 +1218,11 @@ async function parseCodexConversation(filePath, account) {
|
|
|
1167
1218
|
if (!cwd) cwd = asString(payload.cwd);
|
|
1168
1219
|
continue;
|
|
1169
1220
|
}
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
if (
|
|
1175
|
-
messages.push({ role, text, timestamp: ts });
|
|
1176
|
-
textParts.push(text);
|
|
1177
|
-
if (role === "user") lastUserText = text;
|
|
1221
|
+
const message = codexEntryToMessage(entry);
|
|
1222
|
+
if (!message) continue;
|
|
1223
|
+
messages.push(message);
|
|
1224
|
+
textParts.push(message.text);
|
|
1225
|
+
if (message.role === "user") lastUserText = message.text;
|
|
1178
1226
|
}
|
|
1179
1227
|
} catch (err) {
|
|
1180
1228
|
log.warn({ filePath, err }, "parseCodexConversation: read failed");
|
|
@@ -1802,7 +1850,7 @@ var import_fs9 = require("fs");
|
|
|
1802
1850
|
var import_path8 = require("path");
|
|
1803
1851
|
|
|
1804
1852
|
// src/persistent/schema.ts
|
|
1805
|
-
var SCHEMA_VERSION =
|
|
1853
|
+
var SCHEMA_VERSION = 6;
|
|
1806
1854
|
var SCHEMA_SQL = `
|
|
1807
1855
|
CREATE TABLE IF NOT EXISTS conversation_files (
|
|
1808
1856
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -1877,7 +1925,11 @@ CREATE TABLE IF NOT EXISTS conversations (
|
|
|
1877
1925
|
|
|
1878
1926
|
model TEXT,
|
|
1879
1927
|
is_subagent INTEGER NOT NULL DEFAULT 0,
|
|
1928
|
+
-- The parent's JSONL PATH (matched against source_path), not an id.
|
|
1880
1929
|
parent_session_id TEXT,
|
|
1930
|
+
-- The subagent's own id (Claude agentId), and the parent's session UUID.
|
|
1931
|
+
subagent_id TEXT,
|
|
1932
|
+
parent_session_uuid TEXT,
|
|
1881
1933
|
is_teammate INTEGER NOT NULL DEFAULT 0,
|
|
1882
1934
|
team_name TEXT,
|
|
1883
1935
|
tool_names_json TEXT,
|
|
@@ -2010,6 +2062,29 @@ function runMigrations(db) {
|
|
|
2010
2062
|
}
|
|
2011
2063
|
}
|
|
2012
2064
|
}
|
|
2065
|
+
if (current >= 1 && current < 6 && tableExists(db, "conversations")) {
|
|
2066
|
+
for (const [col, ddl] of [
|
|
2067
|
+
["subagent_id", "ALTER TABLE conversations ADD COLUMN subagent_id TEXT"],
|
|
2068
|
+
["parent_session_uuid", "ALTER TABLE conversations ADD COLUMN parent_session_uuid TEXT"]
|
|
2069
|
+
]) {
|
|
2070
|
+
if (!hasColumn(db, "conversations", col)) db.exec(ddl);
|
|
2071
|
+
}
|
|
2072
|
+
if (tableExists(db, "conversation_files")) {
|
|
2073
|
+
const assignments = [];
|
|
2074
|
+
if (hasColumn(db, "conversation_files", "last_indexed_offset")) {
|
|
2075
|
+
assignments.push("last_indexed_offset = 0");
|
|
2076
|
+
}
|
|
2077
|
+
if (hasColumn(db, "conversation_files", "last_indexed_line")) {
|
|
2078
|
+
assignments.push("last_indexed_line = 0");
|
|
2079
|
+
}
|
|
2080
|
+
if (hasColumn(db, "conversation_files", "reducer_state")) {
|
|
2081
|
+
assignments.push("reducer_state = NULL");
|
|
2082
|
+
}
|
|
2083
|
+
if (assignments.length > 0) {
|
|
2084
|
+
db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2013
2088
|
db.exec(SCHEMA_SQL);
|
|
2014
2089
|
db.pragma(`user_version = ${SCHEMA_VERSION}`);
|
|
2015
2090
|
}
|
|
@@ -2334,6 +2409,8 @@ function rowToMeta(row) {
|
|
|
2334
2409
|
model: row.model,
|
|
2335
2410
|
isSubagent: row.is_subagent === 1,
|
|
2336
2411
|
parentSessionId: row.parent_session_id,
|
|
2412
|
+
subagentId: row.subagent_id ?? void 0,
|
|
2413
|
+
parentSessionUuid: row.parent_session_uuid ?? void 0,
|
|
2337
2414
|
isTeammate: row.is_teammate === 1,
|
|
2338
2415
|
teamName: row.team_name,
|
|
2339
2416
|
toolNames: row.tool_names_json ? JSON.parse(row.tool_names_json) : [],
|
|
@@ -2357,7 +2434,8 @@ var ConversationsRepo = class {
|
|
|
2357
2434
|
account, branch, preview, content_snippet, message_count, page_message_count,
|
|
2358
2435
|
last_message_sender,
|
|
2359
2436
|
timestamp, index_seq, first_sent_at, first_sent_text, last_sent_at, last_sent_text,
|
|
2360
|
-
model, is_subagent, parent_session_id,
|
|
2437
|
+
model, is_subagent, parent_session_id, subagent_id, parent_session_uuid,
|
|
2438
|
+
is_teammate, team_name, tool_names_json,
|
|
2361
2439
|
last_prompt, status, updated_at
|
|
2362
2440
|
) VALUES (
|
|
2363
2441
|
@file_id, @source_path, @provider, @kind, @external_session_id,
|
|
@@ -2367,7 +2445,8 @@ var ConversationsRepo = class {
|
|
|
2367
2445
|
@timestamp,
|
|
2368
2446
|
(SELECT COALESCE(MAX(index_seq), 0) + 1 FROM conversations),
|
|
2369
2447
|
@first_sent_at, @first_sent_text, @last_sent_at, @last_sent_text,
|
|
2370
|
-
@model, @is_subagent, @parent_session_id, @
|
|
2448
|
+
@model, @is_subagent, @parent_session_id, @subagent_id, @parent_session_uuid,
|
|
2449
|
+
@is_teammate, @team_name, @tool_names_json,
|
|
2371
2450
|
@last_prompt, 'active', CURRENT_TIMESTAMP
|
|
2372
2451
|
)
|
|
2373
2452
|
ON CONFLICT(file_id) DO UPDATE SET
|
|
@@ -2394,6 +2473,8 @@ var ConversationsRepo = class {
|
|
|
2394
2473
|
model = excluded.model,
|
|
2395
2474
|
is_subagent = excluded.is_subagent,
|
|
2396
2475
|
parent_session_id = excluded.parent_session_id,
|
|
2476
|
+
subagent_id = excluded.subagent_id,
|
|
2477
|
+
parent_session_uuid = excluded.parent_session_uuid,
|
|
2397
2478
|
is_teammate = excluded.is_teammate,
|
|
2398
2479
|
team_name = excluded.team_name,
|
|
2399
2480
|
tool_names_json = excluded.tool_names_json,
|
|
@@ -2429,6 +2510,8 @@ var ConversationsRepo = class {
|
|
|
2429
2510
|
model: meta.model,
|
|
2430
2511
|
is_subagent: meta.isSubagent ? 1 : 0,
|
|
2431
2512
|
parent_session_id: meta.parentSessionId,
|
|
2513
|
+
subagent_id: meta.subagentId ?? null,
|
|
2514
|
+
parent_session_uuid: meta.parentSessionUuid ?? null,
|
|
2432
2515
|
is_teammate: meta.isTeammate ? 1 : 0,
|
|
2433
2516
|
team_name: meta.teamName,
|
|
2434
2517
|
tool_names_json: JSON.stringify(meta.toolNames),
|
|
@@ -3978,6 +4061,7 @@ async function getConversation(id, options, scanner) {
|
|
|
3978
4061
|
getLogger,
|
|
3979
4062
|
getProjectsDir,
|
|
3980
4063
|
loadProfiles,
|
|
4064
|
+
parseCodexJsonlLine,
|
|
3981
4065
|
parseJsonlLine,
|
|
3982
4066
|
readGitBranch,
|
|
3983
4067
|
readSidecar,
|