context-doctor 0.47.0 → 0.49.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 +17 -14
- package/dist/ab.d.ts +51 -3
- package/dist/ab.js +68 -26
- 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/budget.d.ts +5 -2
- package/dist/budget.js +21 -7
- package/dist/cache.js +3 -3
- package/dist/cachemisses.d.ts +3 -0
- package/dist/cachemisses.js +8 -0
- package/dist/cachettl.js +6 -2
- package/dist/ccost.d.ts +160 -0
- package/dist/ccost.js +304 -0
- package/dist/cli.js +154 -32
- package/dist/cline.d.ts +41 -0
- package/dist/cline.js +174 -0
- package/dist/coldresume.d.ts +11 -0
- package/dist/coldresume.js +3 -3
- package/dist/coldreturns.d.ts +145 -0
- package/dist/coldreturns.js +282 -0
- package/dist/compactcost.d.ts +10 -4
- package/dist/compactcost.js +12 -7
- package/dist/compactwindow.js +2 -2
- package/dist/copilotusage.d.ts +78 -0
- package/dist/copilotusage.js +193 -0
- package/dist/doctor.d.ts +6 -0
- package/dist/doctor.js +17 -4
- package/dist/fix.d.ts +35 -4
- package/dist/fix.js +55 -8
- package/dist/install.js +2 -0
- package/dist/limits.d.ts +222 -14
- package/dist/limits.js +684 -33
- package/dist/mcp.d.ts +4 -0
- package/dist/mcp.js +142 -98
- package/dist/mcpclient.js +73 -42
- package/dist/mcpdefer.d.ts +47 -0
- package/dist/mcpdefer.js +91 -0
- package/dist/mod/api.d.ts +72 -2
- package/dist/mod/api.js +5 -1
- package/dist/mod/logic.d.ts +281 -0
- package/dist/mod/logic.js +336 -0
- package/dist/mod/register.d.ts +35 -2
- package/dist/mod/register.js +283 -6
- package/dist/modelids.d.ts +58 -0
- package/dist/modelids.js +133 -1
- package/dist/modmeasure.d.ts +6 -4
- package/dist/modmeasure.js +8 -4
- package/dist/opencode.d.ts +57 -0
- package/dist/opencode.js +234 -0
- package/dist/orgrates.d.ts +7 -0
- package/dist/orgrates.js +19 -0
- package/dist/overhead.d.ts +3 -0
- package/dist/overhead.js +5 -1
- package/dist/pricing.d.ts +59 -2
- package/dist/pricing.js +139 -12
- package/dist/proxy.d.ts +8 -1
- package/dist/proxy.js +13 -1
- package/dist/savings.d.ts +5 -1
- package/dist/savings.js +11 -5
- package/dist/scan.d.ts +3 -1
- package/dist/scan.js +8 -1
- package/dist/sessionprice.d.ts +5 -0
- package/dist/sessionprice.js +5 -1
- package/dist/spend.d.ts +86 -3
- package/dist/spend.js +240 -23
- package/dist/spendplace.d.ts +40 -0
- package/dist/spendplace.js +93 -0
- package/dist/spendteam.d.ts +160 -0
- package/dist/spendteam.js +286 -0
- package/dist/starts.d.ts +106 -0
- package/dist/starts.js +406 -0
- package/dist/statusline.d.ts +2 -2
- package/dist/statusline.js +2 -2
- package/dist/subagentmodel.js +9 -7
- package/dist/subagentpay.d.ts +31 -2
- package/dist/subagentpay.js +232 -68
- package/dist/subagents.js +3 -3
- package/dist/tasks.js +3 -2
- package/dist/tooloutput.js +5 -5
- package/dist/usagepane.d.ts +77 -0
- package/dist/usagepane.js +287 -0
- package/package.json +6 -3
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `fix --apply mcp-defer`: keep an MCP server's tools behind tool search.
|
|
3
|
+
*
|
|
4
|
+
* Tool search defers MCP tool definitions by default, but a server the user
|
|
5
|
+
* configured with `"alwaysLoad": true`, or whose author marks its tools
|
|
6
|
+
* `_meta["anthropic/alwaysLoad"]`, is sent whole on every request of every
|
|
7
|
+
* session and subagent. `"alwaysLoad": false` in the server's own entry
|
|
8
|
+
* defers all of its tools, the author-marked ones too (Claude Code 2.1.287+,
|
|
9
|
+
* "Defer a server's tools" in the MCP docs). Only servers in the user's own
|
|
10
|
+
* `~/.claude.json` (user scope, or this project's local scope) are written: a
|
|
11
|
+
* project's `.mcp.json` is shared with everyone who clones it, so it is named,
|
|
12
|
+
* not changed. The Desktop app's own servers and connectors are not in any
|
|
13
|
+
* config file and no setting reaches them.
|
|
14
|
+
*
|
|
15
|
+
* Undo puts back each key as it was (absent, or the value it had), only
|
|
16
|
+
* where it still holds `false`: Claude Code rewrites `~/.claude.json` all the
|
|
17
|
+
* time, so the file is never restored whole.
|
|
18
|
+
*/
|
|
19
|
+
/** The Claude Code version that first reads `alwaysLoad: false` on a server. */
|
|
20
|
+
export declare const MCP_DEFER_SINCE = "2.1.287";
|
|
21
|
+
export interface DeferEntry {
|
|
22
|
+
/** The key path in ~/.claude.json. */
|
|
23
|
+
key: string[];
|
|
24
|
+
/** Whether the key was there before, and its value then. */
|
|
25
|
+
hadPrevious: boolean;
|
|
26
|
+
previous?: unknown;
|
|
27
|
+
}
|
|
28
|
+
/** Where a server's `alwaysLoad` lives in ~/.claude.json, by scope; undefined for a scope fix does not write. */
|
|
29
|
+
export declare function deferKey(name: string, scope: string, cwd?: string): string[] | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Set `alwaysLoad: false` on each server, in one write of ~/.claude.json.
|
|
32
|
+
* A server no longer in the file is skipped; one already deferred is left.
|
|
33
|
+
* The caller holds the fix records' lock.
|
|
34
|
+
*/
|
|
35
|
+
export declare function applyMcpDefer(servers: Array<{
|
|
36
|
+
name: string;
|
|
37
|
+
scope: string;
|
|
38
|
+
}>, opts?: {
|
|
39
|
+
home?: string;
|
|
40
|
+
cwd?: string;
|
|
41
|
+
}): {
|
|
42
|
+
file: string;
|
|
43
|
+
entries: DeferEntry[];
|
|
44
|
+
lines: string[];
|
|
45
|
+
};
|
|
46
|
+
/** Put each key back where it still holds `false`. The caller holds the fix records' lock. */
|
|
47
|
+
export declare function undoMcpDefer(file: string, entries: DeferEntry[]): string[];
|
package/dist/mcpdefer.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `fix --apply mcp-defer`: keep an MCP server's tools behind tool search.
|
|
3
|
+
*
|
|
4
|
+
* Tool search defers MCP tool definitions by default, but a server the user
|
|
5
|
+
* configured with `"alwaysLoad": true`, or whose author marks its tools
|
|
6
|
+
* `_meta["anthropic/alwaysLoad"]`, is sent whole on every request of every
|
|
7
|
+
* session and subagent. `"alwaysLoad": false` in the server's own entry
|
|
8
|
+
* defers all of its tools, the author-marked ones too (Claude Code 2.1.287+,
|
|
9
|
+
* "Defer a server's tools" in the MCP docs). Only servers in the user's own
|
|
10
|
+
* `~/.claude.json` (user scope, or this project's local scope) are written: a
|
|
11
|
+
* project's `.mcp.json` is shared with everyone who clones it, so it is named,
|
|
12
|
+
* not changed. The Desktop app's own servers and connectors are not in any
|
|
13
|
+
* config file and no setting reaches them.
|
|
14
|
+
*
|
|
15
|
+
* Undo puts back each key as it was (absent, or the value it had), only
|
|
16
|
+
* where it still holds `false`: Claude Code rewrites `~/.claude.json` all the
|
|
17
|
+
* time, so the file is never restored whole.
|
|
18
|
+
*/
|
|
19
|
+
import { resolve } from "node:path";
|
|
20
|
+
import { claudeJsonPath, tilde } from "./claudedir.js";
|
|
21
|
+
import { ABSENT, getPath, readSettings, SettingsError, setJsonPath, writeAtomic } from "./settingsedit.js";
|
|
22
|
+
/** The Claude Code version that first reads `alwaysLoad: false` on a server. */
|
|
23
|
+
export const MCP_DEFER_SINCE = "2.1.287";
|
|
24
|
+
/** Where a server's `alwaysLoad` lives in ~/.claude.json, by scope; undefined for a scope fix does not write. */
|
|
25
|
+
export function deferKey(name, scope, cwd = process.cwd()) {
|
|
26
|
+
if (scope === "user")
|
|
27
|
+
return ["mcpServers", name, "alwaysLoad"];
|
|
28
|
+
if (scope === "project")
|
|
29
|
+
return ["projects", resolve(cwd), "mcpServers", name, "alwaysLoad"];
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Set `alwaysLoad: false` on each server, in one write of ~/.claude.json.
|
|
34
|
+
* A server no longer in the file is skipped; one already deferred is left.
|
|
35
|
+
* The caller holds the fix records' lock.
|
|
36
|
+
*/
|
|
37
|
+
export function applyMcpDefer(servers, opts = {}) {
|
|
38
|
+
const file = claudeJsonPath(opts.home);
|
|
39
|
+
const cur = readSettings(file);
|
|
40
|
+
if (cur.text === undefined)
|
|
41
|
+
throw new SettingsError(`${tilde(file)} does not exist: no MCP server to defer. Nothing was changed.`);
|
|
42
|
+
let text = cur.text;
|
|
43
|
+
const entries = [];
|
|
44
|
+
const lines = [];
|
|
45
|
+
for (const s of servers) {
|
|
46
|
+
const key = deferKey(s.name, s.scope, opts.cwd);
|
|
47
|
+
if (!key) {
|
|
48
|
+
lines.push(`– ${s.name}: in ${s.scope}, shared with the repository: set "alwaysLoad": false there yourself if everyone should get it`);
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const entry = getPath(cur.data, key.slice(0, -1));
|
|
52
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
53
|
+
lines.push(`– ${s.name}: no longer in ${tilde(file)}: skipped`);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const now = entry.alwaysLoad;
|
|
57
|
+
if (now === false) {
|
|
58
|
+
lines.push(`– ${s.name}: already deferred`);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
text = setJsonPath(text, key, false);
|
|
62
|
+
entries.push({ key, hadPrevious: now !== undefined, ...(now !== undefined ? { previous: now } : {}) });
|
|
63
|
+
lines.push(`✓ ${s.name}: "alwaysLoad": false in ${tilde(file)}`);
|
|
64
|
+
}
|
|
65
|
+
if (entries.length)
|
|
66
|
+
writeAtomic(file, text);
|
|
67
|
+
return { file, entries, lines };
|
|
68
|
+
}
|
|
69
|
+
/** Put each key back where it still holds `false`. The caller holds the fix records' lock. */
|
|
70
|
+
export function undoMcpDefer(file, entries) {
|
|
71
|
+
const cur = readSettings(file);
|
|
72
|
+
if (cur.text === undefined)
|
|
73
|
+
return [`– ${tilde(file)} is gone: nothing to put back`];
|
|
74
|
+
let text = cur.text;
|
|
75
|
+
const lines = [];
|
|
76
|
+
let changed = false;
|
|
77
|
+
for (const e of entries) {
|
|
78
|
+
const name = e.key[e.key.length - 2];
|
|
79
|
+
const now = getPath(cur.data, e.key);
|
|
80
|
+
if (now !== false) {
|
|
81
|
+
lines.push(`– ${name}: alwaysLoad was changed since fix set it (now ${now === undefined ? "not set" : JSON.stringify(now)}): left as it is`);
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
text = setJsonPath(text, e.key, e.hadPrevious ? e.previous : ABSENT);
|
|
85
|
+
changed = true;
|
|
86
|
+
lines.push(`✓ ${name}: alwaysLoad ${e.hadPrevious ? `back to ${JSON.stringify(e.previous)}` : "removed"}`);
|
|
87
|
+
}
|
|
88
|
+
if (changed)
|
|
89
|
+
writeAtomic(file, text);
|
|
90
|
+
return lines;
|
|
91
|
+
}
|
package/dist/mod/api.d.ts
CHANGED
|
@@ -6,8 +6,12 @@
|
|
|
6
6
|
* declarations Claude Code 2.1.321 writes (`claude-code.d.ts`): `$.process.run`,
|
|
7
7
|
* `$.session.{id,model,compact}`, `$.ui.{open,resolve,invalidate,toast}`,
|
|
8
8
|
* `$.command.register`, `$.clock.{now,every}`, `$.env.get`, `$.plugin.root`,
|
|
9
|
+
* `$.model.fork` (from the GitHub copy of the declarations, 2026-11-15),
|
|
9
10
|
* and the events `session.start`, `session.measure`, `session.end`,
|
|
10
|
-
* `command.run`, `ui.render
|
|
11
|
+
* `command.run`, `ui.render`; from 2.1.325's, for the usage pane,
|
|
12
|
+
* `$.agent.list`, `$.session.usage`, the `Svg` element, a pane's `placement`
|
|
13
|
+
* and `bodyColumns`, and `ui.close`. A subset, structurally compatible: no
|
|
14
|
+
* runtime code.
|
|
11
15
|
*/
|
|
12
16
|
export type Surface = "terminal" | "desktop" | "vscode" | "mobile";
|
|
13
17
|
export interface RateLimit {
|
|
@@ -45,6 +49,47 @@ export interface RenderEvent {
|
|
|
45
49
|
bodyColumns?: number;
|
|
46
50
|
title?: string;
|
|
47
51
|
isFocused?: boolean;
|
|
52
|
+
placement?: "dock" | "inline" | "widget" | string;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** What `$.model.fork` resolves to: the reply and its usage, or why there is none (`nothing-to-fork`, `api-error`, `empty-reply`, `aborted`). */
|
|
56
|
+
export type ForkResult = {
|
|
57
|
+
isAnswered: true;
|
|
58
|
+
text: string;
|
|
59
|
+
usage: {
|
|
60
|
+
input_tokens: number;
|
|
61
|
+
output_tokens: number;
|
|
62
|
+
cache_read_input_tokens: number;
|
|
63
|
+
cache_creation_input_tokens: number;
|
|
64
|
+
};
|
|
65
|
+
} | {
|
|
66
|
+
isAnswered: false;
|
|
67
|
+
reason: string;
|
|
68
|
+
status?: number;
|
|
69
|
+
usage?: {
|
|
70
|
+
input_tokens: number;
|
|
71
|
+
output_tokens: number;
|
|
72
|
+
cache_read_input_tokens: number;
|
|
73
|
+
cache_creation_input_tokens: number;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
/** One agent loop as `$.agent.list()` answers it (the fields the usage pane reads). */
|
|
77
|
+
export interface AgentInfo {
|
|
78
|
+
id: string;
|
|
79
|
+
type: string;
|
|
80
|
+
description: string;
|
|
81
|
+
status: string;
|
|
82
|
+
name?: string;
|
|
83
|
+
parentId?: string;
|
|
84
|
+
teammateId?: string;
|
|
85
|
+
}
|
|
86
|
+
/** `$.session.usage()`: Claude Code's own figures, as `session.measure` pushes them. */
|
|
87
|
+
export interface SessionUsage {
|
|
88
|
+
startedAt: number;
|
|
89
|
+
context: MeasureEvent["context"];
|
|
90
|
+
rateLimits: RateLimit[];
|
|
91
|
+
cost?: {
|
|
92
|
+
usd: number;
|
|
48
93
|
};
|
|
49
94
|
}
|
|
50
95
|
export interface Engine {
|
|
@@ -69,6 +114,11 @@ export interface Engine {
|
|
|
69
114
|
}) => Promise<{
|
|
70
115
|
skip?: string;
|
|
71
116
|
}>;
|
|
117
|
+
usage: () => Promise<SessionUsage>;
|
|
118
|
+
};
|
|
119
|
+
/** 2.1.325 has it; the usage pane says so where an older engine has not. */
|
|
120
|
+
agent: {
|
|
121
|
+
list: () => Promise<AgentInfo[]>;
|
|
72
122
|
};
|
|
73
123
|
ui: {
|
|
74
124
|
open: (pane: {
|
|
@@ -78,7 +128,9 @@ export interface Engine {
|
|
|
78
128
|
isPlaced: boolean;
|
|
79
129
|
}>;
|
|
80
130
|
/** The engine's is generic per surface (each has its own table); the mod passes the render event it got. */
|
|
81
|
-
resolve: (e: any) => Record<"Box" | "Text" | "Button", Ctor
|
|
131
|
+
resolve: (e: any) => Record<"Box" | "Text" | "Button", Ctor> & {
|
|
132
|
+
Svg?: Ctor;
|
|
133
|
+
};
|
|
82
134
|
invalidate: (event: "ui.render") => void;
|
|
83
135
|
toast: (text: string, options?: {
|
|
84
136
|
timeoutMs?: number;
|
|
@@ -88,8 +140,20 @@ export interface Engine {
|
|
|
88
140
|
register: (spec: {
|
|
89
141
|
name: string;
|
|
90
142
|
description: string;
|
|
143
|
+
argumentHint?: string;
|
|
91
144
|
}) => Promise<unknown>;
|
|
92
145
|
};
|
|
146
|
+
/**
|
|
147
|
+
* `$.model.fork` (claude-code.d.ts, mods/types on GitHub, read 2026-11-15):
|
|
148
|
+
* the main thread's last request again (its model, system prompt, tools,
|
|
149
|
+
* messages) with `prompt` after it, tools denied, its own tail never
|
|
150
|
+
* cached, nothing written to the transcript. An engine without it throws a TypeError at the call (a module may not test for it: validate refuses `$.model` read as a value).
|
|
151
|
+
*/
|
|
152
|
+
model: {
|
|
153
|
+
fork: (request: {
|
|
154
|
+
prompt: string;
|
|
155
|
+
}) => Promise<ForkResult>;
|
|
156
|
+
};
|
|
93
157
|
clock: {
|
|
94
158
|
now: () => Promise<number>;
|
|
95
159
|
every: (ms: number, fn: () => void) => {
|
|
@@ -132,4 +196,10 @@ export interface On {
|
|
|
132
196
|
component: string;
|
|
133
197
|
requestId?: string;
|
|
134
198
|
}, hook: Hook<RenderEvent, Element>): unknown;
|
|
199
|
+
(event: "ui.close", hook: Hook<{
|
|
200
|
+
id: string;
|
|
201
|
+
origin: {
|
|
202
|
+
kind: string;
|
|
203
|
+
};
|
|
204
|
+
}, unknown>): unknown;
|
|
135
205
|
}
|
package/dist/mod/api.js
CHANGED
|
@@ -6,7 +6,11 @@
|
|
|
6
6
|
* declarations Claude Code 2.1.321 writes (`claude-code.d.ts`): `$.process.run`,
|
|
7
7
|
* `$.session.{id,model,compact}`, `$.ui.{open,resolve,invalidate,toast}`,
|
|
8
8
|
* `$.command.register`, `$.clock.{now,every}`, `$.env.get`, `$.plugin.root`,
|
|
9
|
+
* `$.model.fork` (from the GitHub copy of the declarations, 2026-11-15),
|
|
9
10
|
* and the events `session.start`, `session.measure`, `session.end`,
|
|
10
|
-
* `command.run`, `ui.render
|
|
11
|
+
* `command.run`, `ui.render`; from 2.1.325's, for the usage pane,
|
|
12
|
+
* `$.agent.list`, `$.session.usage`, the `Svg` element, a pane's `placement`
|
|
13
|
+
* and `bodyColumns`, and `ui.close`. A subset, structurally compatible: no
|
|
14
|
+
* runtime code.
|
|
11
15
|
*/
|
|
12
16
|
export {};
|
package/dist/mod/logic.d.ts
CHANGED
|
@@ -156,3 +156,284 @@ export declare function outcome(stdout: string, stderr: string, exitCode: number
|
|
|
156
156
|
ok: boolean;
|
|
157
157
|
lines: string[];
|
|
158
158
|
};
|
|
159
|
+
/**
|
|
160
|
+
* `/context-doctor-keep-warm <hours> [$cap]`: while the person is away, a
|
|
161
|
+
* cache read of the session's whole context every 55 minutes (4.5 on a
|
|
162
|
+
* 5-minute cache), through Claude Code's `$.model.fork`: the main thread's
|
|
163
|
+
* last request again with one short message after it, the reply kept out of
|
|
164
|
+
* the transcript, so the return reads the context instead of writing it
|
|
165
|
+
* again. Only on that command (the yes), capped in hours and dollars, never
|
|
166
|
+
* armed by itself or again after it stops.
|
|
167
|
+
*
|
|
168
|
+
* On the author's 30 days (2026-11-15) a 2-hour cap would have sent 918
|
|
169
|
+
* pings ($87) and kept 56 of 183 cold returns warm ($275 of re-writes): $188
|
|
170
|
+
* net. `cache-misses` prices it on your own history.
|
|
171
|
+
*/
|
|
172
|
+
export declare const KEEP_WARM_COMMAND = "context-doctor-keep-warm";
|
|
173
|
+
export declare const KEEP_WARM_MAX_HOURS = 8;
|
|
174
|
+
export declare const KEEP_WARM_DEFAULT_CAP_USD = 2;
|
|
175
|
+
export declare const KEEP_WARM_MAX_CAP_USD = 20;
|
|
176
|
+
/** A ping every this long keeps a 1-hour cache warm, and a 5-minute one (coldreturns.ts prices the same). */
|
|
177
|
+
export declare const PING_EVERY_1H_MS: number;
|
|
178
|
+
export declare const PING_EVERY_5M_MS = 270000;
|
|
179
|
+
/** The band's clock ticks this often: a ping goes out within one tick before its time, never after it. */
|
|
180
|
+
export declare const KEEP_WARM_TICK_MS = 30000;
|
|
181
|
+
/** Asks for haste in the prompt, not with `effort`: a level other than the session's could write the whole context again. */
|
|
182
|
+
export declare const PING_PROMPT = "context-doctor keep-warm: an automated cache refresh while the person is away, not a request. Reply with the single word ok, straight away, with no tools and without thinking it over.";
|
|
183
|
+
export type KeepWarmRequest = {
|
|
184
|
+
kind: "off";
|
|
185
|
+
} | {
|
|
186
|
+
kind: "status";
|
|
187
|
+
} | {
|
|
188
|
+
kind: "arm";
|
|
189
|
+
hours: number;
|
|
190
|
+
capUsd: number;
|
|
191
|
+
} | {
|
|
192
|
+
kind: "error";
|
|
193
|
+
text: string;
|
|
194
|
+
};
|
|
195
|
+
/** The command's arguments: `2h`, `90m`, `2h $5`, `off`. None is a question, not a yes. */
|
|
196
|
+
export declare function parseKeepWarm(args: string | undefined): KeepWarmRequest;
|
|
197
|
+
/** One yes: its limits, what it has spent, and why it stopped. */
|
|
198
|
+
export interface KeepWarm {
|
|
199
|
+
armedAt: number;
|
|
200
|
+
until: number;
|
|
201
|
+
capUsd: number;
|
|
202
|
+
spentUsd: number;
|
|
203
|
+
pings: number;
|
|
204
|
+
lastPingAt?: number;
|
|
205
|
+
stopped?: string;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* CONTEXT_DOCTOR_KEEP_WARM_PING_MS: a ping every this many ms (1 s to 5 min)
|
|
209
|
+
* and the clock ticking at least that often, for the canary alone, which
|
|
210
|
+
* cannot wait 55 minutes to see a ping reach its mock API. Unset, the real
|
|
211
|
+
* intervals.
|
|
212
|
+
*/
|
|
213
|
+
export declare function keepWarmTestEvery(raw: string | undefined): number | undefined;
|
|
214
|
+
export declare const pingEvery: (ttlMs: number) => number;
|
|
215
|
+
/** What a ping should cost: one read of the context (the band's per-message figure), and a little more for the prompt and reply. */
|
|
216
|
+
export declare function pingEstimateUsd(d: BandData): number | undefined;
|
|
217
|
+
/** Why keeping warm cannot start now, or undefined when it can. */
|
|
218
|
+
export declare function keepWarmRefusal(d: BandData | undefined, now: number): string | undefined;
|
|
219
|
+
export type KeepWarmStep = {
|
|
220
|
+
do: "wait";
|
|
221
|
+
} | {
|
|
222
|
+
do: "ping";
|
|
223
|
+
} | {
|
|
224
|
+
do: "stop";
|
|
225
|
+
why: string;
|
|
226
|
+
};
|
|
227
|
+
/**
|
|
228
|
+
* What the timer does at `now`: wait, ping, or stop for good. A ping is due
|
|
229
|
+
* a tick before its interval is up after the last request or ping, so it
|
|
230
|
+
* lands inside the cache's life; a cache that lapsed anyway (Claude Code
|
|
231
|
+
* closed, the machine asleep) is not pinged, since that ping would write the
|
|
232
|
+
* whole context.
|
|
233
|
+
*/
|
|
234
|
+
export declare function keepWarmStep(kw: KeepWarm | undefined, d: BandData | undefined, now: number, everyMs?: number): KeepWarmStep;
|
|
235
|
+
/** A ping's usage as `$.model.fork` reports it. */
|
|
236
|
+
export interface PingUsage {
|
|
237
|
+
input_tokens: number;
|
|
238
|
+
output_tokens: number;
|
|
239
|
+
cache_read_input_tokens: number;
|
|
240
|
+
cache_creation_input_tokens: number;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* What a ping read and cost. Warm: it read the context and wrote little
|
|
244
|
+
* (the fork's own tail is never cached). Priced from the band's figures: a
|
|
245
|
+
* read at the per-message rate, a write at the session's re-write rate,
|
|
246
|
+
* uncached input at that over the TTL's multiple (2x for 1 hour, 1.25x for
|
|
247
|
+
* 5 minutes), output at 5x input (every current Claude model). An estimate.
|
|
248
|
+
*/
|
|
249
|
+
export declare function pingOutcome(u: PingUsage, d: BandData): {
|
|
250
|
+
warm: boolean;
|
|
251
|
+
usd: number;
|
|
252
|
+
};
|
|
253
|
+
/** The band while keeping warm: for how long more, what it has spent, against its limit. */
|
|
254
|
+
export declare function keepWarmText(kw: KeepWarm, now: number): string;
|
|
255
|
+
/** What the command says when it arms. */
|
|
256
|
+
export declare function keepWarmArmedText(kw: KeepWarm, d: BandData): string;
|
|
257
|
+
/** The command with no arguments: the price of a yes, or how the one in force stands. Arms nothing. */
|
|
258
|
+
export declare function keepWarmStatusText(kw: KeepWarm | undefined, d: BandData | undefined, now: number): string;
|
|
259
|
+
/** `mod usage`'s answer (usagepane.ts prints exactly this shape). */
|
|
260
|
+
export interface ModelUse {
|
|
261
|
+
model: string;
|
|
262
|
+
usd: number;
|
|
263
|
+
tokens: number;
|
|
264
|
+
requests: number;
|
|
265
|
+
}
|
|
266
|
+
export interface PeriodUse {
|
|
267
|
+
key: "today" | "7d" | "30d";
|
|
268
|
+
label: string;
|
|
269
|
+
usd: number;
|
|
270
|
+
tokens: number;
|
|
271
|
+
requests: number;
|
|
272
|
+
models: ModelUse[];
|
|
273
|
+
}
|
|
274
|
+
export interface HistoryUse {
|
|
275
|
+
at: number;
|
|
276
|
+
periods: PeriodUse[];
|
|
277
|
+
unpriced?: number;
|
|
278
|
+
/** `limits`' per-reset figures (F4): dollars per 1% of each window, of the current one or else the last with a figure. */
|
|
279
|
+
limitFits?: Partial<Record<string, {
|
|
280
|
+
usdPerPct: number;
|
|
281
|
+
relSe?: number;
|
|
282
|
+
current: boolean;
|
|
283
|
+
resetsAt: number;
|
|
284
|
+
}>>;
|
|
285
|
+
/** The latest move in that figure: before and after, after / before, when. */
|
|
286
|
+
limitMove?: {
|
|
287
|
+
window: string;
|
|
288
|
+
at: number;
|
|
289
|
+
before: number;
|
|
290
|
+
after: number;
|
|
291
|
+
factor: number;
|
|
292
|
+
};
|
|
293
|
+
/** Weekly readings and no 5-hour ones: a plan without that window (Ultra). */
|
|
294
|
+
noFiveHour?: boolean;
|
|
295
|
+
}
|
|
296
|
+
export interface LimitWindow {
|
|
297
|
+
window: string;
|
|
298
|
+
label: string;
|
|
299
|
+
pct: number;
|
|
300
|
+
at: number;
|
|
301
|
+
resetsAt?: number;
|
|
302
|
+
resetSince: boolean;
|
|
303
|
+
perHour?: number;
|
|
304
|
+
runsOutAt?: number;
|
|
305
|
+
beforeReset?: boolean;
|
|
306
|
+
usdPerPct?: number;
|
|
307
|
+
relSe?: number;
|
|
308
|
+
fitFromEarlier?: boolean;
|
|
309
|
+
stale?: boolean;
|
|
310
|
+
}
|
|
311
|
+
export interface AgentUse {
|
|
312
|
+
id: string;
|
|
313
|
+
model?: string;
|
|
314
|
+
contextTokens?: number;
|
|
315
|
+
window?: number;
|
|
316
|
+
usd?: number;
|
|
317
|
+
requests?: number;
|
|
318
|
+
}
|
|
319
|
+
export interface UsagePaneData {
|
|
320
|
+
at: number;
|
|
321
|
+
history?: HistoryUse;
|
|
322
|
+
historyFrom?: "cache" | "measured";
|
|
323
|
+
historyMs?: number;
|
|
324
|
+
limits: LimitWindow[];
|
|
325
|
+
agents: AgentUse[];
|
|
326
|
+
}
|
|
327
|
+
/** What Claude Code said last (`session.measure`, or `$.session.usage()` when the pane opened). */
|
|
328
|
+
export interface LiveUsage {
|
|
329
|
+
at: number;
|
|
330
|
+
context?: {
|
|
331
|
+
tokens?: number;
|
|
332
|
+
window: number;
|
|
333
|
+
percent?: number;
|
|
334
|
+
};
|
|
335
|
+
rateLimits?: RateLimitLike[];
|
|
336
|
+
model?: string;
|
|
337
|
+
}
|
|
338
|
+
export interface RateLimitLike {
|
|
339
|
+
kind: string;
|
|
340
|
+
percentUsed: number;
|
|
341
|
+
resetsAt?: string;
|
|
342
|
+
}
|
|
343
|
+
/** A subagent as `$.agent.list()` names it (the fields the pane reads). */
|
|
344
|
+
export interface AgentLike {
|
|
345
|
+
id: string;
|
|
346
|
+
type?: string;
|
|
347
|
+
description?: string;
|
|
348
|
+
status?: string;
|
|
349
|
+
name?: string;
|
|
350
|
+
}
|
|
351
|
+
/** The agent statuses that count as running: started and not settled. */
|
|
352
|
+
export declare const RUNNING: Set<string>;
|
|
353
|
+
/** "claude-opus-5-5" → "Opus 5.5", "claude-haiku-4-5-20251001" → "Haiku 4.5"; anything else as it is. */
|
|
354
|
+
export declare function shortModel(id: string | undefined): string;
|
|
355
|
+
/** A bar of `width` cells, filled to `pct`: "██████░░░░". */
|
|
356
|
+
export declare function bar(pct: number, width?: number): string;
|
|
357
|
+
/** "41%", "0.4%", "100%". */
|
|
358
|
+
export declare function pctText(pct: number): string;
|
|
359
|
+
/** The context ring, for the surfaces that draw `Svg`: a circle filled to `pct`, the percent in its middle. */
|
|
360
|
+
export declare function ringSvg(pct: number, size?: number): string;
|
|
361
|
+
export interface UsageView {
|
|
362
|
+
/** The context ring: its percent and its words. */
|
|
363
|
+
context: {
|
|
364
|
+
pct?: number;
|
|
365
|
+
text: string;
|
|
366
|
+
};
|
|
367
|
+
limits: Array<{
|
|
368
|
+
key: string;
|
|
369
|
+
label: string;
|
|
370
|
+
pct: number;
|
|
371
|
+
text: string;
|
|
372
|
+
sub?: string;
|
|
373
|
+
}>;
|
|
374
|
+
limitsNote?: string;
|
|
375
|
+
/** One line per period: "Today $42.10 · 3.1M tokens". */
|
|
376
|
+
periods: Array<{
|
|
377
|
+
key: string;
|
|
378
|
+
text: string;
|
|
379
|
+
}>;
|
|
380
|
+
/** The chosen period, by model. */
|
|
381
|
+
period?: {
|
|
382
|
+
key: string;
|
|
383
|
+
label: string;
|
|
384
|
+
rows: Array<{
|
|
385
|
+
model: string;
|
|
386
|
+
text: string;
|
|
387
|
+
}>;
|
|
388
|
+
};
|
|
389
|
+
historyNote?: string;
|
|
390
|
+
agents: Array<{
|
|
391
|
+
key: string;
|
|
392
|
+
head: string;
|
|
393
|
+
text: string;
|
|
394
|
+
}>;
|
|
395
|
+
agentsNote?: string;
|
|
396
|
+
/** For a minimized pane (the Desktop app's widget): one line. */
|
|
397
|
+
glance: string;
|
|
398
|
+
footer: string;
|
|
399
|
+
}
|
|
400
|
+
export interface UsageViewInput {
|
|
401
|
+
data?: UsagePaneData;
|
|
402
|
+
live?: LiveUsage;
|
|
403
|
+
/** `$.agent.list()`'s rows; undefined when this Claude Code has no such call. */
|
|
404
|
+
agents?: AgentLike[];
|
|
405
|
+
/** Which period the by-model rows are for. */
|
|
406
|
+
period?: PeriodUse["key"];
|
|
407
|
+
loading?: boolean;
|
|
408
|
+
error?: string;
|
|
409
|
+
now: number;
|
|
410
|
+
}
|
|
411
|
+
/** The limit windows to show: the ledger's, each overlaid by Claude Code's own newer reading; a window only Claude Code has, from it alone. */
|
|
412
|
+
export declare function mergeLimits(ledger: LimitWindow[], live: LiveUsage | undefined): LimitWindow[];
|
|
413
|
+
/** Everything the usage pane says, as words; register.ts lays it out. */
|
|
414
|
+
export declare function usageView(v: UsageViewInput): UsageView;
|
|
415
|
+
/** The pane as lines of text: the command's answer where no surface draws the pane (`claude -p`, a headless host). */
|
|
416
|
+
export declare function usageText(view: UsageView): string;
|
|
417
|
+
/** How often the pane asks `mod usage` again: the history (cached by the CLI for as long) and the subagents while any runs. */
|
|
418
|
+
export declare const USAGE_HISTORY_EVERY_MS: number;
|
|
419
|
+
export declare const USAGE_AGENTS_EVERY_MS = 30000;
|
|
420
|
+
/**
|
|
421
|
+
* Whether the pane asks `mod usage` now, and for what. Never while closed or
|
|
422
|
+
* while a run is in flight; the history at most every 5 minutes; the
|
|
423
|
+
* subagents and the limits every 30 s while a subagent runs or after a turn
|
|
424
|
+
* moved them. Nothing on a draw: drawing only reads.
|
|
425
|
+
*/
|
|
426
|
+
export declare function usageDue(s: {
|
|
427
|
+
open: boolean;
|
|
428
|
+
loading: boolean;
|
|
429
|
+
lastAt?: number;
|
|
430
|
+
historyAt?: number;
|
|
431
|
+
measuredAt?: number;
|
|
432
|
+
agentsRunning: number;
|
|
433
|
+
}, now: number): false | {
|
|
434
|
+
history: boolean;
|
|
435
|
+
};
|
|
436
|
+
/** The command the pane runs: the CLI's own. */
|
|
437
|
+
export declare function usageArgv(node: string, cli: string): string[];
|
|
438
|
+
/** Parse `mod usage`'s output; undefined when it is not one. */
|
|
439
|
+
export declare function parseUsage(stdout: string): UsagePaneData | undefined;
|