@linxin666/dsh-remote-bridge 0.4.14 → 0.4.16

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.i18n.yaml CHANGED
@@ -2,5 +2,5 @@
2
2
  # side as of the last confirmed-consistent state. Both languages carry equal authority;
3
3
  # after editing either side, bring the other along and re-record with:
4
4
  # node scripts/verify-docs.mjs --write <dir>
5
- README.md: ace1c8b53b33dc58da128a48c8f663a88aa3b1a3
6
- README.zh.md: 18a9d176979ab0366db0662c626dadbead5419cf
5
+ README.md: 697ff27093520de35e6fa631fcb50581daeff7a5
6
+ README.zh.md: 1c1a6d7ea5df84a6044b1a83009c8160b1bf3600
package/README.md CHANGED
@@ -5,7 +5,7 @@ English | [中文](README.zh.md)
5
5
  <p align="center">
6
6
  <img src="https://img.shields.io/npm/v/@linxin666/dsh-remote-bridge?style=flat-square" alt="Version">
7
7
  &nbsp;
8
- <img src="https://img.shields.io/badge/DSH-%3E%3D0.2.1--rc.3-4c6ef5?style=flat-square&amp;labelColor=454a54" alt="DSH">
8
+ <img src="https://img.shields.io/badge/DSH-%3E%3D0.2.2--rc.1-4c6ef5?style=flat-square&amp;labelColor=454a54" alt="DSH">
9
9
  &nbsp;
10
10
  <img src="https://img.shields.io/badge/license-Apache--2.0-blue?style=flat-square" alt="License">
11
11
  </p>
@@ -135,7 +135,7 @@ A compact listing is the roster's other form, and it takes both halves to appear
135
135
 
136
136
  An `approval.request` carries a summary taken from the harness's display reason in the client's language, falling back to English and then to the tool name, plus the tool name itself. The client answers it with `approval.resolve`, whose `decision` is either `allowed-once` or `rejected`; an unknown or expired `id` is refused, and a request nobody answers is resolved after two minutes as unavailable, which the harness reads as a rejection. Every paired connection receives the event the moment the tool asks — the first broadcast is behind no capability — and a connection that declared `approvals.v1` in `hello` is handed every still-waiting request again, so a phone that reconnected, or a session screen opened after the fact, still holds a card. Only an unsettled request is replayed: one that was answered, timed out or withdrawn is gone from the claim registry, and re-handing a request never moves its two-minute deadline. The capability gates that second delivery and nothing else, which is why it is absent from `hello`'s `capabilities` and leaves `minor` alone: the handshake answers every client the same frame. The bridge claims an approval request only while a paired client is connected: with none, the request is left to the next answerer instead of waiting out a phone that is not there.
137
137
 
138
- The question channel is the one claim that outlives the socket. A question arrives as a `question.request` event under the host's own call id, or under one this bridge mints when a blocking ask carries none, and `question.answer` settles the host's ask: while that ask is still open the answer resolves the promise the bridge holds, and once the host's deadline has released the model a late answer takes the host's Remote `answer` path instead. `question.list` answers the questions the bridge is still holding, which is what a phone reconciles the cards it carries against. With no paired connection on the wire, but a device on the roster that registered for push, the bridge claims the question for that phone and the alert is its delivery: for one bridge-owned window the question exists only on the phone's side, and when the window ends it goes back to the host's own answerer chain. The window is `OFFLINE_QUESTION_CLAIM_TTL_MS`, ten minutes, overridable with `DSH_REMOTE_BRIDGE_OFFLINE_CLAIM_TTL_MS`. Inside it a phone that reconnects and declares `questions.v1` is handed the live claim and the window ends there; a phone that answers settles it, and the host's chain is then never started; and a hello from a paired connection that did not declare the channel releases the claim at once, because a claim nobody on the wire can receive is not kept. A blocking ask — no call id, no deadline — is claimed the same way, and its cost is stated rather than hidden: the agent behind it waits at most that window. Approvals keep the stricter rule above, where nothing is ever held for a phone that is not on the wire.
138
+ The question channel is the one claim that outlives the socket. A question arrives as a `question.request` event under the host's own call id, or under one this bridge mints when a blocking ask carries none, and `question.answer` settles the host's ask: while that ask is still open the answer resolves the promise the bridge holds, and once the host's deadline has released the model a late answer takes the host's Remote `answer` path instead. Claiming yields to the host's own answerer chain the instant the claim exists, so both sides hold the card and the first answer wins: a host answer broadcasts `question.request` with `state:"settled"` and releases the claim, while a phone answer resolves the bridge's promise and leaves a later host settlement ignored; a host chain that rejects is not a verdict and leaves the claim answerable. `question.list` answers the questions the bridge is still holding, which is what a phone reconciles the cards it carries against. With no paired connection on the wire, but a device on the roster that registered for push, the bridge still claims the question, sends the alert when no live browser client is connected, and yields to the host's answerer chain at once: the claim lives until it is answered, the host's deadline ends it, or the bridge unloads, and it is given up if APNs refuses every registered token on the roster. Approvals keep the stricter rule above, where nothing is ever claimed for a phone that is not on the wire.
139
139
 
140
140
  The interactive-reply channel is the one place a page travels instead of a question. `ui_present` is this bridge's own model tool: the agent writes one whole self-contained document (`<!doctype html>` first, at most 256 KiB of UTF-8) and it crosses as a `ui.request` event under the host's own `ToolCallId`, so the card hangs on the same tool-call row the transcript already draws. The call then blocks until the user's FIRST action inside the page arrives, and that action — `{type, payload?}` with `type` the page's own closed set and `payload` at most 8 KiB — is the tool call's result: one card settles one action, and a page that should keep taking them is presented again. The card is announced over as `state:"settled"` to every client that declared `ui.v1`, including the one that acted, so a second tap on the phone and a second phone both learn it is over. `ui.list` answers the cards this bridge still holds, which is what a phone reconciles against after a restart, and only a complete answer may retire one. A card never carries `expiresAt`: the tool schema declares no `timeout`, so this bridge invents no deadline, and it takes the same grace window as a question instead — a page nobody can answer any more is released to the agent as a timeout when the window the last paired device left behind runs out, and a phone that declares the channel inside that window is handed the live card and cancels the release. With no paired connection that declared `ui.v1`, `ui_present` answers `{ok:false, reason:"unavailable"}` at once instead of holding the agent. Every result of a page that did reach the wire carries the presentation payload as `meta.ui` — `{key, title?, html, height?, state}` with `key` spelled `"<sessionId>/<callId>"` — for a client that renders the card out of the transcript and holds no `ui.request` socket; the body of the result stays one human sentence.
141
141
 
@@ -183,7 +183,7 @@ The device token rides the WebSocket upgrade as `Authorization: Bearer <deviceTo
183
183
 
184
184
  The pairing entry is a QR code icon at the bottom of the sidebar, with the accessible label "Pair an iPhone". Clicking it opens the pairing panel. The panel is strictly available on localhost: its token route `GET /remote-bridge/pair/token` is guarded by a two-condition loopback gate where both the socket address and the `Host` header must name this machine (remote or tunneled requests return 403).
185
185
 
186
- The pairing code is single-use and valid for 30 seconds (`BOOTSTRAP_TOKEN_TTL_MS = 30_000`), consumed immediately upon the first `pair.begin`; clicking "New code" in the panel voids the previous code and mints a fresh one. There is no "Stop" button and no action to revoke all connected devices. The link is printed to the host log, while the code itself renders in the pairing panel for scanning.
186
+ The pairing code is single-use and valid for 30 seconds (`BOOTSTRAP_TOKEN_TTL_MS = 30_000`), consumed immediately upon the first `pair.begin`; clicking "New code" in the panel voids the previous code and mints a fresh one. There is no "Stop" button and no action to revoke all connected devices. The machine-local link is printed to the host log as `pair a device with <ws link>`, and that line is followed only by the kind of phone-facing address: `(phone: lan)` when the host calls the origin a LAN address or the literal itself answers only inside the network this page is already on, `(phone: public)` in every other case, and no suffix when the host found no address at all. The code itself renders in the pairing panel for scanning.
187
187
 
188
188
  ```sh
189
189
  curl -s http://127.0.0.1:3080/remote-bridge/pair/token
@@ -198,7 +198,7 @@ When this machine can determine a public or LAN origin — from live relay lease
198
198
  "expiresAt": 1760000030000,
199
199
  "url": "ws://127.0.0.1:3080/ios/v1?token=...",
200
200
  "origin": "wss://<id>.dsh-market.com",
201
- "originSource": "registry",
201
+ "originSource": "realtime",
202
202
  "pairingUrl": "wss://<id>.dsh-market.com/ios/v1?token=..."
203
203
  }
204
204
  ```
@@ -276,14 +276,14 @@ The plugin is configured through profile YAML (`cordis.patch.yml` or profile con
276
276
 
277
277
  ## Web GUI pairing panel
278
278
 
279
- The browser half exists so that an operator who never opens a terminal still has a way to start pairing. It follows the family's sidebar-foot convention: the trigger registers into the official `sidebar.footer.action` list slot (declared by ui-sidebar, sharing this list slot with `dsh-update`'s updater) and opens the official `Modal`, whose headless card this package fills. Every control it renders is a library primitive — the dialog, the three actions and their glyphs — so the mask, the card, the focus trap, Escape, focus restoration and each hover/focus/disabled state are the shell's behavior rather than a copy of it. It is delivered by the same plugin row: `exports["./client"]` is the artifact and `dsh.client` declares the client modules that must be live first.
279
+ The browser half exists so that an operator who never opens a terminal still has a way to start pairing. It follows the family's sidebar-foot convention: the trigger registers into the official `sidebar.footer.action` list slot (declared by ui-sidebar, the same list slot the family's other foot triggers use) and opens the official `Modal`, whose headless card this package fills. Every control it renders is a library primitive — the dialog, the three actions and their glyphs — so the mask, the card, the focus trap, Escape, focus restoration and each hover/focus/disabled state are the shell's behavior rather than a copy of it. It is delivered by the same plugin row: `exports["./client"]` is the artifact and `dsh.client` declares the client modules that must be live first.
280
280
 
281
281
  The panel has one job — put the live one-time code in front of the operator, in one reading order:
282
282
 
283
283
  - **Header and subtitle set the scope.** Title "iOS app pairing"; subtitle "Scan the QR code with the iOS app (beta) to connect an iPhone to this computer. The code is shown only on this machine.", stating the target and security boundary.
284
284
  - **The QR symbol is the code.** It encodes either the bare 43-character base64url token or, when the host can name its own public origin, the `{token,url}` document one scan turns into a fully configured iPhone. A URL the host did not vouch for would let the app's own parser rewrite its origin onto this machine's loopback address, which is precisely the address an iPhone cannot reach. The encoded string is mirrored once, as the `data-dsh-qr-value` attribute on the symbol's part, so a UI check can compare it without decoding anything; it is never rendered as text.
285
285
  - **One status line under the symbol.** A live code counts its 30 s window down beside a progress bar; an expired code states the expiry in the same fixed box, so only the sentence changes.
286
- - **One address line.** When the host located its relay origin, the line states "The iPhone will dial {origin}"; otherwise it says outright "No public address found: set the connection address in the app to your public relay first, then scan. {host} (this page) is reachable only from this machine."
286
+ - **One address line.** A located origin is stated as a kind rather than printed: "The QR code carries the public address: the iPhone connects to this computer as soon as it scans". The one-time code burns 30 seconds after it appears, while a durable public hostname, once rendered as text, outlives every screenshot it appears in; the symbol already carries the address the phone needs, and Copy hands over the same `{token,url}` string either way. A LAN literal is not that fact, and the line names it — "The QR code points at the LAN address {origin}: the iPhone must be on the same network" — when the host calls the origin a LAN address or when the literal itself answers only inside the network this page is already on. With no located address the line says outright "No public address found: set the connection address in the app to your public relay first, then scan. {host} (this page) is reachable only from this machine."
287
287
  - **One single-use note.** The code is single-use: pairing spends it, and a new code voids the previous one.
288
288
  - **One action row.** Copy puts the very string the symbol encodes on the clipboard, and **New code** mints a fresh token and voids the previous one; both are one library control at one size, so their states never diverge. Once the code expires, mint-again is the only way back to a scannable symbol: copy is disabled and the symbol is dimmed in place instead of resized or removed.
289
289
  - **One beta entry.** Provides "[The iOS app is in beta. Come talk to us on Discord](https://discord.gg/nBy28kjun)", clickable across the entire line.
@@ -346,7 +346,7 @@ The bridge is mounted like any other host plugin row. It carries no user-facing
346
346
 
347
347
  - **Pairing is a full-control credential.** A paired device reaches the harness in-process: sessions, prompts, approvals. Only pair devices you control, and revoke by removing the roster row and restarting the host.
348
348
  - **In-process calls speak for the owner, only behind this bridge's own gate.** Since DSH 0.2.1 the harness gateway requires every call to name the peer it speaks for, and the bridge answers with one in-process owner peer (`{kind:'owner'}`) that it mints itself at mount and attaches to every gateway call. That claim is safe because it is exercised only after the bridge's own pairing check — an unpaired connection is refused before any gateway call exists — and no field of a protocol frame can set a principal: a client that names one in its payload is ignored. The peer takes no forwarded-event interactions, so it never receives forwarded Host events either.
349
- - **The token endpoint is loopback-only, on two conditions.** The socket address must be loopback and the `Host` header must name this machine. A tunneled request is terminated by the tunnel client on this same host, so the socket address alone reads `127.0.0.1` for a request the whole internet can reach, while the relay and a plain tunnel rewrite `Host` to the public name; failing either condition is a 403. The token is memory-only, expires in 30 s, is spent by one `pair.begin`, and the same link is written to the host log — treat that log line as a live secret.
349
+ - **The token endpoint is loopback-only, on two conditions.** The socket address must be loopback and the `Host` header must name this machine. A tunneled request is terminated by the tunnel client on this same host, so the socket address alone reads `127.0.0.1` for a request the whole internet can reach, while the relay and a plain tunnel rewrite `Host` to the public name; failing either condition is a 403. The token is memory-only, expires in 30 s, is spent by one `pair.begin`, and the machine-local link is written to the host log — treat that log line as a live secret. The phone's side of that line is the kind of address alone (`(phone: public)` or `(phone: lan)`, no suffix when there is none): this pairing line is the one an operator pastes elsewhere, and a public hostname or a LAN literal in it would outlive the code it belongs to.
350
350
  - **The pairing panel renders a live secret and nothing more.** It reads the same loopback-gated route over a same-origin request, so it is reachable exactly where the `curl` form is, and nowhere else. It cannot mint a device token, spend one, list the roster or revoke a device: `pair.begin` stays the phone's call, and revocation stays a roster edit plus a host restart. The QR carries either the bare token or the host's own `{token,url}` answer, so the page's `127.0.0.1` origin is never handed to the phone.
351
351
  - **An unpaired connection has a three-method whitelist.** `hello`, `pair.begin` and `pair.finish`; every other method answers `unpaired` before dispatch, so no session, approval or roster surface is reachable without a device token.
352
352
  - **Device tokens are stored as hashes only.** The roster keeps the public key and its SHA-256 fingerprint, never the token, so the file is not a credential store. A lost, rotated or rejected token means pairing again — a routine flow, not an exception path (a fresh bootstrap link, or a re-scan of the desktop pairing flow), and it never requires editing the roster by hand.
package/README.zh.md CHANGED
@@ -5,7 +5,7 @@
5
5
  <p align="center">
6
6
  <img src="https://img.shields.io/npm/v/@linxin666/dsh-remote-bridge?style=flat-square" alt="Version">
7
7
  &nbsp;
8
- <img src="https://img.shields.io/badge/DSH-%3E%3D0.2.1--rc.3-4c6ef5?style=flat-square&amp;labelColor=454a54" alt="DSH">
8
+ <img src="https://img.shields.io/badge/DSH-%3E%3D0.2.2--rc.1-4c6ef5?style=flat-square&amp;labelColor=454a54" alt="DSH">
9
9
  &nbsp;
10
10
  <img src="https://img.shields.io/badge/license-Apache--2.0-blue?style=flat-square" alt="License">
11
11
  </p>
@@ -132,7 +132,7 @@ fork 的方法同样什么都不解释。`session.fork` 把 `sessionId` 与客
132
132
 
133
133
  `approval.request` 的摘要取自宿主按客户端语言给出的显示理由,缺失时回落英文、再回落工具名,并附带工具名本身。客户端用 `approval.resolve` 作答,`decision` 取 `allowed-once` 或 `rejected`;未知或过期的 `id` 会被拒绝,而无人应答的请求在两分钟后按 unavailable 结算,宿主视之为拒绝。工具发起请求的那一刻,每一条已配对连接都会收到该事件——首播不在任何能力名之后——而声明了 `approvals.v1` 的连接会在 `hello` 之后再次收到所有仍在等待的请求,因此重连过的手机、或事后才打开该会话的界面,手里依然有卡片。只有未结算的请求会被重放:已作答、已超时、已撤回的请求早已离开认领表,而重新递一次请求绝不会挪动它的两分钟截止时间。该能力只门控这第二次送达,因此它不出现在 `hello` 的 `capabilities` 里、也不改动 `minor`:握手对每个客户端都回同一个帧。桥只在下游有已配对客户端连接时才认领审批请求:一个都没有时,请求交给下一个应答者,而不是干等一台不在场的手机。
134
134
 
135
- 提问通道是唯一一条能比套接字活得久的认领。提问以 `question.request` 事件到达手机,call id 用宿主自己的;阻塞式提问没有 call id,就由本桥另铸一个。手机用 `question.answer` 结算宿主的询问:询问仍然开着时,答案直接解开本桥手里的 promise;宿主自己的截止时间已经放走模型之后,迟到的答案改走宿主的 Remote `answer`。`question.list` 回答本桥此刻仍持有的提问,手机据此与手里的卡对账。没有任何已配对连接在线、但设备名册里有登记过推送令牌时,桥替那台手机认领这道题,推送就是它的送达:在桥自有的一个窗口内,这道题只存在于手机侧,窗口结束即回到宿主自己的应答者链。这个窗口是 `OFFLINE_QUESTION_CLAIM_TTL_MS`,十分钟,可用 `DSH_REMOTE_BRIDGE_OFFLINE_CLAIM_TTL_MS` 覆盖。窗口内重连并声明 `questions.v1` 的手机直接拿到这条仍然有效的认领,窗口到此为止;手机作答即结算,宿主链于是从未启动;而已配对连接完成 `hello` 却没有声明这条通道时,认领立刻被撤回——线上没人能收的认领不留。阻塞式提问(无 call id、无 deadline)同样认领,代价写在明处:它背后的 agent 最多白等这一个窗口。审批沿用上面更严的那条规则:永远不为不在线上的手机持有任何东西。
135
+ 提问通道是唯一一条能比套接字活得久的认领。提问以 `question.request` 事件到达手机,call id 用宿主自己的;阻塞式提问没有 call id,就由本桥另铸一个。手机用 `question.answer` 结算宿主的询问:询问仍然开着时,答案直接解开本桥手里的 promise;宿主自己的截止时间已经放走模型之后,迟到的答案改走宿主的 Remote `answer`。认领成立即刻让位给宿主自己的应答者链,两端同时持有卡片,先答者胜:宿主链先答时,桥向已声明 `questions.v1` 的连接广播 `state:"settled"` 的 `question.request` 并释放认领;手机先答时,桥返回手机的答案并忽略宿主链随后到达的结算;宿主链 reject 不是判决,认领保留,手机仍可作答。`question.list` 回答本桥此刻仍持有的提问,手机据此与手里的卡对账。没有任何已配对连接在线、但设备名册里有登记过推送令牌的设备时,桥照旧替那台手机认领这道题、在宿主没有在线浏览器客户端时发推送,并立刻让位给宿主自己的应答者链:认领活到被答、宿主自己的截止时间到点或本桥卸载;若 APNs 对名册上每个已登记令牌都拒绝,则放弃这次认领。审批沿用上面更严的那条规则:永远不为不在线上的手机认领任何东西。
136
136
 
137
137
  可交互回复是唯一一条「走一整页而不是走一个问题」的通道。`ui_present` 是本桥自己的模型工具:agent 写一整份自包含文档(以 `<!doctype html>` 开头,UTF-8 最多 256 KiB),它作为 `ui.request` 事件、用宿主自己的 `ToolCallId` 下发,于是这张卡正好挂在转录里那条工具调用行上。随后这次调用阻塞,直到用户在页面里的**第一条**动作为止——那个动作 `{type, payload?}`(`type` 是页面自己的闭集,`payload` 最多 8 KiB)就是这次工具调用的返回值:一张卡结算一个动作,需要继续接受动作就让 agent 再呈现一次。结算时这条卡以 `state:"settled"` 对每个声明了 `ui.v1` 的客户端再公告一次(包括刚作答的那台),所以手机上重复的第二次点击、以及第二台手机都能读到它已结束。`ui.list` 回答本桥此刻仍持有的卡,是手机重启后的对账依据,且只有 `complete` 的应答才允许退休一张卡。卡永不携带 `expiresAt`:工具 schema 不声明 `timeout`,本桥也就不发明超时;它拿的是与提问同一个宽限窗口——再没有人能作答的卡在「最后一次配对设备离开」留下的窗口到期时,以超时交还给 agent,而在这个窗口内声明了通道的手机则被重放活卡、并取消这次释放。没有任何声明了 `ui.v1` 的已配对连接时,`ui_present` 立即回 `{ok:false, reason:"unavailable"}`,不占用宿主的等待。真的到过线缆上的那次呈现,其结果在 `meta.ui` 里带着同一份展示载荷——`{key, title?, html, height?, state}`,`key` 是 `"<sessionId>/<callId>"` 拼法——供从转录渲染、手里没有 `ui.request` socket 的客户端使用;结果正文仍是一句人可读的话。
138
138
 
@@ -180,7 +180,7 @@ fork 的方法同样什么都不解释。`session.fork` 把 `sessionId` 与客
180
180
 
181
181
  配对入口位于侧栏底部的二维码图标,按钮的 aria-label 为「配对 iPhone」。点击后打开配对面板。该面板只在本机可用:令牌路由 `GET /remote-bridge/pair/token` 受回环门控保护,来源地址与 `Host` header 必须均为本机(非本机或经隧道访问一律返回 403)。
182
182
 
183
- 配对码一次性有效且具备 30 秒时效(`BOOTSTRAP_TOKEN_TTL_MS = 30_000`),被首次 `pair.begin` 用掉即失效;在面板中点击「重新取码」会使上一张配对码作废并生成新码。面板中没有「停止」按钮,也没有「吊销所有已连接设备」的操作。同一条链接会打印到宿主日志,配对码本身则渲染在配对面板中供扫码。
183
+ 配对码一次性有效且具备 30 秒时效(`BOOTSTRAP_TOKEN_TTL_MS = 30_000`),被首次 `pair.begin` 用掉即失效;在面板中点击「重新取码」会使上一张配对码作废并生成新码。面板中没有「停止」按钮,也没有「吊销所有已连接设备」的操作。本机链接会以 `pair a device with <ws 链接>` 打印到宿主日志,而这一行后面只跟手机侧地址的种类:宿主把这个 origin 叫作局域网地址、或者该字面量本身就只在当前网络内可达时是 `(phone: lan)`,其余情形是 `(phone: public)`,一个地址都没有时不带后缀。配对码本身则渲染在配对面板中供扫码。
184
184
 
185
185
  ```sh
186
186
  curl -s http://127.0.0.1:3080/remote-bridge/pair/token
@@ -195,7 +195,7 @@ curl -s http://127.0.0.1:3080/remote-bridge/pair/token
195
195
  "expiresAt": 1760000030000,
196
196
  "url": "ws://127.0.0.1:3080/ios/v1?token=...",
197
197
  "origin": "wss://<id>.dsh-market.com",
198
- "originSource": "registry",
198
+ "originSource": "realtime",
199
199
  "pairingUrl": "wss://<id>.dsh-market.com/ios/v1?token=..."
200
200
  }
201
201
  ```
@@ -273,14 +273,14 @@ curl -s http://127.0.0.1:3080/remote-bridge/pair/token
273
273
 
274
274
  ## Web GUI 配对面板
275
275
 
276
- 浏览器半区存在的理由,是让从不开终端的操作者也有一条发起配对的路径。它沿用家族在侧栏底部的惯例:触发器注册进官方 `sidebar.footer.action` 列表槽位(由 ui-sidebar 声明,与 `dsh-update` 的更新器共用该列表槽位),点开后是官方 `Modal`,这张无头卡片由本包填充。它渲染的每个控件都是库里已有的 primitive——弹窗、三个动作与它们的字形——因此遮罩、卡片、焦点圈定、Esc、焦点归还,以及每个 hover/focus/disabled 状态都是官方壳自己的行为,而不是本包的一份复制品。它由同一插件行承载:产物是 `exports["./client"]`,`dsh.client` 声明必须先就位的 client 模块。
276
+ 浏览器半区存在的理由,是让从不开终端的操作者也有一条发起配对的路径。它沿用家族在侧栏底部的惯例:触发器注册进官方 `sidebar.footer.action` 列表槽位(由 ui-sidebar 声明,与家族其它脚部触发器共用该列表槽位),点开后是官方 `Modal`,这张无头卡片由本包填充。它渲染的每个控件都是库里已有的 primitive——弹窗、三个动作与它们的字形——因此遮罩、卡片、焦点圈定、Esc、焦点归还,以及每个 hover/focus/disabled 状态都是官方壳自己的行为,而不是本包的一份复制品。它由同一插件行承载:产物是 `exports["./client"]`,`dsh.client` 声明必须先就位的 client 模块。
277
277
 
278
278
  面板只做一件事——把活着的那个一次性配对码摆到操作者面前,且只有这一个阅读顺序:
279
279
 
280
280
  - **卡头与副标题说明目标。** 标题为「iOS App 配对」,副标题「用 iOS App(内测)扫描二维码,把 iPhone 连到这台电脑上。配对码只在本机显示。」,说明操作对象与安全边界。
281
281
  - **二维码本身就是那个码。** 它要么装 43 个 base64url 字符的裸 token,要么在宿主说得出自己公网地址时装 `{token,url}` 文档,扫一次就把 iPhone 配好。若放一个宿主没背书过的 URL,App 端的解析器会顺手把 origin 改写成这台机器的 loopback 地址,而那恰恰是 iPhone 够不到的地址。编码串只在二维码部件的 `data-dsh-qr-value` 属性里留一份镜像,供 UI 检查不必解码就比对;它从不以文字形式渲染。
282
282
  - **二维码下方只有一条状态行。** 活着的码在进度条旁倒数那 30 秒;过期的码在同一个固定高度里直说过期,变的只有那句话。
283
- - **一条地址说明。** 宿主定位到中继地址时,这一行写明「iPhone 将连到 {origin}」;定位不到时,它直说「没有找到公网地址:先在 App 里把连接地址填成你的公网中继,再扫码。本页的 {host} 只有本机能连。」。
283
+ - **一条地址说明。** 定位到的公网地址只交代种类,不写成文字:「二维码已包含公网地址,扫码后 iPhone 自动连上这台电脑」。一次性配对码 30 秒即焚,而持久公网主机名一旦以文字渲染,会比它出现的每张截图活得久;二维码本身已带手机需要的地址,「复制配对码」交出的仍是同一个 `{token,url}` 串。局域网字面量不属于这一类事实:当宿主把这个 origin 叫作局域网地址,或者该字面量本身就只在当前网络内可达时,这一行都点名它——「二维码指向局域网地址 {origin},iPhone 需与本机在同一网络」。定位不到地址时,它直说「没有找到公网地址:先在 App 里把连接地址填成你的公网中继,再扫码。本页的 {host} 只有本机能连。」。
284
284
  - **一条一次性说明。** 配对码一次性有效:iPhone 一开始配对就作废,重新取码也会作废上一张。
285
285
  - **一行动作。** 复制把二维码里那个字符串原样放进剪贴板,「重新取码」签发新 token 并作废上一张;两者都是同一个库控件、同一个尺寸,交互态不会各走一套。码一旦过期,回到可扫状态的唯一路径就是重新取码:复制被禁用,二维码原地降级变暗,而不是缩小或被移除。
286
286
  - **一行内测入口。** 提供「[iOS App 还在内测,欢迎来 Discord 交流](https://discord.gg/nBy28kjun)」,整行可点击打开。
@@ -343,7 +343,7 @@ dsh plugin --profile web add link:$(pwd)/packages/dsh-remote-bridge
343
343
 
344
344
  - **配对即完全控制凭据。** 已配对设备在同一进程内触达宿主:会话、发言、审批。只配对你掌控的设备,吊销方式是移除名册那一行并重启宿主。
345
345
  - **进程内调用以 owner 身份发言,且只在桥自己的门禁之后。** 自 DSH 0.2.1 起,宿主网关要求每次调用都指明代表谁发言,桥的回答是自己在挂载时铸造的一个进程内 owner peer(`{kind:'owner'}`),挂到每一次网关调用上。这个声明之所以安全,是因为它只在桥自己的配对检查之后才会被用到——未配对连接在任何网关调用存在之前即被拒——且协议帧的任何字段都不能设定 principal:客户端在载荷里自报的身份会被忽略。该 peer 不接收转发事件交互,因此它也永远收不到宿主转发事件。
346
- - **token 端点仅 loopback 可达,且看两个条件。** 来源地址必须是 loopback,且 `Host` header 必须写本机。经隧道的请求由本机的隧道客户端终结,所以对一条全互联网可达的请求,来源地址也读作 `127.0.0.1`;而中继与普通隧道都会把 `Host` 改写成公网名。任一条件不成立即 403。token 只存内存、30 秒过期、被一次 `pair.begin` 用掉即焚,同一条链接还会写进宿主日志——把那一行日志当作活着的密钥。
346
+ - **token 端点仅 loopback 可达,且看两个条件。** 来源地址必须是 loopback,且 `Host` header 必须写本机。经隧道的请求由本机的隧道客户端终结,所以对一条全互联网可达的请求,来源地址也读作 `127.0.0.1`;而中继与普通隧道都会把 `Host` 改写成公网名。任一条件不成立即 403。token 只存内存、30 秒过期、被一次 `pair.begin` 用掉即焚,本机链接还会写进宿主日志——把那一行日志当作活着的密钥。那一行里手机侧只有地址种类(`(phone: public)` 或 `(phone: lan)`,没有地址时不带后缀):这一行配对日志正是操作者会粘贴到别处的那一行,公网主机名或局域网字面量写在里面,就会比它对应的配对码活得更久。
347
347
  - **配对面板渲染的是一份活密钥,也仅止于此。** 它用同源请求读同一条仅 loopback 门禁的路由,所以在 `curl` 够得到的地方它才够得到,别处都不行。它不能签发设备令牌、不能消耗配对码、不能列名册、不能吊销设备:`pair.begin` 始终是手机那一侧的动作,吊销始终是改名册加重启宿主。二维码里装的是裸 token 或宿主自己那份 `{token,url}` 应答,因此本页的 `127.0.0.1` origin 永远不会被交给手机。
348
348
  - **未配对连接只有三个方法的白名单。** `hello`、`pair.begin`、`pair.finish`;其余方法在分发前即回 `unpaired`,因此没有设备令牌就够不到会话面、审批面与名册面。
349
349
  - **设备令牌只存哈希。** 名册保留公钥及其 SHA-256 指纹,从不存令牌本身,所以该文件不是凭据库。令牌丢失、轮换或被拒的处置就是重新配对——这是常规流程而非异常路径(重新签发一条 bootstrap 链接,或在桌面配对流程里重扫),且从不需要手工改名册。
package/lib/client.js CHANGED
@@ -1211,6 +1211,36 @@ window.__ModuleLoader__.load({
1211
1211
  });
1212
1212
  QRCodeSVG.displayName = "QRCodeSVG";
1213
1213
  //#endregion
1214
+ //#region src/core/pair-address.ts
1215
+ /**
1216
+ * Hosts a phone can only reach from the same network: the private IPv4 ranges,
1217
+ * the unspecified address, and the IPv6 loopback, unique-local and link-local
1218
+ * prefixes. IPv4-mapped IPv6 and anything else this does not place stays public,
1219
+ * because the failure this predicate may never have is printing a name the host
1220
+ * did not vouch for.
1221
+ */
1222
+ const LAN_HOST_RE = /^(?:localhost|0\.0\.0\.0|(?:(?:10|127)(?:\.\d{1,3}){3}|192\.168(?:\.\d{1,3}){2}|172\.(?:1[6-9]|2\d|3[01])(?:\.\d{1,3}){2}|169\.254(?:\.\d{1,3}){2})|\[(?:::1|f[cd][0-9a-f]{2}:|fe[89ab][0-9a-f]:)[0-9a-f:]*\])$/i;
1223
+ /** The hostname a URL carries, or null when the value is not a URL at all. */
1224
+ function hostnameOf(origin) {
1225
+ try {
1226
+ return new URL(origin).hostname;
1227
+ } catch {
1228
+ return null;
1229
+ }
1230
+ }
1231
+ /**
1232
+ * Whether a located origin answers only inside this network.
1233
+ * @param origin - the located origin, or null when there is none.
1234
+ * @param source - where the host said that origin came from.
1235
+ * @returns true when a phone must be on the same network to dial it.
1236
+ */
1237
+ function isLanOrigin(origin, source) {
1238
+ if (source === "lan") return true;
1239
+ if (origin === null) return false;
1240
+ const host = hostnameOf(origin);
1241
+ return host !== null && LAN_HOST_RE.test(host);
1242
+ }
1243
+ //#endregion
1214
1244
  //#region src/client/semantic.ts
1215
1245
  /**
1216
1246
  * Semantic attribute values for the protocol v1 pairing panel (contract:
@@ -1269,8 +1299,8 @@ window.__ModuleLoader__.load({
1269
1299
  //#region src/client/PairPanel.tsx
1270
1300
  /**
1271
1301
  * The protocol v1 pairing panel: the QR symbol, the countdown with its expiry
1272
- * state, the one address fact the reader must not miss, and the two actions that
1273
- * keep a fresh code on screen.
1302
+ * state, the line that says which kind of address the code carries, and the two
1303
+ * actions that keep a fresh code on screen.
1274
1304
  *
1275
1305
  * The shell is the official headless `Modal` and every action is the official
1276
1306
  * `Button`, so the overlay, the mask, the card, the focus trap, the Escape
@@ -1326,6 +1356,7 @@ window.__ModuleLoader__.load({
1326
1356
  const canCopy = !expired && payload !== "";
1327
1357
  const primaryLabel = state.kind === "failed" || state.kind === "unreachable" ? t("action.retry") : t("pair.refresh");
1328
1358
  const located = ready && state.pairingUrl !== null;
1359
+ const onLan = located && isLanOrigin(state.origin, state.originSource);
1329
1360
  (0, react.useLayoutEffect)(() => {
1330
1361
  const element = panel.current;
1331
1362
  if (element === null) return;
@@ -1452,7 +1483,11 @@ window.__ModuleLoader__.load({
1452
1483
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
1453
1484
  className: panel_module_css_default.address,
1454
1485
  "data-tone": located ? "plain" : "warning",
1455
- children: [ready && located && t("origin.located", { origin: state.origin ?? "" }), ready && !located && t("origin.missing", { host })]
1486
+ children: [
1487
+ ready && located && !onLan && t("origin.public"),
1488
+ ready && onLan && t("origin.lan", { origin: state.origin ?? "" }),
1489
+ ready && !located && t("origin.missing", { host })
1490
+ ]
1456
1491
  }),
1457
1492
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1458
1493
  className: panel_module_css_default.hint,
@@ -1574,6 +1609,7 @@ window.__ModuleLoader__.load({
1574
1609
  issuedAt,
1575
1610
  expiresAt: outcome.expiresAt,
1576
1611
  origin: outcome.origin,
1612
+ originSource: outcome.originSource,
1577
1613
  pairingUrl: outcome.pairingUrl
1578
1614
  };
1579
1615
  case "forbidden": return { kind: "forbidden" };
@@ -1678,22 +1714,6 @@ window.__ModuleLoader__.load({
1678
1714
  }
1679
1715
  //#endregion
1680
1716
  //#region src/client/pair-token.ts
1681
- /**
1682
- * The panel's one wire call: read the one-shot bootstrap token from this
1683
- * package's own Host route.
1684
- *
1685
- * The route is same-origin and document-relative (the GUI is served with
1686
- * `<base href="./">`, so a sub-path deployment resolves it against its entry
1687
- * directory instead of escaping to the origin root — the same rule
1688
- * `dsh-remote-web-ui`'s pair API follows). It is NOT consumed here: the panel
1689
- * only displays the secret, and the phone spends it in `pair.begin`, so a
1690
- * mis-click on "new code" voids a token without ever pairing a device.
1691
- *
1692
- * `403` is a fact, not an error: the loopback gate in `core/loopback.ts`
1693
- * refuses any page whose socket or `Host` is not this machine, which is exactly
1694
- * the case the panel must name out loud.
1695
- * @module dsh-remote-bridge/client/pair-token
1696
- */
1697
1717
  /** Document-relative form of the Host route, for a page served under any base. */
1698
1718
  const PAIR_TOKEN_URL = "/remote-bridge/pair/token".replace(/^\/+/, "");
1699
1719
  /** Read a string field, treating a missing, mistyped or empty value as absent. */
@@ -1751,12 +1771,15 @@ window.__ModuleLoader__.load({
1751
1771
  };
1752
1772
  const origin = stringOrNull(body.origin);
1753
1773
  const candidate = stringOrNull(body.pairingUrl);
1774
+ const pairingUrl = candidate !== null && /^wss?:\/\/\S+$/.test(candidate) ? candidate : null;
1775
+ const source = body.originSource;
1754
1776
  return {
1755
1777
  kind: "ok",
1756
1778
  token,
1757
1779
  expiresAt,
1758
1780
  origin,
1759
- pairingUrl: candidate !== null && /^wss?:\/\/\S+$/.test(candidate) ? candidate : null
1781
+ originSource: source === "realtime" || source === "env" || source === "lan" ? source : null,
1782
+ pairingUrl
1760
1783
  };
1761
1784
  }
1762
1785
  //#endregion
@@ -2248,11 +2271,15 @@ window.__ModuleLoader__.load({
2248
2271
  *
2249
2272
  * The panel has one job — put the live one-shot code in front of the operator as
2250
2273
  * a QR symbol — so its copy carries what to do with the symbol, how long it
2251
- * lives, which address the phone will actually dial, why the code is single-use,
2274
+ * lives, what kind of address the phone will dial, why the code is single-use,
2252
2275
  * and that the app is still in testing: the reader is told what they are joining
2253
- * and where to ask about it. No key states how the host finds its public
2254
- * address, and no key names the wire protocol: both are implementation facts the
2255
- * reader cannot act on.
2276
+ * and where to ask about it. No key renders the public origin: the symbol
2277
+ * already carries it, and a durable public hostname printed as text would
2278
+ * outlive every screenshot it appears in. A LAN literal is not that fact — it
2279
+ * answers only inside the network this page is already on — so the LAN line
2280
+ * keeps naming it. No key states how the host finds either address, and no key
2281
+ * names the wire protocol: both are implementation facts the reader cannot act
2282
+ * on.
2256
2283
  *
2257
2284
  * The card's keys say only what the transcript row can act on: whether the page
2258
2285
  * is still waiting for the operator, that it is over, that this desktop renders
@@ -2270,7 +2297,8 @@ window.__ModuleLoader__.load({
2270
2297
  "pair.expired": "配对码已过期",
2271
2298
  "pair.refresh": "重新取码",
2272
2299
  "pair.usedHint": "配对码一次性有效:iPhone 一开始配对就作废,重新取码也会作废上一张。",
2273
- "origin.located": "iPhone 将连到 {origin}",
2300
+ "origin.public": "二维码已包含公网地址,扫码后 iPhone 自动连上这台电脑",
2301
+ "origin.lan": "二维码指向局域网地址 {origin},iPhone 需与本机在同一网络",
2274
2302
  "origin.missing": "没有找到公网地址:先在 App 里把连接地址填成你的公网中继,再扫码。本页的 {host} 只有本机能连。",
2275
2303
  "community.invite": "iOS App 还在内测,欢迎来 Discord 交流",
2276
2304
  "forbidden.title": "这个页面不是从本机打开的",
@@ -2303,7 +2331,8 @@ window.__ModuleLoader__.load({
2303
2331
  "pair.expired": "The pairing code expired",
2304
2332
  "pair.refresh": "New code",
2305
2333
  "pair.usedHint": "The code is single-use: pairing spends it, and a new code voids the previous one.",
2306
- "origin.located": "The iPhone will dial {origin}",
2334
+ "origin.public": "The QR code carries the public address: the iPhone connects to this computer as soon as it scans",
2335
+ "origin.lan": "The QR code points at the LAN address {origin}: the iPhone must be on the same network",
2307
2336
  "origin.missing": "No public address found: set the connection address in the app to your public relay first, then scan. {host} (this page) is reachable only from this machine.",
2308
2337
  "community.invite": "The iOS app is in beta. Come talk to us on Discord",
2309
2338
  "forbidden.title": "This page is not open on this machine",