context-doctor 0.43.0 → 0.45.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 (61) hide show
  1. package/README.md +4 -2
  2. package/dist/budget.d.ts +23 -3
  3. package/dist/budget.js +184 -50
  4. package/dist/cache.js +5 -4
  5. package/dist/cachemisses.js +1 -1
  6. package/dist/cachettl.d.ts +5 -1
  7. package/dist/cachettl.js +16 -29
  8. package/dist/ci.js +18 -2
  9. package/dist/cli.js +16 -12
  10. package/dist/codexcompact.d.ts +24 -3
  11. package/dist/codexcompact.js +221 -48
  12. package/dist/coldresume.js +16 -8
  13. package/dist/compactwindow.js +14 -9
  14. package/dist/cursor.d.ts +10 -0
  15. package/dist/cursor.js +20 -0
  16. package/dist/doctor.d.ts +9 -0
  17. package/dist/doctor.js +52 -0
  18. package/dist/extract.d.ts +2 -2
  19. package/dist/extract.js +14 -3
  20. package/dist/fanout.js +4 -2
  21. package/dist/fix.d.ts +8 -1
  22. package/dist/fix.js +59 -13
  23. package/dist/hook.js +45 -15
  24. package/dist/httpguard.d.ts +9 -1
  25. package/dist/httpguard.js +5 -4
  26. package/dist/install.js +56 -19
  27. package/dist/lens.js +7 -7
  28. package/dist/limits.d.ts +17 -4
  29. package/dist/limits.js +41 -29
  30. package/dist/mcp.js +63 -63
  31. package/dist/mcpclient.js +19 -19
  32. package/dist/mcpschema.js +10 -12
  33. package/dist/overhead.d.ts +7 -2
  34. package/dist/overhead.js +11 -3
  35. package/dist/pack.js +87 -23
  36. package/dist/pricing.d.ts +125 -6
  37. package/dist/pricing.js +304 -59
  38. package/dist/proxy.d.ts +26 -1
  39. package/dist/proxy.js +45 -5
  40. package/dist/prune.d.ts +8 -0
  41. package/dist/prune.js +73 -10
  42. package/dist/savings.js +17 -9
  43. package/dist/scan.d.ts +7 -1
  44. package/dist/scan.js +19 -1
  45. package/dist/sessionprice.d.ts +9 -2
  46. package/dist/sessionprice.js +95 -36
  47. package/dist/settingsedit.js +3 -2
  48. package/dist/spend.d.ts +75 -10
  49. package/dist/spend.js +279 -37
  50. package/dist/statusline.d.ts +10 -2
  51. package/dist/statusline.js +17 -8
  52. package/dist/subagentmodel.d.ts +2 -2
  53. package/dist/subagentmodel.js +42 -25
  54. package/dist/subagentpay.d.ts +17 -0
  55. package/dist/subagentpay.js +41 -2
  56. package/dist/subagents.d.ts +24 -0
  57. package/dist/subagents.js +93 -27
  58. package/dist/tasks.js +9 -6
  59. package/dist/tooloutput.d.ts +2 -0
  60. package/dist/tooloutput.js +16 -5
  61. package/package.json +1 -1
package/dist/spend.d.ts CHANGED
@@ -5,7 +5,8 @@
5
5
  * Each tool keeps its own record of what it sent, and none adds them up:
6
6
  *
7
7
  * - Claude Code: every reply's `usage` in its transcripts, the main
8
- * conversation and each subagent's (`<session>/subagents/agent-*.jsonl`),
8
+ * conversation, each subagent's (`<session>/subagents/agent-*.jsonl`)
9
+ * and each workflow agent's (`<session>/subagents/workflows/<run>/`),
9
10
  * read as `limits` reads them (claudeFileUsage): each reply once, its
10
11
  * output settled on its last row, a fork's copy of its parent counted once.
11
12
  * - Codex: the `token_count` events of its rollouts (~/.codex/sessions and
@@ -20,7 +21,10 @@
20
21
  * and an upper bound. Replies on Auto ("default") have no list price and
21
22
  * are counted, not priced.
22
23
  *
23
- * Priced at pricing.ts's list prices (usageCost), as every report here is.
24
+ * Priced at pricing.ts's list prices with what each request recorded that
25
+ * changes its bill (requestCost: fast mode, US-only inference, a long
26
+ * prompt's tier, web searches, a price past its end date), as every report
27
+ * here is; the report says what the modifiers added.
24
28
  * Claude Code, Codex and Gemini CLI are read through the shared scan
25
29
  * (scan.ts), so a second run reads only what was appended since; Cursor's
26
30
  * replies are kept per chat until the chat changes.
@@ -30,6 +34,7 @@
30
34
  * sessions with 10+ requests. `spend` counts every request, its output and
31
35
  * subagents too; on the requests both count, the dollars are the same.
32
36
  */
37
+ import { type Modifiers } from "./pricing.js";
33
38
  import { type Extractor } from "./scan.js";
34
39
  export type Tool = "claude" | "codex" | "gemini" | "cursor";
35
40
  export declare const TOOLS: Tool[];
@@ -53,29 +58,68 @@ export interface SpendItem {
53
58
  readUsd: number;
54
59
  outputUsd: number;
55
60
  priced: boolean;
56
- /** Claude Code: run by a subagent. */
61
+ /** Priced by its family's row, not one of its own (a new release, an id the table does not list), or past `changedOn`: an estimate. */
62
+ estimated?: boolean;
63
+ /** Its model's price in the table changed on this day ("YYYY-MM-DD"), before the request: priced at what the page said would follow, an estimate. */
64
+ changedOn?: string;
65
+ /** What fast mode, US-only, a long prompt's tier and web searches added to its list price, inside `usd`; absent when nothing. */
66
+ modifiers?: Modifiers;
67
+ /** Run by a subagent: Claude Code's (the Agent tool's), or an agent a Codex thread spawned (its `session` is then the thread's). */
57
68
  subagent?: boolean;
69
+ /** Claude Code: run by a workflow agent: its run, "<session>/<run>". */
70
+ workflow?: string;
58
71
  /** Claude Code: the reply's row uuid, which a fork's copy shares. Codex: the event's codexEventKey, which a forked rollout's copy shares. */
59
72
  key?: string;
60
73
  }
61
- /** A project's name as `savings` shows it: the folder's path with "-" for separators, less "-Users-<you>-". */
74
+ /**
75
+ * A project folder's name (its path with "-" for separators, as Claude Code
76
+ * names its projects/ folders) less the home folder: "-Users-<you>-" on
77
+ * macOS, "-home-<you>-" (or "-root-") on Linux, "C--Users-<you>-" on Windows.
78
+ * Only macOS's was stripped, so on Linux and Windows every project read
79
+ * "home-kp-app" or "C--Users-kp-app".
80
+ */
81
+ export declare function projectFromDir(dir: string): string;
82
+ /** A project's name as `savings` shows it: the folder's path with "-" for separators, less the home folder. */
62
83
  export declare function projectName(folder: string): string;
84
+ /** Whether a request's modifiers added anything (kept on an item only then). */
85
+ export declare const anyModifier: (m: Modifiers | undefined) => m is Modifiers;
63
86
  /**
64
87
  * Claude Code's requests between `since` and `until`, main threads and
65
88
  * subagents, over `tops` (default: every transcript written since `since`).
66
89
  */
67
90
  export declare function claudeSpend(since: number, until?: number, tops?: string[], onProgress?: (done: number, total: number) => void): SpendItem[];
68
91
  /**
69
- * What `spend` takes from a Codex rollout: its folder, each model change,
70
- * and every token_count event's last request and running total.
92
+ * What `spend` takes from a Codex rollout: its folder, its own id and the
93
+ * thread that spawned it (the first session_meta), each model change, and
94
+ * every token_count event's last request and running total.
71
95
  */
72
- export declare const CODEX_SPEND_ROWS: Extractor<null>;
96
+ export declare const CODEX_SPEND_ROWS: Extractor<{
97
+ m?: 1;
98
+ }>;
73
99
  /** The requests of one Codex rollout since `since`. Throws when it cannot be read. */
74
100
  export declare function codexFileSpend(file: string, since: number, until?: number): SpendItem[];
75
101
  /** Codex rollouts written since `since`: the live ones and the archived. */
76
102
  export declare function codexFiles(since: number, home?: string): string[];
77
- /** Every Codex request in the window, once: a forked rollout's copy of its parent's (codexEventKey) counts at the earliest time met. */
103
+ /** A Codex rollout's own thread id and the thread that spawned it, when one did (spawnedBy). Throws when it cannot be read. */
104
+ export declare function codexRolloutMeta(file: string): {
105
+ id?: string;
106
+ parent?: string;
107
+ };
108
+ /**
109
+ * Every Codex request in the window, once: a forked rollout's copy of its
110
+ * parent's (codexEventKey) counts at the earliest time met. A spawned
111
+ * agent's requests are its session's (the thread at the top of its
112
+ * parents, when its rollout is among the window's), marked `subagent`: they
113
+ * bill to the same work, as a Claude Code subagent's do.
114
+ */
78
115
  export declare function codexSpend(since: number, until?: number, home?: string): SpendItem[];
116
+ /**
117
+ * The rollouts of the agents a Codex thread spawned (and theirs), for the
118
+ * session price: those written since the thread began in its own folder,
119
+ * the day folders from then to `now` (by local and UTC date) and the
120
+ * archive. Only each candidate's first line is read.
121
+ */
122
+ export declare function codexSpawnedRollouts(parent: string, now?: number, home?: string): string[];
79
123
  /**
80
124
  * What `spend` takes from a Gemini CLI chat (JSONL): each `gemini` message's
81
125
  * id, time, model and token counts. A message without a time of its own
@@ -100,14 +144,23 @@ export interface ToolSpend {
100
144
  write: number;
101
145
  output: number;
102
146
  };
103
- /** Claude Code: what its subagents cost, inside `usd`. */
147
+ /** What its subagents cost, inside `usd`: Claude Code's (the Agent tool's), Codex's spawned agents. */
104
148
  subagentUsd?: number;
149
+ /** Claude Code: what its workflow agents cost, inside `usd`, and in how many workflow runs. */
150
+ workflowUsd?: number;
151
+ workflowRuns?: number;
105
152
  /** Cursor: priced without a cache split, an upper bound. */
106
153
  estimate?: boolean;
107
154
  /** Requests whose model has no list price, counted but not in `usd`. */
108
155
  unpriced: number;
109
156
  unpricedTokens: number;
110
157
  unpricedModels: string[];
158
+ /** Requests on a model the table prices only by its family (SpendItem.estimated): in `usd`, an estimate. */
159
+ estimated?: {
160
+ requests: number;
161
+ usd: number;
162
+ models: string[];
163
+ };
111
164
  }
112
165
  export interface SpendRow {
113
166
  usd: number;
@@ -131,13 +184,23 @@ export interface SpendReport {
131
184
  daily: Array<SpendRow & {
132
185
  day: string;
133
186
  }>;
134
- /** The bill by what it paid for. */
187
+ /** The bill by what it paid for; web searches (Claude's, per use) only when there were any. */
135
188
  parts: {
136
189
  inputUsd: number;
137
190
  writeUsd: number;
138
191
  readUsd: number;
139
192
  outputUsd: number;
193
+ webSearchUsd?: number;
140
194
  };
195
+ /** What billing modifiers added to the list prices, inside `usd` (fast mode, US-only, long-prompt tiers, web searches); absent when nothing. */
196
+ modifiers?: Modifiers;
197
+ /** Models whose price in the table changed on a day before some of their requests: those are priced at what the page said would follow, an estimate. */
198
+ priceChanged?: Array<{
199
+ model: string;
200
+ on: string;
201
+ requests: number;
202
+ usd: number;
203
+ }>;
141
204
  sessions: Array<{
142
205
  tool: Tool;
143
206
  project: string;
@@ -174,6 +237,8 @@ export declare const MAX_SPEND_DAYS = 3650;
174
237
  /** The last `days` days, every tool on this machine. A tool with nothing on disk is just absent. */
175
238
  export declare function spendReport(days?: number, opts?: SpendOptions): SpendReport;
176
239
  export declare const usd: (n: number) => string;
240
+ /** "fast mode +$4.10, US-only +$0.93, web searches $0.12 (12), long-prompt tier +$0.40": what each billing modifier added, the ones that added anything. */
241
+ export declare function modifiersText(m: Modifiers): string;
177
242
  /** The full report, kept within 80 columns. `top`: rows per list. */
178
243
  export declare function renderSpend(r: SpendReport, top?: number): string;
179
244
  /**