@suifei/dsh-ai-team 0.4.64 → 0.4.66

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,35 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.66 - 2026-11-12
4
+
5
+ **`wake.fail` 带上 cause 链:`NOT_RESUMABLE` 的真实原因不再被吞掉**
6
+
7
+ 真机复盘:过去一天 118 次 `NOT_RESUMABLE` 的日志全是同一句
8
+ `subagent "X" is unavailable`——外层错误把真实原因(persistence 读不出会话 /
9
+ descriptor 不可续 / 血缘校验失败)挂在 `cause` 上丢掉了,等于无法定位。这轮同时核实了
10
+ 这些会话本身是健康的(多帧 zstd 解压后 87 个事件、`subagent/descriptor` 的
11
+ `mode: "continuable"` 都在),所以问题在外层读取路径,不在会话内容。
12
+
13
+ - 新增 `lib/runtime/error-chain.js` 的 `describeCauseChain()`(最多 4 层、防循环、
14
+ 非 Error cause 也能渲染),`wake.fail` 行新增 `cause` 字段。
15
+ - 顺带核实并归档了两条「发现但非缺陷」:
16
+ - `dispatch.fail` 全是 `thread.post E_STALE_REPLY`(乐观并发守卫按设计拒绝,提示可直接行动);
17
+ - `workspace.attach.fail` 在成员会话重建后归零(重启后仅存 1 条,属修复前的旧会话)。
18
+ - 测试:`node --test` **269 通过 / 1 跳过**(新增 `error-chain` 3 例:带 code 的链、
19
+ 深度上限、循环与非法 cause)。
20
+
21
+ ## 0.4.65 - 2026-11-12
22
+
23
+ **修:重建出来的会话仍落在插件数据目录(host 会话 cwd 是 11-09 的旧值)**
24
+
25
+ 解压真机会话日志后发现:最近 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` 每天上百次的来源。
26
+
27
+ - `ensureHostAgent`:resume 之后核对 `session.header.cwd` 与期望的项目工作区;不一致就 **dispose 旧句柄并新建 host**(路径比较忽略大小写与末尾分隔符)。
28
+ - 失败行 `host.resume.cwd-mismatch.fail` 进诊断(带 `expectedCwd` / `actualCwd`),下次 boot 可直接确认是否再次发生。
29
+ - 副作用与自愈路径:新 host 的会话 id 变化后,既有成员的下一次唤醒会 `NOT_RESUMABLE` → `member.autoreseat` 重建到新 host 之下(这是既有机制,不需要额外代码)。
30
+ - 顺带修掉 `diag-sink` 用例的清理竞态(诊断 logger 仍在落盘时 `rm` 报 ENOTEMPTY,改为重试)。
31
+ - 测试:`node --test` **266 通过 / 1 跳过**(新增 2 例:旧 cwd 的 host 会被替换并释放、匹配 cwd 仍走 resume 且大小写/尾斜杠不影响判定)。
32
+
3
33
  ## 0.4.64 - 2026-11-12
4
34
 
5
35
  **重建后不再从零开始:冷路径提示词带上当前 Task 与最近对话**
package/README.md CHANGED
@@ -170,7 +170,7 @@ POST /ai-team/api/projects/<id>/commands
170
170
 
171
171
  ## 验证
172
172
 
173
- - `node --test`:**264 通过 / 1 跳过**(跳过项是目录 junction 用例,本机沙箱不允许创建)
173
+ - `node --test`:**269 通过 / 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
@@ -47,6 +47,7 @@ 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
49
  import { describeTaskContext, describeWake, planWakes } from './lib/host/waker.js';
50
+ import { describeCauseChain } from './lib/runtime/error-chain.js';
50
51
  import { aggregatePeople } from './lib/host/people-view.js';
51
52
  import { riskView } from './lib/host/risk-view.js';
52
53
  import { weeklyView } from './lib/host/weekly-view.js';
@@ -733,6 +734,10 @@ export function apply(ctx, config = {}) {
733
734
  reason: plan.reason,
734
735
  code: error?.code ?? null,
735
736
  message: error?.message ?? String(error),
737
+ // 外层错误只写「subagent X is unavailable」,真实原因在 cause 里
738
+ // (persistence 读不出会话 / descriptor 不可续 / 血缘校验失败)。
739
+ // 不把它带出来,每次只能看到同一句无从下手的提示。
740
+ cause: describeCauseChain(error),
736
741
  });
737
742
  console.warn('[ai-team] wake failed:', plan.memberId, error?.code ?? error?.message ?? error);
738
743
  // 一次性迁移自愈:旧形态成员会话(历史上由 agents.create 创建、
@@ -0,0 +1,31 @@
1
+ /**
2
+ * 把 Error 的 cause 链摊平成一行可检索文本。
3
+ *
4
+ * 实机背景:`subagents.sendMessage` 失败时外层只给
5
+ * `subagent "X" is unavailable`,真实原因(persistence 读不出会话、descriptor
6
+ * 不可续、血缘校验失败)挂在 `cause` 上被丢掉,诊断日志因此无法定位。
7
+ */
8
+
9
+ const MAX_DEPTH = 4;
10
+ const MAX_PART = 240;
11
+
12
+ /**
13
+ * @param {unknown} error
14
+ * @returns {string|null} `code: message ← code: message`;没有 cause 时返回 null
15
+ */
16
+ export function describeCauseChain(error) {
17
+ if (error === undefined || error === null) return null;
18
+ const parts = [];
19
+ const seen = new Set();
20
+ let current = error.cause;
21
+ let depth = 0;
22
+ while (current !== undefined && current !== null && depth < MAX_DEPTH && !seen.has(current)) {
23
+ seen.add(current);
24
+ const code = typeof current.code === 'string' && current.code !== '' ? `${current.code}: ` : '';
25
+ const message = typeof current.message === 'string' ? current.message : String(current);
26
+ parts.push(`${code}${message}`.slice(0, MAX_PART));
27
+ current = current.cause;
28
+ depth += 1;
29
+ }
30
+ return parts.length === 0 ? null : parts.join(' ← ');
31
+ }
@@ -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.64",
3
+ "version": "0.4.66",
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",