context-doctor 0.35.0 → 0.35.1

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 CHANGED
@@ -12,7 +12,7 @@ npx context-doctor savings # what your recent sessions cost, and what each f
12
12
 
13
13
  <img src="https://raw.githubusercontent.com/KushalP1/context-doctor/main/assets/savings.svg" alt="npx context-doctor savings: input billed, what /compact at cold resumes, autopilot and an earlier auto-compact window would have saved" width="640">
14
14
 
15
- > **Which context-doctor is this?** Several projects share the name. This one is [`context-doctor` on npm](https://www.npmjs.com/package/context-doctor) and `io.github.KushalP1/context-doctor` in the [official MCP Registry](https://registry.modelcontextprotocol.io). Built and maintained by [gAI Ventures](https://gai.ventures).
15
+ > **Which context-doctor is this?** Several projects share the name. This one is [`context-doctor` on npm](https://www.npmjs.com/package/context-doctor) and `io.github.KushalP1/context-doctor` in the official MCP Registry ([see the entry](https://registry.modelcontextprotocol.io/v0/servers/io.github.KushalP1%2Fcontext-doctor/versions/latest)). The registry is a service, not a list in a GitHub repo: the `modelcontextprotocol/servers` repository holds only reference servers and points to the registry for the rest. Built and maintained by [gAI Ventures](https://gai.ventures).
16
16
 
17
17
  ## Quick start
18
18
 
package/dist/mcp.js CHANGED
@@ -89,7 +89,7 @@ data:
89
89
  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.
90
90
  3. Refer to earlier content by name; never re-quote it or inline base64.
91
91
  4. To answer from a big file or folder you won't edit, call pack_context with the question; don't read it whole.
92
- 5. If optimize_context returns a pruned-turns digest, write its \u2264150-token summary.`,XO=["dedupe","trim-tool-results","trim-tool-calls","strip-base64","prune-history"];function R0({fileAccess:t=!0}={}){let e=new na({name:"context-doctor",version:"0.35.0"},{instructions:GO});return e.tool("profile_context","Profile an LLM conversation or prompt: token breakdown, largest blocks, and findings about wasted context (duplicates, oversized pastes or tool results, base64 blobs, long history). Pass ONE input: `conversation` (full OpenAI/Anthropic JSON or raw text) or `sketch` (chat apps such as Claude Desktop or ChatGPT, where you cannot export the conversation: the turn count plus the few blocks that matter, ~120 tokens). Call it whenever the user asks about token usage, context size, cost, speed or limits, and once on your own when the conversation first passes ~30 turns or 3+ large pastes. Act on the top finding.",{conversation:te.string().optional().describe("Conversation JSON (OpenAI or Anthropic format, or bare message array) or raw prompt text. Omit in chat apps and pass `sketch`."),sketch:te.object({turns:te.number().int().nonnegative().max(1e5).describe("User+assistant exchanges so far"),model:te.string().optional().describe("Model this chat runs as, e.g. claude-sonnet-5, gpt-5"),blocks:te.array(te.object({turn:te.number().int().positive().max(1e5).describe("1-based turn the block sits in"),kind:te.enum(["paste","code","tool_result","image","base64","text"]),label:te.string().describe("Short name you can refer to later, e.g. 'the nginx config'"),approx_tokens:te.number().positive().max(1e7).optional(),approx_lines:te.number().positive().max(1e6).optional(),approx_words:te.number().positive().max(5e6).optional(),approx_chars:te.number().positive().max(4e7).optional(),repeated:te.number().int().positive().max(1e3).optional().describe("Times this same content appears (2+ = duplicate)"),stale:te.boolean().optional().describe("Already acted on; nothing in it is still needed")})).max(500).describe("Only the blocks over ~500 tokens, repeated, or images. Plain turns need not be listed.")}).optional().describe("Coarse description of the conversation for chat apps. One size hint per block: lines for code, words for prose, chars (or tokens) for logs and tool output, which vary most per line."),model:te.string().optional().describe("Target model name for context-window math, e.g. claude-sonnet-5 or gpt-4o")},{title:"Profile context",readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},async({conversation:r,sketch:n,model:o})=>{if(n)return{content:[{type:"text",text:(r?"Note: both `conversation` and `sketch` were passed; profiled the sketch only. Pass one.\n\n":"")+Pv({...n,model:n.model??o})}]};if(!r)return{isError:!0,content:[{type:"text",text:"Pass either `conversation` (full JSON or text) or `sketch` (turns + large/repeated blocks). In a chat app, use `sketch`."}]};let s=vv(uv(r),o);return{content:[{type:"text",text:Sv(s)}]}}),e.tool("optimize_context","Rewrite a conversation to reclaim tokens with deterministic strategies (dedupe, trim stale tool results, strip base64; prune-history is optional and lossy). Returns the slimmed JSON and a savings summary; no LLM calls. Results over 100k chars are not echoed back (summary and a CLI command instead). Use after profile_context finds waste the user wants fixed. Add prune-history only with the user's consent, then write the replacement summary as the result instructs.",{conversation:te.string().describe("Conversation JSON (OpenAI or Anthropic format, or bare message array)"),strategies:te.array(te.enum(XO)).optional().describe("Default: dedupe, trim-tool-results, strip-base64. Add trim-tool-calls for big inline file writes, prune-history for lossy compaction of old turns."),keep_recent:te.number().int().nonnegative().optional().describe("Messages at the tail to leave untouched (default 6; 0 = none; prune-history keeps at least 2)"),max_tool_result_tokens:te.number().int().positive().optional().describe("Token budget for trimmed tool results (default 300)")},{title:"Optimize context",readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},async({conversation:r,strategies:n,keep_recent:o,max_tool_result_tokens:s})=>{let i=$v(r,{strategies:n,keepRecent:o,maxToolResultTokens:s}),a=i.tokensBefore-i.tokensAfter;a>0&&da({ev:"optimize",src:"mcp",saved:a,model:i.conversation?.model});let c=`Saved ~${H(a)} tokens (${H(i.tokensBefore)} \u2192 ${H(i.tokensAfter)}) via ${i.applied.length} change(s):
92
+ 5. If optimize_context returns a pruned-turns digest, write its \u2264150-token summary.`,XO=["dedupe","trim-tool-results","trim-tool-calls","strip-base64","prune-history"];function R0({fileAccess:t=!0}={}){let e=new na({name:"context-doctor",version:"0.35.1"},{instructions:GO});return e.tool("profile_context","Profile an LLM conversation or prompt: token breakdown, largest blocks, and findings about wasted context (duplicates, oversized pastes or tool results, base64 blobs, long history). Pass ONE input: `conversation` (full OpenAI/Anthropic JSON or raw text) or `sketch` (chat apps such as Claude Desktop or ChatGPT, where you cannot export the conversation: the turn count plus the few blocks that matter, ~120 tokens). Call it whenever the user asks about token usage, context size, cost, speed or limits, and once on your own when the conversation first passes ~30 turns or 3+ large pastes. Act on the top finding.",{conversation:te.string().optional().describe("Conversation JSON (OpenAI or Anthropic format, or bare message array) or raw prompt text. Omit in chat apps and pass `sketch`."),sketch:te.object({turns:te.number().int().nonnegative().max(1e5).describe("User+assistant exchanges so far"),model:te.string().optional().describe("Model this chat runs as, e.g. claude-sonnet-5, gpt-5"),blocks:te.array(te.object({turn:te.number().int().positive().max(1e5).describe("1-based turn the block sits in"),kind:te.enum(["paste","code","tool_result","image","base64","text"]),label:te.string().describe("Short name you can refer to later, e.g. 'the nginx config'"),approx_tokens:te.number().positive().max(1e7).optional(),approx_lines:te.number().positive().max(1e6).optional(),approx_words:te.number().positive().max(5e6).optional(),approx_chars:te.number().positive().max(4e7).optional(),repeated:te.number().int().positive().max(1e3).optional().describe("Times this same content appears (2+ = duplicate)"),stale:te.boolean().optional().describe("Already acted on; nothing in it is still needed")})).max(500).describe("Only the blocks over ~500 tokens, repeated, or images. Plain turns need not be listed.")}).optional().describe("Coarse description of the conversation for chat apps. One size hint per block: lines for code, words for prose, chars (or tokens) for logs and tool output, which vary most per line."),model:te.string().optional().describe("Target model name for context-window math, e.g. claude-sonnet-5 or gpt-4o")},{title:"Profile context",readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},async({conversation:r,sketch:n,model:o})=>{if(n)return{content:[{type:"text",text:(r?"Note: both `conversation` and `sketch` were passed; profiled the sketch only. Pass one.\n\n":"")+Pv({...n,model:n.model??o})}]};if(!r)return{isError:!0,content:[{type:"text",text:"Pass either `conversation` (full JSON or text) or `sketch` (turns + large/repeated blocks). In a chat app, use `sketch`."}]};let s=vv(uv(r),o);return{content:[{type:"text",text:Sv(s)}]}}),e.tool("optimize_context","Rewrite a conversation to reclaim tokens with deterministic strategies (dedupe, trim stale tool results, strip base64; prune-history is optional and lossy). Returns the slimmed JSON and a savings summary; no LLM calls. Results over 100k chars are not echoed back (summary and a CLI command instead). Use after profile_context finds waste the user wants fixed. Add prune-history only with the user's consent, then write the replacement summary as the result instructs.",{conversation:te.string().describe("Conversation JSON (OpenAI or Anthropic format, or bare message array)"),strategies:te.array(te.enum(XO)).optional().describe("Default: dedupe, trim-tool-results, strip-base64. Add trim-tool-calls for big inline file writes, prune-history for lossy compaction of old turns."),keep_recent:te.number().int().nonnegative().optional().describe("Messages at the tail to leave untouched (default 6; 0 = none; prune-history keeps at least 2)"),max_tool_result_tokens:te.number().int().positive().optional().describe("Token budget for trimmed tool results (default 300)")},{title:"Optimize context",readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},async({conversation:r,strategies:n,keep_recent:o,max_tool_result_tokens:s})=>{let i=$v(r,{strategies:n,keepRecent:o,maxToolResultTokens:s}),a=i.tokensBefore-i.tokensAfter;a>0&&da({ev:"optimize",src:"mcp",saved:a,model:i.conversation?.model});let c=`Saved ~${H(a)} tokens (${H(i.tokensBefore)} \u2192 ${H(i.tokensAfter)}) via ${i.applied.length} change(s):
93
93
  `+i.applied.map(p=>`- [${p.strategy}] message #${p.messageIndex}: ${p.note} (~${H(p.tokensSaved)})`).join(`
94
94
  `),u=1e5,l=JSON.stringify(i.conversation),d=[{type:"text",text:c},l.length<=u?{type:"text",text:l}:{type:"text",text:`[optimized conversation is ${l.length} chars \u2014 too large to echo into this context. Tell the user the savings above and that \`npx context-doctor optimize <file> --out slim.json\` produces the file directly.]`}];return i.prunedDigest&&d.push({type:"text",text:`ACTION REQUIRED (you, the assistant calling this tool): the pruned turns are digested below. Write a dense factual summary of them (\u2264150 tokens: decisions, current state, open items, key identifiers) and replace the '[context-doctor: ... pruned]' stub message in the conversation above with your summary before presenting the result.
95
95
 
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.35.0";
68
+ export declare const PROXY_VERSION = "0.35.1";
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.35.0";
27
+ export const PROXY_VERSION = "0.35.1";
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "context-doctor",
3
- "version": "0.35.0",
3
+ "version": "0.35.1",
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",