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,71 @@
1
+ /** QUESTIONS.md, read into questions with options the app can show as a pick list. */
2
+ const ITEM = /^(\d+[.)]|[-*])\s+/;
3
+ const RECOMMENDED = /\(?\brecommended\b\)?:?/i;
4
+ function option(lines) {
5
+ const raw = lines.map((l) => l.trim()).join('\n').replace(ITEM, '');
6
+ const recommended = RECOMMENDED.test(raw.split('\n')[0] ?? '');
7
+ const text = raw.replace(/\*\*\s*\(?recommended\)?:?\s*\*\*\s*/i, '').replace(RECOMMENDED, '').trim();
8
+ const flat = text.replace(/\s*\n\s*/g, ' ').replace(/\*\*|__/g, '').replace(/^[\s:–—-]+/, '');
9
+ // The label is the first sentence; "e.g." and "i.e." don't end one.
10
+ const end = /(?<!\b(?:e\.g|i\.e|etc|vs))[.?!]`?(?=\s)/.exec(flat);
11
+ const cut = end ? end.index + end[0].length : flat.length;
12
+ return { label: flat.slice(0, cut).trim(), detail: flat.slice(cut).trim(), recommended };
13
+ }
14
+ /** Join hard-wrapped lines into one line per paragraph; list items keep their own line. */
15
+ function unwrap(lines) {
16
+ const out = [];
17
+ for (const line of lines) {
18
+ const t = line.trim();
19
+ const prev = out[out.length - 1];
20
+ if (t && prev && !ITEM.test(t) && !ITEM.test(prev))
21
+ out[out.length - 1] = `${prev} ${t}`;
22
+ else
23
+ out.push(t);
24
+ }
25
+ return out.join('\n').replace(/\n{3,}/g, '\n\n').trim();
26
+ }
27
+ function question(title, body) {
28
+ const at = body.findIndex((l) => /^\s*\**options\**:?\**\s*$/i.test(l));
29
+ const before = at === -1 ? body : body.slice(0, at);
30
+ const options = [];
31
+ if (at !== -1) {
32
+ let cur = null;
33
+ for (const line of body.slice(at + 1)) {
34
+ if (ITEM.test(line)) {
35
+ if (cur)
36
+ options.push(option(cur));
37
+ cur = [line];
38
+ }
39
+ else if (cur && /^\s+\S/.test(line))
40
+ cur.push(line); // continuation of the item
41
+ else if (cur && line.trim()) {
42
+ options.push(option(cur));
43
+ cur = null;
44
+ }
45
+ }
46
+ if (cur)
47
+ options.push(option(cur));
48
+ }
49
+ return { title, context: unwrap(before), options: options.length >= 2 ? options : [] };
50
+ }
51
+ /** Each "## " heading is one question. A file without headings is one question titled by its first line. */
52
+ export function parseQuestions(markdown) {
53
+ const lines = markdown.split('\n').filter((l) => !/^#\s/.test(l)); // drop the "# Questions for task" title
54
+ const out = [];
55
+ let title = null;
56
+ let body = [];
57
+ for (const line of lines) {
58
+ const h = /^#{2,3}\s+(.*)$/.exec(line);
59
+ if (h) {
60
+ if (title !== null || body.some((l) => l.trim()))
61
+ out.push(question(title ?? '', body));
62
+ title = (h[1] ?? '').replace(/\*\*|__/g, '').trim();
63
+ body = [];
64
+ }
65
+ else
66
+ body.push(line);
67
+ }
68
+ if (title !== null || body.some((l) => l.trim()))
69
+ out.push(question(title ?? '', body));
70
+ return out.filter((q) => q.title || q.context || q.options.length);
71
+ }
package/dist/recap.js ADDED
@@ -0,0 +1,74 @@
1
+ /** One cookie per 100k tokens, like the jar in the panel. */
2
+ export const TOKENS_PER_COOKIE = 100_000;
3
+ const pad = (n) => String(n).padStart(2, '0');
4
+ const localDay = (iso) => {
5
+ const d = new Date(iso);
6
+ return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
7
+ };
8
+ const rowTokens = (r) => r.input + r.output + r.cacheRead + r.cacheWrite5m + r.cacheWrite1h;
9
+ /** Which month to recap: "2026-11", or by default this month once it's 7 days old, else last month. */
10
+ export function recapMonth(now, month) {
11
+ let y;
12
+ let m; // 0-based
13
+ if (month) {
14
+ const match = /^(\d{4})-(\d{2})$/.exec(month);
15
+ if (!match || Number(match[2]) < 1 || Number(match[2]) > 12)
16
+ throw new Error(`Month must look like 2026-11, not "${month}".`);
17
+ y = Number(match[1]);
18
+ m = Number(match[2]) - 1;
19
+ }
20
+ else if (now.getDate() >= 7) {
21
+ y = now.getFullYear();
22
+ m = now.getMonth();
23
+ }
24
+ else {
25
+ const prev = new Date(now.getFullYear(), now.getMonth() - 1, 1);
26
+ y = prev.getFullYear();
27
+ m = prev.getMonth();
28
+ }
29
+ const start = new Date(y, m, 1);
30
+ const monthEnd = new Date(y, m + 1, 1);
31
+ return { start, end: monthEnd < now ? monthEnd : now };
32
+ }
33
+ export function recap(rows, runs, cards, range) {
34
+ const from = range.start.toISOString();
35
+ const to = range.end.toISOString();
36
+ const inRange = (at) => !!at && at >= from && at < to;
37
+ const days = new Map();
38
+ const sessions = new Set();
39
+ const models = new Map();
40
+ let tokens = 0;
41
+ let costUsd = 0;
42
+ for (const r of rows) {
43
+ if (!inRange(r.at))
44
+ continue;
45
+ const n = rowTokens(r);
46
+ tokens += n;
47
+ costUsd += r.costUsd;
48
+ days.set(localDay(r.at), (days.get(localDay(r.at)) ?? 0) + n);
49
+ if (!r.session.startsWith('chompyy-card-'))
50
+ sessions.add(r.session);
51
+ models.set(r.model, (models.get(r.model) ?? 0) + n);
52
+ }
53
+ const busiest = [...days].sort((a, b) => b[1] - a[1])[0];
54
+ const monthRuns = runs.filter((r) => inRange(r.at));
55
+ const biggest = monthRuns
56
+ .filter((r) => r.tokens)
57
+ .map((r) => ({ tokens: r.tokens.input + r.tokens.output + r.tokens.cacheRead + r.tokens.cacheWrite, minutes: Math.max(1, Math.round(r.durationMs / 60_000)) }))
58
+ .sort((a, b) => b.tokens - a.tokens)[0];
59
+ return {
60
+ label: range.start.toLocaleDateString('en-US', { month: 'long', year: 'numeric' }),
61
+ from,
62
+ to,
63
+ tokens,
64
+ costUsd: Math.round(costUsd * 100) / 100,
65
+ cookies: Math.round(tokens / TOKENS_PER_COOKIE),
66
+ activeDays: [...days.values()].filter((n) => n > 0).length,
67
+ busiestDay: busiest ? { day: busiest[0], tokens: busiest[1] } : null,
68
+ conversations: sessions.size,
69
+ cardsBaked: monthRuns.filter((r) => r.status === 'ok').length,
70
+ kept: cards.filter((c) => !c.advice && c.outcome === 'kept' && inRange(c.updatedAt)).length,
71
+ biggestBake: biggest ?? null,
72
+ topModel: [...models].sort((a, b) => b[1] - a[1])[0]?.[0] ?? null,
73
+ };
74
+ }
@@ -0,0 +1,48 @@
1
+ import { compactTokens } from './usage.js';
2
+ const WEEK = 7 * 24 * 3600_000;
3
+ const usd = (n) => `$${n.toFixed(2)}`;
4
+ const x = (n) => `×${n}`;
5
+ export function receipt(runs, cards, resent, now) {
6
+ const t = now.getTime();
7
+ const inWeek = (at) => !!at && Date.parse(at) > t - WEEK && Date.parse(at) <= t;
8
+ const week = runs.filter((r) => inWeek(r.at));
9
+ const baked = week.filter((r) => r.status === 'ok');
10
+ const value = week.reduce((a, r) => a + (r.tokens?.costUsd ?? 0), 0);
11
+ const tokens = week.reduce((a, r) => a + (r.tokens ? r.tokens.input + r.tokens.output + r.tokens.cacheRead + r.tokens.cacheWrite : 0), 0);
12
+ const settled = cards.filter((c) => !c.advice && inWeek(c.updatedAt));
13
+ const kept = settled.filter((c) => c.outcome === 'kept').length;
14
+ const undone = settled.filter((c) => c.outcome === 'undone').length;
15
+ const lines = [
16
+ { label: 'Cards baked', qty: x(baked.length), amount: usd(baked.reduce((a, r) => a + (r.tokens?.costUsd ?? 0), 0)) },
17
+ { label: 'Kept', qty: x(kept), amount: '' },
18
+ { label: 'Burnt (undone)', qty: x(undone), amount: '' },
19
+ { label: 'Oven time', qty: '', amount: compactTokens(tokens) + ' tokens' },
20
+ ];
21
+ const less = resent ? resent.lastWeek - resent.thisWeek : 0;
22
+ if (resent && less > 0)
23
+ lines.push({ label: 'Resent less than last wk', qty: '', amount: compactTokens(less) + ' tokens' });
24
+ else if (resent && less < 0)
25
+ lines.push({ label: 'Resent more than last wk', qty: '', amount: compactTokens(-less) + ' tokens' });
26
+ const footer = baked.length === 0
27
+ ? 'Quiet week in the bakery. Approve a card and it bakes while you\'re away.'
28
+ : kept >= baked.length / 2
29
+ ? 'Fresh batch, mostly kept. Thanks for shopping at Chompyy!'
30
+ : 'Some came out burnt. Smaller cards bake better.';
31
+ return { from: new Date(t - WEEK).toISOString(), to: now.toISOString(), lines, total: usd(value), footer };
32
+ }
33
+ /** The receipt as text, for the terminal or a paste. */
34
+ export function receiptText(r) {
35
+ const width = 36;
36
+ const day = (iso) => new Date(iso).toLocaleDateString('en-US', { month: 'short', day: 'numeric' });
37
+ const row = (l, r) => `${l}${' '.repeat(Math.max(1, width - l.length - r.length))}${r}`;
38
+ return [
39
+ '🍪 CHOMPYY BAKE SALE',
40
+ `${day(r.from)} – ${day(r.to)}`,
41
+ '-'.repeat(width),
42
+ ...r.lines.map((l) => row(l.qty ? `${l.label} ${l.qty}` : l.label, l.amount)),
43
+ '-'.repeat(width),
44
+ row('Work done (API value)', r.total),
45
+ '',
46
+ r.footer,
47
+ ].join('\n');
48
+ }
package/dist/recipe.js ADDED
@@ -0,0 +1,79 @@
1
+ /**
2
+ * A kept card as a recipe: the files it changed are the ingredients, what the run did is the steps, and the run time
3
+ * is the baking time (the app draws the card; this finds the parts).
4
+ *
5
+ * Kept work lands on main as a merge: "Keep Chompyy card #N: …" (review.ts keepCard) or a pull request from
6
+ * chompyy/card-N (send.ts). Its branch is usually gone by then, so the merge is what's left to read.
7
+ */
8
+ import { execFileSync } from 'node:child_process';
9
+ import { exe } from './exe.js';
10
+ import { gitRoot } from './workspace.js';
11
+ const MAX_STEPS = 5;
12
+ const STEP_CHARS = 80;
13
+ function git(cwd, args) {
14
+ try {
15
+ return execFileSync(exe('git'), ['-C', cwd, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
16
+ }
17
+ catch {
18
+ return '';
19
+ }
20
+ }
21
+ const lines = (s) => s.split('\n').map((l) => l.trim()).filter(Boolean);
22
+ /** The merge that brought card `id` onto a branch: Keep's own merge, or the pull request from chompyy/card-<id>. */
23
+ export function keptMerge(root, id) {
24
+ const keep = `Keep Chompyy card #${id}:`;
25
+ const pr = new RegExp(`/chompyy/card-${id}$`);
26
+ for (const l of lines(git(root, ['log', '--all', '--merges', '--format=%H%x09%cI%x09%s']))) {
27
+ const [commit = '', at = '', subject = ''] = l.split('\t');
28
+ if (commit && (subject.startsWith(keep) || pr.test(subject)))
29
+ return { commit, at };
30
+ }
31
+ return null;
32
+ }
33
+ /** The bullets of a run summary, without markdown: "- **`a.md`** has a title" → "a.md has a title". */
34
+ export function summarySteps(summary) {
35
+ return lines(summary)
36
+ .filter((l) => /^([-*]|\d+\.)\s+/.test(l))
37
+ .map((l) => l.replace(/^([-*]|\d+\.)\s+/, '').replace(/\*\*|`/g, '').trim())
38
+ .filter((l) => l.length > 0)
39
+ .slice(0, MAX_STEPS);
40
+ }
41
+ /**
42
+ * A summary bullet as a recipe step: no "cli/src/a.ts:272-275:" in front, the first sentence only, about 80
43
+ * characters, capitalized. "src/a.ts:3: approving now closes it. Before, …" → "Approving now closes it."
44
+ */
45
+ export function plainStep(text) {
46
+ let s = text
47
+ .replace(/^Chompyy card #\d+:\s*/i, '')
48
+ .replace(/^[\w./-]+\.\w+(?::\d+(?:-\d+)?)?\s*[:—–-]\s+/, '')
49
+ .trim();
50
+ if (s.endsWith(':'))
51
+ return ''; // a heading over sub-bullets, not a step
52
+ s = s.split(/(?<=[.!?])\s+(?=[A-Z"(])/)[0].trim();
53
+ if (s.length > STEP_CHARS) {
54
+ const cut = s.slice(0, STEP_CHARS - 1);
55
+ s = cut.slice(0, cut.lastIndexOf(' ') > 40 ? cut.lastIndexOf(' ') : cut.length).replace(/[\s,;:—–-]+$/, '') + '…';
56
+ }
57
+ // "a.ts exports a" stays as it is: a file name keeps its case.
58
+ return /^\S*[./]\S/.test(s) ? s : s.charAt(0).toUpperCase() + s.slice(1);
59
+ }
60
+ export function recipeOf(card) {
61
+ const root = gitRoot(card.cwd);
62
+ const merge = root ? keptMerge(root, card.id) : null;
63
+ let ingredients = [];
64
+ let commits = [];
65
+ if (root && merge) {
66
+ ingredients = lines(git(root, ['diff', '--name-only', `${merge.commit}^1`, merge.commit]));
67
+ commits = lines(git(root, ['log', '--no-merges', '--reverse', '--format=%s', `${merge.commit}^1..${merge.commit}^2`]));
68
+ }
69
+ else if (root && card.run?.branch) {
70
+ // Not merged yet (or merged by hand): read the branch while it's there.
71
+ const base = card.run.base?.commit ?? 'HEAD';
72
+ ingredients = lines(git(root, ['diff', '--name-only', `${base}...${card.run.branch}`]));
73
+ commits = lines(git(root, ['log', '--no-merges', '--reverse', '--format=%s', `${base}..${card.run.branch}`]));
74
+ }
75
+ const own = card.run?.recipe ?? [];
76
+ const fromSummary = summarySteps(card.run?.summary ?? '');
77
+ const steps = own.length ? own : (fromSummary.length ? fromSummary : commits).map(plainStep).filter(Boolean);
78
+ return { ingredients, steps: steps.slice(0, MAX_STEPS), servedAt: merge?.at ?? null };
79
+ }
@@ -0,0 +1,111 @@
1
+ // The Savings window's data (`chompyy savings --json`): one bar for the week (what's fine vs what's fixable), each
2
+ // waste ranked with its status and before → after bars, and one conversation step by step to show a waste happen.
3
+ // It only gathers what other parts already measure: the nutrition label (label.ts), detect + codeburn (detect.ts),
4
+ // the saved-so-far total and each advice card's verdict (didwork.ts).
5
+ import { basename } from 'node:path';
6
+ import { coldReturns } from './detect.js';
7
+ /** The advice-card key a finding's card carries. */
8
+ export const keyOf = (f) => f.key ?? (f.source === 'codeburn' ? `cb:${f.codeburnId}` : f.rule);
9
+ const STATUS = { worked: 'worked', short: 'not yet', 'no-change': 'not yet', worse: 'not yet' };
10
+ function statusOf(card, f, declined) {
11
+ if (f.worthKnowing)
12
+ return 'worth knowing';
13
+ if (!card && declined)
14
+ return 'declined';
15
+ if (!card?.advice)
16
+ return 'to fix';
17
+ const v = card.advice.result?.verdict;
18
+ if (v && STATUS[v])
19
+ return STATUS[v];
20
+ // Approved, not in yet: a setting waiting for 10 idle minutes, or a work card waiting for the away run.
21
+ if (card.column === 'approved' || card.column === 'running')
22
+ return 'queued';
23
+ if (card.advice.state === 'applied' || card.advice.state === 'trying' || card.advice.state === 'done')
24
+ return 'applied';
25
+ return 'card waiting';
26
+ }
27
+ export function weekParts(label) {
28
+ return {
29
+ from: label.from,
30
+ to: label.to,
31
+ tokens: label.tokens,
32
+ // "Resent after a break" sits inside cache writes on the label; here it's its own slice, taken out of writes.
33
+ parts: label.lines.map((l, i) => {
34
+ const resent = /resent/i.test(l.name);
35
+ const next = label.lines[i + 1];
36
+ const minus = !l.sub && next?.sub && /resent/i.test(next.name) ? next : null;
37
+ const tokens = l.tokens - (minus?.tokens ?? 0);
38
+ return { name: l.name, tokens, pct: label.tokens ? Math.round((tokens / label.tokens) * 1000) / 10 : 0, fixable: resent };
39
+ }),
40
+ };
41
+ }
42
+ export function savingsRows(r, cards, dropped = new Set()) {
43
+ const advice = cards.filter((c) => c.advice).sort((a, b) => (b.updatedAt ?? '').localeCompare(a.updatedAt ?? ''));
44
+ const rows = r.findings.map((f) => {
45
+ const key = keyOf(f);
46
+ const card = advice.find((c) => c.advice.key === key || c.advice.key.startsWith(`${key}:`));
47
+ const res = card?.advice?.result;
48
+ // Cold returns: tokens rebuilt per week (the card's own check counts returns, which reads worse as bars).
49
+ const bars = f.rule === 'C1' && r.scanned.coldWeeks
50
+ ? r.scanned.coldWeeks.map((w, i, all) => ({ label: new Date(w.from).toLocaleDateString('en-US', { month: 'short', day: 'numeric' }), value: w.tokens, ...(i === all.length - 1 ? { highlight: true } : {}) }))
51
+ : res?.before !== undefined && res.after !== undefined
52
+ ? [{ label: 'Before', value: res.before }, { label: 'After', value: res.after, highlight: true }]
53
+ : undefined;
54
+ return {
55
+ key,
56
+ title: f.title,
57
+ say: f.say,
58
+ fix: f.fix,
59
+ ...(f.tokens !== undefined ? { tokens: f.tokens } : {}),
60
+ basis: f.basis,
61
+ source: f.source ?? 'chompyy',
62
+ status: statusOf(card, f, dropped.has(key) || [...dropped].some((d) => d.startsWith(`${key}:`))),
63
+ ...(bars ? { bars } : {}),
64
+ ...(res?.line ? { verdict: res.line } : {}),
65
+ ...(card ? { cardId: card.id } : {}),
66
+ };
67
+ });
68
+ // Fixes first by tokens; then what you declined; worth-knowing at the end.
69
+ const tier = (x) => (x.status === 'worth knowing' ? 2 : x.status === 'declined' ? 1 : 0);
70
+ return rows.sort((a, b) => tier(a) - tier(b) || (b.tokens ?? -1) - (a.tokens ?? -1));
71
+ }
72
+ /** The biggest cold return in the last 14 days, with up to 8 requests before it and 4 after. */
73
+ export function coldTrace(s, now) {
74
+ const since = now - 14 * 86_400_000;
75
+ let best = null;
76
+ for (const ses of s.sessions) {
77
+ const one = { ...s, sessions: [ses] };
78
+ for (const c of coldReturns(one, since)) {
79
+ if (!best || c.tokens > best.tokens)
80
+ best = { ses, i: ses.turns.findIndex((t) => t.at === c.at), tokens: c.tokens };
81
+ }
82
+ }
83
+ if (!best || best.i < 1)
84
+ return undefined;
85
+ const { ses, i } = best;
86
+ const turns = ses.turns.slice(Math.max(0, i - 8), i + 5);
87
+ return {
88
+ project: basename(ses.cwd || 'conversation'),
89
+ rebuilt: best.tokens,
90
+ steps: turns.map((t, k) => {
91
+ const prev = k > 0 ? turns[k - 1] : null;
92
+ return { at: new Date(t.at).toISOString(), written: t.cacheWrite, read: t.cacheRead, gapMin: prev ? Math.round((t.at - prev.at) / 60_000) : 0, cold: t === ses.turns[i] };
93
+ }),
94
+ };
95
+ }
96
+ export function savingsView(input) {
97
+ const rows = savingsRows(input.detect, input.cards, input.dropped);
98
+ const open = (r) => r.status === 'to fix' || r.status === 'card waiting';
99
+ for (const r of rows)
100
+ if (input.autoKeys?.has(r.key) || [...(input.autoKeys ?? [])].some((k) => k.startsWith(`${r.key}:`)))
101
+ r.auto = true;
102
+ const trace = input.scan ? coldTrace(input.scan, input.now.getTime()) : undefined;
103
+ return {
104
+ week: weekParts(input.label),
105
+ saved: input.saved,
106
+ fixable: { tokens: rows.filter((r) => !['worth knowing', 'worked', 'declined'].includes(r.status)).reduce((a, r) => a + (r.tokens ?? 0), 0), days: input.detect.scanned.days },
107
+ rows,
108
+ fixForMe: { count: rows.filter((r) => open(r) && r.auto).length, needsYou: rows.filter((r) => open(r) && !r.auto).length },
109
+ ...(trace ? { trace } : {}),
110
+ };
111
+ }
package/dist/stamps.js ADDED
@@ -0,0 +1,14 @@
1
+ export const STAMPS_PER_CARD = 10;
2
+ export function stampCard(cards) {
3
+ const kept = cards
4
+ .filter((c) => !c.advice && c.outcome === 'kept')
5
+ .map((c) => c.updatedAt)
6
+ .sort();
7
+ const n = kept.length;
8
+ const fullCards = Math.floor(n / STAMPS_PER_CARD);
9
+ const onCard = n % STAMPS_PER_CARD;
10
+ // Just filled a card: show it full until the next stamp starts a new one.
11
+ const full = n > 0 && onCard === 0;
12
+ const stamps = full ? kept.slice(-STAMPS_PER_CARD) : kept.slice(n - onCard);
13
+ return { kept: n, fullCards, stamps, full, toGo: full ? 0 : STAMPS_PER_CARD - onCard };
14
+ }
package/dist/suggest.js CHANGED
@@ -9,6 +9,7 @@ import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
9
9
  import { basename, join } from 'node:path';
10
10
  import { addCard } from './board.js';
11
11
  import { readTaste } from './taste.js';
12
+ import { approveScore, reasonFor } from './approvals.js';
12
13
  import { exe } from './exe.js';
13
14
  /** Vision and convention docs, in order of how much they say about where the repo is going. */
14
15
  const DOCS = ['README.md', 'VISION.md', 'ROADMAP.md', 'FEATURES.md', 'PLAN.md', 'TODO.md', 'CONTRIBUTING.md', 'CLAUDE.md', 'AGENTS.md'];
@@ -146,20 +147,29 @@ function parseJson(text) {
146
147
  export async function suggestTasks(repo, runner, opts) {
147
148
  const count = opts.count ?? 5;
148
149
  const digest = repoDigest(repo, { existing: opts.existing, issues: opts.issues ?? openIssues(repo) });
149
- const result = await runner.run({ prompt: suggestPrompt(digest.text, count), cwd: opts.cwd, model: opts.model, tools: '', timeoutMs: 240_000 });
150
+ const text = opts.approvals ? `${digest.text}\n\n${opts.approvals}` : digest.text;
151
+ const result = await runner.run({ prompt: suggestPrompt(text, count), cwd: opts.cwd, model: opts.model, tools: '', timeoutMs: 240_000 });
150
152
  if (result.timedOut)
151
153
  throw new Error('Suggesting tasks timed out. Try again.');
152
154
  if (result.exitCode !== 0)
153
155
  throw new Error(`claude exited with ${result.exitCode}: ${result.stderr.trim().slice(0, 300)}`);
154
156
  return validateTasks(parseJson(result.output), digest.sources, opts.existing, count);
155
157
  }
156
- /** The tasks as suggested cards in that repo, each saying where it came from. */
157
- export function addSuggested(board, repo, tasks, now) {
158
- return tasks.map((t) => {
158
+ /**
159
+ * The tasks as suggested cards in that repo, each saying where it came from. With `stats` (approvals.ts), the ones
160
+ * you'd most likely approve go first, and the why says so ("you approved 9 of 10 chores").
161
+ */
162
+ export function addSuggested(board, repo, tasks, now, stats = []) {
163
+ const why = (t) => `${t.kind === 'vision' ? 'Next step' : 'Chore'} from ${t.source} · ${t.size}${t.why ? `: ${t.why}` : ''}`;
164
+ const ranked = tasks
165
+ .map((t) => ({ t, card: { title: t.title, idea: t.idea, why: why(t), source: 'suggest' } }))
166
+ .map((x) => ({ ...x, score: approveScore(x.card, stats), reason: reasonFor(x.card, stats) }))
167
+ .sort((a, b) => b.score - a.score);
168
+ return ranked.map(({ t, card, reason }) => {
159
169
  const c = addCard(board, t.idea, repo, now, 'suggested');
160
170
  c.title = t.title;
161
171
  c.source = 'suggest';
162
- c.why = `${t.kind === 'vision' ? 'Next step' : 'Chore'} from ${t.source} · ${t.size}${t.why ? `: ${t.why}` : ''}`;
172
+ c.why = card.why + (reason ? ` · ${reason}` : '');
163
173
  return c;
164
174
  });
165
175
  }
package/dist/triggers.js CHANGED
@@ -19,6 +19,11 @@ export function markFired(key, now, why) {
19
19
  s.lastDecision = why;
20
20
  writeJson(statePath(), s);
21
21
  }
22
+ /** Forget a fired key: "Skip tonight" undone. */
23
+ export function unmarkFired(key) {
24
+ const s = loadTriggerState();
25
+ writeJson(statePath(), { ...s, fired: s.fired.filter((k) => k !== key) });
26
+ }
22
27
  export function noteTick(now, why) {
23
28
  writeJson(statePath(), { ...loadTriggerState(), lastTickAt: now.toISOString(), lastDecision: why });
24
29
  }
package/dist/usage.js CHANGED
@@ -15,6 +15,7 @@ import { join } from 'node:path';
15
15
  import { projectsDir } from './dream.js';
16
16
  import { homePath, readJson, writeJson } from './home.js';
17
17
  import { CLAUDE_PRICES } from './vendor/codeburn/prices.js';
18
+ import { windowFor } from './context.js';
18
19
  /** Bump when parsing or pricing changes, so old cached rows are re-read. */
19
20
  export const CACHE_VERSION = 3;
20
21
  export function usageCachePath() {
@@ -251,6 +252,8 @@ export function usageView(ledger, now, days = 7, top = 10, canShowTitle = () =>
251
252
  const models = new Map();
252
253
  const convs = new Map();
253
254
  const helperOnly = new Set();
255
+ // Per conversation: the last main-session request (its context and model) and the biggest one.
256
+ const ctx = new Map();
254
257
  const all = zero();
255
258
  for (const r of inRange) {
256
259
  add(all, r);
@@ -270,7 +273,7 @@ export function usageView(ledger, now, days = 7, top = 10, canShowTitle = () =>
270
273
  helperOnly.add(r.session);
271
274
  const away = r.basis === 'recorded';
272
275
  const shown = away || canShowTitle(r.workspace);
273
- c = { ...zero(), session: r.session, title: shown ? ledger.titles[r.session] ?? null : null, workspace: r.workspace, start: r.at, end: r.at, models: [], away, private: !shown };
276
+ c = { ...zero(), session: r.session, title: shown ? ledger.titles[r.session] ?? null : null, workspace: r.workspace, start: r.at, end: r.at, models: [], away, private: !shown, context: 0, window: 0, model: '' };
274
277
  convs.set(r.session, c);
275
278
  }
276
279
  add(c, r);
@@ -280,6 +283,23 @@ export function usageView(ledger, now, days = 7, top = 10, canShowTitle = () =>
280
283
  c.end = r.at;
281
284
  if (!c.models.includes(r.model))
282
285
  c.models.push(r.model);
286
+ // Away runs keep only their totals, never one request's size: no context for them.
287
+ if (!r.agent && r.basis !== 'recorded') {
288
+ const sent = r.input + r.cacheRead + r.cacheWrite5m + r.cacheWrite1h;
289
+ const k = ctx.get(r.session);
290
+ if (!k)
291
+ ctx.set(r.session, { at: r.at, context: sent, model: r.model, peak: sent });
292
+ else {
293
+ k.peak = Math.max(k.peak, sent);
294
+ if (r.at >= k.at)
295
+ Object.assign(k, { at: r.at, context: sent, model: r.model });
296
+ }
297
+ }
298
+ }
299
+ for (const [session, k] of ctx) {
300
+ const c = convs.get(session);
301
+ if (c)
302
+ Object.assign(c, { context: k.context, window: windowFor(k.model, k.peak), model: k.model });
283
303
  }
284
304
  const sortTally = (xs) => xs.sort((a, b) => b.total.costUsd - a.total.costUsd);
285
305
  const today = dayMap.get(localDay(now.toISOString())) ?? zero();