@trazum/cli 2.4.1 → 2.4.3

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/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { createHash } from 'node:crypto';
3
3
  import { readdirSync, readFileSync } from 'node:fs';
4
4
  import { mkdir, mkdtemp, open, readdir, readFile, rm, stat, writeFile } from 'node:fs/promises';
5
- import { cpus, tmpdir } from 'node:os';
5
+ import { cpus, homedir, tmpdir } from 'node:os';
6
6
  import { createInterface } from 'node:readline/promises';
7
7
  import { dirname, join, resolve as resolvePath } from 'node:path';
8
8
  import { fileURLToPath } from 'node:url';
@@ -24,6 +24,7 @@ import { WATCH_STATE_VERSION, checkWebhook, postWebhook, readWatchState, writeWa
24
24
  import { LOCALE_ENV_VARS, detectLocale, getCliMessages } from './i18n/index.js';
25
25
  import { MAX_SUMMARY_CHARS, fitWithin, renderBlameMarkdown, renderCheckMarkdown, renderDiffMarkdown, renderRankMarkdown, renderProfileMarkdown, } from './markdown.js';
26
26
  import { renderPositionHtml, renderProfileHtml, renderRollupHtml } from './html.js';
27
+ import { renderProfilePdf } from './pdf.js';
27
28
  // --------------------------------------------------------------------------
28
29
  // Presentation
29
30
  // --------------------------------------------------------------------------
@@ -98,6 +99,7 @@ const VALUE_FLAGS = new Set([
98
99
  'config',
99
100
  'markdown-out',
100
101
  'html-out',
102
+ 'pdf-out',
101
103
  'otlp-out',
102
104
  'pricing',
103
105
  'prompt',
@@ -222,6 +224,42 @@ function levelFlag(args, config, t) {
222
224
  * as a log would be the same directory billing differently by verb.
223
225
  */
224
226
  const LOG_EXTENSIONS = ['.jsonl', '.ndjson', '.log', '.json'];
227
+ /**
228
+ * Whether a directory walk reads this file: one of `LOG_EXTENSIONS`, plain or
229
+ * gzipped, in any case.
230
+ *
231
+ * The list above said one list, and six walks still kept four of their own:
232
+ * `bill` skipped `.log`, which `profile` read, so the same directory billed
233
+ * $7.51 by one verb and $15.01 by the other, and `bill` did not even count
234
+ * the file it skipped. A predicate every walk calls is the only form of "one
235
+ * list" that cannot drift.
236
+ */
237
+ function isUsageLogName(name) {
238
+ const lower = name.toLowerCase();
239
+ return LOG_EXTENSIONS.some((extension) => lower.endsWith(extension) || lower.endsWith(`${extension}.gz`));
240
+ }
241
+ /**
242
+ * How many positional arguments a command reads. One unless listed.
243
+ *
244
+ * Every command used to read `positional[0]` and ignore the rest, so
245
+ * `trazum bill logs/*.jsonl`, which the shell expands to every file, priced
246
+ * the first file alone and reported no gap: a bill understated with the
247
+ * confidence of a complete one, and a spend gate judging one day of seven.
248
+ * A command now either reads every path it is given or refuses the extras.
249
+ */
250
+ const POSITIONAL_LIMIT = {
251
+ bill: Number.POSITIVE_INFINITY,
252
+ rollup: Number.POSITIVE_INFINITY,
253
+ diff: 2,
254
+ };
255
+ function rejectExtraPositionals(args, t) {
256
+ if (!COMMAND_FLAGS[args.command])
257
+ return;
258
+ const limit = POSITIONAL_LIMIT[args.command] ?? 1;
259
+ if (args.positional.length <= limit)
260
+ return;
261
+ throw new Error(t.errors.extraPositional(args.command, limit, args.positional.length, args.positional[limit] ?? ''));
262
+ }
225
263
  /**
226
264
  * One usage log, gzip included, shared by every command that reads one.
227
265
  *
@@ -367,7 +405,7 @@ const COMMAND_FLAGS = {
367
405
  ],
368
406
  check: ['max-tokens', 'level', 'exact-tokens', 'markdown-out', 'baseline', 'files-from'],
369
407
  baseline: ['model', 'calls', 'output-tokens', 'cache-hit-rate', 'batch', 'exact-tokens', 'out', 'o'],
370
- profile: ['json', 'pricing', 'pricing-live', 'against', 'what-if', 'markdown-out', 'html-out', 'csv-out', 'csv-shape', 'max-usd', 'max-growth-usd', 'max-cache-loss-usd', 'max-day-usd', 'max-session-usd', 'label', 'since', 'until', 'dry-run', 'markdown-summary', 'by-source', 'allow-empty'],
408
+ profile: ['json', 'pricing', 'pricing-live', 'against', 'what-if', 'markdown-out', 'html-out', 'pdf-out', 'csv-out', 'csv-shape', 'max-usd', 'max-growth-usd', 'max-cache-loss-usd', 'max-day-usd', 'max-session-usd', 'label', 'since', 'until', 'dry-run', 'markdown-summary', 'by-source', 'allow-empty'],
371
409
  plan: ['json', 'out', 'markdown-out', 'min-usd', 'pricing', 'pricing-live'],
372
410
  verify: ['against', 'gate', 'json', 'markdown-out', 'pricing', 'pricing-live'],
373
411
  history: ['store', 'json', 'markdown-out'],
@@ -394,7 +432,7 @@ const COMMAND_FLAGS = {
394
432
  'from-anthropic': ['label', 'label-by-workspace', 'out', 'o'],
395
433
  'from-openai': ['label', 'label-by-project', 'out', 'o'],
396
434
  'from-openrouter': ['label', 'label-by-workspace', 'out', 'o'],
397
- bill: ['label', 'out', 'o', 'stamp', 'pricing', 'pricing-live'],
435
+ bill: ['label', 'label-from-project', 'out', 'o', 'stamp', 'receipt', 'table', 'pricing', 'pricing-live', 'html-out', 'pdf-out', 'markdown-out', 'csv-out', 'csv-shape'],
398
436
  'from-helicone': ['out', 'o'],
399
437
  'from-langsmith': ['out', 'o'],
400
438
  switch: ['to', 'migration-usd', 'cases'],
@@ -2704,35 +2742,86 @@ function usageSourcesOf(text) {
2704
2742
  * a bill rather than usage, and pointed at `reconcile`.
2705
2743
  */
2706
2744
  async function commandBill(args, pricing, t) {
2707
- const target = args.positional[0];
2708
- if (target === undefined)
2709
- throw new Error(t.bill.noPath());
2710
- let info;
2711
- try {
2712
- info = await stat(target);
2713
- }
2714
- catch {
2715
- throw new Error(t.bill.notFound(target));
2745
+ /* Refused before any file is read: a bad shape found after the receipt
2746
+ printed would end a run that looked finished with an error. */
2747
+ const csvShape = csvShapeOf(args, t);
2748
+ /*
2749
+ No path is the most common first run, and it used to be a refusal: the
2750
+ person had to know where Claude Code keeps its sessions before the one
2751
+ line on the README worked. Claude Code's own folders are searched
2752
+ instead, and the ones found are named, so nothing is read silently.
2753
+ */
2754
+ let targets = args.positional;
2755
+ if (targets.length === 0) {
2756
+ const { found, tried } = await claudeProjectFolders(process.env);
2757
+ if (found.length === 0)
2758
+ throw new Error(t.bill.noPath(tried.join(', ')));
2759
+ console.error(t.bill.defaultPath(found.join(', ')));
2760
+ targets = found;
2716
2761
  }
2762
+ /*
2763
+ Every path given, files and directories alike, because a shell glob hands
2764
+ over many and reading the first was a bill missing the rest. A file named
2765
+ twice (a directory and a file inside it) is read once: counting it twice
2766
+ would be the opposite mistake.
2767
+ */
2717
2768
  const files = [];
2718
- if (info.isDirectory()) {
2719
- const entries = await readdir(target, { recursive: true, withFileTypes: true });
2720
- for (const entry of entries) {
2721
- if (entry.isFile() && /\.(json|jsonl|ndjson)(\.gz)?$/i.test(entry.name)) {
2722
- files.push(join(entry.parentPath, entry.name));
2723
- }
2769
+ const seen = new Set();
2770
+ /* Reached through a directory: where a project folder can name the work. */
2771
+ const walked = new Set();
2772
+ const add = (file, fromDirectory) => {
2773
+ const key = resolvePath(file);
2774
+ if (fromDirectory)
2775
+ walked.add(file);
2776
+ if (seen.has(key))
2777
+ return;
2778
+ seen.add(key);
2779
+ files.push(file);
2780
+ };
2781
+ for (const target of targets) {
2782
+ let info;
2783
+ try {
2784
+ info = await stat(target);
2785
+ }
2786
+ catch {
2787
+ throw new Error(t.bill.notFound(target));
2788
+ }
2789
+ if (info.isDirectory()) {
2790
+ const entries = await readdir(target, { recursive: true, withFileTypes: true });
2791
+ const found = entries
2792
+ .filter((entry) => entry.isFile() && isUsageLogName(entry.name))
2793
+ .map((entry) => join(entry.parentPath, entry.name))
2794
+ .sort();
2795
+ if (found.length === 0)
2796
+ throw new Error(t.bill.noFiles(target));
2797
+ for (const file of found)
2798
+ add(file, true);
2799
+ }
2800
+ else {
2801
+ add(target, false);
2724
2802
  }
2725
- files.sort();
2726
- if (files.length === 0)
2727
- throw new Error(t.bill.noFiles(target));
2728
- }
2729
- else {
2730
- files.push(target);
2731
2803
  }
2732
2804
  const label = stringFlag(args, 'label');
2733
2805
  const withLabel = label === undefined ? {} : { label };
2806
+ /*
2807
+ Claude Code keeps one folder per project, and "per project" is the
2808
+ question this door is for. `from-claude-code` has labelled a directory by
2809
+ its project folders since 1.77; `bill` read the same transcripts with no
2810
+ label at all, so the bill it printed could not say which project spent
2811
+ the money. Same default, same function, same way to decline.
2812
+ */
2813
+ const labelFromProject = boolFlag(args, 'label-from-project', true);
2814
+ let labelledByProject = 0;
2734
2815
  const lines = [];
2735
2816
  let sources = 0;
2817
+ /*
2818
+ One line per file is right for a handful and noise for a Claude Code
2819
+ folder of hundreds. Past a handful, the lines are per shape, and the
2820
+ files no shape claims are named for the first few and counted after.
2821
+ */
2822
+ const perFile = files.length <= 8;
2823
+ const unclaimed = [];
2824
+ const byShape = new Map();
2736
2825
  for (const file of files) {
2737
2826
  const text = await readUsageLog(file, t);
2738
2827
  const claims = usageSourcesOf(text);
@@ -2741,7 +2830,7 @@ async function commandBill(args, pricing, t) {
2741
2830
  console.error(t.bill.costReport(file));
2742
2831
  }
2743
2832
  else {
2744
- console.error(t.bill.unknown(file));
2833
+ unclaimed.push(file);
2745
2834
  }
2746
2835
  continue;
2747
2836
  }
@@ -2756,7 +2845,10 @@ async function commandBill(args, pricing, t) {
2756
2845
  let leftOut = 0;
2757
2846
  switch (shape) {
2758
2847
  case 'claude-code': {
2759
- const c = claudeCodeRecords(text, withLabel);
2848
+ const project = label === undefined && labelFromProject && walked.has(file) ? projectLabelFor(file) : undefined;
2849
+ if (project !== undefined && project !== '')
2850
+ labelledByProject += 1;
2851
+ const c = claudeCodeRecords(text, project !== undefined && project !== '' ? { label: project } : withLabel);
2760
2852
  records = c.records;
2761
2853
  leftOut = c.assistantWithoutUsage + c.unparseable;
2762
2854
  break;
@@ -2815,23 +2907,56 @@ async function commandBill(args, pricing, t) {
2815
2907
  for (const record of records)
2816
2908
  lines.push(JSON.stringify(record));
2817
2909
  sources += 1;
2818
- console.error(t.bill.file(file, shape, shape === 'usage-log' ? null : records.length, leftOut));
2819
- }
2910
+ const count = shape === 'usage-log' ? null : records.length;
2911
+ if (perFile) {
2912
+ console.error(t.bill.file(file, shape, count, leftOut));
2913
+ }
2914
+ else {
2915
+ const sum = byShape.get(shape) ?? { files: 0, records: count === null ? null : 0, leftOut: 0 };
2916
+ sum.files += 1;
2917
+ if (sum.records !== null && count !== null)
2918
+ sum.records += count;
2919
+ sum.leftOut += leftOut;
2920
+ byShape.set(shape, sum);
2921
+ }
2922
+ }
2923
+ for (const [shape, sum] of byShape)
2924
+ console.error(t.bill.shapeSummary(shape, sum.files, sum.records, sum.leftOut));
2925
+ const named = perFile ? unclaimed : unclaimed.slice(0, 3);
2926
+ for (const file of named)
2927
+ console.error(t.bill.unknown(file));
2928
+ if (unclaimed.length > named.length)
2929
+ console.error(t.bill.unknownMore(unclaimed.length - named.length));
2930
+ if (labelledByProject > 0)
2931
+ console.error(t.bill.labelledByProject(labelledByProject));
2820
2932
  if (sources === 0)
2821
2933
  throw new Error(t.bill.nothingRead());
2822
2934
  const report = profileUsage(lines.join('\n'), { catalogue: pricing });
2823
2935
  const document = receiptFrom(report, pricing, boolFlag(args, 'stamp') ? { emittedAt: new Date() } : {});
2824
2936
  const json = JSON.stringify(document, null, 2);
2937
+ /*
2938
+ A terminal gets a statement a person can read; a pipe gets the receipt.
2939
+ The receipt on a terminal was 60 lines of JSON before the first figure a
2940
+ reader wanted, which is the screen a first run ends on. Scripts are
2941
+ untouched: they pipe, and a pipe is not a TTY. `--receipt` forces the
2942
+ receipt and `--table` forces the statement, either way round. Not
2943
+ `--json`: that flag means a documented contract in docs/format.md, and
2944
+ the receipt is `trazum receipt`'s document, emitted here unchanged.
2945
+ */
2825
2946
  const out = stringFlag(args, 'out') ?? stringFlag(args, 'o');
2947
+ const statement = !boolFlag(args, 'receipt') && boolFlag(args, 'table', process.stdout.isTTY === true);
2826
2948
  if (out !== undefined) {
2827
2949
  await writeFile(out, json + '\n', 'utf8');
2828
2950
  console.error(t.bill.written(out));
2829
2951
  }
2830
- else {
2952
+ else if (!statement) {
2831
2953
  console.log(json);
2832
2954
  }
2833
2955
  console.error(t.bill.sources(sources, files.length));
2834
2956
  printReceiptSummary(document, t);
2957
+ if (statement)
2958
+ printBillStatement(report, labelledByProject > 0, t);
2959
+ await writeBillSideFiles(args, report, pricing, csvShape, t);
2835
2960
  /*
2836
2961
  A slug with a slash in it is how OpenRouter names a model, and the bundled
2837
2962
  catalogue does not carry those: the live overlay does. Said only when the
@@ -2843,6 +2968,150 @@ async function commandBill(args, pricing, t) {
2843
2968
  console.error(t.bill.pricingLiveHint(slugged.length));
2844
2969
  }
2845
2970
  }
2971
+ /**
2972
+ * Where Claude Code keeps its sessions, in the order it looks itself.
2973
+ *
2974
+ * `CLAUDE_CONFIG_DIR` first, because a person who set it moved the folder on
2975
+ * purpose; then the two defaults Claude Code has used. Every folder that
2976
+ * exists is returned, deduplicated, so a machine with both is billed for
2977
+ * both, once each. `tried` is every candidate, for the refusal to name.
2978
+ */
2979
+ async function claudeProjectFolders(env) {
2980
+ const home = homedir();
2981
+ const tried = [
2982
+ ...(env.CLAUDE_CONFIG_DIR ? [join(env.CLAUDE_CONFIG_DIR, 'projects')] : []),
2983
+ join(home, '.claude', 'projects'),
2984
+ join(home, '.config', 'claude', 'projects'),
2985
+ ];
2986
+ const found = [];
2987
+ const seen = new Set();
2988
+ for (const candidate of tried) {
2989
+ const key = resolvePath(candidate);
2990
+ if (seen.has(key))
2991
+ continue;
2992
+ seen.add(key);
2993
+ try {
2994
+ if ((await stat(candidate)).isDirectory())
2995
+ found.push(candidate);
2996
+ }
2997
+ catch {
2998
+ // Not there, which is the ordinary case for two of the three.
2999
+ }
3000
+ }
3001
+ return { found, tried };
3002
+ }
3003
+ /**
3004
+ * The bill as a person reads it: the total, by project, by model, and what
3005
+ * is not in the total, on stdout. The receipt's figures, rendered: nothing
3006
+ * here is computed that the receipt does not carry.
3007
+ */
3008
+ function printBillStatement(report, byProject, t) {
3009
+ const n = (value) => value.toLocaleString(t.numberLocale);
3010
+ const pct = (share) => `${(share * 100).toFixed(1)}%`;
3011
+ const total = report.total.totalUsd;
3012
+ const LIMIT = 12;
3013
+ const rowsOf = (entries) => {
3014
+ const shown = entries.slice(0, LIMIT).map(({ name, calls, usd }) => {
3015
+ const share = total > 0 ? usd / total : 0;
3016
+ return [name, n(calls), formatUsd(usd), `${bar(share)} ${pct(share)}`];
3017
+ });
3018
+ if (entries.length > LIMIT)
3019
+ shown.push([c.dim(t.bill.moreRows(entries.length - LIMIT)), '', '', '']);
3020
+ return shown;
3021
+ };
3022
+ const columns = (first) => [
3023
+ { header: first, align: 'left' },
3024
+ { header: t.bill.colCalls(), align: 'right' },
3025
+ { header: 'USD', align: 'right' },
3026
+ { header: t.bill.colShare(), align: 'left' },
3027
+ ];
3028
+ console.log();
3029
+ console.log(sectionHeading(t.bill.statementHeading()));
3030
+ console.log(` ${c.bold(t.bill.statementTotal(formatUsd(total), report.total.calls))}`);
3031
+ if (report.span !== null) {
3032
+ const span = t.profile.spanLine(dayOf(report.span.fromMs), dayOf(report.span.toMs), spanDays(report.span.fromMs, report.span.toMs));
3033
+ console.log(c.dim(` ${wrap(span, 74, ' ')}`));
3034
+ }
3035
+ const labelled = report.byLabel.filter((row) => row.label !== UNLABELLED);
3036
+ if (labelled.length > 0) {
3037
+ console.log();
3038
+ const entries = report.byLabel.map((row) => ({
3039
+ name: row.label === UNLABELLED ? t.profile.unlabelled() : row.label,
3040
+ calls: row.breakdown.calls,
3041
+ usd: row.breakdown.totalUsd,
3042
+ }));
3043
+ for (const line of table(columns(byProject ? t.bill.colProject() : t.bill.colWorkload()), rowsOf(entries))) {
3044
+ console.log(line);
3045
+ }
3046
+ }
3047
+ const priced = report.byModel.filter((row) => !report.unpricedModels.includes(row.model));
3048
+ if (priced.length > 0) {
3049
+ console.log();
3050
+ const entries = priced.map((row) => ({ name: row.model, calls: row.breakdown.calls, usd: row.breakdown.totalUsd }));
3051
+ for (const line of table(columns(t.bill.colModel()), rowsOf(entries)))
3052
+ console.log(line);
3053
+ }
3054
+ console.log();
3055
+ if (report.unpricedModels.length > 0) {
3056
+ console.log(` ${wrap(t.bill.statementUnpriced(report.unpricedModels.join(', '), report.unpriced.calls), 74, ' ')}`);
3057
+ }
3058
+ if (report.skippedLines.length > 0)
3059
+ console.log(` ${t.bill.statementUnread(report.skippedLines.length)}`);
3060
+ console.log(c.dim(` ${wrap(t.bill.statementNext(), 74, ' ')}`));
3061
+ console.log();
3062
+ }
3063
+ /**
3064
+ * The bill as a document for somebody else: PDF, HTML, Markdown, CSV.
3065
+ *
3066
+ * The receipt on stdout is for a machine. The person who signs the bill off
3067
+ * reads a PDF in an email, and until now reaching one meant knowing the log
3068
+ * was a usage log and rerunning `profile` on it, which a converted Claude Code
3069
+ * transcript is not. These are `profile`'s own renderers fed the report `bill`
3070
+ * just priced, so the files and the receipt cannot disagree: one report, five
3071
+ * envelopes. The stale-price caveat travels with them, computed the way
3072
+ * `profile` computes it, for the providers this bill actually used.
3073
+ */
3074
+ async function writeBillSideFiles(args, report, pricing, csvShape, t) {
3075
+ const markdownOut = stringFlag(args, 'markdown-out');
3076
+ const htmlOut = stringFlag(args, 'html-out');
3077
+ const pdfOut = stringFlag(args, 'pdf-out');
3078
+ const csvOut = stringFlag(args, 'csv-out');
3079
+ if (markdownOut === undefined && htmlOut === undefined && pdfOut === undefined && csvOut === undefined)
3080
+ return;
3081
+ const reviewed = reviewedForModels(report.byModel.map((row) => row.model), pricing);
3082
+ const ageDays = reviewAgeDays(reviewed, new Date());
3083
+ const renderInput = {
3084
+ report,
3085
+ levers: billLevers(report, { catalogue: pricing }),
3086
+ cache: cacheEconomics(report.total),
3087
+ t,
3088
+ ...(ageDays !== null && ageDays > STALE_PRICING_DAYS ? { stalePricing: { date: reviewed, days: ageDays } } : {}),
3089
+ };
3090
+ if (markdownOut !== undefined) {
3091
+ await writeFile(markdownOut, renderProfileMarkdown(renderInput), 'utf8');
3092
+ console.error(t.report.reportWritten(markdownOut));
3093
+ }
3094
+ if (htmlOut !== undefined) {
3095
+ await writeFile(htmlOut, renderProfileHtml(renderInput), 'utf8');
3096
+ console.error(t.html.written(htmlOut));
3097
+ }
3098
+ if (pdfOut !== undefined) {
3099
+ await writeFile(pdfOut, renderProfilePdf(renderInput));
3100
+ console.error(t.pdf.written(pdfOut));
3101
+ }
3102
+ if (csvOut !== undefined) {
3103
+ await writeFile(csvOut, profileToCsv(report, { unlabelled: t.profile.unlabelled(), shape: csvShape }), 'utf8');
3104
+ console.error(t.report.reportWritten(csvOut));
3105
+ }
3106
+ }
3107
+ /** `--csv-shape`, checked: one list of shapes for `profile` and `bill`. */
3108
+ function csvShapeOf(args, t) {
3109
+ const shape = stringFlag(args, 'csv-shape') ?? 'slice';
3110
+ if (shape !== 'slice' && shape !== 'day' && shape !== 'hour' && shape !== 'model-day') {
3111
+ throw new Error(t.profile.badCsvShape(shape));
3112
+ }
3113
+ return shape;
3114
+ }
2846
3115
  /**
2847
3116
  * `trazum from-otel <file|dir>` — OpenTelemetry GenAI spans as a usage log.
2848
3117
  *
@@ -7398,7 +7667,8 @@ async function writeProfileSideFiles(context) {
7398
7667
  */
7399
7668
  const markdownOut = stringFlag(args, 'markdown-out');
7400
7669
  const htmlOut = stringFlag(args, 'html-out');
7401
- if (markdownOut !== undefined || htmlOut !== undefined) {
7670
+ const pdfOut = stringFlag(args, 'pdf-out');
7671
+ if (markdownOut !== undefined || htmlOut !== undefined || pdfOut !== undefined) {
7402
7672
  /**
7403
7673
  * Derived here, not borrowed from the terminal path. Under `--json`
7404
7674
  * that path never runs, and the outer `levers` this block used to
@@ -7458,12 +7728,16 @@ async function writeProfileSideFiles(context) {
7458
7728
  });
7459
7729
  if (markdownOut !== undefined) {
7460
7730
  await writeFile(markdownOut, renderProfileMarkdown(renderInput), 'utf8');
7461
- notice(c.dim(t.report.wroteTo(markdownOut)));
7731
+ notice(c.dim(t.report.reportWritten(markdownOut)));
7462
7732
  }
7463
7733
  if (htmlOut !== undefined) {
7464
7734
  await writeFile(htmlOut, renderProfileHtml(renderInput), 'utf8');
7465
7735
  notice(c.dim(t.html.written(htmlOut)));
7466
7736
  }
7737
+ if (pdfOut !== undefined) {
7738
+ await writeFile(pdfOut, renderProfilePdf(renderInput));
7739
+ notice(c.dim(t.pdf.written(pdfOut)));
7740
+ }
7467
7741
  }
7468
7742
  /**
7469
7743
  * The same report as a spreadsheet, one row per label and model — the grain
@@ -7478,12 +7752,9 @@ async function writeProfileSideFiles(context) {
7478
7752
  * spreadsheet that has to filter before it can sum is a spreadsheet
7479
7753
  * somebody sums wrong.
7480
7754
  */
7481
- const shape = stringFlag(args, 'csv-shape') ?? 'slice';
7482
- if (shape !== 'slice' && shape !== 'day' && shape !== 'hour' && shape !== 'model-day') {
7483
- throw new Error(t.profile.badCsvShape(shape));
7484
- }
7755
+ const shape = csvShapeOf(args, t);
7485
7756
  await writeFile(csvOut, profileToCsv(report, { unlabelled: t.profile.unlabelled(), shape }), 'utf8');
7486
- notice(c.dim(t.report.wroteTo(csvOut)));
7757
+ notice(c.dim(t.report.reportWritten(csvOut)));
7487
7758
  }
7488
7759
  }
7489
7760
  /**
@@ -10720,6 +10991,7 @@ async function main() {
10720
10991
  return;
10721
10992
  }
10722
10993
  rejectUnknownFlags(args, t);
10994
+ rejectExtraPositionals(args, t);
10723
10995
  // Loaded before dispatch so every command sees the same settings, and after
10724
10996
  // flag validation so a typo is reported before any file is touched. An
10725
10997
  // invalid config throws here rather than quietly reverting to defaults —