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/away.js
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
// Away run (spec §5.2, §5.5, §5.6): approved cards, one at a time, headless, inside the window.
|
|
2
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
-
import { awayQueue, loadBoard, recoverRunning, updateBoard, getCard } from './board.js';
|
|
4
|
+
import { awayQueue, ensureCardDir, loadBoard, recoverRunning, updateBoard, getCard } from './board.js';
|
|
5
5
|
import { formatDuration } from './duration.js';
|
|
6
6
|
import { budgetGate } from './gate.js';
|
|
7
7
|
import { homePath } from './home.js';
|
|
8
|
+
import { windowView } from './quota.js';
|
|
9
|
+
import { recordRun, usedBetween } from './costs.js';
|
|
10
|
+
import { applyPermissions } from './permissions.js';
|
|
11
|
+
import { tasteForPrompt } from './taste.js';
|
|
12
|
+
import { boxTempDirs } from './verify.js';
|
|
13
|
+
import { formatTokens } from './tokens.js';
|
|
8
14
|
/** Don't start a card with less than this much time left in the away run. */
|
|
9
15
|
export const MIN_CARD_MS = 2 * 60_000;
|
|
16
|
+
/** After a 5-hour reset, wait this much longer before carrying on (the new window needs a moment to show up). */
|
|
17
|
+
export const RESET_WAIT_MARGIN_MS = 2 * 60_000;
|
|
10
18
|
export function safetyRules(workdir) {
|
|
11
19
|
return `You are running unattended while the user is away. Nobody can answer questions. Rules:
|
|
12
20
|
1. Work only inside this directory: ${workdir}. Don't read or change files outside it.
|
|
@@ -14,18 +22,19 @@ export function safetyRules(workdir) {
|
|
|
14
22
|
no publishing packages, no purchases, no changes to remote services.
|
|
15
23
|
3. If you need a decision only the user can make, stop and write the question(s) to QUESTIONS.md in this
|
|
16
24
|
directory, with the options you see and your recommendation. Don't guess on anything irreversible.
|
|
17
|
-
4. Stay inside the blueprint's scope.
|
|
18
|
-
|
|
19
|
-
|
|
25
|
+
4. Stay inside the blueprint's scope. Don't commit: leave your changes as files in this directory. Chompyy
|
|
26
|
+
commits them to this folder's branch when you finish (the branch is how the user reviews and undoes it), and
|
|
27
|
+
the repo's .git is read-only to you. git status, git diff and git log work.
|
|
20
28
|
5. Check your work the way the blueprint says (run the tests if there are any). Shell commands run in a
|
|
21
|
-
sandbox, so local commands like tests and scripts are fine.
|
|
29
|
+
sandbox, so local commands like tests and scripts are fine. The sandbox has no network: don't install or
|
|
30
|
+
download anything (no npm install/ci, pip install, brew, curl). Dependencies the repo already has installed
|
|
31
|
+
are in place. If a check can't run without a download, don't retry it: say so in the CHECKS line.
|
|
22
32
|
6. End with a short summary: what you made, where it is, and how to check it. The very last line must be
|
|
23
33
|
exactly one of:
|
|
24
34
|
CHECKS: passed — <what you ran>
|
|
25
35
|
CHECKS: failed — <what fails, and whether it failed before your change>
|
|
26
36
|
CHECKS: not run — <why you couldn't check>`;
|
|
27
37
|
}
|
|
28
|
-
/** Claude Code sandbox settings for an away run: writes only in the card's folder (+ its repo's .git), no network. */
|
|
29
38
|
/**
|
|
30
39
|
* Build tools keep caches in your home folder (Go in ~/Library/Caches/go-build, npm in ~/.npm), which the
|
|
31
40
|
* sandbox blocks. Point them at one Chompyy cache folder the sandbox allows, so tests and builds work.
|
|
@@ -38,15 +47,21 @@ export function cacheEnv(dir) {
|
|
|
38
47
|
npm_config_cache: `${dir}/npm`,
|
|
39
48
|
PIP_CACHE_DIR: `${dir}/pip`,
|
|
40
49
|
XDG_CACHE_HOME: dir,
|
|
50
|
+
CLANG_MODULE_CACHE_PATH: `${dir}/clang-module-cache`,
|
|
41
51
|
};
|
|
42
52
|
}
|
|
43
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Claude Code sandbox settings for an away run: writes only in the card's folder, the tool cache and temp folders;
|
|
55
|
+
* no network. Not the repo's .git: from there a hook or a config line (core.fsmonitor, core.hooksPath) would run
|
|
56
|
+
* outside the sandbox the next time git runs in your checkout, keep included (#24). Chompyy commits instead.
|
|
57
|
+
*/
|
|
58
|
+
export function sandboxSettings(_ws, allowedDomains, cacheDir, denyRead = []) {
|
|
44
59
|
return {
|
|
45
60
|
sandbox: {
|
|
46
61
|
enabled: true,
|
|
47
62
|
failIfUnavailable: true, // refuse to run rather than run unprotected
|
|
48
63
|
allowUnsandboxedCommands: false, // no retrying outside the sandbox
|
|
49
|
-
filesystem: { allowWrite: [...(
|
|
64
|
+
filesystem: { allowWrite: [...(cacheDir ? [cacheDir] : []), ...boxTempDirs()], ...(denyRead.length ? { denyRead } : {}) },
|
|
50
65
|
network: { allowedDomains },
|
|
51
66
|
// Commands are confined by the sandbox, so local ones (tests, scripts) run without a prompt.
|
|
52
67
|
// The deny list still blocks outward commands (push, publish, curl, …).
|
|
@@ -54,9 +69,39 @@ export function sandboxSettings(ws, allowedDomains, cacheDir) {
|
|
|
54
69
|
},
|
|
55
70
|
};
|
|
56
71
|
}
|
|
57
|
-
|
|
72
|
+
/** Web tools: they don't go through the sandbox's network block, so away runs only get them when you turn on awayWeb. */
|
|
73
|
+
const WEB_TOOLS = new Set(['WebSearch', 'WebFetch']);
|
|
74
|
+
/** Read, Glob and Grep with no path open every file on the Mac; without them, the file tools read the card's folder only. */
|
|
75
|
+
const READ_ANYWHERE = new Set(['Read', 'Glob', 'Grep']);
|
|
76
|
+
/**
|
|
77
|
+
* The tools an unattended run may use without asking (#24). A run tricked by text in the repo could otherwise read
|
|
78
|
+
* files outside its folder and send them out in a WebFetch URL. Also applied to an older config.json that still
|
|
79
|
+
* lists them.
|
|
80
|
+
*/
|
|
81
|
+
export function awayTools(config, extra = []) {
|
|
82
|
+
const tools = [...config.allowedTools, ...extra].filter((t) => !READ_ANYWHERE.has(t) && !WEB_TOOLS.has(t));
|
|
83
|
+
return config.awayWeb ? [...tools, ...WEB_TOOLS] : tools;
|
|
84
|
+
}
|
|
85
|
+
/** Read rules for the file tools: the sandbox's denyRead only covers shell commands. */
|
|
86
|
+
export function denyReadRules(paths) {
|
|
87
|
+
return paths.flatMap((p) => [`Read(${p})`, `Read(${p}/**)`]);
|
|
88
|
+
}
|
|
89
|
+
export function taskPrompt(card, workdir, taste = '', checks = []) {
|
|
58
90
|
return `${safetyRules(workdir)}
|
|
91
|
+
${checks.length ? `
|
|
92
|
+
# How to check this repo (Chompyy ran these on main in this same sandbox: they pass here)
|
|
59
93
|
|
|
94
|
+
${checks.map((c) => `- in ${c.dir || 'the top folder'}: \`${c.label}\``).join('\n')}
|
|
95
|
+
|
|
96
|
+
Run these, exactly as written. If one fails after your change, it's your change.
|
|
97
|
+
After you finish, Chompyy runs them again itself and compares the result with main. So CHECKS: failed means
|
|
98
|
+
your change broke something. If a check can't run at all (a permission or sandbox error, a missing download),
|
|
99
|
+
that is not your change: write CHECKS: not run, with the error.
|
|
100
|
+
` : ''}${taste ? `
|
|
101
|
+
# How this user likes work done (their taste.md; follow it unless the blueprint says otherwise)
|
|
102
|
+
|
|
103
|
+
${taste}
|
|
104
|
+
` : ''}
|
|
60
105
|
# Task #${card.id}: ${card.title}
|
|
61
106
|
|
|
62
107
|
Original idea: ${card.idea}
|
|
@@ -93,14 +138,17 @@ function firstLines(text, n = 5) {
|
|
|
93
138
|
function stamp(ms) {
|
|
94
139
|
return new Date(ms).toISOString().replace(/[:.]/g, '-');
|
|
95
140
|
}
|
|
141
|
+
/** When quota was last read after a card (module state: one away run per process). */
|
|
142
|
+
let lastRefreshMs = -Infinity;
|
|
96
143
|
export async function away(durationMs, deps, opts = {}) {
|
|
97
144
|
const { config, out } = deps;
|
|
98
145
|
const start = deps.now();
|
|
99
146
|
const deadline = start + durationMs;
|
|
147
|
+
lastRefreshMs = -Infinity;
|
|
100
148
|
if (!opts.dryRun) {
|
|
101
|
-
const recovered = updateBoard((b) => recoverRunning(b, new Date(deps.now())));
|
|
149
|
+
const recovered = updateBoard((b) => recoverRunning(b, new Date(deps.now()), deps.plan));
|
|
102
150
|
if (recovered.length)
|
|
103
|
-
out(`
|
|
151
|
+
out(`Moved to review after an interrupted run: ${recovered.map((id) => `#${id}`).join(', ')}`);
|
|
104
152
|
}
|
|
105
153
|
const queue = awayQueue(loadBoard());
|
|
106
154
|
const summary = { ran: [], skipped: [], stoppedBecause: null };
|
|
@@ -115,9 +163,28 @@ export async function away(durationMs, deps, opts = {}) {
|
|
|
115
163
|
summary.stoppedBecause = 'time is up';
|
|
116
164
|
break;
|
|
117
165
|
}
|
|
118
|
-
|
|
166
|
+
// The previous card already read quota when it finished; don't ask twice in a row.
|
|
167
|
+
if (!opts.dryRun && deps.refreshQuota && deps.now() - lastRefreshMs > 60_000)
|
|
119
168
|
await deps.refreshQuota();
|
|
120
|
-
|
|
169
|
+
let gate = budgetGate(deps.snapshot(), config, new Date(deps.now()));
|
|
170
|
+
// The 5-hour window ran low but the run has time left (going to sleep): wait for the reset and carry on,
|
|
171
|
+
// instead of stopping at 23:40 and leaving the night unused. Weekly limits still stop it.
|
|
172
|
+
while (!gate.ok && !opts.force && !opts.dryRun && deps.wait) {
|
|
173
|
+
const five = windowView(deps.snapshot()?.fiveHour, new Date(deps.now()));
|
|
174
|
+
const onlyFiveHour = gate.reasons.every((r) => r.startsWith('5h window'));
|
|
175
|
+
if (!onlyFiveHour || !five.known)
|
|
176
|
+
break;
|
|
177
|
+
const wakeAt = five.resetsAt * 1000 + RESET_WAIT_MARGIN_MS;
|
|
178
|
+
if (wakeAt + MIN_CARD_MS > deadline)
|
|
179
|
+
break;
|
|
180
|
+
out(` ⏸ ${gate.reasons.join('; ')}. Waiting for the 5-hour window to reset at ${new Date(five.resetsAt * 1000).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}, then carrying on.`);
|
|
181
|
+
await deps.wait(wakeAt - deps.now());
|
|
182
|
+
if (deps.refreshQuota) {
|
|
183
|
+
await deps.refreshQuota().catch(() => { });
|
|
184
|
+
lastRefreshMs = deps.now();
|
|
185
|
+
}
|
|
186
|
+
gate = budgetGate(deps.snapshot(), config, new Date(deps.now()));
|
|
187
|
+
}
|
|
121
188
|
if (!gate.ok && !opts.force) {
|
|
122
189
|
summary.stoppedBecause = gate.reasons.join('; ');
|
|
123
190
|
break;
|
|
@@ -129,7 +196,8 @@ export async function away(durationMs, deps, opts = {}) {
|
|
|
129
196
|
summary.ran.push(queued.id);
|
|
130
197
|
continue;
|
|
131
198
|
}
|
|
132
|
-
|
|
199
|
+
const timeoutMs = Math.min(config.cardTimeoutMin * 60_000, remaining);
|
|
200
|
+
summary.ran.push(deps.isolate ? await runIsolated(queued.id, timeoutMs, deps, opts.trigger) : await runCard(queued.id, timeoutMs, deps, opts.trigger));
|
|
133
201
|
}
|
|
134
202
|
const notRun = queue.map((c) => c.id).filter((id) => !summary.ran.includes(id));
|
|
135
203
|
summary.skipped = notRun;
|
|
@@ -143,9 +211,39 @@ export async function away(durationMs, deps, opts = {}) {
|
|
|
143
211
|
out(`Done. ${summary.ran.length} card(s) in review. See \`chompyy report\`.`);
|
|
144
212
|
return summary;
|
|
145
213
|
}
|
|
146
|
-
|
|
214
|
+
/** Where a card's agent pid is kept while it runs, so the supervisor can stop it if the worker dies. */
|
|
215
|
+
export const agentPidPath = (id) => homePath('runs', id, 'agent.pid');
|
|
216
|
+
/** Run a card in a worker process; if the worker dies mid-card, stop its agent and put the card in review. */
|
|
217
|
+
async function runIsolated(id, timeoutMs, deps, trigger) {
|
|
218
|
+
let res;
|
|
219
|
+
try {
|
|
220
|
+
res = await deps.isolate(id, timeoutMs, trigger);
|
|
221
|
+
}
|
|
222
|
+
catch (err) {
|
|
223
|
+
res = { exitCode: null, stderr: String(err instanceof Error ? err.message : err) };
|
|
224
|
+
}
|
|
225
|
+
// An orphaned agent would keep working (and spending) alongside the next card.
|
|
226
|
+
const pid = Number(existsSync(agentPidPath(id)) ? readFileSync(agentPidPath(id), 'utf8') : NaN);
|
|
227
|
+
if (pid > 0) {
|
|
228
|
+
try {
|
|
229
|
+
process.kill(-pid, 'SIGTERM');
|
|
230
|
+
}
|
|
231
|
+
catch { }
|
|
232
|
+
}
|
|
233
|
+
rmSync(agentPidPath(id), { force: true });
|
|
234
|
+
if (getCard(loadBoard(), id).column !== 'running')
|
|
235
|
+
return id;
|
|
236
|
+
const how = res.signal ? `was killed (${res.signal})` : `exited with code ${res.exitCode}`;
|
|
237
|
+
const tail = res.stderr.trim().split('\n').filter((l) => !/^\s*\d+: 0x/.test(l)).slice(-3).join(' ').slice(0, 300);
|
|
238
|
+
const why = `Chompyy's worker for this card ${how} before it finished${tail ? `: ${tail}` : ''}.`;
|
|
239
|
+
updateBoard((b) => recoverRunning(b, new Date(deps.now()), deps.plan, why));
|
|
240
|
+
deps.out(` ⛔ #${id}: ${why} Moving on to the next card.`);
|
|
241
|
+
return id;
|
|
242
|
+
}
|
|
243
|
+
export async function runCard(id, timeoutMs, deps, trigger) {
|
|
147
244
|
const { config, out } = deps;
|
|
148
245
|
const startedMs = deps.now();
|
|
246
|
+
const quotaBefore = deps.snapshot();
|
|
149
247
|
const card = updateBoard((b) => {
|
|
150
248
|
const c = getCard(b, id);
|
|
151
249
|
c.column = 'running';
|
|
@@ -153,16 +251,27 @@ async function runCard(id, timeoutMs, deps) {
|
|
|
153
251
|
return { ...c };
|
|
154
252
|
});
|
|
155
253
|
out(`▶ #${card.id} ${card.title} (up to ${formatDuration(timeoutMs)})`);
|
|
156
|
-
|
|
254
|
+
// Run output lives in the card's folder, under its workspace: <store>/<workspace>/<id>/.
|
|
255
|
+
const logPath = join(ensureCardDir(card), `${stamp(startedMs)}.log`);
|
|
157
256
|
let ws = null;
|
|
158
257
|
let status;
|
|
159
258
|
let exitCode = null;
|
|
160
259
|
let summaryText = '';
|
|
161
260
|
let checks;
|
|
261
|
+
let verified;
|
|
262
|
+
let tokens;
|
|
162
263
|
let log = '';
|
|
163
264
|
try {
|
|
164
265
|
ws = deps.prepare(card);
|
|
165
|
-
|
|
266
|
+
if (ws.base)
|
|
267
|
+
out(` from ${ws.base.ref} @ ${ws.base.commit.slice(0, 7)}`);
|
|
268
|
+
for (const s of ws.setup ?? [])
|
|
269
|
+
if (s.source !== 'kept')
|
|
270
|
+
out(` deps in ${s.dir}: ${s.source}${s.note ? ` (${s.note})` : ''}`);
|
|
271
|
+
const granted = applyPermissions(card.permissions);
|
|
272
|
+
if (card.permissions?.length)
|
|
273
|
+
out(` allowed for this card: ${card.permissions.join(', ')}`);
|
|
274
|
+
const prompt = taskPrompt(card, ws.dir, (deps.taste ?? tasteForPrompt)(), deps.repoChecks?.(card) ?? []);
|
|
166
275
|
const cacheDir = homePath('cache', 'tools');
|
|
167
276
|
mkdirSync(cacheDir, { recursive: true });
|
|
168
277
|
const questionsPath = join(ws.dir, 'QUESTIONS.md');
|
|
@@ -175,24 +284,55 @@ async function runCard(id, timeoutMs, deps) {
|
|
|
175
284
|
maxTurns: config.maxTurns,
|
|
176
285
|
permissionMode: config.permissionMode,
|
|
177
286
|
permissionPrompts: config.permissionPrompts,
|
|
178
|
-
allowedTools: config.allowedTools,
|
|
179
|
-
disallowedTools: config.disallowedTools,
|
|
180
|
-
...(config.sandbox ? { settings: sandboxSettings(ws, config.sandboxAllowedDomains, cacheDir) } : {}),
|
|
287
|
+
allowedTools: awayTools(config, granted.allowedTools),
|
|
288
|
+
disallowedTools: [...config.disallowedTools, ...denyReadRules(config.denyReadPaths)],
|
|
289
|
+
...(config.sandbox ? { settings: sandboxSettings(ws, [...config.sandboxAllowedDomains, ...granted.domains], cacheDir, config.denyReadPaths) } : {}),
|
|
181
290
|
env: cacheEnv(cacheDir),
|
|
182
291
|
extraArgs: config.extraArgs,
|
|
292
|
+
...(config.loopRepeat > 0 ? { loopRepeat: config.loopRepeat } : {}),
|
|
293
|
+
...(config.idleTimeoutMin > 0 ? { idleTimeoutMs: config.idleTimeoutMin * 60_000 } : {}),
|
|
294
|
+
...(config.maxDenied > 0 ? { maxDenied: config.maxDenied } : {}),
|
|
295
|
+
onSpawn: (pid) => writeFileSync(agentPidPath(card.id), String(pid)),
|
|
296
|
+
// The whole stream (every tool call and result) goes to disk, never into memory: what to read when a run goes wrong.
|
|
297
|
+
rawLogPath: logPath.replace(/\.log$/, '.stream.jsonl'),
|
|
183
298
|
});
|
|
299
|
+
rmSync(agentPidPath(card.id), { force: true });
|
|
184
300
|
exitCode = result.exitCode;
|
|
301
|
+
tokens = result.tokens;
|
|
302
|
+
if (tokens)
|
|
303
|
+
out(` used ${formatTokens(tokens)}`);
|
|
304
|
+
if (result.needs) {
|
|
305
|
+
try {
|
|
306
|
+
deps.recordNeeds?.(card, result.needs);
|
|
307
|
+
}
|
|
308
|
+
catch { }
|
|
309
|
+
out(` blocked on: ${[...result.needs.commands, ...result.needs.hosts].join(', ')} (offered on the next blueprint here)`);
|
|
310
|
+
}
|
|
185
311
|
try {
|
|
186
312
|
if (deps.commitLeftovers?.(ws, card))
|
|
187
|
-
out(
|
|
313
|
+
out(" (Chompyy committed the agent's changes)");
|
|
188
314
|
}
|
|
189
315
|
catch (err) {
|
|
190
316
|
out(` couldn't commit leftover changes: ${err instanceof Error ? err.message : err}`);
|
|
191
317
|
}
|
|
192
318
|
const hasQuestions = existsSync(questionsPath) && readFileSync(questionsPath, 'utf8') !== questionsBefore;
|
|
193
|
-
status = result.timedOut ? 'timeout' : result.exitCode !== 0 ? 'failed' : hasQuestions ? 'questions' : 'ok';
|
|
319
|
+
status = result.stuck || result.stalled ? 'stuck' : result.timedOut ? 'timeout' : result.exitCode !== 0 ? 'failed' : hasQuestions ? 'questions' : 'ok';
|
|
320
|
+
if (result.stuck)
|
|
321
|
+
out(` ⛔ stopped: it was going in circles (${result.stuck})`);
|
|
322
|
+
if (result.stalled)
|
|
323
|
+
out(` ⛔ stopped: ${result.stalled}`);
|
|
194
324
|
checks = parseChecks(result.output);
|
|
195
|
-
|
|
325
|
+
if (deps.verify && ws.kind === 'worktree' && !result.stuck && !result.timedOut && result.exitCode === 0) {
|
|
326
|
+
out(' checking it independently (running the repo\'s tests, sandboxed)…');
|
|
327
|
+
verified = await deps.verify(ws, card).catch(() => undefined);
|
|
328
|
+
if (verified)
|
|
329
|
+
out(` ${verified.result === 'passed' ? '✓' : verified.result === 'failed' ? '✗' : '·'} ${verified.why}`);
|
|
330
|
+
}
|
|
331
|
+
summaryText = result.stuck
|
|
332
|
+
? `Stopped by Chompyy: it was going in circles (${result.stuck}).`
|
|
333
|
+
: result.stalled
|
|
334
|
+
? `Stopped by Chompyy: ${result.stalled} (a hung command or a stalled agent), so the next card could run.`
|
|
335
|
+
: firstLines(result.output.replace(/^\s*CHECKS:.*$/gim, '')) || firstLines(result.stderr);
|
|
196
336
|
log = `# prompt\n\n${prompt}\n\n# output\n\n${result.output}\n\n# stderr\n\n${result.stderr}\n`;
|
|
197
337
|
}
|
|
198
338
|
catch (err) {
|
|
@@ -201,6 +341,16 @@ async function runCard(id, timeoutMs, deps) {
|
|
|
201
341
|
log = `# error\n\n${summaryText}\n`;
|
|
202
342
|
}
|
|
203
343
|
const finishedMs = deps.now();
|
|
344
|
+
// What the card cost, in points of your windows: quota after minus before (an upper bound if you were busy too).
|
|
345
|
+
if (deps.refreshQuota) {
|
|
346
|
+
await deps.refreshQuota().catch(() => { });
|
|
347
|
+
lastRefreshMs = deps.now();
|
|
348
|
+
}
|
|
349
|
+
const quotaAfter = deps.snapshot();
|
|
350
|
+
const cost = {
|
|
351
|
+
fiveHourPct: usedBetween(quotaBefore?.fiveHour, quotaAfter?.fiveHour),
|
|
352
|
+
weeklyPct: usedBetween(quotaBefore?.sevenDay, quotaAfter?.sevenDay),
|
|
353
|
+
};
|
|
204
354
|
const header = `card #${card.id} · ${status} · exit ${exitCode} · ${formatDuration(finishedMs - startedMs)}\nworkdir: ${ws?.dir ?? '-'}${ws?.branch ? `\nbranch: ${ws.branch}` : ''}\n\n`;
|
|
205
355
|
writeFileSync(logPath, header + log);
|
|
206
356
|
updateBoard((b) => {
|
|
@@ -216,10 +366,26 @@ async function runCard(id, timeoutMs, deps) {
|
|
|
216
366
|
exitCode,
|
|
217
367
|
workdir: ws?.dir ?? '',
|
|
218
368
|
...(ws?.branch ? { branch: ws.branch } : {}),
|
|
369
|
+
...(ws?.base ? { base: ws.base } : {}),
|
|
219
370
|
summary: summaryText,
|
|
220
371
|
...(checks ? { checks } : {}),
|
|
372
|
+
cost,
|
|
373
|
+
...(verified ? { verified } : {}),
|
|
374
|
+
...(tokens ? { tokens } : {}),
|
|
375
|
+
...(trigger ? { trigger } : {}),
|
|
221
376
|
};
|
|
222
377
|
});
|
|
223
|
-
|
|
378
|
+
recordRun({
|
|
379
|
+
at: new Date(finishedMs).toISOString(),
|
|
380
|
+
card: card.id,
|
|
381
|
+
title: card.title,
|
|
382
|
+
idea: card.idea,
|
|
383
|
+
cwd: card.cwd,
|
|
384
|
+
status,
|
|
385
|
+
durationMs: finishedMs - startedMs,
|
|
386
|
+
...cost,
|
|
387
|
+
...(tokens ? { tokens } : {}),
|
|
388
|
+
});
|
|
389
|
+
out(` → ${status} · ${formatDuration(finishedMs - startedMs)}${cost.fiveHourPct !== null ? ` · used ${cost.fiveHourPct}% of the 5h window` : ''} · log ${logPath}`);
|
|
224
390
|
return card.id;
|
|
225
391
|
}
|
package/dist/blueprint.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
// Blueprint (spec §5.4): the scope agreed before a card runs, drafted by a cheap model.
|
|
2
|
+
import { writeFileSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { ensureCardDir } from './board.js';
|
|
1
5
|
export const BLUEPRINT_SECTIONS = ['Goal', 'Scope', 'Out of scope', 'Shape', "How it's checked"];
|
|
6
|
+
/** Optional: what the run needs beyond the box, for the permission plan. */
|
|
7
|
+
export const OPTIONAL_SECTIONS = ['Needs'];
|
|
2
8
|
export function blueprintPrompt(card) {
|
|
3
9
|
return `You write short blueprints for tasks a coding agent will run unattended, with nobody to ask.
|
|
4
10
|
Turn the idea below into a blueprint. Reply with ONLY this Markdown, no preamble:
|
|
@@ -18,15 +24,23 @@ Turn the idea below into a blueprint. Reply with ONLY this Markdown, no preamble
|
|
|
18
24
|
## How it's checked
|
|
19
25
|
- <how someone can verify the result without the author: tests, files that exist, cited sources>
|
|
20
26
|
|
|
27
|
+
## Needs
|
|
28
|
+
- <ONLY if the run truly can't succeed inside the box; otherwise leave this whole section out>
|
|
29
|
+
- network: <domain>: <why, one line> (the shell needs to reach this domain, e.g. to download a file)
|
|
30
|
+
- command: <program>: <why, one line> (a program the run must use that needs approval)
|
|
31
|
+
|
|
21
32
|
Look at the working directory first (read-only) so the blueprint fits what is really there: its files,
|
|
22
33
|
languages, test command and tooling. Don't plan steps for tools the repo doesn't have.
|
|
34
|
+
If the plan depends on facts you're unsure of (an API, a library's usage, a format), you may check them with
|
|
35
|
+
WebSearch or WebFetch first. Keep research short: the blueprint, not the research, is the deliverable.
|
|
23
36
|
|
|
24
37
|
The run can only change files inside the working directory. Its shell has no network, but the agent CAN
|
|
25
38
|
read public web pages with its web tools (WebFetch, WebSearch), so reading docs or a linked page is fine.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
39
|
+
The repo's installed dependencies are already in the run's copy, so don't plan to install them.
|
|
40
|
+
If the idea needs the shell to reach a site or run a program needing approval, list it under Needs: the user
|
|
41
|
+
can allow it when approving. If it needs anything else outside the directory (global or user config, other
|
|
42
|
+
folders or repos, accounts, calling APIs), start Out of scope with "Can't run unattended: <why>" and plan only
|
|
43
|
+
what can be done inside the directory, such as a script or written steps the user can run themselves.
|
|
30
44
|
|
|
31
45
|
Keep it under 200 words. Pick the smallest useful version of the idea.
|
|
32
46
|
Never write "no commits" or "leave files untracked": the run always commits to the card's own branch (Chompyy
|
|
@@ -37,6 +51,12 @@ can make, say so in Out of scope and plan to write that question to QUESTIONS.md
|
|
|
37
51
|
Working directory: ${card.cwd}
|
|
38
52
|
Idea: ${card.idea}`;
|
|
39
53
|
}
|
|
54
|
+
/** Keep a copy of the card's blueprint in its folder (`<store>/<workspace>/<id>/blueprint.md`). Returns the path. */
|
|
55
|
+
export function writeBlueprintFile(card, text) {
|
|
56
|
+
const path = join(ensureCardDir(card), 'blueprint.md');
|
|
57
|
+
writeFileSync(path, text.trim() + '\n');
|
|
58
|
+
return path;
|
|
59
|
+
}
|
|
40
60
|
/** Strip chatter before the first heading; insist on the Goal heading. */
|
|
41
61
|
export function cleanBlueprint(output) {
|
|
42
62
|
const text = output.trim();
|
|
@@ -50,15 +70,90 @@ export async function draftBlueprint(card, runner, opts) {
|
|
|
50
70
|
prompt: blueprintPrompt(card),
|
|
51
71
|
cwd: opts.cwd,
|
|
52
72
|
model: opts.model,
|
|
53
|
-
|
|
54
|
-
|
|
73
|
+
// Research while drafting: the plan you approve should already be checked against the docs.
|
|
74
|
+
tools: 'Read,Glob,Grep,WebSearch,WebFetch',
|
|
75
|
+
// Headless runs refuse anything not allowed up front (nobody to approve), so allow the research tools.
|
|
76
|
+
allowedTools: ['Read', 'Glob', 'Grep', 'WebSearch', 'WebFetch'],
|
|
77
|
+
timeoutMs: opts.timeoutMs ?? 240_000,
|
|
55
78
|
});
|
|
56
79
|
if (result.timedOut)
|
|
57
80
|
throw new Error('Blueprint model timed out.');
|
|
81
|
+
// In -p mode Claude Code prints some failures (like the usage limit) on stdout, so fall back to it.
|
|
58
82
|
if (result.exitCode !== 0)
|
|
59
|
-
throw new Error(`claude exited with ${result.exitCode}: ${result.stderr.trim().slice(0, 300)}`);
|
|
83
|
+
throw new Error(`claude exited with ${result.exitCode}: ${(result.stderr.trim() || result.output.trim()).slice(0, 300)}`);
|
|
60
84
|
return cleanBlueprint(result.output);
|
|
61
85
|
}
|
|
86
|
+
/** Most words and characters a card title may have. */
|
|
87
|
+
export const TITLE_MAX_WORDS = 10;
|
|
88
|
+
export const TITLE_MAX_CHARS = 60;
|
|
89
|
+
export function titlePrompt(idea) {
|
|
90
|
+
return `Write a short title for this task card on a kanban board. Reply with ONLY the title: at most ${TITLE_MAX_WORDS} words,
|
|
91
|
+
no quotes, no ending period, no preamble. Say what the task is about, e.g. "Retitle parked cards with a model summary".
|
|
92
|
+
|
|
93
|
+
Task: ${idea}`;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The model's reply as a card title: first non-empty line, without quotes, bullets, a "Title:" label or an
|
|
97
|
+
* ending period, cut to 10 words and 60 characters. Empty when nothing usable is left.
|
|
98
|
+
*/
|
|
99
|
+
export function cleanTitle(output) {
|
|
100
|
+
const line = output.split('\n').map((l) => l.trim()).find((l) => l.length > 0) ?? '';
|
|
101
|
+
let t = line
|
|
102
|
+
.replace(/^([-*•#]+|\d+[.)])\s*/, '')
|
|
103
|
+
.replace(/^title\s*:\s*/i, '')
|
|
104
|
+
.replace(/^["'`*_]+|["'`*_]+$/g, '')
|
|
105
|
+
.replace(/[.。]+$/, '')
|
|
106
|
+
.replace(/\s+/g, ' ')
|
|
107
|
+
.trim();
|
|
108
|
+
t = t.split(' ').slice(0, TITLE_MAX_WORDS).join(' ');
|
|
109
|
+
if (t.length > TITLE_MAX_CHARS)
|
|
110
|
+
t = t.slice(0, TITLE_MAX_CHARS - 1).trimEnd() + '…';
|
|
111
|
+
return t;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* A short title for the card, written by the same cheap model as the blueprint (no tools, one short call).
|
|
115
|
+
* Never throws: if the call fails or the reply is unusable, the card keeps its current title.
|
|
116
|
+
*/
|
|
117
|
+
export async function draftTitle(card, runner, opts) {
|
|
118
|
+
try {
|
|
119
|
+
const result = await runner.run({ prompt: titlePrompt(card.idea), cwd: opts.cwd, model: opts.model, tools: '', timeoutMs: opts.timeoutMs ?? 60_000 });
|
|
120
|
+
if (result.exitCode !== 0 || result.timedOut)
|
|
121
|
+
return card.title;
|
|
122
|
+
return cleanTitle(result.output) || card.title;
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
return card.title;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/** A draft that started this long ago and never finished (its process died) counts as not drafting. */
|
|
129
|
+
const DRAFT_STALE_MS = 3 * 60_000;
|
|
130
|
+
/**
|
|
131
|
+
* Later cards "Draft all" should draft: no blueprint yet and not being drafted right now.
|
|
132
|
+
* Cards with a blueprint (edited ones too) are left alone; a card whose last draft failed is retried.
|
|
133
|
+
*/
|
|
134
|
+
export function laterToDraft(board, now = new Date()) {
|
|
135
|
+
return board.cards.filter((c) => c.column === 'later' &&
|
|
136
|
+
!c.blueprint?.trim() &&
|
|
137
|
+
(!c.draftingAt || Date.parse(c.draftingAt) < now.getTime() - DRAFT_STALE_MS));
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The plan for `chompyy blueprint --all-later`: which cards to draft, or why it drafts nothing.
|
|
141
|
+
* Same gate as background drafting: with no active 5-hour window a model call would start a new one.
|
|
142
|
+
*/
|
|
143
|
+
export function draftAllPlan(board, windowActive, now = new Date()) {
|
|
144
|
+
if (!windowActive)
|
|
145
|
+
return { ids: [], message: 'No active 5-hour window: drafting now would start one. Nothing drafted; try again while you are using Claude Code.' };
|
|
146
|
+
const ids = laterToDraft(board, now).map((c) => c.id);
|
|
147
|
+
return ids.length ? { ids } : { ids, message: 'Every later card already has a blueprint (or is being drafted).' };
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* True when a failed model call ran into the plan's usage limit (out of quota), e.g. Claude Code's
|
|
151
|
+
* "Claude AI usage limit reached|1763470800", "5-hour limit reached ∙ resets 3pm" or "You've hit your limit".
|
|
152
|
+
* Such a failure isn't the card's fault: it should wait for the reset, not be marked failed.
|
|
153
|
+
*/
|
|
154
|
+
export function isUsageLimit(message) {
|
|
155
|
+
return /usage limit reached|(5-hour|weekly|session|opus) limit reached|hit your (usage )?limit|limit reached\s*[∙·|]\s*resets/i.test(message);
|
|
156
|
+
}
|
|
62
157
|
/** Generic options when a card-specific list can't be made (e.g. no active window). */
|
|
63
158
|
export const GENERIC_FIVE_STAR = ['Closer to what I asked for', 'Shorter and simpler', 'More thorough', 'A different format'];
|
|
64
159
|
export function fiveStarPrompt(card) {
|