sillyspec 3.25.9 → 3.25.11

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.
Files changed (71) hide show
  1. package/.claude/skills/sillyspec-auto/SKILL.md +8 -13
  2. package/.claude/skills/sillyspec-brainstorm/SKILL.md +8 -6
  3. package/.claude/skills/sillyspec-continue/SKILL.md +3 -3
  4. package/.claude/skills/sillyspec-doctor/SKILL.md +1 -1
  5. package/.claude/skills/sillyspec-execute/SKILL.md +10 -4
  6. package/.claude/skills/sillyspec-plan/SKILL.md +1 -1
  7. package/.claude/skills/sillyspec-verify/SKILL.md +1 -1
  8. package/README.md +9 -0
  9. package/package.json +2 -2
  10. package/src/change-list.js +11 -8
  11. package/src/change-risk-profile.js +22 -0
  12. package/src/db.js +160 -159
  13. package/src/dispatch/backends/local-agent.js +152 -0
  14. package/src/dispatch/backends/sillyhub-mcp.js +242 -0
  15. package/src/dispatch/probe.js +208 -0
  16. package/src/dispatch/strategy.js +121 -0
  17. package/src/doctor-diagnostics.js +19 -25
  18. package/src/fs-atomic.js +69 -69
  19. package/src/git-helper.js +66 -0
  20. package/src/hooks/worktree-guard.js +64 -55
  21. package/src/index.js +176 -34
  22. package/src/init.js +7 -14
  23. package/src/machine-interface.js +54 -19
  24. package/src/migrate.js +14 -4
  25. package/src/modules.js +16 -5
  26. package/src/progress/change-registry.js +72 -70
  27. package/src/progress/consistency-doctor.js +71 -14
  28. package/src/progress/shared.js +6 -3
  29. package/src/progress/stage-machine.js +61 -65
  30. package/src/progress/step-store.js +62 -67
  31. package/src/progress.js +155 -233
  32. package/src/quicklog.js +13 -5
  33. package/src/run/command.js +65 -37
  34. package/src/run/complete-handlers.js +1005 -889
  35. package/src/run/complete.js +115 -208
  36. package/src/run/concurrent-detect.js +132 -0
  37. package/src/run/gates.js +289 -17
  38. package/src/run/prompt.js +22 -68
  39. package/src/run/quick-audit.js +10 -9
  40. package/src/run/shared.js +648 -600
  41. package/src/run/stage.js +43 -24
  42. package/src/scan-postcheck.js +9 -31
  43. package/src/sillyhub-mcp/client.js +389 -0
  44. package/src/spec-dir-typo.js +71 -0
  45. package/src/stage-contract-engine.js +22 -1
  46. package/src/stage-contract-spec.js +11 -4
  47. package/src/stage-contract.js +26 -3
  48. package/src/stage-review.js +13 -9
  49. package/src/stages/archive.js +4 -6
  50. package/src/stages/brainstorm-auto.js +26 -20
  51. package/src/stages/brainstorm.js +29 -5
  52. package/src/stages/cmd-existence.js +145 -0
  53. package/src/stages/doctor.js +9 -6
  54. package/src/stages/execute.js +61 -20
  55. package/src/stages/plan-postcheck.js +152 -0
  56. package/src/stages/plan.js +16 -31
  57. package/src/stages/quick.js +1 -1
  58. package/src/stages/scan.js +9 -3
  59. package/src/stages/status.js +0 -1
  60. package/src/stages/verify.js +12 -7
  61. package/src/sync.js +4 -4
  62. package/src/task-review.js +30 -1
  63. package/src/verify-postcheck.js +933 -862
  64. package/src/version.js +19 -0
  65. package/src/worktree-apply.js +85 -68
  66. package/src/worktree-deps.js +89 -5
  67. package/src/worktree.js +213 -111
  68. package/templates/prompts/taskcard-rules.md +27 -0
  69. package/templates/prompts/verify-probes.md +3 -3
  70. package/.claude/skills/sillyspec-propose/SKILL.md +0 -87
  71. package/src/stages/propose.js +0 -181
package/src/modules.js CHANGED
@@ -60,7 +60,7 @@ function parseModuleCardFrontmatter(content) {
60
60
  * - verify_commands: 验证命令(build/test/lint)
61
61
  * - related_docs: 关联文档路径
62
62
  */
63
- export async function rebuildModuleMap(cwd) {
63
+ export async function rebuildModuleMap(cwd, { force = false } = {}) {
64
64
  const mapPath = findModuleMapPath(cwd);
65
65
  if (!mapPath) {
66
66
  console.error('❌ 未找到 .sillyspec/docs/<project>/modules/ 目录');
@@ -162,6 +162,13 @@ export async function rebuildModuleMap(cwd) {
162
162
  yaml += `\n`;
163
163
  }
164
164
 
165
+ // 破坏性保护(multi-agent-platform 坑 modules-rebuild-destructive):默认 dry-run 只预览不写,--force 才覆盖。
166
+ if (!force && existingMap) {
167
+ console.log('⚠️ rebuild 默认不写入(破坏性保护):该命令会覆盖 _module-map.yaml,清空 tags/entrypoints/main_symbols/depends_on/used_by 等手动维护字段');
168
+ console.log(' 本次为预览,未写入磁盘。确认覆盖请运行:sillyspec modules rebuild --force');
169
+ return { dryRun: true, path: mapPath }
170
+ }
171
+
165
172
  writeFileSync(mapPath, yaml, 'utf8');
166
173
  console.log(`✅ _module-map.yaml 已重建:${mapPath}`);
167
174
  console.log(` 模块数量:${allModuleIds.size}`);
@@ -170,6 +177,7 @@ export async function rebuildModuleMap(cwd) {
170
177
  }
171
178
  console.log(`\n⚠️ 注意:rebuild 只重建骨架。tags/entrypoints/main_symbols/depends_on/used_by 需要重新运行 scan 或手动补充。`);
172
179
  console.log(`ℹ️ schema 已升级到 v2,支持 role/core_files/test_files/entrypoints/depends_on/risk_level/verify_commands 等字段。`);
180
+ return { dryRun: false, path: mapPath, modules: allModuleIds.size }
173
181
  }
174
182
 
175
183
  /**
@@ -278,7 +286,10 @@ export async function generateDependenciesMd(cwd) {
278
286
  console.log(`✅ dependencies.md 已生成`);
279
287
  }
280
288
 
281
- function parseModuleMapSimple(content) {
289
+ // _module-map.yaml 简单 YAML 解析(模块上下文索引)。canonical 单一真相源——run/prompt.js
290
+ // 的 loadModuleContextIndex 与本文件 generateDependenciesMd 共用此函数(合并历史两份分叉副本,
291
+ // 2026-08-07;字段集取并集:core_files/test_files/related_docs/verify_commands + role/risk_level)。
292
+ export function parseModuleMapSimple(content) {
282
293
  const modules = {};
283
294
  let currentModule = null;
284
295
  let currentKey = null;
@@ -299,7 +310,7 @@ function parseModuleMapSimple(content) {
299
310
  if (!currentModule) continue;
300
311
 
301
312
  // Array field like depends_on:\n - xxx
302
- const arrayFieldMatch = line.match(/^ (depends_on|used_by|paths|tags|aliases|entrypoints|main_symbols|review_reasons):$/);
313
+ const arrayFieldMatch = line.match(/^ (depends_on|used_by|paths|tags|aliases|entrypoints|main_symbols|review_reasons|core_files|test_files|related_docs|verify_commands):$/);
303
314
  if (arrayFieldMatch) {
304
315
  if (currentArray && currentKey) modules[currentModule][currentKey] = currentArray;
305
316
  currentKey = arrayFieldMatch[1];
@@ -308,7 +319,7 @@ function parseModuleMapSimple(content) {
308
319
  }
309
320
 
310
321
  // Inline array like tags: [a, b]
311
- const inlineArrayMatch = line.match(/^ (depends_on|used_by|paths|tags|aliases|entrypoints|main_symbols|review_reasons): \[(.*)\]$/);
322
+ const inlineArrayMatch = line.match(/^ (depends_on|used_by|paths|tags|aliases|entrypoints|main_symbols|review_reasons|core_files|test_files|related_docs|verify_commands): \[(.*)\]$/);
312
323
  if (inlineArrayMatch) {
313
324
  if (currentArray && currentKey) modules[currentModule][currentKey] = currentArray;
314
325
  const vals = inlineArrayMatch[2].split(',').map(v => v.trim()).filter(Boolean);
@@ -319,7 +330,7 @@ function parseModuleMapSimple(content) {
319
330
  }
320
331
 
321
332
  // Scalar field
322
- const scalarMatch = line.match(/^ (status|doc|needs_review): (.+)$/);
333
+ const scalarMatch = line.match(/^ (status|doc|needs_review|role|risk_level): (.+)$/);
323
334
  if (scalarMatch) {
324
335
  if (currentArray && currentKey) { modules[currentModule][currentKey] = currentArray; currentArray = null; currentKey = null; }
325
336
  modules[currentModule][scalarMatch[1]] = scalarMatch[2];
@@ -12,32 +12,31 @@ export class ChangeRegistry {
12
12
  * 列出所有活跃变更名
13
13
  * SQL: SELECT name FROM changes WHERE status = 'active'
14
14
  */
15
- async listChanges(cwd) {
16
- const db = await this.pm._ensureDB(cwd);
15
+ listChanges(cwd) {
16
+ const db = this.pm._ensureDB(cwd);
17
17
  const sqlDb = db.getDb();
18
- const rows = sqlDb.exec("SELECT name FROM changes WHERE status = 'active' ORDER BY name");
19
- if (!rows || rows.length === 0) return [];
20
- return rows[0].values.map(r => r[0]);
18
+ const rows = sqlDb.prepare("SELECT name FROM changes WHERE status = 'active' ORDER BY name").all();
19
+ return rows.map(r => r.name);
21
20
  }
22
21
 
23
22
  /**
24
23
  * 注册变更到活跃列表
25
24
  * SQL: INSERT OR IGNORE → 若已 archived 则 UPDATE status='active'
26
25
  */
27
- async registerChange(cwd, changeName) {
26
+ registerChange(cwd, changeName) {
28
27
  if (!changeName) {
29
28
  console.warn('⚠️ registerChange: changeName 为空,跳过');
30
29
  return;
31
30
  }
32
- const db = await this.pm._ensureDB(cwd);
33
- db.transaction((sqlDb) => {
31
+ const db = this.pm._ensureDB(cwd);
32
+ db.transaction(() => {
33
+ const sqlDb = db.getDb();
34
34
  const now = new Date().toISOString();
35
35
  // 尝试插入新行
36
- sqlDb.run(
36
+ sqlDb.prepare(
37
37
  `INSERT OR IGNORE INTO changes (name, created_at, last_active)
38
- VALUES (?, ?, ?)`,
39
- [changeName, now, now]
40
- );
38
+ VALUES (?, ?, ?)`
39
+ ).run(changeName, now, now);
41
40
  // 注意:不复活已归档的变更——归档是不可逆操作
42
41
  // 如果变更已存在且为 archived,保持 archived 状态不变
43
42
  });
@@ -49,15 +48,15 @@ export class ChangeRegistry {
49
48
  * @param {string} changeName - 变更名
50
49
  * @param {{ status: string, mode?: string, reason?: string }} isolation
51
50
  */
52
- async updateChangeIsolation(cwd, changeName, isolation) {
53
- const db = await this.pm._ensureDB(cwd);
54
- const sqlDb = db.getDb();
51
+ updateChangeIsolation(cwd, changeName, isolation) {
52
+ const db = this.pm._ensureDB(cwd);
55
53
  try {
56
- sqlDb.run(
57
- `UPDATE changes SET isolation_status = ?, isolation_mode = ?, isolation_reason = ?, last_active = ? WHERE name = ?`,
58
- [isolation.status, isolation.mode || null, isolation.reason || null, new Date().toISOString(), changeName]
59
- );
60
- db._save();
54
+ db.transaction(() => {
55
+ const sqlDb = db.getDb();
56
+ sqlDb.prepare(
57
+ `UPDATE changes SET isolation_status = ?, isolation_mode = ?, isolation_reason = ?, last_active = ? WHERE name = ?`
58
+ ).run(isolation.status, isolation.mode || null, isolation.reason || null, new Date().toISOString(), changeName);
59
+ });
61
60
  } catch (err) {
62
61
  console.warn('⚠️ 更新 isolation 状态失败:', err.message);
63
62
  }
@@ -69,55 +68,54 @@ export class ChangeRegistry {
69
68
  * @param {string} changeName - 变更名
70
69
  * @returns {{ status: string|null, mode: string|null, reason: string|null }|null}
71
70
  */
72
- async readChangeIsolation(cwd, changeName) {
73
- const db = await this.pm._ensureDB(cwd);
71
+ readChangeIsolation(cwd, changeName) {
72
+ const db = this.pm._ensureDB(cwd);
74
73
  const sqlDb = db.getDb();
75
74
  try {
76
- const rows = sqlDb.exec(
77
- `SELECT isolation_status, isolation_mode, isolation_reason FROM changes WHERE name = ?`,
78
- [changeName]
79
- );
80
- if (!rows || rows.length === 0 || rows[0].values.length === 0) return null;
81
- const [status, mode, reason] = rows[0].values[0];
75
+ const row = sqlDb.prepare(
76
+ `SELECT isolation_status, isolation_mode, isolation_reason FROM changes WHERE name = ?`
77
+ ).get(changeName);
78
+ if (row === undefined) return null;
79
+ const { isolation_status: status, isolation_mode: mode, isolation_reason: reason } = row;
82
80
  return { status: status || null, mode: mode || null, reason: reason || null };
83
81
  } catch {
84
82
  return null;
85
83
  }
86
84
  }
87
85
 
88
- async _updatePlatformLastSync(cwd, changeName) {
86
+ _updatePlatformLastSync(cwd, changeName) {
89
87
  if (!changeName) return;
90
- const db = await this.pm._ensureDB(cwd);
91
- db.transaction((sqlDb) => {
92
- sqlDb.run(
93
- 'UPDATE changes SET platform_last_sync = ?, platform_sync_enabled = 1 WHERE name = ?',
94
- [new Date().toISOString(), changeName]
95
- );
88
+ const db = this.pm._ensureDB(cwd);
89
+ db.transaction(() => {
90
+ const sqlDb = db.getDb();
91
+ sqlDb.prepare(
92
+ 'UPDATE changes SET platform_last_sync = ?, platform_sync_enabled = 1 WHERE name = ?'
93
+ ).run(new Date().toISOString(), changeName);
96
94
  });
97
95
  }
98
96
 
99
- async _updateApprovalStatus(cwd, changeName, status, reason = null) {
97
+ _updateApprovalStatus(cwd, changeName, status, reason = null) {
100
98
  if (!changeName || !status) return;
101
- const db = await this.pm._ensureDB(cwd);
102
- db.transaction((sqlDb) => {
103
- const rows = sqlDb.exec('SELECT id FROM changes WHERE name = ?', [changeName]);
104
- if (!rows || rows.length === 0 || rows[0].values.length === 0) return;
105
- const changeId = rows[0].values[0][0];
99
+ const db = this.pm._ensureDB(cwd);
100
+ db.transaction(() => {
101
+ const sqlDb = db.getDb();
102
+ const row = sqlDb.prepare('SELECT id FROM changes WHERE name = ?').get(changeName);
103
+ if (row === undefined) return;
104
+ const changeId = row.id;
106
105
  const now = new Date().toISOString();
107
- sqlDb.run(
106
+ sqlDb.prepare(
108
107
  `INSERT INTO approvals (change_id, status, requested_at, approved_at, rejection_reason)
109
108
  VALUES (?, ?, ?, ?, ?)
110
109
  ON CONFLICT(change_id) DO UPDATE SET
111
110
  status = excluded.status,
112
111
  approved_at = excluded.approved_at,
113
- rejection_reason = excluded.rejection_reason`,
114
- [
115
- changeId,
116
- status,
117
- now,
118
- status === 'approved' ? now : null,
119
- status === 'rejected' ? reason : null,
120
- ]
112
+ rejection_reason = excluded.rejection_reason`
113
+ ).run(
114
+ changeId,
115
+ status,
116
+ now,
117
+ status === 'approved' ? now : null,
118
+ status === 'rejected' ? reason : null,
121
119
  );
122
120
  });
123
121
  }
@@ -128,7 +126,7 @@ export class ChangeRegistry {
128
126
  * @param {string} oldName - 旧变更名
129
127
  * @param {string} newName - 新变更名
130
128
  */
131
- async renameChange(cwd, oldName, newName) {
129
+ renameChange(cwd, oldName, newName) {
132
130
  if (!oldName || !newName) {
133
131
  console.warn('⚠️ renameChange: 旧名或新名为空,跳过');
134
132
  return;
@@ -137,21 +135,23 @@ export class ChangeRegistry {
137
135
  console.warn('⚠️ renameChange: 新旧名称相同,跳过');
138
136
  return;
139
137
  }
140
- const db = await this.pm._ensureDB(cwd);
138
+ const db = this.pm._ensureDB(cwd);
141
139
  // 检查旧名是否存在
142
- const existing = db.transaction((sqlDb) => {
143
- const row = sqlDb.exec(`SELECT name, status FROM changes WHERE name = ?`, [oldName]);
144
- if (!row || !row[0] || row[0].values.length === 0) return null;
145
- return { name: row[0].values[0][0], status: row[0].values[0][1] };
140
+ const existing = db.transaction(() => {
141
+ const sqlDb = db.getDb();
142
+ const row = sqlDb.prepare(`SELECT name, status FROM changes WHERE name = ?`).get(oldName);
143
+ if (row === undefined) return null;
144
+ return { name: row.name, status: row.status };
146
145
  });
147
146
  if (!existing) {
148
147
  console.error(`❌ 变更 ${oldName} 不存在`);
149
148
  return;
150
149
  }
151
150
  // 检查新名是否已存在
152
- const conflict = db.transaction((sqlDb) => {
153
- const row = sqlDb.exec(`SELECT name FROM changes WHERE name = ?`, [newName]);
154
- return row && row[0] && row[0].values.length > 0;
151
+ const conflict = db.transaction(() => {
152
+ const sqlDb = db.getDb();
153
+ const row = sqlDb.prepare(`SELECT name FROM changes WHERE name = ?`).get(newName);
154
+ return row !== undefined;
155
155
  });
156
156
  if (conflict) {
157
157
  console.error(`❌ 变更 ${newName} 已存在`);
@@ -164,8 +164,9 @@ export class ChangeRegistry {
164
164
  const newDir = this.pm._changePath(cwd, newName);
165
165
  const now = new Date().toISOString();
166
166
  try {
167
- db.transaction((sqlDb) => {
168
- sqlDb.run(`UPDATE changes SET name = ?, last_active = ? WHERE name = ?`, [newName, now, oldName]);
167
+ db.transaction(() => {
168
+ const sqlDb = db.getDb();
169
+ sqlDb.prepare(`UPDATE changes SET name = ?, last_active = ? WHERE name = ?`).run(newName, now, oldName);
169
170
  });
170
171
  } catch (e) {
171
172
  console.error(`❌ 重命名失败:更新数据库时出错(${e.message})`);
@@ -179,8 +180,9 @@ export class ChangeRegistry {
179
180
  renamed = false;
180
181
  // FS 重命名失败:回滚 DB 恢复 oldName,保持 DB 与目录一致
181
182
  try {
182
- db.transaction((sqlDb) => {
183
- sqlDb.run(`UPDATE changes SET name = ?, last_active = ? WHERE name = ?`, [oldName, now, newName]);
183
+ db.transaction(() => {
184
+ const sqlDb = db.getDb();
185
+ sqlDb.prepare(`UPDATE changes SET name = ?, last_active = ? WHERE name = ?`).run(oldName, now, newName);
184
186
  });
185
187
  console.error(`❌ 重命名失败:移动目录出错(${e.message}),已回滚数据库`);
186
188
  } catch (rollbackErr) {
@@ -199,18 +201,18 @@ export class ChangeRegistry {
199
201
  * 从活跃列表移除变更(归档时调用,不物理删除)
200
202
  * SQL: UPDATE changes SET status = 'archived'
201
203
  */
202
- async unregisterChange(cwd, changeName) {
204
+ unregisterChange(cwd, changeName) {
203
205
  if (!changeName) {
204
206
  console.warn('⚠️ unregisterChange: changeName 为空,跳过');
205
207
  return;
206
208
  }
207
- const db = await this.pm._ensureDB(cwd);
208
- db.transaction((sqlDb) => {
209
+ const db = this.pm._ensureDB(cwd);
210
+ db.transaction(() => {
211
+ const sqlDb = db.getDb();
209
212
  const now = new Date().toISOString();
210
- sqlDb.run(
211
- `UPDATE changes SET status = 'archived', last_active = ? WHERE name = ?`,
212
- [now, changeName]
213
- );
213
+ sqlDb.prepare(
214
+ `UPDATE changes SET status = 'archived', last_active = ? WHERE name = ?`
215
+ ).run(now, changeName);
214
216
  });
215
217
  }
216
218
  }
@@ -1,9 +1,10 @@
1
1
  // W6 Step9a: Revision v1 状态一致性检查 + 修复 + --force 审计日志。
2
2
  // 从 src/progress.js 单体 ProgressManager 抽出。持有 pm 引用(构造注入),调 pm.read / pm._write /
3
3
  // pm._ensureRuntimeDir / pm._runtimePath(persistence-core 留 facade 本体)。
4
- import { appendFileSync } from 'fs';
5
- import { existsSync } from 'fs';
6
- import { STAGE_ORDER } from './shared.js';
4
+ import { appendFileSync, existsSync, readdirSync } from 'fs';
5
+ import { join } from 'path';
6
+ import { summarizeTaskCompletion } from '../task-review.js';
7
+ import { STAGE_ORDER, MAIN_FLOW_ORDER } from './shared.js';
7
8
 
8
9
  export class ConsistencyDoctor {
9
10
  constructor(pm) {
@@ -32,8 +33,8 @@ export class ConsistencyDoctor {
32
33
  * @param {string|null} changeName
33
34
  * @returns {{ ok: boolean, issues: string[], warnings: string[] }}
34
35
  */
35
- async checkConsistency(cwd, changeName = null) {
36
- const data = await this.pm.read(cwd, changeName);
36
+ checkConsistency(cwd, changeName = null) {
37
+ const data = this.pm.read(cwd, changeName);
37
38
  if (!data) {
38
39
  return { ok: false, issues: ['无法读取进度数据'], warnings: [] };
39
40
  }
@@ -71,9 +72,11 @@ export class ConsistencyDoctor {
71
72
  }
72
73
 
73
74
  // d. 下游 completed 不能出现在上游 stale/revising 之后
74
- const stageIdx = STAGE_ORDER.indexOf(stageName);
75
+ // 用 MAIN_FLOW_ORDER(不含 scan)算上下游:scan 是 auxiliary 永不要求 completed,
76
+ // 把 scan 当上游会让「scan stale/revising」误报 brainstorm 不该 completed(plan-c 同根因)。
77
+ const stageIdx = MAIN_FLOW_ORDER.indexOf(stageName);
75
78
  for (let i = 0; i < stageIdx; i++) {
76
- const upstream = STAGE_ORDER[i];
79
+ const upstream = MAIN_FLOW_ORDER[i];
77
80
  const upData = data.stages[upstream];
78
81
  if (upData && (upData.status === 'stale' || upData.status === 'revising')) {
79
82
  if (sd.status === 'completed') {
@@ -91,6 +94,12 @@ export class ConsistencyDoctor {
91
94
  }
92
95
  }
93
96
 
97
+ // FR-07 / AC-03 / design §7 / D-02:lost-update 间接信号
98
+ // (.runtime/worktrees/<change> 目录残留 vs DB current_stage≠execute)。
99
+ // 只读诊断并入 issues 报告,不写 DB / 不删 worktree / 不自动修复。
100
+ const lostUpdateSignals = this.detectLostUpdateSignals(cwd);
101
+ issues.push(...lostUpdateSignals);
102
+
94
103
  // 输出报告
95
104
  console.log('');
96
105
  console.log(' ═══════════════════════════════════════');
@@ -114,6 +123,55 @@ export class ConsistencyDoctor {
114
123
  return { ok: issues.length === 0, issues, warnings };
115
124
  }
116
125
 
126
+ /**
127
+ * 检测 lost-update 间接信号(FR-07 / AC-03 / design §7 / D-02)。
128
+ *
129
+ * 判据:.runtime/worktrees/<change> 目录存在但 DB current_stage ≠ 'execute'
130
+ * → worktree 残留但进度被回退,是并发场景下 lost-update 的间接痕迹。
131
+ *
132
+ * 信号定义严格遵循 design §7 / FR-07:仅 current_stage !== 'execute' 判信号,
133
+ * 不扩展到 quick 等其它 stage;DB 无对应行(data=null)的 worktree 目录不算信号。
134
+ *
135
+ * 只读诊断:不写 DB、不删 worktree 目录、不自动修复
136
+ * (修复仍走 doctor --align / repairConsistency 既有逻辑)。
137
+ *
138
+ * @param {string} cwd
139
+ * @returns {string[]} issue 描述数组(每条含 change 名、实际 current_stage、worktree 目录路径)
140
+ */
141
+ detectLostUpdateSignals(cwd) {
142
+ const worktreesRoot = this.pm._runtimePath(cwd, 'worktrees');
143
+ // 零信号兼容既有 fixture:worktrees 目录不存在或读取失败时直接返回空数组
144
+ if (!existsSync(worktreesRoot)) return [];
145
+
146
+ let entries;
147
+ try {
148
+ entries = readdirSync(worktreesRoot, { withFileTypes: true });
149
+ } catch {
150
+ return [];
151
+ }
152
+
153
+ const issues = [];
154
+ for (const entry of entries) {
155
+ // Dirent.isDirectory 在 Windows / Linux / macOS 上一致判定目录项
156
+ if (!entry.isDirectory()) continue;
157
+ const changeName = entry.name;
158
+ const worktreeDir = join(worktreesRoot, changeName);
159
+
160
+ // 复用 pm.read(task-08 已同步化,直接拿返回值,无 await),不新开 DB 连接
161
+ const data = this.pm.read(cwd, changeName);
162
+ // DB 无对应行(data=null)不算信号,跳过
163
+ if (!data) continue;
164
+ // 仅 current_stage !== 'execute' 判信号
165
+ if (data.currentStage !== 'execute') {
166
+ issues.push(
167
+ `lost-update 信号: change "${changeName}" 的 worktree 目录仍存在(${worktreeDir}),` +
168
+ `但 current_stage 为 "${data.currentStage}"(非 execute,疑进度被回退)`
169
+ );
170
+ }
171
+ }
172
+ return issues;
173
+ }
174
+
117
175
  /**
118
176
  * Revision v1.2 状态修复
119
177
  * 默认 dry-run,--apply 才真正修改 DB。
@@ -125,10 +183,10 @@ export class ConsistencyDoctor {
125
183
  * @param {string|null} [opts.changeName]
126
184
  * @returns {{ fixable: object[], manual: string[], applied: object[] }}
127
185
  */
128
- async repairConsistency(cwd, opts = {}) {
186
+ repairConsistency(cwd, opts = {}) {
129
187
  const { apply = false, changeName = null } = opts;
130
188
 
131
- const data = await this.pm.read(cwd, changeName);
189
+ const data = this.pm.read(cwd, changeName);
132
190
  if (!data) {
133
191
  console.log('❌ 无法读取进度数据');
134
192
  return { fixable: [], manual: ['无法读取进度数据'], applied: [] };
@@ -156,10 +214,10 @@ export class ConsistencyDoctor {
156
214
  });
157
215
  }
158
216
 
159
- // Fix b: 上游 stale/revising,下游仍 completed → cascade stale
160
- const stageIdx = STAGE_ORDER.indexOf(stageName);
217
+ // Fix b: 上游 stale/revising,下游仍 completed → cascade stale(同 d,用 MAIN_FLOW_ORDER 排除 scan)
218
+ const stageIdx = MAIN_FLOW_ORDER.indexOf(stageName);
161
219
  for (let i = 0; i < stageIdx; i++) {
162
- const upstream = STAGE_ORDER[i];
220
+ const upstream = MAIN_FLOW_ORDER[i];
163
221
  const upData = data.stages[upstream];
164
222
  if (upData && (upData.status === 'stale' || upData.status === 'revising')) {
165
223
  if (sd.status === 'completed') {
@@ -206,7 +264,6 @@ export class ConsistencyDoctor {
206
264
  const changeDir = this.pm._changePath(cwd, changeName);
207
265
  if (changeDir && existsSync(changeDir)) {
208
266
  const runtimeRoot = this.pm._runtimePath(cwd);
209
- const { summarizeTaskCompletion } = await import('../task-review.js');
210
267
  const summary = summarizeTaskCompletion({ changeDir, runtimeRoot, changeName });
211
268
  if (summary.source === 'review.json' && summary.total > 0 && summary.pending.length === 0) {
212
269
  const desc = `execute: ${badSteps.length} 个 step 状态脱钩(${badSteps.map(st => st.name).join(', ')})——review.json 客观产出全通过(${summary.completed}/${summary.total}),自动标 completed`;
@@ -286,7 +343,7 @@ export class ConsistencyDoctor {
286
343
 
287
344
  if (apply && applied.length > 0) {
288
345
  data.lastActive = now;
289
- await this.pm._write(cwd, data, changeName);
346
+ this.pm._write(cwd, data, changeName);
290
347
  console.log(`\n ✅ 已修复 ${applied.length} 项`);
291
348
  }
292
349
 
@@ -18,10 +18,13 @@ export const STAGE_LABELS = {
18
18
  archive: '📦 归档变更',
19
19
  };
20
20
 
21
- // 完整主流程顺序(含 scan),用于下游 cascade / 一致性检查
21
+ // 完整阶段顺序(含 scan),仅用于展示/迭代顺序
22
22
  export const STAGE_ORDER = ['scan', 'brainstorm', 'plan', 'execute', 'verify', 'archive'];
23
- // 主流程阶段(不含 scan/quick/explore 等辅助阶段)—— 当前与 STAGE_ORDER 同值
24
- export const MAIN_FLOW_ORDER = STAGE_ORDER;
23
+ // 主流程阶段(不含 scan/quick/explore 等辅助阶段)—— 用于下游 cascade / 一致性上下游判定。
24
+ // scan 是 auxiliary(AUXILIARY_STAGES,按需显式跑、可 failed_post_check、永不要求 completed),
25
+ // 把它算进主流程上下游会让「scan stale/revising」误报 brainstorm/plan/execute 不该 completed
26
+ // (consistency-doctor 坑 + prompt-control-debt plan-c 同根因)。
27
+ export const MAIN_FLOW_ORDER = ['brainstorm', 'plan', 'execute', 'verify', 'archive'];
25
28
 
26
29
  // progress 数据版本(v3 = SQLite)
27
30
  export const CURRENT_VERSION = 3;