dsh-plugin-mesh 0.5.2 → 0.5.4

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.
@@ -1,10 +1,17 @@
1
1
  /**
2
- * tsnet sidecar 的进程管理(机器级单实例)。
2
+ * tsnet sidecar 的进程管理(机器级,每个 tailnet 通道一个节点)。
3
3
  *
4
4
  * 为什么是「机器级」而不是「profile 级」:
5
5
  * 每个 sidecar 就是 tailnet 里的一个设备,会占用一个设备名额。同一台机器上
6
- * 跑 desktop / meshtest 两个 profile 不应该变成两台设备,所以整机只跑一个
7
- * sidecar,由第一个用到的实例拉起,后来的实例通过 rendezvous 文件复用。
6
+ * 跑 desktop / meshtest 两个 profile 不应该变成两台设备,所以整机每个通道只跑
7
+ * 一个 sidecar,由第一个用到的实例拉起,后来的实例通过 rendezvous 文件复用。
8
+ *
9
+ * 为什么是「多个通道」:
10
+ * 一台机器可能同时属于多个 tailnet(个人账号 / 公司 tailnet / 自建 Headscale)。
11
+ * 一个 tsnet 节点只能加入一个 tailnet,所以每条通道各有自己的 sidecar、状态目录
12
+ * 和 rendezvous。通道 id 是稳定标识:`default` 沿用旧目录,升级不丢设备身份;
13
+ * 其它通道各占 `tsnet/<id>/`。**设备身份仍然只有一个** —— 多条通道只是同一个
14
+ * mesh 节点的多条可达路径。
8
15
  *
9
16
  * 生命周期:
10
17
  * · sidecar 监听 stdin EOF 自杀 —— 即使 DSH 被 kill -9,也不会留下野进程
@@ -13,12 +20,12 @@
13
20
  */
14
21
  import { EventEmitter } from "node:events";
15
22
  import { spawn } from "node:child_process";
16
- import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
23
+ import { mkdirSync, readFileSync, renameSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
17
24
  import { request as httpRequest } from "node:http";
18
25
  import { createHash, randomBytes } from "node:crypto";
19
26
  import { join } from "node:path";
20
27
  import { homedir } from "node:os";
21
- import { SIDECAR_PROTOCOL, binaryPath, ensureBinary, cacheIsCurrent, binaryInfo, clearBinary, looksExecutable } from "./download.js";
28
+ import { SIDECAR_PROTOCOL, binaryPath, ensureBinary, cacheIsCurrent, binaryInfo, clearBinary } from "./download.js";
22
29
 
23
30
  /** 重启退避(毫秒);用完就停手,避免疯狂重启把日志刷爆。 */
24
31
  const RESTART_BACKOFF_MS = [2000, 8000, 20000];
@@ -33,22 +40,56 @@ function meshDir() {
33
40
  }
34
41
 
35
42
  /** 机器级共享目录:sidecar 状态、rendezvous、二进制缓存都挂在这下面。 */
36
- function nodeDir() {
43
+ export function tsnetRootDir() {
37
44
  return join(meshDir(), "tsnet");
38
45
  }
39
46
 
40
- function rendezvousPath() {
41
- return join(nodeDir(), "rendezvous.json");
47
+ /**
48
+ * 通道 id 的合法化:只保留 [a-z0-9_-]。
49
+ *
50
+ * 通道 id 会进文件路径,所以这里必须挡掉 `/`、`..` 之类;空值兜底成
51
+ * `default`,正好与旧版本的单节点目录对应。
52
+ */
53
+ export function channelKey(raw, fallback = "default") {
54
+ const s = String(raw ?? "")
55
+ .trim()
56
+ .toLowerCase()
57
+ .replace(/[^a-z0-9_-]+/g, "-")
58
+ .replace(/^-+|-+$/g, "")
59
+ .slice(0, 40);
60
+ return s || fallback;
61
+ }
62
+
63
+ /**
64
+ * 通道的私有目录。
65
+ *
66
+ * `default` 沿用旧布局(`mesh/tsnet/` 根目录),这样升级前注册过的那台设备
67
+ * 身份不丢;其它通道各自一个子目录 —— 每个 sidecar 是一个独立 tailnet 节点,
68
+ * 状态目录绝不能共享,否则第二个节点会顶掉第一个的身份。
69
+ */
70
+ export function channelDir(key) {
71
+ const k = channelKey(key);
72
+ return k === "default" ? tsnetRootDir() : join(tsnetRootDir(), k);
73
+ }
74
+
75
+ function rendezvousPath(key) {
76
+ return join(channelDir(key), "rendezvous.json");
42
77
  }
43
78
 
44
79
  /** tsnet 的节点身份目录 —— 必须持久,否则每次重启都会注册成新设备。 */
45
- function stateDir() {
46
- return join(nodeDir(), "state");
80
+ export function channelStateDir(key) {
81
+ return join(channelDir(key), "state");
47
82
  }
48
83
 
49
- function readRendezvous() {
84
+ /** 授权码指纹:只用来判断"rendezvous 里的节点是不是用同一把 key 拉起的"。 */
85
+ function authKeyTag(authKey) {
86
+ const s = String(authKey ?? "").trim();
87
+ return s ? createHash("sha256").update(s).digest("hex").slice(0, 12) : "";
88
+ }
89
+
90
+ function readRendezvous(key) {
50
91
  try {
51
- const raw = JSON.parse(readFileSync(rendezvousPath(), "utf8"));
92
+ const raw = JSON.parse(readFileSync(rendezvousPath(key), "utf8"));
52
93
  if (raw && typeof raw.port === "number" && typeof raw.pid === "number") return raw;
53
94
  } catch {
54
95
  /* 没有或坏了,当作没有 */
@@ -56,16 +97,18 @@ function readRendezvous() {
56
97
  return null;
57
98
  }
58
99
 
59
- function writeRendezvous(info) {
60
- mkdirSync(nodeDir(), { recursive: true });
61
- const tmp = `${rendezvousPath()}.tmp`;
100
+ function writeRendezvous(key, info) {
101
+ const dir = channelDir(key);
102
+ mkdirSync(dir, { recursive: true });
103
+ const target = rendezvousPath(key);
104
+ const tmp = `${target}.tmp`;
62
105
  writeFileSync(tmp, JSON.stringify(info, null, 2), { mode: 0o600 });
63
- renameSync(tmp, rendezvousPath());
106
+ renameSync(tmp, target);
64
107
  }
65
108
 
66
- function clearRendezvous() {
109
+ function clearRendezvous(key) {
67
110
  try {
68
- unlinkSync(rendezvousPath());
111
+ unlinkSync(rendezvousPath(key));
69
112
  } catch {
70
113
  /* 本来就没有 */
71
114
  }
@@ -101,11 +144,33 @@ export function toHostname(raw) {
101
144
  return name;
102
145
  }
103
146
 
147
+ /**
148
+ * 连接参数指纹:授权码 / 控制服务器 / 节点名。
149
+ *
150
+ * 上层用它判断"配置变了没有":没变就复用活着的节点,变了才重建 sidecar。
151
+ * 只输出哈希,不泄露授权码明文。
152
+ */
153
+ export function channelSignature(channel = {}) {
154
+ return createHash("sha256")
155
+ .update(
156
+ JSON.stringify([
157
+ String(channel.authKey ?? "").trim(),
158
+ String(channel.controlUrl ?? "").trim(),
159
+ String(channel.hostname ?? "").trim(),
160
+ ]),
161
+ )
162
+ .digest("hex")
163
+ .slice(0, 12);
164
+ }
165
+
104
166
  /**
105
167
  * 一个 tsnet 节点的句柄。可以自己拉起 sidecar,也可以复用它人已拉起的。
106
168
  */
107
169
  export class TsnetNode extends EventEmitter {
108
- #config;
170
+ #channel;
171
+ #key;
172
+ #label;
173
+ #signature;
109
174
  #log;
110
175
  #warn;
111
176
  #child = null;
@@ -121,20 +186,64 @@ export class TsnetNode extends EventEmitter {
121
186
  #forwards = new Set();
122
187
  #hostname;
123
188
 
124
- constructor({ config, log = () => {}, warn = () => {}, machineName = "" }) {
189
+ /**
190
+ * @param channel 通道描述:{ id, label, authKey, controlUrl, hostname, downloadSources }
191
+ * 也兼容旧调用方式(直接传 config,单通道 = default)。
192
+ */
193
+ constructor({ config = {}, channel = null, log = () => {}, warn = () => {}, machineName = "" }) {
125
194
  super();
126
- this.#config = config;
127
195
  this.#log = log;
128
196
  this.#warn = warn;
129
- // 机器级节点名:整机一个,不带 profile 后缀。
130
- this.#hostname = toHostname(config.tsnetHostname || machineName || "dsh-node");
197
+ const ch = channel ?? {
198
+ id: "default",
199
+ label: "Tailscale",
200
+ authKey: config.tsnetAuthKey ?? "",
201
+ controlUrl: config.tsnetControlUrl ?? "",
202
+ hostname: config.tsnetHostname ?? "",
203
+ };
204
+ this.#key = channelKey(ch.id);
205
+ this.#label = String(ch.label ?? "").trim() || this.#key;
206
+ this.#channel = {
207
+ id: this.#key,
208
+ label: this.#label,
209
+ authKey: String(ch.authKey ?? "").trim(),
210
+ controlUrl: String(ch.controlUrl ?? "").trim(),
211
+ hostname: String(ch.hostname ?? "").trim(),
212
+ downloadSources: Array.isArray(ch.downloadSources) ? ch.downloadSources : (config.tsnetDownloadSources ?? []),
213
+ };
214
+ // 机器级节点名:整机一个,不带 profile 后缀。多通道同一台机器在不同 tailnet
215
+ // 里可以同名(互不相干);同一 tailnet 里挂两条通道才会撞名,由用户显式命名。
216
+ this.#hostname = toHostname(this.#channel.hostname || machineName || "dsh-node");
131
217
  this.#status.hostname = this.#hostname;
218
+ // 连接参数的指纹:上层用它判断"配置变了没有",没变就复用活着的节点,
219
+ // 不要在用户重试时把等待授权的 sidecar 反复踢掉重来。
220
+ this.#signature = channelSignature(this.#channel);
132
221
  }
133
222
 
134
223
  get hostname() {
135
224
  return this.#hostname;
136
225
  }
137
226
 
227
+ /** 通道 id(稳定,进文件路径与端点 key)。 */
228
+ get channelKey() {
229
+ return this.#key;
230
+ }
231
+
232
+ /** 通道显示名。 */
233
+ get label() {
234
+ return this.#label;
235
+ }
236
+
237
+ /** 连接参数指纹(授权码/控制服务器/节点名)。不含明文授权码。 */
238
+ get signature() {
239
+ return this.#signature;
240
+ }
241
+
242
+ /** 本机在这条 tailnet 上的地址(未连接时为空)。 */
243
+ get selfIpv4() {
244
+ return this.#status.selfIpv4;
245
+ }
246
+
138
247
  get phase() {
139
248
  return this.#status.phase;
140
249
  }
@@ -156,7 +265,16 @@ export class TsnetNode extends EventEmitter {
156
265
  } catch (err) {
157
266
  binary = { installed: false, path: "", size: 0, error: String(err?.message ?? err) };
158
267
  }
159
- return { ...this.#status, protocol: SIDECAR_PROTOCOL, ownsProcess: this.#ownsProcess, port: this.#port, binary };
268
+ return {
269
+ ...this.#status,
270
+ channelKey: this.#key,
271
+ label: this.#label,
272
+ controlUrl: this.#channel.controlUrl,
273
+ protocol: SIDECAR_PROTOCOL,
274
+ ownsProcess: this.#ownsProcess,
275
+ port: this.#port,
276
+ binary,
277
+ };
160
278
  }
161
279
 
162
280
  /** 最近若干条 sidecar 事件,给 UI 做诊断用。 */
@@ -297,21 +415,29 @@ export class TsnetNode extends EventEmitter {
297
415
 
298
416
  /** 尝试接管 rendezvous 里记录的 sidecar;成功返回 true。 */
299
417
  async #tryAdopt() {
300
- const rv = readRendezvous();
418
+ const rv = readRendezvous(this.#key);
301
419
  if (!rv) return false;
302
420
  if (!pidAlive(rv.pid)) {
303
- this.#log(`rendezvous 里的 sidecar(pid ${rv.pid})已不在,清理后重新拉起`);
304
- clearRendezvous();
421
+ this.#log(`[${this.#label}] rendezvous 里的 sidecar(pid ${rv.pid})已不在,清理后重新拉起`);
422
+ clearRendezvous(this.#key);
305
423
  return false;
306
424
  }
307
425
  if (rv.protocol !== SIDECAR_PROTOCOL) {
308
- this.#log(`运行中的 sidecar 协议 v${rv.protocol} 与本插件 v${SIDECAR_PROTOCOL} 不一致,重启它`);
426
+ this.#log(`[${this.#label}] 运行中的 sidecar 协议 v${rv.protocol} 与本插件 v${SIDECAR_PROTOCOL} 不一致,重启它`);
309
427
  await this.#killStale(rv);
310
428
  return false;
311
429
  }
312
430
  if (rv.hostname && rv.hostname !== this.#hostname) {
313
431
  // 机器名改了:旧节点的 MagicDNS 名字已经不对,重启以应用新名字。
314
- this.#log(`sidecar 节点名 ${rv.hostname} 与当前机器名 ${this.#hostname} 不一致,重启它`);
432
+ this.#log(`[${this.#label}] sidecar 节点名 ${rv.hostname} 与当前机器名 ${this.#hostname} 不一致,重启它`);
433
+ await this.#killStale(rv);
434
+ return false;
435
+ }
436
+ // 授权码换了:旧 sidecar 还在旧 tailnet / 旧账号里,必须重建。
437
+ // 兼容没有 authKeyTag 的老 rendezvous:不确定就不动它(宁可沿用,不要无故踢掉)。
438
+ const tag = authKeyTag(this.#channel.authKey);
439
+ if (rv.authKeyTag && tag && rv.authKeyTag !== tag) {
440
+ this.#log(`[${this.#label}] 授权码已变更,重启 sidecar 以加入新的 tailnet`);
315
441
  await this.#killStale(rv);
316
442
  return false;
317
443
  }
@@ -326,13 +452,13 @@ export class TsnetNode extends EventEmitter {
326
452
  this.#rendezvous = rv;
327
453
  this.#ownsProcess = false;
328
454
  this.#setStatus({ pid: rv.pid });
329
- this.#log(`复用已在运行的 sidecar(pid ${rv.pid},端口 ${rv.port})`);
455
+ this.#log(`[${this.#label}] 复用已在运行的 sidecar(pid ${rv.pid},端口 ${rv.port})`);
330
456
  return true;
331
457
  } catch (err) {
332
458
  this.#port = prevPort;
333
459
  this.#token = prevToken;
334
- this.#log(`rendezvous 里的 sidecar 无响应(${err.message}),清理后重新拉起`);
335
- clearRendezvous();
460
+ this.#log(`[${this.#label}] rendezvous 里的 sidecar 无响应(${err.message}),清理后重新拉起`);
461
+ clearRendezvous(this.#key);
336
462
  return false;
337
463
  }
338
464
  }
@@ -344,7 +470,7 @@ export class TsnetNode extends EventEmitter {
344
470
  } catch {
345
471
  /* 已经没了 */
346
472
  }
347
- clearRendezvous();
473
+ clearRendezvous(this.#key);
348
474
  // 等它释放 tailnet 监听,否则紧接着的 bind 会撞端口。
349
475
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
350
476
  const deadline = Date.now() + 4000;
@@ -380,7 +506,7 @@ export class TsnetNode extends EventEmitter {
380
506
  // 命中缓存时它只做一次 stat + 读一个几十字节的标记文件,不联网。
381
507
  if (!cacheIsCurrent()) this.#setStatus({ phase: "downloading", error: "" });
382
508
  const res = await ensureBinary({
383
- extraSources: this.#config.tsnetDownloadSources ?? [],
509
+ extraSources: this.#channel.downloadSources ?? [],
384
510
  log: (m) => {
385
511
  this.#log(m);
386
512
  this.#setStatus({ lastLog: m });
@@ -389,17 +515,21 @@ export class TsnetNode extends EventEmitter {
389
515
  });
390
516
  this.#setStatus({ downloadPercent: 100, binaryPath: res.path });
391
517
 
392
- mkdirSync(stateDir(), { recursive: true });
518
+ const dir = channelStateDir(this.#key);
519
+ mkdirSync(dir, { recursive: true });
393
520
  const token = randomBytes(24).toString("hex");
394
- const args = ["-hostname", this.#hostname, "-dir", stateDir(), "-token", token];
395
- if (this.#config.tsnetControlUrl) args.push("-control-url", String(this.#config.tsnetControlUrl));
521
+ const args = ["-hostname", this.#hostname, "-dir", dir, "-token", token];
522
+ if (this.#channel.controlUrl) args.push("-control-url", this.#channel.controlUrl);
396
523
 
397
- const authKey = String(this.#config.tsnetAuthKey ?? "").trim();
524
+ const authKey = this.#channel.authKey;
398
525
  const env = { ...process.env };
399
526
  if (authKey) env.DSH_TSNET_AUTHKEY = authKey; // 走环境变量:macOS 上 ps 能看到命令行,看不到环境
400
527
  else delete env.DSH_TSNET_AUTHKEY;
401
528
 
402
- this.#log(`拉起 sidecar:${binaryPath()} -hostname ${this.#hostname}${authKey ? " (已带授权码)" : " (无授权码,需交互登录)"}`);
529
+ this.#log(
530
+ `[${this.#label}] 拉起 sidecar:${binaryPath()} -hostname ${this.#hostname}` +
531
+ `${authKey ? " (已带授权码)" : " (无授权码,需交互登录)"}`,
532
+ );
403
533
  const child = spawn(binaryPath(), args, { stdio: ["pipe", "pipe", "pipe"], env, windowsHide: true });
404
534
  this.#child = child;
405
535
  this.#ownsProcess = true;
@@ -436,9 +566,18 @@ export class TsnetNode extends EventEmitter {
436
566
  this.#port = ev.port;
437
567
  // 让上层能直接看到 sidecar 的 pid(诊断和"是否留了孤儿"的判断都要用)
438
568
  this.#setStatus({ pid: ev.pid ?? child.pid ?? 0 });
439
- this.#rendezvous = { pid: child.pid, port: ev.port, token, hostname: this.#hostname, protocol: SIDECAR_PROTOCOL, startedAt: Date.now() };
440
- writeRendezvous(this.#rendezvous);
441
- this.#log(`sidecar 已就绪(pid ${child.pid},控制端口 ${ev.port})`);
569
+ this.#rendezvous = {
570
+ pid: child.pid,
571
+ port: ev.port,
572
+ token,
573
+ hostname: this.#hostname,
574
+ channelKey: this.#key,
575
+ authKeyTag: authKeyTag(authKey),
576
+ protocol: SIDECAR_PROTOCOL,
577
+ startedAt: Date.now(),
578
+ };
579
+ writeRendezvous(this.#key, this.#rendezvous);
580
+ this.#log(`[${this.#label}] sidecar 已就绪(pid ${child.pid},控制端口 ${ev.port})`);
442
581
 
443
582
  child.on("exit", (code, signal) => this.#onExit(code, signal));
444
583
  }
@@ -513,8 +652,8 @@ export class TsnetNode extends EventEmitter {
513
652
  #onExit(code, signal) {
514
653
  if (this.#stopping) return;
515
654
  this.#setStatus({ phase: "exited", backendState: "", error: `sidecar 退出(code=${code} signal=${signal})` });
516
- this.#warn(`sidecar 意外退出(code=${code} signal=${signal})`);
517
- clearRendezvous();
655
+ this.#warn(`[${this.#label}] sidecar 意外退出(code=${code} signal=${signal})`);
656
+ clearRendezvous(this.#key);
518
657
  this.#port = 0;
519
658
  this.#child = null;
520
659
 
@@ -569,7 +708,7 @@ export class TsnetNode extends EventEmitter {
569
708
  if (!this.#ownsProcess && !pidAlive(this.#rendezvous?.pid ?? 0)) {
570
709
  // 复用的 sidecar 消失了:下次扫描时上层会重新 start()。
571
710
  this.#setStatus({ phase: "exited", error: `共享 sidecar 已消失:${err.message}` });
572
- clearRendezvous();
711
+ clearRendezvous(this.#key);
573
712
  this.#port = 0;
574
713
  }
575
714
  }
@@ -581,7 +720,7 @@ export class TsnetNode extends EventEmitter {
581
720
  clearBinary();
582
721
  this.#setStatus({ phase: "idle", error: "" });
583
722
  return ensureBinary({
584
- extraSources: this.#config.tsnetDownloadSources ?? [],
723
+ extraSources: this.#channel.downloadSources ?? [],
585
724
  log: (m) => this.#log(m),
586
725
  onProgress: (p) => this.#setStatus({ downloadPercent: p.percent }),
587
726
  force: true,
@@ -592,7 +731,7 @@ export class TsnetNode extends EventEmitter {
592
731
  async relogin() {
593
732
  await this.stop({ keepRemote: false });
594
733
  try {
595
- rmSync(stateDir(), { recursive: true, force: true });
734
+ rmSync(channelStateDir(this.#key), { recursive: true, force: true });
596
735
  } catch {
597
736
  /* 忽略 */
598
737
  }
@@ -646,7 +785,7 @@ export class TsnetNode extends EventEmitter {
646
785
  resolve();
647
786
  });
648
787
  });
649
- clearRendezvous();
788
+ clearRendezvous(this.#key);
650
789
  this.#port = 0;
651
790
  this.#child = null;
652
791
  }
package/llms.txt CHANGED
@@ -26,8 +26,10 @@ Verify after restart: `GET http://127.0.0.1:45917/mesh/v1/health` returns JSON c
26
26
 
27
27
  - Sends a JSON heartbeat to UDP multicast `239.255.42.99:45892` every `announceIntervalMs` (default 5000 ms) and listens on the same group.
28
28
  - Serves a small HTTP peer API on TCP port 45917 (configurable via `port`).
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.
29
+ - Optionally starts bundled Go sidecars, each running a userspace Tailscale node (tsnet) for one tailnet channel. Multiple channels can run at once: one machine identity, several reachability paths. No TUN device is created, so the host cannot route to `100.x.y.z`; all tailnet traffic is proxied through the matching 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
 
@@ -75,10 +77,11 @@ Override by id in the profile's `cordis.patch.yml`:
75
77
  | `agentPreset` | string | `"standard"` | Agent preset for auto-created sessions |
76
78
  | `permissionPreset` | string | `"workspace-write"` | Permission preset for auto-created sessions |
77
79
  | `workspaceRoot` | string | `""` | |
78
- | `tsnetEnabled` | boolean | `false` | |
79
- | `tsnetAuthKey` | string | `""` | Tailscale auth key; must be reusable |
80
- | `tsnetControlUrl` | string | `""` | |
81
- | `tsnetHostname` | string | `""` | The plugin prefixes `dsh-`; do not include it yourself |
80
+ | `tsnetChannels` | array | `[]` | Multi-tailnet channels: `{id, label, authKey, controlUrl, hostname, enabled}`. A non-empty list pins the channel set (UI read-only) and wins over the legacy single-channel fields. `id` is the stable sidecar directory / tailnet device identity — always give it explicitly when hand-editing; renaming `label` alone derives a new id and therefore registers a new device |
81
+ | `tsnetEnabled` | boolean | `false` | Legacy single-channel switch; only used when `tsnetChannels` is empty |
82
+ | `tsnetAuthKey` | string | `""` | Legacy single channel. Tailscale auth key; must be reusable |
83
+ | `tsnetControlUrl` | string | `""` | Legacy single channel |
84
+ | `tsnetHostname` | string | `""` | Legacy single channel. The plugin prefixes `dsh-`; do not include it yourself |
82
85
  | `tsnetPermissionPreset` | string | `""` | Empty = same as `permissionPreset` |
83
86
  | `maxWakesPerThread` | natural | `30` | Per-thread wake cap per window |
84
87
  | `threadWindowMs` | natural | `3600000` | Window for the cap above |
@@ -93,10 +96,16 @@ if you are not signed in yet. The key **must be Reusable**; single-use keys fail
93
96
  with `invalid key` on the next start. If device approval is enabled in the tailnet,
94
97
  tick Pre-approved as well.
95
98
 
96
- Set `tsnetEnabled: true` plus `tsnetAuthKey` in config, or paste the key once into the
97
- Mesh panel's tailnet card — it is stored in `~/.dsh/mesh/state.json` (mode 0600) and
98
- never needs re-entry. The plugin's UI links to the key page directly; do not tell users
99
- to hunt for it.
99
+ Add a channel in the Mesh panel (name + key, optionally a Headscale control URL), or
100
+ set `tsnetChannels` in config. Keys pasted in the UI are stored in
101
+ `~/.dsh/mesh/state.json` (mode 0600) and never need re-entry. The plugin's UI links to
102
+ the key page directly; do not tell users to hunt for it.
103
+
104
+ One machine can join several tailnets at once. Each channel gets its own sidecar and
105
+ its own state directory; the mesh device identity stays the same, so peers see one
106
+ machine with several tailnet endpoints. Endpoint health is tracked per channel: one
107
+ tailnet going down neither takes the device offline nor affects the other channels.
108
+ Outbound dispatch tries LAN first, then each tailnet channel in order.
100
109
 
101
110
  ## Network and security facts
102
111
 
@@ -117,7 +126,7 @@ to hunt for it.
117
126
 
118
127
  ```bash
119
128
  npm run check # version consistency + TDZ scan + syntax + loadability
120
- npm test # = check + four regression suites (~138 assertions, network-free)
129
+ npm test # = check + regression suites (~280 assertions, network-free)
121
130
  npm run selftest:caps # capability collection: sanitising, GPU parsing, retries, claim rules
122
131
  npm run selftest:client # client bundle rendering without a browser
123
132
  npm run selftest:prompt # task prompt generation
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.4",
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,8 +64,10 @@
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",
68
- "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",
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",
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 lib/tsnet/channels.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",
71
73
  "release:plan": "node scripts/release-plan.mjs",