context-doctor 0.36.0 → 0.38.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 +25 -15
- package/dist/autoclear.d.ts +11 -4
- package/dist/autoclear.js +52 -6
- package/dist/autopilot.d.ts +24 -0
- package/dist/autopilot.js +108 -0
- package/dist/cachemisses.d.ts +104 -2
- package/dist/cachemisses.js +199 -11
- package/dist/cli.js +172 -12
- package/dist/compact.d.ts +36 -0
- package/dist/compact.js +144 -0
- package/dist/compactwindow.d.ts +1 -1
- package/dist/compactwindow.js +6 -1
- package/dist/doctor.js +58 -1
- package/dist/extract.d.ts +23 -0
- package/dist/extract.js +121 -4
- package/dist/fanout.d.ts +131 -0
- package/dist/fanout.js +317 -0
- package/dist/fileparams.d.ts +61 -0
- package/dist/fileparams.js +308 -0
- package/dist/handoff.d.ts +143 -0
- package/dist/handoff.js +539 -0
- package/dist/hook.js +15 -0
- package/dist/httpguard.d.ts +56 -0
- package/dist/httpguard.js +141 -0
- package/dist/install.js +17 -5
- package/dist/ledger.d.ts +2 -0
- package/dist/ledger.js +44 -7
- package/dist/lens.d.ts +56 -0
- package/dist/lens.js +213 -0
- package/dist/limits.d.ts +229 -0
- package/dist/limits.js +869 -0
- package/dist/mcp.d.ts +3 -0
- package/dist/mcp.js +79 -56
- package/dist/mcpschema.d.ts +25 -1
- package/dist/mcpschema.js +78 -25
- package/dist/overhead.js +7 -6
- package/dist/pack.d.ts +20 -0
- package/dist/pack.js +29 -1
- package/dist/precompact.js +8 -7
- package/dist/preferences.d.ts +3 -1
- package/dist/preferences.js +8 -6
- package/dist/pricing.d.ts +29 -2
- package/dist/pricing.js +46 -8
- package/dist/proxy.d.ts +5 -3
- package/dist/proxy.js +12 -7
- package/dist/prune.d.ts +116 -0
- package/dist/prune.js +428 -0
- package/dist/recall.d.ts +104 -0
- package/dist/recall.js +393 -0
- package/dist/rules.d.ts +7 -4
- package/dist/rules.js +12 -8
- package/dist/savings.d.ts +1 -1
- package/dist/savings.js +11 -1
- package/dist/session.js +6 -13
- package/dist/sketch.d.ts +5 -1
- package/dist/sketch.js +23 -7
- package/dist/statusline.d.ts +6 -0
- package/dist/statusline.js +9 -0
- package/dist/subagentpay.d.ts +11 -0
- package/dist/subagentpay.js +1 -1
- package/package.json +1 -1
- package/skills/context-doctor/SKILL.md +3 -0
package/dist/limits.d.ts
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `context-doctor limits`: your plan's usage limits, in their own unit.
|
|
3
|
+
*
|
|
4
|
+
* Subscriptions are billed in % of a 5-hour and a weekly window (Claude
|
|
5
|
+
* Pro/Max), or in credits per token (Codex since April 2026), and neither
|
|
6
|
+
* vendor shows where the percentage went. Two local sources say:
|
|
7
|
+
*
|
|
8
|
+
* - Claude Code hands its status line command `rate_limits.five_hour` and
|
|
9
|
+
* `.seven_day`, each `{used_percentage, resets_at}` (documented at
|
|
10
|
+
* code.claude.com/docs/en/statusline; built in 2.1.308 as
|
|
11
|
+
* Math.round(utilization*1000)/10, so 0.1% steps; present only for
|
|
12
|
+
* Pro/Max subscribers, after the first reply). `context-doctor statusline`
|
|
13
|
+
* appends each new reading to a small local log (recordLimits).
|
|
14
|
+
* - Codex records `rate_limits.primary` / `.secondary`
|
|
15
|
+
* `{used_percent, window_minutes, resets_at}` on every token_count event of
|
|
16
|
+
* its rollouts (~/.codex/sessions), next to that request's usage, in
|
|
17
|
+
* whole percent.
|
|
18
|
+
*
|
|
19
|
+
* From the readings: the current %, the pace, and when each window runs out
|
|
20
|
+
* at that pace. And, by fitting each rise in % against the usage recorded on
|
|
21
|
+
* this machine over the same interval, an estimate of what 1M tokens of each
|
|
22
|
+
* kind cost in % of the limit, with the fit's error. Usage elsewhere (claude.ai
|
|
23
|
+
* in a browser, another computer) moves the % without leaving a transcript
|
|
24
|
+
* here; it shows up as error, and rises with no local usage at all are
|
|
25
|
+
* counted apart. When the fit is too thin to trust, the report says so
|
|
26
|
+
* instead of printing a number.
|
|
27
|
+
*/
|
|
28
|
+
/** Claude Code's two windows, as its status line input names them. */
|
|
29
|
+
export declare const CLAUDE_WINDOWS: readonly ["five_hour", "seven_day"];
|
|
30
|
+
/** One reading of one window: how much of it was used at `ts`. */
|
|
31
|
+
export interface LimitReading {
|
|
32
|
+
/** When it was read, ms. */
|
|
33
|
+
ts: number;
|
|
34
|
+
app: "claude" | "codex";
|
|
35
|
+
/** "five_hour", "seven_day", or for Codex "codex:[<plan>:][<limit id>:]<minutes>". */
|
|
36
|
+
window: string;
|
|
37
|
+
/** Percent used, 0-100 (a gateway's spend can pass 100). */
|
|
38
|
+
pct: number;
|
|
39
|
+
/** When the window resets, ms. */
|
|
40
|
+
resetsAt?: number;
|
|
41
|
+
/** The window's length, ms, when known. */
|
|
42
|
+
windowMs?: number;
|
|
43
|
+
/** Codex's plan ("plus", "team", "free"...). */
|
|
44
|
+
plan?: string;
|
|
45
|
+
}
|
|
46
|
+
/** One request's usage, from a transcript on this machine. */
|
|
47
|
+
export interface UsagePoint {
|
|
48
|
+
ts: number;
|
|
49
|
+
app: "claude" | "codex";
|
|
50
|
+
model?: string;
|
|
51
|
+
/** Uncached input, cache reads, cache writes, output: tokens. */
|
|
52
|
+
input: number;
|
|
53
|
+
read: number;
|
|
54
|
+
write: number;
|
|
55
|
+
output: number;
|
|
56
|
+
/** At API list price; 0 when the model has no price on file. */
|
|
57
|
+
usd: number;
|
|
58
|
+
}
|
|
59
|
+
/** Beside the hook state and the ledger: ~/.claude/.context-doctor-limits.jsonl. */
|
|
60
|
+
export declare function limitsLogPath(): string;
|
|
61
|
+
/**
|
|
62
|
+
* Append what changed in Claude Code's `rate_limits` to the log: a window
|
|
63
|
+
* whose % or reset time moved since its last line, or that has not been
|
|
64
|
+
* written for 15 minutes. Nothing when there are no limits (an API key,
|
|
65
|
+
* Bedrock, Vertex). Never throws: the status line must stay silent. Returns
|
|
66
|
+
* the lines written.
|
|
67
|
+
*/
|
|
68
|
+
export declare function recordLimits(rateLimits: unknown, now?: number, path?: string): number;
|
|
69
|
+
/** Every Claude reading in the log since `since`. */
|
|
70
|
+
export declare function readClaudeReadings(since?: number, path?: string): LimitReading[];
|
|
71
|
+
export declare function codexSessionsRoot(home?: string): string;
|
|
72
|
+
/**
|
|
73
|
+
* Codex readings and usage since `since`. A token_count event repeats the
|
|
74
|
+
* last request's usage when only the limits were refreshed, so a request is
|
|
75
|
+
* counted when the running total moves.
|
|
76
|
+
*/
|
|
77
|
+
export declare function codexLimitData(since: number, root?: string): {
|
|
78
|
+
readings: LimitReading[];
|
|
79
|
+
usage: UsagePoint[];
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Every Claude Code request between `since` and `until`, main threads and
|
|
83
|
+
* subagents alike (both draw on the same limits), each reply once.
|
|
84
|
+
*/
|
|
85
|
+
export declare function claudeUsage(since: number, until?: number, paths?: string[]): UsagePoint[];
|
|
86
|
+
export interface WindowStatus {
|
|
87
|
+
window: string;
|
|
88
|
+
label: string;
|
|
89
|
+
app: "claude" | "codex";
|
|
90
|
+
pct: number;
|
|
91
|
+
/** When the newest reading was taken. */
|
|
92
|
+
at: number;
|
|
93
|
+
resetsAt?: number;
|
|
94
|
+
/** True when the newest reading's window has reset since (its % is stale). */
|
|
95
|
+
resetSince: boolean;
|
|
96
|
+
/** Points per hour over the recent stretch (the last hour of a 5-hour window, the last day otherwise). */
|
|
97
|
+
recentPerHour?: number;
|
|
98
|
+
/** Points per hour since the window began, when its length is known. */
|
|
99
|
+
averagePerHour?: number;
|
|
100
|
+
/** At the recent pace: when it reaches 100%, and whether that is before the reset. */
|
|
101
|
+
runsOutAt?: number;
|
|
102
|
+
beforeReset?: boolean;
|
|
103
|
+
readings: number;
|
|
104
|
+
plan?: string;
|
|
105
|
+
}
|
|
106
|
+
export declare function windowLabel(window: string, windowMs?: number): string;
|
|
107
|
+
/**
|
|
108
|
+
* One window's readings, in time order, without the stale ones: a reading
|
|
109
|
+
* lower than an earlier one of the same period comes from another session
|
|
110
|
+
* (two Claude Code windows, two Codex sessions) still holding an older
|
|
111
|
+
* figure. Within a period usage only grows, so it is dropped, never read as
|
|
112
|
+
* a new period or a fall in the pace. Logs written before 0.38 hold them.
|
|
113
|
+
*/
|
|
114
|
+
export declare function cleanReadings(readings: LimitReading[]): LimitReading[];
|
|
115
|
+
/** 0.1 when any reading has a fraction (Claude), else 1 (Codex's whole percents). */
|
|
116
|
+
export declare function resolutionOf(readings: LimitReading[]): number;
|
|
117
|
+
export declare function windowStatus(readings: LimitReading[], now?: number): WindowStatus | undefined;
|
|
118
|
+
/** A stretch of one window's period in which the % rose by `dpct`, with the usage recorded in it. */
|
|
119
|
+
export interface Segment {
|
|
120
|
+
from: number;
|
|
121
|
+
to: number;
|
|
122
|
+
dpct: number;
|
|
123
|
+
/** Millions of tokens: uncached input, cache read, cache write, output. */
|
|
124
|
+
x: [number, number, number, number];
|
|
125
|
+
usd: number;
|
|
126
|
+
requests: number;
|
|
127
|
+
}
|
|
128
|
+
export declare const TOKEN_TYPES: readonly ["input", "cache read", "cache write", "output"];
|
|
129
|
+
/**
|
|
130
|
+
* Cut each period into stretches of at least `stretchMs` (half an hour on
|
|
131
|
+
* Claude's 0.1% steps, three hours on Codex's whole percents) and sum the
|
|
132
|
+
* usage that falls inside each. Cut by time, not by rise: stretches then
|
|
133
|
+
* differ in how much was used, which is what the fit learns from, and a
|
|
134
|
+
* quiet stretch says as much as a busy one. A rise with no local usage at
|
|
135
|
+
* all is usage elsewhere: counted, kept out of the fit; a quiet stretch with
|
|
136
|
+
* no rise is left out.
|
|
137
|
+
*/
|
|
138
|
+
export declare function segmentsOf(readings: LimitReading[], usage: UsagePoint[], stretchMs?: number): {
|
|
139
|
+
segments: Segment[];
|
|
140
|
+
elsewhere: number;
|
|
141
|
+
elsewherePct: number;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Non-negative least squares through the origin, exactly, by trying every
|
|
145
|
+
* subset of columns (four token types: sixteen subsets) and keeping the best
|
|
146
|
+
* fit whose coefficients are all non-negative. Columns with almost no data
|
|
147
|
+
* are left out and reported as such.
|
|
148
|
+
*/
|
|
149
|
+
export declare function nnls(rows: number[][], y: number[], usable: number[]): number[];
|
|
150
|
+
export interface FitQuality {
|
|
151
|
+
/** 1 - SSE / total sum of squares around the mean: share of the variation explained (shown, not a gate). */
|
|
152
|
+
r2: number;
|
|
153
|
+
/** Cross-validated prediction error, in points of the limit per stretch. */
|
|
154
|
+
looRmse: number;
|
|
155
|
+
/** looRmse relative to the mean rise per stretch. */
|
|
156
|
+
relError: number;
|
|
157
|
+
/** Price fit only: the coefficient's standard error relative to the coefficient. */
|
|
158
|
+
relSe?: number;
|
|
159
|
+
}
|
|
160
|
+
export interface LimitFit {
|
|
161
|
+
window: string;
|
|
162
|
+
label: string;
|
|
163
|
+
app: "claude" | "codex";
|
|
164
|
+
segments: number;
|
|
165
|
+
/** Points the window rose over the fitted segments. */
|
|
166
|
+
totalPct: number;
|
|
167
|
+
/** Rises with no usage on this machine (usage elsewhere), left out. */
|
|
168
|
+
elsewhere: number;
|
|
169
|
+
elsewherePct: number;
|
|
170
|
+
resolution: number;
|
|
171
|
+
/** Requests and list-price dollars the segments hold. */
|
|
172
|
+
requests: number;
|
|
173
|
+
usd: number;
|
|
174
|
+
/** % of the limit per 1M tokens of each type; undefined for a type with too little data. */
|
|
175
|
+
perMillion?: Partial<Record<(typeof TOKEN_TYPES)[number], number>>;
|
|
176
|
+
byType?: FitQuality;
|
|
177
|
+
/** % of the limit per list-price dollar, and how well that alone explains the rises. */
|
|
178
|
+
pctPerUsd?: number;
|
|
179
|
+
byPrice?: FitQuality;
|
|
180
|
+
/** The model most of the dollars went to, which the per-1M figures from price are for. */
|
|
181
|
+
mainModel?: string;
|
|
182
|
+
/** Stretches left out of the price fit for rising far beyond their usage (use elsewhere at the same time), and the excess points. */
|
|
183
|
+
outliers?: number;
|
|
184
|
+
outlierPct?: number;
|
|
185
|
+
/** With an intercept, the slope's standard error relative to it: large when the rises do not follow the usage. */
|
|
186
|
+
slopeRelSe?: number;
|
|
187
|
+
/** Good enough to put savings in % of this limit. */
|
|
188
|
+
usable: boolean;
|
|
189
|
+
/** Why not, in words, when it is not. */
|
|
190
|
+
why?: string;
|
|
191
|
+
}
|
|
192
|
+
export declare function fitWindow(readings: LimitReading[], usage: UsagePoint[], stretchMs?: number): LimitFit | undefined;
|
|
193
|
+
export interface LimitsReport {
|
|
194
|
+
days: number;
|
|
195
|
+
now: number;
|
|
196
|
+
/** Where the Claude readings are logged, and how many there are. */
|
|
197
|
+
claudeLog: string;
|
|
198
|
+
claudeReadings: number;
|
|
199
|
+
codexReadings: number;
|
|
200
|
+
windows: WindowStatus[];
|
|
201
|
+
fits: LimitFit[];
|
|
202
|
+
}
|
|
203
|
+
export interface LimitsOptions {
|
|
204
|
+
now?: number;
|
|
205
|
+
logPath?: string;
|
|
206
|
+
codexRoot?: string;
|
|
207
|
+
/** Claude Code transcripts to read usage from (default: every one touched in the period). */
|
|
208
|
+
claudePaths?: string[];
|
|
209
|
+
/** Leave Codex out (savings and the other Claude Code reports). */
|
|
210
|
+
claudeOnly?: boolean;
|
|
211
|
+
}
|
|
212
|
+
export declare function limitsReport(days?: number, opts?: LimitsOptions): LimitsReport;
|
|
213
|
+
/** The Claude fit to quote savings in: the weekly window first (savings are weekly), then the 5-hour one. */
|
|
214
|
+
export declare function claudeLimitFit(r: LimitsReport): LimitFit | undefined;
|
|
215
|
+
/**
|
|
216
|
+
* A dollar saving over `days`, in the limit's own unit: for the weekly
|
|
217
|
+
* limit, points of it a week ("≈ 4.1% of your weekly limit a week (±0.4)");
|
|
218
|
+
* for the 5-hour window, how many whole windows the saving amounts to. The
|
|
219
|
+
* ± is the rate's own standard error: a saving sums many stretches, so the
|
|
220
|
+
* per-stretch miss averages out and the rate's error is what remains.
|
|
221
|
+
*/
|
|
222
|
+
export declare function inLimit(fit: LimitFit, usd: number, days: number): string | undefined;
|
|
223
|
+
/**
|
|
224
|
+
* Lines for the Claude Code reports: each lever's saving in the limit, when
|
|
225
|
+
* a fit is good enough; nothing otherwise (never a number the fit cannot
|
|
226
|
+
* carry). Kept within 60 columns, as `savings` is.
|
|
227
|
+
*/
|
|
228
|
+
export declare function limitSavingsLines(fit: LimitFit | undefined, items: Array<[label: string, usd: number]>, days: number): string[];
|
|
229
|
+
export declare function renderLimits(r: LimitsReport): string;
|