@trazum/cli 1.63.0 → 1.65.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
@@ -9,6 +9,7 @@ import { gunzipSync } from 'node:zlib';
9
9
 
10
10
  import {
11
11
  CONTRACT_NAMES,
12
+ contractSchema,
12
13
  applyRewrites,
13
14
  BASELINE_FILENAME,
14
15
  BASELINE_VERSION,
@@ -238,6 +239,7 @@ import {
238
239
  renderRankMarkdown,
239
240
  renderProfileMarkdown,
240
241
  } from './markdown.js';
242
+ import { renderProfileHtml, renderRollupHtml } from './html.js';
241
243
  import type { CliMessages } from './i18n/index.js';
242
244
 
243
245
  // --------------------------------------------------------------------------
@@ -331,6 +333,7 @@ const VALUE_FLAGS = new Set([
331
333
  'locale',
332
334
  'config',
333
335
  'markdown-out',
336
+ 'html-out',
334
337
  'otlp-out',
335
338
  'pricing',
336
339
  'prompt',
@@ -617,7 +620,7 @@ const COMMAND_FLAGS: Record<string, string[]> = {
617
620
  ],
618
621
  check: ['max-tokens', 'level', 'exact-tokens', 'markdown-out', 'baseline'],
619
622
  baseline: ['model', 'calls', 'output-tokens', 'cache-hit-rate', 'batch', 'exact-tokens', 'out', 'o'],
620
- profile: ['json', 'pricing', 'pricing-live', 'against', 'what-if', 'markdown-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'],
623
+ 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'],
621
624
  plan: ['json', 'out', 'markdown-out', 'min-usd', 'pricing', 'pricing-live'],
622
625
  verify: ['against', 'gate', 'json', 'markdown-out', 'pricing', 'pricing-live'],
623
626
  history: ['store', 'json', 'markdown-out'],
@@ -633,7 +636,8 @@ const COMMAND_FLAGS: Record<string, string[]> = {
633
636
  rank: ['level', 'model', 'calls', 'output-tokens', 'batch', 'disable', 'prompt', 'markdown-out'],
634
637
  init: ['dry-run', 'yes', 'json', 'pricing', 'pricing-live'],
635
638
  conform: ['contract', 'json'],
636
- rollup: ['json'],
639
+ schema: [],
640
+ rollup: ['json', 'html-out'],
637
641
  pulse: ['json', 'max-stale-hours'],
638
642
  bench: ['workload', 'json', 'record', 'against', 'max-ratio'],
639
643
  write: ['answers', 'json', 'out', 'o', 'calls', 'avg-output'],
@@ -2193,6 +2197,14 @@ async function commandRollup(args: Args, t: CliMessages): Promise<void> {
2193
2197
 
2194
2198
  const document = rollUp(inputs);
2195
2199
 
2200
+ // The HTML door, on both output paths — a side file that vanished under
2201
+ // --json is the fault the profile's --csv-out already taught this file.
2202
+ const htmlOut = stringFlag(args, 'html-out');
2203
+ if (htmlOut !== undefined) {
2204
+ await writeFile(htmlOut, renderRollupHtml(document, t), 'utf8');
2205
+ console.error(c.dim(t.html.written(htmlOut)));
2206
+ }
2207
+
2196
2208
  if (boolFlag(args, 'json')) {
2197
2209
  console.log(JSON.stringify(document, null, 2));
2198
2210
  // A rejected contribution is a machine missing from the total, so it gates
@@ -2879,6 +2891,26 @@ async function readBenchBaseline(path: string, t: CliMessages): Promise<BenchBas
2879
2891
  return candidate;
2880
2892
  }
2881
2893
 
2894
+
2895
+ /**
2896
+ * `trazum schema <contract>` — the format, portable.
2897
+ *
2898
+ * Prints the JSON Schema for a named contract, so a document can be checked
2899
+ * by any off-the-shelf validator with no Trazum installed. The output is the
2900
+ * schema and nothing else — pipeable by construction, like `--json`
2901
+ * everywhere — and the refusal with no or an unknown name lists every
2902
+ * contract, derived from the same list `--contract` accepts, the way the
2903
+ * gateway names its providers.
2904
+ */
2905
+ function commandSchema(args: Args, t: CliMessages): void {
2906
+ const name = args.positional[0];
2907
+ if (name === undefined) throw new Error(t.schema.noTarget(CONTRACT_NAMES.join(', ')));
2908
+ if (!(CONTRACT_NAMES as readonly string[]).includes(name)) {
2909
+ throw new Error(t.schema.unknown(name, CONTRACT_NAMES.join(', ')));
2910
+ }
2911
+ console.log(JSON.stringify(contractSchema(name as (typeof CONTRACT_NAMES)[number]), null, 2));
2912
+ }
2913
+
2882
2914
  async function commandBench(args: Args, t: CliMessages): Promise<void> {
2883
2915
  const asJson = boolFlag(args, 'json');
2884
2916
  const chosen = stringFlag(args, 'workload');
@@ -7329,11 +7361,26 @@ async function commandProfile(
7329
7361
  * comment. Written from the same message catalogue the terminal used, because
7330
7362
  * two renderings of one finding drift the moment they are worded twice.
7331
7363
  */
7332
- const markdownOut = stringFlag(args, 'markdown-out');
7333
- if (markdownOut !== undefined) {
7334
- await writeFile(
7335
- markdownOut,
7336
- renderProfileMarkdown({
7364
+ const markdownOut = stringFlag(args, 'markdown-out');
7365
+ const htmlOut = stringFlag(args, 'html-out');
7366
+ if (markdownOut !== undefined || htmlOut !== undefined) {
7367
+ /**
7368
+ * Derived here, not borrowed from the terminal path. Under `--json`
7369
+ * that path never runs, and the outer `levers` this block used to
7370
+ * reach for was an uninitialised binding — `profile --json
7371
+ * --markdown-out` crashed with a ReferenceError from 1.59 until the
7372
+ * HTML door's test drove both flags together and found it. The flag
7373
+ * did not silently do nothing; it loudly did nothing, and no test had
7374
+ * ever asked.
7375
+ */
7376
+ const levers = billLevers(report, { catalogue: pricing });
7377
+ const cache = cacheEconomics(report.total);
7378
+ /**
7379
+ * One input object for both doors, built once: the HTML file and the
7380
+ * Markdown file are two projections of the same figures, and building
7381
+ * the input twice is how two renderings of one bill start disagreeing.
7382
+ */
7383
+ const renderInput = ({
7337
7384
  report,
7338
7385
  levers,
7339
7386
  cache,
@@ -7375,10 +7422,15 @@ async function commandProfile(
7375
7422
  },
7376
7423
  }
7377
7424
  : {}),
7378
- }),
7379
- 'utf8',
7380
- );
7381
- notice(c.dim(t.report.wroteTo(markdownOut)));
7425
+ });
7426
+ if (markdownOut !== undefined) {
7427
+ await writeFile(markdownOut, renderProfileMarkdown(renderInput), 'utf8');
7428
+ notice(c.dim(t.report.wroteTo(markdownOut)));
7429
+ }
7430
+ if (htmlOut !== undefined) {
7431
+ await writeFile(htmlOut, renderProfileHtml(renderInput), 'utf8');
7432
+ notice(c.dim(t.html.written(htmlOut)));
7433
+ }
7382
7434
  }
7383
7435
 
7384
7436
  /**
@@ -10614,6 +10666,9 @@ async function main(): Promise<void> {
10614
10666
  case 'conform':
10615
10667
  await commandConform(args, t);
10616
10668
  break;
10669
+ case 'schema':
10670
+ commandSchema(args, t);
10671
+ break;
10617
10672
  case 'rollup':
10618
10673
  await commandRollup(args, t);
10619
10674
  break;