@warpgogol/forge 9.5.0 → 9.6.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 (338) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +30 -0
  3. package/README.uk.md +30 -0
  4. package/bin/cli.ts +19 -50
  5. package/dist/bin/cli.js +18 -43
  6. package/dist/bin/cli.js.map +1 -1
  7. package/dist/os/codebase/codebase.module.d.ts +3 -0
  8. package/dist/os/codebase/codebase.module.d.ts.map +1 -0
  9. package/dist/os/codebase/codebase.module.js +53 -0
  10. package/dist/os/codebase/codebase.module.js.map +1 -0
  11. package/dist/os/codebase/handlers/codebase-measure-symbols.d.ts +15 -0
  12. package/dist/os/codebase/handlers/codebase-measure-symbols.d.ts.map +1 -0
  13. package/dist/os/codebase/handlers/codebase-measure-symbols.js +97 -0
  14. package/dist/os/codebase/handlers/codebase-measure-symbols.js.map +1 -0
  15. package/dist/os/codebase/handlers/codebase-measure.d.ts +22 -0
  16. package/dist/os/codebase/handlers/codebase-measure.d.ts.map +1 -0
  17. package/dist/os/codebase/handlers/codebase-measure.js +435 -0
  18. package/dist/os/codebase/handlers/codebase-measure.js.map +1 -0
  19. package/dist/os/codebase/index.d.ts +4 -0
  20. package/dist/os/codebase/index.d.ts.map +1 -0
  21. package/dist/os/codebase/index.js +13 -0
  22. package/dist/os/codebase/index.js.map +1 -0
  23. package/dist/os/codebase/types.d.ts +35 -0
  24. package/dist/os/codebase/types.d.ts.map +1 -0
  25. package/dist/os/codebase/types.js +17 -0
  26. package/dist/os/codebase/types.js.map +1 -0
  27. package/dist/os/core/handlers/package-health.d.ts +6 -4
  28. package/dist/os/core/handlers/package-health.d.ts.map +1 -1
  29. package/dist/os/core/handlers/package-health.js +15 -20
  30. package/dist/os/core/handlers/package-health.js.map +1 -1
  31. package/dist/os/correctness/anchors.d.ts +24 -0
  32. package/dist/os/correctness/anchors.d.ts.map +1 -0
  33. package/dist/os/correctness/anchors.js +156 -0
  34. package/dist/os/correctness/anchors.js.map +1 -0
  35. package/dist/os/correctness/audit/bindings-verify-substance.d.ts +7 -0
  36. package/dist/os/correctness/audit/bindings-verify-substance.d.ts.map +1 -0
  37. package/dist/os/correctness/audit/bindings-verify-substance.js +145 -0
  38. package/dist/os/correctness/audit/bindings-verify-substance.js.map +1 -0
  39. package/dist/os/correctness/audit/differential.d.ts +7 -0
  40. package/dist/os/correctness/audit/differential.d.ts.map +1 -0
  41. package/dist/os/correctness/audit/differential.js +105 -0
  42. package/dist/os/correctness/audit/differential.js.map +1 -0
  43. package/dist/os/correctness/audit/ledger-orphans.d.ts +6 -0
  44. package/dist/os/correctness/audit/ledger-orphans.d.ts.map +1 -0
  45. package/dist/os/correctness/audit/ledger-orphans.js +71 -0
  46. package/dist/os/correctness/audit/ledger-orphans.js.map +1 -0
  47. package/dist/os/correctness/audit/ledger.d.ts +29 -0
  48. package/dist/os/correctness/audit/ledger.d.ts.map +1 -0
  49. package/dist/os/correctness/audit/ledger.js +72 -0
  50. package/dist/os/correctness/audit/ledger.js.map +1 -0
  51. package/dist/os/correctness/audit/run.d.ts +27 -0
  52. package/dist/os/correctness/audit/run.d.ts.map +1 -0
  53. package/dist/os/correctness/audit/run.js +184 -0
  54. package/dist/os/correctness/audit/run.js.map +1 -0
  55. package/dist/os/correctness/audit/schema-db.d.ts +32 -0
  56. package/dist/os/correctness/audit/schema-db.d.ts.map +1 -0
  57. package/dist/os/correctness/audit/schema-db.js +166 -0
  58. package/dist/os/correctness/audit/schema-db.js.map +1 -0
  59. package/dist/os/correctness/audit/snapshot.d.ts +34 -0
  60. package/dist/os/correctness/audit/snapshot.d.ts.map +1 -0
  61. package/dist/os/correctness/audit/snapshot.js +190 -0
  62. package/dist/os/correctness/audit/snapshot.js.map +1 -0
  63. package/dist/os/correctness/audit/sql-scanner.d.ts +28 -0
  64. package/dist/os/correctness/audit/sql-scanner.d.ts.map +1 -0
  65. package/dist/os/correctness/audit/sql-scanner.js +279 -0
  66. package/dist/os/correctness/audit/sql-scanner.js.map +1 -0
  67. package/dist/os/correctness/audit/sql-schema-conform.d.ts +17 -0
  68. package/dist/os/correctness/audit/sql-schema-conform.d.ts.map +1 -0
  69. package/dist/os/correctness/audit/sql-schema-conform.js +163 -0
  70. package/dist/os/correctness/audit/sql-schema-conform.js.map +1 -0
  71. package/dist/os/correctness/audit/state-transitions-coverage.d.ts +19 -0
  72. package/dist/os/correctness/audit/state-transitions-coverage.d.ts.map +1 -0
  73. package/dist/os/correctness/audit/state-transitions-coverage.js +263 -0
  74. package/dist/os/correctness/audit/state-transitions-coverage.js.map +1 -0
  75. package/dist/os/correctness/audit/tests/git-fixture.d.ts +15 -0
  76. package/dist/os/correctness/audit/tests/git-fixture.d.ts.map +1 -0
  77. package/dist/os/correctness/audit/tests/git-fixture.js +85 -0
  78. package/dist/os/correctness/audit/tests/git-fixture.js.map +1 -0
  79. package/dist/os/correctness/audit/types.d.ts +58 -0
  80. package/dist/os/correctness/audit/types.d.ts.map +1 -0
  81. package/dist/os/correctness/audit/types.js +34 -0
  82. package/dist/os/correctness/audit/types.js.map +1 -0
  83. package/dist/os/correctness/correctness.module.d.ts +3 -0
  84. package/dist/os/correctness/correctness.module.d.ts.map +1 -0
  85. package/dist/os/correctness/correctness.module.js +173 -0
  86. package/dist/os/correctness/correctness.module.js.map +1 -0
  87. package/dist/os/correctness/gate/frozen.d.ts +52 -0
  88. package/dist/os/correctness/gate/frozen.d.ts.map +1 -0
  89. package/dist/os/correctness/gate/frozen.js +322 -0
  90. package/dist/os/correctness/gate/frozen.js.map +1 -0
  91. package/dist/os/correctness/gate/origin.d.ts +28 -0
  92. package/dist/os/correctness/gate/origin.d.ts.map +1 -0
  93. package/dist/os/correctness/gate/origin.js +139 -0
  94. package/dist/os/correctness/gate/origin.js.map +1 -0
  95. package/dist/os/correctness/gate/repo.d.ts +25 -0
  96. package/dist/os/correctness/gate/repo.d.ts.map +1 -0
  97. package/dist/os/correctness/gate/repo.js +88 -0
  98. package/dist/os/correctness/gate/repo.js.map +1 -0
  99. package/dist/os/correctness/gate/run.d.ts +22 -0
  100. package/dist/os/correctness/gate/run.d.ts.map +1 -0
  101. package/dist/os/correctness/gate/run.js +430 -0
  102. package/dist/os/correctness/gate/run.js.map +1 -0
  103. package/dist/os/correctness/gate/runner.d.ts +18 -0
  104. package/dist/os/correctness/gate/runner.d.ts.map +1 -0
  105. package/dist/os/correctness/gate/runner.js +123 -0
  106. package/dist/os/correctness/gate/runner.js.map +1 -0
  107. package/dist/os/correctness/gate/tests/gate-fixture.d.ts +36 -0
  108. package/dist/os/correctness/gate/tests/gate-fixture.d.ts.map +1 -0
  109. package/dist/os/correctness/gate/tests/gate-fixture.js +153 -0
  110. package/dist/os/correctness/gate/tests/gate-fixture.js.map +1 -0
  111. package/dist/os/correctness/gate/types.d.ts +102 -0
  112. package/dist/os/correctness/gate/types.d.ts.map +1 -0
  113. package/dist/os/correctness/gate/types.js +64 -0
  114. package/dist/os/correctness/gate/types.js.map +1 -0
  115. package/dist/os/correctness/handlers/audit.d.ts +4 -0
  116. package/dist/os/correctness/handlers/audit.d.ts.map +1 -0
  117. package/dist/os/correctness/handlers/audit.js +95 -0
  118. package/dist/os/correctness/handlers/audit.js.map +1 -0
  119. package/dist/os/correctness/handlers/gate.d.ts +4 -0
  120. package/dist/os/correctness/handlers/gate.d.ts.map +1 -0
  121. package/dist/os/correctness/handlers/gate.js +62 -0
  122. package/dist/os/correctness/handlers/gate.js.map +1 -0
  123. package/dist/os/correctness/handlers/validate.d.ts +19 -0
  124. package/dist/os/correctness/handlers/validate.d.ts.map +1 -0
  125. package/dist/os/correctness/handlers/validate.js +367 -0
  126. package/dist/os/correctness/handlers/validate.js.map +1 -0
  127. package/dist/os/correctness/index.d.ts +8 -0
  128. package/dist/os/correctness/index.d.ts.map +1 -0
  129. package/dist/os/correctness/index.js +23 -0
  130. package/dist/os/correctness/index.js.map +1 -0
  131. package/dist/os/correctness/manifest-schema.d.ts +155 -0
  132. package/dist/os/correctness/manifest-schema.d.ts.map +1 -0
  133. package/dist/os/correctness/manifest-schema.js +110 -0
  134. package/dist/os/correctness/manifest-schema.js.map +1 -0
  135. package/dist/os/correctness/references.d.ts +22 -0
  136. package/dist/os/correctness/references.d.ts.map +1 -0
  137. package/dist/os/correctness/references.js +129 -0
  138. package/dist/os/correctness/references.js.map +1 -0
  139. package/dist/os/correctness/tests/fixture-workspace.d.ts +23 -0
  140. package/dist/os/correctness/tests/fixture-workspace.d.ts.map +1 -0
  141. package/dist/os/correctness/tests/fixture-workspace.js +104 -0
  142. package/dist/os/correctness/tests/fixture-workspace.js.map +1 -0
  143. package/dist/os/correctness/workspace.d.ts +32 -0
  144. package/dist/os/correctness/workspace.d.ts.map +1 -0
  145. package/dist/os/correctness/workspace.js +147 -0
  146. package/dist/os/correctness/workspace.js.map +1 -0
  147. package/dist/os/flow/correctness-step.d.ts +19 -0
  148. package/dist/os/flow/correctness-step.d.ts.map +1 -0
  149. package/dist/os/flow/correctness-step.js +133 -0
  150. package/dist/os/flow/correctness-step.js.map +1 -0
  151. package/dist/os/flow/digest.d.ts +18 -0
  152. package/dist/os/flow/digest.d.ts.map +1 -1
  153. package/dist/os/flow/digest.js +28 -1
  154. package/dist/os/flow/digest.js.map +1 -1
  155. package/dist/os/flow/flow.module.d.ts.map +1 -1
  156. package/dist/os/flow/flow.module.js +17 -3
  157. package/dist/os/flow/flow.module.js.map +1 -1
  158. package/dist/os/flow/handlers/flow-digest.d.ts.map +1 -1
  159. package/dist/os/flow/handlers/flow-digest.js +11 -1
  160. package/dist/os/flow/handlers/flow-digest.js.map +1 -1
  161. package/dist/os/flow/handlers/flow-integrate.d.ts +11 -0
  162. package/dist/os/flow/handlers/flow-integrate.d.ts.map +1 -1
  163. package/dist/os/flow/handlers/flow-integrate.js +90 -5
  164. package/dist/os/flow/handlers/flow-integrate.js.map +1 -1
  165. package/dist/os/flow/post-rebase-regen.d.ts +33 -0
  166. package/dist/os/flow/post-rebase-regen.d.ts.map +1 -0
  167. package/dist/os/flow/post-rebase-regen.js +120 -0
  168. package/dist/os/flow/post-rebase-regen.js.map +1 -0
  169. package/dist/os/flow/preflight.d.ts.map +1 -1
  170. package/dist/os/flow/preflight.js +11 -15
  171. package/dist/os/flow/preflight.js.map +1 -1
  172. package/dist/os/flow/publish.d.ts.map +1 -1
  173. package/dist/os/flow/publish.js +23 -4
  174. package/dist/os/flow/publish.js.map +1 -1
  175. package/dist/os/flow/registry.d.ts +4 -4
  176. package/dist/os/flow/tests/helpers.d.ts +9 -1
  177. package/dist/os/flow/tests/helpers.d.ts.map +1 -1
  178. package/dist/os/flow/tests/helpers.js +36 -2
  179. package/dist/os/flow/tests/helpers.js.map +1 -1
  180. package/dist/os/friction/types.d.ts +2 -2
  181. package/dist/os/gate-run/status.d.ts +12 -0
  182. package/dist/os/gate-run/status.d.ts.map +1 -1
  183. package/dist/os/gate-run/status.js +24 -3
  184. package/dist/os/gate-run/status.js.map +1 -1
  185. package/dist/os/program/schemas.d.ts +3 -3
  186. package/dist/os/queue/types.d.ts +2 -2
  187. package/dist/os/rfc/handlers/implement-stamp-promotes.d.ts +8 -0
  188. package/dist/os/rfc/handlers/implement-stamp-promotes.d.ts.map +1 -0
  189. package/dist/os/rfc/handlers/implement-stamp-promotes.js +65 -0
  190. package/dist/os/rfc/handlers/implement-stamp-promotes.js.map +1 -0
  191. package/dist/os/rfc/handlers/implement-stamp.d.ts.map +1 -1
  192. package/dist/os/rfc/handlers/implement-stamp.js +15 -2
  193. package/dist/os/rfc/handlers/implement-stamp.js.map +1 -1
  194. package/dist/os/rfc/handlers/validate-rules.d.ts.map +1 -1
  195. package/dist/os/rfc/handlers/validate-rules.js +26 -5
  196. package/dist/os/rfc/handlers/validate-rules.js.map +1 -1
  197. package/dist/os/rfc/rfc.module.d.ts.map +1 -1
  198. package/dist/os/rfc/rfc.module.js +18 -6
  199. package/dist/os/rfc/rfc.module.js.map +1 -1
  200. package/dist/os/rfc/types.d.ts +12 -3
  201. package/dist/os/rfc/types.d.ts.map +1 -1
  202. package/dist/os/rfc/types.js +5 -2
  203. package/dist/os/rfc/types.js.map +1 -1
  204. package/dist/os/rfc/verify-workspace.d.ts +12 -0
  205. package/dist/os/rfc/verify-workspace.d.ts.map +1 -1
  206. package/dist/os/rfc/verify-workspace.js +155 -0
  207. package/dist/os/rfc/verify-workspace.js.map +1 -1
  208. package/dist/os/system/task-schemas.d.ts +1 -1
  209. package/dist/os/system/tests/helpers.d.ts.map +1 -1
  210. package/dist/os/system/tests/helpers.js +6 -1
  211. package/dist/os/system/tests/helpers.js.map +1 -1
  212. package/dist/os/werkstatt/handlers/schema.d.ts +1 -1
  213. package/dist/src/command-modules.d.ts +4 -0
  214. package/dist/src/command-modules.d.ts.map +1 -0
  215. package/dist/src/command-modules.js +42 -0
  216. package/dist/src/command-modules.js.map +1 -0
  217. package/dist/src/config/forge-config.d.ts +16 -1
  218. package/dist/src/config/forge-config.d.ts.map +1 -1
  219. package/dist/src/config/forge-config.js +27 -11
  220. package/dist/src/config/forge-config.js.map +1 -1
  221. package/dist/src/correctness/index.d.ts +32 -0
  222. package/dist/src/correctness/index.d.ts.map +1 -0
  223. package/dist/src/correctness/index.js +157 -0
  224. package/dist/src/correctness/index.js.map +1 -0
  225. package/dist/src/correctness/schema-hash.d.ts +15 -0
  226. package/dist/src/correctness/schema-hash.d.ts.map +1 -0
  227. package/dist/src/correctness/schema-hash.js +44 -0
  228. package/dist/src/correctness/schema-hash.js.map +1 -0
  229. package/dist/src/knowledge/schema.d.ts +1 -1
  230. package/dist/src/onboarding/agents-generate.d.ts.map +1 -1
  231. package/dist/src/onboarding/agents-generate.js +20 -3
  232. package/dist/src/onboarding/agents-generate.js.map +1 -1
  233. package/dist/src/onboarding/create.d.ts +7 -0
  234. package/dist/src/onboarding/create.d.ts.map +1 -1
  235. package/dist/src/onboarding/create.js +62 -9
  236. package/dist/src/onboarding/create.js.map +1 -1
  237. package/docs/reference/correctness-audit.md +91 -0
  238. package/docs/reference/correctness-gate.md +102 -0
  239. package/docs/reference/correctness-manifest.md +142 -0
  240. package/docs/reference/forge-yaml.md +15 -0
  241. package/os/codebase/codebase.module.ts +57 -0
  242. package/os/codebase/handlers/codebase-measure-symbols.ts +131 -0
  243. package/os/codebase/handlers/codebase-measure.ts +503 -0
  244. package/os/codebase/index.ts +21 -0
  245. package/os/codebase/types.ts +55 -0
  246. package/os/core/handlers/package-health.test.ts +24 -2
  247. package/os/core/handlers/package-health.ts +16 -19
  248. package/os/correctness/anchors.ts +182 -0
  249. package/os/correctness/audit/bindings-verify-substance.test.ts +79 -0
  250. package/os/correctness/audit/bindings-verify-substance.ts +155 -0
  251. package/os/correctness/audit/differential.test.ts +113 -0
  252. package/os/correctness/audit/differential.ts +131 -0
  253. package/os/correctness/audit/ledger-orphans.test.ts +96 -0
  254. package/os/correctness/audit/ledger-orphans.ts +84 -0
  255. package/os/correctness/audit/ledger.test.ts +65 -0
  256. package/os/correctness/audit/ledger.ts +103 -0
  257. package/os/correctness/audit/run.ts +220 -0
  258. package/os/correctness/audit/schema-db.ts +208 -0
  259. package/os/correctness/audit/snapshot.ts +211 -0
  260. package/os/correctness/audit/sql-scanner.test.ts +84 -0
  261. package/os/correctness/audit/sql-scanner.ts +289 -0
  262. package/os/correctness/audit/sql-schema-conform.test.ts +170 -0
  263. package/os/correctness/audit/sql-schema-conform.ts +178 -0
  264. package/os/correctness/audit/state-transitions-coverage.test.ts +141 -0
  265. package/os/correctness/audit/state-transitions-coverage.ts +271 -0
  266. package/os/correctness/audit/tests/git-fixture.ts +98 -0
  267. package/os/correctness/audit/types.ts +91 -0
  268. package/os/correctness/correctness-capture.test.ts +107 -0
  269. package/os/correctness/correctness-chain.test.ts +232 -0
  270. package/os/correctness/correctness-coverage.test.ts +86 -0
  271. package/os/correctness/correctness-mode.test.ts +108 -0
  272. package/os/correctness/correctness-substrate.test.ts +64 -0
  273. package/os/correctness/correctness.module.ts +182 -0
  274. package/os/correctness/gate/anchor-events.test.ts +77 -0
  275. package/os/correctness/gate/freeze-coverage.test.ts +218 -0
  276. package/os/correctness/gate/freeze-diff.test.ts +110 -0
  277. package/os/correctness/gate/frozen.ts +399 -0
  278. package/os/correctness/gate/gate-mode.test.ts +76 -0
  279. package/os/correctness/gate/hardening.test.ts +175 -0
  280. package/os/correctness/gate/oracle-edit.test.ts +83 -0
  281. package/os/correctness/gate/oracle-origin.test.ts +142 -0
  282. package/os/correctness/gate/origin.ts +175 -0
  283. package/os/correctness/gate/repo.ts +102 -0
  284. package/os/correctness/gate/run.ts +547 -0
  285. package/os/correctness/gate/runner.ts +136 -0
  286. package/os/correctness/gate/substrate-attestation.test.ts +71 -0
  287. package/os/correctness/gate/tests/gate-fixture.ts +205 -0
  288. package/os/correctness/gate/tier-high.test.ts +92 -0
  289. package/os/correctness/gate/types.ts +144 -0
  290. package/os/correctness/handlers/audit.ts +107 -0
  291. package/os/correctness/handlers/gate.ts +75 -0
  292. package/os/correctness/handlers/validate.ts +514 -0
  293. package/os/correctness/index.ts +24 -0
  294. package/os/correctness/manifest-schema.ts +174 -0
  295. package/os/correctness/references.ts +143 -0
  296. package/os/correctness/tests/fixture-workspace.ts +119 -0
  297. package/os/correctness/workspace.ts +167 -0
  298. package/os/flow/correctness-step.ts +166 -0
  299. package/os/flow/digest.ts +40 -1
  300. package/os/flow/flow.module.ts +18 -3
  301. package/os/flow/handlers/flow-digest.ts +11 -1
  302. package/os/flow/handlers/flow-integrate.ts +117 -5
  303. package/os/flow/post-rebase-regen.ts +170 -0
  304. package/os/flow/preflight.ts +11 -19
  305. package/os/flow/publish.ts +23 -4
  306. package/os/flow/tests/flow-detachable.test.ts +31 -0
  307. package/os/flow/tests/flow-digest-correctness-trail.test.ts +55 -0
  308. package/os/flow/tests/flow-integrate-correctness-gate.test.ts +275 -0
  309. package/os/flow/tests/flow-integrate.post-rebase-regen.test.ts +234 -0
  310. package/os/flow/tests/flow-integrate.test.ts +10 -9
  311. package/os/flow/tests/helpers.ts +45 -24
  312. package/os/gate-run/status.ts +36 -3
  313. package/os/gate-run/tests/gate-run-status.test.ts +114 -0
  314. package/os/rfc/handlers/implement-stamp-promotes.test.ts +214 -0
  315. package/os/rfc/handlers/implement-stamp-promotes.ts +79 -0
  316. package/os/rfc/handlers/implement-stamp.ts +16 -2
  317. package/os/rfc/handlers/validate-rules.ts +43 -5
  318. package/os/rfc/rfc.module.ts +19 -6
  319. package/os/rfc/types.ts +16 -2
  320. package/os/rfc/verify-workspace-manifest.test.ts +55 -0
  321. package/os/rfc/verify-workspace.ts +167 -0
  322. package/os/system/tests/helpers.ts +6 -1
  323. package/package.json +41 -1
  324. package/profiles/typescript.yaml +16 -0
  325. package/skills/_shared/agent-operating-model.md +4 -0
  326. package/skills/fo/fo-idea-audit/SKILL.md +4 -0
  327. package/skills/fo/fo-idea-create-rfc/SKILL.md +6 -2
  328. package/skills/fo/fo-idea-implement/SKILL.md +8 -2
  329. package/skills/fo/fo-review/SKILL.md +16 -2
  330. package/src/command-modules.ts +62 -0
  331. package/src/config/forge-config.ts +37 -11
  332. package/src/correctness/index.ts +192 -0
  333. package/src/correctness/schema-hash.ts +59 -0
  334. package/src/onboarding/agents-generate.ts +20 -3
  335. package/src/onboarding/create.ts +59 -9
  336. package/src/tests/agents-generate-detach.test.ts +126 -0
  337. package/src/tests/codebase-measure-rfc-1581.test.ts +260 -0
  338. package/src/tests/command-modules.test.ts +34 -0
@@ -0,0 +1,110 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>RFC-1580 AC-3: deleting a manifest entry present at the base revision is CORR-GATE-02 and refuses in warn mode as well; an isolated weakening session can be accepted.</purpose>
4
+ <non-goals>
5
+ <item>Not a contract source of truth — gate/run.ts owns behaviour.</item>
6
+ </non-goals>
7
+ </MODULE_CONTRACT>
8
+ <CHANGE_SUMMARY>
9
+ <item>RFC-1580: initial suite.</item>
10
+ <item>RFC-1580: correctness.gate and the flow.integrate step
11
+
12
+ Add os/correctness/gate (frozen set at --base, weakening diff incl. byte changes without verifier trailers and frozen exempt mode, git-derived oracle origin with forge/oracle-review@1 records, argv oracle runner with timeout, schema-hash substrate attestation, anchor events, tier high/formal, forge/correctness-bundle@1), the correctness.gate command, test-side helpers @warpgogol/forge/correctness, bindings.paths.oracleReviewsDir, and flow.integrate spawning the primary install's gate after hooks/integration-gate.sh (FLOW-INT-18, --accept-weakening with an X-Correctness-Weakening trailer commit). Flow and system test primaries get a stand-in forge binary; integration warnings now survive the cleanup report.</item>
13
+ <item>RFC-1580: close review REVIEW-CODE-2026-11-13-04 findings
14
+
15
+ F1 bootstrap degrade only on an exact unknown-command stderr line with no JSON; F2 review records count only from a verifier-trailer commit naming them; F3 any frozen substrate change or dropped capture is a weakening, declared L3 needs loaded captures; F4 requirement origin needs acceptance before --base; F5 anchor events only for L2+ runs; F6 proof oracles via proof.check only, non-self; F7 bundle naming; F8/F9 limitations; F10 every anchor copy; F11 base entry refs; F12 unreadable base manifest refuses; F13 dirty worktree warning; F14 source/statement diffs; F15 process-group kill; F16 run root cleanup; F20 review dir stripped, blob hashes. Regression tests for spoofing, plain-commit review, L3, requirement origin, rewording, timeout, formal tier, rebind, real-gate pass, accept-weakening. DEV-1..DEV-6 recorded in the RFC.</item>
16
+ </CHANGE_SUMMARY>
17
+ */
18
+
19
+ import { afterEach, describe, expect, it } from "vitest";
20
+
21
+ import { runCorrectnessGate } from "./run.ts";
22
+ import {
23
+ L1_ORACLE,
24
+ MOCK_ORACLE,
25
+ ORACLE_PATH,
26
+ lifecycleOracle,
27
+ makeGateFixture,
28
+ manifestYaml,
29
+ reviewYaml,
30
+ type GateFixture,
31
+ } from "./tests/gate-fixture.ts";
32
+
33
+ const fixtures: GateFixture[] = [];
34
+ afterEach(() => fixtures.splice(0).forEach((f) => f.cleanup()));
35
+ const fx = (o: Parameters<typeof makeGateFixture>[0] = {}) => {
36
+ const f = makeGateFixture(o);
37
+ fixtures.push(f);
38
+ return f;
39
+ };
40
+ const gate = async (f: GateFixture, acceptWeakening?: string) => {
41
+ const out = await runCorrectnessGate(f.root, {
42
+ base: f.base,
43
+ bundleDir: `${f.root}/.bundles`,
44
+ acceptWeakening,
45
+ });
46
+ if (!out.ok) throw new Error(out.usageError);
47
+ return out.result;
48
+ };
49
+ const rules = (r: { violations: { rule: string }[] }) => r.violations.map((v) => v.rule);
50
+ void [L1_ORACLE, MOCK_ORACLE, ORACLE_PATH, lifecycleOracle, manifestYaml, reviewYaml];
51
+
52
+ describe("frozen-set diff", () => {
53
+ it("AC-3: a deleted base entry is CORR-GATE-02 and refuses in warn mode too", async () => {
54
+ const f = fx({ mode: "warn" });
55
+ f.write(
56
+ "docs/correctness.yaml",
57
+ "schema: forge/correctness-manifest@1\nentries: []\nsupport: []\nexemptions: []\n",
58
+ );
59
+ f.commit("drop the entry");
60
+ const r = await gate(f);
61
+ const v = r.violations.find((x) => x.rule === "CORR-GATE-02");
62
+ expect(v?.message, "deleting a frozen entry is a weakening").toMatch(
63
+ /entry CM-dispatch-01 was deleted/,
64
+ );
65
+ expect(v?.severity).toBe("error");
66
+ expect(r.status).toBe("fail");
67
+ });
68
+
69
+ it("a lowered substrate, an added unverifiable exemption, and a repointed checkRun are weakenings", async () => {
70
+ const f = fx();
71
+ f.write(
72
+ "docs/correctness.yaml",
73
+ manifestYaml({ substrate: "L1" })
74
+ .replace("substrate: L1", "substrate: L0")
75
+ .replace(
76
+ "exemptions: []",
77
+ 'exemptions:\n - ref: REQ-01\n kind: unverifiable\n reason: "nope"',
78
+ ),
79
+ );
80
+ f.write(
81
+ "forge.yaml",
82
+ f.read("forge.yaml").replace('checkRun: "node {file}"', 'checkRun: "true {file}"'),
83
+ );
84
+ f.commit("weaken");
85
+ const msgs = (await gate(f)).violations
86
+ .filter((x) => x.rule === "CORR-GATE-02")
87
+ .map((x) => x.message);
88
+ expect(msgs.some((m) => /substrate changed from L1 to L0/.test(m))).toBe(true);
89
+ expect(msgs.some((m) => /unverifiable exemption added for REQ-01/.test(m))).toBe(true);
90
+ expect(msgs.some((m) => /bindings.commands.checkRun changed/.test(m))).toBe(true);
91
+ });
92
+
93
+ it("--accept-weakening passes an isolated weakening session and refuses a mixed one", async () => {
94
+ const f = fx({ mode: "warn" });
95
+ f.write(
96
+ "docs/correctness.yaml",
97
+ "schema: forge/correctness-manifest@1\nentries: []\nsupport: []\nexemptions: []\n",
98
+ );
99
+ f.commit("drop the entry");
100
+ const isolated = await gate(f, "operator: entry retired with REQ-01");
101
+ expect(rules(isolated)).not.toContain("CORR-GATE-02");
102
+ expect(isolated.acceptedWeakening).toBe("operator: entry retired with REQ-01");
103
+ f.write("apps/api/src/other.ts", "export const x = 1;\n");
104
+ f.commit("unrelated change");
105
+ const mixed = await gate(f, "operator: entry retired with REQ-01");
106
+ expect(mixed.violations.find((x) => x.rule === "CORR-GATE-02")?.message).toMatch(
107
+ /mixed-weakening/,
108
+ );
109
+ });
110
+ });
@@ -0,0 +1,399 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>RFC-1580: the frozen set read at `--base` and the weakening diff
4
+ against the judged HEAD (CORR-GATE-02). Frozen: the manifest at the base
5
+ binding path, `checkRun` / `correctnessManifest` / `oracleReviewsDir`,
6
+ `correctness.mode` / `tier` / `audit.allow[]`, every oracle check file,
7
+ capture and sidecar named by a base entry, every file matched by the base
8
+ `support` globs, and the statements of the anchors base entries bind.</purpose>
9
+ <non-goals>
10
+ <item>No edit classifier — any byte change of a frozen file is a weakening unless the last commit touching it carries the verifier trailer pair (operator decision).</item>
11
+ <item>No acceptance decision — run.ts applies --accept-weakening.</item>
12
+ </non-goals>
13
+ </MODULE_CONTRACT>
14
+ <CHANGE_SUMMARY>
15
+ <item>RFC-1580: initial frozen set and weakening diff.</item>
16
+ <item>RFC-1580: correctness.gate and the flow.integrate step
17
+
18
+ Add os/correctness/gate (frozen set at --base, weakening diff incl. byte changes without verifier trailers and frozen exempt mode, git-derived oracle origin with forge/oracle-review@1 records, argv oracle runner with timeout, schema-hash substrate attestation, anchor events, tier high/formal, forge/correctness-bundle@1), the correctness.gate command, test-side helpers @warpgogol/forge/correctness, bindings.paths.oracleReviewsDir, and flow.integrate spawning the primary install's gate after hooks/integration-gate.sh (FLOW-INT-18, --accept-weakening with an X-Correctness-Weakening trailer commit). Flow and system test primaries get a stand-in forge binary; integration warnings now survive the cleanup report.</item>
19
+ <item>RFC-1580: close review REVIEW-CODE-2026-11-13-04 findings
20
+
21
+ F1 bootstrap degrade only on an exact unknown-command stderr line with no JSON; F2 review records count only from a verifier-trailer commit naming them; F3 any frozen substrate change or dropped capture is a weakening, declared L3 needs loaded captures; F4 requirement origin needs acceptance before --base; F5 anchor events only for L2+ runs; F6 proof oracles via proof.check only, non-self; F7 bundle naming; F8/F9 limitations; F10 every anchor copy; F11 base entry refs; F12 unreadable base manifest refuses; F13 dirty worktree warning; F14 source/statement diffs; F15 process-group kill; F16 run root cleanup; F20 review dir stripped, blob hashes. Regression tests for spoofing, plain-commit review, L3, requirement origin, rewording, timeout, formal tier, rebind, real-gate pass, accept-weakening. DEV-1..DEV-6 recorded in the RFC.</item>
22
+ <item>RFC-1580: close review REVIEW-CODE-2026-11-13-05 findings
23
+
24
+ N1 bootstrap degrade only while the base has not adopted the contour (a forge downgrade refuses); N2 L3 on data/lifecycle counts at its attested level; N3 anchor events bound to the attested handle; N4 new support-glob files are frozen additions; N5/N6 isolated sessions may touch anchor files and only frozen forge.yaml keys; N7 RFC body amended; N8 regression tests; N9 run root in finally and grandchildren reaped; N10 every declared capture loaded. DEV-7 recorded; DEV-5 narrowed pending operator confirmation.</item>
25
+ </CHANGE_SUMMARY>
26
+ */
27
+
28
+ import picomatch from "picomatch";
29
+ import { parse as parseYaml } from "yaml";
30
+
31
+ import { invariantStatementSha } from "../../../src/compass/invariant-parser.ts";
32
+ import { anchorsFromSource, buildAnchorIndex, isAnchorSourceCandidate } from "../anchors.ts";
33
+ import {
34
+ CAPTURE_SIDECAR_SUFFIX,
35
+ correctnessManifestSchema,
36
+ substrateRank,
37
+ type CorrectnessManifest,
38
+ } from "../manifest-schema.ts";
39
+ import { normalizeCheckRef, normalizeRelPath } from "../workspace.ts";
40
+ import { checkTarget, type GateRepo } from "./repo.ts";
41
+ import type { Weakening } from "./types.ts";
42
+
43
+ export interface CorrectnessSide {
44
+ manifestPath: string | null;
45
+ checkRun: string | null;
46
+ reviewsDir: string | null;
47
+ mode: string;
48
+ tier: string;
49
+ allow: { check: string; subject: string }[];
50
+ manifest: CorrectnessManifest | null;
51
+ compassDocs: string[];
52
+ invariantsFile: string | null;
53
+ }
54
+
55
+ /** Correctness settings + manifest as recorded in one forge.yaml/manifest text pair. */
56
+ export function sideFrom(
57
+ forgeYaml: string | null,
58
+ readManifest: (rel: string) => string | null,
59
+ ): CorrectnessSide {
60
+ let doc: Record<string, unknown> = {};
61
+ try {
62
+ doc = (forgeYaml ? parseYaml(forgeYaml) : {}) ?? {};
63
+ } catch {
64
+ doc = {};
65
+ }
66
+ const bindings = (doc["bindings"] ?? {}) as {
67
+ commands?: Record<string, unknown>;
68
+ paths?: Record<string, unknown>;
69
+ };
70
+ const section = (doc["correctness"] ?? {}) as Record<string, unknown>;
71
+ const manifestPath =
72
+ typeof bindings.paths?.["correctnessManifest"] === "string"
73
+ ? (bindings.paths["correctnessManifest"] as string)
74
+ : null;
75
+ let manifest: CorrectnessManifest | null = null;
76
+ if (manifestPath) {
77
+ const raw = readManifest(manifestPath);
78
+ if (raw) {
79
+ try {
80
+ const parsed = correctnessManifestSchema.safeParse(parseYaml(raw) ?? {});
81
+ if (parsed.success) manifest = parsed.data;
82
+ } catch {
83
+ manifest = null;
84
+ }
85
+ }
86
+ }
87
+ const allowRaw = ((section["audit"] ?? {}) as { allow?: unknown }).allow;
88
+ return {
89
+ manifestPath,
90
+ checkRun:
91
+ typeof bindings.commands?.["checkRun"] === "string"
92
+ ? (bindings.commands["checkRun"] as string)
93
+ : null,
94
+ reviewsDir:
95
+ typeof bindings.paths?.["oracleReviewsDir"] === "string"
96
+ ? (bindings.paths["oracleReviewsDir"] as string)
97
+ : null,
98
+ mode: typeof section["mode"] === "string" ? (section["mode"] as string) : "warn",
99
+ tier: typeof section["tier"] === "string" ? (section["tier"] as string) : "standard",
100
+ allow: Array.isArray(allowRaw)
101
+ ? (allowRaw as { check?: unknown; subject?: unknown }[]).map((a) => ({
102
+ check: String(a?.check ?? ""),
103
+ subject: String(a?.subject ?? ""),
104
+ }))
105
+ : [],
106
+ manifest,
107
+ compassDocs: Array.isArray(bindings.paths?.["compassDocs"])
108
+ ? (bindings.paths["compassDocs"] as string[])
109
+ : [],
110
+ invariantsFile:
111
+ typeof bindings.paths?.["invariantsFile"] === "string"
112
+ ? (bindings.paths["invariantsFile"] as string)
113
+ : null,
114
+ };
115
+ }
116
+
117
+ const TIER_RANK: Record<string, number> = { standard: 0, high: 1, formal: 2 };
118
+
119
+ export interface FrozenSet {
120
+ base: CorrectnessSide;
121
+ /** Frozen file paths (oracles, captures, sidecars, support matches) at base. */
122
+ files: string[];
123
+ /** Anchor id → normalized statement sha at base (anchors bound by base entries). */
124
+ anchors: Map<string, string>;
125
+ /** Requirement, DNA, and manifest-entry refs that existed at base (deferred exemptions for them are weakenings). */
126
+ baseRefs: Set<string>;
127
+ /** True when the base binds a manifest file that exists but does not parse. */
128
+ baseManifestUnreadable: boolean;
129
+ /** Base `support` globs (new files matching them are frozen-set additions). */
130
+ supportGlobs: string[];
131
+ /** Files at base that declare a frozen anchor (an isolated anchor change touches them). */
132
+ anchorFiles: string[];
133
+ /** Every file path at base. */
134
+ baseFiles: string[];
135
+ }
136
+
137
+ export async function readFrozenSet(repo: GateRepo, base: string): Promise<FrozenSet> {
138
+ const forgeYaml = await repo.show(base, "forge.yaml");
139
+ const manifests = new Map<string, string | null>();
140
+ const baseManifestPath = sideFrom(forgeYaml, () => null).manifestPath;
141
+ if (baseManifestPath)
142
+ manifests.set(baseManifestPath, await repo.show(base, normalizeRelPath(baseManifestPath)));
143
+ const side = sideFrom(forgeYaml, (rel) => manifests.get(rel) ?? null);
144
+ // A bound base manifest that exists but does not parse must not freeze
145
+ // nothing (fail-open) — the gate refuses until it is readable.
146
+ const baseManifestUnreadable =
147
+ baseManifestPath !== null &&
148
+ (manifests.get(baseManifestPath) ?? null) !== null &&
149
+ side.manifest === null;
150
+ const files = new Set<string>();
151
+ const baseFiles = await repo.files(base);
152
+ if (side.manifest) {
153
+ for (const entry of side.manifest.entries) {
154
+ for (const oracle of entry.oracles) {
155
+ const target = checkTarget(oracle.check);
156
+ if (target) files.add(normalizeRelPath(target));
157
+ for (const c of oracle.captures ?? []) {
158
+ files.add(normalizeRelPath(c));
159
+ files.add(`${normalizeRelPath(c)}${CAPTURE_SIDECAR_SUFFIX}`);
160
+ }
161
+ }
162
+ }
163
+ for (const glob of side.manifest.support) {
164
+ const match = picomatch(normalizeRelPath(glob), { dot: true });
165
+ for (const f of baseFiles) if (match(f)) files.add(f);
166
+ }
167
+ }
168
+ // Anchor statements at base, for ids bound by base entries.
169
+ const wanted = new Set((side.manifest?.entries ?? []).flatMap((e) => e.anchors));
170
+ const anchors = new Map<string, string>();
171
+ const anchorFiles = new Set<string>();
172
+ if (wanted.size > 0) {
173
+ const grep = await repo.git.run(["grep", "-l", "-z", "-F", "@ai-invariant[", base, "--"]);
174
+ const hits = (grep ?? "")
175
+ .split("\0")
176
+ .filter((l) => l.length > 0)
177
+ .map((l) => (l.startsWith(`${base}:`) ? l.slice(base.length + 1) : l))
178
+ .filter(isAnchorSourceCandidate);
179
+ for (const rel of hits) {
180
+ const text = await repo.show(base, rel);
181
+ if (!text) continue;
182
+ for (const a of anchorsFromSource(rel, text)) {
183
+ if (wanted.has(a.id)) anchorFiles.add(rel);
184
+ if (wanted.has(a.id) && !anchors.has(a.id))
185
+ anchors.set(a.id, invariantStatementSha(a.statement));
186
+ }
187
+ }
188
+ }
189
+ // Requirement / DNA ids at base.
190
+ const baseRefs = new Set<string>();
191
+ for (const rel of side.compassDocs) {
192
+ const text = await repo.show(base, normalizeRelPath(rel));
193
+ if (text && /<document-id>\s*requirements\s*<\/document-id>/.test(text)) {
194
+ for (const m of text.matchAll(/<requirement\b[^>]*?\bid\s*=\s*"([^"]+)"/g))
195
+ baseRefs.add(m[1]!);
196
+ }
197
+ }
198
+ if (side.invariantsFile) {
199
+ const text = await repo.show(base, normalizeRelPath(side.invariantsFile));
200
+ for (const m of (text ?? "").matchAll(/^##\s+DNA-(\d+)\b/gm)) baseRefs.add(`DNA-${m[1]}`);
201
+ }
202
+ for (const e of side.manifest?.entries ?? []) if (e.ref) baseRefs.add(e.ref);
203
+ return {
204
+ base: side,
205
+ files: [...files].sort(),
206
+ anchors,
207
+ baseRefs,
208
+ baseManifestUnreadable,
209
+ supportGlobs: side.manifest?.support ?? [],
210
+ anchorFiles: [...anchorFiles].sort(),
211
+ baseFiles,
212
+ };
213
+ }
214
+
215
+ /** The judged side, read from the working tree of the session worktree. */
216
+ export function readHeadSide(
217
+ root: string,
218
+ readFile: (rel: string) => string | null,
219
+ ): CorrectnessSide {
220
+ return sideFrom(readFile("forge.yaml"), (rel) => readFile(normalizeRelPath(rel)));
221
+ }
222
+
223
+ /** Structural weakenings: bindings, correctness section, entries, oracles, exemptions. */
224
+ export function diffWeakenings(frozen: FrozenSet, now: CorrectnessSide): Weakening[] {
225
+ const base = frozen.base;
226
+ const out: Weakening[] = [];
227
+ const add = (kind: string, subject: string, message: string) =>
228
+ out.push({ kind, subject, message });
229
+
230
+ // Bindings and the correctness section.
231
+ for (const [key, before, after] of [
232
+ ["bindings.paths.correctnessManifest", base.manifestPath, now.manifestPath],
233
+ ["bindings.commands.checkRun", base.checkRun, now.checkRun],
234
+ ["bindings.paths.oracleReviewsDir", base.reviewsDir, now.reviewsDir],
235
+ ] as const) {
236
+ if (before !== null && before !== after)
237
+ add(
238
+ "binding",
239
+ key,
240
+ `${key} changed from ${JSON.stringify(before)} to ${JSON.stringify(after)}`,
241
+ );
242
+ }
243
+ if (base.mode === "enforce" && now.mode !== "enforce")
244
+ add("mode", "correctness.mode", `correctness.mode changed from enforce to ${now.mode}`);
245
+ // A session must not exempt itself (it would also drop CORR-AUDIT-04, RFC-1579).
246
+ else if (base.mode !== "exempt" && now.mode === "exempt")
247
+ add("mode", "correctness.mode", `correctness.mode changed from ${base.mode} to exempt`);
248
+ if ((TIER_RANK[now.tier] ?? 0) < (TIER_RANK[base.tier] ?? 0))
249
+ add("tier", "correctness.tier", `correctness.tier lowered from ${base.tier} to ${now.tier}`);
250
+ const baseAllow = new Set(base.allow.map((a) => `${a.check}\0${a.subject}`));
251
+ for (const a of now.allow) {
252
+ if (!baseAllow.has(`${a.check}\0${a.subject}`))
253
+ add(
254
+ "allow",
255
+ `${a.check}:${a.subject}`,
256
+ `correctness.audit.allow[] gained ${a.check} ${a.subject}`,
257
+ );
258
+ }
259
+
260
+ // Manifest entries.
261
+ const nowEntries = new Map((now.manifest?.entries ?? []).map((e) => [e.id, e]));
262
+ for (const e of base.manifest?.entries ?? []) {
263
+ const n = nowEntries.get(e.id);
264
+ if (!n) {
265
+ add("entry-deleted", e.id, `manifest entry ${e.id} was deleted`);
266
+ continue;
267
+ }
268
+ if ((n.ref ?? null) !== (e.ref ?? null))
269
+ add("entry-changed", e.id, `${e.id} ref changed from ${e.ref ?? "∅"} to ${n.ref ?? "∅"}`);
270
+ if (n.seam !== e.seam)
271
+ add("entry-changed", e.id, `${e.id} seam changed from ${e.seam} to ${n.seam}`);
272
+ if (n.source !== e.source)
273
+ add("entry-changed", e.id, `${e.id} source changed from ${e.source} to ${n.source}`);
274
+ if ((n.statement ?? null) !== (e.statement ?? null))
275
+ add("entry-changed", e.id, `${e.id} statement changed`);
276
+ if ([...n.anchors].sort().join(",") !== [...e.anchors].sort().join(","))
277
+ add("entry-changed", e.id, `${e.id} anchors changed`);
278
+ const nowOracles = new Map(n.oracles.map((o) => [normalizeCheckRef(o.check), o]));
279
+ for (const o of e.oracles) {
280
+ const m = nowOracles.get(normalizeCheckRef(o.check));
281
+ if (!m)
282
+ add("oracle-removed", `${e.id}:${o.check}`, `${e.id} lost (or rebound) oracle ${o.check}`);
283
+ else {
284
+ // Any substrate change of a frozen oracle is a weakening: lowering
285
+ // drops rigor, raising re-declares what the oracle runs on.
286
+ if (m.substrate !== o.substrate) {
287
+ add(
288
+ substrateRank(m.substrate) < substrateRank(o.substrate)
289
+ ? "substrate-lowered"
290
+ : "substrate-changed",
291
+ `${e.id}:${o.check}`,
292
+ `${e.id} oracle ${o.check} substrate changed from ${o.substrate} to ${m.substrate}`,
293
+ );
294
+ }
295
+ const kept = new Set((m.captures ?? []).map(normalizeRelPath));
296
+ for (const c of o.captures ?? []) {
297
+ if (!kept.has(normalizeRelPath(c))) {
298
+ add(
299
+ "capture-dropped",
300
+ `${e.id}:${o.check}`,
301
+ `${e.id} oracle ${o.check} dropped capture ${c}`,
302
+ );
303
+ }
304
+ }
305
+ }
306
+ }
307
+ }
308
+
309
+ // Exemptions.
310
+ const baseEx = new Set((base.manifest?.exemptions ?? []).map((x) => `${x.ref}\0${x.kind}`));
311
+ for (const x of now.manifest?.exemptions ?? []) {
312
+ if (baseEx.has(`${x.ref}\0${x.kind}`)) continue;
313
+ if (x.kind === "unverifiable")
314
+ add("exemption", x.ref, `unverifiable exemption added for ${x.ref} (an operator decision)`);
315
+ else if (frozen.baseRefs.has(x.ref))
316
+ add(
317
+ "exemption",
318
+ x.ref,
319
+ `deferred exemption added for ${x.ref}, which existed at the base revision`,
320
+ );
321
+ }
322
+
323
+ return out;
324
+ }
325
+
326
+ /** Byte-change weakenings: a frozen file whose blob differs at HEAD, unless a verifier commit made the last change. */
327
+ export async function byteWeakenings(
328
+ repo: GateRepo,
329
+ base: string,
330
+ head: string,
331
+ files: string[],
332
+ ): Promise<Weakening[]> {
333
+ const out: Weakening[] = [];
334
+ for (const rel of files) {
335
+ const before = await repo.blob(base, rel);
336
+ const after = await repo.blob(head, rel);
337
+ if (before === after) continue;
338
+ if (after !== null && (await repo.lastTouchIsVerifier(head, rel))) continue;
339
+ out.push({
340
+ kind: "frozen-file",
341
+ subject: rel,
342
+ message:
343
+ after === null
344
+ ? `frozen file ${rel} was deleted`
345
+ : `frozen file ${rel} changed without the verifier trailer pair on its last commit`,
346
+ });
347
+ }
348
+ return out;
349
+ }
350
+
351
+ /** Anchor weakenings: a frozen anchor id removed, or its normalized statement changed. */
352
+ /**
353
+ * Files new at HEAD that match a base `support` glob (a new runner config or
354
+ * setup file shapes how frozen oracles run) — weakenings unless a verifier
355
+ * commit added them.
356
+ */
357
+ export async function supportAdditions(
358
+ repo: GateRepo,
359
+ base: string,
360
+ head: string,
361
+ frozen: FrozenSet,
362
+ ): Promise<Weakening[]> {
363
+ void base;
364
+ if (frozen.supportGlobs.length === 0) return [];
365
+ const before = new Set(frozen.baseFiles);
366
+ const matchers = frozen.supportGlobs.map((g) => picomatch(normalizeRelPath(g), { dot: true }));
367
+ const out: Weakening[] = [];
368
+ for (const rel of await repo.files(head)) {
369
+ if (before.has(rel) || !matchers.some((m) => m(rel))) continue;
370
+ if (await repo.lastTouchIsVerifier(head, rel)) continue;
371
+ out.push({
372
+ kind: "frozen-file",
373
+ subject: rel,
374
+ message: `new file ${rel} matches a frozen support glob and was not added by a verifier commit`,
375
+ });
376
+ }
377
+ return out;
378
+ }
379
+
380
+ export function anchorWeakenings(root: string, files: string[], frozen: FrozenSet): Weakening[] {
381
+ if (frozen.anchors.size === 0) return [];
382
+ const index = buildAnchorIndex(root, files, [...frozen.anchors.keys()]);
383
+ const out: Weakening[] = [];
384
+ for (const [id, sha] of frozen.anchors) {
385
+ const now = index.anchors.get(id) ?? [];
386
+ if (now.length === 0)
387
+ out.push({ kind: "anchor-removed", subject: id, message: `frozen anchor ${id} was removed` });
388
+ // Every copy must keep the frozen statement — a duplicate comment carrying
389
+ // the old text must not mask a reworded real anchor.
390
+ else if (!now.every((a) => invariantStatementSha(a.statement) === sha)) {
391
+ out.push({
392
+ kind: "anchor-reworded",
393
+ subject: id,
394
+ message: `frozen anchor ${id} statement changed`,
395
+ });
396
+ }
397
+ }
398
+ return out;
399
+ }
@@ -0,0 +1,76 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>RFC-1580 AC-8: correctness.mode semantics at the gate — warn mode
4
+ turns CORR-GATE-03..08 into warnings and passes; a covered entry passes in
5
+ enforce; exempt short-circuits.</purpose>
6
+ <non-goals>
7
+ <item>Not a contract source of truth — gate/run.ts owns behaviour.</item>
8
+ </non-goals>
9
+ </MODULE_CONTRACT>
10
+ <CHANGE_SUMMARY>
11
+ <item>RFC-1580: initial suite.</item>
12
+ <item>RFC-1580: correctness.gate and the flow.integrate step
13
+
14
+ Add os/correctness/gate (frozen set at --base, weakening diff incl. byte changes without verifier trailers and frozen exempt mode, git-derived oracle origin with forge/oracle-review@1 records, argv oracle runner with timeout, schema-hash substrate attestation, anchor events, tier high/formal, forge/correctness-bundle@1), the correctness.gate command, test-side helpers @warpgogol/forge/correctness, bindings.paths.oracleReviewsDir, and flow.integrate spawning the primary install's gate after hooks/integration-gate.sh (FLOW-INT-18, --accept-weakening with an X-Correctness-Weakening trailer commit). Flow and system test primaries get a stand-in forge binary; integration warnings now survive the cleanup report.</item>
15
+ </CHANGE_SUMMARY>
16
+ */
17
+
18
+ import { afterEach, describe, expect, it } from "vitest";
19
+
20
+ import { runCorrectnessGate } from "./run.ts";
21
+ import { makeGateFixture, type GateFixture } from "./tests/gate-fixture.ts";
22
+
23
+ const fixtures: GateFixture[] = [];
24
+ afterEach(() => fixtures.splice(0).forEach((f) => f.cleanup()));
25
+ const fx = (o: Parameters<typeof makeGateFixture>[0]) => {
26
+ const f = makeGateFixture(o);
27
+ fixtures.push(f);
28
+ return f;
29
+ };
30
+ const gate = async (f: GateFixture) => {
31
+ const out = await runCorrectnessGate(f.root, { base: f.base, bundleDir: `${f.root}/.bundles` });
32
+ if (!out.ok) throw new Error(out.usageError);
33
+ return out.result;
34
+ };
35
+
36
+ describe("gate mode", () => {
37
+ it("a reviewed, attested L1 oracle covers its data entry in enforce mode", async () => {
38
+ const r = await gate(fx({}));
39
+ expect(r.violations, JSON.stringify(r.violations)).toEqual([]);
40
+ expect(r.status).toBe("pass");
41
+ });
42
+
43
+ it("AC-8: in warn mode CORR-GATE-03..08 are warnings and the gate passes", async () => {
44
+ const f = fx({ mode: "warn", oracle: "process.exit(1);\n" });
45
+ const r = await gate(f);
46
+ const rules = new Set(r.violations.map((v) => v.rule));
47
+ expect(rules.has("CORR-GATE-07"), "the failing oracle must still be reported").toBe(true);
48
+ expect(r.violations.every((v) => v.severity === "warning")).toBe(true);
49
+ expect(r.status).toBe("pass");
50
+ });
51
+
52
+ it("the same failure refuses in enforce mode", async () => {
53
+ const r = await gate(fx({ oracle: "process.exit(1);\n" }));
54
+ expect(r.violations.find((v) => v.rule === "CORR-GATE-07")?.severity).toBe("error");
55
+ expect(r.status).toBe("fail");
56
+ });
57
+ });
58
+
59
+ describe("frozen exempt mode", () => {
60
+ it("a session that switches its repository to exempt is refused, not exempted", async () => {
61
+ const f = fx({});
62
+ f.write(
63
+ "forge.yaml",
64
+ f
65
+ .read("forge.yaml")
66
+ .replace("mode: enforce", "mode: exempt")
67
+ .replace(" correctnessManifest: docs/correctness.yaml\n", ""),
68
+ );
69
+ f.commit("exempt myself");
70
+ const r = await gate(f);
71
+ expect(r.status).toBe("fail");
72
+ expect(r.violations.some((v) => v.rule === "CORR-GATE-02" && /to exempt/.test(v.message))).toBe(
73
+ true,
74
+ );
75
+ });
76
+ });