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
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the user started this process, so the next steps we print can be
|
|
3
|
+
* typed as they are. Someone who ran `npx context-doctor savings` has no
|
|
4
|
+
* `context-doctor` on PATH: a hint saying `context-doctor autopilot on` is
|
|
5
|
+
* "command not found" for them.
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync } from "node:fs";
|
|
8
|
+
import { platform } from "node:os";
|
|
9
|
+
import { delimiter, join } from "node:path";
|
|
10
|
+
/** Started through npx (or `npm exec`): npm says so, or the script sits in npx's cache. */
|
|
11
|
+
export function launchedViaNpx(env = process.env, script = process.argv[1] ?? "") {
|
|
12
|
+
return env.npm_command === "exec" || /[\\/]_npx[\\/]/.test(script);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A `context-doctor` the user's own shell will find: on PATH, outside npx's
|
|
16
|
+
* cache and outside a project's node_modules/.bin (which npm puts on PATH
|
|
17
|
+
* only while it runs a command).
|
|
18
|
+
*/
|
|
19
|
+
function installedBinary(env) {
|
|
20
|
+
const exts = platform() === "win32" ? [".cmd", ".exe", ""] : [""];
|
|
21
|
+
for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
|
|
22
|
+
if (!dir || /[\\/]_npx[\\/]|[\\/]node_modules[\\/]\.bin\b|[\\/]\.npm[\\/]|[\\/]npm-cache[\\/]/i.test(dir + "/"))
|
|
23
|
+
continue;
|
|
24
|
+
if (exts.some((e) => existsSync(join(dir, "context-doctor" + e))))
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
/** Should follow-up commands be spelled `npx context-doctor …`? */
|
|
30
|
+
export function needsNpx(env = process.env, script) {
|
|
31
|
+
return launchedViaNpx(env, script) && !installedBinary(env);
|
|
32
|
+
}
|
|
33
|
+
/** A follow-up command as the user should type it: `npx context-doctor <rest>` after an npx run. */
|
|
34
|
+
export function selfCommand(rest, env = process.env, script) {
|
|
35
|
+
return `${needsNpx(env, script) ? "npx context-doctor" : "context-doctor"} ${rest}`;
|
|
36
|
+
}
|
|
37
|
+
const SUBCOMMANDS = "install|uninstall|autopilot|init|compact-window|compactions|doctor|savings|instructions|session|overhead|report|subagents|tasks|reads|--help";
|
|
38
|
+
/**
|
|
39
|
+
* Rewrite the `context-doctor <command>` hints in printed text for the way
|
|
40
|
+
* this process was started. Autopilot runs as a background service, which
|
|
41
|
+
* cannot point into npx's cache, so from npx its hint is a global install.
|
|
42
|
+
*/
|
|
43
|
+
export function withInvocation(text, env = process.env, script) {
|
|
44
|
+
if (!needsNpx(env, script))
|
|
45
|
+
return text;
|
|
46
|
+
return text
|
|
47
|
+
.replace(/(?<![\w/@.-])context-doctor autopilot on\b/g, "npm i -g context-doctor && context-doctor autopilot on")
|
|
48
|
+
.replace(new RegExp(`(?<![\\w/@.-]|npx |-g |&& )context-doctor (?=(?:${SUBCOMMANDS})\\b)`, "g"), "npx context-doctor ");
|
|
49
|
+
}
|
package/dist/mcp.d.ts
CHANGED
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* context-doctor MCP server (stdio).
|
|
4
4
|
*
|
|
5
|
-
* Plug into Claude Desktop,
|
|
6
|
-
*
|
|
5
|
+
* Plug into Claude Desktop, Claude Code, Cursor, Codex, Gemini CLI or any MCP
|
|
6
|
+
* client that launches a local command:
|
|
7
7
|
*
|
|
8
8
|
* { "mcpServers": { "context-doctor": { "command": "npx", "args": ["-y", "context-doctor", "mcp"] } } }
|
|
9
9
|
*
|
|
10
|
+
* ChatGPT launches nothing locally: it connects only to a URL (a developer-mode
|
|
11
|
+
* connector), which `--http` serves (see the transport dispatch at the end).
|
|
12
|
+
*
|
|
10
13
|
* Tools:
|
|
11
14
|
* profile_context — analyze a conversation/prompt, report token breakdown + findings
|
|
12
15
|
* optimize_context — apply safe strategies, return the slimmed conversation
|