@johnhenry/wsh 0.50.0 → 0.52.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
@@ -386,8 +386,11 @@ The notation above is written down once, as a specification, with vectors that a
386
386
  capabilities the notation knows, a timestamp it can read, no control character or line break in the comment, a plain Ed25519
387
387
  key, and it reads its own line back through a host's parser before returning it.
388
388
  - **The gateway error table** is data too: `GATEWAY_FAIL`, `GATEWAY_FAIL_TABLE` and `gatewayFailName(code)` are exported from the
389
- package root (`@johnhenry/browsermesh-netway` decodes the same numbers). The table notes that the Rust server sends `5` for a
390
- disabled gateway where the Node gateway sends it for a timeout.
389
+ package root (`@johnhenry/browsermesh-netway` decodes the same numbers; the vectors are `spec/gateway-fail.vectors.json`). `5` is
390
+ `GATEWAY_DISABLED` (the spec and the Rust server) and `TIMEOUT` is `8` (#223). A Node gateway of 0.51.0 or earlier sent `5` for a timeout,
391
+ so a reader keeps treating a `5` as "the gateway is disabled, or a timeout from an older Node gateway": `GATEWAY_FAIL_TABLE` and the
392
+ message of a `GatewayError` that carries `5` say both. A new Node gateway sends `8` for a timeout, so a client written for the
393
+ old number (`code === 5` meaning a timeout) must also accept `8`.
391
394
  - **For the object and MCP layers**: the identity handed to `authorize(who, op)` is `{ username, fingerprint, podId? }`.
392
395
  `fingerprint` is always the hex hash of the caller's key; `podId` is there when the transport knows the caller by one. A
393
396
  transport that is not wsh gives an identity object (`createDuplexPeer({ send, who: { podId } })`, or `attach(peer, { who })`)
@@ -667,6 +670,7 @@ bundler drop what you do not use.
667
670
  | `@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
671
  | `@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
672
  | `@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) |
673
+ | `@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) |
670
674
  | `@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 |
671
675
  | `@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 |
672
676
  | `@johnhenry/wsh/server` | Node only |
@@ -698,8 +702,9 @@ optional ML-KEM backend, is left out of the measurement. What a page ships is wh
698
702
  | `@johnhenry/wsh/reverse` (whole entry point) | 221.7 kB | 68.6 kB |
699
703
  | `@johnhenry/wsh/pipe-relay` (whole entry point) | 7.0 kB | 3.0 kB |
700
704
  | `@johnhenry/wsh/testing` (whole entry point) | 241.2 kB | 76.0 kB |
701
- | `@johnhenry/wsh/page` (whole entry point) | 302.4 kB | 96.0 kB |
702
- | `@johnhenry/wsh/objects` (whole entry point) | 177.4 kB | 54.4 kB |
705
+ | `@johnhenry/wsh/page` (whole entry point) | 327.0 kB | 104.1 kB |
706
+ | `@johnhenry/wsh/objects` (whole entry point) | 201.5 kB | 62.0 kB |
707
+ | `@johnhenry/wsh/objects-types` (whole entry point) | 10.2 kB | 4.2 kB |
703
708
  | `@johnhenry/wsh/capabilities` (whole entry point) | 10.6 kB | 3.8 kB |
704
709
  | `@johnhenry/wsh/identity` (whole entry point) | 15.7 kB | 5.7 kB |
705
710
  | `@johnhenry/wsh/duplex` (whole entry point) | 140.1 kB | 42.4 kB |
@@ -752,6 +757,34 @@ On the far side nothing new is needed: `wsh-mcp --sealed --host-key <host.finger
752
757
  server any MCP client can launch, and in code `client.connect(host.operatorUrl, { keyPair, sealSession: true })` then
753
758
  `client.openRpc('mcp')`. The host serves one operator at a time and dials the relay again when a session ends.
754
759
 
760
+ **The dial-out form (`connect`, #219), off unless written.** For an operator that *listens* (a process of yours that accepts connections), the page can dial it itself
761
+ instead of waiting behind a relay: `createPageHost({ window, connect: 'wss://operator.example/pages/shop', name, authorizedKeys, mcp, expose })` (not together with `relay`;
762
+ there is no `operatorUrl` and no rendezvous id, both are `null`). The URL is dialled **exactly as written** (no role or rendezvous id is added), must be `ws://` or `wss://` with
763
+ no user name, password or fragment in it, and is **never logged** (its query may hold a secret). Everything after the socket opens is what it is behind a relay: key login only
764
+ (`authorizedKeys`), a sealed session, `onSession`, the person's approval for consequential tools, the visible indicator and **Stop** (which also refuses that key), the
765
+ `mcp` and `wsh-objects` channels, closing when the window leaves its origin, and dialling again after a session or a failed attempt (`reconnect`, with the same backoff). The operator
766
+ is the wsh *client* on what it accepts, for example in Node:
767
+
768
+ ```js
769
+ import { WebSocketServer } from 'ws';
770
+ import { connectWshOverDuplex } from '@johnhenry/wsh/duplex';
771
+
772
+ new WebSocketServer({ port: 9000 }).on('connection', (ws) => {
773
+ const link = connectWshOverDuplex({ send: (bytes) => ws.send(bytes), close: () => ws.close(1000) },
774
+ { username: 'alice', keyPair, expectHostKey: pageHostFingerprint }); // the page shows host.fingerprint; the login is sealed and bound to it
775
+ ws.on('message', (data) => link.receive(data));
776
+ ws.on('close', () => link.end('the page left'));
777
+ link.connected.then((client) => client.openRpc('mcp'));
778
+ });
779
+ ```
780
+
781
+ What the form changes: **nothing sits between the page and the operator**, so there is no relay to see ciphertext (the sealed session still hides the traffic from a hop you did not
782
+ choose, such as a proxy), and **the page chooses whom to dial**: whoever answers at that URL learns the page's host key and what its handshake states before any key logs in, and can
783
+ only try to log in (a key that is not in `authorizedKeys`, or whose `capabilities` do not allow it, gets nothing). What it does **not** protect against: a URL that points at the wrong
784
+ listener is not noticed by the page (the operator must pin the page's host key, and the page does not pin the operator: it authenticates keys, not endpoints); a page that
785
+ is told to dial by code you did not write dials; the page redials the URL for as long as the host is open, so a listener that wants a quiet period must say no at login, or the host be
786
+ closed. Browser pages can dial `wss://` endpoints their content security policy allows (`connect-src`), and not `ws://` from an `https:` page.
787
+
755
788
  **`window` is explicit.** `createPageHost`, `webmcpTools` and `captureWebMcp` read nothing but the object they are given: where tools are
756
789
  registered (`window.document.modelContext`, the older `window.navigator.modelContext`), where the indicator is drawn
757
790
  (`window.document`), which `WebSocket` dials the relay, and whose origin is reported. A test greps the entry point's source for
@@ -934,10 +967,16 @@ await release(cart); // gives its place back; everything
934
967
  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.
935
968
  - **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).
936
969
  - **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
937
- 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.
970
+ 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).
971
+ - **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
972
+ 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
973
+ 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
974
+ 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.
975
+ The delivery is the same too: plain copies, never the event, never a handle.
938
976
 
939
- 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);
940
- 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.
977
+ A host says what it supports with its roots (`features`: `events`, `callbacks`, `callback-returns` when an entry lets a callback return a value, `types`, 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
978
+ a handle on one that has not said `handle-events` (0.50.0 and before; a named `unsupported` error, nothing is sent);
979
+ 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.
941
980
 
942
981
  #### Callbacks
943
982
 
@@ -949,7 +988,14 @@ await win.app.subscribe((event) => console.log(event.n)); // the page's subscr
949
988
  await release(fn); // kills the stub (also: the channel ending)
950
989
  ```
951
990
 
952
- - **One-way.** The stub copies its arguments, queues a notification and **returns `undefined` at once**: the page cannot be made to wait for the far side, and the far side's return value is not delivered back (a notation to ask for it is not built).
991
+ - **One-way.** The stub copies its arguments, queues a notification and **returns `undefined` at once**: the page cannot be made to wait for the far side, and the far side's return value is not delivered back. That is the rule for every entry that says only `(callback)`. The next bullet is the one way to get a value back, and only where the host wrote it.
992
+ - **Callback return values (#219), off unless the host opts in per entry.** An entry that ends in `(callback:returns)` (every function the call takes may answer) or `(callback:returns=0,2)` (only the functions at those argument positions; the others stay one-way) makes that stub return a **promise** of what the far side's function returned: `const ok = await stub(question)`. The page is never blocked and never waits unboundedly:
993
+ - **The wait is bounded by the host**, from the call (queueing included): `limits.callbackReturnTimeoutMs`, 2000 by default and **at most 30000** (a larger value is a `TypeError` when the host is created). The host needs `timers` (`exposeObjects` and `createPageHost` supply them; `createObjectsServer` without `timers` and a returning entry is a `TypeError`).
994
+ - **Every case that is not an answer is `undefined`**, and the promise **never rejects**: the timeout, an error thrown by the far side's function (its text stays on the far side, where `onCallbackError` gets it), a result that is not plain data (a function, a handle) or larger than `maxCallbackResultBytes` (16384), a call over the rate or size bound, a table that is full (`maxPendingCallbackReturns`, 8 calls waiting per channel, at most 64: the call is dropped, counted and **not sent**), a released callback, the end of the channel (Stop, a navigation, a revoke settle every waiting call with `undefined` at once and take the timers away), and a far side that did not say it can answer. So treat `undefined` as "no answer": a function that returns `undefined` is indistinguishable from a timeout, and code that asks "may I?" must treat anything but an explicit `true` as no.
995
+ - **The value is plain data**, copied under the same rules as an argument (`maxDepth` 4, bytes, bytes arrays, no function, no handle, never an object with a prototype), and the page is handed the copy. A late answer after the timeout is ignored. An answer is for a request id the host gave on this channel, once; an answer for an id nobody waits for is counted against the request rate and changes nothing else.
996
+ - **A far side that is slow or hostile can make the page wait at most `callbackReturnTimeoutMs` per call and at most `maxPendingCallbackReturns` calls at a time**; it cannot make the page wait for anything else. `host.callbackReturnStats()` (on what `attach` returns) says how many calls are `pending` and how many were `answered`, `timedOut`, `failed`, `refused` or `dropped`.
997
+ - **Negotiation.** A host states `callback-returns` in the `features` of its `roots` answer only when an entry says it; a client says it answers by listing `callback-returns` in the `features` of its `roots` request. A host that has not been told never asks (the stub resolves `undefined` at once and the callback is delivered one-way), so a 0.51.0 client against a new host neither waits nor breaks, and a new client against a 0.51.0 host sends one extra optional field that it ignores. The `types` a host sends tell an entry as `(callback)` so a 0.51.0 client reads them; the generated types do not describe a returned value.
998
+ - **What it does not do.** It does not make the answer true or safe: whatever the far side returns is data from the person or program on the other end, and the page's code that acts on it (`if (await ask())`) is what to write defensively. It adds no other direction: the far side still cannot call into the page except through the entries the host listed.
953
999
  - **Plain values only.** The arguments are copied under the same rules as a result: plain data and bytes; what cannot be cloned (a function, a node, a class instance, a date) is `null`; never a handle.
954
1000
  - **Bounds.** `maxCallbacks` (16 per channel, refused by name), `maxCallbacksPerSecond` (20 per callback), `maxCallbackBytes` (16384 per call); a call over the rate, the size or the shared queue (`maxQueuedEvents`) is dropped and counted, and the next delivered call is preceded by
955
1001
  `onCallbackDropped({ dropped })` on the client. The notifications go through the channel's credit like events. The same function sent again is the same callback.
@@ -957,6 +1003,34 @@ await release(fn); // kills the stub (a
957
1003
  - 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
958
1004
  stub the page will use for what the caller should see.
959
1005
 
1006
+ #### An MCP face for allow-listed paths (#219)
1007
+
1008
+ 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:
1009
+
1010
+ ```js
1011
+ const handler = exposeObjects({
1012
+ roots: { window }, allow: { get: ['window.document.title'], call: ['window.app.cart.add', 'window.app.cart.clearAll'] },
1013
+ mcp: { tools: [
1014
+ { name: 'cart_add', description: 'Add a product to the cart', call: 'window.app.cart.add',
1015
+ inputSchema: { type: 'object', properties: { sku: { type: 'string', minLength: 1 }, qty: { type: 'integer', minimum: 1 } }, required: ['sku'], additionalProperties: false } },
1016
+ { name: 'page_title', description: 'The title of the page', get: 'window.document.title' },
1017
+ ] },
1018
+ }); // clearAll is allowed by call and is NOT a tool: nothing is a tool by being allowed
1019
+ const mcp = webmcpTools({ window, tools: handler.mcpTools, allow: handler.mcpToolNames }); // createPageHost does this itself; any host with `rpc: { mcp }` or serveMcpOverDuplex can
1020
+ ```
1021
+
1022
+ - **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
1023
+ 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.
1024
+ 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).
1025
+ - **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
1026
+ (`$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.
1027
+ - **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.
1028
+ `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.
1029
+ - **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.
1030
+ 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.**
1031
+ - **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,
1032
+ but a Rust `wsh --sealed --via ... mcp` reaches a page host's `mcp` channel and so lists and calls these tools like any others.
1033
+
960
1034
  **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
961
1035
  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**.
962
1036
 
@@ -975,9 +1049,35 @@ reach is exactly the paths the lists name (and, below a `get`, the plain data in
975
1049
  written by third parties.
976
1050
  - 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.
977
1051
 
978
- 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
979
- 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).
980
- Not built yet (later steps of #190): typed remotes (`Remote<T>`), an MCP face for the allow-listed paths, and a dial-out form.
1052
+ 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).
1053
+ A dial-out form of the page host (`createPageHost({ connect })`, an operator that listens) is described under [A page as a host](#a-page-as-a-host-johnhenrywshpage-190).
1054
+
1055
+ #### Typed remotes (#219)
1056
+
1057
+ `@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:
1058
+
1059
+ 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:
1060
+ `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`
1061
+ (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)`.
1062
+ 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`
1063
+ (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,
1064
+ 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()`),
1065
+ 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 }`),
1066
+ and an entry in `allow.set` makes `set(ref, key, value)` check the key. Use it as `client.openObjects<{ window: WindowRemote }>()`.
1067
+ 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 }' } } })`
1068
+ (`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<{ ... }>`.
1069
+
1070
+ **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
1071
+ 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).
1072
+ 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
1073
+ 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.
1074
+
1075
+ **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
1076
+ 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:
1077
+ 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.
1078
+
1079
+ **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`.
1080
+ The Rust `wsh --sealed [--via RELAY] objects user@host types ROOT` (`rust-v0.19.0`) asks the same question and prints the description as JSON (`wsh_client::objects::ObjectsClient::root_description`); it has no generator for `.d.ts` text. 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.
981
1081
 
982
1082
  ### WebTransport listener
983
1083
 
@@ -1648,6 +1748,29 @@ wsh-host` works (it is the same rpc channel, and a handy check). `wsh mcp` follo
1648
1748
  `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
1649
1749
  been run against WebSocket hosts.
1650
1750
 
1751
+ **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**:
1752
+
1753
+ ```
1754
+ wsh --sealed [--via RELAY] objects user@host roots
1755
+ wsh --sealed [--via RELAY] objects user@host get window.document.title
1756
+ wsh --sealed [--via RELAY] objects user@host call window.app.cart.add '{"sku":"A1"}' 2 # each argument is one JSON value
1757
+ wsh --sealed [--via RELAY] objects user@host set window.app.n 5
1758
+ wsh --sealed [--via RELAY] objects user@host snapshot window.app.state --depth 3
1759
+ wsh --sealed [--via RELAY] objects user@host describe window.app
1760
+ wsh --sealed [--via RELAY] objects user@host watch window.app.bus@ready --field detail --count 3
1761
+ wsh --sealed [--via RELAY] objects user@host types window # what this key may do on the root, as the host describes it (needs the host to state `types`)
1762
+ wsh --sealed [--via RELAY] objects user@host session # JSON requests on stdin, one answer line each: one connection, so a handle, a subscription or a callback can be held across calls
1763
+ ```
1764
+
1765
+ 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).
1766
+ **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.
1767
+ 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` / `handle-events` / `callbacks` / `types`, which are refused locally before anything is sent). `wsh --help objects` lists the rest.
1768
+
1769
+ In a `session`, one line per request and one answer line each, in order. Events and callbacks live there because they need one connection: `{"op":"watch","path":"window.app.bus","event":"ready"}` answers `{"ok":true,"result":{"subscription":"s1"}}` (through a handle: `{"op":"watch","handle":"h1","path":"","event":"ready"}`; the host must state `handle-events`, and releasing the handle ends the subscription); `{"op":"next","subscription":"s1"}` waits (`timeoutMs`, default 10000) for the next event; `{"op":"callback"}` answers `{"callback":"c1"}`, which a call passes with `{"op":"call","path":"window.app.listen","args":[null],"callbacks":[[0,"c1"]]}` (the host must state `callbacks`, and the allow-list entry must end in `(callback)`); `{"op":"next","callback":"c1"}` waits for the host's next call of it; `unwatch` and `{"op":"release","callback":"c1"}` end them.
1770
+
1771
+ In Rust code, `wsh_client::objects::ObjectsClient::open(&client)` gives `roots()`, `root(name)`, `root_description(root)` (the `types` answer, as plain data), `callback(capacity)` and a `Target` with `get` / `call` / `call_with` (callbacks among the arguments) / `construct` / `set` / `snapshot` / `describe` / `resolve(Chain)` (a whole chain such as `app.getCart().items` is one request) and `subscribe` (a bounded `Subscription`, from a root or from a handle's `target()`), with typed `ObjectsError`s (`Refused`, `Limit`, `NotFound`, `Unsupported`, ...) carrying the host's `reason`, values as a serde-friendly `Value` (bytes native), `Handle`s (released with `release()`, when dropped, and when the session ends) and `Callback`s (a bounded queue of the host's calls; one-way: the host gets no return value).
1772
+ **What it cannot do:** serve objects (`wsh-server` has no page host and no `wsh-objects` handler, and will not: see [why](spec/objects.md#11-what-the-released-peers-do)); 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. A callback hands the host's code a way to push plain values at this process: they are bounded (this side's queue, the host's rate and size limits) and untrusted like every other byte from the host, and a `session`'s `next` prints them as escaped JSON.
1773
+
1651
1774
  ### Host key (fingerprint / TOFU)
1652
1775
 
1653
1776
  Give the server an identity and the stock client can pin it:
@@ -2151,7 +2274,7 @@ instead of dragging its own toolchain and CI job into an unrelated
2151
2274
  browser-app repo. It was previously deleted from clawser by accident
2152
2275
  (2026-03-14) and restored (2026-07-05) before this move.
2153
2276
 
2154
- Four crates, workspace-versioned (currently `0.17.1`):
2277
+ Four crates, workspace-versioned (currently `0.19.0`):
2155
2278
 
2156
2279
  | Crate | Kind | Description |
2157
2280
  |-------|------|--------------|
@@ -2321,8 +2444,12 @@ than left to be found.
2321
2444
  | 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 |
2322
2445
  | 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 |
2323
2446
  | 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) |
2324
- | 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) |
2325
- | 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 |
2447
+ | 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) |
2448
+ | A page host that dials an operator that listens, instead of a relay (#219): `createPageHost({ connect })` | `@johnhenry/wsh/page`; the operator is any process that accepts the socket and logs in as the client (`connectWshOverDuplex` from `@johnhenry/wsh/duplex`) | none: the Rust CLI has no listening operator mode (`wsh --via` dials a relay's operator side), so a Rust far side cannot be the listener | **JS-only**, no wire change: the same handshake and sealed session over a socket the page opened, URL as written |
2449
+ | 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; from `rust-v0.19.0`: events through a handle, callbacks, `root_description`) and `wsh --sealed [--via RELAY] objects user@host roots\|get\|call\|set\|snapshot\|describe\|watch\|types\|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. Callback return values (`(callback:returns)`, a JS host notation) are not asked of it: it never lists `callback-returns`, so a callback it passes stays one-way. Not planned: a host in `wsh-server` (it has no object graph to expose, see `spec/objects.md` section 11); it 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) |
2450
+ | 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 | **Client only** (`rust-v0.19.0`): `Target::subscribe` on a handle's `target()` and, in `wsh objects session`, `{"op":"watch","handle":...}`; refused locally unless the host states `handle-events`; releasing the handle ends the subscription. No Rust host | **JS host**; 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 |
2451
+ | 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 | **Client only, the data not the generator** (`rust-v0.19.0`): `ObjectsClient::root_description` and `wsh objects types ROOT` print the host's `types` answer as JSON; refused locally unless the host states `types`. No `.d.ts` generator and no `Remote<T>` in Rust; no Rust host | **JS host**; 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 |
2452
+ | 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 |
2326
2453
  | 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 |
2327
2454
  | 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) |
2328
2455
  | 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 |
@@ -2344,7 +2471,7 @@ than left to be found.
2344
2471
  | `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 |
2345
2472
  | 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`) |
2346
2473
  | 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 |
2347
- | `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 |
2474
+ | `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"; the Node gateway sends `8` for a timeout (older Node gateways sent `5`, so a reader still takes a `5` as "disabled, or a timeout from an older Node gateway") | **Notation unified by vectors**; the functions are the JS implementation's and are not a wire feature |
2348
2475
  | 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 |
2349
2476
  | 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 |
2350
2477
 
@@ -2401,7 +2528,7 @@ plus one `SHA256SUMS` file covering every archive in the release. These
2401
2528
  names are a stable contract other repos (clawser) pin and download by --
2402
2529
  do not change them without coordinating downstream.
2403
2530
 
2404
- `wsh --version` and `wsh-server --version` print the workspace version the binary was built from (`wsh 0.17.1`), which is the
2531
+ `wsh --version` and `wsh-server --version` print the workspace version the binary was built from (`wsh 0.19.0`), which is the
2405
2532
  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
2406
2533
  version cannot be read from the binary (look for a flag in `wsh --help` instead).
2407
2534
 
@@ -2516,7 +2643,9 @@ out explicitly below rather than left to be discovered.
2516
2643
  bounds, a visible Stop) and what it cannot make safe (a tool does whatever its `execute` does with the user's session; results may carry
2517
2644
  third-party text and are untrusted to the MCP client; the dialog and the indicator belong to the page and are not a defence against code
2518
2645
  already in it; a fresh host key per page load means no pin outlives it unless `hostKeyStore` is given) are stated in
2519
- [A page as a host](#a-page-as-a-host-johnhenrywshpage-190).
2646
+ [A page as a host](#a-page-as-a-host-johnhenrywshpage-190). The **dial-out form** (`connect`, off unless written) makes the page dial an endpoint of the embedder's choosing:
2647
+ the page does not authenticate that endpoint (the operator pins the page's host key, the page checks keys), the endpoint learns the host key and the stated features before
2648
+ any login, and the page redials it while the host is open; the URL is not logged. The key login, sealing, approval, indicator and Stop are unchanged.
2520
2649
  - **Objects and MCP over a transport that is not wsh (`createDuplexPeer`, `serveMcpOverDuplex`, #220) are only as authenticated as that transport.** The
2521
2650
  identity they hand to `authorize(who, op)`, a prompt and `onCall` is whatever the adapter gave (`who`, `permit`, `permits`): `fingerprint` and `podId`
2522
2651
  are checked to agree, nothing else is verified, and the messages carry no proof of either. They bound what they receive (message size, requests in
@@ -2524,9 +2653,9 @@ out explicitly below rather than left to be discovered.
2524
2653
  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
2525
2654
  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.
2526
2655
  - **`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
2527
- 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
2656
+ 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
2528
2657
  [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
2529
- 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.
2658
+ few paths (`document.cookie`, storage, `fetch`, ...) need an entry that names them. A callback that returns a value (`(callback:returns)`) is not a way for the far side to call into the page more widely, but it is a way for the far side to make the page wait: that wait is bounded by the host (`callbackReturnTimeoutMs`, at most 30 s, and `maxPendingCallbackReturns` waiting calls per channel), and nothing the far side answers is more than plain data; it does not protect a page whose own code trusts the answer. 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. The Rust client (`wsh objects`, `wsh_client::objects`) is only as safe as the host it speaks to: a callback it passes lets the host's code push plain values at the process (bounded by its own queue and the host's rate and size limits; they are text from the host and are escaped in `wsh objects session` output, never interpreted), a subscription through a handle lives only as long as the handle, and `types` prints text the host wrote. None of it widens what the host's allow-lists and the key's capabilities allow.
2530
2659
  - **`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
2531
2660
  file, `0600`), logs in as you and hands the MCP client everything the host's `mcp` channel serves; whatever the MCP client (or the
2532
2661
  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),
@@ -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.50.0",
3
+ "version": "0.52.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"
@@ -62,7 +66,8 @@
62
66
  "./spec/wsh-v1.yaml": "./spec/wsh-v1.yaml"
63
67
  },
64
68
  "bin": {
65
- "wsh-mcp": "./bin/wsh-mcp.mjs"
69
+ "wsh-mcp": "./bin/wsh-mcp.mjs",
70
+ "wsh-objects-types": "./bin/wsh-objects-types.mjs"
66
71
  },
67
72
  "sideEffects": false,
68
73
  "types": "./src/index.d.ts",
@@ -0,0 +1,14 @@
1
+ {
2
+ "version": 1,
3
+ "description": "The codes of GatewayFail (#223): the number, its name, and who sends it. Code 5 is GATEWAY_DISABLED (what spec/wsh-v1.yaml says and what the Rust wsh-server sends). A Node gateway older than the release that introduced 8 sent 5 for a timeout, so a reader treats a 5 as 'disabled, or a timeout from an older Node gateway'. TIMEOUT is 8. A code is never reused and a reader that gets a number it does not know says so rather than guessing.",
4
+ "codes": [
5
+ { "code": 1, "name": "CONNECTION_REFUSED", "sentBy": ["node", "rust"] },
6
+ { "code": 2, "name": "HOST_UNREACHABLE", "sentBy": ["node", "rust"] },
7
+ { "code": 3, "name": "DNS_FAILED", "sentBy": ["node"] },
8
+ { "code": 4, "name": "POLICY_DENIED", "sentBy": ["node", "rust"] },
9
+ { "code": 5, "name": "GATEWAY_DISABLED", "alsoSentAs": ["TIMEOUT"], "sentBy": ["rust", "node-before-timeout-8"] },
10
+ { "code": 6, "name": "CLOSED", "sentBy": ["node"] },
11
+ { "code": 7, "name": "QUEUE_FULL", "sentBy": ["node", "rust"] },
12
+ { "code": 8, "name": "TIMEOUT", "sentBy": ["node"] }
13
+ ]
14
+ }