@suifei/dsh-ai-team 0.4.75 → 0.4.77
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/index.js +54 -0
- package/lib/ledger/fold.js +12 -1
- package/lib/runtime/activation-budget.js +46 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -51,6 +51,7 @@ import { describeTaskContext, describeWake, planWakes } from './lib/host/waker.j
|
|
|
51
51
|
import { describeCauseChain } from './lib/runtime/error-chain.js';
|
|
52
52
|
import { classifyWakeFailure } from './lib/runtime/wake-failure.js';
|
|
53
53
|
import { registerShellGuard } from './lib/runtime/shell-guard.js';
|
|
54
|
+
import { createActivationBudget } from './lib/runtime/activation-budget.js';
|
|
54
55
|
import { aggregatePeople } from './lib/host/people-view.js';
|
|
55
56
|
import { riskView } from './lib/host/risk-view.js';
|
|
56
57
|
import { weeklyView } from './lib/host/weekly-view.js';
|
|
@@ -99,6 +100,8 @@ export const Config = z.object({
|
|
|
99
100
|
skilloptJudgeVotes: z.number().step(1).min(3).max(9).default(3),
|
|
100
101
|
// 初装默认项目与「新建项目」对话框的默认工作目录;留空则取宿主 cwd(见 boot)。
|
|
101
102
|
defaultWorkspace: z.string().default(''),
|
|
103
|
+
// 同一成员 30 分钟内允许的自动重建次数(失败→自愈→再失败的死循环闸门)。
|
|
104
|
+
autoReseatLimitPer30Min: z.number().step(1).min(1).max(100).default(6),
|
|
102
105
|
// 成员 shell 风险守卫:'warn' 只记诊断(默认),'block' 直接拒绝,'off' 不介入。
|
|
103
106
|
// 实机事故:成员写 serve.ps1 并用隐藏窗口拉起常驻进程,触发杀软报毒。
|
|
104
107
|
shellGuard: z.union(['off', 'warn', 'block']).default('warn'),
|
|
@@ -429,6 +432,38 @@ export function apply(ctx, config = {}) {
|
|
|
429
432
|
// 都会在这里露出原始错误码——不再靠日志里那句
|
|
430
433
|
// 「subagent X is unavailable」猜。
|
|
431
434
|
await probePersistence(value.sessionIds);
|
|
435
|
+
// 路由过期对账:账本重新折叠时,凡是「上次失败的路由 ≠ 当前配置」的成员
|
|
436
|
+
// 都会带上 routeStale(老数据无需迁移脚本),但那条标记只有**新配置事件**
|
|
437
|
+
// 才会触发唤醒计划,失败成员又被排除在自动唤醒之外。所以 boot 后补一次
|
|
438
|
+
// 强制重建,让升级本身就把卡住的成员救回来。
|
|
439
|
+
for (const runtime of value.runtimes.values()) {
|
|
440
|
+
for (const member of Object.values(runtime.service.state.members ?? {})) {
|
|
441
|
+
if (member.kind !== 'agent' || member.routeStale !== true) continue;
|
|
442
|
+
if (member.status === 'retired') continue;
|
|
443
|
+
const budget = activationBudget.take(member.id);
|
|
444
|
+
if (budget.allowed !== true) {
|
|
445
|
+
diag.append({ ev: 'member.route-reconcile.suppressed.fail', projectId: runtime.id, memberId: member.id, count: budget.count, limit: budget.limit });
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
448
|
+
void activateMember({
|
|
449
|
+
payload: {
|
|
450
|
+
memberId: member.id,
|
|
451
|
+
force: true,
|
|
452
|
+
prompt: '模型/提供方已切换,会话按新路由重建。先读 tasks 与 thread 的当前状态,继续未完成的工作,不要重复已完成的事。',
|
|
453
|
+
},
|
|
454
|
+
}, runtime).then((result) => {
|
|
455
|
+
diag.append({
|
|
456
|
+
ev: result?.error === undefined ? 'member.route-reconciled' : 'member.route-reconcile.fail',
|
|
457
|
+
projectId: runtime.id,
|
|
458
|
+
memberId: member.id,
|
|
459
|
+
sessionId: result?.member?.sessionId ?? null,
|
|
460
|
+
error: result?.error ?? null,
|
|
461
|
+
});
|
|
462
|
+
}).catch((error) => {
|
|
463
|
+
diag.append({ ev: 'member.route-reconcile.fail', projectId: runtime.id, memberId: member.id, message: error?.message ?? String(error) });
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
}
|
|
432
467
|
for (const runtime of value.runtimes.values()) {
|
|
433
468
|
for (const member of Object.values(runtime.service.state.members ?? {})) {
|
|
434
469
|
if (member.kind === 'agent' && typeof member.sessionId === 'string') {
|
|
@@ -666,6 +701,10 @@ export function apply(ctx, config = {}) {
|
|
|
666
701
|
// 本次请求的连续失败计数(按成员会话、10 分钟窗口)。
|
|
667
702
|
const requestAttempts = new Map();
|
|
668
703
|
const activationTasks = new Map();
|
|
704
|
+
// 自动重建预算:见 lib/runtime/activation-budget.js(issue #1 的 7 小时循环)。
|
|
705
|
+
const activationBudget = createActivationBudget({
|
|
706
|
+
limit: Number.isSafeInteger(config?.autoReseatLimitPer30Min) ? config.autoReseatLimitPer30Min : 6,
|
|
707
|
+
});
|
|
669
708
|
const pmoLastKick = new Map();
|
|
670
709
|
const pmoLastStall = new Map();
|
|
671
710
|
const pmoLastHeartbeat = new Map();
|
|
@@ -857,6 +896,21 @@ export function apply(ctx, config = {}) {
|
|
|
857
896
|
hasActivateMember: typeof activateMember === 'function',
|
|
858
897
|
});
|
|
859
898
|
if (legacySession) {
|
|
899
|
+
// 自动重建必须限额:issue #1 的「7 小时 / 200+ 子代理」就是这条路径
|
|
900
|
+
// 无上限地循环。超额后不再重建,成员保持 failed 并留可见诊断。
|
|
901
|
+
const budget = activationBudget.take(plan.memberId);
|
|
902
|
+
if (budget.allowed !== true) {
|
|
903
|
+
diag.append({
|
|
904
|
+
ev: 'member.reseat.suppressed.fail',
|
|
905
|
+
projectId: projectRuntime.id,
|
|
906
|
+
memberId: plan.memberId,
|
|
907
|
+
reason: plan.reason,
|
|
908
|
+
count: budget.count,
|
|
909
|
+
limit: budget.limit,
|
|
910
|
+
windowMs: budget.windowMs,
|
|
911
|
+
});
|
|
912
|
+
return;
|
|
913
|
+
}
|
|
860
914
|
try {
|
|
861
915
|
const reseated = await activateMember({
|
|
862
916
|
payload: {
|
package/lib/ledger/fold.js
CHANGED
|
@@ -835,6 +835,17 @@ export function applyEvent(state, event) {
|
|
|
835
835
|
const nextConfig = isPlainObject(payload.config) ? payload.config : (isPlainObject(payload.after) ? payload.after : null);
|
|
836
836
|
if (nextConfig === null) return advance(state, event);
|
|
837
837
|
const version = Number.isSafeInteger(payload.configVersion) ? payload.configVersion : member.configVersion ?? 0;
|
|
838
|
+
// 会话停在旧路由的两种证据:
|
|
839
|
+
// 1) 本次配置事件明确标了 routeChanged;
|
|
840
|
+
// 2) 上次失败记录里的 provider/model 与**新配置**不一致——说明会话仍在用
|
|
841
|
+
// 旧路由(实机:失败记录 provider=deepseek-official,配置已改 qwen)。
|
|
842
|
+
// 第 2 条只依赖账本自身,因此**重新折叠历史**就能把已切换过的成员标出来,
|
|
843
|
+
// 不需要额外的迁移脚本。
|
|
844
|
+
const lastFailure = member.lastFailure;
|
|
845
|
+
const routeDiffersFromFailure = lastFailure !== undefined && lastFailure !== null
|
|
846
|
+
&& typeof lastFailure.provider === 'string' && lastFailure.provider !== ''
|
|
847
|
+
&& (lastFailure.provider !== (nextConfig.provider ?? '')
|
|
848
|
+
|| (lastFailure.model ?? null) !== (nextConfig.model ?? null));
|
|
838
849
|
return advance(state, event, {
|
|
839
850
|
members: {
|
|
840
851
|
...state.members,
|
|
@@ -849,7 +860,7 @@ export function applyEvent(state, event) {
|
|
|
849
860
|
// agentOptions 里,追加 model/selection 只改模型名、改不了路由,于是
|
|
850
861
|
// 表现成「模型换成了 Qwen,provider 还是 deepseek-official → 缺 key」。
|
|
851
862
|
// 标记过期,下一次唤醒直接重建会话让新路由生效。
|
|
852
|
-
routeStale: payload.routeChanged === true ? true : member.routeStale === true,
|
|
863
|
+
routeStale: payload.routeChanged === true || routeDiffersFromFailure ? true : member.routeStale === true,
|
|
853
864
|
},
|
|
854
865
|
},
|
|
855
866
|
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 自动重建预算:把「失败 → 自愈重建 → 再失败」的死循环挡在插件这一侧。
|
|
3
|
+
*
|
|
4
|
+
* 实机报告(issue #1):一句「在吗」跑了 7 小时、派了两百多个子代理。触发链是
|
|
5
|
+
* 「唤醒失败(会话不可恢复/认证失败)→ 自动重建 → 新会话再失败 → 下一次唤醒再重建」;
|
|
6
|
+
* 只要唤醒源源不断(thread 回复、PMO 心跳),这个循环就没有上限。
|
|
7
|
+
*
|
|
8
|
+
* 这里给自动重建加一个滑动窗口额度:同一成员在 windowMs 内最多重建 limit 次,
|
|
9
|
+
* 超出后**不再自动重建**,改为写一条可见诊断并让成员保持 failed(等 Human 处理)。
|
|
10
|
+
* 正常团队工作远达不到这个阈值,只有循环才会撞上。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const DEFAULT_LIMIT = 6;
|
|
14
|
+
const DEFAULT_WINDOW_MS = 30 * 60 * 1000;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {{ limit?: number, windowMs?: number }} options
|
|
18
|
+
*/
|
|
19
|
+
export function createActivationBudget(options = {}) {
|
|
20
|
+
const limit = Number.isSafeInteger(options.limit) && options.limit > 0 ? options.limit : DEFAULT_LIMIT;
|
|
21
|
+
const windowMs = Number.isSafeInteger(options.windowMs) && options.windowMs > 0 ? options.windowMs : DEFAULT_WINDOW_MS;
|
|
22
|
+
/** @type {Map<string, number[]>} memberId -> 最近一次重建的时间戳 */
|
|
23
|
+
const taken = new Map();
|
|
24
|
+
return {
|
|
25
|
+
/** 记录一次重建并返回是否允许(先判后记,拒绝时不消耗额度)。 */
|
|
26
|
+
take(memberId, now = Date.now()) {
|
|
27
|
+
if (typeof memberId !== 'string' || memberId === '') return { allowed: true, count: 0 };
|
|
28
|
+
const recent = (taken.get(memberId) ?? []).filter((at) => now - at < windowMs);
|
|
29
|
+
if (recent.length >= limit) {
|
|
30
|
+
taken.set(memberId, recent);
|
|
31
|
+
return { allowed: false, count: recent.length, limit, windowMs };
|
|
32
|
+
}
|
|
33
|
+
recent.push(now);
|
|
34
|
+
taken.set(memberId, recent);
|
|
35
|
+
return { allowed: true, count: recent.length, limit, windowMs };
|
|
36
|
+
},
|
|
37
|
+
/** 只读查询,不消耗额度。 */
|
|
38
|
+
peek(memberId, now = Date.now()) {
|
|
39
|
+
const recent = (taken.get(memberId) ?? []).filter((at) => now - at < windowMs);
|
|
40
|
+
return recent.length;
|
|
41
|
+
},
|
|
42
|
+
reset(memberId) {
|
|
43
|
+
taken.delete(memberId);
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@suifei/dsh-ai-team",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.77",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "文渊阁 (Wenyuan Pavilion) — AI Team mode for DeepSeek Harness: concurrent projects, owned tasks, threads, inbox and an append-only team ledger",
|
|
6
6
|
"license": "MIT",
|