@warpgogol/forge 8.0.4 → 9.0.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 (660) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/bin/cli.ts +25 -13
  3. package/dist/bin/cli.js +17 -13
  4. package/dist/bin/cli.js.map +1 -1
  5. package/dist/os/adr/handlers/implement-stamp.d.ts.map +1 -1
  6. package/dist/os/adr/handlers/implement-stamp.js +1 -0
  7. package/dist/os/adr/handlers/implement-stamp.js.map +1 -1
  8. package/dist/os/adr/types.d.ts +2 -0
  9. package/dist/os/adr/types.d.ts.map +1 -1
  10. package/dist/os/agent/agent.module.d.ts +3 -0
  11. package/dist/os/agent/agent.module.d.ts.map +1 -0
  12. package/dist/os/agent/agent.module.js +60 -0
  13. package/dist/os/agent/agent.module.js.map +1 -0
  14. package/dist/os/agent/handlers/agent-delegate.d.ts +29 -0
  15. package/dist/os/agent/handlers/agent-delegate.d.ts.map +1 -0
  16. package/dist/os/agent/handlers/agent-delegate.js +187 -0
  17. package/dist/os/agent/handlers/agent-delegate.js.map +1 -0
  18. package/dist/os/agent/handlers/agent-tiers-validate.d.ts +15 -0
  19. package/dist/os/agent/handlers/agent-tiers-validate.d.ts.map +1 -0
  20. package/dist/os/agent/handlers/agent-tiers-validate.js +205 -0
  21. package/dist/os/agent/handlers/agent-tiers-validate.js.map +1 -0
  22. package/dist/os/agent/index.d.ts +5 -0
  23. package/dist/os/agent/index.d.ts.map +1 -0
  24. package/dist/os/agent/index.js +14 -0
  25. package/dist/os/agent/index.js.map +1 -0
  26. package/dist/os/agent/invoke-adapter.d.ts +43 -0
  27. package/dist/os/agent/invoke-adapter.d.ts.map +1 -0
  28. package/dist/os/agent/invoke-adapter.js +83 -0
  29. package/dist/os/agent/invoke-adapter.js.map +1 -0
  30. package/dist/os/authority/authority.module.d.ts.map +1 -1
  31. package/dist/os/authority/authority.module.js +2 -10
  32. package/dist/os/authority/authority.module.js.map +1 -1
  33. package/dist/os/checks/checks.module.d.ts +3 -0
  34. package/dist/os/checks/checks.module.d.ts.map +1 -0
  35. package/dist/os/checks/checks.module.js +90 -0
  36. package/dist/os/checks/checks.module.js.map +1 -0
  37. package/dist/os/checks/handlers/contribution-report.d.ts +35 -0
  38. package/dist/os/checks/handlers/contribution-report.d.ts.map +1 -0
  39. package/dist/os/checks/handlers/contribution-report.js +264 -0
  40. package/dist/os/checks/handlers/contribution-report.js.map +1 -0
  41. package/dist/os/checks/handlers/counters-export.d.ts +19 -0
  42. package/dist/os/checks/handlers/counters-export.d.ts.map +1 -0
  43. package/dist/os/checks/handlers/counters-export.js +122 -0
  44. package/dist/os/checks/handlers/counters-export.js.map +1 -0
  45. package/dist/os/checks/handlers/counters-journal.d.ts +67 -0
  46. package/dist/os/checks/handlers/counters-journal.d.ts.map +1 -0
  47. package/dist/os/checks/handlers/counters-journal.js +154 -0
  48. package/dist/os/checks/handlers/counters-journal.js.map +1 -0
  49. package/dist/os/checks/handlers/counters-validate.d.ts +11 -0
  50. package/dist/os/checks/handlers/counters-validate.d.ts.map +1 -0
  51. package/dist/os/checks/handlers/counters-validate.js +131 -0
  52. package/dist/os/checks/handlers/counters-validate.js.map +1 -0
  53. package/dist/os/checks/index.d.ts +6 -0
  54. package/dist/os/checks/index.d.ts.map +1 -0
  55. package/dist/os/checks/index.js +6 -0
  56. package/dist/os/checks/index.js.map +1 -0
  57. package/dist/os/compass/compass.module.d.ts.map +1 -1
  58. package/dist/os/compass/compass.module.js +55 -20
  59. package/dist/os/compass/compass.module.js.map +1 -1
  60. package/dist/os/compass/handlers/compass-header-scaffold.d.ts.map +1 -1
  61. package/dist/os/compass/handlers/compass-header-scaffold.js +4 -2
  62. package/dist/os/compass/handlers/compass-header-scaffold.js.map +1 -1
  63. package/dist/os/compass/handlers/compass-invariants-generate.d.ts +15 -0
  64. package/dist/os/compass/handlers/compass-invariants-generate.d.ts.map +1 -0
  65. package/dist/os/compass/handlers/compass-invariants-generate.js +208 -0
  66. package/dist/os/compass/handlers/compass-invariants-generate.js.map +1 -0
  67. package/dist/os/compass/handlers/compass-inventory-handler.d.ts.map +1 -1
  68. package/dist/os/compass/handlers/compass-inventory-handler.js +46 -4
  69. package/dist/os/compass/handlers/compass-inventory-handler.js.map +1 -1
  70. package/dist/os/compass/handlers/invariant-bindings.d.ts +85 -0
  71. package/dist/os/compass/handlers/invariant-bindings.d.ts.map +1 -0
  72. package/dist/os/compass/handlers/invariant-bindings.js +390 -0
  73. package/dist/os/compass/handlers/invariant-bindings.js.map +1 -0
  74. package/dist/os/conformance/conformance.module.d.ts +3 -0
  75. package/dist/os/conformance/conformance.module.d.ts.map +1 -0
  76. package/dist/os/conformance/conformance.module.js +96 -0
  77. package/dist/os/conformance/conformance.module.js.map +1 -0
  78. package/dist/os/conformance/handlers/conformance-run.d.ts +14 -0
  79. package/dist/os/conformance/handlers/conformance-run.d.ts.map +1 -0
  80. package/dist/os/conformance/handlers/conformance-run.js +149 -0
  81. package/dist/os/conformance/handlers/conformance-run.js.map +1 -0
  82. package/dist/os/conformance/handlers/conformance-validate.d.ts +14 -0
  83. package/dist/os/conformance/handlers/conformance-validate.d.ts.map +1 -0
  84. package/dist/os/conformance/handlers/conformance-validate.js +216 -0
  85. package/dist/os/conformance/handlers/conformance-validate.js.map +1 -0
  86. package/dist/os/conformance/index.d.ts +6 -0
  87. package/dist/os/conformance/index.d.ts.map +1 -0
  88. package/dist/os/conformance/index.js +17 -0
  89. package/dist/os/conformance/index.js.map +1 -0
  90. package/dist/os/context/context.module.d.ts +3 -0
  91. package/dist/os/context/context.module.d.ts.map +1 -0
  92. package/dist/os/context/context.module.js +68 -0
  93. package/dist/os/context/context.module.js.map +1 -0
  94. package/dist/os/context/handlers/context-assemble.d.ts +28 -0
  95. package/dist/os/context/handlers/context-assemble.d.ts.map +1 -0
  96. package/dist/os/context/handlers/context-assemble.js +142 -0
  97. package/dist/os/context/handlers/context-assemble.js.map +1 -0
  98. package/dist/os/context/handlers/context-slate-eval.d.ts +15 -0
  99. package/dist/os/context/handlers/context-slate-eval.d.ts.map +1 -0
  100. package/dist/os/context/handlers/context-slate-eval.js +70 -0
  101. package/dist/os/context/handlers/context-slate-eval.js.map +1 -0
  102. package/dist/os/context/handlers/index-build.d.ts +19 -0
  103. package/dist/os/context/handlers/index-build.d.ts.map +1 -0
  104. package/dist/os/context/handlers/index-build.js +188 -0
  105. package/dist/os/context/handlers/index-build.js.map +1 -0
  106. package/dist/os/context/index.d.ts +5 -0
  107. package/dist/os/context/index.d.ts.map +1 -0
  108. package/dist/os/context/index.js +5 -0
  109. package/dist/os/context/index.js.map +1 -0
  110. package/dist/os/core/core.module.d.ts.map +1 -1
  111. package/dist/os/core/core.module.js +34 -11
  112. package/dist/os/core/core.module.js.map +1 -1
  113. package/dist/os/formal/formal.module.d.ts +3 -0
  114. package/dist/os/formal/formal.module.d.ts.map +1 -0
  115. package/dist/os/formal/formal.module.js +63 -0
  116. package/dist/os/formal/formal.module.js.map +1 -0
  117. package/dist/os/formal/handlers/proof-check.d.ts +10 -0
  118. package/dist/os/formal/handlers/proof-check.d.ts.map +1 -0
  119. package/dist/os/formal/handlers/proof-check.js +82 -0
  120. package/dist/os/formal/handlers/proof-check.js.map +1 -0
  121. package/dist/os/formal/index.d.ts +4 -0
  122. package/dist/os/formal/index.d.ts.map +1 -0
  123. package/dist/os/formal/index.js +16 -0
  124. package/dist/os/formal/index.js.map +1 -0
  125. package/dist/os/friction/friction.module.d.ts +3 -0
  126. package/dist/os/friction/friction.module.d.ts.map +1 -0
  127. package/dist/os/friction/friction.module.js +71 -0
  128. package/dist/os/friction/friction.module.js.map +1 -0
  129. package/dist/os/friction/handlers/friction-validate.d.ts +4 -0
  130. package/dist/os/friction/handlers/friction-validate.d.ts.map +1 -0
  131. package/dist/os/friction/handlers/friction-validate.js +228 -0
  132. package/dist/os/friction/handlers/friction-validate.js.map +1 -0
  133. package/dist/os/friction/index.d.ts +4 -0
  134. package/dist/os/friction/index.d.ts.map +1 -0
  135. package/dist/os/friction/index.js +23 -0
  136. package/dist/os/friction/index.js.map +1 -0
  137. package/dist/os/friction/types.d.ts +97 -0
  138. package/dist/os/friction/types.d.ts.map +1 -0
  139. package/dist/os/friction/types.js +78 -0
  140. package/dist/os/friction/types.js.map +1 -0
  141. package/dist/os/gate/gate.module.d.ts +3 -0
  142. package/dist/os/gate/gate.module.d.ts.map +1 -0
  143. package/dist/os/gate/gate.module.js +65 -0
  144. package/dist/os/gate/gate.module.js.map +1 -0
  145. package/dist/os/gate/handlers/gate-probe-catalog.d.ts +18 -0
  146. package/dist/os/gate/handlers/gate-probe-catalog.d.ts.map +1 -0
  147. package/dist/os/gate/handlers/gate-probe-catalog.js +66 -0
  148. package/dist/os/gate/handlers/gate-probe-catalog.js.map +1 -0
  149. package/dist/os/gate/handlers/gate-probe.d.ts +32 -0
  150. package/dist/os/gate/handlers/gate-probe.d.ts.map +1 -0
  151. package/dist/os/gate/handlers/gate-probe.js +228 -0
  152. package/dist/os/gate/handlers/gate-probe.js.map +1 -0
  153. package/dist/os/gate/index.d.ts +4 -0
  154. package/dist/os/gate/index.d.ts.map +1 -0
  155. package/dist/os/gate/index.js +4 -0
  156. package/dist/os/gate/index.js.map +1 -0
  157. package/dist/os/instructions/handlers/budget-validate.d.ts +29 -0
  158. package/dist/os/instructions/handlers/budget-validate.d.ts.map +1 -0
  159. package/dist/os/instructions/handlers/budget-validate.js +164 -0
  160. package/dist/os/instructions/handlers/budget-validate.js.map +1 -0
  161. package/dist/os/instructions/handlers/scar-migrate.d.ts +13 -0
  162. package/dist/os/instructions/handlers/scar-migrate.d.ts.map +1 -0
  163. package/dist/os/instructions/handlers/scar-migrate.js +270 -0
  164. package/dist/os/instructions/handlers/scar-migrate.js.map +1 -0
  165. package/dist/os/instructions/instructions.module.d.ts +3 -0
  166. package/dist/os/instructions/instructions.module.d.ts.map +1 -0
  167. package/dist/os/instructions/instructions.module.js +74 -0
  168. package/dist/os/instructions/instructions.module.js.map +1 -0
  169. package/dist/os/knowledge/handlers/knowledge-authz-probe.d.ts +16 -0
  170. package/dist/os/knowledge/handlers/knowledge-authz-probe.d.ts.map +1 -0
  171. package/dist/os/knowledge/handlers/knowledge-authz-probe.js +198 -0
  172. package/dist/os/knowledge/handlers/knowledge-authz-probe.js.map +1 -0
  173. package/dist/os/knowledge/handlers/knowledge-rebuild.d.ts +15 -0
  174. package/dist/os/knowledge/handlers/knowledge-rebuild.d.ts.map +1 -0
  175. package/dist/os/knowledge/handlers/knowledge-rebuild.js +137 -0
  176. package/dist/os/knowledge/handlers/knowledge-rebuild.js.map +1 -0
  177. package/dist/os/knowledge/index.d.ts +4 -0
  178. package/dist/os/knowledge/index.d.ts.map +1 -0
  179. package/dist/os/knowledge/index.js +4 -0
  180. package/dist/os/knowledge/index.js.map +1 -0
  181. package/dist/os/knowledge/knowledge.module.d.ts +3 -0
  182. package/dist/os/knowledge/knowledge.module.d.ts.map +1 -0
  183. package/dist/os/knowledge/knowledge.module.js +61 -0
  184. package/dist/os/knowledge/knowledge.module.js.map +1 -0
  185. package/dist/os/mission/handlers/archive.d.ts.map +1 -1
  186. package/dist/os/mission/handlers/archive.js +102 -6
  187. package/dist/os/mission/handlers/archive.js.map +1 -1
  188. package/dist/os/mission/mission.module.d.ts.map +1 -1
  189. package/dist/os/mission/mission.module.js +7 -0
  190. package/dist/os/mission/mission.module.js.map +1 -1
  191. package/dist/os/naming/naming-convention.d.ts.map +1 -1
  192. package/dist/os/naming/naming-convention.js +2 -1
  193. package/dist/os/naming/naming-convention.js.map +1 -1
  194. package/dist/os/program/schemas.d.ts +5 -5
  195. package/dist/os/queue/handlers/queue-validate.d.ts.map +1 -1
  196. package/dist/os/queue/handlers/queue-validate.js +129 -5
  197. package/dist/os/queue/handlers/queue-validate.js.map +1 -1
  198. package/dist/os/queue/queue.module.d.ts.map +1 -1
  199. package/dist/os/queue/queue.module.js +12 -31
  200. package/dist/os/queue/queue.module.js.map +1 -1
  201. package/dist/os/queue/types.d.ts +23 -0
  202. package/dist/os/queue/types.d.ts.map +1 -1
  203. package/dist/os/queue/types.js +24 -3
  204. package/dist/os/queue/types.js.map +1 -1
  205. package/dist/os/resolver/handlers/resolver-doors-audit.d.ts +22 -0
  206. package/dist/os/resolver/handlers/resolver-doors-audit.d.ts.map +1 -0
  207. package/dist/os/resolver/handlers/resolver-doors-audit.js +238 -0
  208. package/dist/os/resolver/handlers/resolver-doors-audit.js.map +1 -0
  209. package/dist/os/resolver/resolver.module.d.ts +3 -0
  210. package/dist/os/resolver/resolver.module.d.ts.map +1 -0
  211. package/dist/os/resolver/resolver.module.js +40 -0
  212. package/dist/os/resolver/resolver.module.js.map +1 -0
  213. package/dist/os/rfc/acceptance.d.ts +2 -1
  214. package/dist/os/rfc/acceptance.d.ts.map +1 -1
  215. package/dist/os/rfc/acceptance.js +158 -82
  216. package/dist/os/rfc/acceptance.js.map +1 -1
  217. package/dist/os/rfc/decision-log.d.ts +10 -0
  218. package/dist/os/rfc/decision-log.d.ts.map +1 -1
  219. package/dist/os/rfc/decision-log.js +14 -0
  220. package/dist/os/rfc/decision-log.js.map +1 -1
  221. package/dist/os/rfc/handlers/fixed-inputs.d.ts +29 -0
  222. package/dist/os/rfc/handlers/fixed-inputs.d.ts.map +1 -0
  223. package/dist/os/rfc/handlers/fixed-inputs.js +214 -0
  224. package/dist/os/rfc/handlers/fixed-inputs.js.map +1 -0
  225. package/dist/os/rfc/handlers/implement-stamp-deviations.d.ts +47 -0
  226. package/dist/os/rfc/handlers/implement-stamp-deviations.d.ts.map +1 -0
  227. package/dist/os/rfc/handlers/implement-stamp-deviations.js +145 -0
  228. package/dist/os/rfc/handlers/implement-stamp-deviations.js.map +1 -0
  229. package/dist/os/rfc/handlers/implement-stamp-origin.d.ts +15 -1
  230. package/dist/os/rfc/handlers/implement-stamp-origin.d.ts.map +1 -1
  231. package/dist/os/rfc/handlers/implement-stamp-origin.js +57 -5
  232. package/dist/os/rfc/handlers/implement-stamp-origin.js.map +1 -1
  233. package/dist/os/rfc/handlers/implement-stamp-outcome.d.ts +42 -0
  234. package/dist/os/rfc/handlers/implement-stamp-outcome.d.ts.map +1 -0
  235. package/dist/os/rfc/handlers/implement-stamp-outcome.js +102 -0
  236. package/dist/os/rfc/handlers/implement-stamp-outcome.js.map +1 -0
  237. package/dist/os/rfc/handlers/implement-stamp.d.ts.map +1 -1
  238. package/dist/os/rfc/handlers/implement-stamp.js +101 -12
  239. package/dist/os/rfc/handlers/implement-stamp.js.map +1 -1
  240. package/dist/os/rfc/handlers/index-graph.d.ts +4 -2
  241. package/dist/os/rfc/handlers/index-graph.d.ts.map +1 -1
  242. package/dist/os/rfc/handlers/index-graph.js +57 -3
  243. package/dist/os/rfc/handlers/index-graph.js.map +1 -1
  244. package/dist/os/rfc/handlers/list-create.d.ts.map +1 -1
  245. package/dist/os/rfc/handlers/list-create.js +117 -12
  246. package/dist/os/rfc/handlers/list-create.js.map +1 -1
  247. package/dist/os/rfc/handlers/supersede-propose.d.ts.map +1 -1
  248. package/dist/os/rfc/handlers/supersede-propose.js +34 -7
  249. package/dist/os/rfc/handlers/supersede-propose.js.map +1 -1
  250. package/dist/os/rfc/handlers/validate-rules.d.ts +4 -1
  251. package/dist/os/rfc/handlers/validate-rules.d.ts.map +1 -1
  252. package/dist/os/rfc/handlers/validate-rules.js +159 -11
  253. package/dist/os/rfc/handlers/validate-rules.js.map +1 -1
  254. package/dist/os/rfc/handlers/validate.d.ts.map +1 -1
  255. package/dist/os/rfc/handlers/validate.js +10 -1
  256. package/dist/os/rfc/handlers/validate.js.map +1 -1
  257. package/dist/os/rfc/outcome-probe.d.ts +20 -0
  258. package/dist/os/rfc/outcome-probe.d.ts.map +1 -0
  259. package/dist/os/rfc/outcome-probe.js +315 -0
  260. package/dist/os/rfc/outcome-probe.js.map +1 -0
  261. package/dist/os/rfc/reachable-symbol.d.ts.map +1 -1
  262. package/dist/os/rfc/reachable-symbol.js +51 -12
  263. package/dist/os/rfc/reachable-symbol.js.map +1 -1
  264. package/dist/os/rfc/rfc.module.d.ts.map +1 -1
  265. package/dist/os/rfc/rfc.module.js +48 -11
  266. package/dist/os/rfc/rfc.module.js.map +1 -1
  267. package/dist/os/rfc/types.d.ts +90 -12
  268. package/dist/os/rfc/types.d.ts.map +1 -1
  269. package/dist/os/rfc/types.js +8 -7
  270. package/dist/os/rfc/types.js.map +1 -1
  271. package/dist/os/rfc/verification-evidence.d.ts +4 -1
  272. package/dist/os/rfc/verification-evidence.d.ts.map +1 -1
  273. package/dist/os/rfc/verification-evidence.js +69 -17
  274. package/dist/os/rfc/verification-evidence.js.map +1 -1
  275. package/dist/os/rfc/verification-origin.d.ts +8 -0
  276. package/dist/os/rfc/verification-origin.d.ts.map +1 -1
  277. package/dist/os/rfc/verification-origin.js +48 -1
  278. package/dist/os/rfc/verification-origin.js.map +1 -1
  279. package/dist/os/rfc/verification-refresh.d.ts.map +1 -1
  280. package/dist/os/rfc/verification-refresh.js +19 -2
  281. package/dist/os/rfc/verification-refresh.js.map +1 -1
  282. package/dist/os/rfc/verification-verdicts.d.ts +14 -0
  283. package/dist/os/rfc/verification-verdicts.d.ts.map +1 -0
  284. package/dist/os/rfc/verification-verdicts.js +104 -0
  285. package/dist/os/rfc/verification-verdicts.js.map +1 -0
  286. package/dist/os/rfc/verifier/rfc-1391/support.d.ts +34 -0
  287. package/dist/os/rfc/verifier/rfc-1391/support.d.ts.map +1 -0
  288. package/dist/os/rfc/verifier/rfc-1391/support.js +184 -0
  289. package/dist/os/rfc/verifier/rfc-1391/support.js.map +1 -0
  290. package/dist/os/session/frontmatter-io.d.ts +3 -1
  291. package/dist/os/session/frontmatter-io.d.ts.map +1 -1
  292. package/dist/os/session/frontmatter-io.js +3 -1
  293. package/dist/os/session/frontmatter-io.js.map +1 -1
  294. package/dist/os/session/handlers/session-audit-report.d.ts +20 -0
  295. package/dist/os/session/handlers/session-audit-report.d.ts.map +1 -0
  296. package/dist/os/session/handlers/session-audit-report.js +78 -0
  297. package/dist/os/session/handlers/session-audit-report.js.map +1 -0
  298. package/dist/os/session/handlers/session-audit.d.ts +25 -0
  299. package/dist/os/session/handlers/session-audit.d.ts.map +1 -0
  300. package/dist/os/session/handlers/session-audit.js +265 -0
  301. package/dist/os/session/handlers/session-audit.js.map +1 -0
  302. package/dist/os/session/session.module.d.ts.map +1 -1
  303. package/dist/os/session/session.module.js +49 -2
  304. package/dist/os/session/session.module.js.map +1 -1
  305. package/dist/os/spec/spec-amendments.d.ts +7 -0
  306. package/dist/os/spec/spec-amendments.d.ts.map +1 -0
  307. package/dist/os/spec/spec-amendments.js +86 -0
  308. package/dist/os/spec/spec-amendments.js.map +1 -0
  309. package/dist/os/spec/spec-materialize.d.ts.map +1 -1
  310. package/dist/os/spec/spec-materialize.js +22 -24
  311. package/dist/os/spec/spec-materialize.js.map +1 -1
  312. package/dist/os/spec/spec-status.d.ts.map +1 -1
  313. package/dist/os/spec/spec-status.js +25 -29
  314. package/dist/os/spec/spec-status.js.map +1 -1
  315. package/dist/os/spec/spec-validate.d.ts.map +1 -1
  316. package/dist/os/spec/spec-validate.js +9 -29
  317. package/dist/os/spec/spec-validate.js.map +1 -1
  318. package/dist/os/spec/spec.module.d.ts.map +1 -1
  319. package/dist/os/spec/spec.module.js +7 -36
  320. package/dist/os/spec/spec.module.js.map +1 -1
  321. package/dist/os/trajectory/handlers/journal-io.d.ts +51 -0
  322. package/dist/os/trajectory/handlers/journal-io.d.ts.map +1 -0
  323. package/dist/os/trajectory/handlers/journal-io.js +161 -0
  324. package/dist/os/trajectory/handlers/journal-io.js.map +1 -0
  325. package/dist/os/trajectory/handlers/outcome-record.d.ts +16 -0
  326. package/dist/os/trajectory/handlers/outcome-record.d.ts.map +1 -0
  327. package/dist/os/trajectory/handlers/outcome-record.js +142 -0
  328. package/dist/os/trajectory/handlers/outcome-record.js.map +1 -0
  329. package/dist/os/trajectory/handlers/trajectory-index.d.ts +59 -0
  330. package/dist/os/trajectory/handlers/trajectory-index.d.ts.map +1 -0
  331. package/dist/os/trajectory/handlers/trajectory-index.js +427 -0
  332. package/dist/os/trajectory/handlers/trajectory-index.js.map +1 -0
  333. package/dist/os/trajectory/handlers/trajectory-recall.d.ts +21 -0
  334. package/dist/os/trajectory/handlers/trajectory-recall.d.ts.map +1 -0
  335. package/dist/os/trajectory/handlers/trajectory-recall.js +176 -0
  336. package/dist/os/trajectory/handlers/trajectory-recall.js.map +1 -0
  337. package/dist/os/trajectory/index.d.ts +5 -0
  338. package/dist/os/trajectory/index.d.ts.map +1 -0
  339. package/dist/os/trajectory/index.js +5 -0
  340. package/dist/os/trajectory/index.js.map +1 -0
  341. package/dist/os/trajectory/trajectory.module.d.ts +3 -0
  342. package/dist/os/trajectory/trajectory.module.d.ts.map +1 -0
  343. package/dist/os/trajectory/trajectory.module.js +91 -0
  344. package/dist/os/trajectory/trajectory.module.js.map +1 -0
  345. package/dist/os/werkstatt/handlers/session-close.d.ts +13 -0
  346. package/dist/os/werkstatt/handlers/session-close.d.ts.map +1 -0
  347. package/dist/os/werkstatt/handlers/session-close.js +53 -0
  348. package/dist/os/werkstatt/handlers/session-close.js.map +1 -0
  349. package/dist/os/werkstatt/handlers/session-engine.d.ts +3 -0
  350. package/dist/os/werkstatt/handlers/session-engine.d.ts.map +1 -0
  351. package/dist/os/werkstatt/handlers/session-engine.js +25 -0
  352. package/dist/os/werkstatt/handlers/session-engine.js.map +1 -0
  353. package/dist/os/werkstatt/handlers/session-open.d.ts +10 -0
  354. package/dist/os/werkstatt/handlers/session-open.d.ts.map +1 -0
  355. package/dist/os/werkstatt/handlers/session-open.js +43 -0
  356. package/dist/os/werkstatt/handlers/session-open.js.map +1 -0
  357. package/dist/os/werkstatt/handlers/session-status.d.ts +9 -0
  358. package/dist/os/werkstatt/handlers/session-status.d.ts.map +1 -0
  359. package/dist/os/werkstatt/handlers/session-status.js +31 -0
  360. package/dist/os/werkstatt/handlers/session-status.js.map +1 -0
  361. package/dist/os/werkstatt/werkstatt.module.d.ts.map +1 -1
  362. package/dist/os/werkstatt/werkstatt.module.js +98 -3
  363. package/dist/os/werkstatt/werkstatt.module.js.map +1 -1
  364. package/dist/src/authority/delegations.d.ts +1 -1
  365. package/dist/src/authority/delegations.d.ts.map +1 -1
  366. package/dist/src/authority/delegations.js +2 -0
  367. package/dist/src/authority/delegations.js.map +1 -1
  368. package/dist/src/cli-flags.d.ts.map +1 -1
  369. package/dist/src/cli-flags.js +90 -11
  370. package/dist/src/cli-flags.js.map +1 -1
  371. package/dist/src/compass/index.d.ts +2 -0
  372. package/dist/src/compass/index.d.ts.map +1 -0
  373. package/dist/src/compass/index.js +26 -0
  374. package/dist/src/compass/index.js.map +1 -0
  375. package/dist/src/compass/invariant-parser.d.ts +37 -0
  376. package/dist/src/compass/invariant-parser.d.ts.map +1 -0
  377. package/dist/src/compass/invariant-parser.js +218 -0
  378. package/dist/src/compass/invariant-parser.js.map +1 -0
  379. package/dist/src/config/forge-config.d.ts +108 -0
  380. package/dist/src/config/forge-config.d.ts.map +1 -1
  381. package/dist/src/config/forge-config.js +79 -9
  382. package/dist/src/config/forge-config.js.map +1 -1
  383. package/dist/src/conformance/index.d.ts +42 -0
  384. package/dist/src/conformance/index.d.ts.map +1 -0
  385. package/dist/src/conformance/index.js +193 -0
  386. package/dist/src/conformance/index.js.map +1 -0
  387. package/dist/src/formal/exhaustive.d.ts +40 -0
  388. package/dist/src/formal/exhaustive.d.ts.map +1 -0
  389. package/dist/src/formal/exhaustive.js +140 -0
  390. package/dist/src/formal/exhaustive.js.map +1 -0
  391. package/dist/src/formal/index.d.ts +7 -0
  392. package/dist/src/formal/index.d.ts.map +1 -0
  393. package/dist/src/formal/index.js +13 -0
  394. package/dist/src/formal/index.js.map +1 -0
  395. package/dist/src/formal/proof-runner.d.ts +51 -0
  396. package/dist/src/formal/proof-runner.d.ts.map +1 -0
  397. package/dist/src/formal/proof-runner.js +450 -0
  398. package/dist/src/formal/proof-runner.js.map +1 -0
  399. package/dist/src/formal/proof-spec.d.ts +69 -0
  400. package/dist/src/formal/proof-spec.d.ts.map +1 -0
  401. package/dist/src/formal/proof-spec.js +96 -0
  402. package/dist/src/formal/proof-spec.js.map +1 -0
  403. package/dist/src/knowledge/schema.d.ts +8 -0
  404. package/dist/src/knowledge/schema.d.ts.map +1 -1
  405. package/dist/src/knowledge/schema.js +5 -0
  406. package/dist/src/knowledge/schema.js.map +1 -1
  407. package/dist/src/knowledge/serialize.d.ts.map +1 -1
  408. package/dist/src/knowledge/serialize.js +3 -0
  409. package/dist/src/knowledge/serialize.js.map +1 -1
  410. package/dist/src/onboarding/agents-generate.d.ts.map +1 -1
  411. package/dist/src/onboarding/agents-generate.js +17 -2
  412. package/dist/src/onboarding/agents-generate.js.map +1 -1
  413. package/dist/src/onboarding/doctor.d.ts.map +1 -1
  414. package/dist/src/onboarding/doctor.js +87 -1
  415. package/dist/src/onboarding/doctor.js.map +1 -1
  416. package/dist/src/onboarding/init.js +3 -3
  417. package/dist/src/onboarding/init.js.map +1 -1
  418. package/dist/src/profiles/profile-schema.d.ts +8 -0
  419. package/dist/src/profiles/profile-schema.d.ts.map +1 -1
  420. package/dist/src/profiles/profile-schema.js +10 -2
  421. package/dist/src/profiles/profile-schema.js.map +1 -1
  422. package/dist/src/profiles/stack-profile.d.ts +4 -0
  423. package/dist/src/profiles/stack-profile.d.ts.map +1 -1
  424. package/dist/src/reachability/command-mentions.d.ts +17 -0
  425. package/dist/src/reachability/command-mentions.d.ts.map +1 -0
  426. package/dist/src/reachability/command-mentions.js +81 -0
  427. package/dist/src/reachability/command-mentions.js.map +1 -0
  428. package/dist/src/registry.d.ts +10 -0
  429. package/dist/src/registry.d.ts.map +1 -1
  430. package/dist/src/registry.js +40 -2
  431. package/dist/src/registry.js.map +1 -1
  432. package/dist/src/types.d.ts +51 -3
  433. package/dist/src/types.d.ts.map +1 -1
  434. package/dist/src/types.js +11 -14
  435. package/dist/src/types.js.map +1 -1
  436. package/dist/src/utils/sync-fs.d.ts +1 -1
  437. package/dist/src/utils/sync-fs.d.ts.map +1 -1
  438. package/dist/src/utils/sync-fs.js +2 -1
  439. package/dist/src/utils/sync-fs.js.map +1 -1
  440. package/docs/reference/forge-yaml.md +20 -0
  441. package/os/adr/handlers/implement-stamp.ts +2 -0
  442. package/os/adr/types.ts +2 -0
  443. package/os/agent/agent.module.ts +64 -0
  444. package/os/agent/handlers/agent-delegate.ts +227 -0
  445. package/os/agent/handlers/agent-tiers-validate.ts +228 -0
  446. package/os/agent/index.ts +14 -0
  447. package/os/agent/invoke-adapter.ts +119 -0
  448. package/os/authority/authority.module.ts +2 -10
  449. package/os/checks/checks.module.ts +95 -0
  450. package/os/checks/handlers/contribution-report.test.ts +244 -0
  451. package/os/checks/handlers/contribution-report.ts +316 -0
  452. package/os/checks/handlers/counters-export.test.ts +175 -0
  453. package/os/checks/handlers/counters-export.ts +170 -0
  454. package/os/checks/handlers/counters-journal.test.ts +187 -0
  455. package/os/checks/handlers/counters-journal.ts +179 -0
  456. package/os/checks/handlers/counters-validate.test.ts +176 -0
  457. package/os/checks/handlers/counters-validate.ts +159 -0
  458. package/os/checks/handlers/variant-candidates.test.ts +65 -0
  459. package/os/checks/index.ts +15 -0
  460. package/os/compass/compass.module.ts +58 -20
  461. package/os/compass/handlers/compass-header-scaffold.ts +4 -2
  462. package/os/compass/handlers/compass-invariants-generate.ts +293 -0
  463. package/os/compass/handlers/compass-inventory-handler.ts +59 -4
  464. package/os/compass/handlers/invariant-bindings.ts +526 -0
  465. package/os/compass/handlers/tests/compass-invariant-binding.test.ts +500 -0
  466. package/os/compass/handlers/tests/compass-invariants-generate.test.ts +235 -0
  467. package/os/compass/handlers/tests/compass-migrate.test.ts +5 -3
  468. package/os/conformance/conformance.module.ts +105 -0
  469. package/os/conformance/handlers/conformance-run.ts +175 -0
  470. package/os/conformance/handlers/conformance-validate.ts +334 -0
  471. package/os/conformance/handlers/tests/conformance.test.ts +657 -0
  472. package/os/conformance/index.ts +19 -0
  473. package/os/context/context.module.ts +73 -0
  474. package/os/context/handlers/context-assemble.test.ts +89 -0
  475. package/os/context/handlers/context-assemble.ts +171 -0
  476. package/os/context/handlers/context-slate-eval.test.ts +64 -0
  477. package/os/context/handlers/context-slate-eval.ts +86 -0
  478. package/os/context/handlers/index-build.test.ts +68 -0
  479. package/os/context/handlers/index-build.ts +211 -0
  480. package/os/context/handlers/no-model-deps.test.ts +32 -0
  481. package/os/context/handlers/slate-fill.test.ts +31 -0
  482. package/os/context/index.ts +4 -0
  483. package/os/core/core.module.ts +34 -11
  484. package/os/formal/formal.module.ts +67 -0
  485. package/os/formal/handlers/proof-check.test.ts +337 -0
  486. package/os/formal/handlers/proof-check.ts +100 -0
  487. package/os/formal/index.ts +17 -0
  488. package/os/friction/friction-validate.test.ts +442 -0
  489. package/os/friction/friction.module.ts +74 -0
  490. package/os/friction/handlers/friction-validate.ts +349 -0
  491. package/os/friction/index.ts +30 -0
  492. package/os/friction/types.ts +113 -0
  493. package/os/gate/gate.module.ts +69 -0
  494. package/os/gate/handlers/gate-probe-catalog.test.ts +76 -0
  495. package/os/gate/handlers/gate-probe-catalog.ts +85 -0
  496. package/os/gate/handlers/gate-probe.test.ts +108 -0
  497. package/os/gate/handlers/gate-probe.ts +252 -0
  498. package/os/gate/index.ts +3 -0
  499. package/os/instructions/budget.test.ts +125 -0
  500. package/os/instructions/handlers/budget-validate.ts +197 -0
  501. package/os/instructions/handlers/scar-migrate.ts +292 -0
  502. package/os/instructions/instructions.module.ts +78 -0
  503. package/os/knowledge/handlers/knowledge-authz-probe.test.ts +86 -0
  504. package/os/knowledge/handlers/knowledge-authz-probe.ts +236 -0
  505. package/os/knowledge/handlers/knowledge-rebuild.test.ts +76 -0
  506. package/os/knowledge/handlers/knowledge-rebuild.ts +163 -0
  507. package/os/knowledge/index.ts +3 -0
  508. package/os/knowledge/knowledge.module.ts +65 -0
  509. package/os/mission/handlers/archive.ts +113 -6
  510. package/os/mission/handlers/ship-inflight-degraded.test.ts +105 -0
  511. package/os/mission/mission.module.ts +8 -0
  512. package/os/naming/naming-convention.ts +2 -1
  513. package/os/queue/decision-ledger.test.ts +39 -0
  514. package/os/queue/handlers/queue-validate.ts +132 -5
  515. package/os/queue/queue-validate.test.ts +194 -0
  516. package/os/queue/queue.module.ts +12 -31
  517. package/os/queue/types.ts +26 -3
  518. package/os/resolver/handlers/resolver-doors-audit.test.ts +147 -0
  519. package/os/resolver/handlers/resolver-doors-audit.ts +281 -0
  520. package/os/resolver/resolver.module.ts +43 -0
  521. package/os/rfc/acceptance-reachable.test.ts +78 -0
  522. package/os/rfc/acceptance.test.ts +229 -1
  523. package/os/rfc/acceptance.ts +141 -45
  524. package/os/rfc/decision-log.ts +15 -0
  525. package/os/rfc/handlers/fixed-inputs.ts +252 -0
  526. package/os/rfc/handlers/implement-stamp-deviations.test.ts +140 -0
  527. package/os/rfc/handlers/implement-stamp-deviations.ts +183 -0
  528. package/os/rfc/handlers/implement-stamp-formal.test.ts +168 -0
  529. package/os/rfc/handlers/implement-stamp-origin.ts +87 -11
  530. package/os/rfc/handlers/implement-stamp-outcome.test.ts +193 -0
  531. package/os/rfc/handlers/implement-stamp-outcome.ts +146 -0
  532. package/os/rfc/handlers/implement-stamp.ts +107 -10
  533. package/os/rfc/handlers/index-graph.ts +66 -4
  534. package/os/rfc/handlers/list-create.test.ts +142 -0
  535. package/os/rfc/handlers/list-create.ts +140 -12
  536. package/os/rfc/handlers/supersede-propose.ts +50 -7
  537. package/os/rfc/handlers/tests/index-graph.test.ts +165 -0
  538. package/os/rfc/handlers/validate-rules-rfc1453.test.ts +163 -0
  539. package/os/rfc/handlers/validate-rules-rfc1454.test.ts +136 -0
  540. package/os/rfc/handlers/validate-rules-rfc1455.test.ts +282 -0
  541. package/os/rfc/handlers/validate-rules.test.ts +129 -2
  542. package/os/rfc/handlers/validate-rules.ts +233 -9
  543. package/os/rfc/handlers/validate.ts +11 -0
  544. package/os/rfc/outcome-probe.ts +326 -0
  545. package/os/rfc/reachable-symbol.ts +64 -16
  546. package/os/rfc/rfc-0000-template.md +4 -0
  547. package/os/rfc/rfc.module.ts +51 -11
  548. package/os/rfc/types.ts +109 -14
  549. package/os/rfc/verification-evidence.ts +74 -14
  550. package/os/rfc/verification-origin.ts +61 -1
  551. package/os/rfc/verification-refresh.test.ts +63 -0
  552. package/os/rfc/verification-refresh.ts +24 -2
  553. package/os/rfc/verification-verdicts.ts +123 -0
  554. package/os/rfc/verifier/rfc-1391/ac1-proved-exit-0.acceptance.test.ts +151 -0
  555. package/os/rfc/verifier/rfc-1391/ac2-unavailable-nonzero.acceptance.test.ts +111 -0
  556. package/os/rfc/verifier/rfc-1391/ac3-version-mismatch-error.acceptance.test.ts +97 -0
  557. package/os/rfc/verifier/rfc-1391/ac4-cardinality-mismatch-error.acceptance.test.ts +179 -0
  558. package/os/rfc/verifier/rfc-1391/ac5-imp13-formal-stamp-block.acceptance.test.ts +295 -0
  559. package/os/rfc/verifier/rfc-1391/ac6-formal-high-tier-gates.acceptance.test.ts +203 -0
  560. package/os/rfc/verifier/rfc-1391/ac7-v46-empty-assumptions.acceptance.test.ts +126 -0
  561. package/os/rfc/verifier/rfc-1391/cx1-emit-proof-envelope.acceptance.test.ts +130 -0
  562. package/os/rfc/verifier/rfc-1391/fixtures/no-report.proof.test.ts +35 -0
  563. package/os/rfc/verifier/rfc-1391/fixtures/small-domain.proof.test.ts +41 -0
  564. package/os/rfc/verifier/rfc-1391/origin-proof-spec-entry.acceptance.test.ts +175 -0
  565. package/os/rfc/verifier/rfc-1391/support.ts +205 -0
  566. package/os/session/fixtures/audit/clean.md +7 -0
  567. package/os/session/fixtures/audit/denied-retry.md +10 -0
  568. package/os/session/frontmatter-io.ts +3 -1
  569. package/os/session/handlers/session-audit-detectors.test.ts +91 -0
  570. package/os/session/handlers/session-audit-report.test.ts +64 -0
  571. package/os/session/handlers/session-audit-report.ts +93 -0
  572. package/os/session/handlers/session-audit.test.ts +80 -0
  573. package/os/session/handlers/session-audit.ts +317 -0
  574. package/os/session/session.module.ts +51 -2
  575. package/os/spec/spec-amendments.ts +91 -0
  576. package/os/spec/spec-materialize.ts +20 -22
  577. package/os/spec/spec-status.test.ts +17 -1
  578. package/os/spec/spec-status.ts +23 -29
  579. package/os/spec/spec-validate.test.ts +45 -0
  580. package/os/spec/spec-validate.ts +9 -29
  581. package/os/spec/spec.module.ts +7 -36
  582. package/os/trajectory/handlers/extract-units.test.ts +69 -0
  583. package/os/trajectory/handlers/journal-io.ts +211 -0
  584. package/os/trajectory/handlers/outcome-record.test.ts +192 -0
  585. package/os/trajectory/handlers/outcome-record.ts +162 -0
  586. package/os/trajectory/handlers/producer-trust.test.ts +163 -0
  587. package/os/trajectory/handlers/trajectory-index.test.ts +246 -0
  588. package/os/trajectory/handlers/trajectory-index.ts +470 -0
  589. package/os/trajectory/handlers/trajectory-recall.test.ts +227 -0
  590. package/os/trajectory/handlers/trajectory-recall.ts +198 -0
  591. package/os/trajectory/handlers/trajectory.test.ts +94 -0
  592. package/os/trajectory/handlers/verdict-binding.test.ts +209 -0
  593. package/os/trajectory/index.ts +4 -0
  594. package/os/trajectory/trajectory.module.ts +96 -0
  595. package/os/werkstatt/handlers/session-close.ts +79 -0
  596. package/os/werkstatt/handlers/session-engine.ts +31 -0
  597. package/os/werkstatt/handlers/session-open.ts +65 -0
  598. package/os/werkstatt/handlers/session-status.ts +52 -0
  599. package/os/werkstatt/werkstatt.module.ts +101 -3
  600. package/package.json +194 -1
  601. package/profiles/forge-shell.yaml +3 -1
  602. package/profiles/godot-game.yaml +3 -1
  603. package/profiles/knowledge.yaml +3 -1
  604. package/profiles/phaser-game.yaml +3 -1
  605. package/profiles/site-workshop.yaml +3 -1
  606. package/profiles/typescript.yaml +3 -1
  607. package/skills/_shared/agent-operating-model.md +1 -1
  608. package/skills/_shared/fo-pipeline-conventions.md +5 -1
  609. package/skills/fo/fo-add-tests/SKILL.md +9 -1
  610. package/skills/fo/fo-add-tests/pbt-guide.md +1 -0
  611. package/skills/fo/fo-compass-annotate/SKILL.md +18 -0
  612. package/skills/fo/fo-compass-annotate/templates/header-format.md +3 -2
  613. package/skills/fo/fo-fix/SKILL.md +14 -8
  614. package/skills/fo/fo-idea-create-adr/SKILL.md +5 -3
  615. package/skills/fo/fo-idea-create-rfc/SKILL.md +20 -8
  616. package/skills/fo/fo-idea-create-rfc/acceptance-criteria-standard.md +20 -0
  617. package/skills/fo/fo-idea-i-just-want-to-see-the-result/SKILL.md +31 -13
  618. package/skills/fo/fo-idea-implement/SKILL.md +20 -14
  619. package/skills/fo/fo-idea-plan/SKILL.md +1 -1
  620. package/skills/fo/fo-knowledge-distill/SKILL.md +7 -0
  621. package/skills/fo/fo-memory-sync/SKILL.md +6 -0
  622. package/skills/fo/fo-reproduce/SKILL.md +116 -0
  623. package/skills/fo/fo-review/SKILL.md +11 -5
  624. package/skills/fo/fo-session-retro/SKILL.md +134 -49
  625. package/skills/fo/fo-step-commit/SKILL.md +4 -3
  626. package/skills/fo/fo-triage/SKILL.md +9 -0
  627. package/skills/shared/grilling/SKILL.md +4 -0
  628. package/skills/shared/grilling/learned-principles.md +7 -0
  629. package/skills/shared/grilling/qa-log.md +39 -0
  630. package/src/authority/delegations.ts +2 -0
  631. package/src/cli-flags.ts +110 -11
  632. package/src/compass/index.ts +37 -0
  633. package/src/compass/invariant-parser.ts +253 -0
  634. package/src/config/forge-config.ts +111 -9
  635. package/src/conformance/index.ts +281 -0
  636. package/src/formal/exhaustive.test.ts +117 -0
  637. package/src/formal/exhaustive.ts +182 -0
  638. package/src/formal/index.ts +23 -0
  639. package/src/formal/proof-runner.test.ts +310 -0
  640. package/src/formal/proof-runner.ts +562 -0
  641. package/src/formal/proof-spec.test.ts +70 -0
  642. package/src/formal/proof-spec.ts +131 -0
  643. package/src/knowledge/schema.ts +9 -0
  644. package/src/knowledge/serialize.ts +3 -0
  645. package/src/onboarding/agents-generate.ts +18 -2
  646. package/src/onboarding/doctor.ts +93 -1
  647. package/src/onboarding/init.ts +3 -3
  648. package/src/onboarding/templates/behavioral-layer-core.md +1 -1
  649. package/src/profiles/profile-schema.ts +10 -2
  650. package/src/reachability/command-mentions.ts +87 -0
  651. package/src/registry.ts +44 -2
  652. package/src/tests/bindings-schema.test.ts +4 -0
  653. package/src/tests/cli-flags.test.ts +225 -0
  654. package/src/tests/fixtures/agents-generate-business-before.txt +4 -2
  655. package/src/tests/forge-config.test.ts +5 -2
  656. package/src/tests/implement-stamp.test.ts +51 -0
  657. package/src/tests/rfc-verification-verdict-ingest.test.ts +244 -0
  658. package/src/tests/session-retro.test.ts +47 -0
  659. package/src/types.ts +59 -18
  660. package/src/utils/sync-fs.ts +2 -0
@@ -0,0 +1,316 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>
4
+ RFC-1473/1474: checks.contribution.report — per-rule marginal-contribution
5
+ read-model. Joins the validator inventory (rule universe, contracts[].contract)
6
+ + the counters journal docs/.index/checks/counters.jsonl as the PRIMARY firing
7
+ surface (one record per evaluated rule; emitted/zeroStreak/lastFiredAt derive
8
+ from it; coverage none|partial|complete vs the --window run count; CONTRIB-03
9
+ warns on absent/empty journal, effectiveCoverage = fired ids ∩ inventory ids) +
10
+ session audit sidecars as SECONDARY diagnostic-signature history
11
+ (uniqueEmitted/firedOn/variantCandidates) + frictions (escapes by forge.yaml
12
+ checksContribution.contractMappings). uniqueEmitted = signatures seen under no
13
+ sibling rule (cross-rule dedup — redundant is reachable). verdict:
14
+ earning|silent|redundant|guard (guard declared via checksContribution.guardRules).
15
+ --check diffs the computed artifact vs the committed file (freshness gate,
16
+ producer-tail tolerated).
17
+ </purpose>
18
+ </MODULE_CONTRACT>
19
+ <CHANGE_SUMMARY>
20
+ <item>RFC-1474: per-rule check-execution counters
21
+
22
+ Append-only counters.jsonl journaled per evaluated rule ({runId, ruleId, contract, outcome, at}; runId = commandInvocationId; outcomes pass|diagnostic|skipped|ensured; dry-run suppressed; append failures warn never fail). checks.counters.validate audits the journal against the validator inventory (COUNT-01/02); checks.counters.export projects deterministic per-rule totals (COUNT-03, generatedAt = max journal at; producer-tail tolerated). checks.contribution.report joins counters as the canonical firing source (CONTRIB-03 on absent/empty journal; coverage none|partial|complete; live effectiveCoverage positive). Validator inventory now includes every rules[]-declaring command — fail-closed gate surfaced 9 contract-declaration defects, fixed with domain contracts.</item>
23
+ <item>RFC-1474: check-execution counters — apply review findings (F-1..F-9)</item>
24
+ <item>RFC-1474: check-execution counters — apply re-review findings (structural skip flag, violations extraction, Date.parse ordering, DEV-5/6)</item>
25
+ <item>RFC-1474: check-execution counters — close emission-shape extraction class (round-3 review)</item>
26
+ <item>RFC-1474: check-execution counters — null-doc inventory fail-closed + token boundaries (round-4 review)</item>
27
+ <history>RFC-1473</history>
28
+ </CHANGE_SUMMARY>
29
+ */
30
+
31
+ import path from "node:path";
32
+ import { parse as yamlParse, stringify as yamlStringify } from "yaml";
33
+ import { ambientIo, resolveIo } from "../../../src/utils/io.ts";
34
+ import type {
35
+ Diagnostic,
36
+ ForgeCommandInput,
37
+ ForgeCommandResult,
38
+ ForgeRuntimeContext,
39
+ } from "../../../src/types.ts";
40
+ import {
41
+ readCountersJournal,
42
+ recordsCoveredByArtifact,
43
+ type CheckCounterRecord,
44
+ } from "./counters-journal.ts";
45
+
46
+ export interface ContributionRecord {
47
+ ruleId: string;
48
+ contract: string;
49
+ emitted: number;
50
+ evaluated: number;
51
+ lastFiredAt: string;
52
+ uniqueEmitted: number;
53
+ zeroStreak: number;
54
+ escapeCount: number | null;
55
+ verdict: "earning" | "silent" | "redundant" | "guard";
56
+ action?: "probe" | "scope" | "retire-rfc" | "keep";
57
+ }
58
+
59
+ export interface VariantCandidate {
60
+ rule: string;
61
+ firedOn: string[];
62
+ siblingScope: string;
63
+ }
64
+
65
+ export interface ContributionData {
66
+ command: "checks.contribution.report";
67
+ status: "ok";
68
+ window: { runs: number; coverage: "none" | "partial" | "complete"; effective: number; observable: number };
69
+ rules: ContributionRecord[];
70
+ variantCandidates: VariantCandidate[];
71
+ ungovernedContracts: string[];
72
+ metrics: string;
73
+ diagnostics?: Diagnostic[];
74
+ }
75
+
76
+
77
+ interface FiredRule { uniqueSignatures: Set<string>; sessions: number; firedOn: Set<string> }
78
+ interface CounterStats { emitted: number; evaluated: number; lastFiredAt: string; lastDiagRunIdx: number; evalRunIdxs: Set<number> }
79
+
80
+ export async function runContributionReport(
81
+ input: ForgeCommandInput,
82
+ context: ForgeRuntimeContext,
83
+ ): Promise<ForgeCommandResult<ContributionData>> {
84
+ const io = resolveIo(context.io ?? ambientIo);
85
+ const root = context.workspaceRoot;
86
+ const contractFilter = input.flags["contract"] as string | undefined;
87
+ const windowN = Math.max(1, Number(input.flags["window"] ?? 20) || 20);
88
+ const check = input.flags["check"] === true;
89
+
90
+ // CONTRIB-01: the rule universe must exist — a missing inventory is a
91
+ // blocking input, not a silent empty report. Only ENOENT means "absent" —
92
+ // other read failures surface as real I/O errors.
93
+ const invPath = path.join(root, "docs", "validator-inventory.generated.yaml");
94
+ const invSrc = await io.readFile(invPath).catch((error: unknown) => {
95
+ if ((error as NodeJS.ErrnoException).code === "ENOENT") return null;
96
+ throw error;
97
+ });
98
+ if (invSrc === null) {
99
+ return {
100
+ data: { command: "checks.contribution.report", status: "ok", window: { runs: 0, coverage: "none", effective: 0, observable: 0 }, rules: [], variantCandidates: [], ungovernedContracts: [], metrics: "" },
101
+ summary: "CONTRIB-01 docs/validator-inventory.generated.yaml missing — rule universe unavailable",
102
+ exitCode: 1,
103
+ };
104
+ }
105
+ const parsed = (() => {
106
+ try {
107
+ return yamlParse(invSrc) as {
108
+ contracts?: { contract?: string; validators?: { rules?: { id?: string; severity?: string }[] }[] }[];
109
+ } | null;
110
+ } catch {
111
+ return undefined;
112
+ }
113
+ })();
114
+ // undefined = unparseable, null = empty document — both unavailable universes.
115
+ if (parsed == null) {
116
+ return {
117
+ data: { command: "checks.contribution.report", status: "ok", window: { runs: 0, coverage: "none", effective: 0, observable: 0 }, rules: [], variantCandidates: [], ungovernedContracts: [], metrics: "" },
118
+ summary: `CONTRIB-01 docs/validator-inventory.generated.yaml ${parsed === undefined ? "malformed — rule universe unparseable" : "empty — no contracts declared"}`,
119
+ exitCode: 1,
120
+ };
121
+ }
122
+ const inventoryContracts = (parsed?.contracts ?? []).map((c) => c.contract ?? "?");
123
+ if (contractFilter && !inventoryContracts.includes(contractFilter)) {
124
+ return {
125
+ data: { command: "checks.contribution.report", status: "ok", window: { runs: 0, coverage: "none", effective: 0, observable: 0 }, rules: [], variantCandidates: [], ungovernedContracts: [], metrics: "" },
126
+ summary: `CONTRIB-01 unknown --contract "${contractFilter}" (declared: ${inventoryContracts.join(", ")})`,
127
+ exitCode: 1,
128
+ };
129
+ }
130
+ const rules = (parsed?.contracts ?? []).flatMap((c) =>
131
+ (c.validators ?? []).flatMap((v) =>
132
+ (v.rules ?? []).filter((r) => r.id && (!contractFilter || c.contract === contractFilter)).map((r) => ({ id: r.id!, contract: c.contract ?? "?" })),
133
+ ),
134
+ );
135
+ // Counters ruleIds carry the namespaced `<contract>/<id>` form — the join key.
136
+ const inventoryJoinIds = new Set(rules.map((r) => `${r.contract}/${r.id}`));
137
+
138
+ // RFC-1474: the counters journal is the PRIMARY firing source — one record
139
+ // per evaluated rule per run. The window is the last `windowN` distinct
140
+ // runIds ordered by each run's first `at`.
141
+ const { records: counterRecords } = await readCountersJournal(root);
142
+ const computeWindowStats = (source: readonly CheckCounterRecord[]) => {
143
+ const runFirstAt = new Map<string, number>();
144
+ for (const r of source) {
145
+ const atMs = Date.parse(r.at);
146
+ const cur = runFirstAt.get(r.runId);
147
+ if (cur === undefined || atMs < cur) runFirstAt.set(r.runId, atMs);
148
+ }
149
+ const orderedRuns = [...runFirstAt.keys()].sort(
150
+ (a, b) => runFirstAt.get(a)! - runFirstAt.get(b)!,
151
+ );
152
+ const windowRunIds = orderedRuns.slice(-windowN);
153
+ const windowRunSet = new Set(windowRunIds);
154
+ const runIndex = new Map(windowRunIds.map((id, i) => [id, i]));
155
+ const windowRecords = source.filter((r) => windowRunSet.has(r.runId));
156
+
157
+ const stats = new Map<string, CounterStats>();
158
+ let to = "";
159
+ let toMs = Number.NEGATIVE_INFINITY;
160
+ for (const r of windowRecords) {
161
+ const atMs = Date.parse(r.at);
162
+ if (atMs > toMs) {
163
+ toMs = atMs;
164
+ to = r.at;
165
+ }
166
+ const s = stats.get(r.ruleId) ?? { emitted: 0, evaluated: 0, lastFiredAt: "", lastDiagRunIdx: -1, evalRunIdxs: new Set<number>() };
167
+ if (r.outcome !== "skipped") {
168
+ s.evaluated++;
169
+ s.evalRunIdxs.add(runIndex.get(r.runId) ?? -1);
170
+ }
171
+ if (r.outcome === "diagnostic") {
172
+ s.emitted++;
173
+ if (s.lastFiredAt === "" || atMs > Date.parse(s.lastFiredAt)) s.lastFiredAt = r.at;
174
+ s.lastDiagRunIdx = Math.max(s.lastDiagRunIdx, runIndex.get(r.runId) ?? -1);
175
+ }
176
+ stats.set(r.ruleId, s);
177
+ }
178
+ const evaluated = [...stats.entries()].filter(([, s]) => s.evaluated > 0).map(([id]) => id);
179
+ const cov: "none" | "partial" | "complete" =
180
+ source.length === 0 ? "none" : orderedRuns.length >= windowN ? "complete" : "partial";
181
+ return { stats, evaluated, coverage: cov, windowTo: to, runCount: windowRunIds.length };
182
+ };
183
+
184
+ // Secondary source (RFC-1474): session audit sidecars keep the diagnostic
185
+ // signature history — uniqueEmitted / firedOn / variantCandidates only.
186
+ const auditDir = path.join(root, "docs", "sessions", "audit");
187
+ const sidecars = (await io.readdir(auditDir).catch(() => [] as { name: string; isDirectory: boolean }[]))
188
+ .filter((e) => !e.isDirectory && e.name.endsWith(".audit.yaml"))
189
+ .map((e) => e.name)
190
+ .sort()
191
+ .slice(-windowN);
192
+
193
+ const fired = new Map<string, FiredRule>();
194
+ const signatureOwners = new Map<string, Set<string>>();
195
+ for (let i = 0; i < sidecars.length; i++) {
196
+ const src = await io.readFile(path.join(auditDir, sidecars[i]!)).catch(() => "");
197
+ const sc = yamlParse(src) as { findings?: { ruleId?: string; signature?: string; evidence?: { file?: string } }[] } | null;
198
+ for (const f of sc?.findings ?? []) {
199
+ if (!f.ruleId) continue;
200
+ const g = fired.get(f.ruleId) ?? { uniqueSignatures: new Set<string>(), sessions: 0, firedOn: new Set<string>() };
201
+ if (f.signature) g.uniqueSignatures.add(f.signature);
202
+ if (f.evidence?.file) g.firedOn.add(f.evidence.file);
203
+ g.sessions++;
204
+ fired.set(f.ruleId, g);
205
+ if (f.signature) {
206
+ const owners = signatureOwners.get(f.signature) ?? new Set<string>();
207
+ owners.add(f.ruleId);
208
+ signatureOwners.set(f.signature, owners);
209
+ }
210
+ }
211
+ }
212
+
213
+ // Escape mapping — forge.yaml checksContribution: maps friction contracts/
214
+ // categories to the contract whose rules should have caught them.
215
+ const forgeYaml = await io.readFile(path.join(root, "forge.yaml")).catch(() => "");
216
+ const cc = (yamlParse(forgeYaml) as { checksContribution?: { contractMappings?: Record<string, string>; guardRules?: string[] } } | null)?.checksContribution ?? {};
217
+ const contractMappings = cc.contractMappings ?? {};
218
+ const guardRules = new Set(cc.guardRules ?? []);
219
+ const frictionsSrc = await io.readFile(path.join(root, "docs", "frictions.yaml")).catch(() => "");
220
+ // frictions.yaml is a bare top-level sequence (- id: F-NNNN), not a {frictions:[]} map.
221
+ const frParsed = yamlParse(frictionsSrc) as unknown;
222
+ const frictions: { id?: string; category?: string; contract?: string; tags?: string[] }[] = Array.isArray(frParsed)
223
+ ? frParsed
224
+ : ((frParsed as { frictions?: typeof frictions } | null)?.frictions ?? []);
225
+ const ungovernedContracts = [...new Set(frictions.map((f) => f.category).filter((c): c is string => !!c))].filter((c) => !Object.keys(contractMappings).includes(c));
226
+
227
+ const computeView = (source: readonly CheckCounterRecord[]) => {
228
+ const ws = computeWindowStats(source);
229
+ const effectiveIds = ws.evaluated.filter((id) => inventoryJoinIds.has(id));
230
+ const recs: ContributionRecord[] = [];
231
+ const candidates: VariantCandidate[] = [];
232
+ for (const r of rules) {
233
+ const f = fired.get(r.id) ?? { uniqueSignatures: new Set<string>(), sessions: 0, firedOn: new Set<string>() };
234
+ const cs = ws.stats.get(`${r.contract}/${r.id}`) ?? { emitted: 0, evaluated: 0, lastFiredAt: "", lastDiagRunIdx: -1, evalRunIdxs: new Set<number>() };
235
+ // Streak counts evaluation opportunities, not the whole run universe —
236
+ // operational commands journal their own rules, so foreign runs must not
237
+ // inflate a rule's silence (RFC-1474 review F-6).
238
+ const zeroStreak = [...cs.evalRunIdxs].filter((i) => i > cs.lastDiagRunIdx).length;
239
+ const escapeCount = Object.keys(contractMappings).length > 0
240
+ ? frictions.filter((fr) => contractMappings[fr.category ?? ""] === r.contract).length
241
+ : null;
242
+ const uniqueEmitted = [...f.uniqueSignatures].filter((s) => (signatureOwners.get(s)?.size ?? 0) === 1).length;
243
+ let verdict: ContributionRecord["verdict"];
244
+ let action: ContributionRecord["action"] | undefined;
245
+ if (guardRules.has(r.id)) { verdict = "guard"; action = "keep"; }
246
+ else if (cs.emitted > 0 && f.uniqueSignatures.size > 0 && uniqueEmitted === 0) { verdict = "redundant"; action = "scope"; }
247
+ else if (cs.emitted > 0) verdict = "earning";
248
+ else { verdict = "silent"; action = escapeCount === null || escapeCount > 0 ? "scope" : "probe"; }
249
+ if (uniqueEmitted > 0) {
250
+ candidates.push({ rule: r.id, firedOn: [...f.firedOn], siblingScope: r.contract });
251
+ }
252
+ recs.push({ ruleId: r.id, contract: r.contract, emitted: cs.emitted, evaluated: cs.evaluated, lastFiredAt: cs.lastFiredAt, uniqueEmitted, zeroStreak, escapeCount, verdict, action });
253
+ }
254
+ const metrics = {
255
+ schema: "forge/check-contribution@1",
256
+ generatedAt: ws.windowTo || "no-data",
257
+ window: { runs: ws.runCount, coverage: ws.coverage, effective: effectiveIds.length, observable: ws.evaluated.length },
258
+ rules: recs,
259
+ variantCandidates: candidates,
260
+ ungovernedContracts,
261
+ };
262
+ return { metrics, records: recs, variantCandidates: candidates, ws, effectiveIds };
263
+ };
264
+
265
+ const view = computeView(counterRecords);
266
+ const { metrics, records, variantCandidates, ws, effectiveIds } = view;
267
+ const { coverage, evaluated: evaluatedJoinIds } = ws;
268
+
269
+ const metricsRel = "docs/metrics/check-contribution.generated.yaml";
270
+ const serialized = yamlStringify(metrics) + "\n";
271
+
272
+ const diagnostics: Diagnostic[] = [];
273
+ if (coverage === "none") {
274
+ diagnostics.push({
275
+ ruleId: "CONTRIB-03",
276
+ severity: "warning",
277
+ message: "counters journal is empty or absent — coverage is none, all firing signals are honest zeros (no retroactive fabrication)",
278
+ });
279
+ }
280
+
281
+ if (check) {
282
+ const committed = await io.readFile(path.join(root, metricsRel)).catch(() => null);
283
+ // Recompute over the record set the committed artifact could have seen —
284
+ // this report's own journal tail is structurally unreachable.
285
+ const committedAt =
286
+ committed === null
287
+ ? ""
288
+ : ((yamlParse(committed) as { generatedAt?: string } | null)?.generatedAt ?? "");
289
+ const covered = recordsCoveredByArtifact(counterRecords, committedAt, "checks.contribution.report-");
290
+ const expected = yamlStringify(computeView(covered).metrics) + "\n";
291
+ const stale = committed !== expected;
292
+ return {
293
+ data: { command: "checks.contribution.report", status: "ok", window: metrics.window, rules: records, variantCandidates, ungovernedContracts, metrics: metricsRel, diagnostics },
294
+ summary: stale ? "CONTRIB-02 committed report is stale — run checks.contribution.report" : "report fresh",
295
+ exitCode: stale ? 1 : 0,
296
+ };
297
+ }
298
+
299
+ await io.mkdir(path.join(root, "docs", "metrics")).catch(() => {});
300
+ await io.writeFile(path.join(root, metricsRel), serialized);
301
+ if (context.outputFormat === "pretty") {
302
+ if (coverage === "none") {
303
+ context.logger.warn(`CONTRIB-03 counters journal is empty or absent — coverage: none`);
304
+ } else if (effectiveIds.length === 0 && evaluatedJoinIds.length > 0) {
305
+ context.logger.warn(`observableCoverage: ${effectiveIds.length}/${evaluatedJoinIds.length} evaluated ids resolve in the inventory — firing surface is structurally disjoint from the rule universe`);
306
+ }
307
+ for (const r of records.filter((r) => r.verdict === "silent" || r.verdict === "redundant")) {
308
+ context.logger.warn(`${r.verdict.toUpperCase()} ${r.ruleId} — ${r.emitted} emitted, ${r.uniqueEmitted} unique, streak ${r.zeroStreak} → ${r.action}`);
309
+ }
310
+ }
311
+ return {
312
+ data: { command: "checks.contribution.report", status: "ok", window: metrics.window, rules: records, variantCandidates, ungovernedContracts, metrics: metricsRel, diagnostics },
313
+ summary: `${records.length} rule(s): ${records.filter((r) => r.verdict === "earning").length} earning, ${records.filter((r) => r.verdict === "silent").length} silent, ${records.filter((r) => r.verdict === "redundant").length} redundant (effectiveCoverage ${effectiveIds.length}/${evaluatedJoinIds.length}, coverage ${coverage})`,
314
+ exitCode: 0,
315
+ };
316
+ }
@@ -0,0 +1,175 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>RFC-1474 checks.counters.export tests — journal projection into the
4
+ deterministic docs/metrics/check-counters.generated.yaml artifact (per-rule
5
+ evaluated/diagnostic/lastRunId/lastAt), generatedAt derived from the max
6
+ journal `at` (never wall-clock), --check staleness gate (COUNT-03).</purpose>
7
+ </MODULE_CONTRACT>
8
+ */
9
+
10
+ import { test, expect, describe, beforeEach, afterEach } from "vitest";
11
+ import { mkdtemp, rm, mkdir, appendFile, writeFile } from "node:fs/promises";
12
+ import { join } from "node:path";
13
+ import { tmpdir } from "node:os";
14
+ import { runCountersExport } from "./counters-export.ts";
15
+ import { COUNTERS_JOURNAL_PATH, type CheckCounterRecord } from "./counters-journal.ts";
16
+ import type { ForgeRuntimeContext } from "../../../src/types.ts";
17
+
18
+ let root: string;
19
+
20
+ function ctx(): ForgeRuntimeContext {
21
+ return {
22
+ workspaceRoot: root,
23
+ outputFormat: "json",
24
+ logger: { info() {}, warn() {}, error() {}, success() {}, section() {} },
25
+ } as unknown as ForgeRuntimeContext;
26
+ }
27
+
28
+ function flags(f: Record<string, unknown> = {}) {
29
+ return { argv: [], flags: f } as never;
30
+ }
31
+
32
+ const rec = (over: Partial<CheckCounterRecord> = {}): CheckCounterRecord => ({
33
+ runId: "run-a",
34
+ ruleId: "gate/GATE-CMP-01",
35
+ contract: "gate",
36
+ outcome: "pass",
37
+ at: "2026-10-31T20:00:00.000Z",
38
+ ...over,
39
+ });
40
+
41
+ async function seedJournal(records: CheckCounterRecord[]) {
42
+ await mkdir(join(root, "docs", ".index", "checks"), { recursive: true });
43
+ await appendFile(
44
+ join(root, COUNTERS_JOURNAL_PATH),
45
+ records.map((r) => JSON.stringify(r)).join("\n") + "\n",
46
+ );
47
+ }
48
+
49
+ beforeEach(async () => {
50
+ root = await mkdtemp(join(tmpdir(), "counters-export-"));
51
+ });
52
+
53
+ afterEach(async () => {
54
+ await rm(root, { recursive: true, force: true });
55
+ });
56
+
57
+ describe("checks.counters.export", () => {
58
+ test("AC-2: projects per-rule totals into the deterministic artifact", async () => {
59
+ await seedJournal([
60
+ rec({ outcome: "pass" }),
61
+ rec({ outcome: "diagnostic", runId: "run-b", at: "2026-10-31T21:00:00.000Z" }),
62
+ rec({ ruleId: "gate/GATE-CMP-02", outcome: "skipped", runId: "run-b", at: "2026-10-31T21:00:00.000Z" }),
63
+ ]);
64
+ const result = await runCountersExport(flags(), ctx());
65
+ expect(result.exitCode).toBe(0);
66
+ const artifact = await readFileSync();
67
+ expect(artifact.rules.find((r) => r.ruleId === "gate/GATE-CMP-01")).toMatchObject({
68
+ evaluated: 2,
69
+ diagnostic: 1,
70
+ lastRunId: "run-b",
71
+ lastAt: "2026-10-31T21:00:00.000Z",
72
+ });
73
+ // skipped does not count as evaluated.
74
+ expect(artifact.rules.find((r) => r.ruleId === "gate/GATE-CMP-02")).toMatchObject({
75
+ evaluated: 0,
76
+ diagnostic: 0,
77
+ });
78
+ expect(artifact.runCount).toBe(2);
79
+ });
80
+
81
+ async function readFileSync() {
82
+ const { parse } = await import("yaml");
83
+ const { readFile } = await import("node:fs/promises");
84
+ const src = await readFile(join(root, "docs", "metrics", "check-counters.generated.yaml"), "utf8");
85
+ return parse(src) as {
86
+ generatedAt: string;
87
+ runCount: number;
88
+ rules: { ruleId: string; evaluated: number; diagnostic: number; lastRunId: string; lastAt: string }[];
89
+ };
90
+ }
91
+
92
+ test("AC-10: generatedAt derives from the max journal at, never wall-clock", async () => {
93
+ await seedJournal([
94
+ rec({ at: "2026-10-31T20:00:00.000Z" }),
95
+ rec({ at: "2026-10-29T10:00:00.000Z", ruleId: "gate/G-2" }),
96
+ rec({ at: "2026-10-31T23:59:59.000Z", ruleId: "gate/G-3" }),
97
+ ]);
98
+ const result = await runCountersExport(flags(), ctx());
99
+ expect(result.exitCode).toBe(0);
100
+ const artifact = await readFileSync();
101
+ expect(artifact.generatedAt).toBe("2026-10-31T23:59:59.000Z");
102
+ expect(artifact.generatedAt).not.toMatch(/^2026-1[12]/); // not the current clock
103
+ });
104
+
105
+ test("empty journal exports an honest empty artifact", async () => {
106
+ const result = await runCountersExport(flags(), ctx());
107
+ expect(result.exitCode).toBe(0);
108
+ const artifact = await readFileSync();
109
+ expect(artifact.rules).toEqual([]);
110
+ expect(artifact.generatedAt).toBe("no-data");
111
+ expect(artifact.runCount).toBe(0);
112
+ });
113
+
114
+ test("does not crash on a truncated journal tail (AC-2 tolerance)", async () => {
115
+ await mkdir(join(root, "docs", ".index", "checks"), { recursive: true });
116
+ await appendFile(
117
+ join(root, COUNTERS_JOURNAL_PATH),
118
+ JSON.stringify(rec()) + "\n" + `{"runId":"x","ruleId":"gat`,
119
+ );
120
+ const result = await runCountersExport(flags(), ctx());
121
+ expect(result.exitCode).toBe(0);
122
+ const artifact = await readFileSync();
123
+ expect(artifact.rules).toHaveLength(1);
124
+ });
125
+
126
+ test("COUNT-03: --check exits 1 when the committed artifact is stale", async () => {
127
+ await seedJournal([rec()]);
128
+ await mkdir(join(root, "docs", "metrics"), { recursive: true });
129
+ await writeFile(join(root, "docs", "metrics", "check-counters.generated.yaml"), "stale: true\n");
130
+ const result = await runCountersExport(flags({ check: true }), ctx());
131
+ expect(result.exitCode).toBe(1);
132
+ expect(result.data!.diagnostics?.some((d) => d.ruleId === "COUNT-03")).toBe(true);
133
+ });
134
+
135
+ test("--check exits 0 when the artifact is fresh", async () => {
136
+ await seedJournal([rec()]);
137
+ await runCountersExport(flags(), ctx()); // write fresh artifact
138
+ const result = await runCountersExport(flags({ check: true }), ctx());
139
+ expect(result.exitCode).toBe(0);
140
+ });
141
+
142
+ test("producer-own tail records do not pin --check red (self-tail tolerance)", async () => {
143
+ await seedJournal([rec()]);
144
+ await runCountersExport(flags(), ctx());
145
+ // Simulate the exporter's own post-write journal tail — structurally
146
+ // unreachable by the committed artifact, so the check stays green.
147
+ await appendFile(
148
+ join(root, COUNTERS_JOURNAL_PATH),
149
+ JSON.stringify(rec({ ruleId: "checks/COUNT-03", contract: "checks", runId: "checks.counters.export-999-zz", at: "2026-10-31T22:00:00.000Z" })) + "\n",
150
+ );
151
+ const result = await runCountersExport(flags({ check: true }), ctx());
152
+ expect(result.exitCode).toBe(0);
153
+ });
154
+
155
+ test("non-producer journal growth still flags COUNT-03", async () => {
156
+ await seedJournal([rec()]);
157
+ await runCountersExport(flags(), ctx());
158
+ await appendFile(
159
+ join(root, COUNTERS_JOURNAL_PATH),
160
+ JSON.stringify(rec({ ruleId: "gate/GATE-CMP-02", runId: "other.validator-1-x", at: "2026-10-31T22:00:00.000Z" })) + "\n",
161
+ );
162
+ const result = await runCountersExport(flags({ check: true }), ctx());
163
+ expect(result.exitCode).toBe(1);
164
+ expect(result.data!.diagnostics!.some((d) => d.ruleId === "COUNT-03")).toBe(true);
165
+ });
166
+
167
+ test("--out overrides the artifact path", async () => {
168
+ await seedJournal([rec()]);
169
+ const result = await runCountersExport(flags({ out: "docs/metrics/custom-counters.yaml" }), ctx());
170
+ expect(result.exitCode).toBe(0);
171
+ const { readFile } = await import("node:fs/promises");
172
+ const src = await readFile(join(root, "docs", "metrics", "custom-counters.yaml"), "utf8");
173
+ expect(src).toContain("forge/check-counters@1");
174
+ });
175
+ });
@@ -0,0 +1,170 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>RFC-1474: checks.counters.export — projects the append-only counters
4
+ journal (docs/.index/checks/counters.jsonl) into the deterministic committed
5
+ artifact docs/metrics/check-counters.generated.yaml. Per-rule totals:
6
+ evaluated (pass|diagnostic|ensured — skipped never counts), diagnostic,
7
+ lastRunId, lastAt. generatedAt derives from the max journal `at`, never
8
+ wall-clock. --check diffs the computed artifact against the committed file
9
+ (COUNT-03 staleness, same freshness contract as other generated artifacts).
10
+ </purpose>
11
+ </MODULE_CONTRACT>
12
+ <CHANGE_SUMMARY>
13
+ <item>RFC-1474: checks.counters.export — deterministic journal projection + COUNT-03 --check gate</item>
14
+ <item>RFC-1474: per-rule check-execution counters
15
+
16
+ Append-only counters.jsonl journaled per evaluated rule ({runId, ruleId, contract, outcome, at}; runId = commandInvocationId; outcomes pass|diagnostic|skipped|ensured; dry-run suppressed; append failures warn never fail). checks.counters.validate audits the journal against the validator inventory (COUNT-01/02); checks.counters.export projects deterministic per-rule totals (COUNT-03, generatedAt = max journal at; producer-tail tolerated). checks.contribution.report joins counters as the canonical firing source (CONTRIB-03 on absent/empty journal; coverage none|partial|complete; live effectiveCoverage positive). Validator inventory now includes every rules[]-declaring command — fail-closed gate surfaced 9 contract-declaration defects, fixed with domain contracts.</item>
17
+ <item>RFC-1474: check-execution counters — apply re-review findings (structural skip flag, violations extraction, Date.parse ordering, DEV-5/6)</item>
18
+ </CHANGE_SUMMARY>
19
+ */
20
+
21
+ import path from "node:path";
22
+ import { parse as yamlParse, stringify as yamlStringify } from "yaml";
23
+ import { ambientIo, resolveIo } from "../../../src/utils/io.ts";
24
+ import type {
25
+ Diagnostic,
26
+ ForgeCommandInput,
27
+ ForgeCommandResult,
28
+ ForgeRuntimeContext,
29
+ } from "../../../src/types.ts";
30
+ import {
31
+ readCountersJournal,
32
+ recordsCoveredByArtifact,
33
+ type CheckCounterRecord,
34
+ } from "./counters-journal.ts";
35
+
36
+ const DEFAULT_OUT = "docs/metrics/check-counters.generated.yaml";
37
+ /** Producer run family — own-invocation tail records are excluded on --check. */
38
+ const PRODUCER_RUN_PREFIX = "checks.counters.export-";
39
+
40
+ export interface CounterRuleTotal {
41
+ ruleId: string;
42
+ contract: string;
43
+ evaluated: number;
44
+ diagnostic: number;
45
+ lastRunId: string;
46
+ lastAt: string;
47
+ }
48
+
49
+ export interface CountersExportData {
50
+ command: "checks.counters.export";
51
+ status: "ok";
52
+ rules: CounterRuleTotal[];
53
+ runCount: number;
54
+ out: string;
55
+ diagnostics?: Diagnostic[];
56
+ }
57
+
58
+ const countsAsEvaluated = (r: CheckCounterRecord) => r.outcome !== "skipped";
59
+
60
+ interface CountersArtifact {
61
+ schema: "forge/check-counters@1";
62
+ generatedAt: string;
63
+ runCount: number;
64
+ rules: CounterRuleTotal[];
65
+ }
66
+
67
+ function computeArtifact(records: readonly CheckCounterRecord[]): CountersArtifact {
68
+ const runIds = new Set<string>();
69
+ let generatedAt = "";
70
+ let generatedAtMs = Number.NEGATIVE_INFINITY;
71
+ const totals = new Map<string, CounterRuleTotal & { lastSeq: number }>();
72
+ records.forEach((r, seq) => {
73
+ runIds.add(r.runId);
74
+ const atMs = Date.parse(r.at);
75
+ if (atMs > generatedAtMs) {
76
+ generatedAtMs = atMs;
77
+ generatedAt = r.at;
78
+ }
79
+ const t = totals.get(r.ruleId) ?? {
80
+ ruleId: r.ruleId,
81
+ contract: r.contract,
82
+ evaluated: 0,
83
+ diagnostic: 0,
84
+ lastRunId: "",
85
+ lastAt: "",
86
+ lastSeq: -1,
87
+ };
88
+ if (countsAsEvaluated(r)) {
89
+ t.evaluated++;
90
+ if (r.outcome === "diagnostic") t.diagnostic++;
91
+ }
92
+ if (seq > t.lastSeq) {
93
+ t.lastSeq = seq;
94
+ t.lastRunId = r.runId;
95
+ t.lastAt = r.at;
96
+ }
97
+ totals.set(r.ruleId, t);
98
+ });
99
+
100
+ const rules = [...totals.values()]
101
+ .map(({ lastSeq: _lastSeq, ...t }) => t)
102
+ .sort((a, b) => (a.ruleId < b.ruleId ? -1 : a.ruleId > b.ruleId ? 1 : 0));
103
+
104
+ return {
105
+ schema: "forge/check-counters@1",
106
+ generatedAt: generatedAt || "no-data",
107
+ runCount: runIds.size,
108
+ rules,
109
+ };
110
+ }
111
+
112
+ export async function runCountersExport(
113
+ input: ForgeCommandInput,
114
+ context: ForgeRuntimeContext,
115
+ ): Promise<ForgeCommandResult<CountersExportData>> {
116
+ const io = resolveIo(context.io ?? ambientIo);
117
+ const root = context.workspaceRoot;
118
+ const check = input.flags["check"] === true;
119
+ const outRel = (input.flags["out"] as string | undefined) ?? DEFAULT_OUT;
120
+
121
+ const { records } = await readCountersJournal(root);
122
+ const artifact = computeArtifact(records);
123
+ const serialized = yamlStringify(artifact) + "\n";
124
+
125
+ const data: CountersExportData = {
126
+ command: "checks.counters.export",
127
+ status: "ok",
128
+ rules: artifact.rules,
129
+ runCount: artifact.runCount,
130
+ out: outRel,
131
+ };
132
+
133
+ if (check) {
134
+ const committed = await io.readFile(path.join(root, outRel)).catch(() => null);
135
+ // Recompute over the record set the committed artifact could have seen —
136
+ // the producing run's own tail records are structurally unreachable.
137
+ const committedAt =
138
+ committed === null
139
+ ? ""
140
+ : ((yamlParse(committed) as { generatedAt?: string } | null)?.generatedAt ?? "");
141
+ const covered = recordsCoveredByArtifact(records, committedAt, PRODUCER_RUN_PREFIX);
142
+ const expected = yamlStringify(computeArtifact(covered)) + "\n";
143
+ const stale = committed !== expected;
144
+ data.diagnostics = stale
145
+ ? [
146
+ {
147
+ ruleId: "COUNT-03",
148
+ severity: "warning",
149
+ message: `committed counters artifact is stale vs the journal tail — run checks.counters.export`,
150
+ file: outRel,
151
+ },
152
+ ]
153
+ : [];
154
+ return {
155
+ data,
156
+ summary: stale
157
+ ? `COUNT-03 ${outRel} is stale — run checks.counters.export`
158
+ : "counters artifact fresh",
159
+ exitCode: stale ? 1 : 0,
160
+ };
161
+ }
162
+
163
+ await io.mkdir(path.dirname(path.join(root, outRel))).catch(() => {});
164
+ await io.writeFile(path.join(root, outRel), serialized);
165
+ return {
166
+ data,
167
+ summary: `${artifact.rules.length} rule(s) across ${artifact.runCount} run(s) → ${outRel}`,
168
+ exitCode: 0,
169
+ };
170
+ }