context-doctor 0.48.0 → 0.49.1

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.
Files changed (77) hide show
  1. package/README.md +16 -14
  2. package/dist/abclaude.js +1 -1
  3. package/dist/budget.d.ts +5 -2
  4. package/dist/budget.js +21 -7
  5. package/dist/cache.js +3 -3
  6. package/dist/cachemisses.d.ts +3 -0
  7. package/dist/cachemisses.js +8 -0
  8. package/dist/cachettl.js +6 -2
  9. package/dist/ccost.d.ts +195 -0
  10. package/dist/ccost.js +400 -0
  11. package/dist/cli.js +135 -32
  12. package/dist/cline.d.ts +41 -0
  13. package/dist/cline.js +174 -0
  14. package/dist/coldresume.d.ts +11 -0
  15. package/dist/coldresume.js +3 -3
  16. package/dist/coldreturns.d.ts +145 -0
  17. package/dist/coldreturns.js +282 -0
  18. package/dist/compactcost.d.ts +10 -4
  19. package/dist/compactcost.js +12 -7
  20. package/dist/compactwindow.js +2 -2
  21. package/dist/copilotusage.d.ts +78 -0
  22. package/dist/copilotusage.js +193 -0
  23. package/dist/doctor.d.ts +6 -0
  24. package/dist/doctor.js +17 -4
  25. package/dist/fix.d.ts +28 -2
  26. package/dist/fix.js +49 -5
  27. package/dist/install.js +1 -1
  28. package/dist/limits.d.ts +232 -14
  29. package/dist/limits.js +739 -33
  30. package/dist/mcp.js +19 -19
  31. package/dist/mcpdefer.d.ts +47 -0
  32. package/dist/mcpdefer.js +91 -0
  33. package/dist/mod/api.d.ts +72 -2
  34. package/dist/mod/api.js +5 -1
  35. package/dist/mod/logic.d.ts +289 -16
  36. package/dist/mod/logic.js +362 -38
  37. package/dist/mod/register.d.ts +37 -2
  38. package/dist/mod/register.js +290 -9
  39. package/dist/modmeasure.d.ts +6 -4
  40. package/dist/modmeasure.js +8 -4
  41. package/dist/opencode.d.ts +57 -0
  42. package/dist/opencode.js +234 -0
  43. package/dist/orgrates.d.ts +7 -0
  44. package/dist/orgrates.js +19 -0
  45. package/dist/overhead.d.ts +3 -0
  46. package/dist/overhead.js +5 -1
  47. package/dist/pricing.d.ts +59 -2
  48. package/dist/pricing.js +130 -10
  49. package/dist/proxy.d.ts +8 -1
  50. package/dist/proxy.js +13 -1
  51. package/dist/savings.d.ts +5 -1
  52. package/dist/savings.js +11 -5
  53. package/dist/scan.d.ts +3 -1
  54. package/dist/scan.js +8 -1
  55. package/dist/sessionprice.d.ts +5 -0
  56. package/dist/sessionprice.js +5 -1
  57. package/dist/sidecost.d.ts +65 -0
  58. package/dist/sidecost.js +117 -0
  59. package/dist/spend.d.ts +94 -3
  60. package/dist/spend.js +251 -23
  61. package/dist/spendplace.d.ts +40 -0
  62. package/dist/spendplace.js +93 -0
  63. package/dist/spendteam.d.ts +160 -0
  64. package/dist/spendteam.js +286 -0
  65. package/dist/starts.d.ts +106 -0
  66. package/dist/starts.js +406 -0
  67. package/dist/statusline.d.ts +2 -2
  68. package/dist/statusline.js +2 -2
  69. package/dist/subagentmodel.js +9 -7
  70. package/dist/subagentpay.d.ts +31 -2
  71. package/dist/subagentpay.js +232 -68
  72. package/dist/subagents.js +3 -3
  73. package/dist/tasks.js +3 -2
  74. package/dist/tooloutput.js +5 -5
  75. package/dist/usagepane.d.ts +77 -0
  76. package/dist/usagepane.js +287 -0
  77. package/package.json +1 -1
@@ -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[];
@@ -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`. A subset, structurally compatible: no runtime code.
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`. A subset, structurally compatible: no runtime code.
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 {};
@@ -50,16 +50,6 @@ export type Band = {
50
50
  text: string;
51
51
  compact: string;
52
52
  };
53
- /** The band shows within this long of the cache going cold... */
54
- export declare const WARN_BEFORE_MS: number;
55
- /**
56
- * ...or within this share of the cache's life, when that is shorter: the last
57
- * minute of a 5-minute cache (WARN_BEFORE_MS would be all of it, the band
58
- * after every turn), the last five of the 1-hour cache.
59
- */
60
- export declare const WARN_SHARE: number;
61
- /** How long before the cache goes cold the band warns, for a cache that lives `ttlMs`. */
62
- export declare function warnBeforeMs(ttlMs: number): number;
63
53
  /** The session price thresholds when the CLI cannot say them (no Node): the defaults, the environment's own, or none. */
64
54
  export declare const DEFAULT_THRESHOLDS: number[];
65
55
  /** CONTEXT_DOCTOR_SESSION_PRICE and CONTEXT_DOCTOR_NO_SESSION_PRICE read as sessionprice.ts reads them. */
@@ -77,15 +67,17 @@ export declare function priceText(d: Pick<BandData, "usd" | "ccUsd">): string |
77
67
  export interface BandOptions {
78
68
  /** Keys the person hid this session. */
79
69
  hidden?: ReadonlySet<string>;
80
- /** CONTEXT_DOCTOR_MOD_BAND=always: show the cache clock and the price at all times, not only when they pay. */
70
+ /** CONTEXT_DOCTOR_MOD_BAND=cold: show the cold-return offer (Compact first). */
71
+ cold?: boolean;
72
+ /** CONTEXT_DOCTOR_MOD_BAND=always: the cold return, and the cache clock and the price at all times. */
81
73
  always?: boolean;
82
74
  }
83
75
  /**
84
- * The band above the prompt at `now`. Quiet unless it pays (the cache about
85
- * to go cold, or gone cold, on a context worth caring about; the session
86
- * past a price threshold), except with `always`. The terminal has the
87
- * status line for the clock and the price, so there the band shows only the
88
- * cold return, the one thing with a button. Nothing on mobile.
76
+ * The band above the prompt at `now`. Off by default: on a big session it came
77
+ * up after nearly every reply, and the every-prompt hook already has Claude
78
+ * offer to compact on a cold return. `cold` shows that return (back at a big
79
+ * session after its cache expired) with Compact first; `always` adds the cache
80
+ * clock, the expired notice and the session price. Nothing on mobile.
89
81
  */
90
82
  export declare function band(d: BandData | undefined, now: number, surface: Surface, opts?: BandOptions): Band;
91
83
  /** A lever as `context-doctor fix --json` prints it (the fields the pane reads). */
@@ -156,3 +148,284 @@ export declare function outcome(stdout: string, stderr: string, exitCode: number
156
148
  ok: boolean;
157
149
  lines: string[];
158
150
  };
151
+ /**
152
+ * `/context-doctor-keep-warm <hours> [$cap]`: while the person is away, a
153
+ * cache read of the session's whole context every 55 minutes (4.5 on a
154
+ * 5-minute cache), through Claude Code's `$.model.fork`: the main thread's
155
+ * last request again with one short message after it, the reply kept out of
156
+ * the transcript, so the return reads the context instead of writing it
157
+ * again. Only on that command (the yes), capped in hours and dollars, never
158
+ * armed by itself or again after it stops.
159
+ *
160
+ * On the author's 30 days (2026-11-15) a 2-hour cap would have sent 918
161
+ * pings ($87) and kept 56 of 183 cold returns warm ($275 of re-writes): $188
162
+ * net. `cache-misses` prices it on your own history.
163
+ */
164
+ export declare const KEEP_WARM_COMMAND = "context-doctor-keep-warm";
165
+ export declare const KEEP_WARM_MAX_HOURS = 8;
166
+ export declare const KEEP_WARM_DEFAULT_CAP_USD = 2;
167
+ export declare const KEEP_WARM_MAX_CAP_USD = 20;
168
+ /** A ping every this long keeps a 1-hour cache warm, and a 5-minute one (coldreturns.ts prices the same). */
169
+ export declare const PING_EVERY_1H_MS: number;
170
+ export declare const PING_EVERY_5M_MS = 270000;
171
+ /** The band's clock ticks this often: a ping goes out within one tick before its time, never after it. */
172
+ export declare const KEEP_WARM_TICK_MS = 30000;
173
+ /** Asks for haste in the prompt, not with `effort`: a level other than the session's could write the whole context again. */
174
+ 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.";
175
+ export type KeepWarmRequest = {
176
+ kind: "off";
177
+ } | {
178
+ kind: "status";
179
+ } | {
180
+ kind: "arm";
181
+ hours: number;
182
+ capUsd: number;
183
+ } | {
184
+ kind: "error";
185
+ text: string;
186
+ };
187
+ /** The command's arguments: `2h`, `90m`, `2h $5`, `off`. None is a question, not a yes. */
188
+ export declare function parseKeepWarm(args: string | undefined): KeepWarmRequest;
189
+ /** One yes: its limits, what it has spent, and why it stopped. */
190
+ export interface KeepWarm {
191
+ armedAt: number;
192
+ until: number;
193
+ capUsd: number;
194
+ spentUsd: number;
195
+ pings: number;
196
+ lastPingAt?: number;
197
+ stopped?: string;
198
+ }
199
+ /**
200
+ * CONTEXT_DOCTOR_KEEP_WARM_PING_MS: a ping every this many ms (1 s to 5 min)
201
+ * and the clock ticking at least that often, for the canary alone, which
202
+ * cannot wait 55 minutes to see a ping reach its mock API. Unset, the real
203
+ * intervals.
204
+ */
205
+ export declare function keepWarmTestEvery(raw: string | undefined): number | undefined;
206
+ export declare const pingEvery: (ttlMs: number) => number;
207
+ /** 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. */
208
+ export declare function pingEstimateUsd(d: BandData): number | undefined;
209
+ /** Why keeping warm cannot start now, or undefined when it can. */
210
+ export declare function keepWarmRefusal(d: BandData | undefined, now: number): string | undefined;
211
+ export type KeepWarmStep = {
212
+ do: "wait";
213
+ } | {
214
+ do: "ping";
215
+ } | {
216
+ do: "stop";
217
+ why: string;
218
+ };
219
+ /**
220
+ * What the timer does at `now`: wait, ping, or stop for good. A ping is due
221
+ * a tick before its interval is up after the last request or ping, so it
222
+ * lands inside the cache's life; a cache that lapsed anyway (Claude Code
223
+ * closed, the machine asleep) is not pinged, since that ping would write the
224
+ * whole context.
225
+ */
226
+ export declare function keepWarmStep(kw: KeepWarm | undefined, d: BandData | undefined, now: number, everyMs?: number): KeepWarmStep;
227
+ /** A ping's usage as `$.model.fork` reports it. */
228
+ export interface PingUsage {
229
+ input_tokens: number;
230
+ output_tokens: number;
231
+ cache_read_input_tokens: number;
232
+ cache_creation_input_tokens: number;
233
+ }
234
+ /**
235
+ * What a ping read and cost. Warm: it read the context and wrote little
236
+ * (the fork's own tail is never cached). Priced from the band's figures: a
237
+ * read at the per-message rate, a write at the session's re-write rate,
238
+ * uncached input at that over the TTL's multiple (2x for 1 hour, 1.25x for
239
+ * 5 minutes), output at 5x input (every current Claude model). An estimate.
240
+ */
241
+ export declare function pingOutcome(u: PingUsage, d: BandData): {
242
+ warm: boolean;
243
+ usd: number;
244
+ };
245
+ /** The band while keeping warm: for how long more, what it has spent, against its limit. */
246
+ export declare function keepWarmText(kw: KeepWarm, now: number): string;
247
+ /** What the command says when it arms. */
248
+ export declare function keepWarmArmedText(kw: KeepWarm, d: BandData): string;
249
+ /** The command with no arguments: the price of a yes, or how the one in force stands. Arms nothing. */
250
+ export declare function keepWarmStatusText(kw: KeepWarm | undefined, d: BandData | undefined, now: number): string;
251
+ /** `mod usage`'s answer (usagepane.ts prints exactly this shape). */
252
+ export interface ModelUse {
253
+ model: string;
254
+ usd: number;
255
+ tokens: number;
256
+ requests: number;
257
+ }
258
+ export interface PeriodUse {
259
+ key: "today" | "7d" | "30d";
260
+ label: string;
261
+ usd: number;
262
+ tokens: number;
263
+ requests: number;
264
+ models: ModelUse[];
265
+ }
266
+ export interface HistoryUse {
267
+ at: number;
268
+ periods: PeriodUse[];
269
+ unpriced?: number;
270
+ /** `limits`' per-reset figures (F4): dollars per 1% of each window, of the current one or else the last with a figure. */
271
+ limitFits?: Partial<Record<string, {
272
+ usdPerPct: number;
273
+ relSe?: number;
274
+ current: boolean;
275
+ resetsAt: number;
276
+ }>>;
277
+ /** The latest move in that figure: before and after, after / before, when. */
278
+ limitMove?: {
279
+ window: string;
280
+ at: number;
281
+ before: number;
282
+ after: number;
283
+ factor: number;
284
+ };
285
+ /** Weekly readings and no 5-hour ones: a plan without that window (Ultra). */
286
+ noFiveHour?: boolean;
287
+ }
288
+ export interface LimitWindow {
289
+ window: string;
290
+ label: string;
291
+ pct: number;
292
+ at: number;
293
+ resetsAt?: number;
294
+ resetSince: boolean;
295
+ perHour?: number;
296
+ runsOutAt?: number;
297
+ beforeReset?: boolean;
298
+ usdPerPct?: number;
299
+ relSe?: number;
300
+ fitFromEarlier?: boolean;
301
+ stale?: boolean;
302
+ }
303
+ export interface AgentUse {
304
+ id: string;
305
+ model?: string;
306
+ contextTokens?: number;
307
+ window?: number;
308
+ usd?: number;
309
+ requests?: number;
310
+ }
311
+ export interface UsagePaneData {
312
+ at: number;
313
+ history?: HistoryUse;
314
+ historyFrom?: "cache" | "measured";
315
+ historyMs?: number;
316
+ limits: LimitWindow[];
317
+ agents: AgentUse[];
318
+ }
319
+ /** What Claude Code said last (`session.measure`, or `$.session.usage()` when the pane opened). */
320
+ export interface LiveUsage {
321
+ at: number;
322
+ context?: {
323
+ tokens?: number;
324
+ window: number;
325
+ percent?: number;
326
+ };
327
+ rateLimits?: RateLimitLike[];
328
+ model?: string;
329
+ }
330
+ export interface RateLimitLike {
331
+ kind: string;
332
+ percentUsed: number;
333
+ resetsAt?: string;
334
+ }
335
+ /** A subagent as `$.agent.list()` names it (the fields the pane reads). */
336
+ export interface AgentLike {
337
+ id: string;
338
+ type?: string;
339
+ description?: string;
340
+ status?: string;
341
+ name?: string;
342
+ }
343
+ /** The agent statuses that count as running: started and not settled. */
344
+ export declare const RUNNING: Set<string>;
345
+ /** "claude-opus-5-5" → "Opus 5.5", "claude-haiku-4-5-20251001" → "Haiku 4.5"; anything else as it is. */
346
+ export declare function shortModel(id: string | undefined): string;
347
+ /** A bar of `width` cells, filled to `pct`: "██████░░░░". */
348
+ export declare function bar(pct: number, width?: number): string;
349
+ /** "41%", "0.4%", "100%". */
350
+ export declare function pctText(pct: number): string;
351
+ /** The context ring, for the surfaces that draw `Svg`: a circle filled to `pct`, the percent in its middle. */
352
+ export declare function ringSvg(pct: number, size?: number): string;
353
+ export interface UsageView {
354
+ /** The context ring: its percent and its words. */
355
+ context: {
356
+ pct?: number;
357
+ text: string;
358
+ };
359
+ limits: Array<{
360
+ key: string;
361
+ label: string;
362
+ pct: number;
363
+ text: string;
364
+ sub?: string;
365
+ }>;
366
+ limitsNote?: string;
367
+ /** One line per period: "Today $42.10 · 3.1M tokens". */
368
+ periods: Array<{
369
+ key: string;
370
+ text: string;
371
+ }>;
372
+ /** The chosen period, by model. */
373
+ period?: {
374
+ key: string;
375
+ label: string;
376
+ rows: Array<{
377
+ model: string;
378
+ text: string;
379
+ }>;
380
+ };
381
+ historyNote?: string;
382
+ agents: Array<{
383
+ key: string;
384
+ head: string;
385
+ text: string;
386
+ }>;
387
+ agentsNote?: string;
388
+ /** For a minimized pane (the Desktop app's widget): one line. */
389
+ glance: string;
390
+ footer: string;
391
+ }
392
+ export interface UsageViewInput {
393
+ data?: UsagePaneData;
394
+ live?: LiveUsage;
395
+ /** `$.agent.list()`'s rows; undefined when this Claude Code has no such call. */
396
+ agents?: AgentLike[];
397
+ /** Which period the by-model rows are for. */
398
+ period?: PeriodUse["key"];
399
+ loading?: boolean;
400
+ error?: string;
401
+ now: number;
402
+ }
403
+ /** 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. */
404
+ export declare function mergeLimits(ledger: LimitWindow[], live: LiveUsage | undefined): LimitWindow[];
405
+ /** Everything the usage pane says, as words; register.ts lays it out. */
406
+ export declare function usageView(v: UsageViewInput): UsageView;
407
+ /** The pane as lines of text: the command's answer where no surface draws the pane (`claude -p`, a headless host). */
408
+ export declare function usageText(view: UsageView): string;
409
+ /** How often the pane asks `mod usage` again: the history (cached by the CLI for as long) and the subagents while any runs. */
410
+ export declare const USAGE_HISTORY_EVERY_MS: number;
411
+ export declare const USAGE_AGENTS_EVERY_MS = 30000;
412
+ /**
413
+ * Whether the pane asks `mod usage` now, and for what. Never while closed or
414
+ * while a run is in flight; the history at most every 5 minutes; the
415
+ * subagents and the limits every 30 s while a subagent runs or after a turn
416
+ * moved them. Nothing on a draw: drawing only reads.
417
+ */
418
+ export declare function usageDue(s: {
419
+ open: boolean;
420
+ loading: boolean;
421
+ lastAt?: number;
422
+ historyAt?: number;
423
+ measuredAt?: number;
424
+ agentsRunning: number;
425
+ }, now: number): false | {
426
+ history: boolean;
427
+ };
428
+ /** The command the pane runs: the CLI's own. */
429
+ export declare function usageArgv(node: string, cli: string): string[];
430
+ /** Parse `mod usage`'s output; undefined when it is not one. */
431
+ export declare function parseUsage(stdout: string): UsagePaneData | undefined;