@trazum/cli 1.53.3 → 1.55.0
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 +76 -2
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/es.d.ts.map +1 -1
- package/dist/i18n/es.js +77 -2
- package/dist/i18n/es.js.map +1 -1
- package/dist/i18n/types.d.ts +37 -0
- package/dist/i18n/types.d.ts.map +1 -1
- package/dist/index.js +191 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/i18n/en.ts +85 -2
- package/src/i18n/es.ts +87 -2
- package/src/i18n/types.ts +38 -0
- package/src/index.ts +229 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trazum/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.55.0",
|
|
4
4
|
"description": "Trazum CLI: find where your LLM bill goes, price every finding per month, and enforce token budgets in CI.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "David Mu\u00f1oz Rey",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"prepublishOnly": "npm run build && npm test"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@trazum/core": "1.
|
|
40
|
+
"@trazum/core": "1.55.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/node": "^26.2.0",
|
package/src/i18n/en.ts
CHANGED
|
@@ -56,6 +56,7 @@ ${bold('USAGE')}
|
|
|
56
56
|
trazum prune <file> --cases <file> --yes
|
|
57
57
|
trazum where [file]
|
|
58
58
|
trazum conform <file|-> [--contract <name>]
|
|
59
|
+
trazum rollup <document...|dir> [--json]
|
|
59
60
|
trazum models
|
|
60
61
|
trazum rules
|
|
61
62
|
trazum gateway <provider> --on-cannot-tell <fail-open|fail-closed>
|
|
@@ -87,8 +88,7 @@ ${bold('OPTIONS FOR init')}
|
|
|
87
88
|
|
|
88
89
|
${bold('OPTIONS FOR conform')}
|
|
89
90
|
--contract <name> Check against a named contract instead of
|
|
90
|
-
detecting one:
|
|
91
|
-
verification, history, connected, cost-answer.
|
|
91
|
+
detecting one: ${d.contracts.join(', ')}.
|
|
92
92
|
--json The report as data.
|
|
93
93
|
|
|
94
94
|
Answers two questions and keeps them apart. Does this document conform —
|
|
@@ -99,6 +99,23 @@ ${bold('OPTIONS FOR conform')}
|
|
|
99
99
|
The second never gates. Choosing not to log sessions is a decision, not a
|
|
100
100
|
defect. See docs/format.md.
|
|
101
101
|
|
|
102
|
+
${bold('OPTIONS FOR rollup')}
|
|
103
|
+
--json The roll-up document as data. See docs/format.md.
|
|
104
|
+
|
|
105
|
+
Several people's bills, one roll-up. Each contributor runs
|
|
106
|
+
\`trazum profile --json\` where their traffic already is; this merges the
|
|
107
|
+
documents. A format and a merge, not a service: nothing is uploaded and there
|
|
108
|
+
is no account — the documents arrive however your team already moves files.
|
|
109
|
+
|
|
110
|
+
Most of the output is what the merge could not do. Each contributor's own
|
|
111
|
+
gaps stay with that contributor rather than being averaged into one figure,
|
|
112
|
+
the findings that need individual calls are named instead of dropped, and
|
|
113
|
+
every roll-up of more than one document says that overlap between
|
|
114
|
+
contributors is unmeasurable — two people exporting the same traffic double
|
|
115
|
+
the bill and no merge of summaries can see it.
|
|
116
|
+
|
|
117
|
+
Exits 1 when a contribution was handed over and could not be merged.
|
|
118
|
+
|
|
102
119
|
${bold('OPTIONS FOR feedback')}
|
|
103
120
|
(none)
|
|
104
121
|
|
|
@@ -1378,6 +1395,72 @@ ${bold('EXAMPLES')}
|
|
|
1378
1395
|
'None of those failed anything. Choosing not to record a field is a decision, not a defect, and a gate that failed on it would be this tool telling you what to log.',
|
|
1379
1396
|
},
|
|
1380
1397
|
|
|
1398
|
+
rollup: {
|
|
1399
|
+
noTargets: () =>
|
|
1400
|
+
'Pass the profile documents to roll up — each one written by `trazum profile --json` — or a directory of them.',
|
|
1401
|
+
noSuchTarget: (path) => `${path} is not there. A roll-up never guesses at a contribution it could not read.`,
|
|
1402
|
+
emptyDirectory: (path) =>
|
|
1403
|
+
`${path} holds no .json documents. An empty folder rolled up silently would report a team that spent nothing.`,
|
|
1404
|
+
heading: (contributors, usd, calls) =>
|
|
1405
|
+
`Roll-up of ${plural(contributors, 'contributor')} — ${usd} over ${plural(calls, 'call')}`,
|
|
1406
|
+
span: (from, to) => `Covering ${from} to ${to}, stated and never extrapolated from.`,
|
|
1407
|
+
noSpan: () => 'No contributor carried a clock, so this roll-up covers no stated period.',
|
|
1408
|
+
contributorsHeading: () => 'Contributors, and what each one could not see',
|
|
1409
|
+
contributor: (name, usd, calls, spanDays) =>
|
|
1410
|
+
`${name} — ${usd}, ${plural(calls, 'call')}${spanDays === null ? ', no clock' : `, ${plural(spanDays, 'day')}`}`,
|
|
1411
|
+
claimedSpan: (from, to, contributors) =>
|
|
1412
|
+
`Asked for ${from} to ${to} by ${plural(contributors, 'contributor')} — a claim about what was gone looking for, kept apart from what the records showed.`,
|
|
1413
|
+
claimedRow: (from, to) => `asked for ${from} to ${to}`,
|
|
1414
|
+
silentRuns: (runs) => runs,
|
|
1415
|
+
undated: (count) =>
|
|
1416
|
+
`${plural(count, 'record')} this contributor's own window could not place, because they carried no clock`,
|
|
1417
|
+
rejectedHeading: () => 'Handed over and not merged',
|
|
1418
|
+
rejected: (name, because) => `${name} — ${because}`,
|
|
1419
|
+
via: (rollup) => `via ${rollup}`,
|
|
1420
|
+
rejectedVia: (name, via, because) => `${name}, via ${via} — ${because}`,
|
|
1421
|
+
repeated: (names) =>
|
|
1422
|
+
`Handed over more than once, by name: ${names}. Its money is counted every time. Two machines genuinely sharing a name is possible, so nothing was subtracted — check whether a roll-up and one of the machines inside it were both handed over.`,
|
|
1423
|
+
identical: (names) => `The same document arrived more than once: ${names}.`,
|
|
1424
|
+
identicalUsd: (usd) =>
|
|
1425
|
+
`${usd} of the total above is the repeat. It is counted, not discarded — whether it is one export handed over twice or two machines that agreed exactly is yours to know.`,
|
|
1426
|
+
byLabelHeading: () => 'The merged bill, per workload',
|
|
1427
|
+
labelRow: (label, usd, calls) => `${label} — ${usd}, ${plural(calls, 'call')}`,
|
|
1428
|
+
notMergedHeading: () => 'Findings that do not roll up',
|
|
1429
|
+
notMerged: (finding, because) => `${finding} — ${because}.`,
|
|
1430
|
+
presentIn: (names) => `Present in: ${names}. Read it there.`,
|
|
1431
|
+
cannotSayHeading: () => 'What this roll-up cannot say about itself',
|
|
1432
|
+
caveat: (code) => {
|
|
1433
|
+
switch (code) {
|
|
1434
|
+
case 'overlap-invisible':
|
|
1435
|
+
return 'Overlap between contributors is unmeasurable here. Two people exporting the same traffic double the bill, and a merge of summaries cannot see it — the raw lines a duplicate check needs are in no document.';
|
|
1436
|
+
case 'mismatched-spans':
|
|
1437
|
+
return 'The contributors cover meaningfully different periods. The sum is a sum; reading a share of it as a comparison of rates is the mistake this names.';
|
|
1438
|
+
case 'contributor-without-clock':
|
|
1439
|
+
return 'A contributor carried no timestamp at all, so none of its spend is in any day above.';
|
|
1440
|
+
case 'day-top-label-unknown':
|
|
1441
|
+
return "A day drew from more than one contributor, so its dearest label is unknown: each contributor knows its own, and the merged answer needs per-label-per-day spend no document carries.";
|
|
1442
|
+
case 'no-claimed-period':
|
|
1443
|
+
return 'A contributor stated no window, so its span is all that is known of it — and a log whose latest record is the 5th may be a log of a quiet week or a log that stopped being written on the 5th.';
|
|
1444
|
+
case 'silence-inside-a-claim':
|
|
1445
|
+
return 'A contributor recorded nothing on days it asked for. Whether that is a quiet stretch or an export that stopped is yours to know; the days are named above.';
|
|
1446
|
+
case 'claim-not-bounded':
|
|
1447
|
+
return 'A contributor claimed one end of a window and not the other, so its silence cannot be measured against it.';
|
|
1448
|
+
case 'claim-too-long-to-enumerate':
|
|
1449
|
+
return 'A claimed window was too long to walk day by day and was not walked. The claim is kept; only its silence is unmeasured.';
|
|
1450
|
+
case 'contributor-named-twice':
|
|
1451
|
+
return 'A contributor name appears more than once, so its money may be counted twice. Handing over a roll-up and one of the machines inside it does exactly that, and the documents differ so the identical-document check cannot see it.';
|
|
1452
|
+
case 'identical-contributions':
|
|
1453
|
+
return 'Two contributions were the same document.';
|
|
1454
|
+
case 'contribution-rejected':
|
|
1455
|
+
return 'A contribution was not merged. That machine contributed nothing, which is a different statement from having spent nothing.';
|
|
1456
|
+
case 'unknown-fields-dropped':
|
|
1457
|
+
return 'A contribution carried a numeric field this version cannot classify, so it was left out rather than combined the wrong way.';
|
|
1458
|
+
default:
|
|
1459
|
+
return code;
|
|
1460
|
+
}
|
|
1461
|
+
},
|
|
1462
|
+
},
|
|
1463
|
+
|
|
1381
1464
|
where: {
|
|
1382
1465
|
hostHeading: () => 'Running inside',
|
|
1383
1466
|
subscription: (host) =>
|
package/src/i18n/es.ts
CHANGED
|
@@ -43,6 +43,7 @@ ${bold('USO')}
|
|
|
43
43
|
trazum prune <fichero> --cases <fichero> --yes
|
|
44
44
|
trazum where [fichero]
|
|
45
45
|
trazum conform <fichero|-> [--contract <nombre>]
|
|
46
|
+
trazum rollup <documento...|dir> [--json]
|
|
46
47
|
trazum models
|
|
47
48
|
trazum rules
|
|
48
49
|
trazum gateway <provider> --on-cannot-tell <fail-open|fail-closed>
|
|
@@ -74,8 +75,7 @@ ${bold('OPCIONES DE init')}
|
|
|
74
75
|
|
|
75
76
|
${bold('OPCIONES DE conform')}
|
|
76
77
|
--contract <nombre> Comprueba contra un contrato concreto en vez de
|
|
77
|
-
detectarlo:
|
|
78
|
-
verification, history, connected, cost-answer.
|
|
78
|
+
detectarlo: ${d.contracts.join(', ')}.
|
|
79
79
|
--json El informe como datos.
|
|
80
80
|
|
|
81
81
|
Responde dos preguntas y las mantiene separadas. ¿Cumple este documento —
|
|
@@ -86,6 +86,24 @@ ${bold('OPCIONES DE conform')}
|
|
|
86
86
|
La segunda nunca hace fallar nada. Decidir no registrar sesiones es una
|
|
87
87
|
decisión, no un defecto. Ver docs/format.md.
|
|
88
88
|
|
|
89
|
+
${bold('OPCIONES DE rollup')}
|
|
90
|
+
--json El documento de agregación como datos. Ver
|
|
91
|
+
docs/format.md.
|
|
92
|
+
|
|
93
|
+
Las facturas de varias personas, una sola agregación. Cada contribuyente
|
|
94
|
+
ejecuta \`trazum profile --json\` donde ya está su tráfico; esto fusiona los
|
|
95
|
+
documentos. Un formato y una fusión, no un servicio: no se sube nada y no hay
|
|
96
|
+
cuenta — los documentos llegan como tu equipo ya mueve ficheros.
|
|
97
|
+
|
|
98
|
+
Casi toda la salida es lo que la fusión no pudo hacer. Los huecos de cada
|
|
99
|
+
contribuyente se quedan con ese contribuyente en vez de promediarse en una
|
|
100
|
+
sola cifra, los hallazgos que necesitan llamadas individuales se nombran en
|
|
101
|
+
vez de desaparecer, y toda agregación de más de un documento dice que el
|
|
102
|
+
solapamiento entre contribuyentes no se puede medir: dos personas exportando
|
|
103
|
+
el mismo tráfico duplican la factura y ninguna fusión de resúmenes lo ve.
|
|
104
|
+
|
|
105
|
+
Sale con 1 cuando una contribución se entregó y no se pudo agregar.
|
|
106
|
+
|
|
89
107
|
${bold('OPCIONES DE feedback')}
|
|
90
108
|
(ninguna)
|
|
91
109
|
|
|
@@ -1383,6 +1401,73 @@ ${bold('EJEMPLOS')}
|
|
|
1383
1401
|
'Nada de eso ha hecho fallar nada. Decidir no registrar un campo es una decisión, no un defecto, y una puerta que fallara por ello sería esta herramienta diciéndote qué registrar.',
|
|
1384
1402
|
},
|
|
1385
1403
|
|
|
1404
|
+
rollup: {
|
|
1405
|
+
noTargets: () =>
|
|
1406
|
+
'Pasa los documentos de perfil que quieres agregar — cada uno escrito por `trazum profile --json` — o un directorio con ellos.',
|
|
1407
|
+
noSuchTarget: (path) =>
|
|
1408
|
+
`${path} no está. Una agregación nunca adivina una contribución que no pudo leer.`,
|
|
1409
|
+
emptyDirectory: (path) =>
|
|
1410
|
+
`${path} no contiene documentos .json. Una carpeta vacía agregada en silencio diría que el equipo no gastó nada.`,
|
|
1411
|
+
heading: (contributors, usd, calls) =>
|
|
1412
|
+
`Agregación de ${plural(contributors, 'contribuyente')} — ${usd} en ${plural(calls, 'llamada')}`,
|
|
1413
|
+
span: (from, to) => `Cubre del ${from} al ${to}, declarado y nunca extrapolado.`,
|
|
1414
|
+
noSpan: () => 'Ningún contribuyente traía reloj, así que esta agregación no cubre ningún período declarado.',
|
|
1415
|
+
contributorsHeading: () => 'Contribuyentes, y lo que cada uno no pudo ver',
|
|
1416
|
+
contributor: (name, usd, calls, spanDays) =>
|
|
1417
|
+
`${name} — ${usd}, ${plural(calls, 'llamada')}${spanDays === null ? ', sin reloj' : `, ${plural(spanDays, 'día')}`}`,
|
|
1418
|
+
claimedSpan: (from, to, contributors) =>
|
|
1419
|
+
`Pidió del ${from} al ${to} ${plural(contributors, 'contribuyente')} — una afirmación sobre lo que se fue a buscar, separada de lo que mostraron los registros.`,
|
|
1420
|
+
claimedRow: (from, to) => `pidió del ${from} al ${to}`,
|
|
1421
|
+
silentRuns: (runs) => runs,
|
|
1422
|
+
undated: (count) =>
|
|
1423
|
+
`${plural(count, 'registro')} que la propia ventana de este contribuyente no pudo situar, porque no traían reloj`,
|
|
1424
|
+
rejectedHeading: () => 'Entregado y no agregado',
|
|
1425
|
+
rejected: (name, because) => `${name} — ${because}`,
|
|
1426
|
+
via: (rollup) => `vía ${rollup}`,
|
|
1427
|
+
rejectedVia: (name, via, because) => `${name}, vía ${via} — ${because}`,
|
|
1428
|
+
repeated: (names) =>
|
|
1429
|
+
`Entregado más de una vez, por nombre: ${names}. Su dinero se cuenta cada vez. Que dos máquinas compartan nombre es posible, así que no se ha restado nada — comprueba si se entregaron a la vez una agregación y una de las máquinas que contiene.`,
|
|
1430
|
+
identical: (names) => `El mismo documento llegó más de una vez: ${names}.`,
|
|
1431
|
+
identicalUsd: (usd) =>
|
|
1432
|
+
`${usd} del total de arriba es la repetición. Se cuenta, no se descarta: si es una exportación entregada dos veces o dos máquinas que coincidieron exactamente es cosa tuya saberlo.`,
|
|
1433
|
+
byLabelHeading: () => 'La factura agregada, por carga de trabajo',
|
|
1434
|
+
labelRow: (label, usd, calls) => `${label} — ${usd}, ${plural(calls, 'llamada')}`,
|
|
1435
|
+
notMergedHeading: () => 'Hallazgos que no se agregan',
|
|
1436
|
+
notMerged: (finding, because) => `${finding} — ${because}.`,
|
|
1437
|
+
presentIn: (names) => `Presente en: ${names}. Léelo ahí.`,
|
|
1438
|
+
cannotSayHeading: () => 'Lo que esta agregación no puede decir sobre sí misma',
|
|
1439
|
+
caveat: (code) => {
|
|
1440
|
+
switch (code) {
|
|
1441
|
+
case 'overlap-invisible':
|
|
1442
|
+
return 'El solapamiento entre contribuyentes aquí no se puede medir. Dos personas exportando el mismo tráfico duplican la factura, y una fusión de resúmenes no lo ve: las líneas en bruto que necesita una comprobación de duplicados no están en ningún documento.';
|
|
1443
|
+
case 'mismatched-spans':
|
|
1444
|
+
return 'Los contribuyentes cubren períodos claramente distintos. La suma es una suma; leer una parte de ella como comparación de ritmos es el error que esto señala.';
|
|
1445
|
+
case 'contributor-without-clock':
|
|
1446
|
+
return 'Un contribuyente no traía ninguna marca de tiempo, así que nada de su gasto está en los días de arriba.';
|
|
1447
|
+
case 'day-top-label-unknown':
|
|
1448
|
+
return 'Un día vino de más de un contribuyente, así que su etiqueta más cara se desconoce: cada contribuyente conoce la suya, y la respuesta agregada necesita el gasto por etiqueta y día que ningún documento lleva.';
|
|
1449
|
+
case 'no-claimed-period':
|
|
1450
|
+
return 'Un contribuyente no declaró ninguna ventana, así que su tramo es todo lo que se sabe de él — y un registro cuya última línea es del día 5 puede ser una semana tranquila o un registro que dejó de escribirse el día 5.';
|
|
1451
|
+
case 'silence-inside-a-claim':
|
|
1452
|
+
return 'Un contribuyente no registró nada en días que pidió. Si es un tramo tranquilo o una exportación que se paró es cosa tuya saberlo; los días están nombrados arriba.';
|
|
1453
|
+
case 'claim-not-bounded':
|
|
1454
|
+
return 'Un contribuyente declaró un extremo de la ventana y no el otro, así que su silencio no se puede medir contra ella.';
|
|
1455
|
+
case 'claim-too-long-to-enumerate':
|
|
1456
|
+
return 'Una ventana declarada era demasiado larga para recorrerla día a día y no se recorrió. La afirmación se conserva; solo su silencio queda sin medir.';
|
|
1457
|
+
case 'contributor-named-twice':
|
|
1458
|
+
return 'Un nombre de contribuyente aparece más de una vez, así que su dinero puede estar contado dos veces. Entregar una agregación y una de las máquinas que contiene hace justo eso, y los documentos difieren, así que la comprobación de documento idéntico no lo ve.';
|
|
1459
|
+
case 'identical-contributions':
|
|
1460
|
+
return 'Dos contribuciones eran el mismo documento.';
|
|
1461
|
+
case 'contribution-rejected':
|
|
1462
|
+
return 'Una contribución no se agregó. Esa máquina no aportó nada, que no es lo mismo que no haber gastado nada.';
|
|
1463
|
+
case 'unknown-fields-dropped':
|
|
1464
|
+
return 'Una contribución traía un campo numérico que esta versión no sabe clasificar, así que se dejó fuera en vez de combinarlo mal.';
|
|
1465
|
+
default:
|
|
1466
|
+
return code;
|
|
1467
|
+
}
|
|
1468
|
+
},
|
|
1469
|
+
},
|
|
1470
|
+
|
|
1386
1471
|
where: {
|
|
1387
1472
|
hostHeading: () => 'Ejecutándose dentro de',
|
|
1388
1473
|
subscription: (host) =>
|
package/src/i18n/types.ts
CHANGED
|
@@ -16,6 +16,15 @@ export interface HelpDefaults {
|
|
|
16
16
|
avgOutputTokens: number;
|
|
17
17
|
cacheHitRate: number;
|
|
18
18
|
locales: readonly string[];
|
|
19
|
+
/**
|
|
20
|
+
* Every contract `--contract` accepts, from the one place that defines them.
|
|
21
|
+
*
|
|
22
|
+
* Retyped into the help text, this list stopped at `cost-answer` and stayed
|
|
23
|
+
* there through two releases that each added a contract — the same shape as
|
|
24
|
+
* the provider enumeration `help-enumerations.test.js` exists to keep out of
|
|
25
|
+
* USAGE, one section further down the same page.
|
|
26
|
+
*/
|
|
27
|
+
contracts: readonly string[];
|
|
19
28
|
}
|
|
20
29
|
|
|
21
30
|
export interface CliMessages {
|
|
@@ -423,6 +432,35 @@ export interface CliMessages {
|
|
|
423
432
|
unavailableNeverGates(): string;
|
|
424
433
|
};
|
|
425
434
|
|
|
435
|
+
rollup: {
|
|
436
|
+
noTargets(): string;
|
|
437
|
+
noSuchTarget(path: string): string;
|
|
438
|
+
emptyDirectory(path: string): string;
|
|
439
|
+
heading(contributors: number, usd: string, calls: number): string;
|
|
440
|
+
span(from: string, to: string): string;
|
|
441
|
+
noSpan(): string;
|
|
442
|
+
contributorsHeading(): string;
|
|
443
|
+
contributor(name: string, usd: string, calls: number, spanDays: number | null): string;
|
|
444
|
+
claimedSpan(from: string, to: string, contributors: number): string;
|
|
445
|
+
claimedRow(from: string, to: string): string;
|
|
446
|
+
silentRuns(runs: string): string;
|
|
447
|
+
undated(count: number): string;
|
|
448
|
+
rejectedHeading(): string;
|
|
449
|
+
rejected(name: string, because: string): string;
|
|
450
|
+
via(rollup: string): string;
|
|
451
|
+
rejectedVia(name: string, via: string, because: string): string;
|
|
452
|
+
repeated(names: string): string;
|
|
453
|
+
identical(names: string): string;
|
|
454
|
+
identicalUsd(usd: string): string;
|
|
455
|
+
byLabelHeading(): string;
|
|
456
|
+
labelRow(label: string, usd: string, calls: number): string;
|
|
457
|
+
notMergedHeading(): string;
|
|
458
|
+
notMerged(finding: string, because: string): string;
|
|
459
|
+
presentIn(names: string): string;
|
|
460
|
+
cannotSayHeading(): string;
|
|
461
|
+
caveat(code: string): string;
|
|
462
|
+
};
|
|
463
|
+
|
|
426
464
|
where: {
|
|
427
465
|
hostHeading(): string;
|
|
428
466
|
subscription(host: string): string;
|
package/src/index.ts
CHANGED
|
@@ -69,6 +69,7 @@ import {
|
|
|
69
69
|
explainGateFailure,
|
|
70
70
|
assignSources,
|
|
71
71
|
fleetRollup,
|
|
72
|
+
rollUp,
|
|
72
73
|
labelCoverage,
|
|
73
74
|
measuredUsage,
|
|
74
75
|
gateMargin,
|
|
@@ -593,6 +594,7 @@ const COMMAND_FLAGS: Record<string, string[]> = {
|
|
|
593
594
|
rank: ['level', 'model', 'calls', 'output-tokens', 'batch', 'disable', 'prompt', 'markdown-out'],
|
|
594
595
|
init: ['dry-run', 'yes', 'json', 'pricing', 'pricing-live'],
|
|
595
596
|
conform: ['contract', 'json'],
|
|
597
|
+
rollup: ['json'],
|
|
596
598
|
feedback: [],
|
|
597
599
|
gateway: ['on-cannot-tell', 'port', 'socket', 'pricing', 'pricing-live'],
|
|
598
600
|
ladder: ['pricing', 'pricing-live', 'since', 'until', 'label'],
|
|
@@ -2038,6 +2040,229 @@ async function commandConform(args: Args, t: CliMessages): Promise<void> {
|
|
|
2038
2040
|
console.log();
|
|
2039
2041
|
}
|
|
2040
2042
|
|
|
2043
|
+
/**
|
|
2044
|
+
* `trazum rollup <document...>` — several people's bills, one roll-up.
|
|
2045
|
+
*
|
|
2046
|
+
* The first command here that reads *documents* rather than logs. Everything
|
|
2047
|
+
* else assumes one operator with the files on disk; this assumes four people
|
|
2048
|
+
* who each already ran `trazum profile --json` where their traffic is, and one
|
|
2049
|
+
* of them wants the total.
|
|
2050
|
+
*
|
|
2051
|
+
* **A format and a merge, not a service.** There is no upload, no account and
|
|
2052
|
+
* no server: the documents arrive however the team already moves files, and
|
|
2053
|
+
* this reads them off the filesystem. That is the whole design — a tool whose
|
|
2054
|
+
* argument is that it reads your bill without uploading it cannot also be the
|
|
2055
|
+
* place everybody's bill is uploaded.
|
|
2056
|
+
*
|
|
2057
|
+
* A directory argument is expanded to the `.json` files directly inside it, so
|
|
2058
|
+
* a shared folder people drop a document into is a roll-up without anybody
|
|
2059
|
+
* writing a shell loop.
|
|
2060
|
+
*
|
|
2061
|
+
* The rendering leads with the total and then spends most of its lines on what
|
|
2062
|
+
* the merge could **not** do: the contributors' own gaps, the findings that do
|
|
2063
|
+
* not roll up, and the overlap between contributors that nothing here can see.
|
|
2064
|
+
* A roll-up is the document most likely to be pasted into a slide, and a total
|
|
2065
|
+
* with its caveats one screen away is a total that will be quoted alone.
|
|
2066
|
+
*/
|
|
2067
|
+
async function commandRollup(args: Args, t: CliMessages): Promise<void> {
|
|
2068
|
+
if (args.positional.length === 0) throw new Error(t.rollup.noTargets());
|
|
2069
|
+
|
|
2070
|
+
/** Every document to merge, in the order the caller named them. */
|
|
2071
|
+
const inputs: { name: string; text: string }[] = [];
|
|
2072
|
+
/** What a failed filesystem call was refusing, when it said. */
|
|
2073
|
+
const codeOf = (error: unknown): string | undefined =>
|
|
2074
|
+
typeof error === 'object' && error !== null ? (error as { code?: string }).code : undefined;
|
|
2075
|
+
|
|
2076
|
+
for (const target of args.positional) {
|
|
2077
|
+
/**
|
|
2078
|
+
* Attempted, not checked first.
|
|
2079
|
+
*
|
|
2080
|
+
* The obvious shape is `stat` and then branch on `isDirectory()`, and it
|
|
2081
|
+
* is a check-then-act: between the answer and the read the path can become
|
|
2082
|
+
* something else, and CodeQL flagged exactly that on the pull request that
|
|
2083
|
+
* introduced this command. Reading the error code has no window between
|
|
2084
|
+
* the two operations, because there is only one operation — and it is the
|
|
2085
|
+
* same reasoning the gateway applies to a budget decision, which happens
|
|
2086
|
+
* before the upstream is opened rather than between two things.
|
|
2087
|
+
*
|
|
2088
|
+
* `ENOTDIR` is an answer — this is a file — and every other failure is a
|
|
2089
|
+
* failure.
|
|
2090
|
+
*/
|
|
2091
|
+
const listing = await readdir(target, { withFileTypes: true }).catch((error: unknown) => {
|
|
2092
|
+
const code = codeOf(error);
|
|
2093
|
+
if (code === 'ENOTDIR') return null;
|
|
2094
|
+
if (code === 'ENOENT') throw new Error(t.rollup.noSuchTarget(target));
|
|
2095
|
+
throw error;
|
|
2096
|
+
});
|
|
2097
|
+
|
|
2098
|
+
if (listing !== null) {
|
|
2099
|
+
const found = listing
|
|
2100
|
+
.filter((child) => child.isFile() && child.name.endsWith('.json'))
|
|
2101
|
+
.map((child) => join(target, child.name))
|
|
2102
|
+
.sort((a, b) => a.localeCompare(b));
|
|
2103
|
+
// An empty directory is named rather than quietly contributing nothing:
|
|
2104
|
+
// a roll-up of a folder somebody spelled wrong would otherwise report a
|
|
2105
|
+
// total of zero and look like a team that spent nothing.
|
|
2106
|
+
if (found.length === 0) throw new Error(t.rollup.emptyDirectory(target));
|
|
2107
|
+
for (const file of found) inputs.push({ name: file, text: await readFile(file, 'utf8') });
|
|
2108
|
+
continue;
|
|
2109
|
+
}
|
|
2110
|
+
|
|
2111
|
+
const text = await readFile(target, 'utf8').catch((error: unknown) => {
|
|
2112
|
+
// Gone between the two calls, which is the race the shape above avoids
|
|
2113
|
+
// deciding on: the read is what says so, and it says so by name.
|
|
2114
|
+
if (codeOf(error) === 'ENOENT') throw new Error(t.rollup.noSuchTarget(target));
|
|
2115
|
+
throw error;
|
|
2116
|
+
});
|
|
2117
|
+
inputs.push({ name: target, text });
|
|
2118
|
+
}
|
|
2119
|
+
|
|
2120
|
+
const document = rollUp(inputs);
|
|
2121
|
+
|
|
2122
|
+
if (boolFlag(args, 'json')) {
|
|
2123
|
+
console.log(JSON.stringify(document, null, 2));
|
|
2124
|
+
// A rejected contribution is a machine missing from the total, so it gates
|
|
2125
|
+
// — the same reason `conform` exits 1 on a problem. Every other caveat is
|
|
2126
|
+
// a property of merging summaries and would gate on every honest roll-up.
|
|
2127
|
+
if (document.rejected.length > 0) process.exitCode = 1;
|
|
2128
|
+
return;
|
|
2129
|
+
}
|
|
2130
|
+
|
|
2131
|
+
const day = (ms: number): string => new Date(ms).toISOString().slice(0, 10);
|
|
2132
|
+
|
|
2133
|
+
console.log();
|
|
2134
|
+
console.log(
|
|
2135
|
+
c.bold(
|
|
2136
|
+
t.rollup.heading(document.contributors.length, formatUsd(document.total.totalUsd), document.total.calls),
|
|
2137
|
+
),
|
|
2138
|
+
);
|
|
2139
|
+
console.log(
|
|
2140
|
+
` ${c.dim(
|
|
2141
|
+
document.span === null
|
|
2142
|
+
? t.rollup.noSpan()
|
|
2143
|
+
: t.rollup.span(day(document.span.fromMs), day(document.span.toMs)),
|
|
2144
|
+
)}`,
|
|
2145
|
+
);
|
|
2146
|
+
if (document.claimedSpan !== null) {
|
|
2147
|
+
console.log(
|
|
2148
|
+
` ${c.dim(
|
|
2149
|
+
wrap(
|
|
2150
|
+
t.rollup.claimedSpan(
|
|
2151
|
+
day(document.claimedSpan.fromMs),
|
|
2152
|
+
day(document.claimedSpan.toMs - 1),
|
|
2153
|
+
document.claimedSpan.contributors,
|
|
2154
|
+
),
|
|
2155
|
+
72,
|
|
2156
|
+
' ',
|
|
2157
|
+
),
|
|
2158
|
+
)}`,
|
|
2159
|
+
);
|
|
2160
|
+
}
|
|
2161
|
+
|
|
2162
|
+
console.log();
|
|
2163
|
+
console.log(c.bold(t.rollup.contributorsHeading()));
|
|
2164
|
+
for (const contributor of document.contributors) {
|
|
2165
|
+
console.log(
|
|
2166
|
+
` ${t.rollup.contributor(
|
|
2167
|
+
contributor.name,
|
|
2168
|
+
formatUsd(contributor.totalUsd),
|
|
2169
|
+
contributor.calls,
|
|
2170
|
+
contributor.spanDays === null ? null : Math.round(contributor.spanDays),
|
|
2171
|
+
)}${contributor.via === null ? '' : ` ${c.dim(t.rollup.via(contributor.via))}`}`,
|
|
2172
|
+
);
|
|
2173
|
+
/**
|
|
2174
|
+
* What this contributor asked for, before what it found.
|
|
2175
|
+
*
|
|
2176
|
+
* A span is not a period: a log whose latest record is the 5th may be a
|
|
2177
|
+
* log of a quiet week or a log that stopped being written on the 5th, and
|
|
2178
|
+
* only a claim tells those apart. Printed above the gaps because the
|
|
2179
|
+
* silence below is measured against it.
|
|
2180
|
+
*/
|
|
2181
|
+
if (contributor.claimed !== null) {
|
|
2182
|
+
const { sinceMs, untilMs } = contributor.claimed;
|
|
2183
|
+
if (sinceMs !== null && untilMs !== null) {
|
|
2184
|
+
// The window is half-open, so the last claimed day is the one before
|
|
2185
|
+
// `until` — printed as the reader would say it, not as the filter
|
|
2186
|
+
// stores it.
|
|
2187
|
+
console.log(` ${c.dim(t.rollup.claimedRow(day(sinceMs), day(untilMs - 1)))}`);
|
|
2188
|
+
}
|
|
2189
|
+
if (contributor.undatedExcluded !== null && contributor.undatedExcluded > 0) {
|
|
2190
|
+
console.log(` ${c.yellow(wrap(t.rollup.undated(contributor.undatedExcluded), 70, ' '))}`);
|
|
2191
|
+
}
|
|
2192
|
+
}
|
|
2193
|
+
// Every gap under the contributor that has it, never summed into one
|
|
2194
|
+
// figure: "one of your four machines is 90% unpriced" is the finding, and
|
|
2195
|
+
// an average is what hides it.
|
|
2196
|
+
for (const gap of contributor.gaps) {
|
|
2197
|
+
console.log(` ${c.yellow(wrap(gap.detail, 70, ' '))}`);
|
|
2198
|
+
}
|
|
2199
|
+
// The silent stretches by name, under the gap that counted them: "eight
|
|
2200
|
+
// days recorded nothing" is a number, and which eight is the finding.
|
|
2201
|
+
if (contributor.silence !== null && contributor.silence.runs.length > 0) {
|
|
2202
|
+
const runs = contributor.silence.runs
|
|
2203
|
+
.map((run) => (run.from === run.to ? run.from : `${run.from} to ${run.to}`))
|
|
2204
|
+
.join(', ');
|
|
2205
|
+
console.log(` ${c.dim(wrap(t.rollup.silentRuns(runs), 68, ' '))}`);
|
|
2206
|
+
}
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2209
|
+
if (document.rejected.length > 0) {
|
|
2210
|
+
console.log();
|
|
2211
|
+
console.log(c.bold(t.rollup.rejectedHeading()));
|
|
2212
|
+
for (const rejection of document.rejected) {
|
|
2213
|
+
// The roll-up it arrived through, when it came through one: a rejection
|
|
2214
|
+
// whose origin got lost is a machine nobody knows to go and fix.
|
|
2215
|
+
const line =
|
|
2216
|
+
rejection.via === null
|
|
2217
|
+
? t.rollup.rejected(rejection.name, rejection.because)
|
|
2218
|
+
: t.rollup.rejectedVia(rejection.name, rejection.via, rejection.because);
|
|
2219
|
+
console.log(` ${c.red(wrap(line, 72, ' '))}`);
|
|
2220
|
+
}
|
|
2221
|
+
process.exitCode = 1;
|
|
2222
|
+
}
|
|
2223
|
+
|
|
2224
|
+
if (document.identicalContributions.groups.length > 0) {
|
|
2225
|
+
console.log();
|
|
2226
|
+
for (const group of document.identicalContributions.groups) {
|
|
2227
|
+
console.log(` ${c.yellow(wrap(t.rollup.identical(group.join(', ')), 72, ' '))}`);
|
|
2228
|
+
}
|
|
2229
|
+
console.log(` ${c.dim(t.rollup.identicalUsd(formatUsd(document.identicalContributions.usd)))}`);
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2232
|
+
if (document.repeatedContributors.length > 0) {
|
|
2233
|
+
console.log();
|
|
2234
|
+
console.log(` ${c.yellow(wrap(t.rollup.repeated(document.repeatedContributors.join(', ')), 72, ' '))}`);
|
|
2235
|
+
}
|
|
2236
|
+
|
|
2237
|
+
if (document.byLabel.length > 0) {
|
|
2238
|
+
console.log();
|
|
2239
|
+
console.log(c.bold(t.rollup.byLabelHeading()));
|
|
2240
|
+
for (const row of document.byLabel.slice(0, 8)) {
|
|
2241
|
+
console.log(` ${t.rollup.labelRow(row.label, formatUsd(row.breakdown.totalUsd), row.breakdown.calls)}`);
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
|
|
2245
|
+
if (document.notMerged.length > 0) {
|
|
2246
|
+
console.log();
|
|
2247
|
+
console.log(c.bold(t.rollup.notMergedHeading()));
|
|
2248
|
+
for (const finding of document.notMerged) {
|
|
2249
|
+
console.log(` ${wrap(t.rollup.notMerged(finding.finding, finding.because), 72, ' ')}`);
|
|
2250
|
+
if (finding.presentIn.length > 0) {
|
|
2251
|
+
console.log(` ${c.dim(t.rollup.presentIn(finding.presentIn.join(', ')))}`);
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
|
|
2256
|
+
if (document.cannotSay.length > 0) {
|
|
2257
|
+
console.log();
|
|
2258
|
+
console.log(c.bold(t.rollup.cannotSayHeading()));
|
|
2259
|
+
for (const caveat of document.cannotSay) {
|
|
2260
|
+
console.log(` ${c.dim(wrap(t.rollup.caveat(caveat), 72, ' '))}`);
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
console.log();
|
|
2264
|
+
}
|
|
2265
|
+
|
|
2041
2266
|
/**
|
|
2042
2267
|
* `trazum feedback` — where to say it, and what to say.
|
|
2043
2268
|
*
|
|
@@ -9343,6 +9568,7 @@ async function main(): Promise<void> {
|
|
|
9343
9568
|
avgOutputTokens: DEFAULT_USAGE.avgOutputTokens,
|
|
9344
9569
|
cacheHitRate: DEFAULT_USAGE.cacheHitRate,
|
|
9345
9570
|
locales: LOCALES,
|
|
9571
|
+
contracts: CONTRACT_NAMES,
|
|
9346
9572
|
},
|
|
9347
9573
|
c.bold,
|
|
9348
9574
|
),
|
|
@@ -9487,6 +9713,9 @@ async function main(): Promise<void> {
|
|
|
9487
9713
|
case 'conform':
|
|
9488
9714
|
await commandConform(args, t);
|
|
9489
9715
|
break;
|
|
9716
|
+
case 'rollup':
|
|
9717
|
+
await commandRollup(args, t);
|
|
9718
|
+
break;
|
|
9490
9719
|
case 'init':
|
|
9491
9720
|
await commandInit(args, config, pricing, t);
|
|
9492
9721
|
break;
|