sillyspec 3.25.0 → 3.25.2

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 (45) hide show
  1. package/.claude/skills/sillyspec-doctor/SKILL.md +9 -0
  2. package/.playwright-mcp/console-2026-07-27T15-45-50-621Z.log +1 -0
  3. package/.playwright-mcp/page-2026-07-27T15-45-51-459Z.yml +144 -0
  4. package/.playwright-mcp/prompt-final.png +0 -0
  5. package/.playwright-mcp/prompt-view.png +0 -0
  6. package/CLAUDE.md +18 -0
  7. package/package.json +1 -1
  8. package/src/change-risk-profile.js +60 -12
  9. package/src/check-primitives.js +65 -0
  10. package/src/db.js +28 -8
  11. package/src/hooks/worktree-guard.js +9 -2
  12. package/src/index.js +140 -11
  13. package/src/machine-interface.js +13 -7
  14. package/src/progress/change-registry.js +217 -0
  15. package/src/progress/consistency-doctor.js +259 -0
  16. package/src/progress/shared.js +33 -0
  17. package/src/progress/stage-machine.js +535 -0
  18. package/src/progress/step-store.js +256 -0
  19. package/src/progress.js +75 -1191
  20. package/src/quicklog.js +3 -1
  21. package/src/run/command.js +1088 -0
  22. package/src/run/complete-handlers.js +874 -0
  23. package/src/run/complete.js +725 -0
  24. package/src/run/gates.js +326 -0
  25. package/src/run/prompt.js +619 -0
  26. package/src/run/quick-audit.js +107 -0
  27. package/src/run/scan-profile.js +238 -0
  28. package/src/run/shared.js +418 -0
  29. package/src/run/stage.js +414 -0
  30. package/src/run.js +23 -4379
  31. package/src/stage-contract-engine.js +150 -0
  32. package/src/stage-contract-spec.js +517 -0
  33. package/src/stage-contract.js +87 -150
  34. package/src/stage-review.js +63 -0
  35. package/src/stages/brainstorm.js +3 -1
  36. package/src/stages/execute.js +5 -2
  37. package/src/stages/plan-postcheck.js +38 -27
  38. package/src/stages/plan.js +12 -49
  39. package/src/stages/propose.js +2 -1
  40. package/src/stages/scan.js +3 -1
  41. package/src/workflow.js +9 -17
  42. package/src/worktree-apply.js +5 -2
  43. package/src/worktree-deps.js +114 -32
  44. package/src/worktree.js +23 -11
  45. package/src/brainstorm-postcheck.js +0 -158
@@ -0,0 +1,259 @@
1
+ // W6 Step9a: Revision v1 状态一致性检查 + 修复 + --force 审计日志。
2
+ // 从 src/progress.js 单体 ProgressManager 抽出。持有 pm 引用(构造注入),调 pm.read / pm._write /
3
+ // pm._ensureRuntimeDir / pm._runtimePath(persistence-core 留 facade 本体)。
4
+ import { appendFileSync } from 'fs';
5
+ import { STAGE_ORDER } from './shared.js';
6
+
7
+ export class ConsistencyDoctor {
8
+ constructor(pm) {
9
+ this.pm = pm;
10
+ }
11
+
12
+ /**
13
+ * 强制状态变更的审计记录(--force 逃生口专用)。
14
+ * 追加到 .runtime/audit.log,供人工/doctor 追溯"谁在什么时候绕过了校验"。
15
+ */
16
+ _appendAuditLog(cwd, entry) {
17
+ try {
18
+ this.pm._ensureRuntimeDir(cwd);
19
+ const auditPath = this.pm._runtimePath(cwd, 'audit.log');
20
+ const line = JSON.stringify({ at: new Date().toISOString(), ...entry });
21
+ appendFileSync(auditPath, line + '\n');
22
+ } catch (e) {
23
+ console.warn(`⚠️ 审计日志写入失败: ${e.message}`);
24
+ }
25
+ }
26
+
27
+ /**
28
+ * Revision v1 状态一致性检查
29
+ * 只报告,不自动修复。
30
+ * @param {string} cwd
31
+ * @param {string|null} changeName
32
+ * @returns {{ ok: boolean, issues: string[], warnings: string[] }}
33
+ */
34
+ async checkConsistency(cwd, changeName = null) {
35
+ const data = await this.pm.read(cwd, changeName);
36
+ if (!data) {
37
+ return { ok: false, issues: ['无法读取进度数据'], warnings: [] };
38
+ }
39
+
40
+ const issues = [];
41
+ const warnings = [];
42
+
43
+ for (const stageName of STAGE_ORDER) {
44
+ const sd = data.stages[stageName];
45
+ if (!sd) continue;
46
+
47
+ // a. completed stage 不能有 pending/stale steps
48
+ if (sd.status === 'completed' && sd.steps) {
49
+ const badSteps = sd.steps.filter(s => ['pending', 'stale', 'in-progress'].includes(s.status));
50
+ for (const step of badSteps) {
51
+ issues.push(`${stageName}/${step.name}: step 状态为 ${step.status},但 stage 状态为 completed`);
52
+ }
53
+ }
54
+
55
+ // b. revising stage 应有 revision > 0 或 reopenedFromStep
56
+ if (sd.status === 'revising') {
57
+ if (!sd.revision || sd.revision < 1) {
58
+ issues.push(`${stageName}: 状态为 revising 但 revision 缺失或为 0`);
59
+ }
60
+ if (!sd.reopenedFromStep) {
61
+ warnings.push(`${stageName}: 状态为 revising 但未记录 reopenedFromStep`);
62
+ }
63
+ }
64
+
65
+ // c. stale stage 应有 staleReason
66
+ if (sd.status === 'stale') {
67
+ if (!sd.staleReason) {
68
+ warnings.push(`${stageName}: 状态为 stale 但缺少 staleReason`);
69
+ }
70
+ }
71
+
72
+ // d. 下游 completed 不能出现在上游 stale/revising 之后
73
+ const stageIdx = STAGE_ORDER.indexOf(stageName);
74
+ for (let i = 0; i < stageIdx; i++) {
75
+ const upstream = STAGE_ORDER[i];
76
+ const upData = data.stages[upstream];
77
+ if (upData && (upData.status === 'stale' || upData.status === 'revising')) {
78
+ if (sd.status === 'completed') {
79
+ issues.push(`${stageName}: 状态为 completed,但上游 ${upstream} 状态为 ${upData.status}(下游不应在上游修订/失效时保持 completed)`);
80
+ }
81
+ }
82
+ }
83
+
84
+ // e. step stale 时 stage 不应是 completed
85
+ if (sd.status === 'completed' && sd.steps) {
86
+ const staleSteps = sd.steps.filter(s => s.status === 'stale');
87
+ for (const step of staleSteps) {
88
+ issues.push(`${stageName}/${step.name}: step 状态为 stale,但 stage 状态为 completed`);
89
+ }
90
+ }
91
+ }
92
+
93
+ // 输出报告
94
+ console.log('');
95
+ console.log(' ═══════════════════════════════════════');
96
+ console.log(' 状态一致性检查');
97
+ console.log(' ═══════════════════════════════════════');
98
+
99
+ if (issues.length === 0 && warnings.length === 0) {
100
+ console.log(' ✅ 未发现一致性问题');
101
+ } else {
102
+ if (issues.length > 0) {
103
+ console.log(`\n ❌ 问题 (${issues.length}):`);
104
+ for (const issue of issues) console.log(` - ${issue}`);
105
+ }
106
+ if (warnings.length > 0) {
107
+ console.log(`\n ⚠️ 警告 (${warnings.length}):`);
108
+ for (const w of warnings) console.log(` - ${w}`);
109
+ }
110
+ }
111
+ console.log('');
112
+
113
+ return { ok: issues.length === 0, issues, warnings };
114
+ }
115
+
116
+ /**
117
+ * Revision v1.2 状态修复
118
+ * 默认 dry-run,--apply 才真正修改 DB。
119
+ * 只修安全项,不碰产物文件、不 reset/reopen stage。
120
+ *
121
+ * @param {string} cwd
122
+ * @param {object} opts
123
+ * @param {boolean} [opts.apply=false]
124
+ * @param {string|null} [opts.changeName]
125
+ * @returns {{ fixable: object[], manual: string[], applied: object[] }}
126
+ */
127
+ async repairConsistency(cwd, opts = {}) {
128
+ const { apply = false, changeName = null } = opts;
129
+
130
+ const data = await this.pm.read(cwd, changeName);
131
+ if (!data) {
132
+ console.log('❌ 无法读取进度数据');
133
+ return { fixable: [], manual: ['无法读取进度数据'], applied: [] };
134
+ }
135
+
136
+ const fixable = []; // { stage, action, description, apply: (data) => void }
137
+ const manual = []; // string
138
+
139
+ const now = new Date().toLocaleString('zh-CN', { hour12: false });
140
+
141
+ for (const stageName of STAGE_ORDER) {
142
+ const sd = data.stages[stageName];
143
+ if (!sd) continue;
144
+
145
+ // Fix a: stale stage 缺 staleReason → 补默认原因
146
+ if (sd.status === 'stale' && !sd.staleReason) {
147
+ const reason = stageName === 'archive'
148
+ ? 'upstream stage revised; existing archive artifacts are preserved but no longer trusted'
149
+ : 'unknown upstream revision';
150
+ fixable.push({
151
+ stage: stageName,
152
+ action: 'set_stale_reason',
153
+ description: `${stageName}: stale 缺 staleReason → 补 "${reason}"`,
154
+ apply: (d) => { d.stages[stageName].staleReason = reason; },
155
+ });
156
+ }
157
+
158
+ // Fix b: 上游 stale/revising,下游仍 completed → cascade stale
159
+ const stageIdx = STAGE_ORDER.indexOf(stageName);
160
+ for (let i = 0; i < stageIdx; i++) {
161
+ const upstream = STAGE_ORDER[i];
162
+ const upData = data.stages[upstream];
163
+ if (upData && (upData.status === 'stale' || upData.status === 'revising')) {
164
+ if (sd.status === 'completed') {
165
+ const upStatus = upData.status;
166
+ const reason = `upstream ${upstream} is ${upStatus}`;
167
+ fixable.push({
168
+ stage: stageName,
169
+ action: 'cascade_stale',
170
+ description: `${stageName}: completed → stale(上游 ${upstream} 为 ${upStatus})`,
171
+ apply: (d) => {
172
+ d.stages[stageName].status = 'stale';
173
+ d.stages[stageName].staleReason = reason;
174
+ d.stages[stageName].completedAt = null;
175
+ },
176
+ });
177
+ }
178
+ }
179
+ }
180
+
181
+ // Fix c: archive stale 缺 staleReason(专用文案)
182
+ if (stageName === 'archive' && sd.status === 'stale' && !sd.staleReason) {
183
+ // 已在 Fix a 中处理,这里不重复
184
+ }
185
+
186
+ // Fix d: revising stage 缺 reopenedAt → 补当前时间
187
+ if (sd.status === 'revising' && !sd.reopenedAt) {
188
+ fixable.push({
189
+ stage: stageName,
190
+ action: 'set_reopened_at',
191
+ description: `${stageName}: revising 缺 reopenedAt → 补当前时间`,
192
+ apply: (d) => { d.stages[stageName].reopenedAt = now; },
193
+ });
194
+ }
195
+
196
+ // Manual a: completed stage 里有 pending/stale/in-progress steps
197
+ if (sd.status === 'completed' && sd.steps) {
198
+ const badSteps = sd.steps.filter(s => ['pending', 'stale', 'in-progress'].includes(s.status));
199
+ for (const step of badSteps) {
200
+ manual.push(`${stageName}/${step.name}: step 状态为 ${step.status},但 stage 状态为 completed(需手动确认)`);
201
+ }
202
+ }
203
+
204
+ // Manual b: revising stage 缺 reopenedFromStep
205
+ if (sd.status === 'revising' && !sd.reopenedFromStep) {
206
+ manual.push(`${stageName}: revising 缺 reopenedFromStep(需手动确认修订起始步骤)`);
207
+ }
208
+
209
+ // Manual c: steps 为空但 stage completed
210
+ if (sd.status === 'completed' && (!sd.steps || sd.steps.length === 0)) {
211
+ manual.push(`${stageName}: completed 但 steps 为空(需手动确认)`);
212
+ }
213
+ }
214
+
215
+ // 输出报告
216
+ console.log('');
217
+ console.log(' ═══════════════════════════════════════');
218
+ console.log(` 状态修复 ${apply ? '(--apply 模式)' : '(dry-run 模式)'}`);
219
+ console.log(' ═══════════════════════════════════════');
220
+
221
+ if (fixable.length === 0 && manual.length === 0) {
222
+ console.log(' ✅ 未发现问题,无需修复');
223
+ console.log('');
224
+ return { fixable: [], manual: [], applied: [] };
225
+ }
226
+
227
+ const applied = [];
228
+
229
+ if (fixable.length > 0) {
230
+ console.log(`\n 🔧 可自动修复 (${fixable.length}):`);
231
+ for (const item of fixable) {
232
+ console.log(` - ${item.description}`);
233
+ if (apply) {
234
+ item.apply(data);
235
+ applied.push({ stage: item.stage, action: item.action });
236
+ }
237
+ }
238
+ if (!apply) {
239
+ console.log('\n 💡 使用 --apply 执行修复');
240
+ }
241
+ }
242
+
243
+ if (manual.length > 0) {
244
+ console.log(`\n 👆 需手动处理 (${manual.length}):`);
245
+ for (const m of manual) console.log(` - ${m}`);
246
+ }
247
+
248
+ if (apply && applied.length > 0) {
249
+ data.lastActive = now;
250
+ await this.pm._write(cwd, data, changeName);
251
+ console.log(`\n ✅ 已修复 ${applied.length} 项`);
252
+ }
253
+
254
+ console.log('');
255
+
256
+ return { fixable, manual, applied };
257
+ }
258
+ }
259
+
@@ -0,0 +1,33 @@
1
+ // W6 Step9 共享常量:progress.js facade 与 src/progress/* 子模块共用,避免 facade↔子模块循环引用。
2
+ // 9a: STAGE_ORDER/MAIN_FLOW_ORDER;9c: VALID_STAGES/STAGE_LABELS;9d: SPEC_DIR_NAME/CURRENT_VERSION/emptyStage。
3
+
4
+ export const SPEC_DIR_NAME = '.sillyspec';
5
+
6
+ // 合法阶段名(含辅助阶段 scan/quick/explore)
7
+ export const VALID_STAGES = ['scan', 'brainstorm', 'plan', 'execute', 'verify', 'archive', 'quick', 'explore'];
8
+
9
+ // 阶段展示文案
10
+ export const STAGE_LABELS = {
11
+ brainstorm: '🧠 需求探索',
12
+ plan: '📐 实现计划',
13
+ execute: '⚡ 波次执行',
14
+ verify: '🔍 验证确认',
15
+ scan: '🔍 代码扫描',
16
+ quick: '⚡ 快速任务',
17
+ explore: '🧭 自由探索',
18
+ archive: '📦 归档变更',
19
+ };
20
+
21
+ // 完整主流程顺序(含 scan),用于下游 cascade / 一致性检查
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;
25
+
26
+ // progress 数据版本(v3 = SQLite)
27
+ export const CURRENT_VERSION = 3;
28
+
29
+ // 空阶段骨架
30
+ export function emptyStage() {
31
+ return { status: 'pending', steps: [], startedAt: null, completedAt: null };
32
+ }
33
+