@trazum/cli 2.5.1 → 2.5.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/README.md +75 -6
- package/dist/filter.d.ts +2 -0
- package/dist/filter.d.ts.map +1 -0
- package/dist/filter.js +151 -0
- package/dist/filter.js.map +1 -0
- package/dist/gateway-server.d.ts +2 -0
- package/dist/gateway-server.d.ts.map +1 -1
- package/dist/gateway-server.js +49 -9
- package/dist/gateway-server.js.map +1 -1
- package/dist/gateway-spend.d.ts +32 -0
- package/dist/gateway-spend.d.ts.map +1 -0
- package/dist/gateway-spend.js +116 -0
- package/dist/gateway-spend.js.map +1 -0
- package/dist/html.d.ts.map +1 -1
- package/dist/html.js +22 -1
- package/dist/html.js.map +1 -1
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +29 -3
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/es.d.ts.map +1 -1
- package/dist/i18n/es.js +29 -3
- package/dist/i18n/es.js.map +1 -1
- package/dist/i18n/types.d.ts +13 -1
- package/dist/i18n/types.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +118 -61
- package/dist/index.js.map +1 -1
- package/dist/markdown.d.ts.map +1 -1
- package/dist/markdown.js +19 -1
- package/dist/markdown.js.map +1 -1
- package/dist/pdf.d.ts.map +1 -1
- package/dist/pdf.js +38 -1
- package/dist/pdf.js.map +1 -1
- package/dist/serve-savings-schema.d.ts +65 -0
- package/dist/serve-savings-schema.d.ts.map +1 -0
- package/dist/serve-savings-schema.js +54 -0
- package/dist/serve-savings-schema.js.map +1 -0
- package/dist/serve-savings.d.ts +55 -0
- package/dist/serve-savings.d.ts.map +1 -0
- package/dist/serve-savings.js +144 -0
- package/dist/serve-savings.js.map +1 -0
- package/dist/serve-schema.d.ts +536 -0
- package/dist/serve-schema.d.ts.map +1 -0
- package/dist/serve-schema.js +143 -0
- package/dist/serve-schema.js.map +1 -0
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +30 -5
- package/dist/serve.js.map +1 -1
- package/package.json +2 -2
- package/src/filter.ts +114 -0
- package/src/gateway-server.ts +46 -10
- package/src/gateway-spend.ts +120 -0
- package/src/html.ts +25 -1
- package/src/i18n/en.ts +31 -4
- package/src/i18n/es.ts +31 -4
- package/src/i18n/types.ts +14 -1
- package/src/index.ts +108 -63
- package/src/markdown.ts +20 -1
- package/src/pdf.ts +36 -1
- package/src/serve-savings-schema.ts +53 -0
- package/src/serve-savings.ts +140 -0
- package/src/serve-schema.ts +147 -0
- package/src/serve.ts +31 -5
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { createInterface } from 'node:readline/promises';
|
|
|
7
7
|
import { dirname, join, resolve as resolvePath } from 'node:path';
|
|
8
8
|
import { fileURLToPath } from 'node:url';
|
|
9
9
|
import { gunzipSync } from 'node:zlib';
|
|
10
|
-
import { CONTRACT_NAMES, contractSchema, 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, bandGoverns, 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, rollUp, heartbeats, ruleYield, labelCoverage, measuredUsage, gateMargin, GATE_MARGIN_TIGHT, estimateTokens, evaluate, extractPrompts, findExamples, formatBaseline, formatSignedUsd, formatUsd, receiptFrom, getMessages, getModel, hasMarker, LOCALES, MAX_BASELINE_BYTES, matchGlob, MAX_INPUT_CHARS, moneyIsComparable, mostSpecificMatch, assemble, interview, nearestName, slot, SLOT_IDS, optimize, parseBaseline, PHRASE_LANGUAGES, detectTextLanguage, dictionaryStanding, languagesWithStanding, indexUsage, parseUsageLine, plannedCalls, claudeCodeRecords, ESTIMATE_ERROR_BAND_PCT, bandFor, foreignTokenizer, measuredForeignError, anthropicCostReport, anthropicUsageRecords, looksLikeOpenaiCost, looksLikeAnthropicCost, looksLikeAnthropicUsage, looksLikeClaudeCodeTranscript, looksLikeHelicone, looksLikeLangsmith, looksLikeLiteLlm, looksLikeOpenaiUsage, looksLikeOpenrouterActivity, looksLikeOtel, openaiCostReport, openaiUsageRecords, openrouterActivityRecords, reconcile, heliconeRecords, langsmithRecords, litellmRecords, otelRecords, ownRate, positionAt, positionReport, PRICING_LAST_REVIEWED, reviewedForModels, PROVIDER_REVIEWED, STALE_PRICING_DAYS, profilePrompt, profileToCsv, profileUsage, promptId, providerFromEnv, pruneExamples, refineWithLlm, rejectionText, reorderForCache, repriceProfile, switchAnalysis, reviewAgeDays, reviewExamples, RULES, sharedPrefixes, sharesOf, isOffered, SOURCE_EXTENSIONS, suggestRewrites, toOtlpMetrics, toPromptfoo, UNLABELLED, withExactTokenCounts, } from '@trazum/core';
|
|
10
|
+
import { CONTRACT_NAMES, contractSchema, 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, bandGoverns, 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, rollUp, heartbeats, ruleYield, labelCoverage, measuredUsage, gateMargin, GATE_MARGIN_TIGHT, estimateTokens, evaluate, extractPrompts, findExamples, formatBaseline, formatSignedUsd, formatUsd, receiptFrom, getMessages, getModel, hasMarker, LOCALES, MAX_BASELINE_BYTES, matchGlob, MAX_INPUT_CHARS, moneyIsComparable, mostSpecificMatch, assemble, interview, nearestName, slot, SLOT_IDS, optimize, parseBaseline, PHRASE_LANGUAGES, detectTextLanguage, dictionaryStanding, languagesWithStanding, indexUsage, parseUsageLine, plannedCalls, claudeCodeRecords, codexRecords, looksLikeCodexTranscript, ESTIMATE_ERROR_BAND_PCT, bandFor, foreignTokenizer, measuredForeignError, anthropicCostReport, anthropicUsageRecords, looksLikeOpenaiCost, looksLikeAnthropicCost, looksLikeAnthropicUsage, looksLikeClaudeCodeTranscript, looksLikeHelicone, looksLikeLangsmith, looksLikeLiteLlm, looksLikeOpenaiUsage, looksLikeOpenrouterActivity, looksLikeOtel, openaiCostReport, openaiUsageRecords, openrouterActivityRecords, reconcile, heliconeRecords, langsmithRecords, litellmRecords, otelRecords, ownRate, positionAt, positionReport, PRICING_LAST_REVIEWED, reviewedForModels, PROVIDER_REVIEWED, STALE_PRICING_DAYS, profilePrompt, profileToCsv, profileUsage, promptId, providerFromEnv, pruneExamples, refineWithLlm, rejectionText, reorderForCache, repriceProfile, switchAnalysis, reviewAgeDays, reviewExamples, RULES, sharedPrefixes, sharesOf, spendByMonth, isOffered, SOURCE_EXTENSIONS, suggestRewrites, toOtlpMetrics, toPromptfoo, UNLABELLED, withExactTokenCounts, } from '@trazum/core';
|
|
11
11
|
import { cacheDir, cacheStats, cachingProvider, clearCache } from './suggest-cache.js';
|
|
12
12
|
import { OPTIONAL_COUNTERS } from './optional-counters.js';
|
|
13
13
|
import { dayOf, formatGap, median, spanDays } from './time.js';
|
|
@@ -34,6 +34,7 @@ import { renderProfilePdf } from './pdf.js';
|
|
|
34
34
|
// to plain output, and a pipe stays plain.
|
|
35
35
|
import { bar, c, sectionHeading, table } from './style.js';
|
|
36
36
|
const VALUE_FLAGS = new Set([
|
|
37
|
+
'recovery-dir',
|
|
37
38
|
'answers',
|
|
38
39
|
'label-by-cwd',
|
|
39
40
|
'label-by-workspace',
|
|
@@ -397,6 +398,7 @@ function disabledRules(args, config) {
|
|
|
397
398
|
*/
|
|
398
399
|
const GLOBAL_FLAGS = ['help', 'h', 'version', 'v', 'locale', 'json', 'config', 'pricing', 'pricing-live', 'max-input'];
|
|
399
400
|
const COMMAND_FLAGS = {
|
|
401
|
+
filter: ['recovery-dir'],
|
|
400
402
|
optimize: [
|
|
401
403
|
'level', 'model', 'calls', 'output-tokens', 'cache-hit-rate', 'batch',
|
|
402
404
|
'disable', 'llm', 'exact-tokens', 'diff', 'reorder', 'out', 'o',
|
|
@@ -425,6 +427,7 @@ const COMMAND_FLAGS = {
|
|
|
425
427
|
rollup: ['json', 'html-out'],
|
|
426
428
|
position: ['json', 'html-out', 'pricing', 'pricing-live'],
|
|
427
429
|
receipt: ['out', 'o', 'stamp', 'pricing', 'pricing-live', 'since', 'until'],
|
|
430
|
+
'from-codex': ['label', 'out', 'o'],
|
|
428
431
|
'from-claude-code': ['label', 'label-by-cwd', 'label-from-project', 'out', 'o', 'state'],
|
|
429
432
|
'from-otel': ['label-from-service', 'out', 'o'],
|
|
430
433
|
'from-litellm': ['out', 'o'],
|
|
@@ -890,6 +893,10 @@ measured = null) {
|
|
|
890
893
|
* a measurable one, and it is the honest answer to "what did I gain" on a plan
|
|
891
894
|
* that costs the same either way.
|
|
892
895
|
*/
|
|
896
|
+
/** A conservative display default, never evidence of a payment arrangement. */
|
|
897
|
+
function prefersTokenReport(host) {
|
|
898
|
+
return ['claude-code', 'codex', 'cursor'].includes(host.id);
|
|
899
|
+
}
|
|
893
900
|
function printTokensOnly(result, host, t, n,
|
|
894
901
|
/** Whether they named a scenario while the money was being withheld. */
|
|
895
902
|
namedScenario = false) {
|
|
@@ -897,10 +904,7 @@ namedScenario = false) {
|
|
|
897
904
|
const saved = result.tokensBefore - result.tokensAfter;
|
|
898
905
|
console.log();
|
|
899
906
|
console.log(sectionHeading(t.report.tokensOnlyHeading(host.displayName)));
|
|
900
|
-
|
|
901
|
-
// flag on GitHub Actions, the first version said "GitHub Actions bills by
|
|
902
|
-
// subscription", which is simply false.
|
|
903
|
-
console.log(` ${host.billing === 'subscription'
|
|
907
|
+
console.log(` ${prefersTokenReport(host)
|
|
904
908
|
? t.report.tokensOnlyWhy(host.displayName)
|
|
905
909
|
: t.report.tokensOnlyAsked()}`);
|
|
906
910
|
console.log();
|
|
@@ -1142,12 +1146,7 @@ async function commandWhere(args, config, pricing, t) {
|
|
|
1142
1146
|
console.log();
|
|
1143
1147
|
console.log(c.bold(t.where.hostHeading()));
|
|
1144
1148
|
console.log(` ${host.displayName}${host.evidence ? c.dim(` (${host.evidence})`) : ''}`);
|
|
1145
|
-
|
|
1146
|
-
// figure Trazum computes is arithmetic about tokens, not money anybody gets
|
|
1147
|
-
// back, and saying so is more useful than saying nothing.
|
|
1148
|
-
if (host.billing === 'subscription') {
|
|
1149
|
-
console.log(` ${c.yellow(t.where.subscription(host.displayName))}`);
|
|
1150
|
-
}
|
|
1149
|
+
console.log(` ${c.dim(t.where.billingUnknown(host.displayName))}`);
|
|
1151
1150
|
const target = args.positional[0];
|
|
1152
1151
|
if (target === undefined) {
|
|
1153
1152
|
console.log();
|
|
@@ -1300,9 +1299,7 @@ function renderInit(proposal, ctx) {
|
|
|
1300
1299
|
console.log();
|
|
1301
1300
|
// 1. Where this is running.
|
|
1302
1301
|
console.log(` ${t.init.host(ctx.host.displayName)}`);
|
|
1303
|
-
|
|
1304
|
-
console.log(` ${c.yellow(t.where.subscription(ctx.host.displayName))}`);
|
|
1305
|
-
}
|
|
1302
|
+
console.log(` ${c.dim(t.where.billingUnknown(ctx.host.displayName))}`);
|
|
1306
1303
|
// 2. The prompts.
|
|
1307
1304
|
console.log(` ${ctx.prompts.files.length === 0 ? c.dim(t.init.noPrompts()) : t.init.prompts(ctx.prompts.files.length)}`);
|
|
1308
1305
|
if (ctx.truncated)
|
|
@@ -2749,6 +2746,8 @@ function printReceiptSummary(document, t) {
|
|
|
2749
2746
|
*/
|
|
2750
2747
|
function usageSourcesOf(text) {
|
|
2751
2748
|
const claims = [];
|
|
2749
|
+
if (looksLikeCodexTranscript(text))
|
|
2750
|
+
claims.push('codex');
|
|
2752
2751
|
if (looksLikeClaudeCodeTranscript(text))
|
|
2753
2752
|
claims.push('claude-code');
|
|
2754
2753
|
if (looksLikeOtel(text))
|
|
@@ -2870,6 +2869,8 @@ async function commandBill(args, pricing, t) {
|
|
|
2870
2869
|
let labelledByProject = 0;
|
|
2871
2870
|
/* Claude Code transcripts read: their money is an API-rate equivalent. */
|
|
2872
2871
|
let claudeCodeFiles = 0;
|
|
2872
|
+
let codexFiles = 0;
|
|
2873
|
+
const codexEvidence = { source: 'codex', basis: 'api-equivalent-telemetry', files: 0, duplicates: 0, missingModel: 0, unsupported: 0, unparseable: 0 };
|
|
2873
2874
|
const lines = [];
|
|
2874
2875
|
let sources = 0;
|
|
2875
2876
|
/*
|
|
@@ -2902,6 +2903,20 @@ async function commandBill(args, pricing, t) {
|
|
|
2902
2903
|
let records = [];
|
|
2903
2904
|
let leftOut = 0;
|
|
2904
2905
|
switch (shape) {
|
|
2906
|
+
case 'codex': {
|
|
2907
|
+
codexFiles += 1;
|
|
2908
|
+
const c = codexRecords(text, withLabel);
|
|
2909
|
+
codexEvidence.files += 1;
|
|
2910
|
+
codexEvidence.duplicates += c.duplicates;
|
|
2911
|
+
codexEvidence.missingModel += c.missingModel;
|
|
2912
|
+
codexEvidence.unsupported += c.unsupported;
|
|
2913
|
+
codexEvidence.unparseable += c.unparseable;
|
|
2914
|
+
records = c.records;
|
|
2915
|
+
leftOut = c.missingModel + c.unsupported + c.unparseable;
|
|
2916
|
+
if (leftOut > 0)
|
|
2917
|
+
console.error(t.fromCodex.gaps(c.missingModel, c.unsupported, c.unparseable));
|
|
2918
|
+
break;
|
|
2919
|
+
}
|
|
2905
2920
|
case 'claude-code': {
|
|
2906
2921
|
claudeCodeFiles += 1;
|
|
2907
2922
|
const project = label === undefined && labelFromProject && walked.has(file) ? projectLabelFor(file) : undefined;
|
|
@@ -2998,7 +3013,11 @@ async function commandBill(args, pricing, t) {
|
|
|
2998
3013
|
});
|
|
2999
3014
|
refuseEmptyPeriod(text, report, period, pricing, t);
|
|
3000
3015
|
const document = receiptFrom(report, pricing, boolFlag(args, 'stamp') ? { emittedAt: new Date() } : {});
|
|
3001
|
-
const
|
|
3016
|
+
const billDocument = codexFiles === 0 ? document : {
|
|
3017
|
+
...document,
|
|
3018
|
+
importEvidence: [{ ...codexEvidence, complete: codexEvidence.missingModel + codexEvidence.unsupported + codexEvidence.unparseable === 0 }],
|
|
3019
|
+
};
|
|
3020
|
+
const json = JSON.stringify(billDocument, null, 2);
|
|
3002
3021
|
/*
|
|
3003
3022
|
A terminal gets a statement a person can read; a pipe gets the receipt.
|
|
3004
3023
|
The receipt on a terminal was 60 lines of JSON before the first figure a
|
|
@@ -3020,8 +3039,8 @@ async function commandBill(args, pricing, t) {
|
|
|
3020
3039
|
console.error(t.bill.sources(sources, files.length));
|
|
3021
3040
|
printReceiptSummary(document, t);
|
|
3022
3041
|
if (statement)
|
|
3023
|
-
printBillStatement(report, labelledByProject > 0, t, period.words, claudeCodeFiles > 0);
|
|
3024
|
-
await writeBillSideFiles(args, report, pricing, csvShape, t, period.words, claudeCodeFiles > 0);
|
|
3042
|
+
printBillStatement(report, labelledByProject > 0, t, period.words, claudeCodeFiles + codexFiles > 0);
|
|
3043
|
+
await writeBillSideFiles(args, report, pricing, csvShape, t, period.words, claudeCodeFiles + codexFiles > 0);
|
|
3025
3044
|
/*
|
|
3026
3045
|
A slug with a slash in it is how OpenRouter names a model, and the bundled
|
|
3027
3046
|
catalogue does not carry those: the live overlay does. Said only when the
|
|
@@ -3143,38 +3162,22 @@ function printBillStatement(report, byProject, t, window, apiEquivalent = false)
|
|
|
3143
3162
|
report's own days, oldest first, newest kept when there are many; shown
|
|
3144
3163
|
only once the bill spans two calendar months, since one month is the total.
|
|
3145
3164
|
*/
|
|
3146
|
-
const months =
|
|
3147
|
-
|
|
3148
|
-
const
|
|
3149
|
-
month.calls += day.calls;
|
|
3150
|
-
month.usd += day.usd;
|
|
3151
|
-
months.set(day.day.slice(0, 7), month);
|
|
3152
|
-
}
|
|
3153
|
-
if (months.size >= 2) {
|
|
3154
|
-
const ordered = [...months.entries()].sort(([a], [b]) => a.localeCompare(b));
|
|
3155
|
-
const shown = ordered.slice(-LIMIT).map(([name, { calls, usd }]) => {
|
|
3165
|
+
const { months, undated } = spendByMonth(report);
|
|
3166
|
+
if (months.length >= 2) {
|
|
3167
|
+
const shown = months.slice(-LIMIT).map(({ month, calls, usd }) => {
|
|
3156
3168
|
const share = total > 0 ? usd / total : 0;
|
|
3157
|
-
return [
|
|
3169
|
+
return [month, n(calls), formatUsd(usd), `${bar(share)} ${pct(share)}`];
|
|
3158
3170
|
});
|
|
3159
|
-
if (
|
|
3160
|
-
shown.unshift([c.dim(t.bill.earlierMonths(
|
|
3171
|
+
if (months.length > LIMIT)
|
|
3172
|
+
shown.unshift([c.dim(t.bill.earlierMonths(months.length - LIMIT)), '', '', '']);
|
|
3161
3173
|
console.log();
|
|
3162
3174
|
for (const line of table(columns(t.bill.colMonth()), shown))
|
|
3163
3175
|
console.log(line);
|
|
3164
|
-
|
|
3165
|
-
calls
|
|
3166
|
-
usd: 0,
|
|
3167
|
-
});
|
|
3168
|
-
const undatedCalls = report.total.calls - dated.calls;
|
|
3169
|
-
if (undatedCalls > 0) {
|
|
3170
|
-
console.log(c.dim(` ${wrap(t.bill.monthsUndated(undatedCalls, formatUsd(total - dated.usd)), 74, ' ')}`));
|
|
3171
|
-
}
|
|
3172
|
-
const newest = ordered[ordered.length - 1]?.[0];
|
|
3173
|
-
if (newest !== undefined) {
|
|
3174
|
-
const [year, month] = newest.split('-').map(Number);
|
|
3175
|
-
const lastDay = new Date(Date.UTC(year ?? 1970, month ?? 1, 0)).toISOString().slice(0, 10);
|
|
3176
|
-
console.log(c.dim(` ${t.bill.monthHint(`${newest}-01`, lastDay)}`));
|
|
3176
|
+
if (undated.calls > 0) {
|
|
3177
|
+
console.log(c.dim(` ${wrap(t.bill.monthsUndated(undated.calls, formatUsd(undated.usd)), 74, ' ')}`));
|
|
3177
3178
|
}
|
|
3179
|
+
const newest = months[months.length - 1];
|
|
3180
|
+
console.log(c.dim(` ${t.bill.monthHint(newest.firstDay, newest.lastDay)}`));
|
|
3178
3181
|
}
|
|
3179
3182
|
console.log();
|
|
3180
3183
|
if (report.unpricedModels.length > 0) {
|
|
@@ -3390,6 +3393,61 @@ function commandOwnrate(args, t) {
|
|
|
3390
3393
|
};
|
|
3391
3394
|
console.log(JSON.stringify(snippet, null, 2));
|
|
3392
3395
|
}
|
|
3396
|
+
/** Explicit paths only: Codex histories are not discovered from the user's home. */
|
|
3397
|
+
async function commandFromCodex(args, t) {
|
|
3398
|
+
const target = args.positional[0];
|
|
3399
|
+
if (target === undefined)
|
|
3400
|
+
throw new Error(t.fromCodex.noPath());
|
|
3401
|
+
let info;
|
|
3402
|
+
try {
|
|
3403
|
+
info = await stat(target);
|
|
3404
|
+
}
|
|
3405
|
+
catch {
|
|
3406
|
+
throw new Error(t.fromCodex.notFound(target));
|
|
3407
|
+
}
|
|
3408
|
+
const files = info.isDirectory()
|
|
3409
|
+
? (await readdir(target, { recursive: true, withFileTypes: true }))
|
|
3410
|
+
.filter((entry) => entry.isFile() && /\.(jsonl|ndjson)$/i.test(entry.name))
|
|
3411
|
+
.map((entry) => join(entry.parentPath, entry.name)).sort()
|
|
3412
|
+
: [target];
|
|
3413
|
+
if (files.length === 0)
|
|
3414
|
+
throw new Error(t.fromCodex.noFiles(target));
|
|
3415
|
+
const label = stringFlag(args, 'label');
|
|
3416
|
+
const lines = [];
|
|
3417
|
+
let duplicates = 0;
|
|
3418
|
+
let missingModel = 0;
|
|
3419
|
+
let unsupported = 0;
|
|
3420
|
+
let unparseable = 0;
|
|
3421
|
+
for (const file of files) {
|
|
3422
|
+
const text = await readFile(file, 'utf8');
|
|
3423
|
+
if (!looksLikeCodexTranscript(text)) {
|
|
3424
|
+
unsupported++;
|
|
3425
|
+
continue;
|
|
3426
|
+
}
|
|
3427
|
+
const conversion = codexRecords(text, label === undefined ? {} : { label });
|
|
3428
|
+
for (const record of conversion.records)
|
|
3429
|
+
lines.push(JSON.stringify(record));
|
|
3430
|
+
duplicates += conversion.duplicates;
|
|
3431
|
+
missingModel += conversion.missingModel;
|
|
3432
|
+
unsupported += conversion.unsupported;
|
|
3433
|
+
unparseable += conversion.unparseable;
|
|
3434
|
+
}
|
|
3435
|
+
console.error(t.fromCodex.summary(files.length, lines.length, duplicates));
|
|
3436
|
+
if (missingModel + unsupported + unparseable > 0) {
|
|
3437
|
+
console.error(t.fromCodex.gaps(missingModel, unsupported, unparseable));
|
|
3438
|
+
}
|
|
3439
|
+
console.error(t.fromCodex.caveat());
|
|
3440
|
+
if (lines.length === 0)
|
|
3441
|
+
throw new Error(t.fromCodex.noUsage());
|
|
3442
|
+
const out = stringFlag(args, 'out') ?? stringFlag(args, 'o');
|
|
3443
|
+
const text = lines.join('\n') + '\n';
|
|
3444
|
+
if (out !== undefined) {
|
|
3445
|
+
await writeFile(out, text, 'utf8');
|
|
3446
|
+
console.error(t.fromCodex.written(out));
|
|
3447
|
+
}
|
|
3448
|
+
else
|
|
3449
|
+
console.log(text.trimEnd());
|
|
3450
|
+
}
|
|
3393
3451
|
async function commandFromOtel(args, t) {
|
|
3394
3452
|
const target = args.positional[0];
|
|
3395
3453
|
if (target === undefined)
|
|
@@ -4540,12 +4598,13 @@ async function commandGateway(args, config, configDir, pricing, t) {
|
|
|
4540
4598
|
const budget = budgetPositions(resolved.records, config.spend, { catalogue: pricing });
|
|
4541
4599
|
const position = budget.positions[0] ?? null;
|
|
4542
4600
|
/**
|
|
4543
|
-
* Read once at start
|
|
4601
|
+
* Read the baseline once at start. The gateway adds its own completed
|
|
4602
|
+
* usage and reserves in-flight estimates in memory via `liveBudget`.
|
|
4544
4603
|
*
|
|
4545
4604
|
* A file read in the request path would put Trazum's own latency between a
|
|
4546
4605
|
* caller and their provider on every call, which is a cost this product
|
|
4547
|
-
* would otherwise be reporting on somebody else.
|
|
4548
|
-
*
|
|
4606
|
+
* would otherwise be reporting on somebody else. External spend is still
|
|
4607
|
+
* stale, so a refusal carries the baseline's `asOfMs`.
|
|
4549
4608
|
*/
|
|
4550
4609
|
const standing = position === null || position.coverage === 'none'
|
|
4551
4610
|
? null
|
|
@@ -4567,6 +4626,7 @@ async function commandGateway(args, config, configDir, pricing, t) {
|
|
|
4567
4626
|
*/
|
|
4568
4627
|
let unmeasured = 0;
|
|
4569
4628
|
const server = buildGateway({
|
|
4629
|
+
liveBudget: true,
|
|
4570
4630
|
provider,
|
|
4571
4631
|
catalogue: pricing,
|
|
4572
4632
|
policy: {
|
|
@@ -5948,24 +6008,12 @@ async function commandOptimize(args, config, pricing, t, locale) {
|
|
|
5948
6008
|
}
|
|
5949
6009
|
return;
|
|
5950
6010
|
}
|
|
5951
|
-
//
|
|
5952
|
-
//
|
|
5953
|
-
// money. Either flag overrides it, because the host says where *Trazum* runs
|
|
5954
|
-
// and not where the prompt goes — somebody editing a production prompt inside
|
|
5955
|
-
// Cursor wants the dollars, and they should not have to leave the editor to
|
|
5956
|
-
// see them.
|
|
6011
|
+
// Agent harnesses default to token context; their identity does not establish
|
|
6012
|
+
// billing. Explicit API-cost requests and usage-log scenarios retain pricing.
|
|
5957
6013
|
const host = detectHost();
|
|
5958
|
-
/**
|
|
5959
|
-
* `--from-log` implies `--cost`, and the reasoning is different from the
|
|
5960
|
-
* `--calls` case documented below: `--calls` is a typed scenario parameter,
|
|
5961
|
-
* but a usage log with billed token counts is *evidence* — proof this
|
|
5962
|
-
* prompt's traffic goes to a metered API, whatever the terminal running
|
|
5963
|
-
* the command bills like. Withholding the money there would suppress
|
|
5964
|
-
* exactly the figures the person measured in order to see.
|
|
5965
|
-
*/
|
|
5966
6014
|
const tokensOnly = boolFlag(args, 'cost') || measured !== null
|
|
5967
6015
|
? false
|
|
5968
|
-
: boolFlag(args, 'tokens-only') || host
|
|
6016
|
+
: boolFlag(args, 'tokens-only') || prefersTokenReport(host);
|
|
5969
6017
|
/**
|
|
5970
6018
|
* Whether they named a scenario while the money was being withheld.
|
|
5971
6019
|
*
|
|
@@ -11115,6 +11163,12 @@ function printRank(ranked, context) {
|
|
|
11115
11163
|
}
|
|
11116
11164
|
async function main() {
|
|
11117
11165
|
const argv = process.argv.slice(2);
|
|
11166
|
+
// The stdin display filter has its own small grammar and no project config.
|
|
11167
|
+
if (argv[0] === 'filter') {
|
|
11168
|
+
const { runFilter } = await import('./filter.js');
|
|
11169
|
+
await runFilter(argv.slice(1));
|
|
11170
|
+
return;
|
|
11171
|
+
}
|
|
11118
11172
|
let locale = localeFromArgv(argv);
|
|
11119
11173
|
let t = getCliMessages(locale);
|
|
11120
11174
|
const args = parseArgs(argv, t);
|
|
@@ -11316,6 +11370,9 @@ async function main() {
|
|
|
11316
11370
|
case 'reconcile':
|
|
11317
11371
|
await commandReconcile(args, t);
|
|
11318
11372
|
break;
|
|
11373
|
+
case 'from-codex':
|
|
11374
|
+
await commandFromCodex(args, t);
|
|
11375
|
+
break;
|
|
11319
11376
|
case 'from-otel':
|
|
11320
11377
|
await commandFromOtel(args, t);
|
|
11321
11378
|
break;
|