@trazum/cli 1.68.0 → 1.69.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trazum/cli",
3
- "version": "1.68.0",
3
+ "version": "1.69.0",
4
4
  "description": "Trazum CLI: find where your LLM bill goes, price every finding per month, and enforce token budgets in CI.",
5
5
  "license": "MIT",
6
6
  "author": "David Mu\u00f1oz Rey",
@@ -37,7 +37,7 @@
37
37
  "prepublishOnly": "npm run build && npm test"
38
38
  },
39
39
  "dependencies": {
40
- "@trazum/core": "1.68.0"
40
+ "@trazum/core": "1.69.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/node": "^26.2.0",
package/src/i18n/en.ts CHANGED
@@ -59,6 +59,7 @@ ${bold('USAGE')}
59
59
  trazum schema <contract>
60
60
  trazum rollup <document...|dir> [--json] [--html-out <file>]
61
61
  trazum position <usage.jsonl>
62
+ trazum from-claude-code <file|dir> [--label <name>] [-o <file>]
62
63
  trazum pulse [--max-stale-hours <n>]
63
64
  trazum bench [--workload <id>] [--record <file>] [--against <file> --max-ratio <n>] [--json]
64
65
  trazum write [--answers <file>] [--json] [-o <file>]
@@ -136,6 +137,20 @@ ${bold('OPTIONS FOR write')}
136
137
  --calls <n> Calls per month, for the estimate.
137
138
  --avg-output <n> Average output tokens per call, for the estimate.
138
139
 
140
+ ${bold('OPTIONS FOR from-claude-code')}
141
+ --label <name> Stamp every record with one label.
142
+ --label-from-project Label each record with its transcript's project
143
+ directory name, verbatim — map it to a workload
144
+ name with the config's \`labels\` block.
145
+ -o, --out <file> Write the usage log there instead of stdout.
146
+
147
+ Claude Code's transcripts, read as a usage log: model, timestamp, session
148
+ and the API's own usage object — the cache TTL split included — and
149
+ nothing else. No message text, no paths, no branches cross the
150
+ conversion. One API call is written as one line per content block, so
151
+ lines are collapsed by request id; what was collapsed or passed over is
152
+ said on stderr, never silently.
153
+
139
154
  ${bold('OPTIONS FOR position')}
140
155
  --html-out <file> The position as one self-contained page — the
141
156
  same sentences the terminal prints, caveats
@@ -1598,6 +1613,19 @@ ${bold('EXAMPLES')}
1598
1613
  },
1599
1614
  },
1600
1615
 
1616
+ fromClaudeCode: {
1617
+ noPath: () => 'from-claude-code needs a transcript file or directory: trazum from-claude-code ~/.claude/projects',
1618
+ notFound: (path) => `${path}: not found`,
1619
+ noTranscripts: (path) => `${path}: no .jsonl transcripts under it. Claude Code writes them per session under ~/.claude/projects/<project>/.`,
1620
+ summary: (files, records) => `${files} transcript(s), ${records} priced call(s).`,
1621
+ collapsed: (lines) => `${lines} extra line(s) of already-counted calls collapsed — one API call is written as one line per content block, and counting each line would overbill.`,
1622
+ streamed: (count) => `${count} call(s) were written while still streaming; the final line's counts stood.`,
1623
+ disagreements: (count) => `${count} call(s) had lines that disagreed beyond streaming growth — a count shrank, or another field changed. The last line stood, but that is a finding: worth a look at the transcript.`,
1624
+ noRequestId: (count) => `${count} call(s) carried no request id, so nothing could be collapsed against them; each is priced as recorded.`,
1625
+ skipped: (other, unparseable, withoutUsage) => `Passed over: ${other} non-assistant line(s) (the transcript's other business), ${unparseable} unparseable, ${withoutUsage} assistant line(s) without usage.`,
1626
+ written: (file) => `Wrote ${file}.`,
1627
+ },
1628
+
1601
1629
  position: {
1602
1630
  heading: (month) => `Where ${month} stands, measured`,
1603
1631
  scopeMonth: () => 'the month',
package/src/i18n/es.ts CHANGED
@@ -1612,6 +1612,19 @@ ${bold('EJEMPLOS')}
1612
1612
  },
1613
1613
  },
1614
1614
 
1615
+ fromClaudeCode: {
1616
+ noPath: () => 'from-claude-code necesita un archivo o directorio de transcripts: trazum from-claude-code ~/.claude/projects',
1617
+ notFound: (path) => `${path}: no existe`,
1618
+ noTranscripts: (path) => `${path}: no hay transcripts .jsonl debajo. Claude Code los escribe por sesión en ~/.claude/projects/<proyecto>/.`,
1619
+ summary: (files, records) => `${files} transcript(s), ${records} llamada(s) tasadas.`,
1620
+ collapsed: (lines) => `${lines} línea(s) extra de llamadas ya contadas colapsadas — una llamada a la API se escribe como una línea por bloque de contenido, y contar cada línea sobrefacturaría.`,
1621
+ streamed: (count) => `${count} llamada(s) se escribieron aún en streaming; quedaron los recuentos de la línea final.`,
1622
+ disagreements: (count) => `${count} llamada(s) tenían líneas en desacuerdo más allá del crecimiento del streaming — un recuento encogió, u otro campo cambió. Se quedó la última línea, pero es un hallazgo: merece un vistazo al transcript.`,
1623
+ noRequestId: (count) => `${count} llamada(s) sin id de petición, así que nada pudo colapsarse contra ellas; cada una se tasa tal como quedó registrada.`,
1624
+ skipped: (other, unparseable, withoutUsage) => `Omitidas: ${other} línea(s) no-assistant (el resto del negocio del transcript), ${unparseable} imparseables, ${withoutUsage} línea(s) assistant sin usage.`,
1625
+ written: (file) => `Escrito ${file}.`,
1626
+ },
1627
+
1615
1628
  position: {
1616
1629
  heading: (month) => `Dónde está ${month}, medido`,
1617
1630
  scopeMonth: () => 'el mes',
package/src/i18n/types.ts CHANGED
@@ -518,6 +518,26 @@ export interface CliMessages {
518
518
  caveat(code: string): string;
519
519
  };
520
520
 
521
+ /**
522
+ * `trazum from-claude-code` — transcripts as a usage log. The summary is
523
+ * the command's honesty: what was priced, what was collapsed (one API
524
+ * call arrives as one line per content block), and what was passed over.
525
+ */
526
+ fromClaudeCode: {
527
+ noPath(): string;
528
+ notFound(path: string): string;
529
+ noTranscripts(path: string): string;
530
+ summary(files: number, records: number): string;
531
+ collapsed(lines: number): string;
532
+ /** Calls written while still streaming; the final line's counts stood. */
533
+ streamed(count: number): string;
534
+ /** Lines of one request disagreed beyond streaming growth. A finding. */
535
+ disagreements(count: number): string;
536
+ noRequestId(count: number): string;
537
+ skipped(other: number, unparseable: number, withoutUsage: number): string;
538
+ written(file: string): string;
539
+ };
540
+
521
541
  position: {
522
542
  /** `Where 2026-08 stands, measured` — the month is data, not prose. */
523
543
  heading(month: string): string;
package/src/index.ts CHANGED
@@ -110,6 +110,7 @@ import {
110
110
  indexUsage,
111
111
  parseUsageLine,
112
112
  plannedCalls,
113
+ claudeCodeRecords,
113
114
  positionAt,
114
115
  positionReport,
115
116
  PRICING_LAST_REVIEWED,
@@ -668,6 +669,7 @@ const COMMAND_FLAGS: Record<string, string[]> = {
668
669
  schema: [],
669
670
  rollup: ['json', 'html-out'],
670
671
  position: ['json', 'html-out', 'pricing', 'pricing-live'],
672
+ 'from-claude-code': ['label', 'label-from-project', 'out', 'o'],
671
673
  pulse: ['json', 'max-stale-hours'],
672
674
  bench: ['workload', 'json', 'record', 'against', 'max-ratio'],
673
675
  write: ['answers', 'json', 'out', 'o', 'calls', 'avg-output'],
@@ -2549,6 +2551,90 @@ async function commandWrite(args: Args, t: CliMessages): Promise<void> {
2549
2551
  }
2550
2552
  }
2551
2553
 
2554
+ /**
2555
+ * `trazum from-claude-code <file|dir>` — transcripts as a usage log.
2556
+ *
2557
+ * The conversion is `claudeCodeRecords` in core, and this command is only
2558
+ * the walk and the honesty: every transcript under an explicit path (never
2559
+ * a silent default reach into somebody's home), the records on stdout or
2560
+ * `-o`, and a stderr summary of what was collapsed — one API call arrives
2561
+ * as one line per content block, and counting lines would overbill by a
2562
+ * third on a real session — and what was passed over. No message text, no
2563
+ * `cwd`, no branch name crosses the conversion; the suite plants one of
2564
+ * each in a fixture and greps the whole output for them.
2565
+ */
2566
+ async function commandFromClaudeCode(args: Args, t: CliMessages): Promise<void> {
2567
+ const target = args.positional[0];
2568
+ if (target === undefined) throw new Error(t.fromClaudeCode.noPath());
2569
+
2570
+ let info;
2571
+ try {
2572
+ info = await stat(target);
2573
+ } catch {
2574
+ throw new Error(t.fromClaudeCode.notFound(target));
2575
+ }
2576
+ const files: string[] = [];
2577
+ if (info.isDirectory()) {
2578
+ const entries = await readdir(target, { recursive: true, withFileTypes: true });
2579
+ for (const entry of entries) {
2580
+ if (entry.isFile() && entry.name.endsWith('.jsonl')) {
2581
+ files.push(join(entry.parentPath, entry.name));
2582
+ }
2583
+ }
2584
+ files.sort();
2585
+ if (files.length === 0) throw new Error(t.fromClaudeCode.noTranscripts(target));
2586
+ } else {
2587
+ files.push(target);
2588
+ }
2589
+
2590
+ const label = stringFlag(args, 'label');
2591
+ const labelFromProject = boolFlag(args, 'label-from-project');
2592
+ const lines: string[] = [];
2593
+ let records = 0;
2594
+ let collapsed = 0;
2595
+ let noRequestId = 0;
2596
+ let otherLines = 0;
2597
+ let unparseable = 0;
2598
+ let withoutUsage = 0;
2599
+ let streamed = 0;
2600
+ let disagreements = 0;
2601
+ for (const file of files) {
2602
+ const text = await readFile(file, 'utf8');
2603
+ const projectLabel = labelFromProject ? dirname(resolvePath(file)).split('/').pop() : undefined;
2604
+ const conversion = claudeCodeRecords(text, {
2605
+ ...(label !== undefined
2606
+ ? { label }
2607
+ : projectLabel !== undefined && projectLabel !== ''
2608
+ ? { label: projectLabel }
2609
+ : {}),
2610
+ });
2611
+ for (const record of conversion.records) lines.push(JSON.stringify(record));
2612
+ records += conversion.records.length;
2613
+ collapsed += conversion.collapsed;
2614
+ noRequestId += conversion.noRequestId;
2615
+ otherLines += conversion.otherLines;
2616
+ unparseable += conversion.unparseable;
2617
+ withoutUsage += conversion.assistantWithoutUsage;
2618
+ streamed += conversion.streamed;
2619
+ disagreements += conversion.disagreements;
2620
+ }
2621
+
2622
+ const out = stringFlag(args, 'out') ?? stringFlag(args, 'o');
2623
+ if (out !== undefined) {
2624
+ await writeFile(out, lines.join('\n') + (lines.length > 0 ? '\n' : ''), 'utf8');
2625
+ console.error(t.fromClaudeCode.written(out));
2626
+ } else {
2627
+ for (const line of lines) console.log(line);
2628
+ }
2629
+
2630
+ console.error(t.fromClaudeCode.summary(files.length, records));
2631
+ if (collapsed > 0) console.error(t.fromClaudeCode.collapsed(collapsed));
2632
+ if (streamed > 0) console.error(t.fromClaudeCode.streamed(streamed));
2633
+ if (disagreements > 0) console.error(t.fromClaudeCode.disagreements(disagreements));
2634
+ if (noRequestId > 0) console.error(t.fromClaudeCode.noRequestId(noRequestId));
2635
+ console.error(t.fromClaudeCode.skipped(otherLines, unparseable, withoutUsage));
2636
+ }
2637
+
2552
2638
  /**
2553
2639
  * `trazum position <usage.jsonl>` — where the month stands, measured.
2554
2640
  *
@@ -10940,6 +11026,9 @@ async function main(): Promise<void> {
10940
11026
  case 'position':
10941
11027
  await commandPosition(args, config, pricing, t);
10942
11028
  break;
11029
+ case 'from-claude-code':
11030
+ await commandFromClaudeCode(args, t);
11031
+ break;
10943
11032
  case 'pulse':
10944
11033
  await commandPulse(args, t);
10945
11034
  break;