chompyy 0.4.6 → 0.5.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 +43 -19
- package/dist/advice.js +2 -1
- package/dist/appstate.js +11 -3
- package/dist/board.js +7 -0
- package/dist/cli.js +95 -24
- package/dist/daytime.js +68 -0
- package/dist/deps.js +3 -2
- package/dist/didwork.js +46 -0
- package/dist/dream.js +2 -1
- package/dist/exe.js +34 -0
- package/dist/learning.js +35 -0
- package/dist/live.js +4 -3
- package/dist/livequota.js +2 -1
- package/dist/macapp.js +2 -1
- package/dist/nudge.js +9 -5
- package/dist/picture.js +2 -1
- package/dist/preflight.js +2 -1
- package/dist/quota.js +10 -0
- package/dist/refresh.js +2 -1
- package/dist/report.js +6 -0
- package/dist/review.js +2 -1
- package/dist/runner.js +3 -2
- package/dist/send.js +172 -92
- package/dist/statusline.js +110 -0
- package/dist/suggest.js +3 -2
- package/dist/taste-merge.js +79 -0
- package/dist/taste.js +106 -10
- package/dist/triggers.js +2 -1
- package/dist/unkeep.js +220 -0
- package/dist/verify.js +4 -1
- package/dist/verifycard.js +166 -46
- package/dist/workspace.js +3 -2
- package/package.json +11 -3
package/dist/send.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
// Send kept cards (2026-11-30). Keep merges a card into your local main and stops there, so kept work only
|
|
2
|
-
// reached GitHub when someone pushed it by hand (five cards sat on one Mac that way). Send
|
|
3
|
-
//
|
|
4
|
-
//
|
|
2
|
+
// reached GitHub when someone pushed it by hand (five cards sat on one Mac that way). Send gives every kept card
|
|
3
|
+
// GitHub's main doesn't have its own pull request, from Chompyy's branch chompyy/card-<id> holding the card's own
|
|
4
|
+
// commits, so you merge, skip or revert each card alone on GitHub. (It was one PR for all of them until the user
|
|
5
|
+
// asked for one per card, 2026-11-30.) It never pushes main itself. Once every kept card is on GitHub's main, Send
|
|
6
|
+
// moves your main to match it, so the two don't drift apart.
|
|
5
7
|
import { execFileSync } from 'node:child_process';
|
|
6
8
|
import { realpathSync } from 'node:fs';
|
|
7
9
|
import { resolve } from 'node:path';
|
|
8
10
|
import { homePath, readJson, writeJson } from './home.js';
|
|
9
11
|
import { gitRoot } from './workspace.js';
|
|
10
|
-
|
|
12
|
+
import { exe } from './exe.js';
|
|
13
|
+
const git = (dir, args) => execFileSync(exe('git'), ['-C', dir, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
|
|
11
14
|
const tryGit = (dir, args) => {
|
|
12
15
|
try {
|
|
13
16
|
return git(dir, args);
|
|
@@ -17,11 +20,16 @@ const tryGit = (dir, args) => {
|
|
|
17
20
|
}
|
|
18
21
|
};
|
|
19
22
|
/** The merge commit Keep makes (review.ts keepCard). */
|
|
20
|
-
const KEEP = /^Keep Chompyy card #(\S+): (.*)$/;
|
|
21
|
-
|
|
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');
|
|
22
27
|
/** The repo's one .git folder, as a real path: every folder of the repo (and /var vs /private/var) agrees on it. */
|
|
23
28
|
const commonDir = (repo) => realpathSync(resolve(repo, git(repo, ['rev-parse', '--git-common-dir'])));
|
|
24
|
-
const sentKey = (repo, branch) => `${commonDir(repo)}\n${branch}`;
|
|
29
|
+
export const sentKey = (repo, branch) => `${commonDir(repo)}\n${branch}`;
|
|
30
|
+
/** The PRs Send opened for this branch, by card id (a record from before per-card PRs has none). */
|
|
31
|
+
export const sentCards = (repo, branch) => (readJson(sentPath(), {})[sentKey(repo, branch)]?.cards ?? {});
|
|
32
|
+
export const cardBranch = (id) => `chompyy/card-${id}`;
|
|
25
33
|
/** The branches kept cards landed on: one per repo and branch, however many folders the repo has. */
|
|
26
34
|
export function landings(cards) {
|
|
27
35
|
const roots = new Map();
|
|
@@ -45,7 +53,7 @@ export function landings(cards) {
|
|
|
45
53
|
return [...out.values()];
|
|
46
54
|
}
|
|
47
55
|
/** Where `branch` goes on GitHub: its upstream's remote and branch, or null when it has none. */
|
|
48
|
-
function upstreamOf(repo, branch) {
|
|
56
|
+
export function upstreamOf(repo, branch) {
|
|
49
57
|
const remote = tryGit(repo, ['config', `branch.${branch}.remote`]);
|
|
50
58
|
const merge = tryGit(repo, ['config', `branch.${branch}.merge`]);
|
|
51
59
|
if (!remote || remote === '.' || !merge?.startsWith('refs/heads/'))
|
|
@@ -60,22 +68,57 @@ export function outbox(repo, branch) {
|
|
|
60
68
|
return null;
|
|
61
69
|
return outboxAt(repo, branch, up.remote, up.base, tip);
|
|
62
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.
|
|
75
|
+
*/
|
|
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;
|
|
83
|
+
const tab = line.indexOf('\t');
|
|
84
|
+
const parents = line.slice(0, tab).split(' ');
|
|
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) {
|
|
107
|
+
if (!keeps.length)
|
|
108
|
+
return [];
|
|
109
|
+
const missing = new Set(git(repo, ['rev-list', ...keeps.map((k) => k.tip), `^${upstream}`]).split('\n'));
|
|
110
|
+
return keeps.filter((k) => missing.has(k.tip));
|
|
111
|
+
}
|
|
63
112
|
function outboxAt(repo, branch, remote, base, tip) {
|
|
64
|
-
const sendBranch = `chompyy/kept-${base}`;
|
|
65
113
|
const upstream = `refs/remotes/${remote}/${base}`;
|
|
66
|
-
const sent =
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
.
|
|
70
|
-
.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const fresh = sent ? keeps([upstream, sent]) : cards;
|
|
75
|
-
const own = Number(git(repo, ['rev-list', '--count', '--first-parent', '--no-merges', tip, `^${upstream}`]));
|
|
76
|
-
const rec = readJson(sentPath(), {})[sentKey(repo, branch)];
|
|
77
|
-
const pr = rec && fresh.length < cards.length ? { number: rec.number, url: rec.url } : null;
|
|
78
|
-
return { repo, branch, remote, base, sendBranch, cards, fresh, own, pr };
|
|
114
|
+
const sent = sentCards(repo, branch);
|
|
115
|
+
const line = ownLine(repo, tip, upstream);
|
|
116
|
+
const cards = unsentKeeps(repo, line.keeps, upstream).map((k) => {
|
|
117
|
+
const rec = sent[k.id];
|
|
118
|
+
return { ...k, pr: rec && rec.tip === k.tip ? { number: rec.number, url: rec.url } : null };
|
|
119
|
+
});
|
|
120
|
+
const own = line.own;
|
|
121
|
+
return { repo, branch, remote, base, cards, fresh: cards.filter((c) => !c.pr), own };
|
|
79
122
|
}
|
|
80
123
|
/** Every landing branch with kept cards GitHub doesn't have, for the app (`chompyy state`). */
|
|
81
124
|
export function outboxes(cards) {
|
|
@@ -93,7 +136,7 @@ export function outboxes(cards) {
|
|
|
93
136
|
/** Files where `tip` and GitHub's base change the same lines, or [] (git before 2.38 can't tell: then []). */
|
|
94
137
|
export function clashFiles(repo, upstream, tip) {
|
|
95
138
|
try {
|
|
96
|
-
execFileSync('git', ['-C', repo, 'merge-tree', '--write-tree', '--name-only', upstream, tip], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] });
|
|
139
|
+
execFileSync(exe('git'), ['-C', repo, 'merge-tree', '--write-tree', '--name-only', upstream, tip], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] });
|
|
97
140
|
return [];
|
|
98
141
|
}
|
|
99
142
|
catch (e) {
|
|
@@ -114,27 +157,20 @@ export function githubRepo(url) {
|
|
|
114
157
|
return /github\.com[:/]+([^/\s]+\/[^/\s]+?)(?:\.git)?\/?$/.exec(url.trim())?.[1] ?? null;
|
|
115
158
|
}
|
|
116
159
|
const plural = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
|
|
160
|
+
const fileList = (files) => files.slice(0, 3).join(', ') + (files.length > 3 ? ` and ${files.length - 3} more` : '');
|
|
117
161
|
/** No "#31" in GitHub text: GitHub would link card 31 to its own PR or issue #31. */
|
|
118
|
-
export function prTitle(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (ids.length > 5)
|
|
123
|
-
return `Kept cards ${ids.slice(0, 5).join(', ')} and ${ids.length - 5} more`;
|
|
124
|
-
return `Kept cards ${ids.slice(0, -1).join(', ')} and ${ids.at(-1)}`;
|
|
125
|
-
}
|
|
126
|
-
export function prBody(o, checks) {
|
|
162
|
+
export function prTitle(card) {
|
|
163
|
+
return `Kept card ${card.id}: ${card.title}`;
|
|
164
|
+
}
|
|
165
|
+
export function prBody(card, o) {
|
|
127
166
|
const lines = [
|
|
128
|
-
`Merge this to land ${
|
|
129
|
-
'',
|
|
130
|
-
...o.cards.map((c) => {
|
|
131
|
-
const result = checks(c.id);
|
|
132
|
-
return `- card ${c.id}: ${c.title}${result ? ` · ${result}` : ''}`;
|
|
133
|
-
}),
|
|
167
|
+
`Merge this to land card ${card.id} on ${o.base}: ${card.title}${o.checks ? ` (${o.checks})` : ''}. It is already on ${o.branch} on the Mac that sent it, kept with Chompyy.`,
|
|
134
168
|
];
|
|
135
|
-
if (o.
|
|
136
|
-
lines.push('', `
|
|
137
|
-
|
|
169
|
+
if (o.after)
|
|
170
|
+
lines.push('', `It was built on card ${o.after.id}: merge PR #${o.after.pr} first. Until then this PR shows that card's changes too.`);
|
|
171
|
+
if (o.clash.length)
|
|
172
|
+
lines.push('', `It clashes with ${o.base} in ${fileList(o.clash)}: resolve that here before merging.`);
|
|
173
|
+
lines.push('', 'Each kept card gets its own PR, so you can merge or revert it alone (`chompyy send`).');
|
|
138
174
|
return lines.join('\n');
|
|
139
175
|
}
|
|
140
176
|
/** What the card's checks said, for the PR body: Chompyy's own run of the repo's tests first, else the agent's word. */
|
|
@@ -142,8 +178,45 @@ export function checksOf(card) {
|
|
|
142
178
|
const result = card?.run?.verified?.result ?? card?.run?.checks?.result;
|
|
143
179
|
return result === 'passed' ? 'checks passed' : result === 'failed' ? 'checks failed' : null;
|
|
144
180
|
}
|
|
145
|
-
const realGh = (repo, args, input) => execFileSync('gh', args, { cwd: repo, encoding: 'utf8', input, stdio: [input === undefined ? 'ignore' : 'pipe', 'pipe', 'pipe'] }).trim();
|
|
146
|
-
/**
|
|
181
|
+
export const realGh = (repo, args, input) => execFileSync(exe('gh'), args, { cwd: repo, encoding: 'utf8', input, stdio: [input === undefined ? 'ignore' : 'pipe', 'pipe', 'pipe'] }).trim();
|
|
182
|
+
/** The folder that has `branch` checked out, if any. */
|
|
183
|
+
export function folderWith(repo, branch) {
|
|
184
|
+
for (const b of git(repo, ['worktree', 'list', '--porcelain']).split('\n\n')) {
|
|
185
|
+
const dir = b.match(/^worktree (.+)$/m)?.[1];
|
|
186
|
+
if (dir && b.includes(`\nbranch refs/heads/${branch}`))
|
|
187
|
+
return dir;
|
|
188
|
+
}
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Every kept card is on GitHub's base: move your branch there when that loses nothing, so the two don't drift apart.
|
|
193
|
+
* With per-card PRs GitHub merges each card's own commits, and Keep's merges stay on your branch only.
|
|
194
|
+
*/
|
|
195
|
+
function catchUp(repo, branch, upstream, base, tip) {
|
|
196
|
+
const done = `Nothing to send: GitHub's ${base} has every kept card already`;
|
|
197
|
+
const there = git(repo, ['rev-parse', upstream]);
|
|
198
|
+
if (tip === there)
|
|
199
|
+
return { message: `${done}.`, url: null };
|
|
200
|
+
const own = ownLine(repo, tip, upstream).own;
|
|
201
|
+
if (own)
|
|
202
|
+
return { message: `${done}. Push your own ${plural(own, 'commit')} on ${branch} yourself: Send only carries kept cards.`, url: null };
|
|
203
|
+
// Your branch may only add Keep's merges (and Undos of them): merged into GitHub's base, it would change nothing.
|
|
204
|
+
const merged = tryGit(repo, ['merge-tree', '--write-tree', upstream, tip])?.split('\n')[0];
|
|
205
|
+
if (merged !== git(repo, ['rev-parse', `${upstream}^{tree}`]))
|
|
206
|
+
return { message: `${done}. Your ${branch} differs from GitHub's: run git pull there.`, url: null };
|
|
207
|
+
const folder = folderWith(repo, branch);
|
|
208
|
+
try {
|
|
209
|
+
if (folder)
|
|
210
|
+
git(folder, ['reset', '-q', '--keep', there]); // keeps your unsaved changes; refuses if they'd clash
|
|
211
|
+
else
|
|
212
|
+
git(repo, ['update-ref', `refs/heads/${branch}`, there, tip]);
|
|
213
|
+
}
|
|
214
|
+
catch (e) {
|
|
215
|
+
return { message: `${done}. Your ${branch} couldn't move to GitHub's: ${e.message.split('\n')[0]}`, url: null };
|
|
216
|
+
}
|
|
217
|
+
return { message: `${done}: your ${branch} now matches GitHub's.`, url: null };
|
|
218
|
+
}
|
|
219
|
+
/** Send one landing branch: fetch GitHub's base, then push each kept card's branch and open or update its PR. */
|
|
147
220
|
export function sendOne(repo, branch, cards, deps) {
|
|
148
221
|
const up = upstreamOf(repo, branch);
|
|
149
222
|
if (!up)
|
|
@@ -152,55 +225,72 @@ export function sendOne(repo, branch, cards, deps) {
|
|
|
152
225
|
const slug = githubRepo(tryGit(repo, ['config', `remote.${remote}.url`]) ?? '');
|
|
153
226
|
if (!slug)
|
|
154
227
|
throw new Error(`Send works with GitHub only, and ${remote} isn't on GitHub. Nothing was sent.`);
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
try {
|
|
160
|
-
git(repo, ['fetch', '-q', remote, `+refs/heads/${sendBranch}:${sendRef}`]);
|
|
161
|
-
}
|
|
162
|
-
catch {
|
|
163
|
-
tryGit(repo, ['update-ref', '-d', sendRef]); // gone on GitHub (deleted after its PR merged)
|
|
164
|
-
}
|
|
228
|
+
const upstream = `refs/remotes/${remote}/${base}`;
|
|
229
|
+
// GitHub's latest first, so what's sent is about what is there now. Card branches merged and deleted drop out.
|
|
230
|
+
git(repo, ['fetch', '-q', remote, `+refs/heads/${base}:${upstream}`]);
|
|
231
|
+
tryGit(repo, ['fetch', '-q', '--prune', remote, `+refs/heads/chompyy/card-*:refs/remotes/${remote}/chompyy/card-*`]);
|
|
165
232
|
const tip = git(repo, ['rev-parse', `refs/heads/${branch}`]);
|
|
166
233
|
const o = outboxAt(repo, branch, remote, base, tip);
|
|
167
234
|
if (!o.cards.length)
|
|
168
|
-
return
|
|
169
|
-
const clash = clashFiles(repo, `refs/remotes/${remote}/${base}`, tip);
|
|
170
|
-
if (clash.length) {
|
|
171
|
-
const files = clash.slice(0, 3).join(', ') + (clash.length > 3 ? ` and ${clash.length - 3} more` : '');
|
|
172
|
-
throw new Error(`Merge ${remote}/${base} into your ${branch} first: kept cards clash with it in ${files}.\nNothing was sent.`);
|
|
173
|
-
}
|
|
235
|
+
return catchUp(repo, branch, upstream, base, tip);
|
|
174
236
|
try {
|
|
175
237
|
deps.gh(repo, ['auth', 'status']);
|
|
176
238
|
}
|
|
177
239
|
catch {
|
|
178
240
|
throw new Error("Install GitHub's gh and sign in first: brew install gh, then gh auth login.\nNothing was sent.");
|
|
179
241
|
}
|
|
180
|
-
const
|
|
181
|
-
git(repo, ['push', '-q', `--force-with-lease=refs/heads/${sendBranch}:${lease}`, remote, `${tip}:refs/heads/${sendBranch}`]);
|
|
182
|
-
tryGit(repo, ['update-ref', sendRef, tip]);
|
|
242
|
+
const open = new Map(JSON.parse(deps.gh(repo, ['pr', 'list', '--repo', slug, '--state', 'open', '--json', 'number,url,headRefName', '--limit', '200']) || '[]').map((p) => [p.headRefName, { number: p.number, url: p.url }]));
|
|
183
243
|
const byId = new Map(cards.map((c) => [c.id, c]));
|
|
184
|
-
const
|
|
185
|
-
const
|
|
186
|
-
const open = JSON.parse(deps.gh(repo, ['pr', 'list', '--repo', slug, '--head', sendBranch, '--state', 'open', '--json', 'number,url', '--limit', '1']) || '[]');
|
|
187
|
-
let pr = open[0];
|
|
188
|
-
if (pr) {
|
|
189
|
-
deps.gh(repo, ['pr', 'edit', String(pr.number), '--repo', slug, '--title', title, '--body-file', '-'], body);
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
const url = deps.gh(repo, ['pr', 'create', '--repo', slug, '--base', base, '--head', sendBranch, '--title', title, '--body-file', '-'], body).split('\n').pop().trim();
|
|
193
|
-
pr = { number: Number(/\/pull\/(\d+)/.exec(url)?.[1] ?? 0), url };
|
|
194
|
-
}
|
|
244
|
+
const sent = [];
|
|
245
|
+
const errors = [];
|
|
195
246
|
const all = readJson(sentPath(), {});
|
|
196
|
-
all[sentKey(repo, branch)] = {
|
|
247
|
+
const rec = (all[sentKey(repo, branch)] = { cards: { ...(all[sentKey(repo, branch)]?.cards ?? {}) } });
|
|
248
|
+
for (const [i, card] of o.cards.entries()) {
|
|
249
|
+
const head = cardBranch(card.id);
|
|
250
|
+
const remoteRef = `refs/remotes/${remote}/${head}`;
|
|
251
|
+
try {
|
|
252
|
+
// Built on an earlier kept card that isn't on GitHub yet (it started from your main): its PR carries that
|
|
253
|
+
// card's commits too until that one merges. Based on main still, so merging it can never land elsewhere.
|
|
254
|
+
const reach = new Set(git(repo, ['rev-list', card.tip, `^${upstream}`]).split('\n'));
|
|
255
|
+
const before = o.cards.slice(0, i).filter((e) => reach.has(e.tip)).at(-1);
|
|
256
|
+
const beforePr = before && (sent.find((s) => s.card.id === before.id)?.pr ?? open.get(cardBranch(before.id)));
|
|
257
|
+
const clash = clashFiles(repo, upstream, card.tip);
|
|
258
|
+
const there = tryGit(repo, ['rev-parse', '--verify', '-q', remoteRef]);
|
|
259
|
+
if (there !== card.tip) {
|
|
260
|
+
git(repo, ['push', '-q', `--force-with-lease=refs/heads/${head}:${there ?? ''}`, remote, `${card.tip}:refs/heads/${head}`]);
|
|
261
|
+
tryGit(repo, ['update-ref', remoteRef, card.tip]);
|
|
262
|
+
}
|
|
263
|
+
const body = prBody(card, { base, branch, checks: checksOf(byId.get(card.id)), after: before && beforePr ? { id: before.id, pr: beforePr.number } : null, clash });
|
|
264
|
+
let pr = open.get(head);
|
|
265
|
+
const isNew = !pr;
|
|
266
|
+
if (pr) {
|
|
267
|
+
if (there !== card.tip)
|
|
268
|
+
deps.gh(repo, ['pr', 'edit', String(pr.number), '--repo', slug, '--body-file', '-'], body);
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
const url = deps.gh(repo, ['pr', 'create', '--repo', slug, '--base', base, '--head', head, '--title', prTitle(card), '--body-file', '-'], body).split('\n').pop().trim();
|
|
272
|
+
pr = { number: Number(/\/pull\/(\d+)/.exec(url)?.[1] ?? 0), url };
|
|
273
|
+
}
|
|
274
|
+
rec.cards[card.id] = { number: pr.number, url: pr.url, tip: card.tip, at: deps.now().toISOString() };
|
|
275
|
+
sent.push({ card, pr, isNew, clash });
|
|
276
|
+
}
|
|
277
|
+
catch (e) {
|
|
278
|
+
errors.push(`card ${card.id}: ${e.message.split('\n')[0]}`);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
197
281
|
writeJson(sentPath(), all);
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
282
|
+
if (!sent.length)
|
|
283
|
+
throw new Error(`Nothing was sent: ${errors[0]}`);
|
|
284
|
+
const clashing = sent.filter((s) => s.clash.length).length;
|
|
285
|
+
const fresh = sent.filter((s) => s.isNew).length;
|
|
286
|
+
const url = sent.length === 1 ? sent[0].pr.url : `https://github.com/${slug}/pulls?q=${encodeURIComponent('is:pr is:open "Kept card" in:title')}`;
|
|
287
|
+
const what = sent.length === 1 ? `PR #${sent[0].pr.number}` : `${sent.length} PRs`;
|
|
288
|
+
const how = sent.length === 1 ? ` to land kept card ${sent[0].card.id} on ${base}` : `, one per kept card, to land them on ${base}`;
|
|
289
|
+
const news = fresh === sent.length ? '' : fresh ? ` (${fresh} new)` : sent.length === 1 ? ' (sent before)' : ' (all sent before)';
|
|
290
|
+
const notes = [clashing ? `${plural(clashing, 'clashes', 'clash')} with ${base}: resolve on GitHub` : '', errors.length ? `${plural(errors.length, 'card')} not sent: ${errors[0]}` : '']
|
|
291
|
+
.filter(Boolean)
|
|
292
|
+
.join('; ');
|
|
293
|
+
return { message: `Merge ${what} on GitHub${how}${news}${notes ? `. ${notes}` : ''}.\n${url}`, url };
|
|
204
294
|
}
|
|
205
295
|
/** `chompyy send`: every landing branch with kept cards GitHub doesn't have. */
|
|
206
296
|
export function sendKept(cards, deps = {}) {
|
|
@@ -211,19 +301,9 @@ export function sendKept(cards, deps = {}) {
|
|
|
211
301
|
const linked = ls.filter((l) => upstreamOf(l.repo, l.branch));
|
|
212
302
|
if (!linked.length)
|
|
213
303
|
throw new Error(`Link ${ls[0].branch} to GitHub first (git branch -u origin/${ls[0].branch}): it has no branch there to merge into. Nothing was sent.`);
|
|
214
|
-
// Skip repos whose kept cards were all on GitHub at the last fetch (no network for those). Never fetched: ask.
|
|
215
|
-
const due = linked.filter((l) => {
|
|
216
|
-
try {
|
|
217
|
-
const o = outbox(l.repo, l.branch);
|
|
218
|
-
return o === null || o.cards.length > 0;
|
|
219
|
-
}
|
|
220
|
-
catch {
|
|
221
|
-
return true;
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
304
|
const results = [];
|
|
225
305
|
const errors = [];
|
|
226
|
-
for (const l of
|
|
306
|
+
for (const l of linked) {
|
|
227
307
|
try {
|
|
228
308
|
results.push(sendOne(l.repo, l.branch, cards, d));
|
|
229
309
|
}
|
|
@@ -232,7 +312,7 @@ export function sendKept(cards, deps = {}) {
|
|
|
232
312
|
}
|
|
233
313
|
}
|
|
234
314
|
const sent = results.filter((r) => r.url);
|
|
235
|
-
if (errors.length && !
|
|
315
|
+
if (errors.length && !results.length)
|
|
236
316
|
throw new Error(errors[0]);
|
|
237
317
|
if (!sent.length)
|
|
238
318
|
return results[0] ?? { message: 'Nothing to send: GitHub has every kept card already.', url: null };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// The cache timer in Claude Code's status line (2026-11-30). Claude Code 2.1.251+ hands the status line
|
|
2
|
+
// `prompt_cache`: when the main conversation's cache goes cold and what the next message rewrites then. It re-runs
|
|
3
|
+
// the status line the moment the cache expires, so a clock time ("warm till 14:32") stays true without a refresh
|
|
4
|
+
// timer. The nudge stops the first message after the cache expired; this shows it before you type.
|
|
5
|
+
//
|
|
6
|
+
// `chompyy statusline on` keeps the status line you had: Chompyy runs it on the same input and prints its line
|
|
7
|
+
// above Chompyy's (Orca's, for one, prints nothing and only reports to Orca).
|
|
8
|
+
import { spawnSync } from 'node:child_process';
|
|
9
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
10
|
+
import { homedir } from 'node:os';
|
|
11
|
+
import { dirname } from 'node:path';
|
|
12
|
+
import { homePath } from './home.js';
|
|
13
|
+
import { claudeSettingsPath, MIN_CONTEXT, readSettings, selfCommand } from './nudge.js';
|
|
14
|
+
const MARK = '# chompyy statusline';
|
|
15
|
+
const k = (n) => (n >= 1e6 ? `${(n / 1e6).toFixed(1)}M` : `${Math.round(n / 1000)}k`);
|
|
16
|
+
const hhmm = (ms) => new Date(ms).toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit' });
|
|
17
|
+
/**
|
|
18
|
+
* The cache part of the line, or null when there's nothing worth saying: a conversation too small for a cold cache
|
|
19
|
+
* to matter (the nudge's 40k), one just compacted, caching off, or a Claude Code too old to report it.
|
|
20
|
+
*/
|
|
21
|
+
export function cacheText(stdin, now) {
|
|
22
|
+
let pc;
|
|
23
|
+
try {
|
|
24
|
+
pc = JSON.parse(stdin).prompt_cache;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const tokens = pc?.recache_tokens_if_cold;
|
|
30
|
+
if (!pc?.caching_observed || typeof tokens !== 'number' || tokens < MIN_CONTEXT)
|
|
31
|
+
return null;
|
|
32
|
+
const expires = typeof pc.expires_at === 'number' ? pc.expires_at * 1000 : 0;
|
|
33
|
+
if (pc.warm && expires > now.getTime())
|
|
34
|
+
return { cold: false, text: `cache warm till ${hhmm(expires)}` };
|
|
35
|
+
return { cold: true, text: `/compact first: cache cold, next message rewrites ${k(tokens)}` };
|
|
36
|
+
}
|
|
37
|
+
/** Cold goes first, where a long line can't cut it off; warm goes last, dim. */
|
|
38
|
+
export function composeLine(quota, cache, color = false) {
|
|
39
|
+
if (!cache)
|
|
40
|
+
return quota;
|
|
41
|
+
const paint = (code, s) => (color ? `\u001b[${code}m${s}\u001b[0m` : s);
|
|
42
|
+
return cache.cold ? `🍪 ${paint(33, cache.text)} | ${quota.replace(/^🍪 /, '')}` : `${quota} | ${paint(2, cache.text)}`;
|
|
43
|
+
}
|
|
44
|
+
/** Run the status line you had on the same input. One that fails or takes over `timeoutMs` prints nothing. */
|
|
45
|
+
export function runWrapped(command, stdin, timeoutMs = 3_000) {
|
|
46
|
+
try {
|
|
47
|
+
const r = spawnSync('/bin/sh', ['-c', command], { input: stdin, encoding: 'utf8', timeout: timeoutMs, env: process.env });
|
|
48
|
+
return r.status === 0 && typeof r.stdout === 'string' ? r.stdout.replace(/\s+$/, '') : '';
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return '';
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** Your status line's output above Chompyy's line. */
|
|
55
|
+
export function statusLineOutput(ours, wrapped, stdin) {
|
|
56
|
+
const theirs = wrapped ? runWrapped(wrapped, stdin) : '';
|
|
57
|
+
return theirs ? `${theirs}\n${ours}` : ours;
|
|
58
|
+
}
|
|
59
|
+
const savedPath = () => homePath('statusline.json');
|
|
60
|
+
const isOurs = (s) => Boolean(s?.command?.includes(MARK));
|
|
61
|
+
/** The status line Chompyy wraps, saved when it was turned on. */
|
|
62
|
+
function saved() {
|
|
63
|
+
try {
|
|
64
|
+
return JSON.parse(readFileSync(savedPath(), 'utf8'));
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export function wrappedCommand() {
|
|
71
|
+
return saved()?.wrapped?.command ?? null;
|
|
72
|
+
}
|
|
73
|
+
export function statuslineInstalled(path = claudeSettingsPath()) {
|
|
74
|
+
try {
|
|
75
|
+
return isOurs(readSettings(path).settings.statusLine);
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export const statuslineCommand = (script, node) => `${selfCommand(script, node)} statusline ${MARK}`;
|
|
82
|
+
/** Point Claude Code's status line at Chompyy, keeping the one you had inside it; off gives yours back. Backs the file up first. */
|
|
83
|
+
export function setStatusline(on, command, path = claudeSettingsPath()) {
|
|
84
|
+
const { settings, raw } = readSettings(path);
|
|
85
|
+
const current = settings.statusLine;
|
|
86
|
+
const where = path.replace(homedir(), '~');
|
|
87
|
+
if (on) {
|
|
88
|
+
const wrapped = isOurs(current) ? (saved()?.wrapped ?? null) : (current ?? null);
|
|
89
|
+
mkdirSync(dirname(savedPath()), { recursive: true });
|
|
90
|
+
writeFileSync(savedPath(), JSON.stringify({ wrapped }, null, 2) + '\n');
|
|
91
|
+
settings.statusLine = { ...(wrapped ?? {}), type: 'command', command: command ?? statuslineCommand() };
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
if (current && !isOurs(current))
|
|
95
|
+
return `Nothing to turn off: the status line in ${where} isn't Chompyy's.`;
|
|
96
|
+
const wrapped = saved()?.wrapped ?? null;
|
|
97
|
+
if (wrapped)
|
|
98
|
+
settings.statusLine = wrapped;
|
|
99
|
+
else
|
|
100
|
+
delete settings.statusLine;
|
|
101
|
+
rmSync(savedPath(), { force: true });
|
|
102
|
+
}
|
|
103
|
+
if (raw !== null)
|
|
104
|
+
writeFileSync(`${path}.chompyy-backup`, raw);
|
|
105
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
106
|
+
writeFileSync(path, JSON.stringify(settings, null, 2) + '\n');
|
|
107
|
+
return on
|
|
108
|
+
? `Restart open conversations to see the cache timer. (Status line set in ${where}${current && !isOurs(current) ? '; yours still runs above it' : ''}; old file saved as .chompyy-backup.)`
|
|
109
|
+
: `Cache timer off. (${existsSync(path) && settings.statusLine ? 'Your status line is back' : 'Status line removed'} in ${where}.)`;
|
|
110
|
+
}
|
package/dist/suggest.js
CHANGED
|
@@ -9,6 +9,7 @@ import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
|
9
9
|
import { basename, join } from 'node:path';
|
|
10
10
|
import { addCard } from './board.js';
|
|
11
11
|
import { readTaste } from './taste.js';
|
|
12
|
+
import { exe } from './exe.js';
|
|
12
13
|
/** Vision and convention docs, in order of how much they say about where the repo is going. */
|
|
13
14
|
const DOCS = ['README.md', 'VISION.md', 'ROADMAP.md', 'FEATURES.md', 'PLAN.md', 'TODO.md', 'CONTRIBUTING.md', 'CLAUDE.md', 'AGENTS.md'];
|
|
14
15
|
const PER_DOC = 6000;
|
|
@@ -19,12 +20,12 @@ const MAX_DIGEST = 40_000;
|
|
|
19
20
|
*/
|
|
20
21
|
function safeGit(repo, args) {
|
|
21
22
|
const env = Object.fromEntries(Object.entries(process.env).filter(([k]) => !k.startsWith('GIT_')));
|
|
22
|
-
const r = spawnSync('git', ['-c', 'core.fsmonitor=false', '-c', 'core.hooksPath=/dev/null', '-C', repo, ...args], { encoding: 'utf8', env, timeout: 15_000, maxBuffer: 4 << 20 });
|
|
23
|
+
const r = spawnSync(exe('git'), ['-c', 'core.fsmonitor=false', '-c', 'core.hooksPath=/dev/null', '-C', repo, ...args], { encoding: 'utf8', env, timeout: 15_000, maxBuffer: 4 << 20 });
|
|
23
24
|
return r.status === 0 ? r.stdout : '';
|
|
24
25
|
}
|
|
25
26
|
/** Open issues through your own `gh`, when the repo is on GitHub and gh is logged in. Optional: [] otherwise. */
|
|
26
27
|
export function openIssues(repo) {
|
|
27
|
-
const r = spawnSync('gh', ['issue', 'list', '--state', 'open', '--limit', '30', '--json', 'number,title'], { cwd: repo, encoding: 'utf8', timeout: 20_000 });
|
|
28
|
+
const r = spawnSync(exe('gh'), ['issue', 'list', '--state', 'open', '--limit', '30', '--json', 'number,title'], { cwd: repo, encoding: 'utf8', timeout: 20_000 });
|
|
28
29
|
if (r.status !== 0)
|
|
29
30
|
return [];
|
|
30
31
|
try {
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Near-duplicate taste.md lines: find them and propose one merged line. Deterministic, no model calls,
|
|
2
|
+
// and nothing is written: callers decide what to do with a proposal.
|
|
3
|
+
//
|
|
4
|
+
// Similarity is a token-set score (Jaccard: shared words / all distinct words) over the instruction text,
|
|
5
|
+
// lowercased, with the learned suffix "(learned … · from cards #3 · p12)", the pN id and filler words removed.
|
|
6
|
+
/** Pairs scoring at or above this are flagged. Measured on the test fixtures: true duplicates score 0.42–0.44, the must-not-merge pair 0.125. */
|
|
7
|
+
export const MERGE_THRESHOLD = 0.4;
|
|
8
|
+
const SUFFIX = /\s+\((?:learned|from your history|merged)[^)]*\)\s*$/;
|
|
9
|
+
const STOP = new Set('a an the and or for with to in on of at by as is are be it its this that then too my their your our me i so'.split(' '));
|
|
10
|
+
/** Parse one taste.md bullet. Null for headings, comments, blanks and anything not a "- " bullet. */
|
|
11
|
+
export function parseTasteLine(raw) {
|
|
12
|
+
const m = raw.match(/^\s*[-*]\s+(.+)$/);
|
|
13
|
+
const body = m?.[1];
|
|
14
|
+
if (!body)
|
|
15
|
+
return null;
|
|
16
|
+
const suffix = body.match(SUFFIX)?.[0] ?? '';
|
|
17
|
+
const text = body.slice(0, body.length - suffix.length).trim();
|
|
18
|
+
if (!text)
|
|
19
|
+
return null;
|
|
20
|
+
return {
|
|
21
|
+
text,
|
|
22
|
+
ids: [...new Set(suffix.match(/\bp\d+\b/g) ?? [])],
|
|
23
|
+
cards: [...new Set(suffix.match(/#\d+/g) ?? [])],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function tokens(text) {
|
|
27
|
+
return new Set(text
|
|
28
|
+
.toLowerCase()
|
|
29
|
+
.replace(/\bp\d+\b/g, ' ')
|
|
30
|
+
.split(/[^a-z0-9]+/)
|
|
31
|
+
.filter((t) => t && !STOP.has(t)));
|
|
32
|
+
}
|
|
33
|
+
/** Token-set (Jaccard) similarity of two instruction texts, 0..1. */
|
|
34
|
+
export function similarity(a, b) {
|
|
35
|
+
const ta = tokens(a);
|
|
36
|
+
const tb = tokens(b);
|
|
37
|
+
if (!ta.size || !tb.size)
|
|
38
|
+
return 0;
|
|
39
|
+
let shared = 0;
|
|
40
|
+
for (const t of ta)
|
|
41
|
+
if (tb.has(t))
|
|
42
|
+
shared++;
|
|
43
|
+
return shared / (ta.size + tb.size - shared);
|
|
44
|
+
}
|
|
45
|
+
/** Every pair of bullet lines scoring at or above the threshold, highest score first. */
|
|
46
|
+
export function findNearDuplicates(lines, threshold = MERGE_THRESHOLD) {
|
|
47
|
+
const parsed = lines.map(parseTasteLine);
|
|
48
|
+
const out = [];
|
|
49
|
+
for (let i = 0; i < parsed.length; i++) {
|
|
50
|
+
const pi = parsed[i];
|
|
51
|
+
if (!pi)
|
|
52
|
+
continue;
|
|
53
|
+
for (let j = i + 1; j < parsed.length; j++) {
|
|
54
|
+
const pj = parsed[j];
|
|
55
|
+
if (!pj)
|
|
56
|
+
continue;
|
|
57
|
+
const score = similarity(pi.text, pj.text);
|
|
58
|
+
if (score >= threshold)
|
|
59
|
+
out.push({ a: i, b: j, score });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return out.sort((x, y) => y.score - x.score || x.a - y.a || x.b - y.b);
|
|
63
|
+
}
|
|
64
|
+
const byNumber = (x, y) => Number(x.replace(/\D/g, '')) - Number(y.replace(/\D/g, ''));
|
|
65
|
+
/**
|
|
66
|
+
* One merged line for two near-duplicates. Keeps the longer instruction (it usually carries more of the
|
|
67
|
+
* rule) and the union of both lines' pN ids and card refs, so no evidence is lost.
|
|
68
|
+
*/
|
|
69
|
+
export function proposeMerge(a, b) {
|
|
70
|
+
const pa = parseTasteLine(a);
|
|
71
|
+
const pb = parseTasteLine(b);
|
|
72
|
+
if (!pa || !pb)
|
|
73
|
+
throw new Error('proposeMerge needs two taste.md bullet lines');
|
|
74
|
+
const text = pb.text.length > pa.text.length ? pb.text : pa.text;
|
|
75
|
+
const ids = [...new Set([...pa.ids, ...pb.ids])].sort(byNumber);
|
|
76
|
+
const cards = [...new Set([...pa.cards, ...pb.cards])].sort(byNumber);
|
|
77
|
+
const parts = ['merged', ...(cards.length ? [`from cards ${cards.join(', ')}`] : []), ...(ids.length ? [ids.join(' + ')] : [])];
|
|
78
|
+
return { text, ids, cards, line: `- ${text} (${parts.join(' · ')})` };
|
|
79
|
+
}
|