@trazum/cli 1.51.0 → 1.51.2

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);
@@ -2354,6 +2356,19 @@ async function commandReport(args, config, pricing, t) {
2354
2356
  }))
2355
2357
  .sort((a, b) => a.month.localeCompare(b.month));
2356
2358
  const record = annualRecord(year, periods);
2359
+ /**
2360
+ * `--json` is the document *instead of* the report, not after it.
2361
+ *
2362
+ * It used to print the human report and then append the JSON, and the help
2363
+ * said "Also emit". That made the one command emitting the `annual-record`
2364
+ * contract the one command whose output no machine can read: `| jq` and
2365
+ * `| trazum conform -` both fail on the prose in front. Every other `--json`
2366
+ * in this CLI returns here rather than adding to what was printed.
2367
+ */
2368
+ if (boolFlag(args, 'json')) {
2369
+ console.log(JSON.stringify(record, null, 2));
2370
+ return;
2371
+ }
2357
2372
  const n = (value) => value.toLocaleString(t.numberLocale);
2358
2373
  console.log();
2359
2374
  console.log(c.bold(t.annual.heading(year)));
@@ -2391,9 +2406,6 @@ async function commandReport(args, config, pricing, t) {
2391
2406
  console.log();
2392
2407
  console.log(` ${c.dim(wrap(t.annual.noNewData(), 74, ' '))}`);
2393
2408
  console.log();
2394
- if (boolFlag(args, 'json')) {
2395
- console.log(JSON.stringify(record, null, 2));
2396
- }
2397
2409
  }
2398
2410
  function commandModels(t, pricing) {
2399
2411
  const n = (value) => value.toLocaleString(t.numberLocale);