chompyy 0.0.0-stage β†’ 0.1.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/dist/board.js ADDED
@@ -0,0 +1,156 @@
1
+ // The board (spec Β§5.3): cards in columns, stored in ~/.chompyy/board.json.
2
+ import { appendJsonl, homePath, readJson, writeJson } from './home.js';
3
+ export const COLUMNS = ['suggested', 'later', 'approved', 'running', 'review', 'done'];
4
+ export const COLUMN_LABEL = {
5
+ suggested: 'πŸ’‘ suggested',
6
+ later: 'πŸ“₯ later',
7
+ approved: 'βœ… approved',
8
+ running: 'βš™οΈ running',
9
+ review: 'πŸ‘€ review',
10
+ done: '⭐ done',
11
+ };
12
+ /** Which moves are allowed. Running and review are only entered by an away run. */
13
+ const TRANSITIONS = {
14
+ suggested: ['later', 'approved'],
15
+ later: ['approved'],
16
+ approved: ['running', 'later'],
17
+ running: ['review', 'approved'],
18
+ review: ['done', 'approved'],
19
+ done: [],
20
+ };
21
+ export function boardPath() {
22
+ return homePath('board.json');
23
+ }
24
+ export function loadBoard() {
25
+ return readJson(boardPath(), { nextId: 1, cards: [] });
26
+ }
27
+ export function saveBoard(board) {
28
+ writeJson(boardPath(), board);
29
+ }
30
+ /** Load, change, save. Keeps the read-modify-write window short (a background blueprint may write too). */
31
+ export function updateBoard(fn) {
32
+ const board = loadBoard();
33
+ const result = fn(board);
34
+ saveBoard(board);
35
+ return result;
36
+ }
37
+ export function titleFrom(idea) {
38
+ const first = idea.trim().split('\n')[0] ?? '';
39
+ return first.length > 60 ? first.slice(0, 57).trimEnd() + '…' : first;
40
+ }
41
+ export function addCard(board, idea, cwd, now, column = 'later') {
42
+ const text = idea.trim();
43
+ if (!text)
44
+ throw new Error('The idea is empty.');
45
+ const at = now.toISOString();
46
+ const card = {
47
+ id: String(board.nextId++),
48
+ title: titleFrom(text),
49
+ idea: text,
50
+ cwd,
51
+ column,
52
+ blueprint: null,
53
+ createdAt: at,
54
+ updatedAt: at,
55
+ };
56
+ board.cards.push(card);
57
+ return card;
58
+ }
59
+ export function getCard(board, id) {
60
+ const card = board.cards.find((c) => c.id === id.replace(/^#/, ''));
61
+ if (!card)
62
+ throw new Error(`No card #${id}. See \`chompyy board\`.`);
63
+ return card;
64
+ }
65
+ export function canMove(from, to) {
66
+ return TRANSITIONS[from].includes(to);
67
+ }
68
+ export function moveCard(board, id, to, now) {
69
+ const card = getCard(board, id);
70
+ if (!canMove(card.column, to))
71
+ throw new Error(`Card #${card.id} is in ${card.column}; it can't move to ${to}.`);
72
+ if (to === 'approved' && !card.blueprint?.trim()) {
73
+ throw new Error(`Card #${card.id} has no blueprint yet. Run \`chompyy blueprint ${card.id}\` first.`);
74
+ }
75
+ card.column = to;
76
+ card.updatedAt = now.toISOString();
77
+ if (to === 'approved')
78
+ card.approvedAt = card.updatedAt;
79
+ return card;
80
+ }
81
+ /** Remove a card from the board; it is kept in archive.jsonl in case you want it back. */
82
+ export function dropCard(board, id, now) {
83
+ const card = getCard(board, id);
84
+ if (card.column === 'running')
85
+ throw new Error(`Card #${card.id} is running; wait for the run to finish.`);
86
+ board.cards = board.cards.filter((c) => c !== card);
87
+ appendJsonl(homePath('archive.jsonl'), { ...card, droppedAt: now.toISOString() });
88
+ return card;
89
+ }
90
+ export function cardsIn(board, column) {
91
+ return board.cards.filter((c) => c.column === column);
92
+ }
93
+ /** Approved cards in the order they were approved: the away queue. */
94
+ /** Cards stuck in running (the away run was stopped or crashed) go back to approved. Returns their ids. */
95
+ export function recoverRunning(board, now) {
96
+ const stuck = cardsIn(board, 'running');
97
+ for (const c of stuck) {
98
+ c.column = 'approved';
99
+ c.updatedAt = now.toISOString();
100
+ }
101
+ return stuck.map((c) => c.id);
102
+ }
103
+ export function awayQueue(board) {
104
+ return cardsIn(board, 'approved').sort((a, b) => (a.approvedAt ?? '').localeCompare(b.approvedAt ?? ''));
105
+ }
106
+ function shortPath(p) {
107
+ const home = process.env.HOME;
108
+ return home && p.startsWith(home) ? '~' + p.slice(home.length) : p;
109
+ }
110
+ function cardLine(c) {
111
+ const marks = [];
112
+ if (c.column === 'later' || c.column === 'suggested') {
113
+ marks.push(c.blueprint ? 'blueprint βœ“' : c.blueprintError ? 'blueprint failed' : 'no blueprint');
114
+ }
115
+ if (c.run)
116
+ marks.push(c.run.status);
117
+ if (c.rating)
118
+ marks.push(`${'β˜…'.repeat(c.rating.score)}`);
119
+ const tail = marks.length ? ` [${marks.join(' Β· ')}]` : '';
120
+ return ` #${c.id.padEnd(3)} ${c.title}${tail} ${shortPath(c.cwd)}`;
121
+ }
122
+ export function formatBoard(board, columns = COLUMNS) {
123
+ if (board.cards.length === 0)
124
+ return 'The board is empty. Park an idea with `chompyy later "<idea>"`.';
125
+ const out = [];
126
+ for (const col of columns) {
127
+ const cards = cardsIn(board, col);
128
+ if (cards.length === 0)
129
+ continue;
130
+ out.push(`${COLUMN_LABEL[col]} (${cards.length})`);
131
+ for (const c of cards)
132
+ out.push(cardLine(c));
133
+ }
134
+ return out.length ? out.join('\n') : `No cards in ${columns.join(', ')}.`;
135
+ }
136
+ export function formatCard(c) {
137
+ const lines = [
138
+ `#${c.id} ${c.title}`,
139
+ `column: ${c.column} Β· cwd: ${shortPath(c.cwd)} Β· created ${c.createdAt}`,
140
+ ];
141
+ if (c.idea !== c.title)
142
+ lines.push('', c.idea);
143
+ lines.push('', c.blueprint ?? (c.blueprintError ? `(blueprint failed: ${c.blueprintError})` : '(no blueprint yet)'));
144
+ if (c.run) {
145
+ lines.push('', `last run: ${c.run.status} Β· ${c.run.workdir}${c.run.branch ? ` Β· branch ${c.run.branch}` : ''}`);
146
+ if (c.run.summary)
147
+ lines.push('', 'what the agent said:', ...c.run.summary.split('\n').map((l) => ` ${l}`));
148
+ }
149
+ if (c.logPath)
150
+ lines.push(`log: ${c.logPath}`);
151
+ if (c.outcome)
152
+ lines.push(`outcome: ${c.outcome}`);
153
+ if (c.rating)
154
+ lines.push(`rating: ${c.rating.score}/5${c.rating.reason ? ` Β· ${c.rating.reason}` : ''}`);
155
+ return lines.join('\n');
156
+ }
package/dist/cli.js ADDED
@@ -0,0 +1,479 @@
1
+ #!/usr/bin/env node
2
+ // chompyy: park ideas, blueprint them, run approved cards while you're away.
3
+ import { spawn } from 'node:child_process';
4
+ import { existsSync, readFileSync } from 'node:fs';
5
+ import { parseArgs } from 'node:util';
6
+ import { away } from './away.js';
7
+ import { draftBlueprint, draftFiveStarOptions, GENERIC_FIVE_STAR } from './blueprint.js';
8
+ import { addCard, COLUMNS, dropCard, formatBoard, formatCard, getCard, loadBoard, moveCard, updateBoard } from './board.js';
9
+ import { loadConfig } from './config.js';
10
+ import { formatDuration, parseDuration } from './duration.js';
11
+ import { budgetGate } from './gate.js';
12
+ import { chompyyHome, homePath } from './home.js';
13
+ import { loadSnapshot, mergeSnapshot, parseStatusline, saveSnapshot, statusLineText, statusText, windowView } from './quota.js';
14
+ import { cardsSince, formatReport, lastReportAt, markReported, rateCard, readTaste } from './report.js';
15
+ import { changedFiles, diffCard, keepCard, questionsOf, undoCard } from './review.js';
16
+ import { ClaudeRunner, claudeAvailable } from './runner.js';
17
+ import { commitLeftovers, planWorkspace, prepareWorkspace } from './workspace.js';
18
+ import { answerCard, appState, cardView, editBlueprint, recordCliLocation } from './appstate.js';
19
+ import { refreshLiveQuota } from './livequota.js';
20
+ import { recentProjects } from './projects.js';
21
+ import { cliVersion, installApp } from './macapp.js';
22
+ const HELP = `chompyy: use the 5-hour window capacity that would reset unused
23
+
24
+ Quota
25
+ chompyy statusline Claude Code statusLine command: reads JSON on stdin, saves a snapshot
26
+ chompyy status % left, time to reset, pace, weekly used, staleness
27
+ chompyy quota [--refresh] read live quota from Anthropic now (uses Claude Code's saved login; sends no message)
28
+ chompyy eat-tokens show leftover quota and cards you could choose to run (read-only)
29
+
30
+ Board
31
+ chompyy later "<idea>" park an idea in later (blueprint drafted in the background)
32
+ --no-blueprint don't draft one --wait draft it now, in the foreground
33
+ chompyy board [--column c] cards by column (suggested later approved running review done)
34
+ chompyy show <id> one card: blueprint, last run, what the agent said
35
+ chompyy blueprint <id> (re)draft the blueprint with a cheap model [--model haiku]
36
+ chompyy approve <id> later β†’ approved (needs a blueprint)
37
+ chompyy edit-blueprint <id> replace the blueprint with text from stdin
38
+ chompyy drop <id> remove a card (kept in archive.jsonl)
39
+
40
+ Away
41
+ chompyy away <1h|30m|1h30m> run approved cards headless, one at a time, until the time is up
42
+ --dry-run print the plan, start nothing
43
+ --force skip the budget gate (the duration still holds)
44
+
45
+ Back
46
+ chompyy report [--all] what ran, and the one thing to do about each
47
+ chompyy diff <id> the change it made
48
+ chompyy keep <id> merge its branch into your current branch
49
+ chompyy undo <id> throw it away (removes its branch; yours are untouched)
50
+ chompyy answer <id> answer the run's questions (stdin); the card goes back to approved
51
+ chompyy redo <id> throw this attempt away and run it again from your latest code
52
+ chompyy rate <id> <1-5> ["why"] [--to-five "change" ...] rate a result; --to-five = what would have made it a 5
53
+ chompyy five-star <id> options for "what would have made it a 5?" (JSON)
54
+ chompyy taste show taste.md
55
+ chompyy signals [--json] everything Chompyy has recorded from you: ratings, edits, answers
56
+
57
+ App
58
+ chompyy app install (or update) the Mac app in ~/Applications and open it
59
+ chompyy version this CLI's version
60
+ chompyy projects [--json] recent project folders (from Claude Code history and past cards)
61
+ chompyy state --json everything the Mac app shows, in one JSON (board, show, status also take --json)
62
+
63
+ State lives in ${chompyyHome()} (override with CHOMPYY_HOME).`;
64
+ async function readStdin() {
65
+ if (process.stdin.isTTY)
66
+ return '';
67
+ const chunks = [];
68
+ for await (const chunk of process.stdin)
69
+ chunks.push(chunk);
70
+ return Buffer.concat(chunks).toString('utf8');
71
+ }
72
+ function need(value, usage) {
73
+ if (!value)
74
+ throw new Error(`Usage: ${usage}`);
75
+ return value;
76
+ }
77
+ async function blueprintCard(id, model) {
78
+ const config = loadConfig();
79
+ const card = getCard(loadBoard(), id);
80
+ try {
81
+ const text = await draftBlueprint(card, new ClaudeRunner(config.claudeBin), {
82
+ model: model ?? config.blueprintModel,
83
+ // Run in the card's folder so the model can read the repo (read-only tools only).
84
+ cwd: existsSync(card.cwd) ? card.cwd : chompyyHome(),
85
+ });
86
+ updateBoard((b) => {
87
+ const c = getCard(b, id);
88
+ c.blueprint = text;
89
+ delete c.blueprintError;
90
+ delete c.draftingAt;
91
+ c.updatedAt = new Date().toISOString();
92
+ });
93
+ return text;
94
+ }
95
+ catch (err) {
96
+ const message = err instanceof Error ? err.message : String(err);
97
+ updateBoard((b) => {
98
+ const c = getCard(b, id);
99
+ c.blueprintError = message;
100
+ delete c.draftingAt;
101
+ });
102
+ throw err;
103
+ }
104
+ }
105
+ /** The agent's whole final message from the run log (the board keeps only its first lines). */
106
+ function fullOutput(card) {
107
+ if (!card.logPath || !existsSync(card.logPath))
108
+ return undefined;
109
+ const m = readFileSync(card.logPath, 'utf8').match(/# output\n\n([\s\S]*?)\n\n# stderr/);
110
+ return m?.[1]?.trim().slice(0, 4000);
111
+ }
112
+ /** True when a 5-hour window is already running, so a model call uses it instead of starting a new one. */
113
+ function windowActive(now) {
114
+ return windowView(loadSnapshot()?.fiveHour, now).known;
115
+ }
116
+ /**
117
+ * Draft blueprints that are waiting, but only while a window is active: drafting is a model call, and
118
+ * with no active window it would start a new 5-hour window. Called whenever quota is fresh.
119
+ */
120
+ function draftPending(now) {
121
+ if (!windowActive(now) || !claudeAvailable(loadConfig().claudeBin))
122
+ return;
123
+ const stale = now.getTime() - 3 * 60_000;
124
+ const ids = updateBoard((b) => {
125
+ const due = b.cards.filter((c) => (c.column === 'later' || c.column === 'suggested') && !c.blueprint && !c.blueprintError && !c.noAutoDraft && (!c.draftingAt || Date.parse(c.draftingAt) < stale));
126
+ for (const c of due)
127
+ c.draftingAt = now.toISOString();
128
+ return due.map((c) => c.id);
129
+ });
130
+ for (const id of ids)
131
+ blueprintInBackground(id);
132
+ }
133
+ /** Draft the blueprint in a detached child so `later` returns at once. */
134
+ function blueprintInBackground(id) {
135
+ const child = spawn(process.execPath, [process.argv[1], 'blueprint', id, '--quiet'], {
136
+ detached: true,
137
+ stdio: 'ignore',
138
+ env: process.env,
139
+ });
140
+ child.unref();
141
+ }
142
+ async function main(argv) {
143
+ const { values, positionals } = parseArgs({
144
+ args: argv,
145
+ allowPositionals: true,
146
+ options: {
147
+ 'no-blueprint': { type: 'boolean' },
148
+ wait: { type: 'boolean' },
149
+ 'dry-run': { type: 'boolean' },
150
+ force: { type: 'boolean' },
151
+ all: { type: 'boolean' },
152
+ quiet: { type: 'boolean' },
153
+ model: { type: 'string' },
154
+ column: { type: 'string', multiple: true },
155
+ help: { type: 'boolean', short: 'h' },
156
+ json: { type: 'boolean' },
157
+ refresh: { type: 'boolean' },
158
+ 'to-five': { type: 'string', multiple: true },
159
+ },
160
+ });
161
+ const [command, ...args] = values.help ? ["help"] : positionals;
162
+ const now = new Date();
163
+ const json = (data) => console.log(JSON.stringify(data, null, 2));
164
+ if (command !== 'statusline')
165
+ recordCliLocation();
166
+ /** Fresh quota before anything that reads it (at most every 5 minutes unless forced). */
167
+ const freshQuota = async (force = false) => {
168
+ if (loadConfig().quotaSource !== 'api')
169
+ return null;
170
+ try {
171
+ return await refreshLiveQuota({ force });
172
+ }
173
+ catch {
174
+ return null;
175
+ }
176
+ };
177
+ switch (command) {
178
+ case 'statusline': {
179
+ // Must never fail loudly: it runs on every status bar refresh.
180
+ try {
181
+ const parsed = parseStatusline(await readStdin(), now);
182
+ const snap = mergeSnapshot(loadSnapshot(), { ...parsed, ...(parsed.fiveHour || parsed.sevenDay ? { source: 'statusline' } : {}) });
183
+ saveSnapshot(snap);
184
+ console.log(statusLineText(snap, now));
185
+ }
186
+ catch {
187
+ console.log('πŸͺ');
188
+ }
189
+ return;
190
+ }
191
+ case 'status': {
192
+ await freshQuota();
193
+ draftPending(now);
194
+ if (values.json)
195
+ return json(appState(loadBoard(), loadSnapshot(), loadConfig(), now).quota);
196
+ console.log(statusText(loadSnapshot(), now));
197
+ return;
198
+ }
199
+ case 'quota': {
200
+ const r = await freshQuota(Boolean(values.refresh));
201
+ if (r)
202
+ console.log(r.message);
203
+ else if (loadConfig().quotaSource !== 'api')
204
+ console.log('quotaSource is "statusline" in config.json; live reading is off.');
205
+ console.log(statusText(loadSnapshot(), now));
206
+ return;
207
+ }
208
+ case 'state': {
209
+ await freshQuota(Boolean(values.refresh));
210
+ draftPending(now);
211
+ return json(appState(loadBoard(), loadSnapshot(), loadConfig(), now));
212
+ }
213
+ case 'app': {
214
+ console.log(`Downloading Chompyy ${cliVersion()} for Mac…`);
215
+ const at = await installApp();
216
+ console.log(`Installed ${at} and opened it. Look for the cookie in your menu bar.`);
217
+ return;
218
+ }
219
+ case 'version':
220
+ console.log(cliVersion());
221
+ return;
222
+ case 'projects': {
223
+ const list = recentProjects(loadBoard());
224
+ if (values.json)
225
+ return json(list);
226
+ for (const p of list)
227
+ console.log(`${p.name.padEnd(28)} ${p.path}${p.isGit ? '' : ' (not a git repo)'}`);
228
+ return;
229
+ }
230
+ case 'five-star': {
231
+ // Options for "what would have made it a 5?", written for this card; cached on the card.
232
+ const id = need(args[0], 'chompyy five-star <id>');
233
+ const card = getCard(loadBoard(), id);
234
+ if (card.fiveStarOptions?.length)
235
+ return json(card.fiveStarOptions);
236
+ await freshQuota();
237
+ // A model call with no active window would start one, so fall back to generic options then.
238
+ if (!windowActive(now) || !claudeAvailable(loadConfig().claudeBin))
239
+ return json(GENERIC_FIVE_STAR);
240
+ try {
241
+ const view = cardView(card);
242
+ const options = await draftFiveStarOptions({ idea: card.idea, blueprint: card.blueprint, summary: fullOutput(card) ?? card.run?.summary, files: view.files }, new ClaudeRunner(loadConfig().claudeBin), { model: loadConfig().blueprintModel, cwd: chompyyHome() });
243
+ updateBoard((b) => {
244
+ getCard(b, id).fiveStarOptions = options;
245
+ });
246
+ return json(options);
247
+ }
248
+ catch {
249
+ return json(GENERIC_FIVE_STAR);
250
+ }
251
+ }
252
+ case 'signals': {
253
+ const path = homePath('signals.jsonl');
254
+ const lines = existsSync(path) ? readFileSync(path, 'utf8').split('\n').filter(Boolean) : [];
255
+ const items = lines.flatMap((l) => {
256
+ try {
257
+ return [JSON.parse(l)];
258
+ }
259
+ catch {
260
+ return [];
261
+ }
262
+ });
263
+ if (values.json)
264
+ return json(items.reverse());
265
+ for (const s of items)
266
+ console.log(`${s.at.slice(0, 16)} #${s.card} ${s.kind ?? 'rating'} ${s.rating ? `${s.rating}/5 ` : ''}${s.reason ?? s.text ?? ''}${s.toFive ? ` β†’ to make it a 5: ${s.toFive.join('; ')}` : ''}`);
267
+ return;
268
+ }
269
+ case 'edit-blueprint': {
270
+ const id = need(args[0], 'chompyy edit-blueprint <id> (new blueprint on stdin)');
271
+ const text = await readStdin();
272
+ const card = updateBoard((b) => editBlueprint(b, id, text, now));
273
+ console.log(`✏️ #${card.id} blueprint updated.`);
274
+ return;
275
+ }
276
+ case 'answer': {
277
+ const id = need(args[0], 'chompyy answer <id> (answers on stdin)');
278
+ const text = args.slice(1).join(' ').trim() || (await readStdin());
279
+ const card = updateBoard((b) => answerCard(b, id, text, now));
280
+ console.log(`πŸ’¬ #${card.id} answered and back in approved; the next away run continues it.`);
281
+ return;
282
+ }
283
+ case 'eat-tokens': {
284
+ await freshQuota();
285
+ const snapshot = loadSnapshot();
286
+ console.log(statusText(snapshot, now));
287
+ const view = windowView(snapshot?.fiveHour, now);
288
+ if (!view.known) {
289
+ console.log('\nNo leftover window can be planned: refresh the Claude Code status line first.');
290
+ return;
291
+ }
292
+ const eligible = loadBoard().cards.filter((card) => card.column === 'approved' || card.column === 'later');
293
+ if (!eligible.length) {
294
+ console.log('\nNo cards to consider. Park an idea with `chompyy later "<idea>"`.');
295
+ return;
296
+ }
297
+ console.log(`\n${Math.round(view.leftPct)}% left until reset (${formatDuration(view.msLeft)}). Choose from these cards:`);
298
+ for (const card of eligible) {
299
+ const state = card.column === 'approved' ? 'approved Β· ready' : 'later Β· approve to run';
300
+ console.log(` #${card.id} ${card.title} [${state}]`);
301
+ if (card.column === 'later' && !card.blueprint?.trim())
302
+ console.log(' blueprint needed before approval');
303
+ }
304
+ console.log('\nThis is a read-only list. Start selected work with `chompyy away <duration>`.');
305
+ return;
306
+ }
307
+ case 'later': {
308
+ const idea = need(args.join(' ').trim(), 'chompyy later "<idea>"');
309
+ const card = updateBoard((b) => addCard(b, idea, process.cwd(), now));
310
+ console.log(`πŸ“₯ #${card.id} parked in later: ${card.title}`);
311
+ if (values['no-blueprint']) {
312
+ updateBoard((b) => {
313
+ getCard(b, card.id).noAutoDraft = true;
314
+ });
315
+ return;
316
+ }
317
+ if (!claudeAvailable(loadConfig().claudeBin)) {
318
+ console.log(` (claude CLI not found; draft the blueprint later with \`chompyy blueprint ${card.id}\`)`);
319
+ return;
320
+ }
321
+ if (values.wait) {
322
+ try {
323
+ console.log('\n' + (await blueprintCard(card.id)));
324
+ }
325
+ catch (err) {
326
+ console.log(` blueprint failed: ${err instanceof Error ? err.message : err}`);
327
+ }
328
+ return;
329
+ }
330
+ await freshQuota();
331
+ if (!windowActive(now)) {
332
+ console.log(' the blueprint waits until your 5-hour window is active (drafting now would start a new window)');
333
+ return;
334
+ }
335
+ updateBoard((b) => {
336
+ getCard(b, card.id).draftingAt = now.toISOString();
337
+ });
338
+ blueprintInBackground(card.id);
339
+ console.log(` drafting the blueprint in the background; see it with \`chompyy show ${card.id}\``);
340
+ return;
341
+ }
342
+ case 'board': {
343
+ const cols = (values.column ?? []).flatMap((c) => c.split(','));
344
+ const bad = cols.filter((c) => !COLUMNS.includes(c));
345
+ if (bad.length)
346
+ throw new Error(`Unknown column(s): ${bad.join(', ')}. Columns: ${COLUMNS.join(', ')}`);
347
+ if (values.json)
348
+ return json(loadBoard().cards.filter((c) => !cols.length || cols.includes(c.column)));
349
+ console.log(formatBoard(loadBoard(), cols.length ? cols : COLUMNS));
350
+ return;
351
+ }
352
+ case 'show': {
353
+ const card = getCard(loadBoard(), need(args[0], 'chompyy show <id>'));
354
+ if (values.json)
355
+ return json(cardView(card));
356
+ console.log(formatCard(card));
357
+ return;
358
+ }
359
+ case 'blueprint': {
360
+ const id = need(args[0], 'chompyy blueprint <id> [--model haiku]');
361
+ const text = await blueprintCard(id, values.model);
362
+ if (!values.quiet)
363
+ console.log(text);
364
+ return;
365
+ }
366
+ case 'approve': {
367
+ const card = updateBoard((b) => moveCard(b, need(args[0], 'chompyy approve <id>'), 'approved', now));
368
+ console.log(`βœ… #${card.id} approved: ${card.title}`);
369
+ return;
370
+ }
371
+ case 'drop': {
372
+ const card = updateBoard((b) => dropCard(b, need(args[0], 'chompyy drop <id>'), now));
373
+ console.log(`πŸ—‘ #${card.id} dropped: ${card.title}`);
374
+ return;
375
+ }
376
+ case 'away': {
377
+ const ms = parseDuration(need(args[0], 'chompyy away <1h|30m> [--dry-run] [--force]'));
378
+ const config = loadConfig();
379
+ await freshQuota(true);
380
+ const gate = budgetGate(loadSnapshot(), config, now);
381
+ console.log(statusText(loadSnapshot(), now));
382
+ console.log(`gate ${gate.ok ? 'open' : values.force ? 'closed, forced open' : 'closed'}${[...gate.reasons, ...gate.notes].map((r) => `\n Β· ${r}`).join('')}\n`);
383
+ await away(ms, {
384
+ runner: new ClaudeRunner(config.claudeBin),
385
+ config,
386
+ now: () => Date.now(),
387
+ snapshot: loadSnapshot,
388
+ plan: planWorkspace,
389
+ prepare: prepareWorkspace,
390
+ commitLeftovers,
391
+ refreshQuota: async () => {
392
+ await freshQuota(true);
393
+ },
394
+ out: (line) => console.log(line),
395
+ }, { dryRun: values['dry-run'], force: values.force });
396
+ return;
397
+ }
398
+ case 'report': {
399
+ const since = values.all ? null : lastReportAt();
400
+ console.log(formatReport(cardsSince(loadBoard(), since), since, (c) => ({ files: changedFiles(c), questions: questionsOf(c) })));
401
+ markReported(now);
402
+ return;
403
+ }
404
+ case 'diff': {
405
+ console.log(diffCard(getCard(loadBoard(), need(args[0], 'chompyy diff <id>'))));
406
+ return;
407
+ }
408
+ case 'keep': {
409
+ const id = need(args[0], 'chompyy keep <id>');
410
+ console.log(keepCard(getCard(loadBoard(), id)));
411
+ updateBoard((b) => {
412
+ const card = getCard(b, id);
413
+ card.outcome = 'kept';
414
+ card.column = 'done';
415
+ card.updatedAt = now.toISOString();
416
+ return card;
417
+ });
418
+ return;
419
+ }
420
+ case 'undo': {
421
+ const id = need(args[0], 'chompyy undo <id>');
422
+ console.log(undoCard(getCard(loadBoard(), id)));
423
+ updateBoard((b) => {
424
+ const card = getCard(b, id);
425
+ card.outcome = 'undone';
426
+ card.column = 'done';
427
+ card.updatedAt = now.toISOString();
428
+ return card;
429
+ });
430
+ return;
431
+ }
432
+ case 'redo': {
433
+ const id = need(args[0], 'chompyy redo <id>');
434
+ const before = getCard(loadBoard(), id);
435
+ if (before.column !== 'review' && before.column !== 'done')
436
+ throw new Error(`Card #${id} is in ${before.column}; only cards that ran can be run again.`);
437
+ if (before.run)
438
+ console.log(undoCard(before));
439
+ const card = updateBoard((b) => {
440
+ const c = getCard(b, id);
441
+ c.column = 'approved';
442
+ c.approvedAt = now.toISOString();
443
+ c.updatedAt = c.approvedAt;
444
+ delete c.run;
445
+ delete c.outcome;
446
+ return c;
447
+ });
448
+ console.log(`πŸ” #${card.id} back in approved; it runs again from your latest code on the next away run.`);
449
+ return;
450
+ }
451
+ case 'rate': {
452
+ const usage = 'chompyy rate <id> <1-5> ["optional reason"]';
453
+ const id = need(args[0], usage);
454
+ const score = Number(need(args[1], usage));
455
+ const reason = args.slice(2).join(' ').trim() || undefined;
456
+ const toFive = (values['to-five'] ?? []).map((t) => t.trim()).filter(Boolean);
457
+ const card = updateBoard((b) => rateCard(b, id, score, reason, now, toFive));
458
+ console.log(`⭐ #${card.id} rated ${score}/5${reason ? ` ("${reason}")` : ''}. Saved to signals.jsonl${card.column === 'review' ? '; keep or undo it when you’re ready' : ''}.`);
459
+ return;
460
+ }
461
+ case 'taste': {
462
+ const { path, text, created } = readTaste();
463
+ if (created)
464
+ console.log(`(created ${path})\n`);
465
+ console.log(text);
466
+ return;
467
+ }
468
+ case undefined:
469
+ case 'help':
470
+ console.log(HELP);
471
+ return;
472
+ default:
473
+ throw new Error(`Unknown command "${command}". Run \`chompyy help\`.`);
474
+ }
475
+ }
476
+ main(process.argv.slice(2)).catch((err) => {
477
+ console.error(`chompyy: ${err instanceof Error ? err.message : err}`);
478
+ process.exit(1);
479
+ });
package/dist/config.js ADDED
@@ -0,0 +1,54 @@
1
+ // User settings: ~/.chompyy/config.json, merged over these defaults.
2
+ import { homePath, readJson } from './home.js';
3
+ export const DEFAULT_CONFIG = {
4
+ claudeBin: 'claude',
5
+ blueprintModel: 'haiku',
6
+ runModel: null,
7
+ cardTimeoutMin: 30,
8
+ maxTurns: 50,
9
+ min5hLeftPct: 10,
10
+ weeklyReservePct: 10,
11
+ weeklyPace: true,
12
+ permissionMode: 'acceptEdits',
13
+ permissionPrompts: 'none',
14
+ allowedTools: [
15
+ 'Read',
16
+ 'Glob',
17
+ 'Grep',
18
+ 'WebSearch',
19
+ 'WebFetch',
20
+ 'Bash(ls *)',
21
+ 'Bash(git status *)',
22
+ 'Bash(git diff *)',
23
+ 'Bash(git log *)',
24
+ 'Bash(git add *)',
25
+ 'Bash(git commit *)',
26
+ 'Bash(npm test *)',
27
+ 'Bash(npm run *)',
28
+ 'Bash(npx vitest *)',
29
+ 'Bash(pytest *)',
30
+ ],
31
+ disallowedTools: [
32
+ 'Bash(git push *)',
33
+ 'Bash(git merge *)',
34
+ 'Bash(git rebase *)',
35
+ 'Bash(git reset *)',
36
+ 'Bash(git checkout *)',
37
+ 'Bash(git switch *)',
38
+ 'Bash(git worktree *)',
39
+ 'Bash(gh *)',
40
+ 'Bash(npm publish *)',
41
+ 'Bash(curl *)',
42
+ 'Bash(rm -rf *)',
43
+ ],
44
+ sandbox: true,
45
+ sandboxAllowedDomains: [],
46
+ quotaSource: 'api',
47
+ extraArgs: [],
48
+ };
49
+ export function configPath() {
50
+ return homePath('config.json');
51
+ }
52
+ export function loadConfig() {
53
+ return { ...DEFAULT_CONFIG, ...readJson(configPath(), {}) };
54
+ }