cc-peer 1.3.5 → 1.5.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.
@@ -1,35 +1,15 @@
1
1
  #!/usr/bin/env node
2
- //#region \0rolldown/runtime.js
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
- key = keys[i];
12
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
- get: ((k) => from[k]).bind(null, key),
14
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
- });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
20
- value: mod,
21
- enumerable: true
22
- }) : target, mod));
23
- //#endregion
24
- const require_cc_peer = require("../cc-peer-CXzxAUE4.cjs");
2
+ const require_rolldown_runtime = require("../rolldown-runtime-VH7oDXx4.cjs");
3
+ const require_cc_peer = require("../cc-peer-ClYIGdRf.cjs");
4
+ const require_errors = require("../errors-Dl_lSq1N.cjs");
25
5
  let node_crypto = require("node:crypto");
26
6
  let zod = require("zod");
27
7
  let node_process = require("node:process");
28
- node_process = __toESM(node_process, 1);
8
+ node_process = require_rolldown_runtime.__toESM(node_process, 1);
29
9
  let node_http = require("node:http");
30
10
  //#region src/api/schemas.ts
31
11
  /** Address a REST target by session pid, roster name, or raw address. */
32
- const PeerTargetSchema = require_cc_peer.defineSchema(zod.z.object({
12
+ const PeerTargetSchema = require_errors.defineSchema(zod.z.object({
33
13
  pid: zod.z.number().int().positive().optional(),
34
14
  name: zod.z.string().min(1).optional(),
35
15
  address: zod.z.string().min(1).optional()
@@ -37,7 +17,7 @@ const PeerTargetSchema = require_cc_peer.defineSchema(zod.z.object({
37
17
  id: "PeerTarget",
38
18
  title: "Peer target"
39
19
  }));
40
- const SendMessageRequestSchema = require_cc_peer.defineSchema(zod.z.object({
20
+ const SendMessageRequestSchema = require_errors.defineSchema(zod.z.object({
41
21
  to: PeerTargetSchema,
42
22
  body: zod.z.string().min(1),
43
23
  priority: require_cc_peer.PrioritySchema.optional(),
@@ -47,19 +27,19 @@ const SendMessageRequestSchema = require_cc_peer.defineSchema(zod.z.object({
47
27
  id: "SendMessageRequest",
48
28
  title: "Send message request"
49
29
  }));
50
- const IdleSubscriptionRequestSchema = require_cc_peer.defineSchema(zod.z.object({ to: PeerTargetSchema }).meta({
30
+ const IdleSubscriptionRequestSchema = require_errors.defineSchema(zod.z.object({ to: PeerTargetSchema }).meta({
51
31
  id: "IdleSubscriptionRequest",
52
32
  title: "Idle subscription request"
53
33
  }));
54
- const SendAcceptedSchema = require_cc_peer.defineSchema(zod.z.object({ msgId: zod.z.string() }).meta({
34
+ const SendAcceptedSchema = require_errors.defineSchema(zod.z.object({ msgId: zod.z.string() }).meta({
55
35
  id: "SendAccepted",
56
36
  title: "Send accepted"
57
37
  }));
58
- const RosterResponseSchema = require_cc_peer.defineSchema(zod.z.object({ sessions: zod.z.array(require_cc_peer.RegistryEntrySchema) }).meta({
38
+ const RosterResponseSchema = require_errors.defineSchema(zod.z.object({ sessions: zod.z.array(require_cc_peer.RegistryEntrySchema) }).meta({
59
39
  id: "RosterResponse",
60
40
  title: "Roster response"
61
41
  }));
62
- const ErrorResponseSchema = require_cc_peer.defineSchema(zod.z.object({ error: zod.z.string() }).meta({
42
+ const ErrorResponseSchema = require_errors.defineSchema(zod.z.object({ error: zod.z.string() }).meta({
63
43
  id: "ErrorResponse",
64
44
  title: "Error response"
65
45
  }));
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { a as defineSchema, i as RegistryEntrySchema, n as CcPeer, r as PrioritySchema } from "../cc-peer-CJqStHIL.mjs";
2
+ import { i as RegistryEntrySchema, n as CcPeer, r as PrioritySchema } from "../cc-peer-BduoSupO.mjs";
3
+ import { o as defineSchema } from "../errors-Dcqq2MIW.mjs";
3
4
  import { randomBytes } from "node:crypto";
4
5
  import { z } from "zod";
5
6
  import process from "node:process";
@@ -0,0 +1,312 @@
1
+ import { EventEmitter } from "node:events";
2
+ import { z } from "zod";
3
+ //#region src/adapters/node/paths.d.ts
4
+ interface PathConfig {
5
+ homeDir?: string;
6
+ socketDir?: string;
7
+ }
8
+ //#endregion
9
+ //#region src/ports/transport.d.ts
10
+ /** Transport port: per-exchange connections and the listening inbox. */
11
+ interface Transport {
12
+ /**
13
+ * One connection, one write of the given lines (each newline-terminated), then close after a short linger. Mirrors the reference client's `Pe`.
14
+ */
15
+ connectWrite: (socketPath: string, lines: readonly string[], lingerMs?: number) => Promise<void>;
16
+ /** Probe whether a socket accepts connections (roster admission uses this). */
17
+ probe: (socketPath: string) => Promise<boolean>;
18
+ listen: (socketPath: string, onConnection: (conn: Readonly<InboundConnection>) => void) => Promise<ListeningSocket>;
19
+ }
20
+ interface InboundConnection {
21
+ /** Resolves once the kernel reports the connecting process's pid (macOS). */
22
+ peerPid: () => number | undefined;
23
+ readLines: () => AsyncIterable<string>;
24
+ close: () => void;
25
+ }
26
+ interface ListeningSocket {
27
+ socketPath: string;
28
+ close: () => Promise<void>;
29
+ }
30
+ //#endregion
31
+ //#region src/schemas/registry.d.ts
32
+ /** One entry of the ~/.claude/sessions/<pid>.json registry. */
33
+ declare const RegistryEntrySchema: z.ZodObject<{
34
+ pid: z.ZodNumber;
35
+ sessionId: z.ZodString;
36
+ cwd: z.ZodString;
37
+ startedAt: z.ZodNumber;
38
+ procStart: z.ZodString;
39
+ version: z.ZodString;
40
+ ccPeerVersion: z.ZodOptional<z.ZodString>;
41
+ peerProtocol: z.ZodNumber;
42
+ peerFeatures: z.ZodArray<z.ZodEnum<{
43
+ notify_idle: "notify_idle";
44
+ reply_across_default_dirs: "reply_across_default_dirs";
45
+ artifact_yield: "artifact_yield";
46
+ }> & {
47
+ is(value: unknown): value is "notify_idle" | "reply_across_default_dirs" | "artifact_yield";
48
+ }>;
49
+ kind: z.ZodEnum<{
50
+ interactive: "interactive";
51
+ bg: "bg";
52
+ daemon: "daemon";
53
+ "daemon-worker": "daemon-worker";
54
+ }> & {
55
+ is(value: unknown): value is "interactive" | "bg" | "daemon" | "daemon-worker";
56
+ };
57
+ entrypoint: z.ZodString;
58
+ pidDomain: z.ZodString;
59
+ messagingSocketPath: z.ZodString;
60
+ name: z.ZodOptional<z.ZodString>;
61
+ nameSource: z.ZodOptional<z.ZodEnum<{
62
+ user: "user";
63
+ peer: "peer";
64
+ derived: "derived";
65
+ collision: "collision";
66
+ auto: "auto";
67
+ hook: "hook";
68
+ }> & {
69
+ is(value: unknown): value is "user" | "peer" | "derived" | "collision" | "auto" | "hook";
70
+ }>;
71
+ nameSince: z.ZodOptional<z.ZodNumber>;
72
+ updatedAt: z.ZodNumber;
73
+ status: z.ZodOptional<z.ZodEnum<{
74
+ idle: "idle";
75
+ busy: "busy";
76
+ shell: "shell";
77
+ waiting: "waiting";
78
+ }> & {
79
+ is(value: unknown): value is "idle" | "busy" | "shell" | "waiting";
80
+ }>;
81
+ statusUpdatedAt: z.ZodOptional<z.ZodNumber>;
82
+ bridgeSessionId: z.ZodOptional<z.ZodString>;
83
+ }, z.core.$strip> & {
84
+ is(value: unknown): value is {
85
+ pid: number;
86
+ sessionId: string;
87
+ cwd: string;
88
+ startedAt: number;
89
+ procStart: string;
90
+ version: string;
91
+ peerProtocol: number;
92
+ peerFeatures: ("notify_idle" | "reply_across_default_dirs" | "artifact_yield")[];
93
+ kind: "interactive" | "bg" | "daemon" | "daemon-worker";
94
+ entrypoint: string;
95
+ pidDomain: string;
96
+ messagingSocketPath: string;
97
+ updatedAt: number;
98
+ ccPeerVersion?: string | undefined;
99
+ name?: string | undefined;
100
+ nameSource?: "user" | "peer" | "derived" | "collision" | "auto" | "hook" | undefined;
101
+ nameSince?: number | undefined;
102
+ status?: "idle" | "busy" | "shell" | "waiting" | undefined;
103
+ statusUpdatedAt?: number | undefined;
104
+ bridgeSessionId?: string | undefined;
105
+ };
106
+ };
107
+ type RegistryEntry = z.infer<typeof RegistryEntrySchema>;
108
+ //#endregion
109
+ //#region src/ports/registry-store.d.ts
110
+ /** Registry port: the ~/.claude/sessions/<pid>.json store. */
111
+ interface RegistryStore {
112
+ list: () => Promise<RegistryEntry[]>;
113
+ read: (pid: number) => Promise<RegistryEntry | undefined>;
114
+ write: (entry: RegistryEntry) => Promise<void>;
115
+ /** Heartbeat: bump updatedAt/statusUpdatedAt without rewriting the rest. */
116
+ touch: (pid: number) => Promise<void>;
117
+ remove: (pid: number) => Promise<void>;
118
+ }
119
+ //#endregion
120
+ //#region src/schemas/keyfile.d.ts
121
+ /** The auth key a session publishes next to its socket. */
122
+ declare const PeerKeyFileSchema: z.ZodObject<{
123
+ peerToken: z.ZodString;
124
+ procStart: z.ZodString;
125
+ pidDomain: z.ZodString;
126
+ }, z.core.$strip> & {
127
+ is(value: unknown): value is {
128
+ peerToken: string;
129
+ procStart: string;
130
+ pidDomain: string;
131
+ };
132
+ };
133
+ type PeerKeyFile = z.infer<typeof PeerKeyFileSchema>;
134
+ //#endregion
135
+ //#region src/ports/key-store.d.ts
136
+ /** Key-store port: auth keys published next to each session socket. */
137
+ interface KeyStore {
138
+ readForSocket: (socketPath: string) => Promise<PeerKeyFile | undefined>;
139
+ /** Write our own key file for the socket we own. */
140
+ writeForSocket: (socketPath: string, keyFile: Readonly<PeerKeyFile>) => Promise<void>;
141
+ removeForSocket: (socketPath: string) => Promise<void>;
142
+ }
143
+ //#endregion
144
+ //#region src/ports/proc-info.d.ts
145
+ /** Process-info port: the liveness and proc-start facts the roster needs. */
146
+ interface ProcInfo {
147
+ alive: (pid: number) => Promise<boolean>;
148
+ /**
149
+ * The process start string, byte-equal to `LC_ALL=C TZ=UTC ps -o lstart=` output — the exact value the receiver's registry byte-compares against.
150
+ */
151
+ lstart: (pid: number) => Promise<string | undefined>;
152
+ }
153
+ //#endregion
154
+ //#region src/ports/clock.d.ts
155
+ /** Clock port: injectable time for pacer/refill and freshness windows. */
156
+ interface Clock {
157
+ nowMs: () => number;
158
+ }
159
+ //#endregion
160
+ //#region src/schemas/wire.d.ts
161
+ declare const PeerMessageStatusSchema: z.ZodObject<{
162
+ type: z.ZodLiteral<"control">;
163
+ action: z.ZodLiteral<"peer_message_status">;
164
+ status: z.ZodEnum<{
165
+ held: "held";
166
+ delivered: "delivered";
167
+ denied: "denied";
168
+ expired: "expired";
169
+ dropped: "dropped";
170
+ }>;
171
+ reason: z.ZodString;
172
+ from: z.ZodString;
173
+ orig_msg_id: z.ZodString;
174
+ status_detail: z.ZodOptional<z.ZodString>;
175
+ drop_reason: z.ZodOptional<z.ZodEnum<{
176
+ "rate-limited": "rate-limited";
177
+ duplicate: "duplicate";
178
+ "hop-loop": "hop-loop";
179
+ "hop-runaway": "hop-runaway";
180
+ "queue-full": "queue-full";
181
+ }> & {
182
+ is(value: unknown): value is "rate-limited" | "duplicate" | "hop-loop" | "hop-runaway" | "queue-full";
183
+ }>;
184
+ dropped_msg_ids: z.ZodOptional<z.ZodArray<z.ZodString>>;
185
+ msgV: z.ZodNumber;
186
+ msg_id: z.ZodString;
187
+ }, z.core.$strip> & {
188
+ is(value: unknown): value is {
189
+ type: "control";
190
+ action: "peer_message_status";
191
+ status: "held" | "delivered" | "denied" | "expired" | "dropped";
192
+ reason: string;
193
+ from: string;
194
+ orig_msg_id: string;
195
+ msgV: number;
196
+ msg_id: string;
197
+ status_detail?: string | undefined;
198
+ drop_reason?: "rate-limited" | "duplicate" | "hop-loop" | "hop-runaway" | "queue-full" | undefined;
199
+ dropped_msg_ids?: string[] | undefined;
200
+ };
201
+ };
202
+ type PeerMessageStatus = z.infer<typeof PeerMessageStatusSchema>;
203
+ declare const PeerIdleNoticeSchema: z.ZodObject<{
204
+ type: z.ZodLiteral<"control">;
205
+ action: z.ZodLiteral<"peer_idle_notice">;
206
+ orig_msg_id: z.ZodString;
207
+ state: z.ZodEnum<{
208
+ idle: "idle";
209
+ exited: "exited";
210
+ }>;
211
+ finished_at: z.ZodNumber;
212
+ detail: z.ZodOptional<z.ZodString>;
213
+ from: z.ZodString;
214
+ from_mode: z.ZodOptional<z.ZodEnum<{
215
+ bypass: "bypass";
216
+ prompting: "prompting";
217
+ }>>;
218
+ msgV: z.ZodNumber;
219
+ msg_id: z.ZodString;
220
+ }, z.core.$strip> & {
221
+ is(value: unknown): value is {
222
+ type: "control";
223
+ action: "peer_idle_notice";
224
+ orig_msg_id: string;
225
+ state: "idle" | "exited";
226
+ finished_at: number;
227
+ from: string;
228
+ msgV: number;
229
+ msg_id: string;
230
+ detail?: string | undefined;
231
+ from_mode?: "bypass" | "prompting" | undefined;
232
+ };
233
+ };
234
+ type PeerIdleNotice = z.infer<typeof PeerIdleNoticeSchema>;
235
+ //#endregion
236
+ //#region src/cc-peer.d.ts
237
+ /** cc-peer's own package version, read from package.json and inlined at bundle time so it needs no filesystem access at runtime (the SEA build ships as a single file with no package.json alongside it). */
238
+ declare const CC_PEER_VERSION: string;
239
+ /** How a target can be addressed. */
240
+ type PeerRef = {
241
+ pid: number;
242
+ } | {
243
+ name: string;
244
+ } | {
245
+ address: string;
246
+ };
247
+ interface CcPeerOptions extends PathConfig {
248
+ name?: string;
249
+ sessionId?: string;
250
+ heartbeatMs?: number;
251
+ logger?: (message: string) => void;
252
+ }
253
+ interface SendOptions {
254
+ priority?: "next" | "later";
255
+ /** Attaches from-mode attestation; false deliberately sends unattested (recipient holds it). */
256
+ fromMode?: "bypass" | "prompting" | false;
257
+ /** When set, must match the receiver's sessionId or the frame is silently dropped. */
258
+ sessionId?: string;
259
+ }
260
+ interface InboundMessage {
261
+ from?: string;
262
+ fromSession?: string;
263
+ fromName?: string;
264
+ fromMode?: "bypass" | "prompting";
265
+ hopChain?: string[];
266
+ body: string;
267
+ msgId: string;
268
+ }
269
+ type Receipt = PeerMessageStatus;
270
+ type IdleNotice = PeerIdleNotice;
271
+ interface Deps {
272
+ transport: Transport;
273
+ registry: RegistryStore;
274
+ keys: KeyStore;
275
+ procInfo: ProcInfo;
276
+ clock: Clock;
277
+ }
278
+ /**
279
+ * A registered peer on Claude Code's cross-session mesh. Receipts and idle notices only reach the process that owns the listening socket (the protocol verifies return addresses via kernel peer pids), so do not split sending and listening across differently-owned processes.
280
+ */
281
+ declare class CcPeer extends EventEmitter {
282
+ private readonly options;
283
+ private readonly deps;
284
+ private listening;
285
+ private heartbeatTimer;
286
+ private ownKey;
287
+ private readonly pacer;
288
+ private readonly log;
289
+ private stopped;
290
+ constructor(options: Readonly<CcPeerOptions>, deps: Deps);
291
+ static create(options?: Readonly<CcPeerOptions>): Promise<CcPeer>;
292
+ /**
293
+ * Bind, publish key and registry, and begin listening. Public rather than private because dependency-injected construction (this constructor takes the full Deps) needs to trigger it explicitly; everyday callers use the static create(), which wires the real node adapters.
294
+ */
295
+ start(): Promise<void>;
296
+ /** procStart is a required parameter, not read from this.ownKey: start() already guarantees a non-empty value before this is called, so the type checker enforces it rather than a runtime fallback that can never actually fire. */
297
+ private buildRegistryEntry;
298
+ roster(): Promise<RegistryEntry[]>;
299
+ send(target: PeerRef, body: string, options?: Readonly<SendOptions>): Promise<{
300
+ msgId: string;
301
+ }>;
302
+ private pacedSend;
303
+ subscribeIdle(target: PeerRef): Promise<{
304
+ msgId: string;
305
+ }>;
306
+ private resolveTarget;
307
+ /** ownToken is passed explicitly rather than read from this.ownKey: the listener callback that invokes this is only ever registered after start() has set ownKey, so the parameter records that guarantee at the type level instead of a runtime guard that can never actually be false. */
308
+ private handleConnection;
309
+ stop(): Promise<void>;
310
+ }
311
+ //#endregion
312
+ export { InboundMessage as a, SendOptions as c, IdleNotice as i, PathConfig as l, CcPeer as n, PeerRef as o, CcPeerOptions as r, Receipt as s, CC_PEER_VERSION as t };