@trazum/cli 1.51.1 → 1.52.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/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import { open, readdir, readFile, stat, writeFile } from 'node:fs/promises';
4
4
  import { dirname, join, resolve as resolvePath } from 'node:path';
5
5
  import { fileURLToPath } from 'node:url';
6
6
  import { gunzipSync } from 'node:zlib';
7
- import { applyRewrites, BASELINE_FILENAME, BASELINE_VERSION, breaches, cacheableMinimum, analyzeCachePrefix, billLevers, bucketedCacheEconomics, bucketedProfile, buildHistory, buildPlan, connectorFor, CONNECTORS, normalizeAnthropicUsage, normalizeOpenAIUsage, bucketsFromRecords, evaluateWatch, firedKey, pruneRecords, recordsFromBuckets, storeInventory, storedReportFrom, verifyPlan, cacheEconomics, cacheHitRate, contextPressure, comparePrompts, compareToBaseline, computeSavings, countTokensAnthropic, DEFAULT_USAGE, budgetPositions, conform, BREAK_EVEN_BAND, allocate, annualRecord, replayCommitment, coversTheTerm, runExperiment, qualityGate, semanticPassCost, verifySemanticProposals, SEMANTIC_SYSTEM_PROMPT, ladderPosition, validateLadder, outcomeReport, rankPerOutcome, FAILURE_POLICIES, detectFromSource, matchLocale, parsePlanDocument, waiverDay, waiverHistory, proposeInit, MIN_RATE_DAYS, parseConfig, coverageDrift, driversBetween, explainGateFailure, assignSources, fleetRollup, labelCoverage, measuredUsage, gateMargin, GATE_MARGIN_TIGHT, estimateTokens, evaluate, extractPrompts, findExamples, formatBaseline, formatSignedUsd, formatUsd, getMessages, getModel, hasMarker, LOCALES, MAX_BASELINE_BYTES, moneyIsComparable, mostSpecificMatch, nearestName, optimize, parseBaseline, PHRASE_LANGUAGES, plannedCalls, profilePrompt, profileToCsv, profileUsage, promptId, providerFromEnv, pruneExamples, refineWithLlm, rejectionText, reorderForCache, repriceProfile, reviewAgeDays, reviewExamples, RULES, sharedPrefixes, sharesOf, SOURCE_EXTENSIONS, suggestRewrites, toOtlpMetrics, toPromptfoo, TTL_1H_MS, UNLABELLED, withExactTokenCounts, } from '@trazum/core';
7
+ import { CONTRACT_NAMES, applyRewrites, BASELINE_FILENAME, BASELINE_VERSION, breaches, cacheableMinimum, analyzeCachePrefix, billLevers, bucketedCacheEconomics, bucketedProfile, buildHistory, buildPlan, connectorFor, CONNECTORS, normalizeAnthropicUsage, normalizeOpenAIUsage, bucketsFromRecords, evaluateWatch, firedKey, pruneRecords, recordsFromBuckets, storeInventory, storedReportFrom, verifyPlan, cacheEconomics, cacheHitRate, contextPressure, comparePrompts, compareToBaseline, computeSavings, countTokensAnthropic, DEFAULT_USAGE, budgetPositions, conform, BREAK_EVEN_BAND, allocate, annualRecord, replayCommitment, coversTheTerm, runExperiment, qualityGate, semanticPassCost, verifySemanticProposals, SEMANTIC_SYSTEM_PROMPT, ladderPosition, validateLadder, outcomeReport, rankPerOutcome, FAILURE_POLICIES, detectFromSource, matchLocale, parsePlanDocument, waiverDay, waiverHistory, proposeInit, MIN_RATE_DAYS, parseConfig, coverageDrift, driversBetween, explainGateFailure, assignSources, fleetRollup, labelCoverage, measuredUsage, gateMargin, GATE_MARGIN_TIGHT, estimateTokens, evaluate, extractPrompts, findExamples, formatBaseline, formatSignedUsd, formatUsd, getMessages, getModel, hasMarker, LOCALES, MAX_BASELINE_BYTES, moneyIsComparable, mostSpecificMatch, nearestName, optimize, parseBaseline, PHRASE_LANGUAGES, plannedCalls, profilePrompt, profileToCsv, profileUsage, promptId, providerFromEnv, pruneExamples, refineWithLlm, rejectionText, reorderForCache, repriceProfile, reviewAgeDays, reviewExamples, RULES, sharedPrefixes, sharesOf, SOURCE_EXTENSIONS, suggestRewrites, toOtlpMetrics, toPromptfoo, TTL_1H_MS, UNLABELLED, withExactTokenCounts, } from '@trazum/core';
8
8
  import { cacheDir, cacheStats, cachingProvider, clearCache } from './suggest-cache.js';
9
9
  import { dayOf, formatGap, median, spanDays } from './time.js';
10
10
  // Everything that reads the filesystem, on its own entry point so the web
@@ -1099,16 +1099,15 @@ const VERSION = (() => {
1099
1099
  const FEEDBACK_REPO = 'https://github.com/Davmunrey/Trazum';
1100
1100
  /** Problems listed before the rest are counted. A wall of them helps nobody. */
1101
1101
  const MAX_CONFORM_PROBLEMS = 20;
1102
- /** The contracts `--contract` accepts, so a typo is refused with the list. */
1103
- const CONTRACT_NAMES = [
1104
- 'usage-log',
1105
- 'profile',
1106
- 'plan',
1107
- 'verification',
1108
- 'history',
1109
- 'connected',
1110
- 'cost-answer',
1111
- ];
1102
+ /**
1103
+ * The contracts `--contract` accepts, so a typo is refused with the list.
1104
+ *
1105
+ * Imported, never retyped. This was a hand-written copy of the union in
1106
+ * `conform.ts` and it stopped at `cost-answer`: `outcome-report` (1.50.4) and
1107
+ * `annual-record` (1.51.0) had rules, had cross-rules, and were refused by name
1108
+ * with "is not a contract" — the list telling the caller they had made a typo
1109
+ * when the list was the thing that was wrong.
1110
+ */
1112
1111
  /** How many source files, and how large each may be. Both reported when they bite. */
1113
1112
  const INIT_MAX_SOURCE_FILES = 400;
1114
1113
  const INIT_MAX_SOURCE_BYTES = 256 * 1024;
@@ -1479,7 +1478,10 @@ async function commandConform(args, t) {
1479
1478
  if (target === undefined)
1480
1479
  throw new Error(t.conform.noTarget());
1481
1480
  const named = stringFlag(args, 'contract');
1482
- if (named !== undefined && !CONTRACT_NAMES.includes(named)) {
1481
+ // Widened for the membership test only: the array is `as const` so the union
1482
+ // is derived from it, and narrowing back is what `isContract` does below.
1483
+ const isContract = (value) => CONTRACT_NAMES.includes(value);
1484
+ if (named !== undefined && !isContract(named)) {
1483
1485
  throw new Error(t.conform.badContract(named, CONTRACT_NAMES.join(', ')));
1484
1486
  }
1485
1487
  const text = target === '-' ? await readInput('-', t) : await readUsageLog(target, t);
@@ -1649,6 +1651,14 @@ async function commandGateway(args, config, configDir, pricing, t) {
1649
1651
  asOfMs: Date.now(),
1650
1652
  };
1651
1653
  const measured = { calls: 0, usd: 0 };
1654
+ /**
1655
+ * Forwarded calls whose cost this session cannot see.
1656
+ *
1657
+ * Counted separately and never folded into `measured`: the money was spent,
1658
+ * so the two are not interchangeable, and a total that quietly absorbed them
1659
+ * would be the flattering direction.
1660
+ */
1661
+ let unmeasured = 0;
1652
1662
  const server = buildGateway({
1653
1663
  provider,
1654
1664
  catalogue: pricing,
@@ -1661,6 +1671,10 @@ async function commandGateway(args, config, configDir, pricing, t) {
1661
1671
  measured.calls += 1;
1662
1672
  console.error(c.dim(t.gateway.measured(call.model, call.label, call.inputTokens, call.outputTokens, call.substituted)));
1663
1673
  },
1674
+ unmeasured: (cause) => {
1675
+ unmeasured += 1;
1676
+ console.error(c.yellow(` ${t.gateway.unmeasured(cause, unmeasured)}`));
1677
+ },
1664
1678
  note: (line) => {
1665
1679
  console.error(c.yellow(` ${line}`));
1666
1680
  },
@@ -2354,6 +2368,19 @@ async function commandReport(args, config, pricing, t) {
2354
2368
  }))
2355
2369
  .sort((a, b) => a.month.localeCompare(b.month));
2356
2370
  const record = annualRecord(year, periods);
2371
+ /**
2372
+ * `--json` is the document *instead of* the report, not after it.
2373
+ *
2374
+ * It used to print the human report and then append the JSON, and the help
2375
+ * said "Also emit". That made the one command emitting the `annual-record`
2376
+ * contract the one command whose output no machine can read: `| jq` and
2377
+ * `| trazum conform -` both fail on the prose in front. Every other `--json`
2378
+ * in this CLI returns here rather than adding to what was printed.
2379
+ */
2380
+ if (boolFlag(args, 'json')) {
2381
+ console.log(JSON.stringify(record, null, 2));
2382
+ return;
2383
+ }
2357
2384
  const n = (value) => value.toLocaleString(t.numberLocale);
2358
2385
  console.log();
2359
2386
  console.log(c.bold(t.annual.heading(year)));
@@ -2391,9 +2418,6 @@ async function commandReport(args, config, pricing, t) {
2391
2418
  console.log();
2392
2419
  console.log(` ${c.dim(wrap(t.annual.noNewData(), 74, ' '))}`);
2393
2420
  console.log();
2394
- if (boolFlag(args, 'json')) {
2395
- console.log(JSON.stringify(record, null, 2));
2396
- }
2397
2421
  }
2398
2422
  function commandModels(t, pricing) {
2399
2423
  const n = (value) => value.toLocaleString(t.numberLocale);