dsh-plugin-mesh 0.0.0-stage → 0.3.29

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.
Files changed (48) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1183 -2
  3. package/client/client.js +958 -0
  4. package/cordis.patch.yml +80 -0
  5. package/install.sh +142 -0
  6. package/lib/_rehearsal-peer.mjs +229 -0
  7. package/lib/_selftest-capabilities.mjs +631 -0
  8. package/lib/_selftest-client.mjs +249 -0
  9. package/lib/_selftest-discovery.mjs +51 -0
  10. package/lib/_selftest-newsession.mjs +124 -0
  11. package/lib/_selftest-prompt.mjs +97 -0
  12. package/lib/_selftest-tsnet-live.mjs +169 -0
  13. package/lib/_selftest-tsnet-tailnet.mjs +418 -0
  14. package/lib/_selftest-tsnet.mjs +647 -0
  15. package/lib/capabilities.js +786 -0
  16. package/lib/conversation.js +59 -0
  17. package/lib/discovery.js +744 -0
  18. package/lib/identity.js +136 -0
  19. package/lib/index.js +2079 -0
  20. package/lib/prompt.js +50 -0
  21. package/lib/scan.js +118 -0
  22. package/lib/tsnet/bridge.js +71 -0
  23. package/lib/tsnet/checksums.js +19 -0
  24. package/lib/tsnet/download.js +384 -0
  25. package/lib/tsnet/manager.js +655 -0
  26. package/package.json +118 -4
  27. package/scripts/__pycache__/mesh-tsnet-merge.cpython-312.pyc +0 -0
  28. package/scripts/_selftest-tsnet-merge.py +168 -0
  29. package/scripts/build-sidecar.sh +372 -0
  30. package/scripts/check-loadable.mjs +154 -0
  31. package/scripts/check-tarball.mjs +106 -0
  32. package/scripts/check-tdz.mjs +78 -0
  33. package/scripts/check-version.mjs +32 -0
  34. package/scripts/fix-android-tls-align.py +87 -0
  35. package/scripts/mesh-tsnet-merge.py +345 -0
  36. package/scripts/mesh-tsnet-onboarding.md +98 -0
  37. package/scripts/publish-assets.py +213 -0
  38. package/scripts/push-via-api.py +262 -0
  39. package/scripts/release-plugin.sh +129 -0
  40. package/scripts/restart-dsh.sh +308 -0
  41. package/scripts/submit-to-awesome.py +212 -0
  42. package/scripts/verify-lan-mirror.mjs +57 -0
  43. package/sidecar/androidbin_linux.go +39 -0
  44. package/sidecar/androidnet_linux.go +414 -0
  45. package/sidecar/androidnet_other.go +15 -0
  46. package/sidecar/go.mod +51 -0
  47. package/sidecar/go.sum +239 -0
  48. package/sidecar/main.go +850 -0
@@ -0,0 +1,958 @@
1
+ /**
2
+ * dsh-plugin-mesh —— 浏览器侧(Client half)
3
+ *
4
+ * 手写的 __ModuleLoader__ bundle,不需要打包工具。
5
+ * 只依赖 react,数据走相对路径 fetch('/mesh/api/*')(同源)。
6
+ *
7
+ * 挂两个槽位:
8
+ * sidebar.panellist (list, key=id) → 侧栏一个图标,点击切到本面板
9
+ * main (keyed, key) → 面板内容(layout 按 activePanelId 取 entry)
10
+ *
11
+ * 用 ctx.slots.inject(name, cb) 注册:槽位还没声明时会自动等待,
12
+ * 所以不依赖插件加载顺序。
13
+ */
14
+ window.__ModuleLoader__.load({
15
+ id: "dsh-plugin-mesh",
16
+ factory: (require) => {
17
+ var module = { exports: {} };
18
+ var exports = module.exports;
19
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
20
+
21
+ const react = require("react");
22
+ const h = react.createElement;
23
+
24
+ const PANEL_ID = "mesh";
25
+ const API = "/mesh/api";
26
+ const inject = ["slots"];
27
+
28
+ // ─────────────────────── 数据 ───────────────────────
29
+
30
+ function useMeshState(intervalMs) {
31
+ const [state, setState] = react.useState(null);
32
+ const [error, setError] = react.useState(null);
33
+ react.useEffect(() => {
34
+ let alive = true;
35
+ const load = async () => {
36
+ try {
37
+ const r = await fetch(`${API}/state`, { headers: { accept: "application/json" } });
38
+ const j = await r.json();
39
+ if (alive) {
40
+ setState(j);
41
+ setError(null);
42
+ }
43
+ } catch (e) {
44
+ if (alive) setError(String((e && e.message) || e));
45
+ }
46
+ };
47
+ load();
48
+ const t = setInterval(load, intervalMs || 3000);
49
+ return () => {
50
+ alive = false;
51
+ clearInterval(t);
52
+ };
53
+ }, [intervalMs]);
54
+ return { state, error };
55
+ }
56
+
57
+ async function call(path, body) {
58
+ const r = await fetch(API + path, {
59
+ method: "POST",
60
+ headers: { "content-type": "application/json" },
61
+ body: JSON.stringify(body || {}),
62
+ });
63
+ return r.json().catch(() => ({}));
64
+ }
65
+
66
+ // ─────────────────────── 样式 ───────────────────────
67
+
68
+ const S = {
69
+ /**
70
+ * 页面根容器。必须自己当滚动容器:
71
+ * layout 的 centerCol 是 `display:flex; flex-direction:column; overflow:hidden`,
72
+ * 面板内容一旦溢出会被直接裁掉、页面滚不动。官方面板用的是同一套
73
+ * (conversation 的 scrollBody = flex:1 + min-height:0 + overflow-y:auto)。
74
+ * minHeight:0 不能省 —— flex 子项默认 min-height:auto,会拒绝收缩。
75
+ */
76
+ page: {
77
+ flex: 1,
78
+ minHeight: 0,
79
+ overflowY: "auto",
80
+ width: "100%",
81
+ boxSizing: "border-box",
82
+ padding: "24px 28px",
83
+ color: "var(--dsw-alias-label-primary, #111)",
84
+ font: "14px/1.6 system-ui, -apple-system, 'Segoe UI', sans-serif",
85
+ },
86
+ /** 内容限宽居中;与滚动容器分开,滚动条才会贴窗口边缘而不是卡在 1080px 处 */
87
+ pageInner: { maxWidth: 1080, margin: "0 auto" },
88
+ h1: { fontSize: 20, fontWeight: 600, margin: "0 0 4px" },
89
+ sub: { color: "var(--dsw-alias-label-secondary, #666)", fontSize: 13, marginBottom: 20 },
90
+ card: { border: "1px solid var(--dsw-alias-border-secondary, #e3e5e8)", borderRadius: 10, padding: 16, marginBottom: 16, background: "var(--dsw-alias-bg-elevated, transparent)" },
91
+ cardTitle: { fontSize: 13, fontWeight: 600, margin: "0 0 12px", color: "var(--dsw-alias-label-secondary, #666)" },
92
+ row: { display: "flex", gap: 8, alignItems: "center", flexWrap: "wrap" },
93
+ input: { flex: 1, minWidth: 180, padding: "7px 10px", border: "1px solid var(--dsw-alias-border-secondary, #d5d8dc)", borderRadius: 7, background: "var(--dsw-alias-bg-base, #fff)", color: "inherit", font: "inherit" },
94
+ textarea: { width: "100%", minHeight: 68, padding: "8px 10px", border: "1px solid var(--dsw-alias-border-secondary, #d5d8dc)", borderRadius: 7, background: "var(--dsw-alias-bg-base, #fff)", color: "inherit", font: "inherit", resize: "vertical", boxSizing: "border-box" },
95
+ btn: { padding: "7px 14px", border: "1px solid var(--dsw-alias-border-secondary, #d5d8dc)", borderRadius: 7, background: "var(--dsw-alias-bg-elevated, #f6f7f8)", color: "inherit", cursor: "pointer", font: "inherit", whiteSpace: "nowrap" },
96
+ btnPrimary: { padding: "7px 14px", border: "1px solid transparent", borderRadius: 7, background: "var(--dsw-alias-button-primary-fill, #111)", color: "#fff", cursor: "pointer", font: "inherit", whiteSpace: "nowrap" },
97
+ btnSm: { padding: "4px 10px", fontSize: 12, border: "1px solid var(--dsw-alias-border-secondary, #d5d8dc)", borderRadius: 6, background: "transparent", color: "inherit", cursor: "pointer", font: "inherit" },
98
+ peer: { display: "flex", alignItems: "center", gap: 12, padding: "10px 12px", border: "1px solid var(--dsw-alias-border-secondary, #e8eaed)", borderRadius: 8, marginBottom: 8 },
99
+ dot: (on) => ({ width: 8, height: 8, borderRadius: 4, flex: "0 0 auto", background: on ? "#2ea043" : "#9aa0a6" }),
100
+ mono: { fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace", fontSize: 12 },
101
+ muted: { color: "var(--dsw-alias-label-secondary, #777)", fontSize: 12 },
102
+ tag: { fontSize: 11, padding: "1px 7px", borderRadius: 999, border: "1px solid var(--dsw-alias-border-secondary, #d5d8dc)", color: "var(--dsw-alias-label-secondary, #666)" },
103
+ log: { ...{ fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace", fontSize: 12 }, maxHeight: 220, overflow: "auto" },
104
+ logRow: { padding: "5px 0", borderBottom: "1px solid var(--dsw-alias-border-secondary, #f0f1f3)" },
105
+ };
106
+
107
+ const label = { fontWeight: 600, color: "var(--dsw-alias-label-secondary, #666)", fontSize: 12, marginBottom: 4, display: "block" };
108
+
109
+ // ─────────────────────── 小组件 ───────────────────────
110
+
111
+ // ─────────────────────── 命名 ───────────────────────
112
+
113
+ /**
114
+ * 本机名字。首次使用(还落在主机名上)时主动询问一次 ——
115
+ * 别的机器就是靠这个名字找到你的,所以值得让用户确认一下。
116
+ */
117
+ function NameCard({ self, onSaved }) {
118
+ const needs = !!self.needsName;
119
+ const fromConfig = self.machineSource === "config";
120
+ const [editing, setEditing] = react.useState(false);
121
+ const [value, setValue] = react.useState(self.hostname || "");
122
+ const [msg, setMsg] = react.useState("");
123
+ const [busy, setBusy] = react.useState(false);
124
+
125
+ // 首次进入自动展开
126
+ react.useEffect(() => {
127
+ if (needs) setEditing(true);
128
+ }, [needs]);
129
+
130
+ const save = async () => {
131
+ setBusy(true);
132
+ const r = await call("/name", { name: value });
133
+ setBusy(false);
134
+ if (r && r.ok) {
135
+ setMsg(`已改名为「${r.name}」,已重新广播`);
136
+ setEditing(false);
137
+ onSaved && onSaved();
138
+ } else {
139
+ setMsg(`失败:${(r && r.error) || "未知错误"}`);
140
+ }
141
+ setTimeout(() => setMsg(""), 4000);
142
+ };
143
+
144
+ if (!needs && !editing) {
145
+ return h(
146
+ "div",
147
+ { style: { ...S.row, marginBottom: 12 } },
148
+ h("span", { style: S.muted }, "本机名字"),
149
+ h("strong", { style: { fontSize: 15 } }, self.machine || "?"),
150
+ h("span", { style: S.tag }, fromConfig ? "由配置指定" : "已命名"),
151
+ fromConfig
152
+ ? null
153
+ : h("button", { style: S.btnSm, onClick: () => { setValue(self.machine || ""); setEditing(true); } }, "改名"),
154
+ msg ? h("span", { style: { fontSize: 12 } }, msg) : null,
155
+ );
156
+ }
157
+
158
+ return h(
159
+ "div",
160
+ { style: { ...S.card, borderColor: needs ? "#bf8700" : undefined } },
161
+ h("div", { style: S.cardTitle }, needs ? "首次使用:给这台机器起个名字" : "改本机名字"),
162
+ h(
163
+ "div",
164
+ { style: S.muted },
165
+ needs
166
+ ? "其他机器会用它来找到你、把任务派给你。留空或直接用主机名也行。"
167
+ : "别的机器正在用这个名字找你,改完会立刻重新广播。",
168
+ ),
169
+ h(
170
+ "div",
171
+ { style: { ...S.row, marginTop: 12 } },
172
+ h("input", {
173
+ style: S.input,
174
+ placeholder: self.hostname || "例如 livingroom-mac",
175
+ value,
176
+ onChange: (e) => setValue(e.target.value),
177
+ onKeyDown: (e) => {
178
+ if (e.key === "Enter" && value.trim()) save();
179
+ },
180
+ }),
181
+ h("button", { style: S.btnPrimary, onClick: save, disabled: busy || !value.trim() }, busy ? "保存中…" : "就这个"),
182
+ h("button", { style: S.btn, onClick: () => { setValue(self.hostname || ""); } }, "用主机名"),
183
+ editing && !needs ? h("button", { style: S.btnSm, onClick: () => setEditing(false) }, "取消") : null,
184
+ ),
185
+ msg ? h("div", { style: { marginTop: 8, fontSize: 12 } }, msg) : null,
186
+ );
187
+ }
188
+
189
+ function SecretBox({ self, config, onSaved }) {
190
+ const [open, setOpen] = react.useState(false);
191
+ const [reveal, setReveal] = react.useState(false);
192
+ const [paste, setPaste] = react.useState("");
193
+ const [msg, setMsg] = react.useState("");
194
+ const secret = (self && self.secret) || "";
195
+ const required = !!(config && config.requirePairing);
196
+
197
+ const copy = async () => {
198
+ try {
199
+ await navigator.clipboard.writeText(secret);
200
+ setMsg("已复制到剪贴板");
201
+ } catch {
202
+ setMsg("复制失败,请手动选择文本");
203
+ }
204
+ setTimeout(() => setMsg(""), 2500);
205
+ };
206
+
207
+ const save = async () => {
208
+ const r = await call("/secret", { secret: paste.trim() });
209
+ setMsg(r && r.ok ? "已保存,正在重新广播" : `保存失败:${(r && r.error) || "未知错误"}`);
210
+ if (r && r.ok) {
211
+ setPaste("");
212
+ onSaved && onSaved();
213
+ }
214
+ setTimeout(() => setMsg(""), 3000);
215
+ };
216
+
217
+ return h(
218
+ "div",
219
+ { style: S.card },
220
+ h(
221
+ "div",
222
+ { style: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: 8 } },
223
+ h(
224
+ "div",
225
+ null,
226
+ h("span", { style: S.cardTitle }, "配对码"),
227
+ h("span", { style: { ...S.tag, marginLeft: 8 } }, required ? "已启用" : "未启用(默认)"),
228
+ ),
229
+ h("button", { style: S.btnSm, onClick: () => setOpen(!open) }, open ? "收起" : "展开"),
230
+ ),
231
+ h(
232
+ "div",
233
+ { style: { ...S.muted, marginTop: 8 } },
234
+ required
235
+ ? "当前要求两端配对码一致才能互相派发任务。"
236
+ : "默认不需要配对:同一内网发现即可互相派发任务。若你的网络不完全可信(合租/公司/有访客设备),在插件配置里把 requirePairing 设为 true 再回来对码。",
237
+ ),
238
+ open
239
+ ? h(
240
+ "div",
241
+ { style: { marginTop: 14 } },
242
+ h(
243
+ "div",
244
+ { style: S.row },
245
+ h("span", { style: S.muted }, "本机配对码"),
246
+ h("code", { style: { ...S.mono, flex: 1, wordBreak: "break-all" } }, reveal ? secret || "(未生成)" : "•".repeat(Math.min(28, (secret || "").length || 28))),
247
+ h("button", { style: S.btnSm, onClick: () => setReveal(!reveal) }, reveal ? "隐藏" : "显示"),
248
+ h("button", { style: S.btnSm, onClick: copy }, "复制"),
249
+ ),
250
+ h(
251
+ "div",
252
+ { style: { ...S.row, marginTop: 12 } },
253
+ h("input", {
254
+ style: S.input,
255
+ placeholder: "把另一台机器的配对码粘贴到这里,然后点保存",
256
+ value: paste,
257
+ onChange: (e) => setPaste(e.target.value),
258
+ }),
259
+ h("button", { style: S.btn, onClick: save, disabled: paste.trim().length < 16 }, "保存对端配对码"),
260
+ ),
261
+ )
262
+ : null,
263
+ msg ? h("div", { style: { marginTop: 8, fontSize: 12 } }, msg) : null,
264
+ );
265
+ }
266
+
267
+ /**
268
+ * 互联网自组网(Tailscale)卡片。
269
+ *
270
+ * 交互目标:**只有一个必填项**。
271
+ * · 授权码 —— 唯一必填,填一次就存进 state.json(0600),以后不用再填
272
+ * · 控制服务器 —— 只有 Headscale 用户要填,官方用户留空
273
+ * 其余全部自动:节点名取自机器名、二进制按平台下载并校验、进程由插件托管。
274
+ */
275
+ function TsnetCard({ tsnet, onChanged }) {
276
+ const node = tsnet.node || null;
277
+ // 还没启用时默认展开,直接把"授权码"这个入口摆在用户面前
278
+ const [open, setOpen] = react.useState(!tsnet.enabled);
279
+ const [authKey, setAuthKey] = react.useState("");
280
+ const [controlUrl, setControlUrl] = react.useState(tsnet.controlUrl || "");
281
+ const [busy, setBusy] = react.useState("");
282
+ const [msg, setMsg] = react.useState("");
283
+
284
+ react.useEffect(() => {
285
+ setControlUrl(tsnet.controlUrl || "");
286
+ }, [tsnet.controlUrl]);
287
+
288
+ const flash = (m) => {
289
+ setMsg(m);
290
+ setTimeout(() => setMsg(""), 6000);
291
+ };
292
+
293
+ const run = async (label, fn) => {
294
+ setBusy(label);
295
+ try {
296
+ await fn();
297
+ } catch (e) {
298
+ flash(`出错:${(e && e.message) || e}`);
299
+ } finally {
300
+ setBusy("");
301
+ }
302
+ };
303
+
304
+ // 保存后立刻启动:否则用户会以为"保存了却没反应"
305
+ const saveAndStart = () =>
306
+ run("save", async () => {
307
+ const saved = await call("/tsnet/config", {
308
+ authKey: authKey.trim(),
309
+ controlUrl: controlUrl.trim(),
310
+ enabled: true,
311
+ });
312
+ if (!saved || !saved.ok) return flash(`保存失败:${(saved && saved.error) || "未知错误"}`);
313
+ setAuthKey("");
314
+ flash("已保存。授权码只在这里输入一次,之后不再需要。");
315
+ onChanged && onChanged();
316
+ const started = await call("/tsnet/start", {});
317
+ if (started && started.ok) flash("已启动,正在连接…");
318
+ else flash(`启动失败:${(started && started.error) || "未知错误"}`);
319
+ onChanged && onChanged();
320
+ });
321
+
322
+ const phase = node && node.phase ? node.phase : tsnet.enabled ? "idle" : "off";
323
+ const view = {
324
+ off: { text: "未启用", color: "#9aa0a6" },
325
+ idle: { text: "已启用,未启动", color: "#9aa0a6" },
326
+ starting: { text: "正在启动…", color: "#d29922" },
327
+ downloading: { text: `正在下载 sidecar${node && node.downloadPercent ? ` ${node.downloadPercent}%` : ""}…`, color: "#d29922" },
328
+ "needs-login": { text: "需要授权", color: "#d29922" },
329
+ running: { text: `已连接 ${(node && node.selfIpv4) || ""}`.trim(), color: "#2ea043" },
330
+ exited: { text: "进程已退出", color: "#c0392b" },
331
+ error: { text: "出错", color: "#c0392b" },
332
+ }[phase] || { text: phase, color: "#9aa0a6" };
333
+
334
+ const err = (node && node.error) || "";
335
+
336
+ return h(
337
+ "div",
338
+ { style: S.card },
339
+ h(
340
+ "div",
341
+ { style: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: 8 } },
342
+ h(
343
+ "div",
344
+ { style: { display: "flex", alignItems: "center", gap: 8, flexWrap: "wrap" } },
345
+ h("span", { style: S.cardTitle }, "互联网组网(Tailscale)"),
346
+ h("span", { style: { ...S.tag, color: view.color, borderColor: view.color } }, view.text),
347
+ node && node.selfDnsName ? h("span", { style: S.mono }, node.selfDnsName) : null,
348
+ ),
349
+ h("button", { style: S.btnSm, onClick: () => setOpen(!open) }, open ? "收起" : "设置"),
350
+ ),
351
+
352
+ h(
353
+ "div",
354
+ { style: { ...S.muted, marginTop: 8 } },
355
+ "跨互联网也能互相发现和派任务,和局域网是同一套用法。",
356
+ "不需要安装 Tailscale 客户端,也不需要装 Go —— sidecar 会按平台自动下载。",
357
+ ),
358
+
359
+ // 需要登录时把授权链接摆在最显眼的位置,不用点开设置
360
+ node && node.authUrl
361
+ ? h(
362
+ "div",
363
+ { style: { marginTop: 10, padding: "8px 10px", border: "1px solid #d29922", borderRadius: 7, fontSize: 13 } },
364
+ "需要你授权这台机器加入 tailnet:",
365
+ h(
366
+ "a",
367
+ { href: node.authUrl, target: "_blank", rel: "noreferrer", style: { marginLeft: 6, color: "inherit", wordBreak: "break-all" } },
368
+ node.authUrl,
369
+ ),
370
+ )
371
+ : null,
372
+
373
+ err ? h("div", { style: { ...S.muted, marginTop: 8, color: "#c0392b" } }, err) : null,
374
+
375
+ open
376
+ ? h(
377
+ "div",
378
+ { style: { marginTop: 14 } },
379
+ h(
380
+ "div",
381
+ { style: S.row },
382
+ h("input", {
383
+ style: S.input,
384
+ type: "password",
385
+ autoComplete: "off",
386
+ placeholder: tsnet.authKeySaved ? "授权码已保存 —— 留空则沿用,粘贴新值可替换" : "粘贴 Tailscale 授权码(tskey-auth-…)",
387
+ value: authKey,
388
+ onChange: (e) => setAuthKey(e.target.value),
389
+ }),
390
+ h("button", { style: S.btnPrimary, onClick: saveAndStart, disabled: busy === "save" }, busy === "save" ? "处理中…" : tsnet.enabled ? "保存并重启" : "保存并启动"),
391
+ ),
392
+ h(
393
+ "div",
394
+ { style: { ...S.muted, marginTop: 6 } },
395
+ tsnet.authKeySaved ? "✓ 授权码已保存在本机(state.json,权限 0600),只会在这里输入一次。" : "在 Tailscale 后台 Settings → Keys 生成,勾选 Reusable 与 Pre-approved。",
396
+ ),
397
+
398
+ h(
399
+ "div",
400
+ { style: { ...S.row, marginTop: 12 } },
401
+ h("input", {
402
+ style: S.input,
403
+ placeholder: "控制服务器地址(留空 = 官方 Tailscale;Headscale 用户填自己的)",
404
+ value: controlUrl,
405
+ onChange: (e) => setControlUrl(e.target.value),
406
+ }),
407
+ ),
408
+
409
+ h(
410
+ "div",
411
+ { style: { ...S.row, marginTop: 12 } },
412
+ tsnet.enabled
413
+ ? h("button", { style: S.btn, onClick: () => run("stop", async () => { await call("/tsnet/stop", {}); flash("已停止"); onChanged && onChanged(); }), disabled: !!busy }, "停止")
414
+ : h("button", { style: S.btn, onClick: () => run("start", async () => { const r = await call("/tsnet/start", {}); flash(r && r.ok ? "已启动" : `启动失败:${(r && r.error) || "未知错误"}`); onChanged && onChanged(); }), disabled: !!busy }, "启动"),
415
+ h("button", { style: S.btnSm, onClick: () => run("scan", async () => { const r = await call("/tsnet/scan", {}); flash(r && r.ok ? `扫描完成:命中 ${r.found ?? 0} 台` : "扫描失败"); onChanged && onChanged(); }), disabled: !!busy || !tsnet.enabled }, "扫描 tailnet"),
416
+ h("button", { style: S.btnSm, onClick: () => run("relogin", async () => { const r = await call("/tsnet/relogin", {}); flash(r && r.ok ? "已清除节点身份,等待重新授权" : `失败:${(r && r.error) || "未知错误"}`); onChanged && onChanged(); }), disabled: !!busy || !tsnet.enabled }, "重新登录"),
417
+ h("button", { style: S.btnSm, onClick: () => run("reinstall", async () => { const r = await call("/tsnet/reinstall", {}); flash(r && r.ok ? "已重新下载 sidecar" : `失败:${(r && r.error) || "未知错误"}`); onChanged && onChanged(); }), disabled: !!busy || !tsnet.enabled }, "重新下载"),
418
+ ),
419
+
420
+ h(
421
+ "div",
422
+ { style: { ...S.muted, marginTop: 10 } },
423
+ `节点名 ${tsnet.hostname || node?.hostname || "(自动取自机器名)"}`,
424
+ node && node.pid ? ` · 进程 ${node.pid}` : "",
425
+ ` · 对端权限 ${tsnet.permissionPresetEffective || "与局域网一致"}`,
426
+ node && node.binary && node.binary.installed ? ` · sidecar ${(node.binary.size / 1048576).toFixed(1)}MB` : "",
427
+ ),
428
+
429
+ (node && node.diagnostics && node.diagnostics.length) || (node && node.recentEvents && node.recentEvents.length)
430
+ ? h(
431
+ "div",
432
+ { style: { ...S.log, marginTop: 10 } },
433
+ (node.recentEvents || []).slice(-8).map((ev, i) =>
434
+ h("div", { key: i, style: S.logRow }, `${new Date(ev.at).toLocaleTimeString()} ${ev.event}${ev.message ? " " + ev.message : ""}${ev.url ? " " + ev.url : ""}`),
435
+ ),
436
+ )
437
+ : null,
438
+ )
439
+ : null,
440
+
441
+ msg ? h("div", { style: { marginTop: 8, fontSize: 12 } }, msg) : null,
442
+ );
443
+ }
444
+
445
+ /**
446
+ * 「这台机器能干什么」——Placement 第 2 步的展示层。
447
+ *
448
+ * 三种「不知道」必须**分开显示**,绝不能都渲染成「什么都没装」:
449
+ * · 对端没报能力 → 明说「未知」(老版本插件 / 还没采集完)
450
+ * · 报过但已过期 → 标「能力已过期」,仍展示但仅供参考
451
+ * · 有探测项没探准 → 标「探测未探准」,并说明此处的「缺失」不能当结论
452
+ *
453
+ * 混起来显示的后果很具体:用户看到一台没有任何运行时的机器,会把任务派到
454
+ * 跑不了的机器上;而真正的原因(对端没报 / 探测超时)反而完全看不见。
455
+ */
456
+ function CapabilityLine({ peer }) {
457
+ const caps = peer && peer.capabilities;
458
+ if (!caps) {
459
+ return h(
460
+ "div",
461
+ { style: { ...S.muted, marginTop: 4 } },
462
+ "能力:未知(对端未上报;可能是旧版本插件,或还没采集完)",
463
+ );
464
+ }
465
+
466
+ // 形状校验不能省:`Object.entries("nope")` 会给出 ["0","n"],["1","o"]…
467
+ // 于是坏数据会被渲染成一串莫名其妙的徽章,而不是干净地降级。
468
+ // (正常路径上主机侧已经净化过,但渲染函数应该是全函数。)
469
+ const rtRaw = caps.runtimes;
470
+ const runtimes =
471
+ rtRaw && typeof rtRaw === "object" && !Array.isArray(rtRaw) ? Object.entries(rtRaw) : [];
472
+ const badges = runtimes.map(([name, ver]) =>
473
+ h(
474
+ "span",
475
+ { key: `rt-${name}`, style: { ...S.tag, color: "#1a7f37", borderColor: "#8cd19d" } },
476
+ `${name} ${ver}`,
477
+ ),
478
+ );
479
+
480
+ const specs = [];
481
+ if (caps.cpuCores) specs.push(`${caps.cpuCores} 核`);
482
+ if (caps.memMb) specs.push(`${Math.round(caps.memMb / 1024)} GB 内存`);
483
+ if (caps.arch) specs.push(caps.arch);
484
+
485
+ const hints = caps.workspaceHints || [];
486
+ // 悬停给出完整信息:徽章只放最需要一眼看到的东西
487
+ const tip = [
488
+ `操作系统:${caps.os || "?"}`,
489
+ `运行时:${runtimes.length ? runtimes.map(([k, v]) => `${k} ${v}`).join("、") : "(未探到)"}`,
490
+ caps.gpu && caps.gpu.name
491
+ ? `显卡:${caps.gpu.name}${caps.gpu.vramMb ? ` ${caps.gpu.vramMb}MB` : ""}`
492
+ : "显卡:未探到或没有独立显卡",
493
+ hints.length ? `常用目录:${hints.join(" ")}` : "",
494
+ caps.capabilitiesAt ? `采集于 ${new Date(caps.capabilitiesAt).toLocaleString()}` : "采集时间未知",
495
+ ]
496
+ .filter(Boolean)
497
+ .join("\n");
498
+
499
+ return h(
500
+ "div",
501
+ {
502
+ style: { display: "flex", gap: 6, flexWrap: "wrap", alignItems: "center", marginTop: 5 },
503
+ title: tip,
504
+ },
505
+ badges.length ? badges : h("span", { style: S.muted }, "未探到运行时"),
506
+ caps.gpu && caps.gpu.name
507
+ ? h("span", { style: { ...S.tag, color: "#8250df", borderColor: "#c9a7f5" } }, `GPU ${caps.gpu.name}`)
508
+ : null,
509
+ specs.length ? h("span", { style: S.muted }, specs.join(" / ")) : null,
510
+ peer.capabilitiesStale
511
+ ? h(
512
+ "span",
513
+ {
514
+ style: { ...S.tag, color: "#bf8700", borderColor: "#e0b64a" },
515
+ title: "对端的能力名片太旧了,可能已经不准(比如中途装了新运行时)",
516
+ },
517
+ "能力已过期",
518
+ )
519
+ : null,
520
+ caps.runtimesIncomplete
521
+ ? h(
522
+ "span",
523
+ {
524
+ style: { ...S.tag, color: "#bf8700", borderColor: "#e0b64a" },
525
+ title:
526
+ "对端有探测项没探准(多半是它当时机器忙、探测超时)。" +
527
+ "所以这里「没有某个运行时」不能当结论用 —— 别据此排除这台机器。",
528
+ },
529
+ "探测未探准",
530
+ )
531
+ : null,
532
+ );
533
+ }
534
+
535
+ function PeerRow({ peer, onSend, onProbe, probe }) {
536
+ const target = peer.machine;
537
+ return h(
538
+ "div",
539
+ { style: S.peer },
540
+ h("div", { style: S.dot(peer.online) }),
541
+ h(
542
+ "div",
543
+ { style: { flex: 1, minWidth: 0 } },
544
+ h(
545
+ "div",
546
+ { style: { display: "flex", gap: 8, alignItems: "center", flexWrap: "wrap" } },
547
+ h("strong", null, peer.machine),
548
+ peer.online ? null : h("span", { style: S.tag }, "离线"),
549
+ // 一台设备可能同时有局域网与互联网两条通道,任意一条通就算可达。
550
+ peer.endpoints
551
+ ? h(
552
+ "span",
553
+ { style: { ...S.muted, ...S.mono } },
554
+ `${peer.host || "?"}:${peer.port || "?"}`,
555
+ )
556
+ : h("span", { style: { ...S.muted, ...S.mono } }, `${peer.host}:${peer.port}`),
557
+ ),
558
+ // ── 通道明细 ──
559
+ //
560
+ // 一台设备可能同时有局域网与互联网两条通道,而且**任意一条通就算可达**。
561
+ // 把每条都摆出来并标出"当前在用哪条",否则某条通道断掉时只能靠猜
562
+ // (今天在 dispatch-failed 上已经吃过一次这个亏)。
563
+ (peer.endpoints || []).length > 0
564
+ ? h(
565
+ "div",
566
+ { style: { display: "flex", gap: 6, flexWrap: "wrap", marginTop: 5 } },
567
+ (peer.endpoints || []).map((ep) => {
568
+ const cooling = !!(ep.downUntil && Date.now() < ep.downUntil);
569
+ const unverified = ep.verified === false;
570
+ const active = ep.transport === peer.transport;
571
+ const color = active ? "#2ea043" : cooling ? "#c0392b" : unverified ? "#9aa0a6" : "#666";
572
+ const cname = ep.transport === "tsnet" ? "互联网" : "局域网";
573
+ const cstate = active ? "在用" : cooling ? "冷却中" : unverified ? "未探测" : "备用";
574
+ return h(
575
+ "span",
576
+ {
577
+ key: ep.transport,
578
+ style: { ...S.tag, color, borderColor: color, ...(active ? { fontWeight: 600 } : null) },
579
+ title:
580
+ `${cname} ${ep.host}:${ep.port} · ${cstate}` +
581
+ (ep.rttMs ? ` · ${ep.rttMs}ms` : "") +
582
+ ` · 成功 ${ep.okCount} 次 / 失败 ${ep.failCount} 次`,
583
+ },
584
+ `${cname} ${cstate}`,
585
+ );
586
+ }),
587
+ )
588
+ : null,
589
+ h(
590
+ "div",
591
+ { style: S.muted },
592
+ `${peer.os || "?"} · user=${peer.user || "?"}`,
593
+ peer.profile ? ` · profile=${peer.profile}` : "",
594
+ ` · 最后心跳 ${new Date(peer.lastSeen).toLocaleTimeString()}`,
595
+ ),
596
+ // 这台机器能干什么 —— 决定任务该派给谁的依据
597
+ h(CapabilityLine, { peer }),
598
+ peer.hostname || peer.mac
599
+ ? h(
600
+ "div",
601
+ { style: { ...S.mono, ...S.muted, fontSize: 11 } },
602
+ [peer.hostname ? `hostname=${peer.hostname} ` : "", peer.mac ? `mac=${peer.mac}` : ""],
603
+ )
604
+ : null,
605
+ probe && probe.machine === target
606
+ ? h(
607
+ "div",
608
+ { style: { ...S.mono, marginTop: 4, color: probe.reachable ? (probe.paired ? "#2ea043" : "#bf8700") : "#c0392b" } },
609
+ probe.reachable ? (probe.paired ? "✓ 可达且已配对" : "⚠ 可达但配对码不一致,无法派发") : `✗ 不可达:${probe.error || ""}`,
610
+ )
611
+ : null,
612
+ ),
613
+ h("button", { style: S.btnSm, onClick: () => onProbe(target) }, "探测"),
614
+ h("button", { style: S.btnSm, onClick: () => onSend(target), disabled: !peer.online }, "派发任务"),
615
+ );
616
+ }
617
+
618
+ /**
619
+ * 限速提示卡:某个 thread 撞到唤醒上限时,让用户决定要不要提高上限。
620
+ *
621
+ * 为什么要有这个:限速是为了防两个 agent 互相回执停不下来,但正常的
622
+ * 长线程也可能撞上。所以不静默丢弃,而是把选择权交回用户:
623
+ * 「提高上限」→ 调高该 thread 的窗口上限,并立刻放行最新一条;
624
+ * 「忽略」→ 只清提示,上限不变,被挡的任务仍留在收件箱。
625
+ */
626
+ function ThrottleCard({ items, onDone }) {
627
+ const [busy, setBusy] = react.useState("");
628
+ if (!items || items.length === 0) return null;
629
+
630
+ const raise = async (thread) => {
631
+ setBusy(thread);
632
+ const r = await call("/throttle/raise", { thread });
633
+ setBusy("");
634
+ onDone(
635
+ r && r.ok
636
+ ? `已把 ${thread} 的上限提到 ${r.cap}${r.replayed ? `,并放行最新一条(其余 ${r.remaining} 条仍在收件箱)` : ""}`
637
+ : `提高上限失败:${(r && r.error) || "未知错误"}`,
638
+ );
639
+ };
640
+
641
+ const dismiss = async (thread) => {
642
+ setBusy(thread);
643
+ await call("/throttle/dismiss", { thread });
644
+ setBusy("");
645
+ onDone(`已忽略 ${thread} 的限速提示(上限不变,被挡的任务仍在收件箱)`);
646
+ };
647
+
648
+ return h(
649
+ "div",
650
+ { style: { ...S.card, borderColor: "#d29922" } },
651
+ h("div", { style: S.cardTitle }, "⚠ 有 thread 撞到唤醒上限,已暂停自动唤醒"),
652
+ h(
653
+ "div",
654
+ { style: { ...S.muted, marginBottom: 12 } },
655
+ "这是防「两个 agent 互相回执停不下来」的限速。下面这些线程在窗口内已用满配额," +
656
+ "新消息仍收进收件箱、但不会自动开跑 —— 你可以决定是否放宽。",
657
+ ),
658
+ items.map((it) =>
659
+ h(
660
+ "div",
661
+ { key: it.thread, style: { ...S.row, justifyContent: "space-between", padding: "8px 0", borderTop: "1px solid var(--dsw-alias-border-secondary, #eee)" } },
662
+ h(
663
+ "div",
664
+ null,
665
+ h("div", { style: { fontWeight: 600 } }, it.thread, it.overridden ? h("span", { style: { ...S.muted, fontWeight: 400 } }, "(已手动提高过)") : null),
666
+ h(
667
+ "div",
668
+ { style: S.muted },
669
+ `上限 ${it.cap} 次 / ${Math.round(it.windowMs / 60000)} 分钟 · 已挡下 ${it.blocked} 条`,
670
+ it.overridden ? ` · 配置默认 ${it.defaultCap}` : "",
671
+ ),
672
+ ),
673
+ h(
674
+ "div",
675
+ { style: S.row },
676
+ h(
677
+ "button",
678
+ { style: S.btnSm, disabled: busy === it.thread, onClick: () => raise(it.thread) },
679
+ busy === it.thread ? "处理中…" : "提高上限并放行最新一条",
680
+ ),
681
+ h("button", { style: S.btnSm, disabled: busy === it.thread, onClick: () => dismiss(it.thread) }, "忽略"),
682
+ ),
683
+ ),
684
+ ),
685
+ );
686
+ }
687
+
688
+ function MeshPage() {
689
+ const { state, error } = useMeshState(3000);
690
+ const [target, setTarget] = react.useState("");
691
+ const [task, setTask] = react.useState("");
692
+ const [thread, setThread] = react.useState("");
693
+ const [busy, setBusy] = react.useState(false);
694
+ const [toast, setToast] = react.useState("");
695
+ const [probe, setProbe] = react.useState(null);
696
+ const [tab, setTab] = react.useState("peers");
697
+ const [scanning, setScanning] = react.useState(false);
698
+
699
+ const refresh = async () => {
700
+ await call("/refresh", {});
701
+ };
702
+
703
+ const doScan = async () => {
704
+ setScanning(true);
705
+ setToast("正在扫描本网段的 " + ((state && state.self && state.self.port) || "") + " 端口…");
706
+ const r = await call("/scan", {});
707
+ setScanning(false);
708
+ setToast(
709
+ r && r.ok
710
+ ? `扫描完成:探测 ${r.scanned} 个地址,命中 ${r.found} 台`
711
+ : `扫描失败:${(r && r.error) || "未知错误"}`,
712
+ );
713
+ setTimeout(() => setToast(""), 4000);
714
+ };
715
+
716
+ const doProbe = async (machine) => {
717
+ setProbe({ machine, pending: true });
718
+ const r = await call("/probe", { peer: machine });
719
+ setProbe({ machine, ...r });
720
+ };
721
+
722
+ const doSend = async () => {
723
+ if (!target || !task.trim()) return;
724
+ setBusy(true);
725
+ const r = await call("/send", { peer: target, task, thread });
726
+ setBusy(false);
727
+ setToast(r && r.ok ? `已派发给 ${target}(id ${r.id})—— 对端会在它自己的会话里执行` : `派发失败:${(r && r.error) || "未知错误"}`);
728
+ if (r && r.ok) setTask("");
729
+ setTimeout(() => setToast(""), 5000);
730
+ };
731
+
732
+ if (error && !state) {
733
+ return h("div", { style: S.page }, h("div", { style: S.pageInner }, h("h1", { style: S.h1 }, "局域网 Mesh"), h("div", { style: S.card }, `无法读取本机 mesh 状态:${error}`, h("div", { style: { ...S.muted, marginTop: 8 } }, "请确认主机侧插件 dsh-plugin-mesh 已加载。"))));
734
+ }
735
+ if (!state) return h("div", { style: S.page }, h("div", { style: S.pageInner }, "正在加载…"));
736
+
737
+ // 主机侧出错时 /mesh/api/state 返回的是 {ok:false, error},没有 self。
738
+ // 之前这里会静默渲染成「本机 undefined · undefined:undefined」,把真正的原因
739
+ // 整个藏起来(实测踩过:Android 上 detectTarget 抛异常,整页变成 undefined,
740
+ // 却看不出为什么)。所以显式把错误摆到页面上。
741
+ if (state.ok === false) {
742
+ return h(
743
+ "div",
744
+ { style: S.page },
745
+ h(
746
+ "div",
747
+ { style: S.pageInner },
748
+ h("h1", { style: S.h1 }, "局域网 Mesh"),
749
+ h(
750
+ "div",
751
+ { style: { ...S.card, borderColor: "#c0392b" } },
752
+ "主机侧返回错误,无法读取状态:",
753
+ h("div", { style: { ...S.mono, marginTop: 8, wordBreak: "break-all" } }, String(state.error || "(未提供错误信息)")),
754
+ h("div", { style: { ...S.muted, marginTop: 8 } }, "请把这段错误原文发给开发者。"),
755
+ ),
756
+ ),
757
+ );
758
+ }
759
+
760
+ const self = state.self || {};
761
+ const cfg = state.config || {};
762
+ const peers = state.peers || [];
763
+ const online = peers.filter((p) => p.online);
764
+
765
+ return h(
766
+ "div",
767
+ { style: S.page },
768
+ h(
769
+ "div",
770
+ { style: S.pageInner },
771
+ h("h1", { style: S.h1 }, "局域网 Mesh"),
772
+ h(
773
+ "div",
774
+ { style: S.sub },
775
+ `本机 ${self.machine} · ${self.host}:${self.port} · 发现 ${peers.length} 台,在线 ${online.length} 台`,
776
+ h("br"),
777
+ h("span", { style: { ...S.mono, fontSize: 11 } }, `hostname=${self.hostname || "?"}${self.mac ? " · mac=" + self.mac : ""}`),
778
+ h("br"),
779
+ h(
780
+ "span",
781
+ { style: { fontSize: 12 } },
782
+ `发现方式:${cfg.useMulticast === false ? "主动扫描" : "组播 + 扫描"}`,
783
+ cfg.scanIntervalMs ? `(每 ${Math.round(cfg.scanIntervalMs / 1000)}s 重扫)` : "",
784
+ cfg.pingIntervalMs ? ` · ping 保活每 ${Math.round(cfg.pingIntervalMs / 1000)}s` : "",
785
+ ` · 配对要求:${cfg.requirePairing ? "开" : "关"}`,
786
+ ),
787
+ ),
788
+
789
+ toast ? h("div", { style: { ...S.card, borderColor: "#2ea043" } }, toast) : null,
790
+
791
+ h(ThrottleCard, { items: state.throttled || [], onDone: (msg) => { setToast(msg); setTimeout(() => setToast(""), 6000); } }),
792
+
793
+ h(NameCard, { self, onSaved: refresh }),
794
+
795
+ (state.duplicateNames || []).length > 0
796
+ ? h(
797
+ "div",
798
+ { style: { ...S.card, borderColor: "#c0392b" } },
799
+ `⚠ 有重名:${state.duplicateNames.join("、")}。派任务时会因为分不清目标而失败,请给其中一台改名。`,
800
+ )
801
+ : null,
802
+
803
+ h(SecretBox, { self, config: cfg, onSaved: refresh }),
804
+
805
+ // 旧版主机端不会返回 state.tsnet,所以这里做存在性判断,避免升级不同步时报错
806
+ state.tsnet ? h(TsnetCard, { tsnet: state.tsnet, onChanged: refresh }) : null,
807
+
808
+ h(
809
+ "div",
810
+ { style: S.card },
811
+ h(
812
+ "div",
813
+ { style: { display: "flex", justifyContent: "space-between", alignItems: "center" } },
814
+ h("div", { style: S.cardTitle }, "发现的机器"),
815
+ h(
816
+ "div",
817
+ { style: S.row },
818
+ h("button", { style: S.btnSm, onClick: doScan, disabled: scanning }, scanning ? "扫描中…" : "扫描本网段"),
819
+ h("button", { style: S.btnSm, onClick: refresh }, "重新广播"),
820
+ h("button", { style: S.btnSm, onClick: () => setTab(tab === "peers" ? "tasks" : "peers") }, tab === "peers" ? "看任务记录" : "看机器列表"),
821
+ ),
822
+ ),
823
+ // 本机也能干什么 —— 和下面每台对端并排看,才知道"这活该放哪"
824
+ h(
825
+ "div",
826
+ { style: { ...S.peer, flexDirection: "column", alignItems: "stretch", background: "var(--dsw-alias-bg-base, #fafbfc)" } },
827
+ h(
828
+ "div",
829
+ { style: { display: "flex", gap: 8, alignItems: "center", flexWrap: "wrap" } },
830
+ h("span", { style: S.tag }, "本机"),
831
+ h("strong", null, self.machine || "?"),
832
+ h("span", { style: { ...S.muted, ...S.mono } }, `${self.host || "?"}:${self.port || "?"}`),
833
+ ),
834
+ // self 没有 capabilitiesStale(本机的能力是现算的,不存在过期)
835
+ h(CapabilityLine, { peer: { capabilities: self.capabilities || null } }),
836
+ ),
837
+ tab === "peers"
838
+ ? peers.length === 0
839
+ ? h(
840
+ "div",
841
+ { style: S.muted },
842
+ "还没有发现其他 DSH。点上面的「扫描本网段」试一次;若仍没有,对照检查:",
843
+ h(
844
+ "ul",
845
+ { style: { margin: "6px 0 0 18px", padding: 0 } },
846
+ h("li", null, "两台机器在同一网段吗"),
847
+ h("li", null, `对端也装了 dsh-plugin-mesh、并且用的是同一个端口(本机 ${self.port})吗`),
848
+ h("li", null, "对端防火墙是否放行这个 TCP 端口(以及 UDP 45892 组播)"),
849
+ ),
850
+ )
851
+ : peers.map((p) =>
852
+ h(PeerRow, {
853
+ key: p.id,
854
+ peer: p,
855
+ onProbe: doProbe,
856
+ onSend: (m) => {
857
+ setTarget(m);
858
+ },
859
+ probe,
860
+ }),
861
+ )
862
+ : null,
863
+ ),
864
+
865
+ h(
866
+ "div",
867
+ { style: S.card },
868
+ h("div", { style: S.cardTitle }, "派发任务"),
869
+ h(
870
+ "div",
871
+ { style: { ...S.row, marginBottom: 8 } },
872
+ h(
873
+ "select",
874
+ { style: { ...S.input, flex: "0 0 220px" }, value: target, onChange: (e) => setTarget(e.target.value) },
875
+ h("option", { value: "" }, "选择目标机器…"),
876
+ online.map((p) => h("option", { key: p.id, value: p.machine }, `${p.machine} (${p.host})`)),
877
+ ),
878
+ h("input", { style: { ...S.input, flex: "0 0 180px" }, placeholder: "线程标识(可选)", value: thread, onChange: (e) => setThread(e.target.value) }),
879
+ ),
880
+ h("textarea", { style: S.textarea, placeholder: "要对方 agent 做什么?例如:拉取最新代码,重新构建并重启 web 服务,然后回报结果。", value: task, onChange: (e) => setTask(e.target.value) }),
881
+ h(
882
+ "div",
883
+ { style: { ...S.row, marginTop: 10, justifyContent: "space-between" } },
884
+ h("div", { style: S.muted }, "异步:派发只代表对方已接收,结果会由对端 agent 回派。"),
885
+ h("button", { style: S.btnPrimary, onClick: doSend, disabled: busy || !target || !task.trim() }, busy ? "派发中…" : "派发"),
886
+ ),
887
+ ),
888
+
889
+ tab === "tasks"
890
+ ? h(
891
+ "div",
892
+ { style: S.card },
893
+ h("div", { style: S.cardTitle }, "收到的任务(对端派给本机)"),
894
+ h(
895
+ "div",
896
+ { style: S.log },
897
+ (state.inbound || []).length === 0
898
+ ? h("div", { style: S.muted }, "(无)")
899
+ : state.inbound.map((t) => h("div", { key: t.id, style: S.logRow }, h("code", { style: S.mono }, `[${t.id}]`), ` ${t.status} `, h("strong", null, t.from), " — ", String(t.task).slice(0, 120))),
900
+ ),
901
+ h("div", { style: { ...S.cardTitle, marginTop: 18 } }, "派出的任务"),
902
+ h(
903
+ "div",
904
+ { style: S.log },
905
+ (state.outbound || []).length === 0
906
+ ? h("div", { style: S.muted }, "(无)")
907
+ : state.outbound.map((t, i) => h("div", { key: `${t.id}-${i}`, style: S.logRow }, h("code", { style: S.mono }, `[${t.id}]`), ` → ${t.toMachine} ${t.ok ? "已送达" : "失败"} `, String(t.task).slice(0, 100))),
908
+ ),
909
+ )
910
+ : null,
911
+ ),
912
+ );
913
+ }
914
+
915
+ /** 侧栏图标;props: {size, active} */
916
+ function MeshIcon(props) {
917
+ const size = (props && props.size) || 16;
918
+ return h(
919
+ "svg",
920
+ { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round" },
921
+ h("circle", { cx: 12, cy: 5, r: 2.4 }),
922
+ h("circle", { cx: 5.5, cy: 18, r: 2.4 }),
923
+ h("circle", { cx: 18.5, cy: 18, r: 2.4 }),
924
+ h("path", { d: "M12 7.4 6.6 15.8M12 7.4l5.4 8.4M7.9 18h8.2" }),
925
+ );
926
+ }
927
+
928
+ // ─────────────────────── 注册 ───────────────────────
929
+
930
+ function apply(ctx) {
931
+ // 侧栏面板入口
932
+ ctx.slots.inject("sidebar.panellist", () =>
933
+ ctx.slots.register(
934
+ { name: "sidebar.panellist", id: PANEL_ID, order: 50, label: "Mesh" },
935
+ MeshIcon,
936
+ ),
937
+ );
938
+
939
+ // 面板内容:layout 的 MainPanel 用 activePanelId 作 key 取 main 槽
940
+ ctx.slots.inject("main", () =>
941
+ ctx.slots.register({ name: "main", key: PANEL_ID }, MeshPage),
942
+ );
943
+
944
+ ctx.logger?.info?.("mesh client: 已注册侧栏面板 Mesh");
945
+ }
946
+
947
+ exports.apply = apply;
948
+ exports.inject = inject;
949
+ // 仅供仓库内自测(`lib/_selftest-client.mjs`)。浏览器侧只读 apply/inject。
950
+ //
951
+ // 为什么要有这个出口:这是个**手写 bundle、没有构建步骤**,而这个安装里
952
+ // 也没有 react-dom,所以没有别的方式在无浏览器环境下验证渲染逻辑。
953
+ // 组件都是纯函数(CapabilityLine 不用 hook),拿 createElement 的返回树
954
+ // 直接走一遍就能断言文案与标记 —— 比"看代码觉得对"强得多。
955
+ exports.__test = { CapabilityLine, PeerRow, MeshPage };
956
+ return module.exports;
957
+ },
958
+ });