@suifei/dsh-ai-team 0.4.38 → 0.4.39

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,24 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.39 - 2026-11-12
4
+
5
+ **第三轮(对抗性复审)回归修复**
6
+
7
+ 三路独立复审对 `b64b4ae..HEAD` 提出 19 条,其中 10 条已修:
8
+
9
+ - **投影版本必须递增**:我改了折叠语义(接管不再写 claimHistory、换 owner 同步 ownerId)却没升 `FOLD_STATE_VERSION`,旧 checkpoint 会被零尾放采信——升级后「前 owner 仍通过 isLead」「接管继任者仍被排除在验收候选外」永久保留。现为 **v3**,旧 checkpoint 作废重折。
10
+ - **repair 只修了段文件**:门面 `repair()` 返回 writer 结果却不重折 state/events,`state.lastSeq` 停在修复前水位,下一次 append 后中间事件永不进投影、零尾放把缺口固化。现在从磁盘重读并 `fold()` 重建,同时落一次 checkpoint。
11
+ - **迁移门禁**:此前只按「目标数据更少」判断,若从 `--profile ai-team` 启动一个 CLI,会把 desktop 的 `ai-team/default` 整体搬进该 profile。现在**只允许** `argv-path` 来源(桌面启动器)触发迁移;`resolveProfile` 同时返回来源。
12
+ - **迁移回滚**:第二步 rename 失败时目标已被挪走,原实现返回 `kept` 但目标消失,下次 boot 会用空目录重建 registry。现在失败会还原目标。
13
+ - **作者契约**:`bootstrap` 的 `stream[].author` 上一版发的是字符串,而客户端读 `item.author.kind/.name`——作者仍显示「—」。现在发 `{ id, kind, name }`。
14
+ - **PMO 自动作答进锁**:`autoAnswerDecision` 读 head → 分配 seq → append,与 `thread.post` 并发时同 seq 会被 fold 静默丢弃,Human 的明确决策可能被自动决策替换。
15
+ - **建卡校验不再误伤**:只校验**显式传入**的 `ownerId`;默认 owner(退役的 Project owner)不再把工作台建卡入口整个封死。
16
+ - **依赖校验**:`blockedBy` 用 `Object.hasOwn`(原型链键不再算「存在」)。
17
+ - **决策终态**补上 `done`。
18
+ - **别名值容错**:`people-aliases.json` 里非字符串值不再让 `/api/people` 500。
19
+ - **迁移后的 judging job**:`job.project` 是绝对路径,迁移后精确比较失败会让这些 job 永久跳过;现在按项目 id 兜底匹配。
20
+ - 测试:`node --test` **239/239**(新增 4 例:来源门禁、迁移回滚、别名容错、显式 owner 校验)。
21
+
3
22
  ## 0.4.38 - 2026-11-12
4
23
 
5
24
  **中危批次 8:技能根、决策串行化、失败升级去重**
package/index.js CHANGED
@@ -15,7 +15,7 @@ import { existsSync, readFileSync, statSync, writeFileSync } from 'node:fs';
15
15
  import z from '@deepseek-ai/schemastery';
16
16
  import { ProjectRuntime } from './lib/host/project-runtime.js';
17
17
  import { ProjectRegistry } from './lib/host/project-registry.js';
18
- import { migrateLegacyNamespace, resolveProfileName } from './lib/ledger/namespace.js';
18
+ import { migrateLegacyNamespace, resolveProfile } from './lib/ledger/namespace.js';
19
19
  import { ids } from './lib/domain/ids.js';
20
20
  import { MemberRuntime, validatePermissionProfile } from './lib/runtime/member-runtime.js';
21
21
  import { ensureHostAgent } from './lib/runtime/host-agent.js';
@@ -154,11 +154,15 @@ function dshHome() {
154
154
  return process.env.DSH_HOME || join(homedir(), '.dsh');
155
155
  }
156
156
 
157
+ function resolvedProfile() {
158
+ return resolveProfile(process.argv, process.env);
159
+ }
160
+
157
161
  function profileName() {
158
162
  // 桌面启动器不导出 DSH_PROFILE,而是把 profile 目录作为**位置参数**传进来
159
163
  // (… <dsh-root> C:\Users\…\.dsh\profiles\desktop …)。解析规则抽到
160
164
  // lib/ledger/namespace.js:`--profile x`、`--profile=x`、位置路径与 env 都要认。
161
- return resolveProfileName(process.argv, process.env);
165
+ return resolvedProfile().name;
162
166
  }
163
167
 
164
168
  /**
@@ -172,7 +176,11 @@ async function boot(diag) {
172
176
  // `--profile`,而桌面启动器按位置参数传)。这里做一次性、数据驱动、可回退的
173
177
  // 搬迁:只有旧命名空间的数据明显更多时才搬,目标原有内容改名保留、不删除。
174
178
  const legacyDir = join(dshHome(), 'ai-team', 'default');
175
- if (dataDir !== legacyDir) migrateLegacyNamespace({ fromDir: legacyDir, toDir: dataDir, diag });
179
+ // 只在**桌面启动器**(profile 以位置参数传入)时搬迁:那个坑正是它造成的。
180
+ // 从 --profile ai-team 起一个 CLI 不该把 GUI 的团队偷走。
181
+ if (dataDir !== legacyDir && resolvedProfile().source === 'argv-path') {
182
+ migrateLegacyNamespace({ fromDir: legacyDir, toDir: dataDir, diag });
183
+ }
176
184
  const registry = ProjectRegistry.load(dataDir);
177
185
  const runtimes = new Map();
178
186
  for (const project of registry.list()) {
@@ -1247,7 +1255,13 @@ export function apply(ctx, config = {}) {
1247
1255
  };
1248
1256
  for (const job of jobs) {
1249
1257
  if (job.state !== 'judging' || typeof job.reviewTaskId !== 'string') continue;
1250
- const runtime = [...(booted?.runtimes?.values?.() ?? [])].find((entry) => entry.dir === job.project);
1258
+ // job.project 是绝对路径;命名空间迁移后它会指向旧目录,精确比较会让
1259
+ // 这些 judging job 永久跳过(既收不到票也不再超时)。目录相同优先,
1260
+ // 否则按项目 id(目录名)匹配。
1261
+ const allRuntimes = [...(booted?.runtimes?.values?.() ?? [])];
1262
+ const dirName = (value) => String(value ?? '').split(/[\\\\/]/).filter(Boolean).pop() ?? '';
1263
+ const runtime = allRuntimes.find((entry) => entry.dir === job.project)
1264
+ ?? allRuntimes.find((entry) => entry.id === dirName(job.project));
1251
1265
  if (runtime === undefined) continue;
1252
1266
  const collected = collectReview({ service: runtime.service, job });
1253
1267
  const expected = collected.expected ?? job.reviewOrders?.length ?? 3;
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * 人员池只读聚合(11-管理视角与信息架构 §2):遍历各 Project 账本的
3
3
  * members/tasks,按姓名把"同一个人在各项目的身份"聚成一行。
4
4
  * 不产生任何新数据——输入是既有账本投影,输出是纯视图。
@@ -21,11 +21,16 @@ const ACTIVE_TASK_STATUSES = new Set(['pending', 'in_progress', 'pending_accepta
21
21
  export function aggregatePeople(registryEntries, runtimes, options = {}) {
22
22
  const aliases = options.aliases ?? null;
23
23
  const people = new Map();
24
+ // 别名文件是手工/旧版本可写的,值不一定是字符串:直接 .startsWith 会让 /api/people 500。
25
+ const aliasOf = (name) => {
26
+ const raw = aliases !== null && Object.prototype.hasOwnProperty.call(aliases, name) ? aliases[name] : null;
27
+ return typeof raw === 'string' && raw !== '' ? raw : null;
28
+ };
24
29
  const bucketOf = (name) => {
25
30
  // 别名的目标可以是 `person:<id>`(真正的 personId)、`name:<名字>`,或
26
31
  // 历史数据里的裸名字。裸名字必须归一到 `name:<名字>`——否则「X → 白砚」
27
32
  // 会让 X 落到 `person:白砚`,而白砚本人是 `name:白砚`,两行永远合不到一起。
28
- const alias = aliases !== null && Object.prototype.hasOwnProperty.call(aliases, name) ? aliases[name] : null;
33
+ const alias = aliasOf(name);
29
34
  if (alias === null) return `name:${name}`;
30
35
  if (alias.startsWith('person:') || alias.startsWith('name:')) return alias;
31
36
  return `name:${alias}`;
@@ -33,8 +38,8 @@ export function aggregatePeople(registryEntries, runtimes, options = {}) {
33
38
  // 合并出来的那一行必须叫**目标**的名字:它由遍历顺序里第一个成员创建,若直接用
34
39
  // 该成员的原始名字,「百里 → 白砚」会合成一行却显示成「百里」。
35
40
  const displayNameOf = (name) => {
36
- const alias = aliases !== null && Object.prototype.hasOwnProperty.call(aliases, name) ? aliases[name] : null;
37
- return typeof alias === 'string' && alias.startsWith('name:') ? alias.slice('name:'.length) : name;
41
+ const alias = aliasOf(name);
42
+ return alias !== null && alias.startsWith('name:') ? alias.slice('name:'.length) : name;
38
43
  };
39
44
  for (const runtime of runtimes) {
40
45
  const projectName = registryEntries.find((project) => project.id === runtime.id)?.name ?? runtime.id;
@@ -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';
@@ -234,9 +234,20 @@ export class TeamService {
234
234
  : (state.stream ?? [])
235
235
  .filter((entry) => entry.projectId === selectedProject.id)
236
236
  .slice(-200)
237
- // 客户端渲染作者名(item.author),而账本只有 authorId:在这里补上,
238
- // 否则主对话与 Thread 的作者永远显示「—」。
239
- .map((entry) => ({ ...entry, author: state.members?.[entry.authorId]?.name ?? entry.authorId ?? '' }));
237
+ // 客户端按对象读作者(`item.author.kind` / `.name`),账本只有 authorId:
238
+ // 在这里补成 { id, kind, name },否则主对话与 Thread 的作者恒为「—」,
239
+ // human 判定也永远是 false。
240
+ .map((entry) => {
241
+ const member = state.members?.[entry.authorId];
242
+ return {
243
+ ...entry,
244
+ author: {
245
+ id: entry.authorId ?? null,
246
+ kind: member?.kind ?? entry.authorKind ?? 'agent',
247
+ name: member?.name ?? entry.authorId ?? '',
248
+ },
249
+ };
250
+ });
240
251
  const selected = threadTaskId ?? tasks.find((task) => task.status === 'in_progress')?.id ?? tasks[0]?.id;
241
252
  const threadOf = (taskId) => {
242
253
  const full = taskId === undefined || taskId === null ? undefined : state.threads?.[taskId];
@@ -1087,11 +1098,13 @@ export class TeamService {
1087
1098
  }
1088
1099
  // 幽灵成员 id / 不存在的依赖会被直接写进投影,且没有修复命令:卡的 owner 永远
1089
1100
  // 不对,或被一个不存在的依赖永久 blocked。
1090
- requireMemberRef(state, ownerId, 'ownerId');
1101
+ // 只校验**显式传入**的 ownerId:默认值来自 project.ownerMemberId,若该成员已退役,
1102
+ // 校验会把工作台的建卡入口整个封死(退役不转移所有权)。
1103
+ if (typeof payload.ownerId === 'string' && payload.ownerId !== '') requireMemberRef(state, payload.ownerId, 'ownerId');
1091
1104
  requireMemberRef(state, payload.assigneeId, 'assigneeId', { agentOnly: true });
1092
1105
  if (Array.isArray(payload.blockedBy)) {
1093
1106
  for (const dependency of payload.blockedBy) {
1094
- if (typeof dependency !== 'string' || state.tasks?.[dependency] === undefined) {
1107
+ if (typeof dependency !== 'string' || Object.hasOwn(state.tasks ?? {}, dependency) !== true) {
1095
1108
  fail(ERRORS.INVALID_ARGUMENT, `blockedBy ${String(dependency)} is not a Task of this project`);
1096
1109
  }
1097
1110
  }
@@ -1308,7 +1321,9 @@ export class TeamService {
1308
1321
  for (const item of items) {
1309
1322
  const questions = Array.isArray(item.ref?.questions) ? item.ref.questions : [];
1310
1323
  const answers = chooseDecisionAnswers(questions);
1311
- results.push(await this.autoAnswerDecision(item, answers, projectId));
1324
+ // 自动作答也要在锁内:它与 thread.post 一样是「读 head → 分配 seq → append」,
1325
+ // 并发时同 seq 会被 fold 静默丢弃,而 Human 的明确决策可能被自动决策替换。
1326
+ results.push(await this.runExclusive(() => this.autoAnswerDecision(item, answers, projectId)));
1312
1327
  }
1313
1328
  return results;
1314
1329
  }
@@ -1424,7 +1439,7 @@ export class TeamService {
1424
1439
  if (item.memberId !== humanId) fail(ERRORS.UNAUTHORIZED, 'decision belongs to another member');
1425
1440
  // 终态前置:已 resolved/dismissed/superseded 的决策项再次提交过去会被接受,
1426
1441
  // 于是同一决策重复写 Thread 回复,ack 回来的 item 还是旧答案。
1427
- if (['resolved', 'dismissed', 'superseded'].includes(item.state)) {
1442
+ if (['resolved', 'dismissed', 'superseded', 'done'].includes(item.state)) {
1428
1443
  fail(ERRORS.INVALID_STATE, `decision ${String(item.id)} is already ${String(item.state)}`);
1429
1444
  }
1430
1445
  const answers = (Array.isArray(payload.answers) ? payload.answers : [])
@@ -33,8 +33,15 @@
33
33
  import { GENESIS_HASH, isPlainObject } from './events.js';
34
34
  import { isReviewCandidate } from '../domain/policy.js';
35
35
 
36
- /** 投影状态版本;改动折叠语义时必须递增(03 §6.4)。 */
37
- export const FOLD_STATE_VERSION = 2;
36
+ /**
37
+ * 投影状态版本;改动折叠语义时必须递增(03 §6.4)。
38
+ *
39
+ * v3:`task/taken-over` 不再写 claimHistory(INV-07),`project/owner-changed`
40
+ * 同时更新 ownerId。旧 checkpoint(v2)里仍带着旧语义的投影,必须作废重折,
41
+ * 否则升级后「前 owner 仍通过 isLead」「接管继任者仍被排除在验收候选外」会
42
+ * 被零尾放永久保留。
43
+ */
44
+ export const FOLD_STATE_VERSION = 3;
38
45
 
39
46
  /**
40
47
  * 投影封顶:大规模/长迭代账本下,stream 与每个 Thread 的 entries 不随事件数
@@ -16,20 +16,37 @@ import { join } from 'node:path';
16
16
 
17
17
  /** 从启动参数/env 解析 profile 名。 */
18
18
  export function resolveProfileName(argv = process.argv, env = process.env) {
19
+ return resolveProfile(argv, env).name;
20
+ }
21
+
22
+ /**
23
+ * 同 `resolveProfileName`,但同时给出**来源**:
24
+ * - `flag`:`--profile x` / `--profile=x`(CLI 显式指定)
25
+ * - `argv-path`:位置参数里的 `…/profiles/<name>`(桌面启动器)
26
+ * - `env` / `default`
27
+ *
28
+ * 迁移只允许发生在 `argv-path`:旧命名空间那个坑正是桌面启动器造成的;
29
+ * 若从 `--profile ai-team` 起一个 CLI 就顺手把 desktop 的数据搬过去,会把
30
+ * GUI 的团队偷走。
31
+ */
32
+ export function resolveProfile(argv = process.argv, env = process.env) {
19
33
  const list = Array.isArray(argv) ? argv.map(String) : [];
20
34
  const flagAt = list.indexOf('--profile');
21
- if (flagAt >= 0 && typeof list[flagAt + 1] === 'string' && list[flagAt + 1] !== '') return list[flagAt + 1];
35
+ if (flagAt >= 0 && typeof list[flagAt + 1] === 'string' && list[flagAt + 1] !== '') {
36
+ return { name: list[flagAt + 1], source: 'flag' };
37
+ }
22
38
  const inline = list.find((arg) => arg.startsWith('--profile='));
23
39
  if (inline !== undefined) {
24
40
  const value = inline.slice('--profile='.length);
25
- if (value !== '') return value;
41
+ if (value !== '') return { name: value, source: 'flag' };
26
42
  }
27
43
  // 位置参数形态:…/profiles/<name>(Windows 反斜杠与 POSIX 斜杠都要认)。
28
44
  for (const arg of list) {
29
45
  const match = /[\\/]profiles[\\/]([^\\/]+)[\\/]?$/.exec(arg);
30
- if (match !== null) return match[1];
46
+ if (match !== null) return { name: match[1], source: 'argv-path' };
31
47
  }
32
- return env?.DSH_PROFILE || 'default';
48
+ if (env?.DSH_PROFILE) return { name: env.DSH_PROFILE, source: 'env' };
49
+ return { name: 'default', source: 'default' };
33
50
  }
34
51
 
35
52
  /** 目录下所有文件的总字节数;目录不存在按 0 计。 */
@@ -53,21 +70,33 @@ export function dirBytes(dir) {
53
70
  * 旧命名空间有明显更多数据时搬迁到目标命名空间。
54
71
  * @returns {'migrated'|'kept'|'none'} migrated=已搬迁,kept=目标更新/一样大,none=没有旧数据
55
72
  */
56
- export function migrateLegacyNamespace({ fromDir, toDir, diag = null, now = Date.now }) {
73
+ export function migrateLegacyNamespace({ fromDir, toDir, diag = null, now = Date.now, rename = renameSync }) {
57
74
  if (fromDir === toDir) return 'none';
58
75
  if (!existsSync(join(fromDir, 'projects.json'))) return 'none';
59
76
  const legacyBytes = dirBytes(fromDir);
60
77
  const targetBytes = dirBytes(toDir);
61
78
  if (legacyBytes <= targetBytes) return 'kept';
79
+ let supersededDir = null;
62
80
  try {
63
81
  if (existsSync(toDir)) {
64
82
  // 目标原有内容改名保留(不删除),便于回退与人工核对。
65
- renameSync(toDir, `${toDir}.superseded-${now()}`);
83
+ supersededDir = `${toDir}.superseded-${now()}`;
84
+ rename(toDir, supersededDir);
66
85
  }
67
- renameSync(fromDir, toDir);
86
+ rename(fromDir, toDir);
68
87
  diag?.append?.({ ev: 'ledger.namespace.migrated', from: fromDir, to: toDir, legacyBytes, targetBytes });
69
88
  return 'migrated';
70
89
  } catch (error) {
90
+ // 第二步失败时目标已经被挪走:必须还原,否则下一次 boot 会用一个空目录
91
+ // 重建 registry,用户看到的是「团队被清空」,而数据只躺在 superseded 里。
92
+ if (supersededDir !== null && !existsSync(toDir)) {
93
+ try {
94
+ rename(supersededDir, toDir);
95
+ diag?.append?.({ ev: 'ledger.namespace.migrate.rollback', to: toDir, superseded: supersededDir });
96
+ } catch (rollbackError) {
97
+ diag?.append?.({ ev: 'ledger.namespace.rollback.fail', to: toDir, superseded: supersededDir, message: rollbackError?.message ?? String(rollbackError) });
98
+ }
99
+ }
71
100
  diag?.append?.({ ev: 'ledger.namespace.migrate.fail', from: fromDir, to: toDir, message: error?.message ?? String(error) });
72
101
  return 'kept';
73
102
  }
@@ -1225,7 +1225,22 @@ export function openLedger(options = {}) {
1225
1225
  }
1226
1226
  },
1227
1227
  repair() {
1228
- return writer.repair();
1228
+ const result = writer.repair();
1229
+ // writer 层修的是段文件;门面这一层的 state/events 必须跟着**重折**。
1230
+ // 只返回 writer 的结果会让 state.lastSeq 停在修复前的水位:下一次 append
1231
+ // 之后 state.lastSeq 直接跳到新 head,中间那段事件永远不进投影,而
1232
+ // checkpoint 的零尾放会把这条缺口永久固化。
1233
+ // 从磁盘重读而不是用缓存:缓存里可能正是修复前那份含撕裂批次的列表。
1234
+ events = writer.readAll({ repairTail: false });
1235
+ state = fold(events);
1236
+ eventsSinceCheckpoint = 0;
1237
+ if (checkpointOptions) saveCheckpointNow();
1238
+ return {
1239
+ ...result,
1240
+ refolded: true,
1241
+ events: events.length,
1242
+ stateLastSeq: state.lastSeq ?? null,
1243
+ };
1229
1244
  },
1230
1245
  close() {
1231
1246
  if (checkpointOptions) saveCheckpointNow();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suifei/dsh-ai-team",
3
- "version": "0.4.38",
3
+ "version": "0.4.39",
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",