sillyspec 3.17.15 → 3.18.1
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/docs/platform-scan-protocol.md +298 -0
- package/package.json +1 -1
- package/src/constants.js +70 -0
- package/src/db.js +4 -0
- package/src/hooks/worktree-guard.js +97 -4
- package/src/index.js +56 -1
- package/src/progress.js +41 -14
- package/src/run.js +315 -83
- package/src/scan-postcheck.js +17 -16
- package/src/stage-contract.js +244 -12
- package/src/stages/brainstorm.js +228 -8
- package/src/stages/index.js +0 -2
- package/src/stages/plan.js +237 -52
- package/src/stages/propose.js +30 -4
- package/src/stages/quick.js +13 -10
- package/src/stages/scan.js +12 -0
- package/src/stages/verify.js +31 -13
- package/src/workflow.js +1 -0
- package/test/platform-artifacts.test.mjs +190 -0
- package/test/platform-failure-samples.test.mjs +195 -0
- package/test/platform-recovery-chain.test.mjs +179 -0
- package/test/platform-recovery.test.mjs +14 -6
- package/test/platform-scan-p0.test.mjs +5 -2
- package/test/run-tests.mjs +31 -3
- package/test/scan-paths.test.mjs +1 -1
- package/test/scan-postcheck.test.mjs +4 -3
- package/test/spec-dir.test.mjs +3 -2
- package/test/stage-contract.test.mjs +120 -7
- package/test/stage-definitions.test.mjs +2 -6
- package/test/wait-gates.test.mjs +501 -0
- package/test/worktree-guard.test.mjs +58 -0
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
# 平台 Scan 产物协议
|
|
2
|
+
|
|
3
|
+
SillySpec 平台执行模式的核心设计:**SillySpec 写产物,SillyHub 读产物**。平台不看 stdout,只靠文件系统判断 scan 成功、失败原因和证据文件位置。
|
|
4
|
+
|
|
5
|
+
## 状态枚举(src/constants.js)
|
|
6
|
+
|
|
7
|
+
所有平台产物共享同一套枚举值,SillyHub 直接使用常量,不猜字符串。
|
|
8
|
+
|
|
9
|
+
### SCAN_STATUS
|
|
10
|
+
|
|
11
|
+
| 值 | 说明 |
|
|
12
|
+
---|---|
|
|
13
|
+
| `pending` | scan 未开始 |
|
|
14
|
+
| `in_progress` | scan 进行中 |
|
|
15
|
+
| `success` | scan 成功,所有检查通过 |
|
|
16
|
+
| `completed_with_warnings` | scan 成功但有警告 |
|
|
17
|
+
| `failed_post_check` | scan 失败,post-check 不通过 |
|
|
18
|
+
|
|
19
|
+
### POINTER_STATUS
|
|
20
|
+
|
|
21
|
+
| 值 | 说明 |
|
|
22
|
+
---|---|
|
|
23
|
+
| `active` | 指针活跃,任务进行中 |
|
|
24
|
+
| `scan_completed` | scan 已完成 |
|
|
25
|
+
| `stale` | 指针过时(完成超过 24h,建议清理) |
|
|
26
|
+
| `corrupted` | 指针损坏(缺少必要字段) |
|
|
27
|
+
|
|
28
|
+
### CHECK_SEVERITY
|
|
29
|
+
|
|
30
|
+
| 值 | 说明 |
|
|
31
|
+
---|---|
|
|
32
|
+
| `failed` | 严重:阻止成功 |
|
|
33
|
+
| `warning` | 警告:不阻止成功 |
|
|
34
|
+
| `passed` | 通过 |
|
|
35
|
+
|
|
36
|
+
## 目录结构
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
<spec_root>/
|
|
40
|
+
├── manifest.json # 扫描元数据 + 产物索引
|
|
41
|
+
├── docs/<project>/scan/ # 项目文档
|
|
42
|
+
│ ├── ARCHITECTURE.md
|
|
43
|
+
│ ├── CONVENTIONS.md
|
|
44
|
+
│ ├── PROJECT.md
|
|
45
|
+
│ ├── STACK.md
|
|
46
|
+
│ ├── STRUCTURE.md
|
|
47
|
+
│ └── ... (7 份必需文档)
|
|
48
|
+
├── projects/*.yaml # 子项目注册
|
|
49
|
+
├── changes/<change-name>/ # 变更目录
|
|
50
|
+
└── .runtime/
|
|
51
|
+
├── postcheck-result.json # post-check 结构化结果
|
|
52
|
+
└── platform-scan.json # 平台参数持久化(主文件)
|
|
53
|
+
|
|
54
|
+
<runtime_root>/
|
|
55
|
+
└── scan-runs/<scan_run_id>/
|
|
56
|
+
└── workflow-runs/
|
|
57
|
+
└── <timestamp>-<workflow>-<project>-<status>.json # workflow 检查结果
|
|
58
|
+
|
|
59
|
+
<source_root>/
|
|
60
|
+
├── .sillyspec-platform.json # 平台参数恢复指针(轻量,不在 .sillyspec 内)
|
|
61
|
+
└── (源码,禁止 .sillyspec/ 污染)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## manifest.json
|
|
65
|
+
|
|
66
|
+
scan 完成后写入 `<spec_root>/manifest.json`,是 SillyHub 判断 scan 结果的入口文件。
|
|
67
|
+
|
|
68
|
+
### 结构
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
{
|
|
72
|
+
"workspace_id": "ws-xxx",
|
|
73
|
+
"scan_run_id": "scan-2026-06-14-test-001",
|
|
74
|
+
"source_root": "/path/to/source",
|
|
75
|
+
"spec_root": "/path/to/spec",
|
|
76
|
+
"runtime_root": "/path/to/runtime",
|
|
77
|
+
"source_commit": "abc123...",
|
|
78
|
+
"source_commit_error": null,
|
|
79
|
+
"generated_at": "2026-06-14T01:50:00.000Z",
|
|
80
|
+
"schema_version": 1,
|
|
81
|
+
"postcheck_result_path": "<spec_root>/.runtime/postcheck-result.json",
|
|
82
|
+
"workflow_runs_dir": "<runtime_root>/scan-runs/<scan_run_id>/workflow-runs",
|
|
83
|
+
"platform_pointer_path": "<source_root>/.sillyspec-platform.json",
|
|
84
|
+
"platform_pointer_status": "active",
|
|
85
|
+
"scan_post_check": {
|
|
86
|
+
"status": "success | completed_with_warnings | failed_post_check",
|
|
87
|
+
"checks": [...]
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### 字段说明
|
|
93
|
+
|
|
94
|
+
| 字段 | 类型 | 说明 |
|
|
95
|
+
|---|---|---|
|
|
96
|
+
| `workspace_id` | string \| null | SillyHub workspace 标识 |
|
|
97
|
+
| `scan_run_id` | string \| null | 本次 scan 唯一标识 |
|
|
98
|
+
| `source_root` | string | 源码目录绝对路径 |
|
|
99
|
+
| `spec_root` | string \| null | 规范目录(specDir) |
|
|
100
|
+
| `runtime_root` | string \| null | 运行时产物目录 |
|
|
101
|
+
| `source_commit` | string \| null | 源码 HEAD commit hash |
|
|
102
|
+
| `source_commit_error` | string \| undefined | commit 获取失败原因 |
|
|
103
|
+
| `generated_at` | string (ISO 8601) | manifest 生成时间 |
|
|
104
|
+
| `schema_version` | number | 产物协议版本,当前为 1 |
|
|
105
|
+
| `postcheck_result_path` | string \| null | post-check 结构化结果路径 |
|
|
106
|
+
| `workflow_runs_dir` | string \| null | workflow 检查结果目录 |
|
|
107
|
+
| `platform_pointer_path` | string | 平台指针文件路径 |
|
|
108
|
+
| `platform_pointer_status` | string | 初始 `active`,由指针文件独立更新 |
|
|
109
|
+
| `scan_post_check` | object \| undefined | post-check 结果(写入后追加) |
|
|
110
|
+
|
|
111
|
+
### 判断 scan 结果
|
|
112
|
+
|
|
113
|
+
SillyHub 消费 manifest 的方式:
|
|
114
|
+
|
|
115
|
+
1. 读取 `<spec_root>/manifest.json`
|
|
116
|
+
2. 检查 `scan_post_check.status`:
|
|
117
|
+
- `success` → scan 成功
|
|
118
|
+
- `completed_with_warnings` → scan 成功但有警告
|
|
119
|
+
- `failed_post_check` → scan 失败
|
|
120
|
+
3. 如果失败,读 `scan_post_check.checks` 获取具体失败项
|
|
121
|
+
4. 读 `postcheck_result_path` 获取完整结构化结果
|
|
122
|
+
5. 读 `workflow_runs_dir` 获取 workflow 检查证据
|
|
123
|
+
|
|
124
|
+
## .sillyspec-platform.json
|
|
125
|
+
|
|
126
|
+
跨 `--done` 生命周期的轻量指针文件,存储在 `<source_root>/.sillyspec-platform.json`(不在 `.sillyspec/` 内,不污染源码结构)。
|
|
127
|
+
|
|
128
|
+
### 生命周期
|
|
129
|
+
|
|
130
|
+
| 阶段 | 行为 |
|
|
131
|
+
|---|---|
|
|
132
|
+
| **创建** | `run scan --spec-root` 时,写入 cwd 根目录 |
|
|
133
|
+
| **读取** | 每次 `run`/`--done`/`--skip` 时,优先从 pointer 恢复平台参数 |
|
|
134
|
+
| **更新** | 每次 `run` 时刷新 `savedAt` |
|
|
135
|
+
| **完成标记** | scan post-check 后追加 `status=scan_completed` + `completedAt` + `scanStatus` |
|
|
136
|
+
| **异常检测** | pointer 存在但缺 `specRoot` 时报错退出 |
|
|
137
|
+
| **清理** | 无自动清理。`sillyspec platform pointer` 查看状态,`sillyspec platform pointer --cleanup` 手动清理 |
|
|
138
|
+
|
|
139
|
+
### CLI 检查命令
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
# 查看指针状态
|
|
143
|
+
sillyspec platform pointer
|
|
144
|
+
|
|
145
|
+
# 清理过时/损坏指针
|
|
146
|
+
sillyspec platform pointer --cleanup
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
输出示例:
|
|
150
|
+
```
|
|
151
|
+
📄 指针文件: /path/to/source/.sillyspec-platform.json
|
|
152
|
+
specRoot: /path/to/spec
|
|
153
|
+
runtimeRoot: /path/to/runtime
|
|
154
|
+
workspaceId: ws-xxx
|
|
155
|
+
scanRunId: scan-2026-06-14-test-001
|
|
156
|
+
savedAt: 2026-06-14T01:50:00.000Z
|
|
157
|
+
状态: stale ⚠️
|
|
158
|
+
completedAt: 2026-06-12T01:00:00.000Z
|
|
159
|
+
scanStatus: success
|
|
160
|
+
⚠️ 指针已过时(完成超过 24h),可以安全删除。
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
状态判定逻辑:
|
|
164
|
+
- 缺少 `specRoot` → `corrupted`
|
|
165
|
+
- `status=scan_completed` 且 `completedAt` 超过 24h → `stale`
|
|
166
|
+
- `status=scan_completed` 且未超时 → `scan_completed` ✅
|
|
167
|
+
- 无 `status` 字段 → `active` 🔄
|
|
168
|
+
|
|
169
|
+
### 结构
|
|
170
|
+
|
|
171
|
+
```json
|
|
172
|
+
{
|
|
173
|
+
"specRoot": "/path/to/spec",
|
|
174
|
+
"runtimeRoot": "/path/to/runtime",
|
|
175
|
+
"workspaceId": "ws-xxx",
|
|
176
|
+
"scanRunId": "scan-2026-06-14-test-001",
|
|
177
|
+
"savedAt": "2026-06-14T01:50:00.000Z"
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
scan 完成后追加:
|
|
182
|
+
|
|
183
|
+
```json
|
|
184
|
+
{
|
|
185
|
+
"status": "scan_completed",
|
|
186
|
+
"completedAt": "2026-06-14T01:52:00.000Z",
|
|
187
|
+
"scanStatus": "success"
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## postcheck-result.json
|
|
192
|
+
|
|
193
|
+
写入 `<spec_root>/.runtime/postcheck-result.json`(平台模式)或 `<cwd>/.sillyspec/.runtime/postcheck-result.json`(本地模式)。
|
|
194
|
+
|
|
195
|
+
### 结构
|
|
196
|
+
|
|
197
|
+
```json
|
|
198
|
+
{
|
|
199
|
+
"workspace_id": "ws-xxx",
|
|
200
|
+
"scan_run_id": "scan-2026-06-14-test-001",
|
|
201
|
+
"status": "success | completed_with_warnings | failed_post_check",
|
|
202
|
+
"source_root": "/path/to/source",
|
|
203
|
+
"spec_root": "/path/to/spec",
|
|
204
|
+
"runtime_root": "/path/to/runtime",
|
|
205
|
+
"checks": [
|
|
206
|
+
{
|
|
207
|
+
"name": "source_root_docs_leak",
|
|
208
|
+
"severity": "failed | warning",
|
|
209
|
+
"detail": "..."
|
|
210
|
+
}
|
|
211
|
+
],
|
|
212
|
+
"source_root_leak": true,
|
|
213
|
+
"docs_missing": ["ARCHITECTURE.md"],
|
|
214
|
+
"profile": {
|
|
215
|
+
"mode": "quick | standard | deep",
|
|
216
|
+
"file_count": 10,
|
|
217
|
+
"source_bytes": 102400,
|
|
218
|
+
"project_count": 1,
|
|
219
|
+
"reason": "..."
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### check 类型
|
|
225
|
+
|
|
226
|
+
| check name | severity | 说明 |
|
|
227
|
+
|---|---|---|
|
|
228
|
+
| `source_root_docs_leak` | failed | docs 文档泄漏到 source_root |
|
|
229
|
+
| `source_root_leak` | failed | projects/workflows/knowledge/manifest/local 泄漏到 source_root |
|
|
230
|
+
| `all_docs_missing` | failed | 7 份必需文档全部缺失 |
|
|
231
|
+
| `partial_docs_missing` | failed | 部分文档缺失 |
|
|
232
|
+
| `docs_missing_header` | warning | 文档缺少 frontmatter |
|
|
233
|
+
| `local_config_invalid` | warning | local.yaml 中命令不存在 |
|
|
234
|
+
| `tool_use_error` | warning | AI 执行工具调用错误 |
|
|
235
|
+
| `api_error` | warning | API 错误(529/429/超时) |
|
|
236
|
+
|
|
237
|
+
## workflow-runs
|
|
238
|
+
|
|
239
|
+
写入 `<runtime_root>/scan-runs/<scan_run_id>/workflow-runs/`(平台模式)或 `<cwd>/.sillyspec/.runtime/workflow-runs/`(本地模式)。
|
|
240
|
+
|
|
241
|
+
每个文件命名:`<timestamp>-<workflow>-<project>-<status>.json`
|
|
242
|
+
|
|
243
|
+
### 结构
|
|
244
|
+
|
|
245
|
+
```json
|
|
246
|
+
{
|
|
247
|
+
"run_id": "20260614015000-scan-docs-test-project-pass",
|
|
248
|
+
"created_at": "2026-06-14T01:50:00.000Z",
|
|
249
|
+
"source": "run.js",
|
|
250
|
+
"stage": "scan",
|
|
251
|
+
"step": "深度扫描",
|
|
252
|
+
"workflow": "scan-docs",
|
|
253
|
+
"project": "test-project",
|
|
254
|
+
"status": "pass | fail",
|
|
255
|
+
"spec_version": 1,
|
|
256
|
+
"roles": [...],
|
|
257
|
+
"workflow_checks": [...],
|
|
258
|
+
"failures": [...],
|
|
259
|
+
"retry_prompts": [...]
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## source_root 零污染
|
|
264
|
+
|
|
265
|
+
平台模式的核心约束:source_root 下不产生 `.sillyspec/` 目录。
|
|
266
|
+
|
|
267
|
+
post-check 会检查以下路径是否存在泄漏:
|
|
268
|
+
- `<source_root>/.sillyspec/docs/` — 文档泄漏
|
|
269
|
+
- `<source_root>/.sillyspec/projects/` — 项目注册泄漏
|
|
270
|
+
- `<source_root>/.sillyspec/workflows/` — 工作流泄漏
|
|
271
|
+
- `<source_root>/.sillyspec/knowledge/` — 术语泄漏
|
|
272
|
+
- `<source_root>/.sillyspec/manifest.json` — manifest 泄漏
|
|
273
|
+
- `<source_root>/.sillyspec/local.yaml` — 配置泄漏
|
|
274
|
+
|
|
275
|
+
## 产物消费优先级
|
|
276
|
+
|
|
277
|
+
SillyHub 判断 scan 结果的推荐顺序:
|
|
278
|
+
|
|
279
|
+
1. `manifest.json` → `scan_post_check.overall_status` → 快速判断成功/失败
|
|
280
|
+
2. `postcheck-result.json` → 完整检查明细 + failure_categories
|
|
281
|
+
3. `workflow-runs/*.json` → workflow 检查证据
|
|
282
|
+
4. `docs/<project>/scan/*.md` → 实际文档内容
|
|
283
|
+
|
|
284
|
+
### failure_categories
|
|
285
|
+
|
|
286
|
+
`postcheck-result.json` 中的 `failure_categories` 提供分类视图:
|
|
287
|
+
|
|
288
|
+
| 类别 | 包含的 check |
|
|
289
|
+
---|---|
|
|
290
|
+
| `path_pollution` | source_root_leak, source_root_docs_leak |
|
|
291
|
+
| `missing_outputs` | all_docs_missing, partial_docs_missing, missing_docs |
|
|
292
|
+
| `bad_references` | local_config_invalid |
|
|
293
|
+
| `quality_warnings` | tool_use_error, api_error_529, rate_limit_exhausted, fallback_or_skip |
|
|
294
|
+
| `violations` | manifest_write_failed, project_list_parse_failed + 所有 path_pollution |
|
|
295
|
+
|
|
296
|
+
SillyHub 可以按类别快速定位问题域,而不需要遍历所有 checks。
|
|
297
|
+
|
|
298
|
+
不需要解析 stdout。
|
package/package.json
CHANGED
package/src/constants.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SillySpec 平台状态枚举
|
|
3
|
+
*
|
|
4
|
+
* 所有平台产物(manifest、pointer、postcheck、workflow-runs)共享这些枚举。
|
|
5
|
+
* SillyHub 侧直接使用常量值,不需要猜字符串。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// ── scan 阶段状态 ──
|
|
9
|
+
export const SCAN_STATUS = Object.freeze({
|
|
10
|
+
PENDING: 'pending', // scan 未开始
|
|
11
|
+
IN_PROGRESS: 'in_progress', // scan 进行中
|
|
12
|
+
SUCCESS: 'success', // scan 成功(所有检查通过)
|
|
13
|
+
COMPLETED_WITH_WARNINGS: 'completed_with_warnings', // scan 成功但有警告
|
|
14
|
+
FAILED_POST_CHECK: 'failed_post_check', // scan 失败(post-check 不通过)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
// ── 平台指针状态 ──
|
|
18
|
+
export const POINTER_STATUS = Object.freeze({
|
|
19
|
+
ACTIVE: 'active', // 指针活跃,任务进行中
|
|
20
|
+
SCAN_COMPLETED: 'scan_completed', // scan 已完成
|
|
21
|
+
STALE: 'stale', // 指针过时(完成超过 24h,建议清理)
|
|
22
|
+
CORRUPTED: 'corrupted', // 指针损坏(缺少必要字段)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
// ── workflow 检查状态 ──
|
|
26
|
+
export const WORKFLOW_STATUS = Object.freeze({
|
|
27
|
+
PASS: 'pass',
|
|
28
|
+
FAIL: 'fail',
|
|
29
|
+
SKIPPED: 'skipped',
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
// ── postcheck 检查严重级别 ──
|
|
33
|
+
export const CHECK_SEVERITY = Object.freeze({
|
|
34
|
+
FAILED: 'failed',
|
|
35
|
+
WARNING: 'warning',
|
|
36
|
+
PASSED: 'passed',
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
// ── stage 步骤状态 ──
|
|
40
|
+
export const STEP_STATUS = Object.freeze({
|
|
41
|
+
PENDING: 'pending',
|
|
42
|
+
IN_PROGRESS: 'in-progress',
|
|
43
|
+
COMPLETED: 'completed',
|
|
44
|
+
SKIPPED: 'skipped',
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
// ── stage 阶段状态 ──
|
|
48
|
+
export const STAGE_STATUS = Object.freeze({
|
|
49
|
+
PENDING: 'pending',
|
|
50
|
+
IN_PROGRESS: 'in_progress',
|
|
51
|
+
COMPLETED: 'completed',
|
|
52
|
+
FAILED_POST_CHECK: 'failed_post_check',
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 判断指针是否过时(完成超过 24h)
|
|
57
|
+
*/
|
|
58
|
+
export function isPointerStale(pointer) {
|
|
59
|
+
if (!pointer.completedAt) return false
|
|
60
|
+
const completed = new Date(pointer.completedAt)
|
|
61
|
+
const age = Date.now() - completed.getTime()
|
|
62
|
+
return age > 24 * 60 * 60 * 1000
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 判断指针是否损坏(缺少必要字段)
|
|
67
|
+
*/
|
|
68
|
+
export function isPointerCorrupted(pointer) {
|
|
69
|
+
return !pointer || !pointer.specRoot || !pointer.savedAt
|
|
70
|
+
}
|
package/src/db.js
CHANGED
|
@@ -175,6 +175,10 @@ export class DB {
|
|
|
175
175
|
this._migrateAddColumn('steps', 'wait_options', 'TEXT');
|
|
176
176
|
this._migrateAddColumn('steps', 'wait_answer', 'TEXT');
|
|
177
177
|
this._migrateAddColumn('steps', 'waited_at', 'TEXT');
|
|
178
|
+
// repeatableWait support
|
|
179
|
+
this._migrateAddColumn('steps', 'wait_answers', 'TEXT'); // JSON array
|
|
180
|
+
this._migrateAddColumn('steps', 'wait_round', 'INTEGER');
|
|
181
|
+
this._migrateAddColumn('steps', 'max_wait_rounds', 'INTEGER');
|
|
178
182
|
}
|
|
179
183
|
|
|
180
184
|
/**
|
|
@@ -126,6 +126,96 @@ function isPathInside(child, parent) {
|
|
|
126
126
|
return absChild === absParent || absChild.startsWith(absParent + path.sep)
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
+
function toPosixPath(filePath) {
|
|
130
|
+
return filePath.replace(/\\/g, '/')
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function parseFrontmatter(content) {
|
|
134
|
+
if (!content.startsWith('---\n') && !content.startsWith('---\r\n')) return {}
|
|
135
|
+
const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n/)
|
|
136
|
+
if (!match) return {}
|
|
137
|
+
const result = {}
|
|
138
|
+
for (const line of match[1].split(/\r?\n/)) {
|
|
139
|
+
const m = line.match(/^([A-Za-z0-9_-]+):\s*(.*)$/)
|
|
140
|
+
if (!m) continue
|
|
141
|
+
result[m[1]] = m[2].replace(/^['"]|['"]$/g, '').trim()
|
|
142
|
+
}
|
|
143
|
+
return result
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function parseTimestamp(value) {
|
|
147
|
+
if (!value) return null
|
|
148
|
+
const time = Date.parse(value)
|
|
149
|
+
return Number.isNaN(time) ? null : time
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function getScanDocInfo(filePath) {
|
|
153
|
+
const normalized = toPosixPath(path.resolve(filePath))
|
|
154
|
+
const match = normalized.match(/^(.*)\/docs\/([^/]+)\/scan\/([^/]+\.md)$/)
|
|
155
|
+
if (!match) return null
|
|
156
|
+
return {
|
|
157
|
+
specRoot: path.resolve(match[1]),
|
|
158
|
+
projectName: match[2],
|
|
159
|
+
docName: match[3],
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function readScanGuard(scanDocInfo, projectRoot) {
|
|
164
|
+
const candidates = [
|
|
165
|
+
path.join(scanDocInfo.specRoot, '.runtime', 'scan-guard.json'),
|
|
166
|
+
path.join(projectRoot, '.sillyspec', '.runtime', 'scan-guard.json'),
|
|
167
|
+
]
|
|
168
|
+
for (const p of candidates) {
|
|
169
|
+
if (!existsSync(p)) continue
|
|
170
|
+
try {
|
|
171
|
+
return JSON.parse(readFileSync(p, 'utf8'))
|
|
172
|
+
} catch {
|
|
173
|
+
return null
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return null
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function shouldBlockScanDocOverwrite(filePath, projectRoot) {
|
|
180
|
+
const scanDocInfo = getScanDocInfo(filePath)
|
|
181
|
+
if (!scanDocInfo || !existsSync(filePath)) return { blocked: false }
|
|
182
|
+
|
|
183
|
+
const guard = readScanGuard(scanDocInfo, projectRoot)
|
|
184
|
+
if (!guard || guard.forceRescan) return { blocked: false }
|
|
185
|
+
|
|
186
|
+
let frontmatter = {}
|
|
187
|
+
try {
|
|
188
|
+
frontmatter = parseFrontmatter(readFileSync(filePath, 'utf8'))
|
|
189
|
+
} catch {
|
|
190
|
+
return { blocked: false }
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const relPath = toPosixPath(path.relative(projectRoot, filePath))
|
|
194
|
+
if (frontmatter.source_commit && guard.sourceCommit && frontmatter.source_commit !== guard.sourceCommit) {
|
|
195
|
+
return {
|
|
196
|
+
blocked: true,
|
|
197
|
+
reason: [
|
|
198
|
+
`scan 覆盖保护:${relPath} 的 source_commit=${frontmatter.source_commit} 与当前 scan source_commit=${guard.sourceCommit} 不一致。`,
|
|
199
|
+
'如确认要重新生成,请重新运行 scan 并添加 --force-rescan。',
|
|
200
|
+
].join('\n')
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const existingUpdatedAt = parseTimestamp(frontmatter.updated_at)
|
|
205
|
+
const scanStartedAt = parseTimestamp(guard.startedAt)
|
|
206
|
+
if (existingUpdatedAt && scanStartedAt && existingUpdatedAt > scanStartedAt) {
|
|
207
|
+
return {
|
|
208
|
+
blocked: true,
|
|
209
|
+
reason: [
|
|
210
|
+
`scan 覆盖保护:${relPath} 的 updated_at 晚于本次 scan 开始时间,可能包含手工编辑。`,
|
|
211
|
+
'如确认要覆盖,请重新运行 scan 并添加 --force-rescan。',
|
|
212
|
+
].join('\n')
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return { blocked: false }
|
|
217
|
+
}
|
|
218
|
+
|
|
129
219
|
function isInsideWorktreeStorage(filePath, cwd) {
|
|
130
220
|
const absPath = path.isAbsolute(filePath) ? filePath : path.resolve(cwd || process.cwd(), filePath)
|
|
131
221
|
return isPathInside(absPath, resolveWorktreeDir(cwd || process.cwd()))
|
|
@@ -489,12 +579,15 @@ export function shouldBlockWrite(filePath, cwd) {
|
|
|
489
579
|
const projectRoot = findProjectRoot(callerCwd)
|
|
490
580
|
const absPath = path.isAbsolute(filePath) ? filePath : path.resolve(callerCwd, filePath)
|
|
491
581
|
|
|
492
|
-
// 1.
|
|
493
|
-
if (!isInsideWorktreeStorage(absPath, projectRoot) && matchFileWhitelist(absPath)) return { blocked: false }
|
|
494
|
-
|
|
495
|
-
// 2. 阶段门禁(使用 fallback 读取)
|
|
582
|
+
// 1. 阶段门禁(使用 fallback 读取)
|
|
496
583
|
const stage = readCurrentStage(projectRoot) || '(none)'
|
|
497
584
|
|
|
585
|
+
const scanGuardResult = shouldBlockScanDocOverwrite(absPath, projectRoot)
|
|
586
|
+
if (scanGuardResult.blocked) return scanGuardResult
|
|
587
|
+
|
|
588
|
+
// 2. 文件门禁:文档类/配置类始终放行,但 worktree 存储区内的源码必须继续走登记校验。
|
|
589
|
+
if (!isInsideWorktreeStorage(absPath, projectRoot) && matchFileWhitelist(absPath)) return { blocked: false }
|
|
590
|
+
|
|
498
591
|
if (!['execute', 'quick'].includes(stage)) {
|
|
499
592
|
return {
|
|
500
593
|
blocked: true,
|
package/src/index.js
CHANGED
|
@@ -40,7 +40,7 @@ SillySpec CLI — 规范驱动开发工具包
|
|
|
40
40
|
auto 连续推进 brainstorm→plan→execute→verify
|
|
41
41
|
|
|
42
42
|
可选阶段:
|
|
43
|
-
scan, brainstorm,
|
|
43
|
+
scan, brainstorm, plan, execute, verify, archive
|
|
44
44
|
quick, explore, status, doctor
|
|
45
45
|
|
|
46
46
|
sillyspec progress <cmd> 进度记录(轻量,不强制顺序)
|
|
@@ -451,6 +451,7 @@ SillySpec platform — SillyHub 平台同步
|
|
|
451
451
|
sillyspec platform sync [--change <name>]
|
|
452
452
|
sillyspec platform sync-docs [--change <name>]
|
|
453
453
|
sillyspec platform status
|
|
454
|
+
sillyspec platform pointer [--cleanup]
|
|
454
455
|
sillyspec platform approve <change-name>
|
|
455
456
|
sillyspec platform reject <change-name> [--reason <reason>]
|
|
456
457
|
`);
|
|
@@ -466,6 +467,60 @@ SillySpec platform — SillyHub 平台同步
|
|
|
466
467
|
}
|
|
467
468
|
|
|
468
469
|
switch (platformSub) {
|
|
470
|
+
case 'pointer': {
|
|
471
|
+
// 指针状态检查(不依赖 sync 模块)
|
|
472
|
+
const { readFileSync, existsSync } = await import('fs')
|
|
473
|
+
const { join } = await import('path')
|
|
474
|
+
const { POINTER_STATUS, isPointerStale, isPointerCorrupted } = await import('./constants.js')
|
|
475
|
+
const pointerPath = join(dir, '.sillyspec-platform.json')
|
|
476
|
+
|
|
477
|
+
if (!existsSync(pointerPath)) {
|
|
478
|
+
console.log('ℹ️ 无平台指针文件。当前不在平台模式或未进行过平台 scan。')
|
|
479
|
+
break
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
try {
|
|
483
|
+
const pointer = JSON.parse(readFileSync(pointerPath, 'utf8'))
|
|
484
|
+
console.log(`📄 指针文件: ${pointerPath}`)
|
|
485
|
+
console.log(` specRoot: ${pointer.specRoot || '(缺失 ❌)'}`)
|
|
486
|
+
console.log(` runtimeRoot: ${pointer.runtimeRoot || '(未设置)'}`)
|
|
487
|
+
console.log(` workspaceId: ${pointer.workspaceId || '(未设置)'}`)
|
|
488
|
+
console.log(` scanRunId: ${pointer.scanRunId || '(未设置)'}`)
|
|
489
|
+
console.log(` savedAt: ${pointer.savedAt || '(未知)'}`)
|
|
490
|
+
|
|
491
|
+
if (isPointerCorrupted(pointer)) {
|
|
492
|
+
console.log(` 状态: ${POINTER_STATUS.CORRUPTED} ❌`)
|
|
493
|
+
console.log(` ⚠️ 指针损坏(缺少 specRoot),建议删除后重新运行平台 scan。`)
|
|
494
|
+
if (platformArgs.includes('--cleanup')) {
|
|
495
|
+
const { unlinkSync } = await import('fs')
|
|
496
|
+
unlinkSync(pointerPath)
|
|
497
|
+
console.log(` 🗑️ 已清理损坏指针。`)
|
|
498
|
+
}
|
|
499
|
+
} else if (pointer.status === POINTER_STATUS.SCAN_COMPLETED) {
|
|
500
|
+
if (isPointerStale(pointer)) {
|
|
501
|
+
console.log(` 状态: ${POINTER_STATUS.STALE} ⚠️`)
|
|
502
|
+
console.log(` completedAt: ${pointer.completedAt}`)
|
|
503
|
+
console.log(` scanStatus: ${pointer.scanStatus || '(未知)'}`)
|
|
504
|
+
console.log(` ⚠️ 指针已过时(完成超过 24h),可以安全删除。`)
|
|
505
|
+
if (platformArgs.includes('--cleanup')) {
|
|
506
|
+
const { unlinkSync } = await import('fs')
|
|
507
|
+
unlinkSync(pointerPath)
|
|
508
|
+
console.log(` 🗑️ 已清理过时指针。`)
|
|
509
|
+
}
|
|
510
|
+
} else {
|
|
511
|
+
console.log(` 状态: ${pointer.status} ✅`)
|
|
512
|
+
console.log(` completedAt: ${pointer.completedAt}`)
|
|
513
|
+
console.log(` scanStatus: ${pointer.scanStatus || '(未知)'}`)
|
|
514
|
+
}
|
|
515
|
+
} else {
|
|
516
|
+
console.log(` 状态: ${POINTER_STATUS.ACTIVE} 🔄`)
|
|
517
|
+
}
|
|
518
|
+
} catch (e) {
|
|
519
|
+
console.log(` 状态: ${POINTER_STATUS.CORRUPTED} ❌`)
|
|
520
|
+
console.log(` ⚠️ 指针文件损坏: ${e.message}`)
|
|
521
|
+
}
|
|
522
|
+
break;
|
|
523
|
+
}
|
|
469
524
|
case 'connect': {
|
|
470
525
|
const url = platformArgs[0];
|
|
471
526
|
if (!url) {
|