@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.d.cts
CHANGED
|
@@ -44,6 +44,8 @@ interface ConversationMeta {
|
|
|
44
44
|
model: string | null;
|
|
45
45
|
isSubagent: boolean;
|
|
46
46
|
parentSessionId: string | null;
|
|
47
|
+
subagentId?: string;
|
|
48
|
+
parentSessionUuid?: string;
|
|
47
49
|
isTeammate: boolean;
|
|
48
50
|
teamName: string | null;
|
|
49
51
|
toolNames: string[];
|
|
@@ -303,6 +305,8 @@ interface CodexAccumulator {
|
|
|
303
305
|
latestTimestamp: string;
|
|
304
306
|
messageCount: number;
|
|
305
307
|
lastMessageSender: MessageSender;
|
|
308
|
+
isSubagent: boolean;
|
|
309
|
+
parentSessionUuid: string | null;
|
|
306
310
|
firstUser: MessageSnapshot | null;
|
|
307
311
|
lastUser: MessageSnapshot | null;
|
|
308
312
|
lastAssistant: MessageSnapshot | null;
|
|
@@ -332,6 +336,8 @@ interface ReducerState {
|
|
|
332
336
|
messageCount: number;
|
|
333
337
|
pageMessageCount: number;
|
|
334
338
|
lastMessageSender: MessageSender;
|
|
339
|
+
agentId: string;
|
|
340
|
+
isSidechain: boolean;
|
|
335
341
|
isTeammate: boolean;
|
|
336
342
|
firstUserSeen: boolean;
|
|
337
343
|
firstMessage: MessageSnapshot | null;
|
package/dist/index.d.ts
CHANGED
|
@@ -44,6 +44,8 @@ interface ConversationMeta {
|
|
|
44
44
|
model: string | null;
|
|
45
45
|
isSubagent: boolean;
|
|
46
46
|
parentSessionId: string | null;
|
|
47
|
+
subagentId?: string;
|
|
48
|
+
parentSessionUuid?: string;
|
|
47
49
|
isTeammate: boolean;
|
|
48
50
|
teamName: string | null;
|
|
49
51
|
toolNames: string[];
|
|
@@ -303,6 +305,8 @@ interface CodexAccumulator {
|
|
|
303
305
|
latestTimestamp: string;
|
|
304
306
|
messageCount: number;
|
|
305
307
|
lastMessageSender: MessageSender;
|
|
308
|
+
isSubagent: boolean;
|
|
309
|
+
parentSessionUuid: string | null;
|
|
306
310
|
firstUser: MessageSnapshot | null;
|
|
307
311
|
lastUser: MessageSnapshot | null;
|
|
308
312
|
lastAssistant: MessageSnapshot | null;
|
|
@@ -332,6 +336,8 @@ interface ReducerState {
|
|
|
332
336
|
messageCount: number;
|
|
333
337
|
pageMessageCount: number;
|
|
334
338
|
lastMessageSender: MessageSender;
|
|
339
|
+
agentId: string;
|
|
340
|
+
isSidechain: boolean;
|
|
335
341
|
isTeammate: boolean;
|
|
336
342
|
firstUserSeen: boolean;
|
|
337
343
|
firstMessage: MessageSnapshot | null;
|
package/dist/index.js
CHANGED
|
@@ -373,6 +373,8 @@ function initialReducerState() {
|
|
|
373
373
|
model: null,
|
|
374
374
|
messageCount: 0,
|
|
375
375
|
lastMessageSender: "user",
|
|
376
|
+
agentId: "",
|
|
377
|
+
isSidechain: false,
|
|
376
378
|
isTeammate: false,
|
|
377
379
|
firstUserSeen: false,
|
|
378
380
|
firstMessage: null,
|
|
@@ -392,6 +394,8 @@ function reduceLine(state, entry, tier) {
|
|
|
392
394
|
if (entry.sessionId && !state.sessionId) state.sessionId = entry.sessionId;
|
|
393
395
|
if (entry.slug && !state.sessionName) state.sessionName = entry.slug;
|
|
394
396
|
if (entry.teamName && !state.teamName) state.teamName = entry.teamName;
|
|
397
|
+
if (entry.agentId && !state.agentId) state.agentId = entry.agentId;
|
|
398
|
+
if (entry.isSidechain === true) state.isSidechain = true;
|
|
395
399
|
if (entry.timestamp) {
|
|
396
400
|
const ts = entry.timestamp;
|
|
397
401
|
if (!state.latestTimestamp || ts > state.latestTimestamp) state.latestTimestamp = ts;
|
|
@@ -443,9 +447,11 @@ function reduceLine(state, entry, tier) {
|
|
|
443
447
|
}
|
|
444
448
|
function finalizeMeta(state, filePath, account, tier) {
|
|
445
449
|
if (state.messageCount === 0) return null;
|
|
446
|
-
const
|
|
450
|
+
const isSidechain = state.isSidechain && !!state.agentId;
|
|
451
|
+
const isSubagentPath = SUBAGENT_PATH_RE.test(filePath);
|
|
452
|
+
const isSubagent = isSidechain || isSubagentPath;
|
|
447
453
|
let parentSessionId = null;
|
|
448
|
-
if (
|
|
454
|
+
if (isSubagentPath) {
|
|
449
455
|
const uuidDir = dirname2(dirname2(filePath));
|
|
450
456
|
parentSessionId = join2(dirname2(uuidDir), `${basename(uuidDir)}.jsonl`);
|
|
451
457
|
}
|
|
@@ -468,6 +474,10 @@ function finalizeMeta(state, filePath, account, tier) {
|
|
|
468
474
|
model: state.model,
|
|
469
475
|
isSubagent,
|
|
470
476
|
parentSessionId,
|
|
477
|
+
subagentId: isSidechain ? state.agentId : void 0,
|
|
478
|
+
// A sidechain line's `sessionId` IS the parent's id — that is exactly the
|
|
479
|
+
// conflation `subagentId` exists to undo, so it is the parent UUID here.
|
|
480
|
+
parentSessionUuid: isSidechain && state.sessionId ? state.sessionId : void 0,
|
|
471
481
|
isTeammate: state.isTeammate,
|
|
472
482
|
teamName: state.teamName || null,
|
|
473
483
|
toolNames: state.toolNames,
|
|
@@ -476,6 +486,7 @@ function finalizeMeta(state, filePath, account, tier) {
|
|
|
476
486
|
lastPrompt: state.lastPrompt || void 0
|
|
477
487
|
};
|
|
478
488
|
}
|
|
489
|
+
var SUBAGENT_PATH_RE = /[\\/]subagents[\\/]/;
|
|
479
490
|
function deriveSessionNameFromFirstMessage(firstMessage) {
|
|
480
491
|
const firstLine = firstMessage?.text.split("\n", 1)[0]?.trim() ?? "";
|
|
481
492
|
return firstLine.slice(0, 80);
|
|
@@ -961,6 +972,8 @@ var CodexCliProvider = class {
|
|
|
961
972
|
latestTimestamp: "",
|
|
962
973
|
messageCount: 0,
|
|
963
974
|
lastMessageSender: "user",
|
|
975
|
+
isSubagent: false,
|
|
976
|
+
parentSessionUuid: null,
|
|
964
977
|
firstUser: null,
|
|
965
978
|
lastUser: null,
|
|
966
979
|
lastAssistant: null,
|
|
@@ -1022,6 +1035,10 @@ function reduceCodexEntry(acc, entry, tier) {
|
|
|
1022
1035
|
if (!acc.cwd) acc.cwd = asString(payload.cwd);
|
|
1023
1036
|
const git = payload.git;
|
|
1024
1037
|
if (acc.gitBranch === null && git?.branch) acc.gitBranch = asString(git.branch) || null;
|
|
1038
|
+
if (!acc.isSubagent && isSubagentSource(payload.source)) {
|
|
1039
|
+
acc.isSubagent = true;
|
|
1040
|
+
acc.parentSessionUuid = parentThreadId(payload.source);
|
|
1041
|
+
}
|
|
1025
1042
|
return;
|
|
1026
1043
|
}
|
|
1027
1044
|
if (acc.model === null && payload.model) acc.model = asString(payload.model) || null;
|
|
@@ -1037,6 +1054,7 @@ function reduceCodexEntry(acc, entry, tier) {
|
|
|
1037
1054
|
if (role !== "user" && role !== "assistant") return;
|
|
1038
1055
|
const text = extractCodexText(payload.content);
|
|
1039
1056
|
if (!text) return;
|
|
1057
|
+
if (acc.messageCount === 0 && role === "user" && isCodexInjectedContext(text)) return;
|
|
1040
1058
|
const sender = role;
|
|
1041
1059
|
acc.messageCount++;
|
|
1042
1060
|
acc.lastMessageSender = sender;
|
|
@@ -1070,7 +1088,10 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
|
|
|
1070
1088
|
kind,
|
|
1071
1089
|
externalSessionId: acc.sessionId || void 0,
|
|
1072
1090
|
sessionId,
|
|
1073
|
-
|
|
1091
|
+
// Mirrors the Claude reducer: a rollout carries no slug, so the opening turn
|
|
1092
|
+
// is the only human-readable name source. Only useful because the injected
|
|
1093
|
+
// AGENTS.md turn is skipped above — otherwise every title would be that blob.
|
|
1094
|
+
sessionName: deriveSessionNameFromFirstMessage(acc.firstUser),
|
|
1074
1095
|
projectPath,
|
|
1075
1096
|
projectName: getShortProjectName3(projectPath),
|
|
1076
1097
|
account,
|
|
@@ -1081,8 +1102,10 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
|
|
|
1081
1102
|
contentSnippet: acc.snippetParts.join(" "),
|
|
1082
1103
|
gitBranch: acc.gitBranch,
|
|
1083
1104
|
model: acc.model,
|
|
1084
|
-
isSubagent:
|
|
1105
|
+
isSubagent: acc.isSubagent,
|
|
1106
|
+
// Codex exposes no path-shaped parent, and no per-child id of its own.
|
|
1085
1107
|
parentSessionId: null,
|
|
1108
|
+
parentSessionUuid: acc.parentSessionUuid ?? void 0,
|
|
1086
1109
|
isTeammate: false,
|
|
1087
1110
|
teamName: null,
|
|
1088
1111
|
toolNames: acc.toolNames,
|
|
@@ -1091,9 +1114,24 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
|
|
|
1091
1114
|
lastPrompt: acc.lastUser?.text || void 0
|
|
1092
1115
|
};
|
|
1093
1116
|
}
|
|
1117
|
+
function isCodexInjectedContext(text) {
|
|
1118
|
+
if (text.startsWith("# AGENTS.md") || text.includes("<INSTRUCTIONS>")) return true;
|
|
1119
|
+
return text.startsWith("<permissions instructions>") || text.includes("Filesystem sandboxing defines");
|
|
1120
|
+
}
|
|
1094
1121
|
function getShortProjectName3(fullPath) {
|
|
1095
1122
|
return fullPath.split("/").filter(Boolean).slice(-3).join("/");
|
|
1096
1123
|
}
|
|
1124
|
+
function isSubagentSource(source) {
|
|
1125
|
+
return typeof source === "object" && source !== null && "subagent" in source;
|
|
1126
|
+
}
|
|
1127
|
+
function parentThreadId(source) {
|
|
1128
|
+
if (!isSubagentSource(source)) return null;
|
|
1129
|
+
const subagent = source.subagent;
|
|
1130
|
+
if (typeof subagent !== "object" || subagent === null) return null;
|
|
1131
|
+
const spawn = subagent.thread_spawn;
|
|
1132
|
+
if (typeof spawn !== "object" || spawn === null) return null;
|
|
1133
|
+
return asString(spawn.parent_thread_id) || null;
|
|
1134
|
+
}
|
|
1097
1135
|
async function parseCodexConversation(filePath, account) {
|
|
1098
1136
|
const log = getLogger();
|
|
1099
1137
|
const messages = [];
|
|
@@ -1753,7 +1791,7 @@ import { mkdirSync } from "fs";
|
|
|
1753
1791
|
import { dirname as dirname3 } from "path";
|
|
1754
1792
|
|
|
1755
1793
|
// src/persistent/schema.ts
|
|
1756
|
-
var SCHEMA_VERSION =
|
|
1794
|
+
var SCHEMA_VERSION = 7;
|
|
1757
1795
|
var SCHEMA_SQL = `
|
|
1758
1796
|
CREATE TABLE IF NOT EXISTS conversation_files (
|
|
1759
1797
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -1828,7 +1866,11 @@ CREATE TABLE IF NOT EXISTS conversations (
|
|
|
1828
1866
|
|
|
1829
1867
|
model TEXT,
|
|
1830
1868
|
is_subagent INTEGER NOT NULL DEFAULT 0,
|
|
1869
|
+
-- The parent's JSONL PATH (matched against source_path), not an id.
|
|
1831
1870
|
parent_session_id TEXT,
|
|
1871
|
+
-- The subagent's own id (Claude agentId), and the parent's session UUID.
|
|
1872
|
+
subagent_id TEXT,
|
|
1873
|
+
parent_session_uuid TEXT,
|
|
1832
1874
|
is_teammate INTEGER NOT NULL DEFAULT 0,
|
|
1833
1875
|
team_name TEXT,
|
|
1834
1876
|
tool_names_json TEXT,
|
|
@@ -1961,6 +2003,44 @@ function runMigrations(db) {
|
|
|
1961
2003
|
}
|
|
1962
2004
|
}
|
|
1963
2005
|
}
|
|
2006
|
+
if (current >= 1 && current < 6 && tableExists(db, "conversations")) {
|
|
2007
|
+
for (const [col, ddl] of [
|
|
2008
|
+
["subagent_id", "ALTER TABLE conversations ADD COLUMN subagent_id TEXT"],
|
|
2009
|
+
["parent_session_uuid", "ALTER TABLE conversations ADD COLUMN parent_session_uuid TEXT"]
|
|
2010
|
+
]) {
|
|
2011
|
+
if (!hasColumn(db, "conversations", col)) db.exec(ddl);
|
|
2012
|
+
}
|
|
2013
|
+
if (tableExists(db, "conversation_files")) {
|
|
2014
|
+
const assignments = [];
|
|
2015
|
+
if (hasColumn(db, "conversation_files", "last_indexed_offset")) {
|
|
2016
|
+
assignments.push("last_indexed_offset = 0");
|
|
2017
|
+
}
|
|
2018
|
+
if (hasColumn(db, "conversation_files", "last_indexed_line")) {
|
|
2019
|
+
assignments.push("last_indexed_line = 0");
|
|
2020
|
+
}
|
|
2021
|
+
if (hasColumn(db, "conversation_files", "reducer_state")) {
|
|
2022
|
+
assignments.push("reducer_state = NULL");
|
|
2023
|
+
}
|
|
2024
|
+
if (assignments.length > 0) {
|
|
2025
|
+
db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
}
|
|
2029
|
+
if (current >= 1 && current < 7 && tableExists(db, "conversation_files")) {
|
|
2030
|
+
const assignments = [];
|
|
2031
|
+
if (hasColumn(db, "conversation_files", "last_indexed_offset")) {
|
|
2032
|
+
assignments.push("last_indexed_offset = 0");
|
|
2033
|
+
}
|
|
2034
|
+
if (hasColumn(db, "conversation_files", "last_indexed_line")) {
|
|
2035
|
+
assignments.push("last_indexed_line = 0");
|
|
2036
|
+
}
|
|
2037
|
+
if (hasColumn(db, "conversation_files", "reducer_state")) {
|
|
2038
|
+
assignments.push("reducer_state = NULL");
|
|
2039
|
+
}
|
|
2040
|
+
if (assignments.length > 0) {
|
|
2041
|
+
db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
1964
2044
|
db.exec(SCHEMA_SQL);
|
|
1965
2045
|
db.pragma(`user_version = ${SCHEMA_VERSION}`);
|
|
1966
2046
|
}
|
|
@@ -2285,6 +2365,8 @@ function rowToMeta(row) {
|
|
|
2285
2365
|
model: row.model,
|
|
2286
2366
|
isSubagent: row.is_subagent === 1,
|
|
2287
2367
|
parentSessionId: row.parent_session_id,
|
|
2368
|
+
subagentId: row.subagent_id ?? void 0,
|
|
2369
|
+
parentSessionUuid: row.parent_session_uuid ?? void 0,
|
|
2288
2370
|
isTeammate: row.is_teammate === 1,
|
|
2289
2371
|
teamName: row.team_name,
|
|
2290
2372
|
toolNames: row.tool_names_json ? JSON.parse(row.tool_names_json) : [],
|
|
@@ -2308,7 +2390,8 @@ var ConversationsRepo = class {
|
|
|
2308
2390
|
account, branch, preview, content_snippet, message_count, page_message_count,
|
|
2309
2391
|
last_message_sender,
|
|
2310
2392
|
timestamp, index_seq, first_sent_at, first_sent_text, last_sent_at, last_sent_text,
|
|
2311
|
-
model, is_subagent, parent_session_id,
|
|
2393
|
+
model, is_subagent, parent_session_id, subagent_id, parent_session_uuid,
|
|
2394
|
+
is_teammate, team_name, tool_names_json,
|
|
2312
2395
|
last_prompt, status, updated_at
|
|
2313
2396
|
) VALUES (
|
|
2314
2397
|
@file_id, @source_path, @provider, @kind, @external_session_id,
|
|
@@ -2318,7 +2401,8 @@ var ConversationsRepo = class {
|
|
|
2318
2401
|
@timestamp,
|
|
2319
2402
|
(SELECT COALESCE(MAX(index_seq), 0) + 1 FROM conversations),
|
|
2320
2403
|
@first_sent_at, @first_sent_text, @last_sent_at, @last_sent_text,
|
|
2321
|
-
@model, @is_subagent, @parent_session_id, @
|
|
2404
|
+
@model, @is_subagent, @parent_session_id, @subagent_id, @parent_session_uuid,
|
|
2405
|
+
@is_teammate, @team_name, @tool_names_json,
|
|
2322
2406
|
@last_prompt, 'active', CURRENT_TIMESTAMP
|
|
2323
2407
|
)
|
|
2324
2408
|
ON CONFLICT(file_id) DO UPDATE SET
|
|
@@ -2345,6 +2429,8 @@ var ConversationsRepo = class {
|
|
|
2345
2429
|
model = excluded.model,
|
|
2346
2430
|
is_subagent = excluded.is_subagent,
|
|
2347
2431
|
parent_session_id = excluded.parent_session_id,
|
|
2432
|
+
subagent_id = excluded.subagent_id,
|
|
2433
|
+
parent_session_uuid = excluded.parent_session_uuid,
|
|
2348
2434
|
is_teammate = excluded.is_teammate,
|
|
2349
2435
|
team_name = excluded.team_name,
|
|
2350
2436
|
tool_names_json = excluded.tool_names_json,
|
|
@@ -2380,6 +2466,8 @@ var ConversationsRepo = class {
|
|
|
2380
2466
|
model: meta.model,
|
|
2381
2467
|
is_subagent: meta.isSubagent ? 1 : 0,
|
|
2382
2468
|
parent_session_id: meta.parentSessionId,
|
|
2469
|
+
subagent_id: meta.subagentId ?? null,
|
|
2470
|
+
parent_session_uuid: meta.parentSessionUuid ?? null,
|
|
2383
2471
|
is_teammate: meta.isTeammate ? 1 : 0,
|
|
2384
2472
|
team_name: meta.teamName,
|
|
2385
2473
|
tool_names_json: JSON.stringify(meta.toolNames),
|