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/cli.js
ADDED
|
@@ -0,0 +1,861 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// chompyy: park ideas, blueprint them, run approved cards while you're away.
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
5
|
+
import { join, relative } from 'node:path';
|
|
6
|
+
import { parseArgs } from 'node:util';
|
|
7
|
+
import { away, cacheEnv, runCard } from './away.js';
|
|
8
|
+
import { draftBlueprint, draftFiveStarOptions, GENERIC_FIVE_STAR } from './blueprint.js';
|
|
9
|
+
import { addCard, awayQueue, COLUMNS, dropCard, expireSuggested, formatBoard, formatCard, getCard, loadBoard, moveCard, recoverRunning, updateBoard } from './board.js';
|
|
10
|
+
import { loadConfig, setConfig } from './config.js';
|
|
11
|
+
import { formatDuration, parseDuration } from './duration.js';
|
|
12
|
+
import { budgetGate } from './gate.js';
|
|
13
|
+
import { chompyyHome, homePath } from './home.js';
|
|
14
|
+
import { loadSnapshot, mergeSnapshot, parseStatusline, saveSnapshot, statusLineText, statusText as baseStatusText, windowView } from './quota.js';
|
|
15
|
+
import { loadSamples } from './pacing.js';
|
|
16
|
+
import { cardsSince, formatReport, lastReportAt, markReported, morningLine, rateCard, readTaste } from './report.js';
|
|
17
|
+
import { changedFiles, diffCard, keepCard, overlaps, questionsOf, undoCard } from './review.js';
|
|
18
|
+
import { CappedText, ClaudeRunner, claudeAvailable } from './runner.js';
|
|
19
|
+
import { commitLeftovers, gitRoot, planWorkspace, prepareWorkspace } from './workspace.js';
|
|
20
|
+
import { verifyRun } from './verify.js';
|
|
21
|
+
import { answerCard, appState, cardView, editBlueprint, recordCliLocation } from './appstate.js';
|
|
22
|
+
import { refreshLiveQuota } from './livequota.js';
|
|
23
|
+
import { recentProjects } from './projects.js';
|
|
24
|
+
import { cliVersion, installApp } from './macapp.js';
|
|
25
|
+
import { buildDigest, historyRetention, scanHistory } from './history.js';
|
|
26
|
+
import { acceptColdStart, forgetColdStart, formatColdStart, loadColdStart, runColdStart } from './coldstart.js';
|
|
27
|
+
import { keepHistory } from './claudesettings.js';
|
|
28
|
+
import { blueprintHash, drawPicture } from './picture.js';
|
|
29
|
+
import { costRange, formatCostRange, readRuns, trendLines } from './costs.js';
|
|
30
|
+
import { answerPreference, distill, distillDue, formatPrefs, formatQuestion, formatWhy, getPref, loadStore, nextQuestion, readSignals, recordOutcome, retirePreference, syncTasteFile, tasteChangesSince, } from './taste.js';
|
|
31
|
+
import { agentInstalled, awayRunning, bedtimeKey, decideTrigger, installAgent, loadTriggerState, markFired, noteTick, parseClock, takeAwayLock, uninstallAgent } from './triggers.js';
|
|
32
|
+
const HELP = `chompyy: use the 5-hour window capacity that would reset unused
|
|
33
|
+
|
|
34
|
+
Quota
|
|
35
|
+
chompyy statusline Claude Code statusLine command: reads JSON on stdin, saves a snapshot
|
|
36
|
+
chompyy status % left, time to reset, pace, weekly used, staleness
|
|
37
|
+
chompyy quota [--refresh] read live quota from Anthropic now (uses Claude Code's saved login; sends no message)
|
|
38
|
+
chompyy eat-tokens show leftover quota and cards you could choose to run (read-only)
|
|
39
|
+
|
|
40
|
+
Board
|
|
41
|
+
chompyy later "<idea>" park an idea in later (blueprint drafted in the background)
|
|
42
|
+
--no-blueprint don't draft one --wait draft it now, in the foreground
|
|
43
|
+
chompyy board [--column c] cards by column (suggested later approved running review done)
|
|
44
|
+
chompyy show <id> one card: blueprint, last run, what the agent said
|
|
45
|
+
chompyy blueprint <id> (re)draft the blueprint with a cheap model [--model haiku]
|
|
46
|
+
chompyy picture <id> (re)draw the card's picture: a diagram of what it will do (diagram-design skill)
|
|
47
|
+
chompyy approve <id> later β approved (needs a blueprint)
|
|
48
|
+
chompyy edit-blueprint <id> replace the blueprint with text from stdin
|
|
49
|
+
chompyy drop <id> remove a card (kept in archive.jsonl)
|
|
50
|
+
|
|
51
|
+
Away
|
|
52
|
+
chompyy away <1h|30m|1h30m> run approved cards headless, one at a time, until the time is up
|
|
53
|
+
--dry-run print the plan, start nothing
|
|
54
|
+
--force skip the budget gate (the duration still holds)
|
|
55
|
+
|
|
56
|
+
Back
|
|
57
|
+
chompyy report [--all] what ran, and the one thing to do about each
|
|
58
|
+
chompyy diff <id> the change it made
|
|
59
|
+
chompyy keep <id> merge its branch into your current branch
|
|
60
|
+
chompyy undo <id> throw it away (removes its branch; yours are untouched)
|
|
61
|
+
chompyy answer <id> answer the run's questions (stdin); the card goes back to approved
|
|
62
|
+
chompyy redo <id> throw this attempt away and run it again from your latest code
|
|
63
|
+
chompyy rate <id> <1-5> ["why"] [--to-five "change" ...] rate a result; --to-five = what would have made it a 5
|
|
64
|
+
chompyy five-star <id> options for "what would have made it a 5?" (JSON)
|
|
65
|
+
chompyy signals [--json] everything Chompyy has recorded from you: ratings, edits, answers
|
|
66
|
+
chompyy trends last 7 days vs the 7 before: cost per card, keep rate, rating, blueprint edits
|
|
67
|
+
|
|
68
|
+
Taste (learned from what you keep, undo, edit and rate)
|
|
69
|
+
chompyy taste show taste.md
|
|
70
|
+
chompyy taste list every preference: to ask, in taste.md, candidates, declined, retired
|
|
71
|
+
chompyy taste why <id> the cards, edits and quotes behind a preference
|
|
72
|
+
chompyy taste yes|not-now|never <id> answer a question (yes writes it to taste.md)
|
|
73
|
+
chompyy taste retire <id> stop using a preference (kept, with the reason)
|
|
74
|
+
chompyy distill [--force] read new signals and update preferences now (one model call; runs after away too)
|
|
75
|
+
|
|
76
|
+
Triggers (start away runs on their own; the budget gate still decides every card)
|
|
77
|
+
chompyy triggers on|off install or remove the macOS LaunchAgent that runs \`chompyy tick\` every 5 minutes
|
|
78
|
+
chompyy triggers what is set, and what the last tick decided
|
|
79
|
+
chompyy bedtime <23:30|off> run approved cards at bedtime (with the window that is left)
|
|
80
|
+
chompyy last-hour <on|off> run approved cards in the last hour before a 5-hour reset
|
|
81
|
+
chompyy tick check the triggers once (what the LaunchAgent runs)
|
|
82
|
+
|
|
83
|
+
Get to know you (cold start)
|
|
84
|
+
chompyy history [--digest] what Chompyy would read from your Claude Code history (local; --digest = the exact text it would send)
|
|
85
|
+
chompyy coldstart [--force] read your history once and propose taste lines and suggested cards (one model call)
|
|
86
|
+
chompyy coldstart show the proposals accept --taste t1,t2 --cards c1 forget
|
|
87
|
+
chompyy keep-history <days> keep Claude Code transcripts longer (cleanupPeriodDays; default 30)
|
|
88
|
+
|
|
89
|
+
App
|
|
90
|
+
chompyy app install (or update) the Mac app in ~/Applications and open it
|
|
91
|
+
chompyy version this CLI's version
|
|
92
|
+
chompyy projects [--json] recent project folders (from Claude Code history and past cards)
|
|
93
|
+
chompyy state --json everything the Mac app shows, in one JSON (board, show, status also take --json)
|
|
94
|
+
|
|
95
|
+
State lives in ${chompyyHome()} (override with CHOMPYY_HOME).`;
|
|
96
|
+
/** `chompyy status` text with pacing: burn-rate history and your bedtime. */
|
|
97
|
+
function statusText(snap, now) {
|
|
98
|
+
return baseStatusText(snap, now, { samples: loadSamples(), bedtime: loadConfig().bedtime });
|
|
99
|
+
}
|
|
100
|
+
async function readStdin() {
|
|
101
|
+
if (process.stdin.isTTY)
|
|
102
|
+
return '';
|
|
103
|
+
const chunks = [];
|
|
104
|
+
for await (const chunk of process.stdin)
|
|
105
|
+
chunks.push(chunk);
|
|
106
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
107
|
+
}
|
|
108
|
+
function need(value, usage) {
|
|
109
|
+
if (!value)
|
|
110
|
+
throw new Error(`Usage: ${usage}`);
|
|
111
|
+
return value;
|
|
112
|
+
}
|
|
113
|
+
async function blueprintCard(id, model) {
|
|
114
|
+
const config = loadConfig();
|
|
115
|
+
const card = getCard(loadBoard(), id);
|
|
116
|
+
try {
|
|
117
|
+
const text = await draftBlueprint(card, new ClaudeRunner(config.claudeBin), {
|
|
118
|
+
model: model ?? config.blueprintModel,
|
|
119
|
+
// Run in the card's folder so the model can read the repo (read-only tools only).
|
|
120
|
+
cwd: existsSync(card.cwd) ? card.cwd : chompyyHome(),
|
|
121
|
+
});
|
|
122
|
+
updateBoard((b) => {
|
|
123
|
+
const c = getCard(b, id);
|
|
124
|
+
c.blueprint = text;
|
|
125
|
+
delete c.blueprintError;
|
|
126
|
+
delete c.draftingAt;
|
|
127
|
+
c.updatedAt = new Date().toISOString();
|
|
128
|
+
});
|
|
129
|
+
if (config.pictures && windowActive(new Date()))
|
|
130
|
+
await pictureCard(id).catch(() => { });
|
|
131
|
+
return text;
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
135
|
+
updateBoard((b) => {
|
|
136
|
+
const c = getCard(b, id);
|
|
137
|
+
c.blueprintError = message;
|
|
138
|
+
delete c.draftingAt;
|
|
139
|
+
});
|
|
140
|
+
throw err;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/** Draw (or redraw) a card's picture with the diagram-design skill. Errors are kept on the card. */
|
|
144
|
+
async function pictureCard(id, model) {
|
|
145
|
+
const config = loadConfig();
|
|
146
|
+
const card = getCard(loadBoard(), id);
|
|
147
|
+
updateBoard((b) => {
|
|
148
|
+
getCard(b, id).drawingAt = new Date().toISOString();
|
|
149
|
+
});
|
|
150
|
+
try {
|
|
151
|
+
const info = await drawPicture(card, new ClaudeRunner(config.claudeBin), { model: model ?? config.pictureModel, now: new Date() });
|
|
152
|
+
updateBoard((b) => {
|
|
153
|
+
const c = getCard(b, id);
|
|
154
|
+
c.picture = info;
|
|
155
|
+
delete c.pictureError;
|
|
156
|
+
delete c.drawingAt;
|
|
157
|
+
});
|
|
158
|
+
return info.path;
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
162
|
+
updateBoard((b) => {
|
|
163
|
+
const c = getCard(b, id);
|
|
164
|
+
c.pictureError = message;
|
|
165
|
+
delete c.drawingAt;
|
|
166
|
+
});
|
|
167
|
+
throw err;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/** The agent's whole final message from the run log (the board keeps only its first lines). */
|
|
171
|
+
function fullOutput(card) {
|
|
172
|
+
if (!card.logPath || !existsSync(card.logPath))
|
|
173
|
+
return undefined;
|
|
174
|
+
const m = readFileSync(card.logPath, 'utf8').match(/# output\n\n([\s\S]*?)\n\n# stderr/);
|
|
175
|
+
return m?.[1]?.trim().slice(0, 4000);
|
|
176
|
+
}
|
|
177
|
+
/** True when a 5-hour window is already running, so a model call uses it instead of starting a new one. */
|
|
178
|
+
function windowActive(now) {
|
|
179
|
+
return windowView(loadSnapshot()?.fiveHour, now).known;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Draft blueprints that are waiting, but only while a window is active: drafting is a model call, and
|
|
183
|
+
* with no active window it would start a new 5-hour window. Called whenever quota is fresh.
|
|
184
|
+
*/
|
|
185
|
+
function draftPending(now) {
|
|
186
|
+
const days = loadConfig().suggestedExpiryDays;
|
|
187
|
+
if (days > 0 && loadBoard().cards.some((c) => c.column === 'suggested'))
|
|
188
|
+
updateBoard((b) => expireSuggested(b, now, days));
|
|
189
|
+
if (!windowActive(now) || !claudeAvailable(loadConfig().claudeBin))
|
|
190
|
+
return;
|
|
191
|
+
const stale = now.getTime() - 3 * 60_000;
|
|
192
|
+
const ids = updateBoard((b) => {
|
|
193
|
+
const due = b.cards.filter((c) => (c.column === 'later' || c.column === 'suggested') && !c.blueprint && !c.blueprintError && !c.noAutoDraft && (!c.draftingAt || Date.parse(c.draftingAt) < stale));
|
|
194
|
+
for (const c of due)
|
|
195
|
+
c.draftingAt = now.toISOString();
|
|
196
|
+
return due.map((c) => c.id);
|
|
197
|
+
});
|
|
198
|
+
for (const id of ids)
|
|
199
|
+
blueprintInBackground(id);
|
|
200
|
+
// Pictures for cards whose blueprint is ready but not drawn yet, or changed since (an edit or a redraw).
|
|
201
|
+
if (!loadConfig().pictures)
|
|
202
|
+
return;
|
|
203
|
+
const toDraw = updateBoard((b) => {
|
|
204
|
+
const due = b.cards.filter((c) => ['suggested', 'later', 'approved'].includes(c.column) &&
|
|
205
|
+
c.blueprint && !c.draftingAt && !c.pictureError &&
|
|
206
|
+
(!c.picture || c.picture.blueprintHash !== blueprintHash(c.blueprint)) &&
|
|
207
|
+
(!c.drawingAt || Date.parse(c.drawingAt) < now.getTime() - 6 * 60_000));
|
|
208
|
+
for (const c of due)
|
|
209
|
+
c.drawingAt = now.toISOString();
|
|
210
|
+
return due.map((c) => c.id);
|
|
211
|
+
});
|
|
212
|
+
for (const id of toDraw)
|
|
213
|
+
inBackground(['picture', id, '--quiet']);
|
|
214
|
+
}
|
|
215
|
+
function inBackground(args) {
|
|
216
|
+
const child = spawn(process.execPath, [process.argv[1], ...args], { detached: true, stdio: 'ignore', env: process.env });
|
|
217
|
+
child.unref();
|
|
218
|
+
}
|
|
219
|
+
/** Draft the blueprint in a detached child so `later` returns at once. */
|
|
220
|
+
function blueprintInBackground(id) {
|
|
221
|
+
const child = spawn(process.execPath, [process.argv[1], 'blueprint', id, '--quiet'], {
|
|
222
|
+
detached: true,
|
|
223
|
+
stdio: 'ignore',
|
|
224
|
+
env: process.env,
|
|
225
|
+
});
|
|
226
|
+
child.unref();
|
|
227
|
+
}
|
|
228
|
+
/** Distil taste from new signals, but only inside an active window (a model call would otherwise start one). */
|
|
229
|
+
async function distillNow(now, force = false) {
|
|
230
|
+
const config = loadConfig();
|
|
231
|
+
if (!force && !windowActive(now))
|
|
232
|
+
return 'No active 5-hour window: distilling now would start one. It runs after your next away, or add --force.';
|
|
233
|
+
if (!claudeAvailable(config.claudeBin))
|
|
234
|
+
return `Can't find Claude Code (\`${config.claudeBin}\`).`;
|
|
235
|
+
const r = await distill(loadBoard(), new ClaudeRunner(config.claudeBin), { model: config.distillModel, cwd: chompyyHome(), now });
|
|
236
|
+
if (!r.read)
|
|
237
|
+
return 'No new signals to learn from.';
|
|
238
|
+
const c = r.changes;
|
|
239
|
+
const parts = [`${c.added.length} new`, `${c.extended.length} with more evidence`, `${c.ready.length} ready to ask`, `${c.retired.length} retired`];
|
|
240
|
+
return `Read ${r.read} new signal(s): ${parts.join(', ')}${c.dropped ? ` (${c.dropped} thrown out for weak evidence)` : ''}. See \`chompyy taste list\`.`;
|
|
241
|
+
}
|
|
242
|
+
/** An away run: one at a time (lock), then distil what the run taught, if anything. */
|
|
243
|
+
/** What an away run (and each card's worker) needs from the real world. */
|
|
244
|
+
function awayDeps(config, freshQuota) {
|
|
245
|
+
return {
|
|
246
|
+
runner: new ClaudeRunner(config.claudeBin),
|
|
247
|
+
config,
|
|
248
|
+
now: () => Date.now(),
|
|
249
|
+
snapshot: loadSnapshot,
|
|
250
|
+
plan: planWorkspace,
|
|
251
|
+
prepare: prepareWorkspace,
|
|
252
|
+
commitLeftovers,
|
|
253
|
+
refreshQuota: async () => {
|
|
254
|
+
await freshQuota(true);
|
|
255
|
+
},
|
|
256
|
+
...(config.independentCheck
|
|
257
|
+
? {
|
|
258
|
+
verify: (ws, card) => {
|
|
259
|
+
const root = gitRoot(card.cwd);
|
|
260
|
+
const cacheDir = homePath('cache', 'tools');
|
|
261
|
+
// A card made in a subfolder (e.g. cli/ of a repo) is checked there, with that folder's node_modules.
|
|
262
|
+
const sub = root ? relative(root, card.cwd) : '';
|
|
263
|
+
return verifyRun({
|
|
264
|
+
dir: sub && !sub.startsWith('..') ? join(ws.dir, sub) : ws.dir,
|
|
265
|
+
repoRoot: sub && !sub.startsWith('..') ? card.cwd : root,
|
|
266
|
+
cacheDir,
|
|
267
|
+
env: cacheEnv(cacheDir),
|
|
268
|
+
denyRead: config.denyReadPaths,
|
|
269
|
+
timeoutMs: config.checkTimeoutMin * 60_000,
|
|
270
|
+
override: root ? config.checkCommands[root] : undefined,
|
|
271
|
+
now: () => new Date(),
|
|
272
|
+
});
|
|
273
|
+
},
|
|
274
|
+
}
|
|
275
|
+
: {}),
|
|
276
|
+
out: (line) => console.log(line),
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
/** The supervisor's side of a worker: run `chompyy run-card` and wait, killing it if it outlives its card. */
|
|
280
|
+
function isolateCard(config) {
|
|
281
|
+
return (id, timeoutMs, trigger) => new Promise((resolve) => {
|
|
282
|
+
const args = [process.argv[1], 'run-card', id, '--timeout', String(timeoutMs), ...(trigger ? ['--trigger', trigger] : [])];
|
|
283
|
+
const child = spawn(process.execPath, args, { stdio: ['ignore', 'inherit', 'pipe'], env: process.env });
|
|
284
|
+
const stderr = new CappedText(64 * 1024);
|
|
285
|
+
child.stderr.setEncoding('utf8');
|
|
286
|
+
child.stderr.on('data', (d) => {
|
|
287
|
+
stderr.push(d);
|
|
288
|
+
process.stderr.write(d);
|
|
289
|
+
});
|
|
290
|
+
// Watchdog: the card's cap, plus time for the independent check and committing, plus a margin.
|
|
291
|
+
const limit = timeoutMs + (config.independentCheck ? config.checkTimeoutMin * 60_000 : 0) + 5 * 60_000;
|
|
292
|
+
const dog = setTimeout(() => {
|
|
293
|
+
child.kill('SIGTERM'); // the worker stops its agent's process group on SIGTERM
|
|
294
|
+
setTimeout(() => child.kill('SIGKILL'), 10_000).unref();
|
|
295
|
+
}, limit);
|
|
296
|
+
child.on('close', (code, signal) => {
|
|
297
|
+
clearTimeout(dog);
|
|
298
|
+
resolve({ exitCode: code, signal, stderr: stderr.toString() });
|
|
299
|
+
});
|
|
300
|
+
child.on('error', (err) => {
|
|
301
|
+
clearTimeout(dog);
|
|
302
|
+
resolve({ exitCode: null, signal: null, stderr: String(err) });
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
async function runAway(ms, opts, now, freshQuota) {
|
|
307
|
+
const config = loadConfig();
|
|
308
|
+
const release = opts.dryRun ? () => { } : takeAwayLock(now, opts.trigger ?? 'away');
|
|
309
|
+
try {
|
|
310
|
+
await away(ms, { ...awayDeps(config, freshQuota), isolate: isolateCard(config) }, opts);
|
|
311
|
+
}
|
|
312
|
+
finally {
|
|
313
|
+
release();
|
|
314
|
+
}
|
|
315
|
+
if (!opts.dryRun && config.distillAfterAway && distillDue(loadBoard(), new Date(), 0)) {
|
|
316
|
+
try {
|
|
317
|
+
console.log(`Taste: ${await distillNow(new Date())}`);
|
|
318
|
+
}
|
|
319
|
+
catch (err) {
|
|
320
|
+
console.log(`Taste: couldn't distil (${err instanceof Error ? err.message : err})`);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
async function main(argv) {
|
|
325
|
+
const { values, positionals } = parseArgs({
|
|
326
|
+
args: argv,
|
|
327
|
+
allowPositionals: true,
|
|
328
|
+
options: {
|
|
329
|
+
'no-blueprint': { type: 'boolean' },
|
|
330
|
+
wait: { type: 'boolean' },
|
|
331
|
+
'dry-run': { type: 'boolean' },
|
|
332
|
+
force: { type: 'boolean' },
|
|
333
|
+
all: { type: 'boolean' },
|
|
334
|
+
quiet: { type: 'boolean' },
|
|
335
|
+
model: { type: 'string' },
|
|
336
|
+
column: { type: 'string', multiple: true },
|
|
337
|
+
help: { type: 'boolean', short: 'h' },
|
|
338
|
+
json: { type: 'boolean' },
|
|
339
|
+
refresh: { type: 'boolean' },
|
|
340
|
+
'to-five': { type: 'string', multiple: true },
|
|
341
|
+
digest: { type: 'boolean' },
|
|
342
|
+
taste: { type: 'string' },
|
|
343
|
+
cards: { type: 'string' },
|
|
344
|
+
timeout: { type: 'string' },
|
|
345
|
+
trigger: { type: 'string' },
|
|
346
|
+
},
|
|
347
|
+
});
|
|
348
|
+
const [command, ...args] = values.help ? ["help"] : positionals;
|
|
349
|
+
const now = new Date();
|
|
350
|
+
const json = (data) => console.log(JSON.stringify(data, null, 2));
|
|
351
|
+
if (command !== 'statusline')
|
|
352
|
+
recordCliLocation();
|
|
353
|
+
/** Fresh quota before anything that reads it (at most every 5 minutes unless forced). */
|
|
354
|
+
const freshQuota = async (force = false) => {
|
|
355
|
+
if (loadConfig().quotaSource !== 'api')
|
|
356
|
+
return null;
|
|
357
|
+
try {
|
|
358
|
+
return await refreshLiveQuota({ force });
|
|
359
|
+
}
|
|
360
|
+
catch {
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
switch (command) {
|
|
365
|
+
case 'statusline': {
|
|
366
|
+
// Must never fail loudly: it runs on every status bar refresh.
|
|
367
|
+
try {
|
|
368
|
+
const parsed = parseStatusline(await readStdin(), now);
|
|
369
|
+
const snap = mergeSnapshot(loadSnapshot(), { ...parsed, ...(parsed.fiveHour || parsed.sevenDay ? { source: 'statusline' } : {}) });
|
|
370
|
+
saveSnapshot(snap);
|
|
371
|
+
console.log(statusLineText(snap, now, { samples: loadSamples(), color: true }));
|
|
372
|
+
}
|
|
373
|
+
catch {
|
|
374
|
+
console.log('πͺ');
|
|
375
|
+
}
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
case 'status': {
|
|
379
|
+
await freshQuota();
|
|
380
|
+
draftPending(now);
|
|
381
|
+
if (values.json)
|
|
382
|
+
return json(appState(loadBoard(), loadSnapshot(), loadConfig(), now).quota);
|
|
383
|
+
console.log(statusText(loadSnapshot(), now));
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
case 'quota': {
|
|
387
|
+
const r = await freshQuota(Boolean(values.refresh));
|
|
388
|
+
if (r)
|
|
389
|
+
console.log(r.message);
|
|
390
|
+
else if (loadConfig().quotaSource !== 'api')
|
|
391
|
+
console.log('quotaSource is "statusline" in config.json; live reading is off.');
|
|
392
|
+
console.log(statusText(loadSnapshot(), now));
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
case 'state': {
|
|
396
|
+
const refreshed = await freshQuota(Boolean(values.refresh));
|
|
397
|
+
draftPending(now);
|
|
398
|
+
// A card left in running by an away run that died shouldn't look like it's still working.
|
|
399
|
+
if (!awayRunning() && loadBoard().cards.some((c) => c.column === 'running'))
|
|
400
|
+
updateBoard((b) => recoverRunning(b, now, planWorkspace));
|
|
401
|
+
// What the quota check just did, so the app's Refresh button can say it instead of looking dead.
|
|
402
|
+
const quotaRefresh = values.refresh ? (refreshed ? { ok: refreshed.ok, message: refreshed.message } : { ok: false, message: 'Live quota reading is off (quotaSource in config.json).' }) : null;
|
|
403
|
+
return json({ ...appState(loadBoard(), loadSnapshot(), loadConfig(), now), quotaRefresh });
|
|
404
|
+
}
|
|
405
|
+
case 'app': {
|
|
406
|
+
console.log(`Downloading Chompyy ${cliVersion()} for Macβ¦`);
|
|
407
|
+
const at = await installApp();
|
|
408
|
+
console.log(`Installed ${at} and opened it. Look for the cookie in your menu bar.`);
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
case 'history': {
|
|
412
|
+
const scan = scanHistory();
|
|
413
|
+
if (values.digest)
|
|
414
|
+
return console.log(buildDigest(scan.sessions).text || '(nothing to read)');
|
|
415
|
+
const { included, text } = buildDigest(scan.sessions);
|
|
416
|
+
const retention = historyRetention();
|
|
417
|
+
const projects = [...new Set(scan.sessions.map((s) => s.project))];
|
|
418
|
+
const info = {
|
|
419
|
+
sessions: scan.sessions.length,
|
|
420
|
+
projects: projects.length,
|
|
421
|
+
projectNames: projects.map((p) => p.split('/').pop()),
|
|
422
|
+
from: scan.from,
|
|
423
|
+
to: scan.to,
|
|
424
|
+
skipped: scan.skipped,
|
|
425
|
+
digest: { sessions: included.length, chars: text.length },
|
|
426
|
+
retention,
|
|
427
|
+
};
|
|
428
|
+
if (values.json)
|
|
429
|
+
return json(info);
|
|
430
|
+
console.log(`${info.sessions} interactive sessions in ${info.projects} projects, ${(scan.from ?? '').slice(0, 10)} to ${(scan.to ?? '').slice(0, 10)}`);
|
|
431
|
+
console.log(`Skipped: ${scan.skipped.headless} headless runs, ${scan.skipped.temp} in temp folders, ${scan.skipped.empty} empty`);
|
|
432
|
+
console.log(`Would send: the newest ${included.length} sessions, ${text.length} characters (see it: chompyy history --digest)`);
|
|
433
|
+
console.log(`Claude Code keeps transcripts ${retention.days} days${retention.isDefault ? ' (default; raise it with chompyy keep-history 365)' : ''}`);
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
case 'coldstart': {
|
|
437
|
+
const sub = args[0];
|
|
438
|
+
if (sub === 'show') {
|
|
439
|
+
const cs = loadColdStart();
|
|
440
|
+
if (values.json)
|
|
441
|
+
return json(cs);
|
|
442
|
+
return console.log(cs ? formatColdStart(cs) : 'No cold start yet. Run `chompyy coldstart`.');
|
|
443
|
+
}
|
|
444
|
+
if (sub === 'accept') {
|
|
445
|
+
const list = (v) => (v ?? '').split(',').map((x) => x.trim()).filter(Boolean);
|
|
446
|
+
const r = acceptColdStart({ taste: list(values.taste), cards: list(values.cards) }, now);
|
|
447
|
+
if (values.json)
|
|
448
|
+
return json(r);
|
|
449
|
+
console.log(`Added ${r.taste.length} taste line(s) to taste.md and ${r.cards.length} card(s) to suggested${r.cards.length ? ` (${r.cards.map((c) => `#${c.id}`).join(', ')})` : ''}.`);
|
|
450
|
+
draftPending(now);
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
if (sub === 'forget')
|
|
454
|
+
return console.log(forgetColdStart() ? 'Forgot the cold start proposals. Accepted taste lines stay in taste.md.' : 'Nothing to forget.');
|
|
455
|
+
if (sub)
|
|
456
|
+
throw new Error('Usage: chompyy coldstart [show|accept|forget]');
|
|
457
|
+
await freshQuota();
|
|
458
|
+
if (!values.force && !windowActive(now))
|
|
459
|
+
throw new Error('No active 5-hour window: reading your history would start one. Try again while you are using Claude Code, or add --force.');
|
|
460
|
+
const config = loadConfig();
|
|
461
|
+
if (!claudeAvailable(config.claudeBin))
|
|
462
|
+
throw new Error(`Can't find Claude Code (\`${config.claudeBin}\`).`);
|
|
463
|
+
const cs = await runColdStart(scanHistory(), new ClaudeRunner(config.claudeBin), { model: config.coldStartModel, cwd: chompyyHome(), now, existing: loadBoard().cards.map((c) => c.title) });
|
|
464
|
+
if (values.json)
|
|
465
|
+
return json(cs);
|
|
466
|
+
console.log(formatColdStart(cs));
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
case 'keep-history': {
|
|
470
|
+
const days = Number(need(args[0], 'chompyy keep-history <days>'));
|
|
471
|
+
if (!Number.isInteger(days) || days < 1)
|
|
472
|
+
throw new Error('Days must be a whole number, e.g. 365.');
|
|
473
|
+
const r = keepHistory(days);
|
|
474
|
+
console.log(`Claude Code now keeps transcripts for ${days} days (was ${r.before ?? '30, the default'}). Changed ${r.path}.`);
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
case 'version':
|
|
478
|
+
console.log(cliVersion());
|
|
479
|
+
return;
|
|
480
|
+
case 'projects': {
|
|
481
|
+
const list = recentProjects(loadBoard());
|
|
482
|
+
if (values.json)
|
|
483
|
+
return json(list);
|
|
484
|
+
for (const p of list)
|
|
485
|
+
console.log(`${p.name.padEnd(28)} ${p.path}${p.isGit ? '' : ' (not a git repo)'}`);
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
case 'five-star': {
|
|
489
|
+
// Options for "what would have made it a 5?", written for this card; cached on the card.
|
|
490
|
+
const id = need(args[0], 'chompyy five-star <id>');
|
|
491
|
+
const card = getCard(loadBoard(), id);
|
|
492
|
+
if (card.fiveStarOptions?.length)
|
|
493
|
+
return json(card.fiveStarOptions);
|
|
494
|
+
await freshQuota();
|
|
495
|
+
// A model call with no active window would start one, so fall back to generic options then.
|
|
496
|
+
if (!windowActive(now) || !claudeAvailable(loadConfig().claudeBin))
|
|
497
|
+
return json(GENERIC_FIVE_STAR);
|
|
498
|
+
try {
|
|
499
|
+
const view = cardView(card);
|
|
500
|
+
const options = await draftFiveStarOptions({ idea: card.idea, blueprint: card.blueprint, summary: fullOutput(card) ?? card.run?.summary, files: view.files }, new ClaudeRunner(loadConfig().claudeBin), { model: loadConfig().blueprintModel, cwd: chompyyHome() });
|
|
501
|
+
updateBoard((b) => {
|
|
502
|
+
getCard(b, id).fiveStarOptions = options;
|
|
503
|
+
});
|
|
504
|
+
return json(options);
|
|
505
|
+
}
|
|
506
|
+
catch {
|
|
507
|
+
return json(GENERIC_FIVE_STAR);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
case 'signals': {
|
|
511
|
+
const path = homePath('signals.jsonl');
|
|
512
|
+
const lines = existsSync(path) ? readFileSync(path, 'utf8').split('\n').filter(Boolean) : [];
|
|
513
|
+
const items = lines.flatMap((l) => {
|
|
514
|
+
try {
|
|
515
|
+
return [JSON.parse(l)];
|
|
516
|
+
}
|
|
517
|
+
catch {
|
|
518
|
+
return [];
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
if (values.json)
|
|
522
|
+
return json(items.reverse());
|
|
523
|
+
for (const s of items) {
|
|
524
|
+
if (s.kind === 'coldstart') {
|
|
525
|
+
console.log(`${s.at.slice(0, 16)} coldstart kept: ${[...s.accepted.taste, ...s.accepted.cards].join('; ') || '-'} left out: ${[...s.declined.taste, ...s.declined.cards].join('; ') || '-'}`);
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
528
|
+
console.log(`${s.at.slice(0, 16)} #${s.card} ${s.kind ?? 'rating'} ${s.rating ? `${s.rating}/5 ` : ''}${s.reason ?? s.text ?? ''}${s.toFive ? ` β to make it a 5: ${s.toFive.join('; ')}` : ''}`);
|
|
529
|
+
}
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
case 'edit-blueprint': {
|
|
533
|
+
const id = need(args[0], 'chompyy edit-blueprint <id> (new blueprint on stdin)');
|
|
534
|
+
const text = await readStdin();
|
|
535
|
+
const card = updateBoard((b) => editBlueprint(b, id, text, now));
|
|
536
|
+
console.log(`βοΈ #${card.id} blueprint updated.`);
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
case 'answer': {
|
|
540
|
+
const id = need(args[0], 'chompyy answer <id> (answers on stdin)');
|
|
541
|
+
const text = args.slice(1).join(' ').trim() || (await readStdin());
|
|
542
|
+
const card = updateBoard((b) => answerCard(b, id, text, now));
|
|
543
|
+
console.log(`π¬ #${card.id} answered and back in approved; the next away run continues it.`);
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
case 'eat-tokens': {
|
|
547
|
+
await freshQuota();
|
|
548
|
+
const snapshot = loadSnapshot();
|
|
549
|
+
console.log(statusText(snapshot, now));
|
|
550
|
+
const view = windowView(snapshot?.fiveHour, now);
|
|
551
|
+
if (!view.known) {
|
|
552
|
+
console.log('\nNo leftover window can be planned: refresh the Claude Code status line first.');
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
const eligible = loadBoard().cards.filter((card) => card.column === 'approved' || card.column === 'later');
|
|
556
|
+
const runs = readRuns();
|
|
557
|
+
if (!eligible.length) {
|
|
558
|
+
console.log('\nNo cards to consider. Park an idea with `chompyy later "<idea>"`.');
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
console.log(`\n${Math.round(view.leftPct)}% left until reset (${formatDuration(view.msLeft)}). Choose from these cards:`);
|
|
562
|
+
for (const card of eligible) {
|
|
563
|
+
const state = card.column === 'approved' ? 'approved Β· ready' : 'later Β· approve to run';
|
|
564
|
+
console.log(` #${card.id} ${card.title} [${state}]`);
|
|
565
|
+
if (card.column === 'later' && !card.blueprint?.trim())
|
|
566
|
+
console.log(' blueprint needed before approval');
|
|
567
|
+
console.log(` ${formatCostRange(costRange(card, runs))}`);
|
|
568
|
+
}
|
|
569
|
+
console.log('\nThis is a read-only list. Start selected work with `chompyy away <duration>`.');
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
case 'later': {
|
|
573
|
+
const idea = need(args.join(' ').trim(), 'chompyy later "<idea>"');
|
|
574
|
+
const card = updateBoard((b) => addCard(b, idea, process.cwd(), now));
|
|
575
|
+
console.log(`π₯ #${card.id} parked in later: ${card.title}`);
|
|
576
|
+
if (values['no-blueprint']) {
|
|
577
|
+
updateBoard((b) => {
|
|
578
|
+
getCard(b, card.id).noAutoDraft = true;
|
|
579
|
+
});
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
if (!claudeAvailable(loadConfig().claudeBin)) {
|
|
583
|
+
console.log(` (claude CLI not found; draft the blueprint later with \`chompyy blueprint ${card.id}\`)`);
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
if (values.wait) {
|
|
587
|
+
try {
|
|
588
|
+
console.log('\n' + (await blueprintCard(card.id)));
|
|
589
|
+
}
|
|
590
|
+
catch (err) {
|
|
591
|
+
console.log(` blueprint failed: ${err instanceof Error ? err.message : err}`);
|
|
592
|
+
}
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
await freshQuota();
|
|
596
|
+
if (!windowActive(now)) {
|
|
597
|
+
console.log(' the blueprint waits until your 5-hour window is active (drafting now would start a new window)');
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
updateBoard((b) => {
|
|
601
|
+
getCard(b, card.id).draftingAt = now.toISOString();
|
|
602
|
+
});
|
|
603
|
+
blueprintInBackground(card.id);
|
|
604
|
+
console.log(` drafting the blueprint in the background; see it with \`chompyy show ${card.id}\``);
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
case 'board': {
|
|
608
|
+
const cols = (values.column ?? []).flatMap((c) => c.split(','));
|
|
609
|
+
const bad = cols.filter((c) => !COLUMNS.includes(c));
|
|
610
|
+
if (bad.length)
|
|
611
|
+
throw new Error(`Unknown column(s): ${bad.join(', ')}. Columns: ${COLUMNS.join(', ')}`);
|
|
612
|
+
if (values.json)
|
|
613
|
+
return json(loadBoard().cards.filter((c) => !cols.length || cols.includes(c.column)));
|
|
614
|
+
console.log(formatBoard(loadBoard(), cols.length ? cols : COLUMNS));
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
case 'show': {
|
|
618
|
+
const card = getCard(loadBoard(), need(args[0], 'chompyy show <id>'));
|
|
619
|
+
if (values.json)
|
|
620
|
+
return json(cardView(card));
|
|
621
|
+
console.log(formatCard(card));
|
|
622
|
+
if (!card.run)
|
|
623
|
+
console.log(`\n${formatCostRange(costRange(card, readRuns()))}`);
|
|
624
|
+
else if (card.run.cost?.fiveHourPct != null)
|
|
625
|
+
console.log(`used ${card.run.cost.fiveHourPct}% of the 5h window${card.run.trigger ? ` Β· started by the ${card.run.trigger} trigger` : ''}`);
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
case 'picture': {
|
|
629
|
+
const id = need(args[0], 'chompyy picture <id> [--model sonnet]');
|
|
630
|
+
await freshQuota();
|
|
631
|
+
if (!values.force && !windowActive(now))
|
|
632
|
+
throw new Error('No active 5-hour window: drawing would start one. Add --force to draw anyway.');
|
|
633
|
+
const path = await pictureCard(id, values.model);
|
|
634
|
+
if (!values.quiet)
|
|
635
|
+
console.log(`Drew the picture for #${id}: ${path}`);
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
case 'blueprint': {
|
|
639
|
+
const id = need(args[0], 'chompyy blueprint <id> [--model haiku]');
|
|
640
|
+
const text = await blueprintCard(id, values.model);
|
|
641
|
+
if (!values.quiet)
|
|
642
|
+
console.log(text);
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
case 'approve': {
|
|
646
|
+
const card = updateBoard((b) => moveCard(b, need(args[0], 'chompyy approve <id>'), 'approved', now));
|
|
647
|
+
console.log(`β
#${card.id} approved: ${card.title}`);
|
|
648
|
+
for (const o of overlaps(card, loadBoard().cards)) {
|
|
649
|
+
console.log(` β οΈ #${o.id} "${o.title}" may touch the same files (${o.files.slice(0, 3).join(', ')}). Keeping both can conflict; Run again fixes that.`);
|
|
650
|
+
}
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
case 'drop': {
|
|
654
|
+
const card = updateBoard((b) => dropCard(b, need(args[0], 'chompyy drop <id>'), now));
|
|
655
|
+
console.log(`π #${card.id} dropped: ${card.title}`);
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
case 'run-card': {
|
|
659
|
+
// A worker started by an away run: one card in its own process, so a crash ends only this card.
|
|
660
|
+
const id = need(args[0], 'chompyy run-card <id> --timeout <ms>');
|
|
661
|
+
const config = loadConfig();
|
|
662
|
+
await runCard(id, Number(values.timeout) || config.cardTimeoutMin * 60_000, awayDeps(config, freshQuota), values.trigger);
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
case 'away': {
|
|
666
|
+
const ms = parseDuration(need(args[0], 'chompyy away <1h|30m> [--dry-run] [--force]'));
|
|
667
|
+
const config = loadConfig();
|
|
668
|
+
await freshQuota(true);
|
|
669
|
+
const gate = budgetGate(loadSnapshot(), config, now);
|
|
670
|
+
console.log(statusText(loadSnapshot(), now));
|
|
671
|
+
console.log(`gate ${gate.ok ? 'open' : values.force ? 'closed, forced open' : 'closed'}${[...gate.reasons, ...gate.notes].map((r) => `\n Β· ${r}`).join('')}\n`);
|
|
672
|
+
await runAway(ms, { dryRun: values['dry-run'], force: values.force }, now, freshQuota);
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
case 'tick': {
|
|
676
|
+
// Run by the LaunchAgent every 5 minutes. Prints one line per tick to tick.log.
|
|
677
|
+
await freshQuota();
|
|
678
|
+
const config = loadConfig();
|
|
679
|
+
const board = loadBoard();
|
|
680
|
+
const d = decideTrigger(now, loadSnapshot(), config, loadTriggerState().fired, awayQueue(board).length, Boolean(awayRunning()));
|
|
681
|
+
const stamp = now.toISOString().slice(0, 16);
|
|
682
|
+
if (!d.fire) {
|
|
683
|
+
noteTick(now, d.why);
|
|
684
|
+
// Nightly consolidation: at bedtime, distil taste even when no card runs.
|
|
685
|
+
if (config.bedtime && bedtimeKey(now, config.bedtime, config.bedtimeWindowMin) && !awayRunning() && windowActive(now) && distillDue(board, now, 12 * 3600_000)) {
|
|
686
|
+
console.log(`${stamp} bedtime Β· taste: ${await distillNow(now).catch((e) => String(e))}`);
|
|
687
|
+
}
|
|
688
|
+
else if (values.json || process.stdout.isTTY)
|
|
689
|
+
console.log(`${stamp} ${d.why}`);
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
markFired(d.key, now, d.why);
|
|
693
|
+
console.log(`${stamp} βΆ ${d.why}: away for ${formatDuration(d.durationMs)}`);
|
|
694
|
+
await runAway(d.durationMs, { trigger: d.kind }, now, freshQuota);
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
case 'triggers': {
|
|
698
|
+
const sub = args[0];
|
|
699
|
+
if (sub === 'on') {
|
|
700
|
+
const path = installAgent();
|
|
701
|
+
const c = loadConfig();
|
|
702
|
+
console.log(`Triggers on: ${path} runs \`chompyy tick\` every 5 minutes.`);
|
|
703
|
+
console.log(` last hour before a reset: ${c.lastHourTrigger ? `on (with β₯${c.lastHourMinLeftPct}% left)` : 'off'} Β· bedtime: ${c.bedtime ?? 'not set (chompyy bedtime 23:30)'}`);
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
if (sub === 'off')
|
|
707
|
+
return console.log(uninstallAgent() ? 'Triggers off: removed the LaunchAgent.' : 'Triggers were already off.');
|
|
708
|
+
if (sub)
|
|
709
|
+
throw new Error('Usage: chompyy triggers [on|off]');
|
|
710
|
+
const c = loadConfig();
|
|
711
|
+
const st = loadTriggerState();
|
|
712
|
+
if (values.json)
|
|
713
|
+
return json({ installed: agentInstalled(), lastHour: c.lastHourTrigger, lastHourMinLeftPct: c.lastHourMinLeftPct, bedtime: c.bedtime, ...st });
|
|
714
|
+
console.log(`LaunchAgent ${agentInstalled() ? 'on (every 5 minutes)' : 'off (turn on: chompyy triggers on)'}`);
|
|
715
|
+
console.log(`last hour ${c.lastHourTrigger ? `on, with β₯${c.lastHourMinLeftPct}% of the window left` : 'off'}`);
|
|
716
|
+
console.log(`bedtime ${c.bedtime ?? 'not set'}`);
|
|
717
|
+
if (st.lastTickAt)
|
|
718
|
+
console.log(`last tick ${st.lastTickAt.slice(0, 16).replace('T', ' ')}: ${st.lastDecision ?? ''}`);
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
case 'bedtime': {
|
|
722
|
+
const v = need(args[0], 'chompyy bedtime <23:30|off>');
|
|
723
|
+
if (v === 'off') {
|
|
724
|
+
setConfig('bedtime', null);
|
|
725
|
+
return console.log('Bedtime trigger off.');
|
|
726
|
+
}
|
|
727
|
+
parseClock(v);
|
|
728
|
+
setConfig('bedtime', v);
|
|
729
|
+
console.log(`Bedtime set to ${v}: approved cards run then, with the window that is left.${agentInstalled() ? '' : ' Turn triggers on with `chompyy triggers on`.'}`);
|
|
730
|
+
return;
|
|
731
|
+
}
|
|
732
|
+
case 'last-hour': {
|
|
733
|
+
const v = need(args[0], 'chompyy last-hour <on|off>');
|
|
734
|
+
if (v !== 'on' && v !== 'off')
|
|
735
|
+
throw new Error('Usage: chompyy last-hour <on|off>');
|
|
736
|
+
setConfig('lastHourTrigger', v === 'on');
|
|
737
|
+
console.log(`Last-hour trigger ${v}.${v === 'on' && !agentInstalled() ? ' Turn triggers on with `chompyy triggers on`.' : ''}`);
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
740
|
+
case 'distill': {
|
|
741
|
+
console.log(await distillNow(now, Boolean(values.force)));
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
case 'trends': {
|
|
745
|
+
const lines = trendLines(readRuns(), readSignals(), now);
|
|
746
|
+
console.log(lines.length ? lines.join('\n') : 'Not enough runs yet for trends (needs 3).');
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
749
|
+
case 'report': {
|
|
750
|
+
const since = values.all ? null : lastReportAt();
|
|
751
|
+
syncTasteFile(now);
|
|
752
|
+
const cards = cardsSince(loadBoard(), since);
|
|
753
|
+
const store = loadStore();
|
|
754
|
+
const signals = readSignals();
|
|
755
|
+
const morning = morningLine(cards, tasteChangesSince(store, since));
|
|
756
|
+
const question = nextQuestion(store, signals);
|
|
757
|
+
const footer = [...(question ? formatQuestion(question, signals) : []), ...trendLines(readRuns(), signals, now)];
|
|
758
|
+
console.log(formatReport(cards, since, (c) => ({ files: changedFiles(c), questions: questionsOf(c) }), { header: morning ? [morning] : [], footer }));
|
|
759
|
+
markReported(now);
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
762
|
+
case 'diff': {
|
|
763
|
+
console.log(diffCard(getCard(loadBoard(), need(args[0], 'chompyy diff <id>'))));
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
case 'keep': {
|
|
767
|
+
const id = need(args[0], 'chompyy keep <id>');
|
|
768
|
+
console.log(keepCard(getCard(loadBoard(), id)));
|
|
769
|
+
updateBoard((b) => {
|
|
770
|
+
const card = getCard(b, id);
|
|
771
|
+
card.outcome = 'kept';
|
|
772
|
+
card.column = 'done';
|
|
773
|
+
card.updatedAt = now.toISOString();
|
|
774
|
+
recordOutcome(card, 'kept', now);
|
|
775
|
+
return card;
|
|
776
|
+
});
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
case 'undo': {
|
|
780
|
+
const id = need(args[0], 'chompyy undo <id>');
|
|
781
|
+
console.log(undoCard(getCard(loadBoard(), id)));
|
|
782
|
+
updateBoard((b) => {
|
|
783
|
+
const card = getCard(b, id);
|
|
784
|
+
card.outcome = 'undone';
|
|
785
|
+
card.column = 'done';
|
|
786
|
+
card.updatedAt = now.toISOString();
|
|
787
|
+
recordOutcome(card, 'undone', now);
|
|
788
|
+
return card;
|
|
789
|
+
});
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
792
|
+
case 'redo': {
|
|
793
|
+
const id = need(args[0], 'chompyy redo <id>');
|
|
794
|
+
const before = getCard(loadBoard(), id);
|
|
795
|
+
if (before.column !== 'review' && before.column !== 'done')
|
|
796
|
+
throw new Error(`Card #${id} is in ${before.column}; only cards that ran can be run again.`);
|
|
797
|
+
if (before.run)
|
|
798
|
+
console.log(undoCard(before));
|
|
799
|
+
const card = updateBoard((b) => {
|
|
800
|
+
const c = getCard(b, id);
|
|
801
|
+
c.column = 'approved';
|
|
802
|
+
c.approvedAt = now.toISOString();
|
|
803
|
+
c.updatedAt = c.approvedAt;
|
|
804
|
+
delete c.run;
|
|
805
|
+
delete c.outcome;
|
|
806
|
+
return c;
|
|
807
|
+
});
|
|
808
|
+
console.log(`π #${card.id} back in approved; it runs again from your latest code on the next away run.`);
|
|
809
|
+
return;
|
|
810
|
+
}
|
|
811
|
+
case 'rate': {
|
|
812
|
+
const usage = 'chompyy rate <id> <1-5> ["optional reason"]';
|
|
813
|
+
const id = need(args[0], usage);
|
|
814
|
+
const score = Number(need(args[1], usage));
|
|
815
|
+
const reason = args.slice(2).join(' ').trim() || undefined;
|
|
816
|
+
const toFive = (values['to-five'] ?? []).map((t) => t.trim()).filter(Boolean);
|
|
817
|
+
const card = updateBoard((b) => rateCard(b, id, score, reason, now, toFive));
|
|
818
|
+
console.log(`β #${card.id} rated ${score}/5${reason ? ` ("${reason}")` : ''}. Saved to signals.jsonl${card.column === 'review' ? '; keep or undo it when youβre ready' : ''}.`);
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
821
|
+
case 'taste': {
|
|
822
|
+
const sub = args[0];
|
|
823
|
+
const removed = syncTasteFile(now);
|
|
824
|
+
if (removed.length)
|
|
825
|
+
console.log(`Retired ${removed.join(', ')}: you removed ${removed.length === 1 ? 'it' : 'them'} from taste.md.\n`);
|
|
826
|
+
if (sub === 'list') {
|
|
827
|
+
if (values.json)
|
|
828
|
+
return json(loadStore());
|
|
829
|
+
return console.log(formatPrefs(loadStore(), readSignals()));
|
|
830
|
+
}
|
|
831
|
+
if (sub === 'why')
|
|
832
|
+
return console.log(formatWhy(getPref(loadStore(), need(args[1], 'chompyy taste why <id>')), readSignals()));
|
|
833
|
+
if (sub === 'yes' || sub === 'not-now' || sub === 'never') {
|
|
834
|
+
const p = answerPreference(need(args[1], `chompyy taste ${sub} <id>`), sub, now);
|
|
835
|
+
const said = { yes: `β Added to taste.md: "${p.text}". Agents follow it from now on.`, 'not-now': `Okay, not now. Chompyy asks again only when there's more evidence.`, never: `π Won't ask about "${p.text}" again.` };
|
|
836
|
+
return console.log(said[sub]);
|
|
837
|
+
}
|
|
838
|
+
if (sub === 'retire') {
|
|
839
|
+
const p = retirePreference(need(args[1], 'chompyy taste retire <id>'), now);
|
|
840
|
+
return console.log(`Retired ${p.id}: "${p.text}". It's kept in \`chompyy taste list\` with the reason.`);
|
|
841
|
+
}
|
|
842
|
+
if (sub)
|
|
843
|
+
throw new Error('Usage: chompyy taste [list | why <id> | yes|not-now|never <id> | retire <id>]');
|
|
844
|
+
const { path, text, created } = readTaste();
|
|
845
|
+
if (created)
|
|
846
|
+
console.log(`(created ${path})\n`);
|
|
847
|
+
console.log(text);
|
|
848
|
+
return;
|
|
849
|
+
}
|
|
850
|
+
case undefined:
|
|
851
|
+
case 'help':
|
|
852
|
+
console.log(HELP);
|
|
853
|
+
return;
|
|
854
|
+
default:
|
|
855
|
+
throw new Error(`Unknown command "${command}". Run \`chompyy help\`.`);
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
main(process.argv.slice(2)).catch((err) => {
|
|
859
|
+
console.error(`chompyy: ${err instanceof Error ? err.message : err}`);
|
|
860
|
+
process.exit(1);
|
|
861
|
+
});
|