@suifei/dsh-ai-team 0.4.138 → 0.4.140
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/CHANGELOG.md +23 -0
- package/README.md +13 -1
- package/index.js +71 -31
- package/lib/diaglog.js +2 -0
- package/lib/domain/policy.js +79 -0
- package/lib/domain/task.js +8 -0
- package/lib/host/member-tools.js +9 -1
- package/lib/host/pmo.js +111 -0
- package/lib/host/service.js +38 -1
- package/lib/host/views.js +1 -0
- package/lib/host/waker.js +34 -12
- package/lib/runtime/deferred-wakes.js +148 -0
- package/lib/runtime/host-repair.js +92 -73
- package/lib/runtime/wake-failure.js +29 -1
- package/lib/vendor/skillopt/src/index.js +1 -1
- package/package.json +1 -1
- package/lib/runtime/stale-tree-wakes.js +0 -119
package/lib/host/service.js
CHANGED
|
@@ -27,7 +27,7 @@ import { MEMBER_STATUS, isBoardIdle } from '../ledger/fold.js';
|
|
|
27
27
|
|
|
28
28
|
const MEMBER_STATUS_VALUES = new Set(Object.values(MEMBER_STATUS));
|
|
29
29
|
import { checkPersonality, isQaMember, unfinishedTasksFor } from '../domain/member-profile.js';
|
|
30
|
-
import { isLeadMember } from '../domain/policy.js';
|
|
30
|
+
import { isLeadMember, reviewPairs } from '../domain/policy.js';
|
|
31
31
|
import { describeAttachments, findMentions, normalizeAttachments, plainMentionLinks } from '../domain/rich-message.js';
|
|
32
32
|
|
|
33
33
|
/**
|
|
@@ -202,9 +202,12 @@ export class TeamService {
|
|
|
202
202
|
id: p.id, name: p.name, goal: p.goal ?? '', owner: p.ownerName ?? p.ownerMemberId ?? p.ownerId, workspacePath: p.workspacePath ?? '', pmoAuto: p.pmoAuto !== false, active: p.status !== 'archived',
|
|
203
203
|
runState: p.runState === 'stopped' ? 'stopped' : 'running',
|
|
204
204
|
}));
|
|
205
|
+
// 开发↔验收配对(reviewPairs):界面与外部工具读插件算好的搭档,不自己按字段重算。
|
|
206
|
+
const pairs = reviewPairs(state);
|
|
205
207
|
const members = Object.values(state.members ?? {}).map((m) => ({
|
|
206
208
|
id: m.id,
|
|
207
209
|
name: m.name,
|
|
210
|
+
reviewerId: pairs.get(m.id) ?? null,
|
|
208
211
|
role: m.role ?? '',
|
|
209
212
|
status: m.status ?? 'idle',
|
|
210
213
|
kind: m.kind ?? 'agent',
|
|
@@ -1555,6 +1558,40 @@ export class TeamService {
|
|
|
1555
1558
|
}
|
|
1556
1559
|
|
|
1557
1560
|
/** Surface an explicit Human decision request with all questions inline. */
|
|
1561
|
+
/**
|
|
1562
|
+
* 加人建议(planStaffingAdvice)落到 Human 收件箱。故意不带结构化 questions:
|
|
1563
|
+
* autoAnswerDecisions 只自动回答带 questions 的项,加不加人必须由 Human 决定。
|
|
1564
|
+
*/
|
|
1565
|
+
async recordStaffingAdvice(projectId, advice) {
|
|
1566
|
+
return this.runExclusive(async () => {
|
|
1567
|
+
const humanId = this.humanId();
|
|
1568
|
+
if (humanId === null) return null;
|
|
1569
|
+
const item = createInboxItem({
|
|
1570
|
+
memberId: humanId,
|
|
1571
|
+
type: 'decision_required',
|
|
1572
|
+
ref: {
|
|
1573
|
+
kind: 'staffing_advice',
|
|
1574
|
+
role: advice.role,
|
|
1575
|
+
count: advice.count,
|
|
1576
|
+
title: advice.title,
|
|
1577
|
+
reasons: advice.reasons,
|
|
1578
|
+
taskIds: advice.taskIds,
|
|
1579
|
+
taskId: advice.taskIds?.[0] ?? null,
|
|
1580
|
+
memberName: 'PMO',
|
|
1581
|
+
},
|
|
1582
|
+
requiresDecision: true,
|
|
1583
|
+
}, { at: this.now() });
|
|
1584
|
+
await this.ledger.append({
|
|
1585
|
+
type: 'inbox/item-created',
|
|
1586
|
+
payload: { itemId: item.id, ...item },
|
|
1587
|
+
actor: { kind: 'system' },
|
|
1588
|
+
projectId,
|
|
1589
|
+
at: this.now(),
|
|
1590
|
+
});
|
|
1591
|
+
return item;
|
|
1592
|
+
});
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1558
1595
|
async requestDecision(command, payload) {
|
|
1559
1596
|
const humanId = this.humanId();
|
|
1560
1597
|
if (humanId === null) fail(ERRORS.NOT_FOUND, 'Human member not found');
|
package/lib/host/views.js
CHANGED
|
@@ -35,6 +35,7 @@ export function taskCard(state, task) {
|
|
|
35
35
|
following: (state.followers?.[task.id] ?? []).length > 0,
|
|
36
36
|
blockedBy: Array.isArray(task.blockedBy) ? [...task.blockedBy] : [],
|
|
37
37
|
blocked: isBlocked(state, task),
|
|
38
|
+
writeScopes: Array.isArray(task.writeScopes) ? [...task.writeScopes] : [],
|
|
38
39
|
revision: task.revision,
|
|
39
40
|
resultDefinition: task.resultDefinition ?? '',
|
|
40
41
|
irreversible: task.irreversible === true,
|
package/lib/host/waker.js
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* deduplication and permission checks stay in the Host.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { PERSONALITY_LIMIT,
|
|
10
|
-
import {
|
|
9
|
+
import { PERSONALITY_LIMIT, unfinishedTasksFor } from '../domain/member-profile.js';
|
|
10
|
+
import { pairedReviewer, projectOwnerId, reviewPairs } from '../domain/policy.js';
|
|
11
11
|
import { isBoardIdle } from '../ledger/fold.js';
|
|
12
12
|
import { describeAttachments, normalizeAttachments } from '../domain/rich-message.js';
|
|
13
13
|
|
|
@@ -43,7 +43,7 @@ function taskTitle(state, taskId) {
|
|
|
43
43
|
* 主理人照做(「遵令未开新任务」);wave_done 又算作 PMO 已看过局面,定时推进于是一直不触发——
|
|
44
44
|
* 看板空转 7 小时,直到 10 点 Human 加了一名成员才被叫醒。判断下一步不该等钟点,也不该等 Human 说「继续」。
|
|
45
45
|
*/
|
|
46
|
-
const CONTINUE_RULES = '对照 Human 最近一次的指令判断目标是否已经达成:已达成且没有明确的后续价值 → 用 team action=say 在主对话简短说明「已完成、暂无后续」,然后结束本回合,不开新卡。确有必要继续时,现在就产出下一批 Task(读取已完成 Task、Thread 与核心 skill,需要成员意见就在 Thread @ 相关成员),并用 action=say 告诉 Human 新一批做什么、为什么;resultDefinition 必须可验证,qaRequired 必须有 qaChecklist。不要重复已完成卡,不要扩大到 Human 没要求的范围,也不要把下一步推迟到某个时间点或等 Human 说「继续」。自主续开有批次上限,用尽时建卡会被拒绝,那时停下等 Human。';
|
|
46
|
+
const CONTINUE_RULES = '对照 Human 最近一次的指令判断目标是否已经达成:已达成且没有明确的后续价值 → 用 team action=say 在主对话简短说明「已完成、暂无后续」,然后结束本回合,不开新卡。确有必要继续时,现在就产出下一批 Task(读取已完成 Task、Thread 与核心 skill,需要成员意见就在 Thread @ 相关成员),并用 action=say 告诉 Human 新一批做什么、为什么;resultDefinition 必须可验证,qaRequired 必须有 qaChecklist;能并行的卡分给不同的人,每张写 writeScopes(要改的文件或目录,彼此不重叠),有先后关系的用 blockedBy。不要重复已完成卡,不要扩大到 Human 没要求的范围,也不要把下一步推迟到某个时间点或等 Human 说「继续」。自主续开有批次上限,用尽时建卡会被拒绝,那时停下等 Human。';
|
|
47
47
|
|
|
48
48
|
function promptFor(reason, state, taskId) {
|
|
49
49
|
const task = state.tasks?.[taskId];
|
|
@@ -88,6 +88,9 @@ function promptFor(reason, state, taskId) {
|
|
|
88
88
|
if (reason === 'pmo_dispatch') {
|
|
89
89
|
return `PMO 补派:${title} 仍处于待处理且你当前空闲(可能此前的唤醒未送达)。调用 team 工具认领(claim)它并立即推进;若它不再由你负责或无法推进,用 task.reassign 交还并说明原因;不要静默等待。`;
|
|
90
90
|
}
|
|
91
|
+
if (reason === 'pmo_claim') {
|
|
92
|
+
return `PMO 派活:你现在没有任务,${title} 待认领。调用 team 工具认领(claim)并立即推进,完成后 submit 证据;认领失败(已被别人认领)就用 action=tasks 看还有没有你能认领的待办,没有就结束本回合。`;
|
|
93
|
+
}
|
|
91
94
|
if (reason === 'pmo_review') {
|
|
92
95
|
return `PMO 验收提醒:${title} 仍处于 pending_acceptance,还没有人验收。请独立复核(有 QA checklist 时逐项复跑)并按 resultDefinition 验收或退回;不要静默等待,也不要把验收推回 Human。`;
|
|
93
96
|
}
|
|
@@ -201,7 +204,8 @@ export function planWakes(state, result, actor = {}, options = {}) {
|
|
|
201
204
|
}
|
|
202
205
|
if (event?.type === 'task/submitted') {
|
|
203
206
|
const current = state.tasks?.[event.payload?.taskId];
|
|
204
|
-
|
|
207
|
+
// 开发↔验收配对:叫交活人的搭档;搭档不合格时退回原排名第一位(lib/domain/policy.js pairedReviewer)。
|
|
208
|
+
const reviewer = pairedReviewer(state, current);
|
|
205
209
|
if (reviewer !== undefined) {
|
|
206
210
|
add(reviewer.id, event.payload?.taskId, 'review_requested', `review_requested:${event.seq ?? event.payload?.taskId}`);
|
|
207
211
|
}
|
|
@@ -280,14 +284,12 @@ export function planWakes(state, result, actor = {}, options = {}) {
|
|
|
280
284
|
const task = state.tasks?.[event.payload?.taskId];
|
|
281
285
|
if (task !== undefined) {
|
|
282
286
|
const bucket = event.payload?.bucket ?? Math.floor(Date.now() / 600_000);
|
|
283
|
-
//
|
|
284
|
-
// qaRequired
|
|
285
|
-
//
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
for (const member of reviewers) {
|
|
290
|
-
add(member.id, task.id, 'pmo_review', `pmo_review:${task.id}:${member.id}:${bucket}`);
|
|
287
|
+
// 与提交时的 review_requested 同口径:只叫交活人的配对验收人(开发↔验收 1:1);搭档不合格时退回
|
|
288
|
+
// 原排名第一位。此前 qaRequired 的卡会叫**全部** QA——两个验收人时同一张卡被两人同时验,配对失效。
|
|
289
|
+
// #18(qaRequired=false 的待验收卡没人催、静置 111 分钟)仍由这里兜住:总会叫到一位。
|
|
290
|
+
const reviewer = pairedReviewer(state, task);
|
|
291
|
+
if (reviewer !== undefined) {
|
|
292
|
+
add(reviewer.id, task.id, 'pmo_review', `pmo_review:${task.id}:${reviewer.id}:${bucket}`);
|
|
291
293
|
}
|
|
292
294
|
}
|
|
293
295
|
}
|
|
@@ -324,6 +326,26 @@ export function planWakes(state, result, actor = {}, options = {}) {
|
|
|
324
326
|
add(target, task.id, 'pmo_heartbeat', `pmo_heartbeat:${task.id}:${bucket}`);
|
|
325
327
|
}
|
|
326
328
|
}
|
|
329
|
+
if (event?.type === 'pmo/staffing') {
|
|
330
|
+
// 空闲必派(lib/host/pmo.js planIdleStaffing):有可认领的待办就叫空闲开发各认领一张;
|
|
331
|
+
// 不够分的空闲开发交给主理人拆新卡、直接指派(team 工具没有改派动作)。
|
|
332
|
+
const bucket = event.payload?.bucket ?? Math.floor(Date.now() / 60_000);
|
|
333
|
+
for (const claim of event.payload?.claims ?? []) {
|
|
334
|
+
const claimTask = state.tasks?.[claim?.taskId];
|
|
335
|
+
if (claimTask === undefined || claimTask.status !== 'pending') continue;
|
|
336
|
+
add(claim.memberId, claimTask.id, 'pmo_claim', `pmo_claim:${claimTask.id}:${bucket}`);
|
|
337
|
+
}
|
|
338
|
+
const spare = (event.payload?.spare ?? []).map((memberId) => state.members?.[memberId]).filter((member) => member !== undefined);
|
|
339
|
+
const lead = projectOwnerId(state);
|
|
340
|
+
if (spare.length > 0 && lead !== null) {
|
|
341
|
+
const pairs = reviewPairs(state);
|
|
342
|
+
const names = spare.map((member) => {
|
|
343
|
+
const reviewer = state.members?.[pairs.get(member.id)];
|
|
344
|
+
return `${member.name}(${member.role || '开发'},id ${member.id}${reviewer === undefined ? '' : `,验收搭档 ${reviewer.name}`})`;
|
|
345
|
+
}).join('、');
|
|
346
|
+
add(lead, null, 'pmo_staffing', `pmo_staffing:${bucket}`, `PMO 派活:${names} 当前没有任务,看板上也没有他们能认领的待办。你是项目负责人:把还没开工的工作拆成新卡,用 team action=create 直接 assigneeId 给他们,每人一张,resultDefinition 写可验证的验收标准;每张卡写 writeScopes(要改的文件或目录),同一时间不同人的卡范围不重叠,避免互相覆盖;有先后关系的用 blockedBy。验收会按配对自动交给各自的验收搭档,不用你指定。确实没有可拆的工作就不建卡,直接结束本回合。`);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
327
349
|
if (event?.type === 'pmo/stall') {
|
|
328
350
|
const task = state.tasks?.[event.payload?.taskId];
|
|
329
351
|
if (task !== undefined) {
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 延后唤醒:宿主暂时投不进、但不是会话坏了的唤醒,暂存起来,等时机到了按原路补投,不记失败。
|
|
3
|
+
*
|
|
4
|
+
* 两类(判定见 wake-failure.js):
|
|
5
|
+
*
|
|
6
|
+
* - `stale-tree`(热重载后「旧树未散」):实机 il2c 2026-11-19 04:47,插件关再开后唤醒玄策连续
|
|
7
|
+
* `UNAUTHORIZED target belongs to another subagent tree`。成员重载前开的回合常驻在旧宿主 Agent
|
|
8
|
+
* 那棵树下;宿主在**该成员**回合结束、空闲后把它收掉(dsh-subagent `watchLocalSettlement`),之后的
|
|
9
|
+
* 投递在新根下冷恢复。所以等该成员 `turn/end` + settleDelayMs 再投(r43:旧回合结束 5 秒后补投成功)。
|
|
10
|
+
* 旧回合结束后仍被拒、退避用尽才放弃并记 `.fail`。
|
|
11
|
+
* - `capacity`(团队超过宿主并发上限):宿主同时运行的子智能体有上限(`maxActiveSubagents`,默认 8),
|
|
12
|
+
* 满了不排队而是直接拒绝(dsh-subagent activation.ts `ACTIVATION_LIMIT_REACHED`)。团队可以超过 8 人,
|
|
13
|
+
* 多出来的排队:**任一**会话 `turn/end` 都可能腾出名额,按入队先后补投最早的一条;不设放弃上限
|
|
14
|
+
* (排多久都等),只按退避定时器兜底重试。
|
|
15
|
+
*
|
|
16
|
+
* 同一成员只留最新一条计划——唤醒内容在投递时按当时状态生成,旧计划没有额外信息。最终投到记
|
|
17
|
+
* `wake.<类>.recovered`(errors 级可见)。
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export const DEFERRED_BACKOFF_MS = Object.freeze([30_000, 60_000, 120_000, 300_000, 600_000]);
|
|
21
|
+
export const DEFERRED_SETTLE_MS = 5_000;
|
|
22
|
+
|
|
23
|
+
/** 各类的诊断事件前缀;名字沿用 0.4.138 的 `wake.tree-stale.*`,已有的日志检索不失效。 */
|
|
24
|
+
const EVENT = Object.freeze({ 'stale-tree': 'wake.tree-stale', capacity: 'wake.capacity' });
|
|
25
|
+
export const DEFERRED_KINDS = Object.freeze(Object.keys(EVENT));
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {{
|
|
29
|
+
* redeliver: (entry: { kind: string, sessionId: string|null, projectId: string, memberId: string, plan: any }) => Promise<unknown>,
|
|
30
|
+
* diag?: { append?: (row: object) => void },
|
|
31
|
+
* backoffMs?: readonly number[],
|
|
32
|
+
* settleDelayMs?: number,
|
|
33
|
+
* setTimer?: (fn: () => void, ms: number) => any,
|
|
34
|
+
* clearTimer?: (handle: any) => void,
|
|
35
|
+
* now?: () => number,
|
|
36
|
+
* }} options
|
|
37
|
+
*/
|
|
38
|
+
export function createDeferredWakes({
|
|
39
|
+
redeliver, diag, backoffMs = DEFERRED_BACKOFF_MS, settleDelayMs = DEFERRED_SETTLE_MS,
|
|
40
|
+
setTimer = setTimeout, clearTimer = clearTimeout, now = () => Date.now(),
|
|
41
|
+
}) {
|
|
42
|
+
/** `${projectId}:${memberId}` → { key, kind, sessionId, projectId, memberId, plan, queuedAt, timer, armedBy } */
|
|
43
|
+
const pending = new Map();
|
|
44
|
+
/**
|
|
45
|
+
* key → { kind, tries, attempts, ended, queuedAt }。queuedAt 是首次入队时间:补投又被拒时仍按它排队,不掉到队尾。
|
|
46
|
+
* 出现在这里即「曾被暂存」,投到时据此记 recovered。
|
|
47
|
+
* tries:被拒总次数,只决定下一次间隔(封顶最后一档);attempts(仅 stale-tree):该成员旧回合结束**之后**
|
|
48
|
+
* 仍被拒的次数,用尽才放弃——回合没结束前被拒是预期之中(r43:2 分钟的旧回合里被拒 3 次)。
|
|
49
|
+
*/
|
|
50
|
+
const state = new Map();
|
|
51
|
+
let disposed = false;
|
|
52
|
+
const keyOf = (projectId, memberId) => `${projectId}:${memberId}`;
|
|
53
|
+
const ev = (kind, suffix = '') => `${EVENT[kind]}${suffix}`;
|
|
54
|
+
const arm = (entry, ms, trigger) => {
|
|
55
|
+
clearTimer(entry.timer);
|
|
56
|
+
entry.armedBy = trigger;
|
|
57
|
+
entry.timer = setTimer(() => fire(entry.key, trigger), ms);
|
|
58
|
+
entry.timer?.unref?.();
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const fire = (key, trigger) => {
|
|
62
|
+
const entry = pending.get(key);
|
|
63
|
+
if (entry === undefined || disposed) return;
|
|
64
|
+
pending.delete(key);
|
|
65
|
+
clearTimer(entry.timer);
|
|
66
|
+
const { kind, sessionId, projectId, memberId, plan } = entry;
|
|
67
|
+
diag?.append?.({ ev: ev(kind, '.redeliver'), projectId, memberId, sessionId, trigger, tries: state.get(key)?.tries ?? 0, waitedMs: now() - entry.queuedAt, reason: plan?.reason ?? null });
|
|
68
|
+
Promise.resolve()
|
|
69
|
+
.then(() => redeliver({ kind, sessionId, projectId, memberId, plan }))
|
|
70
|
+
.catch((error) => diag?.append?.({ ev: ev(kind, '.redeliver.fail'), projectId, memberId, sessionId, message: error?.message ?? String(error) }));
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
/**
|
|
75
|
+
* 暂存一条被宿主暂时拒绝的唤醒。retry=true 表示这是补投又被拒。
|
|
76
|
+
* @param {{ kind: 'stale-tree'|'capacity', sessionId?: string|null, projectId: string, memberId: string, plan: any, retry?: boolean }} input
|
|
77
|
+
* @returns {boolean} false:放弃(仅 stale-tree 退避用尽)、未知类或已卸载,调用方按普通失败处理
|
|
78
|
+
*/
|
|
79
|
+
defer({ kind, sessionId = null, projectId, memberId, plan, retry = false }) {
|
|
80
|
+
if (disposed || !(kind in EVENT)) return false;
|
|
81
|
+
const key = keyOf(projectId, memberId);
|
|
82
|
+
const s = state.get(key) ?? { kind, tries: 0, attempts: 0, ended: false, queuedAt: now() };
|
|
83
|
+
if (s.kind !== kind) Object.assign(s, { kind, tries: 0, attempts: 0, ended: false, queuedAt: now() });
|
|
84
|
+
state.set(key, s);
|
|
85
|
+
if (retry) {
|
|
86
|
+
s.tries += 1;
|
|
87
|
+
if (kind === 'stale-tree' && s.ended) s.attempts += 1;
|
|
88
|
+
}
|
|
89
|
+
const previous = pending.get(key);
|
|
90
|
+
if (kind === 'stale-tree' && s.attempts >= backoffMs.length) {
|
|
91
|
+
if (previous !== undefined) clearTimer(previous.timer);
|
|
92
|
+
pending.delete(key);
|
|
93
|
+
state.delete(key);
|
|
94
|
+
diag?.append?.({ ev: ev(kind, '.giveup.fail'), projectId, memberId, sessionId, attempts: s.attempts, tries: s.tries, reason: plan?.reason ?? null });
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
if (previous !== undefined && previous.kind === kind) {
|
|
98
|
+
// 还没投出去又来新计划:换成最新的;排队位置与定时器照旧。
|
|
99
|
+
Object.assign(previous, { plan, sessionId: sessionId ?? previous.sessionId });
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
if (previous !== undefined) clearTimer(previous.timer);
|
|
103
|
+
const delayMs = backoffMs[Math.min(s.tries, backoffMs.length - 1)];
|
|
104
|
+
const entry = { key, kind, sessionId, projectId, memberId, plan, queuedAt: s.queuedAt, timer: undefined, armedBy: null };
|
|
105
|
+
pending.set(key, entry);
|
|
106
|
+
arm(entry, delayMs, 'timer');
|
|
107
|
+
diag?.append?.({ ev: ev(kind), projectId, memberId, sessionId, tries: s.tries, attempts: s.attempts, delayMs, queued: [...pending.values()].filter((item) => item.kind === kind).length, reason: plan?.reason ?? null });
|
|
108
|
+
return true;
|
|
109
|
+
},
|
|
110
|
+
/** 投递成功:曾被暂存过的成员记一行 recovered,并清掉计数。 */
|
|
111
|
+
delivered(projectId, memberId, context = {}) {
|
|
112
|
+
const key = keyOf(projectId, memberId);
|
|
113
|
+
const s = state.get(key);
|
|
114
|
+
if (s === undefined) return;
|
|
115
|
+
diag?.append?.({ ev: ev(s.kind, '.recovered'), projectId, memberId, tries: s.tries, attempts: s.attempts, ...context });
|
|
116
|
+
state.delete(key);
|
|
117
|
+
},
|
|
118
|
+
/**
|
|
119
|
+
* `session/event` 观察者,只看 `turn/end`:
|
|
120
|
+
* - stale-tree:该成员自己的回合结束 → 等宿主收尾后补投;此后再被拒才计入放弃次数。
|
|
121
|
+
* - capacity:任一回合结束都可能腾出一个名额 → 补投排队最久、还没被叫的那一条。
|
|
122
|
+
*/
|
|
123
|
+
observe(session, event) {
|
|
124
|
+
const sessionId = session?.id;
|
|
125
|
+
if (event?.type !== 'turn/end' || typeof sessionId !== 'string') return;
|
|
126
|
+
for (const entry of pending.values()) {
|
|
127
|
+
if (entry.kind !== 'stale-tree' || entry.sessionId !== sessionId) continue;
|
|
128
|
+
const s = state.get(entry.key);
|
|
129
|
+
if (s !== undefined) s.ended = true;
|
|
130
|
+
arm(entry, settleDelayMs, 'turn-end');
|
|
131
|
+
}
|
|
132
|
+
let oldest;
|
|
133
|
+
for (const entry of pending.values()) {
|
|
134
|
+
if (entry.kind !== 'capacity' || entry.armedBy === 'turn-end') continue;
|
|
135
|
+
if (oldest === undefined || entry.queuedAt < oldest.queuedAt) oldest = entry;
|
|
136
|
+
}
|
|
137
|
+
if (oldest !== undefined) arm(oldest, settleDelayMs, 'turn-end');
|
|
138
|
+
},
|
|
139
|
+
/** 测试与诊断:当前暂存的成员,按入队先后。 */
|
|
140
|
+
pending: () => [...pending.values()].sort((a, b) => a.queuedAt - b.queuedAt).map(({ kind, projectId, memberId }) => ({ kind, projectId, memberId })),
|
|
141
|
+
dispose() {
|
|
142
|
+
disposed = true;
|
|
143
|
+
for (const entry of pending.values()) clearTimer(entry.timer);
|
|
144
|
+
pending.clear();
|
|
145
|
+
state.clear();
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
|
@@ -1,73 +1,92 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Repair Team Host sessions archived by earlier revisions.
|
|
3
|
-
*
|
|
4
|
-
* Members are subagent descendants of the Host Agent, and
|
|
5
|
-
* `archived-session-gate` (dsh-api-session-controller) rejects every
|
|
6
|
-
* `agent/pre-step` whose Session — or any Session above it in the subagent
|
|
7
|
-
* lineage — is archived. The loop then ends the turn as `{kind:'blocked'}`
|
|
8
|
-
* **without issuing a model request**, so an archived Host silently disables
|
|
9
|
-
* the whole team (measured: 453 blocked turns, 0 completed, no `request/header`).
|
|
10
|
-
*
|
|
11
|
-
* Earlier revisions archived the Host on purpose to hide it from the session
|
|
12
|
-
* list. This sweep lifts that damage by calling `unarchiveSession` for the
|
|
13
|
-
* persisted host of each runtime and the `parentSession` of every member session.
|
|
14
|
-
*
|
|
15
|
-
* Two constraints learned the hard way:
|
|
16
|
-
* 1. Use only the **documented** API. `archivedSessionIds` is not part of the
|
|
17
|
-
* workspaceRegistry contract; gating on it silently skipped the whole
|
|
18
|
-
* repair. `unarchiveSession` on a non-archived id resolves without writing,
|
|
19
|
-
* so calling it unconditionally is safe and needs no read-back.
|
|
20
|
-
* 2. Diagnostics ending without `.fail` are dropped at the default `errors`
|
|
21
|
-
* diag level. Failure rows therefore carry `.fail`; success is proven by
|
|
22
|
-
* the durable archive list, not by a log line.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @param {{
|
|
27
|
-
* runtimes: Iterable<any>,
|
|
28
|
-
* sessions?: { get?: (id: string) => any },
|
|
29
|
-
* workspaceRegistry?: { unarchiveSession?: (id: string) => Promise<void> },
|
|
30
|
-
* diag?: { append?: (row: any) => any } | null,
|
|
31
|
-
* knownHostSessionIds?: Iterable<string>
|
|
32
|
-
* }} options
|
|
33
|
-
* @returns {Promise<string[]|null>} session ids the sweep asked to unarchive;
|
|
34
|
-
* `null` means the registry was not ready yet and the caller should retry.
|
|
35
|
-
*/
|
|
36
|
-
export async function repairArchivedHosts(options = {}) {
|
|
37
|
-
const registry = options.workspaceRegistry;
|
|
38
|
-
// `workspaceRegistry` 要等 sessionPersistence 与历史 bootstrap 完成才 active,
|
|
39
|
-
// 插件激活瞬间常常还取不到。此时返回 null(而不是空数组)让调用方保持
|
|
40
|
-
// 「未修复」状态,等下一个 tick 重试——而不是一次失败就永久放弃。
|
|
41
|
-
if (registry === undefined || registry === null || typeof registry.unarchiveSession !== 'function') return null;
|
|
42
|
-
|
|
43
|
-
const victims = new Set();
|
|
44
|
-
for (const known of options.knownHostSessionIds ?? []) {
|
|
45
|
-
if (typeof known === 'string' && known !== '') victims.add(known);
|
|
46
|
-
}
|
|
47
|
-
for (const runtime of options.runtimes ?? []) {
|
|
48
|
-
const hostId = runtime?.service?.state?.hostSessionId;
|
|
49
|
-
if (typeof hostId === 'string' && hostId !== '') victims.add(hostId);
|
|
50
|
-
for (const member of Object.values(runtime?.service?.state?.members ?? {})) {
|
|
51
|
-
const sessionId = member?.sessionId;
|
|
52
|
-
if (typeof sessionId !== 'string' || sessionId === '') continue;
|
|
53
|
-
// 成员会话自己也可能被归档(例如用户手动归档了那条会话):gate 会直接
|
|
54
|
-
// 拒绝它,只有 host 一代的解归档覆盖不到。
|
|
55
|
-
victims.add(sessionId);
|
|
56
|
-
try {
|
|
57
|
-
const header = options.sessions?.get?.(sessionId)?.header;
|
|
58
|
-
if (typeof header?.parentSession === 'string') victims.add(header.parentSession);
|
|
59
|
-
} catch { /* member session is not live; skip */ }
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const repaired = [];
|
|
64
|
-
for (const sessionId of victims) {
|
|
65
|
-
try {
|
|
66
|
-
await registry.unarchiveSession(sessionId);
|
|
67
|
-
repaired.push(sessionId);
|
|
68
|
-
} catch (error) {
|
|
69
|
-
options.diag?.append?.({ ev: 'host.unarchive.fail', sessionId, message: error?.message ?? String(error) });
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return repaired;
|
|
73
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Repair Team Host sessions archived by earlier revisions.
|
|
3
|
+
*
|
|
4
|
+
* Members are subagent descendants of the Host Agent, and
|
|
5
|
+
* `archived-session-gate` (dsh-api-session-controller) rejects every
|
|
6
|
+
* `agent/pre-step` whose Session — or any Session above it in the subagent
|
|
7
|
+
* lineage — is archived. The loop then ends the turn as `{kind:'blocked'}`
|
|
8
|
+
* **without issuing a model request**, so an archived Host silently disables
|
|
9
|
+
* the whole team (measured: 453 blocked turns, 0 completed, no `request/header`).
|
|
10
|
+
*
|
|
11
|
+
* Earlier revisions archived the Host on purpose to hide it from the session
|
|
12
|
+
* list. This sweep lifts that damage by calling `unarchiveSession` for the
|
|
13
|
+
* persisted host of each runtime and the `parentSession` of every member session.
|
|
14
|
+
*
|
|
15
|
+
* Two constraints learned the hard way:
|
|
16
|
+
* 1. Use only the **documented** API. `archivedSessionIds` is not part of the
|
|
17
|
+
* workspaceRegistry contract; gating on it silently skipped the whole
|
|
18
|
+
* repair. `unarchiveSession` on a non-archived id resolves without writing,
|
|
19
|
+
* so calling it unconditionally is safe and needs no read-back.
|
|
20
|
+
* 2. Diagnostics ending without `.fail` are dropped at the default `errors`
|
|
21
|
+
* diag level. Failure rows therefore carry `.fail`; success is proven by
|
|
22
|
+
* the durable archive list, not by a log line.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {{
|
|
27
|
+
* runtimes: Iterable<any>,
|
|
28
|
+
* sessions?: { get?: (id: string) => any },
|
|
29
|
+
* workspaceRegistry?: { unarchiveSession?: (id: string) => Promise<void> },
|
|
30
|
+
* diag?: { append?: (row: any) => any } | null,
|
|
31
|
+
* knownHostSessionIds?: Iterable<string>
|
|
32
|
+
* }} options
|
|
33
|
+
* @returns {Promise<string[]|null>} session ids the sweep asked to unarchive;
|
|
34
|
+
* `null` means the registry was not ready yet and the caller should retry.
|
|
35
|
+
*/
|
|
36
|
+
export async function repairArchivedHosts(options = {}) {
|
|
37
|
+
const registry = options.workspaceRegistry;
|
|
38
|
+
// `workspaceRegistry` 要等 sessionPersistence 与历史 bootstrap 完成才 active,
|
|
39
|
+
// 插件激活瞬间常常还取不到。此时返回 null(而不是空数组)让调用方保持
|
|
40
|
+
// 「未修复」状态,等下一个 tick 重试——而不是一次失败就永久放弃。
|
|
41
|
+
if (registry === undefined || registry === null || typeof registry.unarchiveSession !== 'function') return null;
|
|
42
|
+
|
|
43
|
+
const victims = new Set();
|
|
44
|
+
for (const known of options.knownHostSessionIds ?? []) {
|
|
45
|
+
if (typeof known === 'string' && known !== '') victims.add(known);
|
|
46
|
+
}
|
|
47
|
+
for (const runtime of options.runtimes ?? []) {
|
|
48
|
+
const hostId = runtime?.service?.state?.hostSessionId;
|
|
49
|
+
if (typeof hostId === 'string' && hostId !== '') victims.add(hostId);
|
|
50
|
+
for (const member of Object.values(runtime?.service?.state?.members ?? {})) {
|
|
51
|
+
const sessionId = member?.sessionId;
|
|
52
|
+
if (typeof sessionId !== 'string' || sessionId === '') continue;
|
|
53
|
+
// 成员会话自己也可能被归档(例如用户手动归档了那条会话):gate 会直接
|
|
54
|
+
// 拒绝它,只有 host 一代的解归档覆盖不到。
|
|
55
|
+
victims.add(sessionId);
|
|
56
|
+
try {
|
|
57
|
+
const header = options.sessions?.get?.(sessionId)?.header;
|
|
58
|
+
if (typeof header?.parentSession === 'string') victims.add(header.parentSession);
|
|
59
|
+
} catch { /* member session is not live; skip */ }
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const repaired = [];
|
|
64
|
+
for (const sessionId of victims) {
|
|
65
|
+
try {
|
|
66
|
+
await registry.unarchiveSession(sessionId);
|
|
67
|
+
repaired.push(sessionId);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
options.diag?.append?.({ ev: 'host.unarchive.fail', sessionId, message: error?.message ?? String(error) });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return repaired;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 归档修复的调用门:修好之前同一时刻只跑一次,并发调用共享同一个 Promise;修好后直接返回。
|
|
77
|
+
*
|
|
78
|
+
* 启动 tick、ensureParent、blocked 回合会并发调用修复;旧写法在 await 之前只查「修好没」,
|
|
79
|
+
* 几路都通过,同一批会话被解档、PMO 被归入工作区各三遍(il2c 11-19 04:47:11 与 09:17:32
|
|
80
|
+
* 热重载各三行 host.repair.ok,相隔 ≤11ms)。没修好(如 workspaceRegistry 未就绪)时,
|
|
81
|
+
* 下一次调用照常重跑。
|
|
82
|
+
* @param {() => Promise<void>} run 一次修复
|
|
83
|
+
* @param {() => boolean} isDone 是否已修好
|
|
84
|
+
*/
|
|
85
|
+
export function repairOnce(run, isDone) {
|
|
86
|
+
let running = null;
|
|
87
|
+
return () => {
|
|
88
|
+
if (isDone()) return Promise.resolve();
|
|
89
|
+
running ??= Promise.resolve().then(run).finally(() => { running = null; });
|
|
90
|
+
return running;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
@@ -22,7 +22,7 @@ const BUSY_HANDLE = /active write handle/i;
|
|
|
22
22
|
* 宿主 Agent 的生命周期挂在创建它的插件作用域上(dsh-agent-loop `initializeAgent` 的 `ownerCtx.effect`),
|
|
23
23
|
* 插件卸载即拆,新实例 resume 出新对象当根,而成员重载前开的回合仍常驻在旧树下。官方 `subagents.prompt`
|
|
24
24
|
* 也救不了:它按旧根投递,旧根已不是在线 Agent(rootOf:exact live caller,r43 第二轮实测)。
|
|
25
|
-
* 回合结束、宿主把它收掉(settlement)之后,下一次投递在新根下冷恢复——见
|
|
25
|
+
* 回合结束、宿主把它收掉(settlement)之后,下一次投递在新根下冷恢复——见 deferred-wakes.js。
|
|
26
26
|
* 同为 UNAUTHORIZED 的「another parent session」是血缘错配,不在此列。
|
|
27
27
|
*/
|
|
28
28
|
export function isStaleTreeError(error) {
|
|
@@ -30,6 +30,34 @@ export function isStaleTreeError(error) {
|
|
|
30
30
|
&& /another subagent tree/i.test(String(error?.message ?? ''));
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* 团队超过宿主并发上限:宿主同时运行的子智能体有上限(dsh-subagent `maxActiveSubagents`,默认 8),
|
|
35
|
+
* 满了**不排队、直接拒绝**(activation.ts `reserve`:`ACTIVATION_LIMIT_REACHED`
|
|
36
|
+
* 「subagent limit reached (active child limit: N); wait for an existing child to finish …」)。
|
|
37
|
+
* 不是会话坏了,也不是成员失败:排队等名额(deferred-wakes.js `capacity`)。
|
|
38
|
+
*/
|
|
39
|
+
export function isCapacityError(error) {
|
|
40
|
+
return String(error?.code ?? '').toUpperCase() === 'ACTIVATION_LIMIT_REACHED'
|
|
41
|
+
|| /subagent limit reached/i.test(String(error?.message ?? ''));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 容量报错里宿主给出的上限(`active child limit: N`);不是容量报错或没带数字时返回 null。 */
|
|
45
|
+
export function capacityLimit(error) {
|
|
46
|
+
if (!isCapacityError(error)) return null;
|
|
47
|
+
const match = /active child limit:\s*(\d+)/i.exec(String(error?.message ?? ''));
|
|
48
|
+
return match === null ? null : Number(match[1]);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 被宿主暂时拒绝、该延后重投的唤醒属于哪一类;不属于延后类返回 null。
|
|
53
|
+
* @returns {'stale-tree'|'capacity'|null}
|
|
54
|
+
*/
|
|
55
|
+
export function deferredWakeKind(error) {
|
|
56
|
+
if (isStaleTreeError(error)) return 'stale-tree';
|
|
57
|
+
if (isCapacityError(error)) return 'capacity';
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
33
61
|
/**
|
|
34
62
|
* @param {string|null|undefined} causeChain `describeCauseChain()` 的输出
|
|
35
63
|
* @returns {'wake.session-busy'|'wake.fail'} busy 表示「写租约被占用,必然需要重建」
|
|
@@ -374,7 +374,7 @@ export function apply(ctx, config = {}) {
|
|
|
374
374
|
defineTool({
|
|
375
375
|
name: t.name,
|
|
376
376
|
description: t.description,
|
|
377
|
-
parameters: t.parameters,
|
|
377
|
+
parameters: { type: 'object', properties: t.parameters },
|
|
378
378
|
output: { schema: { type: 'string' }, render: renderOutput },
|
|
379
379
|
async execute(args, exec) {
|
|
380
380
|
const a = args || {}
|
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.140",
|
|
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",
|