chompyy 0.4.0 → 0.4.2
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 +7 -0
- package/dist/advice.js +383 -0
- package/dist/away.js +4 -1
- package/dist/blueprint.js +45 -0
- package/dist/board.js +61 -2
- package/dist/cli.js +138 -5
- package/dist/detect.js +568 -0
- package/dist/didwork.js +367 -0
- package/dist/nudge.js +438 -0
- package/dist/pacing.js +5 -0
- package/dist/premise.js +122 -0
- package/package.json +1 -1
package/dist/didwork.js
ADDED
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
// The detective, step 5: "did it work?" (research/detective/RULEBOOK.md §10). Every Advice card registered its
|
|
2
|
+
// check before it was applied (rule 7); this measures each one against it, from your own local files.
|
|
3
|
+
//
|
|
4
|
+
// The rules it keeps (M1–M3):
|
|
5
|
+
// - Name the method, strongest first: a re-count of the thing that changed (deterministic), else before vs
|
|
6
|
+
// after (can't separate the fix from anything else that week, and says so). Never added across methods.
|
|
7
|
+
// - A saving is signed: a regression shows as a regression, never as zero and never as a saving.
|
|
8
|
+
// - "Worked" means at least 70% of the promised saving; habits wait the two weeks their card names.
|
|
9
|
+
// - Provenance: a settings change is re-read each time. If something changed it since, the saving is not claimed.
|
|
10
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
11
|
+
import { homedir } from 'node:os';
|
|
12
|
+
import { dirname } from 'node:path';
|
|
13
|
+
import { coldReturns, configuredMcp, installedSkills, ruleS4, ruleS5, scan, tokensOf } from './detect.js';
|
|
14
|
+
import { projectsDir } from './dream.js';
|
|
15
|
+
import { learnedQuiet, loadNudges, loadPrefs, nudgeOnSince, outcomes, QUIET_AFTER, warnOutcomes } from './nudge.js';
|
|
16
|
+
const DAY = 86_400_000;
|
|
17
|
+
/** Habits: the window their card names ("two weeks on"). */
|
|
18
|
+
export const HABIT_DAYS = 14;
|
|
19
|
+
/** "Worked" = at least this share of the promised saving (codeburn `act`). */
|
|
20
|
+
export const WORKED_SHARE = 0.7;
|
|
21
|
+
/** Before/after on session starts: wait this long and for this many sessions. */
|
|
22
|
+
const MIN_DAYS = 3;
|
|
23
|
+
const MIN_SESSIONS = 5;
|
|
24
|
+
const k = (n) => {
|
|
25
|
+
const a = Math.abs(n);
|
|
26
|
+
const s = a >= 1e6 ? `${(a / 1e6).toFixed(1)}M` : a >= 1000 ? `${(a / 1000).toFixed(a >= 10_000 ? 0 : 1)}k` : `${Math.round(a)}`;
|
|
27
|
+
return n < 0 ? `-${s}` : s;
|
|
28
|
+
};
|
|
29
|
+
const day = (ms) => new Date(ms).toLocaleDateString('en-US', { month: 'short', day: 'numeric' });
|
|
30
|
+
const median = (xs) => {
|
|
31
|
+
const s = [...xs].sort((a, b) => a - b);
|
|
32
|
+
return s.length ? (s.length % 2 ? s[(s.length - 1) / 2] : (s[s.length / 2 - 1] + s[s.length / 2]) / 2) : 0;
|
|
33
|
+
};
|
|
34
|
+
const plural = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
|
|
35
|
+
/** Before → after: which way it went, given the pre-registered bar for "worked". */
|
|
36
|
+
function verdictOf(before, after, worked) {
|
|
37
|
+
if (worked)
|
|
38
|
+
return 'worked';
|
|
39
|
+
if (after < before)
|
|
40
|
+
return 'short';
|
|
41
|
+
if (after === before)
|
|
42
|
+
return 'no-change';
|
|
43
|
+
return 'worse';
|
|
44
|
+
}
|
|
45
|
+
const sessionsIn = (s, from, to) => s.sessions.filter((x) => x.turns[0].at >= from && x.turns[0].at < to);
|
|
46
|
+
// ---------- habits: before vs after, over the two weeks the card names ----------
|
|
47
|
+
/** C1: cold returns in the week before you started vs the second week after (the card: "two weeks on, a week has a third fewer"). */
|
|
48
|
+
export function checkC1(since, now, s) {
|
|
49
|
+
const due = since + HABIT_DAYS * DAY;
|
|
50
|
+
const before = coldReturns(s, since - 7 * DAY).filter((x) => x.at < since);
|
|
51
|
+
const base = { at: new Date(now).toISOString(), method: 'before-after', per: 'week', dueAt: new Date(due).toISOString() };
|
|
52
|
+
if (!before.length)
|
|
53
|
+
return { ...base, verdict: 'cant-tell', line: 'No cold returns in the week before you started, so there is nothing to compare against.' };
|
|
54
|
+
const tokens = (xs) => xs.reduce((a, x) => a + x.tokens, 0);
|
|
55
|
+
if (now < due) {
|
|
56
|
+
const so = coldReturns(s, since);
|
|
57
|
+
const days = Math.max(1, (now - since) / DAY);
|
|
58
|
+
return {
|
|
59
|
+
...base,
|
|
60
|
+
verdict: 'too-early',
|
|
61
|
+
before: before.length,
|
|
62
|
+
after: so.length,
|
|
63
|
+
line: `${plural(so.length, 'cold return')} so far (was ${before.length} a week). Verdict ${day(due)}.`,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
const week = coldReturns(s, since + 7 * DAY).filter((x) => x.at < due);
|
|
67
|
+
const bar = Math.floor((before.length * 2) / 3);
|
|
68
|
+
const verdict = verdictOf(before.length, week.length, week.length <= bar);
|
|
69
|
+
const saved = tokens(before) - tokens(week);
|
|
70
|
+
const nBefore = sessionsIn(s, since - 7 * DAY, since).length;
|
|
71
|
+
const nAfter = sessionsIn(s, since + 7 * DAY, due).length;
|
|
72
|
+
const said = {
|
|
73
|
+
worked: 'it worked',
|
|
74
|
+
short: `fewer, but not the third fewer the card asked for (${bar} or less)`,
|
|
75
|
+
'no-change': 'no change',
|
|
76
|
+
worse: 'more than before',
|
|
77
|
+
}[verdict];
|
|
78
|
+
return {
|
|
79
|
+
...base,
|
|
80
|
+
verdict,
|
|
81
|
+
before: before.length,
|
|
82
|
+
after: week.length,
|
|
83
|
+
saved,
|
|
84
|
+
line: `${said[0].toUpperCase()}${said.slice(1)}: cold returns ${before.length} → ${week.length} a week (${saved >= 0 ? `${k(saved)} fewer` : `${k(-saved)} more`} tokens rewritten).`,
|
|
85
|
+
also: `Sessions: ${nBefore} → ${nAfter}. A quieter week also cuts cold returns.`,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const isRebuild = (t) => t.miss === 'tools_changed' || t.miss === 'messages_changed';
|
|
89
|
+
function rebuilds(s, from, to) {
|
|
90
|
+
let count = 0;
|
|
91
|
+
let tokens = 0;
|
|
92
|
+
for (const ses of s.sessions) {
|
|
93
|
+
for (const t of ses.turns) {
|
|
94
|
+
if (t.at < from || t.at >= to || !isRebuild(t))
|
|
95
|
+
continue;
|
|
96
|
+
count++;
|
|
97
|
+
tokens += t.missedTokens ?? t.cacheWrite;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return { count, tokens };
|
|
101
|
+
}
|
|
102
|
+
/** C2: mid-session rebuilds, two weeks before vs two weeks after (the card: "it worked if there are none"). */
|
|
103
|
+
export function checkC2(since, now, s) {
|
|
104
|
+
const due = since + HABIT_DAYS * DAY;
|
|
105
|
+
const before = rebuilds(s, since - HABIT_DAYS * DAY, since);
|
|
106
|
+
const after = rebuilds(s, since, Math.min(now, due));
|
|
107
|
+
const base = { at: new Date(now).toISOString(), method: 'before-after', per: 'two weeks', dueAt: new Date(due).toISOString(), before: before.count, after: after.count };
|
|
108
|
+
if (!before.count)
|
|
109
|
+
return { ...base, verdict: 'cant-tell', line: `Nothing to improve: no mid-session rebuilds before you started${after.count ? `, ${after.count} since` : ''}.` };
|
|
110
|
+
if (now < due) {
|
|
111
|
+
return { ...base, verdict: 'too-early', line: `${plural(after.count, 'mid-session rebuild')} so far (was ${before.count}). Verdict ${day(due)}.` };
|
|
112
|
+
}
|
|
113
|
+
const verdict = verdictOf(before.count, after.count, after.count === 0);
|
|
114
|
+
const saved = before.tokens - after.tokens;
|
|
115
|
+
return {
|
|
116
|
+
...base,
|
|
117
|
+
verdict,
|
|
118
|
+
saved,
|
|
119
|
+
line: `${verdict === 'worked' ? 'It worked' : verdict === 'worse' ? 'More than before' : 'Not zero yet'}: mid-session rebuilds ${before.count} → ${after.count} in two weeks (${saved >= 0 ? `${k(saved)} fewer` : `${k(-saved)} more`} tokens).`,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
// ---------- settings and setup: re-count what changed ----------
|
|
123
|
+
function readJson(file) {
|
|
124
|
+
try {
|
|
125
|
+
return JSON.parse(readFileSync(file, 'utf8'));
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function valueAt(obj, key) {
|
|
132
|
+
let cur = obj;
|
|
133
|
+
for (const p of key)
|
|
134
|
+
cur = cur && typeof cur === 'object' ? cur[p] : undefined;
|
|
135
|
+
return cur;
|
|
136
|
+
}
|
|
137
|
+
/** M1: is every value still what Chompyy set? The first one that isn't, for the sentence. */
|
|
138
|
+
export function provenance(changes) {
|
|
139
|
+
for (const c of changes) {
|
|
140
|
+
if (!existsSync(c.file))
|
|
141
|
+
return { state: 'missing', what: `${c.file.replace(homedir(), '~')} is gone` };
|
|
142
|
+
const json = readJson(c.file);
|
|
143
|
+
const now = json ? valueAt(json, c.key) : undefined;
|
|
144
|
+
if (JSON.stringify(now) !== JSON.stringify(c.to))
|
|
145
|
+
return { state: 'changed', what: `${c.key.at(-1)} is ${JSON.stringify(now ?? '(not set)')} again, not ${JSON.stringify(c.to)}` };
|
|
146
|
+
}
|
|
147
|
+
return { state: 'intact' };
|
|
148
|
+
}
|
|
149
|
+
/** Median first turn (what a session start costs), sessions started in [from, to). */
|
|
150
|
+
const startCost = (s, from, to) => {
|
|
151
|
+
const xs = sessionsIn(s, from, to).map((x) => x.turns[0].cacheRead + x.turns[0].cacheWrite).filter((n) => n > 0);
|
|
152
|
+
return { n: xs.length, median: median(xs) };
|
|
153
|
+
};
|
|
154
|
+
/** S3, a plugin turned off: re-count the plugin's skills that still load at a session start. */
|
|
155
|
+
export function checkPlugin(a, since, now, s) {
|
|
156
|
+
const at = new Date(now).toISOString();
|
|
157
|
+
const changes = a.changes ?? [];
|
|
158
|
+
const id = changes[0]?.key.at(-1) ?? '';
|
|
159
|
+
// Cards made before `baseline` existed: the promise is on the card's chart (Now − After).
|
|
160
|
+
const bars = a.chart?.bars;
|
|
161
|
+
// Older still: the promise is in the check text ("start about 965 tokens smaller", "~2.1k tokens smaller").
|
|
162
|
+
const said = a.check.match(/~?([\d.]+)(k?) tokens smaller/);
|
|
163
|
+
const fromText = said ? Math.round(Number(said[1]) * (said[2] ? 1000 : 1)) : 0;
|
|
164
|
+
const promised = a.baseline?.perStart ?? (bars?.length === 2 ? bars[0].value - bars[1].value : fromText);
|
|
165
|
+
const p = provenance(changes);
|
|
166
|
+
if (p.state !== 'intact') {
|
|
167
|
+
return { at, verdict: 'cant-tell', method: 'recount', provenance: p.state, line: `Not claimed: ${p.what}, so the plugin loads again.` };
|
|
168
|
+
}
|
|
169
|
+
const claudeDir = dirname(changes[0].file);
|
|
170
|
+
const still = installedSkills(claudeDir).filter((x) => x.plugin === id).reduce((n, x) => n + x.descriptionTokens, 0);
|
|
171
|
+
const saved = promised - still;
|
|
172
|
+
const worked = promised > 0 && saved >= WORKED_SHARE * promised;
|
|
173
|
+
const r = {
|
|
174
|
+
at,
|
|
175
|
+
verdict: promised ? verdictOf(promised, still, worked) : 'cant-tell',
|
|
176
|
+
method: 'recount',
|
|
177
|
+
provenance: 'intact',
|
|
178
|
+
before: promised,
|
|
179
|
+
after: still,
|
|
180
|
+
saved,
|
|
181
|
+
per: 'session start',
|
|
182
|
+
line: promised
|
|
183
|
+
? `${worked ? 'It worked' : 'Not yet'}: each session start ~${k(promised)} → ~${k(still)} tokens (re-counted).`
|
|
184
|
+
: `Its skills add ~${k(still)} tokens to a session start. No baseline, so no verdict.`,
|
|
185
|
+
};
|
|
186
|
+
// The weaker method, beside it: whole session starts before vs after (moves with which projects you worked in).
|
|
187
|
+
if (s && now - since >= MIN_DAYS * DAY) {
|
|
188
|
+
const b = startCost(s, since - HABIT_DAYS * DAY, since);
|
|
189
|
+
const n = startCost(s, since, now);
|
|
190
|
+
if (b.n >= MIN_SESSIONS && n.n >= MIN_SESSIONS) {
|
|
191
|
+
const d = b.median - n.median;
|
|
192
|
+
r.also = `Whole session starts: ${(b.median / 1000).toFixed(1)}k → ${(n.median / 1000).toFixed(1)}k (${d >= 0 ? `${Math.round(d)} smaller` : `${Math.round(-d)} bigger`}; moves with your projects too).`;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return r;
|
|
196
|
+
}
|
|
197
|
+
/** S3, skills only you can turn off (synced from claude.ai, or your own): which of them still load. */
|
|
198
|
+
export function checkSkillsGone(a, now, claudeDir, plan) {
|
|
199
|
+
const at = new Date(now).toISOString();
|
|
200
|
+
// Cards made before `baseline` existed: the names are in the card's own instructions.
|
|
201
|
+
const listed = plan?.match(/(?:the ones you don't use|~\/\.claude\/skills[^:]*): ([^\n]+?)\.(?: Then press|$)/m)?.[1];
|
|
202
|
+
const names = a.baseline?.names ?? listed?.split(', ').map((x) => x.trim()).filter(Boolean) ?? [];
|
|
203
|
+
if (!names.length)
|
|
204
|
+
return { at, verdict: 'cant-tell', method: 'recount', line: "The card didn't record which skills, so there is nothing to re-count." };
|
|
205
|
+
const loaded = installedSkills(claudeDir);
|
|
206
|
+
const left = names.filter((n) => loaded.some((x) => x.name === n && x.source !== 'plugin'));
|
|
207
|
+
const gone = names.length - left.length;
|
|
208
|
+
const tokens = loaded.filter((x) => left.includes(x.name) && x.source !== 'plugin').reduce((n, x) => n + x.descriptionTokens, 0);
|
|
209
|
+
const worked = gone >= WORKED_SHARE * names.length;
|
|
210
|
+
return {
|
|
211
|
+
at,
|
|
212
|
+
verdict: verdictOf(names.length, left.length, worked),
|
|
213
|
+
method: 'recount',
|
|
214
|
+
before: names.length,
|
|
215
|
+
after: left.length,
|
|
216
|
+
line: left.length
|
|
217
|
+
? `${worked ? 'It worked' : 'Not yet'}: ${left.length} of ${names.length} still load (~${k(tokens)} tokens a session): ${left.slice(0, 5).join(', ')}${left.length > 5 ? ', …' : ''}.`
|
|
218
|
+
: `It worked: none of the ${names.length} skills load any more.`,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
/** S2: re-measure the CLAUDE.md (the card: "under 200 lines and ~2k tokens"). */
|
|
222
|
+
export function checkClaudeMd(a, now) {
|
|
223
|
+
const at = new Date(now).toISOString();
|
|
224
|
+
const file = a.key.slice('S2:'.length);
|
|
225
|
+
if (!existsSync(file))
|
|
226
|
+
return { at, verdict: 'cant-tell', method: 'recount', provenance: 'missing', line: `${file.replace(homedir(), '~')} is gone, so there is nothing to re-count.` };
|
|
227
|
+
const text = readFileSync(file, 'utf8');
|
|
228
|
+
const lines = text.split('\n').length;
|
|
229
|
+
const tokens = tokensOf(text);
|
|
230
|
+
const before = a.baseline?.tokens;
|
|
231
|
+
const worked = lines <= 200 && tokens <= 2000;
|
|
232
|
+
const saved = before === undefined ? undefined : before - tokens;
|
|
233
|
+
return {
|
|
234
|
+
at,
|
|
235
|
+
verdict: before === undefined ? (worked ? 'worked' : 'short') : verdictOf(before, tokens, worked),
|
|
236
|
+
method: 'recount',
|
|
237
|
+
...(before === undefined ? {} : { before, saved }),
|
|
238
|
+
after: tokens,
|
|
239
|
+
per: 'session start there',
|
|
240
|
+
line: `${worked ? 'It worked' : 'Still too long'}: ${a.baseline?.lines ? `${a.baseline.lines} → ` : ''}${lines} lines, ${before === undefined ? '' : `~${k(before)} → `}~${k(tokens)} tokens.`,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
/** S4 and S5: run the same rule again; it worked if the finding is gone (what the card registered). */
|
|
244
|
+
export function checkRuleAgain(a, now, s, root) {
|
|
245
|
+
const at = new Date(now).toISOString();
|
|
246
|
+
const subject = (say) => say.split(' ')[0];
|
|
247
|
+
if (a.rule === 'S5') {
|
|
248
|
+
const file = subject(a.key.slice(3));
|
|
249
|
+
const still = ruleS5(root).find((f) => subject(f.say) === file);
|
|
250
|
+
return { at, verdict: still ? 'no-change' : 'worked', method: 'recount', line: still ? `Re-checked: ${still.say}` : `Re-checked: ${file} now fits in what Claude Code loads: it worked.` };
|
|
251
|
+
}
|
|
252
|
+
const still = ruleS4(s, configuredMcp(s.sessions.map((x) => x.cwd).filter(Boolean)));
|
|
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
|
+
}
|
|
255
|
+
// ---------- all cards ----------
|
|
256
|
+
/** The cards with something to measure: applied, being tried, or done (by you, or kept from an away run). */
|
|
257
|
+
export function measurable(c) {
|
|
258
|
+
const a = c.advice;
|
|
259
|
+
if (!a)
|
|
260
|
+
return false;
|
|
261
|
+
if (a.lane === 'work')
|
|
262
|
+
return c.column === 'done' && c.outcome === 'kept';
|
|
263
|
+
return a.state === 'applied' || a.state === 'trying' || a.state === 'done';
|
|
264
|
+
}
|
|
265
|
+
/** When the clock started: when it was applied, approved, or kept. */
|
|
266
|
+
const startOf = (c) => Date.parse(c.advice.since ?? c.approvedAt ?? c.updatedAt) || 0;
|
|
267
|
+
/** A habit's verdict, once due, is final (the transcripts behind it get cleaned up later). Re-counts run every time. */
|
|
268
|
+
const settled = (r) => Boolean(r && r.method === 'before-after' && r.verdict !== 'too-early');
|
|
269
|
+
/** Measure every applied/tried/done advice card and write the result on it. Returns the cards measured. */
|
|
270
|
+
export function checkWorked(board, now, opts = {}) {
|
|
271
|
+
const cards = board.cards.filter(measurable);
|
|
272
|
+
if (!cards.length)
|
|
273
|
+
return [];
|
|
274
|
+
const t = now.getTime();
|
|
275
|
+
// One scan covering the earliest card's "before" window.
|
|
276
|
+
const earliest = Math.min(...cards.map(startOf));
|
|
277
|
+
const needsScan = cards.some((c) => ['C1', 'C2', 'S3', 'S4'].includes(c.advice.rule) && !settled(c.advice.result));
|
|
278
|
+
const days = Math.ceil((t - earliest) / DAY) + HABIT_DAYS + 1;
|
|
279
|
+
const root = opts.root ?? projectsDir();
|
|
280
|
+
const s = needsScan ? scan({ days: Math.max(30, days), now, root }) : null;
|
|
281
|
+
for (const c of cards) {
|
|
282
|
+
const a = c.advice;
|
|
283
|
+
if (settled(a.result))
|
|
284
|
+
continue;
|
|
285
|
+
const since = startOf(c);
|
|
286
|
+
if (a.rule === 'C1')
|
|
287
|
+
a.result = checkC1(since, t, s);
|
|
288
|
+
else if (a.rule === 'C2')
|
|
289
|
+
a.result = checkC2(since, t, s);
|
|
290
|
+
else if (a.rule === 'S3' && a.lane === 'settings')
|
|
291
|
+
a.result = checkPlugin(a, since, t, s);
|
|
292
|
+
else if (a.rule === 'S3')
|
|
293
|
+
a.result = checkSkillsGone(a, t, opts.claudeDir, c.blueprint);
|
|
294
|
+
else if (a.rule === 'S2')
|
|
295
|
+
a.result = checkClaudeMd(a, t);
|
|
296
|
+
else if (a.rule === 'S4' || a.rule === 'S5')
|
|
297
|
+
a.result = checkRuleAgain(a, t, s ?? scan({ now, root }), root);
|
|
298
|
+
}
|
|
299
|
+
return cards;
|
|
300
|
+
}
|
|
301
|
+
export function nudgeProof(now, opts = {}) {
|
|
302
|
+
const events = opts.events ?? loadNudges();
|
|
303
|
+
const since = nudgeOnSince(events);
|
|
304
|
+
if (!since)
|
|
305
|
+
return null;
|
|
306
|
+
const t = now.getTime();
|
|
307
|
+
const s = opts.s ?? scan({ days: Math.max(30, Math.ceil((t - since) / DAY) + 8), now, root: opts.root ?? projectsDir() });
|
|
308
|
+
const after = (e) => Date.parse(e.at) >= since;
|
|
309
|
+
const stops = outcomes(events).filter((o) => after(o.event));
|
|
310
|
+
const warns = warnOutcomes(events).filter((o) => after(o.event) && o.did === 'compacted');
|
|
311
|
+
const n = (d) => stops.filter((o) => o.did === d).length;
|
|
312
|
+
// Compacting is measured (the next request was small); leaving assumes a fresh start costs what this one's first turn did.
|
|
313
|
+
const measured = [...stops.filter((o) => o.did === 'compacted'), ...warns].reduce((a, o) => a + o.saved, 0);
|
|
314
|
+
const saved = measured + stops.filter((o) => o.did === 'left').reduce((a, o) => a + o.saved, 0);
|
|
315
|
+
const rewritten = stops.filter((o) => o.did === 'sent').reduce((a, o) => a + o.event.context, 0);
|
|
316
|
+
const prefs = loadPrefs();
|
|
317
|
+
const quiet = [...new Set(events.map((e) => e.cwd).filter((c) => Boolean(c)))]
|
|
318
|
+
.map((cwd) => ({ cwd, q: learnedQuiet(cwd, events, prefs) }))
|
|
319
|
+
.filter((x) => x.q.quiet)
|
|
320
|
+
.map((x) => ({ project: x.cwd.split('/').pop(), why: x.q.why }));
|
|
321
|
+
return {
|
|
322
|
+
since: new Date(since).toISOString(),
|
|
323
|
+
result: checkC1(since, t, s),
|
|
324
|
+
counted: { stops: stops.length, compacted: n('compacted') + warns.length, left: n('left'), sent: n('sent'), saved, measured, rewritten },
|
|
325
|
+
quiet,
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
export function nudgeProofText(p) {
|
|
329
|
+
const c = p.counted;
|
|
330
|
+
const lines = [`Live suggestions (on since ${day(Date.parse(p.since))})`, `${ICON[p.result.verdict]} ${p.result.line}`];
|
|
331
|
+
if (c.stops || c.compacted) {
|
|
332
|
+
lines.push(` Counted per stop: ~${k(c.saved)} not rewritten (compacted ${c.compacted}, left ${c.left}${c.saved > c.measured ? `; ~${k(c.saved - c.measured)} of it estimated` : ''}). Sent anyway ${c.sent}${c.rewritten ? `: ${k(c.rewritten)} rewritten` : ''}.`);
|
|
333
|
+
}
|
|
334
|
+
for (const q of p.quiet)
|
|
335
|
+
lines.push(` Not stopping you in ${q.project}: ${q.why === 'you' ? 'you asked' : `you sent anyway ${QUIET_AFTER} times in a row`}.`);
|
|
336
|
+
return lines;
|
|
337
|
+
}
|
|
338
|
+
const ICON = { 'too-early': '⏳', worked: '✅', short: '🟡', 'no-change': '➖', worse: '🔻', 'cant-tell': '❔' };
|
|
339
|
+
/** One screen: each fix, its verdict, and the saving by method (never added across methods). */
|
|
340
|
+
export function workedText(cards) {
|
|
341
|
+
if (!cards.length)
|
|
342
|
+
return 'Nothing to measure yet. Approve an advice card: chompyy advise';
|
|
343
|
+
const lines = [];
|
|
344
|
+
for (const c of cards) {
|
|
345
|
+
const r = c.advice.result;
|
|
346
|
+
if (!r)
|
|
347
|
+
continue;
|
|
348
|
+
lines.push(`${ICON[r.verdict]} #${c.id} ${c.title}`, ` ${r.line}`);
|
|
349
|
+
if (r.also)
|
|
350
|
+
lines.push(` ${r.also}`);
|
|
351
|
+
if (r.verdict === 'worse' && c.advice.lane === 'settings')
|
|
352
|
+
lines.push(` Put it back: chompyy undo ${c.id}`);
|
|
353
|
+
}
|
|
354
|
+
const recount = cards.map((c) => c.advice.result).filter((r) => r?.method === 'recount' && r.per === 'session start' && r.saved !== undefined && r.verdict !== 'cant-tell');
|
|
355
|
+
const weekly = cards.map((c) => c.advice.result).filter((r) => r?.method === 'before-after' && r.per === 'week' && r.saved !== undefined);
|
|
356
|
+
if (recount.length || weekly.length)
|
|
357
|
+
lines.push('');
|
|
358
|
+
if (recount.length) {
|
|
359
|
+
const sum = recount.reduce((n, r) => n + r.saved, 0);
|
|
360
|
+
lines.push(`Re-counted: ${sum >= 0 ? `~${k(sum)} tokens off` : `~${k(-sum)} tokens added to`} every session start.`);
|
|
361
|
+
}
|
|
362
|
+
if (weekly.length) {
|
|
363
|
+
const sum = weekly.reduce((n, r) => n + r.saved, 0);
|
|
364
|
+
lines.push(`Before vs after: ${sum >= 0 ? `${k(sum)} fewer` : `${k(-sum)} more`} tokens rewritten a week (not added to the line above).`);
|
|
365
|
+
}
|
|
366
|
+
return lines.join('\n');
|
|
367
|
+
}
|