chompyy 0.5.0 → 0.7.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 (162) hide show
  1. package/README.md +14 -1
  2. package/dist/advice.js +98 -1
  3. package/dist/agentlimits.js +77 -0
  4. package/dist/agentusage.js +96 -0
  5. package/dist/approvals.js +129 -0
  6. package/dist/appstate.js +73 -3
  7. package/dist/away.js +48 -5
  8. package/dist/blueprint.js +3 -7
  9. package/dist/board.js +1 -0
  10. package/dist/cli.js +343 -18
  11. package/dist/codexquota.js +106 -0
  12. package/dist/codexusage.js +10 -0
  13. package/dist/config.js +2 -0
  14. package/dist/context.js +30 -0
  15. package/dist/costs.js +41 -2
  16. package/dist/demon.js +20 -0
  17. package/dist/detect.js +38 -6
  18. package/dist/didwork.js +26 -0
  19. package/dist/label.js +33 -0
  20. package/dist/menu.js +17 -0
  21. package/dist/nightcap.js +72 -0
  22. package/dist/nudge.js +70 -24
  23. package/dist/pacing.js +16 -1
  24. package/dist/punchcard.js +39 -0
  25. package/dist/questions.js +71 -0
  26. package/dist/recap.js +74 -0
  27. package/dist/receipt.js +48 -0
  28. package/dist/recipe.js +79 -0
  29. package/dist/savings.js +111 -0
  30. package/dist/stamps.js +14 -0
  31. package/dist/suggest.js +15 -5
  32. package/dist/triggers.js +5 -0
  33. package/dist/usage.js +21 -1
  34. package/dist/vendor/codeburn/antigravity.js +309 -0
  35. package/dist/vendor/codeburn/codex.js +429 -0
  36. package/dist/vendor/codeburn/copilot.js +292 -0
  37. package/dist/vendor/codeburn/gemini.js +195 -0
  38. package/dist/vendor/codeburn/grokbot.js +182 -0
  39. package/dist/vendor/codeburn/kimi.js +178 -0
  40. package/dist/vendor/codeburn/shims/chalk.js +14 -0
  41. package/dist/vendor/codeburn/shims/strip-ansi.js +6 -0
  42. package/dist/vendor/codeburn/src/act/backup.js +83 -0
  43. package/dist/vendor/codeburn/src/act/model-defaults.js +151 -0
  44. package/dist/vendor/codeburn/src/act/types.js +37 -0
  45. package/dist/vendor/codeburn/src/bash-utils.js +204 -0
  46. package/dist/vendor/codeburn/src/behavioral-weight.js +47 -0
  47. package/dist/vendor/codeburn/src/cache-dir.js +26 -0
  48. package/dist/vendor/codeburn/src/cache-refresh-lock.js +543 -0
  49. package/dist/vendor/codeburn/src/cache-sweep.js +67 -0
  50. package/dist/vendor/codeburn/src/classifier.js +209 -0
  51. package/dist/vendor/codeburn/src/claude-identity.js +223 -0
  52. package/dist/vendor/codeburn/src/codex-cache.js +377 -0
  53. package/dist/vendor/codeburn/src/codex-fork-replay.js +232 -0
  54. package/dist/vendor/codeburn/src/codex-jsonl-fields.js +99 -0
  55. package/dist/vendor/codeburn/src/codex-session-index.js +113 -0
  56. package/dist/vendor/codeburn/src/codex-throughput.js +544 -0
  57. package/dist/vendor/codeburn/src/compare-stats.js +405 -0
  58. package/dist/vendor/codeburn/src/config.js +145 -0
  59. package/dist/vendor/codeburn/src/content-utils.js +56 -0
  60. package/dist/vendor/codeburn/src/context-tree-codex.js +329 -0
  61. package/dist/vendor/codeburn/src/context-tree.js +664 -0
  62. package/dist/vendor/codeburn/src/copilot-aiu.js +16 -0
  63. package/dist/vendor/codeburn/src/currency.js +189 -0
  64. package/dist/vendor/codeburn/src/cursor-cache.js +238 -0
  65. package/dist/vendor/codeburn/src/cursor-import.js +402 -0
  66. package/dist/vendor/codeburn/src/cursor-sync.js +256 -0
  67. package/dist/vendor/codeburn/src/daily-cache.js +2036 -0
  68. package/dist/vendor/codeburn/src/data/litellm-snapshot.json +1 -0
  69. package/dist/vendor/codeburn/src/data/pricing-fallback.json +1 -0
  70. package/dist/vendor/codeburn/src/day-aggregator.js +327 -0
  71. package/dist/vendor/codeburn/src/editor-data-dir.js +11 -0
  72. package/dist/vendor/codeburn/src/fetch-utils.js +18 -0
  73. package/dist/vendor/codeburn/src/format.js +118 -0
  74. package/dist/vendor/codeburn/src/fs-utils.js +270 -0
  75. package/dist/vendor/codeburn/src/git-origin.js +334 -0
  76. package/dist/vendor/codeburn/src/granular-history.js +328 -0
  77. package/dist/vendor/codeburn/src/hermes-session-ledger.js +512 -0
  78. package/dist/vendor/codeburn/src/launcher-homes.js +142 -0
  79. package/dist/vendor/codeburn/src/live-sessions.js +358 -0
  80. package/dist/vendor/codeburn/src/math-utils.js +8 -0
  81. package/dist/vendor/codeburn/src/menubar-json.js +294 -0
  82. package/dist/vendor/codeburn/src/models.js +1879 -0
  83. package/dist/vendor/codeburn/src/optimize-one-hour-cache.js +92 -0
  84. package/dist/vendor/codeburn/src/optimize.js +4110 -0
  85. package/dist/vendor/codeburn/src/parse-workers.js +219 -0
  86. package/dist/vendor/codeburn/src/parser.js +6955 -0
  87. package/dist/vendor/codeburn/src/path-privacy.js +26 -0
  88. package/dist/vendor/codeburn/src/plans.js +135 -0
  89. package/dist/vendor/codeburn/src/pr-signals.js +132 -0
  90. package/dist/vendor/codeburn/src/project-filter-warnings.js +33 -0
  91. package/dist/vendor/codeburn/src/provider-issues.js +30 -0
  92. package/dist/vendor/codeburn/src/providers/amp.js +286 -0
  93. package/dist/vendor/codeburn/src/providers/antigravity.js +1731 -0
  94. package/dist/vendor/codeburn/src/providers/claude.js +551 -0
  95. package/dist/vendor/codeburn/src/providers/cline-cli.js +401 -0
  96. package/dist/vendor/codeburn/src/providers/cline.js +63 -0
  97. package/dist/vendor/codeburn/src/providers/codebuff.js +336 -0
  98. package/dist/vendor/codeburn/src/providers/codewhale.js +442 -0
  99. package/dist/vendor/codeburn/src/providers/codex.js +1720 -0
  100. package/dist/vendor/codeburn/src/providers/command-code.js +196 -0
  101. package/dist/vendor/codeburn/src/providers/copilot.js +3278 -0
  102. package/dist/vendor/codeburn/src/providers/crush.js +226 -0
  103. package/dist/vendor/codeburn/src/providers/cursor-agent.js +837 -0
  104. package/dist/vendor/codeburn/src/providers/cursor.js +1163 -0
  105. package/dist/vendor/codeburn/src/providers/devin.js +569 -0
  106. package/dist/vendor/codeburn/src/providers/droid.js +324 -0
  107. package/dist/vendor/codeburn/src/providers/dsh.js +690 -0
  108. package/dist/vendor/codeburn/src/providers/forge.js +245 -0
  109. package/dist/vendor/codeburn/src/providers/gemini.js +230 -0
  110. package/dist/vendor/codeburn/src/providers/goose.js +252 -0
  111. package/dist/vendor/codeburn/src/providers/grok.js +581 -0
  112. package/dist/vendor/codeburn/src/providers/grokbot.js +290 -0
  113. package/dist/vendor/codeburn/src/providers/hermes.js +771 -0
  114. package/dist/vendor/codeburn/src/providers/ibm-bob.js +53 -0
  115. package/dist/vendor/codeburn/src/providers/index.js +360 -0
  116. package/dist/vendor/codeburn/src/providers/kilo-code.js +50 -0
  117. package/dist/vendor/codeburn/src/providers/kimi.js +363 -0
  118. package/dist/vendor/codeburn/src/providers/kimicode.js +402 -0
  119. package/dist/vendor/codeburn/src/providers/kiro.js +1174 -0
  120. package/dist/vendor/codeburn/src/providers/lingtai-tui.js +372 -0
  121. package/dist/vendor/codeburn/src/providers/mistral-vibe-unified.js +236 -0
  122. package/dist/vendor/codeburn/src/providers/mistral-vibe.js +405 -0
  123. package/dist/vendor/codeburn/src/providers/mux.js +242 -0
  124. package/dist/vendor/codeburn/src/providers/open-design.js +217 -0
  125. package/dist/vendor/codeburn/src/providers/openclaude.js +309 -0
  126. package/dist/vendor/codeburn/src/providers/openclaw.js +442 -0
  127. package/dist/vendor/codeburn/src/providers/opencode-file-parser.js +131 -0
  128. package/dist/vendor/codeburn/src/providers/opencode.js +91 -0
  129. package/dist/vendor/codeburn/src/providers/pi.js +429 -0
  130. package/dist/vendor/codeburn/src/providers/quickdesk.js +491 -0
  131. package/dist/vendor/codeburn/src/providers/qwen.js +193 -0
  132. package/dist/vendor/codeburn/src/providers/session-message.js +118 -0
  133. package/dist/vendor/codeburn/src/providers/sqlite-session-parser.js +457 -0
  134. package/dist/vendor/codeburn/src/providers/types.js +5 -0
  135. package/dist/vendor/codeburn/src/providers/vercel-gateway.js +135 -0
  136. package/dist/vendor/codeburn/src/providers/vscode-cline-parser.js +212 -0
  137. package/dist/vendor/codeburn/src/providers/warp.js +575 -0
  138. package/dist/vendor/codeburn/src/providers/zcode.js +249 -0
  139. package/dist/vendor/codeburn/src/providers/zed.js +187 -0
  140. package/dist/vendor/codeburn/src/providers/zerostack.js +139 -0
  141. package/dist/vendor/codeburn/src/quota/antigravity.js +310 -0
  142. package/dist/vendor/codeburn/src/quota/claude.js +244 -0
  143. package/dist/vendor/codeburn/src/quota/cursor.js +301 -0
  144. package/dist/vendor/codeburn/src/quota/security.js +299 -0
  145. package/dist/vendor/codeburn/src/quota/types.js +1 -0
  146. package/dist/vendor/codeburn/src/scan-facts.js +99 -0
  147. package/dist/vendor/codeburn/src/session-cache.js +3040 -0
  148. package/dist/vendor/codeburn/src/session-count-label.js +14 -0
  149. package/dist/vendor/codeburn/src/session-output.js +139 -0
  150. package/dist/vendor/codeburn/src/session-population.js +30 -0
  151. package/dist/vendor/codeburn/src/sessions-report.js +1342 -0
  152. package/dist/vendor/codeburn/src/sqlite.js +528 -0
  153. package/dist/vendor/codeburn/src/sync/otlp.js +420 -0
  154. package/dist/vendor/codeburn/src/telemetry-snapshot.js +244 -0
  155. package/dist/vendor/codeburn/src/token-estimate.js +5 -0
  156. package/dist/vendor/codeburn/src/types.js +16 -0
  157. package/dist/vendor/codeburn/src/work-units.js +126 -0
  158. package/dist/vendor/codeburn/src/workflow-insights.js +228 -0
  159. package/dist/vendor/codeburn/src/wsl.js +198 -0
  160. package/dist/vendor/codeburn/src/yield.js +666 -0
  161. package/dist/wastechecks.js +233 -0
  162. package/package.json +1 -1
@@ -0,0 +1,30 @@
1
+ /**
2
+ * How full a conversation's context window is: the tokens its last request sent, out of the window its model has.
3
+ *
4
+ * The window depends on the model and on how it was run. Claude models have a 200k window by default; some run
5
+ * with 1M (Claude Code's `[1m]` models), and the transcript doesn't say which. So a conversation that ever sent more
6
+ * than the default must be on the bigger window. Other agents' models get their own default here when Chompyy
7
+ * reads them (provider switching).
8
+ */
9
+ export const DEFAULT_WINDOW = 200_000;
10
+ export const LONG_WINDOW = 1_000_000;
11
+ /** Default windows by model family (prefix match, first wins). Unknown models get DEFAULT_WINDOW. */
12
+ // Only Claude for now. Other agents' rows come with provider switching, from LiteLLM's max_input_tokens (the same
13
+ // snapshot codeburn bundles for prices).
14
+ const WINDOWS = [['claude-', DEFAULT_WINDOW]];
15
+ /** The window a conversation runs in: its model's default, or 1M once it has sent more than that. */
16
+ export function windowFor(model, peak) {
17
+ const base = WINDOWS.find(([p]) => model.startsWith(p))?.[1] ?? DEFAULT_WINDOW;
18
+ return peak > base ? Math.max(LONG_WINDOW, base) : base;
19
+ }
20
+ /**
21
+ * Claude Code compacts on its own a little before the window is full (it keeps room for the summary), so the jar
22
+ * reads full at this share: the time to compact yourself, on your terms, is just before.
23
+ */
24
+ export const FULL_AT = 0.9;
25
+ /** 0...1: how full the jar is (1 = where the agent would compact by itself). */
26
+ export function fill(context, window) {
27
+ if (window <= 0)
28
+ return 0;
29
+ return Math.max(0, Math.min(1, context / (window * FULL_AT)));
30
+ }
package/dist/costs.js CHANGED
@@ -81,17 +81,56 @@ export function costRange(card, runs) {
81
81
  high: percentile(pcts, hi),
82
82
  durationLowMs: percentile(durs, lo),
83
83
  durationHighMs: percentile(durs, hi),
84
+ durationMidMs: percentile(durs, 50),
84
85
  n: pool.length,
85
86
  basis,
86
87
  };
87
88
  }
89
+ /**
90
+ * Backtest: for each past run, the range Chompyy would have given from only the runs before it, and whether the run
91
+ * landed inside. The last `last` runs that had a range count. Same formula as costRange, so it's the range you saw.
92
+ */
93
+ export function hitRate(runs, last = 10) {
94
+ const ordered = [...runs].sort((a, b) => a.at.localeCompare(b.at));
95
+ const time = [];
96
+ const quota = [];
97
+ for (let i = 0; i < ordered.length; i++) {
98
+ const r = ordered[i];
99
+ if (r.status === 'error')
100
+ continue;
101
+ const est = costRange({ id: r.card, title: r.title, idea: r.idea, cwd: r.cwd }, ordered.slice(0, i));
102
+ if (!est)
103
+ continue;
104
+ time.push(r.durationMs >= est.durationLowMs && r.durationMs <= est.durationHighMs);
105
+ if (r.fiveHourPct !== null)
106
+ quota.push(r.fiveHourPct >= est.low && r.fiveHourPct <= est.high);
107
+ }
108
+ if (!time.length)
109
+ return null;
110
+ const tail = (xs) => xs.slice(-last);
111
+ return {
112
+ time: { hit: tail(time).filter(Boolean).length, of: tail(time).length },
113
+ quota: { hit: tail(quota).filter(Boolean).length, of: tail(quota).length },
114
+ };
115
+ }
116
+ /** Both, plainly: "the quota range was right for 8 of the last 10 runs, the time range for 5 of 10". Needs 3 runs. */
117
+ export function hitLine(h) {
118
+ if (!h)
119
+ return '';
120
+ const q = h.quota.of >= 3 ? `the quota range was right for ${h.quota.hit} of the last ${h.quota.of} runs` : '';
121
+ const t = h.time.of >= 3 ? `the time range for ${h.time.hit} of ${h.time.of}` : '';
122
+ if (q && t)
123
+ return `${q}, ${t}`;
124
+ return q || (t ? `the time range was right for ${h.time.hit} of the last ${h.time.of} runs` : '');
125
+ }
88
126
  const fmtPct = (n) => (n < 10 ? String(Math.round(n * 10) / 10) : String(Math.round(n)));
89
- export function formatCostRange(r) {
127
+ export function formatCostRange(r, hit = null) {
90
128
  if (!r)
91
129
  return 'Cost: not known yet (needs 2 past runs)';
130
+ const right = hitLine(hit);
92
131
  const pct = r.low === r.high ? `~${fmtPct(r.low)}%` : `${fmtPct(r.low)}–${fmtPct(r.high)}%`;
93
132
  const dur = r.durationLowMs === r.durationHighMs ? formatDuration(r.durationLowMs) : `${formatDuration(r.durationLowMs)}–${formatDuration(r.durationHighMs)}`;
94
- return `Cost: ${pct} of a 5h window · ${dur} (from ${r.n} ${r.basis === 'similar' ? 'similar' : 'past'} run${r.n === 1 ? '' : 's'})`;
133
+ return `Cost: ${pct} of a 5h window · ${dur} (from ${r.n} ${r.basis === 'similar' ? 'similar' : 'past'} run${r.n === 1 ? '' : 's'})${right ? `\n So far ${right}.` : ''}`;
95
134
  }
96
135
  export function periodStats(runs, signals, from, to) {
97
136
  const inRange = (at) => {
package/dist/demon.js ADDED
@@ -0,0 +1,20 @@
1
+ import { formatDuration } from './duration.js';
2
+ /** Offer only in the last 90 minutes: earlier, the window is still yours to use. */
3
+ export const OFFER_WITHIN_MS = 90 * 60_000;
4
+ /** Less than this and an away run can't finish a card. */
5
+ const MIN_RUN_MS = 15 * 60_000;
6
+ /** Stop a few minutes before the reset, so the last card isn't cut off by it. */
7
+ const SLACK_MS = 5 * 60_000;
8
+ /** Worth a demon only when at least this much would go to waste. */
9
+ export const MIN_UNUSED_PCT = 20;
10
+ export function demonOffer(five, forecast, approved, awayBusy) {
11
+ if (!five.known || approved < 1 || awayBusy)
12
+ return null;
13
+ if (five.msLeft > OFFER_WITHIN_MS || five.msLeft - SLACK_MS < MIN_RUN_MS)
14
+ return null;
15
+ const unusedPct = forecast.kind === 'unused' ? forecast.unusedPct : forecast.kind === 'unknown' ? five.leftPct : 0;
16
+ if (unusedPct < MIN_UNUSED_PCT)
17
+ return null;
18
+ const runMs = Math.floor((five.msLeft - SLACK_MS) / (5 * 60_000)) * 5 * 60_000;
19
+ return { unusedPct: Math.round(unusedPct), resetsAt: five.resetsAt, cards: approved, duration: formatDuration(runMs) };
20
+ }
package/dist/detect.js CHANGED
@@ -104,6 +104,7 @@ export function readSession(file) {
104
104
  };
105
105
  return Object.assign(session, { skills, commands, mcp });
106
106
  }
107
+ const sessionMemo = new Map();
107
108
  /** Your sessions from the last `days` days (by file time), automated runs left out. */
108
109
  export function scan(opts = {}) {
109
110
  const now = (opts.now ?? new Date()).getTime();
@@ -125,14 +126,22 @@ export function scan(opts = {}) {
125
126
  }
126
127
  for (const n of names) {
127
128
  const file = join(dir, n);
129
+ let st;
128
130
  try {
129
- if (statSync(file).mtimeMs < since)
131
+ st = statSync(file);
132
+ if (st.mtimeMs < since)
130
133
  continue;
131
134
  }
132
135
  catch {
133
136
  continue;
134
137
  }
135
- const s = readSession(file);
138
+ // Parsed once per file version: savings, detect and the saved total each scan, in one process.
139
+ const key = `${st.size}:${st.mtimeMs}`;
140
+ let s = sessionMemo.get(file)?.key === key ? sessionMemo.get(file).s : undefined;
141
+ if (s === undefined) {
142
+ s = readSession(file);
143
+ sessionMemo.set(file, { key, s });
144
+ }
136
145
  if (!s || !s.turns.length)
137
146
  continue;
138
147
  out.sessions.push({ id: s.id, cwd: s.cwd, turns: s.turns });
@@ -526,6 +535,17 @@ export function detect(opts = {}) {
526
535
  findings,
527
536
  };
528
537
  }
538
+ /** `detect` plus codeburn's waste checks (wastechecks.ts), one list. Slower (a few seconds): the CLI and advise use it. */
539
+ export async function detectFull(opts = {}) {
540
+ const r = detect(opts);
541
+ if (opts.codeburn === false)
542
+ return r;
543
+ const { otherAgentChecks, wasteChecks } = await import('./wastechecks.js');
544
+ const window = { days: opts.days ?? 30, ...(opts.now ? { now: opts.now } : {}) };
545
+ const theirs = await wasteChecks(window);
546
+ const others = opts.agents === false ? [] : await otherAgentChecks(window);
547
+ return { ...r, findings: [...r.findings, ...theirs, ...others] };
548
+ }
529
549
  const short = (text) => text.split(/(?<=\.)\s/)[0];
530
550
  /**
531
551
  * One screen: what it read, the findings ranked by tokens, and the one fix to start with. `all` adds each
@@ -541,16 +561,28 @@ export function detectText(r, opts = {}) {
541
561
  }
542
562
  const read = `Read ${sessions} sessions (last ${days} days), ${skills} skills, ${mcpServers} MCP servers. Nothing left this computer.`;
543
563
  if (!r.findings.length)
544
- return ['Nothing to fix in what this version checks (startup tax and cache).', '', read];
545
- const ranked = [...r.findings].sort((a, b) => (b.tokens ?? -1) - (a.tokens ?? -1));
564
+ return ['Nothing to fix in what this version checks.', '', read];
565
+ const byTokens = (a, b) => (b.tokens ?? -1) - (a.tokens ?? -1);
566
+ const ranked = r.findings.filter((f) => !f.worthKnowing).sort(byTokens);
567
+ const known = r.findings.filter((f) => f.worthKnowing).sort(byTokens);
568
+ if (!ranked.length)
569
+ ranked.push(...known.splice(0));
546
570
  const cost = (f) => (f.tokens === undefined ? '' : `${f.basis === 'estimated' ? '~' : ''}${fmt(f.tokens)}`);
547
571
  const cw = Math.max(...ranked.map((f) => cost(f).length));
548
572
  const w = Math.max(...ranked.map((f) => f.title.length));
549
- const lines = [`Start here: ${short(ranked[0].fix)}`, ''];
573
+ // Start with a concrete step: ours, or a codeburn fix it can write itself. Its habit nudges still rank below.
574
+ const start = ranked.find((f) => f.source !== 'codeburn' || f.lane === 'settings') ?? ranked[0];
575
+ const lines = [`Start here: ${short(start.fix)}`, ''];
550
576
  for (const f of ranked.slice(0, opts.all ? undefined : 5))
551
577
  lines.push(` ${cost(f).padStart(cw)} ${f.title.padEnd(w)} ${f.basis}`);
552
578
  if (!opts.all && ranked.length > 5)
553
579
  lines.push(` …and ${ranked.length - 5} more: chompyy detect --all`);
580
+ if (known.length) {
581
+ const kw = Math.max(...known.map((f) => cost(f).length));
582
+ lines.push('', 'Worth knowing (may be needed, not a fix):');
583
+ for (const f of known.slice(0, opts.all ? undefined : 3))
584
+ lines.push(` ${cost(f).padStart(kw)} ${f.title}`);
585
+ }
554
586
  lines.push('', read);
555
587
  if (sessions < 20)
556
588
  lines.push(`Only ${sessions} sessions: some checks need 20 over 14 days.`);
@@ -558,7 +590,7 @@ export function detectText(r, opts = {}) {
558
590
  lines.push('Evidence and every fix: chompyy detect --all');
559
591
  return lines;
560
592
  }
561
- for (const f of ranked) {
593
+ for (const f of [...ranked, ...known]) {
562
594
  lines.push('', `${cost(f) ? `${cost(f)} · ` : ''}${f.title} (${f.basis}${f.tokensHow ? `: ${f.tokensHow}` : ''})`, ` ${f.say}`);
563
595
  if (f.notProve)
564
596
  lines.push(` Not proven: ${f.notProve}`);
package/dist/didwork.js CHANGED
@@ -252,6 +252,30 @@ export function checkRuleAgain(a, now, s, root) {
252
252
  const still = ruleS4(s, configuredMcp(s.sessions.map((x) => x.cwd).filter(Boolean)));
253
253
  return { at, verdict: still.length ? 'no-change' : 'worked', method: 'recount', line: still.length ? `Re-checked: ${still[0].say}` : 'Re-checked: no configured MCP server goes unused any more: it worked.' };
254
254
  }
255
+ /** Cards for codeburn's checks and our newer rules (advice.ts newCheckAdvice): keyed `cb:<id>` or `<rule>:<what>`. */
256
+ export const isNewCheck = (a) => a.key.startsWith('cb:') || /^L1:/.test(a.key);
257
+ /** Days of data since the card started that a new-check card is measured over (at least a week). */
258
+ export const newCheckDays = (since, now) => Math.floor((now - since) / DAY);
259
+ /**
260
+ * A new-check card: the same check run again over only the days since you started, per week, against the per-week
261
+ * number registered on the card. Worked at ≥ 70% of the promise (down to a third). It can't isolate the fix from
262
+ * the rest of those days, so it's a before → after reading.
263
+ */
264
+ export function checkNewCheck(a, since, now, findings) {
265
+ const at = new Date(now).toISOString();
266
+ const days = newCheckDays(since, now);
267
+ const before = a.baseline?.tokens ?? 0;
268
+ if (days < 7 || !findings) {
269
+ return { at, verdict: 'too-early', method: 'before-after', line: `Checked again a week after you started (${new Date(since + 7 * DAY).toLocaleDateString('en-US', { month: 'short', day: 'numeric' })}).`, dueAt: new Date(since + 7 * DAY).toISOString() };
270
+ }
271
+ const found = findings.find((f) => (f.key ?? (f.source === 'codeburn' ? `cb:${f.codeburnId}` : f.rule)) === a.key);
272
+ const after = found?.tokens ? Math.round((found.tokens / days) * 7) : 0;
273
+ const saved = before - after;
274
+ const promise = before - Math.floor(before / 3);
275
+ const verdict = saved >= 0.7 * promise ? 'worked' : Math.abs(saved) < 0.05 * before ? 'no-change' : saved > 0 ? 'short' : 'worse';
276
+ const say = { worked: 'it worked', short: 'better, not there yet', 'no-change': 'no change yet', worse: 'it got worse', 'too-early': '', 'cant-tell': '' };
277
+ return { at, verdict, method: 'before-after', before, after, saved, per: 'week', line: `Re-checked over ${days} days: ~${k(after)} tokens a week (was ~${k(before)}): ${say[verdict]}.` };
278
+ }
255
279
  // ---------- all cards ----------
256
280
  /** The cards with something to measure: applied, being tried, or done (by you, or kept from an away run). */
257
281
  export function measurable(c) {
@@ -293,6 +317,8 @@ export function checkWorked(board, now, opts = {}) {
293
317
  a.result = checkSkillsGone(a, t, opts.claudeDir, c.blueprint);
294
318
  else if (a.rule === 'S2')
295
319
  a.result = checkClaudeMd(a, t);
320
+ else if (isNewCheck(a))
321
+ a.result = checkNewCheck(a, since, t, opts.recheck?.get(newCheckDays(since, t)));
296
322
  else if (a.rule === 'S4' || a.rule === 'S5')
297
323
  a.result = checkRuleAgain(a, t, s ?? scan({ now, root }), root);
298
324
  }
package/dist/label.js ADDED
@@ -0,0 +1,33 @@
1
+ const WEEK = 7 * 86_400_000;
2
+ export function nutritionLabel(rows, resentTokens, now) {
3
+ const t = now.getTime();
4
+ const from = new Date(t - WEEK).toISOString();
5
+ const to = now.toISOString();
6
+ let input = 0, output = 0, cacheRead = 0, cacheWrite = 0, costUsd = 0;
7
+ const sessions = new Set();
8
+ for (const r of rows) {
9
+ if (r.at < from || r.at > to)
10
+ continue;
11
+ input += r.input;
12
+ output += r.output;
13
+ cacheRead += r.cacheRead;
14
+ cacheWrite += r.cacheWrite5m + r.cacheWrite1h;
15
+ costUsd += r.costUsd;
16
+ if (!r.session.startsWith('chompyy-card-'))
17
+ sessions.add(r.session);
18
+ }
19
+ const tokens = input + output + cacheRead + cacheWrite;
20
+ const pct = (n) => (tokens ? Math.round((n / tokens) * 1000) / 10 : 0);
21
+ const sugar = Math.min(resentTokens, cacheWrite);
22
+ const lines = [
23
+ { name: 'Cached reads', kind: 'fibre', tokens: cacheRead, pct: pct(cacheRead) },
24
+ { name: 'Cache writes', kind: 'carbs', tokens: cacheWrite, pct: pct(cacheWrite) },
25
+ { name: 'Resent after a break', kind: 'added sugar', tokens: sugar, pct: pct(sugar), sub: true },
26
+ { name: 'Fresh input', kind: 'protein', tokens: input, pct: pct(input) },
27
+ { name: 'Output', kind: 'protein', tokens: output, pct: pct(output) },
28
+ ];
29
+ const tip = sugar > 0
30
+ ? 'Cut the sugar: /compact before a long break, so the next message doesn\'t resend it all.'
31
+ : 'No added sugar this week. Nicely baked.';
32
+ return { from, to, tokens, costUsd: Math.round(costUsd * 100) / 100, servings: sessions.size, lines, tip };
33
+ }
package/dist/menu.js ADDED
@@ -0,0 +1,17 @@
1
+ const DAYS = 30;
2
+ export function menuFrom(claude, agents, now) {
3
+ const items = [
4
+ { name: 'Claude Code', tokens: claude.tokens, costUsd: claude.costUsd, model: claude.model },
5
+ ...agents.map((a) => ({ name: a.displayName, tokens: a.month.tokens, costUsd: a.month.costUsd, model: a.models[0] ?? null })),
6
+ ]
7
+ .filter((i) => i.tokens > 0)
8
+ .sort((a, b) => b.tokens - a.tokens);
9
+ const total = items.reduce((t, i) => ({ tokens: t.tokens + i.tokens, costUsd: t.costUsd + i.costUsd }), { tokens: 0, costUsd: 0 });
10
+ return {
11
+ from: new Date(now.getTime() - DAYS * 86_400_000).toISOString(),
12
+ to: now.toISOString(),
13
+ items,
14
+ total,
15
+ special: items[0]?.model ?? null,
16
+ };
17
+ }
@@ -0,0 +1,72 @@
1
+ /**
2
+ * The bedtime nightcap: in the evening, Chompyy puts on a nightcap and offers, inline in the panel, to run your
3
+ * approved cards while you sleep ("Leave it to me tonight?"). Once bedtime is set it says what runs tonight, with
4
+ * Skip tonight. The bedtime trigger (triggers.ts) does the running; this only decides what the panel says.
5
+ */
6
+ import { bedtimeKey, parseClock } from './triggers.js';
7
+ /** The nightcap goes on this long before bedtime. */
8
+ const EVENING_MIN = 3 * 60;
9
+ /** With no bedtime set, offer from 20:00 to 00:59. */
10
+ const OFFER_FROM = 20 * 60;
11
+ const OFFER_UNTIL = 60;
12
+ const DEFAULT_BEDTIME = '23:30';
13
+ const pad = (n) => String(n).padStart(2, '0');
14
+ const dayKey = (d) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
15
+ /** Minutes until the next `bedtime`, and the trigger key for it. Inside the bedtime window: 0 and tonight's key. */
16
+ export function nextBedtime(now, bedtime, windowMin) {
17
+ const current = bedtimeKey(now, bedtime, windowMin);
18
+ if (current)
19
+ return { inMin: 0, key: current };
20
+ const start = parseClock(bedtime);
21
+ const minutes = now.getHours() * 60 + now.getMinutes();
22
+ const day = new Date(now);
23
+ let inMin = start - minutes;
24
+ if (inMin < 0) {
25
+ inMin += 24 * 60;
26
+ day.setDate(day.getDate() + 1);
27
+ }
28
+ return { inMin, key: `bedtime:${dayKey(day)}` };
29
+ }
30
+ /** A quiet hour (Usage → Week × hour) counts as a bedtime only at night: 21:00 to 04:00. */
31
+ export const nightHour = (h) => h >= 21 || h <= 4;
32
+ /**
33
+ * A bedtime to offer: the start of your quiet stretch when it's at night and at least 30 minutes away, else 23:30,
34
+ * or the next half hour at least 30 minutes away when it's already late.
35
+ */
36
+ export function offeredBedtime(now, quietFrom = null) {
37
+ const minutes = now.getHours() * 60 + now.getMinutes();
38
+ if (quietFrom !== null && nightHour(quietFrom)) {
39
+ const ahead = (quietFrom * 60 - minutes + 24 * 60) % (24 * 60);
40
+ if (ahead >= 30 && ahead <= 8 * 60)
41
+ return `${pad(quietFrom)}:00`;
42
+ }
43
+ const late = minutes >= 23 * 60 || minutes < OFFER_UNTIL;
44
+ if (!late)
45
+ return DEFAULT_BEDTIME;
46
+ const t = (Math.ceil((minutes + 30) / 30) * 30) % (24 * 60);
47
+ return `${pad(Math.floor(t / 60))}:${pad(t % 60)}`;
48
+ }
49
+ export function nightcap(i) {
50
+ if (i.bedtime && i.triggersOn) {
51
+ const next = nextBedtime(i.now, i.bedtime, i.bedtimeWindowMin);
52
+ if (next.inMin === 0 && i.awayBusy)
53
+ return { phase: 'running', bedtime: i.bedtime, cards: i.approved, key: next.key };
54
+ if (next.inMin === 0 && i.fired.includes(next.key))
55
+ return null; // tonight's run is done (or skipped)
56
+ if (next.inMin > EVENING_MIN || i.approved < 1)
57
+ return null;
58
+ return { phase: i.fired.includes(next.key) ? 'skipped' : 'armed', bedtime: i.bedtime, cards: i.approved, key: next.key };
59
+ }
60
+ const minutes = i.now.getHours() * 60 + i.now.getMinutes();
61
+ if (i.approved < 1 || (minutes < OFFER_FROM && minutes >= OFFER_UNTIL))
62
+ return null;
63
+ const evening = new Date(i.now);
64
+ if (minutes < OFFER_UNTIL)
65
+ evening.setDate(evening.getDate() - 1);
66
+ const key = `nightcap-offer:${dayKey(evening)}`;
67
+ if (i.fired.includes(key))
68
+ return null; // "Not tonight"
69
+ const quiet = i.quietFrom?.() ?? null;
70
+ const bedtime = offeredBedtime(i.now, quiet);
71
+ return { phase: 'offer', bedtime, cards: i.approved, key, ...(quiet !== null && bedtime === `${pad(quiet)}:00` ? { quiet: true } : {}) };
72
+ }
package/dist/nudge.js CHANGED
@@ -10,6 +10,7 @@ import { formatDuration } from './duration.js';
10
10
  import { appendJsonl, homePath } from './home.js';
11
11
  import { coldReturns, isAutomated, scan } from './detect.js';
12
12
  import { projectsDir } from './dream.js';
13
+ import { windowFor } from './context.js';
13
14
  /** The main conversation's cache lives an hour (5 minutes on API keys): past an hour it's cold either way. */
14
15
  export const COLD_AFTER_MS = 60 * 60_000;
15
16
  /** Below this the rebuild is cheap; not worth stopping you. */
@@ -117,20 +118,32 @@ function slice(file, bytes, fromEnd) {
117
118
  * The conversation's last reply, its first (about what a fresh conversation costs: tools, CLAUDE.md, memory), and
118
119
  * a compaction after the last reply, if there was one.
119
120
  */
120
- export function replies(transcript) {
121
+ /** `withPeak` also reads every reply in the tail for the biggest context (warm caches); the hook skips it to stay fast. */
122
+ export function replies(transcript, withPeak = false) {
121
123
  const tail = slice(transcript, 4 << 20, true).split('\n');
122
124
  let last = null;
123
125
  let compacted = null;
124
- for (let i = tail.length - 1; i >= 0 && !last; i--) {
125
- last = replyOf(tail[i]);
126
- if (!last)
126
+ let peak = 0;
127
+ let model = '';
128
+ for (let i = tail.length - 1; i >= 0; i--) {
129
+ if (last && !withPeak)
130
+ break;
131
+ const r = replyOf(tail[i]);
132
+ if (r)
133
+ peak = Math.max(peak, r.context);
134
+ if (last)
135
+ continue;
136
+ last = r;
137
+ if (last)
138
+ model = tail[i].match(/"model":"([^"]+)"/)?.[1] ?? '';
139
+ else
127
140
  compacted ??= compactionOf(tail[i]);
128
141
  }
129
142
  let first = null;
130
143
  for (const line of slice(transcript, 2 << 20, false).split('\n'))
131
144
  if ((first = replyOf(line)))
132
145
  break;
133
- return { last, first, compacted };
146
+ return { last, first, compacted, peak, model };
134
147
  }
135
148
  export function loadNudges() {
136
149
  const path = homePath('nudges.jsonl');
@@ -228,12 +241,37 @@ export function runHook(stdin, now = Date.now()) {
228
241
  */
229
242
  export function goingCold(now = Date.now(), dir = projectsDir(), events = loadNudges()) {
230
243
  const out = [];
244
+ for (const { transcript, session, last, first } of bigConversations(now, dir, WARN_AFTER_MS - 60_000)) {
245
+ const idleMs = now - last.at;
246
+ if (idleMs < WARN_AFTER_MS || idleMs >= COLD_AFTER_MS)
247
+ continue;
248
+ if (events.some((e) => e.kind === 'warned' && e.session === session && Date.parse(e.at) > last.at))
249
+ continue;
250
+ const cwd = cwdOf(transcript);
251
+ const fresh = first && first.context < last.context / 2 ? first.context : undefined;
252
+ out.push({ session, transcript, project: cwd ? basename(cwd) : basename(dirname(transcript)), context: last.context, ...(fresh ? { fresh } : {}), idleMs, coldAt: new Date(last.at + COLD_AFTER_MS).toISOString() });
253
+ }
254
+ return out;
255
+ }
256
+ /** Every warm cache right now, the one expiring soonest first. */
257
+ export function warmCaches(now = Date.now(), dir = projectsDir()) {
258
+ const out = [];
259
+ for (const { transcript, session, last, peak, model } of bigConversations(now, dir, 0, true)) {
260
+ if (now - last.at >= COLD_AFTER_MS)
261
+ continue;
262
+ const cwd = cwdOf(transcript);
263
+ out.push({ session, project: cwd ? basename(cwd) : basename(dirname(transcript)), context: last.context, window: windowFor(model, peak), model, warmTill: new Date(last.at + COLD_AFTER_MS).toISOString() });
264
+ }
265
+ return out.sort((a, b) => a.warmTill.localeCompare(b.warmTill));
266
+ }
267
+ /** Transcripts written in the last hour (and at least `minIdleMs` ago) whose last reply is big and not compacted. */
268
+ function* bigConversations(now, dir, minIdleMs, withPeak = false) {
231
269
  let folders = [];
232
270
  try {
233
271
  folders = readdirSync(dir).filter((f) => !isAutomated(f));
234
272
  }
235
273
  catch {
236
- return out;
274
+ return;
237
275
  }
238
276
  for (const folder of folders) {
239
277
  let files = [];
@@ -247,27 +285,18 @@ export function goingCold(now = Date.now(), dir = projectsDir(), events = loadNu
247
285
  const transcript = join(dir, folder, f);
248
286
  try {
249
287
  const mtime = statSync(transcript).mtimeMs;
250
- if (now - mtime > COLD_AFTER_MS || now - mtime < WARN_AFTER_MS - 60_000)
288
+ if (now - mtime > COLD_AFTER_MS || now - mtime < minIdleMs)
251
289
  continue;
252
- const { last, first, compacted } = replies(transcript);
290
+ const { last, first, compacted, peak, model } = replies(transcript, withPeak);
253
291
  if (!last || compacted || last.context < MIN_CONTEXT)
254
292
  continue;
255
- const idleMs = now - last.at;
256
- if (idleMs < WARN_AFTER_MS || idleMs >= COLD_AFTER_MS)
257
- continue;
258
- const session = f.replace(/\.jsonl$/, '');
259
- if (events.some((e) => e.kind === 'warned' && e.session === session && Date.parse(e.at) > last.at))
260
- continue;
261
- const cwd = cwdOf(transcript);
262
- const fresh = first && first.context < last.context / 2 ? first.context : undefined;
263
- out.push({ session, transcript, project: cwd ? basename(cwd) : folder, context: last.context, ...(fresh ? { fresh } : {}), idleMs, coldAt: new Date(last.at + COLD_AFTER_MS).toISOString() });
293
+ yield { transcript, session: f.replace(/\.jsonl$/, ''), last, first, peak, model };
264
294
  }
265
295
  catch {
266
296
  /* one bad file never hides the others */
267
297
  }
268
298
  }
269
299
  }
270
- return out;
271
300
  }
272
301
  function cwdOf(transcript) {
273
302
  const m = slice(transcript, 64 << 10, true).match(/"cwd":"((?:[^"\\]|\\.)*)"/g);
@@ -295,6 +324,27 @@ export function coldWarningText(d) {
295
324
  body: `After ${at} its cache expires and coming back rewrites all ${k(d.context)}. Done with it? Do nothing.`,
296
325
  };
297
326
  }
327
+ /**
328
+ * A transcript's compactions and replies, in file order, parsed once per file version (path, size, mtime). Many stops
329
+ * point at the same big transcript; reading and parsing it again for each made the Savings window take seconds.
330
+ */
331
+ const marksMemo = new Map();
332
+ export function transcriptMarks(path) {
333
+ const st = statSync(path);
334
+ const key = `${st.size}:${st.mtimeMs}`;
335
+ const had = marksMemo.get(path);
336
+ if (had?.key === key)
337
+ return had.marks;
338
+ const marks = [];
339
+ for (const line of readFileSync(path, 'utf8').split('\n')) {
340
+ const c = compactionOf(line);
341
+ const r = replyOf(line);
342
+ if (c || r)
343
+ marks.push({ c, r });
344
+ }
345
+ marksMemo.set(path, { key, marks });
346
+ return marks;
347
+ }
298
348
  /**
299
349
  * Read each stopped conversation after the stop: sent anyway, carried on small (compacted), or left. A stop that
300
350
  * came after a compaction (Claude Code's own, while you were away) had nothing at stake: it isn't counted.
@@ -308,11 +358,9 @@ export function outcomes(events = loadNudges()) {
308
358
  let after = null;
309
359
  let compacted = null;
310
360
  try {
311
- for (const line of readFileSync(event.transcript, 'utf8').split('\n')) {
312
- const c = compactionOf(line);
361
+ for (const { c, r } of transcriptMarks(event.transcript)) {
313
362
  if (c && !compacted && c.at > at - event.idleMs && c.at < until)
314
363
  compacted = c;
315
- const r = replyOf(line);
316
364
  if (r && r.at > at && r.at < until) {
317
365
  after = r;
318
366
  break;
@@ -340,11 +388,9 @@ export function warnOutcomes(events = loadNudges()) {
340
388
  let next = null;
341
389
  let compacted = null;
342
390
  try {
343
- for (const line of readFileSync(event.transcript, 'utf8').split('\n')) {
344
- const c = compactionOf(line);
391
+ for (const { c, r } of transcriptMarks(event.transcript)) {
345
392
  if (c && !compacted && c.at > at && c.at < coldAt)
346
393
  compacted = c;
347
- const r = replyOf(line);
348
394
  if (r && r.at > at) {
349
395
  next = r;
350
396
  break;
package/dist/pacing.js CHANGED
@@ -149,6 +149,20 @@ export function windowShareOfWeek(samples) {
149
149
  return five >= 50 ? (100 * week) / five : null;
150
150
  }
151
151
  const dayClock = (ms) => `${new Date(ms).toLocaleDateString('en-US', { weekday: 'short' })} ${clock(ms)}`;
152
+ /** This week's readings as (share of the week passed, % used), thinned to `max` points, ending at now. */
153
+ export function weekCurve(samples, resetsAt, now, usedNow, max = 48) {
154
+ const start = resetsAt * 1000 - WEEK;
155
+ const t = (at) => Math.max(0, Math.min(1, (at - start) / WEEK));
156
+ const pts = samples
157
+ .filter((x) => x.week?.resetsAt === resetsAt && x.at >= start && x.at <= now.getTime() && typeof x.week.usedPct === 'number')
158
+ .map((x) => ({ t: t(x.at), used: x.week.usedPct }));
159
+ const buckets = new Map();
160
+ for (const p of pts)
161
+ buckets.set(Math.floor(p.t * max), p); // last reading in each slice
162
+ const out = [{ t: 0, used: 0 }, ...buckets.values()].sort((a, b) => a.t - b.t);
163
+ out.push({ t: t(now.getTime()), used: usedNow });
164
+ return out.map((p) => ({ t: Math.round(p.t * 1000) / 1000, used: p.used }));
165
+ }
152
166
  export function weekForecast(snap, samples, now) {
153
167
  const v = windowView(snap?.sevenDay, now);
154
168
  if (!v.known)
@@ -186,7 +200,8 @@ export function weekForecast(snap, samples, now) {
186
200
  line += '. Less than one 5-hour window left before then.';
187
201
  }
188
202
  const short = line.slice(head.length + 1);
189
- return { usedPct: v.usedPct, resetsAt: v.resetsAt, unusedPct, ...(runsOutAt ? { runsOutAt } : {}), windowPct, spareWindows, maxReachablePct, line, short };
203
+ const curve = weekCurve(samples, v.resetsAt, now, v.usedPct);
204
+ return { usedPct: v.usedPct, resetsAt: v.resetsAt, unusedPct, projectedPct: Math.min(100, projected), curve, ...(runsOutAt ? { runsOutAt } : {}), windowPct, spareWindows, maxReachablePct, line, short };
190
205
  }
191
206
  // ---------- rolling daily allowance ----------
192
207
  /** The day you're in: from your last bedtime (or midnight) to the next. */
@@ -0,0 +1,39 @@
1
+ const tokens = (r) => r.input + r.output + r.cacheRead + r.cacheWrite5m + r.cacheWrite1h;
2
+ export function punchcard(rows, now, weeks = 4) {
3
+ const from = now.getTime() - weeks * 7 * 86_400_000;
4
+ const grid = Array.from({ length: 7 }, () => Array(24).fill(0));
5
+ for (const r of rows) {
6
+ const t = Date.parse(r.at);
7
+ if (!(t >= from && t <= now.getTime()))
8
+ continue;
9
+ const d = new Date(t);
10
+ grid[(d.getDay() + 6) % 7][d.getHours()] += tokens(r);
11
+ }
12
+ return { grid, quiet: quietStretch(grid), weeks };
13
+ }
14
+ /** Quiet = under 5% of your busiest hour, summed over the week. Wraps past midnight (e.g. 01:00–08:00). */
15
+ export function quietStretch(grid) {
16
+ const byHour = Array.from({ length: 24 }, (_, h) => grid.reduce((a, day) => a + day[h], 0));
17
+ const peak = Math.max(...byHour);
18
+ if (peak <= 0)
19
+ return null;
20
+ const quiet = byHour.map((x) => x <= peak * 0.05);
21
+ if (quiet.every(Boolean))
22
+ return null;
23
+ let best = { from: 0, len: 0 };
24
+ // Start right after a busy hour so a stretch is never split by midnight.
25
+ const start = quiet.findIndex((q) => !q);
26
+ for (let i = 0, run = 0, runFrom = 0; i < 24; i++) {
27
+ const h = (start + 1 + i) % 24;
28
+ if (quiet[h]) {
29
+ if (!run)
30
+ runFrom = h;
31
+ run += 1;
32
+ if (run > best.len)
33
+ best = { from: runFrom, len: run };
34
+ }
35
+ else
36
+ run = 0;
37
+ }
38
+ return best.len >= 4 ? { from: best.from, to: (best.from + best.len) % 24, hours: best.len } : null;
39
+ }