@suifei/dsh-ai-team 0.4.39 → 0.4.40

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,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.40 - 2026-11-12
4
+
5
+ **批 9:依赖可达性、账本修复入口、job 状态机、投票解析统一**
6
+
7
+ - **依赖不能指向已删的卡**:删除是 tombstone,而依赖判定只认 `status === 'done'`——指向一张已删除/已取消的卡会让新卡**永久** blocked 且无修复命令。`task.create` 现在拒绝这类 `blockedBy`。
8
+ - **`project.repair` 命令**:`ledger.repair()` 此前没有任何生产调用点,poison 之后只能重启。新增 Human 专用命令,返回 `repair`/`repairs`/`events`/`stateLastSeq` 并记 `ledger.repaired` 诊断。
9
+ - **job 状态机三处**:① `deps.vcs.backup` 不是每个适配器都有(git 就没有),无脑调用会 TypeError 让 job 卡到 TTL;② `plan.next` 是在 switch 之前算的,回写会把刚判死的 job 复活成 `judging`,下一轮再拿一个未应用的候选写假记录;③ `rollback` 无条件把陈旧的 `before` 写回 live,会覆盖评审期间的人工修改——现在先校验 live 仍是候选文本。
10
+ - **投票解析统一**:评审通道原本用自己的「第一个 `{` 到第一个 `}`」正则,会把模板回显计成票、也会在正文含 `}` 时整票丢弃。现在复用 judge 的平衡扫描解析器,并让它保留 `orderId`。
11
+ - 测试:`node --test` **242/242**(新增 4 例)。
12
+
3
13
  ## 0.4.39 - 2026-11-12
4
14
 
5
15
  **第三轮(对抗性复审)回归修复**
@@ -413,6 +413,7 @@ export class TeamService {
413
413
  case 'project.create': return await this.createProject(command, payload);
414
414
  case 'project.owner.update': return await this.changeProjectOwner(command, payload);
415
415
  case 'project.workspace.update': return await this.changeProjectWorkspace(command, payload);
416
+ case 'project.repair': return await this.runExclusive(() => this.repairLedger(command));
416
417
  case 'project.pmo.update': return await this.setProjectPmo(command, payload);
417
418
  case 'project.archive': return await this.setProjectArchive(command, payload);
418
419
  case 'project.runState': return await this.setProjectRunState(command, payload);
@@ -524,6 +525,27 @@ export class TeamService {
524
525
  return { project };
525
526
  }
526
527
 
528
+ /**
529
+ * 账本自检/修复入口(仅 Human)。`ledger.repair()` 此前没有任何生产调用点:
530
+ * 回滚失败被置为 poisoned 之后,除了重启宿主没有任何恢复路径。
531
+ */
532
+ async repairLedger(command) {
533
+ if (command.actor.kind !== 'human') fail(ERRORS.UNAUTHORIZED, 'only Human may repair the ledger');
534
+ const result = this.ledger.repair();
535
+ this.diag?.append({
536
+ ev: 'ledger.repaired',
537
+ projectId: command.projectId ?? null,
538
+ repair: result?.repair ?? null,
539
+ events: result?.events ?? null,
540
+ stateLastSeq: result?.stateLastSeq ?? null,
541
+ });
542
+ return {
543
+ repaired: result?.repair ?? null,
544
+ repairs: Array.isArray(result?.repairs) ? result.repairs : [],
545
+ events: result?.events ?? null,
546
+ stateLastSeq: result?.stateLastSeq ?? null,
547
+ };
548
+ }
527
549
  async changeProjectWorkspace(command, payload) {
528
550
  if (command.actor.kind !== 'human') fail(ERRORS.UNAUTHORIZED, 'only Human may change the Project workspace');
529
551
  const projectId = command.projectId;
@@ -1107,6 +1129,12 @@ export class TeamService {
1107
1129
  if (typeof dependency !== 'string' || Object.hasOwn(state.tasks ?? {}, dependency) !== true) {
1108
1130
  fail(ERRORS.INVALID_ARGUMENT, `blockedBy ${String(dependency)} is not a Task of this project`);
1109
1131
  }
1132
+ // 删除是 tombstone 而不是物理移除,而依赖判定只认 status === 'done':
1133
+ // 指向一张已删除的卡会让新卡**永久** blocked,且没有修复命令。
1134
+ const dependencyTask = state.tasks[dependency];
1135
+ if (dependencyTask?.tombstone === true || dependencyTask?.status === 'deleted' || dependencyTask?.status === 'cancelled') {
1136
+ fail(ERRORS.INVALID_ARGUMENT, `blockedBy ${String(dependency)} can never complete (it is ${dependencyTask?.tombstone === true ? 'deleted' : String(dependencyTask?.status)})`);
1137
+ }
1110
1138
  }
1111
1139
  }
1112
1140
  const title = typeof payload.title === 'string' ? payload.title.trim() : '';
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * 优化 job 的宿主侧收割:每个 PMO tick 调用一次,把状态机的一步动作落到
3
3
  * 真实文件/子代理/结果记录上。
4
4
  *
@@ -82,7 +82,10 @@ export async function stepJob(input) {
82
82
  deps.diag?.({ ev: 'skillopt.job.fail', jobId: job.id, reason: validation.reason });
83
83
  break;
84
84
  }
85
- job = { ...job, before, candidate: action.payload.text, backup: await deps.vcs.backup(job.skillPath, before) };
85
+ // 不是每个 vcs 适配器都有 backup(git 适配器就没有):无脑调用会 TypeError,
86
+ // job 卡到 TTL 才失败。
87
+ const backup = typeof deps.vcs?.backup === 'function' ? await deps.vcs.backup(job.skillPath, before) : null;
88
+ job = { ...job, before, candidate: action.payload.text, backup };
86
89
  // 先落盘再改 live:中途崩溃时 job 里已有 before/backup,可据此回滚;
87
90
  // 反过来(先改 live)会让磁盘上的技能停在未审候选且无任何记录。
88
91
  writeJob(projectDir, job);
@@ -140,13 +143,28 @@ export async function stepJob(input) {
140
143
  deps.diag?.({ ev: 'skillopt.job.done', jobId: job.id, verdict: decision.verdict, better: decision.better, worse: decision.worse, kept });
141
144
  }
142
145
  }
143
- if (plan.next !== job.state && plan.next !== 'failed') job = { ...job, state: plan.next, updatedAt: deps.now() };
146
+ // 失败/完成是终态:plan 是在 switch 之前算的,若拿它回写就会把刚判死的 job
147
+ // 复活成 judging,下一轮再拿一个未应用的候选写假记录。
148
+ const terminal = job.state === 'failed' || job.state === 'done';
149
+ if (!terminal && plan.next !== job.state && plan.next !== 'failed') job = { ...job, state: plan.next, updatedAt: deps.now() };
144
150
  writeJob(projectDir, job);
145
151
  return { job, changed: true };
146
152
  }
147
153
 
148
154
  async function rollback({ deps, job, projectDir }) {
149
155
  if (job?.candidate === undefined || job?.before === undefined) return;
156
+ // 回滚前必须确认 live 仍是**我们写下的那个候选**:评审期间可能有人手改,
157
+ // 无条件把陈旧的 before 写回去会覆盖掉那次人工修改(且原子性无从谈起)。
158
+ let current = null;
159
+ try {
160
+ current = deps.readText ? deps.readText(job.skillPath) : null;
161
+ } catch {
162
+ current = null;
163
+ }
164
+ if (typeof current === 'string' && sha12(current) !== sha12(job.candidate)) {
165
+ deps.diag?.({ ev: 'skillopt.rollback.skipped', jobId: job.id, reason: 'live file changed since the candidate was applied' });
166
+ return;
167
+ }
150
168
  try {
151
169
  if (deps.vcs.kind === 'file' && typeof job.backup === 'string') {
152
170
  await deps.vcs.restore(job.skillPath, job.backup);
@@ -88,6 +88,9 @@ export function parseJudgeOutput(output) {
88
88
  better: row.better,
89
89
  margin: row.margin === 'clear' ? 'clear' : 'slight',
90
90
  reason: typeof row.reason === 'string' ? row.reason.slice(0, 300) : '',
91
+ // 评审通道的回帖带 orderId(这一票对应哪一个 A/B 顺序);judge 通道没有
92
+ // 这个字段,忽略即可。保留它才能让两条通道共用同一个解析器。
93
+ ...(typeof row.orderId === 'string' && row.orderId !== '' ? { orderId: row.orderId } : {}),
91
94
  };
92
95
  }
93
96
  return found;
@@ -7,6 +7,7 @@
7
7
  * 的条目即可拿到 verdict,**不依赖一次性子代理的输出**。
8
8
  */
9
9
  import { REVIEWER_NAME, REVIEWER_ROLE, buildReviewRequest, decideReviewVotes, reviewVoteCount } from './reviewer.js';
10
+ import { parseJudgeOutput } from './judge.js';
10
11
 
11
12
  const REVIEW_TASK_PREFIX = 'skillopt-review';
12
13
 
@@ -79,14 +80,9 @@ export function collectReview({ service, job }) {
79
80
  for (const entry of entries) {
80
81
  if (votes.length >= orders.length) break;
81
82
  if (entry?.authorId !== reviewerId) continue;
82
- const parsed = (() => {
83
- try {
84
- const match = String(entry.body ?? '').match(/\{[\s\S]*?"better"[\s\S]*?\}/);
85
- return match === null ? null : JSON.parse(match[0]);
86
- } catch {
87
- return null;
88
- }
89
- })();
83
+ // 复用 judge 的容错解析:自己的「第一个 { 到第一个 }」正则会把模板回显
84
+ // 计成票,也会在正文含 } 时整票丢弃。
85
+ const parsed = parseJudgeOutput(entry.body);
90
86
  if (parsed === null || (parsed.better !== 'A' && parsed.better !== 'B' && parsed.better !== 'tie')) continue;
91
87
  let order = typeof parsed.orderId === 'string' ? byOrderId.get(parsed.orderId) : undefined;
92
88
  // 旧 job 的 orders 没有 orderId:保留按序对齐的兼容路径,但仍受票数上限约束。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suifei/dsh-ai-team",
3
- "version": "0.4.39",
3
+ "version": "0.4.40",
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",