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.
Files changed (178) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +252 -2
  3. package/THIRD_PARTY_NOTICES.md +59 -0
  4. package/dist/appstate.js +116 -0
  5. package/dist/away.js +314 -0
  6. package/dist/blueprint.js +91 -0
  7. package/dist/board.js +186 -0
  8. package/dist/claudesettings.js +23 -0
  9. package/dist/cli.js +861 -0
  10. package/dist/coldstart.js +207 -0
  11. package/dist/config.js +89 -0
  12. package/dist/costs.js +162 -0
  13. package/dist/duration.js +36 -0
  14. package/dist/gate.js +69 -0
  15. package/dist/history.js +308 -0
  16. package/dist/home.js +34 -0
  17. package/dist/livequota.js +92 -0
  18. package/dist/macapp.js +57 -0
  19. package/dist/pacing.js +189 -0
  20. package/dist/picture.js +117 -0
  21. package/dist/projects.js +114 -0
  22. package/dist/quota.js +153 -0
  23. package/dist/report.js +136 -0
  24. package/dist/review.js +173 -0
  25. package/dist/runner.js +357 -0
  26. package/dist/taste.js +507 -0
  27. package/dist/triggers.js +182 -0
  28. package/dist/vendor/codeburn/claude.js +255 -0
  29. package/dist/vendor/codeburn/security.js +260 -0
  30. package/dist/vendor/codeburn/types.js +1 -0
  31. package/dist/verify.js +131 -0
  32. package/dist/workspace.js +80 -0
  33. package/package.json +48 -4
  34. package/skills/away/SKILL.md +26 -0
  35. package/skills/eat-tokens/SKILL.md +18 -0
  36. package/skills/later/SKILL.md +20 -0
  37. package/skills/taste/SKILL.md +19 -0
  38. package/vendor/diagram-design/LICENSE +21 -0
  39. package/vendor/diagram-design/SKILL.md +399 -0
  40. package/vendor/diagram-design/UPSTREAM.md +18 -0
  41. package/vendor/diagram-design/assets/example-arc-diagram.html +111 -0
  42. package/vendor/diagram-design/assets/example-architecture-containment.html +205 -0
  43. package/vendor/diagram-design/assets/example-architecture-delta.html +193 -0
  44. package/vendor/diagram-design/assets/example-architecture.html +183 -0
  45. package/vendor/diagram-design/assets/example-axonometric-plan-campus.html +108 -0
  46. package/vendor/diagram-design/assets/example-axonometric-plan-coffee-shop.html +121 -0
  47. package/vendor/diagram-design/assets/example-axonometric-plan-warehouse.html +127 -0
  48. package/vendor/diagram-design/assets/example-axonometric-plan.html +114 -0
  49. package/vendor/diagram-design/assets/example-bar.html +129 -0
  50. package/vendor/diagram-design/assets/example-beeswarm.html +384 -0
  51. package/vendor/diagram-design/assets/example-box-plot.html +127 -0
  52. package/vendor/diagram-design/assets/example-bubble.html +147 -0
  53. package/vendor/diagram-design/assets/example-bump.html +142 -0
  54. package/vendor/diagram-design/assets/example-data-flow.html +143 -0
  55. package/vendor/diagram-design/assets/example-datalake.html +269 -0
  56. package/vendor/diagram-design/assets/example-db-schema.html +302 -0
  57. package/vendor/diagram-design/assets/example-dependency.html +224 -0
  58. package/vendor/diagram-design/assets/example-deployment.html +190 -0
  59. package/vendor/diagram-design/assets/example-dp-integration.html +81 -0
  60. package/vendor/diagram-design/assets/example-dp-security-matrix.html +88 -0
  61. package/vendor/diagram-design/assets/example-er.html +202 -0
  62. package/vendor/diagram-design/assets/example-event-modeling.html +64 -0
  63. package/vendor/diagram-design/assets/example-exploded-ai-stack.html +85 -0
  64. package/vendor/diagram-design/assets/example-exploded-keyboard.html +84 -0
  65. package/vendor/diagram-design/assets/example-exploded-phone.html +83 -0
  66. package/vendor/diagram-design/assets/example-exploded-unboxing.html +84 -0
  67. package/vendor/diagram-design/assets/example-exploded.html +83 -0
  68. package/vendor/diagram-design/assets/example-fishbone.html +152 -0
  69. package/vendor/diagram-design/assets/example-flowchart.html +163 -0
  70. package/vendor/diagram-design/assets/example-gantt.html +137 -0
  71. package/vendor/diagram-design/assets/example-heatmap.html +224 -0
  72. package/vendor/diagram-design/assets/example-high-level-vertical.html +325 -0
  73. package/vendor/diagram-design/assets/example-high-level.html +301 -0
  74. package/vendor/diagram-design/assets/example-import-drawio.html +185 -0
  75. package/vendor/diagram-design/assets/example-import-excalidraw.html +70 -0
  76. package/vendor/diagram-design/assets/example-import-mermaid.html +70 -0
  77. package/vendor/diagram-design/assets/example-import-plantuml.html +107 -0
  78. package/vendor/diagram-design/assets/example-it-state.html +128 -0
  79. package/vendor/diagram-design/assets/example-journey.html +148 -0
  80. package/vendor/diagram-design/assets/example-kanban.html +174 -0
  81. package/vendor/diagram-design/assets/example-layers.html +123 -0
  82. package/vendor/diagram-design/assets/example-line.html +111 -0
  83. package/vendor/diagram-design/assets/example-loop.html +100 -0
  84. package/vendor/diagram-design/assets/example-marimekko.html +148 -0
  85. package/vendor/diagram-design/assets/example-medallion.html +159 -0
  86. package/vendor/diagram-design/assets/example-nested.html +136 -0
  87. package/vendor/diagram-design/assets/example-org-chart.html +45 -0
  88. package/vendor/diagram-design/assets/example-polar.html +116 -0
  89. package/vendor/diagram-design/assets/example-process.html +64 -0
  90. package/vendor/diagram-design/assets/example-pyramid.html +119 -0
  91. package/vendor/diagram-design/assets/example-quadrant-consultant.html +166 -0
  92. package/vendor/diagram-design/assets/example-quadrant.html +135 -0
  93. package/vendor/diagram-design/assets/example-radar.html +139 -0
  94. package/vendor/diagram-design/assets/example-requirement-traceability.html +122 -0
  95. package/vendor/diagram-design/assets/example-ridgeline.html +104 -0
  96. package/vendor/diagram-design/assets/example-sankey.html +150 -0
  97. package/vendor/diagram-design/assets/example-sbgn.html +213 -0
  98. package/vendor/diagram-design/assets/example-scatter.html +141 -0
  99. package/vendor/diagram-design/assets/example-sequence-oauth.html +227 -0
  100. package/vendor/diagram-design/assets/example-sequence.html +222 -0
  101. package/vendor/diagram-design/assets/example-service-blueprint.html +185 -0
  102. package/vendor/diagram-design/assets/example-slopegraph.html +119 -0
  103. package/vendor/diagram-design/assets/example-state-lifecycle.html +92 -0
  104. package/vendor/diagram-design/assets/example-state.html +147 -0
  105. package/vendor/diagram-design/assets/example-steps.html +78 -0
  106. package/vendor/diagram-design/assets/example-story-map.html +184 -0
  107. package/vendor/diagram-design/assets/example-streamgraph.html +99 -0
  108. package/vendor/diagram-design/assets/example-swimlane.html +172 -0
  109. package/vendor/diagram-design/assets/example-timeline.html +135 -0
  110. package/vendor/diagram-design/assets/example-tree-block-decomposition.html +151 -0
  111. package/vendor/diagram-design/assets/example-tree.html +173 -0
  112. package/vendor/diagram-design/assets/example-treemap.html +107 -0
  113. package/vendor/diagram-design/assets/example-uml-class.html +188 -0
  114. package/vendor/diagram-design/assets/example-unit-grid.html +141 -0
  115. package/vendor/diagram-design/assets/example-venn.html +110 -0
  116. package/vendor/diagram-design/assets/example-wardley.html +153 -0
  117. package/vendor/diagram-design/assets/example-waterfall.html +129 -0
  118. package/vendor/diagram-design/assets/template-dark.html +99 -0
  119. package/vendor/diagram-design/assets/template.html +100 -0
  120. package/vendor/diagram-design/references/layout-budget.md +103 -0
  121. package/vendor/diagram-design/references/output-spec.md +277 -0
  122. package/vendor/diagram-design/references/primitive-annotation.md +36 -0
  123. package/vendor/diagram-design/references/primitive-sketchy.md +43 -0
  124. package/vendor/diagram-design/references/primitives-core.md +146 -0
  125. package/vendor/diagram-design/references/semantic-patterns.md +154 -0
  126. package/vendor/diagram-design/references/style-guide.md +234 -0
  127. package/vendor/diagram-design/references/type-architecture-delta.md +143 -0
  128. package/vendor/diagram-design/references/type-architecture.md +117 -0
  129. package/vendor/diagram-design/references/type-axonometric-plan.md +83 -0
  130. package/vendor/diagram-design/references/type-bar.md +108 -0
  131. package/vendor/diagram-design/references/type-data-flow.md +371 -0
  132. package/vendor/diagram-design/references/type-db-schema.md +48 -0
  133. package/vendor/diagram-design/references/type-dependency.md +113 -0
  134. package/vendor/diagram-design/references/type-deployment.md +45 -0
  135. package/vendor/diagram-design/references/type-dp-integration.md +407 -0
  136. package/vendor/diagram-design/references/type-dp-security-matrix.md +379 -0
  137. package/vendor/diagram-design/references/type-er.md +25 -0
  138. package/vendor/diagram-design/references/type-event-modeling.md +36 -0
  139. package/vendor/diagram-design/references/type-exploded.md +115 -0
  140. package/vendor/diagram-design/references/type-fishbone.md +75 -0
  141. package/vendor/diagram-design/references/type-flowchart.md +23 -0
  142. package/vendor/diagram-design/references/type-gantt.md +45 -0
  143. package/vendor/diagram-design/references/type-heatmap.md +80 -0
  144. package/vendor/diagram-design/references/type-high-level.md +470 -0
  145. package/vendor/diagram-design/references/type-it-state.md +468 -0
  146. package/vendor/diagram-design/references/type-journey.md +55 -0
  147. package/vendor/diagram-design/references/type-kanban.md +49 -0
  148. package/vendor/diagram-design/references/type-layers.md +26 -0
  149. package/vendor/diagram-design/references/type-line.md +337 -0
  150. package/vendor/diagram-design/references/type-loop.md +223 -0
  151. package/vendor/diagram-design/references/type-medallion.md +356 -0
  152. package/vendor/diagram-design/references/type-nested.md +22 -0
  153. package/vendor/diagram-design/references/type-org-chart.md +44 -0
  154. package/vendor/diagram-design/references/type-polar.md +136 -0
  155. package/vendor/diagram-design/references/type-process.md +490 -0
  156. package/vendor/diagram-design/references/type-pyramid.md +33 -0
  157. package/vendor/diagram-design/references/type-quadrant.md +81 -0
  158. package/vendor/diagram-design/references/type-radar.md +82 -0
  159. package/vendor/diagram-design/references/type-requirement-traceability.md +45 -0
  160. package/vendor/diagram-design/references/type-sankey.md +75 -0
  161. package/vendor/diagram-design/references/type-sbgn.md +80 -0
  162. package/vendor/diagram-design/references/type-scatter.md +276 -0
  163. package/vendor/diagram-design/references/type-sequence.md +130 -0
  164. package/vendor/diagram-design/references/type-service-blueprint.md +103 -0
  165. package/vendor/diagram-design/references/type-state.md +30 -0
  166. package/vendor/diagram-design/references/type-steps.md +180 -0
  167. package/vendor/diagram-design/references/type-story-map.md +46 -0
  168. package/vendor/diagram-design/references/type-swimlane.md +22 -0
  169. package/vendor/diagram-design/references/type-timeline.md +20 -0
  170. package/vendor/diagram-design/references/type-tree.md +24 -0
  171. package/vendor/diagram-design/references/type-treemap.md +137 -0
  172. package/vendor/diagram-design/references/type-uml-class.md +65 -0
  173. package/vendor/diagram-design/references/type-unit-grid.md +63 -0
  174. package/vendor/diagram-design/references/type-venn.md +26 -0
  175. package/vendor/diagram-design/references/type-wardley.md +39 -0
  176. package/vendor/diagram-design/references/type-waterfall.md +75 -0
  177. package/vendor/diagram-design/scripts/self_check.py +1177 -0
  178. package/vendor/diagram-design/scripts/verify_geometry.py +696 -0
@@ -0,0 +1,207 @@
1
+ // History cold start (spec §5.9): one model call over a digest of your Claude Code history proposes a first
2
+ // taste.md and a few suggested cards. Nothing is added until you accept it. Every proposal must cite your
3
+ // sessions, and the citations are checked against the digest, so the model can't invent evidence.
4
+ import { existsSync, rmSync, writeFileSync } from 'node:fs';
5
+ import { addCard, updateBoard } from './board.js';
6
+ import { appendJsonl, homePath, readJson, writeJson } from './home.js';
7
+ import { buildDigest, pickPrompts } from './history.js';
8
+ import { insertUnderHeading, readTaste } from './taste.js';
9
+ /** A preference must show up in this many separate sessions (spec §5.8: 3 confirmations). */
10
+ export const MIN_TASTE_SESSIONS = 3;
11
+ export function coldStartPath() {
12
+ return homePath('coldstart.json');
13
+ }
14
+ export function loadColdStart() {
15
+ return readJson(coldStartPath(), null);
16
+ }
17
+ export function coldStartPrompt(digest, existing = []) {
18
+ return `Below is a digest of one developer's Claude Code sessions: their own words ("> " lines), newest
19
+ session first, and the last thing Claude said in each session. Do two jobs.
20
+
21
+ 1. TASTE: how this person likes work done. Only preferences visible in at least ${MIN_TASTE_SESSIONS} DIFFERENT sessions
22
+ (corrections like "no, ..." or "don't ..." are the strongest evidence). Write each as an instruction to
23
+ an agent, at most 20 words, e.g. "Explain in plain words, one step at a time". Scope is "Everywhere" or a
24
+ project name from the digest. Write it as the instruction itself, never about the person ("they
25
+ often ask…"). Only about how work should be done: nothing about their health,
26
+ relationships, money, identity or private life.
27
+
28
+ 2. CARDS: small tasks they would likely want an agent to do unattended while they're away, grounded in
29
+ what they said: ideas they parked ("later", "next time", "之後"), offers Claude made at the end of a
30
+ session that were never taken up, work abandoned midway, TODOs they mentioned, routines repeated often.
31
+ Each card must be one self-contained task an agent can finish in under 30 minutes inside that project
32
+ folder, with no installs, no network services, no decision only the person can make, and nothing
33
+ outward (no push, publish, send or post). Skip anything a later session shows was already done.
34
+
35
+ ${existing.length ? `Already on their board (don't propose these again, or anything that is the same task in other words):
36
+ ${existing.map((t) => `- ${t}`).join('\n')}
37
+
38
+ ` : ''}Fewer, stronger proposals beat many weak ones: at most 8 taste lines and 6 cards; empty lists are fine.
39
+
40
+ Reply with ONLY this JSON, no prose:
41
+ {"taste":[{"scope":"Everywhere","text":"...","sessions":["S3","S9","S12"]}],
42
+ "cards":[{"title":"at most 8 words","idea":"2-4 sentences, as they would write it to park the idea",
43
+ "project":"the exact folder path from the session header","why":"one sentence to them, saying 'you' (e.g. 'You said you'd add a changelog later.')",
44
+ "sessions":["S4"],"quote":"3-15 words copied exactly from that session's lines in the digest"}]}
45
+
46
+ Digest:
47
+ ${digest}`;
48
+ }
49
+ const norm = (s) => s
50
+ .toLowerCase()
51
+ .replace(/[…"“”'‘’`]/g, '')
52
+ .replace(/\s+/g, ' ')
53
+ .trim();
54
+ /** The text the model saw for one session, to check a quote against. */
55
+ function sessionText(s) {
56
+ return norm([...pickPrompts(s.prompts), s.lastReply ?? ''].join(' '));
57
+ }
58
+ function parseJson(output) {
59
+ const start = output.indexOf('{');
60
+ const end = output.lastIndexOf('}');
61
+ if (start < 0 || end <= start)
62
+ throw new Error('The model did not reply with JSON.');
63
+ return JSON.parse(output.slice(start, end + 1));
64
+ }
65
+ const str = (v, max) => (typeof v === 'string' ? v.trim().slice(0, max) : '');
66
+ const ids = (v) => (Array.isArray(v) ? [...new Set(v.filter((x) => typeof x === 'string').map((x) => x.trim().toUpperCase()))] : []);
67
+ /** Keep only proposals whose evidence is real: cited sessions exist, enough of them, quotes really said. */
68
+ export function validateProposals(raw, included, exists = existsSync) {
69
+ const byId = new Map(included.map((s) => [s.id, s]));
70
+ const projects = new Set(included.map((s) => s.project));
71
+ const dropped = { taste: 0, cards: 0 };
72
+ const taste = [];
73
+ for (const t of raw.taste ?? []) {
74
+ const o = (t ?? {});
75
+ const sessions = ids(o.sessions).filter((id) => byId.has(id));
76
+ const text = str(o.text, 200);
77
+ if (!text || sessions.length < MIN_TASTE_SESSIONS) {
78
+ dropped.taste++;
79
+ continue;
80
+ }
81
+ const lastSeen = sessions.map((id) => byId.get(id).ended).sort().pop() ?? '';
82
+ taste.push({ id: `t${taste.length + 1}`, scope: str(o.scope, 60) || 'Everywhere', text, sessions, lastSeen: lastSeen.slice(0, 10), status: 'proposed' });
83
+ if (taste.length >= 8)
84
+ break;
85
+ }
86
+ const cards = [];
87
+ for (const c of raw.cards ?? []) {
88
+ const o = (c ?? {});
89
+ const sessions = ids(o.sessions).filter((id) => byId.has(id));
90
+ const quote = str(o.quote, 300);
91
+ const project = str(o.project, 500);
92
+ const idea = str(o.idea, 1200);
93
+ const title = str(o.title, 80);
94
+ const quoted = quote.length >= 8 && sessions.some((id) => sessionText(byId.get(id)).includes(norm(quote)));
95
+ if (!title || !idea || !sessions.length || !quoted || !projects.has(project) || !exists(project)) {
96
+ dropped.cards++;
97
+ continue;
98
+ }
99
+ cards.push({ id: `c${cards.length + 1}`, title, idea, project, why: str(o.why, 300), quote, sessions, status: 'proposed' });
100
+ if (cards.length >= 6)
101
+ break;
102
+ }
103
+ return { taste, cards, dropped };
104
+ }
105
+ /** Read the digest with the model and save the proposals to coldstart.json. */
106
+ export async function runColdStart(scan, runner, opts) {
107
+ if (!scan.sessions.length)
108
+ throw new Error('No Claude Code sessions found to learn from yet. Use Claude Code for a while, then try again.');
109
+ const { text, included } = buildDigest(scan.sessions, opts.maxChars);
110
+ const result = await runner.run({ prompt: coldStartPrompt(text, opts.existing), cwd: opts.cwd, model: opts.model, tools: '', timeoutMs: 240_000 });
111
+ if (result.timedOut)
112
+ throw new Error('Reading your history timed out. Try again.');
113
+ if (result.exitCode !== 0)
114
+ throw new Error(`claude exited with ${result.exitCode}: ${result.stderr.trim().slice(0, 300)}`);
115
+ const { taste, cards: proposed, dropped } = validateProposals(parseJson(result.output), included);
116
+ // Same title as a card you already have: drop it even if the model ignored the list.
117
+ const have = new Set((opts.existing ?? []).map(norm));
118
+ const cards = proposed.filter((c) => !have.has(norm(c.title))).map((c, i) => ({ ...c, id: `c${i + 1}` }));
119
+ dropped.cards += proposed.length - cards.length;
120
+ const cs = {
121
+ generatedAt: opts.now.toISOString(),
122
+ model: opts.model,
123
+ scanned: { sessions: scan.sessions.length, included: included.length, projects: new Set(scan.sessions.map((s) => s.project)).size, from: scan.from, to: scan.to },
124
+ taste,
125
+ cards,
126
+ dropped,
127
+ };
128
+ writeJson(coldStartPath(), cs);
129
+ return cs;
130
+ }
131
+ /** Add the taste lines under their scope heading in taste.md. Your own lines are never touched. */
132
+ export function addTasteLines(text, lines) {
133
+ let out = text;
134
+ for (const t of lines)
135
+ out = insertUnderHeading(out, t.scope, `- ${t.text} (from your history · seen in ${t.sessions.length} sessions · last ${t.lastSeen})`);
136
+ return out;
137
+ }
138
+ /** Accept the chosen proposals; the rest of what's still proposed is declined (also a signal). */
139
+ export function acceptColdStart(choice, now) {
140
+ const cs = loadColdStart();
141
+ if (!cs)
142
+ throw new Error('Nothing to accept yet. Run `chompyy coldstart` first.');
143
+ const pickT = new Set(choice.taste.map((s) => s.toLowerCase()));
144
+ const pickC = new Set(choice.cards.map((s) => s.toLowerCase()));
145
+ for (const id of [...pickT, ...pickC]) {
146
+ if (![...cs.taste, ...cs.cards].some((p) => p.id === id))
147
+ throw new Error(`No proposal "${id}". See \`chompyy coldstart show\`.`);
148
+ }
149
+ const tasteNow = cs.taste.filter((t) => t.status === 'proposed' && pickT.has(t.id));
150
+ const cardsNow = cs.cards.filter((c) => c.status === 'proposed' && pickC.has(c.id));
151
+ if (tasteNow.length) {
152
+ const { path, text } = readTaste();
153
+ writeFileSync(path, addTasteLines(text, tasteNow));
154
+ }
155
+ const made = updateBoard((b) => cardsNow.map((p) => {
156
+ const card = addCard(b, p.idea, p.project, now, 'suggested');
157
+ card.title = p.title;
158
+ card.why = p.why;
159
+ card.source = 'history';
160
+ p.cardId = card.id;
161
+ return card;
162
+ }));
163
+ for (const t of cs.taste)
164
+ if (t.status === 'proposed')
165
+ t.status = pickT.has(t.id) ? 'accepted' : 'declined';
166
+ for (const c of cs.cards)
167
+ if (c.status === 'proposed')
168
+ c.status = pickC.has(c.id) ? 'accepted' : 'declined';
169
+ writeJson(coldStartPath(), cs);
170
+ appendJsonl(homePath('signals.jsonl'), {
171
+ at: now.toISOString(),
172
+ kind: 'coldstart',
173
+ accepted: { taste: tasteNow.map((t) => t.text), cards: cardsNow.map((c) => c.title) },
174
+ declined: {
175
+ taste: cs.taste.filter((t) => t.status === 'declined').map((t) => t.text),
176
+ cards: cs.cards.filter((c) => c.status === 'declined').map((c) => c.title),
177
+ },
178
+ });
179
+ return { taste: tasteNow, cards: made };
180
+ }
181
+ /** Forget the cold start's proposals. Accepted taste lines stay in taste.md, where you can edit them. */
182
+ export function forgetColdStart() {
183
+ const path = coldStartPath();
184
+ if (!existsSync(path))
185
+ return false;
186
+ rmSync(path);
187
+ return true;
188
+ }
189
+ export function formatColdStart(cs) {
190
+ const mark = (s) => (s === 'accepted' ? '✓' : s === 'declined' ? '✗' : '·');
191
+ const out = [
192
+ `Read ${cs.scanned.included} of ${cs.scanned.sessions} sessions in ${cs.scanned.projects} projects (${(cs.scanned.from ?? '').slice(0, 10)} to ${(cs.scanned.to ?? '').slice(0, 10)}).`,
193
+ '',
194
+ `Taste (each seen in ${MIN_TASTE_SESSIONS}+ sessions):`,
195
+ ...(cs.taste.length ? cs.taste.map((t) => ` ${mark(t.status)} ${t.id} [${t.scope}] ${t.text} (${t.sessions.length} sessions)`) : [' (nothing seen often enough yet)']),
196
+ '',
197
+ 'Suggested cards:',
198
+ ...(cs.cards.length
199
+ ? cs.cards.flatMap((c) => [` ${mark(c.status)} ${c.id} ${c.title} · ${c.project.split('/').pop()}`, ` why: ${c.why}`, ` you said: "${c.quote}"`])
200
+ : [' (no grounded ideas found)']),
201
+ ];
202
+ if (cs.dropped.taste || cs.dropped.cards)
203
+ out.push('', `Thrown out for weak evidence: ${cs.dropped.taste} taste, ${cs.dropped.cards} cards.`);
204
+ if ([...cs.taste, ...cs.cards].some((p) => p.status === 'proposed'))
205
+ out.push('', 'Accept with: chompyy coldstart accept --taste t1,t2 --cards c1 (the rest are declined)');
206
+ return out.join('\n');
207
+ }
package/dist/config.js ADDED
@@ -0,0 +1,89 @@
1
+ // User settings: ~/.chompyy/config.json, merged over these defaults.
2
+ import { homePath, readJson, writeJson } from './home.js';
3
+ export const DEFAULT_CONFIG = {
4
+ claudeBin: 'claude',
5
+ blueprintModel: 'haiku',
6
+ coldStartModel: 'sonnet',
7
+ pictures: true,
8
+ pictureModel: 'sonnet',
9
+ runModel: null,
10
+ cardTimeoutMin: 30,
11
+ maxTurns: 50,
12
+ min5hLeftPct: 10,
13
+ weeklyReservePct: 10,
14
+ weeklyPace: true,
15
+ permissionMode: 'acceptEdits',
16
+ permissionPrompts: 'none',
17
+ allowedTools: [
18
+ 'Read',
19
+ 'Glob',
20
+ 'Grep',
21
+ 'WebSearch',
22
+ 'WebFetch',
23
+ 'Bash(ls *)',
24
+ 'Bash(git status *)',
25
+ 'Bash(git diff *)',
26
+ 'Bash(git log *)',
27
+ 'Bash(git add *)',
28
+ 'Bash(git commit *)',
29
+ 'Bash(npm test *)',
30
+ 'Bash(npm run *)',
31
+ 'Bash(npx vitest *)',
32
+ 'Bash(pytest *)',
33
+ ],
34
+ disallowedTools: [
35
+ 'Bash(git push *)',
36
+ 'Bash(git merge *)',
37
+ 'Bash(git rebase *)',
38
+ 'Bash(git reset *)',
39
+ 'Bash(git checkout *)',
40
+ 'Bash(git switch *)',
41
+ 'Bash(git worktree *)',
42
+ 'Bash(gh *)',
43
+ 'Bash(npm publish *)',
44
+ 'Bash(curl *)',
45
+ 'Bash(rm -rf *)',
46
+ ],
47
+ sandbox: true,
48
+ sandboxAllowedDomains: [],
49
+ denyReadPaths: [
50
+ '~/.ssh',
51
+ '~/.aws',
52
+ '~/.gnupg',
53
+ '~/.config/gh',
54
+ '~/.config/gcloud',
55
+ '~/.azure',
56
+ '~/.kube',
57
+ '~/.docker',
58
+ '~/.netrc',
59
+ '~/.npmrc',
60
+ '~/.pypirc',
61
+ '~/.git-credentials',
62
+ '~/.claude/.credentials.json',
63
+ '~/Library/Keychains',
64
+ ],
65
+ independentCheck: true,
66
+ checkTimeoutMin: 10,
67
+ checkCommands: {},
68
+ loopRepeat: 5,
69
+ idleTimeoutMin: 15,
70
+ suggestedExpiryDays: 14,
71
+ quotaSource: 'api',
72
+ extraArgs: [],
73
+ distillModel: 'sonnet',
74
+ distillAfterAway: true,
75
+ lastHourTrigger: true,
76
+ lastHourMinLeftPct: 25,
77
+ bedtime: null,
78
+ bedtimeWindowMin: 60,
79
+ };
80
+ export function configPath() {
81
+ return homePath('config.json');
82
+ }
83
+ export function loadConfig() {
84
+ return { ...DEFAULT_CONFIG, ...readJson(configPath(), {}) };
85
+ }
86
+ /** Change one setting in config.json, keeping the rest of what you set. */
87
+ export function setConfig(key, value) {
88
+ writeJson(configPath(), { ...readJson(configPath(), {}), [key]: value });
89
+ }
package/dist/costs.js ADDED
@@ -0,0 +1,162 @@
1
+ // Cost ranges and trends (spec §5.4, FEATURES §5–6).
2
+ //
3
+ // Each away run records what it cost in your own currency: the % of the 5-hour window (and the week) it used,
4
+ // read from quota before and after the card. Models predict their own spend poorly (r ≤ 0.39), so a card's
5
+ // cost is a range from similar past runs, which narrows as history grows. The quota delta also counts anything
6
+ // else you did in that window at the same time, so it is an upper bound.
7
+ import { existsSync, readFileSync } from 'node:fs';
8
+ import { formatDuration } from './duration.js';
9
+ import { appendJsonl, homePath } from './home.js';
10
+ export function runsPath() {
11
+ return homePath('runs.jsonl');
12
+ }
13
+ export function readRuns() {
14
+ const path = runsPath();
15
+ if (!existsSync(path))
16
+ return [];
17
+ return readFileSync(path, 'utf8')
18
+ .split('\n')
19
+ .flatMap((l) => {
20
+ try {
21
+ return l.trim() ? [JSON.parse(l)] : [];
22
+ }
23
+ catch {
24
+ return [];
25
+ }
26
+ });
27
+ }
28
+ export function recordRun(r) {
29
+ appendJsonl(runsPath(), r);
30
+ }
31
+ /** Used points between two readings of the same window; null if it reset in between or either is unknown. */
32
+ export function usedBetween(before, after) {
33
+ if (!before || !after || before.resetsAt !== after.resetsAt)
34
+ return null;
35
+ return Math.max(0, Math.round((after.usedPct - before.usedPct) * 10) / 10);
36
+ }
37
+ const STOP = new Set('a an and the to of in for on with from by is it this that be as at or into add make write update fix use new'.split(' '));
38
+ export function words(text) {
39
+ return new Set(text
40
+ .toLowerCase()
41
+ .split(/[^\p{L}\p{N}]+/u)
42
+ .filter((w) => w.length > 2 && !STOP.has(w)));
43
+ }
44
+ export function similarity(a, b) {
45
+ if (!a.size || !b.size)
46
+ return 0;
47
+ let both = 0;
48
+ for (const w of a)
49
+ if (b.has(w))
50
+ both++;
51
+ return both / (a.size + b.size - both);
52
+ }
53
+ /** Nearest-rank percentile of sorted values. */
54
+ function percentile(sorted, p) {
55
+ const i = Math.min(sorted.length - 1, Math.max(0, Math.ceil((p / 100) * sorted.length) - 1));
56
+ return sorted[i];
57
+ }
58
+ export const MIN_SIMILARITY = 0.15;
59
+ /**
60
+ * A cost range for a card from past runs: the most similar ones (same words in title and idea, same project
61
+ * counts extra) when there are at least 3, else all runs. P10–P90 once there are 5+ runs, min–max before.
62
+ */
63
+ export function costRange(card, runs) {
64
+ const known = runs.filter((r) => r.fiveHourPct !== null && r.card !== card.id && r.status !== 'error');
65
+ if (known.length < 2)
66
+ return null;
67
+ const mine = words(`${card.title} ${card.idea}`);
68
+ const scored = known
69
+ .map((r) => ({ r, s: similarity(mine, words(`${r.title} ${r.idea}`)) + (r.cwd === card.cwd ? 0.05 : 0) }))
70
+ .filter((x) => x.s >= MIN_SIMILARITY)
71
+ .sort((a, b) => b.s - a.s)
72
+ .slice(0, 8)
73
+ .map((x) => x.r);
74
+ const basis = scored.length >= 3 ? 'similar' : 'all';
75
+ const pool = basis === 'similar' ? scored : known;
76
+ const pcts = pool.map((r) => r.fiveHourPct).sort((a, b) => a - b);
77
+ const durs = pool.map((r) => r.durationMs).sort((a, b) => a - b);
78
+ const [lo, hi] = pool.length >= 5 ? [10, 90] : [0, 100];
79
+ return {
80
+ low: percentile(pcts, lo),
81
+ high: percentile(pcts, hi),
82
+ durationLowMs: percentile(durs, lo),
83
+ durationHighMs: percentile(durs, hi),
84
+ n: pool.length,
85
+ basis,
86
+ };
87
+ }
88
+ const fmtPct = (n) => (n < 10 ? String(Math.round(n * 10) / 10) : String(Math.round(n)));
89
+ export function formatCostRange(r) {
90
+ if (!r)
91
+ return 'Cost: not known yet (needs 2 past runs)';
92
+ const pct = r.low === r.high ? `~${fmtPct(r.low)}%` : `${fmtPct(r.low)}–${fmtPct(r.high)}%`;
93
+ const dur = r.durationLowMs === r.durationHighMs ? formatDuration(r.durationLowMs) : `${formatDuration(r.durationLowMs)}–${formatDuration(r.durationHighMs)}`;
94
+ return `Cost: ${pct} of a 5h window · ${dur} (from ${r.n} ${r.basis === 'similar' ? 'similar' : 'past'} run${r.n === 1 ? '' : 's'})`;
95
+ }
96
+ export function periodStats(runs, signals, from, to) {
97
+ const inRange = (at) => {
98
+ const t = Date.parse(at);
99
+ return t >= from && t < to;
100
+ };
101
+ const rs = runs.filter((r) => inRange(r.at));
102
+ const costs = rs.filter((r) => r.fiveHourPct !== null).map((r) => r.fiveHourPct);
103
+ const sig = signals.filter((s) => inRange(s.at));
104
+ // The last decision per card counts (a card can be redone and decided again).
105
+ const decided = new Map();
106
+ for (const s of sig)
107
+ if (s.kind === 'outcome' && s.card)
108
+ decided.set(s.card, String(s.raw.outcome));
109
+ const kept = [...decided.values()].filter((o) => o === 'kept').length;
110
+ const undone = [...decided.values()].filter((o) => o === 'undone').length;
111
+ const ratings = sig.filter((s) => s.kind === 'rating' && typeof s.raw.rating === 'number').map((s) => s.raw.rating);
112
+ const ranCards = new Set(rs.map((r) => r.card));
113
+ const edits = sig.filter((s) => s.kind === 'blueprint-edit' && s.card && ranCards.has(s.card)).length;
114
+ const avg = (xs) => (xs.length ? xs.reduce((a, b) => a + b, 0) / xs.length : null);
115
+ return {
116
+ runs: rs.length,
117
+ costPerRun: avg(costs),
118
+ costRuns: costs.length,
119
+ kept,
120
+ undone,
121
+ keepRate: kept + undone ? kept / (kept + undone) : null,
122
+ ratings: ratings.length,
123
+ avgRating: avg(ratings),
124
+ editsPerCard: ranCards.size ? edits / ranCards.size : null,
125
+ };
126
+ }
127
+ const DAY = 24 * 3600_000;
128
+ /** A metric is compared only when both periods have at least this many data points. */
129
+ export const MIN_POINTS = 3;
130
+ /** "Last 7 days vs the 7 before" lines; empty when there isn't enough history to say anything honest. */
131
+ export function trendLines(runs, signals, now, days = 7) {
132
+ const end = now.getTime();
133
+ const cur = periodStats(runs, signals, end - days * DAY, end + 1);
134
+ const prev = periodStats(runs, signals, end - 2 * days * DAY, end - days * DAY);
135
+ const parts = [];
136
+ const change = (a, b) => (a ? `${b >= a ? '+' : '−'}${Math.abs(Math.round(((b - a) / a) * 100))}%` : '');
137
+ if (cur.costRuns >= MIN_POINTS && prev.costRuns >= MIN_POINTS && cur.costPerRun !== null && prev.costPerRun !== null) {
138
+ parts.push(`cost per card ${fmtPct(prev.costPerRun)}% → ${fmtPct(cur.costPerRun)}% of a 5h window (${change(prev.costPerRun, cur.costPerRun)})`);
139
+ }
140
+ if (cur.kept + cur.undone >= MIN_POINTS && prev.kept + prev.undone >= MIN_POINTS) {
141
+ parts.push(`keep rate ${Math.round(prev.keepRate * 100)}% → ${Math.round(cur.keepRate * 100)}%`);
142
+ }
143
+ if (cur.ratings >= MIN_POINTS && prev.ratings >= MIN_POINTS) {
144
+ parts.push(`rating ${prev.avgRating.toFixed(1)} → ${cur.avgRating.toFixed(1)}`);
145
+ }
146
+ if (cur.runs >= MIN_POINTS && prev.runs >= MIN_POINTS && cur.editsPerCard !== null && prev.editsPerCard !== null) {
147
+ const d = cur.editsPerCard - prev.editsPerCard;
148
+ parts.push(`blueprint edits per card ${prev.editsPerCard.toFixed(1)} → ${cur.editsPerCard.toFixed(1)} (${d <= 0 ? '−' : '+'}${Math.abs(d).toFixed(1)})`);
149
+ }
150
+ if (parts.length)
151
+ return [`📈 Last ${days} days vs the ${days} before: ${parts.join(' · ')}`];
152
+ // Not enough to compare: say what there is, if anything.
153
+ const all = periodStats(runs, signals, 0, end + 1);
154
+ if (all.runs < MIN_POINTS)
155
+ return [];
156
+ const bits = [`${all.runs} runs`];
157
+ if (all.keepRate !== null)
158
+ bits.push(`${Math.round(all.keepRate * 100)}% kept`);
159
+ if (all.costPerRun !== null)
160
+ bits.push(`~${fmtPct(all.costPerRun)}% of a 5h window per card`);
161
+ return [`📈 So far: ${bits.join(' · ')} (trends once there are two weeks to compare)`];
162
+ }
@@ -0,0 +1,36 @@
1
+ /** Parse "1h", "30m", "1h30m", "45s" or a bare number of minutes into milliseconds. */
2
+ export function parseDuration(text) {
3
+ const s = text.trim().toLowerCase();
4
+ if (/^\d+(\.\d+)?$/.test(s))
5
+ return checked(Number(s) * 60_000, text);
6
+ const re = /(\d+(?:\.\d+)?)\s*(h|m|s)/g;
7
+ let ms = 0;
8
+ let consumed = '';
9
+ for (const m of s.matchAll(re)) {
10
+ const n = Number(m[1]);
11
+ ms += m[2] === 'h' ? n * 3_600_000 : m[2] === 'm' ? n * 60_000 : n * 1000;
12
+ consumed += m[0];
13
+ }
14
+ if (consumed.replace(/\s/g, '') !== s.replace(/\s/g, ''))
15
+ throw new Error(`Can't read duration "${text}". Try 1h, 30m or 1h30m.`);
16
+ return checked(ms, text);
17
+ }
18
+ function checked(ms, text) {
19
+ if (!Number.isFinite(ms) || ms <= 0)
20
+ throw new Error(`Duration must be more than zero: "${text}"`);
21
+ return Math.round(ms);
22
+ }
23
+ /** 6000000 → "1h40m", 2400000 → "40m", 30000 → "<1m". */
24
+ export function formatDuration(ms) {
25
+ if (ms < 60_000)
26
+ return '<1m';
27
+ const totalMin = Math.floor(ms / 60_000);
28
+ const d = Math.floor(totalMin / 1440);
29
+ const h = Math.floor((totalMin % 1440) / 60);
30
+ const m = totalMin % 60;
31
+ if (d > 0)
32
+ return `${d}d${h}h`;
33
+ if (h > 0)
34
+ return m > 0 ? `${h}h${String(m).padStart(2, '0')}m` : `${h}h`;
35
+ return `${m}m`;
36
+ }
package/dist/gate.js ADDED
@@ -0,0 +1,69 @@
1
+ // Budget gate (spec §5.2): only spend what would otherwise reset; stay on an even weekly pace, hard stop at 90%.
2
+ import { windowView } from './quota.js';
3
+ /** Which per-model windows apply: the run's model if it's named, else all of them (the default may be any). */
4
+ function modelWindowsFor(snap, runModel) {
5
+ const all = Object.entries(snap?.models ?? {});
6
+ if (!runModel)
7
+ return all;
8
+ const m = runModel.toLowerCase();
9
+ return all.filter(([name]) => m.includes(name.toLowerCase()));
10
+ }
11
+ const WEEK_MS = 7 * 24 * 3600_000;
12
+ /** How far through the 7-day window we are, as a % (an even pace would have used this much). */
13
+ export function weekElapsedPct(msLeft) {
14
+ return Math.min(100, Math.max(0, (1 - msLeft / WEEK_MS) * 100));
15
+ }
16
+ export function budgetGate(snap, cfg, now) {
17
+ const reasons = [];
18
+ const notes = [];
19
+ const five = windowView(snap?.fiveHour, now);
20
+ if (!five.known) {
21
+ // A reset (or no) window means running would *start* a fresh window, which isn't leftover capacity.
22
+ reasons.push(five.reason === 'stale'
23
+ ? '5h window unknown: the snapshot is from a window that has reset'
24
+ : '5h window unknown: no quota snapshot (set up `chompyy statusline`)');
25
+ }
26
+ else if (five.usedPct >= 100) {
27
+ // Whatever the settings say: past 100% a plan with extra usage turned on starts billing.
28
+ reasons.push('5h window is used up: running now would spill into paid extra usage');
29
+ }
30
+ else if (five.leftPct < cfg.min5hLeftPct) {
31
+ reasons.push(`5h window has ${Math.round(five.leftPct)}% left, under the ${cfg.min5hLeftPct}% minimum`);
32
+ }
33
+ const week = windowView(snap?.sevenDay, now);
34
+ const maxWeeklyUsed = 100 - cfg.weeklyReservePct;
35
+ if (!week.known) {
36
+ notes.push('weekly usage unknown; reserve not checked');
37
+ }
38
+ else if (week.usedPct >= 100) {
39
+ reasons.push('weekly limit is used up: running now would spill into paid extra usage');
40
+ }
41
+ else if (week.usedPct > maxWeeklyUsed) {
42
+ reasons.push(`weekly usage is ${Math.round(week.usedPct)}%, over the ${maxWeeklyUsed}% hard stop`);
43
+ }
44
+ else if (cfg.weeklyPace) {
45
+ // Spend only what you haven't used so far this week; never borrow from the days ahead.
46
+ const pace = weekElapsedPct(week.msLeft);
47
+ if (week.usedPct > pace) {
48
+ reasons.push(`ahead of pace this week: ${Math.round(week.usedPct)}% used, an even pace is ${Math.round(pace)}% by now`);
49
+ }
50
+ else {
51
+ notes.push(`${Math.round(pace - week.usedPct)}% of the week unspent so far (${Math.round(week.usedPct)}% used, even pace ${Math.round(pace)}%)`);
52
+ }
53
+ }
54
+ // Per-model weekly limits (e.g. Opus has its own 7-day window).
55
+ for (const [name, w] of modelWindowsFor(snap, cfg.runModel)) {
56
+ const v = windowView(w, now);
57
+ if (!v.known)
58
+ continue;
59
+ if (v.usedPct >= 100)
60
+ reasons.push(`weekly ${name} limit is used up: running now would spill into paid extra usage`);
61
+ else if (v.usedPct > maxWeeklyUsed) {
62
+ if (cfg.runModel)
63
+ reasons.push(`weekly ${name} usage is ${Math.round(v.usedPct)}%, over the ${maxWeeklyUsed}% hard stop`);
64
+ else
65
+ notes.push(`weekly ${name} usage is ${Math.round(v.usedPct)}%; away runs use Claude Code's default model, which may be ${name}`);
66
+ }
67
+ }
68
+ return { ok: reasons.length === 0, reasons, notes };
69
+ }