chompyy 0.6.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.
- package/README.md +3 -1
- package/dist/advice.js +98 -1
- package/dist/approvals.js +129 -0
- package/dist/appstate.js +10 -0
- package/dist/away.js +6 -2
- package/dist/cli.js +80 -13
- package/dist/costs.js +40 -2
- package/dist/detect.js +38 -6
- package/dist/didwork.js +26 -0
- package/dist/nightcap.js +15 -3
- package/dist/nudge.js +23 -6
- package/dist/punchcard.js +39 -0
- package/dist/savings.js +111 -0
- package/dist/suggest.js +15 -5
- package/dist/vendor/codeburn/src/parser.js +2 -0
- package/dist/wastechecks.js +233 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -143,7 +143,7 @@ Each card in a git repo runs in its own worktree at `~/.chompyy/worktrees/<id>`
|
|
|
143
143
|
| `chompyy trends` | Last 7 days vs the 7 before: cost per card, keep rate, rating, blueprint edits; then what Chompyy learned: rules this week, waiting, corrections per conversation |
|
|
144
144
|
| `chompyy premise [--json]` | How often a 5-hour window reset with 20%+ left in a week that still had 10%+ spare: the capacity away runs can use. From your quota readings; every ended window is kept in `windows.jsonl` (numbers only), so it grows past the 8 days of `quota-history.json`. `--json` to share it |
|
|
145
145
|
| `chompyy detect [--days 30] [--all] [--json]` | The detective: what wastes tokens in your setup and habits, from your own files. One screen: the findings ranked by tokens and the fix to start with; `--all` adds each finding's count, measured or estimated, what it doesn't prove, and every fix. A mid-session cache rebuild names its cause (e.g. Tool Search loading an MCP server's tools). Works cold with `npx chompyy detect`, nothing else installed. This version checks startup tax (long CLAUDE.md, unused skills and MCP servers, cut-off MEMORY.md) and cache (cold returns, mid-session rebuilds). Reads only; changes nothing |
|
|
146
|
-
| `chompyy advise [--json]` | The detective, step 3: turns detect's findings into suggested cards on the board (the app's "Find savings"). Each card's plan shows what Chompyy saw, what it doesn't prove, the exact change and how it will check it worked. Approve a settings card (e.g. turn off a plugin you never use) and Chompyy applies it once no Claude Code session has been active for 10 minutes, backed up first; `chompyy undo <id>` puts it back if nothing changed it since. Habit cards are tracked from the day you approve; some things only you can do (claude.ai-synced skills). Dropped advice never comes back. Advice never runs on an away run |
|
|
146
|
+
| `chompyy advise [--json]` | The detective, step 3: turns detect's findings into suggested cards on the board (the app's Savings window: "Find savings again"; `chompyy advise fix` is its "Fix for me"). Each card's plan shows what Chompyy saw, what it doesn't prove, the exact change and how it will check it worked. Approve a settings card (e.g. turn off a plugin you never use) and Chompyy applies it once no Claude Code session has been active for 10 minutes, backed up first; `chompyy undo <id>` puts it back if nothing changed it since. Habit cards are tracked from the day you approve; some things only you can do (claude.ai-synced skills). Dropped advice never comes back. Advice never runs on an away run |
|
|
147
147
|
| `chompyy advise apply` | Apply approved settings advice now if no session has been active for 10 minutes (the app and the 5-minute tick do this on their own) |
|
|
148
148
|
| `chompyy worked [--all] [--json] [--share]` | Did the advice work: each applied card against the check it set up, plus the nudge's measured result, and one "Saved so far" total (also in the menu panel) that adds only what was counted. `--share` prints a summary with no project, skill or file names |
|
|
149
149
|
| `chompyy nudge on\|off` | Live suggestions while you work. Adds a UserPromptSubmit hook to `~/.claude/settings.json` (backed up first; your other hooks stay). When you come back to a conversation of 40k+ tokens after more than an hour, its cache has expired: the hook stops that first message once and says what sending it rebuilds, what a fresh start costs, and the cheaper ways (/clear with a note, or /compact). Send it again and it goes through. A conversation compacted since its last reply (your /compact, or Claude Code's own while you were away) sends a summary, so it isn't stopped. Needs a global install (`npm install -g chompyy`); away runs turn hooks off, so it never touches them |
|
|
@@ -154,6 +154,8 @@ Each card in a git repo runs in its own worktree at `~/.chompyy/worktrees/<id>`
|
|
|
154
154
|
| `chompyy recap [--month 2026-11] [--json]` | Your month with Chompyy on one card: tokens, API value and cookies, busiest day, conversations, cards baked and kept, biggest bake. This month once it's a week old, else last month. No names, safe to share |
|
|
155
155
|
| `chompyy menu [--json]` | Every coding agent you used in the last 30 days as a café chalkboard: Claude Code and the others, tokens and API value, most first. Agent and model names only, safe to share |
|
|
156
156
|
| `chompyy label [--json]` | Your week of Claude Code as a Nutrition Facts label: cached reads (fibre), cache writes (carbs), tokens resent after a break (added sugar), input and output (protein). Amounts only, safe to share |
|
|
157
|
+
| `chompyy approvals [--json]` | Which of Chompyy's suggestions you approve, by kind (repo tasks, chores, tests, docs, …), from what you approved, dropped or let expire. New suggestions are ranked by it and the suggester is told what you tend to want |
|
|
158
|
+
| `chompyy savings [--json]` | Where your tokens went this week (cheap cached reads vs the slice worth fixing), every waste ranked with its status (to fix, measuring, worked) and before → after, and your biggest cold return step by step. The app's Savings window draws it |
|
|
157
159
|
| `chompyy stamps [--json]` | Your loyalty stamp card: one stamp per card you kept, ten to a card, with the dates. No titles, safe to share |
|
|
158
160
|
| `chompyy agents [--json] [--refresh]` | Every other coding agent codeburn reads (Cursor, Copilot, Gemini CLI, OpenCode, … about 40): tokens and API value today, this week and over 30 and 90 days (agents used in the last 90 days), at most one scan per 10 minutes |
|
|
159
161
|
| `chompyy codex [on\|off] [--json]` | Codex beside Claude: its 5-hour and weekly limits (reads Codex's saved login to ask OpenAI; never renews or changes it) and its tokens and API value (codeburn's Codex parser) |
|
package/dist/advice.js
CHANGED
|
@@ -28,6 +28,63 @@ function plan(f, a, what) {
|
|
|
28
28
|
`**Check:** ${a.check}`,
|
|
29
29
|
].filter(Boolean).join('\n\n');
|
|
30
30
|
}
|
|
31
|
+
/** Most new-check cards one advise run makes, and the least tokens a week worth a card. */
|
|
32
|
+
export const NEW_CHECK_CARDS = 3;
|
|
33
|
+
export const NEW_CHECK_MIN_WEEK = 10_000;
|
|
34
|
+
/** codeburn reports that point at sessions or correlations, with no step to take: listed, never a card. */
|
|
35
|
+
const NO_CARD = new Set(['retry-heavy-capabilities', 'low-worth-sessions', 'cost-outliers']);
|
|
36
|
+
/**
|
|
37
|
+
* codeburn checks Chompyy can fix itself, as a Claude Code setting with a backup and Undo (settings lane): no
|
|
38
|
+
* shell-profile edits. These always get a card (not capped), since one approval does the whole fix.
|
|
39
|
+
*/
|
|
40
|
+
export const AUTO_FIX = {
|
|
41
|
+
'bash-output-cap': (settings) => ({
|
|
42
|
+
changes: [{ file: settings, key: ['env', 'BASH_MAX_OUTPUT_LENGTH'], from: settingAt(settings, ['env', 'BASH_MAX_OUTPUT_LENGTH']), to: '15000' }],
|
|
43
|
+
doing: 'Cap shell output at 15,000 characters in new sessions (Claude Code setting). Undo puts it back',
|
|
44
|
+
}),
|
|
45
|
+
};
|
|
46
|
+
function settingAt(file, key) {
|
|
47
|
+
try {
|
|
48
|
+
return getAt(JSON.parse(readFileSync(file, 'utf8')), key);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** Tokens a week, from a total over `days` days. */
|
|
55
|
+
export const perWeek = (tokens, days) => Math.round((tokens / Math.max(1, days)) * 7);
|
|
56
|
+
/**
|
|
57
|
+
* A card for one of codeburn's checks or our newer rules: what it found, the exact fix to do (a command, a line for
|
|
58
|
+
* CLAUDE.md, or a habit), and the check registered before: the same check, per week, a third or less of today.
|
|
59
|
+
* Nothing is changed for you yet: "I've done it" (or trying the habit) starts the clock.
|
|
60
|
+
*/
|
|
61
|
+
export function newCheckAdvice(f, days, settings = claudeSettingsPath()) {
|
|
62
|
+
if (!f.tokens)
|
|
63
|
+
return null;
|
|
64
|
+
const week = perWeek(f.tokens, days);
|
|
65
|
+
const habit = f.lane === 'habit';
|
|
66
|
+
const goal = Math.floor(week / 3);
|
|
67
|
+
const a = {
|
|
68
|
+
key: f.key ?? `cb:${f.codeburnId}`,
|
|
69
|
+
rule: f.rule,
|
|
70
|
+
lane: habit ? 'habit' : 'manual',
|
|
71
|
+
basis: f.basis,
|
|
72
|
+
tokens: f.tokens,
|
|
73
|
+
baseline: { tokens: week },
|
|
74
|
+
check: `It worked if this check finds ~${k(goal)} tokens a week or less (now ~${k(week)}).`,
|
|
75
|
+
saw: `${f.basis === 'estimated' ? '~' : ''}${k(week)} tokens a week: ${f.title.charAt(0).toLowerCase()}${f.title.slice(1)}`,
|
|
76
|
+
// codeburn's fix reads "<action>: <detail>"; the action alone is the short step.
|
|
77
|
+
doing: (f.source === 'codeburn' ? f.fix.split(': ')[0] : f.fix.split(/(?<=\.)\s/)[0]).replace(/\.$/, ''),
|
|
78
|
+
checkShort: `~${k(goal)} a week or less (now ~${k(week)})`,
|
|
79
|
+
};
|
|
80
|
+
const auto = f.codeburnId ? AUTO_FIX[f.codeburnId]?.(settings) : undefined;
|
|
81
|
+
if (auto) {
|
|
82
|
+
Object.assign(a, { lane: 'settings', changes: auto.changes, doing: auto.doing });
|
|
83
|
+
return { title: f.title, idea: auto.doing, plan: plan(f, a, settingsWhat(auto.changes)), advice: a };
|
|
84
|
+
}
|
|
85
|
+
const what = habit ? `**Try:** ${f.fix}` : `**Do:** ${f.fix}\n\nThen press "I've done it".`;
|
|
86
|
+
return { title: f.title, idea: f.fix, plan: plan(f, a, what), advice: a };
|
|
87
|
+
}
|
|
31
88
|
const settingsWhat = (changes) => [
|
|
32
89
|
'**The change:**',
|
|
33
90
|
...changes.map((c) => `- ${describeKey(c)}`),
|
|
@@ -39,7 +96,23 @@ export function adviceFrom(r, opts = {}) {
|
|
|
39
96
|
const out = [];
|
|
40
97
|
const settings = opts.settings ?? claudeSettingsPath();
|
|
41
98
|
const home = homedir();
|
|
99
|
+
// codeburn's checks and our newer ones (own key): cards only for the biggest few with a concrete step, so the
|
|
100
|
+
// board isn't flooded; the rest stay in detect and the Savings window.
|
|
101
|
+
const isNew = (f) => (f.source === 'codeburn' || f.key) && !f.worthKnowing && !!f.tokens;
|
|
102
|
+
const autoFix = r.findings.filter((f) => isNew(f) && f.codeburnId && AUTO_FIX[f.codeburnId]);
|
|
103
|
+
const fresh = r.findings
|
|
104
|
+
.filter((f) => isNew(f) && !autoFix.includes(f) && !NO_CARD.has(f.codeburnId ?? '') && perWeek(f.tokens, r.scanned.days) >= NEW_CHECK_MIN_WEEK)
|
|
105
|
+
.sort((a, b) => b.tokens - a.tokens)
|
|
106
|
+
.slice(0, NEW_CHECK_CARDS);
|
|
107
|
+
for (const f of [...autoFix, ...fresh]) {
|
|
108
|
+
const draft = newCheckAdvice(f, r.scanned.days, settings);
|
|
109
|
+
if (draft)
|
|
110
|
+
out.push({ ...draft, cwd: home });
|
|
111
|
+
}
|
|
42
112
|
for (const f of r.findings) {
|
|
113
|
+
// codeburn's checks and our newer ones (own key): handled above.
|
|
114
|
+
if (f.source === 'codeburn' || f.key)
|
|
115
|
+
continue;
|
|
43
116
|
if (f.rule === 'C1') {
|
|
44
117
|
const w = r.scanned.coldWeek;
|
|
45
118
|
const a = {
|
|
@@ -147,7 +220,8 @@ export function adviceFrom(r, opts = {}) {
|
|
|
147
220
|
return out;
|
|
148
221
|
}
|
|
149
222
|
/** Keys you dropped (not ones that expired unseen): those never come back. */
|
|
150
|
-
|
|
223
|
+
/** Advice keys you dropped ("no, never"): never suggested again, and the Savings window says you declined them. */
|
|
224
|
+
export function droppedKeys() {
|
|
151
225
|
const path = homePath('archive.jsonl');
|
|
152
226
|
const keys = new Set();
|
|
153
227
|
if (!existsSync(path))
|
|
@@ -220,6 +294,29 @@ export function approveAdvice(c, now) {
|
|
|
220
294
|
a.state = a.lane === 'habit' ? 'trying' : 'done';
|
|
221
295
|
return a.lane === 'habit' ? `✅ #${c.id} closed: trying it from today. ${a.check}` : `✅ #${c.id} closed. ${a.check}`;
|
|
222
296
|
}
|
|
297
|
+
/** Lanes Chompyy carries out itself: a settings change (backed up, Undo) or a sandboxed away run. */
|
|
298
|
+
export const SELF_LANES = new Set(['settings', 'work']);
|
|
299
|
+
/**
|
|
300
|
+
* "Fix these for me": approve every suggested advice card Chompyy can carry out itself. Settings go in once no
|
|
301
|
+
* Claude Code session has run for 10 minutes; work cards run in the next away run (tonight's, with a bedtime).
|
|
302
|
+
* Habits and steps only you can take stay as they are, counted so the window can say so.
|
|
303
|
+
*/
|
|
304
|
+
export function fixForMe(board, now) {
|
|
305
|
+
const open = board.cards.filter((c) => c.advice && (c.column === 'suggested' || c.column === 'later'));
|
|
306
|
+
const approved = [];
|
|
307
|
+
for (const c of open) {
|
|
308
|
+
if (!SELF_LANES.has(c.advice.lane))
|
|
309
|
+
continue;
|
|
310
|
+
if (c.advice.lane === 'work') {
|
|
311
|
+
c.column = 'approved';
|
|
312
|
+
c.approvedAt = c.updatedAt = now.toISOString();
|
|
313
|
+
}
|
|
314
|
+
else
|
|
315
|
+
approveAdvice(c, now);
|
|
316
|
+
approved.push(c);
|
|
317
|
+
}
|
|
318
|
+
return { approved, needsYou: open.length - approved.length };
|
|
319
|
+
}
|
|
223
320
|
/** When a Claude Code session last wrote its transcript (ms), so settings never change under an open conversation. */
|
|
224
321
|
export function lastSessionActivity(root = projectsDir()) {
|
|
225
322
|
let last = 0;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// Which of Chompyy's suggestions you approve: a separate taste from how you like work done (FEATURES §3). Every
|
|
2
|
+
// suggested card you approve, drop or leave to expire is one decision; each card has a few plain features (where it
|
|
3
|
+
// came from, next step or chore, small or medium, what it's about). The approve rate per feature ranks new
|
|
4
|
+
// suggestions and tells the suggester what you tend to want. Counts only, from the board and its archive.
|
|
5
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
6
|
+
import { homePath } from './home.js';
|
|
7
|
+
const TOPICS = [
|
|
8
|
+
['tests', /\btests?\b|\bspec\b|coverage/i],
|
|
9
|
+
['docs', /\bdocs?\b|readme|documentation|changelog|comment/i],
|
|
10
|
+
['bug fixes', /\bfix(es|ed)?\b|\bbug\b|crash|broken|error/i],
|
|
11
|
+
['refactors', /refactor|clean ?up|simplif|rename|split|extract/i],
|
|
12
|
+
['speed', /\bperf|faster|slow|cache|speed/i],
|
|
13
|
+
['UI', /\bui\b|window|button|panel|popover|layout|board|menu/i],
|
|
14
|
+
['savings', /token|quota|compact|skill|plugin|mcp/i],
|
|
15
|
+
];
|
|
16
|
+
/** A card's features: "from repo tasks", "chores", "small", "tests", … (plain words: they show in the app and prompt). */
|
|
17
|
+
export function features(c) {
|
|
18
|
+
const out = [];
|
|
19
|
+
if (c.source === 'detect')
|
|
20
|
+
out.push('savings advice');
|
|
21
|
+
else if (c.source === 'history')
|
|
22
|
+
out.push('ideas from history');
|
|
23
|
+
else if (c.source === 'suggest')
|
|
24
|
+
out.push('repo tasks');
|
|
25
|
+
const why = c.why ?? '';
|
|
26
|
+
if (/^Chore\b/.test(why))
|
|
27
|
+
out.push('chores');
|
|
28
|
+
else if (/^Next step\b/.test(why))
|
|
29
|
+
out.push('next steps');
|
|
30
|
+
if (/· medium/.test(why))
|
|
31
|
+
out.push('medium tasks');
|
|
32
|
+
else if (/· small/.test(why))
|
|
33
|
+
out.push('small tasks');
|
|
34
|
+
// Topic from the title only: every suggested idea says how it's checked ("tests pass"), which isn't its topic.
|
|
35
|
+
for (const [name, re] of TOPICS)
|
|
36
|
+
if (re.test(c.title))
|
|
37
|
+
out.push(name);
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
const PAST_SUGGESTED = new Set(['approved', 'running', 'review', 'done']);
|
|
41
|
+
/** One decision per Chompyy-suggested card: approved (on the board), dropped or expired (in the archive). */
|
|
42
|
+
export function decisions(board, archived) {
|
|
43
|
+
const out = [];
|
|
44
|
+
for (const c of board.cards) {
|
|
45
|
+
if (!c.source)
|
|
46
|
+
continue;
|
|
47
|
+
if (c.approvedAt || PAST_SUGGESTED.has(c.column))
|
|
48
|
+
out.push({ card: c, outcome: 'yes' });
|
|
49
|
+
}
|
|
50
|
+
for (const c of archived) {
|
|
51
|
+
if (!c.source || !c.droppedAt)
|
|
52
|
+
continue;
|
|
53
|
+
if (c.approvedAt)
|
|
54
|
+
out.push({ card: c, outcome: 'yes' });
|
|
55
|
+
else
|
|
56
|
+
out.push({ card: c, outcome: c.expired ? 'ignored' : 'no' });
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
/** A feature needs this many decisions before it ranks anything or reaches the prompt. */
|
|
61
|
+
export const MIN_DECISIONS = 3;
|
|
62
|
+
export function featureStats(ds) {
|
|
63
|
+
const by = new Map();
|
|
64
|
+
for (const d of ds) {
|
|
65
|
+
for (const f of features(d.card)) {
|
|
66
|
+
const s = by.get(f) ?? { feature: f, yes: 0, no: 0, ignored: 0, rate: 0 };
|
|
67
|
+
s[d.outcome] += 1;
|
|
68
|
+
by.set(f, s);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
for (const s of by.values())
|
|
72
|
+
s.rate = (s.yes + 1) / (s.yes + s.no + s.ignored / 2 + 2);
|
|
73
|
+
return [...by.values()].sort((a, b) => b.rate - a.rate || b.yes - a.yes);
|
|
74
|
+
}
|
|
75
|
+
const decided = (s) => s.yes + s.no + s.ignored;
|
|
76
|
+
/** How likely you'd approve this card: the mean rate of its features with enough decisions, else 0.5. */
|
|
77
|
+
export function approveScore(c, stats) {
|
|
78
|
+
const known = features(c).map((f) => stats.find((s) => s.feature === f)).filter((s) => !!s && decided(s) >= MIN_DECISIONS);
|
|
79
|
+
return known.length ? known.reduce((a, s) => a + s.rate, 0) / known.length : 0.5;
|
|
80
|
+
}
|
|
81
|
+
/** The strongest reason a card ranks where it does, e.g. "you approved 9 of 10 chores". */
|
|
82
|
+
export function reasonFor(c, stats) {
|
|
83
|
+
const known = features(c).map((f) => stats.find((s) => s.feature === f)).filter((s) => !!s && decided(s) >= MIN_DECISIONS);
|
|
84
|
+
const top = known.sort((a, b) => Math.abs(b.rate - 0.5) - Math.abs(a.rate - 0.5))[0];
|
|
85
|
+
return top ? `you approved ${top.yes} of ${decided(top)} ${top.feature}` : null;
|
|
86
|
+
}
|
|
87
|
+
/** For the suggester's prompt: what you tend to approve and drop. Empty until there are enough decisions. */
|
|
88
|
+
export function approvalsPrompt(stats) {
|
|
89
|
+
const known = stats.filter((s) => decided(s) >= MIN_DECISIONS);
|
|
90
|
+
const likes = known.filter((s) => s.rate >= 0.6).slice(0, 3);
|
|
91
|
+
const dislikes = known.filter((s) => s.rate <= 0.4).slice(-3);
|
|
92
|
+
if (!likes.length && !dislikes.length)
|
|
93
|
+
return '';
|
|
94
|
+
const say = (s) => `${s.feature} (approved ${s.yes} of ${decided(s)})`;
|
|
95
|
+
return [
|
|
96
|
+
'## Which suggestions the owner approves (from past decisions)',
|
|
97
|
+
likes.length ? `Tends to approve: ${likes.map(say).join(', ')}.` : '',
|
|
98
|
+
dislikes.length ? `Tends to drop or ignore: ${dislikes.map(say).join(', ')}. Suggest fewer of these unless the source is strong.` : '',
|
|
99
|
+
].filter(Boolean).join('\n');
|
|
100
|
+
}
|
|
101
|
+
export function loadArchive() {
|
|
102
|
+
const path = homePath('archive.jsonl');
|
|
103
|
+
if (!existsSync(path))
|
|
104
|
+
return [];
|
|
105
|
+
const out = [];
|
|
106
|
+
for (const line of readFileSync(path, 'utf8').split('\n')) {
|
|
107
|
+
try {
|
|
108
|
+
if (line.trim())
|
|
109
|
+
out.push(JSON.parse(line));
|
|
110
|
+
}
|
|
111
|
+
catch { }
|
|
112
|
+
}
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
export function approvalStats(board) {
|
|
116
|
+
return featureStats(decisions(board, loadArchive()));
|
|
117
|
+
}
|
|
118
|
+
export function approvalsText(stats, total) {
|
|
119
|
+
if (!total)
|
|
120
|
+
return 'No decisions on suggested cards yet. Approve or drop a few and Chompyy learns which ones you want.';
|
|
121
|
+
const known = stats.filter((s) => decided(s) >= MIN_DECISIONS);
|
|
122
|
+
const lines = [`What you approve, from ${total} decisions on suggested cards:`, ''];
|
|
123
|
+
for (const s of known.slice(0, 8))
|
|
124
|
+
lines.push(` ${String(Math.round(s.rate * 100)).padStart(3)}% ${s.feature.padEnd(20)} approved ${s.yes}, dropped ${s.no}, let expire ${s.ignored}`);
|
|
125
|
+
if (!known.length)
|
|
126
|
+
lines.push(` Not enough yet: each kind needs ${MIN_DECISIONS} decisions.`);
|
|
127
|
+
lines.push('', 'New suggestions are ranked by this, and the suggester is told what you tend to want.');
|
|
128
|
+
return lines.join('\n');
|
|
129
|
+
}
|
package/dist/appstate.js
CHANGED
|
@@ -20,6 +20,8 @@ import { learning } from './learning.js';
|
|
|
20
20
|
import { describeSignal, loadStore, nextQuestion, readSignals, receipts } from './taste.js';
|
|
21
21
|
import { agentInstalled, awayRunning, loadTriggerState } from './triggers.js';
|
|
22
22
|
import { nightcap } from './nightcap.js';
|
|
23
|
+
import { punchcard } from './punchcard.js';
|
|
24
|
+
import { loadLedger } from './usage.js';
|
|
23
25
|
import { demonOffer } from './demon.js';
|
|
24
26
|
import { planFor } from './permissions.js';
|
|
25
27
|
import { loadProfile, preflightHosts } from './preflight.js';
|
|
@@ -135,6 +137,14 @@ export function nightcapNow(board, config, now) {
|
|
|
135
137
|
approved: board.cards.filter((c) => c.column === 'approved').length,
|
|
136
138
|
fired: loadTriggerState().fired,
|
|
137
139
|
awayBusy: awayRunning() !== null,
|
|
140
|
+
quietFrom: () => {
|
|
141
|
+
try {
|
|
142
|
+
return punchcard(loadLedger().rows, now).quiet?.from ?? null;
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
},
|
|
138
148
|
});
|
|
139
149
|
}
|
|
140
150
|
function safeWarmCaches(now) {
|
package/dist/away.js
CHANGED
|
@@ -7,7 +7,7 @@ import { formatDuration } from './duration.js';
|
|
|
7
7
|
import { budgetGate } from './gate.js';
|
|
8
8
|
import { homePath } from './home.js';
|
|
9
9
|
import { windowView } from './quota.js';
|
|
10
|
-
import { costRange, readRuns, recordRun, usedBetween } from './costs.js';
|
|
10
|
+
import { costRange, hitRate, readRuns, recordRun, usedBetween } from './costs.js';
|
|
11
11
|
import { applyPermissions } from './permissions.js';
|
|
12
12
|
import { tasteForPrompt } from './taste.js';
|
|
13
13
|
import { boxTempDirs } from './verify.js';
|
|
@@ -280,11 +280,15 @@ export async function runCard(id, timeoutMs, deps, trigger) {
|
|
|
280
280
|
const c = getCard(b, id);
|
|
281
281
|
c.column = 'running';
|
|
282
282
|
c.updatedAt = new Date(startedMs).toISOString();
|
|
283
|
-
const
|
|
283
|
+
const past = readRuns();
|
|
284
|
+
const est = costRange(c, past);
|
|
285
|
+
const right = hitRate(past);
|
|
284
286
|
c.oven = {
|
|
285
287
|
since: c.updatedAt,
|
|
286
288
|
until: new Date(startedMs + timeoutMs).toISOString(),
|
|
287
289
|
...(est ? { expect: new Date(startedMs + Math.min(est.durationMidMs, timeoutMs)).toISOString(), from: est.n } : {}),
|
|
290
|
+
// How often these ranges were right (a backtest over past runs): the timer's hover says it.
|
|
291
|
+
...(est && right && right.time.of >= 3 ? { right: right.time } : {}),
|
|
288
292
|
};
|
|
289
293
|
return { ...c };
|
|
290
294
|
});
|
package/dist/cli.js
CHANGED
|
@@ -32,7 +32,10 @@ import { nutritionLabel } from './label.js';
|
|
|
32
32
|
import { recap, recapMonth } from './recap.js';
|
|
33
33
|
import { menuFrom } from './menu.js';
|
|
34
34
|
import { limitsState, READERS, refreshLimits } from './agentlimits.js';
|
|
35
|
-
import {
|
|
35
|
+
import { detectFull, detectText, scan } from './detect.js';
|
|
36
|
+
import { savingsView } from './savings.js';
|
|
37
|
+
import { punchcard } from './punchcard.js';
|
|
38
|
+
import { approvalsPrompt, approvalStats, approvalsText, decisions, featureStats, loadArchive } from './approvals.js';
|
|
36
39
|
import { allWindowEnds, archiveWindowEnds, premise, premiseText } from './premise.js';
|
|
37
40
|
import { keychainAllowed, loadLiveState, refreshLiveQuota } from './livequota.js';
|
|
38
41
|
import { recentProjects } from './projects.js';
|
|
@@ -42,16 +45,16 @@ import { acceptColdStart, forgetColdStart, formatColdStart, loadColdStart, runCo
|
|
|
42
45
|
import { keepHistory } from './claudesettings.js';
|
|
43
46
|
import { blueprintHash, drawPicture } from './picture.js';
|
|
44
47
|
import { receipt, receiptText } from './receipt.js';
|
|
45
|
-
import { costRange, formatCostRange, readRuns, tasteEffect, tasteEffectLine, trendLines } from './costs.js';
|
|
48
|
+
import { costRange, formatCostRange, hitRate, readRuns, tasteEffect, tasteEffectLine, trendLines } from './costs.js';
|
|
46
49
|
import { answerPreference, distill, distillDue, formatPrefs, formatQuestion, formatWhy, getPref, learnedCount, loadStore, nextQuestion, readSignals, recordOutcome, renderAgentsBlock, retirePreference, syncTasteFile, tasteChangesSince, tasteRulesForProject, } from './taste.js';
|
|
47
50
|
import { cachedWorkspaces, dream, dreamDue, formatDream, formatWorkspaces, projectsDir, readLogPath, setTicked } from './dream.js';
|
|
48
51
|
import { byKind, compactTokens, compare, formatExtras, formatUsage, loadLedger, periodDays, PERIODS, prCosts, usageView } from './usage.js';
|
|
49
52
|
import { formatTrace, traceSession } from './trace.js';
|
|
50
53
|
import { homedir } from 'node:os';
|
|
51
54
|
import { clashOf, refreshCard, refreshGate, refreshClashing, withRefreshLock } from './refresh.js';
|
|
52
|
-
import { adviseText, applyDue, approveAdvice, runAdvise, undoAdvice } from './advice.js';
|
|
55
|
+
import { adviceFrom, adviseText, applyDue, approveAdvice, droppedKeys, fixForMe, runAdvise, SELF_LANES, undoAdvice } from './advice.js';
|
|
53
56
|
import { daytimeFile, daytimeState, setDaytime } from './daytime.js';
|
|
54
|
-
import { checkWorked, nudgeProofText, savedSoFar, shareText, workedText } from './didwork.js';
|
|
57
|
+
import { checkWorked, isNewCheck, measurable, newCheckDays, nudgeProofText, savedSoFar, shareText, workedText } from './didwork.js';
|
|
55
58
|
import { addSuggested, suggestTasks, suggestText } from './suggest.js';
|
|
56
59
|
import { coldWarningText, hookCommand, impact, loadNudges, nudgeInstalled, nudgeText, runHook, setNudge, setProjectMode, takeGoingCold } from './nudge.js';
|
|
57
60
|
import { withKeepLock } from './keeplock.js';
|
|
@@ -148,6 +151,8 @@ Triggers (start away runs on their own; the budget gate still decides every card
|
|
|
148
151
|
chompyy recap [--month 2026-11] [--json] your month on one shareable card: tokens, busiest day, cards baked
|
|
149
152
|
chompyy menu [--json] every agent you used in 30 days as a café chalkboard: tokens and value, safe to share
|
|
150
153
|
chompyy label [--json] your week as Nutrition Facts: cached reads, cache writes, resent tokens, output; shareable
|
|
154
|
+
chompyy approvals [--json] which suggestions you approve, by kind; ranks new suggestions
|
|
155
|
+
chompyy savings [--json] where your tokens went, what's worth fixing, what your fixes saved
|
|
151
156
|
chompyy stamps [--json] your loyalty stamp card: one stamp per kept card, ten to a card; shareable
|
|
152
157
|
chompyy agents [--json] every other coding agent on this Mac (Cursor, Copilot, Gemini, …): tokens and value
|
|
153
158
|
chompyy codex [on|off] [--json] Codex's limits and tokens beside Claude's (on = read its login, never change it)
|
|
@@ -692,6 +697,30 @@ async function main(argv) {
|
|
|
692
697
|
console.log(l.tip);
|
|
693
698
|
return;
|
|
694
699
|
}
|
|
700
|
+
case 'savings': {
|
|
701
|
+
// The Savings window: the week as one bar (fine vs fixable), every waste ranked with its status and
|
|
702
|
+
// before → after, and one conversation step by step (savings.ts).
|
|
703
|
+
let resent = 0;
|
|
704
|
+
try {
|
|
705
|
+
resent = impact().thisWeek.tokens;
|
|
706
|
+
}
|
|
707
|
+
catch { }
|
|
708
|
+
const label = nutritionLabel(loadLedger().rows, resent, now);
|
|
709
|
+
const r = await detectFull({ now });
|
|
710
|
+
const cards = loadBoard().cards;
|
|
711
|
+
const { total } = savedSoFar(cards.filter((c) => c.advice), now, { on: nudgeInstalled() || loadNudges().length > 0 });
|
|
712
|
+
const view = savingsView({ label, detect: r, cards, saved: total ? { tokens: total.tokens, since: total.since, line: total.line } : null, scan: scan({ days: 14, now }), now, dropped: droppedKeys(), autoKeys: new Set(adviceFrom(r, { nudgeOn: nudgeInstalled() }).filter((d) => SELF_LANES.has(d.advice.lane)).map((d) => d.advice.key)) });
|
|
713
|
+
if (values.json)
|
|
714
|
+
return json(view);
|
|
715
|
+
console.log(`This week: ${compactTokens(view.week.tokens)} tokens, ${view.week.parts.filter((p) => p.fixable).map((p) => `${compactTokens(p.tokens)} resent for nothing`).join('') || 'nothing resent'}.`);
|
|
716
|
+
if (view.saved)
|
|
717
|
+
console.log(view.saved.line);
|
|
718
|
+
console.log(`Still fixable: ~${compactTokens(view.fixable.tokens)} tokens in ${view.fixable.days} days.\n`);
|
|
719
|
+
for (const row of view.rows.slice(0, 5))
|
|
720
|
+
console.log(` ${row.status.padEnd(13)} ${row.tokens === undefined ? '' : compactTokens(row.tokens).padStart(6)} ${row.title}`);
|
|
721
|
+
console.log('\nOpen it as a picture: the Savings window in the app.');
|
|
722
|
+
return;
|
|
723
|
+
}
|
|
695
724
|
case 'stamps': {
|
|
696
725
|
// The loyalty stamp card: one stamp per kept card, ten to a card. Safe to share (no titles).
|
|
697
726
|
const c = stampCard(loadBoard().cards);
|
|
@@ -951,7 +980,7 @@ async function main(argv) {
|
|
|
951
980
|
console.log(` #${card.id} ${card.title} [${state}]`);
|
|
952
981
|
if (card.column === 'later' && !card.blueprint?.trim())
|
|
953
982
|
console.log(' blueprint needed before approval');
|
|
954
|
-
console.log(` ${formatCostRange(costRange(card, runs))}`);
|
|
983
|
+
console.log(` ${formatCostRange(costRange(card, runs), hitRate(runs))}`);
|
|
955
984
|
}
|
|
956
985
|
console.log('\nThis is a read-only list. Start selected work with `chompyy away <duration>`.');
|
|
957
986
|
return;
|
|
@@ -1015,7 +1044,7 @@ async function main(argv) {
|
|
|
1015
1044
|
return json(cardView(card));
|
|
1016
1045
|
console.log(formatCard(card));
|
|
1017
1046
|
if (!card.run)
|
|
1018
|
-
console.log(`\n${formatCostRange(costRange(card, readRuns()))}`);
|
|
1047
|
+
console.log(`\n${formatCostRange(costRange(card, readRuns()), hitRate(readRuns()))}`);
|
|
1019
1048
|
else if (card.run.cost?.fiveHourPct != null)
|
|
1020
1049
|
console.log(`used ${card.run.cost.fiveHourPct}% of the 5h window${card.run.trigger ? ` · started by the ${card.run.trigger} trigger` : ''}`);
|
|
1021
1050
|
return;
|
|
@@ -1371,7 +1400,7 @@ async function main(argv) {
|
|
|
1371
1400
|
if (values.json && values.app) {
|
|
1372
1401
|
const long = usageView(ledger, now, 84, 0, canShow);
|
|
1373
1402
|
const week = usageView(ledger, now, 7, 10, canShow);
|
|
1374
|
-
return json({ generatedAt: to, period: period || `${days}d`, days: long.days, today: long.today, week, view: { ...view, byKind: kinds, prs }, compare: cmp, unpriced: long.unpriced });
|
|
1403
|
+
return json({ generatedAt: to, period: period || `${days}d`, days: long.days, today: long.today, week, view: { ...view, byKind: kinds, prs }, compare: cmp, unpriced: long.unpriced, punchcard: punchcard(ledger.rows, now) });
|
|
1375
1404
|
}
|
|
1376
1405
|
if (values.json)
|
|
1377
1406
|
return json({ ...view, byKind: kinds, prs, compare: cmp });
|
|
@@ -1404,7 +1433,7 @@ async function main(argv) {
|
|
|
1404
1433
|
return;
|
|
1405
1434
|
}
|
|
1406
1435
|
case 'detect': {
|
|
1407
|
-
const r =
|
|
1436
|
+
const r = await detectFull({ days: values.days ? Number(values.days) : 30, now });
|
|
1408
1437
|
if (values.json)
|
|
1409
1438
|
return json(r);
|
|
1410
1439
|
console.log(detectText(r, { all: Boolean(values.all), projects: projectsDir().replace(homedir(), '~') }).join('\n'));
|
|
@@ -1419,7 +1448,26 @@ async function main(argv) {
|
|
|
1419
1448
|
return json(lines);
|
|
1420
1449
|
return console.log(lines.length ? lines.join('\n') : 'Nothing waiting to be applied.');
|
|
1421
1450
|
}
|
|
1422
|
-
const
|
|
1451
|
+
const found = await detectFull({ now });
|
|
1452
|
+
if (args[0] === 'fix') {
|
|
1453
|
+
// "Fix these for me" (Savings window): cards for every finding, then approve what Chompyy can do itself.
|
|
1454
|
+
updateBoard((b) => runAdvise(b, now, found));
|
|
1455
|
+
const res = updateBoard((b) => fixForMe(b, now));
|
|
1456
|
+
const applied = updateBoard((b) => applyDue(b, now));
|
|
1457
|
+
if (values.json)
|
|
1458
|
+
return json({ approved: res.approved.map((c) => ({ id: c.id, title: c.title, lane: c.advice.lane })), needsYou: res.needsYou, applied });
|
|
1459
|
+
if (!res.approved.length)
|
|
1460
|
+
return console.log(`Nothing Chompyy can fix by itself right now.${res.needsYou ? ` ${res.needsYou} need you: habits and steps only you can take.` : ''}`);
|
|
1461
|
+
console.log(`Fixing ${res.approved.length}:`);
|
|
1462
|
+
for (const c of res.approved)
|
|
1463
|
+
console.log(` #${c.id} ${c.title} · ${c.advice.lane === 'work' ? 'runs in the next away run' : 'settings, once no session has run for 10 min (Undo any time)'}`);
|
|
1464
|
+
for (const line of applied)
|
|
1465
|
+
console.log(` ${line}`);
|
|
1466
|
+
if (res.needsYou)
|
|
1467
|
+
console.log(`${res.needsYou} need you: habits and steps only you can take.`);
|
|
1468
|
+
return;
|
|
1469
|
+
}
|
|
1470
|
+
const res = updateBoard((b) => runAdvise(b, now, found));
|
|
1423
1471
|
if (values.json)
|
|
1424
1472
|
return json({ added: res.added.map((c) => c.id), updated: res.updated.map((c) => c.id), skipped: res.skipped });
|
|
1425
1473
|
return console.log(adviseText(res));
|
|
@@ -1439,7 +1487,14 @@ async function main(argv) {
|
|
|
1439
1487
|
}
|
|
1440
1488
|
case 'worked': {
|
|
1441
1489
|
// The detective, step 5: each applied/tried advice card against the check it registered (didwork.ts).
|
|
1442
|
-
|
|
1490
|
+
// New-check cards (codeburn's checks, our newer rules) re-run those checks over the days since each started.
|
|
1491
|
+
const recheck = new Map();
|
|
1492
|
+
for (const c of loadBoard().cards.filter((x) => measurable(x) && isNewCheck(x.advice))) {
|
|
1493
|
+
const days = newCheckDays(Date.parse(c.advice.since ?? c.approvedAt ?? c.updatedAt), now.getTime());
|
|
1494
|
+
if (days >= 7 && !recheck.has(days))
|
|
1495
|
+
recheck.set(days, (await detectFull({ days, now })).findings);
|
|
1496
|
+
}
|
|
1497
|
+
const cards = updateBoard((b) => checkWorked(b, now, { recheck }));
|
|
1443
1498
|
const { proof, total } = savedSoFar(cards, now, { on: nudgeInstalled() || loadNudges().length > 0 });
|
|
1444
1499
|
if (values.share) {
|
|
1445
1500
|
// A summary to paste on the tester issue: counts, tokens and dates; no project, skill or file names.
|
|
@@ -1465,13 +1520,25 @@ async function main(argv) {
|
|
|
1465
1520
|
throw new Error('Suggesting tasks needs the claude command (Claude Code in Terminal). See TRY.md.');
|
|
1466
1521
|
if (!values.force && !windowActive(now))
|
|
1467
1522
|
throw new Error('No active 5-hour window: suggesting now would start one. Try again while you use Claude Code, or add --force.');
|
|
1468
|
-
const
|
|
1469
|
-
const
|
|
1470
|
-
|
|
1523
|
+
const board = loadBoard();
|
|
1524
|
+
const existing = board.cards.map((c) => c.title);
|
|
1525
|
+
// What you tend to approve (approvals.ts) steers the suggester and ranks what comes back.
|
|
1526
|
+
const stats = approvalStats(board);
|
|
1527
|
+
const { tasks, dropped } = await suggestTasks(repo, new ClaudeRunner(config.claudeBin), { model: config.suggestModel, cwd: chompyyHome(), existing, approvals: approvalsPrompt(stats) });
|
|
1528
|
+
const cards = updateBoard((b) => addSuggested(b, repo, tasks, now, stats));
|
|
1471
1529
|
if (values.json)
|
|
1472
1530
|
return json({ repo, added: cards.map((c) => ({ id: c.id, title: c.title, why: c.why })), dropped });
|
|
1473
1531
|
return console.log(suggestText(repo, cards, dropped));
|
|
1474
1532
|
}
|
|
1533
|
+
case 'approvals': {
|
|
1534
|
+
// Which suggestions you approve: the rate per kind of card, from approvals, drops and expiries.
|
|
1535
|
+
const board = loadBoard();
|
|
1536
|
+
const ds = decisions(board, loadArchive());
|
|
1537
|
+
const stats = featureStats(ds);
|
|
1538
|
+
if (values.json)
|
|
1539
|
+
return json({ decisions: ds.length, features: stats });
|
|
1540
|
+
return console.log(approvalsText(stats, ds.length));
|
|
1541
|
+
}
|
|
1475
1542
|
case 'hook': {
|
|
1476
1543
|
// Claude Code's UserPromptSubmit hook. Must never fail loudly or stop a prompt by accident.
|
|
1477
1544
|
if (args[0] !== 'prompt')
|
package/dist/costs.js
CHANGED
|
@@ -86,13 +86,51 @@ export function costRange(card, runs) {
|
|
|
86
86
|
basis,
|
|
87
87
|
};
|
|
88
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
|
+
}
|
|
89
126
|
const fmtPct = (n) => (n < 10 ? String(Math.round(n * 10) / 10) : String(Math.round(n)));
|
|
90
|
-
export function formatCostRange(r) {
|
|
127
|
+
export function formatCostRange(r, hit = null) {
|
|
91
128
|
if (!r)
|
|
92
129
|
return 'Cost: not known yet (needs 2 past runs)';
|
|
130
|
+
const right = hitLine(hit);
|
|
93
131
|
const pct = r.low === r.high ? `~${fmtPct(r.low)}%` : `${fmtPct(r.low)}–${fmtPct(r.high)}%`;
|
|
94
132
|
const dur = r.durationLowMs === r.durationHighMs ? formatDuration(r.durationLowMs) : `${formatDuration(r.durationLowMs)}–${formatDuration(r.durationHighMs)}`;
|
|
95
|
-
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}.` : ''}`;
|
|
96
134
|
}
|
|
97
135
|
export function periodStats(runs, signals, from, to) {
|
|
98
136
|
const inRange = (at) => {
|
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
|
-
|
|
131
|
+
st = statSync(file);
|
|
132
|
+
if (st.mtimeMs < since)
|
|
130
133
|
continue;
|
|
131
134
|
}
|
|
132
135
|
catch {
|
|
133
136
|
continue;
|
|
134
137
|
}
|
|
135
|
-
|
|
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
|
|
545
|
-
const
|
|
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
|
-
|
|
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/nightcap.js
CHANGED
|
@@ -27,9 +27,19 @@ export function nextBedtime(now, bedtime, windowMin) {
|
|
|
27
27
|
}
|
|
28
28
|
return { inMin, key: `bedtime:${dayKey(day)}` };
|
|
29
29
|
}
|
|
30
|
-
/** A
|
|
31
|
-
export
|
|
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) {
|
|
32
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
|
+
}
|
|
33
43
|
const late = minutes >= 23 * 60 || minutes < OFFER_UNTIL;
|
|
34
44
|
if (!late)
|
|
35
45
|
return DEFAULT_BEDTIME;
|
|
@@ -56,5 +66,7 @@ export function nightcap(i) {
|
|
|
56
66
|
const key = `nightcap-offer:${dayKey(evening)}`;
|
|
57
67
|
if (i.fired.includes(key))
|
|
58
68
|
return null; // "Not tonight"
|
|
59
|
-
|
|
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 } : {}) };
|
|
60
72
|
}
|
package/dist/nudge.js
CHANGED
|
@@ -324,6 +324,27 @@ export function coldWarningText(d) {
|
|
|
324
324
|
body: `After ${at} its cache expires and coming back rewrites all ${k(d.context)}. Done with it? Do nothing.`,
|
|
325
325
|
};
|
|
326
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
|
+
}
|
|
327
348
|
/**
|
|
328
349
|
* Read each stopped conversation after the stop: sent anyway, carried on small (compacted), or left. A stop that
|
|
329
350
|
* came after a compaction (Claude Code's own, while you were away) had nothing at stake: it isn't counted.
|
|
@@ -337,11 +358,9 @@ export function outcomes(events = loadNudges()) {
|
|
|
337
358
|
let after = null;
|
|
338
359
|
let compacted = null;
|
|
339
360
|
try {
|
|
340
|
-
for (const
|
|
341
|
-
const c = compactionOf(line);
|
|
361
|
+
for (const { c, r } of transcriptMarks(event.transcript)) {
|
|
342
362
|
if (c && !compacted && c.at > at - event.idleMs && c.at < until)
|
|
343
363
|
compacted = c;
|
|
344
|
-
const r = replyOf(line);
|
|
345
364
|
if (r && r.at > at && r.at < until) {
|
|
346
365
|
after = r;
|
|
347
366
|
break;
|
|
@@ -369,11 +388,9 @@ export function warnOutcomes(events = loadNudges()) {
|
|
|
369
388
|
let next = null;
|
|
370
389
|
let compacted = null;
|
|
371
390
|
try {
|
|
372
|
-
for (const
|
|
373
|
-
const c = compactionOf(line);
|
|
391
|
+
for (const { c, r } of transcriptMarks(event.transcript)) {
|
|
374
392
|
if (c && !compacted && c.at > at && c.at < coldAt)
|
|
375
393
|
compacted = c;
|
|
376
|
-
const r = replyOf(line);
|
|
377
394
|
if (r && r.at > at) {
|
|
378
395
|
next = r;
|
|
379
396
|
break;
|
|
@@ -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
|
+
}
|
package/dist/savings.js
ADDED
|
@@ -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/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
|
|
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
|
-
/**
|
|
157
|
-
|
|
158
|
-
|
|
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 =
|
|
172
|
+
c.why = card.why + (reason ? ` · ${reason}` : '');
|
|
163
173
|
return c;
|
|
164
174
|
});
|
|
165
175
|
}
|
|
@@ -3114,6 +3114,8 @@ export function cachedCallToApiCall(call) {
|
|
|
3114
3114
|
deduplicationKey: call.deduplicationKey,
|
|
3115
3115
|
cacheCreationOneHourTokens: u.cacheCreationOneHourTokens || undefined,
|
|
3116
3116
|
toolSequence: call.toolSequence,
|
|
3117
|
+
// Chompyy patch: carry the cached tool-error count back (upstream caches it but drops it on read).
|
|
3118
|
+
...(call.toolErrors ? { toolErrors: call.toolErrors } : {}),
|
|
3117
3119
|
activeDurationMs: call.activeDurationMs,
|
|
3118
3120
|
activeGeneratedTokens: call.activeGeneratedTokens,
|
|
3119
3121
|
toolWaitMs: call.toolWaitMs,
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
// codeburn's own waste checks (src/vendor/codeburn/src/optimize.ts, `codeburn optimize`): about 25 detectors for
|
|
2
|
+
// re-reads, build-folder reads, low cache hit, bloated context, the long-context price, noisy shell output, pasted
|
|
3
|
+
// context repeated in every chat, unused MCP servers and more. We run them as they are and translate each finding
|
|
4
|
+
// into Chompyy's shape, so `chompyy detect` shows ours and theirs in one ranked list. No parser of our own.
|
|
5
|
+
import { loadAgents, prepareCodeburn } from './agentusage.js';
|
|
6
|
+
import { findingBasis, findingClass, scanAndDetect } from './vendor/codeburn/src/optimize.js';
|
|
7
|
+
import { parseAllSessions } from './vendor/codeburn/src/parser.js';
|
|
8
|
+
/** Our rulebook rule (research/detective/RULEBOOK.md) for each codeburn finding id; `CB` when the rulebook has none. */
|
|
9
|
+
export const RULE_FOR = {
|
|
10
|
+
'redundant-rereads': 'R1',
|
|
11
|
+
'build-folder-reads': 'R2',
|
|
12
|
+
'read-edit-ratio': 'R1',
|
|
13
|
+
'warmup-heavy': 'S1',
|
|
14
|
+
'unused-mcp': 'S4',
|
|
15
|
+
'mcp-low-coverage': 'S4',
|
|
16
|
+
'mcp-project-scope': 'S4',
|
|
17
|
+
'mcp-deferral-off': 'S4',
|
|
18
|
+
'mcp-alwaysload-hygiene': 'S4',
|
|
19
|
+
'mcp-defer-threshold': 'S4',
|
|
20
|
+
'retry-heavy-capabilities': 'L1',
|
|
21
|
+
'low-worth-sessions': 'X3',
|
|
22
|
+
'context-heavy-sessions': 'X3',
|
|
23
|
+
'cost-outliers': 'X3',
|
|
24
|
+
'low-cache-hit-sessions': 'C4',
|
|
25
|
+
'one-hour-cache-unused': 'C4',
|
|
26
|
+
'claude-md-too-long': 'S2',
|
|
27
|
+
'bash-output-cap': 'O1',
|
|
28
|
+
'unused-agents': 'S3',
|
|
29
|
+
'unused-skills': 'S3',
|
|
30
|
+
'unused-commands': 'S3',
|
|
31
|
+
'recurring-context': 'L4',
|
|
32
|
+
'fast-mode-background': 'X2',
|
|
33
|
+
'long-context-premium': 'X2',
|
|
34
|
+
'idle-compaction-blocked': 'X1',
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Checks we already run ourselves, with our own measured numbers: skip codeburn's version so a waste isn't listed
|
|
38
|
+
* twice. (CLAUDE.md length S2, unused skills S3, unused MCP S4.)
|
|
39
|
+
*/
|
|
40
|
+
const OURS = new Set(['claude-md-too-long', 'unused-skills', 'unused-mcp']);
|
|
41
|
+
const LANE = { fix: 'settings', nudge: 'habit', keep: 'habit' };
|
|
42
|
+
/** One codeburn finding in Chompyy's shape. The first sentence of codeburn's explanation is what it saw. */
|
|
43
|
+
export function toFinding(w) {
|
|
44
|
+
const cls = findingClass(w);
|
|
45
|
+
return {
|
|
46
|
+
rule: RULE_FOR[w.id] ?? 'CB',
|
|
47
|
+
title: w.title,
|
|
48
|
+
say: w.explanation,
|
|
49
|
+
basis: findingBasis(w),
|
|
50
|
+
...(cls === 'keep' ? { notProve: 'The cost may be worth it: the context or speed may be needed.', worthKnowing: true } : {}),
|
|
51
|
+
fix: w.fix.label.replace(/[:.\s]+$/, '') + (w.fix.type === 'paste' || w.fix.type === 'command' ? `: ${w.fix.text.split('\n')[0]}` : ''),
|
|
52
|
+
lane: LANE[cls],
|
|
53
|
+
tokens: Math.round(w.tokensSaved),
|
|
54
|
+
source: 'codeburn',
|
|
55
|
+
codeburnId: w.id,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** Each session's calls in order, subagent transcripts left out (their errors are the subagent's business). */
|
|
59
|
+
function sessionCalls(projects) {
|
|
60
|
+
const out = [];
|
|
61
|
+
for (const p of projects) {
|
|
62
|
+
for (const s of p.sessions) {
|
|
63
|
+
if (s.isSidechain)
|
|
64
|
+
continue;
|
|
65
|
+
const calls = s.turns.flatMap((t) => t.assistantCalls).sort((a, b) => a.timestamp.localeCompare(b.timestamp));
|
|
66
|
+
if (calls.length)
|
|
67
|
+
out.push(calls);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
/** New tokens a call sent: fresh input, cache writes and output (cache reads would have been read anyway). */
|
|
73
|
+
const fresh = (c) => c.usage.inputTokens + c.usage.cacheCreationInputTokens + c.usage.outputTokens;
|
|
74
|
+
/** The context the call carried. */
|
|
75
|
+
const context = (c) => c.usage.inputTokens + c.usage.cacheReadInputTokens + c.usage.cacheCreationInputTokens;
|
|
76
|
+
const TOOL_TIP = {
|
|
77
|
+
Edit: 'Read a file before editing it: most failed edits are stale or whitespace-mismatched old text.',
|
|
78
|
+
Write: 'Read a file before overwriting it.',
|
|
79
|
+
NotebookEdit: 'Read the notebook first to get the cell ids right.',
|
|
80
|
+
};
|
|
81
|
+
/** L1 · Tool errors: the request after a failed tool call is the cost of recovering from it, by tool. */
|
|
82
|
+
export function ruleToolErrors(projects) {
|
|
83
|
+
const by = new Map();
|
|
84
|
+
const shell = new Map();
|
|
85
|
+
for (const calls of sessionCalls(projects)) {
|
|
86
|
+
for (let i = 0; i < calls.length - 1; i++) {
|
|
87
|
+
const c = calls[i];
|
|
88
|
+
if (!c.toolErrors || !c.tools.length)
|
|
89
|
+
continue;
|
|
90
|
+
const share = fresh(calls[i + 1]) / c.tools.length;
|
|
91
|
+
for (const cmd of c.bashCommands ?? []) {
|
|
92
|
+
const word = cmd.trim().split(/\s+/)[0];
|
|
93
|
+
if (word)
|
|
94
|
+
shell.set(word, (shell.get(word) ?? 0) + 1);
|
|
95
|
+
}
|
|
96
|
+
for (const t of c.tools) {
|
|
97
|
+
const e = by.get(t) ?? { tokens: 0, fails: 0 };
|
|
98
|
+
e.tokens += share;
|
|
99
|
+
e.fails += 1;
|
|
100
|
+
by.set(t, e);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const ranked = [...by].filter(([, e]) => e.fails >= 5).sort((a, b) => b[1].tokens - a[1].tokens);
|
|
105
|
+
if (!ranked.length)
|
|
106
|
+
return [];
|
|
107
|
+
const total = ranked.reduce((a, [, e]) => a + e.tokens, 0);
|
|
108
|
+
const [top, e] = ranked[0];
|
|
109
|
+
return [{
|
|
110
|
+
rule: 'L1',
|
|
111
|
+
key: 'L1:errors',
|
|
112
|
+
title: 'Recovering from failed tool calls',
|
|
113
|
+
say: `${ranked.reduce((a, [, x]) => a + x.fails, 0)} failed tool calls; the request after each one sent ~${Math.round(total / 1000)}k new tokens in all. ${top} failed most (${e.fails} times).`,
|
|
114
|
+
basis: 'estimated',
|
|
115
|
+
notProve: 'Some failures are cheap tries that find the answer faster.',
|
|
116
|
+
fix: top === 'Bash' && shell.size
|
|
117
|
+
? `Look at why \`${[...shell].sort((a, b) => b[1] - a[1])[0][0]}\` fails most (a blocked path, a missing tool, a wrong folder) and put the fix in CLAUDE.md.`
|
|
118
|
+
: TOOL_TIP[top] ?? `Look at what ${top} gets wrong in the failing calls: most failures are in the input.`,
|
|
119
|
+
lane: 'habit',
|
|
120
|
+
tokens: Math.round(total),
|
|
121
|
+
tokensHow: 'the request after each failure',
|
|
122
|
+
}];
|
|
123
|
+
}
|
|
124
|
+
const BUCKETS = [[0, 50_000, '50k'], [50_000, 100_000, '100k'], [100_000, 150_000, '150k'], [150_000, 200_000, '200k'], [200_000, Infinity, '200k+']];
|
|
125
|
+
/** X1 · Context decay: tool calls start failing more once a conversation passes a size. Shows the size, not tokens. */
|
|
126
|
+
export function ruleContextDecay(projects) {
|
|
127
|
+
const total = BUCKETS.map(() => 0);
|
|
128
|
+
const failed = BUCKETS.map(() => 0);
|
|
129
|
+
for (const calls of sessionCalls(projects)) {
|
|
130
|
+
for (const c of calls) {
|
|
131
|
+
if (!c.tools.length)
|
|
132
|
+
continue;
|
|
133
|
+
const i = BUCKETS.findIndex(([lo, hi]) => context(c) >= lo && context(c) < hi);
|
|
134
|
+
total[i] += 1;
|
|
135
|
+
if (c.toolErrors)
|
|
136
|
+
failed[i] += 1;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const ok = total.map((n, i) => (n >= 30 ? 1 - failed[i] / n : null));
|
|
140
|
+
let best = -1;
|
|
141
|
+
for (let i = 0; i < ok.length; i++) {
|
|
142
|
+
const r = ok[i];
|
|
143
|
+
if (r == null)
|
|
144
|
+
continue;
|
|
145
|
+
if (best >= 0 && ok[best] - r > 0.15) {
|
|
146
|
+
const past = i === 0 ? '0' : BUCKETS[i - 1][2];
|
|
147
|
+
return [{
|
|
148
|
+
rule: 'X1',
|
|
149
|
+
title: `Tool calls fail more past ${past} tokens of context`,
|
|
150
|
+
say: `Tool calls succeed ${Math.round(ok[best] * 100)}% of the time in smaller conversations, ${Math.round(r * 100)}% past ${past} (${total[i]} calls).`,
|
|
151
|
+
basis: 'measured',
|
|
152
|
+
notProve: 'Bigger conversations may also be harder tasks.',
|
|
153
|
+
fix: `Start fresh or /compact before a conversation passes ${past} tokens.`,
|
|
154
|
+
lane: 'habit',
|
|
155
|
+
}];
|
|
156
|
+
}
|
|
157
|
+
if (best < 0 || r > ok[best])
|
|
158
|
+
best = i;
|
|
159
|
+
}
|
|
160
|
+
return [];
|
|
161
|
+
}
|
|
162
|
+
const same = (a, b) => a.tool === b.tool && a.file === b.file && a.command === b.command;
|
|
163
|
+
/** L1 · Retry loops: the same tool with the same file or command three times in a row. */
|
|
164
|
+
export function ruleRetryLoops(projects) {
|
|
165
|
+
let loops = 0;
|
|
166
|
+
let sessions = 0;
|
|
167
|
+
let tokens = 0;
|
|
168
|
+
for (const calls of sessionCalls(projects)) {
|
|
169
|
+
const seq = calls.flatMap((c) => (c.toolSequence ?? []).flat().map((t) => ({ ...t, call: c })));
|
|
170
|
+
let found = 0;
|
|
171
|
+
for (let i = 2; i < seq.length; i++) {
|
|
172
|
+
const [a, b, c] = [seq[i - 2], seq[i - 1], seq[i]];
|
|
173
|
+
if (!(a.file || a.command) || !same(a, b) || !same(b, c))
|
|
174
|
+
continue;
|
|
175
|
+
found += 1;
|
|
176
|
+
tokens += fresh(c.call);
|
|
177
|
+
i += 2;
|
|
178
|
+
}
|
|
179
|
+
if (found) {
|
|
180
|
+
loops += found;
|
|
181
|
+
sessions += 1;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (loops < 3)
|
|
185
|
+
return [];
|
|
186
|
+
return [{
|
|
187
|
+
rule: 'L1',
|
|
188
|
+
key: 'L1:loops',
|
|
189
|
+
title: 'The same call three times in a row',
|
|
190
|
+
say: `${loops} times in ${sessions} sessions Claude ran the same tool on the same file or command three times running.`,
|
|
191
|
+
basis: 'estimated',
|
|
192
|
+
notProve: 'Some repeats are on purpose: re-running a test after each fix.',
|
|
193
|
+
fix: 'When Claude repeats a call, stop it and say what changed or what to try instead.',
|
|
194
|
+
lane: 'habit',
|
|
195
|
+
tokens,
|
|
196
|
+
tokensHow: 'the third call of each run',
|
|
197
|
+
}];
|
|
198
|
+
}
|
|
199
|
+
/** codeburn's checks over the last `days` days of Claude Code sessions. Empty (never throws) when its reader fails. */
|
|
200
|
+
export async function wasteChecks(opts = {}) {
|
|
201
|
+
try {
|
|
202
|
+
await prepareCodeburn();
|
|
203
|
+
const end = opts.now ?? new Date();
|
|
204
|
+
const range = { start: new Date(end.getTime() - (opts.days ?? 30) * 86_400_000), end };
|
|
205
|
+
const provider = opts.provider ?? 'claude';
|
|
206
|
+
const projects = await parseAllSessions(range, provider);
|
|
207
|
+
const { findings } = await scanAndDetect(projects, range, provider);
|
|
208
|
+
return [
|
|
209
|
+
...findings.filter((w) => !OURS.has(w.id) && w.tokensSaved > 0).map(toFinding),
|
|
210
|
+
...ruleToolErrors(projects),
|
|
211
|
+
...ruleContextDecay(projects),
|
|
212
|
+
...ruleRetryLoops(projects),
|
|
213
|
+
];
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
return [];
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* The same checks for the other agents you used this month (most tokens first, up to 3), from codeburn's readers.
|
|
221
|
+
* codeburn runs only the checks that mean something outside Claude Code (heavy sessions, cache hit, long-context
|
|
222
|
+
* price, …). Each finding is tagged with its agent and named in its title, e.g. "Codex: 2 context-heavy sessions".
|
|
223
|
+
*/
|
|
224
|
+
export async function otherAgentChecks(opts = {}) {
|
|
225
|
+
const agents = (loadAgents()?.agents ?? []).filter((a) => a.month.tokens > 0).slice(0, 3);
|
|
226
|
+
const out = [];
|
|
227
|
+
for (const a of agents) {
|
|
228
|
+
for (const f of await wasteChecks({ ...opts, provider: a.name })) {
|
|
229
|
+
out.push({ ...f, agent: a.name, title: `${a.displayName}: ${f.title.charAt(0).toLowerCase()}${f.title.slice(1)}`, ...(f.key ? { key: `${a.name}:${f.key}` } : {}), ...(f.codeburnId ? { codeburnId: `${a.name}:${f.codeburnId}` } : {}) });
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return out;
|
|
233
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chompyy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Chompyy: runs the tasks you approve with the Claude Code 5-hour window you'd otherwise lose, then lets you review, keep and send them to GitHub. CLI behind the Chompyy Mac menu bar app.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude-code",
|