chompyy 0.3.0 → 0.4.1
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 +6 -3
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/dist/appstate.js +81 -5
- package/dist/away.js +93 -16
- package/dist/blueprint.js +102 -7
- package/dist/board.js +110 -12
- package/dist/catalog.js +81 -0
- package/dist/cli.js +444 -56
- package/dist/coldstart.js +2 -1
- package/dist/config.js +7 -7
- package/dist/deps.js +124 -0
- package/dist/detect.js +511 -0
- package/dist/dream.js +422 -0
- package/dist/duration.js +3 -3
- package/dist/gate.js +11 -5
- package/dist/live.js +255 -0
- package/dist/livequota.js +27 -4
- package/dist/macapp.js +25 -2
- package/dist/pacing.js +5 -0
- package/dist/permissions.js +106 -0
- package/dist/picture.js +13 -6
- package/dist/picturetype.js +208 -0
- package/dist/preflight.js +168 -0
- package/dist/premise.js +122 -0
- package/dist/projects.js +3 -2
- package/dist/refresh.js +290 -0
- package/dist/report.js +3 -0
- package/dist/review.js +66 -9
- package/dist/runner.js +56 -8
- package/dist/taste.js +34 -13
- package/dist/tokens.js +75 -0
- package/dist/tokenstore.js +61 -0
- package/dist/trace.js +284 -0
- package/dist/triggers.js +16 -5
- package/dist/usage.js +467 -0
- package/dist/vendor/codeburn/prices.js +45 -0
- package/dist/verify.js +24 -5
- package/dist/verifycard.js +146 -0
- package/dist/workspace.js +132 -18
- package/package.json +3 -2
package/dist/board.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
// The board (spec §5.3): cards in columns, stored in ~/.chompyy/board.json.
|
|
2
|
-
import {
|
|
2
|
+
import { mkdirSync } from 'node:fs';
|
|
3
|
+
import { formatTokens } from './tokens.js';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { appendJsonl, chompyyHome, homePath, readJson, writeJson } from './home.js';
|
|
3
6
|
export const COLUMNS = ['suggested', 'later', 'approved', 'running', 'review', 'done'];
|
|
4
7
|
export const COLUMN_LABEL = {
|
|
5
8
|
suggested: '💡 suggested',
|
|
@@ -38,7 +41,28 @@ export function titleFrom(idea) {
|
|
|
38
41
|
const first = idea.trim().split('\n')[0] ?? '';
|
|
39
42
|
return first.length > 60 ? first.slice(0, 57).trimEnd() + '…' : first;
|
|
40
43
|
}
|
|
41
|
-
|
|
44
|
+
/** Where cards with no branch (or made before workspaces existed) are grouped. */
|
|
45
|
+
export const UNSORTED = 'unsorted';
|
|
46
|
+
/** The card's workspace; old cards and cards made outside a git branch are `unsorted`. */
|
|
47
|
+
export function workspaceOf(card) {
|
|
48
|
+
return card.workspace?.trim() || UNSORTED;
|
|
49
|
+
}
|
|
50
|
+
/** A workspace name as one safe folder name: "feat/login" -> "feat-login"; nothing that could climb out. */
|
|
51
|
+
export function workspaceFolder(workspace) {
|
|
52
|
+
const safe = workspace.trim().replace(/[^A-Za-z0-9._-]+/g, '-').replace(/^[.-]+|-+$/g, '');
|
|
53
|
+
return safe || UNSORTED;
|
|
54
|
+
}
|
|
55
|
+
/** The card's own folder, `<store>/<workspace>/<card-id>/` (store = ~/.chompyy/cards). Not created here. */
|
|
56
|
+
export function cardDir(card, store = join(chompyyHome(), 'cards')) {
|
|
57
|
+
return join(store, workspaceFolder(workspaceOf(card)), workspaceFolder(card.id));
|
|
58
|
+
}
|
|
59
|
+
/** Like cardDir, and makes sure the folder exists. */
|
|
60
|
+
export function ensureCardDir(card) {
|
|
61
|
+
const dir = cardDir(card);
|
|
62
|
+
mkdirSync(dir, { recursive: true });
|
|
63
|
+
return dir;
|
|
64
|
+
}
|
|
65
|
+
export function addCard(board, idea, cwd, now, column = 'later', workspace) {
|
|
42
66
|
const text = idea.trim();
|
|
43
67
|
if (!text)
|
|
44
68
|
throw new Error('The idea is empty.');
|
|
@@ -48,6 +72,7 @@ export function addCard(board, idea, cwd, now, column = 'later') {
|
|
|
48
72
|
title: titleFrom(text),
|
|
49
73
|
idea: text,
|
|
50
74
|
cwd,
|
|
75
|
+
workspace: workspace?.trim() || UNSORTED,
|
|
51
76
|
column,
|
|
52
77
|
blueprint: null,
|
|
53
78
|
createdAt: at,
|
|
@@ -104,6 +129,64 @@ export function expireSuggested(board, now, days) {
|
|
|
104
129
|
export function cardsIn(board, column) {
|
|
105
130
|
return board.cards.filter((c) => c.column === column);
|
|
106
131
|
}
|
|
132
|
+
/** "14:05" in local time, from Unix seconds. */
|
|
133
|
+
function clock(unixSec) {
|
|
134
|
+
return new Date(unixSec * 1000).toTimeString().slice(0, 5);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Why drafting must wait, or null if it can go ahead. A running 5-hour window with 0% left means a draft
|
|
138
|
+
* would only fail on the usage limit, so the card waits instead of looking stuck.
|
|
139
|
+
*/
|
|
140
|
+
export function quotaWaitReason(five) {
|
|
141
|
+
if (!five.known || five.leftPct > 0)
|
|
142
|
+
return null;
|
|
143
|
+
return `waiting for quota: the 5-hour window is used up, drafts after it resets at ${clock(five.resetsAt)}`;
|
|
144
|
+
}
|
|
145
|
+
/** A parked card with no blueprint that should be drafted now (not already drafting, not told to wait). */
|
|
146
|
+
function needsDraft(c, now) {
|
|
147
|
+
const stale = now.getTime() - 3 * 60_000;
|
|
148
|
+
return ((c.column === 'later' || c.column === 'suggested') &&
|
|
149
|
+
!c.blueprint && !c.blueprintError && !c.noAutoDraft &&
|
|
150
|
+
(!c.draftingAt || Date.parse(c.draftingAt) < stale) &&
|
|
151
|
+
(!c.blueprintWaitUntil || Date.parse(c.blueprintWaitUntil) <= now.getTime()));
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Claim the cards whose blueprint should be drafted now: marks them drafting and returns their ids.
|
|
155
|
+
* With `waiting` set (no quota left), nothing is drafted: the cards get the reason instead and stay due,
|
|
156
|
+
* so a later pass drafts them once quota returns.
|
|
157
|
+
*/
|
|
158
|
+
export function claimDrafts(board, now, waiting) {
|
|
159
|
+
const due = board.cards.filter((c) => needsDraft(c, now));
|
|
160
|
+
if (waiting) {
|
|
161
|
+
for (const c of due)
|
|
162
|
+
c.blueprintWaiting = waiting;
|
|
163
|
+
return [];
|
|
164
|
+
}
|
|
165
|
+
for (const c of due) {
|
|
166
|
+
c.draftingAt = now.toISOString();
|
|
167
|
+
delete c.blueprintWaiting;
|
|
168
|
+
delete c.blueprintWaitUntil;
|
|
169
|
+
}
|
|
170
|
+
return due.map((c) => c.id);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Record a failed draft. A usage-limit failure isn't the card's fault, so it gets no blueprintError (which
|
|
174
|
+
* would stop retries): it waits and is retried after `retryAt`.
|
|
175
|
+
*/
|
|
176
|
+
export function noteDraftFailure(board, id, message, usageLimit, retryAt) {
|
|
177
|
+
const c = getCard(board, id);
|
|
178
|
+
delete c.draftingAt;
|
|
179
|
+
if (usageLimit) {
|
|
180
|
+
delete c.blueprintError;
|
|
181
|
+
c.blueprintWaiting = `waiting for quota: the usage limit was hit, retries after ${clock(retryAt.getTime() / 1000)}`;
|
|
182
|
+
c.blueprintWaitUntil = retryAt.toISOString();
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
c.blueprintError = message;
|
|
186
|
+
delete c.blueprintWaiting;
|
|
187
|
+
delete c.blueprintWaitUntil;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
107
190
|
/** Approved cards in the order they were approved: the away queue. */
|
|
108
191
|
/**
|
|
109
192
|
* Cards stuck in running whose away run is gone (it crashed or was stopped) go to review as an error, with
|
|
@@ -140,7 +223,7 @@ function shortPath(p) {
|
|
|
140
223
|
function cardLine(c) {
|
|
141
224
|
const marks = [];
|
|
142
225
|
if (c.column === 'later' || c.column === 'suggested') {
|
|
143
|
-
marks.push(c.blueprint ? 'blueprint ✓' : c.blueprintError ? 'blueprint failed' : 'no blueprint');
|
|
226
|
+
marks.push(c.blueprint ? 'blueprint ✓' : c.blueprintError ? 'blueprint failed' : c.blueprintWaiting ? 'waiting for quota' : 'no blueprint');
|
|
144
227
|
}
|
|
145
228
|
if (c.run)
|
|
146
229
|
marks.push(c.run.status);
|
|
@@ -149,30 +232,45 @@ function cardLine(c) {
|
|
|
149
232
|
const tail = marks.length ? ` [${marks.join(' · ')}]` : '';
|
|
150
233
|
return ` #${c.id.padEnd(3)} ${c.title}${tail} ${shortPath(c.cwd)}`;
|
|
151
234
|
}
|
|
235
|
+
/** Workspace names in the order they should be listed: named ones A-Z, `unsorted` last. */
|
|
236
|
+
export function workspacesOf(cards) {
|
|
237
|
+
const names = [...new Set(cards.map(workspaceOf))];
|
|
238
|
+
return names.sort((a, b) => (a === UNSORTED ? 1 : b === UNSORTED ? -1 : a.localeCompare(b)));
|
|
239
|
+
}
|
|
240
|
+
/** The board, one header per workspace (branch), and the columns inside each. */
|
|
152
241
|
export function formatBoard(board, columns = COLUMNS) {
|
|
153
242
|
if (board.cards.length === 0)
|
|
154
243
|
return 'The board is empty. Park an idea with `chompyy later "<idea>"`.';
|
|
244
|
+
const shown = board.cards.filter((c) => columns.includes(c.column));
|
|
155
245
|
const out = [];
|
|
156
|
-
for (const
|
|
157
|
-
const
|
|
158
|
-
if (
|
|
159
|
-
|
|
160
|
-
out.push(
|
|
161
|
-
for (const
|
|
162
|
-
|
|
246
|
+
for (const ws of workspacesOf(shown)) {
|
|
247
|
+
const mine = shown.filter((c) => workspaceOf(c) === ws);
|
|
248
|
+
if (out.length)
|
|
249
|
+
out.push('');
|
|
250
|
+
out.push(`[${ws}] (${mine.length})`);
|
|
251
|
+
for (const col of columns) {
|
|
252
|
+
const cards = mine.filter((c) => c.column === col);
|
|
253
|
+
if (cards.length === 0)
|
|
254
|
+
continue;
|
|
255
|
+
out.push(`${COLUMN_LABEL[col]} (${cards.length})`);
|
|
256
|
+
for (const c of cards)
|
|
257
|
+
out.push(cardLine(c));
|
|
258
|
+
}
|
|
163
259
|
}
|
|
164
260
|
return out.length ? out.join('\n') : `No cards in ${columns.join(', ')}.`;
|
|
165
261
|
}
|
|
166
262
|
export function formatCard(c) {
|
|
167
263
|
const lines = [
|
|
168
264
|
`#${c.id} ${c.title}`,
|
|
169
|
-
`column: ${c.column} · cwd: ${shortPath(c.cwd)} · created ${c.createdAt}`,
|
|
265
|
+
`column: ${c.column} · workspace: ${workspaceOf(c)} · cwd: ${shortPath(c.cwd)} · created ${c.createdAt}`,
|
|
170
266
|
];
|
|
171
267
|
if (c.idea !== c.title)
|
|
172
268
|
lines.push('', c.idea);
|
|
173
|
-
lines.push('', c.blueprint ?? (c.blueprintError ? `(blueprint failed: ${c.blueprintError})` : '(no blueprint yet)'));
|
|
269
|
+
lines.push('', c.blueprint ?? (c.blueprintError ? `(blueprint failed: ${c.blueprintError})` : c.blueprintWaiting ? `(no blueprint yet: ${c.blueprintWaiting})` : '(no blueprint yet)'));
|
|
174
270
|
if (c.run) {
|
|
175
271
|
lines.push('', `last run: ${c.run.status} · ${c.run.workdir}${c.run.branch ? ` · branch ${c.run.branch}` : ''}`);
|
|
272
|
+
if (c.run.tokens)
|
|
273
|
+
lines.push(`used: ${formatTokens(c.run.tokens)}`);
|
|
176
274
|
if (c.run.summary)
|
|
177
275
|
lines.push('', 'what the agent said:', ...c.run.summary.split('\n').map((l) => ` ${l}`));
|
|
178
276
|
}
|
package/dist/catalog.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// The failure catalog (research/away-readiness.md, step 1): every known way the away box blocks real work,
|
|
2
|
+
// as a signature in the output → a cause in plain words → the kind of fix. Preflight only consults it after
|
|
3
|
+
// proving the failure is the box's (the check passes outside the box on the same code); it never decides alone.
|
|
4
|
+
// A new kind of failure gets an entry here and a scenario in the tests, never a one-off patch.
|
|
5
|
+
export const CATALOG = [
|
|
6
|
+
{
|
|
7
|
+
id: 'nested-sandbox',
|
|
8
|
+
title: 'The tool tries to start its own sandbox',
|
|
9
|
+
match: /sandbox_apply|sandbox-exec: .*Operation not permitted|unable to (?:create|apply) sandbox|failed to (?:create|apply) (?:the )?sandbox/i,
|
|
10
|
+
cause: "macOS doesn't allow a sandbox inside a sandbox; tools like SwiftPM sandbox their own build steps.",
|
|
11
|
+
fix: 'auto',
|
|
12
|
+
remedy: 'Turn the tool\'s own sandbox off (the away box already sandboxes it): Chompyy runs `swift build --disable-sandbox` with its caches inside the box.',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
id: 'tool-cache-outside',
|
|
16
|
+
title: 'The tool writes its cache outside the project',
|
|
17
|
+
match: /org\.swift\.swiftpm|ModuleCache|clang[\\/]ModuleCache|\.swiftpm[\\/]|go-build|Library[\\/]Caches|is not accessible|\.cache[\\/].*(?:EACCES|EPERM|denied)/i,
|
|
18
|
+
cause: 'Build tools keep caches in your home folder (~/Library/Caches, ~/.cache), which the box can\'t write.',
|
|
19
|
+
fix: 'auto',
|
|
20
|
+
remedy: 'Chompyy points the tool\'s caches at a folder inside the box.',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: 'writes-home',
|
|
24
|
+
title: 'A test writes to your home folder',
|
|
25
|
+
match: /(?:EPERM|EACCES|Operation not permitted|permission denied)[^\n]*(?:\/Users\/[^/\s]+\/(?!Library\/Caches)|\$HOME|homedir)|mkdtemp[^\n]*\/Users\//i,
|
|
26
|
+
cause: 'The test creates files directly in your home folder; the box only allows writes in the project and temp folders.',
|
|
27
|
+
fix: 'repo',
|
|
28
|
+
remedy: 'Make the test use a temp folder (`os.tmpdir()`), which works everywhere and leaves nothing behind.',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: 'temp-outside',
|
|
32
|
+
title: "The tool can't save through the system temp folder",
|
|
33
|
+
match: /You don.t have permission to save the file|error: permissionDenied/i,
|
|
34
|
+
cause: 'macOS tools save files safely by writing a temp copy in your per-user temp folder (/private/var/folders/…) first; a box that blocks it breaks the save (swift build, 2026-11-18).',
|
|
35
|
+
fix: 'auto',
|
|
36
|
+
remedy: "Every box allows the same temp folders (boxTempDirs): the agent's sandbox and Chompyy's own check.",
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: 'runner-reply-timeout',
|
|
40
|
+
title: 'The test runner timed out talking to its worker',
|
|
41
|
+
match: /Timeout calling "?on\w+"?/i,
|
|
42
|
+
cause: 'Tests that block the worker (synchronous git or shell calls) for over 60 s in one file starve Vitest\'s reply channel; every test passes but the run fails.',
|
|
43
|
+
fix: 'repo',
|
|
44
|
+
remedy: 'Give the worker a pause after each test (a setup file with `afterEach(() => new Promise((r) => setImmediate(r)))`), or make the slow calls async.',
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
id: 'network',
|
|
48
|
+
title: 'It needs the network',
|
|
49
|
+
match: /ENOTFOUND|EAI_AGAIN|getaddrinfo|Could not resolve host|network is unreachable|ECONNREFUSED|Failed to fetch|unable to access 'https?:/i,
|
|
50
|
+
cause: 'The box has no network for shell commands (package downloads, API calls).',
|
|
51
|
+
fix: 'permission',
|
|
52
|
+
remedy: 'Install dependencies before the box closes (Chompyy\'s setup step), or allow the domain on the blueprint.',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: 'missing-deps',
|
|
56
|
+
title: 'Dependencies are missing',
|
|
57
|
+
match: /Cannot find module|ERR_MODULE_NOT_FOUND|command not found: (?:vitest|jest|tsc|eslint)|(?:vitest|jest|tsc|eslint): (?:command )?not found|No module named/i,
|
|
58
|
+
cause: 'A fresh copy of the repo has no installed packages, and the box can\'t download them.',
|
|
59
|
+
fix: 'auto',
|
|
60
|
+
remedy: 'Chompyy clones your installed packages into the copy (instant, no download).',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
id: 'needs-approval',
|
|
64
|
+
title: 'It needed an approval nobody could give',
|
|
65
|
+
match: /no approval surface|requires approval|permission request denied automatically/i,
|
|
66
|
+
cause: 'Away runs are unattended, so anything that asks for approval is refused.',
|
|
67
|
+
fix: 'permission',
|
|
68
|
+
remedy: 'Chompyy lists it on the blueprint so you can allow it when you approve the card.',
|
|
69
|
+
},
|
|
70
|
+
];
|
|
71
|
+
/** Which known box failures this output shows, most specific first, each with the line that matched. */
|
|
72
|
+
export function diagnose(output) {
|
|
73
|
+
const lines = output.split('\n');
|
|
74
|
+
const found = [];
|
|
75
|
+
for (const entry of CATALOG) {
|
|
76
|
+
const line = lines.find((l) => entry.match.test(l));
|
|
77
|
+
if (line)
|
|
78
|
+
found.push({ entry, evidence: line.trim().slice(0, 240) });
|
|
79
|
+
}
|
|
80
|
+
return found;
|
|
81
|
+
}
|