sillyspec 3.27.5 → 3.27.7

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 (1101) hide show
  1. package/.claude/skills/sillyspec-archive/SKILL.md +87 -87
  2. package/.claude/skills/sillyspec-auto/SKILL.md +93 -93
  3. package/.claude/skills/sillyspec-brainstorm/SKILL.md +114 -114
  4. package/.claude/skills/sillyspec-commit/SKILL.md +67 -67
  5. package/.claude/skills/sillyspec-continue/SKILL.md +47 -47
  6. package/.claude/skills/sillyspec-doctor/SKILL.md +76 -76
  7. package/.claude/skills/sillyspec-execute/SKILL.md +214 -214
  8. package/.claude/skills/sillyspec-explore/SKILL.md +102 -102
  9. package/.claude/skills/sillyspec-export/SKILL.md +57 -57
  10. package/.claude/skills/sillyspec-init/SKILL.md +177 -177
  11. package/.claude/skills/sillyspec-knowledge/SKILL.md +269 -269
  12. package/.claude/skills/sillyspec-plan/SKILL.md +156 -156
  13. package/.claude/skills/sillyspec-propose/SKILL.md +87 -0
  14. package/.claude/skills/sillyspec-quick/SKILL.md +116 -116
  15. package/.claude/skills/sillyspec-resume/SKILL.md +70 -70
  16. package/.claude/skills/sillyspec-scan/SKILL.md +79 -79
  17. package/.claude/skills/sillyspec-state/SKILL.md +64 -64
  18. package/.claude/skills/sillyspec-status/SKILL.md +54 -54
  19. package/.claude/skills/sillyspec-verify/SKILL.md +87 -87
  20. package/.claude/skills/sillyspec-workspace/SKILL.md +175 -175
  21. package/.claude/skills/verify-per-user/SKILL.md +6 -0
  22. package/.worktrees/2c37b1d7/.claude/skills/sillyspec-archive/SKILL.md +87 -0
  23. package/.worktrees/2c37b1d7/.claude/skills/sillyspec-auto/SKILL.md +93 -0
  24. package/.worktrees/2c37b1d7/.claude/skills/sillyspec-brainstorm/SKILL.md +114 -0
  25. package/.worktrees/2c37b1d7/.claude/skills/sillyspec-commit/SKILL.md +67 -0
  26. package/.worktrees/2c37b1d7/.claude/skills/sillyspec-continue/SKILL.md +47 -0
  27. package/.worktrees/2c37b1d7/.claude/skills/sillyspec-doctor/SKILL.md +76 -0
  28. package/.worktrees/2c37b1d7/.claude/skills/sillyspec-execute/SKILL.md +214 -0
  29. package/.worktrees/2c37b1d7/.claude/skills/sillyspec-explore/SKILL.md +102 -0
  30. package/.worktrees/2c37b1d7/.claude/skills/sillyspec-export/SKILL.md +57 -0
  31. package/.worktrees/2c37b1d7/.claude/skills/sillyspec-init/SKILL.md +177 -0
  32. package/.worktrees/2c37b1d7/.claude/skills/sillyspec-knowledge/SKILL.md +270 -0
  33. package/.worktrees/2c37b1d7/.claude/skills/sillyspec-plan/SKILL.md +156 -0
  34. package/.worktrees/2c37b1d7/.claude/skills/sillyspec-propose/SKILL.md +87 -0
  35. package/.worktrees/2c37b1d7/.claude/skills/sillyspec-quick/SKILL.md +116 -0
  36. package/.worktrees/2c37b1d7/.claude/skills/sillyspec-resume/SKILL.md +70 -0
  37. package/.worktrees/2c37b1d7/.claude/skills/sillyspec-scan/SKILL.md +79 -0
  38. package/.worktrees/2c37b1d7/.claude/skills/sillyspec-state/SKILL.md +64 -0
  39. package/.worktrees/2c37b1d7/.claude/skills/sillyspec-status/SKILL.md +54 -0
  40. package/.worktrees/2c37b1d7/.claude/skills/sillyspec-verify/SKILL.md +87 -0
  41. package/.worktrees/2c37b1d7/.claude/skills/sillyspec-workspace/SKILL.md +175 -0
  42. package/.worktrees/2c37b1d7/.claude/skills/verify-per-user/SKILL.md +6 -0
  43. package/.worktrees/2c37b1d7/.gitattributes +2 -0
  44. package/.worktrees/2c37b1d7/.husky/pre-push +20 -0
  45. package/.worktrees/2c37b1d7/README.md +203 -0
  46. package/.worktrees/2c37b1d7/SKILL.md +91 -0
  47. package/.worktrees/2c37b1d7/architecture-analysis.md +448 -0
  48. package/.worktrees/2c37b1d7/bin/sillyspec.js +2 -0
  49. package/.worktrees/2c37b1d7/eval/README.md +86 -0
  50. package/.worktrees/2c37b1d7/eval/eval.config.json +28 -0
  51. package/.worktrees/2c37b1d7/eval/lib/adapters/cli.mjs +63 -0
  52. package/.worktrees/2c37b1d7/eval/lib/adapters/dryrun.mjs +27 -0
  53. package/.worktrees/2c37b1d7/eval/lib/config.mjs +82 -0
  54. package/.worktrees/2c37b1d7/eval/lib/db.mjs +76 -0
  55. package/.worktrees/2c37b1d7/eval/lib/report.mjs +120 -0
  56. package/.worktrees/2c37b1d7/eval/lib/runner.mjs +157 -0
  57. package/.worktrees/2c37b1d7/eval/lib/tasks.mjs +73 -0
  58. package/.worktrees/2c37b1d7/eval/lib/util.mjs +107 -0
  59. package/.worktrees/2c37b1d7/eval/lib/workdir.mjs +30 -0
  60. package/.worktrees/2c37b1d7/eval/run.mjs +83 -0
  61. package/.worktrees/2c37b1d7/eval/tasks/001-slugify/files/package.json +6 -0
  62. package/.worktrees/2c37b1d7/eval/tasks/001-slugify/solution/src/slugify.mjs +26 -0
  63. package/.worktrees/2c37b1d7/eval/tasks/001-slugify/task.json +6 -0
  64. package/.worktrees/2c37b1d7/eval/tasks/001-slugify/verify.mjs +28 -0
  65. package/.worktrees/2c37b1d7/eval/tasks/002-each-day/files/package.json +6 -0
  66. package/.worktrees/2c37b1d7/eval/tasks/002-each-day/files/src/dates.mjs +4 -0
  67. package/.worktrees/2c37b1d7/eval/tasks/002-each-day/solution/src/dates.mjs +30 -0
  68. package/.worktrees/2c37b1d7/eval/tasks/002-each-day/task.json +6 -0
  69. package/.worktrees/2c37b1d7/eval/tasks/002-each-day/verify.mjs +31 -0
  70. package/.worktrees/2c37b1d7/eval/tasks/003-word-report/files/data/notes.txt +5 -0
  71. package/.worktrees/2c37b1d7/eval/tasks/003-word-report/files/package.json +6 -0
  72. package/.worktrees/2c37b1d7/eval/tasks/003-word-report/solution/bin/report.mjs +36 -0
  73. package/.worktrees/2c37b1d7/eval/tasks/003-word-report/task.json +6 -0
  74. package/.worktrees/2c37b1d7/eval/tasks/003-word-report/verify.mjs +38 -0
  75. package/.worktrees/2c37b1d7/logo.jpg +0 -0
  76. package/.worktrees/2c37b1d7/package-lock.json +977 -0
  77. package/.worktrees/2c37b1d7/package.json +41 -0
  78. package/.worktrees/2c37b1d7/packages/dashboard/dist/assets/index-Bq_Z2hne.js +7446 -0
  79. package/.worktrees/2c37b1d7/packages/dashboard/dist/assets/index-O2W5RV4z.css +1 -0
  80. package/.worktrees/2c37b1d7/packages/dashboard/dist/favicon.jpg +0 -0
  81. package/.worktrees/2c37b1d7/packages/dashboard/dist/index.html +16 -0
  82. package/.worktrees/2c37b1d7/packages/dashboard/dist/logo.jpg +0 -0
  83. package/.worktrees/2c37b1d7/packages/dashboard/dist/prototype-dashboard.html +836 -0
  84. package/.worktrees/2c37b1d7/packages/dashboard/dist/prototype-overview.html +256 -0
  85. package/.worktrees/2c37b1d7/packages/dashboard/package.json +25 -0
  86. package/.worktrees/2c37b1d7/packages/dashboard/server/executor.js +95 -0
  87. package/.worktrees/2c37b1d7/packages/dashboard/server/index.js +679 -0
  88. package/.worktrees/2c37b1d7/packages/dashboard/server/parser.js +526 -0
  89. package/.worktrees/2c37b1d7/packages/dashboard/server/watcher.js +357 -0
  90. package/.worktrees/2c37b1d7/src/agent-session-log.js +803 -0
  91. package/.worktrees/2c37b1d7/src/change-list.js +290 -0
  92. package/.worktrees/2c37b1d7/src/change-risk-profile.js +339 -0
  93. package/.worktrees/2c37b1d7/src/check-primitives.js +65 -0
  94. package/.worktrees/2c37b1d7/src/classify-change.js +109 -0
  95. package/.worktrees/2c37b1d7/src/commit-suggest.js +202 -0
  96. package/.worktrees/2c37b1d7/src/config-cat.js +88 -0
  97. package/.worktrees/2c37b1d7/src/config-schema.js +328 -0
  98. package/.worktrees/2c37b1d7/src/constants.js +97 -0
  99. package/.worktrees/2c37b1d7/src/contract-matrix.js +533 -0
  100. package/.worktrees/2c37b1d7/src/datetime.js +20 -0
  101. package/.worktrees/2c37b1d7/src/db-engine.js +55 -0
  102. package/.worktrees/2c37b1d7/src/db.js +381 -0
  103. package/.worktrees/2c37b1d7/src/decision-distill.js +517 -0
  104. package/.worktrees/2c37b1d7/src/dispatch/backends/local-agent.js +155 -0
  105. package/.worktrees/2c37b1d7/src/dispatch/backends/sillyhub-mcp.js +245 -0
  106. package/.worktrees/2c37b1d7/src/dispatch/probe.js +246 -0
  107. package/.worktrees/2c37b1d7/src/dispatch/strategy.js +121 -0
  108. package/.worktrees/2c37b1d7/src/docs-check.js +825 -0
  109. package/.worktrees/2c37b1d7/src/docs-debt.js +393 -0
  110. package/.worktrees/2c37b1d7/src/docs-gate.js +107 -0
  111. package/.worktrees/2c37b1d7/src/doctor-diagnostics.js +1099 -0
  112. package/.worktrees/2c37b1d7/src/endpoint-extractor.js +409 -0
  113. package/.worktrees/2c37b1d7/src/foreign-declared.js +155 -0
  114. package/.worktrees/2c37b1d7/src/fs-atomic.js +73 -0
  115. package/.worktrees/2c37b1d7/src/git-helper.js +150 -0
  116. package/.worktrees/2c37b1d7/src/hooks/claude-pre-tool-use.cjs +130 -0
  117. package/.worktrees/2c37b1d7/src/hooks/worktree-guard.js +892 -0
  118. package/.worktrees/2c37b1d7/src/index.js +2854 -0
  119. package/.worktrees/2c37b1d7/src/init.js +626 -0
  120. package/.worktrees/2c37b1d7/src/knowledge-match.js +231 -0
  121. package/.worktrees/2c37b1d7/src/local-detect.js +128 -0
  122. package/.worktrees/2c37b1d7/src/local-register.js +104 -0
  123. package/.worktrees/2c37b1d7/src/machine-interface.js +543 -0
  124. package/.worktrees/2c37b1d7/src/migrate.js +127 -0
  125. package/.worktrees/2c37b1d7/src/module-impact.js +166 -0
  126. package/.worktrees/2c37b1d7/src/module-resolve.js +222 -0
  127. package/.worktrees/2c37b1d7/src/modules.js +580 -0
  128. package/.worktrees/2c37b1d7/src/plan-adopt-waves.js +126 -0
  129. package/.worktrees/2c37b1d7/src/progress/change-registry.js +336 -0
  130. package/.worktrees/2c37b1d7/src/progress/consistency-doctor.js +355 -0
  131. package/.worktrees/2c37b1d7/src/progress/shared.js +36 -0
  132. package/.worktrees/2c37b1d7/src/progress/stage-machine.js +594 -0
  133. package/.worktrees/2c37b1d7/src/progress/step-store.js +265 -0
  134. package/.worktrees/2c37b1d7/src/progress.js +1304 -0
  135. package/.worktrees/2c37b1d7/src/quick-recommend.js +115 -0
  136. package/.worktrees/2c37b1d7/src/quicklog.js +883 -0
  137. package/.worktrees/2c37b1d7/src/review-tier.js +77 -0
  138. package/.worktrees/2c37b1d7/src/run/command.js +1641 -0
  139. package/.worktrees/2c37b1d7/src/run/complete-handlers.js +1552 -0
  140. package/.worktrees/2c37b1d7/src/run/complete.js +1259 -0
  141. package/.worktrees/2c37b1d7/src/run/concurrent-detect.js +156 -0
  142. package/.worktrees/2c37b1d7/src/run/gates.js +1111 -0
  143. package/.worktrees/2c37b1d7/src/run/multi-repo-context.js +208 -0
  144. package/.worktrees/2c37b1d7/src/run/next.js +128 -0
  145. package/.worktrees/2c37b1d7/src/run/prompt.js +843 -0
  146. package/.worktrees/2c37b1d7/src/run/quick-audit.js +186 -0
  147. package/.worktrees/2c37b1d7/src/run/scan-profile.js +269 -0
  148. package/.worktrees/2c37b1d7/src/run/shared.js +1562 -0
  149. package/.worktrees/2c37b1d7/src/run/stage.js +587 -0
  150. package/.worktrees/2c37b1d7/src/run.js +23 -0
  151. package/.worktrees/2c37b1d7/src/scan-diff.js +388 -0
  152. package/.worktrees/2c37b1d7/src/scan-postcheck.js +524 -0
  153. package/.worktrees/2c37b1d7/src/scan-staleness.js +95 -0
  154. package/.worktrees/2c37b1d7/src/setup.js +414 -0
  155. package/.worktrees/2c37b1d7/src/sillyhub-mcp/client.js +597 -0
  156. package/.worktrees/2c37b1d7/src/sillyhub-mcp/config.js +62 -0
  157. package/.worktrees/2c37b1d7/src/spec-dir-typo.js +50 -0
  158. package/.worktrees/2c37b1d7/src/spec-sync.js +358 -0
  159. package/.worktrees/2c37b1d7/src/stage-contract-engine.js +171 -0
  160. package/.worktrees/2c37b1d7/src/stage-contract-spec.js +551 -0
  161. package/.worktrees/2c37b1d7/src/stage-contract.js +948 -0
  162. package/.worktrees/2c37b1d7/src/stage-review.js +597 -0
  163. package/.worktrees/2c37b1d7/src/stages/archive.js +199 -0
  164. package/.worktrees/2c37b1d7/src/stages/brainstorm-auto.js +285 -0
  165. package/.worktrees/2c37b1d7/src/stages/brainstorm.js +624 -0
  166. package/.worktrees/2c37b1d7/src/stages/cmd-existence.js +145 -0
  167. package/.worktrees/2c37b1d7/src/stages/doctor.js +540 -0
  168. package/.worktrees/2c37b1d7/src/stages/execute.js +1277 -0
  169. package/.worktrees/2c37b1d7/src/stages/explore.js +43 -0
  170. package/.worktrees/2c37b1d7/src/stages/index.js +29 -0
  171. package/.worktrees/2c37b1d7/src/stages/knowledge.js +514 -0
  172. package/.worktrees/2c37b1d7/src/stages/plan-postcheck.js +1398 -0
  173. package/.worktrees/2c37b1d7/src/stages/plan.js +655 -0
  174. package/.worktrees/2c37b1d7/src/stages/quick.js +167 -0
  175. package/.worktrees/2c37b1d7/src/stages/scan.js +608 -0
  176. package/.worktrees/2c37b1d7/src/stages/status.js +64 -0
  177. package/.worktrees/2c37b1d7/src/stages/verify.js +246 -0
  178. package/.worktrees/2c37b1d7/src/sync.js +1470 -0
  179. package/.worktrees/2c37b1d7/src/task-review.js +1498 -0
  180. package/.worktrees/2c37b1d7/src/taskcard-placeholders.js +21 -0
  181. package/.worktrees/2c37b1d7/src/taskcard.js +250 -0
  182. package/.worktrees/2c37b1d7/src/verify-postcheck.js +1718 -0
  183. package/.worktrees/2c37b1d7/src/verify-probes.js +327 -0
  184. package/.worktrees/2c37b1d7/src/version.js +19 -0
  185. package/.worktrees/2c37b1d7/src/workflow.js +600 -0
  186. package/.worktrees/2c37b1d7/src/workspace.js +125 -0
  187. package/.worktrees/2c37b1d7/src/worktree-apply.js +1611 -0
  188. package/.worktrees/2c37b1d7/src/worktree-deps.js +668 -0
  189. package/.worktrees/2c37b1d7/src/worktree.js +1849 -0
  190. package/.worktrees/2c37b1d7/templates/claude-instruction.md +23 -0
  191. package/.worktrees/2c37b1d7/templates/prompts/taskcard-rules.md +29 -0
  192. package/.worktrees/2c37b1d7/templates/prompts/testcase-design.md +12 -0
  193. package/.worktrees/2c37b1d7/templates/prompts/verify-probes.md +32 -0
  194. package/.worktrees/2c37b1d7/templates/workflows/archive-impact.yaml +79 -0
  195. package/.worktrees/2c37b1d7/templates/workflows/scan-docs.yaml +132 -0
  196. package/.worktrees/542c4415/.claude/skills/sillyspec-archive/SKILL.md +87 -0
  197. package/.worktrees/542c4415/.claude/skills/sillyspec-auto/SKILL.md +93 -0
  198. package/.worktrees/542c4415/.claude/skills/sillyspec-brainstorm/SKILL.md +114 -0
  199. package/.worktrees/542c4415/.claude/skills/sillyspec-commit/SKILL.md +67 -0
  200. package/.worktrees/542c4415/.claude/skills/sillyspec-continue/SKILL.md +47 -0
  201. package/.worktrees/542c4415/.claude/skills/sillyspec-doctor/SKILL.md +76 -0
  202. package/.worktrees/542c4415/.claude/skills/sillyspec-execute/SKILL.md +214 -0
  203. package/.worktrees/542c4415/.claude/skills/sillyspec-explore/SKILL.md +102 -0
  204. package/.worktrees/542c4415/.claude/skills/sillyspec-export/SKILL.md +57 -0
  205. package/.worktrees/542c4415/.claude/skills/sillyspec-init/SKILL.md +177 -0
  206. package/.worktrees/542c4415/.claude/skills/sillyspec-knowledge/SKILL.md +270 -0
  207. package/.worktrees/542c4415/.claude/skills/sillyspec-plan/SKILL.md +156 -0
  208. package/.worktrees/542c4415/.claude/skills/sillyspec-quick/SKILL.md +116 -0
  209. package/.worktrees/542c4415/.claude/skills/sillyspec-resume/SKILL.md +70 -0
  210. package/.worktrees/542c4415/.claude/skills/sillyspec-scan/SKILL.md +79 -0
  211. package/.worktrees/542c4415/.claude/skills/sillyspec-state/SKILL.md +64 -0
  212. package/.worktrees/542c4415/.claude/skills/sillyspec-status/SKILL.md +54 -0
  213. package/.worktrees/542c4415/.claude/skills/sillyspec-verify/SKILL.md +87 -0
  214. package/.worktrees/542c4415/.claude/skills/sillyspec-workspace/SKILL.md +175 -0
  215. package/.worktrees/542c4415/.gitattributes +2 -0
  216. package/.worktrees/542c4415/.husky/pre-push +20 -0
  217. package/.worktrees/542c4415/README.md +203 -0
  218. package/.worktrees/542c4415/SKILL.md +91 -0
  219. package/.worktrees/542c4415/architecture-analysis.md +448 -0
  220. package/.worktrees/542c4415/bin/sillyspec.js +2 -0
  221. package/.worktrees/542c4415/eval/README.md +86 -0
  222. package/.worktrees/542c4415/eval/eval.config.json +28 -0
  223. package/.worktrees/542c4415/eval/lib/adapters/cli.mjs +63 -0
  224. package/.worktrees/542c4415/eval/lib/adapters/dryrun.mjs +27 -0
  225. package/.worktrees/542c4415/eval/lib/config.mjs +82 -0
  226. package/.worktrees/542c4415/eval/lib/db.mjs +76 -0
  227. package/.worktrees/542c4415/eval/lib/report.mjs +120 -0
  228. package/.worktrees/542c4415/eval/lib/runner.mjs +157 -0
  229. package/.worktrees/542c4415/eval/lib/tasks.mjs +73 -0
  230. package/.worktrees/542c4415/eval/lib/util.mjs +107 -0
  231. package/.worktrees/542c4415/eval/lib/workdir.mjs +30 -0
  232. package/.worktrees/542c4415/eval/run.mjs +83 -0
  233. package/.worktrees/542c4415/eval/tasks/001-slugify/files/package.json +6 -0
  234. package/.worktrees/542c4415/eval/tasks/001-slugify/solution/src/slugify.mjs +26 -0
  235. package/.worktrees/542c4415/eval/tasks/001-slugify/task.json +6 -0
  236. package/.worktrees/542c4415/eval/tasks/001-slugify/verify.mjs +28 -0
  237. package/.worktrees/542c4415/eval/tasks/002-each-day/files/package.json +6 -0
  238. package/.worktrees/542c4415/eval/tasks/002-each-day/files/src/dates.mjs +4 -0
  239. package/.worktrees/542c4415/eval/tasks/002-each-day/solution/src/dates.mjs +30 -0
  240. package/.worktrees/542c4415/eval/tasks/002-each-day/task.json +6 -0
  241. package/.worktrees/542c4415/eval/tasks/002-each-day/verify.mjs +31 -0
  242. package/.worktrees/542c4415/eval/tasks/003-word-report/files/data/notes.txt +5 -0
  243. package/.worktrees/542c4415/eval/tasks/003-word-report/files/package.json +6 -0
  244. package/.worktrees/542c4415/eval/tasks/003-word-report/solution/bin/report.mjs +36 -0
  245. package/.worktrees/542c4415/eval/tasks/003-word-report/task.json +6 -0
  246. package/.worktrees/542c4415/eval/tasks/003-word-report/verify.mjs +38 -0
  247. package/.worktrees/542c4415/logo.jpg +0 -0
  248. package/.worktrees/542c4415/package-lock.json +977 -0
  249. package/.worktrees/542c4415/package.json +41 -0
  250. package/.worktrees/542c4415/packages/dashboard/dist/assets/index-Bq_Z2hne.js +7446 -0
  251. package/.worktrees/542c4415/packages/dashboard/dist/assets/index-O2W5RV4z.css +1 -0
  252. package/.worktrees/542c4415/packages/dashboard/dist/favicon.jpg +0 -0
  253. package/.worktrees/542c4415/packages/dashboard/dist/index.html +16 -0
  254. package/.worktrees/542c4415/packages/dashboard/dist/logo.jpg +0 -0
  255. package/.worktrees/542c4415/packages/dashboard/dist/prototype-dashboard.html +836 -0
  256. package/.worktrees/542c4415/packages/dashboard/dist/prototype-overview.html +256 -0
  257. package/.worktrees/542c4415/packages/dashboard/package.json +25 -0
  258. package/.worktrees/542c4415/packages/dashboard/server/executor.js +95 -0
  259. package/.worktrees/542c4415/packages/dashboard/server/index.js +679 -0
  260. package/.worktrees/542c4415/packages/dashboard/server/parser.js +526 -0
  261. package/.worktrees/542c4415/packages/dashboard/server/watcher.js +357 -0
  262. package/.worktrees/542c4415/src/agent-session-log.js +803 -0
  263. package/.worktrees/542c4415/src/change-list.js +290 -0
  264. package/.worktrees/542c4415/src/change-risk-profile.js +339 -0
  265. package/.worktrees/542c4415/src/check-primitives.js +65 -0
  266. package/.worktrees/542c4415/src/classify-change.js +109 -0
  267. package/.worktrees/542c4415/src/commit-suggest.js +202 -0
  268. package/.worktrees/542c4415/src/config-cat.js +88 -0
  269. package/.worktrees/542c4415/src/config-schema.js +328 -0
  270. package/.worktrees/542c4415/src/constants.js +97 -0
  271. package/.worktrees/542c4415/src/contract-matrix.js +533 -0
  272. package/.worktrees/542c4415/src/datetime.js +20 -0
  273. package/.worktrees/542c4415/src/db-engine.js +55 -0
  274. package/.worktrees/542c4415/src/db.js +381 -0
  275. package/.worktrees/542c4415/src/decision-distill.js +517 -0
  276. package/.worktrees/542c4415/src/dispatch/backends/local-agent.js +155 -0
  277. package/.worktrees/542c4415/src/dispatch/backends/sillyhub-mcp.js +245 -0
  278. package/.worktrees/542c4415/src/dispatch/probe.js +246 -0
  279. package/.worktrees/542c4415/src/dispatch/strategy.js +121 -0
  280. package/.worktrees/542c4415/src/docs-check.js +825 -0
  281. package/.worktrees/542c4415/src/docs-debt.js +393 -0
  282. package/.worktrees/542c4415/src/docs-gate.js +107 -0
  283. package/.worktrees/542c4415/src/doctor-diagnostics.js +1099 -0
  284. package/.worktrees/542c4415/src/endpoint-extractor.js +409 -0
  285. package/.worktrees/542c4415/src/foreign-declared.js +155 -0
  286. package/.worktrees/542c4415/src/fs-atomic.js +73 -0
  287. package/.worktrees/542c4415/src/git-helper.js +150 -0
  288. package/.worktrees/542c4415/src/hooks/claude-pre-tool-use.cjs +130 -0
  289. package/.worktrees/542c4415/src/hooks/worktree-guard.js +892 -0
  290. package/.worktrees/542c4415/src/index.js +2854 -0
  291. package/.worktrees/542c4415/src/init.js +626 -0
  292. package/.worktrees/542c4415/src/knowledge-match.js +231 -0
  293. package/.worktrees/542c4415/src/local-detect.js +128 -0
  294. package/.worktrees/542c4415/src/local-register.js +104 -0
  295. package/.worktrees/542c4415/src/machine-interface.js +543 -0
  296. package/.worktrees/542c4415/src/migrate.js +127 -0
  297. package/.worktrees/542c4415/src/module-impact.js +166 -0
  298. package/.worktrees/542c4415/src/module-resolve.js +222 -0
  299. package/.worktrees/542c4415/src/modules.js +580 -0
  300. package/.worktrees/542c4415/src/plan-adopt-waves.js +126 -0
  301. package/.worktrees/542c4415/src/progress/change-registry.js +336 -0
  302. package/.worktrees/542c4415/src/progress/consistency-doctor.js +355 -0
  303. package/.worktrees/542c4415/src/progress/shared.js +36 -0
  304. package/.worktrees/542c4415/src/progress/stage-machine.js +594 -0
  305. package/.worktrees/542c4415/src/progress/step-store.js +265 -0
  306. package/.worktrees/542c4415/src/progress.js +1304 -0
  307. package/.worktrees/542c4415/src/quick-recommend.js +115 -0
  308. package/.worktrees/542c4415/src/quicklog.js +883 -0
  309. package/.worktrees/542c4415/src/review-tier.js +77 -0
  310. package/.worktrees/542c4415/src/run/command.js +1641 -0
  311. package/.worktrees/542c4415/src/run/complete-handlers.js +1552 -0
  312. package/.worktrees/542c4415/src/run/complete.js +1259 -0
  313. package/.worktrees/542c4415/src/run/concurrent-detect.js +156 -0
  314. package/.worktrees/542c4415/src/run/gates.js +1111 -0
  315. package/.worktrees/542c4415/src/run/multi-repo-context.js +208 -0
  316. package/.worktrees/542c4415/src/run/next.js +128 -0
  317. package/.worktrees/542c4415/src/run/prompt.js +843 -0
  318. package/.worktrees/542c4415/src/run/quick-audit.js +186 -0
  319. package/.worktrees/542c4415/src/run/scan-profile.js +269 -0
  320. package/.worktrees/542c4415/src/run/shared.js +1562 -0
  321. package/.worktrees/542c4415/src/run/stage.js +587 -0
  322. package/.worktrees/542c4415/src/run.js +23 -0
  323. package/.worktrees/542c4415/src/scan-diff.js +388 -0
  324. package/.worktrees/542c4415/src/scan-postcheck.js +524 -0
  325. package/.worktrees/542c4415/src/scan-staleness.js +95 -0
  326. package/.worktrees/542c4415/src/setup.js +414 -0
  327. package/.worktrees/542c4415/src/sillyhub-mcp/client.js +597 -0
  328. package/.worktrees/542c4415/src/sillyhub-mcp/config.js +62 -0
  329. package/.worktrees/542c4415/src/spec-dir-typo.js +50 -0
  330. package/.worktrees/542c4415/src/spec-sync.js +358 -0
  331. package/.worktrees/542c4415/src/stage-contract-engine.js +171 -0
  332. package/.worktrees/542c4415/src/stage-contract-spec.js +551 -0
  333. package/.worktrees/542c4415/src/stage-contract.js +948 -0
  334. package/.worktrees/542c4415/src/stage-review.js +597 -0
  335. package/.worktrees/542c4415/src/stages/archive.js +199 -0
  336. package/.worktrees/542c4415/src/stages/brainstorm-auto.js +285 -0
  337. package/.worktrees/542c4415/src/stages/brainstorm.js +624 -0
  338. package/.worktrees/542c4415/src/stages/cmd-existence.js +145 -0
  339. package/.worktrees/542c4415/src/stages/doctor.js +540 -0
  340. package/.worktrees/542c4415/src/stages/execute.js +1277 -0
  341. package/.worktrees/542c4415/src/stages/explore.js +43 -0
  342. package/.worktrees/542c4415/src/stages/index.js +29 -0
  343. package/.worktrees/542c4415/src/stages/knowledge.js +514 -0
  344. package/.worktrees/542c4415/src/stages/plan-postcheck.js +1398 -0
  345. package/.worktrees/542c4415/src/stages/plan.js +655 -0
  346. package/.worktrees/542c4415/src/stages/quick.js +167 -0
  347. package/.worktrees/542c4415/src/stages/scan.js +608 -0
  348. package/.worktrees/542c4415/src/stages/status.js +64 -0
  349. package/.worktrees/542c4415/src/stages/verify.js +246 -0
  350. package/.worktrees/542c4415/src/sync.js +1470 -0
  351. package/.worktrees/542c4415/src/task-review.js +1498 -0
  352. package/.worktrees/542c4415/src/taskcard-placeholders.js +21 -0
  353. package/.worktrees/542c4415/src/taskcard.js +250 -0
  354. package/.worktrees/542c4415/src/verify-postcheck.js +1718 -0
  355. package/.worktrees/542c4415/src/verify-probes.js +327 -0
  356. package/.worktrees/542c4415/src/version.js +19 -0
  357. package/.worktrees/542c4415/src/workflow.js +600 -0
  358. package/.worktrees/542c4415/src/workspace.js +125 -0
  359. package/.worktrees/542c4415/src/worktree-apply.js +1611 -0
  360. package/.worktrees/542c4415/src/worktree-deps.js +668 -0
  361. package/.worktrees/542c4415/src/worktree.js +1849 -0
  362. package/.worktrees/542c4415/templates/claude-instruction.md +23 -0
  363. package/.worktrees/542c4415/templates/prompts/taskcard-rules.md +29 -0
  364. package/.worktrees/542c4415/templates/prompts/testcase-design.md +12 -0
  365. package/.worktrees/542c4415/templates/prompts/verify-probes.md +32 -0
  366. package/.worktrees/542c4415/templates/workflows/archive-impact.yaml +79 -0
  367. package/.worktrees/542c4415/templates/workflows/scan-docs.yaml +132 -0
  368. package/.worktrees/8d2d0392/.claude/skills/sillyspec-archive/SKILL.md +87 -0
  369. package/.worktrees/8d2d0392/.claude/skills/sillyspec-auto/SKILL.md +93 -0
  370. package/.worktrees/8d2d0392/.claude/skills/sillyspec-brainstorm/SKILL.md +114 -0
  371. package/.worktrees/8d2d0392/.claude/skills/sillyspec-commit/SKILL.md +67 -0
  372. package/.worktrees/8d2d0392/.claude/skills/sillyspec-continue/SKILL.md +47 -0
  373. package/.worktrees/8d2d0392/.claude/skills/sillyspec-doctor/SKILL.md +76 -0
  374. package/.worktrees/8d2d0392/.claude/skills/sillyspec-execute/SKILL.md +214 -0
  375. package/.worktrees/8d2d0392/.claude/skills/sillyspec-explore/SKILL.md +102 -0
  376. package/.worktrees/8d2d0392/.claude/skills/sillyspec-export/SKILL.md +57 -0
  377. package/.worktrees/8d2d0392/.claude/skills/sillyspec-init/SKILL.md +177 -0
  378. package/.worktrees/8d2d0392/.claude/skills/sillyspec-knowledge/SKILL.md +270 -0
  379. package/.worktrees/8d2d0392/.claude/skills/sillyspec-plan/SKILL.md +156 -0
  380. package/.worktrees/8d2d0392/.claude/skills/sillyspec-propose/SKILL.md +87 -0
  381. package/.worktrees/8d2d0392/.claude/skills/sillyspec-quick/SKILL.md +116 -0
  382. package/.worktrees/8d2d0392/.claude/skills/sillyspec-resume/SKILL.md +70 -0
  383. package/.worktrees/8d2d0392/.claude/skills/sillyspec-scan/SKILL.md +79 -0
  384. package/.worktrees/8d2d0392/.claude/skills/sillyspec-state/SKILL.md +64 -0
  385. package/.worktrees/8d2d0392/.claude/skills/sillyspec-status/SKILL.md +54 -0
  386. package/.worktrees/8d2d0392/.claude/skills/sillyspec-verify/SKILL.md +87 -0
  387. package/.worktrees/8d2d0392/.claude/skills/sillyspec-workspace/SKILL.md +175 -0
  388. package/.worktrees/8d2d0392/.claude/skills/verify-per-user/SKILL.md +6 -0
  389. package/.worktrees/8d2d0392/.gitattributes +2 -0
  390. package/.worktrees/8d2d0392/.husky/pre-push +20 -0
  391. package/.worktrees/8d2d0392/README.md +203 -0
  392. package/.worktrees/8d2d0392/SKILL.md +91 -0
  393. package/.worktrees/8d2d0392/architecture-analysis.md +448 -0
  394. package/.worktrees/8d2d0392/bin/sillyspec.js +2 -0
  395. package/.worktrees/8d2d0392/eval/README.md +86 -0
  396. package/.worktrees/8d2d0392/eval/eval.config.json +28 -0
  397. package/.worktrees/8d2d0392/eval/lib/adapters/cli.mjs +63 -0
  398. package/.worktrees/8d2d0392/eval/lib/adapters/dryrun.mjs +27 -0
  399. package/.worktrees/8d2d0392/eval/lib/config.mjs +82 -0
  400. package/.worktrees/8d2d0392/eval/lib/db.mjs +76 -0
  401. package/.worktrees/8d2d0392/eval/lib/report.mjs +120 -0
  402. package/.worktrees/8d2d0392/eval/lib/runner.mjs +157 -0
  403. package/.worktrees/8d2d0392/eval/lib/tasks.mjs +73 -0
  404. package/.worktrees/8d2d0392/eval/lib/util.mjs +107 -0
  405. package/.worktrees/8d2d0392/eval/lib/workdir.mjs +30 -0
  406. package/.worktrees/8d2d0392/eval/run.mjs +83 -0
  407. package/.worktrees/8d2d0392/eval/tasks/001-slugify/files/package.json +6 -0
  408. package/.worktrees/8d2d0392/eval/tasks/001-slugify/solution/src/slugify.mjs +26 -0
  409. package/.worktrees/8d2d0392/eval/tasks/001-slugify/task.json +6 -0
  410. package/.worktrees/8d2d0392/eval/tasks/001-slugify/verify.mjs +28 -0
  411. package/.worktrees/8d2d0392/eval/tasks/002-each-day/files/package.json +6 -0
  412. package/.worktrees/8d2d0392/eval/tasks/002-each-day/files/src/dates.mjs +4 -0
  413. package/.worktrees/8d2d0392/eval/tasks/002-each-day/solution/src/dates.mjs +30 -0
  414. package/.worktrees/8d2d0392/eval/tasks/002-each-day/task.json +6 -0
  415. package/.worktrees/8d2d0392/eval/tasks/002-each-day/verify.mjs +31 -0
  416. package/.worktrees/8d2d0392/eval/tasks/003-word-report/files/data/notes.txt +5 -0
  417. package/.worktrees/8d2d0392/eval/tasks/003-word-report/files/package.json +6 -0
  418. package/.worktrees/8d2d0392/eval/tasks/003-word-report/solution/bin/report.mjs +36 -0
  419. package/.worktrees/8d2d0392/eval/tasks/003-word-report/task.json +6 -0
  420. package/.worktrees/8d2d0392/eval/tasks/003-word-report/verify.mjs +38 -0
  421. package/.worktrees/8d2d0392/logo.jpg +0 -0
  422. package/.worktrees/8d2d0392/package-lock.json +977 -0
  423. package/.worktrees/8d2d0392/package.json +41 -0
  424. package/.worktrees/8d2d0392/packages/dashboard/dist/assets/index-Bq_Z2hne.js +7446 -0
  425. package/.worktrees/8d2d0392/packages/dashboard/dist/assets/index-O2W5RV4z.css +1 -0
  426. package/.worktrees/8d2d0392/packages/dashboard/dist/favicon.jpg +0 -0
  427. package/.worktrees/8d2d0392/packages/dashboard/dist/index.html +16 -0
  428. package/.worktrees/8d2d0392/packages/dashboard/dist/logo.jpg +0 -0
  429. package/.worktrees/8d2d0392/packages/dashboard/dist/prototype-dashboard.html +836 -0
  430. package/.worktrees/8d2d0392/packages/dashboard/dist/prototype-overview.html +256 -0
  431. package/.worktrees/8d2d0392/packages/dashboard/package.json +25 -0
  432. package/.worktrees/8d2d0392/packages/dashboard/server/executor.js +95 -0
  433. package/.worktrees/8d2d0392/packages/dashboard/server/index.js +679 -0
  434. package/.worktrees/8d2d0392/packages/dashboard/server/parser.js +526 -0
  435. package/.worktrees/8d2d0392/packages/dashboard/server/watcher.js +357 -0
  436. package/.worktrees/8d2d0392/src/agent-session-log.js +803 -0
  437. package/.worktrees/8d2d0392/src/change-list.js +290 -0
  438. package/.worktrees/8d2d0392/src/change-risk-profile.js +339 -0
  439. package/.worktrees/8d2d0392/src/check-primitives.js +65 -0
  440. package/.worktrees/8d2d0392/src/classify-change.js +109 -0
  441. package/.worktrees/8d2d0392/src/commit-suggest.js +202 -0
  442. package/.worktrees/8d2d0392/src/config-cat.js +88 -0
  443. package/.worktrees/8d2d0392/src/config-schema.js +328 -0
  444. package/.worktrees/8d2d0392/src/constants.js +97 -0
  445. package/.worktrees/8d2d0392/src/contract-matrix.js +533 -0
  446. package/.worktrees/8d2d0392/src/datetime.js +20 -0
  447. package/.worktrees/8d2d0392/src/db-engine.js +55 -0
  448. package/.worktrees/8d2d0392/src/db.js +381 -0
  449. package/.worktrees/8d2d0392/src/decision-distill.js +517 -0
  450. package/.worktrees/8d2d0392/src/dispatch/backends/local-agent.js +155 -0
  451. package/.worktrees/8d2d0392/src/dispatch/backends/sillyhub-mcp.js +245 -0
  452. package/.worktrees/8d2d0392/src/dispatch/probe.js +246 -0
  453. package/.worktrees/8d2d0392/src/dispatch/strategy.js +121 -0
  454. package/.worktrees/8d2d0392/src/docs-check.js +825 -0
  455. package/.worktrees/8d2d0392/src/docs-debt.js +393 -0
  456. package/.worktrees/8d2d0392/src/docs-gate.js +107 -0
  457. package/.worktrees/8d2d0392/src/doctor-diagnostics.js +1099 -0
  458. package/.worktrees/8d2d0392/src/endpoint-extractor.js +409 -0
  459. package/.worktrees/8d2d0392/src/foreign-declared.js +78 -0
  460. package/.worktrees/8d2d0392/src/fs-atomic.js +73 -0
  461. package/.worktrees/8d2d0392/src/git-helper.js +150 -0
  462. package/.worktrees/8d2d0392/src/hooks/claude-pre-tool-use.cjs +130 -0
  463. package/.worktrees/8d2d0392/src/hooks/worktree-guard.js +892 -0
  464. package/.worktrees/8d2d0392/src/index.js +2854 -0
  465. package/.worktrees/8d2d0392/src/init.js +626 -0
  466. package/.worktrees/8d2d0392/src/knowledge-match.js +231 -0
  467. package/.worktrees/8d2d0392/src/local-detect.js +128 -0
  468. package/.worktrees/8d2d0392/src/local-register.js +104 -0
  469. package/.worktrees/8d2d0392/src/machine-interface.js +543 -0
  470. package/.worktrees/8d2d0392/src/migrate.js +127 -0
  471. package/.worktrees/8d2d0392/src/module-impact.js +166 -0
  472. package/.worktrees/8d2d0392/src/module-resolve.js +222 -0
  473. package/.worktrees/8d2d0392/src/modules.js +580 -0
  474. package/.worktrees/8d2d0392/src/plan-adopt-waves.js +126 -0
  475. package/.worktrees/8d2d0392/src/progress/change-registry.js +336 -0
  476. package/.worktrees/8d2d0392/src/progress/consistency-doctor.js +355 -0
  477. package/.worktrees/8d2d0392/src/progress/shared.js +36 -0
  478. package/.worktrees/8d2d0392/src/progress/stage-machine.js +594 -0
  479. package/.worktrees/8d2d0392/src/progress/step-store.js +265 -0
  480. package/.worktrees/8d2d0392/src/progress.js +1304 -0
  481. package/.worktrees/8d2d0392/src/quick-recommend.js +115 -0
  482. package/.worktrees/8d2d0392/src/quicklog.js +883 -0
  483. package/.worktrees/8d2d0392/src/review-tier.js +77 -0
  484. package/.worktrees/8d2d0392/src/run/command.js +1641 -0
  485. package/.worktrees/8d2d0392/src/run/complete-handlers.js +1552 -0
  486. package/.worktrees/8d2d0392/src/run/complete.js +1259 -0
  487. package/.worktrees/8d2d0392/src/run/concurrent-detect.js +156 -0
  488. package/.worktrees/8d2d0392/src/run/gates.js +1094 -0
  489. package/.worktrees/8d2d0392/src/run/multi-repo-context.js +208 -0
  490. package/.worktrees/8d2d0392/src/run/next.js +128 -0
  491. package/.worktrees/8d2d0392/src/run/prompt.js +843 -0
  492. package/.worktrees/8d2d0392/src/run/quick-audit.js +186 -0
  493. package/.worktrees/8d2d0392/src/run/scan-profile.js +269 -0
  494. package/.worktrees/8d2d0392/src/run/shared.js +1562 -0
  495. package/.worktrees/8d2d0392/src/run/stage.js +587 -0
  496. package/.worktrees/8d2d0392/src/run.js +23 -0
  497. package/.worktrees/8d2d0392/src/scan-diff.js +388 -0
  498. package/.worktrees/8d2d0392/src/scan-postcheck.js +524 -0
  499. package/.worktrees/8d2d0392/src/scan-staleness.js +95 -0
  500. package/.worktrees/8d2d0392/src/setup.js +414 -0
  501. package/.worktrees/8d2d0392/src/sillyhub-mcp/client.js +597 -0
  502. package/.worktrees/8d2d0392/src/sillyhub-mcp/config.js +62 -0
  503. package/.worktrees/8d2d0392/src/spec-dir-typo.js +50 -0
  504. package/.worktrees/8d2d0392/src/spec-sync.js +358 -0
  505. package/.worktrees/8d2d0392/src/stage-contract-engine.js +171 -0
  506. package/.worktrees/8d2d0392/src/stage-contract-spec.js +551 -0
  507. package/.worktrees/8d2d0392/src/stage-contract.js +948 -0
  508. package/.worktrees/8d2d0392/src/stage-review.js +597 -0
  509. package/.worktrees/8d2d0392/src/stages/archive.js +199 -0
  510. package/.worktrees/8d2d0392/src/stages/brainstorm-auto.js +285 -0
  511. package/.worktrees/8d2d0392/src/stages/brainstorm.js +624 -0
  512. package/.worktrees/8d2d0392/src/stages/cmd-existence.js +145 -0
  513. package/.worktrees/8d2d0392/src/stages/doctor.js +540 -0
  514. package/.worktrees/8d2d0392/src/stages/execute.js +1277 -0
  515. package/.worktrees/8d2d0392/src/stages/explore.js +43 -0
  516. package/.worktrees/8d2d0392/src/stages/index.js +29 -0
  517. package/.worktrees/8d2d0392/src/stages/knowledge.js +514 -0
  518. package/.worktrees/8d2d0392/src/stages/plan-postcheck.js +1398 -0
  519. package/.worktrees/8d2d0392/src/stages/plan.js +651 -0
  520. package/.worktrees/8d2d0392/src/stages/quick.js +167 -0
  521. package/.worktrees/8d2d0392/src/stages/scan.js +608 -0
  522. package/.worktrees/8d2d0392/src/stages/status.js +64 -0
  523. package/.worktrees/8d2d0392/src/stages/verify.js +246 -0
  524. package/.worktrees/8d2d0392/src/sync.js +1470 -0
  525. package/.worktrees/8d2d0392/src/task-review.js +1498 -0
  526. package/.worktrees/8d2d0392/src/taskcard-placeholders.js +21 -0
  527. package/.worktrees/8d2d0392/src/taskcard.js +217 -0
  528. package/.worktrees/8d2d0392/src/verify-postcheck.js +1718 -0
  529. package/.worktrees/8d2d0392/src/verify-probes.js +327 -0
  530. package/.worktrees/8d2d0392/src/version.js +19 -0
  531. package/.worktrees/8d2d0392/src/workflow.js +600 -0
  532. package/.worktrees/8d2d0392/src/workspace.js +125 -0
  533. package/.worktrees/8d2d0392/src/worktree-apply.js +1611 -0
  534. package/.worktrees/8d2d0392/src/worktree-deps.js +576 -0
  535. package/.worktrees/8d2d0392/src/worktree.js +1838 -0
  536. package/.worktrees/8d2d0392/templates/claude-instruction.md +23 -0
  537. package/.worktrees/8d2d0392/templates/prompts/taskcard-rules.md +29 -0
  538. package/.worktrees/8d2d0392/templates/prompts/testcase-design.md +12 -0
  539. package/.worktrees/8d2d0392/templates/prompts/verify-probes.md +32 -0
  540. package/.worktrees/8d2d0392/templates/workflows/archive-impact.yaml +79 -0
  541. package/.worktrees/8d2d0392/templates/workflows/scan-docs.yaml +132 -0
  542. package/.worktrees/c1eae35e/.claude/skills/sillyspec-archive/SKILL.md +87 -0
  543. package/.worktrees/c1eae35e/.claude/skills/sillyspec-auto/SKILL.md +93 -0
  544. package/.worktrees/c1eae35e/.claude/skills/sillyspec-brainstorm/SKILL.md +114 -0
  545. package/.worktrees/c1eae35e/.claude/skills/sillyspec-commit/SKILL.md +67 -0
  546. package/.worktrees/c1eae35e/.claude/skills/sillyspec-continue/SKILL.md +47 -0
  547. package/.worktrees/c1eae35e/.claude/skills/sillyspec-doctor/SKILL.md +76 -0
  548. package/.worktrees/c1eae35e/.claude/skills/sillyspec-execute/SKILL.md +214 -0
  549. package/.worktrees/c1eae35e/.claude/skills/sillyspec-explore/SKILL.md +102 -0
  550. package/.worktrees/c1eae35e/.claude/skills/sillyspec-export/SKILL.md +57 -0
  551. package/.worktrees/c1eae35e/.claude/skills/sillyspec-init/SKILL.md +177 -0
  552. package/.worktrees/c1eae35e/.claude/skills/sillyspec-knowledge/SKILL.md +270 -0
  553. package/.worktrees/c1eae35e/.claude/skills/sillyspec-plan/SKILL.md +156 -0
  554. package/.worktrees/c1eae35e/.claude/skills/sillyspec-quick/SKILL.md +116 -0
  555. package/.worktrees/c1eae35e/.claude/skills/sillyspec-resume/SKILL.md +70 -0
  556. package/.worktrees/c1eae35e/.claude/skills/sillyspec-scan/SKILL.md +79 -0
  557. package/.worktrees/c1eae35e/.claude/skills/sillyspec-state/SKILL.md +64 -0
  558. package/.worktrees/c1eae35e/.claude/skills/sillyspec-status/SKILL.md +54 -0
  559. package/.worktrees/c1eae35e/.claude/skills/sillyspec-verify/SKILL.md +87 -0
  560. package/.worktrees/c1eae35e/.claude/skills/sillyspec-workspace/SKILL.md +175 -0
  561. package/.worktrees/c1eae35e/.gitattributes +2 -0
  562. package/.worktrees/c1eae35e/.husky/pre-push +20 -0
  563. package/.worktrees/c1eae35e/README.md +203 -0
  564. package/.worktrees/c1eae35e/SKILL.md +91 -0
  565. package/.worktrees/c1eae35e/architecture-analysis.md +448 -0
  566. package/.worktrees/c1eae35e/bin/sillyspec.js +2 -0
  567. package/.worktrees/c1eae35e/eval/README.md +86 -0
  568. package/.worktrees/c1eae35e/eval/eval.config.json +28 -0
  569. package/.worktrees/c1eae35e/eval/lib/adapters/cli.mjs +63 -0
  570. package/.worktrees/c1eae35e/eval/lib/adapters/dryrun.mjs +27 -0
  571. package/.worktrees/c1eae35e/eval/lib/config.mjs +82 -0
  572. package/.worktrees/c1eae35e/eval/lib/db.mjs +76 -0
  573. package/.worktrees/c1eae35e/eval/lib/report.mjs +120 -0
  574. package/.worktrees/c1eae35e/eval/lib/runner.mjs +157 -0
  575. package/.worktrees/c1eae35e/eval/lib/tasks.mjs +73 -0
  576. package/.worktrees/c1eae35e/eval/lib/util.mjs +107 -0
  577. package/.worktrees/c1eae35e/eval/lib/workdir.mjs +30 -0
  578. package/.worktrees/c1eae35e/eval/run.mjs +83 -0
  579. package/.worktrees/c1eae35e/eval/tasks/001-slugify/files/package.json +6 -0
  580. package/.worktrees/c1eae35e/eval/tasks/001-slugify/solution/src/slugify.mjs +26 -0
  581. package/.worktrees/c1eae35e/eval/tasks/001-slugify/task.json +6 -0
  582. package/.worktrees/c1eae35e/eval/tasks/001-slugify/verify.mjs +28 -0
  583. package/.worktrees/c1eae35e/eval/tasks/002-each-day/files/package.json +6 -0
  584. package/.worktrees/c1eae35e/eval/tasks/002-each-day/files/src/dates.mjs +4 -0
  585. package/.worktrees/c1eae35e/eval/tasks/002-each-day/solution/src/dates.mjs +30 -0
  586. package/.worktrees/c1eae35e/eval/tasks/002-each-day/task.json +6 -0
  587. package/.worktrees/c1eae35e/eval/tasks/002-each-day/verify.mjs +31 -0
  588. package/.worktrees/c1eae35e/eval/tasks/003-word-report/files/data/notes.txt +5 -0
  589. package/.worktrees/c1eae35e/eval/tasks/003-word-report/files/package.json +6 -0
  590. package/.worktrees/c1eae35e/eval/tasks/003-word-report/solution/bin/report.mjs +36 -0
  591. package/.worktrees/c1eae35e/eval/tasks/003-word-report/task.json +6 -0
  592. package/.worktrees/c1eae35e/eval/tasks/003-word-report/verify.mjs +38 -0
  593. package/.worktrees/c1eae35e/logo.jpg +0 -0
  594. package/.worktrees/c1eae35e/package-lock.json +977 -0
  595. package/.worktrees/c1eae35e/package.json +41 -0
  596. package/.worktrees/c1eae35e/packages/dashboard/dist/assets/index-Bq_Z2hne.js +7446 -0
  597. package/.worktrees/c1eae35e/packages/dashboard/dist/assets/index-O2W5RV4z.css +1 -0
  598. package/.worktrees/c1eae35e/packages/dashboard/dist/favicon.jpg +0 -0
  599. package/.worktrees/c1eae35e/packages/dashboard/dist/index.html +16 -0
  600. package/.worktrees/c1eae35e/packages/dashboard/dist/logo.jpg +0 -0
  601. package/.worktrees/c1eae35e/packages/dashboard/dist/prototype-dashboard.html +836 -0
  602. package/.worktrees/c1eae35e/packages/dashboard/dist/prototype-overview.html +256 -0
  603. package/.worktrees/c1eae35e/packages/dashboard/package.json +25 -0
  604. package/.worktrees/c1eae35e/packages/dashboard/server/executor.js +95 -0
  605. package/.worktrees/c1eae35e/packages/dashboard/server/index.js +679 -0
  606. package/.worktrees/c1eae35e/packages/dashboard/server/parser.js +526 -0
  607. package/.worktrees/c1eae35e/packages/dashboard/server/watcher.js +357 -0
  608. package/.worktrees/c1eae35e/src/agent-session-log.js +803 -0
  609. package/.worktrees/c1eae35e/src/change-list.js +290 -0
  610. package/.worktrees/c1eae35e/src/change-risk-profile.js +339 -0
  611. package/.worktrees/c1eae35e/src/check-primitives.js +65 -0
  612. package/.worktrees/c1eae35e/src/classify-change.js +109 -0
  613. package/.worktrees/c1eae35e/src/commit-suggest.js +202 -0
  614. package/.worktrees/c1eae35e/src/config-cat.js +88 -0
  615. package/.worktrees/c1eae35e/src/config-schema.js +328 -0
  616. package/.worktrees/c1eae35e/src/constants.js +97 -0
  617. package/.worktrees/c1eae35e/src/contract-matrix.js +533 -0
  618. package/.worktrees/c1eae35e/src/datetime.js +20 -0
  619. package/.worktrees/c1eae35e/src/db-engine.js +55 -0
  620. package/.worktrees/c1eae35e/src/db.js +381 -0
  621. package/.worktrees/c1eae35e/src/decision-distill.js +517 -0
  622. package/.worktrees/c1eae35e/src/dispatch/backends/local-agent.js +155 -0
  623. package/.worktrees/c1eae35e/src/dispatch/backends/sillyhub-mcp.js +245 -0
  624. package/.worktrees/c1eae35e/src/dispatch/probe.js +246 -0
  625. package/.worktrees/c1eae35e/src/dispatch/strategy.js +121 -0
  626. package/.worktrees/c1eae35e/src/docs-check.js +825 -0
  627. package/.worktrees/c1eae35e/src/docs-debt.js +393 -0
  628. package/.worktrees/c1eae35e/src/docs-gate.js +107 -0
  629. package/.worktrees/c1eae35e/src/doctor-diagnostics.js +1099 -0
  630. package/.worktrees/c1eae35e/src/endpoint-extractor.js +409 -0
  631. package/.worktrees/c1eae35e/src/foreign-declared.js +155 -0
  632. package/.worktrees/c1eae35e/src/fs-atomic.js +73 -0
  633. package/.worktrees/c1eae35e/src/git-helper.js +150 -0
  634. package/.worktrees/c1eae35e/src/hooks/claude-pre-tool-use.cjs +130 -0
  635. package/.worktrees/c1eae35e/src/hooks/worktree-guard.js +892 -0
  636. package/.worktrees/c1eae35e/src/index.js +2854 -0
  637. package/.worktrees/c1eae35e/src/init.js +626 -0
  638. package/.worktrees/c1eae35e/src/knowledge-match.js +231 -0
  639. package/.worktrees/c1eae35e/src/local-detect.js +128 -0
  640. package/.worktrees/c1eae35e/src/local-register.js +104 -0
  641. package/.worktrees/c1eae35e/src/machine-interface.js +543 -0
  642. package/.worktrees/c1eae35e/src/migrate.js +127 -0
  643. package/.worktrees/c1eae35e/src/module-impact.js +166 -0
  644. package/.worktrees/c1eae35e/src/module-resolve.js +222 -0
  645. package/.worktrees/c1eae35e/src/modules.js +580 -0
  646. package/.worktrees/c1eae35e/src/plan-adopt-waves.js +126 -0
  647. package/.worktrees/c1eae35e/src/progress/change-registry.js +336 -0
  648. package/.worktrees/c1eae35e/src/progress/consistency-doctor.js +355 -0
  649. package/.worktrees/c1eae35e/src/progress/shared.js +36 -0
  650. package/.worktrees/c1eae35e/src/progress/stage-machine.js +594 -0
  651. package/.worktrees/c1eae35e/src/progress/step-store.js +265 -0
  652. package/.worktrees/c1eae35e/src/progress.js +1304 -0
  653. package/.worktrees/c1eae35e/src/quick-recommend.js +115 -0
  654. package/.worktrees/c1eae35e/src/quicklog.js +883 -0
  655. package/.worktrees/c1eae35e/src/review-tier.js +77 -0
  656. package/.worktrees/c1eae35e/src/run/command.js +1641 -0
  657. package/.worktrees/c1eae35e/src/run/complete-handlers.js +1552 -0
  658. package/.worktrees/c1eae35e/src/run/complete.js +1259 -0
  659. package/.worktrees/c1eae35e/src/run/concurrent-detect.js +156 -0
  660. package/.worktrees/c1eae35e/src/run/gates.js +1111 -0
  661. package/.worktrees/c1eae35e/src/run/multi-repo-context.js +208 -0
  662. package/.worktrees/c1eae35e/src/run/next.js +128 -0
  663. package/.worktrees/c1eae35e/src/run/prompt.js +843 -0
  664. package/.worktrees/c1eae35e/src/run/quick-audit.js +186 -0
  665. package/.worktrees/c1eae35e/src/run/scan-profile.js +269 -0
  666. package/.worktrees/c1eae35e/src/run/shared.js +1562 -0
  667. package/.worktrees/c1eae35e/src/run/stage.js +587 -0
  668. package/.worktrees/c1eae35e/src/run.js +23 -0
  669. package/.worktrees/c1eae35e/src/scan-diff.js +388 -0
  670. package/.worktrees/c1eae35e/src/scan-postcheck.js +524 -0
  671. package/.worktrees/c1eae35e/src/scan-staleness.js +95 -0
  672. package/.worktrees/c1eae35e/src/setup.js +414 -0
  673. package/.worktrees/c1eae35e/src/sillyhub-mcp/client.js +597 -0
  674. package/.worktrees/c1eae35e/src/sillyhub-mcp/config.js +62 -0
  675. package/.worktrees/c1eae35e/src/spec-dir-typo.js +50 -0
  676. package/.worktrees/c1eae35e/src/spec-sync.js +358 -0
  677. package/.worktrees/c1eae35e/src/stage-contract-engine.js +171 -0
  678. package/.worktrees/c1eae35e/src/stage-contract-spec.js +551 -0
  679. package/.worktrees/c1eae35e/src/stage-contract.js +948 -0
  680. package/.worktrees/c1eae35e/src/stage-review.js +597 -0
  681. package/.worktrees/c1eae35e/src/stages/archive.js +199 -0
  682. package/.worktrees/c1eae35e/src/stages/brainstorm-auto.js +285 -0
  683. package/.worktrees/c1eae35e/src/stages/brainstorm.js +624 -0
  684. package/.worktrees/c1eae35e/src/stages/cmd-existence.js +145 -0
  685. package/.worktrees/c1eae35e/src/stages/doctor.js +540 -0
  686. package/.worktrees/c1eae35e/src/stages/execute.js +1277 -0
  687. package/.worktrees/c1eae35e/src/stages/explore.js +43 -0
  688. package/.worktrees/c1eae35e/src/stages/index.js +29 -0
  689. package/.worktrees/c1eae35e/src/stages/knowledge.js +514 -0
  690. package/.worktrees/c1eae35e/src/stages/plan-postcheck.js +1398 -0
  691. package/.worktrees/c1eae35e/src/stages/plan.js +655 -0
  692. package/.worktrees/c1eae35e/src/stages/quick.js +167 -0
  693. package/.worktrees/c1eae35e/src/stages/scan.js +608 -0
  694. package/.worktrees/c1eae35e/src/stages/status.js +64 -0
  695. package/.worktrees/c1eae35e/src/stages/verify.js +246 -0
  696. package/.worktrees/c1eae35e/src/sync.js +1470 -0
  697. package/.worktrees/c1eae35e/src/task-review.js +1498 -0
  698. package/.worktrees/c1eae35e/src/taskcard-placeholders.js +21 -0
  699. package/.worktrees/c1eae35e/src/taskcard.js +250 -0
  700. package/.worktrees/c1eae35e/src/verify-postcheck.js +1718 -0
  701. package/.worktrees/c1eae35e/src/verify-probes.js +327 -0
  702. package/.worktrees/c1eae35e/src/version.js +19 -0
  703. package/.worktrees/c1eae35e/src/workflow.js +600 -0
  704. package/.worktrees/c1eae35e/src/workspace.js +125 -0
  705. package/.worktrees/c1eae35e/src/worktree-apply.js +1611 -0
  706. package/.worktrees/c1eae35e/src/worktree-deps.js +668 -0
  707. package/.worktrees/c1eae35e/src/worktree.js +1849 -0
  708. package/.worktrees/c1eae35e/templates/claude-instruction.md +23 -0
  709. package/.worktrees/c1eae35e/templates/prompts/taskcard-rules.md +29 -0
  710. package/.worktrees/c1eae35e/templates/prompts/testcase-design.md +12 -0
  711. package/.worktrees/c1eae35e/templates/prompts/verify-probes.md +32 -0
  712. package/.worktrees/c1eae35e/templates/workflows/archive-impact.yaml +79 -0
  713. package/.worktrees/c1eae35e/templates/workflows/scan-docs.yaml +132 -0
  714. package/.worktrees/dafc71ad/.claude/skills/sillyspec-archive/SKILL.md +87 -0
  715. package/.worktrees/dafc71ad/.claude/skills/sillyspec-auto/SKILL.md +93 -0
  716. package/.worktrees/dafc71ad/.claude/skills/sillyspec-brainstorm/SKILL.md +114 -0
  717. package/.worktrees/dafc71ad/.claude/skills/sillyspec-commit/SKILL.md +67 -0
  718. package/.worktrees/dafc71ad/.claude/skills/sillyspec-continue/SKILL.md +47 -0
  719. package/.worktrees/dafc71ad/.claude/skills/sillyspec-doctor/SKILL.md +76 -0
  720. package/.worktrees/dafc71ad/.claude/skills/sillyspec-execute/SKILL.md +214 -0
  721. package/.worktrees/dafc71ad/.claude/skills/sillyspec-explore/SKILL.md +102 -0
  722. package/.worktrees/dafc71ad/.claude/skills/sillyspec-export/SKILL.md +57 -0
  723. package/.worktrees/dafc71ad/.claude/skills/sillyspec-init/SKILL.md +177 -0
  724. package/.worktrees/dafc71ad/.claude/skills/sillyspec-knowledge/SKILL.md +270 -0
  725. package/.worktrees/dafc71ad/.claude/skills/sillyspec-plan/SKILL.md +156 -0
  726. package/.worktrees/dafc71ad/.claude/skills/sillyspec-propose/SKILL.md +87 -0
  727. package/.worktrees/dafc71ad/.claude/skills/sillyspec-quick/SKILL.md +116 -0
  728. package/.worktrees/dafc71ad/.claude/skills/sillyspec-resume/SKILL.md +70 -0
  729. package/.worktrees/dafc71ad/.claude/skills/sillyspec-scan/SKILL.md +79 -0
  730. package/.worktrees/dafc71ad/.claude/skills/sillyspec-state/SKILL.md +64 -0
  731. package/.worktrees/dafc71ad/.claude/skills/sillyspec-status/SKILL.md +54 -0
  732. package/.worktrees/dafc71ad/.claude/skills/sillyspec-verify/SKILL.md +87 -0
  733. package/.worktrees/dafc71ad/.claude/skills/sillyspec-workspace/SKILL.md +175 -0
  734. package/.worktrees/dafc71ad/.gitattributes +2 -0
  735. package/.worktrees/dafc71ad/.husky/pre-push +20 -0
  736. package/.worktrees/dafc71ad/README.md +203 -0
  737. package/.worktrees/dafc71ad/SKILL.md +91 -0
  738. package/.worktrees/dafc71ad/analysis.md +366 -0
  739. package/.worktrees/dafc71ad/architecture-analysis.md +448 -0
  740. package/.worktrees/dafc71ad/bin/sillyspec.js +2 -0
  741. package/.worktrees/dafc71ad/eval/README.md +86 -0
  742. package/.worktrees/dafc71ad/eval/eval.config.json +28 -0
  743. package/.worktrees/dafc71ad/eval/lib/adapters/cli.mjs +63 -0
  744. package/.worktrees/dafc71ad/eval/lib/adapters/dryrun.mjs +27 -0
  745. package/.worktrees/dafc71ad/eval/lib/config.mjs +82 -0
  746. package/.worktrees/dafc71ad/eval/lib/db.mjs +76 -0
  747. package/.worktrees/dafc71ad/eval/lib/report.mjs +120 -0
  748. package/.worktrees/dafc71ad/eval/lib/runner.mjs +157 -0
  749. package/.worktrees/dafc71ad/eval/lib/tasks.mjs +73 -0
  750. package/.worktrees/dafc71ad/eval/lib/util.mjs +107 -0
  751. package/.worktrees/dafc71ad/eval/lib/workdir.mjs +30 -0
  752. package/.worktrees/dafc71ad/eval/run.mjs +83 -0
  753. package/.worktrees/dafc71ad/eval/tasks/001-slugify/files/package.json +6 -0
  754. package/.worktrees/dafc71ad/eval/tasks/001-slugify/solution/src/slugify.mjs +26 -0
  755. package/.worktrees/dafc71ad/eval/tasks/001-slugify/task.json +6 -0
  756. package/.worktrees/dafc71ad/eval/tasks/001-slugify/verify.mjs +28 -0
  757. package/.worktrees/dafc71ad/eval/tasks/002-each-day/files/package.json +6 -0
  758. package/.worktrees/dafc71ad/eval/tasks/002-each-day/files/src/dates.mjs +4 -0
  759. package/.worktrees/dafc71ad/eval/tasks/002-each-day/solution/src/dates.mjs +30 -0
  760. package/.worktrees/dafc71ad/eval/tasks/002-each-day/task.json +6 -0
  761. package/.worktrees/dafc71ad/eval/tasks/002-each-day/verify.mjs +31 -0
  762. package/.worktrees/dafc71ad/eval/tasks/003-word-report/files/data/notes.txt +5 -0
  763. package/.worktrees/dafc71ad/eval/tasks/003-word-report/files/package.json +6 -0
  764. package/.worktrees/dafc71ad/eval/tasks/003-word-report/solution/bin/report.mjs +36 -0
  765. package/.worktrees/dafc71ad/eval/tasks/003-word-report/task.json +6 -0
  766. package/.worktrees/dafc71ad/eval/tasks/003-word-report/verify.mjs +38 -0
  767. package/.worktrees/dafc71ad/logo.jpg +0 -0
  768. package/.worktrees/dafc71ad/package-lock.json +977 -0
  769. package/.worktrees/dafc71ad/package.json +41 -0
  770. package/.worktrees/dafc71ad/packages/dashboard/dist/assets/index-Bq_Z2hne.js +7446 -0
  771. package/.worktrees/dafc71ad/packages/dashboard/dist/assets/index-O2W5RV4z.css +1 -0
  772. package/.worktrees/dafc71ad/packages/dashboard/dist/favicon.jpg +0 -0
  773. package/.worktrees/dafc71ad/packages/dashboard/dist/index.html +16 -0
  774. package/.worktrees/dafc71ad/packages/dashboard/dist/logo.jpg +0 -0
  775. package/.worktrees/dafc71ad/packages/dashboard/dist/prototype-dashboard.html +836 -0
  776. package/.worktrees/dafc71ad/packages/dashboard/dist/prototype-overview.html +256 -0
  777. package/.worktrees/dafc71ad/packages/dashboard/package.json +25 -0
  778. package/.worktrees/dafc71ad/packages/dashboard/server/executor.js +95 -0
  779. package/.worktrees/dafc71ad/packages/dashboard/server/index.js +679 -0
  780. package/.worktrees/dafc71ad/packages/dashboard/server/parser.js +526 -0
  781. package/.worktrees/dafc71ad/packages/dashboard/server/watcher.js +357 -0
  782. package/.worktrees/dafc71ad/src/agent-session-log.js +803 -0
  783. package/.worktrees/dafc71ad/src/change-list.js +290 -0
  784. package/.worktrees/dafc71ad/src/change-risk-profile.js +339 -0
  785. package/.worktrees/dafc71ad/src/check-primitives.js +65 -0
  786. package/.worktrees/dafc71ad/src/classify-change.js +109 -0
  787. package/.worktrees/dafc71ad/src/commit-suggest.js +202 -0
  788. package/.worktrees/dafc71ad/src/config-cat.js +88 -0
  789. package/.worktrees/dafc71ad/src/config-schema.js +328 -0
  790. package/.worktrees/dafc71ad/src/constants.js +97 -0
  791. package/.worktrees/dafc71ad/src/contract-matrix.js +533 -0
  792. package/.worktrees/dafc71ad/src/datetime.js +20 -0
  793. package/.worktrees/dafc71ad/src/db-engine.js +55 -0
  794. package/.worktrees/dafc71ad/src/db.js +381 -0
  795. package/.worktrees/dafc71ad/src/decision-distill.js +517 -0
  796. package/.worktrees/dafc71ad/src/dispatch/backends/local-agent.js +155 -0
  797. package/.worktrees/dafc71ad/src/dispatch/backends/sillyhub-mcp.js +245 -0
  798. package/.worktrees/dafc71ad/src/dispatch/probe.js +246 -0
  799. package/.worktrees/dafc71ad/src/dispatch/strategy.js +121 -0
  800. package/.worktrees/dafc71ad/src/docs-check.js +825 -0
  801. package/.worktrees/dafc71ad/src/docs-debt.js +393 -0
  802. package/.worktrees/dafc71ad/src/docs-gate.js +107 -0
  803. package/.worktrees/dafc71ad/src/doctor-diagnostics.js +1099 -0
  804. package/.worktrees/dafc71ad/src/endpoint-extractor.js +409 -0
  805. package/.worktrees/dafc71ad/src/foreign-declared.js +155 -0
  806. package/.worktrees/dafc71ad/src/fs-atomic.js +73 -0
  807. package/.worktrees/dafc71ad/src/git-helper.js +150 -0
  808. package/.worktrees/dafc71ad/src/hooks/claude-pre-tool-use.cjs +130 -0
  809. package/.worktrees/dafc71ad/src/hooks/worktree-guard.js +892 -0
  810. package/.worktrees/dafc71ad/src/index.js +2854 -0
  811. package/.worktrees/dafc71ad/src/init.js +626 -0
  812. package/.worktrees/dafc71ad/src/knowledge-match.js +231 -0
  813. package/.worktrees/dafc71ad/src/local-detect.js +128 -0
  814. package/.worktrees/dafc71ad/src/local-register.js +104 -0
  815. package/.worktrees/dafc71ad/src/machine-interface.js +543 -0
  816. package/.worktrees/dafc71ad/src/migrate.js +127 -0
  817. package/.worktrees/dafc71ad/src/module-impact.js +166 -0
  818. package/.worktrees/dafc71ad/src/module-resolve.js +222 -0
  819. package/.worktrees/dafc71ad/src/modules.js +580 -0
  820. package/.worktrees/dafc71ad/src/plan-adopt-waves.js +126 -0
  821. package/.worktrees/dafc71ad/src/progress/change-registry.js +336 -0
  822. package/.worktrees/dafc71ad/src/progress/consistency-doctor.js +355 -0
  823. package/.worktrees/dafc71ad/src/progress/shared.js +36 -0
  824. package/.worktrees/dafc71ad/src/progress/stage-machine.js +594 -0
  825. package/.worktrees/dafc71ad/src/progress/step-store.js +265 -0
  826. package/.worktrees/dafc71ad/src/progress.js +1304 -0
  827. package/.worktrees/dafc71ad/src/quick-recommend.js +115 -0
  828. package/.worktrees/dafc71ad/src/quicklog.js +883 -0
  829. package/.worktrees/dafc71ad/src/review-tier.js +77 -0
  830. package/.worktrees/dafc71ad/src/run/command.js +1641 -0
  831. package/.worktrees/dafc71ad/src/run/complete-handlers.js +1552 -0
  832. package/.worktrees/dafc71ad/src/run/complete.js +1259 -0
  833. package/.worktrees/dafc71ad/src/run/concurrent-detect.js +156 -0
  834. package/.worktrees/dafc71ad/src/run/gates.js +1111 -0
  835. package/.worktrees/dafc71ad/src/run/multi-repo-context.js +208 -0
  836. package/.worktrees/dafc71ad/src/run/next.js +128 -0
  837. package/.worktrees/dafc71ad/src/run/prompt.js +843 -0
  838. package/.worktrees/dafc71ad/src/run/quick-audit.js +186 -0
  839. package/.worktrees/dafc71ad/src/run/scan-profile.js +269 -0
  840. package/.worktrees/dafc71ad/src/run/shared.js +1562 -0
  841. package/.worktrees/dafc71ad/src/run/stage.js +587 -0
  842. package/.worktrees/dafc71ad/src/run.js +23 -0
  843. package/.worktrees/dafc71ad/src/scan-diff.js +388 -0
  844. package/.worktrees/dafc71ad/src/scan-postcheck.js +524 -0
  845. package/.worktrees/dafc71ad/src/scan-staleness.js +95 -0
  846. package/.worktrees/dafc71ad/src/setup.js +414 -0
  847. package/.worktrees/dafc71ad/src/sillyhub-mcp/client.js +597 -0
  848. package/.worktrees/dafc71ad/src/sillyhub-mcp/config.js +62 -0
  849. package/.worktrees/dafc71ad/src/spec-dir-typo.js +50 -0
  850. package/.worktrees/dafc71ad/src/spec-sync.js +358 -0
  851. package/.worktrees/dafc71ad/src/stage-contract-engine.js +171 -0
  852. package/.worktrees/dafc71ad/src/stage-contract-spec.js +551 -0
  853. package/.worktrees/dafc71ad/src/stage-contract.js +948 -0
  854. package/.worktrees/dafc71ad/src/stage-review.js +597 -0
  855. package/.worktrees/dafc71ad/src/stages/archive.js +199 -0
  856. package/.worktrees/dafc71ad/src/stages/brainstorm-auto.js +285 -0
  857. package/.worktrees/dafc71ad/src/stages/brainstorm.js +624 -0
  858. package/.worktrees/dafc71ad/src/stages/cmd-existence.js +145 -0
  859. package/.worktrees/dafc71ad/src/stages/doctor.js +540 -0
  860. package/.worktrees/dafc71ad/src/stages/execute.js +1277 -0
  861. package/.worktrees/dafc71ad/src/stages/explore.js +43 -0
  862. package/.worktrees/dafc71ad/src/stages/index.js +29 -0
  863. package/.worktrees/dafc71ad/src/stages/knowledge.js +514 -0
  864. package/.worktrees/dafc71ad/src/stages/plan-postcheck.js +1398 -0
  865. package/.worktrees/dafc71ad/src/stages/plan.js +655 -0
  866. package/.worktrees/dafc71ad/src/stages/quick.js +167 -0
  867. package/.worktrees/dafc71ad/src/stages/scan.js +608 -0
  868. package/.worktrees/dafc71ad/src/stages/status.js +64 -0
  869. package/.worktrees/dafc71ad/src/stages/verify.js +246 -0
  870. package/.worktrees/dafc71ad/src/sync.js +1470 -0
  871. package/.worktrees/dafc71ad/src/task-review.js +1498 -0
  872. package/.worktrees/dafc71ad/src/taskcard-placeholders.js +21 -0
  873. package/.worktrees/dafc71ad/src/taskcard.js +250 -0
  874. package/.worktrees/dafc71ad/src/verify-postcheck.js +1718 -0
  875. package/.worktrees/dafc71ad/src/verify-probes.js +327 -0
  876. package/.worktrees/dafc71ad/src/version.js +19 -0
  877. package/.worktrees/dafc71ad/src/workflow.js +600 -0
  878. package/.worktrees/dafc71ad/src/workspace.js +125 -0
  879. package/.worktrees/dafc71ad/src/worktree-apply.js +1611 -0
  880. package/.worktrees/dafc71ad/src/worktree-deps.js +668 -0
  881. package/.worktrees/dafc71ad/src/worktree.js +1849 -0
  882. package/.worktrees/dafc71ad/templates/claude-instruction.md +23 -0
  883. package/.worktrees/dafc71ad/templates/prompts/taskcard-rules.md +29 -0
  884. package/.worktrees/dafc71ad/templates/prompts/testcase-design.md +12 -0
  885. package/.worktrees/dafc71ad/templates/prompts/verify-probes.md +32 -0
  886. package/.worktrees/dafc71ad/templates/workflows/archive-impact.yaml +79 -0
  887. package/.worktrees/dafc71ad/templates/workflows/scan-docs.yaml +132 -0
  888. package/.worktrees/e58fcc4c/.claude/skills/sillyspec-archive/SKILL.md +87 -0
  889. package/.worktrees/e58fcc4c/.claude/skills/sillyspec-auto/SKILL.md +93 -0
  890. package/.worktrees/e58fcc4c/.claude/skills/sillyspec-brainstorm/SKILL.md +114 -0
  891. package/.worktrees/e58fcc4c/.claude/skills/sillyspec-commit/SKILL.md +67 -0
  892. package/.worktrees/e58fcc4c/.claude/skills/sillyspec-continue/SKILL.md +47 -0
  893. package/.worktrees/e58fcc4c/.claude/skills/sillyspec-doctor/SKILL.md +76 -0
  894. package/.worktrees/e58fcc4c/.claude/skills/sillyspec-execute/SKILL.md +214 -0
  895. package/.worktrees/e58fcc4c/.claude/skills/sillyspec-explore/SKILL.md +102 -0
  896. package/.worktrees/e58fcc4c/.claude/skills/sillyspec-export/SKILL.md +57 -0
  897. package/.worktrees/e58fcc4c/.claude/skills/sillyspec-init/SKILL.md +177 -0
  898. package/.worktrees/e58fcc4c/.claude/skills/sillyspec-knowledge/SKILL.md +270 -0
  899. package/.worktrees/e58fcc4c/.claude/skills/sillyspec-plan/SKILL.md +156 -0
  900. package/.worktrees/e58fcc4c/.claude/skills/sillyspec-propose/SKILL.md +87 -0
  901. package/.worktrees/e58fcc4c/.claude/skills/sillyspec-quick/SKILL.md +116 -0
  902. package/.worktrees/e58fcc4c/.claude/skills/sillyspec-resume/SKILL.md +70 -0
  903. package/.worktrees/e58fcc4c/.claude/skills/sillyspec-scan/SKILL.md +79 -0
  904. package/.worktrees/e58fcc4c/.claude/skills/sillyspec-state/SKILL.md +64 -0
  905. package/.worktrees/e58fcc4c/.claude/skills/sillyspec-status/SKILL.md +54 -0
  906. package/.worktrees/e58fcc4c/.claude/skills/sillyspec-verify/SKILL.md +87 -0
  907. package/.worktrees/e58fcc4c/.claude/skills/sillyspec-workspace/SKILL.md +175 -0
  908. package/.worktrees/e58fcc4c/.gitattributes +2 -0
  909. package/.worktrees/e58fcc4c/.husky/pre-push +20 -0
  910. package/.worktrees/e58fcc4c/README.md +203 -0
  911. package/.worktrees/e58fcc4c/SKILL.md +91 -0
  912. package/.worktrees/e58fcc4c/architecture-analysis.md +503 -0
  913. package/.worktrees/e58fcc4c/bin/sillyspec.js +2 -0
  914. package/.worktrees/e58fcc4c/eval/README.md +86 -0
  915. package/.worktrees/e58fcc4c/eval/eval.config.json +28 -0
  916. package/.worktrees/e58fcc4c/eval/lib/adapters/cli.mjs +63 -0
  917. package/.worktrees/e58fcc4c/eval/lib/adapters/dryrun.mjs +27 -0
  918. package/.worktrees/e58fcc4c/eval/lib/config.mjs +82 -0
  919. package/.worktrees/e58fcc4c/eval/lib/db.mjs +76 -0
  920. package/.worktrees/e58fcc4c/eval/lib/report.mjs +120 -0
  921. package/.worktrees/e58fcc4c/eval/lib/runner.mjs +157 -0
  922. package/.worktrees/e58fcc4c/eval/lib/tasks.mjs +73 -0
  923. package/.worktrees/e58fcc4c/eval/lib/util.mjs +107 -0
  924. package/.worktrees/e58fcc4c/eval/lib/workdir.mjs +30 -0
  925. package/.worktrees/e58fcc4c/eval/run.mjs +83 -0
  926. package/.worktrees/e58fcc4c/eval/tasks/001-slugify/files/package.json +6 -0
  927. package/.worktrees/e58fcc4c/eval/tasks/001-slugify/solution/src/slugify.mjs +26 -0
  928. package/.worktrees/e58fcc4c/eval/tasks/001-slugify/task.json +6 -0
  929. package/.worktrees/e58fcc4c/eval/tasks/001-slugify/verify.mjs +28 -0
  930. package/.worktrees/e58fcc4c/eval/tasks/002-each-day/files/package.json +6 -0
  931. package/.worktrees/e58fcc4c/eval/tasks/002-each-day/files/src/dates.mjs +4 -0
  932. package/.worktrees/e58fcc4c/eval/tasks/002-each-day/solution/src/dates.mjs +30 -0
  933. package/.worktrees/e58fcc4c/eval/tasks/002-each-day/task.json +6 -0
  934. package/.worktrees/e58fcc4c/eval/tasks/002-each-day/verify.mjs +31 -0
  935. package/.worktrees/e58fcc4c/eval/tasks/003-word-report/files/data/notes.txt +5 -0
  936. package/.worktrees/e58fcc4c/eval/tasks/003-word-report/files/package.json +6 -0
  937. package/.worktrees/e58fcc4c/eval/tasks/003-word-report/solution/bin/report.mjs +36 -0
  938. package/.worktrees/e58fcc4c/eval/tasks/003-word-report/task.json +6 -0
  939. package/.worktrees/e58fcc4c/eval/tasks/003-word-report/verify.mjs +38 -0
  940. package/.worktrees/e58fcc4c/logo.jpg +0 -0
  941. package/.worktrees/e58fcc4c/package-lock.json +977 -0
  942. package/.worktrees/e58fcc4c/package.json +41 -0
  943. package/.worktrees/e58fcc4c/packages/dashboard/dist/assets/index-Bq_Z2hne.js +7446 -0
  944. package/.worktrees/e58fcc4c/packages/dashboard/dist/assets/index-O2W5RV4z.css +1 -0
  945. package/.worktrees/e58fcc4c/packages/dashboard/dist/favicon.jpg +0 -0
  946. package/.worktrees/e58fcc4c/packages/dashboard/dist/index.html +16 -0
  947. package/.worktrees/e58fcc4c/packages/dashboard/dist/logo.jpg +0 -0
  948. package/.worktrees/e58fcc4c/packages/dashboard/dist/prototype-dashboard.html +836 -0
  949. package/.worktrees/e58fcc4c/packages/dashboard/dist/prototype-overview.html +256 -0
  950. package/.worktrees/e58fcc4c/packages/dashboard/package.json +25 -0
  951. package/.worktrees/e58fcc4c/packages/dashboard/server/executor.js +95 -0
  952. package/.worktrees/e58fcc4c/packages/dashboard/server/index.js +679 -0
  953. package/.worktrees/e58fcc4c/packages/dashboard/server/parser.js +526 -0
  954. package/.worktrees/e58fcc4c/packages/dashboard/server/watcher.js +357 -0
  955. package/.worktrees/e58fcc4c/src/agent-session-log.js +803 -0
  956. package/.worktrees/e58fcc4c/src/change-list.js +290 -0
  957. package/.worktrees/e58fcc4c/src/change-risk-profile.js +339 -0
  958. package/.worktrees/e58fcc4c/src/check-primitives.js +65 -0
  959. package/.worktrees/e58fcc4c/src/classify-change.js +109 -0
  960. package/.worktrees/e58fcc4c/src/commit-suggest.js +202 -0
  961. package/.worktrees/e58fcc4c/src/config-cat.js +88 -0
  962. package/.worktrees/e58fcc4c/src/config-schema.js +328 -0
  963. package/.worktrees/e58fcc4c/src/constants.js +97 -0
  964. package/.worktrees/e58fcc4c/src/contract-matrix.js +533 -0
  965. package/.worktrees/e58fcc4c/src/datetime.js +20 -0
  966. package/.worktrees/e58fcc4c/src/db-engine.js +55 -0
  967. package/.worktrees/e58fcc4c/src/db.js +381 -0
  968. package/.worktrees/e58fcc4c/src/decision-distill.js +517 -0
  969. package/.worktrees/e58fcc4c/src/dispatch/backends/local-agent.js +155 -0
  970. package/.worktrees/e58fcc4c/src/dispatch/backends/sillyhub-mcp.js +245 -0
  971. package/.worktrees/e58fcc4c/src/dispatch/probe.js +246 -0
  972. package/.worktrees/e58fcc4c/src/dispatch/strategy.js +121 -0
  973. package/.worktrees/e58fcc4c/src/docs-check.js +825 -0
  974. package/.worktrees/e58fcc4c/src/docs-debt.js +393 -0
  975. package/.worktrees/e58fcc4c/src/docs-gate.js +107 -0
  976. package/.worktrees/e58fcc4c/src/doctor-diagnostics.js +1099 -0
  977. package/.worktrees/e58fcc4c/src/endpoint-extractor.js +409 -0
  978. package/.worktrees/e58fcc4c/src/foreign-declared.js +155 -0
  979. package/.worktrees/e58fcc4c/src/fs-atomic.js +73 -0
  980. package/.worktrees/e58fcc4c/src/git-helper.js +150 -0
  981. package/.worktrees/e58fcc4c/src/hooks/claude-pre-tool-use.cjs +130 -0
  982. package/.worktrees/e58fcc4c/src/hooks/worktree-guard.js +892 -0
  983. package/.worktrees/e58fcc4c/src/index.js +2854 -0
  984. package/.worktrees/e58fcc4c/src/init.js +626 -0
  985. package/.worktrees/e58fcc4c/src/knowledge-match.js +231 -0
  986. package/.worktrees/e58fcc4c/src/local-detect.js +128 -0
  987. package/.worktrees/e58fcc4c/src/local-register.js +104 -0
  988. package/.worktrees/e58fcc4c/src/machine-interface.js +543 -0
  989. package/.worktrees/e58fcc4c/src/migrate.js +127 -0
  990. package/.worktrees/e58fcc4c/src/module-impact.js +166 -0
  991. package/.worktrees/e58fcc4c/src/module-resolve.js +222 -0
  992. package/.worktrees/e58fcc4c/src/modules.js +580 -0
  993. package/.worktrees/e58fcc4c/src/plan-adopt-waves.js +126 -0
  994. package/.worktrees/e58fcc4c/src/progress/change-registry.js +336 -0
  995. package/.worktrees/e58fcc4c/src/progress/consistency-doctor.js +355 -0
  996. package/.worktrees/e58fcc4c/src/progress/shared.js +36 -0
  997. package/.worktrees/e58fcc4c/src/progress/stage-machine.js +594 -0
  998. package/.worktrees/e58fcc4c/src/progress/step-store.js +265 -0
  999. package/.worktrees/e58fcc4c/src/progress.js +1304 -0
  1000. package/.worktrees/e58fcc4c/src/quick-recommend.js +115 -0
  1001. package/.worktrees/e58fcc4c/src/quicklog.js +883 -0
  1002. package/.worktrees/e58fcc4c/src/review-tier.js +77 -0
  1003. package/.worktrees/e58fcc4c/src/run/command.js +1641 -0
  1004. package/.worktrees/e58fcc4c/src/run/complete-handlers.js +1552 -0
  1005. package/.worktrees/e58fcc4c/src/run/complete.js +1259 -0
  1006. package/.worktrees/e58fcc4c/src/run/concurrent-detect.js +156 -0
  1007. package/.worktrees/e58fcc4c/src/run/gates.js +1111 -0
  1008. package/.worktrees/e58fcc4c/src/run/multi-repo-context.js +208 -0
  1009. package/.worktrees/e58fcc4c/src/run/next.js +128 -0
  1010. package/.worktrees/e58fcc4c/src/run/prompt.js +843 -0
  1011. package/.worktrees/e58fcc4c/src/run/quick-audit.js +186 -0
  1012. package/.worktrees/e58fcc4c/src/run/scan-profile.js +269 -0
  1013. package/.worktrees/e58fcc4c/src/run/shared.js +1562 -0
  1014. package/.worktrees/e58fcc4c/src/run/stage.js +587 -0
  1015. package/.worktrees/e58fcc4c/src/run.js +23 -0
  1016. package/.worktrees/e58fcc4c/src/scan-diff.js +388 -0
  1017. package/.worktrees/e58fcc4c/src/scan-postcheck.js +524 -0
  1018. package/.worktrees/e58fcc4c/src/scan-staleness.js +95 -0
  1019. package/.worktrees/e58fcc4c/src/setup.js +414 -0
  1020. package/.worktrees/e58fcc4c/src/sillyhub-mcp/client.js +597 -0
  1021. package/.worktrees/e58fcc4c/src/sillyhub-mcp/config.js +62 -0
  1022. package/.worktrees/e58fcc4c/src/spec-dir-typo.js +50 -0
  1023. package/.worktrees/e58fcc4c/src/spec-sync.js +358 -0
  1024. package/.worktrees/e58fcc4c/src/stage-contract-engine.js +171 -0
  1025. package/.worktrees/e58fcc4c/src/stage-contract-spec.js +551 -0
  1026. package/.worktrees/e58fcc4c/src/stage-contract.js +948 -0
  1027. package/.worktrees/e58fcc4c/src/stage-review.js +597 -0
  1028. package/.worktrees/e58fcc4c/src/stages/archive.js +199 -0
  1029. package/.worktrees/e58fcc4c/src/stages/brainstorm-auto.js +285 -0
  1030. package/.worktrees/e58fcc4c/src/stages/brainstorm.js +624 -0
  1031. package/.worktrees/e58fcc4c/src/stages/cmd-existence.js +145 -0
  1032. package/.worktrees/e58fcc4c/src/stages/doctor.js +540 -0
  1033. package/.worktrees/e58fcc4c/src/stages/execute.js +1277 -0
  1034. package/.worktrees/e58fcc4c/src/stages/explore.js +43 -0
  1035. package/.worktrees/e58fcc4c/src/stages/index.js +29 -0
  1036. package/.worktrees/e58fcc4c/src/stages/knowledge.js +514 -0
  1037. package/.worktrees/e58fcc4c/src/stages/plan-postcheck.js +1398 -0
  1038. package/.worktrees/e58fcc4c/src/stages/plan.js +655 -0
  1039. package/.worktrees/e58fcc4c/src/stages/quick.js +167 -0
  1040. package/.worktrees/e58fcc4c/src/stages/scan.js +608 -0
  1041. package/.worktrees/e58fcc4c/src/stages/status.js +64 -0
  1042. package/.worktrees/e58fcc4c/src/stages/verify.js +246 -0
  1043. package/.worktrees/e58fcc4c/src/sync.js +1470 -0
  1044. package/.worktrees/e58fcc4c/src/task-review.js +1498 -0
  1045. package/.worktrees/e58fcc4c/src/taskcard-placeholders.js +21 -0
  1046. package/.worktrees/e58fcc4c/src/taskcard.js +250 -0
  1047. package/.worktrees/e58fcc4c/src/verify-postcheck.js +1718 -0
  1048. package/.worktrees/e58fcc4c/src/verify-probes.js +327 -0
  1049. package/.worktrees/e58fcc4c/src/version.js +19 -0
  1050. package/.worktrees/e58fcc4c/src/workflow.js +600 -0
  1051. package/.worktrees/e58fcc4c/src/workspace.js +125 -0
  1052. package/.worktrees/e58fcc4c/src/worktree-apply.js +1611 -0
  1053. package/.worktrees/e58fcc4c/src/worktree-deps.js +668 -0
  1054. package/.worktrees/e58fcc4c/src/worktree.js +1849 -0
  1055. package/.worktrees/e58fcc4c/templates/claude-instruction.md +23 -0
  1056. package/.worktrees/e58fcc4c/templates/prompts/taskcard-rules.md +29 -0
  1057. package/.worktrees/e58fcc4c/templates/prompts/testcase-design.md +12 -0
  1058. package/.worktrees/e58fcc4c/templates/prompts/verify-probes.md +32 -0
  1059. package/.worktrees/e58fcc4c/templates/workflows/archive-impact.yaml +79 -0
  1060. package/.worktrees/e58fcc4c/templates/workflows/scan-docs.yaml +132 -0
  1061. package/architecture-analysis.md +448 -0
  1062. package/package.json +1 -1
  1063. package/src/contract-matrix.js +7 -4
  1064. package/src/endpoint-extractor.js +41 -52
  1065. package/src/foreign-declared.js +88 -5
  1066. package/src/fs-atomic.js +20 -3
  1067. package/src/hooks/worktree-guard.js +9 -3
  1068. package/src/index.js +36 -19
  1069. package/src/module-impact.js +1 -1
  1070. package/src/modules.js +23 -21
  1071. package/src/progress/stage-machine.js +23 -0
  1072. package/src/progress.js +38 -2
  1073. package/src/quicklog.js +7 -5
  1074. package/src/run/command.js +7 -6
  1075. package/src/run/complete-handlers.js +6 -2
  1076. package/src/run/complete.js +33 -20
  1077. package/src/run/gates.js +31 -4
  1078. package/src/run/next.js +4 -3
  1079. package/src/run/prompt.js +66 -6
  1080. package/src/run/scan-profile.js +1 -0
  1081. package/src/run/shared.js +11 -5
  1082. package/src/run/stage.js +15 -12
  1083. package/src/scan-diff.js +4 -2
  1084. package/src/stage-contract-spec.js +1 -1
  1085. package/src/stage-contract.js +16 -8
  1086. package/src/stages/brainstorm-auto.js +43 -1
  1087. package/src/stages/brainstorm.js +24 -8
  1088. package/src/stages/execute.js +36 -9
  1089. package/src/stages/knowledge.js +18 -5
  1090. package/src/stages/plan-postcheck.js +63 -7
  1091. package/src/stages/plan.js +13 -6
  1092. package/src/stages/verify.js +1 -1
  1093. package/src/sync.js +27 -11
  1094. package/src/task-review.js +5 -3
  1095. package/src/taskcard.js +35 -0
  1096. package/src/verify-postcheck.js +24 -13
  1097. package/src/verify-probes.js +39 -13
  1098. package/src/worktree-apply.js +481 -292
  1099. package/src/worktree-deps.js +93 -1
  1100. package/src/worktree.js +91 -21
  1101. package/templates/prompts/taskcard-rules.md +1 -1
@@ -0,0 +1,1304 @@
1
+ /**
2
+ * SillySpec ProgressManager — 进度恢复管理
3
+ *
4
+ * 纯 Node.js,无外部依赖。支持多变更并行。
5
+ *
6
+ * 存储结构:
7
+ * .sillyspec/.runtime/sillyspec.db — SQLite 数据库(权威状态源,含全局状态/项目名/活跃变更)
8
+ *
9
+ * 历史迁移:v1/v2 使用 progress.json 文件,v3 已全部迁移至 SQLite。
10
+ * worktree-guard hook 直读 sillyspec.db,不再有 gate-status.json 缓存双源(task-10 废除)。
11
+ */
12
+
13
+ import { existsSync, mkdirSync, readFileSync, writeFileSync, renameSync, unlinkSync, appendFileSync, copyFileSync, readdirSync, statSync } from 'fs';
14
+ import { join, basename, dirname, resolve, sep } from 'path';
15
+ import { tmpdir } from 'os';
16
+ import { writeAtomicSync } from './fs-atomic.js';
17
+ import { DB } from './db.js';
18
+ import { checkExecuteCodeEvidence } from './stage-contract.js';
19
+ import { ConsistencyDoctor } from './progress/consistency-doctor.js';
20
+ import { ChangeRegistry } from './progress/change-registry.js';
21
+ import { StepStore } from './progress/step-store.js';
22
+ import { StageMachine } from './progress/stage-machine.js';
23
+ import { stageRegistry } from './stages/index.js';
24
+ import { STAGE_ORDER, MAIN_FLOW_ORDER, VALID_STAGES, STAGE_LABELS, SPEC_DIR_NAME, CURRENT_VERSION, emptyStage } from './progress/shared.js';
25
+ // resolveSpecDir 单一真相源在 src/run/shared.js(含 home 拒绝守卫,坑 cwd-correction-home-collision
26
+ // 根治:home 下 .sillyspec 恒不命中,防 smoke/临时目录污染自我延续)。此处 re-export 保持
27
+ // 既有 import 路径兼容;run/shared.js 对 progress.js 只有动态 import,无静态循环。
28
+ import { resolveSpecDir } from './run/shared.js';
29
+ import { checkPlatformManaged, PLATFORM_MANAGED_FILENAME } from './run/shared.js';
30
+ export { resolveSpecDir };
31
+
32
+ // 默认规范目录名(相对于 cwd)
33
+ // SPEC_DIR_NAME → ./progress/shared.js(W6 Step9d)
34
+ const RUNTIME_SUBDIR = '.runtime';
35
+
36
+ /**
37
+ * 向上查找含 .sillyspec 目录的祖先目录——实现已收敛至 src/run/shared.js(单一真相源,
38
+ * 含 home 拒绝守卫),此处 re-export。见顶部 import 说明。
39
+ */
40
+
41
+ /**
42
+ * 平台指针不可达错误。pointer 存在但失效时抛出,阻止静默回退到本地孤儿 db。
43
+ * 逃生口:显式 --spec-dir 绕过 pointer 校验。
44
+ */
45
+ export class PointerUnreachableError extends Error {
46
+ constructor({ pointerPath, specRoot, reason, hint }) {
47
+ super(
48
+ `平台指针不可用:${reason}\n` +
49
+ ` pointer: ${pointerPath}\n` +
50
+ ` specRoot: ${specRoot || '(缺失)'}\n` +
51
+ `修复:${hint}`
52
+ );
53
+ this.name = 'PointerUnreachableError';
54
+ this.pointerPath = pointerPath;
55
+ this.specRoot = specRoot || null;
56
+ }
57
+ }
58
+
59
+ /**
60
+ * 平台接管声明生效错误(指针缺失但声明存在)。fail-closed 入口一:
61
+ * 防指针被 cleanup/STALE 清理或项目挪动后裸调静默建本地进度库(状态分裂根因)。
62
+ *
63
+ * ⚠️ 不覆写 this.name(保持父类的 'PointerUnreachableError')——CLI 顶层 catch 按
64
+ * err?.name === 'PointerUnreachableError' 严格字符串匹配(index.js),子类改名会
65
+ * 落通用错误分支打 stack noise。靠 message 首行"平台接管声明生效"区分场景。
66
+ */
67
+ export class PlatformManagedError extends PointerUnreachableError {
68
+ constructor({ declarationPath, specRoot }) {
69
+ super({
70
+ pointerPath: declarationPath,
71
+ specRoot,
72
+ reason: `平台接管声明生效——本项目已由平台托管,但恢复指针缺失(可能被 platform pointer --cleanup 清理或项目目录被移动),拒绝静默回退本地模式`,
73
+ hint: `① 重跑平台 scan/init(带 --spec-root)重建指针;② 确认不再使用平台:sillyspec platform disconnect(删除接管声明);③ 显式 --spec-dir <路径> 临时指定目录`,
74
+ });
75
+ this.declarationPath = declarationPath;
76
+ }
77
+ }
78
+
79
+ /**
80
+ * 平台感知的 specDir 解析(fail-closed,所有 CLI 子命令统一入口)。
81
+ *
82
+ * 优先级:显式 --spec-dir > pointer.specRoot(可达)> resolveSpecDir(cwd)。
83
+ *
84
+ * fail-closed 语义(修复"状态穿越"定时炸弹):
85
+ * 一旦项目进入过平台模式(pointer 文件存在),pointer 失效(specRoot 不可达 /
86
+ * 损坏 / 缺字段)不再静默回退到本地——否则会读到切平台前的过期本地 db。
87
+ * 此时抛 PointerUnreachableError,由 CLI 顶层捕获并打印修复引导。
88
+ *
89
+ * 无 pointer = 纯本地项目(从未平台 scan),正常走本地解析,不受影响。
90
+ */
91
+ export function resolvePlatformSpecDir(cwd, explicitSpecDir = null) {
92
+ if (explicitSpecDir) return resolve(explicitSpecDir);
93
+ const pointerPath = join(resolve(cwd), '.sillyspec-platform.json');
94
+ if (!existsSync(pointerPath)) {
95
+ // 指针缺失:查平台接管声明(fail-closed 入口一)。声明存在 = 项目进过平台模式,
96
+ // 指针丢失不该静默当纯本地项目处理(会建本地进度库 → 状态分裂)。
97
+ const decl = checkPlatformManaged(cwd);
98
+ if (decl) {
99
+ throw new PlatformManagedError({
100
+ declarationPath: join(resolve(cwd), PLATFORM_MANAGED_FILENAME),
101
+ specRoot: decl.specRoot,
102
+ });
103
+ }
104
+ return resolveSpecDir(cwd);
105
+ }
106
+ // pointer 存在 = 进过平台模式,严格校验,不静默回退
107
+ let ptr;
108
+ try {
109
+ ptr = JSON.parse(readFileSync(pointerPath, 'utf8'));
110
+ } catch (e) {
111
+ throw new PointerUnreachableError({
112
+ pointerPath,
113
+ specRoot: null,
114
+ reason: `pointer 文件损坏(${e.message})`,
115
+ hint: `sillyspec platform pointer --cleanup 删除后重跑平台 scan`,
116
+ });
117
+ }
118
+ if (!ptr.specRoot) {
119
+ throw new PointerUnreachableError({
120
+ pointerPath,
121
+ specRoot: null,
122
+ reason: 'pointer 缺少 specRoot 字段',
123
+ hint: `sillyspec platform pointer --cleanup 删除后重跑平台 scan`,
124
+ });
125
+ }
126
+ if (!existsSync(ptr.specRoot)) {
127
+ throw new PointerUnreachableError({
128
+ pointerPath,
129
+ specRoot: ptr.specRoot,
130
+ reason: 'pointer.specRoot 路径不存在(daemon 未起?已迁移?)',
131
+ hint: `启动 SillyHub daemon;或 sillyspec doctor --json 诊断;或显式 --spec-dir <本地路径> 临时走本地`,
132
+ });
133
+ }
134
+ // 驾驭:pointer 指向 OS temp 目录几乎肯定是陈旧测试/CI 残留(合法项目不会把 specRoot 放 temp)。
135
+ // 历史:npm test 等会写 pointer 到 Temp/spec-dir-test-*,不清理则污染真实环境,所有命令静默落错库。
136
+ // 非阻断警告:让 agent 知道当前解析到的 specDir 可疑,而非静默写到死库。
137
+ const resolvedTmp = resolve(tmpdir());
138
+ if (resolve(ptr.specRoot) === resolvedTmp || resolve(ptr.specRoot).startsWith(resolvedTmp + sep)) {
139
+ console.warn(
140
+ `⚠️ 平台 pointer 的 specRoot 指向系统 temp 目录:${ptr.specRoot}\n` +
141
+ ` 这通常是陈旧的测试/CI 残留,命令会写进这个可疑库而非你当前项目。\n` +
142
+ ` 修复:sillyspec platform pointer --cleanup(删除 ${pointerPath}),或删除该 pointer 文件后回到项目目录重跑。`
143
+ );
144
+ }
145
+ return ptr.specRoot;
146
+ }
147
+
148
+ const CHANGES_SUBDIR = 'changes';
149
+ // CURRENT_VERSION → ./progress/shared.js(W6 Step9d)
150
+ // VALID_STAGES → ./progress/shared.js(W6 Step9c)
151
+ // VALID_STATUSES → ./progress/step-store.js(updateStep 专用,本地化)
152
+
153
+
154
+ // ── ProgressManager ──
155
+
156
+ export class ProgressManager {
157
+ /** 模块级 DB 连接池:Map<dbPath, DB>(SEC-09/PERF-10,见 _ensureDB 注释) */
158
+ static _dbPool = new Map();
159
+
160
+ /**
161
+ * @param {object} [opts]
162
+ * @param {string} [opts.specDir] - 规范目录绝对路径(默认 cwd/.sillyspec)
163
+ */
164
+ constructor(opts = {}) {
165
+ this._customSpecDir = opts.specDir || null;
166
+ this._consistency = new ConsistencyDoctor(this);
167
+ this._changeRegistry = new ChangeRegistry(this);
168
+ this._stepStore = new StepStore(this);
169
+ this._stageMachine = new StageMachine(this);
170
+ }
171
+
172
+ // ── 路径工具 ──
173
+
174
+ /** 获取 specDir(优先自定义,否则向上查找含 .sillyspec 的目录,fallback 到 cwd/.sillyspec) */
175
+ _getSpecDir(cwd) {
176
+ if (this._customSpecDir) return this._customSpecDir;
177
+ // specDir 对给定 cwd 在进程生命周期内不变(.sillyspec 目录不会被移动),
178
+ // 按 cwd 缓存,避免每次路径解析都向上 existsSync 遍历目录树(热路径)。
179
+ if (!this._specDirCache) this._specDirCache = new Map();
180
+ const cached = this._specDirCache.get(cwd);
181
+ if (cached) return cached;
182
+ const resolved = resolveSpecDir(cwd);
183
+ this._specDirCache.set(cwd, resolved);
184
+ return resolved;
185
+ }
186
+
187
+ _runtimePath(cwd, ...parts) {
188
+ return join(this._getSpecDir(cwd), RUNTIME_SUBDIR, ...parts);
189
+ }
190
+
191
+ _changePath(cwd, changeName, ...parts) {
192
+ return join(this._getSpecDir(cwd), CHANGES_SUBDIR, changeName, ...parts);
193
+ }
194
+
195
+ _ensureRuntimeDir(cwd) {
196
+ const runtimeDir = this._runtimePath(cwd);
197
+ if (!existsSync(runtimeDir)) {
198
+ mkdirSync(runtimeDir, { recursive: true });
199
+ for (const d of ['artifacts', 'history', 'logs', 'templates']) {
200
+ mkdirSync(join(runtimeDir, d), { recursive: true });
201
+ }
202
+ }
203
+ }
204
+
205
+ /**
206
+ * 懒初始化 DB 连接,缓存在实例上(better-sqlite3 同步 API,init 无 async)。
207
+ *
208
+ * SEC-09/PERF-10(2026-08-20 体检):连接额外进模块级 Map<dbPath, DB> 单例——
209
+ * 一条平台命令此前会 new 多个 ProgressManager(triggerPull / sync / import 各建),
210
+ * 同一 sillyspec.db 被 open 3-5 次,每次重跑 PRAGMA + schema 探测,且多连接
211
+ * 提升 SQLITE_BUSY 概率、Windows 残留句柄影响文件替换。CLI 短进程生命周期内
212
+ * dbPath 不变,进程退出由 OS 回收句柄(node:sqlite 无显式泄漏);进程内共享
213
+ * 单连接后 WAL 写竞争面反而缩小。
214
+ */
215
+ _ensureDB(cwd) {
216
+ if (!this._db) {
217
+ const dbPath = this._runtimePath(cwd, 'sillyspec.db');
218
+ let db = ProgressManager._dbPool.get(dbPath);
219
+ if (!db) {
220
+ db = new DB(dbPath);
221
+ db.init();
222
+ ProgressManager._dbPool.set(dbPath, db);
223
+ }
224
+ this._db = db;
225
+ }
226
+ return this._db;
227
+ }
228
+
229
+ _ensureChangeDir(cwd, changeName) {
230
+ const dir = this._changePath(cwd, changeName);
231
+ if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
232
+ return dir;
233
+ }
234
+
235
+ // ── 全局状态 ──
236
+
237
+ readGlobal(cwd) {
238
+ // SQL: SELECT FROM project + changes
239
+ const db = this._ensureDB(cwd);
240
+ const sqlDb = db.getDb();
241
+
242
+ // 读取 project 行(id=1)
243
+ const row = sqlDb.prepare('SELECT name, schema_version FROM project WHERE id = 1').get();
244
+ if (row === undefined) return null;
245
+ const { name, schema_version: schemaVersion } = row;
246
+
247
+ // 读取 active 变更列表
248
+ const changeRows = sqlDb.prepare("SELECT name FROM changes WHERE status = 'active' ORDER BY name").all();
249
+ const activeChanges = changeRows.map(r => r.name);
250
+
251
+ return {
252
+ _version: schemaVersion,
253
+ project: name,
254
+ activeChanges,
255
+ };
256
+ }
257
+
258
+ // ── 变更级别状态 ──
259
+
260
+ /**
261
+ * 读取指定变更的 progress(SQL 版)
262
+ * @param {string} cwd
263
+ * @param {string|null} changeName - 变更名,null 时尝试自动检测
264
+ * @returns {object|null} 与 SQLite 查询结果一致的 JS 对象
265
+ */
266
+ read(cwd, changeName = null) {
267
+ // 自动检测变更名(listChanges 已在 task-08 同步化,此处直接拿到活跃变更数组)
268
+ if (!changeName) {
269
+ const changes = this.listChanges(cwd);
270
+ if (changes.length === 1) {
271
+ changeName = changes[0];
272
+ } else {
273
+ // 多个或零个活跃变更,无法确定
274
+ return null;
275
+ }
276
+ }
277
+
278
+ const db = this._ensureDB(cwd);
279
+ const sqlDb = db.getDb();
280
+
281
+ // 1. 从 changes 表获取基本信息
282
+ const changeRow = sqlDb.prepare('SELECT id, name, current_stage, no_worktree, last_active FROM changes WHERE name = ?').get(changeName);
283
+ if (changeRow === undefined) return null;
284
+ const { id: changeId, name: cName, current_stage: currentStage, no_worktree: noWorktree, last_active: lastActive } = changeRow;
285
+
286
+ // 2. 从 stages 表获取所有阶段(含 revision 列)
287
+ const stageRows = sqlDb.prepare('SELECT id, stage, status, started_at, completed_at, revision, reopened_from_step, reopened_at, stale_reason FROM stages WHERE change_id = ? ORDER BY id').all(changeId);
288
+ const stageMap = {};
289
+ const stageIds = [];
290
+ for (const row of stageRows) {
291
+ const { id: sId, stage, status, started_at: startedAt, completed_at: completedAt, revision, reopened_from_step: reopenedFromStep, reopened_at: reopenedAt, stale_reason: staleReason } = row;
292
+ stageMap[stage] = { _dbId: sId, status, startedAt, completedAt,
293
+ ...(revision != null ? { revision } : {}),
294
+ ...(reopenedFromStep ? { reopenedFromStep } : {}),
295
+ ...(reopenedAt ? { reopenedAt } : {}),
296
+ ...(staleReason ? { staleReason } : {}),
297
+ };
298
+ stageIds.push(sId);
299
+ }
300
+
301
+ // 3. 从 steps 表获取所有步骤
302
+ const stepsByStage = {};
303
+ if (stageIds.length > 0) {
304
+ const placeholders = stageIds.map(() => '?').join(',');
305
+ const stepRows = sqlDb.prepare(
306
+ `SELECT stage_id, name, status, output, completed_at, ordering, wait_reason, wait_options, wait_answer, waited_at, wait_answers, wait_round, max_wait_rounds FROM steps WHERE stage_id IN (${placeholders}) ORDER BY stage_id, ordering`
307
+ ).all(...stageIds);
308
+ // 按阶段分组步骤
309
+ for (const row of stepRows) {
310
+ const { stage_id: stageId, name, status, output, completed_at: completedAt, wait_reason: waitReason, wait_options: waitOptions, wait_answer: waitAnswer, waited_at: waitedAt, wait_answers: waitAnswersJson, wait_round: waitRound, max_wait_rounds: maxWaitRounds } = row;
311
+ if (!stepsByStage[stageId]) stepsByStage[stageId] = [];
312
+ let waitAnswers = null;
313
+ if (waitAnswersJson) {
314
+ try { waitAnswers = JSON.parse(waitAnswersJson); } catch (e) { console.warn(`[progress] waitAnswers JSON 损坏,已跳过: ${e.message}`); }
315
+ }
316
+ stepsByStage[stageId].push({
317
+ name, status, output, completedAt,
318
+ ...(waitReason ? { waitReason } : {}),
319
+ ...(waitOptions ? { waitOptions } : {}),
320
+ ...(waitAnswer ? { waitAnswer } : {}),
321
+ ...(waitedAt ? { waitedAt } : {}),
322
+ ...(waitAnswers ? { waitAnswers } : {}),
323
+ ...(waitRound != null ? { waitRound } : {}),
324
+ ...(maxWaitRounds != null ? { maxWaitRounds } : {}),
325
+ });
326
+ }
327
+ }
328
+
329
+ // 4. 从 batch_progress 表获取批量进度
330
+ const batchRow = sqlDb.prepare('SELECT total, completed, failed, skipped FROM batch_progress WHERE change_id = ?').get(changeId);
331
+ let batchProgress = undefined;
332
+ if (batchRow !== undefined) {
333
+ const { total, completed, failed, skipped } = batchRow;
334
+ batchProgress = { total, completed, failed, skipped };
335
+ }
336
+
337
+ // 5. 获取项目名
338
+ const projectRow = sqlDb.prepare('SELECT name FROM project WHERE id = 1').get();
339
+ const projectName = projectRow !== undefined ? projectRow.name : '';
340
+
341
+ // 6. 组装为兼容对象
342
+ const stages = {};
343
+ // 先填充所有 VALID_STAGES
344
+ for (const s of VALID_STAGES) {
345
+ stages[s] = emptyStage();
346
+ }
347
+ // 用 DB 数据覆盖
348
+ for (const [stage, info] of Object.entries(stageMap)) {
349
+ const steps = (stepsByStage[info._dbId] || []).map(s => ({
350
+ name: s.name,
351
+ status: s.status,
352
+ output: s.output,
353
+ completedAt: s.completedAt,
354
+ ...(s.waitReason ? { waitReason: s.waitReason } : {}),
355
+ ...(s.waitOptions ? { waitOptions: s.waitOptions } : {}),
356
+ ...(s.waitAnswer ? { waitAnswer: s.waitAnswer } : {}),
357
+ ...(s.waitedAt ? { waitedAt: s.waitedAt } : {}),
358
+ ...(s.waitAnswers ? { waitAnswers: s.waitAnswers } : {}),
359
+ ...(s.waitRound != null ? { waitRound: s.waitRound } : {}),
360
+ ...(s.maxWaitRounds != null ? { maxWaitRounds: s.maxWaitRounds } : {}),
361
+ }));
362
+ stages[stage] = {
363
+ status: info.status,
364
+ steps,
365
+ startedAt: info.startedAt,
366
+ completedAt: info.completedAt,
367
+ // Revision v1 fields
368
+ ...(info.revision ? { revision: info.revision } : {}),
369
+ ...(info.reopenedFromStep ? { reopenedFromStep: info.reopenedFromStep } : {}),
370
+ ...(info.reopenedAt ? { reopenedAt: info.reopenedAt } : {}),
371
+ ...(info.staleReason ? { staleReason: info.staleReason } : {}),
372
+ };
373
+ }
374
+
375
+ const result = {
376
+ _version: 5,
377
+ project: projectName,
378
+ currentChange: cName,
379
+ currentStage: currentStage || '',
380
+ lastActive: lastActive || null,
381
+ stages,
382
+ };
383
+
384
+ // noWorktree
385
+ if (noWorktree) result.noWorktree = true;
386
+
387
+ // batchProgress(仅在 DB 中有记录时才包含)
388
+ if (batchProgress) result.batchProgress = batchProgress;
389
+
390
+ return result;
391
+ }
392
+
393
+ /**
394
+ * 同步专用六表完整序列化(design §8/B1,task-02 / D-005@v2 / FR-07)。
395
+ * 与 read()(聚合视图,不读 approvals 且 changes 只投影五列)不同,本方法输出真正六表投影,
396
+ * 作为同步载体(ProgressManager.import() 的逆运算,task-03)。
397
+ *
398
+ * 输出契约(字段名 = DB 列名 snake_case,import 直接对列写回,round-trip 无映射损耗):
399
+ * project { name, schema_version } —— 全局单行稳定字段(id/created_at/updated_at 本地元数据不同步)
400
+ * changes [{ name, current_stage, status, last_active,
401
+ * last_synced_platform_ts, last_local_modified_ts }] —— 只投影流程进度列;
402
+ * 排除 isolation_* 系列 与 platform_* 系列(platform_change_id/workspace_id/last_sync/sync_enabled)
403
+ * 以及 created_at(本地强相关,不同步,B2)
404
+ * stages [{ change_name, stage, status, started_at, completed_at,
405
+ * revision, reopened_from_step, reopened_at, stale_reason }] —— 用 change_name+stage 替代 id 外键
406
+ * steps [{ change_name, stage, name, status, output, completed_at, ordering,
407
+ * wait_reason, wait_options, wait_answer, waited_at, wait_answers,
408
+ * wait_round, max_wait_rounds }] —— wait_options/wait_answers 透传 DB JSON 字符串
409
+ * batch_progress [{ change_name, total, completed, failed, skipped }]
410
+ * approvals [{ change_name, status, requested_at, approved_by, approved_at, rejection_reason }]
411
+ * 可空列归一为 null(非 undefined,保证 JSON 往返键稳定);不含 user/base_ts/pushed_at(D-015,sync.js 放 HTTP header)。
412
+ *
413
+ * @param {string} cwd
414
+ * @param {string|null} [changeName] - 空时单活跃变更自动推导(对齐 read());多/零活跃返回 null
415
+ * @returns {object|null} 六键同步 JSON;change 不存在或无法推导返回 null
416
+ */
417
+ serializeForSync(cwd, changeName = null) {
418
+ // 自动检测变更名(与 read() 同口径):单活跃变更推导,多/零无法确定返回 null
419
+ if (!changeName) {
420
+ const changes = this.listChanges(cwd);
421
+ if (changes.length === 1) {
422
+ changeName = changes[0];
423
+ } else {
424
+ return null;
425
+ }
426
+ }
427
+
428
+ const db = this._ensureDB(cwd);
429
+ const sqlDb = db.getDb();
430
+
431
+ // 1. changes 行(投影流程进度列 + name 标识)
432
+ const changeRow = sqlDb.prepare(
433
+ `SELECT id, name, current_stage, status, last_active, last_synced_platform_ts, last_local_modified_ts
434
+ FROM changes WHERE name = ?`
435
+ ).get(changeName);
436
+ if (changeRow === undefined) return null;
437
+ const changeId = changeRow.id;
438
+ const changeProj = {
439
+ name: changeRow.name,
440
+ current_stage: changeRow.current_stage,
441
+ status: changeRow.status,
442
+ last_active: changeRow.last_active,
443
+ last_synced_platform_ts: changeRow.last_synced_platform_ts ?? null,
444
+ last_local_modified_ts: changeRow.last_local_modified_ts ?? null,
445
+ };
446
+
447
+ // 2. project 全局单行(只投影稳定字段 name/schema_version;created_at/updated_at 是本地库元数据,
448
+ // 同步无意义且破坏 round-trip 跨库等值——与 changes 排除 created_at 同理,B2)
449
+ const projectRow = sqlDb.prepare(
450
+ 'SELECT name, schema_version FROM project WHERE id = 1'
451
+ ).get();
452
+
453
+ // 3. stages(该 change 下,用 change_name+stage 表达外键)
454
+ const stageRows = sqlDb.prepare(
455
+ `SELECT id, stage, status, started_at, completed_at, revision, reopened_from_step, reopened_at, stale_reason
456
+ FROM stages WHERE change_id = ? ORDER BY id`
457
+ ).all(changeId);
458
+ const stageJson = stageRows.map(r => ({
459
+ change_name: changeRow.name,
460
+ stage: r.stage,
461
+ status: r.status,
462
+ started_at: r.started_at ?? null,
463
+ completed_at: r.completed_at ?? null,
464
+ revision: r.revision ?? null,
465
+ reopened_from_step: r.reopened_from_step ?? null,
466
+ reopened_at: r.reopened_at ?? null,
467
+ stale_reason: r.stale_reason ?? null,
468
+ }));
469
+
470
+ // 4. steps(stage_id IN;用 change_name+stage 关联回 stage)
471
+ const stageIds = stageRows.map(r => r.id);
472
+ const stageIdToName = new Map(stageRows.map(r => [r.id, r.stage]));
473
+ let stepJson = [];
474
+ if (stageIds.length > 0) {
475
+ const placeholders = stageIds.map(() => '?').join(',');
476
+ const stepRows = sqlDb.prepare(
477
+ `SELECT stage_id, name, status, output, completed_at, ordering, wait_reason, wait_options,
478
+ wait_answer, waited_at, wait_answers, wait_round, max_wait_rounds
479
+ FROM steps WHERE stage_id IN (${placeholders}) ORDER BY stage_id, ordering`
480
+ ).all(...stageIds);
481
+ stepJson = stepRows.map(r => ({
482
+ change_name: changeRow.name,
483
+ stage: stageIdToName.get(r.stage_id),
484
+ name: r.name,
485
+ status: r.status,
486
+ output: r.output ?? null,
487
+ completed_at: r.completed_at ?? null,
488
+ ordering: r.ordering ?? null,
489
+ wait_reason: r.wait_reason ?? null,
490
+ wait_options: r.wait_options ?? null,
491
+ wait_answer: r.wait_answer ?? null,
492
+ waited_at: r.waited_at ?? null,
493
+ wait_answers: r.wait_answers ?? null,
494
+ wait_round: r.wait_round ?? null,
495
+ max_wait_rounds: r.max_wait_rounds ?? null,
496
+ }));
497
+ }
498
+
499
+ // 5. batch_progress(无行则空数组,import 侧幂等)
500
+ const batchRow = sqlDb.prepare(
501
+ 'SELECT total, completed, failed, skipped FROM batch_progress WHERE change_id = ?'
502
+ ).get(changeId);
503
+ const batchJson = batchRow !== undefined ? [{
504
+ change_name: changeRow.name,
505
+ total: batchRow.total,
506
+ completed: batchRow.completed,
507
+ failed: batchRow.failed,
508
+ skipped: batchRow.skipped,
509
+ }] : [];
510
+
511
+ // 6. approvals(read() 不读此表,serializeForSync 补齐;无行则空数组)
512
+ const approvalRow = sqlDb.prepare(
513
+ 'SELECT status, requested_at, approved_by, approved_at, rejection_reason FROM approvals WHERE change_id = ?'
514
+ ).get(changeId);
515
+ const approvalJson = approvalRow !== undefined ? [{
516
+ change_name: changeRow.name,
517
+ status: approvalRow.status,
518
+ requested_at: approvalRow.requested_at ?? null,
519
+ approved_by: approvalRow.approved_by ?? null,
520
+ approved_at: approvalRow.approved_at ?? null,
521
+ rejection_reason: approvalRow.rejection_reason ?? null,
522
+ }] : [];
523
+
524
+ return {
525
+ project: projectRow || null,
526
+ changes: [changeProj],
527
+ stages: stageJson,
528
+ steps: stepJson,
529
+ batch_progress: batchJson,
530
+ approvals: approvalJson,
531
+ };
532
+ }
533
+
534
+ /**
535
+ * serializeForSync 的逆运算:把平台权威 JSON 原子写回本地 DB 的该 change 行(design §8/B1,task-03 / D-005@v2 / D-011 / FR-07)。
536
+ * ⚠️ 必须保护真实资产:import 前对 DB 做【独立】snapshot `.runtime/sillyspec.db.pre-import-<ts>.bak`,
537
+ * 不抢 _openWithFallback 的 `${dbPath}.bak`(gap5/R-08);任何失败本地进度库不损坏。
538
+ *
539
+ * 语义:
540
+ * - 单个 DB.transaction() 包裹,原子重建 stages/steps/batch_progress/approvals 四表(任一失败整体回滚)
541
+ * - changes 行用 UPDATE 选择投影列(current_stage/status/last_active/last_synced_platform_ts/last_local_modified_ts),
542
+ * 保留 isolation_* / platform_* / created_at(本地强相关状态不被覆盖,B2;change 不存在时 INSERT 兜底平台新增)
543
+ * - import 后 last_synced_platform_ts 与 last_local_modified_ts 均置为 progressObj.pushed_at(D-013 例外:
544
+ * 不更新 now()——否则 now()>base_ts 下次 pull 误判冲突;pushed_at 由 sync.js pull() 从响应 header attach)
545
+ * - 本地确定性操作,失败 throw 中文(非 sync 类 Best Effort,CONVENTIONS #4)
546
+ *
547
+ * @param {string} cwd
548
+ * @param {object} progressObj - serializeForSync 输出 + sync.js 附加的 pushed_at
549
+ * @param {string|null} [changeName] - 空则从 progressObj.changes[0].name 推导
550
+ * @returns {ImportResult} { ok:true, imported:changeName, reason?, bakPath }
551
+ */
552
+ import(cwd, progressObj, changeName = null) {
553
+ if (!progressObj || typeof progressObj !== 'object') {
554
+ throw new Error('import 参数无效:progressObj 必须是 serializeForSync() 输出的六表 JSON 对象');
555
+ }
556
+
557
+ const cn = changeName || (progressObj.changes && progressObj.changes[0] && progressObj.changes[0].name);
558
+ if (!cn) {
559
+ throw new Error('import 缺少 changeName:无法定位目标 change(progressObj.changes[0].name 为空)');
560
+ }
561
+
562
+ // ⚠️ 必须保护真实资产:独立 .bak snapshot(前缀 pre-import- 区分于主 .bak 备份机制)
563
+ const dbPath = this._runtimePath(cwd, 'sillyspec.db');
564
+ if (!existsSync(dbPath)) {
565
+ throw new Error(`本地进度库不存在,无法 import:${dbPath}`);
566
+ }
567
+ const bakTs = new Date().toISOString().replace(/[:.]/g, '-');
568
+ const bakPath = this._runtimePath(cwd, `sillyspec.db.pre-import-${bakTs}.bak`);
569
+ // 体检 BUG-18:WAL 模式下最近已提交事务可能仍在 -wal 侧车,直接 copy 主库文件会拿到
570
+ // 缺尾部提交的快照(恢复时静默回退进度)。先尽力 checkpoint(TRUNCATE) 把 WAL 合并回主库;
571
+ // 他进程持连接致 checkpoint 不完全时,把 -wal 侧车一并备份,恢复侧才有完整提交
572
+ try {
573
+ this._ensureDB(cwd).getDb().exec('PRAGMA wal_checkpoint(TRUNCATE)');
574
+ } catch { /* best-effort:失败退化为连 -wal 一起备份 */ }
575
+ copyFileSync(dbPath, bakPath);
576
+ const walSidecar = `${dbPath}-wal`;
577
+ if (existsSync(walSidecar)) {
578
+ try { copyFileSync(walSidecar, `${bakPath}-wal`); } catch { /* 侧车消失=已 checkpoint,无碍 */ }
579
+ }
580
+
581
+ const pushedAt = progressObj.pushed_at ?? null;
582
+ const now = new Date().toISOString();
583
+
584
+ try {
585
+ const db = this._ensureDB(cwd);
586
+ db.transaction(() => {
587
+ const sqlDb = db.getDb();
588
+
589
+ // 1. changes 行:INSERT OR IGNORE 兜底平台新增 change;UPDATE 只覆盖投影列(保留本地隔离/平台/created_at 列)
590
+ sqlDb.prepare(
591
+ `INSERT OR IGNORE INTO changes (name, current_stage, status, created_at, last_active)
592
+ VALUES (?, '', 'active', ?, ?)`
593
+ ).run(cn, now, now);
594
+ const ch = progressObj.changes && progressObj.changes[0];
595
+ sqlDb.prepare(
596
+ `UPDATE changes SET
597
+ current_stage = ?, status = ?, last_active = ?,
598
+ last_synced_platform_ts = ?, last_local_modified_ts = ?
599
+ WHERE name = ?`
600
+ ).run(
601
+ ch && ch.current_stage != null ? ch.current_stage : '',
602
+ ch && ch.status != null ? ch.status : 'active',
603
+ ch && ch.last_active != null ? ch.last_active : now,
604
+ pushedAt, pushedAt, cn
605
+ );
606
+ const changeRow = sqlDb.prepare('SELECT id FROM changes WHERE name = ?').get(cn);
607
+ const changeId = changeRow.id;
608
+
609
+ // 2. project 行:幂等确保存在(不覆盖已有全局行,round-trip 等值不受影响;仅补缺失)
610
+ const projExists = sqlDb.prepare('SELECT id FROM project WHERE id = 1').get();
611
+ if (projExists === undefined) {
612
+ const pj = progressObj.project || {};
613
+ sqlDb.prepare(
614
+ `INSERT INTO project (id, name, schema_version, created_at, updated_at)
615
+ VALUES (1, ?, ?, ?, ?)`
616
+ ).run(pj.name != null ? pj.name : 'project', pj.schema_version != null ? pj.schema_version : CURRENT_VERSION, now, now);
617
+ }
618
+
619
+ // 3. 重建 stages + steps:DELETE stages(ON DELETE CASCADE 级联删 steps),按 JSON 重建
620
+ sqlDb.prepare('DELETE FROM stages WHERE change_id = ?').run(changeId);
621
+ const stageToId = new Map();
622
+ for (const s of (progressObj.stages || [])) {
623
+ if (!s || !s.stage) continue;
624
+ sqlDb.prepare(
625
+ `INSERT INTO stages (change_id, stage, status, started_at, completed_at, revision, reopened_from_step, reopened_at, stale_reason)
626
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`
627
+ ).run(changeId, s.stage, s.status != null ? s.status : 'pending', s.started_at ?? null, s.completed_at ?? null,
628
+ s.revision != null ? s.revision : 0, s.reopened_from_step ?? null, s.reopened_at ?? null, s.stale_reason ?? null);
629
+ const row = sqlDb.prepare('SELECT id FROM stages WHERE change_id = ? AND stage = ?').get(changeId, s.stage);
630
+ stageToId.set(s.stage, row.id);
631
+ }
632
+ for (const st of (progressObj.steps || [])) {
633
+ if (!st || !st.name) continue;
634
+ const stageId = stageToId.get(st.stage);
635
+ if (stageId === undefined) continue; // 孤儿 step(stage 不在 JSON)跳过,不破坏完整性
636
+ sqlDb.prepare(
637
+ `INSERT INTO steps (stage_id, name, status, output, completed_at, ordering, wait_reason, wait_options, wait_answer, waited_at, wait_answers, wait_round, max_wait_rounds)
638
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
639
+ ).run(stageId, st.name, st.status != null ? st.status : 'pending', st.output ?? null, st.completed_at ?? null,
640
+ st.ordering != null ? st.ordering : 0, st.wait_reason ?? null, st.wait_options ?? null, st.wait_answer ?? null,
641
+ st.waited_at ?? null, st.wait_answers ?? null, st.wait_round ?? null, st.max_wait_rounds ?? null);
642
+ }
643
+
644
+ // 4. 重建 batch_progress(DELETE 再插,无行则清空)
645
+ sqlDb.prepare('DELETE FROM batch_progress WHERE change_id = ?').run(changeId);
646
+ const bp = progressObj.batch_progress && progressObj.batch_progress[0];
647
+ if (bp) {
648
+ sqlDb.prepare(
649
+ `INSERT INTO batch_progress (change_id, total, completed, failed, skipped)
650
+ VALUES (?, ?, ?, ?, ?)`
651
+ ).run(changeId, bp.total != null ? bp.total : 0, bp.completed != null ? bp.completed : 0,
652
+ bp.failed != null ? bp.failed : 0, bp.skipped != null ? bp.skipped : 0);
653
+ }
654
+
655
+ // 5. 重建 approvals(DELETE 再插,无行则清空)
656
+ sqlDb.prepare('DELETE FROM approvals WHERE change_id = ?').run(changeId);
657
+ const ap = progressObj.approvals && progressObj.approvals[0];
658
+ if (ap) {
659
+ sqlDb.prepare(
660
+ `INSERT INTO approvals (change_id, status, requested_at, approved_by, approved_at, rejection_reason)
661
+ VALUES (?, ?, ?, ?, ?, ?)`
662
+ ).run(changeId, ap.status != null ? ap.status : 'not_required', ap.requested_at ?? null, ap.approved_by ?? null,
663
+ ap.approved_at ?? null, ap.rejection_reason ?? null);
664
+ }
665
+ });
666
+ } catch (e) {
667
+ // 事务失败自动回滚(DB 未变),.bak 保留可恢复;fail-loud 中文
668
+ throw new Error(`import 失败,本地进度库已回滚(snapshot: ${bakPath}):${e.message}`);
669
+ }
670
+
671
+ return { ok: true, imported: cn, reason: undefined, bakPath };
672
+ }
673
+
674
+ /**
675
+ * 本地脏度标记(D-013 / task-04):写入路径末尾更新 changes.last_local_modified_ts。
676
+ * 在写方法的事务内调用则属于该事务(原子,失败整体回滚);import 是例外不调本方法
677
+ * (import 自己把 last_local_modified_ts 置为 pushed_at,表示本地=平台干净)。
678
+ * @param {string} cwd
679
+ * @param {string} changeName
680
+ * @param {string} [ts] - 复用调用方事务内的时间戳,保证与本次写入同时刻
681
+ */
682
+ _touchLocalModified(cwd, changeName, ts = null) {
683
+ if (!changeName) return;
684
+ const db = this._ensureDB(cwd);
685
+ const stamp = ts || new Date().toISOString();
686
+ db.getDb().prepare('UPDATE changes SET last_local_modified_ts = ? WHERE name = ?').run(stamp, changeName);
687
+ }
688
+
689
+ /**
690
+ * 写入指定变更的 progress
691
+ * @param {string} cwd
692
+ * @param {object} data
693
+ * @param {string|null} changeName - 从 data.currentChange 推导,或显式传入
694
+ *
695
+ * 持锁窗口评估(task-05 / R-08):本方法采用全量 UPSERT——无条件 UPDATE changes 行 +
696
+ * 遍历所有 stages(每 stage UPSERT stages 行 + 每 step 先 DELETE 再 INSERT 全量 + 末尾
697
+ * DELETE data 中不存在的多余 step)。评估过改"只写 diff(仅写变更过的 change/stage/step 行)"
698
+ * 以缩小事务持锁窗口、降低 BUSY 概率,结论:保持现状(全量 UPSERT)。
699
+ * 理由:
700
+ * 1. steps 表无 UNIQUE 约束(见循环内 DELETE-then-INSERT 注释),diff 写需先读现状再逐条
701
+ * 比较,复杂度高易错,易引入孤儿/缺失步骤破坏 FK 级联语义(design §3/§8);
702
+ * 2. busy_timeout=5000 + DB 层 SQLITE_BUSY 应用层有限重试(见 db.js transaction)已兜底
703
+ * 并发冲突,全量 UPSERT 的持锁窗口在此兜底下不是瓶颈;
704
+ * 3. 单进程内调用串行(design §9),事务窗口短(毫秒级),全量写正确性远高于 diff 的边际收益。
705
+ * 结论:全量 UPSERT 的简单正确性 > 持锁窗口优化的边际收益,不强行改 diff。
706
+ */
707
+ _write(cwd, data, changeName = null) {
708
+ const cn = changeName || data.currentChange;
709
+ if (!cn) {
710
+ console.warn('⚠️ _write: 无变更名,跳过写入');
711
+ return;
712
+ }
713
+
714
+ const db = this._ensureDB(cwd);
715
+ db.transaction(() => {
716
+ const sqlDb = db.getDb();
717
+ // 1. 更新 changes 表(last_local_modified_ts 脏度:D-013 / task-04)
718
+ const now = new Date().toISOString();
719
+ const noWorktree = data.noWorktree ? 1 : 0;
720
+ sqlDb.prepare(
721
+ 'UPDATE changes SET current_stage = ?, last_active = ?, no_worktree = ?, last_local_modified_ts = ? WHERE name = ?'
722
+ ).run(data.currentStage || '', now, noWorktree, now, cn);
723
+
724
+ // 2. 获取 change_id
725
+ const changeRow = sqlDb.prepare('SELECT id FROM changes WHERE name = ?').get(cn);
726
+ if (changeRow === undefined) return;
727
+ const changeId = changeRow.id;
728
+
729
+ // 3. 遍历 stages,UPSERT stages 表和 steps 表
730
+ if (data.stages && typeof data.stages === 'object') {
731
+ for (const [stageName, stageData] of Object.entries(data.stages)) {
732
+ // UPSERT stages 行(含 revision 列)
733
+ sqlDb.prepare(
734
+ `INSERT INTO stages (change_id, stage, status, started_at, completed_at, revision, reopened_from_step, reopened_at, stale_reason)
735
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
736
+ ON CONFLICT(change_id, stage) DO UPDATE SET
737
+ status = excluded.status,
738
+ started_at = excluded.started_at,
739
+ completed_at = excluded.completed_at,
740
+ revision = COALESCE(excluded.revision, stages.revision),
741
+ reopened_from_step = excluded.reopened_from_step,
742
+ reopened_at = excluded.reopened_at,
743
+ stale_reason = excluded.stale_reason`
744
+ ).run(changeId, stageName, stageData.status || 'pending', stageData.startedAt || null, stageData.completedAt || null,
745
+ stageData.revision || 0, stageData.reopenedFromStep || null, stageData.reopenedAt || null, stageData.staleReason || null);
746
+
747
+ // 获取 stage_id
748
+ const stageRow = sqlDb.prepare('SELECT id FROM stages WHERE change_id = ? AND stage = ?').get(changeId, stageName);
749
+ if (stageRow === undefined) continue;
750
+ const stageId = stageRow.id;
751
+
752
+ // 收集 data 中的步骤名
753
+ const stepNames = new Set();
754
+ if (Array.isArray(stageData.steps)) {
755
+ for (let i = 0; i < stageData.steps.length; i++) {
756
+ const step = stageData.steps[i];
757
+ stepNames.add(step.name);
758
+ // UPSERT 步骤(先删再插,steps 表无 UNIQUE 约束)
759
+ sqlDb.prepare('DELETE FROM steps WHERE stage_id = ? AND name = ?').run(stageId, step.name);
760
+ sqlDb.prepare(
761
+ 'INSERT INTO steps (stage_id, name, status, output, completed_at, ordering, wait_reason, wait_options, wait_answer, waited_at, wait_answers, wait_round, max_wait_rounds) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
762
+ ).run(stageId, step.name, step.status || 'pending', step.output || null, step.completedAt || null, i,
763
+ step.waitReason ?? null, Array.isArray(step.waitOptions) ? JSON.stringify(step.waitOptions) : (step.waitOptions ?? null), step.waitAnswer ?? null, step.waitedAt ?? null,
764
+ Array.isArray(step.waitAnswers) ? JSON.stringify(step.waitAnswers) : null,
765
+ step.waitRound ?? null, step.maxWaitRounds ?? null);
766
+ }
767
+ }
768
+
769
+ // 删除 data 中不存在的多余步骤
770
+ if (stepNames.size > 0) {
771
+ const namePlaceholders = [...stepNames].map(() => '?').join(',');
772
+ sqlDb.prepare(
773
+ `DELETE FROM steps WHERE stage_id = ? AND name NOT IN (${namePlaceholders})`
774
+ ).run(stageId, ...stepNames);
775
+ } else {
776
+ // data 中没有步骤,清空该阶段所有步骤
777
+ sqlDb.prepare('DELETE FROM steps WHERE stage_id = ?').run(stageId);
778
+ }
779
+ }
780
+ }
781
+
782
+ // 4. UPSERT batch_progress
783
+ if (data.batchProgress && typeof data.batchProgress === 'object') {
784
+ sqlDb.prepare(
785
+ `INSERT INTO batch_progress (change_id, total, completed, failed, skipped)
786
+ VALUES (?, ?, ?, ?, ?)
787
+ ON CONFLICT(change_id) DO UPDATE SET
788
+ total = excluded.total,
789
+ completed = excluded.completed,
790
+ failed = excluded.failed,
791
+ skipped = excluded.skipped`
792
+ ).run(changeId, data.batchProgress.total || 0, data.batchProgress.completed || 0, data.batchProgress.failed || 0, data.batchProgress.skipped || 0);
793
+ }
794
+ });
795
+ }
796
+
797
+ // ── 变更管理 ──
798
+
799
+ listChanges(cwd) { return this._changeRegistry.listChanges(cwd); }
800
+
801
+ // 单变更阶段查询(quick 轻量归档阶段闸):无行 null,读失败抛(调用方 fail-closed)
802
+ getChangeStage(cwd, changeName) { return this._changeRegistry.getChangeStage(cwd, changeName); }
803
+
804
+ registerChange(cwd, changeName) { return this._changeRegistry.registerChange(cwd, changeName); }
805
+
806
+ updateChangeIsolation(cwd, changeName, isolation) { return this._changeRegistry.updateChangeIsolation(cwd, changeName, isolation); }
807
+
808
+ readChangeIsolation(cwd, changeName) { return this._changeRegistry.readChangeIsolation(cwd, changeName); }
809
+
810
+ // syncedTs 透传(ql-20260818-008):push 成功推进 base_ts,facade 曾丢参致列永不写入
811
+ _updatePlatformLastSync(cwd, changeName, syncedTs = null) { return this._changeRegistry._updatePlatformLastSync(cwd, changeName, syncedTs); }
812
+
813
+ _updateApprovalStatus(cwd, changeName, status, reason = null) { return this._changeRegistry._updateApprovalStatus(cwd, changeName, status, reason); }
814
+
815
+ renameChange(cwd, oldName, newName) { return this._changeRegistry.renameChange(cwd, oldName, newName); }
816
+
817
+ // opts.archiveStepNames 给定时做归档终态一致化收尾(见 change-registry.unregisterChange 注释,
818
+ // 坑 manual-archive-desync-status-only);archiveStepNamesForArchive() 取 stageRegistry 单一真相
819
+ //(stages/* 不反向依赖 progress.js,静态 import 无环)。
820
+ unregisterChange(cwd, changeName, opts) { return this._changeRegistry.unregisterChange(cwd, changeName, opts); }
821
+
822
+ archiveStepNamesForArchive() {
823
+ if (!this._archiveStepNamesCache) {
824
+ const defs = stageRegistry?.archive?.steps
825
+ this._archiveStepNamesCache = Array.isArray(defs) ? defs.map(s => s.name) : []
826
+ }
827
+ return this._archiveStepNamesCache
828
+ }
829
+
830
+ updateChangeMeta(cwd, changeName, meta) { return this._changeRegistry.updateChangeMeta(cwd, changeName, meta); }
831
+
832
+ // ── CLI 命令 ──
833
+
834
+ init(cwd) {
835
+ this._ensureRuntimeDir(cwd);
836
+
837
+ // 初始化 DB(如不存在则创建文件 + 建表)
838
+ const db = this._ensureDB(cwd);
839
+ db.transaction(() => {
840
+ const sqlDb = db.getDb();
841
+ const now = new Date().toISOString();
842
+ const projectName = basename(cwd) || 'project';
843
+
844
+ // 检查 project id=1 是否已存在
845
+ const existing = sqlDb.prepare('SELECT id FROM project WHERE id = 1').get();
846
+ if (existing === undefined) {
847
+ sqlDb.prepare(
848
+ `INSERT INTO project (id, name, schema_version, created_at, updated_at)
849
+ VALUES (1, ?, ?, ?, ?)`
850
+ ).run(projectName, CURRENT_VERSION, now, now);
851
+ console.log(`✅ 已创建全局状态文件(SQLite)`);
852
+ } else {
853
+ console.log(`ℹ️ 全局状态文件已存在,跳过`);
854
+ }
855
+ });
856
+
857
+ // 创建 user-inputs.md
858
+ const inputsPath = this._runtimePath(cwd, 'user-inputs.md');
859
+ if (!existsSync(inputsPath)) {
860
+ writeFileSync(inputsPath, '# 用户输入记录\n\n> 每步完成时由 AI 自动追加,记录用户所有原话。\n\n');
861
+ }
862
+
863
+ this._ensureGitignore(cwd);
864
+ return this.readGlobal(cwd);
865
+ }
866
+
867
+ /**
868
+ * 初始化指定变更的 progress
869
+ * SQL: INSERT changes + 批量 INSERT stages
870
+ */
871
+ initChange(cwd, changeName, meta = {}) {
872
+ if (!changeName) {
873
+ console.warn('⚠️ initChange: changeName 为空,跳过');
874
+ return null;
875
+ }
876
+ // quick 会话 id(quick-<uuid8>,见 run.js QUICK_SID_RE)只作 progress 的跨进程 session key,
877
+ // 进度存 SQL 不需要实体 change 目录——跳过避免 changes/quick-<uuid>/ 空目录残留。
878
+ if (!/^quick-[0-9a-f]{8}$/.test(changeName)) {
879
+ this._ensureChangeDir(cwd, changeName);
880
+ }
881
+
882
+ const db = this._ensureDB(cwd);
883
+ db.transaction(() => {
884
+ const sqlDb = db.getDb();
885
+ const now = new Date().toISOString();
886
+
887
+ // 检查变更是否已存在
888
+ const existing = sqlDb.prepare('SELECT id FROM changes WHERE name = ?').get(changeName);
889
+ if (existing === undefined) {
890
+ // 插入 changes 行
891
+ sqlDb.prepare(
892
+ `INSERT INTO changes (name, current_stage, status, created_at, last_active, title, quicklog_id)
893
+ VALUES (?, 'scan', 'active', ?, ?, ?, ?)`
894
+ ).run(changeName, now, now, meta.title || null, meta.quicklogId || null);
895
+ }
896
+
897
+ // 获取 change_id
898
+ const changeRow = sqlDb.prepare('SELECT id FROM changes WHERE name = ?').get(changeName);
899
+ const changeId = changeRow.id;
900
+
901
+ // 批量插入所有合法阶段(INSERT OR IGNORE 跳过已存在的);沿用顶部 import 的 VALID_STAGES 单一源
902
+ for (const stage of VALID_STAGES) {
903
+ sqlDb.prepare(
904
+ `INSERT OR IGNORE INTO stages (change_id, stage, status)
905
+ VALUES (?, ?, 'pending')`
906
+ ).run(changeId, stage);
907
+ }
908
+ // 本地脏度(D-013 / task-04):新建 change 视为有未同步数据
909
+ this._touchLocalModified(cwd, changeName, now);
910
+ });
911
+
912
+ // 不再需要写文件:read() 已改为 SQL
913
+ return this.read(cwd, changeName);
914
+ }
915
+
916
+ setStage(cwd, stage, changeName = null) { return this._stepStore.setStage(cwd, stage, changeName); }
917
+
918
+ addStep(cwd, stage, stepName, changeName = null) { return this._stepStore.addStep(cwd, stage, stepName, changeName); }
919
+
920
+ updateStep(cwd, stage, stepName, options = {}, changeName = null) { return this._stepStore.updateStep(cwd, stage, stepName, options, changeName); }
921
+
922
+ _appendAuditLog(cwd, entry) { return this._consistency._appendAuditLog(cwd, entry); }
923
+
924
+ _validateStageArtifacts(cwd, stage, changeName) { return this._stageMachine._validateStageArtifacts(cwd, stage, changeName); }
925
+
926
+ completeStage(cwd, stage, changeName = null, opts = {}) { return this._stageMachine.completeStage(cwd, stage, changeName, opts); }
927
+
928
+ show(cwd, changeName = null) { return this._stageMachine.show(cwd, changeName); }
929
+
930
+ _showChange(cwd, changeName) { return this._stageMachine._showChange(cwd, changeName); }
931
+
932
+ _getNextSuggestion(data) { return this._stageMachine._getNextSuggestion(data); }
933
+
934
+ status(cwd, changeName = null) { return this._stageMachine.status(cwd, changeName); }
935
+
936
+ checkConsistency(cwd, changeName = null) { return this._consistency.checkConsistency(cwd, changeName); }
937
+
938
+ repairConsistency(cwd, opts = {}) { return this._consistency.repairConsistency(cwd, opts); }
939
+
940
+ validate(cwd, changeName = null) { return this._stageMachine.validate(cwd, changeName); }
941
+
942
+ reopenStage(cwd, stage, opts = {}) { return this._stageMachine.reopenStage(cwd, stage, opts); }
943
+
944
+ _getDownstreamStages(stage) { return this._stageMachine._getDownstreamStages(stage); }
945
+
946
+ reset(cwd, stage, changeName = null) { return this._stageMachine.reset(cwd, stage, changeName); }
947
+
948
+ // ── 内部辅助 ──
949
+
950
+ _readOrInit(cwd, changeName = null) {
951
+ let data = this.read(cwd, changeName);
952
+ if (!data) {
953
+ // 尝试自动检测变更名
954
+ if (!changeName) {
955
+ const changes = this.listChanges(cwd);
956
+ if (changes.length === 1) changeName = changes[0];
957
+ }
958
+ if (changeName) {
959
+ // 确保变更在 DB 中已初始化
960
+ const db = this._ensureDB(cwd);
961
+ db.transaction(() => {
962
+ const sqlDb = db.getDb();
963
+ const now = new Date().toISOString();
964
+ const ins = sqlDb.prepare(
965
+ `INSERT OR IGNORE INTO changes (name, current_stage, status, created_at, last_active) VALUES (?, 'scan', 'active', ?, ?)`
966
+ ).run(changeName, now, now);
967
+ const changeRow = sqlDb.prepare('SELECT id FROM changes WHERE name = ?').get(changeName);
968
+ if (changeRow !== undefined) {
969
+ const changeId = changeRow.id;
970
+ for (const s of VALID_STAGES) {
971
+ sqlDb.prepare(`INSERT OR IGNORE INTO stages (change_id, stage, status) VALUES (?, ?, 'pending')`).run(changeId, s);
972
+ }
973
+ }
974
+ // 只在真正创建 change 时标脏(D-013/task-04);读路径(change 已存在)不标,避免 pull 误判本地有未同步改动
975
+ if (ins.changes > 0) this._touchLocalModified(cwd, changeName, now);
976
+ });
977
+ this.registerChange(cwd, changeName);
978
+ }
979
+ if (!data) {
980
+ data = this.read(cwd, changeName);
981
+ }
982
+ if (!data) {
983
+ console.log('❌ 无法确定当前变更,请指定 --change <name>');
984
+ return null;
985
+ }
986
+ }
987
+ return data;
988
+ }
989
+
990
+ _requireStage(cwd, stage, changeName = null) {
991
+ if (!VALID_STAGES.includes(stage)) {
992
+ console.log(`❌ 未知阶段: ${stage},可选: ${VALID_STAGES.join(', ')}`);
993
+ return null;
994
+ }
995
+ const data = this._readOrInit(cwd, changeName);
996
+ if (!data) return null;
997
+ if (!data.stages[stage]) data.stages[stage] = emptyStage();
998
+ return data;
999
+ }
1000
+
1001
+ _timeAgo(dateStr) { return this._stageMachine._timeAgo(dateStr); }
1002
+
1003
+ // ── 批量进度 ──
1004
+
1005
+ updateBatchProgress(cwd, batchData, changeName = null) { return this._stepStore.updateBatchProgress(cwd, batchData, changeName); }
1006
+
1007
+ readBatchProgress(cwd, changeName = null) { return this._stepStore.readBatchProgress(cwd, changeName); }
1008
+
1009
+ _renderBatchProgress(batchProgress) { return this._stepStore._renderBatchProgress(batchProgress); }
1010
+
1011
+ _ensureGitignore(cwd) {
1012
+ // 外部 specDir 不需要修改项目 .gitignore
1013
+ if (this._customSpecDir) return;
1014
+ const gitignorePath = join(cwd, '.gitignore');
1015
+ const rule = '.sillyspec/.runtime/';
1016
+ if (existsSync(gitignorePath)) {
1017
+ const content = readFileSync(gitignorePath, 'utf8');
1018
+ if (content.includes(rule)) return;
1019
+ // 按既有 EOL 追加(2026-08-21 审查 BUG-9):CRLF 检出的文件混入 LF 行产生全文件
1020
+ // diff 噪声/autocrlf 折腾;写走原子 rename 防并发 init 双跑交错
1021
+ const eol = content.includes('\r\n') ? '\r\n' : '\n';
1022
+ writeAtomicSync(gitignorePath, content.trimEnd() + eol + rule + eol);
1023
+ } else {
1024
+ writeAtomicSync(gitignorePath, rule + '\n');
1025
+ }
1026
+ }
1027
+
1028
+ // ── plan.md 对齐(doctor --align-execute-progress 入口)──
1029
+
1030
+ /**
1031
+ * 解析 changeDir/tasks.md(任务注册表唯一真相)的 task checkbox 统计。
1032
+ * 2026-08-20-task-truth-unify:源从「plan.md 优先回退 tasks.md」改为 tasks.md 唯一源——
1033
+ * 旧顺序下新契约 plan.md(纯 ID 引用行)恒 total=0,doctor --align-execute-progress 会静默失效。
1034
+ * tasks.md 缺失时回退 plan.md(旧归档变更兼容读侧,不写侧迁移)。
1035
+ * 仅匹配 `- [ ] task-NN` / `- [x] task-NN` 形态的行(task- 前缀锚定,避免误捞非任务项)。
1036
+ * @param {string} changeDir - 变更目录绝对路径(含 tasks.md/plan.md)
1037
+ * @returns {{ total: number, checked: number }}
1038
+ */
1039
+ readPlanCheckboxStatus(changeDir) {
1040
+ if (!changeDir || typeof changeDir !== 'string') {
1041
+ throw new Error('changeDir 不能为空');
1042
+ }
1043
+ const tasksPath = join(changeDir, 'tasks.md');
1044
+ const planPath = join(changeDir, 'plan.md');
1045
+ let content = null;
1046
+ if (existsSync(tasksPath)) {
1047
+ content = readFileSync(tasksPath, 'utf8');
1048
+ } else if (existsSync(planPath)) {
1049
+ content = readFileSync(planPath, 'utf8');
1050
+ } else {
1051
+ return { total: 0, checked: 0 };
1052
+ }
1053
+ // 匹配 `- [ ] task-NN` / `- [x] task-NN`(允许 [x] 大小写、空格弹性、task- 前缀)
1054
+ const re = /^\s*[-*]\s+\[([ xX])\]\s+task-\d+/gm;
1055
+ let total = 0;
1056
+ let checked = 0;
1057
+ let m;
1058
+ while ((m = re.exec(content)) !== null) {
1059
+ total++;
1060
+ if (m[1] === 'x' || m[1] === 'X') checked++;
1061
+ }
1062
+ return { total, checked };
1063
+ }
1064
+
1065
+ /**
1066
+ * 按 plan.md 声明对齐 execute 阶段派生进度戳。
1067
+ * 仅当 plan.md 所有 task checkbox 全勾时,把 execute 阶段所有非 completed step 标 completed,
1068
+ * 并显式置 execute stageData.status='completed' + completedAt(绕过 completeStep 推导,D-003@v2)。
1069
+ * 不复核代码,信任 plan.md 声明(与 archive 同源,verify 阶段兜底,D-002/D-004)。
1070
+ *
1071
+ * @param {string} cwd
1072
+ * @param {string} changeName
1073
+ * @param {string} specBase - platformOpts.specRoot || join(cwd, '.sillyspec'),用于定位 changes 目录
1074
+ * @param {object} [opts]
1075
+ * @param {boolean} [opts.confirm=false] - 默认 dry-run,仅当 confirm=true 才落盘
1076
+ * @returns {{ ok: boolean, aligned: number, skipped: number, planTotal: number, planChecked: number, reason?: string, dryRun?: boolean }}
1077
+ */
1078
+ alignExecuteToPlan(cwd, changeName, specBase, opts = {}) {
1079
+ if (!changeName) throw new Error('changeName 不能为空');
1080
+ const { confirm = false } = opts;
1081
+
1082
+ // 1. 读 progress;无 progress / 无 execute 阶段 → 拒绝
1083
+ const progress = this.read(cwd, changeName);
1084
+ if (!progress || !progress.stages || !progress.stages.execute) {
1085
+ return { ok: false, aligned: 0, skipped: 0, planTotal: 0, planChecked: 0, reason: 'execute 阶段无进度数据' };
1086
+ }
1087
+ const executeStage = progress.stages.execute;
1088
+ const steps = Array.isArray(executeStage.steps) ? executeStage.steps : [];
1089
+ if (steps.length === 0) {
1090
+ return { ok: false, aligned: 0, skipped: 0, planTotal: 0, planChecked: 0, reason: 'execute 阶段无进度数据' };
1091
+ }
1092
+
1093
+ // 2. 读 plan.md checkbox;未全勾 → 拒绝(D-002)
1094
+ const specRoot = specBase || this._getSpecDir(cwd);
1095
+ const changeDir = join(specRoot, CHANGES_SUBDIR, changeName);
1096
+ const { total: planTotal, checked: planChecked } = this.readPlanCheckboxStatus(changeDir);
1097
+ if (planTotal === 0) {
1098
+ return { ok: false, aligned: 0, skipped: 0, planTotal, planChecked, reason: 'plan.md 无 task checkbox(无法判定完成度)' };
1099
+ }
1100
+ if (planChecked < planTotal) {
1101
+ return {
1102
+ ok: false,
1103
+ aligned: 0,
1104
+ skipped: 0,
1105
+ planTotal,
1106
+ planChecked,
1107
+ reason: `plan.md 有未勾选 task(${planChecked}/${planTotal}),拒绝对齐`,
1108
+ };
1109
+ }
1110
+
1111
+ // 2.5 最低事实核验:plan.md checkbox 可被手动勾选伪造,
1112
+ // 对齐前用 git 客观核验是否存在真实代码变更(能确证零变更时才拒绝,
1113
+ // unknown 不阻断——worktree 已清理且变更已提交的正常场景无法对账)。
1114
+ try {
1115
+ const evidence = checkExecuteCodeEvidence(cwd, changeName);
1116
+ if (evidence.status === 'unchanged') {
1117
+ return {
1118
+ ok: false,
1119
+ aligned: 0,
1120
+ skipped: 0,
1121
+ planTotal,
1122
+ planChecked,
1123
+ reason: `plan.md 全勾但代码零变更(${evidence.detail}),拒绝对齐 — 请先运行 sillyspec doctor --json 诊断`,
1124
+ };
1125
+ }
1126
+ } catch (e) {
1127
+ console.warn(`⚠️ 代码变更核验异常(不阻断对齐): ${e.message}`);
1128
+ }
1129
+
1130
+ // 3. 全勾:计算将补哪些 step
1131
+ const now = new Date().toISOString();
1132
+ let aligned = 0;
1133
+ let skipped = 0;
1134
+ for (const step of steps) {
1135
+ if (step.status === 'completed') {
1136
+ skipped++;
1137
+ continue;
1138
+ }
1139
+ aligned++;
1140
+ if (confirm) {
1141
+ step.status = 'completed';
1142
+ step.completedAt = now;
1143
+ }
1144
+ }
1145
+
1146
+ // dry-run:只报告,不落盘
1147
+ if (!confirm) {
1148
+ return { ok: true, aligned, skipped, planTotal, planChecked, dryRun: true };
1149
+ }
1150
+
1151
+ // 4. confirm:显式置 execute stageData.status='completed' + completedAt(D-003@v2,复刻 run.js:2303-2304)
1152
+ executeStage.status = 'completed';
1153
+ executeStage.completedAt = now;
1154
+ progress.currentStage = progress.currentStage || 'execute';
1155
+ progress.lastActive = now;
1156
+ this._write(cwd, progress, changeName);
1157
+
1158
+ return { ok: true, aligned, skipped, planTotal, planChecked };
1159
+ }
1160
+
1161
+ // ── 只读 dump(task-01/02/03:daemon 进度读取)──
1162
+
1163
+ /**
1164
+ * dump 输出的时间戳规范化:DB 内部两类形态(步骤推进时 JS Date 变量序列化
1165
+ * 的 ISO 形态、部分历史路径写入的 `YYYY/M/D H:mm:ss` 斜杠形态)统一转 ISO。
1166
+ * backend pydantic datetime 只吃 ISO(斜杠形态校验失败),斜杠 → new Date
1167
+ * 可解析;解析失败原样返回(backend 侧按无效丢弃)。
1168
+ */
1169
+ _dumpIso(ts) {
1170
+ if (!ts) return ts;
1171
+ if (typeof ts === 'string' && /^\d{4}-\d{2}-\d{2}/.test(ts)) return ts;
1172
+ const d = new Date(ts);
1173
+ if (Number.isNaN(d.getTime())) return ts;
1174
+ return d.toISOString();
1175
+ }
1176
+
1177
+ /**
1178
+ * 只读导出进度数据,供 daemon 通过 `sillyspec progress dump --json` 消费。
1179
+ *
1180
+ * 纯读路径:打开 DB 只读、读 user-inputs.md、列 artifacts 目录,不写任何状态。
1181
+ * 无活跃变更或 DB 不存在时返回 null(不抛异常,daemon 按 null 处理空数据)。
1182
+ *
1183
+ * 输出字段 snake_case + ISO 时间戳(2026-08-19-runtime-live-daemon-read
1184
+ * acceptance review P0 修复):契约消费端 backend RuntimeProgress pydantic
1185
+ * 是 snake_case(current_stage/last_active/started_at/size_bytes),
1186
+ * dump 早期误用内部 camelCase;跨端字段名断裂会让 pydantic 静默忽略
1187
+ * 未知字段导致前端核心字段全空。
1188
+ *
1189
+ * @param {string} cwd - specDir(`.sillyspec` 目录),由 CLI 层 --spec-dir 传入
1190
+ * @returns {object|null} 结构化进度数据,格式见 design.md §6.2
1191
+ */
1192
+ dump(cwd) {
1193
+ const specRoot = this._getSpecDir(cwd);
1194
+ const dbPath = this._runtimePath(cwd, 'sillyspec.db');
1195
+
1196
+ // DB 不存在 → 返回 null(项目未初始化进度)
1197
+ if (!existsSync(dbPath)) return null;
1198
+
1199
+ const db = this._ensureDB(cwd);
1200
+ const sqlDb = db.getDb();
1201
+
1202
+ // 1. project 行
1203
+ const projectRow = sqlDb.prepare('SELECT name FROM project WHERE id = 1').get();
1204
+ if (projectRow === undefined) return null;
1205
+ const projectName = projectRow.name;
1206
+
1207
+ // 2. 活跃变更(取 last_active 最新的一个)
1208
+ // ql-20260821-003:多活跃仓(变更隔离是常态,单仓可同时存在 N 个 active)下
1209
+ // 原 ORDER BY name 恒取字典序最前(通常是最老的变更),「当前变更/最后活动」
1210
+ // 停留在历史数据。dump 语义是「当前工作流状态」→ 取最近活跃的那个。
1211
+ const changeRows = sqlDb.prepare("SELECT id, name, current_stage, last_active FROM changes WHERE status = 'active' ORDER BY last_active DESC").all();
1212
+ if (changeRows.length === 0) {
1213
+ // 无活跃变更 → 返回仅含 project 的骨架
1214
+ return {
1215
+ project: projectName,
1216
+ current_stage: null,
1217
+ current_change: null,
1218
+ last_active: null,
1219
+ stages: {},
1220
+ user_inputs: this._readUserInputs(cwd),
1221
+ artifacts: this._listArtifacts(cwd),
1222
+ };
1223
+ }
1224
+
1225
+ const change = changeRows[0];
1226
+ const { id: changeId, name: changeName, current_stage: currentStage, last_active: lastActive } = change;
1227
+
1228
+ // 3. stages
1229
+ const stageRows = sqlDb.prepare(
1230
+ 'SELECT id, stage, status, started_at, completed_at, revision FROM stages WHERE change_id = ? ORDER BY id'
1231
+ ).all(changeId);
1232
+
1233
+ const stages = {};
1234
+ for (const s of VALID_STAGES) {
1235
+ stages[s] = { status: 'pending', steps: [] };
1236
+ }
1237
+ // PERF-06:一次 IN (...) 批量取全部 steps 再按 stage_id 分组(原逐 stage 查询是 N+1,
1238
+ // dump 是 daemon 轮询接口;与 read() :283-287 的批量读法对齐)
1239
+ const stepsByStage = new Map();
1240
+ if (stageRows.length > 0) {
1241
+ const placeholders = stageRows.map(() => '?').join(', ');
1242
+ const allStepRows = sqlDb.prepare(
1243
+ `SELECT stage_id, name, status, output, completed_at FROM steps WHERE stage_id IN (${placeholders}) ORDER BY stage_id, ordering`
1244
+ ).all(...stageRows.map(r => r.id));
1245
+ for (const sr of allStepRows) {
1246
+ if (!stepsByStage.has(sr.stage_id)) stepsByStage.set(sr.stage_id, []);
1247
+ stepsByStage.get(sr.stage_id).push(sr);
1248
+ }
1249
+ }
1250
+ for (const row of stageRows) {
1251
+ const stepRows = stepsByStage.get(row.id) || [];
1252
+ stages[row.stage] = {
1253
+ status: row.status,
1254
+ started_at: this._dumpIso(row.started_at) || undefined,
1255
+ completed_at: this._dumpIso(row.completed_at) || undefined,
1256
+ ...(row.revision ? { revision: row.revision } : {}),
1257
+ steps: stepRows.map(sr => ({
1258
+ name: sr.name,
1259
+ status: sr.status,
1260
+ ...(sr.output ? { output: sr.output } : {}),
1261
+ ...(sr.completed_at ? { completed_at: this._dumpIso(sr.completed_at) } : {}),
1262
+ })),
1263
+ };
1264
+ }
1265
+
1266
+ return {
1267
+ project: projectName,
1268
+ current_stage: currentStage || null,
1269
+ current_change: changeName,
1270
+ last_active: this._dumpIso(lastActive) || null,
1271
+ stages,
1272
+ user_inputs: this._readUserInputs(cwd),
1273
+ artifacts: this._listArtifacts(cwd),
1274
+ };
1275
+ }
1276
+
1277
+ /** 只读 user-inputs.md 内容(不存在返回 null) */
1278
+ _readUserInputs(cwd) {
1279
+ const p = this._runtimePath(cwd, 'user-inputs.md');
1280
+ if (!existsSync(p)) return null;
1281
+ return readFileSync(p, 'utf8');
1282
+ }
1283
+
1284
+ /** 列 artifacts 目录(不存在返回空数组) */
1285
+ _listArtifacts(cwd) {
1286
+ const dir = this._runtimePath(cwd, 'artifacts');
1287
+ if (!existsSync(dir)) return [];
1288
+ try {
1289
+ return readdirSync(dir, { withFileTypes: true })
1290
+ .filter(e => e.isFile())
1291
+ .map(e => {
1292
+ const fullPath = join(dir, e.name);
1293
+ const st = statSync(fullPath);
1294
+ return {
1295
+ filename: e.name,
1296
+ size_bytes: st.size,
1297
+ last_modified: st.mtime.toISOString(),
1298
+ };
1299
+ });
1300
+ } catch {
1301
+ return [];
1302
+ }
1303
+ }
1304
+ }