context-doctor 0.50.0 → 0.52.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/README.md +36 -38
- package/dist/apptools.d.ts +89 -0
- package/dist/apptools.js +203 -0
- package/dist/appwindow.d.ts +6 -0
- package/dist/appwindow.js +15 -1
- package/dist/budget.d.ts +20 -2
- package/dist/budget.js +43 -3
- package/dist/cachemisses.d.ts +70 -0
- package/dist/cachemisses.js +126 -0
- package/dist/cli.js +39 -10
- package/dist/credits.d.ts +64 -2
- package/dist/credits.js +88 -3
- package/dist/doctor.d.ts +18 -6
- package/dist/doctor.js +82 -14
- package/dist/fileparams.js +15 -3
- package/dist/fix.d.ts +11 -2
- package/dist/fix.js +53 -18
- package/dist/limits.d.ts +44 -3
- package/dist/limits.js +210 -22
- package/dist/mcp.js +68 -68
- package/dist/mod/api.d.ts +1 -1
- package/dist/mod/logic.d.ts +46 -1
- package/dist/mod/logic.js +76 -4
- package/dist/mod/register.d.ts +13 -3
- package/dist/mod/register.js +39 -9
- package/dist/modelids.d.ts +15 -0
- package/dist/modelids.js +33 -0
- package/dist/modmeasure.d.ts +7 -0
- package/dist/modmeasure.js +9 -0
- package/dist/overhead.js +8 -2
- package/dist/progresssummaries.d.ts +85 -2
- package/dist/progresssummaries.js +169 -23
- package/dist/proxy.d.ts +1 -1
- package/dist/proxy.js +1 -1
- package/dist/sample.d.ts +8 -0
- package/dist/sample.js +86 -0
- package/dist/savings.d.ts +8 -1
- package/dist/savings.js +32 -7
- package/dist/spend.d.ts +4 -2
- package/dist/spend.js +33 -4
- package/dist/starts.d.ts +7 -0
- package/dist/starts.js +7 -3
- package/dist/usagepane.js +1 -1
- package/package.json +1 -1
|
@@ -47,6 +47,30 @@
|
|
|
47
47
|
* subagent whose transcript says `version` 2.1.328 or later is priced once,
|
|
48
48
|
* at Haiku 5.5's rates (low and high the same); an older one as before.
|
|
49
49
|
*
|
|
50
|
+
* Read again from the 2.1.330 binary: that is a terminal session on the
|
|
51
|
+
* Anthropic API's only. Per subagent, Claude Code reads its provider (from
|
|
52
|
+
* CLAUDE_CODE_USE_*: the Claude Code gateway, Bedrock, Foundry, Anthropic on
|
|
53
|
+
* AWS or Google Cloud, Mantle, Vertex, else the Anthropic API):
|
|
54
|
+
* - Bedrock, Vertex, Foundry or the gateway (CLAUDE_CODE_USE_GATEWAY): the
|
|
55
|
+
* notes, written by the subagent's OWN model ("release" mode).
|
|
56
|
+
* - Any other: a served flag (notes unless it says otherwise), and the
|
|
57
|
+
* writer is the small fast model only when ANTHROPIC_SMALL_FAST_MODEL and
|
|
58
|
+
* ANTHROPIC_DEFAULT_HAIKU_MODEL are both unset, the provider is the
|
|
59
|
+
* Anthropic API, and the API counts as Anthropic's: ANTHROPIC_BASE_URL
|
|
60
|
+
* unset or api.anthropic.com (or _CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URL),
|
|
61
|
+
* or the key is an Anthropic API key (sk-ant-api..., not
|
|
62
|
+
* ANTHROPIC_AUTH_TOKEN, a claude.ai sign-in or /login's managed key).
|
|
63
|
+
* With no writer, the summary is the whole context on the agent's own
|
|
64
|
+
* model, the pre-2.1.328 form. A plain ANTHROPIC_BASE_URL is not the
|
|
65
|
+
* "gateway": a proxy on 127.0.0.1 (context-doctor's autopilot) leaves the
|
|
66
|
+
* provider the Anthropic API and fails the base-URL test, so on a Claude
|
|
67
|
+
* sign-in it gets the whole context.
|
|
68
|
+
* Which applied is told from the transcript where it can be (Bedrock and
|
|
69
|
+
* Vertex model and message ids), else from the settings and environment
|
|
70
|
+
* now (summaryRoute), autopilot's proxy counted from when autopilot was
|
|
71
|
+
* turned on. Where neither tells (an API key that may or may not be used
|
|
72
|
+
* behind a proxy), a range: Haiku notes low, the whole context high.
|
|
73
|
+
*
|
|
50
74
|
* Estimated per subagent from what its transcript does record: the time of
|
|
51
75
|
* each message (the ticks and whether the transcript changed), each reply's
|
|
52
76
|
* prompt size and model (the context a fork would read, the rates). Each
|
|
@@ -54,8 +78,11 @@
|
|
|
54
78
|
* tick held while the agent's own request waits on a cold cache (it fires
|
|
55
79
|
* later, not more often), and the thinking a summary may do.
|
|
56
80
|
*/
|
|
57
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
81
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
82
|
+
import { join } from "node:path";
|
|
58
83
|
import { pick, rowsOf } from "./scan.js";
|
|
84
|
+
import { claudeDir } from "./claudedir.js";
|
|
85
|
+
import { effectiveEnv, settingsSources } from "./effective.js";
|
|
59
86
|
import { requestCost } from "./pricing.js";
|
|
60
87
|
import { realModel } from "./tokens.js";
|
|
61
88
|
import { workflowRunOf } from "./subagents.js";
|
|
@@ -78,6 +105,92 @@ export const SMALL_FAST_MODEL_NAME = "Haiku 5.5";
|
|
|
78
105
|
export const FORK_PROMPT_TOKENS = 150;
|
|
79
106
|
/** Each summary's output: #86879's measured mean (21,966 tokens over 339 summaries). */
|
|
80
107
|
export const SUMMARY_OUTPUT_TOKENS = 65;
|
|
108
|
+
/** Nothing set: the Anthropic API, notes by Haiku. */
|
|
109
|
+
export const ANTHROPIC_API_ROUTE = { form: "haiku", why: "Claude Code on the Anthropic API" };
|
|
110
|
+
/** The cloud a reply's ids name: Bedrock's (`anthropic.`, region-prefixed, an ARN; `msg_bdrk_`), Vertex's (`@date`; `msg_vrtx_`). */
|
|
111
|
+
export function replyCloud(model, id) {
|
|
112
|
+
const m = typeof model === "string" ? model : "";
|
|
113
|
+
const i = typeof id === "string" ? id : "";
|
|
114
|
+
if (/^(?:[a-z]{2,7}\.)?anthropic\.claude-[\w.-]*\d|^arn:aws[\w-]*:bedrock:/.test(m) || i.startsWith("msg_bdrk_"))
|
|
115
|
+
return "bedrock";
|
|
116
|
+
if (/^claude-[\w.-]+@/.test(m) || i.startsWith("msg_vrtx_"))
|
|
117
|
+
return "vertex";
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
const on = (v) => v !== undefined && !["", "0", "false", "no", "off"].includes(v.trim().toLowerCase());
|
|
121
|
+
/** Autopilot's own file and address (autopilot.ts autopilotPaths, proxyUrl), read here without its imports. */
|
|
122
|
+
const AUTOPILOT_CONFIG = ".context-doctor-autopilot.json";
|
|
123
|
+
/**
|
|
124
|
+
* Which form Claude Code 2.1.330 uses for a terminal subagent on a
|
|
125
|
+
* first-party model id, from the settings and environment as they are now
|
|
126
|
+
* (read only). Autopilot's proxy counts from when autopilot was turned on
|
|
127
|
+
* (its config file, written then); before it, the address it replaced.
|
|
128
|
+
*/
|
|
129
|
+
export function summaryRoute(deps = {}) {
|
|
130
|
+
const env = deps.env ?? process.env;
|
|
131
|
+
const sources = deps.sources ?? settingsSources({ home: deps.home, cwd: deps.cwd, env });
|
|
132
|
+
const get = (n) => effectiveEnv(n, sources, env);
|
|
133
|
+
const provider = [
|
|
134
|
+
["CLAUDE_CODE_USE_GATEWAY", "own-notes", "Claude Code is set to its gateway"],
|
|
135
|
+
["CLAUDE_CODE_USE_BEDROCK", "own-notes", "Claude Code is set to Amazon Bedrock"],
|
|
136
|
+
["CLAUDE_CODE_USE_FOUNDRY", "own-notes", "Claude Code is set to Microsoft Foundry"],
|
|
137
|
+
["CLAUDE_CODE_USE_ANTHROPIC_AWS", "whole", "Claude Code is set to Anthropic on AWS"],
|
|
138
|
+
["CLAUDE_CODE_USE_ANTHROPIC_GOOGLE_CLOUD", "whole", "Claude Code is set to Anthropic on Google Cloud"],
|
|
139
|
+
["CLAUDE_CODE_USE_MANTLE", "whole", "Claude Code is set to Mantle"],
|
|
140
|
+
["CLAUDE_CODE_USE_VERTEX", "own-notes", "Claude Code is set to Google Vertex AI"],
|
|
141
|
+
];
|
|
142
|
+
for (const [name, form, why] of provider) {
|
|
143
|
+
const v = get(name);
|
|
144
|
+
if (v && on(v.value))
|
|
145
|
+
return { form, why: `${why} (${v.where})` };
|
|
146
|
+
}
|
|
147
|
+
for (const name of ["ANTHROPIC_SMALL_FAST_MODEL", "ANTHROPIC_DEFAULT_HAIKU_MODEL"]) {
|
|
148
|
+
const v = get(name);
|
|
149
|
+
if (v)
|
|
150
|
+
return { form: "whole", why: `${v.where} replaces the small model that writes them` };
|
|
151
|
+
}
|
|
152
|
+
const base = get("ANTHROPIC_BASE_URL");
|
|
153
|
+
const route = byBaseUrl(base?.value, base?.where ?? "", sources, env, "an address that is not Anthropic's");
|
|
154
|
+
if (!base)
|
|
155
|
+
return route;
|
|
156
|
+
// Autopilot's proxy: from when autopilot was turned on; before it, the address it replaced (none: the Anthropic API).
|
|
157
|
+
const cfgPath = join(claudeDir(deps.home, env), AUTOPILOT_CONFIG);
|
|
158
|
+
try {
|
|
159
|
+
const cfg = JSON.parse(readFileSync(cfgPath, "utf8"));
|
|
160
|
+
if (typeof cfg?.port === "number" && base.value.replace(/\/+$/, "") === `http://127.0.0.1:${cfg.port}`) {
|
|
161
|
+
const prev = typeof cfg.previousBaseUrl === "string" && cfg.previousBaseUrl ? cfg.previousBaseUrl : undefined;
|
|
162
|
+
return { ...byBaseUrl(base.value, base.where, sources, env, "context-doctor's autopilot proxy, not Anthropic's address"), since: statSync(cfgPath).mtimeMs, before: byBaseUrl(prev, `ANTHROPIC_BASE_URL=${prev} before autopilot`, sources, env, "an address that is not Anthropic's") };
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
/* no autopilot */
|
|
167
|
+
}
|
|
168
|
+
return route;
|
|
169
|
+
}
|
|
170
|
+
/** The form for an ANTHROPIC_BASE_URL: Anthropic's own host (or none) is the Anthropic API; any other needs an Anthropic API key for Haiku. */
|
|
171
|
+
function byBaseUrl(url, where, sources, env, label) {
|
|
172
|
+
if (!url)
|
|
173
|
+
return ANTHROPIC_API_ROUTE;
|
|
174
|
+
let host = "";
|
|
175
|
+
try {
|
|
176
|
+
host = new URL(url).host;
|
|
177
|
+
}
|
|
178
|
+
catch { /* not a URL: not Anthropic's */ }
|
|
179
|
+
const assume = effectiveEnv("_CLAUDE_CODE_ASSUME_FIRST_PARTY_BASE_URL", sources, env);
|
|
180
|
+
if (host === "api.anthropic.com" || (assume && on(assume.value)))
|
|
181
|
+
return ANTHROPIC_API_ROUTE;
|
|
182
|
+
const to = `Claude Code talks to ${label} (${where})`;
|
|
183
|
+
if (effectiveEnv("ANTHROPIC_AUTH_TOKEN", sources, env))
|
|
184
|
+
return { form: "whole", why: `${to} with ANTHROPIC_AUTH_TOKEN, not an Anthropic API key` };
|
|
185
|
+
const key = effectiveEnv("ANTHROPIC_API_KEY", sources, env);
|
|
186
|
+
const helper = sources.find((s) => typeof s.settings.apiKeyHelper === "string" && s.settings.apiKeyHelper.trim());
|
|
187
|
+
if ((key && key.value.startsWith("sk-ant-api")) || helper) {
|
|
188
|
+
return { form: "range", why: `${to}; they are notes by Haiku only if it uses your Anthropic API key (${key ? "ANTHROPIC_API_KEY" : "apiKeyHelper"}), and context-doctor cannot tell whether it does` };
|
|
189
|
+
}
|
|
190
|
+
if (key)
|
|
191
|
+
return { form: "whole", why: `${to} with an ANTHROPIC_API_KEY that is not an Anthropic API key` };
|
|
192
|
+
return { form: "whole", why: `${to} and you sign in with a Claude account, not an Anthropic API key` };
|
|
193
|
+
}
|
|
81
194
|
/** How Claude Code reads the variable (a boolean: "1", "true", "yes", "on"). */
|
|
82
195
|
export const disablesSummaries = (v) => ["1", "true", "yes", "on"].includes(String(v ?? "").trim().toLowerCase());
|
|
83
196
|
/**
|
|
@@ -86,7 +199,7 @@ export const disablesSummaries = (v) => ["1", "true", "yes", "on"].includes(Stri
|
|
|
86
199
|
* reply; its output is in the next prompt).
|
|
87
200
|
*/
|
|
88
201
|
export const PROGRESS_ROWS = {
|
|
89
|
-
id: "progress-summaries.
|
|
202
|
+
id: "progress-summaries.2",
|
|
90
203
|
init: () => ({ head: false, ids: {} }),
|
|
91
204
|
line(raw, row, out, st) {
|
|
92
205
|
if (!raw.includes('"timestamp"'))
|
|
@@ -122,7 +235,8 @@ export const PROGRESS_ROWS = {
|
|
|
122
235
|
const u = m.usage;
|
|
123
236
|
const n = (v) => (typeof v === "number" && Number.isFinite(v) && v > 0 ? v : 0);
|
|
124
237
|
const prompt = n(u.input_tokens) + n(u.cache_read_input_tokens) + n(u.cache_creation_input_tokens);
|
|
125
|
-
|
|
238
|
+
const cloud = replyCloud(m.model, id);
|
|
239
|
+
out.push({ t: "r", ts, model: realModel(m.model), p: prompt, ...(u.speed === "fast" ? { speed: "fast" } : {}), ...(u.inference_geo === "us" ? { geo: "us" } : {}), ...(cloud ? { cloud } : {}) });
|
|
126
240
|
},
|
|
127
241
|
};
|
|
128
242
|
export function readAgentMeta(file) {
|
|
@@ -158,13 +272,25 @@ export function eligibility(meta, entrypoint, opts = {}) {
|
|
|
158
272
|
return "host";
|
|
159
273
|
return opts.forkGateOff ? "fork-gate-off" : "yes";
|
|
160
274
|
}
|
|
275
|
+
/** How one agent's summaries were written: its transcript's cloud, else the route at its start. */
|
|
276
|
+
export function agentRoute(recs, route = ANTHROPIC_API_ROUTE) {
|
|
277
|
+
const cloud = recs.find((x) => x.t === "r" && !!x.cloud)?.cloud;
|
|
278
|
+
if (cloud)
|
|
279
|
+
return { form: "own-notes", why: `the subagents ran on ${cloud === "bedrock" ? "Amazon Bedrock" : "Google Vertex AI"} (their model ids say so)` };
|
|
280
|
+
const first = recs.reduce((m, x) => (x.t === "m" && x.ts < m ? x.ts : m), Infinity);
|
|
281
|
+
let r = route;
|
|
282
|
+
while (r.since !== undefined && r.before && first < r.since)
|
|
283
|
+
r = r.before;
|
|
284
|
+
return r;
|
|
285
|
+
}
|
|
161
286
|
/**
|
|
162
287
|
* The ticks a running agent's timer made and the summaries they sent, from
|
|
163
288
|
* its timeline: every 30 s from its first row to its last, a summary when
|
|
164
289
|
* it has 3+ messages and more than at the last summary. Only ticks in
|
|
165
290
|
* [since, until] are counted.
|
|
166
291
|
*/
|
|
167
|
-
export function simulateAgent(recs, since = -Infinity, until = Infinity,
|
|
292
|
+
export function simulateAgent(recs, since = -Infinity, until = Infinity, mode = "old") {
|
|
293
|
+
const form = mode === true ? "haiku" : mode === false ? "old" : mode;
|
|
168
294
|
const msgs = recs.filter((r) => r.t === "m").map((r) => r.ts).sort((a, b) => a - b);
|
|
169
295
|
const replies = recs.filter((r) => r.t === "r").sort((a, b) => a.ts - b.ts);
|
|
170
296
|
const out = { calls: 0, notesUsd: 0, forkUsd: 0 };
|
|
@@ -194,29 +320,24 @@ export function simulateAgent(recs, since = -Infinity, until = Infinity, smallNo
|
|
|
194
320
|
const read = cur ? cur.p : 0;
|
|
195
321
|
const fresh = (next ? Math.max(0, next.p - read) : 0) + FORK_PROMPT_TOKENS;
|
|
196
322
|
const b = { ...(ref.speed ? { speed: ref.speed } : {}), ...(ref.geo ? { inference_geo: ref.geo } : {}) };
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
out.forkUsd += small.totalUsd;
|
|
204
|
-
out.notesUsd += small.totalUsd;
|
|
205
|
-
continue;
|
|
206
|
-
}
|
|
207
|
-
const fork = requestCost(model, { input_tokens: fresh, cache_read_input_tokens: read, cache_creation_input_tokens: 0, output_tokens: SUMMARY_OUTPUT_TOKENS, ...b }, at);
|
|
208
|
-
const notes = requestCost(model, { input_tokens: NOTES_TOKENS, cache_read_input_tokens: 0, cache_creation_input_tokens: 0, output_tokens: SUMMARY_OUTPUT_TOKENS, ...b }, at);
|
|
209
|
-
if (!fork || !notes)
|
|
323
|
+
// 2.1.328+ on the Anthropic API: the notes on the small fast model, the one way it sends them (the agent's fast mode is not the writer's).
|
|
324
|
+
const small = form === "haiku" || form === "range" ? requestCost(SMALL_FAST_MODEL, { input_tokens: NOTES_TOKENS, cache_read_input_tokens: 0, cache_creation_input_tokens: 0, output_tokens: SUMMARY_OUTPUT_TOKENS, ...(ref.geo ? { inference_geo: ref.geo } : {}) }, at) : undefined;
|
|
325
|
+
const fork = form === "old" || form === "whole" || form === "range" ? requestCost(model, { input_tokens: fresh, cache_read_input_tokens: read, cache_creation_input_tokens: 0, output_tokens: SUMMARY_OUTPUT_TOKENS, ...b }, at) : undefined;
|
|
326
|
+
const notes = form === "old" || form === "own-notes" ? requestCost(model, { input_tokens: NOTES_TOKENS, cache_read_input_tokens: 0, cache_creation_input_tokens: 0, output_tokens: SUMMARY_OUTPUT_TOKENS, ...b }, at) : undefined;
|
|
327
|
+
const [low, high] = form === "haiku" ? [small, small] : form === "own-notes" ? [notes, notes] : form === "whole" ? [fork, fork] : form === "range" ? [small, fork] : [notes, fork];
|
|
328
|
+
if (!low || !high)
|
|
210
329
|
continue;
|
|
211
330
|
out.calls++;
|
|
212
|
-
out.forkUsd +=
|
|
213
|
-
out.notesUsd +=
|
|
331
|
+
out.forkUsd += high.totalUsd;
|
|
332
|
+
out.notesUsd += low.totalUsd;
|
|
214
333
|
}
|
|
215
334
|
return out;
|
|
216
335
|
}
|
|
217
336
|
/** The summaries of the subagents in `files` (their `.jsonl` transcripts), estimated. */
|
|
218
337
|
export function estimateProgressSummaries(files, opts = {}) {
|
|
219
338
|
const r = { agents: 0, summarized: 0, calls: 0, smallCalls: 0, notesUsd: 0, forkUsd: 0, none: {}, hosts: [] };
|
|
339
|
+
const routes = new Map();
|
|
340
|
+
let value = 0;
|
|
220
341
|
const hosts = new Set();
|
|
221
342
|
for (const file of files) {
|
|
222
343
|
let recs;
|
|
@@ -244,16 +365,27 @@ export function estimateProgressSummaries(files, opts = {}) {
|
|
|
244
365
|
if (first > until)
|
|
245
366
|
why = "off";
|
|
246
367
|
else {
|
|
247
|
-
const
|
|
248
|
-
const
|
|
368
|
+
const recent = !!head?.version && compareVersions(head.version, SMALL_NOTES_SINCE) >= 0;
|
|
369
|
+
const route = recent ? agentRoute(recs, opts.route) : undefined;
|
|
370
|
+
const s = simulateAgent(recs, opts.since, until, route?.form ?? "old");
|
|
249
371
|
// One that ran under 30 s, or outside the window, sent none.
|
|
250
372
|
if (s.calls)
|
|
251
373
|
r.summarized++;
|
|
252
374
|
r.calls += s.calls;
|
|
253
|
-
if (small)
|
|
254
|
-
r.smallCalls += s.calls;
|
|
255
375
|
r.notesUsd += s.notesUsd;
|
|
256
376
|
r.forkUsd += s.forkUsd;
|
|
377
|
+
value += route ? s.forkUsd : s.notesUsd;
|
|
378
|
+
if (route?.form === "haiku")
|
|
379
|
+
r.smallCalls += s.calls;
|
|
380
|
+
else if (route && s.calls) {
|
|
381
|
+
const k = `${route.form}\n${route.why}`;
|
|
382
|
+
const g = routes.get(k) ?? { form: route.form, why: route.why, calls: 0, agents: 0, lowUsd: 0, highUsd: 0 };
|
|
383
|
+
g.calls += s.calls;
|
|
384
|
+
g.agents++;
|
|
385
|
+
g.lowUsd += s.notesUsd;
|
|
386
|
+
g.highUsd += s.forkUsd;
|
|
387
|
+
routes.set(k, g);
|
|
388
|
+
}
|
|
257
389
|
continue;
|
|
258
390
|
}
|
|
259
391
|
}
|
|
@@ -262,8 +394,22 @@ export function estimateProgressSummaries(files, opts = {}) {
|
|
|
262
394
|
r.none[why] = (r.none[why] ?? 0) + 1;
|
|
263
395
|
}
|
|
264
396
|
r.hosts = [...hosts].sort();
|
|
397
|
+
if (routes.size) {
|
|
398
|
+
r.routes = [...routes.values()].sort((a, b) => b.highUsd - a.highUsd);
|
|
399
|
+
r.valueUsd = value;
|
|
400
|
+
}
|
|
265
401
|
return r;
|
|
266
402
|
}
|
|
403
|
+
/** A 2.1.328+ form in words: what each summary sent, and on what. */
|
|
404
|
+
export function formWords(form) {
|
|
405
|
+
if (form === "haiku")
|
|
406
|
+
return `short notes, written by ${SMALL_FAST_MODEL_NAME}`;
|
|
407
|
+
if (form === "own-notes")
|
|
408
|
+
return "short notes, written by the subagent's own model";
|
|
409
|
+
if (form === "whole")
|
|
410
|
+
return "the subagent's whole context, on its own model";
|
|
411
|
+
return `short notes by ${SMALL_FAST_MODEL_NAME} (low) or the whole context (high)`;
|
|
412
|
+
}
|
|
267
413
|
/** "the Desktop app", "the SDK or -p": a host as a person knows it. */
|
|
268
414
|
export function hostName(entrypoint) {
|
|
269
415
|
if (entrypoint === "claude-desktop")
|
package/dist/proxy.d.ts
CHANGED
|
@@ -83,7 +83,7 @@ export interface ProxyOptions extends OptimizeOptions {
|
|
|
83
83
|
/** Default request body cap: far above any real request (a 1M-token context is ~4 MB of JSON, images aside). */
|
|
84
84
|
export declare const DEFAULT_MAX_BODY_BYTES: number;
|
|
85
85
|
/** Reported by /health so `autopilot status` can tell an outdated service from a current one. */
|
|
86
|
-
export declare const PROXY_VERSION = "0.
|
|
86
|
+
export declare const PROXY_VERSION = "0.52.0";
|
|
87
87
|
/**
|
|
88
88
|
* Remove a leading `/t/<token>` from a request path, or return undefined when
|
|
89
89
|
* the prefix is absent or the token differs. The comparison is constant time
|
package/dist/proxy.js
CHANGED
|
@@ -25,7 +25,7 @@ import { makeGuard, refusal } from "./httpguard.js";
|
|
|
25
25
|
/** Default request body cap: far above any real request (a 1M-token context is ~4 MB of JSON, images aside). */
|
|
26
26
|
export const DEFAULT_MAX_BODY_BYTES = 100 * 1024 * 1024;
|
|
27
27
|
/** Reported by /health so `autopilot status` can tell an outdated service from a current one. */
|
|
28
|
-
export const PROXY_VERSION = "0.
|
|
28
|
+
export const PROXY_VERSION = "0.52.0";
|
|
29
29
|
/** Connection-level headers that must not be forwarded. */
|
|
30
30
|
const SKIP_REQUEST_HEADERS = new Set(["host", "content-length", "connection", "transfer-encoding", "accept-encoding", "expect"]);
|
|
31
31
|
/** A reply carrying any of these has something for the limits ledger: a plan window, or the usage-credits state. */
|
package/dist/sample.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface SampleHistory {
|
|
2
|
+
/** Transcript paths, ready for estimateSavings(days, {}, paths). */
|
|
3
|
+
paths: string[];
|
|
4
|
+
/** Delete the temp folder. Call it in a finally. */
|
|
5
|
+
cleanup: () => void;
|
|
6
|
+
}
|
|
7
|
+
/** Two synthetic sessions: one with a cold return past the prompt cache, one without. */
|
|
8
|
+
export declare function writeSampleHistory(now?: number): SampleHistory;
|
package/dist/sample.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `savings --sample`: a demonstration report. The sessions are synthetic,
|
|
3
|
+
* written to a temp folder here and deleted right after; the report is the
|
|
4
|
+
* real replay pipeline (replaySession, estimateSavings) run over them, so
|
|
5
|
+
* every dollar is the product's own arithmetic on generated data. Nothing is
|
|
6
|
+
* measured on the user's machine and no usage is invented for them: the
|
|
7
|
+
* output says SAMPLE and says the data is generated. It is never substituted
|
|
8
|
+
* for the real report: with no history, `savings` says so and offers the flag.
|
|
9
|
+
*
|
|
10
|
+
* Deterministic apart from the anchor time: contents come from a seeded
|
|
11
|
+
* generator, timestamps are relative to `now` so the sessions always fall
|
|
12
|
+
* inside the report's 30-day window.
|
|
13
|
+
*/
|
|
14
|
+
import { mkdtempSync, rmSync, utimesSync, writeFileSync } from "node:fs";
|
|
15
|
+
import { tmpdir } from "node:os";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
const MIN = 60_000;
|
|
18
|
+
const DAY = 86_400_000;
|
|
19
|
+
function rng(seed) {
|
|
20
|
+
return () => {
|
|
21
|
+
seed |= 0;
|
|
22
|
+
seed = (seed + 0x6d2b79f5) | 0;
|
|
23
|
+
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
|
|
24
|
+
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
|
25
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/** A Read result, big enough to matter once it goes stale. */
|
|
29
|
+
const BIG_READ = "const value = compute(input, options); // step\n".repeat(400);
|
|
30
|
+
function sessionRows(s) {
|
|
31
|
+
const r = rng(s.seed);
|
|
32
|
+
const rows = [];
|
|
33
|
+
let t = s.start;
|
|
34
|
+
const iso = (ms) => new Date(ms).toISOString();
|
|
35
|
+
rows.push(JSON.stringify({ type: "user", cwd: "/work/app", sessionId: s.id, version: "2.1.300", entrypoint: "cli", uuid: `${s.id}-q0`, timestamp: iso(t), message: { role: "user", content: "Work through the backlog in src/, and run the tests as you go." } }));
|
|
36
|
+
const PROMPTS = ["Fix the failing test", "Now the next ticket", "That broke the build, revert it", "Add the retry and run the suite again", "Looks right, continue"];
|
|
37
|
+
const breakAt = new Map((s.breaks ?? []).map((b) => [b.at, b.hours]));
|
|
38
|
+
let prompt = s.promptStart;
|
|
39
|
+
for (let i = 0; i < s.requests; i++) {
|
|
40
|
+
const brk = breakAt.get(i);
|
|
41
|
+
t += brk !== undefined ? brk * 60 * MIN : 30_000 + Math.floor(r() * 60_000);
|
|
42
|
+
// Each request starts with what the person typed, as real transcripts do;
|
|
43
|
+
// the return after a long break always does.
|
|
44
|
+
if (i > 0 && (brk !== undefined || r() < 0.5)) {
|
|
45
|
+
rows.push(JSON.stringify({ type: "user", cwd: "/work/app", sessionId: s.id, version: "2.1.300", entrypoint: "cli", uuid: `${s.id}-u${i}`, timestamp: iso(t - 2_000), message: { role: "user", content: PROMPTS[Math.floor(r() * PROMPTS.length)] } }));
|
|
46
|
+
}
|
|
47
|
+
const usage = {
|
|
48
|
+
input_tokens: 5 + Math.floor(r() * 20),
|
|
49
|
+
cache_read_input_tokens: prompt,
|
|
50
|
+
cache_creation_input_tokens: s.promptStep,
|
|
51
|
+
output_tokens: 100 + Math.floor(r() * 400),
|
|
52
|
+
cache_creation: { ephemeral_5m_input_tokens: 0, ephemeral_1h_input_tokens: s.promptStep },
|
|
53
|
+
service_tier: "standard",
|
|
54
|
+
};
|
|
55
|
+
const toolId = `toolu_${s.id}_${i}`;
|
|
56
|
+
rows.push(JSON.stringify({
|
|
57
|
+
type: "assistant", cwd: "/work/app", sessionId: s.id, version: "2.1.300", entrypoint: "cli", uuid: `${s.id}-a${i}`, timestamp: iso(t),
|
|
58
|
+
message: { id: `msg_${s.id}_${i}`, type: "message", role: "assistant", model: s.model, content: [{ type: "tool_use", id: toolId, name: "Read", input: { file_path: `/work/app/src/file${i % 7}.ts` } }], usage },
|
|
59
|
+
}));
|
|
60
|
+
rows.push(JSON.stringify({
|
|
61
|
+
type: "user", cwd: "/work/app", sessionId: s.id, version: "2.1.300", entrypoint: "cli", uuid: `${s.id}-r${i}`, timestamp: iso(t + 1_000),
|
|
62
|
+
message: { role: "user", content: [{ type: "tool_result", tool_use_id: toolId, content: BIG_READ }] },
|
|
63
|
+
}));
|
|
64
|
+
prompt += s.promptStep;
|
|
65
|
+
}
|
|
66
|
+
return { rows, end: t + 2_000 };
|
|
67
|
+
}
|
|
68
|
+
/** Two synthetic sessions: one with a cold return past the prompt cache, one without. */
|
|
69
|
+
export function writeSampleHistory(now = Date.now()) {
|
|
70
|
+
const dir = mkdtempSync(join(tmpdir(), "context-doctor-sample-"));
|
|
71
|
+
const specs = [
|
|
72
|
+
// A big session, come back to twice after the cache expired: both levers show.
|
|
73
|
+
{ id: "sample-a", start: now - 6 * DAY, requests: 40, seed: 42, model: "claude-opus-5-5", promptStart: 200_000, promptStep: 15_000, breaks: [{ at: 12, hours: 3 }, { at: 26, hours: 26 }] },
|
|
74
|
+
// A smaller session without a cold return: not every session has one.
|
|
75
|
+
{ id: "sample-b", start: now - 2 * DAY, requests: 14, seed: 7, model: "claude-opus-5-5", promptStart: 60_000, promptStep: 8_000 },
|
|
76
|
+
];
|
|
77
|
+
const paths = [];
|
|
78
|
+
for (const s of specs) {
|
|
79
|
+
const { rows, end } = sessionRows(s);
|
|
80
|
+
const p = join(dir, `${s.id}.jsonl`);
|
|
81
|
+
writeFileSync(p, rows.join("\n") + "\n");
|
|
82
|
+
utimesSync(p, end / 1000, end / 1000);
|
|
83
|
+
paths.push(p);
|
|
84
|
+
}
|
|
85
|
+
return { paths, cleanup: () => rmSync(dir, { recursive: true, force: true }) };
|
|
86
|
+
}
|
package/dist/savings.d.ts
CHANGED
|
@@ -94,7 +94,14 @@ export declare function renderSavings(r: SavingsReport, autopilotOn?: boolean, c
|
|
|
94
94
|
hours: number;
|
|
95
95
|
netUsd: number;
|
|
96
96
|
pingUsd: number;
|
|
97
|
-
}): string;
|
|
97
|
+
}, sample?: boolean): string;
|
|
98
|
+
/**
|
|
99
|
+
* The demonstration report: the real replay over the synthetic history from
|
|
100
|
+
* sample.ts, said to be a sample in its first and last lines. Shown only by
|
|
101
|
+
* `savings --sample`; without it, no history stays an honest empty report
|
|
102
|
+
* that offers the flag.
|
|
103
|
+
*/
|
|
104
|
+
export declare function renderSampleSavings(r: SavingsReport): string;
|
|
98
105
|
/**
|
|
99
106
|
* `savings --share`: a few lines people can paste or screenshot. Totals only:
|
|
100
107
|
* no project names, paths or session ids, so sharing it leaks nothing.
|
package/dist/savings.js
CHANGED
|
@@ -354,10 +354,11 @@ export function estimateSavings(days = 30, options = {}, paths, onProgress, repl
|
|
|
354
354
|
}
|
|
355
355
|
const tokens = (n) => (n >= 1e9 ? `${(n / 1e9).toFixed(1)}B` : formatTokens(n));
|
|
356
356
|
const usd = (n) => (n >= 100 ? `$${Math.round(n).toLocaleString("en-US")}` : `$${n.toFixed(2)}`);
|
|
357
|
-
export function renderSavings(r, autopilotOn = false, cw, missLines, limitLines, lensLines, keepWarm) {
|
|
357
|
+
export function renderSavings(r, autopilotOn = false, cw, missLines, limitLines, lensLines, keepWarm, sample = false) {
|
|
358
358
|
const lines = [];
|
|
359
359
|
if (r.sessions.length === 0) {
|
|
360
|
-
lines.push(`No Claude Code sessions with 10+ requests in the last ${r.days} days to replay.`);
|
|
360
|
+
lines.push(`No Claude Code sessions with 10+ requests in the last ${r.days} days to replay: nothing of yours was measured.`);
|
|
361
|
+
lines.push("See the same report on generated example sessions: `context-doctor savings --sample`.");
|
|
361
362
|
lines.push("Use Claude Code for a while, then run this again: `context-doctor savings`.");
|
|
362
363
|
return withInvocation(lines.join("\n"));
|
|
363
364
|
}
|
|
@@ -365,9 +366,11 @@ export function renderSavings(r, autopilotOn = false, cw, missLines, limitLines,
|
|
|
365
366
|
const allDesktop = r.unreachableSessions === n;
|
|
366
367
|
const pct = (x) => (r.billedUsd > 0 ? ` (${Math.round((x / r.billedUsd) * 100)}%)` : "");
|
|
367
368
|
// Kept within 80 columns: this is most people's first screen of the tool.
|
|
368
|
-
lines.push("What context-doctor finds in your Claude Code sessions");
|
|
369
|
+
lines.push(sample ? "SAMPLE: what context-doctor finds in Claude Code sessions" : "What context-doctor finds in your Claude Code sessions");
|
|
369
370
|
// The same count, said the same way, as compact-window's.
|
|
370
|
-
lines.push(
|
|
371
|
+
lines.push(sample
|
|
372
|
+
? `Generated example sessions (no real history here), ${priceBasis()}`
|
|
373
|
+
: `Last ${r.days} days, ${sessionsLabel(n, r.transcripts ?? n)}, ${priceBasis()}`);
|
|
371
374
|
lines.push("─".repeat(60));
|
|
372
375
|
lines.push(`Input in your main conversations ${usd(r.billedUsd).padStart(9)} from your transcripts' usage`);
|
|
373
376
|
// spend's total is larger: it adds output and the subagents. Said here, so the two do not look like they disagree.
|
|
@@ -424,12 +427,34 @@ export function renderSavings(r, autopilotOn = false, cw, missLines, limitLines,
|
|
|
424
427
|
lines.push(...missLines);
|
|
425
428
|
}
|
|
426
429
|
lines.push("");
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
+
if (sample) {
|
|
431
|
+
lines.push("Replayed request by request through the shipped code, on sessions");
|
|
432
|
+
lines.push("generated for this demonstration. Nothing was measured on this machine.");
|
|
433
|
+
}
|
|
434
|
+
else {
|
|
435
|
+
lines.push("Replayed request by request through the shipped code and priced as the");
|
|
436
|
+
lines.push("prompt cache bills. On a subscription the same tokens come out of your");
|
|
437
|
+
lines.push("usage limit instead. Share yours: context-doctor savings --share");
|
|
438
|
+
lines.push("Run it again after a week of use: the report re-measures on what");
|
|
439
|
+
lines.push("changed, and `fix` shows what each applied fix has saved since.");
|
|
440
|
+
}
|
|
430
441
|
// Hints as the user can type them: `npx context-doctor …` after an npx run.
|
|
431
442
|
return withInvocation(lines.join("\n"));
|
|
432
443
|
}
|
|
444
|
+
/**
|
|
445
|
+
* The demonstration report: the real replay over the synthetic history from
|
|
446
|
+
* sample.ts, said to be a sample in its first and last lines. Shown only by
|
|
447
|
+
* `savings --sample`; without it, no history stays an honest empty report
|
|
448
|
+
* that offers the flag.
|
|
449
|
+
*/
|
|
450
|
+
export function renderSampleSavings(r) {
|
|
451
|
+
const body = renderSavings(r, false, undefined, undefined, undefined, undefined, undefined, true);
|
|
452
|
+
if (r.sessions.length === 0)
|
|
453
|
+
return body;
|
|
454
|
+
return body + "\n\n" + withInvocation("This is a demonstration on generated data, not your usage. Once this\n" +
|
|
455
|
+
"machine has real Claude Code sessions, `context-doctor savings` replays\n" +
|
|
456
|
+
"them the same way. See this sample again: `context-doctor savings --sample`.");
|
|
457
|
+
}
|
|
433
458
|
/**
|
|
434
459
|
* `savings --share`: a few lines people can paste or screenshot. Totals only:
|
|
435
460
|
* no project names, paths or session ids, so sharing it leaks nothing.
|
package/dist/spend.d.ts
CHANGED
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
* sessions with 10+ requests. `spend` counts every request, its output and
|
|
41
41
|
* subagents too; on the requests both count, the dollars are the same.
|
|
42
42
|
*/
|
|
43
|
-
import { type ProgressOptions } from "./progresssummaries.js";
|
|
43
|
+
import { type ProgressOptions, type ProgressSummaryEstimate } from "./progresssummaries.js";
|
|
44
44
|
import { type Modifiers } from "./pricing.js";
|
|
45
45
|
import { type SessionGap } from "./ccost.js";
|
|
46
46
|
import type { ExtraUsage } from "./claudedir.js";
|
|
@@ -298,6 +298,7 @@ export interface SpendReport {
|
|
|
298
298
|
* Claude Code's subagent progress summaries, estimated (no transcript records them): NOT in `usd`.
|
|
299
299
|
* `notesUsd` as short notes (served since November 2026), `forkUsd` as the whole context (before).
|
|
300
300
|
* `smallCalls`: of `calls`, those on Claude Code 2.1.328+, notes on the small fast model in both figures (absent when none).
|
|
301
|
+
* `routes`: the 2.1.328+ ones not on the Anthropic API, by form and why (absent when none): their figures are in both.
|
|
301
302
|
* `set`: CLAUDE_CODE_DISABLE_AGENT_PROGRESS_SUMMARIES is set there, since when unknown: not estimated.
|
|
302
303
|
* Absent when no subagent got any.
|
|
303
304
|
*/
|
|
@@ -305,6 +306,7 @@ export interface SpendReport {
|
|
|
305
306
|
agents: number;
|
|
306
307
|
calls: number;
|
|
307
308
|
smallCalls?: number;
|
|
309
|
+
routes?: ProgressSummaryEstimate["routes"];
|
|
308
310
|
notesUsd: number;
|
|
309
311
|
forkUsd: number;
|
|
310
312
|
} | {
|
|
@@ -356,7 +358,7 @@ export interface SpendOptions {
|
|
|
356
358
|
* The progress summaries' estimate: the fork gate, when the variable turned them off
|
|
357
359
|
* (fix's record), or where it is set with no record (then not estimated); false: none.
|
|
358
360
|
*/
|
|
359
|
-
progress?: false | (Pick<ProgressOptions, "forkGateOff" | "offSince"> & {
|
|
361
|
+
progress?: false | (Pick<ProgressOptions, "forkGateOff" | "offSince" | "route"> & {
|
|
360
362
|
set?: string;
|
|
361
363
|
});
|
|
362
364
|
/** The limits ledger to read for requests past the plan's limit (tests); default ~/.claude's. */
|
package/dist/spend.js
CHANGED
|
@@ -45,7 +45,7 @@ import { codexDir } from "./codexdir.js";
|
|
|
45
45
|
import { homedir } from "node:os";
|
|
46
46
|
import { closeSync, existsSync, openSync, readdirSync, readSync, statSync } from "node:fs";
|
|
47
47
|
import { claudeFileUsage, claudeUsageFiles, codexEventKey, codexSessionsRoot, rolloutFiles, USAGE_ROWS } from "./limits.js";
|
|
48
|
-
import { estimateProgressSummaries, PROGRESS_ROWS, PROGRESS_SUMMARIES_ENV, SMALL_FAST_MODEL_NAME as SMALL_NAME, SMALL_NOTES_SINCE } from "./progresssummaries.js";
|
|
48
|
+
import { estimateProgressSummaries, formWords, PROGRESS_ROWS, PROGRESS_SUMMARIES_ENV, SMALL_FAST_MODEL_NAME as SMALL_NAME, SMALL_NOTES_SINCE } from "./progresssummaries.js";
|
|
49
49
|
import { listGeminiChats, readGeminiMessages } from "./gemini.js";
|
|
50
50
|
import { cursorClaudeId, cursorUsage, SqliteUnavailableError } from "./cursor.js";
|
|
51
51
|
import { copilotCalls } from "./copilotusage.js";
|
|
@@ -764,8 +764,8 @@ function claudeProgressSummaries(since, until, tops, o) {
|
|
|
764
764
|
if (o?.set && o.offSince === undefined)
|
|
765
765
|
return { set: o.set };
|
|
766
766
|
const files = claudeUsageFiles(since, tops).filter((f) => f.subagent && !f.run).map((f) => f.file);
|
|
767
|
-
const e = estimateProgressSummaries(files, { since, until, forkGateOff: o?.forkGateOff, offSince: o?.offSince });
|
|
768
|
-
return e.calls ? { agents: e.summarized, calls: e.calls, ...(e.smallCalls ? { smallCalls: e.smallCalls } : {}), notesUsd: e.notesUsd, forkUsd: e.forkUsd } : undefined;
|
|
767
|
+
const e = estimateProgressSummaries(files, { since, until, forkGateOff: o?.forkGateOff, offSince: o?.offSince, route: o?.route });
|
|
768
|
+
return e.calls ? { agents: e.summarized, calls: e.calls, ...(e.smallCalls ? { smallCalls: e.smallCalls } : {}), ...(e.routes?.length ? { routes: e.routes } : {}), notesUsd: e.notesUsd, forkUsd: e.forkUsd } : undefined;
|
|
769
769
|
}
|
|
770
770
|
/**
|
|
771
771
|
* The longest window: ten years, older than any history these tools keep.
|
|
@@ -870,6 +870,24 @@ export function spendReport(days = 30, opts = {}) {
|
|
|
870
870
|
// ---------------------------------------------------------------------------
|
|
871
871
|
/** What an iteration type is, in the report's words. */
|
|
872
872
|
const ITERATION_NAME = { advisor_message: ["advisor call", "advisor calls"], message: ["attempt a fallback model replaced", "attempts a fallback model replaced"], fallback_message: ["fallback attempt replaced again", "fallback attempts replaced again"], compaction: ["server-side compaction", "server-side compactions"] };
|
|
873
|
+
/** The summaries' low and high figures are one (every form known). */
|
|
874
|
+
const oneFigure = (ps) => ps.forkUsd - ps.notesUsd < 0.005;
|
|
875
|
+
/** `text` in lines of at most 80 characters: the first indented by `first`, the rest by `rest`. */
|
|
876
|
+
function wrapLines(text, first, rest) {
|
|
877
|
+
const out = [];
|
|
878
|
+
let line = first;
|
|
879
|
+
for (const w of text.split(" ")) {
|
|
880
|
+
if (line.trim() && (line + " " + w).length > 80) {
|
|
881
|
+
out.push(line);
|
|
882
|
+
line = rest + w;
|
|
883
|
+
}
|
|
884
|
+
else
|
|
885
|
+
line = line.trim() ? `${line} ${w}` : line + w;
|
|
886
|
+
}
|
|
887
|
+
if (line.trim())
|
|
888
|
+
out.push(line);
|
|
889
|
+
return out;
|
|
890
|
+
}
|
|
873
891
|
export const usd = (n) => (n >= 100 ? `$${Math.round(n).toLocaleString("en-US")}` : n > 0 && n < 0.005 ? "<$0.01" : `$${n.toFixed(2)}`);
|
|
874
892
|
const share = (part, whole) => (whole > 0 ? `${Math.round((part / whole) * 100)}%` : "");
|
|
875
893
|
const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
@@ -981,6 +999,17 @@ export function renderSpend(r, top = 8) {
|
|
|
981
999
|
lines.push(` Not in it: ~${ps.calls.toLocaleString("en-US")} subagent progress summaries (${ps.agents} background ${ps.agents === 1 ? "agent" : "agents"}), an estimate:`);
|
|
982
1000
|
if (ps.smallCalls === ps.calls)
|
|
983
1001
|
lines.push(` ${usd(ps.notesUsd)}, short notes on ${SMALL_NAME} (Claude Code ${SMALL_NOTES_SINCE}+); in no transcript`);
|
|
1002
|
+
else if (ps.routes?.length) {
|
|
1003
|
+
// 2.1.328+ off the Anthropic API: each form with its count and why, wrapped.
|
|
1004
|
+
lines.push(` ${oneFigure(ps) ? usd(ps.forkUsd) : `${usd(ps.notesUsd)} to ${usd(ps.forkUsd)}`}; no transcript records them. How each was sent:`);
|
|
1005
|
+
if (ps.smallCalls)
|
|
1006
|
+
lines.push(` - ${ps.smallCalls.toLocaleString("en-US")}: ${formWords("haiku")} (Claude Code ${SMALL_NOTES_SINCE}+)`);
|
|
1007
|
+
for (const g of ps.routes)
|
|
1008
|
+
lines.push(...wrapLines(`- ${g.calls.toLocaleString("en-US")}: ${formWords(g.form)}${g.form === "range" ? `, ${usd(g.lowUsd)} to ${usd(g.highUsd)}: context-doctor cannot tell which` : `, ${usd(g.highUsd)}`}. Why: ${g.why}.`, " ", " "));
|
|
1009
|
+
const old = ps.calls - (ps.smallCalls ?? 0) - ps.routes.reduce((n, g) => n + g.calls, 0);
|
|
1010
|
+
if (old > 0)
|
|
1011
|
+
lines.push(` - ${old.toLocaleString("en-US")}: before Claude Code ${SMALL_NOTES_SINCE}, notes (low) or the whole context`);
|
|
1012
|
+
}
|
|
984
1013
|
else {
|
|
985
1014
|
lines.push(` ${usd(ps.notesUsd)} as notes, ${usd(ps.forkUsd)} at the whole context; no transcript records them`);
|
|
986
1015
|
if (ps.smallCalls)
|
|
@@ -1061,7 +1090,7 @@ export function renderSpendShare(r) {
|
|
|
1061
1090
|
lines.push(`Billed above list rates: ${modifiersText(r.modifiers)}.`);
|
|
1062
1091
|
const ps = r.progressSummaries;
|
|
1063
1092
|
if (ps && "calls" in ps)
|
|
1064
|
-
lines.push(`Not in it: Claude Code's subagent progress summaries, which no transcript records: ${ps.smallCalls === ps.calls ? usd(ps.notesUsd) : `${usd(ps.notesUsd)}-${usd(ps.forkUsd)}`}, an estimate.`);
|
|
1093
|
+
lines.push(`Not in it: Claude Code's subagent progress summaries, which no transcript records: ${ps.smallCalls === ps.calls || oneFigure(ps) ? usd(ps.notesUsd) : `${usd(ps.notesUsd)}-${usd(ps.forkUsd)}`}, an estimate.`);
|
|
1065
1094
|
const parts = [["cache writes", r.parts.writeUsd], ["cache reads", r.parts.readUsd], ["output", r.parts.outputUsd], ["uncached input", r.parts.inputUsd], ["web searches", r.parts.webSearchUsd ?? 0]];
|
|
1066
1095
|
const [bigPart, bigUsd] = parts.sort((a, b) => b[1] - a[1])[0];
|
|
1067
1096
|
const busiest = [...r.daily].sort((a, b) => b.usd - a.usd)[0];
|
package/dist/starts.d.ts
CHANGED
|
@@ -128,5 +128,12 @@ export declare function startServers(r: StartsReport): Array<StartServer & {
|
|
|
128
128
|
export declare function deferrableApp(r: StartsReport): Array<StartServer & {
|
|
129
129
|
usd: number;
|
|
130
130
|
}>;
|
|
131
|
+
/** Every start's cost over the period as billed, and the subagents' part of it; `unpriced` when a start had a model with no price. */
|
|
132
|
+
export declare function startsTotal(r: StartsReport): {
|
|
133
|
+
usd: number;
|
|
134
|
+
subagentUsd: number;
|
|
135
|
+
subagents: boolean;
|
|
136
|
+
unpriced: boolean;
|
|
137
|
+
};
|
|
131
138
|
/** The starts section of `overhead`. */
|
|
132
139
|
export declare function renderStarts(r: StartsReport, applied?: ReadonlySet<string>): string[];
|
package/dist/starts.js
CHANGED
|
@@ -404,6 +404,11 @@ export function deferrableApp(r) {
|
|
|
404
404
|
return startServers(r).filter((s) => !s.configured && APP_TOOL_SERVERS.includes(s.name));
|
|
405
405
|
}
|
|
406
406
|
const tok = (n) => `~${formatTokens(n)}`;
|
|
407
|
+
/** Every start's cost over the period as billed, and the subagents' part of it; `unpriced` when a start had a model with no price. */
|
|
408
|
+
export function startsTotal(r) {
|
|
409
|
+
const subs = r.groups.filter((g) => g.kind === "subagent");
|
|
410
|
+
return { usd: r.groups.reduce((t, g) => t + g.usd, 0), subagentUsd: subs.reduce((t, g) => t + g.usd, 0), subagents: subs.length > 0, unpriced: r.groups.some((g) => g.unpriced) };
|
|
411
|
+
}
|
|
407
412
|
/** The starts section of `overhead`. */
|
|
408
413
|
export function renderStarts(r, applied = new Set()) {
|
|
409
414
|
const out = ["", "Session and subagent starts (the first request, before the first message)", "─".repeat(56)];
|
|
@@ -424,9 +429,8 @@ export function renderStarts(r, applied = new Set()) {
|
|
|
424
429
|
line(`${entrypointName(g.entrypoint)} sessions`, g);
|
|
425
430
|
for (const g of subs)
|
|
426
431
|
line(`${g.agentType} (subagent)${new Set(subs.map((x) => x.entrypoint)).size > 1 ? ` (${entrypointName(g.entrypoint)})` : ""}`, g);
|
|
427
|
-
const
|
|
428
|
-
|
|
429
|
-
out.push(` Every start, re-read at each step over ${r.days} days: ${formatUsd(total)}${subs.length ? ` (subagents ${formatUsd(subUsd)})` : ""}. Token counts are the API's; tool sizes are estimates from their length.`);
|
|
432
|
+
const t = startsTotal(r);
|
|
433
|
+
out.push(` Every start, re-read at each step over ${r.days} days: ${formatUsd(t.usd)}${t.subagents ? ` (subagents ${formatUsd(t.subagentUsd)})` : ""}. Token counts are the API's; tool sizes are estimates from their length.`);
|
|
430
434
|
if (r.gap && r.gap.tokens > 0) {
|
|
431
435
|
out.push(` Desktop app vs terminal: a Desktop session starts ~${formatTokens(r.gap.tokens)} tokens larger (median ${tok(r.gap.desktop)} against ${tok(r.gap.terminal)}): ${formatUsd(r.gap.usd)} of its starts' cost in ${r.days} days.`);
|
|
432
436
|
}
|
package/dist/usagepane.js
CHANGED
|
@@ -112,7 +112,7 @@ export function limitFitsOf(r) {
|
|
|
112
112
|
const move = r.changes.filter((c) => c.window === "five_hour" || c.window === "seven_day").sort((a, b) => b.at - a.at)[0];
|
|
113
113
|
return {
|
|
114
114
|
...(Object.keys(fits).length ? { limitFits: fits } : {}),
|
|
115
|
-
...(move ? { limitMove: { window: move.window, at: move.at, before: round(move.usdPerPctBefore), after: round(move.usdPerPctAfter), factor: round(move.factor) } } : {}),
|
|
115
|
+
...(move ? { limitMove: { window: move.window, at: move.at, before: round(move.usdPerPctBefore), after: round(move.usdPerPctAfter), factor: round(move.factor), ...(move.cause && move.cause !== "limit" ? { cause: move.cause } : {}), ...(move.mix && (move.cause === "mix" || move.cause === "both") ? { model: move.mix.grew } : {}) } } : {}),
|
|
116
116
|
...(r.noFiveHour ? { noFiveHour: true } : {}),
|
|
117
117
|
};
|
|
118
118
|
}
|