@suifei/dsh-ai-team 0.4.76 → 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 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'),
@@ -437,6 +440,11 @@ export function apply(ctx, config = {}) {
437
440
  for (const member of Object.values(runtime.service.state.members ?? {})) {
438
441
  if (member.kind !== 'agent' || member.routeStale !== true) continue;
439
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
+ }
440
448
  void activateMember({
441
449
  payload: {
442
450
  memberId: member.id,
@@ -693,6 +701,10 @@ export function apply(ctx, config = {}) {
693
701
  // 本次请求的连续失败计数(按成员会话、10 分钟窗口)。
694
702
  const requestAttempts = new Map();
695
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
+ });
696
708
  const pmoLastKick = new Map();
697
709
  const pmoLastStall = new Map();
698
710
  const pmoLastHeartbeat = new Map();
@@ -884,6 +896,21 @@ export function apply(ctx, config = {}) {
884
896
  hasActivateMember: typeof activateMember === 'function',
885
897
  });
886
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
+ }
887
914
  try {
888
915
  const reseated = await activateMember({
889
916
  payload: {
@@ -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.76",
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",