@suifei/dsh-ai-team 0.4.63 → 0.4.65

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,32 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.65 - 2026-11-12
4
+
5
+ **修:重建出来的会话仍落在插件数据目录(host 会话 cwd 是 11-09 的旧值)**
6
+
7
+ 解压真机会话日志后发现:最近 3 小时 34 个新会话里 **30 个 `cwd = C:\Users\SuiFei\.dsh\ai-team\default`**(插件数据目录),且它们都是同一条 host 会话的子会话——那条 host 建于 **2026-11-09**,记录的 cwd 就是旧数据目录。0.4.43 修的是「新建 host 时用项目工作区」,但**持久化的 host 每次 boot 都是 resume,cwd 沿用旧值**,于是成员子会话全部继承它;这正是 `workspace.attach.fail` 每天上百次的来源。
8
+
9
+ - `ensureHostAgent`:resume 之后核对 `session.header.cwd` 与期望的项目工作区;不一致就 **dispose 旧句柄并新建 host**(路径比较忽略大小写与末尾分隔符)。
10
+ - 失败行 `host.resume.cwd-mismatch.fail` 进诊断(带 `expectedCwd` / `actualCwd`),下次 boot 可直接确认是否再次发生。
11
+ - 副作用与自愈路径:新 host 的会话 id 变化后,既有成员的下一次唤醒会 `NOT_RESUMABLE` → `member.autoreseat` 重建到新 host 之下(这是既有机制,不需要额外代码)。
12
+ - 顺带修掉 `diag-sink` 用例的清理竞态(诊断 logger 仍在落盘时 `rm` 报 ENOTEMPTY,改为重试)。
13
+ - 测试:`node --test` **266 通过 / 1 跳过**(新增 2 例:旧 cwd 的 host 会被替换并释放、匹配 cwd 仍走 resume 且大小写/尾斜杠不影响判定)。
14
+
15
+ ## 0.4.64 - 2026-11-12
16
+
17
+ **重建后不再从零开始:冷路径提示词带上当前 Task 与最近对话**
18
+
19
+ 实测发现 `NOT_RESUMABLE` **不是**重启瞬间的边界:今天 120 次 `wake.fail` 里 118 次是它,00–11 时每小时都有(`thread_reply` 64、`pmo_heartbeat` 12、`pmo_meeting` 11…)。每次失败都会重建成员会话 = 上下文清零,而唤醒提示词只有一行指令,成员只能自己去 `team` 里翻现场。
20
+
21
+ - 新增 `describeTaskContext(state, taskId, { includeThread })`(`lib/host/waker.js`):从账本投影渲染
22
+ 「【当前 Task】#55 标题 [状态]」+「【最近对话】」最近 3 条(正文截断 120 字)。
23
+ **不新增任何存储**——数据本来就在 `state.tasks` / `state.threads` / `state.members` 里。
24
+ - 冷路径才附对话尾巴:`member.sessionId` 不在线(成员首次激活、会话不可恢复)时
25
+ `includeThread: true`;热路径上下文已在会话里,加进去只是白烧 token。
26
+ - 重建提示词同样复用该上下文(原文案「会话已升级…历史会话迁移」改为「会话已重建…」)。
27
+ - 测试:`node --test` **264 通过 / 1 跳过**(新增 2 例:Task 行恒带、对话尾巴仅在冷路径;
28
+ 长对话只保留最近 3 条且每行 ≤130 字)。
29
+
3
30
  ## 0.4.63 - 2026-11-12
4
31
 
5
32
  **产物收尾:README 验证段落与验证清单升版**
package/README.md CHANGED
@@ -170,7 +170,7 @@ POST /ai-team/api/projects/<id>/commands
170
170
 
171
171
  ## 验证
172
172
 
173
- - `node --test`:**262 通过 / 1 跳过**(跳过项是目录 junction 用例,本机沙箱不允许创建)
173
+ - `node --test`:**266 通过 / 1 跳过**(跳过项是目录 junction 用例,本机沙箱不允许创建)
174
174
  - 真实账本副本干跑(`.ptc/rounds/dryrun-real-ledger.mjs`,可重复运行、不写生产数据):
175
175
  用**已安装的 npm 产物**启动真实项目账本,核对 `health` / `bootstrap` / `/people` /
176
176
  `project.repair`(`acceptedRange` + `seqGaps`)/ 新建项目空目录被 400 拒绝
package/index.js CHANGED
@@ -46,7 +46,7 @@ import { createMemberPermissionGuard } from './lib/host/permission-guard.js';
46
46
  import { installFaultAdapter } from './lib/host/fault-adapter.js';
47
47
  import { buildModelCatalog } from './lib/host/model-catalog.js';
48
48
  import { createTeamTool } from './lib/host/member-tools.js';
49
- import { describeWake, planWakes } from './lib/host/waker.js';
49
+ import { describeTaskContext, describeWake, planWakes } from './lib/host/waker.js';
50
50
  import { aggregatePeople } from './lib/host/people-view.js';
51
51
  import { riskView } from './lib/host/risk-view.js';
52
52
  import { weeklyView } from './lib/host/weekly-view.js';
@@ -645,7 +645,7 @@ export function apply(ctx, config = {}) {
645
645
  // A live member already carries the activation context (identity,
646
646
  // personality, skills). A wake is only the Task delta; re-sending the
647
647
  // whole activation prompt caused the duplicated blocks users saw.
648
- const wakePrompt = async (plan) => describeWake(plan, projectRuntime.service.state);
648
+ const wakePrompt = async (plan, member, options = {}) => describeWake(plan, projectRuntime.service.state, options);
649
649
  for (const plan of plans) {
650
650
  if (wakeKeys.has(plan.key)) continue;
651
651
  let member = projectRuntime.service.state.members?.[plan.memberId];
@@ -676,7 +676,7 @@ export function apply(ctx, config = {}) {
676
676
  // 调用里,await 先让出执行权、单飞表还没登记,并发的两个计划会各自
677
677
  // 启动一次激活(两个子会话)。
678
678
  activation = (async () => activateMember({
679
- payload: { memberId: member.id, prompt: await wakePrompt(plan, member) },
679
+ payload: { memberId: member.id, prompt: await wakePrompt(plan, member, { includeThread: true }) },
680
680
  }, projectRuntime))();
681
681
  activationTasks.set(activationKey, activation);
682
682
  activation.finally(() => activationTasks.delete(activationKey)).catch(() => {});
@@ -701,7 +701,11 @@ export function apply(ctx, config = {}) {
701
701
  cwd,
702
702
  trackHandle: (sessionId, handle) => resumedHandles.set(sessionId, handle),
703
703
  });
704
- const delivered = await runtime.wake(member, { prompt: await wakePrompt(plan, member) });
704
+ const delivered = await runtime.wake(member, {
705
+ // 冷路径(会话不在线)才附 Thread 尾巴:成员靠它续跑,不必从零回忆;
706
+ // 热路径上下文已在会话里,附上去只是白烧 token。
707
+ prompt: await wakePrompt(plan, member, { includeThread: sessions?.get?.(member.sessionId) === undefined }),
708
+ });
705
709
  messageId = delivered.messageId ?? null;
706
710
  // A cold session cannot be renamed before wake; retry once it is live.
707
711
  await titleMemberSession(projectRuntime, member);
@@ -769,7 +773,9 @@ export function apply(ctx, config = {}) {
769
773
  payload: {
770
774
  memberId: plan.memberId,
771
775
  force: true,
772
- prompt: '会话已升级为团队子智能体形态(历史会话迁移)。先读 tasks/thread 当前状态,继续推进;不要重复已完成的工作。',
776
+ // 重建 = 上下文清零:把当前 Task 与 Thread 尾巴直接递到手上,
777
+ // 不让成员靠猜测恢复现场(数据来自账本投影,不另存一份)。
778
+ prompt: `会话已重建(原会话不可恢复)。先读 tasks/thread 当前状态,继续推进;不要重复已完成的工作。${describeTaskContext(projectRuntime.service.state, plan.taskId, { includeThread: true })}`,
773
779
  },
774
780
  }, projectRuntime);
775
781
  diag.append({
package/lib/host/waker.js CHANGED
@@ -276,15 +276,67 @@ export function planWakes(state, result, actor = {}, options = {}) {
276
276
  return [...targets.values()];
277
277
  }
278
278
 
279
+ /** Thread 尾巴:只带最近几条,正文按字符截断,避免把提示词撑大。 */
280
+ const CONTEXT_ENTRY_LIMIT = 3;
281
+ const CONTEXT_BODY_LIMIT = 120;
282
+ const CONTEXT_TITLE_LIMIT = 80;
283
+
284
+ const shortText = (value, limit) => {
285
+ const text = typeof value === 'string' ? value.replace(/\s+/g, ' ').trim() : '';
286
+ return text.length > limit ? `${text.slice(0, limit)}…` : text;
287
+ };
288
+
289
+ /**
290
+ * 冷路径(会话不可恢复/重建)的最小可续跑上下文:当前 Task 一句话 + Thread 最近几条。
291
+ *
292
+ * 为什么不另存一份:这些都已在 Project 账本投影里(`state.tasks` / `state.threads` /
293
+ * `state.members`),再建一份存储就是第二个真相源。这里只负责**投喂**——成员重建后
294
+ * 不必从零开始回忆「刚才在做什么、谁说了什么」。
295
+ *
296
+ * @param {object} state 账本投影
297
+ * @param {string} taskId 当前 Task
298
+ * @param {{ includeThread?: boolean, entryLimit?: number, bodyLimit?: number }} options
299
+ * @returns {string} 以换行开头;没有可用内容时返回空串
300
+ */
301
+ export function describeTaskContext(state, taskId, options = {}) {
302
+ if (typeof taskId !== 'string' || taskId === '') return '';
303
+ const entryLimit = Number.isSafeInteger(options.entryLimit) && options.entryLimit > 0 ? options.entryLimit : CONTEXT_ENTRY_LIMIT;
304
+ const bodyLimit = Number.isSafeInteger(options.bodyLimit) && options.bodyLimit > 0 ? options.bodyLimit : CONTEXT_BODY_LIMIT;
305
+ const lines = [];
306
+ const task = state?.tasks?.[taskId];
307
+ if (task !== undefined && task !== null) {
308
+ const title = shortText(task.title, CONTEXT_TITLE_LIMIT) || '(无标题)';
309
+ lines.push(`【当前 Task】#${task.number ?? '?'} ${title} [${task.status ?? '?'}]`);
310
+ }
311
+ if (options.includeThread === true) {
312
+ const entries = Array.isArray(state?.threads?.[taskId]?.entries)
313
+ ? state.threads[taskId].entries.slice(-entryLimit)
314
+ : [];
315
+ const rendered = [];
316
+ for (const entry of entries) {
317
+ const body = shortText(entry?.body, bodyLimit);
318
+ if (body === '') continue;
319
+ const author = state?.members?.[entry?.authorId]?.name ?? entry?.authorId ?? '?';
320
+ rendered.push(`- ${author}:${body}`);
321
+ }
322
+ if (rendered.length > 0) lines.push('【最近对话】', ...rendered);
323
+ }
324
+ return lines.length === 0 ? '' : `\n${lines.join('\n')}`;
325
+ }
326
+
279
327
  /**
280
328
  * Compact Task delta for a live member. Identity, personality and the core
281
329
  * skill are activation-only; re-sending them on every wake duplicated the
282
330
  * prompt and crowded the persistent session.
331
+ *
332
+ * `options.includeThread` 打开时才附 Thread 尾巴:**只有冷路径**(会话不可恢复、
333
+ * 或重建后)才需要它,否则每次唤醒都白烧 token。
283
334
  */
284
- export function describeWake(wake, state) {
335
+ export function describeWake(wake, state, options = {}) {
285
336
  const member = state.members?.[wake.memberId];
286
337
  const boundary = typeof wake.taskId === 'string' && wake.taskId !== ''
287
338
  ? '【Task 边界】这是当前 Task 的增量指令;先读 Task/Thread 当前状态,不要把上一个 Task 的假设直接带入。\n'
288
339
  : '';
289
- return `${boundary}[${member?.name ?? wake.memberId}] ${wake.prompt}`;
340
+ const context = describeTaskContext(state, wake.taskId, options);
341
+ return `${boundary}[${member?.name ?? wake.memberId}] ${wake.prompt}${context}`;
290
342
  }
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * Resolve the parent Agent that owns member activations.
3
3
  *
4
4
  * Preference order:
@@ -19,6 +19,13 @@
19
19
  * repaired here by unarchiving on resolve.
20
20
  */
21
21
  import { randomUUID } from 'node:crypto';
22
+ import { reportFail } from '../diaglog.js';
23
+
24
+ /** Windows 路径大小写不敏感,末尾分隔符也不该影响判定。 */
25
+ const samePath = (left, right) => {
26
+ const norm = (value) => String(value).replace(/[\\/]+$/, '').replace(/\\/g, '/').toLowerCase();
27
+ return norm(left) === norm(right);
28
+ };
22
29
 
23
30
  export class HostAgentError extends Error {
24
31
  constructor(code, message, details = {}) {
@@ -83,15 +90,31 @@ export async function ensureHostAgent(options) {
83
90
  try {
84
91
  const handle = await agents.resume({ resumeSessionId: options.resumeSessionId });
85
92
  await unarchiveHost(options.resumeSessionId);
86
- const selection = typeof options.agentDefaultModel?.currentSelection === 'function' ? options.agentDefaultModel.currentSelection() : null;
87
- persistSelection(options.resumeSessionId, selection);
88
- return {
89
- agent: handle.agent,
90
- created: false,
91
- resumed: true,
92
- sessionId: options.resumeSessionId,
93
- dispose: async () => { try { await handle.dispose?.(); } catch { /* already gone */ } },
94
- };
93
+ // 持久化的 host 会话保留着**创建时的 cwd**,而成员子会话会继承它。
94
+ // 实机事故:2026-11-09 建的 host 记的是 `…/.dsh/ai-team/default`,于是
95
+ // 30 个成员会话全在插件数据目录里干活,`workspace.attachSession` 每天被拒
96
+ // 上百次。cwd 不一致时不能复用这条 host——释放它,落到下面的创建分支。
97
+ const expectedCwd = typeof options.cwd === 'string' ? options.cwd.trim() : '';
98
+ const actualCwd = handle?.agent?.session?.header?.cwd ?? options.sessions?.get?.(options.resumeSessionId)?.header?.cwd ?? null;
99
+ if (expectedCwd !== '' && typeof actualCwd === 'string' && actualCwd !== ''
100
+ && samePath(actualCwd, expectedCwd) === false) {
101
+ try { await handle.dispose?.(); } catch { /* already gone */ }
102
+ reportFail(
103
+ 'host.resume.cwd-mismatch.fail',
104
+ { sessionId: options.resumeSessionId, expectedCwd, actualCwd },
105
+ '[ai-team] Team Host session cwd does not match the project workspace; creating a fresh host',
106
+ );
107
+ } else {
108
+ const selection = typeof options.agentDefaultModel?.currentSelection === 'function' ? options.agentDefaultModel.currentSelection() : null;
109
+ persistSelection(options.resumeSessionId, selection);
110
+ return {
111
+ agent: handle.agent,
112
+ created: false,
113
+ resumed: true,
114
+ sessionId: options.resumeSessionId,
115
+ dispose: async () => { try { await handle.dispose?.(); } catch { /* already gone */ } },
116
+ };
117
+ }
95
118
  } catch (error) {
96
119
  // A persisted host must be resumed: creating another one would break the
97
120
  // existing members' direct-child adjacency.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suifei/dsh-ai-team",
3
- "version": "0.4.63",
3
+ "version": "0.4.65",
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",