chompyy 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +252 -2
- package/THIRD_PARTY_NOTICES.md +59 -0
- package/dist/appstate.js +116 -0
- package/dist/away.js +314 -0
- package/dist/blueprint.js +91 -0
- package/dist/board.js +186 -0
- package/dist/claudesettings.js +23 -0
- package/dist/cli.js +861 -0
- package/dist/coldstart.js +207 -0
- package/dist/config.js +89 -0
- package/dist/costs.js +162 -0
- package/dist/duration.js +36 -0
- package/dist/gate.js +69 -0
- package/dist/history.js +308 -0
- package/dist/home.js +34 -0
- package/dist/livequota.js +92 -0
- package/dist/macapp.js +57 -0
- package/dist/pacing.js +189 -0
- package/dist/picture.js +117 -0
- package/dist/projects.js +114 -0
- package/dist/quota.js +153 -0
- package/dist/report.js +136 -0
- package/dist/review.js +173 -0
- package/dist/runner.js +357 -0
- package/dist/taste.js +507 -0
- package/dist/triggers.js +182 -0
- package/dist/vendor/codeburn/claude.js +255 -0
- package/dist/vendor/codeburn/security.js +260 -0
- package/dist/vendor/codeburn/types.js +1 -0
- package/dist/verify.js +131 -0
- package/dist/workspace.js +80 -0
- package/package.json +48 -4
- package/skills/away/SKILL.md +26 -0
- package/skills/eat-tokens/SKILL.md +18 -0
- package/skills/later/SKILL.md +20 -0
- package/skills/taste/SKILL.md +19 -0
- 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
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
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, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { awayQueue, loadBoard, recoverRunning, updateBoard, getCard } from './board.js';
|
|
5
|
+
import { formatDuration } from './duration.js';
|
|
6
|
+
import { budgetGate } from './gate.js';
|
|
7
|
+
import { homePath } from './home.js';
|
|
8
|
+
import { recordRun, usedBetween } from './costs.js';
|
|
9
|
+
import { tasteForPrompt } from './taste.js';
|
|
10
|
+
/** Don't start a card with less than this much time left in the away run. */
|
|
11
|
+
export const MIN_CARD_MS = 2 * 60_000;
|
|
12
|
+
export function safetyRules(workdir) {
|
|
13
|
+
return `You are running unattended while the user is away. Nobody can answer questions. Rules:
|
|
14
|
+
1. Work only inside this directory: ${workdir}. Don't read or change files outside it.
|
|
15
|
+
2. Nothing outward: no git push, merge, rebase or pull request; no sending email or messages, no posting,
|
|
16
|
+
no publishing packages, no purchases, no changes to remote services.
|
|
17
|
+
3. If you need a decision only the user can make, stop and write the question(s) to QUESTIONS.md in this
|
|
18
|
+
directory, with the options you see and your recommendation. Don't guess on anything irreversible.
|
|
19
|
+
4. Stay inside the blueprint's scope. If this is a git repo, commit your work to the current branch: that is
|
|
20
|
+
always allowed, even if the blueprint says otherwise, because the branch is how the user reviews and undoes it.
|
|
21
|
+
Don't commit QUESTIONS.md.
|
|
22
|
+
5. Check your work the way the blueprint says (run the tests if there are any). Shell commands run in a
|
|
23
|
+
sandbox, so local commands like tests and scripts are fine.
|
|
24
|
+
6. End with a short summary: what you made, where it is, and how to check it. The very last line must be
|
|
25
|
+
exactly one of:
|
|
26
|
+
CHECKS: passed — <what you ran>
|
|
27
|
+
CHECKS: failed — <what fails, and whether it failed before your change>
|
|
28
|
+
CHECKS: not run — <why you couldn't check>`;
|
|
29
|
+
}
|
|
30
|
+
/** Claude Code sandbox settings for an away run: writes only in the card's folder (+ its repo's .git), no network. */
|
|
31
|
+
/**
|
|
32
|
+
* Build tools keep caches in your home folder (Go in ~/Library/Caches/go-build, npm in ~/.npm), which the
|
|
33
|
+
* sandbox blocks. Point them at one Chompyy cache folder the sandbox allows, so tests and builds work.
|
|
34
|
+
*/
|
|
35
|
+
export function cacheEnv(dir) {
|
|
36
|
+
return {
|
|
37
|
+
GOCACHE: `${dir}/go-build`,
|
|
38
|
+
GOMODCACHE: `${dir}/go-mod`,
|
|
39
|
+
GOFLAGS: '-modcacherw',
|
|
40
|
+
npm_config_cache: `${dir}/npm`,
|
|
41
|
+
PIP_CACHE_DIR: `${dir}/pip`,
|
|
42
|
+
XDG_CACHE_HOME: dir,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export function sandboxSettings(ws, allowedDomains, cacheDir, denyRead = []) {
|
|
46
|
+
return {
|
|
47
|
+
sandbox: {
|
|
48
|
+
enabled: true,
|
|
49
|
+
failIfUnavailable: true, // refuse to run rather than run unprotected
|
|
50
|
+
allowUnsandboxedCommands: false, // no retrying outside the sandbox
|
|
51
|
+
filesystem: { allowWrite: [...(ws.gitDir ? [ws.gitDir] : []), ...(cacheDir ? [cacheDir] : [])], ...(denyRead.length ? { denyRead } : {}) },
|
|
52
|
+
network: { allowedDomains },
|
|
53
|
+
// Commands are confined by the sandbox, so local ones (tests, scripts) run without a prompt.
|
|
54
|
+
// The deny list still blocks outward commands (push, publish, curl, …).
|
|
55
|
+
autoAllowBashIfSandboxed: true,
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** Read rules for the file tools: the sandbox's denyRead only covers shell commands. */
|
|
60
|
+
export function denyReadRules(paths) {
|
|
61
|
+
return paths.flatMap((p) => [`Read(${p})`, `Read(${p}/**)`]);
|
|
62
|
+
}
|
|
63
|
+
export function taskPrompt(card, workdir, taste = '') {
|
|
64
|
+
return `${safetyRules(workdir)}
|
|
65
|
+
${taste ? `
|
|
66
|
+
# How this user likes work done (their taste.md; follow it unless the blueprint says otherwise)
|
|
67
|
+
|
|
68
|
+
${taste}
|
|
69
|
+
` : ''}
|
|
70
|
+
# Task #${card.id}: ${card.title}
|
|
71
|
+
|
|
72
|
+
Original idea: ${card.idea}
|
|
73
|
+
|
|
74
|
+
# Blueprint (agreed scope)
|
|
75
|
+
|
|
76
|
+
${card.blueprint ?? ''}
|
|
77
|
+
${card.answers?.length ? `
|
|
78
|
+
# Your earlier questions have been answered
|
|
79
|
+
|
|
80
|
+
The previous run left QUESTIONS.md. The user's answers:
|
|
81
|
+
|
|
82
|
+
${card.answers.map((a) => a.text).join('\n\n')}
|
|
83
|
+
|
|
84
|
+
Continue from the work already in this folder. Delete QUESTIONS.md once it's resolved.
|
|
85
|
+
` : ''}`;
|
|
86
|
+
}
|
|
87
|
+
/** The agent's own verdict on its checks: the last "CHECKS: passed|failed|not run — why" line. */
|
|
88
|
+
export function parseChecks(output) {
|
|
89
|
+
const matches = [...output.matchAll(/^\s*\**CHECKS:\**\s*(passed|failed|not run)\s*[—–:-]*\s*(.*)$/gim)];
|
|
90
|
+
const last = matches.at(-1);
|
|
91
|
+
if (!last)
|
|
92
|
+
return undefined;
|
|
93
|
+
return { result: last[1].toLowerCase(), why: last[2].trim() };
|
|
94
|
+
}
|
|
95
|
+
function firstLines(text, n = 5) {
|
|
96
|
+
return text
|
|
97
|
+
.split('\n')
|
|
98
|
+
.map((l) => l.trimEnd())
|
|
99
|
+
.filter((l) => l.trim() !== '')
|
|
100
|
+
.slice(0, n)
|
|
101
|
+
.join('\n');
|
|
102
|
+
}
|
|
103
|
+
function stamp(ms) {
|
|
104
|
+
return new Date(ms).toISOString().replace(/[:.]/g, '-');
|
|
105
|
+
}
|
|
106
|
+
/** When quota was last read after a card (module state: one away run per process). */
|
|
107
|
+
let lastRefreshMs = -Infinity;
|
|
108
|
+
export async function away(durationMs, deps, opts = {}) {
|
|
109
|
+
const { config, out } = deps;
|
|
110
|
+
const start = deps.now();
|
|
111
|
+
const deadline = start + durationMs;
|
|
112
|
+
lastRefreshMs = -Infinity;
|
|
113
|
+
if (!opts.dryRun) {
|
|
114
|
+
const recovered = updateBoard((b) => recoverRunning(b, new Date(deps.now()), deps.plan));
|
|
115
|
+
if (recovered.length)
|
|
116
|
+
out(`Moved to review after an interrupted run: ${recovered.map((id) => `#${id}`).join(', ')}`);
|
|
117
|
+
}
|
|
118
|
+
const queue = awayQueue(loadBoard());
|
|
119
|
+
const summary = { ran: [], skipped: [], stoppedBecause: null };
|
|
120
|
+
if (queue.length === 0) {
|
|
121
|
+
out('No approved cards. Approve one with `chompyy approve <id>`.');
|
|
122
|
+
return summary;
|
|
123
|
+
}
|
|
124
|
+
out(`${opts.dryRun ? 'Plan' : 'Away'} for ${formatDuration(durationMs)}: ${queue.length} approved card(s), one at a time, ${config.cardTimeoutMin}m max each.`);
|
|
125
|
+
for (const queued of queue) {
|
|
126
|
+
const remaining = deadline - deps.now();
|
|
127
|
+
if (!opts.dryRun && remaining < MIN_CARD_MS) {
|
|
128
|
+
summary.stoppedBecause = 'time is up';
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
// The previous card already read quota when it finished; don't ask twice in a row.
|
|
132
|
+
if (!opts.dryRun && deps.refreshQuota && deps.now() - lastRefreshMs > 60_000)
|
|
133
|
+
await deps.refreshQuota();
|
|
134
|
+
const gate = budgetGate(deps.snapshot(), config, new Date(deps.now()));
|
|
135
|
+
if (!gate.ok && !opts.force) {
|
|
136
|
+
summary.stoppedBecause = gate.reasons.join('; ');
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
if (opts.dryRun) {
|
|
140
|
+
const ws = deps.plan(queued);
|
|
141
|
+
out(` would run #${queued.id} ${queued.title}`);
|
|
142
|
+
out(` in ${ws.kind === 'worktree' ? `worktree ${ws.dir} (branch ${ws.branch})` : `draft folder ${ws.dir}`}`);
|
|
143
|
+
summary.ran.push(queued.id);
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const timeoutMs = Math.min(config.cardTimeoutMin * 60_000, remaining);
|
|
147
|
+
summary.ran.push(deps.isolate ? await runIsolated(queued.id, timeoutMs, deps, opts.trigger) : await runCard(queued.id, timeoutMs, deps, opts.trigger));
|
|
148
|
+
}
|
|
149
|
+
const notRun = queue.map((c) => c.id).filter((id) => !summary.ran.includes(id));
|
|
150
|
+
summary.skipped = notRun;
|
|
151
|
+
if (summary.stoppedBecause)
|
|
152
|
+
out(`${opts.dryRun ? 'Would stop' : 'Stopped'}: ${summary.stoppedBecause}.`);
|
|
153
|
+
if (notRun.length)
|
|
154
|
+
out(`Left in approved: ${notRun.map((id) => `#${id}`).join(', ')}`);
|
|
155
|
+
if (opts.dryRun)
|
|
156
|
+
out('Dry run: nothing was started.');
|
|
157
|
+
else
|
|
158
|
+
out(`Done. ${summary.ran.length} card(s) in review. See \`chompyy report\`.`);
|
|
159
|
+
return summary;
|
|
160
|
+
}
|
|
161
|
+
/** Where a card's agent pid is kept while it runs, so the supervisor can stop it if the worker dies. */
|
|
162
|
+
export const agentPidPath = (id) => homePath('runs', id, 'agent.pid');
|
|
163
|
+
/** Run a card in a worker process; if the worker dies mid-card, stop its agent and put the card in review. */
|
|
164
|
+
async function runIsolated(id, timeoutMs, deps, trigger) {
|
|
165
|
+
let res;
|
|
166
|
+
try {
|
|
167
|
+
res = await deps.isolate(id, timeoutMs, trigger);
|
|
168
|
+
}
|
|
169
|
+
catch (err) {
|
|
170
|
+
res = { exitCode: null, stderr: String(err instanceof Error ? err.message : err) };
|
|
171
|
+
}
|
|
172
|
+
// An orphaned agent would keep working (and spending) alongside the next card.
|
|
173
|
+
const pid = Number(existsSync(agentPidPath(id)) ? readFileSync(agentPidPath(id), 'utf8') : NaN);
|
|
174
|
+
if (pid > 0) {
|
|
175
|
+
try {
|
|
176
|
+
process.kill(-pid, 'SIGTERM');
|
|
177
|
+
}
|
|
178
|
+
catch { }
|
|
179
|
+
}
|
|
180
|
+
rmSync(agentPidPath(id), { force: true });
|
|
181
|
+
if (getCard(loadBoard(), id).column !== 'running')
|
|
182
|
+
return id;
|
|
183
|
+
const how = res.signal ? `was killed (${res.signal})` : `exited with code ${res.exitCode}`;
|
|
184
|
+
const tail = res.stderr.trim().split('\n').filter((l) => !/^\s*\d+: 0x/.test(l)).slice(-3).join(' ').slice(0, 300);
|
|
185
|
+
const why = `Chompyy's worker for this card ${how} before it finished${tail ? `: ${tail}` : ''}.`;
|
|
186
|
+
updateBoard((b) => recoverRunning(b, new Date(deps.now()), deps.plan, why));
|
|
187
|
+
deps.out(` ⛔ #${id}: ${why} Moving on to the next card.`);
|
|
188
|
+
return id;
|
|
189
|
+
}
|
|
190
|
+
export async function runCard(id, timeoutMs, deps, trigger) {
|
|
191
|
+
const { config, out } = deps;
|
|
192
|
+
const startedMs = deps.now();
|
|
193
|
+
const quotaBefore = deps.snapshot();
|
|
194
|
+
const card = updateBoard((b) => {
|
|
195
|
+
const c = getCard(b, id);
|
|
196
|
+
c.column = 'running';
|
|
197
|
+
c.updatedAt = new Date(startedMs).toISOString();
|
|
198
|
+
return { ...c };
|
|
199
|
+
});
|
|
200
|
+
out(`▶ #${card.id} ${card.title} (up to ${formatDuration(timeoutMs)})`);
|
|
201
|
+
const logPath = homePath('runs', card.id, `${stamp(startedMs)}.log`);
|
|
202
|
+
let ws = null;
|
|
203
|
+
let status;
|
|
204
|
+
let exitCode = null;
|
|
205
|
+
let summaryText = '';
|
|
206
|
+
let checks;
|
|
207
|
+
let verified;
|
|
208
|
+
let log = '';
|
|
209
|
+
try {
|
|
210
|
+
ws = deps.prepare(card);
|
|
211
|
+
const prompt = taskPrompt(card, ws.dir, (deps.taste ?? tasteForPrompt)());
|
|
212
|
+
const cacheDir = homePath('cache', 'tools');
|
|
213
|
+
mkdirSync(cacheDir, { recursive: true });
|
|
214
|
+
const questionsPath = join(ws.dir, 'QUESTIONS.md');
|
|
215
|
+
const questionsBefore = existsSync(questionsPath) ? readFileSync(questionsPath, 'utf8') : null;
|
|
216
|
+
const result = await deps.runner.run({
|
|
217
|
+
prompt,
|
|
218
|
+
cwd: ws.dir,
|
|
219
|
+
timeoutMs,
|
|
220
|
+
model: config.runModel,
|
|
221
|
+
maxTurns: config.maxTurns,
|
|
222
|
+
permissionMode: config.permissionMode,
|
|
223
|
+
permissionPrompts: config.permissionPrompts,
|
|
224
|
+
allowedTools: config.allowedTools,
|
|
225
|
+
disallowedTools: [...config.disallowedTools, ...denyReadRules(config.denyReadPaths)],
|
|
226
|
+
...(config.sandbox ? { settings: sandboxSettings(ws, config.sandboxAllowedDomains, cacheDir, config.denyReadPaths) } : {}),
|
|
227
|
+
env: cacheEnv(cacheDir),
|
|
228
|
+
extraArgs: config.extraArgs,
|
|
229
|
+
...(config.loopRepeat > 0 ? { loopRepeat: config.loopRepeat } : {}),
|
|
230
|
+
...(config.idleTimeoutMin > 0 ? { idleTimeoutMs: config.idleTimeoutMin * 60_000 } : {}),
|
|
231
|
+
onSpawn: (pid) => writeFileSync(agentPidPath(card.id), String(pid)),
|
|
232
|
+
// The whole stream (every tool call and result) goes to disk, never into memory: what to read when a run goes wrong.
|
|
233
|
+
rawLogPath: logPath.replace(/\.log$/, '.stream.jsonl'),
|
|
234
|
+
});
|
|
235
|
+
rmSync(agentPidPath(card.id), { force: true });
|
|
236
|
+
exitCode = result.exitCode;
|
|
237
|
+
try {
|
|
238
|
+
if (deps.commitLeftovers?.(ws, card))
|
|
239
|
+
out(' (committed changes the agent left uncommitted)');
|
|
240
|
+
}
|
|
241
|
+
catch (err) {
|
|
242
|
+
out(` couldn't commit leftover changes: ${err instanceof Error ? err.message : err}`);
|
|
243
|
+
}
|
|
244
|
+
const hasQuestions = existsSync(questionsPath) && readFileSync(questionsPath, 'utf8') !== questionsBefore;
|
|
245
|
+
status = result.stuck || result.stalled ? 'stuck' : result.timedOut ? 'timeout' : result.exitCode !== 0 ? 'failed' : hasQuestions ? 'questions' : 'ok';
|
|
246
|
+
if (result.stuck)
|
|
247
|
+
out(` ⛔ stopped: it was going in circles (${result.stuck})`);
|
|
248
|
+
if (result.stalled)
|
|
249
|
+
out(` ⛔ stopped: ${result.stalled}`);
|
|
250
|
+
checks = parseChecks(result.output);
|
|
251
|
+
if (deps.verify && ws.kind === 'worktree' && !result.stuck && !result.timedOut && result.exitCode === 0) {
|
|
252
|
+
out(' checking it independently (running the repo\'s tests, sandboxed)…');
|
|
253
|
+
verified = await deps.verify(ws, card).catch(() => undefined);
|
|
254
|
+
if (verified)
|
|
255
|
+
out(` ${verified.result === 'passed' ? '✓' : verified.result === 'failed' ? '✗' : '·'} ${verified.why}`);
|
|
256
|
+
}
|
|
257
|
+
summaryText = result.stuck
|
|
258
|
+
? `Stopped by Chompyy: it was going in circles (${result.stuck}).`
|
|
259
|
+
: result.stalled
|
|
260
|
+
? `Stopped by Chompyy: ${result.stalled} (a hung command or a stalled agent), so the next card could run.`
|
|
261
|
+
: firstLines(result.output.replace(/^\s*CHECKS:.*$/gim, '')) || firstLines(result.stderr);
|
|
262
|
+
log = `# prompt\n\n${prompt}\n\n# output\n\n${result.output}\n\n# stderr\n\n${result.stderr}\n`;
|
|
263
|
+
}
|
|
264
|
+
catch (err) {
|
|
265
|
+
status = 'error';
|
|
266
|
+
summaryText = String(err instanceof Error ? err.message : err);
|
|
267
|
+
log = `# error\n\n${summaryText}\n`;
|
|
268
|
+
}
|
|
269
|
+
const finishedMs = deps.now();
|
|
270
|
+
// What the card cost, in points of your windows: quota after minus before (an upper bound if you were busy too).
|
|
271
|
+
if (deps.refreshQuota) {
|
|
272
|
+
await deps.refreshQuota().catch(() => { });
|
|
273
|
+
lastRefreshMs = deps.now();
|
|
274
|
+
}
|
|
275
|
+
const quotaAfter = deps.snapshot();
|
|
276
|
+
const cost = {
|
|
277
|
+
fiveHourPct: usedBetween(quotaBefore?.fiveHour, quotaAfter?.fiveHour),
|
|
278
|
+
weeklyPct: usedBetween(quotaBefore?.sevenDay, quotaAfter?.sevenDay),
|
|
279
|
+
};
|
|
280
|
+
const header = `card #${card.id} · ${status} · exit ${exitCode} · ${formatDuration(finishedMs - startedMs)}\nworkdir: ${ws?.dir ?? '-'}${ws?.branch ? `\nbranch: ${ws.branch}` : ''}\n\n`;
|
|
281
|
+
writeFileSync(logPath, header + log);
|
|
282
|
+
updateBoard((b) => {
|
|
283
|
+
const c = getCard(b, id);
|
|
284
|
+
c.column = 'review';
|
|
285
|
+
c.updatedAt = new Date(finishedMs).toISOString();
|
|
286
|
+
c.logPath = logPath;
|
|
287
|
+
c.run = {
|
|
288
|
+
status,
|
|
289
|
+
startedAt: new Date(startedMs).toISOString(),
|
|
290
|
+
finishedAt: new Date(finishedMs).toISOString(),
|
|
291
|
+
durationMs: finishedMs - startedMs,
|
|
292
|
+
exitCode,
|
|
293
|
+
workdir: ws?.dir ?? '',
|
|
294
|
+
...(ws?.branch ? { branch: ws.branch } : {}),
|
|
295
|
+
summary: summaryText,
|
|
296
|
+
...(checks ? { checks } : {}),
|
|
297
|
+
cost,
|
|
298
|
+
...(verified ? { verified } : {}),
|
|
299
|
+
...(trigger ? { trigger } : {}),
|
|
300
|
+
};
|
|
301
|
+
});
|
|
302
|
+
recordRun({
|
|
303
|
+
at: new Date(finishedMs).toISOString(),
|
|
304
|
+
card: card.id,
|
|
305
|
+
title: card.title,
|
|
306
|
+
idea: card.idea,
|
|
307
|
+
cwd: card.cwd,
|
|
308
|
+
status,
|
|
309
|
+
durationMs: finishedMs - startedMs,
|
|
310
|
+
...cost,
|
|
311
|
+
});
|
|
312
|
+
out(` → ${status} · ${formatDuration(finishedMs - startedMs)}${cost.fiveHourPct !== null ? ` · used ${cost.fiveHourPct}% of the 5h window` : ''} · log ${logPath}`);
|
|
313
|
+
return card.id;
|
|
314
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
export const BLUEPRINT_SECTIONS = ['Goal', 'Scope', 'Out of scope', 'Shape', "How it's checked"];
|
|
2
|
+
export function blueprintPrompt(card) {
|
|
3
|
+
return `You write short blueprints for tasks a coding agent will run unattended, with nobody to ask.
|
|
4
|
+
Turn the idea below into a blueprint. Reply with ONLY this Markdown, no preamble:
|
|
5
|
+
|
|
6
|
+
## Goal
|
|
7
|
+
<one line: what exists when this is done>
|
|
8
|
+
|
|
9
|
+
## Scope
|
|
10
|
+
- <3 to 5 bullets of what the result will contain>
|
|
11
|
+
|
|
12
|
+
## Out of scope
|
|
13
|
+
- <1 to 3 bullets of what will NOT be done, especially anything outward: no push, merge, PR, sending or posting. Committing is fine: the run commits to the card's own branch, which Chompyy creates; don't name a branch>
|
|
14
|
+
|
|
15
|
+
## Shape
|
|
16
|
+
<a short outline of the artifact: files, sections or steps>
|
|
17
|
+
|
|
18
|
+
## How it's checked
|
|
19
|
+
- <how someone can verify the result without the author: tests, files that exist, cited sources>
|
|
20
|
+
|
|
21
|
+
Look at the working directory first (read-only) so the blueprint fits what is really there: its files,
|
|
22
|
+
languages, test command and tooling. Don't plan steps for tools the repo doesn't have.
|
|
23
|
+
|
|
24
|
+
The run can only change files inside the working directory. Its shell has no network, but the agent CAN
|
|
25
|
+
read public web pages with its web tools (WebFetch, WebSearch), so reading docs or a linked page is fine.
|
|
26
|
+
If the idea needs anything outside that (global or user config, other folders or repos, accounts,
|
|
27
|
+
installing packages, calling APIs or downloading from the shell),
|
|
28
|
+
start Out of scope with "Can't run unattended: <why>" and plan only what can be done inside the directory,
|
|
29
|
+
such as a script or written steps the user can run themselves.
|
|
30
|
+
|
|
31
|
+
Keep it under 200 words. Pick the smallest useful version of the idea.
|
|
32
|
+
Never write "no commits" or "leave files untracked": the run always commits to the card's own branch (Chompyy
|
|
33
|
+
creates and names it, so don't name one), and that branch is how the user reviews, keeps or undoes the work.
|
|
34
|
+
Don't plan a QUESTIONS.md by default. Only if the idea truly can't be done without a decision only the user
|
|
35
|
+
can make, say so in Out of scope and plan to write that question to QUESTIONS.md.
|
|
36
|
+
|
|
37
|
+
Working directory: ${card.cwd}
|
|
38
|
+
Idea: ${card.idea}`;
|
|
39
|
+
}
|
|
40
|
+
/** Strip chatter before the first heading; insist on the Goal heading. */
|
|
41
|
+
export function cleanBlueprint(output) {
|
|
42
|
+
const text = output.trim();
|
|
43
|
+
const start = text.indexOf('## Goal');
|
|
44
|
+
if (start === -1)
|
|
45
|
+
throw new Error('The model reply has no "## Goal" section.');
|
|
46
|
+
return text.slice(start).trim();
|
|
47
|
+
}
|
|
48
|
+
export async function draftBlueprint(card, runner, opts) {
|
|
49
|
+
const result = await runner.run({
|
|
50
|
+
prompt: blueprintPrompt(card),
|
|
51
|
+
cwd: opts.cwd,
|
|
52
|
+
model: opts.model,
|
|
53
|
+
tools: 'Read,Glob,Grep',
|
|
54
|
+
timeoutMs: opts.timeoutMs ?? 120_000,
|
|
55
|
+
});
|
|
56
|
+
if (result.timedOut)
|
|
57
|
+
throw new Error('Blueprint model timed out.');
|
|
58
|
+
if (result.exitCode !== 0)
|
|
59
|
+
throw new Error(`claude exited with ${result.exitCode}: ${result.stderr.trim().slice(0, 300)}`);
|
|
60
|
+
return cleanBlueprint(result.output);
|
|
61
|
+
}
|
|
62
|
+
/** Generic options when a card-specific list can't be made (e.g. no active window). */
|
|
63
|
+
export const GENERIC_FIVE_STAR = ['Closer to what I asked for', 'Shorter and simpler', 'More thorough', 'A different format'];
|
|
64
|
+
export function fiveStarPrompt(card) {
|
|
65
|
+
return `A coding agent finished a task and the user rated it below 5 stars. Suggest what would most likely
|
|
66
|
+
have made it a 5 for this user. Reply with ONLY 4 lines, one option per line, no numbering, no bullets.
|
|
67
|
+
Each option: a concrete, specific change to the result, at most 9 words, written as the user would say it
|
|
68
|
+
(e.g. "Put the answers in a separate file"). Make them different from each other.
|
|
69
|
+
|
|
70
|
+
Task: ${card.idea}
|
|
71
|
+
|
|
72
|
+
Blueprint:
|
|
73
|
+
${card.blueprint ?? '(none)'}
|
|
74
|
+
|
|
75
|
+
What the agent said it did:
|
|
76
|
+
${card.summary ?? '(nothing)'}
|
|
77
|
+
|
|
78
|
+
Files changed: ${(card.files ?? []).join(', ') || '(unknown)'}`;
|
|
79
|
+
}
|
|
80
|
+
export async function draftFiveStarOptions(card, runner, opts) {
|
|
81
|
+
const result = await runner.run({ prompt: fiveStarPrompt(card), cwd: opts.cwd, model: opts.model, tools: '', timeoutMs: 60_000 });
|
|
82
|
+
if (result.exitCode !== 0 || result.timedOut)
|
|
83
|
+
throw new Error('could not draft options');
|
|
84
|
+
const lines = result.output
|
|
85
|
+
.split('\n')
|
|
86
|
+
.map((l) => l.replace(/^\s*([-*•]|\d+[.)])\s*/, '').replace(/^"|"$/g, '').trim())
|
|
87
|
+
.filter((l) => l.length > 2 && l.length < 90);
|
|
88
|
+
if (lines.length < 2)
|
|
89
|
+
throw new Error('could not draft options');
|
|
90
|
+
return lines.slice(0, 4);
|
|
91
|
+
}
|
package/dist/board.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
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
|
+
/**
|
|
91
|
+
* Suggested cards (Chompyy's ideas, not yours) that sat untouched for `days` are archived, so the column
|
|
92
|
+
* doesn't fill with stale guesses. Your own parked ideas never expire. Returns the archived cards.
|
|
93
|
+
*/
|
|
94
|
+
export function expireSuggested(board, now, days) {
|
|
95
|
+
if (days <= 0)
|
|
96
|
+
return [];
|
|
97
|
+
const cutoff = now.getTime() - days * 24 * 3600_000;
|
|
98
|
+
const stale = board.cards.filter((c) => c.column === 'suggested' && Date.parse(c.updatedAt) < cutoff && !c.draftingAt && !c.drawingAt);
|
|
99
|
+
for (const c of stale)
|
|
100
|
+
appendJsonl(homePath('archive.jsonl'), { ...c, droppedAt: now.toISOString(), expired: true });
|
|
101
|
+
board.cards = board.cards.filter((c) => !stale.includes(c));
|
|
102
|
+
return stale;
|
|
103
|
+
}
|
|
104
|
+
export function cardsIn(board, column) {
|
|
105
|
+
return board.cards.filter((c) => c.column === column);
|
|
106
|
+
}
|
|
107
|
+
/** Approved cards in the order they were approved: the away queue. */
|
|
108
|
+
/**
|
|
109
|
+
* Cards stuck in running whose away run is gone (it crashed or was stopped) go to review as an error, with
|
|
110
|
+
* whatever they finished: put back in approved they would look untouched, and a card that crashes Chompyy
|
|
111
|
+
* would crash every away. `where` says where a card's work is. Returns their ids.
|
|
112
|
+
*/
|
|
113
|
+
export function recoverRunning(board, now, where = () => ({ dir: '' }), why = 'The away run stopped in the middle of this card (Chompyy crashed or was stopped), so it never finished.') {
|
|
114
|
+
const stuck = cardsIn(board, 'running');
|
|
115
|
+
for (const c of stuck) {
|
|
116
|
+
const ws = where(c);
|
|
117
|
+
const startedAt = c.updatedAt || now.toISOString();
|
|
118
|
+
c.column = 'review';
|
|
119
|
+
c.updatedAt = now.toISOString();
|
|
120
|
+
c.run = {
|
|
121
|
+
status: 'error',
|
|
122
|
+
startedAt,
|
|
123
|
+
finishedAt: now.toISOString(),
|
|
124
|
+
durationMs: Math.max(0, now.getTime() - Date.parse(startedAt)) || 0,
|
|
125
|
+
exitCode: null,
|
|
126
|
+
workdir: ws.dir,
|
|
127
|
+
...(ws.branch ? { branch: ws.branch } : {}),
|
|
128
|
+
summary: `${why} Anything it committed is on its branch; Run again to retry.`,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return stuck.map((c) => c.id);
|
|
132
|
+
}
|
|
133
|
+
export function awayQueue(board) {
|
|
134
|
+
return cardsIn(board, 'approved').sort((a, b) => (a.approvedAt ?? '').localeCompare(b.approvedAt ?? ''));
|
|
135
|
+
}
|
|
136
|
+
function shortPath(p) {
|
|
137
|
+
const home = process.env.HOME;
|
|
138
|
+
return home && p.startsWith(home) ? '~' + p.slice(home.length) : p;
|
|
139
|
+
}
|
|
140
|
+
function cardLine(c) {
|
|
141
|
+
const marks = [];
|
|
142
|
+
if (c.column === 'later' || c.column === 'suggested') {
|
|
143
|
+
marks.push(c.blueprint ? 'blueprint ✓' : c.blueprintError ? 'blueprint failed' : 'no blueprint');
|
|
144
|
+
}
|
|
145
|
+
if (c.run)
|
|
146
|
+
marks.push(c.run.status);
|
|
147
|
+
if (c.rating)
|
|
148
|
+
marks.push(`${'★'.repeat(c.rating.score)}`);
|
|
149
|
+
const tail = marks.length ? ` [${marks.join(' · ')}]` : '';
|
|
150
|
+
return ` #${c.id.padEnd(3)} ${c.title}${tail} ${shortPath(c.cwd)}`;
|
|
151
|
+
}
|
|
152
|
+
export function formatBoard(board, columns = COLUMNS) {
|
|
153
|
+
if (board.cards.length === 0)
|
|
154
|
+
return 'The board is empty. Park an idea with `chompyy later "<idea>"`.';
|
|
155
|
+
const out = [];
|
|
156
|
+
for (const col of columns) {
|
|
157
|
+
const cards = cardsIn(board, col);
|
|
158
|
+
if (cards.length === 0)
|
|
159
|
+
continue;
|
|
160
|
+
out.push(`${COLUMN_LABEL[col]} (${cards.length})`);
|
|
161
|
+
for (const c of cards)
|
|
162
|
+
out.push(cardLine(c));
|
|
163
|
+
}
|
|
164
|
+
return out.length ? out.join('\n') : `No cards in ${columns.join(', ')}.`;
|
|
165
|
+
}
|
|
166
|
+
export function formatCard(c) {
|
|
167
|
+
const lines = [
|
|
168
|
+
`#${c.id} ${c.title}`,
|
|
169
|
+
`column: ${c.column} · cwd: ${shortPath(c.cwd)} · created ${c.createdAt}`,
|
|
170
|
+
];
|
|
171
|
+
if (c.idea !== c.title)
|
|
172
|
+
lines.push('', c.idea);
|
|
173
|
+
lines.push('', c.blueprint ?? (c.blueprintError ? `(blueprint failed: ${c.blueprintError})` : '(no blueprint yet)'));
|
|
174
|
+
if (c.run) {
|
|
175
|
+
lines.push('', `last run: ${c.run.status} · ${c.run.workdir}${c.run.branch ? ` · branch ${c.run.branch}` : ''}`);
|
|
176
|
+
if (c.run.summary)
|
|
177
|
+
lines.push('', 'what the agent said:', ...c.run.summary.split('\n').map((l) => ` ${l}`));
|
|
178
|
+
}
|
|
179
|
+
if (c.logPath)
|
|
180
|
+
lines.push(`log: ${c.logPath}`);
|
|
181
|
+
if (c.outcome)
|
|
182
|
+
lines.push(`outcome: ${c.outcome}`);
|
|
183
|
+
if (c.rating)
|
|
184
|
+
lines.push(`rating: ${c.rating.score}/5${c.rating.reason ? ` · ${c.rating.reason}` : ''}`);
|
|
185
|
+
return lines.join('\n');
|
|
186
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// The one change Chompyy offers to make to Claude Code's own settings: keep transcripts longer
|
|
2
|
+
// (`cleanupPeriodDays`, default 30), so there's more history to learn from. Only on request.
|
|
3
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { dirname, join } from 'node:path';
|
|
6
|
+
export function keepHistory(days, path = join(homedir(), '.claude', 'settings.json')) {
|
|
7
|
+
let settings = {};
|
|
8
|
+
if (existsSync(path)) {
|
|
9
|
+
const raw = readFileSync(path, 'utf8');
|
|
10
|
+
try {
|
|
11
|
+
settings = JSON.parse(raw);
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
throw new Error(`${path} isn't valid JSON, so I left it alone. Add "cleanupPeriodDays": ${days} yourself.`);
|
|
15
|
+
}
|
|
16
|
+
writeFileSync(`${path}.chompyy-backup`, raw);
|
|
17
|
+
}
|
|
18
|
+
const before = typeof settings.cleanupPeriodDays === 'number' ? settings.cleanupPeriodDays : null;
|
|
19
|
+
settings.cleanupPeriodDays = days;
|
|
20
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
21
|
+
writeFileSync(path, JSON.stringify(settings, null, 2) + '\n');
|
|
22
|
+
return { path, before };
|
|
23
|
+
}
|