dsh-plugin-mesh 0.5.21 → 0.5.22
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/lib/_selftest-approval.mjs +32 -8
- package/lib/_selftest-reply-route.mjs +20 -0
- package/lib/approval.js +57 -15
- package/lib/index.js +60 -16
- package/llms.txt +3 -2
- package/package.json +1 -1
|
@@ -150,21 +150,45 @@ test("fromMachine 缺失时回退 from 的机器名部分", () => {
|
|
|
150
150
|
|
|
151
151
|
console.log("\n── 回执必须绕过闸门(否则结果永远回不来)──");
|
|
152
152
|
|
|
153
|
+
const NOW = Date.parse("2026-11-24T12:00:00.000Z");
|
|
154
|
+
const fresh = (extra = {}) => ({ toMachine: "hos", thread: "build-1", at: new Date(NOW - 60_000).toISOString(), ...extra });
|
|
155
|
+
|
|
153
156
|
test("同一台机器 + 同一 thread 的回执 → 是回执", () => {
|
|
154
|
-
|
|
155
|
-
|
|
157
|
+
assert.equal(isReplyToOutbound({ fromMachine: "hos", thread: "build-1" }, [fresh()], NOW), true);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test("对端声明了 answers → 按 id 精确认领(同一个 thread 的第 2 轮也是回执)", () => {
|
|
161
|
+
const out = [fresh({ id: "t-1" }), fresh({ id: "t-2" })];
|
|
162
|
+
assert.equal(isReplyToOutbound({ fromMachine: "hos", thread: "build-1", answers: "t-2" }, out, NOW), true);
|
|
163
|
+
// 声明的 id 不是发给这台机器的 → 不认(不能让陌生机器借一个 id 绕过闸门)
|
|
164
|
+
assert.equal(isReplyToOutbound({ fromMachine: "evilbox", thread: "build-1", answers: "t-2" }, out, NOW), false);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test("同一 thread 上已认领过的派发 → 第 2 条不再是回执(D-001 / #33)", () => {
|
|
168
|
+
const out = [fresh({ replyAt: new Date(NOW - 30_000).toISOString() })];
|
|
169
|
+
assert.equal(isReplyToOutbound({ fromMachine: "hos", thread: "build-1" }, out, NOW), false);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test("我方自己发出去的回执不参与认领(它不期待别人再回一条)", () => {
|
|
173
|
+
const out = [fresh({ answers: "t-0" })];
|
|
174
|
+
assert.equal(isReplyToOutbound({ fromMachine: "hos", thread: "build-1" }, out, NOW), false);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test("超过认领窗口的旧派发 → 不再认领(否则它会永远吃掉同 thread 的新任务)", () => {
|
|
178
|
+
const stale = fresh({ at: new Date(NOW - 2 * 3600_000).toISOString() });
|
|
179
|
+
assert.equal(isReplyToOutbound({ fromMachine: "hos", thread: "build-1" }, [stale], NOW), false);
|
|
156
180
|
});
|
|
157
181
|
|
|
158
182
|
test("换一台机器或换一个 thread → 不是回执(不能借旧 thread 名绕过)", () => {
|
|
159
|
-
const out = [
|
|
160
|
-
assert.equal(isReplyToOutbound({ fromMachine: "evilbox", thread: "build-1" }, out), false);
|
|
161
|
-
assert.equal(isReplyToOutbound({ fromMachine: "hos", thread: "build-2" }, out), false);
|
|
183
|
+
const out = [fresh()];
|
|
184
|
+
assert.equal(isReplyToOutbound({ fromMachine: "evilbox", thread: "build-1" }, out, NOW), false);
|
|
185
|
+
assert.equal(isReplyToOutbound({ fromMachine: "hos", thread: "build-2" }, out, NOW), false);
|
|
162
186
|
});
|
|
163
187
|
|
|
164
188
|
test("没有 thread / 没有机器名 / outbound 不是数组 → 都不是回执", () => {
|
|
165
|
-
assert.equal(isReplyToOutbound({ fromMachine: "hos" }, [{
|
|
166
|
-
assert.equal(isReplyToOutbound({ thread: "x" }, [{
|
|
167
|
-
assert.equal(isReplyToOutbound({ fromMachine: "hos", thread: "x" }, null), false);
|
|
189
|
+
assert.equal(isReplyToOutbound({ fromMachine: "hos" }, [fresh({ thread: "" })], NOW), false);
|
|
190
|
+
assert.equal(isReplyToOutbound({ thread: "x" }, [fresh({ thread: "x" })], NOW), false);
|
|
191
|
+
assert.equal(isReplyToOutbound({ fromMachine: "hos", thread: "x" }, null, NOW), false);
|
|
168
192
|
});
|
|
169
193
|
|
|
170
194
|
console.log(`\n${failed === 0 ? "全部通过" : "有失败"}:${passed} 通过 / ${failed} 失败\n`);
|
|
@@ -249,6 +249,26 @@ try {
|
|
|
249
249
|
assert.equal(original.messages.length, agentReplyBefore, "agent 互刷的 noWake 仍然不唤醒");
|
|
250
250
|
console.log("✓ agent-originated noWake replies stay recorded-only");
|
|
251
251
|
|
|
252
|
+
// ── D-001 / issue #33:同一 thread 的第 2、3 轮是真任务,不是回执 ──
|
|
253
|
+
//
|
|
254
|
+
// 旧判据是"这个 thread 上我方派过没有",第 2 轮必然命中,于是提示词被写成
|
|
255
|
+
// 「这是回执…不要回派」,结果静默丢失。现在:worker 会话发出的回执带
|
|
256
|
+
// `answers: <任务 id>`,接收端按 id 认领一次,因此每一轮都是新任务。
|
|
257
|
+
const multi = "d001-multiround";
|
|
258
|
+
for (const round of [1, 2, 3]) {
|
|
259
|
+
await a.send("B", multi, "original-session");
|
|
260
|
+
await until(() => b.inbound.filter((t) => t.thread === multi).length >= round);
|
|
261
|
+
const rec = b.inbound.filter((t) => t.thread === multi).at(-1);
|
|
262
|
+
assert.equal(rec.isReply, false, `第 ${round} 轮的同一 thread 任务被误判成回执(D-001 / #33)`);
|
|
263
|
+
// 第 1 轮新建会话,第 2 轮起复用同一个会话(上下文连续)。
|
|
264
|
+
const session = [...b.agents.keys()].at(-1);
|
|
265
|
+
const sent = await b.send("A", multi, session);
|
|
266
|
+
assert.match(String(sent), /已派发/, String(sent));
|
|
267
|
+
await until(() => a.inbound.at(-1)?.thread === multi && a.inbound.at(-1)?.isReply === true);
|
|
268
|
+
assert.equal(a.inbound.at(-1).status, "injected-thread-session", "回执要注入发起会话");
|
|
269
|
+
}
|
|
270
|
+
console.log("✓ same thread round 1..3 are tasks, not replies (D-001 / #33)");
|
|
271
|
+
|
|
252
272
|
// 一键关闭的工具面:三个范围、默认关闭、不认识的范围要明确报错。
|
|
253
273
|
const switchTool = b.tools.get("mesh_switch");
|
|
254
274
|
assert.ok(switchTool, "必须注册 mesh_switch");
|
package/lib/approval.js
CHANGED
|
@@ -128,27 +128,69 @@ export function needsApproval({ enabled = false, approved = [], peer = {}, pairi
|
|
|
128
128
|
return !isApproved(approved, peer);
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
/** 没有 `answers` 声明时的认领窗口(毫秒)。超窗口的旧派发不再被认领,避免它永远吃掉同 thread 的新任务。 */
|
|
132
|
+
export const REPLY_WINDOW_MS = 30 * 60_000;
|
|
133
|
+
|
|
131
134
|
/**
|
|
132
|
-
*
|
|
135
|
+
* 这条入站任务在回答哪一次派发?返回被它回答的那条派发记录;不是回执则返回
|
|
136
|
+
* `null`。闸门只**查**不改,真正写 `replyAt` 的是处理阶段(见 index.js),
|
|
137
|
+
* 这样"要不要审批"和"要不要当回执"看的是同一个判据。
|
|
133
138
|
*
|
|
134
|
-
*
|
|
135
|
-
* 往外派过任务。回执**必须绕过**首次确认闸门,否则对方把结果派回来时会被本机
|
|
136
|
-
* 拦下,整条回路卡死在"等允许"。
|
|
139
|
+
* 两级判据:
|
|
137
140
|
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
141
|
+
* 1. **声明优先**:对端带了 `answers: <任务 id>`,按 id + 机器精确认领。这是
|
|
142
|
+
* D-001(issue #33)的治本路径 —— 意图由发送方声明,不靠历史推断。
|
|
143
|
+
* 2. **老对端回退**:没有声明时,认领"同机器 + 同 thread"上最早一条**未认领**、
|
|
144
|
+
* 且**本身不是回执**的派发(窗口 `windowMs` 内)。认领一次就写 `replyAt`,
|
|
145
|
+
* 所以同一 thread 的第 2 轮起不会再被当成回执。
|
|
146
|
+
*
|
|
147
|
+
* 为什么"本身不是回执"要排除:我方发出去的回执(`answers` 非空)不期待别人
|
|
148
|
+
* 再回一条。不排除的话,它会在发送方永远挂着,把之后每一轮都判成回执 ——
|
|
149
|
+
* 这正是 issue #33 里那版补丁不管用的原因。
|
|
140
150
|
*
|
|
141
|
-
* @param {object} task 入站任务
|
|
142
151
|
* @param {Array} outbound 本机发出的任务记录
|
|
152
|
+
* @param {object} task 入站任务
|
|
153
|
+
* @param {number} now 当前时间(毫秒),便于测试
|
|
154
|
+
* @param {number} windowMs 回退判据的认领窗口
|
|
143
155
|
*/
|
|
144
|
-
export function
|
|
145
|
-
const
|
|
146
|
-
if (!thread) return false;
|
|
156
|
+
export function replyClaim(outbound, task = {}, now = Date.now(), windowMs = REPLY_WINDOW_MS) {
|
|
157
|
+
const list = Array.isArray(outbound) ? outbound : [];
|
|
147
158
|
const machine = String(task?.fromMachine || String(task?.from || "").split("/")[0] || "").trim();
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
159
|
+
const declared = String(task?.answers || "").trim();
|
|
160
|
+
if (declared) {
|
|
161
|
+
// id 已经足够唯一,机器名再挡一次伪造:陌生机器不能借一个我们发给别人的 id 绕过闸门。
|
|
162
|
+
return list.find((o) => String(o?.id || "") === declared && String(o?.toMachine || "").trim() === machine) ?? null;
|
|
163
|
+
}
|
|
164
|
+
const thread = String(task?.thread || "").trim();
|
|
165
|
+
if (!machine || !thread) return null;
|
|
166
|
+
const window = Number.isFinite(windowMs) && windowMs > 0 ? windowMs : REPLY_WINDOW_MS;
|
|
167
|
+
return (
|
|
168
|
+
list.find((o) => {
|
|
169
|
+
const at = Date.parse(o?.at ?? "");
|
|
170
|
+
return (
|
|
171
|
+
String(o?.toMachine || "").trim() === machine &&
|
|
172
|
+
String(o?.thread || "").trim() === thread &&
|
|
173
|
+
o?.ok !== false && // 没送达的派发不期待回执
|
|
174
|
+
!o?.answers && // 这一条本身是回执,不是待认领的派发
|
|
175
|
+
!o?.replyAt && // 已经认领过
|
|
176
|
+
Number.isFinite(at) &&
|
|
177
|
+
now - at <= window
|
|
178
|
+
);
|
|
179
|
+
}) ?? null
|
|
153
180
|
);
|
|
154
181
|
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* 这条入站任务是不是在「回答问题」而不是派新活?
|
|
185
|
+
*
|
|
186
|
+
* 回执**必须绕过**首次确认闸门,否则对方把结果派回来时会被本机拦下,整条回路
|
|
187
|
+
* 卡死在"等允许"。判据与 handleInboundTask 共用 `replyClaim`,避免两处漂移。
|
|
188
|
+
*
|
|
189
|
+
* @param {object} task 入站任务
|
|
190
|
+
* @param {Array} outbound 本机发出的任务记录
|
|
191
|
+
* @param {number} now 当前时间(毫秒)
|
|
192
|
+
* @param {number} windowMs 回退判据的认领窗口
|
|
193
|
+
*/
|
|
194
|
+
export function isReplyToOutbound(task = {}, outbound = [], now = Date.now(), windowMs = REPLY_WINDOW_MS) {
|
|
195
|
+
return replyClaim(outbound, task, now, windowMs) !== null;
|
|
196
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -89,6 +89,7 @@ import {
|
|
|
89
89
|
needsApproval,
|
|
90
90
|
normalizeApproved,
|
|
91
91
|
peerOfTask,
|
|
92
|
+
replyClaim,
|
|
92
93
|
revokePeer,
|
|
93
94
|
} from "./approval.js";
|
|
94
95
|
import {
|
|
@@ -130,7 +131,7 @@ import {
|
|
|
130
131
|
export const name = "dsh-plugin-mesh";
|
|
131
132
|
export const inject = ["tools", "webServer"];
|
|
132
133
|
|
|
133
|
-
const VERSION = "0.5.
|
|
134
|
+
const VERSION = "0.5.22";
|
|
134
135
|
// 诊断用:进程启动时间 + 入口真实路径。磁盘上的版本**不在这里缓存** ——
|
|
135
136
|
// 升级之后进程还跑旧代码,版本号必须现读磁盘才能立刻反映出来(真踩过:
|
|
136
137
|
// 磁盘升到 0.5.1,进程还在 0.5.0,界面显示 0.5.0)。
|
|
@@ -250,6 +251,12 @@ export const Config = z.object({
|
|
|
250
251
|
/** 超过这么久没心跳、也没 ping 通,算离线 */
|
|
251
252
|
peerTtlMs: z.natural().default(20000),
|
|
252
253
|
requestTimeoutMs: z.natural().default(20000),
|
|
254
|
+
/**
|
|
255
|
+
* 回执认领窗口(毫秒)。对端带了 `replyTo` 时按 id 精确认领、不受此限;
|
|
256
|
+
* 只有**没有声明**的老对端才靠"同机器同 thread 上最近的派发"认领,超过这个
|
|
257
|
+
* 窗口的派发不再被认领 —— 否则一条没等到回执的派发会永远吃掉同 thread 的新任务。
|
|
258
|
+
*/
|
|
259
|
+
replyWindowMs: z.natural().default(30 * 60_000),
|
|
253
260
|
|
|
254
261
|
// ── 发现方式(两者互补,默认都开)──
|
|
255
262
|
/** 用 UDP 组播做被动发现:零配置、即时 */
|
|
@@ -2191,18 +2198,24 @@ function classifyInbound(task, threadState, config, now, capFor, { canInject = f
|
|
|
2191
2198
|
* 最后才新建会话。复用是为了避免"每条消息都从零重新探索上下文"。
|
|
2192
2199
|
*/
|
|
2193
2200
|
function handleInboundTask(ctx, task, inbound, config, log, warn, waker, threadState, capFor, throttled, onHistoryChange, outbound) {
|
|
2201
|
+
const now = Date.now();
|
|
2194
2202
|
// ── 这条入站是「回执」还是「新任务」? ──
|
|
2195
2203
|
//
|
|
2196
|
-
//
|
|
2204
|
+
// 判据见 approval.js 的 `replyClaim`:对端声明了 `answers` 就按 id 精确认领;
|
|
2205
|
+
// 没有声明时回退到"同机器同 thread 上最早一条未认领的派发"。**认领一次就
|
|
2206
|
+
// 落 `replyAt`**,所以同一 thread 的第 2 轮起不会再被当成回执(D-001 / #33)。
|
|
2197
2207
|
// 是回执的话,提示词要明确禁止再回派,否则两边会互相回执形成循环
|
|
2198
2208
|
// (2026-10-21 手动派发实测:一轮几十条)。
|
|
2199
|
-
if (task?.thread) {
|
|
2200
|
-
const
|
|
2201
|
-
|
|
2202
|
-
task.isReply = (outbound ?? []).some(sameThread);
|
|
2209
|
+
if (task?.thread || task?.answers) {
|
|
2210
|
+
const claimed = replyClaim(outbound, task, now, config.replyWindowMs);
|
|
2211
|
+
task.isReply = !!claimed;
|
|
2203
2212
|
// 人发起的派发(聊天窗口 @ / 面板手动派发)的回执:即使发送方标了 noWake,
|
|
2204
2213
|
// 也要投递回会话 —— 那是用户等着的答案,不是可以静默丢掉的寒暄。
|
|
2205
|
-
task.humanReply = task.isReply &&
|
|
2214
|
+
task.humanReply = task.isReply && claimed?.human === true;
|
|
2215
|
+
if (claimed && !claimed.replyAt) {
|
|
2216
|
+
claimed.replyAt = new Date(now).toISOString();
|
|
2217
|
+
onHistoryChange?.();
|
|
2218
|
+
}
|
|
2206
2219
|
}
|
|
2207
2220
|
const rec = inbound.find((t) => t.id === task.id);
|
|
2208
2221
|
// 记下"回信地址",与"本机用哪个会话处理"是两件事。对端可以 GET
|
|
@@ -2223,7 +2236,6 @@ function handleInboundTask(ctx, task, inbound, config, log, warn, waker, threadS
|
|
|
2223
2236
|
return null;
|
|
2224
2237
|
}
|
|
2225
2238
|
};
|
|
2226
|
-
const now = Date.now();
|
|
2227
2239
|
|
|
2228
2240
|
// 闸门:先判断值不值得开跑,再决定走哪条路径
|
|
2229
2241
|
// 先判断"能不能注入已有会话":能的话冷却不适用(见 classifyInbound 的说明)
|
|
@@ -2283,6 +2295,24 @@ function handleInboundTask(ctx, task, inbound, config, log, warn, waker, threadS
|
|
|
2283
2295
|
saveThreads(threadState);
|
|
2284
2296
|
};
|
|
2285
2297
|
|
|
2298
|
+
/**
|
|
2299
|
+
* 记下"这个会话正在回答哪条入站任务"。worker 会话回派时带上 `answers`,
|
|
2300
|
+
* 对端就能按 id 精确认领,不必猜(D-001 / issue #33)。
|
|
2301
|
+
*
|
|
2302
|
+
* 只记**任务型**入站:回执被注入某个会话之后,那个会话接着发出的东西是新的
|
|
2303
|
+
* 请求(同一 thread 的第 2 轮),标记必须清掉,否则发起端自己的第二轮会被
|
|
2304
|
+
* 对端当成回执吞掉 —— 那正是这个缺陷的另一半。
|
|
2305
|
+
*/
|
|
2306
|
+
const noteAnswering = (sessionId) => {
|
|
2307
|
+
if (!key) return;
|
|
2308
|
+
const st = threadState.get(key) ?? { wakesAt: [], sessionId: "" };
|
|
2309
|
+
st.sessionId = String(sessionId);
|
|
2310
|
+
if (task.isReply === true) delete st.answering;
|
|
2311
|
+
else st.answering = { id: task.id, sessionId: String(sessionId), at: now };
|
|
2312
|
+
threadState.set(key, st);
|
|
2313
|
+
saveThreads(threadState);
|
|
2314
|
+
};
|
|
2315
|
+
|
|
2286
2316
|
/**
|
|
2287
2317
|
* 把一个任务注入本机某个仍在运行的会话。
|
|
2288
2318
|
*
|
|
@@ -2329,7 +2359,10 @@ function handleInboundTask(ctx, task, inbound, config, log, warn, waker, threadS
|
|
|
2329
2359
|
// 除非发送方显式要求新起会话(task.newSession),此时跳过复用直接建新的
|
|
2330
2360
|
if (key && task.newSession !== true) {
|
|
2331
2361
|
const known = threadState.get(key)?.sessionId;
|
|
2332
|
-
if (known && injectInto(known, "injected-thread-session", "同 thread 会话"))
|
|
2362
|
+
if (known && injectInto(known, "injected-thread-session", "同 thread 会话")) {
|
|
2363
|
+
noteAnswering(known);
|
|
2364
|
+
return;
|
|
2365
|
+
}
|
|
2333
2366
|
}
|
|
2334
2367
|
|
|
2335
2368
|
// 路径 B 已移除 —— 原来这里是拿 `task.originSession` 去本机找活跃会话。
|
|
@@ -2405,12 +2438,7 @@ function handleInboundTask(ctx, task, inbound, config, log, warn, waker, threadS
|
|
|
2405
2438
|
? `${resumed ? "恢复了已结束的会话" : "新建会话"}并绑定会话键 ${key}(${why})`
|
|
2406
2439
|
: "新建会话(无会话键,一次性任务,用完不绑定)";
|
|
2407
2440
|
}
|
|
2408
|
-
if (key)
|
|
2409
|
-
const st = threadState.get(key) ?? { wakesAt: [now], sessionId: "" };
|
|
2410
|
-
st.sessionId = String(sessionId);
|
|
2411
|
-
threadState.set(key, st);
|
|
2412
|
-
saveThreads(threadState);
|
|
2413
|
-
}
|
|
2441
|
+
if (key) noteAnswering(sessionId);
|
|
2414
2442
|
log(`任务 ${task.id} 已派发,会话 ${String(sessionId).slice(0, 20)}…`);
|
|
2415
2443
|
|
|
2416
2444
|
// 排空队列:排队那些消息和第一条属于同一场对话,按到达顺序注入同一个会话
|
|
@@ -3251,6 +3279,7 @@ function startPeerServer(ctx, { config, discovery, inbound, outbound, log, warn,
|
|
|
3251
3279
|
task: body.task,
|
|
3252
3280
|
thread: body.thread ? String(body.thread) : "",
|
|
3253
3281
|
originSession: body.originSession ? String(body.originSession) : "",
|
|
3282
|
+
answers: body.answers ? String(body.answers) : "",
|
|
3254
3283
|
noWake: body.noWake === true,
|
|
3255
3284
|
newSession: body.newSession === true,
|
|
3256
3285
|
workspace: body.workspace ? String(body.workspace) : "",
|
|
@@ -3273,7 +3302,7 @@ function startPeerServer(ctx, { config, discovery, inbound, outbound, log, warn,
|
|
|
3273
3302
|
//
|
|
3274
3303
|
// 回执不算:同一台机器 + 同一个 thread 上我们确实往外派过任务,那这条
|
|
3275
3304
|
// 就是对方在回答案,不是新活儿 —— 对回执再要一次确认会把整条回路卡死。
|
|
3276
|
-
const replyFromPeer = isReplyToOutbound(task, outbound);
|
|
3305
|
+
const replyFromPeer = isReplyToOutbound(task, outbound, Date.now(), config.replyWindowMs);
|
|
3277
3306
|
if (!replyFromPeer && inboundNeedsApproval(config, task)) {
|
|
3278
3307
|
task.status = "needs-approval";
|
|
3279
3308
|
task.routeDecision = `等待本机确认:还没有允许「${peerOfTask(task).machine || task.sourceAddress || "未知设备"}」`;
|
|
@@ -3671,6 +3700,21 @@ function registerTools(ctx, { discovery, config, inbound, outbound, log, warn, t
|
|
|
3671
3700
|
threadState.set(replyKey, { ...previous, wakesAt: previous?.wakesAt ?? [], sessionId: payload.originSession });
|
|
3672
3701
|
saveThreads(threadState);
|
|
3673
3702
|
// Retain the binding on failure: a timeout does not prove non-delivery.
|
|
3703
|
+
|
|
3704
|
+
// 这条派发是在回某条入站任务吗?是的话声明 `answers`,对端据此按 id
|
|
3705
|
+
// 精确认领,不必再靠"同 thread 派过没有"去猜(D-001 / issue #33)。
|
|
3706
|
+
//
|
|
3707
|
+
// 只认**任务型**入站发出的回执:回执被注入某个会话之后,那个会话接着
|
|
3708
|
+
// 发出的东西是新的请求(同一 thread 的第 2 轮),不是回执 —— 否则发起端
|
|
3709
|
+
// 自己的第二轮会被对端当成回执吞掉。
|
|
3710
|
+
const answering = threadState.get(replyKey)?.answering;
|
|
3711
|
+
if (answering && String(answering.sessionId || "") === payload.originSession) {
|
|
3712
|
+
payload.answers = String(answering.id);
|
|
3713
|
+
const st = threadState.get(replyKey);
|
|
3714
|
+
delete st.answering; // 一次任务只认一次回执;后续派发按新任务算
|
|
3715
|
+
threadState.set(replyKey, st);
|
|
3716
|
+
saveThreads(threadState);
|
|
3717
|
+
}
|
|
3674
3718
|
}
|
|
3675
3719
|
|
|
3676
3720
|
const started = Date.now();
|
package/llms.txt
CHANGED
|
@@ -43,7 +43,7 @@ Verify after restart: `GET http://127.0.0.1:45917/mesh/v1/health` returns JSON c
|
|
|
43
43
|
- 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.
|
|
44
44
|
- 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.
|
|
45
45
|
- 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.
|
|
46
|
-
- **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
|
|
46
|
+
- **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 bypass the gate — otherwise the result would never come back: a reply declares `answers: <task id>` naming one of this machine's outbound dispatch ids; for peers that do not declare it, a task whose `thread` matches an unclaimed outbound dispatch to the same machine (within `replyWindowMs`, default 30 min) still counts. With `requirePairing` on (or the pairing switch enabled) the gate is skipped: pairing is the stronger trust gesture.
|
|
47
47
|
- `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.
|
|
48
48
|
- `/mesh/api/state` additionally exposes `approvals[]` (pending first-contact tasks, only present when the debug gate below is on) and `approvedPeers[]` (`{machine,address,at}`).
|
|
49
49
|
|
|
@@ -70,7 +70,7 @@ These are outcomes, not a fixed feature list: the peer agent can run any command
|
|
|
70
70
|
|
|
71
71
|
`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.
|
|
72
72
|
|
|
73
|
-
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.
|
|
73
|
+
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. When an agent answers a task it received, the plugin attaches `answers: <task id>` automatically, so the peer routes the result to the exact dispatch instead of guessing from the thread.
|
|
74
74
|
|
|
75
75
|
`newSession: true` forces a fresh session while keeping the same conversation key (i.e. it is still the same conversation, with a clean context).
|
|
76
76
|
|
|
@@ -204,6 +204,7 @@ Override by id in the profile's `cordis.patch.yml`:
|
|
|
204
204
|
| `threadWindowMs` | natural | `3600000` | Window for the cap above |
|
|
205
205
|
| `threadCooldownMs` | natural | `5000` | Cooldown between session-creating wakes |
|
|
206
206
|
| `minTaskChars` | natural | `24` | Bodies shorter than this are not woken (inbox only) |
|
|
207
|
+
| `replyWindowMs` | natural | `1800000` | How long an undeclared dispatch stays claimable as the target of a reply |
|
|
207
208
|
|
|
208
209
|
## Tailnet setup (the only step that needs an external account)
|
|
209
210
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-mesh",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.22",
|
|
4
4
|
"type": "module",
|
|
5
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",
|