dsh-plugin-mesh 0.5.6 → 0.5.8

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/AGENTS.md CHANGED
@@ -100,7 +100,10 @@ lib/identity.js persistent UUID + OS machine fingerprint (claim only)
100
100
  lib/conversation.js conversation key + reply target (both sides compute independently)
101
101
  lib/capabilities.js runtime/GPU/capability collection, sanitising, staleness
102
102
  lib/prompt.js task prompt text generation (pure, unit-tested)
103
+ lib/at-mention.js chat-window `@machine` parsing + rewritten prompt (pure, unit-tested)
103
104
  lib/switch.js one-click shutdown resolver (pure, unit-tested): state.json `shutdown`
105
+ lib/update.js version comparison + npm registry lookup (pure + injectable fetch, unit-tested)
106
+ lib/upgrade.js one-click upgrade: sha512 verify, tar extract, loadability gate, atomic swap (unit-tested)
104
107
  lib/tsnet/ sidecar download/verify, per-channel process manager, tailnet HTTP bridge,
105
108
  channel-list resolution (channels.js, pure and unit-tested)
106
109
  client/client.js renderer: sidebar icon + Mesh panel, hand-written bundle
@@ -120,9 +123,13 @@ inject the prompt → the peer's agent replies by calling `mesh_run`.
120
123
  |---|---|---|
121
124
  | Core / tsnet | `npm run selftest` | discovery, multi-channel endpoints, channel resolution, conversation keys, stall detection (76) |
122
125
  | Capabilities | `npm run selftest:caps` | sanitising, GPU parsing, retry-on-timeout, claim rules (72) |
123
- | Client render | `npm run selftest:client` | bundle loads, `apply()` registers slots, component output, kill-switch rows + overview bar (60) |
124
- | Prompt | `npm run selftest:prompt` | reply target must be a machine name, not `machine/user` (10) |
126
+ | Client render | `npm run selftest:client` | bundle loads, `apply()` registers slots, component output, kill-switch rows + overview bar, chat-window @ source (72) |
127
+ | Prompt | `npm run selftest:prompt` | reply target must be a machine name, not `machine/user`; results must not carry noWake (16) |
128
+ | Chat-window @ | `npm run selftest:at` | leading `@machine` parsing, name-with-spaces matching, failure wording (19) |
129
+ | Chat-window @ (host) | `npm run selftest:at:host` | real `agent/pre-step` → loopback POST, dedupe, offline/ambiguous/closed failures, inbound gate bypass for human tasks (17) |
125
130
  | Kill switch | `npm run selftest:switch` | shutdown merge rules: `off` defaults to true, `all` closes both scopes, strict booleans only (15) |
131
+ | Update check | `npm run selftest:update` | version compare/prerelease, registry fallback, "failure is not up-to-date" (22) |
132
+ | One-click upgrade | `npm run selftest:upgrade` | integrity, tar paths, change classification, atomic swap/rollback (26) |
126
133
 
127
134
  `lib/_selftest-newsession.mjs` is a manual end-to-end check that needs a dev host
128
135
  running; it is deliberately not part of `npm test` because it creates real agent
package/README.md CHANGED
@@ -652,6 +652,36 @@ agent 多出五个工具:
652
652
 
653
653
  > 「看看局域网里有哪些机器,然后让 B 把 web 服务重新部署一下,跑完告诉我。」
654
654
 
655
+ ### 聊天窗口 @ 设备
656
+
657
+ 在**任意会话的输入框**里打 `@`,菜单会列出**当前在线的 mesh 设备**(和文件、会话
658
+ 引用在同一个菜单里,按 `Mesh 设备` 分组)。选中某项只会插入 `@机器名 ` 这段文本,
659
+ 真正的派发发生在**你按下回车之后**:宿主认出消息开头的 @目标,把正文直接发给那台
660
+ 机器,回执再回到当前这个会话。
661
+
662
+ ```
663
+ @文超-win 把 web 服务重新部署一下,跑完告诉我
664
+ ```
665
+
666
+ - **只认开头的 @。** `@机器名` 出现在正文中间不会自动派发 —— 那多半只是"提到某台
667
+ 机器",交给本机 agent 自己决定要不要用 `mesh_run`。
668
+ - **可以一次 @ 多台**:`@mac @hos 都看一下磁盘` 会给每台各发一条,各自一个 thread,
669
+ 回执不会串线。
670
+ - **回执一定落回当前会话**:thread 在 HTTP 之前就绑到当前会话上,对端回执会作为一条新
671
+ 消息进入这场对话(会话没开也会被恢复)。对端 agent 常把自己的结果也标成「回执」
672
+ (`noWake`)—— 人发起的派发的回执不受 `noWake` 限制,照样投递,否则你等着的答案
673
+ 只会躺在收件箱里显示「仅记录」。
674
+ - **失败一定说出来。** 离线 / 同名歧义 / 本机 mesh 已关闭 / 对端 500,都会把原因写进
675
+ 这一轮的消息里,并明确「没有在本机执行」—— 不会静默丢包,也不会让 agent 顺手在
676
+ 本机把远端任务做一遍。
677
+ - **文件引用不受影响。** 开头的 `@路径`(比如 `@AGENTS.md`)只有在该名字刚好是某台
678
+ 机器的名字时才算派发目标;`@"带空格路径"` 一律让给文件引用。
679
+ - 不想要这个行为就把 `atDispatch` 设为 `false`(见「配置项」),`@` 会退回普通文本。
680
+
681
+ > 实现分两半:浏览器侧 `client/client.js` 注册一个 `@` 源(候选 = 在线设备);
682
+ > 宿主侧 `lib/index.js` 的 `agent/pre-step` 调用 `lib/at-mention.js`(纯逻辑,单测
683
+ > 覆盖)认出开头的 @目标并派发。
684
+
655
685
  ### 一键关闭(kill switch)
656
686
 
657
687
  三个范围,两处入口:**主页概览卡**上的一排胶囊(`一键关闭 · 全部 / 局域网 / 互联网`,
@@ -689,6 +719,52 @@ TCP/UDP,只放行 HTTP 客户端的代理设置对它无效(实测诊断里
689
719
 
690
720
  ---
691
721
 
722
+ ### 问题反馈与检查更新(主页页头)
723
+
724
+ 两个入口在主页页头右侧,和「专注」「自定义」同一行,**只有一行小字,不占卡片**:
725
+
726
+ **检查更新(可一键安装)**
727
+
728
+ - 进主页时静默查一次最新版本;宿主机侧缓存 30 分钟(失败只缓存 1 分钟),
729
+ 点一下「检查更新」立即强查。版本源是 npm registry:`registry.npmjs.org` 优先,
730
+ `registry.npmmirror.com` 兜底,每源 5 秒超时。接口是 `GET /mesh/api/update`
731
+ (`?force=1` 跳过缓存)。
732
+ - 有新版本时旁边多出「**新版本 vX**」,点第一下只是确认(6 秒内不点第二下自动
733
+ 取消),第二下才开始装。整条链路:
734
+ 1. 从 npm 取该版本的 `dist.tarball` 与 `dist.integrity`(官方源 → 镜像);
735
+ 2. 下载后**必须**通过 sha512 校验,不一致直接丢弃;
736
+ 3. 解包到安装目录旁的 staging(同文件系统,后面 rename 才是原子的);
737
+ 4. 用真实的 `import()` 检查新入口可加载 —— 不通过就中止,绝不覆盖;
738
+ 5. 备份旧目录 → 原子替换;失败自动回滚。备份名 `.mesh-upgrade-backup-*`,
739
+ 只保留最近 3 份。
740
+ - 装完之后按「这次改了什么」给不同的动作:
741
+ - 改了宿主半(`lib/`)→ **重启生效**。DSH Desktop 上点它走宿主自己的
742
+ `desktopSettingsController.restart()`(原生确认框 + 有序 relaunch,和切换
743
+ profile 同一条路);普通 `dsh web` / headless 如果装了 dshmarket,会退到它的
744
+ 自重启(`/dsh-market/api/v1/restart`,同源回环);两者都没有就老实说
745
+ 「手动重启」,不会假装成功;
746
+ - 只改了界面(`client/`)→ **重载界面** 即可,不需要重启宿主。桌面端走宿主内置的
747
+ `desktopSettingsController.reloadRenderer()`(等同「设置 → 开发者选项 → 重新加载
748
+ 界面」);其它宿主没有这个入口,退到页面自身 `location.reload()`;
749
+ - 只改了版本号 → 建议重启(否则进程里的版本号还是旧的)。
750
+ - **失败一定保留旧版**:任何一步出错都会把阶段(下载 / 校验 / 解包 / 可加载 /
751
+ 替换)和原因写回界面,旁边显示「安装失败」,点一下重试。下载 450KB 的包通常
752
+ 一两秒,超时 60 秒。
753
+ - **查不到就说查不到。** 超时 / HTTP 错误 / registry 返回了无法比较的版本号时,
754
+ 旁边会多出一个「检查失败」(悬停可看逐条原因),点一下重试 —— 不会显示成
755
+ 「已是最新」,否则用户会永远升不了级还看不出来。
756
+ - 写接口只接受**同源回环**请求(`POST /mesh/api/upgrade`、`/mesh/api/upgrade/restart`),
757
+ 不接受转发头,防止局域网页面借浏览器重启宿主。
758
+
759
+ **问题反馈**
760
+
761
+ - 点「问题反馈」在 GitHub 打开新建 Issue 页,标题与正文已预填:正文含版本、系统、
762
+ 发现方式、对端数量与本机名 / 地址 / MAC,**不含**配对码与 tsnet 授权码
763
+ (`buildDiagnostics()` 只挑安全字段)。提交前可以自己删改。
764
+ - GitHub 打不开时,把鼠标停在「问题反馈」上能看到邮件地址
765
+ `geekstartup@163.com`,直接把现场贴过去即可。
766
+
767
+ ---
692
768
 
693
769
  ### 远程面板与 SSH 终端
694
770
 
@@ -763,6 +839,7 @@ TCP/UDP,只放行 HTTP 客户端的代理设置对它无效(实测诊断里
763
839
  agentPreset: standard
764
840
  permissionPreset: workspace-write
765
841
  workspaceRoot: ''
842
+ atDispatch: true # 聊天窗口 @ 在线设备后,发送即派发(false = @ 只当文本)
766
843
  # ── 互联网自组网(Tailscale / tsnet)──
767
844
  # 多 tailnet 通道:每项 { id, label, authKey, controlUrl, hostname, enabled }。
768
845
  # 非空时优先于下面的旧版单通道字段,且界面只能看不能改(部署方钉死)。
@@ -804,6 +881,15 @@ Mesh 页面看到,不会被丢弃):
804
881
  | 寒暄识别 | 内置 | `ping` / `ack` / `收到` / `好的` 等整条即寒暄的,不开会话 |
805
882
  | `threadCooldownMs` | 5s | 同一 thread 不会连续秒回,管**突发** |
806
883
  | `maxWakesPerThread` | 30 | 同一 thread 在 `threadWindowMs` 内的唤醒上限,管**持续速率** |
884
+ | `noWake`(发送方标记) | — | 只入箱、不开会话;**例外**见下 |
885
+
886
+ ⚠️ **人手动派发的任务与它的回执不走前两道闸门。** 聊天窗口 `@` 设备、Mesh 面板
887
+ 「派发任务」发出去的任务带 `human` 标记,对端不再用「太短 / 纯寒暄」拦它 ——
888
+ 人说一句「看下磁盘」只有 4 个字,被吞成「仅记录」只会让人以为派发坏了
889
+ (2026-10-30 真机:`routeDecision = 正文仅 6 字符 < minTaskChars(8)`)。同理,
890
+ **这条派发的回执即使被对端 agent 标成 `noWake`,也会投递回会话**:那是用户等着的
891
+ 答案,不是可以静默丢掉的寒暄;对端是旧版本、仍按旧文案把结果标成回执时也一样。
892
+ 限速(`maxWakesPerThread`)对人和回执同样生效 —— 防刷靠它,不靠内容闸门。
807
893
 
808
894
  `maxWakesPerThread` 是**滑动窗口限速,不是终身配额**:只统计最近
809
895
  `threadWindowMs`(默认 1 小时)内的唤醒。窗口内的唤醒点会随时间自然过期,
@@ -1000,6 +1086,7 @@ dsh-plugin-mesh/
1000
1086
  │ ├── conversation.js # 会话键 + 回信地址(两端各自算,不协商)
1001
1087
  │ ├── capabilities.js # 能力采集/净化/摘要(Placement 第 1 步)
1002
1088
  │ ├── scan.js # 主动扫描(固定端口 + CIDR 展开)
1089
+ │ ├── at-mention.js # 聊天窗口 @ 设备的纯逻辑(认目标 / 改写消息,单测覆盖)
1003
1090
  │ ├── tsnet/ # 用户态 tailscale 节点(sidecar 下载/管理/桥接)
1004
1091
  │ └── _selftest-*.mjs # 回归脚本(默认不碰网络)
1005
1092
  ├── sidecar/ # Go 源码:tsnet 用户态节点
package/client/client.js CHANGED
@@ -37,6 +37,11 @@ window.__ModuleLoader__.load({
37
37
  const TS_KEYS_URL = "https://console.tailscale.com/admin/settings/keys";
38
38
  const TRANSFER_KEY = "mesh.transfers.v1";
39
39
  const TRANSFER_LIMIT = 50;
40
+ // 更新与反馈都指向同一个 GitHub 仓库;邮件是 GitHub 不通时的退路
41
+ //(作者机器上 git-over-https 到 github.com 常被重置,见 AGENTS.md)。
42
+ const RELEASE_REPO = "peng456/dsh-plugin-mesh";
43
+ const NEW_ISSUE_URL = `https://github.com/${RELEASE_REPO}/issues/new`;
44
+ const FEEDBACK_MAIL = "geekstartup@163.com";
40
45
  let pluginCtx = null;
41
46
 
42
47
  const HOME_PREF_KEY = "mesh.home.v1";
@@ -310,12 +315,7 @@ window.__ModuleLoader__.load({
310
315
  return (r && (r.error || r.message)) || "未知错误";
311
316
  }
312
317
 
313
- async function api(path, body) {
314
- const r = await fetch(API + path, {
315
- method: "POST",
316
- headers: { "content-type": "application/json" },
317
- body: JSON.stringify(body || {}),
318
- });
318
+ async function parseApiResponse(r) {
319
319
  let j = {};
320
320
  try {
321
321
  j = await r.json();
@@ -326,6 +326,24 @@ window.__ModuleLoader__.load({
326
326
  return j;
327
327
  }
328
328
 
329
+ async function api(path, body) {
330
+ const r = await fetch(API + path, {
331
+ method: "POST",
332
+ headers: { "content-type": "application/json" },
333
+ body: JSON.stringify(body || {}),
334
+ });
335
+ return parseApiResponse(r);
336
+ }
337
+
338
+ /** 只读接口走 GET(/mesh/api/update 就是这一类:查一次版本,不改任何状态)。 */
339
+ async function apiGet(path) {
340
+ const r = await fetch(API + path, {
341
+ headers: { accept: "application/json" },
342
+ cache: "no-store",
343
+ });
344
+ return parseApiResponse(r);
345
+ }
346
+
329
347
  async function copyText(text) {
330
348
  try {
331
349
  if (navigator.clipboard && navigator.clipboard.writeText) {
@@ -1692,6 +1710,23 @@ window.__ModuleLoader__.load({
1692
1710
  .mesh-editor-error { margin: 8px 0; font-size: 11.5px; color: var(--mesh-err); }
1693
1711
  .mesh-editor-foot { display: flex; align-items: center; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
1694
1712
  .mesh-card-text.is-pre { white-space: pre-wrap; }
1713
+ /* 主页页头的轻入口:只有文字,没有边框/底色,和「专注」「自定义」同一行 */
1714
+ .mesh-home-meta { display: inline-flex; align-items: center; gap: 12px; flex-wrap: wrap; }
1715
+ .mesh-meta-link {
1716
+ appearance: none; -webkit-appearance: none;
1717
+ border: 0; background: none; padding: 2px 0; margin: 0;
1718
+ font: inherit; font-size: 11px; line-height: 1.5;
1719
+ color: var(--mesh-muted); cursor: pointer;
1720
+ text-decoration: none; white-space: nowrap;
1721
+ transition: color var(--mesh-dur-fast) ease;
1722
+ }
1723
+ .mesh-meta-link:hover { color: var(--mesh-accent); text-decoration: underline; text-underline-offset: 2px; }
1724
+ .mesh-meta-link:focus-visible { outline: 2px solid var(--mesh-accent); outline-offset: 2px; border-radius: 4px; }
1725
+ .mesh-meta-link:disabled { cursor: default; opacity: .6; }
1726
+ .mesh-meta-link.is-update { color: var(--mesh-accent); font-weight: 600; }
1727
+ .mesh-meta-link.is-warn { color: var(--mesh-warn); }
1728
+ .mesh-meta-link.is-busy { opacity: .65; }
1729
+ .mesh-meta-pill { font-size: 11px; line-height: 1.5; color: var(--mesh-accent); font-weight: 600; white-space: nowrap; }
1695
1730
  .mesh-card-link { color: var(--mesh-accent); text-decoration: none; }
1696
1731
  .mesh-card-link:hover { text-decoration: underline; }
1697
1732
  .mesh-focus .mesh-dot.is-ok::after,
@@ -2168,6 +2203,115 @@ window.__ModuleLoader__.load({
2168
2203
  return now;
2169
2204
  }
2170
2205
 
2206
+ // ─────────────────────── 聊天窗口 @ 设备 ───────────────────────
2207
+ //
2208
+ // composer 里打 @ 时,菜单把**在线的 mesh 机器**列出来。选中只插入
2209
+ // `@机器名 ` 这段文本;真正的派发在宿主侧:agent/pre-step 认出消息开头的
2210
+ // @机器名,把正文直接发给那台机器(见 lib/at-mention.js)。
2211
+ //
2212
+ // 候选数据来自和面板同一个 /mesh/api/state,但带 2.5 秒缓存 —— 补全是按键
2213
+ // 触发的,不能让每个字符都打一次接口(那还会顺带读盘)。
2214
+
2215
+ const AT_STATE_TTL_MS = 2500;
2216
+ const AT_SECTION = "Mesh 设备";
2217
+ let atPeersCache = { at: 0, rows: [] };
2218
+
2219
+ /** 读一次在线设备列表(带短缓存);失败沿用上一份缓存,不把错误抛给补全管线。 */
2220
+ async function loadOnlinePeers(signal) {
2221
+ if (atPeersCacheFresh()) return atPeersCache.rows;
2222
+ try {
2223
+ const r = await fetch(`${API}/state`, {
2224
+ headers: { accept: "application/json" },
2225
+ cache: "no-store",
2226
+ ...(signal ? { signal } : {}),
2227
+ });
2228
+ const j = await r.json();
2229
+ const peers = j && Array.isArray(j.peers) ? j.peers : [];
2230
+ const rows = peers
2231
+ .filter((p) => p && p.online === true && String(p.machine || "").trim())
2232
+ .map((p) => ({
2233
+ machine: String(p.machine).trim(),
2234
+ address: peerAddress(p),
2235
+ system: osInfoLabel(p),
2236
+ user: String(p.user || "").trim(),
2237
+ }))
2238
+ .sort((a, b) => a.machine.localeCompare(b.machine));
2239
+ atPeersCache = { at: Date.now(), rows };
2240
+ return rows;
2241
+ } catch {
2242
+ // 网络/宿主不可用:沿用上一次的列表(可能为空)。候选失败必须静默,
2243
+ // 否则每敲一个字都弹一次错误。
2244
+ return atPeersCache.rows;
2245
+ }
2246
+ }
2247
+
2248
+ function resetAtPeersCache() {
2249
+ atPeersCache = { at: 0, rows: [] };
2250
+ }
2251
+
2252
+ /** 缓存是否还新鲜(空列表也要缓存:没有在线设备时别每敲一个字都打接口)。 */
2253
+ function atPeersCacheFresh() {
2254
+ return atPeersCache.at > 0 && Date.now() - atPeersCache.at < AT_STATE_TTL_MS;
2255
+ }
2256
+
2257
+ /**
2258
+ * 一个 `@` 源:在线设备 → 插入 `@名字 `。
2259
+ *
2260
+ * `showGroupTitle: false` + 每行带 section:菜单里显示的是我们自己的分组名,
2261
+ * 而不是触发管线按 source 名("mesh")反查出来的原始 key。
2262
+ */
2263
+ function buildAtPeerSource() {
2264
+ return {
2265
+ trigger: "@",
2266
+ name: "mesh",
2267
+ showGroupTitle: false,
2268
+ async candidates(_session, { query, quoted, signal }) {
2269
+ // @"..." 是文件路径语法(见 @deepseek-ai/dsh-client-ui-reference),让给文件引用。
2270
+ if (quoted === true) return [];
2271
+ const rows = await loadOnlinePeers(signal);
2272
+ if (signal && signal.aborted) return [];
2273
+ const needle = String(query || "").trim().toLocaleLowerCase();
2274
+ return rows
2275
+ .filter(
2276
+ (row) =>
2277
+ needle === "" ||
2278
+ row.machine.toLocaleLowerCase().includes(needle) ||
2279
+ row.address.toLocaleLowerCase().includes(needle),
2280
+ )
2281
+ .map((row) => ({
2282
+ name: row.machine,
2283
+ description: [row.address, row.system, row.user ? `user=${row.user}` : ""].filter(Boolean).join(" · "),
2284
+ section: AT_SECTION,
2285
+ value: row.machine,
2286
+ }));
2287
+ },
2288
+ onPick({ candidate }) {
2289
+ const machine = String((candidate && candidate.value) || "").trim();
2290
+ if (!machine) return undefined;
2291
+ return { text: `@${machine} ` };
2292
+ },
2293
+ };
2294
+ }
2295
+
2296
+ /**
2297
+ * 注册 @ 源。宿主没有触发管线(老版本 DSH)时安静跳过 —— 不能因为多了
2298
+ * 一个可选增强,让整个 Mesh 面板起不来。
2299
+ */
2300
+ function registerAtPeerSource(ctx) {
2301
+ if (!ctx || typeof ctx.inject !== "function") return;
2302
+ try {
2303
+ ctx.inject(["inputTriggers"], (scoped) => {
2304
+ const inputTriggers =
2305
+ (scoped && (scoped.inputTriggers || (scoped.get && scoped.get("inputTriggers")))) || null;
2306
+ if (!inputTriggers || typeof inputTriggers.registerSource !== "function") return;
2307
+ scoped.effect(() => inputTriggers.registerSource(buildAtPeerSource()), "mesh: @ 在线设备");
2308
+ });
2309
+ } catch (err) {
2310
+ // 触发管线是可选的:注册失败只记一条日志,不能让 Mesh 面板跟着挂掉。
2311
+ console.warn("mesh client: 聊天窗口 @ 设备注册失败(面板不受影响)", err);
2312
+ }
2313
+ }
2314
+
2171
2315
  function prefersReducedMotion() {
2172
2316
  try {
2173
2317
  return typeof window !== "undefined" && window.matchMedia
@@ -6298,6 +6442,310 @@ window.__ModuleLoader__.load({
6298
6442
  );
6299
6443
  }
6300
6444
 
6445
+ // ─────────────────────── 主页 · 问题反馈 / 检查更新(轻入口) ───────────────────────
6446
+
6447
+ /**
6448
+ * 主页页头的两个轻入口:只占一行文字,不占卡片。
6449
+ *
6450
+ * 它们最初是两张卡片,真机上看太占首屏 —— 主页要回答的是"谁在线、能不能
6451
+ * 派活",更新和反馈是偶尔用一次的事。于是收成和「专注」「自定义」同一行的
6452
+ * 两个小字,功能一个不少:
6453
+ * · 问题反馈 → GitHub 新建 Issue(标题/正文预填,带诊断、不含 secret);
6454
+ * · 检查更新 → 查一次 registry;有更新时旁边多出「新版本 vX」,点它复制
6455
+ * 升级命令;失败时多出「检查失败」,点它重试。
6456
+ * 失败**不会**显示成"已是最新":徽标、tooltip、toast 说的都是"没查到"。
6457
+ */
6458
+
6459
+ /** 反馈正文:与「诊断」同一份数据,Issue 链接里预填。 */
6460
+ function feedbackBody(state) {
6461
+ return [
6462
+ "### 发生了什么",
6463
+ "",
6464
+ "<!-- 一句话描述:做了什么、期望什么、实际发生了什么 -->",
6465
+ "",
6466
+ "### 复现步骤",
6467
+ "",
6468
+ "1. ",
6469
+ "",
6470
+ "### 诊断信息(可删掉不想公开的行)",
6471
+ "",
6472
+ "```",
6473
+ buildDiagnostics(state),
6474
+ "```",
6475
+ ].join("\n");
6476
+ }
6477
+
6478
+ function feedbackIssueUrl(state) {
6479
+ const self = (state && state.self) || {};
6480
+ const title = `[反馈] Mesh ${self.version || ""}${self.machine ? ` · ${self.machine}` : ""}`.trim();
6481
+ const params = new URLSearchParams({ title, body: feedbackBody(state) });
6482
+ return `${NEW_ISSUE_URL}?${params.toString()}`;
6483
+ }
6484
+
6485
+ /** 问题反馈:一个链接,直接打开预填好的新建 Issue 页。 */
6486
+ function FeedbackLink({ state }) {
6487
+ return h(
6488
+ "a",
6489
+ {
6490
+ className: "mesh-meta-link",
6491
+ href: feedbackIssueUrl(state),
6492
+ target: "_blank",
6493
+ rel: "noreferrer",
6494
+ title: `在 GitHub 提 Issue(打不开可以邮件 ${FEEDBACK_MAIL})`,
6495
+ },
6496
+ "问题反馈",
6497
+ );
6498
+ }
6499
+
6500
+ /**
6501
+ * 检查更新的展示层(纯 props):自测可以直接给各种现场,不用联网。
6502
+ *
6503
+ * 状态优先级(写在这里是为了让"该装 / 已装待重启 / 已装待重载"不会互相盖住):
6504
+ * pendingUpgrade(磁盘已是目标版)→ 只给「重启」或「重载界面」;
6505
+ * 否则 hasUpdate → 给「新版本 vX」,点第一下变确认、第二下才开始装;
6506
+ * 失败 → 明确写「安装失败」,点一下重试(绝不悄悄回到"有新版本")。
6507
+ */
6508
+ function UpdateLinkView({ phase, report, install, onCheck, onInstall, onRestart, onReload }) {
6509
+ const checking = phase === "checking";
6510
+ const state = (install && install.state) || "idle";
6511
+ const running = state === "running";
6512
+ const armed = state === "armed";
6513
+ const installFailed = state === "failed";
6514
+ const busy = checking || running;
6515
+ const pending =
6516
+ report && report.ok === true && report.pendingUpgrade && (!report.latest || report.pendingUpgrade.version === report.latest)
6517
+ ? report.pendingUpgrade
6518
+ : null;
6519
+ const hasUpdate = !!report && report.ok === true && report.hasUpdate === true;
6520
+ const failed = !!report && report.ok !== true;
6521
+ const incomparable = !!report && report.ok === true && report.comparable === false;
6522
+ const canInstall = hasUpdate && !pending && report.diskVersion !== report.latest;
6523
+ const label = checking ? "检查中…" : "检查更新";
6524
+ const title = failed
6525
+ ? `上次检查失败:${String(report.error || "未知原因")}(点一下重试)`
6526
+ : incomparable
6527
+ ? `当前 v${report.current} 与 registry 返回的 v${report.latest} 无法比较,点一下重新检查`
6528
+ : hasUpdate
6529
+ ? `当前 v${report.current} → 最新 v${report.latest};点一下重新检查`
6530
+ : "查一下有没有新版本";
6531
+ return h(
6532
+ react.Fragment,
6533
+ null,
6534
+ h(
6535
+ "button",
6536
+ {
6537
+ type: "button",
6538
+ className: cls("mesh-meta-link", busy && "is-busy"),
6539
+ onClick: onCheck,
6540
+ disabled: busy,
6541
+ title,
6542
+ "aria-label": "检查更新",
6543
+ "aria-busy": busy || undefined,
6544
+ },
6545
+ label,
6546
+ ),
6547
+ pending
6548
+ ? h(
6549
+ "span",
6550
+ { className: "mesh-meta-pill", title: pending.at ? `安装于 ${pending.at}` : undefined },
6551
+ `已安装 v${pending.version}`,
6552
+ )
6553
+ : null,
6554
+ pending && pending.restartRequired
6555
+ ? h(
6556
+ "button",
6557
+ {
6558
+ type: "button",
6559
+ className: "mesh-meta-link is-update",
6560
+ onClick: onRestart,
6561
+ title: "重启 DSH 让新版本生效(会中断当前会话)",
6562
+ },
6563
+ "重启生效",
6564
+ )
6565
+ : null,
6566
+ pending && !pending.restartRequired
6567
+ ? h(
6568
+ "button",
6569
+ {
6570
+ type: "button",
6571
+ className: "mesh-meta-link is-update",
6572
+ onClick: onReload,
6573
+ title: "这次只改了界面,重载界面即可生效",
6574
+ },
6575
+ "重载界面",
6576
+ )
6577
+ : null,
6578
+ !pending && canInstall
6579
+ ? h(
6580
+ "button",
6581
+ {
6582
+ type: "button",
6583
+ className: cls("mesh-meta-link is-update", installFailed && "is-warn"),
6584
+ onClick: onInstall,
6585
+ disabled: running,
6586
+ title: installFailed
6587
+ ? `上次安装失败:${String(install.error || "未知原因")};点一下重试`
6588
+ : armed
6589
+ ? `再点一次开始安装 v${report.latest}(sha512 校验后替换,装完重启生效)`
6590
+ : `一键安装 v${report.latest}(先校验 sha512,可加载检查通过才替换)`,
6591
+ "aria-label": armed ? `确认安装 v${report.latest}` : `安装 v${report.latest}`,
6592
+ },
6593
+ installFailed ? "安装失败" : running ? "安装中…" : armed ? `确认安装 v${report.latest}` : `新版本 v${report.latest}`,
6594
+ )
6595
+ : null,
6596
+ failed && !canInstall
6597
+ ? h(
6598
+ "button",
6599
+ { type: "button", className: "mesh-meta-link is-warn", onClick: onCheck, title: report.error },
6600
+ "检查失败",
6601
+ )
6602
+ : null,
6603
+ incomparable
6604
+ ? h(
6605
+ "button",
6606
+ { type: "button", className: "mesh-meta-link is-warn", onClick: onCheck, title },
6607
+ "无法比较",
6608
+ )
6609
+ : null,
6610
+ );
6611
+ }
6612
+
6613
+ /**
6614
+ * 检查更新的容器:进主页**静默**查一次(宿主机缓存 30 分钟),点一下强查。
6615
+ * 点「新版本」第一下只是确认(6 秒内不点第二下自动取消),第二下才真的装。
6616
+ */
6617
+ function UpdateLink({ push }) {
6618
+ const [phase, setPhase] = react.useState("idle");
6619
+ const [report, setReport] = react.useState(null);
6620
+ const [install, setInstall] = react.useState({ state: "idle", error: "" });
6621
+ const alive = react.useRef(true);
6622
+ const run = react.useCallback(
6623
+ async (force, announce) => {
6624
+ setPhase("checking");
6625
+ try {
6626
+ const r = await apiGet(`/update${force ? "?force=1" : ""}`);
6627
+ if (!alive.current) return;
6628
+ const next = r && typeof r === "object" ? r : { ok: false, error: "主机没有返回结果" };
6629
+ setReport(next);
6630
+ setPhase("done");
6631
+ if (!announce) return;
6632
+ if (next.ok !== true) {
6633
+ push("error", `没查到最新版本:${String(next.error || "未知原因")}`);
6634
+ } else if (next.comparable === false) {
6635
+ push("error", `版本号无法比较:v${next.current} vs v${next.latest},请到 Release 页面确认`);
6636
+ } else if (next.pendingUpgrade && (!next.latest || next.pendingUpgrade.version === next.latest)) {
6637
+ push(
6638
+ "success",
6639
+ next.pendingUpgrade.restartRequired
6640
+ ? `已安装 v${next.pendingUpgrade.version},重启 DSH 后生效`
6641
+ : `已安装 v${next.pendingUpgrade.version},重载界面后生效`,
6642
+ );
6643
+ } else if (next.hasUpdate) {
6644
+ push("success", `有新版本 v${next.latest}(当前 v${next.current}),点「新版本」一键安装`);
6645
+ } else {
6646
+ push("success", `已是最新(v${next.current})`);
6647
+ }
6648
+ } catch (e) {
6649
+ if (!alive.current) return;
6650
+ setReport({ ok: false, error: String((e && e.message) || e) });
6651
+ setPhase("done");
6652
+ if (announce) push("error", `没查到最新版本:${String((e && e.message) || e)}`);
6653
+ }
6654
+ },
6655
+ [push],
6656
+ );
6657
+ react.useEffect(() => {
6658
+ alive.current = true;
6659
+ run(false, false);
6660
+ return () => {
6661
+ alive.current = false;
6662
+ };
6663
+ }, [run]);
6664
+ // 确认态 6 秒后自动取消:避免"上次点了一半"的按钮一直挂着。
6665
+ react.useEffect(() => {
6666
+ if (install.state !== "armed") return;
6667
+ const timer = setTimeout(() => setInstall({ state: "idle", error: "" }), 6000);
6668
+ return () => clearTimeout(timer);
6669
+ }, [install.state]);
6670
+
6671
+ const startInstall = react.useCallback(async () => {
6672
+ if (!report || report.ok !== true || !report.latest) return;
6673
+ if (install.state !== "armed") {
6674
+ setInstall({ state: "armed", error: "" });
6675
+ return;
6676
+ }
6677
+ setInstall({ state: "running", error: "" });
6678
+ try {
6679
+ const r = await api("/upgrade", { version: report.latest });
6680
+ if (!alive.current) return;
6681
+ if (!r || r.ok !== true) {
6682
+ setInstall({ state: "failed", error: apiErr(r) });
6683
+ push("error", `安装失败:${apiErr(r)}`);
6684
+ return;
6685
+ }
6686
+ setInstall({ state: "idle", error: "" });
6687
+ if (r.upToDate || r.installed === false) {
6688
+ push("success", `v${report.latest} 已经在磁盘上,不用重复安装`);
6689
+ } else if (r.restartRequired) {
6690
+ push("success", `已安装 v${r.version},重启 DSH 后生效(旧版已备份,可回滚)`);
6691
+ } else if (r.reloadRequired) {
6692
+ push("success", `已安装 v${r.version},点「重载界面」即可生效`);
6693
+ } else {
6694
+ push("success", `已安装 v${r.version}`);
6695
+ }
6696
+ await run(true, false);
6697
+ } catch (e) {
6698
+ if (!alive.current) return;
6699
+ setInstall({ state: "failed", error: String((e && e.message) || e) });
6700
+ push("error", `安装失败:${String((e && e.message) || e)}`);
6701
+ }
6702
+ }, [install.state, push, report, run]);
6703
+
6704
+ const restart = react.useCallback(async () => {
6705
+ try {
6706
+ const r = await api("/upgrade/restart", {});
6707
+ if (r && r.ok) push("success", "正在重启 DSH,窗口会自动回来…");
6708
+ else push("error", (r && r.error) || "当前宿主没有可用的重启入口,请手动重启 DSH");
6709
+ } catch (e) {
6710
+ push("error", String((e && e.message) || e));
6711
+ }
6712
+ }, [push]);
6713
+
6714
+ const reload = react.useCallback(async () => {
6715
+ // 先问宿主有没有内置重载入口(DSH Desktop 有:和「开发者选项 → 重新加载
6716
+ // 界面」同一个动作);没有才用页面自身 reload。两种都只重载渲染器,
6717
+ // 不重启宿主。
6718
+ try {
6719
+ const r = await api("/upgrade/reload", {});
6720
+ if (r && r.ok) {
6721
+ push("success", "正在重新加载界面…");
6722
+ return;
6723
+ }
6724
+ } catch {
6725
+ /* 落到页面自身重载 */
6726
+ }
6727
+ try {
6728
+ window.location.reload();
6729
+ } catch {
6730
+ push("error", "无法自动重载,请按 Cmd/Ctrl+R 手动重载界面");
6731
+ }
6732
+ }, [push]);
6733
+
6734
+ return h(UpdateLinkView, {
6735
+ phase,
6736
+ report,
6737
+ install,
6738
+ onCheck: () => run(true, true),
6739
+ onInstall: startInstall,
6740
+ onRestart: restart,
6741
+ onReload: reload,
6742
+ });
6743
+ }
6744
+
6745
+ function HomeMetaLinks({ state, push }) {
6746
+ return h("div", { className: "mesh-home-meta" }, h(FeedbackLink, { state }), h(UpdateLink, { push }));
6747
+ }
6748
+
6301
6749
  // ─────────────────────── 主页 · 派发任务 ───────────────────────
6302
6750
 
6303
6751
  /**
@@ -6913,6 +7361,7 @@ window.__ModuleLoader__.load({
6913
7361
  ? h(Button, { variant: "primary", size: "sm", icon: "check", onClick: () => setEditing(false) }, "完成")
6914
7362
  : h(Button, { variant: "secondary", size: "sm", icon: "edit", onClick: () => setEditing(true) }, "自定义"),
6915
7363
  editing ? h(Button, { variant: "ghost", size: "sm", onClick: onReset }, "恢复默认") : null,
7364
+ h(HomeMetaLinks, { state, push }),
6916
7365
  ),
6917
7366
  ),
6918
7367
  h(
@@ -7917,6 +8366,7 @@ window.__ModuleLoader__.load({
7917
8366
  ctx.slots.inject("main", () =>
7918
8367
  ctx.slots.register({ name: "main", key: PANEL_ID }, MeshApp),
7919
8368
  );
8369
+ registerAtPeerSource(ctx);
7920
8370
  ctx.logger?.info?.("mesh client: 已注册 Mesh 工作台");
7921
8371
  }
7922
8372
 
@@ -7960,6 +8410,15 @@ window.__ModuleLoader__.load({
7960
8410
  SwitchBody,
7961
8411
  SwitchRow,
7962
8412
  HomeSwitchBar,
8413
+ HomeMetaLinks,
8414
+ UpdateLink,
8415
+ UpdateLinkView,
8416
+ FeedbackLink,
8417
+ feedbackBody,
8418
+ feedbackIssueUrl,
8419
+ buildAtPeerSource,
8420
+ loadOnlinePeers,
8421
+ resetAtPeersCache,
7963
8422
  };
7964
8423
  return module.exports;
7965
8424
  },