@threadbase-sh/scanner 0.25.0 → 0.25.2

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.
Files changed (45) hide show
  1. package/dist/cli.js +10 -3
  2. package/dist/cli.js.map +1 -1
  3. package/dist/filters.d.ts +1 -1
  4. package/dist/index.cjs +9 -2
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.ts +26 -26
  7. package/dist/index.js +9 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/indexer.d.ts +1 -1
  10. package/dist/name-stores.d.ts +2 -2
  11. package/dist/parse-helpers.d.ts +1 -1
  12. package/dist/parse-helpers.d.ts.map +1 -1
  13. package/dist/parse.cjs +9 -2
  14. package/dist/parse.cjs.map +1 -1
  15. package/dist/parse.d.ts +4 -4
  16. package/dist/parse.js +9 -2
  17. package/dist/parse.js.map +1 -1
  18. package/dist/parser.d.ts +2 -2
  19. package/dist/persistent/claude-name-slots.d.ts +1 -1
  20. package/dist/persistent/conversation-reducer.d.ts +2 -2
  21. package/dist/persistent/conversation-stream.d.ts +2 -2
  22. package/dist/persistent/cursor.d.ts +1 -1
  23. package/dist/persistent/dir-watermark.d.ts +3 -3
  24. package/dist/persistent/index-engine.d.ts +9 -9
  25. package/dist/persistent/jsonl-tail-reader.d.ts +2 -2
  26. package/dist/persistent/metadata-reducer.d.ts +2 -2
  27. package/dist/persistent/paged-reader.d.ts +3 -3
  28. package/dist/persistent/repositories/checkpoints.repo.d.ts +1 -1
  29. package/dist/persistent/repositories/conversations.repo.d.ts +1 -1
  30. package/dist/persistent/repositories/fts.repo.d.ts +2 -2
  31. package/dist/persistent/sidecar.d.ts +1 -1
  32. package/dist/profiles.d.ts +1 -1
  33. package/dist/providers/codex-cli.d.ts +3 -3
  34. package/dist/providers/copilot.d.ts +3 -3
  35. package/dist/providers/cursor.d.ts +3 -3
  36. package/dist/providers/parse.d.ts +2 -2
  37. package/dist/providers/provider.d.ts +1 -1
  38. package/dist/providers/threadbase.d.ts +3 -3
  39. package/dist/scanner.d.ts +2 -2
  40. package/dist/search-matches.d.ts +1 -1
  41. package/dist/session-name.d.ts +1 -1
  42. package/dist/tiers.d.ts +1 -1
  43. package/dist/types.d.ts +1 -1
  44. package/dist/watcher/file-watcher.d.ts +1 -1
  45. package/package.json +2 -2
package/dist/indexer.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ConversationMeta, SearchResult } from "./types";
1
+ import type { ConversationMeta, SearchResult } from "./types.js";
2
2
  export declare class SearchIndexer {
3
3
  private index;
4
4
  private documents;
@@ -1,5 +1,5 @@
1
- import type { ScannerProviderName } from "./providers/provider";
2
- import { type NameSlots } from "./session-name";
1
+ import type { ScannerProviderName } from "./providers/provider.js";
2
+ import { type NameSlots } from "./session-name.js";
3
3
  export declare function readCodexNameSlots(codexHome: string, id: string): NameSlots;
4
4
  export declare function readCursorCliNameSlots(chatsDir: string, id: string): NameSlots;
5
5
  export declare function readCursorIdeNameSlots(stateDbPath: string, id: string): NameSlots;
@@ -1,4 +1,4 @@
1
- import type { TeamInfo, ToolResultBlock, ToolUseBlock } from "./types";
1
+ import type { TeamInfo, ToolResultBlock, ToolUseBlock } from "./types.js";
2
2
  export declare function asQueuedPromptUserEntry(entry: Record<string, unknown>): Record<string, unknown>;
3
3
  export declare function extractTextContent(content: unknown): string;
4
4
  export declare function extractToolUseNames(content: unknown): string[];
@@ -1 +1 @@
1
- {"version":3,"file":"parse-helpers.d.ts","sourceRoot":"","sources":["../src/parse-helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAMvE,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAa/F;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAgB3D;AA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AuB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAGjE;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAaxF;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAOxD;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CASxE"}
package/dist/parse.cjs CHANGED
@@ -68,16 +68,23 @@ function asQueuedPromptUserEntry(entry) {
68
68
  message: { role: "user", content: att.prompt }
69
69
  };
70
70
  }
71
+ var COMMAND_RE = /^\s*<command-name>([\s\S]*?)<\/command-name>/;
72
+ var COMMAND_ARGS_RE = /<command-args>([\s\S]*?)<\/command-args>/;
73
+ function cleanText(text) {
74
+ const name = text.match(COMMAND_RE)?.[1]?.trim();
75
+ const args = name ? text.match(COMMAND_ARGS_RE)?.[1]?.trim() : void 0;
76
+ return name && args ? `${name} ${args}` : cleanSystemTags(text);
77
+ }
71
78
  function extractTextContent(content) {
72
79
  if (!content) return "";
73
- if (typeof content === "string") return cleanSystemTags(content);
80
+ if (typeof content === "string") return cleanText(content);
74
81
  if (Array.isArray(content)) {
75
82
  return content.map((item) => {
76
83
  if (typeof item === "string") return item;
77
84
  if (item?.type === "text" && item?.text) return item.text;
78
85
  if (item?.type === "tool_result" && typeof item?.content === "string") return item.content;
79
86
  return "";
80
- }).filter(Boolean).map(cleanSystemTags).join(" ");
87
+ }).filter(Boolean).map(cleanText).join(" ");
81
88
  }
82
89
  return "";
83
90
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/parse.ts","../src/tags.ts","../src/parse-helpers.ts","../src/session-name.ts","../src/persistent/claude-name-slots.ts","../src/persistent/conversation-reducer.ts"],"sourcesContent":["export type { ConvReducerState as JsonlParseState } from \"./persistent/conversation-reducer\";\nexport {\n initialConvState as createJsonlParseState,\n parseJsonlLine,\n} from \"./persistent/conversation-reducer\";\nexport { cleanSystemTags } from \"./tags\";\nexport type * from \"./types\";\n","const SYSTEM_TAGS = [\n \"system-reminder\",\n \"command-name\",\n \"command-message\",\n \"command-args\",\n \"ide_selection\",\n \"ide_opened_file\",\n \"local-command-stdout\",\n \"local-command-caveat\",\n \"retrieval_status\",\n \"task_id\",\n \"task_type\",\n \"task-id\",\n \"task-notification\",\n \"fast_mode_info\",\n \"persisted-output\",\n \"tool_use_error\",\n \"user-prompt-submit-hook\",\n \"thinking\",\n \"ask_user\",\n \"teammate-message\",\n];\n\nconst SYSTEM_TAG_RE = new RegExp(`<(${SYSTEM_TAGS.join(\"|\")})[^>]*>[\\\\s\\\\S]*?<\\\\/\\\\1>`, \"g\");\n\n// The CLI wraps an oversized paste in <pasted_content id=\"XXXX\"> /\n// </pasted_content id=\"XXXX\"> (the closing tag repeats the id, so it isn't a\n// SYSTEM_TAGS-style `<\\/\\1>` pair) or a plain </pasted_content>. Unlike the\n// system tags above, this wraps the user's real prompt, so only the tag lines\n// are dropped and the inner text is kept.\nconst PASTED_CONTENT_RE =\n /<pasted_content id=\"[0-9a-f]{4}\">([\\s\\S]*?)<\\/pasted_content(?: id=\"[0-9a-f]{4}\")?>/g;\n\nexport function cleanSystemTags(text: string): string {\n return text\n .replace(SYSTEM_TAG_RE, \"\")\n .replace(PASTED_CONTENT_RE, \"$1\")\n .replace(/[^\\S\\n]+/g, \" \")\n .replace(/\\n{3,}/g, \"\\n\\n\")\n .trim();\n}\n","import { cleanSystemTags } from \"./tags\";\nimport type { TeamInfo, ToolResultBlock, ToolUseBlock } from \"./types\";\n\n// A prompt the user sends while Claude is mid-turn is written only as a\n// queued_command attachment, never as a `user` row, so history would drop it.\n// Returns the `user` entry it stands for; every other entry, including the\n// task-notification and peer queued_commands, comes back unchanged.\nexport function asQueuedPromptUserEntry(entry: Record<string, unknown>): Record<string, unknown> {\n if (entry.type !== \"attachment\") return entry;\n const att = entry.attachment as\n | { type?: string; commandMode?: string; origin?: { kind?: string }; prompt?: unknown }\n | undefined;\n if (att?.type !== \"queued_command\" || att.commandMode !== \"prompt\") return entry;\n if (att.origin?.kind !== \"human\") return entry;\n return {\n ...entry,\n type: \"user\",\n attachment: undefined,\n message: { role: \"user\", content: att.prompt },\n };\n}\n\nexport function extractTextContent(content: unknown): string {\n if (!content) return \"\";\n if (typeof content === \"string\") return cleanSystemTags(content);\n if (Array.isArray(content)) {\n return content\n .map((item) => {\n if (typeof item === \"string\") return item;\n if (item?.type === \"text\" && item?.text) return item.text;\n if (item?.type === \"tool_result\" && typeof item?.content === \"string\") return item.content;\n return \"\";\n })\n .filter(Boolean)\n .map(cleanSystemTags)\n .join(\" \");\n }\n return \"\";\n}\n\nexport function extractToolUseNames(content: unknown): string[] {\n if (!Array.isArray(content)) return [];\n return content\n .filter((item) => item?.type === \"tool_use\" && item?.name)\n .map((item) => item.name as string);\n}\n\nexport function extractToolUseBlocks(content: unknown): ToolUseBlock[] {\n if (!Array.isArray(content)) return [];\n return content\n .filter((item) => item?.type === \"tool_use\" && item?.name && item?.id)\n .map((item) => ({\n id: item.id as string,\n name: item.name as string,\n input: (item.input as Record<string, unknown>) || {},\n }));\n}\n\nconst TOOL_NAME_TO_TYPE: Record<string, ToolResultBlock[\"type\"]> = {\n Edit: \"edit\",\n Write: \"write\",\n Read: \"read\",\n Bash: \"bash\",\n Grep: \"grep\",\n Glob: \"glob\",\n Agent: \"taskAgent\",\n TaskCreate: \"taskCreate\",\n TaskUpdate: \"taskUpdate\",\n};\n\nexport function extractToolResultBlocks(\n content: unknown,\n pendingToolUses: Map<string, ToolUseBlock>,\n): ToolResultBlock[] {\n if (!Array.isArray(content)) return [];\n return content\n .filter((item) => item?.type === \"tool_result\" && item?.tool_use_id)\n .map((item) => {\n const toolName = pendingToolUses.get(item.tool_use_id as string)?.name ?? \"\";\n return {\n toolUseId: item.tool_use_id as string,\n type: TOOL_NAME_TO_TYPE[toolName] ?? \"generic\",\n content:\n typeof item.content === \"string\"\n ? { text: item.content as string }\n : ((item.content as Record<string, unknown>) ?? {}),\n isError: typeof item.is_error === \"boolean\" ? item.is_error : undefined,\n };\n });\n}\n\nexport function isOnlyToolResultContent(content: unknown): boolean {\n if (!Array.isArray(content)) return false;\n return content.length > 0 && content.every((item) => item?.type === \"tool_result\");\n}\n\nexport function extractThinking(content: unknown): { content: string; signature: string } {\n if (!Array.isArray(content)) return { content: \"\", signature: \"\" };\n const blocks = content.filter((item) => item?.type === \"thinking\");\n return {\n content: blocks\n .map((b) => b.thinking as string)\n .filter(Boolean)\n .join(\"\\n\\n\"),\n signature: blocks\n .map((b) => b.signature as string)\n .filter(Boolean)\n .join(\"\"),\n };\n}\n\nexport function hasImageBlocks(content: unknown): boolean {\n if (!Array.isArray(content)) return false;\n return content.some(\n (item) =>\n item?.type === \"image\" &&\n (item?.source?.type === \"base64\" || item?.file?.base64 !== undefined),\n );\n}\n\nexport function parseTeammateMessageTag(content: string): TeamInfo | null {\n const match = content.match(/<teammate-message\\s+([^>]*)>/);\n if (!match) return null;\n const attrs = match[1];\n const id = attrs.match(/teammate_id=\"([^\"]*)\"/)?.[1];\n if (!id) return null;\n const summary = attrs.match(/summary=\"([^\"]*)\"/)?.[1];\n const color = attrs.match(/color=\"([^\"]*)\"/)?.[1];\n return { teammateId: id, summary, color };\n}\n","import type { ScannerProviderName } from \"./providers/provider\";\nimport { cleanSystemTags } from \"./tags\";\n\nexport type NameSlot = \"userTitle\" | \"toolTitle\" | \"lastPrompt\" | \"firstUserMessage\" | \"slug\";\n\n// Highest first: the first non-empty slot is the session's name.\nexport const NAME_PRECEDENCE: readonly NameSlot[] = [\n \"userTitle\",\n \"toolTitle\",\n \"lastPrompt\",\n \"firstUserMessage\",\n \"slug\",\n];\n\nexport interface NameSlots {\n userTitle?: string;\n toolTitle?: string;\n lastPrompt?: string;\n firstUserMessage?: string; // set once, never replaced\n slug?: string;\n}\n\nexport interface ResolvedSessionName {\n name: string | null; // full, untruncated\n source: NameSlot | null;\n}\n\n// Text the host injects as a \"user\" turn. Matched against the trimmed text.\nconst CLAUDE_SYSTEM_PREFIXES = [\n \"<command-name>\",\n \"<command-message>\",\n \"<command-args>\",\n \"<local-command-stdout>\",\n \"<local-command-stderr>\",\n \"<local-command-caveat>\",\n \"<bash-input>\",\n \"<bash-stdout>\",\n \"<bash-stderr>\",\n \"<system-reminder>\",\n \"<task-notification>\",\n \"<teammate-message\",\n \"Another Claude session sent a message:\",\n \"[Request interrupted by user\",\n];\n\nconst CODEX_SYSTEM_PREFIXES = [\n \"<environment_context>\",\n \"# AGENTS.md instructions\",\n \"<user_instructions>\",\n \"<INSTRUCTIONS>\",\n \"<external_codex_apps_open\",\n \"<user_shell_command>\",\n \"<turn_aborted>\",\n];\n\n/**\n * Boilerplate Codex injects as a `user`-role turn. Codex-generic only — prompts a\n * host passes as argv (Codex has no --system-prompt flag) also land as role:user,\n * but recognising those is the host's business, not the scanner's.\n */\nexport function isCodexInjectedContext(text: string): boolean {\n // AGENTS.md / instruction dumps prepended as the opening turn.\n if (text.startsWith(\"# AGENTS.md\") || text.includes(\"<INSTRUCTIONS>\")) return true;\n // Permissions / sandbox preamble, sometimes a giant user-role blob.\n return (\n text.startsWith(\"<permissions instructions>\") || text.includes(\"Filesystem sandboxing defines\")\n );\n}\n\nconst CODEX_IMAGE_TAG_RE = /<\\/?image\\b[^>]*>/g;\n\n// The text to store for a candidate, or null when it cannot name a session.\nfunction normalizeCandidate(text: string, provider: ScannerProviderName): string | null {\n let t = text.trim();\n if (provider === \"codex-cli\") t = t.replace(CODEX_IMAGE_TAG_RE, \"\").trim();\n const prefixes =\n provider === \"claude-code\"\n ? CLAUDE_SYSTEM_PREFIXES\n : provider === \"codex-cli\"\n ? CODEX_SYSTEM_PREFIXES\n : [];\n if (prefixes.some((p) => t.startsWith(p))) return null;\n if (provider === \"codex-cli\" && isCodexInjectedContext(t)) return null;\n return cleanSystemTags(t) || null;\n}\n\nexport function isValidNameCandidate(text: string, provider: ScannerProviderName): boolean {\n return normalizeCandidate(text, provider) !== null;\n}\n\n// Pure: same slots in, same name out.\nexport function resolveSessionName(slots: NameSlots): ResolvedSessionName {\n for (const slot of NAME_PRECEDENCE) {\n const value = slots[slot];\n if (value?.trim()) return { name: value, source: slot };\n }\n return { name: null, source: null };\n}\n\n// The single write path for every slot: the last valid occurrence wins, an\n// invalid candidate never overwrites a valid value, and firstUserMessage is set\n// once. Returns a new object, or the input unchanged when nothing applies.\nexport function applyNameCandidate(\n slots: NameSlots,\n slot: NameSlot,\n raw: string | undefined,\n provider: ScannerProviderName,\n): NameSlots {\n if (typeof raw !== \"string\") return slots;\n if (slot === \"firstUserMessage\" && slots.firstUserMessage !== undefined) return slots;\n const text = normalizeCandidate(raw, provider);\n return text === null ? slots : { ...slots, [slot]: text };\n}\n","import { applyNameCandidate, type NameSlots } from \"../session-name\";\n\n// Prompt text of a user entry, or \"\" when it can't name a session: injected\n// meta/compaction rows, and entries with no `text` block (tool results only).\n// Raw on purpose: the prefix checks in isValidNameCandidate run before tags are\n// cleaned, so a `<command-name>` row is rejected rather than emptied.\nfunction userPromptText(entry: Record<string, unknown>): string {\n if (entry.isMeta || entry.isCompactSummary === true) return \"\";\n const content = (entry.message as Record<string, unknown> | undefined)?.content;\n if (typeof content === \"string\") return content;\n if (!Array.isArray(content)) return \"\";\n return content\n .map((b) => (typeof b === \"string\" ? b : b?.type === \"text\" ? b.text : \"\"))\n .filter((t): t is string => typeof t === \"string\" && t !== \"\")\n .join(\" \");\n}\n\n// Maps one Claude JSONL entry to its name-slot candidates. Shared by the\n// metadata and conversation reducers so neither keeps its own naming logic.\nexport function applyClaudeNameEntry(slots: NameSlots, entry: Record<string, unknown>): NameSlots {\n const apply = (slot: Parameters<typeof applyNameCandidate>[1], raw: unknown) =>\n applyNameCandidate(slots, slot, typeof raw === \"string\" ? raw : undefined, \"claude-code\");\n\n // slug rides on every entry of a session, so skip the re-normalising when it\n // is the value already held — this runs once per line of a 100k-line file.\n if (entry.slug !== slots.slug) slots = apply(\"slug\", entry.slug);\n switch (entry.type) {\n case \"custom-title\":\n return apply(\"userTitle\", entry.customTitle);\n case \"ai-title\":\n return apply(\"toolTitle\", entry.aiTitle);\n case \"last-prompt\":\n return apply(\"lastPrompt\", entry.lastPrompt);\n case \"user\":\n return slots.firstUserMessage === undefined\n ? apply(\"firstUserMessage\", userPromptText(entry))\n : slots;\n default:\n return slots;\n }\n}\n","import {\n asQueuedPromptUserEntry,\n extractTextContent,\n extractThinking,\n extractToolResultBlocks,\n extractToolUseBlocks,\n extractToolUseNames,\n hasImageBlocks,\n isOnlyToolResultContent,\n parseTeammateMessageTag,\n} from \"../parse-helpers\";\nimport type { NameSlots } from \"../session-name\";\nimport type {\n AttachmentSidecar,\n CompactionInfo,\n ConversationMessage,\n MessageMetadata,\n MessageSender,\n TeamInfo,\n ToolUseBlock,\n} from \"../types\";\nimport { applyClaudeNameEntry } from \"./claude-name-slots\";\n\n// Resumable, serializable state for the conversation line→message reduction.\n// Mirrors parseConversation()'s loop so a full reduce equals a streamed parse,\n// and so a bounded page read can resume an *equivalent* parse from a checkpoint\n// by restoring the cross-line state (pending tool_use blocks + team info).\nexport interface ConvReducerState {\n cwd: string;\n sessionId: string;\n nameSlots: NameSlots;\n latestTimestamp: string;\n lastPrompt: string;\n // id -> tool_use block, so a later tool_result line resolves its tool type.\n pendingToolUses: Record<string, ToolUseBlock>;\n // teamName -> info, collected as lines are read and applied to messages.\n teamInfo: Record<string, TeamInfo>;\n // The last compact_boundary row seen, held until its summary row (a few\n // lines later) picks it up. Absent in checkpoints written before this field.\n pendingCompaction?: CompactionInfo;\n}\n\nexport function initialConvState(): ConvReducerState {\n return {\n cwd: \"\",\n sessionId: \"\",\n nameSlots: {},\n latestTimestamp: \"\",\n lastPrompt: \"\",\n pendingToolUses: {},\n teamInfo: {},\n };\n}\n\n// Fold one JSONL entry. Returns the produced ConversationMessage (its message\n// index is the count of messages emitted so far), or null if the line produced\n// no message. Mutates `state` (header fields + cross-line maps).\nexport function reduceConvLine(\n state: ConvReducerState,\n rawEntry: Record<string, unknown>,\n): ConversationMessage | null {\n const entry = asQueuedPromptUserEntry(rawEntry);\n if (entry.cwd && !state.cwd) state.cwd = entry.cwd as string;\n if (entry.sessionId && !state.sessionId) state.sessionId = entry.sessionId as string;\n state.nameSlots = applyClaudeNameEntry(state.nameSlots, entry);\n if (entry.timestamp) {\n const ts = entry.timestamp as string;\n if (!state.latestTimestamp || ts > state.latestTimestamp) state.latestTimestamp = ts;\n }\n\n const type = entry.type as string;\n\n if (type === \"last-prompt\") {\n if (entry.lastPrompt && !state.lastPrompt) state.lastPrompt = entry.lastPrompt as string;\n return null;\n }\n if (type === \"system\" && entry.subtype === \"compact_boundary\") {\n const meta = (entry.compactMetadata ?? {}) as Record<string, unknown>;\n state.pendingCompaction = {\n trigger: typeof meta.trigger === \"string\" ? meta.trigger : undefined,\n preTokens: typeof meta.preTokens === \"number\" ? meta.preTokens : undefined,\n postTokens: typeof meta.postTokens === \"number\" ? meta.postTokens : undefined,\n };\n return null;\n }\n // system (incl. turn_duration), file-history-snapshot, etc. produce no message.\n if (type !== \"user\" && type !== \"assistant\") return null;\n if (entry.isMeta) return null;\n\n const isCompactSummary = type === \"user\" && entry.isCompactSummary === true;\n const compaction = isCompactSummary ? state.pendingCompaction : undefined;\n if (isCompactSummary) delete state.pendingCompaction;\n\n const msg = entry.message as Record<string, unknown> | undefined;\n\n const toolUseBlocks = extractToolUseBlocks(msg?.content);\n for (const block of toolUseBlocks) state.pendingToolUses[block.id] = block;\n\n const hasToolUseResult = type === \"user\" && entry.toolUseResult != null;\n const isToolResultOnly = hasToolUseResult && isOnlyToolResultContent(msg?.content);\n const content = extractTextContent(msg?.content);\n const thinking = type === \"assistant\" ? extractThinking(msg?.content) : null;\n const hasThinking = !!(thinking?.content || thinking?.signature);\n\n if (!(content || isToolResultOnly || toolUseBlocks.length > 0 || hasThinking)) return null;\n\n const metadata: MessageMetadata = {};\n if (msg?.model) metadata.model = msg.model as string;\n if (msg?.stop_reason !== undefined) metadata.stopReason = msg.stop_reason as string | null;\n if (entry.gitBranch) metadata.gitBranch = entry.gitBranch as string;\n if (entry.version) metadata.version = entry.version as string;\n\n const usage = msg?.usage as Record<string, number> | undefined;\n if (usage) {\n if (usage.input_tokens) metadata.inputTokens = usage.input_tokens;\n if (usage.output_tokens) metadata.outputTokens = usage.output_tokens;\n if (usage.cache_read_input_tokens) metadata.cacheReadTokens = usage.cache_read_input_tokens;\n if (usage.cache_creation_input_tokens)\n metadata.cacheCreationTokens = usage.cache_creation_input_tokens;\n }\n\n const toolUseNames = extractToolUseNames(msg?.content);\n if (toolUseNames.length > 0) metadata.toolUses = toolUseNames;\n if (toolUseBlocks.length > 0) metadata.toolUseBlocks = toolUseBlocks;\n\n if (isToolResultOnly) {\n const pending = new Map(Object.entries(state.pendingToolUses));\n const toolResultBlocks = extractToolResultBlocks(msg?.content, pending);\n if (toolResultBlocks.length > 0) {\n metadata.toolResults = toolResultBlocks;\n // A result consumes its tool_use: prune it so the cross-line map stays\n // bounded by IN-FLIGHT tool calls instead of growing with the file.\n // Unpruned, every checkpoint snapshot/serialization of this state costs\n // O(file) — the structuredClone stall on large live conversations.\n for (const block of toolResultBlocks) delete state.pendingToolUses[block.toolUseId];\n }\n }\n\n if (entry.teamName) {\n metadata.teamName = entry.teamName as string;\n if (!state.teamInfo[metadata.teamName] && content) {\n const info = parseTeammateMessageTag(content);\n if (info) state.teamInfo[metadata.teamName] = info;\n }\n }\n\n const thinkingContent = thinking?.content || undefined;\n const thinkingSignature = thinking?.signature || undefined;\n const hasMetadata = Object.keys(metadata).length > 0;\n\n return {\n role: type as MessageSender,\n text: content || \"\",\n timestamp: (entry.timestamp as string) || \"\",\n uuid: (entry.uuid as string) || undefined,\n metadata: hasMetadata ? metadata : undefined,\n isToolResult: isToolResultOnly || undefined,\n isThinking: thinkingContent || thinkingSignature ? true : undefined,\n thinkingContent,\n thinkingSignature,\n parentUuid: entry.parentUuid !== undefined ? (entry.parentUuid as string | null) : undefined,\n requestId: type === \"assistant\" ? (entry.requestId as string | undefined) : undefined,\n promptId: type === \"user\" ? (entry.promptId as string | undefined) : undefined,\n isSidechain: typeof entry.isSidechain === \"boolean\" ? entry.isSidechain : undefined,\n permissionMode: type === \"user\" ? (entry.permissionMode as string | undefined) : undefined,\n hasImages: hasImageBlocks(msg?.content) || undefined,\n attachment:\n entry.attachment !== undefined ? (entry.attachment as AttachmentSidecar) : undefined,\n isCompactSummary: isCompactSummary || undefined,\n compaction,\n };\n}\n\n// Parse/classify one raw JSONL line — the exact line→message mapping the\n// scanner uses internally, exported for downstream indexers (e.g. a watcher\n// tailing appended lines) so their semantics cannot drift from the scanner's.\n// Returns the produced ConversationMessage, or null when the line yields none\n// (system/summary/sidecar records, blank or malformed lines). Whether a line\n// produces a message — and its core fields (role, uuid, timestamp) — is\n// state-independent, so calls without `state` classify correctly on their own;\n// pass one shared `state` across successive lines of a file to also resolve\n// cross-line references (tool_result → tool_use types, team info) identically\n// to a full parse.\nexport function parseJsonlLine(\n line: string,\n state: ConvReducerState = initialConvState(),\n): ConversationMessage | null {\n const text = line.trimEnd();\n if (text.trim().length === 0) return null;\n let entry: Record<string, unknown>;\n try {\n entry = JSON.parse(text);\n } catch {\n return null;\n }\n return reduceConvLine(state, entry);\n}\n\n// Back-apply collected team info to a set of messages (the post-pass\n// parseConversation does). Safe to call on a window: teamInfo for a given name\n// is stable once first seen, so a window restored from a checkpoint that\n// carries earlier teamInfo gets the same result.\nexport function applyTeamInfo(messages: ConversationMessage[], state: ConvReducerState): void {\n if (Object.keys(state.teamInfo).length === 0) return;\n for (const m of messages) {\n const name = m.metadata?.teamName;\n if (name && state.teamInfo[name] && m.metadata) m.metadata.teamInfo = state.teamInfo[name];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAM,cAAc;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAA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MAAM,cAAc;AAAA,IAC1E,gBAAgB,SAAS,SAAU,MAAM,iBAAwC;AAAA,IACjF,WAAW,eAAe,KAAK,OAAO,KAAK;AAAA,IAC3C,YACE,MAAM,eAAe,SAAa,MAAM,aAAmC;AAAA,IAC7E,kBAAkB,oBAAoB;AAAA,IACtC;AAAA,EACF;AACF;AAYO,SAAS,eACd,MACA,QAA0B,iBAAiB,GACf;AAC5B,QAAM,OAAO,KAAK,QAAQ;AAC1B,MAAI,KAAK,KAAK,EAAE,WAAW,EAAG,QAAO;AACrC,MAAI;AACJ,MAAI;AACF,YAAQ,KAAK,MAAM,IAAI;AAAA,EACzB,QAAQ;AACN,WAAO;AAAA,EACT;AACA,SAAO,eAAe,OAAO,KAAK;AACpC;","names":[]}
1
+ {"version":3,"sources":["../src/parse.ts","../src/tags.ts","../src/parse-helpers.ts","../src/session-name.ts","../src/persistent/claude-name-slots.ts","../src/persistent/conversation-reducer.ts"],"sourcesContent":["export type { ConvReducerState as JsonlParseState } from \"./persistent/conversation-reducer\";\nexport {\n initialConvState as createJsonlParseState,\n parseJsonlLine,\n} from \"./persistent/conversation-reducer\";\nexport { cleanSystemTags } from \"./tags\";\nexport type * from \"./types\";\n","const SYSTEM_TAGS = [\n \"system-reminder\",\n \"command-name\",\n \"command-message\",\n \"command-args\",\n \"ide_selection\",\n \"ide_opened_file\",\n \"local-command-stdout\",\n \"local-command-caveat\",\n \"retrieval_status\",\n \"task_id\",\n \"task_type\",\n \"task-id\",\n \"task-notification\",\n \"fast_mode_info\",\n \"persisted-output\",\n \"tool_use_error\",\n \"user-prompt-submit-hook\",\n \"thinking\",\n \"ask_user\",\n \"teammate-message\",\n];\n\nconst SYSTEM_TAG_RE = new RegExp(`<(${SYSTEM_TAGS.join(\"|\")})[^>]*>[\\\\s\\\\S]*?<\\\\/\\\\1>`, \"g\");\n\n// The CLI wraps an oversized paste in <pasted_content id=\"XXXX\"> /\n// </pasted_content id=\"XXXX\"> (the closing tag repeats the id, so it isn't a\n// SYSTEM_TAGS-style `<\\/\\1>` pair) or a plain </pasted_content>. Unlike the\n// system tags above, this wraps the user's real prompt, so only the tag lines\n// are dropped and the inner text is kept.\nconst PASTED_CONTENT_RE =\n /<pasted_content id=\"[0-9a-f]{4}\">([\\s\\S]*?)<\\/pasted_content(?: id=\"[0-9a-f]{4}\")?>/g;\n\nexport function cleanSystemTags(text: string): string {\n return text\n .replace(SYSTEM_TAG_RE, \"\")\n .replace(PASTED_CONTENT_RE, \"$1\")\n .replace(/[^\\S\\n]+/g, \" \")\n .replace(/\\n{3,}/g, \"\\n\\n\")\n .trim();\n}\n","import { cleanSystemTags } from \"./tags\";\nimport type { TeamInfo, ToolResultBlock, ToolUseBlock } from \"./types\";\n\n// A prompt the user sends while Claude is mid-turn is written only as a\n// queued_command attachment, never as a `user` row, so history would drop it.\n// Returns the `user` entry it stands for; every other entry, including the\n// task-notification and peer queued_commands, comes back unchanged.\nexport function asQueuedPromptUserEntry(entry: Record<string, unknown>): Record<string, unknown> {\n if (entry.type !== \"attachment\") return entry;\n const att = entry.attachment as\n | { type?: string; commandMode?: string; origin?: { kind?: string }; prompt?: unknown }\n | undefined;\n if (att?.type !== \"queued_command\" || att.commandMode !== \"prompt\") return entry;\n if (att.origin?.kind !== \"human\") return entry;\n return {\n ...entry,\n type: \"user\",\n attachment: undefined,\n message: { role: \"user\", content: att.prompt },\n };\n}\n\n// A typed slash command is stored as <command-name>/x</command-name> plus\n// <command-args>…</command-args>, and the args are where the user's real prompt\n// lives (`/plan <prompt>`). cleanSystemTags strips both tags, which emptied the\n// line and dropped the session's first prompt from history. Rebuild what was typed.\nconst COMMAND_RE = /^\\s*<command-name>([\\s\\S]*?)<\\/command-name>/;\nconst COMMAND_ARGS_RE = /<command-args>([\\s\\S]*?)<\\/command-args>/;\n\nfunction cleanText(text: string): string {\n const name = text.match(COMMAND_RE)?.[1]?.trim();\n const args = name ? text.match(COMMAND_ARGS_RE)?.[1]?.trim() : undefined;\n // A bare command (/compact, /clear) carries no prompt and stays hidden.\n return name && args ? `${name} ${args}` : cleanSystemTags(text);\n}\n\nexport function extractTextContent(content: unknown): string {\n if (!content) return \"\";\n if (typeof content === \"string\") return cleanText(content);\n if (Array.isArray(content)) {\n return content\n .map((item) => {\n if (typeof item === \"string\") return item;\n if (item?.type === \"text\" && item?.text) return item.text;\n if (item?.type === \"tool_result\" && typeof item?.content === \"string\") return item.content;\n return \"\";\n })\n .filter(Boolean)\n .map(cleanText)\n .join(\" \");\n }\n return \"\";\n}\n\nexport function extractToolUseNames(content: unknown): string[] {\n if (!Array.isArray(content)) return [];\n return content\n .filter((item) => item?.type === \"tool_use\" && item?.name)\n .map((item) => item.name as string);\n}\n\nexport function extractToolUseBlocks(content: unknown): ToolUseBlock[] {\n if (!Array.isArray(content)) return [];\n return content\n .filter((item) => item?.type === \"tool_use\" && item?.name && item?.id)\n .map((item) => ({\n id: item.id as string,\n name: item.name as string,\n input: (item.input as Record<string, unknown>) || {},\n }));\n}\n\nconst TOOL_NAME_TO_TYPE: Record<string, ToolResultBlock[\"type\"]> = {\n Edit: \"edit\",\n Write: \"write\",\n Read: \"read\",\n Bash: \"bash\",\n Grep: \"grep\",\n Glob: \"glob\",\n Agent: \"taskAgent\",\n TaskCreate: \"taskCreate\",\n TaskUpdate: \"taskUpdate\",\n};\n\nexport function extractToolResultBlocks(\n content: unknown,\n pendingToolUses: Map<string, ToolUseBlock>,\n): ToolResultBlock[] {\n if (!Array.isArray(content)) return [];\n return content\n .filter((item) => item?.type === \"tool_result\" && item?.tool_use_id)\n .map((item) => {\n const toolName = pendingToolUses.get(item.tool_use_id as string)?.name ?? \"\";\n return {\n toolUseId: item.tool_use_id as string,\n type: TOOL_NAME_TO_TYPE[toolName] ?? \"generic\",\n content:\n typeof item.content === \"string\"\n ? { text: item.content as string }\n : ((item.content as Record<string, unknown>) ?? {}),\n isError: typeof item.is_error === \"boolean\" ? item.is_error : undefined,\n };\n });\n}\n\nexport function isOnlyToolResultContent(content: unknown): boolean {\n if (!Array.isArray(content)) return false;\n return content.length > 0 && content.every((item) => item?.type === \"tool_result\");\n}\n\nexport function extractThinking(content: unknown): { content: string; signature: string } {\n if (!Array.isArray(content)) return { content: \"\", signature: \"\" };\n const blocks = content.filter((item) => item?.type === \"thinking\");\n return {\n content: blocks\n .map((b) => b.thinking as string)\n .filter(Boolean)\n .join(\"\\n\\n\"),\n signature: blocks\n .map((b) => b.signature as string)\n .filter(Boolean)\n .join(\"\"),\n };\n}\n\nexport function hasImageBlocks(content: unknown): boolean {\n if (!Array.isArray(content)) return false;\n return content.some(\n (item) =>\n item?.type === \"image\" &&\n (item?.source?.type === \"base64\" || item?.file?.base64 !== undefined),\n );\n}\n\nexport function parseTeammateMessageTag(content: string): TeamInfo | null {\n const match = content.match(/<teammate-message\\s+([^>]*)>/);\n if (!match) return null;\n const attrs = match[1];\n const id = attrs.match(/teammate_id=\"([^\"]*)\"/)?.[1];\n if (!id) return null;\n const summary = attrs.match(/summary=\"([^\"]*)\"/)?.[1];\n const color = attrs.match(/color=\"([^\"]*)\"/)?.[1];\n return { teammateId: id, summary, color };\n}\n","import type { ScannerProviderName } from \"./providers/provider\";\nimport { cleanSystemTags } from \"./tags\";\n\nexport type NameSlot = \"userTitle\" | \"toolTitle\" | \"lastPrompt\" | \"firstUserMessage\" | \"slug\";\n\n// Highest first: the first non-empty slot is the session's name.\nexport const NAME_PRECEDENCE: readonly NameSlot[] = [\n \"userTitle\",\n \"toolTitle\",\n \"lastPrompt\",\n \"firstUserMessage\",\n \"slug\",\n];\n\nexport interface NameSlots {\n userTitle?: string;\n toolTitle?: string;\n lastPrompt?: string;\n firstUserMessage?: string; // set once, never replaced\n slug?: string;\n}\n\nexport interface ResolvedSessionName {\n name: string | null; // full, untruncated\n source: NameSlot | null;\n}\n\n// Text the host injects as a \"user\" turn. Matched against the trimmed text.\nconst CLAUDE_SYSTEM_PREFIXES = [\n \"<command-name>\",\n \"<command-message>\",\n \"<command-args>\",\n \"<local-command-stdout>\",\n \"<local-command-stderr>\",\n \"<local-command-caveat>\",\n \"<bash-input>\",\n \"<bash-stdout>\",\n \"<bash-stderr>\",\n \"<system-reminder>\",\n \"<task-notification>\",\n \"<teammate-message\",\n \"Another Claude session sent a message:\",\n \"[Request interrupted by user\",\n];\n\nconst CODEX_SYSTEM_PREFIXES = [\n \"<environment_context>\",\n \"# AGENTS.md instructions\",\n \"<user_instructions>\",\n \"<INSTRUCTIONS>\",\n \"<external_codex_apps_open\",\n \"<user_shell_command>\",\n \"<turn_aborted>\",\n];\n\n/**\n * Boilerplate Codex injects as a `user`-role turn. Codex-generic only — prompts a\n * host passes as argv (Codex has no --system-prompt flag) also land as role:user,\n * but recognising those is the host's business, not the scanner's.\n */\nexport function isCodexInjectedContext(text: string): boolean {\n // AGENTS.md / instruction dumps prepended as the opening turn.\n if (text.startsWith(\"# AGENTS.md\") || text.includes(\"<INSTRUCTIONS>\")) return true;\n // Permissions / sandbox preamble, sometimes a giant user-role blob.\n return (\n text.startsWith(\"<permissions instructions>\") || text.includes(\"Filesystem sandboxing defines\")\n );\n}\n\nconst CODEX_IMAGE_TAG_RE = /<\\/?image\\b[^>]*>/g;\n\n// The text to store for a candidate, or null when it cannot name a session.\nfunction normalizeCandidate(text: string, provider: ScannerProviderName): string | null {\n let t = text.trim();\n if (provider === \"codex-cli\") t = t.replace(CODEX_IMAGE_TAG_RE, \"\").trim();\n const prefixes =\n provider === \"claude-code\"\n ? CLAUDE_SYSTEM_PREFIXES\n : provider === \"codex-cli\"\n ? CODEX_SYSTEM_PREFIXES\n : [];\n if (prefixes.some((p) => t.startsWith(p))) return null;\n if (provider === \"codex-cli\" && isCodexInjectedContext(t)) return null;\n return cleanSystemTags(t) || null;\n}\n\nexport function isValidNameCandidate(text: string, provider: ScannerProviderName): boolean {\n return normalizeCandidate(text, provider) !== null;\n}\n\n// Pure: same slots in, same name out.\nexport function resolveSessionName(slots: NameSlots): ResolvedSessionName {\n for (const slot of NAME_PRECEDENCE) {\n const value = slots[slot];\n if (value?.trim()) return { name: value, source: slot };\n }\n return { name: null, source: null };\n}\n\n// The single write path for every slot: the last valid occurrence wins, an\n// invalid candidate never overwrites a valid value, and firstUserMessage is set\n// once. Returns a new object, or the input unchanged when nothing applies.\nexport function applyNameCandidate(\n slots: NameSlots,\n slot: NameSlot,\n raw: string | undefined,\n provider: ScannerProviderName,\n): NameSlots {\n if (typeof raw !== \"string\") return slots;\n if (slot === \"firstUserMessage\" && slots.firstUserMessage !== undefined) return slots;\n const text = normalizeCandidate(raw, provider);\n return text === null ? slots : { ...slots, [slot]: text };\n}\n","import { applyNameCandidate, type NameSlots } from \"../session-name\";\n\n// Prompt text of a user entry, or \"\" when it can't name a session: injected\n// meta/compaction rows, and entries with no `text` block (tool results only).\n// Raw on purpose: the prefix checks in isValidNameCandidate run before tags are\n// cleaned, so a `<command-name>` row is rejected rather than emptied.\nfunction userPromptText(entry: Record<string, unknown>): string {\n if (entry.isMeta || entry.isCompactSummary === true) return \"\";\n const content = (entry.message as Record<string, unknown> | undefined)?.content;\n if (typeof content === \"string\") return content;\n if (!Array.isArray(content)) return \"\";\n return content\n .map((b) => (typeof b === \"string\" ? b : b?.type === \"text\" ? b.text : \"\"))\n .filter((t): t is string => typeof t === \"string\" && t !== \"\")\n .join(\" \");\n}\n\n// Maps one Claude JSONL entry to its name-slot candidates. Shared by the\n// metadata and conversation reducers so neither keeps its own naming logic.\nexport function applyClaudeNameEntry(slots: NameSlots, entry: Record<string, unknown>): NameSlots {\n const apply = (slot: Parameters<typeof applyNameCandidate>[1], raw: unknown) =>\n applyNameCandidate(slots, slot, typeof raw === \"string\" ? raw : undefined, \"claude-code\");\n\n // slug rides on every entry of a session, so skip the re-normalising when it\n // is the value already held — this runs once per line of a 100k-line file.\n if (entry.slug !== slots.slug) slots = apply(\"slug\", entry.slug);\n switch (entry.type) {\n case \"custom-title\":\n return apply(\"userTitle\", entry.customTitle);\n case \"ai-title\":\n return apply(\"toolTitle\", entry.aiTitle);\n case \"last-prompt\":\n return apply(\"lastPrompt\", entry.lastPrompt);\n case \"user\":\n return slots.firstUserMessage === undefined\n ? apply(\"firstUserMessage\", userPromptText(entry))\n : slots;\n default:\n return slots;\n }\n}\n","import {\n asQueuedPromptUserEntry,\n extractTextContent,\n extractThinking,\n extractToolResultBlocks,\n extractToolUseBlocks,\n extractToolUseNames,\n hasImageBlocks,\n isOnlyToolResultContent,\n parseTeammateMessageTag,\n} from \"../parse-helpers\";\nimport type { NameSlots } from \"../session-name\";\nimport type {\n AttachmentSidecar,\n CompactionInfo,\n ConversationMessage,\n MessageMetadata,\n MessageSender,\n TeamInfo,\n ToolUseBlock,\n} from \"../types\";\nimport { applyClaudeNameEntry } from \"./claude-name-slots\";\n\n// Resumable, serializable state for the conversation line→message reduction.\n// Mirrors parseConversation()'s loop so a full reduce equals a streamed parse,\n// and so a bounded page read can resume an *equivalent* parse from a checkpoint\n// by restoring the cross-line state (pending tool_use blocks + team info).\nexport interface ConvReducerState {\n cwd: string;\n sessionId: string;\n nameSlots: NameSlots;\n latestTimestamp: string;\n lastPrompt: string;\n // id -> tool_use block, so a later tool_result line resolves its tool type.\n pendingToolUses: Record<string, ToolUseBlock>;\n // teamName -> info, collected as lines are read and applied to messages.\n teamInfo: Record<string, TeamInfo>;\n // The last compact_boundary row seen, held until its summary row (a few\n // lines later) picks it up. Absent in checkpoints written before this field.\n pendingCompaction?: CompactionInfo;\n}\n\nexport function initialConvState(): ConvReducerState {\n return {\n cwd: \"\",\n sessionId: \"\",\n nameSlots: {},\n latestTimestamp: \"\",\n lastPrompt: \"\",\n pendingToolUses: {},\n teamInfo: {},\n };\n}\n\n// Fold one JSONL entry. Returns the produced ConversationMessage (its message\n// index is the count of messages emitted so far), or null if the line produced\n// no message. Mutates `state` (header fields + cross-line maps).\nexport function reduceConvLine(\n state: ConvReducerState,\n rawEntry: Record<string, unknown>,\n): ConversationMessage | null {\n const entry = asQueuedPromptUserEntry(rawEntry);\n if (entry.cwd && !state.cwd) state.cwd = entry.cwd as string;\n if (entry.sessionId && !state.sessionId) state.sessionId = entry.sessionId as string;\n state.nameSlots = applyClaudeNameEntry(state.nameSlots, entry);\n if (entry.timestamp) {\n const ts = entry.timestamp as string;\n if (!state.latestTimestamp || ts > state.latestTimestamp) state.latestTimestamp = ts;\n }\n\n const type = entry.type as string;\n\n if (type === \"last-prompt\") {\n if (entry.lastPrompt && !state.lastPrompt) state.lastPrompt = entry.lastPrompt as string;\n return null;\n }\n if (type === \"system\" && entry.subtype === \"compact_boundary\") {\n const meta = (entry.compactMetadata ?? {}) as Record<string, unknown>;\n state.pendingCompaction = {\n trigger: typeof meta.trigger === \"string\" ? meta.trigger : undefined,\n preTokens: typeof meta.preTokens === \"number\" ? meta.preTokens : undefined,\n postTokens: typeof meta.postTokens === \"number\" ? meta.postTokens : undefined,\n };\n return null;\n }\n // system (incl. turn_duration), file-history-snapshot, etc. produce no message.\n if (type !== \"user\" && type !== \"assistant\") return null;\n if (entry.isMeta) return null;\n\n const isCompactSummary = type === \"user\" && entry.isCompactSummary === true;\n const compaction = isCompactSummary ? state.pendingCompaction : undefined;\n if (isCompactSummary) delete state.pendingCompaction;\n\n const msg = entry.message as Record<string, unknown> | undefined;\n\n const toolUseBlocks = extractToolUseBlocks(msg?.content);\n for (const block of toolUseBlocks) state.pendingToolUses[block.id] = block;\n\n const hasToolUseResult = type === \"user\" && entry.toolUseResult != null;\n const isToolResultOnly = hasToolUseResult && isOnlyToolResultContent(msg?.content);\n const content = extractTextContent(msg?.content);\n const thinking = type === \"assistant\" ? extractThinking(msg?.content) : null;\n const hasThinking = !!(thinking?.content || thinking?.signature);\n\n if (!(content || isToolResultOnly || toolUseBlocks.length > 0 || hasThinking)) return null;\n\n const metadata: MessageMetadata = {};\n if (msg?.model) metadata.model = msg.model as string;\n if (msg?.stop_reason !== undefined) metadata.stopReason = msg.stop_reason as string | null;\n if (entry.gitBranch) metadata.gitBranch = entry.gitBranch as string;\n if (entry.version) metadata.version = entry.version as string;\n\n const usage = msg?.usage as Record<string, number> | undefined;\n if (usage) {\n if (usage.input_tokens) metadata.inputTokens = usage.input_tokens;\n if (usage.output_tokens) metadata.outputTokens = usage.output_tokens;\n if (usage.cache_read_input_tokens) metadata.cacheReadTokens = usage.cache_read_input_tokens;\n if (usage.cache_creation_input_tokens)\n metadata.cacheCreationTokens = usage.cache_creation_input_tokens;\n }\n\n const toolUseNames = extractToolUseNames(msg?.content);\n if (toolUseNames.length > 0) metadata.toolUses = toolUseNames;\n if (toolUseBlocks.length > 0) metadata.toolUseBlocks = toolUseBlocks;\n\n if (isToolResultOnly) {\n const pending = new Map(Object.entries(state.pendingToolUses));\n const toolResultBlocks = extractToolResultBlocks(msg?.content, pending);\n if (toolResultBlocks.length > 0) {\n metadata.toolResults = toolResultBlocks;\n // A result consumes its tool_use: prune it so the cross-line map stays\n // bounded by IN-FLIGHT tool calls instead of growing with the file.\n // Unpruned, every checkpoint snapshot/serialization of this state costs\n // O(file) — the structuredClone stall on large live conversations.\n for (const block of toolResultBlocks) delete state.pendingToolUses[block.toolUseId];\n }\n }\n\n if (entry.teamName) {\n metadata.teamName = entry.teamName as string;\n if (!state.teamInfo[metadata.teamName] && content) {\n const info = parseTeammateMessageTag(content);\n if (info) state.teamInfo[metadata.teamName] = info;\n }\n }\n\n const thinkingContent = thinking?.content || undefined;\n const thinkingSignature = thinking?.signature || undefined;\n const hasMetadata = Object.keys(metadata).length > 0;\n\n return {\n role: type as MessageSender,\n text: content || \"\",\n timestamp: (entry.timestamp as string) || \"\",\n uuid: (entry.uuid as string) || undefined,\n metadata: hasMetadata ? metadata : undefined,\n isToolResult: isToolResultOnly || undefined,\n isThinking: thinkingContent || thinkingSignature ? true : undefined,\n thinkingContent,\n thinkingSignature,\n parentUuid: entry.parentUuid !== undefined ? (entry.parentUuid as string | null) : undefined,\n requestId: type === \"assistant\" ? (entry.requestId as string | undefined) : undefined,\n promptId: type === \"user\" ? (entry.promptId as string | undefined) : undefined,\n isSidechain: typeof entry.isSidechain === \"boolean\" ? entry.isSidechain : undefined,\n permissionMode: type === \"user\" ? (entry.permissionMode as string | undefined) : undefined,\n hasImages: hasImageBlocks(msg?.content) || undefined,\n attachment:\n entry.attachment !== undefined ? (entry.attachment as AttachmentSidecar) : undefined,\n isCompactSummary: isCompactSummary || undefined,\n compaction,\n };\n}\n\n// Parse/classify one raw JSONL line — the exact line→message mapping the\n// scanner uses internally, exported for downstream indexers (e.g. a watcher\n// tailing appended lines) so their semantics cannot drift from the scanner's.\n// Returns the produced ConversationMessage, or null when the line yields none\n// (system/summary/sidecar records, blank or malformed lines). Whether a line\n// produces a message — and its core fields (role, uuid, timestamp) — is\n// state-independent, so calls without `state` classify correctly on their own;\n// pass one shared `state` across successive lines of a file to also resolve\n// cross-line references (tool_result → tool_use types, team info) identically\n// to a full parse.\nexport function parseJsonlLine(\n line: string,\n state: ConvReducerState = initialConvState(),\n): ConversationMessage | null {\n const text = line.trimEnd();\n if (text.trim().length === 0) return null;\n let entry: Record<string, unknown>;\n try {\n entry = JSON.parse(text);\n } catch {\n return null;\n }\n return reduceConvLine(state, entry);\n}\n\n// Back-apply collected team info to a set of messages (the post-pass\n// parseConversation does). Safe to call on a window: teamInfo for a given name\n// is stable once first seen, so a window restored from a checkpoint that\n// carries earlier teamInfo gets the same result.\nexport function applyTeamInfo(messages: ConversationMessage[], state: ConvReducerState): void {\n if (Object.keys(state.teamInfo).length === 0) return;\n for (const m of messages) {\n const name = m.metadata?.teamName;\n if (name && state.teamInfo[name] && m.metadata) m.metadata.teamInfo = state.teamInfo[name];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAM,cAAc;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAA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A,IACnF,WAAW,SAAS,cAAe,MAAM,YAAmC;AAAA,IAC5E,UAAU,SAAS,SAAU,MAAM,WAAkC;AAAA,IACrE,aAAa,OAAO,MAAM,gBAAgB,YAAY,MAAM,cAAc;AAAA,IAC1E,gBAAgB,SAAS,SAAU,MAAM,iBAAwC;AAAA,IACjF,WAAW,eAAe,KAAK,OAAO,KAAK;AAAA,IAC3C,YACE,MAAM,eAAe,SAAa,MAAM,aAAmC;AAAA,IAC7E,kBAAkB,oBAAoB;AAAA,IACtC;AAAA,EACF;AACF;AAYO,SAAS,eACd,MACA,QAA0B,iBAAiB,GACf;AAC5B,QAAM,OAAO,KAAK,QAAQ;AAC1B,MAAI,KAAK,KAAK,EAAE,WAAW,EAAG,QAAO;AACrC,MAAI;AACJ,MAAI;AACF,YAAQ,KAAK,MAAM,IAAI;AAAA,EACzB,QAAQ;AACN,WAAO;AAAA,EACT;AACA,SAAO,eAAe,OAAO,KAAK;AACpC;","names":[]}
package/dist/parse.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export type { ConvReducerState as JsonlParseState } from "./persistent/conversation-reducer";
2
- export { initialConvState as createJsonlParseState, parseJsonlLine, } from "./persistent/conversation-reducer";
3
- export { cleanSystemTags } from "./tags";
4
- export type * from "./types";
1
+ export type { ConvReducerState as JsonlParseState } from "./persistent/conversation-reducer.js";
2
+ export { initialConvState as createJsonlParseState, parseJsonlLine, } from "./persistent/conversation-reducer.js";
3
+ export { cleanSystemTags } from "./tags.js";
4
+ export type * from "./types.js";
5
5
  //# sourceMappingURL=parse.d.ts.map
package/dist/parse.js CHANGED
@@ -40,16 +40,23 @@ function asQueuedPromptUserEntry(entry) {
40
40
  message: { role: "user", content: att.prompt }
41
41
  };
42
42
  }
43
+ var COMMAND_RE = /^\s*<command-name>([\s\S]*?)<\/command-name>/;
44
+ var COMMAND_ARGS_RE = /<command-args>([\s\S]*?)<\/command-args>/;
45
+ function cleanText(text) {
46
+ const name = text.match(COMMAND_RE)?.[1]?.trim();
47
+ const args = name ? text.match(COMMAND_ARGS_RE)?.[1]?.trim() : void 0;
48
+ return name && args ? `${name} ${args}` : cleanSystemTags(text);
49
+ }
43
50
  function extractTextContent(content) {
44
51
  if (!content) return "";
45
- if (typeof content === "string") return cleanSystemTags(content);
52
+ if (typeof content === "string") return cleanText(content);
46
53
  if (Array.isArray(content)) {
47
54
  return content.map((item) => {
48
55
  if (typeof item === "string") return item;
49
56
  if (item?.type === "text" && item?.text) return item.text;
50
57
  if (item?.type === "tool_result" && typeof item?.content === "string") return item.content;
51
58
  return "";
52
- }).filter(Boolean).map(cleanSystemTags).join(" ");
59
+ }).filter(Boolean).map(cleanText).join(" ");
53
60
  }
54
61
  return "";
55
62
  }
package/dist/parse.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/tags.ts","../src/parse-helpers.ts","../src/session-name.ts","../src/persistent/claude-name-slots.ts","../src/persistent/conversation-reducer.ts"],"sourcesContent":["const SYSTEM_TAGS = [\n \"system-reminder\",\n \"command-name\",\n \"command-message\",\n \"command-args\",\n \"ide_selection\",\n \"ide_opened_file\",\n \"local-command-stdout\",\n \"local-command-caveat\",\n \"retrieval_status\",\n \"task_id\",\n \"task_type\",\n \"task-id\",\n \"task-notification\",\n \"fast_mode_info\",\n \"persisted-output\",\n \"tool_use_error\",\n \"user-prompt-submit-hook\",\n \"thinking\",\n \"ask_user\",\n \"teammate-message\",\n];\n\nconst SYSTEM_TAG_RE = new RegExp(`<(${SYSTEM_TAGS.join(\"|\")})[^>]*>[\\\\s\\\\S]*?<\\\\/\\\\1>`, \"g\");\n\n// The CLI wraps an oversized paste in <pasted_content id=\"XXXX\"> /\n// </pasted_content id=\"XXXX\"> (the closing tag repeats the id, so it isn't a\n// SYSTEM_TAGS-style `<\\/\\1>` pair) or a plain </pasted_content>. Unlike the\n// system tags above, this wraps the user's real prompt, so only the tag lines\n// are dropped and the inner text is kept.\nconst PASTED_CONTENT_RE =\n /<pasted_content id=\"[0-9a-f]{4}\">([\\s\\S]*?)<\\/pasted_content(?: id=\"[0-9a-f]{4}\")?>/g;\n\nexport function cleanSystemTags(text: string): string {\n return text\n .replace(SYSTEM_TAG_RE, \"\")\n .replace(PASTED_CONTENT_RE, \"$1\")\n .replace(/[^\\S\\n]+/g, \" \")\n .replace(/\\n{3,}/g, \"\\n\\n\")\n .trim();\n}\n","import { cleanSystemTags } from \"./tags\";\nimport type { TeamInfo, ToolResultBlock, ToolUseBlock } from \"./types\";\n\n// A prompt the user sends while Claude is mid-turn is written only as a\n// queued_command attachment, never as a `user` row, so history would drop it.\n// Returns the `user` entry it stands for; every other entry, including the\n// task-notification and peer queued_commands, comes back unchanged.\nexport function asQueuedPromptUserEntry(entry: Record<string, unknown>): Record<string, unknown> {\n if (entry.type !== \"attachment\") return entry;\n const att = entry.attachment as\n | { type?: string; commandMode?: string; origin?: { kind?: string }; prompt?: unknown }\n | undefined;\n if (att?.type !== \"queued_command\" || att.commandMode !== \"prompt\") return entry;\n if (att.origin?.kind !== \"human\") return entry;\n return {\n ...entry,\n type: \"user\",\n attachment: undefined,\n message: { role: \"user\", content: att.prompt },\n };\n}\n\nexport function extractTextContent(content: unknown): string {\n if (!content) return \"\";\n if (typeof content === \"string\") return cleanSystemTags(content);\n if (Array.isArray(content)) {\n return content\n .map((item) => {\n if (typeof item === \"string\") return item;\n if (item?.type === \"text\" && item?.text) return item.text;\n if (item?.type === \"tool_result\" && typeof item?.content === \"string\") return item.content;\n return \"\";\n })\n .filter(Boolean)\n .map(cleanSystemTags)\n .join(\" \");\n }\n return \"\";\n}\n\nexport function extractToolUseNames(content: unknown): string[] {\n if (!Array.isArray(content)) return [];\n return content\n .filter((item) => item?.type === \"tool_use\" && item?.name)\n .map((item) => item.name as string);\n}\n\nexport function extractToolUseBlocks(content: unknown): ToolUseBlock[] {\n if (!Array.isArray(content)) return [];\n return content\n .filter((item) => item?.type === \"tool_use\" && item?.name && item?.id)\n .map((item) => ({\n id: item.id as string,\n name: item.name as string,\n input: (item.input as Record<string, unknown>) || {},\n }));\n}\n\nconst TOOL_NAME_TO_TYPE: Record<string, ToolResultBlock[\"type\"]> = {\n Edit: \"edit\",\n Write: \"write\",\n Read: \"read\",\n Bash: \"bash\",\n Grep: \"grep\",\n Glob: \"glob\",\n Agent: \"taskAgent\",\n TaskCreate: \"taskCreate\",\n TaskUpdate: \"taskUpdate\",\n};\n\nexport function extractToolResultBlocks(\n content: unknown,\n pendingToolUses: Map<string, ToolUseBlock>,\n): ToolResultBlock[] {\n if (!Array.isArray(content)) return [];\n return content\n .filter((item) => item?.type === \"tool_result\" && item?.tool_use_id)\n .map((item) => {\n const toolName = pendingToolUses.get(item.tool_use_id as string)?.name ?? \"\";\n return {\n toolUseId: item.tool_use_id as string,\n type: TOOL_NAME_TO_TYPE[toolName] ?? \"generic\",\n content:\n typeof item.content === \"string\"\n ? { text: item.content as string }\n : ((item.content as Record<string, unknown>) ?? {}),\n isError: typeof item.is_error === \"boolean\" ? item.is_error : undefined,\n };\n });\n}\n\nexport function isOnlyToolResultContent(content: unknown): boolean {\n if (!Array.isArray(content)) return false;\n return content.length > 0 && content.every((item) => item?.type === \"tool_result\");\n}\n\nexport function extractThinking(content: unknown): { content: string; signature: string } {\n if (!Array.isArray(content)) return { content: \"\", signature: \"\" };\n const blocks = content.filter((item) => item?.type === \"thinking\");\n return {\n content: blocks\n .map((b) => b.thinking as string)\n .filter(Boolean)\n .join(\"\\n\\n\"),\n signature: blocks\n .map((b) => b.signature as string)\n .filter(Boolean)\n .join(\"\"),\n };\n}\n\nexport function hasImageBlocks(content: unknown): boolean {\n if (!Array.isArray(content)) return false;\n return content.some(\n (item) =>\n item?.type === \"image\" &&\n (item?.source?.type === \"base64\" || item?.file?.base64 !== undefined),\n );\n}\n\nexport function parseTeammateMessageTag(content: string): TeamInfo | null {\n const match = content.match(/<teammate-message\\s+([^>]*)>/);\n if (!match) return null;\n const attrs = match[1];\n const id = attrs.match(/teammate_id=\"([^\"]*)\"/)?.[1];\n if (!id) return null;\n const summary = attrs.match(/summary=\"([^\"]*)\"/)?.[1];\n const color = attrs.match(/color=\"([^\"]*)\"/)?.[1];\n return { teammateId: id, summary, color };\n}\n","import type { ScannerProviderName } from \"./providers/provider\";\nimport { cleanSystemTags } from \"./tags\";\n\nexport type NameSlot = \"userTitle\" | \"toolTitle\" | \"lastPrompt\" | \"firstUserMessage\" | \"slug\";\n\n// Highest first: the first non-empty slot is the session's name.\nexport const NAME_PRECEDENCE: readonly NameSlot[] = [\n \"userTitle\",\n \"toolTitle\",\n \"lastPrompt\",\n \"firstUserMessage\",\n \"slug\",\n];\n\nexport interface NameSlots {\n userTitle?: string;\n toolTitle?: string;\n lastPrompt?: string;\n firstUserMessage?: string; // set once, never replaced\n slug?: string;\n}\n\nexport interface ResolvedSessionName {\n name: string | null; // full, untruncated\n source: NameSlot | null;\n}\n\n// Text the host injects as a \"user\" turn. Matched against the trimmed text.\nconst CLAUDE_SYSTEM_PREFIXES = [\n \"<command-name>\",\n \"<command-message>\",\n \"<command-args>\",\n \"<local-command-stdout>\",\n \"<local-command-stderr>\",\n \"<local-command-caveat>\",\n \"<bash-input>\",\n \"<bash-stdout>\",\n \"<bash-stderr>\",\n \"<system-reminder>\",\n \"<task-notification>\",\n \"<teammate-message\",\n \"Another Claude session sent a message:\",\n \"[Request interrupted by user\",\n];\n\nconst CODEX_SYSTEM_PREFIXES = [\n \"<environment_context>\",\n \"# AGENTS.md instructions\",\n \"<user_instructions>\",\n \"<INSTRUCTIONS>\",\n \"<external_codex_apps_open\",\n \"<user_shell_command>\",\n \"<turn_aborted>\",\n];\n\n/**\n * Boilerplate Codex injects as a `user`-role turn. Codex-generic only — prompts a\n * host passes as argv (Codex has no --system-prompt flag) also land as role:user,\n * but recognising those is the host's business, not the scanner's.\n */\nexport function isCodexInjectedContext(text: string): boolean {\n // AGENTS.md / instruction dumps prepended as the opening turn.\n if (text.startsWith(\"# AGENTS.md\") || text.includes(\"<INSTRUCTIONS>\")) return true;\n // Permissions / sandbox preamble, sometimes a giant user-role blob.\n return (\n text.startsWith(\"<permissions instructions>\") || text.includes(\"Filesystem sandboxing defines\")\n );\n}\n\nconst CODEX_IMAGE_TAG_RE = /<\\/?image\\b[^>]*>/g;\n\n// The text to store for a candidate, or null when it cannot name a session.\nfunction normalizeCandidate(text: string, provider: ScannerProviderName): string | null {\n let t = text.trim();\n if (provider === \"codex-cli\") t = t.replace(CODEX_IMAGE_TAG_RE, \"\").trim();\n const prefixes =\n provider === \"claude-code\"\n ? CLAUDE_SYSTEM_PREFIXES\n : provider === \"codex-cli\"\n ? CODEX_SYSTEM_PREFIXES\n : [];\n if (prefixes.some((p) => t.startsWith(p))) return null;\n if (provider === \"codex-cli\" && isCodexInjectedContext(t)) return null;\n return cleanSystemTags(t) || null;\n}\n\nexport function isValidNameCandidate(text: string, provider: ScannerProviderName): boolean {\n return normalizeCandidate(text, provider) !== null;\n}\n\n// Pure: same slots in, same name out.\nexport function resolveSessionName(slots: NameSlots): ResolvedSessionName {\n for (const slot of NAME_PRECEDENCE) {\n const value = slots[slot];\n if (value?.trim()) return { name: value, source: slot };\n }\n return { name: null, source: null };\n}\n\n// The single write path for every slot: the last valid occurrence wins, an\n// invalid candidate never overwrites a valid value, and firstUserMessage is set\n// once. Returns a new object, or the input unchanged when nothing applies.\nexport function applyNameCandidate(\n slots: NameSlots,\n slot: NameSlot,\n raw: string | undefined,\n provider: ScannerProviderName,\n): NameSlots {\n if (typeof raw !== \"string\") return slots;\n if (slot === \"firstUserMessage\" && slots.firstUserMessage !== undefined) return slots;\n const text = normalizeCandidate(raw, provider);\n return text === null ? slots : { ...slots, [slot]: text };\n}\n","import { applyNameCandidate, type NameSlots } from \"../session-name\";\n\n// Prompt text of a user entry, or \"\" when it can't name a session: injected\n// meta/compaction rows, and entries with no `text` block (tool results only).\n// Raw on purpose: the prefix checks in isValidNameCandidate run before tags are\n// cleaned, so a `<command-name>` row is rejected rather than emptied.\nfunction userPromptText(entry: Record<string, unknown>): string {\n if (entry.isMeta || entry.isCompactSummary === true) return \"\";\n const content = (entry.message as Record<string, unknown> | undefined)?.content;\n if (typeof content === \"string\") return content;\n if (!Array.isArray(content)) return \"\";\n return content\n .map((b) => (typeof b === \"string\" ? b : b?.type === \"text\" ? b.text : \"\"))\n .filter((t): t is string => typeof t === \"string\" && t !== \"\")\n .join(\" \");\n}\n\n// Maps one Claude JSONL entry to its name-slot candidates. Shared by the\n// metadata and conversation reducers so neither keeps its own naming logic.\nexport function applyClaudeNameEntry(slots: NameSlots, entry: Record<string, unknown>): NameSlots {\n const apply = (slot: Parameters<typeof applyNameCandidate>[1], raw: unknown) =>\n applyNameCandidate(slots, slot, typeof raw === \"string\" ? raw : undefined, \"claude-code\");\n\n // slug rides on every entry of a session, so skip the re-normalising when it\n // is the value already held — this runs once per line of a 100k-line file.\n if (entry.slug !== slots.slug) slots = apply(\"slug\", entry.slug);\n switch (entry.type) {\n case \"custom-title\":\n return apply(\"userTitle\", entry.customTitle);\n case \"ai-title\":\n return apply(\"toolTitle\", entry.aiTitle);\n case \"last-prompt\":\n return apply(\"lastPrompt\", entry.lastPrompt);\n case \"user\":\n return slots.firstUserMessage === undefined\n ? apply(\"firstUserMessage\", userPromptText(entry))\n : slots;\n default:\n return slots;\n }\n}\n","import {\n asQueuedPromptUserEntry,\n extractTextContent,\n extractThinking,\n extractToolResultBlocks,\n extractToolUseBlocks,\n extractToolUseNames,\n hasImageBlocks,\n isOnlyToolResultContent,\n parseTeammateMessageTag,\n} from \"../parse-helpers\";\nimport type { NameSlots } from \"../session-name\";\nimport type {\n AttachmentSidecar,\n CompactionInfo,\n ConversationMessage,\n MessageMetadata,\n MessageSender,\n TeamInfo,\n ToolUseBlock,\n} from \"../types\";\nimport { applyClaudeNameEntry } from \"./claude-name-slots\";\n\n// Resumable, serializable state for the conversation line→message reduction.\n// Mirrors parseConversation()'s loop so a full reduce equals a streamed parse,\n// and so a bounded page read can resume an *equivalent* parse from a checkpoint\n// by restoring the cross-line state (pending tool_use blocks + team info).\nexport interface ConvReducerState {\n cwd: string;\n sessionId: string;\n nameSlots: NameSlots;\n latestTimestamp: string;\n lastPrompt: string;\n // id -> tool_use block, so a later tool_result line resolves its tool type.\n pendingToolUses: Record<string, ToolUseBlock>;\n // teamName -> info, collected as lines are read and applied to messages.\n teamInfo: Record<string, TeamInfo>;\n // The last compact_boundary row seen, held until its summary row (a few\n // lines later) picks it up. Absent in checkpoints written before this field.\n pendingCompaction?: CompactionInfo;\n}\n\nexport function initialConvState(): ConvReducerState {\n return {\n cwd: \"\",\n sessionId: \"\",\n nameSlots: {},\n latestTimestamp: \"\",\n lastPrompt: \"\",\n pendingToolUses: {},\n teamInfo: {},\n };\n}\n\n// Fold one JSONL entry. Returns the produced ConversationMessage (its message\n// index is the count of messages emitted so far), or null if the line produced\n// no message. Mutates `state` (header fields + cross-line maps).\nexport function reduceConvLine(\n state: ConvReducerState,\n rawEntry: Record<string, unknown>,\n): ConversationMessage | null {\n const entry = asQueuedPromptUserEntry(rawEntry);\n if (entry.cwd && !state.cwd) state.cwd = entry.cwd as string;\n if (entry.sessionId && !state.sessionId) state.sessionId = entry.sessionId as string;\n state.nameSlots = applyClaudeNameEntry(state.nameSlots, entry);\n if (entry.timestamp) {\n const ts = entry.timestamp as string;\n if (!state.latestTimestamp || ts > state.latestTimestamp) state.latestTimestamp = ts;\n }\n\n const type = entry.type as string;\n\n if (type === \"last-prompt\") {\n if (entry.lastPrompt && !state.lastPrompt) state.lastPrompt = entry.lastPrompt as string;\n return null;\n }\n if (type === \"system\" && entry.subtype === \"compact_boundary\") {\n const meta = (entry.compactMetadata ?? {}) as Record<string, unknown>;\n state.pendingCompaction = {\n trigger: typeof meta.trigger === \"string\" ? meta.trigger : undefined,\n preTokens: typeof meta.preTokens === \"number\" ? meta.preTokens : undefined,\n postTokens: typeof meta.postTokens === \"number\" ? meta.postTokens : undefined,\n };\n return null;\n }\n // system (incl. turn_duration), file-history-snapshot, etc. produce no message.\n if (type !== \"user\" && type !== \"assistant\") return null;\n if (entry.isMeta) return null;\n\n const isCompactSummary = type === \"user\" && entry.isCompactSummary === true;\n const compaction = isCompactSummary ? state.pendingCompaction : undefined;\n if (isCompactSummary) delete state.pendingCompaction;\n\n const msg = entry.message as Record<string, unknown> | undefined;\n\n const toolUseBlocks = extractToolUseBlocks(msg?.content);\n for (const block of toolUseBlocks) state.pendingToolUses[block.id] = block;\n\n const hasToolUseResult = type === \"user\" && entry.toolUseResult != null;\n const isToolResultOnly = hasToolUseResult && isOnlyToolResultContent(msg?.content);\n const content = extractTextContent(msg?.content);\n const thinking = type === \"assistant\" ? extractThinking(msg?.content) : null;\n const hasThinking = !!(thinking?.content || thinking?.signature);\n\n if (!(content || isToolResultOnly || toolUseBlocks.length > 0 || hasThinking)) return null;\n\n const metadata: MessageMetadata = {};\n if (msg?.model) metadata.model = msg.model as string;\n if (msg?.stop_reason !== undefined) metadata.stopReason = msg.stop_reason as string | null;\n if (entry.gitBranch) metadata.gitBranch = entry.gitBranch as string;\n if (entry.version) metadata.version = entry.version as string;\n\n const usage = msg?.usage as Record<string, number> | undefined;\n if (usage) {\n if (usage.input_tokens) metadata.inputTokens = usage.input_tokens;\n if (usage.output_tokens) metadata.outputTokens = usage.output_tokens;\n if (usage.cache_read_input_tokens) metadata.cacheReadTokens = usage.cache_read_input_tokens;\n if (usage.cache_creation_input_tokens)\n metadata.cacheCreationTokens = usage.cache_creation_input_tokens;\n }\n\n const toolUseNames = extractToolUseNames(msg?.content);\n if (toolUseNames.length > 0) metadata.toolUses = toolUseNames;\n if (toolUseBlocks.length > 0) metadata.toolUseBlocks = toolUseBlocks;\n\n if (isToolResultOnly) {\n const pending = new Map(Object.entries(state.pendingToolUses));\n const toolResultBlocks = extractToolResultBlocks(msg?.content, pending);\n if (toolResultBlocks.length > 0) {\n metadata.toolResults = toolResultBlocks;\n // A result consumes its tool_use: prune it so the cross-line map stays\n // bounded by IN-FLIGHT tool calls instead of growing with the file.\n // Unpruned, every checkpoint snapshot/serialization of this state costs\n // O(file) — the structuredClone stall on large live conversations.\n for (const block of toolResultBlocks) delete state.pendingToolUses[block.toolUseId];\n }\n }\n\n if (entry.teamName) {\n metadata.teamName = entry.teamName as string;\n if (!state.teamInfo[metadata.teamName] && content) {\n const info = parseTeammateMessageTag(content);\n if (info) state.teamInfo[metadata.teamName] = info;\n }\n }\n\n const thinkingContent = thinking?.content || undefined;\n const thinkingSignature = thinking?.signature || undefined;\n const hasMetadata = Object.keys(metadata).length > 0;\n\n return {\n role: type as MessageSender,\n text: content || \"\",\n timestamp: (entry.timestamp as string) || \"\",\n uuid: (entry.uuid as string) || undefined,\n metadata: hasMetadata ? metadata : undefined,\n isToolResult: isToolResultOnly || undefined,\n isThinking: thinkingContent || thinkingSignature ? true : undefined,\n thinkingContent,\n thinkingSignature,\n parentUuid: entry.parentUuid !== undefined ? (entry.parentUuid as string | null) : undefined,\n requestId: type === \"assistant\" ? (entry.requestId as string | undefined) : undefined,\n promptId: type === \"user\" ? (entry.promptId as string | undefined) : undefined,\n isSidechain: typeof entry.isSidechain === \"boolean\" ? entry.isSidechain : undefined,\n permissionMode: type === \"user\" ? (entry.permissionMode as string | undefined) : undefined,\n hasImages: hasImageBlocks(msg?.content) || undefined,\n attachment:\n entry.attachment !== undefined ? (entry.attachment as AttachmentSidecar) : undefined,\n isCompactSummary: isCompactSummary || undefined,\n compaction,\n };\n}\n\n// Parse/classify one raw JSONL line — the exact line→message mapping the\n// scanner uses internally, exported for downstream indexers (e.g. a watcher\n// tailing appended lines) so their semantics cannot drift from the scanner's.\n// Returns the produced ConversationMessage, or null when the line yields none\n// (system/summary/sidecar records, blank or malformed lines). Whether a line\n// produces a message — and its core fields (role, uuid, timestamp) — is\n// state-independent, so calls without `state` classify correctly on their own;\n// pass one shared `state` across successive lines of a file to also resolve\n// cross-line references (tool_result → tool_use types, team info) identically\n// to a full parse.\nexport function parseJsonlLine(\n line: string,\n state: ConvReducerState = initialConvState(),\n): ConversationMessage | null {\n const text = line.trimEnd();\n if (text.trim().length === 0) return null;\n let entry: Record<string, unknown>;\n try {\n entry = JSON.parse(text);\n } catch {\n return null;\n }\n return reduceConvLine(state, entry);\n}\n\n// Back-apply collected team info to a set of messages (the post-pass\n// parseConversation does). Safe to call on a window: teamInfo for a given name\n// is stable once first seen, so a window restored from a checkpoint that\n// carries earlier teamInfo gets the same result.\nexport function applyTeamInfo(messages: ConversationMessage[], state: ConvReducerState): void {\n if (Object.keys(state.teamInfo).length === 0) return;\n for (const m of messages) {\n const name = m.metadata?.teamName;\n if (name && state.teamInfo[name] && m.metadata) m.metadata.teamInfo = state.teamInfo[name];\n }\n}\n"],"mappings":";AAAA,IAAM,cAAc;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,IAAM,gBAAgB,IAAI,OAAO,KAAK,YAAY,KAAK,GAAG,CAAC,6BAA6B,GAAG;AAO3F,IAAM,oBACJ;AAEK,SAAS,gBAAgB,MAAsB;AACpD,SAAO,KACJ,QAAQ,eAAe,EAAE,EACzB,QAAQ,mBAAmB,IAAI,EAC/B,QAAQ,aAAa,GAAG,EACxB,QAAQ,WAAW,MAAM,EACzB,KAAK;AACV;;;ACjCO,SAAS,wBAAwB,OAAyD;AAC/F,MAAI,MAAM,SAAS,aAAc,QAAO;AACxC,QAAM,MAAM,MAAM;AAGlB,MAAI,KAAK,SAAS,oBAAoB,IAAI,gBAAgB,SAAU,QAAO;AAC3E,MAAI,IAAI,QAAQ,SAAS,QAAS,QAAO;AACzC,SAAO;AAAA,IACL,GAAG;AAAA,IACH,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,SAAS,EAAE,MAAM,QAAQ,SAAS,IAAI,OAAO;AAAA,EAC/C;AACF;AAEO,SAAS,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AAK,QAAQ,EAAE,SAAS;AAEnD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,MAAM,WAAW;AAAA,IACjB,WAAY,MAAM,aAAwB;AAAA,IAC1C,MAAO,MAAM,QAAmB;AAAA,IAChC,UAAU,cAAc,WAAW;AAAA,IACnC,cAAc,oBAAoB;AAAA,IAClC,YAAY,mBAAmB,oBAAoB,OAAO;AAAA,IAC1D;AAAA,IACA;AAAA,IACA,YAAY,MAAM,eAAe,SAAa,MAAM,aAA+B;AAAA,IACnF,WAAW,SAAS,cAAe,MAAM,YAAmC;AAAA,IAC5E,UAAU,SAAS,SAAU,MAAM,WAAkC;AAAA,IACrE,aAAa,OAAO,MAAM,gBAAgB,YAAY,MAAM,cAAc;AAAA,IAC1E,gBAAgB,SAAS,SAAU,MAAM,iBAAwC;AAAA,IACjF,WAAW,eAAe,KAAK,OAAO,KAAK;AAAA,IAC3C,YACE,MAAM,eAAe,SAAa,MAAM,aAAmC;AAAA,IAC7E,kBAAkB,oBAAoB;AAAA,IACtC;AAAA,EACF;AACF;AAYO,SAAS,eACd,MACA,QAA0B,iBAAiB,GACf;AAC5B,QAAM,OAAO,KAAK,QAAQ;AAC1B,MAAI,KAAK,KAAK,EAAE,WAAW,EAAG,QAAO;AACrC,MAAI;AACJ,MAAI;AACF,YAAQ,KAAK,MAAM,IAAI;AAAA,EACzB,QAAQ;AACN,WAAO;AAAA,EACT;AACA,SAAO,eAAe,OAAO,KAAK;AACpC;","names":[]}
1
+ {"version":3,"sources":["../src/tags.ts","../src/parse-helpers.ts","../src/session-name.ts","../src/persistent/claude-name-slots.ts","../src/persistent/conversation-reducer.ts"],"sourcesContent":["const SYSTEM_TAGS = [\n \"system-reminder\",\n \"command-name\",\n \"command-message\",\n \"command-args\",\n \"ide_selection\",\n \"ide_opened_file\",\n \"local-command-stdout\",\n \"local-command-caveat\",\n \"retrieval_status\",\n \"task_id\",\n \"task_type\",\n \"task-id\",\n \"task-notification\",\n \"fast_mode_info\",\n \"persisted-output\",\n \"tool_use_error\",\n \"user-prompt-submit-hook\",\n \"thinking\",\n \"ask_user\",\n \"teammate-message\",\n];\n\nconst SYSTEM_TAG_RE = new RegExp(`<(${SYSTEM_TAGS.join(\"|\")})[^>]*>[\\\\s\\\\S]*?<\\\\/\\\\1>`, \"g\");\n\n// The CLI wraps an oversized paste in <pasted_content id=\"XXXX\"> /\n// </pasted_content id=\"XXXX\"> (the closing tag repeats the id, so it isn't a\n// SYSTEM_TAGS-style `<\\/\\1>` pair) or a plain </pasted_content>. Unlike the\n// system tags above, this wraps the user's real prompt, so only the tag lines\n// are dropped and the inner text is kept.\nconst PASTED_CONTENT_RE =\n /<pasted_content id=\"[0-9a-f]{4}\">([\\s\\S]*?)<\\/pasted_content(?: id=\"[0-9a-f]{4}\")?>/g;\n\nexport function cleanSystemTags(text: string): string {\n return text\n .replace(SYSTEM_TAG_RE, \"\")\n .replace(PASTED_CONTENT_RE, \"$1\")\n .replace(/[^\\S\\n]+/g, \" \")\n .replace(/\\n{3,}/g, \"\\n\\n\")\n .trim();\n}\n","import { cleanSystemTags } from \"./tags\";\nimport type { TeamInfo, ToolResultBlock, ToolUseBlock } from \"./types\";\n\n// A prompt the user sends while Claude is mid-turn is written only as a\n// queued_command attachment, never as a `user` row, so history would drop it.\n// Returns the `user` entry it stands for; every other entry, including the\n// task-notification and peer queued_commands, comes back unchanged.\nexport function asQueuedPromptUserEntry(entry: Record<string, unknown>): Record<string, unknown> {\n if (entry.type !== \"attachment\") return entry;\n const att = entry.attachment as\n | { type?: string; commandMode?: string; origin?: { kind?: string }; prompt?: unknown }\n | undefined;\n if (att?.type !== \"queued_command\" || att.commandMode !== \"prompt\") return entry;\n if (att.origin?.kind !== \"human\") return entry;\n return {\n ...entry,\n type: \"user\",\n attachment: undefined,\n message: { role: \"user\", content: att.prompt },\n };\n}\n\n// A typed slash command is stored as <command-name>/x</command-name> plus\n// <command-args>…</command-args>, and the args are where the user's real prompt\n// lives (`/plan <prompt>`). cleanSystemTags strips both tags, which emptied the\n// line and dropped the session's first prompt from history. Rebuild what was typed.\nconst COMMAND_RE = /^\\s*<command-name>([\\s\\S]*?)<\\/command-name>/;\nconst COMMAND_ARGS_RE = /<command-args>([\\s\\S]*?)<\\/command-args>/;\n\nfunction cleanText(text: string): string {\n const name = text.match(COMMAND_RE)?.[1]?.trim();\n const args = name ? text.match(COMMAND_ARGS_RE)?.[1]?.trim() : undefined;\n // A bare command (/compact, /clear) carries no prompt and stays hidden.\n return name && args ? `${name} ${args}` : cleanSystemTags(text);\n}\n\nexport function extractTextContent(content: unknown): string {\n if (!content) return \"\";\n if (typeof content === \"string\") return cleanText(content);\n if (Array.isArray(content)) {\n return content\n .map((item) => {\n if (typeof item === \"string\") return item;\n if (item?.type === \"text\" && item?.text) return item.text;\n if (item?.type === \"tool_result\" && typeof item?.content === \"string\") return item.content;\n return \"\";\n })\n .filter(Boolean)\n .map(cleanText)\n .join(\" \");\n }\n return \"\";\n}\n\nexport function extractToolUseNames(content: unknown): string[] {\n if (!Array.isArray(content)) return [];\n return content\n .filter((item) => item?.type === \"tool_use\" && item?.name)\n .map((item) => item.name as string);\n}\n\nexport function extractToolUseBlocks(content: unknown): ToolUseBlock[] {\n if (!Array.isArray(content)) return [];\n return content\n .filter((item) => item?.type === \"tool_use\" && item?.name && item?.id)\n .map((item) => ({\n id: item.id as string,\n name: item.name as string,\n input: (item.input as Record<string, unknown>) || {},\n }));\n}\n\nconst TOOL_NAME_TO_TYPE: Record<string, ToolResultBlock[\"type\"]> = {\n Edit: \"edit\",\n Write: \"write\",\n Read: \"read\",\n Bash: \"bash\",\n Grep: \"grep\",\n Glob: \"glob\",\n Agent: \"taskAgent\",\n TaskCreate: \"taskCreate\",\n TaskUpdate: \"taskUpdate\",\n};\n\nexport function extractToolResultBlocks(\n content: unknown,\n pendingToolUses: Map<string, ToolUseBlock>,\n): ToolResultBlock[] {\n if (!Array.isArray(content)) return [];\n return content\n .filter((item) => item?.type === \"tool_result\" && item?.tool_use_id)\n .map((item) => {\n const toolName = pendingToolUses.get(item.tool_use_id as string)?.name ?? \"\";\n return {\n toolUseId: item.tool_use_id as string,\n type: TOOL_NAME_TO_TYPE[toolName] ?? \"generic\",\n content:\n typeof item.content === \"string\"\n ? { text: item.content as string }\n : ((item.content as Record<string, unknown>) ?? {}),\n isError: typeof item.is_error === \"boolean\" ? item.is_error : undefined,\n };\n });\n}\n\nexport function isOnlyToolResultContent(content: unknown): boolean {\n if (!Array.isArray(content)) return false;\n return content.length > 0 && content.every((item) => item?.type === \"tool_result\");\n}\n\nexport function extractThinking(content: unknown): { content: string; signature: string } {\n if (!Array.isArray(content)) return { content: \"\", signature: \"\" };\n const blocks = content.filter((item) => item?.type === \"thinking\");\n return {\n content: blocks\n .map((b) => b.thinking as string)\n .filter(Boolean)\n .join(\"\\n\\n\"),\n signature: blocks\n .map((b) => b.signature as string)\n .filter(Boolean)\n .join(\"\"),\n };\n}\n\nexport function hasImageBlocks(content: unknown): boolean {\n if (!Array.isArray(content)) return false;\n return content.some(\n (item) =>\n item?.type === \"image\" &&\n (item?.source?.type === \"base64\" || item?.file?.base64 !== undefined),\n );\n}\n\nexport function parseTeammateMessageTag(content: string): TeamInfo | null {\n const match = content.match(/<teammate-message\\s+([^>]*)>/);\n if (!match) return null;\n const attrs = match[1];\n const id = attrs.match(/teammate_id=\"([^\"]*)\"/)?.[1];\n if (!id) return null;\n const summary = attrs.match(/summary=\"([^\"]*)\"/)?.[1];\n const color = attrs.match(/color=\"([^\"]*)\"/)?.[1];\n return { teammateId: id, summary, color };\n}\n","import type { ScannerProviderName } from \"./providers/provider\";\nimport { cleanSystemTags } from \"./tags\";\n\nexport type NameSlot = \"userTitle\" | \"toolTitle\" | \"lastPrompt\" | \"firstUserMessage\" | \"slug\";\n\n// Highest first: the first non-empty slot is the session's name.\nexport const NAME_PRECEDENCE: readonly NameSlot[] = [\n \"userTitle\",\n \"toolTitle\",\n \"lastPrompt\",\n \"firstUserMessage\",\n \"slug\",\n];\n\nexport interface NameSlots {\n userTitle?: string;\n toolTitle?: string;\n lastPrompt?: string;\n firstUserMessage?: string; // set once, never replaced\n slug?: string;\n}\n\nexport interface ResolvedSessionName {\n name: string | null; // full, untruncated\n source: NameSlot | null;\n}\n\n// Text the host injects as a \"user\" turn. Matched against the trimmed text.\nconst CLAUDE_SYSTEM_PREFIXES = [\n \"<command-name>\",\n \"<command-message>\",\n \"<command-args>\",\n \"<local-command-stdout>\",\n \"<local-command-stderr>\",\n \"<local-command-caveat>\",\n \"<bash-input>\",\n \"<bash-stdout>\",\n \"<bash-stderr>\",\n \"<system-reminder>\",\n \"<task-notification>\",\n \"<teammate-message\",\n \"Another Claude session sent a message:\",\n \"[Request interrupted by user\",\n];\n\nconst CODEX_SYSTEM_PREFIXES = [\n \"<environment_context>\",\n \"# AGENTS.md instructions\",\n \"<user_instructions>\",\n \"<INSTRUCTIONS>\",\n \"<external_codex_apps_open\",\n \"<user_shell_command>\",\n \"<turn_aborted>\",\n];\n\n/**\n * Boilerplate Codex injects as a `user`-role turn. Codex-generic only — prompts a\n * host passes as argv (Codex has no --system-prompt flag) also land as role:user,\n * but recognising those is the host's business, not the scanner's.\n */\nexport function isCodexInjectedContext(text: string): boolean {\n // AGENTS.md / instruction dumps prepended as the opening turn.\n if (text.startsWith(\"# AGENTS.md\") || text.includes(\"<INSTRUCTIONS>\")) return true;\n // Permissions / sandbox preamble, sometimes a giant user-role blob.\n return (\n text.startsWith(\"<permissions instructions>\") || text.includes(\"Filesystem sandboxing defines\")\n );\n}\n\nconst CODEX_IMAGE_TAG_RE = /<\\/?image\\b[^>]*>/g;\n\n// The text to store for a candidate, or null when it cannot name a session.\nfunction normalizeCandidate(text: string, provider: ScannerProviderName): string | null {\n let t = text.trim();\n if (provider === \"codex-cli\") t = t.replace(CODEX_IMAGE_TAG_RE, \"\").trim();\n const prefixes =\n provider === \"claude-code\"\n ? CLAUDE_SYSTEM_PREFIXES\n : provider === \"codex-cli\"\n ? CODEX_SYSTEM_PREFIXES\n : [];\n if (prefixes.some((p) => t.startsWith(p))) return null;\n if (provider === \"codex-cli\" && isCodexInjectedContext(t)) return null;\n return cleanSystemTags(t) || null;\n}\n\nexport function isValidNameCandidate(text: string, provider: ScannerProviderName): boolean {\n return normalizeCandidate(text, provider) !== null;\n}\n\n// Pure: same slots in, same name out.\nexport function resolveSessionName(slots: NameSlots): ResolvedSessionName {\n for (const slot of NAME_PRECEDENCE) {\n const value = slots[slot];\n if (value?.trim()) return { name: value, source: slot };\n }\n return { name: null, source: null };\n}\n\n// The single write path for every slot: the last valid occurrence wins, an\n// invalid candidate never overwrites a valid value, and firstUserMessage is set\n// once. Returns a new object, or the input unchanged when nothing applies.\nexport function applyNameCandidate(\n slots: NameSlots,\n slot: NameSlot,\n raw: string | undefined,\n provider: ScannerProviderName,\n): NameSlots {\n if (typeof raw !== \"string\") return slots;\n if (slot === \"firstUserMessage\" && slots.firstUserMessage !== undefined) return slots;\n const text = normalizeCandidate(raw, provider);\n return text === null ? slots : { ...slots, [slot]: text };\n}\n","import { applyNameCandidate, type NameSlots } from \"../session-name\";\n\n// Prompt text of a user entry, or \"\" when it can't name a session: injected\n// meta/compaction rows, and entries with no `text` block (tool results only).\n// Raw on purpose: the prefix checks in isValidNameCandidate run before tags are\n// cleaned, so a `<command-name>` row is rejected rather than emptied.\nfunction userPromptText(entry: Record<string, unknown>): string {\n if (entry.isMeta || entry.isCompactSummary === true) return \"\";\n const content = (entry.message as Record<string, unknown> | undefined)?.content;\n if (typeof content === \"string\") return content;\n if (!Array.isArray(content)) return \"\";\n return content\n .map((b) => (typeof b === \"string\" ? b : b?.type === \"text\" ? b.text : \"\"))\n .filter((t): t is string => typeof t === \"string\" && t !== \"\")\n .join(\" \");\n}\n\n// Maps one Claude JSONL entry to its name-slot candidates. Shared by the\n// metadata and conversation reducers so neither keeps its own naming logic.\nexport function applyClaudeNameEntry(slots: NameSlots, entry: Record<string, unknown>): NameSlots {\n const apply = (slot: Parameters<typeof applyNameCandidate>[1], raw: unknown) =>\n applyNameCandidate(slots, slot, typeof raw === \"string\" ? raw : undefined, \"claude-code\");\n\n // slug rides on every entry of a session, so skip the re-normalising when it\n // is the value already held — this runs once per line of a 100k-line file.\n if (entry.slug !== slots.slug) slots = apply(\"slug\", entry.slug);\n switch (entry.type) {\n case \"custom-title\":\n return apply(\"userTitle\", entry.customTitle);\n case \"ai-title\":\n return apply(\"toolTitle\", entry.aiTitle);\n case \"last-prompt\":\n return apply(\"lastPrompt\", entry.lastPrompt);\n case \"user\":\n return slots.firstUserMessage === undefined\n ? apply(\"firstUserMessage\", userPromptText(entry))\n : slots;\n default:\n return slots;\n }\n}\n","import {\n asQueuedPromptUserEntry,\n extractTextContent,\n extractThinking,\n extractToolResultBlocks,\n extractToolUseBlocks,\n extractToolUseNames,\n hasImageBlocks,\n isOnlyToolResultContent,\n parseTeammateMessageTag,\n} from \"../parse-helpers\";\nimport type { NameSlots } from \"../session-name\";\nimport type {\n AttachmentSidecar,\n CompactionInfo,\n ConversationMessage,\n MessageMetadata,\n MessageSender,\n TeamInfo,\n ToolUseBlock,\n} from \"../types\";\nimport { applyClaudeNameEntry } from \"./claude-name-slots\";\n\n// Resumable, serializable state for the conversation line→message reduction.\n// Mirrors parseConversation()'s loop so a full reduce equals a streamed parse,\n// and so a bounded page read can resume an *equivalent* parse from a checkpoint\n// by restoring the cross-line state (pending tool_use blocks + team info).\nexport interface ConvReducerState {\n cwd: string;\n sessionId: string;\n nameSlots: NameSlots;\n latestTimestamp: string;\n lastPrompt: string;\n // id -> tool_use block, so a later tool_result line resolves its tool type.\n pendingToolUses: Record<string, ToolUseBlock>;\n // teamName -> info, collected as lines are read and applied to messages.\n teamInfo: Record<string, TeamInfo>;\n // The last compact_boundary row seen, held until its summary row (a few\n // lines later) picks it up. Absent in checkpoints written before this field.\n pendingCompaction?: CompactionInfo;\n}\n\nexport function initialConvState(): ConvReducerState {\n return {\n cwd: \"\",\n sessionId: \"\",\n nameSlots: {},\n latestTimestamp: \"\",\n lastPrompt: \"\",\n pendingToolUses: {},\n teamInfo: {},\n };\n}\n\n// Fold one JSONL entry. Returns the produced ConversationMessage (its message\n// index is the count of messages emitted so far), or null if the line produced\n// no message. Mutates `state` (header fields + cross-line maps).\nexport function reduceConvLine(\n state: ConvReducerState,\n rawEntry: Record<string, unknown>,\n): ConversationMessage | null {\n const entry = asQueuedPromptUserEntry(rawEntry);\n if (entry.cwd && !state.cwd) state.cwd = entry.cwd as string;\n if (entry.sessionId && !state.sessionId) state.sessionId = entry.sessionId as string;\n state.nameSlots = applyClaudeNameEntry(state.nameSlots, entry);\n if (entry.timestamp) {\n const ts = entry.timestamp as string;\n if (!state.latestTimestamp || ts > state.latestTimestamp) state.latestTimestamp = ts;\n }\n\n const type = entry.type as string;\n\n if (type === \"last-prompt\") {\n if (entry.lastPrompt && !state.lastPrompt) state.lastPrompt = entry.lastPrompt as string;\n return null;\n }\n if (type === \"system\" && entry.subtype === \"compact_boundary\") {\n const meta = (entry.compactMetadata ?? {}) as Record<string, unknown>;\n state.pendingCompaction = {\n trigger: typeof meta.trigger === \"string\" ? meta.trigger : undefined,\n preTokens: typeof meta.preTokens === \"number\" ? meta.preTokens : undefined,\n postTokens: typeof meta.postTokens === \"number\" ? meta.postTokens : undefined,\n };\n return null;\n }\n // system (incl. turn_duration), file-history-snapshot, etc. produce no message.\n if (type !== \"user\" && type !== \"assistant\") return null;\n if (entry.isMeta) return null;\n\n const isCompactSummary = type === \"user\" && entry.isCompactSummary === true;\n const compaction = isCompactSummary ? state.pendingCompaction : undefined;\n if (isCompactSummary) delete state.pendingCompaction;\n\n const msg = entry.message as Record<string, unknown> | undefined;\n\n const toolUseBlocks = extractToolUseBlocks(msg?.content);\n for (const block of toolUseBlocks) state.pendingToolUses[block.id] = block;\n\n const hasToolUseResult = type === \"user\" && entry.toolUseResult != null;\n const isToolResultOnly = hasToolUseResult && isOnlyToolResultContent(msg?.content);\n const content = extractTextContent(msg?.content);\n const thinking = type === \"assistant\" ? extractThinking(msg?.content) : null;\n const hasThinking = !!(thinking?.content || thinking?.signature);\n\n if (!(content || isToolResultOnly || toolUseBlocks.length > 0 || hasThinking)) return null;\n\n const metadata: MessageMetadata = {};\n if (msg?.model) metadata.model = msg.model as string;\n if (msg?.stop_reason !== undefined) metadata.stopReason = msg.stop_reason as string | null;\n if (entry.gitBranch) metadata.gitBranch = entry.gitBranch as string;\n if (entry.version) metadata.version = entry.version as string;\n\n const usage = msg?.usage as Record<string, number> | undefined;\n if (usage) {\n if (usage.input_tokens) metadata.inputTokens = usage.input_tokens;\n if (usage.output_tokens) metadata.outputTokens = usage.output_tokens;\n if (usage.cache_read_input_tokens) metadata.cacheReadTokens = usage.cache_read_input_tokens;\n if (usage.cache_creation_input_tokens)\n metadata.cacheCreationTokens = usage.cache_creation_input_tokens;\n }\n\n const toolUseNames = extractToolUseNames(msg?.content);\n if (toolUseNames.length > 0) metadata.toolUses = toolUseNames;\n if (toolUseBlocks.length > 0) metadata.toolUseBlocks = toolUseBlocks;\n\n if (isToolResultOnly) {\n const pending = new Map(Object.entries(state.pendingToolUses));\n const toolResultBlocks = extractToolResultBlocks(msg?.content, pending);\n if (toolResultBlocks.length > 0) {\n metadata.toolResults = toolResultBlocks;\n // A result consumes its tool_use: prune it so the cross-line map stays\n // bounded by IN-FLIGHT tool calls instead of growing with the file.\n // Unpruned, every checkpoint snapshot/serialization of this state costs\n // O(file) — the structuredClone stall on large live conversations.\n for (const block of toolResultBlocks) delete state.pendingToolUses[block.toolUseId];\n }\n }\n\n if (entry.teamName) {\n metadata.teamName = entry.teamName as string;\n if (!state.teamInfo[metadata.teamName] && content) {\n const info = parseTeammateMessageTag(content);\n if (info) state.teamInfo[metadata.teamName] = info;\n }\n }\n\n const thinkingContent = thinking?.content || undefined;\n const thinkingSignature = thinking?.signature || undefined;\n const hasMetadata = Object.keys(metadata).length > 0;\n\n return {\n role: type as MessageSender,\n text: content || \"\",\n timestamp: (entry.timestamp as string) || \"\",\n uuid: (entry.uuid as string) || undefined,\n metadata: hasMetadata ? metadata : undefined,\n isToolResult: isToolResultOnly || undefined,\n isThinking: thinkingContent || thinkingSignature ? true : undefined,\n thinkingContent,\n thinkingSignature,\n parentUuid: entry.parentUuid !== undefined ? (entry.parentUuid as string | null) : undefined,\n requestId: type === \"assistant\" ? (entry.requestId as string | undefined) : undefined,\n promptId: type === \"user\" ? (entry.promptId as string | undefined) : undefined,\n isSidechain: typeof entry.isSidechain === \"boolean\" ? entry.isSidechain : undefined,\n permissionMode: type === \"user\" ? (entry.permissionMode as string | undefined) : undefined,\n hasImages: hasImageBlocks(msg?.content) || undefined,\n attachment:\n entry.attachment !== undefined ? (entry.attachment as AttachmentSidecar) : undefined,\n isCompactSummary: isCompactSummary || undefined,\n compaction,\n };\n}\n\n// Parse/classify one raw JSONL line — the exact line→message mapping the\n// scanner uses internally, exported for downstream indexers (e.g. a watcher\n// tailing appended lines) so their semantics cannot drift from the scanner's.\n// Returns the produced ConversationMessage, or null when the line yields none\n// (system/summary/sidecar records, blank or malformed lines). Whether a line\n// produces a message — and its core fields (role, uuid, timestamp) — is\n// state-independent, so calls without `state` classify correctly on their own;\n// pass one shared `state` across successive lines of a file to also resolve\n// cross-line references (tool_result → tool_use types, team info) identically\n// to a full parse.\nexport function parseJsonlLine(\n line: string,\n state: ConvReducerState = initialConvState(),\n): ConversationMessage | null {\n const text = line.trimEnd();\n if (text.trim().length === 0) return null;\n let entry: Record<string, unknown>;\n try {\n entry = JSON.parse(text);\n } catch {\n return null;\n }\n return reduceConvLine(state, entry);\n}\n\n// Back-apply collected team info to a set of messages (the post-pass\n// parseConversation does). Safe to call on a window: teamInfo for a given name\n// is stable once first seen, so a window restored from a checkpoint that\n// carries earlier teamInfo gets the same result.\nexport function applyTeamInfo(messages: ConversationMessage[], state: ConvReducerState): void {\n if (Object.keys(state.teamInfo).length === 0) return;\n for (const m of messages) {\n const name = m.metadata?.teamName;\n if (name && state.teamInfo[name] && m.metadata) m.metadata.teamInfo = state.teamInfo[name];\n }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AAwB;AAAA,IAC1C,MAAO,MAAM,QAAmB;AAAA,IAChC,UAAU,cAAc,WAAW;AAAA,IACnC,cAAc,oBAAoB;AAAA,IAClC,YAAY,mBAAmB,oBAAoB,OAAO;AAAA,IAC1D;AAAA,IACA;AAAA,IACA,YAAY,MAAM,eAAe,SAAa,MAAM,aAA+B;AAAA,IACnF,WAAW,SAAS,cAAe,MAAM,YAAmC;AAAA,IAC5E,UAAU,SAAS,SAAU,MAAM,WAAkC;AAAA,IACrE,aAAa,OAAO,MAAM,gBAAgB,YAAY,MAAM,cAAc;AAAA,IAC1E,gBAAgB,SAAS,SAAU,MAAM,iBAAwC;AAAA,IACjF,WAAW,eAAe,KAAK,OAAO,KAAK;AAAA,IAC3C,YACE,MAAM,eAAe,SAAa,MAAM,aAAmC;AAAA,IAC7E,kBAAkB,oBAAoB;AAAA,IACtC;AAAA,EACF;AACF;AAYO,SAAS,eACd,MACA,QAA0B,iBAAiB,GACf;AAC5B,QAAM,OAAO,KAAK,QAAQ;AAC1B,MAAI,KAAK,KAAK,EAAE,WAAW,EAAG,QAAO;AACrC,MAAI;AACJ,MAAI;AACF,YAAQ,KAAK,MAAM,IAAI;AAAA,EACzB,QAAQ;AACN,WAAO;AAAA,EACT;AACA,SAAO,eAAe,OAAO,KAAK;AACpC;","names":[]}
package/dist/parser.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { ContentTier, Conversation, ConversationMeta, TurnDuration } from "./types";
2
- export { asQueuedPromptUserEntry, extractTextContent, extractThinking, extractToolResultBlocks, extractToolUseBlocks, extractToolUseNames, hasImageBlocks, isOnlyToolResultContent, parseTeammateMessageTag, } from "./parse-helpers";
1
+ import type { ContentTier, Conversation, ConversationMeta, TurnDuration } from "./types.js";
2
+ export { asQueuedPromptUserEntry, extractTextContent, extractThinking, extractToolResultBlocks, extractToolUseBlocks, extractToolUseNames, hasImageBlocks, isOnlyToolResultContent, parseTeammateMessageTag, } from "./parse-helpers.js";
3
3
  export declare function turnDurationOf(entry: Record<string, unknown>): TurnDuration | null;
4
4
  export declare function parseMeta(filePath: string, account: string, tier: ContentTier, onEntry?: (entry: Record<string, unknown>) => void): Promise<ConversationMeta | null>;
5
5
  export declare function parseConversation(filePath: string, account: string): Promise<Conversation | null>;
@@ -1,3 +1,3 @@
1
- import { type NameSlots } from "../session-name";
1
+ import { type NameSlots } from "../session-name.js";
2
2
  export declare function applyClaudeNameEntry(slots: NameSlots, entry: Record<string, unknown>): NameSlots;
3
3
  //# sourceMappingURL=claude-name-slots.d.ts.map
@@ -1,5 +1,5 @@
1
- import type { NameSlots } from "../session-name";
2
- import type { CompactionInfo, ConversationMessage, TeamInfo, ToolUseBlock } from "../types";
1
+ import type { NameSlots } from "../session-name.js";
2
+ import type { CompactionInfo, ConversationMessage, TeamInfo, ToolUseBlock } from "../types.js";
3
3
  export interface ConvReducerState {
4
4
  cwd: string;
5
5
  sessionId: string;
@@ -1,5 +1,5 @@
1
- import type { Conversation } from "../types";
2
- import { type ConvReducerState } from "./conversation-reducer";
1
+ import type { Conversation } from "../types.js";
2
+ import { type ConvReducerState } from "./conversation-reducer.js";
3
3
  export interface ConversationResume {
4
4
  state: ConvReducerState;
5
5
  offset: number;
@@ -1,4 +1,4 @@
1
- import type { FileRow } from "./repositories/conversation-files.repo";
1
+ import type { FileRow } from "./repositories/conversation-files.repo.js";
2
2
  export type FileChange = "unchanged" | "appended" | "reindex" | "vanished";
3
3
  export interface FileStat {
4
4
  size: number;
@@ -1,6 +1,6 @@
1
- import { type DiscoveredFile } from "../discovery";
2
- import type { ConversationFilesRepo } from "./repositories/conversation-files.repo";
3
- import type { ScannedDirsRepo } from "./repositories/scanned-dirs.repo";
1
+ import { type DiscoveredFile } from "../discovery.js";
2
+ import type { ConversationFilesRepo } from "./repositories/conversation-files.repo.js";
3
+ import type { ScannedDirsRepo } from "./repositories/scanned-dirs.repo.js";
4
4
  export declare const FULL_RECONCILE_EVERY_N_SCANS = 20;
5
5
  export declare function discoverJsonlFilesGated(dirs: {
6
6
  projectsDir: string;
@@ -1,12 +1,12 @@
1
- import { type ScannerProvider } from "../providers/provider";
2
- import type { ConversationMeta, ConversationPage, GetConversationPageOptions, Profile, ScanOptions, SearchHighlight, TurnDuration } from "../types";
3
- import { type FileChange } from "./cursor";
4
- import { type DB } from "./db";
5
- import { CheckpointsRepo } from "./repositories/checkpoints.repo";
6
- import { ConversationFilesRepo } from "./repositories/conversation-files.repo";
7
- import { ConversationsRepo } from "./repositories/conversations.repo";
8
- import { FtsRepo, type FtsSearchFilters } from "./repositories/fts.repo";
9
- import { ScannedDirsRepo } from "./repositories/scanned-dirs.repo";
1
+ import { type ScannerProvider } from "../providers/provider.js";
2
+ import type { ConversationMeta, ConversationPage, GetConversationPageOptions, Profile, ScanOptions, SearchHighlight, TurnDuration } from "../types.js";
3
+ import { type FileChange } from "./cursor.js";
4
+ import { type DB } from "./db.js";
5
+ import { CheckpointsRepo } from "./repositories/checkpoints.repo.js";
6
+ import { ConversationFilesRepo } from "./repositories/conversation-files.repo.js";
7
+ import { ConversationsRepo } from "./repositories/conversations.repo.js";
8
+ import { FtsRepo, type FtsSearchFilters } from "./repositories/fts.repo.js";
9
+ import { ScannedDirsRepo } from "./repositories/scanned-dirs.repo.js";
10
10
  export interface EngineSearchHit {
11
11
  meta: ConversationMeta;
12
12
  body: {
@@ -1,5 +1,5 @@
1
- import type { ContentTier } from "../types";
2
- import { type ReducerState } from "./metadata-reducer";
1
+ import type { ContentTier } from "../types.js";
2
+ import { type ReducerState } from "./metadata-reducer.js";
3
3
  export declare const YIELD_EVERY_LINES = 500;
4
4
  export interface TailReadResult {
5
5
  newOffset: number;
@@ -1,5 +1,5 @@
1
- import { type NameSlots } from "../session-name";
2
- import type { ContentTier, ConversationMeta, MessageSender, MessageSnapshot, TurnDuration } from "../types";
1
+ import { type NameSlots } from "../session-name.js";
2
+ import type { ContentTier, ConversationMeta, MessageSender, MessageSnapshot, TurnDuration } from "../types.js";
3
3
  export interface ReducerState {
4
4
  sessionId: string;
5
5
  nameSlots: NameSlots;
@@ -1,6 +1,6 @@
1
- import type { Conversation, ConversationMessage, ConversationPage, GetConversationPageOptions, TurnDuration } from "../types";
2
- import { type ConvReducerState } from "./conversation-reducer";
3
- import type { Checkpoint } from "./repositories/checkpoints.repo";
1
+ import type { Conversation, ConversationMessage, ConversationPage, GetConversationPageOptions, TurnDuration } from "../types.js";
2
+ import { type ConvReducerState } from "./conversation-reducer.js";
3
+ import type { Checkpoint } from "./repositories/checkpoints.repo.js";
4
4
  export declare const CHECKPOINT_INTERVAL = 500;
5
5
  export declare function streamMessages(filePath: string, startOffset: number, startLine: number, state: ConvReducerState, onMessage: (message: ConversationMessage, nextByteOffset: number, nextLine: number) => boolean, onEntry?: (entry: Record<string, unknown>) => boolean): Promise<{
6
6
  offset: number;
@@ -1,5 +1,5 @@
1
1
  import type { Database } from "better-sqlite3";
2
- import type { ConvReducerState } from "../conversation-reducer";
2
+ import type { ConvReducerState } from "../conversation-reducer.js";
3
3
  export interface Checkpoint {
4
4
  messageIndex: number;
5
5
  byteOffset: number;
@@ -1,5 +1,5 @@
1
1
  import type { Database } from "better-sqlite3";
2
- import type { ConversationMeta } from "../../types";
2
+ import type { ConversationMeta } from "../../types.js";
3
3
  export interface ConversationRow {
4
4
  id: number;
5
5
  file_id: number;
@@ -1,6 +1,6 @@
1
1
  import type { Database } from "better-sqlite3";
2
- import type { SearchDocument } from "../../search-document";
3
- import type { ConversationMeta, SearchHighlight } from "../../types";
2
+ import type { SearchDocument } from "../../search-document.js";
3
+ import type { ConversationMeta, SearchHighlight } from "../../types.js";
4
4
  export interface FtsSearchFilters {
5
5
  account?: string;
6
6
  provider?: string;
@@ -1,4 +1,4 @@
1
- import type { ConversationMeta } from "../types";
1
+ import type { ConversationMeta } from "../types.js";
2
2
  export declare const SIDECAR_VERSION = 1;
3
3
  export interface Sidecar {
4
4
  version: number;
@@ -1,4 +1,4 @@
1
- import type { Profile } from "./types";
1
+ import type { Profile } from "./types.js";
2
2
  export declare function resolveConfigDir(configDir: string): string;
3
3
  export declare function getProjectsDir(profile: Profile): string;
4
4
  export declare function detectDefaultProfile(): Promise<Profile>;
@@ -1,6 +1,6 @@
1
- import { isCodexInjectedContext, type NameSlots } from "../session-name";
2
- import type { ContentTier, Conversation, ConversationMessage, ConversationMeta, MessageSender, MessageSnapshot } from "../types";
3
- import { type DiscoveredConversationFile, type ScannerProvider } from "./provider";
1
+ import { isCodexInjectedContext, type NameSlots } from "../session-name.js";
2
+ import type { ContentTier, Conversation, ConversationMessage, ConversationMeta, MessageSender, MessageSnapshot } from "../types.js";
3
+ import { type DiscoveredConversationFile, type ScannerProvider } from "./provider.js";
4
4
  export interface CodexAccumulator {
5
5
  sessionId: string;
6
6
  cwd: string;
@@ -1,6 +1,6 @@
1
- import { type NameSlots } from "../session-name";
2
- import type { ContentTier, Conversation, ConversationMessage, ConversationMeta, MessageSender, MessageSnapshot } from "../types";
3
- import { type DiscoveredConversationFile, type ScannerProvider } from "./provider";
1
+ import { type NameSlots } from "../session-name.js";
2
+ import type { ContentTier, Conversation, ConversationMessage, ConversationMeta, MessageSender, MessageSnapshot } from "../types.js";
3
+ import { type DiscoveredConversationFile, type ScannerProvider } from "./provider.js";
4
4
  export interface CopilotAccumulator {
5
5
  sessionId: string;
6
6
  cwd: string;
@@ -1,6 +1,6 @@
1
- import { type NameSlots } from "../session-name";
2
- import type { ContentTier, Conversation, ConversationMessage, ConversationMeta, MessageSender, MessageSnapshot } from "../types";
3
- import { type DiscoveredConversationFile, type ScannerProvider } from "./provider";
1
+ import { type NameSlots } from "../session-name.js";
2
+ import type { ContentTier, Conversation, ConversationMessage, ConversationMeta, MessageSender, MessageSnapshot } from "../types.js";
3
+ import { type DiscoveredConversationFile, type ScannerProvider } from "./provider.js";
4
4
  export interface CursorAccumulator {
5
5
  sessionId: string;
6
6
  latestTimestamp: string;
@@ -1,4 +1,4 @@
1
- import type { ContentTier, ConversationMeta } from "../types";
2
- import type { ScannerProvider } from "./provider";
1
+ import type { ContentTier, ConversationMeta } from "../types.js";
2
+ import type { ScannerProvider } from "./provider.js";
3
3
  export declare function parseMetaWithProvider(provider: ScannerProvider, filePath: string, account: string, tier: ContentTier, onEntry?: (entry: Record<string, unknown>) => void): Promise<ConversationMeta | null>;
4
4
  //# sourceMappingURL=parse.d.ts.map