@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/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;
@@ -320,6 +324,7 @@ declare class CodexCliProvider implements ScannerProvider<CodexAccumulator> {
320
324
  reduceEntry(acc: CodexAccumulator, entry: Record<string, unknown>, tier: ContentTier): void;
321
325
  finalize(acc: CodexAccumulator, filePath: string, account: string, tier: ContentTier): ConversationMeta | null;
322
326
  }
327
+ declare function parseCodexJsonlLine(line: string): ConversationMessage | null;
323
328
 
324
329
  interface ReducerState {
325
330
  sessionId: string;
@@ -331,6 +336,8 @@ interface ReducerState {
331
336
  messageCount: number;
332
337
  pageMessageCount: number;
333
338
  lastMessageSender: MessageSender;
339
+ agentId: string;
340
+ isSidechain: boolean;
334
341
  isTeammate: boolean;
335
342
  firstUserSeen: boolean;
336
343
  firstMessage: MessageSnapshot | null;
@@ -445,4 +452,4 @@ declare function scan(options?: ScanOptions, scanner?: ConversationScanner): Pro
445
452
  declare function search(query: string, options?: SearchOptions, scanner?: ConversationScanner): Promise<SearchResult[]>;
446
453
  declare function getConversation(id: string, options?: GetConversationOptions, scanner?: ConversationScanner): Promise<Conversation | null>;
447
454
 
448
- export { type AttachmentSidecar, CodexCliProvider, type ContentTier, type Conversation, type ConversationMessage, type ConversationMeta, type ConversationPage, ConversationScanner, type ConversationScannerOptions, DEFAULT_TIERS, type DeferredToolsDeltaAttachment, type DiscoveredConversationFile, type FileStatEntry, type GetConversationOptions, type GetConversationPageOptions, type GroupedConversations, type Include, type ConvReducerState as JsonlParseState, type MessageMetadata, type MessageSender, type MessageSnapshot, type PersistentConfig, type Profile, type ProviderName, type ScanOptions, type ScanResult, type ScannerChangeEvent, type ScannerProvider, type ScannerProviderName, type SearchHighlight, SearchIndexer, type SearchMatch, type SearchOptions, type SearchResult, type Sidecar, type SingleFilePage, type SortOrder, type TeamInfo, ThreadbaseProvider, type ToolResultBlock, type ToolUseBlock, type TreeConversation, type TurnDuration, VALID_SORT_ORDERS, type View, type WatchOptions, applyAccountFilter, applyIncludeFilter, applyPagination, applyProjectFilter, applySinceFilter, applySort, cleanSystemTags, initialConvState as createJsonlParseState, createLogger, detectDefaultProfile, getConversation, getLogger, getProjectsDir, loadProfiles, parseJsonlLine, readGitBranch, readSidecar, resetDefaultScanner, resolveConfigDir, resolveTier, saveProfiles, scan, search, setLogger, sidecarPath };
455
+ export { type AttachmentSidecar, CodexCliProvider, type ContentTier, type Conversation, type ConversationMessage, type ConversationMeta, type ConversationPage, ConversationScanner, type ConversationScannerOptions, DEFAULT_TIERS, type DeferredToolsDeltaAttachment, type DiscoveredConversationFile, type FileStatEntry, type GetConversationOptions, type GetConversationPageOptions, type GroupedConversations, type Include, type ConvReducerState as JsonlParseState, type MessageMetadata, type MessageSender, type MessageSnapshot, type PersistentConfig, type Profile, type ProviderName, type ScanOptions, type ScanResult, type ScannerChangeEvent, type ScannerProvider, type ScannerProviderName, type SearchHighlight, SearchIndexer, type SearchMatch, type SearchOptions, type SearchResult, type Sidecar, type SingleFilePage, type SortOrder, type TeamInfo, ThreadbaseProvider, type ToolResultBlock, type ToolUseBlock, type TreeConversation, type TurnDuration, VALID_SORT_ORDERS, type View, type WatchOptions, applyAccountFilter, applyIncludeFilter, applyPagination, applyProjectFilter, applySinceFilter, applySort, cleanSystemTags, initialConvState as createJsonlParseState, createLogger, detectDefaultProfile, getConversation, getLogger, getProjectsDir, loadProfiles, parseCodexJsonlLine, parseJsonlLine, readGitBranch, readSidecar, resetDefaultScanner, resolveConfigDir, resolveTier, saveProfiles, scan, search, setLogger, sidecarPath };
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;
@@ -320,6 +324,7 @@ declare class CodexCliProvider implements ScannerProvider<CodexAccumulator> {
320
324
  reduceEntry(acc: CodexAccumulator, entry: Record<string, unknown>, tier: ContentTier): void;
321
325
  finalize(acc: CodexAccumulator, filePath: string, account: string, tier: ContentTier): ConversationMeta | null;
322
326
  }
327
+ declare function parseCodexJsonlLine(line: string): ConversationMessage | null;
323
328
 
324
329
  interface ReducerState {
325
330
  sessionId: string;
@@ -331,6 +336,8 @@ interface ReducerState {
331
336
  messageCount: number;
332
337
  pageMessageCount: number;
333
338
  lastMessageSender: MessageSender;
339
+ agentId: string;
340
+ isSidechain: boolean;
334
341
  isTeammate: boolean;
335
342
  firstUserSeen: boolean;
336
343
  firstMessage: MessageSnapshot | null;
@@ -445,4 +452,4 @@ declare function scan(options?: ScanOptions, scanner?: ConversationScanner): Pro
445
452
  declare function search(query: string, options?: SearchOptions, scanner?: ConversationScanner): Promise<SearchResult[]>;
446
453
  declare function getConversation(id: string, options?: GetConversationOptions, scanner?: ConversationScanner): Promise<Conversation | null>;
447
454
 
448
- export { type AttachmentSidecar, CodexCliProvider, type ContentTier, type Conversation, type ConversationMessage, type ConversationMeta, type ConversationPage, ConversationScanner, type ConversationScannerOptions, DEFAULT_TIERS, type DeferredToolsDeltaAttachment, type DiscoveredConversationFile, type FileStatEntry, type GetConversationOptions, type GetConversationPageOptions, type GroupedConversations, type Include, type ConvReducerState as JsonlParseState, type MessageMetadata, type MessageSender, type MessageSnapshot, type PersistentConfig, type Profile, type ProviderName, type ScanOptions, type ScanResult, type ScannerChangeEvent, type ScannerProvider, type ScannerProviderName, type SearchHighlight, SearchIndexer, type SearchMatch, type SearchOptions, type SearchResult, type Sidecar, type SingleFilePage, type SortOrder, type TeamInfo, ThreadbaseProvider, type ToolResultBlock, type ToolUseBlock, type TreeConversation, type TurnDuration, VALID_SORT_ORDERS, type View, type WatchOptions, applyAccountFilter, applyIncludeFilter, applyPagination, applyProjectFilter, applySinceFilter, applySort, cleanSystemTags, initialConvState as createJsonlParseState, createLogger, detectDefaultProfile, getConversation, getLogger, getProjectsDir, loadProfiles, parseJsonlLine, readGitBranch, readSidecar, resetDefaultScanner, resolveConfigDir, resolveTier, saveProfiles, scan, search, setLogger, sidecarPath };
455
+ export { type AttachmentSidecar, CodexCliProvider, type ContentTier, type Conversation, type ConversationMessage, type ConversationMeta, type ConversationPage, ConversationScanner, type ConversationScannerOptions, DEFAULT_TIERS, type DeferredToolsDeltaAttachment, type DiscoveredConversationFile, type FileStatEntry, type GetConversationOptions, type GetConversationPageOptions, type GroupedConversations, type Include, type ConvReducerState as JsonlParseState, type MessageMetadata, type MessageSender, type MessageSnapshot, type PersistentConfig, type Profile, type ProviderName, type ScanOptions, type ScanResult, type ScannerChangeEvent, type ScannerProvider, type ScannerProviderName, type SearchHighlight, SearchIndexer, type SearchMatch, type SearchOptions, type SearchResult, type Sidecar, type SingleFilePage, type SortOrder, type TeamInfo, ThreadbaseProvider, type ToolResultBlock, type ToolUseBlock, type TreeConversation, type TurnDuration, VALID_SORT_ORDERS, type View, type WatchOptions, applyAccountFilter, applyIncludeFilter, applyPagination, applyProjectFilter, applySinceFilter, applySort, cleanSystemTags, initialConvState as createJsonlParseState, createLogger, detectDefaultProfile, getConversation, getLogger, getProjectsDir, loadProfiles, parseCodexJsonlLine, parseJsonlLine, readGitBranch, readSidecar, resetDefaultScanner, resolveConfigDir, resolveTier, saveProfiles, scan, search, setLogger, sidecarPath };
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 isSubagent = filePath.includes("/subagents/");
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 (isSubagent) {
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,
@@ -991,6 +1004,26 @@ function extractCodexText(content) {
991
1004
  return "";
992
1005
  }).filter(Boolean).map(cleanSystemTags).join(" ");
993
1006
  }
1007
+ function parseCodexJsonlLine(line) {
1008
+ if (!line.trim()) return null;
1009
+ let entry;
1010
+ try {
1011
+ entry = JSON.parse(line);
1012
+ } catch {
1013
+ return null;
1014
+ }
1015
+ return codexEntryToMessage(entry);
1016
+ }
1017
+ function codexEntryToMessage(entry) {
1018
+ const payload = entry.payload;
1019
+ if (!payload || typeof payload !== "object") return null;
1020
+ if (entry.type !== "response_item" || payload.type !== "message") return null;
1021
+ const role = payload.role;
1022
+ if (role !== "user" && role !== "assistant") return null;
1023
+ const text = extractCodexText(payload.content);
1024
+ if (!text) return null;
1025
+ return { role, text, timestamp: asString(entry.timestamp) };
1026
+ }
994
1027
  function reduceCodexEntry(acc, entry, tier) {
995
1028
  const ts = asString(entry.timestamp);
996
1029
  if (ts && (!acc.latestTimestamp || ts > acc.latestTimestamp)) acc.latestTimestamp = ts;
@@ -1002,6 +1035,10 @@ function reduceCodexEntry(acc, entry, tier) {
1002
1035
  if (!acc.cwd) acc.cwd = asString(payload.cwd);
1003
1036
  const git = payload.git;
1004
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
+ }
1005
1042
  return;
1006
1043
  }
1007
1044
  if (acc.model === null && payload.model) acc.model = asString(payload.model) || null;
@@ -1061,8 +1098,10 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
1061
1098
  contentSnippet: acc.snippetParts.join(" "),
1062
1099
  gitBranch: acc.gitBranch,
1063
1100
  model: acc.model,
1064
- isSubagent: false,
1101
+ isSubagent: acc.isSubagent,
1102
+ // Codex exposes no path-shaped parent, and no per-child id of its own.
1065
1103
  parentSessionId: null,
1104
+ parentSessionUuid: acc.parentSessionUuid ?? void 0,
1066
1105
  isTeammate: false,
1067
1106
  teamName: null,
1068
1107
  toolNames: acc.toolNames,
@@ -1074,6 +1113,17 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
1074
1113
  function getShortProjectName3(fullPath) {
1075
1114
  return fullPath.split("/").filter(Boolean).slice(-3).join("/");
1076
1115
  }
1116
+ function isSubagentSource(source) {
1117
+ return typeof source === "object" && source !== null && "subagent" in source;
1118
+ }
1119
+ function parentThreadId(source) {
1120
+ if (!isSubagentSource(source)) return null;
1121
+ const subagent = source.subagent;
1122
+ if (typeof subagent !== "object" || subagent === null) return null;
1123
+ const spawn = subagent.thread_spawn;
1124
+ if (typeof spawn !== "object" || spawn === null) return null;
1125
+ return asString(spawn.parent_thread_id) || null;
1126
+ }
1077
1127
  async function parseCodexConversation(filePath, account) {
1078
1128
  const log = getLogger();
1079
1129
  const messages = [];
@@ -1101,14 +1151,11 @@ async function parseCodexConversation(filePath, account) {
1101
1151
  if (!cwd) cwd = asString(payload.cwd);
1102
1152
  continue;
1103
1153
  }
1104
- if (entry.type !== "response_item" || payload.type !== "message") continue;
1105
- const role = payload.role;
1106
- if (role !== "user" && role !== "assistant") continue;
1107
- const text = extractCodexText(payload.content);
1108
- if (!text) continue;
1109
- messages.push({ role, text, timestamp: ts });
1110
- textParts.push(text);
1111
- if (role === "user") lastUserText = text;
1154
+ const message = codexEntryToMessage(entry);
1155
+ if (!message) continue;
1156
+ messages.push(message);
1157
+ textParts.push(message.text);
1158
+ if (message.role === "user") lastUserText = message.text;
1112
1159
  }
1113
1160
  } catch (err) {
1114
1161
  log.warn({ filePath, err }, "parseCodexConversation: read failed");
@@ -1736,7 +1783,7 @@ import { mkdirSync } from "fs";
1736
1783
  import { dirname as dirname3 } from "path";
1737
1784
 
1738
1785
  // src/persistent/schema.ts
1739
- var SCHEMA_VERSION = 5;
1786
+ var SCHEMA_VERSION = 6;
1740
1787
  var SCHEMA_SQL = `
1741
1788
  CREATE TABLE IF NOT EXISTS conversation_files (
1742
1789
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -1811,7 +1858,11 @@ CREATE TABLE IF NOT EXISTS conversations (
1811
1858
 
1812
1859
  model TEXT,
1813
1860
  is_subagent INTEGER NOT NULL DEFAULT 0,
1861
+ -- The parent's JSONL PATH (matched against source_path), not an id.
1814
1862
  parent_session_id TEXT,
1863
+ -- The subagent's own id (Claude agentId), and the parent's session UUID.
1864
+ subagent_id TEXT,
1865
+ parent_session_uuid TEXT,
1815
1866
  is_teammate INTEGER NOT NULL DEFAULT 0,
1816
1867
  team_name TEXT,
1817
1868
  tool_names_json TEXT,
@@ -1944,6 +1995,29 @@ function runMigrations(db) {
1944
1995
  }
1945
1996
  }
1946
1997
  }
1998
+ if (current >= 1 && current < 6 && tableExists(db, "conversations")) {
1999
+ for (const [col, ddl] of [
2000
+ ["subagent_id", "ALTER TABLE conversations ADD COLUMN subagent_id TEXT"],
2001
+ ["parent_session_uuid", "ALTER TABLE conversations ADD COLUMN parent_session_uuid TEXT"]
2002
+ ]) {
2003
+ if (!hasColumn(db, "conversations", col)) db.exec(ddl);
2004
+ }
2005
+ if (tableExists(db, "conversation_files")) {
2006
+ const assignments = [];
2007
+ if (hasColumn(db, "conversation_files", "last_indexed_offset")) {
2008
+ assignments.push("last_indexed_offset = 0");
2009
+ }
2010
+ if (hasColumn(db, "conversation_files", "last_indexed_line")) {
2011
+ assignments.push("last_indexed_line = 0");
2012
+ }
2013
+ if (hasColumn(db, "conversation_files", "reducer_state")) {
2014
+ assignments.push("reducer_state = NULL");
2015
+ }
2016
+ if (assignments.length > 0) {
2017
+ db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
2018
+ }
2019
+ }
2020
+ }
1947
2021
  db.exec(SCHEMA_SQL);
1948
2022
  db.pragma(`user_version = ${SCHEMA_VERSION}`);
1949
2023
  }
@@ -2268,6 +2342,8 @@ function rowToMeta(row) {
2268
2342
  model: row.model,
2269
2343
  isSubagent: row.is_subagent === 1,
2270
2344
  parentSessionId: row.parent_session_id,
2345
+ subagentId: row.subagent_id ?? void 0,
2346
+ parentSessionUuid: row.parent_session_uuid ?? void 0,
2271
2347
  isTeammate: row.is_teammate === 1,
2272
2348
  teamName: row.team_name,
2273
2349
  toolNames: row.tool_names_json ? JSON.parse(row.tool_names_json) : [],
@@ -2291,7 +2367,8 @@ var ConversationsRepo = class {
2291
2367
  account, branch, preview, content_snippet, message_count, page_message_count,
2292
2368
  last_message_sender,
2293
2369
  timestamp, index_seq, first_sent_at, first_sent_text, last_sent_at, last_sent_text,
2294
- model, is_subagent, parent_session_id, is_teammate, team_name, tool_names_json,
2370
+ model, is_subagent, parent_session_id, subagent_id, parent_session_uuid,
2371
+ is_teammate, team_name, tool_names_json,
2295
2372
  last_prompt, status, updated_at
2296
2373
  ) VALUES (
2297
2374
  @file_id, @source_path, @provider, @kind, @external_session_id,
@@ -2301,7 +2378,8 @@ var ConversationsRepo = class {
2301
2378
  @timestamp,
2302
2379
  (SELECT COALESCE(MAX(index_seq), 0) + 1 FROM conversations),
2303
2380
  @first_sent_at, @first_sent_text, @last_sent_at, @last_sent_text,
2304
- @model, @is_subagent, @parent_session_id, @is_teammate, @team_name, @tool_names_json,
2381
+ @model, @is_subagent, @parent_session_id, @subagent_id, @parent_session_uuid,
2382
+ @is_teammate, @team_name, @tool_names_json,
2305
2383
  @last_prompt, 'active', CURRENT_TIMESTAMP
2306
2384
  )
2307
2385
  ON CONFLICT(file_id) DO UPDATE SET
@@ -2328,6 +2406,8 @@ var ConversationsRepo = class {
2328
2406
  model = excluded.model,
2329
2407
  is_subagent = excluded.is_subagent,
2330
2408
  parent_session_id = excluded.parent_session_id,
2409
+ subagent_id = excluded.subagent_id,
2410
+ parent_session_uuid = excluded.parent_session_uuid,
2331
2411
  is_teammate = excluded.is_teammate,
2332
2412
  team_name = excluded.team_name,
2333
2413
  tool_names_json = excluded.tool_names_json,
@@ -2363,6 +2443,8 @@ var ConversationsRepo = class {
2363
2443
  model: meta.model,
2364
2444
  is_subagent: meta.isSubagent ? 1 : 0,
2365
2445
  parent_session_id: meta.parentSessionId,
2446
+ subagent_id: meta.subagentId ?? null,
2447
+ parent_session_uuid: meta.parentSessionUuid ?? null,
2366
2448
  is_teammate: meta.isTeammate ? 1 : 0,
2367
2449
  team_name: meta.teamName,
2368
2450
  tool_names_json: JSON.stringify(meta.toolNames),
@@ -3911,6 +3993,7 @@ export {
3911
3993
  getLogger,
3912
3994
  getProjectsDir,
3913
3995
  loadProfiles,
3996
+ parseCodexJsonlLine,
3914
3997
  parseJsonlLine,
3915
3998
  readGitBranch,
3916
3999
  readSidecar,