@threadbase-sh/scanner 0.15.0 → 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/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 isSubagent = filePath.includes("/subagents/");
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 (isSubagent) {
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;
@@ -1148,8 +1165,10 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
1148
1165
  contentSnippet: acc.snippetParts.join(" "),
1149
1166
  gitBranch: acc.gitBranch,
1150
1167
  model: acc.model,
1151
- isSubagent: false,
1168
+ isSubagent: acc.isSubagent,
1169
+ // Codex exposes no path-shaped parent, and no per-child id of its own.
1152
1170
  parentSessionId: null,
1171
+ parentSessionUuid: acc.parentSessionUuid ?? void 0,
1153
1172
  isTeammate: false,
1154
1173
  teamName: null,
1155
1174
  toolNames: acc.toolNames,
@@ -1161,6 +1180,17 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
1161
1180
  function getShortProjectName3(fullPath) {
1162
1181
  return fullPath.split("/").filter(Boolean).slice(-3).join("/");
1163
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
+ }
1164
1194
  async function parseCodexConversation(filePath, account) {
1165
1195
  const log = getLogger();
1166
1196
  const messages = [];
@@ -1820,7 +1850,7 @@ var import_fs9 = require("fs");
1820
1850
  var import_path8 = require("path");
1821
1851
 
1822
1852
  // src/persistent/schema.ts
1823
- var SCHEMA_VERSION = 5;
1853
+ var SCHEMA_VERSION = 6;
1824
1854
  var SCHEMA_SQL = `
1825
1855
  CREATE TABLE IF NOT EXISTS conversation_files (
1826
1856
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -1895,7 +1925,11 @@ CREATE TABLE IF NOT EXISTS conversations (
1895
1925
 
1896
1926
  model TEXT,
1897
1927
  is_subagent INTEGER NOT NULL DEFAULT 0,
1928
+ -- The parent's JSONL PATH (matched against source_path), not an id.
1898
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,
1899
1933
  is_teammate INTEGER NOT NULL DEFAULT 0,
1900
1934
  team_name TEXT,
1901
1935
  tool_names_json TEXT,
@@ -2028,6 +2062,29 @@ function runMigrations(db) {
2028
2062
  }
2029
2063
  }
2030
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
+ }
2031
2088
  db.exec(SCHEMA_SQL);
2032
2089
  db.pragma(`user_version = ${SCHEMA_VERSION}`);
2033
2090
  }
@@ -2352,6 +2409,8 @@ function rowToMeta(row) {
2352
2409
  model: row.model,
2353
2410
  isSubagent: row.is_subagent === 1,
2354
2411
  parentSessionId: row.parent_session_id,
2412
+ subagentId: row.subagent_id ?? void 0,
2413
+ parentSessionUuid: row.parent_session_uuid ?? void 0,
2355
2414
  isTeammate: row.is_teammate === 1,
2356
2415
  teamName: row.team_name,
2357
2416
  toolNames: row.tool_names_json ? JSON.parse(row.tool_names_json) : [],
@@ -2375,7 +2434,8 @@ var ConversationsRepo = class {
2375
2434
  account, branch, preview, content_snippet, message_count, page_message_count,
2376
2435
  last_message_sender,
2377
2436
  timestamp, index_seq, first_sent_at, first_sent_text, last_sent_at, last_sent_text,
2378
- model, is_subagent, parent_session_id, is_teammate, team_name, tool_names_json,
2437
+ model, is_subagent, parent_session_id, subagent_id, parent_session_uuid,
2438
+ is_teammate, team_name, tool_names_json,
2379
2439
  last_prompt, status, updated_at
2380
2440
  ) VALUES (
2381
2441
  @file_id, @source_path, @provider, @kind, @external_session_id,
@@ -2385,7 +2445,8 @@ var ConversationsRepo = class {
2385
2445
  @timestamp,
2386
2446
  (SELECT COALESCE(MAX(index_seq), 0) + 1 FROM conversations),
2387
2447
  @first_sent_at, @first_sent_text, @last_sent_at, @last_sent_text,
2388
- @model, @is_subagent, @parent_session_id, @is_teammate, @team_name, @tool_names_json,
2448
+ @model, @is_subagent, @parent_session_id, @subagent_id, @parent_session_uuid,
2449
+ @is_teammate, @team_name, @tool_names_json,
2389
2450
  @last_prompt, 'active', CURRENT_TIMESTAMP
2390
2451
  )
2391
2452
  ON CONFLICT(file_id) DO UPDATE SET
@@ -2412,6 +2473,8 @@ var ConversationsRepo = class {
2412
2473
  model = excluded.model,
2413
2474
  is_subagent = excluded.is_subagent,
2414
2475
  parent_session_id = excluded.parent_session_id,
2476
+ subagent_id = excluded.subagent_id,
2477
+ parent_session_uuid = excluded.parent_session_uuid,
2415
2478
  is_teammate = excluded.is_teammate,
2416
2479
  team_name = excluded.team_name,
2417
2480
  tool_names_json = excluded.tool_names_json,
@@ -2447,6 +2510,8 @@ var ConversationsRepo = class {
2447
2510
  model: meta.model,
2448
2511
  is_subagent: meta.isSubagent ? 1 : 0,
2449
2512
  parent_session_id: meta.parentSessionId,
2513
+ subagent_id: meta.subagentId ?? null,
2514
+ parent_session_uuid: meta.parentSessionUuid ?? null,
2450
2515
  is_teammate: meta.isTeammate ? 1 : 0,
2451
2516
  team_name: meta.teamName,
2452
2517
  tool_names_json: JSON.stringify(meta.toolNames),