@johnhenry/wsh 0.49.0 → 0.51.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.
package/README.md CHANGED
@@ -666,6 +666,8 @@ bundler drop what you do not use.
666
666
  | `@johnhenry/wsh/reverse` | `createReverseHost()` for a page or Worker: dial out to a relay and serve the operator it bridges. The same function `@johnhenry/wsh/server` exports, minus `exec: true` and `fs: { root }` |
667
667
  | `@johnhenry/wsh/testing` | the QMux record and frame codec (`encodeStream`, `encodeRecord`, `RecordDecoder`, `decodeFrames`, the varint and the other frame encoders), for a test that reads, alters and re-wraps what travels on a connection; and two test doubles for code that embeds wsh: `createInProcessPipeRelay({ tap })` (the real pipe relay in this process, with a `WebSocket` that dials it, a record of every message it copied, and a `tap` that may change, drop, repeat or add to what it writes, like a hostile relay) and `createMemoryPair({ host, username })` (a memory host and a client already logged in to it). **Experimental: not part of the stable API**; it may change or disappear in any release. Importing only the codec costs under 1 kB: the doubles are separate exports a bundler drops |
668
668
  | `@johnhenry/wsh/identity` | a key in its four spellings, and `authorized_keys` lines: `fingerprint` and `podId` of a raw key, `fingerprintToPodId` / `podIdToFingerprint`, `rawKeyToOpenSsh` / `openSshToRawKey` / `parseOpenSshKey` / `publicKeyToOpenSsh`, `identityOf`, `normalizeIdentity`, `authorizedKeyLine`. Stable; see [Identity and capabilities for other implementations](#identity-and-capabilities-for-other-implementations-220) |
669
+ | `@johnhenry/wsh/duplex` | a full wsh session over a duplex of messages another library provides: `serveWshOverDuplex(host, { send })`, `connectWshOverDuplex({ send }, credentials)`, `createDuplexSocket`. Sealed by default; see [wsh over a duplex](#wsh-over-a-duplex-220) |
670
+ | `@johnhenry/wsh/objects-types` | `describeRootTypes(description, { name })`: the `.d.ts` text for a root of `wsh-objects`, from what a key may do (a pure function), and `checkTypeText`; see [Typed remotes](#typed-remotes-219) |
669
671
  | `@johnhenry/wsh/capabilities` | `permits(capabilities, request)`: the notation of key capabilities as a pure function, the one `@johnhenry/wsh/server` and the memory host evaluate. Stable; same section |
670
672
  | `@johnhenry/wsh/spec/*.json`, `*.md`, `wsh-v1.yaml` | the data files of the specification: `capabilities.md`, `capabilities.vectors.json`, `key-options.vectors.json`, the wire spec |
671
673
  | `@johnhenry/wsh/server` | Node only |
@@ -692,19 +694,21 @@ optional ML-KEM backend, is left out of the measurement. What a page ships is wh
692
694
  | browser bundle | minified | gzip |
693
695
  | --- | ---: | ---: |
694
696
  | `@johnhenry/wsh` (whole entry point) | 165.8 kB | 50.3 kB |
695
- | `@johnhenry/wsh/memory` (whole entry point) | 232.6 kB | 72.7 kB |
696
- | `@johnhenry/wsh/host` (whole entry point) | 127.3 kB | 41.9 kB |
697
- | `@johnhenry/wsh/reverse` (whole entry point) | 221.1 kB | 68.4 kB |
697
+ | `@johnhenry/wsh/memory` (whole entry point) | 233.4 kB | 72.9 kB |
698
+ | `@johnhenry/wsh/host` (whole entry point) | 127.9 kB | 42.1 kB |
699
+ | `@johnhenry/wsh/reverse` (whole entry point) | 221.7 kB | 68.6 kB |
698
700
  | `@johnhenry/wsh/pipe-relay` (whole entry point) | 7.0 kB | 3.0 kB |
699
- | `@johnhenry/wsh/testing` (whole entry point) | 240.4 kB | 75.7 kB |
700
- | `@johnhenry/wsh/page` (whole entry point) | 301.5 kB | 95.8 kB |
701
- | `@johnhenry/wsh/objects` (whole entry point) | 177.4 kB | 54.4 kB |
702
- | `@johnhenry/wsh/capabilities` (whole entry point) | 10.5 kB | 3.8 kB |
701
+ | `@johnhenry/wsh/testing` (whole entry point) | 241.2 kB | 76.0 kB |
702
+ | `@johnhenry/wsh/page` (whole entry point) | 327.0 kB | 104.1 kB |
703
+ | `@johnhenry/wsh/objects` (whole entry point) | 201.5 kB | 62.0 kB |
704
+ | `@johnhenry/wsh/objects-types` (whole entry point) | 10.2 kB | 4.2 kB |
705
+ | `@johnhenry/wsh/capabilities` (whole entry point) | 10.6 kB | 3.8 kB |
703
706
  | `@johnhenry/wsh/identity` (whole entry point) | 15.7 kB | 5.7 kB |
707
+ | `@johnhenry/wsh/duplex` (whole entry point) | 140.1 kB | 42.4 kB |
704
708
  | `import { encodeRecord } from '@johnhenry/wsh/testing'` | 1.8 kB | 0.9 kB |
705
709
  | `import { generateKeyPair } from '@johnhenry/wsh'` | 0.4 kB | 0.3 kB |
706
710
  | `import { WshClient } from '@johnhenry/wsh'` | 135.9 kB | 40.8 kB |
707
- | `import { createConnectionFactory } from '@johnhenry/wsh/host'` | 104.0 kB | 34.0 kB |
711
+ | `import { createConnectionFactory } from '@johnhenry/wsh/host'` | 104.6 kB | 34.2 kB |
708
712
  <!-- bundle-size:end -->
709
713
 
710
714
  ### Signing with a page-held signer
@@ -932,10 +936,16 @@ await release(cart); // gives its place back; everything
932
936
  so, `handles: { window: { wideEntries: true } }` (in `createPageHost`, `wideEntries: true` beside `mode: 'handles'`), or lists the paths. A wildcard in `get` alone needs no acknowledgement. A values root is not affected.
933
937
  - **Capabilities.** `objects:ROOT[:OP]` apply unchanged: an operation through a handle is the same `get`, `call`, `set` of the producing path (a key with `objects:window:get` can read through a handle and cannot call through it).
934
938
  - **What a handle is not.** The host's real object stays in the page: calling a method runs the page's code with the caller's plain-data arguments, as for any `call`; a handle to an object with a powerful method is as powerful as that method's entry in `call`. A handle is
935
- a reference to something already reachable by a path, so it cannot reach more than the path's own entries; but a wide entry (`window.app.**`) covers every member of every object under it. Events are not offered through a handle, and callbacks are not built.
939
+ a reference to something already reachable by a path, so it cannot reach more than the path's own entries; but a wide entry (`window.app.**`) covers every member of every object under it. Callbacks are one-way (see below).
940
+ - **Events through a handle** (`on(use(handle).bus, 'ready', listener)`, or `on(use(handle), ...)` when the handle is the source itself). The source is the handle's **producing path extended as written**, and it is judged exactly as a path subscription for that
941
+ path would be: an `allow.on` entry that names that path and the type exactly (no wildcard in either), the key's `objects:ROOT:on`, and `authorize` (`op.text` is the extended path, `op.type` the type). **Never implied by `get` or `call`**, and never inherited: the same object reached by
942
+ another path is a different path with its own entry. A node handle keeps its rules (no node handle without `nodes: true`; the graph members need an entry that names them). The subscription **ends with the handle**: `release(handle)` takes the page's listener out
943
+ and drops what it had queued; it also ends with the channel, Stop, a navigation and a revoke, as a path subscription does. A handle released while its subscription was being authorized leaves no listener. `maxSubscriptions`, the rate, size and queue bounds and the drop counting are the same ones, shared with path subscriptions.
944
+ The delivery is the same too: plain copies, never the event, never a handle.
936
945
 
937
- A host says what it supports with its roots (`features`: `events`, `callbacks`, and `handles` when a root opted in). A client does not send a function to a host that has not said it supports callbacks, nor use events on one that has not said so (a named `unsupported` error);
938
- a handle-shaped answer from a host that never said it supports handles is the same error. A 0.47.0 host says nothing, so it counts as supporting none of them.
946
+ A host says what it supports with its roots (`features`: `events`, `callbacks`, and `handles` and `handle-events` when a root opted in). A client does not send a function to a host that has not said it supports callbacks, nor use events on one that has not said so, nor subscribe through
947
+ a handle on one that has not said `handle-events` (0.50.0 and before; a named `unsupported` error, nothing is sent);
948
+ a handle-shaped answer from a host that never said it supports handles is the same error. A 0.47.0 host says nothing, so it counts as supporting none of them. A 0.50.0 client never sends a handle subscription (it refuses to write one), so it is unaffected by a 0.51.0 host.
939
949
 
940
950
  #### Callbacks
941
951
 
@@ -955,6 +965,34 @@ await release(fn); // kills the stub (a
955
965
  - The call with callbacks is a `call` for `authorize` (`op.callbacks` is how many) and for the key's `objects:ROOT:call` capability. A callback is a channel for the page's own code to push plain values to the caller: it can send whatever the page's code puts in it, within the bounds, so list `(callback)` only on calls whose
956
966
  stub the page will use for what the caller should see.
957
967
 
968
+ #### An MCP face for allow-listed paths (#219)
969
+
970
+ An MCP client can use named paths of a root without the objects client: `exposeObjects({ roots, allow, mcp: { tools: [...] } })` (and, in a page host, `createPageHost({ expose: { window: { allow, mcp: { tools: [...] } } } })`, with paths relative to the root) makes **exactly the paths it names** into MCP tools:
971
+
972
+ ```js
973
+ const handler = exposeObjects({
974
+ roots: { window }, allow: { get: ['window.document.title'], call: ['window.app.cart.add', 'window.app.cart.clearAll'] },
975
+ mcp: { tools: [
976
+ { name: 'cart_add', description: 'Add a product to the cart', call: 'window.app.cart.add',
977
+ inputSchema: { type: 'object', properties: { sku: { type: 'string', minLength: 1 }, qty: { type: 'integer', minimum: 1 } }, required: ['sku'], additionalProperties: false } },
978
+ { name: 'page_title', description: 'The title of the page', get: 'window.document.title' },
979
+ ] },
980
+ }); // clearAll is allowed by call and is NOT a tool: nothing is a tool by being allowed
981
+ const mcp = webmcpTools({ window, tools: handler.mcpTools, allow: handler.mcpToolNames }); // createPageHost does this itself; any host with `rpc: { mcp }` or serveMcpOverDuplex can
982
+ ```
983
+
984
+ - **What a tool is.** A **call** of one named method (`call: 'window.app.cart.add'`), or a **get** of one named value (`get: 'window.document.title'`; add `readOnly: true` to skip the question for it); a literal member path (no wildcard, no path through a call result), that the allow-lists name for that operation and that needs no listing it does not have (checked when the host is created: a tool never widens
985
+ the allow-list, and a path that is not listed there is a `TypeError`, not a silent tool). Each tool has a host-authored `name`, `description` and `inputSchema`, and `readOnly` (**only `readOnly: true` marks a tool read-only, a get included: with nothing said a tool asks the person like any other, because a getter can have effects**). `args: 'object'` passes the validated input as the call's one argument (the default when the schema lists properties), `args: ['a', 'b']` passes those properties as the arguments in order.
986
+ There is no tool for an event, a handle or a callback, and none can be made: an argument is plain data, a result is plain data or an error (a function, or an object that is not plain data, is an error that says so, never a handle).
987
+ - **Arguments are validated before anything runs.** `inputSchema` is checked against the far side's arguments before the person is asked and before the page's function is called, by a small bounded subset of JSON Schema (`type`, `enum`, `const`, `properties`, `required`, `additionalProperties`, `items`, `minItems`, `maxItems`, `minLength`, `maxLength`, `minimum`, `maximum`, `anyOf`; depth 8, 2000 values; no key that climbs to a prototype). **A schema that uses another keyword
988
+ (`$ref`, `pattern`, `oneOf`, ...) is refused when the host is created**, so what is advertised is what is checked. Write `additionalProperties: false`: with `args: 'object'` an extra property is passed to the page's function otherwise. The arguments then go through the same copy as an objects call.
989
+ - **The same approval, bounds and label as the WebMCP bridge**, because they are served by the same handler: a tool that is not marked read-only asks the person at the page first (`approve`, `prompt`; with no way to ask it is denied); `maxInputBytes`, `maxResultBytes`, `maxInflight`, `maxCallsPerMinute`, the call timeout, the schema size; every result is labelled untrusted page content (`_meta['wsh/untrusted']`); a page function that throws is an error result with its message and no stack.
990
+ `onCall` sees the calls. Remember what a read-only mark is: the host's word. A getter that has effects is still a getter, and marking it read-only skips the question.
991
+ - **Two notations, both required.** A key lists and calls a tool only if its capabilities permit `mcp:TOOL` (or `mcp:*`) **and** the operation on that root (`objects:ROOT` or `objects:ROOT:call` for a call, `objects:ROOT` or `objects:ROOT:get` for a get): `capabilities="mcp:cart_add,objects:window:call"`. A key that has a capability line with `mcp:TOOL` and no `objects:` entry for the root sees no tool and can call none; a key with `objects:` and no `mcp:` entry cannot open the channel. A key with no capability line has both, as for every capability.
992
+ The `objects:` grant is asked again when the tool runs, with the allow-list, the names that need listing and `authorize(who, op)` (`op.kind` is `get` or `call`): **a tool never widens what the objects client would be allowed for that key.**
993
+ - **What it does not do.** It does not make the page's function safe (it runs with the page's authority and the caller's arguments); it does not label a result as true, only as untrusted; it is no more than the allow-list plus the tool list plus the approval, and a wide allow-list entry under a tool path does not widen the tool (the tool names one path) but does widen the objects client. Wire: nothing new (the existing `mcp` channel and its methods); Rust hosts and clients have no `wsh-objects`, so there is no Rust equivalent of the host side,
994
+ but a Rust `wsh --sealed --via ... mcp` reaches a page host's `mcp` channel and so lists and calls these tools like any others.
995
+
958
996
  **The indicator is best effort.** The page host shows a visible element while a session is connected, puts it back if the page removes it, and has a Stop button. Page code can always remove or cover a DOM element, and a tool or a
959
997
  function the caller may call runs with the page's authority. What holds is **Stop and revoke** (they close the channel from the page's own code, whatever is on screen) and **the key's capabilities and the host's allow-lists**.
960
998
 
@@ -973,9 +1011,35 @@ reach is exactly the paths the lists name (and, below a `get`, the plain data in
973
1011
  written by third parties.
974
1012
  - A sealed session, a key login and a visible indicator (the page host) are what keep a relay and an unknown caller out; `authorize` is where an embedder asks the person.
975
1013
 
976
- Types: `@johnhenry/wsh/objects` ships `.d.ts` (`client.openObjects<T>()` types the roots; references are untyped). Size: `@johnhenry/wsh/objects` is 53.4 kB gzipped (it contains the client), and
977
- the page entry point is 93.1 kB with it; no other entry point changed. A capability per root and operation (`objects:ROOT[:OP]`) is described under [per-key capabilities](#authorized-key-options-122).
978
- Not built yet (later steps of #190): typed remotes (`Remote<T>`), an MCP face for the allow-listed paths, and a dial-out form.
1014
+ Size: see the size table (`npm run size`) for `@johnhenry/wsh/objects` (it contains the client and the checks the host runs on a type map), `@johnhenry/wsh/objects-types` and the page entry point. A capability per root and operation (`objects:ROOT[:OP]`) is described under [per-key capabilities](#authorized-key-options-122).
1015
+ Not built yet: a dial-out form.
1016
+
1017
+ #### Typed remotes (#219)
1018
+
1019
+ `@johnhenry/wsh/objects` ships `.d.ts`; `client.openObjects<T>()` returns `T`, so a typed Proxy is a `T` you give it. Three ways, from least to most generated:
1020
+
1021
+ 1. **Write the value types.** `Remote<T>` maps a value type to the reference type (it `await`s to the value, has the members as references, and its methods return references); `RemoteRoots<T>` does it for the roots:
1022
+ `const { shop } = await client.openObjects<RemoteRoots<{ shop: Shop }>>(); const n: number = await shop.cart.add({ sku: 'A' });`. It says what you believe the host exposes; the host's allow-lists still decide. A reference is `PromiseLike`, not a `Promise`
1023
+ (there is no `catch` or `finally` on it: `ref.catch` is a remote property), and arguments stay plain data. `RemoteHandle<T>` carries a value type to `use(handle)`.
1024
+ 2. **Generate them for the key that connects.** `describeRootTypes(description, { name })` from `@johnhenry/wsh/objects-types` is a **pure function** that returns the text of a `.d.ts` for one root, and `rootDescription(page.window)` fetches the `description`
1025
+ (the host's `types` answer): the host's allow-list entries for that root, narrowed by **this key's** `objects:ROOT:OP` capabilities, and the host's type map. A path appears in the file only if an entry names it for an operation the key holds; an operation the key lacks,
1026
+ a path no entry names, and a member the host refuses are not there at all (not even as `never`). A plain value is `RemoteValue<unknown>` (a `PromiseLike<unknown>`), a call is `RemoteCall<unknown[], unknown, ...>` (`(...args: unknown[]) => PromiseLike<unknown>`, continuing as the members the allow-list names under `f()`),
1027
+ a wildcard (`*`, `**`) is `RemoteUntyped` (`any`: the members behind it are not guessed), `allow.on` and `eventFields` become typed `on` overloads (a source offers its listed types, and a listener gets `{ type, timeStamp, isTrusted, ...fields }` or `{ type, args }`),
1028
+ and an entry in `allow.set` makes `set(ref, key, value)` check the key. Use it as `client.openObjects<{ window: WindowRemote }>()`.
1029
+ 3. **Add precise types as the host.** `exposeObjects({ types: { 'window.app.cart.add': { args: '[item: { sku: string }]', result: 'number' }, 'window.document.title': { value: 'string' }, 'window.app.bus@ready': { data: '{ n: number }' } } })`
1030
+ (`createPageHost({ expose: { window: { types } } })` takes the same with paths relative to the root). `value` is the awaited value of a get (or the value a set takes), `args` a tuple and `result` the awaited value of a call, `data` what an event listener receives; a text may use `RemoteHandle<{ ... }>`.
1031
+
1032
+ **The host's type text is untrusted text.** It travels to the far side and is written into a file, so the far side checks it again: `checkTypeText` accepts a conservative subset of type syntax (identifiers, literals, and the punctuation of object, tuple, function, union, intersection, generic, conditional and indexed types) and refuses a new line or anything
1033
+ outside printable ASCII, comments (`//`, `/*`), `\`, backticks, `@`, `#`, the words `import`, `export`, `require`, `declare`, `module`, `namespace`, `global`, `typeof`, `class`, `function`, `enum`, `interface` and `eval`, unbalanced or mismatched brackets, a `;` outside braces and a `,` outside any bracket (so a text cannot close the declaration it sits in or add a member to it).
1034
+ Bounds: 1024 characters a text, 256 entries and 32 KiB for a root, 16 levels of nesting. A text is also refused unless an allow-list entry names its path for the operation it types, **when the host is created** and again when the far side builds the file. The text is **never evaluated**: it is copied into the string `describeRootTypes` returns, and nothing is written to a file
1035
+ unless you do it (the CLI below writes only when given `--out`, and not over an existing file without `--force`). A path segment that is not an identifier is written as a quoted name.
1036
+
1037
+ **What the types do not promise.** They are advisory and erased before anything runs: a type never widens what the host allows, and `authorize`, the always-refused names and the paths that must be named (`fetch`, cookies, storage, ...) still refuse at call time whatever the file says; a type can be wrong (the host's text is what the host believes, and
1038
+ a hand-written `T` is what you believe); `authorize` is dynamic and is not reflected; a wildcard region is untyped; whether a value arrives as a plain value, a named non-value or a handle depends on the page's data at run time, which no file can say (on a root with handles a get is `unknown` unless the host typed it `RemoteHandle<...>`); and the file describes the key that fetched it:
1039
+ another key gets another file, and a key that changes or expires changes the answer. The `types` answer tells a key the allow-list entries it may use, which is what `describe` would reveal path by path and nothing about a member the key may not reach.
1040
+
1041
+ **The CLI.** `wsh-objects-types [--root NAME] [--name TYPE] [--out FILE [--force]] [--sealed] [--host-key KEY] [--identity FILE] [user@]<url>` (the package's second bin; JavaScript only) connects like `wsh-mcp` does, asks for the description of one root and prints the declarations, or writes them with `--out`.
1042
+ The Rust `wsh` has no `wsh-objects` client and no equivalent. A host before 0.51.0 does not state the `types` feature in the `features` of its `roots` answer, and `rootDescription` then refuses with a named `unsupported` error without sending anything.
979
1043
 
980
1044
  ### WebTransport listener
981
1045
 
@@ -1646,6 +1710,26 @@ wsh-host` works (it is the same rpc channel, and a handy check). `wsh mcp` follo
1646
1710
  `SessionData` with credit (#191), so `wsh mcp --sealed` and `wsh --via <pipe relay> mcp` work against a JS host, as the npm `wsh-mcp --sealed` does. Not covered: WebTransport (`https://`) opens the channel's stream but the Rust client has only
1647
1711
  been run against WebSocket hosts.
1648
1712
 
1713
+ **Rust: `wsh objects`** reads and drives a host's remote objects (`wsh-objects`, written down in `spec/objects.md`; `rust-v0.18.0` carries it). It is a client only, for **sealed sessions only**:
1714
+
1715
+ ```
1716
+ wsh --sealed [--via RELAY] objects user@host roots
1717
+ wsh --sealed [--via RELAY] objects user@host get window.document.title
1718
+ wsh --sealed [--via RELAY] objects user@host call window.app.cart.add '{"sku":"A1"}' 2 # each argument is one JSON value
1719
+ wsh --sealed [--via RELAY] objects user@host set window.app.n 5
1720
+ wsh --sealed [--via RELAY] objects user@host snapshot window.app.state --depth 3
1721
+ wsh --sealed [--via RELAY] objects user@host describe window.app
1722
+ wsh --sealed [--via RELAY] objects user@host watch window.app.bus@ready --field detail --count 3
1723
+ wsh --sealed [--via RELAY] objects user@host session # JSON requests on stdin, one answer line each: one connection, so a handle can be held across calls
1724
+ ```
1725
+
1726
+ JSON on stdout. Plain data is printed as the JSON it is; bytes as `{"$bytes":"<base64>"}`, what the host could not clone as `{"$nonValue":{"kind":"function","type":"fn"}}`, a handle as `{"$handle":{...}}` (a page can build plain data that looks like these: this is an inspection format; use the library where that matters).
1727
+ **Text from the page is never interpreted**: names, strings, previews and error messages are printed as JSON strings in which every control character, C1 control, line or paragraph separator and bidirectional-text control is a `\uXXXX` escape. `watch` prints one line per event, `{"seq":N,"dropped":N,"dropped_here":N,"data":...}`: `dropped` is what the host dropped before it (its bounds: rate, size, queue), `dropped_here` what this side dropped when its bounded queue was full.
1728
+ Exit status: 0 done; 1 other failure; 2 usage, or not `--sealed`; 3 the host refused (its allow-lists, a key's `objects:` capability, a bound); 4 not found; 5 unsupported (the host does not state the channel, or `events` / `handles`, which are refused locally before anything is sent). `wsh --help objects` lists the rest.
1729
+
1730
+ In Rust code, `wsh_client::objects::ObjectsClient::open(&client)` gives `roots()`, `root(name)` and a `Target` with `get` / `call` / `construct` / `set` / `snapshot` / `describe` / `resolve(Chain)` (a whole chain such as `app.getCart().items` is one request) and `subscribe` (a bounded `Subscription`), with typed `ObjectsError`s (`Refused`, `Limit`, `NotFound`, `Unsupported`, ...) carrying the host's `reason`, values as a serde-friendly `Value` (bytes native), and `Handle`s (released with `release()`, when dropped, and when the session ends).
1731
+ **What it cannot do:** callbacks (passing a function to the host), events through a handle (the host offers none), and serving objects (`wsh-server` has no page host and no `wsh-objects` handler); WebTransport and Windows are not exercised. It protects nothing the host's allow-lists do not: it only speaks to a host that chose to expose objects.
1732
+
1649
1733
  ### Host key (fingerprint / TOFU)
1650
1734
 
1651
1735
  Give the server an identity and the stock client can pin it:
@@ -2149,7 +2233,7 @@ instead of dragging its own toolchain and CI job into an unrelated
2149
2233
  browser-app repo. It was previously deleted from clawser by accident
2150
2234
  (2026-03-14) and restored (2026-07-05) before this move.
2151
2235
 
2152
- Four crates, workspace-versioned (currently `0.17.1`):
2236
+ Four crates, workspace-versioned (currently `0.18.0`):
2153
2237
 
2154
2238
  | Crate | Kind | Description |
2155
2239
  |-------|------|--------------|
@@ -2319,8 +2403,11 @@ than left to be found.
2319
2403
  | Signals and resize for a one-off command | `session.signal()`, `session.resize()` | `wsh host command` forwards SIGINT/SIGTERM/SIGHUP (the same signal twice disconnects); `wsh --tty host command` also forwards terminal resizes | **Wire-unified** (`Signal`, `Resize`). The Rust `wsh-server` delivers `Signal` (#145) to a pty session's foreground process group (what ^C reaches) and to an exec-on-pipes command's own process group, for `HUP INT QUIT TERM KILL USR1 USR2 WINCH CONT STOP TSTP ALRM` (with or without `SIG`); another name is ignored, and only the control attachment of the connection that owns the channel can send one. Not delivered on Windows |
2320
2404
  | Dial target | a URL | `wsh [user@]host` (dials `https://` then `wss://` on `--port`), or a full URL: `wsh wss://host:8443/rendezvous/ab12 command`, `ws://127.0.0.1:PORT/` | **CLI-only convenience**: a URL is dialled exactly as given (no transport fallback; `--port` and `--transport` do not apply). Plain `ws://` is accepted only to a loopback host |
2321
2405
  | Host that runs in a browser page (`createMemoryHost`, `@johnhenry/wsh/reverse`) | yes, with injected `pty` / `fs` / `hostKey` | no (a Rust host is a process) | **JS-only**. A Rust *client* can operate such a host only with `dataStreams: false` (#132): the released Rust client over WebSocket cannot open QMux data streams, and says nothing in `Hello` that a host could use to decide. `wsh scp` works against such a host with the Rust client of the next `rust-v` release (it speaks `FileChunk`, #140); a released `rust-v0.11.0` or older `wsh scp` hangs against it (`wsh ls` and exec work) |
2322
- | A page's WebMCP tools served as MCP, behind a pipe relay (#190) | `createPageHost`, `webmcpTools`, `captureWebMcp` from `@johnhenry/wsh/page`; the far side is `wsh-mcp --sealed` or `openRpc('mcp')` | the far side only: `wsh --sealed --via <relay>/r/<id> mcp user@host` (the Rust CLI, `rust-v0.17.1`+) lists and calls a page host's tools (`test/rust/wsh-mcp-page-host.test.mjs`); the Rust client has no `wsh-objects` client, and no Rust host serves either | **JS-only** host (a page); the far side is unchanged wire (`mcp` rpc in virtual mode, #191) |
2323
- | Remote objects by path, `values` mode (#190): `wsh-objects`, `client.openObjects()` | `exposeObjects` / `createObjectsServer` / `createPageHost({ expose })` host side; `get`, `set`, `call`, `construct`, `snapshot`, `describe` far side (`@johnhenry/wsh/objects`) | none: the Rust client and `wsh-server` do not speak `wsh-objects`, and `wsh-server` has no handler for it | **JS-only**; an rpc protocol on the existing `rpc` channel (no new message or feature string), so a released peer simply does not offer or open it |
2406
+ | A page's WebMCP tools served as MCP, behind a pipe relay (#190) | `createPageHost`, `webmcpTools`, `captureWebMcp` from `@johnhenry/wsh/page`; the far side is `wsh-mcp --sealed` or `openRpc('mcp')` | the far side only: `wsh --sealed --via <relay>/r/<id> mcp user@host` (the Rust CLI, `rust-v0.17.1`+) lists and calls a page host's tools (`test/rust/wsh-mcp-page-host.test.mjs`); the Rust `wsh objects` is a `wsh-objects` client (next row), and no Rust host serves either | **JS-only** host (a page); the far side is unchanged wire (`mcp` rpc in virtual mode, #191) |
2407
+ | Remote objects by path, `values` mode (#190): `wsh-objects`, `client.openObjects()` | `exposeObjects` / `createObjectsServer` / `createPageHost({ expose })` host side; `get`, `set`, `call`, `construct`, `snapshot`, `describe` far side (`@johnhenry/wsh/objects`) | **Client only** (`rust-v0.18.0`, #219): `wsh_client::objects` (`ObjectsClient`, values mode, events with a bounded `Subscription`, handles) and `wsh --sealed [--via RELAY] objects user@host roots\|get\|call\|set\|snapshot\|describe\|watch\|session` (sealed sessions only; JSON on stdout; exit 3 refused, 4 not found, 5 unsupported); a feature the host does not state is refused locally. Not built: callbacks, events through a handle. `wsh-server` serves no `wsh-objects` and refuses an `objects:` key capability. The wire is `spec/objects.md`; tested against a real page host through a recording relay (`test/rust/wsh-objects.test.mjs`) | **JS host, Rust or JS far side**; an rpc protocol on the existing `rpc` channel (no new message or feature string), so a released peer simply does not offer or open it. The Rust codec gained a CBOR-value read path so byte strings survive (the existing `rpc` channels still reject them) |
2408
+ | Events through a handle (#219): `on(use(handle).path, type, listener)` | `@johnhenry/wsh/objects` (`exposeObjects({ handles })`); the host states `handle-events` in the `features` of its `roots` answer | none: no Rust `wsh-objects` client or host | **JS-only**; a new `subscribe` parameter (`handle`) on the existing `wsh-objects` rpc channel, offered only to a client that saw `handle-events`. A 0.50.0 host does not say it, and a new client then refuses to subscribe through a handle with a named `unsupported` error without sending anything; a 0.50.0 client cannot write such a request |
2409
+ | Typed remotes (#219): `describeRootTypes`, `rootDescription`, `Remote<T>`, `wsh-objects-types` | `@johnhenry/wsh/objects` (the `types` method, the `types` option, `Remote<T>`, `RemoteRoots<T>`), `@johnhenry/wsh/objects-types` (the pure generator), the `wsh-objects-types` bin | none: no Rust `wsh-objects` client or host, and the Rust CLI has no equivalent of the bin | **JS-only**; a new `types` method on the existing `wsh-objects` rpc channel and a `types` string in the `features` of its `roots` answer (no new message type or `ServerHello` feature). A 0.50.0 host does not state it, and a new client then refuses with a named `unsupported` error and sends nothing; a 0.50.0 client never calls it |
2410
+ | An MCP face for named object paths (#219): `exposeObjects({ mcp: { tools } })`, `createPageHost({ expose: { ROOT: { mcp: { tools } } } })` | `@johnhenry/wsh/objects` (`handler.mcpTools`, `server.invoke`) served by `webmcpTools` / `serveMcpOverDuplex` on the `mcp` channel; the far side is any MCP client (`wsh-mcp --sealed`, `client.openRpc('mcp')`) | the far side only: `wsh --sealed --via <relay>/r/<id> mcp user@host` lists and calls these tools like any `mcp` tool; no Rust `wsh-objects` host | **JS-only host**; **wire: nothing new** (the existing `mcp` rpc channel and its methods, no feature string), so any released MCP-speaking peer reaches it |
2324
2411
  | Interactive shell UI | none -- this SDK is a protocol client, not a terminal emulator; pair with xterm.js/ghostty-web | `wsh connect`, `wsh sftp` (line-oriented REPL) | **Deliberately not unified** -- a browser embeds a terminal widget the host page owns; a CLI process owns its own TTY |
2325
2412
  | Attach / resume | `attachSession()`, `resumeSession()`, `WshSession.seq` | `attach_session()`, `resume_session()` | **Wire-unified** (`Attach`/`Resume`/`Presence`); `seq` = cumulative output bytes. `@johnhenry/wsh/server` honours `last_seq` (bounded ring, gap errors) and answers Presence with `channel_id`/`seq`; the Rust `wsh-server` does the same (`rust-v0.2.0`+; fixed 256 KiB ring) |
2326
2413
  | Reverse-connect / relay peer | `connectReverse()`, `trustRelayPeer()`; `@johnhenry/wsh/server`: `relay` option and `createReverseHost()` | `wsh reverse`, `wsh agent` (persistent, with startup-unit install) | **Wire-unified** (registration, discovery, signed peer records); **daemonization is CLI-only** -- a browser tab cannot be a background OS service. The Node relay is default-deny and bridges one operator per peer unless `maxOperatorsPerPeer` is raised (`busy:` reasons say so); E2E and bridged feature gates need `rust-v0.3.0`+ on the Rust side. **Several operators per peer (#93): both relays** (`maxOperatorsPerPeer`; `[relay] max_operators_per_peer`, default 1) **and both peers** (`createReverseHost({ maxOperators })`; `wsh --max-operators n reverse` / `agent run`, default 1), negotiated by `relay-multi-operator`; a Rust peer serving several operators does not seal bridges (see the reverse-mode notes), and the Rust relay leaves a peer connected when its operator leaves. The signed `KeyExchange` (`e2e-sign`) is carried by the Rust relay too |
@@ -2341,6 +2428,7 @@ than left to be found.
2341
2428
  | `clientEnv` allow-list (#126) | default `TERM`, `COLORTERM`, `LANG`, `LANGUAGE`, `LC_*` | `wsh-server`: the same default; `[server] client_env = true` (everything, the old behaviour), `false` (nothing) or a list of names / `PREFIX*` (replaces the default) | **Both hosts**; wire unchanged. **Breaking default in the Rust server**, see the CHANGELOG |
2342
2429
  | `authorized_keys` options (#122): `restrict`, `permit-*`, `no-pty`, `command=`, `max-sessions=` | `auth.authorizedKeys` lines with options on `createWshServer` / `createMemoryHost`; `parseAuthorizedKeyEntries()` | `wsh-server` reads `~/.wsh/authorized_keys` (then `~/.ssh/authorized_keys`) | **Same rules and the same vectors on both hosts** (`spec/key-options.vectors.json`, run by the JS suite and a Rust test); an option that is not understood keeps the key out, on both. See [Authorized-key options](#authorized-key-options-122) for the per-host column |
2343
2430
  | Per-key capabilities and expiry (#122): `capabilities="..."`, `expires="..."`; `authorize()` may return a set | every entry the host has: `Open` kinds, `FileOp` read vs write, gateway TCP/UDP/unix/endpoint open and listen, MCP discovery and calls, targets, rpc channels, relay; refusals through `onRefused` (`not-permitted`, `key-expired`) | the same, except **no endpoints and no targets** (`endpoint:` / `target:` parse and grant nothing; such requests are refused); refusals are logged, there is no callback; no `authorize` | **Same grammar, same vectors, same refusal codes on both hosts**; default-deny only for a key whose line has `capabilities`. Neither covers sessions already open, see [Security model](#security-model). The notation is written in `spec/capabilities.md` and its vectors (`spec/capabilities.vectors.json`, `version` 1) ship in the npm package and are run by both; the Rust server's subset is stated by refusal: a key line with an `objects:` capability is refused at load (`unknown-capability`) |
2431
+ | A session over a caller-supplied duplex (#220): `serveWshOverDuplex`, `connectWshOverDuplex` from `@johnhenry/wsh/duplex` | exported, browser-safe; sealed by default | none: the Rust server and client dial a WebSocket, TLS or a pipe relay (a pipe relay carries the same bytes) | **Unified on the wire** (nothing new); the binding is the JS implementation's |
2344
2432
  | `permits(capabilities, request)`, `@johnhenry/wsh/identity` (fingerprint, pod id, OpenSSH line, `authorized_keys` line builder), the `GATEWAY_FAIL` table, `serveMcpOverDuplex`, `createDuplexPeer({ who, permit })` (#220) | exported pure functions and seams of the JS package, browser-safe | none: the Rust server and CLI export no library function of these; the Rust server sends the same `GatewayFail` numbers, with `5` meaning "gateway disabled" where the Node gateway sends it for a timeout | **Notation unified by vectors**; the functions are the JS implementation's and are not a wire feature |
2345
2433
  | Session recording/replay | `SessionRecorder`/`SessionPlayer` (asciicast-v2-shaped JSON) | none | **JS-only** -- no current Rust consumer needs playback; the vocabulary is asciicast v2's, so a Rust port could share it |
2346
2434
  | Self-signed cert pinning | `serverCertificateHashes` (WebTransport option) | `--cert-hash <sha256>` (repeatable) and `ConnectConfig.cert_hash`/`cert_hashes`, with the same rules (SHA-256, ECDSA P-256, at most 14 days); `wsh-server` prints its certificate hash at start-up. Without a pin the certificate is validated against the system trust store; `--insecure-skip-cert-verification` is the development-only opt-out | **Not a wire concept**; a default changed in the Rust client, see the CHANGELOG |
@@ -2398,7 +2486,7 @@ plus one `SHA256SUMS` file covering every archive in the release. These
2398
2486
  names are a stable contract other repos (clawser) pin and download by --
2399
2487
  do not change them without coordinating downstream.
2400
2488
 
2401
- `wsh --version` and `wsh-server --version` print the workspace version the binary was built from (`wsh 0.17.1`), which is the
2489
+ `wsh --version` and `wsh-server --version` print the workspace version the binary was built from (`wsh 0.18.0`), which is the
2402
2490
  number in the `rust-vX.Y.Z` tag. Binaries of `rust-v0.9.0` to `rust-v0.10.0` printed a fixed `0.1.0`, so against one of those the
2403
2491
  version cannot be read from the binary (look for a flag in `wsh --help` instead).
2404
2492
 
@@ -2521,9 +2609,9 @@ out explicitly below rather than left to be discovered.
2521
2609
  a hop that can read the duplex reads every tool result and every value. The capability notation (`spec/capabilities.md`) is a **reading** of a list, not a
2522
2610
  credential: an implementation that reads it more loosely than the vectors say grants more than the list does, which is why the vectors are shipped.
2523
2611
  - **`wsh-objects` (`@johnhenry/wsh/objects`, #190) lets a key read, call and set the paths an allow-list names on the roots a host names, and nothing else.** An allow-list of paths means what it says
2524
- only because nothing but cloneable values crosses (no handles in `values` mode; on a root that opted in to [handles](#handles), a handle is judged by the path that produced it and never widens it, and nodes need their own opt-in); what it cannot make safe is stated in
2612
+ only because nothing but cloneable values crosses (no handles in `values` mode; on a root that opted in to [handles](#handles), a handle is judged by the path that produced it and never widens it, and nodes need their own opt-in; an event subscription through a handle needs the producing path's own `allow.on` entry and ends with the handle); what it cannot make safe is stated in
2525
2613
  [Remote objects](#remote-objects-johnhenrywshobjects-190): a getter or a setter on an allowed path runs, a called function does whatever it does with the page's authority, a wide pattern means its width, and a
2526
- few paths (`document.cookie`, storage, `fetch`, ...) need an entry that names them. Object access is off on every host unless `exposeObjects` or `createPageHost({ expose })` is written, and `rpc:wsh-objects` is the key capability that gates it.
2614
+ few paths (`document.cookie`, storage, `fetch`, ...) need an entry that names them. The generated types (#219) are advisory text: the host's type map is host-authored text that is checked, bounded and never evaluated (see [Typed remotes](#typed-remotes-219)), and the file says only what the fetching key may do. The MCP face for named paths (#219) is the allow-list **plus** a list of the paths that are tools, **plus** the WebMCP bridge's approval for any tool not marked read-only: a tool needs the key's `mcp:TOOL` and `objects:ROOT:OP`, its arguments are validated before the person is asked, its results are labelled untrusted, and it makes no handle, event or callback; a called function still does whatever it does with the page's authority. Object access is off on every host unless `exposeObjects` or `createPageHost({ expose })` is written, and `rpc:wsh-objects` is the key capability that gates it.
2527
2615
  - **`wsh-mcp` runs as a client with your key (#127).** It reads a private key file you point it at (no passphrase support: protect the
2528
2616
  file, `0600`), logs in as you and hands the MCP client everything the host's `mcp` channel serves; whatever the MCP client (or the
2529
2617
  model behind it) asks of those tools is done as you. It does not pin the host unless you pass `--host-key` (it warns once on stderr),
@@ -2875,6 +2963,37 @@ browsermesh** (a test of the pod id derivation uses `@johnhenry/browsermesh-prim
2875
2963
  `serveMcpOverDuplex` for MCP, the identity object `{ username, fingerprint, podId }`, and `permits()` of the
2876
2964
  [capability notation](#identity-and-capabilities-for-other-implementations-220), which the mesh's own grants run the same vectors against.
2877
2965
 
2966
+ #### wsh over a duplex (#220)
2967
+
2968
+ `@johnhenry/wsh/duplex` runs a whole wsh session (login, host-key proof, sealed session, channels) over a duplex of messages that another library
2969
+ provides, so a browser with no relay can be reached by hopping through a mesh peer, and a pod can reach a wsh host without a relay. The transport
2970
+ is the one wsh already runs over a WebSocket; `createDuplexSocket` is a WebSocket-shaped object whose messages are the duplex's.
2971
+
2972
+ ```js
2973
+ // host (a page, a pod): a host with a host key
2974
+ const host = createMemoryHost({ auth: { authorizedKeys }, hostKey: true, dataStreams: false, exec });
2975
+ const served = serveWshOverDuplex(host, { send: (bytes) => channel.send(bytes) });
2976
+ channel.onmessage = (bytes) => served.receive(bytes);
2977
+ // client: it names the host key it expects (over a mesh: podIdToFingerprint(peerPodId))
2978
+ const link = connectWshOverDuplex({ send: (bytes) => channel.send(bytes) }, { username, keyPair, expectHostKey });
2979
+ channel.onmessage = (bytes) => link.receive(bytes);
2980
+ const client = await link.connected;
2981
+ ```
2982
+
2983
+ **The duplex must** deliver messages of bytes reliably and in order, with a maximum size both ends know (`maxMessageBytes`, default 64 KiB; a larger
2984
+ write is cut, a larger incoming message ends the link), and apply backpressure by `send` returning a promise (what waits is bounded by
2985
+ `maxBufferedBytes`, default 4 MiB). One duplex carries one session. The full statement is [`spec/duplex-binding.md`](spec/duplex-binding.md).
2986
+
2987
+ **Channel binding here is not TLS's.** There is none of `cert-hash` or `tls-exporter`. The authentication is carried by the host-key proof (the client
2988
+ compares the key with the one it named), the login bound to that key (`requireChannelBinding: ['host']`, the default) and the sealed session. So a hop on
2989
+ the duplex cannot read or change a command, an output or a credential after login, cannot replay one, and cannot answer as the host to a client that named
2990
+ its key. It can see that a session exists, its timing and sizes, and the plain handshake (the host key, the username, the client's public key); it can
2991
+ drop or delay (the session stalls) or end the link. It is **not** protected against: a client that does not name the host key (`trustOnFirstUse: true` is
2992
+ said out loud: the first answer is trusted), a **password** login (sent before the seal; refused unless `allowUnsealed: true`), or what the host's own
2993
+ `auth` and capabilities allow. **Unsealed is refused by default**: the host serves a duplex only sealed (it needs a host key; `sealSession: 'require'`
2994
+ can now be asked of one connection, `host.accept(socket, { sealSession: 'require' })`, and only strengthens the host's setting), and the client
2995
+ refuses a host that cannot seal. `allowUnsealed: true` on either lifts it, and then a hop can read and change everything.
2996
+
2878
2997
  **What is deliberately not shared**
2879
2998
 
2880
2999
  - **Sealing.** A wsh session is sealed once, after a signed key exchange, and everything after login travels in authenticated frames; the
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env node
2
+ // wsh-objects-types (#219): connect to a wsh host that serves `wsh-objects` (a page host behind a relay, any host with `exposeObjects`), ask what THIS key may do on one
3
+ // root, and write the TypeScript declarations for it. JavaScript only: the Rust CLI has no `wsh-objects` client. Nothing is evaluated: the host's type texts are checked and
4
+ // copied, and the file is written only when --out is given.
5
+
6
+ import { parseArgs } from 'node:util';
7
+ import { createRequire } from 'node:module';
8
+ import { userInfo } from 'node:os';
9
+ import { writeFile } from 'node:fs/promises';
10
+ import { loadIdentity, defaultIdentityPath, McpBridgeError } from '../src/mcp-stdio.mjs';
11
+ import { WshClient } from '../src/index.mjs';
12
+ import { openObjects, rootDescription } from '../src/objects.mjs';
13
+ import { describeRootTypes } from '../src/objects-types.mjs';
14
+
15
+ const { version } = createRequire(import.meta.url)('../package.json');
16
+
17
+ const HELP = `wsh-objects-types ${version} -- the TypeScript types of a root of wsh-objects, for what this key may do
18
+
19
+ Usage: wsh-objects-types [options] [user@]<url>
20
+
21
+ <url> ws://, wss:// or https:// URL of the wsh host (a host serving the rpc channel "wsh-objects"; a page host: its operator URL)
22
+ -l, --user NAME login name (default: the user@ part of the URL, else $WSH_USER, $USER, or the OS user)
23
+ -i, --identity FILE Ed25519 private key (default: ~/.wsh/keys/default.pem, the key \`wsh keygen\` makes)
24
+ --root NAME the root to describe (default: the only one the key may use; required when there are several)
25
+ --name TYPE the name of the exported type (default: the root's name, capitalised, plus Remote)
26
+ -o, --out FILE write the declarations to FILE (default: standard output). An existing file is not overwritten without --force
27
+ --force overwrite --out
28
+ --sealed seal the whole session end to end and refuse a host that cannot (a host behind a relay, a page); key login only
29
+ --host-key KEY pin the host: a hex fingerprint, or an ssh-ed25519 line (default: not pinned, with a warning)
30
+ --timeout MS to log in and to open the channel (default: 15000)
31
+ -h, --help this text
32
+ -V, --version
33
+
34
+ The declarations say only what the key that connected may do (the host's allow-lists narrowed by that key's capabilities); values are \`unknown\` unless the host
35
+ supplied a type, which is checked and copied as text, never evaluated. Use it as: client.openObjects<{ window: WindowRemote }>().
36
+ Exit status: 0 written, 2 it could not be done.
37
+ `;
38
+
39
+ const fail = (message) => { process.stderr.write(`wsh-objects-types: ${message}\n`); process.exit(2); };
40
+
41
+ let parsed;
42
+ try {
43
+ parsed = parseArgs({
44
+ allowPositionals: true,
45
+ options: {
46
+ user: { type: 'string', short: 'l' },
47
+ identity: { type: 'string', short: 'i' },
48
+ root: { type: 'string' },
49
+ name: { type: 'string' },
50
+ out: { type: 'string', short: 'o' },
51
+ force: { type: 'boolean' },
52
+ sealed: { type: 'boolean' },
53
+ 'host-key': { type: 'string' },
54
+ timeout: { type: 'string' },
55
+ help: { type: 'boolean', short: 'h' },
56
+ version: { type: 'boolean', short: 'V' },
57
+ },
58
+ });
59
+ } catch (e) { fail(`${e.message}\nTry \`wsh-objects-types --help\`.`); }
60
+ const { values, positionals } = parsed;
61
+ if (values.help) { process.stdout.write(HELP); process.exit(0); }
62
+ if (values.version) { process.stdout.write(`${version}\n`); process.exit(0); }
63
+ if (positionals.length !== 1) fail('exactly one host URL is required. Try `wsh-objects-types --help`.');
64
+
65
+ let url = positionals[0];
66
+ let userFromUrl;
67
+ const at = url.indexOf('@');
68
+ if (at > 0 && !url.slice(0, at).includes('/') && !url.slice(0, at).includes(':')) { userFromUrl = url.slice(0, at); url = url.slice(at + 1); }
69
+ if (!/^(wss?|https?):\/\//.test(url)) fail(`${url}: expected a ws://, wss:// or https:// URL`);
70
+ const timeout = values.timeout === undefined ? 15_000 : Number(values.timeout);
71
+ if (!Number.isInteger(timeout) || timeout < 1) fail('--timeout must be a whole number of at least 1');
72
+ const username = values.user ?? userFromUrl ?? process.env.WSH_USER ?? process.env.USER ?? userInfo().username;
73
+
74
+ const client = new WshClient();
75
+ let code = 0;
76
+ try {
77
+ let signer;
78
+ try { signer = await loadIdentity(values.identity ?? defaultIdentityPath()); } catch (e) { throw e instanceof McpBridgeError ? e : new Error(e?.message ?? String(e)); }
79
+ await client.connect(url, { username, signer, timeout, ...(values['host-key'] ? { expectHostKey: values['host-key'] } : {}), ...(values.sealed ? { sealSession: true } : {}) });
80
+ const page = await openObjects(client);
81
+ const roots = Object.keys(page);
82
+ if (roots.length === 0) throw new Error('this key may use no root of the host');
83
+ const root = values.root ?? (roots.length === 1 ? roots[0] : undefined);
84
+ if (root === undefined) throw new Error(`the host has several roots the key may use (${roots.join(', ')}): choose one with --root`);
85
+ if (!roots.includes(root)) throw new Error(`no root ${JSON.stringify(root)} that this key may use (${roots.join(', ')})`);
86
+ const text = describeRootTypes(await rootDescription(page[root]), values.name === undefined ? {} : { name: values.name });
87
+ if (values.out === undefined) process.stdout.write(text);
88
+ else {
89
+ await writeFile(values.out, text, { flag: values.force ? 'w' : 'wx', mode: 0o644 });
90
+ process.stderr.write(`wsh-objects-types: wrote ${values.out}\n`);
91
+ }
92
+ } catch (e) {
93
+ process.stderr.write(`wsh-objects-types: ${e?.code === 'EEXIST' ? `${values.out} exists (--force overwrites it)` : (e?.message ?? e)}\n`);
94
+ code = 2;
95
+ } finally {
96
+ await client.disconnect().catch(() => {});
97
+ }
98
+ process.exit(code);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnhenry/wsh",
3
- "version": "0.49.0",
3
+ "version": "0.51.0",
4
4
  "description": "Web Shell \u2014 browser-native remote command execution over WebTransport and WebSocket with Ed25519 authentication",
5
5
  "type": "module",
6
6
  "main": "./src/index.mjs",
@@ -37,6 +37,10 @@
37
37
  "types": "./src/objects.d.ts",
38
38
  "import": "./src/objects.mjs"
39
39
  },
40
+ "./objects-types": {
41
+ "types": "./src/objects-types.d.ts",
42
+ "import": "./src/objects-types.mjs"
43
+ },
40
44
  "./testing": {
41
45
  "types": "./src/testing.d.ts",
42
46
  "import": "./src/testing.mjs"
@@ -49,6 +53,10 @@
49
53
  "types": "./src/capabilities.d.ts",
50
54
  "import": "./src/capabilities.mjs"
51
55
  },
56
+ "./duplex": {
57
+ "types": "./src/duplex.d.ts",
58
+ "import": "./src/duplex.mjs"
59
+ },
52
60
  "./identity": {
53
61
  "types": "./src/identity.d.ts",
54
62
  "import": "./src/identity.mjs"
@@ -58,7 +66,8 @@
58
66
  "./spec/wsh-v1.yaml": "./spec/wsh-v1.yaml"
59
67
  },
60
68
  "bin": {
61
- "wsh-mcp": "./bin/wsh-mcp.mjs"
69
+ "wsh-mcp": "./bin/wsh-mcp.mjs",
70
+ "wsh-objects-types": "./bin/wsh-objects-types.mjs"
62
71
  },
63
72
  "sideEffects": false,
64
73
  "types": "./src/index.d.ts",
@@ -96,6 +96,7 @@ A request is an object with a `kind`. The capability needed (the name a refusal
96
96
  | `{ kind: 'open', channel: 'rpc', protocol: 'mcp' }` | `mcp:*` (an `mcp:TOOL` key opens it only through a handler that narrows by tool itself, `scoped: true`) |
97
97
  | `{ kind: 'open', channel: 'rpc', protocol: 'wsh-objects', scoped: true }` | `rpc:wsh-objects` or any `objects:` entry |
98
98
  | `{ kind: 'open', channel: 'rpc', protocol: P }` | `rpc:P` |
99
+ | `{ kind: 'open', channel: 'rpc', protocol: P, authorizesItself: true }` | nothing from the list: a handler that asks the host's own `permits` for every call (`handler.authorizesItself = true`) is opened by any key the options and expiry let in; its own checks decide |
99
100
  | `{ kind: 'file-op', op }` | `fs:read` for `stat`, `list`, `read`; `fs:write` for every other `op` |
100
101
  | `{ kind: 'mcp' }` (discovery) | any `mcp:` entry |
101
102
  | `{ kind: 'mcp-call' | 'mcp-tool', tool }` | `mcp:TOOL` or `mcp:*` |
@@ -0,0 +1,86 @@
1
+ # wsh over a caller-supplied duplex
2
+
3
+ Status: implemented in `@johnhenry/wsh/duplex` (`createDuplexSocket`, `serveWshOverDuplex`, `connectWshOverDuplex`). Nothing is added to the wire.
4
+
5
+ ## What this is for
6
+
7
+ A full wsh session (login, host-key proof, the sealed session, channels) over a duplex of messages that another library provides: a browsermesh
8
+ channel between two pods, a `MessagePort`, a data channel. Two things it makes possible: a browser with no relay can be reached by hopping
9
+ through a mesh peer, and a pod can reach a wsh host without a relay. wsh knows nothing of the library that provides the duplex.
10
+
11
+ ## What already existed, and what this adds
12
+
13
+ The transport wsh runs over a WebSocket is QMux records on a stream of binary messages (`src/transport-ws.mjs`), and a host serves any
14
+ WebSocket-shaped object it is handed (`host.accept(socket)`, `bindSocket`). So the session needs no new protocol: only a WebSocket-shaped object
15
+ whose messages are the duplex's. That is `createDuplexSocket`. The rest is policy, because a duplex somebody else carries is not a TLS connection:
16
+
17
+ - the session over it is **sealed** unless said otherwise (the host serves nothing until it is; the client refuses a host that cannot);
18
+ - the client must **name the host key** it expects;
19
+ - `sealSession: 'require'` can now be asked for per connection (`bindSocket(..., { sealSession: 'require' })`, `host.accept(socket, { sealSession: 'require' })`):
20
+ it can only strengthen the host's own setting, and a host that cannot seal (no host key, or data streams) refuses to attach the connection at all.
21
+
22
+ ## What the duplex must guarantee
23
+
24
+ 1. **Reliable, in order, no duplicates.** The bytes of a QMux record and of a sealed frame arrive in the order sent, none lost, none twice. (A
25
+ hop may do worse; see below: what it can do is limited to ending or stalling the session, not changing it.)
26
+ 2. **Messages of bytes.** Each message is a `Uint8Array` / `ArrayBuffer`. Text is refused (the link ends).
27
+ 3. **A maximum message size** that both ends know (`maxMessageBytes`, default 64 KiB). A write larger than it is cut into messages of at most
28
+ that size and a message larger than it ends the link. Where the cuts fall does not matter: the transport above reads a byte stream and
29
+ reassembles records. (A mesh channel with a smaller limit sets it smaller; a pipe relay carries 4 MiB.)
30
+ 4. **Backpressure by a returned promise.** `send` may be asynchronous; the next message is not written until it settles, and what waits is bounded
31
+ (`maxBufferedBytes`, default 4 MiB): over it the link is ended rather than buffered without bound. A `send` that throws or rejects ends the link.
32
+ Inbound, what arrives before anyone listens is held, bounded by the same figure.
33
+ 5. **One connection per duplex.** A duplex carries one session. When it ends (the peer left, the channel closed) the caller calls `end()`; when
34
+ the session ends it calls the duplex's `close`.
35
+ 6. **Open before use.** The host speaks first (its transport handshake). The caller must have wired `receive` before the far side can send, or hold
36
+ what arrives until it has: a message for an end that does not exist yet is the caller's to keep (a mesh adapter has the channel before the client).
37
+
38
+ Ordering matters more than delivery: a duplex that reorders, or repeats, a record corrupts the byte stream and the session ends; one that drops
39
+ a message stalls it until a timeout. Neither lets anything through that was not sent.
40
+
41
+ ## Channel binding: what there is, and what there is not
42
+
43
+ There is **no TLS** on this transport, so there is no `cert-hash` and no `tls-exporter` binding to the connection. What carries the
44
+ authentication instead:
45
+
46
+ - **The host-key proof.** The host signs a challenge that names this session and the client's nonce with its host key; the client checks the
47
+ signature and compares the key with the one it expects (`expectHostKey`, or a `known_hosts` entry; over a mesh, the peer's pod id is the key's hash,
48
+ so `expectHostKey: podIdToFingerprint(peer)`). A hop that answers as the host would have to hold that key.
49
+ - **The login bound to the host key.** `requireChannelBinding: ['host']` (the one binding a memory host has): the client's signature covers the host
50
+ key it proved, so a hop that relays a genuine login to a different host, or the host's challenge to a different client, produces a signature
51
+ the real host rejects. This is the default of `connectWshOverDuplex`.
52
+ - **The sealed session.** After login a signed key exchange (X25519 and ML-KEM-768, both halves signed by the login key and the host key) keys an
53
+ authenticated encryption of every message but the keepalive, with a role tag and a counter: a frame that does not open ends the session, a
54
+ replayed, reflected or reordered one does not open, and an unsealed message after sealing is dropped.
55
+
56
+ ## What a hop on the duplex can and cannot do
57
+
58
+ It **cannot**: read a command, an output, a file, a credential, a tool call or an object value after login; change one without the session
59
+ ending (or the message being dropped: nothing altered is delivered); replay a message so that it runs twice; log in as the client or serve as the
60
+ host to a client that named the host key; make a client that required sealing talk unsealed, or make a host that requires it serve a plain client.
61
+
62
+ It **can**: see that a session exists, when it starts and ends, and the size and timing of messages; drop or delay messages (the session
63
+ stalls; there is no integrity of availability); end the link; refuse to carry it. It reads the **handshake**, which is plain before the seal: the
64
+ host's key (public), the client's username, the client's public key and the features each side states.
65
+
66
+ It is **not protected against**: a client that does not name the host key (it trusts the first host that answers, `trustOnFirstUse: true`,
67
+ said out loud, and that is the one moment a hop can answer as the host); a **password** login (the password is sent before the session is sealed,
68
+ so `connectWshOverDuplex` refuses one unless `allowUnsealed: true`); the host's own configuration (what the key may do is the host's `auth`,
69
+ capabilities and allow-lists, not the duplex's); an endpoint that is itself hostile (sealing protects from the hop, not from the peer).
70
+
71
+ ## Unsealed
72
+
73
+ `allowUnsealed: true` on either function lifts the seal requirement and the default binding. Nothing a hop does is then caught: it can read and change
74
+ everything. It is for a duplex that is already protected by something else, and it is said in the call.
75
+
76
+ ## Not covered here
77
+
78
+ Discovery, and who the peer is (the mesh's business: it must give the key to expect); relaying through several hops (each hop is another
79
+ duplex, and the session is end to end); reconnecting a session over a new duplex (a `resume` of an exec session works as over any connection;
80
+ the duplex itself is one connection).
81
+
82
+ ## Compatibility
83
+
84
+ No message, field or feature string is new. A released peer on the other end of a duplex is an ordinary wsh peer: a 0.48.0 client or host
85
+ interoperates (it seals as it always did); the Rust client and server are not bound to a duplex by this change (the Rust CLI dials a pipe
86
+ relay, which carries bytes the same way, with `--via`, and `wsh --sealed`).