strands-darwin 0.0.37 → 0.0.40

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 (99) hide show
  1. package/README.md +17 -2
  2. package/README.zh-CN.md +12 -2
  3. package/dist/src/agent/permission-rules.js +1 -1
  4. package/dist/src/agent/permission-rules.js.map +1 -1
  5. package/dist/src/agent/permission.d.ts +4 -1
  6. package/dist/src/agent/permission.js +21 -4
  7. package/dist/src/agent/permission.js.map +1 -1
  8. package/dist/src/agent/runtime.d.ts +6 -2
  9. package/dist/src/agent/runtime.js +37 -6
  10. package/dist/src/agent/runtime.js.map +1 -1
  11. package/dist/src/agent/session-lease.d.ts +31 -0
  12. package/dist/src/agent/session-lease.js +42 -0
  13. package/dist/src/agent/session-lease.js.map +1 -0
  14. package/dist/src/agent/session.d.ts +2 -47
  15. package/dist/src/agent/session.js +3 -50
  16. package/dist/src/agent/session.js.map +1 -1
  17. package/dist/src/agent/stream-idle.d.ts +1 -1
  18. package/dist/src/agent/stream-idle.js +1 -1
  19. package/dist/src/cli-list-agents.d.ts +1 -0
  20. package/dist/src/cli-list-agents.js +12 -0
  21. package/dist/src/cli-list-agents.js.map +1 -0
  22. package/dist/src/cli-usage.d.ts +1 -1
  23. package/dist/src/cli-usage.js +7 -0
  24. package/dist/src/cli-usage.js.map +1 -1
  25. package/dist/src/cli.js +9 -1
  26. package/dist/src/cli.js.map +1 -1
  27. package/dist/src/collaboration/command.d.ts +5 -0
  28. package/dist/src/collaboration/command.js +84 -0
  29. package/dist/src/collaboration/command.js.map +1 -0
  30. package/dist/src/collaboration/grammar.d.ts +3 -0
  31. package/dist/src/collaboration/grammar.js +9 -0
  32. package/dist/src/collaboration/grammar.js.map +1 -0
  33. package/dist/src/collaboration/hub-command.d.ts +21 -0
  34. package/dist/src/collaboration/hub-command.js +129 -0
  35. package/dist/src/collaboration/hub-command.js.map +1 -0
  36. package/dist/src/collaboration/hub-store.d.ts +58 -0
  37. package/dist/src/collaboration/hub-store.js +108 -0
  38. package/dist/src/collaboration/hub-store.js.map +1 -0
  39. package/dist/src/collaboration/hub-transport.d.ts +86 -0
  40. package/dist/src/collaboration/hub-transport.js +456 -0
  41. package/dist/src/collaboration/hub-transport.js.map +1 -0
  42. package/dist/src/collaboration/hub-wire.d.ts +356 -0
  43. package/dist/src/collaboration/hub-wire.js +192 -0
  44. package/dist/src/collaboration/hub-wire.js.map +1 -0
  45. package/dist/src/collaboration/local.d.ts +78 -0
  46. package/dist/src/collaboration/local.js +464 -0
  47. package/dist/src/collaboration/local.js.map +1 -0
  48. package/dist/src/collaboration/protocol.d.ts +113 -0
  49. package/dist/src/collaboration/protocol.js +27 -0
  50. package/dist/src/collaboration/protocol.js.map +1 -0
  51. package/dist/src/collaboration/storage.d.ts +37 -0
  52. package/dist/src/collaboration/storage.js +246 -0
  53. package/dist/src/collaboration/storage.js.map +1 -0
  54. package/dist/src/collaboration/tools.d.ts +5 -0
  55. package/dist/src/collaboration/tools.js +10 -0
  56. package/dist/src/collaboration/tools.js.map +1 -0
  57. package/dist/src/commands/custom-commands.d.ts +1 -1
  58. package/dist/src/commands/custom-commands.js +3 -1
  59. package/dist/src/commands/custom-commands.js.map +1 -1
  60. package/dist/src/commands/review-command.d.ts +8 -3
  61. package/dist/src/commands/review-command.js +17 -3
  62. package/dist/src/commands/review-command.js.map +1 -1
  63. package/dist/src/config.d.ts +7 -5
  64. package/dist/src/config.js +5 -3
  65. package/dist/src/config.js.map +1 -1
  66. package/dist/src/dev-repl.js +8 -1
  67. package/dist/src/dev-repl.js.map +1 -1
  68. package/dist/src/headless-protocol.d.ts +6 -2
  69. package/dist/src/headless-protocol.js +32 -8
  70. package/dist/src/headless-protocol.js.map +1 -1
  71. package/dist/src/headless-runner.js +45 -1
  72. package/dist/src/headless-runner.js.map +1 -1
  73. package/dist/src/headless.d.ts +2 -1
  74. package/dist/src/headless.js +5 -5
  75. package/dist/src/headless.js.map +1 -1
  76. package/dist/src/list-agents.d.ts +21 -0
  77. package/dist/src/list-agents.js +219 -0
  78. package/dist/src/list-agents.js.map +1 -0
  79. package/dist/src/paths.d.ts +5 -0
  80. package/dist/src/paths.js +14 -2
  81. package/dist/src/paths.js.map +1 -1
  82. package/dist/src/trajectory/record.d.ts +8 -3
  83. package/dist/src/trajectory/record.js +3 -0
  84. package/dist/src/trajectory/record.js.map +1 -1
  85. package/dist/src/trajectory/replay.js +13 -0
  86. package/dist/src/trajectory/replay.js.map +1 -1
  87. package/dist/src/trajectory/rewind-history.js +1 -1
  88. package/dist/src/trajectory/rewind-history.js.map +1 -1
  89. package/dist/src/trajectory/writer.d.ts +3 -2
  90. package/dist/src/trajectory/writer.js +4 -0
  91. package/dist/src/trajectory/writer.js.map +1 -1
  92. package/dist/src/tui/App.js +83 -1
  93. package/dist/src/tui/App.js.map +1 -1
  94. package/dist/src/tui/InputBox.d.ts +1 -1
  95. package/dist/src/tui/InputBox.js +1 -1
  96. package/dist/src/tui/help-format.d.ts +2 -2
  97. package/dist/src/tui/help-format.js +4 -3
  98. package/dist/src/tui/help-format.js.map +1 -1
  99. package/package.json +1 -1
@@ -0,0 +1,356 @@
1
+ import { z } from 'zod';
2
+ export declare const MAX_TEXT_BYTES = 4096;
3
+ export declare const MAX_FRAME_BYTES = 16384;
4
+ export declare const MAX_QUEUE = 8;
5
+ export declare const MESSAGE_TTL_MS = 60000;
6
+ export declare const CHAIN_TTL_MS = 300000;
7
+ export declare const MAX_HOPS = 4;
8
+ /** Connect assertion and envelope `sent` clock window (both directions). */
9
+ export declare const CLOCK_SKEW_MS = 60000;
10
+ export declare const MAX_DISCOVERY = 32;
11
+ export declare const ENROLL_TOKEN_TTL_MS = 600000;
12
+ export declare const uuidSchema: z.ZodString;
13
+ export declare const sessionSchema: z.ZodString;
14
+ /** Normalized remote identity: lowercase host plus 1–8 path segments, ≤256 bytes. */
15
+ export declare const hubProjectSchema: z.ZodString;
16
+ export declare const nodeNameSchema: z.ZodString;
17
+ /** Ed25519 SPKI DER (44 bytes) as base64. */
18
+ export declare const publicKeySchema: z.ZodString;
19
+ export declare const signatureSchema: z.ZodString;
20
+ export declare const fingerprintSchema: z.ZodString;
21
+ export declare const nonceSchema: z.ZodString;
22
+ export declare const tokenSchema: z.ZodString;
23
+ export declare const chainSchema: z.ZodObject<{
24
+ id: z.ZodString;
25
+ started: z.ZodNumber;
26
+ hop: z.ZodNumber;
27
+ readOnly: z.ZodBoolean;
28
+ }, z.core.$strict>;
29
+ export type PeerChain = z.infer<typeof chainSchema>;
30
+ export declare const hubAddressSchema: z.ZodObject<{
31
+ version: z.ZodLiteral<2>;
32
+ transport: z.ZodLiteral<"hub">;
33
+ node: z.ZodString;
34
+ endpoint: z.ZodString;
35
+ project: z.ZodString;
36
+ session: z.ZodString;
37
+ }, z.core.$strict>;
38
+ export type HubAddress = z.infer<typeof hubAddressSchema>;
39
+ export declare const hubEnvelopeSchema: z.ZodObject<{
40
+ version: z.ZodLiteral<2>;
41
+ id: z.ZodString;
42
+ sender: z.ZodObject<{
43
+ version: z.ZodLiteral<2>;
44
+ transport: z.ZodLiteral<"hub">;
45
+ node: z.ZodString;
46
+ endpoint: z.ZodString;
47
+ project: z.ZodString;
48
+ session: z.ZodString;
49
+ }, z.core.$strict>;
50
+ target: z.ZodObject<{
51
+ version: z.ZodLiteral<2>;
52
+ transport: z.ZodLiteral<"hub">;
53
+ node: z.ZodString;
54
+ endpoint: z.ZodString;
55
+ project: z.ZodString;
56
+ session: z.ZodString;
57
+ }, z.core.$strict>;
58
+ sent: z.ZodNumber;
59
+ chain: z.ZodObject<{
60
+ id: z.ZodString;
61
+ started: z.ZodNumber;
62
+ hop: z.ZodNumber;
63
+ readOnly: z.ZodBoolean;
64
+ }, z.core.$strict>;
65
+ text: z.ZodString;
66
+ }, z.core.$strict>;
67
+ export type HubEnvelope = z.infer<typeof hubEnvelopeSchema>;
68
+ export interface NodeKeys {
69
+ publicKey: string;
70
+ privateKey: string;
71
+ }
72
+ export declare function generateNodeKeys(): NodeKeys;
73
+ export declare function fingerprint(publicKey: string): string;
74
+ /** Display form: first 16 hex in groups of four. Pinning always compares the full key. */
75
+ export declare function shortFingerprint(value: string): string;
76
+ export declare function signEnvelope(privateKey: string, envelope: HubEnvelope): string;
77
+ export declare function verifyEnvelope(publicKey: string, envelope: unknown, signature: unknown): envelope is HubEnvelope;
78
+ /** `audience` is `<apiId>/<stage>`, binding an assertion to one deployment. */
79
+ export declare function connectMessage(audience: string, node: string, ts: number, nonce: string): Buffer;
80
+ export interface ConnectHeaders {
81
+ 'X-Darwin-Node': string;
82
+ 'X-Darwin-Ts': string;
83
+ 'X-Darwin-Nonce': string;
84
+ 'X-Darwin-Sig': string;
85
+ }
86
+ export declare function connectHeaders(audience: string, node: string, privateKey: string, now?: number): ConnectHeaders;
87
+ export interface ConnectAssertion {
88
+ node: string;
89
+ ts: number;
90
+ nonce: string;
91
+ sig: string;
92
+ }
93
+ /** Case-insensitive header lookup, bounded parse; undefined on any malformed field. */
94
+ export declare function parseConnectHeaders(headers: Record<string, string | undefined> | undefined): ConnectAssertion | undefined;
95
+ export declare function verifyConnect(publicKey: string, audience: string, assertion: ConnectAssertion, now?: number): boolean;
96
+ export declare function mintToken(): string;
97
+ export declare function tokenHash(token: string): string;
98
+ /**
99
+ * Normalize an `origin` URL to `host/path`. Userinfo (which may hold a token), port, scheme and
100
+ * `.git` are dropped; host lowercased, path case kept. Local paths and file URLs are refused:
101
+ * they name a directory on one machine, not a shared project.
102
+ */
103
+ export declare function normalizeRemote(raw: string): string;
104
+ export declare function projectLabel(project: string): string;
105
+ export declare const registerFrame: z.ZodObject<{
106
+ action: z.ZodLiteral<"register">;
107
+ rid: z.ZodString;
108
+ endpoint: z.ZodString;
109
+ project: z.ZodString;
110
+ session: z.ZodString;
111
+ }, z.core.$strict>;
112
+ export declare const unregisterFrame: z.ZodObject<{
113
+ action: z.ZodLiteral<"unregister">;
114
+ endpoint: z.ZodString;
115
+ }, z.core.$strict>;
116
+ export declare const discoverFrame: z.ZodObject<{
117
+ action: z.ZodLiteral<"discover">;
118
+ rid: z.ZodString;
119
+ }, z.core.$strict>;
120
+ export declare const sendFrame: z.ZodObject<{
121
+ action: z.ZodLiteral<"send">;
122
+ envelope: z.ZodObject<{
123
+ version: z.ZodLiteral<2>;
124
+ id: z.ZodString;
125
+ sender: z.ZodObject<{
126
+ version: z.ZodLiteral<2>;
127
+ transport: z.ZodLiteral<"hub">;
128
+ node: z.ZodString;
129
+ endpoint: z.ZodString;
130
+ project: z.ZodString;
131
+ session: z.ZodString;
132
+ }, z.core.$strict>;
133
+ target: z.ZodObject<{
134
+ version: z.ZodLiteral<2>;
135
+ transport: z.ZodLiteral<"hub">;
136
+ node: z.ZodString;
137
+ endpoint: z.ZodString;
138
+ project: z.ZodString;
139
+ session: z.ZodString;
140
+ }, z.core.$strict>;
141
+ sent: z.ZodNumber;
142
+ chain: z.ZodObject<{
143
+ id: z.ZodString;
144
+ started: z.ZodNumber;
145
+ hop: z.ZodNumber;
146
+ readOnly: z.ZodBoolean;
147
+ }, z.core.$strict>;
148
+ text: z.ZodString;
149
+ }, z.core.$strict>;
150
+ sig: z.ZodString;
151
+ }, z.core.$strict>;
152
+ export declare const ackFrame: z.ZodObject<{
153
+ action: z.ZodLiteral<"ack">;
154
+ id: z.ZodString;
155
+ status: z.ZodEnum<{
156
+ queued: "queued";
157
+ refused: "refused";
158
+ }>;
159
+ reason: z.ZodOptional<z.ZodString>;
160
+ }, z.core.$strict>;
161
+ export declare const pingFrame: z.ZodObject<{
162
+ action: z.ZodLiteral<"ping">;
163
+ }, z.core.$strict>;
164
+ export declare const clientFrame: z.ZodDiscriminatedUnion<[z.ZodObject<{
165
+ action: z.ZodLiteral<"register">;
166
+ rid: z.ZodString;
167
+ endpoint: z.ZodString;
168
+ project: z.ZodString;
169
+ session: z.ZodString;
170
+ }, z.core.$strict>, z.ZodObject<{
171
+ action: z.ZodLiteral<"unregister">;
172
+ endpoint: z.ZodString;
173
+ }, z.core.$strict>, z.ZodObject<{
174
+ action: z.ZodLiteral<"discover">;
175
+ rid: z.ZodString;
176
+ }, z.core.$strict>, z.ZodObject<{
177
+ action: z.ZodLiteral<"send">;
178
+ envelope: z.ZodObject<{
179
+ version: z.ZodLiteral<2>;
180
+ id: z.ZodString;
181
+ sender: z.ZodObject<{
182
+ version: z.ZodLiteral<2>;
183
+ transport: z.ZodLiteral<"hub">;
184
+ node: z.ZodString;
185
+ endpoint: z.ZodString;
186
+ project: z.ZodString;
187
+ session: z.ZodString;
188
+ }, z.core.$strict>;
189
+ target: z.ZodObject<{
190
+ version: z.ZodLiteral<2>;
191
+ transport: z.ZodLiteral<"hub">;
192
+ node: z.ZodString;
193
+ endpoint: z.ZodString;
194
+ project: z.ZodString;
195
+ session: z.ZodString;
196
+ }, z.core.$strict>;
197
+ sent: z.ZodNumber;
198
+ chain: z.ZodObject<{
199
+ id: z.ZodString;
200
+ started: z.ZodNumber;
201
+ hop: z.ZodNumber;
202
+ readOnly: z.ZodBoolean;
203
+ }, z.core.$strict>;
204
+ text: z.ZodString;
205
+ }, z.core.$strict>;
206
+ sig: z.ZodString;
207
+ }, z.core.$strict>, z.ZodObject<{
208
+ action: z.ZodLiteral<"ack">;
209
+ id: z.ZodString;
210
+ status: z.ZodEnum<{
211
+ queued: "queued";
212
+ refused: "refused";
213
+ }>;
214
+ reason: z.ZodOptional<z.ZodString>;
215
+ }, z.core.$strict>, z.ZodObject<{
216
+ action: z.ZodLiteral<"ping">;
217
+ }, z.core.$strict>], "action">;
218
+ export type ClientFrame = z.infer<typeof clientFrame>;
219
+ export declare const nodeInfoSchema: z.ZodObject<{
220
+ node: z.ZodString;
221
+ name: z.ZodString;
222
+ publicKey: z.ZodString;
223
+ fingerprint: z.ZodString;
224
+ }, z.core.$strict>;
225
+ export type NodeInfo = z.infer<typeof nodeInfoSchema>;
226
+ export declare const discoverRowSchema: z.ZodObject<{
227
+ address: z.ZodObject<{
228
+ version: z.ZodLiteral<2>;
229
+ transport: z.ZodLiteral<"hub">;
230
+ node: z.ZodString;
231
+ endpoint: z.ZodString;
232
+ project: z.ZodString;
233
+ session: z.ZodString;
234
+ }, z.core.$strict>;
235
+ name: z.ZodString;
236
+ publicKey: z.ZodString;
237
+ fingerprint: z.ZodString;
238
+ }, z.core.$strict>;
239
+ export type DiscoverRow = z.infer<typeof discoverRowSchema>;
240
+ export declare const hubFrame: z.ZodDiscriminatedUnion<[z.ZodObject<{
241
+ type: z.ZodLiteral<"registered">;
242
+ rid: z.ZodString;
243
+ endpoint: z.ZodString;
244
+ ok: z.ZodBoolean;
245
+ reason: z.ZodOptional<z.ZodString>;
246
+ }, z.core.$strict>, z.ZodObject<{
247
+ type: z.ZodLiteral<"discovered">;
248
+ rid: z.ZodString;
249
+ endpoints: z.ZodArray<z.ZodObject<{
250
+ address: z.ZodObject<{
251
+ version: z.ZodLiteral<2>;
252
+ transport: z.ZodLiteral<"hub">;
253
+ node: z.ZodString;
254
+ endpoint: z.ZodString;
255
+ project: z.ZodString;
256
+ session: z.ZodString;
257
+ }, z.core.$strict>;
258
+ name: z.ZodString;
259
+ publicKey: z.ZodString;
260
+ fingerprint: z.ZodString;
261
+ }, z.core.$strict>>;
262
+ omitted: z.ZodNumber;
263
+ }, z.core.$strict>, z.ZodObject<{
264
+ type: z.ZodLiteral<"deliver">;
265
+ envelope: z.ZodObject<{
266
+ version: z.ZodLiteral<2>;
267
+ id: z.ZodString;
268
+ sender: z.ZodObject<{
269
+ version: z.ZodLiteral<2>;
270
+ transport: z.ZodLiteral<"hub">;
271
+ node: z.ZodString;
272
+ endpoint: z.ZodString;
273
+ project: z.ZodString;
274
+ session: z.ZodString;
275
+ }, z.core.$strict>;
276
+ target: z.ZodObject<{
277
+ version: z.ZodLiteral<2>;
278
+ transport: z.ZodLiteral<"hub">;
279
+ node: z.ZodString;
280
+ endpoint: z.ZodString;
281
+ project: z.ZodString;
282
+ session: z.ZodString;
283
+ }, z.core.$strict>;
284
+ sent: z.ZodNumber;
285
+ chain: z.ZodObject<{
286
+ id: z.ZodString;
287
+ started: z.ZodNumber;
288
+ hop: z.ZodNumber;
289
+ readOnly: z.ZodBoolean;
290
+ }, z.core.$strict>;
291
+ text: z.ZodString;
292
+ }, z.core.$strict>;
293
+ sig: z.ZodString;
294
+ sender: z.ZodObject<{
295
+ node: z.ZodString;
296
+ name: z.ZodString;
297
+ publicKey: z.ZodString;
298
+ fingerprint: z.ZodString;
299
+ }, z.core.$strict>;
300
+ }, z.core.$strict>, z.ZodObject<{
301
+ type: z.ZodLiteral<"sendResult">;
302
+ id: z.ZodString;
303
+ status: z.ZodEnum<{
304
+ delivered: "delivered";
305
+ offline: "offline";
306
+ rejected: "rejected";
307
+ }>;
308
+ reason: z.ZodOptional<z.ZodString>;
309
+ }, z.core.$strict>, z.ZodObject<{
310
+ type: z.ZodLiteral<"ack">;
311
+ id: z.ZodString;
312
+ status: z.ZodEnum<{
313
+ queued: "queued";
314
+ refused: "refused";
315
+ }>;
316
+ reason: z.ZodOptional<z.ZodString>;
317
+ }, z.core.$strict>, z.ZodObject<{
318
+ type: z.ZodLiteral<"node-enrolled">;
319
+ node: z.ZodObject<{
320
+ node: z.ZodString;
321
+ name: z.ZodString;
322
+ publicKey: z.ZodString;
323
+ fingerprint: z.ZodString;
324
+ }, z.core.$strict>;
325
+ enrolledAt: z.ZodNumber;
326
+ }, z.core.$strict>, z.ZodObject<{
327
+ type: z.ZodLiteral<"node-revoked">;
328
+ node: z.ZodString;
329
+ }, z.core.$strict>, z.ZodObject<{
330
+ type: z.ZodLiteral<"endpoint-gone">;
331
+ endpoint: z.ZodString;
332
+ }, z.core.$strict>, z.ZodObject<{
333
+ type: z.ZodLiteral<"error">;
334
+ reason: z.ZodString;
335
+ }, z.core.$strict>], "type">;
336
+ export type HubFrame = z.infer<typeof hubFrame>;
337
+ export declare const enrollRequestSchema: z.ZodObject<{
338
+ token: z.ZodString;
339
+ node: z.ZodString;
340
+ name: z.ZodString;
341
+ publicKey: z.ZodString;
342
+ }, z.core.$strict>;
343
+ export type EnrollRequest = z.infer<typeof enrollRequestSchema>;
344
+ export declare const enrollResponseSchema: z.ZodObject<{
345
+ ok: z.ZodLiteral<true>;
346
+ node: z.ZodString;
347
+ fingerprint: z.ZodString;
348
+ wsUrl: z.ZodString;
349
+ audience: z.ZodString;
350
+ }, z.core.$strict>;
351
+ export declare const timeResponseSchema: z.ZodObject<{
352
+ now: z.ZodNumber;
353
+ }, z.core.$strict>;
354
+ /** Parse one inbound JSON frame with the byte cap first; undefined on any violation. */
355
+ export declare function parseFrame<T>(schema: z.ZodType<T>, raw: string | Buffer): T | undefined;
356
+ export declare function encodeFrame(value: unknown): string;
@@ -0,0 +1,192 @@
1
+ /**
2
+ * Collaboration hub wire contract (hub/README.md §4, §6, §8). Pure: zod and node:crypto only,
3
+ * no filesystem or darwin runtime imports, because the hub's Lambda bundle and its dependency-free
4
+ * local server import this exact module — one definition for both ends.
5
+ */
6
+ import { createHash, createPrivateKey, createPublicKey, generateKeyPairSync, randomBytes, sign as edSign, verify as edVerify } from 'node:crypto';
7
+ import { z } from 'zod';
8
+ export const MAX_TEXT_BYTES = 4096;
9
+ export const MAX_FRAME_BYTES = 16_384;
10
+ export const MAX_QUEUE = 8;
11
+ export const MESSAGE_TTL_MS = 60_000;
12
+ export const CHAIN_TTL_MS = 300_000;
13
+ export const MAX_HOPS = 4;
14
+ /** Connect assertion and envelope `sent` clock window (both directions). */
15
+ export const CLOCK_SKEW_MS = 60_000;
16
+ export const MAX_DISCOVERY = 32;
17
+ export const ENROLL_TOKEN_TTL_MS = 600_000;
18
+ export const uuidSchema = z.string().uuid();
19
+ export const sessionSchema = z.string().regex(/^[a-zA-Z0-9_-]{1,128}$/);
20
+ /** Normalized remote identity: lowercase host plus 1–8 path segments, ≤256 bytes. */
21
+ export const hubProjectSchema = z.string().max(256).regex(/^[a-z0-9.-]+(\/[A-Za-z0-9._~-]+){1,8}$/);
22
+ export const nodeNameSchema = z.string().regex(/^[A-Za-z0-9._-]{1,64}$/);
23
+ /** Ed25519 SPKI DER (44 bytes) as base64. */
24
+ export const publicKeySchema = z.string().regex(/^[A-Za-z0-9+/]{59}[A-Za-z0-9+/=]$/);
25
+ export const signatureSchema = z.string().regex(/^[A-Za-z0-9_-]{86}$/);
26
+ export const fingerprintSchema = z.string().regex(/^[a-f0-9]{64}$/);
27
+ export const nonceSchema = z.string().regex(/^[A-Za-z0-9_-]{22}$/);
28
+ export const tokenSchema = z.string().regex(/^dhub1_[A-Za-z0-9_-]{43}$/);
29
+ const reasonSchema = z.string().max(512);
30
+ const textSchema = z.string().min(1).refine(t => Buffer.byteLength(t) <= MAX_TEXT_BYTES, 'text exceeds 4096 UTF-8 bytes');
31
+ export const chainSchema = z.object({ id: uuidSchema, started: z.number().int(), hop: z.number().int().min(0).max(MAX_HOPS), readOnly: z.boolean() }).strict();
32
+ export const hubAddressSchema = z.object({ version: z.literal(2), transport: z.literal('hub'), node: uuidSchema, endpoint: uuidSchema, project: hubProjectSchema, session: sessionSchema }).strict();
33
+ export const hubEnvelopeSchema = z.object({ version: z.literal(2), id: uuidSchema, sender: hubAddressSchema, target: hubAddressSchema, sent: z.number().int(), chain: chainSchema, text: textSchema }).strict();
34
+ export function generateNodeKeys() {
35
+ const { publicKey, privateKey } = generateKeyPairSync('ed25519');
36
+ return {
37
+ publicKey: publicKey.export({ format: 'der', type: 'spki' }).toString('base64'),
38
+ privateKey: privateKey.export({ format: 'der', type: 'pkcs8' }).toString('base64'),
39
+ };
40
+ }
41
+ export function fingerprint(publicKey) {
42
+ return createHash('sha256').update(Buffer.from(publicKeySchema.parse(publicKey), 'base64')).digest('hex');
43
+ }
44
+ /** Display form: first 16 hex in groups of four. Pinning always compares the full key. */
45
+ export function shortFingerprint(value) {
46
+ return (value.slice(0, 16).match(/.{4}/g) ?? []).join(':');
47
+ }
48
+ function signBytes(privateKey, bytes) {
49
+ return edSign(null, bytes, createPrivateKey({ key: Buffer.from(privateKey, 'base64'), format: 'der', type: 'pkcs8' })).toString('base64url');
50
+ }
51
+ function verifyBytes(publicKey, bytes, signature) {
52
+ if (!signatureSchema.safeParse(signature).success || !publicKeySchema.safeParse(publicKey).success)
53
+ return false;
54
+ try {
55
+ const key = createPublicKey({ key: Buffer.from(publicKey, 'base64'), format: 'der', type: 'spki' });
56
+ if (key.asymmetricKeyType !== 'ed25519')
57
+ return false;
58
+ return edVerify(null, bytes, key, Buffer.from(signature, 'base64url'));
59
+ }
60
+ catch {
61
+ return false;
62
+ }
63
+ }
64
+ /** Serialize the zod-parsed value: key order is the schema's, identical on both ends. */
65
+ function envelopeBytes(envelope) {
66
+ return Buffer.from(`darwin-hub-envelope/v1\n${JSON.stringify(hubEnvelopeSchema.parse(envelope))}`, 'utf8');
67
+ }
68
+ export function signEnvelope(privateKey, envelope) {
69
+ return signBytes(privateKey, envelopeBytes(envelope));
70
+ }
71
+ export function verifyEnvelope(publicKey, envelope, signature) {
72
+ const parsed = hubEnvelopeSchema.safeParse(envelope);
73
+ return parsed.success && verifyBytes(publicKey, envelopeBytes(parsed.data), signature);
74
+ }
75
+ /** `audience` is `<apiId>/<stage>`, binding an assertion to one deployment. */
76
+ export function connectMessage(audience, node, ts, nonce) {
77
+ return Buffer.from(`darwin-hub-connect/v1\n${audience}\n${node}\n${ts}\n${nonce}`, 'utf8');
78
+ }
79
+ export function connectHeaders(audience, node, privateKey, now = Date.now()) {
80
+ const nonce = randomBytes(16).toString('base64url');
81
+ return { 'X-Darwin-Node': node, 'X-Darwin-Ts': String(now), 'X-Darwin-Nonce': nonce, 'X-Darwin-Sig': signBytes(privateKey, connectMessage(audience, node, now, nonce)) };
82
+ }
83
+ /** Case-insensitive header lookup, bounded parse; undefined on any malformed field. */
84
+ export function parseConnectHeaders(headers) {
85
+ if (!headers)
86
+ return undefined;
87
+ const get = (name) => Object.entries(headers).find(([key]) => key.toLowerCase() === name)?.[1];
88
+ const node = uuidSchema.safeParse(get('x-darwin-node'));
89
+ const ts = get('x-darwin-ts');
90
+ const nonce = nonceSchema.safeParse(get('x-darwin-nonce'));
91
+ const sig = signatureSchema.safeParse(get('x-darwin-sig'));
92
+ if (!node.success || !nonce.success || !sig.success || ts === undefined || !/^[0-9]{1,15}$/.test(ts))
93
+ return undefined;
94
+ return { node: node.data, ts: Number(ts), nonce: nonce.data, sig: sig.data };
95
+ }
96
+ export function verifyConnect(publicKey, audience, assertion, now = Date.now()) {
97
+ return Math.abs(now - assertion.ts) <= CLOCK_SKEW_MS
98
+ && verifyBytes(publicKey, connectMessage(audience, assertion.node, assertion.ts, assertion.nonce), assertion.sig);
99
+ }
100
+ export function mintToken() { return `dhub1_${randomBytes(32).toString('base64url')}`; }
101
+ export function tokenHash(token) { return createHash('sha256').update(token, 'utf8').digest('hex'); }
102
+ // ---------------------------------------------------------------------------
103
+ // Automatic cross-machine project identity (§4). Pure: the caller runs git.
104
+ /**
105
+ * Normalize an `origin` URL to `host/path`. Userinfo (which may hold a token), port, scheme and
106
+ * `.git` are dropped; host lowercased, path case kept. Local paths and file URLs are refused:
107
+ * they name a directory on one machine, not a shared project.
108
+ */
109
+ export function normalizeRemote(raw) {
110
+ const value = raw.trim();
111
+ if (!value || value.length > 2048 || /[\s\0]/.test(value))
112
+ throw new Error('remote URL empty, oversized or contains whitespace');
113
+ let host;
114
+ let pathname;
115
+ const scp = /^(?:[^@/:]+@)?([^/:@]+):(?!\/\/)(.+)$/.exec(value);
116
+ if (!value.includes('://') && scp) {
117
+ if (/^[a-zA-Z]$/.test(scp[1]))
118
+ throw new Error('remote looks like a local drive path');
119
+ host = scp[1];
120
+ pathname = scp[2];
121
+ }
122
+ else {
123
+ let url;
124
+ try {
125
+ url = new URL(value);
126
+ }
127
+ catch {
128
+ throw new Error('remote is neither a URL nor scp-like host:path (local paths are not shared identities)');
129
+ }
130
+ if (!['https:', 'http:', 'ssh:', 'git:', 'git+ssh:', 'ssh+git:'].includes(url.protocol))
131
+ throw new Error(`remote scheme ${url.protocol} is not a network remote`);
132
+ host = url.hostname;
133
+ pathname = url.pathname;
134
+ }
135
+ host = host.toLowerCase().replace(/^\[|\]$/g, '');
136
+ const segments = pathname.split('/').filter(Boolean);
137
+ if (segments.length)
138
+ segments[segments.length - 1] = segments[segments.length - 1].replace(/\.git$/, '');
139
+ const result = hubProjectSchema.safeParse([host, ...segments.filter(Boolean)].join('/'));
140
+ if (!result.success)
141
+ throw new Error('normalized remote identity is not host/owner/repo shaped (≤8 segments, ≤256 bytes, [A-Za-z0-9._~-])');
142
+ return result.data;
143
+ }
144
+ export function projectLabel(project) {
145
+ return project.slice(project.lastIndexOf('/') + 1).slice(0, 64);
146
+ }
147
+ // ---------------------------------------------------------------------------
148
+ // Frames. Client → hub carries `action` (the API Gateway route key); hub → client carries `type`.
149
+ const rid = uuidSchema;
150
+ export const registerFrame = z.object({ action: z.literal('register'), rid, endpoint: uuidSchema, project: hubProjectSchema, session: sessionSchema }).strict();
151
+ export const unregisterFrame = z.object({ action: z.literal('unregister'), endpoint: uuidSchema }).strict();
152
+ export const discoverFrame = z.object({ action: z.literal('discover'), rid }).strict();
153
+ export const sendFrame = z.object({ action: z.literal('send'), envelope: hubEnvelopeSchema, sig: signatureSchema }).strict();
154
+ export const ackFrame = z.object({ action: z.literal('ack'), id: uuidSchema, status: z.enum(['queued', 'refused']), reason: reasonSchema.optional() }).strict();
155
+ export const pingFrame = z.object({ action: z.literal('ping') }).strict();
156
+ export const clientFrame = z.discriminatedUnion('action', [registerFrame, unregisterFrame, discoverFrame, sendFrame, ackFrame, pingFrame]);
157
+ export const nodeInfoSchema = z.object({ node: uuidSchema, name: nodeNameSchema, publicKey: publicKeySchema, fingerprint: fingerprintSchema }).strict();
158
+ export const discoverRowSchema = z.object({ address: hubAddressSchema, name: nodeNameSchema, publicKey: publicKeySchema, fingerprint: fingerprintSchema }).strict();
159
+ export const hubFrame = z.discriminatedUnion('type', [
160
+ z.object({ type: z.literal('registered'), rid, endpoint: uuidSchema, ok: z.boolean(), reason: reasonSchema.optional() }).strict(),
161
+ z.object({ type: z.literal('discovered'), rid, endpoints: z.array(discoverRowSchema).max(MAX_DISCOVERY), omitted: z.number().int().min(0) }).strict(),
162
+ z.object({ type: z.literal('deliver'), envelope: hubEnvelopeSchema, sig: signatureSchema, sender: nodeInfoSchema }).strict(),
163
+ z.object({ type: z.literal('sendResult'), id: uuidSchema, status: z.enum(['delivered', 'offline', 'rejected']), reason: reasonSchema.optional() }).strict(),
164
+ z.object({ type: z.literal('ack'), id: uuidSchema, status: z.enum(['queued', 'refused']), reason: reasonSchema.optional() }).strict(),
165
+ z.object({ type: z.literal('node-enrolled'), node: nodeInfoSchema, enrolledAt: z.number().int() }).strict(),
166
+ z.object({ type: z.literal('node-revoked'), node: uuidSchema }).strict(),
167
+ z.object({ type: z.literal('endpoint-gone'), endpoint: uuidSchema }).strict(),
168
+ z.object({ type: z.literal('error'), reason: reasonSchema }).strict(),
169
+ ]);
170
+ export const enrollRequestSchema = z.object({ token: tokenSchema, node: uuidSchema, name: nodeNameSchema, publicKey: publicKeySchema }).strict();
171
+ export const enrollResponseSchema = z.object({ ok: z.literal(true), node: uuidSchema, fingerprint: fingerprintSchema, wsUrl: z.string().url().max(512), audience: z.string().max(256) }).strict();
172
+ export const timeResponseSchema = z.object({ now: z.number().int() }).strict();
173
+ /** Parse one inbound JSON frame with the byte cap first; undefined on any violation. */
174
+ export function parseFrame(schema, raw) {
175
+ const size = typeof raw === 'string' ? Buffer.byteLength(raw) : raw.length;
176
+ if (size > MAX_FRAME_BYTES)
177
+ return undefined;
178
+ try {
179
+ const parsed = schema.safeParse(JSON.parse(raw.toString()));
180
+ return parsed.success ? parsed.data : undefined;
181
+ }
182
+ catch {
183
+ return undefined;
184
+ }
185
+ }
186
+ export function encodeFrame(value) {
187
+ const text = JSON.stringify(value);
188
+ if (Buffer.byteLength(text) > MAX_FRAME_BYTES)
189
+ throw new Error('Encoded hub frame exceeds 16 KiB; shorten text/identities');
190
+ return text;
191
+ }
192
+ //# sourceMappingURL=hub-wire.js.map
@@ -0,0 +1 @@
1
+ {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,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IAAC,CAAC;IACrH,MAAM,CAAC;QAAC,OAAO,SAAS,CAAC;IAAC,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACnC,IAAI,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,eAAe;QAAE,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;IAC5H,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,78 @@
1
+ import { type PeerAddress, type PeerInput, type PeerTransport } from './protocol.js';
2
+ import { HubTransport } from './hub-transport.js';
3
+ export declare function socketPath(id: string): string;
4
+ /** Bounded metadata-only endpoint projection, separate from immutable lease discovery. */
5
+ export declare function discoverPeers(): Promise<{
6
+ endpoints: PeerAddress[];
7
+ omitted: number;
8
+ uninspected: number;
9
+ scanLimited: boolean;
10
+ scope: string;
11
+ }>;
12
+ /** One parent session, never a daemon or SDK loop. Only drivers drain the inbox. */
13
+ export declare class LocalCollaboration implements PeerTransport {
14
+ private readonly projectRoot;
15
+ readonly session: string;
16
+ private readonly readOnly;
17
+ private server;
18
+ private registration;
19
+ private sockets;
20
+ private inbox;
21
+ private listeners;
22
+ private notices;
23
+ private seen;
24
+ private chainCounts;
25
+ private cause?;
26
+ private outgoing;
27
+ private peerTurn;
28
+ private lastPeerId?;
29
+ private denied;
30
+ private admitted;
31
+ private window;
32
+ private accepting;
33
+ private stopped;
34
+ private generation;
35
+ private canonicalRoot;
36
+ /** Cross-machine transport (hub/README.md); shares this session's inbox, ledger and caps. */
37
+ readonly hub: HubTransport;
38
+ constructor(projectRoot: string, session: string, readOnly?: () => boolean);
39
+ get project(): string;
40
+ get address(): PeerAddress | undefined;
41
+ /** The project root this session was started in (not canonicalized). */
42
+ get root(): string;
43
+ get pending(): number;
44
+ get active(): boolean;
45
+ subscribe(listener: () => void): () => void;
46
+ takeNotices(): string[];
47
+ private changed;
48
+ private notice;
49
+ start(): Promise<void>;
50
+ /** Headless closes admission before draining a finite snapshot; not an idle daemon. */
51
+ stopAdmission(): void;
52
+ close(reason: string): void;
53
+ private receive;
54
+ private respond;
55
+ private fresh;
56
+ private admit;
57
+ /**
58
+ * Hub admission: the transport already checked block/pin/signature/target. Enrollment is the
59
+ * grant (no per-pair confirmation); everything after is the shared local admission.
60
+ */
61
+ private admitHub;
62
+ /** Drop queued hub input from one node (revoked at the hub, or blocked by the user). */
63
+ dropHubNode(node: string, reason: string): void;
64
+ /** peer_discover: the local projection unchanged, plus the bounded hub projection. */
65
+ discover(): Promise<Awaited<ReturnType<typeof discoverPeers>> & {
66
+ hub: Awaited<ReturnType<HubTransport['discover']>>;
67
+ }>;
68
+ private enqueue;
69
+ /** Only a driver at idle takes input. Runtime rechecks it immediately before invocation. */
70
+ take(): PeerInput | undefined;
71
+ validateDelivery(input: PeerInput): void;
72
+ beginHumanTurn(): void;
73
+ beginPeerTurn(input: PeerInput): void;
74
+ permissionDenied(): void;
75
+ get fromPeer(): boolean;
76
+ get peerReadOnly(): boolean;
77
+ send(target: string, text: string): Promise<string>;
78
+ }