sillyspec 3.20.2 → 3.20.3

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 (208) hide show
  1. package/.claude/skills/sillyspec-archive/SKILL.md +1 -5
  2. package/.claude/skills/sillyspec-auto/SKILL.md +2 -8
  3. package/.claude/skills/sillyspec-brainstorm/SKILL.md +1 -28
  4. package/.claude/skills/sillyspec-commit/SKILL.md +3 -4
  5. package/.claude/skills/sillyspec-continue/SKILL.md +4 -5
  6. package/.claude/skills/sillyspec-doctor/SKILL.md +3 -12
  7. package/.claude/skills/sillyspec-execute/SKILL.md +2 -15
  8. package/.claude/skills/sillyspec-explore/SKILL.md +1 -14
  9. package/.claude/skills/sillyspec-plan/SKILL.md +36 -5
  10. package/.claude/skills/sillyspec-propose/SKILL.md +0 -4
  11. package/.claude/skills/sillyspec-quick/SKILL.md +1 -5
  12. package/.claude/skills/sillyspec-resume/SKILL.md +66 -23
  13. package/.claude/skills/sillyspec-scan/SKILL.md +1 -5
  14. package/.claude/skills/sillyspec-state/SKILL.md +8 -8
  15. package/.claude/skills/sillyspec-status/SKILL.md +1 -5
  16. package/.claude/skills/sillyspec-verify/SKILL.md +1 -5
  17. package/.claude/skills/sillyspec-workspace/SKILL.md +3 -11
  18. package/.sillyspec/changes/archive/2026-04-08-derive-state/design.md +97 -0
  19. package/.sillyspec/changes/archive/2026-04-08-derive-state/plan.md +51 -0
  20. package/.sillyspec/changes/archive/2026-04-08-derive-state/proposal.md +29 -0
  21. package/.sillyspec/changes/archive/2026-04-08-derive-state/requirements.md +34 -0
  22. package/.sillyspec/changes/archive/2026-04-08-derive-state/tasks.md +13 -0
  23. package/.sillyspec/changes/archive/2026-04-08-derive-state/verify-result.md +43 -0
  24. package/.sillyspec/changes/auto-mode/design.md +50 -0
  25. package/.sillyspec/changes/auto-mode/proposal.md +19 -0
  26. package/.sillyspec/changes/auto-mode/requirements.md +21 -0
  27. package/.sillyspec/changes/auto-mode/tasks.md +7 -0
  28. package/.sillyspec/changes/brainstorm-archive/2026-04-05-dashboard-design.md +206 -0
  29. package/.sillyspec/changes/brainstorm-archive/2026-04-05-unified-docs-design.md +199 -0
  30. package/.sillyspec/changes/dashboard/design.md +219 -0
  31. package/.sillyspec/changes/dashboard/design.md.braindraft +206 -0
  32. package/.sillyspec/changes/run-command-design/design.md +1230 -0
  33. package/.sillyspec/changes/unified-docs-design/design.md +199 -0
  34. package/.sillyspec/docs/sillyspec/scan/.gitkeep +0 -0
  35. package/.sillyspec/knowledge/INDEX.md +8 -0
  36. package/.sillyspec/knowledge/uncategorized.md +3 -0
  37. package/.sillyspec/plans/2026-04-05-dashboard.md +737 -0
  38. package/.sillyspec/projects/sillyspec.yaml +3 -0
  39. package/README.md +11 -13
  40. package/SKILL.md +40 -44
  41. package/dist/steps/brainstorm/01-load-context.md +30 -0
  42. package/dist/steps/brainstorm/02-reuse-check.md +6 -0
  43. package/dist/steps/brainstorm/03-prototype-analysis.md +11 -0
  44. package/dist/steps/brainstorm/04-module-split.md +23 -0
  45. package/dist/steps/brainstorm/05-dialog-explore.md +8 -0
  46. package/dist/steps/brainstorm/06-propose-approaches.md +3 -0
  47. package/dist/steps/brainstorm/07-present-design.md +3 -0
  48. package/dist/steps/brainstorm/08-write-design.md +21 -0
  49. package/dist/steps/brainstorm/09-self-review.md +15 -0
  50. package/dist/steps/brainstorm/10-user-confirm.md +3 -0
  51. package/dist/steps/brainstorm/11-output-spec.md +7 -0
  52. package/dist/steps/brainstorm/manifest.yaml +26 -0
  53. package/dist/steps/execute/01-load-context.md +41 -0
  54. package/dist/steps/execute/02-scan-conventions.md +47 -0
  55. package/dist/steps/execute/03-skill-mcp.md +19 -0
  56. package/dist/steps/execute/04-assign-task.md +22 -0
  57. package/dist/steps/execute/04b-prompt-template.md +54 -0
  58. package/dist/steps/execute/05-write-test.md +7 -0
  59. package/dist/steps/execute/06-write-code.md +8 -0
  60. package/dist/steps/execute/07-run-test.md +26 -0
  61. package/dist/steps/execute/08-fix-issues.md +28 -0
  62. package/dist/steps/execute/09-next-task.md +33 -0
  63. package/dist/steps/execute/manifest.yaml +28 -0
  64. package/dist/steps/plan/01-load-context.md +22 -0
  65. package/dist/steps/plan/02-anchor-confirm.md +1 -0
  66. package/dist/steps/plan/03-expand-tasks.md +33 -0
  67. package/dist/steps/plan/04-mark-order.md +15 -0
  68. package/dist/steps/plan/05-e2e-planning.md +17 -0
  69. package/dist/steps/plan/06-self-check.md +16 -0
  70. package/dist/steps/plan/07-save.md +1 -0
  71. package/dist/steps/plan/manifest.yaml +18 -0
  72. package/dist/steps/scan/01-env-detect.md +51 -0
  73. package/dist/steps/scan/02-tech-stack.md +16 -0
  74. package/dist/steps/scan/03-conventions.md +16 -0
  75. package/dist/steps/scan/04-structure.md +19 -0
  76. package/dist/steps/scan/05-quality.md +18 -0
  77. package/dist/steps/scan/06-complete.md +49 -0
  78. package/dist/steps/scan/manifest.yaml +16 -0
  79. package/dist/steps/verify/01-load-specs.md +28 -0
  80. package/dist/steps/verify/02-check-tasks.md +1 -0
  81. package/dist/steps/verify/03-check-design.md +6 -0
  82. package/dist/steps/verify/04-run-tests.md +7 -0
  83. package/dist/steps/verify/05-e2e-tests.md +27 -0
  84. package/dist/steps/verify/05b-e2e-fix.md +33 -0
  85. package/dist/steps/verify/06-code-quality.md +25 -0
  86. package/dist/steps/verify/07-lint-check.md +27 -0
  87. package/dist/steps/verify/08-output-report.md +14 -0
  88. package/dist/steps/verify/manifest.yaml +22 -0
  89. package/package.json +1 -7
  90. package/packages/dashboard/dist/assets/{index-Bq_Z2hne.js → index-D1EVTLmc.js} +1264 -1264
  91. package/packages/dashboard/dist/assets/index-DGe8CqeP.css +1 -0
  92. package/packages/dashboard/dist/index.html +2 -2
  93. package/packages/dashboard/package-lock.json +6 -6
  94. package/packages/dashboard/server/executor.js +1 -1
  95. package/packages/dashboard/server/index.js +18 -98
  96. package/packages/dashboard/server/parser.js +71 -139
  97. package/packages/dashboard/server/watcher.js +6 -14
  98. package/packages/dashboard/src/App.vue +185 -418
  99. package/packages/dashboard/src/components/ActionBar.vue +1 -10
  100. package/packages/dashboard/src/components/CommandPalette.vue +1 -5
  101. package/packages/dashboard/src/components/DocPreview.vue +8 -105
  102. package/packages/dashboard/src/components/DocTree.vue +19 -75
  103. package/packages/dashboard/src/components/PipelineStage.vue +2 -22
  104. package/packages/dashboard/src/components/PipelineView.vue +5 -32
  105. package/packages/dashboard/src/components/ProjectOverview.vue +139 -113
  106. package/packages/dashboard/src/components/StageBadge.vue +3 -17
  107. package/packages/dashboard/src/components/StepCard.vue +2 -7
  108. package/packages/dashboard/src/composables/useDashboard.js +0 -28
  109. package/src/derive.js +147 -0
  110. package/src/index.js +40 -688
  111. package/src/init.js +63 -119
  112. package/src/migrate.js +7 -7
  113. package/src/progress.js +248 -1474
  114. package/src/run.js +302 -3008
  115. package/src/setup.js +64 -2
  116. package/src/stages/archive.js +17 -123
  117. package/src/stages/brainstorm.js +48 -454
  118. package/src/stages/doctor.js +46 -99
  119. package/src/stages/execute.js +59 -420
  120. package/src/stages/index.js +18 -12
  121. package/src/stages/plan.js +189 -492
  122. package/src/stages/propose.js +11 -70
  123. package/src/stages/quick.js +13 -52
  124. package/src/stages/scan.js +68 -485
  125. package/src/stages/status.js +1 -1
  126. package/src/stages/verify.js +16 -203
  127. package/src/step.js +543 -0
  128. package/.claude/skills/sillyspec-knowledge/SKILL.md +0 -270
  129. package/.husky/pre-push +0 -13
  130. package/CLAUDE.md +0 -18
  131. package/docs/brainstorm-plan-contract.md +0 -64
  132. package/docs/plan-execute-contract.md +0 -123
  133. package/docs/platform-scan-protocol.md +0 -298
  134. package/docs/revision-mode.md +0 -115
  135. package/docs/sillyspec/file-lifecycle/known-implementation-gaps.md +0 -99
  136. package/docs/sillyspec/file-lifecycle/platform-workflows-sync.md +0 -218
  137. package/docs/sillyspec/file-lifecycle/stage-artifacts.md +0 -167
  138. package/docs/sillyspec/file-lifecycle/storage-and-state.md +0 -148
  139. package/docs/sillyspec/file-lifecycle/worktree-and-guard.md +0 -193
  140. package/docs/sillyspec/file-lifecycle.md +0 -125
  141. package/docs/workflow-contract-regression.md +0 -106
  142. package/docs/worktree-isolation.md +0 -252
  143. package/packages/dashboard/dist/assets/index-O2W5RV4z.css +0 -1
  144. package/packages/dashboard/dist/prototype-dashboard.html +0 -836
  145. package/packages/dashboard/dist/prototype-overview.html +0 -256
  146. package/packages/dashboard/public/prototype-dashboard.html +0 -836
  147. package/packages/dashboard/public/prototype-overview.html +0 -256
  148. package/packages/dashboard/src/components/HResizeHandle.vue +0 -48
  149. package/packages/dashboard/src/components/ProjectCard.vue +0 -187
  150. package/packages/dashboard/src/components/VResizeHandle.vue +0 -61
  151. package/packages/dashboard/src/composables/useLayout.js +0 -131
  152. package/src/brainstorm-postcheck.js +0 -158
  153. package/src/change-list.js +0 -52
  154. package/src/change-risk-profile.js +0 -352
  155. package/src/classify-change.js +0 -73
  156. package/src/constants.js +0 -70
  157. package/src/contract-matrix.js +0 -278
  158. package/src/db.js +0 -201
  159. package/src/endpoint-extractor.js +0 -315
  160. package/src/hooks/claude-pre-tool-use.cjs +0 -125
  161. package/src/hooks/worktree-guard.js +0 -761
  162. package/src/knowledge-match.js +0 -130
  163. package/src/modules.js +0 -482
  164. package/src/scan-postcheck.js +0 -383
  165. package/src/stage-contract.js +0 -700
  166. package/src/stages/brainstorm-auto.js +0 -229
  167. package/src/stages/explore.js +0 -34
  168. package/src/stages/knowledge.js +0 -498
  169. package/src/stages/plan-postcheck.js +0 -513
  170. package/src/sync.js +0 -497
  171. package/src/task-review.js +0 -346
  172. package/src/workflow.js +0 -785
  173. package/src/worktree-apply.js +0 -549
  174. package/src/worktree.js +0 -932
  175. package/templates/workflows/archive-impact.yaml +0 -79
  176. package/templates/workflows/scan-docs.yaml +0 -132
  177. package/test/brainstorm-plan-contract.test.mjs +0 -273
  178. package/test/check-syntax.mjs +0 -26
  179. package/test/cli-top-level-aliases.test.mjs +0 -174
  180. package/test/contract-artifacts.test.mjs +0 -323
  181. package/test/decision-supersede.test.mjs +0 -277
  182. package/test/knowledge-match.test.mjs +0 -231
  183. package/test/plan-execute-contract.test.mjs +0 -330
  184. package/test/plan-optimization.test.mjs +0 -572
  185. package/test/platform-artifacts.test.mjs +0 -190
  186. package/test/platform-failure-samples.test.mjs +0 -199
  187. package/test/platform-recovery-chain.test.mjs +0 -179
  188. package/test/platform-recovery.test.mjs +0 -167
  189. package/test/platform-scan-p0.test.mjs +0 -175
  190. package/test/revision-v1.test.mjs +0 -1145
  191. package/test/run-sanitize-project-name.test.mjs +0 -51
  192. package/test/run-scan-postcheck-fail.test.mjs +0 -64
  193. package/test/run-scan-project-parse.test.mjs +0 -200
  194. package/test/run-tests.mjs +0 -48
  195. package/test/scan-docs-yaml-placeholders.test.mjs +0 -84
  196. package/test/scan-knowledge.test.mjs +0 -175
  197. package/test/scan-paths.test.mjs +0 -68
  198. package/test/scan-postcheck-project-priority.test.mjs +0 -85
  199. package/test/scan-postcheck.test.mjs +0 -197
  200. package/test/scan-workflow-anyfailed-block.test.mjs +0 -52
  201. package/test/spec-dir.test.mjs +0 -206
  202. package/test/stage-contract-failed-post-check.test.mjs +0 -102
  203. package/test/stage-contract.test.mjs +0 -299
  204. package/test/stage-definitions.test.mjs +0 -39
  205. package/test/wait-gates.test.mjs +0 -501
  206. package/test/workflow-spec-base.test.mjs +0 -142
  207. package/test/worktree-guard.test.mjs +0 -136
  208. package/test/worktree-native-overlay.test.mjs +0 -188
@@ -1,383 +0,0 @@
1
- /**
2
- * scan-postcheck.js — CLI 层 scan 完成后强制校验
3
- *
4
- * 不依赖 AI agent 的自检报告,由 CLI 代码直接检查文件系统。
5
- * 平台模式下必须通过所有 check 才能 success,否则降级。
6
- */
7
-
8
- import { existsSync, readdirSync, readFileSync, mkdirSync, writeFileSync } from 'fs'
9
- import { join, basename } from 'path'
10
- import { SCAN_STATUS, CHECK_SEVERITY } from './constants.js'
11
-
12
- const REQUIRED_SCAN_DOCS = [
13
- 'ARCHITECTURE.md',
14
- 'CONVENTIONS.md',
15
- 'STRUCTURE.md',
16
- 'INTEGRATIONS.md',
17
- 'TESTING.md',
18
- 'CONCERNS.md',
19
- 'PROJECT.md',
20
- ]
21
-
22
- /**
23
- * @param {object} opts
24
- * @param {string} opts.cwd - 源码项目根目录 (source_root)
25
- * @param {string} opts.specDir - 规范目录 (spec-root),null 时为非平台模式
26
- * @param {string} [opts.outputText] - 最后一步(自检)的 AI 输出文本
27
- * @param {object} [opts.scanMeta] - scan 元数据(由 runCommand 传入)
28
- * @param {boolean} [opts.scanMeta.projectListParsed] - Step 2 项目列表是否成功解析
29
- * @param {boolean} [opts.scanMeta.manifestWritten] - manifest.json 是否写入成功
30
- * @param {number} [opts.scanMeta.projectCount] - 实际展开的项目数量
31
- * @returns {{ status: 'success'|'completed_with_warnings'|'failed_post_check', checks: Array<{name, severity, detail}> }}
32
- */
33
- export function runScanPostCheck({ cwd, specDir, outputText = '', scanMeta = {} } ) {
34
- const isPlatform = !!specDir
35
- const checks = []
36
-
37
- if (!isPlatform) {
38
- // 非平台模式:只做轻量检查
39
- const localSpec = join(cwd, '.sillyspec')
40
- const scanDir = join(localSpec, 'docs', basename(cwd), 'scan')
41
-
42
- // 检查 7 份文档是否存在
43
- const missing = REQUIRED_SCAN_DOCS.filter(f => !existsSync(join(scanDir, f)))
44
- if (missing.length > 0) {
45
- checks.push({ name: 'missing_docs', severity: CHECK_SEVERITY.WARNING, detail: `缺少 ${missing.length} 份 scan 文档: ${missing.join(', ')}` })
46
- }
47
-
48
- const hasWarning = checks.some(c => c.severity === 'warning')
49
- return { status: hasWarning ? 'completed_with_warnings' : 'success', checks }
50
- }
51
-
52
- // ── 平台模式:严格检查 ──
53
-
54
- const projectName = basename(cwd)
55
-
56
- // 1. source_root 污染检查(docs/projects/workflows/knowledge/manifest/local)
57
- const pollutePaths = ['docs', 'projects', 'workflows', 'knowledge']
58
- const polluteFiles = ['manifest.json', 'local.yaml']
59
- for (const sub of pollutePaths) {
60
- const localSub = join(cwd, '.sillyspec', sub)
61
- if (existsSync(localSub)) {
62
- try {
63
- const leaked = readdirSync(localSub, { recursive: true }).filter(e => String(e).endsWith('.md') || String(e).endsWith('.yaml') || String(e).endsWith('.json'))
64
- if (leaked.length > 0) {
65
- checks.push({
66
- name: sub === 'docs' ? 'source_root_docs_leak' : 'source_root_leak',
67
- severity: CHECK_SEVERITY.FAILED,
68
- detail: `source_root/.sillyspec/${sub}/ 下存在 ${leaked.length} 个文件(${localSub}/),agent 写入到了错误路径`
69
- })
70
- }
71
- } catch {}
72
- }
73
- }
74
- for (const file of polluteFiles) {
75
- const filePath = join(cwd, '.sillyspec', file)
76
- if (existsSync(filePath)) {
77
- checks.push({
78
- name: 'source_root_leak',
79
- severity: CHECK_SEVERITY.FAILED,
80
- detail: `source_root/.sillyspec/${file} 存在,agent 写入到了错误路径(${filePath})`
81
- })
82
- }
83
- }
84
-
85
- // 2. spec_root 检查 7 份必需文档
86
- const specScanDir = join(specDir, 'docs', projectName, 'scan')
87
- const missingDocs = REQUIRED_SCAN_DOCS.filter(f => !existsSync(join(specScanDir, f)))
88
- if (missingDocs.length > 0) {
89
- checks.push({
90
- name: missingDocs.length === REQUIRED_SCAN_DOCS.length ? 'all_docs_missing' : 'partial_docs_missing',
91
- severity: CHECK_SEVERITY.FAILED,
92
- detail: missingDocs.length === REQUIRED_SCAN_DOCS.length
93
- ? `spec_root 下无任何 scan 文档(${specScanDir}/),扫描可能未执行`
94
- : `spec_root 缺少必需文档: ${missingDocs.join(', ')}(7 份 scan 文档均为 required)`
95
- })
96
- }
97
-
98
- // 3. 检查文档 header(author / created_at)— 只看文件头部,避免正文出现同名词被误判
99
- const existingDocs = REQUIRED_SCAN_DOCS.filter(f => existsSync(join(specScanDir, f)))
100
- const docsMissingHeader = []
101
- for (const doc of existingDocs) {
102
- const content = readFileSync(join(specScanDir, doc), 'utf8')
103
- const headerSlice = content.slice(0, 512)
104
- if (!/author\s*:/.test(headerSlice) || !/created_at\s*:/.test(headerSlice)) {
105
- docsMissingHeader.push(doc)
106
- }
107
- }
108
- if (docsMissingHeader.length > 0) {
109
- checks.push({
110
- name: 'docs_missing_header',
111
- severity: CHECK_SEVERITY.WARNING,
112
- detail: `${docsMissingHeader.length} 份文档缺少 author/created_at: ${docsMissingHeader.join(', ')}`
113
- })
114
- }
115
-
116
- // 4. local.yaml 校验
117
- const localYamlPath = join(specDir, 'local.yaml')
118
- if (existsSync(localYamlPath)) {
119
- const yamlContent = readFileSync(localYamlPath, 'utf8')
120
- const packageJsonPath = join(cwd, 'package.json')
121
- const invalidCommands = []
122
-
123
- // 简单提取 local.yaml 中的 commands
124
- const commandMatch = yamlContent.match(/build:\s*"([^"]+)"/) ||
125
- yamlContent.match(/test:\s*"([^"]+)"/) ||
126
- yamlContent.match(/lint:\s*"([^"]+)"/)
127
-
128
- if (commandMatch) {
129
- // 提取所有 npm run <script> 形式的命令
130
- const npmRunCommands = yamlContent.match(/npm run (\S+)/g) || []
131
- if (npmRunCommands.length > 0 && existsSync(packageJsonPath)) {
132
- try {
133
- const pkg = JSON.parse(readFileSync(packageJsonPath, 'utf8'))
134
- const scripts = pkg.scripts || {}
135
- for (const cmd of npmRunCommands) {
136
- const scriptName = cmd.replace('npm run ', '')
137
- if (!scripts[scriptName]) {
138
- invalidCommands.push(`${cmd} (package.json 无 ${scriptName} script)`)
139
- }
140
- }
141
- } catch {}
142
- }
143
- }
144
-
145
- if (invalidCommands.length > 0) {
146
- checks.push({
147
- name: 'local_config_invalid',
148
- severity: CHECK_SEVERITY.WARNING,
149
- detail: `local.yaml 引用不存在的命令: ${invalidCommands.join('; ')}`
150
- })
151
- }
152
- }
153
-
154
- // 5. 检查 AI 输出中的真实错误标记
155
- // 注意:不对 agent 描述性文本做全文正则匹配,防止误报。
156
- // 只检测明显是 agent 运行时失败的信号(未被捕获的错误块),
157
- // 而非 agent 正常描述中提到这些词。
158
- if (outputText) {
159
- // 5a: 检测未被恢复的 API 错误(连续多次、非描述性提及)
160
- const apiErrorCount = (outputText.match(/API Error\b.*?\b529\b/gi) || []).length
161
- if (apiErrorCount >= 2) {
162
- checks.push({ name: 'api_error_529', severity: CHECK_SEVERITY.WARNING, detail: 'AI 输出中包含多次 API Error 529' })
163
- }
164
- const rateLimitCount = (outputText.match(/rate.?limit.*?exhausted/gi) || []).length
165
- if (rateLimitCount >= 2) {
166
- checks.push({ name: 'rate_limit_exhausted', severity: CHECK_SEVERITY.WARNING, detail: 'AI 输出中包含多次 rate_limit exhausted' })
167
- }
168
- // tool_use_error 和 fallback 已移除:agent 描述性文本中正常提及这些词
169
- // 不应触发 warning。真正的问题会通过文档缺失、manifest 失败等其他检查捕获。
170
- }
171
-
172
- // 6. manifest 写入状态检查
173
- if (scanMeta.manifestWritten === false) {
174
- checks.push({
175
- name: 'manifest_write_failed',
176
- severity: CHECK_SEVERITY.FAILED,
177
- detail: 'manifest.json 写入失败,平台无法消费 scan 结果'
178
- })
179
- }
180
-
181
- // 7. 项目列表解析状态检查
182
- if (scanMeta.projectListParsed === false) {
183
- checks.push({
184
- name: 'project_list_parse_failed',
185
- severity: CHECK_SEVERITY.WARNING,
186
- detail: 'Step 2 项目列表解析失败,回退到注册项目列表,可能遗漏子项目'
187
- })
188
- }
189
-
190
- // 7.5 knowledge 产物校验
191
- const knowledgeDir = join(specDir, 'knowledge')
192
- if (existsSync(knowledgeDir)) {
193
- const indexPath = join(knowledgeDir, 'INDEX.md')
194
- if (!existsSync(indexPath)) {
195
- checks.push({
196
- name: 'knowledge_index_missing',
197
- severity: CHECK_SEVERITY.WARNING,
198
- detail: `knowledge/INDEX.md 不存在`
199
- })
200
- } else {
201
- // 检查 INDEX.md 引用的文件是否真实存在
202
- const indexContent = readFileSync(indexPath, 'utf8')
203
- const referencedFiles = [...indexContent.matchAll(/\(([^)]+\.md)/g)].map(m => m[1])
204
- const missingRefs = referencedFiles.filter(f => !existsSync(join(knowledgeDir, f)))
205
- if (missingRefs.length > 0) {
206
- checks.push({
207
- name: 'knowledge_broken_refs',
208
- severity: CHECK_SEVERITY.WARNING,
209
- detail: `INDEX.md 引用了不存在的文件: ${missingRefs.join(', ')}`
210
- })
211
- }
212
- }
213
- } else {
214
- checks.push({
215
- name: 'knowledge_dir_missing',
216
- severity: CHECK_SEVERITY.WARNING,
217
- detail: `knowledge/ 目录不存在`
218
- })
219
- }
220
-
221
- // 8. 计算 finalStatus
222
- const hasFailed = checks.some(c => c.severity === CHECK_SEVERITY.FAILED)
223
- const hasWarning = checks.some(c => c.severity === CHECK_SEVERITY.WARNING)
224
-
225
- let status
226
- if (hasFailed) {
227
- status = SCAN_STATUS.FAILED_POST_CHECK
228
- } else if (hasWarning) {
229
- status = SCAN_STATUS.COMPLETED_WITH_WARNINGS
230
- } else {
231
- status = SCAN_STATUS.SUCCESS
232
- }
233
-
234
- return { status, checks }
235
- }
236
-
237
- /**
238
- * 将 postcheck 结果转换为结构化 JSON(SillyHub 可消费格式)
239
- *
240
- * failure_category 标准化:
241
- * - warning : 非致命问题,不阻塞流程
242
- * - error : 文档缺失/内容不完整,需要修复
243
- * - critical : 安全问题(source_root 泄漏/路径污染)
244
- *
245
- * 结构化字段:
246
- * - violations : 明确违反约束的条目(source_root 泄漏等)
247
- * - missing_outputs : 预期文件不存在
248
- * - path_pollution : 产物写入了错误路径
249
- * - bad_references : 引用了不存在的命令/资源
250
- * - quality_warnings: AI 输出中包含错误标记等质量信号
251
- *
252
- * @param {object} result - runScanPostCheck 返回值
253
- * @param {object} [meta] - 附带元数据(workspace_id, scan_run_id, timestamp 等)
254
- * @returns {object} 结构化 JSON
255
- */
256
- export function formatStructuredResult(result, meta = {}) {
257
- const structured = {
258
- schema_version: 1,
259
- generated_at: new Date().toISOString(),
260
- overall_status: result.status,
261
- // 路径溯源(供平台消费)
262
- ...(meta.workspace_id ? { workspace_id: meta.workspace_id } : {}),
263
- ...(meta.scan_run_id ? { scan_run_id: meta.scan_run_id } : {}),
264
- ...(meta.source_root ? { source_root: meta.source_root } : {}),
265
- ...(meta.spec_root ? { spec_root: meta.spec_root } : {}),
266
- ...(meta.runtime_root ? { runtime_root: meta.runtime_root } : {}),
267
- summary: {
268
- total_checks: result.checks.length,
269
- critical: 0,
270
- error: 0,
271
- warning: 0,
272
- },
273
- failure_categories: {
274
- violations: [],
275
- missing_outputs: [],
276
- path_pollution: [],
277
- bad_references: [],
278
- quality_warnings: [],
279
- },
280
- checks: result.checks.map(c => ({
281
- name: c.name,
282
- severity: c.severity === 'failed' ? 'critical' : c.severity,
283
- detail: c.detail,
284
- })),
285
- }
286
-
287
- // 分类到 failure_categories
288
- for (const check of result.checks) {
289
- const severity = check.severity === 'failed' ? 'critical' : check.severity
290
- const entry = { name: check.name, detail: check.detail, severity }
291
-
292
- // 路径污染类
293
- if (check.name === 'source_root_leak' || check.name === 'source_root_docs_leak') {
294
- structured.failure_categories.path_pollution.push(entry)
295
- structured.failure_categories.violations.push(entry)
296
- }
297
- // 文档缺失类
298
- else if (check.name === 'all_docs_missing' || check.name === 'partial_docs_missing' || check.name === 'missing_docs') {
299
- structured.failure_categories.missing_outputs.push(entry)
300
- }
301
- // 引用无效类
302
- else if (check.name === 'local_config_invalid') {
303
- structured.failure_categories.bad_references.push(entry)
304
- }
305
- // AI 输出质量类
306
- else if (['api_error_529', 'rate_limit_exhausted'].includes(check.name)) {
307
- structured.failure_categories.quality_warnings.push(entry)
308
- }
309
- // manifest/project 列表问题
310
- else if (check.name === 'manifest_write_failed' || check.name === 'project_list_parse_failed') {
311
- structured.failure_categories.violations.push(entry)
312
- }
313
- // 文档缺少 header
314
- else if (check.name === 'docs_missing_header') {
315
- structured.failure_categories.quality_warnings.push(entry)
316
- }
317
- // 兜底:归入 violations
318
- else {
319
- structured.failure_categories.violations.push(entry)
320
- }
321
- }
322
-
323
- // 汇总计数
324
- for (const check of result.checks) {
325
- if (check.severity === 'failed') structured.summary.critical++
326
- else structured.summary.warning++
327
- }
328
-
329
- return structured
330
- }
331
-
332
- /**
333
- * 将结构化结果写入 JSON 文件(平台模式供 SillyHub 消费)
334
- *
335
- * 本地模式:写入 specDir/.runtime/postcheck-result.json
336
- * 平台模式:写入 runtimeRoot/scan-runs/{scan_run_id}/postcheck-result.json
337
- *
338
- * @param {object} structured - formatStructuredResult 返回值
339
- * @param {string} specDir - 规范目录(本地模式使用)
340
- * @param {object} [opts] - 平台模式选项
341
- * @param {string} [opts.runtimeRoot] - 平台模式运行时根目录
342
- * @param {string} [opts.scanRunId] - scan run ID
343
- * @returns {string|null} 写入的文件路径,失败时返回 null
344
- */
345
- export function writeStructuredResult(structured, specDir, opts = {}) {
346
- if (!specDir && !opts.runtimeRoot) return null
347
- try {
348
- let outPath
349
- if (opts.runtimeRoot && opts.scanRunId) {
350
- const scanRunDir = join(opts.runtimeRoot, 'scan-runs', opts.scanRunId)
351
- mkdirSync(scanRunDir, { recursive: true })
352
- outPath = join(scanRunDir, 'postcheck-result.json')
353
- } else if (specDir) {
354
- const runtimeDir = join(specDir, '.runtime')
355
- mkdirSync(runtimeDir, { recursive: true })
356
- outPath = join(runtimeDir, 'postcheck-result.json')
357
- } else {
358
- return null
359
- }
360
-
361
- writeFileSync(outPath, JSON.stringify(structured, null, 2) + '\n')
362
- return outPath
363
- } catch (e) {
364
- console.warn(` ⚠️ postcheck-result.json 写入失败: ${e.message}`)
365
- return null
366
- }
367
- }
368
-
369
- /**
370
- * 打印 post-check 结果到 stdout
371
- */
372
- export function printScanPostCheckResult(result) {
373
- if (result.checks.length === 0) {
374
- console.log(' ✅ CLI post-check: 全部通过')
375
- return
376
- }
377
-
378
- for (const check of result.checks) {
379
- const icon = check.severity === 'failed' ? '❌' : '⚠️'
380
- console.log(` ${icon} CLI post-check [${check.name}]: ${check.detail}`)
381
- }
382
- console.log(` 📋 最终状态: ${result.status}`)
383
- }