@trazum/cli 1.73.1 → 1.75.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/src/index.ts CHANGED
@@ -112,6 +112,7 @@ import {
112
112
  plannedCalls,
113
113
  claudeCodeRecords,
114
114
  otelRecords,
115
+ ownRate,
115
116
  positionAt,
116
117
  positionReport,
117
118
  PRICING_LAST_REVIEWED,
@@ -125,6 +126,7 @@ import {
125
126
  rejectionText,
126
127
  reorderForCache,
127
128
  repriceProfile,
129
+ switchAnalysis,
128
130
  reviewAgeDays,
129
131
  reviewExamples,
130
132
  RULES,
@@ -253,15 +255,11 @@ import type { CliMessages } from './i18n/index.js';
253
255
  // Presentation
254
256
  // --------------------------------------------------------------------------
255
257
 
256
- const useColor = process.stdout.isTTY && !process.env.NO_COLOR;
257
- const c = {
258
- bold: (s: string) => (useColor ? `\u001b[1m${s}\u001b[22m` : s),
259
- dim: (s: string) => (useColor ? `\u001b[2m${s}\u001b[22m` : s),
260
- green: (s: string) => (useColor ? `\u001b[32m${s}\u001b[39m` : s),
261
- red: (s: string) => (useColor ? `\u001b[31m${s}\u001b[39m` : s),
262
- yellow: (s: string) => (useColor ? `\u001b[33m${s}\u001b[39m` : s),
263
- cyan: (s: string) => (useColor ? `\u001b[36m${s}\u001b[39m` : s),
264
- };
258
+ // The painters, the ANSI-aware measurer, the one table renderer, the
259
+ // proportion bar and the heading rule — the 1.75 style module. The guard in
260
+ // style.test.js holds the contract: stripped colour output is byte-identical
261
+ // to plain output, and a pipe stays plain.
262
+ import { bar, c, sectionHeading, table } from './style.js';
265
263
 
266
264
  // --------------------------------------------------------------------------
267
265
  // Argument parsing
@@ -348,6 +346,12 @@ const VALUE_FLAGS = new Set([
348
346
  'prompt',
349
347
  'out',
350
348
  'o',
349
+ 'to',
350
+ 'migration-usd',
351
+ 'cases',
352
+ 'gpu-usd-hour',
353
+ 'tokens-per-second',
354
+ 'utilization',
351
355
  ]);
352
356
 
353
357
  function parseArgs(argv: string[], t: CliMessages): Args {
@@ -672,6 +676,8 @@ const COMMAND_FLAGS: Record<string, string[]> = {
672
676
  position: ['json', 'html-out', 'pricing', 'pricing-live'],
673
677
  'from-claude-code': ['label', 'label-from-project', 'out', 'o'],
674
678
  'from-otel': ['label-from-service', 'out', 'o'],
679
+ switch: ['to', 'migration-usd', 'cases'],
680
+ ownrate: ['gpu-usd-hour', 'tokens-per-second', 'utilization'],
675
681
  pulse: ['json', 'max-stale-hours'],
676
682
  bench: ['workload', 'json', 'record', 'against', 'max-ratio'],
677
683
  write: ['answers', 'json', 'out', 'o', 'calls', 'avg-output'],
@@ -918,7 +924,7 @@ function printReport(
918
924
  // above already told them nothing changed.
919
925
  if (reorder !== null && (reorder.moved.length > 0 || reorder.declined.length > 0)) {
920
926
  console.log();
921
- console.log(c.bold(t.report.reorderHeading()));
927
+ console.log(sectionHeading(t.report.reorderHeading()));
922
928
  if (reorder.moved.length === 0) {
923
929
  console.log(` ${c.dim(t.report.reorderNothing())}`);
924
930
  } else {
@@ -1230,7 +1236,7 @@ function printTokensOnly(
1230
1236
  const saved = result.tokensBefore - result.tokensAfter;
1231
1237
 
1232
1238
  console.log();
1233
- console.log(c.bold(t.report.tokensOnlyHeading(host.displayName)));
1239
+ console.log(sectionHeading(t.report.tokensOnlyHeading(host.displayName)));
1234
1240
  // Only claim the host bills by subscription when it does. Forced with the
1235
1241
  // flag on GitHub Actions, the first version said "GitHub Actions bills by
1236
1242
  // subscription", which is simply false.
@@ -1714,7 +1720,7 @@ function renderInit(proposal: InitProposal, ctx: InitRenderContext): void {
1714
1720
  const n = (value: number): string => value.toLocaleString(t.numberLocale);
1715
1721
 
1716
1722
  console.log();
1717
- console.log(c.bold(t.init.heading()));
1723
+ console.log(sectionHeading(t.init.heading()));
1718
1724
  console.log();
1719
1725
 
1720
1726
  // 1. Where this is running.
@@ -1742,7 +1748,7 @@ function renderInit(proposal: InitProposal, ctx: InitRenderContext): void {
1742
1748
  console.log();
1743
1749
 
1744
1750
  // 4. What the config would say, and what it will not.
1745
- console.log(c.bold(t.init.configHeading()));
1751
+ console.log(sectionHeading(t.init.configHeading()));
1746
1752
  if (proposal.justified.length === 0) {
1747
1753
  console.log(` ${c.dim(t.init.nothingJustified())}`);
1748
1754
  }
@@ -1759,7 +1765,7 @@ function renderInit(proposal: InitProposal, ctx: InitRenderContext): void {
1759
1765
  console.log();
1760
1766
 
1761
1767
  // 5. The single most valuable thing found — arithmetic first.
1762
- console.log(c.bold(t.init.findingHeading()));
1768
+ console.log(sectionHeading(t.init.findingHeading()));
1763
1769
  if (proposal.headline === null) {
1764
1770
  console.log(` ${c.dim(t.init.noFinding(proposal.noHeadline ?? 'nothing-measured'))}`);
1765
1771
  console.log();
@@ -2141,7 +2147,7 @@ async function commandConform(args: Args, t: CliMessages): Promise<void> {
2141
2147
 
2142
2148
  if (report.unavailable.length > 0) {
2143
2149
  console.log();
2144
- console.log(c.bold(t.conform.unavailableHeading()));
2150
+ console.log(sectionHeading(t.conform.unavailableHeading()));
2145
2151
  for (const gap of report.unavailable) {
2146
2152
  console.log(` ${c.dim(wrap(t.conform.unavailable(gap.finding, gap.because, gap.unlockedBy), 74, ' '))}`);
2147
2153
  }
@@ -2280,7 +2286,7 @@ async function commandRollup(args: Args, t: CliMessages): Promise<void> {
2280
2286
  }
2281
2287
 
2282
2288
  console.log();
2283
- console.log(c.bold(t.rollup.contributorsHeading()));
2289
+ console.log(sectionHeading(t.rollup.contributorsHeading()));
2284
2290
  for (const contributor of document.contributors) {
2285
2291
  console.log(
2286
2292
  ` ${t.rollup.contributor(
@@ -2328,7 +2334,7 @@ async function commandRollup(args: Args, t: CliMessages): Promise<void> {
2328
2334
 
2329
2335
  if (document.rejected.length > 0) {
2330
2336
  console.log();
2331
- console.log(c.bold(t.rollup.rejectedHeading()));
2337
+ console.log(sectionHeading(t.rollup.rejectedHeading()));
2332
2338
  for (const rejection of document.rejected) {
2333
2339
  // The roll-up it arrived through, when it came through one: a rejection
2334
2340
  // whose origin got lost is a machine nobody knows to go and fix.
@@ -2356,7 +2362,7 @@ async function commandRollup(args: Args, t: CliMessages): Promise<void> {
2356
2362
 
2357
2363
  if (document.byLabel.length > 0) {
2358
2364
  console.log();
2359
- console.log(c.bold(t.rollup.byLabelHeading()));
2365
+ console.log(sectionHeading(t.rollup.byLabelHeading()));
2360
2366
  for (const row of document.byLabel.slice(0, 8)) {
2361
2367
  console.log(` ${t.rollup.labelRow(row.label, formatUsd(row.breakdown.totalUsd), row.breakdown.calls)}`);
2362
2368
  }
@@ -2364,7 +2370,7 @@ async function commandRollup(args: Args, t: CliMessages): Promise<void> {
2364
2370
 
2365
2371
  if (document.notMerged.length > 0) {
2366
2372
  console.log();
2367
- console.log(c.bold(t.rollup.notMergedHeading()));
2373
+ console.log(sectionHeading(t.rollup.notMergedHeading()));
2368
2374
  for (const finding of document.notMerged) {
2369
2375
  console.log(` ${wrap(t.rollup.notMerged(finding.finding, finding.because), 72, ' ')}`);
2370
2376
  if (finding.presentIn.length > 0) {
@@ -2375,7 +2381,7 @@ async function commandRollup(args: Args, t: CliMessages): Promise<void> {
2375
2381
 
2376
2382
  if (document.cannotSay.length > 0) {
2377
2383
  console.log();
2378
- console.log(c.bold(t.rollup.cannotSayHeading()));
2384
+ console.log(sectionHeading(t.rollup.cannotSayHeading()));
2379
2385
  for (const caveat of document.cannotSay) {
2380
2386
  console.log(` ${c.dim(wrap(t.rollup.caveat(caveat), 72, ' '))}`);
2381
2387
  }
@@ -2648,6 +2654,138 @@ async function commandFromClaudeCode(args: Args, t: CliMessages): Promise<void>
2648
2654
  * standardised the TTL split). Prompt content, trace ids and every other span
2649
2655
  * attribute stay in the span; a fixture greps the whole output to prove it.
2650
2656
  */
2657
+ /**
2658
+ * `trazum switch` — the forty-first command, from the 1.74 plan: the decision
2659
+ * every what-if serves, priced. Rests on `switchAnalysis`, which rests on
2660
+ * `repriceProfile`, so over-context slices and cache minimums keep their
2661
+ * honesty. Ends, always, on the refusal: quality is `trazum route`'s verdict.
2662
+ */
2663
+ async function commandSwitch(args: Args, pricing: PricingCatalogue, t: CliMessages): Promise<void> {
2664
+ const file = args.positional[0];
2665
+ if (file === undefined) throw new Error(t.switchCmd.noLog());
2666
+ const target = stringFlag(args, 'to');
2667
+ if (target === undefined) throw new Error(t.switchCmd.noTarget());
2668
+ // Optional numbers: absent stays absent — a defaulted migration cost or
2669
+ // case count would be an invented one.
2670
+ const optional = (name: string): number | undefined => {
2671
+ const raw = stringFlag(args, name);
2672
+ if (raw === undefined) return undefined;
2673
+ const value = Number(raw);
2674
+ if (!Number.isFinite(value) || value < 0) throw new Error(t.errors.mustBeNonNegative(name, raw));
2675
+ return value;
2676
+ };
2677
+ const migrationUsd = optional('migration-usd');
2678
+ const cases = optional('cases');
2679
+
2680
+ const text = await readUsageLog(file, t);
2681
+ const report = profileUsage(text, { catalogue: pricing });
2682
+ const analysis = switchAnalysis(report, target, {
2683
+ catalogue: pricing,
2684
+ ...(migrationUsd !== undefined ? { migrationUsd } : {}),
2685
+ ...(cases !== undefined ? { evalCases: cases } : {}),
2686
+ });
2687
+ if (analysis === null) throw new Error(t.switchCmd.unknownModel(target));
2688
+
2689
+ const { reprice, savingUsd, measuredDays, breakEven, evalCost } = analysis;
2690
+ console.log();
2691
+ console.log(sectionHeading(t.switchCmd.heading(reprice.target.displayName)));
2692
+ if (reprice.slices.length === 0) {
2693
+ console.log(` ${wrap(t.switchCmd.nothingMovable(), 74, ' ')}`);
2694
+ } else {
2695
+ const line =
2696
+ savingUsd >= 0
2697
+ ? t.switchCmd.saves(formatUsd(reprice.currentUsd), formatUsd(reprice.targetUsd), formatUsd(savingUsd))
2698
+ : t.switchCmd.costs(formatUsd(reprice.currentUsd), formatUsd(reprice.targetUsd), formatUsd(-savingUsd));
2699
+ console.log(` ${savingUsd >= 0 ? c.green('->') : c.red('->')} ${wrap(line, 72, ' ')}`);
2700
+ const movableCalls = reprice.slices.reduce((sum, slice) => sum + slice.calls, 0);
2701
+ console.log(` ${wrap(t.switchCmd.movable(movableCalls, reprice.slices.length), 74, ' ')}`);
2702
+ }
2703
+ if (reprice.overContext.length > 0) {
2704
+ const usd = reprice.overContext.reduce((sum, slice) => sum + slice.currentUsd, 0);
2705
+ console.log(` ${c.yellow('!')} ${wrap(t.switchCmd.overContext(reprice.overContext.length, formatUsd(usd)), 72, ' ')}`);
2706
+ }
2707
+ if (reprice.alreadyOnTarget.calls > 0) {
2708
+ console.log(` ${wrap(t.switchCmd.alreadyOnTarget(reprice.alreadyOnTarget.calls, formatUsd(reprice.alreadyOnTarget.usd)), 74, ' ')}`);
2709
+ }
2710
+ console.log(
2711
+ ` ${wrap(measuredDays !== null ? t.switchCmd.window(measuredDays) : t.switchCmd.noWindow(), 74, ' ')}`,
2712
+ );
2713
+ if (breakEven !== null) {
2714
+ const sentence =
2715
+ 'days' in breakEven
2716
+ ? t.switchCmd.breakEvenDays(formatUsd(breakEven.migrationUsd), Math.ceil(breakEven.days), measuredDays ?? 0)
2717
+ : breakEven.refused === 'no-saving'
2718
+ ? t.switchCmd.breakEvenNoSaving(formatUsd(breakEven.migrationUsd))
2719
+ : t.switchCmd.breakEvenNoClock(formatUsd(breakEven.migrationUsd));
2720
+ console.log(` ${wrap(sentence, 74, ' ')}`);
2721
+ }
2722
+ if (evalCost !== null) {
2723
+ console.log(` ${wrap(t.switchCmd.evalCost(evalCost.cases, formatUsd(evalCost.totalUsd)), 74, ' ')}`);
2724
+ } else if (reprice.slices.length > 0) {
2725
+ console.log(` ${c.dim(wrap(t.switchCmd.evalCostHint(), 74, ' '))}`);
2726
+ }
2727
+ console.log();
2728
+ console.log(
2729
+ ` ${wrap(t.switchCmd.quality(`trazum route ${file} --prompt-file <prompt> --cases <cases> --yes`), 74, ' ')}`,
2730
+ );
2731
+ }
2732
+
2733
+ /**
2734
+ * `trazum ownrate` — the forty-second: a self-hosted model's $/MTok, derived
2735
+ * from the operator's own declared numbers, with the overlay snippet ready to
2736
+ * paste. Division and a label, nothing modelled.
2737
+ */
2738
+ function commandOwnrate(args: Args, t: CliMessages): void {
2739
+ const optional = (name: string): number | undefined => {
2740
+ const raw = stringFlag(args, name);
2741
+ if (raw === undefined) return undefined;
2742
+ const value = Number(raw);
2743
+ if (!Number.isFinite(value)) throw new Error(t.ownrate.invalid(name));
2744
+ return value;
2745
+ };
2746
+ const gpuUsdPerHour = optional('gpu-usd-hour');
2747
+ const tokensPerSecond = optional('tokens-per-second');
2748
+ const utilization = optional('utilization');
2749
+ if (gpuUsdPerHour === undefined || tokensPerSecond === undefined) throw new Error(t.ownrate.missing());
2750
+ if (!(gpuUsdPerHour > 0)) throw new Error(t.ownrate.invalid('gpu-usd-hour'));
2751
+ if (!(tokensPerSecond > 0)) throw new Error(t.ownrate.invalid('tokens-per-second'));
2752
+ if (utilization !== undefined && !(utilization > 0 && utilization <= 1))
2753
+ throw new Error(t.ownrate.invalid('utilization'));
2754
+
2755
+ const { usdPerMTok } = ownRate({
2756
+ gpuUsdPerHour,
2757
+ tokensPerSecond,
2758
+ ...(utilization !== undefined ? { utilization } : {}),
2759
+ });
2760
+ const pct = Math.round((utilization ?? 1) * 100);
2761
+ console.log();
2762
+ console.log(
2763
+ ` ${wrap(t.ownrate.result(formatUsd(usdPerMTok), tokensPerSecond, formatUsd(gpuUsdPerHour), pct), 74, ' ')}`,
2764
+ );
2765
+ console.log(` ${c.dim(wrap(t.ownrate.declared(), 74, ' '))}`);
2766
+ console.log();
2767
+ console.log(` ${t.ownrate.snippetHeading()}`);
2768
+ // Complete on purpose: the overlay parser refuses a new model with fields
2769
+ // missing, and a snippet that does not paste is worse than none. The
2770
+ // honest values for what a self-hosted model has not measured are the
2771
+ // catalogue's own unknowns, never a guess.
2772
+ const snippet = {
2773
+ lastReviewed: new Date().toISOString().slice(0, 10),
2774
+ models: {
2775
+ 'my-self-hosted-model': {
2776
+ displayName: 'My self-hosted model',
2777
+ inputPerMTok: Number(usdPerMTok.toFixed(4)),
2778
+ outputPerMTok: Number(usdPerMTok.toFixed(4)),
2779
+ contextWindow: 32768,
2780
+ cacheMinTokens: null,
2781
+ tier: 'unknown',
2782
+ capability: 'unknown',
2783
+ },
2784
+ },
2785
+ };
2786
+ console.log(JSON.stringify(snippet, null, 2));
2787
+ }
2788
+
2651
2789
  async function commandFromOtel(args: Args, t: CliMessages): Promise<void> {
2652
2790
  const target = args.positional[0];
2653
2791
  if (target === undefined) throw new Error(t.fromOtel.noPath());
@@ -2757,7 +2895,7 @@ async function commandPosition(
2757
2895
  : t.position.scopeLabel(position.label ?? '');
2758
2896
 
2759
2897
  console.log();
2760
- console.log(c.bold(t.position.heading(document.month.id)));
2898
+ console.log(sectionHeading(t.position.heading(document.month.id)));
2761
2899
  for (const position of document.positions) {
2762
2900
  const name = scopeName(position);
2763
2901
  if (position.verdict === 'cannot-tell') {
@@ -2862,7 +3000,7 @@ async function commandPulse(args: Args, t: CliMessages): Promise<void> {
2862
3000
  const when = (ms: number): string => new Date(ms).toISOString().replace('T', ' ').slice(0, 16);
2863
3001
 
2864
3002
  console.log();
2865
- console.log(c.bold(t.pulse.heading()));
3003
+ console.log(sectionHeading(t.pulse.heading()));
2866
3004
  for (const heartbeat of report.beats) {
2867
3005
  const name = t.pulse.kind(heartbeat.kind);
2868
3006
  if (heartbeat.lastMs === null) {
@@ -3155,7 +3293,7 @@ function printBenchTable(measurements: BenchMeasurement[], t: CliMessages, machi
3155
3293
  const idWidth = Math.max(...measurements.map((m) => m.id.length), t.bench.colWorkload().length);
3156
3294
 
3157
3295
  console.log();
3158
- console.log(c.bold(t.bench.heading()));
3296
+ console.log(sectionHeading(t.bench.heading()));
3159
3297
  if (machine !== undefined) {
3160
3298
  console.log(` ${c.dim(t.bench.machine(machine.node, machine.platform, machine.cpus, machine.cpuModel))}`);
3161
3299
  }
@@ -3358,11 +3496,11 @@ function commandFeedback(t: CliMessages): void {
3358
3496
  `${FEEDBACK_REPO}/issues/new?body=${encodeURIComponent(body)}`;
3359
3497
 
3360
3498
  console.log();
3361
- console.log(c.bold(t.feedback.heading()));
3499
+ console.log(sectionHeading(t.feedback.heading()));
3362
3500
  console.log(` ${c.dim(wrap(t.feedback.sendsNothing(), 74, ' '))}`);
3363
3501
  console.log();
3364
3502
 
3365
- console.log(c.bold(t.feedback.whereHeading()));
3503
+ console.log(sectionHeading(t.feedback.whereHeading()));
3366
3504
  console.log(` ${t.feedback.wrongOptimisation()}`);
3367
3505
  console.log(` ${c.dim(`${FEEDBACK_REPO}/issues/new?template=wrong_optimisation.yml`)}`);
3368
3506
  console.log(` ${t.feedback.bug()}`);
@@ -3373,12 +3511,12 @@ function commandFeedback(t: CliMessages): void {
3373
3511
  console.log(` ${c.dim(`${FEEDBACK_REPO}/security/advisories/new`)}`);
3374
3512
  console.log();
3375
3513
 
3376
- console.log(c.bold(t.feedback.environmentHeading()));
3514
+ console.log(sectionHeading(t.feedback.environmentHeading()));
3377
3515
  for (const line of environment) console.log(` ${line}`);
3378
3516
  console.log(` ${c.dim(wrap(t.feedback.environmentOnly(), 74, ' '))}`);
3379
3517
  console.log();
3380
3518
 
3381
- console.log(c.bold(t.feedback.linkHeading()));
3519
+ console.log(sectionHeading(t.feedback.linkHeading()));
3382
3520
  console.log(` ${url}`);
3383
3521
  console.log();
3384
3522
  }
@@ -3574,7 +3712,7 @@ async function commandLadder(
3574
3712
  const pct = (value: number): string => `${(value * 100).toFixed(1)}%`;
3575
3713
 
3576
3714
  console.log();
3577
- console.log(c.bold(t.ladder.heading()));
3715
+ console.log(sectionHeading(t.ladder.heading()));
3578
3716
  if (Object.keys(ladders).length === 0) {
3579
3717
  console.log(` ${c.dim(wrap(t.ladder.noLadders(), 74, ' '))}`);
3580
3718
  console.log();
@@ -3728,7 +3866,7 @@ async function commandExperiment(
3728
3866
  );
3729
3867
 
3730
3868
  console.log();
3731
- console.log(c.bold(t.experiment.heading(aName, bName)));
3869
+ console.log(sectionHeading(t.experiment.heading(aName, bName)));
3732
3870
  console.log();
3733
3871
  for (const side of [result.a, result.b]) {
3734
3872
  console.log(
@@ -3867,7 +4005,7 @@ async function commandQuality(
3867
4005
  const n = (value: number): string => value.toLocaleString(t.numberLocale);
3868
4006
 
3869
4007
  console.log();
3870
- console.log(c.bold(t.quality.heading(label)));
4008
+ console.log(sectionHeading(t.quality.heading(label)));
3871
4009
  console.log(` ${c.dim(wrap(t.quality.notRandomised(), 74, ' '))}`);
3872
4010
  console.log();
3873
4011
  console.log(
@@ -3978,7 +4116,7 @@ async function commandSemantic(
3978
4116
  const n = (value: number): string => value.toLocaleString(t.numberLocale);
3979
4117
 
3980
4118
  console.log();
3981
- console.log(c.bold(t.semantic.heading(args.positional[0] ?? '-')));
4119
+ console.log(sectionHeading(t.semantic.heading(args.positional[0] ?? '-')));
3982
4120
  console.log();
3983
4121
  console.log(
3984
4122
  ` ${wrap(
@@ -4094,7 +4232,7 @@ async function commandOwners(
4094
4232
  if (path === undefined) throw new Error(t.errors.missingInputFile());
4095
4233
 
4096
4234
  console.log();
4097
- console.log(c.bold(t.owners.heading()));
4235
+ console.log(sectionHeading(t.owners.heading()));
4098
4236
  if (config.owners === undefined) {
4099
4237
  console.log(` ${c.dim(wrap(t.owners.noOwners(), 74, ' '))}`);
4100
4238
  console.log();
@@ -4284,7 +4422,7 @@ async function commandCommitment(
4284
4422
  const pct = (value: number): string => `${(value * 100).toFixed(0)}%`;
4285
4423
 
4286
4424
  console.log();
4287
- console.log(c.bold(t.commitment.heading(formatUsd(floor), pct(discount), n(months))));
4425
+ console.log(sectionHeading(t.commitment.heading(formatUsd(floor), pct(discount), n(months))));
4288
4426
  console.log(` ${c.dim(wrap(t.commitment.asIf(), 74, ' '))}`);
4289
4427
  console.log();
4290
4428
 
@@ -4459,7 +4597,7 @@ async function commandReport(
4459
4597
  const n = (value: number): string => value.toLocaleString(t.numberLocale);
4460
4598
 
4461
4599
  console.log();
4462
- console.log(c.bold(t.annual.heading(year)));
4600
+ console.log(sectionHeading(t.annual.heading(year)));
4463
4601
  console.log();
4464
4602
  console.log(
4465
4603
  ` ${t.annual.spent(formatUsd(record.totalUsd), n(record.totalCalls), n(record.months.length))}`,
@@ -4520,7 +4658,7 @@ function commandModels(t: CliMessages, pricing: PricingCatalogue): void {
4520
4658
  const col = t.models.columns;
4521
4659
 
4522
4660
  console.log();
4523
- console.log(c.bold(t.models.title()) + c.dim(t.models.unit()));
4661
+ console.log(sectionHeading(`${t.models.title()}${t.models.unit()}`));
4524
4662
  console.log(
4525
4663
  c.dim(t.models.reviewedOn(pricing.lastReviewed, reviewAgeDays(pricing.lastReviewed, new Date()))),
4526
4664
  );
@@ -4535,27 +4673,17 @@ function commandModels(t: CliMessages, pricing: PricingCatalogue): void {
4535
4673
  // "caches from the first token" — and it is the wrong one.
4536
4674
  cache: m.cacheMinTokens === null ? '—' : n(m.cacheMinTokens),
4537
4675
  }));
4538
- const widths = {
4539
- id: Math.max(...rows.map((r) => r.id.length), col.model.length),
4540
- input: Math.max(...rows.map((r) => r.input.length), col.input.length),
4541
- output: Math.max(...rows.map((r) => r.output.length), col.output.length),
4542
- context: Math.max(...rows.map((r) => r.context.length), col.context.length),
4543
- cache: Math.max(...rows.map((r) => r.cache.length), col.cacheMin.length),
4544
- };
4545
-
4546
- console.log(
4547
- c.bold(
4548
- ` ${col.model.padEnd(widths.id)} ${col.input.padStart(widths.input)} ` +
4549
- `${col.output.padStart(widths.output)} ${col.context.padStart(widths.context)} ` +
4550
- `${col.cacheMin.padStart(widths.cache)}`,
4551
- ),
4552
- );
4553
- for (const row of rows) {
4554
- console.log(
4555
- ` ${row.id.padEnd(widths.id)} ${row.input.padStart(widths.input)} ` +
4556
- `${row.output.padStart(widths.output)} ${row.context.padStart(widths.context)} ` +
4557
- `${row.cache.padStart(widths.cache)}`,
4558
- );
4676
+ for (const line of table(
4677
+ [
4678
+ { header: col.model, align: 'left' },
4679
+ { header: col.input, align: 'right' },
4680
+ { header: col.output, align: 'right' },
4681
+ { header: col.context, align: 'right' },
4682
+ { header: col.cacheMin, align: 'right' },
4683
+ ],
4684
+ rows.map((row) => [row.id, row.input, row.output, row.context, row.cache]),
4685
+ )) {
4686
+ console.log(line);
4559
4687
  }
4560
4688
 
4561
4689
  console.log();
@@ -4571,7 +4699,7 @@ function commandRules(t: CliMessages, locale: Locale): void {
4571
4699
  const copy = getMessages(locale).rules;
4572
4700
 
4573
4701
  console.log();
4574
- console.log(c.bold(t.rules.title()));
4702
+ console.log(sectionHeading(t.rules.title()));
4575
4703
  console.log(c.dim(t.rules.disableHint()));
4576
4704
  console.log();
4577
4705
  for (const rule of RULES) {
@@ -4649,7 +4777,7 @@ async function commandRulesMeasure(
4649
4777
  const n = (value: number): string => value.toLocaleString(t.numberLocale);
4650
4778
 
4651
4779
  console.log();
4652
- console.log(c.bold(t.rules.measureHeading(root, report.prompts, level)));
4780
+ console.log(sectionHeading(t.rules.measureHeading(root, report.prompts, level)));
4653
4781
  console.log(` ${c.dim(t.rules.measureTotals(n(report.tokensBefore), n(report.tokensSaved), n(report.floor)))}`);
4654
4782
  console.log();
4655
4783
 
@@ -4800,7 +4928,7 @@ async function commandOptimize(
4800
4928
  rows.sort((a, b) => b.savingUsd - a.savingUsd);
4801
4929
 
4802
4930
  const n = (value: number): string => value.toLocaleString(t.numberLocale);
4803
- console.log(c.bold(t.report.allLabelsHeading(n(rows.length))));
4931
+ console.log(sectionHeading(t.report.allLabelsHeading(n(rows.length))));
4804
4932
  for (const row of rows) {
4805
4933
  const saving = row.periodOnly
4806
4934
  ? t.report.allLabelsRowPeriod(formatUsd(row.savingUsd))
@@ -5480,7 +5608,7 @@ async function checkEmbedded(
5480
5608
  }
5481
5609
 
5482
5610
  console.log();
5483
- console.log(c.bold(t.check.embeddedHeading(path, extraction.prompts.length)));
5611
+ console.log(sectionHeading(t.check.embeddedHeading(path, extraction.prompts.length)));
5484
5612
 
5485
5613
  for (const verdict of verdicts) {
5486
5614
  const over = isOverBudget(verdict);
@@ -6063,7 +6191,7 @@ function renderBudget(report: BudgetReport, t: CliMessages, n: (value: number) =
6063
6191
  }
6064
6192
 
6065
6193
  console.log();
6066
- console.log(c.bold(t.store.budgetHeading(standing.period.id)));
6194
+ console.log(sectionHeading(t.store.budgetHeading(standing.period.id)));
6067
6195
 
6068
6196
  if (standing.coverage === 'none') {
6069
6197
  // Nothing measured is never rendered as nothing spent. A dead store and a
@@ -6821,7 +6949,7 @@ async function commandPlan(
6821
6949
  return;
6822
6950
  }
6823
6951
 
6824
- console.log(c.bold(t.plan.heading(n(actions.length), formatUsd(plan.totalUsd))));
6952
+ console.log(sectionHeading(t.plan.heading(n(actions.length), formatUsd(plan.totalUsd))));
6825
6953
  console.log(
6826
6954
  ` ${wrap(t.plan.totals(formatUsd(stamped.projectedSavingUsd), formatUsd(stamped.measuredStakeUsd)), 74, ' ')}`,
6827
6955
  );
@@ -7066,7 +7194,7 @@ async function commandProfile(
7066
7194
  ),
7067
7195
  );
7068
7196
  } else {
7069
- console.log(c.bold(t.profile.fleetHeading(n(rollup.sources.length), formatUsd(rollup.totalUsd), t.profile.calls(rollup.calls))));
7197
+ console.log(sectionHeading(t.profile.fleetHeading(n(rollup.sources.length), formatUsd(rollup.totalUsd), t.profile.calls(rollup.calls))));
7070
7198
  for (const row of rollup.sources) {
7071
7199
  const span = row.spanDays === null ? t.profile.fleetNoClock() : t.profile.fleetSpan(row.spanDays.toFixed(1));
7072
7200
  console.log(
@@ -7140,7 +7268,7 @@ async function commandProfile(
7140
7268
  }
7141
7269
  const cov = report.fieldCoverage;
7142
7270
  const parsed = cov.parsed;
7143
- console.log(c.bold(t.profile.dryRunHeading()));
7271
+ console.log(sectionHeading(t.profile.dryRunHeading()));
7144
7272
  console.log(` ${wrap(t.profile.dryRunParsed(n(parsed), n(report.skippedLines.length)), 74, ' ')}`);
7145
7273
  if (report.unpricedModels.length > 0) {
7146
7274
  console.log(` ${c.yellow('!')} ${wrap(t.profile.dryRunUnpriced(report.unpricedModels.join(', ')), 74, ' ')}`);
@@ -7918,7 +8046,7 @@ async function commandProfile(
7918
8046
  ];
7919
8047
 
7920
8048
  console.log();
7921
- console.log(c.bold(t.profile.heading()));
8049
+ console.log(sectionHeading(t.profile.heading()));
7922
8050
  console.log(` ${t.profile.spent(t.profile.calls(report.total.calls), formatUsd(report.total.totalUsd))}`);
7923
8051
  /**
7924
8052
  * The period, when the log carries a clock — stated, never extrapolated. A
@@ -7984,7 +8112,7 @@ async function commandProfile(
7984
8112
  // Every part, including the zero ones. A row missing because it was zero reads
7985
8113
  // as a row somebody forgot, and "you are not caching at all" is a finding.
7986
8114
  for (const [name, usd, share, tokens] of parts) {
7987
- console.log(` ${c.dim(t.profile.part(name, formatUsd(usd), pct(share), n(tokens)))}`);
8115
+ console.log(` ${bar(share)} ${t.profile.part(name, formatUsd(usd), pct(share), n(tokens))}`);
7988
8116
  }
7989
8117
 
7990
8118
  /**
@@ -8428,7 +8556,7 @@ async function commandProfile(
8428
8556
  */
8429
8557
  const levers = billLevers(report, { catalogue: pricing });
8430
8558
  console.log();
8431
- console.log(c.bold(t.profile.leversHeading()));
8559
+ console.log(sectionHeading(t.profile.leversHeading()));
8432
8560
  /**
8433
8561
  * Every lever below describes a mixture when nothing carries a label.
8434
8562
  *
@@ -8502,7 +8630,7 @@ async function commandProfile(
8502
8630
  */
8503
8631
  if (whatIf !== null) {
8504
8632
  console.log();
8505
- console.log(c.bold(t.profile.whatIfHeading(whatIf.target.displayName)));
8633
+ console.log(sectionHeading(t.profile.whatIfHeading(whatIf.target.displayName)));
8506
8634
  console.log(` ${c.dim(wrap(t.profile.whatIfAssumption(), 74, ' '))}`);
8507
8635
  console.log();
8508
8636
  if (whatIf.slices.length === 0) {
@@ -8589,7 +8717,7 @@ async function commandProfile(
8589
8717
  */
8590
8718
  if (report.conversations.length > 0) {
8591
8719
  console.log();
8592
- console.log(c.bold(t.profile.historyHeading()));
8720
+ console.log(sectionHeading(t.profile.historyHeading()));
8593
8721
  for (const growth of report.conversations.slice(0, 3)) {
8594
8722
  const label = growth.label === UNLABELLED ? t.profile.unlabelled() : growth.label;
8595
8723
  console.log();
@@ -8607,7 +8735,7 @@ async function commandProfile(
8607
8735
  * on the line most likely to be the biggest.
8608
8736
  */
8609
8737
  console.log();
8610
- console.log(c.bold(t.profile.historyHeading()));
8738
+ console.log(sectionHeading(t.profile.historyHeading()));
8611
8739
  console.log(` ${c.dim(wrap(t.profile.historyNoSessions(), 74, ' '))}`);
8612
8740
  }
8613
8741
 
@@ -8625,7 +8753,7 @@ async function commandProfile(
8625
8753
  */
8626
8754
  if (report.outputShapes.length > 0) {
8627
8755
  console.log();
8628
- console.log(c.bold(t.profile.outputShapeHeading()));
8756
+ console.log(sectionHeading(t.profile.outputShapeHeading()));
8629
8757
  for (const shape of report.outputShapes.slice(0, 3)) {
8630
8758
  const label = shape.label === UNLABELLED ? t.profile.unlabelled() : shape.label;
8631
8759
  const isTail = shape.heavyCallShare < 0.25;
@@ -8671,7 +8799,7 @@ async function commandProfile(
8671
8799
  */
8672
8800
  if (report.inputShapes.length > 0) {
8673
8801
  console.log();
8674
- console.log(c.bold(t.profile.inputShapeHeading()));
8802
+ console.log(sectionHeading(t.profile.inputShapeHeading()));
8675
8803
  for (const shape of report.inputShapes.slice(0, 3)) {
8676
8804
  const label = shape.label === UNLABELLED ? t.profile.unlabelled() : shape.label;
8677
8805
  console.log();
@@ -8735,7 +8863,7 @@ async function commandProfile(
8735
8863
  {
8736
8864
  if (pressures.length > 0) {
8737
8865
  console.log();
8738
- console.log(c.bold(t.profile.pressureHeading()));
8866
+ console.log(sectionHeading(t.profile.pressureHeading()));
8739
8867
  for (const row of pressures.slice(0, 3)) {
8740
8868
  const label = row.label === UNLABELLED ? t.profile.unlabelled() : row.label;
8741
8869
  const line = t.profile.pressureLine(
@@ -8767,7 +8895,7 @@ async function commandProfile(
8767
8895
  );
8768
8896
  if (moved.length > 0) {
8769
8897
  console.log();
8770
- console.log(c.bold(t.profile.mixDriftHeading()));
8898
+ console.log(sectionHeading(t.profile.mixDriftHeading()));
8771
8899
  for (const m of moved.slice(0, 3)) {
8772
8900
  console.log();
8773
8901
  console.log(
@@ -8790,7 +8918,7 @@ async function commandProfile(
8790
8918
  */
8791
8919
  if (report.repeatedTurns.length > 0) {
8792
8920
  console.log();
8793
- console.log(c.bold(t.profile.repeatsHeading()));
8921
+ console.log(sectionHeading(t.profile.repeatsHeading()));
8794
8922
  for (const row of report.repeatedTurns.slice(0, 3)) {
8795
8923
  const label = row.label === UNLABELLED ? t.profile.unlabelled() : row.label;
8796
8924
  console.log();
@@ -8884,7 +9012,7 @@ async function commandProfile(
8884
9012
  */
8885
9013
  if (previous !== null) {
8886
9014
  console.log();
8887
- console.log(c.bold(t.profile.againstHeading()));
9015
+ console.log(sectionHeading(t.profile.againstHeading()));
8888
9016
  if (previous.total.calls === 0) {
8889
9017
  console.log(` ${c.dim(wrap(t.profile.againstNothingPriced(), 74, ' '))}`);
8890
9018
  } else {
@@ -8991,10 +9119,10 @@ async function commandProfile(
8991
9119
  ] as const) {
8992
9120
  if (rows.length <= 1) continue; // One row is the total again, said twice.
8993
9121
  console.log();
8994
- console.log(c.bold(heading));
9122
+ console.log(sectionHeading(heading));
8995
9123
  for (const [name, breakdown] of rows) {
8996
9124
  const share = report.total.totalUsd > 0 ? breakdown.totalUsd / report.total.totalUsd : 0;
8997
- console.log(` ${t.profile.row(name, formatUsd(breakdown.totalUsd), pct(share), t.profile.calls(breakdown.calls))}`);
9125
+ console.log(` ${bar(share)} ${t.profile.row(name, formatUsd(breakdown.totalUsd), pct(share), t.profile.calls(breakdown.calls))}`);
8998
9126
  }
8999
9127
  }
9000
9128
 
@@ -9027,7 +9155,7 @@ async function commandProfile(
9027
9155
  const outcomes = outcomeReport(report.outcomeTally, config.outcomes ?? null);
9028
9156
  if (outcomes.coverage.recorded > 0) {
9029
9157
  console.log();
9030
- console.log(c.bold(t.profile.outcomeHeading()));
9158
+ console.log(sectionHeading(t.profile.outcomeHeading()));
9031
9159
 
9032
9160
  const col = t.profile.outcomeColumns;
9033
9161
  const rows = [...outcomes.slices, ...outcomes.undeclared].map((slice) => ({
@@ -9108,7 +9236,7 @@ async function commandProfile(
9108
9236
  );
9109
9237
  if (ranking.byCall.length > 0) {
9110
9238
  console.log();
9111
- console.log(c.bold(t.profile.perOutcomeHeading()));
9239
+ console.log(sectionHeading(t.profile.perOutcomeHeading()));
9112
9240
  const pcol = t.profile.perOutcomeColumns;
9113
9241
  const prows = ranking.byCall.map((slice) => ({
9114
9242
  key: slice.key,
@@ -9201,7 +9329,7 @@ async function commandProfile(
9201
9329
  }
9202
9330
  if (missing.length > 0) {
9203
9331
  console.log();
9204
- console.log(c.bold(t.profile.coverageHeading()));
9332
+ console.log(sectionHeading(t.profile.coverageHeading()));
9205
9333
  for (const line of missing) console.log(` ${c.dim(wrap(line, 74, ' '))}`);
9206
9334
  }
9207
9335
  }
@@ -9857,7 +9985,7 @@ async function checkDirectory(
9857
9985
  );
9858
9986
 
9859
9987
  console.log();
9860
- console.log(c.bold(t.check.directoryHeading(root, verdicts.length)));
9988
+ console.log(sectionHeading(t.check.directoryHeading(root, verdicts.length)));
9861
9989
  console.log();
9862
9990
 
9863
9991
  for (const verdict of verdicts) {
@@ -10006,7 +10134,7 @@ async function commandPrune(args: Args, t: CliMessages): Promise<void> {
10006
10134
 
10007
10135
  const pct = (value: number): string => `${(value * 100).toFixed(0)}%`;
10008
10136
  console.log();
10009
- console.log(c.bold(t.prune.heading(provider.model)));
10137
+ console.log(sectionHeading(t.prune.heading(provider.model)));
10010
10138
  console.log(` ${c.dim(t.prune.selfAgreement(pct(report.selfAgreement)))}`);
10011
10139
  console.log();
10012
10140
 
@@ -10099,7 +10227,7 @@ async function commandEval(
10099
10227
 
10100
10228
  const pct = (value: number): string => `${(value * 100).toFixed(0)}%`;
10101
10229
  console.log();
10102
- console.log(c.bold(t.eval.heading()));
10230
+ console.log(sectionHeading(t.eval.heading()));
10103
10231
  console.log(` ${t.eval.selfAgreement(pct(report.selfAgreement))}`);
10104
10232
  console.log(` ${t.eval.crossAgreement(pct(report.crossAgreement))}`);
10105
10233
  console.log();
@@ -10301,7 +10429,7 @@ function printComparison(
10301
10429
  const signed = (value: number): string => `${value > 0 ? '+' : ''}${n(value)}`;
10302
10430
 
10303
10431
  console.log();
10304
- console.log(c.bold(t.diff.heading(beforePath, afterPath)));
10432
+ console.log(sectionHeading(t.diff.heading(beforePath, afterPath)));
10305
10433
  if (optimized) console.log(c.dim(` ${t.diff.measuringOptimised()}`));
10306
10434
  console.log();
10307
10435
  console.log(
@@ -11097,6 +11225,12 @@ async function main(): Promise<void> {
11097
11225
  case 'from-otel':
11098
11226
  await commandFromOtel(args, t);
11099
11227
  break;
11228
+ case 'switch':
11229
+ await commandSwitch(args, pricing, t);
11230
+ break;
11231
+ case 'ownrate':
11232
+ commandOwnrate(args, t);
11233
+ break;
11100
11234
  case 'pulse':
11101
11235
  await commandPulse(args, t);
11102
11236
  break;