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/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/send.js
CHANGED
|
@@ -20,13 +20,15 @@ const tryGit = (dir, args) => {
|
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
/** The merge commit Keep makes (review.ts keepCard). */
|
|
23
|
-
const KEEP = /^Keep Chompyy card #(\S+): (.*)$/;
|
|
24
|
-
|
|
23
|
+
export const KEEP = /^Keep Chompyy card #(\S+): (.*)$/;
|
|
24
|
+
/** The commit Undo after Keep makes when other commits came after the card (unkeep.ts): it reverses that Keep. */
|
|
25
|
+
export const UNDO = /^Undo Chompyy card #(\S+): (.*)$/;
|
|
26
|
+
export const sentPath = () => homePath('sent.json');
|
|
25
27
|
/** The repo's one .git folder, as a real path: every folder of the repo (and /var vs /private/var) agrees on it. */
|
|
26
28
|
const commonDir = (repo) => realpathSync(resolve(repo, git(repo, ['rev-parse', '--git-common-dir'])));
|
|
27
|
-
const sentKey = (repo, branch) => `${commonDir(repo)}\n${branch}`;
|
|
29
|
+
export const sentKey = (repo, branch) => `${commonDir(repo)}\n${branch}`;
|
|
28
30
|
/** The PRs Send opened for this branch, by card id (a record from before per-card PRs has none). */
|
|
29
|
-
const sentCards = (repo, branch) => (readJson(sentPath(), {})[sentKey(repo, branch)]?.cards ?? {});
|
|
31
|
+
export const sentCards = (repo, branch) => (readJson(sentPath(), {})[sentKey(repo, branch)]?.cards ?? {});
|
|
30
32
|
export const cardBranch = (id) => `chompyy/card-${id}`;
|
|
31
33
|
/** The branches kept cards landed on: one per repo and branch, however many folders the repo has. */
|
|
32
34
|
export function landings(cards) {
|
|
@@ -51,7 +53,7 @@ export function landings(cards) {
|
|
|
51
53
|
return [...out.values()];
|
|
52
54
|
}
|
|
53
55
|
/** Where `branch` goes on GitHub: its upstream's remote and branch, or null when it has none. */
|
|
54
|
-
function upstreamOf(repo, branch) {
|
|
56
|
+
export function upstreamOf(repo, branch) {
|
|
55
57
|
const remote = tryGit(repo, ['config', `branch.${branch}.remote`]);
|
|
56
58
|
const merge = tryGit(repo, ['config', `branch.${branch}.merge`]);
|
|
57
59
|
if (!remote || remote === '.' || !merge?.startsWith('refs/heads/'))
|
|
@@ -67,18 +69,41 @@ export function outbox(repo, branch) {
|
|
|
67
69
|
return outboxAt(repo, branch, up.remote, up.base, tip);
|
|
68
70
|
}
|
|
69
71
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
+
* The branch's own line (first parent) since GitHub's base: Keep's merges still in effect, oldest first, and your own
|
|
73
|
+
* commits. A Keep followed by an Undo of that card is out (a card kept again after its Undo is back in), and the
|
|
74
|
+
* Undo commit isn't counted as yours: together they change nothing.
|
|
72
75
|
*/
|
|
73
|
-
function
|
|
74
|
-
const keeps =
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
function ownLine(repo, tip, upstream) {
|
|
77
|
+
const keeps = [];
|
|
78
|
+
const undone = new Map();
|
|
79
|
+
let own = 0;
|
|
80
|
+
for (const line of git(repo, ['log', '--first-parent', '--format=%P%x09%s', tip, `^${upstream}`]).split('\n')) {
|
|
81
|
+
if (!line)
|
|
82
|
+
continue;
|
|
77
83
|
const tab = line.indexOf('\t');
|
|
78
84
|
const parents = line.slice(0, tab).split(' ');
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
85
|
+
const subject = line.slice(tab + 1);
|
|
86
|
+
const keep = parents.length > 1 ? KEEP.exec(subject) : null;
|
|
87
|
+
const undo = parents.length === 1 ? UNDO.exec(subject) : null;
|
|
88
|
+
if (undo)
|
|
89
|
+
undone.set(undo[1], (undone.get(undo[1]) ?? 0) + 1);
|
|
90
|
+
else if (keep && parents[1]) {
|
|
91
|
+
const left = undone.get(keep[1]) ?? 0;
|
|
92
|
+
if (left)
|
|
93
|
+
undone.set(keep[1], left - 1); // the newest Undo after it took this Keep back
|
|
94
|
+
else
|
|
95
|
+
keeps.unshift({ id: keep[1], title: keep[2], tip: parents[1] });
|
|
96
|
+
}
|
|
97
|
+
else if (parents.length === 1)
|
|
98
|
+
own++;
|
|
99
|
+
}
|
|
100
|
+
return { keeps, own };
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Keep's merges still in effect on the branch whose card isn't on GitHub's base yet. A card counts as there once its
|
|
104
|
+
* own commits are, however they got there: its PR, or an older Send that carried all of main.
|
|
105
|
+
*/
|
|
106
|
+
function unsentKeeps(repo, keeps, upstream) {
|
|
82
107
|
if (!keeps.length)
|
|
83
108
|
return [];
|
|
84
109
|
const missing = new Set(git(repo, ['rev-list', ...keeps.map((k) => k.tip), `^${upstream}`]).split('\n'));
|
|
@@ -87,11 +112,12 @@ function unsentKeeps(repo, tip, upstream) {
|
|
|
87
112
|
function outboxAt(repo, branch, remote, base, tip) {
|
|
88
113
|
const upstream = `refs/remotes/${remote}/${base}`;
|
|
89
114
|
const sent = sentCards(repo, branch);
|
|
90
|
-
const
|
|
115
|
+
const line = ownLine(repo, tip, upstream);
|
|
116
|
+
const cards = unsentKeeps(repo, line.keeps, upstream).map((k) => {
|
|
91
117
|
const rec = sent[k.id];
|
|
92
118
|
return { ...k, pr: rec && rec.tip === k.tip ? { number: rec.number, url: rec.url } : null };
|
|
93
119
|
});
|
|
94
|
-
const own =
|
|
120
|
+
const own = line.own;
|
|
95
121
|
return { repo, branch, remote, base, cards, fresh: cards.filter((c) => !c.pr), own };
|
|
96
122
|
}
|
|
97
123
|
/** Every landing branch with kept cards GitHub doesn't have, for the app (`chompyy state`). */
|
|
@@ -152,9 +178,9 @@ export function checksOf(card) {
|
|
|
152
178
|
const result = card?.run?.verified?.result ?? card?.run?.checks?.result;
|
|
153
179
|
return result === 'passed' ? 'checks passed' : result === 'failed' ? 'checks failed' : null;
|
|
154
180
|
}
|
|
155
|
-
const realGh = (repo, args, input) => execFileSync(exe('gh'), args, { cwd: repo, encoding: 'utf8', input, stdio: [input === undefined ? 'ignore' : 'pipe', 'pipe', 'pipe'] }).trim();
|
|
181
|
+
export const realGh = (repo, args, input) => execFileSync(exe('gh'), args, { cwd: repo, encoding: 'utf8', input, stdio: [input === undefined ? 'ignore' : 'pipe', 'pipe', 'pipe'] }).trim();
|
|
156
182
|
/** The folder that has `branch` checked out, if any. */
|
|
157
|
-
function folderWith(repo, branch) {
|
|
183
|
+
export function folderWith(repo, branch) {
|
|
158
184
|
for (const b of git(repo, ['worktree', 'list', '--porcelain']).split('\n\n')) {
|
|
159
185
|
const dir = b.match(/^worktree (.+)$/m)?.[1];
|
|
160
186
|
if (dir && b.includes(`\nbranch refs/heads/${branch}`))
|
|
@@ -171,10 +197,10 @@ function catchUp(repo, branch, upstream, base, tip) {
|
|
|
171
197
|
const there = git(repo, ['rev-parse', upstream]);
|
|
172
198
|
if (tip === there)
|
|
173
199
|
return { message: `${done}.`, url: null };
|
|
174
|
-
const own =
|
|
200
|
+
const own = ownLine(repo, tip, upstream).own;
|
|
175
201
|
if (own)
|
|
176
202
|
return { message: `${done}. Push your own ${plural(own, 'commit')} on ${branch} yourself: Send only carries kept cards.`, url: null };
|
|
177
|
-
// Your branch may only add Keep's merges: merged into GitHub's base, it would change nothing.
|
|
203
|
+
// Your branch may only add Keep's merges (and Undos of them): merged into GitHub's base, it would change nothing.
|
|
178
204
|
const merged = tryGit(repo, ['merge-tree', '--write-tree', upstream, tip])?.split('\n')[0];
|
|
179
205
|
if (merged !== git(repo, ['rev-parse', `${upstream}^{tree}`]))
|
|
180
206
|
return { message: `${done}. Your ${branch} differs from GitHub's: run git pull there.`, url: null };
|
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/taste.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
// - Never silently deleted: contradicted or removed preferences are retired with the reason and evidence.
|
|
9
9
|
// - Your edits win: delete a learned line from taste.md and the preference is retired.
|
|
10
10
|
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
11
|
+
import { refreshDaytime } from './daytime.js';
|
|
11
12
|
import { appendJsonl, homePath, readJson, writeJson } from './home.js';
|
|
12
13
|
// ---------- taste.md ----------
|
|
13
14
|
export const TASTE_STUB = `# taste.md
|
|
@@ -51,19 +52,76 @@ export function tasteForPrompt() {
|
|
|
51
52
|
const path = tastePath();
|
|
52
53
|
if (!existsSync(path))
|
|
53
54
|
return '';
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
return promptLines(readFileSync(path, 'utf8'), retiredIds()).join('\n').replace(/(## [^\n]+\n)(?=## |$)/g, '').trim();
|
|
56
|
+
}
|
|
57
|
+
function retiredIds() {
|
|
58
|
+
return new Set(loadStore().prefs.filter((p) => p.status === 'retired').map((p) => p.id));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The line filter agents see: bullets and "## " headings only, retired ids dropped, "(learned …)" tails cut.
|
|
62
|
+
* Empty when there are headings but no preferences.
|
|
63
|
+
*/
|
|
64
|
+
function promptLines(text, retired) {
|
|
65
|
+
const kept = text
|
|
56
66
|
.split('\n')
|
|
57
67
|
.filter((l) => {
|
|
58
68
|
const id = l.match(MARK)?.[1];
|
|
59
69
|
return !id || !retired.has(id);
|
|
60
70
|
})
|
|
61
|
-
.map((l) => l.replace(/\s+\((learned|from your history)[^)]*\)\s*$/, ''))
|
|
62
|
-
|
|
71
|
+
.map((l) => l.replace(/\s+\((learned|from your history)[^)]*\)\s*$/, ''))
|
|
72
|
+
.filter((l) => /^\s*[-*]\s+\S/.test(l) || l.startsWith('## '));
|
|
63
73
|
// Only headings, no preferences: nothing to say.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
74
|
+
return kept.some((l) => !l.startsWith('## ')) ? kept : [];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* One project's rules from taste.md text: the "## Everywhere" section plus the "## <project>" section, through
|
|
78
|
+
* the same filter as tasteForPrompt(). Sections with no rules are left out. Empty when neither has a rule.
|
|
79
|
+
*/
|
|
80
|
+
export function tasteRulesFor(text, project, retired = new Set()) {
|
|
81
|
+
const wanted = new Set(['Everywhere', project.trim()]);
|
|
82
|
+
const sections = [];
|
|
83
|
+
let current = null;
|
|
84
|
+
for (const line of promptLines(text, retired)) {
|
|
85
|
+
if (line.startsWith('## ')) {
|
|
86
|
+
current = wanted.has(line.slice(3).trim()) ? [line] : null;
|
|
87
|
+
if (current)
|
|
88
|
+
sections.push(current);
|
|
89
|
+
}
|
|
90
|
+
else
|
|
91
|
+
current?.push(line);
|
|
92
|
+
}
|
|
93
|
+
return sections
|
|
94
|
+
.filter((s) => s.length > 1)
|
|
95
|
+
.map((s) => s.join('\n'))
|
|
96
|
+
.join('\n\n');
|
|
97
|
+
}
|
|
98
|
+
/** tasteRulesFor() on the real taste.md, with retired preferences left out. */
|
|
99
|
+
export function tasteRulesForProject(project) {
|
|
100
|
+
const path = tastePath();
|
|
101
|
+
return existsSync(path) ? tasteRulesFor(readFileSync(path, 'utf8'), project, retiredIds()) : '';
|
|
102
|
+
}
|
|
103
|
+
export const AGENTS_START = '<!-- chompyy:taste:start -->';
|
|
104
|
+
export const AGENTS_END = '<!-- chompyy:taste:end -->';
|
|
105
|
+
/**
|
|
106
|
+
* AGENTS.md text with `rules` between the chompyy taste markers. Replaces an existing block, or appends one at
|
|
107
|
+
* the end. Everything outside the markers is kept byte for byte, so the same rules give back the same text.
|
|
108
|
+
* Throws when the markers are broken (a start without an end, or doubled), rather than guess.
|
|
109
|
+
*/
|
|
110
|
+
export function renderAgentsBlock(text, rules) {
|
|
111
|
+
const block = `${AGENTS_START}\n${rules.trim()}\n${AGENTS_END}`;
|
|
112
|
+
const start = text.indexOf(AGENTS_START);
|
|
113
|
+
const end = text.indexOf(AGENTS_END);
|
|
114
|
+
const count = (m) => text.split(m).length - 1;
|
|
115
|
+
if (start < 0 && end < 0) {
|
|
116
|
+
if (text === '')
|
|
117
|
+
return `${block}\n`;
|
|
118
|
+
const sep = text.endsWith('\n\n') ? '' : text.endsWith('\n') ? '\n' : '\n\n';
|
|
119
|
+
return `${text}${sep}${block}\n`;
|
|
120
|
+
}
|
|
121
|
+
if (start < 0 || end < start || count(AGENTS_START) > 1 || count(AGENTS_END) > 1) {
|
|
122
|
+
throw new Error(`The chompyy taste markers are broken: keep one ${AGENTS_START} line before one ${AGENTS_END} line. Nothing changed.`);
|
|
123
|
+
}
|
|
124
|
+
return text.slice(0, start) + block + text.slice(end + AGENTS_END.length);
|
|
67
125
|
}
|
|
68
126
|
const DAY_MS = 86_400_000;
|
|
69
127
|
/**
|
|
@@ -494,6 +552,8 @@ export function syncTasteFile(now) {
|
|
|
494
552
|
if (out !== text)
|
|
495
553
|
writeFileSync(path, out);
|
|
496
554
|
saveStore(store);
|
|
555
|
+
// Everyday sessions see the change from their next start (only when you turned that on).
|
|
556
|
+
refreshDaytime();
|
|
497
557
|
return retiredByYou;
|
|
498
558
|
}
|
|
499
559
|
// ---------- views ----------
|
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/unkeep.js
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
// Undo after Keep (2026-12-01). Keep merges a card into your local main and Send gives it its own PR, but the only way
|
|
2
|
+
// back was a git command printed by Keep, which only worked right after Keep and never on GitHub. This takes one kept
|
|
3
|
+
// card back wherever it got to, and leaves the cards kept around it alone:
|
|
4
|
+
// - only on this Mac: off your branch (moved back one step when it's the newest, else one Undo commit that reverses
|
|
5
|
+
// it, built off to the side like Keep so your folder never sits in a conflict). Its PR is closed if one is open.
|
|
6
|
+
// - on GitHub's main (its PR merged): a revert PR there (`gh pr revert`); your branch follows when you pull.
|
|
7
|
+
// Send skips a card whose Keep is followed by its Undo (send.ts ownLine), so an undone card is never sent.
|
|
8
|
+
import { execFileSync } from 'node:child_process';
|
|
9
|
+
import { readJson, writeJson } from './home.js';
|
|
10
|
+
import { gitRoot } from './workspace.js';
|
|
11
|
+
import { exe } from './exe.js';
|
|
12
|
+
import { KEEP, UNDO, folderWith, githubRepo, realGh, sentCards, sentKey, sentPath, upstreamOf } from './send.js';
|
|
13
|
+
const git = (dir, args) => execFileSync(exe('git'), ['-C', dir, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
|
|
14
|
+
const tryGit = (dir, args) => {
|
|
15
|
+
try {
|
|
16
|
+
return git(dir, args);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const firstLine = (e) => String(e.stderr || e.message).trim().split('\n')[0].replace(/^(error|fatal): /, '');
|
|
23
|
+
const words = (xs) => (xs.length < 3 ? xs.join(' and ') : `${xs.slice(0, -1).join(', ')} and ${xs.at(-1)}`);
|
|
24
|
+
function find(card) {
|
|
25
|
+
if (card.outcome !== 'kept')
|
|
26
|
+
throw new Error(`Card #${card.id} isn't kept, so there's nothing to take back.`);
|
|
27
|
+
const repo = gitRoot(card.cwd);
|
|
28
|
+
if (!repo)
|
|
29
|
+
throw new Error(`${card.cwd} is no longer a git repo.`);
|
|
30
|
+
const branch = card.run?.base?.branch ?? tryGit(repo, ['symbolic-ref', '--short', 'HEAD']);
|
|
31
|
+
if (!branch)
|
|
32
|
+
throw new Error(`Can't tell which branch card #${card.id} was kept on. Nothing was changed.`);
|
|
33
|
+
const id = card.id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
34
|
+
// The newest Keep or Undo of this card on the branch's own line.
|
|
35
|
+
const latest = tryGit(repo, ['log', '--first-parent', '-E', `--grep=^(Keep|Undo) Chompyy card #${id}: `, '--format=%H %P%x09%s', '-1', `refs/heads/${branch}`]);
|
|
36
|
+
let merge = null;
|
|
37
|
+
let tip = null;
|
|
38
|
+
if (latest) {
|
|
39
|
+
const tab = latest.indexOf('\t');
|
|
40
|
+
const [sha, , second] = latest.slice(0, tab).split(' ');
|
|
41
|
+
if (UNDO.test(latest.slice(tab + 1)))
|
|
42
|
+
throw new Error(`Card #${card.id} is already undone on ${branch}.`);
|
|
43
|
+
if (KEEP.test(latest.slice(tab + 1)) && second)
|
|
44
|
+
[merge, tip] = [sha, second];
|
|
45
|
+
}
|
|
46
|
+
const up = upstreamOf(repo, branch);
|
|
47
|
+
const slug = up ? githubRepo(tryGit(repo, ['config', `remote.${up.remote}.url`]) ?? '') : null;
|
|
48
|
+
const sent = sentCards(repo, branch)[card.id] ?? null;
|
|
49
|
+
return { repo, branch, merge, tip: tip ?? sent?.tip ?? null, up, slug, sent };
|
|
50
|
+
}
|
|
51
|
+
const upstreamRef = (f) => {
|
|
52
|
+
if (!f.up)
|
|
53
|
+
return null;
|
|
54
|
+
const ref = `refs/remotes/${f.up.remote}/${f.up.base}`;
|
|
55
|
+
return tryGit(f.repo, ['rev-parse', '--verify', '-q', ref]) ? ref : null;
|
|
56
|
+
};
|
|
57
|
+
const onGithub = (f) => {
|
|
58
|
+
const upstream = upstreamRef(f);
|
|
59
|
+
return !!(f.tip && upstream && tryGit(f.repo, ['merge-base', '--is-ancestor', f.tip, upstream]) !== null);
|
|
60
|
+
};
|
|
61
|
+
/** Later kept cards on the branch that started on top of this one: their own work carries this card's commits. */
|
|
62
|
+
function builtOn(f, head) {
|
|
63
|
+
if (!f.merge || !f.tip || head === f.merge)
|
|
64
|
+
return [];
|
|
65
|
+
return git(f.repo, ['log', '--first-parent', '--merges', '--reverse', '--format=%P%x09%s', `${f.merge}..${head}`])
|
|
66
|
+
.split('\n')
|
|
67
|
+
.flatMap((line) => {
|
|
68
|
+
const tab = line.indexOf('\t');
|
|
69
|
+
const second = line.slice(0, tab).split(' ')[1];
|
|
70
|
+
const m = KEEP.exec(line.slice(tab + 1));
|
|
71
|
+
return m && second && tryGit(f.repo, ['merge-base', '--is-ancestor', f.tip, second]) !== null ? [m[1]] : [];
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
const builtOnNote = (ids, id) => ids.length ? `Undo card${ids.length === 1 ? '' : 's'} ${words(ids)} too, or ${ids.length === 1 ? 'its' : 'their'} PR brings this work back: ${ids.length === 1 ? 'it was' : 'they were'} built on card ${id}.` : '';
|
|
75
|
+
function planFrom(card, f) {
|
|
76
|
+
if (onGithub(f)) {
|
|
77
|
+
const base = f.up.base;
|
|
78
|
+
if (!f.sent || !f.slug)
|
|
79
|
+
throw new Error(`Revert card ${card.id} on GitHub by hand: it reached ${base} without its own PR, so Chompyy can't take it back alone. Nothing was changed.`);
|
|
80
|
+
return { how: 'revert-pr', line: `Opens a PR on GitHub that reverts PR #${f.sent.number}, which landed card ${card.id} on ${base}. Your ${f.branch} follows once you merge it and pull.` };
|
|
81
|
+
}
|
|
82
|
+
if (!f.merge)
|
|
83
|
+
throw new Error(`Can't find card ${card.id}'s Keep on ${f.branch}: it was reset away or never landed there. Nothing was changed.`);
|
|
84
|
+
const head = git(f.repo, ['rev-parse', `refs/heads/${f.branch}`]);
|
|
85
|
+
const after = head === f.merge ? 0 : Number(git(f.repo, ['rev-list', '--count', '--first-parent', `${f.merge}..${head}`]));
|
|
86
|
+
const take = after
|
|
87
|
+
? `takes card ${card.id} off your ${f.branch} with one Undo commit (${after === 1 ? 'the commit after it stays' : `the ${after} commits after it stay`})`
|
|
88
|
+
: `takes card ${card.id} off your ${f.branch}: it moves back one step, to before the Keep`;
|
|
89
|
+
const first = f.sent ? `Closes PR #${f.sent.number}, then ${take}.` : `${take[0].toUpperCase()}${take.slice(1)}.`;
|
|
90
|
+
return { how: after ? 'reverted' : 'dropped', line: [first, builtOnNote(builtOn(f, head), card.id)].filter(Boolean).join('\n') };
|
|
91
|
+
}
|
|
92
|
+
/** What Undo Keep would do, from what this Mac last fetched (no network, nothing changed). */
|
|
93
|
+
export function planUnkeep(card) {
|
|
94
|
+
return planFrom(card, find(card));
|
|
95
|
+
}
|
|
96
|
+
/** `git merge-tree` of three commits: the merged tree, or the files that conflict. */
|
|
97
|
+
function mergeTree(repo, base, ours, theirs) {
|
|
98
|
+
try {
|
|
99
|
+
return { tree: git(repo, ['merge-tree', '--write-tree', '--name-only', `--merge-base=${base}`, ours, theirs]).split('\n')[0] };
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
const out = String(e.stdout ?? '');
|
|
103
|
+
if (e.status !== 1 || !out)
|
|
104
|
+
throw e;
|
|
105
|
+
const files = [];
|
|
106
|
+
for (const l of out.split('\n').slice(1)) {
|
|
107
|
+
if (!l)
|
|
108
|
+
break;
|
|
109
|
+
files.push(l);
|
|
110
|
+
}
|
|
111
|
+
return { files: [...new Set(files)] };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/** Who changed `files` after the card's Keep: "card 36", or your own commit. */
|
|
115
|
+
function inTheWay(f, head, files) {
|
|
116
|
+
const subjects = git(f.repo, ['log', '--first-parent', '--format=%s', `${f.merge}..${head}`, '--', ...files]).split('\n').filter(Boolean);
|
|
117
|
+
const last = subjects.at(-1) ?? ''; // the first one after the card's Keep
|
|
118
|
+
const keep = KEEP.exec(last) ?? UNDO.exec(last);
|
|
119
|
+
return keep ? { card: keep[1], what: `card ${keep[1]}` } : { card: null, what: `your commit "${last}"` };
|
|
120
|
+
}
|
|
121
|
+
function revertOnGithub(card, f, gh) {
|
|
122
|
+
const n = String(f.sent.number);
|
|
123
|
+
const slug = f.slug;
|
|
124
|
+
const base = f.up.base;
|
|
125
|
+
let state;
|
|
126
|
+
try {
|
|
127
|
+
state = JSON.parse(gh(f.repo, ['pr', 'view', n, '--repo', slug, '--json', 'state'])).state;
|
|
128
|
+
}
|
|
129
|
+
catch (e) {
|
|
130
|
+
throw new Error(`Install GitHub's gh and sign in first (brew install gh, then gh auth login): ${firstLine(e)}. Nothing was changed.`);
|
|
131
|
+
}
|
|
132
|
+
if (state !== 'MERGED')
|
|
133
|
+
throw new Error(`Revert card ${card.id} on GitHub by hand: its work is on ${base}, but PR #${n} didn't merge it. Nothing was changed.`);
|
|
134
|
+
const body = `Undoes kept card ${card.id} (${card.title}), which PR #${n} landed on ${base}. Opened by Undo Keep in Chompyy.\n`;
|
|
135
|
+
let url;
|
|
136
|
+
try {
|
|
137
|
+
url = gh(f.repo, ['pr', 'revert', n, '--repo', slug, '--title', `Undo kept card ${card.id}: ${card.title}`, '--body-file', '-'], body).split('\n').pop().trim();
|
|
138
|
+
}
|
|
139
|
+
catch (e) {
|
|
140
|
+
throw new Error(`Revert PR #${n} on GitHub by hand: gh couldn't (${firstLine(e)}). Nothing was changed.`);
|
|
141
|
+
}
|
|
142
|
+
const number = Number(/\/pull\/(\d+)/.exec(url)?.[1] ?? 0);
|
|
143
|
+
return {
|
|
144
|
+
message: `Merge ${number ? `PR #${number}` : 'the revert PR'} on GitHub to undo card ${card.id}: it reverts PR #${n}. Your ${f.branch} follows when you pull.\n${url}`,
|
|
145
|
+
unkept: { how: 'revert-pr', ...(number ? { pr: { number, url } } : {}) },
|
|
146
|
+
url,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/** Close the card's PR (its work was taken back before it merged) and forget it, so Send never brings it back. */
|
|
150
|
+
function closePr(card, f, gh) {
|
|
151
|
+
const n = f.sent.number;
|
|
152
|
+
const all = readJson(sentPath(), {});
|
|
153
|
+
delete all[sentKey(f.repo, f.branch)]?.cards?.[card.id];
|
|
154
|
+
writeJson(sentPath(), all);
|
|
155
|
+
if (!f.slug)
|
|
156
|
+
return { note: '' };
|
|
157
|
+
try {
|
|
158
|
+
const { state } = JSON.parse(gh(f.repo, ['pr', 'view', String(n), '--repo', f.slug, '--json', 'state']));
|
|
159
|
+
if (state !== 'OPEN')
|
|
160
|
+
return { note: '' };
|
|
161
|
+
gh(f.repo, ['pr', 'close', String(n), '--repo', f.slug, '--delete-branch', '--comment', `Undone in Chompyy: card ${card.id} was taken off ${f.branch} before this merged.`]);
|
|
162
|
+
return { closed: n, note: ` Closed PR #${n}.` };
|
|
163
|
+
}
|
|
164
|
+
catch (e) {
|
|
165
|
+
return { note: ` Close PR #${n} on GitHub yourself: ${firstLine(e)}.` };
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/** Undo Keep: take one kept card back, off your branch or with a revert PR on GitHub (see the top of this file). */
|
|
169
|
+
export function unkeep(card, deps = {}) {
|
|
170
|
+
const gh = deps.gh ?? realGh;
|
|
171
|
+
const f = find(card);
|
|
172
|
+
// GitHub's latest first: whether the card's PR merged there decides how it comes back.
|
|
173
|
+
if (f.up) {
|
|
174
|
+
try {
|
|
175
|
+
git(f.repo, ['fetch', '-q', f.up.remote, `+refs/heads/${f.up.base}:refs/remotes/${f.up.remote}/${f.up.base}`]);
|
|
176
|
+
}
|
|
177
|
+
catch (e) {
|
|
178
|
+
if (f.sent)
|
|
179
|
+
throw new Error(`Connect to the internet and try again: card ${card.id} was sent to GitHub, and Chompyy has to see whether its PR merged (${firstLine(e)}). Nothing was changed.`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const plan = planFrom(card, f);
|
|
183
|
+
if (plan.how === 'revert-pr')
|
|
184
|
+
return revertOnGithub(card, f, gh);
|
|
185
|
+
const merge = f.merge;
|
|
186
|
+
const head = git(f.repo, ['rev-parse', `refs/heads/${f.branch}`]);
|
|
187
|
+
const folder = folderWith(f.repo, f.branch);
|
|
188
|
+
let to;
|
|
189
|
+
if (plan.how === 'dropped') {
|
|
190
|
+
to = git(f.repo, ['rev-parse', `${merge}^1`]);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
// Reverse just this Keep on top of everything after it, without touching a folder: a conflict changes nothing.
|
|
194
|
+
const r = mergeTree(f.repo, merge, head, `${merge}^1`);
|
|
195
|
+
if ('files' in r) {
|
|
196
|
+
const who = inTheWay(f, head, r.files);
|
|
197
|
+
const shown = r.files.slice(0, 3).join(', ') + (r.files.length > 3 ? ` and ${r.files.length - 3} more` : '');
|
|
198
|
+
throw new Error(`${who.card ? `Undo card ${who.card} first` : `Take card ${card.id} back by hand`}: ${who.what} changed the same lines in ${shown} after card ${card.id}. Nothing was changed.`);
|
|
199
|
+
}
|
|
200
|
+
to = git(f.repo, ['commit-tree', r.tree, '-p', head, '-m', `Undo Chompyy card #${card.id}: ${card.title}`, '-m', `Reverses ${merge.slice(0, 7)}, the Keep of card #${card.id}.`]);
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
// In the folder that has the branch open, your unsaved changes stay; git refuses if they touch the same files.
|
|
204
|
+
if (folder)
|
|
205
|
+
git(folder, plan.how === 'dropped' ? ['reset', '-q', '--keep', to] : ['merge', '-q', '--ff-only', to]);
|
|
206
|
+
else
|
|
207
|
+
git(f.repo, ['update-ref', `refs/heads/${f.branch}`, to, head]);
|
|
208
|
+
}
|
|
209
|
+
catch (e) {
|
|
210
|
+
throw new Error(`Commit or set aside your unsaved changes in ${folder ?? f.repo} first: they touch files card ${card.id} changed (${firstLine(e)}). Nothing was changed.`);
|
|
211
|
+
}
|
|
212
|
+
const pr = f.sent ? closePr(card, f, gh) : { note: '' };
|
|
213
|
+
const did = plan.how === 'dropped' ? `your ${f.branch} moved back one step, to before its Keep` : `one Undo commit on ${f.branch} reverses it, and the commits after it stay`;
|
|
214
|
+
const later = builtOnNote(builtOn(f, head), card.id);
|
|
215
|
+
return {
|
|
216
|
+
message: [`Undone #${card.id} after Keep: ${did}.${pr.note}`, later].filter(Boolean).join('\n'),
|
|
217
|
+
unkept: { how: plan.how, ...(pr.closed ? { closed: pr.closed } : {}) },
|
|
218
|
+
url: null,
|
|
219
|
+
};
|
|
220
|
+
}
|
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();
|