@seanmars/tospec 0.19.0-beta.7 → 0.20.0

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 (429) hide show
  1. package/CHANGELOG.md +60 -231
  2. package/README.md +69 -82
  3. package/assets/dashboard/app.js +14 -3
  4. package/assets/dashboard/style.css +7 -0
  5. package/assets/rules/tospec/decision.md +3 -0
  6. package/dist/cli/index.d.ts.map +1 -1
  7. package/dist/cli/index.js +227 -86
  8. package/dist/cli/index.js.map +1 -1
  9. package/dist/commands/config.d.ts +9 -17
  10. package/dist/commands/config.d.ts.map +1 -1
  11. package/dist/commands/config.js +366 -107
  12. package/dist/commands/config.js.map +1 -1
  13. package/dist/commands/dashboard.d.ts +57 -99
  14. package/dist/commands/dashboard.d.ts.map +1 -1
  15. package/dist/commands/dashboard.js +224 -282
  16. package/dist/commands/dashboard.js.map +1 -1
  17. package/dist/commands/decision.d.ts +41 -19
  18. package/dist/commands/decision.d.ts.map +1 -1
  19. package/dist/commands/decision.js +385 -79
  20. package/dist/commands/decision.js.map +1 -1
  21. package/dist/commands/metrics.d.ts +28 -51
  22. package/dist/commands/metrics.d.ts.map +1 -1
  23. package/dist/commands/metrics.js +62 -93
  24. package/dist/commands/metrics.js.map +1 -1
  25. package/dist/commands/shared-output.d.ts +18 -21
  26. package/dist/commands/shared-output.d.ts.map +1 -1
  27. package/dist/commands/shared-output.js +49 -23
  28. package/dist/commands/shared-output.js.map +1 -1
  29. package/dist/commands/show.d.ts +7 -0
  30. package/dist/commands/show.d.ts.map +1 -1
  31. package/dist/commands/show.js +29 -7
  32. package/dist/commands/show.js.map +1 -1
  33. package/dist/commands/validate.d.ts +43 -45
  34. package/dist/commands/validate.d.ts.map +1 -1
  35. package/dist/commands/validate.js +262 -129
  36. package/dist/commands/validate.js.map +1 -1
  37. package/dist/commands/workflow/index.d.ts +6 -10
  38. package/dist/commands/workflow/index.d.ts.map +1 -1
  39. package/dist/commands/workflow/index.js +6 -10
  40. package/dist/commands/workflow/index.js.map +1 -1
  41. package/dist/commands/workflow/instructions.d.ts +21 -8
  42. package/dist/commands/workflow/instructions.d.ts.map +1 -1
  43. package/dist/commands/workflow/instructions.js +254 -95
  44. package/dist/commands/workflow/instructions.js.map +1 -1
  45. package/dist/commands/workflow/new-change.d.ts +4 -5
  46. package/dist/commands/workflow/new-change.d.ts.map +1 -1
  47. package/dist/commands/workflow/new-change.js +90 -25
  48. package/dist/commands/workflow/new-change.js.map +1 -1
  49. package/dist/commands/workflow/schemas.d.ts +3 -5
  50. package/dist/commands/workflow/schemas.d.ts.map +1 -1
  51. package/dist/commands/workflow/schemas.js +37 -11
  52. package/dist/commands/workflow/schemas.js.map +1 -1
  53. package/dist/commands/workflow/shared.d.ts +48 -21
  54. package/dist/commands/workflow/shared.d.ts.map +1 -1
  55. package/dist/commands/workflow/shared.js +36 -33
  56. package/dist/commands/workflow/shared.js.map +1 -1
  57. package/dist/commands/workflow/status.d.ts +10 -6
  58. package/dist/commands/workflow/status.d.ts.map +1 -1
  59. package/dist/commands/workflow/status.js +81 -42
  60. package/dist/commands/workflow/status.js.map +1 -1
  61. package/dist/commands/workflow/templates.d.ts +10 -3
  62. package/dist/commands/workflow/templates.d.ts.map +1 -1
  63. package/dist/commands/workflow/templates.js +39 -40
  64. package/dist/commands/workflow/templates.js.map +1 -1
  65. package/dist/core/archive.d.ts +26 -21
  66. package/dist/core/archive.d.ts.map +1 -1
  67. package/dist/core/archive.js +378 -235
  68. package/dist/core/archive.js.map +1 -1
  69. package/dist/core/artifact-graph/graph.d.ts +25 -42
  70. package/dist/core/artifact-graph/graph.d.ts.map +1 -1
  71. package/dist/core/artifact-graph/graph.js +45 -63
  72. package/dist/core/artifact-graph/graph.js.map +1 -1
  73. package/dist/core/artifact-graph/index.d.ts +1 -1
  74. package/dist/core/artifact-graph/index.d.ts.map +1 -1
  75. package/dist/core/artifact-graph/index.js +1 -1
  76. package/dist/core/artifact-graph/index.js.map +1 -1
  77. package/dist/core/artifact-graph/instruction-loader.d.ts +97 -103
  78. package/dist/core/artifact-graph/instruction-loader.d.ts.map +1 -1
  79. package/dist/core/artifact-graph/instruction-loader.js +146 -119
  80. package/dist/core/artifact-graph/instruction-loader.js.map +1 -1
  81. package/dist/core/artifact-graph/outputs.d.ts +9 -23
  82. package/dist/core/artifact-graph/outputs.d.ts.map +1 -1
  83. package/dist/core/artifact-graph/outputs.js +45 -38
  84. package/dist/core/artifact-graph/outputs.js.map +1 -1
  85. package/dist/core/artifact-graph/resolver.d.ts +44 -63
  86. package/dist/core/artifact-graph/resolver.d.ts.map +1 -1
  87. package/dist/core/artifact-graph/resolver.js +85 -86
  88. package/dist/core/artifact-graph/resolver.js.map +1 -1
  89. package/dist/core/artifact-graph/schema.d.ts +0 -6
  90. package/dist/core/artifact-graph/schema.d.ts.map +1 -1
  91. package/dist/core/artifact-graph/schema.js +7 -32
  92. package/dist/core/artifact-graph/schema.js.map +1 -1
  93. package/dist/core/artifact-graph/state.d.ts +1 -8
  94. package/dist/core/artifact-graph/state.d.ts.map +1 -1
  95. package/dist/core/artifact-graph/state.js +2 -17
  96. package/dist/core/artifact-graph/state.js.map +1 -1
  97. package/dist/core/artifact-graph/stub-detection.d.ts +12 -0
  98. package/dist/core/artifact-graph/stub-detection.d.ts.map +1 -0
  99. package/dist/core/artifact-graph/stub-detection.js +39 -0
  100. package/dist/core/artifact-graph/stub-detection.js.map +1 -0
  101. package/dist/core/artifact-graph/types.d.ts +4 -0
  102. package/dist/core/artifact-graph/types.d.ts.map +1 -1
  103. package/dist/core/artifact-graph/types.js +30 -10
  104. package/dist/core/artifact-graph/types.js.map +1 -1
  105. package/dist/core/available-tools.d.ts +3 -12
  106. package/dist/core/available-tools.d.ts.map +1 -1
  107. package/dist/core/available-tools.js +4 -13
  108. package/dist/core/available-tools.js.map +1 -1
  109. package/dist/core/change-metadata/schema.d.ts +1 -1
  110. package/dist/core/change-metadata/schema.d.ts.map +1 -1
  111. package/dist/core/change-metadata/schema.js +10 -7
  112. package/dist/core/change-metadata/schema.js.map +1 -1
  113. package/dist/core/change-presenter.d.ts +23 -18
  114. package/dist/core/change-presenter.d.ts.map +1 -1
  115. package/dist/core/change-presenter.js +102 -43
  116. package/dist/core/change-presenter.js.map +1 -1
  117. package/dist/core/change-status-policy.d.ts +8 -1
  118. package/dist/core/change-status-policy.d.ts.map +1 -1
  119. package/dist/core/change-status-policy.js +25 -1
  120. package/dist/core/change-status-policy.js.map +1 -1
  121. package/dist/core/codex-metrics.d.ts +25 -45
  122. package/dist/core/codex-metrics.d.ts.map +1 -1
  123. package/dist/core/codex-metrics.js +44 -88
  124. package/dist/core/codex-metrics.js.map +1 -1
  125. package/dist/core/codex-residue.d.ts +14 -15
  126. package/dist/core/codex-residue.d.ts.map +1 -1
  127. package/dist/core/codex-residue.js +18 -22
  128. package/dist/core/codex-residue.js.map +1 -1
  129. package/dist/core/command-generation/adapters/claude.d.ts +2 -9
  130. package/dist/core/command-generation/adapters/claude.d.ts.map +1 -1
  131. package/dist/core/command-generation/adapters/claude.js +2 -12
  132. package/dist/core/command-generation/adapters/claude.js.map +1 -1
  133. package/dist/core/command-generation/adapters/index.d.ts +1 -9
  134. package/dist/core/command-generation/adapters/index.d.ts.map +1 -1
  135. package/dist/core/command-generation/adapters/index.js +1 -9
  136. package/dist/core/command-generation/adapters/index.js.map +1 -1
  137. package/dist/core/command-generation/generator.d.ts +0 -17
  138. package/dist/core/command-generation/generator.d.ts.map +1 -1
  139. package/dist/core/command-generation/generator.js +0 -17
  140. package/dist/core/command-generation/generator.js.map +1 -1
  141. package/dist/core/command-generation/index.d.ts +2 -5
  142. package/dist/core/command-generation/index.d.ts.map +1 -1
  143. package/dist/core/command-generation/index.js +0 -9
  144. package/dist/core/command-generation/index.js.map +1 -1
  145. package/dist/core/command-generation/types.d.ts +10 -36
  146. package/dist/core/command-generation/types.d.ts.map +1 -1
  147. package/dist/core/command-generation/types.js +0 -6
  148. package/dist/core/command-generation/types.js.map +1 -1
  149. package/dist/core/command-generation/yaml.d.ts +3 -18
  150. package/dist/core/command-generation/yaml.d.ts.map +1 -1
  151. package/dist/core/command-generation/yaml.js +5 -23
  152. package/dist/core/command-generation/yaml.js.map +1 -1
  153. package/dist/core/config-prompts.d.ts +2 -4
  154. package/dist/core/config-prompts.d.ts.map +1 -1
  155. package/dist/core/config-prompts.js +2 -7
  156. package/dist/core/config-prompts.js.map +1 -1
  157. package/dist/core/config-schema.d.ts +8 -53
  158. package/dist/core/config-schema.d.ts.map +1 -1
  159. package/dist/core/config-schema.js +49 -62
  160. package/dist/core/config-schema.js.map +1 -1
  161. package/dist/core/config.d.ts +39 -26
  162. package/dist/core/config.d.ts.map +1 -1
  163. package/dist/core/config.js +36 -22
  164. package/dist/core/config.js.map +1 -1
  165. package/dist/core/dashboard-activity.d.ts +7 -9
  166. package/dist/core/dashboard-activity.d.ts.map +1 -1
  167. package/dist/core/dashboard-activity.js +26 -24
  168. package/dist/core/dashboard-activity.js.map +1 -1
  169. package/dist/core/dashboard-data.d.ts +40 -22
  170. package/dist/core/dashboard-data.d.ts.map +1 -1
  171. package/dist/core/dashboard-data.js +62 -70
  172. package/dist/core/dashboard-data.js.map +1 -1
  173. package/dist/core/global-config.d.ts +24 -53
  174. package/dist/core/global-config.d.ts.map +1 -1
  175. package/dist/core/global-config.js +38 -67
  176. package/dist/core/global-config.js.map +1 -1
  177. package/dist/core/init.d.ts +25 -19
  178. package/dist/core/init.d.ts.map +1 -1
  179. package/dist/core/init.js +168 -181
  180. package/dist/core/init.js.map +1 -1
  181. package/dist/core/list.d.ts +1 -1
  182. package/dist/core/list.d.ts.map +1 -1
  183. package/dist/core/list.js +121 -28
  184. package/dist/core/list.js.map +1 -1
  185. package/dist/core/local-server.d.ts +41 -83
  186. package/dist/core/local-server.d.ts.map +1 -1
  187. package/dist/core/local-server.js +53 -98
  188. package/dist/core/local-server.js.map +1 -1
  189. package/dist/core/markdown-render.d.ts +25 -0
  190. package/dist/core/markdown-render.d.ts.map +1 -0
  191. package/dist/core/markdown-render.js +94 -0
  192. package/dist/core/markdown-render.js.map +1 -0
  193. package/dist/core/migrate.d.ts +29 -14
  194. package/dist/core/migrate.d.ts.map +1 -1
  195. package/dist/core/migrate.js +184 -122
  196. package/dist/core/migrate.js.map +1 -1
  197. package/dist/core/parsers/change-parser.d.ts +7 -10
  198. package/dist/core/parsers/change-parser.d.ts.map +1 -1
  199. package/dist/core/parsers/change-parser.js +48 -56
  200. package/dist/core/parsers/change-parser.js.map +1 -1
  201. package/dist/core/parsers/markdown-parser.d.ts +8 -9
  202. package/dist/core/parsers/markdown-parser.d.ts.map +1 -1
  203. package/dist/core/parsers/markdown-parser.js +31 -22
  204. package/dist/core/parsers/markdown-parser.js.map +1 -1
  205. package/dist/core/parsers/requirement-blocks.d.ts +43 -15
  206. package/dist/core/parsers/requirement-blocks.d.ts.map +1 -1
  207. package/dist/core/parsers/requirement-blocks.js +142 -70
  208. package/dist/core/parsers/requirement-blocks.js.map +1 -1
  209. package/dist/core/parsers/requirement-text.d.ts +73 -79
  210. package/dist/core/parsers/requirement-text.d.ts.map +1 -1
  211. package/dist/core/parsers/requirement-text.js +137 -79
  212. package/dist/core/parsers/requirement-text.js.map +1 -1
  213. package/dist/core/parsers/spec-structure.d.ts.map +1 -1
  214. package/dist/core/parsers/spec-structure.js +10 -6
  215. package/dist/core/parsers/spec-structure.js.map +1 -1
  216. package/dist/core/profiles.d.ts +3 -10
  217. package/dist/core/profiles.d.ts.map +1 -1
  218. package/dist/core/profiles.js +5 -12
  219. package/dist/core/profiles.js.map +1 -1
  220. package/dist/core/project-config.d.ts +43 -44
  221. package/dist/core/project-config.d.ts.map +1 -1
  222. package/dist/core/project-config.js +107 -82
  223. package/dist/core/project-config.js.map +1 -1
  224. package/dist/core/project-layout.d.ts +9 -17
  225. package/dist/core/project-layout.d.ts.map +1 -1
  226. package/dist/core/project-layout.js +16 -26
  227. package/dist/core/project-layout.js.map +1 -1
  228. package/dist/core/root-selection.d.ts +11 -7
  229. package/dist/core/root-selection.d.ts.map +1 -1
  230. package/dist/core/root-selection.js +7 -8
  231. package/dist/core/root-selection.js.map +1 -1
  232. package/dist/core/rules.d.ts +6 -1
  233. package/dist/core/rules.d.ts.map +1 -1
  234. package/dist/core/rules.js +23 -2
  235. package/dist/core/rules.js.map +1 -1
  236. package/dist/core/schema-names.d.ts +16 -0
  237. package/dist/core/schema-names.d.ts.map +1 -0
  238. package/dist/core/schema-names.js +16 -0
  239. package/dist/core/schema-names.js.map +1 -0
  240. package/dist/core/schemas/base.schema.d.ts +3 -0
  241. package/dist/core/schemas/base.schema.d.ts.map +1 -1
  242. package/dist/core/schemas/base.schema.js +22 -6
  243. package/dist/core/schemas/base.schema.js.map +1 -1
  244. package/dist/core/schemas/change.schema.d.ts +16 -0
  245. package/dist/core/schemas/change.schema.d.ts.map +1 -1
  246. package/dist/core/schemas/change.schema.js +41 -10
  247. package/dist/core/schemas/change.schema.js.map +1 -1
  248. package/dist/core/schemas/spec.schema.d.ts +2 -0
  249. package/dist/core/schemas/spec.schema.d.ts.map +1 -1
  250. package/dist/core/shared/index.d.ts +3 -8
  251. package/dist/core/shared/index.d.ts.map +1 -1
  252. package/dist/core/shared/index.js +3 -8
  253. package/dist/core/shared/index.js.map +1 -1
  254. package/dist/core/shared/rules-generation.d.ts +19 -8
  255. package/dist/core/shared/rules-generation.d.ts.map +1 -1
  256. package/dist/core/shared/rules-generation.js +117 -50
  257. package/dist/core/shared/rules-generation.js.map +1 -1
  258. package/dist/core/shared/skill-generation.d.ts +28 -43
  259. package/dist/core/shared/skill-generation.d.ts.map +1 -1
  260. package/dist/core/shared/skill-generation.js +82 -51
  261. package/dist/core/shared/skill-generation.js.map +1 -1
  262. package/dist/core/shared/tool-detection.d.ts +39 -61
  263. package/dist/core/shared/tool-detection.d.ts.map +1 -1
  264. package/dist/core/shared/tool-detection.js +88 -80
  265. package/dist/core/shared/tool-detection.js.map +1 -1
  266. package/dist/core/skill-metrics.d.ts +36 -63
  267. package/dist/core/skill-metrics.d.ts.map +1 -1
  268. package/dist/core/skill-metrics.js +34 -73
  269. package/dist/core/skill-metrics.js.map +1 -1
  270. package/dist/core/spec-presenter.js +6 -6
  271. package/dist/core/spec-presenter.js.map +1 -1
  272. package/dist/core/specs-apply.d.ts +22 -23
  273. package/dist/core/specs-apply.d.ts.map +1 -1
  274. package/dist/core/specs-apply.js +166 -193
  275. package/dist/core/specs-apply.js.map +1 -1
  276. package/dist/core/templates/fragments/interview.d.ts +2 -6
  277. package/dist/core/templates/fragments/interview.d.ts.map +1 -1
  278. package/dist/core/templates/fragments/interview.js +2 -6
  279. package/dist/core/templates/fragments/interview.js.map +1 -1
  280. package/dist/core/templates/fragments/next-step.d.ts +4 -8
  281. package/dist/core/templates/fragments/next-step.d.ts.map +1 -1
  282. package/dist/core/templates/fragments/next-step.js +4 -8
  283. package/dist/core/templates/fragments/next-step.js.map +1 -1
  284. package/dist/core/templates/fragments/validate.d.ts +13 -0
  285. package/dist/core/templates/fragments/validate.d.ts.map +1 -0
  286. package/dist/core/templates/fragments/validate.js +13 -0
  287. package/dist/core/templates/fragments/validate.js.map +1 -0
  288. package/dist/core/templates/fragments/verify.d.ts +9 -12
  289. package/dist/core/templates/fragments/verify.d.ts.map +1 -1
  290. package/dist/core/templates/fragments/verify.js +9 -12
  291. package/dist/core/templates/fragments/verify.js.map +1 -1
  292. package/dist/core/templates/index.d.ts +0 -6
  293. package/dist/core/templates/index.d.ts.map +1 -1
  294. package/dist/core/templates/index.js +0 -7
  295. package/dist/core/templates/index.js.map +1 -1
  296. package/dist/core/templates/skill-templates.d.ts +1 -5
  297. package/dist/core/templates/skill-templates.d.ts.map +1 -1
  298. package/dist/core/templates/skill-templates.js +0 -5
  299. package/dist/core/templates/skill-templates.js.map +1 -1
  300. package/dist/core/templates/types.d.ts +3 -7
  301. package/dist/core/templates/types.d.ts.map +1 -1
  302. package/dist/core/templates/types.js +0 -3
  303. package/dist/core/templates/types.js.map +1 -1
  304. package/dist/core/templates/workflows/apply.d.ts +3 -9
  305. package/dist/core/templates/workflows/apply.d.ts.map +1 -1
  306. package/dist/core/templates/workflows/apply.js +11 -13
  307. package/dist/core/templates/workflows/apply.js.map +1 -1
  308. package/dist/core/templates/workflows/archive.d.ts +0 -6
  309. package/dist/core/templates/workflows/archive.d.ts.map +1 -1
  310. package/dist/core/templates/workflows/archive.js +19 -6
  311. package/dist/core/templates/workflows/archive.js.map +1 -1
  312. package/dist/core/templates/workflows/decision.js +4 -4
  313. package/dist/core/templates/workflows/decision.js.map +1 -1
  314. package/dist/core/templates/workflows/explore.js +1 -1
  315. package/dist/core/templates/workflows/grill.d.ts.map +1 -1
  316. package/dist/core/templates/workflows/grill.js +0 -2
  317. package/dist/core/templates/workflows/grill.js.map +1 -1
  318. package/dist/core/templates/workflows/issue.d.ts +0 -6
  319. package/dist/core/templates/workflows/issue.d.ts.map +1 -1
  320. package/dist/core/templates/workflows/issue.js +3 -2
  321. package/dist/core/templates/workflows/issue.js.map +1 -1
  322. package/dist/core/templates/workflows/propose.d.ts +0 -6
  323. package/dist/core/templates/workflows/propose.d.ts.map +1 -1
  324. package/dist/core/templates/workflows/propose.js +2 -2
  325. package/dist/core/templates/workflows/propose.js.map +1 -1
  326. package/dist/core/templates/workflows/sync.d.ts +2 -8
  327. package/dist/core/templates/workflows/sync.d.ts.map +1 -1
  328. package/dist/core/templates/workflows/sync.js +4 -3
  329. package/dist/core/templates/workflows/sync.js.map +1 -1
  330. package/dist/core/templates/workflows/update.d.ts +0 -6
  331. package/dist/core/templates/workflows/update.d.ts.map +1 -1
  332. package/dist/core/templates/workflows/update.js +9 -2
  333. package/dist/core/templates/workflows/update.js.map +1 -1
  334. package/dist/core/update.d.ts +23 -23
  335. package/dist/core/update.d.ts.map +1 -1
  336. package/dist/core/update.js +139 -118
  337. package/dist/core/update.js.map +1 -1
  338. package/dist/core/user-state-migration.d.ts +13 -15
  339. package/dist/core/user-state-migration.d.ts.map +1 -1
  340. package/dist/core/user-state-migration.js +16 -20
  341. package/dist/core/user-state-migration.js.map +1 -1
  342. package/dist/core/validation/constants.d.ts +4 -10
  343. package/dist/core/validation/constants.d.ts.map +1 -1
  344. package/dist/core/validation/constants.js +25 -20
  345. package/dist/core/validation/constants.js.map +1 -1
  346. package/dist/core/validation/prose-length.d.ts +15 -0
  347. package/dist/core/validation/prose-length.d.ts.map +1 -0
  348. package/dist/core/validation/prose-length.js +29 -0
  349. package/dist/core/validation/prose-length.js.map +1 -0
  350. package/dist/core/validation/purpose-placeholder.d.ts +9 -16
  351. package/dist/core/validation/purpose-placeholder.d.ts.map +1 -1
  352. package/dist/core/validation/purpose-placeholder.js +30 -44
  353. package/dist/core/validation/purpose-placeholder.js.map +1 -1
  354. package/dist/core/validation/section-validator.d.ts +4 -4
  355. package/dist/core/validation/section-validator.d.ts.map +1 -1
  356. package/dist/core/validation/section-validator.js +43 -7
  357. package/dist/core/validation/section-validator.js.map +1 -1
  358. package/dist/core/validation/task-numbering.d.ts +6 -3
  359. package/dist/core/validation/task-numbering.d.ts.map +1 -1
  360. package/dist/core/validation/task-numbering.js +23 -11
  361. package/dist/core/validation/task-numbering.js.map +1 -1
  362. package/dist/core/validation/types.d.ts +18 -0
  363. package/dist/core/validation/types.d.ts.map +1 -1
  364. package/dist/core/validation/types.js +12 -1
  365. package/dist/core/validation/types.js.map +1 -1
  366. package/dist/core/validation/validator.d.ts +43 -63
  367. package/dist/core/validation/validator.d.ts.map +1 -1
  368. package/dist/core/validation/validator.js +500 -267
  369. package/dist/core/validation/validator.js.map +1 -1
  370. package/dist/prompts/searchable-multi-select.d.ts +3 -8
  371. package/dist/prompts/searchable-multi-select.d.ts.map +1 -1
  372. package/dist/prompts/searchable-multi-select.js +16 -39
  373. package/dist/prompts/searchable-multi-select.js.map +1 -1
  374. package/dist/utils/change-metadata.d.ts +11 -50
  375. package/dist/utils/change-metadata.d.ts.map +1 -1
  376. package/dist/utils/change-metadata.js +48 -67
  377. package/dist/utils/change-metadata.js.map +1 -1
  378. package/dist/utils/change-utils.d.ts +30 -54
  379. package/dist/utils/change-utils.d.ts.map +1 -1
  380. package/dist/utils/change-utils.js +133 -91
  381. package/dist/utils/change-utils.js.map +1 -1
  382. package/dist/utils/file-lock.d.ts +39 -0
  383. package/dist/utils/file-lock.d.ts.map +1 -0
  384. package/dist/utils/file-lock.js +149 -0
  385. package/dist/utils/file-lock.js.map +1 -0
  386. package/dist/utils/file-system.d.ts +12 -32
  387. package/dist/utils/file-system.d.ts.map +1 -1
  388. package/dist/utils/file-system.js +16 -40
  389. package/dist/utils/file-system.js.map +1 -1
  390. package/dist/utils/frontmatter.d.ts +7 -11
  391. package/dist/utils/frontmatter.d.ts.map +1 -1
  392. package/dist/utils/frontmatter.js +11 -11
  393. package/dist/utils/frontmatter.js.map +1 -1
  394. package/dist/utils/interactive.d.ts +4 -9
  395. package/dist/utils/interactive.d.ts.map +1 -1
  396. package/dist/utils/interactive.js +2 -4
  397. package/dist/utils/interactive.js.map +1 -1
  398. package/dist/utils/item-discovery.d.ts +15 -10
  399. package/dist/utils/item-discovery.d.ts.map +1 -1
  400. package/dist/utils/item-discovery.js +42 -47
  401. package/dist/utils/item-discovery.js.map +1 -1
  402. package/dist/utils/link.d.ts +9 -18
  403. package/dist/utils/link.d.ts.map +1 -1
  404. package/dist/utils/link.js +9 -18
  405. package/dist/utils/link.js.map +1 -1
  406. package/dist/utils/requirement-diff.d.ts +13 -23
  407. package/dist/utils/requirement-diff.d.ts.map +1 -1
  408. package/dist/utils/requirement-diff.js +13 -23
  409. package/dist/utils/requirement-diff.js.map +1 -1
  410. package/dist/utils/spec-files.d.ts +7 -20
  411. package/dist/utils/spec-files.d.ts.map +1 -1
  412. package/dist/utils/spec-files.js +26 -51
  413. package/dist/utils/spec-files.js.map +1 -1
  414. package/dist/utils/task-progress.d.ts +11 -9
  415. package/dist/utils/task-progress.d.ts.map +1 -1
  416. package/dist/utils/task-progress.js +53 -32
  417. package/dist/utils/task-progress.js.map +1 -1
  418. package/dist/utils/timestamp.d.ts +5 -8
  419. package/dist/utils/timestamp.d.ts.map +1 -1
  420. package/dist/utils/timestamp.js +5 -8
  421. package/dist/utils/timestamp.js.map +1 -1
  422. package/package.json +2 -3
  423. package/schemas/decision/templates/decision.md +3 -1
  424. package/schemas/decision/templates/index.md +2 -2
  425. package/schemas/issue/schema.yaml +8 -1
  426. package/schemas/issue/templates/spec.md +27 -2
  427. package/schemas/sdd/schema.yaml +20 -1
  428. package/schemas/sdd/templates/spec.md +27 -2
  429. /package/assets/rules/tospec/{single-sourc-of-truth.md → single-source-of-truth.md} +0 -0
@@ -1,16 +1,68 @@
1
1
  import { readFileSync, promises as fs } from 'fs';
2
2
  import path from 'path';
3
- import { SpecSchema, ChangeSchema } from '../schemas/index.js';
3
+ import { SpecSchema } from '../schemas/index.js';
4
4
  import { MarkdownParser } from '../parsers/markdown-parser.js';
5
- import { ChangeParser } from '../parsers/change-parser.js';
6
- import { MIN_PURPOSE_LENGTH, MAX_REQUIREMENT_TEXT_LENGTH, VALIDATION_MESSAGES } from './constants.js';
5
+ import { MIN_PURPOSE_LENGTH, MAX_REQUIREMENT_TEXT_LENGTH, MAX_DELTAS_PER_CHANGE, VALIDATION_MESSAGES } from './constants.js';
6
+ import { proseLength } from './prose-length.js';
7
7
  import { parseDeltaSpec, normalizeRequirementName, extractRequirementsSection } from '../parsers/requirement-blocks.js';
8
- import { extractRequirementBody as extractRequirementBodyShared, containsShallOrMust as containsShallOrMustShared, analyzeScenarios, scanCodeFences, findMissingScenarios, } from '../parsers/requirement-text.js';
8
+ import { extractRequirementBody as extractRequirementBodyShared, containsShallOrMust, analyzeScenarios, scanCodeFences, findMissingScenarios, findDroppedBullets, withoutScenarios, normalizeDocument, } from '../parsers/requirement-text.js';
9
9
  import { findMainSpecStructureIssues } from '../parsers/spec-structure.js';
10
10
  import { findPurposePlaceholderIssue } from './purpose-placeholder.js';
11
11
  import { FileSystemUtils, extractNameFromPath, isMissingPathError } from '../../utils/file-system.js';
12
12
  import { findAllMarkdownFiles } from '../../utils/spec-files.js';
13
- import { findSpecUpdates, buildUpdatedSpec } from '../specs-apply.js';
13
+ import { findSpecUpdates, buildUpdatedSpec, extractDeltaPurpose } from '../specs-apply.js';
14
+ /**
15
+ * The one place the `## REMOVED Scenarios` grammar is spelled out in a
16
+ * message. Both the "omits scenario(s)" error and the empty-section error
17
+ * point here, so an author who reached either sees the exact lines to write
18
+ * instead of being sent to the template.
19
+ */
20
+ const REMOVED_SCENARIOS_GRAMMAR = 'Each entry is three bullets: "- Requirement: `<name>`" / "- Scenario: `<name>`" / "- Reason: <why>".';
21
+ /**
22
+ * Merge notices the archive dry run forwards as validation warnings: a REMOVED
23
+ * block naming something the target spec does not have, so archiving deletes
24
+ * nothing. Matched by code, not message text, so rewording a notice cannot
25
+ * switch the check off.
26
+ */
27
+ const REMOVED_NOOP_NOTICE_CODES = new Set([
28
+ 'archive_removed_requirement_absent',
29
+ 'archive_removed_ignored_new_spec',
30
+ ]);
31
+ /**
32
+ * Merge failures the structural pass already reports under its own wording:
33
+ * duplicate or cross-section names (`validation failed - ...`), a section that
34
+ * parsed to nothing, and a MODIFIED that drops a scenario. Matched by the
35
+ * fixed prefix each message opens with; the rest of a message carries names
36
+ * that vary per delta.
37
+ */
38
+ const STRUCTURAL_MERGE_FAILURE = /( validation failed - |^Delta parsing found no operations|current spec contains scenario\(s\) not present)/;
39
+ /**
40
+ * A name the template shipped and nobody replaced: `[name]`, `[old name]`,
41
+ * `[scenario name]`. Bracketed end to end, which is how every placeholder in
42
+ * the shipped templates is spelled and how no real name is.
43
+ *
44
+ * ERROR, unlike the whole-artifact stub check, because a placeholder that
45
+ * reaches archive is merged into the main spec as a requirement literally
46
+ * named "[name]" — and the stub check cannot catch it once any other line of
47
+ * the file has been edited. This is what makes the template's promise that a
48
+ * placeholder section "left as-is does not validate" true.
49
+ */
50
+ function isTemplatePlaceholder(name) {
51
+ return /^\[.*\]$/.test(name.trim());
52
+ }
53
+ /**
54
+ * One `path` notation across the report. Zod hands back a segment array that
55
+ * `join('.')` renders as `requirements.0.scenarios`, while every hand-written
56
+ * rule here writes `requirements[0]` — so the same report used two spellings
57
+ * for the same address and neither was safely parseable.
58
+ */
59
+ function formatIssuePath(segments) {
60
+ return segments.reduce((acc, segment) => {
61
+ if (typeof segment === 'number')
62
+ return `${acc}[${segment}]`;
63
+ return acc ? `${acc}.${String(segment)}` : String(segment);
64
+ }, '');
65
+ }
14
66
  export class Validator {
15
67
  strictMode;
16
68
  constructor(strictMode = false) {
@@ -28,14 +80,10 @@ export class Validator {
28
80
  { level: 'ERROR', path: 'file', message: this.enrichTopLevelError(specName, baseMessage) },
29
81
  ]);
30
82
  }
31
- // Everything past the read is identical to the content path — keeping one
32
- // body is what stops `validate` and `archive` grading the same spec
33
- // differently.
83
+ // One body past the read, so `validate` and `archive` cannot grade the same
84
+ // spec differently.
34
85
  return this.validateSpecContent(specName, content);
35
86
  }
36
- /**
37
- * Validate spec content from a string (used for pre-write validation of rebuilt specs)
38
- */
39
87
  async validateSpecContent(specName, content) {
40
88
  const issues = [];
41
89
  try {
@@ -54,56 +102,19 @@ export class Validator {
54
102
  }
55
103
  return this.createReport(issues);
56
104
  }
57
- async validateChange(filePath) {
58
- const issues = [];
59
- const changeName = extractNameFromPath(filePath);
60
- try {
61
- const content = readFileSync(filePath, 'utf-8');
62
- const changeDir = path.dirname(filePath);
63
- const parser = new ChangeParser(content, changeDir);
64
- const change = await parser.parseChangeWithDeltas(changeName);
65
- const result = ChangeSchema.safeParse(change);
66
- if (!result.success) {
67
- issues.push(...this.convertZodErrors(result.error));
68
- }
69
- issues.push(...this.applyChangeRules(change, content));
70
- }
71
- catch (error) {
72
- const baseMessage = error instanceof Error ? error.message : 'Unknown error';
73
- const enriched = this.enrichTopLevelError(changeName, baseMessage);
74
- issues.push({
75
- level: 'ERROR',
76
- path: 'file',
77
- message: enriched,
78
- });
79
- }
80
- return this.createReport(issues);
81
- }
82
105
  /**
83
- * Validate delta-formatted spec files under a change directory.
84
- * Enforces:
85
- * - At least one delta across all files
86
- * - ADDED/MODIFIED: each requirement has SHALL/MUST and at least one scenario
87
- * - REMOVED: names only; no scenario/description required
88
- * - RENAMED: pairs well-formed
89
- * - No duplicates within sections; no cross-section conflicts per spec
90
- * - MODIFIED: no scenario the current main spec still has is dropped
106
+ * Validate delta-formatted spec files under a change directory: at least one
107
+ * delta overall, ADDED/MODIFIED requirements carrying SHALL/MUST and a
108
+ * scenario, well-formed REMOVED (names only) and RENAMED (FROM:/TO: pairs)
109
+ * entries, no duplicate or cross-section names, and no scenario the current
110
+ * main spec still has dropped by a MODIFIED.
91
111
  *
92
- * `mainSpecsDir` enables that last rule; without it the scenario-loss check is
93
- * skipped, because there is nothing to compare against. Callers that have the
94
- * project root should always pass it — archive refuses these deltas either
95
- * way, and the check only decides whether the user learns now or at archive
96
- * time.
97
- */
98
- /**
99
- * `archivePreflight` is opt-out because the dry run below is worth its cost to
100
- * exactly one caller. It rebuilds every updated spec — re-reading and
101
- * re-parsing the delta and the whole main spec per capability — to report,
102
- * at INFO, what the merge would refuse. For `tospec validate` that is the
103
- * point: the author learns before they try. For `archive` it is pure
104
- * duplication, because archive runs the real merge moments later and already
105
- * turns the same precondition into `archive_spec_update_failed` with a
106
- * non-zero exit, which the INFO never had the level to do.
112
+ * `mainSpecsDir` enables that last rule; without it there is nothing to
113
+ * compare against, so it is skipped. Archive refuses such deltas either way.
114
+ *
115
+ * `archivePreflight` is opt-out because the dry run rebuilds every updated
116
+ * spec. For `tospec validate` that is the point; for `archive` it is
117
+ * duplication, since the real merge follows moments later.
107
118
  */
108
119
  async validateChangeDeltaSpecs(changeDir, mainSpecsDir, options = {}) {
109
120
  const archivePreflight = options.archivePreflight ?? true;
@@ -114,20 +125,14 @@ export class Validator {
114
125
  const missingHeaderSpecs = [];
115
126
  const emptySections = [];
116
127
  try {
117
- // The walk below is recursive, but its purpose is to *reject* anything
118
- // outside specs/<capability>/spec.md, not to support it. The layout is
119
- // fixed at exactly one directory level; see
120
- // tospec/decisions/20260730_014309-delta-spec-layout-one-level.md, which
121
- // reverses the nested multi-area support added in #1182b. Only validation
122
- // ever went recursive — the merge path (findSpecUpdates) never did — so a
123
- // misplaced file that validates clean is a file that archives into
124
- // nothing. Validation is the only place that can catch it.
128
+ // The walk below is recursive in order to *reject* anything outside
129
+ // specs/<capability>/spec.md: the layout is fixed at exactly one directory
130
+ // level (tospec/decisions/20260730_014309-delta-spec-layout-one-level.md).
131
+ // findSpecUpdates never went recursive, so a misplaced file that validates
132
+ // clean is a file that archives into nothing.
125
133
  const rootSpecPath = path.join(specsDir, 'spec.md');
126
- // A spec.md directly at the specs/ root has no capability folder, so the
127
- // apply/archive merge path (findSpecUpdates) drops it: without this error
128
- // the change validates clean and archives while its requirements never
129
- // reach the main specs. Only a regular file counts — a *directory* named
130
- // spec.md is a capability folder like any other.
134
+ // Only a regular file counts — a *directory* named spec.md is a capability
135
+ // folder like any other.
131
136
  const rootSpecStat = await fs.stat(rootSpecPath).catch(() => null);
132
137
  if (rootSpecStat?.isFile() === true) {
133
138
  hasMisplacedSpec = true;
@@ -137,19 +142,17 @@ export class Validator {
137
142
  message: 'Delta spec found at specs/spec.md. Delta specs must live in a capability folder (e.g. specs/<capability>/spec.md) — a file at the specs/ root is ignored when the change is applied or archived.',
138
143
  });
139
144
  }
140
- // Report each misplaced file once, here, and drop it from the delta pass
141
- // below — validating it as if it were a real delta would contradict the
142
- // error that just said it will never be applied.
145
+ // Report each misplaced file once and drop it from the delta pass below —
146
+ // validating it as a real delta would contradict the error that just said
147
+ // it will never be applied.
143
148
  const specFiles = [];
144
149
  for (const specFile of await findAllMarkdownFiles(specsDir)) {
145
150
  if (specFile === rootSpecPath)
146
151
  continue; // already reported above
147
152
  const entryPath = FileSystemUtils.toPosixPath(path.relative(specsDir, specFile));
148
153
  const segments = entryPath.split('/');
149
- // A stray .md directly at specs/ (no capability folder) isn't this
150
- // guard's concern — archive's own spec.md-only backstop
151
- // (src/core/archive.ts, "orphans") already treats a non-spec.md file
152
- // at this depth as harmless clutter rather than a lost delta, and the
154
+ // A stray .md directly at specs/ is not this guard's concern: archive's
155
+ // orphan backstop treats it as clutter rather than a lost delta, and the
153
156
  // two must keep agreeing.
154
157
  if (segments.length === 1)
155
158
  continue;
@@ -165,10 +168,9 @@ export class Validator {
165
168
  });
166
169
  continue;
167
170
  }
168
- // fast-glob (which computes artifact status from the schema's
169
- // specs/*/spec.md) skips dot-directories, while the merge path's
170
- // readdir does not. A dot capability would archive without ever
171
- // showing as done — the same class of silent divergence.
171
+ // fast-glob (which computes artifact status) skips dot-directories while
172
+ // the merge path's readdir does not, so a dot capability would archive
173
+ // without ever showing done.
172
174
  if (segments[0].startsWith('.')) {
173
175
  hasMisplacedSpec = true;
174
176
  issues.push({
@@ -178,12 +180,9 @@ export class Validator {
178
180
  });
179
181
  continue;
180
182
  }
181
- // Right folder, wrong basename — findAllMarkdownFiles is what makes
182
- // this visible at all; findSpecFiles filters by basename === 'spec.md'
183
- // before any guard sees it, so the merge path (which reads only
184
- // specs/<capability>/spec.md) silently drops the file while validation
185
- // reported clean. Any *.md here is either a delta that will be lost or
186
- // clutter that belongs elsewhere, so both are flagged the same way.
183
+ // Right folder, wrong basename. findSpecFiles filters on
184
+ // basename === 'spec.md', so the merge path silently drops the file;
185
+ // findAllMarkdownFiles is what makes it visible here at all.
187
186
  if (segments[1] !== 'spec.md') {
188
187
  hasMisplacedSpec = true;
189
188
  issues.push({
@@ -196,18 +195,29 @@ export class Validator {
196
195
  specFiles.push(specFile);
197
196
  }
198
197
  for (const specFile of specFiles) {
198
+ const entryPath = FileSystemUtils.toPosixPath(path.relative(specsDir, specFile));
199
199
  let content;
200
200
  try {
201
201
  content = await fs.readFile(specFile, 'utf-8');
202
202
  }
203
- catch {
203
+ catch (error) {
204
+ // A file the walk just listed but cannot be read (EACCES, EIO) is a
205
+ // delta, not an absence: skipping it let a change whose only delta
206
+ // was unreadable validate clean and fail inside archive instead. Only
207
+ // a path that vanished between the walk and the read may be skipped.
208
+ if (isMissingPathError(error))
209
+ continue;
210
+ issues.push({
211
+ level: 'ERROR',
212
+ path: entryPath,
213
+ message: `Delta spec specs/${entryPath} exists but could not be read, so it was not validated: ${error instanceof Error ? error.message : String(error)}`,
214
+ });
204
215
  continue;
205
216
  }
206
217
  const plan = parseDeltaSpec(content);
207
- const entryPath = FileSystemUtils.toPosixPath(path.relative(specsDir, specFile));
208
- // An unclosed fence masks every following line — surface it instead
209
- // of silently hiding the rest of the document (report 2.3).
210
- const fenceScan = scanCodeFences(content.split(/\r?\n/));
218
+ // An unclosed fence masks every following line — surface it instead of
219
+ // silently hiding the rest of the document.
220
+ const fenceScan = scanCodeFences(normalizeDocument(content).split('\n'));
211
221
  if (fenceScan.unclosedFenceLine !== null) {
212
222
  issues.push({
213
223
  level: 'ERROR',
@@ -216,12 +226,14 @@ export class Validator {
216
226
  message: `Code fence opened at line ${fenceScan.unclosedFenceLine} is never closed — all content after it is invisible to the parser. Close the fence.`,
217
227
  });
218
228
  }
219
- // Two identical delta headers are an editing accident (a manual edit, a
220
- // badly resolved merge, an agent emitting the section twice), and
221
- // combining them would guess which one the author meant. The parser no
222
- // longer discards the repeated occurrences, so refusing here costs
223
- // nothing that was previously reported: before, the first occurrence's
224
- // requirements were invisible to this very check.
229
+ // A new capability's `## Purpose` is carried verbatim into the main spec
230
+ // archive creates, so the main-spec Purpose rules must run before the
231
+ // copy — otherwise the change archives and only then fails
232
+ // `validate --all --strict`, from a source now under changes/archive/.
233
+ // New capabilities only: an existing one owns its Purpose.
234
+ issues.push(...(await this.collectDeltaPurposeIssues(content, entryPath, mainSpecsDir)));
235
+ // Two identical delta headers are an editing accident, and combining
236
+ // them would guess which one the author meant.
225
237
  for (const duplicate of plan.duplicateSections) {
226
238
  issues.push({
227
239
  level: 'ERROR',
@@ -230,14 +242,24 @@ export class Validator {
230
242
  message: `Delta section "${duplicate.title}" appears more than once (lines ${duplicate.lines.join(', ')}). Merge them into a single section — two headers with the same name are ambiguous about which requirements belong to which.`,
231
243
  });
232
244
  }
245
+ // A present section that yields no entry is a grammar miss, not an
246
+ // empty section: the author wrote something there. Left unreported, the
247
+ // MODIFIED block keeps failing the scenario-loss check with no sign that
248
+ // its declaration was skipped.
249
+ if (plan.sectionPresence.removedScenarios && plan.removedScenarios.length === 0) {
250
+ issues.push({
251
+ level: 'ERROR',
252
+ path: entryPath,
253
+ message: `"## REMOVED Scenarios" declares nothing the parser recognises. ${REMOVED_SCENARIOS_GRAMMAR}`,
254
+ });
255
+ }
233
256
  const hasSections = plan.sectionPresence.added ||
234
257
  plan.sectionPresence.modified ||
235
258
  plan.sectionPresence.removed ||
236
259
  plan.sectionPresence.renamed;
237
260
  const hasEntries = plan.added.length + plan.modified.length + plan.removed.length + plan.renamed.length > 0;
238
- // hasEntries sums all four categories, so once it is false every
239
- // section present in sectionPresence is individually empty too — no
240
- // extra per-section length check is needed to know that.
261
+ // hasEntries sums all four categories, so once it is false every section
262
+ // present in sectionPresence is individually empty too.
241
263
  if (!hasEntries) {
242
264
  if (hasSections) {
243
265
  if (plan.sectionPresence.added)
@@ -258,9 +280,8 @@ export class Validator {
258
280
  const removedNames = new Set();
259
281
  const renamedFrom = new Set();
260
282
  const renamedTo = new Set();
261
- // ADDED and MODIFIED carry identical per-requirement rules. One body
262
- // means a new rule cannot land on only one of the two sections; the
263
- // outer loop preserves the all-ADDED-then-all-MODIFIED issue order.
283
+ // ADDED and MODIFIED carry identical per-requirement rules, so one body
284
+ // stops a new rule landing on only one of them.
264
285
  for (const [section, blocks, seen] of [
265
286
  ['ADDED', plan.added, addedNames],
266
287
  ['MODIFIED', plan.modified, modifiedNames],
@@ -268,6 +289,17 @@ export class Validator {
268
289
  for (const block of blocks) {
269
290
  const key = normalizeRequirementName(block.name);
270
291
  totalDeltas++;
292
+ if (isTemplatePlaceholder(block.name)) {
293
+ // One finding per block: its body is the template's too, and the
294
+ // keyword and scenario checks would only restate that.
295
+ issues.push({
296
+ level: 'ERROR',
297
+ path: entryPath,
298
+ line: block.startLine,
299
+ message: `${section} "${block.name}" (line ${block.startLine}) still carries the template's placeholder name. Replace it with the requirement's real name and fill in the block, or delete the block if this change does not need it.`,
300
+ });
301
+ continue;
302
+ }
271
303
  if (seen.has(key)) {
272
304
  issues.push({ level: 'ERROR', path: entryPath, message: `Duplicate requirement in ${section}: "${block.name}"` });
273
305
  }
@@ -278,28 +310,66 @@ export class Validator {
278
310
  if (!requirementText) {
279
311
  issues.push({ level: 'ERROR', path: entryPath, message: `${section} "${block.name}" is missing requirement text` });
280
312
  }
281
- else if (!this.containsShallOrMust(requirementText)) {
313
+ else if (!containsShallOrMust(requirementText)) {
282
314
  // WARNING, not ERROR: the keyword check is English-only, so at
283
- // ERROR it blocked any requirement whose body states its
284
- // obligation in another language — enforcing a documentation
285
- // language, not normative strength. `--strict` still refuses it
286
- // (strictMode counts warnings as fatal).
287
- // Decision: tospec/decisions/20260814_134116-shall-must-missing-is-a-warning.md
288
- issues.push({ level: 'WARNING', path: entryPath, message: this.buildMissingShallOrMustMessage(`${section} "${block.name}"`, block.name) });
315
+ // ERROR it blocked requirements written in another language.
316
+ // `--strict` still refuses it.
317
+ // tospec/decisions/20260814_134116-shall-must-missing-is-a-warning.md
318
+ issues.push({
319
+ level: 'WARNING',
320
+ path: entryPath,
321
+ ...this.buildMissingShallOrMustMessage(`${section} "${block.name}"`, block.name),
322
+ });
289
323
  }
290
324
  issues.push(...this.collectScenarioIssues(section, block, entryPath));
291
325
  }
292
326
  }
293
- if (mainSpecsDir !== undefined && plan.modified.length > 0) {
327
+ // Also entered on declarations alone: a `## REMOVED Scenarios` with no
328
+ // MODIFIED block matches nothing by construction, and gating on
329
+ // MODIFIED meant the "declaration matched nothing" error below could
330
+ // never fire for the one delta shape where it is always true. The
331
+ // declaration removes nothing by itself (the MODIFIED omission is the
332
+ // mechanism), so such a change archived with the scenario intact.
333
+ // tospec/decisions/20260918_230803-removed-scenarios-is-the-declared-path.md
334
+ // Dropped from the plan once reported: a placeholder entry would
335
+ // otherwise also fail the "matched nothing" check, naming one mistake
336
+ // twice.
337
+ const removedScenarios = plan.removedScenarios.filter((entry) => {
338
+ const placeholders = [entry.requirement, entry.scenario].filter(isTemplatePlaceholder);
339
+ if (placeholders.length === 0)
340
+ return true;
341
+ issues.push({
342
+ level: 'ERROR',
343
+ path: entryPath,
344
+ line: entry.startLine,
345
+ message: `REMOVED Scenarios entry (line ${entry.startLine}) still carries the template's placeholder ${placeholders
346
+ .map((name) => `"${name}"`)
347
+ .join(' and ')}. Name the requirement and the scenario being dropped, or delete the section if this change drops none.`,
348
+ });
349
+ return false;
350
+ });
351
+ if (mainSpecsDir !== undefined && (plan.modified.length > 0 || removedScenarios.length > 0)) {
352
+ const renamedToFrom = new Map();
353
+ for (const { from, to } of plan.renamed) {
354
+ renamedToFrom.set(normalizeRequirementName(to), from);
355
+ }
294
356
  // entryPath is always "<capability>/spec.md" here — misplaced and
295
357
  // dot-prefixed files were reported and dropped above.
296
- issues.push(...(await this.collectDroppedScenarioIssues(mainSpecsDir, entryPath.split('/')[0], plan.modified, entryPath)));
358
+ issues.push(...(await this.collectDroppedScenarioIssues(mainSpecsDir, entryPath.split('/')[0], plan.modified, entryPath, renamedToFrom, removedScenarios)));
297
359
  }
298
- // Validate REMOVED — the template requires Reason and Migration
299
- // fields on every entry (report 2.4).
360
+ // The template requires Reason and Migration on every REMOVED entry.
300
361
  for (const entry of plan.removedEntries) {
301
362
  const key = normalizeRequirementName(entry.name);
302
363
  totalDeltas++;
364
+ if (isTemplatePlaceholder(entry.name)) {
365
+ issues.push({
366
+ level: 'ERROR',
367
+ path: entryPath,
368
+ line: entry.startLine,
369
+ message: `REMOVED "${entry.name}" (line ${entry.startLine}) still carries the template's placeholder name. Name the requirement being removed, or delete the section if this change removes none.`,
370
+ });
371
+ continue;
372
+ }
303
373
  if (removedNames.has(key)) {
304
374
  issues.push({ level: 'ERROR', path: entryPath, message: `Duplicate requirement in REMOVED: "${entry.name}"` });
305
375
  }
@@ -323,7 +393,7 @@ export class Validator {
323
393
  });
324
394
  }
325
395
  }
326
- // Orphaned FROM:/TO: lines were silently dropped before (report 2.4).
396
+ // Orphaned FROM:/TO: lines would otherwise be dropped silently.
327
397
  for (const renamedIssue of plan.renamedIssues) {
328
398
  const description = renamedIssue.kind === 'from-without-to'
329
399
  ? `RENAMED FROM "${renamedIssue.name}" (line ${renamedIssue.line}) has no matching TO: line`
@@ -335,11 +405,21 @@ export class Validator {
335
405
  message: `${description} — write RENAMED entries as a FROM:/TO: pair.`,
336
406
  });
337
407
  }
338
- // Validate RENAMED pairs
339
408
  for (const { from, to } of plan.renamed) {
340
409
  const fromKey = normalizeRequirementName(from);
341
410
  const toKey = normalizeRequirementName(to);
342
411
  totalDeltas++;
412
+ const placeholders = [from, to].filter(isTemplatePlaceholder);
413
+ if (placeholders.length > 0) {
414
+ issues.push({
415
+ level: 'ERROR',
416
+ path: entryPath,
417
+ message: `RENAMED entry still carries the template's placeholder ${placeholders
418
+ .map((name) => `"${name}"`)
419
+ .join(' and ')}. Name the requirement being renamed and its new name, or delete the section if this change renames none.`,
420
+ });
421
+ continue;
422
+ }
343
423
  if (renamedFrom.has(fromKey)) {
344
424
  issues.push({ level: 'ERROR', path: entryPath, message: `Duplicate FROM in RENAMED: "${from}"` });
345
425
  }
@@ -353,7 +433,6 @@ export class Validator {
353
433
  renamedTo.add(toKey);
354
434
  }
355
435
  }
356
- // Cross-section conflicts (within the same spec file)
357
436
  for (const n of modifiedNames) {
358
437
  if (removedNames.has(n)) {
359
438
  issues.push({ level: 'ERROR', path: entryPath, message: `Requirement present in both MODIFIED and REMOVED: "${n}"` });
@@ -379,8 +458,12 @@ export class Validator {
379
458
  }
380
459
  }
381
460
  }
382
- catch {
383
- // If no specs dir, treat as no deltas
461
+ catch (error) {
462
+ // Only an absent specs dir means "no deltas". The walk and the reads
463
+ // above already answer that on their own, so anything else reaching here
464
+ // is a real failure that a bare catch used to turn into a clean verdict.
465
+ if (!isMissingPathError(error))
466
+ throw error;
384
467
  }
385
468
  for (const { path: specPath, kind, header } of emptySections) {
386
469
  issues.push({
@@ -396,24 +479,27 @@ export class Validator {
396
479
  message: 'No delta sections found. Add headers such as "## ADDED Requirements" or move non-delta notes outside specs/.',
397
480
  });
398
481
  }
399
- // Runs here, after every structural error has been pushed, so the exclusion
400
- // set below is just "what has already been reported". Calling it inside the
401
- // loop above meant hand-splicing the two lists that are only raised down
402
- // here — a set that any later check would silently fall out of.
403
- //
404
482
  // The checks above compare a delta against itself and, for MODIFIED, against
405
483
  // the main spec's scenarios. None asks whether the main spec can supply the
406
- // target the delta acts on — the merge's own preconditions, which nothing
407
- // consulted until archive.
484
+ // target the delta acts on — the merge's own preconditions.
408
485
  if (mainSpecsDir !== undefined && archivePreflight) {
409
- issues.push(...(await this.findArchiveBlockers(changeDir, mainSpecsDir, issues.filter((issue) => issue.level === 'ERROR').map((issue) => issue.path))));
486
+ issues.push(...(await this.findArchiveBlockers(changeDir, mainSpecsDir)));
410
487
  }
411
- // A misplaced-spec error already names the file and the fix; adding "No
412
- // deltas found" on top would contradict it, since the deltas are sitting in
413
- // the file just reported.
488
+ // A misplaced-spec error already names the file and the fix; "No deltas
489
+ // found" on top would contradict it.
414
490
  if (totalDeltas === 0 && !hasMisplacedSpec) {
415
491
  issues.push({ level: 'ERROR', path: 'file', message: this.enrichTopLevelError('change', VALIDATION_MESSAGES.CHANGE_NO_DELTAS) });
416
492
  }
493
+ // The ceiling `ChangeSchema.deltas.max()` declares. WARNING because the rule
494
+ // is advice about change size, not a correctness claim; `--strict` is what
495
+ // turns advice into a gate.
496
+ if (totalDeltas > MAX_DELTAS_PER_CHANGE) {
497
+ issues.push({
498
+ level: 'WARNING',
499
+ path: 'file',
500
+ message: `${VALIDATION_MESSAGES.CHANGE_TOO_MANY_DELTAS} (found ${totalDeltas}).`,
501
+ });
502
+ }
417
503
  return this.createReport(issues);
418
504
  }
419
505
  convertZodErrors(error) {
@@ -422,16 +508,22 @@ export class Validator {
422
508
  if (message === VALIDATION_MESSAGES.CHANGE_NO_DELTAS) {
423
509
  message = `${message}. ${VALIDATION_MESSAGES.GUIDE_NO_DELTAS}`;
424
510
  }
511
+ // The guidance used to ride on a second, lower-severity copy of this
512
+ // finding emitted by applySpecRules. Appended here instead so the report
513
+ // carries one issue per fact, at the severity that decides the exit code.
514
+ if (message === VALIDATION_MESSAGES.REQUIREMENT_NO_SCENARIOS) {
515
+ message = `${message}. ${VALIDATION_MESSAGES.GUIDE_SCENARIO_FORMAT}`;
516
+ }
425
517
  return {
426
518
  level: 'ERROR',
427
- path: err.path.join('.'),
519
+ path: formatIssuePath(err.path),
428
520
  message,
429
521
  };
430
522
  });
431
523
  }
432
524
  applySpecRules(spec, content) {
433
525
  const issues = [];
434
- const fenceScan = scanCodeFences(content.split(/\r?\n/));
526
+ const fenceScan = scanCodeFences(normalizeDocument(content).split('\n'));
435
527
  if (fenceScan.unclosedFenceLine !== null) {
436
528
  issues.push({
437
529
  level: 'ERROR',
@@ -448,10 +540,8 @@ export class Validator {
448
540
  message: structuralIssue.message,
449
541
  });
450
542
  }
451
- // The generated placeholder is longer than MIN_PURPOSE_LENGTH, so the
452
- // brevity check below cannot reach it; it is reported on its own terms
453
- // instead. Checked first because a hand-written "TBD" is both a placeholder
454
- // and too brief, and only one of those two tells the author what to do.
543
+ // Checked before brevity: a hand-written "TBD" is both a placeholder and too
544
+ // brief, and only the placeholder message tells the author what to do.
455
545
  const placeholder = findPurposePlaceholderIssue(spec.overview, content);
456
546
  if (placeholder) {
457
547
  issues.push({
@@ -461,7 +551,7 @@ export class Validator {
461
551
  message: VALIDATION_MESSAGES.PURPOSE_IS_PLACEHOLDER,
462
552
  });
463
553
  }
464
- else if (spec.overview.length < MIN_PURPOSE_LENGTH) {
554
+ else if (proseLength(spec.overview) < MIN_PURPOSE_LENGTH) {
465
555
  issues.push({
466
556
  level: 'WARNING',
467
557
  path: 'overview',
@@ -476,62 +566,29 @@ export class Validator {
476
566
  message: VALIDATION_MESSAGES.REQUIREMENT_TOO_LONG,
477
567
  });
478
568
  }
479
- if (req.scenarios.length === 0) {
480
- issues.push({
481
- level: 'WARNING',
482
- path: `requirements[${index}].scenarios`,
483
- message: `${VALIDATION_MESSAGES.REQUIREMENT_NO_SCENARIOS}. ${VALIDATION_MESSAGES.GUIDE_SCENARIO_FORMAT}`,
484
- });
485
- }
569
+ // A missing scenario is not checked here: SpecSchema's `scenarios.min(1)`
570
+ // already reports it as an ERROR, and convertZodErrors appends the same
571
+ // format guidance this branch used to carry. Two copies of one fact, at
572
+ // two severities, only made the report ambiguous about which to fix.
486
573
  });
487
- // SHALL/MUST body-keyword enforcement for main specs (#1156). The main-spec
488
- // parser collapses the requirement header into `text`, so we recover the
489
- // header+body pairs here (the same source the delta path trusts) and reuse
490
- // the delta detection: a body that omits the keyword errors, with the
491
- // targeted "move it to the body line" hint when the keyword is in the header
492
- // only and the generic message otherwise. Emitted exactly once per
493
- // requirement (the Zod refine that used to emit a generic error is removed).
574
+ // The main-spec parser collapses the requirement header into `text`, so
575
+ // recover the header+body pairs here — the same source the delta path
576
+ // trusts — and reuse the delta detection.
494
577
  extractRequirementsSection(content).bodyBlocks.forEach((block, index) => {
495
578
  const requirementText = this.extractRequirementText(block.raw);
496
- // Both conditions stay one branch on purpose. An absent body here is not
497
- // a "missing text" defect: it is the header-only pattern
498
- // (`### Requirement: The system MUST ...` with no body line), and the
499
- // hint that fires for it — move the statement to the body — is the
500
- // intended answer. Splitting them re-reports that case as missing text
501
- // and loses the hint.
579
+ // One branch on purpose: an absent body here is the header-only pattern
580
+ // (`### Requirement: The system MUST ...` with no body line), whose hint —
581
+ // move the statement to the body — is the intended answer.
502
582
  //
503
583
  // WARNING, not ERROR: the keyword check is English-only, so at ERROR it
504
- // blocked any requirement stating its obligation in another language —
505
- // enforcing a documentation language, not normative strength. `--strict`
506
- // still refuses it (strictMode counts warnings as fatal).
507
- // Decision: tospec/decisions/20260814_134116-shall-must-missing-is-a-warning.md
508
- if (!requirementText || !this.containsShallOrMust(requirementText)) {
584
+ // blocked requirements written in another language. `--strict` still
585
+ // refuses it.
586
+ // tospec/decisions/20260814_134116-shall-must-missing-is-a-warning.md
587
+ if (!requirementText || !containsShallOrMust(requirementText)) {
509
588
  issues.push({
510
589
  level: 'WARNING',
511
590
  path: `requirements[${index}]`,
512
- message: this.buildMissingShallOrMustMessage(`Requirement "${block.name}"`, block.name),
513
- });
514
- }
515
- });
516
- return issues;
517
- }
518
- applyChangeRules(change, content) {
519
- const issues = [];
520
- const MIN_DELTA_DESCRIPTION_LENGTH = 10;
521
- change.deltas.forEach((delta, index) => {
522
- if (!delta.description || delta.description.length < MIN_DELTA_DESCRIPTION_LENGTH) {
523
- issues.push({
524
- level: 'WARNING',
525
- path: `deltas[${index}].description`,
526
- message: VALIDATION_MESSAGES.DELTA_DESCRIPTION_TOO_BRIEF,
527
- });
528
- }
529
- if ((delta.operation === 'ADDED' || delta.operation === 'MODIFIED') &&
530
- (!delta.requirements || delta.requirements.length === 0)) {
531
- issues.push({
532
- level: 'WARNING',
533
- path: `deltas[${index}].requirements`,
534
- message: `${delta.operation} ${VALIDATION_MESSAGES.DELTA_MISSING_REQUIREMENTS}`,
591
+ ...this.buildMissingShallOrMustMessage(`Requirement "${block.name}"`, block.name),
535
592
  });
536
593
  }
537
594
  });
@@ -557,78 +614,135 @@ export class Validator {
557
614
  const valid = this.strictMode
558
615
  ? errors === 0 && warnings === 0
559
616
  : errors === 0;
617
+ // One report, one copy of each rule's background: the note belongs to the
618
+ // rule, not to the line that tripped it.
619
+ const notes = [...new Set(issues.map((issue) => issue.note).filter((n) => !!n))];
620
+ const flattened = issues.map(({ note: _note, ...issue }) => issue);
560
621
  return {
561
622
  valid,
562
- issues,
623
+ issues: flattened,
563
624
  summary: {
564
625
  errors,
565
626
  warnings,
566
627
  info,
567
628
  },
629
+ ...(notes.length ? { notes } : {}),
568
630
  };
569
631
  }
570
632
  extractRequirementText(blockRaw) {
571
- // Delegate to the shared, fence-/metadata-/multi-line-aware body reader.
572
- // Validation intentionally does not use the parser/display header-title
573
- // fallback for canonical `### Requirement:` blocks: a SHALL/MUST that
574
- // appears only in the header must still receive the body-keyword hint.
575
- // Line 0 is the `### Requirement: ...` header.
633
+ // Line 0 is the `### Requirement: ...` header. Validation deliberately skips
634
+ // the parser's header-title fallback: a SHALL/MUST that appears only in the
635
+ // header must still receive the body-keyword hint.
576
636
  const [, ...bodyLines] = blockRaw.split('\n');
577
637
  return extractRequirementBodyShared(bodyLines) || undefined;
578
638
  }
579
- containsShallOrMust(text) {
580
- return containsShallOrMustShared(text);
581
- }
582
639
  /**
583
- * Build an error message for a requirement block whose body lacks SHALL/MUST.
584
- *
585
- * When the SHALL/MUST keyword already appears in the requirement header (e.g.
586
- * `### Requirement: The system SHALL ...`) the original generic error
587
- * ("must contain SHALL or MUST") is confusing because the keyword is visibly
588
- * present in the spec. Per the Tospec conventions the keyword has to live
589
- * on the requirement body line (the line right after the header), so we point
590
- * the author at that exact fix when the keyword is found in the header only.
640
+ * When the keyword already appears in the header (`### Requirement: The system
641
+ * SHALL ...`) the generic "must contain SHALL or MUST" reads as wrong, since
642
+ * the keyword is visibly there. The convention puts it on the body line, so
643
+ * point the author at that exact fix instead.
591
644
  */
592
645
  buildMissingShallOrMustMessage(prefix, blockName) {
593
646
  const base = `${prefix} must contain SHALL or MUST`;
594
- if (this.containsShallOrMust(blockName)) {
595
- return `${base} in the requirement body, not only in the header. Move the SHALL/MUST statement to the line immediately after the "### Requirement: ..." header.`;
647
+ if (containsShallOrMust(blockName)) {
648
+ return {
649
+ message: `${base} in the requirement body, not only in the header. Move the SHALL/MUST statement to the line immediately after the "### Requirement: ..." header.`,
650
+ };
651
+ }
652
+ // Carried as a `note`, not appended to the message: it is identical for
653
+ // every requirement, and inlining reprinted the paragraph once per
654
+ // occurrence, burying the names that actually differ.
655
+ return {
656
+ message: `${base}.`,
657
+ note: 'SHALL/MUST detection matches those two English keywords only — a requirement that states ' +
658
+ 'its obligation in another language will always report this. It stays a warning for that ' +
659
+ 'reason; if your specs are not written in English, prefer `tospec validate` over `--strict`, ' +
660
+ 'which treats warnings as fatal.',
661
+ };
662
+ }
663
+ /**
664
+ * The main spec's two Purpose rules, applied to a delta that is about to
665
+ * create that main spec. Placeholder before brevity, as on the spec path.
666
+ *
667
+ * `mainSpecsDir` absent means new capabilities cannot be told from existing
668
+ * ones, so nothing is reported.
669
+ */
670
+ async collectDeltaPurposeIssues(content, entryPath, mainSpecsDir) {
671
+ if (mainSpecsDir === undefined)
672
+ return [];
673
+ const purpose = extractDeltaPurpose(content);
674
+ const capability = entryPath.split('/')[0];
675
+ try {
676
+ await fs.access(path.join(mainSpecsDir, capability, 'spec.md'));
677
+ return []; // Capability exists: its own spec owns the Purpose.
678
+ }
679
+ catch (error) {
680
+ // Only a genuinely absent spec means "new capability"; guessing "new"
681
+ // would report a Purpose that is never copied.
682
+ if (!isMissingPathError(error))
683
+ return [];
684
+ }
685
+ // WARNING, not ERROR: the schema calls the Purpose mandatory, but archive
686
+ // still completes with a placeholder, so this is advice on where the text
687
+ // belongs rather than a merge precondition. Reported here because archive
688
+ // is the only other place that notices, and by then the delta is under
689
+ // changes/archive/ where nobody edits it.
690
+ if (!purpose) {
691
+ return [{ level: 'WARNING', path: entryPath, message: VALIDATION_MESSAGES.DELTA_PURPOSE_MISSING }];
692
+ }
693
+ const placeholder = findPurposePlaceholderIssue(purpose, content);
694
+ if (placeholder) {
695
+ return [
696
+ {
697
+ level: 'WARNING',
698
+ path: entryPath,
699
+ line: placeholder.line,
700
+ message: VALIDATION_MESSAGES.DELTA_PURPOSE_IS_PLACEHOLDER,
701
+ },
702
+ ];
703
+ }
704
+ if (proseLength(purpose) < MIN_PURPOSE_LENGTH) {
705
+ return [{ level: 'WARNING', path: entryPath, message: VALIDATION_MESSAGES.DELTA_PURPOSE_TOO_BRIEF }];
596
706
  }
597
- return base;
707
+ return [];
598
708
  }
599
709
  /**
600
710
  * Scenarios a MODIFIED block would delete from the current main spec.
601
711
  *
602
712
  * A MODIFIED replaces the whole requirement, so a scenario the block omits is
603
- * lost. `specs-apply` already refuses to apply such a block, but only at
604
- * archive time — so a change could validate clean, be implemented and
605
- * reviewed, and fail days later at the most expensive possible moment. Both
606
- * sides now call `findMissingScenarios`, so validate reports exactly what
607
- * archive refuses.
713
+ * lost. `specs-apply` refuses such a block too, but only at archive time. Both
714
+ * sides call `findMissingScenarios`, so validate reports what archive refuses.
608
715
  *
609
- * Deliberately silent in two cases, because archive gates them separately and
610
- * a warning here would be a false alarm:
611
- * - the main spec file does not exist yet (the capability is new)
612
- * - the requirement header is absent from it (a MODIFIED written against a
613
- * sister change still in flight)
716
+ * Silent when the main spec does not exist yet (new capability) or lacks the
717
+ * requirement header (a MODIFIED written against a sister change still in
718
+ * flight): archive gates both separately.
614
719
  */
615
- async collectDroppedScenarioIssues(mainSpecsDir, capability, modified, entryPath) {
720
+ async collectDroppedScenarioIssues(mainSpecsDir, capability, modified, entryPath,
721
+ /**
722
+ * New name → old name, for requirements this change also renames. Without
723
+ * it a MODIFIED under the post-rename header finds nothing in the main spec
724
+ * and is skipped, so archive refuses what validate called valid.
725
+ */
726
+ renamedToFrom,
727
+ /**
728
+ * `## REMOVED Scenarios` declarations. A scenario named here is one the
729
+ * author means to drop, so omitting it from the MODIFIED block stops being
730
+ * the accident this check exists to catch.
731
+ */
732
+ declaredRemovals) {
616
733
  let content;
617
734
  try {
618
735
  content = await fs.readFile(path.join(mainSpecsDir, capability, 'spec.md'), 'utf-8');
619
736
  }
620
737
  catch (error) {
621
- // Silence belongs to the genuinely-absent case documented above. A spec that
622
- // exists and could not be read means the check never ran, and returning []
623
- // reports that as "nothing to lose" — under the same wording, so the reader
624
- // cannot tell a new capability from a broken one.
738
+ // Silence belongs to the genuinely-absent case only: a spec that exists
739
+ // and could not be read means the check never ran, and [] would report
740
+ // that as "nothing to lose".
625
741
  if (isMissingPathError(error))
626
742
  return [];
627
743
  // Reported rather than thrown: the enclosing handler treats any throw as
628
- // "no specs dir" and would swallow this into a misleading no-deltas error.
629
- // Reporting also keeps the other capabilities' findings, which a throw
630
- // would discard. ERROR because archive reads the same file and now fails
631
- // on it too, so this is what archive refuses.
744
+ // "no specs dir" and would discard the other capabilities' findings.
745
+ // ERROR because archive reads the same file and fails on it too.
632
746
  return [
633
747
  {
634
748
  level: 'ERROR',
@@ -642,40 +756,116 @@ export class Validator {
642
756
  currentByName.set(normalizeRequirementName(block.name), block);
643
757
  }
644
758
  const issues = [];
759
+ // Declarations are consumed as matched, so a leftover is one that removed
760
+ // nothing — a typo that would otherwise read as a successful removal.
761
+ const unmatchedRemovals = new Set(declaredRemovals);
762
+ const declaredFor = (requirementKey) => {
763
+ const names = new Set();
764
+ for (const entry of declaredRemovals) {
765
+ if (entry.requirement === requirementKey)
766
+ names.add(entry.scenario);
767
+ }
768
+ return names;
769
+ };
770
+ for (const entry of declaredRemovals) {
771
+ if (!entry.hasReason) {
772
+ issues.push({
773
+ level: 'WARNING',
774
+ path: entryPath,
775
+ line: entry.startLine,
776
+ message: `REMOVED Scenarios entry for "${entry.scenario}" has no Reason. A scenario removal is a behavior removal — record why, the same as a removed requirement does.`,
777
+ });
778
+ }
779
+ }
645
780
  for (const block of modified) {
646
- const current = currentByName.get(normalizeRequirementName(block.name));
781
+ const key = normalizeRequirementName(block.name);
782
+ // Direct hit first; only fall back to the pre-rename name when this change
783
+ // renames the requirement, so an unrelated MODIFIED is unaffected.
784
+ const renamedFrom = renamedToFrom.get(key);
785
+ const current = currentByName.get(key) ??
786
+ (renamedFrom === undefined ? undefined : currentByName.get(normalizeRequirementName(renamedFrom)));
647
787
  if (!current)
648
788
  continue;
649
- const missing = findMissingScenarios(current.raw, block.raw);
650
- if (missing.length === 0)
789
+ // Named by its spec header, not its new one: that is the block the reader
790
+ // has to open to see the scenarios at risk.
791
+ const target = renamedFrom !== undefined && !currentByName.has(key) ? ` (renamed from "${renamedFrom}")` : '';
792
+ const declared = declaredFor(currentByName.has(key) ? key : normalizeRequirementName(renamedFrom ?? ''));
793
+ const missing = findMissingScenarios(current.raw, block.raw).filter((name) => {
794
+ if (!declared.has(name))
795
+ return true;
796
+ for (const entry of unmatchedRemovals) {
797
+ if (entry.scenario === name)
798
+ unmatchedRemovals.delete(entry);
799
+ }
800
+ return false;
801
+ });
802
+ if (missing.length > 0) {
803
+ issues.push({
804
+ level: 'ERROR',
805
+ path: entryPath,
806
+ message: `MODIFIED "${block.name}"${target} omits scenario(s) the current spec still has: ${missing
807
+ .map((name) => `"${name}"`)
808
+ .join(', ')}. A MODIFIED block replaces the whole requirement, so archiving would delete them — restate them in the block, or declare the removal under "## REMOVED Scenarios" with a Reason. ${REMOVED_SCENARIOS_GRAMMAR}`,
809
+ });
810
+ // One finding per requirement: a block missing whole scenarios is also
811
+ // missing their bullets, and reporting both buries the actionable one.
651
812
  continue;
813
+ }
814
+ // WARNING, not ERROR: rewording a bullet is a legitimate MODIFIED, but on
815
+ // disk it is indistinguishable from a stale block reverting someone else's
816
+ // archived edit.
817
+ //
818
+ // Compared against the current requirement *minus* the scenarios this
819
+ // change declared removed: their bullets go with them by definition.
820
+ const currentRaw = withoutScenarios(current.raw, [...declared]);
821
+ const dropped = findDroppedBullets(currentRaw, block.raw);
822
+ // A rewrite replaces bullets; a stale block loses them. When the delta
823
+ // brings at least as many new bullets as it drops, every dropped line has
824
+ // a successor and the block is a rewording — reporting it made every
825
+ // legitimate MODIFIED fail `--strict`. Fewer bullets than before is the
826
+ // shape of a reverted edit, which is the case this check exists for.
827
+ const replaced = findDroppedBullets(block.raw, currentRaw);
828
+ if (dropped.length > 0 && replaced.length < dropped.length) {
829
+ issues.push({
830
+ level: 'WARNING',
831
+ path: entryPath,
832
+ message: `MODIFIED "${block.name}"${target} drops bullet(s) the current spec still has: ${dropped
833
+ .map((line) => `"${line}"`)
834
+ .join(', ')}. Confirm this is an intentional rewrite and not a block written against an older ` +
835
+ `copy of the requirement — run tospec show <change> --diff to see the full comparison.`,
836
+ });
837
+ }
838
+ }
839
+ // A declaration that matched nothing: the author believes a scenario was
840
+ // removed, the spec still has it, and every command reports success. ERROR
841
+ // because there is no reading of it that is correct.
842
+ for (const entry of unmatchedRemovals) {
652
843
  issues.push({
653
844
  level: 'ERROR',
654
845
  path: entryPath,
655
- message: `MODIFIED "${block.name}" omits scenario(s) the current spec still has: ${missing
656
- .map((name) => `"${name}"`)
657
- .join(', ')}. A MODIFIED block replaces the whole requirement, so archiving would delete them — restate them in the block.`,
846
+ line: entry.startLine,
847
+ message: `REMOVED Scenarios declares "${entry.scenario}" under requirement "${entry.requirement}", but no MODIFIED block for that requirement drops that scenario. Check both names against tospec/specs/${capability}/spec.md — a declaration that matches nothing removes nothing.`,
658
848
  });
659
849
  }
660
850
  return issues;
661
851
  }
662
852
  /**
663
- * Dry-run the merge and report what it would refuse.
853
+ * Dry-run the merge and report what it would refuse, plus the one thing it
854
+ * would accept while doing nothing.
664
855
  *
665
856
  * Reusing the merge builder rather than restating its preconditions is the
666
- * whole point: several of them deliberately read a missing target as
667
- * already-synced rather than as a failure, and a second copy of those rules
668
- * would be free to drift — which shows up as validate and archive disagreeing,
669
- * the one thing this check exists to prevent.
857
+ * point: a second copy would be free to drift, which shows up as validate and
858
+ * archive disagreeing.
670
859
  *
671
- * INFO leaves the verdict alone. A MODIFIED whose target is missing is also
672
- * what a change modifying a sibling's unarchived requirement looks like, and
673
- * that is valid today; what is missing is the information, not the verdict.
860
+ * WARNING, not ERROR or INFO. ERROR is wrong because a MODIFIED whose target
861
+ * is missing is also what a change modifying a sibling's unarchived
862
+ * requirement looks like. INFO was wrong because `--strict` ignores it, so the
863
+ * pre-archive gate waved through changes archive would refuse.
864
+ * tospec/decisions/20260916_154000-archive-dry-run-findings-are-warnings.md
674
865
  */
675
- async findArchiveBlockers(changeDir, mainSpecsDir, alreadyReportedPaths) {
676
- const alreadyReported = new Set(alreadyReportedPaths);
677
- // Only ever reaches the generated skeleton's placeholder Purpose, which this
678
- // dry run discards along with the rest of the rebuilt content.
866
+ async findArchiveBlockers(changeDir, mainSpecsDir) {
867
+ // Only reaches the generated skeleton's placeholder Purpose, which this dry
868
+ // run discards with the rest of the rebuilt content.
679
869
  const changeName = path.basename(changeDir);
680
870
  const issues = [];
681
871
  let updates;
@@ -683,9 +873,8 @@ export class Validator {
683
873
  updates = await findSpecUpdates(changeDir, mainSpecsDir);
684
874
  }
685
875
  catch (error) {
686
- // An advisory check that cannot start must not take the report with it.
687
- // The structural pass walks the same tree with fast-glob and reports what
688
- // it found; those findings are the ones the author can act on.
876
+ // An advisory check that cannot start must not take the report with it:
877
+ // the structural pass walks the same tree and its findings are actionable.
689
878
  return [
690
879
  {
691
880
  level: 'INFO',
@@ -699,35 +888,53 @@ export class Validator {
699
888
  // rebuilds the same entryPath the checks above report under.
700
889
  const capability = path.basename(path.dirname(update.source));
701
890
  const entryPath = FileSystemUtils.toPosixPath(`${capability}/spec.md`);
702
- // A delta those checks already rejected would be reported twice, the
703
- // second time in the merge's wording rather than the wording that names
704
- // the actual mistake.
705
- if (alreadyReported.has(entryPath))
706
- continue;
707
891
  try {
708
- await buildUpdatedSpec(update, changeName, { silent: true });
892
+ const built = await buildUpdatedSpec(update, changeName, { silent: true });
893
+ // The merge would succeed but delete nothing, which is not what the
894
+ // delta appears to say. A mistyped REMOVED header is the likeliest
895
+ // cause and the hardest to catch, since nothing visibly happens.
896
+ //
897
+ // Only the REMOVED codes: the merge's other notices are about Purpose,
898
+ // which this validator judges under its own rules.
899
+ for (const notice of built.notices) {
900
+ if (!REMOVED_NOOP_NOTICE_CODES.has(notice.code))
901
+ continue;
902
+ issues.push({
903
+ level: 'WARNING',
904
+ path: entryPath,
905
+ message: `Archive would accept this delta but remove nothing: ${notice.message}`,
906
+ });
907
+ }
709
908
  }
710
909
  catch (error) {
711
910
  // Only the thrown preconditions, which carry no errno. A filesystem
712
- // error says nothing about whether the delta applies, and `validate
713
- // --all` reads several changes at once — a transient EMFILE reported as
714
- // a collision is a conflict that is not there.
911
+ // error says nothing about whether the delta applies, and under
912
+ // `validate --all` a transient EMFILE would read as a collision.
715
913
  if (error?.code !== undefined)
716
914
  continue;
915
+ const message = error instanceof Error ? error.message : String(error);
916
+ // The structural pass above already reported these in its own, more
917
+ // precise wording; repeating them in the merge's would name the same
918
+ // mistake twice. Filtered by *kind* rather than by path: the merge's
919
+ // other preconditions (a MODIFIED or RENAMED target the main spec does
920
+ // not have, an ADDED that collides) are checked nowhere else, so a delta
921
+ // with one unrelated grammar error used to hide them until that error
922
+ // was fixed — one round trip per finding.
923
+ if (STRUCTURAL_MERGE_FAILURE.test(message))
924
+ continue;
717
925
  issues.push({
718
- level: 'INFO',
926
+ level: 'WARNING',
719
927
  path: entryPath,
720
- message: `Archive would refuse this delta: ${error instanceof Error ? error.message : String(error)}`,
928
+ message: `Archive would refuse this delta: ${message}`,
721
929
  });
722
930
  }
723
931
  }
724
932
  return issues;
725
933
  }
726
934
  /**
727
- * Scenario-quality rules for a delta requirement block (report 2.1): only
728
- * `#### Scenario:` headers count as scenarios, each scenario body must
729
- * contain WHEN and THEN (uppercase, per the spec convention), and stray
730
- * level-4 headers get a WARNING so authors know they were not counted.
935
+ * Scenario-quality rules for a delta requirement block: only `#### Scenario:`
936
+ * headers count, each scenario body must contain uppercase WHEN and THEN, and
937
+ * a stray level-4 header gets a WARNING so the author knows it was not counted.
731
938
  */
732
939
  collectScenarioIssues(section, block, entryPath) {
733
940
  const issues = [];
@@ -742,7 +949,34 @@ export class Validator {
742
949
  message: `${section} "${block.name}" must include at least one "#### Scenario:" block`,
743
950
  });
744
951
  }
952
+ // Scenario names are the only handle the MODIFIED scenario-loss guard has —
953
+ // it counts how many times each name appears on each side. Restating one
954
+ // twice keeps the count and silently deletes the other's body on archive.
955
+ const scenarioNames = new Set();
956
+ for (const scenario of analysis.scenarios) {
957
+ const key = scenario.title.trim().toLowerCase();
958
+ if (scenarioNames.has(key)) {
959
+ issues.push({
960
+ level: 'ERROR',
961
+ path: entryPath,
962
+ line: toLine(scenario.relLine),
963
+ message: `${section} "${block.name}" repeats scenario name "${scenario.title}" (line ${toLine(scenario.relLine)}). Scenario names identify a scenario when a later MODIFIED restates this requirement, so two with the same name cannot be told apart — give each one a distinct name.`,
964
+ });
965
+ }
966
+ else {
967
+ scenarioNames.add(key);
968
+ }
969
+ }
745
970
  for (const scenario of analysis.scenarios) {
971
+ if (isTemplatePlaceholder(scenario.title)) {
972
+ issues.push({
973
+ level: 'ERROR',
974
+ path: entryPath,
975
+ line: toLine(scenario.relLine),
976
+ message: `${section} "${block.name}" scenario "${scenario.title}" (line ${toLine(scenario.relLine)}) still carries the template's placeholder name. Name the scenario after the behavior it checks.`,
977
+ });
978
+ continue;
979
+ }
746
980
  const missing = [
747
981
  ...(scenario.hasWhen ? [] : ['WHEN']),
748
982
  ...(scenario.hasThen ? [] : ['THEN']),
@@ -768,10 +1002,9 @@ export class Validator {
768
1002
  }
769
1003
  /**
770
1004
  * RENAMED/REMOVED have their own grammar (FROM:/TO: pairs; name bullets with
771
- * Reason/Migration), not the `### Requirement:` block ADDED/MODIFIED use.
772
- * Pointing a RENAMED/REMOVED author at "add a ### Requirement: block" sends
773
- * them to a fix that does not work — see
774
- * tospec/changes/delta-syntax-diagnostics-misleading/task.md.
1005
+ * Reason/Migration), not the `### Requirement:` block ADDED/MODIFIED use, so
1006
+ * "add a ### Requirement: block" would send their authors to a fix that does
1007
+ * not work.
775
1008
  */
776
1009
  formatEmptySectionMessage(kind, header) {
777
1010
  switch (kind) {