ex-workflow 1.1.1 → 1.3.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 (193) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/README.md +209 -44
  3. package/dist/adapters/index.cjs +1 -1
  4. package/dist/adapters/index.d.cts +1 -1
  5. package/dist/adapters/index.d.ts +1 -1
  6. package/dist/adapters/index.mjs +1 -1
  7. package/dist/{budget-Bd8KpGIr.d.ts → budget-BuQ9GWsg.d.ts} +8 -7
  8. package/dist/{budget-CezCinPF.d.cts → budget-DDqQQIgp.d.cts} +8 -7
  9. package/dist/chunk-2FBA7RBS.cjs +2 -0
  10. package/dist/chunk-2FBA7RBS.cjs.map +1 -0
  11. package/dist/chunk-3S7F5QXK.mjs +2 -0
  12. package/dist/chunk-3S7F5QXK.mjs.map +1 -0
  13. package/dist/chunk-3ZUBCA7Q.cjs +2 -0
  14. package/dist/chunk-3ZUBCA7Q.cjs.map +1 -0
  15. package/dist/chunk-4F5HZLKD.cjs +2 -0
  16. package/dist/chunk-4F5HZLKD.cjs.map +1 -0
  17. package/dist/chunk-5DCOXGRW.mjs +2 -0
  18. package/dist/chunk-5DCOXGRW.mjs.map +1 -0
  19. package/dist/chunk-5GXB6GMX.mjs +2 -0
  20. package/dist/chunk-5GXB6GMX.mjs.map +1 -0
  21. package/dist/chunk-5ZGNEY2I.mjs +2 -0
  22. package/dist/chunk-5ZGNEY2I.mjs.map +1 -0
  23. package/dist/chunk-6PFJYRM7.cjs +2 -0
  24. package/dist/chunk-6PFJYRM7.cjs.map +1 -0
  25. package/dist/chunk-BANKVCYY.cjs +2 -0
  26. package/dist/chunk-BANKVCYY.cjs.map +1 -0
  27. package/dist/chunk-BBI7AKJK.cjs +2 -0
  28. package/dist/chunk-BBI7AKJK.cjs.map +1 -0
  29. package/dist/chunk-BD665RYK.mjs +2 -0
  30. package/dist/chunk-BD665RYK.mjs.map +1 -0
  31. package/dist/chunk-C4ISBUZR.mjs +2 -0
  32. package/dist/chunk-C4ISBUZR.mjs.map +1 -0
  33. package/dist/chunk-COPYGMHE.mjs +2 -0
  34. package/dist/chunk-COPYGMHE.mjs.map +1 -0
  35. package/dist/chunk-CVGEIXW6.cjs +2 -0
  36. package/dist/chunk-CVGEIXW6.cjs.map +1 -0
  37. package/dist/chunk-CX2E7ZTQ.mjs +2 -0
  38. package/dist/chunk-CX2E7ZTQ.mjs.map +1 -0
  39. package/dist/chunk-DVFTTBCT.cjs +3 -0
  40. package/dist/chunk-DVFTTBCT.cjs.map +1 -0
  41. package/dist/chunk-EQXYFHHD.cjs +2 -0
  42. package/dist/chunk-EQXYFHHD.cjs.map +1 -0
  43. package/dist/chunk-GKN5M4B7.cjs +2 -0
  44. package/dist/chunk-GKN5M4B7.cjs.map +1 -0
  45. package/dist/chunk-H26KXQ3I.cjs +2 -0
  46. package/dist/chunk-H26KXQ3I.cjs.map +1 -0
  47. package/dist/chunk-IDZ435YZ.mjs +2 -0
  48. package/dist/{chunk-KIQOUUEZ.mjs.map → chunk-IDZ435YZ.mjs.map} +1 -1
  49. package/dist/chunk-ILDXZWEL.mjs +2 -0
  50. package/dist/chunk-ILDXZWEL.mjs.map +1 -0
  51. package/dist/chunk-KA6DVHO5.cjs +6 -0
  52. package/dist/chunk-KA6DVHO5.cjs.map +1 -0
  53. package/dist/chunk-KLOSFZFK.cjs +2 -0
  54. package/dist/chunk-KLOSFZFK.cjs.map +1 -0
  55. package/dist/chunk-LG23WXAP.mjs +2 -0
  56. package/dist/chunk-LG23WXAP.mjs.map +1 -0
  57. package/dist/chunk-MU26QW32.cjs +2 -0
  58. package/dist/chunk-MU26QW32.cjs.map +1 -0
  59. package/dist/chunk-OEHVWRJG.mjs +2 -0
  60. package/dist/chunk-OEHVWRJG.mjs.map +1 -0
  61. package/dist/chunk-ONVAUZOD.mjs +6 -0
  62. package/dist/chunk-ONVAUZOD.mjs.map +1 -0
  63. package/dist/chunk-OSHBJIYD.cjs +2 -0
  64. package/dist/chunk-OSHBJIYD.cjs.map +1 -0
  65. package/dist/chunk-PFHVB2WT.mjs +2 -0
  66. package/dist/chunk-PFHVB2WT.mjs.map +1 -0
  67. package/dist/chunk-PNWRA4JU.cjs +2 -0
  68. package/dist/{chunk-PO2SPQJP.cjs.map → chunk-PNWRA4JU.cjs.map} +1 -1
  69. package/dist/chunk-QJMOCISZ.mjs +3 -0
  70. package/dist/chunk-QJMOCISZ.mjs.map +1 -0
  71. package/dist/chunk-RGHM3JJM.cjs +2 -0
  72. package/dist/chunk-RGHM3JJM.cjs.map +1 -0
  73. package/dist/chunk-TQR3VFZU.mjs +2 -0
  74. package/dist/chunk-TQR3VFZU.mjs.map +1 -0
  75. package/dist/chunk-UMG3WOD7.cjs +2 -0
  76. package/dist/chunk-UMG3WOD7.cjs.map +1 -0
  77. package/dist/chunk-UT7QV6CE.mjs +2 -0
  78. package/dist/chunk-UT7QV6CE.mjs.map +1 -0
  79. package/dist/chunk-WU5JELOM.mjs +2 -0
  80. package/dist/chunk-WU5JELOM.mjs.map +1 -0
  81. package/dist/chunk-YGCNLXPJ.cjs +2 -0
  82. package/dist/chunk-YGCNLXPJ.cjs.map +1 -0
  83. package/dist/chunk-YS6CXERQ.mjs +2 -0
  84. package/dist/chunk-YS6CXERQ.mjs.map +1 -0
  85. package/dist/cli/bin.cjs +1 -1
  86. package/dist/cli/bin.cjs.map +1 -1
  87. package/dist/cli/bin.mjs +1 -1
  88. package/dist/cli/bin.mjs.map +1 -1
  89. package/dist/cli/index.cjs +1 -1
  90. package/dist/cli/index.mjs +1 -1
  91. package/dist/experimentation/index.cjs +1 -1
  92. package/dist/experimentation/index.d.cts +2 -2
  93. package/dist/experimentation/index.d.ts +2 -2
  94. package/dist/experimentation/index.mjs +1 -1
  95. package/dist/index.cjs +1 -1
  96. package/dist/index.cjs.map +1 -1
  97. package/dist/index.d.cts +145 -15
  98. package/dist/index.d.ts +145 -15
  99. package/dist/index.mjs +1 -1
  100. package/dist/index.mjs.map +1 -1
  101. package/dist/investigation/index.cjs +1 -1
  102. package/dist/investigation/index.d.cts +2 -2
  103. package/dist/investigation/index.d.ts +2 -2
  104. package/dist/investigation/index.mjs +1 -1
  105. package/dist/kanban/index.cjs +1 -1
  106. package/dist/kanban/index.d.cts +2 -1
  107. package/dist/kanban/index.d.ts +2 -1
  108. package/dist/kanban/index.mjs +1 -1
  109. package/dist/policies/index.cjs +2 -0
  110. package/dist/policies/index.cjs.map +1 -0
  111. package/dist/policies/index.d.cts +199 -0
  112. package/dist/policies/index.d.ts +199 -0
  113. package/dist/policies/index.mjs +2 -0
  114. package/dist/policies/index.mjs.map +1 -0
  115. package/dist/registry/index.cjs +2 -0
  116. package/dist/registry/index.cjs.map +1 -0
  117. package/dist/registry/index.d.cts +25 -0
  118. package/dist/registry/index.d.ts +25 -0
  119. package/dist/registry/index.mjs +2 -0
  120. package/dist/registry/index.mjs.map +1 -0
  121. package/dist/schema/index.cjs +1 -1
  122. package/dist/schema/index.d.cts +2 -0
  123. package/dist/schema/index.d.ts +2 -0
  124. package/dist/schema/index.mjs +1 -1
  125. package/dist/scrum/index.cjs +1 -1
  126. package/dist/scrum/index.d.cts +3 -3
  127. package/dist/scrum/index.d.ts +3 -3
  128. package/dist/scrum/index.mjs +1 -1
  129. package/dist/{types-BScHXlRx.d.ts → types-DLOtndDY.d.cts} +121 -22
  130. package/dist/{types-BScHXlRx.d.cts → types-DLOtndDY.d.ts} +121 -22
  131. package/dist/types.cjs +1 -1
  132. package/dist/types.d.cts +1 -1
  133. package/dist/types.d.ts +1 -1
  134. package/dist/types.mjs +1 -1
  135. package/dist/waterfall/index.cjs +1 -1
  136. package/dist/waterfall/index.d.cts +1 -1
  137. package/dist/waterfall/index.d.ts +1 -1
  138. package/dist/waterfall/index.mjs +1 -1
  139. package/package.json +30 -3
  140. package/dist/chunk-2FRRD6A3.mjs +0 -2
  141. package/dist/chunk-2FRRD6A3.mjs.map +0 -1
  142. package/dist/chunk-6P3OKXSK.mjs +0 -2
  143. package/dist/chunk-6P3OKXSK.mjs.map +0 -1
  144. package/dist/chunk-7FS6KWTG.cjs +0 -2
  145. package/dist/chunk-7FS6KWTG.cjs.map +0 -1
  146. package/dist/chunk-7QQY4KJ2.mjs +0 -2
  147. package/dist/chunk-7QQY4KJ2.mjs.map +0 -1
  148. package/dist/chunk-AD4Z3JBL.cjs +0 -2
  149. package/dist/chunk-AD4Z3JBL.cjs.map +0 -1
  150. package/dist/chunk-ATCJ4IHP.mjs +0 -2
  151. package/dist/chunk-ATCJ4IHP.mjs.map +0 -1
  152. package/dist/chunk-C2IYMWE6.cjs +0 -3
  153. package/dist/chunk-C2IYMWE6.cjs.map +0 -1
  154. package/dist/chunk-EACZBAP3.cjs +0 -2
  155. package/dist/chunk-EACZBAP3.cjs.map +0 -1
  156. package/dist/chunk-EFCUM6DK.mjs +0 -2
  157. package/dist/chunk-EFCUM6DK.mjs.map +0 -1
  158. package/dist/chunk-EHBQBXWA.cjs +0 -2
  159. package/dist/chunk-EHBQBXWA.cjs.map +0 -1
  160. package/dist/chunk-FTS75UIU.mjs +0 -2
  161. package/dist/chunk-FTS75UIU.mjs.map +0 -1
  162. package/dist/chunk-HCRVWMG4.cjs +0 -2
  163. package/dist/chunk-HCRVWMG4.cjs.map +0 -1
  164. package/dist/chunk-KIQOUUEZ.mjs +0 -2
  165. package/dist/chunk-KLWZEXZU.mjs +0 -3
  166. package/dist/chunk-KLWZEXZU.mjs.map +0 -1
  167. package/dist/chunk-NDCQTRIV.mjs +0 -2
  168. package/dist/chunk-NDCQTRIV.mjs.map +0 -1
  169. package/dist/chunk-PMUGU5UJ.cjs +0 -2
  170. package/dist/chunk-PMUGU5UJ.cjs.map +0 -1
  171. package/dist/chunk-PO2SPQJP.cjs +0 -2
  172. package/dist/chunk-QZ6HD6DE.mjs +0 -6
  173. package/dist/chunk-QZ6HD6DE.mjs.map +0 -1
  174. package/dist/chunk-RL27372B.cjs +0 -2
  175. package/dist/chunk-RL27372B.cjs.map +0 -1
  176. package/dist/chunk-S3BXVHO7.cjs +0 -2
  177. package/dist/chunk-S3BXVHO7.cjs.map +0 -1
  178. package/dist/chunk-SP5MC7RR.mjs +0 -2
  179. package/dist/chunk-SP5MC7RR.mjs.map +0 -1
  180. package/dist/chunk-SVGTSPZF.cjs +0 -2
  181. package/dist/chunk-SVGTSPZF.cjs.map +0 -1
  182. package/dist/chunk-SYLO7FUL.mjs +0 -2
  183. package/dist/chunk-SYLO7FUL.mjs.map +0 -1
  184. package/dist/chunk-T3V5UE34.mjs +0 -2
  185. package/dist/chunk-T3V5UE34.mjs.map +0 -1
  186. package/dist/chunk-TS66RAJR.cjs +0 -2
  187. package/dist/chunk-TS66RAJR.cjs.map +0 -1
  188. package/dist/chunk-U23FUYPD.cjs +0 -6
  189. package/dist/chunk-U23FUYPD.cjs.map +0 -1
  190. package/dist/chunk-U6GHFKKE.mjs +0 -2
  191. package/dist/chunk-U6GHFKKE.mjs.map +0 -1
  192. package/dist/chunk-YJQ5YJ7S.cjs +0 -2
  193. package/dist/chunk-YJQ5YJ7S.cjs.map +0 -1
@@ -1,2 +1,2 @@
1
- 'use strict';var chunkYJQ5YJ7S_cjs=require('../chunk-YJQ5YJ7S.cjs');require('../chunk-EHBQBXWA.cjs'),require('../chunk-HCRVWMG4.cjs'),require('../chunk-EACZBAP3.cjs'),require('../chunk-S3BXVHO7.cjs');Object.defineProperty(exports,"ACTIVE",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.a}});Object.defineProperty(exports,"CADENCE_EVENT",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.s}});Object.defineProperty(exports,"CLASSES",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.k}});Object.defineProperty(exports,"DAY_MS",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.l}});Object.defineProperty(exports,"DEFAULT_COLUMNS",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.n}});Object.defineProperty(exports,"KANBAN_CADENCES",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.j}});Object.defineProperty(exports,"KANBAN_VOCABULARY",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.F}});Object.defineProperty(exports,"OPEN",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.b}});Object.defineProperty(exports,"activeExpedites",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.h}});Object.defineProperty(exports,"addedAt",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.p}});Object.defineProperty(exports,"board",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.r}});Object.defineProperty(exports,"byClassThenAge",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.H}});Object.defineProperty(exports,"cadencesDue",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.t}});Object.defineProperty(exports,"cardAge",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.q}});Object.defineProperty(exports,"columnIndex",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.f}});Object.defineProperty(exports,"columnStays",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.w}});Object.defineProperty(exports,"commitmentColumn",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.d}});Object.defineProperty(exports,"configOf",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.m}});Object.defineProperty(exports,"deliveryColumn",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.e}});Object.defineProperty(exports,"enteredStageAt",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.i}});Object.defineProperty(exports,"kanban",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.I}});Object.defineProperty(exports,"kanbanCeremonies",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.B}});Object.defineProperty(exports,"kanbanMetrics",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.x}});Object.defineProperty(exports,"kanbanRoles",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.C}});Object.defineProperty(exports,"kanbanRules",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.D}});Object.defineProperty(exports,"kanbanStages",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.E}});Object.defineProperty(exports,"onBoard",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.g}});Object.defineProperty(exports,"opsReport",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.y}});Object.defineProperty(exports,"optionsColumn",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.c}});Object.defineProperty(exports,"percentile",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.v}});Object.defineProperty(exports,"priorityByClass",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.G}});Object.defineProperty(exports,"replay",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.u}});Object.defineProperty(exports,"riskReport",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.z}});Object.defineProperty(exports,"validateKanbanConfig",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.o}});Object.defineProperty(exports,"wantItems",{enumerable:true,get:function(){return chunkYJQ5YJ7S_cjs.A}});//# sourceMappingURL=index.cjs.map
1
+ 'use strict';var chunkYGCNLXPJ_cjs=require('../chunk-YGCNLXPJ.cjs');require('../chunk-GKN5M4B7.cjs'),require('../chunk-BANKVCYY.cjs'),require('../chunk-H26KXQ3I.cjs'),require('../chunk-MU26QW32.cjs'),require('../chunk-OSHBJIYD.cjs');Object.defineProperty(exports,"ACTIVE",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.a}});Object.defineProperty(exports,"CADENCE_EVENT",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.s}});Object.defineProperty(exports,"CLASSES",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.k}});Object.defineProperty(exports,"DAY_MS",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.l}});Object.defineProperty(exports,"DEFAULT_COLUMNS",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.n}});Object.defineProperty(exports,"KANBAN_CADENCES",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.j}});Object.defineProperty(exports,"KANBAN_VOCABULARY",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.F}});Object.defineProperty(exports,"OPEN",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.b}});Object.defineProperty(exports,"activeExpedites",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.h}});Object.defineProperty(exports,"addedAt",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.p}});Object.defineProperty(exports,"board",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.r}});Object.defineProperty(exports,"byClassThenAge",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.H}});Object.defineProperty(exports,"cadencesDue",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.t}});Object.defineProperty(exports,"cardAge",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.q}});Object.defineProperty(exports,"columnIndex",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.f}});Object.defineProperty(exports,"columnStays",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.w}});Object.defineProperty(exports,"commitmentColumn",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.d}});Object.defineProperty(exports,"configOf",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.m}});Object.defineProperty(exports,"deliveryColumn",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.e}});Object.defineProperty(exports,"enteredStageAt",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.i}});Object.defineProperty(exports,"kanban",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.I}});Object.defineProperty(exports,"kanbanCeremonies",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.B}});Object.defineProperty(exports,"kanbanMetrics",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.x}});Object.defineProperty(exports,"kanbanRoles",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.C}});Object.defineProperty(exports,"kanbanRules",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.D}});Object.defineProperty(exports,"kanbanStages",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.E}});Object.defineProperty(exports,"onBoard",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.g}});Object.defineProperty(exports,"opsReport",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.y}});Object.defineProperty(exports,"optionsColumn",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.c}});Object.defineProperty(exports,"percentile",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.v}});Object.defineProperty(exports,"priorityByClass",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.G}});Object.defineProperty(exports,"replay",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.u}});Object.defineProperty(exports,"riskReport",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.z}});Object.defineProperty(exports,"validateKanbanConfig",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.o}});Object.defineProperty(exports,"wantItems",{enumerable:true,get:function(){return chunkYGCNLXPJ_cjs.A}});//# sourceMappingURL=index.cjs.map
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1,4 +1,4 @@
1
- import { m as ClassOfService, P as Policy, W as WorkflowState, R as Role, S as Stage, g as Rule, M as Methodology, f as Ceremony, n as CeremonyInput, j as ItemStatus, l as WorkItem, o as Event, k as CoreTerm } from '../types-BScHXlRx.cjs';
1
+ import { r as ClassOfService, P as Policy, W as WorkflowState, R as Role, S as Stage, g as Rule, M as Methodology, f as Ceremony, s as CeremonyInput, j as ItemStatus, l as WorkItem, t as Event, k as CoreTerm } from '../types-DLOtndDY.cjs';
2
2
 
3
3
  type KanbanCadence = "replenishment" | "delivery-planning" | "service-delivery-review" | "operations-review" | "risk-review" | "strategy-review";
4
4
  declare const KANBAN_CADENCES: readonly KanbanCadence[];
@@ -37,6 +37,7 @@ interface KanbanConfig {
37
37
  maxExpedite: number;
38
38
  }
39
39
  declare function configOf(state: WorkflowState): KanbanConfig;
40
+ /** Deeply frozen: `validateKanbanConfig` gives each config its own copy. */
40
41
  declare const DEFAULT_COLUMNS: KanbanColumn[];
41
42
  declare function validateKanbanConfig(raw: unknown): KanbanConfig;
42
43
 
@@ -1,4 +1,4 @@
1
- import { m as ClassOfService, P as Policy, W as WorkflowState, R as Role, S as Stage, g as Rule, M as Methodology, f as Ceremony, n as CeremonyInput, j as ItemStatus, l as WorkItem, o as Event, k as CoreTerm } from '../types-BScHXlRx.js';
1
+ import { r as ClassOfService, P as Policy, W as WorkflowState, R as Role, S as Stage, g as Rule, M as Methodology, f as Ceremony, s as CeremonyInput, j as ItemStatus, l as WorkItem, t as Event, k as CoreTerm } from '../types-DLOtndDY.js';
2
2
 
3
3
  type KanbanCadence = "replenishment" | "delivery-planning" | "service-delivery-review" | "operations-review" | "risk-review" | "strategy-review";
4
4
  declare const KANBAN_CADENCES: readonly KanbanCadence[];
@@ -37,6 +37,7 @@ interface KanbanConfig {
37
37
  maxExpedite: number;
38
38
  }
39
39
  declare function configOf(state: WorkflowState): KanbanConfig;
40
+ /** Deeply frozen: `validateKanbanConfig` gives each config its own copy. */
40
41
  declare const DEFAULT_COLUMNS: KanbanColumn[];
41
42
  declare function validateKanbanConfig(raw: unknown): KanbanConfig;
42
43
 
@@ -1,2 +1,2 @@
1
- export{a as ACTIVE,s as CADENCE_EVENT,k as CLASSES,l as DAY_MS,n as DEFAULT_COLUMNS,j as KANBAN_CADENCES,F as KANBAN_VOCABULARY,b as OPEN,h as activeExpedites,p as addedAt,r as board,H as byClassThenAge,t as cadencesDue,q as cardAge,f as columnIndex,w as columnStays,d as commitmentColumn,m as configOf,e as deliveryColumn,i as enteredStageAt,I as kanban,B as kanbanCeremonies,x as kanbanMetrics,C as kanbanRoles,D as kanbanRules,E as kanbanStages,g as onBoard,y as opsReport,c as optionsColumn,v as percentile,G as priorityByClass,u as replay,z as riskReport,o as validateKanbanConfig,A as wantItems}from'../chunk-T3V5UE34.mjs';import'../chunk-FTS75UIU.mjs';import'../chunk-NDCQTRIV.mjs';import'../chunk-6P3OKXSK.mjs';import'../chunk-2FRRD6A3.mjs';//# sourceMappingURL=index.mjs.map
1
+ export{a as ACTIVE,s as CADENCE_EVENT,k as CLASSES,l as DAY_MS,n as DEFAULT_COLUMNS,j as KANBAN_CADENCES,F as KANBAN_VOCABULARY,b as OPEN,h as activeExpedites,p as addedAt,r as board,H as byClassThenAge,t as cadencesDue,q as cardAge,f as columnIndex,w as columnStays,d as commitmentColumn,m as configOf,e as deliveryColumn,i as enteredStageAt,I as kanban,B as kanbanCeremonies,x as kanbanMetrics,C as kanbanRoles,D as kanbanRules,E as kanbanStages,g as onBoard,y as opsReport,c as optionsColumn,v as percentile,G as priorityByClass,u as replay,z as riskReport,o as validateKanbanConfig,A as wantItems}from'../chunk-3S7F5QXK.mjs';import'../chunk-C4ISBUZR.mjs';import'../chunk-5DCOXGRW.mjs';import'../chunk-PFHVB2WT.mjs';import'../chunk-COPYGMHE.mjs';import'../chunk-YS6CXERQ.mjs';//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,2 @@
1
+ 'use strict';var chunkGKN5M4B7_cjs=require('../chunk-GKN5M4B7.cjs'),chunk6PFJYRM7_cjs=require('../chunk-6PFJYRM7.cjs'),chunkMU26QW32_cjs=require('../chunk-MU26QW32.cjs'),chunkOSHBJIYD_cjs=require('../chunk-OSHBJIYD.cjs');var ke=new WeakMap;function X(e,n,t){let s=e.get(n);s?s.push(t):e.set(n,[t]);}function je(e){let n={evidence:new Map,transitions:new Map,rework:new Map,changed:new Map};for(let t=0;t<e.length;t++){let s=e[t],r=s.payload;if(s.type==="item.evidence")X(n.evidence,r?.id,t);else if(s.type==="item.transition"||r?.transition)X(n.transitions,r?.id,t);else if(s.type==="item.rework")n.rework.set(r?.id,t);else if(s.type==="repo.changed"&&Array.isArray(r?.paths)){let i=r.paths;for(let a=0;a<i.length;a++)typeof i[a]=="string"&&X(n.changed,i[a],[t,a]);}}return n}function _(e){let n=e.events,t=n.length,s=ke.get(n);if(s&&s.n===t&&s.last===n[t-1])return s.index;let r=je(n);return ke.set(n,{n:t,last:n[t-1],index:r}),r}function Z(e,n,t){let s=0,r=e.length;for(;s<r;){let i=s+r>>1;t(e[i])>n?r=i:s=i+1;}return s}function F(e,n,t){let s=e.rework.get(n);if(s===void 0)return;let r=t??[];return r.length-Z(r,s,i=>i)}function T(e,n){let t=_(e),s=t.transitions.get(n.id)??[],r=n.transitions,i=F(t,n.id,s),a=i===void 0||s.length!==r.length?r:r.slice(r.length-i),u=new Set;for(let o of a)o.to.status==="in_progress"&&u.add(o.by);for(let o of [n.role,chunkMU26QW32_cjs.G(e,n)])o!==void 0&&u.add(o);return [...u]}var j=chunkGKN5M4B7_cjs.a(["low","medium","high","critical"]),J=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),P=(e,n)=>Object.hasOwn(e,n)?e[n]:void 0,be=new WeakSet;function U(e,n){if(typeof e=="object"&&e!==null&&be.has(e))return e;let t=(l,m)=>chunkOSHBJIYD_cjs.b("invalid-input",`${n} options: ${l}`,m),s=(l,m,f)=>{for(let g of Object.keys(l))m.includes(g)||t(`unknown key "${g}" in ${f}`,`use only: ${m.join(", ")}`);},r=(l,m)=>{if(l==="human")return l;let f=J(l)?P(l,"capability"):void 0;return (typeof f!="string"||f.trim()===""||Object.keys(l).length!==1)&&t(`${m} must be "human" or { capability: <name> }`,'e.g. ["human"] or [{ "capability": "review" }]'),{capability:f}};J(e)||t("must be an object",'pass { "gates": ["code-review"] }');let i=e;s(i,["gates","table"],"options");let a=P(i,"gates");Array.isArray(a)||t("gates must be an array of gate ids",'e.g. "gates": ["code-review"]');let u=a.map(l=>(chunkOSHBJIYD_cjs.c(l,"risk gate id"),l)),o=P(i,"table"),d;if(o!==void 0){J(o)||t("table must be an object keyed by risk level",`levels: ${j.join(", ")}`);let l=o;s(l,j,"table"),d={};let m=[];for(let f of j){let g=P(l,f);J(g)||t(`table is missing level "${f}"`,`give every level a row, e.g. "${f}": { "requires": [] }`);let h=g;s(h,["requires","evidence"],`table.${f}`);let I=P(h,"requires");Array.isArray(I)||t(`table.${f}.requires must be an array`,'e.g. "requires": ["human"]');let p=P(h,"evidence");p!==void 0&&(!Array.isArray(p)||!p.every(b=>typeof b=="string"&&b.trim()!==""))&&t(`table.${f}.evidence must be an array of evidence kinds`,'e.g. "evidence": ["sbom"]');let y=I.map((b,w)=>r(b,`table.${f}.requires[${w}]`)),R=p===void 0?void 0:[...p],M=[...y.map(b=>JSON.stringify(b)),...(R??[]).map(b=>`evidence ${JSON.stringify(b)}`)],O=m.filter(b=>!M.includes(b));O.length&&t(`table.${f} must include everything the level below it adds (missing ${O.join(", ")})`,"a stricter level only adds: copy the lower level's requires and evidence into it"),m=M,d[f]={requires:y,...R===void 0?{}:{evidence:R}};}}let c=chunkGKN5M4B7_cjs.a(d?{gates:u,table:d}:{gates:u});return be.add(c),c}var we=chunkGKN5M4B7_cjs.a({low:{requires:[]},medium:{requires:[]},high:{requires:["human"]},critical:{requires:["human"]}}),Ie=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function Ce(e){return Ie(e)&&j.includes(e.level)&&Array.isArray(e.factors)&&e.factors.every(n=>typeof n=="string")&&(e.subject===void 0||typeof e.subject=="string")}function Q(e,n,t,s=T(e,n)){return chunkMU26QW32_cjs.l(e,t,"verify")?chunk6PFJYRM7_cjs.a(t,s).length?"not-independent":void 0:"invalid"}function ee(e,n,t,s){let r=U(s,"riskEscalation");if(!r.gates.includes(t.id))return;let i,a="missing",u,o;for(let l of chunkMU26QW32_cjs.y(e,n)){if(l.kind!=="risk-assessment")continue;let m=Ce(l.data)?Q(e,n,l.by,o??=T(e,n)):"invalid";if(m){i||(a=m,u=l);continue}let f=l.data.level;(!i||j.indexOf(f)>=j.indexOf(i))&&(i=f,a="assessed",u=l);}let d=i??"critical",c=(r.table??we)[d];return {requires:c.requires.map(l=>l==="human"?l:{capability:l.capability}),evidence:[...c.evidence??[]],reason:{level:d,why:a,assessment:u?.ref??null,by:u?.by??null}}}var ne=["item","level","factors","ref","subject","by","now"],S=(e,n)=>chunkOSHBJIYD_cjs.b("invalid-input",`risk assessment: ${e}`,n);function Me(e,n,t){(typeof t!="object"||t===null||Array.isArray(t))&&S("input must be an object",`pass { ${ne.join(", ")} }`);for(let f of Object.keys(t))ne.includes(f)||S(`unknown key "${f}"`,`use only: ${ne.join(", ")}`);let{item:s,level:r,factors:i,ref:a,subject:u,by:o,now:d}=t;typeof s!="string"&&S("item must be an item id",'e.g. "item": "CART-12"');let c=chunkMU26QW32_cjs.r(e,s);j.includes(r)||S(`unknown level ${JSON.stringify(r)}`,`use one of: ${j.join(", ")}`),(!Array.isArray(i)||!i.every(f=>typeof f=="string"))&&S("factors must be an array of strings",'e.g. "factors": ["ci-cd", "secrets"]'),(typeof a!="string"||a.trim()==="")&&S("ref must be a non-empty string",'name the assessment artifact, e.g. "risk/CART-12.md"'),u!==void 0&&typeof u!="string"&&S("subject must be a string","pass the assessed SHA or ref, or omit it"),d!==void 0&&typeof d!="string"&&S("now must be an ISO timestamp string","omit now to use the clock"),(typeof o!="string"||o==="")&&S("by must name the assessor",'e.g. "by": "human"');let l=Q(e,c,o);l==="invalid"&&S(`"${o}" may not assess risk (needs capability "verify")`,`assess as human or one of: ${chunkMU26QW32_cjs.g(e,"verify").map(f=>f.id).join(", ")||"(no role has verify; register one)"}`),l&&S(`"${o}" did the work on "${s}" and may not assess its risk`,"assess as human or an independent role with capability verify");let m={level:r,factors:[...i]};return u!==void 0&&(m.subject=u),chunkMU26QW32_cjs.W(e,n,{type:"risk.assess",by:o,payload:{item:s,ref:a,...m}},f=>chunkMU26QW32_cjs.z(f,s,{kind:"risk-assessment",ref:a,by:o,data:m},d))}var z=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),V=e=>typeof e=="string"&&e.trim()!=="",B=(e,n)=>Object.keys(e).find(t=>!n.includes(t));function Ee(e){return e<32||e>=127&&e<=159||e===1564||e===8206||e===8207||e>=8234&&e<=8238||e>=8294&&e<=8297}function se(e){let n=typeof e!="string"?"not a string":e.length>4096?"longer than 4096 characters":[...e].some(s=>Ee(s.codePointAt(0)))?"has a control or bidirectional formatting character":e!==e.trim()?"has leading or trailing whitespace":e!==e.normalize("NFC")?"is not Unicode NFC":e.includes("\\")||/^[A-Za-z]:/.test(e)||!e.split("/").every(s=>s!==""&&s!=="."&&s!=="..")?"is not relative with / separators and no empty, . or .. segment":void 0;return n?`${JSON.stringify(typeof e=="string"&&e.length>80?`${e.slice(0,80)}\u2026`:e)} is not a repository-relative POSIX path (${n})`:void 0}function ve(e){if(!z(e))return "data must be an object";let n=B(e,["revision","assumptions"]);if(n)return `unknown key "${n}"`;if(!V(e.revision))return "revision must be a non-empty string";let t=e.assumptions;if(!Array.isArray(t))return "assumptions must be an array";for(let[s,r]of t.entries()){let i=`assumptions[${s}]`;if(!z(r))return `${i} must be an object`;let a=B(r,["claim","required","source"]);if(a)return `unknown key "${a}" in ${i}`;if(!V(r.claim))return `${i}.claim must be a non-empty string`;if(r.required!==void 0&&typeof r.required!="boolean")return `${i}.required must be a boolean`;let u=r.source;if(u===void 0)continue;if(!z(u))return `${i}.source must be an object`;let o=B(u,["path","lines","hash"]);if(o)return `unknown key "${o}" in ${i}.source`;let d=se(u.path);if(d)return `${i}.source.path ${d}`;if(!V(u.hash))return `${i}.source.hash must be a non-empty string`;let c=u.lines;if(c!==void 0&&!(Array.isArray(c)&&c.length===2&&Number.isInteger(c[0])&&Number.isInteger(c[1])&&1<=c[0]&&c[0]<=c[1]))return `${i}.source.lines must be two integers [from, to] with 1 <= from <= to`}}function xe(e,n,t){return typeof n!="string"||n!=="human"&&!Object.hasOwn(e.roles,n)?`${JSON.stringify(n)} is neither human nor a registered role`:t.includes(n)?`"${n}" worked on the item`:void 0}var $e=e=>e.assumptions.some(n=>n.source),Ne=({source:e,...n})=>e?{...n,source:{...e,...e.lines?{lines:[...e.lines]}:{}}}:n;function E(e,n){let t=_(e),s=t.evidence.get(n.id)??[],r=n.evidence,i=F(t,n.id,s),a=i===void 0?r.length:Math.min(i,r.length),u;for(let o=r.length-1;o>=r.length-a;o--){let d=r[o];if(d.kind!=="context-snapshot"||ve(d.data)!==void 0)continue;let c=d.data;if(!$e(c)||xe(e,d.by,u??=T(e,n)))continue;let l=s[o+s.length-r.length]??-1,m=[];for(let f of new Set(c.assumptions.map(g=>g.source?.path))){let g=f===void 0?void 0:t.changed.get(f),h=g?Z(g,l,I=>I[0]):0;g&&h<g.length&&m.push([g[h][0],g[h][1],f]);}return m.sort((f,g)=>f[0]-g[0]||f[1]-g[1]),{revision:c.revision,assumptions:c.assumptions.map(Ne),snapshot:d.ref,by:d.by,stale:m.map(f=>f[2]),unverified:c.assumptions.filter(f=>!f.source).map(f=>f.claim)}}}var te=["item","revision","assumptions","ref","by","now"],C=(e,n)=>chunkOSHBJIYD_cjs.b("invalid-input",`context snapshot: ${e}`,n);function Ge(e,n,t){z(t)||C("input must be an object",`pass { ${te.join(", ")} }`);let s=B(t,te);s&&C(`unknown key "${s}"`,`use only: ${te.join(", ")}`);let{item:r,revision:i,assumptions:a,ref:u,by:o,now:d}=t;typeof r!="string"&&C("item must be an item id",'e.g. "item": "CART-12"');let c=chunkMU26QW32_cjs.r(e,r),l={revision:i,assumptions:a},m=ve(l);m&&C(m,'e.g. { "revision": "4f2c1e0", "assumptions": [{ "claim": "totals are cents", "source": { "path": "src/cart.ts", "hash": "\u2026" } }] }'),V(u)||C("ref must be a non-empty string",'name the snapshot artifact, e.g. "ctx/CART-12.json"'),V(o)||C("by must name who recorded it",'e.g. "by": "scout"');let f=xe(e,o,T(e,c));f&&C(`${f} and may not record its context`,"record as human or a registered role that did not work on the item"),$e(l)||C("a snapshot needs at least one assumption with a source (nothing was verified)",'cite what was checked, e.g. "source": { "path": "src/cart.ts", "hash": "\u2026" }'),d!==void 0&&typeof d!="string"&&C("now must be an ISO timestamp string","omit now to use the clock");let g=JSON.parse(JSON.stringify(l));return chunkMU26QW32_cjs.W(e,n,{type:"context.snapshot",by:o,payload:{item:r,ref:u,...g}},h=>chunkMU26QW32_cjs.z(h,r,{kind:"context-snapshot",ref:u,by:o,data:g},d))}var We="policy:custom:context-grounded",oe="record a fresh one with recordContextSnapshot";function re(e,n){let t=[],s=(o,d)=>t.push({rule:We,severity:"error",item:n.id,message:o,fix:d}),r=E(e,n);if(!r)return s(`item "${n.id}" has no qualifying context snapshot (none since its last rework is valid, cites a source and was recorded by human or a registered role that did not work on it)`,`have an independent role or a human verify the context and ${oe}`),t;let i=`context snapshot "${r.snapshot}" of "${n.id}"`;r.stale.length&&s(`${i} is stale: ${r.stale.join(", ")} changed since`,`re-verify the claims and ${oe}`);let u=r.assumptions.filter(o=>o.required).filter(o=>!o.source).map(o=>o.claim);return u.length&&s(`${i} has unverified required assumption(s): ${u.join(" | ")}`,`cite a source { path, hash } for each and ${oe}`),t}var qe=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function Te(e,n){let t=U(n,"withRiskGate"),s=e.escalateGate;return {...e,escalateGate(r,i,a){let u=ee(r,i,a,t),o=s?.call(e,r,i,a);return !o||!u?o??u:{requires:[...o.requires,...u.requires],evidence:[...o.evidence,...u.evidence],reason:{...o.reason,...u.reason}}}}}var ie="context-grounded",Pe={kind:"custom",id:ie,description:"grounded in a fresh, verified context snapshot"},ae=(e,n)=>chunkOSHBJIYD_cjs.b("invalid-input",`withContextGrounding options: ${e}`,n);function Re(e,n){let t=e[n];return t===void 0&&n==="exit"?[]:(Array.isArray(t)||ae(`${n} must be an array of stage ids`,`e.g. "${n}": ["dev"]`),t.map(s=>(chunkOSHBJIYD_cjs.c(s,`context-grounded ${n} stage id`),s)))}function Le(e,n){qe(n)||ae("must be an object",'pass { "entry": ["dev"] }');let t=n;for(let o of Object.keys(t))o!=="entry"&&o!=="exit"&&ae(`unknown key "${o}"`,"use only: entry, exit");let s=Re(t,"entry"),r=Re(t,"exit"),{customPolicy:i,briefContext:a}=e,u=(o,d)=>d&&!o.some(c=>c.kind==="custom"&&c.id===ie)?[...o,Pe]:o;return {...e,defaultStages(o){let d=e.defaultStages(o);for(let c of [...s,...r])d.some(l=>l.id===c)||chunkOSHBJIYD_cjs.b("invalid-input",`withContextGrounding: unknown stage "${c}"`,`stages: ${d.map(l=>l.id).join(", ")}`);return d.map(c=>({...c,entryPolicy:u(c.entryPolicy,s.includes(c.id)),exitPolicy:u(c.exitPolicy,r.includes(c.id))}))},customPolicy(o,d,c){return c.id===ie?re(o,d):i?.call(e,o,d,c)},briefContext(o,d){return E(o,d)??a?.call(e,o,d)}}}var ce=["revision","paths","by","now"],Ve=["in_progress","review","awaiting_human"],N=(e,n)=>chunkOSHBJIYD_cjs.b("invalid-input",`repo change: ${e}`,n);function De(e,n,t){(typeof t!="object"||t===null||Array.isArray(t))&&N("input must be an object",`pass { ${ce.join(", ")} }`);for(let c of Object.keys(t))ce.includes(c)||N(`unknown key "${c}"`,`use only: ${ce.join(", ")}`);let{revision:s,paths:r,by:i,now:a}=t;(typeof s!="string"||s.trim()==="")&&N("revision must be a non-empty string",'e.g. "revision": "4f2c1e0"'),(!Array.isArray(r)||r.length===0)&&N("paths must be a non-empty array of paths",'e.g. "paths": ["src/cart.ts"]'),r.forEach((c,l)=>{let m=se(c);m&&N(`paths[${l}] ${m}`,'send paths as `git diff --name-only -z` lists them (NUL-separated, unquoted; or with `-c core.quotePath=false`), e.g. "src/cart.ts"');}),(typeof i!="string"||i==="")&&N("by must name the reporter",'e.g. "by": "ci"'),a!==void 0&&typeof a!="string"&&N("now must be an ISO timestamp string","omit now to use the clock");let u=[...new Set(r)],o=chunkMU26QW32_cjs.W(e,n,{type:"repo.change",by:i,payload:{revision:s,paths:u}},c=>chunkMU26QW32_cjs.c(c,"repo.changed",i,{revision:s,paths:u},chunkMU26QW32_cjs.a(a))),d=[];for(let c of Object.values(o.state.items)){if(!Ve.includes(c.status))continue;let l=E(e,c);if(!l)continue;let m=new Set(l.assumptions.map(h=>h.source?.path)),f=new Set(l.stale),g=u.filter(h=>m.has(h)&&!f.has(h));g.length&&d.push({rule:"context-stale",severity:"warning",item:c.id,message:`context snapshot "${l.snapshot}" of "${c.id}" is stale: ${g.join(", ")} changed at ${s}`,fix:`re-verify and record a fresh snapshot of "${c.id}" with recordContextSnapshot`});}return {state:o.state,warnings:[...o.warnings,...d]}}var Ae=["baseline","mustPass","passTolerance","costTolerance"],Ke=["tokens","durationMs","turns","humanInterventions","reworks","escalations","itemsDone"],k=(e,n)=>chunkOSHBJIYD_cjs.b("invalid-input",`compareRuns: ${e}`,n),$=e=>typeof e=="string"?JSON.stringify(e):typeof e=="object"&&e!==null?Array.isArray(e)?"an array":"an object":typeof e=="function"||typeof e=="symbol"?typeof e:String(e),G=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),x=(e,n)=>Object.hasOwn(e,n)?e[n]:void 0,fe=(e,n)=>Number.isFinite(e)?e:k(`${n} is not finite (${e})`,"pass the host's measured usage figures"),Y=(e,n)=>(typeof e!="string"&&k(`${n} is ${$(e)}, not an id`,'pass a string id such as "V0"'),chunkOSHBJIYD_cjs.c(e,n),e),Se=(e,n)=>e===void 0?0:((typeof e!="number"||!Number.isFinite(e)||e<0||e>1)&&k(`${n} is ${$(e)}, not a fraction in [0, 1]`,`pass e.g. "${n}": 0.05`),e);function _e(e,n){if(!G(e))return k(`${n}.state is ${$(e)}, not a workflow state`,"pass the finished state.json");let[t,s,r]=["events","accounting","items"].map(a=>x(e,a));if(!Array.isArray(t)||!Array.isArray(s))return k(`${n}.state has no events and accounting arrays`,"pass a WorkflowState as loaded by loadState");if(!G(r))return k(`${n}.state.items is ${$(r)}, not an object`,"pass a WorkflowState as loaded by loadState");let i={tokens:0,durationMs:0,turns:s.length,humanInterventions:0,reworks:0,escalations:0,itemsDone:0};s.forEach((a,u)=>{if(!G(a))return k(`${n}.state.accounting[${u}] is ${$(a)}`,"pass accounting lines as recorded by complete");for(let o of ["tokensIn","tokensOut","durationMs"]){let d=x(a,o);(typeof d!="number"||!Number.isFinite(d)||d<0)&&k(`${n}.state.accounting[${u}].${o} is ${$(d)}, not a finite non-negative number`,"pass the host's measured usage figures");}i.tokens+=a.tokensIn+a.tokensOut,i.durationMs+=a.durationMs;}),fe(i.tokens,`${n}.state token total`),fe(i.durationMs,`${n}.state duration total`),t.forEach((a,u)=>{if(!G(a)||typeof x(a,"type")!="string")return k(`${n}.state.events[${u}] is ${$(a)}, not an event`,"pass events as recorded by the engine");let o=a.type;o==="pending.raised"||o==="blocker.cleared"?i.humanInterventions++:o==="item.rework"?i.reworks++:o==="item.escalated"&&i.escalations++;});for(let a of Object.values(r))G(a)&&x(a,"status")==="done"&&i.itemsDone++;return i}var Oe=e=>e.sort((n,t)=>n-t).reduce((n,t)=>n+t,0)/e.length,ue=(e,n)=>e<n?-1:e>n?1:0;function Fe(e,n){if(Array.isArray(e)||k(`runs is ${$(e)}, not an array`,"pass an array of { variant, scenario, state, passed }"),e.length===0&&k("no runs to compare","pass at least the baseline's finished runs"),!G(n))return k(`options is ${$(n)}, not an object`,'pass { baseline: "V0" }');for(let p of Object.keys(n))Ae.includes(p)||k(`unknown option "${p}"`,`use only: ${Ae.join(", ")}`);let t=n,s=Y(x(t,"baseline"),"baseline"),r=x(t,"mustPass");r!==void 0&&!Array.isArray(r)&&k(`mustPass is ${$(r)}, not an array`,'pass e.g. "mustPass": ["s1"]');let i=[...new Set((r??[]).map(p=>Y(p,"mustPass scenario")))],a=Se(x(t,"passTolerance"),"passTolerance"),u=Se(x(t,"costTolerance"),"costTolerance"),o=new Map,d=new Set;e.forEach((p,y)=>{let R=`runs[${y}]`;if(!G(p))return k(`${R} is ${$(p)}, not a run record`,"pass { variant, scenario, state, passed }");let M=Y(x(p,"variant"),`${R}.variant`),O=Y(x(p,"scenario"),`${R}.scenario`),b=x(p,"passed");typeof b!="boolean"&&k(`${R}.passed is ${$(b)}, not a boolean`,"pass the scorer's verdict as true or false");let w=_e(x(p,"state"),R),A=o.get(M);A||o.set(M,A={metrics:[],passed:0,ran:new Map,failed:new Set}),A.metrics.push(w);let H=A.ran.get(O)??[0,0];A.ran.set(O,H),H[1]++,d.add(O),b?(A.passed++,H[0]++):A.failed.add(O);});let c=o.get(s);c||k(`baseline "${s}" has no run`,"name a variant that appears in runs");for(let p of i)d.has(p)||k(`mustPass scenario "${p}" has no run`,"name a scenario that appears in runs");let l=[...new Set([...c.ran.keys(),...i])].sort(ue),m=[...o].map(([p,y])=>{let R=y.metrics.length,M={};for(let w of Ke)M[w]=fe(Oe(y.metrics.map(A=>A[w])),`variant ${p} mean ${w}`);let O=i.filter(w=>y.failed.has(w)).sort(ue),b=l.filter(w=>!y.ran.has(w));return {variant:p,runs:R,passed:y.passed,passRate:Oe([...y.ran.values()].map(([w,A])=>w/A)),mean:M,regressions:O,missing:b,eligible:O.length===0&&b.length===0}});m.sort((p,y)=>Number(y.eligible)-Number(p.eligible)||y.passRate-p.passRate||p.mean.tokens-y.mean.tokens||p.mean.durationMs-y.mean.durationMs||p.mean.humanInterventions-y.mean.humanInterventions||ue(p.variant,y.variant));let f=m.find(p=>p.variant===s),g=m.find(p=>p.variant!==s&&p.eligible&&p.passRate>=f.passRate-a&&(p.passRate>f.passRate+a||p.mean.tokens<f.mean.tokens*(1-u)));if(g)return {baseline:s,variants:m,winner:g.variant,reason:`${g.variant} beats baseline ${s}: pass rate ${g.passRate} vs ${f.passRate}, mean tokens ${g.mean.tokens} vs ${f.mean.tokens}`};let h=m.filter(p=>p.variant!==s),I;if(h.length===0)I=`no variant to compare with baseline ${s}`;else if(h.some(p=>p.eligible))I=`within noise: no eligible variant beats baseline ${s} beyond the tolerances`;else {let p=h.map(y=>`${y.variant} (${(y.regressions.length?y.regressions:y.missing).join(", ")})`).join("; ");I=`${h.some(y=>y.regressions.length)?"must-pass regression":"no eligible variant, missing runs"}: ${p}`;}return {baseline:s,variants:m,winner:null,reason:I}}exports.DEFAULT_RISK_TABLE=we;exports.compareRuns=Fe;exports.contextGroundedViolations=re;exports.contextOf=E;exports.recordContextSnapshot=Ge;exports.recordRepoChange=De;exports.recordRiskAssessment=Me;exports.riskEscalation=ee;exports.withContextGrounding=Le;exports.withRiskGate=Te;//# sourceMappingURL=index.cjs.map
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/common/event-index.ts","../../src/common/workers.ts","../../src/common/risk/options.ts","../../src/common/risk/escalation.ts","../../src/common/risk/assessment.ts","../../src/common/context/snapshot.ts","../../src/common/context/policy.ts","../../src/interface/policies.ts","../../src/common/context/repo-change.ts","../../src/common/compare-runs.ts"],"names":["cache","push","m","k","v","list","build","events","index","i","ev","p","paths","j","eventIndex","state","n","hit","firstAfter","xs","at","lo","hi","mid","sinceRework","id","positions","rw","x","workersOf","item","all","after","ts","out","t","w","authorOf","RISK_LEVELS","deepFreeze","isObj","own","o","validated","riskOptions","options","who","bad","what","fix","fail","closed","keys","requirement","q","c","gs","gates","g","assertId","raw","table","below","level","row","rq","requires","evidence","here","missing","DEFAULT_RISK_TABLE","isRiskData","data","f","assessorIssue","by","workers","canDo","independenceConflicts","riskEscalation","gate","opts","why","pick","e","freshEvidence","issue","l","resolved","KEYS","recordRiskAssessment","methodology","input","factors","ref","subject","now","getItem","rolesWith","r","applyAction","s","addEvidence","nonEmpty","extra","hidden","repoPathIssue","path","ch","seg","snapshotIssue","a","ka","src","ks","pathIssue","recorderIssue","sourced","d","copyOf","source","rest","contextOf","fresh","pos","hits","b","h","recordContextSnapshot","revision","assumptions","copy","RULE","RECORD","contextGroundedViolations","message","ctx","of","unverified","withRiskGate","inner","prior","GROUNDED","groundedPolicy","badGrounding","stageIds","key","ids","withContextGrounding","entry","exit","customPolicy","briefContext","add","on","config","stages","st","policy","IN_FLIGHT","recordRepoChange","changed","res","appendEvent","nowOf","warnings","cited","was","OPTION_KEYS","METRICS","show","isObject","finite","idOf","tolerance","metricsOf","where","accounting","items","line","it","meanOf","byId","compareRuns","runs","baseline","must","mustPass","passTol","costTol","groups","named","variant","scenario","passed","metrics","tally","base","required","results","mean","regressions","win","others","reason"],"mappings":"6NAuBA,IAAMA,EAAAA,CAAQ,IAAI,OAAA,CAElB,SAASC,CAAAA,CAAWC,CAAAA,CAAgBC,CAAAA,CAAMC,CAAAA,CAAY,CACpD,IAAMC,CAAAA,CAAOH,CAAAA,CAAE,GAAA,CAAIC,CAAC,CAAA,CAChBE,CAAAA,CAAMA,CAAAA,CAAK,IAAA,CAAKD,CAAC,CAAA,CAChBF,CAAAA,CAAE,GAAA,CAAIC,CAAAA,CAAG,CAACC,CAAC,CAAC,EACnB,CAEA,SAASE,EAAAA,CAAMC,CAAAA,CAAqD,CAClE,IAAMC,CAAAA,CAAoB,CACxB,QAAA,CAAU,IAAI,GAAA,CACd,WAAA,CAAa,IAAI,GAAA,CACjB,MAAA,CAAQ,IAAI,GAAA,CACZ,OAAA,CAAS,IAAI,GACf,CAAA,CACA,IAAA,IAASC,CAAAA,CAAI,CAAA,CAAGA,CAAAA,CAAIF,CAAAA,CAAO,MAAA,CAAQE,CAAAA,EAAAA,CAAK,CACtC,IAAMC,CAAAA,CAAKH,CAAAA,CAAOE,CAAC,CAAA,CACbE,CAAAA,CAAID,CAAAA,CAAG,OAAA,CACb,GAAIA,CAAAA,CAAG,IAAA,GAAS,eAAA,CAAiBT,CAAAA,CAAKO,CAAAA,CAAM,QAAA,CAAUG,CAAAA,EAAG,EAAA,CAAIF,CAAC,UACrDC,CAAAA,CAAG,IAAA,GAAS,iBAAA,EAAqBC,CAAAA,EAAG,UAAA,CAAYV,CAAAA,CAAKO,CAAAA,CAAM,WAAA,CAAaG,CAAAA,EAAG,EAAA,CAAIF,CAAC,CAAA,CAAA,KAAA,GAChFC,CAAAA,CAAG,IAAA,GAAS,cAAeF,CAAAA,CAAM,MAAA,CAAO,GAAA,CAAIG,CAAAA,EAAG,EAAA,CAAIF,CAAC,CAAA,CAAA,KAAA,GACpDC,CAAAA,C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CAAAA,EAAMA,CAAAA,CAAE,OAAA,GAAYqL,CAAQ,CAAA,CACvDmB,CAAAA,CACJ,GAAID,CAAAA,CAAO,MAAA,GAAW,CAAA,CAAGC,CAAAA,CAAS,CAAA,oCAAA,EAAuCnB,CAAQ,CAAA,CAAA,CAAA,KAAA,GACxEkB,EAAO,IAAA,CAAMvM,CAAAA,EAAMA,CAAAA,CAAE,QAAQ,CAAA,CACpCwM,CAAAA,CAAS,CAAA,iDAAA,EAAoDnB,CAAQ,CAAA,sBAAA,CAAA,CAAA,KAClE,CACH,IAAMvG,CAAAA,CAAMyH,CAAAA,CACT,GAAA,CAAKvM,CAAAA,EAAM,CAAA,EAAGA,CAAAA,CAAE,OAAO,CAAA,EAAA,EAAA,CAAMA,CAAAA,CAAE,WAAA,CAAY,MAAA,CAASA,CAAAA,CAAE,WAAA,CAAcA,CAAAA,CAAE,OAAA,EAAS,IAAA,CAAK,IAAI,CAAC,CAAA,CAAA,CAAG,EAC5F,IAAA,CAAK,IAAI,CAAA,CACZwM,CAAAA,CAAS,CAAA,EAAGD,CAAAA,CAAO,IAAA,CAAMvM,CAAAA,EAAMA,CAAAA,CAAE,WAAA,CAAY,MAAM,CAAA,CAAI,sBAAA,CAAyB,mCAAmC,CAAA,EAAA,EAAK8E,CAAG,CAAA,EAC7H,CACA,OAAO,CAAE,QAAA,CAAAuG,CAAAA,CAAU,QAAA,CAAUc,CAAAA,CAAS,MAAA,CAAQ,IAAA,CAAM,MAAA,CAAAK,CAAO,CAC7D","file":"index.cjs","sourcesContent":["// A per-log index of the events the 1.3 policies read (design spec section 27, F1 G3-2..G3-5):\n// built in one pass over `state.events` and cached per events array, so reading the context or the\n// workers of many items of one state costs one pass, not one per item. Pure and deterministic: the\n// cache only avoids recomputing what the same array gives; an array changed in place (its length or\n// its last event differs) is indexed again.\nimport type { WorkflowState } from \"../core/types.ts\";\n\nexport interface EventIndex {\n /** Item id -> positions of its `item.evidence` events, ascending. */\n evidence: Map<unknown, number[]>;\n /**\n * Item id -> positions of the events that appended a transition to the item, ascending: its\n * `item.transition` events and the `blocker.raised` / `blocker.cleared` events whose payload\n * carries a non-null `transition` (spec 27, F2 G5-1). `workersOf` uses them only when they are\n * exactly as many as `item.transitions`.\n */\n transitions: Map<unknown, number[]>;\n /** Item id -> position of its last `item.rework` event. */\n rework: Map<unknown, number>;\n /** Path -> `[position, index in the event's paths]` of each listing in a `repo.changed`, ascending. */\n changed: Map<string, [number, number][]>;\n}\n\nconst cache = new WeakMap<object, { n: number; last: unknown; index: EventIndex }>();\n\nfunction push<K, V>(m: Map<K, V[]>, k: K, v: V): void {\n const list = m.get(k);\n if (list) list.push(v);\n else m.set(k, [v]);\n}\n\nfunction build(events: WorkflowState<string>[\"events\"]): EventIndex {\n const index: EventIndex = {\n evidence: new Map(),\n transitions: new Map(),\n rework: new Map(),\n changed: new Map(),\n };\n for (let i = 0; i < events.length; i++) {\n const ev = events[i]!;\n const p = ev.payload as { id?: unknown; paths?: unknown; transition?: unknown } | null;\n if (ev.type === \"item.evidence\") push(index.evidence, p?.id, i);\n else if (ev.type === \"item.transition\" || p?.transition) push(index.transitions, p?.id, i);\n else if (ev.type === \"item.rework\") index.rework.set(p?.id, i);\n else if (ev.type === \"repo.changed\" && Array.isArray(p?.paths)) {\n // a path listed twice in one event keeps both entries; readers take the first after a position\n const paths: unknown[] = p.paths;\n for (let j = 0; j < paths.length; j++)\n if (typeof paths[j] === \"string\") push(index.changed, paths[j] as string, [i, j]);\n }\n }\n return index;\n}\n\n/** The index of `state.events`, built once per events array. */\nexport function eventIndex(state: WorkflowState<string>): EventIndex {\n const events = state.events;\n const n = events.length;\n const hit = cache.get(events);\n if (hit && hit.n === n && hit.last === events[n - 1]) return hit.index;\n const index = build(events);\n cache.set(events, { n, last: events[n - 1], index });\n return index;\n}\n\n/** The first index `k` of the ascending `xs` with `at(xs[k]) > p`, or `xs.length`. */\nexport function firstAfter<T>(xs: readonly T[], p: number, at: (x: T) => number): number {\n let lo = 0;\n let hi = xs.length;\n while (lo < hi) {\n const mid = (lo + hi) >> 1;\n if (at(xs[mid]!) > p) hi = mid;\n else lo = mid + 1;\n }\n return lo;\n}\n\n/**\n * How many of the item's events listed in `positions` (ascending) follow its last `item.rework`\n * event, or `undefined` when it was never reworked: the count `freshEvidence` derives by scanning.\n */\nexport function sinceRework(\n index: EventIndex,\n id: string,\n positions: readonly number[] | undefined,\n): number | undefined {\n const rw = index.rework.get(id);\n if (rw === undefined) return undefined;\n const list = positions ?? [];\n return list.length - firstAfter(list, rw, (x) => x);\n}\n","// Who worked on an item (design spec section 27, F1 G1-1): the independence checks of the\n// risk-adaptive gate and the context-grounded policy compare an assessor or a snapshot's recorder\n// against every one of them, not only the last author.\nimport { authorOf } from \"../core/gates.ts\";\nimport type { WorkItem, WorkflowState } from \"../core/types.ts\";\nimport { eventIndex, sinceRework } from \"./event-index.ts\";\n\n/**\n * The roles that worked on `item`: the `by` of each dispatch (a transition into `in_progress`)\n * since the item's last `item.rework` event (or since creation), in order, then its assigned\n * `role` and its author by the 1.3 rule (`authorOf`), each once. The rework boundary is found by\n * matching `item.transitions` to the events that appended them (`item.transition`, and the\n * `blocker.*` events that carry a `transition`) from the end; when those events are not exactly as\n * many as the transitions, every transition counts (fail closed: more workers, never fewer).\n */\nexport function workersOf(state: WorkflowState<string>, item: WorkItem): string[] {\n const index = eventIndex(state);\n const at = index.transitions.get(item.id) ?? [];\n const all = item.transitions;\n const after = sinceRework(index, item.id, at);\n const ts = after === undefined || at.length !== all.length ? all : all.slice(all.length - after);\n const out = new Set<string>();\n for (const t of ts) if (t.to.status === \"in_progress\") out.add(t.by);\n for (const w of [item.role, authorOf(state, item)]) if (w !== undefined) out.add(w);\n return [...out];\n}\n","// Validation of the risk-adaptive gate options (design spec section 27, #35; F1 G1-4, G1-6): one\n// validator for `withRiskGate` (once, at wrap time) and `riskEscalation` (per call, unless given the\n// frozen options the validator itself returned), so both refuse the same input with invalid-input.\nimport { assertId, fail } from \"../../core/errors.ts\";\nimport type { GateRequirement } from \"../../core/types.ts\";\nimport { deepFreeze } from \"../deep-freeze.ts\";\nimport type { RiskGateOptions, RiskLevel, RiskTable } from \"./escalation.ts\";\n\n/** The levels, least strict first. */\nexport const RISK_LEVELS: readonly RiskLevel[] = /* @__PURE__ */ deepFreeze([\n \"low\",\n \"medium\",\n \"high\",\n \"critical\",\n]);\n\nconst isObj = (x: unknown): x is Record<string, unknown> =>\n typeof x === \"object\" && x !== null && !Array.isArray(x);\n/** `o[k]` only when `o` has it as an own property (G5-5, as `compareRuns` reads its input). */\nconst own = (o: Record<string, unknown>, k: string): unknown =>\n Object.hasOwn(o, k) ? o[k] : undefined;\nconst validated = new WeakSet<object>();\n\n/**\n * `options` validated and copied (deeply frozen), so later changes by the caller do not leak in.\n * Refuses `invalid-input`, prefixed with `who`, for: a non-object or an unknown key; `gates` not an\n * array of valid ids; a `table` that is not an object keyed by exactly the four levels, a row with\n * an unknown key, a requirement that is neither `\"human\"` nor `{ capability: <non-empty string> }`,\n * an evidence kind that is not a non-empty string; and a row that does not include every\n * requirement and evidence kind of the level below it (a stricter level only adds, G1-4).\n * Every key is read as an own property: an inherited one counts as absent (G5-5).\n */\nexport function riskOptions(options: unknown, who: string): Required<RiskGateOptions> {\n if (typeof options === \"object\" && options !== null && validated.has(options))\n return options as Required<RiskGateOptions>;\n const bad = (what: string, fix: string): never =>\n fail(\"invalid-input\", `${who} options: ${what}`, fix);\n const closed = (o: Record<string, unknown>, keys: readonly string[], at: string): void => {\n for (const k of Object.keys(o))\n if (!keys.includes(k)) bad(`unknown key \"${k}\" in ${at}`, `use only: ${keys.join(\", \")}`);\n };\n const requirement = (q: unknown, at: string): GateRequirement => {\n if (q === \"human\") return q;\n const c = isObj(q) ? own(q, \"capability\") : undefined;\n if (typeof c !== \"string\" || c.trim() === \"\" || Object.keys(q as object).length !== 1)\n bad(\n `${at} must be \"human\" or { capability: <name> }`,\n 'e.g. [\"human\"] or [{ \"capability\": \"review\" }]',\n );\n return { capability: c as string };\n };\n if (!isObj(options)) bad(\"must be an object\", 'pass { \"gates\": [\"code-review\"] }');\n const o = options as Record<string, unknown>;\n closed(o, [\"gates\", \"table\"], \"options\");\n const gs = own(o, \"gates\");\n if (!Array.isArray(gs))\n bad(\"gates must be an array of gate ids\", 'e.g. \"gates\": [\"code-review\"]');\n const gates = (gs as unknown[]).map((g) => {\n assertId(g, \"risk gate id\");\n return g as string;\n });\n const raw = own(o, \"table\");\n let table: RiskTable | undefined;\n if (raw !== undefined) {\n if (!isObj(raw))\n bad(\"table must be an object keyed by risk level\", `levels: ${RISK_LEVELS.join(\", \")}`);\n const t = raw as Record<string, unknown>;\n closed(t, RISK_LEVELS, \"table\");\n table = {} as RiskTable;\n let below: string[] = [];\n for (const level of RISK_LEVELS) {\n const row = own(t, level);\n if (!isObj(row))\n bad(\n `table is missing level \"${level}\"`,\n `give every level a row, e.g. \"${level}\": { \"requires\": [] }`,\n );\n const rw = row as Record<string, unknown>;\n closed(rw, [\"requires\", \"evidence\"], `table.${level}`);\n const rq = own(rw, \"requires\");\n if (!Array.isArray(rq))\n bad(`table.${level}.requires must be an array`, 'e.g. \"requires\": [\"human\"]');\n const ev = own(rw, \"evidence\");\n if (\n ev !== undefined &&\n (!Array.isArray(ev) || !ev.every((k) => typeof k === \"string\" && k.trim() !== \"\"))\n )\n bad(\n `table.${level}.evidence must be an array of evidence kinds`,\n 'e.g. \"evidence\": [\"sbom\"]',\n );\n const requires = (rq as unknown[]).map((q, i) =>\n requirement(q, `table.${level}.requires[${i}]`),\n );\n const evidence = ev === undefined ? undefined : [...(ev as string[])];\n // each level includes everything the level below it adds; requirements and evidence kinds\n // are separate sets (G5-4: evidence \"human\" is not the requirement \"human\")\n const here = [\n ...requires.map((x) => JSON.stringify(x)),\n ...(evidence ?? []).map((k) => `evidence ${JSON.stringify(k)}`),\n ];\n const missing = below.filter((x) => !here.includes(x));\n if (missing.length)\n bad(\n `table.${level} must include everything the level below it adds (missing ${missing.join(\", \")})`,\n \"a stricter level only adds: copy the lower level's requires and evidence into it\",\n );\n below = here;\n table[level] = { requires, ...(evidence === undefined ? {} : { evidence }) };\n }\n }\n const out = deepFreeze(table ? { gates, table } : ({ gates } as Required<RiskGateOptions>));\n validated.add(out);\n return out;\n}\n","// Risk-adaptive gate (design spec section 27, #35): the level of the strictest fresh, valid and\n// independent `risk-assessment` evidence picks a row of a table of what the gate additionally needs.\nimport { canDo } from \"../../core/roles/guards.ts\";\nimport { freshEvidence } from \"../../core/items/evidence.ts\";\nimport type {\n Evidence,\n Gate,\n GateEscalation,\n GateRequirement,\n WorkItem,\n WorkflowState,\n} from \"../../core/types.ts\";\nimport { deepFreeze } from \"../deep-freeze.ts\";\nimport { independenceConflicts } from \"../independence.ts\";\nimport { workersOf } from \"../workers.ts\";\nimport { RISK_LEVELS, riskOptions } from \"./options.ts\";\n\nexport type RiskLevel = \"low\" | \"medium\" | \"high\" | \"critical\";\n/** `data` of a `risk-assessment` evidence entry. */\nexport interface RiskAssessmentData {\n level: RiskLevel;\n /** Free strings naming what drives the risk, e.g. `ci-cd`, `prod-infra`, `secrets`, `blast-radius`, `irreversible`. */\n factors: string[];\n /** The item SHA or ref that was assessed. */\n subject?: string;\n}\n/** What each level ADDS to the static gate. */\nexport type RiskTable = Record<RiskLevel, { requires: GateRequirement[]; evidence?: string[] }>;\nexport interface RiskGateOptions {\n /** Ids of the gates the policy applies to; every other gate stays static. */\n gates: string[];\n /** Default `DEFAULT_RISK_TABLE`. */\n table?: RiskTable;\n}\n\nexport { RISK_LEVELS };\n\n/** `low` and `medium` add nothing; `high` and `critical` add a human approval. Deeply frozen. */\nexport const DEFAULT_RISK_TABLE: RiskTable = /* @__PURE__ */ deepFreeze({\n low: { requires: [] },\n medium: { requires: [] },\n high: { requires: [\"human\"] },\n critical: { requires: [\"human\"] },\n});\n\nconst isObj = (x: unknown): x is Record<string, unknown> =>\n typeof x === \"object\" && x !== null && !Array.isArray(x);\n\n/** True when `data` is a well-formed `RiskAssessmentData`. */\nexport function isRiskData(data: unknown): data is RiskAssessmentData {\n return (\n isObj(data) &&\n RISK_LEVELS.includes(data[\"level\"] as RiskLevel) &&\n Array.isArray(data[\"factors\"]) &&\n data[\"factors\"].every((f) => typeof f === \"string\") &&\n (data[\"subject\"] === undefined || typeof data[\"subject\"] === \"string\")\n );\n}\n\n/**\n * Why `by` may not assess `item`: `invalid` when it is neither `human` nor a role with capability\n * `verify`, `not-independent` when it worked on the item (`workersOf`: every role that dispatched\n * it since its last rework, its assigned role, its author); `undefined` when it may. `workers`\n * defaults to `workersOf(state, item)`; pass it to check several assessors against one state.\n */\nexport function assessorIssue(\n state: WorkflowState<string>,\n item: WorkItem,\n by: string,\n workers: readonly string[] = workersOf(state, item),\n): \"invalid\" | \"not-independent\" | undefined {\n if (!canDo(state, by, \"verify\")) return \"invalid\";\n return independenceConflicts(by, workers).length ? \"not-independent\" : undefined;\n}\n\n/**\n * The escalation of `gate` for `item` under `options` (the `escalateGate` hook `withRiskGate`\n * installs): `undefined` for a gate not in `options.gates`, else the table row of the resolved\n * level. The resolved level is the strictest fresh (post-rework) valid assessment, so a later,\n * lower assessment never relaxes an earlier one; with none it is `critical`, and `reason.why` says\n * whether assessments were `missing`, `invalid` or `not-independent` (the latest rejected one).\n * Invalid options fail `invalid-input` as in `withRiskGate`, never a `TypeError`. Pure: no clock,\n * no randomness; the same state gives the same answer.\n */\nexport function riskEscalation(\n state: WorkflowState<string>,\n item: WorkItem,\n gate: Gate,\n options: RiskGateOptions,\n): GateEscalation | undefined {\n // validated here unless these are the frozen options withRiskGate validated (G1-6)\n const opts = riskOptions(options, \"riskEscalation\");\n if (!opts.gates.includes(gate.id)) return undefined;\n let level: RiskLevel | undefined;\n let why = \"missing\";\n let pick: Evidence | undefined;\n let workers: string[] | undefined;\n for (const e of freshEvidence(state, item)) {\n if (e.kind !== \"risk-assessment\") continue;\n const issue = isRiskData(e.data)\n ? assessorIssue(state, item, e.by, (workers ??= workersOf(state, item)))\n : \"invalid\";\n if (issue) {\n if (!level) {\n why = issue;\n pick = e;\n }\n continue;\n }\n const l = (e.data as unknown as RiskAssessmentData).level;\n if (!level || RISK_LEVELS.indexOf(l) >= RISK_LEVELS.indexOf(level)) {\n level = l;\n why = \"assessed\";\n pick = e;\n }\n }\n const resolved = level ?? \"critical\";\n const row = (opts.table ?? DEFAULT_RISK_TABLE)[resolved];\n return {\n requires: row.requires.map((q) => (q === \"human\" ? q : { capability: q.capability })),\n evidence: [...(row.evidence ?? [])],\n reason: { level: resolved, why, assessment: pick?.ref ?? null, by: pick?.by ?? null },\n };\n}\n","import { fail } from \"../../core/errors.ts\";\nimport { addEvidence } from \"../../core/items/evidence.ts\";\nimport { getItem } from \"../../core/items/record.ts\";\nimport { applyAction } from \"../../core/methodology.ts\";\nimport { rolesWith } from \"../../core/roles/lookup.ts\";\nimport type { ApplyResult, Methodology, WorkflowState } from \"../../core/types.ts\";\nimport { assessorIssue, type RiskLevel } from \"./escalation.ts\";\nimport { RISK_LEVELS } from \"./options.ts\";\n\nexport interface RiskAssessmentInput {\n item: string;\n level: RiskLevel;\n factors: string[];\n /** The host's assessment artifact. */\n ref: string;\n /** The item SHA or ref that was assessed. */\n subject?: string;\n /** The assessor: `human` or a role with capability `verify` that did not do the work. */\n by: string;\n now?: string;\n}\n\nconst KEYS = [\"item\", \"level\", \"factors\", \"ref\", \"subject\", \"by\", \"now\"];\nconst bad = (what: string, fix: string): never =>\n fail(\"invalid-input\", `risk assessment: ${what}`, fix);\n\n/**\n * Records a risk assessment of an item as evidence `risk-assessment` with `data: { level, factors,\n * subject? }` (design spec section 27, #35), through `applyAction` (action `risk.assess`) so the\n * methodology's rules see it. Refuses `invalid-input` for an unknown key, an unknown level, a\n * non-string factor, an empty ref, an assessor that is neither `human` nor a role with `verify`, and\n * an assessor that is the item's author or assigned role.\n */\nexport function recordRiskAssessment<N extends string>(\n state: WorkflowState<N>,\n methodology: Methodology<unknown, N>,\n input: RiskAssessmentInput,\n): ApplyResult<N> {\n if (typeof input !== \"object\" || input === null || Array.isArray(input))\n bad(\"input must be an object\", `pass { ${KEYS.join(\", \")} }`);\n for (const k of Object.keys(input))\n if (!KEYS.includes(k)) bad(`unknown key \"${k}\"`, `use only: ${KEYS.join(\", \")}`);\n const { item: id, level, factors, ref, subject, by, now } = input;\n if (typeof id !== \"string\") bad(\"item must be an item id\", 'e.g. \"item\": \"CART-12\"');\n const item = getItem(state, id);\n if (!RISK_LEVELS.includes(level))\n bad(`unknown level ${JSON.stringify(level)}`, `use one of: ${RISK_LEVELS.join(\", \")}`);\n if (!Array.isArray(factors) || !factors.every((f) => typeof f === \"string\"))\n bad(\"factors must be an array of strings\", 'e.g. \"factors\": [\"ci-cd\", \"secrets\"]');\n if (typeof ref !== \"string\" || ref.trim() === \"\")\n bad(\"ref must be a non-empty string\", 'name the assessment artifact, e.g. \"risk/CART-12.md\"');\n if (subject !== undefined && typeof subject !== \"string\")\n bad(\"subject must be a string\", \"pass the assessed SHA or ref, or omit it\");\n if (now !== undefined && typeof now !== \"string\")\n bad(\"now must be an ISO timestamp string\", \"omit now to use the clock\");\n if (typeof by !== \"string\" || by === \"\") bad(\"by must name the assessor\", 'e.g. \"by\": \"human\"');\n const issue = assessorIssue(state, item, by);\n if (issue === \"invalid\")\n bad(\n `\"${by}\" may not assess risk (needs capability \"verify\")`,\n `assess as human or one of: ${\n rolesWith(state, \"verify\")\n .map((r) => r.id)\n .join(\", \") || \"(no role has verify; register one)\"\n }`,\n );\n if (issue)\n bad(\n `\"${by}\" did the work on \"${id}\" and may not assess its risk`,\n \"assess as human or an independent role with capability verify\",\n );\n const data: Record<string, unknown> = { level, factors: [...factors] };\n if (subject !== undefined) data[\"subject\"] = subject;\n return applyAction(\n state,\n methodology,\n { type: \"risk.assess\", by, payload: { item: id, ref, ...data } },\n (s) => addEvidence(s, id, { kind: \"risk-assessment\", ref, by, data }, now),\n );\n}\n","// Context snapshots (design spec section 27, #36): what a scout verified about the repository\n// before an item is worked, as evidence `context-snapshot`, and whether a later `repo.changed`\n// event made it stale. Event order decides, never timestamps (principle 5); no file is read.\nimport { fail } from \"../../core/errors.ts\";\nimport { addEvidence } from \"../../core/items/evidence.ts\";\nimport { getItem } from \"../../core/items/record.ts\";\nimport { applyAction } from \"../../core/methodology.ts\";\nimport type {\n ApplyResult,\n BriefContext,\n ContextAssumption,\n ContextSnapshotData,\n Methodology,\n WorkItem,\n WorkflowState,\n} from \"../../core/types.ts\";\nimport { eventIndex, firstAfter, sinceRework } from \"../event-index.ts\";\nimport { workersOf } from \"../workers.ts\";\n\nexport interface ContextSnapshotInput {\n item: string;\n /** The repository revision the snapshot was taken at. */\n revision: string;\n assumptions: ContextAssumption[];\n /** The host's snapshot artifact. */\n ref: string;\n /** Who recorded it: `human` or a registered role that did not work on the item. */\n by: string;\n now?: string;\n}\n\nconst isObj = (x: unknown): x is Record<string, unknown> =>\n typeof x === \"object\" && x !== null && !Array.isArray(x);\nconst nonEmpty = (x: unknown): x is string => typeof x === \"string\" && x.trim() !== \"\";\nconst extra = (o: Record<string, unknown>, keys: string[]) =>\n Object.keys(o).find((k) => !keys.includes(k));\n\n/** True for a C0 or C1 control character or a bidirectional formatting character. */\nfunction hidden(c: number): boolean {\n return (\n c < 0x20 ||\n (c >= 0x7f && c <= 0x9f) ||\n c === 0x61c ||\n c === 0x200e ||\n c === 0x200f ||\n (c >= 0x202a && c <= 0x202e) ||\n (c >= 0x2066 && c <= 0x2069)\n );\n}\n\n/**\n * Why `path` is not a repository-relative POSIX path as Git lists it, or `undefined` when it is:\n * no leading `/`, `./` or drive letter, `/` separators only, no empty, `.` or `..` segment, at most\n * 4096 characters, Unicode NFC, no control or bidirectional formatting character and no leading or\n * trailing whitespace (F1 G2-8, G4-4). Paths are compared exactly (case included), so the recorders\n * accept one spelling per file.\n */\nexport function repoPathIssue(path: unknown): string | undefined {\n const why =\n typeof path !== \"string\"\n ? \"not a string\"\n : path.length > 4096\n ? \"longer than 4096 characters\"\n : [...path].some((ch) => hidden(ch.codePointAt(0)!))\n ? \"has a control or bidirectional formatting character\"\n : path !== path.trim()\n ? \"has leading or trailing whitespace\"\n : path !== path.normalize(\"NFC\")\n ? \"is not Unicode NFC\"\n : path.includes(\"\\\\\") ||\n /^[A-Za-z]:/.test(path) ||\n !path.split(\"/\").every((seg) => seg !== \"\" && seg !== \".\" && seg !== \"..\")\n ? \"is not relative with / separators and no empty, . or .. segment\"\n : undefined;\n if (!why) return undefined;\n const shown = JSON.stringify(\n typeof path === \"string\" && path.length > 80 ? `${path.slice(0, 80)}…` : path,\n );\n return `${shown} is not a repository-relative POSIX path (${why})`;\n}\n\n/** Why `data` is not a well-formed `ContextSnapshotData` (closed objects), or `undefined`. */\nfunction snapshotIssue(data: unknown): string | undefined {\n if (!isObj(data)) return \"data must be an object\";\n const k = extra(data, [\"revision\", \"assumptions\"]);\n if (k) return `unknown key \"${k}\"`;\n if (!nonEmpty(data[\"revision\"])) return \"revision must be a non-empty string\";\n const list = data[\"assumptions\"];\n if (!Array.isArray(list)) return \"assumptions must be an array\";\n for (const [i, a] of list.entries()) {\n const at = `assumptions[${i}]`;\n if (!isObj(a)) return `${at} must be an object`;\n const ka = extra(a, [\"claim\", \"required\", \"source\"]);\n if (ka) return `unknown key \"${ka}\" in ${at}`;\n if (!nonEmpty(a[\"claim\"])) return `${at}.claim must be a non-empty string`;\n if (a[\"required\"] !== undefined && typeof a[\"required\"] !== \"boolean\")\n return `${at}.required must be a boolean`;\n const src = a[\"source\"];\n if (src === undefined) continue;\n if (!isObj(src)) return `${at}.source must be an object`;\n const ks = extra(src, [\"path\", \"lines\", \"hash\"]);\n if (ks) return `unknown key \"${ks}\" in ${at}.source`;\n const pathIssue = repoPathIssue(src[\"path\"]);\n if (pathIssue) return `${at}.source.path ${pathIssue}`;\n if (!nonEmpty(src[\"hash\"])) return `${at}.source.hash must be a non-empty string`;\n const l = src[\"lines\"];\n if (\n l !== undefined &&\n !(\n Array.isArray(l) &&\n l.length === 2 &&\n Number.isInteger(l[0]) &&\n Number.isInteger(l[1]) &&\n 1 <= l[0] &&\n l[0] <= l[1]\n )\n )\n return `${at}.source.lines must be two integers [from, to] with 1 <= from <= to`;\n }\n return undefined;\n}\n\n/**\n * Why `by` may not ground an item whose workers are `workers` (design spec section 27, F1 G1-2,\n * G2-2): it is neither `human` nor a registered role, or it worked on the item; else `undefined`.\n */\nfunction recorderIssue(\n state: WorkflowState<string>,\n by: unknown,\n workers: readonly string[],\n): string | undefined {\n if (typeof by !== \"string\" || (by !== \"human\" && !Object.hasOwn(state.roles, by)))\n return `${JSON.stringify(by)} is neither human nor a registered role`;\n return workers.includes(by) ? `\"${by}\" worked on the item` : undefined;\n}\nconst sourced = (d: ContextSnapshotData): boolean => d.assumptions.some((a) => a.source);\n/** A copy of a validated assumption (closed object: claim, required, source { path, lines, hash }). */\nconst copyOf = ({ source, ...rest }: ContextAssumption): ContextAssumption =>\n source\n ? {\n ...rest,\n source: {\n ...source,\n ...(source.lines ? { lines: [...source.lines] as [number, number] } : {}),\n },\n }\n : rest;\n\n/**\n * The item's current context (design spec section 27, #36): its latest fresh (post-rework)\n * qualifying `context-snapshot` evidence (valid data with at least one sourced assumption,\n * recorded by `human` or a registered role that did not work on the item, `workersOf`), with\n * `stale` the cited source paths a later `repo.changed` event listed (exact match, in event order)\n * and `unverified` the claims with no source; `undefined` when there is none. The answer is a\n * copy. Each evidence entry is located at its own `item.evidence` event, matched from the end as\n * `freshEvidence` does; an entry with no event counts as older than every event.\n */\nexport function contextOf(state: WorkflowState<string>, item: WorkItem): BriefContext | undefined {\n // one indexed pass over the log per state, not per item (F1 G3-2, G3-3, G3-4)\n const index = eventIndex(state);\n const at = index.evidence.get(item.id) ?? [];\n const all = item.evidence;\n const after = sinceRework(index, item.id, at);\n const fresh = after === undefined ? all.length : Math.min(after, all.length);\n let workers: string[] | undefined;\n for (let k = all.length - 1; k >= all.length - fresh; k--) {\n const e = all[k]!;\n if (e.kind !== \"context-snapshot\" || snapshotIssue(e.data) !== undefined) continue;\n const data = e.data as unknown as ContextSnapshotData;\n // a snapshot that does not qualify is ignored, so it cannot supersede one that does (G2-1)\n if (!sourced(data) || recorderIssue(state, e.by, (workers ??= workersOf(state, item))))\n continue;\n // each cited path's first repo.changed after the snapshot's own event, in event order\n const pos = at[k + at.length - all.length] ?? -1;\n const hits: [number, number, string][] = [];\n for (const path of new Set(data.assumptions.map((a) => a.source?.path))) {\n const list = path === undefined ? undefined : index.changed.get(path);\n const f = list ? firstAfter(list, pos, (x) => x[0]) : 0;\n if (list && f < list.length) hits.push([list[f]![0], list[f]![1], path!]);\n }\n // oxlint-disable-next-line unicorn/no-array-sort -- a fresh local array; toSorted needs Node 20\n hits.sort((a, b) => a[0] - b[0] || a[1] - b[1]);\n return {\n revision: data.revision,\n // copies: a caller (a brief, a host) changing the answer must not change the state (G2-9)\n assumptions: data.assumptions.map(copyOf),\n snapshot: e.ref,\n by: e.by,\n stale: hits.map((h) => h[2]),\n unverified: data.assumptions.filter((a) => !a.source).map((a) => a.claim),\n };\n }\n return undefined;\n}\n\nconst KEYS = [\"item\", \"revision\", \"assumptions\", \"ref\", \"by\", \"now\"];\nconst bad = (what: string, fix: string): never =>\n fail(\"invalid-input\", `context snapshot: ${what}`, fix);\n\n/**\n * Records a context snapshot of an item as evidence `context-snapshot` with `data: { revision,\n * assumptions }` (design spec section 27, #36), through `applyAction` (action `context.snapshot`)\n * so the methodology's rules see it. Refuses `invalid-input` for an unknown key, an empty revision,\n * claim or ref, a source with a path that is not repository-relative POSIX or an empty hash,\n * `lines` that are not two integers `1 <= from <= to`, no assumption with a source, and a `by`\n * that is neither `human` nor a registered role or that worked on the item. The input is copied.\n */\nexport function recordContextSnapshot<N extends string>(\n state: WorkflowState<N>,\n methodology: Methodology<unknown, N>,\n input: ContextSnapshotInput,\n): ApplyResult<N> {\n if (!isObj(input)) bad(\"input must be an object\", `pass { ${KEYS.join(\", \")} }`);\n const k = extra(input as unknown as Record<string, unknown>, KEYS);\n if (k) bad(`unknown key \"${k}\"`, `use only: ${KEYS.join(\", \")}`);\n const { item: id, revision, assumptions, ref, by, now } = input;\n if (typeof id !== \"string\") bad(\"item must be an item id\", 'e.g. \"item\": \"CART-12\"');\n const item = getItem(state, id);\n const data = { revision, assumptions } as unknown as Record<string, unknown>;\n const issue = snapshotIssue(data);\n if (issue)\n bad(\n issue,\n 'e.g. { \"revision\": \"4f2c1e0\", \"assumptions\": [{ \"claim\": \"totals are cents\", \"source\": { \"path\": \"src/cart.ts\", \"hash\": \"…\" } }] }',\n );\n if (!nonEmpty(ref))\n bad(\"ref must be a non-empty string\", 'name the snapshot artifact, e.g. \"ctx/CART-12.json\"');\n if (!nonEmpty(by)) bad(\"by must name who recorded it\", 'e.g. \"by\": \"scout\"');\n const who = recorderIssue(state, by, workersOf(state, item));\n if (who)\n bad(\n `${who} and may not record its context`,\n \"record as human or a registered role that did not work on the item\",\n );\n if (!sourced(data as unknown as ContextSnapshotData))\n bad(\n \"a snapshot needs at least one assumption with a source (nothing was verified)\",\n 'cite what was checked, e.g. \"source\": { \"path\": \"src/cart.ts\", \"hash\": \"…\" }',\n );\n if (now !== undefined && typeof now !== \"string\")\n bad(\"now must be an ISO timestamp string\", \"omit now to use the clock\");\n // validated plain data, copied so no reference to the caller's arrays is kept\n const copy = JSON.parse(JSON.stringify(data)) as Record<string, unknown>;\n return applyAction(\n state,\n methodology,\n { type: \"context.snapshot\", by, payload: { item: id, ref, ...copy } },\n (s) => addEvidence(s, id, { kind: \"context-snapshot\", ref, by, data: copy }, now),\n );\n}\n","// The context-grounded entry policy (design spec section 27, #36): an item may enter a stage only\n// with a fresh, verified context snapshot that a human or a registered role other than its workers\n// recorded (contextOf counts only such a snapshot).\nimport type { Violation, WorkItem, WorkflowState } from \"../../core/types.ts\";\nimport { contextOf } from \"./snapshot.ts\";\n\nconst RULE = \"policy:custom:context-grounded\";\nconst RECORD = \"record a fresh one with recordContextSnapshot\";\n\n/**\n * Violations of the custom policy `context-grounded` for `item` (rule\n * `policy:custom:context-grounded`, the 1.2 rule id of a custom policy): no qualifying fresh\n * context snapshot (`contextOf`: valid, at least one sourced assumption, recorded by `human` or a\n * registered role that did not work on the item); a stale one (names the changed paths); a\n * `required` assumption without a source (names the claims). Empty when the item is grounded.\n * Pure: the same state gives the same answer.\n */\nexport function contextGroundedViolations(\n state: WorkflowState<string>,\n item: WorkItem,\n): Violation[] {\n const out: Violation[] = [];\n const v = (message: string, fix: string) =>\n out.push({ rule: RULE, severity: \"error\", item: item.id, message, fix });\n const ctx = contextOf(state, item);\n if (!ctx) {\n v(\n `item \"${item.id}\" has no qualifying context snapshot (none since its last rework is valid, cites a source and was recorded by human or a registered role that did not work on it)`,\n `have an independent role or a human verify the context and ${RECORD}`,\n );\n return out;\n }\n const of = `context snapshot \"${ctx.snapshot}\" of \"${item.id}\"`;\n if (ctx.stale.length)\n v(\n `${of} is stale: ${ctx.stale.join(\", \")} changed since`,\n `re-verify the claims and ${RECORD}`,\n );\n const required = ctx.assumptions.filter((a) => a.required);\n const unverified = required.filter((a) => !a.source).map((a) => a.claim);\n if (unverified.length)\n v(\n `${of} has unverified required assumption(s): ${unverified.join(\" | \")}`,\n `cite a source { path, hash } for each and ${RECORD}`,\n );\n return out;\n}\n","// Wrappers that turn any methodology into one carrying a policy (design spec section 27). The\n// wrapped methodology keeps every other member, its name included, so registerMethodology accepts it.\nimport { assertId, fail } from \"../core/errors.ts\";\nimport type { Methodology, Policy } from \"../core/types.ts\";\nimport { contextGroundedViolations } from \"../common/context/policy.ts\";\nimport { contextOf } from \"../common/context/snapshot.ts\";\nimport { riskEscalation, type RiskGateOptions } from \"../common/risk/escalation.ts\";\nimport { riskOptions } from \"../common/risk/options.ts\";\n\nconst isObj = (x: unknown): x is Record<string, unknown> =>\n typeof x === \"object\" && x !== null && !Array.isArray(x);\n\n/**\n * `methodology` with the risk-adaptive gate policy (design spec section 27, #35): for each gate in\n * `options.gates`, `complete()` adds the requirements of the row of `options.table` (default\n * `DEFAULT_RISK_TABLE`) that the item's strictest fresh, valid, independent risk assessment picks,\n * `critical` when there is none. An `escalateGate` the methodology already has is kept: both widen\n * the gate. Invalid options fail `invalid-input` here, once.\n */\nexport function withRiskGate<C, N extends string>(\n methodology: Methodology<C, N>,\n options: RiskGateOptions,\n): Methodology<C, N> {\n const opts = riskOptions(options, \"withRiskGate\");\n const inner = methodology.escalateGate;\n return {\n ...methodology,\n escalateGate(state, item, gate) {\n const own = riskEscalation(state, item, gate, opts);\n const prior = inner?.call(methodology, state, item, gate);\n if (!prior || !own) return prior ?? own;\n return {\n requires: [...prior.requires, ...own.requires],\n evidence: [...prior.evidence, ...own.evidence],\n reason: { ...prior.reason, ...own.reason },\n };\n },\n };\n}\n\nexport interface ContextGroundingOptions {\n /** Stage ids whose entry policies gain the custom policy `context-grounded`. */\n entry: string[];\n /** Stage ids whose exit policies gain it. */\n exit?: string[];\n}\n\nconst GROUNDED = \"context-grounded\";\nconst groundedPolicy: Policy = {\n kind: \"custom\",\n id: GROUNDED,\n description: \"grounded in a fresh, verified context snapshot\",\n};\nconst badGrounding = (what: string, fix: string): never =>\n fail(\"invalid-input\", `withContextGrounding options: ${what}`, fix);\n\nfunction stageIds(o: Record<string, unknown>, key: \"entry\" | \"exit\"): string[] {\n const ids = o[key];\n if (ids === undefined && key === \"exit\") return [];\n if (!Array.isArray(ids))\n badGrounding(`${key} must be an array of stage ids`, `e.g. \"${key}\": [\"dev\"]`);\n return (ids as unknown[]).map((id) => {\n assertId(id, `context-grounded ${key} stage id`);\n return id as string;\n });\n}\n\n/**\n * `methodology` with the context-grounded policy (design spec section 27, #36): `defaultStages`\n * adds the custom policy `context-grounded` to the entry policies of the `entry` stages and the\n * exit policies of the `exit` stages (an unknown stage id fails `invalid-input` there), and\n * `plan()`/`complete()` answer it with `contextGroundedViolations`; `synthesizeBrief` carries\n * `contextOf` as `Brief.context`. Hooks the methodology already has answer every other policy id\n * and a brief with no snapshot. Invalid options fail `invalid-input` here, once.\n */\nexport function withContextGrounding<C, N extends string>(\n methodology: Methodology<C, N>,\n options: ContextGroundingOptions,\n): Methodology<C, N> {\n if (!isObj(options)) badGrounding(\"must be an object\", 'pass { \"entry\": [\"dev\"] }');\n const o = options as unknown as Record<string, unknown>;\n for (const k of Object.keys(o))\n if (k !== \"entry\" && k !== \"exit\") badGrounding(`unknown key \"${k}\"`, \"use only: entry, exit\");\n const entry = stageIds(o, \"entry\");\n const exit = stageIds(o, \"exit\");\n const { customPolicy, briefContext } = methodology;\n const add = (list: Policy[], on: boolean): Policy[] =>\n on && !list.some((p) => p.kind === \"custom\" && p.id === GROUNDED)\n ? [...list, groundedPolicy]\n : list;\n return {\n ...methodology,\n defaultStages(config) {\n const stages = methodology.defaultStages(config);\n for (const id of [...entry, ...exit])\n if (!stages.some((st) => st.id === id))\n fail(\n \"invalid-input\",\n `withContextGrounding: unknown stage \"${id}\"`,\n `stages: ${stages.map((st) => st.id).join(\", \")}`,\n );\n return stages.map((st) => ({\n ...st,\n entryPolicy: add(st.entryPolicy, entry.includes(st.id)),\n exitPolicy: add(st.exitPolicy, exit.includes(st.id)),\n }));\n },\n customPolicy(state, item, policy) {\n return policy.id === GROUNDED\n ? contextGroundedViolations(state, item)\n : customPolicy?.call(methodology, state, item, policy);\n },\n briefContext(state, item) {\n return contextOf(state, item) ?? briefContext?.call(methodology, state, item);\n },\n };\n}\n","// `repo.changed` (design spec section 27, #36): the host reports which repository paths a new\n// revision changed; context snapshots citing one of them go stale (see contextOf).\nimport { fail } from \"../../core/errors.ts\";\nimport { applyAction } from \"../../core/methodology.ts\";\nimport { appendEvent, nowOf } from \"../../core/state.ts\";\nimport type { ApplyResult, Methodology, Violation, WorkflowState } from \"../../core/types.ts\";\nimport { contextOf, repoPathIssue } from \"./snapshot.ts\";\n\nexport interface RepoChangeInput {\n /** The new repository revision. */\n revision: string;\n /** Repository-relative POSIX paths the revision changed, as Git lists them. */\n paths: string[];\n by: string;\n now?: string;\n}\n\nconst KEYS = [\"revision\", \"paths\", \"by\", \"now\"];\nconst IN_FLIGHT = [\"in_progress\", \"review\", \"awaiting_human\"];\nconst bad = (what: string, fix: string): never =>\n fail(\"invalid-input\", `repo change: ${what}`, fix);\n\n/**\n * Records that `revision` changed `paths` (design spec section 27, #36): action `repo.change`\n * through `applyAction`, event `repo.changed { revision, paths }` with the paths deduplicated in\n * input order. No item status changes; `warnings` carries one `context-stale` warning per item in\n * `in_progress`, `review` or `awaiting_human` whose context snapshot this change made stale (a\n * cited path it changed that was not stale already). Refuses `invalid-input` for an unknown key,\n * an empty revision, and paths that are not a non-empty array of repository-relative POSIX paths.\n */\nexport function recordRepoChange<N extends string>(\n state: WorkflowState<N>,\n methodology: Methodology<unknown, N>,\n input: RepoChangeInput,\n): ApplyResult<N> {\n if (typeof input !== \"object\" || input === null || Array.isArray(input))\n bad(\"input must be an object\", `pass { ${KEYS.join(\", \")} }`);\n for (const k of Object.keys(input))\n if (!KEYS.includes(k)) bad(`unknown key \"${k}\"`, `use only: ${KEYS.join(\", \")}`);\n const { revision, paths, by, now } = input;\n if (typeof revision !== \"string\" || revision.trim() === \"\")\n bad(\"revision must be a non-empty string\", 'e.g. \"revision\": \"4f2c1e0\"');\n if (!Array.isArray(paths) || paths.length === 0)\n bad(\"paths must be a non-empty array of paths\", 'e.g. \"paths\": [\"src/cart.ts\"]');\n paths.forEach((p, i) => {\n const issue = repoPathIssue(p);\n if (issue)\n bad(\n `paths[${i}] ${issue}`,\n 'send paths as `git diff --name-only -z` lists them (NUL-separated, unquoted; or with `-c core.quotePath=false`), e.g. \"src/cart.ts\"',\n );\n });\n if (typeof by !== \"string\" || by === \"\") bad(\"by must name the reporter\", 'e.g. \"by\": \"ci\"');\n if (now !== undefined && typeof now !== \"string\")\n bad(\"now must be an ISO timestamp string\", \"omit now to use the clock\");\n const changed = [...new Set(paths)];\n const res = applyAction(\n state,\n methodology,\n { type: \"repo.change\", by, payload: { revision, paths: changed } },\n (s) => appendEvent(s, \"repo.changed\", by, { revision, paths: changed }, nowOf(now)),\n );\n const warnings: Violation[] = [];\n for (const item of Object.values(res.state.items)) {\n if (!IN_FLIGHT.includes(item.status)) continue;\n // the new event is the last one, so the paths it made stale are the cited changed paths that\n // were not stale before it, in its order: one indexed read of the earlier log per item\n const ctx = contextOf(state, item);\n if (!ctx) continue;\n const cited = new Set(ctx.assumptions.map((a) => a.source?.path));\n const was = new Set(ctx.stale);\n const hit = changed.filter((p) => cited.has(p) && !was.has(p));\n if (hit.length)\n warnings.push({\n rule: \"context-stale\",\n severity: \"warning\",\n item: item.id,\n message: `context snapshot \"${ctx.snapshot}\" of \"${item.id}\" is stale: ${hit.join(\", \")} changed at ${revision}`,\n fix: `re-verify and record a fresh snapshot of \"${item.id}\" with recordContextSnapshot`,\n });\n }\n return { state: res.state, warnings: [...res.warnings, ...warnings] };\n}\n","// `compareRuns` (design spec section 27, #34): a pure comparison of finished runs, one metric\n// vector per variant, a deterministic ranking and a winner or no winner. Scoring, the scenario\n// suite and running the variants stay with the host.\nimport { assertId, fail } from \"../core/errors.ts\";\nimport type { WorkflowState } from \"../core/types.ts\";\n\n/** One finished run of one variant on one scenario. */\nexport interface RunRecord {\n variant: string;\n scenario: string;\n state: WorkflowState<string>;\n /** The host scorer's verdict for this scenario run. */\n passed: boolean;\n}\n\nexport interface CompareRunsOptions {\n /** The variant every other one is compared with. */\n baseline: string;\n /** Scenarios any failing run of which makes a variant ineligible. */\n mustPass?: string[];\n /** Pass-rate noise, a fraction in `[0, 1]` (default `0`). */\n passTolerance?: number;\n /** Token-cost noise, a fraction in `[0, 1]` (default `0`). */\n costTolerance?: number;\n}\n\nexport interface RunMetrics {\n tokens: number;\n durationMs: number;\n turns: number;\n humanInterventions: number;\n reworks: number;\n escalations: number;\n itemsDone: number;\n}\n\nexport interface VariantResult {\n variant: string;\n runs: number;\n passed: number;\n passRate: number;\n mean: RunMetrics;\n /** Must-pass scenarios with at least one failing run. */\n regressions: string[];\n /** Baseline or must-pass scenarios the variant never ran. */\n missing: string[];\n eligible: boolean;\n}\n\nexport interface RunComparison {\n baseline: string;\n /** Ranked: eligible first, then pass rate, tokens, duration, interventions, id. */\n variants: VariantResult[];\n winner: string | null;\n reason: string;\n}\n\nconst OPTION_KEYS = [\"baseline\", \"mustPass\", \"passTolerance\", \"costTolerance\"];\nconst METRICS = [\n \"tokens\",\n \"durationMs\",\n \"turns\",\n \"humanInterventions\",\n \"reworks\",\n \"escalations\",\n \"itemsDone\",\n] as const;\n\nconst bad = (what: string, fix: string): never =>\n fail(\"invalid-input\", `compareRuns: ${what}`, fix);\nconst show = (v: unknown): string =>\n typeof v === \"string\"\n ? JSON.stringify(v)\n : typeof v === \"object\" && v !== null\n ? Array.isArray(v)\n ? \"an array\"\n : \"an object\"\n : typeof v === \"function\" || typeof v === \"symbol\"\n ? typeof v\n : String(v);\nconst isObject = (v: unknown): v is Record<string, unknown> =>\n typeof v === \"object\" && v !== null && !Array.isArray(v);\n/** `o[k]` when `o` has it as an own property: inherited values (a `{ __proto__: … }` literal) are not read. */\nconst own = (o: Record<string, unknown>, k: string): unknown =>\n Object.hasOwn(o, k) ? o[k] : undefined;\nconst finite = (v: number, what: string): number =>\n Number.isFinite(v)\n ? v\n : bad(`${what} is not finite (${v})`, \"pass the host's measured usage figures\");\nconst idOf = (v: unknown, what: string): string => {\n if (typeof v !== \"string\")\n bad(`${what} is ${show(v)}, not an id`, `pass a string id such as \"V0\"`);\n assertId(v, what);\n return v as string;\n};\nconst tolerance = (v: unknown, key: string): number => {\n if (v === undefined) return 0;\n if (typeof v !== \"number\" || !Number.isFinite(v) || v < 0 || v > 1)\n bad(`${key} is ${show(v)}, not a fraction in [0, 1]`, `pass e.g. \"${key}\": 0.05`);\n return v as number;\n};\n\nfunction metricsOf(state: unknown, where: string): RunMetrics {\n if (!isObject(state))\n return bad(\n `${where}.state is ${show(state)}, not a workflow state`,\n \"pass the finished state.json\",\n );\n const [events, accounting, items] = [\"events\", \"accounting\", \"items\"].map((k) => own(state, k));\n if (!Array.isArray(events) || !Array.isArray(accounting))\n return bad(\n `${where}.state has no events and accounting arrays`,\n \"pass a WorkflowState as loaded by loadState\",\n );\n if (!isObject(items))\n return bad(\n `${where}.state.items is ${show(items)}, not an object`,\n \"pass a WorkflowState as loaded by loadState\",\n );\n const m: RunMetrics = {\n tokens: 0,\n durationMs: 0,\n turns: accounting.length,\n humanInterventions: 0,\n reworks: 0,\n escalations: 0,\n itemsDone: 0,\n };\n accounting.forEach((line: unknown, i) => {\n if (!isObject(line))\n return bad(\n `${where}.state.accounting[${i}] is ${show(line)}`,\n \"pass accounting lines as recorded by complete\",\n );\n for (const k of [\"tokensIn\", \"tokensOut\", \"durationMs\"]) {\n const v = own(line, k);\n if (typeof v !== \"number\" || !Number.isFinite(v) || v < 0)\n bad(\n `${where}.state.accounting[${i}].${k} is ${show(v)}, not a finite non-negative number`,\n \"pass the host's measured usage figures\",\n );\n }\n m.tokens += (line[\"tokensIn\"] as number) + (line[\"tokensOut\"] as number);\n m.durationMs += line[\"durationMs\"] as number;\n });\n // finite figures can still sum to Infinity (G2-7)\n finite(m.tokens, `${where}.state token total`);\n finite(m.durationMs, `${where}.state duration total`);\n events.forEach((ev: unknown, i) => {\n if (!isObject(ev) || typeof own(ev, \"type\") !== \"string\")\n return bad(\n `${where}.state.events[${i}] is ${show(ev)}, not an event`,\n \"pass events as recorded by the engine\",\n );\n const t = ev[\"type\"];\n if (t === \"pending.raised\" || t === \"blocker.cleared\") m.humanInterventions++;\n else if (t === \"item.rework\") m.reworks++;\n else if (t === \"item.escalated\") m.escalations++;\n });\n for (const it of Object.values(items))\n if (isObject(it) && own(it, \"status\") === \"done\") m.itemsDone++;\n return m;\n}\n\n// summed in ascending order so the order of `runs` never changes a float result\nconst meanOf = (xs: number[]): number =>\n xs.sort((a, b) => a - b).reduce((s, x) => s + x, 0) / xs.length;\nconst byId = (a: string, b: string): number => (a < b ? -1 : a > b ? 1 : 0);\n\n/**\n * Compares finished runs (design spec section 27, #34). Pure: reads only its arguments and\n * returns fresh objects. Each variant gets a metric vector (the mean over its runs of tokens,\n * duration, turns, human interventions, reworks, escalations and done items), a pass rate (the\n * mean over its scenarios of each scenario's passing share, so every scenario weighs the same) and an\n * eligibility (no must-pass regression, nothing missing). The winner is the first ranked eligible\n * non-baseline variant that is not worse than the baseline on pass rate and better on pass rate\n * or tokens, beyond the tolerances; otherwise `null` with the reason. Refuses `invalid-input`\n * naming the offending value for malformed input, never a `TypeError`.\n */\nexport function compareRuns(\n runs: readonly RunRecord[],\n options: CompareRunsOptions,\n): RunComparison {\n if (!Array.isArray(runs))\n bad(\n `runs is ${show(runs)}, not an array`,\n \"pass an array of { variant, scenario, state, passed }\",\n );\n if (runs.length === 0) bad(\"no runs to compare\", \"pass at least the baseline's finished runs\");\n if (!isObject(options))\n return bad(`options is ${show(options)}, not an object`, 'pass { baseline: \"V0\" }');\n for (const k of Object.keys(options))\n if (!OPTION_KEYS.includes(k))\n bad(`unknown option \"${k}\"`, `use only: ${OPTION_KEYS.join(\", \")}`);\n const o = options as unknown as Record<string, unknown>;\n const baseline = idOf(own(o, \"baseline\"), \"baseline\");\n const must = own(o, \"mustPass\");\n if (must !== undefined && !Array.isArray(must))\n bad(`mustPass is ${show(must)}, not an array`, 'pass e.g. \"mustPass\": [\"s1\"]');\n const mustPass = [\n ...new Set(((must ?? []) as unknown[]).map((s) => idOf(s, \"mustPass scenario\"))),\n ];\n const passTol = tolerance(own(o, \"passTolerance\"), \"passTolerance\");\n const costTol = tolerance(own(o, \"costTolerance\"), \"costTolerance\");\n\n interface Acc {\n metrics: RunMetrics[];\n passed: number;\n /** scenario -> [passing runs, runs] */\n ran: Map<string, [number, number]>;\n failed: Set<string>;\n }\n const groups = new Map<string, Acc>();\n const named = new Set<string>();\n runs.forEach((r: unknown, i) => {\n const where = `runs[${i}]`;\n if (!isObject(r))\n return bad(\n `${where} is ${show(r)}, not a run record`,\n \"pass { variant, scenario, state, passed }\",\n );\n const variant = idOf(own(r, \"variant\"), `${where}.variant`);\n const scenario = idOf(own(r, \"scenario\"), `${where}.scenario`);\n const passed = own(r, \"passed\");\n if (typeof passed !== \"boolean\")\n bad(\n `${where}.passed is ${show(passed)}, not a boolean`,\n \"pass the scorer's verdict as true or false\",\n );\n const metrics = metricsOf(own(r, \"state\"), where);\n let g = groups.get(variant);\n if (!g)\n groups.set(variant, (g = { metrics: [], passed: 0, ran: new Map(), failed: new Set() }));\n g.metrics.push(metrics);\n const tally = g.ran.get(scenario) ?? [0, 0];\n g.ran.set(scenario, tally);\n tally[1]++;\n named.add(scenario);\n if (passed) {\n g.passed++;\n tally[0]++;\n } else g.failed.add(scenario);\n });\n const base = groups.get(baseline);\n if (!base) bad(`baseline \"${baseline}\" has no run`, \"name a variant that appears in runs\");\n for (const s of mustPass)\n if (!named.has(s))\n bad(`mustPass scenario \"${s}\" has no run`, \"name a scenario that appears in runs\");\n const required = [...new Set([...base!.ran.keys(), ...mustPass])].sort(byId);\n\n const results: VariantResult[] = [...groups].map(([variant, g]) => {\n const n = g.metrics.length;\n const mean = {} as RunMetrics;\n for (const k of METRICS)\n mean[k] = finite(meanOf(g.metrics.map((m) => m[k])), `variant ${variant} mean ${k}`);\n const regressions = mustPass.filter((s) => g.failed.has(s)).sort(byId);\n const missing = required.filter((s) => !g.ran.has(s));\n return {\n variant,\n runs: n,\n passed: g.passed,\n // scenario-weighted: each scenario counts once, whatever its number of runs (G1-3)\n passRate: meanOf([...g.ran.values()].map(([p, k]) => p / k)),\n mean,\n regressions,\n missing,\n eligible: regressions.length === 0 && missing.length === 0,\n };\n });\n results.sort(\n (a, b) =>\n Number(b.eligible) - Number(a.eligible) ||\n b.passRate - a.passRate ||\n a.mean.tokens - b.mean.tokens ||\n a.mean.durationMs - b.mean.durationMs ||\n a.mean.humanInterventions - b.mean.humanInterventions ||\n byId(a.variant, b.variant),\n );\n\n const ref = results.find((v) => v.variant === baseline)!;\n const win = results.find(\n (v) =>\n v.variant !== baseline &&\n v.eligible &&\n v.passRate >= ref.passRate - passTol &&\n (v.passRate > ref.passRate + passTol || v.mean.tokens < ref.mean.tokens * (1 - costTol)),\n );\n if (win)\n return {\n baseline,\n variants: results,\n winner: win.variant,\n reason: `${win.variant} beats baseline ${baseline}: pass rate ${win.passRate} vs ${ref.passRate}, mean tokens ${win.mean.tokens} vs ${ref.mean.tokens}`,\n };\n const others = results.filter((v) => v.variant !== baseline);\n let reason: string;\n if (others.length === 0) reason = `no variant to compare with baseline ${baseline}`;\n else if (others.some((v) => v.eligible))\n reason = `within noise: no eligible variant beats baseline ${baseline} beyond the tolerances`;\n else {\n const why = others\n .map((v) => `${v.variant} (${(v.regressions.length ? v.regressions : v.missing).join(\", \")})`)\n .join(\"; \");\n reason = `${others.some((v) => v.regressions.length) ? \"must-pass regression\" : \"no eligible variant, missing runs\"}: ${why}`;\n }\n return { baseline, variants: results, winner: null, reason };\n}\n"]}
@@ -0,0 +1,199 @@
1
+ import { G as GateRequirement, W as WorkflowState, l as WorkItem, m as Gate, n as GateEscalation, M as Methodology, o as ApplyResult, p as ContextAssumption, q as BriefContext, V as Violation } from '../types-DLOtndDY.cjs';
2
+
3
+ type RiskLevel = "low" | "medium" | "high" | "critical";
4
+ /** `data` of a `risk-assessment` evidence entry. */
5
+ interface RiskAssessmentData {
6
+ level: RiskLevel;
7
+ /** Free strings naming what drives the risk, e.g. `ci-cd`, `prod-infra`, `secrets`, `blast-radius`, `irreversible`. */
8
+ factors: string[];
9
+ /** The item SHA or ref that was assessed. */
10
+ subject?: string;
11
+ }
12
+ /** What each level ADDS to the static gate. */
13
+ type RiskTable = Record<RiskLevel, {
14
+ requires: GateRequirement[];
15
+ evidence?: string[];
16
+ }>;
17
+ interface RiskGateOptions {
18
+ /** Ids of the gates the policy applies to; every other gate stays static. */
19
+ gates: string[];
20
+ /** Default `DEFAULT_RISK_TABLE`. */
21
+ table?: RiskTable;
22
+ }
23
+
24
+ /** `low` and `medium` add nothing; `high` and `critical` add a human approval. Deeply frozen. */
25
+ declare const DEFAULT_RISK_TABLE: RiskTable;
26
+ /**
27
+ * The escalation of `gate` for `item` under `options` (the `escalateGate` hook `withRiskGate`
28
+ * installs): `undefined` for a gate not in `options.gates`, else the table row of the resolved
29
+ * level. The resolved level is the strictest fresh (post-rework) valid assessment, so a later,
30
+ * lower assessment never relaxes an earlier one; with none it is `critical`, and `reason.why` says
31
+ * whether assessments were `missing`, `invalid` or `not-independent` (the latest rejected one).
32
+ * Invalid options fail `invalid-input` as in `withRiskGate`, never a `TypeError`. Pure: no clock,
33
+ * no randomness; the same state gives the same answer.
34
+ */
35
+ declare function riskEscalation(state: WorkflowState<string>, item: WorkItem, gate: Gate, options: RiskGateOptions): GateEscalation | undefined;
36
+
37
+ interface RiskAssessmentInput {
38
+ item: string;
39
+ level: RiskLevel;
40
+ factors: string[];
41
+ /** The host's assessment artifact. */
42
+ ref: string;
43
+ /** The item SHA or ref that was assessed. */
44
+ subject?: string;
45
+ /** The assessor: `human` or a role with capability `verify` that did not do the work. */
46
+ by: string;
47
+ now?: string;
48
+ }
49
+ /**
50
+ * Records a risk assessment of an item as evidence `risk-assessment` with `data: { level, factors,
51
+ * subject? }` (design spec section 27, #35), through `applyAction` (action `risk.assess`) so the
52
+ * methodology's rules see it. Refuses `invalid-input` for an unknown key, an unknown level, a
53
+ * non-string factor, an empty ref, an assessor that is neither `human` nor a role with `verify`, and
54
+ * an assessor that is the item's author or assigned role.
55
+ */
56
+ declare function recordRiskAssessment<N extends string>(state: WorkflowState<N>, methodology: Methodology<unknown, N>, input: RiskAssessmentInput): ApplyResult<N>;
57
+
58
+ /**
59
+ * `methodology` with the risk-adaptive gate policy (design spec section 27, #35): for each gate in
60
+ * `options.gates`, `complete()` adds the requirements of the row of `options.table` (default
61
+ * `DEFAULT_RISK_TABLE`) that the item's strictest fresh, valid, independent risk assessment picks,
62
+ * `critical` when there is none. An `escalateGate` the methodology already has is kept: both widen
63
+ * the gate. Invalid options fail `invalid-input` here, once.
64
+ */
65
+ declare function withRiskGate<C, N extends string>(methodology: Methodology<C, N>, options: RiskGateOptions): Methodology<C, N>;
66
+ interface ContextGroundingOptions {
67
+ /** Stage ids whose entry policies gain the custom policy `context-grounded`. */
68
+ entry: string[];
69
+ /** Stage ids whose exit policies gain it. */
70
+ exit?: string[];
71
+ }
72
+ /**
73
+ * `methodology` with the context-grounded policy (design spec section 27, #36): `defaultStages`
74
+ * adds the custom policy `context-grounded` to the entry policies of the `entry` stages and the
75
+ * exit policies of the `exit` stages (an unknown stage id fails `invalid-input` there), and
76
+ * `plan()`/`complete()` answer it with `contextGroundedViolations`; `synthesizeBrief` carries
77
+ * `contextOf` as `Brief.context`. Hooks the methodology already has answer every other policy id
78
+ * and a brief with no snapshot. Invalid options fail `invalid-input` here, once.
79
+ */
80
+ declare function withContextGrounding<C, N extends string>(methodology: Methodology<C, N>, options: ContextGroundingOptions): Methodology<C, N>;
81
+
82
+ interface ContextSnapshotInput {
83
+ item: string;
84
+ /** The repository revision the snapshot was taken at. */
85
+ revision: string;
86
+ assumptions: ContextAssumption[];
87
+ /** The host's snapshot artifact. */
88
+ ref: string;
89
+ /** Who recorded it: `human` or a registered role that did not work on the item. */
90
+ by: string;
91
+ now?: string;
92
+ }
93
+ /**
94
+ * The item's current context (design spec section 27, #36): its latest fresh (post-rework)
95
+ * qualifying `context-snapshot` evidence (valid data with at least one sourced assumption,
96
+ * recorded by `human` or a registered role that did not work on the item, `workersOf`), with
97
+ * `stale` the cited source paths a later `repo.changed` event listed (exact match, in event order)
98
+ * and `unverified` the claims with no source; `undefined` when there is none. The answer is a
99
+ * copy. Each evidence entry is located at its own `item.evidence` event, matched from the end as
100
+ * `freshEvidence` does; an entry with no event counts as older than every event.
101
+ */
102
+ declare function contextOf(state: WorkflowState<string>, item: WorkItem): BriefContext | undefined;
103
+ /**
104
+ * Records a context snapshot of an item as evidence `context-snapshot` with `data: { revision,
105
+ * assumptions }` (design spec section 27, #36), through `applyAction` (action `context.snapshot`)
106
+ * so the methodology's rules see it. Refuses `invalid-input` for an unknown key, an empty revision,
107
+ * claim or ref, a source with a path that is not repository-relative POSIX or an empty hash,
108
+ * `lines` that are not two integers `1 <= from <= to`, no assumption with a source, and a `by`
109
+ * that is neither `human` nor a registered role or that worked on the item. The input is copied.
110
+ */
111
+ declare function recordContextSnapshot<N extends string>(state: WorkflowState<N>, methodology: Methodology<unknown, N>, input: ContextSnapshotInput): ApplyResult<N>;
112
+
113
+ interface RepoChangeInput {
114
+ /** The new repository revision. */
115
+ revision: string;
116
+ /** Repository-relative POSIX paths the revision changed, as Git lists them. */
117
+ paths: string[];
118
+ by: string;
119
+ now?: string;
120
+ }
121
+ /**
122
+ * Records that `revision` changed `paths` (design spec section 27, #36): action `repo.change`
123
+ * through `applyAction`, event `repo.changed { revision, paths }` with the paths deduplicated in
124
+ * input order. No item status changes; `warnings` carries one `context-stale` warning per item in
125
+ * `in_progress`, `review` or `awaiting_human` whose context snapshot this change made stale (a
126
+ * cited path it changed that was not stale already). Refuses `invalid-input` for an unknown key,
127
+ * an empty revision, and paths that are not a non-empty array of repository-relative POSIX paths.
128
+ */
129
+ declare function recordRepoChange<N extends string>(state: WorkflowState<N>, methodology: Methodology<unknown, N>, input: RepoChangeInput): ApplyResult<N>;
130
+
131
+ /**
132
+ * Violations of the custom policy `context-grounded` for `item` (rule
133
+ * `policy:custom:context-grounded`, the 1.2 rule id of a custom policy): no qualifying fresh
134
+ * context snapshot (`contextOf`: valid, at least one sourced assumption, recorded by `human` or a
135
+ * registered role that did not work on the item); a stale one (names the changed paths); a
136
+ * `required` assumption without a source (names the claims). Empty when the item is grounded.
137
+ * Pure: the same state gives the same answer.
138
+ */
139
+ declare function contextGroundedViolations(state: WorkflowState<string>, item: WorkItem): Violation[];
140
+
141
+ /** One finished run of one variant on one scenario. */
142
+ interface RunRecord {
143
+ variant: string;
144
+ scenario: string;
145
+ state: WorkflowState<string>;
146
+ /** The host scorer's verdict for this scenario run. */
147
+ passed: boolean;
148
+ }
149
+ interface CompareRunsOptions {
150
+ /** The variant every other one is compared with. */
151
+ baseline: string;
152
+ /** Scenarios any failing run of which makes a variant ineligible. */
153
+ mustPass?: string[];
154
+ /** Pass-rate noise, a fraction in `[0, 1]` (default `0`). */
155
+ passTolerance?: number;
156
+ /** Token-cost noise, a fraction in `[0, 1]` (default `0`). */
157
+ costTolerance?: number;
158
+ }
159
+ interface RunMetrics {
160
+ tokens: number;
161
+ durationMs: number;
162
+ turns: number;
163
+ humanInterventions: number;
164
+ reworks: number;
165
+ escalations: number;
166
+ itemsDone: number;
167
+ }
168
+ interface VariantResult {
169
+ variant: string;
170
+ runs: number;
171
+ passed: number;
172
+ passRate: number;
173
+ mean: RunMetrics;
174
+ /** Must-pass scenarios with at least one failing run. */
175
+ regressions: string[];
176
+ /** Baseline or must-pass scenarios the variant never ran. */
177
+ missing: string[];
178
+ eligible: boolean;
179
+ }
180
+ interface RunComparison {
181
+ baseline: string;
182
+ /** Ranked: eligible first, then pass rate, tokens, duration, interventions, id. */
183
+ variants: VariantResult[];
184
+ winner: string | null;
185
+ reason: string;
186
+ }
187
+ /**
188
+ * Compares finished runs (design spec section 27, #34). Pure: reads only its arguments and
189
+ * returns fresh objects. Each variant gets a metric vector (the mean over its runs of tokens,
190
+ * duration, turns, human interventions, reworks, escalations and done items), a pass rate (the
191
+ * mean over its scenarios of each scenario's passing share, so every scenario weighs the same) and an
192
+ * eligibility (no must-pass regression, nothing missing). The winner is the first ranked eligible
193
+ * non-baseline variant that is not worse than the baseline on pass rate and better on pass rate
194
+ * or tokens, beyond the tolerances; otherwise `null` with the reason. Refuses `invalid-input`
195
+ * naming the offending value for malformed input, never a `TypeError`.
196
+ */
197
+ declare function compareRuns(runs: readonly RunRecord[], options: CompareRunsOptions): RunComparison;
198
+
199
+ export { type CompareRunsOptions, type ContextGroundingOptions, type ContextSnapshotInput, DEFAULT_RISK_TABLE, type RepoChangeInput, type RiskAssessmentData, type RiskAssessmentInput, type RiskGateOptions, type RiskLevel, type RiskTable, type RunComparison, type RunMetrics, type RunRecord, type VariantResult, compareRuns, contextGroundedViolations, contextOf, recordContextSnapshot, recordRepoChange, recordRiskAssessment, riskEscalation, withContextGrounding, withRiskGate };