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
package/src/constants.js DELETED
@@ -1,70 +0,0 @@
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
- }
@@ -1,278 +0,0 @@
1
- /**
2
- * contract-matrix.js — API Contract Matrix 生成与注入
3
- *
4
- * plan 阶段:识别 task 之间的 provider/consumer 关系,生成契约矩阵
5
- * execute 阶段:
6
- * - 后端 task 完成后自动提取 endpoint artifact
7
- * - 前端 task 开始时注入上游契约
8
- * verify 阶段:读取 artifact 做 parity check
9
- */
10
-
11
- import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync } from 'fs'
12
- import { join, resolve, basename, relative } from 'path'
13
- import {
14
- scanBackendEndpoints,
15
- scanFrontendApiCalls,
16
- normalizePath,
17
- } from './endpoint-extractor.js'
18
-
19
- // ─── 关键词检测 ─────────────────────────────────────────────────────────
20
-
21
- const PROVIDER_KEYWORDS = /router|routes|endpoint|api|backend|controller|fastapi|flask|express|koa|spring/i
22
- const CONSUMER_KEYWORDS = /frontend|client|service|apiFetch|request|fetch|axios|http/i
23
-
24
- /**
25
- * 判断一个 task 文档是 provider(产出 API)还是 consumer(消费 API)
26
- * @param {string} taskContent - task markdown 内容
27
- * @returns {{ isProvider: boolean, isConsumer: boolean, confidence: number }}
28
- */
29
- export function classifyTask(taskContent) {
30
- const isProvider = PROVIDER_KEYWORDS.test(taskContent)
31
- const isConsumer = CONSUMER_KEYWORDS.test(taskContent)
32
- // 避免所有 task 都被标记(因为几乎所有 task 都含 "api")
33
- // 加强判定:provider 要命中 router/endpoint/backend/controller + api
34
- // consumer 要命中 frontend/client/apiFetch + api
35
- const providerStrong = /router|endpoint|backend|controller|fastapi|flask/i.test(taskContent)
36
- const consumerStrong = /frontend|apiFetch|axios|api.*client/i.test(taskContent)
37
- const providerConfidence = providerStrong ? 0.8 : (isProvider ? 0.4 : 0)
38
- const consumerConfidence = consumerStrong ? 0.8 : (isConsumer ? 0.4 : 0)
39
- return {
40
- isProvider: providerConfidence >= 0.4,
41
- isConsumer: consumerConfidence >= 0.4,
42
- confidence: Math.max(providerConfidence, consumerConfidence),
43
- }
44
- }
45
-
46
- /**
47
- * 从 plan.md 解析 task 依赖关系,识别 provider → consumer 对
48
- * @param {string} planContent - plan.md 内容
49
- * @param {string} changeDir - changes/<name>/ 目录
50
- * @returns {Array<{ provider: string, consumer: string, type: string }>}
51
- */
52
- export function buildContractMatrix(planContent, changeDir) {
53
- const contracts = []
54
-
55
- // 解析 task 依赖关系
56
- // 格式: - [ ] task-04: ... (depends_on: [task-01]) 或
57
- // | task-04 | ... | 01 |
58
- const taskDeps = parseTaskDependencies(planContent)
59
-
60
- // 读取各 task 文档,分类 provider/consumer
61
- const taskClasses = {}
62
- for (const taskName of Object.keys(taskDeps)) {
63
- const taskFile = join(changeDir, 'tasks', `${taskName}.md`)
64
- if (existsSync(taskFile)) {
65
- taskClasses[taskName] = classifyTask(readFileSync(taskFile, 'utf8'))
66
- }
67
- }
68
-
69
- // 识别契约对:A depends_on B,且 A 是 consumer,B 是 provider
70
- for (const [consumer, deps] of Object.entries(taskDeps)) {
71
- const consumerClass = taskClasses[consumer]
72
- if (!consumerClass?.isConsumer) continue
73
-
74
- for (const provider of deps) {
75
- const providerClass = taskClasses[provider]
76
- if (!providerClass?.isProvider) continue
77
-
78
- // 避免自引用和重复
79
- if (consumer === provider) continue
80
- const alreadyExists = contracts.some(
81
- c => c.provider === provider && c.consumer === consumer
82
- )
83
- if (alreadyExists) continue
84
-
85
- contracts.push({
86
- provider,
87
- consumer,
88
- type: 'api',
89
- })
90
- }
91
- }
92
-
93
- return contracts
94
- }
95
-
96
- /**
97
- * 从 plan.md 解析 task 依赖关系
98
- * @param {string} planContent
99
- * @returns {Record<string, string[]>} task → depends_on list
100
- */
101
- function parseTaskDependencies(planContent) {
102
- const deps = {}
103
-
104
- // 方式 1: 表格形式 | task-04 | ... | 01,02 |
105
- const tableRows = planContent.matchAll(/\|[^|]*task-(\d+)[^|]*\|[^|]*\|[^|]*(?:task-)?(\d+(?:\s*[,,]\s*\d+)*)[^|]*\|/gi)
106
- for (const match of tableRows) {
107
- const task = `task-${match[1]}`
108
- const depList = match[2].split(/[,,\s]+/).map(d => `task-${d.trim()}`).filter(d => d.startsWith('task-'))
109
- deps[task] = depList
110
- }
111
-
112
- // 方式 2: depends_on 关键字
113
- const dependsPattern = planContent.matchAll(/task-(\d+).*?depends_on.*?(\d+(?:\s*[,,]\s*\d+)*)/gi)
114
- for (const match of dependsPattern) {
115
- const task = `task-${match[1]}`
116
- const depList = match[2].split(/[,,\s]+/).map(d => `task-${d.trim()}`).filter(d => d.startsWith('task-'))
117
- if (!deps[task]) deps[task] = []
118
- for (const d of depList) {
119
- if (!deps[task].includes(d)) deps[task].push(d)
120
- }
121
- }
122
-
123
- return deps
124
- }
125
-
126
- // ─── Execute 阶段:后端 task 完成后提取 artifact ───────────────────────
127
-
128
- /**
129
- * 后端 task 完成后,扫描变更文件提取 endpoint artifact
130
- * @param {string} changeDir - changes/<name>/ 目录
131
- * @param {string} worktreePath - worktree 路径(扫描源码用)
132
- * @param {string} specBase - .sillyspec 目录
133
- * @param {string} taskName - task-04
134
- * @returns {{ ok: boolean, endpoints: Array, artifactPath: string|null }}
135
- */
136
- export function extractProviderArtifact(changeDir, worktreePath, specBase, taskName) {
137
- const artifactDir = join(specBase, '.runtime', 'contract-artifacts', taskName)
138
- const artifactPath = join(artifactDir, 'endpoints.json')
139
-
140
- if (!worktreePath || !existsSync(worktreePath)) {
141
- return { ok: false, endpoints: [], artifactPath: null, error: 'worktree not found' }
142
- }
143
-
144
- try {
145
- const endpoints = scanBackendEndpoints(worktreePath)
146
-
147
- if (endpoints.length > 0) {
148
- mkdirSync(artifactDir, { recursive: true })
149
- const artifact = {
150
- task: taskName,
151
- type: 'backend_endpoints',
152
- extractedAt: new Date().toISOString(),
153
- endpoints: endpoints.map(e => ({
154
- method: e.method,
155
- path: normalizePath(e.path),
156
- source: relative(worktreePath, e.source),
157
- line: e.line,
158
- })),
159
- }
160
- writeFileSync(artifactPath, JSON.stringify(artifact, null, 2) + '\n')
161
- return { ok: true, endpoints: artifact.endpoints, artifactPath }
162
- }
163
-
164
- // 无端点提取到 — 不算错误(可能不是 router task)
165
- return { ok: true, endpoints: [], artifactPath: null }
166
- } catch (e) {
167
- return { ok: false, endpoints: [], artifactPath: null, error: e.message }
168
- }
169
- }
170
-
171
- // ─── Execute 阶段:前端 task 开始时注入契约 ─────────────────────────────
172
-
173
- /**
174
- * 为 consumer task 构建上游契约注入文本
175
- * @param {string} changeDir - changes/<name>/ 目录
176
- * @param {string} specBase - .sillyspec 目录
177
- * @param {string} taskName - 当前 task(consumer)
178
- * @param {Array<{ provider: string, consumer: string, type: string }>} contracts
179
- * @returns {string|null} 注入到 prompt 的契约文本,无契约时返回 null
180
- */
181
- export function buildConsumerInjection(changeDir, specBase, taskName, contracts) {
182
- const myContracts = contracts.filter(c => c.consumer === taskName)
183
- if (myContracts.length === 0) return null
184
-
185
- const parts = []
186
- for (const contract of myContracts) {
187
- const artifactDir = join(specBase, '.runtime', 'contract-artifacts', contract.provider)
188
- const artifactFile = join(artifactDir, 'endpoints.json')
189
-
190
- let endpoints = []
191
- if (existsSync(artifactFile)) {
192
- try {
193
- const artifact = JSON.parse(readFileSync(artifactFile, 'utf8'))
194
- endpoints = artifact.endpoints || []
195
- } catch {}
196
- }
197
-
198
- parts.push(`### Upstream Contract: ${contract.provider}`)
199
- if (endpoints.length > 0) {
200
- parts.push(`\nAvailable endpoints from **${contract.provider}**:`)
201
- for (const ep of endpoints) {
202
- parts.push(`- **${ep.method}** \`${ep.path}\``)
203
- }
204
- } else {
205
- parts.push(`\n⚠️ No endpoint artifact found for ${contract.provider}. This may indicate a contract gap.`)
206
- }
207
- }
208
-
209
- if (parts.length === 0) return null
210
-
211
- parts.unshift('## Upstream API Contracts')
212
- parts.push('')
213
- parts.push('### Rules')
214
- parts.push('1. Do not invent API paths. Use only endpoints listed above.')
215
- parts.push('2. If a required endpoint is missing, **stop and report the contract gap** instead of coding around it.')
216
- parts.push('3. If you need to add new endpoints, you must also update the backend provider task.')
217
-
218
- return parts.join('\n')
219
- }
220
-
221
- // ─── Verify 阶段:parity check ──────────────────────────────────────────
222
-
223
- /**
224
- * verify 阶段执行 API parity check
225
- * @param {string} specBase - .sillyspec 目录
226
- * @param {string} worktreePath - worktree 路径
227
- * @returns {{ ok: boolean, missingBackend: Array, unusedBackend: Array, summary: string }}
228
- */
229
- export function verifyApiParity(specBase, worktreePath) {
230
- const { diffApiParity } = require('./endpoint-extractor.js')
231
-
232
- // 读取所有 provider artifacts
233
- const artifactBase = join(specBase, '.runtime', 'contract-artifacts')
234
- const allProviderEndpoints = []
235
-
236
- if (existsSync(artifactBase)) {
237
- for (const entry of readdirSync(artifactBase, { withFileTypes: true })) {
238
- if (!entry.isDirectory()) continue
239
- const epFile = join(artifactBase, entry.name, 'endpoints.json')
240
- if (existsSync(epFile)) {
241
- try {
242
- const artifact = JSON.parse(readFileSync(epFile, 'utf8'))
243
- for (const ep of (artifact.endpoints || [])) {
244
- allProviderEndpoints.push({
245
- method: ep.method,
246
- path: ep.path,
247
- source: `${entry.name}/${ep.source}`,
248
- })
249
- }
250
- } catch {}
251
- }
252
- }
253
- }
254
-
255
- // 扫描前端调用
256
- if (!worktreePath || !existsSync(worktreePath)) {
257
- return {
258
- ok: true,
259
- missingBackend: [],
260
- unusedBackend: [],
261
- summary: 'No worktree to scan for parity check',
262
- }
263
- }
264
-
265
- const frontendCalls = scanFrontendApiCalls(worktreePath)
266
- const { missingBackend, unusedBackend } = diffApiParity(frontendCalls, allProviderEndpoints)
267
-
268
- const ok = missingBackend.length === 0
269
- let summary = ok
270
- ? `✅ API parity check passed: ${allProviderEndpoints.length} backend endpoints, ${frontendCalls.length} frontend calls`
271
- : `❌ API parity check failed: ${missingBackend.length} frontend calls have no matching backend endpoint`
272
-
273
- if (unusedBackend.length > 0) {
274
- summary += ` | ${unusedBackend.length} backend endpoints unused by frontend`
275
- }
276
-
277
- return { ok, missingBackend, unusedBackend, summary }
278
- }
package/src/db.js DELETED
@@ -1,201 +0,0 @@
1
- import initSqlJs from 'sql.js';
2
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
3
- import { dirname } from 'path';
4
-
5
- export class DB {
6
- constructor(dbPath) {
7
- this.dbPath = dbPath;
8
- this.db = null;
9
- }
10
-
11
- async init() {
12
- // 1. 确保父目录存在
13
- const dir = dirname(this.dbPath);
14
- if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
15
-
16
- // 2. 初始化 sql.js
17
- const SQL = await initSqlJs();
18
-
19
- // 3. 加载已有数据库或创建新库
20
- if (existsSync(this.dbPath)) {
21
- const buf = readFileSync(this.dbPath);
22
- this.db = new SQL.Database(buf);
23
- } else {
24
- this.db = new SQL.Database();
25
- }
26
-
27
- // 4. 设置 PRAGMA
28
- this.db.run('PRAGMA journal_mode = WAL');
29
- this.db.run('PRAGMA busy_timeout = 5000');
30
- this.db.run('PRAGMA foreign_keys = ON');
31
- this.db.run('PRAGMA synchronous = NORMAL');
32
-
33
- // 5. 创建表结构
34
- this._createSchema();
35
-
36
- // 6. 保存到磁盘
37
- this._save();
38
- }
39
-
40
- close() {
41
- if (this.db) {
42
- this._save();
43
- this.db.close();
44
- this.db = null;
45
- }
46
- }
47
-
48
- transaction(fn) {
49
- if (!this.db) throw new Error('DB not initialized');
50
- this.db.run('BEGIN');
51
- try {
52
- const result = fn(this.db);
53
- this.db.run('COMMIT');
54
- this._save();
55
- return result;
56
- } catch (err) {
57
- this.db.run('ROLLBACK');
58
- throw err;
59
- }
60
- }
61
-
62
- /** 获取底层 db 对象(供 progress.js 直接使用) */
63
- getDb() {
64
- return this.db;
65
- }
66
-
67
- /** 将内存中的数据库持久化到磁盘 */
68
- _save() {
69
- if (!this.db) return;
70
- const data = this.db.export();
71
- const buffer = Buffer.from(data);
72
- writeFileSync(this.dbPath, buffer);
73
- // sql.js 的 export() 会重置 PRAGMA 状态,需要重新设置
74
- this.db.run('PRAGMA journal_mode = WAL');
75
- this.db.run('PRAGMA busy_timeout = 5000');
76
- this.db.run('PRAGMA foreign_keys = ON');
77
- this.db.run('PRAGMA synchronous = NORMAL');
78
- }
79
-
80
- _createSchema() {
81
- // project 表
82
- this.db.run(`
83
- CREATE TABLE IF NOT EXISTS project (
84
- id INTEGER PRIMARY KEY DEFAULT 1,
85
- name TEXT NOT NULL,
86
- schema_version INTEGER DEFAULT 4,
87
- created_at TEXT NOT NULL,
88
- updated_at TEXT NOT NULL
89
- )
90
- `);
91
-
92
- // changes 表
93
- this.db.run(`
94
- CREATE TABLE IF NOT EXISTS changes (
95
- id INTEGER PRIMARY KEY AUTOINCREMENT,
96
- name TEXT UNIQUE NOT NULL,
97
- current_stage TEXT DEFAULT 'scan',
98
- status TEXT DEFAULT 'active',
99
- no_worktree INTEGER DEFAULT 0,
100
- created_at TEXT NOT NULL,
101
- last_active TEXT NOT NULL,
102
- platform_change_id INTEGER,
103
- platform_workspace_id INTEGER,
104
- platform_last_sync TEXT,
105
- platform_sync_enabled INTEGER DEFAULT 0
106
- )
107
- `);
108
-
109
- // stages 表
110
- this.db.run(`
111
- CREATE TABLE IF NOT EXISTS stages (
112
- id INTEGER PRIMARY KEY AUTOINCREMENT,
113
- change_id INTEGER NOT NULL REFERENCES changes(id) ON DELETE CASCADE,
114
- stage TEXT NOT NULL,
115
- status TEXT DEFAULT 'pending',
116
- started_at TEXT,
117
- completed_at TEXT,
118
- UNIQUE(change_id, stage)
119
- )
120
- `);
121
-
122
- // steps 表
123
- this.db.run(`
124
- CREATE TABLE IF NOT EXISTS steps (
125
- id INTEGER PRIMARY KEY AUTOINCREMENT,
126
- stage_id INTEGER NOT NULL REFERENCES stages(id) ON DELETE CASCADE,
127
- name TEXT NOT NULL,
128
- status TEXT DEFAULT 'pending',
129
- output TEXT,
130
- completed_at TEXT,
131
- ordering INTEGER NOT NULL DEFAULT 0
132
- )
133
- `);
134
-
135
- // batch_progress 表
136
- this.db.run(`
137
- CREATE TABLE IF NOT EXISTS batch_progress (
138
- id INTEGER PRIMARY KEY AUTOINCREMENT,
139
- change_id INTEGER NOT NULL REFERENCES changes(id) ON DELETE CASCADE,
140
- total INTEGER DEFAULT 0,
141
- completed INTEGER DEFAULT 0,
142
- failed INTEGER DEFAULT 0,
143
- skipped INTEGER DEFAULT 0,
144
- UNIQUE(change_id)
145
- )
146
- `);
147
-
148
- // approvals 表
149
- this.db.run(`
150
- CREATE TABLE IF NOT EXISTS approvals (
151
- id INTEGER PRIMARY KEY AUTOINCREMENT,
152
- change_id INTEGER NOT NULL REFERENCES changes(id) ON DELETE CASCADE,
153
- status TEXT DEFAULT 'not_required',
154
- requested_at TEXT,
155
- approved_by TEXT,
156
- approved_at TEXT,
157
- rejection_reason TEXT,
158
- UNIQUE(change_id)
159
- )
160
- `);
161
-
162
- // 索引
163
- this.db.run('CREATE INDEX IF NOT EXISTS idx_changes_current_stage ON changes(current_stage)');
164
- this.db.run('CREATE INDEX IF NOT EXISTS idx_changes_status ON changes(status)');
165
- this.db.run('CREATE INDEX IF NOT EXISTS idx_stages_change ON stages(change_id)');
166
- this.db.run('CREATE INDEX IF NOT EXISTS idx_steps_stage ON steps(stage_id)');
167
-
168
- // Migration: add isolation columns to changes table (idempotent)
169
- this._migrateAddColumn('changes', 'isolation_status', 'TEXT');
170
- this._migrateAddColumn('changes', 'isolation_mode', 'TEXT');
171
- this._migrateAddColumn('changes', 'isolation_reason', 'TEXT');
172
-
173
- // Migration: add waiting support columns to steps table (idempotent)
174
- this._migrateAddColumn('steps', 'wait_reason', 'TEXT');
175
- this._migrateAddColumn('steps', 'wait_options', 'TEXT');
176
- this._migrateAddColumn('steps', 'wait_answer', 'TEXT');
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');
182
-
183
- // Revision v1 support
184
- this._migrateAddColumn('stages', 'revision', 'INTEGER DEFAULT 0');
185
- this._migrateAddColumn('stages', 'reopened_from_step', 'TEXT');
186
- this._migrateAddColumn('stages', 'reopened_at', 'TEXT');
187
- this._migrateAddColumn('stages', 'stale_reason', 'TEXT');
188
- }
189
-
190
- /**
191
- * 幂等地给表添加列(列已存在则跳过)
192
- * @private
193
- */
194
- _migrateAddColumn(table, column, type) {
195
- try {
196
- this.db.run(`ALTER TABLE ${table} ADD COLUMN ${column} ${type}`);
197
- } catch {
198
- // 列已存在,静默跳过
199
- }
200
- }
201
- }