chompyy 0.1.0 → 0.4.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 +82 -8
- package/THIRD_PARTY_NOTICES.md +29 -1
- package/dist/appstate.js +121 -4
- package/dist/away.js +191 -25
- package/dist/blueprint.js +102 -7
- package/dist/board.js +143 -15
- package/dist/catalog.js +81 -0
- package/dist/claudesettings.js +23 -0
- package/dist/cli.js +804 -55
- package/dist/coldstart.js +208 -0
- package/dist/config.js +43 -8
- package/dist/costs.js +162 -0
- package/dist/deps.js +124 -0
- package/dist/dream.js +422 -0
- package/dist/duration.js +3 -3
- package/dist/gate.js +40 -5
- package/dist/history.js +308 -0
- package/dist/live.js +255 -0
- package/dist/livequota.js +42 -5
- package/dist/macapp.js +25 -2
- package/dist/pacing.js +189 -0
- package/dist/permissions.js +106 -0
- package/dist/picture.js +124 -0
- package/dist/picturetype.js +208 -0
- package/dist/preflight.js +168 -0
- package/dist/projects.js +5 -4
- package/dist/quota.js +31 -5
- package/dist/refresh.js +290 -0
- package/dist/report.js +41 -21
- package/dist/review.js +111 -11
- package/dist/runner.js +318 -10
- package/dist/taste.js +528 -0
- package/dist/tokens.js +75 -0
- package/dist/tokenstore.js +61 -0
- package/dist/trace.js +284 -0
- package/dist/triggers.js +193 -0
- package/dist/usage.js +467 -0
- package/dist/vendor/codeburn/prices.js +45 -0
- package/dist/verify.js +150 -0
- package/dist/verifycard.js +146 -0
- package/dist/workspace.js +132 -18
- package/package.json +4 -2
- package/skills/taste/SKILL.md +4 -1
- package/vendor/diagram-design/LICENSE +21 -0
- package/vendor/diagram-design/SKILL.md +399 -0
- package/vendor/diagram-design/UPSTREAM.md +18 -0
- package/vendor/diagram-design/assets/example-arc-diagram.html +111 -0
- package/vendor/diagram-design/assets/example-architecture-containment.html +205 -0
- package/vendor/diagram-design/assets/example-architecture-delta.html +193 -0
- package/vendor/diagram-design/assets/example-architecture.html +183 -0
- package/vendor/diagram-design/assets/example-axonometric-plan-campus.html +108 -0
- package/vendor/diagram-design/assets/example-axonometric-plan-coffee-shop.html +121 -0
- package/vendor/diagram-design/assets/example-axonometric-plan-warehouse.html +127 -0
- package/vendor/diagram-design/assets/example-axonometric-plan.html +114 -0
- package/vendor/diagram-design/assets/example-bar.html +129 -0
- package/vendor/diagram-design/assets/example-beeswarm.html +384 -0
- package/vendor/diagram-design/assets/example-box-plot.html +127 -0
- package/vendor/diagram-design/assets/example-bubble.html +147 -0
- package/vendor/diagram-design/assets/example-bump.html +142 -0
- package/vendor/diagram-design/assets/example-data-flow.html +143 -0
- package/vendor/diagram-design/assets/example-datalake.html +269 -0
- package/vendor/diagram-design/assets/example-db-schema.html +302 -0
- package/vendor/diagram-design/assets/example-dependency.html +224 -0
- package/vendor/diagram-design/assets/example-deployment.html +190 -0
- package/vendor/diagram-design/assets/example-dp-integration.html +81 -0
- package/vendor/diagram-design/assets/example-dp-security-matrix.html +88 -0
- package/vendor/diagram-design/assets/example-er.html +202 -0
- package/vendor/diagram-design/assets/example-event-modeling.html +64 -0
- package/vendor/diagram-design/assets/example-exploded-ai-stack.html +85 -0
- package/vendor/diagram-design/assets/example-exploded-keyboard.html +84 -0
- package/vendor/diagram-design/assets/example-exploded-phone.html +83 -0
- package/vendor/diagram-design/assets/example-exploded-unboxing.html +84 -0
- package/vendor/diagram-design/assets/example-exploded.html +83 -0
- package/vendor/diagram-design/assets/example-fishbone.html +152 -0
- package/vendor/diagram-design/assets/example-flowchart.html +163 -0
- package/vendor/diagram-design/assets/example-gantt.html +137 -0
- package/vendor/diagram-design/assets/example-heatmap.html +224 -0
- package/vendor/diagram-design/assets/example-high-level-vertical.html +325 -0
- package/vendor/diagram-design/assets/example-high-level.html +301 -0
- package/vendor/diagram-design/assets/example-import-drawio.html +185 -0
- package/vendor/diagram-design/assets/example-import-excalidraw.html +70 -0
- package/vendor/diagram-design/assets/example-import-mermaid.html +70 -0
- package/vendor/diagram-design/assets/example-import-plantuml.html +107 -0
- package/vendor/diagram-design/assets/example-it-state.html +128 -0
- package/vendor/diagram-design/assets/example-journey.html +148 -0
- package/vendor/diagram-design/assets/example-kanban.html +174 -0
- package/vendor/diagram-design/assets/example-layers.html +123 -0
- package/vendor/diagram-design/assets/example-line.html +111 -0
- package/vendor/diagram-design/assets/example-loop.html +100 -0
- package/vendor/diagram-design/assets/example-marimekko.html +148 -0
- package/vendor/diagram-design/assets/example-medallion.html +159 -0
- package/vendor/diagram-design/assets/example-nested.html +136 -0
- package/vendor/diagram-design/assets/example-org-chart.html +45 -0
- package/vendor/diagram-design/assets/example-polar.html +116 -0
- package/vendor/diagram-design/assets/example-process.html +64 -0
- package/vendor/diagram-design/assets/example-pyramid.html +119 -0
- package/vendor/diagram-design/assets/example-quadrant-consultant.html +166 -0
- package/vendor/diagram-design/assets/example-quadrant.html +135 -0
- package/vendor/diagram-design/assets/example-radar.html +139 -0
- package/vendor/diagram-design/assets/example-requirement-traceability.html +122 -0
- package/vendor/diagram-design/assets/example-ridgeline.html +104 -0
- package/vendor/diagram-design/assets/example-sankey.html +150 -0
- package/vendor/diagram-design/assets/example-sbgn.html +213 -0
- package/vendor/diagram-design/assets/example-scatter.html +141 -0
- package/vendor/diagram-design/assets/example-sequence-oauth.html +227 -0
- package/vendor/diagram-design/assets/example-sequence.html +222 -0
- package/vendor/diagram-design/assets/example-service-blueprint.html +185 -0
- package/vendor/diagram-design/assets/example-slopegraph.html +119 -0
- package/vendor/diagram-design/assets/example-state-lifecycle.html +92 -0
- package/vendor/diagram-design/assets/example-state.html +147 -0
- package/vendor/diagram-design/assets/example-steps.html +78 -0
- package/vendor/diagram-design/assets/example-story-map.html +184 -0
- package/vendor/diagram-design/assets/example-streamgraph.html +99 -0
- package/vendor/diagram-design/assets/example-swimlane.html +172 -0
- package/vendor/diagram-design/assets/example-timeline.html +135 -0
- package/vendor/diagram-design/assets/example-tree-block-decomposition.html +151 -0
- package/vendor/diagram-design/assets/example-tree.html +173 -0
- package/vendor/diagram-design/assets/example-treemap.html +107 -0
- package/vendor/diagram-design/assets/example-uml-class.html +188 -0
- package/vendor/diagram-design/assets/example-unit-grid.html +141 -0
- package/vendor/diagram-design/assets/example-venn.html +110 -0
- package/vendor/diagram-design/assets/example-wardley.html +153 -0
- package/vendor/diagram-design/assets/example-waterfall.html +129 -0
- package/vendor/diagram-design/assets/template-dark.html +99 -0
- package/vendor/diagram-design/assets/template.html +100 -0
- package/vendor/diagram-design/references/layout-budget.md +103 -0
- package/vendor/diagram-design/references/output-spec.md +277 -0
- package/vendor/diagram-design/references/primitive-annotation.md +36 -0
- package/vendor/diagram-design/references/primitive-sketchy.md +43 -0
- package/vendor/diagram-design/references/primitives-core.md +146 -0
- package/vendor/diagram-design/references/semantic-patterns.md +154 -0
- package/vendor/diagram-design/references/style-guide.md +234 -0
- package/vendor/diagram-design/references/type-architecture-delta.md +143 -0
- package/vendor/diagram-design/references/type-architecture.md +117 -0
- package/vendor/diagram-design/references/type-axonometric-plan.md +83 -0
- package/vendor/diagram-design/references/type-bar.md +108 -0
- package/vendor/diagram-design/references/type-data-flow.md +371 -0
- package/vendor/diagram-design/references/type-db-schema.md +48 -0
- package/vendor/diagram-design/references/type-dependency.md +113 -0
- package/vendor/diagram-design/references/type-deployment.md +45 -0
- package/vendor/diagram-design/references/type-dp-integration.md +407 -0
- package/vendor/diagram-design/references/type-dp-security-matrix.md +379 -0
- package/vendor/diagram-design/references/type-er.md +25 -0
- package/vendor/diagram-design/references/type-event-modeling.md +36 -0
- package/vendor/diagram-design/references/type-exploded.md +115 -0
- package/vendor/diagram-design/references/type-fishbone.md +75 -0
- package/vendor/diagram-design/references/type-flowchart.md +23 -0
- package/vendor/diagram-design/references/type-gantt.md +45 -0
- package/vendor/diagram-design/references/type-heatmap.md +80 -0
- package/vendor/diagram-design/references/type-high-level.md +470 -0
- package/vendor/diagram-design/references/type-it-state.md +468 -0
- package/vendor/diagram-design/references/type-journey.md +55 -0
- package/vendor/diagram-design/references/type-kanban.md +49 -0
- package/vendor/diagram-design/references/type-layers.md +26 -0
- package/vendor/diagram-design/references/type-line.md +337 -0
- package/vendor/diagram-design/references/type-loop.md +223 -0
- package/vendor/diagram-design/references/type-medallion.md +356 -0
- package/vendor/diagram-design/references/type-nested.md +22 -0
- package/vendor/diagram-design/references/type-org-chart.md +44 -0
- package/vendor/diagram-design/references/type-polar.md +136 -0
- package/vendor/diagram-design/references/type-process.md +490 -0
- package/vendor/diagram-design/references/type-pyramid.md +33 -0
- package/vendor/diagram-design/references/type-quadrant.md +81 -0
- package/vendor/diagram-design/references/type-radar.md +82 -0
- package/vendor/diagram-design/references/type-requirement-traceability.md +45 -0
- package/vendor/diagram-design/references/type-sankey.md +75 -0
- package/vendor/diagram-design/references/type-sbgn.md +80 -0
- package/vendor/diagram-design/references/type-scatter.md +276 -0
- package/vendor/diagram-design/references/type-sequence.md +130 -0
- package/vendor/diagram-design/references/type-service-blueprint.md +103 -0
- package/vendor/diagram-design/references/type-state.md +30 -0
- package/vendor/diagram-design/references/type-steps.md +180 -0
- package/vendor/diagram-design/references/type-story-map.md +46 -0
- package/vendor/diagram-design/references/type-swimlane.md +22 -0
- package/vendor/diagram-design/references/type-timeline.md +20 -0
- package/vendor/diagram-design/references/type-tree.md +24 -0
- package/vendor/diagram-design/references/type-treemap.md +137 -0
- package/vendor/diagram-design/references/type-uml-class.md +65 -0
- package/vendor/diagram-design/references/type-unit-grid.md +63 -0
- package/vendor/diagram-design/references/type-venn.md +26 -0
- package/vendor/diagram-design/references/type-wardley.md +39 -0
- package/vendor/diagram-design/references/type-waterfall.md +75 -0
- package/vendor/diagram-design/scripts/self_check.py +1177 -0
- package/vendor/diagram-design/scripts/verify_geometry.py +696 -0
package/dist/refresh.js
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
// Refresh (2026-11-19): Chompyy keeps cards in review up to date with main by itself. Cards from one night start
|
|
2
|
+
// from the same main; keeping one can make the next clash with it (#20 and #21 after #12, #19, #22 were kept).
|
|
3
|
+
// You shouldn't have to pick an order or merge by hand. After each Keep, every card in review that now clashes
|
|
4
|
+
// is brought onto the new main: git merges it when it can, and when it can't, a short agent session in the
|
|
5
|
+
// card's own sandbox fits both changes together. Then Chompyy's own check runs again against the new main.
|
|
6
|
+
// Pressing Keep on a clashing card does the same and keeps it once the check passes.
|
|
7
|
+
import { execFileSync } from 'node:child_process';
|
|
8
|
+
import { closeSync, existsSync, openSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
9
|
+
import { join, resolve } from 'node:path';
|
|
10
|
+
import { awayTools, cacheEnv, denyReadRules, safetyRules, sandboxSettings } from './away.js';
|
|
11
|
+
import { getCard, loadBoard, updateBoard } from './board.js';
|
|
12
|
+
import { homePath } from './home.js';
|
|
13
|
+
import { windowView } from './quota.js';
|
|
14
|
+
import { commitLeftovers, gitRoot, restoreGitLink } from './workspace.js';
|
|
15
|
+
const git = (cwd, args) => execFileSync('git', ['-C', cwd, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
|
|
16
|
+
const ok = (cwd, args) => {
|
|
17
|
+
try {
|
|
18
|
+
git(cwd, args);
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
/** The branch Keep would land the card on. */
|
|
26
|
+
export function landingBranch(card) {
|
|
27
|
+
if (card.run?.base?.branch)
|
|
28
|
+
return card.run.base.branch;
|
|
29
|
+
try {
|
|
30
|
+
return git(card.cwd, ['rev-parse', '--abbrev-ref', 'HEAD']) || null;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Would Keep clash? For a card in review: the landing branch's commit, and the files git can't merge by itself.
|
|
38
|
+
* Null when it merges cleanly (or isn't a branch card in review). Uses `git merge-tree`, which touches no folder.
|
|
39
|
+
*/
|
|
40
|
+
export function clashOf(card) {
|
|
41
|
+
const run = card.run;
|
|
42
|
+
if (card.column !== 'review' || !run?.branch)
|
|
43
|
+
return null;
|
|
44
|
+
const repo = gitRoot(card.cwd);
|
|
45
|
+
const branch = landingBranch(card);
|
|
46
|
+
if (!repo || !branch)
|
|
47
|
+
return null;
|
|
48
|
+
try {
|
|
49
|
+
const onto = git(repo, ['rev-parse', branch]);
|
|
50
|
+
if (ok(repo, ['merge-base', '--is-ancestor', onto, run.branch]))
|
|
51
|
+
return null; // already has it
|
|
52
|
+
try {
|
|
53
|
+
git(repo, ['merge-tree', '--write-tree', '--name-only', onto, run.branch]);
|
|
54
|
+
return null; // merges cleanly
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
const e = err;
|
|
58
|
+
if (e.status !== 1)
|
|
59
|
+
return null; // not a conflict (an old git, a missing branch): leave it to Keep
|
|
60
|
+
const files = String(e.stdout ?? '').split('\n\n')[0].split('\n').slice(1).filter(Boolean);
|
|
61
|
+
return { onto, branch, files: [...new Set(files)] };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** Why a refresh must wait, or null. Like drafting: it finishes work you already chose, so only a used-up window stops it. */
|
|
69
|
+
export function refreshGate(snap, now) {
|
|
70
|
+
const five = windowView(snap?.fiveHour, now);
|
|
71
|
+
const week = windowView(snap?.sevenDay, now);
|
|
72
|
+
if (five.known && five.usedPct >= 100)
|
|
73
|
+
return 'the 5-hour window is used up; it updates after the reset';
|
|
74
|
+
if (week.known && week.usedPct >= 100)
|
|
75
|
+
return 'the weekly limit is used up; it updates after the reset';
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
export function refreshPrompt(card, workdir, branch, files, checks) {
|
|
79
|
+
return `${safetyRules(workdir)}
|
|
80
|
+
|
|
81
|
+
# Bring card #${card.id} up to date with ${branch}
|
|
82
|
+
|
|
83
|
+
This folder is card #${card.id} ("${card.title}"), waiting for review. Meanwhile other work was kept on ${branch}, and
|
|
84
|
+
the two now clash. Chompyy has already started \`git merge ${branch}\` here; these files have conflicts:
|
|
85
|
+
|
|
86
|
+
${files.map((f) => `- ${f}`).join('\n')}
|
|
87
|
+
|
|
88
|
+
Resolve every conflict so that BOTH changes work: this card's change (what it was for: ${card.idea}) and what is
|
|
89
|
+
already on ${branch}. Usually that means keeping both sides and fitting them together: both imports, both fields,
|
|
90
|
+
both functions, both tests. Don't drop either side's feature, don't change anything else, and don't restart or
|
|
91
|
+
abort the merge. Leave the resolved files as they are: don't \`git add\` or commit (.git is read-only to you).
|
|
92
|
+
Chompyy checks them and finishes the merge.
|
|
93
|
+
${checks.length ? `
|
|
94
|
+
After the merge, check it (these pass on ${branch}):
|
|
95
|
+
${checks.map((c) => `- in ${c.dir || 'the top folder'}: \`${c.label}\``).join('\n')}
|
|
96
|
+
` : ''}`;
|
|
97
|
+
}
|
|
98
|
+
function setRefresh(id, refresh, extra = () => { }) {
|
|
99
|
+
updateBoard((b) => {
|
|
100
|
+
const c = getCard(b, id);
|
|
101
|
+
c.refresh = refresh;
|
|
102
|
+
extra(c);
|
|
103
|
+
c.updatedAt = refresh.at;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/** Markers git leaves in a conflicted file. */
|
|
107
|
+
const MARKERS = /^(<{7}|>{7})( |$)/m;
|
|
108
|
+
/** Bring one card in review onto its landing branch. Returns what happened (also saved on the card). */
|
|
109
|
+
export async function refreshCard(id, deps) {
|
|
110
|
+
const card = getCard(loadBoard(), id);
|
|
111
|
+
const at = () => deps.now().toISOString();
|
|
112
|
+
const keepIfAsked = (verified) => {
|
|
113
|
+
if (!card.keepWhenRefreshed || !deps.keep)
|
|
114
|
+
return;
|
|
115
|
+
if (verified && verified.result !== 'passed')
|
|
116
|
+
return deps.out(` not keeping #${id} by itself: ${verified.why}`);
|
|
117
|
+
deps.keep(id);
|
|
118
|
+
};
|
|
119
|
+
const clash = clashOf(card);
|
|
120
|
+
if (!clash) {
|
|
121
|
+
const done = { state: 'done', why: 'already merges cleanly with main', at: at() };
|
|
122
|
+
if (card.refresh || card.keepWhenRefreshed)
|
|
123
|
+
setRefresh(id, done);
|
|
124
|
+
keepIfAsked(undefined);
|
|
125
|
+
return done;
|
|
126
|
+
}
|
|
127
|
+
const short = clash.onto.slice(0, 7);
|
|
128
|
+
const waiting = refreshGate(deps.snapshot(), deps.now());
|
|
129
|
+
if (waiting) {
|
|
130
|
+
const r = { state: 'waiting', onto: clash.onto, files: clash.files, why: waiting, at: at() };
|
|
131
|
+
setRefresh(id, r);
|
|
132
|
+
deps.out(` #${id} clashes with ${clash.branch} but waits: ${waiting}`);
|
|
133
|
+
return r;
|
|
134
|
+
}
|
|
135
|
+
const run = card.run;
|
|
136
|
+
const dir = run.workdir;
|
|
137
|
+
const fail = (why) => {
|
|
138
|
+
const r = { state: 'failed', onto: clash.onto, files: clash.files, why, at: at() };
|
|
139
|
+
setRefresh(id, r, (c) => delete c.keepWhenRefreshed);
|
|
140
|
+
deps.out(` ✗ #${id}: ${why}`);
|
|
141
|
+
return r;
|
|
142
|
+
};
|
|
143
|
+
if (!existsSync(join(dir, '.git')))
|
|
144
|
+
return fail(`its folder ${dir} is gone; run it again on top of the latest with \`chompyy redo ${id}\``);
|
|
145
|
+
setRefresh(id, { state: 'running', onto: clash.onto, files: clash.files, why: `bringing it onto ${clash.branch} @ ${short}`, at: at() });
|
|
146
|
+
deps.out(`▶ refreshing #${id} onto ${clash.branch} @ ${short} (clashes in ${clash.files.join(', ')})`);
|
|
147
|
+
commitLeftovers({ kind: 'worktree', dir }, card);
|
|
148
|
+
const before = git(dir, ['rev-parse', 'HEAD']);
|
|
149
|
+
let agentGitDir;
|
|
150
|
+
const undo = () => {
|
|
151
|
+
if (agentGitDir)
|
|
152
|
+
restoreGitLink(dir, agentGitDir); // the agent may have repointed it; never run git through its link
|
|
153
|
+
if (ok(dir, ['rev-parse', '-q', '--verify', 'MERGE_HEAD']))
|
|
154
|
+
ok(dir, ['merge', '--abort']);
|
|
155
|
+
ok(dir, ['reset', '-q', '--hard', before]);
|
|
156
|
+
};
|
|
157
|
+
let by = 'git';
|
|
158
|
+
let tokens;
|
|
159
|
+
const ident = ['-c', 'user.name=Chompyy', '-c', 'user.email=chompyy@localhost'];
|
|
160
|
+
if (!ok(dir, [...ident, 'merge', '--no-edit', '-m', `Bring Chompyy card #${id} up to date with ${clash.branch}`, clash.onto])) {
|
|
161
|
+
by = 'agent';
|
|
162
|
+
const config = deps.config;
|
|
163
|
+
const gitDir = resolve(dir, git(dir, ['rev-parse', '--git-common-dir']));
|
|
164
|
+
const ws = { kind: 'worktree', dir, branch: run.branch, gitDir };
|
|
165
|
+
agentGitDir = gitDir;
|
|
166
|
+
const cacheDir = homePath('cache', 'tools');
|
|
167
|
+
try {
|
|
168
|
+
const result = await deps.runner.run({
|
|
169
|
+
prompt: refreshPrompt(card, dir, clash.branch, clash.files, deps.repoChecks?.(card) ?? []),
|
|
170
|
+
cwd: dir,
|
|
171
|
+
timeoutMs: deps.timeoutMs ?? 15 * 60_000,
|
|
172
|
+
model: config.runModel,
|
|
173
|
+
maxTurns: config.maxTurns,
|
|
174
|
+
permissionMode: config.permissionMode,
|
|
175
|
+
permissionPrompts: config.permissionPrompts,
|
|
176
|
+
allowedTools: awayTools(config),
|
|
177
|
+
disallowedTools: [...config.disallowedTools, ...denyReadRules(config.denyReadPaths)],
|
|
178
|
+
...(config.sandbox ? { settings: sandboxSettings(ws, config.sandboxAllowedDomains, cacheDir, config.denyReadPaths) } : {}),
|
|
179
|
+
env: cacheEnv(cacheDir),
|
|
180
|
+
extraArgs: config.extraArgs,
|
|
181
|
+
...(config.idleTimeoutMin > 0 ? { idleTimeoutMs: config.idleTimeoutMin * 60_000 } : {}),
|
|
182
|
+
rawLogPath: homePath('runs', id, `refresh-${at().replace(/[:.]/g, '-')}.stream.jsonl`),
|
|
183
|
+
});
|
|
184
|
+
tokens = result.tokens;
|
|
185
|
+
if (result.timedOut || result.stuck || result.stalled) {
|
|
186
|
+
undo();
|
|
187
|
+
return fail(`the agent couldn't finish fitting the changes together (${result.timedOut ? 'ran out of time' : result.stuck ?? result.stalled}); nothing was changed`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
catch (err) {
|
|
191
|
+
undo();
|
|
192
|
+
return fail(`the agent didn't run (${err instanceof Error ? err.message : err}); nothing was changed`);
|
|
193
|
+
}
|
|
194
|
+
// The agent can't write .git, so Chompyy finishes the merge: only once no conflict markers are left.
|
|
195
|
+
restoreGitLink(dir, gitDir);
|
|
196
|
+
const resolved = clash.files.every((f) => !existsSync(join(dir, f)) || !MARKERS.test(readFileSync(join(dir, f), 'utf8')));
|
|
197
|
+
if (resolved && ok(dir, ['rev-parse', '-q', '--verify', 'MERGE_HEAD'])) {
|
|
198
|
+
ok(dir, ['add', '-A', '--', ...clash.files]);
|
|
199
|
+
ok(dir, ['add', '-u']);
|
|
200
|
+
ok(dir, [...ident, 'commit', '--no-verify', '--no-edit']);
|
|
201
|
+
}
|
|
202
|
+
// Chompyy checks the merge itself, never on the agent's word.
|
|
203
|
+
const stillMerging = ok(dir, ['rev-parse', '-q', '--verify', 'MERGE_HEAD']);
|
|
204
|
+
const leftMarkers = clash.files.filter((f) => existsSync(join(dir, f)) && MARKERS.test(readFileSync(join(dir, f), 'utf8')));
|
|
205
|
+
const hasMain = ok(dir, ['merge-base', '--is-ancestor', clash.onto, 'HEAD']);
|
|
206
|
+
if (stillMerging || leftMarkers.length || !hasMain) {
|
|
207
|
+
undo();
|
|
208
|
+
return fail(leftMarkers.length
|
|
209
|
+
? `conflict markers were left in ${leftMarkers.join(', ')}; nothing was changed`
|
|
210
|
+
: stillMerging
|
|
211
|
+
? "the merge wasn't finished; nothing was changed"
|
|
212
|
+
: `the result doesn't contain ${clash.branch}; nothing was changed`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
const base = { ref: run.base?.ref ?? clash.branch, branch: clash.branch, commit: clash.onto };
|
|
216
|
+
let verified;
|
|
217
|
+
if (deps.verify) {
|
|
218
|
+
deps.out(' checking it against the new main (running the repo\'s tests, sandboxed)…');
|
|
219
|
+
verified = await deps.verify({ kind: 'worktree', dir, branch: run.branch, base }, card).catch(() => undefined);
|
|
220
|
+
if (verified)
|
|
221
|
+
deps.out(` ${verified.result === 'passed' ? '✓' : verified.result === 'failed' ? '✗' : '·'} ${verified.why}`);
|
|
222
|
+
}
|
|
223
|
+
const done = {
|
|
224
|
+
state: 'done',
|
|
225
|
+
onto: clash.onto,
|
|
226
|
+
files: clash.files,
|
|
227
|
+
by,
|
|
228
|
+
...(tokens ? { tokens } : {}),
|
|
229
|
+
why: by === 'agent' ? `brought onto ${clash.branch} @ ${short}; an agent fitted both changes together in ${clash.files.join(', ')}` : `brought onto ${clash.branch} @ ${short}`,
|
|
230
|
+
at: at(),
|
|
231
|
+
};
|
|
232
|
+
setRefresh(id, done, (c) => {
|
|
233
|
+
c.run = { ...c.run, base, ...(verified ? { verified } : {}) };
|
|
234
|
+
});
|
|
235
|
+
deps.out(` → #${id} is up to date with ${clash.branch}`);
|
|
236
|
+
keepIfAsked(verified);
|
|
237
|
+
return done;
|
|
238
|
+
}
|
|
239
|
+
/** Every card in review that clashes with its main, one at a time. */
|
|
240
|
+
export async function refreshClashing(deps) {
|
|
241
|
+
const out = [];
|
|
242
|
+
for (const c of loadBoard().cards) {
|
|
243
|
+
if (c.column !== 'review' || !c.run?.branch)
|
|
244
|
+
continue;
|
|
245
|
+
if (!clashOf(c) && !c.keepWhenRefreshed && c.refresh?.state !== 'waiting')
|
|
246
|
+
continue;
|
|
247
|
+
out.push(await refreshCard(c.id, deps));
|
|
248
|
+
}
|
|
249
|
+
return out;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* One refresh at a time (two Keeps in a row ask twice). A second ask leaves a note and the running one goes
|
|
253
|
+
* round again, so every card ends up on the newest main. Returns false when another refresh took the ask.
|
|
254
|
+
*/
|
|
255
|
+
export async function withRefreshLock(fn) {
|
|
256
|
+
const lock = homePath('refresh.lock');
|
|
257
|
+
const again = homePath('refresh.again');
|
|
258
|
+
let fd;
|
|
259
|
+
try {
|
|
260
|
+
fd = openSync(lock, 'wx');
|
|
261
|
+
}
|
|
262
|
+
catch {
|
|
263
|
+
const pid = Number(readFileSync(lock, 'utf8')) || 0;
|
|
264
|
+
let alive = false;
|
|
265
|
+
try {
|
|
266
|
+
if (pid)
|
|
267
|
+
process.kill(pid, 0);
|
|
268
|
+
alive = pid > 0;
|
|
269
|
+
}
|
|
270
|
+
catch { }
|
|
271
|
+
if (alive) {
|
|
272
|
+
writeFileSync(again, '');
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
rmSync(lock, { force: true });
|
|
276
|
+
fd = openSync(lock, 'wx');
|
|
277
|
+
}
|
|
278
|
+
try {
|
|
279
|
+
writeFileSync(fd, String(process.pid));
|
|
280
|
+
do {
|
|
281
|
+
rmSync(again, { force: true });
|
|
282
|
+
await fn();
|
|
283
|
+
} while (existsSync(again));
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
finally {
|
|
287
|
+
closeSync(fd);
|
|
288
|
+
rmSync(lock, { force: true });
|
|
289
|
+
}
|
|
290
|
+
}
|
package/dist/report.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// "While you were away" report and rating (spec §5.7).
|
|
2
|
-
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
2
|
import { getCard } from './board.js';
|
|
3
|
+
import { formatTokens } from './tokens.js';
|
|
4
4
|
import { formatDuration } from './duration.js';
|
|
5
5
|
import { wrap } from './review.js';
|
|
6
6
|
import { appendJsonl, homePath, readJson, writeJson } from './home.js';
|
|
@@ -23,11 +23,13 @@ const ACTION = {
|
|
|
23
23
|
failed: { icon: '❌', rank: 1, text: "It didn't finish. Look at what happened, then undo or run it again" },
|
|
24
24
|
error: { icon: '⚠️', rank: 1, text: "It couldn't start. Look at what happened" },
|
|
25
25
|
timeout: { icon: '⏱', rank: 2, text: 'It ran out of time. Check what it got done, then keep or undo' },
|
|
26
|
+
stuck: { icon: '⛔', rank: 1, text: 'Chompyy stopped it: it was going in circles. Look at what happened, then undo or run it again' },
|
|
26
27
|
ok: { icon: '✅', rank: 3, text: 'Check the change, then keep or undo' },
|
|
27
28
|
};
|
|
28
29
|
/** Finished, but its own checks didn't pass: say so instead of a plain ✅. */
|
|
29
30
|
const UNCHECKED = {
|
|
30
31
|
failed: { icon: '⚠️', rank: 1, text: 'It finished, but its checks fail. See why before you keep it' },
|
|
32
|
+
failedIndependently: { icon: '⚠️', rank: 1, text: "It says it's done, but the tests fail when Chompyy runs them. See why before you keep it" },
|
|
31
33
|
notRun: { icon: '🔍', rank: 2, text: "It finished but couldn't check its work. Check it yourself, then keep or undo" },
|
|
32
34
|
};
|
|
33
35
|
/** Once you've kept or undone a card, the only thing left is the rating. */
|
|
@@ -41,13 +43,38 @@ function filesLine(files) {
|
|
|
41
43
|
const shown = files.slice(0, 3).join(', ');
|
|
42
44
|
return files.length > 3 ? `${shown} +${files.length - 3} more` : shown;
|
|
43
45
|
}
|
|
44
|
-
/**
|
|
45
|
-
export function
|
|
46
|
+
/** "Last night: 3 cards ran, 1 kept · taste: 1 learned, 1 retired, 1 question". Shows the system evolving. */
|
|
47
|
+
export function morningLine(cards, taste) {
|
|
48
|
+
const bits = [];
|
|
49
|
+
if (cards.length) {
|
|
50
|
+
const kept = cards.filter((c) => c.outcome === 'kept').length;
|
|
51
|
+
const used = cards.map((c) => c.run?.cost?.fiveHourPct).filter((n) => typeof n === 'number');
|
|
52
|
+
const total = Math.round(used.reduce((a, b) => a + b, 0));
|
|
53
|
+
bits.push(`${cards.length} card${cards.length === 1 ? '' : 's'} ran${kept ? `, ${kept} kept` : ''}${used.length ? `, using ${total}% of 5h windows` : ''}`);
|
|
54
|
+
}
|
|
55
|
+
const t = [];
|
|
56
|
+
if (taste.learned)
|
|
57
|
+
t.push(`${taste.learned} learned`);
|
|
58
|
+
if (taste.retired)
|
|
59
|
+
t.push(`${taste.retired} retired`);
|
|
60
|
+
if (t.length)
|
|
61
|
+
bits.push(`taste: ${t.join(', ')}`);
|
|
62
|
+
return bits.length ? `Since last time: ${bits.join(' · ')}` : null;
|
|
63
|
+
}
|
|
64
|
+
export function formatReport(cards, since, facts, extras = {}) {
|
|
65
|
+
const footer = extras.footer?.length ? ['', ...extras.footer] : [];
|
|
46
66
|
if (cards.length === 0)
|
|
47
|
-
return since ? 'Nothing new since your last report.' : 'Nothing has run yet.';
|
|
67
|
+
return [since ? 'Nothing new since your last report.' : 'Nothing has run yet.', ...footer].join('\n');
|
|
48
68
|
const actionOf = (c) => {
|
|
49
69
|
if (c.outcome)
|
|
50
70
|
return DECIDED[c.outcome];
|
|
71
|
+
// Chompyy's own test run outranks what the agent says about itself.
|
|
72
|
+
if (c.run.status === 'ok' && c.run.verified?.result === 'failed' && !c.run.verified.sandboxBlocked)
|
|
73
|
+
return UNCHECKED.failedIndependently;
|
|
74
|
+
if (c.run.status === 'ok' && c.run.verified?.sandboxBlocked)
|
|
75
|
+
return UNCHECKED.notRun;
|
|
76
|
+
if (c.run.status === 'ok' && c.run.verified?.result === 'passed')
|
|
77
|
+
return ACTION.ok;
|
|
51
78
|
if (c.run.status === 'ok' && c.run.checks && c.run.checks.result !== 'passed') {
|
|
52
79
|
return c.run.checks.result === 'failed' ? UNCHECKED.failed : UNCHECKED.notRun;
|
|
53
80
|
}
|
|
@@ -55,19 +82,24 @@ export function formatReport(cards, since, facts) {
|
|
|
55
82
|
};
|
|
56
83
|
const rank = (c) => actionOf(c)?.rank ?? 9;
|
|
57
84
|
const sorted = [...cards].sort((a, b) => rank(a) - rank(b));
|
|
58
|
-
const out = [`🍪 While you were away · ${cards.length} card${cards.length === 1 ? '' : 's'}`, ''];
|
|
85
|
+
const out = [`🍪 While you were away · ${cards.length} card${cards.length === 1 ? '' : 's'}`, ...(extras.header ?? []), ''];
|
|
59
86
|
for (const c of sorted) {
|
|
60
87
|
const decided = c.outcome ? DECIDED[c.outcome] : undefined;
|
|
61
88
|
const action = actionOf(c) ?? { icon: '•', text: 'Take a look' };
|
|
62
89
|
const { files, questions } = decided ? { files: [], questions: [] } : facts(c);
|
|
63
90
|
out.push(`${action.icon} #${c.id} ${c.title}`);
|
|
64
91
|
out.push(` → ${action.text}`);
|
|
65
|
-
|
|
92
|
+
const v = c.run.verified;
|
|
93
|
+
if (!decided && v && v.result !== 'not run')
|
|
94
|
+
wrap(`${v.result === 'passed' ? '✓' : '✗'} ${v.why} (run by Chompyy, not the agent)`, 70).forEach((part, i) => out.push(` ${i === 0 ? '·' : ' '} ${part}`));
|
|
95
|
+
else if (!decided && action !== ACTION[c.run.status] && c.run.checks?.why)
|
|
66
96
|
wrap(c.run.checks.why, 70).forEach((part, i) => out.push(` ${i === 0 ? '·' : ' '} ${part}`));
|
|
67
97
|
for (const q of questions)
|
|
68
98
|
wrap(q, 70).forEach((part, i) => out.push(` ${i === 0 ? '·' : ' '} ${part}`));
|
|
69
99
|
if (!decided)
|
|
70
100
|
out.push(` changed: ${filesLine(files)} · took ${formatDuration(c.run.durationMs)}`);
|
|
101
|
+
if (!decided && c.run.tokens)
|
|
102
|
+
out.push(` used: ${formatTokens(c.run.tokens)}`);
|
|
71
103
|
out.push('');
|
|
72
104
|
}
|
|
73
105
|
const top = sorted[0];
|
|
@@ -75,6 +107,7 @@ export function formatReport(cards, since, facts) {
|
|
|
75
107
|
out.push(top.outcome
|
|
76
108
|
? `More on a card: chompyy show ${id} · rate ${id} <1-5>`
|
|
77
109
|
: `More on a card: chompyy show ${id} · diff ${id} · keep ${id} · undo ${id} · rate ${id} <1-5>`);
|
|
110
|
+
out.push(...footer);
|
|
78
111
|
return out.join('\n');
|
|
79
112
|
}
|
|
80
113
|
export function rateCard(board, id, score, reason, now, toFive = []) {
|
|
@@ -90,7 +123,7 @@ export function rateCard(board, id, score, reason, now, toFive = []) {
|
|
|
90
123
|
if (card.outcome)
|
|
91
124
|
card.column = 'done';
|
|
92
125
|
card.updatedAt = at;
|
|
93
|
-
// Raw material for taste distillation (spec §5.8).
|
|
126
|
+
// Raw material for taste distillation (spec §5.8, taste.ts).
|
|
94
127
|
appendJsonl(homePath('signals.jsonl'), {
|
|
95
128
|
at,
|
|
96
129
|
card: card.id,
|
|
@@ -103,17 +136,4 @@ export function rateCard(board, id, score, reason, now, toFive = []) {
|
|
|
103
136
|
});
|
|
104
137
|
return card;
|
|
105
138
|
}
|
|
106
|
-
export
|
|
107
|
-
|
|
108
|
-
What Chompyy has learned about how you like work done. Plain text: edit it freely, your edits win.
|
|
109
|
-
Nothing is distilled yet; ratings collect in signals.jsonl until the distiller exists.
|
|
110
|
-
|
|
111
|
-
## Everywhere
|
|
112
|
-
`;
|
|
113
|
-
export function readTaste() {
|
|
114
|
-
const path = homePath('taste.md');
|
|
115
|
-
if (existsSync(path))
|
|
116
|
-
return { path, text: readFileSync(path, 'utf8'), created: false };
|
|
117
|
-
writeFileSync(path, TASTE_STUB);
|
|
118
|
-
return { path, text: TASTE_STUB, created: true };
|
|
119
|
-
}
|
|
139
|
+
export { readTaste, TASTE_STUB } from './taste.js';
|
package/dist/review.js
CHANGED
|
@@ -3,7 +3,16 @@
|
|
|
3
3
|
import { execFileSync } from 'node:child_process';
|
|
4
4
|
import { existsSync, readFileSync, readdirSync, rmSync } from 'node:fs';
|
|
5
5
|
import { join } from 'node:path';
|
|
6
|
+
import { homePath } from './home.js';
|
|
6
7
|
import { commitLeftovers, gitRoot, uncommittedWork } from './workspace.js';
|
|
8
|
+
/**
|
|
9
|
+
* What a card's changes are measured from: the commit it started from (the latest main at the time), so the
|
|
10
|
+
* list shows only the card's own work. Measuring from your folder's HEAD showed 56 files for a 6-file card when
|
|
11
|
+
* the folder sat on an older commit (2026-11-18). Older cards without a base fall back to HEAD.
|
|
12
|
+
*/
|
|
13
|
+
function since(run) {
|
|
14
|
+
return run.base?.commit ?? 'HEAD';
|
|
15
|
+
}
|
|
7
16
|
function git(cwd, args) {
|
|
8
17
|
return execFileSync('git', ['-C', cwd, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
|
|
9
18
|
}
|
|
@@ -59,7 +68,7 @@ export function changedFiles(card) {
|
|
|
59
68
|
const root = gitRoot(card.cwd);
|
|
60
69
|
if (!root)
|
|
61
70
|
return [];
|
|
62
|
-
return git(root, ['diff', '--name-only',
|
|
71
|
+
return git(root, ['diff', '--name-only', `${since(run)}...${run.branch}`]).split('\n').filter(Boolean);
|
|
63
72
|
}
|
|
64
73
|
return readdirSync(run.workdir, { recursive: true, withFileTypes: true })
|
|
65
74
|
.filter((d) => d.isFile())
|
|
@@ -69,6 +78,35 @@ export function changedFiles(card) {
|
|
|
69
78
|
return [];
|
|
70
79
|
}
|
|
71
80
|
}
|
|
81
|
+
/** File paths a blueprint names: `src/x.ts`, docs/README.md, … (a guess at what a card will touch). */
|
|
82
|
+
export function blueprintFiles(blueprint) {
|
|
83
|
+
if (!blueprint)
|
|
84
|
+
return [];
|
|
85
|
+
const found = new Set();
|
|
86
|
+
for (const m of blueprint.matchAll(/`([^`\s]+)`|(?:^|[\s(])((?:[\w.-]+\/)*[\w-]+\.[a-z]{1,6})(?=[\s),.:;]|$)/gim)) {
|
|
87
|
+
const p = (m[1] ?? m[2] ?? '').replace(/^\.\//, '');
|
|
88
|
+
if (/\.[a-z]{1,6}$/i.test(p) && !/^https?:/.test(p) && !/^\d+(\.\d+)+$/.test(p) && !/^(e\.g|i\.e|etc)\.?$/i.test(p))
|
|
89
|
+
found.add(p);
|
|
90
|
+
}
|
|
91
|
+
return [...found];
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Cards already queued, running or waiting for review that look like they touch the same files as `card`:
|
|
95
|
+
* from what a run really changed, else the files its blueprint names. A warning, not a block: overlaps only
|
|
96
|
+
* conflict at keep time, and Run again recovers.
|
|
97
|
+
*/
|
|
98
|
+
export function overlaps(card, others, changed = changedFiles) {
|
|
99
|
+
const mine = new Set(blueprintFiles(card.blueprint));
|
|
100
|
+
if (!mine.size)
|
|
101
|
+
return [];
|
|
102
|
+
return others
|
|
103
|
+
.filter((o) => o.id !== card.id && o.cwd === card.cwd && (['approved', 'running'].includes(o.column) || (o.column === 'review' && !o.outcome)))
|
|
104
|
+
.map((o) => {
|
|
105
|
+
const theirs = o.run ? changed(o) : blueprintFiles(o.blueprint);
|
|
106
|
+
return { id: o.id, title: o.title, files: theirs.filter((f) => mine.has(f)) };
|
|
107
|
+
})
|
|
108
|
+
.filter((o) => o.files.length);
|
|
109
|
+
}
|
|
72
110
|
export function diffCard(card) {
|
|
73
111
|
const run = ran(card);
|
|
74
112
|
if (!run.branch)
|
|
@@ -76,30 +114,86 @@ export function diffCard(card) {
|
|
|
76
114
|
const root = gitRoot(card.cwd);
|
|
77
115
|
if (!root)
|
|
78
116
|
throw new Error(`${card.cwd} is no longer a git repo.`);
|
|
79
|
-
return git(root, ['diff', '--stat', '--patch',
|
|
117
|
+
return git(root, ['diff', '--stat', '--patch', `${since(run)}...${run.branch}`]) || 'No changes on the branch.';
|
|
80
118
|
}
|
|
81
119
|
function removeWorktree(root, card) {
|
|
82
120
|
const run = ran(card);
|
|
83
121
|
if (existsSync(run.workdir))
|
|
84
122
|
git(root, ['worktree', 'remove', '--force', run.workdir]);
|
|
85
123
|
}
|
|
86
|
-
/**
|
|
124
|
+
/**
|
|
125
|
+
* Where Keep lands a card that started from the latest main: the folder that has that branch open (merged there,
|
|
126
|
+
* with your unsaved work protected as before), else a temporary copy of the branch, so your folders aren't touched.
|
|
127
|
+
*/
|
|
128
|
+
export function landingFor(root, branch, id) {
|
|
129
|
+
const blocks = git(root, ['worktree', 'list', '--porcelain']).split('\n\n');
|
|
130
|
+
for (const b of blocks) {
|
|
131
|
+
const dir = b.match(/^worktree (.+)$/m)?.[1];
|
|
132
|
+
if (dir && b.includes(`\nbranch refs/heads/${branch}`) && existsSync(dir))
|
|
133
|
+
return { dir, temporary: false };
|
|
134
|
+
}
|
|
135
|
+
const has = (ref) => {
|
|
136
|
+
try {
|
|
137
|
+
git(root, ['rev-parse', '--verify', '--quiet', ref]);
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
if (!has(`refs/heads/${branch}`)) {
|
|
145
|
+
if (!has(`refs/remotes/origin/${branch}`))
|
|
146
|
+
throw new Error(`There's no ${branch} branch in ${root} to keep this card on.`);
|
|
147
|
+
git(root, ['branch', branch, `origin/${branch}`]);
|
|
148
|
+
}
|
|
149
|
+
const dir = homePath('landing', id);
|
|
150
|
+
rmSync(dir, { recursive: true, force: true });
|
|
151
|
+
git(root, ['worktree', 'add', '--quiet', dir, branch]);
|
|
152
|
+
return { dir, temporary: true };
|
|
153
|
+
}
|
|
154
|
+
/** Merge the card's branch into the branch it started from (or, for older cards, the repo's current branch), then tidy up. */
|
|
87
155
|
export function keepCard(card) {
|
|
88
156
|
const run = ran(card);
|
|
89
157
|
if (!run.branch)
|
|
90
158
|
return `Card #${card.id} ran in a draft folder; copy what you want from ${run.workdir}`;
|
|
91
|
-
const
|
|
92
|
-
if (!
|
|
159
|
+
const repo = gitRoot(card.cwd);
|
|
160
|
+
if (!repo)
|
|
93
161
|
throw new Error(`${card.cwd} is no longer a git repo.`);
|
|
94
|
-
|
|
95
|
-
|
|
162
|
+
const landing = run.base?.branch ? landingFor(repo, run.base.branch, card.id) : { dir: repo, temporary: false };
|
|
163
|
+
const root = landing.dir;
|
|
164
|
+
const dropLanding = () => {
|
|
165
|
+
if (landing.temporary) {
|
|
166
|
+
try {
|
|
167
|
+
git(repo, ['worktree', 'remove', '--force', landing.dir]);
|
|
168
|
+
}
|
|
169
|
+
catch { }
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
// Your own unsaved work only blocks Keep when it touches the same files as the card (git's own rule),
|
|
173
|
+
// or when something is staged (git won't put unrelated staged changes into a merge commit).
|
|
174
|
+
const into = git(root, ['rev-parse', '--abbrev-ref', 'HEAD']);
|
|
175
|
+
const yours = [...new Set(git(root, ['status', '--porcelain', '--untracked-files=all']).split('\n').filter(Boolean)
|
|
176
|
+
.map((l) => l.trim().replace(/^\S+\s+/, '').replace(/^.* -> /, '')))];
|
|
177
|
+
if (yours.length) {
|
|
178
|
+
const theirs = new Set(git(root, ['diff', '--name-only', `${since(run)}...${run.branch}`]).split('\n').filter(Boolean));
|
|
179
|
+
const clash = yours.filter((f) => theirs.has(f));
|
|
180
|
+
const staged = git(root, ['diff', '--cached', '--name-only']).split('\n').filter(Boolean);
|
|
181
|
+
const list = (fs) => fs.slice(0, 3).join(', ') + (fs.length > 3 ? ` and ${fs.length - 3} more` : '');
|
|
182
|
+
if (clash.length) {
|
|
183
|
+
dropLanding();
|
|
184
|
+
throw new Error(`Can't keep #${card.id} yet: it changes ${list(clash)}, and you have unsaved changes in ${clash.length === 1 ? 'that file' : 'those files'} in ${root} (branch ${into}). Commit or set them aside first, or press Undo to drop the card's work.`);
|
|
185
|
+
}
|
|
186
|
+
if (staged.length) {
|
|
187
|
+
dropLanding();
|
|
188
|
+
throw new Error(`Can't keep #${card.id} yet: ${root} has staged changes (${list(staged)}) that a merge would mix in. Commit or unstage them first, or press Undo to drop the card's work.`);
|
|
189
|
+
}
|
|
96
190
|
}
|
|
97
191
|
commitLeftovers({ kind: 'worktree', dir: run.workdir }, card); // older runs may have left work uncommitted
|
|
98
192
|
const loose = uncommittedWork(run.workdir);
|
|
99
193
|
if (loose.length) {
|
|
194
|
+
dropLanding();
|
|
100
195
|
throw new Error(`The card's folder has uncommitted work that keep would lose: ${loose.slice(0, 5).join(', ')}. Commit it in ${run.workdir} first.`);
|
|
101
196
|
}
|
|
102
|
-
const into = git(root, ['rev-parse', '--abbrev-ref', 'HEAD']);
|
|
103
197
|
try {
|
|
104
198
|
git(root, ['merge', '--no-ff', '-m', `Keep Chompyy card #${card.id}: ${card.title}`, run.branch]);
|
|
105
199
|
}
|
|
@@ -108,11 +202,17 @@ export function keepCard(card) {
|
|
|
108
202
|
git(root, ['merge', '--abort']);
|
|
109
203
|
}
|
|
110
204
|
catch { }
|
|
205
|
+
dropLanding();
|
|
111
206
|
throw new Error(`${run.branch} conflicts with ${into}: another card or your own work changed the same lines. Nothing was changed. Run it again on top of the latest with \`chompyy redo ${card.id}\` (or merge by hand: git -C ${root} merge ${run.branch}).`);
|
|
112
207
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
208
|
+
dropLanding();
|
|
209
|
+
removeWorktree(repo, card);
|
|
210
|
+
git(repo, ['branch', '-D', run.branch]); // merged just now (into the landing branch, which may not be this folder's)
|
|
211
|
+
const note = yours.length ? ` Your ${yours.length} unsaved change${yours.length === 1 ? ' was' : 's were'} left as they were.` : '';
|
|
212
|
+
if (landing.temporary) {
|
|
213
|
+
return `Kept #${card.id}: merged ${run.branch} into ${into} (none of your folders has ${into} open, so they weren't touched).${note} Undo it with \`git -C ${repo} branch -f ${into} ${into}~1\`.`;
|
|
214
|
+
}
|
|
215
|
+
return `Kept #${card.id}: merged ${run.branch} into ${into}${root !== repo ? ` in ${root}` : ''}.${note} Undo it with \`git -C ${root} reset --hard HEAD~1\`.`;
|
|
116
216
|
}
|
|
117
217
|
/** Throw the run away: remove the worktree and branch (or the draft folder). */
|
|
118
218
|
export function undoCard(card) {
|