@trazum/cli 3.0.1 → 3.0.3
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 +4 -1
- package/assets/trazum-statusline.sh +45 -0
- package/dist/base-cost.d.ts +173 -0
- package/dist/base-cost.d.ts.map +1 -0
- package/dist/base-cost.js +244 -0
- package/dist/base-cost.js.map +1 -0
- package/dist/bill-range.d.ts +118 -0
- package/dist/bill-range.d.ts.map +1 -0
- package/dist/bill-range.js +122 -0
- package/dist/bill-range.js.map +1 -0
- package/dist/command-help.d.ts +17 -0
- package/dist/command-help.d.ts.map +1 -0
- package/dist/command-help.js +69 -0
- package/dist/command-help.js.map +1 -0
- package/dist/filter.d.ts +7 -1
- package/dist/filter.d.ts.map +1 -1
- package/dist/filter.js +10 -18
- package/dist/filter.js.map +1 -1
- package/dist/gateway-metrics.d.ts +83 -0
- package/dist/gateway-metrics.d.ts.map +1 -0
- package/dist/gateway-metrics.js +181 -0
- package/dist/gateway-metrics.js.map +1 -0
- package/dist/gateway-server.d.ts +23 -5
- package/dist/gateway-server.d.ts.map +1 -1
- package/dist/gateway-server.js +26 -1
- package/dist/gateway-server.js.map +1 -1
- package/dist/gateway-spend.d.ts +11 -1
- package/dist/gateway-spend.d.ts.map +1 -1
- package/dist/gateway-spend.js +44 -32
- package/dist/gateway-spend.js.map +1 -1
- package/dist/git.d.ts +70 -0
- package/dist/git.d.ts.map +1 -1
- package/dist/git.js +145 -0
- package/dist/git.js.map +1 -1
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +358 -6
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/es.d.ts +0 -1
- package/dist/i18n/es.d.ts.map +1 -1
- package/dist/i18n/es.js +456 -35
- package/dist/i18n/es.js.map +1 -1
- package/dist/i18n/types.d.ts +205 -0
- package/dist/i18n/types.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +942 -59
- package/dist/index.js.map +1 -1
- package/dist/loopback-guard.d.ts +37 -0
- package/dist/loopback-guard.d.ts.map +1 -0
- package/dist/loopback-guard.js +65 -0
- package/dist/loopback-guard.js.map +1 -0
- package/dist/markdown.d.ts +23 -0
- package/dist/markdown.d.ts.map +1 -1
- package/dist/markdown.js +105 -0
- package/dist/markdown.js.map +1 -1
- package/dist/plan-edits.d.ts +63 -0
- package/dist/plan-edits.d.ts.map +1 -0
- package/dist/plan-edits.js +96 -0
- package/dist/plan-edits.js.map +1 -0
- package/dist/proactive.d.ts +17 -2
- package/dist/proactive.d.ts.map +1 -1
- package/dist/proactive.js +16 -9
- package/dist/proactive.js.map +1 -1
- package/dist/receipt-send.d.ts +44 -0
- package/dist/receipt-send.d.ts.map +1 -0
- package/dist/receipt-send.js +71 -0
- package/dist/receipt-send.js.map +1 -0
- package/dist/serve.d.ts +7 -0
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +22 -1
- package/dist/serve.js.map +1 -1
- package/dist/session-guard.d.ts +210 -0
- package/dist/session-guard.d.ts.map +1 -0
- package/dist/session-guard.js +463 -0
- package/dist/session-guard.js.map +1 -0
- package/dist/task.d.ts +7 -1
- package/dist/task.d.ts.map +1 -1
- package/dist/task.js +7 -26
- package/dist/task.js.map +1 -1
- package/dist/waste.d.ts +25 -0
- package/dist/waste.d.ts.map +1 -0
- package/dist/waste.js +39 -0
- package/dist/waste.js.map +1 -0
- package/dist/zone.d.ts +27 -0
- package/dist/zone.d.ts.map +1 -0
- package/dist/zone.js +96 -0
- package/dist/zone.js.map +1 -0
- package/package.json +2 -2
- package/src/base-cost.ts +384 -0
- package/src/bill-range.ts +206 -0
- package/src/command-help.ts +65 -0
- package/src/filter.ts +11 -18
- package/src/gateway-metrics.ts +209 -0
- package/src/gateway-server.ts +43 -6
- package/src/gateway-spend.ts +45 -33
- package/src/git.ts +158 -0
- package/src/i18n/en.ts +424 -6
- package/src/i18n/es.ts +542 -35
- package/src/i18n/types.ts +208 -0
- package/src/index.ts +952 -58
- package/src/loopback-guard.ts +74 -0
- package/src/markdown.ts +117 -0
- package/src/plan-edits.ts +120 -0
- package/src/proactive.ts +22 -13
- package/src/receipt-send.ts +89 -0
- package/src/serve.ts +23 -1
- package/src/session-guard.ts +541 -0
- package/src/task.ts +8 -26
- package/src/waste.ts +42 -0
- package/src/zone.ts +95 -0
package/dist/waste.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `trazum waste`: the files it reads, and nothing else.
|
|
3
|
+
*
|
|
4
|
+
* The analysis is `analyzeSessionWaste` in the core and is pure. This is the
|
|
5
|
+
* part that touches the disk, kept small so what it touches can be said in one
|
|
6
|
+
* place: the session's transcript, the transcripts of its subagents in the
|
|
7
|
+
* folder beside it (as `session-guard` and the status line read them), and the
|
|
8
|
+
* size in bytes of one CLAUDE.md. A `stat` for the size. The content of that
|
|
9
|
+
* file is never opened, and no file is written.
|
|
10
|
+
*/
|
|
11
|
+
import { readFile, stat } from 'node:fs/promises';
|
|
12
|
+
import { join, resolve } from 'node:path';
|
|
13
|
+
import { jsonlFiles } from './session-guard.js';
|
|
14
|
+
/** The transcript first, then its subagents' transcripts in a stable order. */
|
|
15
|
+
export async function readSession(target) {
|
|
16
|
+
const info = await stat(target).catch(() => null);
|
|
17
|
+
if (info === null || !info.isFile())
|
|
18
|
+
return { ok: false, cause: 'not-found' };
|
|
19
|
+
const subagents = await jsonlFiles(join(target.replace(/\.jsonl$/, ''), 'subagents'));
|
|
20
|
+
if (subagents === null)
|
|
21
|
+
return { ok: false, cause: 'unreadable' };
|
|
22
|
+
const texts = [];
|
|
23
|
+
for (const file of [target, ...subagents]) {
|
|
24
|
+
try {
|
|
25
|
+
texts.push(await readFile(file, 'utf8'));
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return { ok: false, cause: 'unreadable' };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return { ok: true, texts };
|
|
32
|
+
}
|
|
33
|
+
/** A file's size in bytes, or null when it is not a regular file here. Never its content. */
|
|
34
|
+
export async function sizeOf(path) {
|
|
35
|
+
const absolute = resolve(path);
|
|
36
|
+
const info = await stat(absolute).catch(() => null);
|
|
37
|
+
return info !== null && info.isFile() ? { path: absolute, bytes: info.size } : null;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=waste.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"waste.js","sourceRoot":"","sources":["../src/waste.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAMhD,+EAA+E;AAC/E,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAAc;IAC9C,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;IAClD,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;IAC9E,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC;IACtF,IAAI,SAAS,KAAK,IAAI;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC;IAClE,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,IAAI,IAAI,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,EAAE,CAAC;QAC1C,IAAI,CAAC;YACH,KAAK,CAAC,IAAI,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;QAC3C,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC;QAC5C,CAAC;IACH,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC;AAED,6FAA6F;AAC7F,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,IAAY;IACvC,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;IACpD,OAAO,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACtF,CAAC"}
|
package/dist/zone.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The zone's own spelling of a name the platform accepts (`europe/madrid` is
|
|
3
|
+
* `Europe/Madrid`), or `null` for one it does not. Nothing is guessed: a name
|
|
4
|
+
* the platform refuses is refused here.
|
|
5
|
+
*/
|
|
6
|
+
export declare function canonicalZone(name: string): string | null;
|
|
7
|
+
/** `YYYY-MM-DD` of an instant on the calendar of `zone`. */
|
|
8
|
+
export declare function dayInZone(ms: number, zone: string): string;
|
|
9
|
+
/** The calendar day after a `YYYY-MM-DD` one. Pure calendar arithmetic: no zone is involved. */
|
|
10
|
+
export declare function nextDay(day: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* The first instant of a `YYYY-MM-DD` day in `zone`.
|
|
13
|
+
*
|
|
14
|
+
* Found by search, not by adding an offset: the offset at midnight is not the
|
|
15
|
+
* offset the day began under when a clock change falls that night, and a day
|
|
16
|
+
* whose midnight does not exist (a zone that skips it) begins at the first
|
|
17
|
+
* instant that is on or after the day. Every zone's offset is within -12h and
|
|
18
|
+
* +14h, so the instant lies within a day and a half of the UTC midnight.
|
|
19
|
+
*/
|
|
20
|
+
export declare function startOfDayInZone(day: string, zone: string): number;
|
|
21
|
+
/**
|
|
22
|
+
* The usage lines grouped by the day they fall on in `zone`. A line with no
|
|
23
|
+
* clock, or one the profile cannot read, is in no group: the profile accounts
|
|
24
|
+
* for those itself, and the bill's own total still holds them.
|
|
25
|
+
*/
|
|
26
|
+
export declare function groupByDayInZone(lines: readonly string[], zone: string): Map<string, string[]>;
|
|
27
|
+
//# sourceMappingURL=zone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zone.d.ts","sourceRoot":"","sources":["../src/zone.ts"],"names":[],"mappings":"AA8BA;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAOzD;AAED,4DAA4D;AAC5D,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAI1D;AAED,gGAAgG;AAChG,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAWlE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAW9F"}
|
package/dist/zone.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { parseUsageLine } from '@trazum/core';
|
|
2
|
+
/**
|
|
3
|
+
* Calendar days in a named time zone, for `trazum bill --timezone` (#826).
|
|
4
|
+
*
|
|
5
|
+
* Everything else in the CLI cuts days in UTC, so the same log answers the same
|
|
6
|
+
* way in every office. A person who bills by their own calendar asks for their
|
|
7
|
+
* zone by its IANA name, and this is the whole of what that costs: the platform's
|
|
8
|
+
* `Intl.DateTimeFormat` knows the zone's rules, including the days that are 23 or
|
|
9
|
+
* 25 hours long, so no offset table and no dependency is shipped here.
|
|
10
|
+
*/
|
|
11
|
+
const formatters = new Map();
|
|
12
|
+
function formatterFor(zone) {
|
|
13
|
+
const known = formatters.get(zone);
|
|
14
|
+
if (known !== undefined)
|
|
15
|
+
return known;
|
|
16
|
+
const made = new Intl.DateTimeFormat('en-US', {
|
|
17
|
+
timeZone: zone,
|
|
18
|
+
calendar: 'gregory',
|
|
19
|
+
numberingSystem: 'latn',
|
|
20
|
+
hourCycle: 'h23',
|
|
21
|
+
year: 'numeric',
|
|
22
|
+
month: '2-digit',
|
|
23
|
+
day: '2-digit',
|
|
24
|
+
});
|
|
25
|
+
formatters.set(zone, made);
|
|
26
|
+
return made;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The zone's own spelling of a name the platform accepts (`europe/madrid` is
|
|
30
|
+
* `Europe/Madrid`), or `null` for one it does not. Nothing is guessed: a name
|
|
31
|
+
* the platform refuses is refused here.
|
|
32
|
+
*/
|
|
33
|
+
export function canonicalZone(name) {
|
|
34
|
+
if (name.trim() === '')
|
|
35
|
+
return null;
|
|
36
|
+
try {
|
|
37
|
+
return new Intl.DateTimeFormat('en-US', { timeZone: name }).resolvedOptions().timeZone;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** `YYYY-MM-DD` of an instant on the calendar of `zone`. */
|
|
44
|
+
export function dayInZone(ms, zone) {
|
|
45
|
+
const parts = formatterFor(zone).formatToParts(new Date(ms));
|
|
46
|
+
const of = (type) => parts.find((part) => part.type === type)?.value ?? '';
|
|
47
|
+
return `${of('year').padStart(4, '0')}-${of('month')}-${of('day')}`;
|
|
48
|
+
}
|
|
49
|
+
/** The calendar day after a `YYYY-MM-DD` one. Pure calendar arithmetic: no zone is involved. */
|
|
50
|
+
export function nextDay(day) {
|
|
51
|
+
return new Date(Date.parse(`${day}T00:00:00Z`) + 86_400_000).toISOString().slice(0, 10);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The first instant of a `YYYY-MM-DD` day in `zone`.
|
|
55
|
+
*
|
|
56
|
+
* Found by search, not by adding an offset: the offset at midnight is not the
|
|
57
|
+
* offset the day began under when a clock change falls that night, and a day
|
|
58
|
+
* whose midnight does not exist (a zone that skips it) begins at the first
|
|
59
|
+
* instant that is on or after the day. Every zone's offset is within -12h and
|
|
60
|
+
* +14h, so the instant lies within a day and a half of the UTC midnight.
|
|
61
|
+
*/
|
|
62
|
+
export function startOfDayInZone(day, zone) {
|
|
63
|
+
const utcMidnight = Date.parse(`${day}T00:00:00Z`);
|
|
64
|
+
let low = utcMidnight - 15 * 3_600_000;
|
|
65
|
+
let high = utcMidnight + 15 * 3_600_000;
|
|
66
|
+
/* Invariant: `low` is on an earlier day than `day`, `high` on `day` or later. */
|
|
67
|
+
while (high - low > 1) {
|
|
68
|
+
const mid = Math.floor((low + high) / 2);
|
|
69
|
+
if (dayInZone(mid, zone) < day)
|
|
70
|
+
low = mid;
|
|
71
|
+
else
|
|
72
|
+
high = mid;
|
|
73
|
+
}
|
|
74
|
+
return high;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The usage lines grouped by the day they fall on in `zone`. A line with no
|
|
78
|
+
* clock, or one the profile cannot read, is in no group: the profile accounts
|
|
79
|
+
* for those itself, and the bill's own total still holds them.
|
|
80
|
+
*/
|
|
81
|
+
export function groupByDayInZone(lines, zone) {
|
|
82
|
+
const days = new Map();
|
|
83
|
+
for (const line of lines) {
|
|
84
|
+
const record = parseUsageLine(line);
|
|
85
|
+
if (record === null || record.ts === null)
|
|
86
|
+
continue;
|
|
87
|
+
const day = dayInZone(record.ts, zone);
|
|
88
|
+
const own = days.get(day);
|
|
89
|
+
if (own === undefined)
|
|
90
|
+
days.set(day, [line]);
|
|
91
|
+
else
|
|
92
|
+
own.push(line);
|
|
93
|
+
}
|
|
94
|
+
return days;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=zone.js.map
|
package/dist/zone.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zone.js","sourceRoot":"","sources":["../src/zone.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trazum/cli",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "What your AI agents cost, per project, offline: one bill across Claude Code, Codex and Gemini CLI sessions, plus Anthropic, OpenAI, Gemini, OpenRouter, OTel and LiteLLM usage, written as PDF, HTML or CSV, with budgets enforced in CI.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "David Mu\u00f1oz Rey",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"prepublishOnly": "npm run build && npm test"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@trazum/core": "3.0.
|
|
57
|
+
"@trazum/core": "3.0.3"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@types/node": "^26.6.6",
|
package/src/base-cost.ts
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { resolve, sep } from 'node:path';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
PRICING_LAST_REVIEWED,
|
|
6
|
+
SOURCE_EXTENSIONS,
|
|
7
|
+
effectivePricing,
|
|
8
|
+
extractPrompts,
|
|
9
|
+
hasMarker,
|
|
10
|
+
matchGlob,
|
|
11
|
+
promptId,
|
|
12
|
+
reviewedForModels,
|
|
13
|
+
} from '@trazum/core';
|
|
14
|
+
import type { ModelPricing, PricingCatalogue } from '@trazum/core';
|
|
15
|
+
import { walkIncludes, walkPrompts } from '@trazum/core/node';
|
|
16
|
+
|
|
17
|
+
import { commitOf, contentAt, filesAt, gitAvailable, pathInRepository, repositoryRoot } from './git.js';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* What a pull request does to each prompt's cost against its base branch
|
|
21
|
+
* (#785): `trazum check <target> --base <ref>`.
|
|
22
|
+
*
|
|
23
|
+
* The base side is read out of the clone the job already has, with
|
|
24
|
+
* `git show`, through `git.ts`. Nothing is fetched and nothing is sent: a
|
|
25
|
+
* base commit the checkout does not hold is reported as missing, never
|
|
26
|
+
* replaced by the working tree, which would compare the head with itself
|
|
27
|
+
* and report every pull request as free.
|
|
28
|
+
*
|
|
29
|
+
* Every figure is **input tokens at the model's input price**: what the
|
|
30
|
+
* prompt itself costs per call. Output is left out on purpose, because a
|
|
31
|
+
* prompt edit does not set how much the model writes back, and a figure
|
|
32
|
+
* that included a typed output size would carry a number nobody measured.
|
|
33
|
+
*
|
|
34
|
+
* A month needs a number of calls, and that number is a statement about
|
|
35
|
+
* traffic. It comes from `volumes` in `trazum.config.json`, keyed by the
|
|
36
|
+
* label `labels` maps to the prompt file, and from nowhere else. A prompt
|
|
37
|
+
* with no stated volume is priced per call, and the report says so: a
|
|
38
|
+
* month at an invented volume is the figure this product exists not to
|
|
39
|
+
* print.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/** One prompt, on both sides of the comparison. `null` where it is absent. */
|
|
43
|
+
export interface PromptPair {
|
|
44
|
+
/** How the report names it: a path, or `path#name` for a marked prompt. */
|
|
45
|
+
id: string;
|
|
46
|
+
/** The file it lives in, as the head's walk names it. */
|
|
47
|
+
file: string;
|
|
48
|
+
/** True for a prompt marked inside a source file. */
|
|
49
|
+
embedded: boolean;
|
|
50
|
+
base: string | null;
|
|
51
|
+
head: string | null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** One side of one prompt, priced. */
|
|
55
|
+
export interface PricedSide {
|
|
56
|
+
tokens: number;
|
|
57
|
+
/** The input price this side was billed at, per million tokens. */
|
|
58
|
+
inputPerMTok: number;
|
|
59
|
+
perCallUsd: number;
|
|
60
|
+
/** `null` when nobody stated a volume for this prompt. */
|
|
61
|
+
monthlyUsd: number | null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface BaseCostRow {
|
|
65
|
+
id: string;
|
|
66
|
+
base: PricedSide | null;
|
|
67
|
+
head: PricedSide | null;
|
|
68
|
+
/** Calls a month from `volumes`, or `null`: then the row is per call only. */
|
|
69
|
+
callsPerMonth: number | null;
|
|
70
|
+
/** The labels whose volumes were added up for this prompt. */
|
|
71
|
+
labels: string[];
|
|
72
|
+
perCallChangeUsd: number;
|
|
73
|
+
monthlyChangeUsd: number | null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The price every figure was computed at, and where it came from. */
|
|
77
|
+
export interface BaseCostPrice {
|
|
78
|
+
model: string;
|
|
79
|
+
displayName: string;
|
|
80
|
+
/** Who sells it, as the catalogue records it; `null` for an overlay's model with none. */
|
|
81
|
+
provider: string | null;
|
|
82
|
+
/** True when a local pricing overlay supplied this model's price. */
|
|
83
|
+
overlaid: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* The day this price was read: the provider's review date in the bundled
|
|
86
|
+
* catalogue, or the overlay's own date. Never today's date and never a
|
|
87
|
+
* date this module made up: `reviewedForModels` is the one place it comes
|
|
88
|
+
* from.
|
|
89
|
+
*/
|
|
90
|
+
readOn: string;
|
|
91
|
+
/** When a promotional price applied, the last day it does. */
|
|
92
|
+
promoUntil: string | null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface BaseCostGate {
|
|
96
|
+
/** The most the monthly cost may grow, from `--max-monthly-increase-usd`. */
|
|
97
|
+
maxIncreaseUsd: number;
|
|
98
|
+
breached: boolean;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export type BaseCostReport =
|
|
102
|
+
| {
|
|
103
|
+
status: 'compared';
|
|
104
|
+
/** What the caller passed, and the commit it named. */
|
|
105
|
+
ref: string;
|
|
106
|
+
sha: string;
|
|
107
|
+
price: BaseCostPrice;
|
|
108
|
+
/** Whether the model came from `usage.model` or is Trazum's default. */
|
|
109
|
+
modelFrom: 'config' | 'default';
|
|
110
|
+
/** Prompts whose text differs, added or removed, in id order. */
|
|
111
|
+
rows: BaseCostRow[];
|
|
112
|
+
/** Prompts identical on both sides: counted, not listed. */
|
|
113
|
+
unchanged: number;
|
|
114
|
+
/** Over the rows with a stated volume; `null` when no row has one. */
|
|
115
|
+
totals: { baseUsd: number; headUsd: number; changeUsd: number } | null;
|
|
116
|
+
/** Changed rows with no stated volume, priced per call only. */
|
|
117
|
+
perCallOnly: number;
|
|
118
|
+
gate: BaseCostGate | null;
|
|
119
|
+
}
|
|
120
|
+
| {
|
|
121
|
+
status: 'unavailable';
|
|
122
|
+
ref: string;
|
|
123
|
+
/** No git, not a repository, or a commit this checkout does not have. */
|
|
124
|
+
why: 'no-git' | 'not-a-repository' | 'no-commit';
|
|
125
|
+
/** A gate that was asked for and could not judge anything. */
|
|
126
|
+
gate: { maxIncreaseUsd: number } | null;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/** Whether a gate asked for in this report fails the run. */
|
|
130
|
+
export function baseGateFails(report: BaseCostReport): boolean {
|
|
131
|
+
if (report.gate === null) return false;
|
|
132
|
+
// A gate that could not read the base is not a pass: it judged nothing.
|
|
133
|
+
if (report.status === 'unavailable') return true;
|
|
134
|
+
return report.gate.breached;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** The prompts one file holds: itself, or each one marked inside it. */
|
|
138
|
+
function promptsIn(file: string, text: string): { id: string; text: string; embedded: boolean }[] {
|
|
139
|
+
const isSource = SOURCE_EXTENSIONS.some((ext) => file.toLowerCase().endsWith(ext));
|
|
140
|
+
if (!isSource) return [{ id: file, text, embedded: false }];
|
|
141
|
+
if (!hasMarker(text)) return [];
|
|
142
|
+
return extractPrompts(text).prompts.map((prompt) => ({
|
|
143
|
+
id: promptId(file, prompt),
|
|
144
|
+
text: prompt.text,
|
|
145
|
+
embedded: true,
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const toPosix = (path: string): string => path.split(sep).join('/');
|
|
150
|
+
|
|
151
|
+
/** `a/b` joined for display, the way `check` keys a path under its root. */
|
|
152
|
+
function joinShown(root: string, rel: string): string {
|
|
153
|
+
const trimmed = root.replace(/[\\/]+$/, '').replace(/\\/g, '/');
|
|
154
|
+
if (trimmed === '' || trimmed === '.') return rel;
|
|
155
|
+
return `${trimmed}/${rel}`;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Reads both sides of every prompt under `target`.
|
|
160
|
+
*
|
|
161
|
+
* The head is the disk, walked the way `check` walks it. The base is the
|
|
162
|
+
* commit, listed with `git ls-tree` and read with `git show`, and kept to
|
|
163
|
+
* the files the walk would have kept (`walkIncludes`), so a file the walk
|
|
164
|
+
* skips is not reported as deleted. `listed` is `--files-from`'s list, which
|
|
165
|
+
* replaces the walk on both sides.
|
|
166
|
+
*/
|
|
167
|
+
export async function readBothSides(options: {
|
|
168
|
+
ref: string;
|
|
169
|
+
target: string;
|
|
170
|
+
kind: 'file' | 'directory' | 'list';
|
|
171
|
+
listed?: readonly string[];
|
|
172
|
+
extensions: readonly string[];
|
|
173
|
+
ignore: readonly string[];
|
|
174
|
+
cwd?: string;
|
|
175
|
+
readHead?: (path: string) => Promise<string>;
|
|
176
|
+
}): Promise<{ status: 'read'; sha: string; pairs: PromptPair[] } | { status: 'unavailable'; why: 'no-git' | 'not-a-repository' | 'no-commit' }> {
|
|
177
|
+
const cwd = options.cwd ?? process.cwd();
|
|
178
|
+
const readHead = options.readHead ?? ((path: string) => readFile(resolve(cwd, path), 'utf8'));
|
|
179
|
+
|
|
180
|
+
if (!gitAvailable(cwd)) return { status: 'unavailable', why: 'no-git' };
|
|
181
|
+
const root = repositoryRoot(cwd);
|
|
182
|
+
if (root === null) return { status: 'unavailable', why: 'not-a-repository' };
|
|
183
|
+
let sha: string | null;
|
|
184
|
+
try {
|
|
185
|
+
sha = commitOf(options.ref, root);
|
|
186
|
+
} catch {
|
|
187
|
+
return { status: 'unavailable', why: 'no-git' };
|
|
188
|
+
}
|
|
189
|
+
if (sha === null) return { status: 'unavailable', why: 'no-commit' };
|
|
190
|
+
|
|
191
|
+
/** A path as the report shows it, relative to the working directory, to its repository path. */
|
|
192
|
+
const repoPathOf = (shown: string): string | null => {
|
|
193
|
+
const absolute = resolve(cwd, shown);
|
|
194
|
+
if (absolute === resolve(root)) return '';
|
|
195
|
+
return pathInRepository(root, absolute);
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
// Every file to look at, as the report shows it, mapped to its path in the repository.
|
|
199
|
+
const files = new Map<string, string>();
|
|
200
|
+
const walkOptions = { extensions: options.extensions, ignore: options.ignore };
|
|
201
|
+
|
|
202
|
+
if (options.kind === 'file') {
|
|
203
|
+
const repoPath = repoPathOf(options.target);
|
|
204
|
+
if (repoPath !== null && repoPath !== '') files.set(toPosix(options.target), repoPath);
|
|
205
|
+
} else if (options.kind === 'list') {
|
|
206
|
+
// The list's own rule, as `check --files-from` applies it: a prompt
|
|
207
|
+
// extension and no ignore pattern. Kept whether or not the file is still
|
|
208
|
+
// on disk, because a deletion is half of what a base comparison is for.
|
|
209
|
+
const extensions = options.extensions.map((ext) => ext.toLowerCase());
|
|
210
|
+
for (const raw of options.listed ?? []) {
|
|
211
|
+
const rel = raw.replace(/^\.\//, '');
|
|
212
|
+
if (!extensions.some((ext) => rel.toLowerCase().endsWith(ext))) continue;
|
|
213
|
+
if (options.ignore.some((pattern) => matchGlob(pattern, rel) || matchGlob(pattern, `${rel}/`))) continue;
|
|
214
|
+
const repoPath = repoPathOf(rel);
|
|
215
|
+
if (repoPath !== null && repoPath !== '') files.set(rel, repoPath);
|
|
216
|
+
}
|
|
217
|
+
} else {
|
|
218
|
+
const walked = await walkPrompts(resolve(cwd, options.target), walkOptions);
|
|
219
|
+
for (const rel of walked.files) {
|
|
220
|
+
const shown = joinShown(options.target, rel);
|
|
221
|
+
const repoPath = repoPathOf(shown);
|
|
222
|
+
if (repoPath !== null) files.set(shown, repoPath);
|
|
223
|
+
}
|
|
224
|
+
const rootPath = repoPathOf(options.target);
|
|
225
|
+
if (rootPath !== null) {
|
|
226
|
+
for (const repoPath of filesAt(sha, rootPath, root) ?? []) {
|
|
227
|
+
const rel = rootPath === '' ? repoPath : repoPath.slice(rootPath.length + 1);
|
|
228
|
+
if (!walkIncludes(rel, walkOptions)) continue;
|
|
229
|
+
const shown = joinShown(options.target, rel);
|
|
230
|
+
if (!files.has(shown)) files.set(shown, repoPath);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const pairs = new Map<string, PromptPair>();
|
|
236
|
+
for (const [shown, repoPath] of [...files.entries()].sort((a, b) => a[0].localeCompare(b[0]))) {
|
|
237
|
+
// The base is read from the commit, and only from the commit.
|
|
238
|
+
const atBase = (filesAt(sha, repoPath, root) ?? []).includes(repoPath) ? contentAt(sha, repoPath, root) : null;
|
|
239
|
+
const atHead = await readHead(shown).catch(() => null);
|
|
240
|
+
for (const prompt of atBase === null ? [] : promptsIn(shown, atBase)) {
|
|
241
|
+
pairs.set(prompt.id, { id: prompt.id, file: shown, embedded: prompt.embedded, base: prompt.text, head: null });
|
|
242
|
+
}
|
|
243
|
+
for (const prompt of atHead === null ? [] : promptsIn(shown, atHead)) {
|
|
244
|
+
const existing = pairs.get(prompt.id);
|
|
245
|
+
if (existing !== undefined) existing.head = prompt.text;
|
|
246
|
+
else pairs.set(prompt.id, { id: prompt.id, file: shown, embedded: prompt.embedded, base: null, head: prompt.text });
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return { status: 'read', sha, pairs: [...pairs.values()] };
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* The calls a month stated for a prompt file, from `volumes` through `labels`.
|
|
254
|
+
*
|
|
255
|
+
* Every label mapping to the file is a workload sending it, so their
|
|
256
|
+
* volumes add. When one of them states none, the month is not known and
|
|
257
|
+
* the answer is `null`: a sum missing a workload would be an understated
|
|
258
|
+
* month printed as a whole one. A prompt marked inside a source file gets
|
|
259
|
+
* none, because a label maps a file and a file holding several prompts
|
|
260
|
+
* does not say how often each is sent.
|
|
261
|
+
*/
|
|
262
|
+
export function volumeFor(
|
|
263
|
+
pair: Pick<PromptPair, 'file' | 'embedded'>,
|
|
264
|
+
labels: Readonly<Record<string, string>>,
|
|
265
|
+
volumes: Readonly<Record<string, number>>,
|
|
266
|
+
cwd: string = process.cwd(),
|
|
267
|
+
): { calls: number; labels: string[] } | null {
|
|
268
|
+
if (pair.embedded) return null;
|
|
269
|
+
const target = resolve(cwd, pair.file);
|
|
270
|
+
const sending = Object.keys(labels)
|
|
271
|
+
.filter((label) => resolve(cwd, labels[label]!) === target)
|
|
272
|
+
.sort();
|
|
273
|
+
if (sending.length === 0) return null;
|
|
274
|
+
let calls = 0;
|
|
275
|
+
for (const label of sending) {
|
|
276
|
+
const stated = volumes[label];
|
|
277
|
+
if (stated === undefined) return null;
|
|
278
|
+
calls += stated;
|
|
279
|
+
}
|
|
280
|
+
return { calls, labels: sending };
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Prices every changed prompt on both sides, at one model and one price list.
|
|
285
|
+
*
|
|
286
|
+
* Both sides are priced at today's prices, from the same catalogue, so a
|
|
287
|
+
* provider repricing between the base and the head cannot appear as a
|
|
288
|
+
* change the pull request made.
|
|
289
|
+
*/
|
|
290
|
+
export async function priceAgainstBase(input: {
|
|
291
|
+
ref: string;
|
|
292
|
+
sha: string;
|
|
293
|
+
pairs: readonly PromptPair[];
|
|
294
|
+
count: (text: string) => Promise<number>;
|
|
295
|
+
model: ModelPricing;
|
|
296
|
+
modelFrom: 'config' | 'default';
|
|
297
|
+
pricing: PricingCatalogue;
|
|
298
|
+
volumeOf: (pair: PromptPair) => { calls: number; labels: string[] } | null;
|
|
299
|
+
maxIncreaseUsd: number | null;
|
|
300
|
+
on?: Date;
|
|
301
|
+
}): Promise<BaseCostReport> {
|
|
302
|
+
const on = input.on ?? new Date();
|
|
303
|
+
const model = input.model;
|
|
304
|
+
let promoApplied = false;
|
|
305
|
+
|
|
306
|
+
const side = async (text: string | null, calls: number | null): Promise<PricedSide | null> => {
|
|
307
|
+
if (text === null) return null;
|
|
308
|
+
const tokens = await input.count(text);
|
|
309
|
+
const rates = effectivePricing(model, on, { inputTokens: tokens });
|
|
310
|
+
promoApplied ||= rates.promoApplied;
|
|
311
|
+
const perCallUsd = (tokens * rates.inputPerMTok) / 1_000_000;
|
|
312
|
+
return {
|
|
313
|
+
tokens,
|
|
314
|
+
inputPerMTok: rates.inputPerMTok,
|
|
315
|
+
perCallUsd,
|
|
316
|
+
monthlyUsd: calls === null ? null : perCallUsd * calls,
|
|
317
|
+
};
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
const rows: BaseCostRow[] = [];
|
|
321
|
+
let unchanged = 0;
|
|
322
|
+
for (const pair of [...input.pairs].sort((a, b) => a.id.localeCompare(b.id))) {
|
|
323
|
+
if (pair.base === pair.head) {
|
|
324
|
+
if (pair.base !== null) unchanged++;
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
const volume = input.volumeOf(pair);
|
|
328
|
+
const calls = volume === null ? null : volume.calls;
|
|
329
|
+
const base = await side(pair.base, calls);
|
|
330
|
+
const head = await side(pair.head, calls);
|
|
331
|
+
const perCallChangeUsd = (head?.perCallUsd ?? 0) - (base?.perCallUsd ?? 0);
|
|
332
|
+
rows.push({
|
|
333
|
+
id: pair.id,
|
|
334
|
+
base,
|
|
335
|
+
head,
|
|
336
|
+
callsPerMonth: calls,
|
|
337
|
+
labels: volume?.labels ?? [],
|
|
338
|
+
perCallChangeUsd,
|
|
339
|
+
monthlyChangeUsd: calls === null ? null : perCallChangeUsd * calls,
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
const monthly = rows.filter((row) => row.callsPerMonth !== null);
|
|
344
|
+
const totals =
|
|
345
|
+
monthly.length === 0
|
|
346
|
+
? null
|
|
347
|
+
: {
|
|
348
|
+
baseUsd: monthly.reduce((sum, row) => sum + (row.base?.monthlyUsd ?? 0), 0),
|
|
349
|
+
headUsd: monthly.reduce((sum, row) => sum + (row.head?.monthlyUsd ?? 0), 0),
|
|
350
|
+
changeUsd: monthly.reduce((sum, row) => sum + (row.monthlyChangeUsd ?? 0), 0),
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
const overlaid =
|
|
354
|
+
input.pricing.lastReviewed !== PRICING_LAST_REVIEWED ||
|
|
355
|
+
input.pricing.overriddenModels.includes(model.id) ||
|
|
356
|
+
input.pricing.addedModels.includes(model.id);
|
|
357
|
+
|
|
358
|
+
return {
|
|
359
|
+
status: 'compared',
|
|
360
|
+
ref: input.ref,
|
|
361
|
+
sha: input.sha,
|
|
362
|
+
price: {
|
|
363
|
+
model: model.id,
|
|
364
|
+
displayName: model.displayName,
|
|
365
|
+
provider: model.provider ?? null,
|
|
366
|
+
overlaid,
|
|
367
|
+
readOn: reviewedForModels([model.id], input.pricing),
|
|
368
|
+
promoUntil: promoApplied ? (model.promo?.until ?? null) : null,
|
|
369
|
+
},
|
|
370
|
+
modelFrom: input.modelFrom,
|
|
371
|
+
rows,
|
|
372
|
+
unchanged,
|
|
373
|
+
totals,
|
|
374
|
+
perCallOnly: rows.length - monthly.length,
|
|
375
|
+
gate:
|
|
376
|
+
input.maxIncreaseUsd === null
|
|
377
|
+
? null
|
|
378
|
+
: {
|
|
379
|
+
maxIncreaseUsd: input.maxIncreaseUsd,
|
|
380
|
+
// A floating-point hair over the limit is not over it.
|
|
381
|
+
breached: (totals?.changeUsd ?? 0) - input.maxIncreaseUsd > 1e-9,
|
|
382
|
+
},
|
|
383
|
+
};
|
|
384
|
+
}
|