@threadbase-sh/scanner 0.24.7 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -0
- package/dist/cli.js +91 -89
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +363 -363
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +351 -351
- package/dist/index.js.map +1 -1
- package/dist/parse-helpers.d.ts +14 -0
- package/dist/parse-helpers.d.ts.map +1 -0
- package/dist/parse.cjs +340 -0
- package/dist/parse.cjs.map +1 -0
- package/dist/parse.d.ts +5 -0
- package/dist/parse.d.ts.map +1 -0
- package/dist/parse.js +311 -0
- package/dist/parse.js.map +1 -0
- package/dist/parser.d.ts +2 -13
- package/dist/parser.d.ts.map +1 -1
- package/package.json +7 -2
package/dist/parse.js
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
// src/tags.ts
|
|
2
|
+
var SYSTEM_TAGS = [
|
|
3
|
+
"system-reminder",
|
|
4
|
+
"command-name",
|
|
5
|
+
"command-message",
|
|
6
|
+
"command-args",
|
|
7
|
+
"ide_selection",
|
|
8
|
+
"ide_opened_file",
|
|
9
|
+
"local-command-stdout",
|
|
10
|
+
"local-command-caveat",
|
|
11
|
+
"retrieval_status",
|
|
12
|
+
"task_id",
|
|
13
|
+
"task_type",
|
|
14
|
+
"task-id",
|
|
15
|
+
"task-notification",
|
|
16
|
+
"fast_mode_info",
|
|
17
|
+
"persisted-output",
|
|
18
|
+
"tool_use_error",
|
|
19
|
+
"user-prompt-submit-hook",
|
|
20
|
+
"thinking",
|
|
21
|
+
"ask_user",
|
|
22
|
+
"teammate-message"
|
|
23
|
+
];
|
|
24
|
+
var SYSTEM_TAG_RE = new RegExp(`<(${SYSTEM_TAGS.join("|")})[^>]*>[\\s\\S]*?<\\/\\1>`, "g");
|
|
25
|
+
var PASTED_CONTENT_RE = /<pasted_content id="[0-9a-f]{4}">([\s\S]*?)<\/pasted_content(?: id="[0-9a-f]{4}")?>/g;
|
|
26
|
+
function cleanSystemTags(text) {
|
|
27
|
+
return text.replace(SYSTEM_TAG_RE, "").replace(PASTED_CONTENT_RE, "$1").replace(/[^\S\n]+/g, " ").replace(/\n{3,}/g, "\n\n").trim();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// src/parse-helpers.ts
|
|
31
|
+
function asQueuedPromptUserEntry(entry) {
|
|
32
|
+
if (entry.type !== "attachment") return entry;
|
|
33
|
+
const att = entry.attachment;
|
|
34
|
+
if (att?.type !== "queued_command" || att.commandMode !== "prompt") return entry;
|
|
35
|
+
if (att.origin?.kind !== "human") return entry;
|
|
36
|
+
return {
|
|
37
|
+
...entry,
|
|
38
|
+
type: "user",
|
|
39
|
+
attachment: void 0,
|
|
40
|
+
message: { role: "user", content: att.prompt }
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function extractTextContent(content) {
|
|
44
|
+
if (!content) return "";
|
|
45
|
+
if (typeof content === "string") return cleanSystemTags(content);
|
|
46
|
+
if (Array.isArray(content)) {
|
|
47
|
+
return content.map((item) => {
|
|
48
|
+
if (typeof item === "string") return item;
|
|
49
|
+
if (item?.type === "text" && item?.text) return item.text;
|
|
50
|
+
if (item?.type === "tool_result" && typeof item?.content === "string") return item.content;
|
|
51
|
+
return "";
|
|
52
|
+
}).filter(Boolean).map(cleanSystemTags).join(" ");
|
|
53
|
+
}
|
|
54
|
+
return "";
|
|
55
|
+
}
|
|
56
|
+
function extractToolUseNames(content) {
|
|
57
|
+
if (!Array.isArray(content)) return [];
|
|
58
|
+
return content.filter((item) => item?.type === "tool_use" && item?.name).map((item) => item.name);
|
|
59
|
+
}
|
|
60
|
+
function extractToolUseBlocks(content) {
|
|
61
|
+
if (!Array.isArray(content)) return [];
|
|
62
|
+
return content.filter((item) => item?.type === "tool_use" && item?.name && item?.id).map((item) => ({
|
|
63
|
+
id: item.id,
|
|
64
|
+
name: item.name,
|
|
65
|
+
input: item.input || {}
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
var TOOL_NAME_TO_TYPE = {
|
|
69
|
+
Edit: "edit",
|
|
70
|
+
Write: "write",
|
|
71
|
+
Read: "read",
|
|
72
|
+
Bash: "bash",
|
|
73
|
+
Grep: "grep",
|
|
74
|
+
Glob: "glob",
|
|
75
|
+
Agent: "taskAgent",
|
|
76
|
+
TaskCreate: "taskCreate",
|
|
77
|
+
TaskUpdate: "taskUpdate"
|
|
78
|
+
};
|
|
79
|
+
function extractToolResultBlocks(content, pendingToolUses) {
|
|
80
|
+
if (!Array.isArray(content)) return [];
|
|
81
|
+
return content.filter((item) => item?.type === "tool_result" && item?.tool_use_id).map((item) => {
|
|
82
|
+
const toolName = pendingToolUses.get(item.tool_use_id)?.name ?? "";
|
|
83
|
+
return {
|
|
84
|
+
toolUseId: item.tool_use_id,
|
|
85
|
+
type: TOOL_NAME_TO_TYPE[toolName] ?? "generic",
|
|
86
|
+
content: typeof item.content === "string" ? { text: item.content } : item.content ?? {},
|
|
87
|
+
isError: typeof item.is_error === "boolean" ? item.is_error : void 0
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
function isOnlyToolResultContent(content) {
|
|
92
|
+
if (!Array.isArray(content)) return false;
|
|
93
|
+
return content.length > 0 && content.every((item) => item?.type === "tool_result");
|
|
94
|
+
}
|
|
95
|
+
function extractThinking(content) {
|
|
96
|
+
if (!Array.isArray(content)) return { content: "", signature: "" };
|
|
97
|
+
const blocks = content.filter((item) => item?.type === "thinking");
|
|
98
|
+
return {
|
|
99
|
+
content: blocks.map((b) => b.thinking).filter(Boolean).join("\n\n"),
|
|
100
|
+
signature: blocks.map((b) => b.signature).filter(Boolean).join("")
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function hasImageBlocks(content) {
|
|
104
|
+
if (!Array.isArray(content)) return false;
|
|
105
|
+
return content.some(
|
|
106
|
+
(item) => item?.type === "image" && (item?.source?.type === "base64" || item?.file?.base64 !== void 0)
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
function parseTeammateMessageTag(content) {
|
|
110
|
+
const match = content.match(/<teammate-message\s+([^>]*)>/);
|
|
111
|
+
if (!match) return null;
|
|
112
|
+
const attrs = match[1];
|
|
113
|
+
const id = attrs.match(/teammate_id="([^"]*)"/)?.[1];
|
|
114
|
+
if (!id) return null;
|
|
115
|
+
const summary = attrs.match(/summary="([^"]*)"/)?.[1];
|
|
116
|
+
const color = attrs.match(/color="([^"]*)"/)?.[1];
|
|
117
|
+
return { teammateId: id, summary, color };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// src/session-name.ts
|
|
121
|
+
var CLAUDE_SYSTEM_PREFIXES = [
|
|
122
|
+
"<command-name>",
|
|
123
|
+
"<command-message>",
|
|
124
|
+
"<command-args>",
|
|
125
|
+
"<local-command-stdout>",
|
|
126
|
+
"<local-command-stderr>",
|
|
127
|
+
"<local-command-caveat>",
|
|
128
|
+
"<bash-input>",
|
|
129
|
+
"<bash-stdout>",
|
|
130
|
+
"<bash-stderr>",
|
|
131
|
+
"<system-reminder>",
|
|
132
|
+
"<task-notification>",
|
|
133
|
+
"<teammate-message",
|
|
134
|
+
"Another Claude session sent a message:",
|
|
135
|
+
"[Request interrupted by user"
|
|
136
|
+
];
|
|
137
|
+
var CODEX_SYSTEM_PREFIXES = [
|
|
138
|
+
"<environment_context>",
|
|
139
|
+
"# AGENTS.md instructions",
|
|
140
|
+
"<user_instructions>",
|
|
141
|
+
"<INSTRUCTIONS>",
|
|
142
|
+
"<external_codex_apps_open",
|
|
143
|
+
"<user_shell_command>",
|
|
144
|
+
"<turn_aborted>"
|
|
145
|
+
];
|
|
146
|
+
function isCodexInjectedContext(text) {
|
|
147
|
+
if (text.startsWith("# AGENTS.md") || text.includes("<INSTRUCTIONS>")) return true;
|
|
148
|
+
return text.startsWith("<permissions instructions>") || text.includes("Filesystem sandboxing defines");
|
|
149
|
+
}
|
|
150
|
+
var CODEX_IMAGE_TAG_RE = /<\/?image\b[^>]*>/g;
|
|
151
|
+
function normalizeCandidate(text, provider) {
|
|
152
|
+
let t = text.trim();
|
|
153
|
+
if (provider === "codex-cli") t = t.replace(CODEX_IMAGE_TAG_RE, "").trim();
|
|
154
|
+
const prefixes = provider === "claude-code" ? CLAUDE_SYSTEM_PREFIXES : provider === "codex-cli" ? CODEX_SYSTEM_PREFIXES : [];
|
|
155
|
+
if (prefixes.some((p) => t.startsWith(p))) return null;
|
|
156
|
+
if (provider === "codex-cli" && isCodexInjectedContext(t)) return null;
|
|
157
|
+
return cleanSystemTags(t) || null;
|
|
158
|
+
}
|
|
159
|
+
function applyNameCandidate(slots, slot, raw, provider) {
|
|
160
|
+
if (typeof raw !== "string") return slots;
|
|
161
|
+
if (slot === "firstUserMessage" && slots.firstUserMessage !== void 0) return slots;
|
|
162
|
+
const text = normalizeCandidate(raw, provider);
|
|
163
|
+
return text === null ? slots : { ...slots, [slot]: text };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/persistent/claude-name-slots.ts
|
|
167
|
+
function userPromptText(entry) {
|
|
168
|
+
if (entry.isMeta || entry.isCompactSummary === true) return "";
|
|
169
|
+
const content = entry.message?.content;
|
|
170
|
+
if (typeof content === "string") return content;
|
|
171
|
+
if (!Array.isArray(content)) return "";
|
|
172
|
+
return content.map((b) => typeof b === "string" ? b : b?.type === "text" ? b.text : "").filter((t) => typeof t === "string" && t !== "").join(" ");
|
|
173
|
+
}
|
|
174
|
+
function applyClaudeNameEntry(slots, entry) {
|
|
175
|
+
const apply = (slot, raw) => applyNameCandidate(slots, slot, typeof raw === "string" ? raw : void 0, "claude-code");
|
|
176
|
+
if (entry.slug !== slots.slug) slots = apply("slug", entry.slug);
|
|
177
|
+
switch (entry.type) {
|
|
178
|
+
case "custom-title":
|
|
179
|
+
return apply("userTitle", entry.customTitle);
|
|
180
|
+
case "ai-title":
|
|
181
|
+
return apply("toolTitle", entry.aiTitle);
|
|
182
|
+
case "last-prompt":
|
|
183
|
+
return apply("lastPrompt", entry.lastPrompt);
|
|
184
|
+
case "user":
|
|
185
|
+
return slots.firstUserMessage === void 0 ? apply("firstUserMessage", userPromptText(entry)) : slots;
|
|
186
|
+
default:
|
|
187
|
+
return slots;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// src/persistent/conversation-reducer.ts
|
|
192
|
+
function initialConvState() {
|
|
193
|
+
return {
|
|
194
|
+
cwd: "",
|
|
195
|
+
sessionId: "",
|
|
196
|
+
nameSlots: {},
|
|
197
|
+
latestTimestamp: "",
|
|
198
|
+
lastPrompt: "",
|
|
199
|
+
pendingToolUses: {},
|
|
200
|
+
teamInfo: {}
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function reduceConvLine(state, rawEntry) {
|
|
204
|
+
const entry = asQueuedPromptUserEntry(rawEntry);
|
|
205
|
+
if (entry.cwd && !state.cwd) state.cwd = entry.cwd;
|
|
206
|
+
if (entry.sessionId && !state.sessionId) state.sessionId = entry.sessionId;
|
|
207
|
+
state.nameSlots = applyClaudeNameEntry(state.nameSlots, entry);
|
|
208
|
+
if (entry.timestamp) {
|
|
209
|
+
const ts = entry.timestamp;
|
|
210
|
+
if (!state.latestTimestamp || ts > state.latestTimestamp) state.latestTimestamp = ts;
|
|
211
|
+
}
|
|
212
|
+
const type = entry.type;
|
|
213
|
+
if (type === "last-prompt") {
|
|
214
|
+
if (entry.lastPrompt && !state.lastPrompt) state.lastPrompt = entry.lastPrompt;
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
if (type === "system" && entry.subtype === "compact_boundary") {
|
|
218
|
+
const meta = entry.compactMetadata ?? {};
|
|
219
|
+
state.pendingCompaction = {
|
|
220
|
+
trigger: typeof meta.trigger === "string" ? meta.trigger : void 0,
|
|
221
|
+
preTokens: typeof meta.preTokens === "number" ? meta.preTokens : void 0,
|
|
222
|
+
postTokens: typeof meta.postTokens === "number" ? meta.postTokens : void 0
|
|
223
|
+
};
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
if (type !== "user" && type !== "assistant") return null;
|
|
227
|
+
if (entry.isMeta) return null;
|
|
228
|
+
const isCompactSummary = type === "user" && entry.isCompactSummary === true;
|
|
229
|
+
const compaction = isCompactSummary ? state.pendingCompaction : void 0;
|
|
230
|
+
if (isCompactSummary) delete state.pendingCompaction;
|
|
231
|
+
const msg = entry.message;
|
|
232
|
+
const toolUseBlocks = extractToolUseBlocks(msg?.content);
|
|
233
|
+
for (const block of toolUseBlocks) state.pendingToolUses[block.id] = block;
|
|
234
|
+
const hasToolUseResult = type === "user" && entry.toolUseResult != null;
|
|
235
|
+
const isToolResultOnly = hasToolUseResult && isOnlyToolResultContent(msg?.content);
|
|
236
|
+
const content = extractTextContent(msg?.content);
|
|
237
|
+
const thinking = type === "assistant" ? extractThinking(msg?.content) : null;
|
|
238
|
+
const hasThinking = !!(thinking?.content || thinking?.signature);
|
|
239
|
+
if (!(content || isToolResultOnly || toolUseBlocks.length > 0 || hasThinking)) return null;
|
|
240
|
+
const metadata = {};
|
|
241
|
+
if (msg?.model) metadata.model = msg.model;
|
|
242
|
+
if (msg?.stop_reason !== void 0) metadata.stopReason = msg.stop_reason;
|
|
243
|
+
if (entry.gitBranch) metadata.gitBranch = entry.gitBranch;
|
|
244
|
+
if (entry.version) metadata.version = entry.version;
|
|
245
|
+
const usage = msg?.usage;
|
|
246
|
+
if (usage) {
|
|
247
|
+
if (usage.input_tokens) metadata.inputTokens = usage.input_tokens;
|
|
248
|
+
if (usage.output_tokens) metadata.outputTokens = usage.output_tokens;
|
|
249
|
+
if (usage.cache_read_input_tokens) metadata.cacheReadTokens = usage.cache_read_input_tokens;
|
|
250
|
+
if (usage.cache_creation_input_tokens)
|
|
251
|
+
metadata.cacheCreationTokens = usage.cache_creation_input_tokens;
|
|
252
|
+
}
|
|
253
|
+
const toolUseNames = extractToolUseNames(msg?.content);
|
|
254
|
+
if (toolUseNames.length > 0) metadata.toolUses = toolUseNames;
|
|
255
|
+
if (toolUseBlocks.length > 0) metadata.toolUseBlocks = toolUseBlocks;
|
|
256
|
+
if (isToolResultOnly) {
|
|
257
|
+
const pending = new Map(Object.entries(state.pendingToolUses));
|
|
258
|
+
const toolResultBlocks = extractToolResultBlocks(msg?.content, pending);
|
|
259
|
+
if (toolResultBlocks.length > 0) {
|
|
260
|
+
metadata.toolResults = toolResultBlocks;
|
|
261
|
+
for (const block of toolResultBlocks) delete state.pendingToolUses[block.toolUseId];
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (entry.teamName) {
|
|
265
|
+
metadata.teamName = entry.teamName;
|
|
266
|
+
if (!state.teamInfo[metadata.teamName] && content) {
|
|
267
|
+
const info = parseTeammateMessageTag(content);
|
|
268
|
+
if (info) state.teamInfo[metadata.teamName] = info;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
const thinkingContent = thinking?.content || void 0;
|
|
272
|
+
const thinkingSignature = thinking?.signature || void 0;
|
|
273
|
+
const hasMetadata = Object.keys(metadata).length > 0;
|
|
274
|
+
return {
|
|
275
|
+
role: type,
|
|
276
|
+
text: content || "",
|
|
277
|
+
timestamp: entry.timestamp || "",
|
|
278
|
+
uuid: entry.uuid || void 0,
|
|
279
|
+
metadata: hasMetadata ? metadata : void 0,
|
|
280
|
+
isToolResult: isToolResultOnly || void 0,
|
|
281
|
+
isThinking: thinkingContent || thinkingSignature ? true : void 0,
|
|
282
|
+
thinkingContent,
|
|
283
|
+
thinkingSignature,
|
|
284
|
+
parentUuid: entry.parentUuid !== void 0 ? entry.parentUuid : void 0,
|
|
285
|
+
requestId: type === "assistant" ? entry.requestId : void 0,
|
|
286
|
+
promptId: type === "user" ? entry.promptId : void 0,
|
|
287
|
+
isSidechain: typeof entry.isSidechain === "boolean" ? entry.isSidechain : void 0,
|
|
288
|
+
permissionMode: type === "user" ? entry.permissionMode : void 0,
|
|
289
|
+
hasImages: hasImageBlocks(msg?.content) || void 0,
|
|
290
|
+
attachment: entry.attachment !== void 0 ? entry.attachment : void 0,
|
|
291
|
+
isCompactSummary: isCompactSummary || void 0,
|
|
292
|
+
compaction
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
function parseJsonlLine(line, state = initialConvState()) {
|
|
296
|
+
const text = line.trimEnd();
|
|
297
|
+
if (text.trim().length === 0) return null;
|
|
298
|
+
let entry;
|
|
299
|
+
try {
|
|
300
|
+
entry = JSON.parse(text);
|
|
301
|
+
} catch {
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
return reduceConvLine(state, entry);
|
|
305
|
+
}
|
|
306
|
+
export {
|
|
307
|
+
cleanSystemTags,
|
|
308
|
+
initialConvState as createJsonlParseState,
|
|
309
|
+
parseJsonlLine
|
|
310
|
+
};
|
|
311
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -0,0 +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,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7C,QAAM,oBAAoB,UAAU,aAAa;AACjD,QAAM,cAAc,OAAO,KAAK,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":[]}
|
package/dist/parser.d.ts
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
1
|
-
import type { ContentTier, Conversation, ConversationMeta,
|
|
2
|
-
export
|
|
1
|
+
import type { ContentTier, Conversation, ConversationMeta, TurnDuration } from "./types";
|
|
2
|
+
export { asQueuedPromptUserEntry, extractTextContent, extractThinking, extractToolResultBlocks, extractToolUseBlocks, extractToolUseNames, hasImageBlocks, isOnlyToolResultContent, parseTeammateMessageTag, } from "./parse-helpers";
|
|
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>;
|
|
6
|
-
export declare function extractTextContent(content: unknown): string;
|
|
7
|
-
export declare function extractToolUseNames(content: unknown): string[];
|
|
8
|
-
export declare function extractToolUseBlocks(content: unknown): ToolUseBlock[];
|
|
9
|
-
export declare function extractToolResultBlocks(content: unknown, pendingToolUses: Map<string, ToolUseBlock>): ToolResultBlock[];
|
|
10
6
|
export declare function collectToolNames(content: unknown, toolSet: Set<string>): void;
|
|
11
|
-
export declare function isOnlyToolResultContent(content: unknown): boolean;
|
|
12
|
-
export declare function extractThinking(content: unknown): {
|
|
13
|
-
content: string;
|
|
14
|
-
signature: string;
|
|
15
|
-
};
|
|
16
|
-
export declare function hasImageBlocks(content: unknown): boolean;
|
|
17
|
-
export declare function parseTeammateMessageTag(content: string): TeamInfo | null;
|
|
18
7
|
export declare function getShortProjectName(fullPath: string): string;
|
|
19
8
|
//# sourceMappingURL=parser.d.ts.map
|
package/dist/parser.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EAEZ,gBAAgB,EAChB,YAAY,EACb,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EAClB,eAAe,EACf,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,cAAc,EACd,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,iBAAiB,CAAC;AAGzB,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY,GAAG,IAAI,CAalF;AAID,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,WAAW,EACjB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,GACjD,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAuClC;AAED,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAwE9B;AAID,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,CAO7E;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG5D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threadbase-sh/scanner",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "Unified Claude Code conversation history scanner",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -36,6 +36,11 @@
|
|
|
36
36
|
"import": "./dist/index.js",
|
|
37
37
|
"require": "./dist/index.cjs"
|
|
38
38
|
},
|
|
39
|
+
"./parse": {
|
|
40
|
+
"types": "./dist/parse.d.ts",
|
|
41
|
+
"import": "./dist/parse.js",
|
|
42
|
+
"require": "./dist/parse.cjs"
|
|
43
|
+
},
|
|
39
44
|
"./package.json": "./package.json"
|
|
40
45
|
},
|
|
41
46
|
"publishConfig": {
|
|
@@ -48,7 +53,7 @@
|
|
|
48
53
|
"node": ">=22"
|
|
49
54
|
},
|
|
50
55
|
"scripts": {
|
|
51
|
-
"build": "tsup && tsc -p tsconfig.build.json",
|
|
56
|
+
"build": "tsup && tsc -p tsconfig.build.json && node scripts/check-parse-entry.mjs",
|
|
52
57
|
"prepare": "npm run build",
|
|
53
58
|
"dev": "tsup --watch",
|
|
54
59
|
"test": "vitest run",
|