claude-rpc 1.5.2 → 1.5.4
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 +34 -24
- package/SECURITY.md +99 -20
- package/package.json +1 -1
- package/src/atomic-rename.js +45 -2
- package/src/badge.js +3 -4
- package/src/card.js +1 -22
- package/src/cli-path.js +286 -0
- package/src/cli.js +310 -383
- package/src/community.js +101 -60
- package/src/config.js +4 -1
- package/src/daemon.js +45 -47
- package/src/default-config.js +4 -3
- package/src/discord-ipc.js +24 -13
- package/src/doctor.js +63 -37
- package/src/ensure-daemon.js +11 -4
- package/src/fmt.js +8 -6
- package/src/format.js +8 -13
- package/src/gist.js +8 -18
- package/src/git.js +4 -1
- package/src/hook.js +27 -32
- package/src/insights.js +3 -4
- package/src/install.js +100 -79
- package/src/leaderboard.js +3 -2
- package/src/mcp.js +2 -8
- package/src/nudge.js +8 -3
- package/src/pricing.js +24 -2
- package/src/privacy.js +22 -7
- package/src/profile.js +0 -6
- package/src/recap.js +4 -17
- package/src/scanner.js +103 -71
- package/src/server/api.js +64 -36
- package/src/server/assets/dashboard.client.js +75 -44
- package/src/server/assets/dashboard.css +18 -18
- package/src/server/assets/dashboard.html +13 -15
- package/src/server/assets/wrapped.client.js +26 -11
- package/src/server/assets/wrapped.css +2 -2
- package/src/server/index.js +43 -32
- package/src/server/page.js +6 -3
- package/src/server/sse.js +90 -34
- package/src/session-card.js +3 -1
- package/src/state.js +14 -24
- package/src/tui.js +3 -12
- package/src/ui.js +7 -5
- package/src/verify.js +3 -7
- package/src/version.js +1 -1
- package/src/week.js +4 -4
package/src/server/index.js
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
// server/api.js — data helpers (snapshot, windowedAggregate, drilldowns)
|
|
7
7
|
// server/routes.js — declarative /api/* route table
|
|
8
8
|
// server/sse.js — SSE broadcast + file watchers
|
|
9
|
-
// server/page.js —
|
|
9
|
+
// server/page.js — composes the dashboard + /wrapped pages from the
|
|
10
|
+
// on-disk files in server/assets/ (via assets.js)
|
|
10
11
|
//
|
|
11
12
|
// Zero deps, vanilla browser JS, SVG charts. Designed to run alongside the
|
|
12
13
|
// daemon on localhost:47474 so the user can poke at their own data.
|
|
@@ -18,12 +19,20 @@ import { projectDrilldown, dayDetail } from './api.js';
|
|
|
18
19
|
import { watchSources, addClient, removeClient } from './sse.js';
|
|
19
20
|
import { buildHtml, buildWrappedHtml } from './page.js';
|
|
20
21
|
|
|
22
|
+
const PORT = Number(process.env.CLAUDE_RPC_PORT) || 47474;
|
|
23
|
+
|
|
21
24
|
// Pre-compose the HTML once at startup — the only dynamic bit is the port
|
|
22
|
-
// (
|
|
23
|
-
const HTML = buildHtml({ port:
|
|
25
|
+
// (shown in the footer), which is fixed for the life of the process.
|
|
26
|
+
const HTML = buildHtml({ port: PORT });
|
|
24
27
|
const WRAPPED_HTML = buildWrappedHtml();
|
|
28
|
+
const PAGES = new Map([
|
|
29
|
+
['/', HTML], ['/index.html', HTML],
|
|
30
|
+
['/wrapped', WRAPPED_HTML], ['/wrapped.html', WRAPPED_HTML], // animated year-in-review
|
|
31
|
+
]);
|
|
25
32
|
|
|
26
|
-
|
|
33
|
+
// Path-prefix drilldowns — the project name / day key is in the URL path
|
|
34
|
+
// itself, not in a query string.
|
|
35
|
+
const DRILLDOWNS = [['/api/project/', projectDrilldown], ['/api/day/', dayDetail]];
|
|
27
36
|
|
|
28
37
|
function parseUrl(rawUrl) {
|
|
29
38
|
const url = new URL(rawUrl, 'http://x');
|
|
@@ -65,42 +74,25 @@ function dispatch(req, res) {
|
|
|
65
74
|
return;
|
|
66
75
|
}
|
|
67
76
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const result = projectDrilldown(name);
|
|
74
|
-
res.writeHead(result ? 200 : 404, JSON_HEADERS);
|
|
75
|
-
res.end(JSON.stringify(result || { error: 'not found' }));
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Day detail. Same pattern — day key in the URL path.
|
|
80
|
-
if (req.method === 'GET' && path.startsWith('/api/day/')) {
|
|
81
|
-
const day = safeDecode(path.slice('/api/day/'.length));
|
|
82
|
-
if (day === null) { res.writeHead(400, JSON_HEADERS).end(JSON.stringify({ error: 'bad request' })); return; }
|
|
83
|
-
const result = dayDetail(day);
|
|
77
|
+
for (const [prefix, lookup] of DRILLDOWNS) {
|
|
78
|
+
if (req.method !== 'GET' || !path.startsWith(prefix)) continue;
|
|
79
|
+
const id = safeDecode(path.slice(prefix.length));
|
|
80
|
+
if (id === null) { res.writeHead(400, JSON_HEADERS).end(JSON.stringify({ error: 'bad request' })); return; }
|
|
81
|
+
const result = lookup(id);
|
|
84
82
|
res.writeHead(result ? 200 : 404, JSON_HEADERS);
|
|
85
83
|
res.end(JSON.stringify(result || { error: 'not found' }));
|
|
86
84
|
return;
|
|
87
85
|
}
|
|
88
86
|
|
|
89
|
-
// Static /api/* endpoints (state, aggregate, insights, badge.svg,
|
|
87
|
+
// Static /api/* endpoints (state, wrapped, aggregate, insights, badge.svg,
|
|
88
|
+
// card.svg, export.json, export.csv) — see routes.js.
|
|
90
89
|
const handler = ROUTES.get(key);
|
|
91
90
|
if (handler) return handler(req, res, { query });
|
|
92
91
|
|
|
93
|
-
|
|
94
|
-
if (
|
|
92
|
+
const page = req.method === 'GET' && PAGES.get(path);
|
|
93
|
+
if (page) {
|
|
95
94
|
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store' });
|
|
96
|
-
res.end(
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Page.
|
|
101
|
-
if (req.method === 'GET' && (path === '/' || path === '/index.html')) {
|
|
102
|
-
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store' });
|
|
103
|
-
res.end(HTML);
|
|
95
|
+
res.end(page);
|
|
104
96
|
return;
|
|
105
97
|
}
|
|
106
98
|
|
|
@@ -119,9 +111,28 @@ const server = createServer((req, res) => {
|
|
|
119
111
|
}
|
|
120
112
|
});
|
|
121
113
|
|
|
122
|
-
|
|
114
|
+
// Listen failures arrive as an 'error' event. Without a handler the
|
|
115
|
+
// uncaughtException floor below swallowed EADDRINUSE and the process then sat
|
|
116
|
+
// forever on the poll interval + fs watchers, serving nothing — e.g. a second
|
|
117
|
+
// `claude-rpc serve`, or the tray and the Stats tab each spawning one. Say why
|
|
118
|
+
// in one line and exit non-zero instead. Once listening, an 'error' is logged
|
|
119
|
+
// and the dashboard keeps running (same policy as the floor).
|
|
120
|
+
server.on('error', (e) => {
|
|
121
|
+
if (server.listening) {
|
|
122
|
+
try { console.error('dashboard error:', e?.message || e); } catch { /* ignore */ }
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const base = `http://127.0.0.1:${PORT}`;
|
|
126
|
+
console.error(e?.code === 'EADDRINUSE'
|
|
127
|
+
? `✗ Port ${PORT} is already in use — a dashboard may already be running at ${base} (set CLAUDE_RPC_PORT to use another port).`
|
|
128
|
+
: `✗ Dashboard could not listen on 127.0.0.1:${PORT}: ${e?.message || e}`);
|
|
129
|
+
process.exit(1);
|
|
130
|
+
});
|
|
123
131
|
|
|
124
132
|
server.listen(PORT, '127.0.0.1', () => {
|
|
133
|
+
// Start watching only once the port is ours, so a failed listen exits
|
|
134
|
+
// without leaving watchers behind.
|
|
135
|
+
watchSources();
|
|
125
136
|
const base = `http://127.0.0.1:${PORT}`;
|
|
126
137
|
// `claude-rpc wrapped` sets CLAUDE_RPC_OPEN_PATH=/wrapped to land on the
|
|
127
138
|
// animated year-in-review instead of the dashboard.
|
package/src/server/page.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
// Composes the local web dashboard's
|
|
1
|
+
// Composes the local web dashboard's two pages from six on-disk assets:
|
|
2
2
|
// assets/dashboard.html — scaffold with {{STYLES}} {{SCRIPT}} {{PORT}}
|
|
3
3
|
// assets/dashboard.css — stylesheet
|
|
4
4
|
// assets/dashboard.client.js — vanilla browser runtime (one IIFE)
|
|
5
|
+
// assets/wrapped.html — /wrapped scaffold with {{STYLES}} {{SCRIPT}}
|
|
6
|
+
// assets/wrapped.css — /wrapped stylesheet
|
|
7
|
+
// assets/wrapped.client.js — /wrapped story runtime (one IIFE)
|
|
5
8
|
//
|
|
6
9
|
// These are real files you edit with full CSS/HTML/JS tooling — the reason
|
|
7
10
|
// this module shrank from a 1,200-line string monolith. loadAsset() reads
|
|
8
11
|
// them from disk in dev/npm and from the SEA blob in the packaged exe
|
|
9
12
|
// (see src/server/assets.js + sea-config.json).
|
|
10
13
|
//
|
|
11
|
-
//
|
|
12
|
-
// startup and reuses the string for every request.
|
|
14
|
+
// Two exports: buildHtml({ port }) and buildWrappedHtml(). The server
|
|
15
|
+
// composes each once at startup and reuses the string for every request.
|
|
13
16
|
|
|
14
17
|
import { loadAsset } from './assets.js';
|
|
15
18
|
|
package/src/server/sse.js
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
// Server-Sent Events: the dashboard pushes a one-line `data:` frame to
|
|
2
|
-
// connected browsers whenever state
|
|
3
|
-
// Replaces the old 2-second poll.
|
|
4
|
-
// shared client set.
|
|
2
|
+
// connected browsers whenever a session state file or aggregate.json is
|
|
3
|
+
// touched. Replaces the old 2-second poll. One debounced directory watcher
|
|
4
|
+
// per source plus an mtime-poll fallback, one shared client set.
|
|
5
5
|
|
|
6
|
-
import { watch,
|
|
7
|
-
import { dirname, basename } from 'node:path';
|
|
8
|
-
import {
|
|
6
|
+
import { watch, readdirSync, statSync } from 'node:fs';
|
|
7
|
+
import { dirname, basename, join } from 'node:path';
|
|
8
|
+
import { STATE_DIR, AGGREGATE_PATH } from '../paths.js';
|
|
9
9
|
import { pollDecision, pollIntervalMs } from '../watch-poll.js';
|
|
10
10
|
|
|
11
|
+
// Hooks write one state-<sid>.json per Claude Code session (src/state.js
|
|
12
|
+
// statePathFor); the legacy global state.json is only written for payloads
|
|
13
|
+
// without a session id. Watch the whole family, same filter as the daemon's
|
|
14
|
+
// watchFiles() — matching only the literal 'state.json' meant real hook events
|
|
15
|
+
// never reached the live rail. Write-tmp (`*.json.<pid>.tmp`) and lock
|
|
16
|
+
// (`*.json.lock`) siblings don't end in `.json`, so they don't match.
|
|
17
|
+
export const STATE_FILE_RE = /^state(-.+)?\.json$/;
|
|
18
|
+
|
|
11
19
|
export const sseClients = new Set();
|
|
12
20
|
|
|
13
21
|
export function broadcast(payload) {
|
|
@@ -44,35 +52,65 @@ export function removeClient(res) {
|
|
|
44
52
|
}
|
|
45
53
|
}
|
|
46
54
|
|
|
47
|
-
// Watch a
|
|
48
|
-
//
|
|
49
|
-
//
|
|
50
|
-
// once then goes permanently silent.
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
// Watch a directory for entries whose name passes `matches`. Every writer here
|
|
56
|
+
// commits via atomic rename (write-tmp + renameSync), and watching a file path
|
|
57
|
+
// directly binds to the inode at watch-time — on Linux that inode is replaced
|
|
58
|
+
// by the first rename, so the watcher fires once then goes permanently silent.
|
|
59
|
+
// Directory inodes are stable across entry renames. A null filename (some
|
|
60
|
+
// platforms) is treated as a match. `onError` runs if the watcher dies (e.g.
|
|
61
|
+
// the directory was removed) so the caller can re-attach later.
|
|
62
|
+
export function watchDir(dir, matches, callback, onError) {
|
|
55
63
|
try {
|
|
56
|
-
|
|
57
|
-
if (!filename || filename
|
|
64
|
+
const w = watch(dir, (_, filename) => {
|
|
65
|
+
if (!filename || matches(String(filename))) callback();
|
|
66
|
+
});
|
|
67
|
+
w.on('error', () => {
|
|
68
|
+
try { w.close(); } catch { /* already closed */ }
|
|
69
|
+
onError?.();
|
|
58
70
|
});
|
|
71
|
+
return w;
|
|
59
72
|
} catch {
|
|
60
73
|
return null;
|
|
61
74
|
}
|
|
62
75
|
}
|
|
63
76
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
77
|
+
// Single-file convenience wrapper over watchDir (watches the parent directory).
|
|
78
|
+
export function watchFile(filePath, callback) {
|
|
79
|
+
const name = basename(filePath);
|
|
80
|
+
return watchDir(dirname(filePath), (f) => f === name, callback);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Newest mtime among the entries of `dir` that pass `matches` (undefined when
|
|
84
|
+
// none exist or the directory is missing). For the state family this is the
|
|
85
|
+
// max across every session file — monotone under writes, so the poll's
|
|
86
|
+
// `cur > prev` test still detects a change in ANY session; a deleted session
|
|
87
|
+
// file lowers it, which correctly doesn't fire.
|
|
88
|
+
export function newestMtime(dir, matches) {
|
|
89
|
+
let max;
|
|
90
|
+
let names;
|
|
91
|
+
try { names = readdirSync(dir); } catch { return undefined; }
|
|
92
|
+
for (const name of names) {
|
|
93
|
+
if (!matches(name)) continue;
|
|
94
|
+
try {
|
|
95
|
+
const m = statSync(join(dir, name)).mtimeMs;
|
|
96
|
+
if (max === undefined || m > max) max = m;
|
|
97
|
+
} catch { /* vanished or mid-rename; a later observation records it */ }
|
|
69
98
|
}
|
|
99
|
+
return max;
|
|
70
100
|
}
|
|
71
101
|
|
|
72
|
-
|
|
102
|
+
// Start the watchers + poll fallback. Paths are injectable for tests; the
|
|
103
|
+
// server calls it with the defaults. Returns { close } to stop everything.
|
|
104
|
+
export function watchSources({
|
|
105
|
+
stateDir = STATE_DIR,
|
|
106
|
+
aggregatePath = AGGREGATE_PATH,
|
|
107
|
+
pollMs = pollIntervalMs(),
|
|
108
|
+
debounceMs = 200,
|
|
109
|
+
} = {}) {
|
|
110
|
+
const aggName = basename(aggregatePath);
|
|
73
111
|
const targets = [
|
|
74
|
-
{
|
|
75
|
-
{
|
|
112
|
+
{ type: 'state', dir: stateDir, matches: (f) => STATE_FILE_RE.test(f), watcher: null },
|
|
113
|
+
{ type: 'aggregate', dir: dirname(aggregatePath), matches: (f) => f === aggName, watcher: null },
|
|
76
114
|
];
|
|
77
115
|
|
|
78
116
|
// Last mtime we've reacted to, per target. Updated by BOTH the watcher and
|
|
@@ -82,30 +120,48 @@ export function watchSources() {
|
|
|
82
120
|
const lastMtime = new Map();
|
|
83
121
|
const debounceTimers = new Map();
|
|
84
122
|
const recordMtime = (t) => {
|
|
85
|
-
const m =
|
|
86
|
-
if (m !== undefined) lastMtime.set(t.
|
|
123
|
+
const m = newestMtime(t.dir, t.matches);
|
|
124
|
+
if (m !== undefined) lastMtime.set(t.type, m);
|
|
87
125
|
};
|
|
88
126
|
targets.forEach(recordMtime); // seed baselines before watching starts
|
|
89
127
|
|
|
90
128
|
const fire = (t) => {
|
|
91
129
|
recordMtime(t); // record before the debounced broadcast so a re-entrant tick can't double-fire
|
|
92
|
-
clearTimeout(debounceTimers.get(t.
|
|
93
|
-
debounceTimers.set(t.
|
|
130
|
+
clearTimeout(debounceTimers.get(t.type));
|
|
131
|
+
debounceTimers.set(t.type, setTimeout(() => broadcast({ type: t.type }), debounceMs));
|
|
94
132
|
};
|
|
95
133
|
|
|
96
|
-
|
|
134
|
+
// A directory that doesn't exist yet (fresh install, no hook has run) can't
|
|
135
|
+
// be watched; the poll tick below retries the attachment.
|
|
136
|
+
const attach = (t) => {
|
|
137
|
+
if (t.watcher) return;
|
|
138
|
+
t.watcher = watchDir(t.dir, t.matches, () => fire(t), () => { t.watcher = null; });
|
|
139
|
+
};
|
|
140
|
+
targets.forEach(attach);
|
|
97
141
|
|
|
98
142
|
// Mtime-poll fallback. fs.watch drops atomic-rename events on Windows (see
|
|
99
143
|
// watch-poll.js), and unlike the daemon this watcher previously had no
|
|
100
144
|
// backstop at all — a missed event left the dashboard silently stale until
|
|
101
145
|
// some unrelated broadcast happened to fire. Same cadence as the daemon's
|
|
102
146
|
// fallback: fast on Windows, lazy on macOS/Linux.
|
|
103
|
-
setInterval(() => {
|
|
147
|
+
const poll = setInterval(() => {
|
|
104
148
|
for (const t of targets) {
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
|
|
149
|
+
attach(t);
|
|
150
|
+
const cur = newestMtime(t.dir, t.matches);
|
|
151
|
+
const decision = pollDecision(lastMtime.get(t.type), cur);
|
|
152
|
+
if (decision === 'seed') lastMtime.set(t.type, cur);
|
|
108
153
|
else if (decision === 'fire') fire(t);
|
|
109
154
|
}
|
|
110
|
-
},
|
|
155
|
+
}, pollMs);
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
close() {
|
|
159
|
+
clearInterval(poll);
|
|
160
|
+
for (const timer of debounceTimers.values()) clearTimeout(timer);
|
|
161
|
+
for (const t of targets) {
|
|
162
|
+
try { t.watcher?.close(); } catch { /* already closed */ }
|
|
163
|
+
t.watcher = null;
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
};
|
|
111
167
|
}
|
package/src/session-card.js
CHANGED
|
@@ -40,6 +40,8 @@ function tape(x, y, text) {
|
|
|
40
40
|
export function renderSessionCard(vars = {}, { generatedAt = new Date() } = {}) {
|
|
41
41
|
const v = vars || {};
|
|
42
42
|
const C = [40, 210, 380];
|
|
43
|
+
// The day's estimated spend across ALL sessions — there's no per-session cost
|
|
44
|
+
// var — so the cell is labeled as today's, not this session's.
|
|
43
45
|
const cost = v.todayCostFmt || '$0';
|
|
44
46
|
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" role="img" aria-label="Claude Code session recap">
|
|
45
47
|
<defs><pattern id="dg" width="22" height="22" patternUnits="userSpaceOnUse"><circle cx="1" cy="1" r="1" fill="${PALETTE.ink}" opacity="0.06"/></pattern></defs>
|
|
@@ -58,7 +60,7 @@ export function renderSessionCard(vars = {}, { generatedAt = new Date() } = {})
|
|
|
58
60
|
${statCell(C[2], 120, 'Tokens', String(v.tokensFmt || '0'), PALETTE.rust)}
|
|
59
61
|
|
|
60
62
|
${statCell(C[0], 184, 'Files edited', String(v.filesEdited ?? 0), PALETTE.grass)}
|
|
61
|
-
${statCell(C[1], 184, '
|
|
63
|
+
${statCell(C[1], 184, 'Cost today', String(cost), PALETTE.blurple)}
|
|
62
64
|
${statCell(C[2], 184, 'Reads', String(v.filesRead ?? 0))}
|
|
63
65
|
|
|
64
66
|
<text x="40" y="${H - 16}" font-family="JetBrains Mono, ui-monospace, monospace" font-size="10" fill="${PALETTE.inkFaint}">${escapeXml(`${v.currentFilePretty ? 'last: ' + v.currentFilePretty + ' · ' : ''}claude-rpc.com · v${VERSION}`)}</text>
|
package/src/state.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { basename, join } from 'node:path';
|
|
3
|
+
import { STATE_PATH, STATE_DIR } from './paths.js';
|
|
4
|
+
import { pickActiveSession } from './presence.js';
|
|
5
|
+
import { renameSyncRetry, sleepSync } from './atomic-rename.js';
|
|
6
|
+
|
|
7
|
+
// require()d, not imported — on the hook hot path; see hook.js.
|
|
8
|
+
const {
|
|
2
9
|
existsSync,
|
|
3
10
|
mkdirSync,
|
|
4
11
|
readFileSync,
|
|
@@ -9,11 +16,7 @@ import {
|
|
|
9
16
|
statSync,
|
|
10
17
|
fstatSync,
|
|
11
18
|
readdirSync,
|
|
12
|
-
}
|
|
13
|
-
import { basename, join } from 'node:path';
|
|
14
|
-
import { STATE_PATH, STATE_DIR } from './paths.js';
|
|
15
|
-
import { pickActiveSession } from './presence.js';
|
|
16
|
-
import { renameSyncRetry } from './atomic-rename.js';
|
|
19
|
+
} = createRequire(import.meta.url)('node:fs');
|
|
17
20
|
|
|
18
21
|
const DEFAULT_STATE = {
|
|
19
22
|
sessionStart: null,
|
|
@@ -33,12 +36,13 @@ const DEFAULT_STATE = {
|
|
|
33
36
|
// from this when the working tool has been running long enough to be
|
|
34
37
|
// worth surfacing (>5s by default — quick reads don't flicker on the card).
|
|
35
38
|
toolStartedAt: null,
|
|
36
|
-
// Set by PostToolUse when a
|
|
39
|
+
// Set by PostToolUse when a ship is observed (a git push / commit, or a
|
|
40
|
+
// `gh pr|issue|release create` — see ships.classifyShip).
|
|
37
41
|
// format.applyShipped promotes status to 'shipped' for shippedFrameSec
|
|
38
42
|
// (default 60s) after this timestamp, so the card briefly celebrates
|
|
39
43
|
// a ship instead of immediately returning to "Working in <project>".
|
|
40
44
|
justShipped: null,
|
|
41
|
-
justShippedKind: null, // 'push' | 'commit'
|
|
45
|
+
justShippedKind: null, // 'push' | 'commit' | 'pr' | 'issue' | 'tag'
|
|
42
46
|
justShippedSubject: null,
|
|
43
47
|
justShippedBranch: null,
|
|
44
48
|
model: 'claude',
|
|
@@ -75,17 +79,6 @@ const LOCK_STALE_MS = 2000;
|
|
|
75
79
|
const LOCK_RETRY_MS = 4;
|
|
76
80
|
const LOCK_MAX_WAIT_MS = 1000;
|
|
77
81
|
|
|
78
|
-
// Synchronous sleep — hooks are short-lived sync processes, so a blocking spin
|
|
79
|
-
// with a real wait (no busy-loop) is the right tool. Atomics.wait on a throwaway
|
|
80
|
-
// SharedArrayBuffer parks the thread without burning CPU.
|
|
81
|
-
function sleepSync(ms) {
|
|
82
|
-
try {
|
|
83
|
-
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
84
|
-
} catch {
|
|
85
|
-
/* SharedArrayBuffer unavailable — fall through, caller just retries sooner */
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
82
|
function acquireLock(lockPath) {
|
|
90
83
|
const deadline = Date.now() + LOCK_MAX_WAIT_MS;
|
|
91
84
|
for (;;) {
|
|
@@ -161,13 +154,10 @@ export function statePathFor(sessionId) {
|
|
|
161
154
|
|
|
162
155
|
export function readState(sessionId) {
|
|
163
156
|
ensureDir();
|
|
164
|
-
const path = statePathFor(sessionId);
|
|
165
|
-
if (!existsSync(path)) return { ...DEFAULT_STATE };
|
|
166
157
|
try {
|
|
167
|
-
|
|
168
|
-
return { ...DEFAULT_STATE, ...JSON.parse(raw) };
|
|
158
|
+
return { ...DEFAULT_STATE, ...JSON.parse(readFileSync(statePathFor(sessionId), 'utf8')) };
|
|
169
159
|
} catch {
|
|
170
|
-
return { ...DEFAULT_STATE };
|
|
160
|
+
return { ...DEFAULT_STATE }; // missing, torn, or unparseable
|
|
171
161
|
}
|
|
172
162
|
}
|
|
173
163
|
|
package/src/tui.js
CHANGED
|
@@ -7,12 +7,11 @@
|
|
|
7
7
|
// previewable without a live TTY; startTui() owns the IO/loop.
|
|
8
8
|
|
|
9
9
|
import process from 'node:process';
|
|
10
|
-
import { readFileSync, existsSync } from 'node:fs';
|
|
11
10
|
import { readActiveState } from './state.js';
|
|
12
11
|
import { readAggregate, findLiveSessions, dayKey } from './scanner.js';
|
|
13
12
|
import { buildVars, applyIdle, humanProject, fmtNum } from './format.js';
|
|
14
13
|
import { loadConfig } from './config.js';
|
|
15
|
-
import {
|
|
14
|
+
import { daemonAlive } from './ensure-daemon.js';
|
|
16
15
|
import { fmtCost } from './pricing.js';
|
|
17
16
|
import { heat } from './ui.js';
|
|
18
17
|
|
|
@@ -175,16 +174,8 @@ export function loadSnapshot() {
|
|
|
175
174
|
state = applyIdle(state, config);
|
|
176
175
|
const aggregate = readAggregate() || {};
|
|
177
176
|
const vars = buildVars(state, config, aggregate);
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function daemonPid() {
|
|
182
|
-
if (!existsSync(PID_PATH)) return null;
|
|
183
|
-
try {
|
|
184
|
-
const pid = Number(readFileSync(PID_PATH, 'utf8'));
|
|
185
|
-
process.kill(pid, 0);
|
|
186
|
-
return pid;
|
|
187
|
-
} catch { return null; }
|
|
177
|
+
// daemonAlive treats EPERM as alive (the pid exists, we just can't signal it).
|
|
178
|
+
return { state, config, aggregate, vars, pid: daemonAlive() || null };
|
|
188
179
|
}
|
|
189
180
|
|
|
190
181
|
const WD = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
package/src/ui.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// Shared CLI output primitives.
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
// doctor.js,
|
|
3
|
+
// The ANSI palette, status symbols and check/fail/hint rows for the line-
|
|
4
|
+
// oriented commands (cli.js, doctor.js, install.js import them). tui.js keeps
|
|
5
|
+
// its own full-screen palette and box primitives (it borrows only `heat`): it
|
|
6
|
+
// only ever runs on a TTY and gates color on NO_COLOR alone.
|
|
5
7
|
//
|
|
6
8
|
// All output goes to stdout/stderr via console.log/console.error. The
|
|
7
9
|
// daemon's file-bound `log()` is a separate concern (no tty, no color)
|
|
@@ -153,9 +155,9 @@ export function tailLines(raw, n = 30) {
|
|
|
153
155
|
return lines.slice(-n);
|
|
154
156
|
}
|
|
155
157
|
|
|
156
|
-
//
|
|
157
|
-
//
|
|
158
|
-
//
|
|
158
|
+
// One checklist row: `check(label, status, detail, hint)`, status one of
|
|
159
|
+
// pass | fail | warn | info. doctor.js wraps it to count results and record
|
|
160
|
+
// fix kinds for `doctor --fix`.
|
|
159
161
|
export function check(label, status, detail = '', hint = '') {
|
|
160
162
|
let sym;
|
|
161
163
|
if (status === 'pass') sym = SYM_OK;
|
package/src/verify.js
CHANGED
|
@@ -9,10 +9,9 @@
|
|
|
9
9
|
// Consent is now recorded locally as `profile.verifyPending`, and the daemon
|
|
10
10
|
// finishes the same flow the user already agreed to once the server answers.
|
|
11
11
|
|
|
12
|
-
import { readFileSync,
|
|
13
|
-
import { dirname } from 'node:path';
|
|
12
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
14
13
|
import { CONFIG_PATH } from './paths.js';
|
|
15
|
-
import {
|
|
14
|
+
import { writeFileAtomic } from './atomic-rename.js';
|
|
16
15
|
import { normalizeGithubUser, profileIsPublishable } from './leaderboard.js';
|
|
17
16
|
|
|
18
17
|
const FETCH_TIMEOUT_MS = 10_000;
|
|
@@ -154,10 +153,7 @@ export function updateUserConfig(mutate, { path = CONFIG_PATH } = {}) {
|
|
|
154
153
|
}
|
|
155
154
|
if (!cfg || typeof cfg !== 'object') return false;
|
|
156
155
|
if (mutate(cfg) === false) return false;
|
|
157
|
-
|
|
158
|
-
const tmp = `${path}.${process.pid}.tmp`;
|
|
159
|
-
writeFileSync(tmp, JSON.stringify(cfg, null, 2) + '\n');
|
|
160
|
-
renameSyncRetry(tmp, path);
|
|
156
|
+
writeFileAtomic(path, JSON.stringify(cfg, null, 2) + '\n');
|
|
161
157
|
return true;
|
|
162
158
|
}
|
|
163
159
|
|
package/src/version.js
CHANGED
package/src/week.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
1
|
+
// Monday-anchored current-week grid behind `claude-rpc week` (cli.js
|
|
2
|
+
// showWeek): the seven days, future/today flags, and peak — kept in its own
|
|
3
|
+
// module so the date math is unit-testable against a fixed clock. (The TUI's
|
|
4
|
+
// week tab shows a rolling last-7-days window instead; see tui.js last7Days.)
|
|
5
5
|
|
|
6
6
|
import { dayKey } from './scanner.js';
|
|
7
7
|
|