dsh-plugin-mesh 0.5.7 → 0.5.9
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 +9 -2
- package/README.en.md +28 -9
- package/README.md +77 -976
- package/client/client.js +628 -38
- package/cordis.patch.yml +10 -0
- package/lib/_selftest-approval.mjs +165 -0
- package/lib/_selftest-at-mention-host.mjs +377 -0
- package/lib/_selftest-at-mention.mjs +168 -0
- package/lib/_selftest-capabilities.mjs +11 -7
- package/lib/_selftest-prompt.mjs +7 -0
- package/lib/_selftest-reply-route.mjs +60 -1
- package/lib/_selftest-update.mjs +20 -3
- package/lib/_selftest-upgrade.mjs +623 -0
- package/lib/_selftest-workbench.mjs +163 -20
- package/lib/approval.js +152 -0
- package/lib/at-mention.js +109 -0
- package/lib/index.js +712 -99
- package/lib/prompt.js +5 -1
- package/lib/update.js +3 -0
- package/lib/upgrade.js +635 -0
- package/llms.txt +23 -3
- package/package.json +14 -10
- package/scripts/check-tdz.mjs +54 -9
package/llms.txt
CHANGED
|
@@ -30,8 +30,24 @@ Verify after restart: `GET http://127.0.0.1:45917/mesh/v1/health` returns JSON c
|
|
|
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
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
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.
|
|
33
|
-
- Home-page header exposes two compact text links (no cards): **问题反馈** opens a prefilled GitHub issue, and **检查更新** calls `GET /mesh/api/update`. The update route asks the npm registry (`registry.npmjs.org`, falling back to `registry.npmmirror.com`, 5 s per source, 30 min host-side cache) and compares with the running `VERSION`. A failed check returns `{ok:false,error,failures[]}` and is shown as "检查失败" — never as "已是最新".
|
|
33
|
+
- Home-page header exposes two compact text links (no cards): **问题反馈** opens a prefilled GitHub issue, and **检查更新** calls `GET /mesh/api/update`. The update route asks the npm registry (`registry.npmjs.org`, falling back to `registry.npmmirror.com`, 5 s per source, 30 min host-side cache) and compares with the running `VERSION`. A failed check returns `{ok:false,error,failures[]}` and is shown as "检查失败" — never as "已是最新".
|
|
34
|
+
- One-click install: the inline "新版本 vX" link calls `POST /mesh/api/upgrade` (same-origin loopback only). It downloads the npm tarball for that version, verifies `dist.integrity` (sha512), extracts to a sibling staging dir, runs a real `import()` loadability check, backs up the old directory (`.mesh-upgrade-backup-*`, last 3 kept) and atomically swaps. Any failure keeps the old version and returns the failing stage. The result classifies the change: `restartRequired` only when `lib/` changed (plus version-only bumps), `reloadRequired` when only `client/` changed.
|
|
35
|
+
- A successful install writes `upgrade.json` under the mesh state dir; until the process restarts, `GET /mesh/api/update` reports `pendingUpgrade` so the UI offers **重启生效** (`POST /mesh/api/upgrade/restart`) or **重载界面** instead of installing again (`POST /mesh/api/upgrade/reload` uses DSH Desktop's built-in `desktopSettingsController.reloadRenderer()`, the same action as Settings → Developer options → Reload interface; other hosts fall back to a page reload). On DSH Desktop the restart goes through the host's own `desktopSettingsController.restart()` (native confirm + ordered relaunch); plain `dsh web`/headless falls back to dshmarket's self-restart (`POST /dsh-market/api/v1/restart`) when that plugin is installed and not under a detected systemd supervisor. When neither entry exists the response is `mode:"manual"` with an explicit reason — it never pretends a restart happened.
|
|
34
36
|
- The prefilled feedback issue carries the same diagnostics text as the diagnostics section; `buildDiagnostics()` deliberately excludes secrets (pairing code, tsnet auth key). The author's email (`geekstartup@163.com`) is the fallback when GitHub is unreachable.
|
|
37
|
+
- **First-contact approval (default on).** An inbound task from a machine that is not in `state.json`'s `approvedPeers` is stored with `status: "needs-approval"` and answered with **HTTP 202** `{ok:true,pendingApproval:true}`; no agent session is created. The owner allows or denies it in the panel (`POST /mesh/api/approval` `{id,action:"allow"|"deny"}`); allowing adds the peer to `approvedPeers` and immediately runs the stored task. `POST /mesh/api/approval/revoke` `{machine}` removes trust. Replies (a task whose `thread` matches an outbound dispatch to the same machine) bypass the gate — otherwise the result would never come back. With `requirePairing` on (or the pairing switch enabled) the gate is skipped: pairing is the stronger trust gesture.
|
|
38
|
+
- `GET /mesh/api/demo` returns a read-only snapshot of this machine (platform, CPU, memory, load, uptime, a few runtimes) used by the panel's single-machine demo. It contains no secrets and changes no state.
|
|
39
|
+
- `/mesh/api/state` additionally exposes `config.requireApproval`, `approvals[]` (pending first-contact tasks) and `approvedPeers[]` (`{machine,address,at}`).
|
|
40
|
+
|
|
41
|
+
## Usage patterns (agent to agent)
|
|
42
|
+
|
|
43
|
+
What this is for: one agent hands a task to another agent on a different machine, and the result comes back. The receiving agent decides how to do it; the sender only states the outcome.
|
|
44
|
+
|
|
45
|
+
- **Compile on the PC** — “Pull the latest code, build the Windows target, send me the artifact and any errors.” The peer agent runs the build and returns the artifact path, exit code and error summary.
|
|
46
|
+
- **Deploy and verify on Android** — “Install the build I just made on the Android device, launch it, send a screenshot and the logs.” The peer installs, launches, screenshots and returns key log lines.
|
|
47
|
+
- **Plugin adaptation** — “On the Windows box, install the latest build, restart, and confirm `/mesh/v1/health` reports the new version.” The peer upgrades, restarts, probes health and reports the version.
|
|
48
|
+
- **Chains** — the receiving agent can call `mesh_run` itself to hand the next step to a third machine (compile on B, deploy on C), and the consolidated result is dispatched back to the origin. No central scheduler: each hop is just another `mesh_run`.
|
|
49
|
+
|
|
50
|
+
These are outcomes, not a fixed feature list: the peer agent can run any command it has permission for.
|
|
35
51
|
|
|
36
52
|
## Tools registered (callable by the agent)
|
|
37
53
|
|
|
@@ -136,6 +152,7 @@ Override by id in the profile's `cordis.patch.yml`:
|
|
|
136
152
|
| `pingIntervalMs` | natural | `10000` | LAN health probe period |
|
|
137
153
|
| `tsnetProbeIntervalMs` | natural | `60000` | Tailnet health probe period |
|
|
138
154
|
| `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 |
|
|
155
|
+
| `requireApproval` | boolean | `true` | First task from an unknown machine is held as `needs-approval` until the owner clicks Allow. Set `false` to restore fully unattended dispatch. Ignored (no prompt) when pairing is on |
|
|
139
156
|
| `agentPreset` | string | `"standard"` | Agent preset for auto-created sessions |
|
|
140
157
|
| `permissionPreset` | string | `"workspace-write"` | Permission preset for auto-created sessions |
|
|
141
158
|
| `workspaceRoot` | string | `""` | |
|
|
@@ -173,7 +190,8 @@ Outbound dispatch tries LAN first, then each tailnet channel in order.
|
|
|
173
190
|
|
|
174
191
|
- Ports: TCP `45917` (peer HTTP), UDP `45892` (multicast group `239.255.42.99`).
|
|
175
192
|
- Discovery is intentionally public: any host on the same L2 network can see the machine and its self-reported card.
|
|
176
|
-
- With `
|
|
193
|
+
- With `requireApproval: true` (the default) a first task from an unknown machine does **not** wake anything: it is held for local approval. Once approved, later tasks from that machine run unattended. Set `requireApproval: false` to get fully unattended dispatch (the pre-0.6 behaviour).
|
|
194
|
+
- With `requirePairing: false` (the default) there is still no cryptographic authentication of the sender: the trust decision is per-machine, made by the owner, not by a shared secret. On untrusted networks turn on the pairing switch in the Mesh panel (immediate, no restart) or set `requirePairing: true`, and make both machines share one secret. The token travels in a plain HTTP header — it guards against stray devices, not against a network sniffer.
|
|
177
195
|
- 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.
|
|
178
196
|
- 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.
|
|
179
197
|
- 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.
|
|
@@ -201,11 +219,13 @@ npm run build:sidecar # rebuild the Go tsnet sidecar (cross-platform)
|
|
|
201
219
|
|
|
202
220
|
- `AGENTS.md` — agent operating guide, constraints, traps (English)
|
|
203
221
|
- `README.en.md` — short English quickstart (English)
|
|
222
|
+
- `README.md` — user-facing entry (Chinese): what it gives you, 5-minute start, safety, FAQ
|
|
223
|
+
- `docs/DESIGN-NOTES.md` — the old long-form README: multicast/scan/firewall details, tsnet, identity, full config table, security model, limits, development
|
|
204
224
|
- `DESIGN.md` — design rationale, trade-offs and post-mortems (Chinese)
|
|
205
|
-
- `README.md` — full documentation, Chinese, includes design rationale and post-mortems
|
|
206
225
|
- `Placement设计.md` — placement design and implementation record (Chinese)
|
|
207
226
|
- `设备身份与多通道设计.md` — identity and multi-channel design (Chinese)
|
|
208
227
|
- `docs/index.html` — user-facing showcase, Chinese (GitHub Pages)
|
|
228
|
+
- `docs/demo.html` — 60-second animated walkthrough (schematic; connects to nothing)
|
|
209
229
|
|
|
210
230
|
## Contact
|
|
211
231
|
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-mesh",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.9",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "DSH
|
|
5
|
+
"description": "把跑不完的活交给另一台电脑;跑完,结果回到你面前。两台装了 DSH 的电脑各装一次,自动互相发现,任务派过去由对端的 agent 执行,结果派回来。Hand a long task to another machine: your DSH instances find each other, the peer runs it, and the result comes back. No pairing codes, no IPs, no Tailscale client.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "peng456 (https://github.com/peng456)",
|
|
8
8
|
"keywords": [
|
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
"deepseek-harness",
|
|
12
12
|
"dsh-desktop",
|
|
13
13
|
"mesh",
|
|
14
|
-
"lan",
|
|
15
|
-
"multicast",
|
|
16
|
-
"discovery",
|
|
17
14
|
"remote",
|
|
15
|
+
"multi-machine",
|
|
16
|
+
"long-task",
|
|
17
|
+
"second-machine",
|
|
18
|
+
"lan",
|
|
18
19
|
"tailscale",
|
|
19
|
-
"tsnet",
|
|
20
20
|
"tailnet",
|
|
21
|
-
"
|
|
21
|
+
"discovery"
|
|
22
22
|
],
|
|
23
23
|
"homepage": "https://github.com/peng456/dsh-plugin-mesh#readme",
|
|
24
24
|
"repository": {
|
|
@@ -67,8 +67,10 @@
|
|
|
67
67
|
"selftest:diagnostics": "node lib/_selftest-diagnostics.mjs",
|
|
68
68
|
"selftest:osinfo": "node lib/_selftest-osinfo.mjs",
|
|
69
69
|
"selftest:update": "node lib/_selftest-update.mjs",
|
|
70
|
-
"
|
|
71
|
-
"
|
|
70
|
+
"selftest:upgrade": "node lib/_selftest-upgrade.mjs",
|
|
71
|
+
"selftest:approval": "node lib/_selftest-approval.mjs",
|
|
72
|
+
"test": "npm run check && npm run selftest && npm run selftest:prompt && npm run selftest:at && npm run selftest:at:host && npm run selftest:pairing && npm run selftest:approval && npm run selftest:switch && 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 && npm run selftest:update && npm run selftest:upgrade",
|
|
73
|
+
"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/at-mention.js && node --check lib/pairing.js && node --check lib/switch.js && node --check lib/scan.js && node --check lib/update.js && node --check lib/upgrade.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",
|
|
72
74
|
"build:sidecar": "bash scripts/build-sidecar.sh",
|
|
73
75
|
"verify:mirror": "node scripts/verify-lan-mirror.mjs",
|
|
74
76
|
"release:plan": "node scripts/release-plan.mjs",
|
|
@@ -79,7 +81,9 @@
|
|
|
79
81
|
"prepublishOnly": "npm test && node scripts/check-tarball.mjs",
|
|
80
82
|
"check:docs": "node scripts/sync-llms.mjs",
|
|
81
83
|
"selftest:pairing": "node lib/_selftest-pairing.mjs",
|
|
82
|
-
"selftest:switch": "node lib/_selftest-switch.mjs"
|
|
84
|
+
"selftest:switch": "node lib/_selftest-switch.mjs",
|
|
85
|
+
"selftest:at": "node lib/_selftest-at-mention.mjs",
|
|
86
|
+
"selftest:at:host": "node --experimental-vm-modules lib/_selftest-at-mention-host.mjs"
|
|
83
87
|
},
|
|
84
88
|
"publishConfig": {
|
|
85
89
|
"registry": "https://registry.npmjs.org/",
|
package/scripts/check-tdz.mjs
CHANGED
|
@@ -23,20 +23,65 @@ import { fileURLToPath } from "node:url";
|
|
|
23
23
|
import { dirname, join } from "node:path";
|
|
24
24
|
|
|
25
25
|
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
26
|
-
const files = ["lib/index.js", "lib/discovery.js", "lib/conversation.js", "lib/identity.js", "lib/update.js"];
|
|
26
|
+
const files = ["lib/index.js", "lib/discovery.js", "lib/conversation.js", "lib/identity.js", "lib/update.js", "lib/upgrade.js"];
|
|
27
27
|
let problems = 0;
|
|
28
28
|
|
|
29
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* 去掉 `//` 行注释。只认行首或「代码分隔符之后的 //」—— `http://` 这类
|
|
31
|
+
* 字符串里的双斜杠不能被当成注释,否则整行后面的 `{` 会被吞掉、深度从此错位。
|
|
32
|
+
* (Windows 的 CRLF checkout 曾把这个问题放大成"只有 Windows 报错"。)
|
|
33
|
+
*/
|
|
34
|
+
function stripLineComment(line) {
|
|
35
|
+
return line.replace(/(^|[\s;{(,=])\/\/.*$/, "$1");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** 去掉单行字符串/模板串的内容:里面的标识符和花括号都不算代码。 */
|
|
39
|
+
function stripStrings(line) {
|
|
40
|
+
return line
|
|
41
|
+
.replace(/'(?:\\.|[^'\\])*'/g, '""')
|
|
42
|
+
.replace(/"(?:\\.|[^"\\])*"/g, '""')
|
|
43
|
+
.replace(/`(?:\\.|[^`\\])*`/g, '""');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 逐行计算花括号深度(粗略:块注释/字符串/行注释都先剥掉)。
|
|
48
|
+
*
|
|
49
|
+
* 必须做这些剥离:JSDoc 里的 `{{...}}`、URL 里的 `//`、字符串里的花括号都会
|
|
50
|
+
* 让朴素计数错位,而错位之后 TDZ 检查要么漏报、要么在别的行上误报。
|
|
51
|
+
* 行尾的 `\r` 先去掉:CRLF 会让 `/.*$/` 的匹配位置与 LF 不同。
|
|
52
|
+
*/
|
|
30
53
|
function depths(lines) {
|
|
31
54
|
const out = [];
|
|
32
55
|
let d = 0;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
56
|
+
let inBlock = false;
|
|
57
|
+
for (const raw of lines) {
|
|
58
|
+
let code = raw.replace(/\r$/, "");
|
|
59
|
+
if (inBlock) {
|
|
60
|
+
const end = code.indexOf("*/");
|
|
61
|
+
if (end === -1) {
|
|
62
|
+
out.push(d);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
code = code.slice(end + 2);
|
|
66
|
+
inBlock = false;
|
|
67
|
+
}
|
|
68
|
+
for (;;) {
|
|
69
|
+
const start = code.indexOf("/*");
|
|
70
|
+
if (start === -1) break;
|
|
71
|
+
const end = code.indexOf("*/", start + 2);
|
|
72
|
+
if (end === -1) {
|
|
73
|
+
code = code.slice(0, start);
|
|
74
|
+
inBlock = true;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
code = code.slice(0, start) + code.slice(end + 2);
|
|
78
|
+
}
|
|
79
|
+
code = stripStrings(stripLineComment(code));
|
|
36
80
|
for (const ch of code) {
|
|
37
81
|
if (ch === "{") d += 1;
|
|
38
82
|
else if (ch === "}") d -= 1;
|
|
39
83
|
}
|
|
84
|
+
out.push(d);
|
|
40
85
|
}
|
|
41
86
|
return out;
|
|
42
87
|
}
|
|
@@ -55,14 +100,14 @@ for (const rel of files) {
|
|
|
55
100
|
seen.add(key);
|
|
56
101
|
|
|
57
102
|
const D = depth[i];
|
|
58
|
-
// 前面不能是
|
|
59
|
-
const re = new RegExp(`(?<![.\\w$])${name.replace(/\$/g, "\\$")}\\b`);
|
|
103
|
+
// 前面不能是 `.`(属性访问);后面不能是 `:`(对象 key 不是变量引用)。
|
|
104
|
+
const re = new RegExp(`(?<![.\\w$])${name.replace(/\$/g, "\\$")}\\b(?!\\s*:)`);
|
|
60
105
|
for (let j = i - 1; j >= 0; j -= 1) {
|
|
61
106
|
if (depth[j] < D) break; // 出了这个块
|
|
62
107
|
if (depth[j] > D) continue; // 内层块,不同作用域
|
|
63
|
-
const text = lines[j];
|
|
108
|
+
const text = lines[j].replace(/\r$/, "");
|
|
64
109
|
if (/^\s*(\/\/|\*|\/\*)/.test(text)) continue;
|
|
65
|
-
if (re.test(text)) {
|
|
110
|
+
if (re.test(stripStrings(text))) {
|
|
66
111
|
console.error(`✗ ${rel}:${j + 1} 在声明前使用了 '${name}'(声明在 ${i + 1} 行,同属深度 ${D} 的块)`);
|
|
67
112
|
problems += 1;
|
|
68
113
|
break;
|