chompyy 0.1.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -8
- package/THIRD_PARTY_NOTICES.md +29 -1
- package/dist/appstate.js +121 -4
- package/dist/away.js +191 -25
- package/dist/blueprint.js +102 -7
- package/dist/board.js +143 -15
- package/dist/catalog.js +81 -0
- package/dist/claudesettings.js +23 -0
- package/dist/cli.js +804 -55
- package/dist/coldstart.js +208 -0
- package/dist/config.js +43 -8
- package/dist/costs.js +162 -0
- package/dist/deps.js +124 -0
- package/dist/dream.js +422 -0
- package/dist/duration.js +3 -3
- package/dist/gate.js +40 -5
- package/dist/history.js +308 -0
- package/dist/live.js +255 -0
- package/dist/livequota.js +42 -5
- package/dist/macapp.js +25 -2
- package/dist/pacing.js +189 -0
- package/dist/permissions.js +106 -0
- package/dist/picture.js +124 -0
- package/dist/picturetype.js +208 -0
- package/dist/preflight.js +168 -0
- package/dist/projects.js +5 -4
- package/dist/quota.js +31 -5
- package/dist/refresh.js +290 -0
- package/dist/report.js +41 -21
- package/dist/review.js +111 -11
- package/dist/runner.js +318 -10
- package/dist/taste.js +528 -0
- package/dist/tokens.js +75 -0
- package/dist/tokenstore.js +61 -0
- package/dist/trace.js +284 -0
- package/dist/triggers.js +193 -0
- package/dist/usage.js +467 -0
- package/dist/vendor/codeburn/prices.js +45 -0
- package/dist/verify.js +150 -0
- package/dist/verifycard.js +146 -0
- package/dist/workspace.js +132 -18
- package/package.json +4 -2
- package/skills/taste/SKILL.md +4 -1
- package/vendor/diagram-design/LICENSE +21 -0
- package/vendor/diagram-design/SKILL.md +399 -0
- package/vendor/diagram-design/UPSTREAM.md +18 -0
- package/vendor/diagram-design/assets/example-arc-diagram.html +111 -0
- package/vendor/diagram-design/assets/example-architecture-containment.html +205 -0
- package/vendor/diagram-design/assets/example-architecture-delta.html +193 -0
- package/vendor/diagram-design/assets/example-architecture.html +183 -0
- package/vendor/diagram-design/assets/example-axonometric-plan-campus.html +108 -0
- package/vendor/diagram-design/assets/example-axonometric-plan-coffee-shop.html +121 -0
- package/vendor/diagram-design/assets/example-axonometric-plan-warehouse.html +127 -0
- package/vendor/diagram-design/assets/example-axonometric-plan.html +114 -0
- package/vendor/diagram-design/assets/example-bar.html +129 -0
- package/vendor/diagram-design/assets/example-beeswarm.html +384 -0
- package/vendor/diagram-design/assets/example-box-plot.html +127 -0
- package/vendor/diagram-design/assets/example-bubble.html +147 -0
- package/vendor/diagram-design/assets/example-bump.html +142 -0
- package/vendor/diagram-design/assets/example-data-flow.html +143 -0
- package/vendor/diagram-design/assets/example-datalake.html +269 -0
- package/vendor/diagram-design/assets/example-db-schema.html +302 -0
- package/vendor/diagram-design/assets/example-dependency.html +224 -0
- package/vendor/diagram-design/assets/example-deployment.html +190 -0
- package/vendor/diagram-design/assets/example-dp-integration.html +81 -0
- package/vendor/diagram-design/assets/example-dp-security-matrix.html +88 -0
- package/vendor/diagram-design/assets/example-er.html +202 -0
- package/vendor/diagram-design/assets/example-event-modeling.html +64 -0
- package/vendor/diagram-design/assets/example-exploded-ai-stack.html +85 -0
- package/vendor/diagram-design/assets/example-exploded-keyboard.html +84 -0
- package/vendor/diagram-design/assets/example-exploded-phone.html +83 -0
- package/vendor/diagram-design/assets/example-exploded-unboxing.html +84 -0
- package/vendor/diagram-design/assets/example-exploded.html +83 -0
- package/vendor/diagram-design/assets/example-fishbone.html +152 -0
- package/vendor/diagram-design/assets/example-flowchart.html +163 -0
- package/vendor/diagram-design/assets/example-gantt.html +137 -0
- package/vendor/diagram-design/assets/example-heatmap.html +224 -0
- package/vendor/diagram-design/assets/example-high-level-vertical.html +325 -0
- package/vendor/diagram-design/assets/example-high-level.html +301 -0
- package/vendor/diagram-design/assets/example-import-drawio.html +185 -0
- package/vendor/diagram-design/assets/example-import-excalidraw.html +70 -0
- package/vendor/diagram-design/assets/example-import-mermaid.html +70 -0
- package/vendor/diagram-design/assets/example-import-plantuml.html +107 -0
- package/vendor/diagram-design/assets/example-it-state.html +128 -0
- package/vendor/diagram-design/assets/example-journey.html +148 -0
- package/vendor/diagram-design/assets/example-kanban.html +174 -0
- package/vendor/diagram-design/assets/example-layers.html +123 -0
- package/vendor/diagram-design/assets/example-line.html +111 -0
- package/vendor/diagram-design/assets/example-loop.html +100 -0
- package/vendor/diagram-design/assets/example-marimekko.html +148 -0
- package/vendor/diagram-design/assets/example-medallion.html +159 -0
- package/vendor/diagram-design/assets/example-nested.html +136 -0
- package/vendor/diagram-design/assets/example-org-chart.html +45 -0
- package/vendor/diagram-design/assets/example-polar.html +116 -0
- package/vendor/diagram-design/assets/example-process.html +64 -0
- package/vendor/diagram-design/assets/example-pyramid.html +119 -0
- package/vendor/diagram-design/assets/example-quadrant-consultant.html +166 -0
- package/vendor/diagram-design/assets/example-quadrant.html +135 -0
- package/vendor/diagram-design/assets/example-radar.html +139 -0
- package/vendor/diagram-design/assets/example-requirement-traceability.html +122 -0
- package/vendor/diagram-design/assets/example-ridgeline.html +104 -0
- package/vendor/diagram-design/assets/example-sankey.html +150 -0
- package/vendor/diagram-design/assets/example-sbgn.html +213 -0
- package/vendor/diagram-design/assets/example-scatter.html +141 -0
- package/vendor/diagram-design/assets/example-sequence-oauth.html +227 -0
- package/vendor/diagram-design/assets/example-sequence.html +222 -0
- package/vendor/diagram-design/assets/example-service-blueprint.html +185 -0
- package/vendor/diagram-design/assets/example-slopegraph.html +119 -0
- package/vendor/diagram-design/assets/example-state-lifecycle.html +92 -0
- package/vendor/diagram-design/assets/example-state.html +147 -0
- package/vendor/diagram-design/assets/example-steps.html +78 -0
- package/vendor/diagram-design/assets/example-story-map.html +184 -0
- package/vendor/diagram-design/assets/example-streamgraph.html +99 -0
- package/vendor/diagram-design/assets/example-swimlane.html +172 -0
- package/vendor/diagram-design/assets/example-timeline.html +135 -0
- package/vendor/diagram-design/assets/example-tree-block-decomposition.html +151 -0
- package/vendor/diagram-design/assets/example-tree.html +173 -0
- package/vendor/diagram-design/assets/example-treemap.html +107 -0
- package/vendor/diagram-design/assets/example-uml-class.html +188 -0
- package/vendor/diagram-design/assets/example-unit-grid.html +141 -0
- package/vendor/diagram-design/assets/example-venn.html +110 -0
- package/vendor/diagram-design/assets/example-wardley.html +153 -0
- package/vendor/diagram-design/assets/example-waterfall.html +129 -0
- package/vendor/diagram-design/assets/template-dark.html +99 -0
- package/vendor/diagram-design/assets/template.html +100 -0
- package/vendor/diagram-design/references/layout-budget.md +103 -0
- package/vendor/diagram-design/references/output-spec.md +277 -0
- package/vendor/diagram-design/references/primitive-annotation.md +36 -0
- package/vendor/diagram-design/references/primitive-sketchy.md +43 -0
- package/vendor/diagram-design/references/primitives-core.md +146 -0
- package/vendor/diagram-design/references/semantic-patterns.md +154 -0
- package/vendor/diagram-design/references/style-guide.md +234 -0
- package/vendor/diagram-design/references/type-architecture-delta.md +143 -0
- package/vendor/diagram-design/references/type-architecture.md +117 -0
- package/vendor/diagram-design/references/type-axonometric-plan.md +83 -0
- package/vendor/diagram-design/references/type-bar.md +108 -0
- package/vendor/diagram-design/references/type-data-flow.md +371 -0
- package/vendor/diagram-design/references/type-db-schema.md +48 -0
- package/vendor/diagram-design/references/type-dependency.md +113 -0
- package/vendor/diagram-design/references/type-deployment.md +45 -0
- package/vendor/diagram-design/references/type-dp-integration.md +407 -0
- package/vendor/diagram-design/references/type-dp-security-matrix.md +379 -0
- package/vendor/diagram-design/references/type-er.md +25 -0
- package/vendor/diagram-design/references/type-event-modeling.md +36 -0
- package/vendor/diagram-design/references/type-exploded.md +115 -0
- package/vendor/diagram-design/references/type-fishbone.md +75 -0
- package/vendor/diagram-design/references/type-flowchart.md +23 -0
- package/vendor/diagram-design/references/type-gantt.md +45 -0
- package/vendor/diagram-design/references/type-heatmap.md +80 -0
- package/vendor/diagram-design/references/type-high-level.md +470 -0
- package/vendor/diagram-design/references/type-it-state.md +468 -0
- package/vendor/diagram-design/references/type-journey.md +55 -0
- package/vendor/diagram-design/references/type-kanban.md +49 -0
- package/vendor/diagram-design/references/type-layers.md +26 -0
- package/vendor/diagram-design/references/type-line.md +337 -0
- package/vendor/diagram-design/references/type-loop.md +223 -0
- package/vendor/diagram-design/references/type-medallion.md +356 -0
- package/vendor/diagram-design/references/type-nested.md +22 -0
- package/vendor/diagram-design/references/type-org-chart.md +44 -0
- package/vendor/diagram-design/references/type-polar.md +136 -0
- package/vendor/diagram-design/references/type-process.md +490 -0
- package/vendor/diagram-design/references/type-pyramid.md +33 -0
- package/vendor/diagram-design/references/type-quadrant.md +81 -0
- package/vendor/diagram-design/references/type-radar.md +82 -0
- package/vendor/diagram-design/references/type-requirement-traceability.md +45 -0
- package/vendor/diagram-design/references/type-sankey.md +75 -0
- package/vendor/diagram-design/references/type-sbgn.md +80 -0
- package/vendor/diagram-design/references/type-scatter.md +276 -0
- package/vendor/diagram-design/references/type-sequence.md +130 -0
- package/vendor/diagram-design/references/type-service-blueprint.md +103 -0
- package/vendor/diagram-design/references/type-state.md +30 -0
- package/vendor/diagram-design/references/type-steps.md +180 -0
- package/vendor/diagram-design/references/type-story-map.md +46 -0
- package/vendor/diagram-design/references/type-swimlane.md +22 -0
- package/vendor/diagram-design/references/type-timeline.md +20 -0
- package/vendor/diagram-design/references/type-tree.md +24 -0
- package/vendor/diagram-design/references/type-treemap.md +137 -0
- package/vendor/diagram-design/references/type-uml-class.md +65 -0
- package/vendor/diagram-design/references/type-unit-grid.md +63 -0
- package/vendor/diagram-design/references/type-venn.md +26 -0
- package/vendor/diagram-design/references/type-wardley.md +39 -0
- package/vendor/diagram-design/references/type-waterfall.md +75 -0
- package/vendor/diagram-design/scripts/self_check.py +1177 -0
- package/vendor/diagram-design/scripts/verify_geometry.py +696 -0
package/dist/history.js
ADDED
|
@@ -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/live.js
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
// The live copy (2026-11-19): the Chompyy you use runs from its own copy of the repo, ~/.chompyy/live, that
|
|
2
|
+
// follows main and that nobody works in. After each Keep that lands on main, Chompyy brings the copy up to
|
|
3
|
+
// main, rebuilds the CLI, and rebuilds + restarts the Mac app when its code changed. So a kept card shows up
|
|
4
|
+
// in the real app within a couple of minutes, and switching branches in a work folder can't take it away.
|
|
5
|
+
//
|
|
6
|
+
// Why: on 2026-11-19 four kept cards never reached the running app. The app ran from a work folder
|
|
7
|
+
// (token-saving-research-board) that had been switched to another branch, and nothing rebuilt after Keep.
|
|
8
|
+
import { execFileSync, spawn } from 'node:child_process';
|
|
9
|
+
import { createHash } from 'node:crypto';
|
|
10
|
+
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
11
|
+
import { homedir } from 'node:os';
|
|
12
|
+
import { basename, dirname, join, resolve } from 'node:path';
|
|
13
|
+
import { chompyyHome, homePath, readJson, writeJson } from './home.js';
|
|
14
|
+
export const livePath = () => homePath('live.json');
|
|
15
|
+
export const liveDir = () => join(chompyyHome(), 'live');
|
|
16
|
+
export const loadLive = () => readJson(livePath(), null);
|
|
17
|
+
const git = (cwd, args) => execFileSync('git', ['-C', cwd, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
|
|
18
|
+
/** The repo's shared .git folder: the same for every worktree of one repo. */
|
|
19
|
+
export function commonDir(dir) {
|
|
20
|
+
try {
|
|
21
|
+
return resolve(dir, git(dir, ['rev-parse', '--git-common-dir']));
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** Does a Keep in `cardRepo` onto `branch` change what the live copy follows? */
|
|
28
|
+
export function keepAffectsLive(live, cardRepo, branch) {
|
|
29
|
+
if (!live || !branch || branch !== live.branch)
|
|
30
|
+
return false;
|
|
31
|
+
const a = commonDir(cardRepo);
|
|
32
|
+
return !!a && a === commonDir(live.repo);
|
|
33
|
+
}
|
|
34
|
+
export function planUpdate(live, target, depsHash, appExists, macChanged) {
|
|
35
|
+
return {
|
|
36
|
+
target,
|
|
37
|
+
installDeps: live.depsHash !== depsHash,
|
|
38
|
+
buildCli: live.builtCommit !== target,
|
|
39
|
+
buildApp: !appExists || !live.appCommit || (live.appCommit !== target && macChanged(live.appCommit, target)),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const defaultDeps = (log) => ({
|
|
43
|
+
run: (cmd, args, cwd) => {
|
|
44
|
+
execFileSync(cmd, args, { cwd, stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 64 * 1024 * 1024 });
|
|
45
|
+
},
|
|
46
|
+
log,
|
|
47
|
+
appRunning: () => {
|
|
48
|
+
try {
|
|
49
|
+
execFileSync('pgrep', ['-x', 'Chompyy'], { stdio: 'ignore' });
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
sleep: (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms),
|
|
57
|
+
node: process.execPath,
|
|
58
|
+
});
|
|
59
|
+
/** Tries before giving up on opening the new app, one second apart. */
|
|
60
|
+
export const OPEN_TRIES = 3;
|
|
61
|
+
export const appBundle = (dir) => join(dir, 'mac', 'build', 'Chompyy.app');
|
|
62
|
+
/**
|
|
63
|
+
* Where the app is installed so you can open it like any Mac app (Spotlight, Launchpad, the Dock), without a
|
|
64
|
+
* terminal: ~/Applications/Chompyy.app. No admin rights needed. CHOMPYY_APPLICATIONS moves it (tests).
|
|
65
|
+
*/
|
|
66
|
+
export const installedApp = () => join(process.env.CHOMPYY_APPLICATIONS || join(homedir(), 'Applications'), 'Chompyy.app');
|
|
67
|
+
const lockHash = (dir) => {
|
|
68
|
+
const p = join(dir, 'cli', 'package-lock.json');
|
|
69
|
+
return existsSync(p) ? createHash('sha256').update(readFileSync(p)).digest('hex').slice(0, 16) : 'none';
|
|
70
|
+
};
|
|
71
|
+
/** Point the app at the live CLI, and mark it so other copies of the CLI don't take it over (recordCliLocation). */
|
|
72
|
+
export function pinCli(dir, node) {
|
|
73
|
+
writeJson(homePath('cli.json'), { node, script: join(dir, 'cli', 'dist', 'cli.js'), live: true });
|
|
74
|
+
}
|
|
75
|
+
/** Make the live copy: a worktree of `repo` at `branch`, detached so the branch stays free for your own folders. */
|
|
76
|
+
export function liveSet(repo, branch = 'main') {
|
|
77
|
+
const root = git(repo, ['rev-parse', '--show-toplevel']);
|
|
78
|
+
const dir = liveDir();
|
|
79
|
+
if (!existsSync(join(dir, '.git')))
|
|
80
|
+
git(root, ['worktree', 'add', '--quiet', '--detach', dir, branch]);
|
|
81
|
+
const state = { repo: root, branch, dir };
|
|
82
|
+
writeJson(livePath(), state);
|
|
83
|
+
return state;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Bring the live copy to the latest `branch` and rebuild what changed. A failed step leaves the last good build
|
|
87
|
+
* running (the CLI is only repointed after a build succeeds) and records the error for `chompyy live`.
|
|
88
|
+
*/
|
|
89
|
+
export function liveUpdate(deps = defaultDeps((l) => console.log(l))) {
|
|
90
|
+
const live = loadLive();
|
|
91
|
+
if (!live)
|
|
92
|
+
throw new Error('No live copy yet: run `chompyy live set <your Chompyy checkout>` once.');
|
|
93
|
+
const { dir } = live;
|
|
94
|
+
let appClosed = false;
|
|
95
|
+
try {
|
|
96
|
+
const target = git(live.repo, ['rev-parse', live.branch]);
|
|
97
|
+
git(dir, ['checkout', '--quiet', '--force', '--detach', target]);
|
|
98
|
+
const plan = planUpdate(live, target, lockHash(dir), existsSync(appBundle(dir)), (from, to) => {
|
|
99
|
+
try {
|
|
100
|
+
git(dir, ['diff', '--quiet', from, to, '--', 'mac']);
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
const cli = join(dir, 'cli');
|
|
108
|
+
if (plan.installDeps) {
|
|
109
|
+
deps.log('installing the CLI\'s dependencies (the lockfile changed)…');
|
|
110
|
+
deps.run('npm', ['ci', '--no-audit', '--no-fund'], cli);
|
|
111
|
+
live.depsHash = lockHash(dir);
|
|
112
|
+
}
|
|
113
|
+
if (plan.buildCli || plan.installDeps) {
|
|
114
|
+
deps.log(`building the CLI at ${target.slice(0, 7)}…`);
|
|
115
|
+
deps.run('npm', ['run', 'build'], cli);
|
|
116
|
+
live.builtCommit = target;
|
|
117
|
+
}
|
|
118
|
+
pinCli(dir, deps.node);
|
|
119
|
+
const installed = installedApp();
|
|
120
|
+
// Also when only the installed copy is missing or behind (an older download sat there: 0.1.0 on 2026-11-22).
|
|
121
|
+
const install = plan.buildApp || !existsSync(installed) || live.installedCommit !== live.appCommit;
|
|
122
|
+
if (plan.buildApp) {
|
|
123
|
+
deps.log('building the Mac app (its code changed)…');
|
|
124
|
+
deps.run(join(dir, 'mac', 'Scripts', 'build-app.sh'), [], join(dir, 'mac'));
|
|
125
|
+
live.appCommit = target;
|
|
126
|
+
}
|
|
127
|
+
if (install) {
|
|
128
|
+
const wasRunning = deps.appRunning();
|
|
129
|
+
if (wasRunning) {
|
|
130
|
+
try {
|
|
131
|
+
deps.run('pkill', ['-x', 'Chompyy'], dir);
|
|
132
|
+
}
|
|
133
|
+
catch { }
|
|
134
|
+
// pkill only asks it to quit. Opening while the old app is still closing fails (2026-11-21): wait up to 10 s.
|
|
135
|
+
for (let i = 0; i < 50 && deps.appRunning(); i++)
|
|
136
|
+
deps.sleep(200);
|
|
137
|
+
}
|
|
138
|
+
// Replace the copy in Applications with this build, then open that copy.
|
|
139
|
+
if (basename(installed) !== 'Chompyy.app')
|
|
140
|
+
throw new Error(`refusing to replace ${installed}`);
|
|
141
|
+
mkdirSync(dirname(installed), { recursive: true });
|
|
142
|
+
rmSync(installed, { recursive: true, force: true });
|
|
143
|
+
deps.run('ditto', [appBundle(dir), installed], dir);
|
|
144
|
+
live.installedCommit = live.appCommit;
|
|
145
|
+
let failed;
|
|
146
|
+
for (let i = 0; i < OPEN_TRIES; i++) {
|
|
147
|
+
try {
|
|
148
|
+
// In the background and marked as an update: the app comes back quietly to the menu bar.
|
|
149
|
+
deps.run('open', ['-g', installed, '--args', '--updated'], dir);
|
|
150
|
+
failed = undefined;
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
catch (err) {
|
|
154
|
+
failed = err;
|
|
155
|
+
if (i < OPEN_TRIES - 1)
|
|
156
|
+
deps.sleep(1000);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (failed) {
|
|
160
|
+
appClosed = wasRunning;
|
|
161
|
+
throw new Error(`the new app is built but didn't open: open ${installed} by hand (${failed.message.split('\n')[0]})`);
|
|
162
|
+
}
|
|
163
|
+
deps.log(`${wasRunning ? 'restarted the app with the new build' : 'opened the new app'} (installed in ${installed.replace(homedir(), '~')}).`);
|
|
164
|
+
}
|
|
165
|
+
delete live.error;
|
|
166
|
+
if (!plan.buildCli && !install && !plan.installDeps)
|
|
167
|
+
deps.log(`already up to date at ${target.slice(0, 7)}.`);
|
|
168
|
+
}
|
|
169
|
+
catch (err) {
|
|
170
|
+
const e = err;
|
|
171
|
+
live.error = `${e.message ?? err}${e.stderr ? `\n${String(e.stderr).slice(-2000)}` : ''}`.trim();
|
|
172
|
+
// Say what is really running: once the old app was closed, nothing is.
|
|
173
|
+
deps.log(appClosed ? `update failed and the app is closed: ${live.error.split('\n')[0]}` : `update failed, the last good build keeps running: ${live.error.split('\n')[0]}`);
|
|
174
|
+
}
|
|
175
|
+
live.at = new Date().toISOString();
|
|
176
|
+
writeJson(livePath(), live);
|
|
177
|
+
return live;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Run updates one at a time. Keeping two cards in a row asks twice: the second ask leaves a note, and the
|
|
181
|
+
* update that is already running goes round again so it ends at the newest main.
|
|
182
|
+
*/
|
|
183
|
+
export function liveUpdateLocked(deps) {
|
|
184
|
+
const lock = homePath('live.lock');
|
|
185
|
+
const again = homePath('live.again');
|
|
186
|
+
let fd;
|
|
187
|
+
try {
|
|
188
|
+
fd = openSync(lock, 'wx');
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
const pid = Number(readFileSync(lock, 'utf8')) || 0;
|
|
192
|
+
let alive = false;
|
|
193
|
+
try {
|
|
194
|
+
if (pid)
|
|
195
|
+
process.kill(pid, 0);
|
|
196
|
+
alive = pid > 0;
|
|
197
|
+
}
|
|
198
|
+
catch { }
|
|
199
|
+
if (alive) {
|
|
200
|
+
writeFileSync(again, '');
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
rmSync(lock, { force: true }); // left by an update that died
|
|
204
|
+
fd = openSync(lock, 'wx');
|
|
205
|
+
}
|
|
206
|
+
try {
|
|
207
|
+
writeFileSync(fd, String(process.pid));
|
|
208
|
+
let state;
|
|
209
|
+
do {
|
|
210
|
+
rmSync(again, { force: true });
|
|
211
|
+
state = liveUpdate(deps);
|
|
212
|
+
} while (existsSync(again));
|
|
213
|
+
return state;
|
|
214
|
+
}
|
|
215
|
+
finally {
|
|
216
|
+
closeSync(fd);
|
|
217
|
+
rmSync(lock, { force: true });
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/** Start an update in the background, so Keep returns at once and the update outlives an app restart. */
|
|
221
|
+
export function startLiveUpdate(node = process.execPath, script = process.argv[1]) {
|
|
222
|
+
const out = openSync(homePath('live.log'), 'a');
|
|
223
|
+
const child = spawn(node, [script, 'live', 'update'], { detached: true, stdio: ['ignore', out, out] });
|
|
224
|
+
child.unref();
|
|
225
|
+
closeSync(out);
|
|
226
|
+
}
|
|
227
|
+
/** Stop following: the app goes back to whichever CLI runs next (the live folder stays until you delete it). */
|
|
228
|
+
export function liveOff() {
|
|
229
|
+
rmSync(livePath(), { force: true });
|
|
230
|
+
const cli = homePath('cli.json');
|
|
231
|
+
const have = readJson(cli, {});
|
|
232
|
+
if (have.live) {
|
|
233
|
+
delete have.live;
|
|
234
|
+
writeJson(cli, have);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/** For `chompyy live`: where the copy is, and whether it has everything that's on main. */
|
|
238
|
+
export function formatLive(live) {
|
|
239
|
+
if (!live)
|
|
240
|
+
return 'No live copy. Set it up once with `chompyy live set <your Chompyy checkout>`; after that every Keep on main reaches the app by itself.';
|
|
241
|
+
let behind = '';
|
|
242
|
+
try {
|
|
243
|
+
const n = Number(git(live.repo, ['rev-list', '--count', `${live.builtCommit ?? live.branch}..${live.branch}`]));
|
|
244
|
+
behind = n ? `${n} commit(s) on ${live.branch} not built yet` : `up to date with ${live.branch}`;
|
|
245
|
+
}
|
|
246
|
+
catch { }
|
|
247
|
+
return [
|
|
248
|
+
`live copy ${live.dir}`,
|
|
249
|
+
`follows ${live.branch} of ${live.repo}`,
|
|
250
|
+
`CLI built ${live.builtCommit?.slice(0, 7) ?? 'never'}${behind ? ` (${behind})` : ''}`,
|
|
251
|
+
`app built ${live.appCommit?.slice(0, 7) ?? 'never'}`,
|
|
252
|
+
...(live.at ? [`updated ${live.at}`] : []),
|
|
253
|
+
...(live.error ? [`last error ${live.error.split('\n')[0]} (details: ~/.chompyy/live.log)`] : []),
|
|
254
|
+
].join('\n');
|
|
255
|
+
}
|
package/dist/livequota.js
CHANGED
|
@@ -3,8 +3,29 @@
|
|
|
3
3
|
// It sends no message, so it never starts a 5-hour window. Chosen over the status-line
|
|
4
4
|
// snapshot on 2026-11-15 because it is fresh even when no Claude Code session is open.
|
|
5
5
|
import { fetchClaudeQuota } from './vendor/codeburn/claude.js';
|
|
6
|
+
import { setConfig } from './config.js';
|
|
6
7
|
import { homePath, readJson, writeJson } from './home.js';
|
|
7
8
|
import { loadSnapshot, mergeSnapshot, saveSnapshot } from './quota.js';
|
|
9
|
+
/** What the app and `chompyy quota` say while the Keychain read waits for your OK. */
|
|
10
|
+
export const KEYCHAIN_ASK = "Live quota needs your OK to read Claude Code's saved login from your Keychain (only to ask Anthropic how much is left; it sends no message). Run `chompyy quota --allow-keychain`, or press Allow.";
|
|
11
|
+
/** What they say once you turned the Keychain read off. */
|
|
12
|
+
export const KEYCHAIN_OFF = "Keychain reading is off, as you chose. Quota comes from Claude Code's status line; `chompyy quota --allow-keychain` turns live quota back on.";
|
|
13
|
+
/**
|
|
14
|
+
* Reading the Keychain is opt-in (#24). Allowed once you say yes. A Mac where an earlier check already read the
|
|
15
|
+
* login (you chose Always Allow before Chompyy asked first) counts as a yes, and that is saved.
|
|
16
|
+
*/
|
|
17
|
+
export function keychainAllowed(config) {
|
|
18
|
+
if (config.allowKeychain !== null && config.allowKeychain !== undefined)
|
|
19
|
+
return config.allowKeychain;
|
|
20
|
+
if (loadLiveState().connection !== 'connected')
|
|
21
|
+
return false;
|
|
22
|
+
setConfig('allowKeychain', true);
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
/** Whether to show the Allow button: a Mac, live quota on, never asked, and the check found nothing without it. */
|
|
26
|
+
export function keychainAsk(config, platform = process.platform) {
|
|
27
|
+
return platform === 'darwin' && config.quotaSource === 'api' && (config.allowKeychain ?? null) === null && loadLiveState().connection === 'keychainUnchecked';
|
|
28
|
+
}
|
|
8
29
|
/** Don't ask the endpoint more often than this. */
|
|
9
30
|
export const MIN_INTERVAL_MS = 5 * 60_000;
|
|
10
31
|
const statePath = () => homePath('livequota.json');
|
|
@@ -26,24 +47,34 @@ export function snapshotFromProvider(provider, now) {
|
|
|
26
47
|
snap.fiveHour = five;
|
|
27
48
|
if (week)
|
|
28
49
|
snap.sevenDay = week;
|
|
50
|
+
// Per-model weekly windows ("Weekly · Opus", "Weekly · Sonnet", …).
|
|
51
|
+
const models = {};
|
|
52
|
+
for (const row of provider.details) {
|
|
53
|
+
const name = row.label.startsWith('Weekly · ') ? row.label.slice('Weekly · '.length) : '';
|
|
54
|
+
const w = name ? windowFrom(provider, row.label) : undefined;
|
|
55
|
+
if (w)
|
|
56
|
+
models[name] = w;
|
|
57
|
+
}
|
|
58
|
+
if (Object.keys(models).length)
|
|
59
|
+
snap.models = models;
|
|
29
60
|
return snap;
|
|
30
61
|
}
|
|
31
62
|
/**
|
|
32
63
|
* Refresh the snapshot from the endpoint. `force` skips the 5-minute spacing (not a 429 backoff).
|
|
33
|
-
* `allowKeychain` lets macOS
|
|
64
|
+
* `allowKeychain` lets it read the Keychain (macOS shows its one-time "allow access?" prompt); off unless you allowed it.
|
|
34
65
|
*/
|
|
35
66
|
export async function refreshLiveQuota(opts = {}) {
|
|
36
67
|
const now = opts.now ?? new Date();
|
|
37
68
|
const state = loadLiveState();
|
|
38
69
|
const current = loadSnapshot();
|
|
39
70
|
if (state.retryAfterAt && Date.parse(state.retryAfterAt) > now.getTime()) {
|
|
40
|
-
return { ok: false, snapshot: current, message: `Anthropic
|
|
71
|
+
return { ok: false, snapshot: current, message: `Anthropic limits how often quota can be checked; next check after ${hhmm(state.retryAfterAt)}.` };
|
|
41
72
|
}
|
|
42
73
|
if (!opts.force && state.lastTryAt && now.getTime() - Date.parse(state.lastTryAt) < MIN_INTERVAL_MS && current?.source === 'api') {
|
|
43
74
|
return { ok: true, snapshot: current, message: 'Fresh enough.' };
|
|
44
75
|
}
|
|
45
76
|
const fetchQuota = opts.fetchQuota ?? ((o) => fetchClaudeQuota(o));
|
|
46
|
-
const result = await fetchQuota({ allowKeychain: opts.allowKeychain ??
|
|
77
|
+
const result = await fetchQuota({ allowKeychain: opts.allowKeychain ?? false });
|
|
47
78
|
const next = {
|
|
48
79
|
lastTryAt: now.toISOString(),
|
|
49
80
|
connection: result.quota.connection,
|
|
@@ -53,21 +84,27 @@ export async function refreshLiveQuota(opts = {}) {
|
|
|
53
84
|
next.retryAfterAt = new Date(now.getTime() + result.retryAfterSeconds * 1000).toISOString();
|
|
54
85
|
const snap = snapshotFromProvider(result.quota, now);
|
|
55
86
|
if (!snap) {
|
|
56
|
-
|
|
87
|
+
const ask = opts.keychainOff ? KEYCHAIN_OFF : KEYCHAIN_ASK;
|
|
88
|
+
next.note = result.quota.connection === 'keychainUnchecked' ? ask : result.quota.footerLines.join(' ') || result.quota.connection;
|
|
57
89
|
writeJson(statePath(), next);
|
|
58
|
-
|
|
90
|
+
// A 429: other tools signed in with the same Claude login (or a recent check) used up the allowance.
|
|
91
|
+
if (next.retryAfterAt)
|
|
92
|
+
return { ok: false, snapshot: current, message: `Anthropic limits how often quota can be checked; next check after ${hhmm(next.retryAfterAt)}.` };
|
|
93
|
+
return { ok: false, snapshot: current, message: result.quota.connection === 'keychainUnchecked' ? ask : explain(result.quota) };
|
|
59
94
|
}
|
|
60
95
|
const merged = mergeSnapshot(current, snap);
|
|
61
96
|
saveSnapshot(merged);
|
|
62
97
|
writeJson(statePath(), next);
|
|
63
98
|
return { ok: true, snapshot: merged, message: `Updated from Anthropic${result.quota.planLabel ? ` (${result.quota.planLabel})` : ''}.` };
|
|
64
99
|
}
|
|
100
|
+
const hhmm = (iso) => new Date(iso).toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' });
|
|
65
101
|
function explain(p) {
|
|
66
102
|
const extra = p.footerLines.length ? ` ${p.footerLines.join(' ')}` : '';
|
|
67
103
|
switch (p.connection) {
|
|
68
104
|
case 'accessDenied':
|
|
69
105
|
return `macOS didn't allow reading the Claude Code login.${extra}`;
|
|
70
106
|
case 'keychainUnchecked':
|
|
107
|
+
return KEYCHAIN_ASK;
|
|
71
108
|
case 'disconnected':
|
|
72
109
|
return 'No Claude Code login found. Sign in to Claude Code once, then try again.';
|
|
73
110
|
case 'terminalFailure':
|