@suifei/dsh-ai-team 0.4.144 → 0.4.145

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.
Files changed (39) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE +21 -21
  3. package/README.md +4 -0
  4. package/client.js +22 -14
  5. package/cordis.patch.yml +31 -31
  6. package/icon.svg +12 -12
  7. package/lib/domain/ids.js +26 -26
  8. package/lib/domain/inbox.js +93 -93
  9. package/lib/domain/member-config.js +168 -168
  10. package/lib/host/decision-report.js +72 -72
  11. package/lib/host/default-workspace.js +69 -69
  12. package/lib/host/fault-adapter.js +50 -50
  13. package/lib/host/people-view.js +120 -120
  14. package/lib/host/permission-guard.js +61 -61
  15. package/lib/host/pmo.js +13 -13
  16. package/lib/host/project-registry.js +104 -104
  17. package/lib/host/risk-view.js +99 -99
  18. package/lib/host/weekly-view.js +86 -86
  19. package/lib/host/workspace-path.js +94 -94
  20. package/lib/ledger/checkpoint.js +415 -415
  21. package/lib/ledger/events.js +398 -398
  22. package/lib/ledger/namespace.js +124 -124
  23. package/lib/ledger/tools.js +118 -118
  24. package/lib/ledger/writer.js +1266 -1266
  25. package/lib/runtime/error-chain.js +31 -31
  26. package/lib/runtime/shell-guard.js +102 -102
  27. package/lib/runtime/skill-catalog.js +41 -41
  28. package/lib/runtime/skill-policy.js +12 -12
  29. package/lib/skillopt/adopt-gate.js +108 -108
  30. package/lib/skillopt/gate-wiring.js +146 -146
  31. package/lib/skillopt/jobs.js +135 -135
  32. package/lib/skillopt/proposal-store.js +33 -33
  33. package/lib/skillopt/review-runner.js +107 -107
  34. package/lib/skillopt/rubric.js +189 -189
  35. package/lib/skillopt/subagent-text.js +101 -101
  36. package/lib/skillopt/tool-access.js +56 -56
  37. package/locale/en.json +6 -6
  38. package/locale/zh.json +6 -6
  39. package/package.json +1 -1
@@ -1,50 +1,50 @@
1
- /**
2
- * Test-only LLM adapter. It is registered only when DSH_AI_TEAM_TEST=1 and
3
- * lets the Host exercise the real agent loop's failure path with deterministic
4
- * billing/network failures instead of external providers.
5
- */
6
-
7
- export const FAULT_PROVIDER = 'ai-team-fault';
8
-
9
- export function installFaultAdapter(llm, getMode) {
10
- if (!llm || typeof llm.registerAdapter !== 'function') return () => {};
11
- const model = { provider: FAULT_PROVIDER, id: 'fault', name: 'Fault model' };
12
- const adapter = {
13
- providerInfo(provider) {
14
- return { id: provider, name: 'AI Team Fault' };
15
- },
16
- providerRetryPolicy() {
17
- return undefined;
18
- },
19
- imageRequestPricing() {
20
- return undefined;
21
- },
22
- imageRequestTarget() {
23
- return { width: 0, height: 0, maxBytes: 0 };
24
- },
25
- async listModels() {
26
- return [{ ...model }];
27
- },
28
- async resolveModel(provider, id) {
29
- return { provider, id, name: id };
30
- },
31
- async prepareCall(provider, id) {
32
- return {
33
- model: { provider, id, name: id },
34
- stream: () => streamFault(getMode()),
35
- };
36
- },
37
- stream() {
38
- return streamFault(getMode());
39
- },
40
- };
41
- const dispose = llm.registerAdapter([FAULT_PROVIDER], adapter);
42
- return typeof dispose === 'function' ? dispose : () => {};
43
- }
44
-
45
- async function* streamFault(mode) {
46
- const failure = mode === 'billing'
47
- ? { message: 'Injected billing failure', code: 'BILLING', status: 402 }
48
- : { message: 'Injected network reset', code: 'ECONNRESET' };
49
- yield { type: 'finish', reason: { kind: 'error', failure } };
50
- }
1
+ /**
2
+ * Test-only LLM adapter. It is registered only when DSH_AI_TEAM_TEST=1 and
3
+ * lets the Host exercise the real agent loop's failure path with deterministic
4
+ * billing/network failures instead of external providers.
5
+ */
6
+
7
+ export const FAULT_PROVIDER = 'ai-team-fault';
8
+
9
+ export function installFaultAdapter(llm, getMode) {
10
+ if (!llm || typeof llm.registerAdapter !== 'function') return () => {};
11
+ const model = { provider: FAULT_PROVIDER, id: 'fault', name: 'Fault model' };
12
+ const adapter = {
13
+ providerInfo(provider) {
14
+ return { id: provider, name: 'AI Team Fault' };
15
+ },
16
+ providerRetryPolicy() {
17
+ return undefined;
18
+ },
19
+ imageRequestPricing() {
20
+ return undefined;
21
+ },
22
+ imageRequestTarget() {
23
+ return { width: 0, height: 0, maxBytes: 0 };
24
+ },
25
+ async listModels() {
26
+ return [{ ...model }];
27
+ },
28
+ async resolveModel(provider, id) {
29
+ return { provider, id, name: id };
30
+ },
31
+ async prepareCall(provider, id) {
32
+ return {
33
+ model: { provider, id, name: id },
34
+ stream: () => streamFault(getMode()),
35
+ };
36
+ },
37
+ stream() {
38
+ return streamFault(getMode());
39
+ },
40
+ };
41
+ const dispose = llm.registerAdapter([FAULT_PROVIDER], adapter);
42
+ return typeof dispose === 'function' ? dispose : () => {};
43
+ }
44
+
45
+ async function* streamFault(mode) {
46
+ const failure = mode === 'billing'
47
+ ? { message: 'Injected billing failure', code: 'BILLING', status: 402 }
48
+ : { message: 'Injected network reset', code: 'ECONNRESET' };
49
+ yield { type: 'finish', reason: { kind: 'error', failure } };
50
+ }
@@ -1,120 +1,120 @@
1
- /**
2
- * 人员池只读聚合(11-管理视角与信息架构 §2):遍历各 Project 账本的
3
- * members/tasks,按姓名把"同一个人在各项目的身份"聚成一行。
4
- * 不产生任何新数据——输入是既有账本投影,输出是纯视图。
5
- *
6
- * 同名即同一人:默认花名册同名同人;自建成员重名视为同一团队身份(文档化
7
- * 于 docs/11 §5)。可选 `aliases`(name → personId 视图层绑定,R-17)在
8
- * 同名聚合之上生效。
9
- */
10
-
11
- import { isTaskBlocked } from '../ledger/fold.js';
12
-
13
- const ACTIVE_TASK_STATUSES = new Set(['pending', 'in_progress', 'pending_acceptance']);
14
-
15
- /**
16
- * @param {Array<{id:string,name:string}>} registryEntries
17
- * @param {Array<{id:string,service:{state:any}}>} runtimes
18
- * @param {{ aliases?: Record<string,string> }} [options]
19
- * @returns {Array<{name:string,role:string,projects:Array,failures:number,activeTasks:number}>}
20
- */
21
- export function aggregatePeople(registryEntries, runtimes, options = {}) {
22
- const aliases = options.aliases ?? null;
23
- const people = new Map();
24
- // 别名文件是手工/旧版本可写的,值不一定是字符串:直接 .startsWith 会让 /api/people 500。
25
- const aliasOf = (name) => {
26
- const raw = aliases !== null && Object.prototype.hasOwnProperty.call(aliases, name) ? aliases[name] : null;
27
- return typeof raw === 'string' && raw !== '' ? raw : null;
28
- };
29
- const bucketOf = (name) => {
30
- // 别名的目标可以是 `person:<id>`(真正的 personId)、`name:<名字>`,或
31
- // 历史数据里的裸名字。裸名字必须归一到 `name:<名字>`——否则「X → 白砚」
32
- // 会让 X 落到 `person:白砚`,而白砚本人是 `name:白砚`,两行永远合不到一起。
33
- const alias = aliasOf(name);
34
- if (alias === null) return `name:${name}`;
35
- if (alias.startsWith('person:') || alias.startsWith('name:')) return alias;
36
- return `name:${alias}`;
37
- };
38
- // 合并出来的那一行必须叫**目标**的名字:它由遍历顺序里第一个成员创建,若直接用
39
- // 该成员的原始名字,「百里 → 白砚」会合成一行却显示成「百里」。
40
- const displayNameOf = (name) => {
41
- const alias = aliasOf(name);
42
- return alias !== null && alias.startsWith('name:') ? alias.slice('name:'.length) : name;
43
- };
44
- for (const runtime of runtimes) {
45
- const projectName = registryEntries.find((project) => project.id === runtime.id)?.name ?? runtime.id;
46
- const state = runtime.service?.state;
47
- if (state === undefined || state === null) continue;
48
- // 本项目的活跃任务计数:按 owner/assignee 两个责任位累计,并按状态
49
- // 分解(R-10 成员负载:进行中/待验收/受阻)。
50
- const loadByMember = new Map();
51
- for (const task of Object.values(state.tasks ?? {})) {
52
- if (task.tombstone === true || !ACTIVE_TASK_STATUSES.has(task.status)) continue;
53
- const bucketKey = task.status === 'in_progress' ? 'inProgress'
54
- : task.status === 'pending_acceptance' ? 'pendingAcceptance'
55
- : 'pending';
56
- for (const memberId of [task.ownerId, task.assigneeId]) {
57
- if (typeof memberId !== 'string' || memberId === '') continue;
58
- const load = loadByMember.get(memberId) ?? { activeTasks: 0, inProgress: 0, pendingAcceptance: 0, pending: 0, blocked: 0 };
59
- load.activeTasks += 1;
60
- if (bucketKey === 'inProgress') load.inProgress += 1;
61
- else if (bucketKey === 'pendingAcceptance') load.pendingAcceptance += 1;
62
- else load.pending += 1;
63
- if (isTaskBlocked(state, task) === true) load.blocked += 1;
64
- loadByMember.set(memberId, load);
65
- }
66
- }
67
- for (const member of Object.values(state.members ?? {})) {
68
- if (member.kind === 'human') continue;
69
- // 空串名不吃 ?? 兜底(fold 允许空名成员;空名各自按 id 独立成行)。
70
- const memberName = member.name || member.id;
71
- const bucket = bucketOf(memberName);
72
- const entry = people.get(bucket) ?? {
73
- name: displayNameOf(memberName),
74
- role: member.role ?? '',
75
- projects: [],
76
- failures: 0,
77
- activeTasks: 0,
78
- };
79
- if (entry.role === '' && member.role) entry.role = member.role;
80
- const load = loadByMember.get(member.id) ?? { activeTasks: 0, inProgress: 0, pendingAcceptance: 0, pending: 0, blocked: 0 };
81
- // 同人同项目出现多个 memberId(如离职后重入职的新会话 id):合并为
82
- // 一行负载,memberIds 保留全部身份 id(兼容字段 memberId 取首个)。
83
- const existingProjectRow = entry.projects.find((row) => row.projectId === runtime.id);
84
- if (existingProjectRow !== undefined) {
85
- for (const key of ['activeTasks', 'inProgress', 'pendingAcceptance', 'pending', 'blocked']) {
86
- existingProjectRow[key] = (existingProjectRow[key] ?? 0) + load[key];
87
- }
88
- existingProjectRow.status = member.status ?? existingProjectRow.status;
89
- existingProjectRow.sessionId = member.sessionId ?? existingProjectRow.sessionId;
90
- existingProjectRow.memberIds = [...new Set([...(existingProjectRow.memberIds ?? [existingProjectRow.memberId].filter(Boolean)), member.id])];
91
- entry.failures += member.lastFailure !== undefined && member.lastFailure !== null ? 1 : 0;
92
- entry.activeTasks += load.activeTasks;
93
- people.set(bucket, entry);
94
- continue;
95
- }
96
- entry.projects.push({
97
- projectId: runtime.id,
98
- projectName,
99
- status: member.status ?? 'idle',
100
- sessionId: member.sessionId ?? null,
101
- memberIds: [member.id],
102
- talentPool: member.talentPool === true,
103
- attempts: member.attempts ?? 0,
104
- lastFailure: member.lastFailure ?? null,
105
- activeTasks: load.activeTasks,
106
- inProgress: load.inProgress,
107
- pendingAcceptance: load.pendingAcceptance,
108
- pending: load.pending,
109
- blocked: load.blocked,
110
- });
111
- if (member.lastFailure !== undefined && member.lastFailure !== null) entry.failures += 1;
112
- entry.activeTasks += load.activeTasks;
113
- people.set(bucket, entry);
114
- }
115
- }
116
- return [...people.values()].sort((left, right) => left.name.localeCompare(right.name));
117
- }
118
- // 语义备注:failures 计的是"当前仍带 lastFailure 的项目数"——member/recovered
119
- // 不清 lastFailure(保留最近一次失败供展示),康复成员会继续计入;这是展示
120
- // 口径而非存活判定(存活以 status 为准)。
1
+ /**
2
+ * 人员池只读聚合(11-管理视角与信息架构 §2):遍历各 Project 账本的
3
+ * members/tasks,按姓名把"同一个人在各项目的身份"聚成一行。
4
+ * 不产生任何新数据——输入是既有账本投影,输出是纯视图。
5
+ *
6
+ * 同名即同一人:默认花名册同名同人;自建成员重名视为同一团队身份(文档化
7
+ * 于 docs/11 §5)。可选 `aliases`(name → personId 视图层绑定,R-17)在
8
+ * 同名聚合之上生效。
9
+ */
10
+
11
+ import { isTaskBlocked } from '../ledger/fold.js';
12
+
13
+ const ACTIVE_TASK_STATUSES = new Set(['pending', 'in_progress', 'pending_acceptance']);
14
+
15
+ /**
16
+ * @param {Array<{id:string,name:string}>} registryEntries
17
+ * @param {Array<{id:string,service:{state:any}}>} runtimes
18
+ * @param {{ aliases?: Record<string,string> }} [options]
19
+ * @returns {Array<{name:string,role:string,projects:Array,failures:number,activeTasks:number}>}
20
+ */
21
+ export function aggregatePeople(registryEntries, runtimes, options = {}) {
22
+ const aliases = options.aliases ?? null;
23
+ const people = new Map();
24
+ // 别名文件是手工/旧版本可写的,值不一定是字符串:直接 .startsWith 会让 /api/people 500。
25
+ const aliasOf = (name) => {
26
+ const raw = aliases !== null && Object.prototype.hasOwnProperty.call(aliases, name) ? aliases[name] : null;
27
+ return typeof raw === 'string' && raw !== '' ? raw : null;
28
+ };
29
+ const bucketOf = (name) => {
30
+ // 别名的目标可以是 `person:<id>`(真正的 personId)、`name:<名字>`,或
31
+ // 历史数据里的裸名字。裸名字必须归一到 `name:<名字>`——否则「X → 白砚」
32
+ // 会让 X 落到 `person:白砚`,而白砚本人是 `name:白砚`,两行永远合不到一起。
33
+ const alias = aliasOf(name);
34
+ if (alias === null) return `name:${name}`;
35
+ if (alias.startsWith('person:') || alias.startsWith('name:')) return alias;
36
+ return `name:${alias}`;
37
+ };
38
+ // 合并出来的那一行必须叫**目标**的名字:它由遍历顺序里第一个成员创建,若直接用
39
+ // 该成员的原始名字,「百里 → 白砚」会合成一行却显示成「百里」。
40
+ const displayNameOf = (name) => {
41
+ const alias = aliasOf(name);
42
+ return alias !== null && alias.startsWith('name:') ? alias.slice('name:'.length) : name;
43
+ };
44
+ for (const runtime of runtimes) {
45
+ const projectName = registryEntries.find((project) => project.id === runtime.id)?.name ?? runtime.id;
46
+ const state = runtime.service?.state;
47
+ if (state === undefined || state === null) continue;
48
+ // 本项目的活跃任务计数:按 owner/assignee 两个责任位累计,并按状态
49
+ // 分解(R-10 成员负载:进行中/待验收/受阻)。
50
+ const loadByMember = new Map();
51
+ for (const task of Object.values(state.tasks ?? {})) {
52
+ if (task.tombstone === true || !ACTIVE_TASK_STATUSES.has(task.status)) continue;
53
+ const bucketKey = task.status === 'in_progress' ? 'inProgress'
54
+ : task.status === 'pending_acceptance' ? 'pendingAcceptance'
55
+ : 'pending';
56
+ for (const memberId of [task.ownerId, task.assigneeId]) {
57
+ if (typeof memberId !== 'string' || memberId === '') continue;
58
+ const load = loadByMember.get(memberId) ?? { activeTasks: 0, inProgress: 0, pendingAcceptance: 0, pending: 0, blocked: 0 };
59
+ load.activeTasks += 1;
60
+ if (bucketKey === 'inProgress') load.inProgress += 1;
61
+ else if (bucketKey === 'pendingAcceptance') load.pendingAcceptance += 1;
62
+ else load.pending += 1;
63
+ if (isTaskBlocked(state, task) === true) load.blocked += 1;
64
+ loadByMember.set(memberId, load);
65
+ }
66
+ }
67
+ for (const member of Object.values(state.members ?? {})) {
68
+ if (member.kind === 'human') continue;
69
+ // 空串名不吃 ?? 兜底(fold 允许空名成员;空名各自按 id 独立成行)。
70
+ const memberName = member.name || member.id;
71
+ const bucket = bucketOf(memberName);
72
+ const entry = people.get(bucket) ?? {
73
+ name: displayNameOf(memberName),
74
+ role: member.role ?? '',
75
+ projects: [],
76
+ failures: 0,
77
+ activeTasks: 0,
78
+ };
79
+ if (entry.role === '' && member.role) entry.role = member.role;
80
+ const load = loadByMember.get(member.id) ?? { activeTasks: 0, inProgress: 0, pendingAcceptance: 0, pending: 0, blocked: 0 };
81
+ // 同人同项目出现多个 memberId(如离职后重入职的新会话 id):合并为
82
+ // 一行负载,memberIds 保留全部身份 id(兼容字段 memberId 取首个)。
83
+ const existingProjectRow = entry.projects.find((row) => row.projectId === runtime.id);
84
+ if (existingProjectRow !== undefined) {
85
+ for (const key of ['activeTasks', 'inProgress', 'pendingAcceptance', 'pending', 'blocked']) {
86
+ existingProjectRow[key] = (existingProjectRow[key] ?? 0) + load[key];
87
+ }
88
+ existingProjectRow.status = member.status ?? existingProjectRow.status;
89
+ existingProjectRow.sessionId = member.sessionId ?? existingProjectRow.sessionId;
90
+ existingProjectRow.memberIds = [...new Set([...(existingProjectRow.memberIds ?? [existingProjectRow.memberId].filter(Boolean)), member.id])];
91
+ entry.failures += member.lastFailure !== undefined && member.lastFailure !== null ? 1 : 0;
92
+ entry.activeTasks += load.activeTasks;
93
+ people.set(bucket, entry);
94
+ continue;
95
+ }
96
+ entry.projects.push({
97
+ projectId: runtime.id,
98
+ projectName,
99
+ status: member.status ?? 'idle',
100
+ sessionId: member.sessionId ?? null,
101
+ memberIds: [member.id],
102
+ talentPool: member.talentPool === true,
103
+ attempts: member.attempts ?? 0,
104
+ lastFailure: member.lastFailure ?? null,
105
+ activeTasks: load.activeTasks,
106
+ inProgress: load.inProgress,
107
+ pendingAcceptance: load.pendingAcceptance,
108
+ pending: load.pending,
109
+ blocked: load.blocked,
110
+ });
111
+ if (member.lastFailure !== undefined && member.lastFailure !== null) entry.failures += 1;
112
+ entry.activeTasks += load.activeTasks;
113
+ people.set(bucket, entry);
114
+ }
115
+ }
116
+ return [...people.values()].sort((left, right) => left.name.localeCompare(right.name));
117
+ }
118
+ // 语义备注:failures 计的是"当前仍带 lastFailure 的项目数"——member/recovered
119
+ // 不清 lastFailure(保留最近一次失败供展示),康复成员会继续计入;这是展示
120
+ // 口径而非存活判定(存活以 status 为准)。
@@ -1,61 +1,61 @@
1
- /**
2
- * Last-line defense for the Team policy: every tool call from a managed member
3
- * must run with danger-full-access. Activation and wake check once; this guard
4
- * closes the "permission changed mid-turn" window by repairing before dispatch.
5
- */
6
-
7
- export const TEAM_PERMISSION = 'danger-full-access';
8
-
9
- /**
10
- * 目标权限的**预设名**不该被硬编码:部署方可能把 danger-full-access 这一档
11
- * 起成别的名字(例如 `full`)。名字不存在时 `set()` 会抛错,guard 进而拒绝
12
- * 成员的每一次工具调用——整个团队被一个改名卡死。这里按「约定的名字 → 表里
13
- * 第一个 sandbox 为 danger-full-access 的预设」解析,找不到才退回约定名。
14
- */
15
- export function resolveTeamPreset(permissionPresets) {
16
- const sandboxOf = (name) => {
17
- try { return permissionPresets?.resolve?.(name)?.sandbox ?? null; } catch { return null; }
18
- };
19
- if (sandboxOf(TEAM_PERMISSION) === TEAM_PERMISSION) return TEAM_PERMISSION;
20
- // 真实契约里没有 `list()`(用 cordis_inspect 核对过 service 签名):
21
- // 目录是 `catalog()` → `{ options: PresetOption[], defaultOptions, defaultPreset }`,
22
- // 每个 option 的 key 在 `value` 上。按 `list()` 读会永远拿不到候选,
23
- // 于是「预设名可配置」这条修复静默失效。
24
- let options = [];
25
- try {
26
- options = permissionPresets?.catalog?.()?.options ?? [];
27
- } catch {
28
- options = [];
29
- }
30
- if (!Array.isArray(options) || options.length === 0) {
31
- try { options = permissionPresets?.list?.() ?? []; } catch { options = []; }
32
- }
33
- for (const entry of Array.isArray(options) ? options : []) {
34
- const name = typeof entry === 'string' ? entry : (entry?.value ?? entry?.name ?? entry?.id);
35
- if (typeof name !== 'string' || name === '') continue;
36
- if (sandboxOf(name) === TEAM_PERMISSION) return name;
37
- }
38
- return TEAM_PERMISSION;
39
- }
40
-
41
- export function createMemberPermissionGuard({ service, permissionPresets, sandboxPolicy }) {
42
- return (execution) => {
43
- const session = execution?.agent?.session;
44
- if (session === undefined || session === null) return undefined;
45
- const members = Object.values(service?.state?.members ?? {});
46
- const member = members.find((entry) => entry.kind === 'agent' && entry.sessionId === execution.agent.id);
47
- if (member === undefined) return undefined;
48
- const presetName = resolveTeamPreset(permissionPresets);
49
- if (sandboxPolicy?.overrideOf?.(session) !== TEAM_PERMISSION) {
50
- try {
51
- permissionPresets?.set?.(session, presetName);
52
- } catch {
53
- return `member ${member.name ?? member.id} cannot restore ${presetName}`;
54
- }
55
- }
56
- if (sandboxPolicy?.overrideOf?.(session) !== TEAM_PERMISSION) {
57
- return `member ${member.name ?? member.id} is not ${TEAM_PERMISSION}`;
58
- }
59
- return undefined;
60
- };
61
- }
1
+ /**
2
+ * Last-line defense for the Team policy: every tool call from a managed member
3
+ * must run with danger-full-access. Activation and wake check once; this guard
4
+ * closes the "permission changed mid-turn" window by repairing before dispatch.
5
+ */
6
+
7
+ export const TEAM_PERMISSION = 'danger-full-access';
8
+
9
+ /**
10
+ * 目标权限的**预设名**不该被硬编码:部署方可能把 danger-full-access 这一档
11
+ * 起成别的名字(例如 `full`)。名字不存在时 `set()` 会抛错,guard 进而拒绝
12
+ * 成员的每一次工具调用——整个团队被一个改名卡死。这里按「约定的名字 → 表里
13
+ * 第一个 sandbox 为 danger-full-access 的预设」解析,找不到才退回约定名。
14
+ */
15
+ export function resolveTeamPreset(permissionPresets) {
16
+ const sandboxOf = (name) => {
17
+ try { return permissionPresets?.resolve?.(name)?.sandbox ?? null; } catch { return null; }
18
+ };
19
+ if (sandboxOf(TEAM_PERMISSION) === TEAM_PERMISSION) return TEAM_PERMISSION;
20
+ // 真实契约里没有 `list()`(用 cordis_inspect 核对过 service 签名):
21
+ // 目录是 `catalog()` → `{ options: PresetOption[], defaultOptions, defaultPreset }`,
22
+ // 每个 option 的 key 在 `value` 上。按 `list()` 读会永远拿不到候选,
23
+ // 于是「预设名可配置」这条修复静默失效。
24
+ let options = [];
25
+ try {
26
+ options = permissionPresets?.catalog?.()?.options ?? [];
27
+ } catch {
28
+ options = [];
29
+ }
30
+ if (!Array.isArray(options) || options.length === 0) {
31
+ try { options = permissionPresets?.list?.() ?? []; } catch { options = []; }
32
+ }
33
+ for (const entry of Array.isArray(options) ? options : []) {
34
+ const name = typeof entry === 'string' ? entry : (entry?.value ?? entry?.name ?? entry?.id);
35
+ if (typeof name !== 'string' || name === '') continue;
36
+ if (sandboxOf(name) === TEAM_PERMISSION) return name;
37
+ }
38
+ return TEAM_PERMISSION;
39
+ }
40
+
41
+ export function createMemberPermissionGuard({ service, permissionPresets, sandboxPolicy }) {
42
+ return (execution) => {
43
+ const session = execution?.agent?.session;
44
+ if (session === undefined || session === null) return undefined;
45
+ const members = Object.values(service?.state?.members ?? {});
46
+ const member = members.find((entry) => entry.kind === 'agent' && entry.sessionId === execution.agent.id);
47
+ if (member === undefined) return undefined;
48
+ const presetName = resolveTeamPreset(permissionPresets);
49
+ if (sandboxPolicy?.overrideOf?.(session) !== TEAM_PERMISSION) {
50
+ try {
51
+ permissionPresets?.set?.(session, presetName);
52
+ } catch {
53
+ return `member ${member.name ?? member.id} cannot restore ${presetName}`;
54
+ }
55
+ }
56
+ if (sandboxPolicy?.overrideOf?.(session) !== TEAM_PERMISSION) {
57
+ return `member ${member.name ?? member.id} is not ${TEAM_PERMISSION}`;
58
+ }
59
+ return undefined;
60
+ };
61
+ }
package/lib/host/pmo.js CHANGED
@@ -10,15 +10,16 @@ import { STALLED_MEMBER_STATUSES, dependenciesDone, teamRoles, writeScopeConflic
10
10
  */
11
11
 
12
12
  const LOW_VALUE = /最小|暂缓|延后|不做|暂停|维持现状|先不|仅文档|只做骨架/i;
13
- const HIGH_VALUE = /完整|核心|全量|推荐|生产可用|全平台|优先/i;
13
+ const HIGH_VALUE = /完整|核心|全量|生产可用|全平台|优先/i;
14
+ const NEGATED_RECOMMENDATION = /不\s*(?:推荐|建议)|\bnot\s+recommended\b/i;
14
15
 
15
16
  function clean(value) {
16
17
  return typeof value === 'string' ? value.trim() : '';
17
18
  }
18
19
 
19
- /** 选项开头的字母编号(`B.` / `B、` / `B)` / `B:`)。 */
20
+ /** 识别字母编号,也接受 `A(推荐):…` 或 `B 核心方案`。 */
20
21
  function optionLetter(value) {
21
- const match = /^\s*[((]?([A-Za-z])[))..、::]/.exec(value);
22
+ const match = /^\s*[((]?([A-Za-z])(?:[((][^))]+[))]\s*[..、::]|[))..、::]|\s+)/.exec(value);
22
23
  return match === null ? null : match[1].toUpperCase();
23
24
  }
24
25
 
@@ -32,6 +33,9 @@ function recommendationLetter(recommendation) {
32
33
  /** 显式建议命中哪个选项:字母编号优先,其次双向包含。 */
33
34
  function explicitPick(options, recommendation) {
34
35
  if (recommendation === '') return null;
36
+ const exact = options.find((option) => option === recommendation);
37
+ if (exact !== undefined) return exact;
38
+ if (NEGATED_RECOMMENDATION.test(recommendation)) return null;
35
39
  const letter = recommendationLetter(recommendation);
36
40
  if (letter !== null) {
37
41
  const byLetter = options.find((option) => optionLetter(option) === letter);
@@ -40,18 +44,14 @@ function explicitPick(options, recommendation) {
40
44
  return options.find((option) => recommendation.includes(option) || option.includes(recommendation)) ?? null;
41
45
  }
42
46
 
43
- function scoreOption(option, question) {
44
- const value = clean(option);
45
- if (value === '') return -100;
47
+ function scoreOption(value) {
48
+ // 否定说明优先于正向关键词;不把选项编号当作交付价值。
49
+ if (NEGATED_RECOMMENDATION.test(value)) return -100;
46
50
  let score = 0;
47
- if (/推荐/i.test(value)) score += 20;
51
+ if (/推荐|\brecommended\b/i.test(value)) score += 20;
48
52
  if (HIGH_VALUE.test(value)) score += 12;
49
- if (/B\b|C\b|核心|完整/i.test(value)) score += 6;
53
+ if (/核心|完整/i.test(value)) score += 6;
50
54
  if (LOW_VALUE.test(value)) score -= 20;
51
- if (/A\b|最小/i.test(value)) score -= 8;
52
- const recommendation = clean(question?.recommendation);
53
- if (recommendation !== '' && recommendation.includes(value)) score += 30;
54
- if (recommendation !== '' && value.includes(recommendation)) score += 20;
55
55
  return score;
56
56
  }
57
57
 
@@ -68,7 +68,7 @@ export function chooseDecisionAnswers(questions) {
68
68
  const explicit = explicitPick(options, recommendation);
69
69
  if (explicit !== null) return { id, value: explicit };
70
70
  const picked = options
71
- .map((option) => ({ option, score: scoreOption(option, question) }))
71
+ .map((option) => ({ option, score: scoreOption(option) }))
72
72
  .sort((left, right) => right.score - left.score)[0];
73
73
  return { id, value: picked?.option || recommendation || '按完整核心方案执行' };
74
74
  }