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,308 @@
1
+ // Reads your Claude Code history for the cold start (spec §5.9). Runs locally and changes nothing.
2
+ // From each interactive session it keeps only: the folder, the dates, what you typed (cleaned, secrets
3
+ // removed) and the last thing Claude said. Headless runs (Chompyy's own, benchmarks, scripts) are skipped.
4
+ import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from 'node:fs';
5
+ import { homedir } from 'node:os';
6
+ import { basename, join } from 'node:path';
7
+ import { findGitRoot, isTemp } from './projects.js';
8
+ // ---------- redaction ----------
9
+ const SECRET_PATTERNS = [
10
+ [/-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?(-----END [A-Z ]*PRIVATE KEY-----|$)/g, '[secret]'],
11
+ [/\bsk-(ant-)?[A-Za-z0-9_-]{16,}/g, '[secret]'],
12
+ [/\b(ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{20,}/g, '[secret]'],
13
+ [/\bgithub_pat_[A-Za-z0-9_]{20,}/g, '[secret]'],
14
+ [/\bnpm_[A-Za-z0-9]{30,}/g, '[secret]'],
15
+ [/\bAKIA[0-9A-Z]{16}\b/g, '[secret]'],
16
+ [/\bAIza[0-9A-Za-z_-]{35}\b/g, '[secret]'],
17
+ [/\bxox[abprs]-[A-Za-z0-9-]{10,}/g, '[secret]'],
18
+ [/\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/g, '[secret]'], // JWT
19
+ [/\b(sk|rk|pk)_(live|test)_[A-Za-z0-9]{16,}/g, '[secret]'], // Stripe
20
+ [/\bglpat-[A-Za-z0-9_-]{20,}/g, '[secret]'], // GitLab
21
+ [/\bhf_[A-Za-z0-9]{30,}/g, '[secret]'], // Hugging Face
22
+ [/\bya29\.[A-Za-z0-9_-]{20,}/g, '[secret]'], // Google OAuth access token
23
+ [/\b(AccountKey|SharedAccessSignature|sig)=[A-Za-z0-9%+/=]{20,}/g, '[secret]'], // Azure
24
+ [/https:\/\/hooks\.slack\.com\/services\/[A-Za-z0-9/]+/g, '[secret]'],
25
+ [/https:\/\/(discord(app)?\.com)\/api\/webhooks\/[A-Za-z0-9/_-]+/g, '[secret]'],
26
+ // user:password@ in a URL: keep the scheme and host so the sentence still reads
27
+ [/\b([a-z][a-z0-9+.-]*:\/\/)[^\s/:@]+:[^\s/@]+@/gi, (_m, scheme) => `${scheme}[secret]@`],
28
+ [/\b(Bearer|Basic)\s+[A-Za-z0-9._~+/=-]{16,}/g, (_m, kind) => `${kind} [secret]`],
29
+ // keep "password=" so the sentence still reads
30
+ [/\b(password|passwd|pwd|secret|token|api[_-]?key|access[_-]?key)(\s*[:=]\s*)("[^"]*"|'[^']*'|[^\s,;]+)/gi, (_m, name, sep) => `${name}${sep}[secret]`],
31
+ // long random-looking strings (mixed case and digits), not paths or slugs
32
+ [/[A-Za-z0-9+_=-]{32,}/g, (m) => (/[a-z]/.test(m) && /[A-Z]/.test(m) && /\d/.test(m) && (m.match(/-/g)?.length ?? 0) < 3 ? '[secret]' : m)],
33
+ [/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g, '[email]'],
34
+ // phone numbers: +44 20 7946 0958, (415) 555-0132, 415-555-0132
35
+ [/(\+\d{1,3}[\s.-]?)?(\(\d{2,4}\)[\s.-]?|\b\d{2,4}[\s.-])\d{3,4}[\s.-]\d{3,4}\b/g, '[phone]'],
36
+ ];
37
+ // ---------- pastes without markers ----------
38
+ /** How much a line looks machine-made (log, stack trace, code, diff, JSON) rather than typed by a person. */
39
+ function machineLine(line) {
40
+ const t = line.trim();
41
+ if (!t)
42
+ return false;
43
+ return (/^\s*at\s+\S.*(\(|:\d+)/.test(line) || // JS/Java stack frame
44
+ /^\s*File ".*", line \d+/.test(line) || /^Traceback \(most recent call last\)/.test(t) ||
45
+ /^\d{4}-\d\d-\d\d[T ]\d\d:\d\d/.test(t) || /^\[?\d\d:\d\d:\d\d/.test(t) || // timestamped log
46
+ /^\[?(INFO|WARN|WARNING|ERROR|DEBUG|TRACE|FATAL)\b/.test(t) ||
47
+ /^(\+\+\+|---|@@|diff --git|index [0-9a-f]+)/.test(t) || /^[+-](?![+-])\S/.test(t) || // diff
48
+ /^[{}\[\]],?$/.test(t) || /^"[^"]+":\s/.test(t) || // JSON
49
+ /[;{}]$/.test(t) || /^(import|export|from|def|class|function|const|let|var|return|if|for|while|#include|package|func|fn|pub|use)\b.*[({:=;]/.test(t) ||
50
+ /^(\$|>>>|PS [A-Z]:\\|❯)\s/.test(t) || // shell or REPL prompt
51
+ /^\s{4,}\S/.test(line) || /^\t+\S/.test(line) || // indented block
52
+ /^[\w.-]+:\d+(:\d+)?\b/.test(t) // file:line
53
+ );
54
+ }
55
+ /**
56
+ * Replace pasted material that came in without Claude Code's paste markers: fenced code blocks, runs of 3+
57
+ * machine-made lines (logs, stack traces, code, diffs, JSON), and very long unbroken lines. Must run before
58
+ * whitespace is collapsed, because line breaks are what give a paste away.
59
+ */
60
+ export function stripUnmarkedPastes(text) {
61
+ let out = text.replace(/```[\s\S]*?(```|$)/g, '\n[pasted text]\n');
62
+ const lines = out.split('\n');
63
+ const kept = [];
64
+ for (let i = 0; i < lines.length;) {
65
+ // Grow a block while most of its lines look machine-made (a blank or odd line inside is allowed).
66
+ let j = i;
67
+ let machine = 0;
68
+ while (j < lines.length) {
69
+ const isMachine = machineLine(lines[j]);
70
+ const blank = !lines[j].trim();
71
+ if (!isMachine && !blank && (j - i < 1 || machine / (j - i + 1) < 0.6))
72
+ break;
73
+ if (isMachine)
74
+ machine++;
75
+ j++;
76
+ }
77
+ // Don't end a block on a typed line: give trailing non-machine lines back.
78
+ while (j > i && !machineLine(lines[j - 1]))
79
+ j--;
80
+ if (machine >= 3) {
81
+ if (kept.at(-1) !== '[pasted text]')
82
+ kept.push('[pasted text]');
83
+ i = j;
84
+ continue;
85
+ }
86
+ const line = lines[i];
87
+ // One long line with few spaces: minified code, base64, a URL dump, a log line.
88
+ const spaces = (line.match(/\s/g) ?? []).length;
89
+ kept.push(line.length > 400 && spaces / line.length < 0.08 ? '[pasted text]' : line);
90
+ i++;
91
+ }
92
+ return kept.join('\n');
93
+ }
94
+ /** Remove things that look like secrets or personal contact details. */
95
+ export function redact(text) {
96
+ let out = text;
97
+ for (const [re, to] of SECRET_PATTERNS)
98
+ out = typeof to === 'string' ? out.replace(re, to) : out.replace(re, to);
99
+ return out;
100
+ }
101
+ // ---------- reading one transcript ----------
102
+ /** Turn a user message into what you actually typed, or null if it isn't something you typed. */
103
+ export function cleanPrompt(content) {
104
+ let text;
105
+ if (typeof content === 'string')
106
+ text = content;
107
+ else if (Array.isArray(content)) {
108
+ // Arrays hold tool results or text blocks; only plain text blocks are typed words.
109
+ if (content.some((b) => b && typeof b === 'object' && b.type === 'tool_result'))
110
+ return null;
111
+ text = content
112
+ .filter((b) => b && typeof b === 'object' && b.type === 'text')
113
+ .map((b) => b.text ?? '')
114
+ .join('\n');
115
+ }
116
+ else
117
+ return null;
118
+ // A slash command arrives as tags: keep it as "/name args".
119
+ const cmd = text.match(/<command-name>([^<]*)<\/command-name>/);
120
+ if (cmd) {
121
+ const args = text.match(/<command-args>([\s\S]*?)<\/command-args>/)?.[1]?.trim() ?? '';
122
+ const name = cmd[1].trim();
123
+ return name ? `${name.startsWith('/') ? name : `/${name}`}${args ? ` ${args}` : ''}` : null;
124
+ }
125
+ if (/^\s*<(local-command|bash-|system-reminder|task-notification|user-prompt-submit-hook)/.test(text))
126
+ return null;
127
+ if (/^\s*(Caveat:|\[Request interrupted|This session is being continued from a previous conversation)/.test(text))
128
+ return null;
129
+ text = text
130
+ .replace(/<pasted_content[^>]*>[\s\S]*?<\/pasted_content[^>]*>/g, '[pasted text]')
131
+ .replace(/<system-reminder>[\s\S]*?<\/system-reminder>/g, '');
132
+ text = stripUnmarkedPastes(text)
133
+ .replace(/\[Image[^\]]*\]/g, '[image]')
134
+ .replace(/\s+/g, ' ')
135
+ .trim();
136
+ return text ? text : null;
137
+ }
138
+ function textOf(content) {
139
+ if (typeof content === 'string')
140
+ return content;
141
+ if (!Array.isArray(content))
142
+ return '';
143
+ return content
144
+ .filter((b) => b && typeof b === 'object' && b.type === 'text')
145
+ .map((b) => b.text ?? '')
146
+ .join('\n');
147
+ }
148
+ export function parseTranscript(raw) {
149
+ const p = { entrypoint: null, cwd: null, started: null, ended: null, prompts: [], lastReply: null };
150
+ for (const line of raw.split('\n')) {
151
+ if (!line.trim())
152
+ continue;
153
+ let o;
154
+ try {
155
+ o = JSON.parse(line);
156
+ }
157
+ catch {
158
+ continue;
159
+ }
160
+ if (!p.entrypoint && typeof o.entrypoint === 'string')
161
+ p.entrypoint = o.entrypoint;
162
+ if (!p.cwd && typeof o.cwd === 'string')
163
+ p.cwd = o.cwd;
164
+ if (typeof o.timestamp === 'string') {
165
+ p.started ??= o.timestamp;
166
+ p.ended = o.timestamp;
167
+ }
168
+ if (o.isSidechain || o.isMeta || o.isCompactSummary)
169
+ continue;
170
+ const message = o.message;
171
+ if (o.type === 'user') {
172
+ const typed = cleanPrompt(message?.content);
173
+ if (typed)
174
+ p.prompts.push(typed);
175
+ }
176
+ else if (o.type === 'assistant') {
177
+ const t = textOf(message?.content).trim();
178
+ if (t)
179
+ p.lastReply = t;
180
+ }
181
+ }
182
+ return p;
183
+ }
184
+ // ---------- scanning all of it ----------
185
+ /** Read every interactive Claude Code session on this Mac, newest first. */
186
+ export function scanHistory(opts = {}) {
187
+ const temp = opts.isTemp ?? isTemp;
188
+ const claudeDir = opts.claudeDir ?? join(homedir(), '.claude', 'projects');
189
+ const scan = { sessions: [], skipped: { headless: 0, temp: 0, empty: 0, unreadable: 0 }, from: null, to: null };
190
+ if (!existsSync(claudeDir))
191
+ return scan;
192
+ const files = [];
193
+ for (const dir of readdirSync(claudeDir, { withFileTypes: true })) {
194
+ if (!dir.isDirectory())
195
+ continue;
196
+ const folder = join(claudeDir, dir.name);
197
+ for (const f of readdirSync(folder)) {
198
+ if (!f.endsWith('.jsonl'))
199
+ continue;
200
+ try {
201
+ files.push({ file: join(folder, f), mtime: statSync(join(folder, f)).mtimeMs });
202
+ }
203
+ catch { }
204
+ }
205
+ }
206
+ files.sort((a, b) => b.mtime - a.mtime);
207
+ const found = [];
208
+ for (const { file } of files) {
209
+ if (opts.maxSessions && found.length >= opts.maxSessions)
210
+ break;
211
+ let parsed;
212
+ try {
213
+ parsed = parseTranscript(readFileSync(file, 'utf8'));
214
+ }
215
+ catch {
216
+ scan.skipped.unreadable++;
217
+ continue;
218
+ }
219
+ // Headless runs (`claude -p`, SDK) are agents talking, not you.
220
+ if (parsed.entrypoint === 'sdk-cli' || parsed.entrypoint === 'sdk-ts' || parsed.entrypoint === 'sdk-py') {
221
+ scan.skipped.headless++;
222
+ continue;
223
+ }
224
+ if (!parsed.cwd || temp(parsed.cwd) || parsed.cwd.includes('/.branchwork/')) {
225
+ scan.skipped.temp++;
226
+ continue;
227
+ }
228
+ if (parsed.prompts.length === 0) {
229
+ scan.skipped.empty++;
230
+ continue;
231
+ }
232
+ let project = parsed.cwd;
233
+ const root = existsSync(parsed.cwd) ? findGitRoot(parsed.cwd) : null;
234
+ if (root && root !== homedir()) {
235
+ try {
236
+ project = realpathSync.native(root);
237
+ }
238
+ catch {
239
+ project = root;
240
+ }
241
+ }
242
+ found.push({
243
+ file,
244
+ cwd: parsed.cwd,
245
+ project,
246
+ projectName: basename(project),
247
+ started: parsed.started ?? '',
248
+ ended: parsed.ended ?? '',
249
+ prompts: parsed.prompts.map(redact),
250
+ lastReply: parsed.lastReply ? redact(parsed.lastReply) : null,
251
+ });
252
+ }
253
+ found.sort((a, b) => b.ended.localeCompare(a.ended));
254
+ scan.sessions = found.map((s, i) => ({ id: `S${i + 1}`, ...s }));
255
+ const times = found.flatMap((s) => [s.started, s.ended]).filter(Boolean).sort();
256
+ scan.from = times[0] ?? null;
257
+ scan.to = times[times.length - 1] ?? null;
258
+ return scan;
259
+ }
260
+ // ---------- the digest sent to the model ----------
261
+ /** Words that mark an idea for later, in English and Chinese. */
262
+ const LATER = /\b(later|todo|to-do|next time|someday|some day|remind me|come back|eventually|follow[- ]up|not now|backlog|park|wishlist|nice to have)\b|之後|以後|下次|有空|待辦|晚點|再來|改天/i;
263
+ /** Words that mark a correction: the clearest taste evidence. */
264
+ const CORRECTION = /^(no\b|nope|don'?t|do not|stop|instead|actually|wrong|that'?s not|not what|please don'?t|never)|不要|不是|別|改成|太長|太多/i;
265
+ const clip = (s, n) => (s.length > n ? `${s.slice(0, n - 1)}…` : s);
266
+ /** Which prompts of a session go in the digest: the start, ideas for later, corrections, and the end. */
267
+ export function pickPrompts(prompts, max = 14) {
268
+ const keep = new Set();
269
+ const add = (i) => {
270
+ if (i >= 0 && i < prompts.length && keep.size < max)
271
+ keep.add(i);
272
+ };
273
+ [0, 1, 2].forEach(add);
274
+ prompts.forEach((p, i) => LATER.test(p) && add(i));
275
+ prompts.forEach((p, i) => CORRECTION.test(p) && add(i));
276
+ [prompts.length - 3, prompts.length - 2, prompts.length - 1].forEach(add);
277
+ return [...keep].sort((a, b) => a - b).map((i) => prompts[i]);
278
+ }
279
+ /** The digest: one block per session, newest first, until the size cap. */
280
+ export function buildDigest(sessions, maxChars = 60_000) {
281
+ const blocks = [];
282
+ const included = [];
283
+ let size = 0;
284
+ for (const s of sessions) {
285
+ const lines = [
286
+ `### ${s.id} · ${s.projectName} (${s.project}) · ${s.ended.slice(0, 10)} · ${s.prompts.length} prompts`,
287
+ ...pickPrompts(s.prompts).map((p) => `> ${clip(p, 300)}`),
288
+ ...(s.lastReply ? [`Claude ended with: ${clip(s.lastReply.replace(/\s+/g, ' '), 450)}`] : []),
289
+ ];
290
+ const block = lines.join('\n');
291
+ if (size + block.length > maxChars && included.length > 0)
292
+ break;
293
+ blocks.push(block);
294
+ included.push(s);
295
+ size += block.length + 2;
296
+ }
297
+ return { text: blocks.join('\n\n'), included };
298
+ }
299
+ /** How long Claude Code keeps transcripts (`cleanupPeriodDays`, default 30). */
300
+ export function historyRetention(settingsPath = join(homedir(), '.claude', 'settings.json')) {
301
+ try {
302
+ const s = JSON.parse(readFileSync(settingsPath, 'utf8'));
303
+ if (typeof s.cleanupPeriodDays === 'number')
304
+ return { days: s.cleanupPeriodDays, isDefault: false };
305
+ }
306
+ catch { }
307
+ return { days: 30, isDefault: true };
308
+ }
package/dist/home.js ADDED
@@ -0,0 +1,34 @@
1
+ // All Chompyy state lives in one folder of plain files: ~/.chompyy/ (or $CHOMPYY_HOME).
2
+ import { appendFileSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
3
+ import { homedir } from 'node:os';
4
+ import { dirname, join } from 'node:path';
5
+ export function chompyyHome() {
6
+ return process.env.CHOMPYY_HOME || join(homedir(), '.chompyy');
7
+ }
8
+ /** Path inside the Chompyy home. Creates the parent folder. */
9
+ export function homePath(...parts) {
10
+ const path = join(chompyyHome(), ...parts);
11
+ mkdirSync(dirname(path), { recursive: true });
12
+ return path;
13
+ }
14
+ export function readJson(path, fallback) {
15
+ if (!existsSync(path))
16
+ return fallback;
17
+ try {
18
+ return JSON.parse(readFileSync(path, 'utf8'));
19
+ }
20
+ catch {
21
+ return fallback;
22
+ }
23
+ }
24
+ /** Write via a temp file and rename, so a crash or a parallel reader never sees half a file. */
25
+ export function writeJson(path, data) {
26
+ mkdirSync(dirname(path), { recursive: true });
27
+ const tmp = `${path}.${process.pid}.tmp`;
28
+ writeFileSync(tmp, JSON.stringify(data, null, 2) + '\n');
29
+ renameSync(tmp, path);
30
+ }
31
+ export function appendJsonl(path, record) {
32
+ mkdirSync(dirname(path), { recursive: true });
33
+ appendFileSync(path, JSON.stringify(record) + '\n');
34
+ }
@@ -0,0 +1,92 @@
1
+ // Live Claude quota from Anthropic's usage endpoint, via codeburn's reader (src/vendor/codeburn).
2
+ // Uses the login Claude Code already saved (macOS Keychain or ~/.claude/.credentials.json).
3
+ // It sends no message, so it never starts a 5-hour window. Chosen over the status-line
4
+ // snapshot on 2026-11-15 because it is fresh even when no Claude Code session is open.
5
+ import { fetchClaudeQuota } from './vendor/codeburn/claude.js';
6
+ import { homePath, readJson, writeJson } from './home.js';
7
+ import { loadSnapshot, mergeSnapshot, saveSnapshot } from './quota.js';
8
+ /** Don't ask the endpoint more often than this. */
9
+ export const MIN_INTERVAL_MS = 5 * 60_000;
10
+ const statePath = () => homePath('livequota.json');
11
+ export const loadLiveState = () => readJson(statePath(), {});
12
+ function windowFrom(provider, label) {
13
+ const row = provider.details.find((d) => d.label === label);
14
+ if (!row || !row.resetsAt)
15
+ return undefined;
16
+ return { usedPct: Math.round(row.percent * 1000) / 10, resetsAt: Math.floor(Date.parse(row.resetsAt) / 1000) };
17
+ }
18
+ /** Turn codeburn's provider result into Chompyy's snapshot shape. */
19
+ export function snapshotFromProvider(provider, now) {
20
+ if (provider.connection !== 'connected')
21
+ return null;
22
+ const snap = { capturedAt: now.toISOString(), source: 'api' };
23
+ const five = windowFrom(provider, '5-hour');
24
+ const week = windowFrom(provider, 'Weekly');
25
+ if (five)
26
+ snap.fiveHour = five;
27
+ if (week)
28
+ snap.sevenDay = week;
29
+ // Per-model weekly windows ("Weekly · Opus", "Weekly · Sonnet", …).
30
+ const models = {};
31
+ for (const row of provider.details) {
32
+ const name = row.label.startsWith('Weekly · ') ? row.label.slice('Weekly · '.length) : '';
33
+ const w = name ? windowFrom(provider, row.label) : undefined;
34
+ if (w)
35
+ models[name] = w;
36
+ }
37
+ if (Object.keys(models).length)
38
+ snap.models = models;
39
+ return snap;
40
+ }
41
+ /**
42
+ * Refresh the snapshot from the endpoint. `force` skips the 5-minute spacing (not a 429 backoff).
43
+ * `allowKeychain` lets macOS show its one-time "allow access to the Claude Code login?" prompt.
44
+ */
45
+ export async function refreshLiveQuota(opts = {}) {
46
+ const now = opts.now ?? new Date();
47
+ const state = loadLiveState();
48
+ const current = loadSnapshot();
49
+ if (state.retryAfterAt && Date.parse(state.retryAfterAt) > now.getTime()) {
50
+ return { ok: false, snapshot: current, message: `Anthropic limits how often quota can be checked; next check after ${hhmm(state.retryAfterAt)}.` };
51
+ }
52
+ if (!opts.force && state.lastTryAt && now.getTime() - Date.parse(state.lastTryAt) < MIN_INTERVAL_MS && current?.source === 'api') {
53
+ return { ok: true, snapshot: current, message: 'Fresh enough.' };
54
+ }
55
+ const fetchQuota = opts.fetchQuota ?? ((o) => fetchClaudeQuota(o));
56
+ const result = await fetchQuota({ allowKeychain: opts.allowKeychain ?? true });
57
+ const next = {
58
+ lastTryAt: now.toISOString(),
59
+ connection: result.quota.connection,
60
+ plan: result.quota.planLabel,
61
+ };
62
+ if (result.retryAfterSeconds)
63
+ next.retryAfterAt = new Date(now.getTime() + result.retryAfterSeconds * 1000).toISOString();
64
+ const snap = snapshotFromProvider(result.quota, now);
65
+ if (!snap) {
66
+ next.note = result.quota.footerLines.join(' ') || result.quota.connection;
67
+ writeJson(statePath(), next);
68
+ // A 429: other tools signed in with the same Claude login (or a recent check) used up the allowance.
69
+ if (next.retryAfterAt)
70
+ return { ok: false, snapshot: current, message: `Anthropic limits how often quota can be checked; next check after ${hhmm(next.retryAfterAt)}.` };
71
+ return { ok: false, snapshot: current, message: explain(result.quota) };
72
+ }
73
+ const merged = mergeSnapshot(current, snap);
74
+ saveSnapshot(merged);
75
+ writeJson(statePath(), next);
76
+ return { ok: true, snapshot: merged, message: `Updated from Anthropic${result.quota.planLabel ? ` (${result.quota.planLabel})` : ''}.` };
77
+ }
78
+ const hhmm = (iso) => new Date(iso).toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' });
79
+ function explain(p) {
80
+ const extra = p.footerLines.length ? ` ${p.footerLines.join(' ')}` : '';
81
+ switch (p.connection) {
82
+ case 'accessDenied':
83
+ return `macOS didn't allow reading the Claude Code login.${extra}`;
84
+ case 'keychainUnchecked':
85
+ case 'disconnected':
86
+ return 'No Claude Code login found. Sign in to Claude Code once, then try again.';
87
+ case 'terminalFailure':
88
+ return `Anthropic refused the request.${extra}`;
89
+ default:
90
+ return `Couldn't reach Anthropic right now.${extra}`;
91
+ }
92
+ }
package/dist/macapp.js ADDED
@@ -0,0 +1,57 @@
1
+ // `chompyy app`: download the Mac app from this version's GitHub Release into ~/Applications and open it.
2
+ // The app is a thin window over this CLI, so the two versions are kept in step.
3
+ import { execFileSync } from 'node:child_process';
4
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
5
+ import { homedir, tmpdir } from 'node:os';
6
+ import { dirname, join } from 'node:path';
7
+ import { fileURLToPath } from 'node:url';
8
+ export const REPO = 'BranchWork-HQ/Chompyy';
9
+ /** The CLI's own version, from its package.json. */
10
+ export function cliVersion() {
11
+ const pkg = join(dirname(fileURLToPath(import.meta.url)), '..', 'package.json');
12
+ return JSON.parse(readFileSync(pkg, 'utf8')).version;
13
+ }
14
+ export function appZipUrl(version) {
15
+ return `https://github.com/${REPO}/releases/download/v${version}/Chompyy-${version}.zip`;
16
+ }
17
+ const defaultDeps = () => ({
18
+ fetch: (url) => fetch(url),
19
+ exec: (cmd, args) => {
20
+ execFileSync(cmd, args, { stdio: 'ignore' });
21
+ },
22
+ platform: process.platform,
23
+ appsDir: join(homedir(), 'Applications'),
24
+ });
25
+ /** Install (or update) Chompyy.app. Returns where it went. */
26
+ export async function installApp(opts = {}, deps = defaultDeps()) {
27
+ if (deps.platform !== 'darwin')
28
+ throw new Error('The Chompyy app is macOS only for now. The CLI works everywhere: `chompyy help`.');
29
+ const version = opts.version ?? cliVersion();
30
+ const url = appZipUrl(version);
31
+ const res = await deps.fetch(url);
32
+ if (!res.ok)
33
+ throw new Error(`Couldn't download the app (HTTP ${res.status}) from ${url}`);
34
+ const tmp = mkdtempSync(join(tmpdir(), 'chompyy-app-'));
35
+ try {
36
+ const zip = join(tmp, 'Chompyy.zip');
37
+ writeFileSync(zip, Buffer.from(await res.arrayBuffer()));
38
+ deps.exec('ditto', ['-x', '-k', zip, tmp]);
39
+ const unpacked = join(tmp, 'Chompyy.app');
40
+ if (!existsSync(unpacked))
41
+ throw new Error('The download had no Chompyy.app in it.');
42
+ mkdirSync(deps.appsDir, { recursive: true });
43
+ const target = join(deps.appsDir, 'Chompyy.app');
44
+ try {
45
+ deps.exec('pkill', ['-x', 'Chompyy']); // an older copy may be running
46
+ }
47
+ catch { }
48
+ rmSync(target, { recursive: true, force: true });
49
+ renameSync(unpacked, target);
50
+ if (opts.open !== false)
51
+ deps.exec('open', [target]);
52
+ return target;
53
+ }
54
+ finally {
55
+ rmSync(tmp, { recursive: true, force: true });
56
+ }
57
+ }