curt-convert 0.0.0-stage → 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jordan Newell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,119 @@
1
- # Temporary Holding Version
1
+ # curt-convert
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Convert Claude Code session transcripts (`.jsonl`) into
4
+ [`.curt`](https://github.com/JordanNewell/dot_curt) single-file conversation
5
+ format. Built on [`curt-format`](https://www.npmjs.com/package/curt-format)
6
+ (reference implementation, v1 core).
7
+
8
+ > **Warning: output is transcript-equivalent.** Conversion is faithful, not
9
+ > redacting: if the transcript contains secrets (API keys, tokens, hostnames,
10
+ > private paths, unreleased code), the `.curt` file contains them too. Do not
11
+ > share, commit, or publish `.curt` output without scrubbing it first. The
12
+ > fixtures in `test/fixtures/` are fully synthetic; no real transcript content
13
+ > is committed to this repo.
14
+
15
+ ```sh
16
+ npm install -g curt-convert # or: npx curt-convert
17
+ curt-convert C:/Users/you/.claude/projects/C--tmp-demo/abc-123.jsonl
18
+ curt-convert C:/Users/you/.claude/projects/C--tmp-demo/ -o ./out
19
+ curt-convert "**/*.jsonl" -o ./out
20
+ curt-convert session.jsonl --stdout > session.curt
21
+ ```
22
+
23
+ - A `.jsonl` file, a directory (walked recursively), or a glob all work.
24
+ - Output defaults to alongside each input; `-o/--out` redirects to a directory.
25
+ - Output file names follow the Curtis bulk convention
26
+ (`YYYY-MM-DD <slug> <suffix>.curt`) via `curtFilename()`.
27
+ - Bulk runs never overwrite: when two inputs produce the same output name
28
+ (parent sessions and their sidechain files share a `sessionId`), later
29
+ inputs get a deterministic `-<6 hex>` suffix derived from the source file
30
+ path — stable across runs, no randomness.
31
+ - Every file is re-parsed with `parseCurt` before it is written; a file that
32
+ fails round-trip validation is never written (set `CURT_CONVERT_SELFCHECK=0`
33
+ to skip).
34
+
35
+ ## Mapping
36
+
37
+ | Claude Code JSONL | .curt | Notes |
38
+ |---|---|---|
39
+ | `sessionId` | `conversation.id` | Falls back to the file stem. |
40
+ | `ai-title` line `aiTitle` | `conversation.title` | Last one wins; otherwise first user text (<= 60 chars). |
41
+ | first/last kept message `timestamp` | `conversation.createdAt` / `updatedAt` | ISO 8601 -> epoch milliseconds. |
42
+ | `"model"` on assistant messages | `conversation.model` + per-message `model` | Most frequent model wins at conversation level. |
43
+ | — | `conversation.provider` | Always `"anthropic"`. |
44
+ | `cwd`, `gitBranch`, `version` | `conversation.cwd` / `gitBranch` / `claudeCodeVersion` | Extra fields; readers ignore unknowns. |
45
+ | entry `type: "user"`, string `message.content` | message `{ role: "user" }` | `<system-reminder>...</system-reminder>` spans are stripped (harness-injected, not user content). |
46
+ | `message.content[]` block `type: "text"` | `content` (blocks joined with `\n\n`) | On user and assistant messages. |
47
+ | `message.content[]` block `type: "tool_use"` (`id`, `name`, `input`) | `message.toolCalls[] = { id, name, arguments }` | Declares the `tool-linkage` extension on the conversation. |
48
+ | `message.content[]` block `type: "tool_result"` (`tool_use_id`, `content`) | separate message `{ role: "tool", toolCallId }` | Text content lands in `content`; per `tool-linkage`, `toolCallId` references `toolCalls[].id`. |
49
+ | tool_result non-text blocks (images, ...) | message extra field `nonTextContent` | Structured passthrough; the base64 payload survives verbatim. |
50
+ | tool_result `is_error: true` | message extra field `isError: true` | |
51
+ | `type: "assistant"`, `thinking` blocks | message extra field `thinking` | Kept out of `content` (model-internal); opaque `signature` dropped. |
52
+ | `server_tool_use` blocks (web search) | mapped into `toolCalls` like any call | Results for these often have no `tool_use_id` result line; counted as unlinked. |
53
+ | entry `uuid` | message `id` | Synthesized `"<file-stem>-<n>"` when absent. |
54
+ | `isSidechain: true` (subagent turns) | message extra field `isSidechain: true` | Kept, flagged — not dropped. |
55
+ | `isApiErrorMessage: true` | dropped | Failed API calls are not conversation. |
56
+ | `isMeta: true`, `isVisibleInTranscriptOnly` | dropped | Caveat banners and transcript-only echoes. |
57
+
58
+ Lines with any other `type` are noise and dropped: `summary`, `system`,
59
+ `attachment`, `queue-operation`, `ai-title` (read for the title, then dropped),
60
+ `mode`, `permission-mode`, `cost-state`, `file-history-snapshot`,
61
+ `file-history-delta`, `agent-setting`, `atis-latch`, `last-prompt`,
62
+ `agent-name`, `api-request*`, `pr-link`, `fork-context-ref`, `started`,
63
+ `result`, `failed`, `launched`, `continued-in`, and anything unrecognized.
64
+ Unparseable lines are counted in stats, never fatal. User/assistant entries
65
+ that end up with no content at all (whitespace-only text, reminder-only user
66
+ turns, assistant entries with empty block arrays) are skipped too and counted
67
+ as meta, not conversation.
68
+
69
+ ## Documented losses
70
+
71
+ - Token counts and cost (`message.usage`, `cost-state` lines) — dropped.
72
+ - `toolUseResult` on user entries — a client-side debug mirror of tool output,
73
+ not the wire payload; dropped (the `tool_result` block is the source).
74
+ - Thinking block `signature` (opaque verifier) — dropped; the thinking *text*
75
+ is kept on the message.
76
+ - `parentUuid` / `sourceToolAssistantUUID` chain — dropped; ordering is the
77
+ JSONL line order, and call/result linkage rides `tool-linkage` ids instead.
78
+ - `<system-reminder>` spans inside user text — stripped as harness chatter.
79
+ - Summaries, attachments, file-history snapshots, PR links, cost state —
80
+ these lines have no `.curt` counterpart and are dropped entirely.
81
+ - Envelope-top-level extras beyond `curt`/`version`/`generator`/
82
+ `conversation` are not carried from a *read* `.curt` file (this tool only
83
+ writes). Unknown fields inside the conversation and its messages are
84
+ preserved where possible by conforming readers, but preservation is not
85
+ guaranteed normatively by the spec.
86
+
87
+ ## The `tool-linkage` extension
88
+
89
+ When the transcript contains any tool calls, the output declares
90
+ `extensions: ["tool-linkage"]` and uses its field contract: assistant messages
91
+ carry `toolCalls[] = { id, name, arguments }`, and each tool result is its own
92
+ `role: "tool"` message with `toolCallId` referencing `toolCalls[].id`.
93
+ Readers that do not know the extension ignore these fields; the v1 core
94
+ still validates.
95
+
96
+ ## Security
97
+
98
+ See the warning at the top of this README: `.curt` output is
99
+ transcript-equivalent. Conversion adds nothing and removes only harness
100
+ chatter (`<system-reminder>` spans, meta/noise lines) — everything else in
101
+ the conversation, including anything sensitive that was in the session,
102
+ survives verbatim. Scrub before sharing.
103
+
104
+ ## Development
105
+
106
+ ```sh
107
+ npm i
108
+ npm test # vitest, 30 tests
109
+ npm run build # tsc -> dist/
110
+ ```
111
+
112
+ ## Part of the .curt suite
113
+
114
+ - [`curt-format`](https://github.com/JordanNewell/dot_curt) — the .curt format spec + reference implementation ([npm](https://www.npmjs.com/package/curt-format))
115
+ - [`curt-convert`](https://github.com/JordanNewell/curt-convert) — Claude Code transcripts → .curt ([npm](https://www.npmjs.com/package/curt-convert))
116
+ - [`curt-vcon`](https://github.com/JordanNewell/curt-vcon) — .curt ⇄ vCon (IETF) bridge ([npm](https://www.npmjs.com/package/curt-vcon))
117
+ - [`curt-wildchat`](https://github.com/JordanNewell/curt-wildchat) — WildChat-1M records → .curt ([npm](https://www.npmjs.com/package/curt-wildchat))
118
+
119
+ MIT — see [LICENSE](LICENSE).
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ /** curt-convert CLI: Claude Code JSONL transcripts -> .curt files. */
3
+ export {};
package/dist/cli.js ADDED
Binary file
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Convert Claude Code session transcripts (JSONL) to .curt conversations.
3
+ *
4
+ * Observed JSONL schema (Claude Code ~1.x–2.x, corpus of 1167 sessions):
5
+ * - Line types kept: `user`, `assistant` (conversation turns).
6
+ * - Line types treated as noise and dropped: `summary`, `system`,
7
+ * `attachment`, `queue-operation`, `ai-title`, `mode`, `permission-mode`,
8
+ * `cost-state`, `file-history-snapshot`, `file-history-delta`,
9
+ * `agent-setting`, `atis-latch`, `last-prompt`, `agent-name`,
10
+ * `api-request*`, `pr-link`, `fork-context-ref`, `started`, `result`,
11
+ * `failed`, `launched`, `continued-in`, and anything unrecognized.
12
+ * - `user` entries: `message.content` is a plain string, or a block array of
13
+ * `text` / `tool_result` blocks. Noise flags: `isMeta: true`,
14
+ * `isVisibleInTranscriptOnly`. `toolUseResult` is a debug mirror of the
15
+ * tool output (not the wire payload) and is not used.
16
+ * - `assistant` entries: `message.content` is a block array of `text`,
17
+ * `thinking` (`thinking` + opaque `signature`), `tool_use` (`id`, `name`,
18
+ * `input`), rarely `server_tool_use`, rarely `tool_result`.
19
+ * `message.usage` carries token counts (dropped).
20
+ */
21
+ import { type CurtConversation } from "curt-format";
22
+ export declare const GENERATOR = "curt-convert@1.0.0";
23
+ /** Extension used to link tool calls to their results (see EXTENSIONS.md). */
24
+ export declare const TOOL_LINKAGE = "tool-linkage";
25
+ export interface ConvertStats {
26
+ /** Conversation turns and tool-result messages emitted. */
27
+ messages: number;
28
+ toolCalls: number;
29
+ toolResults: number;
30
+ /** tool_result blocks with no matching tool_use id in any prior call. */
31
+ unlinkedToolResults: number;
32
+ /** Lines dropped because of their `type` (summaries, attachments, ...). */
33
+ skippedNoise: number;
34
+ /** user/assistant lines dropped (`isMeta`, API errors, empty content). */
35
+ skippedMeta: number;
36
+ /** Lines that failed JSON.parse. */
37
+ parseErrors: number;
38
+ }
39
+ export interface ConvertResult {
40
+ conversation: CurtConversation;
41
+ stats: ConvertStats;
42
+ }
43
+ /** ISO timestamp -> epoch ms; 0 when missing/unparseable. */
44
+ export declare function parseTimestamp(v: unknown): number;
45
+ /**
46
+ * Claude Code injects harness chatter into user text via
47
+ * `<system-reminder>...</system-reminder>` spans. These are not user
48
+ * content; strip them (documented loss).
49
+ */
50
+ export declare function stripSystemReminders(text: string): string;
51
+ /**
52
+ * Convert one JSONL transcript body into a .curt conversation.
53
+ * `fallbackId` is used when the transcript carries no `sessionId`.
54
+ */
55
+ export declare function convertTranscript(raw: string, fallbackId?: string): ConvertResult;
56
+ /** Serialize a converted conversation as a complete .curt file body. */
57
+ export declare function serializeResult(result: ConvertResult): string;
58
+ /**
59
+ * Deterministic, collision-free output filename for a bulk run.
60
+ *
61
+ * `curtFilename` derives its name from `createdAt` + `conversation.id`, and
62
+ * parent sessions share their `sessionId` with sidechain (subagent) JSONL
63
+ * files, so different inputs can produce identical names and silently
64
+ * overwrite. The first occurrence keeps the plain `curtFilename` output;
65
+ * later ones get a `-<6 hex>` discriminator derived from a SHA-256 of the
66
+ * source file's absolute path — stable across runs, no timestamps or
67
+ * randomness. SPEC.md's naming rule is a convention (readers must not depend
68
+ * on file names), so the suffixed name stays spec-compatible.
69
+ */
70
+ export declare function resolveOutputName(base: string, sourcePath: string, seen: Set<string>): string;
@@ -0,0 +1,323 @@
1
+ /**
2
+ * Convert Claude Code session transcripts (JSONL) to .curt conversations.
3
+ *
4
+ * Observed JSONL schema (Claude Code ~1.x–2.x, corpus of 1167 sessions):
5
+ * - Line types kept: `user`, `assistant` (conversation turns).
6
+ * - Line types treated as noise and dropped: `summary`, `system`,
7
+ * `attachment`, `queue-operation`, `ai-title`, `mode`, `permission-mode`,
8
+ * `cost-state`, `file-history-snapshot`, `file-history-delta`,
9
+ * `agent-setting`, `atis-latch`, `last-prompt`, `agent-name`,
10
+ * `api-request*`, `pr-link`, `fork-context-ref`, `started`, `result`,
11
+ * `failed`, `launched`, `continued-in`, and anything unrecognized.
12
+ * - `user` entries: `message.content` is a plain string, or a block array of
13
+ * `text` / `tool_result` blocks. Noise flags: `isMeta: true`,
14
+ * `isVisibleInTranscriptOnly`. `toolUseResult` is a debug mirror of the
15
+ * tool output (not the wire payload) and is not used.
16
+ * - `assistant` entries: `message.content` is a block array of `text`,
17
+ * `thinking` (`thinking` + opaque `signature`), `tool_use` (`id`, `name`,
18
+ * `input`), rarely `server_tool_use`, rarely `tool_result`.
19
+ * `message.usage` carries token counts (dropped).
20
+ */
21
+ import { createHash } from "node:crypto";
22
+ import { serializeCurt, } from "curt-format";
23
+ export const GENERATOR = "curt-convert@1.0.0";
24
+ /** Extension used to link tool calls to their results (see EXTENSIONS.md). */
25
+ export const TOOL_LINKAGE = "tool-linkage";
26
+ function isObj(v) {
27
+ return typeof v === "object" && v !== null && !Array.isArray(v);
28
+ }
29
+ function asString(v) {
30
+ return typeof v === "string" ? v : undefined;
31
+ }
32
+ /** ISO timestamp -> epoch ms; 0 when missing/unparseable. */
33
+ export function parseTimestamp(v) {
34
+ if (typeof v !== "string")
35
+ return 0;
36
+ const ms = Date.parse(v);
37
+ return Number.isFinite(ms) ? ms : 0;
38
+ }
39
+ /**
40
+ * Claude Code injects harness chatter into user text via
41
+ * `<system-reminder>...</system-reminder>` spans. These are not user
42
+ * content; strip them (documented loss).
43
+ */
44
+ export function stripSystemReminders(text) {
45
+ return text.replace(/<system-reminder>[\s\S]*?<\/system-reminder>/g, "").trim();
46
+ }
47
+ /** Extract plain text from a tool_result `content` (string or block array). */
48
+ function toolResultText(content) {
49
+ if (typeof content === "string")
50
+ return { text: content, nonText: [] };
51
+ if (Array.isArray(content)) {
52
+ const nonText = [];
53
+ const parts = [];
54
+ for (const b of content) {
55
+ if (typeof b === "string") {
56
+ parts.push(b);
57
+ }
58
+ else if (isObj(b) && b.type === "text" && typeof b.text === "string") {
59
+ parts.push(b.text);
60
+ }
61
+ else if (isObj(b)) {
62
+ nonText.push(b);
63
+ }
64
+ }
65
+ return { text: parts.join("\n"), nonText };
66
+ }
67
+ return { text: "", nonText: [] };
68
+ }
69
+ function titleFrom(text) {
70
+ const flat = text.replace(/\s+/g, " ").trim();
71
+ return flat.length > 60 ? `${flat.slice(0, 57)}...` : flat;
72
+ }
73
+ function mode(values) {
74
+ const counts = new Map();
75
+ for (const v of values)
76
+ counts.set(v, (counts.get(v) ?? 0) + 1);
77
+ let best;
78
+ let n = 0;
79
+ for (const [v, c] of counts) {
80
+ if (c > n) {
81
+ best = v;
82
+ n = c;
83
+ }
84
+ }
85
+ return best;
86
+ }
87
+ /**
88
+ * Convert one JSONL transcript body into a .curt conversation.
89
+ * `fallbackId` is used when the transcript carries no `sessionId`.
90
+ */
91
+ export function convertTranscript(raw, fallbackId = "session") {
92
+ const stats = {
93
+ messages: 0,
94
+ toolCalls: 0,
95
+ toolResults: 0,
96
+ unlinkedToolResults: 0,
97
+ skippedNoise: 0,
98
+ skippedMeta: 0,
99
+ parseErrors: 0,
100
+ };
101
+ const messages = [];
102
+ let sessionId;
103
+ let title;
104
+ let firstUserText;
105
+ let cwd;
106
+ let gitBranch;
107
+ let cliVersion;
108
+ const models = [];
109
+ const toolCallIds = new Set();
110
+ const lines = raw.split(/\r?\n/);
111
+ for (const line of lines) {
112
+ if (!line.trim())
113
+ continue;
114
+ let entry;
115
+ try {
116
+ entry = JSON.parse(line);
117
+ }
118
+ catch {
119
+ stats.parseErrors++;
120
+ continue;
121
+ }
122
+ if (!isObj(entry)) {
123
+ stats.skippedNoise++;
124
+ continue;
125
+ }
126
+ if (typeof entry.aiTitle === "string") {
127
+ title = entry.aiTitle;
128
+ }
129
+ const type = asString(entry.type);
130
+ if (type !== "user" && type !== "assistant") {
131
+ stats.skippedNoise++;
132
+ continue;
133
+ }
134
+ if (entry.isMeta === true || entry.isVisibleInTranscriptOnly === true) {
135
+ stats.skippedMeta++;
136
+ continue;
137
+ }
138
+ if (type === "assistant" && entry.isApiErrorMessage === true) {
139
+ stats.skippedMeta++;
140
+ continue;
141
+ }
142
+ if (!sessionId && typeof entry.sessionId === "string") {
143
+ sessionId = entry.sessionId;
144
+ }
145
+ if (!cwd && typeof entry.cwd === "string")
146
+ cwd = entry.cwd;
147
+ if (!gitBranch && typeof entry.gitBranch === "string") {
148
+ gitBranch = entry.gitBranch;
149
+ }
150
+ if (!cliVersion && typeof entry.version === "string") {
151
+ cliVersion = entry.version;
152
+ }
153
+ const timestamp = parseTimestamp(entry.timestamp);
154
+ const id = typeof entry.uuid === "string" ? entry.uuid : `${fallbackId}-${messages.length}`;
155
+ const message = (isObj(entry.message) ? entry.message : {});
156
+ if (type === "assistant") {
157
+ if (typeof message.model === "string" && message.model) {
158
+ models.push(message.model);
159
+ }
160
+ const blocks = Array.isArray(message.content)
161
+ ? message.content
162
+ : [];
163
+ const text = [];
164
+ const thinking = [];
165
+ const toolCalls = [];
166
+ for (const b of blocks) {
167
+ if (!isObj(b))
168
+ continue;
169
+ if (b.type === "text" && typeof b.text === "string") {
170
+ text.push(b.text);
171
+ }
172
+ else if (b.type === "thinking" && typeof b.thinking === "string") {
173
+ thinking.push(b.thinking);
174
+ }
175
+ else if ((b.type === "tool_use" || b.type === "server_tool_use") &&
176
+ typeof b.id === "string" &&
177
+ typeof b.name === "string") {
178
+ toolCalls.push({ id: b.id, name: b.name, arguments: b.input ?? null });
179
+ toolCallIds.add(b.id);
180
+ }
181
+ // Assistant-side `tool_result` blocks (rare, seen on retries):
182
+ // kept out; the user-side copy is the canonical result.
183
+ }
184
+ if (text.length === 0 && thinking.length === 0 && toolCalls.length === 0) {
185
+ stats.skippedMeta++;
186
+ continue;
187
+ }
188
+ const msg = {
189
+ id,
190
+ role: "assistant",
191
+ content: text.join("\n\n"),
192
+ timestamp,
193
+ };
194
+ if (typeof message.model === "string" && message.model) {
195
+ msg.model = message.model;
196
+ }
197
+ if (thinking.length > 0)
198
+ msg.thinking = thinking.join("\n\n");
199
+ if (toolCalls.length > 0)
200
+ msg.toolCalls = toolCalls;
201
+ if (entry.isSidechain === true)
202
+ msg.isSidechain = true;
203
+ messages.push(msg);
204
+ stats.toolCalls += toolCalls.length;
205
+ continue;
206
+ }
207
+ // --- user entry ---
208
+ const content = message.content;
209
+ if (typeof content === "string") {
210
+ const cleaned = stripSystemReminders(content);
211
+ if (!cleaned) {
212
+ stats.skippedMeta++;
213
+ continue;
214
+ }
215
+ messages.push({ id, role: "user", content: cleaned, timestamp });
216
+ firstUserText ??= cleaned;
217
+ continue;
218
+ }
219
+ if (!Array.isArray(content)) {
220
+ stats.skippedMeta++;
221
+ continue;
222
+ }
223
+ const userText = [];
224
+ let emittedToolResult = false;
225
+ for (const b of content) {
226
+ if (!isObj(b))
227
+ continue;
228
+ if (b.type === "text" && typeof b.text === "string") {
229
+ userText.push(b.text);
230
+ }
231
+ else if (b.type === "tool_result") {
232
+ const callId = asString(b.tool_use_id);
233
+ const { text, nonText } = toolResultText(b.content);
234
+ const toolMsg = {
235
+ id: `${id}-tool`,
236
+ role: "tool",
237
+ content: text,
238
+ timestamp,
239
+ toolCallId: callId ?? "",
240
+ };
241
+ if (b.isError === true)
242
+ toolMsg.isError = true;
243
+ if (nonText.length > 0) {
244
+ toolMsg.nonTextContent = nonText;
245
+ }
246
+ messages.push(toolMsg);
247
+ stats.toolResults++;
248
+ if (callId && toolCallIds.has(callId)) {
249
+ // linked
250
+ }
251
+ else {
252
+ stats.unlinkedToolResults++;
253
+ }
254
+ emittedToolResult = true;
255
+ }
256
+ }
257
+ const userContent = userText.join("\n\n").trim();
258
+ if (userContent) {
259
+ messages.push({ id, role: "user", content: userContent, timestamp });
260
+ firstUserText ??= userContent;
261
+ }
262
+ else if (!emittedToolResult) {
263
+ stats.skippedMeta++;
264
+ }
265
+ }
266
+ const usedToolLinkage = stats.toolCalls > 0;
267
+ if (usedToolLinkage) {
268
+ stats.unlinkedToolResults = messages.filter((m) => m.role === "tool" && !(typeof m.toolCallId === "string" && toolCallIds.has(m.toolCallId))).length;
269
+ }
270
+ const first = messages[0];
271
+ const last = messages[messages.length - 1];
272
+ const fallbackTitle = firstUserText ? titleFrom(firstUserText) : "";
273
+ const conversation = {
274
+ id: sessionId ?? fallbackId,
275
+ title: title ?? fallbackTitle,
276
+ createdAt: first?.timestamp ?? 0,
277
+ updatedAt: last?.timestamp ?? 0,
278
+ messages,
279
+ provider: "anthropic",
280
+ };
281
+ const conversationModel = mode(models);
282
+ if (conversationModel)
283
+ conversation.model = conversationModel;
284
+ if (cwd)
285
+ conversation.cwd = cwd;
286
+ if (gitBranch)
287
+ conversation.gitBranch = gitBranch;
288
+ if (cliVersion)
289
+ conversation.claudeCodeVersion = cliVersion;
290
+ if (usedToolLinkage)
291
+ conversation.extensions = [TOOL_LINKAGE];
292
+ stats.messages = messages.length;
293
+ return { conversation, stats };
294
+ }
295
+ /** Serialize a converted conversation as a complete .curt file body. */
296
+ export function serializeResult(result) {
297
+ return serializeCurt(result.conversation, GENERATOR, result.conversation.extensions);
298
+ }
299
+ /**
300
+ * Deterministic, collision-free output filename for a bulk run.
301
+ *
302
+ * `curtFilename` derives its name from `createdAt` + `conversation.id`, and
303
+ * parent sessions share their `sessionId` with sidechain (subagent) JSONL
304
+ * files, so different inputs can produce identical names and silently
305
+ * overwrite. The first occurrence keeps the plain `curtFilename` output;
306
+ * later ones get a `-<6 hex>` discriminator derived from a SHA-256 of the
307
+ * source file's absolute path — stable across runs, no timestamps or
308
+ * randomness. SPEC.md's naming rule is a convention (readers must not depend
309
+ * on file names), so the suffixed name stays spec-compatible.
310
+ */
311
+ export function resolveOutputName(base, sourcePath, seen) {
312
+ if (!seen.has(base)) {
313
+ seen.add(base);
314
+ return base;
315
+ }
316
+ const hex = createHash("sha256").update(sourcePath).digest("hex");
317
+ const tagged = (n) => base.replace(/\.curt$/, `-${hex.slice(0, n)}.curt`);
318
+ let name = tagged(6);
319
+ if (seen.has(name))
320
+ name = tagged(12);
321
+ seen.add(name);
322
+ return name;
323
+ }
package/package.json CHANGED
@@ -1,6 +1,45 @@
1
1
  {
2
- "name": "curt-convert",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "curt-convert",
3
+ "version": "1.0.2",
4
+ "description": "Convert Claude Code session transcripts (JSONL) to .curt conversation files",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "engines": {
8
+ "node": ">=18"
9
+ },
10
+ "bin": {
11
+ "curt-convert": "dist/cli.js"
12
+ },
13
+ "main": "dist/convert.js",
14
+ "types": "dist/convert.d.ts",
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsc",
20
+ "test": "vitest run",
21
+ "prepack": "npm run build"
22
+ },
23
+ "dependencies": {
24
+ "curt-format": "^1.2.0"
25
+ },
26
+ "devDependencies": {
27
+ "@types/node": "^24.0.0",
28
+ "typescript": "^5.6.0",
29
+ "vitest": "^3.0.0"
30
+ },
31
+ "keywords": [
32
+ "curt",
33
+ "claude-code",
34
+ "transcript",
35
+ "converter"
36
+ ],
37
+ "repository": {
38
+ "url": "https://github.com/JordanNewell/curt-convert.git",
39
+ "type": "git"
40
+ },
41
+ "homepage": "https://github.com/JordanNewell/curt-convert#readme",
42
+ "bugs": {
43
+ "url": "https://github.com/JordanNewell/curt-convert/issues"
44
+ }
45
+ }