claude-rpc 1.4.2 → 1.5.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/src/fmt.js CHANGED
@@ -7,7 +7,7 @@
7
7
  // deploys dependency-free and can't import across the package boundary. Keep
8
8
  // the two in sync; test/format.test.js pins fmtNum's tier behavior.
9
9
 
10
- // Compact integer: 999 → "999", 1_500 → "1.5k", 1_500_000 → "1.50M", up to "B".
10
+ // Compact integer: 999 → "999", 1_500 → "1.5k", 1_500_000 → "1.50M", up to "T".
11
11
  // The unit is chosen from the ROUNDED value, so 999_999 → "1.00M" (not the old
12
12
  // "1000.0k") and 999_999_999 → "1.00B".
13
13
  export function fmtNum(n) {
@@ -15,11 +15,11 @@ export function fmtNum(n) {
15
15
  const neg = n < 0 ? '-' : '';
16
16
  const v = Math.abs(n);
17
17
  if (v < 1000) return neg + Math.round(v);
18
- for (const [suf, div, prec] of [['k', 1e3, 1], ['M', 1e6, 2], ['B', 1e9, 2]]) {
18
+ for (const [suf, div, prec] of [['k', 1e3, 1], ['M', 1e6, 2], ['B', 1e9, 2], ['T', 1e12, 2]]) {
19
19
  const s = (v / div).toFixed(prec);
20
20
  if (Number(s) < 1000) return neg + s + suf;
21
21
  }
22
- return neg + (v / 1e9).toFixed(2) + 'B'; // ≥ ~1e12 stays in the B tier
22
+ return neg + (v / 1e12).toFixed(2) + 'T';
23
23
  }
24
24
 
25
25
  // Duration from ms: <60m → "42m", <10h → "2.5h", else "12h". Rounds to whole
package/src/gist.js CHANGED
@@ -26,12 +26,17 @@ const WIN = process.platform === 'win32';
26
26
  function ghQuote(a) {
27
27
  return /[\s"]/.test(a) ? `"${String(a).replace(/"/g, '""')}"` : a;
28
28
  }
29
+ // gh can block on a network stall or a locked keyring, and the daemon now
30
+ // calls it too (background verification resume) — a spawnSync with no timeout
31
+ // would freeze its event loop, so every call is capped. A timeout surfaces as
32
+ // a non-zero/null status, which every caller already treats as failure.
33
+ const GH_TIMEOUT_MS = 30_000;
29
34
  function gh(args, opts = {}) {
30
35
  // windowsHide so the gh.exe/cmd shim doesn't flash a console window on
31
36
  // Windows (shell:true routes through cmd.exe; hide that too). No-op elsewhere.
32
37
  return WIN
33
- ? spawnSync('gh', args.map(ghQuote), { ...opts, shell: true, windowsHide: true })
34
- : spawnSync('gh', args, { ...opts, windowsHide: true });
38
+ ? spawnSync('gh', args.map(ghQuote), { timeout: GH_TIMEOUT_MS, ...opts, shell: true, windowsHide: true })
39
+ : spawnSync('gh', args, { timeout: GH_TIMEOUT_MS, ...opts, windowsHide: true });
35
40
  }
36
41
 
37
42
  // Bare fetch has no total timeout; a stalled GitHub endpoint would hang the
package/src/heatmap.js ADDED
@@ -0,0 +1,342 @@
1
+ // Year heatmap + stats-with-heatmap card — ONE renderer shared by the CLI
2
+ // (`claude-rpc calendar`) and the worker's live /heatmap/<h>.svg and
3
+ // /stats/<h>.svg endpoints. The worker imports this file across the package
4
+ // boundary (wrangler bundles it), so it must stay PURE: no imports, no Node
5
+ // APIs, no Date-of-the-local-machine assumptions. Every date is a
6
+ // 'YYYY-MM-DD' string handled with UTC arithmetic, so the same series
7
+ // renders identically on a laptop and in a Cloudflare isolate.
8
+ //
9
+ // Input series shape (also the profile payload's `daily` field):
10
+ // { end: 'YYYY-MM-DD', tokens: number[], activeMin: number[] }
11
+ // Arrays run oldest → newest; the LAST element is `end`. Arrays may be
12
+ // shorter than a year (leading zeros trimmed) — missing days read as 0.
13
+
14
+ export const HEATMAP_WEEKS = 53;
15
+ export const HEATMAP_DAYS = HEATMAP_WEEKS * 7; // 371 — always covers the 53-column grid
16
+
17
+ const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
18
+ const WEEKDAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
19
+ const DAY_MS = 86_400_000;
20
+
21
+ const PALETTE = {
22
+ paper: '#f4ede0', paper2: '#ebe2d2', empty: '#e1d6c0',
23
+ ink: '#1a1611', inkMute: '#5c5147', inkFaint: '#8a7c6d',
24
+ rust: '#c2491e', amber: '#c0851f', blue: '#3f6f9f', grass: '#4a9462', tape: '#f2d76e',
25
+ };
26
+
27
+ // Per-metric 4-step ramps (level 1..4); level 0 is always PALETTE.empty.
28
+ const RAMPS = {
29
+ tokens: ['#f6dccb', '#f08a4a', '#c2491e', '#8f3415'],
30
+ hours: ['#d5e6c8', '#8fc27a', '#4a9462', '#2c6b3f'],
31
+ };
32
+
33
+ const MONO = 'JetBrains Mono, ui-monospace, monospace';
34
+ const DISPLAY = 'Space Grotesk, Inter, system-ui, sans-serif';
35
+
36
+ function escapeXml(s) {
37
+ return String(s == null ? '' : s)
38
+ .replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
39
+ }
40
+
41
+ // Same rules as src/fmt.js fmtNum / fmtHours (inlined — this module is pure).
42
+ function fmtNum(n) {
43
+ if (!n) return '0';
44
+ const v = Math.abs(n);
45
+ if (v < 1000) return String(Math.round(v));
46
+ for (const [suf, div, prec] of [['k', 1e3, 1], ['M', 1e6, 2], ['B', 1e9, 2], ['T', 1e12, 2]]) {
47
+ const s = (v / div).toFixed(prec);
48
+ if (Number(s) < 1000) return s + suf;
49
+ }
50
+ return (v / 1e12).toFixed(2) + 'T';
51
+ }
52
+ function fmtMinutes(min) {
53
+ if (!min) return '0m';
54
+ if (min < 60) return `${Math.round(min)}m`;
55
+ const h = min / 60;
56
+ return h < 10 ? `${h.toFixed(1)}h` : `${Math.round(h)}h`;
57
+ }
58
+
59
+ // ── dates (UTC arithmetic on YYYY-MM-DD) ─────────────────────────────────
60
+
61
+ export function isDayKey(s) {
62
+ if (typeof s !== 'string' || !/^\d{4}-\d{2}-\d{2}$/.test(s)) return false;
63
+ const t = Date.parse(`${s}T00:00:00Z`);
64
+ return Number.isFinite(t) && new Date(t).toISOString().slice(0, 10) === s;
65
+ }
66
+ export function dayToMs(key) { return Date.parse(`${key}T00:00:00Z`); }
67
+ export function msToDay(ms) { return new Date(ms).toISOString().slice(0, 10); }
68
+ function shortDate(key) {
69
+ const d = new Date(dayToMs(key));
70
+ return `${MONTHS[d.getUTCMonth()]} ${d.getUTCDate()}`;
71
+ }
72
+
73
+ // Normalize a series to exactly `days` values ending at `end` for one metric.
74
+ // metric: 'tokens' | 'hours' (hours reads activeMin).
75
+ export function seriesValues(series, metric = 'tokens', days = HEATMAP_DAYS) {
76
+ const src = (metric === 'hours' ? series?.activeMin : series?.tokens) || [];
77
+ const out = new Array(days).fill(0);
78
+ const n = Math.min(src.length, days);
79
+ for (let i = 0; i < n; i++) {
80
+ const v = Number(src[src.length - 1 - i]);
81
+ out[days - 1 - i] = Number.isFinite(v) && v > 0 ? v : 0;
82
+ }
83
+ return out;
84
+ }
85
+
86
+ // Intensity cutoffs from the user's OWN distribution (quartiles of non-zero
87
+ // days, like GitHub). Token days span 5+ orders of magnitude between users, so
88
+ // fixed thresholds would paint one person all-dark and another all-pale.
89
+ export function levelCutoffs(values) {
90
+ const nz = values.filter((v) => v > 0).sort((a, b) => a - b);
91
+ if (!nz.length) return [Infinity, Infinity, Infinity];
92
+ const q = (p) => nz[Math.min(nz.length - 1, Math.floor(p * nz.length))];
93
+ return [q(0.25), q(0.5), q(0.75)];
94
+ }
95
+ export function levelOf(v, cut) {
96
+ if (!(v > 0)) return 0;
97
+ if (v < cut[0]) return 1;
98
+ if (v < cut[1]) return 2;
99
+ if (v < cut[2]) return 3;
100
+ return 4;
101
+ }
102
+
103
+ // Facts the card prints under the grid. All computed over the visible window.
104
+ export function seriesFacts(series, metric = 'tokens', days = HEATMAP_DAYS) {
105
+ const end = isDayKey(series?.end) ? series.end : null;
106
+ const vals = seriesValues(series, metric, days);
107
+ const endMs = end ? dayToMs(end) : 0;
108
+ let total = 0, activeDays = 0, busiest = null, run = 0, longestRun = 0;
109
+ const byWeekday = new Array(7).fill(0);
110
+ for (let i = 0; i < vals.length; i++) {
111
+ const v = vals[i];
112
+ if (v > 0) {
113
+ total += v; activeDays++; run++;
114
+ longestRun = Math.max(longestRun, run);
115
+ if (end) {
116
+ const key = msToDay(endMs - (vals.length - 1 - i) * DAY_MS);
117
+ if (!busiest || v > busiest.value) busiest = { date: key, value: v };
118
+ byWeekday[new Date(dayToMs(key)).getUTCDay()] += v;
119
+ }
120
+ } else run = 0;
121
+ }
122
+ // Current run: ending today, or yesterday (today may simply not have started).
123
+ let current = 0;
124
+ for (let i = vals.length - 1; i >= 0; i--) {
125
+ if (vals[i] > 0) current++;
126
+ else if (i === vals.length - 1) continue;
127
+ else break;
128
+ }
129
+ let bestWeekday = null;
130
+ for (let d = 0; d < 7; d++) if (byWeekday[d] > 0 && (bestWeekday == null || byWeekday[d] > byWeekday[bestWeekday])) bestWeekday = d;
131
+ return {
132
+ total, activeDays, longestRun, currentRun: current,
133
+ busiest,
134
+ avgPerActiveDay: activeDays ? total / activeDays : 0,
135
+ bestWeekday: bestWeekday == null ? null : WEEKDAYS[bestWeekday],
136
+ };
137
+ }
138
+
139
+ function fmtMetric(v, metric) { return metric === 'hours' ? fmtMinutes(v) : fmtNum(v); }
140
+
141
+ // ── the grid ─────────────────────────────────────────────────────────────
142
+
143
+ // Returns { svg, width, height } for a 53-column Sun..Sat grid at (x, y),
144
+ // month labels above, Mon/Wed/Fri labels to the left (inside x).
145
+ function grid(x, y, series, metric, { cell = 12, gap = 3, empty = false } = {}) {
146
+ const step = cell + gap;
147
+ const end = isDayKey(series?.end) ? series.end : null;
148
+ const ramp = RAMPS[metric] || RAMPS.tokens;
149
+ const fill = (l) => (l === 0 ? PALETTE.empty : ramp[l - 1]);
150
+ const endMs = end ? dayToMs(end) : 0;
151
+ const endDow = end ? new Date(endMs).getUTCDay() : 6;
152
+ const total = (HEATMAP_WEEKS - 1) * 7 + endDow + 1; // last column ends on `end`
153
+ const vals = seriesValues(series, metric, total);
154
+ const cut = levelCutoffs(vals);
155
+ const labelW = 30;
156
+ const gx = x + labelW;
157
+
158
+ let cells = '', months = '', lastMonth = -1, lastLabelCol = -9;
159
+ for (let i = 0; i < total; i++) {
160
+ const col = Math.floor(i / 7), row = i % 7;
161
+ const cx = gx + col * step, cy = y + row * step;
162
+ const key = end ? msToDay(endMs - (total - 1 - i) * DAY_MS) : null;
163
+ const v = vals[i];
164
+ const l = empty ? 0 : levelOf(v, cut);
165
+ const title = key ? `<title>${escapeXml(`${shortDate(key)}: ${fmtMetric(v, metric)}`)}</title>` : '';
166
+ cells += `<rect x="${cx}" y="${cy}" width="${cell}" height="${cell}" rx="2" fill="${fill(l)}" stroke="${PALETTE.ink}" stroke-width="0.4" stroke-opacity="0.55">${title}</rect>`;
167
+ if (row === 0 && key) {
168
+ const m = new Date(dayToMs(key)).getUTCMonth();
169
+ if (m !== lastMonth) {
170
+ // Skip a label squeezed against the previous one (partial first month).
171
+ if (col - lastLabelCol >= 3) {
172
+ months += `<text x="${cx}" y="${y - 7}" font-family="${MONO}" font-size="10" fill="${PALETTE.inkMute}">${MONTHS[m]}</text>`;
173
+ lastLabelCol = col;
174
+ }
175
+ lastMonth = m;
176
+ }
177
+ }
178
+ }
179
+ let rows = '';
180
+ for (const [r, name] of [[1, 'Mon'], [3, 'Wed'], [5, 'Fri']]) {
181
+ rows += `<text x="${x}" y="${y + r * step + cell - 2}" font-family="${MONO}" font-size="9" fill="${PALETTE.inkFaint}">${name}</text>`;
182
+ }
183
+ return { svg: months + rows + cells, width: labelW + HEATMAP_WEEKS * step - gap, height: 7 * step - gap };
184
+ }
185
+
186
+ function legend(xRight, y, metric) {
187
+ const ramp = RAMPS[metric] || RAMPS.tokens;
188
+ const fills = [PALETTE.empty, ...ramp];
189
+ const sw = 12, sg = 4;
190
+ const x0 = xRight - fills.length * (sw + sg) + sg;
191
+ let s = `<text x="${x0 - 8}" y="${y + 10}" text-anchor="end" font-family="${MONO}" font-size="9" fill="${PALETTE.inkFaint}">less</text>`;
192
+ fills.forEach((f, i) => {
193
+ s += `<rect x="${x0 + i * (sw + sg)}" y="${y}" width="${sw}" height="${sw}" rx="2" fill="${f}" stroke="${PALETTE.ink}" stroke-width="0.4" stroke-opacity="0.55"/>`;
194
+ });
195
+ s += `<text x="${xRight + 8}" y="${y + 10}" font-family="${MONO}" font-size="9" fill="${PALETTE.inkFaint}">more</text>`;
196
+ return s;
197
+ }
198
+
199
+ function frame(W, H, inner, label) {
200
+ return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" role="img" aria-label="${escapeXml(label)}">
201
+ <defs>
202
+ <pattern id="dg" width="22" height="22" patternUnits="userSpaceOnUse">
203
+ <circle cx="1" cy="1" r="1" fill="${PALETTE.ink}" opacity="0.07"/>
204
+ </pattern>
205
+ </defs>
206
+ <rect x="3" y="4" width="${W - 6}" height="${H - 7}" fill="${PALETTE.ink}"/>
207
+ <rect x="0.75" y="0.75" width="${W - 7}" height="${H - 9}" fill="${PALETTE.paper}" stroke="${PALETTE.ink}" stroke-width="2"/>
208
+ <rect x="0.75" y="0.75" width="${W - 7}" height="${H - 9}" fill="url(#dg)"/>
209
+ ${inner}
210
+ </svg>`;
211
+ }
212
+
213
+ function spark(cx, cy, r, fill) {
214
+ const i = r * 0.16;
215
+ return `<path d="M ${cx} ${cy - r} C ${cx + i} ${cy - i} ${cx + i} ${cy - i} ${cx + r} ${cy} C ${cx + i} ${cy + i} ${cx + i} ${cy + i} ${cx} ${cy + r} C ${cx - i} ${cy + i} ${cx - i} ${cy + i} ${cx - r} ${cy} C ${cx - i} ${cy - i} ${cx - i} ${cy - i} ${cx} ${cy - r} Z" fill="${fill}"/>`;
216
+ }
217
+
218
+ function verifiedStamp(x, y) {
219
+ return `<g transform="translate(${x} ${y})">
220
+ <circle r="11" fill="${PALETTE.grass}"/>
221
+ <path d="M -4.6 0 L -1.4 3.4 L 5 -4" fill="none" stroke="#fff" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/>
222
+ </g>`;
223
+ }
224
+
225
+ function clip(s, n) { s = String(s || ''); return s.length > n ? `${s.slice(0, n - 1)}…` : s; }
226
+
227
+ function metricOf(m) { return m === 'hours' ? 'hours' : 'tokens'; }
228
+
229
+ // ── standalone heatmap (GET /heatmap/<h>.svg, `claude-rpc calendar`) ─────
230
+
231
+ // opts: { series, metric, title?, subtitle?, footer? , empty? }
232
+ export function renderHeatmap({ series, metric = 'tokens', title, subtitle, footer, empty = false } = {}) {
233
+ metric = metricOf(metric);
234
+ const W = 880;
235
+ const g = grid(28, 98, series, metric, { empty });
236
+ const H = 98 + g.height + 56;
237
+ const f = seriesFacts(series, metric);
238
+ const what = metric === 'hours' ? 'hours' : 'tokens';
239
+ const sub = subtitle != null ? subtitle
240
+ : `${f.activeDays} active days · ${fmtMetric(f.total, metric)}${metric === 'hours' ? ' with Claude' : ' tokens'} in the last year`;
241
+ const inner = `
242
+ ${spark(40, 37, 10, metric === 'hours' ? PALETTE.grass : PALETTE.rust)}
243
+ <text x="58" y="44" font-family="${DISPLAY}" font-size="22" font-weight="800" letter-spacing="-0.6" fill="${PALETTE.ink}">${escapeXml(clip(title || 'a year on Claude Code', 48))}</text>
244
+ <text x="28" y="66" font-family="${MONO}" font-size="11" fill="${PALETTE.inkMute}">${escapeXml(sub)}</text>
245
+ ${g.svg}
246
+ <text x="28" y="${H - 24}" font-family="${MONO}" font-size="10" fill="${PALETTE.inkFaint}">${escapeXml(footer || 'claude-rpc.com')}</text>
247
+ ${legend(W - 66, H - 34, metric)}`;
248
+ return frame(W, H, inner, `Claude Code ${what} heatmap`);
249
+ }
250
+
251
+ // ── stats card with heatmap (GET /stats/<h>.svg, `calendar --card`) ──────
252
+
253
+ function tile(x, y, w, value, label, color) {
254
+ return `<g transform="translate(${x} ${y})">
255
+ <rect x="2" y="3" width="${w}" height="64" fill="${PALETTE.ink}"/>
256
+ <rect x="0" y="0" width="${w}" height="64" fill="${PALETTE.paper2}" stroke="${PALETTE.ink}" stroke-width="1.5"/>
257
+ <rect x="0" y="0" width="5" height="64" fill="${color}"/>
258
+ <text x="18" y="35" font-family="${DISPLAY}" font-size="26" font-weight="800" letter-spacing="-0.5" fill="${color}">${escapeXml(value)}</text>
259
+ <text x="18" y="53" font-family="${MONO}" font-size="9.5" font-weight="700" letter-spacing="1.4" fill="${PALETTE.inkMute}">${escapeXml(label.toUpperCase())}</text>
260
+ </g>`;
261
+ }
262
+
263
+ function fact(x, y, label, value) {
264
+ return `<text x="${x}" y="${y}" font-family="${MONO}" font-size="9" font-weight="700" letter-spacing="1.3" fill="${PALETTE.inkFaint}">${escapeXml(label.toUpperCase())}</text>
265
+ <text x="${x}" y="${y + 18}" font-family="${DISPLAY}" font-size="15" font-weight="700" fill="${PALETTE.ink}">${escapeXml(value)}</text>`;
266
+ }
267
+
268
+ // p: { handle, displayName, verified, githubUser, tokens, sessions, activeMs, streak } | null
269
+ // series: the merged daily series (or null — profile predates heatmap sync).
270
+ // kicker: the subtitle's lead-in ('Claude Code' live; the local card passes
271
+ // its own so a handle-less render doesn't read "Claude Code · Claude Code").
272
+ export function renderStatsCard(p, series, { metric = 'tokens', footer, kicker = 'Claude Code' } = {}) {
273
+ metric = metricOf(metric);
274
+ const W = 880;
275
+ const has = !!p;
276
+ const hasSeries = has && !!series && isDayKey(series.end);
277
+ const name = clip(has ? (p.displayName || `@${p.handle}`) : 'claude-rpc', 30);
278
+ const verified = has && !!p.verified;
279
+ const what = metric === 'hours' ? 'hours' : 'tokens';
280
+ const f = seriesFacts(series, metric);
281
+ const sub = !has ? 'no public profile yet'
282
+ : !hasSeries ? `${kicker} · heatmap fills in after the next profile sync`
283
+ : `${kicker}${verified ? ' · verified' : ''} · ${f.activeDays} active days in the last year`;
284
+
285
+ const dash = '—';
286
+ const tw = 194, tg = 14, tx = 28, ty = 92;
287
+ const tiles = [
288
+ tile(tx, ty, tw, has ? fmtNum(p.tokens || 0) : dash, 'tokens', PALETTE.rust),
289
+ tile(tx + (tw + tg), ty, tw, has ? fmtNum(p.sessions || 0) : dash, 'sessions', PALETTE.blue),
290
+ tile(tx + (tw + tg) * 2, ty, tw, has ? fmtMinutes((p.activeMs || 0) / 60000) : dash, 'hours', PALETTE.amber),
291
+ tile(tx + (tw + tg) * 3, ty, tw, has ? `${p.streak || 0}d` : dash, 'streak', PALETTE.grass),
292
+ ].join('');
293
+
294
+ const gy = 204;
295
+ const g = grid(28, gy, series, metric, { empty: !hasSeries });
296
+ const fy = gy + g.height + 30;
297
+ const facts = hasSeries ? [
298
+ fact(58, fy, 'busiest day', f.busiest ? `${shortDate(f.busiest.date)} · ${fmtMetric(f.busiest.value, metric)}` : dash),
299
+ fact(258, fy, `avg / active day`, fmtMetric(f.avgPerActiveDay, metric)),
300
+ fact(428, fy, 'longest run', `${f.longestRun}d`),
301
+ fact(568, fy, 'best weekday', f.bestWeekday || dash),
302
+ ].join('') : '';
303
+ const H = fy + 62;
304
+ const gh = has && p.githubUser ? `github.com/${p.githubUser}` : 'claude-rpc.com';
305
+
306
+ const inner = `
307
+ ${spark(40, 45, 11, PALETTE.rust)}
308
+ <text x="60" y="54" font-family="${DISPLAY}" font-size="27" font-weight="800" letter-spacing="-1" fill="${PALETTE.ink}">${escapeXml(name)}</text>
309
+ <text x="61" y="74" font-family="${MONO}" font-size="12" fill="${PALETTE.inkMute}">${escapeXml(sub)}</text>
310
+ ${verified ? verifiedStamp(W - 44, 46) : ''}
311
+ ${tiles}
312
+ <text x="28" y="${gy - 24}" font-family="${MONO}" font-size="9" font-weight="700" letter-spacing="1.4" fill="${PALETTE.inkMute}">${escapeXml(`${what} per day · last 12 months`.toUpperCase())}</text>
313
+ ${g.svg}
314
+ ${facts}
315
+ ${legend(W - 66, fy + 4, metric)}
316
+ <text x="28" y="${H - 20}" font-family="${MONO}" font-size="10" fill="${PALETTE.inkFaint}">${escapeXml(footer || gh)}</text>
317
+ <text x="${W - 30}" y="${H - 20}" text-anchor="end" font-family="${MONO}" font-size="10" fill="${PALETTE.inkFaint}">claude-rpc.com</text>`;
318
+ return frame(W, H, inner, `Claude Code stats: ${name}`);
319
+ }
320
+
321
+ // ── series merge (worker: one person, several machines) ──────────────────
322
+
323
+ // Sum several machines' series day-by-day onto one grid ending at `end`.
324
+ // Token and minute totals from different machines come from DIFFERENT
325
+ // transcripts, so summing is right (unlike calendar-day counts, which overlap).
326
+ export function mergeSeries(list, end, days = HEATMAP_DAYS) {
327
+ const endMs = dayToMs(end);
328
+ const tokens = new Array(days).fill(0), activeMin = new Array(days).fill(0);
329
+ let any = false;
330
+ for (const s of list) {
331
+ if (!s || !isDayKey(s.end)) continue;
332
+ any = true;
333
+ const shift = Math.round((endMs - dayToMs(s.end)) / DAY_MS); // days s.end is before `end`
334
+ for (const [src, dst] of [[s.tokens || [], tokens], [s.activeMin || [], activeMin]]) {
335
+ for (let i = 0; i < src.length; i++) {
336
+ const idx = days - 1 - shift - (src.length - 1 - i);
337
+ if (idx >= 0 && idx < days) dst[idx] += Number(src[i]) || 0;
338
+ }
339
+ }
340
+ }
341
+ return any ? { end, tokens, activeMin } : null;
342
+ }
package/src/install.js CHANGED
@@ -20,6 +20,7 @@ import {
20
20
  import { DEFAULT_CONFIG } from './default-config.js';
21
21
  import { VERSION } from './version.js';
22
22
  import { c, SYM_OK, SYM_WARN, SYM_FAIL, SYM_INFO, hintLine } from './ui.js';
23
+ import { inferLegacyVerifyIntent } from './verify.js';
23
24
 
24
25
  const STARTUP_KEY = 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run';
25
26
  const STARTUP_VALUE = 'ClaudeRPC';
@@ -534,6 +535,17 @@ export function migrateConfig({ silent = false } = {}) {
534
535
  added.push('presence.byStatus.thinking.state');
535
536
  }
536
537
 
538
+ // v1.4.3: setup's "connect GitHub?" y could die on a server error (the
539
+ // 2026-08-20 → 09-11 KV write-cap outage 500'd /verify/start most of every
540
+ // day) and was never asked again. 1.4.0–1.4.2 recorded no intent, so infer
541
+ // it from the yes-path's footprint; the daemon then finishes the verification
542
+ // in the background (src/verify.js). Undated — the worker back-dates to the
543
+ // profile's first successful write instead.
544
+ if (inferLegacyVerifyIntent(cfg.profile)) {
545
+ cfg.profile.verifyPending = { since: null };
546
+ added.push('profile.verifyPending (resume GitHub connect)');
547
+ }
548
+
537
549
  // v0.7: community.enabled flipped to true in DEFAULT_CONFIG. For users
538
550
  // upgrading from a version without a community block, we must NOT
539
551
  // silently turn telemetry on — write an explicit `enabled: false` so
package/src/mcp.js CHANGED
@@ -17,7 +17,8 @@ function fmtN(n) {
17
17
  if (n < 1000) return String(Math.round(n));
18
18
  if (n < 1e6) return `${(n / 1e3).toFixed(1)}k`;
19
19
  if (n < 1e9) return `${(n / 1e6).toFixed(2)}M`;
20
- return `${(n / 1e9).toFixed(2)}B`;
20
+ if (n < 1e12) return `${(n / 1e9).toFixed(2)}B`;
21
+ return `${(n / 1e12).toFixed(2)}T`;
21
22
  }
22
23
 
23
24
  // ── Tool handlers — pure(aggregate) → string. Exported for tests. ──────────
package/src/recap.js CHANGED
@@ -34,7 +34,8 @@ function fmtN(n) {
34
34
  if (n < 1000) return String(Math.round(n));
35
35
  if (n < 1e6) return `${(n / 1e3).toFixed(1)}k`;
36
36
  if (n < 1e9) return `${(n / 1e6).toFixed(2)}M`;
37
- return `${(n / 1e9).toFixed(2)}B`;
37
+ if (n < 1e12) return `${(n / 1e9).toFixed(2)}B`;
38
+ return `${(n / 1e12).toFixed(2)}T`;
38
39
  }
39
40
 
40
41
  function dayKeyAt(now, offsetDays) {
@@ -49,7 +49,8 @@
49
49
  if (n < 1000) return String(n);
50
50
  if (n < 1e6) return (n / 1e3).toFixed(1) + 'k';
51
51
  if (n < 1e9) return (n / 1e6).toFixed(2) + 'M';
52
- return (n / 1e9).toFixed(2) + 'B';
52
+ if (n < 1e12) return (n / 1e9).toFixed(2) + 'B';
53
+ return (n / 1e12).toFixed(2) + 'T';
53
54
  };
54
55
  const fmtCost = (usd) => {
55
56
  if (!usd) return '$0';
@@ -8,7 +8,8 @@
8
8
  if (n < 1000) return String(Math.round(n));
9
9
  if (n < 1e6) return (n / 1e3).toFixed(1).replace(/\.0$/, '') + 'k';
10
10
  if (n < 1e9) return (n / 1e6).toFixed(2).replace(/\.?0+$/, '') + 'M';
11
- return (n / 1e9).toFixed(2).replace(/\.?0+$/, '') + 'B';
11
+ if (n < 1e12) return (n / 1e9).toFixed(2).replace(/\.?0+$/, '') + 'B';
12
+ return (n / 1e12).toFixed(2).replace(/\.?0+$/, '') + 'T';
12
13
  };
13
14
  const fmtHours = (ms) => { const h = (ms || 0) / 3.6e6; return h < 1 ? Math.round(h * 60) + 'm' : h < 10 ? h.toFixed(1) + 'h' : Math.round(h) + 'h'; };
14
15
  const esc = (s) => String(s == null ? '' : s).replace(/[&<>]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;' }[c]));