ex-workflow 0.3.0-stage → 0.6.0-stage

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 (104) hide show
  1. package/CHANGELOG.md +52 -1
  2. package/README.md +73 -30
  3. package/dist/adapters/index.cjs +1 -1
  4. package/dist/adapters/index.mjs +1 -1
  5. package/dist/{roles-BLBRKhUZ.d.ts → budget-Cx63FX2K.d.ts} +9 -2
  6. package/dist/{roles-aneKYJ3Z.d.cts → budget-JyNKxP5N.d.cts} +9 -2
  7. package/dist/{chunk-7HZXZF3L.cjs → chunk-2OVYXXNV.cjs} +2 -2
  8. package/dist/chunk-2OVYXXNV.cjs.map +1 -0
  9. package/dist/chunk-3CLDZCHN.cjs +2 -0
  10. package/dist/chunk-3CLDZCHN.cjs.map +1 -0
  11. package/dist/chunk-5TXYMLBF.mjs +3 -0
  12. package/dist/chunk-5TXYMLBF.mjs.map +1 -0
  13. package/dist/chunk-7CDGPTEJ.mjs +2 -0
  14. package/dist/chunk-7CDGPTEJ.mjs.map +1 -0
  15. package/dist/chunk-7IG6EQI4.mjs +6 -0
  16. package/dist/chunk-7IG6EQI4.mjs.map +1 -0
  17. package/dist/chunk-GT57PLUT.mjs +2 -0
  18. package/dist/chunk-GT57PLUT.mjs.map +1 -0
  19. package/dist/chunk-IHE5K4X3.mjs +2 -0
  20. package/dist/chunk-IHE5K4X3.mjs.map +1 -0
  21. package/dist/chunk-KF5VQH3M.mjs +2 -0
  22. package/dist/chunk-KF5VQH3M.mjs.map +1 -0
  23. package/dist/chunk-MH66G5KV.cjs +2 -0
  24. package/dist/chunk-MH66G5KV.cjs.map +1 -0
  25. package/dist/chunk-N3QB2S7R.cjs +2 -0
  26. package/dist/chunk-N3QB2S7R.cjs.map +1 -0
  27. package/dist/chunk-NA53TZE4.mjs +2 -0
  28. package/dist/chunk-NA53TZE4.mjs.map +1 -0
  29. package/dist/chunk-TEPK5Y36.mjs +2 -0
  30. package/dist/chunk-TEPK5Y36.mjs.map +1 -0
  31. package/dist/chunk-UBFIKDIP.cjs +2 -0
  32. package/dist/chunk-UBFIKDIP.cjs.map +1 -0
  33. package/dist/chunk-UUOMQMWT.cjs +2 -0
  34. package/dist/chunk-UUOMQMWT.cjs.map +1 -0
  35. package/dist/chunk-WOGK54HB.cjs +3 -0
  36. package/dist/chunk-WOGK54HB.cjs.map +1 -0
  37. package/dist/chunk-YRATJT7P.cjs +6 -0
  38. package/dist/chunk-YRATJT7P.cjs.map +1 -0
  39. package/dist/chunk-Z3PU6EBI.mjs +2 -0
  40. package/dist/chunk-Z3PU6EBI.mjs.map +1 -0
  41. package/dist/chunk-ZTE7LREB.cjs +2 -0
  42. package/dist/chunk-ZTE7LREB.cjs.map +1 -0
  43. package/dist/cli/bin.cjs +1 -1
  44. package/dist/cli/bin.cjs.map +1 -1
  45. package/dist/cli/bin.mjs +1 -1
  46. package/dist/cli/bin.mjs.map +1 -1
  47. package/dist/cli/index.cjs +1 -1
  48. package/dist/cli/index.mjs +1 -1
  49. package/dist/index.cjs +1 -1
  50. package/dist/index.cjs.map +1 -1
  51. package/dist/index.d.cts +36 -13
  52. package/dist/index.d.ts +36 -13
  53. package/dist/index.mjs +1 -1
  54. package/dist/index.mjs.map +1 -1
  55. package/dist/kanban/index.cjs +1 -1
  56. package/dist/kanban/index.mjs +1 -1
  57. package/dist/schema/index.cjs +2 -0
  58. package/dist/schema/index.cjs.map +1 -0
  59. package/dist/schema/index.d.cts +57 -0
  60. package/dist/schema/index.d.ts +57 -0
  61. package/dist/schema/index.mjs +2 -0
  62. package/dist/schema/index.mjs.map +1 -0
  63. package/dist/scrum/index.cjs +1 -1
  64. package/dist/scrum/index.d.cts +18 -3
  65. package/dist/scrum/index.d.ts +18 -3
  66. package/dist/scrum/index.mjs +1 -1
  67. package/dist/types.d.cts +32 -3
  68. package/dist/types.d.ts +32 -3
  69. package/dist/waterfall/index.cjs +1 -1
  70. package/dist/waterfall/index.d.cts +2 -0
  71. package/dist/waterfall/index.d.ts +2 -0
  72. package/dist/waterfall/index.mjs +1 -1
  73. package/package.json +18 -2
  74. package/dist/chunk-23P7C25E.cjs +0 -2
  75. package/dist/chunk-23P7C25E.cjs.map +0 -1
  76. package/dist/chunk-2IKIBB73.cjs +0 -2
  77. package/dist/chunk-2IKIBB73.cjs.map +0 -1
  78. package/dist/chunk-4A4TD4MH.cjs +0 -2
  79. package/dist/chunk-4A4TD4MH.cjs.map +0 -1
  80. package/dist/chunk-6R3YFUUV.cjs +0 -6
  81. package/dist/chunk-6R3YFUUV.cjs.map +0 -1
  82. package/dist/chunk-7HZXZF3L.cjs.map +0 -1
  83. package/dist/chunk-AUZIQPFT.cjs +0 -2
  84. package/dist/chunk-AUZIQPFT.cjs.map +0 -1
  85. package/dist/chunk-BJEOTG6P.mjs +0 -2
  86. package/dist/chunk-BJEOTG6P.mjs.map +0 -1
  87. package/dist/chunk-FLCYD2QF.mjs +0 -2
  88. package/dist/chunk-FLCYD2QF.mjs.map +0 -1
  89. package/dist/chunk-NN3XJUHP.cjs +0 -2
  90. package/dist/chunk-NN3XJUHP.cjs.map +0 -1
  91. package/dist/chunk-P4P4JTE5.mjs +0 -2
  92. package/dist/chunk-P4P4JTE5.mjs.map +0 -1
  93. package/dist/chunk-R27STIER.mjs +0 -2
  94. package/dist/chunk-R27STIER.mjs.map +0 -1
  95. package/dist/chunk-TMKCALFT.cjs +0 -2
  96. package/dist/chunk-TMKCALFT.cjs.map +0 -1
  97. package/dist/chunk-UOGNVWVO.mjs +0 -2
  98. package/dist/chunk-UOGNVWVO.mjs.map +0 -1
  99. package/dist/chunk-VGD4V5BA.mjs +0 -6
  100. package/dist/chunk-VGD4V5BA.mjs.map +0 -1
  101. package/dist/chunk-WOKNWJKU.mjs +0 -2
  102. package/dist/chunk-WOKNWJKU.mjs.map +0 -1
  103. package/dist/chunk-ZX4DAMTG.mjs +0 -2
  104. package/dist/chunk-ZX4DAMTG.mjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/schema/generated.ts","../src/schema/validate.ts","../src/schema/index.ts"],"names":["CORE_DEFINITIONS","SCRUM_DEFINITIONS","KANBAN_DEFINITIONS","WATERFALL_DEFINITIONS","DEFS","kindOf","v","isType","t","show","s","esc","key","same","a","b","err","path","keyword","message","expected","found","resolve","ref","root","fail","name","def","rank","errors","branchPath","own","e","collapse","branches","first","candidate","consts","c","validate","schema","value","walk","out","types","items","i","obj","prop","at","known","best","failed","branch","merged","assertValid","what","more","DRAFT_07","document","definitions","workflowStateSchema","roleSchema","newItemSchema","itemPatchSchema","handoffSchema","scrumConfigSchema","kanbanConfigSchema","waterfallConfigSchema"],"mappings":"mEAIO,IAAMA,CAAAA,CAA+C,CAC1D,UAAA,CAAY,CACV,IAAA,CAAM,QAAA,CACN,UAAA,CAAY,CACV,IAAA,CAAM,CACJ,IAAA,CAAM,QACR,CAAA,CACA,IAAA,CAAM,CACJ,IAAA,CAAM,QACR,CAAA,CACA,KAAA,CAAO,CACL,IAAA,CAAM,QACR,CAAA,CACA,QAAA,CAAU,CACR,IAAA,CAAM,QACR,CAAA,CACA,SAAA,CAAW,CACT,IAAA,CAAM,QACR,CAAA,CACA,UAAA,CAAY,CACV,IAAA,CAAM,QACR,CAAA,CACA,SAAA,CAAW,CACT,IAAA,CAAM,QACR,CAAA,CACA,OAAA,CAAS,CACP,IAAA,CAAM,QACR,CAAA,CACA,QAAA,CAAU,CACR,IAAA,CAAM,SACR,CACF,CAAA,CACA,QAAA,CAAU,CACR,MAAA,CACA,MAAA,CACA,OAAA,CACA,UAAA,CACA,WAAA,CACA,aACA,WAAA,CACA,SACF,CAAA,CACA,oBAAA,CAAsB,KACxB,CAAA,CACA,QAAA,CAAU,CACR,IAAA,CAAM,QAAA,CACN,UAAA,CAAY,CACV,KAAA,CAAO,CACL,IAAA,CAAM,QACR,CAAA,CACA,OAAA,CAAS,CACP,IAAA,CAAM,QACR,CAAA,CACA,EAAA,CAAI,CACF,IAAA,CAAM,QACR,C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S,eAAA,CAAiB3D,CAAgB,CAAA,CAEhE8D,CAAAA,CAAaH,CAAAA,CAAS,MAAA,CAAQ3D,CAAgB,CAAA,CAE9C+D,CAAAA,CAAgBJ,CAAAA,CAAS,SAAA,CAAW3D,CAAgB,CAAA,CAEpDgE,CAAAA,CAAkBL,CAAAA,CAAS,WAAA,CAAa3D,CAAgB,CAAA,CAExDiE,CAAAA,CAAgBN,CAAAA,CAAS,SAAA,CAAW3D,CAAgB,CAAA,CAEpDkE,CAAAA,CAAoBP,CAAAA,CAAS,aAAA,CAAe1D,CAAiB,CAAA,CAC7DkE,CAAAA,CAAqBR,CAAAA,CAAS,cAAA,CAAgBzD,CAAkB,CAAA,CAChEkE,CAAAA,CAAwBT,CAAAA,CAAS,iBAAA,CAAmBxD,CAAqB","file":"chunk-WOGK54HB.cjs","sourcesContent":["// GENERATED by scripts/gen-schema.mjs from src/types.ts and src/{scrum,kanban,waterfall}/config.ts.\n// Do not edit. Run `pnpm schema:gen`; `pnpm schema:check` fails the build when this file is stale.\nimport type { JsonSchema } from \"./types.ts\";\n\nexport const CORE_DEFINITIONS: Record<string, JsonSchema> = {\n Accounting: {\n type: \"object\",\n properties: {\n item: {\n type: \"string\",\n },\n role: {\n type: \"string\",\n },\n model: {\n type: \"string\",\n },\n tokensIn: {\n type: \"number\",\n },\n tokensOut: {\n type: \"number\",\n },\n durationMs: {\n type: \"number\",\n },\n startedAt: {\n type: \"string\",\n },\n endedAt: {\n type: \"string\",\n },\n estimate: {\n type: \"boolean\",\n },\n },\n required: [\n \"item\",\n \"role\",\n \"model\",\n \"tokensIn\",\n \"tokensOut\",\n \"durationMs\",\n \"startedAt\",\n \"endedAt\",\n ],\n additionalProperties: false,\n },\n Baseline: {\n type: \"object\",\n properties: {\n phase: {\n type: \"string\",\n },\n version: {\n type: \"number\",\n },\n at: {\n type: \"string\",\n },\n approvedBy: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n itemSnapshot: {\n type: \"object\",\n additionalProperties: {\n $ref: \"#/definitions/WorkItem\",\n },\n },\n },\n required: [\"phase\", \"version\", \"at\", \"approvedBy\", \"itemSnapshot\"],\n additionalProperties: false,\n },\n Blocker: {\n type: \"object\",\n properties: {\n id: {\n type: \"string\",\n },\n reason: {\n type: \"string\",\n },\n owner: {\n type: \"string\",\n },\n raisedAt: {\n type: \"string\",\n },\n clearedAt: {\n type: \"string\",\n },\n },\n required: [\"id\", \"reason\", \"owner\", \"raisedAt\"],\n additionalProperties: false,\n },\n Budget: {\n type: \"object\",\n properties: {\n tokens: {\n type: \"number\",\n },\n turns: {\n type: \"number\",\n },\n wallclockMs: {\n type: \"number\",\n },\n },\n additionalProperties: false,\n },\n Capability: {\n type: \"string\",\n enum: [\n \"order-backlog\",\n \"define-acceptance\",\n \"facilitate\",\n \"deliver\",\n \"review\",\n \"verify\",\n \"approve-gate\",\n \"manage-flow\",\n \"control-change\",\n \"escalate\",\n ],\n },\n ClassOfService: {\n type: \"string\",\n enum: [\"expedite\", \"fixed-date\", \"standard\", \"intangible\"],\n },\n Event: {\n type: \"object\",\n properties: {\n seq: {\n type: \"number\",\n },\n at: {\n type: \"string\",\n },\n type: {\n type: \"string\",\n },\n by: {\n type: \"string\",\n },\n payload: {},\n },\n required: [\"seq\", \"at\", \"type\", \"by\", \"payload\"],\n additionalProperties: false,\n },\n Evidence: {\n type: \"object\",\n properties: {\n kind: {\n type: \"string\",\n },\n ref: {\n type: \"string\",\n },\n by: {\n type: \"string\",\n },\n at: {\n type: \"string\",\n },\n },\n required: [\"kind\", \"ref\", \"by\", \"at\"],\n additionalProperties: false,\n },\n Gate: {\n type: \"object\",\n properties: {\n id: {\n type: \"string\",\n },\n requires: {\n type: \"array\",\n items: {\n $ref: \"#/definitions/GateRequirement\",\n },\n },\n evidence: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n onFail: {\n anyOf: [\n {\n type: \"object\",\n properties: {\n action: {\n type: \"string\",\n const: \"block\",\n },\n },\n required: [\"action\"],\n additionalProperties: false,\n },\n {\n type: \"object\",\n properties: {\n action: {\n type: \"string\",\n const: \"return-to\",\n },\n stage: {\n type: \"string\",\n },\n },\n required: [\"action\", \"stage\"],\n additionalProperties: false,\n },\n ],\n },\n },\n required: [\"id\", \"requires\", \"evidence\", \"onFail\"],\n additionalProperties: false,\n },\n GateRequirement: {\n anyOf: [\n {\n type: \"string\",\n const: \"human\",\n },\n {\n type: \"object\",\n properties: {\n capability: {\n type: \"string\",\n },\n },\n required: [\"capability\"],\n additionalProperties: false,\n },\n ],\n },\n Handoff: {\n type: \"object\",\n properties: {\n item: {\n type: \"string\",\n },\n role: {\n type: \"string\",\n },\n produced: {\n type: \"array\",\n items: {\n type: \"object\",\n properties: {\n kind: {\n type: \"string\",\n },\n ref: {\n type: \"string\",\n },\n },\n required: [\"kind\", \"ref\"],\n additionalProperties: false,\n },\n },\n notes: {\n type: \"string\",\n },\n do_not: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n open_questions: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n verdict: {\n $ref: \"#/definitions/Verdict\",\n },\n follow_ups: {\n type: \"array\",\n items: {\n $ref: \"#/definitions/NewItem\",\n },\n },\n lessons: {\n type: \"array\",\n items: {\n type: \"object\",\n properties: {\n text: {\n type: \"string\",\n },\n scope: {\n type: \"string\",\n enum: [\"policy\", \"skill\", \"memory\", \"spec\", \"review\"],\n },\n },\n required: [\"text\", \"scope\"],\n additionalProperties: false,\n },\n },\n },\n required: [\"item\", \"role\", \"produced\", \"notes\", \"do_not\", \"open_questions\"],\n additionalProperties: false,\n },\n ImpactAnalysis: {\n type: \"object\",\n properties: {\n summary: {\n type: \"string\",\n },\n reopen: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n weight: {\n type: \"number\",\n },\n },\n required: [\"summary\", \"reopen\", \"weight\"],\n additionalProperties: false,\n },\n ItemPatch: {\n type: \"object\",\n properties: {\n type: {\n $ref: \"#/definitions/ItemType\",\n },\n title: {\n type: \"string\",\n },\n description: {\n type: \"string\",\n },\n dependsOn: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n priority: {\n type: \"number\",\n },\n weight: {\n type: \"number\",\n },\n deadline: {\n type: \"string\",\n },\n classOfService: {\n $ref: \"#/definitions/ClassOfService\",\n },\n role: {\n type: \"string\",\n },\n parent: {\n type: \"string\",\n },\n acceptance: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n iteration: {\n type: \"string\",\n },\n traces: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n tags: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n affects: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n phase: {\n type: \"string\",\n },\n impactAnalysis: {\n $ref: \"#/definitions/ImpactAnalysis\",\n },\n },\n additionalProperties: false,\n },\n ItemStatus: {\n type: \"string\",\n enum: [\"todo\", \"in_progress\", \"blocked\", \"review\", \"awaiting_human\", \"done\", \"dropped\"],\n },\n ItemType: {\n type: \"string\",\n enum: [\"epic\", \"story\", \"task\", \"bug\", \"change-request\", \"deliverable\", \"question\"],\n },\n Iteration: {\n type: \"object\",\n properties: {\n id: {\n type: \"string\",\n },\n goal: {\n type: \"string\",\n },\n budget: {\n $ref: \"#/definitions/Budget\",\n },\n spent: {\n $ref: \"#/definitions/Spent\",\n },\n startedAt: {\n type: \"string\",\n },\n endedAt: {\n type: \"string\",\n },\n committed: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n carryover: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n outcome: {\n type: \"string\",\n enum: [\"completed\", \"cancelled\"],\n },\n closing: {\n type: \"boolean\",\n },\n },\n required: [\"id\", \"goal\", \"budget\", \"spent\", \"startedAt\", \"committed\", \"carryover\"],\n additionalProperties: false,\n },\n Lesson: {\n type: \"object\",\n properties: {\n id: {\n type: \"string\",\n },\n at: {\n type: \"string\",\n },\n text: {\n type: \"string\",\n },\n scope: {\n type: \"string\",\n enum: [\"policy\", \"skill\", \"memory\", \"spec\", \"review\"],\n },\n status: {\n type: \"string\",\n enum: [\"raised\", \"adopted\", \"dismissed\"],\n },\n from: {\n type: \"string\",\n },\n item: {\n type: \"string\",\n },\n suggestedChange: {\n $ref: \"#/definitions/LessonChange\",\n },\n },\n required: [\"id\", \"at\", \"text\", \"scope\", \"status\"],\n additionalProperties: false,\n },\n LessonChange: {\n anyOf: [\n {\n type: \"object\",\n properties: {\n kind: {\n type: \"string\",\n const: \"agreement\",\n },\n text: {\n type: \"string\",\n },\n replaces: {\n type: \"string\",\n },\n },\n required: [\"kind\", \"text\"],\n additionalProperties: false,\n },\n {\n type: \"object\",\n properties: {\n kind: {\n type: \"string\",\n const: \"dod\",\n },\n policy: {\n $ref: \"#/definitions/Policy\",\n },\n },\n required: [\"kind\", \"policy\"],\n additionalProperties: false,\n },\n {\n type: \"object\",\n properties: {\n kind: {\n type: \"string\",\n const: \"backlog\",\n },\n item: {\n $ref: \"#/definitions/NewItem\",\n },\n },\n required: [\"kind\", \"item\"],\n additionalProperties: false,\n },\n {\n type: \"object\",\n properties: {\n kind: {\n type: \"string\",\n const: \"skill\",\n },\n note: {\n type: \"string\",\n },\n },\n required: [\"kind\", \"note\"],\n additionalProperties: false,\n },\n ],\n },\n MethodologyName: {\n type: \"string\",\n enum: [\"scrum\", \"kanban\", \"waterfall\"],\n },\n ModelTier: {\n type: \"string\",\n enum: [\"small\", \"medium\", \"large\"],\n },\n NewItem: {\n type: \"object\",\n additionalProperties: false,\n properties: {\n stage: {\n type: \"string\",\n },\n type: {\n $ref: \"#/definitions/ItemType\",\n },\n description: {\n type: \"string\",\n },\n dependsOn: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n priority: {\n type: \"number\",\n },\n weight: {\n type: \"number\",\n },\n deadline: {\n type: \"string\",\n },\n classOfService: {\n $ref: \"#/definitions/ClassOfService\",\n },\n role: {\n type: \"string\",\n },\n parent: {\n type: \"string\",\n },\n acceptance: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n iteration: {\n type: \"string\",\n },\n traces: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n tags: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n affects: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n phase: {\n type: \"string\",\n },\n impactAnalysis: {\n $ref: \"#/definitions/ImpactAnalysis\",\n },\n id: {\n type: \"string\",\n },\n title: {\n type: \"string\",\n },\n },\n required: [\"id\", \"title\"],\n },\n PendingHuman: {\n type: \"object\",\n properties: {\n id: {\n type: \"string\",\n },\n kind: {\n type: \"string\",\n enum: [\"gate\", \"decision\"],\n },\n item: {\n type: \"string\",\n },\n gate: {\n type: \"string\",\n },\n question: {\n type: \"string\",\n },\n raisedAt: {\n type: \"string\",\n },\n },\n required: [\"id\", \"kind\", \"question\", \"raisedAt\"],\n additionalProperties: false,\n },\n Phase: {\n type: \"object\",\n properties: {\n id: {\n type: \"string\",\n },\n name: {\n type: \"string\",\n },\n deliverables: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n gate: {\n $ref: \"#/definitions/Gate\",\n },\n status: {\n type: \"string\",\n enum: [\"pending\", \"open\", \"baselined\", \"reopened\"],\n },\n budget: {\n $ref: \"#/definitions/Budget\",\n },\n produced: {\n type: \"array\",\n items: {\n $ref: \"#/definitions/Produced\",\n },\n },\n },\n required: [\"id\", \"name\", \"deliverables\", \"gate\", \"status\"],\n additionalProperties: false,\n },\n Policy: {\n anyOf: [\n {\n type: \"object\",\n properties: {\n kind: {\n type: \"string\",\n const: \"evidence\",\n },\n evidenceKind: {\n type: \"string\",\n },\n },\n required: [\"kind\", \"evidenceKind\"],\n additionalProperties: false,\n },\n {\n type: \"object\",\n properties: {\n kind: {\n type: \"string\",\n const: \"acceptance-written\",\n },\n },\n required: [\"kind\"],\n additionalProperties: false,\n },\n {\n type: \"object\",\n properties: {\n kind: {\n type: \"string\",\n const: \"estimate-present\",\n },\n },\n required: [\"kind\"],\n additionalProperties: false,\n },\n {\n type: \"object\",\n properties: {\n kind: {\n type: \"string\",\n const: \"no-open-blockers\",\n },\n },\n required: [\"kind\"],\n additionalProperties: false,\n },\n {\n type: \"object\",\n properties: {\n kind: {\n type: \"string\",\n const: \"dependencies-done\",\n },\n },\n required: [\"kind\"],\n additionalProperties: false,\n },\n {\n type: \"object\",\n properties: {\n kind: {\n type: \"string\",\n const: \"custom\",\n },\n id: {\n type: \"string\",\n },\n description: {\n type: \"string\",\n },\n },\n required: [\"kind\", \"id\", \"description\"],\n additionalProperties: false,\n },\n ],\n },\n Produced: {\n type: \"object\",\n properties: {\n kind: {\n type: \"string\",\n },\n ref: {\n type: \"string\",\n },\n by: {\n type: \"string\",\n },\n at: {\n type: \"string\",\n },\n },\n required: [\"kind\", \"ref\", \"by\", \"at\"],\n additionalProperties: false,\n },\n Role: {\n type: \"object\",\n properties: {\n id: {\n type: \"string\",\n },\n name: {\n type: \"string\",\n },\n modelTier: {\n $ref: \"#/definitions/ModelTier\",\n },\n resourceClass: {\n type: \"string\",\n },\n maxConcurrent: {\n type: \"number\",\n },\n capabilities: {\n type: \"array\",\n items: {\n $ref: \"#/definitions/Capability\",\n },\n },\n canApprove: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n inputs: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n outputs: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n do_not: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n constraints: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n },\n required: [\n \"id\",\n \"name\",\n \"modelTier\",\n \"capabilities\",\n \"canApprove\",\n \"inputs\",\n \"outputs\",\n \"do_not\",\n ],\n additionalProperties: false,\n },\n Spent: {\n type: \"object\",\n properties: {\n tokens: {\n type: \"number\",\n },\n turns: {\n type: \"number\",\n },\n wallclockMs: {\n type: \"number\",\n },\n },\n required: [\"tokens\", \"turns\", \"wallclockMs\"],\n additionalProperties: false,\n },\n Stage: {\n type: \"object\",\n properties: {\n id: {\n type: \"string\",\n },\n name: {\n type: \"string\",\n },\n wipLimit: {\n type: \"number\",\n },\n entryPolicy: {\n type: \"array\",\n items: {\n $ref: \"#/definitions/Policy\",\n },\n },\n exitPolicy: {\n type: \"array\",\n items: {\n $ref: \"#/definitions/Policy\",\n },\n },\n gate: {\n $ref: \"#/definitions/Gate\",\n },\n commitmentPoint: {\n type: \"boolean\",\n },\n deliveryPoint: {\n type: \"boolean\",\n },\n review: {\n type: \"boolean\",\n },\n },\n required: [\"id\", \"name\", \"entryPolicy\", \"exitPolicy\"],\n additionalProperties: false,\n },\n Transition: {\n type: \"object\",\n properties: {\n from: {\n type: \"object\",\n properties: {\n stage: {\n type: \"string\",\n },\n status: {\n $ref: \"#/definitions/ItemStatus\",\n },\n },\n required: [\"stage\", \"status\"],\n additionalProperties: false,\n },\n to: {\n type: \"object\",\n properties: {\n stage: {\n type: \"string\",\n },\n status: {\n $ref: \"#/definitions/ItemStatus\",\n },\n },\n required: [\"stage\", \"status\"],\n additionalProperties: false,\n },\n at: {\n type: \"string\",\n },\n by: {\n type: \"string\",\n },\n },\n required: [\"from\", \"to\", \"at\", \"by\"],\n additionalProperties: false,\n },\n Verdict: {\n type: \"string\",\n enum: [\"done\", \"blocked\", \"needs-review\", \"rework\", \"escalate\"],\n },\n WorkItem: {\n type: \"object\",\n properties: {\n id: {\n type: \"string\",\n },\n type: {\n $ref: \"#/definitions/ItemType\",\n },\n title: {\n type: \"string\",\n },\n description: {\n type: \"string\",\n },\n dependsOn: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n priority: {\n type: \"number\",\n },\n weight: {\n type: \"number\",\n },\n deadline: {\n type: \"string\",\n },\n classOfService: {\n $ref: \"#/definitions/ClassOfService\",\n },\n stage: {\n type: \"string\",\n },\n status: {\n $ref: \"#/definitions/ItemStatus\",\n },\n role: {\n type: \"string\",\n },\n parent: {\n type: \"string\",\n },\n acceptance: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n evidence: {\n type: \"array\",\n items: {\n $ref: \"#/definitions/Evidence\",\n },\n },\n blockers: {\n type: \"array\",\n items: {\n $ref: \"#/definitions/Blocker\",\n },\n },\n transitions: {\n type: \"array\",\n items: {\n $ref: \"#/definitions/Transition\",\n },\n },\n iteration: {\n type: \"string\",\n },\n traces: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n tags: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n affects: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n phase: {\n type: \"string\",\n },\n impactAnalysis: {\n $ref: \"#/definitions/ImpactAnalysis\",\n },\n },\n required: [\n \"id\",\n \"type\",\n \"title\",\n \"dependsOn\",\n \"stage\",\n \"status\",\n \"acceptance\",\n \"evidence\",\n \"blockers\",\n \"transitions\",\n ],\n additionalProperties: false,\n },\n WorkflowState: {\n type: \"object\",\n properties: {\n version: {\n type: \"number\",\n const: 1,\n },\n methodology: {\n $ref: \"#/definitions/MethodologyName\",\n },\n config: {},\n items: {\n type: \"object\",\n additionalProperties: {\n $ref: \"#/definitions/WorkItem\",\n },\n },\n stages: {\n type: \"array\",\n items: {\n $ref: \"#/definitions/Stage\",\n },\n },\n roles: {\n type: \"object\",\n additionalProperties: {\n $ref: \"#/definitions/Role\",\n },\n },\n iterations: {\n type: \"array\",\n items: {\n $ref: \"#/definitions/Iteration\",\n },\n },\n phases: {\n type: \"array\",\n items: {\n $ref: \"#/definitions/Phase\",\n },\n },\n baseline: {\n $ref: \"#/definitions/Baseline\",\n },\n baselines: {\n type: \"array\",\n items: {\n $ref: \"#/definitions/Baseline\",\n },\n },\n events: {\n type: \"array\",\n items: {\n $ref: \"#/definitions/Event\",\n },\n },\n accounting: {\n type: \"array\",\n items: {\n $ref: \"#/definitions/Accounting\",\n },\n },\n pending: {\n type: \"array\",\n items: {\n $ref: \"#/definitions/PendingHuman\",\n },\n },\n lessons: {\n type: \"array\",\n items: {\n $ref: \"#/definitions/Lesson\",\n },\n },\n agreements: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n },\n required: [\n \"version\",\n \"methodology\",\n \"config\",\n \"items\",\n \"stages\",\n \"roles\",\n \"iterations\",\n \"events\",\n \"accounting\",\n \"pending\",\n \"lessons\",\n \"agreements\",\n ],\n additionalProperties: false,\n },\n};\n\nexport const SCRUM_DEFINITIONS: Record<string, JsonSchema> = {\n Budget: {\n type: \"object\",\n properties: {\n tokens: {\n type: \"number\",\n },\n turns: {\n type: \"number\",\n },\n wallclockMs: {\n type: \"number\",\n },\n },\n additionalProperties: false,\n },\n EstimateMode: {\n type: \"string\",\n enum: [\"per-weight\", \"per-call\"],\n },\n Policy: {\n anyOf: [\n {\n type: \"object\",\n properties: {\n kind: {\n type: \"string\",\n const: \"evidence\",\n },\n evidenceKind: {\n type: \"string\",\n },\n },\n required: [\"kind\", \"evidenceKind\"],\n additionalProperties: false,\n },\n {\n type: \"object\",\n properties: {\n kind: {\n type: \"string\",\n const: \"acceptance-written\",\n },\n },\n required: [\"kind\"],\n additionalProperties: false,\n },\n {\n type: \"object\",\n properties: {\n kind: {\n type: \"string\",\n const: \"estimate-present\",\n },\n },\n required: [\"kind\"],\n additionalProperties: false,\n },\n {\n type: \"object\",\n properties: {\n kind: {\n type: \"string\",\n const: \"no-open-blockers\",\n },\n },\n required: [\"kind\"],\n additionalProperties: false,\n },\n {\n type: \"object\",\n properties: {\n kind: {\n type: \"string\",\n const: \"dependencies-done\",\n },\n },\n required: [\"kind\"],\n additionalProperties: false,\n },\n {\n type: \"object\",\n properties: {\n kind: {\n type: \"string\",\n const: \"custom\",\n },\n id: {\n type: \"string\",\n },\n description: {\n type: \"string\",\n },\n },\n required: [\"kind\", \"id\", \"description\"],\n additionalProperties: false,\n },\n ],\n },\n ScrumConfig: {\n type: \"object\",\n properties: {\n sprintBudget: {\n $ref: \"#/definitions/Budget\",\n },\n productGoal: {\n type: \"string\",\n },\n definitionOfDone: {\n type: \"array\",\n items: {\n $ref: \"#/definitions/Policy\",\n },\n },\n refinementSharePct: {\n type: \"number\",\n },\n allowMidSprintAdd: {\n type: \"string\",\n enum: [\"never\", \"po-only\", \"any\"],\n },\n inProgressWipLimit: {\n type: \"number\",\n },\n autoClose: {\n type: \"boolean\",\n },\n estimateMode: {\n $ref: \"#/definitions/EstimateMode\",\n },\n fallbackTokensPerWeight: {\n type: \"number\",\n },\n },\n required: [\n \"sprintBudget\",\n \"productGoal\",\n \"definitionOfDone\",\n \"refinementSharePct\",\n \"allowMidSprintAdd\",\n ],\n additionalProperties: false,\n },\n};\n\nexport const KANBAN_DEFINITIONS: Record<string, JsonSchema> = {\n ClassConfig: {\n type: \"object\",\n properties: {\n wipBypass: {\n type: \"number\",\n },\n sle: {\n $ref: \"#/definitions/ServiceLevel\",\n },\n },\n additionalProperties: false,\n },\n KanbanColumn: {\n type: \"object\",\n properties: {\n id: {\n type: \"string\",\n },\n name: {\n type: \"string\",\n },\n wipLimit: {\n type: \"number\",\n },\n policies: {\n type: \"array\",\n items: {\n $ref: \"#/definitions/Policy\",\n },\n },\n commitmentPoint: {\n type: \"boolean\",\n },\n deliveryPoint: {\n type: \"boolean\",\n },\n review: {\n type: \"boolean\",\n },\n },\n required: [\"id\", \"name\", \"policies\"],\n additionalProperties: false,\n },\n KanbanConfig: {\n type: \"object\",\n properties: {\n columns: {\n type: \"array\",\n items: {\n $ref: \"#/definitions/KanbanColumn\",\n },\n },\n classesOfService: {\n type: \"object\",\n properties: {\n expedite: {\n $ref: \"#/definitions/ClassConfig\",\n },\n \"fixed-date\": {\n $ref: \"#/definitions/ClassConfig\",\n },\n standard: {\n $ref: \"#/definitions/ClassConfig\",\n },\n intangible: {\n $ref: \"#/definitions/ClassConfig\",\n },\n },\n additionalProperties: false,\n },\n fairness: {\n type: \"object\",\n properties: {\n aging: {\n type: \"boolean\",\n },\n maxDeferralRounds: {\n type: \"number\",\n },\n },\n required: [\"aging\", \"maxDeferralRounds\"],\n additionalProperties: false,\n },\n cadences: {\n type: \"object\",\n properties: {\n replenishment: {\n type: \"object\",\n properties: {\n everyTurns: {\n type: \"number\",\n },\n },\n additionalProperties: false,\n },\n \"delivery-planning\": {\n type: \"object\",\n properties: {\n everyTurns: {\n type: \"number\",\n },\n },\n additionalProperties: false,\n },\n \"service-delivery-review\": {\n type: \"object\",\n properties: {\n everyTurns: {\n type: \"number\",\n },\n },\n additionalProperties: false,\n },\n \"operations-review\": {\n type: \"object\",\n properties: {\n everyTurns: {\n type: \"number\",\n },\n },\n additionalProperties: false,\n },\n \"risk-review\": {\n type: \"object\",\n properties: {\n everyTurns: {\n type: \"number\",\n },\n },\n additionalProperties: false,\n },\n \"strategy-review\": {\n type: \"object\",\n properties: {\n everyTurns: {\n type: \"number\",\n },\n },\n additionalProperties: false,\n },\n },\n additionalProperties: false,\n },\n throughputWindowMs: {\n type: \"number\",\n },\n maxExpedite: {\n type: \"number\",\n },\n },\n required: [\n \"columns\",\n \"classesOfService\",\n \"fairness\",\n \"cadences\",\n \"throughputWindowMs\",\n \"maxExpedite\",\n ],\n additionalProperties: false,\n },\n Policy: {\n anyOf: [\n {\n type: \"object\",\n properties: {\n kind: {\n type: \"string\",\n const: \"evidence\",\n },\n evidenceKind: {\n type: \"string\",\n },\n },\n required: [\"kind\", \"evidenceKind\"],\n additionalProperties: false,\n },\n {\n type: \"object\",\n properties: {\n kind: {\n type: \"string\",\n const: \"acceptance-written\",\n },\n },\n required: [\"kind\"],\n additionalProperties: false,\n },\n {\n type: \"object\",\n properties: {\n kind: {\n type: \"string\",\n const: \"estimate-present\",\n },\n },\n required: [\"kind\"],\n additionalProperties: false,\n },\n {\n type: \"object\",\n properties: {\n kind: {\n type: \"string\",\n const: \"no-open-blockers\",\n },\n },\n required: [\"kind\"],\n additionalProperties: false,\n },\n {\n type: \"object\",\n properties: {\n kind: {\n type: \"string\",\n const: \"dependencies-done\",\n },\n },\n required: [\"kind\"],\n additionalProperties: false,\n },\n {\n type: \"object\",\n properties: {\n kind: {\n type: \"string\",\n const: \"custom\",\n },\n id: {\n type: \"string\",\n },\n description: {\n type: \"string\",\n },\n },\n required: [\"kind\", \"id\", \"description\"],\n additionalProperties: false,\n },\n ],\n },\n ServiceLevel: {\n type: \"object\",\n properties: {\n percentile: {\n type: \"number\",\n },\n targetMs: {\n type: \"number\",\n },\n },\n required: [\"percentile\", \"targetMs\"],\n additionalProperties: false,\n },\n};\n\nexport const WATERFALL_DEFINITIONS: Record<string, JsonSchema> = {\n Budget: {\n type: \"object\",\n properties: {\n tokens: {\n type: \"number\",\n },\n turns: {\n type: \"number\",\n },\n wallclockMs: {\n type: \"number\",\n },\n },\n additionalProperties: false,\n },\n Gate: {\n type: \"object\",\n properties: {\n id: {\n type: \"string\",\n },\n requires: {\n type: \"array\",\n items: {\n $ref: \"#/definitions/GateRequirement\",\n },\n },\n evidence: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n onFail: {\n anyOf: [\n {\n type: \"object\",\n properties: {\n action: {\n type: \"string\",\n const: \"block\",\n },\n },\n required: [\"action\"],\n additionalProperties: false,\n },\n {\n type: \"object\",\n properties: {\n action: {\n type: \"string\",\n const: \"return-to\",\n },\n stage: {\n type: \"string\",\n },\n },\n required: [\"action\", \"stage\"],\n additionalProperties: false,\n },\n ],\n },\n },\n required: [\"id\", \"requires\", \"evidence\", \"onFail\"],\n additionalProperties: false,\n },\n GateRequirement: {\n anyOf: [\n {\n type: \"string\",\n const: \"human\",\n },\n {\n type: \"object\",\n properties: {\n capability: {\n type: \"string\",\n },\n },\n required: [\"capability\"],\n additionalProperties: false,\n },\n ],\n },\n WaterfallConfig: {\n type: \"object\",\n properties: {\n phases: {\n type: \"array\",\n items: {\n $ref: \"#/definitions/WaterfallPhaseConfig\",\n },\n },\n changeControl: {\n type: \"object\",\n properties: {\n requiresImpactAnalysis: {\n type: \"boolean\",\n },\n approvers: {\n type: \"array\",\n items: {\n $ref: \"#/definitions/GateRequirement\",\n },\n },\n },\n required: [\"requiresImpactAnalysis\", \"approvers\"],\n additionalProperties: false,\n },\n traceability: {\n type: \"object\",\n properties: {\n from: {\n type: \"string\",\n },\n to: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n },\n required: [\"from\", \"to\"],\n additionalProperties: false,\n },\n humanGates: {\n anyOf: [\n {\n type: \"string\",\n const: \"all\",\n },\n {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n ],\n },\n fallbackTokensPerWeight: {\n type: \"number\",\n },\n },\n required: [\"phases\", \"changeControl\", \"traceability\", \"humanGates\"],\n additionalProperties: false,\n },\n WaterfallPhaseConfig: {\n type: \"object\",\n properties: {\n id: {\n type: \"string\",\n },\n name: {\n type: \"string\",\n },\n deliverables: {\n type: \"array\",\n items: {\n type: \"string\",\n },\n },\n gate: {\n $ref: \"#/definitions/Gate\",\n },\n budget: {\n $ref: \"#/definitions/Budget\",\n },\n deliverBy: {\n type: \"string\",\n },\n },\n required: [\"id\", \"name\", \"deliverables\", \"gate\"],\n additionalProperties: false,\n },\n};\n","import { fail } from \"../errors.ts\";\nimport type { JsonSchema, SchemaError } from \"./types.ts\";\n\nconst DEFS = \"#/definitions/\";\n\nfunction kindOf(v: unknown): string {\n if (v === null) return \"null\";\n if (Array.isArray(v)) return \"array\";\n return typeof v;\n}\nfunction isType(t: string, v: unknown): boolean {\n if (t === \"integer\") return typeof v === \"number\" && Number.isInteger(v);\n return kindOf(v) === t;\n}\nfunction show(v: unknown): string {\n const s = JSON.stringify(v);\n if (s === undefined) return String(v);\n return s.length > 60 ? `${s.slice(0, 57)}...` : s;\n}\n/** JSON-pointer escaping for one key. */\nfunction esc(key: string): string {\n return key.replace(/~/g, \"~0\").replace(/\\//g, \"~1\");\n}\nfunction same(a: unknown, b: unknown): boolean {\n return JSON.stringify(a) === JSON.stringify(b);\n}\nfunction err(\n path: string,\n keyword: string,\n message: string,\n expected: string,\n found: string,\n): SchemaError {\n return { path: path === \"\" ? \"/\" : path, keyword, message, expected, found };\n}\n\nfunction resolve(ref: string, root: JsonSchema): JsonSchema {\n if (!ref.startsWith(DEFS))\n fail(\n \"invalid-input\",\n `schema $ref ${JSON.stringify(ref)} is not #/definitions/<name>`,\n \"regenerate the schema with pnpm schema:gen\",\n );\n const name = ref.slice(DEFS.length);\n const def =\n root.definitions && Object.hasOwn(root.definitions, name) ? root.definitions[name] : undefined;\n if (!def)\n fail(\n \"invalid-input\",\n `schema $ref ${JSON.stringify(ref)} names no definition`,\n \"regenerate the schema with pnpm schema:gen\",\n );\n return def;\n}\n\n/**\n * Misfit of one anyOf branch (lower is a better fit): a `type` error at the branch's own path (the value is the\n * wrong kind entirely) weighs 1000, a `const` mismatch (a discriminator) 100, anything else 1.\n */\nfunction rank(errors: SchemaError[], branchPath: string): number {\n const own = branchPath === \"\" ? \"/\" : branchPath;\n return errors.reduce(\n (n, e) => n + (e.keyword === \"type\" && e.path === own ? 1000 : e.keyword === \"const\" ? 100 : 1),\n 0,\n );\n}\n\n/** When every failed branch has a `const` error at one pointer (the discriminator), report that once as an enum. */\nfunction collapse(branches: SchemaError[][]): SchemaError | undefined {\n const first = branches[0]?.filter((e) => e.keyword === \"const\") ?? [];\n for (const candidate of first) {\n const consts = branches.map((b) =>\n b.find((e) => e.keyword === \"const\" && e.path === candidate.path),\n );\n if (consts.some((c) => c === undefined)) continue;\n const expected = [...new Set(consts.map((c) => c?.expected))].join(\" | \");\n return {\n path: candidate.path,\n keyword: \"enum\",\n message: `expected one of ${expected}`,\n expected,\n found: candidate.found,\n };\n }\n return undefined;\n}\n\n/** Validate `value` against `schema` (a document: `$ref`s resolve against its `definitions`). Returns every error found. */\nexport function validate(schema: JsonSchema, value: unknown): SchemaError[] {\n return walk(schema, value, schema, \"\");\n}\n\nfunction walk(schema: JsonSchema, value: unknown, root: JsonSchema, path: string): SchemaError[] {\n if (schema.$ref !== undefined) return walk(resolve(schema.$ref, root), value, root, path);\n const out: SchemaError[] = [];\n if (schema.type !== undefined) {\n const types = Array.isArray(schema.type) ? schema.type : [schema.type];\n if (!types.some((t) => isType(t, value))) {\n const expected = types.join(\" | \");\n return [\n err(path, \"type\", `expected ${expected}, got ${kindOf(value)}`, expected, show(value)),\n ];\n }\n }\n if (schema.const !== undefined && !same(value, schema.const))\n out.push(err(path, \"const\", `expected ${show(schema.const)}`, show(schema.const), show(value)));\n if (schema.enum !== undefined && !schema.enum.some((e) => same(e, value))) {\n const expected = schema.enum.map(show).join(\" | \");\n out.push(err(path, \"enum\", `expected one of ${expected}`, expected, show(value)));\n }\n if (typeof value === \"number\") {\n if (schema.minimum !== undefined && value < schema.minimum)\n out.push(\n err(path, \"minimum\", `expected >= ${schema.minimum}`, `>= ${schema.minimum}`, show(value)),\n );\n if (schema.maximum !== undefined && value > schema.maximum)\n out.push(\n err(path, \"maximum\", `expected <= ${schema.maximum}`, `<= ${schema.maximum}`, show(value)),\n );\n }\n if (typeof value === \"string\") {\n if (schema.minLength !== undefined && value.length < schema.minLength)\n out.push(\n err(\n path,\n \"minLength\",\n `expected at least ${schema.minLength} characters`,\n `length >= ${schema.minLength}`,\n show(value),\n ),\n );\n if (schema.pattern !== undefined && !new RegExp(schema.pattern, \"u\").test(value))\n out.push(\n err(\n path,\n \"pattern\",\n `expected to match /${schema.pattern}/`,\n `/${schema.pattern}/`,\n show(value),\n ),\n );\n }\n if (Array.isArray(value) && schema.items !== undefined) {\n const items = schema.items;\n value.forEach((v, i) => out.push(...walk(items, v, root, `${path}/${i}`)));\n }\n if (kindOf(value) === \"object\") {\n const obj = value as Record<string, unknown>;\n for (const [key, v] of Object.entries(obj)) {\n const prop =\n schema.properties && Object.hasOwn(schema.properties, key)\n ? schema.properties[key]\n : undefined;\n const at = `${path}/${esc(key)}`;\n if (prop) out.push(...walk(prop, v, root, at));\n else if (schema.additionalProperties === false) {\n const known = Object.keys(schema.properties ?? {}).join(\", \");\n out.push(\n err(\n at,\n \"additionalProperties\",\n `unknown property ${JSON.stringify(key)}`,\n known ? `one of ${known}` : \"no properties\",\n key,\n ),\n );\n } else if (typeof schema.additionalProperties === \"object\")\n out.push(...walk(schema.additionalProperties, v, root, at));\n }\n for (const key of schema.required ?? [])\n if (!Object.hasOwn(obj, key))\n out.push(\n err(\n `${path}/${esc(key)}`,\n \"required\",\n `missing required property ${JSON.stringify(key)}`,\n \"present\",\n \"absent\",\n ),\n );\n }\n if (schema.anyOf !== undefined) {\n let best: SchemaError[] | undefined;\n const failed: SchemaError[][] = [];\n for (const branch of schema.anyOf) {\n const errors = walk(branch, value, root, path);\n if (errors.length === 0) {\n best = [];\n break;\n }\n failed.push(errors);\n if (best === undefined || rank(errors, path) < rank(best, path)) best = errors;\n }\n const merged = best && best.length > 0 ? collapse(failed) : undefined;\n if (merged) out.push(merged);\n else if (best) out.push(...best);\n }\n return out;\n}\n\n/** Throw WorkflowError(\"invalid-input\") describing the first problem when `value` does not match `schema`. */\nexport function assertValid(schema: JsonSchema, value: unknown, what: string): void {\n const errors = validate(schema, value);\n const first = errors[0];\n if (!first) return;\n const more = errors.length > 1 ? ` (+${errors.length - 1} more)` : \"\";\n fail(\n \"invalid-input\",\n `${what} does not match its schema: ${first.path} ${first.message}${more}`,\n `fix ${what} at ${first.path}: expected ${first.expected}, found ${first.found}`,\n );\n}\n","import {\n CORE_DEFINITIONS,\n KANBAN_DEFINITIONS,\n SCRUM_DEFINITIONS,\n WATERFALL_DEFINITIONS,\n} from \"./generated.ts\";\nimport type { JsonSchema, JsonSchemaDocument } from \"./types.ts\";\n\nexport const DRAFT_07 = \"http://json-schema.org/draft-07/schema#\";\n\nfunction document(name: string, definitions: Record<string, JsonSchema>): JsonSchemaDocument {\n return { $schema: DRAFT_07, $ref: `#/definitions/${name}`, definitions };\n}\n\n/** `.workflow/state.json` */\nexport const workflowStateSchema = document(\"WorkflowState\", CORE_DEFINITIONS);\n/** a role manifest (`.workflow/roles/*.json`, `exwf role add`) */\nexport const roleSchema = document(\"Role\", CORE_DEFINITIONS);\n/** `exwf add <item.json>` */\nexport const newItemSchema = document(\"NewItem\", CORE_DEFINITIONS);\n/** `exwf edit <id> <patch.json>` */\nexport const itemPatchSchema = document(\"ItemPatch\", CORE_DEFINITIONS);\n/** `exwf complete <id> <handoff.json>` */\nexport const handoffSchema = document(\"Handoff\", CORE_DEFINITIONS);\n/** `exwf init scrum --config` / the scrum-master policy.json */\nexport const scrumConfigSchema = document(\"ScrumConfig\", SCRUM_DEFINITIONS);\nexport const kanbanConfigSchema = document(\"KanbanConfig\", KANBAN_DEFINITIONS);\nexport const waterfallConfigSchema = document(\"WaterfallConfig\", WATERFALL_DEFINITIONS);\n\nexport { validate, assertValid } from \"./validate.ts\";\nexport type { JsonSchema, JsonSchemaDocument, SchemaError } from \"./types.ts\";\n"]}
@@ -0,0 +1,6 @@
1
+ 'use strict';var chunkWOGK54HB_cjs=require('./chunk-WOGK54HB.cjs'),chunkS3BXVHO7_cjs=require('./chunk-S3BXVHO7.cjs'),promises=require('fs/promises'),crypto=require('crypto'),n=require('path');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var n__default=/*#__PURE__*/_interopDefault(n);var m=".workflow";function v(t){return n__default.default.join(t,m,"state.json")}async function y(t,e){let i=`${t}.tmp-${process.pid}-${crypto.randomBytes(4).toString("hex")}`;try{await promises.mkdir(n__default.default.dirname(t),{recursive:!0}),await promises.writeFile(i,e,"utf8"),await promises.rename(i,t);}catch(r){await promises.unlink(i).catch(()=>{}),chunkS3BXVHO7_cjs.b("invalid-input",`cannot write ${t}: ${r.message}`,"check the directory exists and is writable");}}async function T(t,e,i={}){let{retries:r=40,intervalMs:w=50,staleMs:u=6e4}=i,s=n__default.default.join(t,m,"state.lock");await promises.mkdir(n__default.default.dirname(s),{recursive:true});let d=false;for(let f=0;!d;f++)try{let a=await promises.open(s,"wx");await a.writeFile(`${process.pid} ${new Date().toISOString()}
2
+ `),await a.close(),d=!0;}catch(a){if(a.code!=="EEXIST")throw a;let o=await promises.stat(s).catch(()=>{});if(o&&Date.now()-o.mtimeMs>u){let l=await promises.stat(s).catch(()=>{});l&&l.ino===o.ino&&l.mtimeMs===o.mtimeMs&&await promises.unlink(s).catch(()=>{});continue}f>=r&&chunkS3BXVHO7_cjs.b("invalid-input","another exwf command holds .workflow/state.lock","retry, or delete the file if no exwf process is running"),await new Promise(l=>setTimeout(l,w));}try{return await e()}finally{await promises.unlink(s).catch(()=>{});}}async function B(t,e){let i=JSON.stringify(e,null,2)+`
3
+ `;chunkWOGK54HB_cjs.b(chunkWOGK54HB_cjs.d,JSON.parse(i),v(t)),await y(v(t),i);}async function F(t){let e=v(t),i;try{i=await promises.readFile(e,"utf8");}catch{chunkS3BXVHO7_cjs.b("invalid-input",`no workflow state at ${e}`,"run `exwf init <scrum|kanban|waterfall> --config <file>` in this directory first");}let r;try{r=JSON.parse(i);}catch(f){chunkS3BXVHO7_cjs.b("invalid-input",`${e} is not valid JSON: ${f.message}`,"restore it from git or re-run exwf init");}(typeof r!="object"||r===null||Array.isArray(r))&&chunkS3BXVHO7_cjs.b("invalid-input",`${e} does not contain a workflow state object`,"restore it from git or re-run exwf init");let w=r;w.version!==1&&chunkS3BXVHO7_cjs.b("state-version",`${e} has schema version ${String(w.version)}; this ex-workflow reads version 1`,"upgrade ex-workflow, or run the migration this version documents in its changelog"),chunkWOGK54HB_cjs.b(chunkWOGK54HB_cjs.d,r,e);let u=n__default.default.join(t,m,"roles"),s=[];try{s=(await promises.readdir(u)).filter(f=>f.endsWith(".json"));}catch{}let d={...w.roles};for(let f of s){let a=n__default.default.join(u,f),o;try{o=JSON.parse(await promises.readFile(a,"utf8"));}catch(l){chunkS3BXVHO7_cjs.b("invalid-input",`role manifest ${a} is not valid JSON: ${l.message}`,"fix or delete that manifest");}chunkWOGK54HB_cjs.b(chunkWOGK54HB_cjs.e,o,`role manifest ${a}`),d[o.id]||(d[o.id]=o);}return {...w,roles:d}}function j(t,e){return n__default.default.resolve(e).startsWith(n__default.default.resolve(t,m)+n__default.default.sep)||chunkS3BXVHO7_cjs.b("invalid-input",`${e} resolves outside ${m}/`,"use a plain item id (letters, digits, - _ .)"),e}async function L(t,e){let i=j(t,n__default.default.join(t,m,"briefs",`${e.item.id}.json`));return await y(i,JSON.stringify(e,null,2)+`
4
+ `),i}async function A(t,e,i){let r=j(t,n__default.default.join(t,m,"handoffs",`${e.item}-${i}.json`));return await y(r,JSON.stringify(e,null,2)+`
5
+ `),r}exports.a=m;exports.b=v;exports.c=T;exports.d=B;exports.e=F;exports.f=L;exports.g=A;//# sourceMappingURL=chunk-YRATJT7P.cjs.map
6
+ //# sourceMappingURL=chunk-YRATJT7P.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/adapters/file.ts"],"names":["WORKFLOW_DIR","statePath","root","path","writeAtomic","file","content","tmp","randomBytes","mkdir","writeFile","rename","e","unlink","fail","withStateLock","fn","opts","retries","intervalMs","staleMs","lock","held","attempt","fh","open","snap","stat","now","resolve","saveState","state","json","assertValid","workflowStateSchema","loadState","raw","readFile","parsed","rolesDir","manifests","readdir","roles","manifestPath","role","roleSchema","inWorkflowDir","saveBrief","brief","saveHandoff","handoff","seq"],"mappings":"gTAOO,IAAMA,EAAe,YAErB,SAASC,EAAUC,CAAAA,CAAsB,CAC9C,OAAOC,kBAAAA,CAAK,KAAKD,CAAAA,CAAMF,CAAAA,CAAc,YAAY,CACnD,CAEA,eAAeI,CAAAA,CAAYC,CAAAA,CAAcC,CAAAA,CAAgC,CACvE,IAAMC,CAAAA,CAAM,CAAA,EAAGF,CAAI,CAAA,KAAA,EAAQ,OAAA,CAAQ,GAAG,CAAA,CAAA,EAAIG,kBAAAA,CAAY,CAAC,CAAA,CAAE,SAAS,KAAK,CAAC,GACxE,GAAI,CACF,MAAMC,cAAAA,CAAMN,kBAAAA,CAAK,OAAA,CAAQE,CAAI,EAAG,CAAE,SAAA,CAAW,EAAK,CAAC,CAAA,CACnD,MAAMK,kBAAAA,CAAUH,CAAAA,CAAKD,EAAS,MAAM,CAAA,CACpC,MAAMK,eAAAA,CAAOJ,CAAAA,CAAKF,CAAI,EACxB,CAAA,MAASO,EAAG,CAEV,MAAMC,eAAAA,CAAON,CAAG,EAAE,KAA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,CAAAA,CAAcgD,CAAAA,CAAkBC,CAAAA,CAA8B,CAC9F,IAAM9C,CAAAA,CAAOyC,CAAAA,CACX5C,CAAAA,CACAC,kBAAAA,CAAK,KAAKD,CAAAA,CAAMF,CAAAA,CAAc,UAAA,CAAY,CAAA,EAAGkD,CAAAA,CAAQ,IAAI,CAAA,CAAA,EAAIC,CAAG,OAAO,CACzE,CAAA,CACA,OAAA,MAAM/C,CAAAA,CAAYC,EAAM,IAAA,CAAK,SAAA,CAAU6C,CAAAA,CAAS,IAAA,CAAM,CAAC,CAAA,CAAI;AAAA,CAAI,EACxD7C,CACT","file":"chunk-YRATJT7P.cjs","sourcesContent":["import { mkdir, open, readFile, readdir, rename, stat, unlink, writeFile } from \"node:fs/promises\";\nimport { randomBytes } from \"node:crypto\";\nimport path from \"node:path\";\nimport { fail } from \"../errors.ts\";\nimport { assertValid, roleSchema, workflowStateSchema } from \"../schema/index.ts\";\nimport type { Brief, Handoff, Role, WorkflowState } from \"../types.ts\";\n\nexport const WORKFLOW_DIR = \".workflow\";\n\nexport function statePath(root: string): string {\n return path.join(root, WORKFLOW_DIR, \"state.json\");\n}\n\nasync function writeAtomic(file: string, content: string): Promise<void> {\n const tmp = `${file}.tmp-${process.pid}-${randomBytes(4).toString(\"hex\")}`;\n try {\n await mkdir(path.dirname(file), { recursive: true });\n await writeFile(tmp, content, \"utf8\");\n await rename(tmp, file);\n } catch (e) {\n // best effort: remove the temp file if it was created; ignore failure\n await unlink(tmp).catch(() => undefined);\n fail(\n \"invalid-input\",\n `cannot write ${file}: ${(e as Error).message}`,\n \"check the directory exists and is writable\",\n );\n }\n}\n\nexport interface LockOptions {\n retries?: number;\n intervalMs?: number;\n staleMs?: number;\n}\n\n/** Run `fn` while holding `.workflow/state.lock`, so concurrent exwf commands cannot lose each other's updates. */\nexport async function withStateLock<T>(\n root: string,\n fn: () => Promise<T>,\n opts: LockOptions = {},\n): Promise<T> {\n const { retries = 40, intervalMs = 50, staleMs = 60_000 } = opts;\n const lock = path.join(root, WORKFLOW_DIR, \"state.lock\");\n await mkdir(path.dirname(lock), { recursive: true });\n let held = false;\n for (let attempt = 0; !held; attempt++) {\n try {\n const fh = await open(lock, \"wx\");\n await fh.writeFile(`${process.pid} ${new Date().toISOString()}\\n`);\n await fh.close();\n held = true;\n } catch (e) {\n if ((e as NodeJS.ErrnoException).code !== \"EEXIST\") throw e;\n const snap = await stat(lock).catch(() => undefined);\n if (snap && Date.now() - snap.mtimeMs > staleMs) {\n // re-stat just before unlink: if another recoverer already replaced the lock, leave it alone\n const now = await stat(lock).catch(() => undefined);\n if (now && now.ino === snap.ino && now.mtimeMs === snap.mtimeMs)\n await unlink(lock).catch(() => undefined);\n continue;\n }\n if (attempt >= retries)\n fail(\n \"invalid-input\",\n \"another exwf command holds .workflow/state.lock\",\n \"retry, or delete the file if no exwf process is running\",\n );\n await new Promise((resolve) => setTimeout(resolve, intervalMs));\n }\n }\n try {\n return await fn();\n } finally {\n await unlink(lock).catch(() => undefined);\n }\n}\n\nexport async function saveState(root: string, state: WorkflowState): Promise<void> {\n const json = JSON.stringify(state, null, 2) + \"\\n\";\n assertValid(workflowStateSchema, JSON.parse(json), statePath(root));\n await writeAtomic(statePath(root), json);\n}\n\nexport async function loadState(root: string): Promise<WorkflowState> {\n const file = statePath(root);\n let raw: string;\n try {\n raw = await readFile(file, \"utf8\");\n } catch {\n fail(\n \"invalid-input\",\n `no workflow state at ${file}`,\n \"run `exwf init <scrum|kanban|waterfall> --config <file>` in this directory first\",\n );\n }\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch (e) {\n fail(\n \"invalid-input\",\n `${file} is not valid JSON: ${(e as Error).message}`,\n \"restore it from git or re-run exwf init\",\n );\n }\n if (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) {\n fail(\n \"invalid-input\",\n `${file} does not contain a workflow state object`,\n \"restore it from git or re-run exwf init\",\n );\n }\n const state = parsed as WorkflowState;\n if (state.version !== 1)\n fail(\n \"state-version\",\n `${file} has schema version ${String(state.version)}; this ex-workflow reads version 1`,\n \"upgrade ex-workflow, or run the migration this version documents in its changelog\",\n );\n assertValid(workflowStateSchema, parsed, file);\n const rolesDir = path.join(root, WORKFLOW_DIR, \"roles\");\n let manifests: string[] = [];\n try {\n manifests = (await readdir(rolesDir)).filter((f) => f.endsWith(\".json\"));\n } catch {\n /* no extra roles */\n }\n const roles = { ...state.roles };\n for (const f of manifests) {\n const manifestPath = path.join(rolesDir, f);\n let role: Role;\n try {\n role = JSON.parse(await readFile(manifestPath, \"utf8\")) as Role;\n } catch (e) {\n fail(\n \"invalid-input\",\n `role manifest ${manifestPath} is not valid JSON: ${(e as Error).message}`,\n \"fix or delete that manifest\",\n );\n }\n assertValid(roleSchema, role, `role manifest ${manifestPath}`);\n if (!roles[role.id]) roles[role.id] = role;\n }\n return { ...state, roles };\n}\n\nfunction inWorkflowDir(root: string, file: string): string {\n if (!path.resolve(file).startsWith(path.resolve(root, WORKFLOW_DIR) + path.sep))\n fail(\n \"invalid-input\",\n `${file} resolves outside ${WORKFLOW_DIR}/`,\n \"use a plain item id (letters, digits, - _ .)\",\n );\n return file;\n}\n\nexport async function saveBrief(root: string, brief: Brief): Promise<string> {\n const file = inWorkflowDir(\n root,\n path.join(root, WORKFLOW_DIR, \"briefs\", `${brief.item.id}.json`),\n );\n await writeAtomic(file, JSON.stringify(brief, null, 2) + \"\\n\");\n return file;\n}\n\nexport async function saveHandoff(root: string, handoff: Handoff, seq: number): Promise<string> {\n const file = inWorkflowDir(\n root,\n path.join(root, WORKFLOW_DIR, \"handoffs\", `${handoff.item}-${seq}.json`),\n );\n await writeAtomic(file, JSON.stringify(handoff, null, 2) + \"\\n\");\n return file;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import {b as b$1,c}from'./chunk-2FRRD6A3.mjs';import {ExFlow,ExFlowRuntimeError}from'ex-flow';function b(t){return t??new Date().toISOString()}function Y(t){let e=new Set;for(let i of t.stages)e.has(i.id)&&b$1("config-invalid",`duplicate stage id "${i.id}"`,"give every stage a unique id"),e.add(i.id);let n={};for(let i of t.roles)c(i.id,"role id"),Object.hasOwn(n,i.id)&&b$1("duplicate-role",`duplicate role id "${i.id}"`,"give every role a unique id"),n[i.id]=i;let o=b(t.now);return {version:1,methodology:t.methodology,config:t.config,items:{},stages:t.stages,roles:n,iterations:[],events:[{seq:1,at:o,type:"state.created",by:"system",payload:{methodology:t.methodology}}],accounting:[],pending:[],lessons:[],agreements:[]}}function h(t,e,n,o,i){let s={seq:(t.events[t.events.length-1]?.seq??0)+1,at:b(i),type:e,by:n,payload:o};return {...t,events:[...t.events,s]}}function je(t,e){for(let n=t.events.length-1;n>=0;n--){let o=t.events[n];if(e===void 0||o.type===e)return o}}function A(t,e){return Object.hasOwn(t.roles,e)?t.roles[e]:void 0}var me=new Set(["in_progress","review","blocked"]);function Ee(t,e,n,o){c(e.id,"role id"),A(t,e.id)&&b$1("duplicate-role",`role "${e.id}" already exists`,`use a different id or retireRole("${e.id}") first`);let i={...t,roles:{...t.roles,[e.id]:e}};return h(i,"role.registered",n,{role:e.id,capabilities:e.capabilities},o)}function Pe(t,e,n,o){A(t,e)||b$1("unknown-role",`role "${e}" does not exist`,`registered roles: ${Object.keys(t.roles).join(", ")||"(none)"}`);let i=Object.values(t.items).filter(s=>s.role===e&&me.has(s.status)).map(s=>s.id);i.length&&b$1("role-has-open-items",`role "${e}" still holds ${i.length} open item(s)`,`complete or reassign ${i.join(", ")} before retiring the role`,{items:i});let r={...t.roles};return delete r[e],h({...t,roles:r},"role.retired",n,{role:e},o)}function J(t,e){return t.capabilities.includes(e)}function F(t,e){return Object.values(t.roles).filter(n=>J(n,e))}function q(t,e,n,o){return Object.values(t.roles).filter(i=>i.id!==o&&i.canApprove.includes(e)&&(n===void 0||i.capabilities.includes(n))).map(i=>i.id)}function Ae(t,e){return F(t,"approve-gate").filter(n=>n.canApprove.includes(e))}function ee(t,e,n){for(let o of e)F(t,o).length===0&&b$1("missing-capability",`no registered role has capability "${o}"`,`register a role whose capabilities include "${o}" (registerRole) before init`);for(let o of n){let i=F(t,o);i.length>1&&b$1("exclusive-capability",`capability "${o}" must belong to exactly one role but is held by ${i.map(r=>r.id).join(", ")}`,`remove "${o}" from all but one role`);}}function te(t,e){return e.length===0?[]:Object.values(t.roles).filter(n=>e.every(o=>J(n,o)))}function ke(t,e,...n){if(e==="human")return true;let o=A(t,e);return !!o&&n.some(i=>J(o,i))}function qe(t,e,...n){if(!ke(t,e,...n)){let o=Object.values(t.roles).filter(i=>n.some(r=>J(i,r))).map(i=>i.id);b$1("missing-capability",`"${e}" lacks capability ${n.map(i=>`"${i}"`).join(" or ")}`,`run this as one of: human${o.map(i=>`, ${i}`).join("")}`);}}function H(t,e){let n=t.stages.find(o=>o.id===e);return n||b$1("unknown-stage",`stage "${e}" does not exist`,`stages are: ${t.stages.map(o=>o.id).join(" \u2192 ")}`),n}function he(t,e){let n=t.stages.findIndex(o=>o.id===e);return n<0&&H(t,e),t.stages[n+1]}function we(t,e){return t.stages[t.stages.length-1]?.id===e}function B(t,e){return {...t,items:{...t.items,[e.id]:e}}}function ye(t,e,n){return B(t,n(j(t,e)))}function ve(t,e,n){return ye(t,e,o=>{let i={...o};for(let r of n)delete i[r];return i})}function j(t,e){let n=Object.hasOwn(t.items,e)?t.items[e]:void 0;return n||b$1("unknown-item",`item "${e}" does not exist`,`add it with addItem first; known items: ${Object.keys(t.items).join(", ")||"(none)"}`,{items:[e]}),n}function V(t,e,n){let o=e.filter(i=>!Object.hasOwn(t.items,i));o.length&&b$1("unknown-item",`${n} refers to unknown item(s) ${o.join(", ")}`,"add those items first or remove the reference",{items:o});}function Te(t,e,n,o){c(e.id,"item id"),Object.hasOwn(t.items,e.id)&&b$1("duplicate-item",`item "${e.id}" already exists`,"use editItem to change it, or pick a new id",{items:[e.id]});let i=t.stages[0];i||b$1("config-invalid","state has no stages","create the state with at least one stage");let r=e.stage??i.id;H(t,r),V(t,e.dependsOn??[],`item "${e.id}".dependsOn`),e.affects&&V(t,e.affects,`item "${e.id}".affects`),e.parent!==void 0&&V(t,[e.parent],`item "${e.id}".parent`),e.role!==void 0&&!Object.hasOwn(t.roles,e.role)&&b$1("unknown-role",`role "${e.role}" does not exist`,`registered roles: ${Object.keys(t.roles).join(", ")}`);let{stage:s,...a}=e,l={type:"task",acceptance:[],dependsOn:[],...a,id:e.id,title:e.title,stage:r,status:"todo",evidence:[],blockers:[],transitions:[]},c$1=B(t,l);return h(c$1,"item.added",n,{id:l.id,type:l.type,stage:l.stage,weight:l.weight??null,priority:l.priority??null,phase:l.phase??null,parent:l.parent??null},o)}function _e(t,e,n,o,i){let r=j(t,e);n.dependsOn&&V(t,n.dependsOn,`item "${e}".dependsOn`),n.affects&&V(t,n.affects,`item "${e}".affects`),n.parent!==void 0&&V(t,[n.parent],`item "${e}".parent`),n.role!==void 0&&!Object.hasOwn(t.roles,n.role)&&b$1("unknown-role",`role "${n.role}" does not exist`,`registered roles: ${Object.keys(t.roles).join(", ")}`);let s=Object.keys(n).filter(c=>JSON.stringify(n[c])!==JSON.stringify(r[c]));s.length===0&&b$1("no-op",`editItem("${e}") changes nothing`,"pass at least one field with a different value",{items:[e]});let a={...r};for(let c of s)a[c]=n[c];let l=B(t,a);return h(l,"item.edited",o,{id:e,changed:s},i)}function M(t,e,n,o,i){let r=j(t,e),s=n.stage??r.stage;H(t,s),(r.status==="done"||r.status==="dropped")&&b$1("invalid-transition",`item "${e}" is ${r.status} and cannot move`,"create a new item (or a change-request) instead of reopening a finished one",{items:[e]}),s===r.stage&&n.status===r.status&&b$1("no-op",`item "${e}" is already ${r.status} in "${s}"`,"choose a different stage or status",{items:[e]});let a=b(i),l={...r,stage:s,status:n.status,transitions:[...r.transitions,{from:{stage:r.stage,status:r.status},to:{stage:s,status:n.status},at:a,by:o}]},c=B(t,l);return h(c,"item.transition",o,{id:e,from:{stage:r.stage,status:r.status},to:{stage:s,status:n.status}},a)}function K(t,e){let n=0,o=false;for(let i=t.events.length-1;i>=0;i--){let r=t.events[i];if(r.payload?.id===e.id){if(r.type==="item.rework"){o=true;break}r.type==="item.evidence"&&n++;}}return o?e.evidence.slice(Math.max(0,e.evidence.length-n)):e.evidence}function Fe(t,e,n,o){let i=j(t,e),r=b(o),s={...i,evidence:[...i.evidence,{...n,at:r}]},a=B(t,s);return h(a,"item.evidence",n.by,{id:e,kind:n.kind,ref:n.ref},r)}function oe(t,e,n,o,i,r){let s=j(t,e),a=b(r),l=`${e}-b${s.blockers.length+1}`,c=s.status==="blocked"?null:{from:{stage:s.stage,status:s.status},to:{stage:s.stage,status:"blocked"},at:a,by:i},p={...s,status:"blocked",blockers:[...s.blockers,{id:l,reason:n,owner:o,raisedAt:a}],transitions:c?[...s.transitions,c]:s.transitions},g=B(t,p);return h(g,"blocker.raised",i,{id:e,blocker:l,reason:n,owner:o,transition:c&&{from:c.from,to:c.to}},a)}function ne(t,e){for(let n=t.transitions.length-1;n>=0;n--){let o=t.transitions[n];if(o.to.status===e)return o}}function Ve(t,e,n,o,i,r){let s=j(t,e),a=s.blockers.findIndex(x=>x.id===n&&!x.clearedAt);a<0&&b$1("invalid-input",`item "${e}" has no open blocker "${n}"`,`open blockers: ${s.blockers.filter(x=>!x.clearedAt).map(x=>x.id).join(", ")||"(none)"}`,{items:[e]});let l=b(i),c=s.blockers.map((x,D)=>D===a?{...x,clearedAt:l}:x),p=c.some(x=>!x.clearedAt),g=ne(s,"blocked")?.from.status??"todo",u=s.stage,m=g,y=false;g==="in_progress"?(m="todo",u=ne(s,"in_progress")?.from.stage??s.stage):g==="awaiting_human"&&(m=H(t,s.stage).review?"review":"todo",y=true);let{role:W,...R}=s,v=p?null:{from:{stage:s.stage,status:"blocked"},to:{stage:u,status:m},at:l,by:o},E={...y&&!p?R:s,blockers:c,stage:p?s.stage:u,status:p?"blocked":m,transitions:v?[...s.transitions,v]:s.transitions},N=B(t,E);return h(N,"blocker.cleared",o,{id:e,blocker:n,transition:v&&{from:v.from,to:v.to},note:r??null},l)}function Q(t,e){return ve(t,e,["role"])}function ie(t,e,n,o,i){let r=j(t,e),s=he(t,r.stage);if(!s)return M(t,e,{status:"done"},n,i);if(we(t,s.id))return M(t,e,{stage:s.id,status:"done"},n,i);let a=o||s.review===true?"review":"todo";return Q(M(t,e,{stage:s.id,status:a},n,i),e)}function U(t,e,n){let o=[],i=K(t,e),r=(s,a,l)=>o.push({rule:s,severity:"error",item:e.id,message:a,fix:l});for(let s of n)switch(s.kind){case "evidence":i.some(a=>a.kind===s.evidenceKind)||r("policy:evidence",`item "${e.id}" has no evidence of kind "${s.evidenceKind}"`,`attach evidence { kind: "${s.evidenceKind}" } via addEvidence or in the handoff.produced`);break;case "acceptance-written":e.acceptance.length===0&&r("policy:acceptance-written",`item "${e.id}" has no acceptance criteria`,"editItem with a non-empty acceptance[] (needs define-acceptance)");break;case "estimate-present":e.weight===void 0&&r("policy:estimate-present",`item "${e.id}" has no weight`,"editItem with a weight (story points)");break;case "no-open-blockers":{let a=e.blockers.filter(l=>!l.clearedAt);a.length&&r("policy:no-open-blockers",`item "${e.id}" has ${a.length} open blocker(s)`,`clearBlocker ${a.map(l=>l.id).join(", ")}`);break}case "dependencies-done":{let a=e.dependsOn.filter(l=>t.items[l]?.status!=="done");a.length&&r("policy:dependencies-done",`item "${e.id}" depends on unfinished ${a.join(", ")}`,`finish ${a.join(", ")} first`);break}case "custom":i.some(a=>a.kind===`policy:${s.id}`)||r(`policy:custom:${s.id}`,`item "${e.id}" has not satisfied "${s.description}"`,`attach evidence { kind: "policy:${s.id}" } when it is satisfied`);break}return o}function Je(t,e,n,o){let i=U(t,e,n);i.length&&b$1("policy-unmet",`item "${e.id}" cannot ${o}: ${i.length} polic${i.length===1?"y":"ies"} unmet`,i.map(r=>r.fix).join("; "),{items:[e.id]});}function xe(t,e){let n=new Map(t.stages.map((i,r)=>[i.id,r])),o=n.get(e.stage);if(o!==void 0)for(let i=e.transitions.length-1;i>=0;i--){let r=e.transitions[i],s=n.get(r.from.stage);if(r.to.status==="in_progress"&&s!==void 0&&s<o)return r}}function L(t,e){let n=xe(t,e);if(n)return n.by;for(let o=e.transitions.length-1;o>=0;o--){let i=e.transitions[o];if(i.to.status==="in_progress")return i.by}}function be(t,e,n,o){let i=[],r=K(t,e);for(let a of n.evidence)r.some(l=>l.kind===a)||i.push({rule:"gate:evidence",severity:"error",item:e.id,message:`gate "${n.id}" needs evidence "${a}" on item "${e.id}"`,fix:`attach evidence { kind: "${a}" } before approving`});if(i.length)return {outcome:"fail",violations:i};let s=false;for(let a of n.requires){if(a==="human"){o!=="human"&&(s=true);continue}if(!q(t,n.id,a.capability).includes(o)){i.push({rule:"gate:capability",severity:"error",item:e.id,message:`"${o}" may not approve gate "${n.id}" (needs capability "${a.capability}" and canApprove "${n.id}")`,fix:`approve as one of: ${q(t,n.id,a.capability).join(", ")||"(no role qualifies; register one)"}`});continue}let c=L(t,e);if(c!==void 0&&c===o){let p=q(t,n.id,a.capability,o);i.push({rule:"conflict-of-interest",severity:"error",item:e.id,message:`role "${o}" did the work on "${e.id}" and may not approve it`,fix:`approve as a different role: ${p.join(", ")||"(register another approver)"}`});}}return i.length?{outcome:"fail",violations:i}:s?{outcome:"human"}:{outcome:"pass"}}function Xe(t,e,n){let o=b(n),i=`p${t.events.filter(a=>a.type==="pending.raised").length+1}`,r={...e,id:i,raisedAt:o},s={...t,pending:[...t.pending,r]};return e.item&&j(s,e.item).status!=="awaiting_human"&&(s=M(s,e.item,{status:"awaiting_human"},"system",o)),h(s,"pending.raised","system",{id:i,kind:e.kind,item:e.item??null,gate:e.gate??null},o)}function Ye(t,e,n,o,i,r,s){n!=="approve"&&n!=="reject"&&b$1("invalid-input",`decision must be "approve" or "reject" (got ${JSON.stringify(n)})`,"pass approve or reject");let a=t.pending.find(u=>u.id===e);a||b$1("unknown-pending",`no pending decision "${e}"`,`open decisions: ${t.pending.map(u=>u.id).join(", ")||"(none)"}`);let l=a.kind==="gate"&&a.item?j(t,a.item):void 0,c=l&&(t.stages.find(u=>a.gate!==void 0&&u.gate?.id===a.gate)?.gate??t.stages.find(u=>u.id===l.stage)?.gate);l&&c&&o!=="human"&&(c.requires.includes("human")?void 0:be(t,l,c,o))?.outcome!=="pass"&&b$1("gate-unmet",`"${o}" may not decide gate "${c.id}" on "${l.id}"`,`decide as one of: human${c.requires.flatMap(m=>m==="human"?[]:q(t,c.id,m.capability)).map(m=>`, ${m}`).join("")}`,{items:[l.id],rule:"gate"});let p=b(r),g={...t,pending:t.pending.filter(u=>u.id!==e)};if(g=h(g,"pending.decided",o,{id:e,decision:n,note:i,item:a.item??null,gate:a.gate??null},p),l){let u=l.id,m=a.gate??c?.id??null;if(n==="approve"){let y=false;for(let W=t.events.length-1;W>=0;W--){let R=t.events[W];if(!(R.type!=="item.completed"||R.payload.id!==u)){y=R.payload.verdict==="needs-review";break}}g=ie(g,u,o,y,p),g=h(g,"gate.passed",o,{item:u,gate:m},p);}else {let y=c?.onFail??{action:"block"};y.action==="return-to"?g=Q(M(g,u,{stage:y.stage,status:"todo"},o,p),u):g=oe(g,u,`gate "${m??"?"}" rejected: ${i||"no reason given"}`,o,o,p),g=h(g,"gate.failed",o,{item:u,gate:m,note:i},p);}}return s?.afterDecide&&(g=s.afterDecide(g,a,n,o,i,p)),g}var tt={tokens:0,turns:0,wallclockMs:0};function nt(t,e){return {tokens:t.tokens+e.tokensIn+e.tokensOut,turns:t.turns+1,wallclockMs:t.wallclockMs+e.durationMs}}function re(t,e){let n={};return t.tokens!==void 0&&(n.tokens=Math.max(0,t.tokens-e.tokens)),t.turns!==void 0&&(n.turns=Math.max(0,t.turns-e.turns)),t.wallclockMs!==void 0&&(n.wallclockMs=Math.max(0,t.wallclockMs-e.wallclockMs)),n}function ot(t,e){return t.tokens!==void 0&&e.tokens>=t.tokens||t.turns!==void 0&&e.turns>=t.turns||t.wallclockMs!==void 0&&e.wallclockMs>=t.wallclockMs}function se(t,e,n=2e4,o="per-weight"){let i=e??1,r=[];for(let l of t.accounting){if(l.estimate===true)continue;let c=l.tokensIn+l.tokensOut;if(o==="per-call"){r.push(c);continue}let p=t.items[l.item]?.weight;p===void 0||p<=0||r.push(c/p);}if(r.length===0)return o==="per-call"?n:n*i;r.sort((l,c)=>l-c);let s=Math.floor(r.length/2),a=r.length%2?r[s]:(r[s-1]+r[s])/2;return Math.round(o==="per-call"?a:a*i)}function Z(t){return t.iterations.find(e=>e.endedAt===void 0)}function le(t,e,n){if(e.role){let r=A(t,e.role);return r||b$1("unknown-role",`item "${e.id}" is assigned to unknown role "${e.role}"`,"editItem with an existing role id"),r}let o=n?n(e):void 0;if(o!==void 0){let r=A(t,o);return r||b$1("unknown-role",`the methodology picked unknown role "${o}" for item "${e.id}"`,`registered roles: ${Object.keys(t.roles).join(", ")||"(none)"}`,{items:[e.id]}),r}if(e.status==="review"){let r=L(t,e),s=F(t,"review"),l=s.find(c=>c.id!==r)??(s.length===1?s[0]:void 0);return l||b$1("missing-capability",`no role has capability "review" for item "${e.id}"`,"register a role with capability review",{items:[e.id]}),l}let i=F(t,"deliver")[0];return i||b$1("missing-capability",`no role has capability "deliver" for item "${e.id}"`,"register a role with capability deliver",{items:[e.id]}),i}function ae(t){let e={};for(let n of Object.values(t.roles))n.maxConcurrent!==void 0&&(e[n.resourceClass??n.id]=n.maxConcurrent);return e}function We(t,e,n,o){let i=new Set(t.map(r=>r.id));return t.map(r=>{let s=le(e,r,o),a={id:r.id,data:{id:r.id},dependsOn:r.dependsOn.filter(c=>i.has(c)),resourceClass:s.resourceClass??s.id},l=n?n(r):r.priority;return l!==void 0&&(a.priority=l),r.weight!==void 0&&(a.weight=r.weight),r.deadline!==void 0&&(a.deadline=Date.parse(r.deadline)),a})}function pt(t,e,n={}){let o=b(n.now),i=e.candidates(t),r=i.filter(d=>d.dependsOn.every(k=>t.items[k]?.status==="done"||i.some(S=>S.id===k))),s=i.filter(d=>d.dependsOn.every(k=>t.items[k]?.status==="done"));if(r.length===0)return {state:t,dispatched:[],skipped:[],reason:Z(t)?.closing?"budget-exhausted":"no-candidates"};let a=e.plannerOptions(t),l={schedulerMode:a.schedulerMode,resourceCaps:ae(t)};if(a.concurrencyCap!==void 0&&(l.concurrencyCap=a.concurrencyCap),a.fairnessPolicy!==void 0&&(l.fairnessPolicy=a.fairnessPolicy),a.maxDeferralRounds!==void 0&&(l.maxDeferralRounds=a.maxDeferralRounds),a.deadlineStrategy!==void 0&&(l.deadlineStrategy=a.deadlineStrategy),a.weightStrategy!==void 0&&(l.weightStrategy=a.weightStrategy),a.tieBreaker!==void 0){let d=a.tieBreaker;l.tieBreaker=(k,S)=>d(t.items[k.data.id],t.items[S.data.id]);}let c,p;try{let d=new ExFlow(l);for(let S of We(r,t,a.priorityOf,a.roleFor))d.addEntity(S);let k=d.resolveExecutionDetails();c=(k.plan.batches[0]??[]).map(S=>S.id),p=k.metrics;}catch(d){throw d instanceof ExFlowRuntimeError&&b$1("planner-error",`ex-flow refused the graph: [${d.code}] ${d.message}`,"fix the item graph (cycles, duplicate ids) with editItem; see diagnostics in the message",{items:r.map(k=>k.id)}),d}let g=c.map(d=>t.items[d]).filter(d=>d.dependsOn.every(k=>t.items[k]?.status==="done")),u=Object.values(t.items).filter(d=>d.status==="in_progress"),m=new Set(a.wipCounts??["in_progress"]),y=Object.values(t.items).filter(d=>m.has(d.status)),W={};for(let d of u){let k=d.role?A(t,d.role):void 0,S=k?k.resourceClass??k.id:"?";W[S]=(W[S]??0)+1;}let R=ae(t),v=Z(t),E=v?re(v.budget,v.spent):{},N=E.tokens,x=v?Object.values(t.items).filter(d=>(d.iteration===v.id||v.committed.includes(d.id))&&d.status==="in_progress").length:0,D=E.turns===void 0?void 0:E.turns-x,fe=E.wallclockMs!==void 0&&E.wallclockMs<=0,ue=a.estimateMode??"per-weight",pe=n.fallbackTokensPerWeight??a.fallbackTokensPerWeight,ge=Math.min(n.max??1/0,a.concurrencyCap??1/0),C=[],O=[],w,$=t;for(let d of g){if(C.length>=ge){w="wip-full";break}let k=typeof a.dispatchStage=="function"?a.dispatchStage(d):a.dispatchStage,S=d.status==="todo"&&k!==void 0?k:d.stage,T=H(t,S),X=d.type==="question"?[]:U(t,d,T.entryPolicy);if(X.length>0){O.push({id:d.id,reason:"entry-policy",detail:X.map(I=>I.message).join("; ")});continue}let z=a.wipLimitOf?a.wipLimitOf(T,d):T.wipLimit;if(z!==void 0&&y.filter(I=>I.stage===T.id&&I.id!==d.id).length+C.filter(I=>I.stage===T.id).length>=z){w="wip-full",O.push({id:d.id,reason:"wip",detail:`stage "${T.id}" is at its WIP limit of ${z}`});continue}let G=le(t,d,a.roleFor),P=G.resourceClass??G.id;if(R[P]!==void 0&&(W[P]??0)>=R[P]){w="wip-full",O.push({id:d.id,reason:"resource-cap",detail:`resource class "${P}" is at its cap of ${R[P]}`});continue}if(D!==void 0&&D<=0){w="budget-exhausted",O.push({id:d.id,reason:"budget",detail:`turns budget spent: ${v.spent.turns} used + ${x+C.length} in flight of ${v.budget.turns}`});continue}if(fe){w="budget-exhausted",O.push({id:d.id,reason:"budget",detail:"wall-clock budget spent"});continue}if(N!==void 0){let I=se(t,d.weight,pe,ue);if(I>N){w="budget-exhausted",O.push({id:d.id,reason:"budget",detail:`needs about ${I} tokens, ${N} left in the iteration`});continue}N-=I;}W[P]=(W[P]??0)+1,D!==void 0&&(D-=1),$=M($,d.id,{stage:S,status:"in_progress"},G.id,o),$={...$,items:{...$.items,[d.id]:{...$.items[d.id],role:G.id}}},C.push($.items[d.id]);}return w===void 0&&O.some(d=>d.reason==="entry-policy")&&(w="policy-blocked"),w===void 0&&C.length<s.length&&(w="wip-full"),C.length===0&&w===void 0&&(w="no-candidates"),$=h($,"planner.resolved","planner",{dispatched:C.map(d=>d.id),reason:w??null,skipped:O,metrics:p},o),w?{state:$,dispatched:C,skipped:O,reason:w}:{state:$,dispatched:C,skipped:O}}function de(t){return [{id:"separation-lost",severity:"warning",check(o,i){return i.type!=="init"&&i.type!=="role.register"?[]:te(o,t.requiredCapabilities).map(r=>({rule:"separation-lost",severity:"warning",message:`role "${r.id}" holds every required capability (${t.requiredCapabilities.join(", ")}); no separation of duties`,fix:"fine for a solo operator; otherwise split capabilities across roles"}))}},{id:"conflict-of-interest",severity:"error",check(o,i){if(i.type!=="complete")return [];let r=i.payload?.handoff;if(!r)return [];let s=r.verdict??"done";if(s!=="done"&&s!=="needs-review")return [];let a=o.items[r.item];if(!a)return [];let l=o.stages.find(p=>p.id===a.stage)?.gate;if(!l||!l.requires.some(p=>p!=="human"))return [];if(L(o,a)!==r.role)return [];let c=q(o,l.id,void 0,r.role);return [{rule:"conflict-of-interest",severity:"error",item:a.id,message:`role "${r.role}" authored "${a.id}" and may not pass gate "${l.id}" on it`,fix:`hand the gate to another approver: ${c.join(", ")||"(register one)"}`}]}}]}function Oe(t,e,n){let o=[];for(let i of [...de(e),...e.rules])o.push(...i.check(t,n));return o}function ce(t,e,n,o){let i=Oe(t,e,n),r=i.filter(s=>s.severity==="error");return r.length&&b$1("rule-violation",`${n.type} violates ${r.map(s=>s.rule).join(", ")}: ${r.map(s=>s.message).join("; ")}`,r.map(s=>s.fix).join("; "),{rule:r[0].rule,items:r.map(s=>s.item).filter(s=>!!s)}),{state:o(t),warnings:i.filter(s=>s.severity==="warning")}}function St(t){let e=t.methodology,n=e.validateConfig(t.config),o=t.stages??e.defaultStages(n),i=t.roles??e.defaultRoles(n),r=t.now!==void 0?{methodology:e.name,config:n,stages:o,roles:i,now:t.now}:{methodology:e.name,config:n,stages:o,roles:i},s=Y(r);return ee(s,e.requiredCapabilities,e.exclusiveCapabilities),ce(s,e,{type:"init",by:t.by??"system"},a=>a)}function $t(t,e,n,o,i){(typeof n!="object"||n===null||Array.isArray(n)||Object.keys(n).length===0)&&b$1("invalid-input","config patch must be a non-empty object",'pass e.g. { "sprintBudget": { "tokens": 1500000 } } to exwf config set');let r=Z(t);r&&b$1("invalid-input",`config cannot change while ${r.id} is open`,"close it first (exwf ceremony review or cancel; a waterfall phase closes at its gate), then run exwf config set");let s=(e.lockedConfigKeys??[]).filter(u=>Object.hasOwn(n,u));s.length&&b$1("invalid-input",`config key(s) ${s.join(", ")} cannot change after init`,e.name==="kanban"?"use the service-delivery-review cadence for columns and classes of service":"start a new workflow with exwf init to change them");let a=t.config??{},l=e.validateConfig({...a,...n}),c=Object.keys(n).filter(u=>!Object.hasOwn(l,u));c.length&&b$1("invalid-input",`unknown config key(s) ${c.join(", ")}`,`known keys: ${Object.keys(l).join(", ")}`);let p=Object.keys(n).filter(u=>JSON.stringify(a[u])!==JSON.stringify(l[u]));p.length===0&&b$1("no-op","config patch changes nothing","pass at least one key with a different value to exwf config set");let g=u=>Object.fromEntries(p.map(m=>[m,u[m]]));return ce(t,e,{type:"config.change",by:o,payload:{patch:n}},u=>{let m=b(i),y=h({...u,config:l},"config.changed",o,{changed:p,before:g(a),after:g(l)},m);return e.afterConfigChange&&(y=e.afterConfigChange(y,m)),y})}export{Ve as A,Q as B,ie as C,U as D,Je as E,xe as F,L as G,be as H,Xe as I,Ye as J,tt as K,nt as L,re as M,ot as N,se as O,Z as P,le as Q,ae as R,We as S,pt as T,de as U,Oe as V,ce as W,St as X,$t as Y,b as a,Y as b,h as c,je as d,A as e,Ee as f,Pe as g,J as h,F as i,q as j,Ae as k,ee as l,te as m,ke as n,qe as o,H as p,he as q,we as r,ye as s,ve as t,j as u,Te as v,_e as w,M as x,Fe as y,oe as z};//# sourceMappingURL=chunk-Z3PU6EBI.mjs.map
2
+ //# sourceMappingURL=chunk-Z3PU6EBI.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/state.ts","../src/roles.ts","../src/items.ts","../src/policies.ts","../src/gates.ts","../src/budget.ts","../src/planner.ts","../src/rules.ts","../src/methodology.ts"],"names":["nowOf","now","createState","input","seenStages","st","fail","roles","r","assertId","at","appendEvent","state","type","by","payload","ev","lastEvent","i","roleOf","id","OPEN","registerRole","role","next","retireRole","roleId","open","hasCapability","cap","rolesWith","approverIds","gateId","except","approversFor","requireCapabilities","required","exclusive","holders","separationLost","c","canDo","caps","requireCap","h","stageOf","stageId","s","nextStageOf","idx","isTerminalStage","putItem","item","patchItem","fn","getItem","stripItemFields","keys","copy","k","it","assertKnownItems","ids","what","missing","d","addItem","firstStage","_s","rest","editItem","patch","changed","updated","moveItem","to","toStage","freshEvidence","after","found","addEvidence","evidence","raiseBlocker","reason","owner","blockerId","t","lastTransitionTo","status","clearBlocker","note","b","blockers","stillBlocked","prev","toStatus","dropRole","_r","noRole","clearRole","itemId","advanceItem","wantsReview","evaluatePolicies","policies","out","fresh","v","rule","message","fix","p","e","notDone","assertPolicies","context","unmet","u","lastDispatchBefore","order","here","from","authorOf","before","checkGate","gate","violations","kind","needsHuman","req","author","others","raisePending","pending","entry","decide","pendingId","decision","methodology","item0","q","onFail","ZERO_SPENT","addSpent","spent","acc","remaining","budget","isExhausted","estimateTokens","weight","fallbackPerWeight","mode","w","samples","a","total","iw","x","y","mid","median","openIteration","assignRole","roleFor","picked","reviewers","resourceCapsFor","toExNodes","items","priorityOf","present","node","pr","plan","opts","all","candidates","readyAll","po","options","tb","firstBatch","metrics","flow","ExFlow","n","details","ExFlowRuntimeError","ready","inProgress","wipCounts","occupying","perClass","cls","iteration","left","tokensLeft","inFlight","turnsLeft","clockOut","estimateMode","fallback","limit","dispatched","skipped","pulledTo","target","stage","limitHere","est","coreRulesFor","action","handoff","verdict","validateAction","applyAction","reduce","errors","init","m","config","stages","stateInput","changeConfig","locked","unknown","pick","o","s2"],"mappings":"8FAGO,SAASA,CAAAA,CAAMC,CAAAA,CAAsB,CAC1C,OAAOA,GAAO,IAAI,IAAA,EAAK,CAAE,WAAA,EAC3B,CAUO,SAASC,CAAAA,CAAYC,CAAAA,CAAwC,CAClE,IAAMC,CAAAA,CAAa,IAAI,GAAA,CACvB,IAAA,IAAWC,CAAAA,IAAMF,CAAAA,CAAM,MAAA,CACjBC,EAAW,GAAA,CAAIC,CAAAA,CAAG,EAAE,CAAA,EACtBC,IAAK,gBAAA,CAAkB,CAAA,oBAAA,EAAuBD,CAAAA,CAAG,E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,CAAA0D,CAAAA,CAAS,MAAA,CAAQ2J,EAAKxG,CAAM,CAAA,CAAG,KAAA,CAAOwG,CAAAA,CAAKrJ,CAAK,CAAE,CAAA,CACpDpE,CACF,CAAA,CACA,OAAIgI,CAAAA,CAAY,iBAAA,GAAmB2F,CAAAA,CAAK3F,CAAAA,CAAY,kBAAkB2F,CAAAA,CAAI3N,CAAE,CAAA,CAAA,CACrE2N,CACT,CAAC,CACH","file":"chunk-Z3PU6EBI.mjs","sourcesContent":["import { assertId, fail } from \"./errors.ts\";\nimport type { Event, MethodologyName, Role, Stage, WorkflowState } from \"./types.ts\";\n\nexport function nowOf(now?: string): string {\n return now ?? new Date().toISOString();\n}\n\nexport interface CreateStateInput {\n methodology: MethodologyName;\n config: unknown;\n stages: Stage[];\n roles: Role[];\n now?: string;\n}\n\nexport function createState(input: CreateStateInput): WorkflowState {\n const seenStages = new Set<string>();\n for (const st of input.stages) {\n if (seenStages.has(st.id))\n fail(\"config-invalid\", `duplicate stage id \"${st.id}\"`, \"give every stage a unique id\");\n seenStages.add(st.id);\n }\n const roles: Record<string, Role> = {};\n for (const r of input.roles) {\n assertId(r.id, \"role id\");\n if (Object.hasOwn(roles, r.id))\n fail(\"duplicate-role\", `duplicate role id \"${r.id}\"`, \"give every role a unique id\");\n roles[r.id] = r;\n }\n const at = nowOf(input.now);\n return {\n version: 1,\n methodology: input.methodology,\n config: input.config,\n items: {},\n stages: input.stages,\n roles,\n iterations: [],\n events: [\n {\n seq: 1,\n at,\n type: \"state.created\",\n by: \"system\",\n payload: { methodology: input.methodology },\n },\n ],\n accounting: [],\n pending: [],\n lessons: [],\n agreements: [],\n };\n}\n\nexport function appendEvent(\n state: WorkflowState,\n type: string,\n by: string,\n payload: unknown,\n now?: string,\n): WorkflowState {\n const last = state.events[state.events.length - 1];\n const ev: Event = { seq: (last?.seq ?? 0) + 1, at: nowOf(now), type, by, payload };\n return { ...state, events: [...state.events, ev] };\n}\n\nexport function lastEvent(state: WorkflowState, type?: string): Event | undefined {\n for (let i = state.events.length - 1; i >= 0; i--) {\n const ev = state.events[i]!;\n if (type === undefined || ev.type === type) return ev;\n }\n return undefined;\n}\n","import { assertId, fail } from \"./errors.ts\";\nimport { appendEvent } from \"./state.ts\";\nimport type { Capability, Role, WorkflowState } from \"./types.ts\";\n\n/** Own-property role lookup (ids such as \"constructor\" never hit the prototype). */\nexport function roleOf(state: WorkflowState, id: string): Role | undefined {\n return Object.hasOwn(state.roles, id) ? state.roles[id] : undefined;\n}\n\nconst OPEN: ReadonlySet<string> = new Set([\"in_progress\", \"review\", \"blocked\"]);\n\nexport function registerRole(\n state: WorkflowState,\n role: Role,\n by: string,\n now?: string,\n): WorkflowState {\n assertId(role.id, \"role id\");\n if (roleOf(state, role.id))\n fail(\n \"duplicate-role\",\n `role \"${role.id}\" already exists`,\n `use a different id or retireRole(\"${role.id}\") first`,\n );\n const next = { ...state, roles: { ...state.roles, [role.id]: role } };\n return appendEvent(\n next,\n \"role.registered\",\n by,\n { role: role.id, capabilities: role.capabilities },\n now,\n );\n}\n\nexport function retireRole(\n state: WorkflowState,\n roleId: string,\n by: string,\n now?: string,\n): WorkflowState {\n if (!roleOf(state, roleId))\n fail(\n \"unknown-role\",\n `role \"${roleId}\" does not exist`,\n `registered roles: ${Object.keys(state.roles).join(\", \") || \"(none)\"}`,\n );\n const open = Object.values(state.items)\n .filter((i) => i.role === roleId && OPEN.has(i.status))\n .map((i) => i.id);\n if (open.length)\n fail(\n \"role-has-open-items\",\n `role \"${roleId}\" still holds ${open.length} open item(s)`,\n `complete or reassign ${open.join(\", \")} before retiring the role`,\n { items: open },\n );\n const roles = { ...state.roles };\n delete roles[roleId];\n return appendEvent({ ...state, roles }, \"role.retired\", by, { role: roleId }, now);\n}\n\nexport function hasCapability(role: Role, cap: Capability): boolean {\n return role.capabilities.includes(cap);\n}\n\nexport function rolesWith(state: WorkflowState, cap: Capability): Role[] {\n return Object.values(state.roles).filter((r) => hasCapability(r, cap));\n}\n\n/** Ids of roles that may approve `gateId`, optionally holding `cap` and excluding one id. */\nexport function approverIds(\n state: WorkflowState,\n gateId: string,\n cap?: string,\n except?: string,\n): string[] {\n return Object.values(state.roles)\n .filter(\n (r) =>\n r.id !== except &&\n r.canApprove.includes(gateId) &&\n (cap === undefined || (r.capabilities as readonly string[]).includes(cap)),\n )\n .map((r) => r.id);\n}\n\nexport function approversFor(state: WorkflowState, gateId: string): Role[] {\n return rolesWith(state, \"approve-gate\").filter((r) => r.canApprove.includes(gateId));\n}\n\nexport function requireCapabilities(\n state: WorkflowState,\n required: Capability[],\n exclusive: Capability[],\n): void {\n for (const cap of required) {\n if (rolesWith(state, cap).length === 0) {\n fail(\n \"missing-capability\",\n `no registered role has capability \"${cap}\"`,\n `register a role whose capabilities include \"${cap}\" (registerRole) before init`,\n );\n }\n }\n for (const cap of exclusive) {\n const holders = rolesWith(state, cap);\n if (holders.length > 1) {\n fail(\n \"exclusive-capability\",\n `capability \"${cap}\" must belong to exactly one role but is held by ${holders.map((r) => r.id).join(\", \")}`,\n `remove \"${cap}\" from all but one role`,\n );\n }\n }\n}\n\nexport function separationLost(state: WorkflowState, required: Capability[]): Role[] {\n if (required.length === 0) return [];\n return Object.values(state.roles).filter((r) => required.every((c) => hasCapability(r, c)));\n}\n\n/** `human` may do anything; a role must hold at least one of `caps`; unknown ids may do nothing. */\nexport function canDo(state: WorkflowState, by: string, ...caps: Capability[]): boolean {\n if (by === \"human\") return true;\n const role = roleOf(state, by);\n return !!role && caps.some((c) => hasCapability(role, c));\n}\n\nexport function requireCap(state: WorkflowState, by: string, ...caps: Capability[]): void {\n if (!canDo(state, by, ...caps)) {\n const holders = Object.values(state.roles)\n .filter((r) => caps.some((c) => hasCapability(r, c)))\n .map((r) => r.id);\n fail(\n \"missing-capability\",\n `\"${by}\" lacks capability ${caps.map((c) => `\"${c}\"`).join(\" or \")}`,\n `run this as one of: human${holders.map((h) => `, ${h}`).join(\"\")}`,\n );\n }\n}\n","import { assertId, fail } from \"./errors.ts\";\nimport type { ItemPatch } from \"./types.ts\";\n\nexport { assertId };\nimport { appendEvent, nowOf } from \"./state.ts\";\nimport type {\n Evidence,\n ItemStatus,\n NewItem,\n Stage,\n Transition,\n WorkItem,\n WorkflowState,\n} from \"./types.ts\";\n\nexport function stageOf(state: WorkflowState, stageId: string): Stage {\n const st = state.stages.find((s) => s.id === stageId);\n if (!st)\n fail(\n \"unknown-stage\",\n `stage \"${stageId}\" does not exist`,\n `stages are: ${state.stages.map((s) => s.id).join(\" → \")}`,\n );\n return st;\n}\n\nexport function nextStageOf(state: WorkflowState, stageId: string): Stage | undefined {\n const idx = state.stages.findIndex((s) => s.id === stageId);\n if (idx < 0) stageOf(state, stageId);\n return state.stages[idx + 1];\n}\n\nexport function isTerminalStage(state: WorkflowState, stageId: string): boolean {\n return state.stages[state.stages.length - 1]?.id === stageId;\n}\n\nfunction putItem(state: WorkflowState, item: WorkItem): WorkflowState {\n return { ...state, items: { ...state.items, [item.id]: item } };\n}\n\n/** Replace one item with `fn(item)`; no event. */\nexport function patchItem(\n state: WorkflowState,\n id: string,\n fn: (item: WorkItem) => WorkItem,\n): WorkflowState {\n return putItem(state, fn(getItem(state, id)));\n}\n\n/** Drop optional fields (iteration, role, ...) from one item; no event. */\nexport function stripItemFields(\n state: WorkflowState,\n id: string,\n keys: Array<\"iteration\" | \"role\">,\n): WorkflowState {\n return patchItem(state, id, (item) => {\n const copy = { ...item };\n for (const k of keys) delete copy[k];\n return copy;\n });\n}\n\nexport function getItem(state: WorkflowState, id: string): WorkItem {\n const it = Object.hasOwn(state.items, id) ? state.items[id] : undefined;\n if (!it)\n fail(\n \"unknown-item\",\n `item \"${id}\" does not exist`,\n `add it with addItem first; known items: ${Object.keys(state.items).join(\", \") || \"(none)\"}`,\n { items: [id] },\n );\n return it;\n}\n\nfunction assertKnownItems(state: WorkflowState, ids: string[], what: string): void {\n const missing = ids.filter((d) => !Object.hasOwn(state.items, d));\n if (missing.length)\n fail(\n \"unknown-item\",\n `${what} refers to unknown item(s) ${missing.join(\", \")}`,\n \"add those items first or remove the reference\",\n { items: missing },\n );\n}\n\nexport function addItem(\n state: WorkflowState,\n input: NewItem,\n by: string,\n now?: string,\n): WorkflowState {\n assertId(input.id, \"item id\");\n if (Object.hasOwn(state.items, input.id))\n fail(\n \"duplicate-item\",\n `item \"${input.id}\" already exists`,\n \"use editItem to change it, or pick a new id\",\n { items: [input.id] },\n );\n const firstStage = state.stages[0];\n if (!firstStage)\n fail(\"config-invalid\", \"state has no stages\", \"create the state with at least one stage\");\n const stageId = input.stage ?? firstStage.id;\n stageOf(state, stageId);\n assertKnownItems(state, input.dependsOn ?? [], `item \"${input.id}\".dependsOn`);\n if (input.affects) assertKnownItems(state, input.affects, `item \"${input.id}\".affects`);\n if (input.parent !== undefined)\n assertKnownItems(state, [input.parent], `item \"${input.id}\".parent`);\n if (input.role !== undefined && !Object.hasOwn(state.roles, input.role))\n fail(\n \"unknown-role\",\n `role \"${input.role}\" does not exist`,\n `registered roles: ${Object.keys(state.roles).join(\", \")}`,\n );\n\n const { stage: _s, ...rest } = input;\n const item: WorkItem = {\n type: \"task\",\n acceptance: [],\n dependsOn: [],\n ...rest,\n id: input.id,\n title: input.title,\n stage: stageId,\n status: \"todo\",\n evidence: [],\n blockers: [],\n transitions: [],\n };\n const next = putItem(state, item);\n return appendEvent(\n next,\n \"item.added\",\n by,\n {\n id: item.id,\n type: item.type,\n stage: item.stage,\n weight: item.weight ?? null,\n priority: item.priority ?? null,\n phase: item.phase ?? null,\n parent: item.parent ?? null,\n },\n now,\n );\n}\n\nexport type { ItemPatch } from \"./types.ts\";\n\nexport function editItem(\n state: WorkflowState,\n id: string,\n patch: ItemPatch,\n by: string,\n now?: string,\n): WorkflowState {\n const item = getItem(state, id);\n if (patch.dependsOn) assertKnownItems(state, patch.dependsOn, `item \"${id}\".dependsOn`);\n if (patch.affects) assertKnownItems(state, patch.affects, `item \"${id}\".affects`);\n if (patch.parent !== undefined) assertKnownItems(state, [patch.parent], `item \"${id}\".parent`);\n if (patch.role !== undefined && !Object.hasOwn(state.roles, patch.role))\n fail(\n \"unknown-role\",\n `role \"${patch.role}\" does not exist`,\n `registered roles: ${Object.keys(state.roles).join(\", \")}`,\n );\n const changed = (Object.keys(patch) as Array<keyof ItemPatch>).filter(\n (k) => JSON.stringify(patch[k]) !== JSON.stringify(item[k]),\n );\n if (changed.length === 0)\n fail(\n \"no-op\",\n `editItem(\"${id}\") changes nothing`,\n \"pass at least one field with a different value\",\n { items: [id] },\n );\n const updated: WorkItem = { ...item };\n for (const k of changed) (updated as unknown as Record<string, unknown>)[k] = patch[k];\n const next = putItem(state, updated);\n return appendEvent(next, \"item.edited\", by, { id, changed }, now);\n}\n\nexport function moveItem(\n state: WorkflowState,\n id: string,\n to: { stage?: string; status: ItemStatus },\n by: string,\n now?: string,\n): WorkflowState {\n const item = getItem(state, id);\n const toStage = to.stage ?? item.stage;\n stageOf(state, toStage);\n if (item.status === \"done\" || item.status === \"dropped\") {\n fail(\n \"invalid-transition\",\n `item \"${id}\" is ${item.status} and cannot move`,\n \"create a new item (or a change-request) instead of reopening a finished one\",\n { items: [id] },\n );\n }\n if (toStage === item.stage && to.status === item.status)\n fail(\n \"no-op\",\n `item \"${id}\" is already ${item.status} in \"${toStage}\"`,\n \"choose a different stage or status\",\n { items: [id] },\n );\n const at = nowOf(now);\n const updated: WorkItem = {\n ...item,\n stage: toStage,\n status: to.status,\n transitions: [\n ...item.transitions,\n {\n from: { stage: item.stage, status: item.status },\n to: { stage: toStage, status: to.status },\n at,\n by,\n },\n ],\n };\n const next = putItem(state, updated);\n return appendEvent(\n next,\n \"item.transition\",\n by,\n {\n id,\n from: { stage: item.stage, status: item.status },\n to: { stage: toStage, status: to.status },\n },\n at,\n );\n}\n\n/** Evidence recorded at or after the item's last `item.rework` event; evidence stays stored, but earlier entries no longer count toward policies or gates. Never-reworked items keep all evidence. */\nexport function freshEvidence(state: WorkflowState, item: WorkItem): Evidence[] {\n // Event order, not timestamps: evidence recorded by an item.evidence event AFTER the item's last\n // item.rework event is fresh. Evidence entries are appended in the same order as those events, so\n // the fresh entries are the last `after` ones. Evidence attached by the rework completion itself\n // precedes its item.rework event and therefore does not count.\n let after = 0;\n let found = false;\n for (let i = state.events.length - 1; i >= 0; i--) {\n const ev = state.events[i]!;\n if ((ev.payload as { id?: string } | null)?.id !== item.id) continue;\n if (ev.type === \"item.rework\") {\n found = true;\n break;\n }\n if (ev.type === \"item.evidence\") after++;\n }\n return found ? item.evidence.slice(Math.max(0, item.evidence.length - after)) : item.evidence;\n}\n\nexport function addEvidence(\n state: WorkflowState,\n id: string,\n evidence: Omit<Evidence, \"at\">,\n now?: string,\n): WorkflowState {\n const item = getItem(state, id);\n const at = nowOf(now);\n const updated: WorkItem = { ...item, evidence: [...item.evidence, { ...evidence, at }] };\n const next = putItem(state, updated);\n return appendEvent(\n next,\n \"item.evidence\",\n evidence.by,\n { id, kind: evidence.kind, ref: evidence.ref },\n at,\n );\n}\n\nexport function raiseBlocker(\n state: WorkflowState,\n id: string,\n reason: string,\n owner: string,\n by: string,\n now?: string,\n): WorkflowState {\n const item = getItem(state, id);\n const at = nowOf(now);\n const blockerId = `${id}-b${item.blockers.length + 1}`;\n const t: Transition | null =\n item.status === \"blocked\"\n ? null\n : {\n from: { stage: item.stage, status: item.status },\n to: { stage: item.stage, status: \"blocked\" },\n at,\n by,\n };\n const updated: WorkItem = {\n ...item,\n status: \"blocked\",\n blockers: [...item.blockers, { id: blockerId, reason, owner, raisedAt: at }],\n transitions: t ? [...item.transitions, t] : item.transitions,\n };\n const next = putItem(state, updated);\n return appendEvent(\n next,\n \"blocker.raised\",\n by,\n { id, blocker: blockerId, reason, owner, transition: t && { from: t.from, to: t.to } },\n at,\n );\n}\n\nfunction lastTransitionTo(item: WorkItem, status: ItemStatus): Transition | undefined {\n for (let i = item.transitions.length - 1; i >= 0; i--) {\n const t = item.transitions[i]!;\n if (t.to.status === status) return t;\n }\n return undefined;\n}\n\nexport function clearBlocker(\n state: WorkflowState,\n id: string,\n blockerId: string,\n by: string,\n now?: string,\n note?: string,\n): WorkflowState {\n const item = getItem(state, id);\n const idx = item.blockers.findIndex((b) => b.id === blockerId && !b.clearedAt);\n if (idx < 0)\n fail(\n \"invalid-input\",\n `item \"${id}\" has no open blocker \"${blockerId}\"`,\n `open blockers: ${\n item.blockers\n .filter((b) => !b.clearedAt)\n .map((b) => b.id)\n .join(\", \") || \"(none)\"\n }`,\n { items: [id] },\n );\n const at = nowOf(now);\n const blockers = item.blockers.map((b, i) => (i === idx ? { ...b, clearedAt: at } : b));\n const stillBlocked = blockers.some((b) => !b.clearedAt);\n const prev = lastTransitionTo(item, \"blocked\")?.from.status ?? \"todo\";\n let toStage = item.stage;\n let toStatus: ItemStatus = prev;\n let dropRole = false;\n if (prev === \"in_progress\") {\n toStatus = \"todo\";\n toStage = lastTransitionTo(item, \"in_progress\")?.from.stage ?? item.stage;\n } else if (prev === \"awaiting_human\") {\n // a rejected human gate: the work is re-dispatched in the current stage\n toStatus = stageOf(state, item.stage).review ? \"review\" : \"todo\";\n dropRole = true;\n }\n const { role: _r, ...noRole } = item;\n const t: Transition | null = stillBlocked\n ? null\n : {\n from: { stage: item.stage, status: \"blocked\" },\n to: { stage: toStage, status: toStatus },\n at,\n by,\n };\n const updated: WorkItem = {\n ...(dropRole && !stillBlocked ? (noRole as WorkItem) : item),\n blockers,\n stage: stillBlocked ? item.stage : toStage,\n status: stillBlocked ? \"blocked\" : toStatus,\n transitions: t ? [...item.transitions, t] : item.transitions,\n };\n const next = putItem(state, updated);\n return appendEvent(\n next,\n \"blocker.cleared\",\n by,\n { id, blocker: blockerId, transition: t && { from: t.from, to: t.to }, note: note ?? null },\n at,\n );\n}\n\n/** Entering a new stage is a new assignment: the role that finished the previous stage is cleared so the planner picks the right one (a reviewer, not the author). */\nexport function clearRole(state: WorkflowState, itemId: string): WorkflowState {\n return stripItemFields(state, itemId, [\"role\"]);\n}\n\n/** Move an item to the next stage (done at the end, review/todo otherwise) and clear its role. */\nexport function advanceItem(\n state: WorkflowState,\n itemId: string,\n by: string,\n wantsReview: boolean,\n now: string,\n): WorkflowState {\n const item = getItem(state, itemId);\n const to = nextStageOf(state, item.stage);\n if (!to) return moveItem(state, itemId, { status: \"done\" }, by, now);\n if (isTerminalStage(state, to.id))\n return moveItem(state, itemId, { stage: to.id, status: \"done\" }, by, now);\n const status = wantsReview || to.review === true ? \"review\" : \"todo\";\n return clearRole(moveItem(state, itemId, { stage: to.id, status }, by, now), itemId);\n}\n","import { fail } from \"./errors.ts\";\nimport { freshEvidence } from \"./items.ts\";\nimport type { Policy, Violation, WorkItem, WorkflowState } from \"./types.ts\";\n\nexport function evaluatePolicies(\n state: WorkflowState,\n item: WorkItem,\n policies: Policy[],\n): Violation[] {\n const out: Violation[] = [];\n const fresh = freshEvidence(state, item);\n const v = (rule: string, message: string, fix: string) =>\n out.push({ rule, severity: \"error\", item: item.id, message, fix });\n for (const p of policies) {\n switch (p.kind) {\n case \"evidence\":\n if (!fresh.some((e) => e.kind === p.evidenceKind))\n v(\n \"policy:evidence\",\n `item \"${item.id}\" has no evidence of kind \"${p.evidenceKind}\"`,\n `attach evidence { kind: \"${p.evidenceKind}\" } via addEvidence or in the handoff.produced`,\n );\n break;\n case \"acceptance-written\":\n if (item.acceptance.length === 0)\n v(\n \"policy:acceptance-written\",\n `item \"${item.id}\" has no acceptance criteria`,\n \"editItem with a non-empty acceptance[] (needs define-acceptance)\",\n );\n break;\n case \"estimate-present\":\n if (item.weight === undefined)\n v(\n \"policy:estimate-present\",\n `item \"${item.id}\" has no weight`,\n \"editItem with a weight (story points)\",\n );\n break;\n case \"no-open-blockers\": {\n const open = item.blockers.filter((b) => !b.clearedAt);\n if (open.length)\n v(\n \"policy:no-open-blockers\",\n `item \"${item.id}\" has ${open.length} open blocker(s)`,\n `clearBlocker ${open.map((b) => b.id).join(\", \")}`,\n );\n break;\n }\n case \"dependencies-done\": {\n const notDone = item.dependsOn.filter((d) => state.items[d]?.status !== \"done\");\n if (notDone.length)\n v(\n \"policy:dependencies-done\",\n `item \"${item.id}\" depends on unfinished ${notDone.join(\", \")}`,\n `finish ${notDone.join(\", \")} first`,\n );\n break;\n }\n case \"custom\":\n if (!fresh.some((e) => e.kind === `policy:${p.id}`))\n v(\n `policy:custom:${p.id}`,\n `item \"${item.id}\" has not satisfied \"${p.description}\"`,\n `attach evidence { kind: \"policy:${p.id}\" } when it is satisfied`,\n );\n break;\n }\n }\n return out;\n}\n\nexport function assertPolicies(\n state: WorkflowState,\n item: WorkItem,\n policies: Policy[],\n context: string,\n): void {\n const unmet = evaluatePolicies(state, item, policies);\n if (unmet.length) {\n fail(\n \"policy-unmet\",\n `item \"${item.id}\" cannot ${context}: ${unmet.length} polic${unmet.length === 1 ? \"y\" : \"ies\"} unmet`,\n unmet.map((u) => u.fix).join(\"; \"),\n { items: [item.id] },\n );\n }\n}\n","import { fail } from \"./errors.ts\";\nimport { advanceItem, freshEvidence, clearRole, getItem, moveItem, raiseBlocker } from \"./items.ts\";\nimport { approverIds } from \"./roles.ts\";\nimport { appendEvent, nowOf } from \"./state.ts\";\nimport type {\n Gate,\n Methodology,\n PendingHuman,\n Transition,\n Violation,\n WorkItem,\n WorkflowState,\n} from \"./types.ts\";\n\nexport type GateResult =\n | { outcome: \"pass\" }\n | { outcome: \"human\" }\n | { outcome: \"fail\"; violations: Violation[] };\n\n/** 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). */\nexport function lastDispatchBefore(state: WorkflowState, item: WorkItem): Transition | undefined {\n const order = new Map(state.stages.map((s, i) => [s.id, i] as const));\n const here = order.get(item.stage);\n if (here === undefined) return undefined;\n for (let i = item.transitions.length - 1; i >= 0; i--) {\n const t = item.transitions[i]!;\n const from = order.get(t.from.stage);\n if (t.to.status === \"in_progress\" && from !== undefined && from < here) return t;\n }\n return undefined;\n}\n\n/** 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. */\nexport function authorOf(state: WorkflowState, item: WorkItem): string | undefined {\n const before = lastDispatchBefore(state, item);\n if (before) return before.by;\n for (let i = item.transitions.length - 1; i >= 0; i--) {\n const t = item.transitions[i]!;\n if (t.to.status === \"in_progress\") return t.by;\n }\n return undefined;\n}\n\nexport function checkGate(\n state: WorkflowState,\n item: WorkItem,\n gate: Gate,\n by: string,\n): GateResult {\n const violations: Violation[] = [];\n const fresh = freshEvidence(state, item);\n for (const kind of gate.evidence) {\n if (!fresh.some((e) => e.kind === kind)) {\n violations.push({\n rule: \"gate:evidence\",\n severity: \"error\",\n item: item.id,\n message: `gate \"${gate.id}\" needs evidence \"${kind}\" on item \"${item.id}\"`,\n fix: `attach evidence { kind: \"${kind}\" } before approving`,\n });\n }\n }\n if (violations.length) return { outcome: \"fail\", violations };\n\n let needsHuman = false;\n for (const req of gate.requires) {\n if (req === \"human\") {\n if (by !== \"human\") needsHuman = true;\n continue;\n }\n const ok = approverIds(state, gate.id, req.capability).includes(by);\n if (!ok) {\n violations.push({\n rule: \"gate:capability\",\n severity: \"error\",\n item: item.id,\n message: `\"${by}\" may not approve gate \"${gate.id}\" (needs capability \"${req.capability}\" and canApprove \"${gate.id}\")`,\n fix: `approve as one of: ${approverIds(state, gate.id, req.capability).join(\", \") || \"(no role qualifies; register one)\"}`,\n });\n continue;\n }\n const author = authorOf(state, item);\n if (author !== undefined && author === by) {\n const others = approverIds(state, gate.id, req.capability, by);\n violations.push({\n rule: \"conflict-of-interest\",\n severity: \"error\",\n item: item.id,\n message: `role \"${by}\" did the work on \"${item.id}\" and may not approve it`,\n fix: `approve as a different role: ${others.join(\", \") || \"(register another approver)\"}`,\n });\n }\n }\n if (violations.length) return { outcome: \"fail\", violations };\n return needsHuman ? { outcome: \"human\" } : { outcome: \"pass\" };\n}\n\nexport function raisePending(\n state: WorkflowState,\n pending: Omit<PendingHuman, \"id\" | \"raisedAt\">,\n now?: string,\n): WorkflowState {\n const at = nowOf(now);\n const id = `p${state.events.filter((e) => e.type === \"pending.raised\").length + 1}`;\n const entry: PendingHuman = { ...pending, id, raisedAt: at };\n let next: WorkflowState = { ...state, pending: [...state.pending, entry] };\n if (pending.item) {\n const item = getItem(next, pending.item);\n if (item.status !== \"awaiting_human\")\n next = moveItem(next, pending.item, { status: \"awaiting_human\" }, \"system\", at);\n }\n return appendEvent(\n next,\n \"pending.raised\",\n \"system\",\n { id, kind: pending.kind, item: pending.item ?? null, gate: pending.gate ?? null },\n at,\n );\n}\n\nexport function decide(\n state: WorkflowState,\n pendingId: string,\n decision: \"approve\" | \"reject\",\n by: string,\n note: string,\n now?: string,\n methodology?: Methodology,\n): WorkflowState {\n if (decision !== \"approve\" && decision !== \"reject\")\n fail(\n \"invalid-input\",\n `decision must be \"approve\" or \"reject\" (got ${JSON.stringify(decision)})`,\n \"pass approve or reject\",\n );\n const entry = state.pending.find((p) => p.id === pendingId);\n if (!entry)\n fail(\n \"unknown-pending\",\n `no pending decision \"${pendingId}\"`,\n `open decisions: ${state.pending.map((p) => p.id).join(\", \") || \"(none)\"}`,\n );\n const item0 = entry.kind === \"gate\" && entry.item ? getItem(state, entry.item) : undefined;\n const gate =\n item0 &&\n (state.stages.find((s) => entry.gate !== undefined && s.gate?.id === entry.gate)?.gate ??\n state.stages.find((s) => s.id === item0.stage)?.gate);\n if (item0 && gate && by !== \"human\") {\n const res = gate.requires.includes(\"human\") ? undefined : checkGate(state, item0, gate, by);\n if (res?.outcome !== \"pass\")\n fail(\n \"gate-unmet\",\n `\"${by}\" may not decide gate \"${gate.id}\" on \"${item0.id}\"`,\n `decide as one of: human${gate.requires\n .flatMap((q) => (q === \"human\" ? [] : approverIds(state, gate.id, q.capability)))\n .map((r) => `, ${r}`)\n .join(\"\")}`,\n { items: [item0.id], rule: \"gate\" },\n );\n }\n const at = nowOf(now);\n let next: WorkflowState = { ...state, pending: state.pending.filter((p) => p.id !== pendingId) };\n next = appendEvent(\n next,\n \"pending.decided\",\n by,\n { id: pendingId, decision, note, item: entry.item ?? null, gate: entry.gate ?? null },\n at,\n );\n if (item0) {\n const id = item0.id;\n const gateId = entry.gate ?? gate?.id ?? null;\n if (decision === \"approve\") {\n let wantsReview = false;\n for (let i = state.events.length - 1; i >= 0; i--) {\n const e = state.events[i]!;\n if (e.type !== \"item.completed\" || (e.payload as { id?: string }).id !== id) continue;\n wantsReview = (e.payload as { verdict?: string }).verdict === \"needs-review\";\n break;\n }\n next = advanceItem(next, id, by, wantsReview, at);\n next = appendEvent(next, \"gate.passed\", by, { item: id, gate: gateId }, at);\n } else {\n const onFail = gate?.onFail ?? { action: \"block\" as const };\n if (onFail.action === \"return-to\")\n next = clearRole(moveItem(next, id, { stage: onFail.stage, status: \"todo\" }, by, at), id);\n else\n next = raiseBlocker(\n next,\n id,\n `gate \"${gateId ?? \"?\"}\" rejected: ${note || \"no reason given\"}`,\n by,\n by,\n at,\n );\n next = appendEvent(next, \"gate.failed\", by, { item: id, gate: gateId, note }, at);\n }\n }\n if (methodology?.afterDecide) next = methodology.afterDecide(next, entry, decision, by, note, at);\n return next;\n}\n","import type { Accounting, Budget, WorkflowState } from \"./types.ts\";\n\nexport const ZERO_SPENT: Required<Budget> = { tokens: 0, turns: 0, wallclockMs: 0 };\n\nexport function addSpent(spent: Required<Budget>, acc: Accounting): Required<Budget> {\n return {\n tokens: spent.tokens + acc.tokensIn + acc.tokensOut,\n turns: spent.turns + 1,\n wallclockMs: spent.wallclockMs + acc.durationMs,\n };\n}\n\nexport function remaining(budget: Budget, spent: Required<Budget>): Budget {\n const out: Budget = {};\n if (budget.tokens !== undefined) out.tokens = Math.max(0, budget.tokens - spent.tokens);\n if (budget.turns !== undefined) out.turns = Math.max(0, budget.turns - spent.turns);\n if (budget.wallclockMs !== undefined)\n out.wallclockMs = Math.max(0, budget.wallclockMs - spent.wallclockMs);\n return out;\n}\n\nexport function isExhausted(budget: Budget, spent: Required<Budget>): boolean {\n return (\n (budget.tokens !== undefined && spent.tokens >= budget.tokens) ||\n (budget.turns !== undefined && spent.turns >= budget.turns) ||\n (budget.wallclockMs !== undefined && spent.wallclockMs >= budget.wallclockMs)\n );\n}\n\nexport type EstimateMode = \"per-weight\" | \"per-call\";\n\nexport function estimateTokens(\n state: WorkflowState,\n weight: number | undefined,\n fallbackPerWeight = 20000,\n mode: EstimateMode = \"per-weight\",\n): number {\n const w = weight ?? 1;\n const samples: number[] = [];\n for (const a of state.accounting) {\n if (a.estimate === true) continue;\n const total = a.tokensIn + a.tokensOut;\n if (mode === \"per-call\") {\n samples.push(total);\n continue;\n }\n const iw = state.items[a.item]?.weight;\n if (iw === undefined || iw <= 0) continue;\n samples.push(total / iw);\n }\n if (samples.length === 0) return mode === \"per-call\" ? fallbackPerWeight : fallbackPerWeight * w;\n samples.sort((x, y) => x - y);\n const mid = Math.floor(samples.length / 2);\n const median = samples.length % 2 ? samples[mid]! : (samples[mid - 1]! + samples[mid]!) / 2;\n return Math.round(mode === \"per-call\" ? median : median * w);\n}\n","import { ExFlow, ExFlowRuntimeError, type ExFlowOptions, type ExNode } from \"ex-flow\";\nimport { estimateTokens, remaining } from \"./budget.ts\";\nimport { fail } from \"./errors.ts\";\nimport { authorOf } from \"./gates.ts\";\nimport { moveItem, stageOf } from \"./items.ts\";\nimport { evaluatePolicies } from \"./policies.ts\";\nimport { roleOf, rolesWith } from \"./roles.ts\";\nimport { appendEvent, nowOf } from \"./state.ts\";\nimport type { ItemStatus, Iteration, Methodology, Role, WorkItem, WorkflowState } from \"./types.ts\";\n\ntype NodeData = { id: string };\n\nexport function openIteration(state: WorkflowState): Iteration | undefined {\n return state.iterations.find((it) => it.endedAt === undefined);\n}\n\nexport function assignRole(\n state: WorkflowState,\n item: WorkItem,\n roleFor?: (item: WorkItem) => string | undefined,\n): Role {\n if (item.role) {\n const r = roleOf(state, item.role);\n if (!r)\n fail(\n \"unknown-role\",\n `item \"${item.id}\" is assigned to unknown role \"${item.role}\"`,\n \"editItem with an existing role id\",\n );\n return r;\n }\n const picked = roleFor ? roleFor(item) : undefined;\n if (picked !== undefined) {\n const r = roleOf(state, picked);\n if (!r)\n fail(\n \"unknown-role\",\n `the methodology picked unknown role \"${picked}\" for item \"${item.id}\"`,\n `registered roles: ${Object.keys(state.roles).join(\", \") || \"(none)\"}`,\n { items: [item.id] },\n );\n return r;\n }\n if (item.status === \"review\") {\n const author = authorOf(state, item);\n const reviewers = rolesWith(state, \"review\");\n const other = reviewers.find((r) => r.id !== author);\n const r = other ?? (reviewers.length === 1 ? reviewers[0] : undefined);\n if (!r)\n fail(\n \"missing-capability\",\n `no role has capability \"review\" for item \"${item.id}\"`,\n \"register a role with capability review\",\n { items: [item.id] },\n );\n return r;\n }\n const r = rolesWith(state, \"deliver\")[0];\n if (!r)\n fail(\n \"missing-capability\",\n `no role has capability \"deliver\" for item \"${item.id}\"`,\n \"register a role with capability deliver\",\n { items: [item.id] },\n );\n return r;\n}\n\nexport function resourceCapsFor(state: WorkflowState): Record<string, number> {\n const caps: Record<string, number> = {};\n for (const r of Object.values(state.roles)) {\n if (r.maxConcurrent !== undefined) caps[r.resourceClass ?? r.id] = r.maxConcurrent;\n }\n return caps;\n}\n\nexport function toExNodes(\n items: WorkItem[],\n state: WorkflowState,\n priorityOf?: (item: WorkItem) => number | undefined,\n roleFor?: (item: WorkItem) => string | undefined,\n): ExNode<NodeData>[] {\n const present = new Set(items.map((i) => i.id));\n return items.map((i) => {\n const role = assignRole(state, i, roleFor);\n const node: ExNode<NodeData> = {\n id: i.id,\n data: { id: i.id },\n dependsOn: i.dependsOn.filter((d) => present.has(d)),\n resourceClass: role.resourceClass ?? role.id,\n };\n const pr = priorityOf ? priorityOf(i) : i.priority;\n if (pr !== undefined) node.priority = pr;\n if (i.weight !== undefined) node.weight = i.weight;\n if (i.deadline !== undefined) node.deadline = Date.parse(i.deadline);\n return node;\n });\n}\n\nexport interface PlanOptions {\n max?: number;\n now?: string;\n fallbackTokensPerWeight?: number;\n}\nexport type PlanReason = \"no-candidates\" | \"budget-exhausted\" | \"wip-full\" | \"policy-blocked\";\n/** A ready item the planner did not pull, and why. */\nexport interface Skipped {\n id: string;\n reason: \"entry-policy\" | \"wip\" | \"resource-cap\" | \"budget\";\n detail: string;\n}\nexport interface PlanResult {\n state: WorkflowState;\n dispatched: WorkItem[];\n skipped: Skipped[];\n reason?: PlanReason;\n}\n\nexport function plan(\n state: WorkflowState,\n methodology: Methodology,\n opts: PlanOptions = {},\n): PlanResult {\n const at = nowOf(opts.now);\n // an item may enter the graph only if every dependency is done or is itself a candidate (so ex-flow orders it)\n const all = methodology.candidates(state);\n const candidates = all.filter((i) =>\n i.dependsOn.every((d) => state.items[d]?.status === \"done\" || all.some((c) => c.id === d)),\n );\n const readyAll = all.filter((i) => i.dependsOn.every((d) => state.items[d]?.status === \"done\"));\n if (candidates.length === 0)\n return {\n state,\n dispatched: [],\n skipped: [],\n reason: openIteration(state)?.closing ? \"budget-exhausted\" : \"no-candidates\",\n };\n\n const po = methodology.plannerOptions(state);\n const options: ExFlowOptions<NodeData> = {\n schedulerMode: po.schedulerMode,\n resourceCaps: resourceCapsFor(state),\n };\n if (po.concurrencyCap !== undefined) options.concurrencyCap = po.concurrencyCap;\n if (po.fairnessPolicy !== undefined) options.fairnessPolicy = po.fairnessPolicy;\n if (po.maxDeferralRounds !== undefined) options.maxDeferralRounds = po.maxDeferralRounds;\n if (po.deadlineStrategy !== undefined) options.deadlineStrategy = po.deadlineStrategy;\n if (po.weightStrategy !== undefined) options.weightStrategy = po.weightStrategy;\n if (po.tieBreaker !== undefined) {\n const tb = po.tieBreaker;\n options.tieBreaker = (a, b) => tb(state.items[a.data.id]!, state.items[b.data.id]!);\n }\n\n let firstBatch: string[];\n let metrics: unknown;\n try {\n const flow = new ExFlow<NodeData>(options);\n for (const n of toExNodes(candidates, state, po.priorityOf, po.roleFor)) flow.addEntity(n);\n const details = flow.resolveExecutionDetails();\n firstBatch = (details.plan.batches[0] ?? []).map((r) => r.id);\n metrics = details.metrics;\n } catch (e) {\n if (e instanceof ExFlowRuntimeError) {\n fail(\n \"planner-error\",\n `ex-flow refused the graph: [${e.code}] ${e.message}`,\n \"fix the item graph (cycles, duplicate ids) with editItem; see diagnostics in the message\",\n { items: candidates.map((c) => c.id) },\n );\n }\n throw e;\n }\n\n // ready = first batch, but only items whose deps are really done (deps inside the batch are impossible by construction)\n const ready = firstBatch\n .map((id) => state.items[id]!)\n .filter((i) => i.dependsOn.every((d) => state.items[d]?.status === \"done\"));\n const inProgress = Object.values(state.items).filter((i) => i.status === \"in_progress\");\n const wipCounts = new Set<ItemStatus>(po.wipCounts ?? [\"in_progress\"]);\n const occupying = Object.values(state.items).filter((i) => wipCounts.has(i.status));\n const perClass: Record<string, number> = {};\n for (const i of inProgress) {\n const r = i.role ? roleOf(state, i.role) : undefined;\n const cls = r ? (r.resourceClass ?? r.id) : \"?\";\n perClass[cls] = (perClass[cls] ?? 0) + 1;\n }\n const caps = resourceCapsFor(state);\n const iteration = openIteration(state);\n const left = iteration ? remaining(iteration.budget, iteration.spent) : {};\n let tokensLeft = left.tokens;\n const inFlight = iteration\n ? Object.values(state.items).filter(\n (i) =>\n (i.iteration === iteration.id || iteration.committed.includes(i.id)) &&\n i.status === \"in_progress\",\n ).length\n : 0;\n let turnsLeft = left.turns === undefined ? undefined : left.turns - inFlight;\n const clockOut = left.wallclockMs !== undefined && left.wallclockMs <= 0;\n const estimateMode = po.estimateMode ?? \"per-weight\";\n const fallback = opts.fallbackTokensPerWeight ?? po.fallbackTokensPerWeight;\n const limit = Math.min(opts.max ?? Infinity, po.concurrencyCap ?? Infinity);\n\n const dispatched: WorkItem[] = [];\n const skipped: Skipped[] = [];\n let reason: PlanReason | undefined;\n let next = state;\n for (const item of ready) {\n if (dispatched.length >= limit) {\n reason = \"wip-full\";\n break;\n }\n const pulledTo =\n typeof po.dispatchStage === \"function\" ? po.dispatchStage(item) : po.dispatchStage;\n const target = item.status === \"todo\" && pulledTo !== undefined ? pulledTo : item.stage;\n const stage = stageOf(state, target);\n // questions are answered, not delivered: like exit policies and gates, entry policies do not apply\n const violations =\n item.type === \"question\" ? [] : evaluatePolicies(state, item, stage.entryPolicy);\n if (violations.length > 0) {\n skipped.push({\n id: item.id,\n reason: \"entry-policy\",\n detail: violations.map((v) => v.message).join(\"; \"),\n });\n continue;\n }\n const limitHere = po.wipLimitOf ? po.wipLimitOf(stage, item) : stage.wipLimit;\n if (\n limitHere !== undefined &&\n occupying.filter((i) => i.stage === stage.id && i.id !== item.id).length +\n dispatched.filter((d) => d.stage === stage.id).length >=\n limitHere\n ) {\n reason = \"wip-full\";\n skipped.push({\n id: item.id,\n reason: \"wip\",\n detail: `stage \"${stage.id}\" is at its WIP limit of ${limitHere}`,\n });\n continue;\n }\n const role = assignRole(state, item, po.roleFor);\n const cls = role.resourceClass ?? role.id;\n if (caps[cls] !== undefined && (perClass[cls] ?? 0) >= caps[cls]!) {\n reason = \"wip-full\";\n skipped.push({\n id: item.id,\n reason: \"resource-cap\",\n detail: `resource class \"${cls}\" is at its cap of ${caps[cls]}`,\n });\n continue;\n }\n if (turnsLeft !== undefined && turnsLeft <= 0) {\n reason = \"budget-exhausted\";\n skipped.push({\n id: item.id,\n reason: \"budget\",\n detail: `turns budget spent: ${iteration!.spent.turns} used + ${inFlight + dispatched.length} in flight of ${iteration!.budget.turns}`,\n });\n continue;\n }\n if (clockOut) {\n reason = \"budget-exhausted\";\n skipped.push({ id: item.id, reason: \"budget\", detail: \"wall-clock budget spent\" });\n continue;\n }\n if (tokensLeft !== undefined) {\n const est = estimateTokens(state, item.weight, fallback, estimateMode);\n if (est > tokensLeft) {\n reason = \"budget-exhausted\";\n skipped.push({\n id: item.id,\n reason: \"budget\",\n detail: `needs about ${est} tokens, ${tokensLeft} left in the iteration`,\n });\n continue;\n }\n tokensLeft -= est;\n }\n perClass[cls] = (perClass[cls] ?? 0) + 1;\n if (turnsLeft !== undefined) turnsLeft -= 1;\n next = moveItem(next, item.id, { stage: target, status: \"in_progress\" }, role.id, at);\n next = {\n ...next,\n items: { ...next.items, [item.id]: { ...next.items[item.id]!, role: role.id } },\n };\n dispatched.push(next.items[item.id]!);\n }\n if (reason === undefined && skipped.some((x) => x.reason === \"entry-policy\"))\n reason = \"policy-blocked\";\n if (reason === undefined && dispatched.length < readyAll.length) reason = \"wip-full\";\n if (dispatched.length === 0 && reason === undefined) reason = \"no-candidates\";\n next = appendEvent(\n next,\n \"planner.resolved\",\n \"planner\",\n { dispatched: dispatched.map((d) => d.id), reason: reason ?? null, skipped, metrics },\n at,\n );\n return reason\n ? { state: next, dispatched, skipped, reason }\n : { state: next, dispatched, skipped };\n}\n","import { authorOf } from \"./gates.ts\";\nimport { approverIds, separationLost } from \"./roles.ts\";\nimport type { Action, Handoff, Methodology, Rule, Violation } from \"./types.ts\";\n\nexport function coreRulesFor(methodology: Pick<Methodology, \"requiredCapabilities\">): Rule[] {\n const separation: Rule = {\n id: \"separation-lost\",\n severity: \"warning\",\n check(state, action: Action): Violation[] {\n if (action.type !== \"init\" && action.type !== \"role.register\") return [];\n return separationLost(state, methodology.requiredCapabilities).map((r) => ({\n rule: \"separation-lost\",\n severity: \"warning\" as const,\n message: `role \"${r.id}\" holds every required capability (${methodology.requiredCapabilities.join(\", \")}); no separation of duties`,\n fix: \"fine for a solo operator; otherwise split capabilities across roles\",\n }));\n },\n };\n const coi: Rule = {\n id: \"conflict-of-interest\",\n severity: \"error\",\n check(state, action: Action): Violation[] {\n // dormant by design: completions reach rules as \"item.complete\" (spec §22 B02), so this match never fires\n if (action.type !== \"complete\") return [];\n const handoff = (action.payload as { handoff?: Handoff } | undefined)?.handoff;\n if (!handoff) return [];\n const verdict = handoff.verdict ?? \"done\";\n if (verdict !== \"done\" && verdict !== \"needs-review\") return [];\n const item = state.items[handoff.item];\n if (!item) return [];\n const gate = state.stages.find((s) => s.id === item.stage)?.gate;\n if (!gate || !gate.requires.some((q) => q !== \"human\")) return [];\n if (authorOf(state, item) !== handoff.role) return [];\n const others = approverIds(state, gate.id, undefined, handoff.role);\n return [\n {\n rule: \"conflict-of-interest\",\n severity: \"error\",\n item: item.id,\n message: `role \"${handoff.role}\" authored \"${item.id}\" and may not pass gate \"${gate.id}\" on it`,\n fix: `hand the gate to another approver: ${others.join(\", \") || \"(register one)\"}`,\n },\n ];\n },\n };\n return [separation, coi];\n}\n","import { fail } from \"./errors.ts\";\nimport { requireCapabilities } from \"./roles.ts\";\nimport { coreRulesFor } from \"./rules.ts\";\nimport { openIteration } from \"./planner.ts\";\nimport { appendEvent, createState, nowOf } from \"./state.ts\";\nimport type {\n Action,\n ApplyResult,\n Methodology,\n Role,\n Stage,\n Violation,\n WorkflowState,\n} from \"./types.ts\";\n\nexport function validateAction(\n state: WorkflowState,\n methodology: Methodology,\n action: Action,\n): Violation[] {\n const out: Violation[] = [];\n for (const rule of [...coreRulesFor(methodology), ...methodology.rules])\n out.push(...rule.check(state, action));\n return out;\n}\n\nexport function applyAction(\n state: WorkflowState,\n methodology: Methodology,\n action: Action,\n reduce: (s: WorkflowState) => WorkflowState,\n): ApplyResult {\n const violations = validateAction(state, methodology, action);\n const errors = violations.filter((v) => v.severity === \"error\");\n if (errors.length) {\n fail(\n \"rule-violation\",\n `${action.type} violates ${errors.map((e) => e.rule).join(\", \")}: ${errors.map((e) => e.message).join(\"; \")}`,\n errors.map((e) => e.fix).join(\"; \"),\n { rule: errors[0]!.rule, items: errors.map((e) => e.item).filter((x): x is string => !!x) },\n );\n }\n return { state: reduce(state), warnings: violations.filter((v) => v.severity === \"warning\") };\n}\n\nexport interface InitInput<C> {\n methodology: Methodology<C>;\n config: unknown;\n roles?: Role[];\n stages?: Stage[];\n by?: string;\n now?: string;\n}\n\nexport function init<C>(input: InitInput<C>): ApplyResult {\n const m = input.methodology;\n const config = m.validateConfig(input.config);\n const stages = input.stages ?? m.defaultStages(config);\n const roles = input.roles ?? m.defaultRoles(config);\n const stateInput =\n input.now !== undefined\n ? { methodology: m.name, config, stages, roles, now: input.now }\n : { methodology: m.name, config, stages, roles };\n const state = createState(stateInput);\n requireCapabilities(state, m.requiredCapabilities, m.exclusiveCapabilities);\n return applyAction(state, m as Methodology, { type: \"init\", by: input.by ?? \"system\" }, (s) => s);\n}\n\n/** Change the config between iterations: re-validated, recorded as config.changed, derived state kept in step by the methodology hook. */\nexport function changeConfig(\n state: WorkflowState,\n methodology: Methodology,\n patch: Record<string, unknown>,\n by: string,\n now?: string,\n): ApplyResult {\n if (\n typeof patch !== \"object\" ||\n patch === null ||\n Array.isArray(patch) ||\n Object.keys(patch).length === 0\n )\n fail(\n \"invalid-input\",\n \"config patch must be a non-empty object\",\n 'pass e.g. { \"sprintBudget\": { \"tokens\": 1500000 } } to exwf config set',\n );\n const open = openIteration(state);\n if (open)\n fail(\n \"invalid-input\",\n `config cannot change while ${open.id} is open`,\n \"close it first (exwf ceremony review or cancel; a waterfall phase closes at its gate), then run exwf config set\",\n );\n const locked = (methodology.lockedConfigKeys ?? []).filter((k) => Object.hasOwn(patch, k));\n if (locked.length)\n fail(\n \"invalid-input\",\n `config key(s) ${locked.join(\", \")} cannot change after init`,\n methodology.name === \"kanban\"\n ? \"use the service-delivery-review cadence for columns and classes of service\"\n : \"start a new workflow with exwf init to change them\",\n );\n const before = (state.config ?? {}) as Record<string, unknown>;\n const after = methodology.validateConfig({ ...before, ...patch }) as Record<string, unknown>;\n const unknown = Object.keys(patch).filter((k) => !Object.hasOwn(after, k));\n if (unknown.length)\n fail(\n \"invalid-input\",\n `unknown config key(s) ${unknown.join(\", \")}`,\n `known keys: ${Object.keys(after).join(\", \")}`,\n );\n const changed = Object.keys(patch).filter(\n (k) => JSON.stringify(before[k]) !== JSON.stringify(after[k]),\n );\n if (changed.length === 0)\n fail(\n \"no-op\",\n \"config patch changes nothing\",\n \"pass at least one key with a different value to exwf config set\",\n );\n const pick = (o: Record<string, unknown>) => Object.fromEntries(changed.map((k) => [k, o[k]]));\n return applyAction(state, methodology, { type: \"config.change\", by, payload: { patch } }, (s) => {\n const at = nowOf(now);\n let s2 = appendEvent(\n { ...s, config: after },\n \"config.changed\",\n by,\n { changed, before: pick(before), after: pick(after) },\n at,\n );\n if (methodology.afterConfigChange) s2 = methodology.afterConfigChange(s2, at);\n return s2;\n });\n}\n"]}