@suifei/dsh-ai-team 0.4.28 → 0.4.29

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.29 - 2026-11-12
4
+
5
+ **第二轮审计批次 3:成员唤醒与归档修复补全**
6
+
7
+ - **第二次唤醒不再丢上下文**:冷恢复拿到的 AgentHandle 现在由 runtime 自己记住;此前 session 变 live 后第二次唤醒会回退到 `subagent.sendMessage`,manager 再做一次冷恢复并以 `NOT_RESUMABLE` 失败,触发上层强制重建、丢掉成员历史(handle 失效时才回退并清理)。
8
+ - **归档修复覆盖成员会话自身**:sweep 之前只处理 host 一代;成员会话被单独归档时该成员每回合仍永久 `blocked`。现在 member session 本身也进 victims。
9
+ - **roots() 快路径也解归档**:选中 Human 根会话时若它已归档,成员血缘被 gate 永久拒绝,而 sweep 因没有 hostSessionId 看不到它。
10
+ - **面板作者名**:`bootstrap` 的 stream 投影补 `author`(客户端读 `item.author`,账本只有 `authorId`),主对话与 Thread 不再恒显示「—」。
11
+ - **决策表章节号**:识别中文序号「六」,以 `## 六、…` 写的第 6 节决策表不再解析不出问题。
12
+ - **唤醒 prompt 截断**:Main stream 的 Human 正文截到 2000 字符,1MB 级粘贴不再整段进入 Project owner 上下文。
13
+ - 测试:`node --test` **203/203**。
14
+
3
15
  ## 0.4.28 - 2026-11-12
4
16
 
5
17
  **第二轮审计:8 条 HIGH + 工作台 409 修复**
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * Read the Human-decision table from a linked Markdown report.
3
3
  *
4
4
  * This is deliberately narrow: only a report containing a section titled
@@ -37,7 +37,7 @@ export function findReportPath(text) {
37
37
 
38
38
  export function parseDecisionQuestions(markdown) {
39
39
  const lines = String(markdown ?? '').split(/\r?\n/);
40
- const start = lines.findIndex((line) => /^##\s*6[.、\s]/.test(line) || /^##\s*6\s*$/.test(line));
40
+ const start = lines.findIndex((line) => /^##\s*(6|六)[.、\s]/.test(line) || /^##\s*(6|六)\s*$/.test(line));
41
41
  if (start < 0) return [];
42
42
  let end = lines.length;
43
43
  for (let index = start + 1; index < lines.length; index += 1) {
@@ -1,4 +1,4 @@
1
- import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
1
+ import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
2
2
  import pathDefault from 'node:path';
3
3
  import { ERRORS, fail } from '../domain/errors.js';
4
4
  import { findReportPath, parseDecisionQuestions } from './decision-report.js';
@@ -219,7 +219,12 @@ export class TeamService {
219
219
  // stream 投影本身已封顶(≤500),bootstrap 再按窗口切尾。
220
220
  const stream = selectedProject === undefined
221
221
  ? []
222
- : (state.stream ?? []).filter((entry) => entry.projectId === selectedProject.id).slice(-200);
222
+ : (state.stream ?? [])
223
+ .filter((entry) => entry.projectId === selectedProject.id)
224
+ .slice(-200)
225
+ // 客户端渲染作者名(item.author),而账本只有 authorId:在这里补上,
226
+ // 否则主对话与 Thread 的作者永远显示「—」。
227
+ .map((entry) => ({ ...entry, author: state.members?.[entry.authorId]?.name ?? entry.authorId ?? '' }));
223
228
  const selected = threadTaskId ?? tasks.find((task) => task.status === 'in_progress')?.id ?? tasks[0]?.id;
224
229
  const threadOf = (taskId) => {
225
230
  const full = taskId === undefined || taskId === null ? undefined : state.threads?.[taskId];
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
  *
@@ -193,7 +193,7 @@ export function planWakes(state, result, actor = {}, options = {}) {
193
193
  null,
194
194
  'human_message',
195
195
  `human_message:${event.seq ?? event.payload?.seq}`,
196
- `你是 Project owner。Human 在 Main stream 说:“${body}”。本轮必须先用 team action=members 查看成员,再用 action=create 创建至少一个 Task;ownerId 必须使用成员 id,写明可验证的 resultDefinition。可用成员:${roster || '无'}。如果需求很大或外部链接只是参考,先创建“调研/澄清/拆解”Task,不要直接开始实现。先做复盘/头脑风暴/深度研究,再产出验收标准;不要等 Human、不要把决策推回 Human。需要记录决策时调用 team action=askHuman,PMO 会自动按最高价值建议处理;不要只写“见报告/§6/已提交 Human”。resultDefinition 只写验收标准,不要写“等待 Human 验收”;不要只读文件或只回一段话结束。`,
196
+ `你是 Project owner。Human 在 Main stream 说:“${body.slice(0, 2000)}”。本轮必须先用 team action=members 查看成员,再用 action=create 创建至少一个 Task;ownerId 必须使用成员 id,写明可验证的 resultDefinition。可用成员:${roster || '无'}。如果需求很大或外部链接只是参考,先创建“调研/澄清/拆解”Task,不要直接开始实现。先做复盘/头脑风暴/深度研究,再产出验收标准;不要等 Human、不要把决策推回 Human。需要记录决策时调用 team action=askHuman,PMO 会自动按最高价值建议处理;不要只写“见报告/§6/已提交 Human”。resultDefinition 只写验收标准,不要写“等待 Human 验收”;不要只读文件或只回一段话结束。`,
197
197
  );
198
198
  }
199
199
  if (event?.type === 'pmo/review') {
@@ -110,6 +110,9 @@ export async function ensureHostAgent(options) {
110
110
  if (header === undefined) return true;
111
111
  return header.origin !== 'subagent' && header.parentSession === undefined;
112
112
  }) ?? roots[0];
113
+ // 被选中的 Human 根会话若已归档,成员血缘会被 gate 永久拒绝——这条快路径
114
+ // 也必须解归档,否则 boot 期的 sweep 由于没有 hostSessionId 看不到它。
115
+ await unarchiveHost(rootAgent.id);
113
116
  return { agent: rootAgent, created: false, sessionId: rootAgent.id, dispose: async () => {} };
114
117
  }
115
118
 
@@ -50,6 +50,9 @@ export async function repairArchivedHosts(options = {}) {
50
50
  for (const member of Object.values(runtime?.service?.state?.members ?? {})) {
51
51
  const sessionId = member?.sessionId;
52
52
  if (typeof sessionId !== 'string' || sessionId === '') continue;
53
+ // 成员会话自己也可能被归档(例如用户手动归档了那条会话):gate 会直接
54
+ // 拒绝它,只有 host 一代的解归档覆盖不到。
55
+ victims.add(sessionId);
53
56
  try {
54
57
  const header = options.sessions?.get?.(sessionId)?.header;
55
58
  if (typeof header?.parentSession === 'string') victims.add(header.parentSession);
@@ -101,6 +101,10 @@ export class MemberRuntime {
101
101
  // Cold resumes produce AgentHandles the caller does not store; the owner
102
102
  // tracks them here so teardown can dispose every member activation.
103
103
  this.trackHandle = typeof options.trackHandle === 'function' ? options.trackHandle : null;
104
+ // 冷恢复得到的 handle 必须自己记住:第二次唤醒时 session 已经 live,但
105
+ // subagent manager 并不把这次 resume 当成 resident activation,再走
106
+ // sendMessage 会触发二次冷恢复 → NOT_RESUMABLE → 上层强制重建丢上下文。
107
+ this.resumedHandles = new Map();
104
108
  this.clock = options.clock ?? (() => Date.now());
105
109
  }
106
110
 
@@ -267,6 +271,7 @@ export class MemberRuntime {
267
271
  } catch { handle = null; }
268
272
  if (handle?.agent !== undefined && handle?.agent !== null && typeof handle.agent.followup === 'function') {
269
273
  this.trackHandle?.(member.sessionId, handle);
274
+ this.resumedHandles.set(member.sessionId, handle);
270
275
  await this.ensurePermission(member.sessionId);
271
276
  const message = userMessage(typeof options.prompt === 'string' ? options.prompt : '继续');
272
277
  handle.agent.followup(message);
@@ -281,6 +286,21 @@ export class MemberRuntime {
281
286
  });
282
287
  return { messageId, sessionId: member.sessionId, cold: true };
283
288
  }
289
+ // 之前由我们 resume 过的会话:继续用同一个 handle 投递,避免掉回
290
+ // sendMessage 的冷恢复路径(见构造函数里的说明)。
291
+ const resumed = this.resumedHandles.get(member.sessionId);
292
+ if (resumed?.agent !== undefined && resumed?.agent !== null && typeof resumed.agent.followup === 'function') {
293
+ try {
294
+ await this.ensurePermission(member.sessionId);
295
+ const message = userMessage(typeof options.prompt === 'string' ? options.prompt : '继续');
296
+ resumed.agent.followup(message);
297
+ if (typeof this.sessions.flush === 'function') await this.sessions.flush(session);
298
+ return { messageId: message.id, sessionId: member.sessionId, cold: false, resumed: true };
299
+ } catch {
300
+ // handle 已失效:清掉后回退到 manager 通道。
301
+ this.resumedHandles.delete(member.sessionId);
302
+ }
303
+ }
284
304
  await this.ensurePermission(member.sessionId);
285
305
  const messageId = await this.subagents.sendMessage(this.parent, member.sessionId, content, {
286
306
  signal: options.signal ?? new AbortController().signal,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suifei/dsh-ai-team",
3
- "version": "0.4.28",
3
+ "version": "0.4.29",
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",