context-doctor 0.43.0 → 0.45.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 +4 -2
- package/dist/budget.d.ts +23 -3
- package/dist/budget.js +184 -50
- package/dist/cache.js +5 -4
- package/dist/cachemisses.js +1 -1
- package/dist/cachettl.d.ts +5 -1
- package/dist/cachettl.js +16 -29
- package/dist/ci.js +18 -2
- package/dist/cli.js +16 -12
- package/dist/codexcompact.d.ts +24 -3
- package/dist/codexcompact.js +221 -48
- package/dist/coldresume.js +16 -8
- package/dist/compactwindow.js +14 -9
- package/dist/cursor.d.ts +10 -0
- package/dist/cursor.js +20 -0
- package/dist/doctor.d.ts +9 -0
- package/dist/doctor.js +52 -0
- package/dist/extract.d.ts +2 -2
- package/dist/extract.js +14 -3
- 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/httpguard.d.ts +9 -1
- package/dist/httpguard.js +5 -4
- package/dist/install.js +56 -19
- package/dist/lens.js +7 -7
- package/dist/limits.d.ts +17 -4
- package/dist/limits.js +41 -29
- package/dist/mcp.js +63 -63
- package/dist/mcpclient.js +19 -19
- package/dist/mcpschema.js +10 -12
- package/dist/overhead.d.ts +7 -2
- package/dist/overhead.js +11 -3
- package/dist/pack.js +87 -23
- package/dist/pricing.d.ts +125 -6
- package/dist/pricing.js +304 -59
- package/dist/proxy.d.ts +26 -1
- package/dist/proxy.js +45 -5
- package/dist/prune.d.ts +8 -0
- package/dist/prune.js +73 -10
- package/dist/savings.js +17 -9
- package/dist/scan.d.ts +7 -1
- package/dist/scan.js +19 -1
- package/dist/sessionprice.d.ts +9 -2
- package/dist/sessionprice.js +95 -36
- package/dist/settingsedit.js +3 -2
- package/dist/spend.d.ts +75 -10
- package/dist/spend.js +279 -37
- package/dist/statusline.d.ts +10 -2
- package/dist/statusline.js +17 -8
- package/dist/subagentmodel.d.ts +2 -2
- package/dist/subagentmodel.js +42 -25
- package/dist/subagentpay.d.ts +17 -0
- package/dist/subagentpay.js +41 -2
- package/dist/subagents.d.ts +24 -0
- package/dist/subagents.js +93 -27
- package/dist/tasks.js +9 -6
- package/dist/tooloutput.d.ts +2 -0
- package/dist/tooloutput.js +16 -5
- 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";
|
|
@@ -95,20 +95,22 @@ export function claudeMcpConfigs(cwd = process.cwd(), home = homedir()) {
|
|
|
95
95
|
out.set(name, { name, scope, command: c.command, args: c.args, env: c.env, url: c.url, type: c.type });
|
|
96
96
|
}
|
|
97
97
|
};
|
|
98
|
+
let cfg;
|
|
98
99
|
try {
|
|
99
|
-
|
|
100
|
-
addAll(cfg.mcpServers, "user");
|
|
101
|
-
addAll(cfg.projects?.[resolve(cwd)]?.mcpServers, "project");
|
|
100
|
+
cfg = JSON.parse(readFileSync(claudeJsonPath(home), "utf8"));
|
|
102
101
|
}
|
|
103
102
|
catch {
|
|
104
103
|
/* absent */
|
|
105
104
|
}
|
|
105
|
+
// A name in several scopes is Claude Code's local one, then the .mcp.json one, then the user's.
|
|
106
|
+
addAll(cfg?.mcpServers, "user");
|
|
106
107
|
try {
|
|
107
108
|
addAll(JSON.parse(readFileSync(join(cwd, ".mcp.json"), "utf8")).mcpServers, ".mcp.json");
|
|
108
109
|
}
|
|
109
110
|
catch {
|
|
110
111
|
/* absent */
|
|
111
112
|
}
|
|
113
|
+
addAll(cfg?.projects?.[resolve(cwd)]?.mcpServers, "project");
|
|
112
114
|
return [...out.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
113
115
|
}
|
|
114
116
|
export const MCP_ROWS = {
|
|
@@ -185,14 +187,10 @@ export function mcpUsage(days = 30, paths, onProgress) {
|
|
|
185
187
|
}
|
|
186
188
|
};
|
|
187
189
|
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) {
|
|
190
|
+
// Subagents and workflow agents call MCP tools too.
|
|
191
|
+
for (const a of subagentFiles(path)) {
|
|
194
192
|
try {
|
|
195
|
-
scan(
|
|
193
|
+
scan(a.file);
|
|
196
194
|
}
|
|
197
195
|
catch { /* one unreadable subagent must not sink the report */ }
|
|
198
196
|
}
|
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, claudeJsonPath } 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. */
|
|
@@ -358,10 +360,16 @@ export function renderPack(r, { outlineLimit = 60 } = {}) {
|
|
|
358
360
|
}
|
|
359
361
|
const SKIP_DIRS = new Set(["node_modules", ".git", "dist", "build", ".next", "target", "__pycache__", ".venv", "venv", "vendor"]);
|
|
360
362
|
export const PACK_LIMITS = { files: 500, fileBytes: 5 * 1024 * 1024, totalBytes: 50 * 1024 * 1024 };
|
|
363
|
+
/**
|
|
364
|
+
* A folder's own .git/config can name a command for `git ls-files` to run
|
|
365
|
+
* (core.fsmonitor): an unpacked archive or a downloaded project brings its
|
|
366
|
+
* .git with it, and packing it must not run anything.
|
|
367
|
+
*/
|
|
368
|
+
const SAFE_GIT = ["-c", "core.fsmonitor=false"];
|
|
361
369
|
/** Files git would consider part of the repository under `dir` (relative to it), or undefined outside git. */
|
|
362
370
|
function gitFiles(dir) {
|
|
363
371
|
try {
|
|
364
|
-
const r = spawnSync("git", ["-C", dir, "ls-files", "-z", "--cached", "--others", "--exclude-standard"], { encoding: "utf8", maxBuffer: 64 * 1024 * 1024, timeout: 30_000 });
|
|
372
|
+
const r = spawnSync("git", [...SAFE_GIT, "-C", dir, "ls-files", "-z", "--cached", "--others", "--exclude-standard"], { encoding: "utf8", maxBuffer: 64 * 1024 * 1024, timeout: 30_000 });
|
|
365
373
|
if (r.status !== 0 || typeof r.stdout !== "string")
|
|
366
374
|
return undefined;
|
|
367
375
|
// --cached lists files deleted from the work tree too; only what exists is read.
|
|
@@ -374,7 +382,7 @@ function gitFiles(dir) {
|
|
|
374
382
|
/** Git ignores something under `dir`: why a folder that has files can list none. */
|
|
375
383
|
function gitIgnoresSome(dir) {
|
|
376
384
|
// --directory names an ignored folder once instead of every file in it.
|
|
377
|
-
const r = spawnSync("git", ["-C", dir, "ls-files", "-z", "--others", "--ignored", "--exclude-standard", "--directory"], { encoding: "utf8", maxBuffer: 64 * 1024 * 1024, timeout: 30_000 });
|
|
385
|
+
const r = spawnSync("git", [...SAFE_GIT, "-C", dir, "ls-files", "-z", "--others", "--ignored", "--exclude-standard", "--directory"], { encoding: "utf8", maxBuffer: 64 * 1024 * 1024, timeout: 30_000 });
|
|
378
386
|
return r.status === 0 && typeof r.stdout === "string" && r.stdout.length > 0;
|
|
379
387
|
}
|
|
380
388
|
/** `inner` is `root` itself or somewhere under it. */
|
|
@@ -389,7 +397,19 @@ function within(root, inner) {
|
|
|
389
397
|
* token verbatim. They are skipped even when named outright or tracked by
|
|
390
398
|
* git; only the CLI's --include-secrets packs them.
|
|
391
399
|
*/
|
|
392
|
-
const SECRET_NAMES = new Set([
|
|
400
|
+
const SECRET_NAMES = new Set([
|
|
401
|
+
".npmrc", ".pypirc", ".netrc", "_netrc", ".git-credentials", ".pgpass", ".htpasswd", ".vault-token",
|
|
402
|
+
// The agents' own sign-ins, which an injected instruction in a packed doc
|
|
403
|
+
// could otherwise ask for by name: Claude Code's OAuth tokens (Linux,
|
|
404
|
+
// Windows), Gemini CLI's, Terraform's.
|
|
405
|
+
".credentials.json", "oauth_creds.json", "credentials.tfrc.json",
|
|
406
|
+
]);
|
|
407
|
+
/** A file name that holds credentials inside one folder only: Codex's sign-in, Cargo's and RubyGems' tokens. */
|
|
408
|
+
const SECRET_IN_DIR = [
|
|
409
|
+
[".codex", ["auth.json"]],
|
|
410
|
+
[".cargo", ["credentials", "credentials.toml"]],
|
|
411
|
+
[".gem", ["credentials"]],
|
|
412
|
+
];
|
|
393
413
|
const SECRET_EXT = new Set([".pem", ".key", ".p12", ".pfx", ".keystore", ".jks"]);
|
|
394
414
|
/** Why `path` looks like a secrets file, or undefined when it does not. */
|
|
395
415
|
export function secretFileReason(path) {
|
|
@@ -405,8 +425,11 @@ export function secretFileReason(path) {
|
|
|
405
425
|
if (SECRET_EXT.has(extname(lower)))
|
|
406
426
|
return `a key or certificate store (${extname(lower)})`;
|
|
407
427
|
const parts = path.split(/[\\/]+/);
|
|
408
|
-
|
|
428
|
+
const parent = (parts[parts.length - 2] ?? "").toLowerCase();
|
|
429
|
+
if (lower === "credentials" && parent === ".aws")
|
|
409
430
|
return "AWS credentials";
|
|
431
|
+
if (SECRET_IN_DIR.some(([dir, files]) => dir === parent && files.includes(lower)))
|
|
432
|
+
return `a credentials file (${parent}/${name})`;
|
|
410
433
|
return undefined;
|
|
411
434
|
}
|
|
412
435
|
/**
|
|
@@ -416,24 +439,65 @@ export function secretFileReason(path) {
|
|
|
416
439
|
function sensitiveDirs() {
|
|
417
440
|
const home = homedir();
|
|
418
441
|
const dirs = [
|
|
419
|
-
...[".ssh", ".aws", ".gnupg", ".kube", ".docker", ".azure", join(".config", "gcloud"), join("Library", "Keychains"), ".password-store"].map((d) => join(home, d)),
|
|
442
|
+
...[".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)),
|
|
443
|
+
// Where CLAUDE_CONFIG_DIR and CODEX_HOME put the agents' sign-ins.
|
|
444
|
+
join(claudeDir(), ".credentials.json"), join(codexDir(), "auth.json"),
|
|
420
445
|
"/etc/shadow", "/etc/gshadow", "/etc/sudoers", "/etc/master.passwd", "/etc/ssh",
|
|
421
446
|
];
|
|
422
447
|
// Compared against real paths: /etc is /private/etc on macOS, and a home
|
|
423
448
|
// under /var/folders is really /private/var/folders.
|
|
424
|
-
|
|
449
|
+
return [...new Set([...dirs, ...dirs.map(realOf)])];
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* The agents' own MCP and settings files, in the home folder (and where
|
|
453
|
+
* CLAUDE_CONFIG_DIR, CODEX_HOME and COPILOT_HOME put them): each MCP server's
|
|
454
|
+
* `env` there commonly holds an API key, and settings.json an `env` of its
|
|
455
|
+
* own. Refused unless secrets are allowed (never over MCP). A project's own
|
|
456
|
+
* `.mcp.json` is not: it is read for good reasons, and it rides in the
|
|
457
|
+
* repository, where a key does not belong.
|
|
458
|
+
*/
|
|
459
|
+
function agentConfigFiles() {
|
|
460
|
+
const home = homedir();
|
|
461
|
+
const files = [
|
|
462
|
+
claudeJsonPath(), join(home, ".claude.json"),
|
|
463
|
+
...[claudeDir(), join(home, ".claude")].flatMap((d) => [join(d, "settings.json"), join(d, "settings.local.json")]),
|
|
464
|
+
join(home, ".cursor", "mcp.json"),
|
|
465
|
+
join(codexDir(), "config.toml"), join(home, ".codex", "config.toml"),
|
|
466
|
+
join(home, ".gemini", "settings.json"),
|
|
467
|
+
// Antigravity: the shared config folder's file, and the app's own from before it.
|
|
468
|
+
join(home, ".gemini", "config", "mcp_config.json"), join(home, ".gemini", "antigravity", "mcp_config.json"),
|
|
469
|
+
// Claude Desktop on macOS, Windows and Linux.
|
|
470
|
+
join(home, "Library", "Application Support", "Claude", "claude_desktop_config.json"),
|
|
471
|
+
join(process.env.APPDATA || join(home, "AppData", "Roaming"), "Claude", "claude_desktop_config.json"),
|
|
472
|
+
join(home, ".config", "Claude", "claude_desktop_config.json"),
|
|
473
|
+
join(process.env.COPILOT_HOME || join(home, ".copilot"), "mcp-config.json"), join(home, ".copilot", "mcp-config.json"),
|
|
474
|
+
];
|
|
475
|
+
return [...new Set([...files, ...files.map(realOf)])];
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* A path's real spelling: links resolved and, where the system can say,
|
|
479
|
+
* the case on disk and Windows' long names (`realpathSync.native`), so
|
|
480
|
+
* ~/.SSH and C:\Users\RUNNER~1 are the folders they name.
|
|
481
|
+
*/
|
|
482
|
+
function realOf(p) {
|
|
483
|
+
for (const real of [realpathSync.native, realpathSync]) {
|
|
425
484
|
try {
|
|
426
|
-
return
|
|
485
|
+
return real(p);
|
|
427
486
|
}
|
|
428
487
|
catch {
|
|
429
|
-
|
|
488
|
+
/* the next */
|
|
430
489
|
}
|
|
431
|
-
}
|
|
432
|
-
return
|
|
490
|
+
}
|
|
491
|
+
return resolve(p);
|
|
433
492
|
}
|
|
434
|
-
/**
|
|
493
|
+
/**
|
|
494
|
+
* The denylisted folder `path` (a real path) sits in, if any. macOS and
|
|
495
|
+
* Windows disks ignore case by default: ~/.AWS/credentials is
|
|
496
|
+
* ~/.aws/credentials there, whatever spelling the path arrived in.
|
|
497
|
+
*/
|
|
435
498
|
function inSensitiveDir(path, dirs) {
|
|
436
|
-
|
|
499
|
+
const fold = process.platform === "darwin" || process.platform === "win32" ? (s) => s.toLowerCase() : (s) => s;
|
|
500
|
+
return dirs.find((d) => within(fold(d), fold(path)));
|
|
437
501
|
}
|
|
438
502
|
/** A short reason for a filesystem error: EACCES reads as "permission denied", not a stack trace. */
|
|
439
503
|
function fsReason(e) {
|
|
@@ -471,6 +535,7 @@ export function readSources(paths, cwdOrOptions = process.cwd()) {
|
|
|
471
535
|
const includeSecrets = options.includeSecrets === true;
|
|
472
536
|
const secretsHint = options.secretsHint ?? "";
|
|
473
537
|
const denied = includeSecrets ? [] : sensitiveDirs();
|
|
538
|
+
const deniedConfigs = includeSecrets ? [] : agentConfigFiles();
|
|
474
539
|
const sources = [];
|
|
475
540
|
const skipped = [];
|
|
476
541
|
let bytes = 0;
|
|
@@ -483,14 +548,6 @@ export function readSources(paths, cwdOrOptions = process.cwd()) {
|
|
|
483
548
|
let hidden = 0;
|
|
484
549
|
// Whether the folder being walked was listed by git (hidden tracked files are source there).
|
|
485
550
|
let insideGit = false;
|
|
486
|
-
const realOf = (p) => {
|
|
487
|
-
try {
|
|
488
|
-
return realpathSync(p);
|
|
489
|
-
}
|
|
490
|
-
catch {
|
|
491
|
-
return resolve(p);
|
|
492
|
-
}
|
|
493
|
-
};
|
|
494
551
|
const visit = (p, top) => {
|
|
495
552
|
if (sources.length >= PACK_LIMITS.files) {
|
|
496
553
|
if (top || skipped.length < 20)
|
|
@@ -508,7 +565,7 @@ export function readSources(paths, cwdOrOptions = process.cwd()) {
|
|
|
508
565
|
if (st.isSymbolicLink()) {
|
|
509
566
|
let target;
|
|
510
567
|
try {
|
|
511
|
-
target = realpathSync(p);
|
|
568
|
+
target = realOf(realpathSync(p));
|
|
512
569
|
}
|
|
513
570
|
catch {
|
|
514
571
|
return; // dangling: nothing to read
|
|
@@ -518,13 +575,19 @@ export function readSources(paths, cwdOrOptions = process.cwd()) {
|
|
|
518
575
|
return;
|
|
519
576
|
}
|
|
520
577
|
if (denied.length > 0) {
|
|
521
|
-
const
|
|
578
|
+
const real = realOf(p);
|
|
579
|
+
const dir = inSensitiveDir(real, denied);
|
|
522
580
|
if (dir) {
|
|
523
581
|
// Once per named path: a folder of keys is one refusal, not one per key.
|
|
524
582
|
if (top)
|
|
525
583
|
skipped.push(`${p}: refused, ${dir} holds credentials${secretsHint}`);
|
|
526
584
|
return;
|
|
527
585
|
}
|
|
586
|
+
const config = inSensitiveDir(real, deniedConfigs);
|
|
587
|
+
if (config) {
|
|
588
|
+
skipped.push(`${p}: refused, ${config} can hold API keys (an MCP server's env)${secretsHint}`);
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
528
591
|
}
|
|
529
592
|
if (st.isDirectory()) {
|
|
530
593
|
const name = basename(p);
|
|
@@ -568,7 +631,8 @@ export function readSources(paths, cwdOrOptions = process.cwd()) {
|
|
|
568
631
|
return;
|
|
569
632
|
}
|
|
570
633
|
if (!includeSecrets) {
|
|
571
|
-
|
|
634
|
+
// The link's name and its target's: notes.md pointing at an .env is an .env.
|
|
635
|
+
const why = secretFileReason(p) ?? secretFileReason(realOf(p));
|
|
572
636
|
if (why) {
|
|
573
637
|
skipped.push(`${p}: ${why}, likely holding secrets; not packed${secretsHint}`);
|
|
574
638
|
return;
|
package/dist/pricing.d.ts
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Per-model pricing for cost estimation, USD per million tokens.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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. What a request recorded can bill it differently (fast
|
|
7
|
+
* mode, US-only inference, a long prompt's tier, web searches) and a row's
|
|
8
|
+
* price can end on a known day: requestCost applies all of it, per request,
|
|
9
|
+
* from the row's billing options. Prices drift, so all cost output is
|
|
7
10
|
* labeled as an estimate. One table, one file, easy to update: PRs welcome
|
|
8
11
|
* when prices change.
|
|
12
|
+
*
|
|
13
|
+
* A row names one model (a "known" price, see knownPricingFor) unless it is
|
|
14
|
+
* listed in FALLBACKS: those price ids the table does not know by version,
|
|
15
|
+
* at a family's price, so a new release still gets a number. A model a
|
|
16
|
+
* provider prices only per minute, per image or not at all has no row.
|
|
9
17
|
*/
|
|
10
18
|
export interface ModelPricing {
|
|
11
19
|
/** USD per 1M input tokens. */
|
|
@@ -27,7 +35,23 @@ export declare const CACHE_WRITE_1H = 2;
|
|
|
27
35
|
*/
|
|
28
36
|
export declare const CACHE_WRITE_OPENAI_30M = 1.25;
|
|
29
37
|
export declare const CACHE_WRITE_OPENAI_12H = 2.5;
|
|
38
|
+
/** A model's list row, as the page lists it today (no tier, mode or date applied). */
|
|
30
39
|
export declare function pricingFor(model?: string): ModelPricing | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* A model's price from a row for that model, not a family fallback: undefined
|
|
42
|
+
* for an id the table only knows by family (a new release, a typo like
|
|
43
|
+
* claude-opus-9, gpt-5-codex) and for one it does not know at all. What a
|
|
44
|
+
* report needs to say which models it priced by guess or not at all.
|
|
45
|
+
*/
|
|
46
|
+
export declare function knownPricingFor(model?: string): ModelPricing | undefined;
|
|
47
|
+
/** Whether a model id has a price of its own in the table (see knownPricingFor). */
|
|
48
|
+
export declare function hasKnownPrice(model?: string): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Ids that are never billed, so never "unpriced": Claude Code writes
|
|
51
|
+
* `<synthetic>` on replies it makes itself (an error, an interruption)
|
|
52
|
+
* without calling the API.
|
|
53
|
+
*/
|
|
54
|
+
export declare function isUnbilledModel(model?: string): boolean;
|
|
31
55
|
/**
|
|
32
56
|
* A Claude model's price from a row for its own version, not a family
|
|
33
57
|
* fallback: what a command that caps spending needs (`ab --budget`). An id
|
|
@@ -51,6 +75,16 @@ export interface RecordedUsage {
|
|
|
51
75
|
ephemeral_1h_input_tokens?: unknown;
|
|
52
76
|
ttl_12h_input_tokens?: unknown;
|
|
53
77
|
} | null;
|
|
78
|
+
/** Anthropic: "fast" for a fast-mode request ("standard" otherwise). */
|
|
79
|
+
speed?: unknown;
|
|
80
|
+
/** Anthropic: "us" for US-only inference ("global", "", "not_available" otherwise). */
|
|
81
|
+
inference_geo?: unknown;
|
|
82
|
+
/** Anthropic: server-side tool uses billed per use. */
|
|
83
|
+
server_tool_use?: {
|
|
84
|
+
web_search_requests?: unknown;
|
|
85
|
+
web_fetch_requests?: unknown;
|
|
86
|
+
code_execution_requests?: unknown;
|
|
87
|
+
} | null;
|
|
54
88
|
}
|
|
55
89
|
export interface UsageCost {
|
|
56
90
|
/** Uncached input. */
|
|
@@ -84,11 +118,96 @@ export declare function cacheWriteSplit(usage: RecordedUsage | undefined | null)
|
|
|
84
118
|
*/
|
|
85
119
|
export declare function writeMultiplier(fiveMinute: number, oneHour: number, twelveHour?: number): number;
|
|
86
120
|
/**
|
|
87
|
-
*
|
|
88
|
-
* TTL, cache reads, output. The
|
|
89
|
-
*
|
|
121
|
+
* Recorded usage at given rates: uncached input, cache writes priced by
|
|
122
|
+
* TTL, cache reads, output. The rates a request was billed at (its tier,
|
|
123
|
+
* fast mode, US-only, its date) are requestCost's to decide.
|
|
90
124
|
*/
|
|
91
125
|
export declare function usageCost(usage: RecordedUsage | undefined | null, pricing: ModelPricing): UsageCost;
|
|
126
|
+
/** US-only inference on Claude 4.6 and later: 1.1x on every token category (Anthropic, "Data residency pricing", read 2026-11-08). */
|
|
127
|
+
export declare const US_ONLY_MULTIPLIER = 1.1;
|
|
128
|
+
/**
|
|
129
|
+
* Claude's web search tool: $10 per 1,000 searches, on top of its tokens
|
|
130
|
+
* (Anthropic, "Web search tool", read 2026-11-08). A token price, so not
|
|
131
|
+
* under the US-only multiplier. Web fetch has no charge beyond its tokens;
|
|
132
|
+
* code execution bills container time (1,550 free hours a month, then $0.05
|
|
133
|
+
* an hour), which usage does not record per request: not modelled.
|
|
134
|
+
*/
|
|
135
|
+
export declare const WEB_SEARCH_USD: number;
|
|
136
|
+
/** The tokens a request's prompt holds: uncached input, cache reads and cache writes (what a long-prompt tier counts). */
|
|
137
|
+
export declare function promptTokens(usage: RecordedUsage | undefined | null): number;
|
|
138
|
+
/**
|
|
139
|
+
* The rates a model's requests bill at, from its row and what the request
|
|
140
|
+
* recorded: `rates` for a prompt up to `over` tokens, `longRates` beyond
|
|
141
|
+
* (no tier: `over` absent). Fast mode replaces the rates (its price holds
|
|
142
|
+
* across the full context window); US-only scales them. A request on or
|
|
143
|
+
* after the day its row's price changes (`changedOn`) is priced at the
|
|
144
|
+
* price the page said would follow, or the old one when it said none: an
|
|
145
|
+
* estimate either way (a scheduled price can be called off: Sonnet 5's was).
|
|
146
|
+
*/
|
|
147
|
+
export interface RateCard {
|
|
148
|
+
rates: ModelPricing;
|
|
149
|
+
over?: number;
|
|
150
|
+
longRates?: ModelPricing;
|
|
151
|
+
/** The list row's own rates, before tier, fast mode and US-only: what the modifiers are measured from. */
|
|
152
|
+
list: ModelPricing;
|
|
153
|
+
/** Fast mode's rates applied. */
|
|
154
|
+
fast?: true;
|
|
155
|
+
/** US-only's 1.1x applied. */
|
|
156
|
+
geo?: true;
|
|
157
|
+
/** Priced by family or past its row's date: an estimate. */
|
|
158
|
+
estimated?: true;
|
|
159
|
+
/** "YYYY-MM-DD": the row's price changed on this day, before the request. */
|
|
160
|
+
changedOn?: string;
|
|
161
|
+
/** Web searches bill per use (Claude). */
|
|
162
|
+
webSearch?: true;
|
|
163
|
+
}
|
|
164
|
+
/** The rate card for one of `model`'s requests at time `at`, with the modifiers its usage records. Undefined for a model with no price. */
|
|
165
|
+
export declare function rateCard(model: string | undefined, usage?: RecordedUsage | null, at?: number): RateCard | undefined;
|
|
166
|
+
/** A card's rates for a prompt of `prompt` tokens: its long tier's past `over`. */
|
|
167
|
+
export declare function ratesAt(card: RateCard, prompt: number): ModelPricing;
|
|
168
|
+
/**
|
|
169
|
+
* What a request's billing modifiers added to its list-row price, in USD:
|
|
170
|
+
* fast mode, US-only inference, a long-prompt tier, and the web searches it
|
|
171
|
+
* ran (`webSearches` of them, `webSearchUsd`).
|
|
172
|
+
*/
|
|
173
|
+
export interface Modifiers {
|
|
174
|
+
fastUsd: number;
|
|
175
|
+
geoUsd: number;
|
|
176
|
+
longUsd: number;
|
|
177
|
+
webSearchUsd: number;
|
|
178
|
+
webSearches: number;
|
|
179
|
+
}
|
|
180
|
+
export declare const NO_MODIFIERS: Readonly<Modifiers>;
|
|
181
|
+
export interface RequestCost extends UsageCost {
|
|
182
|
+
/** The rates its tokens were billed at (the parts above); `totalUsd` adds the web searches. */
|
|
183
|
+
rates: ModelPricing;
|
|
184
|
+
modifiers: Modifiers;
|
|
185
|
+
/** Priced by family, or past the day its row's price changed: an estimate. */
|
|
186
|
+
estimated?: true;
|
|
187
|
+
/** "YYYY-MM-DD": its row's price changed on this day, before the request. */
|
|
188
|
+
changedOn?: string;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* What one recorded request cost, as billed: its model's row at the time it
|
|
192
|
+
* ran, its prompt's tier, fast mode, US-only inference, cache writes by TTL,
|
|
193
|
+
* and per-use tool fees. The one place a request's price is decided, so
|
|
194
|
+
* every report agrees with the others and with the bill. `at`: when it ran.
|
|
195
|
+
* Undefined for a model with no price.
|
|
196
|
+
*/
|
|
197
|
+
export declare function requestCost(model: string | undefined, usage: RecordedUsage | undefined | null, at?: number): RequestCost | undefined;
|
|
198
|
+
/** `a` plus `b`, part by part. */
|
|
199
|
+
export declare function addModifiers(a: Modifiers, b: Readonly<Modifiers>): Modifiers;
|
|
200
|
+
/**
|
|
201
|
+
* When a model's price in the table stops being its list price: the day
|
|
202
|
+
* (YYYY-MM-DD) and, when the page said, the price from then. Undefined for
|
|
203
|
+
* a row with no end date. What `doctor` and the budget say once it has passed.
|
|
204
|
+
*/
|
|
205
|
+
export declare function priceChange(model?: string): {
|
|
206
|
+
on: string;
|
|
207
|
+
then?: ModelPricing;
|
|
208
|
+
} | undefined;
|
|
209
|
+
/** "gemini-4-argon's price changed on 2026-12-01; a newer context-doctor knows the new one": said for each model priced past its row's date. */
|
|
210
|
+
export declare function priceChangedText(models: Array<[model: string, on: string]>): string;
|
|
92
211
|
/**
|
|
93
212
|
* OpenAI usage, in any of its shapes, as RecordedUsage: Responses
|
|
94
213
|
* (`input_tokens`, `input_tokens_details.cached_tokens`, `cache_write_tokens`
|