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/README.md +16 -2
- package/SECURITY.md +28 -1
- package/package.json +1 -1
- package/src/calendar.js +35 -81
- package/src/claude-proc.js +12 -6
- package/src/cli.js +95 -68
- package/src/community.js +27 -1
- package/src/daemon.js +7 -0
- package/src/default-config.js +3 -0
- package/src/fmt.js +3 -3
- package/src/gist.js +7 -2
- package/src/heatmap.js +342 -0
- package/src/install.js +12 -0
- package/src/mcp.js +2 -1
- package/src/recap.js +2 -1
- package/src/server/assets/dashboard.client.js +2 -1
- package/src/server/assets/wrapped.client.js +2 -1
- package/src/verify.js +239 -0
- package/src/version.js +1 -1
package/README.md
CHANGED
|
@@ -147,7 +147,19 @@ claude-rpc readme # prints paste-ready README badge markdown
|
|
|
147
147
|
claude-rpc readme --raw | pbcopy # straight to your clipboard
|
|
148
148
|
```
|
|
149
149
|
|
|
150
|
-
**Live
|
|
150
|
+
**Live stats + year heatmap, paste once.** With a public profile (`claude-rpc profile set --handle <you> && claude-rpc profile on`), the community worker serves an always-current stats card with your last 12 months as a heatmap. You don't need `gh` or a gist, and there's nothing to re-run:
|
|
151
|
+
|
|
152
|
+
```md
|
|
153
|
+
[](https://claude-rpc.com/u/<you>)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
<div align="center">
|
|
157
|
+
<img src="site/examples/stats-heatmap.svg" width="680" alt="Stats card: lifetime tokens, sessions, hours and streak above a 12-month heatmap of tokens per day, with busiest day, daily average, longest run and best weekday" />
|
|
158
|
+
</div>
|
|
159
|
+
|
|
160
|
+
`?metric=hours` shades the grid by time instead of tokens. `/heatmap/<you>.svg` is the grid on its own. If you link several machines, their days are added together. Shading is relative to your own year, so light and heavy users both get a readable map. To publish lifetime totals only, set `"profile": { "heatmap": false }` in config.json; the next flush also clears the stored days.
|
|
161
|
+
|
|
162
|
+
The smaller card and badges are still there:
|
|
151
163
|
|
|
152
164
|
```md
|
|
153
165
|
[](https://claude-rpc.com/u/<you>)
|
|
@@ -164,6 +176,8 @@ claude-rpc badge --metric hours --range 7d --out claude-hours.svg
|
|
|
164
176
|
claude-rpc badge --metric streak --out claude-streak.svg
|
|
165
177
|
claude-rpc badge --metric hours --gist # publish to a gist (live README badge)
|
|
166
178
|
claude-rpc card --range year --out year-on-claude.svg
|
|
179
|
+
claude-rpc calendar --metric tokens --out heatmap.svg # year heatmap (hours by default)
|
|
180
|
+
claude-rpc calendar --card --out stats.svg # stats + heatmap, offline
|
|
167
181
|
```
|
|
168
182
|
|
|
169
183
|
<div align="center">
|
|
@@ -314,7 +328,7 @@ It's a thin bootstrapper — on the first session it just runs `npx claude-rpc@l
|
|
|
314
328
|
| `badge` | Shields-style SVG (`--metric` `--range` `--out` `--gist`) |
|
|
315
329
|
| `card` | Poster-style SVG (`--range year\|month\|week\|all`) |
|
|
316
330
|
| `github-stat` | Embeddable profile stat card (`--handle` `--out` `--gist`) |
|
|
317
|
-
| `calendar` | Year activity heatmap SVG (`--out` `--gist`) |
|
|
331
|
+
| `calendar` | Year activity heatmap SVG (`--metric hours\|tokens` `--card` `--out` `--gist`) |
|
|
318
332
|
| `session-card` | Recap card for the current session (`--out`) |
|
|
319
333
|
| `readme` | Paste-ready README badge markdown for your profile (`--raw` to pipe) |
|
|
320
334
|
| `statusline` | One-line status for tmux/shell prompts (`--template`) |
|
package/SECURITY.md
CHANGED
|
@@ -199,7 +199,8 @@ anonymous 3a report, this one carries your chosen public identity. The
|
|
|
199
199
|
"sessions": 1200,
|
|
200
200
|
"activeMs": 360000000,
|
|
201
201
|
"streak": 23,
|
|
202
|
-
"
|
|
202
|
+
"daily": { "end": "2026-10-02", "tokens": [0, 41200000, …], "activeMin": [0, 95, …] },
|
|
203
|
+
"version": "1.5.0",
|
|
203
204
|
"osFamily": "linux",
|
|
204
205
|
"ts": 1716500000000
|
|
205
206
|
}
|
|
@@ -208,6 +209,15 @@ anonymous 3a report, this one carries your chosen public identity. The
|
|
|
208
209
|
It sends absolute totals (not deltas) and is idempotent worker-side (a SET, not
|
|
209
210
|
an add). `profile off` stops it.
|
|
210
211
|
|
|
212
|
+
**Per-day series (v1.5).** `daily` holds up to 371 days of two numbers per
|
|
213
|
+
**local** calendar day: total tokens and active minutes. It contains no project,
|
|
214
|
+
file, model or prompt data. It feeds the public `/heatmap/<handle>.svg` and
|
|
215
|
+
`/stats/<handle>.svg` images, which show anyone *which days* you used Claude
|
|
216
|
+
Code and how heavily. That reveals more than lifetime totals do, so there's a
|
|
217
|
+
switch: `"profile": { "heatmap": false }` sends `daily: null`, which deletes
|
|
218
|
+
the stored series on the next flush and keeps it off from then on. The series
|
|
219
|
+
is never returned by `GET /profile` or `/leaderboard`.
|
|
220
|
+
|
|
211
221
|
**The setup-time "connect GitHub?" question.** Since v1.4, an interactive
|
|
212
222
|
`claude-rpc setup` ends with one explicit y/N: *connect GitHub?* Answering
|
|
213
223
|
**y** runs the standard opt-in flow above (public profile, handle defaulting
|
|
@@ -218,6 +228,23 @@ non-interactive setups are never asked. There is no private identity tier:
|
|
|
218
228
|
the only way claude-rpc ever learns a GitHub identity is this same public,
|
|
219
229
|
consented profile flow.
|
|
220
230
|
|
|
231
|
+
**Background retry of a consented verification (v1.4.3).** Answering **y**
|
|
232
|
+
(or running `profile verify`) records a local `profile.verifyPending` marker
|
|
233
|
+
before any network step. If the server can't confirm the verification right
|
|
234
|
+
then, the daemon retries the *same* gist flow in the background after its
|
|
235
|
+
profile flush — backing off from 30 minutes to 12 hours, reusing one proof
|
|
236
|
+
gist rather than publishing new ones, and going quiet after 14 days (the
|
|
237
|
+
marker keeps `gaveUpAt`; `profile verify` restarts it). It only ever proves the
|
|
238
|
+
GitHub login you connected: if the `gh` CLI is logged out or has switched to a
|
|
239
|
+
different account, it waits and sends nothing. `profile off` pauses it;
|
|
240
|
+
`link` or a successful verify clears it. Upgrading from 1.4.0–1.4.2 infers the
|
|
241
|
+
marker only for installs whose config shows setup's yes-path (asked, a GitHub
|
|
242
|
+
login stored, publishing on, never verified) — the installs whose connect
|
|
243
|
+
failed during the 2026-08-20 → 09-11 server outage. The retry adds two
|
|
244
|
+
optional fields to `/verify/check` — `resumed: true` and `pendingSince` (the
|
|
245
|
+
local consent timestamp) — which the worker uses only to back-date an
|
|
246
|
+
internal, non-public `verifiedAt` stamp.
|
|
247
|
+
|
|
221
248
|
**Claude Wrapped (opt-in one-shot, never automatic).** `claude-rpc wrapped
|
|
222
249
|
--publish` publishes a year-in-review blob under your profile handle to
|
|
223
250
|
`<endpoint>/wrapped`, rendered at `claude-rpc.com/wrapped/<handle>`. It never
|
package/package.json
CHANGED
package/src/calendar.js
CHANGED
|
@@ -1,94 +1,48 @@
|
|
|
1
1
|
// Activity calendar — a GitHub-contributions-style year heatmap of Claude
|
|
2
2
|
// Code activity, rendered as an embeddable SVG (paper/terracotta brand).
|
|
3
|
-
// `claude-rpc calendar --out cal.svg [--gist]`.
|
|
3
|
+
// `claude-rpc calendar [--metric tokens|hours] [--card] --out cal.svg [--gist]`.
|
|
4
|
+
//
|
|
5
|
+
// Drawing lives in heatmap.js, shared with the worker's live /heatmap and
|
|
6
|
+
// /stats endpoints, so a local render and the live README card look the same.
|
|
4
7
|
|
|
5
|
-
import {
|
|
8
|
+
import { buildDailySeries } from './community.js';
|
|
9
|
+
import { renderHeatmap, renderStatsCard } from './heatmap.js';
|
|
6
10
|
import { localDateStamp } from './fmt.js';
|
|
7
11
|
import { VERSION } from './version.js';
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
ink: '#1a1611',
|
|
12
|
-
inkMute:'#5c5147',
|
|
13
|
-
inkFaint:'#8a7c6d',
|
|
14
|
-
empty: '#e1d6c0',
|
|
15
|
-
l1: '#f6dccb',
|
|
16
|
-
l2: '#f08a4a',
|
|
17
|
-
l3: '#c2491e',
|
|
18
|
-
l4: '#8f3415',
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const MONTHS = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
|
|
22
|
-
|
|
23
|
-
function escapeXml(s) {
|
|
24
|
-
return String(s == null ? '' : s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
13
|
+
function lifetimeTokens(a) {
|
|
14
|
+
return (a?.inputTokens || 0) + (a?.outputTokens || 0) + (a?.cacheReadTokens || 0) + (a?.cacheWriteTokens || 0);
|
|
25
15
|
}
|
|
26
16
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return 4;
|
|
17
|
+
export function renderCalendar(aggregate, { metric = 'hours', generatedAt = new Date() } = {}) {
|
|
18
|
+
const series = buildDailySeries(aggregate, generatedAt.getTime());
|
|
19
|
+
return renderHeatmap({
|
|
20
|
+
series,
|
|
21
|
+
metric,
|
|
22
|
+
footer: `as of ${localDateStamp(generatedAt)} · claude-rpc.com · v${VERSION}`,
|
|
23
|
+
});
|
|
35
24
|
}
|
|
36
|
-
const FILL = [PALETTE.empty, PALETTE.l1, PALETTE.l2, PALETTE.l3, PALETTE.l4];
|
|
37
|
-
|
|
38
|
-
export function renderCalendar(aggregate, { weeks = 53, generatedAt = new Date() } = {}) {
|
|
39
|
-
const byDay = aggregate?.byDay || {};
|
|
40
|
-
const cell = 12, gap = 3, step = cell + gap;
|
|
41
|
-
const padX = 36, padTop = 68, padBottom = 30;
|
|
42
|
-
|
|
43
|
-
// Build the grid ending today. Align the last column to today's weekday so
|
|
44
|
-
// rows read Sun..Sat like GitHub. We render `weeks` columns back from today.
|
|
45
|
-
const today = new Date(generatedAt);
|
|
46
|
-
today.setHours(0, 0, 0, 0);
|
|
47
|
-
const todayDow = today.getDay(); // 0=Sun
|
|
48
|
-
const totalDays = (weeks - 1) * 7 + todayDow + 1;
|
|
49
|
-
|
|
50
|
-
let cells = '';
|
|
51
|
-
let monthLabels = '';
|
|
52
|
-
let lastMonth = -1;
|
|
53
|
-
let totalActiveMs = 0, activeDays = 0;
|
|
54
|
-
|
|
55
|
-
for (let i = 0; i < totalDays; i++) {
|
|
56
|
-
const d = new Date(today);
|
|
57
|
-
d.setDate(d.getDate() - (totalDays - 1 - i));
|
|
58
|
-
const col = Math.floor(i / 7);
|
|
59
|
-
const row = d.getDay();
|
|
60
|
-
const key = dayKey(d);
|
|
61
|
-
const ms = byDay[key]?.activeMs || 0;
|
|
62
|
-
if (ms > 0) { totalActiveMs += ms; activeDays += 1; }
|
|
63
|
-
const x = padX + col * step;
|
|
64
|
-
const y = padTop + row * step;
|
|
65
|
-
cells += `<rect x="${x}" y="${y}" width="${cell}" height="${cell}" rx="2" fill="${FILL[level(ms)]}" stroke="${PALETTE.ink}" stroke-width="0.4"/>`;
|
|
66
|
-
// Month label when a new month starts in the top row region.
|
|
67
|
-
if (d.getMonth() !== lastMonth && d.getDate() <= 7) {
|
|
68
|
-
lastMonth = d.getMonth();
|
|
69
|
-
monthLabels += `<text x="${x}" y="${padTop - 9}" font-family="JetBrains Mono, ui-monospace, monospace" font-size="10" fill="${PALETTE.inkMute}">${MONTHS[d.getMonth()]}</text>`;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const W = padX + weeks * step + 14;
|
|
74
|
-
const H = padTop + 7 * step + padBottom;
|
|
75
|
-
const totalHours = (totalActiveMs / 3_600_000).toFixed(0);
|
|
76
|
-
let legend = '';
|
|
77
|
-
for (let l = 0; l < 5; l++) {
|
|
78
|
-
legend += `<rect x="${W - 150 + l * 16}" y="${H - 20}" width="${cell}" height="${cell}" rx="2" fill="${FILL[l]}" stroke="${PALETTE.ink}" stroke-width="0.4"/>`;
|
|
79
|
-
}
|
|
80
25
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
26
|
+
// Stats card + heatmap from the local aggregate — the offline twin of the
|
|
27
|
+
// worker's /stats/<handle>.svg.
|
|
28
|
+
export function renderCalendarCard(aggregate, { metric = 'tokens', handle = '', generatedAt = new Date() } = {}) {
|
|
29
|
+
const series = buildDailySeries(aggregate, generatedAt.getTime());
|
|
30
|
+
const h = String(handle || '').replace(/^@/, '');
|
|
31
|
+
const p = {
|
|
32
|
+
handle: h || 'you',
|
|
33
|
+
displayName: h ? null : 'Claude Code',
|
|
34
|
+
verified: false,
|
|
35
|
+
githubUser: null,
|
|
36
|
+
tokens: lifetimeTokens(aggregate),
|
|
37
|
+
sessions: aggregate?.sessions || 0,
|
|
38
|
+
activeMs: aggregate?.activeMs || 0,
|
|
39
|
+
streak: aggregate?.streak || 0,
|
|
40
|
+
};
|
|
41
|
+
return renderStatsCard(p, series, {
|
|
42
|
+
metric,
|
|
43
|
+
kicker: h ? 'Claude Code' : 'my year',
|
|
44
|
+
footer: `as of ${localDateStamp(generatedAt)} · v${VERSION}`,
|
|
45
|
+
});
|
|
92
46
|
}
|
|
93
47
|
|
|
94
48
|
export function calendarSvg({ aggregate } = {}) {
|
package/src/claude-proc.js
CHANGED
|
@@ -35,18 +35,24 @@ export function looksLikeClaudeCode(name, cmdline) {
|
|
|
35
35
|
const n = String(name || '').toLowerCase();
|
|
36
36
|
const c = String(cmdline || '').replace(/\\/g, '/').toLowerCase();
|
|
37
37
|
// The Claude DESKTOP app's binary is ALSO named claude(.exe) — Windows
|
|
38
|
-
// installs under …/AnthropicClaude/, macOS ships as Claude.app
|
|
39
|
-
// Claude Code; matching it
|
|
40
|
-
//
|
|
41
|
-
|
|
38
|
+
// installs under …/AnthropicClaude/, macOS ships as Claude.app, Linux builds
|
|
39
|
+
// as …/claude-desktop/claude-desktop. It is not Claude Code; matching it
|
|
40
|
+
// would pin the card up whenever the chat app is open. Path check comes
|
|
41
|
+
// first so nothing below can re-admit it.
|
|
42
|
+
if (c.includes('anthropicclaude') || c.includes('claude.app/') || c.includes('/claude-desktop')) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
42
45
|
// npm / npx install: node …/node_modules/@anthropic-ai/claude-code/cli.js
|
|
43
46
|
if (c.includes('@anthropic-ai/claude-code/')) return true;
|
|
44
47
|
// Native-install version store: …/.local/share/claude/versions/<v>
|
|
45
48
|
if (c.includes('/share/claude/versions/')) return true;
|
|
46
49
|
// A command-line token that IS `claude` / `claude.exe` — bare (as typed in a
|
|
47
50
|
// shell, argv[0] preserved) or as the tail of a path. The boundary required
|
|
48
|
-
// right after "claude" is what keeps claude-rpc from matching.
|
|
49
|
-
|
|
51
|
+
// right after "claude" is what keeps claude-rpc from matching. `--flag=value`
|
|
52
|
+
// tokens are dropped first: Electron children carry a profile path like
|
|
53
|
+
// --user-data-dir=/home/o/.config/Claude, which is a directory, not a binary.
|
|
54
|
+
const tokens = c.replace(/(^|\s)--?[\w-]+=("[^"]*"|\S*)/g, '$1');
|
|
55
|
+
if (/(^|[/"'])claude(\.exe)?["']?(\s|$)/.test(tokens)) return true;
|
|
50
56
|
// No command line to inspect (platform hid it) — fall back to the process
|
|
51
57
|
// name alone. Only safe here because the desktop-app exclusion above could
|
|
52
58
|
// not run; a bare-name match is still far likelier Code than the chat app
|
package/src/cli.js
CHANGED
|
@@ -1216,18 +1216,27 @@ function doStatusline(argv) {
|
|
|
1216
1216
|
}
|
|
1217
1217
|
|
|
1218
1218
|
// Activity calendar — GitHub-contributions-style year heatmap SVG.
|
|
1219
|
+
// --metric hours (default) | tokens; --card wraps it in the stats card.
|
|
1219
1220
|
async function doCalendar(argv) {
|
|
1220
1221
|
argv = splitEqArgs(argv);
|
|
1221
|
-
const opts = { out: '', gist: false };
|
|
1222
|
+
const opts = { out: '', gist: false, metric: 'hours', card: false };
|
|
1222
1223
|
for (let i = 0; i < argv.length; i++) {
|
|
1223
1224
|
if (argv[i] === '--out' || argv[i] === '-o') opts.out = takeValue(argv[++i], '--out');
|
|
1224
1225
|
else if (argv[i] === '--gist') opts.gist = true;
|
|
1226
|
+
else if (argv[i] === '--card') opts.card = true;
|
|
1227
|
+
else if (argv[i] === '--metric') opts.metric = takeValue(argv[++i], '--metric');
|
|
1228
|
+
}
|
|
1229
|
+
if (!['hours', 'tokens'].includes(opts.metric)) {
|
|
1230
|
+
fail(`unknown --metric \`${opts.metric}\``, { hint: 'use --metric hours or --metric tokens', code: EX_USER_ERROR });
|
|
1225
1231
|
}
|
|
1226
1232
|
const aggregate = readAggregate();
|
|
1227
1233
|
if (!aggregate) fail('no aggregate yet — nothing to render', { hint: 'run `claude-rpc scan` first', code: EX_BAD_STATE });
|
|
1228
|
-
const { renderCalendar } = await import('./calendar.js');
|
|
1229
|
-
const svg =
|
|
1230
|
-
|
|
1234
|
+
const { renderCalendar, renderCalendarCard } = await import('./calendar.js');
|
|
1235
|
+
const svg = opts.card
|
|
1236
|
+
? renderCalendarCard(aggregate, { metric: opts.metric, handle: loadConfig().profile?.handle })
|
|
1237
|
+
: renderCalendar(aggregate, { metric: opts.metric });
|
|
1238
|
+
const kind = opts.card ? 'stats' : 'calendar';
|
|
1239
|
+
if (opts.gist) return publishBadgeToGist(svg, { metric: kind, range: 'year' }, kind);
|
|
1231
1240
|
if (opts.out) {
|
|
1232
1241
|
writeFileSync(opts.out, svg);
|
|
1233
1242
|
console.log(` ${c.green}✓${c.reset} wrote ${c.cyan}${opts.out}${c.reset} ${c.dim}(${svg.length} bytes)${c.reset}`);
|
|
@@ -1268,12 +1277,13 @@ function doReadme(argv) {
|
|
|
1268
1277
|
['streak', 'Claude Code streak'],
|
|
1269
1278
|
['tokens', 'Claude Code tokens'],
|
|
1270
1279
|
];
|
|
1271
|
-
// The hero:
|
|
1280
|
+
// The hero: live stats + year heatmap, auto-refreshing from your profile.
|
|
1281
|
+
const statsMd = (h) => `[](${site}/u/${h})`;
|
|
1272
1282
|
const cardMd = (h) => `[](${site}/u/${h})`;
|
|
1273
1283
|
const badgesMd = (h) => metrics
|
|
1274
1284
|
.map(([m, alt]) => `[](${site}/?ref=badge)`)
|
|
1275
1285
|
.join('\n');
|
|
1276
|
-
const liveMd = (h) => `${
|
|
1286
|
+
const liveMd = (h) => `${statsMd(h)}\n\n${badgesMd(h)}`;
|
|
1277
1287
|
|
|
1278
1288
|
// Raw mode: just the markdown, for `claude-rpc readme --raw | pbcopy`.
|
|
1279
1289
|
if (raw) {
|
|
@@ -1288,10 +1298,19 @@ function doReadme(argv) {
|
|
|
1288
1298
|
console.log('');
|
|
1289
1299
|
|
|
1290
1300
|
if (live) {
|
|
1291
|
-
console.log(` ${c.dim}Live
|
|
1301
|
+
console.log(` ${c.dim}Live stats + year heatmap for ${c.reset}${c.cyan}@${handle}${c.reset}${c.dim} — paste once; it auto-updates as you work:${c.reset}`);
|
|
1302
|
+
console.log('');
|
|
1303
|
+
console.log(` ${statsMd(handle)}`);
|
|
1304
|
+
if (profile.heatmap === false) {
|
|
1305
|
+
console.log(` ${c.yellow}profile.heatmap is off — the heatmap stays empty until you turn it back on${c.reset}`);
|
|
1306
|
+
}
|
|
1307
|
+
console.log('');
|
|
1308
|
+
console.log(` ${c.dim}…the compact card (totals only):${c.reset}`);
|
|
1292
1309
|
console.log('');
|
|
1293
1310
|
console.log(` ${cardMd(handle)}`);
|
|
1294
1311
|
console.log('');
|
|
1312
|
+
console.log(` ${c.dim}…just the heatmap:${c.reset} ${c.cyan}${endpoint}/heatmap/${handle}.svg${c.reset}${c.dim} (?metric=hours for time)${c.reset}`);
|
|
1313
|
+
console.log('');
|
|
1295
1314
|
console.log(` ${c.dim}…or compact badges:${c.reset}`);
|
|
1296
1315
|
console.log('');
|
|
1297
1316
|
for (const line of badgesMd(handle).split('\n')) console.log(` ${line}`);
|
|
@@ -1304,6 +1323,8 @@ function doReadme(argv) {
|
|
|
1304
1323
|
console.log(` ${c.cyan}claude-rpc profile set --handle <name> && claude-rpc profile on${c.reset}`);
|
|
1305
1324
|
console.log('');
|
|
1306
1325
|
console.log(` ${c.dim}Then your card + badges live here (self-refreshing — paste once):${c.reset}`);
|
|
1326
|
+
console.log(` ${c.cyan}${endpoint}/stats/<handle>.svg${c.reset} ${c.dim}# stats + year heatmap${c.reset}`);
|
|
1327
|
+
console.log(` ${c.cyan}${endpoint}/heatmap/<handle>.svg${c.reset}`);
|
|
1307
1328
|
console.log(` ${c.cyan}${endpoint}/card/<handle>.svg${c.reset}`);
|
|
1308
1329
|
console.log(` ${c.cyan}${endpoint}/badge/<handle>.svg?metric=hours${c.reset}`);
|
|
1309
1330
|
}
|
|
@@ -1680,8 +1701,9 @@ async function doLink(argv) {
|
|
|
1680
1701
|
// local handle or an explicit enabled:false is always respected.
|
|
1681
1702
|
const userCfg = readJson(CONFIG_PATH, {});
|
|
1682
1703
|
const prevProfile = userCfg.profile || {};
|
|
1704
|
+
const { verifyPending: _linked, ...prevRest } = prevProfile; // a link completes any pending gist verification
|
|
1683
1705
|
userCfg.profile = {
|
|
1684
|
-
...
|
|
1706
|
+
...prevRest,
|
|
1685
1707
|
githubUser: r.json.githubUser,
|
|
1686
1708
|
verified: true,
|
|
1687
1709
|
...(prevProfile.handle ? {} : { handle: r.json.handle }),
|
|
@@ -1902,6 +1924,10 @@ function profileStatus() {
|
|
|
1902
1924
|
// for terminals with no browser nearby.
|
|
1903
1925
|
if (!steps[2].done) {
|
|
1904
1926
|
lines.push('');
|
|
1927
|
+
const vp = p.verifyPending;
|
|
1928
|
+
if (vp && typeof vp === 'object' && !vp.gaveUpAt) {
|
|
1929
|
+
lines.push(`${c.yellow}…${c.reset} ${c.dim}a GitHub verification you started is pending — the daemon retries it automatically${vp.lastError ? ` (last: ${vp.lastError})` : ''}${c.reset}`);
|
|
1930
|
+
}
|
|
1905
1931
|
lines.push(`${c.dim}the code comes from${c.reset} ${c.cyan}claude-rpc link${c.reset} ${c.dim}on a machine you already verified${c.reset}`);
|
|
1906
1932
|
lines.push(`${c.dim}first machine? log in at${c.reset} ${c.cyan}${LINK_PAGE}${c.reset} ${c.dim}— or no browser:${c.reset} ${c.cyan}claude-rpc profile verify${c.reset}`);
|
|
1907
1933
|
}
|
|
@@ -2003,19 +2029,21 @@ async function profilePublish() {
|
|
|
2003
2029
|
|
|
2004
2030
|
// The gist-verification dance shared by `profile verify` and setup's optional
|
|
2005
2031
|
// GitHub-connect question: worker token → public proof gist → worker check →
|
|
2006
|
-
// persist the verified identity locally
|
|
2007
|
-
//
|
|
2008
|
-
//
|
|
2009
|
-
//
|
|
2010
|
-
//
|
|
2032
|
+
// persist the verified identity locally (core in src/verify.js, shared with the
|
|
2033
|
+
// daemon's background resume). Prints its own progress lines (they read the
|
|
2034
|
+
// same in both contexts) and returns { ok, who } on success. It never exits:
|
|
2035
|
+
// hard failures come back as { ok: false, fatal: {label, hint, code} } so
|
|
2036
|
+
// profileVerify can fail() loudly while setup — where the whole step is
|
|
2037
|
+
// optional — shrugs and finishes the install. Callers record consent
|
|
2038
|
+
// (withVerifyIntent) first, so a failure here leaves a pending marker the
|
|
2039
|
+
// daemon keeps retrying.
|
|
2011
2040
|
async function gistVerifyDance(cfg) {
|
|
2012
2041
|
const profile = cfg.profile || {};
|
|
2013
2042
|
const community = cfg.community || {};
|
|
2014
2043
|
if (!community.instanceId) {
|
|
2015
2044
|
return { ok: false, fatal: { label: 'enable the profile first', hint: 'claude-rpc profile on', code: EX_BAD_STATE } };
|
|
2016
2045
|
}
|
|
2017
|
-
|
|
2018
|
-
if (!endpoint) {
|
|
2046
|
+
if (!(community.endpoint || '').replace(/\/+$/, '')) {
|
|
2019
2047
|
return { ok: false, fatal: {
|
|
2020
2048
|
label: 'no community endpoint configured',
|
|
2021
2049
|
hint: 'config.json is missing community.endpoint — re-run `claude-rpc setup` to restore the default',
|
|
@@ -2023,67 +2051,57 @@ async function gistVerifyDance(cfg) {
|
|
|
2023
2051
|
} };
|
|
2024
2052
|
}
|
|
2025
2053
|
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
body: JSON.stringify(body),
|
|
2031
|
-
});
|
|
2032
|
-
return { status: res.status, json: await res.json().catch(() => ({})) };
|
|
2033
|
-
};
|
|
2034
|
-
|
|
2035
|
-
try {
|
|
2036
|
-
// Make sure the profile row exists server-side before we verify it, so
|
|
2037
|
-
// verification works regardless of whether `profile publish` was run first.
|
|
2038
|
-
if (lb.profileIsPublishable(profile)) {
|
|
2054
|
+
// Make sure the profile row exists server-side before we verify it, so
|
|
2055
|
+
// verification works regardless of whether `profile publish` was run first.
|
|
2056
|
+
if (lb.profileIsPublishable(profile)) {
|
|
2057
|
+
try {
|
|
2039
2058
|
const { flushProfile } = await import('./community.js');
|
|
2040
2059
|
await flushProfile(cfg);
|
|
2060
|
+
} catch { /* the check below reports a missing row */ }
|
|
2061
|
+
}
|
|
2062
|
+
const { runGistVerify, markVerifiedLocally, updateUserConfig } = await import('./verify.js');
|
|
2063
|
+
const pending = readJson(CONFIG_PATH, {}).profile?.verifyPending;
|
|
2064
|
+
const r = await runGistVerify(cfg, {
|
|
2065
|
+
onStep: (msg) => console.log(` ${c.dim}${msg}…${c.reset}`),
|
|
2066
|
+
gistId: pending?.gistId || null,
|
|
2067
|
+
pendingSince: pending?.since ?? null,
|
|
2068
|
+
resumed: !!pending,
|
|
2069
|
+
});
|
|
2070
|
+
if (r.ok) {
|
|
2071
|
+
const who = r.githubUser;
|
|
2072
|
+
markVerifiedLocally(who);
|
|
2073
|
+
console.log(` ${c.green}✓${c.reset} verified as ${c.cyan}@${who}${c.reset} — you'll show the ✓ on the board`);
|
|
2074
|
+
if (who && profile.githubUser && who.toLowerCase() !== profile.githubUser.toLowerCase()) {
|
|
2075
|
+
console.log(` ${c.dim}(your gist is owned by @${who}, so the profile now uses that account)${c.reset}`);
|
|
2041
2076
|
}
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
console.log(` ${c.dim}publishing a public proof gist…${c.reset}`);
|
|
2051
|
-
const gist = await publishGistFile({
|
|
2052
|
-
svg: `claude-rpc leaderboard verification\n${token}\n`,
|
|
2053
|
-
filename: 'claude-rpc-verify.txt',
|
|
2054
|
-
description: 'claude-rpc profile verification',
|
|
2055
|
-
isPublic: true,
|
|
2077
|
+
return { ok: true, who };
|
|
2078
|
+
}
|
|
2079
|
+
// Remember the proof gist so a retry (ours or the daemon's) edits it
|
|
2080
|
+
// instead of publishing another one.
|
|
2081
|
+
if (r.gistId) {
|
|
2082
|
+
updateUserConfig((u) => {
|
|
2083
|
+
if (!u.profile?.verifyPending) return false;
|
|
2084
|
+
u.profile.verifyPending = { ...u.profile.verifyPending, gistId: r.gistId };
|
|
2056
2085
|
});
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
// gist-list lag) and reads the real owner — instant, and the owner becomes
|
|
2060
|
-
// the verified identity regardless of what --github was set to.
|
|
2061
|
-
console.log(` ${c.dim}confirming with the server…${c.reset}`);
|
|
2062
|
-
const check = await post('/verify/check', { instanceId: community.instanceId, gistId: gist.id });
|
|
2063
|
-
if (check.json?.verified) {
|
|
2064
|
-
const who = check.json.githubUser || gist.owner || profile.githubUser;
|
|
2065
|
-
// Persist the authoritative owner + a local verified marker so the
|
|
2066
|
-
// profile checklist and future publishes match what got verified.
|
|
2067
|
-
const userCfg = readJson(CONFIG_PATH, {});
|
|
2068
|
-
userCfg.profile = { ...(userCfg.profile || {}), ...(who ? { githubUser: who } : {}), verified: true };
|
|
2069
|
-
writeUserConfig(userCfg);
|
|
2070
|
-
console.log(` ${c.green}✓${c.reset} verified as ${c.cyan}@${who}${c.reset} — you'll show the ✓ on the board`);
|
|
2071
|
-
if (who && profile.githubUser && who.toLowerCase() !== profile.githubUser.toLowerCase()) {
|
|
2072
|
-
console.log(` ${c.dim}(your gist is owned by @${who}, so the profile now uses that account)${c.reset}`);
|
|
2073
|
-
}
|
|
2074
|
-
return { ok: true, who };
|
|
2075
|
-
}
|
|
2086
|
+
}
|
|
2087
|
+
if (r.stage === 'check' && r.status >= 400 && r.status < 500) {
|
|
2076
2088
|
// Soft outcome (matches historical behavior): the message tells the user
|
|
2077
2089
|
// how to finish, and the process still exits 0.
|
|
2078
|
-
console.log(` ${c.yellow}!${c.reset} not confirmed: ${
|
|
2090
|
+
console.log(` ${c.yellow}!${c.reset} not confirmed: ${r.error}`);
|
|
2079
2091
|
console.log(` ${c.dim}↳ make sure the gist is public, then re-run ${c.reset}${c.cyan}claude-rpc profile verify${c.reset}`);
|
|
2080
2092
|
return { ok: false };
|
|
2081
|
-
}
|
|
2093
|
+
}
|
|
2094
|
+
if (r.stage === 'gist') {
|
|
2082
2095
|
return { ok: false, fatal: {
|
|
2083
|
-
label: `verification failed: ${
|
|
2096
|
+
label: `verification failed: ${r.error}`,
|
|
2084
2097
|
hint: 'needs `gh` logged in or GH_TOKEN with gist scope', code: EX_SYS_ERROR,
|
|
2085
2098
|
} };
|
|
2086
2099
|
}
|
|
2100
|
+
return { ok: false, fatal: {
|
|
2101
|
+
label: `${r.stage === 'start' ? 'verify/start' : 'verify/check'} failed: ${r.error}`,
|
|
2102
|
+
hint: 'the server may be having trouble — the daemon retries this automatically in the background',
|
|
2103
|
+
code: EX_SYS_ERROR,
|
|
2104
|
+
} };
|
|
2087
2105
|
}
|
|
2088
2106
|
|
|
2089
2107
|
// GitHub verification: ask the worker for a one-time token, publish it in a
|
|
@@ -2097,7 +2115,12 @@ async function profileVerify() {
|
|
|
2097
2115
|
if (!cfg.profile?.githubUser) {
|
|
2098
2116
|
console.log(` ${c.dim}no --github set — your verified identity will be the account that owns the proof gist${c.reset}`);
|
|
2099
2117
|
}
|
|
2100
|
-
|
|
2118
|
+
if (cfg.community?.instanceId) {
|
|
2119
|
+
// Consent to verify; if the server can't finish it now, the daemon retries.
|
|
2120
|
+
const { withVerifyIntent } = await import('./verify.js');
|
|
2121
|
+
writeUserConfig(withVerifyIntent(readJson(CONFIG_PATH, {})));
|
|
2122
|
+
}
|
|
2123
|
+
const r = await gistVerifyDance(loadConfig());
|
|
2101
2124
|
if (r.fatal) return fail(r.fatal.label, { hint: r.fatal.hint || '', code: r.fatal.code });
|
|
2102
2125
|
}
|
|
2103
2126
|
|
|
@@ -2149,8 +2172,12 @@ async function setupGhConnect() {
|
|
|
2149
2172
|
console.log(` ${c.yellow}!${c.reset} couldn't derive a handle from @${login} — run ${c.cyan}claude-rpc profile set --handle <you>${c.reset} then ${c.cyan}claude-rpc profile verify${c.reset}`);
|
|
2150
2173
|
return;
|
|
2151
2174
|
}
|
|
2175
|
+
// The y above is consent to the whole flow, so record it before any network
|
|
2176
|
+
// step: if the server can't finish it now, the daemon retries in the
|
|
2177
|
+
// background (src/verify.js) instead of the install sitting unverified.
|
|
2152
2178
|
userCfg.profile = { ...userCfg.profile, handle, githubUser: login, enabled: true };
|
|
2153
|
-
|
|
2179
|
+
const { withVerifyIntent } = await import('./verify.js');
|
|
2180
|
+
writeUserConfig(withVerifyIntent(userCfg));
|
|
2154
2181
|
console.log(` ${c.dim}connecting as ${c.reset}${c.cyan}@${login}${c.reset}${c.dim} — handle ${c.reset}${c.cyan}${handle}${c.reset}`);
|
|
2155
2182
|
|
|
2156
2183
|
// A fresh install has no aggregate yet; publish real totals, not zeros.
|
|
@@ -2164,7 +2191,7 @@ async function setupGhConnect() {
|
|
|
2164
2191
|
console.log(` ${c.green}✓${c.reset} you're live at ${c.cyan}https://claude-rpc.com/u/${encodeURIComponent(handle)}${c.reset}`);
|
|
2165
2192
|
} else {
|
|
2166
2193
|
if (r.fatal) console.log(` ${c.yellow}!${c.reset} ${r.fatal.label}`);
|
|
2167
|
-
console.log(` ${c.dim}↳ setup itself is done —
|
|
2194
|
+
console.log(` ${c.dim}↳ setup itself is done — the daemon keeps retrying this in the background, or run ${c.reset}${c.cyan}claude-rpc profile verify${c.reset}`);
|
|
2168
2195
|
}
|
|
2169
2196
|
}
|
|
2170
2197
|
|
|
@@ -2386,7 +2413,7 @@ function help() {
|
|
|
2386
2413
|
['card', 'Render a poster-style SVG summary (--range year|month|week|all)'],
|
|
2387
2414
|
['github-stat', 'Render an embeddable profile stat card (--handle --out --gist)'],
|
|
2388
2415
|
['statusline', 'One-line status for tmux/shell prompts (--template)'],
|
|
2389
|
-
['calendar', 'Year activity heatmap SVG (--out --gist)'],
|
|
2416
|
+
['calendar', 'Year activity heatmap SVG (--metric hours|tokens --card --out --gist)'],
|
|
2390
2417
|
['session-card', 'Recap card for the current session (--out)'],
|
|
2391
2418
|
['readme', 'Paste-ready README card + badges for your profile (--raw to pipe)'],
|
|
2392
2419
|
['mcp install', 'Wire the stats MCP server into Claude Code (one command)'],
|
package/src/community.js
CHANGED
|
@@ -25,7 +25,8 @@ import { AGGREGATE_PATH, STATE_DIR } from './paths.js';
|
|
|
25
25
|
import { VERSION } from './version.js';
|
|
26
26
|
import { profileIsPublishable } from './leaderboard.js';
|
|
27
27
|
import { projectNameIsPrivate } from './privacy.js';
|
|
28
|
-
import { cleanProjectName } from './scanner.js';
|
|
28
|
+
import { cleanProjectName, dayKey } from './scanner.js';
|
|
29
|
+
import { HEATMAP_DAYS } from './heatmap.js';
|
|
29
30
|
import { humanModel } from './format.js';
|
|
30
31
|
|
|
31
32
|
const CURSOR_PATH = join(STATE_DIR, 'community-cursor.json');
|
|
@@ -103,6 +104,28 @@ function totalTokens(aggregate) {
|
|
|
103
104
|
// cursor, no double-count risk, and the board matches your real aggregate
|
|
104
105
|
// exactly. (Deltas were wrong here: the first publish carried the entire
|
|
105
106
|
// lifetime total, which blew past the per-report caps for any established user.)
|
|
107
|
+
// The last year of per-day tokens + active minutes, for the live heatmap
|
|
108
|
+
// (/heatmap/<h>.svg, /stats/<h>.svg). Keyed by LOCAL date like aggregate.byDay;
|
|
109
|
+
// oldest → newest with leading empty days trimmed. Only day totals — nothing
|
|
110
|
+
// about projects, files, or prompts. Opt out with profile.heatmap: false.
|
|
111
|
+
export function buildDailySeries(aggregate, now = Date.now(), days = HEATMAP_DAYS) {
|
|
112
|
+
const byDay = aggregate?.byDay || {};
|
|
113
|
+
const tokens = [], activeMin = [];
|
|
114
|
+
const d = new Date(now);
|
|
115
|
+
d.setHours(12, 0, 0, 0); // noon: DST shifts can't skip or repeat a date
|
|
116
|
+
const end = dayKey(d.getTime());
|
|
117
|
+
d.setDate(d.getDate() - (days - 1));
|
|
118
|
+
for (let i = 0; i < days; i++) {
|
|
119
|
+
const b = byDay[dayKey(d.getTime())];
|
|
120
|
+
tokens.push(b ? totalTokens(b) : 0);
|
|
121
|
+
activeMin.push(b ? Math.round((b.activeMs || 0) / 60_000) : 0);
|
|
122
|
+
d.setDate(d.getDate() + 1);
|
|
123
|
+
}
|
|
124
|
+
let first = 0;
|
|
125
|
+
while (first < days && !tokens[first] && !activeMin[first]) first++;
|
|
126
|
+
return { end, tokens: tokens.slice(first), activeMin: activeMin.slice(first) };
|
|
127
|
+
}
|
|
128
|
+
|
|
106
129
|
export function buildProfilePayload(aggregate, profileCfg, { instanceId, now = Date.now() }) {
|
|
107
130
|
return {
|
|
108
131
|
instanceId,
|
|
@@ -113,6 +136,9 @@ export function buildProfilePayload(aggregate, profileCfg, { instanceId, now = D
|
|
|
113
136
|
sessions: aggregate?.sessions || 0,
|
|
114
137
|
activeMs: aggregate?.activeMs || 0,
|
|
115
138
|
streak: aggregate?.streak || 0,
|
|
139
|
+
// null (not omitted) on opt-out: the worker keeps a stored series when the
|
|
140
|
+
// field is absent (older clients), so clearing has to be explicit.
|
|
141
|
+
daily: profileCfg.heatmap === false ? null : buildDailySeries(aggregate, now),
|
|
116
142
|
version: VERSION,
|
|
117
143
|
osFamily: osFamily(),
|
|
118
144
|
ts: now,
|
package/src/daemon.js
CHANGED
|
@@ -943,6 +943,13 @@ async function runCommunityFlush() {
|
|
|
943
943
|
} else if (!pr.ok && pr.reason !== 'rate-limited' && pr.reason !== 'disabled') {
|
|
944
944
|
log(`profile: ${pr.reason}${pr.error ? ' (' + pr.error + ')' : ''}`);
|
|
945
945
|
}
|
|
946
|
+
// A GitHub connect the user said yes to but the server never confirmed
|
|
947
|
+
// (e.g. the Aug–Sep 2026 KV write-cap outage) — finish it now that the
|
|
948
|
+
// row just published. Self-scheduling and a no-op without a pending marker.
|
|
949
|
+
if (pr.ok && config.profile?.verifyPending) {
|
|
950
|
+
const { resumePendingVerify } = await import('./verify.js');
|
|
951
|
+
await resumePendingVerify(config, { log });
|
|
952
|
+
}
|
|
946
953
|
}
|
|
947
954
|
} catch (e) {
|
|
948
955
|
log('community/profile flush threw:', e.message);
|
package/src/default-config.js
CHANGED
|
@@ -165,6 +165,9 @@ export const DEFAULT_CONFIG = {
|
|
|
165
165
|
handle: null,
|
|
166
166
|
displayName: null,
|
|
167
167
|
githubUser: null,
|
|
168
|
+
// Also publish per-day token + active-minute totals (last year) so the
|
|
169
|
+
// live /heatmap and /stats cards can draw your year. false = totals only.
|
|
170
|
+
heatmap: true,
|
|
168
171
|
},
|
|
169
172
|
showElapsed: true,
|
|
170
173
|
activityType: 0,
|