context-doctor 0.35.0 → 0.36.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 +8 -5
- package/dist/ab.d.ts +188 -0
- package/dist/ab.js +857 -0
- package/dist/abtasks.d.ts +49 -0
- package/dist/abtasks.js +287 -0
- package/dist/cli.js +34 -8
- package/dist/copilot.d.ts +63 -0
- package/dist/copilot.js +96 -0
- package/dist/doctor.js +114 -1
- package/dist/hook.d.ts +1 -1
- package/dist/hook.js +25 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/install.d.ts +16 -0
- package/dist/install.js +176 -3
- package/dist/ledger.d.ts +4 -1
- package/dist/ledger.js +1 -0
- package/dist/mcp.js +38 -38
- package/dist/pricing.d.ts +7 -0
- package/dist/pricing.js +29 -5
- package/dist/proxy.d.ts +1 -1
- package/dist/proxy.js +1 -1
- package/dist/rules.d.ts +16 -0
- package/dist/rules.js +30 -0
- package/package.json +1 -1
package/dist/pricing.d.ts
CHANGED
|
@@ -19,6 +19,13 @@ export interface ModelPricing {
|
|
|
19
19
|
export declare const CACHE_WRITE_5M = 1.25;
|
|
20
20
|
export declare const CACHE_WRITE_1H = 2;
|
|
21
21
|
export declare function pricingFor(model?: string): ModelPricing | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* A Claude model's price from a row for its own version, not a family
|
|
24
|
+
* fallback: what a command that caps spending needs (`ab --budget`). An id
|
|
25
|
+
* the table only knows by family (a new release, a typo like
|
|
26
|
+
* claude-opus-9) gets undefined.
|
|
27
|
+
*/
|
|
28
|
+
export declare function exactClaudePricingFor(model?: string): ModelPricing | undefined;
|
|
22
29
|
export declare function inputCostUsd(tokens: number, pricing: ModelPricing): number;
|
|
23
30
|
/** `usage` as the API returns it and Claude Code records it on each reply. */
|
|
24
31
|
export interface RecordedUsage {
|
package/dist/pricing.js
CHANGED
|
@@ -23,6 +23,8 @@ function claude(families, major, minor) {
|
|
|
23
23
|
? new RegExp(`claude-(?:${families})-${major}(?![.\\d]|-\\d{1,2}(?!\\d))`, "i")
|
|
24
24
|
: new RegExp(`claude-(?:${families})-${major}[-.]${minor}(?!\\d)`, "i");
|
|
25
25
|
}
|
|
26
|
+
/** The Claude family fallbacks: a price for ids the table does not know by version yet. */
|
|
27
|
+
const CLAUDE_FAMILY = [/claude.*fable|claude.*mythos/i, /claude.*opus/i, /claude.*sonnet/i, /claude.*haiku/i];
|
|
26
28
|
const PRICING = [
|
|
27
29
|
// Specific Claude versions first: the family rows below are only a
|
|
28
30
|
// fallback for ids this table does not know yet.
|
|
@@ -45,11 +47,17 @@ const PRICING = [
|
|
|
45
47
|
[claude("haiku", 4, 5), rate(1, 5, 0.1)],
|
|
46
48
|
[/claude-3-5-haiku/i, rate(0.8, 4, 0.08)],
|
|
47
49
|
[/claude-3-haiku/i, rate(0.25, 1.25, 0.03)],
|
|
48
|
-
// Sonnet 4.6, 4.5, 4 and the 3.x Sonnets are all $3 / $15 / $0.30
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
[
|
|
52
|
-
[
|
|
50
|
+
// Sonnet 4.6, 4.5, 4 and the 3.x Sonnets are all $3 / $15 / $0.30, the
|
|
51
|
+
// family row's price; rows of their own so a spending cap can tell a known
|
|
52
|
+
// version from a guess (exactClaudePricingFor).
|
|
53
|
+
[claude("sonnet", 4, 6), rate(3, 15, 0.3)],
|
|
54
|
+
[claude("sonnet", 4, 5), rate(3, 15, 0.3)],
|
|
55
|
+
[claude("sonnet", 4), rate(3, 15, 0.3)],
|
|
56
|
+
[/claude-3-[57]-sonnet/i, rate(3, 15, 0.3)],
|
|
57
|
+
[CLAUDE_FAMILY[0], rate(10, 50, 1)],
|
|
58
|
+
[CLAUDE_FAMILY[1], rate(5, 25, 0.5)],
|
|
59
|
+
[CLAUDE_FAMILY[2], rate(3, 15, 0.3)],
|
|
60
|
+
[CLAUDE_FAMILY[3], rate(1, 5, 0.1)],
|
|
53
61
|
[/gpt-5.*(mini|nano)/i, { inputPerM: 0.25, outputPerM: 2, cacheReadPerM: 0.025 }],
|
|
54
62
|
[/gpt-5/i, { inputPerM: 1.25, outputPerM: 10, cacheReadPerM: 0.125 }],
|
|
55
63
|
[/gpt-4o-mini/i, { inputPerM: 0.15, outputPerM: 0.6, cacheReadPerM: 0.075 }],
|
|
@@ -76,6 +84,22 @@ export function pricingFor(model) {
|
|
|
76
84
|
}
|
|
77
85
|
return undefined;
|
|
78
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* A Claude model's price from a row for its own version, not a family
|
|
89
|
+
* fallback: what a command that caps spending needs (`ab --budget`). An id
|
|
90
|
+
* the table only knows by family (a new release, a typo like
|
|
91
|
+
* claude-opus-9) gets undefined.
|
|
92
|
+
*/
|
|
93
|
+
export function exactClaudePricingFor(model) {
|
|
94
|
+
if (!model || !/claude/i.test(model))
|
|
95
|
+
return undefined;
|
|
96
|
+
for (const [pattern, pricing] of PRICING) {
|
|
97
|
+
if (!pattern.test(model))
|
|
98
|
+
continue;
|
|
99
|
+
return CLAUDE_FAMILY.includes(pattern) ? undefined : pricing;
|
|
100
|
+
}
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
79
103
|
export function inputCostUsd(tokens, pricing) {
|
|
80
104
|
return (tokens / 1_000_000) * pricing.inputPerM;
|
|
81
105
|
}
|
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.36.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
|
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.36.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"]);
|
package/dist/rules.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The standing context rules: the one text every surface without a hook of
|
|
3
|
+
* its own gets. The MCP server sends it as its `instructions` (Claude
|
|
4
|
+
* Desktop, Cursor, ChatGPT and any MCP client that passes them on), and the
|
|
5
|
+
* GitHub Copilot sessionStart hook adds it as context, since the Copilot CLI
|
|
6
|
+
* includes only some MCP servers' instructions unless started with
|
|
7
|
+
* --allow-all-mcp-server-instructions. Kept in a module of its own so both
|
|
8
|
+
* read the same words and neither pulls in the other's dependencies.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* The standing rules every chat gets. ChatGPT's MCP guide says to keep the
|
|
12
|
+
* most important details in the first 512 characters, so rules 1-3 (when to
|
|
13
|
+
* measure, and the two habits) end before character 512; the two that need
|
|
14
|
+
* a particular tool come after.
|
|
15
|
+
*/
|
|
16
|
+
export declare const SERVER_INSTRUCTIONS = "Context hygiene rules (always on):\n1. When asked about tokens, cost, speed or limits, and once at ~30 turns or 3+ large pastes: call profile_context BEFORE answering; act on its top finding. In a chat app pass a `sketch` (turns + big blocks). Do not estimate token counts yourself.\n2. Summarize any paste or tool result over ~2k tokens into the points you need; keep it verbatim only to edit or quote it exactly.\n3. Refer to earlier content by name; never re-quote it or inline base64.\n4. To answer from a big file or folder you won't edit, call pack_context with the question; don't read it whole.\n5. If optimize_context returns a pruned-turns digest, write its \u2264150-token summary.";
|
package/dist/rules.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The standing context rules: the one text every surface without a hook of
|
|
3
|
+
* its own gets. The MCP server sends it as its `instructions` (Claude
|
|
4
|
+
* Desktop, Cursor, ChatGPT and any MCP client that passes them on), and the
|
|
5
|
+
* GitHub Copilot sessionStart hook adds it as context, since the Copilot CLI
|
|
6
|
+
* includes only some MCP servers' instructions unless started with
|
|
7
|
+
* --allow-all-mcp-server-instructions. Kept in a module of its own so both
|
|
8
|
+
* read the same words and neither pulls in the other's dependencies.
|
|
9
|
+
*/
|
|
10
|
+
// Kept deliberately terse: these ride in EVERY conversation's context, and a
|
|
11
|
+
// context-saving tool must not itself be context overhead (~250 Claude tokens).
|
|
12
|
+
//
|
|
13
|
+
// Written as conditions and actions, not offers. On Claude Desktop this string
|
|
14
|
+
// is the only channel that reaches the model without the user asking — MCP has
|
|
15
|
+
// no hook and no data path there — so "offer to run" leaves it to a model that
|
|
16
|
+
// will usually not, while "when X, call Y before answering" is followed. The
|
|
17
|
+
// thresholds keep it from firing on every turn, which would cost more context
|
|
18
|
+
// than it saves.
|
|
19
|
+
/**
|
|
20
|
+
* The standing rules every chat gets. ChatGPT's MCP guide says to keep the
|
|
21
|
+
* most important details in the first 512 characters, so rules 1-3 (when to
|
|
22
|
+
* measure, and the two habits) end before character 512; the two that need
|
|
23
|
+
* a particular tool come after.
|
|
24
|
+
*/
|
|
25
|
+
export const SERVER_INSTRUCTIONS = `Context hygiene rules (always on):
|
|
26
|
+
1. When asked about tokens, cost, speed or limits, and once at ~30 turns or 3+ large pastes: call profile_context BEFORE answering; act on its top finding. In a chat app pass a \`sketch\` (turns + big blocks). Do not estimate token counts yourself.
|
|
27
|
+
2. Summarize any paste or tool result over ~2k tokens into the points you need; keep it verbatim only to edit or quote it exactly.
|
|
28
|
+
3. Refer to earlier content by name; never re-quote it or inline base64.
|
|
29
|
+
4. To answer from a big file or folder you won't edit, call pack_context with the question; don't read it whole.
|
|
30
|
+
5. If optimize_context returns a pruned-turns digest, write its ≤150-token summary.`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "context-doctor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.36.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",
|