@suifei/dsh-ai-team 0.4.88 → 0.4.90

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/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
+ }
@@ -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() {
@@ -679,11 +681,16 @@ export class TeamService {
679
681
  // 并发下还会重复——曾造成 API 返回值与投影不一致)。
680
682
  // kind 必须反映真实作者:`human_message` 是 Waker 判定「Human 下了指令」的
681
683
  // 唯一依据(会触发建卡唤醒),agent 发言若也标成它,等于让 agent 冒充 Human。
684
+ // taskIds:PMO 在主对话里附上的任务卡(界面就地渲染);只收本项目真实存在的卡。
685
+ const taskIds = Array.isArray(payload.taskIds)
686
+ ? [...new Set(payload.taskIds.filter((id) => typeof id === 'string' && Object.hasOwn(this.state.tasks ?? {}, id)))]
687
+ : [];
682
688
  const entry = {
683
689
  kind: command.actor.kind === 'human' ? 'human_message' : 'milestone',
684
690
  authorId: author.id,
685
691
  body,
686
692
  at: this.now(),
693
+ ...(taskIds.length > 0 ? { taskIds } : {}),
687
694
  };
688
695
  const event = await this.ledger.append({
689
696
  type: 'stream/posted',
@@ -1144,6 +1151,15 @@ export class TeamService {
1144
1151
  const projectId = command.projectId;
1145
1152
  const project = state.projects?.[projectId];
1146
1153
  if (project === undefined) fail(ERRORS.NOT_FOUND, `project ${String(projectId)} not found`);
1154
+ // 有界自主:空看板上成员开新一批 = 一轮自主续开;预算用尽即拒绝(Issue #1:
1155
+ // 回收结果后主理人自己续开,绕过了 PMO 定时推进的闸门)。Human 建卡不受限。
1156
+ if (command.actor.kind === 'agent' && isBoardIdle(state)) {
1157
+ const budget = this.pmoBudget();
1158
+ if (budget.exhausted) {
1159
+ await this.announcePmoPause(projectId, budget);
1160
+ fail(ERRORS.PMO_PAUSED, `PMO 已暂停:自 Human 上一次操作以来已自主续开 ${budget.used} 批任务(上限 ${budget.cap})。不要再建卡,也不要改用其它方式绕开;在当前回合结束,等待 Human 的下一条指令。`);
1161
+ }
1162
+ }
1147
1163
  const number = Math.max(0, ...Object.values(state.tasks ?? {}).map((task) => task.number ?? 0)) + 1;
1148
1164
  const ownerId = payload.ownerId ?? project.ownerMemberId ?? project.ownerId;
1149
1165
  const qaRequired = payload.qaRequired === true;
@@ -1368,6 +1384,47 @@ export class TeamService {
1368
1384
  });
1369
1385
  }
1370
1386
 
1387
+ /**
1388
+ * 有界自主预算(对齐官方 /goal 的 maxGoalRounds;计数口径见 fold.applyEvent)。
1389
+ * exhausted:Human 那一批已开过,且自主开出的新批次已达上限——此时空看板上成员不得再建卡,
1390
+ * PMO 也不再定时推进。`cap = 0` 表示 Human 那一批之外从不自主续开。
1391
+ */
1392
+ pmoBudget(cap = this.pmoMaxRounds) {
1393
+ const used = this.state.pmoRoundsUsed ?? 0;
1394
+ const freeWave = this.state.pmoFreeWave !== false;
1395
+ return { used, cap, freeWave, exhausted: !freeWave && used >= cap, announced: this.state.pmoCapped === true };
1396
+ }
1397
+
1398
+ /** 预算用尽时告知一次(账本 `project/pmo-capped` + 主流 milestone),之后静默。调用方须已持有 runExclusive。 */
1399
+ async announcePmoPause(projectId, budget) {
1400
+ if (budget.announced) return false;
1401
+ const actor = { kind: 'system', memberId: 'mem_pmo' };
1402
+ await this.ledger.append({ type: 'project/pmo-capped', payload: { projectId, rounds: budget.used, cap: budget.cap }, actor, projectId, at: this.now() });
1403
+ await this.ledger.append({
1404
+ type: 'stream/posted',
1405
+ payload: {
1406
+ kind: 'milestone',
1407
+ authorId: 'mem_pmo',
1408
+ body: `PMO 已在你上一次操作后自主续开 ${budget.used} 批任务(上限 ${budget.cap}),现在暂停,等待你的指令。发一条消息、新建或重开任务即可继续。`,
1409
+ },
1410
+ actor,
1411
+ projectId,
1412
+ at: this.now(),
1413
+ });
1414
+ this.diag?.append({ ev: 'pmo.paused', projectId, rounds: budget.used, cap: budget.cap });
1415
+ return true;
1416
+ }
1417
+
1418
+ /** PMO 定时推进前调用:预算内放行;用尽则告知一次并拒绝。 */
1419
+ pmoGate(projectId, cap = this.pmoMaxRounds) {
1420
+ return this.runExclusive(async () => {
1421
+ const budget = this.pmoBudget(cap);
1422
+ if (!budget.exhausted) return { admitted: true, ...budget, announcedNow: false };
1423
+ const announcedNow = await this.announcePmoPause(projectId, budget);
1424
+ return { admitted: false, ...budget, announcedNow };
1425
+ });
1426
+ }
1427
+
1371
1428
  /** PMO: answer all pending structured questions with the max-value policy. */
1372
1429
  async autoAnswerDecisions(projectId = Object.keys(this.state.projects ?? {})[0]) {
1373
1430
  const humanId = this.humanId();