dsh-plugin-mesh 0.3.30 → 0.3.32
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 +165 -0
- package/README.en.md +107 -0
- package/README.md +15 -346
- package/client/client.js +88 -8
- package/lib/_selftest-client.mjs +92 -1
- package/lib/_selftest-pairing.mjs +77 -0
- package/lib/index.js +59 -5
- package/lib/pairing.js +25 -0
- package/llms.txt +141 -0
- package/package.json +9 -4
- package/scripts/sync-llms.mjs +54 -0
package/lib/_selftest-client.mjs
CHANGED
|
@@ -138,7 +138,7 @@ test("apply() 注册两个槽位:侧栏图标 + 主面板", () => {
|
|
|
138
138
|
assert.ok(regs.includes("main"), `主面板槽未注册:${JSON.stringify(regs)}`);
|
|
139
139
|
});
|
|
140
140
|
|
|
141
|
-
const { CapabilityLine, PeerRow } = mod.__test;
|
|
141
|
+
const { CapabilityLine, PeerRow, TsnetCard, SecretBox } = mod.__test;
|
|
142
142
|
|
|
143
143
|
console.log("\n── CapabilityLine:三种「不知道」必须分开渲染 ──");
|
|
144
144
|
|
|
@@ -245,5 +245,96 @@ test("PeerRow 渲染出的文案里包含对端的能力", () => {
|
|
|
245
245
|
assert.ok(txt.includes("go 1.25"), `机器卡片里应显示能力:${txt}`);
|
|
246
246
|
});
|
|
247
247
|
|
|
248
|
+
console.log("\n── TsnetCard:用户不该自己去后台找授权码地址 ──");
|
|
249
|
+
|
|
250
|
+
const noop = () => {};
|
|
251
|
+
const tsnetOff = { enabled: false, authKeySaved: false, controlUrl: "", node: null, hostname: "", permissionPresetEffective: "" };
|
|
252
|
+
|
|
253
|
+
test("未配置时,卡片当场说明「需要授权码」而不是只留一个输入框", () => {
|
|
254
|
+
const txt = textOf(TsnetCard({ tsnet: tsnetOff, onChanged: noop })).join(" ");
|
|
255
|
+
assert.ok(txt.includes("授权码"), txt.slice(0, 200));
|
|
256
|
+
assert.ok(txt.includes("免费"), "应说明可以免费注册");
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test("给出可直接点开的授权码页面地址", () => {
|
|
260
|
+
const el = TsnetCard({ tsnet: tsnetOff, onChanged: noop });
|
|
261
|
+
const txt = textOf(el).join(" ");
|
|
262
|
+
assert.ok(txt.includes("https://console.tailscale.com/admin/settings/keys"), "地址必须出现在可见文本里(Electron 里点不动也能复制)");
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test("地址是可点链接且新窗口打开", () => {
|
|
266
|
+
const el = TsnetCard({ tsnet: tsnetOff, onChanged: noop });
|
|
267
|
+
const links = [];
|
|
268
|
+
(function walk(n) {
|
|
269
|
+
if (!n || typeof n !== "object") return;
|
|
270
|
+
if (Array.isArray(n)) return n.forEach(walk);
|
|
271
|
+
if (typeof n.type === "function") return walk(n.type(n.props));
|
|
272
|
+
if (n.props && n.props.href) links.push(n.props);
|
|
273
|
+
walk(n.children);
|
|
274
|
+
if (n.props && n.props.children !== undefined) walk(n.props.children);
|
|
275
|
+
})(el);
|
|
276
|
+
const hit = links.find((a) => a.href === "https://console.tailscale.com/admin/settings/keys");
|
|
277
|
+
assert.ok(hit, "应有指向授权码页面的 <a>");
|
|
278
|
+
assert.equal(hit.target, "_blank");
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
test("点明「必须勾选 Reusable」这个真实坑(一次性码重启就失效)", () => {
|
|
282
|
+
const txt = textOf(TsnetCard({ tsnet: tsnetOff, onChanged: noop })).join(" ");
|
|
283
|
+
assert.ok(txt.includes("Reusable"), txt.slice(0, 300));
|
|
284
|
+
assert.ok(txt.includes("一次性"), "应解释为什么必须 Reusable");
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
test("已经存过授权码时不再重复推销取码步骤,只提示已保存", () => {
|
|
288
|
+
// 注意要用 enabled:false —— 那才是"面板会展开"的状态(open 初值 = !enabled)。
|
|
289
|
+
// 用 enabled:true 测这条是假绿:面板默认收起,什么都断言得到。
|
|
290
|
+
const txt = textOf(
|
|
291
|
+
TsnetCard({ tsnet: { ...tsnetOff, enabled: false, authKeySaved: true }, onChanged: noop }),
|
|
292
|
+
).join(" ");
|
|
293
|
+
assert.ok(txt.includes("已保存"), txt.slice(0, 300));
|
|
294
|
+
assert.ok(!txt.includes("console.tailscale.com"), "已配置后不该再占版面显示取码地址");
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
test("enabled 状态下设置面板默认收起(不占版面)", () => {
|
|
298
|
+
const txt = textOf(
|
|
299
|
+
TsnetCard({ tsnet: { ...tsnetOff, enabled: true, authKeySaved: true }, onChanged: noop }),
|
|
300
|
+
).join(" ");
|
|
301
|
+
assert.ok(txt.includes("设置"), "应有「设置」按钮可以展开");
|
|
302
|
+
assert.ok(!txt.includes("console.tailscale.com"), "收起时不该显示取码步骤");
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
console.log("\n── SecretBox:配对码要有开关,不能只显示状态 ──");
|
|
306
|
+
|
|
307
|
+
test("未启用时给出「启用配对码」按钮(而不是叫人去改 YAML)", () => {
|
|
308
|
+
const txt = textOf(SecretBox({ self: { secret: "x".repeat(32) }, config: { requirePairing: false }, onSaved: noop })).join(" ");
|
|
309
|
+
assert.ok(txt.includes("启用配对码"), txt.slice(0, 200));
|
|
310
|
+
assert.ok(!txt.includes("在插件配置里把 requirePairing 设为 true"), "不能只让人去翻配置文件");
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
test("已启用时按钮变成「停用配对码」", () => {
|
|
314
|
+
const txt = textOf(SecretBox({ self: { secret: "x".repeat(32) }, config: { requirePairing: true }, onSaved: noop })).join(" ");
|
|
315
|
+
assert.ok(txt.includes("停用配对码"), txt.slice(0, 200));
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
test("说明改动立即生效、不用重启", () => {
|
|
319
|
+
const txt = textOf(SecretBox({ self: { secret: "x".repeat(32) }, config: { requirePairing: false }, onSaved: noop })).join(" ");
|
|
320
|
+
assert.ok(txt.includes("立即生效"), txt.slice(0, 300));
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
test("配置钉死时按钮禁用并说明原因(不能让人以为点了有用)", () => {
|
|
324
|
+
const el = SecretBox({ self: { secret: "x".repeat(32) }, config: { requirePairing: true, requirePairingPinned: true }, onSaved: noop });
|
|
325
|
+
const txt = textOf(el).join(" ");
|
|
326
|
+
assert.ok(txt.includes("固定开启"), txt.slice(0, 300));
|
|
327
|
+
let disabled = false;
|
|
328
|
+
(function walk(n) {
|
|
329
|
+
if (!n || typeof n !== "object") return;
|
|
330
|
+
if (Array.isArray(n)) return n.forEach(walk);
|
|
331
|
+
if (typeof n.type === "function") return walk(n.type(n.props));
|
|
332
|
+
if (n.props && n.props.disabled === true) disabled = true;
|
|
333
|
+
walk(n.children);
|
|
334
|
+
if (n.props && n.props.children !== undefined) walk(n.props.children);
|
|
335
|
+
})(el);
|
|
336
|
+
assert.ok(disabled, "钉死时开关应被禁用");
|
|
337
|
+
});
|
|
338
|
+
|
|
248
339
|
console.log(`\n${failed === 0 ? "全部通过" : "有失败"}:${passed} 通过 / ${failed} 失败\n`);
|
|
249
340
|
process.exit(failed === 0 ? 0 : 1);
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 配对码开关的自测。
|
|
3
|
+
*
|
|
4
|
+
* 为什么单独测这一段:它**安全相关**,而且判错的后果是**静默的** ——
|
|
5
|
+
* 配对码没生效时,任务照样能派过去,一切看起来正常,只是不再有保护。
|
|
6
|
+
* 这种东西必须有断言盯着。
|
|
7
|
+
*
|
|
8
|
+
* node lib/_selftest-pairing.mjs
|
|
9
|
+
*/
|
|
10
|
+
import { strict as assert } from "node:assert";
|
|
11
|
+
import { resolvePairing } from "./pairing.js";
|
|
12
|
+
|
|
13
|
+
let passed = 0;
|
|
14
|
+
let failed = 0;
|
|
15
|
+
function test(name, fn) {
|
|
16
|
+
try {
|
|
17
|
+
fn();
|
|
18
|
+
passed += 1;
|
|
19
|
+
console.log(` ✓ ${name}`);
|
|
20
|
+
} catch (err) {
|
|
21
|
+
failed += 1;
|
|
22
|
+
console.log(` ✗ ${name}`);
|
|
23
|
+
console.log(` ${err?.message ?? err}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
console.log("\n── 默认必须是关闭(降低上手成本,也是历史默认值)──");
|
|
28
|
+
|
|
29
|
+
test("配置与 state 都没有 → 不需要配对", () => {
|
|
30
|
+
assert.deepEqual(resolvePairing({ config: {}, state: {} }), { required: false, pinned: false });
|
|
31
|
+
});
|
|
32
|
+
test("全空入参 → 不需要配对,且不崩", () => {
|
|
33
|
+
assert.deepEqual(resolvePairing(), { required: false, pinned: false });
|
|
34
|
+
assert.deepEqual(resolvePairing({}), { required: false, pinned: false });
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
console.log("\n── 界面开关:写 state.json,不钉死 ──");
|
|
38
|
+
|
|
39
|
+
test("state.requirePairing = true → 启用,但界面可以再关掉", () => {
|
|
40
|
+
assert.deepEqual(resolvePairing({ config: {}, state: { requirePairing: true } }), {
|
|
41
|
+
required: true,
|
|
42
|
+
pinned: false,
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
test("state.requirePairing = false → 关闭", () => {
|
|
46
|
+
assert.equal(resolvePairing({ config: {}, state: { requirePairing: false } }).required, false);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
console.log("\n── 配置钉死:部署方强制,界面关不掉 ──");
|
|
50
|
+
|
|
51
|
+
test("config.requirePairing = true → 启用且 pinned", () => {
|
|
52
|
+
assert.deepEqual(resolvePairing({ config: { requirePairing: true }, state: {} }), {
|
|
53
|
+
required: true,
|
|
54
|
+
pinned: true,
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
test("配置钉死时,state 里写 false 也关不掉(配置优先)", () => {
|
|
58
|
+
const r = resolvePairing({ config: { requirePairing: true }, state: { requirePairing: false } });
|
|
59
|
+
assert.equal(r.required, true);
|
|
60
|
+
assert.equal(r.pinned, true);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
console.log("\n── 只认严格的布尔 true(防 YAML 字符串坑)──");
|
|
64
|
+
|
|
65
|
+
test('字符串 "true" 不算开启 —— 否则会让人以为配对生效了,实际没有', () => {
|
|
66
|
+
assert.equal(resolvePairing({ config: { requirePairing: "true" }, state: {} }).required, false);
|
|
67
|
+
assert.equal(resolvePairing({ config: {}, state: { requirePairing: "true" } }).required, false);
|
|
68
|
+
});
|
|
69
|
+
test("数字 1 / 空对象等非 true 值都不算开启", () => {
|
|
70
|
+
for (const v of [1, "1", "yes", {}, [], null, undefined]) {
|
|
71
|
+
assert.equal(resolvePairing({ config: { requirePairing: v }, state: {} }).required, false, `config=${JSON.stringify(v)}`);
|
|
72
|
+
assert.equal(resolvePairing({ config: {}, state: { requirePairing: v } }).required, false, `state=${JSON.stringify(v)}`);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
console.log(`\n${failed === 0 ? "全部通过" : "有失败"}:${passed} 通过 / ${failed} 失败\n`);
|
|
77
|
+
process.exit(failed === 0 ? 0 : 1);
|
package/lib/index.js
CHANGED
|
@@ -38,13 +38,14 @@ import {
|
|
|
38
38
|
} from "./capabilities.js";
|
|
39
39
|
import { conversationKey, replyTarget } from "./conversation.js";
|
|
40
40
|
import { buildPrompt } from "./prompt.js";
|
|
41
|
+
import { resolvePairing } from "./pairing.js";
|
|
41
42
|
import { TsnetNode } from "./tsnet/manager.js";
|
|
42
43
|
import { tailnetFetch, tailnetOrigin } from "./tsnet/bridge.js";
|
|
43
44
|
|
|
44
45
|
export const name = "dsh-plugin-mesh";
|
|
45
46
|
export const inject = ["tools", "webServer"];
|
|
46
47
|
|
|
47
|
-
const VERSION = "0.3.
|
|
48
|
+
const VERSION = "0.3.32";
|
|
48
49
|
const RULE_ID = "mesh-inbound";
|
|
49
50
|
const RULE_KIND = "mesh";
|
|
50
51
|
const MAX_BODY = 256 * 1024;
|
|
@@ -318,6 +319,30 @@ function saveState(patch) {
|
|
|
318
319
|
return next;
|
|
319
320
|
}
|
|
320
321
|
|
|
322
|
+
/**
|
|
323
|
+
* 配对码是否真的要用 —— **每次请求都现算**,所以界面上一开关就立即生效。
|
|
324
|
+
*
|
|
325
|
+
* 两种来源,规则和 tsnet 一致:
|
|
326
|
+
* · 配置里写 `requirePairing: true` → **钉死开启**(部署方强制,界面关不掉)
|
|
327
|
+
* · 否则看 `state.json` 里的 `requirePairing` —— 那是界面上那个开关写的
|
|
328
|
+
*
|
|
329
|
+
* 为什么要界面开关:原来只有配置文件一条路,页面上写着"未启用(默认)"却
|
|
330
|
+
* 没有开关,用户只能去翻 YAML。用户实测就卡在这里("启动开关在哪?")。
|
|
331
|
+
* 默认值仍然是**关闭** —— 这一点没变,打开只是变得可发现、可操作。
|
|
332
|
+
*/
|
|
333
|
+
function pairingState(config) {
|
|
334
|
+
return resolvePairing({ config, state: loadState() });
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function pairingRequired(config) {
|
|
338
|
+
return pairingState(config).required;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/** 配置是否把开关钉死了(钉死时界面只能显示、不能改)。 */
|
|
342
|
+
function pairingPinned(config) {
|
|
343
|
+
return pairingState(config).pinned;
|
|
344
|
+
}
|
|
345
|
+
|
|
321
346
|
/**
|
|
322
347
|
* 解析 tailnet 的有效配置。
|
|
323
348
|
*
|
|
@@ -1375,9 +1400,11 @@ function startPeerServer(ctx, { config, discovery, inbound, log, warn, waker, th
|
|
|
1375
1400
|
res.end(body);
|
|
1376
1401
|
};
|
|
1377
1402
|
|
|
1378
|
-
//
|
|
1403
|
+
// 默认免配对:内网里发现即可连。开启配对后才校验配对码。
|
|
1404
|
+
// 注意这里调 pairingRequired() 而**不是**读 config —— 界面上的开关要立即生效,
|
|
1405
|
+
// 不能要求重启(重启会打断用户正在做的事)。
|
|
1379
1406
|
const authed = (req) =>
|
|
1380
|
-
!config
|
|
1407
|
+
!pairingRequired(config) || safeEqual(req.headers["x-dsh-mesh-token"], currentSecret());
|
|
1381
1408
|
|
|
1382
1409
|
const server = createServer(async (req, res) => {
|
|
1383
1410
|
const url = new URL(req.url, "http://localhost");
|
|
@@ -1385,12 +1412,14 @@ function startPeerServer(ctx, { config, discovery, inbound, log, warn, waker, th
|
|
|
1385
1412
|
const self = { ...discovery.selfRecord(), instanceId: discovery.instanceId };
|
|
1386
1413
|
|
|
1387
1414
|
// 免鉴权:只暴露身份,用于连通性探测、主动扫描与配对握手
|
|
1388
|
-
if (path === "/mesh/v1/health") return send(res, 200, { ok: true, ...self, requirePairing: config
|
|
1415
|
+
if (path === "/mesh/v1/health") return send(res, 200, { ok: true, ...self, requirePairing: pairingRequired(config) });
|
|
1389
1416
|
if (path === "/mesh/v1/hello") {
|
|
1390
1417
|
return send(res, 200, {
|
|
1391
1418
|
ok: true,
|
|
1392
1419
|
...self,
|
|
1393
|
-
requirePairing: config
|
|
1420
|
+
requirePairing: pairingRequired(config),
|
|
1421
|
+
// true = 由插件配置钉死,界面上不能关(界面据此禁用开关并说明原因)
|
|
1422
|
+
requirePairingPinned: pairingPinned(config),
|
|
1394
1423
|
peerPaired: authed(req),
|
|
1395
1424
|
});
|
|
1396
1425
|
}
|
|
@@ -1899,6 +1928,31 @@ function registerUiRoutes(ctx, { discovery, config, identity, inbound, outbound,
|
|
|
1899
1928
|
}
|
|
1900
1929
|
});
|
|
1901
1930
|
|
|
1931
|
+
/**
|
|
1932
|
+
* 界面上的「配对码开关」。
|
|
1933
|
+
*
|
|
1934
|
+
* 为什么需要这个接口:原来开启配对只能改 profile 的 cordis.patch.yml 再重启,
|
|
1935
|
+
* 而页面上却明晃晃写着"未启用(默认)"—— 用户在页面上找不到开关,实测就问
|
|
1936
|
+
* 了一句"启动开关在哪?"。状态能看见、却改不了,比不显示更让人困惑。
|
|
1937
|
+
*
|
|
1938
|
+
* 写进 state.json 而不是改写用户的配置文件:配置文件是用户手写的、还带着注释,
|
|
1939
|
+
* 程序去改它风险太大(YAML 注释会被吃掉)。这也是 tsnet 开关一直在用的做法。
|
|
1940
|
+
* 配置里写死 requirePairing: true 的情况仍然优先(部署方能强制)。
|
|
1941
|
+
*/
|
|
1942
|
+
route("/mesh/api/pairing", async (req, res) => {
|
|
1943
|
+
const body = await readJson(req);
|
|
1944
|
+
const want = body?.enabled === true;
|
|
1945
|
+
if (pairingPinned(config)) {
|
|
1946
|
+
return send(res, 409, {
|
|
1947
|
+
ok: false,
|
|
1948
|
+
error: "配对码已由插件配置 requirePairing: true 固定开启,界面无法关闭",
|
|
1949
|
+
});
|
|
1950
|
+
}
|
|
1951
|
+
saveState({ requirePairing: want });
|
|
1952
|
+
log(`配对码${want ? "已启用" : "已停用"}(界面切换,立即生效,无需重启)`);
|
|
1953
|
+
return send(res, 200, { ok: true, requirePairing: want });
|
|
1954
|
+
});
|
|
1955
|
+
|
|
1902
1956
|
route("/mesh/api/secret", async (req, res) => {
|
|
1903
1957
|
const body = await readJson(req);
|
|
1904
1958
|
const secret = String(body?.secret ?? "").trim();
|
package/lib/pairing.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 配对码开关的判定。
|
|
3
|
+
*
|
|
4
|
+
* 单独成模块的理由:这段逻辑**安全相关** —— 判错了配对码会悄悄不生效,
|
|
5
|
+
* 而表面上一切正常(任务照样能派过去)。埋在大文件里的三行 `if` 没人会为它
|
|
6
|
+
* 写测试,所以拆出来、单测它。
|
|
7
|
+
*
|
|
8
|
+
* 两种来源,规则和 tsnet 开关一致:
|
|
9
|
+
* · 插件配置里写 `requirePairing: true` → **钉死开启**(部署方强制,界面关不掉)
|
|
10
|
+
* · 否则看 `state.json` 里的 `requirePairing` —— 那是界面上那个开关写的
|
|
11
|
+
*
|
|
12
|
+
* 默认是**关闭**:同一内网发现即可派任务,降低上手的门槛。这一点没变过 ——
|
|
13
|
+
* 界面开关只是让它变得可发现、可操作,而不是改变默认。
|
|
14
|
+
*
|
|
15
|
+
* @param {{config?: object, state?: object}} input
|
|
16
|
+
* @returns {{required: boolean, pinned: boolean}} pinned = 由配置钉死,界面不可改
|
|
17
|
+
*/
|
|
18
|
+
export function resolvePairing({ config, state } = {}) {
|
|
19
|
+
// 只有严格的布尔 true 才算开启。字符串 "true"、数字 1 都不算 ——
|
|
20
|
+
// 从 YAML 里读出来的 "true" 是字符串,把它当开启会让人以为配对生效了。
|
|
21
|
+
if (config && config.requirePairing === true) {
|
|
22
|
+
return { required: true, pinned: true };
|
|
23
|
+
}
|
|
24
|
+
return { required: !!(state && state.requirePairing === true), pinned: false };
|
|
25
|
+
}
|
package/llms.txt
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# dsh-plugin-mesh
|
|
2
|
+
|
|
3
|
+
> DSH Mesh is a plugin for DeepSeek Harness (dsh) that discovers other dsh instances on the local network over UDP multicast or port scan, shows each peer's self-reported capabilities in a sidebar panel, and dispatches tasks between machines in both directions — over the LAN, or over an automatically downloaded userspace Tailscale (tsnet) sidecar when machines are not on the same network.
|
|
4
|
+
|
|
5
|
+
Canonical package: `dsh-plugin-mesh` (npm, MIT).
|
|
6
|
+
Repository: https://github.com/peng456/dsh-plugin-mesh
|
|
7
|
+
Showcase: https://peng456.github.io/dsh-plugin-mesh/
|
|
8
|
+
Primary documentation language is Chinese; this file is the English, machine-oriented entry point.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
dsh plugin add dsh-plugin-mesh # 'desktop' profile: must run in DSH Desktop's own terminal
|
|
14
|
+
dsh plugin --profile web add dsh-plugin-mesh # any other profile: a normal terminal is fine
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
From source instead: `git clone https://github.com/peng456/dsh-plugin-mesh && cd dsh-plugin-mesh && ./install.sh`
|
|
18
|
+
|
|
19
|
+
`dsh plugin --profile desktop ...` is rejected from a normal terminal by dsh itself (bin.js:29 — the desktop profile is managed exclusively by the Electron application). Use the app's built-in terminal, or `install.sh`.
|
|
20
|
+
|
|
21
|
+
**A restart of the dsh host is required after install** — the plugin loads at startup.
|
|
22
|
+
|
|
23
|
+
Verify after restart: `GET http://127.0.0.1:45917/mesh/v1/health` returns JSON containing `{"app":"dsh-mesh","machine":"<name>",...}`.
|
|
24
|
+
|
|
25
|
+
## What it does at runtime
|
|
26
|
+
|
|
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
|
+
- 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.
|
|
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
|
+
|
|
32
|
+
## Tools registered (callable by the agent)
|
|
33
|
+
|
|
34
|
+
| Tool | Parameters | Purpose |
|
|
35
|
+
|---|---|---|
|
|
36
|
+
| `mesh_peers` | `includeOffline?: boolean` | List discovered peers: online state, address, OS, user, and the capabilities each peer reports. |
|
|
37
|
+
| `mesh_scan` | none | Actively scan the local subnet for mesh peers. Use when multicast is blocked. |
|
|
38
|
+
| `mesh_run` | `peer: string` (required), `task: string` (required), `thread?: string`, `noWake?: boolean`, `newSession?: boolean`, `workspace?: string` | Dispatch a task to another machine. Asynchronous — a successful call means "accepted", not "done". |
|
|
39
|
+
| `mesh_tasks` | none | Show recently received and sent mesh tasks. |
|
|
40
|
+
|
|
41
|
+
`peer` accepts a machine name, an instance id, or `ip:port`. **Do not pass `machine/user`** — `from` fields look like `machine/user`, but the peer key is the machine name only.
|
|
42
|
+
|
|
43
|
+
Reuse the same `thread` value for the same piece of work: the receiving side reuses one session per `thread`, which saves tokens and keeps context. Use `noWake: true` for pure acknowledgements — otherwise a task wakes an agent session on the peer.
|
|
44
|
+
|
|
45
|
+
`newSession: true` forces a fresh session while keeping the same conversation key (i.e. it is still the same conversation, with a clean context).
|
|
46
|
+
|
|
47
|
+
## Configuration
|
|
48
|
+
|
|
49
|
+
Override by id in the profile's `cordis.patch.yml`:
|
|
50
|
+
|
|
51
|
+
```yaml
|
|
52
|
+
- id: mesh
|
|
53
|
+
config:
|
|
54
|
+
requirePairing: true
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**`config:` is replaced wholesale, not merged** (dsh's patch layer does `target[key] = value`). To add one key you must restate the keys you want to keep, or the others fall back to schema defaults.
|
|
58
|
+
|
|
59
|
+
| Key | Type | Default | Notes |
|
|
60
|
+
|---|---|---|---|
|
|
61
|
+
| `enabled` | boolean | `true` | |
|
|
62
|
+
| `machineName` | string | `""` | Human-readable name; empty = ask/derive from hostname |
|
|
63
|
+
| `port` | natural | `45917` | HTTP peer port |
|
|
64
|
+
| `announceIntervalMs` | natural | `5000` | Multicast heartbeat period |
|
|
65
|
+
| `peerTtlMs` | natural | `20000` | Peer marked offline after this silence |
|
|
66
|
+
| `requestTimeoutMs` | natural | `20000` | Per-request timeout |
|
|
67
|
+
| `useMulticast` | boolean | `true` | |
|
|
68
|
+
| `scanOnStart` | boolean | `true` | |
|
|
69
|
+
| `scanIntervalMs` | natural | `60000` | |
|
|
70
|
+
| `scanConcurrency` | natural | `64` | |
|
|
71
|
+
| `scanTimeoutMs` | natural | `800` | |
|
|
72
|
+
| `pingIntervalMs` | natural | `10000` | LAN health probe period |
|
|
73
|
+
| `tsnetProbeIntervalMs` | natural | `60000` | Tailnet health probe period |
|
|
74
|
+
| `requirePairing` | boolean | `false` | **Default off: the peer API accepts unauthenticated task POSTs.** Setting it `true` here pins pairing on; otherwise the Mesh panel's pairing switch (persisted in `state.json`) decides |
|
|
75
|
+
| `agentPreset` | string | `"standard"` | Agent preset for auto-created sessions |
|
|
76
|
+
| `permissionPreset` | string | `"workspace-write"` | Permission preset for auto-created sessions |
|
|
77
|
+
| `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 |
|
|
82
|
+
| `tsnetPermissionPreset` | string | `""` | Empty = same as `permissionPreset` |
|
|
83
|
+
| `maxWakesPerThread` | natural | `30` | Per-thread wake cap per window |
|
|
84
|
+
| `threadWindowMs` | natural | `3600000` | Window for the cap above |
|
|
85
|
+
| `threadCooldownMs` | natural | `5000` | Cooldown between session-creating wakes |
|
|
86
|
+
| `minTaskChars` | natural | `24` | Bodies shorter than this are not woken (inbox only) |
|
|
87
|
+
|
|
88
|
+
## Tailnet setup (the only step that needs an external account)
|
|
89
|
+
|
|
90
|
+
Cross-network links require a free Tailscale account and an auth key. Create one at
|
|
91
|
+
<https://console.tailscale.com/admin/settings/keys> — that URL redirects to sign-up
|
|
92
|
+
if you are not signed in yet. The key **must be Reusable**; single-use keys fail
|
|
93
|
+
with `invalid key` on the next start. If device approval is enabled in the tailnet,
|
|
94
|
+
tick Pre-approved as well.
|
|
95
|
+
|
|
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.
|
|
100
|
+
|
|
101
|
+
## Network and security facts
|
|
102
|
+
|
|
103
|
+
- Ports: TCP `45917` (peer HTTP), UDP `45892` (multicast group `239.255.42.99`).
|
|
104
|
+
- Discovery is intentionally public: any host on the same L2 network can see the machine and its self-reported card.
|
|
105
|
+
- With `requirePairing: false` (the default), **any host that can reach TCP 45917 can POST a task, which wakes an agent session** using `permissionPreset`. Turn on the pairing switch in the Mesh panel (immediate, no restart) or set `requirePairing: true`, and make both machines share one secret, on untrusted networks. The token travels in a plain HTTP header — it guards against stray devices, not against a network sniffer.
|
|
106
|
+
- The shared secret is stored in `~/.dsh/mesh/state.json` (mode 0600) alongside `machineName`, the persisted `instanceIds`, and the tsnet auth key. It is never included in the multicast card.
|
|
107
|
+
- Persistent identity is a UUID per profile; the OS machine fingerprint is used only to reclaim a reinstalled device (same name, or the old record already offline). Two live instances on one physical machine are kept separate.
|
|
108
|
+
- Sidecar binaries are verified against sha256 checksums pinned in `lib/tsnet/checksums.js` — deliberately not fetched from the same release, so a hostile mirror cannot swap both.
|
|
109
|
+
|
|
110
|
+
## Requirements
|
|
111
|
+
|
|
112
|
+
- A dsh host that can load cordis plugins with a client half (DSH Desktop, or `dsh web` + a profile).
|
|
113
|
+
- Node >= 20 for development. Peer `@deepseek-ai/*` packages are provided by the host and are not bundled.
|
|
114
|
+
- No Go toolchain and no Tailscale client are required by end users.
|
|
115
|
+
|
|
116
|
+
## Development
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
npm run check # version consistency + TDZ scan + syntax + loadability
|
|
120
|
+
npm test # = check + four regression suites (~138 assertions, network-free)
|
|
121
|
+
npm run selftest:caps # capability collection: sanitising, GPU parsing, retries, claim rules
|
|
122
|
+
npm run selftest:client # client bundle rendering without a browser
|
|
123
|
+
npm run selftest:prompt # task prompt generation
|
|
124
|
+
npm run build:sidecar # rebuild the Go tsnet sidecar (cross-platform)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
`AGENTS.md` in the repository root carries the operating guide for coding agents: hard constraints, known traps, and file map. Read it before changing this project.
|
|
128
|
+
|
|
129
|
+
## Documentation map
|
|
130
|
+
|
|
131
|
+
- `AGENTS.md` — agent operating guide, constraints, traps (English)
|
|
132
|
+
- `README.en.md` — short English quickstart (English)
|
|
133
|
+
- `DESIGN.md` — design rationale, trade-offs and post-mortems (Chinese)
|
|
134
|
+
- `README.md` — full documentation, Chinese, includes design rationale and post-mortems
|
|
135
|
+
- `Placement设计.md` — placement design and implementation record (Chinese)
|
|
136
|
+
- `设备身份与多通道设计.md` — identity and multi-channel design (Chinese)
|
|
137
|
+
- `docs/index.html` — user-facing showcase, Chinese (GitHub Pages)
|
|
138
|
+
|
|
139
|
+
## Contact
|
|
140
|
+
|
|
141
|
+
geekstartup@163.com · https://github.com/peng456/dsh-plugin-mesh/issues · npm: `dsh-plugin-mesh`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-mesh",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.32",
|
|
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",
|
|
@@ -36,6 +36,9 @@
|
|
|
36
36
|
"./package.json": "./package.json"
|
|
37
37
|
},
|
|
38
38
|
"files": [
|
|
39
|
+
"README.en.md",
|
|
40
|
+
"AGENTS.md",
|
|
41
|
+
"llms.txt",
|
|
39
42
|
"lib",
|
|
40
43
|
"client",
|
|
41
44
|
"sidecar",
|
|
@@ -55,14 +58,16 @@
|
|
|
55
58
|
"selftest:prompt": "node lib/_selftest-prompt.mjs",
|
|
56
59
|
"selftest:caps": "node lib/_selftest-capabilities.mjs",
|
|
57
60
|
"selftest:newsession": "node lib/_selftest-newsession.mjs",
|
|
58
|
-
"test": "npm run check && npm run selftest && npm run selftest:prompt && npm run selftest:client && npm run selftest:caps",
|
|
59
|
-
"check": "node scripts/check-version.mjs && node scripts/check-tdz.mjs && node --check lib/index.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/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 && npm run check:loadable",
|
|
61
|
+
"test": "npm run check && npm run selftest && npm run selftest:prompt && npm run selftest:pairing && npm run selftest:client && npm run selftest:caps",
|
|
62
|
+
"check": "node scripts/check-version.mjs && node scripts/check-tdz.mjs && node --check lib/index.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 && npm run check:loadable && npm run check:docs",
|
|
60
63
|
"build:sidecar": "bash scripts/build-sidecar.sh",
|
|
61
64
|
"verify:mirror": "node scripts/verify-lan-mirror.mjs",
|
|
62
65
|
"check:loadable": "node scripts/check-loadable.mjs --allow-missing-runtime-dep",
|
|
63
66
|
"check:deploy": "node scripts/check-loadable.mjs",
|
|
64
67
|
"check:scope": "python3 tools/scopecheck.py lib/index.js",
|
|
65
|
-
"prepublishOnly": "npm test && node scripts/check-tarball.mjs"
|
|
68
|
+
"prepublishOnly": "npm test && node scripts/check-tarball.mjs",
|
|
69
|
+
"check:docs": "node scripts/sync-llms.mjs",
|
|
70
|
+
"selftest:pairing": "node lib/_selftest-pairing.mjs"
|
|
66
71
|
},
|
|
67
72
|
"publishConfig": {
|
|
68
73
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 让 `llms.txt` 和 `docs/llms.txt` 保持一致。
|
|
3
|
+
*
|
|
4
|
+
* 为什么需要它:`llms.txt` 是给 agent 的机器入口(llmstxt.org 约定)。它要被
|
|
5
|
+
* 两个地方拿到:
|
|
6
|
+
* · 仓库根 —— clone 下来的 agent 直接读本地文件
|
|
7
|
+
* · `docs/` —— 站点上 `https://<site>/llms.txt`,这是约定里 agent 会去找的路径
|
|
8
|
+
*
|
|
9
|
+
* 两份必须逐字节相同,否则 agent 会读到两个版本的"事实",而且**没人会察觉**
|
|
10
|
+
* (这项目已经栽过好几次"复制了一份、然后忘了同步")。所以改成一份源 + 校验:
|
|
11
|
+
*
|
|
12
|
+
* node scripts/sync-llms.mjs # 校验(默认,CI / npm run check 用)
|
|
13
|
+
* node scripts/sync-llms.mjs --write # 用根目录那份覆盖 docs/
|
|
14
|
+
*/
|
|
15
|
+
import { readFileSync, writeFileSync, existsSync } from "node:fs";
|
|
16
|
+
import { join, dirname } from "node:path";
|
|
17
|
+
import { fileURLToPath } from "node:url";
|
|
18
|
+
|
|
19
|
+
const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
20
|
+
const SRC = join(ROOT, "llms.txt");
|
|
21
|
+
const DST = join(ROOT, "docs", "llms.txt");
|
|
22
|
+
|
|
23
|
+
if (!existsSync(SRC)) {
|
|
24
|
+
console.error("✗ 找不到 llms.txt —— 它是给 agent 的机器入口,不能少");
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const src = readFileSync(SRC, "utf8");
|
|
29
|
+
|
|
30
|
+
if (process.argv.includes("--write")) {
|
|
31
|
+
writeFileSync(DST, src);
|
|
32
|
+
console.log(`✓ 已同步 docs/llms.txt(${src.length} 字符)`);
|
|
33
|
+
process.exit(0);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!existsSync(DST)) {
|
|
37
|
+
console.error("✗ docs/llms.txt 不存在 —— 跑 `node scripts/sync-llms.mjs --write`");
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const dst = readFileSync(DST, "utf8");
|
|
42
|
+
if (dst !== src) {
|
|
43
|
+
// 给出行数差异,别只丢一句"不一致"
|
|
44
|
+
const a = src.split("\n");
|
|
45
|
+
const b = dst.split("\n");
|
|
46
|
+
const firstDiff = a.findIndex((line, i) => line !== b[i]);
|
|
47
|
+
console.error(
|
|
48
|
+
`✗ docs/llms.txt 与 llms.txt 不一致(首个差异在根文件第 ${firstDiff + 1} 行)。\n` +
|
|
49
|
+
` 两份都是 agent 会读的"事实来源",必须相同。\n` +
|
|
50
|
+
` 修复:node scripts/sync-llms.mjs --write`,
|
|
51
|
+
);
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
console.log(`✓ llms.txt 与 docs/llms.txt 一致(${src.length} 字符)`);
|