context-doctor 0.32.0 → 0.33.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 +85 -695
- package/dist/autoclear.js +4 -1
- package/dist/autopilot.d.ts +20 -0
- package/dist/autopilot.js +69 -6
- package/dist/ci.js +9 -1
- package/dist/cli.js +355 -245
- package/dist/clihelp.d.ts +24 -0
- package/dist/clihelp.js +116 -0
- package/dist/compactquality.d.ts +1 -1
- package/dist/compactquality.js +3 -2
- package/dist/compactwindow.d.ts +29 -5
- package/dist/compactwindow.js +50 -18
- package/dist/diff.js +24 -2
- package/dist/doctor.d.ts +3 -2
- package/dist/doctor.js +77 -27
- package/dist/install.d.ts +25 -0
- package/dist/install.js +237 -29
- package/dist/invocation.d.ts +18 -0
- package/dist/invocation.js +49 -0
- package/dist/mcp.d.ts +5 -2
- package/dist/mcp.js +93 -299
- package/dist/mcpclient.js +45 -0
- package/dist/mcpschema.d.ts +1 -1
- package/dist/mcpschema.js +11 -8
- package/dist/optimize.d.ts +2 -0
- package/dist/optimize.js +2 -0
- package/dist/overhead.d.ts +12 -1
- package/dist/overhead.js +31 -7
- package/dist/preferences.d.ts +1 -1
- package/dist/preferences.js +5 -5
- package/dist/proxy.d.ts +1 -1
- package/dist/proxy.js +1 -1
- package/dist/savings.d.ts +3 -0
- package/dist/savings.js +9 -3
- package/dist/session.d.ts +15 -0
- package/dist/session.js +43 -0
- package/dist/subagentpay.d.ts +1 -1
- package/dist/subagentpay.js +3 -2
- package/package.json +5 -8
- package/skills/context-doctor/SKILL.md +3 -3
package/dist/autoclear.js
CHANGED
|
@@ -129,7 +129,10 @@ export function requestTtlMs(body) {
|
|
|
129
129
|
const openai = Array.isArray(body.input) || (Array.isArray(body.messages) && isOpenAIChat(body.messages));
|
|
130
130
|
if (openai)
|
|
131
131
|
return body.prompt_cache_retention === "24h" ? 24 * HOUR : HOUR;
|
|
132
|
-
|
|
132
|
+
// Automatic caching puts cache_control at the top level of the request; a
|
|
133
|
+
// 1-hour cache marked there was read as the 5-minute default, so autopilot
|
|
134
|
+
// could clear into a cache that was still warm.
|
|
135
|
+
const json = JSON.stringify(body.cache_control ?? "") + JSON.stringify(body.system ?? "") + JSON.stringify(body.tools ?? "") + JSON.stringify(body.messages?.slice(-3) ?? "");
|
|
133
136
|
return /"ttl"\s*:\s*"1h"/.test(json) ? HOUR : 300_000;
|
|
134
137
|
}
|
|
135
138
|
function isOpenAIChat(messages) {
|
package/dist/autopilot.d.ts
CHANGED
|
@@ -46,6 +46,16 @@ export declare function windowsTaskCommand(args: string[]): string;
|
|
|
46
46
|
* task name), not per HOME.
|
|
47
47
|
*/
|
|
48
48
|
export type ServiceExec = (cmd: string, args: string[]) => boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Claude Code turns MCP tool search off when ANTHROPIC_BASE_URL is not an
|
|
51
|
+
* Anthropic host ("Set ENABLE_TOOL_SEARCH=true (or auto / auto:N) if your
|
|
52
|
+
* proxy forwards tool_reference blocks", 2.1.295), so routing it through
|
|
53
|
+
* autopilot loaded every MCP tool definition into every request. The proxy
|
|
54
|
+
* forwards those blocks and the anthropic-beta header untouched, so tool
|
|
55
|
+
* search stays on ("auto", Claude Code's own default) unless the user set it.
|
|
56
|
+
* Returns true when we set it.
|
|
57
|
+
*/
|
|
58
|
+
export declare function keepToolSearch(env: Record<string, string>): boolean;
|
|
49
59
|
/** Version of the package a CLI path belongs to (dist/cli.js -> ../package.json). */
|
|
50
60
|
export declare function installedVersion(cli: string): string | undefined;
|
|
51
61
|
/** Restart the installed background service onto the current build (launchd, systemd). */
|
|
@@ -75,6 +85,16 @@ export declare function autopilotOn(port?: number, paths?: AutopilotPaths): Prom
|
|
|
75
85
|
}>;
|
|
76
86
|
export declare function autopilotOff(paths?: AutopilotPaths, exec?: ServiceExec): Promise<string[]>;
|
|
77
87
|
export declare function autopilotPause(paused: boolean, paths?: AutopilotPaths): string;
|
|
88
|
+
/**
|
|
89
|
+
* Pause or resume, saying what actually happened. Without autopilot on there
|
|
90
|
+
* is no proxy to pause: this used to claim "✓ Paused" over nothing, and on a
|
|
91
|
+
* machine with no ~/.claude it threw ENOENT writing the pause file. `ok` is
|
|
92
|
+
* false when nothing was done, for the exit code.
|
|
93
|
+
*/
|
|
94
|
+
export declare function autopilotPauseResult(paused: boolean, paths?: AutopilotPaths): {
|
|
95
|
+
ok: boolean;
|
|
96
|
+
message: string;
|
|
97
|
+
};
|
|
78
98
|
export declare function autopilotStatus(paths?: AutopilotPaths): Promise<string[]>;
|
|
79
99
|
/**
|
|
80
100
|
* Called by the every-prompt hook: if autopilot is on and the proxy is down,
|
package/dist/autopilot.js
CHANGED
|
@@ -188,6 +188,39 @@ function startService(home, exec) {
|
|
|
188
188
|
return exec("systemctl", ["--user", "start", "context-doctor-proxy.service"]);
|
|
189
189
|
return false;
|
|
190
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Claude Code turns MCP tool search off when ANTHROPIC_BASE_URL is not an
|
|
193
|
+
* Anthropic host ("Set ENABLE_TOOL_SEARCH=true (or auto / auto:N) if your
|
|
194
|
+
* proxy forwards tool_reference blocks", 2.1.295), so routing it through
|
|
195
|
+
* autopilot loaded every MCP tool definition into every request. The proxy
|
|
196
|
+
* forwards those blocks and the anthropic-beta header untouched, so tool
|
|
197
|
+
* search stays on ("auto", Claude Code's own default) unless the user set it.
|
|
198
|
+
* Returns true when we set it.
|
|
199
|
+
*/
|
|
200
|
+
export function keepToolSearch(env) {
|
|
201
|
+
if (env.ENABLE_TOOL_SEARCH !== undefined)
|
|
202
|
+
return false;
|
|
203
|
+
env.ENABLE_TOOL_SEARCH = "auto";
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
/** Installs from before 0.33 routed Claude Code without it: add it once, from the every-prompt self-heal. */
|
|
207
|
+
function migrateToolSearch(paths, cfg) {
|
|
208
|
+
if (cfg.setToolSearch !== undefined)
|
|
209
|
+
return;
|
|
210
|
+
try {
|
|
211
|
+
const settings = readJson(paths.settings);
|
|
212
|
+
const env = settings.env;
|
|
213
|
+
if (!env || env.ANTHROPIC_BASE_URL !== proxyUrl(cfg.port))
|
|
214
|
+
return;
|
|
215
|
+
const set = keepToolSearch(env);
|
|
216
|
+
if (set)
|
|
217
|
+
writeJsonWithBackup(paths.settings, settings);
|
|
218
|
+
writeFileSync(paths.config, JSON.stringify({ ...cfg, setToolSearch: set }, null, 2));
|
|
219
|
+
}
|
|
220
|
+
catch {
|
|
221
|
+
/* the self-heal must never disturb a prompt */
|
|
222
|
+
}
|
|
223
|
+
}
|
|
191
224
|
/** Version of the package a CLI path belongs to (dist/cli.js -> ../package.json). */
|
|
192
225
|
export function installedVersion(cli) {
|
|
193
226
|
try {
|
|
@@ -396,12 +429,15 @@ export async function autopilotOn(port = DEFAULT_AUTOPILOT_PORT, paths = autopil
|
|
|
396
429
|
lines.push(`! settings.json already routed Claude Code to ${previousBaseUrl}; autopilot forwards to api.anthropic.com instead. \`autopilot off\` restores it.`);
|
|
397
430
|
}
|
|
398
431
|
env.ANTHROPIC_BASE_URL = proxyUrl(port);
|
|
432
|
+
const setToolSearch = keepToolSearch(env);
|
|
399
433
|
writeJsonWithBackup(paths.settings, settings);
|
|
400
|
-
writeFileSync(paths.config, JSON.stringify({ port, previousBaseUrl, node: process.execPath, cli }, null, 2));
|
|
434
|
+
writeFileSync(paths.config, JSON.stringify({ port, previousBaseUrl, setToolSearch, node: process.execPath, cli }, null, 2));
|
|
401
435
|
if (existsSync(paths.pauseFile))
|
|
402
436
|
rmSync(paths.pauseFile);
|
|
403
437
|
lines.push(`✓ Claude Code routed through it (env.ANTHROPIC_BASE_URL in ${paths.settings})`);
|
|
404
|
-
|
|
438
|
+
if (setToolSearch)
|
|
439
|
+
lines.push("✓ MCP tool search kept on (env.ENABLE_TOOL_SEARCH=auto): Claude Code turns it off behind a non-Anthropic address, which would load every MCP tool definition on every request");
|
|
440
|
+
lines.push(" Applies to Claude Code sessions started from now on in a terminal or IDE (the desktop app's Code tab sets its own address).");
|
|
405
441
|
lines.push(" Sessions already open keep their old route until restarted.");
|
|
406
442
|
lines.push(...reachNote());
|
|
407
443
|
lines.push(` GPT apps on your own OpenAI key get the same: export OPENAI_BASE_URL=${proxyUrl(port)}/v1`);
|
|
@@ -422,6 +458,8 @@ export async function autopilotOff(paths = autopilotPaths(), exec = tryRun) {
|
|
|
422
458
|
env.ANTHROPIC_BASE_URL = restore;
|
|
423
459
|
else
|
|
424
460
|
delete env.ANTHROPIC_BASE_URL;
|
|
461
|
+
if (cfg?.setToolSearch && env.ENABLE_TOOL_SEARCH === "auto")
|
|
462
|
+
delete env.ENABLE_TOOL_SEARCH;
|
|
425
463
|
if (Object.keys(env).length === 0)
|
|
426
464
|
delete settings.env;
|
|
427
465
|
writeJsonWithBackup(paths.settings, settings);
|
|
@@ -438,13 +476,37 @@ export async function autopilotOff(paths = autopilotPaths(), exec = tryRun) {
|
|
|
438
476
|
return lines;
|
|
439
477
|
}
|
|
440
478
|
export function autopilotPause(paused, paths = autopilotPaths()) {
|
|
479
|
+
return autopilotPauseResult(paused, paths).message;
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Pause or resume, saying what actually happened. Without autopilot on there
|
|
483
|
+
* is no proxy to pause: this used to claim "✓ Paused" over nothing, and on a
|
|
484
|
+
* machine with no ~/.claude it threw ENOENT writing the pause file. `ok` is
|
|
485
|
+
* false when nothing was done, for the exit code.
|
|
486
|
+
*/
|
|
487
|
+
export function autopilotPauseResult(paused, paths = autopilotPaths()) {
|
|
488
|
+
// A config that exists but no longer parses still means a proxy may be
|
|
489
|
+
// running and routed: pausing it is the safe thing, so only absence is "off".
|
|
490
|
+
if (!existsSync(paths.config)) {
|
|
491
|
+
// A pause file left behind by an older version has nothing to pause.
|
|
492
|
+
if (!paused && existsSync(paths.pauseFile))
|
|
493
|
+
rmSync(paths.pauseFile);
|
|
494
|
+
return {
|
|
495
|
+
ok: false,
|
|
496
|
+
message: `Autopilot is off; nothing to ${paused ? "pause" : "resume"}. \`context-doctor autopilot on\` turns it on for new Claude Code sessions.`,
|
|
497
|
+
};
|
|
498
|
+
}
|
|
441
499
|
if (paused) {
|
|
500
|
+
if (existsSync(paths.pauseFile))
|
|
501
|
+
return { ok: true, message: "Already paused: the proxy forwards every request unchanged. `autopilot resume` turns it back on." };
|
|
502
|
+
mkdirSync(dirname(paths.pauseFile), { recursive: true });
|
|
442
503
|
writeFileSync(paths.pauseFile, new Date().toISOString());
|
|
443
|
-
return "✓ Paused: the proxy now forwards every request unchanged. `autopilot resume` turns it back on.";
|
|
504
|
+
return { ok: true, message: "✓ Paused: the proxy now forwards every request unchanged. `autopilot resume` turns it back on." };
|
|
444
505
|
}
|
|
445
|
-
if (existsSync(paths.pauseFile))
|
|
446
|
-
|
|
447
|
-
|
|
506
|
+
if (!existsSync(paths.pauseFile))
|
|
507
|
+
return { ok: true, message: "Not paused: autopilot is already clearing stale tool output." };
|
|
508
|
+
rmSync(paths.pauseFile);
|
|
509
|
+
return { ok: true, message: "✓ Resumed: stale tool output is cleared again." };
|
|
448
510
|
}
|
|
449
511
|
export async function autopilotStatus(paths = autopilotPaths()) {
|
|
450
512
|
const cfg = readConfig(paths);
|
|
@@ -489,6 +551,7 @@ export async function ensureProxyUp(paths = autopilotPaths(), exec = tryRun) {
|
|
|
489
551
|
const cfg = readConfig(paths);
|
|
490
552
|
if (!cfg)
|
|
491
553
|
return;
|
|
554
|
+
migrateToolSearch(paths, cfg);
|
|
492
555
|
const h = await health(cfg.port, 300);
|
|
493
556
|
if (h.ok) {
|
|
494
557
|
// A service keeps running the code it started with: after an update it
|
package/dist/ci.js
CHANGED
|
@@ -89,7 +89,15 @@ function isFile(p) {
|
|
|
89
89
|
}
|
|
90
90
|
export function ciReport(opts = {}) {
|
|
91
91
|
const cwd = opts.cwd ?? process.cwd();
|
|
92
|
-
|
|
92
|
+
// Outside a repository `git ls-files` lists nothing, which used to read as
|
|
93
|
+
// "No agent memory files" with exit 0: a CI step in the wrong directory
|
|
94
|
+
// passed every pull request. It is an error, said as one.
|
|
95
|
+
const root = git(["rev-parse", "--show-toplevel"], cwd)?.trim();
|
|
96
|
+
if (!root) {
|
|
97
|
+
throw new Error(git(["--version"], cwd) === undefined
|
|
98
|
+
? "ci needs git, and git is not installed or not on PATH."
|
|
99
|
+
: `ci compares memory files in a git repository, and ${cwd} is not inside one. Run it from the repository's checkout.`);
|
|
100
|
+
}
|
|
93
101
|
// A base git cannot resolve (a typo, or a shallow clone that never fetched
|
|
94
102
|
// it) would read as an empty tree: every file "new", and a failure that
|
|
95
103
|
// blames the PR for the whole memory set. Stop and say so instead.
|