@suifei/dsh-ai-team 0.4.63 → 0.4.64

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,20 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.64 - 2026-11-12
4
+
5
+ **重建后不再从零开始:冷路径提示词带上当前 Task 与最近对话**
6
+
7
+ 实测发现 `NOT_RESUMABLE` **不是**重启瞬间的边界:今天 120 次 `wake.fail` 里 118 次是它,00–11 时每小时都有(`thread_reply` 64、`pmo_heartbeat` 12、`pmo_meeting` 11…)。每次失败都会重建成员会话 = 上下文清零,而唤醒提示词只有一行指令,成员只能自己去 `team` 里翻现场。
8
+
9
+ - 新增 `describeTaskContext(state, taskId, { includeThread })`(`lib/host/waker.js`):从账本投影渲染
10
+ 「【当前 Task】#55 标题 [状态]」+「【最近对话】」最近 3 条(正文截断 120 字)。
11
+ **不新增任何存储**——数据本来就在 `state.tasks` / `state.threads` / `state.members` 里。
12
+ - 冷路径才附对话尾巴:`member.sessionId` 不在线(成员首次激活、会话不可恢复)时
13
+ `includeThread: true`;热路径上下文已在会话里,加进去只是白烧 token。
14
+ - 重建提示词同样复用该上下文(原文案「会话已升级…历史会话迁移」改为「会话已重建…」)。
15
+ - 测试:`node --test` **264 通过 / 1 跳过**(新增 2 例:Task 行恒带、对话尾巴仅在冷路径;
16
+ 长对话只保留最近 3 条且每行 ≤130 字)。
17
+
3
18
  ## 0.4.63 - 2026-11-12
4
19
 
5
20
  **产物收尾: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`:**264 通过 / 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
  }
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.64",
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",