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/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
|
|
@@ -43,19 +44,107 @@ export function insertUnderHeading(text, scope, line) {
|
|
|
43
44
|
rows.splice(end, 0, line);
|
|
44
45
|
return rows.join('\n');
|
|
45
46
|
}
|
|
46
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* taste.md for agents: drop the header comment so prompts carry only the preferences. Empty when nothing learned.
|
|
49
|
+
* A line whose id is retired in preferences.json never reaches a run, even if it was pasted back by hand.
|
|
50
|
+
*/
|
|
47
51
|
export function tasteForPrompt() {
|
|
48
52
|
const path = tastePath();
|
|
49
53
|
if (!existsSync(path))
|
|
50
54
|
return '';
|
|
51
|
-
|
|
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
|
|
52
66
|
.split('\n')
|
|
53
|
-
.
|
|
54
|
-
|
|
67
|
+
.filter((l) => {
|
|
68
|
+
const id = l.match(MARK)?.[1];
|
|
69
|
+
return !id || !retired.has(id);
|
|
70
|
+
})
|
|
71
|
+
.map((l) => l.replace(/\s+\((learned|from your history)[^)]*\)\s*$/, ''))
|
|
72
|
+
.filter((l) => /^\s*[-*]\s+\S/.test(l) || l.startsWith('## '));
|
|
55
73
|
// Only headings, no preferences: nothing to say.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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);
|
|
125
|
+
}
|
|
126
|
+
const DAY_MS = 86_400_000;
|
|
127
|
+
/**
|
|
128
|
+
* Learned lines in taste.md: every "(learned …)" line counts toward the total; those dated within 7 days of
|
|
129
|
+
* `now` also count as new. An undated or badly dated line counts toward the total only.
|
|
130
|
+
*/
|
|
131
|
+
export function learnedCount(text, now) {
|
|
132
|
+
let total = 0;
|
|
133
|
+
let newWithin7Days = 0;
|
|
134
|
+
for (const line of text.split('\n')) {
|
|
135
|
+
const m = line.match(/\(learned\b([^)]*)\)\s*$/);
|
|
136
|
+
if (!m)
|
|
137
|
+
continue;
|
|
138
|
+
total++;
|
|
139
|
+
const date = m[1].match(/\b(\d{4}-\d{2}-\d{2})\b/)?.[1];
|
|
140
|
+
const at = date ? Date.parse(`${date}T00:00:00Z`) : NaN;
|
|
141
|
+
if (Number.isNaN(at))
|
|
142
|
+
continue;
|
|
143
|
+
const days = Math.floor((now.getTime() - at) / DAY_MS);
|
|
144
|
+
if (days >= 0 && days < 7)
|
|
145
|
+
newWithin7Days++;
|
|
146
|
+
}
|
|
147
|
+
return { total, newWithin7Days };
|
|
59
148
|
}
|
|
60
149
|
export function signalsPath() {
|
|
61
150
|
return homePath('signals.jsonl');
|
|
@@ -117,6 +206,8 @@ export function signalWeight(s) {
|
|
|
117
206
|
return 1;
|
|
118
207
|
if (s.kind === 'chat')
|
|
119
208
|
return 2;
|
|
209
|
+
if (s.kind === 'advice-declined')
|
|
210
|
+
return 2;
|
|
120
211
|
return 0;
|
|
121
212
|
}
|
|
122
213
|
/** One line per signal, for the distiller prompt and for "why do you think that?". */
|
|
@@ -137,6 +228,8 @@ export function describeSignal(s, max = 400) {
|
|
|
137
228
|
return `${s.raw.outcome === 'undone' ? 'undid' : 'kept'} the result of ${card}`;
|
|
138
229
|
case 'answer':
|
|
139
230
|
return `answered the questions of ${card}: "${cut(s.raw.text)}"`;
|
|
231
|
+
case 'advice-declined':
|
|
232
|
+
return `declined the advice ${card} (${s.raw.key}): never suggest it again`;
|
|
140
233
|
case 'chat': {
|
|
141
234
|
const where = String(s.raw.workspace ?? '').split('/').pop() || 'a session';
|
|
142
235
|
return `said in a session in ${where} on ${s.at.slice(0, 10)}: "${cut(s.raw.quote)}"${s.raw.why ? ` (${cut(s.raw.why, 200)})` : ''}`;
|
|
@@ -327,10 +420,10 @@ export function retire(p, because, now, against = []) {
|
|
|
327
420
|
p.against = [...(p.against ?? []), ...against];
|
|
328
421
|
p.updatedAt = p.retiredAt;
|
|
329
422
|
}
|
|
330
|
-
/** Signals the distiller should read:
|
|
423
|
+
/** Signals the distiller should read: not yet seen, and from a governed card, a session (chat) or advice you declined. */
|
|
331
424
|
export function newSignals(store, signals, governed) {
|
|
332
425
|
const seen = store.seenThrough ?? 0;
|
|
333
|
-
return signals.filter((s) => Number(s.id.slice(1)) > seen && signalWeight(s) > 0 && (s.kind === 'chat' || (s.card && governed.has(s.card))));
|
|
426
|
+
return signals.filter((s) => Number(s.id.slice(1)) > seen && signalWeight(s) > 0 && (s.kind === 'chat' || s.kind === 'advice-declined' || (s.card && governed.has(s.card))));
|
|
334
427
|
}
|
|
335
428
|
/** Read new signals with the model and update preferences.json. Runs at most once per call; nothing to read = no model call. */
|
|
336
429
|
export async function distill(board, runner, opts) {
|
|
@@ -411,7 +504,8 @@ export function retirePreference(id, now) {
|
|
|
411
504
|
return p;
|
|
412
505
|
}
|
|
413
506
|
// ---------- taste.md stays in step ----------
|
|
414
|
-
|
|
507
|
+
/** The "· pN)" id at the end of a learned line. Tolerates hand-edit spacing like "· p3 )". */
|
|
508
|
+
const MARK = /\s*·\s*(p\d+)\s*\)\s*$/;
|
|
415
509
|
export function learnedLine(p, signals) {
|
|
416
510
|
const byId = new Map(signals.map((s) => [s.id, s]));
|
|
417
511
|
const cards = [...new Set(p.evidence.map((e) => byId.get(e)?.card).filter(Boolean))].map((c) => `#${c}`);
|
|
@@ -458,6 +552,8 @@ export function syncTasteFile(now) {
|
|
|
458
552
|
if (out !== text)
|
|
459
553
|
writeFileSync(path, out);
|
|
460
554
|
saveStore(store);
|
|
555
|
+
// Everyday sessions see the change from their next start (only when you turned that on).
|
|
556
|
+
refreshDaytime();
|
|
461
557
|
return retiredByYou;
|
|
462
558
|
}
|
|
463
559
|
// ---------- views ----------
|
package/dist/triggers.js
CHANGED
|
@@ -9,6 +9,7 @@ import { dirname, join } from 'node:path';
|
|
|
9
9
|
import { budgetGate } from './gate.js';
|
|
10
10
|
import { homePath, readJson, writeJson } from './home.js';
|
|
11
11
|
import { windowView } from './quota.js';
|
|
12
|
+
import { exe } from './exe.js';
|
|
12
13
|
const statePath = () => homePath('triggers.json');
|
|
13
14
|
export const loadTriggerState = () => readJson(statePath(), { fired: [] });
|
|
14
15
|
export function markFired(key, now, why) {
|
|
@@ -155,7 +156,7 @@ ${env}
|
|
|
155
156
|
`;
|
|
156
157
|
}
|
|
157
158
|
function launchctl(args) {
|
|
158
|
-
execFileSync('launchctl', args, { stdio: 'ignore' });
|
|
159
|
+
execFileSync(exe('launchctl'), args, { stdio: 'ignore' });
|
|
159
160
|
}
|
|
160
161
|
/** Install (or reinstall) the LaunchAgent that runs `chompyy tick` every 5 minutes. */
|
|
161
162
|
export function installAgent() {
|
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/verify.js
CHANGED
|
@@ -117,13 +117,16 @@ export async function verifyRun(opts) {
|
|
|
117
117
|
rmSync(linked);
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
+
// Enough for a whole test run: the names of failing tests are read from it, and a 20k tail cut off the first
|
|
121
|
+
// failures of a run with a dozen (each prints its stack), so they looked new on the card (2026-11-30).
|
|
122
|
+
const MAX_OUTPUT = 2_000_000;
|
|
120
123
|
export function run(argv, cwd, env, timeoutMs) {
|
|
121
124
|
return new Promise((resolve, reject) => {
|
|
122
125
|
const child = spawn(argv[0], argv.slice(1), { cwd, env, stdio: ['ignore', 'pipe', 'pipe'], detached: true });
|
|
123
126
|
let output = '';
|
|
124
127
|
let timedOut = false;
|
|
125
128
|
const add = (d) => {
|
|
126
|
-
output = (output + d.toString()).slice(-
|
|
129
|
+
output = (output + d.toString()).slice(-MAX_OUTPUT);
|
|
127
130
|
};
|
|
128
131
|
child.stdout.on('data', add);
|
|
129
132
|
child.stderr.on('data', add);
|