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/client/client.js +72 -1
- package/lib/_selftest-capabilities.mjs +43 -0
- package/lib/_selftest-diagnostics.mjs +92 -0
- package/lib/_selftest-osinfo.mjs +379 -0
- package/lib/_selftest-workbench.mjs +53 -0
- package/lib/capabilities.js +181 -25
- package/lib/diagnostics.js +109 -0
- package/lib/discovery.js +17 -0
- package/lib/index.js +64 -7
- package/lib/osinfo.js +352 -0
- package/llms.txt +2 -0
- package/package.json +4 -2
|
@@ -123,6 +123,7 @@ const {
|
|
|
123
123
|
TaskRow,
|
|
124
124
|
TaskDetail,
|
|
125
125
|
SettingsView,
|
|
126
|
+
Diagnostics,
|
|
126
127
|
Composer,
|
|
127
128
|
DispatchPanel,
|
|
128
129
|
DeviceList,
|
|
@@ -419,6 +420,22 @@ test("任务页左栏只写条数,不重复「任务」", () => {
|
|
|
419
420
|
assert.notEqual(titles[0], "任务");
|
|
420
421
|
});
|
|
421
422
|
|
|
423
|
+
test("诊断卡显示「进程版本 / 磁盘版本」,漂移时说清要重启", () => {
|
|
424
|
+
const drift = {
|
|
425
|
+
self: { version: "0.5.2", diskVersion: "0.5.3", versionDrift: true, port: 45917 },
|
|
426
|
+
config: {},
|
|
427
|
+
peers: [],
|
|
428
|
+
};
|
|
429
|
+
const txt = textOf(Diagnostics({ state: drift, push: noop })).join(" ");
|
|
430
|
+
assert.ok(txt.includes("版本(进程)"), txt);
|
|
431
|
+
assert.ok(txt.includes("版本(磁盘)"), txt);
|
|
432
|
+
assert.ok(txt.includes("重启 DSH 后新版本才生效"), txt);
|
|
433
|
+
|
|
434
|
+
// 没漂移时不该吓人
|
|
435
|
+
const same = { self: { version: "0.5.2", diskVersion: "0.5.2", versionDrift: false }, config: {}, peers: [] };
|
|
436
|
+
assert.ok(!textOf(Diagnostics({ state: same, push: noop })).join(" ").includes("重启 DSH"));
|
|
437
|
+
});
|
|
438
|
+
|
|
422
439
|
test("连接页不再重复写「连接」大标题", () => {
|
|
423
440
|
const el = SettingsView({ state, open: null, onOpen: noop, onSaveName: async () => true, nameBusy: false, push: noop, reload: async () => {} });
|
|
424
441
|
let h1 = 0;
|
|
@@ -428,6 +445,42 @@ test("连接页不再重复写「连接」大标题", () => {
|
|
|
428
445
|
assert.equal(h1, 0, "tab 已经叫「连接」,正文不必再来一个 h1");
|
|
429
446
|
});
|
|
430
447
|
|
|
448
|
+
console.log("\n── 系统身份(osInfo / systems / WSL)──");
|
|
449
|
+
|
|
450
|
+
const winPeer = {
|
|
451
|
+
...peer,
|
|
452
|
+
os: "win32 10.0.22631",
|
|
453
|
+
osInfo: { platform: "win32", name: "Windows 11 Home China", version: "10.0.22631", distro: "", kernel: "10.0.22631", desktop: "", arch: "x64" },
|
|
454
|
+
systems: [
|
|
455
|
+
{ kind: "host", platform: "win32", name: "Windows 11 Home China", version: "10.0.22631" },
|
|
456
|
+
{ kind: "wsl", platform: "linux", name: "Ubuntu", version: "22.04", distro: "ubuntu" },
|
|
457
|
+
],
|
|
458
|
+
capabilities: { ...peer.capabilities, wsl: [{ name: "Ubuntu", runtimes: { node: "22.1", python: "3.12" }, error: "" }] },
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
test("设备详情用结构化 osInfo(不再是 win32 10.0.xxx 这种机器串)", () => {
|
|
462
|
+
const txt = textOf(DeviceDetail({ peer: winPeer, now, onCompose: noop, onProbe: noop, onBack: noop })).join(" ");
|
|
463
|
+
assert.ok(txt.includes("Windows 11 Home China"), txt);
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
test("同一台机器上的 WSL 单独标出来,不混进宿主机", () => {
|
|
467
|
+
const txt = textOf(DeviceDetail({ peer: winPeer, now, onCompose: noop, onProbe: noop, onBack: noop })).join(" ");
|
|
468
|
+
assert.ok(txt.includes("WSL Ubuntu 22.04"), `应显示 WSL 发行版:${txt}`);
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
test("老对端(只有 os 字符串)不能崩,回退到 osLabel", () => {
|
|
472
|
+
const legacy = { ...peer, os: "linux 6.1", osInfo: null, systems: null, capabilities: { runtimes: {} } };
|
|
473
|
+
const txt = textOf(DeviceDetail({ peer: legacy, now, onCompose: noop, onProbe: noop, onBack: noop })).join(" ");
|
|
474
|
+
assert.ok(txt.includes("Linux"), txt);
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
test("能力 chip 里 WSL 运行时单独一行(Windows 的 Python ≠ WSL 的 Python)", () => {
|
|
478
|
+
const txt = textOf(CapabilityChips({ caps: winPeer.capabilities, peer: winPeer })).join(" ");
|
|
479
|
+
assert.ok(txt.includes("WSL"), txt);
|
|
480
|
+
assert.ok(txt.includes("Ubuntu"), txt);
|
|
481
|
+
assert.ok(txt.includes("node 22.1"), txt);
|
|
482
|
+
});
|
|
483
|
+
|
|
431
484
|
console.log("\n── 图标:网段探测 vs 单机探测 ──");
|
|
432
485
|
|
|
433
486
|
/** 收集组件树里所有按钮/图标按钮的 icon 名(含函数组件展开)。 */
|
package/lib/capabilities.js
CHANGED
|
@@ -23,9 +23,13 @@
|
|
|
23
23
|
* 失败更糟,因为它看起来像正常的空数据。
|
|
24
24
|
*/
|
|
25
25
|
import { execFile } from "node:child_process";
|
|
26
|
+
import { promisify } from "node:util";
|
|
26
27
|
import { existsSync } from "node:fs";
|
|
27
28
|
import { homedir, release, totalmem, cpus, platform, arch } from "node:os";
|
|
28
29
|
import { join, delimiter } from "node:path";
|
|
30
|
+
import { wslTargets } from "./osinfo.js";
|
|
31
|
+
|
|
32
|
+
const execFileAsync = promisify(execFile);
|
|
29
33
|
|
|
30
34
|
/** 重新采集的间隔。设计上低频:装了新运行时最迟 10 分钟后上名片。 */
|
|
31
35
|
export const CAPABILITY_REFRESH_MS = 10 * 60 * 1000;
|
|
@@ -332,6 +336,85 @@ export async function collectRuntimes(specs = RUNTIMES) {
|
|
|
332
336
|
return { runtimes, errors };
|
|
333
337
|
}
|
|
334
338
|
|
|
339
|
+
/**
|
|
340
|
+
* 在 WSL 里探测运行时的 shell 片段。
|
|
341
|
+
*
|
|
342
|
+
* 命令是常量(来自 RUNTIMES),不拼接用户输入。每行输出 `名字<TAB>版本输出`;
|
|
343
|
+
* 没装的运行时不会出现在输出里。python 的 fallback 用 if/elif,避免 python3 与
|
|
344
|
+
* python 各打一行。
|
|
345
|
+
*/
|
|
346
|
+
function wslProbeScript() {
|
|
347
|
+
return RUNTIMES.map((spec) => {
|
|
348
|
+
const cmds = [spec, spec.fallback].filter(Boolean);
|
|
349
|
+
const branches = cmds
|
|
350
|
+
.map(
|
|
351
|
+
(c, i) =>
|
|
352
|
+
`${i === 0 ? "if" : "elif"} command -v ${c.cmd} >/dev/null 2>&1; then ` +
|
|
353
|
+
`v=$(${c.cmd} ${c.args.join(" ")} 2>&1 | head -n 1); printf '%s\\t%s\\n' ${spec.name} "$v";`,
|
|
354
|
+
)
|
|
355
|
+
.join(" ");
|
|
356
|
+
return `${branches} fi`;
|
|
357
|
+
}).join("\n");
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* 探测运行中的 WSL 发行版里的运行时。
|
|
362
|
+
*
|
|
363
|
+
* 只探 `running` 的发行版:`wsl -d <name>` 对停着的发行版会把它启动起来,
|
|
364
|
+
* 为了看一眼版本付几十秒启动代价不值得。最多两个发行版,每个 8s 超时;
|
|
365
|
+
* 失败只记录短错误码,绝不抛(能力采集不能拖垮启动)。
|
|
366
|
+
*
|
|
367
|
+
* @returns [{ name, runtimes, error }]
|
|
368
|
+
*/
|
|
369
|
+
export async function collectWslRuntimes({ platform: p = platform(), targets, run, timeoutMs = 8000 } = {}) {
|
|
370
|
+
if (p !== "win32") return [];
|
|
371
|
+
let list = targets;
|
|
372
|
+
if (!list) {
|
|
373
|
+
try {
|
|
374
|
+
list = wslTargets();
|
|
375
|
+
} catch {
|
|
376
|
+
return [];
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
const running = (list ?? []).filter((t) => t && t.running).slice(0, 2);
|
|
380
|
+
if (running.length === 0) return [];
|
|
381
|
+
|
|
382
|
+
const exec = run ?? ((cmd, args, opts) => execFileAsync(cmd, args, opts));
|
|
383
|
+
const script = wslProbeScript();
|
|
384
|
+
|
|
385
|
+
return Promise.all(
|
|
386
|
+
running.map(async (target) => {
|
|
387
|
+
try {
|
|
388
|
+
const { stdout } = await exec(
|
|
389
|
+
"wsl.exe",
|
|
390
|
+
["-d", target.name, "-e", "sh", "-lc", script],
|
|
391
|
+
{ timeout: timeoutMs, windowsHide: true, maxBuffer: 1 << 20 },
|
|
392
|
+
);
|
|
393
|
+
const runtimes = {};
|
|
394
|
+
for (const line of String(stdout ?? "").split("\n")) {
|
|
395
|
+
const tab = line.indexOf("\t");
|
|
396
|
+
if (tab <= 0) continue;
|
|
397
|
+
const name = line.slice(0, tab).trim().toLowerCase();
|
|
398
|
+
const version = parseVersion(line.slice(tab + 1));
|
|
399
|
+
if (name && version) runtimes[name] = version;
|
|
400
|
+
}
|
|
401
|
+
return {
|
|
402
|
+
name: target.name,
|
|
403
|
+
runtimes,
|
|
404
|
+
error: Object.keys(runtimes).length > 0 ? "" : "empty-output",
|
|
405
|
+
};
|
|
406
|
+
} catch (err) {
|
|
407
|
+
return {
|
|
408
|
+
name: target.name,
|
|
409
|
+
runtimes: {},
|
|
410
|
+
error: String(err?.code ?? err?.message ?? err).slice(0, 80),
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
}),
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
|
|
335
418
|
/**
|
|
336
419
|
* 探测失败的项里有没有"不确定"的(超时 / spawn 失败)。
|
|
337
420
|
*
|
|
@@ -431,6 +514,8 @@ export const __normPathForCompare = normPathForCompare;
|
|
|
431
514
|
/** 只为自测导出:原始 GPU 探测输出 —— 用来区分"这台机器没有显卡"和"解析器坏了"。 */
|
|
432
515
|
export const __probeGpu = probeGpu;
|
|
433
516
|
export const __isUncertain = isUncertain;
|
|
517
|
+
/** 只为自测导出:GPU 探测的候选链 —— 靠它钉住「Windows 先问 nvidia-smi」这个顺序。 */
|
|
518
|
+
export const __gpuProbeSpecs = gpuProbeSpecs;
|
|
434
519
|
/** 只为自测导出:Store 别名目录的排除规则(Mac 上没有该目录,无法端到端复现)。 */
|
|
435
520
|
export const __storeAliasDir = STORE_ALIAS_DIR;
|
|
436
521
|
/** 只为自测导出:让自测能按判据反推 runtimesIncomplete 的期望值,而不是写死。 */
|
|
@@ -498,15 +583,30 @@ export function parseNvidiaGpu(text) {
|
|
|
498
583
|
}
|
|
499
584
|
|
|
500
585
|
/**
|
|
501
|
-
*
|
|
586
|
+
* 虚拟显示驱动/远程桌面适配器的名字特征。
|
|
587
|
+
*
|
|
588
|
+
* 为什么需要它:`Get-CimInstance Win32_VideoController` 在多显卡机器上给出多行,
|
|
589
|
+
* 而 MuMu / GameViewer / Parsec / RDP / Hyper-V 这类虚拟适配器常常**排在真卡
|
|
590
|
+
* 前面**。原实现只取第一行,于是装了 3060 的机器会被名片报成
|
|
591
|
+
* "MuMuVMM Display Adapter" —— 真卡被藏起来,Placement 拿到的是假事实。
|
|
502
592
|
*
|
|
503
|
-
*
|
|
504
|
-
|
|
593
|
+
* 保守起见只匹配明确的虚拟/远程产品名;Intel/AMD 的核显是**真卡**,不排除。
|
|
594
|
+
*/
|
|
595
|
+
const VIRTUAL_GPU =
|
|
596
|
+
/virtual|remote|parsec|gameviewer|mumu|vmware|virtualbox|hyper-?v|basic display|rdp|citrix|spacedesk|sunlogin|todesk|displaylink/i;
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* 从 powershell `Get-CimInstance Win32_VideoController` 的多行输出里挑真卡。
|
|
600
|
+
*
|
|
601
|
+
* 规则:跳过已知虚拟适配器,取第一条剩下的;全都像虚拟适配器时退回第一行
|
|
602
|
+
* (**不要**因此返回 null —— "只有虚拟显卡"是一台真机器的真实状态,退回第一行
|
|
603
|
+
* 至少让调用方看到它是什么)。
|
|
505
604
|
*/
|
|
506
605
|
export function parseWindowsGpu(text) {
|
|
507
606
|
const s = gpuText(text);
|
|
508
607
|
if (s === null) return null;
|
|
509
|
-
const
|
|
608
|
+
const names = s.split("\n").map((l) => l.trim()).filter(Boolean);
|
|
609
|
+
const name = names.find((n) => !VIRTUAL_GPU.test(n)) ?? names[0] ?? "";
|
|
510
610
|
return name ? { present: true, name, vramMb: 0 } : null;
|
|
511
611
|
}
|
|
512
612
|
|
|
@@ -520,26 +620,37 @@ export function parseWindowsGpu(text) {
|
|
|
520
620
|
* ⚠️ 每个分支都必须读 `r.output`(runProbe 返回的是 `{output,error}`)。
|
|
521
621
|
* 直接把 `r` 交给解析函数就是上面说的那个 bug。
|
|
522
622
|
*/
|
|
523
|
-
/**
|
|
524
|
-
|
|
623
|
+
/**
|
|
624
|
+
* 每个平台"按什么顺序问 + 用哪个解析器"集中一张表:自测与生产共用同一张表。
|
|
625
|
+
*
|
|
626
|
+
* 返回的是**候选列表**而不是单个命令,因为 Windows 上要"先问准的、再问全的":
|
|
627
|
+
* · `nvidia-smi` 只报真 N 卡,还带显存,是最可信的一手;
|
|
628
|
+
* · `Win32_VideoController` 更全(核显/AMD 也有),但会把虚拟适配器排前面。
|
|
629
|
+
* 先跑前者、解析不出来再跑后者,就不会被虚拟适配器骗到。
|
|
630
|
+
*/
|
|
631
|
+
function gpuProbeSpecs(p = platform()) {
|
|
632
|
+
const NV = {
|
|
633
|
+
cmd: "nvidia-smi",
|
|
634
|
+
args: ["--query-gpu=name,memory.total", "--format=csv,noheader,nounits"],
|
|
635
|
+
parse: parseNvidiaGpu,
|
|
636
|
+
};
|
|
525
637
|
switch (p) {
|
|
526
638
|
case "darwin":
|
|
527
|
-
return { cmd: "system_profiler", args: ["SPDisplaysDataType"], parse: parseMacGpu };
|
|
639
|
+
return [{ cmd: "system_profiler", args: ["SPDisplaysDataType"], parse: parseMacGpu }];
|
|
528
640
|
case "linux":
|
|
529
641
|
case "android":
|
|
530
|
-
return
|
|
531
|
-
cmd: "nvidia-smi",
|
|
532
|
-
args: ["--query-gpu=name,memory.total", "--format=csv,noheader,nounits"],
|
|
533
|
-
parse: parseNvidiaGpu,
|
|
534
|
-
};
|
|
642
|
+
return [NV];
|
|
535
643
|
case "win32":
|
|
536
|
-
return
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
644
|
+
return [
|
|
645
|
+
NV,
|
|
646
|
+
{
|
|
647
|
+
cmd: "powershell",
|
|
648
|
+
args: ["-NoProfile", "-Command", "(Get-CimInstance Win32_VideoController).Name -join \"`n\""],
|
|
649
|
+
parse: parseWindowsGpu,
|
|
650
|
+
},
|
|
651
|
+
];
|
|
541
652
|
default:
|
|
542
|
-
return
|
|
653
|
+
return [];
|
|
543
654
|
}
|
|
544
655
|
}
|
|
545
656
|
|
|
@@ -552,12 +663,19 @@ function gpuProbeSpec(p = platform()) {
|
|
|
552
663
|
* 否则在有显卡的机器上永远绿、在 VM 上永远红(GitHub runner 上就是这么红的)。
|
|
553
664
|
*/
|
|
554
665
|
async function probeGpu() {
|
|
555
|
-
const
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
666
|
+
const specs = gpuProbeSpecs();
|
|
667
|
+
let output = "";
|
|
668
|
+
for (const spec of specs) {
|
|
669
|
+
const r = await runProbe(spec.cmd, spec.args, GPU_TIMEOUT_MS);
|
|
670
|
+
const out = r.output ?? "";
|
|
671
|
+
// 命令没装/超时 → 空输出,换下一条;不要因为"没装 nvidia-smi"就报"没有 GPU"。
|
|
672
|
+
if (!out) continue;
|
|
673
|
+
output = out;
|
|
674
|
+
const gpu = spec.parse(out);
|
|
675
|
+
// 解析出真卡就停;解析不出来继续问下一条更全的命令。
|
|
676
|
+
if (gpu) return { output, gpu };
|
|
677
|
+
}
|
|
678
|
+
return { output, gpu: null };
|
|
561
679
|
}
|
|
562
680
|
|
|
563
681
|
async function collectGpu() {
|
|
@@ -635,9 +753,10 @@ export function setCapabilitiesForTest(value) {
|
|
|
635
753
|
* @param options.hints 额外的"常用目录"(插件传 config.workspaceRoot)
|
|
636
754
|
*/
|
|
637
755
|
export async function collectCapabilities({ now = Date.now(), hints = [] } = {}) {
|
|
638
|
-
const [rt, gpu] = await Promise.all([
|
|
756
|
+
const [rt, gpu, wsl] = await Promise.all([
|
|
639
757
|
collectRuntimes().catch(() => ({ runtimes: {}, errors: { _: "collect-threw" } })),
|
|
640
758
|
collectGpu().catch(() => null),
|
|
759
|
+
collectWslRuntimes().catch(() => []),
|
|
641
760
|
]);
|
|
642
761
|
// 三种触发(对端 hos 逼出来的完整版):
|
|
643
762
|
// ① 探测本身没给出结论(超时 / spawn 失败 / 抛异常)
|
|
@@ -667,6 +786,9 @@ export async function collectCapabilities({ now = Date.now(), hints = [] } = {})
|
|
|
667
786
|
// 只看 `runtimes` 的投影时,"3 项没探到"和"8 项全没探到"长得一样。
|
|
668
787
|
probeFailCount: probeFailCount(rt),
|
|
669
788
|
gpu,
|
|
789
|
+
// WSL 发行版里的运行时(只探运行中的);一台 Windows 机器上"装了 Python"
|
|
790
|
+
// 可能指宿主机,也可能指 WSL 里 —— 分开报才不会被当成同一件事。
|
|
791
|
+
...(wsl.length > 0 ? { wsl } : {}),
|
|
670
792
|
workspaceHints: collectWorkspaceHints(hints),
|
|
671
793
|
capabilitiesAt: now,
|
|
672
794
|
};
|
|
@@ -781,6 +903,32 @@ export function sanitizeCapabilities(raw) {
|
|
|
781
903
|
if (name) gpu = { present: raw.gpu.present !== false, name, vramMb: safeNum(raw.gpu.vramMb, 1 << 20) };
|
|
782
904
|
}
|
|
783
905
|
|
|
906
|
+
const wsl = [];
|
|
907
|
+
if (Array.isArray(raw.wsl)) {
|
|
908
|
+
for (const item of raw.wsl.slice(0, 8)) {
|
|
909
|
+
if (!item || typeof item !== "object" || Array.isArray(item)) continue;
|
|
910
|
+
const name = safeStr(item.name, 32);
|
|
911
|
+
if (!name) continue;
|
|
912
|
+
const wslRuntimes = {};
|
|
913
|
+
let wslCount = 0;
|
|
914
|
+
const rawWslRuntimes =
|
|
915
|
+
item.runtimes && typeof item.runtimes === "object" && !Array.isArray(item.runtimes)
|
|
916
|
+
? item.runtimes
|
|
917
|
+
: {};
|
|
918
|
+
for (const [k, v] of Object.entries(rawWslRuntimes)) {
|
|
919
|
+
if (wslCount >= 12) break;
|
|
920
|
+
const rtName = safeStr(k, 24).toLowerCase();
|
|
921
|
+
const rtVersion = safeStr(v, 16).replace(/[^0-9.]/g, "");
|
|
922
|
+
if (rtName && rtVersion) {
|
|
923
|
+
wslRuntimes[rtName] = rtVersion;
|
|
924
|
+
wslCount += 1;
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
wsl.push({ name, runtimes: wslRuntimes, error: safeStr(item.error, 80) });
|
|
928
|
+
if (wsl.length >= 2) break;
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
|
|
784
932
|
const hints = Array.isArray(raw.workspaceHints)
|
|
785
933
|
? raw.workspaceHints.slice(0, 8).map((h) => safeStr(h, 40)).filter(Boolean)
|
|
786
934
|
: [];
|
|
@@ -798,6 +946,8 @@ export function sanitizeCapabilities(raw) {
|
|
|
798
946
|
// "8 项全没探到"是两回事)。旧对端没有这个字段 → 0(当作"没失败")。
|
|
799
947
|
probeFailCount: safeNum(raw.probeFailCount, 64),
|
|
800
948
|
gpu,
|
|
949
|
+
// 对端报来的 WSL 运行时同样要清洗:名字截断、版本只留数字和点、最多两个发行版。
|
|
950
|
+
...(wsl.length > 0 ? { wsl } : {}),
|
|
801
951
|
workspaceHints: hints,
|
|
802
952
|
// 时间戳不能用 safeNum 的"非法即 0"——0 会让 capabilityAge 变成
|
|
803
953
|
// "1970 年采的",也就是永远过期。非法就置 0 并在下面按"未知"处理。
|
|
@@ -843,6 +993,12 @@ export function describePeerCapabilities(peer) {
|
|
|
843
993
|
` 能力${marks.length ? `(${marks.join(";")})` : ""}:${specs.join(" / ") || "规格未知"}`,
|
|
844
994
|
` 运行时:${summarizeCapabilities(caps) || "(未探到)"}`,
|
|
845
995
|
];
|
|
996
|
+
for (const w of caps.wsl ?? []) {
|
|
997
|
+
const detail = Object.entries(w.runtimes ?? {})
|
|
998
|
+
.map(([name, ver]) => `${name} ${ver}`)
|
|
999
|
+
.join("、");
|
|
1000
|
+
lines.push(` WSL ${w.name}:${detail || "(未探到)"}`);
|
|
1001
|
+
}
|
|
846
1002
|
if (caps.workspaceHints?.length) lines.push(` 常用目录:${caps.workspaceHints.join(" ")}`);
|
|
847
1003
|
if (caps.capabilitiesAt) {
|
|
848
1004
|
lines.push(` 采集于 ${new Date(caps.capabilitiesAt).toISOString().slice(0, 16).replace("T", " ")} UTC`);
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 诊断信息(纯函数 + 两个小 IO 辅助)。
|
|
3
|
+
*
|
|
4
|
+
* 移植自 PR #17,只保留「诊断」这半:任务记录详情主干已有,不再重复。
|
|
5
|
+
*
|
|
6
|
+
* 为什么需要它:这个项目反复在“进程版本 ≠ 磁盘版本”上误诊 —— 重启日志、
|
|
7
|
+
* state.json、磁盘 package.json 都不能证明**当前进程加载的是哪份代码**。
|
|
8
|
+
* 诊断块把三件事摆在一起:
|
|
9
|
+
* · 进程自述版本(VERSION 常量,来自已加载的代码)
|
|
10
|
+
* · 磁盘 package.json 的版本
|
|
11
|
+
* · 入口文件 mtime 与进程启动时间的先后
|
|
12
|
+
*
|
|
13
|
+
* 输出只包含排障必需的信息,**不含** secret / tsnetAuthKey。
|
|
14
|
+
*/
|
|
15
|
+
import { readFileSync, statSync } from "node:fs";
|
|
16
|
+
import { fileURLToPath } from "node:url";
|
|
17
|
+
|
|
18
|
+
/** 读入口同级 package.json 的版本;失败返回空串。 */
|
|
19
|
+
export function readPackageVersion(entryUrl) {
|
|
20
|
+
try {
|
|
21
|
+
const pkg = new URL("../package.json", entryUrl);
|
|
22
|
+
const raw = JSON.parse(readFileSync(pkg, "utf8"));
|
|
23
|
+
return typeof raw?.version === "string" ? raw.version : "";
|
|
24
|
+
} catch {
|
|
25
|
+
return "";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** 入口文件的真实路径与 mtime;失败返回空。 */
|
|
30
|
+
export function entryInfo(entryUrl) {
|
|
31
|
+
try {
|
|
32
|
+
const path = fileURLToPath(entryUrl);
|
|
33
|
+
const stat = statSync(path);
|
|
34
|
+
return { path, mtimeMs: stat.mtimeMs };
|
|
35
|
+
} catch {
|
|
36
|
+
return { path: "", mtimeMs: 0 };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 组装诊断块。所有输入显式传入,方便单测;不做任何探测。
|
|
42
|
+
*
|
|
43
|
+
* @param config 插件配置(只挑安全字段输出,绝不回传 secret / tsnetAuthKey)
|
|
44
|
+
*/
|
|
45
|
+
export function buildDiagnostics({
|
|
46
|
+
version = "",
|
|
47
|
+
packageVersion = "",
|
|
48
|
+
entry = "",
|
|
49
|
+
entryMtimeMs = 0,
|
|
50
|
+
startedAt = Date.now(),
|
|
51
|
+
now = Date.now(),
|
|
52
|
+
pid = process.pid,
|
|
53
|
+
node = process.version,
|
|
54
|
+
platform = process.platform,
|
|
55
|
+
arch = process.arch,
|
|
56
|
+
hostname = "",
|
|
57
|
+
machine = "",
|
|
58
|
+
config = {},
|
|
59
|
+
capabilities = null,
|
|
60
|
+
} = {}) {
|
|
61
|
+
const safeConfig = {};
|
|
62
|
+
for (const key of [
|
|
63
|
+
"port",
|
|
64
|
+
"useMulticast",
|
|
65
|
+
"scanOnStart",
|
|
66
|
+
"scanIntervalMs",
|
|
67
|
+
"pingIntervalMs",
|
|
68
|
+
"requirePairing",
|
|
69
|
+
"agentPreset",
|
|
70
|
+
"permissionPreset",
|
|
71
|
+
"workspaceRoot",
|
|
72
|
+
"tsnetEnabled",
|
|
73
|
+
]) {
|
|
74
|
+
if (config?.[key] !== undefined) safeConfig[key] = config[key];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
ok: true,
|
|
79
|
+
app: "dsh-mesh",
|
|
80
|
+
version: String(version ?? ""),
|
|
81
|
+
packageVersion: String(packageVersion ?? ""),
|
|
82
|
+
// 进程自述版本 vs 磁盘 package.json
|
|
83
|
+
versionMatches: !!version && String(version) === String(packageVersion),
|
|
84
|
+
// 入口文件比进程启动还新 → 磁盘换了代码但没重启
|
|
85
|
+
diskNewerThanProcess: entryMtimeMs > 0 && entryMtimeMs > startedAt,
|
|
86
|
+
startedAt: new Date(startedAt).toISOString(),
|
|
87
|
+
uptimeMs: Math.max(0, Number(now) - Number(startedAt)),
|
|
88
|
+
pid,
|
|
89
|
+
node,
|
|
90
|
+
platform,
|
|
91
|
+
arch,
|
|
92
|
+
hostname: String(hostname ?? ""),
|
|
93
|
+
machine: String(machine ?? ""),
|
|
94
|
+
entry: String(entry ?? ""),
|
|
95
|
+
entryMtime: entryMtimeMs > 0 ? new Date(entryMtimeMs).toISOString() : "",
|
|
96
|
+
config: safeConfig,
|
|
97
|
+
capabilities: capabilities
|
|
98
|
+
? {
|
|
99
|
+
at: Number(capabilities.capabilitiesAt) || 0,
|
|
100
|
+
runtimesIncomplete: capabilities.runtimesIncomplete === true,
|
|
101
|
+
probeFailCount: Number(capabilities.probeFailCount) || 0,
|
|
102
|
+
gpu: String(capabilities.gpu?.name ?? ""),
|
|
103
|
+
wsl: Array.isArray(capabilities.wsl)
|
|
104
|
+
? capabilities.wsl.map((w) => String(w?.name ?? "")).filter(Boolean)
|
|
105
|
+
: [],
|
|
106
|
+
}
|
|
107
|
+
: null,
|
|
108
|
+
};
|
|
109
|
+
}
|
package/lib/discovery.js
CHANGED
|
@@ -17,6 +17,7 @@ import dgram from "node:dgram";
|
|
|
17
17
|
import { EventEmitter } from "node:events";
|
|
18
18
|
import os from "node:os";
|
|
19
19
|
import { sanitizeCapabilities, isCapabilityStale, summarizeCapabilities, currentCapabilities } from "./capabilities.js";
|
|
20
|
+
import { osInfo, sanitizeOsInfo, systems, sanitizeSystems } from "./osinfo.js";
|
|
20
21
|
|
|
21
22
|
export const MESH_GROUP = "239.255.42.99";
|
|
22
23
|
export const MESH_PORT = 45892;
|
|
@@ -305,6 +306,11 @@ export class MeshDiscovery extends EventEmitter {
|
|
|
305
306
|
host: this.#address,
|
|
306
307
|
port: this.#port,
|
|
307
308
|
os: `${os.platform()} ${os.release()}`,
|
|
309
|
+
// 结构化系统身份(平台/系统名/版本/发行版/内核/桌面/架构)。
|
|
310
|
+
// 老对端没有这两个字段;UI 会回退解析 os 字符串,所以是纯增量协议。
|
|
311
|
+
osInfo: osInfo(),
|
|
312
|
+
// 这台机器上可用的系统列表(宿主机 + WSL 等);宿主机排第一。
|
|
313
|
+
systems: systems(),
|
|
308
314
|
user: this.#meta.user ?? os.userInfo().username,
|
|
309
315
|
profile: this.#meta.profile ?? "",
|
|
310
316
|
version: this.#meta.version ?? "",
|
|
@@ -594,6 +600,8 @@ export class MeshDiscovery extends EventEmitter {
|
|
|
594
600
|
hostname: String(msg.hostname ?? ""),
|
|
595
601
|
mac: String(msg.mac ?? ""),
|
|
596
602
|
os: String(msg.os ?? ""),
|
|
603
|
+
osInfo: sanitizeOsInfo(msg.osInfo),
|
|
604
|
+
systems: sanitizeSystems(msg.systems),
|
|
597
605
|
user: String(msg.user ?? ""),
|
|
598
606
|
profile: String(msg.profile ?? ""),
|
|
599
607
|
version: String(msg.version ?? ""),
|
|
@@ -722,6 +730,9 @@ export class MeshDiscovery extends EventEmitter {
|
|
|
722
730
|
hostname: "",
|
|
723
731
|
mac: "",
|
|
724
732
|
os: "",
|
|
733
|
+
// 结构化系统身份;老对端只报 os 字符串时为 null。
|
|
734
|
+
osInfo: null,
|
|
735
|
+
systems: null,
|
|
725
736
|
user: "",
|
|
726
737
|
profile: "",
|
|
727
738
|
version: "",
|
|
@@ -738,6 +749,12 @@ export class MeshDiscovery extends EventEmitter {
|
|
|
738
749
|
peer.hostname = String(msg.hostname ?? peer.hostname ?? "");
|
|
739
750
|
peer.mac = String(msg.mac ?? peer.mac ?? "");
|
|
740
751
|
peer.os = String(msg.os ?? peer.os ?? "");
|
|
752
|
+
// 系统身份是**网络输入**:清洗后再存。没报/报坏了就保持原值,让 UI 回退到
|
|
753
|
+
// 老的 os 字符串,而不是伪造一个空系统。
|
|
754
|
+
const incomingOs = sanitizeOsInfo(msg.osInfo);
|
|
755
|
+
if (incomingOs) peer.osInfo = incomingOs;
|
|
756
|
+
const incomingSystems = sanitizeSystems(msg.systems);
|
|
757
|
+
if (incomingSystems) peer.systems = incomingSystems;
|
|
741
758
|
peer.user = String(msg.user ?? peer.user ?? "");
|
|
742
759
|
peer.profile = String(msg.profile ?? peer.profile ?? "");
|
|
743
760
|
peer.version = String(msg.version ?? peer.version ?? "");
|