@trazum/cli 1.50.9 → 1.50.10
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 +29 -0
- package/dist/i18n/es.js.map +1 -1
- package/dist/i18n/types.d.ts +19 -0
- package/dist/i18n/types.d.ts.map +1 -1
- package/dist/index.js +114 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/i18n/en.ts +36 -0
- package/src/i18n/es.ts +36 -0
- package/src/i18n/types.ts +15 -0
- package/src/index.ts +145 -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, 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, 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
|
|
@@ -327,6 +327,7 @@ const COMMAND_FLAGS = {
|
|
|
327
327
|
experiment: ['a', 'b', 'min-outcomes', 'pricing', 'pricing-live'],
|
|
328
328
|
quality: ['label', 'at', 'gate', 'pricing', 'pricing-live'],
|
|
329
329
|
semantic: ['yes', 'model', 'pricing', 'pricing-live'],
|
|
330
|
+
owners: ['pricing', 'pricing-live', 'since', 'until'],
|
|
330
331
|
where: [],
|
|
331
332
|
rules: [],
|
|
332
333
|
blame: ['limit', 'model', 'calls', 'output-tokens', 'batch', 'prompt', 'markdown-out'],
|
|
@@ -2056,6 +2057,115 @@ async function commandSemantic(args, config, pricing, t) {
|
|
|
2056
2057
|
console.log(` ${c.dim(wrap(t.semantic.optIn(), 74, ' '))}`);
|
|
2057
2058
|
console.log();
|
|
2058
2059
|
}
|
|
2060
|
+
/**
|
|
2061
|
+
* `trazum owners <log>` — whose budget each workload lands on.
|
|
2062
|
+
*
|
|
2063
|
+
* The fleet answered *which service* in 1.37. This answers *whose money*,
|
|
2064
|
+
* which is the question that decides whether anything on the list gets done: a
|
|
2065
|
+
* report saying "the bill is $40,000 and here is $9,000 of savings" is read by
|
|
2066
|
+
* four people who each assume it is one of the other three's problem.
|
|
2067
|
+
*
|
|
2068
|
+
* **The unallocated is its own line and is never spread.** See `owners.ts` for
|
|
2069
|
+
* why that is worth breaking a module over.
|
|
2070
|
+
*/
|
|
2071
|
+
async function commandOwners(args, config, pricing, t) {
|
|
2072
|
+
const path = args.positional[0];
|
|
2073
|
+
if (path === undefined)
|
|
2074
|
+
throw new Error(t.errors.missingInputFile());
|
|
2075
|
+
console.log();
|
|
2076
|
+
console.log(c.bold(t.owners.heading()));
|
|
2077
|
+
if (config.owners === undefined) {
|
|
2078
|
+
console.log(` ${c.dim(wrap(t.owners.noOwners(), 74, ' '))}`);
|
|
2079
|
+
console.log();
|
|
2080
|
+
return;
|
|
2081
|
+
}
|
|
2082
|
+
const report = profileUsage(await readUsageLog(path, t), { catalogue: pricing });
|
|
2083
|
+
const result = allocate(report.byLabel.map((entry) => ({
|
|
2084
|
+
label: entry.label,
|
|
2085
|
+
usd: entry.breakdown.totalUsd,
|
|
2086
|
+
calls: entry.breakdown.calls,
|
|
2087
|
+
})), config.owners);
|
|
2088
|
+
const n = (value) => value.toLocaleString(t.numberLocale);
|
|
2089
|
+
const pct = (value) => `${(value * 100).toFixed(1)}%`;
|
|
2090
|
+
/**
|
|
2091
|
+
* Problems first, before any figure.
|
|
2092
|
+
*
|
|
2093
|
+
* A split that does not sum to one sends a whole workload to unallocated,
|
|
2094
|
+
* and a reader who saw the table before the explanation would go looking for
|
|
2095
|
+
* a bug in their logs.
|
|
2096
|
+
*/
|
|
2097
|
+
if (result.problems.length > 0) {
|
|
2098
|
+
console.log();
|
|
2099
|
+
console.log(` ${c.red('✗')} ${c.bold(t.owners.problemsHeading())}`);
|
|
2100
|
+
for (const problem of result.problems) {
|
|
2101
|
+
const detail = problem.kind === 'budget-for-unknown-owner'
|
|
2102
|
+
? problem.owner
|
|
2103
|
+
: problem.kind === 'split-does-not-sum'
|
|
2104
|
+
? `"${problem.label}" sums to ${problem.total}`
|
|
2105
|
+
: problem.kind === 'negative-share' || problem.kind === 'split-names-unknown-owner'
|
|
2106
|
+
? `"${problem.label}" → ${problem.owner}`
|
|
2107
|
+
: `"${problem.label}"`;
|
|
2108
|
+
console.log(` ${wrap(t.owners.problem(problem.kind, detail), 70, ' ')}`);
|
|
2109
|
+
}
|
|
2110
|
+
process.exitCode = 1;
|
|
2111
|
+
}
|
|
2112
|
+
console.log();
|
|
2113
|
+
const col = t.owners.columns;
|
|
2114
|
+
const rows = result.owners.map((line) => ({
|
|
2115
|
+
owner: line.owner,
|
|
2116
|
+
spend: formatUsd(line.usd),
|
|
2117
|
+
budget: line.budgetUsd === null ? '—' : formatUsd(line.budgetUsd),
|
|
2118
|
+
calls: n(Math.round(line.calls)),
|
|
2119
|
+
verdict: t.owners.verdict(line.verdict),
|
|
2120
|
+
kind: line.verdict,
|
|
2121
|
+
}));
|
|
2122
|
+
const w = {
|
|
2123
|
+
owner: Math.max(...rows.map((r) => r.owner.length), col.owner.length),
|
|
2124
|
+
spend: Math.max(...rows.map((r) => r.spend.length), col.spend.length),
|
|
2125
|
+
budget: Math.max(...rows.map((r) => r.budget.length), col.budget.length),
|
|
2126
|
+
calls: Math.max(...rows.map((r) => r.calls.length), col.calls.length),
|
|
2127
|
+
};
|
|
2128
|
+
console.log(c.dim(` ${col.owner.padEnd(w.owner)} ${col.spend.padStart(w.spend)} ` +
|
|
2129
|
+
`${col.budget.padStart(w.budget)} ${col.calls.padStart(w.calls)}`));
|
|
2130
|
+
for (const row of rows) {
|
|
2131
|
+
const tint = row.kind === 'over' ? c.red : row.kind === 'not-measured' ? c.yellow : c.dim;
|
|
2132
|
+
console.log(` ${row.owner.padEnd(w.owner)} ${row.spend.padStart(w.spend)} ` +
|
|
2133
|
+
`${row.budget.padStart(w.budget)} ${row.calls.padStart(w.calls)} ${tint(row.verdict)}`);
|
|
2134
|
+
}
|
|
2135
|
+
// The 1.37 refusal, applied to people, said in full for each owner it hits.
|
|
2136
|
+
for (const line of result.owners) {
|
|
2137
|
+
if (line.verdict === 'not-measured') {
|
|
2138
|
+
console.log();
|
|
2139
|
+
console.log(` ${c.yellow('!')} ${wrap(t.owners.notMeasured(line.owner), 74, ' ')}`);
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
console.log();
|
|
2143
|
+
if (result.unallocated.usd > 0) {
|
|
2144
|
+
console.log(` ${c.yellow('!')} ${wrap(t.owners.unallocated(formatUsd(result.unallocated.usd), report.total.totalUsd > 0 ? pct(result.unallocated.usd / report.total.totalUsd) : '—', result.unallocated.labels.slice(0, 6).join(', ')), 74, ' ')}`);
|
|
2145
|
+
console.log(` ${c.dim(wrap(t.owners.neverSpread(), 72, ' '))}`);
|
|
2146
|
+
}
|
|
2147
|
+
else {
|
|
2148
|
+
console.log(` ${c.dim(t.owners.nothingUnallocated())}`);
|
|
2149
|
+
}
|
|
2150
|
+
/**
|
|
2151
|
+
* The shared rules, printed with the report.
|
|
2152
|
+
*
|
|
2153
|
+
* The whole design: the argument then happens about the rule — "why is
|
|
2154
|
+
* search 60/40?" — rather than about the number, which is an argument nobody
|
|
2155
|
+
* can win because nobody can see where the number came from.
|
|
2156
|
+
*/
|
|
2157
|
+
if (result.sharedApplied.length > 0) {
|
|
2158
|
+
console.log();
|
|
2159
|
+
console.log(` ${c.bold(t.owners.sharedHeading())}`);
|
|
2160
|
+
for (const { label, split } of result.sharedApplied) {
|
|
2161
|
+
const rule = Object.entries(split)
|
|
2162
|
+
.map(([owner, share]) => `${owner} ${pct(share)}`)
|
|
2163
|
+
.join(', ');
|
|
2164
|
+
console.log(` ${c.dim(t.owners.sharedRule(label, rule))}`);
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
2167
|
+
console.log();
|
|
2168
|
+
}
|
|
2059
2169
|
function commandModels(t, pricing) {
|
|
2060
2170
|
const n = (value) => value.toLocaleString(t.numberLocale);
|
|
2061
2171
|
const col = t.models.columns;
|
|
@@ -7103,6 +7213,9 @@ async function main() {
|
|
|
7103
7213
|
case 'models':
|
|
7104
7214
|
commandModels(t, pricing);
|
|
7105
7215
|
break;
|
|
7216
|
+
case 'owners':
|
|
7217
|
+
await commandOwners(args, config, pricing, t);
|
|
7218
|
+
break;
|
|
7106
7219
|
case 'semantic':
|
|
7107
7220
|
await commandSemantic(args, config, pricing, t);
|
|
7108
7221
|
break;
|