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.
Files changed (52) hide show
  1. package/README.md +72 -62
  2. package/SECURITY.md +99 -20
  3. package/package.json +2 -1
  4. package/src/atomic-rename.js +45 -2
  5. package/src/badge.js +3 -4
  6. package/src/card.js +1 -22
  7. package/src/cli-path.js +286 -0
  8. package/src/cli.js +430 -459
  9. package/src/commands.js +245 -0
  10. package/src/community.js +101 -60
  11. package/src/completion.js +196 -0
  12. package/src/config.js +4 -1
  13. package/src/daemon.js +45 -47
  14. package/src/default-config.js +4 -3
  15. package/src/discord-ipc.js +24 -13
  16. package/src/doctor.js +64 -38
  17. package/src/ensure-daemon.js +11 -4
  18. package/src/fmt.js +8 -6
  19. package/src/format.js +8 -13
  20. package/src/gist.js +8 -18
  21. package/src/git.js +4 -1
  22. package/src/help.js +117 -0
  23. package/src/hook.js +27 -32
  24. package/src/insights.js +3 -4
  25. package/src/install.js +100 -79
  26. package/src/leaderboard.js +3 -2
  27. package/src/mcp.js +2 -8
  28. package/src/nudge.js +10 -5
  29. package/src/png.js +135 -0
  30. package/src/pricing.js +25 -3
  31. package/src/privacy.js +22 -7
  32. package/src/profile.js +0 -6
  33. package/src/recap.js +4 -17
  34. package/src/scanner.js +103 -71
  35. package/src/select.js +60 -0
  36. package/src/server/api.js +64 -36
  37. package/src/server/assets/dashboard.client.js +75 -44
  38. package/src/server/assets/dashboard.css +18 -18
  39. package/src/server/assets/dashboard.html +13 -15
  40. package/src/server/assets/wrapped.client.js +26 -11
  41. package/src/server/assets/wrapped.css +2 -2
  42. package/src/server/index.js +43 -32
  43. package/src/server/page.js +6 -3
  44. package/src/server/sse.js +90 -34
  45. package/src/session-card.js +3 -1
  46. package/src/statcards.js +278 -0
  47. package/src/state.js +14 -24
  48. package/src/tui.js +3 -12
  49. package/src/ui.js +7 -5
  50. package/src/verify.js +3 -7
  51. package/src/version.js +1 -1
  52. 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
- } from 'node:fs';
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 `git push` or `git commit` is observed.
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
- const raw = readFileSync(path, 'utf8');
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 { PID_PATH } from './paths.js';
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
- return { state, config, aggregate, vars, pid: daemonPid() };
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
- // Three duplicates of the same ANSI table + symbol set existed in cli.js,
4
- // doctor.js, and tui.js. This is the one place; everything else imports.
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
- // Compatibility with doctor.js's existing API. Same `check(label, status,
157
- // detail, hint)` signature; doctor.js can switch its private copy out for
158
- // this without behavior change.
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, writeFileSync, mkdirSync, existsSync } from 'node:fs';
13
- import { dirname } from 'node:path';
12
+ import { readFileSync, existsSync } from 'node:fs';
14
13
  import { CONFIG_PATH } from './paths.js';
15
- import { renameSyncRetry } from './atomic-rename.js';
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
- mkdirSync(dirname(path), { recursive: true });
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
@@ -11,7 +11,7 @@ import { readFileSync } from 'node:fs';
11
11
  import { join } from 'node:path';
12
12
  import { ROOT } from './paths.js';
13
13
 
14
- const BAKED = '1.5.2';
14
+ const BAKED = '1.6.0';
15
15
 
16
16
  function readPkgVersion() {
17
17
  try {
package/src/week.js CHANGED
@@ -1,7 +1,7 @@
1
- // Shared Monday-anchored current-week grid. cli.js (showWeek) and tui.js
2
- // (tabWeek) render it with different ANSI widths but compute the same seven
3
- // days, future/today flags, and peak — extracted here so the date math can't
4
- // drift between the two and is unit-testable against a fixed clock.
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