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
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- import { s as ErrorCode, W as WorkflowState, t as MethodologyName, S as Stage, R as Role, o as Event, u as Evidence, N as NewItem, v as ItemPatch, l as WorkItem, j as ItemStatus, P as Policy, V as Violation, G as Gate, M as Methodology, T as Transition, r as PendingHuman, w as Iteration, B as Brief, H as Handoff, A as Accounting, x as ApplyResult, g as Rule, y as Action } from './types-BScHXlRx.cjs';
2
- export { z as Baseline, D as Blocker, a as Budget, C as Capability, f as Ceremony, n as CeremonyInput, m as ClassOfService, k as CoreTerm, p as GateRequirement, F as ImpactAnalysis, J as ItemType, L as Lesson, K as LessonChange, Q as ModelTier, q as Phase, U as PlannerOptions, X as Produced, Y as Spent, Z as Verdict } from './types-BScHXlRx.cjs';
3
- export { E as EstimateMode, Z as ZERO_SPENT, a as addSpent, b as approversFor, c as canDo, e as estimateTokens, h as hasCapability, i as isExhausted, r as registerRole, d as remaining, f as requireCap, g as requireCapabilities, j as retireRole, k as rolesWith, s as separationLost } from './budget-CezCinPF.cjs';
1
+ import { w as ErrorCode, W as WorkflowState, x as MethodologyName, S as Stage, R as Role, t as Event, C as Capability, N as NewItem, y as ItemPatch, l as WorkItem, j as ItemStatus, z as Evidence, P as Policy, M as Methodology, V as Violation, m as Gate, T as Transition, v as PendingHuman, D as Iteration, B as Brief, H as Handoff, A as Accounting, o as ApplyResult, g as Rule, F as Action, e as InvestigationState, i as ExperimentationState } from './types-DLOtndDY.cjs';
2
+ export { J as Baseline, K as Blocker, q as BriefContext, a as Budget, f as Ceremony, s as CeremonyInput, r as ClassOfService, p as ContextAssumption, L as ContextSnapshotData, k as CoreTerm, n as GateEscalation, G as GateRequirement, Q as ImpactAnalysis, U as ItemType, X as Lesson, Y as LessonChange, Z as ModelTier, u as Phase, _ as PlannerOptions, $ as Produced, a0 as Spent, a1 as Verdict, a2 as WorkflowExt } from './types-DLOtndDY.cjs';
3
+ export { E as EstimateMode, Z as ZERO_SPENT, a as addSpent, c as canDo, e as estimateTokens, i as isExhausted, r as remaining, b as requireCap, d as requireCapabilities, s as separationLost } from './budget-DDqQQIgp.cjs';
4
4
  import { ExNode } from 'ex-flow';
5
5
 
6
6
  interface WorkflowErrorExtra {
@@ -22,45 +22,88 @@ declare class WorkflowError extends Error {
22
22
  };
23
23
  }
24
24
  declare function fail(code: ErrorCode, message: string, fix: string, extra?: WorkflowErrorExtra): never;
25
- /** Ids become object keys and file names: letters, digits, `.`, `_`, `-`; no `..`, no prototype names. */
25
+ /**
26
+ * Ids become object keys and file names: at most 128 of letters, digits, `.`, `_`, `-`; no `..`,
27
+ * no `Object.prototype` member name, no Windows device name (`CON`, `NUL.txt`, `COM1`, ...).
28
+ */
26
29
  declare function assertId(id: unknown, what: string): void;
27
30
 
28
31
  declare function nowOf(now?: string): string;
29
- interface CreateStateInput {
30
- methodology: MethodologyName;
32
+ interface CreateStateInput<N extends string = MethodologyName> {
33
+ methodology: N;
31
34
  config: unknown;
32
35
  stages: Stage[];
33
36
  roles: Role[];
34
37
  now?: string;
35
38
  }
36
39
  declare function createState(input: CreateStateInput): WorkflowState;
40
+ declare function createState<N extends string>(input: CreateStateInput<N>): WorkflowState<N>;
41
+ declare function createState(input: CreateStateInput): WorkflowState;
42
+ declare function appendEvent<N extends string>(state: WorkflowState<N>, type: string, by: string, payload: unknown, now?: string): WorkflowState<N>;
37
43
  declare function appendEvent(state: WorkflowState, type: string, by: string, payload: unknown, now?: string): WorkflowState;
44
+ declare function lastEvent(state: WorkflowState<string>, type?: string): Event | undefined;
38
45
  declare function lastEvent(state: WorkflowState, type?: string): Event | undefined;
39
46
 
47
+ declare function registerRole<N extends string>(state: WorkflowState<N>, role: Role, by: string, now?: string): WorkflowState<N>;
48
+ declare function registerRole(state: WorkflowState, role: Role, by: string, now?: string): WorkflowState;
49
+ declare function retireRole<N extends string>(state: WorkflowState<N>, roleId: string, by: string, now?: string): WorkflowState<N>;
50
+ declare function retireRole(state: WorkflowState, roleId: string, by: string, now?: string): WorkflowState;
51
+
52
+ declare function hasCapability(role: Role, cap: Capability): boolean;
53
+ declare function rolesWith(state: WorkflowState<string>, cap: Capability): Role[];
54
+ declare function rolesWith(state: WorkflowState, cap: Capability): Role[];
55
+ declare function approversFor(state: WorkflowState<string>, gateId: string): Role[];
56
+ declare function approversFor(state: WorkflowState, gateId: string): Role[];
57
+
58
+ declare function stageOf(state: WorkflowState<string>, stageId: string): Stage;
40
59
  declare function stageOf(state: WorkflowState, stageId: string): Stage;
60
+ declare function nextStageOf(state: WorkflowState<string>, stageId: string): Stage | undefined;
41
61
  declare function nextStageOf(state: WorkflowState, stageId: string): Stage | undefined;
62
+ declare function isTerminalStage(state: WorkflowState<string>, stageId: string): boolean;
42
63
  declare function isTerminalStage(state: WorkflowState, stageId: string): boolean;
64
+
65
+ declare function getItem(state: WorkflowState<string>, id: string): WorkItem;
43
66
  declare function getItem(state: WorkflowState, id: string): WorkItem;
67
+ declare function addItem<N extends string>(state: WorkflowState<N>, input: NewItem, by: string, now?: string): WorkflowState<N>;
44
68
  declare function addItem(state: WorkflowState, input: NewItem, by: string, now?: string): WorkflowState;
45
-
69
+ declare function editItem<N extends string>(state: WorkflowState<N>, id: string, patch: ItemPatch, by: string, now?: string): WorkflowState<N>;
46
70
  declare function editItem(state: WorkflowState, id: string, patch: ItemPatch, by: string, now?: string): WorkflowState;
71
+
72
+ declare function moveItem<N extends string>(state: WorkflowState<N>, id: string, to: {
73
+ stage?: string;
74
+ status: ItemStatus;
75
+ }, by: string, now?: string): WorkflowState<N>;
47
76
  declare function moveItem(state: WorkflowState, id: string, to: {
48
77
  stage?: string;
49
78
  status: ItemStatus;
50
79
  }, by: string, now?: string): WorkflowState;
80
+
81
+ declare function addEvidence<N extends string>(state: WorkflowState<N>, id: string, evidence: Omit<Evidence, "at">, now?: string): WorkflowState<N>;
51
82
  declare function addEvidence(state: WorkflowState, id: string, evidence: Omit<Evidence, "at">, now?: string): WorkflowState;
83
+
84
+ declare function raiseBlocker<N extends string>(state: WorkflowState<N>, id: string, reason: string, owner: string, by: string, now?: string): WorkflowState<N>;
52
85
  declare function raiseBlocker(state: WorkflowState, id: string, reason: string, owner: string, by: string, now?: string): WorkflowState;
86
+ declare function clearBlocker<N extends string>(state: WorkflowState<N>, id: string, blockerId: string, by: string, now?: string, note?: string): WorkflowState<N>;
53
87
  declare function clearBlocker(state: WorkflowState, id: string, blockerId: string, by: string, now?: string, note?: string): WorkflowState;
54
88
 
55
89
  /** Adds an agreement (idempotent); with `replaces`, retires that one in the same step. */
90
+ declare function applyAgreement<N extends string>(state: WorkflowState<N>, change: {
91
+ text: string;
92
+ replaces?: string;
93
+ }, by: string, now: string): WorkflowState<N>;
56
94
  declare function applyAgreement(state: WorkflowState, change: {
57
95
  text: string;
58
96
  replaces?: string;
59
97
  }, by: string, now: string): WorkflowState;
60
98
  /** Removes an agreement and records why it left (replacedBy null). */
99
+ declare function retireAgreement<N extends string>(state: WorkflowState<N>, text: string, by: string, now: string): WorkflowState<N>;
61
100
  declare function retireAgreement(state: WorkflowState, text: string, by: string, now: string): WorkflowState;
62
101
 
102
+ /** The part of a methodology policy evaluation reads: its `customPolicy` hook (spec 27, #36). */
103
+ type PolicyHook<N extends string> = Pick<Methodology<unknown, N>, "customPolicy">;
104
+ declare function evaluatePolicies<N extends string>(state: WorkflowState<N>, item: WorkItem, policies: Policy[], methodology?: PolicyHook<N>): Violation[];
63
105
  declare function evaluatePolicies(state: WorkflowState, item: WorkItem, policies: Policy[]): Violation[];
106
+ declare function assertPolicies<N extends string>(state: WorkflowState<N>, item: WorkItem, policies: Policy[], context: string, methodology?: PolicyHook<N>): void;
64
107
  declare function assertPolicies(state: WorkflowState, item: WorkItem, policies: Policy[], context: string): void;
65
108
 
66
109
  type GateResult = {
@@ -72,19 +115,28 @@ type GateResult = {
72
115
  violations: Violation[];
73
116
  };
74
117
  /** Last in_progress dispatch made from a stage that comes STRICTLY BEFORE the item's current stage in `state.stages` order (unknown stage ids count as not-before). */
118
+ declare function lastDispatchBefore(state: WorkflowState<string>, item: WorkItem): Transition | undefined;
75
119
  declare function lastDispatchBefore(state: WorkflowState, item: WorkItem): Transition | undefined;
76
120
  /** Role that did the work the gate guards: the last dispatch made from a stage strictly before the current one (so a reviewer dispatched into the gated stage is not its author); else the last dispatch of any stage; undefined if never dispatched. */
121
+ declare function authorOf(state: WorkflowState<string>, item: WorkItem): string | undefined;
77
122
  declare function authorOf(state: WorkflowState, item: WorkItem): string | undefined;
123
+ declare function checkGate(state: WorkflowState<string>, item: WorkItem, gate: Gate, by: string): GateResult;
78
124
  declare function checkGate(state: WorkflowState, item: WorkItem, gate: Gate, by: string): GateResult;
125
+ declare function raisePending<N extends string>(state: WorkflowState<N>, pending: Omit<PendingHuman, "id" | "raisedAt">, now?: string): WorkflowState<N>;
79
126
  declare function raisePending(state: WorkflowState, pending: Omit<PendingHuman, "id" | "raisedAt">, now?: string): WorkflowState;
127
+ declare function decide<N extends string>(state: WorkflowState<N>, pendingId: string, decision: "approve" | "reject", by: string, note: string, now?: string, methodology?: Methodology<unknown, N>): WorkflowState<N>;
80
128
  declare function decide(state: WorkflowState, pendingId: string, decision: "approve" | "reject", by: string, note: string, now?: string, methodology?: Methodology): WorkflowState;
81
129
 
82
130
  type NodeData = {
83
131
  id: string;
84
132
  };
133
+ declare function openIteration(state: WorkflowState<string>): Iteration | undefined;
85
134
  declare function openIteration(state: WorkflowState): Iteration | undefined;
135
+ declare function assignRole(state: WorkflowState<string>, item: WorkItem, roleFor?: (item: WorkItem) => string | undefined): Role;
86
136
  declare function assignRole(state: WorkflowState, item: WorkItem, roleFor?: (item: WorkItem) => string | undefined): Role;
137
+ declare function resourceCapsFor(state: WorkflowState<string>): Record<string, number>;
87
138
  declare function resourceCapsFor(state: WorkflowState): Record<string, number>;
139
+ declare function toExNodes(items: WorkItem[], state: WorkflowState<string>, priorityOf?: (item: WorkItem) => number | undefined, roleFor?: (item: WorkItem) => string | undefined): ExNode<NodeData>[];
88
140
  declare function toExNodes(items: WorkItem[], state: WorkflowState, priorityOf?: (item: WorkItem) => number | undefined, roleFor?: (item: WorkItem) => string | undefined): ExNode<NodeData>[];
89
141
  interface PlanOptions {
90
142
  max?: number;
@@ -98,30 +150,40 @@ interface Skipped {
98
150
  reason: "entry-policy" | "wip" | "resource-cap" | "budget";
99
151
  detail: string;
100
152
  }
101
- interface PlanResult {
102
- state: WorkflowState;
153
+ interface PlanResult<N extends string = MethodologyName> {
154
+ state: WorkflowState<N>;
103
155
  dispatched: WorkItem[];
104
156
  skipped: Skipped[];
105
157
  reason?: PlanReason;
106
158
  }
159
+ declare function plan<N extends string>(state: WorkflowState<N>, methodology: Methodology<unknown, N>, opts?: PlanOptions): PlanResult<N>;
107
160
  declare function plan(state: WorkflowState, methodology: Methodology, opts?: PlanOptions): PlanResult;
108
161
 
162
+ declare function synthesizeBrief<N extends string>(state: WorkflowState<N>, methodology: Methodology<unknown, N>, item: WorkItem): Brief;
109
163
  declare function synthesizeBrief(state: WorkflowState, methodology: Methodology, item: WorkItem): Brief;
110
164
  /** Open questions of finished items: the last completion per item, verdict done/needs-review, with open_questions left unanswered. */
165
+ declare function openQuestions(state: WorkflowState<string>): Array<{
166
+ item: string;
167
+ role: string;
168
+ questions: string[];
169
+ at: string;
170
+ }>;
111
171
  declare function openQuestions(state: WorkflowState): Array<{
112
172
  item: string;
113
173
  role: string;
114
174
  questions: string[];
115
175
  at: string;
116
176
  }>;
117
- interface NextResult {
118
- state: WorkflowState;
177
+ interface NextResult<N extends string = MethodologyName> {
178
+ state: WorkflowState<N>;
119
179
  briefs: Brief[];
120
180
  skipped: Skipped[];
121
181
  reason?: PlanReason;
122
182
  }
183
+ declare function next<N extends string>(state: WorkflowState<N>, methodology: Methodology<unknown, N>, opts?: PlanOptions): NextResult<N>;
123
184
  declare function next(state: WorkflowState, methodology: Methodology, opts?: PlanOptions): NextResult;
124
185
 
186
+ declare function complete<N extends string>(state: WorkflowState<N>, methodology: Methodology<unknown, N>, handoff: Handoff, acc: Accounting, now?: string): ApplyResult<N>;
125
187
  declare function complete(state: WorkflowState, methodology: Methodology, handoff: Handoff, acc: Accounting, now?: string): ApplyResult;
126
188
 
127
189
  interface AccountingPatch {
@@ -134,14 +196,18 @@ interface AccountingPatch {
134
196
  * Rewrite one accounting line of an item (`line` is 1-based among the item's lines, default the last).
135
197
  * The owning iteration's spent follows the delta, open or closed; the event records before/after.
136
198
  */
199
+ declare function correctAccounting<N extends string>(state: WorkflowState<N>, itemId: string, patch: AccountingPatch, by: string, now?: string, line?: number): WorkflowState<N>;
137
200
  declare function correctAccounting(state: WorkflowState, itemId: string, patch: AccountingPatch, by: string, now?: string, line?: number): WorkflowState;
138
201
 
202
+ declare function coreRulesFor<N extends string = MethodologyName>(methodology: Pick<Methodology, "requiredCapabilities">): Rule<N>[];
139
203
  declare function coreRulesFor(methodology: Pick<Methodology, "requiredCapabilities">): Rule[];
140
204
 
205
+ declare function validateAction<N extends string>(state: WorkflowState<N>, methodology: Methodology<unknown, N>, action: Action): Violation[];
141
206
  declare function validateAction(state: WorkflowState, methodology: Methodology, action: Action): Violation[];
207
+ declare function applyAction<N extends string>(state: WorkflowState<N>, methodology: Methodology<unknown, N>, action: Action, reduce: (s: WorkflowState<N>) => WorkflowState<N>): ApplyResult<N>;
142
208
  declare function applyAction(state: WorkflowState, methodology: Methodology, action: Action, reduce: (s: WorkflowState) => WorkflowState): ApplyResult;
143
- interface InitInput<C> {
144
- methodology: Methodology<C>;
209
+ interface InitInput<C, N extends string = MethodologyName> {
210
+ methodology: Methodology<C, N>;
145
211
  config: unknown;
146
212
  roles?: Role[];
147
213
  stages?: Stage[];
@@ -149,9 +215,73 @@ interface InitInput<C> {
149
215
  now?: string;
150
216
  }
151
217
  declare function init<C>(input: InitInput<C>): ApplyResult;
218
+ declare function init<C, N extends string>(input: InitInput<C, N>): ApplyResult<N>;
219
+ declare function init<C>(input: InitInput<C>): ApplyResult;
152
220
  /** Change the config between iterations: re-validated, recorded as config.changed, derived state kept in step by the methodology hook. */
221
+ declare function changeConfig<N extends string>(state: WorkflowState<N>, methodology: Methodology<unknown, N>, patch: Record<string, unknown>, by: string, now?: string): ApplyResult<N>;
153
222
  declare function changeConfig(state: WorkflowState, methodology: Methodology, patch: Record<string, unknown>, by: string, now?: string): ApplyResult;
154
223
 
155
- declare const VERSION = "1.1.1";
224
+ /**
225
+ * Extension records that 1.1 stored as top-level state fields. Writing one also writes its
226
+ * deprecated legacy mirror (`state.investigation`, `state.experimentation`) in memory; on disk
227
+ * only `ext` is stored (spec 26). 2.0 drops the mirror.
228
+ */
229
+ interface LegacyExtRecords {
230
+ investigation: InvestigationState;
231
+ experimentation: ExperimentationState;
232
+ }
233
+ type LegacyKey = keyof LegacyExtRecords;
234
+ /**
235
+ * Reads the extension record `key` (a methodology name or a common piece id) from `state.ext`.
236
+ * A state written before 1.2 has no `ext`; for `investigation` and `experimentation` the legacy
237
+ * top-level field is read instead.
238
+ */
239
+ declare function readExt<K extends LegacyKey>(state: WorkflowState<string>, key: K): LegacyExtRecords[K] | undefined;
240
+ declare function readExt<T = unknown>(state: WorkflowState<string>, key: string): T | undefined;
241
+ /**
242
+ * Returns a copy of `state` with `state.ext[key] = value`; `undefined` removes the key, and adds
243
+ * no empty `ext` to a state that had none. For `investigation` and `experimentation` the legacy
244
+ * top-level field is written (or removed) too, so SDK code reading `state.investigation` /
245
+ * `state.experimentation` sees the same record (dual-write, spec 26). The mirror is read-only:
246
+ * once `ext.<key>` exists, `readExt` ignores the legacy field. It does not make the state
247
+ * loadable by 1.1.x, whose schema rejects `ext`.
248
+ */
249
+ declare function writeExt<N extends string, K extends LegacyKey>(state: WorkflowState<N>, key: K, value: LegacyExtRecords[K] | undefined): WorkflowState<N>;
250
+ declare function writeExt<N extends string, T>(state: WorkflowState<N>, key: string, value: T | undefined): WorkflowState<N>;
251
+
252
+ /**
253
+ * Independence check: a verifying role must not be one that did the work.
254
+ *
255
+ * Returns the ids in `verifiers` that also appear in `workers`, each once, in verifier order;
256
+ * an empty array means the verification is independent. Ids are compared exactly. The caller
257
+ * decides how a conflict fails (a rule violation, a refused ceremony, a skipped role), so the
258
+ * check carries no message of its own.
259
+ *
260
+ * @example
261
+ * // a validator may not validate a candidate it built or integrated
262
+ * if (independenceConflicts(by, [candidate.author, integration.by]).length) refuse();
263
+ */
264
+ declare function independenceConflicts(verifiers: string | readonly string[], workers: readonly string[]): string[];
265
+
266
+ /**
267
+ * Frozen-input check: a frozen or preregistered record may not change after freeze.
268
+ *
269
+ * Compares each key of `frozen` (or only `keys`, when given) with the same key of `supplied`
270
+ * and returns the keys whose value differs, in key order; an empty array means the supplied
271
+ * input matches the freeze. Values are compared by identity (`!==`), so freeze primitive
272
+ * fields such as ids, SHAs and refs. Only own fields of `supplied` are read: a missing record,
273
+ * a missing field or an inherited one reads as `undefined`, which counts as a change unless the
274
+ * frozen value is `undefined` too. The caller decides how a change fails, so the check carries
275
+ * no message of its own.
276
+ *
277
+ * @example
278
+ * // a submission must reuse the frozen harness and base SHA
279
+ * if (frozenChanges({ harness, baseSha }, input).length) refuse();
280
+ */
281
+ declare function frozenChanges<K extends string>(frozen: {
282
+ readonly [P in K]?: unknown;
283
+ }, supplied: object | undefined, keys?: readonly K[]): K[];
284
+
285
+ declare const VERSION = "1.3.0";
156
286
 
157
- export { Accounting, type AccountingPatch, Action, ApplyResult, Brief, ErrorCode, Event, Evidence, Gate, type GateResult, Handoff, type InitInput, ItemPatch, ItemStatus, Iteration, Methodology, MethodologyName, NewItem, type NextResult, PendingHuman, type PlanOptions, type PlanReason, type PlanResult, Policy, Role, Rule, type Skipped, Stage, Transition, VERSION, Violation, WorkItem, WorkflowError, WorkflowState, addEvidence, addItem, appendEvent, applyAction, applyAgreement, assertId, assertPolicies, assignRole, authorOf, changeConfig, checkGate, clearBlocker, complete, coreRulesFor, correctAccounting, createState, decide, editItem, evaluatePolicies, fail, getItem, init, isTerminalStage, lastDispatchBefore, lastEvent, moveItem, next, nextStageOf, nowOf, openIteration, openQuestions, plan, raiseBlocker, raisePending, resourceCapsFor, retireAgreement, stageOf, synthesizeBrief, toExNodes, validateAction };
287
+ export { Accounting, type AccountingPatch, Action, ApplyResult, Brief, Capability, ErrorCode, Event, Evidence, Gate, type GateResult, Handoff, type InitInput, ItemPatch, ItemStatus, Iteration, type LegacyExtRecords, Methodology, MethodologyName, NewItem, type NextResult, PendingHuman, type PlanOptions, type PlanReason, type PlanResult, Policy, Role, Rule, type Skipped, Stage, Transition, VERSION, Violation, WorkItem, WorkflowError, WorkflowState, addEvidence, addItem, appendEvent, applyAction, applyAgreement, approversFor, assertId, assertPolicies, assignRole, authorOf, changeConfig, checkGate, clearBlocker, complete, coreRulesFor, correctAccounting, createState, decide, editItem, evaluatePolicies, fail, frozenChanges, getItem, hasCapability, independenceConflicts, init, isTerminalStage, lastDispatchBefore, lastEvent, moveItem, next, nextStageOf, nowOf, openIteration, openQuestions, plan, raiseBlocker, raisePending, readExt, registerRole, resourceCapsFor, retireAgreement, retireRole, rolesWith, stageOf, synthesizeBrief, toExNodes, validateAction, writeExt };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { s as ErrorCode, W as WorkflowState, t as MethodologyName, S as Stage, R as Role, o as Event, u as Evidence, N as NewItem, v as ItemPatch, l as WorkItem, j as ItemStatus, P as Policy, V as Violation, G as Gate, M as Methodology, T as Transition, r as PendingHuman, w as Iteration, B as Brief, H as Handoff, A as Accounting, x as ApplyResult, g as Rule, y as Action } from './types-BScHXlRx.js';
2
- export { z as Baseline, D as Blocker, a as Budget, C as Capability, f as Ceremony, n as CeremonyInput, m as ClassOfService, k as CoreTerm, p as GateRequirement, F as ImpactAnalysis, J as ItemType, L as Lesson, K as LessonChange, Q as ModelTier, q as Phase, U as PlannerOptions, X as Produced, Y as Spent, Z as Verdict } from './types-BScHXlRx.js';
3
- export { E as EstimateMode, Z as ZERO_SPENT, a as addSpent, b as approversFor, c as canDo, e as estimateTokens, h as hasCapability, i as isExhausted, r as registerRole, d as remaining, f as requireCap, g as requireCapabilities, j as retireRole, k as rolesWith, s as separationLost } from './budget-Bd8KpGIr.js';
1
+ import { w as ErrorCode, W as WorkflowState, x as MethodologyName, S as Stage, R as Role, t as Event, C as Capability, N as NewItem, y as ItemPatch, l as WorkItem, j as ItemStatus, z as Evidence, P as Policy, M as Methodology, V as Violation, m as Gate, T as Transition, v as PendingHuman, D as Iteration, B as Brief, H as Handoff, A as Accounting, o as ApplyResult, g as Rule, F as Action, e as InvestigationState, i as ExperimentationState } from './types-DLOtndDY.js';
2
+ export { J as Baseline, K as Blocker, q as BriefContext, a as Budget, f as Ceremony, s as CeremonyInput, r as ClassOfService, p as ContextAssumption, L as ContextSnapshotData, k as CoreTerm, n as GateEscalation, G as GateRequirement, Q as ImpactAnalysis, U as ItemType, X as Lesson, Y as LessonChange, Z as ModelTier, u as Phase, _ as PlannerOptions, $ as Produced, a0 as Spent, a1 as Verdict, a2 as WorkflowExt } from './types-DLOtndDY.js';
3
+ export { E as EstimateMode, Z as ZERO_SPENT, a as addSpent, c as canDo, e as estimateTokens, i as isExhausted, r as remaining, b as requireCap, d as requireCapabilities, s as separationLost } from './budget-BuQ9GWsg.js';
4
4
  import { ExNode } from 'ex-flow';
5
5
 
6
6
  interface WorkflowErrorExtra {
@@ -22,45 +22,88 @@ declare class WorkflowError extends Error {
22
22
  };
23
23
  }
24
24
  declare function fail(code: ErrorCode, message: string, fix: string, extra?: WorkflowErrorExtra): never;
25
- /** Ids become object keys and file names: letters, digits, `.`, `_`, `-`; no `..`, no prototype names. */
25
+ /**
26
+ * Ids become object keys and file names: at most 128 of letters, digits, `.`, `_`, `-`; no `..`,
27
+ * no `Object.prototype` member name, no Windows device name (`CON`, `NUL.txt`, `COM1`, ...).
28
+ */
26
29
  declare function assertId(id: unknown, what: string): void;
27
30
 
28
31
  declare function nowOf(now?: string): string;
29
- interface CreateStateInput {
30
- methodology: MethodologyName;
32
+ interface CreateStateInput<N extends string = MethodologyName> {
33
+ methodology: N;
31
34
  config: unknown;
32
35
  stages: Stage[];
33
36
  roles: Role[];
34
37
  now?: string;
35
38
  }
36
39
  declare function createState(input: CreateStateInput): WorkflowState;
40
+ declare function createState<N extends string>(input: CreateStateInput<N>): WorkflowState<N>;
41
+ declare function createState(input: CreateStateInput): WorkflowState;
42
+ declare function appendEvent<N extends string>(state: WorkflowState<N>, type: string, by: string, payload: unknown, now?: string): WorkflowState<N>;
37
43
  declare function appendEvent(state: WorkflowState, type: string, by: string, payload: unknown, now?: string): WorkflowState;
44
+ declare function lastEvent(state: WorkflowState<string>, type?: string): Event | undefined;
38
45
  declare function lastEvent(state: WorkflowState, type?: string): Event | undefined;
39
46
 
47
+ declare function registerRole<N extends string>(state: WorkflowState<N>, role: Role, by: string, now?: string): WorkflowState<N>;
48
+ declare function registerRole(state: WorkflowState, role: Role, by: string, now?: string): WorkflowState;
49
+ declare function retireRole<N extends string>(state: WorkflowState<N>, roleId: string, by: string, now?: string): WorkflowState<N>;
50
+ declare function retireRole(state: WorkflowState, roleId: string, by: string, now?: string): WorkflowState;
51
+
52
+ declare function hasCapability(role: Role, cap: Capability): boolean;
53
+ declare function rolesWith(state: WorkflowState<string>, cap: Capability): Role[];
54
+ declare function rolesWith(state: WorkflowState, cap: Capability): Role[];
55
+ declare function approversFor(state: WorkflowState<string>, gateId: string): Role[];
56
+ declare function approversFor(state: WorkflowState, gateId: string): Role[];
57
+
58
+ declare function stageOf(state: WorkflowState<string>, stageId: string): Stage;
40
59
  declare function stageOf(state: WorkflowState, stageId: string): Stage;
60
+ declare function nextStageOf(state: WorkflowState<string>, stageId: string): Stage | undefined;
41
61
  declare function nextStageOf(state: WorkflowState, stageId: string): Stage | undefined;
62
+ declare function isTerminalStage(state: WorkflowState<string>, stageId: string): boolean;
42
63
  declare function isTerminalStage(state: WorkflowState, stageId: string): boolean;
64
+
65
+ declare function getItem(state: WorkflowState<string>, id: string): WorkItem;
43
66
  declare function getItem(state: WorkflowState, id: string): WorkItem;
67
+ declare function addItem<N extends string>(state: WorkflowState<N>, input: NewItem, by: string, now?: string): WorkflowState<N>;
44
68
  declare function addItem(state: WorkflowState, input: NewItem, by: string, now?: string): WorkflowState;
45
-
69
+ declare function editItem<N extends string>(state: WorkflowState<N>, id: string, patch: ItemPatch, by: string, now?: string): WorkflowState<N>;
46
70
  declare function editItem(state: WorkflowState, id: string, patch: ItemPatch, by: string, now?: string): WorkflowState;
71
+
72
+ declare function moveItem<N extends string>(state: WorkflowState<N>, id: string, to: {
73
+ stage?: string;
74
+ status: ItemStatus;
75
+ }, by: string, now?: string): WorkflowState<N>;
47
76
  declare function moveItem(state: WorkflowState, id: string, to: {
48
77
  stage?: string;
49
78
  status: ItemStatus;
50
79
  }, by: string, now?: string): WorkflowState;
80
+
81
+ declare function addEvidence<N extends string>(state: WorkflowState<N>, id: string, evidence: Omit<Evidence, "at">, now?: string): WorkflowState<N>;
51
82
  declare function addEvidence(state: WorkflowState, id: string, evidence: Omit<Evidence, "at">, now?: string): WorkflowState;
83
+
84
+ declare function raiseBlocker<N extends string>(state: WorkflowState<N>, id: string, reason: string, owner: string, by: string, now?: string): WorkflowState<N>;
52
85
  declare function raiseBlocker(state: WorkflowState, id: string, reason: string, owner: string, by: string, now?: string): WorkflowState;
86
+ declare function clearBlocker<N extends string>(state: WorkflowState<N>, id: string, blockerId: string, by: string, now?: string, note?: string): WorkflowState<N>;
53
87
  declare function clearBlocker(state: WorkflowState, id: string, blockerId: string, by: string, now?: string, note?: string): WorkflowState;
54
88
 
55
89
  /** Adds an agreement (idempotent); with `replaces`, retires that one in the same step. */
90
+ declare function applyAgreement<N extends string>(state: WorkflowState<N>, change: {
91
+ text: string;
92
+ replaces?: string;
93
+ }, by: string, now: string): WorkflowState<N>;
56
94
  declare function applyAgreement(state: WorkflowState, change: {
57
95
  text: string;
58
96
  replaces?: string;
59
97
  }, by: string, now: string): WorkflowState;
60
98
  /** Removes an agreement and records why it left (replacedBy null). */
99
+ declare function retireAgreement<N extends string>(state: WorkflowState<N>, text: string, by: string, now: string): WorkflowState<N>;
61
100
  declare function retireAgreement(state: WorkflowState, text: string, by: string, now: string): WorkflowState;
62
101
 
102
+ /** The part of a methodology policy evaluation reads: its `customPolicy` hook (spec 27, #36). */
103
+ type PolicyHook<N extends string> = Pick<Methodology<unknown, N>, "customPolicy">;
104
+ declare function evaluatePolicies<N extends string>(state: WorkflowState<N>, item: WorkItem, policies: Policy[], methodology?: PolicyHook<N>): Violation[];
63
105
  declare function evaluatePolicies(state: WorkflowState, item: WorkItem, policies: Policy[]): Violation[];
106
+ declare function assertPolicies<N extends string>(state: WorkflowState<N>, item: WorkItem, policies: Policy[], context: string, methodology?: PolicyHook<N>): void;
64
107
  declare function assertPolicies(state: WorkflowState, item: WorkItem, policies: Policy[], context: string): void;
65
108
 
66
109
  type GateResult = {
@@ -72,19 +115,28 @@ type GateResult = {
72
115
  violations: Violation[];
73
116
  };
74
117
  /** Last in_progress dispatch made from a stage that comes STRICTLY BEFORE the item's current stage in `state.stages` order (unknown stage ids count as not-before). */
118
+ declare function lastDispatchBefore(state: WorkflowState<string>, item: WorkItem): Transition | undefined;
75
119
  declare function lastDispatchBefore(state: WorkflowState, item: WorkItem): Transition | undefined;
76
120
  /** Role that did the work the gate guards: the last dispatch made from a stage strictly before the current one (so a reviewer dispatched into the gated stage is not its author); else the last dispatch of any stage; undefined if never dispatched. */
121
+ declare function authorOf(state: WorkflowState<string>, item: WorkItem): string | undefined;
77
122
  declare function authorOf(state: WorkflowState, item: WorkItem): string | undefined;
123
+ declare function checkGate(state: WorkflowState<string>, item: WorkItem, gate: Gate, by: string): GateResult;
78
124
  declare function checkGate(state: WorkflowState, item: WorkItem, gate: Gate, by: string): GateResult;
125
+ declare function raisePending<N extends string>(state: WorkflowState<N>, pending: Omit<PendingHuman, "id" | "raisedAt">, now?: string): WorkflowState<N>;
79
126
  declare function raisePending(state: WorkflowState, pending: Omit<PendingHuman, "id" | "raisedAt">, now?: string): WorkflowState;
127
+ declare function decide<N extends string>(state: WorkflowState<N>, pendingId: string, decision: "approve" | "reject", by: string, note: string, now?: string, methodology?: Methodology<unknown, N>): WorkflowState<N>;
80
128
  declare function decide(state: WorkflowState, pendingId: string, decision: "approve" | "reject", by: string, note: string, now?: string, methodology?: Methodology): WorkflowState;
81
129
 
82
130
  type NodeData = {
83
131
  id: string;
84
132
  };
133
+ declare function openIteration(state: WorkflowState<string>): Iteration | undefined;
85
134
  declare function openIteration(state: WorkflowState): Iteration | undefined;
135
+ declare function assignRole(state: WorkflowState<string>, item: WorkItem, roleFor?: (item: WorkItem) => string | undefined): Role;
86
136
  declare function assignRole(state: WorkflowState, item: WorkItem, roleFor?: (item: WorkItem) => string | undefined): Role;
137
+ declare function resourceCapsFor(state: WorkflowState<string>): Record<string, number>;
87
138
  declare function resourceCapsFor(state: WorkflowState): Record<string, number>;
139
+ declare function toExNodes(items: WorkItem[], state: WorkflowState<string>, priorityOf?: (item: WorkItem) => number | undefined, roleFor?: (item: WorkItem) => string | undefined): ExNode<NodeData>[];
88
140
  declare function toExNodes(items: WorkItem[], state: WorkflowState, priorityOf?: (item: WorkItem) => number | undefined, roleFor?: (item: WorkItem) => string | undefined): ExNode<NodeData>[];
89
141
  interface PlanOptions {
90
142
  max?: number;
@@ -98,30 +150,40 @@ interface Skipped {
98
150
  reason: "entry-policy" | "wip" | "resource-cap" | "budget";
99
151
  detail: string;
100
152
  }
101
- interface PlanResult {
102
- state: WorkflowState;
153
+ interface PlanResult<N extends string = MethodologyName> {
154
+ state: WorkflowState<N>;
103
155
  dispatched: WorkItem[];
104
156
  skipped: Skipped[];
105
157
  reason?: PlanReason;
106
158
  }
159
+ declare function plan<N extends string>(state: WorkflowState<N>, methodology: Methodology<unknown, N>, opts?: PlanOptions): PlanResult<N>;
107
160
  declare function plan(state: WorkflowState, methodology: Methodology, opts?: PlanOptions): PlanResult;
108
161
 
162
+ declare function synthesizeBrief<N extends string>(state: WorkflowState<N>, methodology: Methodology<unknown, N>, item: WorkItem): Brief;
109
163
  declare function synthesizeBrief(state: WorkflowState, methodology: Methodology, item: WorkItem): Brief;
110
164
  /** Open questions of finished items: the last completion per item, verdict done/needs-review, with open_questions left unanswered. */
165
+ declare function openQuestions(state: WorkflowState<string>): Array<{
166
+ item: string;
167
+ role: string;
168
+ questions: string[];
169
+ at: string;
170
+ }>;
111
171
  declare function openQuestions(state: WorkflowState): Array<{
112
172
  item: string;
113
173
  role: string;
114
174
  questions: string[];
115
175
  at: string;
116
176
  }>;
117
- interface NextResult {
118
- state: WorkflowState;
177
+ interface NextResult<N extends string = MethodologyName> {
178
+ state: WorkflowState<N>;
119
179
  briefs: Brief[];
120
180
  skipped: Skipped[];
121
181
  reason?: PlanReason;
122
182
  }
183
+ declare function next<N extends string>(state: WorkflowState<N>, methodology: Methodology<unknown, N>, opts?: PlanOptions): NextResult<N>;
123
184
  declare function next(state: WorkflowState, methodology: Methodology, opts?: PlanOptions): NextResult;
124
185
 
186
+ declare function complete<N extends string>(state: WorkflowState<N>, methodology: Methodology<unknown, N>, handoff: Handoff, acc: Accounting, now?: string): ApplyResult<N>;
125
187
  declare function complete(state: WorkflowState, methodology: Methodology, handoff: Handoff, acc: Accounting, now?: string): ApplyResult;
126
188
 
127
189
  interface AccountingPatch {
@@ -134,14 +196,18 @@ interface AccountingPatch {
134
196
  * Rewrite one accounting line of an item (`line` is 1-based among the item's lines, default the last).
135
197
  * The owning iteration's spent follows the delta, open or closed; the event records before/after.
136
198
  */
199
+ declare function correctAccounting<N extends string>(state: WorkflowState<N>, itemId: string, patch: AccountingPatch, by: string, now?: string, line?: number): WorkflowState<N>;
137
200
  declare function correctAccounting(state: WorkflowState, itemId: string, patch: AccountingPatch, by: string, now?: string, line?: number): WorkflowState;
138
201
 
202
+ declare function coreRulesFor<N extends string = MethodologyName>(methodology: Pick<Methodology, "requiredCapabilities">): Rule<N>[];
139
203
  declare function coreRulesFor(methodology: Pick<Methodology, "requiredCapabilities">): Rule[];
140
204
 
205
+ declare function validateAction<N extends string>(state: WorkflowState<N>, methodology: Methodology<unknown, N>, action: Action): Violation[];
141
206
  declare function validateAction(state: WorkflowState, methodology: Methodology, action: Action): Violation[];
207
+ declare function applyAction<N extends string>(state: WorkflowState<N>, methodology: Methodology<unknown, N>, action: Action, reduce: (s: WorkflowState<N>) => WorkflowState<N>): ApplyResult<N>;
142
208
  declare function applyAction(state: WorkflowState, methodology: Methodology, action: Action, reduce: (s: WorkflowState) => WorkflowState): ApplyResult;
143
- interface InitInput<C> {
144
- methodology: Methodology<C>;
209
+ interface InitInput<C, N extends string = MethodologyName> {
210
+ methodology: Methodology<C, N>;
145
211
  config: unknown;
146
212
  roles?: Role[];
147
213
  stages?: Stage[];
@@ -149,9 +215,73 @@ interface InitInput<C> {
149
215
  now?: string;
150
216
  }
151
217
  declare function init<C>(input: InitInput<C>): ApplyResult;
218
+ declare function init<C, N extends string>(input: InitInput<C, N>): ApplyResult<N>;
219
+ declare function init<C>(input: InitInput<C>): ApplyResult;
152
220
  /** Change the config between iterations: re-validated, recorded as config.changed, derived state kept in step by the methodology hook. */
221
+ declare function changeConfig<N extends string>(state: WorkflowState<N>, methodology: Methodology<unknown, N>, patch: Record<string, unknown>, by: string, now?: string): ApplyResult<N>;
153
222
  declare function changeConfig(state: WorkflowState, methodology: Methodology, patch: Record<string, unknown>, by: string, now?: string): ApplyResult;
154
223
 
155
- declare const VERSION = "1.1.1";
224
+ /**
225
+ * Extension records that 1.1 stored as top-level state fields. Writing one also writes its
226
+ * deprecated legacy mirror (`state.investigation`, `state.experimentation`) in memory; on disk
227
+ * only `ext` is stored (spec 26). 2.0 drops the mirror.
228
+ */
229
+ interface LegacyExtRecords {
230
+ investigation: InvestigationState;
231
+ experimentation: ExperimentationState;
232
+ }
233
+ type LegacyKey = keyof LegacyExtRecords;
234
+ /**
235
+ * Reads the extension record `key` (a methodology name or a common piece id) from `state.ext`.
236
+ * A state written before 1.2 has no `ext`; for `investigation` and `experimentation` the legacy
237
+ * top-level field is read instead.
238
+ */
239
+ declare function readExt<K extends LegacyKey>(state: WorkflowState<string>, key: K): LegacyExtRecords[K] | undefined;
240
+ declare function readExt<T = unknown>(state: WorkflowState<string>, key: string): T | undefined;
241
+ /**
242
+ * Returns a copy of `state` with `state.ext[key] = value`; `undefined` removes the key, and adds
243
+ * no empty `ext` to a state that had none. For `investigation` and `experimentation` the legacy
244
+ * top-level field is written (or removed) too, so SDK code reading `state.investigation` /
245
+ * `state.experimentation` sees the same record (dual-write, spec 26). The mirror is read-only:
246
+ * once `ext.<key>` exists, `readExt` ignores the legacy field. It does not make the state
247
+ * loadable by 1.1.x, whose schema rejects `ext`.
248
+ */
249
+ declare function writeExt<N extends string, K extends LegacyKey>(state: WorkflowState<N>, key: K, value: LegacyExtRecords[K] | undefined): WorkflowState<N>;
250
+ declare function writeExt<N extends string, T>(state: WorkflowState<N>, key: string, value: T | undefined): WorkflowState<N>;
251
+
252
+ /**
253
+ * Independence check: a verifying role must not be one that did the work.
254
+ *
255
+ * Returns the ids in `verifiers` that also appear in `workers`, each once, in verifier order;
256
+ * an empty array means the verification is independent. Ids are compared exactly. The caller
257
+ * decides how a conflict fails (a rule violation, a refused ceremony, a skipped role), so the
258
+ * check carries no message of its own.
259
+ *
260
+ * @example
261
+ * // a validator may not validate a candidate it built or integrated
262
+ * if (independenceConflicts(by, [candidate.author, integration.by]).length) refuse();
263
+ */
264
+ declare function independenceConflicts(verifiers: string | readonly string[], workers: readonly string[]): string[];
265
+
266
+ /**
267
+ * Frozen-input check: a frozen or preregistered record may not change after freeze.
268
+ *
269
+ * Compares each key of `frozen` (or only `keys`, when given) with the same key of `supplied`
270
+ * and returns the keys whose value differs, in key order; an empty array means the supplied
271
+ * input matches the freeze. Values are compared by identity (`!==`), so freeze primitive
272
+ * fields such as ids, SHAs and refs. Only own fields of `supplied` are read: a missing record,
273
+ * a missing field or an inherited one reads as `undefined`, which counts as a change unless the
274
+ * frozen value is `undefined` too. The caller decides how a change fails, so the check carries
275
+ * no message of its own.
276
+ *
277
+ * @example
278
+ * // a submission must reuse the frozen harness and base SHA
279
+ * if (frozenChanges({ harness, baseSha }, input).length) refuse();
280
+ */
281
+ declare function frozenChanges<K extends string>(frozen: {
282
+ readonly [P in K]?: unknown;
283
+ }, supplied: object | undefined, keys?: readonly K[]): K[];
284
+
285
+ declare const VERSION = "1.3.0";
156
286
 
157
- export { Accounting, type AccountingPatch, Action, ApplyResult, Brief, ErrorCode, Event, Evidence, Gate, type GateResult, Handoff, type InitInput, ItemPatch, ItemStatus, Iteration, Methodology, MethodologyName, NewItem, type NextResult, PendingHuman, type PlanOptions, type PlanReason, type PlanResult, Policy, Role, Rule, type Skipped, Stage, Transition, VERSION, Violation, WorkItem, WorkflowError, WorkflowState, addEvidence, addItem, appendEvent, applyAction, applyAgreement, assertId, assertPolicies, assignRole, authorOf, changeConfig, checkGate, clearBlocker, complete, coreRulesFor, correctAccounting, createState, decide, editItem, evaluatePolicies, fail, getItem, init, isTerminalStage, lastDispatchBefore, lastEvent, moveItem, next, nextStageOf, nowOf, openIteration, openQuestions, plan, raiseBlocker, raisePending, resourceCapsFor, retireAgreement, stageOf, synthesizeBrief, toExNodes, validateAction };
287
+ export { Accounting, type AccountingPatch, Action, ApplyResult, Brief, Capability, ErrorCode, Event, Evidence, Gate, type GateResult, Handoff, type InitInput, ItemPatch, ItemStatus, Iteration, type LegacyExtRecords, Methodology, MethodologyName, NewItem, type NextResult, PendingHuman, type PlanOptions, type PlanReason, type PlanResult, Policy, Role, Rule, type Skipped, Stage, Transition, VERSION, Violation, WorkItem, WorkflowError, WorkflowState, addEvidence, addItem, appendEvent, applyAction, applyAgreement, approversFor, assertId, assertPolicies, assignRole, authorOf, changeConfig, checkGate, clearBlocker, complete, coreRulesFor, correctAccounting, createState, decide, editItem, evaluatePolicies, fail, frozenChanges, getItem, hasCapability, independenceConflicts, init, isTerminalStage, lastDispatchBefore, lastEvent, moveItem, next, nextStageOf, nowOf, openIteration, openQuestions, plan, raiseBlocker, raisePending, readExt, registerRole, resourceCapsFor, retireAgreement, retireRole, rolesWith, stageOf, synthesizeBrief, toExNodes, validateAction, writeExt };
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export{d as complete,e as correctAccounting,c as next,b as openQuestions,a as synthesizeBrief}from'./chunk-ATCJ4IHP.mjs';import'./chunk-KIQOUUEZ.mjs';export{a as applyAgreement,b as retireAgreement}from'./chunk-NDCQTRIV.mjs';export{K as ZERO_SPENT,y as addEvidence,v as addItem,L as addSpent,c as appendEvent,W as applyAction,k as approversFor,E as assertPolicies,Q as assignRole,G as authorOf,n as canDo,Y as changeConfig,H as checkGate,A as clearBlocker,U as coreRulesFor,b as createState,J as decide,w as editItem,O as estimateTokens,D as evaluatePolicies,u as getItem,h as hasCapability,X as init,N as isExhausted,r as isTerminalStage,F as lastDispatchBefore,d as lastEvent,x as moveItem,q as nextStageOf,a as nowOf,P as openIteration,T as plan,z as raiseBlocker,I as raisePending,f as registerRole,M as remaining,o as requireCap,l as requireCapabilities,R as resourceCapsFor,g as retireRole,i as rolesWith,m as separationLost,p as stageOf,S as toExNodes,V as validateAction}from'./chunk-6P3OKXSK.mjs';export{a as WorkflowError,c as assertId,b as fail}from'./chunk-2FRRD6A3.mjs';var te="1.1.1";export{te as VERSION};//# sourceMappingURL=index.mjs.map
1
+ export{f as complete,g as correctAccounting,e as next,d as openQuestions,a as registerRole,b as retireRole,c as synthesizeBrief}from'./chunk-5GXB6GMX.mjs';import'./chunk-IDZ435YZ.mjs';export{a as applyAgreement,b as retireAgreement}from'./chunk-PFHVB2WT.mjs';export{a as frozenChanges}from'./chunk-BD665RYK.mjs';export{a as independenceConflicts}from'./chunk-WU5JELOM.mjs';export{a as readExt,b as writeExt}from'./chunk-TQR3VFZU.mjs';export{K as ZERO_SPENT,z as addEvidence,s as addItem,L as addSpent,c as appendEvent,W as applyAction,i as approversFor,D as assertPolicies,Q as assignRole,G as authorOf,l as canDo,Y as changeConfig,H as checkGate,B as clearBlocker,U as coreRulesFor,b as createState,J as decide,t as editItem,O as estimateTokens,C as evaluatePolicies,r as getItem,f as hasCapability,X as init,N as isExhausted,p as isTerminalStage,F as lastDispatchBefore,d as lastEvent,u as moveItem,o as nextStageOf,a as nowOf,P as openIteration,T as plan,A as raiseBlocker,I as raisePending,M as remaining,m as requireCap,j as requireCapabilities,R as resourceCapsFor,g as rolesWith,k as separationLost,n as stageOf,S as toExNodes,V as validateAction}from'./chunk-COPYGMHE.mjs';export{a as WorkflowError,c as assertId,b as fail}from'./chunk-YS6CXERQ.mjs';var ae="1.3.0";export{ae as VERSION};//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["VERSION"],"mappings":"2jCAAO,IAAMA,EAAAA,CAAU","file":"index.mjs","sourcesContent":["export const VERSION = \"1.1.1\";\nexport * from \"./types.ts\";\nexport { WorkflowError, fail } from \"./errors.ts\";\nexport { createState, appendEvent, lastEvent, nowOf } from \"./state.ts\";\nexport {\n registerRole,\n retireRole,\n hasCapability,\n rolesWith,\n approversFor,\n requireCapabilities,\n separationLost,\n canDo,\n requireCap,\n} from \"./roles.ts\";\nexport {\n assertId,\n stageOf,\n nextStageOf,\n isTerminalStage,\n getItem,\n addItem,\n editItem,\n moveItem,\n addEvidence,\n raiseBlocker,\n clearBlocker,\n} from \"./items.ts\";\nexport type { ItemPatch } from \"./items.ts\";\nexport { applyAgreement, retireAgreement } from \"./agreements.ts\";\nexport { evaluatePolicies, assertPolicies } from \"./policies.ts\";\nexport { checkGate, authorOf, lastDispatchBefore, raisePending, decide } from \"./gates.ts\";\nexport type { GateResult } from \"./gates.ts\";\nexport { ZERO_SPENT, addSpent, remaining, isExhausted, estimateTokens } from \"./budget.ts\";\nexport type { EstimateMode } from \"./budget.ts\";\nexport { plan, toExNodes, assignRole, resourceCapsFor, openIteration } from \"./planner.ts\";\nexport type { PlanOptions, PlanReason, PlanResult, Skipped } from \"./planner.ts\";\nexport { synthesizeBrief, next, openQuestions } from \"./brief.ts\";\nexport type { NextResult } from \"./brief.ts\";\nexport { complete } from \"./complete.ts\";\nexport { correctAccounting } from \"./accounting.ts\";\nexport type { AccountingPatch } from \"./accounting.ts\";\nexport { coreRulesFor } from \"./rules.ts\";\nexport { applyAction, validateAction, init, changeConfig } from \"./methodology.ts\";\nexport type { InitInput } from \"./methodology.ts\";\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":["VERSION"],"mappings":"0uCAAO,IAAMA,EAAAA,CAAU","file":"index.mjs","sourcesContent":["export const VERSION = \"1.3.0\";\nexport * from \"./core/types.ts\";\nexport { WorkflowError, fail } from \"./core/errors.ts\";\nexport { createState, appendEvent, lastEvent, nowOf } from \"./core/state.ts\";\nexport { registerRole, retireRole } from \"./core/roles/registry.ts\";\nexport { hasCapability, rolesWith, approversFor } from \"./core/roles/lookup.ts\";\nexport { requireCapabilities, separationLost, canDo, requireCap } from \"./core/roles/guards.ts\";\nexport { assertId } from \"./core/errors.ts\";\nexport { stageOf, nextStageOf, isTerminalStage } from \"./core/items/stage.ts\";\nexport { getItem, addItem, editItem } from \"./core/items/record.ts\";\nexport { moveItem } from \"./core/items/move.ts\";\nexport { addEvidence } from \"./core/items/evidence.ts\";\nexport { raiseBlocker, clearBlocker } from \"./core/items/blockers.ts\";\nexport type { ItemPatch } from \"./core/types.ts\";\nexport { applyAgreement, retireAgreement } from \"./core/agreements.ts\";\nexport { evaluatePolicies, assertPolicies } from \"./core/policies.ts\";\nexport { checkGate, authorOf, lastDispatchBefore, raisePending, decide } from \"./core/gates.ts\";\nexport type { GateResult } from \"./core/gates.ts\";\nexport { ZERO_SPENT, addSpent, remaining, isExhausted, estimateTokens } from \"./core/budget.ts\";\nexport type { EstimateMode } from \"./core/budget.ts\";\nexport { plan, toExNodes, assignRole, resourceCapsFor, openIteration } from \"./core/planner.ts\";\nexport type { PlanOptions, PlanReason, PlanResult, Skipped } from \"./core/planner.ts\";\nexport { synthesizeBrief, next, openQuestions } from \"./core/brief.ts\";\nexport type { NextResult } from \"./core/brief.ts\";\nexport { complete } from \"./core/complete.ts\";\nexport { correctAccounting } from \"./core/accounting.ts\";\nexport type { AccountingPatch } from \"./core/accounting.ts\";\nexport { coreRulesFor } from \"./core/rules.ts\";\nexport { applyAction, validateAction, init, changeConfig } from \"./core/methodology.ts\";\nexport type { InitInput } from \"./core/methodology.ts\";\nexport { readExt, writeExt } from \"./interface/ext.ts\";\nexport type { LegacyExtRecords } from \"./interface/ext.ts\";\nexport { independenceConflicts } from \"./common/independence.ts\";\nexport { frozenChanges } from \"./common/frozen.ts\";\n"]}
@@ -1,2 +1,2 @@
1
- 'use strict';var chunkSVGTSPZF_cjs=require('../chunk-SVGTSPZF.cjs');require('../chunk-EACZBAP3.cjs'),require('../chunk-S3BXVHO7.cjs');Object.defineProperty(exports,"investigation",{enumerable:true,get:function(){return chunkSVGTSPZF_cjs.b}});Object.defineProperty(exports,"validateInvestigationConfig",{enumerable:true,get:function(){return chunkSVGTSPZF_cjs.a}});//# sourceMappingURL=index.cjs.map
1
+ 'use strict';var chunkUMG3WOD7_cjs=require('../chunk-UMG3WOD7.cjs');require('../chunk-KLOSFZFK.cjs'),require('../chunk-6PFJYRM7.cjs'),require('../chunk-BBI7AKJK.cjs'),require('../chunk-MU26QW32.cjs'),require('../chunk-OSHBJIYD.cjs');Object.defineProperty(exports,"investigation",{enumerable:true,get:function(){return chunkUMG3WOD7_cjs.b}});Object.defineProperty(exports,"validateInvestigationConfig",{enumerable:true,get:function(){return chunkUMG3WOD7_cjs.a}});//# sourceMappingURL=index.cjs.map
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1,5 +1,5 @@
1
- import { a as Budget, M as Methodology } from '../types-BScHXlRx.cjs';
2
- export { b as BeliefUpdate, E as Experiment, c as Hypothesis, I as InvestigationConclusion, d as InvestigationRound, e as InvestigationState, O as Observation } from '../types-BScHXlRx.cjs';
1
+ import { a as Budget, M as Methodology } from '../types-DLOtndDY.cjs';
2
+ export { b as BeliefUpdate, E as Experiment, c as Hypothesis, I as InvestigationConclusion, d as InvestigationRound, e as InvestigationState, O as Observation } from '../types-DLOtndDY.cjs';
3
3
 
4
4
  interface InvestigationConfig {
5
5
  question: string;
@@ -1,5 +1,5 @@
1
- import { a as Budget, M as Methodology } from '../types-BScHXlRx.js';
2
- export { b as BeliefUpdate, E as Experiment, c as Hypothesis, I as InvestigationConclusion, d as InvestigationRound, e as InvestigationState, O as Observation } from '../types-BScHXlRx.js';
1
+ import { a as Budget, M as Methodology } from '../types-DLOtndDY.js';
2
+ export { b as BeliefUpdate, E as Experiment, c as Hypothesis, I as InvestigationConclusion, d as InvestigationRound, e as InvestigationState, O as Observation } from '../types-DLOtndDY.js';
3
3
 
4
4
  interface InvestigationConfig {
5
5
  question: string;
@@ -1,2 +1,2 @@
1
- export{b as investigation,a as validateInvestigationConfig}from'../chunk-7QQY4KJ2.mjs';import'../chunk-6P3OKXSK.mjs';import'../chunk-2FRRD6A3.mjs';//# sourceMappingURL=index.mjs.map
1
+ export{b as investigation,a as validateInvestigationConfig}from'../chunk-OEHVWRJG.mjs';import'../chunk-BD665RYK.mjs';import'../chunk-WU5JELOM.mjs';import'../chunk-TQR3VFZU.mjs';import'../chunk-COPYGMHE.mjs';import'../chunk-YS6CXERQ.mjs';//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map