claude-rpc 1.1.1 → 1.1.2

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/bin/claude-rpc.js CHANGED
@@ -1,2 +1,3 @@
1
1
  #!/usr/bin/env node
2
+ import '../src/safe-stdio.js';
2
3
  import '../src/cli.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-rpc",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Discord Rich Presence for Claude Code — live model, project, tokens, and lifetime stats driven by Claude Code's hook system.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/daemon.js CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import './safe-stdio.js';
2
3
  import { existsSync, unlinkSync, watch, appendFileSync, mkdirSync, statSync, renameSync, readdirSync } from 'node:fs';
3
4
  import { basename, dirname, join } from 'node:path';
4
5
  import { Client } from './discord-ipc.js';
package/src/hook.js CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import './safe-stdio.js';
2
3
  import { readFileSync, appendFileSync, existsSync, mkdirSync, statSync, renameSync } from 'node:fs';
3
4
  import { dirname } from 'node:path';
4
5
  import { updateState, resetState, pushUnique, shortFile } from './state.js';
@@ -0,0 +1,39 @@
1
+ // Crash-proof stdio. Node's process.stdout / process.stderr / process.stdin
2
+ // are LAZY getters that construct the stream on first access — and on Windows
3
+ // that construction can THROW (EBADF / EINVAL / ENOTSOCK) when the inherited
4
+ // handle is invalid or of a type the probe mishandles: children of
5
+ // GUI-subsystem parents (the packaged Electron dashboard), services, some
6
+ // terminal emulators. Because src/ui.js probes `process.stdout.isTTY` at
7
+ // module load, that throw used to kill the ENTIRE CLI before main() ran —
8
+ // the shipped Windows SEA exe died on startup whenever stdio was a pipe in
9
+ // such contexts, which is exactly how the dashboard and Claude Code's hook
10
+ // runner invoke it.
11
+ //
12
+ // Import this module FIRST from every entrypoint (bin, hook, daemon). It
13
+ // probes each stream once; a stream whose getter throws is replaced with a
14
+ // silent sink (stdout/stderr) or an already-ended reader (stdin). Output is
15
+ // dropped instead of fatal — on a broken handle it was going nowhere anyway.
16
+ // On healthy systems the probe succeeds and NOTHING is replaced.
17
+ import { Writable, Readable } from 'node:stream';
18
+
19
+ function replaceWritable(name, fd) {
20
+ const sink = new Writable({ write(chunk, enc, cb) { cb(); } });
21
+ // The shape console/readline/ui.js expect from a stdio stream:
22
+ sink.isTTY = false;
23
+ sink.columns = 80;
24
+ sink.rows = 24;
25
+ sink.fd = fd;
26
+ Object.defineProperty(process, name, { configurable: true, get: () => sink });
27
+ }
28
+
29
+ function replaceReadable(name) {
30
+ const empty = new Readable({ read() { this.push(null); } });
31
+ empty.isTTY = false;
32
+ empty.fd = 0;
33
+ empty.setRawMode = () => empty;
34
+ Object.defineProperty(process, name, { configurable: true, get: () => empty });
35
+ }
36
+
37
+ try { void process.stdout.isTTY; } catch { replaceWritable('stdout', 1); }
38
+ try { void process.stderr.isTTY; } catch { replaceWritable('stderr', 2); }
39
+ try { void process.stdin.isTTY; } catch { replaceReadable('stdin'); }
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.1.1';
14
+ const BAKED = '1.1.2';
15
15
 
16
16
  function readPkgVersion() {
17
17
  try {