dsh-plugin-mesh 0.5.7 → 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
  三个范围,两处入口:**主页概览卡**上的一排胶囊(`一键关闭 · 全部 / 局域网 / 互联网`,
@@ -693,17 +723,38 @@ TCP/UDP,只放行 HTTP 客户端的代理设置对它无效(实测诊断里
693
723
 
694
724
  两个入口在主页页头右侧,和「专注」「自定义」同一行,**只有一行小字,不占卡片**:
695
725
 
696
- **检查更新**
726
+ **检查更新(可一键安装)**
697
727
 
698
728
  - 进主页时静默查一次最新版本;宿主机侧缓存 30 分钟(失败只缓存 1 分钟),
699
- 点一下「检查更新」立即强查。
700
- - 有新版本时旁边多出一个「**新版本 vX**」,点它直接复制升级命令(插件目录已按
701
- 本机实际安装路径填好,与 Release 资产命名一致),装好后**重启 DSH** 才生效。
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 秒。
702
753
  - **查不到就说查不到。** 超时 / HTTP 错误 / registry 返回了无法比较的版本号时,
703
754
  旁边会多出一个「检查失败」(悬停可看逐条原因),点一下重试 —— 不会显示成
704
755
  「已是最新」,否则用户会永远升不了级还看不出来。
705
- - 版本源是 npm registry:`registry.npmjs.org` 优先,`registry.npmmirror.com`
706
- 兜底,每源 5 秒超时。接口是 `GET /mesh/api/update`(`?force=1` 跳过缓存)。
756
+ - 写接口只接受**同源回环**请求(`POST /mesh/api/upgrade`、`/mesh/api/upgrade/restart`),
757
+ 不接受转发头,防止局域网页面借浏览器重启宿主。
707
758
 
708
759
  **问题反馈**
709
760
 
@@ -788,6 +839,7 @@ TCP/UDP,只放行 HTTP 客户端的代理设置对它无效(实测诊断里
788
839
  agentPreset: standard
789
840
  permissionPreset: workspace-write
790
841
  workspaceRoot: ''
842
+ atDispatch: true # 聊天窗口 @ 在线设备后,发送即派发(false = @ 只当文本)
791
843
  # ── 互联网自组网(Tailscale / tsnet)──
792
844
  # 多 tailnet 通道:每项 { id, label, authKey, controlUrl, hostname, enabled }。
793
845
  # 非空时优先于下面的旧版单通道字段,且界面只能看不能改(部署方钉死)。
@@ -829,6 +881,15 @@ Mesh 页面看到,不会被丢弃):
829
881
  | 寒暄识别 | 内置 | `ping` / `ack` / `收到` / `好的` 等整条即寒暄的,不开会话 |
830
882
  | `threadCooldownMs` | 5s | 同一 thread 不会连续秒回,管**突发** |
831
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`)对人和回执同样生效 —— 防刷靠它,不靠内容闸门。
832
893
 
833
894
  `maxWakesPerThread` 是**滑动窗口限速,不是终身配额**:只统计最近
834
895
  `threadWindowMs`(默认 1 小时)内的唤醒。窗口内的唤醒点会随时间自然过期,
@@ -1025,6 +1086,7 @@ dsh-plugin-mesh/
1025
1086
  │ ├── conversation.js # 会话键 + 回信地址(两端各自算,不协商)
1026
1087
  │ ├── capabilities.js # 能力采集/净化/摘要(Placement 第 1 步)
1027
1088
  │ ├── scan.js # 主动扫描(固定端口 + CIDR 展开)
1089
+ │ ├── at-mention.js # 聊天窗口 @ 设备的纯逻辑(认目标 / 改写消息,单测覆盖)
1028
1090
  │ ├── tsnet/ # 用户态 tailscale 节点(sidecar 下载/管理/桥接)
1029
1091
  │ └── _selftest-*.mjs # 回归脚本(默认不碰网络)
1030
1092
  ├── sidecar/ # Go 源码:tsnet 用户态节点
package/client/client.js CHANGED
@@ -1725,6 +1725,8 @@ window.__ModuleLoader__.load({
1725
1725
  .mesh-meta-link:disabled { cursor: default; opacity: .6; }
1726
1726
  .mesh-meta-link.is-update { color: var(--mesh-accent); font-weight: 600; }
1727
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; }
1728
1730
  .mesh-card-link { color: var(--mesh-accent); text-decoration: none; }
1729
1731
  .mesh-card-link:hover { text-decoration: underline; }
1730
1732
  .mesh-focus .mesh-dot.is-ok::after,
@@ -2201,6 +2203,115 @@ window.__ModuleLoader__.load({
2201
2203
  return now;
2202
2204
  }
2203
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
+
2204
2315
  function prefersReducedMotion() {
2205
2316
  try {
2206
2317
  return typeof window !== "undefined" && window.matchMedia
@@ -6386,12 +6497,29 @@ window.__ModuleLoader__.load({
6386
6497
  );
6387
6498
  }
6388
6499
 
6389
- /** 检查更新的展示层(纯 props):自测可以直接给三种现场,不用联网。 */
6390
- function UpdateLinkView({ phase, report, onCheck, onCopy }) {
6500
+ /**
6501
+ * 检查更新的展示层(纯 props):自测可以直接给各种现场,不用联网。
6502
+ *
6503
+ * 状态优先级(写在这里是为了让"该装 / 已装待重启 / 已装待重载"不会互相盖住):
6504
+ * pendingUpgrade(磁盘已是目标版)→ 只给「重启」或「重载界面」;
6505
+ * 否则 hasUpdate → 给「新版本 vX」,点第一下变确认、第二下才开始装;
6506
+ * 失败 → 明确写「安装失败」,点一下重试(绝不悄悄回到"有新版本")。
6507
+ */
6508
+ function UpdateLinkView({ phase, report, install, onCheck, onInstall, onRestart, onReload }) {
6391
6509
  const checking = phase === "checking";
6392
- const failed = !!report && report.ok !== true;
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;
6393
6519
  const hasUpdate = !!report && report.ok === true && report.hasUpdate === true;
6520
+ const failed = !!report && report.ok !== true;
6394
6521
  const incomparable = !!report && report.ok === true && report.comparable === false;
6522
+ const canInstall = hasUpdate && !pending && report.diskVersion !== report.latest;
6395
6523
  const label = checking ? "检查中…" : "检查更新";
6396
6524
  const title = failed
6397
6525
  ? `上次检查失败:${String(report.error || "未知原因")}(点一下重试)`
@@ -6407,29 +6535,65 @@ window.__ModuleLoader__.load({
6407
6535
  "button",
6408
6536
  {
6409
6537
  type: "button",
6410
- className: cls("mesh-meta-link", checking && "is-busy"),
6538
+ className: cls("mesh-meta-link", busy && "is-busy"),
6411
6539
  onClick: onCheck,
6412
- disabled: checking,
6540
+ disabled: busy,
6413
6541
  title,
6414
6542
  "aria-label": "检查更新",
6415
- "aria-busy": checking || undefined,
6543
+ "aria-busy": busy || undefined,
6416
6544
  },
6417
6545
  label,
6418
6546
  ),
6419
- hasUpdate
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
6420
6567
  ? h(
6421
6568
  "button",
6422
6569
  {
6423
6570
  type: "button",
6424
6571
  className: "mesh-meta-link is-update",
6425
- onClick: () => onCopy(report.upgradeCommand),
6426
- title: `复制升级命令(v${report.current} → v${report.latest},装好后重启 DSH)`,
6427
- "aria-label": `复制升级命令到 v${report.latest}`,
6572
+ onClick: onReload,
6573
+ title: "这次只改了界面,重载界面即可生效",
6428
6574
  },
6429
- `新版本 v${report.latest}`,
6575
+ "重载界面",
6430
6576
  )
6431
6577
  : null,
6432
- failed
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
6433
6597
  ? h(
6434
6598
  "button",
6435
6599
  { type: "button", className: "mesh-meta-link is-warn", onClick: onCheck, title: report.error },
@@ -6448,23 +6612,13 @@ window.__ModuleLoader__.load({
6448
6612
 
6449
6613
  /**
6450
6614
  * 检查更新的容器:进主页**静默**查一次(宿主机缓存 30 分钟),点一下强查。
6451
- * 静默失败也会在页头留下「检查失败」—— 不点也看得见"没问到",而不是假装无事。
6615
+ * 点「新版本」第一下只是确认(6 秒内不点第二下自动取消),第二下才真的装。
6452
6616
  */
6453
6617
  function UpdateLink({ push }) {
6454
6618
  const [phase, setPhase] = react.useState("idle");
6455
6619
  const [report, setReport] = react.useState(null);
6620
+ const [install, setInstall] = react.useState({ state: "idle", error: "" });
6456
6621
  const alive = react.useRef(true);
6457
- const copyCommand = react.useCallback(
6458
- async (text) => {
6459
- if (!text) {
6460
- push("error", "这次结果里没有升级命令,请先重新检查");
6461
- return;
6462
- }
6463
- const ok = await copyText(text);
6464
- push(ok ? "success" : "error", ok ? "升级命令已复制:装好后重启 DSH 生效" : "复制失败,请手动选择");
6465
- },
6466
- [push],
6467
- );
6468
6622
  const run = react.useCallback(
6469
6623
  async (force, announce) => {
6470
6624
  setPhase("checking");
@@ -6479,11 +6633,15 @@ window.__ModuleLoader__.load({
6479
6633
  push("error", `没查到最新版本:${String(next.error || "未知原因")}`);
6480
6634
  } else if (next.comparable === false) {
6481
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
+ );
6482
6643
  } else if (next.hasUpdate) {
6483
- push("success", `有新版本 v${next.latest}(当前 v${next.current})`, {
6484
- label: "复制升级命令",
6485
- onClick: () => copyCommand(next.upgradeCommand),
6486
- });
6644
+ push("success", `有新版本 v${next.latest}(当前 v${next.current}),点「新版本」一键安装`);
6487
6645
  } else {
6488
6646
  push("success", `已是最新(v${next.current})`);
6489
6647
  }
@@ -6494,7 +6652,7 @@ window.__ModuleLoader__.load({
6494
6652
  if (announce) push("error", `没查到最新版本:${String((e && e.message) || e)}`);
6495
6653
  }
6496
6654
  },
6497
- [push, copyCommand],
6655
+ [push],
6498
6656
  );
6499
6657
  react.useEffect(() => {
6500
6658
  alive.current = true;
@@ -6503,7 +6661,85 @@ window.__ModuleLoader__.load({
6503
6661
  alive.current = false;
6504
6662
  };
6505
6663
  }, [run]);
6506
- return h(UpdateLinkView, { phase, report, onCheck: () => run(true, true), onCopy: copyCommand });
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
+ });
6507
6743
  }
6508
6744
 
6509
6745
  function HomeMetaLinks({ state, push }) {
@@ -8130,6 +8366,7 @@ window.__ModuleLoader__.load({
8130
8366
  ctx.slots.inject("main", () =>
8131
8367
  ctx.slots.register({ name: "main", key: PANEL_ID }, MeshApp),
8132
8368
  );
8369
+ registerAtPeerSource(ctx);
8133
8370
  ctx.logger?.info?.("mesh client: 已注册 Mesh 工作台");
8134
8371
  }
8135
8372
 
@@ -8179,6 +8416,9 @@ window.__ModuleLoader__.load({
8179
8416
  FeedbackLink,
8180
8417
  feedbackBody,
8181
8418
  feedbackIssueUrl,
8419
+ buildAtPeerSource,
8420
+ loadOnlinePeers,
8421
+ resetAtPeersCache,
8182
8422
  };
8183
8423
  return module.exports;
8184
8424
  },
package/cordis.patch.yml CHANGED
@@ -61,6 +61,10 @@
61
61
  # 留空会回退到用户主目录 —— 那意味着对端任务在整个家目录里跑,建议指定。
62
62
  workspaceRoot: ''
63
63
 
64
+ # 聊天窗口 @ 派发:会话输入框里 @ 一台在线设备后,发送即把正文派给它。
65
+ # 关掉后 @ 只当普通文本(想自己用 mesh_run 决定派不派时关掉)。
66
+ atDispatch: true
67
+
64
68
  # ── 循环限速 ──
65
69
  #
66
70
  # 入站任务会自动新建会话并让 agent 开跑,而每条消息都由远端决定。