dsh-plugin-mesh 0.5.2 → 0.5.3

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/lib/index.js CHANGED
@@ -19,7 +19,7 @@ import { randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
19
19
  import { readFileSync, writeFileSync, mkdirSync, existsSync } from "node:fs";
20
20
  import { join, basename, isAbsolute, resolve } from "node:path";
21
21
  import { fileURLToPath } from "node:url";
22
- import { homedir, hostname, userInfo, platform } from "node:os";
22
+ import { homedir, hostname, userInfo, platform, arch } from "node:os";
23
23
  import z from "@deepseek-ai/schemastery";
24
24
  import { defineTool } from "@deepseek-ai/dsh-tools";
25
25
  import { createUserMessage } from "@deepseek-ai/dsh-llm";
@@ -45,6 +45,7 @@ import {
45
45
  CAPABILITY_STALE_MS,
46
46
  } from "./capabilities.js";
47
47
  import { conversationKey, replyTarget } from "./conversation.js";
48
+ import { buildDiagnostics, entryInfo, readPackageVersion } from "./diagnostics.js";
48
49
  import { buildPrompt } from "./prompt.js";
49
50
  import { resolvePairing } from "./pairing.js";
50
51
  import {
@@ -59,7 +60,13 @@ import { tailnetFetch, tailnetOrigin } from "./tsnet/bridge.js";
59
60
  export const name = "dsh-plugin-mesh";
60
61
  export const inject = ["tools", "webServer"];
61
62
 
62
- const VERSION = "0.5.2";
63
+ const VERSION = "0.5.3";
64
+ // 诊断用:进程启动时间、入口真实路径、**磁盘上** package.json 的版本。
65
+ // 这三样放一起才能回答"现在跑的到底是哪份代码" —— 只看 state.json 或重启日志
66
+ // 都答不了(真踩过:磁盘升到 0.5.1,进程还在 0.5.0,界面显示 0.5.0)。
67
+ const PROCESS_STARTED_AT = Date.now() - Math.round(process.uptime() * 1000);
68
+ const ENTRY_INFO = entryInfo(import.meta.url);
69
+ const DISK_VERSION = readPackageVersion(import.meta.url);
63
70
  const RULE_ID = "mesh-inbound";
64
71
  const RULE_KIND = "mesh";
65
72
  const MAX_BODY = 256 * 1024;
@@ -669,8 +676,24 @@ function applyUnsafe(ctx, config) {
669
676
  // 入站唤醒的"能力位":服务齐备后由 setupInbound 置位
670
677
  const waker = { ready: false, ctx: undefined };
671
678
 
679
+ /** 诊断块:进程自述版本 / 磁盘版本 / 入口 mtime / 安全字段的配置 / 能力摘要。 */
680
+ const diagnosticsPayload = () =>
681
+ buildDiagnostics({
682
+ version: VERSION,
683
+ packageVersion: DISK_VERSION,
684
+ entry: ENTRY_INFO.path,
685
+ entryMtimeMs: ENTRY_INFO.mtimeMs,
686
+ startedAt: PROCESS_STARTED_AT,
687
+ machine: identity.name,
688
+ hostname: hostname(),
689
+ platform: platform(),
690
+ arch: arch(),
691
+ config,
692
+ capabilities: currentCapabilities(),
693
+ });
694
+
672
695
  // 1) 先起对端 HTTP(拿到真实端口),再开始发现
673
- startPeerServer(ctx, { config, discovery, inbound, outbound, log, warn, waker, threadState, capFor, capOverrides, throttled, onHistoryChange: scheduleHistorySave })
696
+ startPeerServer(ctx, { config, discovery, inbound, outbound, log, warn, waker, threadState, capFor, capOverrides, throttled, onHistoryChange: scheduleHistorySave, diagnostics: diagnosticsPayload })
674
697
  .then(async (port) => {
675
698
  discovery.setPort(port);
676
699
 
@@ -778,7 +801,7 @@ function applyUnsafe(ctx, config) {
778
801
  registerTools(ctx, { discovery, config, inbound, outbound, log, warn, threadState, hostDispatched, onHistoryChange: scheduleHistorySave });
779
802
 
780
803
  // 4) UI 接口
781
- registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound, log, warn, threadState, hostDispatched, capFor, capOverrides, throttled, waker, onHistoryChange: scheduleHistorySave });
804
+ registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound, log, warn, threadState, hostDispatched, capFor, capOverrides, throttled, waker, onHistoryChange: scheduleHistorySave, diagnostics: diagnosticsPayload });
782
805
 
783
806
  ctx.effect(() => () => {
784
807
  discovery.stop();
@@ -790,6 +813,31 @@ function machineOf(discovery) {
790
813
  return discovery.selfRecord().machine;
791
814
  }
792
815
 
816
+ /**
817
+ * 对端的系统身份,单行文本(mesh_peers 工具用)。
818
+ * 新对端有结构化 osInfo;老对端只有 os 字符串,原样回退。
819
+ */
820
+ function osLine(peer) {
821
+ const info = peer?.osInfo;
822
+ if (!info) return peer?.os || "?";
823
+ const label = [info.name, info.version].filter(Boolean).join(" ") || peer?.os || "?";
824
+ const extra = [info.arch, info.distro, info.desktop].filter(Boolean).join(" / ");
825
+ return extra ? `${label} (${extra})` : label;
826
+ }
827
+
828
+ /** 一台机器的全部系统(宿主机 + WSL 等),单行文本。 */
829
+ function systemsLine(peer) {
830
+ const list = Array.isArray(peer?.systems) && peer.systems.length ? peer.systems : null;
831
+ if (!list) return osLine(peer);
832
+ return list
833
+ .map((s) => {
834
+ const label = [s.name, s.version].filter(Boolean).join(" ") || s.platform || "?";
835
+ const extra = [s.kind === "wsl" ? "WSL" : "", s.distro, s.desktop, s.arch].filter(Boolean).join("/");
836
+ return extra ? `${label} (${extra})` : label;
837
+ })
838
+ .join(" + ");
839
+ }
840
+
793
841
  /**
794
842
  * 把对端的能力名片渲染成几行文本(mesh_peers 工具用)。
795
843
  * 渲染逻辑在 capabilities.js 里(可单测),这里只做转发。
@@ -1721,7 +1769,7 @@ async function peerFetchEndpoint(ep, url, opts = {}) {
1721
1769
 
1722
1770
  // ───────────────────────── 对端 HTTP 服务 ─────────────────────────
1723
1771
 
1724
- function startPeerServer(ctx, { config, discovery, inbound, outbound, log, warn, waker, threadState, capFor, capOverrides, throttled, onHistoryChange }) {
1772
+ function startPeerServer(ctx, { config, discovery, inbound, outbound, log, warn, waker, threadState, capFor, capOverrides, throttled, onHistoryChange, diagnostics }) {
1725
1773
  const send = (res, code, payload) => {
1726
1774
  const body = Buffer.from(JSON.stringify(payload), "utf8");
1727
1775
  res.writeHead(code, { "Content-Type": "application/json; charset=utf-8", "Content-Length": body.length });
@@ -1754,6 +1802,9 @@ function startPeerServer(ctx, { config, discovery, inbound, outbound, log, warn,
1754
1802
 
1755
1803
  if (!authed(req)) return send(res, 403, { ok: false, error: "未配对:两台机器的配对码不一致(本机开启了 requirePairing)" });
1756
1804
 
1805
+ // 诊断:进程版本 vs 磁盘版本。**必须在对端鉴权之后** —— 里面有本机路径。
1806
+ if (path === "/mesh/v1/diagnostics") return send(res, 200, diagnostics());
1807
+
1757
1808
  if (path === "/mesh/v1/peers") return send(res, 200, { ok: true, peers: discovery.peers() });
1758
1809
 
1759
1810
  if (path === "/mesh/v1/tasks" && req.method === "GET") {
@@ -1879,7 +1930,7 @@ function registerTools(ctx, { discovery, config, inbound, outbound, log, warn, t
1879
1930
  const lines = list.map((p) => {
1880
1931
  const caps = capabilityLine(p);
1881
1932
  return (
1882
- `${p.online ? "● 在线" : "○ 离线"} ${p.machine} ${p.host}:${p.port} ${p.os} user=${p.user}` +
1933
+ `${p.online ? "● 在线" : "○ 离线"} ${p.machine} ${p.host}:${p.port} ${systemsLine(p)} user=${p.user}` +
1883
1934
  (p.hostname ? `\n hostname=${p.hostname}` : "") +
1884
1935
  (p.mac ? ` mac=${p.mac}` : "") +
1885
1936
  (caps ? `\n${caps}` : "")
@@ -2048,7 +2099,7 @@ function registerTools(ctx, { discovery, config, inbound, outbound, log, warn, t
2048
2099
 
2049
2100
  // ───────────────────────── UI 接口(本地回环) ─────────────────────────
2050
2101
 
2051
- function registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound, log, warn, threadState, hostDispatched, capFor, capOverrides, throttled, waker, onHistoryChange }) {
2102
+ function registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound, log, warn, threadState, hostDispatched, capFor, capOverrides, throttled, waker, onHistoryChange, diagnostics }) {
2052
2103
  const send = (res, code, payload) => {
2053
2104
  const body = Buffer.from(JSON.stringify(payload), "utf8");
2054
2105
  res.writeHead(code, { "Content-Type": "application/json; charset=utf-8", "Content-Length": body.length });
@@ -2149,6 +2200,10 @@ function registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound,
2149
2200
  addresses: lanIPv4Addresses(),
2150
2201
  platform: platform(),
2151
2202
  version: VERSION,
2203
+ // 磁盘上的版本 vs 本进程加载的版本。两者不一致 = 升级了但没重启,
2204
+ // 界面要明说"重启后生效",否则用户会拿旧行为当新版本的 bug 报上来。
2205
+ diskVersion: DISK_VERSION,
2206
+ versionDrift: !!DISK_VERSION && DISK_VERSION !== VERSION,
2152
2207
  secret: currentSecret(),
2153
2208
  // 本机的能力名片(对端看到的也是这一份)。**本机直接读采集缓存**,
2154
2209
  // 不走网络 —— 和 mac 一样,"自己的信息"没必要绕一圈。
@@ -2210,6 +2265,8 @@ function registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound,
2210
2265
  };
2211
2266
 
2212
2267
  route("/mesh/api/state", (_req, res) => send(res, 200, state()));
2268
+ // 只读诊断:UI 的「诊断」卡片用它;与 /mesh/v1/diagnostics 同一份数据。
2269
+ route("/mesh/api/diagnostics", (_req, res) => send(res, 200, diagnostics()));
2213
2270
 
2214
2271
  /**
2215
2272
  * 用户决定提高某个 thread 的限速上限。
package/lib/osinfo.js ADDED
@@ -0,0 +1,352 @@
1
+ /**
2
+ * 设备系统身份(osInfo / systems):平台、展示名、版本、发行版、内核、桌面环境、架构。
3
+ *
4
+ * 三层数据:
5
+ * · osInfo —— 宿主机(老 UI / 老对端只认这一份)
6
+ * · systems[] —— 这台机器上可用的系统列表:宿主机 + WSL 发行版(Windows)
7
+ * · capabilities —— 运行时环境(node/python/...),仍走原来的能力名片
8
+ *
9
+ * 为什么单独一个模块:
10
+ * · 探测有平台分支(sw_vers / /etc/os-release / 注册表 / getprop),散在 discovery 里很难测;
11
+ * · 结果在进程生命周期内不变,探测一次即可 —— 心跳每 5s 一次,不能每条都跑子进程;
12
+ * · 对端名片是网络输入,接收侧必须清洗(sanitizeOsInfo / sanitizeSystems)。
13
+ *
14
+ * WSL 只读注册表,不启动已停止的发行版:要的是"这台机器上有哪些系统",不是把它们
15
+ * 一个个拉起来(那会有几十秒副作用)。运行中的发行版才尝试读 /etc/os-release 补版本。
16
+ */
17
+ import os from "node:os";
18
+ import { execFileSync } from "node:child_process";
19
+ import { readFileSync } from "node:fs";
20
+
21
+ const FIELD_MAX = {
22
+ name: 48,
23
+ version: 48,
24
+ distro: 32,
25
+ kernel: 64,
26
+ desktop: 32,
27
+ arch: 16,
28
+ };
29
+
30
+ const PLATFORMS = new Set(["win32", "darwin", "linux", "android"]);
31
+ const KINDS = new Set(["host", "wsl", "vm", "container"]);
32
+ /** 一台机器的名片最多列几个系统(宿主机 + 3 个额外环境),避免名片无限膨胀。 */
33
+ const MAX_SYSTEMS = 4;
34
+ /** Docker/Rancher/Podman 的 WSL 发行版不是用户系统,不列。 */
35
+ const NON_USER_WSL = /^(docker-desktop|rancher-desktop|podman-machine)/i;
36
+ const WSL_KEY = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Lxss";
37
+
38
+ /** 去控制字符、折叠空白、按字段截断。 */
39
+ function clean(value, max) {
40
+ return String(value ?? "")
41
+ .replace(/[\u0000-\u001f\u007f]/g, "")
42
+ .replace(/\s+/g, " ")
43
+ .trim()
44
+ .slice(0, max);
45
+ }
46
+
47
+ /** 命令输出只取第一行(getprop / sw_vers 都可能带换行)。 */
48
+ function firstLine(value, max) {
49
+ return clean(String(value ?? "").split("\n")[0], max);
50
+ }
51
+
52
+ /** 解析 /etc/os-release;引号可有可无,值里允许 `=`。 */
53
+ function parseOsRelease(text) {
54
+ const out = {};
55
+ for (const line of String(text ?? "").split("\n")) {
56
+ const m = /^([A-Z_]+)=(.*)$/.exec(line.trim());
57
+ if (!m) continue;
58
+ let value = m[2].trim();
59
+ if (
60
+ (value.startsWith('"') && value.endsWith('"')) ||
61
+ (value.startsWith("'") && value.endsWith("'"))
62
+ ) {
63
+ value = value.slice(1, -1);
64
+ }
65
+ out[m[1]] = value;
66
+ }
67
+ return out;
68
+ }
69
+
70
+ /** XDG_CURRENT_DESKTOP 常是 "ubuntu:GNOME",取最后一段。 */
71
+ function desktopEnv(env) {
72
+ const raw = String(env?.XDG_CURRENT_DESKTOP || env?.DESKTOP_SESSION || "").trim();
73
+ if (!raw) return "";
74
+ const parts = raw.split(":").map((s) => s.trim()).filter(Boolean);
75
+ return parts[parts.length - 1] ?? "";
76
+ }
77
+
78
+ function defaultRun(cmd, args) {
79
+ return execFileSync(cmd, args, {
80
+ encoding: "utf8",
81
+ timeout: 2000,
82
+ windowsHide: true,
83
+ stdio: ["ignore", "pipe", "ignore"],
84
+ }).trim();
85
+ }
86
+
87
+ /**
88
+ * 探测宿主机系统身份。所有参数都可注入,方便在非目标平台上用 fixture 单测。
89
+ *
90
+ * 失败一律降级为空字段 / 平台通用名,**绝不抛**:名片的缺失不能拖垮启动,
91
+ * 也不能把"没探到"伪装成某个具体结论。
92
+ */
93
+ export function detectOsInfo(opts = {}) {
94
+ const platformRaw = String(opts.platform ?? process.platform).toLowerCase();
95
+ const platform = PLATFORMS.has(platformRaw) ? platformRaw : "";
96
+ const release = clean(opts.release ?? os.release(), FIELD_MAX.kernel);
97
+ const arch = clean(opts.arch ?? os.arch(), FIELD_MAX.arch);
98
+ const env = opts.env ?? process.env;
99
+ const osVersion =
100
+ opts.osVersion ??
101
+ (() => {
102
+ try {
103
+ return os.version();
104
+ } catch {
105
+ return "";
106
+ }
107
+ });
108
+ const readFile = opts.readFile ?? ((path) => readFileSync(path, "utf8"));
109
+ const run = opts.run ?? defaultRun;
110
+
111
+ let name = "";
112
+ let version = "";
113
+ let distro = "";
114
+ let desktop = "";
115
+
116
+ if (platformRaw === "win32") {
117
+ // Node 13+ 的 os.version() 已经是 "Windows 11 Home China" 这类产品名。
118
+ name = firstLine(osVersion(), FIELD_MAX.name) || "Windows";
119
+ version = release;
120
+ } else if (platformRaw === "darwin") {
121
+ try {
122
+ name = firstLine(run("sw_vers", ["-productName"]), FIELD_MAX.name);
123
+ } catch {
124
+ name = "";
125
+ }
126
+ try {
127
+ version = firstLine(run("sw_vers", ["-productVersion"]), FIELD_MAX.version);
128
+ } catch {
129
+ version = "";
130
+ }
131
+ name = name || "macOS";
132
+ } else if (platformRaw === "linux") {
133
+ try {
134
+ const rel = parseOsRelease(readFile("/etc/os-release"));
135
+ name = clean(rel.NAME || rel.PRETTY_NAME || rel.ID || "Linux", FIELD_MAX.name);
136
+ version = clean(rel.VERSION_ID || "", FIELD_MAX.version);
137
+ distro = clean(rel.ID || "", FIELD_MAX.distro);
138
+ } catch {
139
+ name = "Linux";
140
+ }
141
+ desktop = clean(desktopEnv(env), FIELD_MAX.desktop);
142
+ } else if (platformRaw === "android") {
143
+ name = "Android";
144
+ try {
145
+ version = firstLine(run("getprop", ["ro.build.version.release"]), FIELD_MAX.version);
146
+ } catch {
147
+ version = "";
148
+ }
149
+ } else {
150
+ // 未知平台(FreeBSD 等)至少给个可读名字;platform 留空让 UI 用回退徽章。
151
+ name = clean(platformRaw, FIELD_MAX.name);
152
+ version = release;
153
+ }
154
+
155
+ return sanitizeOsInfo({
156
+ platform,
157
+ name,
158
+ version,
159
+ distro,
160
+ kernel: release,
161
+ desktop,
162
+ arch,
163
+ });
164
+ }
165
+
166
+ /**
167
+ * 清洗对端名片里的单个系统。
168
+ *
169
+ * platform 走白名单(UI 的 logo 映射只认这四个);文本字段控制字符剥掉并截断。
170
+ * 返回 null 表示"对端没报 / 报的东西不可用",UI 应回退到老的 os 字符串。
171
+ */
172
+ export function sanitizeOsInfo(raw) {
173
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
174
+ const platform = PLATFORMS.has(String(raw.platform ?? "").toLowerCase())
175
+ ? String(raw.platform).toLowerCase()
176
+ : "";
177
+ const out = {
178
+ platform,
179
+ name: clean(raw.name, FIELD_MAX.name),
180
+ version: clean(raw.version, FIELD_MAX.version),
181
+ distro: clean(raw.distro, FIELD_MAX.distro),
182
+ kernel: clean(raw.kernel, FIELD_MAX.kernel),
183
+ desktop: clean(raw.desktop, FIELD_MAX.desktop),
184
+ arch: clean(raw.arch, FIELD_MAX.arch),
185
+ };
186
+ if (!out.platform && !out.name) return null;
187
+ return out;
188
+ }
189
+
190
+ /** 解析 `reg query ...\Lxss /s` 的输出,每个 `{guid}` 块一条记录。 */
191
+ function parseWslRegistry(text) {
192
+ const blocks = [];
193
+ let cur = null;
194
+ for (const raw of String(text ?? "").split(/\r?\n/)) {
195
+ const line = raw.trim();
196
+ if (!line) continue;
197
+ if (/^HKEY_/i.test(line)) {
198
+ if (cur) blocks.push(cur);
199
+ cur = {};
200
+ continue;
201
+ }
202
+ const m = /^(\w+)\s+REG_(?:SZ|DWORD|EXPAND_SZ)\s+(.+)$/i.exec(line);
203
+ if (m && cur) cur[m[1]] = m[2].trim();
204
+ }
205
+ if (cur) blocks.push(cur);
206
+ return blocks.filter((b) => b && b.DistributionName);
207
+ }
208
+
209
+ /**
210
+ * 运行中的 WSL 发行版,尝试从 9p 挂载读 /etc/os-release 补版本。
211
+ * 停着的发行版不碰(不启动它);读不到就只报注册表里的名字。
212
+ */
213
+ function readWslOsRelease(name, readFile) {
214
+ for (const root of ["\\\\wsl.localhost\\", "\\\\wsl$\\"]) {
215
+ try {
216
+ const rel = parseOsRelease(readFile(`${root}${name}\\etc\\os-release`));
217
+ if (rel.NAME || rel.ID) return rel;
218
+ } catch {
219
+ /* 没运行 / 9p 不可访问 */
220
+ }
221
+ }
222
+ return null;
223
+ }
224
+
225
+ /**
226
+ * 从注册表列 WSL 发行版(只读,不启动任何发行版)。
227
+ * 运行时探测也用它判断哪些发行版处于 running 状态。
228
+ */
229
+ export function wslTargets(opts = {}) {
230
+ const run = opts.run ?? defaultRun;
231
+ let text;
232
+ try {
233
+ text = run("reg", ["query", WSL_KEY, "/s"]);
234
+ } catch {
235
+ return [];
236
+ }
237
+
238
+ const out = [];
239
+ for (const block of parseWslRegistry(text)) {
240
+ const name = String(block.DistributionName ?? "").trim();
241
+ if (!name || NON_USER_WSL.test(name)) continue;
242
+ out.push({
243
+ name,
244
+ running: parseInt(String(block.State ?? ""), 0) === 1,
245
+ osVersion: String(block.OsVersion ?? "").trim(),
246
+ flavor: String(block.Flavor ?? "").trim().toLowerCase(),
247
+ });
248
+ if (out.length >= MAX_SYSTEMS - 1) break;
249
+ }
250
+ return out;
251
+ }
252
+
253
+ /** 把注册表目标变成 systems[] 里的条目(运行中的才补 os-release 版本)。 */
254
+ function detectWsl(opts = {}) {
255
+ const readFile = opts.readFile ?? ((path) => readFileSync(path, "utf8"));
256
+ const out = [];
257
+ for (const target of wslTargets(opts)) {
258
+ let name = target.name;
259
+ let version = target.osVersion;
260
+ let distro = target.flavor;
261
+
262
+ if ((!version || !distro) && target.running) {
263
+ const rel = readWslOsRelease(target.name, readFile);
264
+ if (rel) {
265
+ name = clean(rel.NAME || name, FIELD_MAX.name);
266
+ version = version || clean(rel.VERSION_ID || "", FIELD_MAX.version);
267
+ distro = distro || clean(rel.ID || "", FIELD_MAX.distro).toLowerCase();
268
+ }
269
+ }
270
+
271
+ out.push({
272
+ kind: "wsl",
273
+ platform: "linux",
274
+ name: clean(name, FIELD_MAX.name),
275
+ version: clean(version, FIELD_MAX.version),
276
+ distro: clean(distro, FIELD_MAX.distro),
277
+ // WSL 的 kernel/desktop/arch 不启动发行版拿不到,留空比瞎猜好。
278
+ kernel: "",
279
+ desktop: "",
280
+ arch: "",
281
+ });
282
+ }
283
+ return out;
284
+ }
285
+
286
+ /** 本机系统列表:宿主机第一,后面是 WSL 等额外环境。 */
287
+ export function detectSystems(opts = {}) {
288
+ const host = detectOsInfo(opts);
289
+ const platform = String(opts.platform ?? process.platform);
290
+ const extra = platform === "win32" ? detectWsl(opts) : [];
291
+ return sanitizeSystems([{ kind: "host", ...host }, ...extra]) ?? [];
292
+ }
293
+
294
+ /**
295
+ * 清洗对端名片里的 systems[]:逐项复用 sanitizeOsInfo,kind 走白名单,
296
+ * 去重、最多 MAX_SYSTEMS 项,宿主机排第一。
297
+ */
298
+ export function sanitizeSystems(raw) {
299
+ if (!Array.isArray(raw)) return null;
300
+ const out = [];
301
+ const seen = new Set();
302
+ for (const item of raw) {
303
+ const info = sanitizeOsInfo(item);
304
+ if (!info) continue;
305
+ const kindRaw = String(item?.kind ?? "").toLowerCase();
306
+ const kind = KINDS.has(kindRaw) ? kindRaw : "";
307
+ const key = `${kind}|${info.platform}|${info.name}|${info.version}`;
308
+ if (seen.has(key)) continue;
309
+ seen.add(key);
310
+ out.push({ kind, ...info });
311
+ if (out.length >= MAX_SYSTEMS * 2) break;
312
+ }
313
+ if (out.length === 0) return null;
314
+ // 宿主机排第一;其余保持到达顺序(stable sort)。
315
+ out.sort((a, b) => (a.kind === "host" ? 0 : 1) - (b.kind === "host" ? 0 : 1));
316
+ return out.slice(0, MAX_SYSTEMS);
317
+ }
318
+
319
+ let cached;
320
+ let cachedSystems;
321
+
322
+ /** 宿主机系统身份,进程内只探测一次。 */
323
+ export function osInfo() {
324
+ if (cached === undefined) {
325
+ try {
326
+ cached = detectOsInfo();
327
+ } catch {
328
+ cached = null;
329
+ }
330
+ }
331
+ return cached;
332
+ }
333
+
334
+ /** 本机系统列表(宿主机 + WSL),进程内只探测一次。 */
335
+ export function systems() {
336
+ if (cachedSystems === undefined) {
337
+ try {
338
+ const host = osInfo();
339
+ const extra = process.platform === "win32" ? detectWsl() : [];
340
+ cachedSystems = sanitizeSystems(host ? [{ kind: "host", ...host }, ...extra] : extra);
341
+ } catch {
342
+ cachedSystems = null;
343
+ }
344
+ }
345
+ return cachedSystems;
346
+ }
347
+
348
+ /** 只为自测:清掉缓存,避免 fixture 之间互相污染。 */
349
+ export function __resetOsInfoCache() {
350
+ cached = undefined;
351
+ cachedSystems = undefined;
352
+ }
package/llms.txt CHANGED
@@ -28,6 +28,8 @@ Verify after restart: `GET http://127.0.0.1:45917/mesh/v1/health` returns JSON c
28
28
  - Serves a small HTTP peer API on TCP port 45917 (configurable via `port`).
29
29
  - Optionally starts a bundled Go sidecar running a userspace Tailscale node (tsnet). No TUN device is created, so the host cannot route to `100.x.y.z`; all tailnet traffic is proxied through the sidecar. The binary is downloaded per-platform on first use and verified against checksums pinned in the plugin source.
30
30
  - Auto-creates an agent session on the receiving machine when a task arrives, then routes that task to a new or reused session.
31
+ - Reports a structured `osInfo` card entry (host) and a `systems[]` array: host first, then environments such as WSL distros on Windows (`kind: "wsl"`, Linux `platform`, distro name/version). Older peers only send `os`, and the UI falls back to parsing it; purely display data, at most 4 systems.
32
+ - On Windows, probes runtimes inside **running** WSL distros (`wsl.exe -d <name> -e sh -lc …`) and reports them as `capabilities.wsl[]`; stopped distros are never started just to probe. Host and WSL runtimes are displayed separately.
31
33
 
32
34
  ## Tools registered (callable by the agent)
33
35
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-mesh",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "type": "module",
5
5
  "description": "DSH Mesh:局域网自动发现同网段的 DSH 实例、显示每台机器上报的能力,并双向派发任务;可用内置的用户态 Tailscale 节点跨互联网组网。Discovers other DSH instances on the LAN, shows the capabilities each one reports, and dispatches tasks between machines in both directions, with an optional userspace Tailscale node for links across networks.",
6
6
  "license": "MIT",
@@ -64,7 +64,9 @@
64
64
  "selftest:persist": "node lib/_selftest-persist.mjs",
65
65
  "selftest:reasoning": "node lib/_selftest-reasoning.mjs",
66
66
  "selftest:layout": "node lib/_selftest-layout.mjs",
67
- "test": "npm run check && npm run selftest && npm run selftest:prompt && npm run selftest:pairing && npm run selftest:client && npm run selftest:caps && npm run selftest:release && npm run selftest:reply && npm run selftest:reasoning && npm run selftest:resume && npm run selftest:persist && npm run selftest:layout",
67
+ "selftest:diagnostics": "node lib/_selftest-diagnostics.mjs",
68
+ "selftest:osinfo": "node lib/_selftest-osinfo.mjs",
69
+ "test": "npm run check && npm run selftest && npm run selftest:prompt && npm run selftest:pairing && npm run selftest:client && npm run selftest:caps && npm run selftest:release && npm run selftest:reply && npm run selftest:reasoning && npm run selftest:resume && npm run selftest:persist && npm run selftest:layout && npm run selftest:diagnostics && npm run selftest:osinfo",
68
70
  "check": "node scripts/check-version.mjs && node scripts/check-tdz.mjs && node --check lib/index.js && node --check lib/layout.js && node --check lib/discovery.js && node --check lib/conversation.js && node --check lib/identity.js && node --check lib/capabilities.js && node --check lib/prompt.js && node --check lib/pairing.js && node --check lib/scan.js && node --check lib/tsnet/download.js && node --check lib/tsnet/manager.js && node --check lib/tsnet/bridge.js && node --check client/client.js && node --check scripts/release-plan.mjs && npm run check:loadable && npm run check:docs",
69
71
  "build:sidecar": "bash scripts/build-sidecar.sh",
70
72
  "verify:mirror": "node scripts/verify-lan-mirror.mjs",