context-doctor 0.49.0 → 0.50.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.
Files changed (50) hide show
  1. package/README.md +16 -14
  2. package/dist/appwindow.d.ts +69 -0
  3. package/dist/appwindow.js +147 -0
  4. package/dist/ccost.d.ts +35 -0
  5. package/dist/ccost.js +105 -5
  6. package/dist/claudedir.d.ts +15 -0
  7. package/dist/claudedir.js +19 -1
  8. package/dist/cli.js +59 -23
  9. package/dist/clihelp.d.ts +5 -1
  10. package/dist/clihelp.js +9 -1
  11. package/dist/codexstatusline.d.ts +176 -0
  12. package/dist/codexstatusline.js +353 -0
  13. package/dist/compactwindow.d.ts +14 -2
  14. package/dist/compactwindow.js +30 -5
  15. package/dist/credits.d.ts +130 -0
  16. package/dist/credits.js +265 -0
  17. package/dist/doctor.d.ts +6 -0
  18. package/dist/doctor.js +15 -1
  19. package/dist/fanout.d.ts +2 -0
  20. package/dist/fanout.js +12 -2
  21. package/dist/fix.d.ts +37 -1
  22. package/dist/fix.js +67 -9
  23. package/dist/install.js +1 -1
  24. package/dist/limits.d.ts +56 -2
  25. package/dist/limits.js +181 -14
  26. package/dist/mcp.d.ts +1 -0
  27. package/dist/mcp.js +106 -100
  28. package/dist/mod/api.d.ts +27 -1
  29. package/dist/mod/api.js +2 -1
  30. package/dist/mod/logic.d.ts +47 -16
  31. package/dist/mod/logic.js +68 -39
  32. package/dist/mod/register.d.ts +6 -0
  33. package/dist/mod/register.js +34 -6
  34. package/dist/modelids.js +2 -2
  35. package/dist/orgrates.d.ts +4 -2
  36. package/dist/orgrates.js +21 -3
  37. package/dist/overhead.js +2 -1
  38. package/dist/pricing.js +12 -0
  39. package/dist/progresssummaries.d.ts +20 -1
  40. package/dist/progresssummaries.js +33 -3
  41. package/dist/proxy.d.ts +1 -1
  42. package/dist/proxy.js +9 -4
  43. package/dist/savings.js +3 -1
  44. package/dist/sidecost.d.ts +65 -0
  45. package/dist/sidecost.js +117 -0
  46. package/dist/spend.d.ts +36 -1
  47. package/dist/spend.js +49 -5
  48. package/dist/starts.d.ts +27 -1
  49. package/dist/starts.js +81 -18
  50. package/package.json +1 -1
package/dist/limits.d.ts CHANGED
@@ -96,6 +96,45 @@ export declare function rateLimitsFromHeaders(get: (name: string) => string | nu
96
96
  used_percentage: number;
97
97
  resets_at?: number;
98
98
  }> | undefined;
99
+ /**
100
+ * What a reply's `anthropic-ratelimit-unified-overage-*` headers say about
101
+ * usage credits (Claude's "extra usage": past a plan's limit, requests go on
102
+ * and are paid from credits). Only the four the proxy records, as given:
103
+ * `-overage-status` ("allowed", "allowed_warning", "rejected"),
104
+ * `-overage-in-use` ("true" while requests are being paid from credits),
105
+ * `-overage-utilization` (a fraction of the credits' cap, kept here as a
106
+ * percent in 0.1 steps) and `-overage-reset` (epoch seconds). Read from
107
+ * Claude Code 2.1.311's own parsing of the same headers. Undefined when a
108
+ * reply carries none of them (an API key, Bedrock, Vertex).
109
+ */
110
+ export interface OverageHeaders {
111
+ status?: string;
112
+ inUse?: boolean;
113
+ pct?: number;
114
+ reset?: number;
115
+ }
116
+ export declare function overageFromHeaders(get: (name: string) => string | null | undefined): OverageHeaders | undefined;
117
+ /** One reading of the credits headers, as the log keeps it. */
118
+ export interface OverageReading {
119
+ ts: number;
120
+ status?: string;
121
+ inUse?: boolean;
122
+ /** Percent of the credits' cap used. */
123
+ pct?: number;
124
+ /** When the credits' cap resets, ms. */
125
+ resetsAt?: number;
126
+ source?: LimitSource;
127
+ }
128
+ /**
129
+ * Append what the credits headers say to the same log as the windows, as a
130
+ * line of its own (`"w": "overage"`, which older versions skip): at
131
+ * once when the status, whether credits are in use, or the reset changed;
132
+ * a moved utilization at most once a minute; an unchanged one every 15
133
+ * minutes. Never throws. Returns the lines written (0 or 1).
134
+ */
135
+ export declare function recordOverage(o: OverageHeaders | undefined, now?: number, path?: string, source?: LimitSource): number;
136
+ /** Every credits reading in the log since `since`, oldest first. */
137
+ export declare function readOverageReadings(since?: number, path?: string): OverageReading[];
99
138
  export declare function codexSessionsRoot(home?: string): string;
100
139
  /** Codex rollouts under `root` (YYYY/MM/DD folders, or flat) written since `since`. */
101
140
  export declare function rolloutFiles(root: string, since: number): string[];
@@ -132,7 +171,15 @@ export declare function codexLimitData(since: number, root?: string): {
132
171
  * kept only where some bill beyond its top-level usage (extraIterations).
133
172
  * Also Claude Code's own running cost: each `cost-state` row as
134
173
  * costStateRecord keeps it, with the Claude Code version of the replies
135
- * before it (ccost.ts compares it with ours).
174
+ * before it (ccost.ts compares it with ours). A reply row keeps its
175
+ * `stop_reason` and `entrypoint` (a prompt suggestion follows a main-thread
176
+ * turn's end, sidecost.ts) and, where it has no `stop_reason`, its content
177
+ * as output tokens (`oc`: what a reply whose rows never settled cost,
178
+ * sidecost.ts). Each `api-request` row (what Claude Code sent, 2.1.308+) as
179
+ * its id, the request it repeats or extends and the time, a reply's
180
+ * `requestRef` to it, and an `api_error` row's code: a request no reply
181
+ * answers and Claude Code sent again a minute or more later is one that hung
182
+ * (ccost.ts names them).
136
183
  */
137
184
  export declare const USAGE_ROWS: Extractor<{
138
185
  ids: Record<string, 1>;
@@ -160,6 +207,8 @@ export interface ClaudeRequest extends UsagePoint {
160
207
  changedOn?: string;
161
208
  /** A compaction's own request, which no row records usage for: estimated (compactcost.ts). */
162
209
  compaction?: boolean;
210
+ /** Output tokens estimated from the reply's content, inside `output` and `usd`: its rows never settled it (sidecost.ts). */
211
+ unsettled?: number;
163
212
  /**
164
213
  * The iterations its top-level usage leaves out (extraIterations: an
165
214
  * advisor's call, an attempt a fallback replaced), each priced at its own
@@ -500,7 +549,12 @@ export declare function limitSavingsLines(fit: LimitFit | undefined, items: Arra
500
549
  * Code), or the autopilot proxy (from the API's rate-limit headers).
501
550
  */
502
551
  export declare const HOW_TO_RECORD = "To record them: `context-doctor install` (the plugin's mod writes them after each turn, Claude Code 2.1.286+; `install --statusline` on older ones), or `context-doctor autopilot on` (its proxy reads them from the API's replies).";
503
- export declare function renderLimits(r: LimitsReport): string;
552
+ /**
553
+ * The full `limits` report. `pastLimit`: lines on requests paid from usage
554
+ * credits past a limit (credits.ts creditsLines), placed under the windows;
555
+ * none when nothing went past one.
556
+ */
557
+ export declare function renderLimits(r: LimitsReport, pastLimit?: string[]): string;
504
558
  /**
505
559
  * `limits --report`: a block to paste into a GitHub issue. Per weekly
506
560
  * window: % used, dollars and tokens per 1%, the split by entrypoint and
package/dist/limits.js CHANGED
@@ -43,6 +43,7 @@ import { addModifiers, extraIterations, isUnbilledModel, NO_MODIFIERS, openAIUsa
43
43
  import { realModel } from "./tokens.js";
44
44
  import { isCompactionRow, newTrack, slimSummary, trackCompaction } from "./compactcost.js";
45
45
  import { PROXY_VERSION } from "./proxy.js";
46
+ import { contentOutputTokens, unsettledVersion } from "./sidecost.js";
46
47
  const MIN = 60_000;
47
48
  const HOUR = 60 * MIN;
48
49
  const DAY = 24 * HOUR;
@@ -152,17 +153,21 @@ export function recordLimits(rateLimits, now = Date.now(), path = limitsLogPath(
152
153
  });
153
154
  if (!due.length)
154
155
  return 0;
155
- if (existsSync(path) && statSync(path).size > LOG_ROTATE_AT) {
156
- const text = tail(path, LOG_KEEP_BYTES);
157
- writeFileSync(path, text.slice(text.indexOf("\n") + 1));
158
- }
159
- appendFileSync(path, due.map((l) => JSON.stringify(l)).join("\n") + "\n");
156
+ appendLog(path, due);
160
157
  return due.length;
161
158
  }
162
159
  catch {
163
160
  return 0;
164
161
  }
165
162
  }
163
+ /** Append lines to the log, keeping its newest LOG_KEEP_BYTES once it passes LOG_ROTATE_AT. Throws on a write error (callers catch). */
164
+ function appendLog(path, lines) {
165
+ if (existsSync(path) && statSync(path).size > LOG_ROTATE_AT) {
166
+ const text = tail(path, LOG_KEEP_BYTES);
167
+ writeFileSync(path, text.slice(text.indexOf("\n") + 1));
168
+ }
169
+ appendFileSync(path, lines.map((l) => JSON.stringify(l)).join("\n") + "\n");
170
+ }
166
171
  /** Every Claude reading in the log since `since`. */
167
172
  export function readClaudeReadings(since = 0, path = limitsLogPath()) {
168
173
  if (!existsSync(path))
@@ -205,6 +210,98 @@ export function rateLimitsFromHeaders(get) {
205
210
  }
206
211
  return Object.keys(out).length ? out : undefined;
207
212
  }
213
+ export function overageFromHeaders(get) {
214
+ const h = (n) => {
215
+ const v = get(`anthropic-ratelimit-unified-overage-${n}`);
216
+ return typeof v === "string" && v.trim() !== "" ? v.trim() : undefined;
217
+ };
218
+ const out = {};
219
+ const status = h("status");
220
+ if (status && /^[a-z_]{1,40}$/.test(status))
221
+ out.status = status;
222
+ const inUse = h("in-use");
223
+ if (inUse === "true" || inUse === "false")
224
+ out.inUse = inUse === "true";
225
+ const u = Number(h("utilization"));
226
+ if (h("utilization") !== undefined && Number.isFinite(u) && u >= 0 && u <= 10)
227
+ out.pct = Math.round(u * 1000) / 10;
228
+ const reset = Number(h("reset"));
229
+ if (h("reset") !== undefined && Number.isFinite(reset) && reset > 0)
230
+ out.reset = Math.round(reset);
231
+ return Object.keys(out).length ? out : undefined;
232
+ }
233
+ function parseOverageLine(line) {
234
+ let e;
235
+ try {
236
+ e = JSON.parse(line);
237
+ }
238
+ catch {
239
+ return undefined;
240
+ }
241
+ if (!e || typeof e !== "object" || e.w !== "overage" || typeof e.ts !== "number" || !Number.isFinite(e.ts))
242
+ return undefined;
243
+ return {
244
+ ts: e.ts, app: "claude", w: "overage",
245
+ ...(typeof e.status === "string" && /^[a-z_]{1,40}$/.test(e.status) ? { status: e.status } : {}),
246
+ ...(typeof e.inUse === "boolean" ? { inUse: e.inUse } : {}),
247
+ ...(typeof e.pct === "number" && Number.isFinite(e.pct) && e.pct >= 0 && e.pct <= 1000 ? { pct: e.pct } : {}),
248
+ ...(typeof e.reset === "number" && Number.isFinite(e.reset) && e.reset > 0 ? { reset: e.reset } : {}),
249
+ ...(typeof e.src === "string" && SOURCES.includes(e.src) ? { src: e.src } : {}),
250
+ };
251
+ }
252
+ /**
253
+ * Append what the credits headers say to the same log as the windows, as a
254
+ * line of its own (`"w": "overage"`, which older versions skip): at
255
+ * once when the status, whether credits are in use, or the reset changed;
256
+ * a moved utilization at most once a minute; an unchanged one every 15
257
+ * minutes. Never throws. Returns the lines written (0 or 1).
258
+ */
259
+ export function recordOverage(o, now = Date.now(), path = limitsLogPath(), source = "proxy") {
260
+ if (!o)
261
+ return 0;
262
+ const line = { ts: now, app: "claude", w: "overage", ...o, src: source };
263
+ try {
264
+ mkdirSync(dirname(path), { recursive: true });
265
+ let last;
266
+ if (existsSync(path)) {
267
+ for (const l of tail(path, 16 * 1024).split("\n"))
268
+ last = parseOverageLine(l) ?? last;
269
+ }
270
+ const sameReset = last && (last.reset !== undefined && line.reset !== undefined ? Math.abs(last.reset - line.reset) * 1000 <= SAME_RESET_MS : last.reset === line.reset);
271
+ const due = !last || now < last.ts || last.status !== line.status || last.inUse !== line.inUse || !sameReset
272
+ ? true
273
+ : last.pct === line.pct ? now - last.ts >= KEEPALIVE_MS : now - last.ts >= THROTTLE_MS;
274
+ if (!due)
275
+ return 0;
276
+ appendLog(path, [line]);
277
+ return 1;
278
+ }
279
+ catch {
280
+ return 0;
281
+ }
282
+ }
283
+ /** Every credits reading in the log since `since`, oldest first. */
284
+ export function readOverageReadings(since = 0, path = limitsLogPath()) {
285
+ if (!existsSync(path))
286
+ return [];
287
+ let text;
288
+ try {
289
+ text = readFileSync(path, "utf8");
290
+ }
291
+ catch {
292
+ return [];
293
+ }
294
+ const out = [];
295
+ for (const line of text.split("\n")) {
296
+ if (!line.includes('"overage"'))
297
+ continue;
298
+ const l = parseOverageLine(line);
299
+ if (!l || l.ts < since)
300
+ continue;
301
+ out.push({ ts: l.ts, ...(l.status ? { status: l.status } : {}), ...(l.inUse !== undefined ? { inUse: l.inUse } : {}), ...(l.pct !== undefined ? { pct: l.pct } : {}), ...(l.reset ? { resetsAt: l.reset * 1000 } : {}), ...(l.src ? { source: l.src } : {}) });
302
+ }
303
+ return out.sort((a, b) => a.ts - b.ts);
304
+ }
208
305
  // ---------------------------------------------------------------------------
209
306
  // Codex: readings and usage, both from its rollouts
210
307
  // ---------------------------------------------------------------------------
@@ -372,16 +469,26 @@ export function codexLimitData(since, root = codexSessionsRoot()) {
372
469
  * kept only where some bill beyond its top-level usage (extraIterations).
373
470
  * Also Claude Code's own running cost: each `cost-state` row as
374
471
  * costStateRecord keeps it, with the Claude Code version of the replies
375
- * before it (ccost.ts compares it with ours).
472
+ * before it (ccost.ts compares it with ours). A reply row keeps its
473
+ * `stop_reason` and `entrypoint` (a prompt suggestion follows a main-thread
474
+ * turn's end, sidecost.ts) and, where it has no `stop_reason`, its content
475
+ * as output tokens (`oc`: what a reply whose rows never settled cost,
476
+ * sidecost.ts). Each `api-request` row (what Claude Code sent, 2.1.308+) as
477
+ * its id, the request it repeats or extends and the time, a reply's
478
+ * `requestRef` to it, and an `api_error` row's code: a request no reply
479
+ * answers and Claude Code sent again a minute or more later is one that hung
480
+ * (ccost.ts names them).
376
481
  */
377
482
  export const USAGE_ROWS = {
378
- id: "usage.5",
483
+ id: "usage.6",
379
484
  init: () => ({ ids: {} }),
380
485
  line(line, row, out, st) {
381
486
  const compaction = isCompactionRow(line);
382
487
  const cost = !compaction && line.startsWith('{"type":"cost-state"');
383
488
  const refusal = !compaction && !cost && line.includes('"model_refusal_fallback"');
384
- if (!compaction && !cost && !refusal && !line.includes('"usage"'))
489
+ const sent = !compaction && !cost && line.startsWith('{"type":"api-request",');
490
+ const failed = !compaction && !cost && !sent && line.includes('"subtype":"api_error"');
491
+ if (!compaction && !cost && !refusal && !sent && !failed && !line.includes('"usage"'))
385
492
  return;
386
493
  let e;
387
494
  try {
@@ -390,6 +497,16 @@ export const USAGE_ROWS = {
390
497
  catch {
391
498
  return;
392
499
  }
500
+ if (sent) {
501
+ if (e?.type === "api-request" && typeof e.id === "string")
502
+ out.push({ type: "api-request", id: e.id, ...(typeof e.base === "string" ? { base: e.base } : {}), t: Array.isArray(e.tail) ? e.tail.length : 0, timestamp: e.timestamp });
503
+ return;
504
+ }
505
+ if (failed) {
506
+ if (e?.type === "system" && e.subtype === "api_error")
507
+ out.push({ type: "system", subtype: "api_error", timestamp: e.timestamp, code: String(e.error?.connection?.code ?? e.error?.status ?? "").slice(0, 40) });
508
+ return;
509
+ }
393
510
  if (cost || refusal) {
394
511
  const r = cost ? costStateRecord(e, st.v) : refusalRecord(e);
395
512
  if (r)
@@ -415,14 +532,23 @@ export const USAGE_ROWS = {
415
532
  if (st.ids[m.id]) {
416
533
  // Its billed iterations too: a streamed reply may settle those on a later row as well.
417
534
  const its = slimUsage(m.usage, { iterations: true });
418
- out.push({ type: "assistant", message: { id: m.id, usage: { ...pick(m.usage, ["output_tokens"]), ...(its?.iterations ? { iterations: its.iterations } : {}) } } });
535
+ out.push({ type: "assistant", message: { id: m.id, usage: { ...pick(m.usage, ["output_tokens"]), ...(its?.iterations ? { iterations: its.iterations } : {}) }, ...settling(m, e.version) } });
419
536
  return;
420
537
  }
421
538
  st.ids[m.id] = 1;
422
539
  }
423
- out.push(pick({ ...e, isSidechain: e.isSidechain === true || undefined, message: pick({ ...m, usage: slimUsage(m.usage, { iterations: true }) }, ["id", "model", "usage"]) }, ["type", "uuid", "timestamp", "isSidechain", "message"]));
540
+ out.push(pick({ ...e, isSidechain: e.isSidechain === true || undefined, message: { ...pick({ ...m, usage: slimUsage(m.usage, { iterations: true }) }, ["id", "model", "usage"]), ...settling(m, e.version) } }, ["type", "uuid", "timestamp", "isSidechain", "entrypoint", "requestRef", "message"]));
424
541
  },
425
542
  };
543
+ /** A reply row's `stop_reason`, or (none, from a Claude Code that left replies unsettled: unsettledVersion) its content as output tokens. */
544
+ function settling(m, version) {
545
+ if (typeof m.stop_reason === "string" && m.stop_reason)
546
+ return { stop_reason: m.stop_reason.slice(0, 40) };
547
+ if (!unsettledVersion(version))
548
+ return {};
549
+ const oc = contentOutputTokens(m.content);
550
+ return oc > 0 ? { oc } : {};
551
+ }
426
552
  /** A compaction's estimated request as a request point (no message id: its key is the boundary's uuid). */
427
553
  export function compactionPoint(c) {
428
554
  const u = c.usage;
@@ -476,6 +602,8 @@ export function claudeFileUsage(file, since, until = Infinity, runRows) {
476
602
  const sighting = replyCounter(runRows);
477
603
  const settle = outputSettler();
478
604
  const byId = new Map();
605
+ // Per reply: whether a row of it settled (has a stop_reason), and what its rows' content took to write (sidecost.ts).
606
+ const settled = new Map();
479
607
  const track = newTrack();
480
608
  rowsOf(file, USAGE_ROWS).forEach((e) => {
481
609
  const done = trackCompaction(track, e);
@@ -484,6 +612,12 @@ export function claudeFileUsage(file, since, until = Infinity, runRows) {
484
612
  const m = e?.message;
485
613
  if (e?.type !== "assistant" || !m?.usage)
486
614
  return;
615
+ if (typeof m.id === "string") {
616
+ const s = settled.get(m.id) ?? settled.set(m.id, { stop: false, oc: 0 }).get(m.id);
617
+ if (m.stop_reason)
618
+ s.stop = true;
619
+ s.oc += typeof m.oc === "number" ? m.oc : 0;
620
+ }
487
621
  const seen = sighting(e);
488
622
  if (seen === "repeat") {
489
623
  const known = typeof m.id === "string" ? byId.get(m.id) : undefined;
@@ -547,6 +681,23 @@ export function claudeFileUsage(file, since, until = Infinity, runRows) {
547
681
  if (typeof m.id === "string")
548
682
  byId.set(m.id, { point, u });
549
683
  });
684
+ // A reply none of whose rows settled (Claude Code 2.1.284-2.1.299's subagents): its output from its content, where that is more.
685
+ for (const [id, s] of settled) {
686
+ const known = byId.get(id);
687
+ if (s.stop || !known || s.oc <= known.point.output)
688
+ continue;
689
+ const p = known.point, more = s.oc - p.output;
690
+ p.output += more;
691
+ p.unsettled = more;
692
+ if (p.rates) {
693
+ p.usd += (more * p.rates.outputPerM) / 1e6;
694
+ if (p.modifiers.fastUsd || p.modifiers.geoUsd || p.modifiers.longUsd) {
695
+ p.modifiers = { ...requestCost(p.model, { ...known.u, output_tokens: p.output }, p.ts).modifiers };
696
+ for (const x of p.extra ?? [])
697
+ addModifiers(p.modifiers, x.modifiers);
698
+ }
699
+ }
700
+ }
550
701
  return out;
551
702
  }
552
703
  /**
@@ -732,7 +883,15 @@ export function windowStatus(readings, now = Date.now()) {
732
883
  const period = readings.slice(first);
733
884
  const lookback = last.windowMs && last.windowMs <= 5 * HOUR ? HOUR : DAY;
734
885
  const recent = period.filter((r) => r.ts >= last.ts - lookback);
735
- const from = recent[0];
886
+ // A window that began within the lookback was at 0% when it began: the
887
+ // pace counts from there. From the period's first reading alone, a weekly
888
+ // window read for the first time hours after its reset (nothing used
889
+ // since) took ten minutes' burst for the day's pace and said a 2% week
890
+ // ran out in 8 hours.
891
+ const start = last.windowMs && last.resetsAt ? last.resetsAt - last.windowMs : undefined;
892
+ const from = start !== undefined && recent[0] && start >= last.ts - lookback && start < recent[0].ts
893
+ ? { ts: start, pct: 0 }
894
+ : recent[0];
736
895
  if (from && last.ts - from.ts >= 10 * MIN) {
737
896
  status.recentPerHour = Math.max(0, ((last.pct - from.pct) / (last.ts - from.ts)) * HOUR);
738
897
  }
@@ -1507,7 +1666,12 @@ function splitLine(list) {
1507
1666
  const ratio = slow.usdPerPct / fast.usdPerPct;
1508
1667
  return `${sorted.map((t) => `${t.key} ${dollars(t.usdPerPct)}${plusMinus(t.relSe)}`).join(", ")} per 1%${ratio >= 1.1 ? ` (${fast.key} drains ${ratio.toFixed(1)}x per dollar against ${slow.key})` : ""}`;
1509
1668
  }
1510
- export function renderLimits(r) {
1669
+ /**
1670
+ * The full `limits` report. `pastLimit`: lines on requests paid from usage
1671
+ * credits past a limit (credits.ts creditsLines), placed under the windows;
1672
+ * none when nothing went past one.
1673
+ */
1674
+ export function renderLimits(r, pastLimit = []) {
1511
1675
  const out = ["USAGE LIMITS", "═".repeat(60)];
1512
1676
  if (!r.windows.length && !r.resets.length) {
1513
1677
  out.push(`No limit readings yet. ${HOW_TO_RECORD}`, "", `Claude readings are kept in ${r.claudeLog.replace(homedir(), "~")}; Codex's are read from ~/.codex/sessions (none in the period).`);
@@ -1529,8 +1693,8 @@ export function renderLimits(r) {
1529
1693
  else if (s.recentPerHour === 0)
1530
1694
  out.push(" Pace: no rise over the recent readings.");
1531
1695
  else {
1532
- const avg = s.averagePerHour !== undefined ? `; ${pts(s.averagePerHour)} a hour on average this window` : "";
1533
- out.push(` Pace: ${pts(s.recentPerHour)} points an hour lately${avg}.`);
1696
+ const avg = s.averagePerHour !== undefined ? `; ${pts(s.averagePerHour)}% an hour on average this window` : "";
1697
+ out.push(` Pace: ${pts(s.recentPerHour)}% of the limit an hour lately${avg}.`);
1534
1698
  if (s.runsOutAt !== undefined) {
1535
1699
  out.push(s.beforeReset
1536
1700
  ? ` At that pace it runs out ${clock(s.runsOutAt, r.now)} (in ${hm(s.runsOutAt - r.now)}), before the reset.`
@@ -1541,6 +1705,9 @@ export function renderLimits(r) {
1541
1705
  if (r.claudeWindows.length === 1 && r.claudeWindows[0] === "seven_day") {
1542
1706
  out.push("", "No 5-hour window in Claude's readings: a plan without one (Ultra), so the weekly window is the limit.");
1543
1707
  }
1708
+ if (pastLimit.length) {
1709
+ out.push("", "Past your plan's limit: usage credits", "─".repeat(60), ...pastLimit);
1710
+ }
1544
1711
  if (r.resets.length) {
1545
1712
  out.push("", "Each weekly (or longer) window, reset to reset: API-equivalent use per 1% (UTC dates)");
1546
1713
  out.push("─".repeat(60));
package/dist/mcp.d.ts CHANGED
@@ -18,6 +18,7 @@
18
18
  * save_handoff — store a handoff brief the next chat starts from (a chat's history cannot be cut)
19
19
  * recall — search this session's own transcript (compacted turns, cleared output); stdio only
20
20
  * Prompts: context_checkup, handoff, ask_file. Resources (stdio): handoff://latest, handoff://<id>.
21
+ * Codex only (stdio): the `statusline` tool and ui://context-doctor/statusline, its footer (codexstatusline.ts).
21
22
  *
22
23
  * Built on the MCP SDK's v2 packages: one server definition answers both
23
24
  * protocol eras, a 2025-era client's `initialize` (2024-10-07 to 2025-11-25)