claude-rpc 1.7.0 → 1.7.1
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 +2 -0
- package/package.json +1 -1
- package/src/card.js +3 -2
- package/src/cli.js +32 -0
- package/src/commands.js +4 -0
- package/src/share.js +76 -0
- package/src/version.js +1 -1
package/README.md
CHANGED
|
@@ -145,6 +145,7 @@ The web dashboard pushes updates via SSE; the TUI refreshes on a 3-second tick.
|
|
|
145
145
|
Stat cards and badges for a README, a site or a Discord message, all from one command. Run it bare for a menu: pick a card, then a **live link** (paste once, it refreshes itself), a **PNG** or an **SVG**:
|
|
146
146
|
|
|
147
147
|
```sh
|
|
148
|
+
claude-rpc share # poster PNG + a ready caption on your clipboard
|
|
148
149
|
claude-rpc statcards # menu: card → link / PNG / SVG
|
|
149
150
|
claude-rpc statcards stats --link --md | pbcopy # README markdown, straight to the clipboard
|
|
150
151
|
claude-rpc statcards poster --png # ./claude-poster.png, 2× for Discord / X
|
|
@@ -327,6 +328,7 @@ It's a thin bootstrapper — on the first session it just runs `npx claude-rpc@l
|
|
|
327
328
|
| `serve` | The local web dashboard (port 47474) |
|
|
328
329
|
| `export` | The aggregate as JSON, or daily rows as CSV (`--csv` `--out`) |
|
|
329
330
|
| **Share** | |
|
|
331
|
+
| `share [week\|month\|year\|all]` | Saves the poster PNG and copies a caption with your numbers and a link (`--no-png`, `--no-copy`, `--png <file>`) |
|
|
330
332
|
| `statcards [card]` | Cards and badges as a live link, PNG or SVG: `stats` `profile` `badge` `heatmap` `poster` `session` `wrapped` (`--link` `--png [file]` `--svg [file]` `--md` `--html` `--metric` `--range` `--copy`; bare = menu) |
|
|
331
333
|
| `statusline` | One-line status for tmux/shell prompts (`--template`) |
|
|
332
334
|
| `mcp` | The stats MCP server (stdio); `mcp install` / `mcp uninstall` wire it into Claude Code |
|
package/package.json
CHANGED
package/src/card.js
CHANGED
|
@@ -51,8 +51,9 @@ function rangeTitle(range) {
|
|
|
51
51
|
return `${rl} on claude`;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
// Roll up a windowed metric across the active range.
|
|
55
|
-
|
|
54
|
+
// Roll up a windowed metric across the active range. Exported for share.js's
|
|
55
|
+
// caption, so the text and the poster count the same window.
|
|
56
|
+
export function rollup(aggregate, range) {
|
|
56
57
|
const window = pickWindow(aggregate?.byDay, range);
|
|
57
58
|
const out = {
|
|
58
59
|
activeMs: 0,
|
package/src/cli.js
CHANGED
|
@@ -2395,6 +2395,30 @@ async function doCompletion(argv) {
|
|
|
2395
2395
|
}
|
|
2396
2396
|
|
|
2397
2397
|
// Offer tab completion once during a first setup, on a terminal only.
|
|
2398
|
+
// One y/N at the end of `setup`, asked at most once ever: join the community
|
|
2399
|
+
// Discord. y opens the invite in the browser (the link is printed too, for
|
|
2400
|
+
// headless boxes); n changes nothing. The ?s=cli tag is the join attribution.
|
|
2401
|
+
const DISCORD_JOIN_URL = 'https://claude-rpc.com/discord?s=cli';
|
|
2402
|
+
async function setupDiscordOffer() {
|
|
2403
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) return;
|
|
2404
|
+
if (readJson(CONFIG_PATH, {}).discordAsked) return;
|
|
2405
|
+
const answer = (await prompt(` join the claude-rpc Discord? ${c.dim}help, card showcase, weekly leaderboard [y/N]${c.reset} `)).trim();
|
|
2406
|
+
// Top-level, not under community: that block's presence is the telemetry
|
|
2407
|
+
// consent marker migrateConfig reads.
|
|
2408
|
+
writeUserConfig({ ...readJson(CONFIG_PATH, {}), discordAsked: true });
|
|
2409
|
+
if (!/^y(es)?$/i.test(answer)) return;
|
|
2410
|
+
try {
|
|
2411
|
+
const { spawn } = await import('node:child_process');
|
|
2412
|
+
const [cmd, args] = process.platform === 'win32' ? ['cmd', ['/c', 'start', '', DISCORD_JOIN_URL]]
|
|
2413
|
+
: process.platform === 'darwin' ? ['open', [DISCORD_JOIN_URL]]
|
|
2414
|
+
: ['xdg-open', [DISCORD_JOIN_URL]];
|
|
2415
|
+
const child = spawn(cmd, args, { detached: true, stdio: 'ignore', windowsHide: true });
|
|
2416
|
+
child.on('error', () => {});
|
|
2417
|
+
child.unref();
|
|
2418
|
+
} catch { /* no opener — the printed link below covers it */ }
|
|
2419
|
+
console.log(` ${c.green}✓${c.reset} ${c.dim}opening${c.reset} ${c.cyan}${DISCORD_JOIN_URL}${c.reset}`);
|
|
2420
|
+
}
|
|
2421
|
+
|
|
2398
2422
|
async function setupCompletionOffer() {
|
|
2399
2423
|
if (!process.stdin.isTTY || !process.stdout.isTTY || process.env.CLAUDE_RPC_NO_COMPLETION) return;
|
|
2400
2424
|
const comp = await import('./completion.js');
|
|
@@ -2413,6 +2437,12 @@ async function setupCompletionOffer() {
|
|
|
2413
2437
|
}
|
|
2414
2438
|
}
|
|
2415
2439
|
|
|
2440
|
+
async function doShare(argv) {
|
|
2441
|
+
const { runShare } = await import('./share.js');
|
|
2442
|
+
const { copyToClipboard } = await import('./statcards.js');
|
|
2443
|
+
await runShare(argv, { aggregate: () => aggregateOr('render'), copy: copyToClipboard });
|
|
2444
|
+
}
|
|
2445
|
+
|
|
2416
2446
|
async function doStatcards(argv) {
|
|
2417
2447
|
const { runStatcards } = await import('./statcards.js');
|
|
2418
2448
|
await runStatcards(argv, {
|
|
@@ -2470,6 +2500,7 @@ process.on('unhandledRejection', (e) => {
|
|
|
2470
2500
|
case '__complete': await doComplete(args); break;
|
|
2471
2501
|
case 'completion': await doCompletion(args); break;
|
|
2472
2502
|
case 'statcards': await doStatcards(args); break;
|
|
2503
|
+
case 'share': await doShare(args); break;
|
|
2473
2504
|
// `setup` and `install` are aliases as of v0.7: both register hooks AND
|
|
2474
2505
|
// the login autostart entry (Windows Run key, macOS LaunchAgent, Linux
|
|
2475
2506
|
// systemd --user unit). Older behavior split them (setup = no startup,
|
|
@@ -2554,6 +2585,7 @@ process.on('unhandledRejection', (e) => {
|
|
|
2554
2585
|
// Optional GitHub connect — one explicit y/N, asked at most once ever.
|
|
2555
2586
|
// The --link path above IS a connect, so it never double-asks.
|
|
2556
2587
|
if (!linkCode) await setupGhConnect();
|
|
2588
|
+
await setupDiscordOffer();
|
|
2557
2589
|
if (changed) await setupCompletionOffer();
|
|
2558
2590
|
}
|
|
2559
2591
|
setupOutro(target, changed, cli);
|
package/src/commands.js
CHANGED
|
@@ -67,6 +67,10 @@ export const COMMANDS = [
|
|
|
67
67
|
flags: [['--csv', 'Daily rows as CSV'], ['--out', 'Write to a file', 'file']] },
|
|
68
68
|
|
|
69
69
|
// ── Share ──
|
|
70
|
+
{ name: 'share', group: 'share', summary: 'Poster PNG + a ready caption on your clipboard', usage: '[week|month|year|all]',
|
|
71
|
+
subs: [['week', 'Last 7 days (default)'], ['month', 'Last 30 days'], ['year', 'Last 12 months'], ['all', 'All time']],
|
|
72
|
+
flags: [['--png', 'Where to save the image', 'file'], ['--no-png', 'Caption only'], ['--no-copy', 'Print, don\'t copy']],
|
|
73
|
+
examples: ['claude-rpc share', 'claude-rpc share month'] },
|
|
70
74
|
{ name: 'statcards', group: 'share', summary: 'Cards and badges as a live link, PNG or SVG', usage: '[card]',
|
|
71
75
|
subs: [['stats', 'Stats + year heatmap'], ['profile', 'Profile card'], ['badge', 'Small badge'],
|
|
72
76
|
['heatmap', 'Year heatmap'], ['poster', 'Poster summary'], ['session', 'This session'],
|
package/src/share.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// `claude-rpc share [week|month|year|all]` — one command to show people what
|
|
2
|
+
// you've been up to: saves the poster PNG for that window and copies a ready
|
|
3
|
+
// caption (your real numbers + a link back) to the clipboard. Nothing is
|
|
4
|
+
// posted anywhere; you paste it wherever you like.
|
|
5
|
+
//
|
|
6
|
+
// claude-rpc share last 7 days → ./claude-share-week.png + caption
|
|
7
|
+
// claude-rpc share month last 30 days
|
|
8
|
+
// claude-rpc share --no-png caption only
|
|
9
|
+
//
|
|
10
|
+
// The link is /get?ref=share so the worker can count what sharing brings in.
|
|
11
|
+
|
|
12
|
+
import { resolve, relative } from 'node:path';
|
|
13
|
+
import { c, fail, EX_USER_ERROR } from './ui.js';
|
|
14
|
+
import { fmtNum, fmtHours } from './fmt.js';
|
|
15
|
+
|
|
16
|
+
export const SHARE_URL = 'https://claude-rpc.com/get?ref=share';
|
|
17
|
+
const RANGES = ['week', 'month', 'year', 'all'];
|
|
18
|
+
const WINDOW = { week: 'last 7 days', month: 'last 30 days', year: 'last 12 months', all: 'all time' };
|
|
19
|
+
|
|
20
|
+
export function parseShareArgs(argv) {
|
|
21
|
+
const o = { range: 'week', png: true, path: null, copy: true };
|
|
22
|
+
for (let i = 0; i < argv.length; i++) {
|
|
23
|
+
const a = argv[i];
|
|
24
|
+
if (a === '--no-png') o.png = false;
|
|
25
|
+
else if (a === '--no-copy') o.copy = false;
|
|
26
|
+
else if (a === '--png' || a === '--out') {
|
|
27
|
+
const n = argv[i + 1];
|
|
28
|
+
if (!n || n.startsWith('-')) return { error: `${a} needs a path` };
|
|
29
|
+
o.path = n; i++;
|
|
30
|
+
} else if (RANGES.includes(a)) o.range = a;
|
|
31
|
+
else return { error: `unknown option ${a}` };
|
|
32
|
+
}
|
|
33
|
+
return o;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// The caption: real numbers for the window, skipping any that are zero so a
|
|
37
|
+
// quiet week doesn't read "0 prompts". `r` is card.js rollup() output.
|
|
38
|
+
export function shareCaption(r, { range = 'week', streak = 0 } = {}) {
|
|
39
|
+
const bits = [];
|
|
40
|
+
if (r.activeMs > 0) bits.push(`${fmtHours(r.activeMs)} with Claude Code`);
|
|
41
|
+
if (r.userMessages > 0) bits.push(`${fmtNum(r.userMessages)} prompts`);
|
|
42
|
+
if (r.tokens > 0) bits.push(`${fmtNum(r.tokens)} tokens`);
|
|
43
|
+
if (r.linesAdded > 0) bits.push(`+${fmtNum(r.linesAdded)} lines`);
|
|
44
|
+
if (streak > 1) bits.push(`${streak}-day streak`);
|
|
45
|
+
const head = bits.length ? `My ${WINDOW[range]}: ${bits.join(' · ')}.` : `Tracking my Claude Code sessions.`;
|
|
46
|
+
return `${head}\nLive on my Discord profile with claude-rpc → ${SHARE_URL}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// ctx: { aggregate(), copy(text) → tool|null }
|
|
50
|
+
export async function runShare(argv, ctx) {
|
|
51
|
+
const o = parseShareArgs(argv);
|
|
52
|
+
if (o.error) return fail(o.error, { hint: 'claude-rpc help share', code: EX_USER_ERROR });
|
|
53
|
+
const aggregate = ctx.aggregate();
|
|
54
|
+
const { rollup, renderCard } = await import('./card.js');
|
|
55
|
+
const caption = shareCaption(rollup(aggregate, o.range), { range: o.range, streak: aggregate?.streak || 0 });
|
|
56
|
+
|
|
57
|
+
console.log('');
|
|
58
|
+
if (o.png) {
|
|
59
|
+
const path = resolve(o.path || `claude-share-${o.range}.png`);
|
|
60
|
+
try {
|
|
61
|
+
const { svgToPng } = await import('./png.js');
|
|
62
|
+
const r = await svgToPng(renderCard(aggregate, { range: o.range }), path);
|
|
63
|
+
console.log(` ${c.green}✓${c.reset} saved ${c.cyan}${relative(process.cwd(), path) || path}${c.reset} ${c.dim}(${r.width}×${r.height}) — drag it into Discord, X or LinkedIn${c.reset}`);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
// No PNG backend is not fatal — the caption is the important half.
|
|
66
|
+
console.log(` ${c.yellow}!${c.reset} ${c.dim}no image: ${e.message}${e.hint ? ` — ${e.hint}` : ''}${c.reset}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
console.log('');
|
|
70
|
+
for (const line of caption.split('\n')) console.log(` ${line}`);
|
|
71
|
+
console.log('');
|
|
72
|
+
const tool = o.copy ? await ctx.copy(caption) : null;
|
|
73
|
+
if (tool) console.log(` ${c.magenta}⧉${c.reset} ${c.dim}caption copied — paste it with the image${c.reset}`);
|
|
74
|
+
else if (o.copy) console.log(` ${c.dim}no clipboard tool found — copy the caption above${c.reset}`);
|
|
75
|
+
console.log('');
|
|
76
|
+
}
|