@johnhenry/wsh 0.48.0 → 0.49.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.
@@ -0,0 +1,2775 @@
1
+ # wsh Protocol Specification — v1
2
+ # This file is the single source of truth for all message types.
3
+ # Run: npm run codegen (node spec/codegen.mjs, from the repository root)
4
+
5
+ protocol:
6
+ name: wsh
7
+ version: "wsh-v1"
8
+ wire_format: cbor
9
+ framing: length_prefixed_be32
10
+
11
+ enums:
12
+ ChannelKind:
13
+ type: string
14
+ values: [pty, exec, meta, file, tcp, udp, job, rpc]
15
+ value_descriptions:
16
+ pty: "Interactive pseudo-terminal session with resize support"
17
+ exec: "One-shot command execution without a PTY"
18
+ meta: "Control metadata channel (session management)"
19
+ file: "File transfer channel (upload or download)"
20
+ tcp: "Gateway-proxied TCP stream to an external host:port"
21
+ udp: "Gateway-proxied UDP datagram socket to an external host:port"
22
+ job: "Background automation job channel for structured task execution"
23
+ rpc: "Typed object-mode channel (wsh #85): Open.command names the protocol, the data stream is a CBOR sequence of JSON-RPC 2.0 messages; offered only when ServerHello.features lists rpc and rpc-protocol:<name>"
24
+ AuthMethod:
25
+ type: string
26
+ values: [pubkey, password]
27
+ SessionDataMode:
28
+ type: string
29
+ values: [stream, virtual]
30
+ value_descriptions:
31
+ stream: "Session uses transport-opened byte streams"
32
+ virtual: "Session uses message-framed SessionData payloads"
33
+ FileEntryType:
34
+ # wsh #59: previously each implementation invented this set privately
35
+ # (the JS SDK's WshFileListEntry.type union) while FileResult.metadata
36
+ # stayed an untyped `json` bag. Generated into both languages now so a
37
+ # directory listing can't describe a symlink as a plain file in one
38
+ # implementation and not the other.
39
+ type: string
40
+ values: [file, directory, symlink, device, pipe, socket]
41
+ value_descriptions:
42
+ file: "Regular file"
43
+ directory: "Directory"
44
+ symlink: "Symbolic link -- see FileEntry.symlink_target for its target"
45
+ device: "Block or character device node"
46
+ pipe: "Named pipe (FIFO)"
47
+ socket: "Unix domain socket"
48
+
49
+ messages:
50
+ handshake:
51
+ Hello:
52
+ code: 0x01
53
+ description: >
54
+ First message sent by the client to initiate a connection.
55
+ Contains the protocol version, username, requested features,
56
+ and preferred authentication method.
57
+ fields:
58
+ version:
59
+ type: string
60
+ required: true
61
+ username:
62
+ type: string
63
+ required: true
64
+ features:
65
+ type: "string[]"
66
+ default: "[]"
67
+ auth_method:
68
+ type: AuthMethod
69
+ required: false
70
+
71
+ ServerHello:
72
+ code: 0x02
73
+ description: >
74
+ Server response to Hello. Assigns a session_id, advertises
75
+ server features, and lists authorized key fingerprints.
76
+ fields:
77
+ session_id:
78
+ type: string
79
+ required: true
80
+ features:
81
+ type: "string[]"
82
+ default: "[]"
83
+ fingerprints:
84
+ type: "string[]"
85
+ default: "[]"
86
+ description: >
87
+ Fingerprints of the keys THIS SERVER currently authorizes for
88
+ login (its ~/.wsh/authorized_keys, not this server's own
89
+ identity). wsh #59 audit: the Rust client's KnownHosts TOFU
90
+ check (crates/wsh-client/src/client.rs verify_host_key) reads
91
+ fingerprints[0] as if it were a stable per-server host identity
92
+ -- it is not; it is whichever authorized client key happens to
93
+ load first, which can differ per user, per config edit, or be
94
+ empty. That is a pre-existing latent gap, not introduced here.
95
+ Use host_fingerprint (below) for actual host identity.
96
+ host_fingerprint:
97
+ type: string
98
+ required: false
99
+ description: >
100
+ wsh #59: the formal host-identity record. SHA-256 fingerprint
101
+ (hex, per crypto.fingerprint) of the server's own persistent
102
+ Ed25519 host identity key -- what TOFU should actually pin,
103
+ distinct from `fingerprints` above. Optional because minting
104
+ and persisting a server host keypair is a separate, security-
105
+ sensitive feature this spec change does not implement; no
106
+ wsh-server release populates it yet. A TOFU-capable client MUST
107
+ treat an absent/empty host_fingerprint as "this server does not
108
+ support host verification" and must NOT fall back to
109
+ fingerprints[0] to fabricate one.
110
+
111
+ Challenge:
112
+ code: 0x03
113
+ description: >
114
+ Sent by the server with a random nonce for the client to sign
115
+ with its private key (pubkey auth) or as part of password auth.
116
+ Carries session_id directly so the auth transcript never depends
117
+ on the client having already received (and processed) ServerHello
118
+ first -- ServerHello and Challenge can arrive in either order, or
119
+ ServerHello can be skipped entirely, with no effect on the
120
+ transcript's correctness.
121
+ fields:
122
+ nonce:
123
+ type: bytes
124
+ required: true
125
+ session_id:
126
+ type: string
127
+ required: true
128
+
129
+ AuthMethods:
130
+ code: 0x04
131
+ description: >
132
+ Sent by the server to advertise which authentication methods
133
+ are available (pubkey, password, or both).
134
+ fields:
135
+ methods:
136
+ type: "AuthMethod[]"
137
+ required: true
138
+
139
+ Auth:
140
+ code: 0x05
141
+ description: >
142
+ Client authentication response. Contains the method and
143
+ either a signature+public_key (pubkey) or password (password).
144
+
145
+ The pubkey signature is over the transcript
146
+ SHA-256("wsh-v1\0" || lp(username) || lp(session_id) || nonce || channel_binding)
147
+ (lp = 4-byte big-endian length prefix). channel_binding (wsh #119)
148
+ is empty unless both ends agree to bind it, which makes the
149
+ signature specific to the connection it was made over, so an
150
+ intermediary that relays a genuine challenge to the host cannot use
151
+ the signature it gets back. It is
152
+ SHA-256("wsh-channel-binding-v1\0" || lp(kind) || lp(value) ...)
153
+ over the kinds present, in this order, with these values:
154
+ cert-hash the 32-byte SHA-256 of the WebTransport certificate
155
+ pinned through serverCertificateHashes (a client
156
+ with exactly one pinned hash; a host serving a
157
+ self-signed certificate)
158
+ host the raw 32-byte Ed25519 host key that proved
159
+ possession in ServerHello (host-key features), so a
160
+ relay presenting its own host key binds to ITS key
161
+ tls-exporter 32 bytes of TLS keying material, label
162
+ "EXPORTER-wsh-channel-binding", empty context
163
+ (RFC 5705 / RFC 8446 7.5), where both ends can
164
+ compute it (Node over wss:// served by the process
165
+ itself; never a browser, never behind a
166
+ TLS-terminating proxy)
167
+ Negotiation is by feature string only: a host lists
168
+ "channel-binding:<kind>" in ServerHello.features for each kind it
169
+ can bind and "channel-binding-required" when it will accept no
170
+ login without one; a client binds every kind the host offers and it
171
+ can supply and signs that; the host accepts the signature over any
172
+ non-empty combination of the kinds it offered (the empty binding
173
+ only when it does not require one, and it requires the kinds it
174
+ names). With no kind the binding is the empty byte string, exactly
175
+ the transcript released peers sign, so they keep working. A client
176
+ that must not authenticate unbound refuses when it ends up with no
177
+ kind -- which also defeats an intermediary stripping the offer.
178
+
179
+ Test vectors (channel_binding = SHA-256 of the layout above, kinds
180
+ filled with one repeated byte, 32 bytes each):
181
+ host = 0x22*32
182
+ 266d39f1ffe60713ab836382fa8373407c8facaa88a3ddaf80c1cd5433e80dcc
183
+ cert-hash = 0x11*32, host = 0x22*32, tls-exporter = 0x33*32
184
+ dc2256bcbd4bff249870321a14390d305147a1e4e6dc701c0a3fc3dfff750da7
185
+ fields:
186
+ method:
187
+ type: AuthMethod
188
+ required: true
189
+ signature:
190
+ type: bytes
191
+ required: false
192
+ public_key:
193
+ type: bytes
194
+ required: false
195
+ password:
196
+ type: string
197
+ required: false
198
+
199
+ AuthOk:
200
+ code: 0x06
201
+ description: >
202
+ Sent by the server on successful authentication. Contains
203
+ the session_id, an opaque connection token, and the connection
204
+ lifetime. Neither field is a credential: token and ttl are kept
205
+ on the wire only because released peers require them (they are
206
+ not optional in 0.35 / rust-v0.6.0 clients).
207
+ fields:
208
+ session_id:
209
+ type: string
210
+ required: true
211
+ token:
212
+ type: bytes
213
+ required: true
214
+ description: >
215
+ An opaque per-connection value. It carries no authority: no
216
+ message accepts it back (Resume and Attach use the per-session
217
+ token from OpenOk, never this one), a host MUST NOT treat it as
218
+ a credential, and a client MUST NOT present it as one. Before
219
+ wsh 0.36 this text called it "a signed session token"; the
220
+ Rust host still sends an HMAC there, which nothing verifies.
221
+ ttl:
222
+ type: u64
223
+ required: true
224
+ description: >
225
+ Seconds this host will keep the connection before it ends it;
226
+ 0 means no limit is promised. A host that sends a non-zero ttl
227
+ MUST end the connection when it elapses (the client reconnects
228
+ and authenticates again); the JS host does so when started
229
+ with connectionTtlMs, and sends 0 otherwise. Before wsh 0.36 the
230
+ JS host sent a fixed 3600 it never enforced, and the Rust
231
+ host sends its session_ttl setting (default 86400) likewise
232
+ unenforced -- a client must not rely on a non-zero ttl from a
233
+ host that does not advertise otherwise.
234
+
235
+ AuthFail:
236
+ code: 0x07
237
+ description: >
238
+ Sent by the server when authentication fails.
239
+ fields:
240
+ reason:
241
+ type: string
242
+ required: true
243
+
244
+ channel:
245
+ Open:
246
+ code: 0x10
247
+ description: >
248
+ Request to open a new channel (PTY, exec, meta, or file).
249
+ The server replies with OpenOk or OpenFail.
250
+ fields:
251
+ kind:
252
+ type: ChannelKind
253
+ required: true
254
+ command:
255
+ type: string
256
+ required: false
257
+ cols:
258
+ type: u16
259
+ required: false
260
+ rows:
261
+ type: u16
262
+ required: false
263
+ env:
264
+ type: "map<string,string>"
265
+ required: false
266
+ stdio:
267
+ type: string
268
+ required: false
269
+ description: >
270
+ Only for `exec` channels. `"pipes"` asks the host to run the
271
+ command on plain pipes instead of a PTY: no echo, no terminal
272
+ rewriting of input, stdout and stderr kept apart, and an EOF
273
+ signal for stdin (a zero-length SessionData from the client).
274
+ Send it only to a host that advertises the `exec-pipes` feature
275
+ in ServerHello.features; an older host rejects the unknown field.
276
+ Omitted (or `"pty"`) is the historical PTY behaviour.
277
+ target:
278
+ type: string
279
+ required: false
280
+ description: >
281
+ Which of the host's execution targets (a container, a VM, a
282
+ worker, a sandbox) this channel runs on or reads from. Send it
283
+ only to a host that advertises the `targets` feature in
284
+ ServerHello.features; an older host rejects the unknown field.
285
+ Omitted: the host's own default, exactly as before. A host that
286
+ does not know the name, or does not allow the caller on it,
287
+ answers OpenFail with the same reason for both (the answer does
288
+ not reveal which targets exist); it never runs the channel
289
+ somewhere else. Discover the names with ListTargets.
290
+
291
+ OpenOk:
292
+ code: 0x11
293
+ description: >
294
+ Sent by the server to confirm a channel was opened successfully.
295
+ Contains the assigned channel_id and any associated stream_ids.
296
+ fields:
297
+ channel_id:
298
+ type: u32
299
+ required: true
300
+ stream_ids:
301
+ type: "u32[]"
302
+ default: "[]"
303
+ data_mode:
304
+ type: SessionDataMode
305
+ default: '"stream"'
306
+ capabilities:
307
+ type: "string[]"
308
+ default: "[]"
309
+ session_id:
310
+ type: string
311
+ required: false
312
+ description: >
313
+ Present only for pty/exec channels (session-bearing kinds; omitted
314
+ for file channels, which have no Attach/Resume-able session).
315
+ The server-assigned session_id this channel belongs to -- pass it
316
+ to Attach/Resume from another connection, or discover it later via
317
+ SessionList.
318
+ token:
319
+ type: bytes
320
+ required: false
321
+ description: >
322
+ Present only alongside session_id. An HMAC-SHA256 credential
323
+ (see wsh-core's token module) scoped to this specific session_id,
324
+ minted at Open time. Resume requires presenting this exact token
325
+ back; Attach accepts it as an alternative to (not a replacement
326
+ for) ownership/ACL-grant authorization -- see Attach's
327
+ description for the reasoning.
328
+ stderr_channel_id:
329
+ type: u32
330
+ required: false
331
+ description: >
332
+ Present only when the host granted `Open.stdio = "pipes"`. The
333
+ command's stderr arrives as SessionData on this channel id (the
334
+ channel_id field itself carries stdout), always before the
335
+ channel's Exit. The OpenOk then also lists `stdin-eof` in
336
+ `capabilities`: a zero-length SessionData from the client on
337
+ `channel_id` closes the command's stdin. stderr is not retained
338
+ for Attach/Resume replay.
339
+
340
+ OpenFail:
341
+ code: 0x12
342
+ description: >
343
+ Sent by the server when a channel open request fails.
344
+ fields:
345
+ reason:
346
+ type: string
347
+ required: true
348
+
349
+ SessionData:
350
+ code: 0x17
351
+ description: >
352
+ Bidirectional data frame for sessions that use virtual message-backed
353
+ transport instead of transport-opened byte streams.
354
+ fields:
355
+ channel_id:
356
+ type: u32
357
+ required: true
358
+ data:
359
+ type: bytes
360
+ required: true
361
+
362
+ Resize:
363
+ code: 0x13
364
+ description: >
365
+ Sent by the client to resize a PTY channel's terminal dimensions.
366
+ fields:
367
+ channel_id:
368
+ type: u32
369
+ required: true
370
+ cols:
371
+ type: u16
372
+ required: true
373
+ rows:
374
+ type: u16
375
+ required: true
376
+
377
+ Signal:
378
+ code: 0x14
379
+ description: >
380
+ Sent by the client to deliver a signal to the process group
381
+ associated with a channel (e.g. SIGINT, SIGTERM).
382
+ fields:
383
+ channel_id:
384
+ type: u32
385
+ required: true
386
+ signal:
387
+ type: string
388
+ required: true
389
+
390
+ Exit:
391
+ code: 0x15
392
+ description: >
393
+ Sent by the server when the process in a channel exits.
394
+ Contains the exit code of the terminated process.
395
+ fields:
396
+ channel_id:
397
+ type: u32
398
+ required: true
399
+ code:
400
+ type: i32
401
+ required: true
402
+
403
+ Close:
404
+ code: 0x16
405
+ description: >
406
+ Sent by either side to close a channel and release its resources.
407
+ fields:
408
+ channel_id:
409
+ type: u32
410
+ required: true
411
+
412
+ transport:
413
+ Error:
414
+ code: 0x20
415
+ description: >
416
+ Generic error message sent by either side. Contains a numeric
417
+ code and human-readable message.
418
+ fields:
419
+ code:
420
+ type: u32
421
+ required: true
422
+ message:
423
+ type: string
424
+ required: true
425
+
426
+ Ping:
427
+ code: 0x21
428
+ description: >
429
+ Keepalive ping. The peer must reply with Pong using the same id.
430
+ fields:
431
+ id:
432
+ type: u64
433
+ required: true
434
+
435
+ Pong:
436
+ code: 0x22
437
+ description: >
438
+ Keepalive pong. Echoes the id from the corresponding Ping.
439
+ fields:
440
+ id:
441
+ type: u64
442
+ required: true
443
+
444
+ session:
445
+ Attach:
446
+ code: 0x30
447
+ description: >
448
+ Attach to an existing session. The server replays the ring buffer
449
+ and broadcasts Presence.
450
+
451
+ Authorization is satisfied by EITHER a valid session token OR the
452
+ caller already owning/having been granted access to the session
453
+ (see the server's check_session_access) -- token is optional and,
454
+ if present but invalid, does not by itself cause rejection as long
455
+ as ownership/ACL access checks out. This lets a principal who was
456
+ granted access via SessionGrant (and so never received the
457
+ session's token -- only its owner does, from OpenOk) attach without
458
+ one, while still letting a token holder attach even without an
459
+ explicit ACL grant (e.g. the owner reconnecting from a fresh
460
+ connection that hasn't otherwise proven ownership yet). Compare
461
+ Resume, which requires the token unconditionally -- Resume is for
462
+ the specific case of the original credentialed connection coming
463
+ back, where demanding proof of that exact credential is meaningful;
464
+ Attach is the general "some authorized principal wants in" case,
465
+ where check_session_access is already the authoritative check.
466
+ fields:
467
+ session_id:
468
+ type: string
469
+ required: true
470
+ token:
471
+ type: bytes
472
+ required: false
473
+ mode:
474
+ type: string
475
+ default: '"control"'
476
+ device_label:
477
+ type: string
478
+ required: false
479
+ description: "Human-readable device/platform label (e.g. 'Chrome/macOS', 'wsh-cli/Linux')"
480
+
481
+ Resume:
482
+ code: 0x31
483
+ description: >
484
+ Resume a session from a specific sequence number. Like Attach
485
+ but replays only output after last_seq for efficient reconnection.
486
+
487
+ seq is the cumulative number of session OUTPUT BYTES: the host
488
+ counts every byte it produces for the session (stream data or
489
+ SessionData alike) from 0, and a client counts the bytes it has
490
+ received. No per-frame field is needed. A host that keeps a
491
+ bounded history replays from last_seq, and refuses a last_seq
492
+ older than its oldest retained byte (Error naming the gap -- fall
493
+ back to Attach) or newer than it has produced. Hosts that retain
494
+ the whole ring and ignore last_seq remain conformant, replaying
495
+ more than was asked for (both the Node host and the Rust wsh-server
496
+ honour it).
497
+
498
+ The Presence that answers a successful Attach/Resume carries, on
499
+ the entry for the caller, the channel_id assigned on this
500
+ connection and the seq of the first byte that will arrive on it
501
+ (see AttachmentInfo); the replay and the live output follow as
502
+ SessionData on that channel.
503
+
504
+ Unlike Attach, token is required and unconditionally verified --
505
+ Resume is specifically the "the credentialed connection that
506
+ received this exact token (from OpenOk, when it opened the
507
+ session) is coming back" case, so demanding proof of that
508
+ credential is the whole point. A principal who only has
509
+ ACL/ownership access but never held the token should use Attach
510
+ instead.
511
+ fields:
512
+ session_id:
513
+ type: string
514
+ required: true
515
+ token:
516
+ type: bytes
517
+ required: true
518
+ last_seq:
519
+ type: u64
520
+ required: true
521
+ description: >
522
+ The cumulative number of session OUTPUT BYTES the client has
523
+ already received for this session (its `seq`): the host counts
524
+ every byte it produces for a session -- on a stream, or in
525
+ SessionData -- from 0, and the client, which sees each of them,
526
+ counts what arrived. The host replays only the bytes at and
527
+ after that position. 0 means "from the start". A host that
528
+ keeps a bounded history refuses a last_seq older than the
529
+ oldest byte it still has (an Error naming the gap; fall back to
530
+ Attach) or newer than it has produced. Hosts that retain the
531
+ whole ring and ignore last_seq are conformant but replay more
532
+ than was asked for (the Node and Rust hosts both honour it).
533
+
534
+ Rename:
535
+ code: 0x32
536
+ description: >
537
+ Rename a session. Sent by the client to assign a human-readable
538
+ name to the session.
539
+ fields:
540
+ session_id:
541
+ type: string
542
+ required: true
543
+ name:
544
+ type: string
545
+ required: true
546
+
547
+ IdleWarning:
548
+ code: 0x33
549
+ description: >
550
+ Sent by the server when a session is approaching its idle
551
+ timeout. The expires_in field indicates seconds remaining.
552
+ fields:
553
+ expires_in:
554
+ type: u64
555
+ required: true
556
+
557
+ Shutdown:
558
+ code: 0x34
559
+ description: >
560
+ Sent by the server on graceful shutdown (SIGTERM). Clients
561
+ should save state and optionally retry after retry_after seconds.
562
+ fields:
563
+ reason:
564
+ type: string
565
+ required: true
566
+ retry_after:
567
+ type: u64
568
+ required: false
569
+
570
+ Snapshot:
571
+ code: 0x35
572
+ description: >
573
+ EXPERIMENTAL, not yet functional: intended to mark a named
574
+ position in the session recording for time-travel. The Rust
575
+ server currently accepts and authorizes this message but only
576
+ logs it -- RecordingEvent::Snapshot (and every other
577
+ RecordingEvent variant besides Start) is never actually
578
+ constructed, so nothing is written to the recording. No JS
579
+ client support exists.
580
+ fields:
581
+ label:
582
+ type: string
583
+ required: true
584
+
585
+ Presence:
586
+ code: 0x36
587
+ description: >
588
+ Broadcast to all attached clients when attachments change.
589
+ Lists all currently attached sessions with their access modes.
590
+ fields:
591
+ attachments:
592
+ type: "AttachmentInfo[]"
593
+ required: true
594
+
595
+ ControlChanged:
596
+ code: 0x37
597
+ description: >
598
+ Broadcast when the controlling client of a session changes.
599
+ fields:
600
+ new_controller:
601
+ type: string
602
+ required: true
603
+
604
+ Metrics:
605
+ code: 0x38
606
+ description: >
607
+ Server metrics snapshot (CPU, memory, session count, RTT).
608
+ Sent in response to MetricsRequest.
609
+ fields:
610
+ cpu:
611
+ type: f64
612
+ required: false
613
+ memory:
614
+ type: u64
615
+ required: false
616
+ sessions:
617
+ type: u32
618
+ required: false
619
+ rtt:
620
+ type: u64
621
+ required: false
622
+
623
+ Clipboard:
624
+ code: 0x39
625
+ description: >
626
+ Clipboard sync message for OSC 52 support. The server detects
627
+ OSC 52 escape sequences in PTY output, extracts the base64
628
+ payload, and sends this message to the client. The client may
629
+ also send this message to set the server-side clipboard.
630
+ fields:
631
+ direction:
632
+ type: string
633
+ required: true
634
+ description: '"server_to_client" or "client_to_server"'
635
+ data:
636
+ type: string
637
+ required: true
638
+ description: "Base64-encoded clipboard content"
639
+
640
+ RecordingExport:
641
+ code: 0x3a
642
+ description: >
643
+ Request or deliver a session recording export. When sent by client,
644
+ requests the recording. When sent by server, delivers the JSONL data.
645
+ fields:
646
+ session_id:
647
+ type: string
648
+ required: true
649
+ format:
650
+ type: string
651
+ default: '"jsonl"'
652
+ description: '"jsonl" or "asciicast"'
653
+ data:
654
+ type: string
655
+ required: false
656
+ description: "Recording content (only in server response)"
657
+
658
+ CommandJournal:
659
+ code: 0x3b
660
+ description: >
661
+ Structured shell command history entry with metadata.
662
+ fields:
663
+ session_id:
664
+ type: string
665
+ required: true
666
+ command:
667
+ type: string
668
+ required: true
669
+ exit_code:
670
+ type: i32
671
+ required: false
672
+ duration_ms:
673
+ type: u64
674
+ required: false
675
+ cwd:
676
+ type: string
677
+ required: false
678
+ timestamp:
679
+ type: u64
680
+ required: true
681
+
682
+ MetricsRequest:
683
+ code: 0x3c
684
+ description: >
685
+ Client request for server metrics.
686
+ fields: {}
687
+
688
+ SuspendSession:
689
+ code: 0x3d
690
+ description: >
691
+ Suspend or resume a session's PTY process (SIGSTOP/SIGCONT).
692
+ fields:
693
+ session_id:
694
+ type: string
695
+ required: true
696
+ action:
697
+ type: string
698
+ required: true
699
+ description: '"suspend" or "resume"'
700
+
701
+ RestartPty:
702
+ code: 0x3e
703
+ description: >
704
+ Restart the PTY shell without killing the session.
705
+ Preserves session metadata and ring buffer.
706
+ fields:
707
+ session_id:
708
+ type: string
709
+ required: true
710
+ command:
711
+ type: string
712
+ required: false
713
+ description: "New command to run (default: user shell)"
714
+
715
+ SessionListRequest:
716
+ code: 0x3f
717
+ description: >
718
+ Request a list of sessions visible to the authenticated user.
719
+ The server replies with SessionList.
720
+ fields: {}
721
+
722
+ SessionList:
723
+ code: 0x5f
724
+ description: >
725
+ Server response to SessionListRequest. Contains summarized
726
+ metadata for each visible session.
727
+ fields:
728
+ sessions:
729
+ type: "SessionSummary[]"
730
+ required: true
731
+
732
+ Detach:
733
+ code: 0x60
734
+ description: >
735
+ Detach the current client from a specific session.
736
+ fields:
737
+ session_id:
738
+ type: string
739
+ required: true
740
+
741
+ DetachOk:
742
+ code: 0x61
743
+ description: >
744
+ Server acknowledgment for a successful detach operation.
745
+ fields:
746
+ session_id:
747
+ type: string
748
+ required: true
749
+
750
+ DetachFail:
751
+ code: 0x62
752
+ description: >
753
+ Server response when detaching from a session fails.
754
+ fields:
755
+ reason:
756
+ type: string
757
+ required: true
758
+
759
+ mcp:
760
+ McpDiscover:
761
+ code: 0x40
762
+ description: >
763
+ Request the list of available MCP tools from the server.
764
+ The server replies with McpTools.
765
+ fields: {}
766
+
767
+ McpTools:
768
+ code: 0x41
769
+ description: >
770
+ Server response to McpDiscover. Lists all available MCP tools
771
+ with their names, descriptions, and parameter schemas.
772
+ fields:
773
+ tools:
774
+ type: "McpToolSpec[]"
775
+ required: true
776
+
777
+ McpCall:
778
+ code: 0x42
779
+ description: >
780
+ Invoke an MCP tool by name with JSON arguments.
781
+ The server replies with McpResult carrying the same call_id.
782
+ fields:
783
+ tool:
784
+ type: string
785
+ required: true
786
+ arguments:
787
+ type: json
788
+ required: true
789
+ call_id:
790
+ type: string
791
+ required: false
792
+ description: >
793
+ Correlates this call with its McpResult. Optional for
794
+ backward compatibility with peers predating it: when absent,
795
+ a client with more than one call in flight cannot tell the
796
+ replies apart and may return one call's result to another.
797
+ Senders SHOULD always set it.
798
+
799
+ McpResult:
800
+ code: 0x43
801
+ description: >
802
+ Result of an MCP tool invocation. Contains the tool's
803
+ JSON response.
804
+ fields:
805
+ result:
806
+ type: json
807
+ required: true
808
+ call_id:
809
+ type: string
810
+ required: false
811
+ description: >
812
+ Echoed verbatim from the McpCall this answers. Responders
813
+ MUST echo it when the call carried one; omitting it forces
814
+ the caller back on type-only matching.
815
+
816
+ McpCancel:
817
+ code: 0x44
818
+ description: >
819
+ Ask the server to stop an in-flight McpCall (the caller aborted).
820
+ Only sent to a server advertising the `mcp-cancel` feature, which
821
+ also advertises `mcp-call-id`: McpCancelPayload is
822
+ deny_unknown_fields on the Rust side, so an older server would
823
+ reject it. Best effort and idempotent -- a call that already
824
+ finished, or an unknown call_id, is ignored. The server aborts the
825
+ tool handler's signal and still answers the call with an McpResult
826
+ (a failure), which a caller that gave up simply discards.
827
+ fields:
828
+ call_id:
829
+ type: string
830
+ required: true
831
+ description: The call_id of the McpCall to stop.
832
+
833
+ reverse:
834
+ ReverseRegister:
835
+ code: 0x50
836
+ description: >
837
+ Register as a reverse peer so other clients can connect to
838
+ this client through the server. Includes the public key for
839
+ fingerprint derivation and advertised capabilities.
840
+
841
+ seq/record_signature form a self-certifying signed peer record
842
+ (libp2p RFC 0002/0003 pattern): the peer signs a domain-separated
843
+ transcript of its own registration fields with its identity key
844
+ (buildPeerRecordTranscript/signPeerRecord in auth.mjs -- a
845
+ distinct signing domain from the auth challenge transcript, even
846
+ though both use the same Ed25519 key). The server verifies this
847
+ against the connection's own authenticated fingerprint (closing
848
+ the impersonation surface where a client could otherwise claim
849
+ someone else's public_key) before accepting registration, and
850
+ forwards the same signed fields in PeerInfo so operators can
851
+ verify a peer's record themselves -- independent of trusting the
852
+ relay -- rather than trusting server-computed fields blindly.
853
+ seq is the signing peer's own monotonic counter (in practice
854
+ current-time-millis); a server/operator MUST reject a record
855
+ whose seq is not greater than the last one accepted for that
856
+ fingerprint, so a compromised or malicious relay can't replay a
857
+ stale (e.g. revoked-capability) record over a newer one.
858
+ fields:
859
+ username:
860
+ type: string
861
+ required: true
862
+ capabilities:
863
+ type: "string[]"
864
+ default: "[]"
865
+ peer_type:
866
+ type: string
867
+ default: '"host"'
868
+ shell_backend:
869
+ type: string
870
+ default: '"pty"'
871
+ supports_attach:
872
+ type: bool
873
+ default: false
874
+ supports_replay:
875
+ type: bool
876
+ default: false
877
+ supports_echo:
878
+ type: bool
879
+ default: false
880
+ supports_term_sync:
881
+ type: bool
882
+ default: false
883
+ public_key:
884
+ type: bytes
885
+ required: true
886
+ seq:
887
+ type: u64
888
+ required: true
889
+ record_signature:
890
+ type: bytes
891
+ required: true
892
+
893
+ ReverseList:
894
+ code: 0x51
895
+ description: >
896
+ Request the list of registered reverse peers.
897
+ The server replies with ReversePeers.
898
+ fields: {}
899
+
900
+ ReversePeers:
901
+ code: 0x52
902
+ description: >
903
+ Server response to ReverseList. Contains information about
904
+ all currently registered reverse peers.
905
+ fields:
906
+ peers:
907
+ type: "PeerInfo[]"
908
+ required: true
909
+
910
+ ReverseConnect:
911
+ code: 0x53
912
+ description: >
913
+ Connect to a registered reverse peer by fingerprint.
914
+ The server forwards the request to the target peer.
915
+ from_fingerprint identifies the requesting operator and MUST be
916
+ set by the server from the operator's own authenticated identity
917
+ when forwarding to the target -- never trust a client-supplied
918
+ value for this field, since the whole point is telling the
919
+ target who is actually asking. Before this field existed, a
920
+ target peer's onReverseConnect handler had no reliable way to
921
+ know who was requesting the connection at all.
922
+ fields:
923
+ target_fingerprint:
924
+ type: string
925
+ required: true
926
+ username:
927
+ type: string
928
+ required: true
929
+ from_fingerprint:
930
+ type: string
931
+ required: true
932
+ features:
933
+ type: "string[]"
934
+ required: false
935
+ description: >
936
+ What the OPERATOR can do, stated by the operator and bounded and
937
+ copied by the relay: "operator-proof" says it answers a
938
+ ReverseChallenge with a ReverseProof (see ReverseChallenge). An
939
+ operator states it only when the relay's ServerHello lists
940
+ "operator-proof" -- a relay that predates the field (a Rust relay,
941
+ which rejects unknown fields) would drop the connection on it.
942
+ Absent: the peer must not send a ReverseChallenge.
943
+
944
+ ReverseAccept:
945
+ code: 0x54
946
+ description: >
947
+ Sent by the target peer after it has created a reverse peer context
948
+ and is ready to receive channel open requests.
949
+ fields:
950
+ target_fingerprint:
951
+ type: string
952
+ required: true
953
+ username:
954
+ type: string
955
+ required: true
956
+ capabilities:
957
+ type: "string[]"
958
+ default: "[]"
959
+ peer_type:
960
+ type: string
961
+ default: '"host"'
962
+ shell_backend:
963
+ type: string
964
+ default: '"pty"'
965
+ supports_attach:
966
+ type: bool
967
+ default: false
968
+ supports_replay:
969
+ type: bool
970
+ default: false
971
+ supports_echo:
972
+ type: bool
973
+ default: false
974
+ supports_term_sync:
975
+ type: bool
976
+ default: false
977
+ features:
978
+ type: "string[]"
979
+ required: false
980
+ description: >
981
+ Features of the bridged host itself, in the vocabulary of
982
+ ServerHello.features (e.g. file-write, file-rename,
983
+ mcp-call-id). A relay's own ServerHello says nothing about the
984
+ host behind a bridge, so the operator reads these instead once
985
+ the bridge is up. Empty or absent means "not stated": an
986
+ operator then falls back to what it knows (the relay's
987
+ features). The relay forwards the field after bounding it; it
988
+ is the peer's own claim, as everything else in this message.
989
+
990
+ One feature is addressed to the relay rather than the operator:
991
+ "relay-multi-operator" says this peer serves several operators at
992
+ once -- it addresses its replies with RelayForward.to_fingerprint
993
+ and understands ReverseClose. Only then does a relay configured
994
+ for more than one operator per peer admit a second one.
995
+
996
+ ReverseReject:
997
+ code: 0x55
998
+ description: >
999
+ Sent by the target peer when it cannot accept a pending reverse
1000
+ connection request.
1001
+ fields:
1002
+ target_fingerprint:
1003
+ type: string
1004
+ required: true
1005
+ username:
1006
+ type: string
1007
+ required: true
1008
+ reason:
1009
+ type: string
1010
+ required: true
1011
+
1012
+ ReverseClose:
1013
+ code: 0x57
1014
+ description: >
1015
+ Sent by the relay to a PEER that serves several operators, when one
1016
+ of them leaves (its connection ended, or it was dropped): the peer
1017
+ should end that operator's bridge and clean up what belongs to it
1018
+ (its channels, processes and trusted-sender entry) while the others
1019
+ carry on. target_fingerprint is the departed operator's key. A relay
1020
+ sends this only to a peer that stated "relay-multi-operator" in
1021
+ ReverseAccept.features and only when it is configured for more than
1022
+ one operator per peer; otherwise the old rule holds -- when the
1023
+ bridge ends the relay closes the peer's connection, and no
1024
+ ReverseClose is sent. It is not forwardable and travels only
1025
+ relay -> peer.
1026
+ fields:
1027
+ target_fingerprint:
1028
+ type: string
1029
+ required: true
1030
+ reason:
1031
+ type: string
1032
+ required: false
1033
+
1034
+ ReverseChallenge:
1035
+ code: 0x58
1036
+ description: >
1037
+ Peer -> operator, between a ReverseConnect and the peer's
1038
+ ReverseAccept/Reject (wsh #117): the peer asks the operator to prove
1039
+ its identity to the PEER, instead of the peer taking the identity
1040
+ the relay stamped on ReverseConnect.from_fingerprint on trust. Sent
1041
+ only to an operator that stated "operator-proof" in
1042
+ ReverseConnect.features, over a relay that lists "operator-proof"
1043
+ in its ServerHello; the relay carries it to the operator with
1044
+ target_fingerprint set to the answering peer, and does nothing else
1045
+ with it. The peer SIGNS the challenge so the operator knows whom it
1046
+ is about to prove itself to and that the peer saw the operator's own
1047
+ fingerprint (a relay that rewrote from_fingerprint shows up here).
1048
+
1049
+ signature (by the peer's Ed25519 identity key, public_key) covers
1050
+ "wsh-reverse-challenge-v1\0" || lp(public_key) || lp(operator_fingerprint)
1051
+ || lp(nonce) || lp(session_id)
1052
+ where lp() is a 4-byte big-endian length prefix, operator_fingerprint
1053
+ is the from_fingerprint the peer received, nonce is 32 random bytes
1054
+ chosen by the peer for this request alone, and session_id is a fresh
1055
+ random string the peer chose for the bridge (it is also the
1056
+ session_id of a sealed bridge's KeyExchange). The operator verifies
1057
+ the signature, that the fingerprint of public_key is the peer it
1058
+ asked for, and that operator_fingerprint is its own; a peer accepts
1059
+ each nonce once, within seconds.
1060
+ fields:
1061
+ target_fingerprint:
1062
+ type: string
1063
+ required: true
1064
+ public_key:
1065
+ type: bytes
1066
+ required: true
1067
+ operator_fingerprint:
1068
+ type: string
1069
+ required: true
1070
+ nonce:
1071
+ type: bytes
1072
+ required: true
1073
+ session_id:
1074
+ type: string
1075
+ required: true
1076
+ signature:
1077
+ type: bytes
1078
+ required: true
1079
+
1080
+ ReverseProof:
1081
+ code: 0x59
1082
+ description: >
1083
+ Operator -> peer, answering a ReverseChallenge (wsh #117). The
1084
+ operator signs, with its Ed25519 identity key (public_key) that is
1085
+ also its login key at the relay,
1086
+ "wsh-operator-proof-v1\0" || lp(peer_public_key) || lp(public_key)
1087
+ || lp(username) || lp(nonce) || lp(session_id)
1088
+ so the signature names the peer it is for (peer_public_key is the
1089
+ raw key from the verified ReverseChallenge), the operator's own key,
1090
+ the username it claims, and the peer's nonce and session id: it
1091
+ cannot be replayed to another peer, at another time, or for another
1092
+ bridge. The peer verifies it BEFORE its accept callback runs, takes
1093
+ the operator's identity from public_key (not from the relay's
1094
+ from_fingerprint) and refuses if the two differ. The relay stamps
1095
+ from_fingerprint on what it delivers; it is advisory here. A peer
1096
+ that requires operator proof refuses an operator that does not send
1097
+ one, and from then on acts only on traffic sealed under a key
1098
+ exchange both sides signed (see KeyExchange.signature), because a
1099
+ relay can stamp any from_fingerprint on a plain message.
1100
+ fields:
1101
+ target_fingerprint:
1102
+ type: string
1103
+ required: true
1104
+ public_key:
1105
+ type: bytes
1106
+ required: true
1107
+ username:
1108
+ type: string
1109
+ required: true
1110
+ nonce:
1111
+ type: bytes
1112
+ required: true
1113
+ session_id:
1114
+ type: string
1115
+ required: true
1116
+ signature:
1117
+ type: bytes
1118
+ required: true
1119
+ from_fingerprint:
1120
+ type: string
1121
+ required: false
1122
+
1123
+ RelayForward:
1124
+ code: 0x56
1125
+ description: >
1126
+ Wraps a message the relay is forwarding between two peers over an
1127
+ established reverse connection (post-handshake channel/session/
1128
+ tool traffic -- Open, Close, McpCall, SessionData, etc; see each
1129
+ message's relay_forwardable flag for the full set). from_fingerprint
1130
+ is the ORIGINATING peer's authenticated identity, set by the relay
1131
+ server -- never trust a client-supplied value. inner is the
1132
+ complete CBOR-encoded envelope bytes of the forwarded message,
1133
+ opaque at this layer (decode it as a normal envelope once
1134
+ from_fingerprint has been checked against the receiving client's
1135
+ own set of peers it has an accepted reverse-connection with, and
1136
+ the decoded inner message's type has been checked against the
1137
+ relay_forwardable allowlist). Introduced to close two gaps:
1138
+ forwarded traffic previously carried no sender identity at all,
1139
+ and the client/server relay_forwardable allowlists had drifted
1140
+ out of sync because each was hand-maintained separately instead
1141
+ of generated from one source of truth.
1142
+ fields:
1143
+ from_fingerprint:
1144
+ type: string
1145
+ required: true
1146
+ inner:
1147
+ type: bytes
1148
+ required: true
1149
+ to_fingerprint:
1150
+ type: string
1151
+ required: false
1152
+ description: >
1153
+ The operator a PEER's RelayForward is addressed to (peer -> relay
1154
+ only). Needed only when the peer serves several operators at once
1155
+ (the relay is then configured with maxOperatorsPerPeer > 1, and
1156
+ the peer stated "relay-multi-operator" in ReverseAccept.features):
1157
+ the relay routes the forward to that operator's connection and
1158
+ re-wraps it with from_fingerprint set to the peer. Absent: the
1159
+ peer's only operator, which is what every peer wrote before this
1160
+ field existed. The relay never sets it on what it delivers (the
1161
+ receiver already knows who it is), and an operator's RelayForward
1162
+ never needs it (an operator has one bridge, to one peer). A relay
1163
+ or peer that predates the field may reject a RelayForward carrying
1164
+ it, so a peer sends it only after the relay has admitted a second
1165
+ operator -- in practice only to a relay that was configured to.
1166
+
1167
+ # ── Gateway subsystem ────────────────────────────────────────────────
1168
+ # The gateway subsystem allows clients to tunnel TCP/UDP connections and
1169
+ # DNS lookups through the server, which acts as a network proxy. Clients
1170
+ # open outbound connections or listeners, and the server relays data
1171
+ # between the client's wsh channels and the external network. All
1172
+ # gateway messages share the 0x70-0x7f opcode range and use a
1173
+ # client-assigned gateway_id or listener_id to correlate requests with
1174
+ # responses.
1175
+ gateway:
1176
+ OpenTcp:
1177
+ code: 0x70
1178
+ description: >
1179
+ Sent by the client to request a TCP connection through the gateway.
1180
+ The server resolves the host, opens a TCP socket, and replies with
1181
+ GatewayOk on success or GatewayFail on error.
1182
+ fields:
1183
+ gateway_id:
1184
+ type: u32
1185
+ required: true
1186
+ host:
1187
+ type: string
1188
+ required: true
1189
+ port:
1190
+ type: u16
1191
+ required: true
1192
+
1193
+ OpenUdp:
1194
+ code: 0x71
1195
+ description: >
1196
+ Sent by the client to request a UDP socket through the gateway.
1197
+ The server binds a local UDP socket for relaying datagrams to the
1198
+ specified host:port and replies with GatewayOk or GatewayFail.
1199
+ The flow is to ONE destination, fixed here: replies are accepted
1200
+ only from that address and port, so it is never a relay to
1201
+ arbitrary peers.
1202
+
1203
+ Payloads travel as GatewayData (one per datagram) on the control
1204
+ stream, unless the transport is WebTransport and BOTH ends listed
1205
+ the feature "gateway-datagram" (the client in Hello.features, the
1206
+ host in ServerHello.features). Then each payload is a WebTransport
1207
+ datagram instead: the whole datagram is the 4-byte big-endian
1208
+ gateway_id of the flow followed by the UDP payload (no other
1209
+ header). Such a flow is not metered by GatewayCredit and nothing
1210
+ is retransmitted; a datagram that names an unknown gateway_id, or
1211
+ is shorter than 4 bytes, is dropped. A payload that does not fit
1212
+ the transport's maxDatagramSize minus 4 is sent as GatewayData on
1213
+ the control stream instead (a host may be configured to drop it).
1214
+ GatewayOk, GatewayFail and GatewayClose always use the control
1215
+ stream.
1216
+ fields:
1217
+ gateway_id:
1218
+ type: u32
1219
+ required: true
1220
+ host:
1221
+ type: string
1222
+ required: true
1223
+ port:
1224
+ type: u16
1225
+ required: true
1226
+
1227
+ ResolveDns:
1228
+ code: 0x72
1229
+ description: >
1230
+ Sent by the client to perform a DNS lookup through the gateway.
1231
+ The server resolves the given hostname and replies with DnsResult
1232
+ containing the resolved addresses, or GatewayFail on error.
1233
+ fields:
1234
+ gateway_id:
1235
+ type: u32
1236
+ required: true
1237
+ name:
1238
+ type: string
1239
+ required: true
1240
+ record_type:
1241
+ type: string
1242
+ default: '"A"'
1243
+
1244
+ GatewayOk:
1245
+ code: 0x73
1246
+ description: >
1247
+ Sent by the server to confirm that an OpenTcp or OpenUdp
1248
+ request succeeded. The gateway_id echoes the client's
1249
+ original request. resolved_addr contains the IP address
1250
+ the server connected to.
1251
+ fields:
1252
+ gateway_id:
1253
+ type: u32
1254
+ required: true
1255
+ resolved_addr:
1256
+ type: string
1257
+ required: false
1258
+
1259
+ GatewayFail:
1260
+ code: 0x74
1261
+ description: >
1262
+ Sent by the server when a gateway request (OpenTcp, OpenUdp,
1263
+ or ResolveDns) fails. The gateway_id echoes the client's
1264
+ original request so it can match the failure. ListenRequest
1265
+ failures use ListenFail instead.
1266
+ fields:
1267
+ gateway_id:
1268
+ type: u32
1269
+ required: true
1270
+ code:
1271
+ type: u32
1272
+ required: true
1273
+ description: >
1274
+ Machine-readable failure reason. Known values:
1275
+ 1=CONNECTION_REFUSED, 2=HOST_UNREACHABLE, 3=DNS_FAILED,
1276
+ 4=POLICY_DENIED, 5=GATEWAY_DISABLED.
1277
+ message:
1278
+ type: string
1279
+ required: true
1280
+
1281
+ GatewayClose:
1282
+ code: 0x75
1283
+ description: >
1284
+ Sent by either side to close an open gateway channel. The client
1285
+ sends it to tear down a proxied connection; the server sends it
1286
+ when the remote peer disconnects or the connection is reset.
1287
+ fields:
1288
+ gateway_id:
1289
+ type: u32
1290
+ required: true
1291
+ reason:
1292
+ type: string
1293
+ required: false
1294
+
1295
+ InboundOpen:
1296
+ code: 0x76
1297
+ description: >
1298
+ Sent by the server when a new inbound connection arrives on an
1299
+ active listener. The client must reply with InboundAccept to
1300
+ accept the connection or InboundReject to refuse it.
1301
+ fields:
1302
+ listener_id:
1303
+ type: u32
1304
+ required: true
1305
+ channel_id:
1306
+ type: u32
1307
+ required: true
1308
+ peer_addr:
1309
+ type: string
1310
+ required: true
1311
+ peer_port:
1312
+ type: u16
1313
+ required: true
1314
+
1315
+ InboundAccept:
1316
+ code: 0x77
1317
+ description: >
1318
+ Sent by the client in response to InboundOpen to accept the
1319
+ inbound connection. After this, data flows over the channel
1320
+ identified by channel_id.
1321
+ fields:
1322
+ channel_id:
1323
+ type: u32
1324
+ required: true
1325
+ gateway_id:
1326
+ type: u32
1327
+ required: false
1328
+
1329
+ InboundReject:
1330
+ code: 0x78
1331
+ description: >
1332
+ Sent by the client in response to InboundOpen to refuse the
1333
+ inbound connection. The server closes the remote socket and
1334
+ releases the channel_id.
1335
+ fields:
1336
+ channel_id:
1337
+ type: u32
1338
+ required: true
1339
+ reason:
1340
+ type: string
1341
+ required: false
1342
+
1343
+ DnsResult:
1344
+ code: 0x79
1345
+ description: >
1346
+ Sent by the server in response to ResolveDns with the resolved
1347
+ addresses. Contains one or more IP address strings and an
1348
+ optional TTL from the DNS response.
1349
+ fields:
1350
+ gateway_id:
1351
+ type: u32
1352
+ required: true
1353
+ addresses:
1354
+ type: "string[]"
1355
+ required: true
1356
+ ttl:
1357
+ type: u32
1358
+ required: false
1359
+
1360
+ ListenRequest:
1361
+ code: 0x7a
1362
+ description: >
1363
+ Sent by the client to ask the server to open a listening socket
1364
+ on the given port and bind address. The server replies with
1365
+ ListenOk (including the actual bound port) or ListenFail.
1366
+ Reverse tunnels are policy-controlled by the host: off unless the
1367
+ operator enables them, bound to an address the OPERATOR chooses
1368
+ (loopback by default; bind_addr is a request the host may ignore),
1369
+ and limited to an allowed set of ports (a port below 1024 only if
1370
+ listed). Each inbound connection is announced with InboundOpen
1371
+ (peer_addr and peer_port are the remote end) and, once the client
1372
+ answers InboundAccept{gateway_id}, flows as GatewayData /
1373
+ GatewayCredit / GatewayClose on that gateway_id. A host that
1374
+ serves this lists "gateway" in ServerHello.features.
1375
+ fields:
1376
+ listener_id:
1377
+ type: u32
1378
+ required: true
1379
+ port:
1380
+ type: u16
1381
+ required: true
1382
+ bind_addr:
1383
+ type: string
1384
+ default: '"0.0.0.0"'
1385
+
1386
+ ListenOk:
1387
+ code: 0x7b
1388
+ description: >
1389
+ Sent by the server to confirm that a ListenRequest succeeded.
1390
+ The actual_port may differ from the requested port when the
1391
+ client requested port 0 (ephemeral port assignment).
1392
+ fields:
1393
+ listener_id:
1394
+ type: u32
1395
+ required: true
1396
+ actual_port:
1397
+ type: u16
1398
+ required: true
1399
+
1400
+ ListenFail:
1401
+ code: 0x7c
1402
+ description: >
1403
+ Sent by the server when a ListenRequest fails, for example
1404
+ because the port is already in use or policy denies the bind.
1405
+ fields:
1406
+ listener_id:
1407
+ type: u32
1408
+ required: true
1409
+ reason:
1410
+ type: string
1411
+ required: true
1412
+
1413
+ ListenClose:
1414
+ code: 0x7d
1415
+ description: >
1416
+ Sent by the client to stop listening on a previously opened
1417
+ listener. The server closes the bound socket and releases
1418
+ the listener_id.
1419
+ fields:
1420
+ listener_id:
1421
+ type: u32
1422
+ required: true
1423
+
1424
+ GatewayData:
1425
+ code: 0x7e
1426
+ description: >
1427
+ Bidirectional data relay for an active gateway connection. Sent by
1428
+ either side to forward payload bytes through a proxied TCP/UDP
1429
+ channel identified by gateway_id.
1430
+ fields:
1431
+ gateway_id:
1432
+ type: u32
1433
+ required: true
1434
+ data:
1435
+ type: bytes
1436
+ required: true
1437
+
1438
+ GatewayCredit:
1439
+ code: 0x7f
1440
+ description: >
1441
+ Per-connection flow control for GatewayData (feature
1442
+ "gateway-credit"). Sent by the RECEIVER of a gateway connection's
1443
+ data to tell the sender it may send `bytes` more payload bytes of
1444
+ GatewayData on gateway_id. Each direction of each connection has its
1445
+ own credit, which starts at 262144 bytes when the connection is
1446
+ established (the host's GatewayOk, or the client's InboundAccept) and
1447
+ is topped up by GatewayCredit as the receiver consumes data (the Node
1448
+ host: when the origin socket has taken it; a client: when the
1449
+ application has read it). A sender never has more than the credit
1450
+ it holds in flight; a receiver closes a connection whose peer
1451
+ overruns the credit it granted. Both peers use it only when the
1452
+ client listed "gateway-credit" in Hello.features AND the host listed
1453
+ it in ServerHello.features; otherwise neither sends it and GatewayData
1454
+ is unmetered as before (the host then bounds its buffering with
1455
+ byte caps instead and closes a connection that exceeds them).
1456
+
1457
+ The same message meters an rpc channel in virtual data mode (feature
1458
+ "rpc-virtual": the channel's CBOR sequence rides SessionData, and
1459
+ EncryptedFrame on a sealed session). Its credit has a number space of
1460
+ its own: `gateway_id` is 0x80000000 OR the rpc channel's channel_id,
1461
+ a flag no gateway id carries. Each direction starts with 262144 bytes
1462
+ and is topped up as the receiver takes the bytes in; a peer that sends
1463
+ more than it was granted has the channel closed. It is sent only on a
1464
+ connection where the host stated "rpc-virtual".
1465
+ fields:
1466
+ gateway_id:
1467
+ type: u32
1468
+ required: true
1469
+ bytes:
1470
+ type: u32
1471
+ required: true
1472
+
1473
+ OpenUnix:
1474
+ code: 0x63
1475
+ description: >
1476
+ Sent by the client to ask the host to connect to a unix-domain
1477
+ socket at `path` on the HOST's file system (OpenSSH streamlocal,
1478
+ `-L ...:/remote.sock`). Only to a host that listed "gateway-unix" in
1479
+ ServerHello.features. Answered by GatewayOk or GatewayFail; the data
1480
+ then flows as GatewayData / GatewayCredit / GatewayClose on
1481
+ gateway_id exactly as for OpenTcp. `path` is absolute; a leading "@"
1482
+ names a Linux abstract-namespace socket. The host refuses (code
1483
+ 4=POLICY_DENIED) any path its policy does not list.
1484
+ fields:
1485
+ gateway_id:
1486
+ type: u32
1487
+ required: true
1488
+ path:
1489
+ type: string
1490
+ required: true
1491
+
1492
+ OpenEndpoint:
1493
+ code: 0x64
1494
+ description: >
1495
+ Sent by the client to open the host's NAMED VIRTUAL ENDPOINT `name`:
1496
+ an in-process handler the host's embedder registered (a host with no
1497
+ file system, such as a browser tab, offers these instead of unix
1498
+ sockets). Only to a host that listed "gateway-endpoints" in
1499
+ ServerHello.features. Answered by GatewayOk or GatewayFail (4 for a
1500
+ name that is not registered); the data then flows as for OpenUnix.
1501
+ It is a separate message rather than a reserved OpenUnix path so
1502
+ that a name can never be confused with a file-system path (or an
1503
+ abstract-namespace name) and so a host's file-system policy is not
1504
+ consulted for it.
1505
+ fields:
1506
+ gateway_id:
1507
+ type: u32
1508
+ required: true
1509
+ name:
1510
+ type: string
1511
+ required: true
1512
+ target:
1513
+ type: string
1514
+ required: false
1515
+ description: >
1516
+ The execution target whose endpoint `name` is meant, as for
1517
+ Open.target (only to a host that advertises `targets`). Omitted:
1518
+ the host's own endpoints. A host with targets answers GatewayFail
1519
+ (4) for a target it does not know or does not allow the caller on.
1520
+
1521
+ ListenUnix:
1522
+ code: 0x65
1523
+ description: >
1524
+ Sent by the client to ask the host to LISTEN on a unix-domain socket
1525
+ at `path` on the host's file system and hand each connection to the
1526
+ client (OpenSSH `-R /remote.sock:...`). Only to a host that listed
1527
+ "gateway-unix". Answered by ListenOk (actual_port is 0) or ListenFail.
1528
+ Each accepted connection is announced with InboundOpen
1529
+ (peer_addr "unix" and peer_port 0, as both implementations send) and, once the client answers
1530
+ InboundAccept{gateway_id}, flows as GatewayData / GatewayCredit /
1531
+ GatewayClose on that gateway_id. ListenClose stops it. The host
1532
+ creates the socket with mode 0600 and removes it when the listener
1533
+ closes or the connection ends. An existing socket file at `path` is
1534
+ replaced only when `replace` is true AND the host's policy allows
1535
+ replacing AND nothing is accepting connections on it.
1536
+ fields:
1537
+ listener_id:
1538
+ type: u32
1539
+ required: true
1540
+ path:
1541
+ type: string
1542
+ required: true
1543
+ replace:
1544
+ type: bool
1545
+ required: false
1546
+
1547
+ # ── Guest sessions ──────────────────────────────────────────────────
1548
+ # Ephemeral guest sessions allow session owners to create short-lived
1549
+ # share links. A guest invite produces a single-use token that a
1550
+ # guest can present via GuestJoin to attach with limited permissions.
1551
+ guest:
1552
+ GuestInvite:
1553
+ code: 0x80
1554
+ description: >
1555
+ Sent by the session owner to create an ephemeral guest token.
1556
+ The server generates a short-lived token, stores it, and returns
1557
+ a GuestInvite reply with the token in the session_id field so
1558
+ the owner can share it with guests.
1559
+ fields:
1560
+ session_id:
1561
+ type: string
1562
+ required: true
1563
+ ttl:
1564
+ type: u64
1565
+ required: true
1566
+ description: "Token lifetime in seconds"
1567
+ permissions:
1568
+ type: "string[]"
1569
+ default: '["read"]'
1570
+ description: '"read", "write", or "control"'
1571
+
1572
+ GuestJoin:
1573
+ code: 0x81
1574
+ description: >
1575
+ Sent by a guest to join a session using an ephemeral token.
1576
+ On success the server replies with Presence; on failure AuthFail.
1577
+ fields:
1578
+ token:
1579
+ type: string
1580
+ required: true
1581
+ device_label:
1582
+ type: string
1583
+ required: false
1584
+
1585
+ GuestRevoke:
1586
+ code: 0x82
1587
+ description: >
1588
+ Sent by the session owner to revoke an outstanding guest token.
1589
+ fields:
1590
+ token:
1591
+ type: string
1592
+ required: true
1593
+ reason:
1594
+ type: string
1595
+ required: false
1596
+
1597
+ # ── Session sharing ─────────────────────────────────────────────────
1598
+ # Multi-attach read-only URL sharing. A session owner creates a
1599
+ # share link that allows others to attach in read-only mode.
1600
+ sharing:
1601
+ ShareSession:
1602
+ code: 0x83
1603
+ description: >
1604
+ Sent by the session owner to create a shareable read-only link.
1605
+ The server generates a share_id and returns it for URL construction.
1606
+ fields:
1607
+ session_id:
1608
+ type: string
1609
+ required: true
1610
+ mode:
1611
+ type: string
1612
+ default: '"read"'
1613
+ description: '"read" or "write"'
1614
+ ttl:
1615
+ type: u64
1616
+ required: true
1617
+ description: "Share link lifetime in seconds"
1618
+
1619
+ ShareRevoke:
1620
+ code: 0x84
1621
+ description: >
1622
+ Sent by the session owner to revoke an active share link.
1623
+ fields:
1624
+ share_id:
1625
+ type: string
1626
+ required: true
1627
+ reason:
1628
+ type: string
1629
+ required: false
1630
+
1631
+ # ── Stream compression ──────────────────────────────────────────────
1632
+ # Negotiate per-connection compression. Either side may propose
1633
+ # compression; the peer accepts or rejects. After CompressAck with
1634
+ # accepted=true, all subsequent frames are compressed.
1635
+ compression:
1636
+ CompressBegin:
1637
+ code: 0x85
1638
+ description: >
1639
+ Propose stream compression. Sent by either side before data
1640
+ transfer begins (or after renegotiation).
1641
+ fields:
1642
+ algorithm:
1643
+ type: string
1644
+ required: true
1645
+ description: '"zstd", "lz4", or "deflate"'
1646
+ level:
1647
+ type: u32
1648
+ default: 3
1649
+ description: "Compression level (algorithm-specific)"
1650
+
1651
+ CompressAck:
1652
+ code: 0x86
1653
+ description: >
1654
+ Accept or reject a compression proposal.
1655
+ fields:
1656
+ algorithm:
1657
+ type: string
1658
+ required: true
1659
+ accepted:
1660
+ type: bool
1661
+ required: true
1662
+
1663
+ # ── Rate control ────────────────────────────────────────────────────
1664
+ # Per-attachment flow control for slow consumers. When an attached
1665
+ # client falls behind, the server can drop or pause output delivery.
1666
+ ratecontrol:
1667
+ RateControl:
1668
+ code: 0x87
1669
+ description: >
1670
+ Set per-attachment rate limits. Sent by either side to configure
1671
+ the maximum data rate for the session.
1672
+ fields:
1673
+ session_id:
1674
+ type: string
1675
+ required: true
1676
+ max_bytes_per_sec:
1677
+ type: u64
1678
+ required: true
1679
+ policy:
1680
+ type: string
1681
+ default: '"pause"'
1682
+ description: '"pause" (backpressure) or "drop" (discard excess)'
1683
+
1684
+ RateWarning:
1685
+ code: 0x88
1686
+ description: >
1687
+ Sent by the server when a client is falling behind.
1688
+ fields:
1689
+ session_id:
1690
+ type: string
1691
+ required: true
1692
+ queued_bytes:
1693
+ type: u64
1694
+ required: true
1695
+ action:
1696
+ type: string
1697
+ required: true
1698
+ description: '"ok", "pausing", or "dropping"'
1699
+
1700
+ # ── Cross-session linking ────────────────────────────────────────────
1701
+ # Jump host support — link one session to another server so data
1702
+ # flows through the first server as a hop.
1703
+ linking:
1704
+ SessionLink:
1705
+ code: 0x89
1706
+ description: >
1707
+ Request a cross-session link (jump host). The server opens a
1708
+ new wsh connection to target_host and bridges the two sessions.
1709
+ fields:
1710
+ source_session:
1711
+ type: string
1712
+ required: true
1713
+ target_host:
1714
+ type: string
1715
+ required: true
1716
+ target_port:
1717
+ type: u16
1718
+ required: true
1719
+ target_user:
1720
+ type: string
1721
+ required: false
1722
+
1723
+ SessionUnlink:
1724
+ code: 0x8a
1725
+ description: >
1726
+ Tear down a cross-session link.
1727
+ fields:
1728
+ link_id:
1729
+ type: string
1730
+ required: true
1731
+ reason:
1732
+ type: string
1733
+ required: false
1734
+
1735
+ # ── AI co-pilot ─────────────────────────────────────────────────────
1736
+ # Read-only AI observer mode. An AI model attaches to a session,
1737
+ # observes terminal output, and can offer suggestions without
1738
+ # directly controlling the session.
1739
+ copilot:
1740
+ CopilotAttach:
1741
+ code: 0x8b
1742
+ description: >
1743
+ Sent by an AI agent to attach as a read-only co-pilot observer.
1744
+ fields:
1745
+ session_id:
1746
+ type: string
1747
+ required: true
1748
+ model:
1749
+ type: string
1750
+ required: true
1751
+ description: "Model identifier (e.g. 'claude-sonnet', 'gpt-4')"
1752
+ context_window:
1753
+ type: u64
1754
+ required: false
1755
+ description: "Model context window size in tokens"
1756
+
1757
+ CopilotSuggest:
1758
+ code: 0x8c
1759
+ description: >
1760
+ Sent by the co-pilot to offer a suggestion to the session user.
1761
+ fields:
1762
+ session_id:
1763
+ type: string
1764
+ required: true
1765
+ suggestion:
1766
+ type: string
1767
+ required: true
1768
+ confidence:
1769
+ type: f64
1770
+ required: false
1771
+ description: "Confidence score 0.0-1.0"
1772
+
1773
+ CopilotDetach:
1774
+ code: 0x8d
1775
+ description: >
1776
+ Sent by either side to end the co-pilot attachment.
1777
+ fields:
1778
+ session_id:
1779
+ type: string
1780
+ required: true
1781
+ reason:
1782
+ type: string
1783
+ required: false
1784
+
1785
+ # ── E2E encryption (EXPERIMENTAL) ─────────────────────────────────────
1786
+ # Inner encryption layer intended for end-to-end confidentiality: after
1787
+ # key exchange, session data is protected so the server cannot read
1788
+ # session content. Status per side of the wire:
1789
+ # WshClient.initiateE2E() performs a real X25519 ECDH exchange
1790
+ # (optionally hybrid with ML-KEM-768, see below) and derives an
1791
+ # AES-256-GCM key (src/client.mjs); as of this JS library's
1792
+ # EncryptedFrame support (wsh #19), that key is used to seal/open
1793
+ # virtual-mode session data (discrete SessionData control messages
1794
+ # swapped 1:1 for EncryptedFrame) via WshSession.enableE2E()
1795
+ # (src/session.mjs, src/e2e-frame.mjs). As of wsh #22 (PR 1 of a
1796
+ # 3-PR rollout), the same key/enableE2E() call also covers
1797
+ # stream-mode sessions (raw byte streams, no message boundaries):
1798
+ # sealed chunks are framed *inline in the raw stream itself* --
1799
+ # [4-byte big-endian length][12-byte nonce][ciphertext + 16-byte GCM
1800
+ # tag] -- reusing the exact same sealFrame/openFrame primitives and
1801
+ # nonce scheme as EncryptedFrame, just without a CBOR envelope. This
1802
+ # inline chunk framing is invisible to this control-message spec: it
1803
+ # lives entirely inside the byte stream a session's data plane already
1804
+ # carries, so it introduces no new message type here (see
1805
+ # src/stream-frame.mjs for the framing/reassembly implementation).
1806
+ # The Rust client (clawser's wsh-client crate) does have KeyExchange/
1807
+ # initiate_e2e support, but does not yet construct or consume
1808
+ # EncryptedFrame or stream-mode chunk framing -- that AEAD sealing is
1809
+ # tracked as a separate follow-up in that repo (wsh #22's PR 2/PR 3).
1810
+ # The Rust server only relays both message types (and raw stream
1811
+ # bytes) opaquely between session participants (correct for true E2E,
1812
+ # but doesn't imply either side actually encrypts). Do not rely on
1813
+ # this for confidentiality against a peer that hasn't actually called
1814
+ # enableE2E()/opened an EncryptedFrame-sealing (or stream chunk
1815
+ # framing) equivalent.
1816
+ e2e:
1817
+ KeyExchange:
1818
+ code: 0x8e
1819
+ description: >
1820
+ Key exchange for establishing a shared secret, X25519 or hybrid
1821
+ X25519+ML-KEM-768. See the e2e section note above for which
1822
+ peers currently wire the derived secret to actual encryption.
1823
+
1824
+ Classical mode ("X25519"): both sides send only public_key
1825
+ (their ephemeral X25519 public key); the shared secret is
1826
+ derived via ECDH directly.
1827
+
1828
+ Hybrid mode ("X25519+ML-KEM-768"): round 1 is the same as
1829
+ classical, plus both sides also send kem_public_key (a fresh
1830
+ ML-KEM-768 public key). After round 1, each side deterministically
1831
+ derives the same "encapsulator"/"decapsulator" role assignment by
1832
+ comparing the two exchanged X25519 public_key values byte-lexico-
1833
+ graphically (the lower one is the encapsulator) -- this needs no
1834
+ extra round trip since both sides already have both values. The
1835
+ encapsulator then encapsulates against the decapsulator's
1836
+ kem_public_key and sends a second KeyExchange carrying only
1837
+ kem_ciphertext (no public_key/kem_public_key); the decapsulator
1838
+ decapsulates it. Both sides combine the X25519 ECDH output and
1839
+ the ML-KEM-768 shared secret via HKDF-SHA256 into the final
1840
+ AES-256-GCM key. A peer that doesn't echo kem_public_key back in
1841
+ its own round-1 message doesn't support hybrid mode -- fall back
1842
+ to classical X25519-only rather than failing the exchange
1843
+ (algorithm agility, not a hard cutover).
1844
+ fields:
1845
+ algorithm:
1846
+ type: string
1847
+ required: true
1848
+ description: '"X25519" or "X25519+ML-KEM-768"'
1849
+ public_key:
1850
+ type: bytes
1851
+ required: false
1852
+ description: "Ephemeral X25519 public key. Omitted only on the hybrid round-2 (kem_ciphertext-only) message."
1853
+ session_id:
1854
+ type: string
1855
+ required: true
1856
+ kem_public_key:
1857
+ type: bytes
1858
+ required: false
1859
+ description: "Hybrid mode round 1 only: a fresh ML-KEM-768 public key (1184 bytes)."
1860
+ kem_ciphertext:
1861
+ type: bytes
1862
+ required: false
1863
+ description: "Hybrid mode round 2 only, encapsulator -> decapsulator: the ML-KEM-768 ciphertext (1088 bytes)."
1864
+ signature:
1865
+ type: bytes
1866
+ required: false
1867
+ description: >
1868
+ Round 1 only, optional: an Ed25519 signature by the sender's
1869
+ long-term identity key, which authenticates the sender's half of
1870
+ an otherwise unauthenticated exchange. It covers the label
1871
+ "wsh-e2e-keyexchange-v1", the session_id, the algorithm, and both
1872
+ sides' ephemeral X25519 public keys (initiator's first, then
1873
+ responder's), each length-prefixed -- so a relay cannot substitute
1874
+ either key without the signer's key. A reverse host signs its
1875
+ reply (it is the responder); the initiating operator verifies it
1876
+ against the host key it connected to (WshClient.initiateE2E
1877
+ { verifyPeer }). A peer that does not sign is simply
1878
+ unauthenticated, as before; a recipient that requires it rejects
1879
+ the exchange. Peers older than this field ignore it (JS) or may
1880
+ reject a KeyExchange carrying it (an older Rust build), so a host
1881
+ signs by default and offers e2e.sign: false for such a relay.
1882
+
1883
+ The INITIATOR may sign its round-1 message too (wsh #117), so
1884
+ that both halves are authenticated. Its signature is over the
1885
+ label "wsh-e2e-keyexchange-init-v1\0" (a different label, so it
1886
+ can never be taken for a responder signature), the session_id,
1887
+ the algorithm, its own ephemeral X25519 key and the responder's
1888
+ raw identity key, each length-prefixed -- the responder's
1889
+ reply, signed as above, then covers both ephemeral keys. The
1890
+ responder verifies it against the operator key it already
1891
+ proved in a ReverseProof (a host that states "e2e-sealed" in
1892
+ ReverseAccept.features does), and a host that requires operator
1893
+ proof refuses an unsigned or badly signed initiator half. An
1894
+ initiator signs only after the host stated "e2e-sealed": an
1895
+ older host would ignore the signature and a Rust one may reject
1896
+ it.
1897
+
1898
+ "e2e-sealed" also means the bridge itself can be sealed: a
1899
+ KeyExchange whose session_id is the ReverseChallenge.session_id
1900
+ of the bridge, sent right after ReverseAccept, establishes a key
1901
+ for the whole bridge. From then on every message that would
1902
+ cross it (the relay forwardable list, KeyExchange aside) travels
1903
+ as an EncryptedFrame with channel_id 0 and that session_id,
1904
+ sealed with the same AES-256-GCM framing as session data
1905
+ (counters, role tags, session_id as AAD), the CBOR of the
1906
+ message as plaintext. A peer or operator that sealed the bridge
1907
+ drops every plaintext message it receives over it. Nothing that
1908
+ names a command, a path or a session is sent before the key
1909
+ exists.
1910
+
1911
+ EncryptedFrame:
1912
+ code: 0x8f
1913
+ description: >
1914
+ An encrypted payload carrying virtual-mode session data, once
1915
+ KeyExchange's derived secret is wired to real encryption via
1916
+ WshSession.enableE2E() (see the e2e section note above).
1917
+ Virtual-mode only -- stream-mode sessions never send this
1918
+ message type; their sealed data instead travels as inline
1919
+ length-prefixed chunks inside the raw byte stream itself (see
1920
+ the e2e section note above and src/stream-frame.mjs), since a
1921
+ stream-mode session has no control-message channel to carry a
1922
+ CBOR envelope like this one through. Sent
1923
+ using AES-256-GCM AEAD, matching the cipher
1924
+ WshClient.initiateE2E() derives a key for (src/client.mjs) --
1925
+ picked over the ChaCha20-Poly1305 this field previously
1926
+ described because it's natively supported by SubtleCrypto in
1927
+ every shipping browser, matching this library's zero-runtime-
1928
+ dependency, Web-Crypto-native design; ChaCha20-Poly1305 has no
1929
+ native browser support and would require bundling a JS
1930
+ implementation. The nonce is 8 bytes of big-endian monotonic
1931
+ send counter followed by a 4-byte fixed per-sender role tag
1932
+ (see src/e2e-frame.mjs); session_id is bound as AEAD additional
1933
+ authenticated data so a relay can't splice ciphertext across
1934
+ sessions.
1935
+ fields:
1936
+ channel_id:
1937
+ type: u32
1938
+ required: true
1939
+ description: "Which channel (session) this frame belongs to -- same routing role as SessionData.channel_id."
1940
+ nonce:
1941
+ type: bytes
1942
+ required: true
1943
+ description: "12-byte AEAD nonce"
1944
+ ciphertext:
1945
+ type: bytes
1946
+ required: true
1947
+ session_id:
1948
+ type: string
1949
+ required: true
1950
+
1951
+ # ── Predictive local echo ────────────────────────────────────────────
1952
+ # Mosh-style local echo. The client speculatively renders keystrokes
1953
+ # and the server confirms via EchoAck. EchoState carries cursor
1954
+ # position so the client can reconcile predictions.
1955
+ echo:
1956
+ EchoAck:
1957
+ code: 0x90
1958
+ description: >
1959
+ Sent by the server to confirm that input up to echo_seq has
1960
+ been processed and rendered. The client can retire predictions
1961
+ up to this sequence number.
1962
+ fields:
1963
+ channel_id:
1964
+ type: u32
1965
+ required: true
1966
+ echo_seq:
1967
+ type: u64
1968
+ required: true
1969
+
1970
+ EchoState:
1971
+ code: 0x91
1972
+ description: >
1973
+ Sent by the server with current terminal cursor state so the
1974
+ client can reconcile local predictions with actual state.
1975
+ fields:
1976
+ channel_id:
1977
+ type: u32
1978
+ required: true
1979
+ echo_seq:
1980
+ type: u64
1981
+ required: true
1982
+ cursor_x:
1983
+ type: u16
1984
+ required: true
1985
+ cursor_y:
1986
+ type: u16
1987
+ required: true
1988
+ pending:
1989
+ type: u32
1990
+ required: true
1991
+ description: "Number of unacknowledged input bytes on server"
1992
+
1993
+ # ── Terminal diff sync ───────────────────────────────────────────────
1994
+ # True mosh replacement — instead of streaming raw bytes, the server
1995
+ # maintains a virtual terminal framebuffer and sends diffs. The
1996
+ # client applies patches to its local copy.
1997
+ termsync:
1998
+ TermSync:
1999
+ code: 0x92
2000
+ description: >
2001
+ Full terminal state synchronization point. The server sends
2002
+ a state_hash so the client can verify consistency. If the
2003
+ client's hash differs, it requests a full resync.
2004
+ fields:
2005
+ channel_id:
2006
+ type: u32
2007
+ required: true
2008
+ frame_seq:
2009
+ type: u64
2010
+ required: true
2011
+ state_hash:
2012
+ type: bytes
2013
+ required: true
2014
+ description: "SHA-256 of the current framebuffer state"
2015
+
2016
+ TermDiff:
2017
+ code: 0x93
2018
+ description: >
2019
+ Incremental screen diff. Contains a binary patch that transforms
2020
+ the framebuffer from base_seq state to frame_seq state.
2021
+ fields:
2022
+ channel_id:
2023
+ type: u32
2024
+ required: true
2025
+ frame_seq:
2026
+ type: u64
2027
+ required: true
2028
+ base_seq:
2029
+ type: u64
2030
+ required: true
2031
+ patch:
2032
+ type: bytes
2033
+ required: true
2034
+ description: "Binary diff patch (run-length encoded cell changes)"
2035
+
2036
+ # ── Horizontal scaling (EXPERIMENTAL, incomplete) ────────────────────
2037
+ # Multi-node cluster support. Nodes announce themselves and can
2038
+ # redirect clients to less-loaded peers. Stateless session tokens
2039
+ # (HMAC-based) allow any node to validate without shared state.
2040
+ # Currently: the Rust server records NodeAnnounce into a registry
2041
+ # (garbage-collected on a timer) but never reads it back for any
2042
+ # routing decision, and nothing anywhere ever constructs a
2043
+ # NodeRedirect -- there is no load-aware routing today, only inert
2044
+ # bookkeeping. No JS client support exists at all.
2045
+ scaling:
2046
+ NodeAnnounce:
2047
+ code: 0x94
2048
+ description: >
2049
+ Sent between cluster nodes to announce presence and load.
2050
+ Used for load-aware routing decisions.
2051
+ fields:
2052
+ node_id:
2053
+ type: string
2054
+ required: true
2055
+ endpoint:
2056
+ type: string
2057
+ required: true
2058
+ description: "WebSocket/WebTransport URL for this node"
2059
+ load:
2060
+ type: f64
2061
+ required: true
2062
+ description: "Current load factor 0.0-1.0"
2063
+ capacity:
2064
+ type: u32
2065
+ required: true
2066
+ description: "Max concurrent sessions"
2067
+
2068
+ NodeRedirect:
2069
+ code: 0x95
2070
+ description: >
2071
+ Sent by a node to redirect a client to a different node.
2072
+ The client should reconnect to target_endpoint and present
2073
+ its session token (which is valid across all cluster nodes).
2074
+ fields:
2075
+ target_node:
2076
+ type: string
2077
+ required: true
2078
+ target_endpoint:
2079
+ type: string
2080
+ required: true
2081
+ session_id:
2082
+ type: string
2083
+ required: true
2084
+ reason:
2085
+ type: string
2086
+ required: false
2087
+
2088
+ # ── Cross-principal session sharing ──────────────────────────────────
2089
+ # Allow session owners to grant access to other authenticated users
2090
+ # (principals). This enables collaborative multi-user sessions.
2091
+ principals:
2092
+ SessionGrant:
2093
+ code: 0x96
2094
+ description: >
2095
+ Grant another principal access to a session. The principal
2096
+ must be an authenticated user on the server.
2097
+ fields:
2098
+ session_id:
2099
+ type: string
2100
+ required: true
2101
+ principal:
2102
+ type: string
2103
+ required: true
2104
+ description: "Username or fingerprint of the grantee"
2105
+ permissions:
2106
+ type: "string[]"
2107
+ default: '["read"]'
2108
+ description: '"read", "write", or "control"'
2109
+
2110
+ SessionRevoke:
2111
+ code: 0x97
2112
+ description: >
2113
+ Revoke a previously granted session access.
2114
+ fields:
2115
+ session_id:
2116
+ type: string
2117
+ required: true
2118
+ principal:
2119
+ type: string
2120
+ required: true
2121
+ reason:
2122
+ type: string
2123
+ required: false
2124
+
2125
+ # ── Structured file channel ──────────────────────────────────────────
2126
+ # SFTP replacement — structured file operations over wsh channels.
2127
+ # Supports stat, list, read, write, mkdir, remove, rename.
2128
+ filechannel:
2129
+ FileOp:
2130
+ code: 0x98
2131
+ description: >
2132
+ Request a file operation (stat, list, read, write, mkdir,
2133
+ remove, rename).
2134
+ fields:
2135
+ channel_id:
2136
+ type: u32
2137
+ required: true
2138
+ op:
2139
+ type: string
2140
+ required: true
2141
+ description: '"stat", "list", "read", "write", "mkdir", "remove", "rename"'
2142
+ path:
2143
+ type: string
2144
+ required: true
2145
+ offset:
2146
+ type: u64
2147
+ required: false
2148
+ description: "Byte offset for read/write"
2149
+ length:
2150
+ type: u64
2151
+ required: false
2152
+ description: "Byte count for read"
2153
+ target:
2154
+ type: string
2155
+ required: false
2156
+ description: >
2157
+ The execution target whose files this operation is about, as for
2158
+ Open.target (only to a host that advertises `targets`). Omitted:
2159
+ the host's own default files.
2160
+
2161
+ FileResult:
2162
+ code: 0x99
2163
+ description: >
2164
+ Result of a file operation. Success with optional metadata,
2165
+ or failure with error message.
2166
+ fields:
2167
+ channel_id:
2168
+ type: u32
2169
+ required: true
2170
+ success:
2171
+ type: bool
2172
+ required: true
2173
+ metadata:
2174
+ type: json
2175
+ default: "{}"
2176
+ description: >
2177
+ Untyped result payload for ops whose shape genuinely varies by
2178
+ op (stat's single-entry metadata is not currently typed either
2179
+ -- see wsh #59's type:json audit in the PR description for why
2180
+ that one is still open rather than fixed here). For "list",
2181
+ use `entries` instead of this field.
2182
+ entries:
2183
+ type: "FileEntry[]"
2184
+ default: "[]"
2185
+ description: >
2186
+ wsh #59: directory entries for a "list" op, generated into both
2187
+ languages so a symlink can't be reported as a plain file in one
2188
+ implementation and not the other. Previously this arrived only
2189
+ in `metadata` (untyped json), and only in the JS SDK's private
2190
+ `ls -la`-over-exec parsing -- never over this message at all.
2191
+ error_message:
2192
+ type: string
2193
+ required: false
2194
+
2195
+ FileChunk:
2196
+ code: 0x9a
2197
+ description: >
2198
+ Data chunk for file read/write transfers -- the single wire scheme
2199
+ for moving file bytes, replacing the old raw-stream length-prefixed
2200
+ header (WshClient.upload/download) and WshFileTransfer's ad-hoc
2201
+ Open.path/Open.size fields. Sent as an ordinary control-channel
2202
+ message over a 'file'-kind channel (Open/OpenOk first), so it works
2203
+ identically whether the channel's data_mode is stream or virtual --
2204
+ it never depends on a real second multiplexed stream existing.
2205
+ total_size lets a receiver detect a truncated transfer: for a
2206
+ well-formed transfer, the chunk with is_final=true always has
2207
+ offset + len(data) == total_size, and if the channel closes before
2208
+ such a chunk arrives, the transfer is known-truncated rather than
2209
+ silently short.
2210
+ fields:
2211
+ channel_id:
2212
+ type: u32
2213
+ required: true
2214
+ offset:
2215
+ type: u64
2216
+ required: true
2217
+ data:
2218
+ type: bytes
2219
+ required: true
2220
+ is_final:
2221
+ type: bool
2222
+ required: true
2223
+ description: "True if this is the last chunk"
2224
+ total_size:
2225
+ type: u64
2226
+ required: true
2227
+ description: "Total transfer size in bytes, constant across every chunk in the sequence"
2228
+
2229
+ # ── Authorized-key management ─────────────────────────────────────────
2230
+ # wsh #59: `wsh copy-id` previously installed a key by building and
2231
+ # running a remote shell command (crates/wsh-cli/src/commands/copy_id.rs)
2232
+ # -- CLI-only, and a quoting question nobody wanted two answers to. A
2233
+ # connection that has already completed AUTH_OK can already do anything
2234
+ # an equivalent `exec`/FileOp write could do to this same file (this
2235
+ # server grants a fully-authenticated connection unsandboxed filesystem
2236
+ # and shell access -- see FileOp/Open<ChannelKind::Exec> -- so this
2237
+ # message adds no new privilege boundary); it only removes the
2238
+ # shell-quoting hazard and makes key installation reachable from
2239
+ # implementations with no shell channel to build a command string for,
2240
+ # starting with the browser SDK.
2241
+ keys:
2242
+ AuthorizedKeyAdd:
2243
+ code: 0x9f
2244
+ description: >
2245
+ Install a public key into the authenticated user's
2246
+ ~/.wsh/authorized_keys, idempotently (a key already present is
2247
+ left as-is, reported via AuthorizedKeyResult.added = false).
2248
+ fields:
2249
+ public_key:
2250
+ type: bytes
2251
+ required: true
2252
+ description: "Raw 32-byte Ed25519 public key (same encoding as Auth.public_key / PeerInfo.public_key)"
2253
+ comment:
2254
+ type: string
2255
+ required: false
2256
+ description: 'Trailing comment for the authorized_keys line, e.g. "user@host"'
2257
+
2258
+ AuthorizedKeyResult:
2259
+ code: 0xa0
2260
+ description: >
2261
+ Result of an AuthorizedKeyAdd request.
2262
+ fields:
2263
+ success:
2264
+ type: bool
2265
+ required: true
2266
+ added:
2267
+ type: bool
2268
+ default: false
2269
+ description: "True if the key was newly appended; false if it was already present"
2270
+ error_message:
2271
+ type: string
2272
+ required: false
2273
+
2274
+ # ── Policy engine ────────────────────────────────────────────────────
2275
+ # OPA-like enterprise policy enforcement. Actions are evaluated
2276
+ # against policy rules before execution. Policies can be updated
2277
+ # at runtime without server restart.
2278
+ policy:
2279
+ PolicyEval:
2280
+ code: 0x9b
2281
+ description: >
2282
+ Request policy evaluation for an action. The server checks
2283
+ the action against loaded policy rules and returns a decision.
2284
+ fields:
2285
+ request_id:
2286
+ type: string
2287
+ required: true
2288
+ action:
2289
+ type: string
2290
+ required: true
2291
+ description: '"open_pty", "exec", "file_write", "gateway", etc.'
2292
+ principal:
2293
+ type: string
2294
+ required: true
2295
+ context:
2296
+ type: json
2297
+ default: "{}"
2298
+ description: "Additional context (IP, time, session metadata)"
2299
+
2300
+ PolicyResult:
2301
+ code: 0x9c
2302
+ description: >
2303
+ Policy evaluation result.
2304
+ fields:
2305
+ request_id:
2306
+ type: string
2307
+ required: true
2308
+ allowed:
2309
+ type: bool
2310
+ required: true
2311
+ reason:
2312
+ type: string
2313
+ required: false
2314
+
2315
+ PolicyUpdate:
2316
+ code: 0x9d
2317
+ description: >
2318
+ Push a policy update. The server reloads policy rules from
2319
+ the provided document.
2320
+ fields:
2321
+ policy_id:
2322
+ type: string
2323
+ required: true
2324
+ rules:
2325
+ type: json
2326
+ required: true
2327
+ description: "Policy document (JSON rule set)"
2328
+ version:
2329
+ type: u64
2330
+ required: true
2331
+
2332
+ # ── Terminal frontend ────────────────────────────────────────────────
2333
+ # Negotiate terminal frontend configuration. Allows the client to
2334
+ # specify which terminal emulator to use (ghostty-web, xterm.js, etc.)
2335
+ # and pass frontend-specific options.
2336
+ terminal:
2337
+ TerminalConfig:
2338
+ code: 0x9e
2339
+ description: >
2340
+ Sent by the client to configure the terminal frontend for a
2341
+ channel. The server may use this to adjust PTY behavior
2342
+ (e.g., TERM environment variable, color depth).
2343
+ fields:
2344
+ channel_id:
2345
+ type: u32
2346
+ required: true
2347
+ frontend:
2348
+ type: string
2349
+ required: true
2350
+ description: '"ghostty-web", "xterm.js", "hterm", or custom'
2351
+ options:
2352
+ type: json
2353
+ default: "{}"
2354
+ description: "Frontend-specific options (font, theme, keybindings)"
2355
+
2356
+ # ── Operator-side shared folders (#159) ──────────────────────────────
2357
+ # A host with no disk of its own (a browser tab) sometimes needs files that
2358
+ # live on the OPERATOR's machine (`docker run -v $PWD:/app` reached through
2359
+ # `wsh -L sock:endpoint=docker`). The operator's client OFFERS named
2360
+ # directories (`wsh --share NAME=/abs/dir[:ro|:rw]`); the host asks for file
2361
+ # operations on them, one bounded request at a time, and the client answers.
2362
+ #
2363
+ # Negotiation: a host that can use shares lists the feature "shares" in
2364
+ # ServerHello.features. A client that has shares to offer and sees the
2365
+ # feature sends ONE ShareOffer after authentication. A host that does not
2366
+ # list the feature never receives a ShareOffer; a client without shares
2367
+ # never sends one, so a released peer is unaffected either way.
2368
+ #
2369
+ # Direction: unlike every other request in wsh, these are HOST-initiated: the
2370
+ # host sends ShareRequest, the client answers each with exactly one
2371
+ # ShareReply carrying the same request_id. The client is the file server and
2372
+ # treats every request as untrusted input (it serves only what its operator
2373
+ # named on the command line; nothing a host sends can add or widen a share).
2374
+ #
2375
+ # Paths: relative to the share root, "/"-separated; a leading "/" means the
2376
+ # root; empty and "." components are ignored; ".." is refused (EINVAL); at
2377
+ # most 4096 bytes and 128 components, each at most 255 bytes. A symlink is
2378
+ # never followed: every operation sees a symlink as a symlink (type
2379
+ # "symlink"), and a symlink in the middle of a path is ELOOP. Sockets,
2380
+ # devices and FIFOs do not exist for the host (ENOENT, and they are left out
2381
+ # of listings).
2382
+ #
2383
+ # Attr (a map): {type: "file" | "directory" | "symlink", size, mode
2384
+ # (permission bits, 0o777 at most), mtime_ms, atime_ms, ctime_ms, nlink, ino}.
2385
+ # Errors: ShareReply.ok=false with `errno` one of ENOENT, EEXIST, ENOTDIR,
2386
+ # EISDIR, ENOTEMPTY, EACCES, EPERM, EROFS, EINVAL, EBADF, ELOOP,
2387
+ # ENAMETOOLONG, ENOSPC, EMFILE, EBUSY, EAGAIN, EXDEV, EFBIG, ENOTSUP, ESTALE,
2388
+ # EIO, and a short `message` for a person (never a path outside the share).
2389
+ #
2390
+ # Flow control: ShareOffer.max_inflight is the number of requests the host
2391
+ # may have unanswered at once (more get EAGAIN); ShareOffer.max_bytes is the
2392
+ # most data one request may carry or ask for (a bigger `length` is clamped, a
2393
+ # bigger `data` is EINVAL). A ShareReply is at most max_bytes of
2394
+ # data plus a bounded listing. This is the same bounded-window idea as
2395
+ # GatewayCredit, expressed in requests because each reply is the answer to
2396
+ # one of them. Everything rides the connection's normal framing, so a sealed
2397
+ # session (EncryptedFrame) protects it with no extra crypto.
2398
+ shares:
2399
+ ShareOffer:
2400
+ code: 0xa8
2401
+ description: >
2402
+ Sent once by the client after authentication to a host that listed
2403
+ "shares", naming the directories it serves. `writable` lists the names
2404
+ among `shares` that accept writes (everything else is read-only).
2405
+ The host may use any subset; it never learns more than the names.
2406
+ fields:
2407
+ shares:
2408
+ type: "string[]"
2409
+ required: true
2410
+ description: 'Share names ([A-Za-z0-9][A-Za-z0-9._-]{0,63}); at most 16'
2411
+ writable:
2412
+ type: "string[]"
2413
+ default: "[]"
2414
+ max_inflight:
2415
+ type: u32
2416
+ required: true
2417
+ description: "Requests the host may have unanswered at once"
2418
+ max_bytes:
2419
+ type: u32
2420
+ required: true
2421
+ description: "Largest data payload of one request or reply"
2422
+ paths:
2423
+ type: "string[]"
2424
+ required: false
2425
+ description: >
2426
+ Optional, parallel to `shares`: each share's root directory on the operator's machine, as the operator
2427
+ typed it, made absolute and lexically tidied (no "//", "." or trailing "/"). ADVISORY: the host cannot
2428
+ verify it and the client still serves only the directory it opened. A client that does not want to reveal
2429
+ paths omits the field (`wsh --share-hide-path`). A host uses it only when it is an array as long as
2430
+ `shares` and the entry is an absolute string of at most 4096 bytes without NUL; anything else is
2431
+ ignored, never an error. Older peers that do not know the field keep working.
2432
+
2433
+ ShareRequest:
2434
+ code: 0xa9
2435
+ description: >
2436
+ Sent by the HOST to ask the client for one file operation on a share.
2437
+ `op` selects the operation; the fields it uses:
2438
+ stat, lstat (path) -> attr;
2439
+ readdir (path, cursor?, length? = most entries) -> entries (each an
2440
+ Attr plus `name`, sorted by name) and `cursor` when more remain: one
2441
+ round trip lists a directory WITH attributes;
2442
+ readlink (path) -> target;
2443
+ open (path, flags, length?) -> handle, attr, and, when the file is
2444
+ no bigger than `length` (clamped to max_bytes) and opened for
2445
+ reading ONLY, its whole content in `data` with eof=true and NO
2446
+ handle (there is nothing left to read or close: a small file costs
2447
+ one round trip); flags are any of
2448
+ "read" "write" "create" "excl" "trunc" (a write is at an explicit
2449
+ offset: there is no append mode); "create", "write" and "trunc"
2450
+ need a writable share; `mode` applies to a created file;
2451
+ create (path, mode?) -> handle, attr: a NEW file (EEXIST if the name
2452
+ is taken, even by a symlink), opened for writing; use open with
2453
+ "create" to open-or-create;
2454
+ read (handle, offset, length) -> data, eof;
2455
+ write (handle, offset, data) -> written;
2456
+ close (handle);
2457
+ mkdir (path, mode?) -> attr; unlink (path); rmdir (path);
2458
+ rename (path, to);
2459
+ setattr (path, or handle, and attr with any of mode, atime_ms,
2460
+ mtime_ms, size) -> attr: a new size is a truncate.
2461
+ A host should close what it opens; the client bounds the open handles
2462
+ (EMFILE) and drops them all when the connection ends.
2463
+ fields:
2464
+ request_id:
2465
+ type: u32
2466
+ required: true
2467
+ share:
2468
+ type: string
2469
+ required: true
2470
+ op:
2471
+ type: string
2472
+ required: true
2473
+ path:
2474
+ type: string
2475
+ required: false
2476
+ to:
2477
+ type: string
2478
+ required: false
2479
+ handle:
2480
+ type: u32
2481
+ required: false
2482
+ offset:
2483
+ type: u64
2484
+ required: false
2485
+ length:
2486
+ type: u32
2487
+ required: false
2488
+ mode:
2489
+ type: u32
2490
+ required: false
2491
+ flags:
2492
+ type: "string[]"
2493
+ default: "[]"
2494
+ cursor:
2495
+ type: string
2496
+ required: false
2497
+ attr:
2498
+ type: json
2499
+ default: "{}"
2500
+ description: "setattr: the changes ({mode, atime_ms, mtime_ms, size})"
2501
+ data:
2502
+ type: bytes
2503
+ required: false
2504
+
2505
+ ShareReply:
2506
+ code: 0xaa
2507
+ description: >
2508
+ The client's answer to one ShareRequest. ok=false carries `errno` (and
2509
+ a `message`); ok=true carries what the operation returns (see
2510
+ ShareRequest). Only the fields an operation returns are present.
2511
+ fields:
2512
+ request_id:
2513
+ type: u32
2514
+ required: true
2515
+ ok:
2516
+ type: bool
2517
+ required: true
2518
+ errno:
2519
+ type: string
2520
+ required: false
2521
+ message:
2522
+ type: string
2523
+ required: false
2524
+ attr:
2525
+ type: json
2526
+ default: "{}"
2527
+ entries:
2528
+ type: json
2529
+ default: "[]"
2530
+ cursor:
2531
+ type: string
2532
+ required: false
2533
+ handle:
2534
+ type: u32
2535
+ required: false
2536
+ data:
2537
+ type: bytes
2538
+ required: false
2539
+ eof:
2540
+ type: bool
2541
+ required: false
2542
+ written:
2543
+ type: u32
2544
+ required: false
2545
+ target:
2546
+ type: string
2547
+ required: false
2548
+
2549
+ # ── Execution targets (wsh #121) ─────────────────────────────────────
2550
+ # A host that fronts several execution targets (containers, VMs, workers,
2551
+ # sandboxes) says so with the `targets` feature in ServerHello.features.
2552
+ # Open, FileOp and OpenEndpoint then take an optional `target`, and a client
2553
+ # may ask what it can reach. Nothing is on by default: a host without the
2554
+ # feature knows no targets, and a client must not send `target` to it (an
2555
+ # older host rejects the unknown field; one that knows the field and has no
2556
+ # targets answers OpenFail, FileResult(success=false) or GatewayFail).
2557
+ # What a key may see is the host's decision: TargetList lists the targets the
2558
+ # caller is allowed on, not every target the host has.
2559
+ targets:
2560
+ ListTargets:
2561
+ code: 0xab
2562
+ description: >
2563
+ Sent by the client to a host that listed "targets" to ask which
2564
+ execution targets it may use. Answered with TargetList.
2565
+ fields: {}
2566
+
2567
+ TargetList:
2568
+ code: 0xac
2569
+ description: >
2570
+ The host's answer to ListTargets: the targets the caller is allowed
2571
+ on (the host decides what to reveal per key), in the host's order.
2572
+ fields:
2573
+ targets:
2574
+ type: "TargetInfo[]"
2575
+ required: true
2576
+
2577
+ nested_types:
2578
+ TargetInfo:
2579
+ fields:
2580
+ name:
2581
+ type: string
2582
+ required: true
2583
+ description: "The value to put in Open.target (and FileOp.target, OpenEndpoint.target)"
2584
+ description:
2585
+ type: string
2586
+ required: false
2587
+ description: "A human line about the target (what it is); not for parsing"
2588
+ capabilities:
2589
+ type: "string[]"
2590
+ default: "[]"
2591
+ description: 'What the caller can do on it: any of "exec", "pty", "file", "endpoint" (a hint; the host decides on each request)'
2592
+
2593
+ FileEntry:
2594
+ # wsh #59: the shape of a directory entry, formalized from the JS SDK's
2595
+ # previously-private WshFileListEntry (name, size, modified, type) so
2596
+ # it is generated into both languages instead of invented once. Used
2597
+ # by FileResult.entries for a "list" op.
2598
+ fields:
2599
+ name:
2600
+ type: string
2601
+ required: true
2602
+ description: "Entry name (not a full path) within the listed directory"
2603
+ size:
2604
+ type: u64
2605
+ required: true
2606
+ description: "Size in bytes (0 for directories and most non-regular-file types)"
2607
+ modified:
2608
+ type: u64
2609
+ required: true
2610
+ description: "Last-modified time, Unix epoch seconds (UTC)"
2611
+ type:
2612
+ type: FileEntryType
2613
+ required: true
2614
+ symlink_target:
2615
+ type: string
2616
+ required: false
2617
+ description: "Present only when type == symlink: the link's target path, unresolved"
2618
+
2619
+ AttachmentInfo:
2620
+ fields:
2621
+ session_id:
2622
+ type: string
2623
+ required: true
2624
+ mode:
2625
+ type: string
2626
+ required: true
2627
+ username:
2628
+ type: string
2629
+ required: false
2630
+ channel_id:
2631
+ type: u32
2632
+ required: false
2633
+ description: >
2634
+ Only in the Presence that answers this connection's own
2635
+ Attach/Resume, on the entry describing that attachment: the
2636
+ channel id the host assigned on this connection. The replay and
2637
+ the live output follow as SessionData with this channel_id (the
2638
+ channel is always message-backed, whatever data_mode the session
2639
+ was opened with), and Exit/Close end it. Absent from roster
2640
+ broadcasts, where the entry is someone else's.
2641
+ seq:
2642
+ type: u64
2643
+ required: false
2644
+ description: >
2645
+ Alongside channel_id: the session output position (cumulative
2646
+ bytes, see Resume.last_seq) of the first byte that will be
2647
+ delivered on that channel -- the requested last_seq for Resume,
2648
+ the oldest retained byte for Attach. A client adds the length of
2649
+ each SessionData it receives to this to know its own position.
2650
+
2651
+ PeerInfo:
2652
+ fields:
2653
+ fingerprint:
2654
+ type: string
2655
+ required: true
2656
+ fingerprint_short:
2657
+ type: string
2658
+ required: true
2659
+ username:
2660
+ type: string
2661
+ required: true
2662
+ capabilities:
2663
+ type: "string[]"
2664
+ default: "[]"
2665
+ peer_type:
2666
+ type: string
2667
+ default: '"host"'
2668
+ shell_backend:
2669
+ type: string
2670
+ default: '"pty"'
2671
+ source:
2672
+ type: string
2673
+ default: '"wsh-relay"'
2674
+ supports_attach:
2675
+ type: bool
2676
+ default: false
2677
+ supports_replay:
2678
+ type: bool
2679
+ default: false
2680
+ supports_echo:
2681
+ type: bool
2682
+ default: false
2683
+ supports_term_sync:
2684
+ type: bool
2685
+ default: false
2686
+ last_seen:
2687
+ type: u64
2688
+ required: false
2689
+ public_key:
2690
+ type: bytes
2691
+ required: false
2692
+ seq:
2693
+ type: u64
2694
+ required: false
2695
+ record_signature:
2696
+ type: bytes
2697
+ required: false
2698
+
2699
+ McpToolSpec:
2700
+ fields:
2701
+ name:
2702
+ type: string
2703
+ required: true
2704
+ description:
2705
+ type: string
2706
+ required: true
2707
+ parameters:
2708
+ type: json
2709
+ default: "{}"
2710
+
2711
+ SessionSummary:
2712
+ fields:
2713
+ session_id:
2714
+ type: string
2715
+ required: true
2716
+ name:
2717
+ type: string
2718
+ required: false
2719
+ username:
2720
+ type: string
2721
+ required: true
2722
+ fingerprint_short:
2723
+ type: string
2724
+ required: true
2725
+ created_at_secs:
2726
+ type: u64
2727
+ required: true
2728
+ idle_secs:
2729
+ type: u64
2730
+ required: true
2731
+ attached_count:
2732
+ type: u32
2733
+ required: true
2734
+
2735
+ crypto:
2736
+ auth_transcript:
2737
+ algorithm: SHA-256
2738
+ formula: 'SHA-256(PROTOCOL_VERSION || "\0" || lp(username) || lp(session_id) || nonce)'
2739
+ note: "lp() is a 4-byte big-endian length prefix, applied to username and session_id since both are variable-length strings that would otherwise be ambiguous when concatenated. username binds the transcript to a specific identity so a signature can't be replayed under a different username. channelBinding can be appended but defaults to empty (no server host-identity binding exists in the protocol yet)."
2740
+ fingerprint:
2741
+ algorithm: SHA-256
2742
+ input: raw_ed25519_public_key_32_bytes
2743
+ output: hex_encoded_64_chars
2744
+ session_token:
2745
+ format: "[8B expiry_be][32B HMAC-SHA256(secret, session_id || expiry)]"
2746
+ total_bytes: 40
2747
+ key_type: Ed25519
2748
+ ssh_wire_format: '[4B len]["ssh-ed25519"][4B len][32B raw_key]'
2749
+
2750
+ transport:
2751
+ webtransport:
2752
+ description: "QUIC streams as channels. 1 bidi = control. Per channel: 1 bidi + optional uni."
2753
+ websocket:
2754
+ framing: "[1B frame_type][4B stream_id][payload]"
2755
+ frame_types:
2756
+ control: 0x01
2757
+ data: 0x02
2758
+ open_stream: 0x03
2759
+ close_stream: 0x04
2760
+ note: "Stream 0 carries length-prefixed CBOR control messages (frameEncode/FrameDecoder); other stream IDs carry raw data bytes with no extra framing. See src/transport-ws.mjs for the reference implementation."
2761
+
2762
+ relay:
2763
+ # Single source of truth for which message types a relay may forward
2764
+ # inside a RelayForward wrapper. Generated into JS (RELAY_FORWARDABLE,
2765
+ # a Set) and Rust (is_relay_forwardable(), a match) by codegen.mjs, so
2766
+ # the two implementations can no longer drift out of sync the way the
2767
+ # hand-maintained allowlists did before RelayForward existed.
2768
+ #
2769
+ # KeyExchange and EncryptedFrame are on the list so two endpoints can run
2770
+ # E2E through a bridge: the relay carries the CBOR of an EncryptedFrame as
2771
+ # opaque bytes and holds no key. KeyExchange is an UNAUTHENTICATED ephemeral
2772
+ # exchange, so it protects against a relay that only observes, not one that
2773
+ # substitutes keys; peers who need that must authenticate the derived key
2774
+ # themselves (see the README's Security model).
2775
+ forwardable: [Open, OpenOk, OpenFail, Close, Exit, Resize, Signal, SessionData, GatewayData, GatewayCredit, GatewayOk, GatewayFail, GatewayClose, McpDiscover, McpTools, McpCall, McpResult, McpCancel, ReverseAccept, ReverseReject, GuestJoin, GuestRevoke, CopilotAttach, CopilotDetach, FileOp, FileResult, FileChunk, PolicyEval, EchoAck, EchoState, TermSync, TermDiff, KeyExchange, EncryptedFrame]