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.
- package/.claude/skills/sillyspec-archive/SKILL.md +1 -5
- package/.claude/skills/sillyspec-auto/SKILL.md +2 -8
- package/.claude/skills/sillyspec-brainstorm/SKILL.md +1 -28
- package/.claude/skills/sillyspec-commit/SKILL.md +3 -4
- package/.claude/skills/sillyspec-continue/SKILL.md +4 -5
- package/.claude/skills/sillyspec-doctor/SKILL.md +3 -12
- package/.claude/skills/sillyspec-execute/SKILL.md +2 -15
- package/.claude/skills/sillyspec-explore/SKILL.md +1 -14
- package/.claude/skills/sillyspec-plan/SKILL.md +36 -5
- package/.claude/skills/sillyspec-propose/SKILL.md +0 -4
- package/.claude/skills/sillyspec-quick/SKILL.md +1 -5
- package/.claude/skills/sillyspec-resume/SKILL.md +66 -23
- package/.claude/skills/sillyspec-scan/SKILL.md +1 -5
- package/.claude/skills/sillyspec-state/SKILL.md +8 -8
- package/.claude/skills/sillyspec-status/SKILL.md +1 -5
- package/.claude/skills/sillyspec-verify/SKILL.md +1 -5
- package/.claude/skills/sillyspec-workspace/SKILL.md +3 -11
- package/.sillyspec/changes/archive/2026-04-08-derive-state/design.md +97 -0
- package/.sillyspec/changes/archive/2026-04-08-derive-state/plan.md +51 -0
- package/.sillyspec/changes/archive/2026-04-08-derive-state/proposal.md +29 -0
- package/.sillyspec/changes/archive/2026-04-08-derive-state/requirements.md +34 -0
- package/.sillyspec/changes/archive/2026-04-08-derive-state/tasks.md +13 -0
- package/.sillyspec/changes/archive/2026-04-08-derive-state/verify-result.md +43 -0
- package/.sillyspec/changes/auto-mode/design.md +50 -0
- package/.sillyspec/changes/auto-mode/proposal.md +19 -0
- package/.sillyspec/changes/auto-mode/requirements.md +21 -0
- package/.sillyspec/changes/auto-mode/tasks.md +7 -0
- package/.sillyspec/changes/brainstorm-archive/2026-04-05-dashboard-design.md +206 -0
- package/.sillyspec/changes/brainstorm-archive/2026-04-05-unified-docs-design.md +199 -0
- package/.sillyspec/changes/dashboard/design.md +219 -0
- package/.sillyspec/changes/dashboard/design.md.braindraft +206 -0
- package/.sillyspec/changes/run-command-design/design.md +1230 -0
- package/.sillyspec/changes/unified-docs-design/design.md +199 -0
- package/.sillyspec/docs/sillyspec/scan/.gitkeep +0 -0
- package/.sillyspec/knowledge/INDEX.md +8 -0
- package/.sillyspec/knowledge/uncategorized.md +3 -0
- package/.sillyspec/plans/2026-04-05-dashboard.md +737 -0
- package/.sillyspec/projects/sillyspec.yaml +3 -0
- package/README.md +11 -13
- package/SKILL.md +40 -44
- package/dist/steps/brainstorm/01-load-context.md +30 -0
- package/dist/steps/brainstorm/02-reuse-check.md +6 -0
- package/dist/steps/brainstorm/03-prototype-analysis.md +11 -0
- package/dist/steps/brainstorm/04-module-split.md +23 -0
- package/dist/steps/brainstorm/05-dialog-explore.md +8 -0
- package/dist/steps/brainstorm/06-propose-approaches.md +3 -0
- package/dist/steps/brainstorm/07-present-design.md +3 -0
- package/dist/steps/brainstorm/08-write-design.md +21 -0
- package/dist/steps/brainstorm/09-self-review.md +15 -0
- package/dist/steps/brainstorm/10-user-confirm.md +3 -0
- package/dist/steps/brainstorm/11-output-spec.md +7 -0
- package/dist/steps/brainstorm/manifest.yaml +26 -0
- package/dist/steps/execute/01-load-context.md +41 -0
- package/dist/steps/execute/02-scan-conventions.md +47 -0
- package/dist/steps/execute/03-skill-mcp.md +19 -0
- package/dist/steps/execute/04-assign-task.md +22 -0
- package/dist/steps/execute/04b-prompt-template.md +54 -0
- package/dist/steps/execute/05-write-test.md +7 -0
- package/dist/steps/execute/06-write-code.md +8 -0
- package/dist/steps/execute/07-run-test.md +26 -0
- package/dist/steps/execute/08-fix-issues.md +28 -0
- package/dist/steps/execute/09-next-task.md +33 -0
- package/dist/steps/execute/manifest.yaml +28 -0
- package/dist/steps/plan/01-load-context.md +22 -0
- package/dist/steps/plan/02-anchor-confirm.md +1 -0
- package/dist/steps/plan/03-expand-tasks.md +33 -0
- package/dist/steps/plan/04-mark-order.md +15 -0
- package/dist/steps/plan/05-e2e-planning.md +17 -0
- package/dist/steps/plan/06-self-check.md +16 -0
- package/dist/steps/plan/07-save.md +1 -0
- package/dist/steps/plan/manifest.yaml +18 -0
- package/dist/steps/scan/01-env-detect.md +51 -0
- package/dist/steps/scan/02-tech-stack.md +16 -0
- package/dist/steps/scan/03-conventions.md +16 -0
- package/dist/steps/scan/04-structure.md +19 -0
- package/dist/steps/scan/05-quality.md +18 -0
- package/dist/steps/scan/06-complete.md +49 -0
- package/dist/steps/scan/manifest.yaml +16 -0
- package/dist/steps/verify/01-load-specs.md +28 -0
- package/dist/steps/verify/02-check-tasks.md +1 -0
- package/dist/steps/verify/03-check-design.md +6 -0
- package/dist/steps/verify/04-run-tests.md +7 -0
- package/dist/steps/verify/05-e2e-tests.md +27 -0
- package/dist/steps/verify/05b-e2e-fix.md +33 -0
- package/dist/steps/verify/06-code-quality.md +25 -0
- package/dist/steps/verify/07-lint-check.md +27 -0
- package/dist/steps/verify/08-output-report.md +14 -0
- package/dist/steps/verify/manifest.yaml +22 -0
- package/package.json +1 -7
- package/packages/dashboard/dist/assets/{index-Bq_Z2hne.js → index-D1EVTLmc.js} +1264 -1264
- package/packages/dashboard/dist/assets/index-DGe8CqeP.css +1 -0
- package/packages/dashboard/dist/index.html +2 -2
- package/packages/dashboard/package-lock.json +6 -6
- package/packages/dashboard/server/executor.js +1 -1
- package/packages/dashboard/server/index.js +18 -98
- package/packages/dashboard/server/parser.js +71 -139
- package/packages/dashboard/server/watcher.js +6 -14
- package/packages/dashboard/src/App.vue +185 -418
- package/packages/dashboard/src/components/ActionBar.vue +1 -10
- package/packages/dashboard/src/components/CommandPalette.vue +1 -5
- package/packages/dashboard/src/components/DocPreview.vue +8 -105
- package/packages/dashboard/src/components/DocTree.vue +19 -75
- package/packages/dashboard/src/components/PipelineStage.vue +2 -22
- package/packages/dashboard/src/components/PipelineView.vue +5 -32
- package/packages/dashboard/src/components/ProjectOverview.vue +139 -113
- package/packages/dashboard/src/components/StageBadge.vue +3 -17
- package/packages/dashboard/src/components/StepCard.vue +2 -7
- package/packages/dashboard/src/composables/useDashboard.js +0 -28
- package/src/derive.js +147 -0
- package/src/index.js +40 -688
- package/src/init.js +63 -119
- package/src/migrate.js +7 -7
- package/src/progress.js +248 -1474
- package/src/run.js +302 -3008
- package/src/setup.js +64 -2
- package/src/stages/archive.js +17 -123
- package/src/stages/brainstorm.js +48 -454
- package/src/stages/doctor.js +46 -99
- package/src/stages/execute.js +59 -420
- package/src/stages/index.js +18 -12
- package/src/stages/plan.js +189 -492
- package/src/stages/propose.js +11 -70
- package/src/stages/quick.js +13 -52
- package/src/stages/scan.js +68 -485
- package/src/stages/status.js +1 -1
- package/src/stages/verify.js +16 -203
- package/src/step.js +543 -0
- package/.claude/skills/sillyspec-knowledge/SKILL.md +0 -270
- package/.husky/pre-push +0 -13
- package/CLAUDE.md +0 -18
- package/docs/brainstorm-plan-contract.md +0 -64
- package/docs/plan-execute-contract.md +0 -123
- package/docs/platform-scan-protocol.md +0 -298
- package/docs/revision-mode.md +0 -115
- package/docs/sillyspec/file-lifecycle/known-implementation-gaps.md +0 -99
- package/docs/sillyspec/file-lifecycle/platform-workflows-sync.md +0 -218
- package/docs/sillyspec/file-lifecycle/stage-artifacts.md +0 -167
- package/docs/sillyspec/file-lifecycle/storage-and-state.md +0 -148
- package/docs/sillyspec/file-lifecycle/worktree-and-guard.md +0 -193
- package/docs/sillyspec/file-lifecycle.md +0 -125
- package/docs/workflow-contract-regression.md +0 -106
- package/docs/worktree-isolation.md +0 -252
- package/packages/dashboard/dist/assets/index-O2W5RV4z.css +0 -1
- package/packages/dashboard/dist/prototype-dashboard.html +0 -836
- package/packages/dashboard/dist/prototype-overview.html +0 -256
- package/packages/dashboard/public/prototype-dashboard.html +0 -836
- package/packages/dashboard/public/prototype-overview.html +0 -256
- package/packages/dashboard/src/components/HResizeHandle.vue +0 -48
- package/packages/dashboard/src/components/ProjectCard.vue +0 -187
- package/packages/dashboard/src/components/VResizeHandle.vue +0 -61
- package/packages/dashboard/src/composables/useLayout.js +0 -131
- package/src/brainstorm-postcheck.js +0 -158
- package/src/change-list.js +0 -52
- package/src/change-risk-profile.js +0 -352
- package/src/classify-change.js +0 -73
- package/src/constants.js +0 -70
- package/src/contract-matrix.js +0 -278
- package/src/db.js +0 -201
- package/src/endpoint-extractor.js +0 -315
- package/src/hooks/claude-pre-tool-use.cjs +0 -125
- package/src/hooks/worktree-guard.js +0 -761
- package/src/knowledge-match.js +0 -130
- package/src/modules.js +0 -482
- package/src/scan-postcheck.js +0 -383
- package/src/stage-contract.js +0 -700
- package/src/stages/brainstorm-auto.js +0 -229
- package/src/stages/explore.js +0 -34
- package/src/stages/knowledge.js +0 -498
- package/src/stages/plan-postcheck.js +0 -513
- package/src/sync.js +0 -497
- package/src/task-review.js +0 -346
- package/src/workflow.js +0 -785
- package/src/worktree-apply.js +0 -549
- package/src/worktree.js +0 -932
- package/templates/workflows/archive-impact.yaml +0 -79
- package/templates/workflows/scan-docs.yaml +0 -132
- package/test/brainstorm-plan-contract.test.mjs +0 -273
- package/test/check-syntax.mjs +0 -26
- package/test/cli-top-level-aliases.test.mjs +0 -174
- package/test/contract-artifacts.test.mjs +0 -323
- package/test/decision-supersede.test.mjs +0 -277
- package/test/knowledge-match.test.mjs +0 -231
- package/test/plan-execute-contract.test.mjs +0 -330
- package/test/plan-optimization.test.mjs +0 -572
- package/test/platform-artifacts.test.mjs +0 -190
- package/test/platform-failure-samples.test.mjs +0 -199
- package/test/platform-recovery-chain.test.mjs +0 -179
- package/test/platform-recovery.test.mjs +0 -167
- package/test/platform-scan-p0.test.mjs +0 -175
- package/test/revision-v1.test.mjs +0 -1145
- package/test/run-sanitize-project-name.test.mjs +0 -51
- package/test/run-scan-postcheck-fail.test.mjs +0 -64
- package/test/run-scan-project-parse.test.mjs +0 -200
- package/test/run-tests.mjs +0 -48
- package/test/scan-docs-yaml-placeholders.test.mjs +0 -84
- package/test/scan-knowledge.test.mjs +0 -175
- package/test/scan-paths.test.mjs +0 -68
- package/test/scan-postcheck-project-priority.test.mjs +0 -85
- package/test/scan-postcheck.test.mjs +0 -197
- package/test/scan-workflow-anyfailed-block.test.mjs +0 -52
- package/test/spec-dir.test.mjs +0 -206
- package/test/stage-contract-failed-post-check.test.mjs +0 -102
- package/test/stage-contract.test.mjs +0 -299
- package/test/stage-definitions.test.mjs +0 -39
- package/test/wait-gates.test.mjs +0 -501
- package/test/workflow-spec-base.test.mjs +0 -142
- package/test/worktree-guard.test.mjs +0 -136
- package/test/worktree-native-overlay.test.mjs +0 -188
package/src/scan-postcheck.js
DELETED
|
@@ -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
|
-
}
|