dsh-plugin-mesh 0.5.7 → 0.5.8
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.md +68 -6
- package/client/client.js +270 -30
- package/cordis.patch.yml +4 -0
- package/lib/_selftest-at-mention-host.mjs +377 -0
- package/lib/_selftest-at-mention.mjs +168 -0
- package/lib/_selftest-prompt.mjs +7 -0
- package/lib/_selftest-reply-route.mjs +49 -1
- package/lib/_selftest-update.mjs +9 -0
- package/lib/_selftest-upgrade.mjs +619 -0
- package/lib/_selftest-workbench.mjs +130 -20
- package/lib/at-mention.js +109 -0
- package/lib/index.js +501 -98
- package/lib/prompt.js +5 -1
- package/lib/update.js +3 -0
- package/lib/upgrade.js +635 -0
- package/llms.txt +3 -1
- package/package.json +7 -4
- package/scripts/check-tdz.mjs +1 -1
|
@@ -1143,14 +1143,133 @@ test("检查更新:没点之前就是一个小字,点了先说「检查中
|
|
|
1143
1143
|
const idle = textOf(UpdateLink({ push: noop })).join(" ");
|
|
1144
1144
|
assert.ok(idle.includes("检查更新"), idle);
|
|
1145
1145
|
assert.ok(!idle.includes("已是最新"), "没查过就不能有任何结论");
|
|
1146
|
-
const checking = textOf(UpdateLinkView({ phase: "checking", report: null,
|
|
1146
|
+
const checking = textOf(UpdateLinkView({ phase: "checking", report: null, install: null, onCheck: noop })).join(" ");
|
|
1147
1147
|
assert.ok(checking.includes("检查中"), checking);
|
|
1148
1148
|
});
|
|
1149
1149
|
|
|
1150
|
-
test("
|
|
1151
|
-
const txt = textOf(
|
|
1150
|
+
test("有更新:一行小字「新版本 v0.6.0」,不铺命令、不占卡片", () => {
|
|
1151
|
+
const txt = textOf(
|
|
1152
|
+
UpdateLinkView({ phase: "done", report: updateReport, install: null, onCheck: noop, onInstall: noop }),
|
|
1153
|
+
).join(" ");
|
|
1152
1154
|
assert.ok(txt.includes("新版本 v0.6.0"), txt);
|
|
1153
|
-
assert.ok(!txt.includes("curl"), "
|
|
1155
|
+
assert.ok(!txt.includes("curl"), "升级命令不再铺在页面上");
|
|
1156
|
+
});
|
|
1157
|
+
|
|
1158
|
+
test("一键安装:第一次点只是确认,第二次点才真的开始装", () => {
|
|
1159
|
+
let installed = 0;
|
|
1160
|
+
const view = (install) =>
|
|
1161
|
+
UpdateLinkView({
|
|
1162
|
+
phase: "done",
|
|
1163
|
+
report: updateReport,
|
|
1164
|
+
install,
|
|
1165
|
+
onCheck: noop,
|
|
1166
|
+
onInstall: () => {
|
|
1167
|
+
installed += 1;
|
|
1168
|
+
},
|
|
1169
|
+
});
|
|
1170
|
+
const findInstallBtn = (el) => {
|
|
1171
|
+
let btn = null;
|
|
1172
|
+
walk(el, (n) => {
|
|
1173
|
+
if (n.type === "button" && textOf(n).join("").includes("确认安装")) btn = n;
|
|
1174
|
+
});
|
|
1175
|
+
return btn;
|
|
1176
|
+
};
|
|
1177
|
+
const armed = view({ state: "armed", error: "" });
|
|
1178
|
+
const btn = findInstallBtn(armed);
|
|
1179
|
+
assert.ok(btn, "确认态要有一个「确认安装 v0.6.0」按钮");
|
|
1180
|
+
btn.props.onClick();
|
|
1181
|
+
assert.equal(installed, 1, "点击确认后才调用安装");
|
|
1182
|
+
});
|
|
1183
|
+
|
|
1184
|
+
test("安装中 / 安装失败:状态写在字面上,失败不悄悄回到「有新版本」", () => {
|
|
1185
|
+
const running = textOf(
|
|
1186
|
+
UpdateLinkView({ phase: "done", report: updateReport, install: { state: "running" }, onCheck: noop, onInstall: noop }),
|
|
1187
|
+
).join(" ");
|
|
1188
|
+
assert.ok(running.includes("安装中"), running);
|
|
1189
|
+
|
|
1190
|
+
let retried = 0;
|
|
1191
|
+
const failed = UpdateLinkView({
|
|
1192
|
+
phase: "done",
|
|
1193
|
+
report: updateReport,
|
|
1194
|
+
install: { state: "failed", error: "sha512 校验失败" },
|
|
1195
|
+
onCheck: noop,
|
|
1196
|
+
onInstall: () => {
|
|
1197
|
+
retried += 1;
|
|
1198
|
+
},
|
|
1199
|
+
});
|
|
1200
|
+
const txt = textOf(failed).join(" ");
|
|
1201
|
+
assert.ok(txt.includes("安装失败"), txt);
|
|
1202
|
+
assert.ok(!txt.includes("新版本 v0.6.0"), "失败时不能又显示成普通的新版本入口");
|
|
1203
|
+
let failBtn = null;
|
|
1204
|
+
walk(failed, (n) => {
|
|
1205
|
+
if (n.type === "button" && textOf(n).join("").includes("安装失败")) failBtn = n;
|
|
1206
|
+
});
|
|
1207
|
+
assert.ok(failBtn, "失败后要能点一下重试");
|
|
1208
|
+
assert.ok(String(failBtn.props.title).includes("sha512 校验失败"), String(failBtn.props.title));
|
|
1209
|
+
failBtn.props.onClick();
|
|
1210
|
+
assert.equal(retried, 1);
|
|
1211
|
+
});
|
|
1212
|
+
|
|
1213
|
+
test("已安装待重启:只给「重启生效」,不再给安装入口", () => {
|
|
1214
|
+
let restarted = 0;
|
|
1215
|
+
const report = {
|
|
1216
|
+
...updateReport,
|
|
1217
|
+
diskVersion: "0.6.0",
|
|
1218
|
+
versionDrift: true,
|
|
1219
|
+
pendingUpgrade: { version: "0.6.0", previous: "0.5.6", at: "", restartRequired: true, reloadRequired: false },
|
|
1220
|
+
};
|
|
1221
|
+
const el = UpdateLinkView({
|
|
1222
|
+
phase: "done",
|
|
1223
|
+
report,
|
|
1224
|
+
install: null,
|
|
1225
|
+
onCheck: noop,
|
|
1226
|
+
onInstall: noop,
|
|
1227
|
+
onRestart: () => {
|
|
1228
|
+
restarted += 1;
|
|
1229
|
+
},
|
|
1230
|
+
});
|
|
1231
|
+
const txt = textOf(el).join(" ");
|
|
1232
|
+
assert.ok(txt.includes("已安装 v0.6.0"), txt);
|
|
1233
|
+
assert.ok(txt.includes("重启生效"), txt);
|
|
1234
|
+
assert.ok(!txt.includes("新版本 v0.6.0"), "装好之后不该再提示再装一次");
|
|
1235
|
+
let btn = null;
|
|
1236
|
+
walk(el, (n) => {
|
|
1237
|
+
if (n.type === "button" && textOf(n).join("").includes("重启生效")) btn = n;
|
|
1238
|
+
});
|
|
1239
|
+
assert.ok(btn, "缺少「重启生效」按钮");
|
|
1240
|
+
btn.props.onClick();
|
|
1241
|
+
assert.equal(restarted, 1);
|
|
1242
|
+
});
|
|
1243
|
+
|
|
1244
|
+
test("只改了界面:给「重载界面」而不是重启", () => {
|
|
1245
|
+
let reloaded = 0;
|
|
1246
|
+
const report = {
|
|
1247
|
+
...updateReport,
|
|
1248
|
+
diskVersion: "0.6.0",
|
|
1249
|
+
versionDrift: true,
|
|
1250
|
+
pendingUpgrade: { version: "0.6.0", previous: "0.5.6", at: "", restartRequired: false, reloadRequired: true },
|
|
1251
|
+
};
|
|
1252
|
+
const el = UpdateLinkView({
|
|
1253
|
+
phase: "done",
|
|
1254
|
+
report,
|
|
1255
|
+
install: null,
|
|
1256
|
+
onCheck: noop,
|
|
1257
|
+
onInstall: noop,
|
|
1258
|
+
onReload: () => {
|
|
1259
|
+
reloaded += 1;
|
|
1260
|
+
},
|
|
1261
|
+
});
|
|
1262
|
+
const txt = textOf(el).join(" ");
|
|
1263
|
+
assert.ok(txt.includes("已安装 v0.6.0"), txt);
|
|
1264
|
+
assert.ok(txt.includes("重载界面"), txt);
|
|
1265
|
+
assert.ok(!txt.includes("重启生效"), "只改界面时不该要求重启");
|
|
1266
|
+
let btn = null;
|
|
1267
|
+
walk(el, (n) => {
|
|
1268
|
+
if (n.type === "button" && textOf(n).join("").includes("重载界面")) btn = n;
|
|
1269
|
+
});
|
|
1270
|
+
assert.ok(btn, "缺少「重载界面」按钮");
|
|
1271
|
+
btn.props.onClick();
|
|
1272
|
+
assert.equal(reloaded, 1);
|
|
1154
1273
|
});
|
|
1155
1274
|
|
|
1156
1275
|
test("检查失败 / 无法比较:各多一个字说明,绝不说「已是最新」", () => {
|
|
@@ -1158,8 +1277,8 @@ test("检查失败 / 无法比较:各多一个字说明,绝不说「已是
|
|
|
1158
1277
|
UpdateLinkView({
|
|
1159
1278
|
phase: "done",
|
|
1160
1279
|
report: { ok: false, current: "0.5.6", error: "检查更新失败:registry.npmjs.org 超时(5000ms)" },
|
|
1280
|
+
install: null,
|
|
1161
1281
|
onCheck: noop,
|
|
1162
|
-
onCopy: noop,
|
|
1163
1282
|
}),
|
|
1164
1283
|
).join(" ");
|
|
1165
1284
|
assert.ok(failed.includes("检查失败"), failed);
|
|
@@ -1170,40 +1289,31 @@ test("检查失败 / 无法比较:各多一个字说明,绝不说「已是
|
|
|
1170
1289
|
UpdateLinkView({
|
|
1171
1290
|
phase: "done",
|
|
1172
1291
|
report: { ...updateReport, latest: "2026.1", comparable: false, hasUpdate: false },
|
|
1292
|
+
install: null,
|
|
1173
1293
|
onCheck: noop,
|
|
1174
|
-
onCopy: noop,
|
|
1175
1294
|
}),
|
|
1176
1295
|
).join(" ");
|
|
1177
1296
|
assert.ok(incomparable.includes("无法比较"), incomparable);
|
|
1178
1297
|
assert.ok(!incomparable.includes("已是最新"));
|
|
1179
1298
|
});
|
|
1180
1299
|
|
|
1181
|
-
test("
|
|
1182
|
-
let copied = "";
|
|
1300
|
+
test("点「检查更新」触发重查(不是跳页)", () => {
|
|
1183
1301
|
let checked = 0;
|
|
1184
1302
|
const el = UpdateLinkView({
|
|
1185
1303
|
phase: "done",
|
|
1186
1304
|
report: updateReport,
|
|
1305
|
+
install: null,
|
|
1187
1306
|
onCheck: () => {
|
|
1188
1307
|
checked += 1;
|
|
1189
1308
|
},
|
|
1190
|
-
|
|
1191
|
-
copied = text;
|
|
1192
|
-
},
|
|
1309
|
+
onInstall: noop,
|
|
1193
1310
|
});
|
|
1194
|
-
let updateBtn = null;
|
|
1195
1311
|
let checkBtn = null;
|
|
1196
1312
|
walk(el, (n) => {
|
|
1197
|
-
if (n.type
|
|
1198
|
-
const label = textOf(n).join("");
|
|
1199
|
-
if (label.includes("新版本")) updateBtn = n;
|
|
1200
|
-
if (label === "检查更新") checkBtn = n;
|
|
1313
|
+
if (n.type === "button" && textOf(n).join("") === "检查更新") checkBtn = n;
|
|
1201
1314
|
});
|
|
1202
|
-
assert.ok(
|
|
1203
|
-
assert.ok(checkBtn, "要有一个「检查更新」按钮");
|
|
1204
|
-
updateBtn.props.onClick();
|
|
1315
|
+
assert.ok(checkBtn, "缺少「检查更新」按钮");
|
|
1205
1316
|
checkBtn.props.onClick();
|
|
1206
|
-
assert.equal(copied, updateReport.upgradeCommand);
|
|
1207
1317
|
assert.equal(checked, 1);
|
|
1208
1318
|
});
|
|
1209
1319
|
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 聊天窗口「@ 一台在线设备」的纯逻辑(宿主侧)。
|
|
3
|
+
*
|
|
4
|
+
* 用户在 composer 里打 `@`,菜单把**在线的 mesh 机器**列出来(client/client.js
|
|
5
|
+
* 注册的那个 @ source);选中后插入 `@机器名 `。发送时宿主在
|
|
6
|
+
* `agent/pre-step` 里把消息开头的 @目标 认出来,把正文直接派发到那些机器 ——
|
|
7
|
+
* 于是「在聊天窗口 @ 一台机器」就等于「把这句话交给那台机器」。
|
|
8
|
+
*
|
|
9
|
+
* 为什么只认**开头**的 @:
|
|
10
|
+
* · 正文中间的 @ 通常是「提到某台机器」或者让本机 agent 自己用 mesh_run,
|
|
11
|
+
* 自动派发会在这种地方误伤;
|
|
12
|
+
* · 文件引用的序列化形式也是 `@path`(见 @deepseek-ai/dsh-client-ui-reference),
|
|
13
|
+
* 而开头的 @路径 不会被误认成机器名(名字必须精确命中已知机器)。
|
|
14
|
+
*
|
|
15
|
+
* 本模块不读文件、不联网、不碰 ctx,全部单测覆盖(lib/_selftest-at-mention.mjs)。
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** 一条消息最多认几个派发目标:再多就不是派活了,是广播。 */
|
|
19
|
+
export const AT_MENTION_LIMIT = 8;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 机器名是否允许出现在 mention 里。
|
|
23
|
+
*
|
|
24
|
+
* 名字由用户起(validateMachineName 允许空格、禁止斜杠与控制字符),所以这里
|
|
25
|
+
* 只挡掉「会破坏 mention 语法」的字符:换行、@ 本身。@ 在名字里会让
|
|
26
|
+
* `@@名字` 这种写法歧义。
|
|
27
|
+
*
|
|
28
|
+
* @param {unknown} name
|
|
29
|
+
* @returns {boolean}
|
|
30
|
+
*/
|
|
31
|
+
export function isMentionableName(name) {
|
|
32
|
+
const value = String(name ?? "").trim();
|
|
33
|
+
if (!value) return false;
|
|
34
|
+
// eslint-disable-next-line no-control-regex
|
|
35
|
+
return !/[@\r\n\t\x00-\x1f\x7f]/.test(value);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 从消息开头认出连续的 `@机器名`。
|
|
40
|
+
*
|
|
41
|
+
* 机器名可以含空格(用户起的名字),所以不能按空白切词 —— 这里按「已知名字
|
|
42
|
+
* 最长优先」逐个试,命中后要求下一个字符是空白或结尾(整词边界)。匹配对大小写
|
|
43
|
+
* 不敏感,返回的名字始终取已知列表里的规范写法。
|
|
44
|
+
*
|
|
45
|
+
* @param {string} text 消息原文(通常就是 composer 里那段文本)。
|
|
46
|
+
* @param {string[]} names 当前已知的机器名(含离线;在线与否由调用方再判)。
|
|
47
|
+
* @returns {{ mentions: { machine: string, raw: string }[], body: string }}
|
|
48
|
+
* `mentions` 是按出现顺序认出的目标;`body` 是去掉这些 @目标 后的任务正文。
|
|
49
|
+
*/
|
|
50
|
+
export function matchLeadingMentions(text, names) {
|
|
51
|
+
const source = typeof text === "string" ? text : "";
|
|
52
|
+
const known = [...new Set((Array.isArray(names) ? names : []).map((n) => String(n ?? "").trim()).filter(isMentionableName))].sort(
|
|
53
|
+
(a, b) => b.length - a.length,
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const mentions = [];
|
|
57
|
+
let cursor = 0;
|
|
58
|
+
const skipSpace = () => {
|
|
59
|
+
while (cursor < source.length && /\s/u.test(source[cursor])) cursor += 1;
|
|
60
|
+
};
|
|
61
|
+
skipSpace();
|
|
62
|
+
while (mentions.length < AT_MENTION_LIMIT && source[cursor] === "@") {
|
|
63
|
+
const nameStart = cursor + 1;
|
|
64
|
+
let hit = null;
|
|
65
|
+
for (const name of known) {
|
|
66
|
+
if (source.slice(nameStart, nameStart + name.length).toLocaleLowerCase() !== name.toLocaleLowerCase()) continue;
|
|
67
|
+
const after = nameStart + name.length;
|
|
68
|
+
if (after < source.length && !/\s/u.test(source[after])) continue;
|
|
69
|
+
hit = { machine: name, raw: source.slice(cursor, after) };
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
if (!hit) break;
|
|
73
|
+
mentions.push(hit);
|
|
74
|
+
cursor = nameStart + hit.machine.length;
|
|
75
|
+
skipSpace();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return { mentions, body: source.slice(cursor).trim() };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 生成这一轮要给模型看的新消息正文。
|
|
83
|
+
*
|
|
84
|
+
* 派发成功时告诉 agent「已经发出去了,别在本机再做一遍」(少了这句话,agent 会
|
|
85
|
+
* 把正文当成本地任务直接执行 —— `/mesh/api/send` 那条路径踩过一次);失败时
|
|
86
|
+
* 把原因说清楚,并明确「没有在本机执行」,让 agent 转告用户、等用户决定。
|
|
87
|
+
*
|
|
88
|
+
* @param {{ body: string, results: { machine: string, id?: string, error?: string }[] }} input
|
|
89
|
+
* @returns {string}
|
|
90
|
+
*/
|
|
91
|
+
export function buildAtPrompt({ body, results }) {
|
|
92
|
+
const text = String(body ?? "").trim();
|
|
93
|
+
const lines = [text || "(这条消息只有 @ 设备名,没有正文)", ""];
|
|
94
|
+
for (const item of Array.isArray(results) ? results : []) {
|
|
95
|
+
const machine = String(item?.machine ?? "").trim();
|
|
96
|
+
if (item?.id) {
|
|
97
|
+
lines.push(
|
|
98
|
+
`[Mesh 聊天窗口派发 → ${machine}/${item.id}] 已发出。现在什么都不用做:不要调用任何工具、不要回派,` +
|
|
99
|
+
`回一句「已派发给 ${machine},等待回执」即可。`,
|
|
100
|
+
);
|
|
101
|
+
} else {
|
|
102
|
+
lines.push(
|
|
103
|
+
`[Mesh 未能派发 @${machine}:${item?.error || "未知原因"}] 这条任务没有发出,也没有在本机执行。` +
|
|
104
|
+
"请把原因直接告诉用户,等用户决定下一步(不要自己动手执行这条任务)。",
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return lines.join("\n");
|
|
109
|
+
}
|