@warpgogol/forge 6.3.6 → 8.0.2

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 (405) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.md +2 -1
  3. package/bin/cli.js +6 -12
  4. package/bin/resolve-entry.js +24 -0
  5. package/dist/os/compass/comment-safety.d.ts +83 -0
  6. package/dist/os/compass/comment-safety.d.ts.map +1 -0
  7. package/dist/os/compass/comment-safety.js +305 -0
  8. package/dist/os/compass/comment-safety.js.map +1 -0
  9. package/dist/os/compass/compass.module.d.ts.map +1 -1
  10. package/dist/os/compass/compass.module.js +47 -4
  11. package/dist/os/compass/compass.module.js.map +1 -1
  12. package/dist/os/compass/handlers/compass-change-summary-handler.d.ts +2 -1
  13. package/dist/os/compass/handlers/compass-change-summary-handler.d.ts.map +1 -1
  14. package/dist/os/compass/handlers/compass-change-summary-handler.js +34 -10
  15. package/dist/os/compass/handlers/compass-change-summary-handler.js.map +1 -1
  16. package/dist/os/compass/handlers/compass-docs-scaffold.d.ts.map +1 -1
  17. package/dist/os/compass/handlers/compass-docs-scaffold.js +54 -17
  18. package/dist/os/compass/handlers/compass-docs-scaffold.js.map +1 -1
  19. package/dist/os/compass/handlers/compass-header-scaffold-handler.d.ts +14 -0
  20. package/dist/os/compass/handlers/compass-header-scaffold-handler.d.ts.map +1 -0
  21. package/dist/os/compass/handlers/compass-header-scaffold-handler.js +261 -0
  22. package/dist/os/compass/handlers/compass-header-scaffold-handler.js.map +1 -0
  23. package/dist/os/compass/handlers/compass-header-scaffold.d.ts +31 -0
  24. package/dist/os/compass/handlers/compass-header-scaffold.d.ts.map +1 -0
  25. package/dist/os/compass/handlers/compass-header-scaffold.js +739 -0
  26. package/dist/os/compass/handlers/compass-header-scaffold.js.map +1 -0
  27. package/dist/os/compass/handlers/compass-inventory-handler.d.ts.map +1 -1
  28. package/dist/os/compass/handlers/compass-inventory-handler.js +8 -4
  29. package/dist/os/compass/handlers/compass-inventory-handler.js.map +1 -1
  30. package/dist/os/compass/handlers/compass-inventory.d.ts +6 -0
  31. package/dist/os/compass/handlers/compass-inventory.d.ts.map +1 -1
  32. package/dist/os/compass/handlers/compass-inventory.js +28 -13
  33. package/dist/os/compass/handlers/compass-inventory.js.map +1 -1
  34. package/dist/os/compass/handlers/compass-migrate-handler.d.ts.map +1 -1
  35. package/dist/os/compass/handlers/compass-migrate-handler.js +12 -26
  36. package/dist/os/compass/handlers/compass-migrate-handler.js.map +1 -1
  37. package/dist/os/compass/handlers/compass-migrate.d.ts +15 -2
  38. package/dist/os/compass/handlers/compass-migrate.d.ts.map +1 -1
  39. package/dist/os/compass/handlers/compass-migrate.js +58 -20
  40. package/dist/os/compass/handlers/compass-migrate.js.map +1 -1
  41. package/dist/os/compass/handlers/git-revision.d.ts +10 -0
  42. package/dist/os/compass/handlers/git-revision.d.ts.map +1 -1
  43. package/dist/os/compass/handlers/git-revision.js +58 -4
  44. package/dist/os/compass/handlers/git-revision.js.map +1 -1
  45. package/dist/os/compass/handlers/summary-record.d.ts +20 -5
  46. package/dist/os/compass/handlers/summary-record.d.ts.map +1 -1
  47. package/dist/os/compass/handlers/summary-record.js +175 -44
  48. package/dist/os/compass/handlers/summary-record.js.map +1 -1
  49. package/dist/os/compass/index.d.ts +1 -0
  50. package/dist/os/compass/index.d.ts.map +1 -1
  51. package/dist/os/compass/index.js +2 -0
  52. package/dist/os/compass/index.js.map +1 -1
  53. package/dist/os/compass/policy.d.ts +9 -0
  54. package/dist/os/compass/policy.d.ts.map +1 -1
  55. package/dist/os/compass/policy.js +11 -2
  56. package/dist/os/compass/policy.js.map +1 -1
  57. package/dist/os/core/core.module.js +1 -1
  58. package/dist/os/core/handlers/package-health.d.ts.map +1 -1
  59. package/dist/os/core/handlers/package-health.js +1 -6
  60. package/dist/os/core/handlers/package-health.js.map +1 -1
  61. package/dist/os/queue/types.d.ts +2 -0
  62. package/dist/os/queue/types.d.ts.map +1 -1
  63. package/dist/os/queue/types.js +3 -1
  64. package/dist/os/queue/types.js.map +1 -1
  65. package/dist/os/rfc/acceptance.d.ts.map +1 -1
  66. package/dist/os/rfc/acceptance.js +66 -2
  67. package/dist/os/rfc/acceptance.js.map +1 -1
  68. package/dist/os/rfc/decision-log.d.ts.map +1 -1
  69. package/dist/os/rfc/decision-log.js +21 -3
  70. package/dist/os/rfc/decision-log.js.map +1 -1
  71. package/dist/os/rfc/dna-trace.d.ts +2 -0
  72. package/dist/os/rfc/dna-trace.d.ts.map +1 -1
  73. package/dist/os/rfc/dna-trace.js +13 -4
  74. package/dist/os/rfc/dna-trace.js.map +1 -1
  75. package/dist/os/rfc/handlers/implement-stamp-origin.d.ts +37 -0
  76. package/dist/os/rfc/handlers/implement-stamp-origin.d.ts.map +1 -0
  77. package/dist/os/rfc/handlers/implement-stamp-origin.js +118 -0
  78. package/dist/os/rfc/handlers/implement-stamp-origin.js.map +1 -0
  79. package/dist/os/rfc/handlers/implement-stamp.d.ts +41 -1
  80. package/dist/os/rfc/handlers/implement-stamp.d.ts.map +1 -1
  81. package/dist/os/rfc/handlers/implement-stamp.js +645 -47
  82. package/dist/os/rfc/handlers/implement-stamp.js.map +1 -1
  83. package/dist/os/rfc/handlers/rfc-evidence-sync.d.ts +42 -0
  84. package/dist/os/rfc/handlers/rfc-evidence-sync.d.ts.map +1 -0
  85. package/dist/os/rfc/handlers/rfc-evidence-sync.js +147 -0
  86. package/dist/os/rfc/handlers/rfc-evidence-sync.js.map +1 -0
  87. package/dist/os/rfc/handlers/validate-rules.d.ts +9 -1
  88. package/dist/os/rfc/handlers/validate-rules.d.ts.map +1 -1
  89. package/dist/os/rfc/handlers/validate-rules.js +71 -10
  90. package/dist/os/rfc/handlers/validate-rules.js.map +1 -1
  91. package/dist/os/rfc/reachable-symbol.d.ts +17 -0
  92. package/dist/os/rfc/reachable-symbol.d.ts.map +1 -0
  93. package/dist/os/rfc/reachable-symbol.js +376 -0
  94. package/dist/os/rfc/reachable-symbol.js.map +1 -0
  95. package/dist/os/rfc/rfc.module.d.ts.map +1 -1
  96. package/dist/os/rfc/rfc.module.js +99 -10
  97. package/dist/os/rfc/rfc.module.js.map +1 -1
  98. package/dist/os/rfc/types.d.ts +112 -14
  99. package/dist/os/rfc/types.d.ts.map +1 -1
  100. package/dist/os/rfc/types.js +27 -10
  101. package/dist/os/rfc/types.js.map +1 -1
  102. package/dist/os/rfc/verification-evidence.d.ts +25 -0
  103. package/dist/os/rfc/verification-evidence.d.ts.map +1 -1
  104. package/dist/os/rfc/verification-evidence.js +244 -13
  105. package/dist/os/rfc/verification-evidence.js.map +1 -1
  106. package/dist/os/rfc/verification-origin.d.ts +58 -0
  107. package/dist/os/rfc/verification-origin.d.ts.map +1 -0
  108. package/dist/os/rfc/verification-origin.js +346 -0
  109. package/dist/os/rfc/verification-origin.js.map +1 -0
  110. package/dist/os/rfc/verification-refresh.d.ts.map +1 -1
  111. package/dist/os/rfc/verification-refresh.js +11 -1
  112. package/dist/os/rfc/verification-refresh.js.map +1 -1
  113. package/dist/os/rfc/verify-workspace.d.ts +23 -0
  114. package/dist/os/rfc/verify-workspace.d.ts.map +1 -0
  115. package/dist/os/rfc/verify-workspace.js +278 -0
  116. package/dist/os/rfc/verify-workspace.js.map +1 -0
  117. package/dist/os/session/handlers/metrics-rfc.d.ts.map +1 -1
  118. package/dist/os/session/handlers/metrics-rfc.js +3 -0
  119. package/dist/os/session/handlers/metrics-rfc.js.map +1 -1
  120. package/dist/os/spec/spec-status.d.ts.map +1 -1
  121. package/dist/os/spec/spec-status.js +5 -23
  122. package/dist/os/spec/spec-status.js.map +1 -1
  123. package/dist/os/spec/spec-validate.d.ts.map +1 -1
  124. package/dist/os/spec/spec-validate.js +30 -9
  125. package/dist/os/spec/spec-validate.js.map +1 -1
  126. package/dist/os/workflow/handlers.d.ts +0 -4
  127. package/dist/os/workflow/handlers.d.ts.map +1 -1
  128. package/dist/os/workflow/handlers.js +9 -36
  129. package/dist/os/workflow/handlers.js.map +1 -1
  130. package/dist/os/workflow/index.d.ts +2 -2
  131. package/dist/os/workflow/index.d.ts.map +1 -1
  132. package/dist/os/workflow/index.js +1 -1
  133. package/dist/os/workflow/index.js.map +1 -1
  134. package/dist/os/workflow/types.d.ts +0 -19
  135. package/dist/os/workflow/types.d.ts.map +1 -1
  136. package/dist/os/workflow/types.js +0 -2
  137. package/dist/os/workflow/types.js.map +1 -1
  138. package/dist/os/workflow/workflow.module.d.ts.map +1 -1
  139. package/dist/os/workflow/workflow.module.js +6 -15
  140. package/dist/os/workflow/workflow.module.js.map +1 -1
  141. package/dist/src/config/forge-config.d.ts +5 -0
  142. package/dist/src/config/forge-config.d.ts.map +1 -1
  143. package/dist/src/config/forge-config.js +5 -2
  144. package/dist/src/config/forge-config.js.map +1 -1
  145. package/dist/src/onboarding/agents-generate.js +1 -1
  146. package/dist/src/onboarding/doctor.js +3 -3
  147. package/dist/src/onboarding/doctor.js.map +1 -1
  148. package/dist/src/onboarding/init.js +2 -2
  149. package/dist/src/onboarding/nested-agents-templates.js +1 -1
  150. package/dist/src/onboarding/prettierignore.js +1 -1
  151. package/dist/src/onboarding/upgrade.js +2 -2
  152. package/dist/src/onboarding/workspace-discovery.js +1 -1
  153. package/dist/src/profiles/profile-schema.d.ts +2 -0
  154. package/dist/src/profiles/profile-schema.d.ts.map +1 -1
  155. package/dist/src/profiles/profile-schema.js +1 -0
  156. package/dist/src/profiles/profile-schema.js.map +1 -1
  157. package/dist/src/profiles/stack-profile.d.ts +1 -0
  158. package/dist/src/profiles/stack-profile.d.ts.map +1 -1
  159. package/dist/src/skill-schema.d.ts +2 -0
  160. package/dist/src/skill-schema.d.ts.map +1 -1
  161. package/dist/src/skill-schema.js +9 -1
  162. package/dist/src/skill-schema.js.map +1 -1
  163. package/dist/src/types.d.ts +23 -0
  164. package/dist/src/types.d.ts.map +1 -1
  165. package/dist/src/types.js +2 -1
  166. package/dist/src/types.js.map +1 -1
  167. package/docs/reference/cli.md +0 -1
  168. package/docs/reference/programmatic-api.md +1 -1
  169. package/os/adr/handlers/validate.test.ts +14 -0
  170. package/os/compass/comment-safety.ts +331 -0
  171. package/os/compass/compass.module.ts +50 -4
  172. package/os/compass/handlers/compass-change-summary-handler.ts +41 -11
  173. package/os/compass/handlers/compass-docs-scaffold.ts +59 -17
  174. package/os/compass/handlers/compass-game-extensions.test.ts +3 -7
  175. package/os/compass/handlers/compass-header-scaffold-handler.ts +352 -0
  176. package/os/compass/handlers/compass-header-scaffold.ts +847 -0
  177. package/os/compass/handlers/compass-inventory-handler.ts +9 -4
  178. package/os/compass/handlers/compass-inventory.ts +29 -13
  179. package/os/compass/handlers/compass-migrate-handler.ts +13 -27
  180. package/os/compass/handlers/compass-migrate.ts +77 -21
  181. package/os/compass/handlers/git-revision.ts +59 -4
  182. package/os/compass/handlers/resolve-scan-root-package.test.ts +14 -0
  183. package/os/compass/handlers/resolve-scan-root-workpiece.test.ts +14 -0
  184. package/os/compass/handlers/summary-record.ts +194 -41
  185. package/os/compass/handlers/tests/compass-audit-plan.test.ts +6 -0
  186. package/os/compass/handlers/tests/compass-audit-record.test.ts +6 -0
  187. package/os/compass/handlers/tests/compass-audit-validate.test.ts +6 -0
  188. package/os/compass/handlers/tests/compass-change-summary-handler.test.ts +131 -0
  189. package/os/compass/handlers/tests/compass-docs-validate.test.ts +6 -0
  190. package/os/compass/handlers/tests/compass-header-scaffold.test.ts +896 -0
  191. package/os/compass/handlers/tests/compass-ledger-scope.test.ts +6 -0
  192. package/os/compass/handlers/tests/compass-migrate.test.ts +87 -9
  193. package/os/compass/handlers/tests/compass-policy.test.ts +1 -1
  194. package/os/compass/handlers/tests/compass-text-safety.test.ts +271 -0
  195. package/os/compass/handlers/tests/compass-v2-contract.test.ts +52 -3
  196. package/os/compass/handlers/tests/summary-record.test.ts +324 -3
  197. package/os/compass/index.ts +15 -0
  198. package/os/compass/policy.ts +27 -2
  199. package/os/core/core.module.ts +1 -1
  200. package/os/core/handlers/invariant-engine.test.ts +3 -1
  201. package/os/core/handlers/note-frontmatter-validate.test.ts +6 -1
  202. package/os/core/handlers/note-link-validate.test.ts +6 -1
  203. package/os/core/handlers/note-orphan-detect.test.ts +6 -1
  204. package/os/core/handlers/package-health.test.ts +6 -0
  205. package/os/core/handlers/package-health.ts +1 -6
  206. package/os/mission/handlers/archive.test.ts +14 -0
  207. package/os/naming/naming-convention.test.ts +14 -0
  208. package/os/queue/decision-ledger.test.ts +27 -4
  209. package/os/queue/queue-validate.test.ts +14 -0
  210. package/os/queue/types.ts +3 -1
  211. package/os/rfc/acceptance-reachable.test.ts +146 -0
  212. package/os/rfc/acceptance.test.ts +136 -0
  213. package/os/rfc/acceptance.ts +71 -2
  214. package/os/rfc/decision-log.ts +22 -4
  215. package/os/rfc/dna-trace.ts +17 -5
  216. package/os/rfc/frontmatter-io.test.ts +14 -0
  217. package/os/rfc/handlers/implement-stamp-acceptance-verification.test.ts +81 -0
  218. package/os/rfc/handlers/implement-stamp-binding.test.ts +79 -0
  219. package/os/rfc/handlers/implement-stamp-origin.test.ts +132 -0
  220. package/os/rfc/handlers/implement-stamp-origin.ts +154 -0
  221. package/os/rfc/handlers/implement-stamp-stale.test.ts +285 -0
  222. package/os/rfc/handlers/implement-stamp.ts +783 -55
  223. package/os/rfc/handlers/lifecycle.test.ts +14 -0
  224. package/os/rfc/handlers/rfc-evidence-sync.ts +221 -0
  225. package/os/rfc/handlers/validate-rules-rfc0997.test.ts +14 -0
  226. package/os/rfc/handlers/validate-rules-rfc1006.test.ts +14 -0
  227. package/os/rfc/handlers/validate-rules-rfc1330.test.ts +120 -0
  228. package/os/rfc/handlers/validate-rules-rfc1334.test.ts +65 -0
  229. package/os/rfc/handlers/validate-rules.test.ts +56 -0
  230. package/os/rfc/handlers/validate-rules.ts +101 -10
  231. package/os/rfc/handlers/validate.test.ts +4 -3
  232. package/os/rfc/reachable-symbol.ts +441 -0
  233. package/os/rfc/rfc-0000-template.md +21 -1
  234. package/os/rfc/rfc-create-concurrent.test.ts +6 -0
  235. package/os/rfc/rfc-create-hint.test.ts +6 -0
  236. package/os/rfc/rfc-read-only-no-side-effects.test.ts +6 -0
  237. package/os/rfc/rfc.module.ts +106 -10
  238. package/os/rfc/types.ts +151 -14
  239. package/os/rfc/verification-emit-check.test.ts +215 -0
  240. package/os/rfc/verification-emit-freshness.test.ts +415 -0
  241. package/os/rfc/verification-emit.test.ts +14 -0
  242. package/os/rfc/verification-evidence.ts +301 -13
  243. package/os/rfc/verification-normalize.test.ts +75 -0
  244. package/os/rfc/verification-origin.test.ts +236 -0
  245. package/os/rfc/verification-origin.ts +417 -0
  246. package/os/rfc/verification-refresh.test.ts +14 -0
  247. package/os/rfc/verification-refresh.ts +12 -1
  248. package/os/rfc/verifier/rfc-1333/imp12-binding.acceptance.test.ts +78 -0
  249. package/os/rfc/verifier/rfc-1333/imp12-gate.acceptance.test.ts +81 -0
  250. package/os/rfc/verifier/rfc-1333/skills-and-types.acceptance.test.ts +50 -0
  251. package/os/rfc/verifier/rfc-1333/verify-workspace.acceptance.test.ts +103 -0
  252. package/os/rfc/verify-workspace.test.ts +122 -0
  253. package/os/rfc/verify-workspace.ts +342 -0
  254. package/os/session/handlers/metrics-rfc.ts +3 -0
  255. package/os/spec/spec-status.test.ts +130 -0
  256. package/os/spec/spec-status.ts +5 -18
  257. package/os/spec/spec-validate.test.ts +76 -1
  258. package/os/spec/spec-validate.ts +26 -7
  259. package/os/workflow/handlers.ts +8 -42
  260. package/os/workflow/index.ts +1 -4
  261. package/os/workflow/types.ts +0 -22
  262. package/os/workflow/workflow.module.ts +6 -16
  263. package/package.json +1 -1
  264. package/skills/_shared/agent-operating-model.md +83 -0
  265. package/skills/_shared/fo-pipeline-conventions.md +1 -0
  266. package/skills/fo/fo-add-tests/SKILL.md +14 -0
  267. package/skills/fo/fo-fix/SKILL.md +2 -1
  268. package/skills/fo/fo-handoff/SKILL.md +1 -1
  269. package/skills/fo/fo-idea/SKILL.md +6 -3
  270. package/skills/fo/fo-idea-create-rfc/acceptance-criteria-standard.md +8 -0
  271. package/skills/fo/fo-idea-i-just-want-to-see-the-result/SKILL.md +4 -2
  272. package/skills/fo/fo-idea-implement/SKILL.md +68 -53
  273. package/skills/fo/fo-idea-plan/SKILL.md +3 -1
  274. package/skills/fo/fo-review/SKILL.md +12 -0
  275. package/skills/fo/fo-session-save/learned-principles.md +13 -0
  276. package/skills/fo/fo-step-commit/SKILL.md +1 -1
  277. package/src/bin-entry.test.ts +37 -0
  278. package/src/compass/contract-registry.test.ts +14 -0
  279. package/src/compass/types.test.ts +14 -0
  280. package/src/config/__tests__/resolve-terminology.test.ts +14 -0
  281. package/src/config/forge-config.test.ts +14 -0
  282. package/src/config/forge-config.ts +7 -2
  283. package/src/forge-module.test.ts +14 -0
  284. package/src/knowledge/__tests__/promote.test.ts +14 -0
  285. package/src/knowledge/__tests__/serialize.test.ts +14 -0
  286. package/src/knowledge/__tests__/sync.test.ts +4 -1
  287. package/src/knowledge/budgets.test.ts +14 -0
  288. package/src/knowledge/compact.test.ts +14 -0
  289. package/src/knowledge/parse.test.ts +14 -0
  290. package/src/knowledge/schema.test.ts +14 -0
  291. package/src/migration-adapters/__tests__/ignored-files.test.ts +14 -0
  292. package/src/migration-adapters/__tests__/registry.test.ts +14 -0
  293. package/src/migration-adapters/__tests__/types.test.ts +14 -0
  294. package/src/onboarding/__tests__/workspace-discovery.test.ts +14 -0
  295. package/src/onboarding/agents-generate.ts +1 -1
  296. package/src/onboarding/compass-docs/semantic-layer-block.test.ts +6 -0
  297. package/src/onboarding/create.test.ts +14 -0
  298. package/src/onboarding/doctor-token-check.test.ts +3 -0
  299. package/src/onboarding/doctor.test.ts +14 -0
  300. package/src/onboarding/doctor.ts +3 -3
  301. package/src/onboarding/init.test.ts +14 -0
  302. package/src/onboarding/init.ts +2 -2
  303. package/src/onboarding/nested-agents-templates.ts +1 -1
  304. package/src/onboarding/prettierignore.ts +1 -1
  305. package/src/onboarding/scaffold.test.ts +14 -0
  306. package/src/onboarding/site-workshop-profile.test.ts +3 -0
  307. package/src/onboarding/templates/behavioral-layer-core.md +8 -0
  308. package/src/onboarding/upgrade.test.ts +14 -0
  309. package/src/onboarding/upgrade.ts +2 -2
  310. package/src/onboarding/workspace-discovery.ts +1 -1
  311. package/src/pipeline-status.test.ts +14 -0
  312. package/src/plugin/forge-plugin-manifest.test.ts +14 -0
  313. package/src/profiles/__tests__/profile-schema.test.ts +14 -0
  314. package/src/profiles/__tests__/stack-profile.test.ts +14 -0
  315. package/src/profiles/__tests__/terminology-utils.test.ts +14 -0
  316. package/src/profiles/profile-schema.ts +1 -0
  317. package/src/skill-schema.ts +9 -1
  318. package/src/tests/acceptance-criteria.test.ts +14 -0
  319. package/src/tests/acceptance-probe-kinds.test.ts +14 -0
  320. package/src/tests/adr-implement-stamp.test.ts +14 -0
  321. package/src/tests/agents-generate-domain.test.ts +3 -0
  322. package/src/tests/agents-generate.test.ts +3 -0
  323. package/src/tests/bindings-schema.test.ts +2 -0
  324. package/src/tests/budgets.test.ts +14 -0
  325. package/src/tests/compact.test.ts +14 -0
  326. package/src/tests/compass-docs-flag.test.ts +6 -0
  327. package/src/tests/compass-docs-scaffold.test.ts +6 -0
  328. package/src/tests/compass-docs-validate-scope.test.ts +6 -0
  329. package/src/tests/contract-registry.test.ts +14 -0
  330. package/src/tests/create.test.ts +3 -0
  331. package/src/tests/discover-pack-skills.test.ts +14 -0
  332. package/src/tests/doctor-autonomy.test.ts +3 -0
  333. package/src/tests/doctor-bindings.test.ts +6 -1
  334. package/src/tests/doctor-dist-freshness.test.ts +26 -2
  335. package/src/tests/doctor-domain.test.ts +6 -1
  336. package/src/tests/doctor-fix.test.ts +3 -0
  337. package/src/tests/doctor-nested-agents.test.ts +3 -0
  338. package/src/tests/doctor-profile-id-known.test.ts +3 -0
  339. package/src/tests/doctor-skills-unmanaged.test.ts +3 -0
  340. package/src/tests/doctor-version-sync.test.ts +4 -1
  341. package/src/tests/editable-generated-region.test.ts +6 -3
  342. package/src/tests/exploration-handlers.test.ts +14 -0
  343. package/src/tests/file-size-lint.test.ts +6 -1
  344. package/src/tests/fixtures/agents-generate-business-before.txt +8 -0
  345. package/src/tests/forge-autonomy-validate.test.ts +3 -1
  346. package/src/tests/forge-config.test.ts +6 -1
  347. package/src/tests/forge-validate-compass-docs.test.ts +6 -0
  348. package/src/tests/fs-atomic.test.ts +14 -0
  349. package/src/tests/fs.test.ts +14 -0
  350. package/src/tests/generated-marker.test.ts +14 -0
  351. package/src/tests/hash.test.ts +14 -0
  352. package/src/tests/implement-stamp.test.ts +476 -10
  353. package/src/tests/init-bindings.test.ts +6 -1
  354. package/src/tests/knowledge-parse.test.ts +14 -0
  355. package/src/tests/knowledge-pbt.test.ts +14 -0
  356. package/src/tests/markdown-table.test.ts +6 -3
  357. package/src/tests/memory-compact.test.ts +3 -0
  358. package/src/tests/memory-scaffold.test.ts +6 -1
  359. package/src/tests/metrics-rfc-1053.test.ts +14 -0
  360. package/src/tests/migration-adapters.test.ts +3 -0
  361. package/src/tests/package-files.test.ts +4 -1
  362. package/src/tests/package-health-lint-surface.test.ts +3 -0
  363. package/src/tests/pinned-check.test.ts +14 -0
  364. package/src/tests/pinned-init.test.ts +14 -0
  365. package/src/tests/pinned-validate.test.ts +14 -0
  366. package/src/tests/plugin-manifest.test.ts +14 -0
  367. package/src/tests/prettierignore-manage.test.ts +3 -0
  368. package/src/tests/profile-schema.test.ts +6 -1
  369. package/src/tests/profile-validate.test.ts +6 -1
  370. package/src/tests/program-lease.test.ts +3 -0
  371. package/src/tests/program-paths-extended.test.ts +3 -0
  372. package/src/tests/program-paths.test.ts +3 -0
  373. package/src/tests/program-property.test.ts +3 -0
  374. package/src/tests/program-schemas.test.ts +3 -0
  375. package/src/tests/program-spec-node.test.ts +3 -0
  376. package/src/tests/promote.test.ts +14 -0
  377. package/src/tests/public-surface.test.ts +6 -1
  378. package/src/tests/registry.test.ts +14 -0
  379. package/src/tests/rfc-evidence-sync.test.ts +347 -0
  380. package/src/tests/rfc-implement-stamp-governance.test.ts +403 -0
  381. package/src/tests/scaffold-project.test.ts +3 -0
  382. package/src/tests/session-handlers.test.ts +14 -0
  383. package/src/tests/session-pbt.test.ts +14 -0
  384. package/src/tests/skill-agents-sync.test.ts +3 -4
  385. package/src/tests/skill-schema.test.ts +53 -0
  386. package/src/tests/skill-sync-marker.test.ts +3 -0
  387. package/src/tests/skill-validate-knowledge.test.ts +14 -0
  388. package/src/tests/skill-validate.test.ts +14 -0
  389. package/src/tests/stack-profile.test.ts +6 -1
  390. package/src/tests/string-utils.test.ts +14 -0
  391. package/src/tests/upgrade.test.ts +6 -1
  392. package/src/tests/werkstatt-lock.test.ts +14 -0
  393. package/src/tests/workspace-discovery-domain.test.ts +6 -1
  394. package/src/tests/workspace-discovery.test.ts +6 -1
  395. package/src/types.test.ts +14 -0
  396. package/src/types.ts +30 -1
  397. package/src/utils/__tests__/fs-idempotent.test.ts +17 -0
  398. package/src/utils/__tests__/fs-trash.test.ts +17 -0
  399. package/src/utils/fs-atomic.test.ts +17 -0
  400. package/src/utils/fs-trash-sync.test.ts +17 -0
  401. package/src/utils/fs.test.ts +17 -0
  402. package/src/utils/generated-marker.test.ts +17 -0
  403. package/src/utils/hash.test.ts +17 -0
  404. package/src/utils/string-utils.test.ts +17 -0
  405. package/src/validators/__tests__/note-orphan-detect.test.ts +14 -0
@@ -5,7 +5,13 @@
5
5
  paths under missions/ or gitignored roots — the tracked ledger only
6
6
  accumulates entries for paths that can be audited long-term.
7
7
  </purpose>
8
+ <non-goals>
9
+ <item>Not a contract source of truth — the module under test owns the authoritative behavior; fixtures are minimal scaffolding only.</item>
10
+ </non-goals>
8
11
  </MODULE_CONTRACT>
12
+ <CHANGE_SUMMARY>
13
+ <item>RFC-1311: Compass header sweep — declares the compass suite's contract for test-file scaffold coverage.</item>
14
+ </CHANGE_SUMMARY>
9
15
  */
10
16
 
11
17
  import { describe, it, expect, beforeEach, afterEach } from "vitest";
@@ -1,6 +1,23 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>
4
+ Unit tests for the compass.migrate codemod — migrateFile action union
5
+ (collapse, strip, seed, reorder, todo, unparseable) and the workspace-walker
6
+ handler across fixture workspaces in temp dirs.
7
+ </purpose>
8
+ <non-goals>
9
+ <item>Fixture Compass markup is built via string concatenation so source-level validators never see literal forbidden tags — do not inline real tag literals.</item>
10
+ </non-goals>
11
+ </MODULE_CONTRACT>
12
+ <CHANGE_SUMMARY>
13
+ <item>RFC-1311: Compass header sweep — declares the suite contract and escapes fixture tag literals for FORBIDDEN-01/SYNTAX-01 parity.</item>
14
+ <item>RFC-1323: review pass — still-open enclosing-style detection, per-file pre-pass parity, scaffold never-throws, docs.scaffold raw-leaf assert, trim per-file skip, CS-08 always-error severity</item>
15
+ </CHANGE_SUMMARY>
16
+ */
17
+
1
18
  import { describe, it, expect, beforeEach, afterEach } from "vitest";
2
19
  import { execFileSync } from "node:child_process";
3
- import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
20
+ import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
4
21
  import { dirname, join } from "node:path";
5
22
  import { tmpdir } from "node:os";
6
23
  import { migrateFile, type MigrateAction } from "../compass-migrate.ts";
@@ -35,10 +52,14 @@ function makeInput(flags: Record<string, unknown> = {}): ForgeCommandInput {
35
52
  // by compass.summary.record itself and rewritten at commit time.
36
53
  const CS_OPEN = "<" + "CHANGE_SUMMARY>";
37
54
  const CS_CLOSE = "</" + "CHANGE_SUMMARY>";
55
+ const MC_OPEN = "<" + "MODULE_CONTRACT>";
56
+ const MC_CLOSE = "</" + "MODULE_CONTRACT>";
38
57
  const MC = (purpose: string) =>
39
- `<MODULE_CONTRACT>\n<purpose>${purpose}</purpose>\n<non-goals>\n <item>Do not perform real validation — fixtures only.</item>\n</non-goals>\n</MODULE_CONTRACT>`;
58
+ `${MC_OPEN}\n<purpose>${purpose}</purpose>\n<non-goals>\n <item>Do not perform real validation — fixtures only.</item>\n</non-goals>\n${MC_CLOSE}`;
59
+ const KD_OPEN = "<" + "KEY_DECISIONS>";
60
+ const KD_CLOSE = "</" + "KEY_DECISIONS>";
40
61
  const KD = (items: string[]) =>
41
- `<KEY_DECISIONS>\n${items.map((i) => ` <item>${i}</item>`).join("\n")}\n</KEY_DECISIONS>`;
62
+ `${KD_OPEN}\n${items.map((i) => ` <item>${i}</item>`).join("\n")}\n${KD_CLOSE}`;
42
63
  const CS = (items: string[], history?: string) =>
43
64
  `${CS_OPEN}\n${items.map((i) => ` <item>${i}</item>`).join("\n")}\n${history ? ` <history>${history}</history>\n` : ""}${CS_CLOSE}`;
44
65
  const wrap = (...blocks: string[]) => `/*\n${blocks.join("\n")}\n*/`;
@@ -82,12 +103,34 @@ describe("compass.migrate codemod (RFC-1097)", () => {
82
103
  });
83
104
 
84
105
  it("unparseable: open tag without close is skipped", () => {
85
- const broken = `/*\n<MODULE_CONTRACT>\n<purpose>${PURPOSE}</purpose>\n`;
106
+ const broken = `/*\n${MC_OPEN}\n<purpose>${PURPOSE}</purpose>\n`;
86
107
  const result = migrateFile(broken, policy, MEDIUM_ROOT, MEDIUM_WS);
87
108
  expect(result.actions).toEqual(["unparseable"]);
88
109
  expect(result.source).toBe(broken);
89
110
  });
90
111
 
112
+ it("RFC-1323: migrateFile throws CompassCommentSafetyError on unsafe authored text", () => {
113
+ // An html-enclosed .md header item carrying `<!--` parses fine — the
114
+ // throw lands at collapse re-emit, not parse time.
115
+ const items = [
116
+ "RFC-0001: first.",
117
+ "RFC-0002: second.",
118
+ "RFC-0003: third.",
119
+ "RFC-0004: fourth.",
120
+ "RFC-0005: fifth.",
121
+ `RFC-0006: notes ${"<"}!-- mid-item`,
122
+ ];
123
+ const source = `${"<"}!--\n${MC(PURPOSE)}\n${CS(items)}\n${"--" + ">"}`;
124
+ expect(() =>
125
+ migrateFile(
126
+ `${source}\n\n${BODY}\n`,
127
+ policy,
128
+ "packages/fixture-pkg/src/guide.md",
129
+ "src/guide.md",
130
+ ),
131
+ ).toThrowError(/COMPASS-CS-08/);
132
+ });
133
+
91
134
  it("collapsed: 8 items keep newest 5, overflow IDs merge into sorted history, ID-less items drop", () => {
92
135
  const items = [
93
136
  "RFC-1001: first.",
@@ -119,8 +162,8 @@ describe("compass.migrate codemod (RFC-1097)", () => {
119
162
 
120
163
  it("stripped: MODULE_MAP, keywords, responsibilities and COMPASS_BLOCK anchors are removed", () => {
121
164
  const mm = "<" + "MODULE_MAP" + ">\n <item>x</item>\n</" + "MODULE_MAP" + ">";
122
- const kw = "<keywords>a, b</keywords>";
123
- const resp = "<responsibilities>\n <item>y</item>\n</responsibilities>";
165
+ const kw = "<" + "keywords" + ">a, b</" + "keywords" + ">";
166
+ const resp = "<" + "responsibilities" + ">\n <item>y</item>\n</" + "responsibilities" + ">";
124
167
  const anchorOpen = "<" + "COMPASS_BLOCK" + ">";
125
168
  const anchorClose = "</" + "COMPASS_BLOCK" + ">";
126
169
  const source = wrap(
@@ -145,7 +188,7 @@ describe("compass.migrate codemod (RFC-1097)", () => {
145
188
  const result = migrate(wrap(MC(PURPOSE), CS(["RFC-1094: fixture."]), KD([KD_ITEM])));
146
189
  expect(result.actions).toContain("reordered");
147
190
  const mcIdx = result.source.indexOf("<MODULE_CONTRACT>");
148
- const kdIdx = result.source.indexOf("<KEY_DECISIONS>");
191
+ const kdIdx = result.source.indexOf(KD_OPEN);
149
192
  const csIdx = result.source.indexOf(CS_OPEN);
150
193
  expect(mcIdx).toBeLessThan(kdIdx);
151
194
  expect(kdIdx).toBeLessThan(csIdx);
@@ -155,7 +198,11 @@ describe("compass.migrate codemod (RFC-1097)", () => {
155
198
  const source = `${wrap(MC(PURPOSE), CS(["RFC-1094: fixture."]))}\n// @ai-invariant RFC-0020: Widget tokens must stay deterministic.\n// @ai-invariant Widget tokens must stay deterministic.\n\n${BODY}\n`;
156
199
  const result = migrateFile(source, policy, MEDIUM_ROOT, MEDIUM_WS);
157
200
  expect(result.actions).toContain("seeded");
158
- const kdMatch = result.source.match(/<KEY_DECISIONS>([\s\S]*?)<\/KEY_DECISIONS>/);
201
+ const kdMatch = result.source.match(
202
+ new RegExp(
203
+ `${KD_OPEN.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}([\\s\\S]*?)${KD_CLOSE.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`,
204
+ ),
205
+ );
159
206
  expect(kdMatch, "seeded file must carry a KEY_DECISIONS block").toBeTruthy();
160
207
  expect(kdMatch![1]).toContain("Widget tokens must stay deterministic.");
161
208
  // Deduped (two identical invariants → one item) and ID prefix stripped (KD-05).
@@ -178,7 +225,7 @@ describe("compass.migrate codemod (RFC-1097)", () => {
178
225
  );
179
226
  expect(result.actions).not.toContain("seeded");
180
227
  expect(result.actions).not.toContain("todo");
181
- expect(result.source).not.toContain("<KEY_DECISIONS>");
228
+ expect(result.source).not.toContain(KD_OPEN);
182
229
  });
183
230
 
184
231
  it("purpose-flagged: boilerplate purpose is reported without rewriting", () => {
@@ -288,4 +335,35 @@ describe("runCompassMigrate handler (RFC-1097)", () => {
288
335
  // custom-dir/widget.ts is low-risk (no layer match) → no seeding, v1 file is already clean.
289
336
  expect(actions).toEqual(["unchanged"]);
290
337
  });
338
+
339
+ it("RFC-1323: an item carrying the enclosing comment's terminator reports unsafe-text and exits 1", async () => {
340
+ // .astro header sits in a markup comment below frontmatter — an item
341
+ // containing `<!--` parses fine (it does not end the comment) but
342
+ // re-emitting it would corrupt. The 6-item window forces a collapse
343
+ // re-emit, which throws COMPASS-CS-08 — converted to a per-file
344
+ // unsafe-text action, never a written file.
345
+ const astroPath = "packages/fixture-pkg/src/page.astro";
346
+ const items = [
347
+ "RFC-0001: first.",
348
+ "RFC-0002: second.",
349
+ "RFC-0003: third.",
350
+ "RFC-0004: fourth.",
351
+ "RFC-0005: fifth.",
352
+ `RFC-0006: notes ${"<"}!-- mid-item`,
353
+ ];
354
+ const header = `---\nconst x = 1;\n---\n${"<"}!--\n${MC(PURPOSE)}\n${CS(items)}\n${"--" + ">"}`;
355
+ writeFixture(astroPath, header);
356
+ git("add", "-A");
357
+ git("commit", "-q", "-m", "fixture");
358
+
359
+ const before = readFileSync(join(tempDir, astroPath), "utf8");
360
+ const result = await runCompassMigrate(makeInput(), makeContext(tempDir));
361
+ expect(result.exitCode).toBe(1);
362
+ const data = dataOf(result);
363
+ const entry = data.files.find((f) => f.path === astroPath);
364
+ expect(entry?.actions).toEqual(["unsafe-text"]);
365
+ expect(entry?.error).toContain("COMPASS-CS-08");
366
+ // Fail closed per file — bytes untouched.
367
+ expect(readFileSync(join(tempDir, astroPath), "utf8")).toBe(before);
368
+ });
291
369
  });
@@ -193,7 +193,7 @@ describe("resolveCompassPolicy (RFC-1096)", () => {
193
193
  const body = Array.from({ length: 25 }, (_, i) => `export const line${i} = ${i};`).join("\n");
194
194
  writeFileSync(
195
195
  join(fixture, "engine.ts"),
196
- `/*\n<MODULE_CONTRACT>\n<purpose>Fixture kernel engine file for the compass policy high-risk test.</purpose>\n<non-goals>\n <item>No production logic.</item>\n</non-goals>\n</MODULE_CONTRACT>\n*/\n${body}\n`,
196
+ `/*\n<MODULE_CONTRACT>\n<purpose>Fixture kernel engine file for the compass policy high-risk test.</purpose>\n\n</MODULE_CONTRACT>\n*/\n${body}\n`,
197
197
  );
198
198
 
199
199
  const result = await runCompassInventory({ flags: {} } as never, makeContext(root));
@@ -0,0 +1,271 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>
4
+ Unit tests for os/compass/comment-safety.ts — the shared comment-terminator
5
+ contract (RFC-1322 note: RFC-1323): style detection, findCompassTerminator,
6
+ assertCompassCommentSafe (COMPASS-CS-08), neutralizeCompassText, and the
7
+ header-region truncation scan findCompassTerminatorInHeader.
8
+ </purpose>
9
+ <non-goals>
10
+ <item>Do not test parseCompassBlocks or writer handlers — writer coverage lives in summary-record/compass-v2-contract suites.</item>
11
+ <item>Do not put a literal comment terminator inside a comment — the strings under test stay inside string literals.</item>
12
+ </non-goals>
13
+ </MODULE_CONTRACT>
14
+ <KEY_DECISIONS>
15
+ <item>Terminator literals are built via concatenation where they would otherwise read as real comment syntax inside doc tooling.</item>
16
+ </KEY_DECISIONS>
17
+ <CHANGE_SUMMARY>
18
+ <item>RFC-1323: created — AC-2 coverage for the comment-safety helper across block, html, and line styles.</item>
19
+ <item>RFC-1323: write-time comment-terminator safety — shared comment-safety seam, authored CS-08 reject, injected neutralization, header-region scan</item>
20
+ <item>RFC-1323: review pass — still-open enclosing-style detection, per-file pre-pass parity, scaffold never-throws, docs.scaffold raw-leaf assert, trim per-file skip, CS-08 always-error severity</item>
21
+ <item>RFC-1323: re-review pass — frontmatter-zone enclosing-style detection, existing-item pre-pass gating, trim exit-1 on unsafe, nextSteps rule labels, severity/census test coverage</item>
22
+ </CHANGE_SUMMARY>
23
+ */
24
+
25
+ import { describe, it, expect } from "vitest";
26
+ import {
27
+ CompassCommentSafetyError,
28
+ commentStyleCandidates,
29
+ commentStyleFor,
30
+ enclosingCommentStyle,
31
+ findCompassTerminator,
32
+ findCompassTerminatorInHeader,
33
+ assertCompassCommentSafe,
34
+ neutralizeCompassText,
35
+ } from "../../comment-safety.ts";
36
+
37
+ // Concatenation keeps the terminator literal out of any comment-level view.
38
+ const BLOCK_TERM = "*" + "/";
39
+ const HTML_CLOSE = "--" + ">";
40
+ const HTML_OPEN = "<!" + "--";
41
+ const NEUTRAL_SLASH = "∕"; // U+2215
42
+ const NEUTRAL_GT = "›"; // U+203A
43
+ const NEUTRAL_LT = "‹"; // U+2039
44
+
45
+ describe("comment-safety — style detection", () => {
46
+ it("classifies extensions: ts/astro-md/gd/tscn", () => {
47
+ expect(commentStyleFor("src/a.ts")).toBe("block");
48
+ expect(commentStyleFor("docs/guide.md")).toBe("html");
49
+ expect(commentStyleFor("game/scene.gd")).toBe("line");
50
+ expect(commentStyleFor("res/world.tscn")).toBe("line");
51
+ expect(commentStyleCandidates("src/page.astro")).toEqual(["block", "html"]);
52
+ });
53
+
54
+ it("detects the enclosing comment style from the source, not the extension", () => {
55
+ const blockSource = `/*\n<TAG>\n*/\nconst x = 1;\n`;
56
+ expect(enclosingCommentStyle(blockSource, 5, "page.astro")).toBe("block");
57
+ const htmlSource = `${HTML_OPEN}\n<TAG>\n${HTML_CLOSE}\n<main/>\n`;
58
+ // .astro extension says block first — the enclosing markup comment is html.
59
+ expect(enclosingCommentStyle(htmlSource, 8, "page.astro")).toBe("html");
60
+ // Line-prefix files always resolve to line.
61
+ expect(enclosingCommentStyle("# hdr\nx", 0, "s.gd")).toBe("line");
62
+ // No opener before the index → extension fallback.
63
+ expect(enclosingCommentStyle("const x = 1;", 4, "a.ts")).toBe("block");
64
+ });
65
+
66
+ it("ignores a /* literal inside an html comment's prose", () => {
67
+ const source = `${HTML_OPEN}\n${"<MODULE_CONTRACT>"}\n<purpose>documents ${"/*"} close pairs</purpose>\n${"</MODULE_CONTRACT>"}\n${HTML_CLOSE}\n`;
68
+ const idx = source.indexOf("<purpose>");
69
+ expect(enclosingCommentStyle(source, idx, "page.astro")).toBe("html");
70
+ expect(enclosingCommentStyle(source, idx, "docs/guide.md")).toBe("html");
71
+ });
72
+
73
+ it("ignores a <!-- literal inside a block comment's prose", () => {
74
+ const source = `/*\n${"<MODULE_CONTRACT>"}\n<purpose>discusses ${HTML_OPEN} pairs</purpose>\n${"</MODULE_CONTRACT>"}\n${BLOCK_TERM}\n`;
75
+ const idx = source.indexOf("<purpose>");
76
+ expect(enclosingCommentStyle(source, idx, "src/a.ts")).toBe("block");
77
+ // .astro extension guesses block — the real enclosing comment is block too.
78
+ expect(enclosingCommentStyle(source, idx, "page.astro")).toBe("block");
79
+ });
80
+
81
+ it("an opener that closed before the index does not win", () => {
82
+ const source = `/*\nprior comment\n${BLOCK_TERM}\n${HTML_OPEN}\n${"<MODULE_CONTRACT>"}\n`;
83
+ const idx = source.indexOf("<MODULE_CONTRACT>");
84
+ expect(enclosingCommentStyle(source, idx, "page.astro")).toBe("html");
85
+ });
86
+
87
+ it("a /* in .md prose is literal text — never opens a comment", () => {
88
+ const source = `note about ${"/*"} markers\n${HTML_OPEN}\n${"<MODULE_CONTRACT>"}\n`;
89
+ const idx = source.indexOf("<MODULE_CONTRACT>");
90
+ expect(enclosingCommentStyle(source, idx, "docs/guide.md")).toBe("html");
91
+ });
92
+
93
+ it("a /* inside .astro frontmatter code is a phantom — the real html header wins", () => {
94
+ // `const m = "/*"` latches block state; without the fence reset the html
95
+ // header below is inert inside the phantom and detection lies "block".
96
+ const source = `---\nconst m = "${"/*"}";\n---\n${HTML_OPEN}\n${"<MODULE_CONTRACT>"}\n`;
97
+ const idx = source.indexOf("<MODULE_CONTRACT>");
98
+ expect(enclosingCommentStyle(source, idx, "page.astro")).toBe("html");
99
+ });
100
+
101
+ it("a real block header INSIDE frontmatter still resolves block", () => {
102
+ const source = `---\n/*\n${"<MODULE_CONTRACT>"}\n<purpose>x</purpose>\n${"</MODULE_CONTRACT>"}\n${BLOCK_TERM}\nconst m = 1;\n---\n<main/>\n`;
103
+ const idx = source.indexOf("<purpose>");
104
+ expect(enclosingCommentStyle(source, idx, "page.astro")).toBe("block");
105
+ });
106
+
107
+ it("the fence reset does not misfire on --- inside a real html comment", () => {
108
+ // Mid-comment `---` (a thematic break in prose) must not reset state —
109
+ // only the LEADING frontmatter close is a fence.
110
+ const source = `${HTML_OPEN}\n${"<MODULE_CONTRACT>"}\n<purpose>text</purpose>\n---\n${"</MODULE_CONTRACT>"}\n${HTML_CLOSE}\n`;
111
+ const idx = source.indexOf("</MODULE_CONTRACT>");
112
+ expect(enclosingCommentStyle(source, idx, "docs/guide.md")).toBe("html");
113
+ });
114
+ });
115
+
116
+ describe("comment-safety — findCompassTerminator", () => {
117
+ it("block style detects only the block close", () => {
118
+ expect(findCompassTerminator(`a ${BLOCK_TERM} b`, "block")).toBe(BLOCK_TERM);
119
+ expect(findCompassTerminator(`a ${HTML_CLOSE} b`, "block")).toBeNull();
120
+ expect(findCompassTerminator("clean text", "block")).toBeNull();
121
+ });
122
+
123
+ it("html style detects the close and the nested open", () => {
124
+ expect(findCompassTerminator(`a ${HTML_CLOSE} b`, "html")).toBe(HTML_CLOSE);
125
+ expect(findCompassTerminator(`a ${HTML_OPEN} b`, "html")).toBe(HTML_OPEN);
126
+ expect(findCompassTerminator(`a ${BLOCK_TERM} b`, "html")).toBeNull();
127
+ });
128
+
129
+ it("line style has no embedded terminator (AC-2)", () => {
130
+ expect(findCompassTerminator(`a ${BLOCK_TERM} b ${HTML_CLOSE}`, "line")).toBeNull();
131
+ expect(findCompassTerminator("anything at all", "line")).toBeNull();
132
+ });
133
+ });
134
+
135
+ describe("comment-safety — assertCompassCommentSafe", () => {
136
+ it("passes clean text and throws COMPASS-CS-08 with file+block context", () => {
137
+ expect(() => assertCompassCommentSafe("glob `src/<dir>/*.ts`", "block")).not.toThrow();
138
+ try {
139
+ assertCompassCommentSafe(`glob src${BLOCK_TERM}*`, "block", {
140
+ file: "src/a.ts",
141
+ block: "CHANGE_SUMMARY",
142
+ });
143
+ expect.unreachable("must throw");
144
+ } catch (err) {
145
+ expect(err).toBeInstanceOf(CompassCommentSafetyError);
146
+ const e = err as CompassCommentSafetyError;
147
+ expect(e.ruleId).toBe("COMPASS-CS-08");
148
+ expect(e.substring).toBe(BLOCK_TERM);
149
+ expect(e.file).toBe("src/a.ts");
150
+ expect(e.block).toBe("CHANGE_SUMMARY");
151
+ expect(e.message).toContain("src/a.ts");
152
+ expect(e.fixHint.length).toBeGreaterThan(0);
153
+ }
154
+ });
155
+ });
156
+
157
+ describe("comment-safety — neutralizeCompassText", () => {
158
+ it("rewrites each terminator to the non-terminating glyph and reports the change", () => {
159
+ const block = neutralizeCompassText(`glob src${BLOCK_TERM}*`, "block");
160
+ expect(block.text).toBe(`glob src*${NEUTRAL_SLASH}*`);
161
+ expect(block.neutralized).toBe(true);
162
+
163
+ const html = neutralizeCompassText(`a ${HTML_CLOSE} b ${HTML_OPEN}`, "html");
164
+ expect(html.text).toBe(`a --${NEUTRAL_GT} b ${NEUTRAL_LT}!--`);
165
+ expect(html.neutralized).toBe(true);
166
+ });
167
+
168
+ it("is idempotent — a second pass is a no-op", () => {
169
+ const once = neutralizeCompassText(`x ${BLOCK_TERM} y`, "block");
170
+ const twice = neutralizeCompassText(once.text, "block");
171
+ expect(twice.text).toBe(once.text);
172
+ expect(twice.neutralized).toBe(false);
173
+ });
174
+
175
+ it("does not touch text that lacks the style's terminator", () => {
176
+ const res = neutralizeCompassText(`a ${BLOCK_TERM} b`, "html");
177
+ expect(res.text).toBe(`a ${BLOCK_TERM} b`);
178
+ expect(res.neutralized).toBe(false);
179
+ });
180
+ });
181
+
182
+ describe("comment-safety — findCompassTerminatorInHeader (CS-08 scan)", () => {
183
+ const MC_OPEN = "<" + "MODULE_CONTRACT>";
184
+ const MC_CLOSE = "</" + "MODULE_CONTRACT>";
185
+ const CS_OPEN = "<" + "CHANGE_SUMMARY>";
186
+ const CS_CLOSE = "</" + "CHANGE_SUMMARY>";
187
+
188
+ it("fires on a terminator landing while inner tags are unclosed", () => {
189
+ const source = `/*\n${MC_OPEN}\n<purpose>references packages${BLOCK_TERM}wg/*\n</purpose>\n${MC_CLOSE}\n*/\n`;
190
+ const hit = findCompassTerminatorInHeader(source, "src/a.ts");
191
+ expect(hit).not.toBeNull();
192
+ expect(hit!.substring).toBe(BLOCK_TERM);
193
+ expect(hit!.line).toBe(3);
194
+ });
195
+
196
+ it("does not fire on a well-formed header — the close after all tags is legal", () => {
197
+ const source = `/*\n${MC_OPEN}\n<purpose>clean</purpose>\n${MC_CLOSE}\n${CS_OPEN}\n <item>RFC-1: x</item>\n${CS_CLOSE}\n*/\nexport const x = 1;\n`;
198
+ expect(findCompassTerminatorInHeader(source, "src/a.ts")).toBeNull();
199
+ });
200
+
201
+ it("ignores legal html comment pairs in a markdown header region", () => {
202
+ const source = `${HTML_OPEN}\n${MC_OPEN}\n<purpose>doc</purpose>\n${MC_CLOSE}\n${HTML_CLOSE}\n\n${HTML_OPEN} a section note ${HTML_CLOSE}\n`;
203
+ expect(findCompassTerminatorInHeader(source, "docs/guide.md")).toBeNull();
204
+ });
205
+
206
+ it("fires on an html-close truncating a markdown Compass header", () => {
207
+ const source = `${HTML_OPEN}\n${CS_OPEN}\n <item>bad ${HTML_CLOSE}</item>\n${CS_CLOSE}\n${HTML_CLOSE}\n`;
208
+ const hit = findCompassTerminatorInHeader(source, "docs/guide.md");
209
+ expect(hit).not.toBeNull();
210
+ expect(hit!.substring).toBe(HTML_CLOSE);
211
+ });
212
+
213
+ it("line-style files never report — no embedded terminator exists", () => {
214
+ const source = `# ${MC_OPEN}\n# <purpose>x ${BLOCK_TERM} y ${HTML_CLOSE}</purpose>\n# ${MC_CLOSE}\n`;
215
+ expect(findCompassTerminatorInHeader(source, "s.gd")).toBeNull();
216
+ });
217
+
218
+ it("ignores corruption markers beyond the header region bound", () => {
219
+ const pad = Array.from({ length: 130 }, () => "// pad").join("\n");
220
+ const source = `/* ok */\n${pad}\n${MC_OPEN} truncated ${BLOCK_TERM}\n`;
221
+ expect(findCompassTerminatorInHeader(source, "src/a.ts")).toBeNull();
222
+ });
223
+
224
+ it("does not fire on a nested <!-- inside an otherwise clean html comment", () => {
225
+ const source = `${HTML_OPEN}\n${HTML_OPEN} stray nested opener — harmless\n${MC_OPEN}\n<purpose>x</purpose>\n${MC_CLOSE}\n${HTML_CLOSE}\n`;
226
+ expect(findCompassTerminatorInHeader(source, "docs/guide.md")).toBeNull();
227
+ });
228
+
229
+ it("does not fire on a JSDoc line carrying a bare <item> — no structural parent", () => {
230
+ const source = `/** <item> documents the <item> tag ${BLOCK_TERM}/\nexport const x = 1;\n`;
231
+ expect(findCompassTerminatorInHeader(source, "src/a.ts")).toBeNull();
232
+ });
233
+
234
+ it("ignores a-->b-shaped code tokens outside comments", () => {
235
+ const source = `/*\n${MC_OPEN}\n<purpose>clean</purpose>\n${MC_CLOSE}\n${BLOCK_TERM}\nconst arrow = a${HTML_CLOSE}b;\n`;
236
+ expect(findCompassTerminatorInHeader(source, "src/a.ts")).toBeNull();
237
+ });
238
+
239
+ it("an escaped <\\/close> does not close a real open tag — a later terminator still fires", () => {
240
+ const source = `/*\n${MC_OPEN}\n<purpose>text</purpose>\nescaped <\\/${"MODULE_CONTRACT"}\n${BLOCK_TERM}\n`;
241
+ const hit = findCompassTerminatorInHeader(source, "src/a.ts");
242
+ expect(hit).not.toBeNull();
243
+ expect(hit!.substring).toBe(BLOCK_TERM);
244
+ });
245
+
246
+ it("fires on the second comment when the first closed legally — state does not leak", () => {
247
+ const source = `/*\n${MC_OPEN}\n<purpose>clean</purpose>\n${MC_CLOSE}\n${BLOCK_TERM}\n\n/*\n${CS_OPEN}\n<item>oops ${BLOCK_TERM}</item>\n`;
248
+ const hit = findCompassTerminatorInHeader(source, "src/a.ts");
249
+ expect(hit).not.toBeNull();
250
+ expect(hit!.substring).toBe(BLOCK_TERM);
251
+ });
252
+
253
+ it(".astro: a phantom /* inside frontmatter code cannot hide a corrupt html header", () => {
254
+ const source = `---\nconst marker = "${"/*"}";\n---\n${HTML_OPEN}\n${CS_OPEN}\n <item>bad ${HTML_CLOSE}</item>\n${CS_CLOSE}\n${HTML_CLOSE}\n<main/>\n`;
255
+ const hit = findCompassTerminatorInHeader(source, "src/page.astro");
256
+ expect(hit).not.toBeNull();
257
+ expect(hit!.substring).toBe(HTML_CLOSE);
258
+ });
259
+
260
+ it("a --- line while Compass tags are open preserves state — the terminator still fires", () => {
261
+ const source = `${HTML_OPEN}\n${MC_OPEN}\n<purpose>text</purpose>\n---\n${HTML_CLOSE}\n`;
262
+ const hit = findCompassTerminatorInHeader(source, "docs/guide.md");
263
+ expect(hit).not.toBeNull();
264
+ expect(hit!.substring).toBe(HTML_CLOSE);
265
+ });
266
+
267
+ it("a --- line inside a tag-less comment resets state — a later close is a legal no-op", () => {
268
+ const source = `/* a note\n---\n${BLOCK_TERM}\nexport const x = 1;\n`;
269
+ expect(findCompassTerminatorInHeader(source, "src/a.ts")).toBeNull();
270
+ });
271
+ });
@@ -1,3 +1,21 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>
4
+ Unit tests for the compass v2 contract ruleset — evaluateV2Rules and
5
+ runCompassValidation over fixture workspaces covering CONTRACT, KD, CS,
6
+ PURPOSE, ORDER, and TODO rule families.
7
+ </purpose>
8
+ <non-goals>
9
+ <item>Fixture Compass markup is built via string concatenation so source-level validators never see literal block tags — do not inline real tag literals.</item>
10
+ </non-goals>
11
+ </MODULE_CONTRACT>
12
+ <CHANGE_SUMMARY>
13
+ <item>RFC-1311: Compass header sweep — declares the suite contract and escapes fixture tag literals for SYNTAX-01 parity.</item>
14
+ <item>RFC-1323: write-time comment-terminator safety — shared comment-safety seam, authored CS-08 reject, injected neutralization, header-region scan</item>
15
+ <item>RFC-1323: re-review pass — frontmatter-zone enclosing-style detection, existing-item pre-pass gating, trim exit-1 on unsafe, nextSteps rule labels, severity/census test coverage</item>
16
+ </CHANGE_SUMMARY>
17
+ */
18
+
1
19
  import { describe, it, expect, beforeEach, afterEach } from "vitest";
2
20
  import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
3
21
  import { dirname, join } from "node:path";
@@ -29,11 +47,15 @@ function makeInput(flags: Record<string, unknown> = {}): ForgeCommandInput {
29
47
  return { flags } as ForgeCommandInput;
30
48
  }
31
49
 
50
+ const MC_OPEN = "<" + "MODULE_CONTRACT>";
51
+ const MC_CLOSE = "</" + "MODULE_CONTRACT>";
32
52
  const MC = (purpose: string) =>
33
- `<MODULE_CONTRACT>\n<purpose>${purpose}</purpose>\n<non-goals>\n <item>Do not perform real validation — fixtures only.</item>\n</non-goals>\n</MODULE_CONTRACT>`;
53
+ `${MC_OPEN}\n<purpose>${purpose}</purpose>\n<non-goals>\n <item>Do not perform real validation — fixtures only.</item>\n</non-goals>\n${MC_CLOSE}`;
54
+ const KD_OPEN = "<" + "KEY_DECISIONS>";
55
+ const KD_CLOSE = "</" + "KEY_DECISIONS>";
34
56
  const KD = (items: string[]) =>
35
- `<KEY_DECISIONS>\n${items.map((i) => ` <item>${i}</item>`).join("\n")}\n</KEY_DECISIONS>`;
36
- const KD_EMPTY = `<KEY_DECISIONS>\n</KEY_DECISIONS>`;
57
+ `${KD_OPEN}\n${items.map((i) => ` <item>${i}</item>`).join("\n")}\n${KD_CLOSE}`;
58
+ const KD_EMPTY = `${KD_OPEN}\n${KD_CLOSE}`;
37
59
  // Dynamic tags: a literal CHANGE_SUMMARY block in this file would be matched
38
60
  // by compass.summary.record itself and rewritten at commit time.
39
61
  const CS_OPEN = "<" + "CHANGE_SUMMARY>";
@@ -252,6 +274,33 @@ describe("compass v2 contract (RFC-1094)", () => {
252
274
  expect(result.exitCode).toBeDefined();
253
275
  });
254
276
 
277
+ it("CS-08: a comment terminator truncating an unclosed Compass block is flagged (RFC-1323 AC-4)", async () => {
278
+ // The `*/` inside <purpose> closes the block comment while MODULE_CONTRACT
279
+ // and purpose are still open — parseCompassBlocks sees a truncated header;
280
+ // the raw-text scan must name it.
281
+ const truncTerm = "*" + "/";
282
+ const corrupted = `/*\n${MC_OPEN}\n<purpose>tracks widgets under packages${truncTerm}wg paths</purpose>\n${MC_CLOSE}\n${truncTerm}\n`;
283
+ writeFixture(LOW_FILE, corrupted);
284
+
285
+ const result = await runCompassValidation(makeInput(), makeContext(tempDir));
286
+ const diag = dataOf(result).diagnostics.find((d) => d.ruleId === "COMPASS-CS-08");
287
+ expect(diag, "CS-08 must fire on a mid-block comment terminator").toBeDefined();
288
+ expect(diag!.message).toContain(truncTerm);
289
+ // RFC-1323: corruption detection, not advisory debt — always an error,
290
+ // even in the default warning mode where sibling v2 rules stay warnings.
291
+ expect(diag!.severity).toBe("error");
292
+ });
293
+
294
+ it("CS-08 negative: a well-formed header emits no terminator diagnostic (RFC-1323)", async () => {
295
+ writeFixture(
296
+ LOW_FILE,
297
+ wrap(MC("Tracks mission notes for the compass v2 contract test suite."), CS([CS_ITEM])),
298
+ );
299
+
300
+ const result = await runCompassValidation(makeInput(), makeContext(tempDir));
301
+ expect(dataOf(result).diagnostics.find((d) => d.ruleId === "COMPASS-CS-08")).toBeUndefined();
302
+ });
303
+
255
304
  it("empty CHANGE_SUMMARY (no items, no history) is legal", async () => {
256
305
  writeFixture(MEDIUM_FILE, wrap(MC(PURPOSE_WITH_TOKEN), KD([KD_ITEM]), CS([])));
257
306