context-doctor 0.43.0 → 0.44.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 +3 -2
- package/dist/budget.d.ts +13 -3
- package/dist/budget.js +158 -40
- package/dist/cachettl.d.ts +5 -1
- package/dist/cachettl.js +10 -25
- package/dist/cli.js +6 -9
- package/dist/codexcompact.d.ts +24 -3
- package/dist/codexcompact.js +207 -41
- package/dist/compactwindow.js +2 -2
- package/dist/cursor.d.ts +10 -0
- package/dist/cursor.js +20 -0
- package/dist/doctor.d.ts +9 -0
- package/dist/doctor.js +45 -0
- package/dist/fanout.js +4 -2
- package/dist/fix.d.ts +8 -1
- package/dist/fix.js +59 -13
- package/dist/hook.js +45 -15
- package/dist/install.js +56 -19
- package/dist/limits.d.ts +6 -2
- package/dist/limits.js +19 -16
- package/dist/mcp.js +63 -63
- package/dist/mcpclient.js +19 -19
- package/dist/mcpschema.js +5 -9
- package/dist/overhead.d.ts +7 -2
- package/dist/overhead.js +11 -3
- package/dist/pack.js +23 -3
- package/dist/pricing.d.ts +25 -5
- package/dist/pricing.js +157 -48
- package/dist/proxy.d.ts +15 -1
- package/dist/proxy.js +33 -5
- package/dist/prune.d.ts +8 -0
- package/dist/prune.js +20 -9
- package/dist/savings.js +2 -1
- package/dist/sessionprice.d.ts +7 -1
- package/dist/sessionprice.js +79 -28
- package/dist/settingsedit.js +3 -2
- package/dist/spend.d.ts +25 -3
- package/dist/spend.js +67 -19
- package/dist/subagentmodel.js +11 -1
- package/dist/subagentpay.d.ts +17 -0
- package/dist/subagentpay.js +41 -2
- package/dist/subagents.d.ts +24 -0
- package/dist/subagents.js +82 -17
- package/dist/tooloutput.d.ts +2 -0
- package/dist/tooloutput.js +2 -0
- package/package.json +1 -1
package/dist/mcpschema.js
CHANGED
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
* up; with it on, an unused server costs about its tool names, not its
|
|
17
17
|
* schemas. Usage of ToolSearch in the transcripts says whether that is so.
|
|
18
18
|
*/
|
|
19
|
-
import {
|
|
19
|
+
import { readFileSync } from "node:fs";
|
|
20
20
|
import { homedir } from "node:os";
|
|
21
21
|
import { join, resolve } from "node:path";
|
|
22
22
|
import { listSessions, isClaudeSession } from "./session.js";
|
|
23
23
|
import { rowsOf } from "./scan.js";
|
|
24
|
-
import {
|
|
24
|
+
import { subagentFiles } from "./subagents.js";
|
|
25
25
|
import { estimateTokens } from "./tokens.js";
|
|
26
26
|
import { claudeJsonPath } from "./claudedir.js";
|
|
27
27
|
const CLAUDE = "claude-opus-5";
|
|
@@ -185,14 +185,10 @@ export function mcpUsage(days = 30, paths, onProgress) {
|
|
|
185
185
|
}
|
|
186
186
|
};
|
|
187
187
|
scan(path);
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
agents = readdirSync(subagentDir(path)).filter((f) => f.endsWith(".jsonl"));
|
|
191
|
-
}
|
|
192
|
-
catch { /* no subagents */ }
|
|
193
|
-
for (const a of agents) {
|
|
188
|
+
// Subagents and workflow agents call MCP tools too.
|
|
189
|
+
for (const a of subagentFiles(path)) {
|
|
194
190
|
try {
|
|
195
|
-
scan(
|
|
191
|
+
scan(a.file);
|
|
196
192
|
}
|
|
197
193
|
catch { /* one unreadable subagent must not sink the report */ }
|
|
198
194
|
}
|
package/dist/overhead.d.ts
CHANGED
|
@@ -80,8 +80,13 @@ export declare function overheadReport(opts?: {
|
|
|
80
80
|
paths?: string[];
|
|
81
81
|
onProgress?: (done: number, total: number, stage: "sessions" | "mcp") => void;
|
|
82
82
|
}): OverheadReport;
|
|
83
|
-
/**
|
|
84
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Launch each configured server and size its tool definitions, then add the
|
|
85
|
+
* findings they support. A project `.mcp.json` server is launched only once
|
|
86
|
+
* the user approved it in Claude Code: the file comes with the repository,
|
|
87
|
+
* and `overhead --mcp` in a fresh clone ran whatever command it named.
|
|
88
|
+
*/
|
|
89
|
+
export declare function measureMcpSizes(r: OverheadReport, home?: string): Promise<void>;
|
|
85
90
|
/** Configured servers nobody called: their definitions ride on every request for nothing. */
|
|
86
91
|
export declare function mcpFindings(m: McpSection, baseline?: Baseline): OverheadFinding[];
|
|
87
92
|
export declare function renderOverhead(r: OverheadReport, home?: string): string;
|
package/dist/overhead.js
CHANGED
|
@@ -24,6 +24,7 @@ import { cacheWriteSplit, formatUsd, pricingFor, writeMultiplier as ttlWriteMult
|
|
|
24
24
|
import { isGeminiChat, readGeminiMessages } from "./gemini.js";
|
|
25
25
|
import { claudeMcpConfigs, mcpUsage, measureServer, otherServerUses, serverUses } from "./mcpschema.js";
|
|
26
26
|
import { claudeDir } from "./claudedir.js";
|
|
27
|
+
import { mcpjsonServerApproved } from "./prune.js";
|
|
27
28
|
import { REQUEST_ROWS } from "./coldresume.js";
|
|
28
29
|
import { rowsOf } from "./scan.js";
|
|
29
30
|
const TTL_MS = 3_600_000;
|
|
@@ -419,9 +420,16 @@ export function overheadReport(opts = {}) {
|
|
|
419
420
|
const mcp = { configs: claudeMcpConfigs(cwd, home), usage: mcpUsage(opts.days ?? 30, claudePaths, tick("mcp")) };
|
|
420
421
|
return { cwd, baseline, baselines, files, findings: overheadFindings(files, baselines), mcp };
|
|
421
422
|
}
|
|
422
|
-
/**
|
|
423
|
-
|
|
424
|
-
|
|
423
|
+
/**
|
|
424
|
+
* Launch each configured server and size its tool definitions, then add the
|
|
425
|
+
* findings they support. A project `.mcp.json` server is launched only once
|
|
426
|
+
* the user approved it in Claude Code: the file comes with the repository,
|
|
427
|
+
* and `overhead --mcp` in a fresh clone ran whatever command it named.
|
|
428
|
+
*/
|
|
429
|
+
export async function measureMcpSizes(r, home = homedir()) {
|
|
430
|
+
r.mcp.sizes = await Promise.all(r.mcp.configs.map((c) => c.scope === ".mcp.json" && !mcpjsonServerApproved(c.name, r.cwd, home)
|
|
431
|
+
? { name: c.name, error: "in this folder's .mcp.json, not approved in Claude Code: not launched" }
|
|
432
|
+
: measureServer(c)));
|
|
425
433
|
r.findings.push(...mcpFindings(r.mcp, r.baseline));
|
|
426
434
|
}
|
|
427
435
|
/** Configured servers nobody called: their definitions ride on every request for nothing. */
|
package/dist/pack.js
CHANGED
|
@@ -19,6 +19,8 @@ import { homedir } from "node:os";
|
|
|
19
19
|
import { basename, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
20
20
|
import { estimateTokens, formatTokens } from "./tokens.js";
|
|
21
21
|
import { EXTRACT_BUDGET_MS, EXTRACTABLE, extractText, extractTextAsync, monotonicNow } from "./extract.js";
|
|
22
|
+
import { claudeDir } from "./claudedir.js";
|
|
23
|
+
import { codexDir } from "./codexdir.js";
|
|
22
24
|
const DEFAULT_BUDGET = 4000;
|
|
23
25
|
const DEFAULT_CHUNK_TOKENS = 400;
|
|
24
26
|
/** Claude's tokenizer produces the most tokens per char; a budget in its terms never overruns another's. */
|
|
@@ -389,7 +391,19 @@ function within(root, inner) {
|
|
|
389
391
|
* token verbatim. They are skipped even when named outright or tracked by
|
|
390
392
|
* git; only the CLI's --include-secrets packs them.
|
|
391
393
|
*/
|
|
392
|
-
const SECRET_NAMES = new Set([
|
|
394
|
+
const SECRET_NAMES = new Set([
|
|
395
|
+
".npmrc", ".pypirc", ".netrc", "_netrc", ".git-credentials", ".pgpass", ".htpasswd", ".vault-token",
|
|
396
|
+
// The agents' own sign-ins, which an injected instruction in a packed doc
|
|
397
|
+
// could otherwise ask for by name: Claude Code's OAuth tokens (Linux,
|
|
398
|
+
// Windows), Gemini CLI's, Terraform's.
|
|
399
|
+
".credentials.json", "oauth_creds.json", "credentials.tfrc.json",
|
|
400
|
+
]);
|
|
401
|
+
/** A file name that holds credentials inside one folder only: Codex's sign-in, Cargo's and RubyGems' tokens. */
|
|
402
|
+
const SECRET_IN_DIR = [
|
|
403
|
+
[".codex", ["auth.json"]],
|
|
404
|
+
[".cargo", ["credentials", "credentials.toml"]],
|
|
405
|
+
[".gem", ["credentials"]],
|
|
406
|
+
];
|
|
393
407
|
const SECRET_EXT = new Set([".pem", ".key", ".p12", ".pfx", ".keystore", ".jks"]);
|
|
394
408
|
/** Why `path` looks like a secrets file, or undefined when it does not. */
|
|
395
409
|
export function secretFileReason(path) {
|
|
@@ -407,6 +421,9 @@ export function secretFileReason(path) {
|
|
|
407
421
|
const parts = path.split(/[\\/]+/);
|
|
408
422
|
if (lower === "credentials" && parts[parts.length - 2] === ".aws")
|
|
409
423
|
return "AWS credentials";
|
|
424
|
+
const parent = (parts[parts.length - 2] ?? "").toLowerCase();
|
|
425
|
+
if (SECRET_IN_DIR.some(([dir, files]) => dir === parent && files.includes(lower)))
|
|
426
|
+
return `a credentials file (${parent}/${name})`;
|
|
410
427
|
return undefined;
|
|
411
428
|
}
|
|
412
429
|
/**
|
|
@@ -416,7 +433,9 @@ export function secretFileReason(path) {
|
|
|
416
433
|
function sensitiveDirs() {
|
|
417
434
|
const home = homedir();
|
|
418
435
|
const dirs = [
|
|
419
|
-
...[".ssh", ".aws", ".gnupg", ".kube", ".docker", ".azure", join(".config", "gcloud"), join("Library", "Keychains"), ".password-store"].map((d) => join(home, d)),
|
|
436
|
+
...[".ssh", ".aws", ".gnupg", ".kube", ".docker", ".azure", join(".config", "gcloud"), join(".config", "gh"), join(".config", "github-copilot"), join("Library", "Keychains"), ".password-store"].map((d) => join(home, d)),
|
|
437
|
+
// Where CLAUDE_CONFIG_DIR and CODEX_HOME put the agents' sign-ins.
|
|
438
|
+
join(claudeDir(), ".credentials.json"), join(codexDir(), "auth.json"),
|
|
420
439
|
"/etc/shadow", "/etc/gshadow", "/etc/sudoers", "/etc/master.passwd", "/etc/ssh",
|
|
421
440
|
];
|
|
422
441
|
// Compared against real paths: /etc is /private/etc on macOS, and a home
|
|
@@ -568,7 +587,8 @@ export function readSources(paths, cwdOrOptions = process.cwd()) {
|
|
|
568
587
|
return;
|
|
569
588
|
}
|
|
570
589
|
if (!includeSecrets) {
|
|
571
|
-
|
|
590
|
+
// The link's name and its target's: notes.md pointing at an .env is an .env.
|
|
591
|
+
const why = secretFileReason(p) ?? secretFileReason(realOf(p));
|
|
572
592
|
if (why) {
|
|
573
593
|
skipped.push(`${p}: ${why}, likely holding secrets; not packed${secretsHint}`);
|
|
574
594
|
return;
|
package/dist/pricing.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Per-model pricing for cost estimation, USD per million tokens.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* List rates of each provider's first-party API (standard tier, global
|
|
5
|
+
* routing, no batch or fast mode), each family with the page it was read
|
|
6
|
+
* from and the date. Prices drift, so all cost output is labeled as an
|
|
7
|
+
* estimate. One table, one file, easy to update: PRs welcome when prices
|
|
8
|
+
* change.
|
|
9
|
+
*
|
|
10
|
+
* A row names one model (a "known" price, see knownPricingFor) unless it is
|
|
11
|
+
* listed in FALLBACKS: those price ids the table does not know by version,
|
|
12
|
+
* at a family's price, so a new release still gets a number. A model a
|
|
13
|
+
* provider prices only per minute, per image or not at all has no row.
|
|
9
14
|
*/
|
|
10
15
|
export interface ModelPricing {
|
|
11
16
|
/** USD per 1M input tokens. */
|
|
@@ -28,6 +33,21 @@ export declare const CACHE_WRITE_1H = 2;
|
|
|
28
33
|
export declare const CACHE_WRITE_OPENAI_30M = 1.25;
|
|
29
34
|
export declare const CACHE_WRITE_OPENAI_12H = 2.5;
|
|
30
35
|
export declare function pricingFor(model?: string): ModelPricing | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* A model's price from a row for that model, not a family fallback: undefined
|
|
38
|
+
* for an id the table only knows by family (a new release, a typo like
|
|
39
|
+
* claude-opus-9, gpt-5-codex) and for one it does not know at all. What a
|
|
40
|
+
* report needs to say which models it priced by guess or not at all.
|
|
41
|
+
*/
|
|
42
|
+
export declare function knownPricingFor(model?: string): ModelPricing | undefined;
|
|
43
|
+
/** Whether a model id has a price of its own in the table (see knownPricingFor). */
|
|
44
|
+
export declare function hasKnownPrice(model?: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Ids that are never billed, so never "unpriced": Claude Code writes
|
|
47
|
+
* `<synthetic>` on replies it makes itself (an error, an interruption)
|
|
48
|
+
* without calling the API.
|
|
49
|
+
*/
|
|
50
|
+
export declare function isUnbilledModel(model?: string): boolean;
|
|
31
51
|
/**
|
|
32
52
|
* A Claude model's price from a row for its own version, not a family
|
|
33
53
|
* fallback: what a command that caps spending needs (`ab --budget`). An id
|
package/dist/pricing.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Per-model pricing for cost estimation, USD per million tokens.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* List rates of each provider's first-party API (standard tier, global
|
|
5
|
+
* routing, no batch or fast mode), each family with the page it was read
|
|
6
|
+
* from and the date. Prices drift, so all cost output is labeled as an
|
|
7
|
+
* estimate. One table, one file, easy to update: PRs welcome when prices
|
|
8
|
+
* change.
|
|
9
|
+
*
|
|
10
|
+
* A row names one model (a "known" price, see knownPricingFor) unless it is
|
|
11
|
+
* listed in FALLBACKS: those price ids the table does not know by version,
|
|
12
|
+
* at a family's price, so a new release still gets a number. A model a
|
|
13
|
+
* provider prices only per minute, per image or not at all has no row.
|
|
9
14
|
*/
|
|
10
15
|
/** Anthropic cache writes, relative to the input price: 5-minute TTL and 1-hour TTL. */
|
|
11
16
|
export const CACHE_WRITE_5M = 1.25;
|
|
@@ -34,7 +39,30 @@ function claude(families, major, minor) {
|
|
|
34
39
|
}
|
|
35
40
|
/** The Claude family fallbacks: a price for ids the table does not know by version yet. */
|
|
36
41
|
const CLAUDE_FAMILY = [/claude.*fable|claude.*mythos/i, /claude.*opus/i, /claude.*sonnet/i, /claude.*haiku/i];
|
|
42
|
+
const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
43
|
+
/**
|
|
44
|
+
* One OpenAI model by its exact name, bare, with a snapshot date
|
|
45
|
+
* (gpt-5.5-2026-04-23) or behind a provider prefix (openai/gpt-5.5):
|
|
46
|
+
* "gpt-5.5" never matches gpt-5.5-pro or gpt-5.5-cyber, "gpt-5" never
|
|
47
|
+
* gpt-5.4, "o3" never o3-pro.
|
|
48
|
+
*/
|
|
49
|
+
function openai(name) {
|
|
50
|
+
return new RegExp(`(?<![\\w.-])${escapeRe(name)}(?:-\\d{4}-\\d{2}-\\d{2})?(?![\\w.-])`, "i");
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* One Gemini text model, with any suffix Google adds to the same model
|
|
54
|
+
* (-preview, -001, -preview-05-20, -customtools), but not the image, audio,
|
|
55
|
+
* live and TTS models that share its name and are priced per image or
|
|
56
|
+
* minute, nor its -lite sibling.
|
|
57
|
+
*/
|
|
58
|
+
function gemini(name) {
|
|
59
|
+
return new RegExp(`(?<![\\w.-])${escapeRe(name)}(?![\\w.])(?!-(?:[\\w.]+-)*(?:lite|image|tts|live|audio|transcribe|translate)\\b)`, "i");
|
|
60
|
+
}
|
|
61
|
+
/** A row that prices ids the table does not know by name, at a family's price. */
|
|
62
|
+
const FALLBACK = true;
|
|
37
63
|
const PRICING = [
|
|
64
|
+
// Anthropic: platform.claude.com/docs/en/about-claude/pricing ("Model
|
|
65
|
+
// pricing"; 5-minute writes 1.25x, 1-hour writes 2x), read 2026-11-06.
|
|
38
66
|
// Specific Claude versions first: the family rows below are only a
|
|
39
67
|
// fallback for ids this table does not know yet.
|
|
40
68
|
[claude("fable|mythos", 5, 1), rate(10, 50, 0.25)],
|
|
@@ -47,51 +75,139 @@ const PRICING = [
|
|
|
47
75
|
[claude("opus", 4, 5), rate(5, 25, 0.5)],
|
|
48
76
|
[claude("opus", 4, 1), rate(15, 75, 1.5)],
|
|
49
77
|
[claude("opus", 4), rate(15, 75, 1.5)],
|
|
50
|
-
|
|
51
|
-
[claude("sonnet", 5, 5), rate(2, 10, 0.
|
|
78
|
+
// Sonnet 5.5's cache hits are 5% of input ($0.10), Sonnet 5's 10%.
|
|
79
|
+
[claude("sonnet", 5, 5), rate(2, 10, 0.1)],
|
|
52
80
|
[claude("sonnet", 5), rate(2, 10, 0.2)],
|
|
53
|
-
// Haiku 5.5's rates hold for prompts up to 100k tokens; longer
|
|
54
|
-
//
|
|
81
|
+
// Haiku 5.5's rates hold for prompts up to 100k tokens; a longer prompt
|
|
82
|
+
// bills the whole request at $0.50 / $2.50 / $0.05, a tier this per-token
|
|
83
|
+
// table does not model.
|
|
55
84
|
[claude("haiku", 5, 5), rate(0.1, 0.5, 0.01)],
|
|
56
85
|
[claude("haiku", 4, 5), rate(1, 5, 0.1)],
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
//
|
|
60
|
-
// family row's price; rows of their own so a spending cap can tell a known
|
|
61
|
-
// version from a guess (exactClaudePricingFor).
|
|
86
|
+
// Sonnet 4.6, 4.5 and 4 are all $3 / $15 / $0.30, the family row's price;
|
|
87
|
+
// rows of their own so a spending cap can tell a known version from a
|
|
88
|
+
// guess (knownPricingFor).
|
|
62
89
|
[claude("sonnet", 4, 6), rate(3, 15, 0.3)],
|
|
63
90
|
[claude("sonnet", 4, 5), rate(3, 15, 0.3)],
|
|
64
91
|
[claude("sonnet", 4), rate(3, 15, 0.3)],
|
|
92
|
+
// Retired Claude 3 models, no longer on the page: their last list price.
|
|
93
|
+
[/claude-3-opus/i, rate(15, 75, 1.5)],
|
|
94
|
+
[/claude-3-5-haiku/i, rate(0.8, 4, 0.08)],
|
|
95
|
+
[/claude-3-haiku/i, rate(0.25, 1.25, 0.03)],
|
|
65
96
|
[/claude-3-[57]-sonnet/i, rate(3, 15, 0.3)],
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
[CLAUDE_FAMILY[
|
|
69
|
-
[CLAUDE_FAMILY[
|
|
70
|
-
[
|
|
71
|
-
[
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
-
[
|
|
80
|
-
[
|
|
81
|
-
[
|
|
82
|
-
[
|
|
83
|
-
[
|
|
84
|
-
[
|
|
85
|
-
[
|
|
97
|
+
// Claude Mythos Preview (claude-mythos-preview) has no list price on the
|
|
98
|
+
// page; the Fable/Mythos family row prices it as a fallback.
|
|
99
|
+
[CLAUDE_FAMILY[0], rate(10, 50, 1), FALLBACK],
|
|
100
|
+
[CLAUDE_FAMILY[1], rate(5, 25, 0.5), FALLBACK],
|
|
101
|
+
[CLAUDE_FAMILY[2], rate(3, 15, 0.3), FALLBACK],
|
|
102
|
+
[CLAUDE_FAMILY[3], rate(1, 5, 0.1), FALLBACK],
|
|
103
|
+
// OpenAI: developers.openai.com/api/docs/pricing (Standard, the "Short"
|
|
104
|
+
// context column), read 2026-11-06. Prompts over 272k input tokens bill
|
|
105
|
+
// the whole request at 2x input and cache rates and 1.5x output on GPT-5.4
|
|
106
|
+
// and later (per model page), a tier this table does not model. Cache
|
|
107
|
+
// writes are 1.25x input on GPT-5.6 and later (CACHE_WRITE_OPENAI_30M).
|
|
108
|
+
// Models with no cached-input price (the -pro ones) read at full input.
|
|
109
|
+
[openai("gpt-6-astra"), rate(10, 50, 1)],
|
|
110
|
+
[openai("gpt-6-astra-law"), rate(10, 50, 1)],
|
|
111
|
+
[openai("gpt-6.1-sol"), rate(2, 10, 0.1)],
|
|
112
|
+
[openai("gpt-6.1-terra"), rate(1, 5, 0.05)],
|
|
113
|
+
[openai("gpt-6-sol"), rate(2, 10, 0.2)],
|
|
114
|
+
[openai("gpt-6-luna"), rate(0.1, 0.5, 0.01)],
|
|
115
|
+
[openai("gpt-6-cyber"), rate(20, 100, 2)],
|
|
116
|
+
[openai("gpt-6-rosalind"), rate(15, 75, 1.5)],
|
|
117
|
+
[openai("gpt-rosalind-research"), rate(5, 25, 0.5)],
|
|
118
|
+
[openai("gpt-rosalind-discovery"), rate(5, 25, 0.5)],
|
|
119
|
+
// GPT-5.6 Sol's $4 / $20 is promotional "until November 30, 2026"; the
|
|
120
|
+
// page does not say what follows. The gpt-5.6 alias routes to Sol (model
|
|
121
|
+
// page, read 2026-11-06).
|
|
122
|
+
[openai("gpt-5.6-sol"), rate(4, 20, 0.4)],
|
|
123
|
+
[openai("gpt-5.6"), rate(4, 20, 0.4)],
|
|
124
|
+
[openai("gpt-5.6-terra"), rate(2, 12, 0.2)],
|
|
125
|
+
[openai("gpt-5.6-luna"), rate(0.2, 1.2, 0.02)],
|
|
126
|
+
[openai("gpt-5.6-cyber"), rate(12.5, 75, 1.25)],
|
|
127
|
+
[openai("gpt-5.5"), rate(5, 30, 0.5)],
|
|
128
|
+
[openai("gpt-5.5-pro"), rate(30, 180, 30)],
|
|
129
|
+
[openai("gpt-5.5-cyber"), rate(12.5, 75, 1.25)],
|
|
130
|
+
[openai("gpt-5.4"), rate(2.5, 15, 0.25)],
|
|
131
|
+
[openai("gpt-5.4-mini"), rate(0.75, 4.5, 0.075)],
|
|
132
|
+
[openai("gpt-5.4-nano"), rate(0.2, 1.25, 0.02)],
|
|
133
|
+
[openai("gpt-5.4-pro"), rate(30, 180, 30)],
|
|
134
|
+
[openai("gpt-5.3-codex"), rate(1.75, 14, 0.175)],
|
|
135
|
+
[openai("gpt-5.2"), rate(1.75, 14, 0.175)],
|
|
136
|
+
[openai("gpt-5.2-pro"), rate(21, 168, 21)],
|
|
137
|
+
[openai("gpt-5.1"), rate(1.25, 10, 0.125)],
|
|
138
|
+
[openai("gpt-5"), rate(1.25, 10, 0.125)],
|
|
139
|
+
[openai("gpt-5-mini"), rate(0.25, 2, 0.025)],
|
|
140
|
+
[openai("gpt-5-nano"), rate(0.05, 0.4, 0.005)],
|
|
141
|
+
[openai("gpt-5-pro"), rate(15, 120, 15)],
|
|
142
|
+
[openai("gpt-4.1"), rate(2, 8, 0.5)],
|
|
143
|
+
[openai("gpt-4.1-mini"), rate(0.4, 1.6, 0.1)],
|
|
144
|
+
[openai("gpt-4o"), rate(2.5, 10, 1.25)],
|
|
145
|
+
[openai("gpt-4o-mini"), rate(0.15, 0.6, 0.075)],
|
|
146
|
+
[openai("o3"), rate(2, 8, 0.5)],
|
|
147
|
+
[openai("o3-pro"), rate(20, 80, 20)],
|
|
148
|
+
[openai("chat-latest"), rate(5, 30, 0.5)],
|
|
149
|
+
// Fallbacks for OpenAI ids not on the page (gpt-5-codex, gpt-5.1-codex-max,
|
|
150
|
+
// gpt-4.1-nano, gpt-4-turbo, o1, o3-mini...): older approximate prices.
|
|
151
|
+
[/gpt-5.*(mini|nano)/i, rate(0.25, 2, 0.025), FALLBACK],
|
|
152
|
+
[/gpt-5/i, rate(1.25, 10, 0.125), FALLBACK],
|
|
153
|
+
[/gpt-4o-mini/i, rate(0.15, 0.6, 0.075), FALLBACK],
|
|
154
|
+
[/gpt-4o|gpt-4\.1/i, rate(2.5, 10, 1.25), FALLBACK],
|
|
155
|
+
[/gpt-4-turbo/i, rate(10, 30, 10), FALLBACK],
|
|
156
|
+
[/o[13](-|$)/i, rate(2, 8, 1), FALLBACK],
|
|
157
|
+
// Google: ai.google.dev/gemini-api/docs/pricing (paid tier, Standard, text),
|
|
158
|
+
// read 2026-11-06.
|
|
159
|
+
// Gemini 4 Argon's $2 / $10 / $0.10 hold through 2026-11-30; from
|
|
160
|
+
// 2026-12-01 it is $4 / $20 / $0.20.
|
|
161
|
+
[gemini("gemini-4-argon"), rate(2, 10, 0.1)],
|
|
162
|
+
// 3.6 and 3.8 Flash double from 2027-01-01 ($1.50 / $7.50 / $0.15).
|
|
163
|
+
[gemini("gemini-3.8-flash"), rate(0.75, 3.75, 0.075)],
|
|
164
|
+
[gemini("gemini-3.6-flash"), rate(0.75, 3.75, 0.075)],
|
|
165
|
+
[gemini("gemini-3.5-flash-lite"), rate(0.3, 2.5, 0.03)],
|
|
166
|
+
[gemini("gemini-3.1-flash-lite"), rate(0.25, 1.5, 0.025)],
|
|
167
|
+
// 3.1 Pro and 2.5 Pro bill prompts over 200k at $4 / $18 / $0.40 and
|
|
168
|
+
// $2.50 / $15 / $0.25, a tier this table does not model.
|
|
169
|
+
[gemini("gemini-3.1-pro"), rate(2, 12, 0.2)],
|
|
170
|
+
[gemini("gemini-3-flash"), rate(0.5, 3, 0.05)],
|
|
171
|
+
[gemini("gemini-2.5-pro"), rate(1.25, 10, 0.125)],
|
|
172
|
+
[gemini("gemini-2.5-flash"), rate(0.3, 2.5, 0.03)],
|
|
173
|
+
[gemini("gemini-2.5-flash-lite"), rate(0.1, 0.4, 0.01)],
|
|
174
|
+
// Fallbacks for Gemini ids not on the page (gemini-3-pro, a new 3.x Flash,
|
|
175
|
+
// 2.0 Flash...).
|
|
176
|
+
[/gemini-3[.\d]*-flash-lite/i, rate(0.3, 2.5, 0.03), FALLBACK],
|
|
177
|
+
[/gemini-3[.\d]*-flash/i, rate(0.75, 3.75, 0.075), FALLBACK],
|
|
178
|
+
[/gemini-3[.\d]*-pro/i, rate(2, 12, 0.2), FALLBACK],
|
|
179
|
+
[/gemini.*flash/i, rate(0.1, 0.4, 0.025), FALLBACK],
|
|
180
|
+
[/gemini.*pro/i, rate(1.25, 5, 0.31), FALLBACK],
|
|
86
181
|
];
|
|
87
|
-
|
|
182
|
+
function row(model) {
|
|
88
183
|
if (!model)
|
|
89
184
|
return undefined;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
185
|
+
return PRICING.find(([pattern]) => pattern.test(model));
|
|
186
|
+
}
|
|
187
|
+
export function pricingFor(model) {
|
|
188
|
+
return row(model)?.[1];
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* A model's price from a row for that model, not a family fallback: undefined
|
|
192
|
+
* for an id the table only knows by family (a new release, a typo like
|
|
193
|
+
* claude-opus-9, gpt-5-codex) and for one it does not know at all. What a
|
|
194
|
+
* report needs to say which models it priced by guess or not at all.
|
|
195
|
+
*/
|
|
196
|
+
export function knownPricingFor(model) {
|
|
197
|
+
const r = row(model);
|
|
198
|
+
return r && !r[2] ? r[1] : undefined;
|
|
199
|
+
}
|
|
200
|
+
/** Whether a model id has a price of its own in the table (see knownPricingFor). */
|
|
201
|
+
export function hasKnownPrice(model) {
|
|
202
|
+
return knownPricingFor(model) !== undefined;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Ids that are never billed, so never "unpriced": Claude Code writes
|
|
206
|
+
* `<synthetic>` on replies it makes itself (an error, an interruption)
|
|
207
|
+
* without calling the API.
|
|
208
|
+
*/
|
|
209
|
+
export function isUnbilledModel(model) {
|
|
210
|
+
return model === "<synthetic>";
|
|
95
211
|
}
|
|
96
212
|
/**
|
|
97
213
|
* A Claude model's price from a row for its own version, not a family
|
|
@@ -100,14 +216,7 @@ export function pricingFor(model) {
|
|
|
100
216
|
* claude-opus-9) gets undefined.
|
|
101
217
|
*/
|
|
102
218
|
export function exactClaudePricingFor(model) {
|
|
103
|
-
|
|
104
|
-
return undefined;
|
|
105
|
-
for (const [pattern, pricing] of PRICING) {
|
|
106
|
-
if (!pattern.test(model))
|
|
107
|
-
continue;
|
|
108
|
-
return CLAUDE_FAMILY.includes(pattern) ? undefined : pricing;
|
|
109
|
-
}
|
|
110
|
-
return undefined;
|
|
219
|
+
return model && /claude/i.test(model) ? knownPricingFor(model) : undefined;
|
|
111
220
|
}
|
|
112
221
|
export function inputCostUsd(tokens, pricing) {
|
|
113
222
|
return (tokens / 1_000_000) * pricing.inputPerM;
|
package/dist/proxy.d.ts
CHANGED
|
@@ -65,7 +65,7 @@ export interface ProxyOptions extends OptimizeOptions {
|
|
|
65
65
|
/** Default request body cap: far above any real request (a 1M-token context is ~4 MB of JSON, images aside). */
|
|
66
66
|
export declare const DEFAULT_MAX_BODY_BYTES: number;
|
|
67
67
|
/** Reported by /health so `autopilot status` can tell an outdated service from a current one. */
|
|
68
|
-
export declare const PROXY_VERSION = "0.
|
|
68
|
+
export declare const PROXY_VERSION = "0.44.0";
|
|
69
69
|
/**
|
|
70
70
|
* Remove a leading `/t/<token>` from a request path, or return undefined when
|
|
71
71
|
* the prefix is absent or the token differs. The comparison is constant time
|
|
@@ -90,6 +90,20 @@ export declare function stripToken(url: string, token: string): string | undefin
|
|
|
90
90
|
*/
|
|
91
91
|
export declare function upstreamFor(url: string, opts: ProxyOptions, headers?: http.IncomingHttpHeaders): string;
|
|
92
92
|
export declare function isGeminiRequest(url: string, headers?: http.IncomingHttpHeaders): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* A request path as the log may show it. Gemini's REST API takes its key in
|
|
95
|
+
* the query (`?key=AIza…`), and the log is a file on disk (autopilot's
|
|
96
|
+
* service writes it beside settings.json): a key there outlives the request.
|
|
97
|
+
*/
|
|
98
|
+
export declare function logUrl(url: string): string;
|
|
99
|
+
/**
|
|
100
|
+
* What to say when the proxy listens beyond this machine with no token:
|
|
101
|
+
* anyone who can reach the address can relay through it (with their own
|
|
102
|
+
* keys) and read /stats. Inside a container that is the point (`--host
|
|
103
|
+
* 0.0.0.0` with the port published to the host only), so it is said, not
|
|
104
|
+
* refused. Undefined on a loopback address or with a token.
|
|
105
|
+
*/
|
|
106
|
+
export declare function exposureWarning(host: string, token?: string): string | undefined;
|
|
93
107
|
/** The model a Gemini request names in its path (…/models/<model>:generateContent). */
|
|
94
108
|
export declare function geminiModelFromUrl(url: string): string | undefined;
|
|
95
109
|
export interface ProxyStats {
|
package/dist/proxy.js
CHANGED
|
@@ -24,7 +24,7 @@ import { withPromptCacheKey } from "./cachekey.js";
|
|
|
24
24
|
/** Default request body cap: far above any real request (a 1M-token context is ~4 MB of JSON, images aside). */
|
|
25
25
|
export const DEFAULT_MAX_BODY_BYTES = 100 * 1024 * 1024;
|
|
26
26
|
/** Reported by /health so `autopilot status` can tell an outdated service from a current one. */
|
|
27
|
-
export const PROXY_VERSION = "0.
|
|
27
|
+
export const PROXY_VERSION = "0.44.0";
|
|
28
28
|
/** Connection-level headers that must not be forwarded. */
|
|
29
29
|
const SKIP_REQUEST_HEADERS = new Set(["host", "content-length", "connection", "transfer-encoding", "accept-encoding", "expect"]);
|
|
30
30
|
const SKIP_RESPONSE_HEADERS = new Set(["content-length", "content-encoding", "transfer-encoding", "connection"]);
|
|
@@ -84,6 +84,30 @@ export function isGeminiRequest(url, headers = {}) {
|
|
|
84
84
|
/^\/(upload\/)?v1(beta|alpha)\d*\//.test(url) ||
|
|
85
85
|
/^\/v1\/[^?]*:(generateContent|streamGenerateContent|countTokens|embedContent|batchEmbedContents)/.test(url));
|
|
86
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* A request path as the log may show it. Gemini's REST API takes its key in
|
|
89
|
+
* the query (`?key=AIza…`), and the log is a file on disk (autopilot's
|
|
90
|
+
* service writes it beside settings.json): a key there outlives the request.
|
|
91
|
+
*/
|
|
92
|
+
export function logUrl(url) {
|
|
93
|
+
return url.replace(/([?&](?:key|api[_-]?key|access_token|token)=)[^&#\s]*/gi, "$1…");
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* What to say when the proxy listens beyond this machine with no token:
|
|
97
|
+
* anyone who can reach the address can relay through it (with their own
|
|
98
|
+
* keys) and read /stats. Inside a container that is the point (`--host
|
|
99
|
+
* 0.0.0.0` with the port published to the host only), so it is said, not
|
|
100
|
+
* refused. Undefined on a loopback address or with a token.
|
|
101
|
+
*/
|
|
102
|
+
export function exposureWarning(host, token) {
|
|
103
|
+
if (token)
|
|
104
|
+
return undefined;
|
|
105
|
+
const h = host.trim().toLowerCase().replace(/^\[|\]$/g, "");
|
|
106
|
+
if (h === "localhost" || h === "::1" || /^127\.\d+\.\d+\.\d+$/.test(h) || /^::ffff:127\./.test(h))
|
|
107
|
+
return undefined;
|
|
108
|
+
return (` WARNING: listening on ${host}, beyond this machine, with no token: anyone who can reach it can send requests through it and read /stats.\n` +
|
|
109
|
+
` Add --token <secret> (or CONTEXT_DOCTOR_PROXY_TOKEN) unless only you can reach this address (a container whose port is published to localhost).`);
|
|
110
|
+
}
|
|
87
111
|
/** The model a Gemini request names in its path (…/models/<model>:generateContent). */
|
|
88
112
|
export function geminiModelFromUrl(url) {
|
|
89
113
|
return /\/models\/([^/:?]+):/.exec(url)?.[1];
|
|
@@ -532,7 +556,7 @@ export function startProxy(opts = {}) {
|
|
|
532
556
|
upstream = new Response(text, { status: upstream.status, statusText: upstream.statusText, headers: upstream.headers });
|
|
533
557
|
}
|
|
534
558
|
}
|
|
535
|
-
console.error(`[context-doctor] ${req.method} ${url} → ${upstream.status} in ${Date.now() - upstreamStart}ms | ${note}` +
|
|
559
|
+
console.error(`[context-doctor] ${req.method} ${logUrl(url)} → ${upstream.status} in ${Date.now() - upstreamStart}ms | ${note}` +
|
|
536
560
|
(stats.tokensSaved > 0 ? ` | session total: ${formatTokens(stats.tokensSaved)} tokens ≈ ${formatUsd(stats.estUsdSaved)} saved` : ""));
|
|
537
561
|
res.statusCode = upstream.status;
|
|
538
562
|
// setHeader per value kept only the last of a repeated header: two
|
|
@@ -589,11 +613,12 @@ export function startProxy(opts = {}) {
|
|
|
589
613
|
}
|
|
590
614
|
catch (e) {
|
|
591
615
|
if (upstreamAbort.signal.aborted) {
|
|
592
|
-
console.error(`[context-doctor] ${req.method} ${url}: client went away; upstream request cancelled`);
|
|
616
|
+
console.error(`[context-doctor] ${req.method} ${logUrl(url)}: client went away; upstream request cancelled`);
|
|
593
617
|
res.destroy();
|
|
594
618
|
return;
|
|
595
619
|
}
|
|
596
|
-
|
|
620
|
+
// fetch's own message can carry the whole upstream URL, query included.
|
|
621
|
+
console.error(`[context-doctor] error on ${logUrl(url)}: ${logUrl(e.message)}`);
|
|
597
622
|
if (res.headersSent) {
|
|
598
623
|
// Upstream failed mid-body. Status and part of the body are already
|
|
599
624
|
// with the client; appending a JSON error and ending cleanly made a
|
|
@@ -604,7 +629,7 @@ export function startProxy(opts = {}) {
|
|
|
604
629
|
}
|
|
605
630
|
res.statusCode = 502;
|
|
606
631
|
res.setHeader("content-type", "application/json");
|
|
607
|
-
res.end(JSON.stringify({ error: `context-doctor proxy: ${e.message}` }));
|
|
632
|
+
res.end(JSON.stringify({ error: `context-doctor proxy: ${logUrl(e.message)}` }));
|
|
608
633
|
}
|
|
609
634
|
});
|
|
610
635
|
// Savings live in memory, so a restart would erase the record the dashboard
|
|
@@ -703,6 +728,9 @@ export function startProxy(opts = {}) {
|
|
|
703
728
|
? ` Autopilot: stale re-runnable tool output is cleared only when the prompt cache is cold; savings are logged here.`
|
|
704
729
|
: ` Every request's context is optimized in flight; savings are logged here.`);
|
|
705
730
|
console.error(` Cumulative savings: http://127.0.0.1:${port}${prefix}/stats`);
|
|
731
|
+
const exposed = exposureWarning(host, opts.token);
|
|
732
|
+
if (exposed)
|
|
733
|
+
console.error(exposed);
|
|
706
734
|
if (opts.token) {
|
|
707
735
|
console.error(` Token required: every path except /health must start with /t/<token>/.`);
|
|
708
736
|
console.error(` Cursor with your own OpenAI key: expose this port on HTTPS (a tunnel), then Settings > Models > OpenAI API Key >`);
|
package/dist/prune.d.ts
CHANGED
|
@@ -85,6 +85,14 @@ export interface PrunePlan {
|
|
|
85
85
|
}
|
|
86
86
|
/** The project's own settings file, where prune writes. */
|
|
87
87
|
export declare function localSettingsPath(cwd: string): string;
|
|
88
|
+
/**
|
|
89
|
+
* Whether Claude Code would start this project `.mcp.json` server without
|
|
90
|
+
* asking: the user approved it (enabledMcpjsonServers, or
|
|
91
|
+
* enableAllProjectMcpServers, in a settings file or ~/.claude.json) and has
|
|
92
|
+
* not switched it off. A `.mcp.json` arrives with a clone, so its commands
|
|
93
|
+
* are a stranger's until then: `overhead --mcp` launches only approved ones.
|
|
94
|
+
*/
|
|
95
|
+
export declare function mcpjsonServerApproved(name: string, cwd?: string, home?: string): boolean;
|
|
88
96
|
export declare function planPrune(days?: number, opts?: {
|
|
89
97
|
home?: string;
|
|
90
98
|
usage?: Map<string, ProjectUse>;
|
package/dist/prune.js
CHANGED
|
@@ -33,7 +33,7 @@ import { dirname, join, resolve } from "node:path";
|
|
|
33
33
|
import { statePath } from "./ledger.js";
|
|
34
34
|
import { listSessions, isClaudeSession } from "./session.js";
|
|
35
35
|
import { rowsOf } from "./scan.js";
|
|
36
|
-
import {
|
|
36
|
+
import { subagentFiles } from "./subagents.js";
|
|
37
37
|
import { claudeMcpConfigs, countMcpRow, serverUses } from "./mcpschema.js";
|
|
38
38
|
import { estimateTokens, formatTokens } from "./tokens.js";
|
|
39
39
|
import { formatUsd } from "./pricing.js";
|
|
@@ -148,13 +148,9 @@ export function projectUsage(days = 30, paths, now = Date.now()) {
|
|
|
148
148
|
};
|
|
149
149
|
try {
|
|
150
150
|
scan(path);
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
catch { /* none */ }
|
|
156
|
-
for (const a of agents)
|
|
157
|
-
scan(join(subagentDir(path), a));
|
|
151
|
+
// Subagents and workflow agents (subagents/workflows/<run>/) use servers too.
|
|
152
|
+
for (const a of subagentFiles(path))
|
|
153
|
+
scan(a.file);
|
|
158
154
|
}
|
|
159
155
|
catch {
|
|
160
156
|
continue;
|
|
@@ -280,7 +276,22 @@ function offFor(cwd, home) {
|
|
|
280
276
|
if (entry?.enableAllProjectMcpServers === true)
|
|
281
277
|
all = true;
|
|
282
278
|
}
|
|
283
|
-
return {
|
|
279
|
+
return {
|
|
280
|
+
off,
|
|
281
|
+
mcpjsonAllowlist: all ? undefined : allow,
|
|
282
|
+
// Approved in so many words: a server nobody said yes to is one Claude Code asks about first.
|
|
283
|
+
mcpjsonApproved: (name) => !off.has(`mcp:${name}`) && (all || (allow?.has(name) ?? false)),
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Whether Claude Code would start this project `.mcp.json` server without
|
|
288
|
+
* asking: the user approved it (enabledMcpjsonServers, or
|
|
289
|
+
* enableAllProjectMcpServers, in a settings file or ~/.claude.json) and has
|
|
290
|
+
* not switched it off. A `.mcp.json` arrives with a clone, so its commands
|
|
291
|
+
* are a stranger's until then: `overhead --mcp` launches only approved ones.
|
|
292
|
+
*/
|
|
293
|
+
export function mcpjsonServerApproved(name, cwd = process.cwd(), home = homedir()) {
|
|
294
|
+
return offFor(cwd, home).mcpjsonApproved(name);
|
|
284
295
|
}
|
|
285
296
|
/** context-doctor's own server: its standing rules work with no calls at all. */
|
|
286
297
|
const OURS = /^context-doctor$/;
|
package/dist/savings.js
CHANGED
|
@@ -20,6 +20,7 @@ import { CACHE_WRITE_1H, CACHE_WRITE_5M, cacheWriteSplit, pricingFor, usageCost,
|
|
|
20
20
|
import { estimateTokens, formatTokens, realModel } from "./tokens.js";
|
|
21
21
|
import { withInvocation } from "./invocation.js";
|
|
22
22
|
import { sessionsLabel } from "./compactwindow.js";
|
|
23
|
+
import { projectFromDir } from "./spend.js";
|
|
23
24
|
/** System prompt and tool schemas: sent on every request, identical in both arms. */
|
|
24
25
|
const FIXED_TOKENS = 54_000;
|
|
25
26
|
const CLAUDE_CODE_TTL_MS = 3_600_000;
|
|
@@ -285,7 +286,7 @@ function settleReplay(path, rows, since, runRows, coldRows, replay) {
|
|
|
285
286
|
const entrypoint = end?.entrypoint;
|
|
286
287
|
return {
|
|
287
288
|
path,
|
|
288
|
-
project: dir
|
|
289
|
+
project: projectFromDir(dir),
|
|
289
290
|
model: end?.model,
|
|
290
291
|
requests,
|
|
291
292
|
billedWeighted: billed,
|