claude-rpc 1.5.2 → 1.6.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 +72 -62
- package/SECURITY.md +99 -20
- package/package.json +2 -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 +430 -459
- package/src/commands.js +245 -0
- package/src/community.js +101 -60
- package/src/completion.js +196 -0
- 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 +64 -38
- 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/help.js +117 -0
- 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 +10 -5
- package/src/png.js +135 -0
- package/src/pricing.js +25 -3
- 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/select.js +60 -0
- 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/statcards.js +278 -0
- 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/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
|
|