@suifei/dsh-ai-team 0.4.88 → 0.4.89
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 +26 -0
- package/index.js +22 -59
- package/lib/domain/errors.js +37 -36
- package/lib/host/pmo.js +114 -75
- package/lib/host/project-runtime.js +106 -106
- package/lib/host/service.js +53 -1
- package/lib/ledger/fold.js +37 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.89 - 2026-11-14
|
|
4
|
+
|
|
5
|
+
**有界自主:Human 每次操作后团队最多自主续开 `pmoMaxRounds` 批任务;心跳不再掩盖卡死任务(Issue #1 主因之二)**
|
|
6
|
+
|
|
7
|
+
一句「在吗」之后,看板一清空 PMO 就每 10 分钟开会、自拟下一批 Task,没有上限;主理人回收结果后
|
|
8
|
+
也会自己接着开卡。两条路径都不受控,是「7 小时 / 两百多个子代理」的另一半成因。
|
|
9
|
+
|
|
10
|
+
- 轮次口径(`lib/ledger/fold.js`,`FOLD_STATE_VERSION` 3→4,旧检查点作废重折):一「轮」=
|
|
11
|
+
看板清空后成员开出的新一批 Task,PMO 定时推进与主理人自己续开同一口径。任何 Human 作者事件
|
|
12
|
+
续满预算;Human 那一批不计轮;预算只由 Human 续,成员不能给自己续;
|
|
13
|
+
- 闸门(`lib/host/service.js`):成员在空看板上建卡且预算用尽 → `E_PMO_PAUSED`;PMO 定时推进
|
|
14
|
+
前同样查预算(`pmoGate`)。用尽时账本记 `project/pmo-capped`、主流发一条 milestone 告知暂停,
|
|
15
|
+
每份预算只告知一次,之后静默。Human 建卡不受限;
|
|
16
|
+
- 配置 `pmoMaxRounds`(默认 3,0 = 只做 Human 那一批);
|
|
17
|
+
- 心跳与巡检分时钟(`lib/host/pmo.js` `planTaskNudges`):心跳看 Thread 是否空闲,巡检(30 分钟)
|
|
18
|
+
与升级(60 分钟)只看 Task 状态是否变化。此前执行人每次回心跳都刷新唯一的时钟,卡死在
|
|
19
|
+
in_progress 的任务永远不会升级给 owner(实测每小时 6 次心跳,无尽头);
|
|
20
|
+
- 测试:`node --test` **314 通过 / 1 跳过**;新增 `pmo-rounds`(6 条:免费批、同批多卡不计轮、
|
|
21
|
+
定时推进与自主续开共用预算、只有 Human 能续、Human 建卡不受限、重启后保留)与
|
|
22
|
+
`pmo-nudges`(5 条,含 r06 卡死场景:30 分钟巡检、60 分钟升级);
|
|
23
|
+
- E2E(rc.1,隔离 DSH_HOME,上限 0):「在吗」→ 1 张卡 → 验收 → PMO 推进被挡、主流告知 1 次,
|
|
24
|
+
之后 12 分钟 0 次唤醒、0 张成员新卡、0 次重建。修复前(只闸定时推进)主理人在暂停后 4 秒
|
|
25
|
+
自己续开了 3 张卡并引发 27 次唤醒。
|
|
26
|
+
|
|
27
|
+
未覆盖:主流「在吗」仍会被唤醒提示逼着建卡(先对话后开卡);rc.2+ `startActivation` 参数形状。
|
|
28
|
+
|
|
3
29
|
## 0.4.88 - 2026-11-14
|
|
4
30
|
|
|
5
31
|
**成员唤醒只走 `subagents.sendMessage`,根除「唤醒即重建会话」(Issue #1 主因之一)**
|
package/index.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* The member runtime (real Agent sessions) lands in M2. Until then the
|
|
9
9
|
* ledger/domain service is the only writer and the Host never fakes work.
|
|
10
10
|
*/
|
|
11
|
+
import { planTaskNudges } from './lib/host/pmo.js';
|
|
11
12
|
import { homedir } from 'node:os';
|
|
12
13
|
import { join, sep } from 'node:path';
|
|
13
14
|
import { fileURLToPath } from 'node:url';
|
|
@@ -109,6 +110,9 @@ export const Config = z.object({
|
|
|
109
110
|
// 成员 shell 风险守卫:'warn' 只记诊断(默认),'block' 直接拒绝,'off' 不介入。
|
|
110
111
|
// 实机事故:成员写 serve.ps1 并用隐藏窗口拉起常驻进程,触发杀软报毒。
|
|
111
112
|
shellGuard: z.union(['off', 'warn', 'block']).default('warn'),
|
|
113
|
+
// 有界自主:Human 每次操作后,PMO 最多自主推进(无 active Task 时开会、自拟下一批卡)几轮;
|
|
114
|
+
// 用尽即暂停并在主流告知,等 Human 续。0 = 从不自主推进。Issue #1:一句「在吗」跑 7 小时。
|
|
115
|
+
pmoMaxRounds: z.number().step(1).min(0).max(100).default(3),
|
|
112
116
|
});
|
|
113
117
|
|
|
114
118
|
/**
|
|
@@ -224,6 +228,7 @@ async function boot(diag, config = {}) {
|
|
|
224
228
|
projectGoal: project.goal,
|
|
225
229
|
workspacePath: project.workspacePath ?? '',
|
|
226
230
|
diag,
|
|
231
|
+
pmoMaxRounds: config.pmoMaxRounds,
|
|
227
232
|
});
|
|
228
233
|
runtimes.set(project.id, runtime);
|
|
229
234
|
}
|
|
@@ -1138,67 +1143,21 @@ export function apply(ctx, config = {}) {
|
|
|
1138
1143
|
event: { type: 'pmo/dispatch', payload: { taskId: task.id, bucket: Math.floor(now / 60_000) } },
|
|
1139
1144
|
}, {});
|
|
1140
1145
|
}
|
|
1146
|
+
// 巡检提醒:两个时钟(Thread 闲 / 状态停滞)的判定在 planTaskNudges(lib/host/pmo.js)。
|
|
1147
|
+
const nudgeClocks = { review: pmoLastReview, heartbeat: pmoLastHeartbeat, escalate: pmoLastEscalate, stall: pmoLastStall };
|
|
1148
|
+
const nudgeEvent = {
|
|
1149
|
+
review: (task) => ({ type: 'pmo/review', payload: { taskId: task.id, bucket: Math.floor(now / 600_000) } }),
|
|
1150
|
+
heartbeat: (task) => ({ type: 'pmo/heartbeat', payload: { taskId: task.id, memberId: task.assigneeId ?? task.ownerId, bucket: Math.floor(now / 600_000) } }),
|
|
1151
|
+
escalate: (task) => ({ type: 'pmo/escalate', payload: { taskId: task.id, bucket: Math.floor(now / 3_600_000) } }),
|
|
1152
|
+
stall: (task) => ({ type: 'pmo/stall', payload: { taskId: task.id, bucket: Math.floor(now / 1_800_000) } }),
|
|
1153
|
+
};
|
|
1141
1154
|
for (const task of active) {
|
|
1142
|
-
const
|
|
1143
|
-
const
|
|
1144
|
-
const
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
const updatedAt = task.status === 'pending_acceptance'
|
|
1148
|
-
? taskAt
|
|
1149
|
-
: Math.max(taskAt, Number.isFinite(threadAt) ? threadAt : 0);
|
|
1150
|
-
if (updatedAt === 0) continue;
|
|
1151
|
-
const idleFor = now - updatedAt;
|
|
1152
|
-
if (task.status === 'pending_acceptance' && task.qaRequired === true && idleFor >= 10 * 60_000) {
|
|
1153
|
-
const lastReview = pmoLastReview.get(task.id) ?? 0;
|
|
1154
|
-
if (now - lastReview >= 10 * 60_000) {
|
|
1155
|
-
pmoLastReview.set(task.id, now);
|
|
1156
|
-
await wakeFromResult(projectRuntime, {
|
|
1157
|
-
event: { type: 'pmo/review', payload: { taskId: task.id, bucket: Math.floor(now / 600_000) } },
|
|
1158
|
-
}, {});
|
|
1159
|
-
}
|
|
1160
|
-
// Acceptance waiting on a Thread-only handoff needs the same
|
|
1161
|
-
// hourly escalation as in-progress work, or the review loop
|
|
1162
|
-
// nudges QA forever while the decided executor never wakes.
|
|
1163
|
-
if (idleFor >= 60 * 60_000) {
|
|
1164
|
-
const lastEscalate = pmoLastEscalate.get(task.id) ?? 0;
|
|
1165
|
-
if (now - lastEscalate >= 60 * 60_000) {
|
|
1166
|
-
pmoLastEscalate.set(task.id, now);
|
|
1167
|
-
await wakeFromResult(projectRuntime, {
|
|
1168
|
-
event: { type: 'pmo/escalate', payload: { taskId: task.id, bucket: Math.floor(now / 3_600_000) } },
|
|
1169
|
-
}, {});
|
|
1170
|
-
}
|
|
1171
|
-
}
|
|
1172
|
-
continue;
|
|
1173
|
-
}
|
|
1174
|
-
if (idleFor >= 10 * 60_000 && idleFor < 30 * 60_000) {
|
|
1175
|
-
const lastHeartbeat = pmoLastHeartbeat.get(task.id) ?? 0;
|
|
1176
|
-
if (now - lastHeartbeat >= 10 * 60_000) {
|
|
1177
|
-
pmoLastHeartbeat.set(task.id, now);
|
|
1178
|
-
await wakeFromResult(projectRuntime, {
|
|
1179
|
-
event: {
|
|
1180
|
-
type: 'pmo/heartbeat',
|
|
1181
|
-
payload: { taskId: task.id, memberId: task.assigneeId ?? task.ownerId, bucket: Math.floor(now / 600_000) },
|
|
1182
|
-
},
|
|
1183
|
-
}, {});
|
|
1184
|
-
}
|
|
1185
|
-
}
|
|
1186
|
-
if (idleFor >= 60 * 60_000) {
|
|
1187
|
-
const lastEscalate = pmoLastEscalate.get(task.id) ?? 0;
|
|
1188
|
-
if (now - lastEscalate >= 60 * 60_000) {
|
|
1189
|
-
pmoLastEscalate.set(task.id, now);
|
|
1190
|
-
await wakeFromResult(projectRuntime, {
|
|
1191
|
-
event: { type: 'pmo/escalate', payload: { taskId: task.id, bucket: Math.floor(now / 3_600_000) } },
|
|
1192
|
-
}, {});
|
|
1193
|
-
}
|
|
1155
|
+
const threadAt = state.threads?.[task.id]?.entries?.at(-1)?.at ?? null;
|
|
1156
|
+
const last = Object.fromEntries(Object.entries(nudgeClocks).map(([kind, map]) => [kind, map.get(task.id) ?? 0]));
|
|
1157
|
+
for (const kind of planTaskNudges(task, { threadAt, now, last })) {
|
|
1158
|
+
nudgeClocks[kind].set(task.id, now);
|
|
1159
|
+
await wakeFromResult(projectRuntime, { event: nudgeEvent[kind](task) }, {});
|
|
1194
1160
|
}
|
|
1195
|
-
if (idleFor < 30 * 60_000) continue;
|
|
1196
|
-
const lastPing = pmoLastStall.get(task.id) ?? 0;
|
|
1197
|
-
if (now - lastPing < 30 * 60_000) continue;
|
|
1198
|
-
pmoLastStall.set(task.id, now);
|
|
1199
|
-
await wakeFromResult(projectRuntime, {
|
|
1200
|
-
event: { type: 'pmo/stall', payload: { taskId: task.id, bucket: Math.floor(now / 1_800_000) } },
|
|
1201
|
-
}, {});
|
|
1202
1161
|
}
|
|
1203
1162
|
if (active.length > 0) {
|
|
1204
1163
|
// Prune per-task clock entries whose task left the active set, so
|
|
@@ -1218,6 +1177,9 @@ export function apply(ctx, config = {}) {
|
|
|
1218
1177
|
const last = pmoLastKick.get(projectRuntime.id) ?? 0;
|
|
1219
1178
|
if (now - last < 10 * 60_000) return;
|
|
1220
1179
|
pmoLastKick.set(projectRuntime.id, now);
|
|
1180
|
+
const gate = await projectRuntime.service.pmoGate(projectRuntime.id);
|
|
1181
|
+
diag.append({ ev: gate.admitted ? 'pmo.continue' : 'pmo.continue.paused', projectId: projectRuntime.id, used: gate.used, cap: gate.cap, freeWave: gate.freeWave, announcedNow: gate.announcedNow });
|
|
1182
|
+
if (!gate.admitted) return;
|
|
1221
1183
|
await wakeFromResult(projectRuntime, {
|
|
1222
1184
|
event: { type: 'pmo/continue', payload: { bucket: Math.floor(now / 600_000) } },
|
|
1223
1185
|
}, {});
|
|
@@ -2112,6 +2074,7 @@ export function apply(ctx, config = {}) {
|
|
|
2112
2074
|
projectGoal,
|
|
2113
2075
|
workspacePath,
|
|
2114
2076
|
diag,
|
|
2077
|
+
pmoMaxRounds: config.pmoMaxRounds,
|
|
2115
2078
|
});
|
|
2116
2079
|
booted.runtimes.set(nextProjectId, next);
|
|
2117
2080
|
attachRuntime(next);
|
package/lib/domain/errors.js
CHANGED
|
@@ -1,36 +1,37 @@
|
|
|
1
|
-
/** Stable domain errors; HTTP/tool adapters map `code` to user-facing text. */
|
|
2
|
-
export class DomainError extends Error {
|
|
3
|
-
/**
|
|
4
|
-
* @param {string} code - stable machine code, e.g. E_TASK_BLOCKED.
|
|
5
|
-
* @param {string} message - developer-readable message.
|
|
6
|
-
* @param {{ status?: number, details?: unknown }} [options]
|
|
7
|
-
*/
|
|
8
|
-
constructor(code, message, options = {}) {
|
|
9
|
-
super(message);
|
|
10
|
-
this.name = 'DomainError';
|
|
11
|
-
this.code = code;
|
|
12
|
-
this.status = options.status ?? 409;
|
|
13
|
-
this.details = options.details;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const ERRORS = {
|
|
18
|
-
NOT_FOUND: 'E_NOT_FOUND',
|
|
19
|
-
INVALID_STATE: 'E_INVALID_STATE',
|
|
20
|
-
UNAUTHORIZED: 'E_UNAUTHORIZED',
|
|
21
|
-
CONFLICT: 'E_CONFLICT',
|
|
22
|
-
REVISION: 'E_REVISION',
|
|
23
|
-
ALREADY_CLAIMED: 'E_ALREADY_CLAIMED',
|
|
24
|
-
BLOCKED: 'E_TASK_BLOCKED',
|
|
25
|
-
NOT_READY: 'E_TASK_NOT_READY',
|
|
26
|
-
NOT_ELIGIBLE: 'E_REVIEWER_NOT_ELIGIBLE',
|
|
27
|
-
STALE_REPLY: 'E_STALE_REPLY',
|
|
28
|
-
LIMIT: 'E_LIMIT',
|
|
29
|
-
IRREVERSIBLE_CONFIRM: 'E_IRREVERSIBLE_CONFIRM_REQUIRED',
|
|
30
|
-
INVALID_ARGUMENT: 'E_INVALID_ARGUMENT',
|
|
31
|
-
CONFIG_POLICY: 'E_CONFIG_POLICY',
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
1
|
+
/** Stable domain errors; HTTP/tool adapters map `code` to user-facing text. */
|
|
2
|
+
export class DomainError extends Error {
|
|
3
|
+
/**
|
|
4
|
+
* @param {string} code - stable machine code, e.g. E_TASK_BLOCKED.
|
|
5
|
+
* @param {string} message - developer-readable message.
|
|
6
|
+
* @param {{ status?: number, details?: unknown }} [options]
|
|
7
|
+
*/
|
|
8
|
+
constructor(code, message, options = {}) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = 'DomainError';
|
|
11
|
+
this.code = code;
|
|
12
|
+
this.status = options.status ?? 409;
|
|
13
|
+
this.details = options.details;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const ERRORS = {
|
|
18
|
+
NOT_FOUND: 'E_NOT_FOUND',
|
|
19
|
+
INVALID_STATE: 'E_INVALID_STATE',
|
|
20
|
+
UNAUTHORIZED: 'E_UNAUTHORIZED',
|
|
21
|
+
CONFLICT: 'E_CONFLICT',
|
|
22
|
+
REVISION: 'E_REVISION',
|
|
23
|
+
ALREADY_CLAIMED: 'E_ALREADY_CLAIMED',
|
|
24
|
+
BLOCKED: 'E_TASK_BLOCKED',
|
|
25
|
+
NOT_READY: 'E_TASK_NOT_READY',
|
|
26
|
+
NOT_ELIGIBLE: 'E_REVIEWER_NOT_ELIGIBLE',
|
|
27
|
+
STALE_REPLY: 'E_STALE_REPLY',
|
|
28
|
+
LIMIT: 'E_LIMIT',
|
|
29
|
+
IRREVERSIBLE_CONFIRM: 'E_IRREVERSIBLE_CONFIRM_REQUIRED',
|
|
30
|
+
INVALID_ARGUMENT: 'E_INVALID_ARGUMENT',
|
|
31
|
+
CONFIG_POLICY: 'E_CONFIG_POLICY',
|
|
32
|
+
PMO_PAUSED: 'E_PMO_PAUSED',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export function fail(code, message, options) {
|
|
36
|
+
throw new DomainError(code, message, options);
|
|
37
|
+
}
|
package/lib/host/pmo.js
CHANGED
|
@@ -1,75 +1,114 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PMO decision policy.
|
|
3
|
-
*
|
|
4
|
-
* Human is not in the loop when PMO auto mode is on: choose the recommendation
|
|
5
|
-
* when one exists, otherwise choose the option that protects delivery value
|
|
6
|
-
* (complete/core) over minimum-effort options. The answer is intentionally
|
|
7
|
-
* explicit so it is auditable in the Task Thread.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
const LOW_VALUE = /最小|暂缓|延后|不做|暂停|维持现状|先不|仅文档|只做骨架/i;
|
|
11
|
-
const HIGH_VALUE = /完整|核心|全量|推荐|生产可用|全平台|优先/i;
|
|
12
|
-
|
|
13
|
-
function clean(value) {
|
|
14
|
-
return typeof value === 'string' ? value.trim() : '';
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** 选项开头的字母编号(`B.` / `B、` / `B)` / `B:`)。 */
|
|
18
|
-
function optionLetter(value) {
|
|
19
|
-
const match = /^\s*[((]?([A-Za-z])[))..、::]/.exec(value);
|
|
20
|
-
return match === null ? null : match[1].toUpperCase();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** 建议里点名的选项字母(`建议 B` / `推荐:C` / `选 A`)。 */
|
|
24
|
-
function recommendationLetter(recommendation) {
|
|
25
|
-
const match = /(?:建议|推荐|选择|选|option|choose)\s*[::]?\s*[((]?([A-Za-z])\b/i.exec(recommendation)
|
|
26
|
-
?? /^\s*[((]?([A-Za-z])[))..、::]/.exec(recommendation);
|
|
27
|
-
return match === null ? null : match[1].toUpperCase();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** 显式建议命中哪个选项:字母编号优先,其次双向包含。 */
|
|
31
|
-
function explicitPick(options, recommendation) {
|
|
32
|
-
if (recommendation === '') return null;
|
|
33
|
-
const letter = recommendationLetter(recommendation);
|
|
34
|
-
if (letter !== null) {
|
|
35
|
-
const byLetter = options.find((option) => optionLetter(option) === letter);
|
|
36
|
-
if (byLetter !== undefined) return byLetter;
|
|
37
|
-
}
|
|
38
|
-
return options.find((option) => recommendation.includes(option) || option.includes(recommendation)) ?? null;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function scoreOption(option, question) {
|
|
42
|
-
const value = clean(option);
|
|
43
|
-
if (value === '') return -100;
|
|
44
|
-
let score = 0;
|
|
45
|
-
if (/推荐/i.test(value)) score += 20;
|
|
46
|
-
if (HIGH_VALUE.test(value)) score += 12;
|
|
47
|
-
if (/B\b|C\b|核心|完整/i.test(value)) score += 6;
|
|
48
|
-
if (LOW_VALUE.test(value)) score -= 20;
|
|
49
|
-
if (/A\b|最小/i.test(value)) score -= 8;
|
|
50
|
-
const recommendation = clean(question?.recommendation);
|
|
51
|
-
if (recommendation !== '' && recommendation.includes(value)) score += 30;
|
|
52
|
-
if (recommendation !== '' && value.includes(recommendation)) score += 20;
|
|
53
|
-
return score;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** Return [ { id, value } ] for every question. */
|
|
57
|
-
export function chooseDecisionAnswers(questions) {
|
|
58
|
-
return (Array.isArray(questions) ? questions : []).map((question, index) => {
|
|
59
|
-
const id = typeof question?.id === 'string' && question.id !== '' ? question.id : `q${index + 1}`;
|
|
60
|
-
const options = Array.isArray(question?.options) ? question.options.map(clean).filter(Boolean) : [];
|
|
61
|
-
const recommendation = clean(question?.recommendation);
|
|
62
|
-
if (options.length > 0) {
|
|
63
|
-
// 问题里给了明确建议就按建议选——只有没有建议、或建议对不上任何选项时,
|
|
64
|
-
// 才退回关键字打分。否则「建议 A」可能被关键词打分选成 B,PMO 自动决策
|
|
65
|
-
// 就与问题给出的建议相反。
|
|
66
|
-
const explicit = explicitPick(options, recommendation);
|
|
67
|
-
if (explicit !== null) return { id, value: explicit };
|
|
68
|
-
const picked = options
|
|
69
|
-
.map((option) => ({ option, score: scoreOption(option, question) }))
|
|
70
|
-
.sort((left, right) => right.score - left.score)[0];
|
|
71
|
-
return { id, value: picked?.option || recommendation || '按完整核心方案执行' };
|
|
72
|
-
}
|
|
73
|
-
return { id, value: recommendation || '按完整、可验收、长期价值最高的方案执行' };
|
|
74
|
-
});
|
|
75
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* PMO decision policy.
|
|
3
|
+
*
|
|
4
|
+
* Human is not in the loop when PMO auto mode is on: choose the recommendation
|
|
5
|
+
* when one exists, otherwise choose the option that protects delivery value
|
|
6
|
+
* (complete/core) over minimum-effort options. The answer is intentionally
|
|
7
|
+
* explicit so it is auditable in the Task Thread.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const LOW_VALUE = /最小|暂缓|延后|不做|暂停|维持现状|先不|仅文档|只做骨架/i;
|
|
11
|
+
const HIGH_VALUE = /完整|核心|全量|推荐|生产可用|全平台|优先/i;
|
|
12
|
+
|
|
13
|
+
function clean(value) {
|
|
14
|
+
return typeof value === 'string' ? value.trim() : '';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** 选项开头的字母编号(`B.` / `B、` / `B)` / `B:`)。 */
|
|
18
|
+
function optionLetter(value) {
|
|
19
|
+
const match = /^\s*[((]?([A-Za-z])[))..、::]/.exec(value);
|
|
20
|
+
return match === null ? null : match[1].toUpperCase();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** 建议里点名的选项字母(`建议 B` / `推荐:C` / `选 A`)。 */
|
|
24
|
+
function recommendationLetter(recommendation) {
|
|
25
|
+
const match = /(?:建议|推荐|选择|选|option|choose)\s*[::]?\s*[((]?([A-Za-z])\b/i.exec(recommendation)
|
|
26
|
+
?? /^\s*[((]?([A-Za-z])[))..、::]/.exec(recommendation);
|
|
27
|
+
return match === null ? null : match[1].toUpperCase();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** 显式建议命中哪个选项:字母编号优先,其次双向包含。 */
|
|
31
|
+
function explicitPick(options, recommendation) {
|
|
32
|
+
if (recommendation === '') return null;
|
|
33
|
+
const letter = recommendationLetter(recommendation);
|
|
34
|
+
if (letter !== null) {
|
|
35
|
+
const byLetter = options.find((option) => optionLetter(option) === letter);
|
|
36
|
+
if (byLetter !== undefined) return byLetter;
|
|
37
|
+
}
|
|
38
|
+
return options.find((option) => recommendation.includes(option) || option.includes(recommendation)) ?? null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function scoreOption(option, question) {
|
|
42
|
+
const value = clean(option);
|
|
43
|
+
if (value === '') return -100;
|
|
44
|
+
let score = 0;
|
|
45
|
+
if (/推荐/i.test(value)) score += 20;
|
|
46
|
+
if (HIGH_VALUE.test(value)) score += 12;
|
|
47
|
+
if (/B\b|C\b|核心|完整/i.test(value)) score += 6;
|
|
48
|
+
if (LOW_VALUE.test(value)) score -= 20;
|
|
49
|
+
if (/A\b|最小/i.test(value)) score -= 8;
|
|
50
|
+
const recommendation = clean(question?.recommendation);
|
|
51
|
+
if (recommendation !== '' && recommendation.includes(value)) score += 30;
|
|
52
|
+
if (recommendation !== '' && value.includes(recommendation)) score += 20;
|
|
53
|
+
return score;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Return [ { id, value } ] for every question. */
|
|
57
|
+
export function chooseDecisionAnswers(questions) {
|
|
58
|
+
return (Array.isArray(questions) ? questions : []).map((question, index) => {
|
|
59
|
+
const id = typeof question?.id === 'string' && question.id !== '' ? question.id : `q${index + 1}`;
|
|
60
|
+
const options = Array.isArray(question?.options) ? question.options.map(clean).filter(Boolean) : [];
|
|
61
|
+
const recommendation = clean(question?.recommendation);
|
|
62
|
+
if (options.length > 0) {
|
|
63
|
+
// 问题里给了明确建议就按建议选——只有没有建议、或建议对不上任何选项时,
|
|
64
|
+
// 才退回关键字打分。否则「建议 A」可能被关键词打分选成 B,PMO 自动决策
|
|
65
|
+
// 就与问题给出的建议相反。
|
|
66
|
+
const explicit = explicitPick(options, recommendation);
|
|
67
|
+
if (explicit !== null) return { id, value: explicit };
|
|
68
|
+
const picked = options
|
|
69
|
+
.map((option) => ({ option, score: scoreOption(option, question) }))
|
|
70
|
+
.sort((left, right) => right.score - left.score)[0];
|
|
71
|
+
return { id, value: picked?.option || recommendation || '按完整核心方案执行' };
|
|
72
|
+
}
|
|
73
|
+
return { id, value: recommendation || '按完整、可验收、长期价值最高的方案执行' };
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const MINUTE = 60_000;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* PMO 巡检对一张 active Task 该发哪些提醒(按序:review / heartbeat / escalate / stall)。
|
|
81
|
+
*
|
|
82
|
+
* 两个时钟分开:
|
|
83
|
+
* - threadIdle:Thread 最后一条或 Task 状态变化以来——只用来判断「该发心跳了」;
|
|
84
|
+
* - stateIdle:Task 状态(claim/submit/accept…)最后一次变化以来——判断巡检与升级。
|
|
85
|
+
* 实机(r06):执行人把交付写在 Thread 里 @ 评审、没有 submit,于是每 10 分钟的心跳
|
|
86
|
+
* 回帖都刷新了单一时钟,巡检(30 分钟)与升级(60 分钟)永远不触发,owner 从未被叫来,
|
|
87
|
+
* 心跳每小时 6 次无休止。回帖不是进展,状态变化才是。
|
|
88
|
+
* 验收中的 Task 只认状态时钟(执行人的 Thread 闲聊不能掩盖沉默的 QA)。
|
|
89
|
+
*
|
|
90
|
+
* @param {any} task
|
|
91
|
+
* @param {{ threadAt?: number|null, now: number, last?: Record<string, number> }} options
|
|
92
|
+
* last:每种提醒上次发出的时间(review/heartbeat/escalate/stall)。
|
|
93
|
+
* @returns {Array<'review'|'heartbeat'|'escalate'|'stall'>}
|
|
94
|
+
*/
|
|
95
|
+
export function planTaskNudges(task, { threadAt = null, now, last = {} }) {
|
|
96
|
+
const taskAt = Number.isFinite(task?.updatedAt) ? task.updatedAt : 0;
|
|
97
|
+
if (taskAt === 0) return [];
|
|
98
|
+
const stateIdle = now - taskAt;
|
|
99
|
+
const threadIdle = task.status === 'pending_acceptance'
|
|
100
|
+
? stateIdle
|
|
101
|
+
: now - Math.max(taskAt, Number.isFinite(threadAt) ? threadAt : 0);
|
|
102
|
+
const due = (kind, every) => now - (last[kind] ?? 0) >= every;
|
|
103
|
+
const out = [];
|
|
104
|
+
if (task.status === 'pending_acceptance' && task.qaRequired === true) {
|
|
105
|
+
if (stateIdle < 10 * MINUTE) return out;
|
|
106
|
+
if (due('review', 10 * MINUTE)) out.push('review');
|
|
107
|
+
if (stateIdle >= 60 * MINUTE && due('escalate', 60 * MINUTE)) out.push('escalate');
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
if (threadIdle >= 10 * MINUTE && stateIdle < 30 * MINUTE && due('heartbeat', 10 * MINUTE)) out.push('heartbeat');
|
|
111
|
+
if (stateIdle >= 60 * MINUTE && due('escalate', 60 * MINUTE)) out.push('escalate');
|
|
112
|
+
if (stateIdle >= 30 * MINUTE && due('stall', 30 * MINUTE)) out.push('stall');
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* One Project runtime: its own ledger, TeamService and optional SSE/waker hooks.
|
|
3
|
-
*
|
|
4
|
-
* A Project is the isolation boundary required by the ledger writer: every
|
|
5
|
-
* ledger event must carry exactly this Project's id. ProjectRuntime wraps the
|
|
6
|
-
* default Project first, so multiple runtimes can be mounted later without
|
|
7
|
-
* changing the single-project behaviour.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { mkdirSync } from 'node:fs';
|
|
11
|
-
import { join } from 'node:path';
|
|
12
|
-
import { FOLD_STATE_VERSION } from '../ledger/fold.js';
|
|
13
|
-
import { openLedger } from '../ledger/writer.js';
|
|
14
|
-
import { seedDefaultRoster } from './default-roster.js';
|
|
15
|
-
import { TeamService } from './service.js';
|
|
16
|
-
|
|
17
|
-
export const DEFAULT_PROJECT_ID = 'prj_main';
|
|
18
|
-
export const HUMAN_ID = 'mem_human';
|
|
19
|
-
|
|
20
|
-
export class ProjectRuntime {
|
|
21
|
-
constructor({ id, rootDir, dir, ledger, service }) {
|
|
22
|
-
this.id = id;
|
|
23
|
-
this.rootDir = rootDir;
|
|
24
|
-
this.dir = dir;
|
|
25
|
-
this.ledger = ledger;
|
|
26
|
-
this.service = service;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
static async open({ rootDir, projectId = DEFAULT_PROJECT_ID, now = undefined, seed = true, projectName = '我的项目', projectGoal = '把事交给团队', workspacePath = '', diag = null }) {
|
|
30
|
-
const dir = join(rootDir, 'projects', projectId);
|
|
31
|
-
mkdirSync(dir, { recursive: true });
|
|
32
|
-
const ledger = openLedger({
|
|
33
|
-
dir,
|
|
34
|
-
projectId,
|
|
35
|
-
fsync: true,
|
|
36
|
-
// 检查点接线:boot 从投影地板续放尾部,跳过全量 fold;每 500 次
|
|
37
|
-
// 追加与 close 前落盘,崩溃窗口有界(账本本体不受影响)。
|
|
38
|
-
checkpoint: { stateVersion: FOLD_STATE_VERSION, saveEvery: 500 },
|
|
39
|
-
});
|
|
40
|
-
const service = new TeamService({ ledger, now, diag });
|
|
41
|
-
const runtime = new ProjectRuntime({ id: projectId, rootDir, dir, ledger, service });
|
|
42
|
-
|
|
43
|
-
const recovery = ledger.recovery;
|
|
44
|
-
if (recovery !== null && recovery !== undefined) {
|
|
45
|
-
diag?.append({
|
|
46
|
-
ev: 'ledger.checkpoint',
|
|
47
|
-
projectId,
|
|
48
|
-
source: recovery.source,
|
|
49
|
-
fromSeq: recovery.fromSeq,
|
|
50
|
-
errors: recovery.errors?.length ?? 0,
|
|
51
|
-
saved: recovery.saved ?? null,
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const repairs = ledger.opened?.repairs ?? (ledger.opened?.repair ? [ledger.opened.repair] : []);
|
|
56
|
-
if (repairs.length > 0) {
|
|
57
|
-
diag?.append({ ev: 'ledger.repair', projectId, repairs });
|
|
58
|
-
await ledger.append({
|
|
59
|
-
type: 'ledger/repaired',
|
|
60
|
-
payload: { repairs },
|
|
61
|
-
actor: { kind: 'system' },
|
|
62
|
-
projectId,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
diag?.append({
|
|
66
|
-
ev: 'ledger.open',
|
|
67
|
-
projectId,
|
|
68
|
-
events: ledger.headSeq,
|
|
69
|
-
head: ledger.head.seq,
|
|
70
|
-
segments: ledger.opened?.segments ?? null,
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
if (seed) {
|
|
74
|
-
const state = service.state;
|
|
75
|
-
if (state.members?.[HUMAN_ID] === undefined) {
|
|
76
|
-
await service.dispatch({
|
|
77
|
-
type: 'member.add',
|
|
78
|
-
actor: { kind: 'human', memberId: HUMAN_ID },
|
|
79
|
-
projectId,
|
|
80
|
-
payload: { id: HUMAN_ID, name: '你', kind: 'human', role: 'Human' },
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
if (state.projects?.[projectId] === undefined) {
|
|
84
|
-
await service.dispatch({
|
|
85
|
-
type: 'project.create',
|
|
86
|
-
actor: { kind: 'human', memberId: HUMAN_ID },
|
|
87
|
-
projectId,
|
|
88
|
-
// 播种是内部路径:允许先建一个「待设定目录」的默认项目,用户在首次使用
|
|
89
|
-
// 引导里选定目录后再 project.workspace.update。
|
|
90
|
-
payload: { id: projectId, name: projectName, goal: projectGoal, workspacePath, seed: true },
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
await seedDefaultRoster(service, projectId, { humanId: HUMAN_ID });
|
|
94
|
-
await service.backfillHumanMentions(state.projects?.[projectId]?.workspacePath ?? '');
|
|
95
|
-
}
|
|
96
|
-
return runtime;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
close() {
|
|
100
|
-
try {
|
|
101
|
-
this.ledger?.close?.();
|
|
102
|
-
} catch {
|
|
103
|
-
/* already closed */
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* One Project runtime: its own ledger, TeamService and optional SSE/waker hooks.
|
|
3
|
+
*
|
|
4
|
+
* A Project is the isolation boundary required by the ledger writer: every
|
|
5
|
+
* ledger event must carry exactly this Project's id. ProjectRuntime wraps the
|
|
6
|
+
* default Project first, so multiple runtimes can be mounted later without
|
|
7
|
+
* changing the single-project behaviour.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { mkdirSync } from 'node:fs';
|
|
11
|
+
import { join } from 'node:path';
|
|
12
|
+
import { FOLD_STATE_VERSION } from '../ledger/fold.js';
|
|
13
|
+
import { openLedger } from '../ledger/writer.js';
|
|
14
|
+
import { seedDefaultRoster } from './default-roster.js';
|
|
15
|
+
import { TeamService } from './service.js';
|
|
16
|
+
|
|
17
|
+
export const DEFAULT_PROJECT_ID = 'prj_main';
|
|
18
|
+
export const HUMAN_ID = 'mem_human';
|
|
19
|
+
|
|
20
|
+
export class ProjectRuntime {
|
|
21
|
+
constructor({ id, rootDir, dir, ledger, service }) {
|
|
22
|
+
this.id = id;
|
|
23
|
+
this.rootDir = rootDir;
|
|
24
|
+
this.dir = dir;
|
|
25
|
+
this.ledger = ledger;
|
|
26
|
+
this.service = service;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static async open({ rootDir, projectId = DEFAULT_PROJECT_ID, now = undefined, seed = true, projectName = '我的项目', projectGoal = '把事交给团队', workspacePath = '', diag = null, pmoMaxRounds = undefined }) {
|
|
30
|
+
const dir = join(rootDir, 'projects', projectId);
|
|
31
|
+
mkdirSync(dir, { recursive: true });
|
|
32
|
+
const ledger = openLedger({
|
|
33
|
+
dir,
|
|
34
|
+
projectId,
|
|
35
|
+
fsync: true,
|
|
36
|
+
// 检查点接线:boot 从投影地板续放尾部,跳过全量 fold;每 500 次
|
|
37
|
+
// 追加与 close 前落盘,崩溃窗口有界(账本本体不受影响)。
|
|
38
|
+
checkpoint: { stateVersion: FOLD_STATE_VERSION, saveEvery: 500 },
|
|
39
|
+
});
|
|
40
|
+
const service = new TeamService({ ledger, now, diag, pmoMaxRounds });
|
|
41
|
+
const runtime = new ProjectRuntime({ id: projectId, rootDir, dir, ledger, service });
|
|
42
|
+
|
|
43
|
+
const recovery = ledger.recovery;
|
|
44
|
+
if (recovery !== null && recovery !== undefined) {
|
|
45
|
+
diag?.append({
|
|
46
|
+
ev: 'ledger.checkpoint',
|
|
47
|
+
projectId,
|
|
48
|
+
source: recovery.source,
|
|
49
|
+
fromSeq: recovery.fromSeq,
|
|
50
|
+
errors: recovery.errors?.length ?? 0,
|
|
51
|
+
saved: recovery.saved ?? null,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const repairs = ledger.opened?.repairs ?? (ledger.opened?.repair ? [ledger.opened.repair] : []);
|
|
56
|
+
if (repairs.length > 0) {
|
|
57
|
+
diag?.append({ ev: 'ledger.repair', projectId, repairs });
|
|
58
|
+
await ledger.append({
|
|
59
|
+
type: 'ledger/repaired',
|
|
60
|
+
payload: { repairs },
|
|
61
|
+
actor: { kind: 'system' },
|
|
62
|
+
projectId,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
diag?.append({
|
|
66
|
+
ev: 'ledger.open',
|
|
67
|
+
projectId,
|
|
68
|
+
events: ledger.headSeq,
|
|
69
|
+
head: ledger.head.seq,
|
|
70
|
+
segments: ledger.opened?.segments ?? null,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
if (seed) {
|
|
74
|
+
const state = service.state;
|
|
75
|
+
if (state.members?.[HUMAN_ID] === undefined) {
|
|
76
|
+
await service.dispatch({
|
|
77
|
+
type: 'member.add',
|
|
78
|
+
actor: { kind: 'human', memberId: HUMAN_ID },
|
|
79
|
+
projectId,
|
|
80
|
+
payload: { id: HUMAN_ID, name: '你', kind: 'human', role: 'Human' },
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (state.projects?.[projectId] === undefined) {
|
|
84
|
+
await service.dispatch({
|
|
85
|
+
type: 'project.create',
|
|
86
|
+
actor: { kind: 'human', memberId: HUMAN_ID },
|
|
87
|
+
projectId,
|
|
88
|
+
// 播种是内部路径:允许先建一个「待设定目录」的默认项目,用户在首次使用
|
|
89
|
+
// 引导里选定目录后再 project.workspace.update。
|
|
90
|
+
payload: { id: projectId, name: projectName, goal: projectGoal, workspacePath, seed: true },
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
await seedDefaultRoster(service, projectId, { humanId: HUMAN_ID });
|
|
94
|
+
await service.backfillHumanMentions(state.projects?.[projectId]?.workspacePath ?? '');
|
|
95
|
+
}
|
|
96
|
+
return runtime;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
close() {
|
|
100
|
+
try {
|
|
101
|
+
this.ledger?.close?.();
|
|
102
|
+
} catch {
|
|
103
|
+
/* already closed */
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
package/lib/host/service.js
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
import { appendReply, createThread } from '../domain/thread.js';
|
|
23
23
|
import { boardView, quadrantsView, taskCard } from './views.js';
|
|
24
24
|
import { applyMemberConfigPatch, normalizeMemberConfig } from '../domain/member-config.js';
|
|
25
|
-
import { MEMBER_STATUS } from '../ledger/fold.js';
|
|
25
|
+
import { MEMBER_STATUS, isBoardIdle } from '../ledger/fold.js';
|
|
26
26
|
|
|
27
27
|
const MEMBER_STATUS_VALUES = new Set(Object.values(MEMBER_STATUS));
|
|
28
28
|
import { isQaMember, unfinishedTasksFor } from '../domain/member-profile.js';
|
|
@@ -122,6 +122,8 @@ export class TeamService {
|
|
|
122
122
|
this.memberConfigPolicy = options.memberConfigPolicy ?? {};
|
|
123
123
|
/** Diagnostic sink ({ append(row) }); optional so tests run without it. */
|
|
124
124
|
this.diag = options.diag ?? null;
|
|
125
|
+
/** 有界自主:Human 那一批之外允许自主续开的批次数(配置 pmoMaxRounds)。 */
|
|
126
|
+
this.pmoMaxRounds = Number.isSafeInteger(options.pmoMaxRounds) ? options.pmoMaxRounds : 3;
|
|
125
127
|
}
|
|
126
128
|
|
|
127
129
|
get state() {
|
|
@@ -1144,6 +1146,15 @@ export class TeamService {
|
|
|
1144
1146
|
const projectId = command.projectId;
|
|
1145
1147
|
const project = state.projects?.[projectId];
|
|
1146
1148
|
if (project === undefined) fail(ERRORS.NOT_FOUND, `project ${String(projectId)} not found`);
|
|
1149
|
+
// 有界自主:空看板上成员开新一批 = 一轮自主续开;预算用尽即拒绝(Issue #1:
|
|
1150
|
+
// 回收结果后主理人自己续开,绕过了 PMO 定时推进的闸门)。Human 建卡不受限。
|
|
1151
|
+
if (command.actor.kind === 'agent' && isBoardIdle(state)) {
|
|
1152
|
+
const budget = this.pmoBudget();
|
|
1153
|
+
if (budget.exhausted) {
|
|
1154
|
+
await this.announcePmoPause(projectId, budget);
|
|
1155
|
+
fail(ERRORS.PMO_PAUSED, `PMO 已暂停:自 Human 上一次操作以来已自主续开 ${budget.used} 批任务(上限 ${budget.cap})。不要再建卡,也不要改用其它方式绕开;在当前回合结束,等待 Human 的下一条指令。`);
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1147
1158
|
const number = Math.max(0, ...Object.values(state.tasks ?? {}).map((task) => task.number ?? 0)) + 1;
|
|
1148
1159
|
const ownerId = payload.ownerId ?? project.ownerMemberId ?? project.ownerId;
|
|
1149
1160
|
const qaRequired = payload.qaRequired === true;
|
|
@@ -1368,6 +1379,47 @@ export class TeamService {
|
|
|
1368
1379
|
});
|
|
1369
1380
|
}
|
|
1370
1381
|
|
|
1382
|
+
/**
|
|
1383
|
+
* 有界自主预算(对齐官方 /goal 的 maxGoalRounds;计数口径见 fold.applyEvent)。
|
|
1384
|
+
* exhausted:Human 那一批已开过,且自主开出的新批次已达上限——此时空看板上成员不得再建卡,
|
|
1385
|
+
* PMO 也不再定时推进。`cap = 0` 表示 Human 那一批之外从不自主续开。
|
|
1386
|
+
*/
|
|
1387
|
+
pmoBudget(cap = this.pmoMaxRounds) {
|
|
1388
|
+
const used = this.state.pmoRoundsUsed ?? 0;
|
|
1389
|
+
const freeWave = this.state.pmoFreeWave !== false;
|
|
1390
|
+
return { used, cap, freeWave, exhausted: !freeWave && used >= cap, announced: this.state.pmoCapped === true };
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
/** 预算用尽时告知一次(账本 `project/pmo-capped` + 主流 milestone),之后静默。调用方须已持有 runExclusive。 */
|
|
1394
|
+
async announcePmoPause(projectId, budget) {
|
|
1395
|
+
if (budget.announced) return false;
|
|
1396
|
+
const actor = { kind: 'system', memberId: 'mem_pmo' };
|
|
1397
|
+
await this.ledger.append({ type: 'project/pmo-capped', payload: { projectId, rounds: budget.used, cap: budget.cap }, actor, projectId, at: this.now() });
|
|
1398
|
+
await this.ledger.append({
|
|
1399
|
+
type: 'stream/posted',
|
|
1400
|
+
payload: {
|
|
1401
|
+
kind: 'milestone',
|
|
1402
|
+
authorId: 'mem_pmo',
|
|
1403
|
+
body: `PMO 已在你上一次操作后自主续开 ${budget.used} 批任务(上限 ${budget.cap}),现在暂停,等待你的指令。发一条消息、新建或重开任务即可继续。`,
|
|
1404
|
+
},
|
|
1405
|
+
actor,
|
|
1406
|
+
projectId,
|
|
1407
|
+
at: this.now(),
|
|
1408
|
+
});
|
|
1409
|
+
this.diag?.append({ ev: 'pmo.paused', projectId, rounds: budget.used, cap: budget.cap });
|
|
1410
|
+
return true;
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
/** PMO 定时推进前调用:预算内放行;用尽则告知一次并拒绝。 */
|
|
1414
|
+
pmoGate(projectId, cap = this.pmoMaxRounds) {
|
|
1415
|
+
return this.runExclusive(async () => {
|
|
1416
|
+
const budget = this.pmoBudget(cap);
|
|
1417
|
+
if (!budget.exhausted) return { admitted: true, ...budget, announcedNow: false };
|
|
1418
|
+
const announcedNow = await this.announcePmoPause(projectId, budget);
|
|
1419
|
+
return { admitted: false, ...budget, announcedNow };
|
|
1420
|
+
});
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1371
1423
|
/** PMO: answer all pending structured questions with the max-value policy. */
|
|
1372
1424
|
async autoAnswerDecisions(projectId = Object.keys(this.state.projects ?? {})[0]) {
|
|
1373
1425
|
const humanId = this.humanId();
|
package/lib/ledger/fold.js
CHANGED
|
@@ -40,8 +40,11 @@ import { isReviewCandidate } from '../domain/policy.js';
|
|
|
40
40
|
* 同时更新 ownerId。旧 checkpoint(v2)里仍带着旧语义的投影,必须作废重折,
|
|
41
41
|
* 否则升级后「前 owner 仍通过 isLead」「接管继任者仍被排除在验收候选外」会
|
|
42
42
|
* 被零尾放永久保留。
|
|
43
|
+
*
|
|
44
|
+
* v4:新增有界自主投影 `pmoFreeWave` / `pmoRoundsUsed` / `pmoCapped`(见 applyEvent);
|
|
45
|
+
* 旧 checkpoint 没有这些字段,作废重折。
|
|
43
46
|
*/
|
|
44
|
-
export const FOLD_STATE_VERSION =
|
|
47
|
+
export const FOLD_STATE_VERSION = 4;
|
|
45
48
|
|
|
46
49
|
/**
|
|
47
50
|
* 投影封顶:大规模/长迭代账本下,stream 与每个 Thread 的 entries 不随事件数
|
|
@@ -655,8 +658,37 @@ function applyFollow(state, event, payload, following) {
|
|
|
655
658
|
|
|
656
659
|
/**
|
|
657
660
|
* 应用一个事件。未知事件、已应用事件、非法结构一律返回原 state 引用。
|
|
661
|
+
*
|
|
662
|
+
* 有界自主(对齐官方 /goal 的 maxGoalRounds)。一「轮」= 看板清空后由成员开出新一批 Task
|
|
663
|
+
* ——不论是 PMO 定时推进还是主理人回收结果后自己续开,口径只有这一个:
|
|
664
|
+
* - 任何 Human 作者的事件:`pmoFreeWave = true`、`pmoRoundsUsed = 0`、`pmoCapped = false`;
|
|
665
|
+
* - 成员在空看板上建卡:有 freeWave 则消耗它(这是 Human 指令的那一批),否则 `pmoRoundsUsed + 1`;
|
|
666
|
+
* - `project/pmo-capped`:本份预算已告知暂停(只告知一次)。
|
|
667
|
+
* 预算只由 Human 续,成员不能给自己续。闸门在 service(createTask / pmoGate)。
|
|
658
668
|
*/
|
|
659
669
|
export function applyEvent(state, event) {
|
|
670
|
+
const next = applyEventCore(state, event);
|
|
671
|
+
if (next === state) return next;
|
|
672
|
+
if (event.type === 'project/pmo-capped') return { ...next, pmoCapped: true };
|
|
673
|
+
if (event.actor?.kind === 'human') {
|
|
674
|
+
if (next.pmoFreeWave === true && (next.pmoRoundsUsed ?? 0) === 0 && next.pmoCapped !== true) return next;
|
|
675
|
+
return { ...next, pmoFreeWave: true, pmoRoundsUsed: 0, pmoCapped: false };
|
|
676
|
+
}
|
|
677
|
+
if (event.type === 'task/created' && event.actor?.kind === 'agent' && isBoardIdle(state)) {
|
|
678
|
+
if (state.pmoFreeWave !== false) return { ...next, pmoFreeWave: false };
|
|
679
|
+
return { ...next, pmoRoundsUsed: (state.pmoRoundsUsed ?? 0) + 1 };
|
|
680
|
+
}
|
|
681
|
+
return next;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
const BOARD_ACTIVE_STATUSES = new Set(['pending', 'in_progress', 'pending_acceptance']);
|
|
685
|
+
|
|
686
|
+
/** 看板上没有进行中的 Task(与 pmoTick 的 active 口径一致)。 */
|
|
687
|
+
export function isBoardIdle(state) {
|
|
688
|
+
return !Object.values(state.tasks ?? {}).some((task) => task.tombstone !== true && BOARD_ACTIVE_STATUSES.has(task.status));
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
function applyEventCore(state, event) {
|
|
660
692
|
if (!isPlainObject(state)) throw new TypeError('applyEvent: state must be a plain object');
|
|
661
693
|
if (!isEventLike(event)) return state;
|
|
662
694
|
if (event.seq <= (Number.isSafeInteger(state.lastSeq) ? state.lastSeq : 0)) return state;
|
|
@@ -670,6 +702,10 @@ export function applyEvent(state, event) {
|
|
|
670
702
|
return advance(state, event, { projects: { ...state.projects, [project.id]: project } });
|
|
671
703
|
}
|
|
672
704
|
|
|
705
|
+
case 'project/pmo-capped':
|
|
706
|
+
// 计数在 applyEvent 外层;这里只推进 seq,使事件「已应用」。
|
|
707
|
+
return advance(state, event);
|
|
708
|
+
|
|
673
709
|
case 'project/pmo-updated': {
|
|
674
710
|
const projectId = textOr(payload.projectId, event.projectId);
|
|
675
711
|
const project = state.projects?.[projectId];
|
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.89",
|
|
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",
|