dsh-plugin-mesh 0.5.0 → 0.5.2
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 +1 -1
- package/README.md +7 -7
- package/client/client.js +6410 -893
- package/cordis.patch.yml +3 -2
- package/lib/_rehearsal-peer.mjs +2 -1
- package/lib/_selftest-capabilities.mjs +28 -2
- package/lib/_selftest-client.mjs +6 -389
- package/lib/_selftest-layout.mjs +112 -0
- package/lib/_selftest-prompt.mjs +67 -1
- package/lib/_selftest-reply-route.mjs +12 -1
- package/lib/_selftest-tsnet.mjs +26 -1
- package/lib/_selftest-workbench.mjs +728 -0
- package/lib/capabilities.js +16 -4
- package/lib/discovery.js +43 -6
- package/lib/index.js +302 -49
- package/lib/layout.js +128 -0
- package/lib/persist.js +4 -0
- package/lib/prompt.js +25 -7
- package/lib/scan.js +11 -10
- package/lib/tsnet/download.js +5 -1
- package/package.json +4 -3
- package/scripts/_selftest-release-plan.mjs +33 -2
- package/scripts/release-plan.mjs +19 -1
package/lib/capabilities.js
CHANGED
|
@@ -104,7 +104,8 @@ function extraPathDirs(p = platform(), env = process.env) {
|
|
|
104
104
|
env["ProgramFiles(x86)"] && join(env["ProgramFiles(x86)"], "nodejs"),
|
|
105
105
|
env.APPDATA && join(env.APPDATA, "npm"),
|
|
106
106
|
env.LOCALAPPDATA && join(env.LOCALAPPDATA, "Programs", "Python"),
|
|
107
|
-
|
|
107
|
+
// 不要把 WindowsApps 补进探测 PATH:那里几乎全是 0 字节的 Store 别名存根,
|
|
108
|
+
// 前置后会遮住后面真正的 python.exe / node.exe(spawn 得 exit 9009)。
|
|
108
109
|
env.ProgramFiles && join(env.ProgramFiles, "Git", "cmd"),
|
|
109
110
|
env.ProgramFiles && join(env.ProgramFiles, "Docker", "Docker", "resources", "bin"),
|
|
110
111
|
env.ProgramData && join(env.ProgramData, "chocolatey", "bin"),
|
|
@@ -263,7 +264,14 @@ async function probeRuntime(spec, timeoutMs = PROBE_TIMEOUT_MS) {
|
|
|
263
264
|
* 是**不确定** —— 不能当作"没装"。
|
|
264
265
|
*/
|
|
265
266
|
function isUncertain(error) {
|
|
266
|
-
return
|
|
267
|
+
return (
|
|
268
|
+
error === "timeout" ||
|
|
269
|
+
error === "spawn-failed" ||
|
|
270
|
+
// Windows Store 别名存根:文件 0 字节,spawn 得到 exit 9009、无输出。
|
|
271
|
+
// 这是“没问出答案”,不是“确定没装”。
|
|
272
|
+
error === "exit-9009" ||
|
|
273
|
+
String(error).startsWith("throw:")
|
|
274
|
+
);
|
|
267
275
|
}
|
|
268
276
|
|
|
269
277
|
/**
|
|
@@ -391,8 +399,11 @@ function isEmptyButFailed({ runtimes, errors } = {}) {
|
|
|
391
399
|
* WindowsApps 算进去,Windows 上会**恒判"可信"** → 假阴性原样复发 —— 实测
|
|
392
400
|
* 文超-win 的候选表去掉 WindowsApps 后恰好为 0,带上它则为 1。
|
|
393
401
|
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
402
|
+
* 注意范围:这个正则本身只用于**健康判据**;探测用的 PATH 里也**不再**补
|
|
403
|
+
* WindowsApps(见 extraPathDirs)。原先这里写着"留着无害",是错的:把它前置到
|
|
404
|
+
* PATH 会挡住真正的 python.exe / node.exe,spawn 得到 exit=9009 + 空输出,
|
|
405
|
+
* 于是"装了"被当成"没装"。现在这种输出记为**不确定**(见 isUncertain),
|
|
406
|
+
* 而不是当作反向证据。
|
|
396
407
|
*/
|
|
397
408
|
const STORE_ALIAS_DIR = /[\\/]Microsoft[\\/]WindowsApps$/i;
|
|
398
409
|
|
|
@@ -419,6 +430,7 @@ export const __pathLookupUnreliable = pathLookupUnreliable;
|
|
|
419
430
|
export const __normPathForCompare = normPathForCompare;
|
|
420
431
|
/** 只为自测导出:原始 GPU 探测输出 —— 用来区分"这台机器没有显卡"和"解析器坏了"。 */
|
|
421
432
|
export const __probeGpu = probeGpu;
|
|
433
|
+
export const __isUncertain = isUncertain;
|
|
422
434
|
/** 只为自测导出:Store 别名目录的排除规则(Mac 上没有该目录,无法端到端复现)。 */
|
|
423
435
|
export const __storeAliasDir = STORE_ALIAS_DIR;
|
|
424
436
|
/** 只为自测导出:让自测能按判据反推 runtimesIncomplete 的期望值,而不是写死。 */
|
package/lib/discovery.js
CHANGED
|
@@ -22,6 +22,35 @@ export const MESH_GROUP = "239.255.42.99";
|
|
|
22
22
|
export const MESH_PORT = 45892;
|
|
23
23
|
export const APP_TAG = "dsh-mesh";
|
|
24
24
|
|
|
25
|
+
/** 带横线的 UUID 形态:opencode-mesh 冒名时用的 id 形状,dsh-mesh 自己从不产出。 */
|
|
26
|
+
const UUID_ID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 这份自述记录*是不是*一个 dsh-mesh 对端。
|
|
30
|
+
*
|
|
31
|
+
* 为什么需要它:`app: "dsh-mesh"` 只是对方自报的一个字符串,不构成身份证明。
|
|
32
|
+
* 2026-10-21 实测到一台装在同机的 OpenCode.app 在 45918 上照抄了
|
|
33
|
+
* `/mesh/v1/health` 的形状,自报 `app: "dsh-mesh"`、`proto: "opencode-mesh"`、
|
|
34
|
+
* `version: "0.1.0"`、id 是带横线的 UUID、没有 capabilities —— 旧准入只查
|
|
35
|
+
* `app` 和 `id`,于是它被当成正经对端收进注册表,还进了快照。
|
|
36
|
+
*
|
|
37
|
+
* 三条判据都取「字段存在才校验」的宽容写法:`v` / `proto` 只有 live 记录里有
|
|
38
|
+
* (persist.js 的快照不存这两个字段),硬要求它们会把 restore 路径整条打死。
|
|
39
|
+
* 真正兜底的是 id 形态 —— `resolveInstanceId()` 用同一个正则校验自己,
|
|
40
|
+
* 所以同血统的对端不可能产出非 16 位十六进制的 id。
|
|
41
|
+
*/
|
|
42
|
+
export function looksLikeDshPeer(record) {
|
|
43
|
+
if (!record || record.app !== APP_TAG || !record.id) return false;
|
|
44
|
+
if (record.v !== undefined && record.v !== 2) return false;
|
|
45
|
+
if (record.proto !== undefined && record.proto !== "dsh-mesh") return false;
|
|
46
|
+
// 已经落盘的老快照里没有 v/proto(见 persist.js 的字段表),那条路径上只剩
|
|
47
|
+
// id 形态可判:dsh-mesh 自己用 randomBytes(8).toString("hex") 生成 id,
|
|
48
|
+
// 同血统的对端不可能产出带横线的 UUID。这里刻意只挡 UUID 形态,而不要求
|
|
49
|
+
// "必须是 16 位十六进制" —— 后者会误伤测试夹具和用户手填的旧 id。
|
|
50
|
+
if (UUID_ID_RE.test(String(record.id))) return false;
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
|
|
25
54
|
/** 「上次见过」缓存的保留期与条数上限:地址用不了那么久,也不该无限长。 */
|
|
26
55
|
const KNOWN_TTL_MS = 30 * 24 * 3600 * 1000;
|
|
27
56
|
const KNOWN_MAX = 200;
|
|
@@ -513,7 +542,7 @@ export class MeshDiscovery extends EventEmitter {
|
|
|
513
542
|
* @returns 是否造成可见变化
|
|
514
543
|
*/
|
|
515
544
|
note(record, sourceAddress, meta = {}) {
|
|
516
|
-
if (!record || record.
|
|
545
|
+
if (!looksLikeDshPeer(record) || record.id === this.#id) return false;
|
|
517
546
|
return this.#upsert(record, { address: sourceAddress ?? record.host ?? "?", ...meta });
|
|
518
547
|
}
|
|
519
548
|
|
|
@@ -535,7 +564,8 @@ export class MeshDiscovery extends EventEmitter {
|
|
|
535
564
|
const cutoff = now - KNOWN_TTL_MS;
|
|
536
565
|
for (const item of snapshot ?? []) {
|
|
537
566
|
const msg = item?.record;
|
|
538
|
-
|
|
567
|
+
// 快照同样要过准入:幽灵 peer 一旦落盘,会以离线行的形态躺满 KNOWN_TTL_MS。
|
|
568
|
+
if (!looksLikeDshPeer(msg) || msg.id === this.#id) continue;
|
|
539
569
|
const peerId = String(msg.id);
|
|
540
570
|
// 现网已经发现的,以现网为准,不写缓存
|
|
541
571
|
if (this.#peers.has(peerId)) continue;
|
|
@@ -594,7 +624,7 @@ export class MeshDiscovery extends EventEmitter {
|
|
|
594
624
|
* (verified=false),局域网一断就能直接拿去探,不必重新发现。
|
|
595
625
|
*/
|
|
596
626
|
noteTailnetCandidate(record, address, port) {
|
|
597
|
-
if (!record || record.
|
|
627
|
+
if (!looksLikeDshPeer(record) || record.id === this.#id) return false;
|
|
598
628
|
return this.#upsert(record, { address, transport: "tsnet", port, probe: false });
|
|
599
629
|
}
|
|
600
630
|
|
|
@@ -678,7 +708,11 @@ export class MeshDiscovery extends EventEmitter {
|
|
|
678
708
|
const address = String(rinfo.address ?? selfHost ?? "?").trim();
|
|
679
709
|
// tailnet 通道**必须**用观察到的地址:对端自述的 host 是它的局域网 IP,
|
|
680
710
|
// 跨互联网根本不可达。
|
|
681
|
-
|
|
711
|
+
// Prefer the observed source address on every transport. The peer's
|
|
712
|
+
// self-reported host/port is unauthenticated; trusting it on the LAN lets a
|
|
713
|
+
// spoofed heartbeat redirect task dispatch (and X-Dsh-Mesh-Token) to an
|
|
714
|
+
// arbitrary host. note()'s contract has always said observed wins.
|
|
715
|
+
const host = address || selfHost;
|
|
682
716
|
const port = Number(rinfo.port ?? msg.port) || 0;
|
|
683
717
|
const verified = rinfo.probe === false ? false : true;
|
|
684
718
|
|
|
@@ -758,12 +792,15 @@ export class MeshDiscovery extends EventEmitter {
|
|
|
758
792
|
lastOkAt: verified ? now : (prevEp?.lastOkAt ?? 0),
|
|
759
793
|
lastFailAt: prevEp?.lastFailAt ?? 0,
|
|
760
794
|
okCount: verified ? (prevEp?.okCount ?? 0) + 1 : (prevEp?.okCount ?? 0),
|
|
761
|
-
|
|
795
|
+
// An inbound heartbeat proves the peer can reach us, not that we can
|
|
796
|
+
// reach it. Keep the outbound failure state; only a successful probe or
|
|
797
|
+
// send (markEndpoint ok) may clear it.
|
|
798
|
+
failCount: prevEp?.failCount ?? 0,
|
|
762
799
|
// RTT 与探测间隔由调用方按实际结果带进来(成功路径走的是 note(),
|
|
763
800
|
// 不是 markEndpoint,所以要在这里一并接住,否则 RTT 永远是 0)
|
|
764
801
|
rttMs: Number(rinfo.rttMs) > 0 ? Number(rinfo.rttMs) : (prevEp?.rttMs ?? 0),
|
|
765
802
|
probeIntervalMs: Number(rinfo.probeIntervalMs) > 0 ? Number(rinfo.probeIntervalMs) : (prevEp?.probeIntervalMs ?? 0),
|
|
766
|
-
downUntil: 0,
|
|
803
|
+
downUntil: prevEp?.downUntil ?? 0,
|
|
767
804
|
verified: prevEp?.verified === true || verified,
|
|
768
805
|
};
|
|
769
806
|
|