dsh-hiss-plugins 1.3.1 → 1.4.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 +37 -11
- package/cordis.patch.yml +7 -0
- package/lib/client.js +260 -6
- package/lib/lan-access/gateway.js +348 -0
- package/lib/lan-access/index.js +298 -0
- package/lib/lan-access/qr.js +442 -0
- package/locale/en.json +15 -3
- package/locale/zh.json +15 -3
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# dsh-hiss-plugins
|
|
2
2
|
|
|
3
|
-
一个 DeepSeek Harness **bundle
|
|
3
|
+
一个 DeepSeek Harness **bundle 插件**,把九个功能装在一个包里:**colgrep**(语义代码检索)、**codegraph**(代码图 MCP)、**project-mcp**(项目 `.mcp.json`)、**git-bash**(Windows 上的 Git Bash shell)、**superpowers**(superpowers 技能常驻引导)、**ponytail**(ponytail 采纳提示与 `/ponytail` 等级切换)、**init**(读项目生成 `AGENTS.md`)、**fix**(先查根因、确认后再修)、**lan-access**(手机通过局域网打开本 GUI)。九个功能各占一条顶层行,可以在 **Plugins 页**里单独开关;包还带一个管理标签,就挂在那个页面上。
|
|
4
4
|
|
|
5
5
|
安装后对 `web`、`headless` 等任意 profile 的**所有 preset、所有会话**生效。
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## 十条行与九个开关
|
|
8
8
|
|
|
9
|
-
`cordis.patch.yml` 只做一件事:`insert`
|
|
9
|
+
`cordis.patch.yml` 只做一件事:`insert` 十条**顶层行**。宿主用 `name`(模块说明符)解析模块,用 `id` 记住开关状态。
|
|
10
10
|
|
|
11
11
|
| 行 id | 模块 | 作用 | 默认 |
|
|
12
12
|
|---|---|---|---|
|
|
@@ -19,8 +19,9 @@
|
|
|
19
19
|
| `dsh-hiss-plugins-ponytail` | `dsh-hiss-plugins/ponytail` | ponytail 采纳提示(随等级变化)+ 宿主 `/ponytail` 等级命令 | 开 |
|
|
20
20
|
| `dsh-hiss-plugins-init` | `dsh-hiss-plugins/init` | 宿主 `/init` 命令:读项目、生成/更新 `AGENTS.md` | 开 |
|
|
21
21
|
| `dsh-hiss-plugins-fix` | `dsh-hiss-plugins/fix` | 宿主 `/fix` 命令:先查根因并报告,确认后才修复 | 开 |
|
|
22
|
+
| `dsh-hiss-plugins-lan-access` | `dsh-hiss-plugins/lan-access` | 局域网网关:把 loopback 上的 GUI 转给手机,`/lan` 打印配对地址 | 关 |
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
**九条功能行就是 Plugins 页里那九个开关。** 载体行不在标签的开关列表里 —— 它是空的 host 半,但只有它在,浏览器半才会被送进页面;关掉它,管理标签本身就没了。
|
|
24
25
|
|
|
25
26
|
为什么必须是顶层行:插件管理器只为「组合后的 patch 里存在同 `id`、同 `name`,且挂载后父 entry 就是 profile 的 `include`」的行持久化开关。包在 `cordis:group` 里的子行在 `listPlugins()` 里被判为 `unaddressable`,**永远不会有开关**。所以这里没有组:git-bash 行把 realm 隔离写在自己身上(见下)。
|
|
26
27
|
|
|
@@ -51,7 +52,7 @@ dsh plugin --profile web remove dsh-hiss-plugins
|
|
|
51
52
|
|
|
52
53
|
## 管理标签(浏览器半)
|
|
53
54
|
|
|
54
|
-
Plugins 页(侧边栏 **插件**)里多出一个 `dsh-hiss-plugins`
|
|
55
|
+
Plugins 页(侧边栏 **插件**)里多出一个 `dsh-hiss-plugins` 标签,列出上面九条功能行与它们的开关。
|
|
55
56
|
|
|
56
57
|
- 浏览器半是 **`lib/client.js`** —— 手写的 lazy-CJS bundle,没有构建步骤:`window.__ModuleLoader__.load({ id: "dsh-hiss-plugins", factory })` 只注册工厂,模块体(slot 注册、locale 字典)在首次被 require 时执行。`id` 必须逐字等于包名(客户端图里的行 id 就是包名)。
|
|
57
58
|
- `package.json` 里 `dsh.client.platform = "web"`、`exports["./client"]` 指向 `lib/client.js`;客户端模块系统按 Loader 行扫描,**只有本包有行挂载,这个文件才会被送进浏览器**。
|
|
@@ -347,6 +348,30 @@ colgrep command:"init" / command:"status" / command:"clear"
|
|
|
347
348
|
|
|
348
349
|
验证:在一个已知会失败的测试或小 bug 上执行 `/fix`,模型应先给出根因报告且不修改文件;回复“修吧”后,模型才实施修复并跑相关检查。
|
|
349
350
|
|
|
351
|
+
## 功能:lan-access(手机通过局域网访问)
|
|
352
|
+
|
|
353
|
+
监听本机的局域网(所有 IPv4 网卡),把桌面端(或任何 web profile)正在跑的那套 GUI 转给同一网络里的手机:**`/lan`** 打印带 token 的地址,本机 window 里打开它给出的 **QR 页**(`/lan-access`)用手机扫一下即可(签名 cookie 有效期 30 天)。这一行**默认关闭** —— 在用户网络上开监听是用户自己的决定。
|
|
354
|
+
|
|
355
|
+
- **为什么是网关而不是改绑定**:桌面端内嵌的 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 失效)。
|
|
356
|
+
- **地址与端口**:默认绑 `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` 交给系统分配,但地址就不稳定了)。
|
|
357
|
+
- **界面入口**:侧边栏底部、设置/用户之上新增一行「手机连接」(收起成 56px 窄条时是手机图标)。点它会先确认 `lan-access` 行已启用(没启用就经 `pluginManager.setPluginEnabled` 开启),然后在应用内弹出二维码弹窗;弹窗用同一个 Host 源上的 `/lan-access?embed=1` 页面(iframe),因此复用同一套 cookie 鉴权。若 profile 没有 HMR、开启需要重启,弹窗会直接说明而不是给一个空二维码。
|
|
358
|
+
- **配对(为什么二维码里没有 host token)**:二维码里放的是网关自己的一次性配对串 `?pair=…`,不是 Host 的 launch token。手机打开它时,**网关自己**拿当前进程的 token 去 loopback 换一次 cookie,把换来的 Host cookie 记在这个客户端地址名下,之后这个 IP 的每个请求(含 WebSocket upgrade)都由网关补上该 cookie。于是手机端既不需要保存 Host token,也不依赖浏览器 cookie 策略;换进程后重新打开二维码页即可(旧的 `pair` 会得到明确的 "pairing expired" 而不是 Host 那句通用 401)。
|
|
359
|
+
- **诊断**:在 profile 的 `cordis.patch.yml` 里给该行加 `config: { debug: true }`,网关会把"配对成功/失败"和所有 `>=400` 的转发结果写到 `~/.dsh/lan-access.log`(256KB 上限、不记录 token/pair 值)。默认关闭。
|
|
360
|
+
- **QR 页**:Host 自己的 loopback 端口上注册了 `/lan-access`,把当前每个 LAN 地址的配对 URL 渲染成内联 SVG 二维码;页面只认 `dsh-client-connection` 的 cookie(`admit`),所以配对串不会出现在未认证的请求里。`?embed=1` 去掉页头与边距,供弹窗内嵌。二维码编码器(`lib/lan-access/qr.js`)是本包自带的字节模式实现,输出已对照独立编码器逐模块校验。
|
|
361
|
+
- **不重复开监听**:Host 本身已经绑在网络地址上时(`dsh web --host <地址>`),`/lan` 直接报那个地址,不再开第二个监听。
|
|
362
|
+
- **认证就是 Host 自己那套**:token → 签名 cookie,本功能不新增鉴权、也不放宽围栏。`Origin` 只在它与入站 `Host` 同源时才改写,跨站请求仍被 Host 的 Origin / `sec-fetch-site` 检查拒绝。
|
|
363
|
+
- **防火墙**:Windows 第一次监听会拦,管理员 PowerShell 放行一次:
|
|
364
|
+
|
|
365
|
+
```powershell
|
|
366
|
+
New-NetFirewallRule -DisplayName "DSH LAN" -Direction Inbound -Protocol TCP -LocalPort 7505 -Action Allow -Profile Any
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
很多 Wi-Fi 会被 Windows 标成 **Public**,只写 `-Profile Private` 时规则不生效;`-Profile Any` 两个都覆盖。若安装时已经给应用本身点过「允许访问」,那条程序级规则(TCP 任意端口)通常已经放行。
|
|
370
|
+
|
|
371
|
+
- **明文的取舍**:局域网内是 `http://`,token 与 cookie 没有 TLS 保护,同网段可嗅探;只在可信网络用,公司/公共 Wi-Fi 下关掉这一行。手机端是非安全上下文:`navigator.clipboard` 不可用(复制按钮可能失灵)、装不成 PWA;GUI 是桌面优先布局,手机上偏挤。
|
|
372
|
+
- **局限**:换 LAN IP(DHCP)后手机要用新地址(重新扫码即可,服务端 cookie 绑的是 `127.0.0.1`,重启/换端口不影响已配对设备)。token 每次重启都变。`/lan` 与 QR 页的输出会进会话日志(进程级 token,重启即失效)。
|
|
373
|
+
- **不想装插件**:也可以直接跑一个独立实例 `dsh --profile web --host <LAN-IP> --port 7505`(反代场景再加 `--trusted-host`),启动时它自己打印带 token 的 URL;代价是另起一个 host 进程、和桌面端写同一份会话存储。
|
|
374
|
+
|
|
350
375
|
## 开发与测试
|
|
351
376
|
|
|
352
377
|
```powershell
|
|
@@ -357,8 +382,8 @@ pnpm test # 在包目录内也可:node --test-isolation=none --test
|
|
|
357
382
|
结构:
|
|
358
383
|
|
|
359
384
|
```text
|
|
360
|
-
package.json
|
|
361
|
-
cordis.patch.yml
|
|
385
|
+
package.json 十条行的 bundle 声明(dsh.bundle.patch)+ 浏览器半声明(dsh.client)+ exports/files
|
|
386
|
+
cordis.patch.yml 十条顶层行(载体 + 九个功能)
|
|
362
387
|
lib/index.js 载体行:空 host 半
|
|
363
388
|
lib/client.js 浏览器半:Plugins 页管理标签(手写 lazy-CJS,无构建步骤)
|
|
364
389
|
lib/colgrep/ colgrep 工具
|
|
@@ -369,17 +394,18 @@ lib/superpowers/ 常驻引导提示词段(只注册 systemPrompt 段,
|
|
|
369
394
|
lib/ponytail/ lib/mode.js 纯逻辑(等级解析与默认值)+ lib/index.js 提示词段与 /ponytail 命令
|
|
370
395
|
lib/init/ lib/prompt.js 纯逻辑(/init 指令正文)+ lib/index.js 命令接缝
|
|
371
396
|
lib/fix/ lib/prompt.js 纯逻辑(/fix 诊断工作流正文)+ lib/index.js 命令接缝
|
|
397
|
+
lib/lan-access/ lib/gateway.js 纯 Node 转发器 + lib/qr.js 二维码编码器(均无宿主导入)+ lib/index.js 行、/lan 与 QR 页
|
|
372
398
|
locale/*.json 管理标签的文案字典
|
|
373
|
-
test/ node:test:<feature>/
|
|
399
|
+
test/ node:test:<feature>/ 九个目录 + manifest / patch / client 三个契约测试
|
|
374
400
|
```
|
|
375
401
|
|
|
376
|
-
`lib/project-mcp/config.js`、`lib/gitbash/resolve.js`、`lib/ponytail/mode.js`、`lib/init/prompt.js` 与 `lib/
|
|
402
|
+
`lib/project-mcp/config.js`、`lib/gitbash/resolve.js`、`lib/ponytail/mode.js`、`lib/init/prompt.js`、`lib/fix/prompt.js`、`lib/lan-access/gateway.js` 与 `lib/lan-access/qr.js` 刻意不导入任何宿主包,所以这些纯逻辑分支可以在没有 dsh 安装的环境里完整跑测试;宿主接缝由各功能的 `index.js` 承担。浏览器半用 fake `window.__ModuleLoader__` + fake `ctx` 测注册与远程调用,不启动浏览器。测试全部离线,不联网、不依赖 `colgrep`/`codegraph` CLI。
|
|
377
403
|
|
|
378
404
|
## 发布(给维护者)
|
|
379
405
|
|
|
380
406
|
```powershell
|
|
381
|
-
git tag dsh-hiss-plugins@1.
|
|
382
|
-
git push origin dsh-hiss-plugins@1.
|
|
407
|
+
git tag dsh-hiss-plugins@1.4.0 # 必须与本目录 package.json 的 version 逐字一致
|
|
408
|
+
git push origin dsh-hiss-plugins@1.4.0
|
|
383
409
|
```
|
|
384
410
|
|
|
385
411
|
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/cordis.patch.yml
CHANGED
|
@@ -43,3 +43,10 @@
|
|
|
43
43
|
|
|
44
44
|
- id: dsh-hiss-plugins-fix
|
|
45
45
|
name: 'dsh-hiss-plugins/fix'
|
|
46
|
+
|
|
47
|
+
# The LAN gateway is off by default: enabling a row is the user's decision to
|
|
48
|
+
# put a listener on their network. It serves plain HTTP and the Host's own
|
|
49
|
+
# token/cookie is the only authentication, so nobody should opt in for them.
|
|
50
|
+
- id: dsh-hiss-plugins-lan-access
|
|
51
|
+
name: 'dsh-hiss-plugins/lan-access'
|
|
52
|
+
disabled: true
|
package/lib/client.js
CHANGED
|
@@ -36,6 +36,7 @@ window.__ModuleLoader__.load({
|
|
|
36
36
|
{ key: "ponytail", moduleName: `${PACKAGE_ID}/ponytail`, description: "featurePonytailDescription" },
|
|
37
37
|
{ key: "init", moduleName: `${PACKAGE_ID}/init`, description: "featureInitDescription" },
|
|
38
38
|
{ key: "fix", moduleName: `${PACKAGE_ID}/fix`, description: "featureFixDescription" },
|
|
39
|
+
{ key: "lan-access", moduleName: `${PACKAGE_ID}/lan-access`, description: "featureLanAccessDescription" },
|
|
39
40
|
];
|
|
40
41
|
/** The same features keyed by the name a card shows. */
|
|
41
42
|
const FEATURE_BY_KEY = new Map(FEATURES.map((feature) => [feature.key, feature]));
|
|
@@ -52,6 +53,15 @@ window.__ModuleLoader__.load({
|
|
|
52
53
|
const NOTICE_STYLE = { margin: 0, color: "var(--dsw-alias-label-secondary, var(--dsw-alias-label-tertiary))", fontSize: "13px", lineHeight: "20px" };
|
|
53
54
|
const REASON_STYLE = { color: "var(--dsw-alias-label-tertiary)", fontSize: "12px", lineHeight: "18px", maxWidth: "220px" };
|
|
54
55
|
const BUTTON_STYLE = { border: "0.5px solid var(--dsw-alias-border-l3)", borderRadius: "6px", color: "var(--dsw-alias-label-primary)", font: "inherit", cursor: "pointer", background: "none", padding: "4px 10px" };
|
|
56
|
+
/** Sidebar-foot action: icon in the rail, icon + label in a wide column. */
|
|
57
|
+
const LAN_BUTTON_STYLE = { display: "inline-flex", alignItems: "center", justifyContent: "center", gap: "8px", height: "32px", padding: "0 8px", border: "none", borderRadius: "8px", background: "transparent", color: "var(--dsw-alias-label-secondary, var(--dsw-alias-label-tertiary))", font: "inherit", fontSize: "13px", cursor: "pointer", whiteSpace: "nowrap" };
|
|
58
|
+
const LAN_RAIL_STYLE = { width: "32px", padding: "0" };
|
|
59
|
+
/** Frame-wide click-catcher for the phone-link popup. */
|
|
60
|
+
const LAN_OVERLAY_STYLE = { position: "fixed", inset: "0", zIndex: 2147483000, display: "flex", alignItems: "center", justifyContent: "center", background: "rgba(0, 0, 0, 0.45)", pointerEvents: "auto" };
|
|
61
|
+
const LAN_DIALOG_STYLE = { width: "380px", maxWidth: "calc(100vw - 32px)", maxHeight: "calc(100vh - 48px)", overflow: "auto", display: "flex", flexDirection: "column", gap: "12px", padding: "16px", borderRadius: "12px", background: "var(--dsw-alias-bg-primary, #fff)", color: "var(--dsw-alias-label-primary)", boxShadow: "0 18px 48px rgba(0, 0, 0, 0.28)" };
|
|
62
|
+
const LAN_HEADER_STYLE = { display: "flex", alignItems: "center", justifyContent: "space-between", gap: "12px" };
|
|
63
|
+
const LAN_HINT_STYLE = { margin: 0, color: "var(--dsw-alias-label-tertiary)", fontSize: "13px", lineHeight: "20px" };
|
|
64
|
+
const LAN_FRAME_STYLE = { width: "100%", height: "360px", border: "none", borderRadius: "8px", background: "#fff", display: "block" };
|
|
55
65
|
|
|
56
66
|
/**
|
|
57
67
|
* Copy for the management tab; the `locale/*.json` files carry the same entries, where the
|
|
@@ -79,6 +89,18 @@ window.__ModuleLoader__.load({
|
|
|
79
89
|
featurePonytailDescription: "ponytail 采纳提示与 /ponytail 等级切换",
|
|
80
90
|
featureInitDescription: "生成或更新项目 AGENTS.md(/init)",
|
|
81
91
|
featureFixDescription: "先查根因并报告,确认后再修复(/fix)",
|
|
92
|
+
featureLanAccessDescription: "让手机在同一局域网打开本 GUI(/lan 给出带 token 的地址)",
|
|
93
|
+
lanButton: "手机连接",
|
|
94
|
+
lanButtonAria: "用手机通过局域网连接:打开二维码",
|
|
95
|
+
lanTitle: "手机扫码连接",
|
|
96
|
+
lanClose: "关闭",
|
|
97
|
+
lanLoading: "正在开启局域网访问…",
|
|
98
|
+
lanHint: "手机与电脑连同一个网络,用相机扫码打开;打开一次后 30 天内免 token。",
|
|
99
|
+
lanRestart: "已开启局域网访问,但需要重启 DSH 后二维码才可用。",
|
|
100
|
+
lanFailed: "无法开启局域网访问:{error}",
|
|
101
|
+
lanNotInstalled: "这个 profile 里没有 lan-access 行。",
|
|
102
|
+
lanReadOnly: "无法在这个页面启用 lan-access 行({reason})。",
|
|
103
|
+
lanFrameFailed: "二维码页没有响应;请先打开 /lan-access 检查原因。",
|
|
82
104
|
};
|
|
83
105
|
/** English dictionary checked against the Chinese key set. */
|
|
84
106
|
const en = {
|
|
@@ -102,6 +124,18 @@ window.__ModuleLoader__.load({
|
|
|
102
124
|
featurePonytailDescription: "ponytail adoption hint and /ponytail level switching",
|
|
103
125
|
featureInitDescription: "generates or updates the project's AGENTS.md (/init)",
|
|
104
126
|
featureFixDescription: "diagnoses the root cause and waits for confirmation before fixing (/fix)",
|
|
127
|
+
featureLanAccessDescription: "opens this GUI from a phone on the same network (/lan prints the tokenized URL)",
|
|
128
|
+
lanButton: "Phone link",
|
|
129
|
+
lanButtonAria: "Connect a phone over the LAN: show the QR code",
|
|
130
|
+
lanTitle: "Scan to connect a phone",
|
|
131
|
+
lanClose: "Close",
|
|
132
|
+
lanLoading: "Enabling LAN access…",
|
|
133
|
+
lanHint: "Keep the phone on the same network and scan with the camera; after one open the token is not needed for 30 days.",
|
|
134
|
+
lanRestart: "LAN access is enabled, but DSH must restart before the QR code is available.",
|
|
135
|
+
lanFailed: "Could not enable LAN access: {error}",
|
|
136
|
+
lanNotInstalled: "This profile has no lan-access row.",
|
|
137
|
+
lanReadOnly: "The lan-access row cannot be enabled from here ({reason}).",
|
|
138
|
+
lanFrameFailed: "The QR page did not answer; open /lan-access to see why.",
|
|
105
139
|
};
|
|
106
140
|
|
|
107
141
|
/** Read one thrown value as text. */
|
|
@@ -324,14 +358,187 @@ window.__ModuleLoader__.load({
|
|
|
324
358
|
});
|
|
325
359
|
}
|
|
326
360
|
|
|
327
|
-
/** Host command whose run this browser half projects into the chat view. */
|
|
328
|
-
const MCP_COMMAND = "mcp";
|
|
329
361
|
/**
|
|
330
|
-
*
|
|
362
|
+
* Values apply() hands the two slot components. They live at module scope because the
|
|
363
|
+
* sidebar action and the overlay host are separate slot occupants with no shared props.
|
|
364
|
+
*/
|
|
365
|
+
const lanUi = {
|
|
366
|
+
store: null,
|
|
367
|
+
t: (key) => key,
|
|
368
|
+
ensureEnabled: async () => "enabled",
|
|
369
|
+
probe: async () => ({ ok: false, message: "" }),
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Popup state shared by the sidebar action and its overlay host: the two live in
|
|
374
|
+
* different slots, so neither can own React state for the other.
|
|
375
|
+
* @returns a tiny external store.
|
|
376
|
+
*/
|
|
377
|
+
function createPopupStore() {
|
|
378
|
+
let open = false;
|
|
379
|
+
const listeners = new Set();
|
|
380
|
+
return {
|
|
381
|
+
get: () => open,
|
|
382
|
+
set(value) {
|
|
383
|
+
const next = value === true;
|
|
384
|
+
if (next === open) return;
|
|
385
|
+
open = next;
|
|
386
|
+
for (const listener of [...listeners]) listener();
|
|
387
|
+
},
|
|
388
|
+
listen(listener) {
|
|
389
|
+
listeners.add(listener);
|
|
390
|
+
return () => {
|
|
391
|
+
listeners.delete(listener);
|
|
392
|
+
};
|
|
393
|
+
},
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Subscribe a component to the popup store.
|
|
399
|
+
* @param store - the shared store.
|
|
400
|
+
* @returns whether the popup is open.
|
|
401
|
+
*/
|
|
402
|
+
function usePopupOpen(store) {
|
|
403
|
+
const [open, setOpen] = React.useState(store.get());
|
|
404
|
+
React.useEffect(() => store.listen(() => setOpen(store.get())), []);
|
|
405
|
+
return open;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/** A phone outline for the sidebar action. */
|
|
409
|
+
function PhoneIcon() {
|
|
410
|
+
return jsx("svg", {
|
|
411
|
+
width: 16,
|
|
412
|
+
height: 16,
|
|
413
|
+
viewBox: "0 0 24 24",
|
|
414
|
+
fill: "none",
|
|
415
|
+
stroke: "currentColor",
|
|
416
|
+
strokeWidth: 1.8,
|
|
417
|
+
strokeLinecap: "round",
|
|
418
|
+
strokeLinejoin: "round",
|
|
419
|
+
"aria-hidden": "true",
|
|
420
|
+
children: [
|
|
421
|
+
jsx("rect", { x: 6, y: 2, width: 12, height: 20, rx: 3, key: "body" }),
|
|
422
|
+
jsx("path", { d: "M11 18h2", key: "home" }),
|
|
423
|
+
],
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* The sidebar-foot action that opens the phone-link popup.
|
|
429
|
+
* @param props - `store`, the bound `t`, and the owner's column width state.
|
|
430
|
+
*/
|
|
431
|
+
function LanAccessButton({ wide }) {
|
|
432
|
+
const { store, t } = lanUi;
|
|
433
|
+
const open = usePopupOpen(store);
|
|
434
|
+
return jsx("button", {
|
|
435
|
+
type: "button",
|
|
436
|
+
title: t("lanButton"),
|
|
437
|
+
"aria-label": t("lanButtonAria"),
|
|
438
|
+
"aria-expanded": open,
|
|
439
|
+
style: wide ? LAN_BUTTON_STYLE : { ...LAN_BUTTON_STYLE, ...LAN_RAIL_STYLE },
|
|
440
|
+
onClick: () => store.set(true),
|
|
441
|
+
children: [
|
|
442
|
+
jsx(PhoneIcon, { key: "icon" }),
|
|
443
|
+
wide ? jsx("span", {
|
|
444
|
+
key: "label",
|
|
445
|
+
children: t("lanButton")
|
|
446
|
+
}) : null
|
|
447
|
+
]
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* The frame-wide popup: enabling the row, waiting for the page, and showing the QR.
|
|
453
|
+
* @param props - `store`, the bound `t`, `ensureEnabled`, and `probe`.
|
|
454
|
+
*/
|
|
455
|
+
function LanAccessPopup() {
|
|
456
|
+
const { store, t, ensureEnabled, probe } = lanUi;
|
|
457
|
+
const open = usePopupOpen(store);
|
|
458
|
+
const [state, setState] = React.useState({ status: "idle" });
|
|
459
|
+
const [frameHeight, setFrameHeight] = React.useState(360);
|
|
460
|
+
React.useEffect(() => {
|
|
461
|
+
if (!open) return undefined;
|
|
462
|
+
let current = true;
|
|
463
|
+
setState({ status: "loading" });
|
|
464
|
+
Promise.resolve().then(ensureEnabled).then((outcome) => {
|
|
465
|
+
if (!current) return undefined;
|
|
466
|
+
if (outcome === "restart-required") {
|
|
467
|
+
setState({ status: "restart" });
|
|
468
|
+
return undefined;
|
|
469
|
+
}
|
|
470
|
+
return probe().then((answer) => {
|
|
471
|
+
if (!current) return;
|
|
472
|
+
setState(answer.ok ? { status: "ready", src: answer.url } : { status: "error", message: answer.message });
|
|
473
|
+
});
|
|
474
|
+
}).catch((error) => {
|
|
475
|
+
if (current) setState({ status: "error", message: messageOf(error) });
|
|
476
|
+
});
|
|
477
|
+
return () => {
|
|
478
|
+
current = false;
|
|
479
|
+
};
|
|
480
|
+
}, [open, ensureEnabled, probe]);
|
|
481
|
+
React.useEffect(() => {
|
|
482
|
+
if (!open) return undefined;
|
|
483
|
+
const onKey = (event) => {
|
|
484
|
+
if (event.key === "Escape") store.set(false);
|
|
485
|
+
};
|
|
486
|
+
globalThis.window?.addEventListener?.("keydown", onKey);
|
|
487
|
+
return () => globalThis.window?.removeEventListener?.("keydown", onKey);
|
|
488
|
+
}, [open, store]);
|
|
489
|
+
if (!open) return null;
|
|
490
|
+
return jsx("div", {
|
|
491
|
+
role: "presentation",
|
|
492
|
+
style: LAN_OVERLAY_STYLE,
|
|
493
|
+
onClick: () => store.set(false),
|
|
494
|
+
children: jsxs("div", {
|
|
495
|
+
role: "dialog",
|
|
496
|
+
"aria-modal": "true",
|
|
497
|
+
"aria-label": t("lanTitle"),
|
|
498
|
+
style: LAN_DIALOG_STYLE,
|
|
499
|
+
onClick: (event) => event.stopPropagation(),
|
|
500
|
+
children: [
|
|
501
|
+
jsxs("div", {
|
|
502
|
+
style: LAN_HEADER_STYLE,
|
|
503
|
+
children: [jsx("strong", { children: t("lanTitle") }), jsx("button", {
|
|
504
|
+
type: "button",
|
|
505
|
+
style: BUTTON_STYLE,
|
|
506
|
+
onClick: () => store.set(false),
|
|
507
|
+
children: t("lanClose")
|
|
508
|
+
})]
|
|
509
|
+
}),
|
|
510
|
+
state.status === "loading" ? jsx("p", { role: "status", style: LAN_HINT_STYLE, children: t("lanLoading") }) : null,
|
|
511
|
+
state.status === "restart" ? jsx("p", { role: "alert", style: LAN_HINT_STYLE, children: t("lanRestart") }) : null,
|
|
512
|
+
state.status === "error" ? jsx("p", { role: "alert", style: LAN_HINT_STYLE, children: t("lanFailed", { error: state.message }) }) : null,
|
|
513
|
+
state.status === "ready" ? jsx("iframe", {
|
|
514
|
+
title: t("lanTitle"),
|
|
515
|
+
src: state.src,
|
|
516
|
+
style: { ...LAN_FRAME_STYLE, height: `${String(frameHeight)}px` },
|
|
517
|
+
onLoad: (event) => {
|
|
518
|
+
// Same origin, so the document height is readable: the frame is cut
|
|
519
|
+
// to its content and the dialog never grows a second scrollbar.
|
|
520
|
+
try {
|
|
521
|
+
const measured = event?.currentTarget?.contentDocument?.documentElement?.scrollHeight;
|
|
522
|
+
if (typeof measured === "number" && measured > 0) setFrameHeight(Math.max(240, Math.min(measured + 2, 560)));
|
|
523
|
+
} catch {
|
|
524
|
+
// A cross-origin document keeps the default height.
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}) : null,
|
|
528
|
+
jsx("p", { style: LAN_HINT_STYLE, children: t("lanHint") })
|
|
529
|
+
]
|
|
530
|
+
})
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/** Host commands whose run this browser half projects into the chat view. */
|
|
535
|
+
const PROJECTED_COMMANDS = new Set(["mcp", "lan"]);
|
|
536
|
+
/**
|
|
537
|
+
* Chat node kind of the `/mcp` and `/lan` projection.
|
|
331
538
|
*
|
|
332
539
|
* DSH hides the whole transcript while a session has no turn (the chat view counts only
|
|
333
540
|
* non-command nodes as activity, and only a turn clears the session's blank flag), so in a
|
|
334
|
-
* never-messaged session the
|
|
541
|
+
* never-messaged session the report — logged as `command/run` + `command/done` — would
|
|
335
542
|
* stay invisible until the first message starts a turn. Registering this non-command node is
|
|
336
543
|
* how DSH's own `ui-goal` keeps `/goal` visible; the report itself stays in the generic
|
|
337
544
|
* command card, which is why the renderer below draws nothing.
|
|
@@ -339,14 +546,14 @@ window.__ModuleLoader__.load({
|
|
|
339
546
|
const MCP_NODE_KIND = "hiss-mcp-command";
|
|
340
547
|
|
|
341
548
|
/**
|
|
342
|
-
* Project one `/mcp` run as an empty chat node.
|
|
549
|
+
* Project one `/mcp` or `/lan` run as an empty chat node.
|
|
343
550
|
* Only `command/run` is claimed: `command/done` still renders through the generic command card,
|
|
344
551
|
* and every other command is untouched.
|
|
345
552
|
*/
|
|
346
553
|
const mcpCommandDefinition = {
|
|
347
554
|
kind: MCP_NODE_KIND,
|
|
348
555
|
target: "chat",
|
|
349
|
-
match: (event) => event.type === "command/run" && event.data.name
|
|
556
|
+
match: (event) => event.type === "command/run" && PROJECTED_COMMANDS.has(event.data.name)
|
|
350
557
|
? { id: String(event.data.commandId), role: "start" }
|
|
351
558
|
: null,
|
|
352
559
|
start: (_context, match) => ({ seq: match.event.seq, commandId: match.event.data.commandId }),
|
|
@@ -414,6 +621,37 @@ window.__ModuleLoader__.load({
|
|
|
414
621
|
if (result.application === "failed") throw refusalError(t, result.error?.code, result.error?.diagnostic);
|
|
415
622
|
return result.application;
|
|
416
623
|
};
|
|
624
|
+
lanUi.store = createPopupStore();
|
|
625
|
+
/**
|
|
626
|
+
* Turn the lan-access row on so the popup has something to show.
|
|
627
|
+
* @returns "enabled" when the listener is being mounted now, "restart-required" when only a restart lands it.
|
|
628
|
+
*/
|
|
629
|
+
const ensureLanEnabled = async () => {
|
|
630
|
+
const rows = await list();
|
|
631
|
+
const row = rows.find((candidate) => candidate.key === "lan-access");
|
|
632
|
+
if (row === undefined) throw new Error(t("lanNotInstalled"));
|
|
633
|
+
if (row.enabled) return "enabled";
|
|
634
|
+
if (!row.toggleable) throw new Error(t("lanReadOnly", { reason: row.reason ?? "unknown" }));
|
|
635
|
+
return (await setEnabled(row.entryId, true)) === "restart-required" ? "restart-required" : "enabled";
|
|
636
|
+
};
|
|
637
|
+
/**
|
|
638
|
+
* Wait for the host's QR page: a just-enabled row registers its route asynchronously.
|
|
639
|
+
* @returns whether the page answers, and the frame URL.
|
|
640
|
+
*/
|
|
641
|
+
const probeLanPage = async () => {
|
|
642
|
+
const url = "/lan-access?embed=1";
|
|
643
|
+
for (let attempt = 0; attempt < 12; attempt += 1) {
|
|
644
|
+
try {
|
|
645
|
+
const response = await fetch(url, { method: "HEAD", cache: "no-store" });
|
|
646
|
+
if (response.ok) return { ok: true, url };
|
|
647
|
+
if (response.status === 401 || response.status === 403) break;
|
|
648
|
+
} catch {
|
|
649
|
+
// The route does not exist yet (404) or the browser is briefly offline.
|
|
650
|
+
}
|
|
651
|
+
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
652
|
+
}
|
|
653
|
+
return { ok: false, message: t("lanFrameFailed", { url: "/lan-access" }) };
|
|
654
|
+
};
|
|
417
655
|
ctx.slots.inject("plugins.tab", () => ctx.slots.register({
|
|
418
656
|
name: "plugins.tab",
|
|
419
657
|
id: "dsh-hiss-plugins",
|
|
@@ -427,6 +665,22 @@ window.__ModuleLoader__.load({
|
|
|
427
665
|
features: FEATURES.map((feature) => feature.key)
|
|
428
666
|
})
|
|
429
667
|
}, HissPluginsTab));
|
|
668
|
+
lanUi.t = t;
|
|
669
|
+
lanUi.ensureEnabled = ensureLanEnabled;
|
|
670
|
+
lanUi.probe = probeLanPage;
|
|
671
|
+
ctx.slots.inject("sidebar.footer.action", () => ctx.slots.register({
|
|
672
|
+
name: "sidebar.footer.action",
|
|
673
|
+
id: "lan-access",
|
|
674
|
+
order: 10,
|
|
675
|
+
locale: NS,
|
|
676
|
+
label: () => t("lanButton"),
|
|
677
|
+
}, LanAccessButton));
|
|
678
|
+
ctx.slots.inject("shell.overlay", () => ctx.slots.register({
|
|
679
|
+
name: "shell.overlay",
|
|
680
|
+
id: "lan-access.popup",
|
|
681
|
+
order: 900,
|
|
682
|
+
locale: NS,
|
|
683
|
+
}, LanAccessPopup));
|
|
430
684
|
}
|
|
431
685
|
|
|
432
686
|
exports.apply = apply;
|