chompyy 0.5.0 → 0.6.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 +11 -0
- package/dist/agentlimits.js +77 -0
- package/dist/agentusage.js +96 -0
- package/dist/appstate.js +63 -3
- package/dist/away.js +44 -5
- package/dist/blueprint.js +3 -7
- package/dist/board.js +1 -0
- package/dist/cli.js +263 -5
- package/dist/codexquota.js +106 -0
- package/dist/codexusage.js +10 -0
- package/dist/config.js +2 -0
- package/dist/context.js +30 -0
- package/dist/costs.js +1 -0
- package/dist/demon.js +20 -0
- package/dist/label.js +33 -0
- package/dist/menu.js +17 -0
- package/dist/nightcap.js +60 -0
- package/dist/nudge.js +47 -18
- package/dist/pacing.js +16 -1
- package/dist/questions.js +71 -0
- package/dist/recap.js +74 -0
- package/dist/receipt.js +48 -0
- package/dist/recipe.js +79 -0
- package/dist/stamps.js +14 -0
- package/dist/triggers.js +5 -0
- package/dist/usage.js +21 -1
- package/dist/vendor/codeburn/antigravity.js +309 -0
- package/dist/vendor/codeburn/codex.js +429 -0
- package/dist/vendor/codeburn/copilot.js +292 -0
- package/dist/vendor/codeburn/gemini.js +195 -0
- package/dist/vendor/codeburn/grokbot.js +182 -0
- package/dist/vendor/codeburn/kimi.js +178 -0
- package/dist/vendor/codeburn/shims/chalk.js +14 -0
- package/dist/vendor/codeburn/shims/strip-ansi.js +6 -0
- package/dist/vendor/codeburn/src/act/backup.js +83 -0
- package/dist/vendor/codeburn/src/act/model-defaults.js +151 -0
- package/dist/vendor/codeburn/src/act/types.js +37 -0
- package/dist/vendor/codeburn/src/bash-utils.js +204 -0
- package/dist/vendor/codeburn/src/behavioral-weight.js +47 -0
- package/dist/vendor/codeburn/src/cache-dir.js +26 -0
- package/dist/vendor/codeburn/src/cache-refresh-lock.js +543 -0
- package/dist/vendor/codeburn/src/cache-sweep.js +67 -0
- package/dist/vendor/codeburn/src/classifier.js +209 -0
- package/dist/vendor/codeburn/src/claude-identity.js +223 -0
- package/dist/vendor/codeburn/src/codex-cache.js +377 -0
- package/dist/vendor/codeburn/src/codex-fork-replay.js +232 -0
- package/dist/vendor/codeburn/src/codex-jsonl-fields.js +99 -0
- package/dist/vendor/codeburn/src/codex-session-index.js +113 -0
- package/dist/vendor/codeburn/src/codex-throughput.js +544 -0
- package/dist/vendor/codeburn/src/compare-stats.js +405 -0
- package/dist/vendor/codeburn/src/config.js +145 -0
- package/dist/vendor/codeburn/src/content-utils.js +56 -0
- package/dist/vendor/codeburn/src/context-tree-codex.js +329 -0
- package/dist/vendor/codeburn/src/context-tree.js +664 -0
- package/dist/vendor/codeburn/src/copilot-aiu.js +16 -0
- package/dist/vendor/codeburn/src/currency.js +189 -0
- package/dist/vendor/codeburn/src/cursor-cache.js +238 -0
- package/dist/vendor/codeburn/src/cursor-import.js +402 -0
- package/dist/vendor/codeburn/src/cursor-sync.js +256 -0
- package/dist/vendor/codeburn/src/daily-cache.js +2036 -0
- package/dist/vendor/codeburn/src/data/litellm-snapshot.json +1 -0
- package/dist/vendor/codeburn/src/data/pricing-fallback.json +1 -0
- package/dist/vendor/codeburn/src/day-aggregator.js +327 -0
- package/dist/vendor/codeburn/src/editor-data-dir.js +11 -0
- package/dist/vendor/codeburn/src/fetch-utils.js +18 -0
- package/dist/vendor/codeburn/src/format.js +118 -0
- package/dist/vendor/codeburn/src/fs-utils.js +270 -0
- package/dist/vendor/codeburn/src/git-origin.js +334 -0
- package/dist/vendor/codeburn/src/granular-history.js +328 -0
- package/dist/vendor/codeburn/src/hermes-session-ledger.js +512 -0
- package/dist/vendor/codeburn/src/launcher-homes.js +142 -0
- package/dist/vendor/codeburn/src/live-sessions.js +358 -0
- package/dist/vendor/codeburn/src/math-utils.js +8 -0
- package/dist/vendor/codeburn/src/menubar-json.js +294 -0
- package/dist/vendor/codeburn/src/models.js +1879 -0
- package/dist/vendor/codeburn/src/optimize-one-hour-cache.js +92 -0
- package/dist/vendor/codeburn/src/optimize.js +4110 -0
- package/dist/vendor/codeburn/src/parse-workers.js +219 -0
- package/dist/vendor/codeburn/src/parser.js +6953 -0
- package/dist/vendor/codeburn/src/path-privacy.js +26 -0
- package/dist/vendor/codeburn/src/plans.js +135 -0
- package/dist/vendor/codeburn/src/pr-signals.js +132 -0
- package/dist/vendor/codeburn/src/project-filter-warnings.js +33 -0
- package/dist/vendor/codeburn/src/provider-issues.js +30 -0
- package/dist/vendor/codeburn/src/providers/amp.js +286 -0
- package/dist/vendor/codeburn/src/providers/antigravity.js +1731 -0
- package/dist/vendor/codeburn/src/providers/claude.js +551 -0
- package/dist/vendor/codeburn/src/providers/cline-cli.js +401 -0
- package/dist/vendor/codeburn/src/providers/cline.js +63 -0
- package/dist/vendor/codeburn/src/providers/codebuff.js +336 -0
- package/dist/vendor/codeburn/src/providers/codewhale.js +442 -0
- package/dist/vendor/codeburn/src/providers/codex.js +1720 -0
- package/dist/vendor/codeburn/src/providers/command-code.js +196 -0
- package/dist/vendor/codeburn/src/providers/copilot.js +3278 -0
- package/dist/vendor/codeburn/src/providers/crush.js +226 -0
- package/dist/vendor/codeburn/src/providers/cursor-agent.js +837 -0
- package/dist/vendor/codeburn/src/providers/cursor.js +1163 -0
- package/dist/vendor/codeburn/src/providers/devin.js +569 -0
- package/dist/vendor/codeburn/src/providers/droid.js +324 -0
- package/dist/vendor/codeburn/src/providers/dsh.js +690 -0
- package/dist/vendor/codeburn/src/providers/forge.js +245 -0
- package/dist/vendor/codeburn/src/providers/gemini.js +230 -0
- package/dist/vendor/codeburn/src/providers/goose.js +252 -0
- package/dist/vendor/codeburn/src/providers/grok.js +581 -0
- package/dist/vendor/codeburn/src/providers/grokbot.js +290 -0
- package/dist/vendor/codeburn/src/providers/hermes.js +771 -0
- package/dist/vendor/codeburn/src/providers/ibm-bob.js +53 -0
- package/dist/vendor/codeburn/src/providers/index.js +360 -0
- package/dist/vendor/codeburn/src/providers/kilo-code.js +50 -0
- package/dist/vendor/codeburn/src/providers/kimi.js +363 -0
- package/dist/vendor/codeburn/src/providers/kimicode.js +402 -0
- package/dist/vendor/codeburn/src/providers/kiro.js +1174 -0
- package/dist/vendor/codeburn/src/providers/lingtai-tui.js +372 -0
- package/dist/vendor/codeburn/src/providers/mistral-vibe-unified.js +236 -0
- package/dist/vendor/codeburn/src/providers/mistral-vibe.js +405 -0
- package/dist/vendor/codeburn/src/providers/mux.js +242 -0
- package/dist/vendor/codeburn/src/providers/open-design.js +217 -0
- package/dist/vendor/codeburn/src/providers/openclaude.js +309 -0
- package/dist/vendor/codeburn/src/providers/openclaw.js +442 -0
- package/dist/vendor/codeburn/src/providers/opencode-file-parser.js +131 -0
- package/dist/vendor/codeburn/src/providers/opencode.js +91 -0
- package/dist/vendor/codeburn/src/providers/pi.js +429 -0
- package/dist/vendor/codeburn/src/providers/quickdesk.js +491 -0
- package/dist/vendor/codeburn/src/providers/qwen.js +193 -0
- package/dist/vendor/codeburn/src/providers/session-message.js +118 -0
- package/dist/vendor/codeburn/src/providers/sqlite-session-parser.js +457 -0
- package/dist/vendor/codeburn/src/providers/types.js +5 -0
- package/dist/vendor/codeburn/src/providers/vercel-gateway.js +135 -0
- package/dist/vendor/codeburn/src/providers/vscode-cline-parser.js +212 -0
- package/dist/vendor/codeburn/src/providers/warp.js +575 -0
- package/dist/vendor/codeburn/src/providers/zcode.js +249 -0
- package/dist/vendor/codeburn/src/providers/zed.js +187 -0
- package/dist/vendor/codeburn/src/providers/zerostack.js +139 -0
- package/dist/vendor/codeburn/src/quota/antigravity.js +310 -0
- package/dist/vendor/codeburn/src/quota/claude.js +244 -0
- package/dist/vendor/codeburn/src/quota/cursor.js +301 -0
- package/dist/vendor/codeburn/src/quota/security.js +299 -0
- package/dist/vendor/codeburn/src/quota/types.js +1 -0
- package/dist/vendor/codeburn/src/scan-facts.js +99 -0
- package/dist/vendor/codeburn/src/session-cache.js +3040 -0
- package/dist/vendor/codeburn/src/session-count-label.js +14 -0
- package/dist/vendor/codeburn/src/session-output.js +139 -0
- package/dist/vendor/codeburn/src/session-population.js +30 -0
- package/dist/vendor/codeburn/src/sessions-report.js +1342 -0
- package/dist/vendor/codeburn/src/sqlite.js +528 -0
- package/dist/vendor/codeburn/src/sync/otlp.js +420 -0
- package/dist/vendor/codeburn/src/telemetry-snapshot.js +244 -0
- package/dist/vendor/codeburn/src/token-estimate.js +5 -0
- package/dist/vendor/codeburn/src/types.js +16 -0
- package/dist/vendor/codeburn/src/work-units.js +126 -0
- package/dist/vendor/codeburn/src/workflow-insights.js +228 -0
- package/dist/vendor/codeburn/src/wsl.js +198 -0
- package/dist/vendor/codeburn/src/yield.js +666 -0
- package/package.json +1 -1
package/dist/nightcap.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bedtime nightcap: in the evening, Chompyy puts on a nightcap and offers, inline in the panel, to run your
|
|
3
|
+
* approved cards while you sleep ("Leave it to me tonight?"). Once bedtime is set it says what runs tonight, with
|
|
4
|
+
* Skip tonight. The bedtime trigger (triggers.ts) does the running; this only decides what the panel says.
|
|
5
|
+
*/
|
|
6
|
+
import { bedtimeKey, parseClock } from './triggers.js';
|
|
7
|
+
/** The nightcap goes on this long before bedtime. */
|
|
8
|
+
const EVENING_MIN = 3 * 60;
|
|
9
|
+
/** With no bedtime set, offer from 20:00 to 00:59. */
|
|
10
|
+
const OFFER_FROM = 20 * 60;
|
|
11
|
+
const OFFER_UNTIL = 60;
|
|
12
|
+
const DEFAULT_BEDTIME = '23:30';
|
|
13
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
14
|
+
const dayKey = (d) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
|
15
|
+
/** Minutes until the next `bedtime`, and the trigger key for it. Inside the bedtime window: 0 and tonight's key. */
|
|
16
|
+
export function nextBedtime(now, bedtime, windowMin) {
|
|
17
|
+
const current = bedtimeKey(now, bedtime, windowMin);
|
|
18
|
+
if (current)
|
|
19
|
+
return { inMin: 0, key: current };
|
|
20
|
+
const start = parseClock(bedtime);
|
|
21
|
+
const minutes = now.getHours() * 60 + now.getMinutes();
|
|
22
|
+
const day = new Date(now);
|
|
23
|
+
let inMin = start - minutes;
|
|
24
|
+
if (inMin < 0) {
|
|
25
|
+
inMin += 24 * 60;
|
|
26
|
+
day.setDate(day.getDate() + 1);
|
|
27
|
+
}
|
|
28
|
+
return { inMin, key: `bedtime:${dayKey(day)}` };
|
|
29
|
+
}
|
|
30
|
+
/** A bedtime to offer: 23:30, or the next half hour at least 30 minutes away when it's already late. */
|
|
31
|
+
export function offeredBedtime(now) {
|
|
32
|
+
const minutes = now.getHours() * 60 + now.getMinutes();
|
|
33
|
+
const late = minutes >= 23 * 60 || minutes < OFFER_UNTIL;
|
|
34
|
+
if (!late)
|
|
35
|
+
return DEFAULT_BEDTIME;
|
|
36
|
+
const t = (Math.ceil((minutes + 30) / 30) * 30) % (24 * 60);
|
|
37
|
+
return `${pad(Math.floor(t / 60))}:${pad(t % 60)}`;
|
|
38
|
+
}
|
|
39
|
+
export function nightcap(i) {
|
|
40
|
+
if (i.bedtime && i.triggersOn) {
|
|
41
|
+
const next = nextBedtime(i.now, i.bedtime, i.bedtimeWindowMin);
|
|
42
|
+
if (next.inMin === 0 && i.awayBusy)
|
|
43
|
+
return { phase: 'running', bedtime: i.bedtime, cards: i.approved, key: next.key };
|
|
44
|
+
if (next.inMin === 0 && i.fired.includes(next.key))
|
|
45
|
+
return null; // tonight's run is done (or skipped)
|
|
46
|
+
if (next.inMin > EVENING_MIN || i.approved < 1)
|
|
47
|
+
return null;
|
|
48
|
+
return { phase: i.fired.includes(next.key) ? 'skipped' : 'armed', bedtime: i.bedtime, cards: i.approved, key: next.key };
|
|
49
|
+
}
|
|
50
|
+
const minutes = i.now.getHours() * 60 + i.now.getMinutes();
|
|
51
|
+
if (i.approved < 1 || (minutes < OFFER_FROM && minutes >= OFFER_UNTIL))
|
|
52
|
+
return null;
|
|
53
|
+
const evening = new Date(i.now);
|
|
54
|
+
if (minutes < OFFER_UNTIL)
|
|
55
|
+
evening.setDate(evening.getDate() - 1);
|
|
56
|
+
const key = `nightcap-offer:${dayKey(evening)}`;
|
|
57
|
+
if (i.fired.includes(key))
|
|
58
|
+
return null; // "Not tonight"
|
|
59
|
+
return { phase: 'offer', bedtime: offeredBedtime(i.now), cards: i.approved, key };
|
|
60
|
+
}
|
package/dist/nudge.js
CHANGED
|
@@ -10,6 +10,7 @@ import { formatDuration } from './duration.js';
|
|
|
10
10
|
import { appendJsonl, homePath } from './home.js';
|
|
11
11
|
import { coldReturns, isAutomated, scan } from './detect.js';
|
|
12
12
|
import { projectsDir } from './dream.js';
|
|
13
|
+
import { windowFor } from './context.js';
|
|
13
14
|
/** The main conversation's cache lives an hour (5 minutes on API keys): past an hour it's cold either way. */
|
|
14
15
|
export const COLD_AFTER_MS = 60 * 60_000;
|
|
15
16
|
/** Below this the rebuild is cheap; not worth stopping you. */
|
|
@@ -117,20 +118,32 @@ function slice(file, bytes, fromEnd) {
|
|
|
117
118
|
* The conversation's last reply, its first (about what a fresh conversation costs: tools, CLAUDE.md, memory), and
|
|
118
119
|
* a compaction after the last reply, if there was one.
|
|
119
120
|
*/
|
|
120
|
-
|
|
121
|
+
/** `withPeak` also reads every reply in the tail for the biggest context (warm caches); the hook skips it to stay fast. */
|
|
122
|
+
export function replies(transcript, withPeak = false) {
|
|
121
123
|
const tail = slice(transcript, 4 << 20, true).split('\n');
|
|
122
124
|
let last = null;
|
|
123
125
|
let compacted = null;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
126
|
+
let peak = 0;
|
|
127
|
+
let model = '';
|
|
128
|
+
for (let i = tail.length - 1; i >= 0; i--) {
|
|
129
|
+
if (last && !withPeak)
|
|
130
|
+
break;
|
|
131
|
+
const r = replyOf(tail[i]);
|
|
132
|
+
if (r)
|
|
133
|
+
peak = Math.max(peak, r.context);
|
|
134
|
+
if (last)
|
|
135
|
+
continue;
|
|
136
|
+
last = r;
|
|
137
|
+
if (last)
|
|
138
|
+
model = tail[i].match(/"model":"([^"]+)"/)?.[1] ?? '';
|
|
139
|
+
else
|
|
127
140
|
compacted ??= compactionOf(tail[i]);
|
|
128
141
|
}
|
|
129
142
|
let first = null;
|
|
130
143
|
for (const line of slice(transcript, 2 << 20, false).split('\n'))
|
|
131
144
|
if ((first = replyOf(line)))
|
|
132
145
|
break;
|
|
133
|
-
return { last, first, compacted };
|
|
146
|
+
return { last, first, compacted, peak, model };
|
|
134
147
|
}
|
|
135
148
|
export function loadNudges() {
|
|
136
149
|
const path = homePath('nudges.jsonl');
|
|
@@ -228,12 +241,37 @@ export function runHook(stdin, now = Date.now()) {
|
|
|
228
241
|
*/
|
|
229
242
|
export function goingCold(now = Date.now(), dir = projectsDir(), events = loadNudges()) {
|
|
230
243
|
const out = [];
|
|
244
|
+
for (const { transcript, session, last, first } of bigConversations(now, dir, WARN_AFTER_MS - 60_000)) {
|
|
245
|
+
const idleMs = now - last.at;
|
|
246
|
+
if (idleMs < WARN_AFTER_MS || idleMs >= COLD_AFTER_MS)
|
|
247
|
+
continue;
|
|
248
|
+
if (events.some((e) => e.kind === 'warned' && e.session === session && Date.parse(e.at) > last.at))
|
|
249
|
+
continue;
|
|
250
|
+
const cwd = cwdOf(transcript);
|
|
251
|
+
const fresh = first && first.context < last.context / 2 ? first.context : undefined;
|
|
252
|
+
out.push({ session, transcript, project: cwd ? basename(cwd) : basename(dirname(transcript)), context: last.context, ...(fresh ? { fresh } : {}), idleMs, coldAt: new Date(last.at + COLD_AFTER_MS).toISOString() });
|
|
253
|
+
}
|
|
254
|
+
return out;
|
|
255
|
+
}
|
|
256
|
+
/** Every warm cache right now, the one expiring soonest first. */
|
|
257
|
+
export function warmCaches(now = Date.now(), dir = projectsDir()) {
|
|
258
|
+
const out = [];
|
|
259
|
+
for (const { transcript, session, last, peak, model } of bigConversations(now, dir, 0, true)) {
|
|
260
|
+
if (now - last.at >= COLD_AFTER_MS)
|
|
261
|
+
continue;
|
|
262
|
+
const cwd = cwdOf(transcript);
|
|
263
|
+
out.push({ session, project: cwd ? basename(cwd) : basename(dirname(transcript)), context: last.context, window: windowFor(model, peak), model, warmTill: new Date(last.at + COLD_AFTER_MS).toISOString() });
|
|
264
|
+
}
|
|
265
|
+
return out.sort((a, b) => a.warmTill.localeCompare(b.warmTill));
|
|
266
|
+
}
|
|
267
|
+
/** Transcripts written in the last hour (and at least `minIdleMs` ago) whose last reply is big and not compacted. */
|
|
268
|
+
function* bigConversations(now, dir, minIdleMs, withPeak = false) {
|
|
231
269
|
let folders = [];
|
|
232
270
|
try {
|
|
233
271
|
folders = readdirSync(dir).filter((f) => !isAutomated(f));
|
|
234
272
|
}
|
|
235
273
|
catch {
|
|
236
|
-
return
|
|
274
|
+
return;
|
|
237
275
|
}
|
|
238
276
|
for (const folder of folders) {
|
|
239
277
|
let files = [];
|
|
@@ -247,27 +285,18 @@ export function goingCold(now = Date.now(), dir = projectsDir(), events = loadNu
|
|
|
247
285
|
const transcript = join(dir, folder, f);
|
|
248
286
|
try {
|
|
249
287
|
const mtime = statSync(transcript).mtimeMs;
|
|
250
|
-
if (now - mtime > COLD_AFTER_MS || now - mtime <
|
|
288
|
+
if (now - mtime > COLD_AFTER_MS || now - mtime < minIdleMs)
|
|
251
289
|
continue;
|
|
252
|
-
const { last, first, compacted } = replies(transcript);
|
|
290
|
+
const { last, first, compacted, peak, model } = replies(transcript, withPeak);
|
|
253
291
|
if (!last || compacted || last.context < MIN_CONTEXT)
|
|
254
292
|
continue;
|
|
255
|
-
|
|
256
|
-
if (idleMs < WARN_AFTER_MS || idleMs >= COLD_AFTER_MS)
|
|
257
|
-
continue;
|
|
258
|
-
const session = f.replace(/\.jsonl$/, '');
|
|
259
|
-
if (events.some((e) => e.kind === 'warned' && e.session === session && Date.parse(e.at) > last.at))
|
|
260
|
-
continue;
|
|
261
|
-
const cwd = cwdOf(transcript);
|
|
262
|
-
const fresh = first && first.context < last.context / 2 ? first.context : undefined;
|
|
263
|
-
out.push({ session, transcript, project: cwd ? basename(cwd) : folder, context: last.context, ...(fresh ? { fresh } : {}), idleMs, coldAt: new Date(last.at + COLD_AFTER_MS).toISOString() });
|
|
293
|
+
yield { transcript, session: f.replace(/\.jsonl$/, ''), last, first, peak, model };
|
|
264
294
|
}
|
|
265
295
|
catch {
|
|
266
296
|
/* one bad file never hides the others */
|
|
267
297
|
}
|
|
268
298
|
}
|
|
269
299
|
}
|
|
270
|
-
return out;
|
|
271
300
|
}
|
|
272
301
|
function cwdOf(transcript) {
|
|
273
302
|
const m = slice(transcript, 64 << 10, true).match(/"cwd":"((?:[^"\\]|\\.)*)"/g);
|
package/dist/pacing.js
CHANGED
|
@@ -149,6 +149,20 @@ export function windowShareOfWeek(samples) {
|
|
|
149
149
|
return five >= 50 ? (100 * week) / five : null;
|
|
150
150
|
}
|
|
151
151
|
const dayClock = (ms) => `${new Date(ms).toLocaleDateString('en-US', { weekday: 'short' })} ${clock(ms)}`;
|
|
152
|
+
/** This week's readings as (share of the week passed, % used), thinned to `max` points, ending at now. */
|
|
153
|
+
export function weekCurve(samples, resetsAt, now, usedNow, max = 48) {
|
|
154
|
+
const start = resetsAt * 1000 - WEEK;
|
|
155
|
+
const t = (at) => Math.max(0, Math.min(1, (at - start) / WEEK));
|
|
156
|
+
const pts = samples
|
|
157
|
+
.filter((x) => x.week?.resetsAt === resetsAt && x.at >= start && x.at <= now.getTime() && typeof x.week.usedPct === 'number')
|
|
158
|
+
.map((x) => ({ t: t(x.at), used: x.week.usedPct }));
|
|
159
|
+
const buckets = new Map();
|
|
160
|
+
for (const p of pts)
|
|
161
|
+
buckets.set(Math.floor(p.t * max), p); // last reading in each slice
|
|
162
|
+
const out = [{ t: 0, used: 0 }, ...buckets.values()].sort((a, b) => a.t - b.t);
|
|
163
|
+
out.push({ t: t(now.getTime()), used: usedNow });
|
|
164
|
+
return out.map((p) => ({ t: Math.round(p.t * 1000) / 1000, used: p.used }));
|
|
165
|
+
}
|
|
152
166
|
export function weekForecast(snap, samples, now) {
|
|
153
167
|
const v = windowView(snap?.sevenDay, now);
|
|
154
168
|
if (!v.known)
|
|
@@ -186,7 +200,8 @@ export function weekForecast(snap, samples, now) {
|
|
|
186
200
|
line += '. Less than one 5-hour window left before then.';
|
|
187
201
|
}
|
|
188
202
|
const short = line.slice(head.length + 1);
|
|
189
|
-
|
|
203
|
+
const curve = weekCurve(samples, v.resetsAt, now, v.usedPct);
|
|
204
|
+
return { usedPct: v.usedPct, resetsAt: v.resetsAt, unusedPct, projectedPct: Math.min(100, projected), curve, ...(runsOutAt ? { runsOutAt } : {}), windowPct, spareWindows, maxReachablePct, line, short };
|
|
190
205
|
}
|
|
191
206
|
// ---------- rolling daily allowance ----------
|
|
192
207
|
/** The day you're in: from your last bedtime (or midnight) to the next. */
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/** QUESTIONS.md, read into questions with options the app can show as a pick list. */
|
|
2
|
+
const ITEM = /^(\d+[.)]|[-*])\s+/;
|
|
3
|
+
const RECOMMENDED = /\(?\brecommended\b\)?:?/i;
|
|
4
|
+
function option(lines) {
|
|
5
|
+
const raw = lines.map((l) => l.trim()).join('\n').replace(ITEM, '');
|
|
6
|
+
const recommended = RECOMMENDED.test(raw.split('\n')[0] ?? '');
|
|
7
|
+
const text = raw.replace(/\*\*\s*\(?recommended\)?:?\s*\*\*\s*/i, '').replace(RECOMMENDED, '').trim();
|
|
8
|
+
const flat = text.replace(/\s*\n\s*/g, ' ').replace(/\*\*|__/g, '').replace(/^[\s:–—-]+/, '');
|
|
9
|
+
// The label is the first sentence; "e.g." and "i.e." don't end one.
|
|
10
|
+
const end = /(?<!\b(?:e\.g|i\.e|etc|vs))[.?!]`?(?=\s)/.exec(flat);
|
|
11
|
+
const cut = end ? end.index + end[0].length : flat.length;
|
|
12
|
+
return { label: flat.slice(0, cut).trim(), detail: flat.slice(cut).trim(), recommended };
|
|
13
|
+
}
|
|
14
|
+
/** Join hard-wrapped lines into one line per paragraph; list items keep their own line. */
|
|
15
|
+
function unwrap(lines) {
|
|
16
|
+
const out = [];
|
|
17
|
+
for (const line of lines) {
|
|
18
|
+
const t = line.trim();
|
|
19
|
+
const prev = out[out.length - 1];
|
|
20
|
+
if (t && prev && !ITEM.test(t) && !ITEM.test(prev))
|
|
21
|
+
out[out.length - 1] = `${prev} ${t}`;
|
|
22
|
+
else
|
|
23
|
+
out.push(t);
|
|
24
|
+
}
|
|
25
|
+
return out.join('\n').replace(/\n{3,}/g, '\n\n').trim();
|
|
26
|
+
}
|
|
27
|
+
function question(title, body) {
|
|
28
|
+
const at = body.findIndex((l) => /^\s*\**options\**:?\**\s*$/i.test(l));
|
|
29
|
+
const before = at === -1 ? body : body.slice(0, at);
|
|
30
|
+
const options = [];
|
|
31
|
+
if (at !== -1) {
|
|
32
|
+
let cur = null;
|
|
33
|
+
for (const line of body.slice(at + 1)) {
|
|
34
|
+
if (ITEM.test(line)) {
|
|
35
|
+
if (cur)
|
|
36
|
+
options.push(option(cur));
|
|
37
|
+
cur = [line];
|
|
38
|
+
}
|
|
39
|
+
else if (cur && /^\s+\S/.test(line))
|
|
40
|
+
cur.push(line); // continuation of the item
|
|
41
|
+
else if (cur && line.trim()) {
|
|
42
|
+
options.push(option(cur));
|
|
43
|
+
cur = null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (cur)
|
|
47
|
+
options.push(option(cur));
|
|
48
|
+
}
|
|
49
|
+
return { title, context: unwrap(before), options: options.length >= 2 ? options : [] };
|
|
50
|
+
}
|
|
51
|
+
/** Each "## " heading is one question. A file without headings is one question titled by its first line. */
|
|
52
|
+
export function parseQuestions(markdown) {
|
|
53
|
+
const lines = markdown.split('\n').filter((l) => !/^#\s/.test(l)); // drop the "# Questions for task" title
|
|
54
|
+
const out = [];
|
|
55
|
+
let title = null;
|
|
56
|
+
let body = [];
|
|
57
|
+
for (const line of lines) {
|
|
58
|
+
const h = /^#{2,3}\s+(.*)$/.exec(line);
|
|
59
|
+
if (h) {
|
|
60
|
+
if (title !== null || body.some((l) => l.trim()))
|
|
61
|
+
out.push(question(title ?? '', body));
|
|
62
|
+
title = (h[1] ?? '').replace(/\*\*|__/g, '').trim();
|
|
63
|
+
body = [];
|
|
64
|
+
}
|
|
65
|
+
else
|
|
66
|
+
body.push(line);
|
|
67
|
+
}
|
|
68
|
+
if (title !== null || body.some((l) => l.trim()))
|
|
69
|
+
out.push(question(title ?? '', body));
|
|
70
|
+
return out.filter((q) => q.title || q.context || q.options.length);
|
|
71
|
+
}
|
package/dist/recap.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/** One cookie per 100k tokens, like the jar in the panel. */
|
|
2
|
+
export const TOKENS_PER_COOKIE = 100_000;
|
|
3
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
4
|
+
const localDay = (iso) => {
|
|
5
|
+
const d = new Date(iso);
|
|
6
|
+
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
|
7
|
+
};
|
|
8
|
+
const rowTokens = (r) => r.input + r.output + r.cacheRead + r.cacheWrite5m + r.cacheWrite1h;
|
|
9
|
+
/** Which month to recap: "2026-11", or by default this month once it's 7 days old, else last month. */
|
|
10
|
+
export function recapMonth(now, month) {
|
|
11
|
+
let y;
|
|
12
|
+
let m; // 0-based
|
|
13
|
+
if (month) {
|
|
14
|
+
const match = /^(\d{4})-(\d{2})$/.exec(month);
|
|
15
|
+
if (!match || Number(match[2]) < 1 || Number(match[2]) > 12)
|
|
16
|
+
throw new Error(`Month must look like 2026-11, not "${month}".`);
|
|
17
|
+
y = Number(match[1]);
|
|
18
|
+
m = Number(match[2]) - 1;
|
|
19
|
+
}
|
|
20
|
+
else if (now.getDate() >= 7) {
|
|
21
|
+
y = now.getFullYear();
|
|
22
|
+
m = now.getMonth();
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const prev = new Date(now.getFullYear(), now.getMonth() - 1, 1);
|
|
26
|
+
y = prev.getFullYear();
|
|
27
|
+
m = prev.getMonth();
|
|
28
|
+
}
|
|
29
|
+
const start = new Date(y, m, 1);
|
|
30
|
+
const monthEnd = new Date(y, m + 1, 1);
|
|
31
|
+
return { start, end: monthEnd < now ? monthEnd : now };
|
|
32
|
+
}
|
|
33
|
+
export function recap(rows, runs, cards, range) {
|
|
34
|
+
const from = range.start.toISOString();
|
|
35
|
+
const to = range.end.toISOString();
|
|
36
|
+
const inRange = (at) => !!at && at >= from && at < to;
|
|
37
|
+
const days = new Map();
|
|
38
|
+
const sessions = new Set();
|
|
39
|
+
const models = new Map();
|
|
40
|
+
let tokens = 0;
|
|
41
|
+
let costUsd = 0;
|
|
42
|
+
for (const r of rows) {
|
|
43
|
+
if (!inRange(r.at))
|
|
44
|
+
continue;
|
|
45
|
+
const n = rowTokens(r);
|
|
46
|
+
tokens += n;
|
|
47
|
+
costUsd += r.costUsd;
|
|
48
|
+
days.set(localDay(r.at), (days.get(localDay(r.at)) ?? 0) + n);
|
|
49
|
+
if (!r.session.startsWith('chompyy-card-'))
|
|
50
|
+
sessions.add(r.session);
|
|
51
|
+
models.set(r.model, (models.get(r.model) ?? 0) + n);
|
|
52
|
+
}
|
|
53
|
+
const busiest = [...days].sort((a, b) => b[1] - a[1])[0];
|
|
54
|
+
const monthRuns = runs.filter((r) => inRange(r.at));
|
|
55
|
+
const biggest = monthRuns
|
|
56
|
+
.filter((r) => r.tokens)
|
|
57
|
+
.map((r) => ({ tokens: r.tokens.input + r.tokens.output + r.tokens.cacheRead + r.tokens.cacheWrite, minutes: Math.max(1, Math.round(r.durationMs / 60_000)) }))
|
|
58
|
+
.sort((a, b) => b.tokens - a.tokens)[0];
|
|
59
|
+
return {
|
|
60
|
+
label: range.start.toLocaleDateString('en-US', { month: 'long', year: 'numeric' }),
|
|
61
|
+
from,
|
|
62
|
+
to,
|
|
63
|
+
tokens,
|
|
64
|
+
costUsd: Math.round(costUsd * 100) / 100,
|
|
65
|
+
cookies: Math.round(tokens / TOKENS_PER_COOKIE),
|
|
66
|
+
activeDays: [...days.values()].filter((n) => n > 0).length,
|
|
67
|
+
busiestDay: busiest ? { day: busiest[0], tokens: busiest[1] } : null,
|
|
68
|
+
conversations: sessions.size,
|
|
69
|
+
cardsBaked: monthRuns.filter((r) => r.status === 'ok').length,
|
|
70
|
+
kept: cards.filter((c) => !c.advice && c.outcome === 'kept' && inRange(c.updatedAt)).length,
|
|
71
|
+
biggestBake: biggest ?? null,
|
|
72
|
+
topModel: [...models].sort((a, b) => b[1] - a[1])[0]?.[0] ?? null,
|
|
73
|
+
};
|
|
74
|
+
}
|
package/dist/receipt.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { compactTokens } from './usage.js';
|
|
2
|
+
const WEEK = 7 * 24 * 3600_000;
|
|
3
|
+
const usd = (n) => `$${n.toFixed(2)}`;
|
|
4
|
+
const x = (n) => `×${n}`;
|
|
5
|
+
export function receipt(runs, cards, resent, now) {
|
|
6
|
+
const t = now.getTime();
|
|
7
|
+
const inWeek = (at) => !!at && Date.parse(at) > t - WEEK && Date.parse(at) <= t;
|
|
8
|
+
const week = runs.filter((r) => inWeek(r.at));
|
|
9
|
+
const baked = week.filter((r) => r.status === 'ok');
|
|
10
|
+
const value = week.reduce((a, r) => a + (r.tokens?.costUsd ?? 0), 0);
|
|
11
|
+
const tokens = week.reduce((a, r) => a + (r.tokens ? r.tokens.input + r.tokens.output + r.tokens.cacheRead + r.tokens.cacheWrite : 0), 0);
|
|
12
|
+
const settled = cards.filter((c) => !c.advice && inWeek(c.updatedAt));
|
|
13
|
+
const kept = settled.filter((c) => c.outcome === 'kept').length;
|
|
14
|
+
const undone = settled.filter((c) => c.outcome === 'undone').length;
|
|
15
|
+
const lines = [
|
|
16
|
+
{ label: 'Cards baked', qty: x(baked.length), amount: usd(baked.reduce((a, r) => a + (r.tokens?.costUsd ?? 0), 0)) },
|
|
17
|
+
{ label: 'Kept', qty: x(kept), amount: '' },
|
|
18
|
+
{ label: 'Burnt (undone)', qty: x(undone), amount: '' },
|
|
19
|
+
{ label: 'Oven time', qty: '', amount: compactTokens(tokens) + ' tokens' },
|
|
20
|
+
];
|
|
21
|
+
const less = resent ? resent.lastWeek - resent.thisWeek : 0;
|
|
22
|
+
if (resent && less > 0)
|
|
23
|
+
lines.push({ label: 'Resent less than last wk', qty: '', amount: compactTokens(less) + ' tokens' });
|
|
24
|
+
else if (resent && less < 0)
|
|
25
|
+
lines.push({ label: 'Resent more than last wk', qty: '', amount: compactTokens(-less) + ' tokens' });
|
|
26
|
+
const footer = baked.length === 0
|
|
27
|
+
? 'Quiet week in the bakery. Approve a card and it bakes while you\'re away.'
|
|
28
|
+
: kept >= baked.length / 2
|
|
29
|
+
? 'Fresh batch, mostly kept. Thanks for shopping at Chompyy!'
|
|
30
|
+
: 'Some came out burnt. Smaller cards bake better.';
|
|
31
|
+
return { from: new Date(t - WEEK).toISOString(), to: now.toISOString(), lines, total: usd(value), footer };
|
|
32
|
+
}
|
|
33
|
+
/** The receipt as text, for the terminal or a paste. */
|
|
34
|
+
export function receiptText(r) {
|
|
35
|
+
const width = 36;
|
|
36
|
+
const day = (iso) => new Date(iso).toLocaleDateString('en-US', { month: 'short', day: 'numeric' });
|
|
37
|
+
const row = (l, r) => `${l}${' '.repeat(Math.max(1, width - l.length - r.length))}${r}`;
|
|
38
|
+
return [
|
|
39
|
+
'🍪 CHOMPYY BAKE SALE',
|
|
40
|
+
`${day(r.from)} – ${day(r.to)}`,
|
|
41
|
+
'-'.repeat(width),
|
|
42
|
+
...r.lines.map((l) => row(l.qty ? `${l.label} ${l.qty}` : l.label, l.amount)),
|
|
43
|
+
'-'.repeat(width),
|
|
44
|
+
row('Work done (API value)', r.total),
|
|
45
|
+
'',
|
|
46
|
+
r.footer,
|
|
47
|
+
].join('\n');
|
|
48
|
+
}
|
package/dist/recipe.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A kept card as a recipe: the files it changed are the ingredients, what the run did is the steps, and the run time
|
|
3
|
+
* is the baking time (the app draws the card; this finds the parts).
|
|
4
|
+
*
|
|
5
|
+
* Kept work lands on main as a merge: "Keep Chompyy card #N: …" (review.ts keepCard) or a pull request from
|
|
6
|
+
* chompyy/card-N (send.ts). Its branch is usually gone by then, so the merge is what's left to read.
|
|
7
|
+
*/
|
|
8
|
+
import { execFileSync } from 'node:child_process';
|
|
9
|
+
import { exe } from './exe.js';
|
|
10
|
+
import { gitRoot } from './workspace.js';
|
|
11
|
+
const MAX_STEPS = 5;
|
|
12
|
+
const STEP_CHARS = 80;
|
|
13
|
+
function git(cwd, args) {
|
|
14
|
+
try {
|
|
15
|
+
return execFileSync(exe('git'), ['-C', cwd, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return '';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const lines = (s) => s.split('\n').map((l) => l.trim()).filter(Boolean);
|
|
22
|
+
/** The merge that brought card `id` onto a branch: Keep's own merge, or the pull request from chompyy/card-<id>. */
|
|
23
|
+
export function keptMerge(root, id) {
|
|
24
|
+
const keep = `Keep Chompyy card #${id}:`;
|
|
25
|
+
const pr = new RegExp(`/chompyy/card-${id}$`);
|
|
26
|
+
for (const l of lines(git(root, ['log', '--all', '--merges', '--format=%H%x09%cI%x09%s']))) {
|
|
27
|
+
const [commit = '', at = '', subject = ''] = l.split('\t');
|
|
28
|
+
if (commit && (subject.startsWith(keep) || pr.test(subject)))
|
|
29
|
+
return { commit, at };
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
/** The bullets of a run summary, without markdown: "- **`a.md`** has a title" → "a.md has a title". */
|
|
34
|
+
export function summarySteps(summary) {
|
|
35
|
+
return lines(summary)
|
|
36
|
+
.filter((l) => /^([-*]|\d+\.)\s+/.test(l))
|
|
37
|
+
.map((l) => l.replace(/^([-*]|\d+\.)\s+/, '').replace(/\*\*|`/g, '').trim())
|
|
38
|
+
.filter((l) => l.length > 0)
|
|
39
|
+
.slice(0, MAX_STEPS);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A summary bullet as a recipe step: no "cli/src/a.ts:272-275:" in front, the first sentence only, about 80
|
|
43
|
+
* characters, capitalized. "src/a.ts:3: approving now closes it. Before, …" → "Approving now closes it."
|
|
44
|
+
*/
|
|
45
|
+
export function plainStep(text) {
|
|
46
|
+
let s = text
|
|
47
|
+
.replace(/^Chompyy card #\d+:\s*/i, '')
|
|
48
|
+
.replace(/^[\w./-]+\.\w+(?::\d+(?:-\d+)?)?\s*[:—–-]\s+/, '')
|
|
49
|
+
.trim();
|
|
50
|
+
if (s.endsWith(':'))
|
|
51
|
+
return ''; // a heading over sub-bullets, not a step
|
|
52
|
+
s = s.split(/(?<=[.!?])\s+(?=[A-Z"(])/)[0].trim();
|
|
53
|
+
if (s.length > STEP_CHARS) {
|
|
54
|
+
const cut = s.slice(0, STEP_CHARS - 1);
|
|
55
|
+
s = cut.slice(0, cut.lastIndexOf(' ') > 40 ? cut.lastIndexOf(' ') : cut.length).replace(/[\s,;:—–-]+$/, '') + '…';
|
|
56
|
+
}
|
|
57
|
+
// "a.ts exports a" stays as it is: a file name keeps its case.
|
|
58
|
+
return /^\S*[./]\S/.test(s) ? s : s.charAt(0).toUpperCase() + s.slice(1);
|
|
59
|
+
}
|
|
60
|
+
export function recipeOf(card) {
|
|
61
|
+
const root = gitRoot(card.cwd);
|
|
62
|
+
const merge = root ? keptMerge(root, card.id) : null;
|
|
63
|
+
let ingredients = [];
|
|
64
|
+
let commits = [];
|
|
65
|
+
if (root && merge) {
|
|
66
|
+
ingredients = lines(git(root, ['diff', '--name-only', `${merge.commit}^1`, merge.commit]));
|
|
67
|
+
commits = lines(git(root, ['log', '--no-merges', '--reverse', '--format=%s', `${merge.commit}^1..${merge.commit}^2`]));
|
|
68
|
+
}
|
|
69
|
+
else if (root && card.run?.branch) {
|
|
70
|
+
// Not merged yet (or merged by hand): read the branch while it's there.
|
|
71
|
+
const base = card.run.base?.commit ?? 'HEAD';
|
|
72
|
+
ingredients = lines(git(root, ['diff', '--name-only', `${base}...${card.run.branch}`]));
|
|
73
|
+
commits = lines(git(root, ['log', '--no-merges', '--reverse', '--format=%s', `${base}..${card.run.branch}`]));
|
|
74
|
+
}
|
|
75
|
+
const own = card.run?.recipe ?? [];
|
|
76
|
+
const fromSummary = summarySteps(card.run?.summary ?? '');
|
|
77
|
+
const steps = own.length ? own : (fromSummary.length ? fromSummary : commits).map(plainStep).filter(Boolean);
|
|
78
|
+
return { ingredients, steps: steps.slice(0, MAX_STEPS), servedAt: merge?.at ?? null };
|
|
79
|
+
}
|
package/dist/stamps.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const STAMPS_PER_CARD = 10;
|
|
2
|
+
export function stampCard(cards) {
|
|
3
|
+
const kept = cards
|
|
4
|
+
.filter((c) => !c.advice && c.outcome === 'kept')
|
|
5
|
+
.map((c) => c.updatedAt)
|
|
6
|
+
.sort();
|
|
7
|
+
const n = kept.length;
|
|
8
|
+
const fullCards = Math.floor(n / STAMPS_PER_CARD);
|
|
9
|
+
const onCard = n % STAMPS_PER_CARD;
|
|
10
|
+
// Just filled a card: show it full until the next stamp starts a new one.
|
|
11
|
+
const full = n > 0 && onCard === 0;
|
|
12
|
+
const stamps = full ? kept.slice(-STAMPS_PER_CARD) : kept.slice(n - onCard);
|
|
13
|
+
return { kept: n, fullCards, stamps, full, toGo: full ? 0 : STAMPS_PER_CARD - onCard };
|
|
14
|
+
}
|
package/dist/triggers.js
CHANGED
|
@@ -19,6 +19,11 @@ export function markFired(key, now, why) {
|
|
|
19
19
|
s.lastDecision = why;
|
|
20
20
|
writeJson(statePath(), s);
|
|
21
21
|
}
|
|
22
|
+
/** Forget a fired key: "Skip tonight" undone. */
|
|
23
|
+
export function unmarkFired(key) {
|
|
24
|
+
const s = loadTriggerState();
|
|
25
|
+
writeJson(statePath(), { ...s, fired: s.fired.filter((k) => k !== key) });
|
|
26
|
+
}
|
|
22
27
|
export function noteTick(now, why) {
|
|
23
28
|
writeJson(statePath(), { ...loadTriggerState(), lastTickAt: now.toISOString(), lastDecision: why });
|
|
24
29
|
}
|
package/dist/usage.js
CHANGED
|
@@ -15,6 +15,7 @@ import { join } from 'node:path';
|
|
|
15
15
|
import { projectsDir } from './dream.js';
|
|
16
16
|
import { homePath, readJson, writeJson } from './home.js';
|
|
17
17
|
import { CLAUDE_PRICES } from './vendor/codeburn/prices.js';
|
|
18
|
+
import { windowFor } from './context.js';
|
|
18
19
|
/** Bump when parsing or pricing changes, so old cached rows are re-read. */
|
|
19
20
|
export const CACHE_VERSION = 3;
|
|
20
21
|
export function usageCachePath() {
|
|
@@ -251,6 +252,8 @@ export function usageView(ledger, now, days = 7, top = 10, canShowTitle = () =>
|
|
|
251
252
|
const models = new Map();
|
|
252
253
|
const convs = new Map();
|
|
253
254
|
const helperOnly = new Set();
|
|
255
|
+
// Per conversation: the last main-session request (its context and model) and the biggest one.
|
|
256
|
+
const ctx = new Map();
|
|
254
257
|
const all = zero();
|
|
255
258
|
for (const r of inRange) {
|
|
256
259
|
add(all, r);
|
|
@@ -270,7 +273,7 @@ export function usageView(ledger, now, days = 7, top = 10, canShowTitle = () =>
|
|
|
270
273
|
helperOnly.add(r.session);
|
|
271
274
|
const away = r.basis === 'recorded';
|
|
272
275
|
const shown = away || canShowTitle(r.workspace);
|
|
273
|
-
c = { ...zero(), session: r.session, title: shown ? ledger.titles[r.session] ?? null : null, workspace: r.workspace, start: r.at, end: r.at, models: [], away, private: !shown };
|
|
276
|
+
c = { ...zero(), session: r.session, title: shown ? ledger.titles[r.session] ?? null : null, workspace: r.workspace, start: r.at, end: r.at, models: [], away, private: !shown, context: 0, window: 0, model: '' };
|
|
274
277
|
convs.set(r.session, c);
|
|
275
278
|
}
|
|
276
279
|
add(c, r);
|
|
@@ -280,6 +283,23 @@ export function usageView(ledger, now, days = 7, top = 10, canShowTitle = () =>
|
|
|
280
283
|
c.end = r.at;
|
|
281
284
|
if (!c.models.includes(r.model))
|
|
282
285
|
c.models.push(r.model);
|
|
286
|
+
// Away runs keep only their totals, never one request's size: no context for them.
|
|
287
|
+
if (!r.agent && r.basis !== 'recorded') {
|
|
288
|
+
const sent = r.input + r.cacheRead + r.cacheWrite5m + r.cacheWrite1h;
|
|
289
|
+
const k = ctx.get(r.session);
|
|
290
|
+
if (!k)
|
|
291
|
+
ctx.set(r.session, { at: r.at, context: sent, model: r.model, peak: sent });
|
|
292
|
+
else {
|
|
293
|
+
k.peak = Math.max(k.peak, sent);
|
|
294
|
+
if (r.at >= k.at)
|
|
295
|
+
Object.assign(k, { at: r.at, context: sent, model: r.model });
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
for (const [session, k] of ctx) {
|
|
300
|
+
const c = convs.get(session);
|
|
301
|
+
if (c)
|
|
302
|
+
Object.assign(c, { context: k.context, window: windowFor(k.model, k.peak), model: k.model });
|
|
283
303
|
}
|
|
284
304
|
const sortTally = (xs) => xs.sort((a, b) => b.total.costUsd - a.total.costUsd);
|
|
285
305
|
const today = dayMap.get(localDay(now.toISOString())) ?? zero();
|