cc-peer 1.6.0 → 1.6.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/README.md CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  Talk to the Claude Code instances running on your machine, from any Node application: send messages, register as a named peer other sessions can discover and message, receive replies and delivery receipts, and subscribe to idle notifications. Ships a REST facade you can run with `npx cc-peer`.
6
6
 
7
+ [![npm downloads chart, log scale](https://shieldcn.dev/chart/npm/cc-peer.svg?bg=transparent&logo=false&yScale=log)](https://www.npmjs.com/package/cc-peer)
8
+
7
9
  > **Unofficial.** This SDK speaks Claude Code's local cross-session peer protocol, which was reverse-engineered and verified against Claude Code 2.1.269. It is not affiliated with or endorsed by Anthropic, and the protocol may change without notice between Claude Code releases.
8
10
 
9
11
  ## Why
@@ -1,5 +1,5 @@
1
1
  const require_rolldown_runtime = require("../../rolldown-runtime-VH7oDXx4.cjs");
2
- const require_cc_peer = require("../../cc-peer-BYqqGdh_.cjs");
2
+ const require_cc_peer = require("../../cc-peer-DNB8oHNm.cjs");
3
3
  const require_errors = require("../../errors-BAbklcGw.cjs");
4
4
  const require_alias_ipc = require("../../alias-ipc-BPc2wfmz.cjs");
5
5
  let node_process = require("node:process");
@@ -12,11 +12,21 @@ let peer;
12
12
  node_process.default.on("message", (raw) => {
13
13
  handleCommand(raw);
14
14
  });
15
+ node_process.default.on("disconnect", () => {
16
+ shutdown();
17
+ });
18
+ async function shutdown() {
19
+ await peer?.stop();
20
+ node_process.default.exit(0);
21
+ }
22
+ /** Relays an event to the parent unless its channel has already closed, since a send on a closed channel raises an error event on the process that nothing handles. */
23
+ function relay(message) {
24
+ if (node_process.default.connected) node_process.default.send?.(message);
25
+ }
15
26
  async function handleCommand(raw) {
16
27
  if (!require_alias_ipc.AliasCommandSchema.is(raw)) return;
17
28
  if (raw.type === "stop") {
18
- await peer?.stop();
19
- node_process.default.exit(0);
29
+ await shutdown();
20
30
  return;
21
31
  }
22
32
  if (raw.type === "send") {
@@ -37,17 +47,17 @@ async function handleCommand(raw) {
37
47
  }
38
48
  peer = created;
39
49
  peer.on("message", (message) => {
40
- node_process.default.send?.({
50
+ relay({
41
51
  type: "message",
42
52
  ...message
43
53
  });
44
54
  });
45
- node_process.default.send?.({ type: "started" });
55
+ relay({ type: "started" });
46
56
  }
47
57
  async function handleSend(command) {
48
58
  const active = peer;
49
59
  if (active === void 0) {
50
- node_process.default.send?.({
60
+ relay({
51
61
  type: "send_failed",
52
62
  requestId: command.requestId,
53
63
  code: "NOT_STARTED",
@@ -57,13 +67,13 @@ async function handleSend(command) {
57
67
  }
58
68
  try {
59
69
  const { msgId } = await active.send(command.target, command.body);
60
- node_process.default.send?.({
70
+ relay({
61
71
  type: "sent",
62
72
  requestId: command.requestId,
63
73
  msgId
64
74
  });
65
75
  } catch (error) {
66
- node_process.default.send?.({
76
+ relay({
67
77
  type: "send_failed",
68
78
  requestId: command.requestId,
69
79
  code: error instanceof require_errors.CcPeerError ? error.code : "UNKNOWN",
@@ -1,4 +1,4 @@
1
- import { n as CcPeer } from "../../cc-peer-BCixELiw.mjs";
1
+ import { n as CcPeer } from "../../cc-peer-zz8MzHY8.mjs";
2
2
  import { r as CcPeerError } from "../../errors-KYBco8pU.mjs";
3
3
  import { t as AliasCommandSchema } from "../../alias-ipc-BSh7Q4LL.mjs";
4
4
  import process from "node:process";
@@ -10,11 +10,21 @@ let peer;
10
10
  process.on("message", (raw) => {
11
11
  handleCommand(raw);
12
12
  });
13
+ process.on("disconnect", () => {
14
+ shutdown();
15
+ });
16
+ async function shutdown() {
17
+ await peer?.stop();
18
+ process.exit(0);
19
+ }
20
+ /** Relays an event to the parent unless its channel has already closed, since a send on a closed channel raises an error event on the process that nothing handles. */
21
+ function relay(message) {
22
+ if (process.connected) process.send?.(message);
23
+ }
13
24
  async function handleCommand(raw) {
14
25
  if (!AliasCommandSchema.is(raw)) return;
15
26
  if (raw.type === "stop") {
16
- await peer?.stop();
17
- process.exit(0);
27
+ await shutdown();
18
28
  return;
19
29
  }
20
30
  if (raw.type === "send") {
@@ -35,17 +45,17 @@ async function handleCommand(raw) {
35
45
  }
36
46
  peer = created;
37
47
  peer.on("message", (message) => {
38
- process.send?.({
48
+ relay({
39
49
  type: "message",
40
50
  ...message
41
51
  });
42
52
  });
43
- process.send?.({ type: "started" });
53
+ relay({ type: "started" });
44
54
  }
45
55
  async function handleSend(command) {
46
56
  const active = peer;
47
57
  if (active === void 0) {
48
- process.send?.({
58
+ relay({
49
59
  type: "send_failed",
50
60
  requestId: command.requestId,
51
61
  code: "NOT_STARTED",
@@ -55,13 +65,13 @@ async function handleSend(command) {
55
65
  }
56
66
  try {
57
67
  const { msgId } = await active.send(command.target, command.body);
58
- process.send?.({
68
+ relay({
59
69
  type: "sent",
60
70
  requestId: command.requestId,
61
71
  msgId
62
72
  });
63
73
  } catch (error) {
64
- process.send?.({
74
+ relay({
65
75
  type: "send_failed",
66
76
  requestId: command.requestId,
67
77
  code: error instanceof CcPeerError ? error.code : "UNKNOWN",
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  const require_rolldown_runtime = require("../rolldown-runtime-VH7oDXx4.cjs");
3
- const require_cc_peer = require("../cc-peer-BYqqGdh_.cjs");
3
+ const require_cc_peer = require("../cc-peer-DNB8oHNm.cjs");
4
4
  const require_errors = require("../errors-BAbklcGw.cjs");
5
5
  let node_crypto = require("node:crypto");
6
6
  let zod = require("zod");
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { i as RegistryEntrySchema, n as CcPeer, r as PrioritySchema } from "../cc-peer-BCixELiw.mjs";
2
+ import { i as RegistryEntrySchema, n as CcPeer, r as PrioritySchema } from "../cc-peer-zz8MzHY8.mjs";
3
3
  import { l as defineSchema } from "../errors-KYBco8pU.mjs";
4
4
  import { randomBytes } from "node:crypto";
5
5
  import { z } from "zod";
@@ -8,7 +8,7 @@ let zod = require("zod");
8
8
  let node_os = require("node:os");
9
9
  let node_child_process = require("node:child_process");
10
10
  //#region package.json
11
- var version = "1.6.0";
11
+ var version = "1.6.2";
12
12
  //#endregion
13
13
  //#region src/adapters/node/uds-transport.ts
14
14
  /** macOS linger before close, matching the reference client's ~150ms. */
@@ -8,7 +8,7 @@ import { z } from "zod";
8
8
  import { homedir } from "node:os";
9
9
  import { spawn } from "node:child_process";
10
10
  //#region package.json
11
- var version = "1.6.0";
11
+ var version = "1.6.2";
12
12
  //#endregion
13
13
  //#region src/adapters/node/uds-transport.ts
14
14
  /** macOS linger before close, matching the reference client's ~150ms. */
package/dist/cc-peer.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_cc_peer = require("./cc-peer-BYqqGdh_.cjs");
2
+ const require_cc_peer = require("./cc-peer-DNB8oHNm.cjs");
3
3
  exports.CC_PEER_VERSION = require_cc_peer.CC_PEER_VERSION;
4
4
  exports.CcPeer = require_cc_peer.CcPeer;
package/dist/cc-peer.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { n as CcPeer, t as CC_PEER_VERSION } from "./cc-peer-BCixELiw.mjs";
1
+ import { n as CcPeer, t as CC_PEER_VERSION } from "./cc-peer-zz8MzHY8.mjs";
2
2
  export { CC_PEER_VERSION, CcPeer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-peer",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "description": "Communicate with local Claude Code instances over their native cross-session peer messaging: send and receive messages, register as a named discoverable peer, receipts, idle subscriptions, and a REST facade via `npx cc-peer`.",
5
5
  "type": "module",
6
6
  "license": "MIT",