werkmeister-core 0.93.2 → 0.93.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/CHANGELOG.md +7 -0
- package/dist/harness/claude/usage.js +21 -4
- package/dist/scaffold.d.ts +1 -1
- package/dist/scaffold.js +11 -6
- package/dist/usage_snapshot.d.ts +5 -1
- package/dist/usage_snapshot.js +22 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# sandbox-core
|
|
2
2
|
|
|
3
|
+
## 0.93.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c9fb647: SW-773: usage costs price the current models (Claude Opus 5.5, Sonnet 5.5, Haiku 5.5, Fable 5.2), so `usage.json` and the `workspace-usage` tool no longer show a null cost for every run. `~/.werkmeister/model-pricing.yaml` now overrides the built-in rates instead of replacing them, so a file seeded before a model shipped still prices it with no edit. A model with no rate is reported once instead of silently. The built-in and newly seeded rates for Claude Opus 4.8 and Sonnet 5 move to their published prices ($5/$25 and $2/$10). An existing `model-pricing.yaml` keeps its own older rows for those two models (15/75 and 3/15), and those still win. Delete those rows, or the whole file, to use the new rates.
|
|
8
|
+
- 058117c: SW-774: close-out's `usage.json` and `usage.md` no longer show negative stage minutes. A stage now ends at the earlier of the record-branch commit that first added a file to its `output/` (`.gitkeep` excluded) and its oldest output file, so stages committed together keep their own times. Before, it ended at its newest output file, so a later edit to an earlier stage made the next stage's duration negative.
|
|
9
|
+
|
|
3
10
|
## 0.93.2
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
|
@@ -6,6 +6,7 @@ import fs from "node:fs/promises";
|
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { parse as parseYaml } from "yaml";
|
|
8
8
|
import { modelPricingYamlPath } from "../../config.js";
|
|
9
|
+
import { warn } from "../../reporter.js";
|
|
9
10
|
import { isFile } from "../../tool_bins.js";
|
|
10
11
|
import { findClaudeProjectDir, listSessionFiles, readSessionTitle } from "./transcript.js";
|
|
11
12
|
const zeroTotals = () => ({ input: 0, output: 0, cacheCreation: 0, cacheRead: 0 });
|
|
@@ -87,10 +88,15 @@ export function rateFor(prices, model) {
|
|
|
87
88
|
const base = model.replace(DATED_MODEL_ID_RE, "");
|
|
88
89
|
return base !== model ? prices[base] : undefined;
|
|
89
90
|
}
|
|
90
|
-
//
|
|
91
|
+
// Under ~/.werkmeister/model-pricing.yaml: a file seeded before a model shipped still prices it (SW-773).
|
|
91
92
|
const DEFAULT_PRICES = {
|
|
92
|
-
"claude-
|
|
93
|
-
"claude-
|
|
93
|
+
"claude-fable-5-2": { input: 8, output: 40, cacheWrite: 10, cacheRead: 0.2 },
|
|
94
|
+
"claude-opus-5-5": { input: 4, output: 20, cacheWrite: 5, cacheRead: 0.2 },
|
|
95
|
+
"claude-opus-4-8": { input: 5, output: 25, cacheWrite: 6.25, cacheRead: 0.5 },
|
|
96
|
+
"claude-sonnet-5-5": { input: 2, output: 10, cacheWrite: 2.5, cacheRead: 0.1 },
|
|
97
|
+
"claude-sonnet-5": { input: 2, output: 10, cacheWrite: 2.5, cacheRead: 0.2 },
|
|
98
|
+
// shortcut: ≤100K-token prompt tier only (over 100K costs 5×); add tiers if Haiku runs main sessions.
|
|
99
|
+
"claude-haiku-5-5": { input: 0.1, output: 0.5, cacheWrite: 0.125, cacheRead: 0.01 },
|
|
94
100
|
"claude-haiku-4-5": { input: 1, output: 5, cacheWrite: 1.25, cacheRead: 0.1 },
|
|
95
101
|
};
|
|
96
102
|
/** Locate `~/.werkmeister/model-pricing.yaml`, mirroring resolveServicesYaml. */
|
|
@@ -104,7 +110,7 @@ export async function loadPriceTable() {
|
|
|
104
110
|
return DEFAULT_PRICES;
|
|
105
111
|
try {
|
|
106
112
|
const doc = parseYaml(await fs.readFile(p, "utf-8"));
|
|
107
|
-
return
|
|
113
|
+
return { ...DEFAULT_PRICES, ...doc?.models };
|
|
108
114
|
}
|
|
109
115
|
catch {
|
|
110
116
|
return DEFAULT_PRICES;
|
|
@@ -138,9 +144,20 @@ export async function usageForDir(name, target) {
|
|
|
138
144
|
}
|
|
139
145
|
return rollUpUsage(name, sessions);
|
|
140
146
|
}
|
|
147
|
+
const warnedUnpriced = new Set();
|
|
141
148
|
/** A workspace's sessions summed by model and by session, priced from the price table. */
|
|
142
149
|
export async function rollUpUsage(name, tallies) {
|
|
143
150
|
const prices = await loadPriceTable();
|
|
151
|
+
// An unpriced model left every cost null unnoticed for weeks (SW-773). Zero-token
|
|
152
|
+
// rows (Claude Code's `<synthetic>` error turns) cost nothing, so they don't warn.
|
|
153
|
+
for (const [model, t] of tallies.flatMap((s) => [...s.reduction.byModel])) {
|
|
154
|
+
if (!(t.input + t.output + t.cacheCreation + t.cacheRead))
|
|
155
|
+
continue;
|
|
156
|
+
if (rateFor(prices, model) || warnedUnpriced.has(model))
|
|
157
|
+
continue;
|
|
158
|
+
warnedUnpriced.add(model);
|
|
159
|
+
warn(`No price for model ${model}: its cost is unknown. Add it to ${modelPricingYamlPath()}.`);
|
|
160
|
+
}
|
|
144
161
|
const wsByModel = new Map();
|
|
145
162
|
const sessions = [];
|
|
146
163
|
for (const { sessionId, title, updatedAt, reduction: session } of tallies) {
|
package/dist/scaffold.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export interface SeedResult {
|
|
|
20
20
|
status: "created" | "present";
|
|
21
21
|
}
|
|
22
22
|
export declare const DEFAULT_PORTS_YAML = "# Port Allocation Scheme\n# Each feature slot (1-12) gets a dedicated port range.\n#\n# k8s port-forward listen-ports (the 9000-range) are NOT defined here \u2014 they\n# live per-service in services.yaml as `k8s_forward_port:` (single source of\n# truth for the forward table).\n\nfeature_slots:\n count: 12\n base_port: 11100\n ports_per_slot: 20\n # Slot 1: 11100-11119\n # Slot 2: 11200-11219\n # ...\n # Slot 12: 12200-12219\n";
|
|
23
|
-
export declare const DEFAULT_MODEL_PRICING_YAML = "# Per-million-token USD rates for estimating Claude Code usage cost.\n# Add or reprice models here \u2014 no code change needed.
|
|
23
|
+
export declare const DEFAULT_MODEL_PRICING_YAML = "# Per-million-token USD rates for estimating Claude Code usage cost.\n# Add or reprice models here \u2014 no code change needed. A rate here overrides\n# werkmeister's built-in one; a model missing here falls back to the built-in\n# rate. Unknown models show token counts with no dollar estimate and a warning.\n# Rates are approximate; update when published pricing changes.\nmodels:\n claude-fable-5-2: { input: 8, output: 40, cacheWrite: 10, cacheRead: 0.20 }\n claude-opus-5-5: { input: 4, output: 20, cacheWrite: 5, cacheRead: 0.20 }\n claude-opus-4-8: { input: 5, output: 25, cacheWrite: 6.25, cacheRead: 0.50 }\n claude-sonnet-5-5: { input: 2, output: 10, cacheWrite: 2.50, cacheRead: 0.10 }\n claude-sonnet-5: { input: 2, output: 10, cacheWrite: 2.50, cacheRead: 0.20 }\n claude-haiku-5-5: { input: 0.10, output: 0.50, cacheWrite: 0.125, cacheRead: 0.01 } # \u2264100K-token prompts\n claude-haiku-4-5: { input: 1, output: 5, cacheWrite: 1.25, cacheRead: 0.10 }\n";
|
|
24
24
|
/**
|
|
25
25
|
* Render the starter secrets.env template.
|
|
26
26
|
*
|
package/dist/scaffold.js
CHANGED
|
@@ -38,13 +38,18 @@ feature_slots:
|
|
|
38
38
|
// model-pricing.yaml
|
|
39
39
|
// ---------------------------------------------------------------------------
|
|
40
40
|
export const DEFAULT_MODEL_PRICING_YAML = `# Per-million-token USD rates for estimating Claude Code usage cost.
|
|
41
|
-
# Add or reprice models here — no code change needed.
|
|
42
|
-
#
|
|
43
|
-
#
|
|
41
|
+
# Add or reprice models here — no code change needed. A rate here overrides
|
|
42
|
+
# werkmeister's built-in one; a model missing here falls back to the built-in
|
|
43
|
+
# rate. Unknown models show token counts with no dollar estimate and a warning.
|
|
44
|
+
# Rates are approximate; update when published pricing changes.
|
|
44
45
|
models:
|
|
45
|
-
claude-
|
|
46
|
-
claude-
|
|
47
|
-
claude-
|
|
46
|
+
claude-fable-5-2: { input: 8, output: 40, cacheWrite: 10, cacheRead: 0.20 }
|
|
47
|
+
claude-opus-5-5: { input: 4, output: 20, cacheWrite: 5, cacheRead: 0.20 }
|
|
48
|
+
claude-opus-4-8: { input: 5, output: 25, cacheWrite: 6.25, cacheRead: 0.50 }
|
|
49
|
+
claude-sonnet-5-5: { input: 2, output: 10, cacheWrite: 2.50, cacheRead: 0.10 }
|
|
50
|
+
claude-sonnet-5: { input: 2, output: 10, cacheWrite: 2.50, cacheRead: 0.20 }
|
|
51
|
+
claude-haiku-5-5: { input: 0.10, output: 0.50, cacheWrite: 0.125, cacheRead: 0.01 } # ≤100K-token prompts
|
|
52
|
+
claude-haiku-4-5: { input: 1, output: 5, cacheWrite: 1.25, cacheRead: 0.10 }
|
|
48
53
|
`;
|
|
49
54
|
// ---------------------------------------------------------------------------
|
|
50
55
|
// secrets.env
|
package/dist/usage_snapshot.d.ts
CHANGED
|
@@ -29,7 +29,11 @@ export interface UsageSnapshot {
|
|
|
29
29
|
}
|
|
30
30
|
export declare function formatTokens(n: number): string;
|
|
31
31
|
export declare function usageSummary(s: UsageSnapshot): string;
|
|
32
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Each `stages/NN_*` finished at the earlier of its first output commit on the record branch and
|
|
34
|
+
* its oldest output file's mtime. Never the newest: re-editing an earlier stage's file later made
|
|
35
|
+
* the next stage's minutes negative (SW-774).
|
|
36
|
+
*/
|
|
33
37
|
export declare function stageTimings(ws: string, firstTurn: string | null): StageTiming[];
|
|
34
38
|
export declare function buildUsageSnapshot(ws: string, name: string, cfg: Record<string, unknown>, outcome: UsageSnapshot["outcome"], closedAt?: string): Promise<UsageSnapshot>;
|
|
35
39
|
export declare function renderUsageMd(s: UsageSnapshot): string;
|
package/dist/usage_snapshot.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* `usage.md` for people. The transcripts it reads are keyed by the workspace path, so once the
|
|
4
4
|
* folder is removed these files are the only record of what the run cost.
|
|
5
5
|
*/
|
|
6
|
+
import { spawnSync } from "node:child_process";
|
|
6
7
|
import * as fs from "node:fs";
|
|
7
8
|
import * as path from "node:path";
|
|
8
9
|
import { sandboxRoot } from "./config.js";
|
|
@@ -32,7 +33,11 @@ export function usageSummary(s) {
|
|
|
32
33
|
const cost = s.estUsd == null ? "cost unknown" : `~${usd(s.estUsd)}`;
|
|
33
34
|
return `Usage: ${formatTokens(tokensOf(s.totals))} tokens, ${cost} across ${s.sessionCount} session${s.sessionCount === 1 ? "" : "s"}`;
|
|
34
35
|
}
|
|
35
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* Each `stages/NN_*` finished at the earlier of its first output commit on the record branch and
|
|
38
|
+
* its oldest output file's mtime. Never the newest: re-editing an earlier stage's file later made
|
|
39
|
+
* the next stage's minutes negative (SW-774).
|
|
40
|
+
*/
|
|
36
41
|
export function stageTimings(ws, firstTurn) {
|
|
37
42
|
const root = path.join(ws, "stages");
|
|
38
43
|
let dirs;
|
|
@@ -46,8 +51,8 @@ export function stageTimings(ws, firstTurn) {
|
|
|
46
51
|
catch {
|
|
47
52
|
return [];
|
|
48
53
|
}
|
|
49
|
-
const
|
|
50
|
-
let
|
|
54
|
+
const oldest = (dir) => {
|
|
55
|
+
let min = 0;
|
|
51
56
|
let entries;
|
|
52
57
|
try {
|
|
53
58
|
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
@@ -57,16 +62,23 @@ export function stageTimings(ws, firstTurn) {
|
|
|
57
62
|
}
|
|
58
63
|
for (const e of entries) {
|
|
59
64
|
const p = path.join(dir, e.name);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
max = Math.max(max, fs.statSync(p).mtimeMs);
|
|
65
|
+
const t = e.isDirectory() ? oldest(p) : e.name === ".gitkeep" ? 0 : fs.statSync(p).mtimeMs;
|
|
66
|
+
if (t && (!min || t < min))
|
|
67
|
+
min = t;
|
|
64
68
|
}
|
|
65
|
-
return
|
|
69
|
+
return min;
|
|
70
|
+
};
|
|
71
|
+
const firstCommitted = (stage) => {
|
|
72
|
+
const out = `stages/${stage}/output`;
|
|
73
|
+
const r = spawnSync("git", ["-C", ws, "log", "--diff-filter=A", "--format=%cI", "--", out, `:!${out}/.gitkeep`], { encoding: "utf8" });
|
|
74
|
+
const first = r.status === 0 ? r.stdout.trim().split("\n").pop() : ""; // newest first
|
|
75
|
+
return first ? Date.parse(first) : 0;
|
|
66
76
|
};
|
|
67
77
|
let prev = firstTurn;
|
|
68
78
|
return dirs.map((stage) => {
|
|
69
|
-
|
|
79
|
+
// The earlier of the two: a commit can bundle several stages, and a checkout resets mtimes.
|
|
80
|
+
const times = [firstCommitted(stage), oldest(path.join(root, stage, "output"))].filter(Boolean);
|
|
81
|
+
const ms = times.length ? Math.min(...times) : 0;
|
|
70
82
|
const finishedAt = ms ? new Date(ms).toISOString() : null;
|
|
71
83
|
const minutes = finishedAt ? minutesBetween(prev, finishedAt) : null;
|
|
72
84
|
if (finishedAt)
|
|
@@ -173,7 +185,7 @@ export function renderUsageMd(s) {
|
|
|
173
185
|
"",
|
|
174
186
|
...table("| session | title | first turn | last turn | turns | tokens | model(s) | est. USD |\n|---|---|---|---|---|---|---|---|", s.sessions.map((x) => `| ${x.sessionId} | ${cell(x.title)} | ${cell(x.firstTurn)} | ${cell(x.lastTurn)} | ${x.turns} | ${formatTokens(tokensOf(x.totals))} | ${cell(x.models.join(", "))} | ${usd(x.estUsd)} |`)),
|
|
175
187
|
"",
|
|
176
|
-
"## Stages (
|
|
188
|
+
"## Stages (from each stage's first output commit or oldest output file, whichever is earlier)",
|
|
177
189
|
"",
|
|
178
190
|
...table("| stage | finished | minutes |\n|---|---|---|", s.stages.map((t) => `| ${t.stage} | ${t.finishedAt ?? "not reached"} | ${cell(t.minutes)} |`)),
|
|
179
191
|
"",
|
package/package.json
CHANGED