@johnhenry/wsh 0.46.1 → 0.48.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
@@ -337,11 +337,17 @@ malformed argument or a bad timestamp refuses the key (logged with the code `unk
337
337
  | `mcp:<tool>` | list and call that tool (`mcp:*`: every tool, and the `mcp` rpc channel) | `McpDiscover` lists only these, `McpCall` / the same |
338
338
  | `target:<name>` | name that target in `Open`, `FileOp`, `OpenEndpoint`; `ListTargets` shows only these | Node host only: the Rust server has no targets and refuses a request that names one |
339
339
  | `rpc:<protocol>` | open that rpc protocol (`wsh-host`, or an embedder's own) | `Open` kind `rpc` / the same |
340
+ | `objects:<root>` , `objects:<root>:<op>` | on that root of `wsh-objects` (`*`: every root), every operation, or just `get`, `call`, `set` or `on` (events) (#190) | JS host only: a `wsh-objects` handler of `exposeObjects` / `createPageHost({ expose })`. The Rust server has none, and it refuses a key line that holds an `objects:` capability (an unknown capability fails closed) |
340
341
  | `relay` | register, list and connect through the relay | `ReverseRegister` `ReverseList` `ReverseConnect` / the same |
341
342
 
342
343
  `<host>` is a name, an IP literal (IPv6 in brackets), `*`, or `*.suffix` (any subdomain, not the apex; the name is compared
343
344
  case-insensitively as the client sent it, so resolution is the gateway's `allow` policy's business). `<port>` is a number or `*`.
344
345
  `<path>` is absolute with no `.` or `..`, exact or ending in `/*` (anything below that directory). `<name>`/`<tool>` are exact or `*`.
346
+ `objects:<root>[:<op>]` follows the roots a host named in `exposeObjects`: a key that holds none keeps what `rpc:wsh-objects` gives (every root, every operation the host's
347
+ allow-lists let through); a key that holds any is **limited to the roots and operations they name** (`objects:window:get` reads `window` and nothing else; `objects:store` is every
348
+ operation on `store`; `objects:*:get` reads every root), may open the channel without `rpc:wsh-objects`, is not told of the roots it cannot use, and still meets the host's
349
+ allow-lists (a capability narrows them and never widens them). Walking to a path (reading the properties on the way) counts as part of any operation on that root. The key
350
+ is asked afresh for every operation, so an `expires` holds at call time.
345
351
  The `wsh-fs` rpc channel puts read and write methods on one channel, so it needs **both** `fs:read` and `fs:write`; a client without
346
352
  both falls back to `FileOp` and the file channels, which are checked per operation. A request with no target runs on the host's own
347
353
  backends and needs no `target:` capability (use `requireTarget` to confine keys to targets). Installing a key (`AuthorizedKeyAdd`) is never
@@ -641,17 +647,17 @@ optional ML-KEM backend, is left out of the measurement. What a page ships is wh
641
647
  <!-- bundle-size:start (generated by `npm run size -- --update`; do not edit) -->
642
648
  | browser bundle | minified | gzip |
643
649
  | --- | ---: | ---: |
644
- | `@johnhenry/wsh` (whole entry point) | 162.8 kB | 49.1 kB |
645
- | `@johnhenry/wsh/memory` (whole entry point) | 229.5 kB | 71.6 kB |
646
- | `@johnhenry/wsh/host` (whole entry point) | 124.8 kB | 41.0 kB |
647
- | `@johnhenry/wsh/reverse` (whole entry point) | 218.1 kB | 67.3 kB |
650
+ | `@johnhenry/wsh` (whole entry point) | 164.0 kB | 49.5 kB |
651
+ | `@johnhenry/wsh/memory` (whole entry point) | 231.5 kB | 72.3 kB |
652
+ | `@johnhenry/wsh/host` (whole entry point) | 126.1 kB | 41.5 kB |
653
+ | `@johnhenry/wsh/reverse` (whole entry point) | 220.0 kB | 68.0 kB |
648
654
  | `@johnhenry/wsh/pipe-relay` (whole entry point) | 7.0 kB | 3.0 kB |
649
655
  | `@johnhenry/wsh/testing` (whole entry point) | 7.9 kB | 2.6 kB |
650
- | `@johnhenry/wsh/page` (whole entry point) | 277.4 kB | 87.6 kB |
651
- | `@johnhenry/wsh/objects` (whole entry point) | 158.3 kB | 48.4 kB |
656
+ | `@johnhenry/wsh/page` (whole entry point) | 293.7 kB | 93.1 kB |
657
+ | `@johnhenry/wsh/objects` (whole entry point) | 174.4 kB | 53.4 kB |
652
658
  | `import { generateKeyPair } from '@johnhenry/wsh'` | 0.4 kB | 0.3 kB |
653
- | `import { WshClient } from '@johnhenry/wsh'` | 134.7 kB | 40.4 kB |
654
- | `import { createConnectionFactory } from '@johnhenry/wsh/host'` | 101.5 kB | 33.1 kB |
659
+ | `import { WshClient } from '@johnhenry/wsh'` | 135.9 kB | 40.8 kB |
660
+ | `import { createConnectionFactory } from '@johnhenry/wsh/host'` | 102.9 kB | 33.6 kB |
655
661
  <!-- bundle-size:end -->
656
662
 
657
663
  ### Signing with a page-held signer
@@ -774,7 +780,7 @@ earlier load will not match and trust-on-first-use gives no continuity. To keep
774
780
  ### Remote objects: `@johnhenry/wsh/objects` (#190)
775
781
 
776
782
  `wsh-objects` is an rpc protocol that reaches an object graph by path: a page's `window`, a worker's `self`, any object a host names as a **root**. It is `values` mode:
777
- only plain cloneable values ever cross (there are no handles, no events and no callbacks yet; `mode: 'handles'` is refused with a sentence saying it is not built).
783
+ only plain cloneable values ever cross (on a root that has not opted in to [handles](#handles) there are no handles and no callbacks; events are delivered as copies, see below).
778
784
  Nothing is reachable but the named roots, and nothing in them is allowed until an allow-list says so.
779
785
 
780
786
  ```js
@@ -829,21 +835,89 @@ chain goes on the *result*, whose path is the callee with `()` (`window.app.getC
829
835
  **Bounds, each refused by name** (`limits`): `maxOps` 32 per request, `maxArgs` 16, `maxDepth` 8, `maxValueBytes` 262144 (and always under what the transport carries in one message), `maxKeys` 200
830
836
  for `describe`, `maxRequestsPerSecond` 50 per channel, `callTimeoutMs` 30000 for a call that returns a promise.
831
837
 
838
+ **Events.** `on(ref, 'type', listener)` subscribes to an EventTarget-style source (`addEventListener` / `removeEventListener`) or an emitter-style one (`on` / `off`, or `on` / `removeListener`),
839
+ but only one that an allow-list entry **of its own** names: `allow.on: ['window.app.bus@ready', 'window@hashchange']` (`path@type`: **the source and the type are named exactly**; a wildcard in either is refused when the host is created, so list the types one by one; in `createPageHost({ expose })` the path is relative to the
840
+ root and `'@hashchange'` is the root itself). `get` and `call` never imply it, and neither does a wildcard in another list; the refused names, the entries that need naming, `authorize(who, op)` (`op.type` is the
841
+ event type) and the key capability `objects:ROOT:on` all apply. What is delivered is plain data, never the event and never a node or a handle: an **Event** becomes `{ type, timeStamp, isTrusted }` plus the fields the **host**
842
+ lists for that type (`eventFields: { hashchange: ['newURL', 'oldURL'], '*': ['detail'] }`) that the subscriber asked for in `{ fields }` (a field not listed is refused; each is copied as plain data and a node is left out);
843
+ an **emitter's** arguments become `{ type, args }` (what cannot be cloned is `null`). The listener is `listener(data, { type, seq, dropped })`; `await on(...)` resolves to the function that unsubscribes (`off(fn)`
844
+ does the same). Bounds, by name: `maxSubscriptions` 16 per channel (refused), `maxEventsPerSecond` 20 per subscription, `maxEventBytes` 16384 and `maxQueuedEvents` 100 per channel: an event over any of the last three
845
+ is **dropped and counted** (the rate and the queue are checked before anything of the event is read or copied, so a dropped event costs a counter), and the next one delivered says how many were lost before it (`dropped`). Events leave as notifications whose write waits for the channel's credit, so a slow reader fills the bounded
846
+ queue and then loses events, counted, instead of growing the page's memory. Every listener is taken out of the page's sources when the channel ends: the operator leaves, Stop, a navigation, a revoke. An error in the far
847
+ side's listener goes to its `onError` and stays there; the host's listener only copies and queues and cannot throw into the page's dispatch. Callbacks as arguments of a call are a separate facility (see [Callbacks](#callbacks)).
848
+
849
+ #### Handles
850
+
851
+ A root can opt in to **handles**: `exposeObjects({ roots, handles: { window: {} }, ... })`, or `createPageHost({ expose: { window: { mode: 'handles', allow } } })`. Values stays the default, and the opt-in is per root.
852
+ On such a root a function or an object that is not plain data (a class instance with state, a `Map`) comes back as an opaque `RemoteHandle` instead of a named non-value, and `use(handle)` makes a reference that stands on it:
853
+
854
+ ```js
855
+ const cart = await win.app.cart; // a RemoteHandle { type: 'Cart' } (what a plain value or a named non-value would have been)
856
+ await use(cart).add({ sku: 'A1' }); // the same object across calls; one request per chain, as ever
857
+ await use(cart).items.length;
858
+ await release(cart); // gives its place back; everything is released when the channel ends
859
+ ```
860
+
861
+ - **The path-bound model.** A handle stands at the **path that produced it**: one got by `get window.app.cart` behaves as `window.app.cart`; one returned by calling `window.app.makeCounter` behaves as `window.app.makeCounter()`
862
+ (the notation values mode uses for results), and its members as `window.app.makeCounter().inc`. Every operation through it is judged by the allow-lists for that path extended by the member, exactly as if the path were written out.
863
+ **A handle never widens what a path grants**: if only `window.app.cart.add` may be called, `use(cart).items` is refused. Allow-list entries can name such paths (`call: ['window.app.makeCounter', 'window.app.makeCounter().inc']`).
864
+ The always-refused names stay refused through a handle, and so do the entries that must name their path (`fetch`, cookies, storage, ...).
865
+ - **A handle is opaque and local.** Its id is 128 random bits (from `crypto.getRandomValues`; the page host uses the served window's). It is meaningful only on the channel that produced it, for the key that holds that channel: another
866
+ channel, another key, a reconnect, or a guess finds nothing (`no such handle`). Nothing of it is enumerable on the far side; it is not thenable, and it cannot be sent as an argument.
867
+ - **Nodes and the window graph.** A DOM node, a window or a document is **not** handed out as a handle (it stays a named non-value) unless the root sets its own opt-in, `nodes: true`, which is control of the page. Even then the members that
868
+ lead back up to the graph (`ownerDocument`, `defaultView`, `parentNode`, `parentElement`, `getRootNode`, `contentWindow`, `contentDocument`, `self`, `window`, `top`, `parent`, `frames`, `opener`, `globalThis`) stay refused
869
+ until an allow-list entry names them; a wildcard does not.
870
+ - **A bounded table.** `maxHandles` (64) per channel, **refused by name on overflow, never evicted**; `release(handle)` is explicit; all of them go when the channel ends (the operator leaving, Stop, a navigation, a revoke). A far side's
871
+ garbage-collection hints would be advisory only; none is used.
872
+ - **Previews.** `handle.preview` (a bounded list of up to 8 member names) is present only if a `get` entry names the handle's path, and lists only the names `describe(use(handle))` would list: those the allow-lists could walk to from there. Otherwise a handle says its type and nothing more.
873
+ - **Wide entries need an acknowledgement.** A wildcard (`*` or `**`) in `allow.call` or `allow.set` on a handles root lets a caller hold and reuse every object under it, so the host refuses to start with one unless the root says
874
+ 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.
875
+ - **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).
876
+ - **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
877
+ 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.
878
+
879
+ 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);
880
+ 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.
881
+
882
+ #### Callbacks
883
+
884
+ A far-side **function passed as an argument** of a call is a callback, but only where the call's allow-list entry says so by ending in `(callback)`: `allow.call: ['window.app.subscribe(callback)']`. A call entry without it refuses a function
885
+ argument (`does not accept callbacks`), and a function nested inside an argument, a remote reference and a handle are refused where they are written. The page then receives a **stub**, a plain function it may keep and call:
886
+
887
+ ```js
888
+ await win.app.subscribe((event) => console.log(event.n)); // the page's subscribe(fn) gets a stub; fn runs here, on the far side
889
+ await release(fn); // kills the stub (also: the channel ending)
890
+ ```
891
+
892
+ - **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).
893
+ - **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.
894
+ - **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
895
+ `onCallbackDropped({ dropped })` on the client. The notifications go through the channel's credit like events. The same function sent again is the same callback.
896
+ - **Dead after the session.** A stub is dead after the channel ends (the operator leaving, Stop, a navigation, a revoke) and after `release(fn)`: calling it does nothing and is counted. A listener that throws on the far side goes to `onCallbackError` and never reaches the page.
897
+ - 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
898
+ stub the page will use for what the caller should see.
899
+
900
+ **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
901
+ 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**.
902
+
832
903
  **Threat model of `values` mode.** An allow-list of paths means what it says **only because nothing but cloneable values crosses**: a result can never be walked somewhere else, so what a session can
833
904
  reach is exactly the paths the lists name (and, below a `get`, the plain data inside that value). That holds up to what the named paths themselves do:
834
905
  - **Getters with side effects are still gets.** Reading an accessor property runs its getter, and setting one runs its setter; an entry that allows the path allows the effect. The copy of a value never runs a getter or a `toJSON`
835
906
  (an accessor member is left out).
836
907
  - **A `call` runs the application's function with the caller's arguments**, with the page's authority: whatever it does, it does. List the functions you would hand to the caller. A wide entry means what it says:
837
908
  `window.**` reaches `window.Object.assign`, `window.history.pushState` and every method of every object under it (it still excludes the refused names above).
909
+ - **An event source runs the page's own `addEventListener` or `on`**, and a field of an event is read by name (an accessor on an event is a getter, as for `get`). Naming a source in `allow.on` hands the caller what
910
+ that source emits, which for `window` or `document` can be every `keydown`, `input` or `message`: the host has to list the types (no wildcard is accepted), and should keep `eventFields` to what the caller should see (a `detail` or `data` field
911
+ carries whatever the page put there).
838
912
  - A Proxy used as a root runs its own traps for the paths that pass the allow-list, and for no others.
839
913
  - The list is judged by path text. Give a root its real name: a root called `doc` that *is* the `document` is not recognised as `document.cookie` by the entries that must name it.
840
914
  - It does not protect against the page's own code, against a function reachable by a listed path doing something unlisted, or against what a person at the keyboard can see. The remote caller sees results, which may hold text
841
915
  written by third parties.
842
916
  - 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.
843
917
 
844
- Types: `@johnhenry/wsh/objects` ships `.d.ts` (`client.openObjects<T>()` types the roots; references are untyped). Size: `@johnhenry/wsh/objects` is 48.4 kB gzipped (it contains the client), and
845
- the page entry point grows to 87.6 kB with it; no other entry point changed. Not built yet (later steps of #190): handles for what cannot be cloned, events and callbacks, a capability per root
846
- (`objects:ROOT`), typed remotes (`Remote<T>`), an MCP face for the allow-listed paths, and a dial-out form.
918
+ 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
919
+ 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).
920
+ Not built yet (later steps of #190): typed remotes (`Remote<T>`), an MCP face for the allow-listed paths, and a dial-out form.
847
921
 
848
922
  ### WebTransport listener
849
923
 
@@ -2185,7 +2259,7 @@ than left to be found.
2185
2259
  | 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 |
2186
2260
  | 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 |
2187
2261
  | 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) |
2188
- | 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 works where the Rust client speaks virtual-mode rpc: it does not yet, so `wsh mcp` cannot reach a page host | **JS-only** host (a page); the far side is unchanged wire (`mcp` rpc in virtual mode, #191) |
2262
+ | 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) |
2189
2263
  | 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 |
2190
2264
  | 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 |
2191
2265
  | 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) |
@@ -2380,7 +2454,7 @@ out explicitly below rather than left to be discovered.
2380
2454
  already in it; a fresh host key per page load means no pin outlives it unless `hostKeyStore` is given) are stated in
2381
2455
  [A page as a host](#a-page-as-a-host-johnhenrywshpage-190).
2382
2456
  - **`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
2383
- only because nothing but cloneable values crosses (no handles in `values` mode); what it cannot make safe is stated in
2457
+ 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
2384
2458
  [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
2385
2459
  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.
2386
2460
  - **`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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnhenry/wsh",
3
- "version": "0.46.1",
3
+ "version": "0.48.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",
@@ -53,7 +53,10 @@ const fail = (code, reason) => ({ ok: false, code, reason });
53
53
  const NAME_CAP_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
54
54
  const TOOL_CAP_RE = /^[A-Za-z0-9_][A-Za-z0-9_.:-]{0,127}$/;
55
55
  const DOMAIN_RE = /^[A-Za-z0-9]([A-Za-z0-9._-]*[A-Za-z0-9])?$/;
56
- const SIMPLE_CAPS = new Set(['exec', 'pty', 'relay', 'fs:read', 'fs:write']);
56
+ const OBJECT_ROOT_RE = /^[A-Za-z_$][A-Za-z0-9_$-]{0,63}$/;
57
+ /** The operations of `wsh-objects` a capability can name (`objects:ROOT:OP`). */
58
+ const OBJECT_OPS = ['get', 'call', 'set', 'on'];
59
+ const SIMPLE_CAPS =new Set(['exec', 'pty', 'relay', 'fs:read', 'fs:write']);
57
60
 
58
61
  const capFail = (code, reason) => ({ ok: false, code, reason });
59
62
 
@@ -132,6 +135,14 @@ function parseCapability(raw) {
132
135
  if (raw.startsWith('target:')) return named('target:', 'target', NAME_CAP_RE, true);
133
136
  if (raw.startsWith('mcp:')) return named('mcp:', 'mcp', TOOL_CAP_RE, true);
134
137
  if (raw.startsWith('rpc:')) return named('rpc:', 'rpc', NAME_CAP_RE, false);
138
+ if (raw.startsWith('objects:')) {
139
+ // objects:ROOT or objects:ROOT:OP (#190): a root of `wsh-objects` (or `*`), and optionally one operation on it. JS hosts only.
140
+ const parts = raw.slice('objects:'.length).split(':');
141
+ const [root, op, ...rest] = parts;
142
+ if (rest.length || !(root === '*' || OBJECT_ROOT_RE.test(root))) return bad('expected objects:<root>[:<get|call|set|on>]');
143
+ if (op !== undefined && !OBJECT_OPS.includes(op)) return bad(`the operation must be one of ${OBJECT_OPS.join(', ')}`);
144
+ return { ok: true, cap: { raw, kind: 'objects', name: root, op: op ?? null } };
145
+ }
135
146
  return capFail('unknown-capability', `unknown capability ${JSON.stringify(raw)}`);
136
147
  }
137
148
 
@@ -340,6 +351,8 @@ function capabilityRefusal(p, req) {
340
351
  // A handler that narrows by capability itself (`capabilityScoped`, req.scoped) may be opened by a key that names any
341
352
  // tool; every other `mcp` handler would show a `mcp:search` key all of its tools, so it still needs `mcp:*`.
342
353
  else if (proto === 'mcp') r = req.scoped ? need('mcp:<tool>', has('mcp')) : need('mcp:*', caps.some((c) => c.kind === 'mcp' && c.name === '*'));
354
+ // Same for `wsh-objects`: a key that names roots (`objects:window:get`) may open it without `rpc:wsh-objects`, and is limited to them.
355
+ else if (proto === 'wsh-objects' && req.scoped) r = need('rpc:wsh-objects', has('objects') || caps.some((c) => c.kind === 'rpc' && c.name === proto));
343
356
  else r = need(`rpc:${proto}`, caps.some((c) => c.kind === 'rpc' && c.name === proto));
344
357
  } else r = need(req.channel, false);
345
358
  return r ?? target();
@@ -350,6 +363,13 @@ function capabilityRefusal(p, req) {
350
363
  }
351
364
  case 'mcp': return need('mcp:*', has('mcp'));
352
365
  case 'mcp-call': case 'mcp-tool': return need(`mcp:${req.tool}`, caps.some((c) => c.kind === 'mcp' && nameMatches(c, req.tool)));
366
+ // An operation of `wsh-objects` on a root (`op`: get, call, set, or `walk`: reading on the way to something): a key that names no root
367
+ // with `objects:` is limited by `rpc:wsh-objects` alone (all roots, as before); one that names roots is limited to them.
368
+ case 'objects': {
369
+ const named = caps.filter((c) => c.kind === 'objects');
370
+ if (!named.length) return need('rpc:wsh-objects', caps.some((c) => c.kind === 'rpc' && c.name === 'wsh-objects'));
371
+ return need(`objects:${req.root}${req.op === 'walk' ? '' : `:${req.op}`}`, named.some((c) => nameMatches(c, req.root) && (req.op === 'walk' || c.op === null || c.op === req.op)));
372
+ }
353
373
  case 'relay': return need('relay', has('relay'));
354
374
  // Installing a key gives a key with no capability list, so a key with one never may.
355
375
  case 'key-admin': return { code: 'key-admin-not-permitted', reason: 'installing a key is not permitted for a restricted key' };
@@ -426,7 +446,7 @@ function optionsRefusal(p, req, activeSessions) {
426
446
  case 'mcp': case 'mcp-call': case 'mcp-tool': return p.mcp ? null : no('mcp-not-permitted', 'MCP not permitted for this key');
427
447
  case 'relay': return p.relay ? null : no('relay-not-permitted', 'relay not permitted for this key');
428
448
  // The gateway, endpoints and targets are not scoped by the options (only by capabilities).
429
- case 'tcp': case 'udp': case 'dns': case 'listen-tcp': case 'unix': case 'listen-unix': case 'endpoint': case 'target': return null;
449
+ case 'tcp': case 'udp': case 'dns': case 'listen-tcp': case 'unix': case 'listen-unix': case 'endpoint': case 'target': case 'objects': return null;
430
450
  // Installing another key (`AuthorizedKeyAdd`, which the Rust server serves): the new key has no options, so only a key that
431
451
  // is not restricted at all may add one -- a restricted key would otherwise mint an unrestricted one.
432
452
  case 'key-admin':