@rstreamlabs/webtty 1.12.2 → 1.12.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,593 +1,32 @@
1
1
  # `@rstreamlabs/webtty`
2
2
 
3
- WebTTY is rstream's remote terminal and command-execution protocol. A server runs on the remote machine and an operator connects through the CLI or a browser. This package implements the browser client so an application can exchange terminal input/output and track process completion.
4
-
5
- Use this package when you need to connect a web application to a WebTTY server
6
- over WebSocket or WebTransport. It handles the protobuf session handshake,
7
- stdin/stdout/stderr streams, remote process completion, terminal resize events,
8
- and heartbeats.
9
-
10
- For a ready-made React terminal, use
11
- [`@rstreamlabs/react`](../react/README.md).
12
-
13
- ## Install
3
+ WebTTY connects an authorized client to a terminal or command on a
4
+ remote machine. This package handles session input, output, resizing
5
+ and completion over WebSocket or WebTransport. An application backend
6
+ decides who can reach each server and supplies a scoped connection.
14
7
 
15
8
  ```sh
16
9
  npm install @rstreamlabs/webtty
17
10
  ```
18
11
 
19
- ## Connect to a WebTTY Session
20
-
21
- ```ts
22
- import { WebTTY } from "@rstreamlabs/webtty";
23
-
24
- const decoder = new TextDecoder();
25
-
26
- const webtty = new WebTTY(
27
- {
28
- url: "wss://host.example.t.rstream.io?rstream.token=<token>",
29
- },
30
- {
31
- cmdArgs: ["uname", "-a"],
32
- interactive: false,
33
- },
34
- {
35
- onConnect: () => {
36
- console.log("connected");
37
- },
38
- onStdout: (chunk) => {
39
- console.log(decoder.decode(chunk));
40
- },
41
- onComplete: (exitCode) => {
42
- console.log("completed", exitCode);
43
- },
44
- onError: (message) => {
45
- console.error(message);
46
- },
47
- },
48
- );
49
-
50
- webtty.connect();
51
- ```
52
-
53
- ## Interactive Sessions
54
-
55
- For an interactive terminal, write encoded input to stdin and forward terminal
56
- resize events.
57
-
58
- ```ts
59
- const encoder = new TextEncoder();
60
-
61
- const webtty = new WebTTY(
62
- { url: "wss://host.example.t.rstream.io?rstream.token=<token>" },
63
- { allocateTty: true, interactive: true },
64
- );
65
-
66
- webtty.connect();
67
-
68
- // After onConnect fires:
69
- webtty.writeStdin(encoder.encode("whoami\n"));
70
- webtty.resize(40, 120);
71
- ```
72
-
73
- Call `closeStdin()` to send EOF, or `disconnect()` to release the reader.
74
- For an Engine-managed detached execution, releasing the reader leaves the
75
- command running within its original execution budget.
76
-
77
- ## Connection failures and diagnostics
78
-
79
- Connection failures are delivered once through `onError`, including normal
80
- WebTransport closure before the stream opens. Disconnecting also releases a
81
- stream that becomes available after the opening was cancelled. A normal close
82
- after opening still drains buffered output before reporting the session result.
83
-
84
- Error messages redact values from the configured endpoint's query parameters,
85
- userinfo and fragment, including their common URL-encoded forms. Avoid logging
86
- the endpoint separately. An identifiable browser `SecurityError` points to
87
- browser policy and `connect-src`; an empty browser error reports that diagnostic
88
- details are unavailable. Such an error does not establish that CSP is the cause.
89
- Invalid endpoint configuration still throws synchronously without echoing the URL.
90
-
91
- ## Execute Commands
92
-
93
- For non-interactive agent workflows, use `runWebTTYCommand` or
94
- `executeWebTTYCommand`. Both open a WebTTY session, collect stdout and stderr,
95
- and resolve when the remote command exits.
96
-
97
- ```ts
98
- import { runWebTTYCommand } from "@rstreamlabs/webtty";
99
-
100
- const result = await runWebTTYCommand(
101
- { url: "wss://host.example.t.rstream.io?rstream.token=<token>" },
102
- "sh",
103
- ["-lc", "docker ps --format '{{.Names}}'"],
104
- { timeoutMs: 30_000 },
105
- );
106
-
107
- if (!result.success) {
108
- throw new Error(
109
- result.stderr || `Remote command exited with ${result.exitCode}`,
110
- );
111
- }
112
-
113
- console.log(result.stdout);
114
- ```
115
-
116
- Use `openWebTTYCommand` when you need live control over a running command. It
117
- returns a command object with replayable stdout/stderr, ordered log iteration,
118
- stdin writes, EOF handling, `wait()`, and explicit `kill()`/`terminate()`.
119
-
120
- `terminate({ signal?, timeoutMs? })` sends a protocol termination request and
121
- waits for the native process result, including final stdout/stderr. `kill()` is
122
- an alias with the same semantics. The default confirmation wait is 65 seconds.
123
- `wait()` and `exitCode` retain the native result, including a natural exit that
124
- races with termination. Repeated requests do not restart termination.
125
-
126
- Missing native support rejects the operation without disconnecting. An aborted
127
- or timed-out confirmation wait leaves the remote result unknown and the reader
128
- connected; `wait()` can still observe a later native result. Use `disconnect()`
129
- when the application is finished with that reader. No local failure invents an
130
- exit code. Managed clients must also check the Engine's `explicit_termination`
131
- capability; an older relay can ignore a request even if a new native server
132
- advertises support, in which case confirmation times out.
133
-
134
- Low-level `WebTTY.canTerminate()` exposes native support after `onConnect`.
135
- `WebTTY.requestTermination()` queues the request; only `onComplete` confirms its
136
- outcome. Managed control permissions still apply independently of support.
137
-
138
- Command output capture is bounded to 8 MiB by default (`maxOutputBytes` can set
139
- another positive byte limit), and at most 32,768 nonempty chunks. Exceeding either
140
- limit raises `WebTTYCommandOutputLimitError` on output readers and requests
141
- termination. Further output is discarded while the bounded confirmation wait
142
- continues; `wait()` still reports a native result if one arrives. If termination
143
- cannot be confirmed, the command reader is disconnected with an unknown result.
144
- Use the low-level `WebTTY` output callbacks for continuous streaming without
145
- retaining a replayable command output buffer.
146
-
147
- ```ts
148
- import { openWebTTYCommand } from "@rstreamlabs/webtty";
149
-
150
- const command = openWebTTYCommand(
151
- { url: "wss://host.example.t.rstream.io?rstream.token=<token>" },
152
- {
153
- cmdArgs: ["sh", "-lc", "npm test"],
154
- timeoutMs: 120_000,
155
- },
156
- );
157
-
158
- for await (const entry of command.logs()) {
159
- process[entry.stream === "stdout" ? "stdout" : "stderr"].write(entry.data);
160
- }
161
-
162
- const status = await command.wait();
163
-
164
- if (!status.success) {
165
- throw new Error(`Remote command exited with ${status.exitCode}`);
166
- }
167
- ```
168
-
169
- Use `WebTTYRemoteExecutor` when the URL is resolved lazily, for example from a
170
- fresh short-lived token. When the WebTTY server is discovered through
171
- `@rstreamlabs/tunnels`, pass the advertised `exec_path` value as `execPath`
172
- instead of assuming `/`.
173
-
174
- ### Bounded detached execution
175
-
176
- Fetch WebTTY capabilities from the same Engine that provides the authenticated
177
- terminal URL, then pass them as `managed.capabilities`. The object returned by
178
- `@rstreamlabs/tunnels`' WebTTY capabilities API is directly compatible.
179
-
180
- ```ts
181
- const command = openWebTTYCommand(
182
- {
183
- url: authenticatedTerminalUrl,
184
- managed: { capabilities, executionSeconds: 300 },
185
- },
186
- { cmdArgs: ["sh", "-c", "run-job"], interactive: false, allocateTty: false },
187
- );
188
- await command.ready();
189
- const executionId = command.managedSessionId;
190
- // Save executionId before releasing the reader.
191
- command.disconnect();
192
- ```
193
-
194
- The SDK checks the advertised transport and maximum duration before connecting.
195
- `ready()` waits for the relay's confirmation; `managedSessionId` then identifies
196
- the same execution for later session API calls. `ready({ signal })` cancels only
197
- that wait. A missing or zero budget preserves the ordinary connection-bound
198
- lifetime. Detaching does not establish an exit result, and losing the opening
199
- response does not make retrying the command safe.
200
-
201
- Use the saved ID to inspect the session or obtain an authorized participant and
202
- Attach grant. No new Open is needed to recover a running command. The original
203
- deadline remains unchanged. This does not add restart survival or an output
204
- cursor; historical output still depends on recording and retention permissions.
205
-
206
- For any managed connection, including Attach, `managed.capabilities` also gates
207
- explicit termination: both Engine and native server support are required. An
208
- Attach without this capability snapshot cannot send Terminate. Current control
209
- authority is still checked by the Engine for every request.
210
-
211
- Omitting `executionSeconds` or setting it to zero keeps the ordinary connection
212
- lifetime, including when the Engine reports `managed_protocol: false`. Supplying
213
- that capability snapshot still prevents unsupported termination requests.
214
-
215
- ### Managed session attach
216
-
217
- Engine-managed sessions are joined with a WebTTY `Attach` message. The attach
218
- grant is obtained from the control-plane API, then sent as the first protobuf
219
- message on the terminal stream. Terminal input and output stay on the WebTTY
220
- data path. The Engine participant stream uses WebSocket, including when the
221
- original execution used WebTransport. Check the session's `live.attachable`
222
- state before requesting an Attach grant and use its advertised participant
223
- transport.
224
-
225
- ```ts
226
- import { WebTTY } from "@rstreamlabs/webtty";
227
-
228
- const session = new WebTTY({
229
- managed: { capabilities },
230
- attach: {
231
- attachGrant,
232
- capabilities: ["read_stream", "request_control"],
233
- participantId,
234
- sessionId,
235
- },
236
- url: participantStreamUrl,
237
- });
238
-
239
- session.connect();
240
- ```
241
-
242
- ## Recorded Session Replay
243
-
244
- The package exposes replay helpers for product-managed WebTTY recordings. The
245
- helpers are public so applications can inspect and audit the decrypt/transcript
246
- path instead of relying on product UI code.
247
-
248
- ```ts
249
- import {
250
- createWebTTYE2EReplayPayloadCryptoFromKeyGrant,
251
- decryptWebTTYRecordedEvent,
252
- decryptWebTTYRecordedTextLog,
253
- } from "@rstreamlabs/webtty";
254
-
255
- const payloadCrypto = await createWebTTYE2EReplayPayloadCryptoFromKeyGrant(
256
- decryptMaterialGrant,
257
- localWorkspaceDeviceWebTTYIdentity,
258
- );
259
-
260
- for (const event of recordedEvents) {
261
- const chunk = await decryptWebTTYRecordedEvent(event, payloadCrypto);
262
- if (chunk) {
263
- // chunk.stream is "stdin", "stdout", or "stderr"; chunk.data is bytes.
264
- }
265
- }
266
-
267
- const transcript = await decryptWebTTYRecordedTextLog(
268
- recordedEvents,
269
- payloadCrypto,
270
- );
271
- console.log(transcript.text);
272
- ```
273
-
274
- `decryptWebTTYRecordedTextLog` renders a readable terminal transcript from
275
- recorded data events. It omits closed alternate-screen applications from the
276
- transcript, matching terminal scrollback behavior. If the recording ends while
277
- alternate screen is still active, the current alternate-screen snapshot is
278
- included by default. Use raw decrypted events when you need full forensic data.
279
-
280
- ## Filesystem Sidecar
281
-
282
- When a WebTTY server is started with `--fs-root`, the optional WebDAV sidecar
283
- advertises an `fs_path` value. Paths passed to the SDK are relative to that
284
- configured root.
285
-
286
- ```ts
287
- import { WebTTYFileSystem } from "@rstreamlabs/webtty";
288
-
289
- const fs = new WebTTYFileSystem({
290
- url: "https://host.example.t.rstream.io?rstream.token=<token>",
291
- });
292
-
293
- const files = await fs.list("/");
294
- const compose = await fs.readText("/compose.yaml");
295
- const stream = await fs.readStream("/large.log");
296
-
297
- await fs.writeFile("/notes/status.txt", "Ready\n");
298
- ```
299
-
300
- When the WebTTY server is discovered through `@rstreamlabs/tunnels`, pass the
301
- advertised `fs_path` value as `fsPath` instead of assuming `/fs`.
302
-
303
- `WebTTYFileSystem` also exposes fs-style aliases such as `readFile`,
304
- `writeFile`, `readdir`, `mkdir`, `stat`, `rename`, `copyFile`, `rm`, and
305
- `exists` for code that expects a familiar filesystem shape.
12
+ | I need to | Start with |
13
+ | -------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
14
+ | Authorize and open a terminal from a browser | [WebTTY browser setup](https://rstream.io/docs/webtty/sdk-browser). |
15
+ | Handle input, output, errors and disconnect in my own UI | [Interactive sessions](https://github.com/rstreamlabs/rstream-js/blob/main/packages/webtty/docs/001-interactive-sessions.md). |
16
+ | Run a command or follow a managed execution | [Commands](https://github.com/rstreamlabs/rstream-js/blob/main/packages/webtty/docs/002-commands.md). |
17
+ | Replay a recording or work with files | [Recordings and files](https://github.com/rstreamlabs/rstream-js/blob/main/packages/webtty/docs/003-recordings-and-files.md). |
18
+ | Select transport and verify the remote endpoint | [Transports and endpoint trust](https://github.com/rstreamlabs/rstream-js/blob/main/packages/webtty/docs/004-transports-and-crypto.md). |
306
19
 
307
- The filesystem sidecar is a WebDAV boundary, not a sandbox. It is rooted by the
308
- server-side `--fs-root` option and runs with the WebTTY server process
309
- permissions. It is not part of the encrypted WebTTY protobuf payload stream and
310
- is intentionally kept separate from WebTTY E2E payload encryption.
20
+ For an existing React UI, use [React](https://github.com/rstreamlabs/rstream-js/blob/main/packages/react/README.md) for a single
21
+ terminal or [Terminal UI](https://github.com/rstreamlabs/rstream-js/blob/main/packages/terminal-ui/README.md) for a workspace.
311
22
 
312
23
  ## Examples
313
24
 
314
- Runnable examples live under `examples/`:
315
-
316
- - `examples/remote-command` runs collected and streaming commands.
317
- - `examples/filesystem-sidecar` reads and writes through the WebDAV sidecar.
318
-
319
- ## Configuration
320
-
321
- Client-level options:
322
-
323
- | Option | Purpose |
324
- | --------------------- | ----------------------------------------------------------- |
325
- | `url` | WebSocket or WebTransport endpoint for the WebTTY server. |
326
- | `transport` | Optional transport override: `websocket` or `webtransport`. |
327
- | `sendHeartbeat` | Send heartbeat messages. Defaults to `true`. |
328
- | `heartbeatIntervalMs` | Heartbeat interval in milliseconds. Defaults to `5000`. |
329
-
330
- Execution options:
331
-
332
- | Option | Purpose |
333
- | ------------- | ------------------------------------------------------- |
334
- | `cmdArgs` | Command arguments requested for the remote session. |
335
- | `envVars` | Environment variables requested for the remote session. |
336
- | `allocateTty` | Ask the server for a TTY. Defaults to `true`. |
337
- | `interactive` | Enable stdin. Defaults to `true`. |
338
- | `username` | Optional user name or numeric user ID. |
339
- | `workdir` | Optional working directory. |
340
-
341
- The remote WebTTY server decides which execution options are accepted. Treat
342
- these values as requests, not local privilege boundaries.
343
-
344
- ## Transports
345
-
346
- The browser client uses WebSocket by default:
347
-
348
- ```ts
349
- const terminal = new WebTTY({ url: "wss://terminal.example/session" });
350
- ```
351
-
352
- In Node.js, supply the Node transport to each client configuration:
353
-
354
- ```ts
355
- import { nodeWebSocketFactory } from "@rstreamlabs/webtty/node";
356
- import { runWebTTYCommand } from "@rstreamlabs/webtty/node";
357
-
358
- const result = await runWebTTYCommand(
359
- {
360
- url: "wss://terminal.example/session",
361
- webSocketFactory: nodeWebSocketFactory,
362
- },
363
- "whoami",
364
- );
365
- ```
366
-
367
- This uses HTTP/1.1 WebSocket with normal TLS verification, a 10-second handshake
368
- deadline, a 1-second close deadline and the configured `maxMessageSize` limit.
369
- It works independently of the global WebSocket implementation and does not
370
- modify other clients or browser bundles. The same option is accepted by
371
- `WebTTY`, `runWebTTYCommand`, `openWebTTYCommand` and `WebTTYRemoteExecutor`.
372
- Choose WebTransport explicitly when the runtime and endpoint support it;
373
- transport selection preserves the requested protocol.
374
-
375
- Use WebTransport when the endpoint is published over HTTP/3 WebTransport:
376
-
377
- ```ts
378
- const terminal = new WebTTY({
379
- transport: "webtransport",
380
- url: "https://terminal.example/session",
381
- });
382
- ```
383
-
384
- Both transports carry the same WebTTY protobuf messages. WebTransport uses the
385
- same length-prefixed protobuf framing as the Go WebTransport implementation.
386
-
387
- For local WebTransport tests that use an ephemeral self-signed certificate, pass
388
- the browser WebTransport certificate pinning options through `webTransportOptions`:
389
-
390
- ```ts
391
- const terminal = new WebTTY({
392
- transport: "webtransport",
393
- url: "https://127.0.0.1:8443/",
394
- webTransportOptions: {
395
- serverCertificateHashes: [
396
- { algorithm: "sha-256", value: certificateSha256 },
397
- ],
398
- },
399
- });
400
- ```
401
-
402
- Production endpoints should normally rely on publicly trusted TLS certificates
403
- and leave `webTransportOptions` unset.
404
-
405
- ## Payload Crypto Hooks
406
-
407
- Managed WebTTY can keep the protobuf session envelope visible to the server
408
- while carrying stdin/stdout/stderr bytes as encrypted payloads. This lets the
409
- server route sessions, record metadata, enforce policy, and track lifecycle
410
- events without receiving plaintext terminal bytes.
411
-
412
- The SDK exposes payload crypto hooks through `payloadCrypto`. It also provides
413
- `generateWebTTYE2EIdentity`, `createWebTTYE2EClientPayloadCrypto`, and
414
- `createWebTTYE2EServerPayloadCrypto` helpers for WebCrypto-backed E2E payload
415
- encryption.
416
-
417
- Implemented E2E suites:
418
-
419
- | Layer | Suite |
420
- | ------------- | -------------------------------------------------------------------- |
421
- | Payload bytes | AES-256-GCM with a fresh 96-bit nonce per WebTTY data message |
422
- | Key envelope | HPKE Base mode: DHKEM(X25519, HKDF-SHA256), HKDF-SHA256, AES-256-GCM |
423
-
424
- Crypto helpers attach a `cryptoInfo` object to the returned `payloadCrypto`.
425
- UI bindings can use it to display runtime security details without hard-coding
426
- suite names. The object reports the E2E mode, payload cipher, tag and nonce
427
- sizes, key agreement, key derivation, and key-encryption suites that are
428
- actually configured for the session.
429
-
430
- The WebTTY protobuf envelope remains visible for routing and policy; only the
431
- stdin/stdout/stderr payload bytes are encrypted by these helpers.
432
-
433
- Key identifiers and X25519 key material can be passed as raw `Uint8Array`
434
- values or as unpadded base64url strings, matching the local WebTTY identity
435
- files generated by the rstream CLI.
436
-
437
- When a client needs replay/decrypt grants to point at product resources instead
438
- of opaque public keys, pass typed recipients to
439
- `createWebTTYE2EClientPayloadCrypto`:
440
-
441
- ```ts
442
- const crypto = await createWebTTYE2EClientPayloadCrypto({
443
- recipients: [
444
- {
445
- id: "keyset-1",
446
- keyId: workspaceRecipientKeyId,
447
- kind: "workspace_keyset",
448
- publicKey: workspaceRecipientPublicKey,
449
- },
450
- ],
451
- });
452
- ```
453
-
454
- The helper builds the WebTTY `key_context` before HPKE wrapping, so the context
455
- is covered by the HPKE authenticated data. `createWebTTYE2EKeyContext` is also
456
- available when the application needs to provide the context explicitly with
457
- workspace, project, or server identifiers.
458
-
459
- Recorded engine events may expose both `key_context` and `key_context_raw`.
460
- Replay and decrypt flows must prefer `key_context_raw` when it is present. It is
461
- the unpadded base64url encoding of the exact context bytes used for HPKE/AAD;
462
- `key_context` is a readable metadata projection and can be affected by JSON
463
- normalization after storage.
464
-
465
- Browser applications do not read environment variables or `.rstream` files. They
466
- must receive either an explicit known server endpoint identity or a
467
- workspace-managed trust grant before creating the WebTTY client. When an
468
- endpoint identity is configured, the browser verifies the server proof before it
469
- sends the WebTTY `Open` message. When the server requires client authentication,
470
- the browser also needs a local client endpoint identity so it can sign a
471
- `ClientProof`.
472
-
473
- Node.js applications that run beside the rstream CLI can use the local trust
474
- helper to apply the same WebTTY trust-store resolution as the CLI and native
475
- clients:
476
-
477
- ```ts
478
- import { createWebTTYE2EClientPayloadCryptoFromLocalTrust } from "@rstreamlabs/webtty/node";
479
-
480
- const payloadCrypto = await createWebTTYE2EClientPayloadCryptoFromLocalTrust({
481
- required: true,
482
- });
483
- ```
484
-
485
- The helper resolves `RSTREAM_WEBTTY_KNOWN_SERVER_KEY`,
486
- `RSTREAM_WEBTTY_KNOWN_SERVERS_FILE`, and the default
487
- `~/.rstream/webtty/known_servers.json` file. If no trust material exists and
488
- `required` is not set, it returns `undefined` so plaintext WebTTY sessions remain
489
- available for unprotected servers.
490
-
491
- The WebDAV filesystem sidecar is a separate HTTP/WebDAV surface. It is not
492
- covered by WebTTY payload crypto and should not be presented as protected by
493
- WebTTY E2E encryption.
494
-
495
- Protocol suite identifiers currently represented in the WebTTY protobuf
496
- contract are:
497
-
498
- | Field | Protocol identifiers |
499
- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------- |
500
- | `payloadSuite` | `aes-256-gcm`, `aes-256-gcm-random-nonce`, `chacha20-poly1305` |
501
- | `keyEnvelopeSuite` | `hpke-x25519-hkdf-sha256-aes-256-gcm`, `p256-hkdf-sha256-aes-256-gcm-random-nonce`, `hpke-x25519-hkdf-sha256-chacha20-poly1305` |
502
-
503
- The helpers support two complete E2E profiles. Existing applications keep using
504
- the default HPKE/X25519/HKDF-SHA256/AES-256-GCM profile. Applications that use
505
- E2E with a FIPS build of the Go client or engine must select the
506
- P-256/HKDF-SHA256/AES-256-GCM random-nonce profile and use WebTransport:
507
-
508
- ```ts
509
- import { createWebTTYE2EClientPayloadCrypto } from "@rstreamlabs/webtty";
510
- import { WebTTY } from "@rstreamlabs/webtty";
511
- import { webTTYFIPSCompatibleKeyEnvelopeSuite } from "@rstreamlabs/webtty";
512
-
513
- const payloadCrypto = await createWebTTYE2EClientPayloadCrypto({
514
- keyEnvelopeSuite: webTTYFIPSCompatibleKeyEnvelopeSuite,
515
- recipients: [
516
- {
517
- keyEnvelopeSuite: webTTYFIPSCompatibleKeyEnvelopeSuite,
518
- keyId: serverKeyId,
519
- publicKey: serverPublicKey,
520
- },
521
- ],
522
- });
523
-
524
- const client = new WebTTY(
525
- { transport: "webtransport", url },
526
- { payloadCrypto },
527
- );
528
- ```
529
-
530
- Standard rstream endpoints accept both profiles. FIPS Go builds accept only the
531
- P-256 random-nonce profile for E2E and require WebTransport. Application E2E
532
- is optional unless server or workspace policy requires it; a transport-only
533
- connection does not protect terminal content from an Engine that terminates
534
- transport encryption. ChaCha20-Poly1305 identifiers remain
535
- reserved for forward compatibility and are rejected by the current helpers.
536
-
537
- This JavaScript implementation provides protocol interoperability with the
538
- FIPS Go artifacts. Browser WebCrypto does not embed the validated Go
539
- Cryptographic Module, so this package does not carry the Go module's FIPS
540
- 140-3 Inside status.
541
-
542
- Do not derive payload keys from passwords or application strings.
543
-
544
- ## Events
545
-
546
- | Event | Purpose |
547
- | ----------------------------- | ------------------------------------------------------------------ |
548
- | `onConnect` | Called after the server acknowledges the session. |
549
- | `onStdout` / `onStderr` | Called with stream chunks from the remote process. |
550
- | `onStdoutEos` / `onStderrEos` | Called when the corresponding stream reaches EOS. |
551
- | `onComplete` | Called with the remote process exit code. |
552
- | `onError` | Called for server errors, protocol errors, or connection failures. |
553
-
554
- ## Security Notes
555
-
556
- Browser WebTTY sessions should use short-lived tokens scoped to the specific
557
- tunnel and path. Do not embed personal access tokens or application credentials
558
- in frontend code.
559
-
560
- The [Node transport dependency baseline](docs/000-dependencies.md) explains the
561
- qualified `ws` version and bounded automatic Pong behavior.
562
-
563
- ## Development
564
-
565
- ```sh
566
- npm --workspace @rstreamlabs/webtty run test
567
- npm --workspace @rstreamlabs/webtty run type-check
568
- npm --workspace @rstreamlabs/webtty run lint
569
- npm --workspace @rstreamlabs/webtty run build
570
- ```
571
-
572
- # Transport resource limits
573
-
574
- `WebTTYClientConfig.maxMessageSize` limits encoded messages in both directions
575
- and defaults to 1 MiB. WebTransport validates a frame length before allocating
576
- its body and buffers at most one partial frame. It pauses reads while an async
577
- message handler (including E2E decryption) is pending. Incoming WebSocket data
578
- and outgoing transport queues are bounded to four times the message limit;
579
- SDK queues also have a 1,024 message limit. Exceeding a limit closes the session
580
- with an explicit error. Applications should split large stdin writes into
581
- chunks below the message limit, allowing for protobuf and encryption overhead.
582
-
583
- Disconnect cancels pending transport setup and reads, aborts writes and drops
584
- queued terminal data. Late decryption results are not delivered after a local
585
- disconnect. A runtime without WebTransport reports that capability limitation.
586
-
587
- For Node local trust helpers, `RSTREAM_DATA_DIR` selects an absolute state root
588
- instead of the default `~/.rstream`. This matches the Go and C++ CLI state layout
589
- and is independent of the engine connection configuration.
590
-
591
- ## Shared filesystem backend
25
+ | Example | What it shows |
26
+ | --------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
27
+ | [Remote command](https://github.com/rstreamlabs/rstream-js/tree/main/packages/webtty/examples/remote-command) | Run and observe a permitted command against an authorized WebTTY endpoint. |
28
+ | [Filesystem sidecar](https://github.com/rstreamlabs/rstream-js/tree/main/packages/webtty/examples/filesystem-sidecar) | List and read files through the authorized sidecar. |
592
29
 
593
- `WebTTYFileSystem` and its existing exports remain available. The implementation now lives in `@rstreamlabs/filesystem`, which also exports `WebDAVFileSystem` and the transport-independent `FileSystemBackend` interface. Existing WebTTY write helpers and configuration are preserved. New read clients can use `readStream` to avoid buffering large downloads; native `downloadURL` is available only when authentication does not require custom headers. This filesystem protocol is independent from the temporary encrypted file-sharing utility and from WebTTY E2E payload encryption.
30
+ For workspace checks and package maintenance, follow
31
+ [Contributing](https://github.com/rstreamlabs/rstream-js/blob/main/CONTRIBUTING.md)
32
+ and the [Node transport dependency baseline](https://github.com/rstreamlabs/rstream-js/blob/main/packages/webtty/docs/000-dependencies.md).
package/dist/index.d.mts CHANGED
@@ -4995,8 +4995,8 @@ interface WebTTYClientConfig {
4995
4995
  webTransportOptions?: WebTTYWebTransportOptions;
4996
4996
  /**
4997
4997
  * Attach to an existing engine-managed WebTTY session instead of opening a
4998
- * new remote process. The attach grant is issued by the control-plane API;
4999
- * terminal bytes still flow through the WebTTY protobuf stream.
4998
+ * new remote process. The Engine API issues the attach grant.
4999
+ * Terminal bytes flow through the WebTTY protobuf stream.
5000
5000
  */
5001
5001
  attach?: WebTTYAttachConfig;
5002
5002
  /** Engine capabilities and optional detached execution budget. */
package/dist/index.d.ts CHANGED
@@ -4995,8 +4995,8 @@ interface WebTTYClientConfig {
4995
4995
  webTransportOptions?: WebTTYWebTransportOptions;
4996
4996
  /**
4997
4997
  * Attach to an existing engine-managed WebTTY session instead of opening a
4998
- * new remote process. The attach grant is issued by the control-plane API;
4999
- * terminal bytes still flow through the WebTTY protobuf stream.
4998
+ * new remote process. The Engine API issues the attach grant.
4999
+ * Terminal bytes flow through the WebTTY protobuf stream.
5000
5000
  */
5001
5001
  attach?: WebTTYAttachConfig;
5002
5002
  /** Engine capabilities and optional detached execution budget. */
@@ -1,11 +1,26 @@
1
- # `rstream-webtty-filesystem-sidecar-example`
1
+ # Write and read a file through a WebTTY sidecar
2
2
 
3
- Example of using `@rstreamlabs/webtty` to read and write files through the optional WebDAV filesystem sidecar.
3
+ This Node.js example writes `codex-note.txt` at the root of a WebTTY WebDAV
4
+ sidecar, lists the directory and reads the file through both text and streaming
5
+ methods. Use a disposable writable export. The write overwrites an existing
6
+ file of the same name.
4
7
 
5
- The sample only needs the WebTTY URL. If you build an inventory-driven integration, pass the advertised `fs_path` from `rstream webtty list -o json` as the SDK `fsPath` option.
8
+ [Build the checkout](../../../../docs/000-building-from-source.md) so this
9
+ sample can load its local SDK dependency. Use an authorized HTTPS endpoint
10
+ with a writable WebDAV sidecar at `/fs`. The
11
+ [sidecar guide](https://rstream.io/docs/webtty/quickstart#add-a-filesystem-sidecar)
12
+ explains server setup. If your endpoint advertises another `fs_path`, pass
13
+ it as `fsPath` in the sample.
14
+
15
+ From this directory, copy the example environment file and set
16
+ `RSTREAM_WEBTTY_URL` to the authorized URL in `.env.local`.
6
17
 
7
18
  ```sh
8
19
  cp .env.local.example .env.local
9
20
  npm install
10
21
  npm start
11
22
  ```
23
+
24
+ Expect the listing to contain `codex-note.txt` and both reads to print
25
+ `written through rstream WebTTY`. The process exits after the reads. Delete
26
+ the sample file from the export and remove the local credential file.
@@ -2,7 +2,10 @@
2
2
 
3
3
  Example of using `@rstreamlabs/webtty` to run collected and streaming commands through a WebTTY server.
4
4
 
5
- The sample only needs the WebTTY URL. If you build an inventory-driven integration, pass the advertised `exec_path` from `rstream webtty list -o json` as the SDK `execPath` option.
5
+ [Build the checkout](../../../../docs/000-building-from-source.md), then use
6
+ this directory. Set `RSTREAM_WEBTTY_URL` in the copied `.env.local` file to an
7
+ authorized URL. For an inventory-driven integration, pass the advertised
8
+ `exec_path` from `rstream webtty list -o json` as the SDK `execPath` option.
6
9
 
7
10
  ```sh
8
11
  cp .env.local.example .env.local
@@ -10,8 +13,7 @@ npm install
10
13
  npm start
11
14
  ```
12
15
 
13
- Use Node.js 24 and npm from this directory after building the monorepo. The Node
14
- entry point supplies `nodeWebSocketFactory`, so it uses the qualified HTTP/1.1
16
+ The Node entry point supplies `nodeWebSocketFactory`, so it uses the qualified HTTP/1.1
15
17
  WebSocket transport with certificate verification. Set `NODE_EXTRA_CA_CERTS`
16
18
  before starting the process when the endpoint uses a private CA. The two commands
17
19
  print collected output and then three streamed ticks. The remote server must
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rstreamlabs/webtty",
3
- "version": "1.12.2",
3
+ "version": "1.12.3",
4
4
  "description": "Client-side implementation of the rstream WebTTY protocol.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -54,7 +54,7 @@
54
54
  "dependencies": {
55
55
  "protobufjs": "^8.8.1",
56
56
  "ws": "^8.23.0",
57
- "@rstreamlabs/filesystem": "^0.3.2"
57
+ "@rstreamlabs/filesystem": "^0.3.3"
58
58
  },
59
59
  "publishConfig": {
60
60
  "access": "public"