@trazum/cli 2.7.5 → 2.7.6

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": "2.7.5",
3
+ "version": "2.7.6",
4
4
  "description": "What your AI agents cost, per project, offline: one bill across Claude Code, Codex and Gemini CLI sessions, plus Anthropic, OpenAI, Gemini, OpenRouter, OTel and LiteLLM usage, written as PDF, HTML or CSV, with budgets enforced in CI.",
5
5
  "license": "MIT",
6
6
  "author": "David Mu\u00f1oz Rey",
@@ -53,7 +53,7 @@
53
53
  "prepublishOnly": "npm run build && npm test"
54
54
  },
55
55
  "dependencies": {
56
- "@trazum/core": "2.7.5"
56
+ "@trazum/core": "2.7.6"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@types/node": "^26.6.6",
package/src/i18n/en.ts CHANGED
@@ -2131,6 +2131,8 @@ ${bold('EXAMPLES')}
2131
2131
  labelledByProject: (files) =>
2132
2132
  `${files} session file(s) labelled by their project folder. --label sets one label instead, --no-label-from-project leaves them unlabelled.`,
2133
2133
  unknownMore: (count) => `${count} more file(s) no shape claims, not guessed at and not in the bill.`,
2134
+ sessionSideFiles: (count) =>
2135
+ `${count} file(s) Claude Code keeps inside its sessions' folders (subagent metadata, workflow journals, long tool output) are not usage, and were passed over.`,
2134
2136
  shapeSummary: (shape, files, records, leftOut) =>
2135
2137
  `${files} file(s): ${shape}${records === null ? ', read as they are' : `, ${records} record(s)`}${leftOut > 0 ? `, ${leftOut} row(s) left out. trazum from-${shape} on a file says why.` : '.'}`,
2136
2138
  statementHeading: () => 'Your bill',
package/src/i18n/es.ts CHANGED
@@ -2161,6 +2161,8 @@ ${bold('EJEMPLOS')}
2161
2161
  labelledByProject: (files) =>
2162
2162
  `${files} archivo(s) de sesión etiquetado(s) por su carpeta de proyecto. --label pone una sola etiqueta, --no-label-from-project los deja sin etiqueta.`,
2163
2163
  unknownMore: (count) => `${count} archivo(s) más que ninguna forma reclama, sin adivinar y fuera de la factura.`,
2164
+ sessionSideFiles: (count) =>
2165
+ `${count} archivo(s) que Claude Code guarda dentro de las carpetas de sus sesiones (metadatos de subagentes, diarios de workflows, salidas largas de herramientas) no son uso, y se han pasado por alto.`,
2164
2166
  shapeSummary: (shape, files, records, leftOut) =>
2165
2167
  `${files} archivo(s): ${shape}${records === null ? ', leídos tal cual' : `, ${records} registro(s)`}${leftOut > 0 ? `, ${leftOut} fila(s) fuera. trazum from-${shape} sobre un archivo dice por qué.` : '.'}`,
2166
2168
  statementHeading: () => 'Tu factura',
package/src/i18n/types.ts CHANGED
@@ -780,6 +780,8 @@ export interface CliMessages {
780
780
  labelledByProject(files: number): string;
781
781
  /** The unclaimed files past the first few, counted rather than listed. */
782
782
  unknownMore(count: number): string;
783
+ /** Files a Claude Code session keeps beside its transcript, inside its own folder: not usage. */
784
+ sessionSideFiles(count: number): string;
783
785
  /** Many files of one shape: one line for the shape, not one per file. */
784
786
  shapeSummary(shape: string, files: number, records: number | null, leftOut: number): string;
785
787
  /** The human statement a terminal gets instead of the JSON receipt. */
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { createHash } from 'node:crypto';
3
- import { readdirSync, readFileSync } from 'node:fs';
3
+ import { existsSync, readdirSync, readFileSync } from 'node:fs';
4
4
  import { mkdir, mkdtemp, open, readdir, readFile, rm, stat, writeFile } from 'node:fs/promises';
5
5
  import type { FileHandle } from 'node:fs/promises';
6
6
  import { cpus, homedir, tmpdir } from 'node:os';
@@ -2815,12 +2815,40 @@ async function commandWrite(args: Args, t: CliMessages): Promise<void> {
2815
2815
  * exists to refuse, and it does not get an exception for being convenient.
2816
2816
  */
2817
2817
  function projectLabelFor(file: string): string | undefined {
2818
- const folder = dirname(resolvePath(file)).split('/').pop();
2818
+ const folder = projectFolderOf(file).split('/').pop();
2819
2819
  if (folder === undefined || folder === '') return undefined;
2820
2820
  const trimmed = folder.replace(/^-+/, '');
2821
2821
  return trimmed !== '' ? trimmed : folder;
2822
2822
  }
2823
2823
 
2824
+ /**
2825
+ * The project folder a transcript belongs to, which is not always its parent.
2826
+ *
2827
+ * A session's own transcript sits in the project folder,
2828
+ * `<project>/<session>.jsonl`, and everything the session spawned sits in a
2829
+ * folder named after it: subagents at `<project>/<session>/subagents/…`,
2830
+ * workflow agents at `<project>/<session>/subagents/workflows/wf_…/…`. The
2831
+ * parent of those is `subagents` or `wf_…`, and labelling by it filed a
2832
+ * session's subagent spend under projects that never existed: measured on
2833
+ * this repository's own transcripts, a quarter of a $569 bill under six
2834
+ * `wf_` names.
2835
+ *
2836
+ * So the folder is found the way Claude Code lays it out, not by a name: the
2837
+ * nearest ancestor that has a transcript of its own name beside it is the
2838
+ * session's folder, and the project is its parent. A transcript with no such
2839
+ * ancestor is a session's own, and its parent is the project, as before.
2840
+ */
2841
+ function projectFolderOf(file: string): string {
2842
+ const parent = dirname(resolvePath(file));
2843
+ let dir = parent;
2844
+ for (;;) {
2845
+ const up = dirname(dir);
2846
+ if (up === dir) return parent;
2847
+ if (existsSync(`${dir}.jsonl`)) return up;
2848
+ dir = up;
2849
+ }
2850
+ }
2851
+
2824
2852
 
2825
2853
  /**
2826
2854
  * The directory rules, read from a JSON file, or nothing when none was asked
@@ -3713,6 +3741,8 @@ async function commandBill(args: Args, pricing: PricingCatalogue, t: CliMessages
3713
3741
  */
3714
3742
  const perFile = files.length <= 8;
3715
3743
  const unclaimed: string[] = [];
3744
+ /* The folders of the Claude Code sessions read, `<project>/<session>`, where the session keeps its other files. */
3745
+ const sessionFolders = new Set<string>();
3716
3746
  const byShape = new Map<string, { files: number; records: number | null; leftOut: number }>();
3717
3747
 
3718
3748
  for (const file of files) {
@@ -3770,6 +3800,7 @@ async function commandBill(args: Args, pricing: PricingCatalogue, t: CliMessages
3770
3800
  const c = claudeCodeRecords(text, project !== undefined && project !== '' ? { label: project } : withLabel);
3771
3801
  records = c.records;
3772
3802
  leftOut = c.assistantWithoutUsage + c.unparseable;
3803
+ sessionFolders.add(resolvePath(file).replace(/\.jsonl$/, ''));
3773
3804
  break;
3774
3805
  }
3775
3806
  case 'otel': {
@@ -3848,9 +3879,30 @@ async function commandBill(args: Args, pricing: PricingCatalogue, t: CliMessages
3848
3879
  }
3849
3880
  }
3850
3881
  for (const [shape, sum] of byShape) console.error(t.bill.shapeSummary(shape, sum.files, sum.records, sum.leftOut));
3851
- const named = perFile ? unclaimed : unclaimed.slice(0, 3);
3882
+ /*
3883
+ A Claude Code session keeps more than its transcript in the folder named
3884
+ after it: each subagent's metadata and prompt prefix, each workflow's
3885
+ journal and script, tool output too long for the transcript. None of it is
3886
+ usage, and naming each as a file no shape claims made a first bill read as
3887
+ a hundred and fifty things gone wrong. Counted once instead, and only
3888
+ inside the folder of a session that was read, so a file anywhere else is
3889
+ still named.
3890
+ */
3891
+ const insideSession = (file: string): boolean => {
3892
+ let dir = dirname(resolvePath(file));
3893
+ for (;;) {
3894
+ if (sessionFolders.has(dir)) return true;
3895
+ const up = dirname(dir);
3896
+ if (up === dir) return false;
3897
+ dir = up;
3898
+ }
3899
+ };
3900
+ const sideFiles = unclaimed.filter(insideSession).length;
3901
+ const unknown = unclaimed.filter((file) => !insideSession(file));
3902
+ if (sideFiles > 0) console.error(t.bill.sessionSideFiles(sideFiles));
3903
+ const named = perFile ? unknown : unknown.slice(0, 3);
3852
3904
  for (const file of named) console.error(t.bill.unknown(file));
3853
- if (unclaimed.length > named.length) console.error(t.bill.unknownMore(unclaimed.length - named.length));
3905
+ if (unknown.length > named.length) console.error(t.bill.unknownMore(unknown.length - named.length));
3854
3906
  if (labelledByProject > 0) console.error(t.bill.labelledByProject(labelledByProject));
3855
3907
  if (geminiRemainder > 0) console.error(t.fromGeminiCli.remainder(geminiRemainder));
3856
3908