@warpgogol/forge 9.4.1 → 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 (411) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +30 -0
  3. package/README.uk.md +30 -0
  4. package/bin/cli.ts +163 -53
  5. package/dist/bin/cli.js +137 -42
  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/dirty-classify.d.ts +7 -0
  156. package/dist/os/flow/dirty-classify.d.ts.map +1 -1
  157. package/dist/os/flow/dirty-classify.js +11 -0
  158. package/dist/os/flow/dirty-classify.js.map +1 -1
  159. package/dist/os/flow/flow.module.d.ts.map +1 -1
  160. package/dist/os/flow/flow.module.js +19 -4
  161. package/dist/os/flow/flow.module.js.map +1 -1
  162. package/dist/os/flow/handlers/flow-check.d.ts.map +1 -1
  163. package/dist/os/flow/handlers/flow-check.js +9 -9
  164. package/dist/os/flow/handlers/flow-check.js.map +1 -1
  165. package/dist/os/flow/handlers/flow-digest.d.ts.map +1 -1
  166. package/dist/os/flow/handlers/flow-digest.js +11 -1
  167. package/dist/os/flow/handlers/flow-digest.js.map +1 -1
  168. package/dist/os/flow/handlers/flow-integrate.d.ts +11 -0
  169. package/dist/os/flow/handlers/flow-integrate.d.ts.map +1 -1
  170. package/dist/os/flow/handlers/flow-integrate.js +148 -30
  171. package/dist/os/flow/handlers/flow-integrate.js.map +1 -1
  172. package/dist/os/flow/handlers/flow-open.d.ts.map +1 -1
  173. package/dist/os/flow/handlers/flow-open.js +14 -19
  174. package/dist/os/flow/handlers/flow-open.js.map +1 -1
  175. package/dist/os/flow/index.d.ts +1 -0
  176. package/dist/os/flow/index.d.ts.map +1 -1
  177. package/dist/os/flow/index.js +5 -3
  178. package/dist/os/flow/index.js.map +1 -1
  179. package/dist/os/flow/post-rebase-regen.d.ts +33 -0
  180. package/dist/os/flow/post-rebase-regen.d.ts.map +1 -0
  181. package/dist/os/flow/post-rebase-regen.js +120 -0
  182. package/dist/os/flow/post-rebase-regen.js.map +1 -0
  183. package/dist/os/flow/preflight.d.ts +24 -0
  184. package/dist/os/flow/preflight.d.ts.map +1 -1
  185. package/dist/os/flow/preflight.js +364 -24
  186. package/dist/os/flow/preflight.js.map +1 -1
  187. package/dist/os/flow/publish.d.ts.map +1 -1
  188. package/dist/os/flow/publish.js +23 -4
  189. package/dist/os/flow/publish.js.map +1 -1
  190. package/dist/os/flow/registry.d.ts +6 -6
  191. package/dist/os/flow/tests/helpers.d.ts +9 -1
  192. package/dist/os/flow/tests/helpers.d.ts.map +1 -1
  193. package/dist/os/flow/tests/helpers.js +36 -2
  194. package/dist/os/flow/tests/helpers.js.map +1 -1
  195. package/dist/os/friction/types.d.ts +2 -2
  196. package/dist/os/gate-run/detach.d.ts +27 -0
  197. package/dist/os/gate-run/detach.d.ts.map +1 -0
  198. package/dist/os/gate-run/detach.js +85 -0
  199. package/dist/os/gate-run/detach.js.map +1 -0
  200. package/dist/os/gate-run/gate-run.module.d.ts +3 -0
  201. package/dist/os/gate-run/gate-run.module.d.ts.map +1 -0
  202. package/dist/os/gate-run/gate-run.module.js +23 -0
  203. package/dist/os/gate-run/gate-run.module.js.map +1 -0
  204. package/dist/os/gate-run/index.d.ts +7 -0
  205. package/dist/os/gate-run/index.d.ts.map +1 -0
  206. package/dist/os/gate-run/index.js +5 -0
  207. package/dist/os/gate-run/index.js.map +1 -0
  208. package/dist/os/gate-run/record.d.ts +47 -0
  209. package/dist/os/gate-run/record.d.ts.map +1 -0
  210. package/dist/os/gate-run/record.js +157 -0
  211. package/dist/os/gate-run/record.js.map +1 -0
  212. package/dist/os/gate-run/status.d.ts +53 -0
  213. package/dist/os/gate-run/status.d.ts.map +1 -0
  214. package/dist/os/gate-run/status.js +163 -0
  215. package/dist/os/gate-run/status.js.map +1 -0
  216. package/dist/os/gate-run/types.d.ts +47 -0
  217. package/dist/os/gate-run/types.d.ts.map +1 -0
  218. package/dist/os/gate-run/types.js +24 -0
  219. package/dist/os/gate-run/types.js.map +1 -0
  220. package/dist/os/program/schemas.d.ts +3 -3
  221. package/dist/os/queue/types.d.ts +2 -2
  222. package/dist/os/rfc/evidence-annotation.d.ts +26 -0
  223. package/dist/os/rfc/evidence-annotation.d.ts.map +1 -0
  224. package/dist/os/rfc/evidence-annotation.js +52 -0
  225. package/dist/os/rfc/evidence-annotation.js.map +1 -0
  226. package/dist/os/rfc/handlers/fixed-inputs.d.ts.map +1 -1
  227. package/dist/os/rfc/handlers/fixed-inputs.js +7 -1
  228. package/dist/os/rfc/handlers/fixed-inputs.js.map +1 -1
  229. package/dist/os/rfc/handlers/implement-stamp-promotes.d.ts +8 -0
  230. package/dist/os/rfc/handlers/implement-stamp-promotes.d.ts.map +1 -0
  231. package/dist/os/rfc/handlers/implement-stamp-promotes.js +65 -0
  232. package/dist/os/rfc/handlers/implement-stamp-promotes.js.map +1 -0
  233. package/dist/os/rfc/handlers/implement-stamp.d.ts.map +1 -1
  234. package/dist/os/rfc/handlers/implement-stamp.js +35 -29
  235. package/dist/os/rfc/handlers/implement-stamp.js.map +1 -1
  236. package/dist/os/rfc/handlers/validate-rules.d.ts.map +1 -1
  237. package/dist/os/rfc/handlers/validate-rules.js +152 -11
  238. package/dist/os/rfc/handlers/validate-rules.js.map +1 -1
  239. package/dist/os/rfc/rfc.module.d.ts.map +1 -1
  240. package/dist/os/rfc/rfc.module.js +20 -7
  241. package/dist/os/rfc/rfc.module.js.map +1 -1
  242. package/dist/os/rfc/types.d.ts +12 -3
  243. package/dist/os/rfc/types.d.ts.map +1 -1
  244. package/dist/os/rfc/types.js +5 -2
  245. package/dist/os/rfc/types.js.map +1 -1
  246. package/dist/os/rfc/verify-workspace.d.ts +12 -0
  247. package/dist/os/rfc/verify-workspace.d.ts.map +1 -1
  248. package/dist/os/rfc/verify-workspace.js +155 -0
  249. package/dist/os/rfc/verify-workspace.js.map +1 -1
  250. package/dist/os/system/task-schemas.d.ts +1 -1
  251. package/dist/os/system/tests/helpers.d.ts.map +1 -1
  252. package/dist/os/system/tests/helpers.js +6 -1
  253. package/dist/os/system/tests/helpers.js.map +1 -1
  254. package/dist/os/werkstatt/handlers/schema.d.ts +1 -1
  255. package/dist/src/cli-flags.d.ts.map +1 -1
  256. package/dist/src/cli-flags.js +6 -0
  257. package/dist/src/cli-flags.js.map +1 -1
  258. package/dist/src/command-modules.d.ts +4 -0
  259. package/dist/src/command-modules.d.ts.map +1 -0
  260. package/dist/src/command-modules.js +42 -0
  261. package/dist/src/command-modules.js.map +1 -0
  262. package/dist/src/config/forge-config.d.ts +16 -1
  263. package/dist/src/config/forge-config.d.ts.map +1 -1
  264. package/dist/src/config/forge-config.js +27 -11
  265. package/dist/src/config/forge-config.js.map +1 -1
  266. package/dist/src/correctness/index.d.ts +32 -0
  267. package/dist/src/correctness/index.d.ts.map +1 -0
  268. package/dist/src/correctness/index.js +157 -0
  269. package/dist/src/correctness/index.js.map +1 -0
  270. package/dist/src/correctness/schema-hash.d.ts +15 -0
  271. package/dist/src/correctness/schema-hash.d.ts.map +1 -0
  272. package/dist/src/correctness/schema-hash.js +44 -0
  273. package/dist/src/correctness/schema-hash.js.map +1 -0
  274. package/dist/src/knowledge/schema.d.ts +1 -1
  275. package/dist/src/onboarding/agents-generate.d.ts.map +1 -1
  276. package/dist/src/onboarding/agents-generate.js +20 -3
  277. package/dist/src/onboarding/agents-generate.js.map +1 -1
  278. package/dist/src/onboarding/create.d.ts +7 -0
  279. package/dist/src/onboarding/create.d.ts.map +1 -1
  280. package/dist/src/onboarding/create.js +62 -9
  281. package/dist/src/onboarding/create.js.map +1 -1
  282. package/dist/src/types.d.ts +7 -0
  283. package/dist/src/types.d.ts.map +1 -1
  284. package/dist/src/types.js +2 -8
  285. package/dist/src/types.js.map +1 -1
  286. package/docs/reference/correctness-audit.md +91 -0
  287. package/docs/reference/correctness-gate.md +102 -0
  288. package/docs/reference/correctness-manifest.md +142 -0
  289. package/docs/reference/forge-yaml.md +15 -0
  290. package/os/codebase/codebase.module.ts +57 -0
  291. package/os/codebase/handlers/codebase-measure-symbols.ts +131 -0
  292. package/os/codebase/handlers/codebase-measure.ts +503 -0
  293. package/os/codebase/index.ts +21 -0
  294. package/os/codebase/types.ts +55 -0
  295. package/os/core/handlers/package-health.test.ts +24 -2
  296. package/os/core/handlers/package-health.ts +16 -19
  297. package/os/correctness/anchors.ts +182 -0
  298. package/os/correctness/audit/bindings-verify-substance.test.ts +79 -0
  299. package/os/correctness/audit/bindings-verify-substance.ts +155 -0
  300. package/os/correctness/audit/differential.test.ts +113 -0
  301. package/os/correctness/audit/differential.ts +131 -0
  302. package/os/correctness/audit/ledger-orphans.test.ts +96 -0
  303. package/os/correctness/audit/ledger-orphans.ts +84 -0
  304. package/os/correctness/audit/ledger.test.ts +65 -0
  305. package/os/correctness/audit/ledger.ts +103 -0
  306. package/os/correctness/audit/run.ts +220 -0
  307. package/os/correctness/audit/schema-db.ts +208 -0
  308. package/os/correctness/audit/snapshot.ts +211 -0
  309. package/os/correctness/audit/sql-scanner.test.ts +84 -0
  310. package/os/correctness/audit/sql-scanner.ts +289 -0
  311. package/os/correctness/audit/sql-schema-conform.test.ts +170 -0
  312. package/os/correctness/audit/sql-schema-conform.ts +178 -0
  313. package/os/correctness/audit/state-transitions-coverage.test.ts +141 -0
  314. package/os/correctness/audit/state-transitions-coverage.ts +271 -0
  315. package/os/correctness/audit/tests/git-fixture.ts +98 -0
  316. package/os/correctness/audit/types.ts +91 -0
  317. package/os/correctness/correctness-capture.test.ts +107 -0
  318. package/os/correctness/correctness-chain.test.ts +232 -0
  319. package/os/correctness/correctness-coverage.test.ts +86 -0
  320. package/os/correctness/correctness-mode.test.ts +108 -0
  321. package/os/correctness/correctness-substrate.test.ts +64 -0
  322. package/os/correctness/correctness.module.ts +182 -0
  323. package/os/correctness/gate/anchor-events.test.ts +77 -0
  324. package/os/correctness/gate/freeze-coverage.test.ts +218 -0
  325. package/os/correctness/gate/freeze-diff.test.ts +110 -0
  326. package/os/correctness/gate/frozen.ts +399 -0
  327. package/os/correctness/gate/gate-mode.test.ts +76 -0
  328. package/os/correctness/gate/hardening.test.ts +175 -0
  329. package/os/correctness/gate/oracle-edit.test.ts +83 -0
  330. package/os/correctness/gate/oracle-origin.test.ts +142 -0
  331. package/os/correctness/gate/origin.ts +175 -0
  332. package/os/correctness/gate/repo.ts +102 -0
  333. package/os/correctness/gate/run.ts +547 -0
  334. package/os/correctness/gate/runner.ts +136 -0
  335. package/os/correctness/gate/substrate-attestation.test.ts +71 -0
  336. package/os/correctness/gate/tests/gate-fixture.ts +205 -0
  337. package/os/correctness/gate/tier-high.test.ts +92 -0
  338. package/os/correctness/gate/types.ts +144 -0
  339. package/os/correctness/handlers/audit.ts +107 -0
  340. package/os/correctness/handlers/gate.ts +75 -0
  341. package/os/correctness/handlers/validate.ts +514 -0
  342. package/os/correctness/index.ts +24 -0
  343. package/os/correctness/manifest-schema.ts +174 -0
  344. package/os/correctness/references.ts +143 -0
  345. package/os/correctness/tests/fixture-workspace.ts +119 -0
  346. package/os/correctness/workspace.ts +167 -0
  347. package/os/flow/correctness-step.ts +166 -0
  348. package/os/flow/digest.ts +40 -1
  349. package/os/flow/dirty-classify.ts +13 -0
  350. package/os/flow/flow.module.ts +20 -4
  351. package/os/flow/handlers/flow-check.ts +17 -18
  352. package/os/flow/handlers/flow-digest.ts +11 -1
  353. package/os/flow/handlers/flow-integrate.ts +191 -39
  354. package/os/flow/handlers/flow-open.ts +24 -31
  355. package/os/flow/index.ts +5 -7
  356. package/os/flow/post-rebase-regen.ts +170 -0
  357. package/os/flow/preflight.ts +361 -27
  358. package/os/flow/publish.ts +23 -4
  359. package/os/flow/tests/flow-detachable.test.ts +31 -0
  360. package/os/flow/tests/flow-digest-correctness-trail.test.ts +55 -0
  361. package/os/flow/tests/flow-integrate-correctness-gate.test.ts +275 -0
  362. package/os/flow/tests/flow-integrate.post-rebase-regen.test.ts +234 -0
  363. package/os/flow/tests/flow-integrate.preflight.test.ts +26 -5
  364. package/os/flow/tests/flow-integrate.test.ts +77 -10
  365. package/os/flow/tests/helpers.ts +45 -24
  366. package/os/flow/tests/lockfile-induced.test.ts +328 -0
  367. package/os/gate-run/detach.ts +106 -0
  368. package/os/gate-run/gate-run.module.ts +25 -0
  369. package/os/gate-run/index.ts +16 -0
  370. package/os/gate-run/record.ts +194 -0
  371. package/os/gate-run/status.ts +201 -0
  372. package/os/gate-run/tests/gate-run-detach.test.ts +144 -0
  373. package/os/gate-run/tests/gate-run-record.test.ts +200 -0
  374. package/os/gate-run/tests/gate-run-status.test.ts +114 -0
  375. package/os/gate-run/types.ts +73 -0
  376. package/os/rfc/evidence-annotation.ts +61 -0
  377. package/os/rfc/handlers/fixed-inputs.test.ts +70 -0
  378. package/os/rfc/handlers/fixed-inputs.ts +11 -1
  379. package/os/rfc/handlers/implement-stamp-promotes.test.ts +214 -0
  380. package/os/rfc/handlers/implement-stamp-promotes.ts +79 -0
  381. package/os/rfc/handlers/implement-stamp.ts +40 -29
  382. package/os/rfc/handlers/list-create.test.ts +14 -5
  383. package/os/rfc/handlers/validate-evidence-shape.test.ts +218 -0
  384. package/os/rfc/handlers/validate-probe-meta.test.ts +71 -0
  385. package/os/rfc/handlers/validate-rules.ts +211 -21
  386. package/os/rfc/handlers/validate-transient-probes.test.ts +222 -0
  387. package/os/rfc/rfc-0000-template.md +10 -10
  388. package/os/rfc/rfc.module.ts +21 -7
  389. package/os/rfc/types.ts +16 -2
  390. package/os/rfc/verify-workspace-manifest.test.ts +55 -0
  391. package/os/rfc/verify-workspace.ts +167 -0
  392. package/os/system/tests/helpers.ts +6 -1
  393. package/package.json +57 -1
  394. package/profiles/typescript.yaml +16 -0
  395. package/skills/_shared/agent-operating-model.md +4 -0
  396. package/skills/fo/fo-idea-audit/SKILL.md +4 -0
  397. package/skills/fo/fo-idea-create-rfc/SKILL.md +6 -2
  398. package/skills/fo/fo-idea-implement/SKILL.md +8 -2
  399. package/skills/fo/fo-review/SKILL.md +16 -2
  400. package/skills/fo/fo-session-retro/SKILL.md +4 -2
  401. package/src/cli-flags.ts +7 -0
  402. package/src/command-modules.ts +62 -0
  403. package/src/config/forge-config.ts +37 -11
  404. package/src/correctness/index.ts +192 -0
  405. package/src/correctness/schema-hash.ts +59 -0
  406. package/src/onboarding/agents-generate.ts +20 -3
  407. package/src/onboarding/create.ts +59 -9
  408. package/src/tests/agents-generate-detach.test.ts +126 -0
  409. package/src/tests/codebase-measure-rfc-1581.test.ts +260 -0
  410. package/src/tests/command-modules.test.ts +34 -0
  411. package/src/types.ts +9 -8
@@ -0,0 +1,178 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>RFC-1579 CORR-AUDIT-01 `sql.schema.conform` — every static SQL
4
+ statement literal in non-test TypeScript must prepare against the real D1
5
+ schema its package owns (`node:sqlite` `prepare()`); `no such column` /
6
+ `no such table` are findings, a migration that fails to apply is a finding,
7
+ everything else (interpolated templates, D1-only syntax) is unverifiable.</purpose>
8
+ <non-goals>
9
+ <item>Never execute statements — `prepare()` only.</item>
10
+ <item>No partial schema — a failed migration makes its package's statements unverifiable.</item>
11
+ <item>No judgement of in-code SQLite storage — a statement touching a table only a `CREATE TABLE` literal in code creates (Durable Object storage) is unverifiable.</item>
12
+ </non-goals>
13
+ </MODULE_CONTRACT>
14
+ <CHANGE_SUMMARY>
15
+ <item>RFC-1579: initial auditor.</item>
16
+ <item>RFC-1579: correctness.audit auditors and differential attribution
17
+
18
+ Add os/correctness/audit: tree snapshots (working tree, index, base via one cat-file batch with git-grep prefilter), literal scanner + SQL classifier, wrangler D1 schema builder on node:sqlite, the four auditors (sql.schema.conform, ledger.orphans, state.transitions.coverage, bindings.verify.substance), subject-keyed differential attribution with allow-list, survival ledger, the correctness.audit handler and registration, and bindings.paths.correctnessLedger.</item>
19
+ <item>RFC-1579: gate line, ecosystem.commit early run, reference page
20
+
21
+ typescript profile integration-gate.sh runs the primary install's correctness.audit against FLOW_BASE_SHA; werkstatt ecosystem.commit gains EC-34 (correctness.audit --staged, refuses introduced CORR-AUDIT-01..03, warns on CORR-AUDIT-04); in-code CREATE TABLE tables (Durable Object storage) are unverifiable instead of D1 findings; correctness.audit declares generates: []; reference page and agent guides.
22
+
23
+ Measured on werkstatt (rollout step 3): 7 wrangler D1 configs, ~10 s per run, 3 legacy sql.schema.conform findings (packages/warpgogol-billing-cloudflare against schemas outside the repo), 127 unverifiable statements, no state machines; CORR-AUDIT-04 present (verify equals test) — fixed by the werkstatt gate-wiring queue task.</item>
24
+ <item>RFC-1579: close review REVIEW-CODE-2026-11-13-01 findings
25
+
26
+ F1 INSERT 'has no column named' is a finding; F2 severity/kind escalation since base is introduced; F3 unparseable machine tables are errors; F4 comma joins, string literals and comments in table extraction; F5 only migration INSERT/REPLACE seed writes; F6 SET-clause-only coverage; F7 method-call writers; F8 regex literals in the scanner; F9 alias resolution; F10 EC-34 judges the payload only; F11 EC-34 before the scoped gates with a dry-run line; F12/F13 config and YAML errors named; F14 config-only check skips snapshots; F15 git grep failures fail closed; F16 portable prefilter; F17 shell no-ops; F18 shared D1 schemas; in-code DDL scoped per package; ledger tests. DEV-1..DEV-4 recorded in the RFC Deviations section.</item>
27
+ <item>RFC-1579: close review REVIEW-CODE-2026-11-13-02 findings
28
+
29
+ N1 EC-34 disowns only findings located in foreign staged files (a payload migration breaking committed code refuses); N2 case-insensitive alias resolution; N3 reference names *.tsx; N4 top-level SET clause. EC-34 payload-scoping tests.</item>
30
+ </CHANGE_SUMMARY>
31
+ */
32
+
33
+ import { candidateSchemas, type SchemaDiscovery } from "./schema-db.ts";
34
+ import { tableAccess, type SqlStatement } from "./sql-scanner.ts";
35
+ import type { AuditorOutput, RawFinding } from "./types.ts";
36
+
37
+ const MISSING_RE = /no such (column|table): ([A-Za-z0-9_."]+)/i;
38
+ // SQLite reports an INSERT column the table lacks with a different message.
39
+ const NO_COLUMN_NAMED_RE = /table ["`]?([A-Za-z0-9_]+)["`]? has no column named ([A-Za-z0-9_]+)/i;
40
+
41
+ /** Alias → table map from `FROM|JOIN <table> [AS] <alias>` (and `UPDATE <table>`). */
42
+ function aliasesOf(sql: string): Map<string, string> {
43
+ const out = new Map<string, string>();
44
+ const re =
45
+ /\b(?:FROM|JOIN|UPDATE|INTO)\s+["`[]?([A-Za-z_][A-Za-z0-9_]*)["`\]]?(?:\s+(?:AS\s+)?([A-Za-z_][A-Za-z0-9_]*))?/gi;
46
+ const keywords =
47
+ /^(?:WHERE|SET|ON|JOIN|LEFT|RIGHT|INNER|OUTER|CROSS|GROUP|ORDER|LIMIT|VALUES|USING|RETURNING|UNION|SELECT|AND|OR)$/i;
48
+ for (const m of sql.matchAll(re)) {
49
+ const table = m[1]!.toLowerCase();
50
+ out.set(table, table);
51
+ if (m[2] && !keywords.test(m[2])) out.set(m[2].toLowerCase(), table);
52
+ }
53
+ return out;
54
+ }
55
+
56
+ /** Table owning a missing column: alias-qualified, else the single table the statement names, else "?". */
57
+ function owningTable(sql: string, column: string): string {
58
+ const aliases = aliasesOf(sql);
59
+ if (column.includes(".")) {
60
+ const q = column.split(".")[0]!.toLowerCase();
61
+ return aliases.get(q) ?? q;
62
+ }
63
+ const unique = [...new Set(aliases.values())];
64
+ return unique.length === 1 ? unique[0]! : "?";
65
+ }
66
+
67
+ /** Package scope of a path: its first two segments (`packages/x`, `apps/y`), or "" at the root. */
68
+ export function packageScope(file: string): string {
69
+ const parts = file.split("/");
70
+ return parts.length > 2 ? `${parts[0]}/${parts[1]}` : "";
71
+ }
72
+
73
+ const IN_CODE_DDL_RE =
74
+ /\bCREATE\s+(?:VIRTUAL\s+)?TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?["`[]?([A-Za-z_][A-Za-z0-9_]*)/gi;
75
+
76
+ /**
77
+ * Tables created by `CREATE TABLE` string literals in code (Durable Object or
78
+ * embedded SQLite storage), keyed by package scope. They belong to a database
79
+ * no wrangler D1 binding declares, so a statement in the same package that
80
+ * touches one cannot be judged against D1.
81
+ */
82
+ export function inCodeTables(literals: { file: string; text: string }[]): Map<string, Set<string>> {
83
+ const out = new Map<string, Set<string>>();
84
+ for (const { file, text } of literals) {
85
+ const scope = packageScope(file);
86
+ const set = out.get(scope) ?? new Set<string>();
87
+ for (const m of text.matchAll(IN_CODE_DDL_RE)) set.add(m[1]!.toLowerCase());
88
+ out.set(scope, set);
89
+ }
90
+ return out;
91
+ }
92
+
93
+ export function auditSqlSchemaConform(
94
+ discovery: SchemaDiscovery,
95
+ statements: SqlStatement[],
96
+ codeTablesByScope: Map<string, Set<string>> = new Map(),
97
+ ): AuditorOutput {
98
+ const findings: RawFinding[] = [];
99
+ let unverifiable = 0;
100
+ for (const f of discovery.failures) {
101
+ findings.push({
102
+ check: "sql.schema.conform",
103
+ subject: f.migration,
104
+ severity: "error",
105
+ message:
106
+ f.kind === "config"
107
+ ? `wrangler config unreadable: ${f.message}`
108
+ : `migration does not apply: ${f.message}`,
109
+ location: { file: f.migration, line: 1 },
110
+ });
111
+ }
112
+ for (const st of statements) {
113
+ const failedOwner = [...discovery.failedPackages].some(
114
+ (dir) => dir === "" || st.file.startsWith(`${dir}/`),
115
+ );
116
+ const candidates = candidateSchemas(discovery.schemas, st.file);
117
+ if (st.interpolated || failedOwner || candidates.length === 0) {
118
+ unverifiable += 1;
119
+ continue;
120
+ }
121
+ const errors: string[] = [];
122
+ let prepared = false;
123
+ for (const schema of candidates) {
124
+ try {
125
+ schema.db.prepare(st.sql);
126
+ prepared = true;
127
+ break;
128
+ } catch (err) {
129
+ errors.push((err as Error).message);
130
+ }
131
+ }
132
+ if (prepared) continue;
133
+ // A finding only when it fails against every candidate with a missing name.
134
+ let kind: "column" | "table" | null = null;
135
+ let name = "";
136
+ let tableHint: string | null = null;
137
+ for (const e of errors) {
138
+ const m = MISSING_RE.exec(e);
139
+ if (m) {
140
+ kind = m[1]!.toLowerCase() as "column" | "table";
141
+ name = m[2]!.replace(/"/g, "");
142
+ break;
143
+ }
144
+ const n = NO_COLUMN_NAMED_RE.exec(e);
145
+ if (n) {
146
+ kind = "column";
147
+ tableHint = n[1]!.toLowerCase();
148
+ name = n[2]!;
149
+ break;
150
+ }
151
+ }
152
+ if (kind === null) {
153
+ unverifiable += 1;
154
+ continue;
155
+ }
156
+ const codeTables = codeTablesByScope.get(packageScope(st.file)) ?? new Set<string>();
157
+ // A statement touching an in-code-DDL table that no candidate D1 schema
158
+ // declares targets another database — unverifiable, never a finding.
159
+ const access = tableAccess(st.sql);
160
+ const touched = [...access.reads, ...access.writes];
161
+ if (touched.some((t) => codeTables.has(t) && !candidates.some((c) => c.tables.has(t)))) {
162
+ unverifiable += 1;
163
+ continue;
164
+ }
165
+ const subject =
166
+ kind === "table"
167
+ ? `${st.file}:${name.toLowerCase()}`
168
+ : `${st.file}:${tableHint ?? owningTable(st.sql, name)}.${name.includes(".") ? name.split(".")[1] : name}`;
169
+ findings.push({
170
+ check: "sql.schema.conform",
171
+ subject,
172
+ severity: "error",
173
+ message: `no such ${kind}: ${name}`,
174
+ location: { file: st.file, line: st.line },
175
+ });
176
+ }
177
+ return { findings, unverifiable, skipped: [] };
178
+ }
@@ -0,0 +1,141 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>RFC-1579 AC-5: `state.transitions.coverage` — a declared
4
+ `@state-machine[<name>]` edge whose target no declared writer receives is a
5
+ finding named `<machine>:<from>→<to>`; literal-argument calls, literal-tuple
6
+ loops, and SQL column literals cover a target; undeclared machines skip.</purpose>
7
+ <non-goals>
8
+ <item>Not a contract source of truth — the auditor owns behaviour.</item>
9
+ </non-goals>
10
+ </MODULE_CONTRACT>
11
+ <CHANGE_SUMMARY>
12
+ <item>RFC-1579: initial suite.</item>
13
+ <item>RFC-1579: correctness.audit auditors and differential attribution
14
+
15
+ Add os/correctness/audit: tree snapshots (working tree, index, base via one cat-file batch with git-grep prefilter), literal scanner + SQL classifier, wrangler D1 schema builder on node:sqlite, the four auditors (sql.schema.conform, ledger.orphans, state.transitions.coverage, bindings.verify.substance), subject-keyed differential attribution with allow-list, survival ledger, the correctness.audit handler and registration, and bindings.paths.correctnessLedger.</item>
16
+ <item>RFC-1579: close review REVIEW-CODE-2026-11-13-01 findings
17
+
18
+ F1 INSERT 'has no column named' is a finding; F2 severity/kind escalation since base is introduced; F3 unparseable machine tables are errors; F4 comma joins, string literals and comments in table extraction; F5 only migration INSERT/REPLACE seed writes; F6 SET-clause-only coverage; F7 method-call writers; F8 regex literals in the scanner; F9 alias resolution; F10 EC-34 judges the payload only; F11 EC-34 before the scoped gates with a dry-run line; F12/F13 config and YAML errors named; F14 config-only check skips snapshots; F15 git grep failures fail closed; F16 portable prefilter; F17 shell no-ops; F18 shared D1 schemas; in-code DDL scoped per package; ledger tests. DEV-1..DEV-4 recorded in the RFC Deviations section.</item>
19
+ <item>RFC-1579: close review REVIEW-CODE-2026-11-13-02 findings
20
+
21
+ N1 EC-34 disowns only findings located in foreign staged files (a payload migration breaking committed code refuses); N2 case-insensitive alias resolution; N3 reference names *.tsx; N4 top-level SET clause. EC-34 payload-scoping tests.</item>
22
+ <item>RFC-1579: close review REVIEW-CODE-2026-11-13-03 observations
23
+
24
+ R1 sub-select text in SET never counts as a state write; R2 DEV-2 and rollout step 5 describe the foreign-staged rule; correctness.audit listed under commands.added.</item>
25
+ </CHANGE_SUMMARY>
26
+ */
27
+
28
+ import { afterEach, describe, expect, it } from "vitest";
29
+
30
+ import { runCorrectnessAudit } from "./run.ts";
31
+ import { makeGitFixture, type GitFixture } from "./tests/git-fixture.ts";
32
+
33
+ const fixtures: GitFixture[] = [];
34
+ afterEach(() => fixtures.splice(0).forEach((f) => f.cleanup()));
35
+
36
+ const MARK = "@state-" + "machine";
37
+ const EDGES = `// ${MARK}[candidate] (writers: transition) (column: state)
38
+ export const EDGES = [
39
+ { from: "draft", to: "approved" },
40
+ { from: "approved", to: "send_ready" },
41
+ { from: "send_ready", to: "queued" },
42
+ ];
43
+ export function transition(db: unknown, id: string, to: string) { return [db, id, to]; }
44
+ `;
45
+ const RECORD = `// ${MARK}[order] (writers: move)
46
+ export const ORDER: Record<string, string[]> = {
47
+ open: ["paid"],
48
+ paid: ["shipped", "refunded"],
49
+ };
50
+ `;
51
+
52
+ const coverage = async (files: Record<string, string>) => {
53
+ const f = makeGitFixture();
54
+ fixtures.push(f);
55
+ for (const [rel, body] of Object.entries(files)) f.write(rel, body);
56
+ const out = await runCorrectnessAudit(f.root, {
57
+ base: f.base,
58
+ check: "state.transitions.coverage",
59
+ });
60
+ if (!out.ok) throw new Error(out.usageError);
61
+ return out.result;
62
+ };
63
+
64
+ describe("state.transitions.coverage", () => {
65
+ it("AC-5: an edge whose target no writer receives is reported by name", async () => {
66
+ const result = await coverage({
67
+ "packages/domain/src/candidate.ts": EDGES,
68
+ "apps/api/src/review.ts":
69
+ 'import { transition } from "x";\nexport const go = (db: unknown) => transition(db, "c1", "approved");\n',
70
+ "apps/api/src/queue.ts":
71
+ "export const q = \"UPDATE candidates SET state = 'queued' WHERE id = ?\";\n",
72
+ });
73
+ const subjects = result.findings.map((x) => x.subject);
74
+ expect(subjects, "approved→send_ready has no writer — defect #2's static half").toEqual([
75
+ "candidate:approved→send_ready",
76
+ ]);
77
+ expect(result.findings[0]!.attribution).toBe("introduced");
78
+ expect(result.findings[0]!.rule).toBe("CORR-AUDIT-03");
79
+ });
80
+
81
+ it("a literal tuple iterated into the writer covers every listed state", async () => {
82
+ const result = await coverage({
83
+ "packages/domain/src/candidate.ts": EDGES,
84
+ "apps/api/src/dispatch2.ts":
85
+ 'export async function run(db: unknown) {\n transition(db, "c", "approved");\n for (const to of ["send_ready", "queued"] as const) {\n await transition(db, "c", to);\n }\n}\n',
86
+ });
87
+ expect(result.findings).toEqual([]);
88
+ });
89
+
90
+ it("Record<State, State[]> tables are audited too", async () => {
91
+ const result = await coverage({
92
+ "apps/api/src/order.ts": RECORD,
93
+ "apps/api/src/pay.ts":
94
+ 'export const p = () => { move("o", "paid"); move("o", "shipped"); };\n',
95
+ });
96
+ expect(result.findings.map((x) => x.subject)).toEqual(["order:paid→refunded"]);
97
+ });
98
+
99
+ it("without a declared machine the auditor reports a skip", async () => {
100
+ const result = await coverage({});
101
+ expect(result.skipped).toContain("state.transitions.coverage: no-declared-machine");
102
+ });
103
+
104
+ it("a marker without a parseable table is reported, never a silent pass", async () => {
105
+ const result = await coverage({
106
+ "apps/api/src/m.ts": `// ${MARK}[broken] (writers: go)\nexport const T = new Map([["a", "b"]]);\n`,
107
+ });
108
+ expect(result.findings.map((x) => x.subject)).toEqual(["broken:unparseable-table"]);
109
+ });
110
+
111
+ it("method-call writers cover; a WHERE clause from-state does not", async () => {
112
+ const result = await coverage({
113
+ "packages/domain/src/candidate.ts": EDGES,
114
+ "apps/api/src/svc.ts":
115
+ 'export const run = (repo: any) => { repo.transition(db, "c", "approved"); repo.transition(db, "c", "queued"); };\n' +
116
+ "export const q = \"UPDATE candidates SET updated_at = 1 WHERE state = 'send_ready'\";\n",
117
+ });
118
+ expect(result.findings.map((x) => x.subject)).toEqual(["candidate:approved→send_ready"]);
119
+ });
120
+
121
+ it("a sub-select WHERE inside SET does not hide a later state assignment", async () => {
122
+ const result = await coverage({
123
+ "packages/domain/src/candidate.ts": EDGES,
124
+ "apps/api/src/sql.ts":
125
+ 'export const a = () => transition(db, "c", "approved");\n' +
126
+ "export const q = \"UPDATE candidates SET n = (SELECT 1 FROM x WHERE y = 1), state = 'send_ready' WHERE id = ?\";\n" +
127
+ "export const r = \"UPDATE candidates SET state = 'queued' WHERE id = ?\";\n",
128
+ });
129
+ expect(result.findings).toEqual([]);
130
+ });
131
+
132
+ it("a state named only inside a sub-select WHERE is not a write", async () => {
133
+ const result = await coverage({
134
+ "packages/domain/src/candidate.ts": EDGES,
135
+ "apps/api/src/sub.ts":
136
+ 'export const a = () => { transition(db, "c", "approved"); transition(db, "c", "queued"); };\n' +
137
+ "export const q = \"UPDATE candidates SET n = (SELECT 1 FROM x WHERE state = 'send_ready') WHERE id = ?\";\n",
138
+ });
139
+ expect(result.findings.map((x) => x.subject)).toEqual(["candidate:approved→send_ready"]);
140
+ });
141
+ });
@@ -0,0 +1,271 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>RFC-1579 CORR-AUDIT-03 `state.transitions.coverage` — every target
4
+ state of an explicitly declared machine needs a writer. A machine is declared
5
+ by a comment marker directly above its transition table:
6
+ `// @state-machine[<name>] (writers: <fn>[, <fn>]) [(column: <sql column>)]`.
7
+ Tables are an array of `{ from: "…", to: "…" }` object literals or a
8
+ `Record<State, State[]>` object literal. A target `S` is covered when a
9
+ non-test file calls a declared writer with `S` as a string-literal argument,
10
+ iterates a literal tuple containing `S` into that call, or carries a static
11
+ SQL UPDATE/INSERT literal setting the declared column to `'S'`.</purpose>
12
+ <non-goals>
13
+ <item>No inference from string-literal unions — only declared machines are audited.</item>
14
+ <item>No runtime proof — the dynamic half is an L2 manifest oracle (RFC-1578).</item>
15
+ </non-goals>
16
+ </MODULE_CONTRACT>
17
+ <CHANGE_SUMMARY>
18
+ <item>RFC-1579: initial auditor and marker grammar.</item>
19
+ <item>RFC-1579: correctness.audit auditors and differential attribution
20
+
21
+ Add os/correctness/audit: tree snapshots (working tree, index, base via one cat-file batch with git-grep prefilter), literal scanner + SQL classifier, wrangler D1 schema builder on node:sqlite, the four auditors (sql.schema.conform, ledger.orphans, state.transitions.coverage, bindings.verify.substance), subject-keyed differential attribution with allow-list, survival ledger, the correctness.audit handler and registration, and bindings.paths.correctnessLedger.</item>
22
+ <item>RFC-1579: close review REVIEW-CODE-2026-11-13-01 findings
23
+
24
+ F1 INSERT 'has no column named' is a finding; F2 severity/kind escalation since base is introduced; F3 unparseable machine tables are errors; F4 comma joins, string literals and comments in table extraction; F5 only migration INSERT/REPLACE seed writes; F6 SET-clause-only coverage; F7 method-call writers; F8 regex literals in the scanner; F9 alias resolution; F10 EC-34 judges the payload only; F11 EC-34 before the scoped gates with a dry-run line; F12/F13 config and YAML errors named; F14 config-only check skips snapshots; F15 git grep failures fail closed; F16 portable prefilter; F17 shell no-ops; F18 shared D1 schemas; in-code DDL scoped per package; ledger tests. DEV-1..DEV-4 recorded in the RFC Deviations section.</item>
25
+ <item>RFC-1579: close review REVIEW-CODE-2026-11-13-02 findings
26
+
27
+ N1 EC-34 disowns only findings located in foreign staged files (a payload migration breaking committed code refuses); N2 case-insensitive alias resolution; N3 reference names *.tsx; N4 top-level SET clause. EC-34 payload-scoping tests.</item>
28
+ <item>RFC-1579: close review REVIEW-CODE-2026-11-13-03 observations
29
+
30
+ R1 sub-select text in SET never counts as a state write; R2 DEV-2 and rollout step 5 describe the foreign-staged rule; correctness.audit listed under commands.added.</item>
31
+ </CHANGE_SUMMARY>
32
+ */
33
+
34
+ import { isTestFile, type TreeSnapshot } from "./snapshot.ts";
35
+ import { scanStatements } from "./sql-scanner.ts";
36
+ import type { AuditorOutput, RawFinding } from "./types.ts";
37
+
38
+ const MARKER_RE =
39
+ /\/\/\s*@state-machine\[([A-Za-z0-9_-]+)\]\s*\(\s*writers\s*:\s*([^)]*)\)\s*(?:\(\s*column\s*:\s*([A-Za-z_][A-Za-z0-9_]*)\s*\))?/;
40
+
41
+ export interface StateMachine {
42
+ name: string;
43
+ file: string;
44
+ line: number;
45
+ writers: string[];
46
+ column: string | null;
47
+ edges: { from: string; to: string }[];
48
+ }
49
+
50
+ /** Index of the bracket that closes the one at `open` (strings respected), or -1. */
51
+ function matchBracket(text: string, open: number): number {
52
+ const opener = text[open]!;
53
+ const closer = opener === "[" ? "]" : opener === "{" ? "}" : ")";
54
+ let depth = 0;
55
+ for (let i = open; i < text.length; i += 1) {
56
+ const ch = text[i]!;
57
+ if (ch === '"' || ch === "'" || ch === "`") {
58
+ const q = ch;
59
+ i += 1;
60
+ while (i < text.length && text[i] !== q) {
61
+ if (text[i] === "\\") i += 1;
62
+ i += 1;
63
+ }
64
+ continue;
65
+ }
66
+ if (ch === "/" && text[i + 1] === "/") {
67
+ while (i < text.length && text[i] !== "\n") i += 1;
68
+ continue;
69
+ }
70
+ if (ch === opener) depth += 1;
71
+ else if (ch === closer) {
72
+ depth -= 1;
73
+ if (depth === 0) return i;
74
+ }
75
+ }
76
+ return -1;
77
+ }
78
+
79
+ const STR = `["'\`]([^"'\`]+)["'\`]`;
80
+
81
+ function parseTable(literal: string): { from: string; to: string }[] {
82
+ const edges: { from: string; to: string }[] = [];
83
+ if (literal.startsWith("[")) {
84
+ for (const obj of literal.matchAll(/\{[^{}]*\}/g)) {
85
+ const from = new RegExp(`["']?\\bfrom["']?\\s*:\\s*${STR}`).exec(obj[0])?.[1];
86
+ const to = new RegExp(`["']?\\bto["']?\\s*:\\s*${STR}`).exec(obj[0])?.[1];
87
+ if (from && to) edges.push({ from, to });
88
+ }
89
+ } else {
90
+ const body = literal.slice(1, -1);
91
+ for (const m of body.matchAll(
92
+ new RegExp(`(?:${STR}|([A-Za-z_][A-Za-z0-9_]*))\\s*:\\s*\\[([^\\]]*)\\]`, "g"),
93
+ )) {
94
+ const from = m[1] ?? m[2]!;
95
+ for (const t of m[3]!.matchAll(new RegExp(STR, "g"))) edges.push({ from, to: t[1]! });
96
+ }
97
+ }
98
+ return edges;
99
+ }
100
+
101
+ /** Find every declared machine in the snapshot's non-test files. */
102
+ export function findStateMachines(snapshot: TreeSnapshot): StateMachine[] {
103
+ const machines: StateMachine[] = [];
104
+ for (const [file, text] of snapshot.files) {
105
+ if (isTestFile(file) || !text.includes("@state-machine[")) continue;
106
+ const lines = text.split("\n");
107
+ let offset = 0;
108
+ for (let i = 0; i < lines.length; i += 1) {
109
+ const lineText = lines[i]!;
110
+ const m = MARKER_RE.exec(lineText);
111
+ if (m) {
112
+ const afterMarker = offset + lineText.length + 1;
113
+ const eq = text.indexOf("=", afterMarker);
114
+ let open = eq === -1 ? -1 : eq + 1;
115
+ while (open !== -1 && open < text.length && /\s/.test(text[open]!)) open += 1;
116
+ const edges: { from: string; to: string }[] = [];
117
+ if (open !== -1 && (text[open] === "[" || text[open] === "{")) {
118
+ const close = matchBracket(text, open);
119
+ if (close !== -1) edges.push(...parseTable(text.slice(open, close + 1)));
120
+ }
121
+ machines.push({
122
+ name: m[1]!,
123
+ file,
124
+ line: i + 1,
125
+ writers: m[2]!
126
+ .split(",")
127
+ .map((w) => w.trim())
128
+ .filter((w) => /^[A-Za-z_$][\w$]*$/.test(w)),
129
+ column: m[3] ?? null,
130
+ edges,
131
+ });
132
+ }
133
+ offset += lineText.length + 1;
134
+ }
135
+ }
136
+ return machines;
137
+ }
138
+
139
+ /** Writer names of every declared machine (feeds the two-pass snapshot loader). */
140
+ export function declaredWriters(files: Map<string, string>): string[] {
141
+ return [...new Set(findStateMachines({ label: "", files }).flatMap((m) => m.writers))];
142
+ }
143
+
144
+ function stringLiterals(text: string): string[] {
145
+ return [...text.matchAll(new RegExp(STR, "g"))].map((m) => m[1]!);
146
+ }
147
+
148
+ /** States a writer call or literal-tuple loop feeding it covers in one file. */
149
+ function coveredByCalls(text: string, writer: string): Set<string> {
150
+ const covered = new Set<string>();
151
+ // Free functions and method calls (`repo.transition(…)`) both count.
152
+ const callRe = new RegExp(`(?<![\\w$])${writer.replace(/\$/g, "\\$")}\\s*\\(`, "g");
153
+ // Loop variables bound to literal tuples: for (const v of ["a", "b"] as const) { … }
154
+ const loops: { variable: string; states: string[]; start: number; end: number }[] = [];
155
+ for (const m of text.matchAll(/for\s*\(\s*(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s+of\s+\[/g)) {
156
+ const open = m.index! + m[0].length - 1;
157
+ const close = matchBracket(text, open);
158
+ if (close === -1) continue;
159
+ const states = stringLiterals(text.slice(open, close + 1));
160
+ const bodyOpen = text.indexOf("{", close);
161
+ const bodyClose = bodyOpen === -1 ? -1 : matchBracket(text, bodyOpen);
162
+ if (bodyClose === -1) continue;
163
+ loops.push({ variable: m[1]!, states, start: bodyOpen, end: bodyClose });
164
+ }
165
+ for (const m of text.matchAll(callRe)) {
166
+ const open = m.index! + m[0].length - 1;
167
+ const close = matchBracket(text, open);
168
+ if (close === -1) continue;
169
+ const args = text.slice(open + 1, close);
170
+ for (const s of stringLiterals(args)) covered.add(s);
171
+ for (const loop of loops) {
172
+ if (
173
+ m.index! > loop.start &&
174
+ m.index! < loop.end &&
175
+ new RegExp(`(?<![\\w$])${loop.variable}(?![\\w$])`).test(args)
176
+ ) {
177
+ loop.states.forEach((s) => covered.add(s));
178
+ }
179
+ }
180
+ }
181
+ return covered;
182
+ }
183
+
184
+ /** The top-level SET clause of an UPDATE (sub-selects blanked), cut at the first top-level WHERE / RETURNING. */
185
+ function topLevelSetClause(sql: string): string {
186
+ const start = /\bSET\b/i.exec(sql);
187
+ if (!start) return "";
188
+ let depth = 0;
189
+ let out = "";
190
+ for (let i = start.index + 3; i < sql.length; i += 1) {
191
+ const ch = sql[i]!;
192
+ if (ch === "(") depth += 1;
193
+ else if (ch === ")") depth -= 1;
194
+ else if (
195
+ depth === 0 &&
196
+ /^(?:WHERE|RETURNING)\b/i.test(sql.slice(i)) &&
197
+ /\W/.test(sql[i - 1] ?? " ")
198
+ )
199
+ break;
200
+ // Sub-select text is blanked: `(SELECT … WHERE state = 'x')` writes nothing.
201
+ out += depth > 0 || ch === ")" ? " " : ch;
202
+ }
203
+ return out;
204
+ }
205
+
206
+ function coveredBySql(file: string, text: string, column: string): Set<string> {
207
+ const covered = new Set<string>();
208
+ for (const st of scanStatements(file, text)) {
209
+ if (st.kind === "update") {
210
+ // Only the SET clause writes; `WHERE state = 'approved'` names the from-state.
211
+ const set = topLevelSetClause(st.sql);
212
+ for (const m of set.matchAll(new RegExp(`\\b${column}\\s*=\\s*'([^']+)'`, "g")))
213
+ covered.add(m[1]!);
214
+ } else if (st.kind === "insert" || st.kind === "replace") {
215
+ const cols = /\(([^)]*)\)\s*VALUES\s*\(([^)]*)\)/i.exec(st.sql);
216
+ if (!cols) continue;
217
+ const names = cols[1]!.split(",").map((c) => c.trim().replace(/["`[\]]/g, ""));
218
+ const values = cols[2]!.split(",").map((v) => v.trim());
219
+ const idx = names.indexOf(column);
220
+ const v = idx === -1 ? undefined : values[idx];
221
+ const lit = v ? /^'([^']+)'$/.exec(v) : null;
222
+ if (lit) covered.add(lit[1]!);
223
+ }
224
+ }
225
+ return covered;
226
+ }
227
+
228
+ export function auditStateTransitions(snapshot: TreeSnapshot): AuditorOutput {
229
+ const machines = findStateMachines(snapshot);
230
+ if (machines.length === 0) {
231
+ return {
232
+ findings: [],
233
+ unverifiable: 0,
234
+ skipped: ["state.transitions.coverage: no-declared-machine"],
235
+ };
236
+ }
237
+ const findings: RawFinding[] = [];
238
+ const codeFiles = [...snapshot.files].filter(
239
+ ([f]) => /\.(?:ts|mts|tsx)$/.test(f) && !isTestFile(f),
240
+ );
241
+ for (const machine of machines) {
242
+ if (machine.edges.length === 0) {
243
+ // A marker whose table cannot be parsed is reported, never a silent pass.
244
+ findings.push({
245
+ check: "state.transitions.coverage",
246
+ subject: `${machine.name}:unparseable-table`,
247
+ severity: "error",
248
+ message: `@state-machine[${machine.name}] marks no parseable transition table (expected an array of { from, to } literals or a Record<State, State[]> object literal directly below the marker)`,
249
+ location: { file: machine.file, line: machine.line },
250
+ });
251
+ continue;
252
+ }
253
+ const covered = new Set<string>();
254
+ for (const [file, text] of codeFiles) {
255
+ for (const writer of machine.writers)
256
+ coveredByCalls(text, writer).forEach((s) => covered.add(s));
257
+ if (machine.column) coveredBySql(file, text, machine.column).forEach((s) => covered.add(s));
258
+ }
259
+ for (const edge of machine.edges) {
260
+ if (covered.has(edge.to)) continue;
261
+ findings.push({
262
+ check: "state.transitions.coverage",
263
+ subject: `${machine.name}:${edge.from}→${edge.to}`,
264
+ severity: "error",
265
+ message: `declared edge ${edge.from} → ${edge.to} has no writer: no call of ${machine.writers.join("/") || "(no writers declared)"} receives "${edge.to}"${machine.column ? ` and no SQL sets ${machine.column} = '${edge.to}'` : ""}`,
266
+ location: { file: machine.file, line: machine.line },
267
+ });
268
+ }
269
+ }
270
+ return { findings, unverifiable: 0, skipped: [] };
271
+ }