chompyy 0.4.7 → 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 +40 -6
- package/dist/advice.js +2 -1
- package/dist/agentlimits.js +77 -0
- package/dist/agentusage.js +96 -0
- package/dist/appstate.js +72 -5
- package/dist/away.js +44 -5
- package/dist/blueprint.js +3 -7
- package/dist/board.js +4 -0
- package/dist/cli.js +328 -15
- 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/daytime.js +68 -0
- package/dist/demon.js +20 -0
- package/dist/didwork.js +46 -0
- package/dist/label.js +33 -0
- package/dist/learning.js +35 -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/send.js +46 -20
- package/dist/stamps.js +14 -0
- package/dist/taste.js +67 -7
- package/dist/triggers.js +5 -0
- package/dist/unkeep.js +220 -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 +11 -3
package/dist/context.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How full a conversation's context window is: the tokens its last request sent, out of the window its model has.
|
|
3
|
+
*
|
|
4
|
+
* The window depends on the model and on how it was run. Claude models have a 200k window by default; some run
|
|
5
|
+
* with 1M (Claude Code's `[1m]` models), and the transcript doesn't say which. So a conversation that ever sent more
|
|
6
|
+
* than the default must be on the bigger window. Other agents' models get their own default here when Chompyy
|
|
7
|
+
* reads them (provider switching).
|
|
8
|
+
*/
|
|
9
|
+
export const DEFAULT_WINDOW = 200_000;
|
|
10
|
+
export const LONG_WINDOW = 1_000_000;
|
|
11
|
+
/** Default windows by model family (prefix match, first wins). Unknown models get DEFAULT_WINDOW. */
|
|
12
|
+
// Only Claude for now. Other agents' rows come with provider switching, from LiteLLM's max_input_tokens (the same
|
|
13
|
+
// snapshot codeburn bundles for prices).
|
|
14
|
+
const WINDOWS = [['claude-', DEFAULT_WINDOW]];
|
|
15
|
+
/** The window a conversation runs in: its model's default, or 1M once it has sent more than that. */
|
|
16
|
+
export function windowFor(model, peak) {
|
|
17
|
+
const base = WINDOWS.find(([p]) => model.startsWith(p))?.[1] ?? DEFAULT_WINDOW;
|
|
18
|
+
return peak > base ? Math.max(LONG_WINDOW, base) : base;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Claude Code compacts on its own a little before the window is full (it keeps room for the summary), so the jar
|
|
22
|
+
* reads full at this share: the time to compact yourself, on your terms, is just before.
|
|
23
|
+
*/
|
|
24
|
+
export const FULL_AT = 0.9;
|
|
25
|
+
/** 0...1: how full the jar is (1 = where the agent would compact by itself). */
|
|
26
|
+
export function fill(context, window) {
|
|
27
|
+
if (window <= 0)
|
|
28
|
+
return 0;
|
|
29
|
+
return Math.max(0, Math.min(1, context / (window * FULL_AT)));
|
|
30
|
+
}
|
package/dist/costs.js
CHANGED
package/dist/daytime.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Taste in daytime sessions: the rules you said yes to, in a file Claude Code loads at every session start.
|
|
2
|
+
//
|
|
3
|
+
// Chompyy writes its own file (~/.chompyy/taste-for-claude.md) and adds one import line to your user CLAUDE.md,
|
|
4
|
+
// inside the chompyy:taste markers. After that it only ever rewrites its own file: a yes, a retire or an edit to
|
|
5
|
+
// taste.md shows up in the next session without touching CLAUDE.md again. Off takes the line out and leaves
|
|
6
|
+
// everything else in CLAUDE.md as it was.
|
|
7
|
+
import { existsSync, readFileSync, rmSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
8
|
+
import { homedir } from 'node:os';
|
|
9
|
+
import { dirname, join } from 'node:path';
|
|
10
|
+
import { homePath, readJson, writeJson } from './home.js';
|
|
11
|
+
import { AGENTS_END, AGENTS_START, renderAgentsBlock, tasteForPrompt } from './taste.js';
|
|
12
|
+
export const claudeMdPath = () => join(homedir(), '.claude', 'CLAUDE.md');
|
|
13
|
+
const statePath = () => homePath('daytime.json');
|
|
14
|
+
export const daytimeFile = () => homePath('taste-for-claude.md');
|
|
15
|
+
export const daytimeState = () => readJson(statePath(), { on: false });
|
|
16
|
+
/** `~/…` when under your home folder: the import line reads the same on any Mac. */
|
|
17
|
+
const tilde = (p) => (p.startsWith(`${homedir()}/`) ? `~${p.slice(homedir().length)}` : p);
|
|
18
|
+
const HEADER = '# How I like work done (learned by Chompyy)\n\nFollow these. A section named after a project applies only in that project.';
|
|
19
|
+
/** The text Claude Code loads: your taste.md rules through the same filter as away runs (retired ones left out). */
|
|
20
|
+
export function daytimeText(rules = tasteForPrompt()) {
|
|
21
|
+
return rules ? `${HEADER}\n\n${rules}\n` : `${HEADER}\n\n(No rules yet: say yes to one in Chompyy.)\n`;
|
|
22
|
+
}
|
|
23
|
+
/** Rough size, so turning it on says what it costs at each session start (about 4 characters a token). */
|
|
24
|
+
export const daytimeTokens = (text) => Math.ceil(text.length / 4);
|
|
25
|
+
/** Rewrite Chompyy's own file when it's on. Called after every taste change. */
|
|
26
|
+
export function refreshDaytime() {
|
|
27
|
+
if (!daytimeState().on)
|
|
28
|
+
return;
|
|
29
|
+
const path = daytimeFile();
|
|
30
|
+
const text = daytimeText();
|
|
31
|
+
if (!existsSync(path) || readFileSync(path, 'utf8') !== text)
|
|
32
|
+
writeFileSync(path, text);
|
|
33
|
+
}
|
|
34
|
+
/** CLAUDE.md text with the chompyy:taste block taken out, and the blank line before it. */
|
|
35
|
+
export function removeBlock(text) {
|
|
36
|
+
const start = text.indexOf(AGENTS_START);
|
|
37
|
+
const end = text.indexOf(AGENTS_END);
|
|
38
|
+
if (start < 0 || end < start)
|
|
39
|
+
return text;
|
|
40
|
+
const before = text.slice(0, start).replace(/\n+$/, text.slice(0, start).trim() ? '\n' : '');
|
|
41
|
+
const after = text.slice(end + AGENTS_END.length).replace(/^\n/, '');
|
|
42
|
+
return before + (before && after ? '\n' : '') + after;
|
|
43
|
+
}
|
|
44
|
+
export function setDaytime(on, claudeMd = claudeMdPath()) {
|
|
45
|
+
const before = existsSync(claudeMd) ? readFileSync(claudeMd, 'utf8') : null;
|
|
46
|
+
const shown = tilde(claudeMd);
|
|
47
|
+
if (on) {
|
|
48
|
+
writeJson(statePath(), { on: true, claudeMd });
|
|
49
|
+
const text = daytimeText();
|
|
50
|
+
writeFileSync(daytimeFile(), text);
|
|
51
|
+
const after = renderAgentsBlock(before ?? '', `@${tilde(daytimeFile())}`);
|
|
52
|
+
if (after !== before) {
|
|
53
|
+
if (before !== null)
|
|
54
|
+
writeFileSync(`${claudeMd}.chompyy-backup`, before);
|
|
55
|
+
mkdirSync(dirname(claudeMd), { recursive: true });
|
|
56
|
+
writeFileSync(claudeMd, after);
|
|
57
|
+
}
|
|
58
|
+
return `Taste in everyday sessions on: new Claude Code sessions load your rules (~${daytimeTokens(text)} tokens each start).\nOne import line in ${shown}; nothing else there changed.`;
|
|
59
|
+
}
|
|
60
|
+
writeJson(statePath(), { on: false });
|
|
61
|
+
rmSync(daytimeFile(), { force: true });
|
|
62
|
+
if (before !== null) {
|
|
63
|
+
const after = removeBlock(before);
|
|
64
|
+
if (after !== before)
|
|
65
|
+
writeFileSync(claudeMd, after);
|
|
66
|
+
}
|
|
67
|
+
return `Taste in everyday sessions off: Chompyy's line is out of ${shown}. Away runs still use your taste.`;
|
|
68
|
+
}
|
package/dist/demon.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { formatDuration } from './duration.js';
|
|
2
|
+
/** Offer only in the last 90 minutes: earlier, the window is still yours to use. */
|
|
3
|
+
export const OFFER_WITHIN_MS = 90 * 60_000;
|
|
4
|
+
/** Less than this and an away run can't finish a card. */
|
|
5
|
+
const MIN_RUN_MS = 15 * 60_000;
|
|
6
|
+
/** Stop a few minutes before the reset, so the last card isn't cut off by it. */
|
|
7
|
+
const SLACK_MS = 5 * 60_000;
|
|
8
|
+
/** Worth a demon only when at least this much would go to waste. */
|
|
9
|
+
export const MIN_UNUSED_PCT = 20;
|
|
10
|
+
export function demonOffer(five, forecast, approved, awayBusy) {
|
|
11
|
+
if (!five.known || approved < 1 || awayBusy)
|
|
12
|
+
return null;
|
|
13
|
+
if (five.msLeft > OFFER_WITHIN_MS || five.msLeft - SLACK_MS < MIN_RUN_MS)
|
|
14
|
+
return null;
|
|
15
|
+
const unusedPct = forecast.kind === 'unused' ? forecast.unusedPct : forecast.kind === 'unknown' ? five.leftPct : 0;
|
|
16
|
+
if (unusedPct < MIN_UNUSED_PCT)
|
|
17
|
+
return null;
|
|
18
|
+
const runMs = Math.floor((five.msLeft - SLACK_MS) / (5 * 60_000)) * 5 * 60_000;
|
|
19
|
+
return { unusedPct: Math.round(unusedPct), resetsAt: five.resetsAt, cards: approved, duration: formatDuration(runMs) };
|
|
20
|
+
}
|
package/dist/didwork.js
CHANGED
|
@@ -411,6 +411,52 @@ function shareLabel(a) {
|
|
|
411
411
|
return 'MEMORY.md compressed';
|
|
412
412
|
return 'Other fix';
|
|
413
413
|
}
|
|
414
|
+
/**
|
|
415
|
+
* Only what was counted goes in: each stop's next request, and each re-counted fix times the sessions that started
|
|
416
|
+
* after it (every stop since the first, even across an off-and-on, unlike the verdict's clean before). Before-vs-after readings (habits, the cold-return trend) can't separate a fix from the rest of the week,
|
|
417
|
+
* so they stay beside the total, never in it (M1). A settings change altered since isn't claimed (M3).
|
|
418
|
+
*/
|
|
419
|
+
export function savedTotal(cards, stops, s, now) {
|
|
420
|
+
const counted = cards.filter((c) => {
|
|
421
|
+
const r = c.advice?.result;
|
|
422
|
+
return r?.method === 'recount' && r.per === 'session start' && r.saved !== undefined && r.verdict !== 'cant-tell' && r.verdict !== 'too-early' && (r.provenance ?? 'intact') === 'intact';
|
|
423
|
+
});
|
|
424
|
+
if (!counted.length && !stops)
|
|
425
|
+
return null;
|
|
426
|
+
let tokens = 0;
|
|
427
|
+
let starts = 0;
|
|
428
|
+
for (const c of counted) {
|
|
429
|
+
const n = sessionsIn(s, startOf(c), now + 1).length;
|
|
430
|
+
starts += n;
|
|
431
|
+
tokens += c.advice.result.saved * n;
|
|
432
|
+
}
|
|
433
|
+
const nudge = stops?.saved ?? 0;
|
|
434
|
+
const since = Math.min(...counted.map(startOf), stops?.since ?? Infinity);
|
|
435
|
+
const total = nudge + tokens;
|
|
436
|
+
const parts = [
|
|
437
|
+
...(stops ? [`live suggestions ~${k(nudge)}`] : []),
|
|
438
|
+
...(counted.length ? [`${plural(counted.length, 'fix', 'fixes')} ~${k(tokens)} over ${plural(starts, 'session start')}`] : []),
|
|
439
|
+
];
|
|
440
|
+
const head = total >= 0 ? `Saved so far: ~${k(total)} tokens since ${day(since)}` : `Cost so far: ~${k(-total)} tokens since ${day(since)}`;
|
|
441
|
+
return { tokens: total, since: new Date(since).toISOString(), nudge, fixes: { count: counted.length, tokens, starts }, line: `${head} (${parts.join(', ')}).` };
|
|
442
|
+
}
|
|
443
|
+
/** Live suggestions' proof and the running total, from one transcript scan long enough for both. */
|
|
444
|
+
export function savedSoFar(cards, now, opts = {}) {
|
|
445
|
+
const events = loadNudges();
|
|
446
|
+
const since = nudgeOnSince(events);
|
|
447
|
+
// The total counts every stop, the same way as the panel's "saved this week" line; the verdict keeps its own start.
|
|
448
|
+
const counted = [...outcomes(events), ...warnOutcomes(events)];
|
|
449
|
+
const stops = counted.length ? { saved: counted.reduce((a, o) => a + o.saved, 0), since: Math.min(...counted.map((o) => Date.parse(o.event.at))) } : null;
|
|
450
|
+
const starts = cards.filter((c) => c.advice?.result?.method === 'recount').map(startOf);
|
|
451
|
+
const earliest = Math.min(since ?? Infinity, stops?.since ?? Infinity, ...starts);
|
|
452
|
+
if (earliest === Infinity)
|
|
453
|
+
return { proof: null, total: null };
|
|
454
|
+
const t = now.getTime();
|
|
455
|
+
const root = opts.root ?? projectsDir();
|
|
456
|
+
const s = scan({ days: Math.max(30, Math.ceil((t - earliest) / DAY) + 8), now, root });
|
|
457
|
+
const proof = (opts.on ?? true) && since ? nudgeProof(now, { root, events, s }) : null;
|
|
458
|
+
return { proof, total: savedTotal(cards, stops, s, t) };
|
|
459
|
+
}
|
|
414
460
|
const VERDICT_WORD = { 'too-early': 'too early', worked: 'worked', short: 'fell short', 'no-change': 'no change', worse: 'went the wrong way', 'cant-tell': "can't tell" };
|
|
415
461
|
/** The numbers only: before → after, the method, the verdict or the day it comes. */
|
|
416
462
|
function shareNumbers(a, r) {
|
package/dist/label.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const WEEK = 7 * 86_400_000;
|
|
2
|
+
export function nutritionLabel(rows, resentTokens, now) {
|
|
3
|
+
const t = now.getTime();
|
|
4
|
+
const from = new Date(t - WEEK).toISOString();
|
|
5
|
+
const to = now.toISOString();
|
|
6
|
+
let input = 0, output = 0, cacheRead = 0, cacheWrite = 0, costUsd = 0;
|
|
7
|
+
const sessions = new Set();
|
|
8
|
+
for (const r of rows) {
|
|
9
|
+
if (r.at < from || r.at > to)
|
|
10
|
+
continue;
|
|
11
|
+
input += r.input;
|
|
12
|
+
output += r.output;
|
|
13
|
+
cacheRead += r.cacheRead;
|
|
14
|
+
cacheWrite += r.cacheWrite5m + r.cacheWrite1h;
|
|
15
|
+
costUsd += r.costUsd;
|
|
16
|
+
if (!r.session.startsWith('chompyy-card-'))
|
|
17
|
+
sessions.add(r.session);
|
|
18
|
+
}
|
|
19
|
+
const tokens = input + output + cacheRead + cacheWrite;
|
|
20
|
+
const pct = (n) => (tokens ? Math.round((n / tokens) * 1000) / 10 : 0);
|
|
21
|
+
const sugar = Math.min(resentTokens, cacheWrite);
|
|
22
|
+
const lines = [
|
|
23
|
+
{ name: 'Cached reads', kind: 'fibre', tokens: cacheRead, pct: pct(cacheRead) },
|
|
24
|
+
{ name: 'Cache writes', kind: 'carbs', tokens: cacheWrite, pct: pct(cacheWrite) },
|
|
25
|
+
{ name: 'Resent after a break', kind: 'added sugar', tokens: sugar, pct: pct(sugar), sub: true },
|
|
26
|
+
{ name: 'Fresh input', kind: 'protein', tokens: input, pct: pct(input) },
|
|
27
|
+
{ name: 'Output', kind: 'protein', tokens: output, pct: pct(output) },
|
|
28
|
+
];
|
|
29
|
+
const tip = sugar > 0
|
|
30
|
+
? 'Cut the sugar: /compact before a long break, so the next message doesn\'t resend it all.'
|
|
31
|
+
: 'No added sugar this week. Nicely baked.';
|
|
32
|
+
return { from, to, tokens, costUsd: Math.round(costUsd * 100) / 100, servings: sessions.size, lines, tip };
|
|
33
|
+
}
|
package/dist/learning.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const WEEK = 7 * 86_400_000;
|
|
2
|
+
/** Conversations read in each week before the correction rate is compared. */
|
|
3
|
+
export const MIN_READ = 5;
|
|
4
|
+
export function learning(store, signals, readThrough, waiting, now) {
|
|
5
|
+
const t = now.getTime();
|
|
6
|
+
const inWeek = (at, back) => {
|
|
7
|
+
const x = Date.parse(at);
|
|
8
|
+
return x >= t - (back + 1) * WEEK && x < t - back * WEEK;
|
|
9
|
+
};
|
|
10
|
+
const active = store.prefs.filter((p) => p.status === 'active');
|
|
11
|
+
const learnedThisWeek = active.filter((p) => p.validFrom && inWeek(p.validFrom, 0)).length;
|
|
12
|
+
const chats = signals.filter((s) => s.kind === 'chat');
|
|
13
|
+
const reads = Object.values(readThrough);
|
|
14
|
+
const c = {
|
|
15
|
+
thisWeek: chats.filter((s) => inWeek(s.at, 0)).length,
|
|
16
|
+
lastWeek: chats.filter((s) => inWeek(s.at, 1)).length,
|
|
17
|
+
readThisWeek: reads.filter((at) => inWeek(at, 0)).length,
|
|
18
|
+
readLastWeek: reads.filter((at) => inWeek(at, 1)).length,
|
|
19
|
+
perThis: null,
|
|
20
|
+
perLast: null,
|
|
21
|
+
};
|
|
22
|
+
if (c.readThisWeek >= MIN_READ && c.readLastWeek >= MIN_READ) {
|
|
23
|
+
c.perThis = c.thisWeek / c.readThisWeek;
|
|
24
|
+
c.perLast = c.lastWeek / c.readLastWeek;
|
|
25
|
+
}
|
|
26
|
+
const rules = (n) => `${n} rule${n === 1 ? '' : 's'}`;
|
|
27
|
+
const head = active.length
|
|
28
|
+
? `Chompyy learned ${learnedThisWeek ? `${rules(learnedThisWeek)} this week (${active.length} in all)` : `${rules(active.length)} so far, none new this week`}`
|
|
29
|
+
: 'Chompyy has no rules yet';
|
|
30
|
+
const wait = waiting ? `; ${waiting} wait${waiting === 1 ? 's' : ''} for your yes` : '';
|
|
31
|
+
const rate = c.perThis !== null && c.perLast !== null
|
|
32
|
+
? ` Corrections per conversation: ${c.perLast.toFixed(1)} → ${c.perThis.toFixed(1)}.`
|
|
33
|
+
: ` Corrections per conversation: not enough read yet (${c.readThisWeek} this week, needs ${MIN_READ}).`;
|
|
34
|
+
return { learned: active.length, learnedThisWeek, waiting, corrections: c, line: `${head}${wait}.${rate}` };
|
|
35
|
+
}
|
package/dist/menu.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const DAYS = 30;
|
|
2
|
+
export function menuFrom(claude, agents, now) {
|
|
3
|
+
const items = [
|
|
4
|
+
{ name: 'Claude Code', tokens: claude.tokens, costUsd: claude.costUsd, model: claude.model },
|
|
5
|
+
...agents.map((a) => ({ name: a.displayName, tokens: a.month.tokens, costUsd: a.month.costUsd, model: a.models[0] ?? null })),
|
|
6
|
+
]
|
|
7
|
+
.filter((i) => i.tokens > 0)
|
|
8
|
+
.sort((a, b) => b.tokens - a.tokens);
|
|
9
|
+
const total = items.reduce((t, i) => ({ tokens: t.tokens + i.tokens, costUsd: t.costUsd + i.costUsd }), { tokens: 0, costUsd: 0 });
|
|
10
|
+
return {
|
|
11
|
+
from: new Date(now.getTime() - DAYS * 86_400_000).toISOString(),
|
|
12
|
+
to: now.toISOString(),
|
|
13
|
+
items,
|
|
14
|
+
total,
|
|
15
|
+
special: items[0]?.model ?? null,
|
|
16
|
+
};
|
|
17
|
+
}
|
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
|
+
}
|