@trazum/cli 1.50.10 → 1.50.11
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/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +29 -0
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/es.d.ts.map +1 -1
- package/dist/i18n/es.js +30 -0
- package/dist/i18n/es.js.map +1 -1
- package/dist/i18n/types.d.ts +20 -0
- package/dist/i18n/types.d.ts.map +1 -1
- package/dist/index.js +129 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/i18n/en.ts +39 -0
- package/src/i18n/es.ts +40 -0
- package/src/i18n/types.ts +16 -0
- package/src/index.ts +170 -0
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, 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 { 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, 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
|
|
@@ -35,6 +35,9 @@ const VALUE_FLAGS = new Set([
|
|
|
35
35
|
'a',
|
|
36
36
|
'at',
|
|
37
37
|
'b',
|
|
38
|
+
'floor',
|
|
39
|
+
'discount',
|
|
40
|
+
'months',
|
|
38
41
|
'min-outcomes',
|
|
39
42
|
'against',
|
|
40
43
|
'contract',
|
|
@@ -328,6 +331,7 @@ const COMMAND_FLAGS = {
|
|
|
328
331
|
quality: ['label', 'at', 'gate', 'pricing', 'pricing-live'],
|
|
329
332
|
semantic: ['yes', 'model', 'pricing', 'pricing-live'],
|
|
330
333
|
owners: ['pricing', 'pricing-live', 'since', 'until'],
|
|
334
|
+
commitment: ['floor', 'discount', 'months', 'pricing', 'pricing-live'],
|
|
331
335
|
where: [],
|
|
332
336
|
rules: [],
|
|
333
337
|
blame: ['limit', 'model', 'calls', 'output-tokens', 'batch', 'prompt', 'markdown-out'],
|
|
@@ -2166,6 +2170,127 @@ async function commandOwners(args, config, pricing, t) {
|
|
|
2166
2170
|
}
|
|
2167
2171
|
console.log();
|
|
2168
2172
|
}
|
|
2173
|
+
/**
|
|
2174
|
+
* `trazum commitment <log> --floor <usd> --discount <pct> [--months 12]`
|
|
2175
|
+
*
|
|
2176
|
+
* What a committed-use deal would have been worth **on the traffic you
|
|
2177
|
+
* actually had**. Every team that signs one of these is doing arithmetic in a
|
|
2178
|
+
* spreadsheet against a number they guessed, and it is the highest-stakes
|
|
2179
|
+
* instance of exactly the failure this product exists to end — because the
|
|
2180
|
+
* guess is annual and signed.
|
|
2181
|
+
*
|
|
2182
|
+
* Nothing here projects. "On the traffic you actually had, this would have
|
|
2183
|
+
* saved $X" is a measurement; "you will save $X" is a claim about the future
|
|
2184
|
+
* this product has refused at every scale since 1.27.
|
|
2185
|
+
*/
|
|
2186
|
+
async function commandCommitment(args, config, pricing, t) {
|
|
2187
|
+
const path = args.positional[0];
|
|
2188
|
+
if (path === undefined)
|
|
2189
|
+
throw new Error(t.errors.missingInputFile());
|
|
2190
|
+
const floorRaw = stringFlag(args, 'floor');
|
|
2191
|
+
const discountRaw = stringFlag(args, 'discount');
|
|
2192
|
+
const floor = floorRaw === undefined ? Number.NaN : Number(floorRaw);
|
|
2193
|
+
const discountInput = discountRaw === undefined ? Number.NaN : Number(discountRaw);
|
|
2194
|
+
if (!Number.isFinite(floor) || floor <= 0 || !Number.isFinite(discountInput) || discountInput <= 0) {
|
|
2195
|
+
throw new Error(t.commitment.needsTerms());
|
|
2196
|
+
}
|
|
2197
|
+
// Written either way in a contract, so read either way: 20 and 0.2 are the
|
|
2198
|
+
// same deal, and refusing one of them would be pedantry with a stack trace.
|
|
2199
|
+
const discount = discountInput > 1 ? discountInput / 100 : discountInput;
|
|
2200
|
+
const months = Number(stringFlag(args, 'months') ?? 12);
|
|
2201
|
+
const terms = { monthlyFloorUsd: floor, discount, months };
|
|
2202
|
+
const report = profileUsage(await readUsageLog(path, t), { catalogue: pricing });
|
|
2203
|
+
/**
|
|
2204
|
+
* Whole calendar months only.
|
|
2205
|
+
*
|
|
2206
|
+
* A partial month replayed against a monthly floor is a shortfall the
|
|
2207
|
+
* traffic never had — the deal would be judged against a fortnight of usage
|
|
2208
|
+
* and a full month of commitment. Dropping them costs an answer; keeping
|
|
2209
|
+
* them would manufacture one.
|
|
2210
|
+
*/
|
|
2211
|
+
const byMonth = new Map();
|
|
2212
|
+
for (const day of report.spendByDay) {
|
|
2213
|
+
const key = day.day.slice(0, 7);
|
|
2214
|
+
byMonth.set(key, (byMonth.get(key) ?? 0) + day.usd);
|
|
2215
|
+
}
|
|
2216
|
+
const days = new Map();
|
|
2217
|
+
for (const day of report.spendByDay) {
|
|
2218
|
+
const key = day.day.slice(0, 7);
|
|
2219
|
+
const set = days.get(key) ?? new Set();
|
|
2220
|
+
set.add(day.day);
|
|
2221
|
+
days.set(key, set);
|
|
2222
|
+
}
|
|
2223
|
+
const whole = [...byMonth.entries()]
|
|
2224
|
+
.filter(([key]) => {
|
|
2225
|
+
const [y, m] = key.split('-').map(Number);
|
|
2226
|
+
const inMonth = new Date(Date.UTC(y ?? 2026, m ?? 1, 0)).getUTCDate();
|
|
2227
|
+
return (days.get(key)?.size ?? 0) >= inMonth - 2;
|
|
2228
|
+
})
|
|
2229
|
+
.map(([month, usd]) => ({ month, usd }))
|
|
2230
|
+
.sort((a, b) => a.month.localeCompare(b.month));
|
|
2231
|
+
const replay = replayCommitment(whole, terms);
|
|
2232
|
+
const coverage = coversTheTerm(replay, terms);
|
|
2233
|
+
const n = (value) => value.toLocaleString(t.numberLocale);
|
|
2234
|
+
const pct = (value) => `${(value * 100).toFixed(0)}%`;
|
|
2235
|
+
console.log();
|
|
2236
|
+
console.log(c.bold(t.commitment.heading(formatUsd(floor), pct(discount), n(months))));
|
|
2237
|
+
console.log(` ${c.dim(wrap(t.commitment.asIf(), 74, ' '))}`);
|
|
2238
|
+
console.log();
|
|
2239
|
+
if (replay.unknown !== null) {
|
|
2240
|
+
console.log(` ${c.yellow('?')} ${wrap(t.commitment.cannotTell(replay.unknown, n(replay.monthsNeeded ?? 0)), 74, ' ')}`);
|
|
2241
|
+
console.log();
|
|
2242
|
+
console.log(` ${c.dim(t.commitment.breakEven(formatUsd(replay.breakEvenMonthlyUsd)))}`);
|
|
2243
|
+
console.log();
|
|
2244
|
+
return;
|
|
2245
|
+
}
|
|
2246
|
+
const col = t.commitment.columns;
|
|
2247
|
+
const rows = replay.months.map((m) => ({
|
|
2248
|
+
month: m.month,
|
|
2249
|
+
list: formatUsd(m.listUsd),
|
|
2250
|
+
paid: formatUsd(m.paidUsd),
|
|
2251
|
+
// Signed: every month in this column can go either way, and formatUsd
|
|
2252
|
+
// renders a negative as `$-2,400`, which reads as a typo. The sign carries
|
|
2253
|
+
// the whole meaning here, so it goes where a reader expects it.
|
|
2254
|
+
saving: formatSignedUsd(m.savingUsd),
|
|
2255
|
+
shortfall: m.shortfall,
|
|
2256
|
+
}));
|
|
2257
|
+
const w = {
|
|
2258
|
+
month: Math.max(...rows.map((r) => r.month.length), col.month.length),
|
|
2259
|
+
list: Math.max(...rows.map((r) => r.list.length), col.list.length),
|
|
2260
|
+
paid: Math.max(...rows.map((r) => r.paid.length), col.paid.length),
|
|
2261
|
+
saving: Math.max(...rows.map((r) => r.saving.length), col.saving.length),
|
|
2262
|
+
};
|
|
2263
|
+
console.log(c.dim(` ${col.month.padEnd(w.month)} ${col.list.padStart(w.list)} ` +
|
|
2264
|
+
`${col.paid.padStart(w.paid)} ${col.saving.padStart(w.saving)}`));
|
|
2265
|
+
for (const row of rows) {
|
|
2266
|
+
const tint = row.shortfall ? c.red : c.dim;
|
|
2267
|
+
console.log(` ${row.month.padEnd(w.month)} ${row.list.padStart(w.list)} ` +
|
|
2268
|
+
`${row.paid.padStart(w.paid)} ${tint(row.saving.padStart(w.saving))}`);
|
|
2269
|
+
}
|
|
2270
|
+
console.log();
|
|
2271
|
+
console.log(` ${c.bold(t.commitment.net(formatUsd(replay.netUsd), n(replay.months.length)))}`);
|
|
2272
|
+
console.log(` ${c.dim(t.commitment.good(formatUsd(replay.savedInGoodMonthsUsd)))}`);
|
|
2273
|
+
if (replay.shortfallMonths > 0) {
|
|
2274
|
+
console.log(` ${c.yellow('!')} ${wrap(t.commitment.lost(formatUsd(replay.lostToUnusedFloorUsd), n(replay.shortfallMonths)), 74, ' ')}`);
|
|
2275
|
+
}
|
|
2276
|
+
else {
|
|
2277
|
+
console.log(` ${c.dim(t.commitment.noShortfall())}`);
|
|
2278
|
+
}
|
|
2279
|
+
console.log();
|
|
2280
|
+
console.log(` ${c.dim(wrap(t.commitment.breakEven(formatUsd(replay.breakEvenMonthlyUsd)), 74, ' '))}`);
|
|
2281
|
+
if (replay.spread !== null) {
|
|
2282
|
+
console.log(` ${c.dim(wrap(t.commitment.spread(formatUsd(replay.spread.lowUsd), formatUsd(replay.spread.highUsd), formatUsd(replay.spread.medianUsd)), 74, ' '))}`);
|
|
2283
|
+
}
|
|
2284
|
+
// Said, not enforced: a shorter history is a real answer about a shorter
|
|
2285
|
+
// period, and the gap must not go unmarked.
|
|
2286
|
+
if (coverage.short) {
|
|
2287
|
+
console.log();
|
|
2288
|
+
console.log(` ${c.yellow('!')} ${wrap(t.commitment.shortTerm(n(coverage.covered), n(coverage.ofMonths)), 74, ' ')}`);
|
|
2289
|
+
}
|
|
2290
|
+
console.log();
|
|
2291
|
+
console.log(` ${c.dim(wrap(t.commitment.neverAForecast(), 74, ' '))}`);
|
|
2292
|
+
console.log();
|
|
2293
|
+
}
|
|
2169
2294
|
function commandModels(t, pricing) {
|
|
2170
2295
|
const n = (value) => value.toLocaleString(t.numberLocale);
|
|
2171
2296
|
const col = t.models.columns;
|
|
@@ -7213,6 +7338,9 @@ async function main() {
|
|
|
7213
7338
|
case 'models':
|
|
7214
7339
|
commandModels(t, pricing);
|
|
7215
7340
|
break;
|
|
7341
|
+
case 'commitment':
|
|
7342
|
+
await commandCommitment(args, config, pricing, t);
|
|
7343
|
+
break;
|
|
7216
7344
|
case 'owners':
|
|
7217
7345
|
await commandOwners(args, config, pricing, t);
|
|
7218
7346
|
break;
|