context-doctor 0.46.0 → 0.48.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 +9 -4
- package/dist/ab.d.ts +51 -3
- package/dist/ab.js +71 -28
- package/dist/abclaude.d.ts +167 -0
- package/dist/abclaude.js +511 -0
- package/dist/abstore.d.ts +46 -0
- package/dist/abstore.js +58 -0
- package/dist/autopilot.js +9 -5
- package/dist/blob.js +66 -12
- package/dist/budget.d.ts +8 -2
- package/dist/budget.js +30 -7
- package/dist/ci.js +2 -1
- package/dist/claudeplugin.d.ts +97 -0
- package/dist/claudeplugin.js +142 -0
- package/dist/cli.js +128 -36
- package/dist/compactcost.d.ts +74 -0
- package/dist/compactcost.js +115 -0
- package/dist/cursor.js +2 -0
- package/dist/doctor.js +90 -18
- package/dist/extract.js +4 -3
- package/dist/fanout.d.ts +15 -0
- package/dist/fanout.js +30 -9
- package/dist/firstfix.d.ts +43 -0
- package/dist/firstfix.js +80 -0
- package/dist/fix.d.ts +53 -4
- package/dist/fix.js +101 -13
- package/dist/httpguard.d.ts +13 -0
- package/dist/httpguard.js +22 -0
- package/dist/install.d.ts +21 -9
- package/dist/install.js +213 -40
- package/dist/limits.d.ts +5 -0
- package/dist/limits.js +26 -2
- package/dist/mcp.d.ts +4 -0
- package/dist/mcp.js +142 -97
- package/dist/mcpclient.js +73 -42
- package/dist/missledger.js +5 -3
- package/dist/mod/api.d.ts +8 -2
- package/dist/mod/api.js +2 -2
- package/dist/mod/logic.d.ts +13 -1
- package/dist/mod/logic.js +24 -2
- package/dist/mod/register.d.ts +2 -0
- package/dist/mod/register.js +19 -5
- package/dist/modelids.d.ts +62 -3
- package/dist/modelids.js +156 -8
- package/dist/modelswitch.js +8 -4
- package/dist/modmeasure.js +13 -1
- package/dist/orgrates.d.ts +18 -0
- package/dist/orgrates.js +51 -2
- package/dist/pack.d.ts +13 -0
- package/dist/pack.js +38 -2
- package/dist/preferences.js +2 -1
- package/dist/pricing.d.ts +8 -0
- package/dist/pricing.js +30 -2
- 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/spend.d.ts +34 -0
- package/dist/spend.js +48 -4
- package/dist/subagentmodel.d.ts +12 -0
- package/dist/subagentmodel.js +17 -4
- package/dist/subagentpay.d.ts +8 -0
- package/dist/subagentpay.js +8 -1
- package/dist/toolcwd.d.ts +14 -0
- package/dist/toolcwd.js +17 -0
- package/package.json +6 -3
package/dist/fix.js
CHANGED
|
@@ -27,11 +27,16 @@
|
|
|
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
|
-
* measure
|
|
34
|
-
*
|
|
36
|
+
* measure from history: its quality line quotes the newest `ab --via
|
|
37
|
+
* claude-code` comparison when there is one (abstore.ts), and says so when
|
|
38
|
+
* there is none. It is applied only when named (never by `--apply all`),
|
|
39
|
+
* and never over a value the user set.
|
|
35
40
|
*/
|
|
36
41
|
import { existsSync, mkdirSync, readFileSync, rmdirSync } from "node:fs";
|
|
37
42
|
import { homedir } from "node:os";
|
|
@@ -40,16 +45,18 @@ import { forEachLine, listSessions, isClaudeSession } from "./session.js";
|
|
|
40
45
|
import { rateCard, ratesAt } from "./pricing.js";
|
|
41
46
|
import { priceBasis } from "./orgrates.js";
|
|
42
47
|
import { contextWindowFor, realModel } from "./tokens.js";
|
|
43
|
-
import { adviseTtl, CACHE_TTL_SINCE, estimateCacheTtl } from "./cachettl.js";
|
|
48
|
+
import { adviseTtl, CACHE_TTL_SINCE, estimateCacheTtl, subagentTranscripts } from "./cachettl.js";
|
|
44
49
|
import { compareVersions, describeInstalls } from "./modelswitch.js";
|
|
45
50
|
import { ABSENT, getPath, parseSettingsText, readSettings, removeFile, sameJson, setJsonPath, SettingsError, settingsLockPath, withLock, withSettingsLock, writeAtomic } from "./settingsedit.js";
|
|
46
|
-
import { compactWindowOverrides, processEnvWhere, settingsSources, shellSet, ttlOverrides } from "./effective.js";
|
|
51
|
+
import { compactWindowOverrides, effectiveEnv, processEnvWhere, settingsSources, shellSet, ttlOverrides, underClaudeCode } from "./effective.js";
|
|
47
52
|
import { tilde } from "./claudedir.js";
|
|
48
53
|
import { applyPrune, undoPrune } from "./prune.js";
|
|
49
54
|
import { fallbackStateDir, readLedger } from "./ledger.js";
|
|
50
55
|
import { claudeDir } from "./claudedir.js";
|
|
56
|
+
import { comparisonLine } from "./abstore.js";
|
|
51
57
|
import { movedFromNames, renderSubagentTypes, subagentModelSavedSince, SUBAGENT_CANDIDATE, SUBAGENT_CANDIDATE_NAME, SUBAGENT_MODEL_ENV } from "./subagentmodel.js";
|
|
52
58
|
import { BASH_OUTPUT_DEFAULT, BASH_OUTPUT_KEY, BASH_OUTPUT_SINCE, breakEven, renderToolOutputCaps, toolOutputSavedSince } from "./tooloutput.js";
|
|
59
|
+
import { disablesSummaries, estimateProgressSummaries, hostName, PROGRESS_SUMMARIES_ENV, PROGRESS_SUMMARIES_OFF, PROGRESS_SUMMARIES_SINCE } from "./progresssummaries.js";
|
|
53
60
|
import { CODEX_COMPACT_KEY, CODEX_COMPACT_LIMIT, codexCompactOverrides, codexCompactSavedSince, codexConfigPath, renderCodexLimits, setTopLevelInt, topLevelValue } from "./codexcompact.js";
|
|
54
61
|
/**
|
|
55
62
|
* The Claude Code version that first reads each setting a fix writes, from
|
|
@@ -59,14 +66,14 @@ import { CODEX_COMPACT_KEY, CODEX_COMPACT_LIMIT, codexCompactOverrides, codexCom
|
|
|
59
66
|
* the subagent variable ahead of agent definitions there). autoCompactWindow
|
|
60
67
|
* is not in 2.1.62 and the changelog does not say when it came: not named.
|
|
61
68
|
*/
|
|
62
|
-
const SINCE = { "cache-ttl": CACHE_TTL_SINCE, "cache-ttl-subagents": CACHE_TTL_SINCE, "tool-output": BASH_OUTPUT_SINCE };
|
|
69
|
+
const SINCE = { "cache-ttl": CACHE_TTL_SINCE, "cache-ttl-subagents": CACHE_TTL_SINCE, "tool-output": BASH_OUTPUT_SINCE, "progress-summaries": PROGRESS_SUMMARIES_SINCE };
|
|
63
70
|
/** Below this a priced fix is not worth a setting. */
|
|
64
71
|
const MIN_USD = 1;
|
|
65
|
-
const money = (n) => (n >= 100 ? `$${Math.round(n).toLocaleString("en-US")}` : `$${n.toFixed(2)}`);
|
|
72
|
+
export const money = (n) => (n >= 100 ? `$${Math.round(n).toLocaleString("en-US")}` : `$${n.toFixed(2)}`);
|
|
66
73
|
const pct = (x) => `${Math.round(x * 100)}%`;
|
|
67
74
|
const k = (n) => `${Math.round(n / 1000)}k`;
|
|
68
75
|
/** " (48%)", or " (37% of subagents)" for a share of something else. */
|
|
69
|
-
const share = (f) => (f.savedShare !== undefined ? ` (${pct(f.savedShare)}${f.shareOf ? ` ${f.shareOf}` : ""})` : "");
|
|
76
|
+
export const share = (f) => (f.savedShare !== undefined ? ` (${pct(f.savedShare)}${f.shareOf ? ` ${f.shareOf}` : ""})` : "");
|
|
70
77
|
export function planFixes(i) {
|
|
71
78
|
const fixes = [];
|
|
72
79
|
const where = tilde(join(claudeDir(), "settings.json"));
|
|
@@ -105,6 +112,7 @@ export function planFixes(i) {
|
|
|
105
112
|
savedShare: a.savedShare,
|
|
106
113
|
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` : ""})`,
|
|
107
114
|
quality: "none: the same content is sent; only the price of keeping it cached changes",
|
|
115
|
+
qualityFree: true,
|
|
108
116
|
change: `${where}: ${key} = "${a.ttl}" (Claude Code 2.1.243+)`,
|
|
109
117
|
state: "available",
|
|
110
118
|
value: a.ttl,
|
|
@@ -142,6 +150,7 @@ export function planFixes(i) {
|
|
|
142
150
|
title: "MCP tool search back on",
|
|
143
151
|
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)`,
|
|
144
152
|
quality: "none expected: Anthropic measured better tool choice with search on (Opus 4.5: 79.5% to 88.1%)",
|
|
153
|
+
qualityFree: true,
|
|
145
154
|
change: `${where}: env.ENABLE_TOOL_SEARCH = "auto"`,
|
|
146
155
|
state: "available",
|
|
147
156
|
value: "auto",
|
|
@@ -154,6 +163,7 @@ export function planFixes(i) {
|
|
|
154
163
|
title: `Switch off ${names.length} unused MCP server${names.length === 1 ? "" : "s"} or skill${names.length === 1 ? "" : "s"} in this project`,
|
|
155
164
|
basis: `none used in ${i.prune.sessions} sessions of this project in ${i.days} days: ${names.slice(0, 5).join(", ")}${names.length > 5 ? ", …" : ""}`,
|
|
156
165
|
quality: "none while they stay unused; undo brings them back",
|
|
166
|
+
qualityFree: true,
|
|
157
167
|
change: join(i.prune.cwd, ".claude", "settings.local.json"),
|
|
158
168
|
state: "available",
|
|
159
169
|
});
|
|
@@ -177,7 +187,7 @@ export function planFixes(i) {
|
|
|
177
187
|
// The subagents' own bill, not the main conversations' input the plan's first line names.
|
|
178
188
|
shareOf: "of subagents",
|
|
179
189
|
basis: `${reqs.toLocaleString("en-US")} subagent requests priced at ${SUBAGENT_CANDIDATE_NAME} with the token counts they had (${money(sm.billedUsd)} billed for all ${sm.agents} subagents); an estimate: another model tokenizes and works differently`,
|
|
180
|
-
quality: `this changes the model your subagents run on (${moved.map((t) => t.type).join(", ")}); the quality cost is not measured here: context-doctor ab can measure it (its tasks with --model ${SUBAGENT_CANDIDATE} and without)`,
|
|
190
|
+
quality: `this changes the model your subagents run on (${moved.map((t) => t.type).join(", ")}); ${i.abComparison ? `measured by context-doctor ab ${comparisonLine(i.abComparison)} (${i.abComparison.tasks} small coding tasks, ${i.abComparison.repeat} run${i.abComparison.repeat === 1 ? "" : "s"} each; your subagents' own work may differ)` : `the quality cost is not measured here: context-doctor ab can measure it (its tasks with --model ${SUBAGENT_CANDIDATE} and without)`}`,
|
|
181
191
|
change: `${where}: env.${SUBAGENT_MODEL_ENV} = "${SUBAGENT_CANDIDATE}"`,
|
|
182
192
|
state: "available",
|
|
183
193
|
value: SUBAGENT_CANDIDATE,
|
|
@@ -204,6 +214,8 @@ export function planFixes(i) {
|
|
|
204
214
|
shareOf: "of input, subagents included",
|
|
205
215
|
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`,
|
|
206
216
|
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",
|
|
217
|
+
// Nothing is lost, only moved (in `--apply all` for the same reason).
|
|
218
|
+
qualityFree: true,
|
|
207
219
|
change: `${where}: ${BASH_OUTPUT_KEY} = ${best.cap} (Claude Code 2.1.261+)`,
|
|
208
220
|
state: "available",
|
|
209
221
|
value: best.cap,
|
|
@@ -231,6 +243,33 @@ export function planFixes(i) {
|
|
|
231
243
|
detail: renderCodexLimits(cx, CODEX_COMPACT_LIMIT),
|
|
232
244
|
});
|
|
233
245
|
}
|
|
246
|
+
const ps = i.progressSummaries;
|
|
247
|
+
const psSet = i.progressSummariesSet;
|
|
248
|
+
if (psSet) {
|
|
249
|
+
const off = disablesSummaries(psSet.value);
|
|
250
|
+
const less = !off && ps && ps.notesUsd >= MIN_USD ? ` (turning them off would have saved about ${money(ps.notesUsd)})` : "";
|
|
251
|
+
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 });
|
|
252
|
+
}
|
|
253
|
+
else if (ps && ps.summarized > 0 && ps.notesUsd >= MIN_USD) {
|
|
254
|
+
const billed = i.subagentModel?.billedUsd ?? 0;
|
|
255
|
+
fixes.push({
|
|
256
|
+
id: "progress-summaries",
|
|
257
|
+
title: "Subagent progress summaries off",
|
|
258
|
+
savedUsd: ps.notesUsd,
|
|
259
|
+
savedShare: billed > 0 ? ps.notesUsd / billed : undefined,
|
|
260
|
+
shareOf: "of subagents",
|
|
261
|
+
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`,
|
|
262
|
+
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",
|
|
263
|
+
qualityFree: true,
|
|
264
|
+
change: `${where}: env.${PROGRESS_SUMMARIES_ENV} = "${PROGRESS_SUMMARIES_OFF}" (Claude Code ${PROGRESS_SUMMARIES_SINCE}+)`,
|
|
265
|
+
state: "available",
|
|
266
|
+
value: PROGRESS_SUMMARIES_OFF,
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
else if (ps && ps.summarized === 0 && (ps.none.host ?? 0) > 0) {
|
|
270
|
+
const n = ps.none.host;
|
|
271
|
+
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` });
|
|
272
|
+
}
|
|
234
273
|
for (const f of fixes) {
|
|
235
274
|
const o = i.overrides?.[f.id];
|
|
236
275
|
if (o?.length && f.state === "available")
|
|
@@ -306,9 +345,12 @@ const KEY_PATH = {
|
|
|
306
345
|
"tool-search": ["env", "ENABLE_TOOL_SEARCH"],
|
|
307
346
|
"subagent-model": ["env", SUBAGENT_MODEL_ENV],
|
|
308
347
|
"tool-output": [BASH_OUTPUT_KEY],
|
|
348
|
+
"progress-summaries": ["env", PROGRESS_SUMMARIES_ENV],
|
|
309
349
|
};
|
|
310
350
|
/** Fixes that never overwrite a value already there: the user set it. */
|
|
311
|
-
const YOURS = new Set(["subagent-model", "tool-output"]);
|
|
351
|
+
const YOURS = new Set(["subagent-model", "tool-output", "progress-summaries"]);
|
|
352
|
+
/** The environment variable a settings fix writes, when the shell's own value is the user's too. */
|
|
353
|
+
const SHELL_ENV = { "subagent-model": SUBAGENT_MODEL_ENV, "progress-summaries": PROGRESS_SUMMARIES_ENV };
|
|
312
354
|
/** Fixes with a quality cost not measured here: applied only when named, never by `--apply all`. */
|
|
313
355
|
const NAMED_ONLY = new Set(["subagent-model"]);
|
|
314
356
|
/** What would keep this fix's value from taking effect, as Claude Code merges settings. */
|
|
@@ -339,6 +381,10 @@ export function fixOverrides(id, deps = {}) {
|
|
|
339
381
|
out.push(`${SUBAGENT_MODEL_ENV}=${s.settings.env[SUBAGENT_MODEL_ENV]} in ${tilde(s.path)} env`);
|
|
340
382
|
return out;
|
|
341
383
|
}
|
|
384
|
+
if (id === "progress-summaries") {
|
|
385
|
+
// A project's, local or managed env is applied over the user's: a value there that does not turn them off wins.
|
|
386
|
+
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`);
|
|
387
|
+
}
|
|
342
388
|
if (id === "tool-output") {
|
|
343
389
|
// Merged settings: a project's or managed value wins over the user's (BASH_MAX_OUTPUT_LENGTH does not: the setting replaces it).
|
|
344
390
|
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)}`);
|
|
@@ -476,9 +522,10 @@ export async function applyFix(fix, deps = {}, context = {}) {
|
|
|
476
522
|
// The environment Claude Code starts in is the user's too: a value there is theirs (settings.json would override it).
|
|
477
523
|
// 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.
|
|
478
524
|
const env = deps.env ?? process.env;
|
|
479
|
-
const
|
|
480
|
-
|
|
481
|
-
|
|
525
|
+
const name = SHELL_ENV[fix.id];
|
|
526
|
+
const shell = name && shellSet(name, settingsSources({ home: deps.home, cwd: deps.cwd, env }), env, String(fix.value)) ? env[name] : undefined;
|
|
527
|
+
if (name && shell)
|
|
528
|
+
return { ok: false, lines: [`✗ ${fix.id}: ${processEnvWhere(name, shell, env)}, a value you set: left as it is. Nothing was changed.`] };
|
|
482
529
|
const lines = applySetting(fix, home, at, { oneHourShareBefore: context.oneHourShare, modelsBefore: context.modelsBefore });
|
|
483
530
|
const over = fixOverrides(fix.id, deps);
|
|
484
531
|
if (over.length)
|
|
@@ -634,6 +681,41 @@ export async function undoFixes(ids, deps = {}) {
|
|
|
634
681
|
}
|
|
635
682
|
return lines;
|
|
636
683
|
}
|
|
684
|
+
// -- What each applied fix saved since ------------------------------------------------
|
|
685
|
+
/**
|
|
686
|
+
* Where CLAUDE_CODE_DISABLE_AGENT_PROGRESS_SUMMARIES is set, as Claude Code
|
|
687
|
+
* sees it: the highest settings file whose env names it (managed, local,
|
|
688
|
+
* project, user: each applied over the one before and over the shell), else
|
|
689
|
+
* the shell's own value. A project's or managed value that keeps them is not
|
|
690
|
+
* the user's (fixOverrides names it); the user's own one is never
|
|
691
|
+
* overwritten. `offSince`: when fix turned them off (its record).
|
|
692
|
+
* `forkGateOff`: CLAUDE_CODE_FORK_SUBAGENT off, which in a terminal session
|
|
693
|
+
* also keeps ordinary background subagents from getting summaries.
|
|
694
|
+
*/
|
|
695
|
+
export function progressSummariesState(deps = {}) {
|
|
696
|
+
const env = deps.env ?? process.env;
|
|
697
|
+
const sources = settingsSources({ home: deps.home, cwd: deps.cwd, env });
|
|
698
|
+
const fork = effectiveEnv("CLAUDE_CODE_FORK_SUBAGENT", sources, env);
|
|
699
|
+
const forkGateOff = !!fork && ["0", "false", "no", "off"].includes(fork.value.trim().toLowerCase());
|
|
700
|
+
const rec = readFixRecords(deps.home).find((r) => r.id === "progress-summaries");
|
|
701
|
+
const off = (value, where) => ({ set: { value, where }, ...(disablesSummaries(value) && rec ? { offSince: rec.at } : {}), forkGateOff });
|
|
702
|
+
for (const s of sources) {
|
|
703
|
+
const v = s.settings.env?.[PROGRESS_SUMMARIES_ENV];
|
|
704
|
+
if (v === undefined || v === null || String(v).trim() === "")
|
|
705
|
+
continue;
|
|
706
|
+
if (disablesSummaries(v) || s.name === "user")
|
|
707
|
+
return off(String(v), `${tilde(s.path)} env`);
|
|
708
|
+
return { forkGateOff };
|
|
709
|
+
}
|
|
710
|
+
// The shell's value, unless it is fix's own copied into a session started before an undo.
|
|
711
|
+
if (shellSet(PROGRESS_SUMMARIES_ENV, sources, env, PROGRESS_SUMMARIES_OFF))
|
|
712
|
+
return off(env[PROGRESS_SUMMARIES_ENV], underClaudeCode(env) ? "this Claude Code session's environment" : "the environment");
|
|
713
|
+
return { forkGateOff };
|
|
714
|
+
}
|
|
715
|
+
/** 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. */
|
|
716
|
+
export function progressSummariesSavedSince(at, subagentPaths, forkGateOff = false) {
|
|
717
|
+
return estimateProgressSummaries(subagentPaths ?? subagentTranscripts(at), { since: at, minVersion: PROGRESS_SUMMARIES_SINCE, forkGateOff });
|
|
718
|
+
}
|
|
637
719
|
/**
|
|
638
720
|
* Compactions since `since` that came before the old window, priced: every
|
|
639
721
|
* later request in that session re-read less context, until the session
|
|
@@ -738,6 +820,10 @@ export function savedSince(records, opts = {}) {
|
|
|
738
820
|
const s = toolOutputSavedSince(r.at, typeof r.previous === "number" ? r.previous : BASH_OUTPUT_DEFAULT, paths);
|
|
739
821
|
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" });
|
|
740
822
|
}
|
|
823
|
+
else if (r.id === "progress-summaries") {
|
|
824
|
+
const s = progressSummariesSavedSince(r.at, opts.subagentPaths);
|
|
825
|
+
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" });
|
|
826
|
+
}
|
|
741
827
|
else if (r.id === "autopilot") {
|
|
742
828
|
const ledger = opts.ledger ?? readLedger();
|
|
743
829
|
const ev = ledger.filter((e) => e.ev === "proxy" && e.ts >= r.at);
|
|
@@ -761,6 +847,7 @@ const LABEL = {
|
|
|
761
847
|
"subagent-model": "Subagent model",
|
|
762
848
|
"tool-output": "Long Bash output",
|
|
763
849
|
"codex-compact": "Codex auto-compact limit",
|
|
850
|
+
"progress-summaries": "Subagent progress summaries",
|
|
764
851
|
};
|
|
765
852
|
/**
|
|
766
853
|
* Priced levers that save part of the same dollars, and why: each is
|
|
@@ -776,6 +863,7 @@ const OVERLAPS = [
|
|
|
776
863
|
["tool-output", "cache-ttl-subagents", "the subagents' cache lifetime changes how often their long output is written to the cache again"],
|
|
777
864
|
["tool-output", "subagent-model", "long output in subagents is priced at the subagents' model, which subagent-model changes"],
|
|
778
865
|
["subagent-model", "cache-ttl-subagents", "the subagents' cache is priced at their model's rates, which subagent-model changes"],
|
|
866
|
+
["progress-summaries", "subagent-model", "the progress summaries run on the subagents' model, which subagent-model changes"],
|
|
779
867
|
];
|
|
780
868
|
/** The overlap lines for the priced fixes in a plan, "a and b: why;" each. */
|
|
781
869
|
export function overlaps(fixes) {
|
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
|