@threadbase-sh/scanner 0.15.0 → 0.16.1
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 +96 -8
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +95 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +95 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -440,6 +440,8 @@ function initialReducerState() {
|
|
|
440
440
|
model: null,
|
|
441
441
|
messageCount: 0,
|
|
442
442
|
lastMessageSender: "user",
|
|
443
|
+
agentId: "",
|
|
444
|
+
isSidechain: false,
|
|
443
445
|
isTeammate: false,
|
|
444
446
|
firstUserSeen: false,
|
|
445
447
|
firstMessage: null,
|
|
@@ -459,6 +461,8 @@ function reduceLine(state, entry, tier) {
|
|
|
459
461
|
if (entry.sessionId && !state.sessionId) state.sessionId = entry.sessionId;
|
|
460
462
|
if (entry.slug && !state.sessionName) state.sessionName = entry.slug;
|
|
461
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;
|
|
462
466
|
if (entry.timestamp) {
|
|
463
467
|
const ts = entry.timestamp;
|
|
464
468
|
if (!state.latestTimestamp || ts > state.latestTimestamp) state.latestTimestamp = ts;
|
|
@@ -510,9 +514,11 @@ function reduceLine(state, entry, tier) {
|
|
|
510
514
|
}
|
|
511
515
|
function finalizeMeta(state, filePath, account, tier) {
|
|
512
516
|
if (state.messageCount === 0) return null;
|
|
513
|
-
const
|
|
517
|
+
const isSidechain = state.isSidechain && !!state.agentId;
|
|
518
|
+
const isSubagentPath = SUBAGENT_PATH_RE.test(filePath);
|
|
519
|
+
const isSubagent = isSidechain || isSubagentPath;
|
|
514
520
|
let parentSessionId = null;
|
|
515
|
-
if (
|
|
521
|
+
if (isSubagentPath) {
|
|
516
522
|
const uuidDir = (0, import_path2.dirname)((0, import_path2.dirname)(filePath));
|
|
517
523
|
parentSessionId = (0, import_path2.join)((0, import_path2.dirname)(uuidDir), `${(0, import_path2.basename)(uuidDir)}.jsonl`);
|
|
518
524
|
}
|
|
@@ -535,6 +541,10 @@ function finalizeMeta(state, filePath, account, tier) {
|
|
|
535
541
|
model: state.model,
|
|
536
542
|
isSubagent,
|
|
537
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,
|
|
538
548
|
isTeammate: state.isTeammate,
|
|
539
549
|
teamName: state.teamName || null,
|
|
540
550
|
toolNames: state.toolNames,
|
|
@@ -543,6 +553,7 @@ function finalizeMeta(state, filePath, account, tier) {
|
|
|
543
553
|
lastPrompt: state.lastPrompt || void 0
|
|
544
554
|
};
|
|
545
555
|
}
|
|
556
|
+
var SUBAGENT_PATH_RE = /[\\/]subagents[\\/]/;
|
|
546
557
|
function deriveSessionNameFromFirstMessage(firstMessage) {
|
|
547
558
|
const firstLine = firstMessage?.text.split("\n", 1)[0]?.trim() ?? "";
|
|
548
559
|
return firstLine.slice(0, 80);
|
|
@@ -1028,6 +1039,8 @@ var CodexCliProvider = class {
|
|
|
1028
1039
|
latestTimestamp: "",
|
|
1029
1040
|
messageCount: 0,
|
|
1030
1041
|
lastMessageSender: "user",
|
|
1042
|
+
isSubagent: false,
|
|
1043
|
+
parentSessionUuid: null,
|
|
1031
1044
|
firstUser: null,
|
|
1032
1045
|
lastUser: null,
|
|
1033
1046
|
lastAssistant: null,
|
|
@@ -1089,6 +1102,10 @@ function reduceCodexEntry(acc, entry, tier) {
|
|
|
1089
1102
|
if (!acc.cwd) acc.cwd = asString(payload.cwd);
|
|
1090
1103
|
const git = payload.git;
|
|
1091
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
|
+
}
|
|
1092
1109
|
return;
|
|
1093
1110
|
}
|
|
1094
1111
|
if (acc.model === null && payload.model) acc.model = asString(payload.model) || null;
|
|
@@ -1104,6 +1121,7 @@ function reduceCodexEntry(acc, entry, tier) {
|
|
|
1104
1121
|
if (role !== "user" && role !== "assistant") return;
|
|
1105
1122
|
const text = extractCodexText(payload.content);
|
|
1106
1123
|
if (!text) return;
|
|
1124
|
+
if (acc.messageCount === 0 && role === "user" && isCodexInjectedContext(text)) return;
|
|
1107
1125
|
const sender = role;
|
|
1108
1126
|
acc.messageCount++;
|
|
1109
1127
|
acc.lastMessageSender = sender;
|
|
@@ -1137,7 +1155,10 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
|
|
|
1137
1155
|
kind,
|
|
1138
1156
|
externalSessionId: acc.sessionId || void 0,
|
|
1139
1157
|
sessionId,
|
|
1140
|
-
|
|
1158
|
+
// Mirrors the Claude reducer: a rollout carries no slug, so the opening turn
|
|
1159
|
+
// is the only human-readable name source. Only useful because the injected
|
|
1160
|
+
// AGENTS.md turn is skipped above — otherwise every title would be that blob.
|
|
1161
|
+
sessionName: deriveSessionNameFromFirstMessage(acc.firstUser),
|
|
1141
1162
|
projectPath,
|
|
1142
1163
|
projectName: getShortProjectName3(projectPath),
|
|
1143
1164
|
account,
|
|
@@ -1148,8 +1169,10 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
|
|
|
1148
1169
|
contentSnippet: acc.snippetParts.join(" "),
|
|
1149
1170
|
gitBranch: acc.gitBranch,
|
|
1150
1171
|
model: acc.model,
|
|
1151
|
-
isSubagent:
|
|
1172
|
+
isSubagent: acc.isSubagent,
|
|
1173
|
+
// Codex exposes no path-shaped parent, and no per-child id of its own.
|
|
1152
1174
|
parentSessionId: null,
|
|
1175
|
+
parentSessionUuid: acc.parentSessionUuid ?? void 0,
|
|
1153
1176
|
isTeammate: false,
|
|
1154
1177
|
teamName: null,
|
|
1155
1178
|
toolNames: acc.toolNames,
|
|
@@ -1158,9 +1181,24 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
|
|
|
1158
1181
|
lastPrompt: acc.lastUser?.text || void 0
|
|
1159
1182
|
};
|
|
1160
1183
|
}
|
|
1184
|
+
function isCodexInjectedContext(text) {
|
|
1185
|
+
if (text.startsWith("# AGENTS.md") || text.includes("<INSTRUCTIONS>")) return true;
|
|
1186
|
+
return text.startsWith("<permissions instructions>") || text.includes("Filesystem sandboxing defines");
|
|
1187
|
+
}
|
|
1161
1188
|
function getShortProjectName3(fullPath) {
|
|
1162
1189
|
return fullPath.split("/").filter(Boolean).slice(-3).join("/");
|
|
1163
1190
|
}
|
|
1191
|
+
function isSubagentSource(source) {
|
|
1192
|
+
return typeof source === "object" && source !== null && "subagent" in source;
|
|
1193
|
+
}
|
|
1194
|
+
function parentThreadId(source) {
|
|
1195
|
+
if (!isSubagentSource(source)) return null;
|
|
1196
|
+
const subagent = source.subagent;
|
|
1197
|
+
if (typeof subagent !== "object" || subagent === null) return null;
|
|
1198
|
+
const spawn = subagent.thread_spawn;
|
|
1199
|
+
if (typeof spawn !== "object" || spawn === null) return null;
|
|
1200
|
+
return asString(spawn.parent_thread_id) || null;
|
|
1201
|
+
}
|
|
1164
1202
|
async function parseCodexConversation(filePath, account) {
|
|
1165
1203
|
const log = getLogger();
|
|
1166
1204
|
const messages = [];
|
|
@@ -1820,7 +1858,7 @@ var import_fs9 = require("fs");
|
|
|
1820
1858
|
var import_path8 = require("path");
|
|
1821
1859
|
|
|
1822
1860
|
// src/persistent/schema.ts
|
|
1823
|
-
var SCHEMA_VERSION =
|
|
1861
|
+
var SCHEMA_VERSION = 7;
|
|
1824
1862
|
var SCHEMA_SQL = `
|
|
1825
1863
|
CREATE TABLE IF NOT EXISTS conversation_files (
|
|
1826
1864
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -1895,7 +1933,11 @@ CREATE TABLE IF NOT EXISTS conversations (
|
|
|
1895
1933
|
|
|
1896
1934
|
model TEXT,
|
|
1897
1935
|
is_subagent INTEGER NOT NULL DEFAULT 0,
|
|
1936
|
+
-- The parent's JSONL PATH (matched against source_path), not an id.
|
|
1898
1937
|
parent_session_id TEXT,
|
|
1938
|
+
-- The subagent's own id (Claude agentId), and the parent's session UUID.
|
|
1939
|
+
subagent_id TEXT,
|
|
1940
|
+
parent_session_uuid TEXT,
|
|
1899
1941
|
is_teammate INTEGER NOT NULL DEFAULT 0,
|
|
1900
1942
|
team_name TEXT,
|
|
1901
1943
|
tool_names_json TEXT,
|
|
@@ -2028,6 +2070,44 @@ function runMigrations(db) {
|
|
|
2028
2070
|
}
|
|
2029
2071
|
}
|
|
2030
2072
|
}
|
|
2073
|
+
if (current >= 1 && current < 6 && tableExists(db, "conversations")) {
|
|
2074
|
+
for (const [col, ddl] of [
|
|
2075
|
+
["subagent_id", "ALTER TABLE conversations ADD COLUMN subagent_id TEXT"],
|
|
2076
|
+
["parent_session_uuid", "ALTER TABLE conversations ADD COLUMN parent_session_uuid TEXT"]
|
|
2077
|
+
]) {
|
|
2078
|
+
if (!hasColumn(db, "conversations", col)) db.exec(ddl);
|
|
2079
|
+
}
|
|
2080
|
+
if (tableExists(db, "conversation_files")) {
|
|
2081
|
+
const assignments = [];
|
|
2082
|
+
if (hasColumn(db, "conversation_files", "last_indexed_offset")) {
|
|
2083
|
+
assignments.push("last_indexed_offset = 0");
|
|
2084
|
+
}
|
|
2085
|
+
if (hasColumn(db, "conversation_files", "last_indexed_line")) {
|
|
2086
|
+
assignments.push("last_indexed_line = 0");
|
|
2087
|
+
}
|
|
2088
|
+
if (hasColumn(db, "conversation_files", "reducer_state")) {
|
|
2089
|
+
assignments.push("reducer_state = NULL");
|
|
2090
|
+
}
|
|
2091
|
+
if (assignments.length > 0) {
|
|
2092
|
+
db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
if (current >= 1 && current < 7 && tableExists(db, "conversation_files")) {
|
|
2097
|
+
const assignments = [];
|
|
2098
|
+
if (hasColumn(db, "conversation_files", "last_indexed_offset")) {
|
|
2099
|
+
assignments.push("last_indexed_offset = 0");
|
|
2100
|
+
}
|
|
2101
|
+
if (hasColumn(db, "conversation_files", "last_indexed_line")) {
|
|
2102
|
+
assignments.push("last_indexed_line = 0");
|
|
2103
|
+
}
|
|
2104
|
+
if (hasColumn(db, "conversation_files", "reducer_state")) {
|
|
2105
|
+
assignments.push("reducer_state = NULL");
|
|
2106
|
+
}
|
|
2107
|
+
if (assignments.length > 0) {
|
|
2108
|
+
db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2031
2111
|
db.exec(SCHEMA_SQL);
|
|
2032
2112
|
db.pragma(`user_version = ${SCHEMA_VERSION}`);
|
|
2033
2113
|
}
|
|
@@ -2352,6 +2432,8 @@ function rowToMeta(row) {
|
|
|
2352
2432
|
model: row.model,
|
|
2353
2433
|
isSubagent: row.is_subagent === 1,
|
|
2354
2434
|
parentSessionId: row.parent_session_id,
|
|
2435
|
+
subagentId: row.subagent_id ?? void 0,
|
|
2436
|
+
parentSessionUuid: row.parent_session_uuid ?? void 0,
|
|
2355
2437
|
isTeammate: row.is_teammate === 1,
|
|
2356
2438
|
teamName: row.team_name,
|
|
2357
2439
|
toolNames: row.tool_names_json ? JSON.parse(row.tool_names_json) : [],
|
|
@@ -2375,7 +2457,8 @@ var ConversationsRepo = class {
|
|
|
2375
2457
|
account, branch, preview, content_snippet, message_count, page_message_count,
|
|
2376
2458
|
last_message_sender,
|
|
2377
2459
|
timestamp, index_seq, first_sent_at, first_sent_text, last_sent_at, last_sent_text,
|
|
2378
|
-
model, is_subagent, parent_session_id,
|
|
2460
|
+
model, is_subagent, parent_session_id, subagent_id, parent_session_uuid,
|
|
2461
|
+
is_teammate, team_name, tool_names_json,
|
|
2379
2462
|
last_prompt, status, updated_at
|
|
2380
2463
|
) VALUES (
|
|
2381
2464
|
@file_id, @source_path, @provider, @kind, @external_session_id,
|
|
@@ -2385,7 +2468,8 @@ var ConversationsRepo = class {
|
|
|
2385
2468
|
@timestamp,
|
|
2386
2469
|
(SELECT COALESCE(MAX(index_seq), 0) + 1 FROM conversations),
|
|
2387
2470
|
@first_sent_at, @first_sent_text, @last_sent_at, @last_sent_text,
|
|
2388
|
-
@model, @is_subagent, @parent_session_id, @
|
|
2471
|
+
@model, @is_subagent, @parent_session_id, @subagent_id, @parent_session_uuid,
|
|
2472
|
+
@is_teammate, @team_name, @tool_names_json,
|
|
2389
2473
|
@last_prompt, 'active', CURRENT_TIMESTAMP
|
|
2390
2474
|
)
|
|
2391
2475
|
ON CONFLICT(file_id) DO UPDATE SET
|
|
@@ -2412,6 +2496,8 @@ var ConversationsRepo = class {
|
|
|
2412
2496
|
model = excluded.model,
|
|
2413
2497
|
is_subagent = excluded.is_subagent,
|
|
2414
2498
|
parent_session_id = excluded.parent_session_id,
|
|
2499
|
+
subagent_id = excluded.subagent_id,
|
|
2500
|
+
parent_session_uuid = excluded.parent_session_uuid,
|
|
2415
2501
|
is_teammate = excluded.is_teammate,
|
|
2416
2502
|
team_name = excluded.team_name,
|
|
2417
2503
|
tool_names_json = excluded.tool_names_json,
|
|
@@ -2447,6 +2533,8 @@ var ConversationsRepo = class {
|
|
|
2447
2533
|
model: meta.model,
|
|
2448
2534
|
is_subagent: meta.isSubagent ? 1 : 0,
|
|
2449
2535
|
parent_session_id: meta.parentSessionId,
|
|
2536
|
+
subagent_id: meta.subagentId ?? null,
|
|
2537
|
+
parent_session_uuid: meta.parentSessionUuid ?? null,
|
|
2450
2538
|
is_teammate: meta.isTeammate ? 1 : 0,
|
|
2451
2539
|
team_name: meta.teamName,
|
|
2452
2540
|
tool_names_json: JSON.stringify(meta.toolNames),
|