@suifei/dsh-ai-team 0.4.29 → 0.4.31
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 +19 -0
- package/index.js +12 -6
- package/lib/host/decision-report.js +14 -4
- package/lib/host/permission-guard.js +24 -2
- package/lib/host/pmo.js +29 -0
- package/lib/host/waker.js +11 -5
- package/lib/runtime/member-runtime.js +5 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.31 - 2026-11-12
|
|
4
|
+
|
|
5
|
+
**中危批次 2:Host 会话落账、报告路径判别、PMO 决策遵从建议**
|
|
6
|
+
|
|
7
|
+
- **Host 会话现在真的会落账**:`bindHostSession` 一直存在却只在「首次创建」时被调用——从 `roots()` 选中既有根会话、或父级换成另一条根会话时都不会写,`state.hostSessionId` 永远为空,归档修复 sweep 看不见它,父级变化后 `sendMessage`/冷恢复直接 `UNAUTHORIZED` 且无自愈。现在每次解析出 Host 都按现状重绑(幂等),失败留诊断。
|
|
8
|
+
- **报告路径按存在性判别**:一份 Thread 里常先给示例、后给真实路径,文末还可能附模板。现在优先取**真实存在**的那条,都不存在时才退回「最后一次提到」,不再被文末模板或旧稿带走。
|
|
9
|
+
- **PMO 决策遵从问题里的建议**:显式 `recommendation` 现在先按选项字母(`建议 A` ↔ `A. …`)匹配,其次双向包含;只有匹配不上才退回关键词打分。此前关键词打分可以让「建议 A」被选成 B。
|
|
10
|
+
- 测试:`node --test` **211/211**。
|
|
11
|
+
|
|
12
|
+
## 0.4.30 - 2026-11-12
|
|
13
|
+
|
|
14
|
+
**中危批次:唤醒路径收敛与权限预设可配置**
|
|
15
|
+
|
|
16
|
+
- **唤醒只剩一条来源**:删掉 HTTP 命令返回后的第二次唤醒规划——`dispatch` 的返回值只有投影、没有事件,那条路径要么算不出计划,要么与账本事件路径用不同去重键重复唤醒。
|
|
17
|
+
- **不再让人验收自己的活**:`pmo/review` 之前把**所有** QA 成员都叫上,包括刚交活的 assignee 和 claim 过这张卡的人;现按 `isReviewCandidate` 排除。
|
|
18
|
+
- **inbox 唤醒分支修复**:账本写的是扁平载荷(`itemId`/`memberId`/`ref`),waker 却按 `payload.item` 读,导致该分支永不触发;空等人的通知现在会真的叫醒收件人。
|
|
19
|
+
- **权限预设名不再硬编码**:`danger-full-access` 只是约定的预设名,部署方改了名字时 `set()` 会抛错、guard 进而拒绝成员的每一次工具调用。现在按「约定名 → 表里第一个 full-access 预设」解析,两个入口(guard 与成员运行时)共用同一个解析器。
|
|
20
|
+
- 测试:`node --test` **206/206**。
|
|
21
|
+
|
|
3
22
|
## 0.4.29 - 2026-11-12
|
|
4
23
|
|
|
5
24
|
**第二轮审计批次 3:成员唤醒与归档修复补全**
|
package/index.js
CHANGED
|
@@ -1400,9 +1400,16 @@ export function apply(ctx, config = {}) {
|
|
|
1400
1400
|
cwd: booted?.dataDir ?? process.cwd(),
|
|
1401
1401
|
resumeSessionId: existingHost,
|
|
1402
1402
|
}).then(async (value) => {
|
|
1403
|
-
|
|
1404
|
-
|
|
1403
|
+
// Host 会话必须落账:它决定冷恢复与 sendMessage 的 parent,也决定归档
|
|
1404
|
+
// 修复 sweep 能不能看见根会话。除了「首次创建」,从 roots() 里选中
|
|
1405
|
+
// 既有会话、以及父级发生变化(换成了另一条根会话)时同样要重绑——
|
|
1406
|
+
// 否则之后每次 sendMessage/coldResume 都以 UNAUTHORIZED 失败且无自愈。
|
|
1407
|
+
for (const runtime of booted?.runtimes?.values() ?? []) {
|
|
1408
|
+
if (runtime.service.state.hostSessionId === value.sessionId) continue;
|
|
1409
|
+
try {
|
|
1405
1410
|
await runtime.service.bindHostSession(value.sessionId, runtime.id);
|
|
1411
|
+
} catch (error) {
|
|
1412
|
+
diag.append({ ev: 'host.bind.fail', projectId: runtime.id, sessionId: value.sessionId, message: error?.message ?? String(error) });
|
|
1406
1413
|
}
|
|
1407
1414
|
}
|
|
1408
1415
|
host = value;
|
|
@@ -2194,10 +2201,9 @@ export function apply(ctx, config = {}) {
|
|
|
2194
2201
|
}
|
|
2195
2202
|
}
|
|
2196
2203
|
send(res, { ok: true, ...result });
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
});
|
|
2204
|
+
// 唤醒只由账本事件路径规划(attachRuntime 的 onEvent):dispatch 的
|
|
2205
|
+
// 返回值只有投影、没有 event,这里再算一次要么算不出计划、要么与
|
|
2206
|
+
// 事件路径用不同的键重复唤醒。同一能力保留一份实现。
|
|
2201
2207
|
return;
|
|
2202
2208
|
} catch (error) {
|
|
2203
2209
|
return errorResponse(res, error);
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Read the Human-decision table from a linked Markdown report.
|
|
3
5
|
*
|
|
4
6
|
* This is deliberately narrow: only a report containing a section titled
|
|
@@ -26,13 +28,21 @@ export function findReportPath(text) {
|
|
|
26
28
|
/`[A-Za-z]:[\\/][^`<>|\r\n]+?\.md`/g,
|
|
27
29
|
/[A-Za-z]:[\\/][^\s"'<>|`]+?\.md\b/g,
|
|
28
30
|
];
|
|
29
|
-
|
|
31
|
+
// 命中多个时先看**哪个真的存在**:模型常先给示例路径、再给真实产物路径,文末
|
|
32
|
+
// 也可能附一段模板示例——单靠「取第一个/取最后一个」都会错一边。存在的路径
|
|
33
|
+
// 优先;都不存在时退回「最后一次提到」,那是模型的最终答复约定。
|
|
34
|
+
const hits = [];
|
|
30
35
|
for (const pattern of patterns) {
|
|
31
36
|
for (const match of text.matchAll(pattern)) {
|
|
32
|
-
|
|
37
|
+
hits.push({ index: match.index ?? 0, path: match[0].replace(/^["'`]|["'`]$/g, '') });
|
|
33
38
|
}
|
|
34
39
|
}
|
|
35
|
-
|
|
40
|
+
if (hits.length === 0) return null;
|
|
41
|
+
hits.sort((a, b) => a.index - b.index);
|
|
42
|
+
const existing = hits.filter((hit) => {
|
|
43
|
+
try { return existsSync(hit.path); } catch { return false; }
|
|
44
|
+
});
|
|
45
|
+
return (existing.length > 0 ? existing[existing.length - 1] : hits[hits.length - 1]).path;
|
|
36
46
|
}
|
|
37
47
|
|
|
38
48
|
export function parseDecisionQuestions(markdown) {
|
|
@@ -6,6 +6,27 @@
|
|
|
6
6
|
|
|
7
7
|
export const TEAM_PERMISSION = 'danger-full-access';
|
|
8
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
|
+
let entries = [];
|
|
21
|
+
try { entries = permissionPresets?.list?.() ?? []; } catch { entries = []; }
|
|
22
|
+
for (const entry of Array.isArray(entries) ? entries : []) {
|
|
23
|
+
const name = typeof entry === 'string' ? entry : (entry?.name ?? entry?.id);
|
|
24
|
+
if (typeof name !== 'string' || name === '') continue;
|
|
25
|
+
if (sandboxOf(name) === TEAM_PERMISSION) return name;
|
|
26
|
+
}
|
|
27
|
+
return TEAM_PERMISSION;
|
|
28
|
+
}
|
|
29
|
+
|
|
9
30
|
export function createMemberPermissionGuard({ service, permissionPresets, sandboxPolicy }) {
|
|
10
31
|
return (execution) => {
|
|
11
32
|
const session = execution?.agent?.session;
|
|
@@ -13,11 +34,12 @@ export function createMemberPermissionGuard({ service, permissionPresets, sandbo
|
|
|
13
34
|
const members = Object.values(service?.state?.members ?? {});
|
|
14
35
|
const member = members.find((entry) => entry.kind === 'agent' && entry.sessionId === execution.agent.id);
|
|
15
36
|
if (member === undefined) return undefined;
|
|
37
|
+
const presetName = resolveTeamPreset(permissionPresets);
|
|
16
38
|
if (sandboxPolicy?.overrideOf?.(session) !== TEAM_PERMISSION) {
|
|
17
39
|
try {
|
|
18
|
-
permissionPresets?.set?.(session,
|
|
40
|
+
permissionPresets?.set?.(session, presetName);
|
|
19
41
|
} catch {
|
|
20
|
-
return `member ${member.name ?? member.id} cannot restore ${
|
|
42
|
+
return `member ${member.name ?? member.id} cannot restore ${presetName}`;
|
|
21
43
|
}
|
|
22
44
|
}
|
|
23
45
|
if (sandboxPolicy?.overrideOf?.(session) !== TEAM_PERMISSION) {
|
package/lib/host/pmo.js
CHANGED
|
@@ -14,6 +14,30 @@ function clean(value) {
|
|
|
14
14
|
return typeof value === 'string' ? value.trim() : '';
|
|
15
15
|
}
|
|
16
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
|
+
|
|
17
41
|
function scoreOption(option, question) {
|
|
18
42
|
const value = clean(option);
|
|
19
43
|
if (value === '') return -100;
|
|
@@ -36,6 +60,11 @@ export function chooseDecisionAnswers(questions) {
|
|
|
36
60
|
const options = Array.isArray(question?.options) ? question.options.map(clean).filter(Boolean) : [];
|
|
37
61
|
const recommendation = clean(question?.recommendation);
|
|
38
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 };
|
|
39
68
|
const picked = options
|
|
40
69
|
.map((option) => ({ option, score: scoreOption(option, question) }))
|
|
41
70
|
.sort((left, right) => right.score - left.score)[0];
|
package/lib/host/waker.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
2
|
* Event-driven wake planner. No timers: a command produces at most one plan,
|
|
3
3
|
* and the Host delivers it with `subagents.sendMessage`/MemberRuntime.wake.
|
|
4
4
|
*
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { eligibleReviewers, isQaMember } from '../domain/member-profile.js';
|
|
10
|
+
import { isReviewCandidate } from '../domain/policy.js';
|
|
10
11
|
|
|
11
12
|
function text(value) {
|
|
12
13
|
return typeof value === 'string' ? value : '';
|
|
@@ -200,10 +201,12 @@ export function planWakes(state, result, actor = {}, options = {}) {
|
|
|
200
201
|
const task = state.tasks?.[event.payload?.taskId];
|
|
201
202
|
if (task !== undefined) {
|
|
202
203
|
const bucket = event.payload?.bucket ?? Math.floor(Date.now() / 600_000);
|
|
204
|
+
// 只叫 QA 成员,并且用同一套资格判定:之前把**所有** QA 成员都叫来,
|
|
205
|
+
// 包括刚交活的 assignee 和 claim 过这张卡的人,等于让人验收自己的活。
|
|
203
206
|
for (const member of Object.values(state.members ?? {})) {
|
|
204
|
-
if (
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
+
if (!isQaMember(member)) continue;
|
|
208
|
+
if (!isReviewCandidate(member, task)) continue;
|
|
209
|
+
add(member.id, task.id, 'pmo_review', `pmo_review:${task.id}:${member.id}:${bucket}`);
|
|
207
210
|
}
|
|
208
211
|
}
|
|
209
212
|
}
|
|
@@ -265,7 +268,10 @@ export function planWakes(state, result, actor = {}, options = {}) {
|
|
|
265
268
|
}
|
|
266
269
|
}
|
|
267
270
|
if (event?.type === 'inbox/item-created') {
|
|
268
|
-
|
|
271
|
+
// 账本写的是**扁平**载荷({ itemId, memberId, ref, ... }),不是嵌套的
|
|
272
|
+
// payload.item —— 之前按嵌套读,这条唤醒分支永远不触发。
|
|
273
|
+
const item = event.payload ?? {};
|
|
274
|
+
add(item.memberId, item.ref?.taskId ?? null, 'inbox', `inbox:${item.itemId ?? item.id ?? event.seq}`);
|
|
269
275
|
}
|
|
270
276
|
return [...targets.values()];
|
|
271
277
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
2
|
* Member runtime adapter (M2 foundation).
|
|
3
3
|
*
|
|
4
4
|
* The registry owns names and ledger events; this module owns the one thing
|
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
import { randomUUID } from 'node:crypto';
|
|
16
16
|
import { buildAgentOptions } from '../domain/member-config.js';
|
|
17
17
|
|
|
18
|
+
import { resolveTeamPreset } from '../host/permission-guard.js';
|
|
19
|
+
|
|
18
20
|
const TEAM_PRESET = 'danger-full-access';
|
|
19
21
|
|
|
20
22
|
function userMessage(text) {
|
|
@@ -115,7 +117,7 @@ export class MemberRuntime {
|
|
|
115
117
|
fail('E_SESSION_MISSING', `member session ${String(sessionId)} is not live`);
|
|
116
118
|
}
|
|
117
119
|
if (this.sandboxPolicy.overrideOf(session) !== TEAM_PRESET) {
|
|
118
|
-
this.permissionPresets.set(session,
|
|
120
|
+
this.permissionPresets.set(session, resolveTeamPreset(this.permissionPresets));
|
|
119
121
|
}
|
|
120
122
|
if (this.sandboxPolicy.overrideOf(session) !== TEAM_PRESET) {
|
|
121
123
|
fail('E_PERMISSION', `member session ${String(sessionId)} is not ${TEAM_PRESET}`, { sessionId });
|
|
@@ -203,7 +205,7 @@ export class MemberRuntime {
|
|
|
203
205
|
}
|
|
204
206
|
const session = handle.agent.session;
|
|
205
207
|
try {
|
|
206
|
-
if (this.sandboxPolicy.overrideOf(session) !== TEAM_PRESET) this.permissionPresets.set(session,
|
|
208
|
+
if (this.sandboxPolicy.overrideOf(session) !== TEAM_PRESET) this.permissionPresets.set(session, resolveTeamPreset(this.permissionPresets));
|
|
207
209
|
if (this.sandboxPolicy.overrideOf(session) !== TEAM_PRESET) {
|
|
208
210
|
fail('E_PERMISSION', `member session ${sessionId} is not ${TEAM_PRESET}`, { sessionId });
|
|
209
211
|
}
|
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.31",
|
|
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",
|