context-doctor 0.45.0 → 0.47.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 -3
- package/dist/ab.js +3 -2
- package/dist/autopilot.js +9 -5
- package/dist/blob.js +66 -12
- package/dist/budget.d.ts +10 -1
- package/dist/budget.js +37 -8
- package/dist/cachemisses.js +5 -3
- package/dist/cacheplan.js +2 -2
- package/dist/cachettl.js +2 -1
- package/dist/ci.js +2 -1
- package/dist/claudeplugin.d.ts +97 -0
- package/dist/claudeplugin.js +142 -0
- package/dist/cli.js +126 -39
- package/dist/coldresume.d.ts +6 -0
- package/dist/coldresume.js +7 -6
- package/dist/compactcost.d.ts +74 -0
- package/dist/compactcost.js +115 -0
- package/dist/compactwindow.js +5 -4
- package/dist/cursor.js +2 -0
- package/dist/doctor.js +106 -17
- package/dist/extract.js +4 -3
- package/dist/fanout.d.ts +15 -0
- package/dist/fanout.js +31 -10
- package/dist/firstfix.d.ts +43 -0
- package/dist/firstfix.js +80 -0
- package/dist/fix.d.ts +46 -2
- package/dist/fix.js +109 -20
- package/dist/hook.js +6 -2
- package/dist/httpguard.d.ts +13 -0
- package/dist/httpguard.js +22 -0
- package/dist/install.d.ts +21 -9
- package/dist/install.js +211 -40
- package/dist/limits.d.ts +5 -0
- package/dist/limits.js +26 -2
- package/dist/mcp.js +63 -62
- package/dist/missledger.js +5 -3
- package/dist/mod/api.d.ts +135 -0
- package/dist/mod/api.js +12 -0
- package/dist/mod/logic.d.ts +158 -0
- package/dist/mod/logic.js +244 -0
- package/dist/mod/register.d.ts +60 -0
- package/dist/mod/register.js +251 -0
- package/dist/modelids.d.ts +24 -0
- package/dist/modelids.js +65 -0
- package/dist/modelswitch.js +8 -4
- package/dist/modmeasure.d.ts +121 -0
- package/dist/modmeasure.js +310 -0
- package/dist/orgrates.d.ts +93 -0
- package/dist/orgrates.js +214 -0
- package/dist/overhead.js +11 -8
- package/dist/pack.d.ts +13 -0
- package/dist/pack.js +68 -3
- package/dist/preferences.js +2 -1
- package/dist/pricing.d.ts +26 -0
- package/dist/pricing.js +61 -7
- package/dist/progresssummaries.d.ts +148 -0
- package/dist/progresssummaries.js +248 -0
- package/dist/proxy.d.ts +1 -1
- package/dist/proxy.js +1 -1
- package/dist/prune.d.ts +8 -0
- package/dist/prune.js +11 -1
- package/dist/savings.js +8 -6
- package/dist/sessionprice.d.ts +22 -0
- package/dist/sessionprice.js +46 -14
- package/dist/spend.d.ts +46 -3
- package/dist/spend.js +86 -10
- package/dist/statusline.js +2 -2
- package/dist/subagentmodel.d.ts +12 -0
- package/dist/subagentmodel.js +17 -4
- package/dist/subagentpay.d.ts +15 -1
- package/dist/subagentpay.js +58 -25
- package/dist/subagents.js +4 -0
- package/dist/toolcwd.d.ts +14 -0
- package/dist/toolcwd.js +17 -0
- package/package.json +1 -1
package/dist/firstfix.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a bare `context-doctor` shows in a terminal with Claude Code history:
|
|
3
|
+
* the plan, not the report, and one question.
|
|
4
|
+
*
|
|
5
|
+
* `fix` lists every lever with how it was measured, what it costs in quality
|
|
6
|
+
* and what it writes: 30 to 50 lines and a question per lever. The author,
|
|
7
|
+
* who wrote every lever, applied none of them that way. So the first screen
|
|
8
|
+
* splits `fix`'s own plan (the same replays, one scan) in two:
|
|
9
|
+
* - the fixes whose quality line is "none" (`Fix.qualityFree`: the model
|
|
10
|
+
* sees the same content, or the same content moved where it can open it,
|
|
11
|
+
* on the same model), one line each with one total and ONE y/N question
|
|
12
|
+
* that applies them all through `applyFix`, as `fix --apply <ids>` does;
|
|
13
|
+
* - the ones that trade something (compacting earlier, autopilot clearing
|
|
14
|
+
* output, the subagents' model, Codex's limit), one line each with their
|
|
15
|
+
* dollars and the command that applies each, after reading it in `fix`.
|
|
16
|
+
* Nothing is written without a `y` typed in a terminal.
|
|
17
|
+
*/
|
|
18
|
+
import { money, overlaps } from "./fix.js";
|
|
19
|
+
import { priceBasis } from "./orgrates.js";
|
|
20
|
+
export function splitFirstFixes(fixes) {
|
|
21
|
+
const avail = fixes.filter((f) => f.state === "available");
|
|
22
|
+
return {
|
|
23
|
+
free: avail.filter((f) => f.qualityFree === true),
|
|
24
|
+
other: avail.filter((f) => f.qualityFree !== true),
|
|
25
|
+
applied: fixes.filter((f) => f.state === "applied"),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const fixes = (n) => `${n} fix${n === 1 ? "" : "es"}`;
|
|
29
|
+
const amount = (f) => (f.savedUsd !== undefined ? money(f.savedUsd) : "not priced").padStart(10);
|
|
30
|
+
/** The screen, everything but the question itself (under 25 lines whatever the plan). */
|
|
31
|
+
export function renderFirstScreen(s) {
|
|
32
|
+
const { free, other, applied } = splitFirstFixes(s.fixes);
|
|
33
|
+
const codex = s.codexBilledUsd ?? 0;
|
|
34
|
+
const out = [];
|
|
35
|
+
if (s.recordProblem)
|
|
36
|
+
out.push(`⚠ ${s.recordProblem}`);
|
|
37
|
+
if (codex > 0 && s.billedUsd > 0)
|
|
38
|
+
out.push(`context-doctor: your last ${s.days} days, Claude Code ${money(s.billedUsd)} of input and Codex ${money(codex)}, ${priceBasis()}`);
|
|
39
|
+
else if (codex > 0)
|
|
40
|
+
out.push(`context-doctor: your last ${s.days} days of Codex, ${money(codex)} of input ${priceBasis()}`);
|
|
41
|
+
else
|
|
42
|
+
out.push(`context-doctor: your last ${s.days} days of Claude Code, ${money(s.billedUsd)} of input ${priceBasis()}`);
|
|
43
|
+
if (s.billedUsd + codex <= 0) {
|
|
44
|
+
out.push(`No Claude Code sessions in the last ${s.days} days to measure yet, so no fix can be priced; ${s.command("fix")} once there are.`);
|
|
45
|
+
return out.join("\n");
|
|
46
|
+
}
|
|
47
|
+
const per = s.days === 30 ? "a month" : `in ${s.days} days`;
|
|
48
|
+
if (free.length) {
|
|
49
|
+
const priced = free.filter((f) => f.savedUsd !== undefined);
|
|
50
|
+
const total = priced.reduce((t, f) => t + f.savedUsd, 0);
|
|
51
|
+
const sum = priced.length ? `${money(total)} ${per}${priced.length < free.length ? ` (${free.length - priced.length} more not priced)` : ""}` : `${fixes(free.length)}, not priced`;
|
|
52
|
+
out.push("");
|
|
53
|
+
out.push(`Free of any quality cost: ${sum}`);
|
|
54
|
+
for (const f of free)
|
|
55
|
+
out.push(` ${amount(f)} ${f.title}${f.overriddenBy?.length ? " (⚠ overridden here: see fix)" : ""}`);
|
|
56
|
+
// Each lever is replayed alone; two that save part of the same dollars do not add up.
|
|
57
|
+
if (overlaps(priced).length)
|
|
58
|
+
out.push(" each measured alone; they overlap, so together a little less");
|
|
59
|
+
}
|
|
60
|
+
if (other.length) {
|
|
61
|
+
out.push("");
|
|
62
|
+
out.push(`These trade something for money; read each in ${s.command("fix")} first:`);
|
|
63
|
+
const width = Math.min(60, Math.max(...other.map((f) => f.title.length)));
|
|
64
|
+
for (const f of other)
|
|
65
|
+
out.push(` ${amount(f)} ${f.title.padEnd(width)} ${s.command(`fix --apply ${f.id}`)}`);
|
|
66
|
+
}
|
|
67
|
+
out.push("");
|
|
68
|
+
if (applied.length)
|
|
69
|
+
out.push(`Applied before: ${applied.map((f) => f.id).join(", ")}; ${s.command("fix")} shows what each saved since.`);
|
|
70
|
+
out.push(`The full report: ${s.command("savings")}. All commands: ${s.command("--help")}`);
|
|
71
|
+
if (!free.length)
|
|
72
|
+
out.push(`Nothing to apply without a quality cost here; ${s.command("fix")} shows every lever, measured.`);
|
|
73
|
+
else if (!s.ask && !s.recordProblem)
|
|
74
|
+
out.push(`Apply ${free.length === 1 ? "it" : "them"}: ${s.command(`fix --apply ${free.map((f) => f.id).join(",")}`)} (undo any time: ${s.command("fix undo")})`);
|
|
75
|
+
return out.join("\n");
|
|
76
|
+
}
|
|
77
|
+
/** The one question, for the quality-free fixes together. */
|
|
78
|
+
export function firstQuestion(n, command) {
|
|
79
|
+
return `Apply ${n === 1 ? "this fix" : `these ${n} fixes`}? (undo any time: ${command("fix undo")}) [y/N] `;
|
|
80
|
+
}
|
package/dist/fix.d.ts
CHANGED
|
@@ -27,7 +27,10 @@
|
|
|
27
27
|
* ran on before against as billed (the same token counts: an estimate);
|
|
28
28
|
* - long Bash output: the results moved to a file that the cap before left
|
|
29
29
|
* inline, priced at the requests that re-read them no more (an estimate:
|
|
30
|
-
* a file the model opens again is not counted)
|
|
30
|
+
* a file the model opens again is not counted);
|
|
31
|
+
* - subagent progress summaries: the summaries Claude Code would have
|
|
32
|
+
* written for the background subagents since (2.1.318+, which read the
|
|
33
|
+
* variable), estimated as `spend` estimates them (progresssummaries.ts).
|
|
31
34
|
*
|
|
32
35
|
* The subagents' model is the one lever with a quality cost `fix` cannot
|
|
33
36
|
* measure: it is offered with that said, applied only when named (never by
|
|
@@ -39,8 +42,9 @@ import { type ProjectPlan } from "./prune.js";
|
|
|
39
42
|
import { readLedger } from "./ledger.js";
|
|
40
43
|
import { type SubagentModelReplay } from "./subagentmodel.js";
|
|
41
44
|
import { type ToolOutputReplay } from "./tooloutput.js";
|
|
45
|
+
import { type ProgressSummaryEstimate } from "./progresssummaries.js";
|
|
42
46
|
import { type CodexCompactReport } from "./codexcompact.js";
|
|
43
|
-
export type FixId = "compact-window" | "cache-ttl" | "cache-ttl-subagents" | "autopilot" | "tool-search" | "prune" | "subagent-model" | "tool-output" | "codex-compact";
|
|
47
|
+
export type FixId = "compact-window" | "cache-ttl" | "cache-ttl-subagents" | "autopilot" | "tool-search" | "prune" | "subagent-model" | "tool-output" | "codex-compact" | "progress-summaries";
|
|
44
48
|
export interface Fix {
|
|
45
49
|
id: FixId;
|
|
46
50
|
title: string;
|
|
@@ -53,6 +57,12 @@ export interface Fix {
|
|
|
53
57
|
basis: string;
|
|
54
58
|
/** What it costs in quality, plainly. */
|
|
55
59
|
quality: string;
|
|
60
|
+
/**
|
|
61
|
+
* The quality line is "none": the model sees the same content, or the same
|
|
62
|
+
* content moved where it can still open it, and runs on the same model. A
|
|
63
|
+
* bare `context-doctor` offers these together under one question (firstfix.ts).
|
|
64
|
+
*/
|
|
65
|
+
qualityFree?: boolean;
|
|
56
66
|
/** What it writes, where. */
|
|
57
67
|
change: string;
|
|
58
68
|
state: "available" | "applied" | "not-here";
|
|
@@ -129,7 +139,17 @@ export interface FixInputs {
|
|
|
129
139
|
raw: string;
|
|
130
140
|
where: string;
|
|
131
141
|
};
|
|
142
|
+
/** The subagents' progress summaries Claude Code wrote, estimated (progresssummaries.ts). */
|
|
143
|
+
progressSummaries?: ProgressSummaryEstimate;
|
|
144
|
+
/** CLAUDE_CODE_DISABLE_AGENT_PROGRESS_SUMMARIES where it is set (progressSummariesState): never overwritten. */
|
|
145
|
+
progressSummariesSet?: {
|
|
146
|
+
value: string;
|
|
147
|
+
where: string;
|
|
148
|
+
};
|
|
132
149
|
}
|
|
150
|
+
export declare const money: (n: number) => string;
|
|
151
|
+
/** " (48%)", or " (37% of subagents)" for a share of something else. */
|
|
152
|
+
export declare const share: (f: Fix) => string;
|
|
133
153
|
export declare function planFixes(i: FixInputs): Fix[];
|
|
134
154
|
export interface FixRecord {
|
|
135
155
|
id: FixId;
|
|
@@ -198,6 +218,30 @@ export declare function applyFix(fix: Fix, deps?: FixDeps, context?: {
|
|
|
198
218
|
}>;
|
|
199
219
|
/** Undo what fix applied: every fix, or the ones named. Returns what it did, line by line. */
|
|
200
220
|
export declare function undoFixes(ids: FixId[] | undefined, deps?: FixDeps): Promise<string[]>;
|
|
221
|
+
/**
|
|
222
|
+
* Where CLAUDE_CODE_DISABLE_AGENT_PROGRESS_SUMMARIES is set, as Claude Code
|
|
223
|
+
* sees it: the highest settings file whose env names it (managed, local,
|
|
224
|
+
* project, user: each applied over the one before and over the shell), else
|
|
225
|
+
* the shell's own value. A project's or managed value that keeps them is not
|
|
226
|
+
* the user's (fixOverrides names it); the user's own one is never
|
|
227
|
+
* overwritten. `offSince`: when fix turned them off (its record).
|
|
228
|
+
* `forkGateOff`: CLAUDE_CODE_FORK_SUBAGENT off, which in a terminal session
|
|
229
|
+
* also keeps ordinary background subagents from getting summaries.
|
|
230
|
+
*/
|
|
231
|
+
export declare function progressSummariesState(deps?: {
|
|
232
|
+
home?: string;
|
|
233
|
+
cwd?: string;
|
|
234
|
+
env?: NodeJS.ProcessEnv;
|
|
235
|
+
}): {
|
|
236
|
+
set?: {
|
|
237
|
+
value: string;
|
|
238
|
+
where: string;
|
|
239
|
+
};
|
|
240
|
+
offSince?: number;
|
|
241
|
+
forkGateOff: boolean;
|
|
242
|
+
};
|
|
243
|
+
/** The summaries fix's variable stopped since `at`: the background subagents on Claude Code 2.1.318+ since, estimated as if it were not set. */
|
|
244
|
+
export declare function progressSummariesSavedSince(at: number, subagentPaths?: string[], forkGateOff?: boolean): ProgressSummaryEstimate;
|
|
201
245
|
export interface SinceResult {
|
|
202
246
|
id: FixId;
|
|
203
247
|
at: number;
|
package/dist/fix.js
CHANGED
|
@@ -27,7 +27,10 @@
|
|
|
27
27
|
* ran on before against as billed (the same token counts: an estimate);
|
|
28
28
|
* - long Bash output: the results moved to a file that the cap before left
|
|
29
29
|
* inline, priced at the requests that re-read them no more (an estimate:
|
|
30
|
-
* a file the model opens again is not counted)
|
|
30
|
+
* a file the model opens again is not counted);
|
|
31
|
+
* - subagent progress summaries: the summaries Claude Code would have
|
|
32
|
+
* written for the background subagents since (2.1.318+, which read the
|
|
33
|
+
* variable), estimated as `spend` estimates them (progresssummaries.ts).
|
|
31
34
|
*
|
|
32
35
|
* The subagents' model is the one lever with a quality cost `fix` cannot
|
|
33
36
|
* measure: it is offered with that said, applied only when named (never by
|
|
@@ -37,18 +40,20 @@ import { existsSync, mkdirSync, readFileSync, rmdirSync } from "node:fs";
|
|
|
37
40
|
import { homedir } from "node:os";
|
|
38
41
|
import { dirname, join } from "node:path";
|
|
39
42
|
import { forEachLine, listSessions, isClaudeSession } from "./session.js";
|
|
40
|
-
import {
|
|
43
|
+
import { rateCard, ratesAt } from "./pricing.js";
|
|
44
|
+
import { priceBasis } from "./orgrates.js";
|
|
41
45
|
import { contextWindowFor, realModel } from "./tokens.js";
|
|
42
|
-
import { adviseTtl, CACHE_TTL_SINCE, estimateCacheTtl } from "./cachettl.js";
|
|
46
|
+
import { adviseTtl, CACHE_TTL_SINCE, estimateCacheTtl, subagentTranscripts } from "./cachettl.js";
|
|
43
47
|
import { compareVersions, describeInstalls } from "./modelswitch.js";
|
|
44
48
|
import { ABSENT, getPath, parseSettingsText, readSettings, removeFile, sameJson, setJsonPath, SettingsError, settingsLockPath, withLock, withSettingsLock, writeAtomic } from "./settingsedit.js";
|
|
45
|
-
import { compactWindowOverrides, processEnvWhere, settingsSources, shellSet, ttlOverrides } from "./effective.js";
|
|
49
|
+
import { compactWindowOverrides, effectiveEnv, processEnvWhere, settingsSources, shellSet, ttlOverrides, underClaudeCode } from "./effective.js";
|
|
46
50
|
import { tilde } from "./claudedir.js";
|
|
47
51
|
import { applyPrune, undoPrune } from "./prune.js";
|
|
48
52
|
import { fallbackStateDir, readLedger } from "./ledger.js";
|
|
49
53
|
import { claudeDir } from "./claudedir.js";
|
|
50
54
|
import { movedFromNames, renderSubagentTypes, subagentModelSavedSince, SUBAGENT_CANDIDATE, SUBAGENT_CANDIDATE_NAME, SUBAGENT_MODEL_ENV } from "./subagentmodel.js";
|
|
51
55
|
import { BASH_OUTPUT_DEFAULT, BASH_OUTPUT_KEY, BASH_OUTPUT_SINCE, breakEven, renderToolOutputCaps, toolOutputSavedSince } from "./tooloutput.js";
|
|
56
|
+
import { disablesSummaries, estimateProgressSummaries, hostName, PROGRESS_SUMMARIES_ENV, PROGRESS_SUMMARIES_OFF, PROGRESS_SUMMARIES_SINCE } from "./progresssummaries.js";
|
|
52
57
|
import { CODEX_COMPACT_KEY, CODEX_COMPACT_LIMIT, codexCompactOverrides, codexCompactSavedSince, codexConfigPath, renderCodexLimits, setTopLevelInt, topLevelValue } from "./codexcompact.js";
|
|
53
58
|
/**
|
|
54
59
|
* The Claude Code version that first reads each setting a fix writes, from
|
|
@@ -58,14 +63,14 @@ import { CODEX_COMPACT_KEY, CODEX_COMPACT_LIMIT, codexCompactOverrides, codexCom
|
|
|
58
63
|
* the subagent variable ahead of agent definitions there). autoCompactWindow
|
|
59
64
|
* is not in 2.1.62 and the changelog does not say when it came: not named.
|
|
60
65
|
*/
|
|
61
|
-
const SINCE = { "cache-ttl": CACHE_TTL_SINCE, "cache-ttl-subagents": CACHE_TTL_SINCE, "tool-output": BASH_OUTPUT_SINCE };
|
|
66
|
+
const SINCE = { "cache-ttl": CACHE_TTL_SINCE, "cache-ttl-subagents": CACHE_TTL_SINCE, "tool-output": BASH_OUTPUT_SINCE, "progress-summaries": PROGRESS_SUMMARIES_SINCE };
|
|
62
67
|
/** Below this a priced fix is not worth a setting. */
|
|
63
68
|
const MIN_USD = 1;
|
|
64
|
-
const money = (n) => (n >= 100 ? `$${Math.round(n).toLocaleString("en-US")}` : `$${n.toFixed(2)}`);
|
|
69
|
+
export const money = (n) => (n >= 100 ? `$${Math.round(n).toLocaleString("en-US")}` : `$${n.toFixed(2)}`);
|
|
65
70
|
const pct = (x) => `${Math.round(x * 100)}%`;
|
|
66
71
|
const k = (n) => `${Math.round(n / 1000)}k`;
|
|
67
72
|
/** " (48%)", or " (37% of subagents)" for a share of something else. */
|
|
68
|
-
const share = (f) => (f.savedShare !== undefined ? ` (${pct(f.savedShare)}${f.shareOf ? ` ${f.shareOf}` : ""})` : "");
|
|
73
|
+
export const share = (f) => (f.savedShare !== undefined ? ` (${pct(f.savedShare)}${f.shareOf ? ` ${f.shareOf}` : ""})` : "");
|
|
69
74
|
export function planFixes(i) {
|
|
70
75
|
const fixes = [];
|
|
71
76
|
const where = tilde(join(claudeDir(), "settings.json"));
|
|
@@ -104,6 +109,7 @@ export function planFixes(i) {
|
|
|
104
109
|
savedShare: a.savedShare,
|
|
105
110
|
basis: `the same ${r.requests.toLocaleString("en-US")} requests priced at each lifetime (${pct(r.oneHourShare)} of writes at 1 hour as billed${a.ttl === "1h" && r.keptWarmAt1h ? `; ${r.keptWarmAt1h} cold re-writes kept warm` : ""})`,
|
|
106
111
|
quality: "none: the same content is sent; only the price of keeping it cached changes",
|
|
112
|
+
qualityFree: true,
|
|
107
113
|
change: `${where}: ${key} = "${a.ttl}" (Claude Code 2.1.243+)`,
|
|
108
114
|
state: "available",
|
|
109
115
|
value: a.ttl,
|
|
@@ -141,6 +147,7 @@ export function planFixes(i) {
|
|
|
141
147
|
title: "MCP tool search back on",
|
|
142
148
|
basis: `ENABLE_TOOL_SEARCH=${i.toolSearchOff} loads every tool definition of your ${i.mcpServers} MCP server${i.mcpServers === 1 ? "" : "s"} into every request; with search on Claude Code loads one when it is needed (Anthropic: ~77k tokens to ~8.7k on a large set, tool choice more accurate, not less)`,
|
|
143
149
|
quality: "none expected: Anthropic measured better tool choice with search on (Opus 4.5: 79.5% to 88.1%)",
|
|
150
|
+
qualityFree: true,
|
|
144
151
|
change: `${where}: env.ENABLE_TOOL_SEARCH = "auto"`,
|
|
145
152
|
state: "available",
|
|
146
153
|
value: "auto",
|
|
@@ -153,6 +160,7 @@ export function planFixes(i) {
|
|
|
153
160
|
title: `Switch off ${names.length} unused MCP server${names.length === 1 ? "" : "s"} or skill${names.length === 1 ? "" : "s"} in this project`,
|
|
154
161
|
basis: `none used in ${i.prune.sessions} sessions of this project in ${i.days} days: ${names.slice(0, 5).join(", ")}${names.length > 5 ? ", …" : ""}`,
|
|
155
162
|
quality: "none while they stay unused; undo brings them back",
|
|
163
|
+
qualityFree: true,
|
|
156
164
|
change: join(i.prune.cwd, ".claude", "settings.local.json"),
|
|
157
165
|
state: "available",
|
|
158
166
|
});
|
|
@@ -203,6 +211,8 @@ export function planFixes(i) {
|
|
|
203
211
|
shareOf: "of input, subagents included",
|
|
204
212
|
basis: `${best.moved.toLocaleString("en-US")} of ${best.results.toLocaleString("en-US")} Bash results were longer; the tokens past a 2,000-character preview priced at each later request that re-read them until a compaction (cache reads, one write); an estimate: a file the model opens again costs about ${money(each)} a time and is not counted, and the saving covers it opening up to ${pct(breakEven(best))} of them`,
|
|
205
213
|
quality: "long output goes to a file the model can still open; it sees the first 2,000 characters and the path, as it already does past 30,000",
|
|
214
|
+
// Nothing is lost, only moved (in `--apply all` for the same reason).
|
|
215
|
+
qualityFree: true,
|
|
206
216
|
change: `${where}: ${BASH_OUTPUT_KEY} = ${best.cap} (Claude Code 2.1.261+)`,
|
|
207
217
|
state: "available",
|
|
208
218
|
value: best.cap,
|
|
@@ -230,6 +240,33 @@ export function planFixes(i) {
|
|
|
230
240
|
detail: renderCodexLimits(cx, CODEX_COMPACT_LIMIT),
|
|
231
241
|
});
|
|
232
242
|
}
|
|
243
|
+
const ps = i.progressSummaries;
|
|
244
|
+
const psSet = i.progressSummariesSet;
|
|
245
|
+
if (psSet) {
|
|
246
|
+
const off = disablesSummaries(psSet.value);
|
|
247
|
+
const less = !off && ps && ps.notesUsd >= MIN_USD ? ` (turning them off would have saved about ${money(ps.notesUsd)})` : "";
|
|
248
|
+
fixes.push({ id: "progress-summaries", title: "Subagent progress summaries", basis: "set", quality: "", change: `env.${PROGRESS_SUMMARIES_ENV}`, state: off ? "applied" : "not-here", note: `${PROGRESS_SUMMARIES_ENV}=${psSet.value} in ${psSet.where}${off ? "" : `: left as you set it${less}`}`, value: psSet.value });
|
|
249
|
+
}
|
|
250
|
+
else if (ps && ps.summarized > 0 && ps.notesUsd >= MIN_USD) {
|
|
251
|
+
const billed = i.subagentModel?.billedUsd ?? 0;
|
|
252
|
+
fixes.push({
|
|
253
|
+
id: "progress-summaries",
|
|
254
|
+
title: "Subagent progress summaries off",
|
|
255
|
+
savedUsd: ps.notesUsd,
|
|
256
|
+
savedShare: billed > 0 ? ps.notesUsd / billed : undefined,
|
|
257
|
+
shareOf: "of subagents",
|
|
258
|
+
basis: `${ps.calls.toLocaleString("en-US")} summaries for ${ps.summarized} background subagent${ps.summarized === 1 ? "" : "s"}, one each 30 s while one ran and its transcript changed; no transcript records them, so an estimate: ~1,850 tokens of notes each (what Anthropic serves since November 2026), ${money(ps.forkUsd)} if each sent the whole context, as before`,
|
|
259
|
+
quality: "none to the work: a summary never enters the subagent's context; you lose the 3-5 word progress line on a running subagent's task row",
|
|
260
|
+
qualityFree: true,
|
|
261
|
+
change: `${where}: env.${PROGRESS_SUMMARIES_ENV} = "${PROGRESS_SUMMARIES_OFF}" (Claude Code ${PROGRESS_SUMMARIES_SINCE}+)`,
|
|
262
|
+
state: "available",
|
|
263
|
+
value: PROGRESS_SUMMARIES_OFF,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
else if (ps && ps.summarized === 0 && (ps.none.host ?? 0) > 0) {
|
|
267
|
+
const n = ps.none.host;
|
|
268
|
+
fixes.push({ id: "progress-summaries", title: "Subagent progress summaries", basis: "", quality: "", change: "", state: "not-here", note: `your ${n} background subagent${n === 1 ? "" : "s"} ran in ${ps.hosts.map(hostName).join(" and ")}, where Claude Code writes no progress summaries: nothing to turn off` });
|
|
269
|
+
}
|
|
233
270
|
for (const f of fixes) {
|
|
234
271
|
const o = i.overrides?.[f.id];
|
|
235
272
|
if (o?.length && f.state === "available")
|
|
@@ -305,9 +342,12 @@ const KEY_PATH = {
|
|
|
305
342
|
"tool-search": ["env", "ENABLE_TOOL_SEARCH"],
|
|
306
343
|
"subagent-model": ["env", SUBAGENT_MODEL_ENV],
|
|
307
344
|
"tool-output": [BASH_OUTPUT_KEY],
|
|
345
|
+
"progress-summaries": ["env", PROGRESS_SUMMARIES_ENV],
|
|
308
346
|
};
|
|
309
347
|
/** Fixes that never overwrite a value already there: the user set it. */
|
|
310
|
-
const YOURS = new Set(["subagent-model", "tool-output"]);
|
|
348
|
+
const YOURS = new Set(["subagent-model", "tool-output", "progress-summaries"]);
|
|
349
|
+
/** The environment variable a settings fix writes, when the shell's own value is the user's too. */
|
|
350
|
+
const SHELL_ENV = { "subagent-model": SUBAGENT_MODEL_ENV, "progress-summaries": PROGRESS_SUMMARIES_ENV };
|
|
311
351
|
/** Fixes with a quality cost not measured here: applied only when named, never by `--apply all`. */
|
|
312
352
|
const NAMED_ONLY = new Set(["subagent-model"]);
|
|
313
353
|
/** What would keep this fix's value from taking effect, as Claude Code merges settings. */
|
|
@@ -338,6 +378,10 @@ export function fixOverrides(id, deps = {}) {
|
|
|
338
378
|
out.push(`${SUBAGENT_MODEL_ENV}=${s.settings.env[SUBAGENT_MODEL_ENV]} in ${tilde(s.path)} env`);
|
|
339
379
|
return out;
|
|
340
380
|
}
|
|
381
|
+
if (id === "progress-summaries") {
|
|
382
|
+
// A project's, local or managed env is applied over the user's: a value there that does not turn them off wins.
|
|
383
|
+
return sources.filter((s) => s.name !== "user" && s.settings.env?.[PROGRESS_SUMMARIES_ENV] !== undefined && s.settings.env[PROGRESS_SUMMARIES_ENV] !== null && !disablesSummaries(s.settings.env[PROGRESS_SUMMARIES_ENV])).map((s) => `${PROGRESS_SUMMARIES_ENV}=${s.settings.env[PROGRESS_SUMMARIES_ENV]} in ${tilde(s.path)} env`);
|
|
384
|
+
}
|
|
341
385
|
if (id === "tool-output") {
|
|
342
386
|
// Merged settings: a project's or managed value wins over the user's (BASH_MAX_OUTPUT_LENGTH does not: the setting replaces it).
|
|
343
387
|
return sources.filter((s) => s.name !== "user" && s.settings[BASH_OUTPUT_KEY] !== undefined).map((s) => `${BASH_OUTPUT_KEY} ${JSON.stringify(s.settings[BASH_OUTPUT_KEY])} in ${tilde(s.path)}`);
|
|
@@ -475,9 +519,10 @@ export async function applyFix(fix, deps = {}, context = {}) {
|
|
|
475
519
|
// The environment Claude Code starts in is the user's too: a value there is theirs (settings.json would override it).
|
|
476
520
|
// Not a value Claude Code copied from a settings file into the session this runs in, nor fix's own left from before an undo.
|
|
477
521
|
const env = deps.env ?? process.env;
|
|
478
|
-
const
|
|
479
|
-
|
|
480
|
-
|
|
522
|
+
const name = SHELL_ENV[fix.id];
|
|
523
|
+
const shell = name && shellSet(name, settingsSources({ home: deps.home, cwd: deps.cwd, env }), env, String(fix.value)) ? env[name] : undefined;
|
|
524
|
+
if (name && shell)
|
|
525
|
+
return { ok: false, lines: [`✗ ${fix.id}: ${processEnvWhere(name, shell, env)}, a value you set: left as it is. Nothing was changed.`] };
|
|
481
526
|
const lines = applySetting(fix, home, at, { oneHourShareBefore: context.oneHourShare, modelsBefore: context.modelsBefore });
|
|
482
527
|
const over = fixOverrides(fix.id, deps);
|
|
483
528
|
if (over.length)
|
|
@@ -633,6 +678,41 @@ export async function undoFixes(ids, deps = {}) {
|
|
|
633
678
|
}
|
|
634
679
|
return lines;
|
|
635
680
|
}
|
|
681
|
+
// -- What each applied fix saved since ------------------------------------------------
|
|
682
|
+
/**
|
|
683
|
+
* Where CLAUDE_CODE_DISABLE_AGENT_PROGRESS_SUMMARIES is set, as Claude Code
|
|
684
|
+
* sees it: the highest settings file whose env names it (managed, local,
|
|
685
|
+
* project, user: each applied over the one before and over the shell), else
|
|
686
|
+
* the shell's own value. A project's or managed value that keeps them is not
|
|
687
|
+
* the user's (fixOverrides names it); the user's own one is never
|
|
688
|
+
* overwritten. `offSince`: when fix turned them off (its record).
|
|
689
|
+
* `forkGateOff`: CLAUDE_CODE_FORK_SUBAGENT off, which in a terminal session
|
|
690
|
+
* also keeps ordinary background subagents from getting summaries.
|
|
691
|
+
*/
|
|
692
|
+
export function progressSummariesState(deps = {}) {
|
|
693
|
+
const env = deps.env ?? process.env;
|
|
694
|
+
const sources = settingsSources({ home: deps.home, cwd: deps.cwd, env });
|
|
695
|
+
const fork = effectiveEnv("CLAUDE_CODE_FORK_SUBAGENT", sources, env);
|
|
696
|
+
const forkGateOff = !!fork && ["0", "false", "no", "off"].includes(fork.value.trim().toLowerCase());
|
|
697
|
+
const rec = readFixRecords(deps.home).find((r) => r.id === "progress-summaries");
|
|
698
|
+
const off = (value, where) => ({ set: { value, where }, ...(disablesSummaries(value) && rec ? { offSince: rec.at } : {}), forkGateOff });
|
|
699
|
+
for (const s of sources) {
|
|
700
|
+
const v = s.settings.env?.[PROGRESS_SUMMARIES_ENV];
|
|
701
|
+
if (v === undefined || v === null || String(v).trim() === "")
|
|
702
|
+
continue;
|
|
703
|
+
if (disablesSummaries(v) || s.name === "user")
|
|
704
|
+
return off(String(v), `${tilde(s.path)} env`);
|
|
705
|
+
return { forkGateOff };
|
|
706
|
+
}
|
|
707
|
+
// The shell's value, unless it is fix's own copied into a session started before an undo.
|
|
708
|
+
if (shellSet(PROGRESS_SUMMARIES_ENV, sources, env, PROGRESS_SUMMARIES_OFF))
|
|
709
|
+
return off(env[PROGRESS_SUMMARIES_ENV], underClaudeCode(env) ? "this Claude Code session's environment" : "the environment");
|
|
710
|
+
return { forkGateOff };
|
|
711
|
+
}
|
|
712
|
+
/** The summaries fix's variable stopped since `at`: the background subagents on Claude Code 2.1.318+ since, estimated as if it were not set. */
|
|
713
|
+
export function progressSummariesSavedSince(at, subagentPaths, forkGateOff = false) {
|
|
714
|
+
return estimateProgressSummaries(subagentPaths ?? subagentTranscripts(at), { since: at, minVersion: PROGRESS_SUMMARIES_SINCE, forkGateOff });
|
|
715
|
+
}
|
|
636
716
|
/**
|
|
637
717
|
* Compactions since `since` that came before the old window, priced: every
|
|
638
718
|
* later request in that session re-read less context, until the session
|
|
@@ -674,26 +754,29 @@ export function compactWindowSavingsSince(since, previousWindow, paths) {
|
|
|
674
754
|
return;
|
|
675
755
|
lastId = typeof msg.id === "string" ? msg.id : undefined;
|
|
676
756
|
const model = realModel(msg.model);
|
|
677
|
-
const price = pricingFor(model);
|
|
678
757
|
const u = msg.usage;
|
|
758
|
+
// As the replays price (requestCost's rates): each prompt at its own tier, so the request a
|
|
759
|
+
// compaction avoided and the one it made can bill at different rates (Haiku 5.5 over 100k).
|
|
760
|
+
const card = rateCard(model, u, Number.isFinite(at) ? at : undefined);
|
|
679
761
|
const total = (u.input_tokens ?? 0) + (u.cache_read_input_tokens ?? 0) + (u.cache_creation_input_tokens ?? 0);
|
|
680
762
|
if (pendingPre !== undefined) {
|
|
681
763
|
const oldTrigger = 0.97 * (previousWindow ?? contextWindowFor(model) ?? 200_000);
|
|
682
764
|
// Only a compaction the old window would not have made yet.
|
|
683
|
-
if (pendingPre < 0.9 * oldTrigger &&
|
|
765
|
+
if (pendingPre < 0.9 * oldTrigger && card) {
|
|
684
766
|
episode = { pre: pendingPre, post: total, trigger: oldTrigger, open: true };
|
|
685
767
|
compactions++;
|
|
686
|
-
|
|
768
|
+
const p = ratesAt(card, pendingPre);
|
|
769
|
+
usd -= (pendingPre * p.cacheReadPerM + 20_000 * p.outputPerM) / 1e6;
|
|
687
770
|
}
|
|
688
771
|
pendingPre = undefined;
|
|
689
772
|
return;
|
|
690
773
|
}
|
|
691
|
-
if (episode?.open &&
|
|
774
|
+
if (episode?.open && card && episode.post !== undefined) {
|
|
692
775
|
const cf = episode.pre + Math.max(0, total - episode.post);
|
|
693
776
|
if (cf >= episode.trigger)
|
|
694
777
|
episode.open = false;
|
|
695
778
|
else
|
|
696
|
-
usd += ((cf - total
|
|
779
|
+
usd += (cf * ratesAt(card, cf).cacheReadPerM - total * ratesAt(card, total).cacheReadPerM) / 1e6;
|
|
697
780
|
}
|
|
698
781
|
});
|
|
699
782
|
}
|
|
@@ -734,6 +817,10 @@ export function savedSince(records, opts = {}) {
|
|
|
734
817
|
const s = toolOutputSavedSince(r.at, typeof r.previous === "number" ? r.previous : BASH_OUTPUT_DEFAULT, paths);
|
|
735
818
|
out.push({ id: r.id, at: r.at, savedUsd: s.moved ? s.savedUsd : undefined, detail: s.moved ? `estimated: ${s.moved.toLocaleString("en-US")} Bash results moved to a file that were inline before, priced at the requests that would have re-read them; files the model opened again not counted` : "no Bash output over the cap since" });
|
|
736
819
|
}
|
|
820
|
+
else if (r.id === "progress-summaries") {
|
|
821
|
+
const s = progressSummariesSavedSince(r.at, opts.subagentPaths);
|
|
822
|
+
out.push({ id: r.id, at: r.at, savedUsd: s.summarized ? s.notesUsd : undefined, detail: s.summarized ? `estimated: ${s.calls.toLocaleString("en-US")} summaries it stopped for ${s.summarized} background subagent${s.summarized === 1 ? "" : "s"} on Claude Code ${PROGRESS_SUMMARIES_SINCE}+, as notes (${money(s.forkUsd)} at the whole context)` : "no background subagent in a terminal session since" });
|
|
823
|
+
}
|
|
737
824
|
else if (r.id === "autopilot") {
|
|
738
825
|
const ledger = opts.ledger ?? readLedger();
|
|
739
826
|
const ev = ledger.filter((e) => e.ev === "proxy" && e.ts >= r.at);
|
|
@@ -757,6 +844,7 @@ const LABEL = {
|
|
|
757
844
|
"subagent-model": "Subagent model",
|
|
758
845
|
"tool-output": "Long Bash output",
|
|
759
846
|
"codex-compact": "Codex auto-compact limit",
|
|
847
|
+
"progress-summaries": "Subagent progress summaries",
|
|
760
848
|
};
|
|
761
849
|
/**
|
|
762
850
|
* Priced levers that save part of the same dollars, and why: each is
|
|
@@ -772,6 +860,7 @@ const OVERLAPS = [
|
|
|
772
860
|
["tool-output", "cache-ttl-subagents", "the subagents' cache lifetime changes how often their long output is written to the cache again"],
|
|
773
861
|
["tool-output", "subagent-model", "long output in subagents is priced at the subagents' model, which subagent-model changes"],
|
|
774
862
|
["subagent-model", "cache-ttl-subagents", "the subagents' cache is priced at their model's rates, which subagent-model changes"],
|
|
863
|
+
["progress-summaries", "subagent-model", "the progress summaries run on the subagents' model, which subagent-model changes"],
|
|
775
864
|
];
|
|
776
865
|
/** The overlap lines for the priced fixes in a plan, "a and b: why;" each. */
|
|
777
866
|
export function overlaps(fixes) {
|
|
@@ -785,11 +874,11 @@ export function renderFixPlan(days, billedUsd, fixes, since, command = (s) => `c
|
|
|
785
874
|
out.push("context-doctor fix: what to change, ranked by what it saves you");
|
|
786
875
|
// Codex's input named beside Claude Code's when there is some; alone on a machine with only Codex.
|
|
787
876
|
if (codexBilledUsd > 0 && billedUsd > 0)
|
|
788
|
-
out.push(`Last ${days} days of your sessions: Claude Code ${money(billedUsd)} of input, Codex ${money(codexBilledUsd)},
|
|
877
|
+
out.push(`Last ${days} days of your sessions: Claude Code ${money(billedUsd)} of input, Codex ${money(codexBilledUsd)}, ${priceBasis()}`);
|
|
789
878
|
else if (codexBilledUsd > 0)
|
|
790
|
-
out.push(`Last ${days} days of your Codex sessions, ${money(codexBilledUsd)} of input
|
|
879
|
+
out.push(`Last ${days} days of your Codex sessions, ${money(codexBilledUsd)} of input ${priceBasis()}`);
|
|
791
880
|
else
|
|
792
|
-
out.push(`Last ${days} days of your Claude Code sessions, ${money(billedUsd)} of input
|
|
881
|
+
out.push(`Last ${days} days of your Claude Code sessions, ${money(billedUsd)} of input ${priceBasis()}`);
|
|
793
882
|
out.push("─".repeat(66));
|
|
794
883
|
const avail = fixes.filter((f) => f.state === "available");
|
|
795
884
|
// No input billed: there is no history to measure, which is not "all applied".
|
|
@@ -845,7 +934,7 @@ export function renderFixPlan(days, billedUsd, fixes, since, command = (s) => `c
|
|
|
845
934
|
if (avail.length) {
|
|
846
935
|
out.push(`Apply: ${command("fix")} in a terminal asks about each one; or ${command(`fix --apply ${avail.map((f) => f.id).join(",")}`)}`);
|
|
847
936
|
}
|
|
848
|
-
out.push(`Undo everything fix applied: ${command("fix undo")}. Dollars
|
|
937
|
+
out.push(`Undo everything fix applied: ${command("fix undo")}. Dollars ${priceBasis(false)}; on a subscription the same tokens come out of your usage limit.`);
|
|
849
938
|
return out.join("\n");
|
|
850
939
|
}
|
|
851
940
|
/** What `fix` says on a machine with no Claude Code sessions in the period: savings' wording, and what to do. */
|
package/dist/hook.js
CHANGED
|
@@ -22,7 +22,7 @@ import { parseSessionFile } from "./session.js";
|
|
|
22
22
|
import { formatTokens, CHARS_PER_TOKEN, LARGEST_WINDOW } from "./tokens.js";
|
|
23
23
|
import { ensureProxyUp } from "./autopilot.js";
|
|
24
24
|
import { autoCompactsAt, detectColdResume, renderColdResume, renderColdResumeNotice, resumeVerdict, sessionWriteMultiplier, withResumeVerdict } from "./coldresume.js";
|
|
25
|
-
import { formatUsd,
|
|
25
|
+
import { formatUsd, rateCard, ratesAt } from "./pricing.js";
|
|
26
26
|
import { checkBudget, loadConfig } from "./config.js";
|
|
27
27
|
import { modelSwitchMessage } from "./modelswitch.js";
|
|
28
28
|
import { compactFacts, compactInstructions } from "./precompact.js";
|
|
@@ -30,6 +30,7 @@ import { fanoutHook, subagentCosts } from "./fanout.js";
|
|
|
30
30
|
import { claudeDir } from "./claudedir.js";
|
|
31
31
|
import { budgetVerdict } from "./budget.js";
|
|
32
32
|
import { renderSessionPrice, sessionPriceDue } from "./sessionprice.js";
|
|
33
|
+
import { tailUsage } from "./statusline.js";
|
|
33
34
|
/** Default nudge threshold; a project budget or env var can lower/raise it. */
|
|
34
35
|
const DEFAULT_WARN_TOKENS = 80_000;
|
|
35
36
|
/**
|
|
@@ -438,7 +439,10 @@ export async function runHook(app) {
|
|
|
438
439
|
// from the transcript's tail: Claude Code's main thread has mostly
|
|
439
440
|
// written the 1-hour cache, at 2x input, where a flat 1.25x quoted the
|
|
440
441
|
// cold message 37% low (5-minute writes stay at 1.25x).
|
|
441
|
-
|
|
442
|
+
// At the rates the next request bills, as the session price's line says them (rateCard): fast mode
|
|
443
|
+
// and US-only as the last reply recorded, the tier of a prompt this size, today's price.
|
|
444
|
+
const card = rateCard(model, cursor ? undefined : tailUsage(transcriptPath)?.billing);
|
|
445
|
+
const pricing = card && ratesAt(card, liveTokens);
|
|
442
446
|
const cachedUsd = pricing ? (liveTokens * pricing.cacheReadPerM) / 1e6 : undefined;
|
|
443
447
|
const coldUsd = pricing ? (liveTokens * pricing.inputPerM * sessionWriteMultiplier(transcriptPath)) / 1e6 : undefined;
|
|
444
448
|
// Cursor's agent transcript records tool calls but not their output, and
|
package/dist/httpguard.d.ts
CHANGED
|
@@ -48,6 +48,19 @@ export declare function hostName(hostHeader: string): string;
|
|
|
48
48
|
export declare function makeGuard(bindHost: string, allowedHosts?: string, allowedOrigins?: string, env?: NodeJS.ProcessEnv, opts?: {
|
|
49
49
|
ipLiterals?: boolean;
|
|
50
50
|
}): HttpGuard;
|
|
51
|
+
/**
|
|
52
|
+
* What to say when the --http server listens beyond this machine: it has no
|
|
53
|
+
* sign-in, so anyone who can reach the address can call its tools (and,
|
|
54
|
+
* with --store-handoffs, save handoffs on this machine). On a host or behind
|
|
55
|
+
* a tunnel for ChatGPT that is the point, so it is said, not refused, as the
|
|
56
|
+
* proxy says it. Undefined on a loopback address.
|
|
57
|
+
*/
|
|
58
|
+
export declare function exposureWarning(host: string, storeHandoffs?: boolean): string | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* The --port value: a port number, 0 for one the system picks, or the
|
|
61
|
+
* default when absent or not a port (0 used to fall back to 8808).
|
|
62
|
+
*/
|
|
63
|
+
export declare function portArg(raw: string | undefined, fallback?: number): number;
|
|
51
64
|
/** Why this request may not reach /mcp, or undefined when it may. */
|
|
52
65
|
export declare function refusal(guard: HttpGuard, headers: IncomingMessage["headers"]): string | undefined;
|
|
53
66
|
/**
|
package/dist/httpguard.js
CHANGED
|
@@ -54,6 +54,28 @@ export function makeGuard(bindHost, allowedHosts, allowedOrigins, env = process.
|
|
|
54
54
|
hosts.add(bind);
|
|
55
55
|
return { hosts, origins, ipLiterals: opts.ipLiterals };
|
|
56
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* What to say when the --http server listens beyond this machine: it has no
|
|
59
|
+
* sign-in, so anyone who can reach the address can call its tools (and,
|
|
60
|
+
* with --store-handoffs, save handoffs on this machine). On a host or behind
|
|
61
|
+
* a tunnel for ChatGPT that is the point, so it is said, not refused, as the
|
|
62
|
+
* proxy says it. Undefined on a loopback address.
|
|
63
|
+
*/
|
|
64
|
+
export function exposureWarning(host, storeHandoffs = false) {
|
|
65
|
+
const h = hostName(host.includes(":") && !host.startsWith("[") ? `[${host}]` : host);
|
|
66
|
+
if (h === "localhost" || h === "::1" || /^127\.\d+\.\d+\.\d+$/.test(h) || /^::ffff:127\./.test(h))
|
|
67
|
+
return undefined;
|
|
68
|
+
return (`WARNING: listening on ${host}, beyond this machine, with no sign-in: anyone who can reach it can call its tools${storeHandoffs ? " and save handoffs here (--store-handoffs)" : ""}.\n` +
|
|
69
|
+
"Put it behind your tunnel's or reverse proxy's authentication unless only you can reach this address.");
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The --port value: a port number, 0 for one the system picks, or the
|
|
73
|
+
* default when absent or not a port (0 used to fall back to 8808).
|
|
74
|
+
*/
|
|
75
|
+
export function portArg(raw, fallback = 8808) {
|
|
76
|
+
const n = Number(raw);
|
|
77
|
+
return raw !== undefined && raw.trim() !== "" && Number.isInteger(n) && n >= 0 && n <= 65535 ? n : fallback;
|
|
78
|
+
}
|
|
57
79
|
/** Why this request may not reach /mcp, or undefined when it may. */
|
|
58
80
|
export function refusal(guard, headers) {
|
|
59
81
|
if (guard.hosts !== "*") {
|
package/dist/install.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* `context-doctor uninstall` reverses it.
|
|
8
8
|
*/
|
|
9
9
|
import { type ClaudeCodeInstall, type ModelSwitchReadiness } from "./modelswitch.js";
|
|
10
|
+
import { type ModReadiness } from "./claudeplugin.js";
|
|
10
11
|
export declare function geminiSettingsPath(): string;
|
|
11
12
|
/**
|
|
12
13
|
* Gemini CLI reads its settings.json through strip-json-comments
|
|
@@ -45,15 +46,7 @@ export declare function launcherNamesMissingPackage(entry: {
|
|
|
45
46
|
command?: unknown;
|
|
46
47
|
args?: unknown;
|
|
47
48
|
} | undefined): boolean;
|
|
48
|
-
|
|
49
|
-
* The Claude Code plugin's key in enabledPlugins: "<plugin>@<marketplace>".
|
|
50
|
-
* Our marketplace (.claude-plugin/marketplace.json) is named context-doctor
|
|
51
|
-
* and lists one plugin, context-doctor, so the official key is
|
|
52
|
-
* "context-doctor@context-doctor"; a copy listed in another marketplace keeps
|
|
53
|
-
* the plugin name, so any "context-doctor@…" key is ours.
|
|
54
|
-
*/
|
|
55
|
-
export declare const PLUGIN_KEY = "context-doctor@context-doctor";
|
|
56
|
-
export declare function isOurPluginKey(key: string): boolean;
|
|
49
|
+
export { PLUGIN_KEY, isOurPluginKey } from "./claudeplugin.js";
|
|
57
50
|
/**
|
|
58
51
|
* Is the context-doctor plugin switched on in the user's Claude Code
|
|
59
52
|
* settings? The plugin brings its own MCP server, skills and hooks, so
|
|
@@ -63,6 +56,25 @@ export declare function isOurPluginKey(key: string): boolean;
|
|
|
63
56
|
export declare function claudePluginEnabled(home?: string): boolean;
|
|
64
57
|
/** What `install` put into Claude Code that the plugin also provides, by name. */
|
|
65
58
|
export declare function claudeInstalledCopies(home?: string): string[];
|
|
59
|
+
/**
|
|
60
|
+
* How install serves Claude Code this run (claudeplugin.ts has the why):
|
|
61
|
+
* through the plugin (`ours`: the keys are install's to write and to take
|
|
62
|
+
* out again; otherwise the user enabled it), or with install's own MCP
|
|
63
|
+
* server, skill and hooks: the plugin turned off by the user ("off"), a
|
|
64
|
+
* Claude Code here that predates mods ("old"), or no version found
|
|
65
|
+
* ("unknown"). Settings are shared by every Claude Code on the machine, so
|
|
66
|
+
* one route serves them all.
|
|
67
|
+
*/
|
|
68
|
+
export type ClaudeCodeRoute = {
|
|
69
|
+
via: "plugin";
|
|
70
|
+
ours: boolean;
|
|
71
|
+
readiness: ModReadiness;
|
|
72
|
+
} | {
|
|
73
|
+
via: "hooks";
|
|
74
|
+
why: "off" | "old" | "unknown";
|
|
75
|
+
readiness: ModReadiness;
|
|
76
|
+
};
|
|
77
|
+
export declare function claudeCodeRoute(readiness?: ModReadiness): ClaudeCodeRoute;
|
|
66
78
|
/**
|
|
67
79
|
* A config that configures nothing: `{}`, or only empty `mcpServers` /
|
|
68
80
|
* `hooks` containers (plus `extraKeys`, e.g. the `version` install writes
|