context-doctor 0.47.0 → 0.48.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.
@@ -1,4 +1,9 @@
1
1
  /**
2
+ * The models a source names, to check each has a price of its own. Claude's
3
+ * below; OpenAI's and Google's price pages, Codex's model catalog and Gemini
4
+ * CLI's model list after them (openaiPageIds...), and the table's own dated
5
+ * rows (datedRows, dueRows). All read by scripts/check-models.mjs.
6
+ *
2
7
  * The Claude models a text names, to check each has a price of its own
3
8
  * (pricing.ts hasKnownPrice) before a user runs it: Claude Code ships a
4
9
  * model days before a context-doctor release (2.1.322 made Fable 5.2 the
@@ -22,3 +27,56 @@ export declare const UNPRICED_ON_PURPOSE: Record<string, string>;
22
27
  export declare function claudeModelIds(text: string): string[];
23
28
  /** The Claude models `text` names that have no price of their own and no reason to lack one. */
24
29
  export declare function unpricedClaudeIds(text: string): string[];
30
+ /** The ids in `ids` that have no price of their own and no reason to lack one. */
31
+ export declare function unpriced(ids: string[]): string[];
32
+ /**
33
+ * The models OpenAI's price page (developers.openai.com/api/docs/pricing,
34
+ * its .md) lists in its text tables: each table row's model cell (the first,
35
+ * or the second where the first is a category), the context-length notes
36
+ * dropped. Tables with a Modality or Use case column (images, audio,
37
+ * transcription) and the tools table are not models priced by the token.
38
+ */
39
+ export declare function openaiPageIds(markdown: string): string[];
40
+ /**
41
+ * The models Google's price page (ai.google.dev/gemini-api/docs/pricing, its
42
+ * .md.txt) prices: each section's model id line (`*[\`gemini-4-argon\`](...)*`),
43
+ * the text models only.
44
+ */
45
+ export declare function googlePageIds(markdown: string): string[];
46
+ /**
47
+ * The models Codex offers (its models catalog, codex-rs/models-manager/
48
+ * models.json): `listed` are the ones its picker shows, `hidden` the rest
49
+ * (internal and trusted-access ids, which the price page may not name).
50
+ */
51
+ export declare function codexModelIds(json: string): {
52
+ listed: string[];
53
+ hidden: string[];
54
+ };
55
+ /**
56
+ * The Gemini models Gemini CLI names (packages/core/src/config/models.ts):
57
+ * every quoted full model id (a version and a Pro/Flash/Flash-Lite name),
58
+ * not family prefixes like 'gemini-3' or the embedding model.
59
+ */
60
+ export declare function geminiCliIds(source: string): string[];
61
+ /** A dated pricing.ts row: the model it prices, the day its price changes, and whether the page gave what follows. */
62
+ export interface DatedRow {
63
+ id: string;
64
+ changes: string;
65
+ successor: boolean;
66
+ }
67
+ /**
68
+ * The rows of pricing.ts's table (its source, `src/pricing.ts`) whose price
69
+ * ends on a known day (`changes`), each with whether the page said what
70
+ * follows (`then`, or `routes`: billed as another model from that day).
71
+ * Throws on a dated row it cannot name, so the check cannot pass by missing one.
72
+ */
73
+ export declare function datedRows(pricingSource: string): DatedRow[];
74
+ /**
75
+ * The dated rows with no successor price whose last day at that price (the
76
+ * day before `changes`) is at most `days` days after `today`, or already
77
+ * past: from then, every install prices that model as an estimate, so the
78
+ * page needs reading again (and the successor price adding, once published).
79
+ */
80
+ export declare function dueRows(rows: DatedRow[], today: string, days?: number): Array<DatedRow & {
81
+ daysLeft: number;
82
+ }>;
package/dist/modelids.js CHANGED
@@ -1,4 +1,9 @@
1
1
  /**
2
+ * The models a source names, to check each has a price of its own. Claude's
3
+ * below; OpenAI's and Google's price pages, Codex's model catalog and Gemini
4
+ * CLI's model list after them (openaiPageIds...), and the table's own dated
5
+ * rows (datedRows, dueRows). All read by scripts/check-models.mjs.
6
+ *
2
7
  * The Claude models a text names, to check each has a price of its own
3
8
  * (pricing.ts hasKnownPrice) before a user runs it: Claude Code ships a
4
9
  * model days before a context-doctor release (2.1.322 made Fable 5.2 the
@@ -36,6 +41,10 @@ const family = (word, major) => {
36
41
  /** Ids that have no price on purpose, with the reason. */
37
42
  export const UNPRICED_ON_PURPOSE = {
38
43
  "claude-mythos-preview": "no list price on the page; priced by the Fable/Mythos family row as an estimate",
44
+ // Gemini CLI names these (packages/core/src/config/models.ts, read
45
+ // 2026-11-14); Google's price page does not, so there is no price to copy.
46
+ "gemini-3-pro-preview": "Gemini CLI's preview model, not on Google's price page (2026-11-14); the 3.x Pro fallback prices it at 3.1 Pro's rates, an estimate",
47
+ "gemini-3.5-flash": "Gemini CLI's base Flash, not on Google's price page (2026-11-14; Gemini CLI rewrites it to gemini-3.8-flash once that is GA); the 3.x Flash fallback prices it at 3.8 Flash's rates, an estimate",
39
48
  };
40
49
  /** The model a Bedrock id names, as a first-party id: region prefix, `-v1:0` and the date dropped. */
41
50
  function fromBedrock(id) {
@@ -61,5 +70,128 @@ export function claudeModelIds(text) {
61
70
  }
62
71
  /** The Claude models `text` names that have no price of their own and no reason to lack one. */
63
72
  export function unpricedClaudeIds(text) {
64
- return claudeModelIds(text).filter((id) => !hasKnownPrice(id) && !(id in UNPRICED_ON_PURPOSE));
73
+ return unpriced(claudeModelIds(text));
74
+ }
75
+ /** The ids in `ids` that have no price of their own and no reason to lack one. */
76
+ export function unpriced(ids) {
77
+ return ids.filter((id) => !hasKnownPrice(id) && !(id in UNPRICED_ON_PURPOSE));
78
+ }
79
+ /**
80
+ * Models priced per image, per minute or per character, or not by the token
81
+ * at all (embeddings, moderation), and Google's endpoints that are not
82
+ * models a coding agent runs (video, music, robots, the Decisions API, Gemma
83
+ * on the free tier only): the table has no row for them on purpose
84
+ * (pricing.ts header). Matched anywhere in the id.
85
+ */
86
+ const NOT_A_TEXT_MODEL = /image|realtime|audio|tts|transcribe|whisper|translate|(?:^|-)live(?:-|$)|embedding|moderation|omni|robotics|decision|lyria|veo|imagen|gemma|nano-banana|sora/i;
87
+ /**
88
+ * The models OpenAI's price page (developers.openai.com/api/docs/pricing,
89
+ * its .md) lists in its text tables: each table row's model cell (the first,
90
+ * or the second where the first is a category), the context-length notes
91
+ * dropped. Tables with a Modality or Use case column (images, audio,
92
+ * transcription) and the tools table are not models priced by the token.
93
+ */
94
+ export function openaiPageIds(markdown) {
95
+ const out = new Set();
96
+ let header;
97
+ for (const line of markdown.split("\n")) {
98
+ if (!line.startsWith("|")) {
99
+ header = undefined;
100
+ continue;
101
+ }
102
+ const cells = line.split("|").slice(1, -1).map((c) => c.trim());
103
+ if (!header) {
104
+ header = cells.map((c) => c.toLowerCase());
105
+ continue;
106
+ }
107
+ if (cells.every((c) => /^-+$/.test(c)))
108
+ continue;
109
+ if (header.includes("modality") || header.includes("use case") || header[0] === "tool")
110
+ continue;
111
+ const at = header.indexOf("model");
112
+ if (at === -1)
113
+ continue;
114
+ const name = cells[at]?.replace(/\s*\(.*\)\s*$/, "").replace(/<[^>]*>/g, "").trim();
115
+ if (name && /^[a-z][a-z0-9.-]*$/.test(name) && !NOT_A_TEXT_MODEL.test(name))
116
+ out.add(name);
117
+ }
118
+ return [...out].sort();
119
+ }
120
+ /**
121
+ * The models Google's price page (ai.google.dev/gemini-api/docs/pricing, its
122
+ * .md.txt) prices: each section's model id line (`*[\`gemini-4-argon\`](...)*`),
123
+ * the text models only.
124
+ */
125
+ export function googlePageIds(markdown) {
126
+ const out = new Set();
127
+ for (const m of markdown.matchAll(/^\s*\*\[`([a-z][a-z0-9.-]*)`\]/gm))
128
+ if (!NOT_A_TEXT_MODEL.test(m[1]))
129
+ out.add(m[1]);
130
+ return [...out].sort();
131
+ }
132
+ /**
133
+ * The models Codex offers (its models catalog, codex-rs/models-manager/
134
+ * models.json): `listed` are the ones its picker shows, `hidden` the rest
135
+ * (internal and trusted-access ids, which the price page may not name).
136
+ */
137
+ export function codexModelIds(json) {
138
+ const models = JSON.parse(json).models ?? [];
139
+ const listed = new Set();
140
+ const hidden = new Set();
141
+ for (const m of models)
142
+ if (typeof m.slug === "string")
143
+ (m.visibility === "list" ? listed : hidden).add(m.slug);
144
+ return { listed: [...listed].sort(), hidden: [...hidden].sort() };
145
+ }
146
+ /**
147
+ * The Gemini models Gemini CLI names (packages/core/src/config/models.ts):
148
+ * every quoted full model id (a version and a Pro/Flash/Flash-Lite name),
149
+ * not family prefixes like 'gemini-3' or the embedding model.
150
+ */
151
+ export function geminiCliIds(source) {
152
+ const out = new Set();
153
+ for (const m of source.matchAll(/['"`](gemini-\d[\d.]*-(?:pro|flash)[a-z0-9.-]*)['"`]/g))
154
+ if (!NOT_A_TEXT_MODEL.test(m[1]))
155
+ out.add(m[1]);
156
+ return [...out].sort();
157
+ }
158
+ /** One way of naming a pricing.ts row, as a model id the row prices. */
159
+ function rowId(line) {
160
+ const named = /\[(?:openai|gemini)\("([^"]+)"\)/.exec(line);
161
+ if (named)
162
+ return named[1];
163
+ const c = /\[claude\("([a-z]+)[^"]*",\s*(\d+)(?:,\s*(\d+))?\)/.exec(line);
164
+ return c ? `claude-${c[1]}-${c[2]}${c[3] ? `-${c[3]}` : ""}` : undefined;
165
+ }
166
+ /**
167
+ * The rows of pricing.ts's table (its source, `src/pricing.ts`) whose price
168
+ * ends on a known day (`changes`), each with whether the page said what
169
+ * follows (`then`, or `routes`: billed as another model from that day).
170
+ * Throws on a dated row it cannot name, so the check cannot pass by missing one.
171
+ */
172
+ export function datedRows(pricingSource) {
173
+ const out = [];
174
+ for (const line of pricingSource.split("\n")) {
175
+ const day = /\bchanges:\s*"(\d{4}-\d{2}-\d{2})"/.exec(line);
176
+ if (!day || /^\s*(?:\/\/|\*)/.test(line))
177
+ continue;
178
+ const id = rowId(line);
179
+ if (!id)
180
+ throw new Error(`a dated row with no model name this check can read: ${line.trim()}`);
181
+ out.push({ id, changes: day[1], successor: /\bthen:|\broutes:/.test(line) });
182
+ }
183
+ return out;
184
+ }
185
+ /**
186
+ * The dated rows with no successor price whose last day at that price (the
187
+ * day before `changes`) is at most `days` days after `today`, or already
188
+ * past: from then, every install prices that model as an estimate, so the
189
+ * page needs reading again (and the successor price adding, once published).
190
+ */
191
+ export function dueRows(rows, today, days = 14) {
192
+ const t = Date.parse(`${today}T00:00:00Z`);
193
+ return rows
194
+ .filter((r) => !r.successor)
195
+ .map((r) => ({ ...r, daysLeft: Math.round((Date.parse(`${r.changes}T00:00:00Z`) - 864e5 - t) / 864e5) }))
196
+ .filter((r) => r.daysLeft <= days);
65
197
  }
package/dist/pricing.js CHANGED
@@ -145,12 +145,15 @@ const PRICING = [
145
145
  // Fast mode (priority processing; Codex records only its thread's
146
146
  // `service_tier`, not each request's) and the 10% regional uplift.
147
147
  [openai("gpt-6-astra"), ...openaiLong(10, 50, 1)],
148
+ // GPT-6 Astra for Law's price is promotional "at least through December
149
+ // 31, 2026" (read 2026-11-14): no end date to record yet.
148
150
  [openai("gpt-6-astra-law"), rate(10, 50, 1)],
149
151
  [openai("gpt-6.1-sol"), ...openaiLong(2, 10, 0.1)],
150
152
  [openai("gpt-6.1-terra"), ...openaiLong(1, 5, 0.05)],
151
153
  [openai("gpt-6-sol"), ...openaiLong(2, 10, 0.2)],
152
154
  [openai("gpt-6-luna"), ...openaiLong(0.1, 0.5, 0.01)],
153
- [openai("gpt-6-cyber"), rate(20, 100, 2)],
155
+ // gpt-6-cyber's long-context row ($40 / $150 / $4, read 2026-11-14) is 2x / 1.5x.
156
+ [openai("gpt-6-cyber"), ...openaiLong(20, 100, 2)],
154
157
  [openai("gpt-6-rosalind"), ...openaiLong(15, 75, 1.5)],
155
158
  [openai("gpt-rosalind-research"), rate(5, 25, 0.5)],
156
159
  [openai("gpt-rosalind-discovery"), rate(5, 25, 0.5)],
@@ -165,6 +168,8 @@ const PRICING = [
165
168
  [openai("gpt-5.5"), ...openaiLong(5, 30, 0.5)],
166
169
  [openai("gpt-5.5-pro"), ...openaiLong(30, 180, 30)],
167
170
  [openai("gpt-5.5-cyber"), rate(12.5, 75, 1.25)],
171
+ // The page names it gpt-5.5-cyber-preview now (read 2026-11-14), at the same price.
172
+ [openai("gpt-5.5-cyber-preview"), rate(12.5, 75, 1.25)],
168
173
  [openai("gpt-5.4"), ...openaiLong(2.5, 15, 0.25)],
169
174
  [openai("gpt-5.4-mini"), rate(0.75, 4.5, 0.075)],
170
175
  [openai("gpt-5.4-nano"), rate(0.2, 1.25, 0.02)],
@@ -184,6 +189,8 @@ const PRICING = [
184
189
  [openai("o3"), rate(2, 8, 0.5)],
185
190
  [openai("o3-pro"), rate(20, 80, 20)],
186
191
  [openai("chat-latest"), rate(5, 30, 0.5)],
192
+ // Specialized models, Search (read 2026-11-14); its web search fee is per call, not modelled.
193
+ [openai("gpt-5-search-api"), rate(1.25, 10, 0.125)],
187
194
  // Fallbacks for OpenAI ids not on the page (gpt-5-codex, gpt-5.1-codex-max,
188
195
  // gpt-4.1-nano, gpt-4-turbo, o1, o3-mini...): older approximate prices.
189
196
  [/gpt-5.*(mini|nano)/i, rate(0.25, 2, 0.025), FALLBACK],
@@ -195,8 +202,13 @@ const PRICING = [
195
202
  // Google: ai.google.dev/gemini-api/docs/pricing (paid tier, Standard, text),
196
203
  // read 2026-11-06; the dates and the Pro tiers read again 2026-11-08.
197
204
  // Gemini 4 Argon's $2 / $10 / $0.10 hold "through November 30, 2026";
198
- // "starting December 1, 2026" it is $4 / $20 / $0.20.
205
+ // "starting December 1, 2026" it is $4 / $20 / $0.20. Read again
206
+ // 2026-11-14: unchanged; Gemini 4 Carbon is new at the same prices and
207
+ // dates, Gemini 4 Hydrogen new at $1.50 / $7.50 / $0.075 with no date.
208
+ // Neither has a long-prompt tier (one 1M-token context).
209
+ [gemini("gemini-4-carbon"), rate(2, 10, 0.1), { changes: "2026-12-01", then: rate(4, 20, 0.2) }],
199
210
  [gemini("gemini-4-argon"), rate(2, 10, 0.1), { changes: "2026-12-01", then: rate(4, 20, 0.2) }],
211
+ [gemini("gemini-4-hydrogen"), rate(1.5, 7.5, 0.075)],
200
212
  // 3.6 and 3.8 Flash double "starting January 1, 2027" ($1.50 / $7.50 / $0.15).
201
213
  [gemini("gemini-3.8-flash"), rate(0.75, 3.75, 0.075), { changes: "2027-01-01", then: rate(1.5, 7.5, 0.15) }],
202
214
  [gemini("gemini-3.6-flash"), rate(0.75, 3.75, 0.075), { changes: "2027-01-01", then: rate(1.5, 7.5, 0.15) }],
package/dist/proxy.d.ts CHANGED
@@ -76,7 +76,7 @@ export interface ProxyOptions extends OptimizeOptions {
76
76
  /** Default request body cap: far above any real request (a 1M-token context is ~4 MB of JSON, images aside). */
77
77
  export declare const DEFAULT_MAX_BODY_BYTES: number;
78
78
  /** Reported by /health so `autopilot status` can tell an outdated service from a current one. */
79
- export declare const PROXY_VERSION = "0.47.0";
79
+ export declare const PROXY_VERSION = "0.48.0";
80
80
  /**
81
81
  * Remove a leading `/t/<token>` from a request path, or return undefined when
82
82
  * 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.47.0";
28
+ export const PROXY_VERSION = "0.48.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
  const SKIP_RESPONSE_HEADERS = new Set(["content-length", "content-encoding", "transfer-encoding", "connection"]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "context-doctor",
3
- "version": "0.47.0",
3
+ "version": "0.48.0",
4
4
  "description": "Context and token optimizer for LLM agents: see where Claude Code, Cursor, Codex and Gemini CLI tokens go, then cut them: an every-prompt hook, smarter compaction, an autopilot proxy that edits history only when the prompt cache is cold, RAG chunk packing and an MCP server. Local, no API key. By gAI Ventures.",
5
5
  "keywords": [
6
6
  "agent",
@@ -77,12 +77,15 @@
77
77
  "version": "node scripts/sync-versions.mjs"
78
78
  },
79
79
  "devDependencies": {
80
+ "@modelcontextprotocol/client": "^2.4.0",
80
81
  "@modelcontextprotocol/sdk": "^1.32.2",
81
- "zod": "^3.23.0",
82
+ "@modelcontextprotocol/server": "^2.4.0",
82
83
  "@types/node": "^22.0.0",
83
84
  "esbuild": "^0.25.12",
84
- "typescript": "^5.5.0"
85
+ "typescript": "^5.5.0",
86
+ "zod": "^4.6.7"
85
87
  },
88
+ "overrides": {},
86
89
  "homepage": "https://github.com/KushalP1/context-doctor#readme",
87
90
  "bugs": {
88
91
  "url": "https://github.com/KushalP1/context-doctor/issues"