dsh-hiss-plugins 1.5.0 → 1.5.1
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 +4 -4
- package/lib/lan-access/index.js +61 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -361,9 +361,9 @@ colgrep command:"init" / command:"status" / command:"clear"
|
|
|
361
361
|
- **为什么是网关而不是改绑定**:桌面端内嵌的 host 固定 `--host 127.0.0.1 --port 0`,交给窗口的 URL 也固定是 `http://127.0.0.1:<端口>`;把 Host 改绑 LAN 地址会让桌面窗口连不上。所以这一行在同一个 host 进程里另开一个监听,转发到 loopback 上的 Host,并把 `Host`/`Origin` 改写成 loopback authority:既过 `dsh-client-connection` 的信任围栏,又让 cookie 绑定在稳定的 `127.0.0.1` 上(Host 的端口每次启动都变,绑端口会让 cookie 失效)。
|
|
362
362
|
- **地址与端口**:默认绑 `0.0.0.0`(所有 IPv4 网卡),端口默认 `7505`。二维码与 `/lan` 只使用**非虚拟网卡**:Hyper-V 的 `vEthernet (Default Switch)`、VPN 等对手机不可达,既不生成二维码也不在码页里列出(`/lan` 的文本报告仍会用一行说明哪些地址被忽略)。这样 Wi-Fi 重新拿地址(DHCP 换网段)也不会像绑具体地址那样报 `EADDRNOTAVAIL` 而静默失效;`/lan` 每次调用都重新读网卡,打印当前地址。若 7505 恰好被本机 Host 的 loopback 监听占用,会退回绑定当前 LAN 地址。要固定网卡或端口就在 profile 的 `cordis.patch.yml` 里给该行加 `config: { host: ..., port: ... }`(`port: 0` 交给系统分配,但地址就不稳定了)。
|
|
363
363
|
- **界面入口**:侧边栏底部、设置/用户之上新增一行「手机连接」(收起成 56px 窄条时是手机图标)。点它会先确认 `lan-access` 行已启用(没启用就经 `pluginManager.setPluginEnabled` 开启),然后在应用内弹出二维码弹窗;弹窗用同一个 Host 源上的 `/lan-access?embed=1` 页面(iframe),因此复用同一套 cookie 鉴权。若 profile 没有 HMR、开启需要重启,弹窗会直接说明而不是给一个空二维码。
|
|
364
|
-
- **配对(为什么二维码里没有 host token)**:二维码里放的是网关自己的一次性配对串 `?pair=…`,不是 Host 的 launch token。手机打开它时,**网关自己**拿当前进程的 token 去 loopback 换一次 cookie,把换来的 Host cookie 记在这个客户端地址名下,之后这个 IP 的每个请求(含 WebSocket upgrade)都由网关补上该 cookie
|
|
364
|
+
- **配对(为什么二维码里没有 host token)**:二维码里放的是网关自己的一次性配对串 `?pair=…`,不是 Host 的 launch token。手机打开它时,**网关自己**拿当前进程的 token 去 loopback 换一次 cookie,把换来的 Host cookie 记在这个客户端地址名下,之后这个 IP 的每个请求(含 WebSocket upgrade)都由网关补上该 cookie。那个带 token 的 URL 是**发 `webserver/entry-url` 收集来的**(Token 插件会把签名 URL 追进 entries;WebApp 与 remote-connection 也这么收)——DSH 0.2.2 起 Connection 不再提供 `authenticatedUrl`,而 Token 也没有暴露成服务,这是唯一不越权的取法。于是手机端既不需要保存 Host token,也不依赖浏览器 cookie 策略;换进程后重新打开二维码页即可(旧的 `pair` 会得到明确的 "pairing expired" 而不是 Host 那句通用 401)。
|
|
365
365
|
- **诊断**:在 profile 的 `cordis.patch.yml` 里给该行加 `config: { debug: true }`,网关会把"配对成功/失败"和所有 `>=400` 的转发结果写到 `~/.dsh/lan-access.log`(256KB 上限、不记录 token/pair 值)。默认关闭。
|
|
366
|
-
- **QR 页**:Host 自己的 loopback 端口上注册了 `/lan-access`,把当前每个 LAN 地址的配对 URL 渲染成内联 SVG
|
|
366
|
+
- **QR 页**:Host 自己的 loopback 端口上注册了 `/lan-access`,把当前每个 LAN 地址的配对 URL 渲染成内联 SVG 二维码。这条路由此声明 `auth: "required"`:DSH 0.2.2 起 Host 自己认证路由、并把已认证的 Peer 交给 handler(页面不再重复认证——重复调 `connection.admit` 在新版 Host 上只会拿到 401);更早的 Host 没有路由级认证,handler 才用 `connection.admit` 兜底。所以配对串不会出现在未认证的请求里。`?embed=1` 去掉页头与边距,供弹窗内嵌。二维码编码器(`lib/lan-access/qr.js`)是本包自带的字节模式实现,输出已对照独立编码器逐模块校验。
|
|
367
367
|
- **不重复开监听**:Host 本身已经绑在网络地址上时(`dsh web --host <地址>`),`/lan` 直接报那个地址,不再开第二个监听。
|
|
368
368
|
- **认证就是 Host 自己那套**:token → 签名 cookie,本功能不新增鉴权、也不放宽围栏。`Origin` 只在它与入站 `Host` 同源时才改写,跨站请求仍被 Host 的 Origin / `sec-fetch-site` 检查拒绝。
|
|
369
369
|
- **防火墙**:Windows 第一次监听会拦,管理员 PowerShell 放行一次:
|
|
@@ -410,8 +410,8 @@ test/ node:test:<feature>/ 九个目录 + manifest / patch / c
|
|
|
410
410
|
## 发布(给维护者)
|
|
411
411
|
|
|
412
412
|
```powershell
|
|
413
|
-
git tag dsh-hiss-plugins@1.5.
|
|
414
|
-
git push origin dsh-hiss-plugins@1.5.
|
|
413
|
+
git tag dsh-hiss-plugins@1.5.1 # 必须与本目录 package.json 的 version 逐字一致
|
|
414
|
+
git push origin dsh-hiss-plugins@1.5.1
|
|
415
415
|
```
|
|
416
416
|
|
|
417
417
|
CI(`.github/workflows/publish.yml`,Windows runner)解析 tag、跑全量测试,再用 **npm trusted publishing(OIDC,无需任何 token)** 发布;包内 `prepublishOnly` 会再跑一次 `npm test`。手工发布:`npm publish`(`publishConfig.access` 已设为 public),发版前先 `node ../scripts/smoke-profile.mjs` 走一遍真实安装 + 真启动。发布新版本前记得递增 `package.json` 的 `version`。
|
package/lib/lan-access/index.js
CHANGED
|
@@ -48,11 +48,35 @@ export function apply(ctx, config = {}) {
|
|
|
48
48
|
const connection = connectionCtx.connection;
|
|
49
49
|
const webServer = connectionCtx.get("webServer");
|
|
50
50
|
|
|
51
|
+
/**
|
|
52
|
+
* The URL a client opens to receive a browser cookie. DSH 0.2.2 moved browser
|
|
53
|
+
* auth into the Token provider and removed Connection's `authenticatedUrl`, so
|
|
54
|
+
* the signed URL is collected the documented way: emit `webserver/entry-url`
|
|
55
|
+
* and take the entry carrying the launch token (WebApp and the remote
|
|
56
|
+
* connection collect their entry URLs the same way).
|
|
57
|
+
* @param base - the advertised root without credentials.
|
|
58
|
+
* @returns the tokenized URL, or `base` when nothing signs one.
|
|
59
|
+
*/
|
|
60
|
+
const authenticatedUrl = (base) => {
|
|
61
|
+
if (webServer === undefined || typeof ctx.emit !== "function") return base;
|
|
62
|
+
const entries = [];
|
|
63
|
+
try {
|
|
64
|
+
ctx.emit(webServer, "webserver/entry-url", base, entries);
|
|
65
|
+
} catch {
|
|
66
|
+
return base;
|
|
67
|
+
}
|
|
68
|
+
return pickTokenUrl(entries, base);
|
|
69
|
+
};
|
|
70
|
+
|
|
51
71
|
if (webServer !== undefined && typeof webServer.register === "function") {
|
|
52
72
|
connectionCtx.effect(() => webServer.register({
|
|
53
73
|
kind: "exact",
|
|
54
74
|
path: PAGE_PATH,
|
|
55
|
-
|
|
75
|
+
// Hosts from 0.2.2 on admit every route themselves and hand the handler the
|
|
76
|
+
// admitted Peer; the page carries a pairing secret, so the requirement is
|
|
77
|
+
// declared here instead of being re-derived inside the handler.
|
|
78
|
+
auth: "required",
|
|
79
|
+
handler: (request, response, peer) => servePage(request, response, { state, connection, addresses: lanAddresses(), peer }),
|
|
56
80
|
}), "lan-access.page");
|
|
57
81
|
try {
|
|
58
82
|
state.pageUrl = new URL(PAGE_PATH, webServer.getOrigin()).href;
|
|
@@ -75,7 +99,7 @@ export function apply(ctx, config = {}) {
|
|
|
75
99
|
try {
|
|
76
100
|
const gateway = await bindGateway(server, port, host, {
|
|
77
101
|
pair,
|
|
78
|
-
tokenUrl: () =>
|
|
102
|
+
tokenUrl: () => authenticatedUrl(`${server.getOrigin()}/`),
|
|
79
103
|
log: debug ? writeLog : undefined,
|
|
80
104
|
});
|
|
81
105
|
if (debug) writeLog({ event: "listen", address: gateway.address, port: gateway.port });
|
|
@@ -99,7 +123,7 @@ export function apply(ctx, config = {}) {
|
|
|
99
123
|
name: "lan",
|
|
100
124
|
description: "Show the LAN URL (and QR page) a phone can use for this Web GUI",
|
|
101
125
|
handler: (invocation) => (invocation.rawInput.trim() === ""
|
|
102
|
-
? report(state,
|
|
126
|
+
? report(state, authenticatedUrl, lanAddresses())
|
|
103
127
|
: { kind: "error", text: "Usage: /lan (no arguments)" }),
|
|
104
128
|
});
|
|
105
129
|
});
|
|
@@ -132,11 +156,11 @@ async function bindGateway(server, port, pinned, pairing) {
|
|
|
132
156
|
* Build the `/lan` answer from the listener's current state; LAN addresses are
|
|
133
157
|
* read at call time, not at boot, so a DHCP change shows up instead of going stale.
|
|
134
158
|
* @param {{ status: string, error?: string, bindHost?: string, port?: number, pageUrl?: string }} state - the listener state.
|
|
135
|
-
* @param {
|
|
159
|
+
* @param {(base: string) => string} authenticatedUrl - signs one URL with this process's launch token.
|
|
136
160
|
* @param {{ name: string, address: string }[]} addresses - the current LAN addresses.
|
|
137
161
|
* @returns {{ kind: "success" | "error", text: string }} the command result.
|
|
138
162
|
*/
|
|
139
|
-
export function report(state,
|
|
163
|
+
export function report(state, authenticatedUrl, addresses) {
|
|
140
164
|
if (state.status === "listening") {
|
|
141
165
|
const physical = addresses.filter((entry) => entry.virtual !== true);
|
|
142
166
|
const ignored = addresses.filter((entry) => entry.virtual === true);
|
|
@@ -152,7 +176,7 @@ export function report(state, connection, addresses) {
|
|
|
152
176
|
return { kind: "success", text: lines.join("\n") };
|
|
153
177
|
}
|
|
154
178
|
if (state.status === "direct") {
|
|
155
|
-
const url =
|
|
179
|
+
const url = authenticatedUrl(`http://${state.bindHost}:${String(state.port)}/`);
|
|
156
180
|
return { kind: "success", text: `The Host already listens on a network address: ${url}` };
|
|
157
181
|
}
|
|
158
182
|
if (state.status === "failed") return { kind: "error", text: `LAN access is not running: ${state.error}. Set \`host\` or \`port\` in the profile patch and reload the row.` };
|
|
@@ -161,22 +185,40 @@ export function report(state, connection, addresses) {
|
|
|
161
185
|
}
|
|
162
186
|
|
|
163
187
|
/**
|
|
164
|
-
*
|
|
188
|
+
* Pick the entry URL that carries this process's launch token.
|
|
189
|
+
* @param {readonly { url?: string }[]} entries - rows `webserver/entry-url` collected.
|
|
190
|
+
* @param {string} base - the URL to keep when no provider signs one.
|
|
191
|
+
* @returns the tokenized URL, or `base`.
|
|
192
|
+
*/
|
|
193
|
+
export function pickTokenUrl(entries, base) {
|
|
194
|
+
for (const entry of entries) {
|
|
195
|
+
if (typeof entry?.url === "string" && /[?&]token=/u.test(entry.url)) return entry.url;
|
|
196
|
+
}
|
|
197
|
+
return base;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Serve the QR page to an authenticated owner only: it carries the pairing secret.
|
|
165
202
|
* @param {import("node:http").IncomingMessage} request - the page request.
|
|
166
203
|
* @param {import("node:http").ServerResponse} response - the answer.
|
|
167
|
-
* @param {{ state: object, connection: object, addresses: { name: string, address: string }[] }} deps - listener state, browser auth,
|
|
204
|
+
* @param {{ state: object, connection: object, addresses: { name: string, address: string }[], peer?: object }} deps - listener state, browser auth, the LAN addresses to show, and the Peer the Host already admitted.
|
|
168
205
|
*/
|
|
169
|
-
export function servePage(request, response, { state, connection, addresses }) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
admission
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
206
|
+
export function servePage(request, response, { state, connection, addresses, peer }) {
|
|
207
|
+
// Hosts from 0.2.2 on move browser auth into the route and hand the handler the
|
|
208
|
+
// admitted Peer; asking `connection.admit` again for that same request fails there.
|
|
209
|
+
// An older Host admits no route, so the handler stays the only gate and checks.
|
|
210
|
+
if (peer === undefined) {
|
|
211
|
+
let admission;
|
|
212
|
+
try {
|
|
213
|
+
admission = connection.admit(request);
|
|
214
|
+
} catch {
|
|
215
|
+
admission = { rejection: 401 };
|
|
216
|
+
}
|
|
217
|
+
if (admission.rejection !== undefined) {
|
|
218
|
+
response.writeHead(admission.rejection, { "content-type": "text/plain; charset=utf-8", "cache-control": "no-store" });
|
|
219
|
+
response.end(admission.rejection === 401 ? "Open this page from the DSH window on this computer.\n" : "forbidden\n");
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
180
222
|
}
|
|
181
223
|
let embed = false;
|
|
182
224
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-hiss-plugins",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "dsh-hiss-plugins — one DeepSeek Harness bundle carrying nine independently switchable plugins (colgrep, codegraph, project-mcp, git-bash, superpowers, ponytail, init, fix, lan-access) plus a management tab in the Plugins page.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|