@trazum/cli 2.7.6 → 2.7.8
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 +15 -9
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/es.d.ts.map +1 -1
- package/dist/i18n/es.js +15 -9
- package/dist/i18n/es.js.map +1 -1
- package/dist/i18n/types.d.ts +15 -4
- package/dist/i18n/types.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +71 -65
- package/dist/index.js.map +1 -1
- package/dist/markdown.js +1 -1
- package/dist/markdown.js.map +1 -1
- package/dist/serve-savings.d.ts.map +1 -1
- package/dist/serve-savings.js +23 -1
- package/dist/serve-savings.js.map +1 -1
- package/package.json +2 -2
- package/src/i18n/en.ts +23 -13
- package/src/i18n/es.ts +23 -13
- package/src/i18n/types.ts +15 -4
- package/src/index.ts +71 -74
- package/src/markdown.ts +1 -1
- package/src/serve-savings.ts +36 -1
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import { dirname, join, resolve as resolvePath } from 'node:path';
|
|
|
8
8
|
import { fileURLToPath } from 'node:url';
|
|
9
9
|
import { createGunzip, gunzipSync } from 'node:zlib';
|
|
10
10
|
import { Readable } from 'node:stream';
|
|
11
|
-
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, geminiCliRecords, looksLikeGeminiCliSession, slimUsageLine, ESTIMATE_ERROR_BAND_PCT, bandFor, foreignTokenizer, measuredForeignError, anthropicCostReport, anthropicUsageRecords, looksLikeOpenaiCost, looksLikeAnthropicCost,
|
|
11
|
+
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, SHAPE_COMMAND, notAUsageLog, usageShapesOf, plannedCalls, claudeCodeRecords, codexRecords, looksLikeCodexTranscript, geminiCliRecords, looksLikeGeminiCliSession, slimUsageLine, ESTIMATE_ERROR_BAND_PCT, bandFor, foreignTokenizer, measuredForeignError, anthropicCostReport, anthropicUsageRecords, looksLikeOpenaiCost, looksLikeAnthropicCost, batchResultRecords, 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, spendByPeriod, isOffered, SOURCE_EXTENSIONS, suggestRewrites, toOtlpMetrics, toPromptfoo, UNLABELLED, withExactTokenCounts, } from '@trazum/core';
|
|
12
12
|
import { cacheDir, cacheStats, cachingProvider, clearCache } from './suggest-cache.js';
|
|
13
13
|
import { OPTIONAL_COUNTERS } from './optional-counters.js';
|
|
14
14
|
import { dayOf, formatGap, median, spanDays } from './time.js';
|
|
@@ -282,7 +282,7 @@ async function usageIndexFrom(args, pricing, t) {
|
|
|
282
282
|
const logPath = stringFlag(args, 'log');
|
|
283
283
|
if (logPath === undefined)
|
|
284
284
|
return null;
|
|
285
|
-
const text = await
|
|
285
|
+
const text = await readUsageLogOnly(logPath, t);
|
|
286
286
|
const records = text
|
|
287
287
|
.split('\n')
|
|
288
288
|
.filter((line) => line.trim() !== '')
|
|
@@ -1630,7 +1630,7 @@ async function commandInit(args, config, pricing, t) {
|
|
|
1630
1630
|
.sort()
|
|
1631
1631
|
.map((name) => join(root, readable.where, name));
|
|
1632
1632
|
if (files.length > 0) {
|
|
1633
|
-
const texts = await Promise.all(files.map((file) =>
|
|
1633
|
+
const texts = await Promise.all(files.map((file) => readUsageLogOnly(file, t)));
|
|
1634
1634
|
measured = profileUsage(texts.join('\n'), { catalogue: pricing });
|
|
1635
1635
|
}
|
|
1636
1636
|
}
|
|
@@ -2644,7 +2644,7 @@ async function commandFromClaudeCode(args, t) {
|
|
|
2644
2644
|
console.error(t.fromClaudeCode.skipped(otherLines, unparseable, withoutUsage));
|
|
2645
2645
|
}
|
|
2646
2646
|
/**
|
|
2647
|
-
* `trazum receipt <usage.jsonl
|
|
2647
|
+
* `trazum receipt <usage.jsonl>` — the bill's counts, with the provenance
|
|
2648
2648
|
* of every figure attached.
|
|
2649
2649
|
*
|
|
2650
2650
|
* A profile answers a question on the terminal that ran it. The same figures
|
|
@@ -2823,7 +2823,7 @@ async function commandReceipt(args, pricing, t) {
|
|
|
2823
2823
|
if (file === undefined)
|
|
2824
2824
|
throw new Error(t.receipt.noLog());
|
|
2825
2825
|
const period = billingPeriod(args, t);
|
|
2826
|
-
const text = await
|
|
2826
|
+
const text = await readUsageLogOnly(file, t);
|
|
2827
2827
|
const report = profileUsage(text, {
|
|
2828
2828
|
catalogue: pricing,
|
|
2829
2829
|
...(period.sinceMs !== undefined ? { sinceMs: period.sinceMs } : {}),
|
|
@@ -2883,42 +2883,41 @@ function printReceiptSummary(document, t) {
|
|
|
2883
2883
|
console.error(t.receipt.webSearch(searches, formatUsd(searchUsd)));
|
|
2884
2884
|
}
|
|
2885
2885
|
/**
|
|
2886
|
-
*
|
|
2887
|
-
*
|
|
2888
|
-
*
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
if (
|
|
2915
|
-
return
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
return claims;
|
|
2886
|
+
* A usage log, for a command that reads nothing else.
|
|
2887
|
+
*
|
|
2888
|
+
* `profile` handed a Claude Code session answered "No usage records in that
|
|
2889
|
+
* file, 84 lines could not be read", which reads as a broken file, while
|
|
2890
|
+
* `bill` reads the same file as it is. So the shapes `bill` tells apart are
|
|
2891
|
+
* asked here too, and a file one of them claims is refused by name, with the
|
|
2892
|
+
* two commands that do read it. A provider's cost report is pointed at
|
|
2893
|
+
* `reconcile`, and a directory at `bill`, which walks one.
|
|
2894
|
+
*
|
|
2895
|
+
* Asked only when the first line is not already a usage line, so a usage log
|
|
2896
|
+
* pays one parse for it. A file nothing claims is returned as before, and its
|
|
2897
|
+
* unreadable lines are counted where they always were.
|
|
2898
|
+
*
|
|
2899
|
+
* `billPath` is what to name after `trazum bill`: the directory somebody
|
|
2900
|
+
* gave, when the file came out of one.
|
|
2901
|
+
*/
|
|
2902
|
+
async function readUsageLogOnly(file, t, billPath = file) {
|
|
2903
|
+
const handle = await open(file, 'r');
|
|
2904
|
+
let text;
|
|
2905
|
+
try {
|
|
2906
|
+
if ((await handle.stat()).isDirectory())
|
|
2907
|
+
throw new Error(t.errors.logIsDirectory(file));
|
|
2908
|
+
text = await readUsageHandle(handle, file, t);
|
|
2909
|
+
}
|
|
2910
|
+
finally {
|
|
2911
|
+
await handle.close();
|
|
2912
|
+
}
|
|
2913
|
+
const not = notAUsageLog(text);
|
|
2914
|
+
if (not === null)
|
|
2915
|
+
return text;
|
|
2916
|
+
if (not.kind === 'shape')
|
|
2917
|
+
throw new Error(t.errors.logIsOtherShape(file, not.shape, not.command, billPath));
|
|
2918
|
+
if (not.kind === 'ambiguous')
|
|
2919
|
+
throw new Error(t.errors.logIsAmbiguous(file, not.shapes.join(', ')));
|
|
2920
|
+
throw new Error(t.errors.logIsCostReport(file));
|
|
2922
2921
|
}
|
|
2923
2922
|
/**
|
|
2924
2923
|
* `trazum bill <file|dir>`: one door, from `docs/plan-2.4.md`.
|
|
@@ -3048,7 +3047,7 @@ async function commandBill(args, pricing, t) {
|
|
|
3048
3047
|
const byShape = new Map();
|
|
3049
3048
|
for (const file of files) {
|
|
3050
3049
|
const text = await readUsageLog(file, t);
|
|
3051
|
-
const claims =
|
|
3050
|
+
const claims = usageShapesOf(text);
|
|
3052
3051
|
if (claims.length === 0) {
|
|
3053
3052
|
if (looksLikeAnthropicCost(text) || looksLikeOpenaiCost(text)) {
|
|
3054
3053
|
console.error(t.bill.costReport(file));
|
|
@@ -3176,7 +3175,7 @@ async function commandBill(args, pricing, t) {
|
|
|
3176
3175
|
sources += 1;
|
|
3177
3176
|
const count = shape === 'usage-log' ? null : records.length;
|
|
3178
3177
|
if (perFile) {
|
|
3179
|
-
console.error(t.bill.file(file, shape, count, leftOut));
|
|
3178
|
+
console.error(t.bill.file(file, shape, count, leftOut, SHAPE_COMMAND[shape]));
|
|
3180
3179
|
}
|
|
3181
3180
|
else {
|
|
3182
3181
|
const sum = byShape.get(shape) ?? { files: 0, records: count === null ? null : 0, leftOut: 0 };
|
|
@@ -3187,8 +3186,9 @@ async function commandBill(args, pricing, t) {
|
|
|
3187
3186
|
byShape.set(shape, sum);
|
|
3188
3187
|
}
|
|
3189
3188
|
}
|
|
3190
|
-
for (const [shape, sum] of byShape)
|
|
3191
|
-
console.error(t.bill.shapeSummary(shape, sum.files, sum.records, sum.leftOut));
|
|
3189
|
+
for (const [shape, sum] of byShape) {
|
|
3190
|
+
console.error(t.bill.shapeSummary(shape, sum.files, sum.records, sum.leftOut, SHAPE_COMMAND[shape]));
|
|
3191
|
+
}
|
|
3192
3192
|
/*
|
|
3193
3193
|
A Claude Code session keeps more than its transcript in the folder named
|
|
3194
3194
|
after it: each subagent's metadata and prompt prefix, each workflow's
|
|
@@ -3634,7 +3634,7 @@ async function commandSwitch(args, pricing, t) {
|
|
|
3634
3634
|
};
|
|
3635
3635
|
const migrationUsd = optional('migration-usd');
|
|
3636
3636
|
const cases = optional('cases');
|
|
3637
|
-
const text = await
|
|
3637
|
+
const text = await readUsageLogOnly(file, t);
|
|
3638
3638
|
const report = profileUsage(text, { catalogue: pricing });
|
|
3639
3639
|
const analysis = switchAnalysis(report, target, {
|
|
3640
3640
|
catalogue: pricing,
|
|
@@ -4405,7 +4405,7 @@ async function commandPosition(args, config, pricing, t) {
|
|
|
4405
4405
|
const file = args.positional[0];
|
|
4406
4406
|
if (file === undefined)
|
|
4407
4407
|
throw new Error(t.position.noLog());
|
|
4408
|
-
const text = await
|
|
4408
|
+
const text = await readUsageLogOnly(file, t);
|
|
4409
4409
|
const records = text
|
|
4410
4410
|
.split('\n')
|
|
4411
4411
|
.filter((line) => line.trim() !== '')
|
|
@@ -5127,7 +5127,7 @@ async function commandLadder(args, config, pricing, t) {
|
|
|
5127
5127
|
if (path === undefined) {
|
|
5128
5128
|
throw new Error(t.errors.missingInputFile());
|
|
5129
5129
|
}
|
|
5130
|
-
const report = profileUsage(await
|
|
5130
|
+
const report = profileUsage(await readUsageLogOnly(path, t), { catalogue: pricing });
|
|
5131
5131
|
const ladders = config.ladders ?? {};
|
|
5132
5132
|
const n = (value) => value.toLocaleString(t.numberLocale);
|
|
5133
5133
|
const pct = (value) => `${(value * 100).toFixed(1)}%`;
|
|
@@ -5239,7 +5239,7 @@ async function commandExperiment(args, config, pricing, t) {
|
|
|
5239
5239
|
if (!Number.isInteger(minOutcomesPerArm) || minOutcomesPerArm < 1) {
|
|
5240
5240
|
throw new Error(t.experiment.needsRule());
|
|
5241
5241
|
}
|
|
5242
|
-
const report = profileUsage(await
|
|
5242
|
+
const report = profileUsage(await readUsageLogOnly(path, t), { catalogue: pricing });
|
|
5243
5243
|
const n = (value) => value.toLocaleString(t.numberLocale);
|
|
5244
5244
|
const pct = (value) => `${(value * 100).toFixed(1)}%`;
|
|
5245
5245
|
const armOf = (label) => {
|
|
@@ -5331,7 +5331,7 @@ async function commandQuality(args, config, pricing, t) {
|
|
|
5331
5331
|
* this whole module exists to avoid: two files gathered under conditions
|
|
5332
5332
|
* nobody wrote down.
|
|
5333
5333
|
*/
|
|
5334
|
-
const raw = await
|
|
5334
|
+
const raw = await readUsageLogOnly(path, t);
|
|
5335
5335
|
const sideOf = (since, until) => {
|
|
5336
5336
|
const report = profileUsage(raw, { catalogue: pricing, label, sinceMs: since, untilMs: until });
|
|
5337
5337
|
const slice = report.outcomeTallyByLabel.find((entry) => entry.label === label);
|
|
@@ -5517,7 +5517,7 @@ async function commandOwners(args, config, pricing, t) {
|
|
|
5517
5517
|
console.log();
|
|
5518
5518
|
return;
|
|
5519
5519
|
}
|
|
5520
|
-
const report = profileUsage(await
|
|
5520
|
+
const report = profileUsage(await readUsageLogOnly(path, t), { catalogue: pricing });
|
|
5521
5521
|
const result = allocate(report.byLabel.map((entry) => ({
|
|
5522
5522
|
label: entry.label,
|
|
5523
5523
|
usd: entry.breakdown.totalUsd,
|
|
@@ -5633,7 +5633,7 @@ async function commandCommitment(args, config, pricing, t) {
|
|
|
5633
5633
|
const discount = discountInput > 1 ? discountInput / 100 : discountInput;
|
|
5634
5634
|
const months = Number(stringFlag(args, 'months') ?? 12);
|
|
5635
5635
|
const terms = { monthlyFloorUsd: floor, discount, months };
|
|
5636
|
-
const report = profileUsage(await
|
|
5636
|
+
const report = profileUsage(await readUsageLogOnly(path, t), { catalogue: pricing });
|
|
5637
5637
|
/**
|
|
5638
5638
|
* Whole calendar months only.
|
|
5639
5639
|
*
|
|
@@ -5745,7 +5745,7 @@ async function commandReport(args, config, pricing, t) {
|
|
|
5745
5745
|
const year = stringFlag(args, 'year');
|
|
5746
5746
|
if (year === undefined || !/^\d{4}$/.test(year))
|
|
5747
5747
|
throw new Error(t.annual.needsYear());
|
|
5748
|
-
const report = profileUsage(await
|
|
5748
|
+
const report = profileUsage(await readUsageLogOnly(path, t), { catalogue: pricing });
|
|
5749
5749
|
/**
|
|
5750
5750
|
* One period per calendar month, built from the day series.
|
|
5751
5751
|
*
|
|
@@ -6117,7 +6117,7 @@ async function commandOptimize(args, config, pricing, t, locale) {
|
|
|
6117
6117
|
const labelsMap = config.labels ?? {};
|
|
6118
6118
|
if (Object.keys(labelsMap).length === 0)
|
|
6119
6119
|
throw new Error(t.errors.allLabelsNeedsMap());
|
|
6120
|
-
const report = profileUsage(await
|
|
6120
|
+
const report = profileUsage(await readUsageLogOnly(fromLogPath, t), { catalogue: pricing });
|
|
6121
6121
|
const coverage = labelCoverage(report, labelsMap);
|
|
6122
6122
|
const level = levelFlag(args, config, t);
|
|
6123
6123
|
const rows = [];
|
|
@@ -6210,7 +6210,7 @@ async function commandOptimize(args, config, pricing, t, locale) {
|
|
|
6210
6210
|
throw new Error(t.errors.fromLogConflict(flag));
|
|
6211
6211
|
}
|
|
6212
6212
|
}
|
|
6213
|
-
const report = profileUsage(await
|
|
6213
|
+
const report = profileUsage(await readUsageLogOnly(fromLog, t), { catalogue: pricing });
|
|
6214
6214
|
/**
|
|
6215
6215
|
* Which label this prompt is. `--label` says it outright; otherwise the
|
|
6216
6216
|
* config's `labels` map is read in reverse — it maps labels to prompt
|
|
@@ -7610,10 +7610,12 @@ async function commandVerify(args, pricing, t) {
|
|
|
7610
7610
|
.filter((entry) => entry.isFile() && READABLE.some((ext) => entry.name.endsWith(ext)))
|
|
7611
7611
|
.map((entry) => join(againstPath, entry.name))
|
|
7612
7612
|
.sort((a, b) => a.localeCompare(b));
|
|
7613
|
-
if (files.length === 0)
|
|
7614
|
-
|
|
7613
|
+
if (files.length === 0) {
|
|
7614
|
+
const folders = entries.some((entry) => entry.isDirectory());
|
|
7615
|
+
throw new Error(t.profile.noLogsInDirectory(againstPath, READABLE.join(', '), folders));
|
|
7616
|
+
}
|
|
7615
7617
|
}
|
|
7616
|
-
const texts = await Promise.all(files.map((file) =>
|
|
7618
|
+
const texts = await Promise.all(files.map((file) => readUsageLogOnly(file, t, againstPath)));
|
|
7617
7619
|
const raw = texts.map((text) => (text.endsWith('\n') ? text : `${text}\n`)).join('');
|
|
7618
7620
|
const report = profileUsage(raw, { catalogue: pricing });
|
|
7619
7621
|
const verification = verifyPlan(plan, report, { currentPricingLastReviewed: pricing.lastReviewed });
|
|
@@ -8988,7 +8990,7 @@ function reportConversationHistory(report, t) {
|
|
|
8988
8990
|
for (const growth of report.conversations.slice(0, 3)) {
|
|
8989
8991
|
const label = growth.label === UNLABELLED ? t.profile.unlabelled() : growth.label;
|
|
8990
8992
|
console.log();
|
|
8991
|
-
console.log(` ${c.bold(wrap(t.profile.historyGrowth(label, growth.modelName, n(Math.round(growth.minTurnTokens)), n(Math.round(growth.maxTurnTokens)), n(growth.longestSession)), 74, ' '))}`);
|
|
8993
|
+
console.log(` ${c.bold(wrap(t.profile.historyGrowth(label, growth.modelName, n(Math.round(growth.minTurnTokens)), n(Math.round(growth.maxTurnTokens)), n(growth.longestSession), growth.sessions), 74, ' '))}`);
|
|
8992
8994
|
console.log(` ${c.dim(wrap(t.profile.historyCeiling(formatUsd(growth.growthUsd), pct(growth.shareOfBill), formatUsd(growth.flatUsd), formatUsd(growth.inputUsd)), 74, ' '))}`);
|
|
8993
8995
|
}
|
|
8994
8996
|
}
|
|
@@ -9536,10 +9538,12 @@ async function commandPlan(args, pricing, t) {
|
|
|
9536
9538
|
.filter((entry) => entry.isFile() && READABLE.some((ext) => entry.name.endsWith(ext)))
|
|
9537
9539
|
.map((entry) => join(path, entry.name))
|
|
9538
9540
|
.sort((a, b) => a.localeCompare(b));
|
|
9539
|
-
if (files.length === 0)
|
|
9540
|
-
|
|
9541
|
+
if (files.length === 0) {
|
|
9542
|
+
const folders = entries.some((entry) => entry.isDirectory());
|
|
9543
|
+
throw new Error(t.profile.noLogsInDirectory(path, READABLE.join(', '), folders));
|
|
9544
|
+
}
|
|
9541
9545
|
}
|
|
9542
|
-
const texts = await Promise.all(files.map((file) =>
|
|
9546
|
+
const texts = await Promise.all(files.map((file) => readUsageLogOnly(file, t, path)));
|
|
9543
9547
|
const raw = texts.map((text) => (text.endsWith('\n') ? text : `${text}\n`)).join('');
|
|
9544
9548
|
const report = profileUsage(raw, { catalogue: pricing });
|
|
9545
9549
|
if (report.total.calls === 0)
|
|
@@ -9688,7 +9692,9 @@ async function commandProfile(args, config, configDir, pricing, t) {
|
|
|
9688
9692
|
.map((entry) => join(entry.parentPath ?? path, entry.name))
|
|
9689
9693
|
.sort((a, b) => a.localeCompare(b));
|
|
9690
9694
|
if (logFiles.length === 0) {
|
|
9691
|
-
|
|
9695
|
+
/* Folders only matter to the flat walk: --by-source went into them. */
|
|
9696
|
+
const folders = !bySourceMode && entries.some((entry) => entry.isDirectory());
|
|
9697
|
+
throw new Error(t.profile.noLogsInDirectory(path, READABLE.join(', '), folders));
|
|
9692
9698
|
}
|
|
9693
9699
|
}
|
|
9694
9700
|
/**
|
|
@@ -9703,7 +9709,7 @@ async function commandProfile(args, config, configDir, pricing, t) {
|
|
|
9703
9709
|
* alternative — skipping it — is a total quietly missing a day, which is
|
|
9704
9710
|
* the failure this repository refuses in every other place it can occur.
|
|
9705
9711
|
*/
|
|
9706
|
-
const logTexts = await Promise.all(logFiles.map((file) =>
|
|
9712
|
+
const logTexts = await Promise.all(logFiles.map((file) => readUsageLogOnly(file, t, path)));
|
|
9707
9713
|
// A file that does not end in a newline would otherwise glue its last record
|
|
9708
9714
|
// to the next file's first one, and both would be reported as unreadable.
|
|
9709
9715
|
const raw = logTexts.map((text) => (text.endsWith('\n') ? text : `${text}\n`)).join('');
|
|
@@ -9845,7 +9851,7 @@ async function commandProfile(args, config, configDir, pricing, t) {
|
|
|
9845
9851
|
// The same reader as the log itself, so `--against last-month.jsonl.gz`
|
|
9846
9852
|
// works: a comparison that could only read one of the two formats would
|
|
9847
9853
|
// be a flag that fails on exactly the rotated file it exists to read.
|
|
9848
|
-
? profileUsage(await
|
|
9854
|
+
? profileUsage(await readUsageLogOnly(againstPath, t), {
|
|
9849
9855
|
catalogue: pricing,
|
|
9850
9856
|
label: onlyLabel,
|
|
9851
9857
|
// The same window on both sides, for the same reason as the label:
|