ex-workflow 1.2.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +147 -13
  3. package/dist/adapters/index.cjs +1 -1
  4. package/dist/adapters/index.d.cts +1 -1
  5. package/dist/adapters/index.d.ts +1 -1
  6. package/dist/adapters/index.mjs +1 -1
  7. package/dist/{budget-Gckmqj74.d.ts → budget-BuQ9GWsg.d.ts} +1 -1
  8. package/dist/{budget-Bm839Qw0.d.cts → budget-DDqQQIgp.d.cts} +1 -1
  9. package/dist/{chunk-LIATP6LY.mjs → chunk-3QUIRAXO.mjs} +2 -2
  10. package/dist/{chunk-LIATP6LY.mjs.map → chunk-3QUIRAXO.mjs.map} +1 -1
  11. package/dist/chunk-3RJ4RNPG.cjs +2 -0
  12. package/dist/chunk-3RJ4RNPG.cjs.map +1 -0
  13. package/dist/chunk-66BO7JFR.cjs +2 -0
  14. package/dist/chunk-66BO7JFR.cjs.map +1 -0
  15. package/dist/chunk-6PFJYRM7.cjs +2 -0
  16. package/dist/chunk-6PFJYRM7.cjs.map +1 -0
  17. package/dist/chunk-76ITDJDM.cjs +2 -0
  18. package/dist/{chunk-QAENYYU6.cjs.map → chunk-76ITDJDM.cjs.map} +1 -1
  19. package/dist/chunk-AWFR3Q4M.mjs +2 -0
  20. package/dist/{chunk-32NVJV5C.mjs.map → chunk-AWFR3Q4M.mjs.map} +1 -1
  21. package/dist/chunk-BD665RYK.mjs +2 -0
  22. package/dist/chunk-BD665RYK.mjs.map +1 -0
  23. package/dist/chunk-BGKXIRGS.mjs +2 -0
  24. package/dist/chunk-BGKXIRGS.mjs.map +1 -0
  25. package/dist/chunk-BNKKOAMP.mjs +2 -0
  26. package/dist/{chunk-OZAYOPLB.mjs.map → chunk-BNKKOAMP.mjs.map} +1 -1
  27. package/dist/{chunk-IIEKK2S3.cjs → chunk-CPM2SPDX.cjs} +2 -2
  28. package/dist/{chunk-IIEKK2S3.cjs.map → chunk-CPM2SPDX.cjs.map} +1 -1
  29. package/dist/chunk-DVFTTBCT.cjs +3 -0
  30. package/dist/chunk-DVFTTBCT.cjs.map +1 -0
  31. package/dist/{chunk-U3RU5LOF.cjs → chunk-G6QELJRL.cjs} +2 -2
  32. package/dist/{chunk-U3RU5LOF.cjs.map → chunk-G6QELJRL.cjs.map} +1 -1
  33. package/dist/{chunk-6D6FL3XK.mjs → chunk-HXEJP6KF.mjs} +2 -2
  34. package/dist/{chunk-6D6FL3XK.mjs.map → chunk-HXEJP6KF.mjs.map} +1 -1
  35. package/dist/chunk-ILNSTPPV.mjs +2 -0
  36. package/dist/chunk-ILNSTPPV.mjs.map +1 -0
  37. package/dist/{chunk-RXY434DX.cjs → chunk-KA6DVHO5.cjs} +4 -4
  38. package/dist/{chunk-RXY434DX.cjs.map → chunk-KA6DVHO5.cjs.map} +1 -1
  39. package/dist/chunk-KLOSFZFK.cjs +2 -0
  40. package/dist/chunk-KLOSFZFK.cjs.map +1 -0
  41. package/dist/chunk-LQJPLXFR.cjs +2 -0
  42. package/dist/chunk-LQJPLXFR.cjs.map +1 -0
  43. package/dist/chunk-MUQ4FKVH.mjs +2 -0
  44. package/dist/chunk-MUQ4FKVH.mjs.map +1 -0
  45. package/dist/chunk-N2NANHRW.mjs +2 -0
  46. package/dist/{chunk-4HG6A3SF.mjs.map → chunk-N2NANHRW.mjs.map} +1 -1
  47. package/dist/chunk-NNQ3RHDP.mjs +2 -0
  48. package/dist/chunk-NNQ3RHDP.mjs.map +1 -0
  49. package/dist/chunk-OAJ4KV4F.mjs +2 -0
  50. package/dist/{chunk-BYPFTO7P.mjs.map → chunk-OAJ4KV4F.mjs.map} +1 -1
  51. package/dist/chunk-OFFQTZEY.cjs +2 -0
  52. package/dist/chunk-OFFQTZEY.cjs.map +1 -0
  53. package/dist/{chunk-3GKYL6VB.mjs → chunk-ONVAUZOD.mjs} +3 -3
  54. package/dist/{chunk-3GKYL6VB.mjs.map → chunk-ONVAUZOD.mjs.map} +1 -1
  55. package/dist/chunk-QJMOCISZ.mjs +3 -0
  56. package/dist/chunk-QJMOCISZ.mjs.map +1 -0
  57. package/dist/chunk-QKW26EV2.mjs +2 -0
  58. package/dist/chunk-QKW26EV2.mjs.map +1 -0
  59. package/dist/{chunk-W2P27645.cjs → chunk-RMXEQ5HN.cjs} +2 -2
  60. package/dist/{chunk-W2P27645.cjs.map → chunk-RMXEQ5HN.cjs.map} +1 -1
  61. package/dist/chunk-TBLIZIWH.cjs +2 -0
  62. package/dist/chunk-TBLIZIWH.cjs.map +1 -0
  63. package/dist/chunk-U23IRPFF.cjs +2 -0
  64. package/dist/{chunk-SFYUJQYW.cjs.map → chunk-U23IRPFF.cjs.map} +1 -1
  65. package/dist/chunk-WM3JM3H7.mjs +2 -0
  66. package/dist/chunk-WM3JM3H7.mjs.map +1 -0
  67. package/dist/chunk-WU5JELOM.mjs +2 -0
  68. package/dist/chunk-WU5JELOM.mjs.map +1 -0
  69. package/dist/chunk-YNYIHJOC.mjs +2 -0
  70. package/dist/chunk-YNYIHJOC.mjs.map +1 -0
  71. package/dist/chunk-YRXFEM3F.cjs +2 -0
  72. package/dist/chunk-YRXFEM3F.cjs.map +1 -0
  73. package/dist/{chunk-K4VSMIJZ.cjs → chunk-ZDT2BZGU.cjs} +2 -2
  74. package/dist/{chunk-K4VSMIJZ.cjs.map → chunk-ZDT2BZGU.cjs.map} +1 -1
  75. package/dist/{chunk-OVR5CK3R.cjs → chunk-ZK3V66NC.cjs} +2 -2
  76. package/dist/{chunk-OVR5CK3R.cjs.map → chunk-ZK3V66NC.cjs.map} +1 -1
  77. package/dist/cli/bin.cjs +1 -1
  78. package/dist/cli/bin.cjs.map +1 -1
  79. package/dist/cli/bin.mjs +1 -1
  80. package/dist/cli/bin.mjs.map +1 -1
  81. package/dist/cli/index.cjs +1 -1
  82. package/dist/cli/index.mjs +1 -1
  83. package/dist/experimentation/index.cjs +1 -1
  84. package/dist/experimentation/index.d.cts +2 -2
  85. package/dist/experimentation/index.d.ts +2 -2
  86. package/dist/experimentation/index.mjs +1 -1
  87. package/dist/index.cjs +1 -1
  88. package/dist/index.cjs.map +1 -1
  89. package/dist/index.d.cts +15 -12
  90. package/dist/index.d.ts +15 -12
  91. package/dist/index.mjs +1 -1
  92. package/dist/index.mjs.map +1 -1
  93. package/dist/investigation/index.cjs +1 -1
  94. package/dist/investigation/index.d.cts +2 -2
  95. package/dist/investigation/index.d.ts +2 -2
  96. package/dist/investigation/index.mjs +1 -1
  97. package/dist/kanban/index.cjs +1 -1
  98. package/dist/kanban/index.d.cts +1 -1
  99. package/dist/kanban/index.d.ts +1 -1
  100. package/dist/kanban/index.mjs +1 -1
  101. package/dist/policies/index.cjs +2 -0
  102. package/dist/policies/index.cjs.map +1 -0
  103. package/dist/policies/index.d.cts +202 -0
  104. package/dist/policies/index.d.ts +202 -0
  105. package/dist/policies/index.mjs +2 -0
  106. package/dist/policies/index.mjs.map +1 -0
  107. package/dist/registry/index.cjs +1 -1
  108. package/dist/registry/index.d.cts +1 -1
  109. package/dist/registry/index.d.ts +1 -1
  110. package/dist/registry/index.mjs +1 -1
  111. package/dist/schema/index.cjs +1 -1
  112. package/dist/schema/index.mjs +1 -1
  113. package/dist/scrum/index.cjs +1 -1
  114. package/dist/scrum/index.d.cts +3 -3
  115. package/dist/scrum/index.d.ts +3 -3
  116. package/dist/scrum/index.mjs +1 -1
  117. package/dist/{types-DjePDfms.d.cts → types-DLOtndDY.d.cts} +61 -1
  118. package/dist/{types-DjePDfms.d.ts → types-DLOtndDY.d.ts} +61 -1
  119. package/dist/types.d.cts +1 -1
  120. package/dist/types.d.ts +1 -1
  121. package/dist/waterfall/index.cjs +1 -1
  122. package/dist/waterfall/index.d.cts +1 -1
  123. package/dist/waterfall/index.d.ts +1 -1
  124. package/dist/waterfall/index.mjs +1 -1
  125. package/package.json +14 -1
  126. package/dist/chunk-32NVJV5C.mjs +0 -2
  127. package/dist/chunk-3O5MPAJT.cjs +0 -2
  128. package/dist/chunk-3O5MPAJT.cjs.map +0 -1
  129. package/dist/chunk-43GLYYA2.cjs +0 -3
  130. package/dist/chunk-43GLYYA2.cjs.map +0 -1
  131. package/dist/chunk-4HG6A3SF.mjs +0 -2
  132. package/dist/chunk-7EF47R2J.mjs +0 -2
  133. package/dist/chunk-7EF47R2J.mjs.map +0 -1
  134. package/dist/chunk-BD76VFI4.mjs +0 -3
  135. package/dist/chunk-BD76VFI4.mjs.map +0 -1
  136. package/dist/chunk-BHAEPYRJ.cjs +0 -2
  137. package/dist/chunk-BHAEPYRJ.cjs.map +0 -1
  138. package/dist/chunk-BYPFTO7P.mjs +0 -2
  139. package/dist/chunk-FDZB73PH.mjs +0 -2
  140. package/dist/chunk-FDZB73PH.mjs.map +0 -1
  141. package/dist/chunk-JNLWI4JM.mjs +0 -2
  142. package/dist/chunk-JNLWI4JM.mjs.map +0 -1
  143. package/dist/chunk-LCN4UNYK.cjs +0 -2
  144. package/dist/chunk-LCN4UNYK.cjs.map +0 -1
  145. package/dist/chunk-MB465DI4.mjs +0 -2
  146. package/dist/chunk-MB465DI4.mjs.map +0 -1
  147. package/dist/chunk-OZAYOPLB.mjs +0 -2
  148. package/dist/chunk-QAENYYU6.cjs +0 -2
  149. package/dist/chunk-SFYUJQYW.cjs +0 -2
  150. package/dist/chunk-UUWDQVIJ.mjs +0 -2
  151. package/dist/chunk-UUWDQVIJ.mjs.map +0 -1
  152. package/dist/chunk-VXOZIP77.cjs +0 -2
  153. package/dist/chunk-VXOZIP77.cjs.map +0 -1
  154. package/dist/chunk-WPVL27G4.mjs +0 -2
  155. package/dist/chunk-WPVL27G4.mjs.map +0 -1
  156. package/dist/chunk-Z43GUETW.cjs +0 -2
  157. package/dist/chunk-Z43GUETW.cjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/common/workers.ts","../src/common/risk/options.ts","../src/common/risk/escalation.ts","../src/common/context/snapshot.ts","../src/common/context/policy.ts","../src/interface/policies.ts"],"names":["workersOf","state","item","index","eventIndex","at","all","after","sinceRework","ts","out","t","w","authorOf","RISK_LEVELS","deepFreeze","isObj","x","own","o","k","validated","riskOptions","options","who","bad","what","fix","fail","closed","keys","requirement","q","c","gs","gates","g","assertId","raw","table","below","level","row","rw","rq","ev","requires","i","evidence","here","missing","DEFAULT_RISK_TABLE","isRiskData","data","f","assessorIssue","by","workers","canDo","independenceConflicts","riskEscalation","gate","opts","why","pick","e","freshEvidence","issue","l","resolved","nonEmpty","extra","hidden","repoPathIssue","path","ch","seg","snapshotIssue","list","a","ka","src","ks","pathIssue","recorderIssue","sourced","d","copyOf","source","rest","contextOf","fresh","qualifying","carried","j","assumptions","claim","pos","hits","firstAfter","b","h","KEYS","recordContextSnapshot","methodology","input","id","revision","ref","now","getItem","copy","applyAction","s","addEvidence","RULE","RECORD","contextGroundedViolations","v","message","ctx","of","unverified","withRiskGate","inner","prior","GROUNDED","groundedPolicy","badGrounding","stageIds","key","ids","withContextGrounding","entry","exit","add","on","p","withGroundingHooks","config","stages","st","checked","ceremonyChecked","name","customPolicy","briefContext","policy"],"mappings":"yNAeO,SAASA,CAAAA,CAAUC,CAAAA,CAA8BC,CAAAA,CAA0B,CAChF,IAAMC,CAAAA,CAAQC,mBAAAA,CAAWH,CAAK,CAAA,CACxBI,CAAAA,CAAKF,CAAAA,CAAM,WAAA,CAAY,IAAID,CAAAA,CAAK,EAAE,CAAA,EAAK,EAAC,CACxCI,CAAAA,CAAMJ,CAAAA,CAAK,WAAA,CACXK,EAAQC,mBAAAA,CAAYL,CAAAA,CAAOD,CAAAA,CAAK,EAAA,CAAIG,CAAE,CAAA,CACtCI,CAAAA,CAAKF,CAAAA,GAAU,QAAaF,CAAAA,CAAG,MAAA,GAAWC,CAAAA,CAAI,MAAA,CAASA,CAAAA,CAAMA,CAAAA,CAAI,KAAA,CAAMA,CAAAA,CAAI,OAASC,CAAK,CAAA,CACzFG,CAAAA,CAAM,IAAI,GAAA,CAChB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PC,CAAAA,CACAJ,CAAAA,CACqC,CACrC,OAAII,CAAAA,GAAS,QAAA,CAAiB,CAAE,MAAO,EAAC,CAAG,IAAA,CAAMJ,CAAAA,CAAO,CAAC,CAAA,CAAI,CAACA,CAAAA,CAAO,CAAC,CAAA,CAAE,EAAE,CAAA,CAAI,EAAG,CAAA,CAC7EI,CAAAA,GAAS,OAAA,CAAgB,CAAE,KAAA,CAAO,EAAC,CAAG,IAAA,CAAM,CAAC,SAAS,CAAE,CAAA,CACxDA,IAAS,iBAAA,CAA0B,CAAE,KAAA,CAAO,CAAC,UAAU,CAAA,CAAG,IAAA,CAAM,EAAG,CAAA,CAChE,CAAE,KAAA,CAAO,EAAC,CAAG,IAAA,CAAM,EAAG,CAC/B,CASO,SAASN,EAAAA,CACdlC,CAAAA,CACmB,CACnB,GAAM,CAAE,YAAA,CAAAyC,EAAc,YAAA,CAAAC,CAAa,CAAA,CAAI1C,CAAAA,CACvC,OAAO,CACL,GAAGA,CAAAA,CACH,aAAavG,CAAAA,CAAOC,CAAAA,CAAMiJ,CAAAA,CAAQ,CAChC,OAAOA,CAAAA,CAAO,EAAA,GAAOrB,CAAAA,CACjBT,GAA0BpH,CAAAA,CAAOC,CAAI,CAAA,CACrC+I,CAAAA,EAAc,IAAA,CAAKzC,CAAAA,CAAavG,CAAAA,CAAOC,CAAAA,CAAMiJ,CAAM,CACzD,CAAA,CACA,YAAA,CAAalJ,CAAAA,CAAOC,CAAAA,CAAM,CACxB,OAAOwF,CAAAA,CAAUzF,EAAOC,CAAI,CAAA,EAAKgJ,CAAAA,EAAc,IAAA,CAAK1C,CAAAA,CAAavG,CAAAA,CAAOC,CAAI,CAC9E,CACF,CACF","file":"chunk-66BO7JFR.cjs","sourcesContent":["// Who worked on an item (design spec section 27, F1 G1-1): the independence checks of the\n// risk-adaptive gate and the context-grounded policy compare an assessor or a snapshot's recorder\n// against every one of them, not only the last author.\nimport { authorOf } from \"../core/authors.ts\";\nimport type { WorkItem, WorkflowState } from \"../core/types.ts\";\nimport { eventIndex, sinceRework } from \"../core/event-index.ts\";\n\n/**\n * The roles that worked on `item`: the `by` of each dispatch (a transition into `in_progress`)\n * since the item's last `item.rework` event (or since creation), in order, then its assigned\n * `role` and its author by the 1.3 rule (`authorOf`), each once. The rework boundary is found by\n * matching `item.transitions` to the events that appended them (`item.transition`, and the\n * `blocker.*` events that carry a `transition`) from the end; when those events are not exactly as\n * many as the transitions, every transition counts (fail closed: more workers, never fewer).\n */\nexport function workersOf(state: WorkflowState<string>, item: WorkItem): string[] {\n const index = eventIndex(state);\n const at = index.transitions.get(item.id) ?? [];\n const all = item.transitions;\n const after = sinceRework(index, item.id, at);\n const ts = after === undefined || at.length !== all.length ? all : all.slice(all.length - after);\n const out = new Set<string>();\n for (const t of ts) if (t.to.status === \"in_progress\") out.add(t.by);\n for (const w of [item.role, authorOf(state, item)]) if (w !== undefined) out.add(w);\n return [...out];\n}\n","// Validation of the risk-adaptive gate options (design spec section 27, #35; F1 G1-4, G1-6): one\n// validator for `withRiskGate` (once, at wrap time) and `riskEscalation` (per call, unless given the\n// frozen options the validator itself returned), so both refuse the same input with invalid-input.\nimport { assertId, fail } from \"../../core/errors.ts\";\nimport type { GateRequirement } from \"../../core/types.ts\";\nimport { deepFreeze } from \"../deep-freeze.ts\";\nimport type { RiskGateOptions, RiskLevel, RiskTable } from \"./escalation.ts\";\n\n/** The levels, least strict first. */\nexport const RISK_LEVELS: readonly RiskLevel[] = /* @__PURE__ */ deepFreeze([\n \"low\",\n \"medium\",\n \"high\",\n \"critical\",\n]);\n\nconst isObj = (x: unknown): x is Record<string, unknown> =>\n typeof x === \"object\" && x !== null && !Array.isArray(x);\n/** `o[k]` only when `o` has it as an own property (G5-5, as `compareRuns` reads its input). */\nconst own = (o: Record<string, unknown>, k: string): unknown =>\n Object.hasOwn(o, k) ? o[k] : undefined;\nconst validated = new WeakSet<object>();\n\n/**\n * `options` validated and copied (deeply frozen), so later changes by the caller do not leak in.\n * Refuses `invalid-input`, prefixed with `who`, for: a non-object or an unknown key; `gates` not an\n * array of valid ids; a `table` that is not an object keyed by exactly the four levels, a row with\n * an unknown key, a requirement that is neither `\"human\"` nor `{ capability: <non-empty string> }`,\n * an evidence kind that is not a non-empty string; and a row that does not include every\n * requirement and evidence kind of the level below it (a stricter level only adds, G1-4).\n * Every key is read as an own property: an inherited one counts as absent (G5-5).\n */\nexport function riskOptions(options: unknown, who: string): Required<RiskGateOptions> {\n if (typeof options === \"object\" && options !== null && validated.has(options))\n return options as Required<RiskGateOptions>;\n const bad = (what: string, fix: string): never =>\n fail(\"invalid-input\", `${who} options: ${what}`, fix);\n const closed = (o: Record<string, unknown>, keys: readonly string[], at: string): void => {\n for (const k of Object.keys(o))\n if (!keys.includes(k)) bad(`unknown key \"${k}\" in ${at}`, `use only: ${keys.join(\", \")}`);\n };\n const requirement = (q: unknown, at: string): GateRequirement => {\n if (q === \"human\") return q;\n const c = isObj(q) ? own(q, \"capability\") : undefined;\n if (typeof c !== \"string\" || c.trim() === \"\" || Object.keys(q as object).length !== 1)\n bad(\n `${at} must be \"human\" or { capability: <name> }`,\n 'e.g. [\"human\"] or [{ \"capability\": \"review\" }]',\n );\n return { capability: c as string };\n };\n if (!isObj(options)) bad(\"must be an object\", 'pass { \"gates\": [\"code-review\"] }');\n const o = options as Record<string, unknown>;\n closed(o, [\"gates\", \"table\"], \"options\");\n const gs = own(o, \"gates\");\n if (!Array.isArray(gs))\n bad(\"gates must be an array of gate ids\", 'e.g. \"gates\": [\"code-review\"]');\n const gates = (gs as unknown[]).map((g) => {\n assertId(g, \"risk gate id\");\n return g as string;\n });\n const raw = own(o, \"table\");\n let table: RiskTable | undefined;\n if (raw !== undefined) {\n if (!isObj(raw))\n bad(\"table must be an object keyed by risk level\", `levels: ${RISK_LEVELS.join(\", \")}`);\n const t = raw as Record<string, unknown>;\n closed(t, RISK_LEVELS, \"table\");\n table = {} as RiskTable;\n let below: string[] = [];\n for (const level of RISK_LEVELS) {\n const row = own(t, level);\n if (!isObj(row))\n bad(\n `table is missing level \"${level}\"`,\n `give every level a row, e.g. \"${level}\": { \"requires\": [] }`,\n );\n const rw = row as Record<string, unknown>;\n closed(rw, [\"requires\", \"evidence\"], `table.${level}`);\n const rq = own(rw, \"requires\");\n if (!Array.isArray(rq))\n bad(`table.${level}.requires must be an array`, 'e.g. \"requires\": [\"human\"]');\n const ev = own(rw, \"evidence\");\n if (\n ev !== undefined &&\n (!Array.isArray(ev) || !ev.every((k) => typeof k === \"string\" && k.trim() !== \"\"))\n )\n bad(\n `table.${level}.evidence must be an array of evidence kinds`,\n 'e.g. \"evidence\": [\"sbom\"]',\n );\n const requires = (rq as unknown[]).map((q, i) =>\n requirement(q, `table.${level}.requires[${i}]`),\n );\n const evidence = ev === undefined ? undefined : [...(ev as string[])];\n // each level includes everything the level below it adds; requirements and evidence kinds\n // are separate sets (G5-4: evidence \"human\" is not the requirement \"human\")\n const here = [\n ...requires.map((x) => JSON.stringify(x)),\n ...(evidence ?? []).map((k) => `evidence ${JSON.stringify(k)}`),\n ];\n const missing = below.filter((x) => !here.includes(x));\n if (missing.length)\n bad(\n `table.${level} must include everything the level below it adds (missing ${missing.join(\", \")})`,\n \"a stricter level only adds: copy the lower level's requires and evidence into it\",\n );\n below = here;\n table[level] = { requires, ...(evidence === undefined ? {} : { evidence }) };\n }\n }\n const out = deepFreeze(table ? { gates, table } : ({ gates } as Required<RiskGateOptions>));\n validated.add(out);\n return out;\n}\n","// Risk-adaptive gate (design spec section 27, #35): the level of the strictest fresh, valid and\n// independent `risk-assessment` evidence picks a row of a table of what the gate additionally needs.\nimport { canDo } from \"../../core/roles/guards.ts\";\nimport { freshEvidence } from \"../../core/items/evidence.ts\";\nimport type {\n Evidence,\n Gate,\n GateEscalation,\n GateRequirement,\n WorkItem,\n WorkflowState,\n} from \"../../core/types.ts\";\nimport { deepFreeze } from \"../deep-freeze.ts\";\nimport { independenceConflicts } from \"../independence.ts\";\nimport { workersOf } from \"../workers.ts\";\nimport { RISK_LEVELS, riskOptions } from \"./options.ts\";\n\nexport type RiskLevel = \"low\" | \"medium\" | \"high\" | \"critical\";\n/** `data` of a `risk-assessment` evidence entry. */\nexport interface RiskAssessmentData {\n level: RiskLevel;\n /** Free strings naming what drives the risk, e.g. `ci-cd`, `prod-infra`, `secrets`, `blast-radius`, `irreversible`. */\n factors: string[];\n /** The item SHA or ref that was assessed. */\n subject?: string;\n}\n/** What each level ADDS to the static gate. */\nexport type RiskTable = Record<RiskLevel, { requires: GateRequirement[]; evidence?: string[] }>;\nexport interface RiskGateOptions {\n /** Ids of the gates the policy applies to; every other gate stays static. */\n gates: string[];\n /** Default `DEFAULT_RISK_TABLE`. */\n table?: RiskTable;\n}\n\nexport { RISK_LEVELS };\n\n/** `low` and `medium` add nothing; `high` and `critical` add a human approval. Deeply frozen. */\nexport const DEFAULT_RISK_TABLE: RiskTable = /* @__PURE__ */ deepFreeze({\n low: { requires: [] },\n medium: { requires: [] },\n high: { requires: [\"human\"] },\n critical: { requires: [\"human\"] },\n});\n\nconst isObj = (x: unknown): x is Record<string, unknown> =>\n typeof x === \"object\" && x !== null && !Array.isArray(x);\n\n/** True when `data` is a well-formed `RiskAssessmentData`. */\nexport function isRiskData(data: unknown): data is RiskAssessmentData {\n return (\n isObj(data) &&\n RISK_LEVELS.includes(data[\"level\"] as RiskLevel) &&\n Array.isArray(data[\"factors\"]) &&\n data[\"factors\"].every((f) => typeof f === \"string\") &&\n (data[\"subject\"] === undefined || typeof data[\"subject\"] === \"string\")\n );\n}\n\n/**\n * Why `by` may not assess `item`: `invalid` when it is neither `human` nor a role with capability\n * `verify`, `not-independent` when it worked on the item (`workersOf`: every role that dispatched\n * it since its last rework, its assigned role, its author); `undefined` when it may. `workers`\n * defaults to `workersOf(state, item)`; pass it to check several assessors against one state.\n */\nexport function assessorIssue(\n state: WorkflowState<string>,\n item: WorkItem,\n by: string,\n workers: readonly string[] = workersOf(state, item),\n): \"invalid\" | \"not-independent\" | undefined {\n if (!canDo(state, by, \"verify\")) return \"invalid\";\n return independenceConflicts(by, workers).length ? \"not-independent\" : undefined;\n}\n\n/**\n * The escalation of `gate` for `item` under `options` (the `escalateGate` hook `withRiskGate`\n * installs): `undefined` for a gate not in `options.gates`, else the table row of the resolved\n * level. The resolved level is the strictest fresh (post-rework) valid assessment, so a later,\n * lower assessment never relaxes an earlier one; with none it is `critical`, and `reason.why` says\n * whether assessments were `missing`, `invalid` or `not-independent` (the latest rejected one).\n * Invalid options fail `invalid-input` as in `withRiskGate`, never a `TypeError`. Pure: no clock,\n * no randomness; the same state gives the same answer.\n */\nexport function riskEscalation(\n state: WorkflowState<string>,\n item: WorkItem,\n gate: Gate,\n options: RiskGateOptions,\n): GateEscalation | undefined {\n // validated here unless these are the frozen options withRiskGate validated (G1-6)\n const opts = riskOptions(options, \"riskEscalation\");\n if (!opts.gates.includes(gate.id)) return undefined;\n let level: RiskLevel | undefined;\n let why = \"missing\";\n let pick: Evidence | undefined;\n let workers: string[] | undefined;\n for (const e of freshEvidence(state, item)) {\n if (e.kind !== \"risk-assessment\") continue;\n const issue = isRiskData(e.data)\n ? assessorIssue(state, item, e.by, (workers ??= workersOf(state, item)))\n : \"invalid\";\n if (issue) {\n if (!level) {\n why = issue;\n pick = e;\n }\n continue;\n }\n const l = (e.data as unknown as RiskAssessmentData).level;\n if (!level || RISK_LEVELS.indexOf(l) >= RISK_LEVELS.indexOf(level)) {\n level = l;\n why = \"assessed\";\n pick = e;\n }\n }\n const resolved = level ?? \"critical\";\n const row = (opts.table ?? DEFAULT_RISK_TABLE)[resolved];\n return {\n requires: row.requires.map((q) => (q === \"human\" ? q : { capability: q.capability })),\n evidence: [...(row.evidence ?? [])],\n reason: { level: resolved, why, assessment: pick?.ref ?? null, by: pick?.by ?? null },\n };\n}\n","// Context snapshots (design spec section 27, #36): what a scout verified about the repository\n// before an item is worked, as evidence `context-snapshot`, and whether a later `repo.changed`\n// event made it stale. Event order decides, never timestamps (principle 5); no file is read.\nimport { fail } from \"../../core/errors.ts\";\nimport { addEvidence } from \"../../core/items/evidence.ts\";\nimport { getItem } from \"../../core/items/record.ts\";\nimport { applyAction } from \"../../core/methodology.ts\";\nimport type {\n ApplyResult,\n BriefContext,\n ContextAssumption,\n ContextSnapshotData,\n Methodology,\n WorkItem,\n WorkflowState,\n} from \"../../core/types.ts\";\nimport { eventIndex, firstAfter, sinceRework } from \"../../core/event-index.ts\";\nimport { workersOf } from \"../workers.ts\";\n\nexport interface ContextSnapshotInput {\n item: string;\n /** The repository revision the snapshot was taken at. */\n revision: string;\n assumptions: ContextAssumption[];\n /** The host's snapshot artifact. */\n ref: string;\n /** Who recorded it: `human` or a registered role that did not work on the item. */\n by: string;\n now?: string;\n}\n\nconst isObj = (x: unknown): x is Record<string, unknown> =>\n typeof x === \"object\" && x !== null && !Array.isArray(x);\nconst nonEmpty = (x: unknown): x is string => typeof x === \"string\" && x.trim() !== \"\";\nconst extra = (o: Record<string, unknown>, keys: string[]) =>\n Object.keys(o).find((k) => !keys.includes(k));\n\n/** True for a C0 or C1 control character or a bidirectional formatting character. */\nfunction hidden(c: number): boolean {\n return (\n c < 0x20 ||\n (c >= 0x7f && c <= 0x9f) ||\n c === 0x61c ||\n c === 0x200e ||\n c === 0x200f ||\n (c >= 0x202a && c <= 0x202e) ||\n (c >= 0x2066 && c <= 0x2069)\n );\n}\n\n/**\n * Why `path` is not a repository-relative POSIX path as Git lists it, or `undefined` when it is:\n * no leading `/`, `./` or drive letter, `/` separators only, no empty, `.` or `..` segment, at most\n * 4096 characters, Unicode NFC, no control or bidirectional formatting character and no leading or\n * trailing whitespace (F1 G2-8, G4-4). Paths are compared exactly (case included), so the recorders\n * accept one spelling per file.\n */\nexport function repoPathIssue(path: unknown): string | undefined {\n const why =\n typeof path !== \"string\"\n ? \"not a string\"\n : path.length > 4096\n ? \"longer than 4096 characters\"\n : [...path].some((ch) => hidden(ch.codePointAt(0)!))\n ? \"has a control or bidirectional formatting character\"\n : path !== path.trim()\n ? \"has leading or trailing whitespace\"\n : path !== path.normalize(\"NFC\")\n ? \"is not Unicode NFC\"\n : path.includes(\"\\\\\") ||\n /^[A-Za-z]:/.test(path) ||\n !path.split(\"/\").every((seg) => seg !== \"\" && seg !== \".\" && seg !== \"..\")\n ? \"is not relative with / separators and no empty, . or .. segment\"\n : undefined;\n if (!why) return undefined;\n const shown = JSON.stringify(\n typeof path === \"string\" && path.length > 80 ? `${path.slice(0, 80)}…` : path,\n );\n return `${shown} is not a repository-relative POSIX path (${why})`;\n}\n\n/** Why `data` is not a well-formed `ContextSnapshotData` (closed objects), or `undefined`. */\nfunction snapshotIssue(data: unknown): string | undefined {\n if (!isObj(data)) return \"data must be an object\";\n const k = extra(data, [\"revision\", \"assumptions\"]);\n if (k) return `unknown key \"${k}\"`;\n if (!nonEmpty(data[\"revision\"])) return \"revision must be a non-empty string\";\n const list = data[\"assumptions\"];\n if (!Array.isArray(list)) return \"assumptions must be an array\";\n for (const [i, a] of list.entries()) {\n const at = `assumptions[${i}]`;\n if (!isObj(a)) return `${at} must be an object`;\n const ka = extra(a, [\"claim\", \"required\", \"source\"]);\n if (ka) return `unknown key \"${ka}\" in ${at}`;\n if (!nonEmpty(a[\"claim\"])) return `${at}.claim must be a non-empty string`;\n if (a[\"required\"] !== undefined && typeof a[\"required\"] !== \"boolean\")\n return `${at}.required must be a boolean`;\n const src = a[\"source\"];\n if (src === undefined) continue;\n if (!isObj(src)) return `${at}.source must be an object`;\n const ks = extra(src, [\"path\", \"lines\", \"hash\"]);\n if (ks) return `unknown key \"${ks}\" in ${at}.source`;\n const pathIssue = repoPathIssue(src[\"path\"]);\n if (pathIssue) return `${at}.source.path ${pathIssue}`;\n if (!nonEmpty(src[\"hash\"])) return `${at}.source.hash must be a non-empty string`;\n const l = src[\"lines\"];\n if (\n l !== undefined &&\n !(\n Array.isArray(l) &&\n l.length === 2 &&\n Number.isInteger(l[0]) &&\n Number.isInteger(l[1]) &&\n 1 <= l[0] &&\n l[0] <= l[1]\n )\n )\n return `${at}.source.lines must be two integers [from, to] with 1 <= from <= to`;\n }\n return undefined;\n}\n\n/**\n * Why `by` may not ground an item whose workers are `workers` (design spec section 27, F1 G1-2,\n * G2-2): it is neither `human` nor a registered role, or it worked on the item; else `undefined`.\n */\nfunction recorderIssue(\n state: WorkflowState<string>,\n by: unknown,\n workers: readonly string[],\n): string | undefined {\n if (typeof by !== \"string\" || (by !== \"human\" && !Object.hasOwn(state.roles, by)))\n return `${JSON.stringify(by)} is neither human nor a registered role`;\n return workers.includes(by) ? `\"${by}\" worked on the item` : undefined;\n}\nconst sourced = (d: ContextSnapshotData): boolean => d.assumptions.some((a) => a.source);\n/** A copy of a validated assumption (closed object: claim, required, source { path, lines, hash }). */\nconst copyOf = ({ source, ...rest }: ContextAssumption): ContextAssumption =>\n source\n ? {\n ...rest,\n source: {\n ...source,\n ...(source.lines ? { lines: [...source.lines] as [number, number] } : {}),\n },\n }\n : rest;\n\n/**\n * The item's current context (design spec section 27, #36): its latest fresh (post-rework)\n * qualifying `context-snapshot` evidence (valid data with at least one sourced assumption,\n * recorded by `human` or a registered role that did not work on the item, `workersOf`), with\n * `stale` the cited source paths a later `repo.changed` event listed (exact match, in event order)\n * and `unverified` the claims with no source; `undefined` when there is none. The `required`\n * claims of every other valid fresh snapshot (earlier or later, whoever recorded it) carry (spec 28, #49): reported\n * `required: true` when the latest has the claim, appended as `{ claim, required: true }` (no\n * source, so unverified) when it lacks it; claims compare by exact text. The answer is a\n * copy. Each evidence entry is located at its own `item.evidence` event, matched from the end as\n * `freshEvidence` does; an entry with no event counts as older than every event.\n */\nexport function contextOf(state: WorkflowState<string>, item: WorkItem): BriefContext | undefined {\n // one indexed pass over the log per state, not per item (F1 G3-2, G3-3, G3-4)\n const index = eventIndex(state);\n const at = index.evidence.get(item.id) ?? [];\n const all = item.evidence;\n const after = sinceRework(index, item.id, at);\n const fresh = after === undefined ? all.length : Math.min(after, all.length);\n let workers: string[] | undefined;\n // the data of entry k when it is a qualifying snapshot; one that does not qualify is ignored, so\n // it cannot supersede one that does (G2-1)\n const qualifying = (k: number): ContextSnapshotData | undefined => {\n const e = all[k]!;\n if (e.kind !== \"context-snapshot\" || snapshotIssue(e.data) !== undefined) return undefined;\n const data = e.data as unknown as ContextSnapshotData;\n return !sourced(data) || recorderIssue(state, e.by, (workers ??= workersOf(state, item)))\n ? undefined\n : data;\n };\n for (let k = all.length - 1; k >= all.length - fresh; k--) {\n const e = all[k]!;\n const data = qualifying(k);\n if (!data) continue;\n // the required claims of every other valid fresh snapshot (earlier or later) carry, whoever recorded\n // it: independence decides who may verify a claim, not which claims are required (spec 28,\n // #49, gate G1-3)\n const carried = new Set<string>();\n for (let j = all.length - 1; j >= all.length - fresh; j--) {\n const d = all[j]!;\n if (j === k) continue;\n if (d.kind === \"context-snapshot\" && snapshotIssue(d.data) === undefined)\n for (const a of (d.data as unknown as ContextSnapshotData).assumptions)\n if (a.required) carried.add(a.claim);\n }\n const assumptions = data.assumptions.map((a) =>\n carried.has(a.claim) ? { ...copyOf(a), required: true } : copyOf(a),\n );\n for (const claim of carried)\n if (!data.assumptions.some((a) => a.claim === claim))\n assumptions.push({ claim, required: true });\n // each cited path's first repo.changed after the snapshot's own event, in event order\n const pos = at[k + at.length - all.length] ?? -1;\n const hits: [number, number, string][] = [];\n for (const path of new Set(data.assumptions.map((a) => a.source?.path))) {\n const list = path === undefined ? undefined : index.changed.get(path);\n const f = list ? firstAfter(list, pos, (x) => x[0]) : 0;\n if (list && f < list.length) hits.push([list[f]![0], list[f]![1], path!]);\n }\n // oxlint-disable-next-line unicorn/no-array-sort -- a fresh local array; toSorted needs Node 20\n hits.sort((a, b) => a[0] - b[0] || a[1] - b[1]);\n return {\n revision: data.revision,\n // copies: a caller (a brief, a host) changing the answer must not change the state (G2-9)\n assumptions,\n snapshot: e.ref,\n by: e.by,\n stale: hits.map((h) => h[2]),\n unverified: assumptions.filter((a) => !a.source).map((a) => a.claim),\n };\n }\n return undefined;\n}\n\nconst KEYS = [\"item\", \"revision\", \"assumptions\", \"ref\", \"by\", \"now\"];\nconst bad = (what: string, fix: string): never =>\n fail(\"invalid-input\", `context snapshot: ${what}`, fix);\n\n/**\n * Records a context snapshot of an item as evidence `context-snapshot` with `data: { revision,\n * assumptions }` (design spec section 27, #36), through `applyAction` (action `context.snapshot`)\n * so the methodology's rules see it. Refuses `invalid-input` for an unknown key, an empty revision,\n * claim or ref, a source with a path that is not repository-relative POSIX or an empty hash,\n * `lines` that are not two integers `1 <= from <= to`, no assumption with a source, and a `by`\n * that is neither `human` nor a registered role or that worked on the item. The input is copied.\n */\nexport function recordContextSnapshot<N extends string>(\n state: WorkflowState<N>,\n methodology: Methodology<unknown, N>,\n input: ContextSnapshotInput,\n): ApplyResult<N> {\n if (!isObj(input)) bad(\"input must be an object\", `pass { ${KEYS.join(\", \")} }`);\n const k = extra(input as unknown as Record<string, unknown>, KEYS);\n if (k) bad(`unknown key \"${k}\"`, `use only: ${KEYS.join(\", \")}`);\n const { item: id, revision, assumptions, ref, by, now } = input;\n if (typeof id !== \"string\") bad(\"item must be an item id\", 'e.g. \"item\": \"CART-12\"');\n const item = getItem(state, id);\n const data = { revision, assumptions } as unknown as Record<string, unknown>;\n const issue = snapshotIssue(data);\n if (issue)\n bad(\n issue,\n 'e.g. { \"revision\": \"4f2c1e0\", \"assumptions\": [{ \"claim\": \"totals are cents\", \"source\": { \"path\": \"src/cart.ts\", \"hash\": \"…\" } }] }',\n );\n if (!nonEmpty(ref))\n bad(\"ref must be a non-empty string\", 'name the snapshot artifact, e.g. \"ctx/CART-12.json\"');\n if (!nonEmpty(by)) bad(\"by must name who recorded it\", 'e.g. \"by\": \"scout\"');\n const who = recorderIssue(state, by, workersOf(state, item));\n if (who)\n bad(\n `${who} and may not record its context`,\n \"record as human or a registered role that did not work on the item\",\n );\n if (!sourced(data as unknown as ContextSnapshotData))\n bad(\n \"a snapshot needs at least one assumption with a source (nothing was verified)\",\n 'cite what was checked, e.g. \"source\": { \"path\": \"src/cart.ts\", \"hash\": \"…\" }',\n );\n if (now !== undefined && typeof now !== \"string\")\n bad(\"now must be an ISO timestamp string\", \"omit now to use the clock\");\n // validated plain data, copied so no reference to the caller's arrays is kept\n const copy = JSON.parse(JSON.stringify(data)) as Record<string, unknown>;\n return applyAction(\n state,\n methodology,\n { type: \"context.snapshot\", by, payload: { item: id, ref, ...copy } },\n (s) => addEvidence(s, id, { kind: \"context-snapshot\", ref, by, data: copy }, now),\n );\n}\n","// The context-grounded entry policy (design spec section 27, #36): an item may enter a stage only\n// with a fresh, verified context snapshot that a human or a registered role other than its workers\n// recorded (contextOf counts only such a snapshot).\nimport type { Violation, WorkItem, WorkflowState } from \"../../core/types.ts\";\nimport { contextOf } from \"./snapshot.ts\";\n\nconst RULE = \"policy:custom:context-grounded\";\nconst RECORD = \"record a fresh one with recordContextSnapshot\";\n\n/**\n * Violations of the custom policy `context-grounded` for `item` (rule\n * `policy:custom:context-grounded`, the 1.2 rule id of a custom policy): no qualifying fresh\n * context snapshot (`contextOf`: valid, at least one sourced assumption, recorded by `human` or a\n * registered role that did not work on the item); a stale one (names the changed paths); a\n * `required` assumption without a source (names the claims). Empty when the item is grounded.\n * Pure: the same state gives the same answer.\n */\nexport function contextGroundedViolations(\n state: WorkflowState<string>,\n item: WorkItem,\n): Violation[] {\n const out: Violation[] = [];\n const v = (message: string, fix: string) =>\n out.push({ rule: RULE, severity: \"error\", item: item.id, message, fix });\n const ctx = contextOf(state, item);\n if (!ctx) {\n v(\n `item \"${item.id}\" has no qualifying context snapshot (none since its last rework is valid, cites a source and was recorded by human or a registered role that did not work on it)`,\n `have an independent role or a human verify the context and ${RECORD}`,\n );\n return out;\n }\n const of = `context snapshot \"${ctx.snapshot}\" of \"${item.id}\"`;\n if (ctx.stale.length)\n v(\n `${of} is stale: ${ctx.stale.join(\", \")} changed since`,\n `re-verify the claims and ${RECORD}`,\n );\n const required = ctx.assumptions.filter((a) => a.required);\n const unverified = required.filter((a) => !a.source).map((a) => a.claim);\n if (unverified.length)\n v(\n `${of} has unverified required assumption(s): ${unverified.join(\" | \")}`,\n `cite a source { path, hash } for each and ${RECORD}`,\n );\n return out;\n}\n","// Wrappers that turn any methodology into one carrying a policy (design spec section 27). The\n// wrapped methodology keeps every other member, its name included, so registerMethodology accepts it.\nimport { assertId, fail } from \"../core/errors.ts\";\nimport type { Methodology, Policy } from \"../core/types.ts\";\nimport { contextGroundedViolations } from \"../common/context/policy.ts\";\nimport { contextOf } from \"../common/context/snapshot.ts\";\nimport { riskEscalation, type RiskGateOptions } from \"../common/risk/escalation.ts\";\nimport { riskOptions } from \"../common/risk/options.ts\";\n\nconst isObj = (x: unknown): x is Record<string, unknown> =>\n typeof x === \"object\" && x !== null && !Array.isArray(x);\n\n/**\n * `methodology` with the risk-adaptive gate policy (design spec section 27, #35): for each gate in\n * `options.gates`, `complete()` adds the requirements of the row of `options.table` (default\n * `DEFAULT_RISK_TABLE`) that the item's strictest fresh, valid, independent risk assessment picks,\n * `critical` when there is none. An `escalateGate` the methodology already has is kept: both widen\n * the gate. Invalid options fail `invalid-input` here, once.\n */\nexport function withRiskGate<C, N extends string>(\n methodology: Methodology<C, N>,\n options: RiskGateOptions,\n): Methodology<C, N> {\n const opts = riskOptions(options, \"withRiskGate\");\n const inner = methodology.escalateGate;\n return {\n ...methodology,\n escalateGate(state, item, gate) {\n const own = riskEscalation(state, item, gate, opts);\n const prior = inner?.call(methodology, state, item, gate);\n if (!prior || !own) return prior ?? own;\n return {\n requires: [...prior.requires, ...own.requires],\n evidence: [...prior.evidence, ...own.evidence],\n reason: { ...prior.reason, ...own.reason },\n };\n },\n };\n}\n\nexport interface ContextGroundingOptions {\n /** Stage ids whose entry policies gain the custom policy `context-grounded`. */\n entry: string[];\n /** Stage ids whose exit policies gain it. */\n exit?: string[];\n}\n\nconst GROUNDED = \"context-grounded\";\nconst groundedPolicy: Policy = {\n kind: \"custom\",\n id: GROUNDED,\n description: \"grounded in a fresh, verified context snapshot\",\n};\nconst badGrounding = (what: string, fix: string): never =>\n fail(\"invalid-input\", `withContextGrounding options: ${what}`, fix);\n\nfunction stageIds(o: Record<string, unknown>, key: \"entry\" | \"exit\"): string[] {\n const ids = o[key];\n if (ids === undefined && key === \"exit\") return [];\n if (!Array.isArray(ids))\n badGrounding(`${key} must be an array of stage ids`, `e.g. \"${key}\": [\"dev\"]`);\n return (ids as unknown[]).map((id) => {\n assertId(id, `context-grounded ${key} stage id`);\n return id as string;\n });\n}\n\n/**\n * `methodology` with the context-grounded policy (design spec section 27, #36): `defaultStages`\n * adds the custom policy `context-grounded` to the entry policies of the `entry` stages and the\n * exit policies of the `exit` stages (an unknown stage id fails `invalid-input` there), and\n * `plan()`/`complete()` answer it with `contextGroundedViolations`; `synthesizeBrief` carries\n * `contextOf` as `Brief.context`. Hooks the methodology already has answer every other policy id\n * and a brief with no snapshot. Invalid options fail `invalid-input` here, once.\n */\nexport function withContextGrounding<C, N extends string>(\n methodology: Methodology<C, N>,\n options: ContextGroundingOptions,\n): Methodology<C, N> {\n if (!isObj(options)) badGrounding(\"must be an object\", 'pass { \"entry\": [\"dev\"] }');\n const o = options as unknown as Record<string, unknown>;\n for (const k of Object.keys(o))\n if (k !== \"entry\" && k !== \"exit\") badGrounding(`unknown key \"${k}\"`, \"use only: entry, exit\");\n const entry = stageIds(o, \"entry\");\n const exit = stageIds(o, \"exit\");\n const add = (list: Policy[], on: boolean): Policy[] =>\n on && !list.some((p) => p.kind === \"custom\" && p.id === GROUNDED)\n ? [...list, groundedPolicy]\n : list;\n return {\n ...withGroundingHooks(methodology),\n defaultStages(config) {\n const stages = methodology.defaultStages(config);\n for (const id of [...entry, ...exit])\n if (!stages.some((st) => st.id === id))\n fail(\n \"invalid-input\",\n `withContextGrounding: unknown stage \"${id}\"`,\n `stages: ${stages.map((st) => st.id).join(\", \")}`,\n );\n // a built-in ceremony checks these policies without the hook, so the policy could never pass\n // there (spec 28, G2 finding 2): refuse them here, once\n const checked = ceremonyChecked(methodology.name, stages);\n for (const [key, ids] of [\n [\"entry\", entry],\n [\"exit\", exit],\n ] as const)\n for (const id of ids)\n if (checked[key].includes(id))\n fail(\n \"invalid-input\",\n `withContextGrounding: the ${methodology.name} ceremony that moves items ${key === \"entry\" ? \"into\" : \"out of\"} \"${id}\" checks its ${key} policies without the grounding hook`,\n `ground a later stage instead, e.g. ${key} [\"${stages.find((st) => !checked.entry.includes(st.id) && !checked.exit.includes(st.id) && st.id !== stages[0]!.id)?.id ?? \"dev\"}\"]`,\n );\n return stages.map((st) => ({\n ...st,\n entryPolicy: add(st.entryPolicy, entry.includes(st.id)),\n exitPolicy: add(st.exitPolicy, exit.includes(st.id)),\n }));\n },\n };\n}\n\n/** Stage policies a built-in methodology's ceremonies check with `assertPolicies` (spec 28). */\nfunction ceremonyChecked(\n name: string,\n stages: readonly { id: string }[],\n): { entry: string[]; exit: string[] } {\n if (name === \"kanban\") return { entry: [], exit: stages[0] ? [stages[0].id] : [] };\n if (name === \"scrum\") return { entry: [], exit: [\"backlog\"] };\n if (name === \"experimentation\") return { entry: [\"building\"], exit: [] };\n return { entry: [], exit: [] };\n}\n\n/**\n * `methodology` with the hooks that answer the custom policy `context-grounded` (spec 28, #47):\n * `customPolicy` with `contextGroundedViolations`, `briefContext` with `contextOf`; hooks the\n * methodology already has answer every other policy id and a brief with no snapshot. Stages are\n * untouched. `withContextGrounding` builds on it, and the CLI wraps every methodology with it so a\n * state the SDK grounded is judged by its snapshots there too. Not exported from an entry point.\n */\nexport function withGroundingHooks<C, N extends string>(\n methodology: Methodology<C, N>,\n): Methodology<C, N> {\n const { customPolicy, briefContext } = methodology;\n return {\n ...methodology,\n customPolicy(state, item, policy) {\n return policy.id === GROUNDED\n ? contextGroundedViolations(state, item)\n : customPolicy?.call(methodology, state, item, policy);\n },\n briefContext(state, item) {\n return contextOf(state, item) ?? briefContext?.call(methodology, state, item);\n },\n };\n}\n"]}
@@ -0,0 +1,2 @@
1
+ 'use strict';function r(n,t){return [...new Set(typeof n=="string"?[n]:n)].filter(e=>t.includes(e))}exports.a=r;//# sourceMappingURL=chunk-6PFJYRM7.cjs.map
2
+ //# sourceMappingURL=chunk-6PFJYRM7.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/common/independence.ts"],"names":["independenceConflicts","verifiers","workers","id"],"mappings":"aAYO,SAASA,CAAAA,CACdC,CAAAA,CACAC,CAAAA,CACU,CACV,OAAO,CAAC,GAAG,IAAI,GAAA,CAAI,OAAOD,CAAAA,EAAc,QAAA,CAAW,CAACA,CAAS,CAAA,CAAIA,CAAS,CAAC,CAAA,CAAE,MAAA,CAAQE,GACnFD,CAAAA,CAAQ,QAAA,CAASC,CAAE,CACrB,CACF","file":"chunk-6PFJYRM7.cjs","sourcesContent":["/**\n * Independence check: a verifying role must not be one that did the work.\n *\n * Returns the ids in `verifiers` that also appear in `workers`, each once, in verifier order;\n * an empty array means the verification is independent. Ids are compared exactly. The caller\n * decides how a conflict fails (a rule violation, a refused ceremony, a skipped role), so the\n * check carries no message of its own.\n *\n * @example\n * // a validator may not validate a candidate it built or integrated\n * if (independenceConflicts(by, [candidate.author, integration.by]).length) refuse();\n */\nexport function independenceConflicts(\n verifiers: string | readonly string[],\n workers: readonly string[],\n): string[] {\n return [...new Set(typeof verifiers === \"string\" ? [verifiers] : verifiers)].filter((id) =>\n workers.includes(id),\n );\n}\n"]}
@@ -0,0 +1,2 @@
1
+ 'use strict';var chunkKLOSFZFK_cjs=require('./chunk-KLOSFZFK.cjs'),chunk6PFJYRM7_cjs=require('./chunk-6PFJYRM7.cjs'),chunkBBI7AKJK_cjs=require('./chunk-BBI7AKJK.cjs'),chunkTBLIZIWH_cjs=require('./chunk-TBLIZIWH.cjs'),chunkOSHBJIYD_cjs=require('./chunk-OSHBJIYD.cjs');var m=e=>chunkBBI7AKJK_cjs.a(e,"investigation"),_=(e,i)=>chunkBBI7AKJK_cjs.b(e,"investigation",i);function v(e,i){return [...new Set([...e.events.filter(d=>d.type==="item.completed"&&d.payload.id===i).map(d=>d.by),...(e.items[i]?.transitions??[]).filter(d=>d.to.status==="in_progress").map(d=>d.by)])]}function N(e,i){let d;for(let p=e.events.length-1;p>=0;p--){let s=e.events[p];if(s.type==="item.completed"&&s.payload.id===i){d=s.payload;break}}return d&&["done","needs-review"].includes(d.verdict)?d.produced.filter(p=>p.kind==="experiment-output").map(p=>p.ref):[]}function I(e){return chunkOSHBJIYD_cjs.b("invalid-input",`the investigation state is inconsistent: ${e}`,"restore .workflow/state.json from git, or start a new investigation")}function O(e){return e.rounds.at(-1)??I(`phase ${e.phase} has no round`)}function S(e){return e.iterations.find(i=>i.id==="investigation")??I('there is no "investigation" iteration')}function R(e){let i=e;return (!i||typeof i!="object"||Array.isArray(i)||typeof i.question!="string"||!i.question.trim()||!Number.isSafeInteger(i.maxRounds)||i.maxRounds<1||!i.budget||typeof i.budget!="object"||Array.isArray(i.budget)||!Object.keys(i.budget).length||Object.entries(i.budget).some(([d,p])=>!["tokens","turns","wallclockMs"].includes(d)||typeof p!="number"||!Number.isFinite(p)||p<=0))&&chunkOSHBJIYD_cjs.b("config-invalid","investigation requires question, positive maxRounds and a finite positive budget","provide bounded investigation config"),{question:i.question,maxRounds:i.maxRounds,budget:{...i.budget}}}function H(e,i,d,p){let s=m(e);return chunkOSHBJIYD_cjs.b("invalid-input",`${i} (phase ${s?.phase??"intake"}): ${d}`,p,{items:s?[s.item,...s.rounds.at(-1)?[s.rounds.at(-1).item]:[]]:[]})}var F=(e,i)=>!!e&&!!i&&!chunkKLOSFZFK_cjs.a(e,i,["id","claim","falsifiedBy"]).length,y=e=>typeof e=="string"&&e.trim().length>0,B=e=>Array.isArray(e)&&e.length>0&&e.every(y)&&new Set(e).size===e.length,D=(e,i)=>e&&typeof e=="object"&&!Array.isArray(e)?Object.keys(e).find(d=>!i.includes(d)):void 0,E=(e,i)=>Array.isArray(e)?e.map(d=>D(d,i)).find(Boolean):void 0;function Q(e,i,d){chunkTBLIZIWH_cjs.e(e,i)?.capabilities.includes(d)||chunkOSHBJIYD_cjs.b("missing-capability",`${i} needs ${d}`,"use a registered role with the required capability");}function b(e,i,d,p){return chunkTBLIZIWH_cjs.c(_(e,i),`investigation.${p}`,d.by,{...i},chunkTBLIZIWH_cjs.a(d.now))}function C(e,i,d,p,s){let n=chunkTBLIZIWH_cjs.a(d.now),t=b(e,{...i,phase:"closed",outcome:p,...s?{stopReason:s}:{}},d,p);t={...t,iterations:t.iterations.map(a=>a.id==="investigation"?{...a,endedAt:n,outcome:p==="stopped"?"cancelled":"completed"}:a)};for(let a of Object.values(t.items).filter(r=>r.id===i.item||i.rounds.some(u=>u.item===r.id)))a.status!=="done"&&a.status!=="dropped"&&(t=chunkTBLIZIWH_cjs.v(t,a.id,{status:p==="resolved"&&a.id===i.item?"done":"dropped"},d.by,n));return t}function U(e){let i,d=()=>i??=e(),p=(s,n,t,a)=>(r,u)=>{Q(r,u.by,n);let o=m(r);return (!o||o.phase==="closed")&&H(r,s,"no active investigation","start a new investigation with intake {item}"),t&&o.phase!==t&&!(s==="hypotheses"&&o.phase==="preregister")&&H(r,s,`expected ${t}, got ${o.phase}`,`finish phase ${o.phase} before calling ${s}; ${s} requires phase ${t}`),chunkTBLIZIWH_cjs.V(r,d(),{type:`ceremony.${s}`,by:u.by,payload:u},()=>a(r,o,u,(l,g)=>H(r,s,l,g)))};return {intake(s,n){Q(s,n.by,"facilitate");let t=(r,u)=>H(s,"intake",r,u);s.methodology!=="investigation"&&t(`workflow methodology is ${s.methodology}, not investigation`,"init a workflow with the investigation methodology before intake"),m(s)&&t("investigation already started","use the existing investigation or initialize a new workflow"),y(n.item)||t("item is required","set intake.item to a unique investigation item ID");let a=R(s.config);return chunkTBLIZIWH_cjs.V(s,d(),{type:"ceremony.intake",by:n.by,payload:n},()=>{let r=chunkTBLIZIWH_cjs.t(s,{id:n.item,title:a.question,acceptance:["Independent evidence-based conclusion"],stage:"intake"},n.by,n.now);return r={...r,iterations:[...r.iterations,{id:"investigation",goal:a.question,budget:{...a.budget},spent:{tokens:0,turns:0,wallclockMs:0},startedAt:chunkTBLIZIWH_cjs.a(n.now),committed:[],carryover:[]}]},b(r,{item:n.item,phase:"hypotheses",hypotheses:[],rounds:[],contributors:[n.by]},n,"intake")})},hypotheses:p("hypotheses","define-acceptance","hypotheses",(s,n,t,a)=>{let r=t.hypotheses,u=E(r,["id","claim","falsifiedBy"]);return u&&a(`unknown key "${u}" in a hypotheses entry`,"use only id, claim and falsifiedBy in each hypotheses entry"),(!Array.isArray(r)||!r.length||r.some(o=>!o||!y(o.id)||!y(o.claim)||!y(o.falsifiedBy))||new Set(r.map(o=>o.id)).size!==r.length||r.length<2&&!y(t.singleHypothesisRationale))&&a("provide competing falsifiable hypotheses or single-testable rationale","set hypotheses to unique {id, claim, falsifiedBy} entries; supply singleHypothesisRationale when there is only one"),b(s,{...n,hypotheses:r.map(o=>({id:o.id,claim:o.claim,falsifiedBy:o.falsifiedBy})),...y(t.singleHypothesisRationale)?{singleHypothesisRationale:t.singleHypothesisRationale}:{},contributors:[...new Set([...n.contributors,t.by])],phase:"preregister"},t,"hypotheses")}),preregister:p("preregister","define-acceptance","preregister",(s,n,t,a)=>{let r=R(s.config),u=s.iterations.find(c=>c.id==="investigation");(n.rounds.length>=r.maxRounds||!u||chunkTBLIZIWH_cjs.M(r.budget,u.spent))&&a(`round limit or budget exhausted (${n.rounds.length} of ${r.maxRounds} rounds used)`,"call stop {reason} to close this investigation, or start a new one with a larger maxRounds or budget");let o=t.experiment,l=D(o,["id","procedureRef","predictions","replayOf"])??E(o?.predictions,["hypothesis","prediction"]);if(l&&a(`unknown key "${l}" in experiment`,"use only id, procedureRef, predictions [{hypothesis, prediction}] and replayOf in experiment"),(!o||!y(o.id)||!y(o.procedureRef)||n.rounds.some(c=>c.experiment.id===o.id)||!Array.isArray(o.predictions)||o.predictions.length!==n.hypotheses.length||n.hypotheses.some(c=>o.predictions.filter(f=>f?.hypothesis===c.id&&y(f.prediction)).length!==1)||new Set(o.predictions.map(c=>c.prediction)).size!==o.predictions.length)&&a("preregister unique experiment with differing predictions for every hypothesis","set experiment.id to a new ID, experiment.procedureRef, and one distinct experiment.predictions entry per hypothesis"),o.replayOf){let c=n.rounds.find(f=>f.experiment.id===o.replayOf&&f.result?.valid);(!c||chunkKLOSFZFK_cjs.a(c.experiment,o,["procedureRef"]).length||c.hypotheses.length!==n.hypotheses.length||n.hypotheses.some(f=>!F(f,c.hypotheses.find(q=>q.id===f.id)))||o.predictions.some(f=>!c.experiment.predictions.some(q=>!chunkKLOSFZFK_cjs.a(q,f,["hypothesis","prediction"]).length)))&&a("replay must repeat the procedure, predictions and hypotheses of a prior valid experiment","set experiment.replayOf to a valid prior experiment with identical procedureRef, predictions and hypothesis definitions");}let g=`${n.item}-run-${n.rounds.length+1}`,w=chunkTBLIZIWH_cjs.t(s,{id:g,title:`Experiment ${o.id}`,stage:"execute",acceptance:[o.procedureRef],iteration:"investigation"},t.by,t.now);return w={...w,iterations:w.iterations.map(c=>c.id==="investigation"?{...c,committed:[...c.committed,g]}:c)},b(w,{...n,phase:"observe",rounds:[...n.rounds,{experiment:{id:o.id,procedureRef:o.procedureRef,predictions:o.predictions.map(c=>({hypothesis:c.hypothesis,prediction:c.prediction})),...o.replayOf?{replayOf:o.replayOf}:{}},hypotheses:n.hypotheses.map(c=>({...c})),item:g,by:t.by}],contributors:[...new Set([...n.contributors,t.by])]},t,"preregister")}),observe:p("observe","verify","observe",(s,n,t,a)=>{let r=O(n),u=t.result,o=D(u,["id","valid","summary","provenanceRefs"]);return o&&a(`unknown key "${o}" in result`,"use only id, valid, summary and provenanceRefs in result"),(t.experiment!==r.experiment.id||!u||!y(u.id)||typeof u.valid!="boolean"||!y(u.summary)||!B(u.provenanceRefs)||n.rounds.some(l=>l.result?.id===u.id))&&a("observation needs current experiment, unique result and provenance","set experiment to the active experiment ID and result to {id, valid, summary, provenanceRefs} with a new result.id"),s.items[r.item]?.status!=="done"&&a("complete experiment execution before recording observations","dispatch and complete the active experiment item before calling observe"),N(s,r.item).some(l=>u.provenanceRefs.includes(l))||a("observation must link fresh experiment-output evidence from the latest completion",`include an experiment-output ref produced by the latest successful completion of item "${r.item}" in result.provenanceRefs`),b(s,{...n,phase:"update-belief",rounds:n.rounds.map(l=>l===r?{...l,result:{id:u.id,valid:u.valid,summary:u.summary,provenanceRefs:[...u.provenanceRefs]}}:l),contributors:[...new Set([...n.contributors,t.by,...v(s,r.item)])]},t,"observe")}),"update-belief":p("update-belief","define-acceptance","update-belief",(s,n,t,a)=>{let r=O(n),u=t.assessments,o=E(u,["hypothesis","assessment","reason"]);o&&a(`unknown key "${o}" in an assessments entry`,"use only hypothesis, assessment and reason in each assessments entry"),(t.result!==r.result?.id||!Array.isArray(u)||u.length!==n.hypotheses.length||n.hypotheses.some(c=>u.filter(f=>f?.hypothesis===c.id&&["supported","refuted","uncertain"].includes(f.assessment)&&y(f.reason)).length!==1)||!["round","conclusion"].includes(t.next))&&a("belief update must assess every hypothesis against current result","set result to the latest result ID, assessments to one {hypothesis, assessment, reason} per hypothesis, and next to round or conclusion"),!(r.result??I(`round ${r.experiment.id} has no result`)).valid&&u.some(c=>c.assessment!=="uncertain")&&a("invalid experiments cannot support beliefs","set every assessment to uncertain for an invalid experiment result");let g=b(s,{...n,phase:t.next==="round"?"preregister":"conclusion",rounds:n.rounds.map(c=>c===r?{...c,update:{result:t.result,assessments:u.map(f=>({hypothesis:f.hypothesis,assessment:f.assessment,reason:f.reason}))}}:c),contributors:[...new Set([...n.contributors,t.by])]},t,"belief-updated"),w=S(g);return t.next==="round"&&(n.rounds.length>=R(s.config).maxRounds||chunkTBLIZIWH_cjs.M(w.budget,w.spent))&&(g=C(g,m(g),t,"stopped","budget or round limit exhausted")),g}),conclude:p("conclude","define-acceptance","conclusion",(s,n,t,a)=>{let r=t;return (!["resolved","inconclusive"].includes(r.outcome)||!y(r.summary)||!B(r.evidenceRefs)||r.evidenceRefs.some(u=>!n.rounds.some(o=>o.result?.provenanceRefs.includes(u))))&&a("conclusion needs observed evidence references","set outcome, summary and evidenceRefs to references preserved in recorded observations"),r.outcome==="resolved"&&(!y(r.supportedHypothesis)||!n.rounds.slice(-1).some(u=>u.result?.valid&&u.update?.assessments.some(o=>o.hypothesis===r.supportedHypothesis&&o.assessment==="supported")))&&a("resolved conclusion needs a supported hypothesis","set supportedHypothesis to a hypothesis supported by the latest valid round, or choose outcome inconclusive"),b(s,{...n,phase:"review",conclusion:{outcome:r.outcome,summary:r.summary,evidenceRefs:[...r.evidenceRefs],...r.supportedHypothesis?{supportedHypothesis:r.supportedHypothesis}:{},by:t.by},contributors:[...new Set([...n.contributors,t.by])]},t,"conclusion")}),"review-conclusion":p("review-conclusion","review","review",(s,n,t,a)=>{let r=n.conclusion??I("phase review has no conclusion");if(chunk6PFJYRM7_cjs.a(t.by,n.contributors).length&&a("conclusion reviewer must be independent of investigation contributors","use a review-capable role that did not contribute to or execute this investigation"),(typeof t.approve!="boolean"||!y(t.reason))&&a("review needs approval and reason","set approve to a boolean and reason to a nonempty review explanation"),!t.approve){let o=t.next??"conclusion";o!=="round"&&o!=="conclusion"&&a("review rejection next must be round or conclusion","set next to round for more evidence or conclusion for a revised conclusion");let l=b(s,{...n,phase:o==="round"?"preregister":"conclusion",reviewHistory:[...n.reviewHistory??[],{by:t.by,reason:t.reason,approve:false,next:o,replayRefs:[]}]},t,"review-rejected"),g=S(s);return o==="round"&&(n.rounds.length>=R(s.config).maxRounds||chunkTBLIZIWH_cjs.M(g.budget,g.spent))?C(l,m(l),t,"stopped","budget or round limit exhausted after review requested another round"):l}let u=Array.isArray(t.replayRefs)?t.replayRefs:[];return r.outcome==="resolved"&&(!B(u)||!n.rounds.some(o=>o.experiment.replayOf&&!chunk6PFJYRM7_cjs.a(v(s,o.item),v(s,(n.rounds.find(l=>l.experiment.id===o.experiment.replayOf)??I(`round ${o.experiment.id} replays the unknown experiment ${o.experiment.replayOf}`)).item)).length&&F(o.hypotheses.find(l=>l.id===r.supportedHypothesis),O(n).hypotheses.find(l=>l.id===r.supportedHypothesis))&&o.result?.valid&&u.includes(o.result.id)&&o.update?.assessments.some(l=>l.hypothesis===r.supportedHypothesis&&l.assessment==="supported")))&&a("resolved conclusion requires valid replay result and supporting belief update","set replayRefs to a valid independent replay result supporting the latest supported hypothesis definition, or reject with next round"),C(s,{...n,review:{by:t.by,reason:t.reason,replayRefs:u},reviewHistory:[...n.reviewHistory??[],{by:t.by,reason:t.reason,approve:true,replayRefs:u}]},t,r.outcome)}),stop:p("stop","facilitate",void 0,(s,n,t,a)=>(y(t.reason)||a("stop needs reason","set reason to a nonempty explanation for stopping this investigation"),C(s,n,t,"stopped",t.reason)))}}function V(){return [{id:"independent-replay",severity:"error",check(e,i){if(i.type!=="item.complete")return [];let d=m(e)?.rounds.find(s=>s.item===i.payload?.item),p=m(e)?.rounds.find(s=>s.experiment.id===d?.experiment.replayOf);return p&&chunk6PFJYRM7_cjs.a(i.by,v(e,p.item)).length?[{rule:"independent-replay",item:d.item,severity:"error",message:"Replay executor also executed the original experiment",fix:"assign a different deliver-capable role"}]:[]}},{id:"investigation-execution-only",severity:"error",check(e,i){if(i.type!=="item.complete")return [];let d=i.payload,p=m(e);return p?.phase==="observe"&&p.rounds.at(-1)?.item===d.item?[]:[{rule:"investigation-execution-only",item:d.item,severity:"error",message:"Only the active preregistered experiment can complete",fix:`complete only the active experiment item in phase observe; current phase is ${p?.phase??"intake"}`}]}}]}function G(){return [{id:"replay-worker",name:"Independent replay worker",modelTier:"small",capabilities:["deliver","verify"],canApprove:[],inputs:["preregistered-experiment"],outputs:["experiment-output"],do_not:["Do not change the replay procedure"]},{id:"investigator",name:"Investigator",modelTier:"large",capabilities:["facilitate","define-acceptance","deliver","verify"],canApprove:[],inputs:["question","prior-results"],outputs:["hypotheses","preregistered-experiment","belief-update"],do_not:["Do not revise predictions after execution","Do not approve your own conclusions"]},{id:"conclusion-reviewer",name:"Independent conclusion reviewer",modelTier:"large",capabilities:["review"],canApprove:["investigation-conclusion"],inputs:["evidence","replay","conclusion"],outputs:["conclusion-review"],do_not:["Do not approve unsupported conclusions"]}]}function J(){return [{id:"intake",name:"Intake",entryPolicy:[],exitPolicy:[{kind:"acceptance-written"}]},{id:"execute",name:"Execute preregistered experiment",entryPolicy:[{kind:"acceptance-written"},{kind:"no-open-blockers"}],exitPolicy:[{kind:"evidence",evidenceKind:"experiment-output"}]},{id:"observed",name:"Execution recorded",entryPolicy:[],exitPolicy:[]}]}function L(){return {name:"investigation",validateConfig:R,lockedConfigKeys:["question","maxRounds","budget"],vocabulary:{backlog:"Questions",item:"Investigation artifact",stage:"Investigation phase",iteration:"Investigation budget",increment:"Conclusion",ceremony:"Investigation ceremony",gate:"Independent conclusion review"},defaultStages:J,defaultRoles:G,requiredCapabilities:["facilitate","define-acceptance","deliver","verify","review"],exclusiveCapabilities:[],humanDefaults:{gates:"none"},ceremonies:U(L),plannerOptions:e=>({schedulerMode:"level",concurrencyCap:1,roleFor:i=>{let d=m(e)?.rounds.find(a=>a.item===i.id),p=m(e)?.rounds.find(a=>a.experiment.id===d?.experiment.replayOf),s=p?v(e,p.item):[],n=Object.values(e.roles),t=(p?void 0:n.find(a=>a.capabilities.includes("deliver")&&a.capabilities.includes("define-acceptance")))??n.find(a=>a.capabilities.includes("deliver")&&!chunk6PFJYRM7_cjs.a(a.id,s).length);return t||chunkOSHBJIYD_cjs.b("missing-capability",`No eligible executor for experiment item "${i.id}"`,p?`register an independent deliver-capable role that did not execute "${p.item}"`:"register a role with deliver capability",{items:[i.id]}),t.id},estimateMode:"per-call",fallbackTokensPerWeight:1}),candidates:e=>{let i=m(e),d=i?.rounds.at(-1)?.item;return i?.phase==="observe"&&!chunkTBLIZIWH_cjs.M(e.config.budget,S(e).spent)?Object.values(e.items).filter(p=>p.id===d&&p.stage==="execute"&&p.status==="todo"):[]},afterComplete:(e,i,d)=>{let p=m(e),s=e.iterations.find(n=>n.id==="investigation");return p?.phase!=="observe"||p.rounds.at(-1)?.item!==i||e.items[i]?.status==="done"||!s||!chunkTBLIZIWH_cjs.M(s.budget,s.spent)?e:C(e,p,{by:"investigation",now:d},"stopped",`budget exhausted before experiment item "${i}" completed; start a new investigation with sufficient budget`)},invariants:e=>[`Question: ${e.config.question}`,"Execute only the preregistered procedure; retain raw observation provenance; report invalid runs."],rules:V(),metrics:e=>({rounds:m(e)?.rounds.length??0,validRuns:m(e)?.rounds.filter(i=>i.result?.valid).length??0,invalidRuns:m(e)?.rounds.filter(i=>i.result&&!i.result.valid).length??0}),report:e=>({phase:m(e)?.phase??"intake",outcome:m(e)?.outcome??null,rounds:m(e)?.rounds.length??0,conclusion:m(e)?.conclusion??null,stopReason:m(e)?.stopReason??null})}}exports.a=R;exports.b=L;//# sourceMappingURL=chunk-76ITDJDM.cjs.map
2
+ //# sourceMappingURL=chunk-76ITDJDM.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/methodologies/investigation/record.ts","../src/methodologies/investigation/execution.ts","../src/methodologies/investigation/invariants.ts","../src/methodologies/investigation/config.ts","../src/methodologies/investigation/ceremonies.ts","../src/methodologies/investigation/rules.ts","../src/methodologies/investigation/roles.ts","../src/methodologies/investigation/stages.ts","../src/methodologies/investigation/index.ts"],"names":["readInvestigation","s","readExt","writeInvestigation","x","writeExt","executionActors","state","item","event","transition","freshOutputRefs","completion","index","output","brokenInvestigation","what","fail","lastRound","investigationIteration","it","validateInvestigationConfig","raw","c","k","v","reject","name","message","fix","sameHypothesis","a","b","frozenChanges","text","refs","extraKey","keys","extraKeyIn","list","authorize","by","cap","roleOf","save","i","appendEvent","nowOf","closeInvestigation","outcome","reason","at","n","candidate","r","moveItem","investigationCeremonies","factory","built","methodology","make","phase","fn","applyAction","bad","addItem","h","extra","isExhausted","e","extraExperiment","p","prior","id","iteration","o","ref","entry","conclusion","independenceConflicts","target","replayRefs","investigationRules","round","investigationRoles","investigationStages","investigation","excluded","roles","selected","role","now"],"mappings":"yNAKO,IAAMA,EAAqBC,CAAAA,EAChCC,mBAAAA,CAAQD,EAAG,eAAe,CAAA,CAGfE,EAAqB,CAACF,C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EAAc,IAClD,EACF,CACF","file":"chunk-QAENYYU6.cjs","sourcesContent":["import { readExt, writeExt } from \"../../interface/ext.ts\";\nimport type { WorkflowState } from \"../../core/types.ts\";\nimport type { InvestigationState } from \"./state.ts\";\n\n/** The investigation record: `ext.investigation`, or the legacy field of a state written before 1.2. */\nexport const readInvestigation = (s: WorkflowState): InvestigationState | undefined =>\n readExt(s, \"investigation\");\n\n/** Stores the investigation record in `ext.investigation` and its deprecated legacy mirror (spec 26). */\nexport const writeInvestigation = (s: WorkflowState, x: InvestigationState): WorkflowState =>\n writeExt(s, \"investigation\", x);\n","import type { Handoff, Verdict, WorkflowState } from \"../../core/types.ts\";\n\ninterface Completion {\n id: string;\n verdict: Verdict;\n produced: Handoff[\"produced\"];\n}\n\n/** Completion actors come from validated handoffs, never caller-supplied accounting identity. */\nexport function executionActors(state: WorkflowState, item: string): string[] {\n return [\n ...new Set([\n ...state.events\n .filter(\n (event) => event.type === \"item.completed\" && (event.payload as Completion).id === item,\n )\n .map((event) => event.by),\n ...(state.items[item]?.transitions ?? [])\n .filter((transition) => transition.to.status === \"in_progress\")\n .map((transition) => transition.by),\n ]),\n ];\n}\n\n/** Only outputs of the latest successful completion can establish observation provenance. */\nexport function freshOutputRefs(state: WorkflowState, item: string): string[] {\n let completion: Completion | undefined;\n for (let index = state.events.length - 1; index >= 0; index--) {\n const event = state.events[index]!;\n if (event.type === \"item.completed\" && (event.payload as Completion).id === item) {\n completion = event.payload as Completion;\n break;\n }\n }\n return completion && [\"done\", \"needs-review\"].includes(completion.verdict)\n ? completion.produced\n .filter((output) => output.kind === \"experiment-output\")\n .map((output) => output.ref)\n : [];\n}\n","import { fail } from \"../../core/errors.ts\";\nimport type { Iteration, WorkflowState } from \"../../core/types.ts\";\nimport type { InvestigationState } from \"./state.ts\";\n\n/** A loaded state that breaks an invariant the ceremonies keep (a hand-edited or damaged file). */\nexport function brokenInvestigation(what: string): never {\n return fail(\n \"invalid-input\",\n `the investigation state is inconsistent: ${what}`,\n \"restore .workflow/state.json from git, or start a new investigation\",\n );\n}\n\n/** The latest round; the phases after preregister always have one. */\nexport function lastRound(x: InvestigationState): InvestigationState[\"rounds\"][number] {\n return x.rounds.at(-1) ?? brokenInvestigation(`phase ${x.phase} has no round`);\n}\n\n/** The `investigation` iteration intake opens; its budget bounds every round. */\nexport function investigationIteration(s: WorkflowState<string>): Iteration {\n return (\n s.iterations.find((it) => it.id === \"investigation\") ??\n brokenInvestigation('there is no \"investigation\" iteration')\n );\n}\n","import { fail } from \"../../core/errors.ts\";\nimport type { Budget } from \"../../core/types.ts\";\nexport interface InvestigationConfig {\n question: string;\n maxRounds: number;\n budget: Budget;\n}\nexport function validateInvestigationConfig(raw: unknown): InvestigationConfig {\n const c = raw as InvestigationConfig;\n if (\n !c ||\n typeof c !== \"object\" ||\n Array.isArray(c) ||\n typeof c.question !== \"string\" ||\n !c.question.trim() ||\n !Number.isSafeInteger(c.maxRounds) ||\n c.maxRounds < 1 ||\n !c.budget ||\n typeof c.budget !== \"object\" ||\n Array.isArray(c.budget) ||\n !Object.keys(c.budget).length ||\n Object.entries(c.budget).some(\n ([k, v]) =>\n ![\"tokens\", \"turns\", \"wallclockMs\"].includes(k) ||\n typeof v !== \"number\" ||\n !Number.isFinite(v) ||\n v <= 0,\n )\n )\n fail(\n \"config-invalid\",\n \"investigation requires question, positive maxRounds and a finite positive budget\",\n \"provide bounded investigation config\",\n );\n return { question: c.question, maxRounds: c.maxRounds, budget: { ...c.budget } };\n}\n","import { readInvestigation, writeInvestigation } from \"./record.ts\";\nimport { executionActors, freshOutputRefs } from \"./execution.ts\";\nimport { independenceConflicts } from \"../../common/independence.ts\";\nimport { frozenChanges } from \"../../common/frozen.ts\";\nimport { fail } from \"../../core/errors.ts\";\nimport { brokenInvestigation, investigationIteration, lastRound } from \"./invariants.ts\";\nimport { roleOf } from \"../../core/roles/lookup.ts\";\nimport { addItem } from \"../../core/items/record.ts\";\nimport { moveItem } from \"../../core/items/move.ts\";\nimport { applyAction } from \"../../core/methodology.ts\";\nimport { appendEvent, nowOf } from \"../../core/state.ts\";\nimport { isExhausted } from \"../../core/budget.ts\";\nimport type {\n Capability,\n Ceremony,\n CeremonyInput,\n Methodology,\n WorkflowState,\n} from \"../../core/types.ts\";\nimport { validateInvestigationConfig, type InvestigationConfig } from \"./config.ts\";\nimport type {\n BeliefUpdate,\n Experiment,\n Hypothesis,\n InvestigationConclusion,\n InvestigationState,\n Observation,\n} from \"./state.ts\";\nfunction reject(s: WorkflowState, name: string, message: string, fix: string): never {\n const x = readInvestigation(s);\n return fail(\"invalid-input\", `${name} (phase ${x?.phase ?? \"intake\"}): ${message}`, fix, {\n items: x ? [x.item, ...(x.rounds.at(-1) ? [x.rounds.at(-1)!.item] : [])] : [],\n });\n}\nconst sameHypothesis = (a: Hypothesis | undefined, b: Hypothesis | undefined) =>\n !!a && !!b && !frozenChanges(a, b, [\"id\", \"claim\", \"falsifiedBy\"]).length;\nconst text = (v: unknown): v is string => typeof v === \"string\" && v.trim().length > 0;\nconst refs = (v: unknown): v is string[] =>\n Array.isArray(v) && v.length > 0 && v.every(text) && new Set(v).size === v.length;\n/** First key of a caller record outside its contract; stored records are closed objects (state schema). */\nconst extraKey = (v: unknown, keys: readonly string[]): string | undefined =>\n v && typeof v === \"object\" && !Array.isArray(v)\n ? Object.keys(v).find((k) => !keys.includes(k))\n : undefined;\nconst extraKeyIn = (list: unknown, keys: readonly string[]): string | undefined =>\n Array.isArray(list) ? list.map((v) => extraKey(v, keys)).find(Boolean) : undefined;\nfunction authorize(s: WorkflowState, by: string, cap: Capability) {\n if (!roleOf(s, by)?.capabilities.includes(cap))\n fail(\n \"missing-capability\",\n `${by} needs ${cap}`,\n \"use a registered role with the required capability\",\n );\n}\nfunction save(s: WorkflowState, x: InvestigationState, i: CeremonyInput, name: string) {\n return appendEvent(\n writeInvestigation(s, x),\n `investigation.${name}`,\n i.by,\n { ...x },\n nowOf(i.now),\n );\n}\nexport function closeInvestigation(\n s: WorkflowState,\n x: InvestigationState,\n i: CeremonyInput,\n outcome: \"stopped\" | \"resolved\" | \"inconclusive\",\n reason?: string,\n) {\n const at = nowOf(i.now);\n let n = save(\n s,\n { ...x, phase: \"closed\", outcome, ...(reason ? { stopReason: reason } : {}) },\n i,\n outcome,\n );\n n = {\n ...n,\n iterations: n.iterations.map((it) =>\n it.id === \"investigation\"\n ? { ...it, endedAt: at, outcome: outcome === \"stopped\" ? \"cancelled\" : \"completed\" }\n : it,\n ),\n };\n for (const item of Object.values(n.items).filter(\n (candidate) => candidate.id === x.item || x.rounds.some((r) => r.item === candidate.id),\n ))\n if (item.status !== \"done\" && item.status !== \"dropped\")\n n = moveItem(\n n,\n item.id,\n { status: outcome === \"resolved\" && item.id === x.item ? \"done\" : \"dropped\" },\n i.by,\n at,\n );\n return n;\n}\nexport function investigationCeremonies(\n factory: () => Methodology<InvestigationConfig>,\n): Record<string, Ceremony> {\n let built: Methodology<InvestigationConfig> | undefined;\n const methodology = () => (built ??= factory());\n const make =\n (\n name: string,\n cap: Capability,\n phase: string | undefined,\n fn: (\n s: WorkflowState,\n x: InvestigationState,\n i: CeremonyInput,\n bad: (message: string, fix: string) => never,\n ) => WorkflowState,\n ): Ceremony =>\n (s, i) => {\n authorize(s, i.by, cap);\n const x = readInvestigation(s);\n if (!x || x.phase === \"closed\")\n reject(s, name, \"no active investigation\", \"start a new investigation with intake {item}\");\n if (phase && x.phase !== phase && !(name === \"hypotheses\" && x.phase === \"preregister\"))\n reject(\n s,\n name,\n `expected ${phase}, got ${x.phase}`,\n `finish phase ${x.phase} before calling ${name}; ${name} requires phase ${phase}`,\n );\n return applyAction(s, methodology(), { type: `ceremony.${name}`, by: i.by, payload: i }, () =>\n fn(s, x, i, (message, fix) => reject(s, name, message, fix)),\n );\n };\n return {\n intake(s, i) {\n authorize(s, i.by, \"facilitate\");\n const bad = (message: string, fix: string) => reject(s, \"intake\", message, fix);\n if (s.methodology !== \"investigation\")\n bad(\n `workflow methodology is ${s.methodology}, not investigation`,\n \"init a workflow with the investigation methodology before intake\",\n );\n if (readInvestigation(s))\n bad(\n \"investigation already started\",\n \"use the existing investigation or initialize a new workflow\",\n );\n if (!text(i.item))\n bad(\"item is required\", \"set intake.item to a unique investigation item ID\");\n const c = validateInvestigationConfig(s.config);\n return applyAction(\n s,\n methodology(),\n { type: \"ceremony.intake\", by: i.by, payload: i },\n () => {\n let n = addItem(\n s,\n {\n id: i.item as string,\n title: c.question,\n acceptance: [\"Independent evidence-based conclusion\"],\n stage: \"intake\",\n },\n i.by,\n i.now,\n );\n n = {\n ...n,\n iterations: [\n ...n.iterations,\n {\n id: \"investigation\",\n goal: c.question,\n budget: { ...c.budget },\n spent: { tokens: 0, turns: 0, wallclockMs: 0 },\n startedAt: nowOf(i.now),\n committed: [],\n carryover: [],\n },\n ],\n };\n return save(\n n,\n {\n item: i.item as string,\n phase: \"hypotheses\",\n hypotheses: [],\n rounds: [],\n contributors: [i.by],\n },\n i,\n \"intake\",\n );\n },\n );\n },\n hypotheses: make(\"hypotheses\", \"define-acceptance\", \"hypotheses\", (s, x, i, bad) => {\n const h = i.hypotheses as Hypothesis[];\n const extra = extraKeyIn(h, [\"id\", \"claim\", \"falsifiedBy\"]);\n if (extra)\n bad(\n `unknown key \"${extra}\" in a hypotheses entry`,\n \"use only id, claim and falsifiedBy in each hypotheses entry\",\n );\n if (\n !Array.isArray(h) ||\n !h.length ||\n h.some((v) => !v || !text(v.id) || !text(v.claim) || !text(v.falsifiedBy)) ||\n new Set(h.map((v) => v.id)).size !== h.length ||\n (h.length < 2 && !text(i.singleHypothesisRationale))\n )\n bad(\n \"provide competing falsifiable hypotheses or single-testable rationale\",\n \"set hypotheses to unique {id, claim, falsifiedBy} entries; supply singleHypothesisRationale when there is only one\",\n );\n return save(\n s,\n {\n ...x,\n hypotheses: h.map((v) => ({ id: v.id, claim: v.claim, falsifiedBy: v.falsifiedBy })),\n ...(text(i.singleHypothesisRationale)\n ? { singleHypothesisRationale: i.singleHypothesisRationale }\n : {}),\n contributors: [...new Set([...x.contributors, i.by])],\n phase: \"preregister\",\n },\n i,\n \"hypotheses\",\n );\n }),\n preregister: make(\"preregister\", \"define-acceptance\", \"preregister\", (s, x, i, bad) => {\n const c = validateInvestigationConfig(s.config),\n it = s.iterations.find((v) => v.id === \"investigation\");\n if (x.rounds.length >= c.maxRounds || !it || isExhausted(c.budget, it.spent))\n bad(\n `round limit or budget exhausted (${x.rounds.length} of ${c.maxRounds} rounds used)`,\n \"call stop {reason} to close this investigation, or start a new one with a larger maxRounds or budget\",\n );\n const e = i.experiment as Experiment;\n const extraExperiment =\n extraKey(e, [\"id\", \"procedureRef\", \"predictions\", \"replayOf\"]) ??\n extraKeyIn(e?.predictions, [\"hypothesis\", \"prediction\"]);\n if (extraExperiment)\n bad(\n `unknown key \"${extraExperiment}\" in experiment`,\n \"use only id, procedureRef, predictions [{hypothesis, prediction}] and replayOf in experiment\",\n );\n if (\n !e ||\n !text(e.id) ||\n !text(e.procedureRef) ||\n x.rounds.some((r) => r.experiment.id === e.id) ||\n !Array.isArray(e.predictions) ||\n e.predictions.length !== x.hypotheses.length ||\n x.hypotheses.some(\n (h) =>\n e.predictions.filter((p) => p?.hypothesis === h.id && text(p.prediction)).length !== 1,\n ) ||\n new Set(e.predictions.map((p) => p.prediction)).size !== e.predictions.length\n )\n bad(\n \"preregister unique experiment with differing predictions for every hypothesis\",\n \"set experiment.id to a new ID, experiment.procedureRef, and one distinct experiment.predictions entry per hypothesis\",\n );\n if (e.replayOf) {\n const prior = x.rounds.find((r) => r.experiment.id === e.replayOf && r.result?.valid);\n if (\n !prior ||\n frozenChanges(prior.experiment, e, [\"procedureRef\"]).length ||\n prior.hypotheses.length !== x.hypotheses.length ||\n x.hypotheses.some(\n (h) =>\n !sameHypothesis(\n h,\n prior.hypotheses.find((p) => p.id === h.id),\n ),\n ) ||\n e.predictions.some(\n (p) =>\n !prior.experiment.predictions.some(\n (q) => !frozenChanges(q, p, [\"hypothesis\", \"prediction\"]).length,\n ),\n )\n )\n bad(\n \"replay must repeat the procedure, predictions and hypotheses of a prior valid experiment\",\n \"set experiment.replayOf to a valid prior experiment with identical procedureRef, predictions and hypothesis definitions\",\n );\n }\n const id = `${x.item}-run-${x.rounds.length + 1}`;\n let n = addItem(\n s,\n {\n id,\n title: `Experiment ${e.id}`,\n stage: \"execute\",\n acceptance: [e.procedureRef],\n iteration: \"investigation\",\n },\n i.by,\n i.now,\n );\n n = {\n ...n,\n iterations: n.iterations.map((iteration) =>\n iteration.id === \"investigation\"\n ? { ...iteration, committed: [...iteration.committed, id] }\n : iteration,\n ),\n };\n return save(\n n,\n {\n ...x,\n phase: \"observe\",\n rounds: [\n ...x.rounds,\n {\n experiment: {\n id: e.id,\n procedureRef: e.procedureRef,\n predictions: e.predictions.map((p) => ({\n hypothesis: p.hypothesis,\n prediction: p.prediction,\n })),\n ...(e.replayOf ? { replayOf: e.replayOf } : {}),\n },\n hypotheses: x.hypotheses.map((v) => ({ ...v })),\n item: id,\n by: i.by,\n },\n ],\n contributors: [...new Set([...x.contributors, i.by])],\n },\n i,\n \"preregister\",\n );\n }),\n observe: make(\"observe\", \"verify\", \"observe\", (s, x, i, bad) => {\n const r = lastRound(x),\n o = i.result as Observation;\n const extra = extraKey(o, [\"id\", \"valid\", \"summary\", \"provenanceRefs\"]);\n if (extra)\n bad(\n `unknown key \"${extra}\" in result`,\n \"use only id, valid, summary and provenanceRefs in result\",\n );\n if (\n i.experiment !== r.experiment.id ||\n !o ||\n !text(o.id) ||\n typeof o.valid !== \"boolean\" ||\n !text(o.summary) ||\n !refs(o.provenanceRefs) ||\n x.rounds.some((prior) => prior.result?.id === o.id)\n )\n bad(\n \"observation needs current experiment, unique result and provenance\",\n \"set experiment to the active experiment ID and result to {id, valid, summary, provenanceRefs} with a new result.id\",\n );\n if (s.items[r.item]?.status !== \"done\")\n bad(\n \"complete experiment execution before recording observations\",\n \"dispatch and complete the active experiment item before calling observe\",\n );\n if (!freshOutputRefs(s, r.item).some((ref) => o.provenanceRefs.includes(ref)))\n bad(\n \"observation must link fresh experiment-output evidence from the latest completion\",\n `include an experiment-output ref produced by the latest successful completion of item \"${r.item}\" in result.provenanceRefs`,\n );\n return save(\n s,\n {\n ...x,\n phase: \"update-belief\",\n rounds: x.rounds.map((v) =>\n v === r\n ? {\n ...v,\n result: {\n id: o.id,\n valid: o.valid,\n summary: o.summary,\n provenanceRefs: [...o.provenanceRefs],\n },\n }\n : v,\n ),\n contributors: [...new Set([...x.contributors, i.by, ...executionActors(s, r.item)])],\n },\n i,\n \"observe\",\n );\n }),\n \"update-belief\": make(\"update-belief\", \"define-acceptance\", \"update-belief\", (s, x, i, bad) => {\n const r = lastRound(x),\n a = i.assessments as BeliefUpdate[\"assessments\"];\n const extra = extraKeyIn(a, [\"hypothesis\", \"assessment\", \"reason\"]);\n if (extra)\n bad(\n `unknown key \"${extra}\" in an assessments entry`,\n \"use only hypothesis, assessment and reason in each assessments entry\",\n );\n if (\n i.result !== r.result?.id ||\n !Array.isArray(a) ||\n a.length !== x.hypotheses.length ||\n x.hypotheses.some(\n (h) =>\n a.filter(\n (v) =>\n v?.hypothesis === h.id &&\n [\"supported\", \"refuted\", \"uncertain\"].includes(v.assessment) &&\n text(v.reason),\n ).length !== 1,\n ) ||\n ![\"round\", \"conclusion\"].includes(i.next as string)\n )\n bad(\n \"belief update must assess every hypothesis against current result\",\n \"set result to the latest result ID, assessments to one {hypothesis, assessment, reason} per hypothesis, and next to round or conclusion\",\n );\n const result = r.result ?? brokenInvestigation(`round ${r.experiment.id} has no result`);\n if (!result.valid && a.some((v) => v.assessment !== \"uncertain\"))\n bad(\n \"invalid experiments cannot support beliefs\",\n \"set every assessment to uncertain for an invalid experiment result\",\n );\n let n = save(\n s,\n {\n ...x,\n phase: i.next === \"round\" ? \"preregister\" : \"conclusion\",\n rounds: x.rounds.map((v) =>\n v === r\n ? {\n ...v,\n update: {\n result: i.result as string,\n assessments: a.map((entry) => ({\n hypothesis: entry.hypothesis,\n assessment: entry.assessment,\n reason: entry.reason,\n })),\n },\n }\n : v,\n ),\n contributors: [...new Set([...x.contributors, i.by])],\n },\n i,\n \"belief-updated\",\n );\n const it = investigationIteration(n);\n if (\n i.next === \"round\" &&\n (x.rounds.length >= validateInvestigationConfig(s.config).maxRounds ||\n isExhausted(it.budget, it.spent))\n )\n n = closeInvestigation(\n n,\n readInvestigation(n)!,\n i,\n \"stopped\",\n \"budget or round limit exhausted\",\n );\n return n;\n }),\n conclude: make(\"conclude\", \"define-acceptance\", \"conclusion\", (s, x, i, bad) => {\n const c = i as unknown as InvestigationConclusion;\n if (\n ![\"resolved\", \"inconclusive\"].includes(c.outcome) ||\n !text(c.summary) ||\n !refs(c.evidenceRefs) ||\n c.evidenceRefs.some((ref) => !x.rounds.some((r) => r.result?.provenanceRefs.includes(ref)))\n )\n bad(\n \"conclusion needs observed evidence references\",\n \"set outcome, summary and evidenceRefs to references preserved in recorded observations\",\n );\n if (\n c.outcome === \"resolved\" &&\n (!text(c.supportedHypothesis) ||\n !x.rounds\n .slice(-1)\n .some(\n (r) =>\n r.result?.valid &&\n r.update?.assessments.some(\n (a) => a.hypothesis === c.supportedHypothesis && a.assessment === \"supported\",\n ),\n ))\n )\n bad(\n \"resolved conclusion needs a supported hypothesis\",\n \"set supportedHypothesis to a hypothesis supported by the latest valid round, or choose outcome inconclusive\",\n );\n return save(\n s,\n {\n ...x,\n phase: \"review\",\n conclusion: {\n outcome: c.outcome,\n summary: c.summary,\n evidenceRefs: [...c.evidenceRefs],\n ...(c.supportedHypothesis ? { supportedHypothesis: c.supportedHypothesis } : {}),\n by: i.by,\n },\n contributors: [...new Set([...x.contributors, i.by])],\n },\n i,\n \"conclusion\",\n );\n }),\n \"review-conclusion\": make(\"review-conclusion\", \"review\", \"review\", (s, x, i, bad) => {\n const conclusion = x.conclusion ?? brokenInvestigation(\"phase review has no conclusion\");\n if (independenceConflicts(i.by, x.contributors).length)\n bad(\n \"conclusion reviewer must be independent of investigation contributors\",\n \"use a review-capable role that did not contribute to or execute this investigation\",\n );\n if (typeof i.approve !== \"boolean\" || !text(i.reason))\n bad(\n \"review needs approval and reason\",\n \"set approve to a boolean and reason to a nonempty review explanation\",\n );\n if (!i.approve) {\n const target = i.next ?? \"conclusion\";\n if (target !== \"round\" && target !== \"conclusion\")\n bad(\n \"review rejection next must be round or conclusion\",\n \"set next to round for more evidence or conclusion for a revised conclusion\",\n );\n const n = save(\n s,\n {\n ...x,\n phase: target === \"round\" ? \"preregister\" : \"conclusion\",\n reviewHistory: [\n ...(x.reviewHistory ?? []),\n {\n by: i.by,\n reason: i.reason as string,\n approve: false,\n next: target as \"round\" | \"conclusion\",\n replayRefs: [],\n },\n ],\n },\n i,\n \"review-rejected\",\n );\n const iteration = investigationIteration(s);\n if (\n target === \"round\" &&\n (x.rounds.length >= validateInvestigationConfig(s.config).maxRounds ||\n isExhausted(iteration.budget, iteration.spent))\n )\n return closeInvestigation(\n n,\n readInvestigation(n)!,\n i,\n \"stopped\",\n \"budget or round limit exhausted after review requested another round\",\n );\n return n;\n }\n const replayRefs = Array.isArray(i.replayRefs) ? i.replayRefs : [];\n if (\n conclusion.outcome === \"resolved\" &&\n (!refs(replayRefs) ||\n !x.rounds.some(\n (r) =>\n r.experiment.replayOf &&\n !independenceConflicts(\n executionActors(s, r.item),\n executionActors(\n s,\n (\n x.rounds.find((p) => p.experiment.id === r.experiment.replayOf) ??\n brokenInvestigation(\n `round ${r.experiment.id} replays the unknown experiment ${r.experiment.replayOf}`,\n )\n ).item,\n ),\n ).length &&\n sameHypothesis(\n r.hypotheses.find((h) => h.id === conclusion.supportedHypothesis),\n lastRound(x).hypotheses.find((h) => h.id === conclusion.supportedHypothesis),\n ) &&\n r.result?.valid &&\n replayRefs.includes(r.result.id) &&\n r.update?.assessments.some(\n (a) =>\n a.hypothesis === conclusion.supportedHypothesis && a.assessment === \"supported\",\n ),\n ))\n )\n bad(\n \"resolved conclusion requires valid replay result and supporting belief update\",\n \"set replayRefs to a valid independent replay result supporting the latest supported hypothesis definition, or reject with next round\",\n );\n return closeInvestigation(\n s,\n {\n ...x,\n review: { by: i.by, reason: i.reason as string, replayRefs: replayRefs as string[] },\n reviewHistory: [\n ...(x.reviewHistory ?? []),\n {\n by: i.by,\n reason: i.reason as string,\n approve: true,\n replayRefs: replayRefs as string[],\n },\n ],\n },\n i,\n conclusion.outcome,\n );\n }),\n stop: make(\"stop\", \"facilitate\", undefined, (s, x, i, bad) => {\n if (!text(i.reason))\n bad(\n \"stop needs reason\",\n \"set reason to a nonempty explanation for stopping this investigation\",\n );\n return closeInvestigation(s, x, i, \"stopped\", i.reason as string);\n }),\n };\n}\n","import { readInvestigation } from \"./record.ts\";\nimport { executionActors } from \"./execution.ts\";\nimport { independenceConflicts } from \"../../common/independence.ts\";\nimport type { Rule } from \"../../core/types.ts\";\nexport function investigationRules(): Rule[] {\n return [\n {\n id: \"independent-replay\",\n severity: \"error\",\n check(s, a) {\n if (a.type !== \"item.complete\") return [];\n const round = readInvestigation(s)?.rounds.find(\n (r) => r.item === (a.payload as { item?: string })?.item,\n );\n const prior = readInvestigation(s)?.rounds.find(\n (r) => r.experiment.id === round?.experiment.replayOf,\n );\n return prior && independenceConflicts(a.by, executionActors(s, prior.item)).length\n ? [\n {\n rule: \"independent-replay\",\n item: round!.item,\n severity: \"error\",\n message: \"Replay executor also executed the original experiment\",\n fix: \"assign a different deliver-capable role\",\n },\n ]\n : [];\n },\n },\n {\n id: \"investigation-execution-only\",\n severity: \"error\",\n check(s, a) {\n if (a.type !== \"item.complete\") return [];\n const p = a.payload as { item: string };\n const x = readInvestigation(s);\n return x?.phase === \"observe\" && x.rounds.at(-1)?.item === p.item\n ? []\n : [\n {\n rule: \"investigation-execution-only\",\n item: p.item,\n severity: \"error\",\n message: \"Only the active preregistered experiment can complete\",\n fix: `complete only the active experiment item in phase observe; current phase is ${x?.phase ?? \"intake\"}`,\n },\n ];\n },\n },\n ];\n}\n","import type { Role } from \"../../core/types.ts\";\nexport function investigationRoles(): Role[] {\n return [\n {\n id: \"replay-worker\",\n name: \"Independent replay worker\",\n modelTier: \"small\",\n capabilities: [\"deliver\", \"verify\"],\n canApprove: [],\n inputs: [\"preregistered-experiment\"],\n outputs: [\"experiment-output\"],\n do_not: [\"Do not change the replay procedure\"],\n },\n {\n id: \"investigator\",\n name: \"Investigator\",\n modelTier: \"large\",\n capabilities: [\"facilitate\", \"define-acceptance\", \"deliver\", \"verify\"],\n canApprove: [],\n inputs: [\"question\", \"prior-results\"],\n outputs: [\"hypotheses\", \"preregistered-experiment\", \"belief-update\"],\n do_not: [\"Do not revise predictions after execution\", \"Do not approve your own conclusions\"],\n },\n {\n id: \"conclusion-reviewer\",\n name: \"Independent conclusion reviewer\",\n modelTier: \"large\",\n capabilities: [\"review\"],\n canApprove: [\"investigation-conclusion\"],\n inputs: [\"evidence\", \"replay\", \"conclusion\"],\n outputs: [\"conclusion-review\"],\n do_not: [\"Do not approve unsupported conclusions\"],\n },\n ];\n}\n","import type { Stage } from \"../../core/types.ts\";\nexport function investigationStages(): Stage[] {\n return [\n {\n id: \"intake\",\n name: \"Intake\",\n entryPolicy: [],\n exitPolicy: [{ kind: \"acceptance-written\" }],\n },\n {\n id: \"execute\",\n name: \"Execute preregistered experiment\",\n entryPolicy: [{ kind: \"acceptance-written\" }, { kind: \"no-open-blockers\" }],\n exitPolicy: [{ kind: \"evidence\", evidenceKind: \"experiment-output\" }],\n },\n { id: \"observed\", name: \"Execution recorded\", entryPolicy: [], exitPolicy: [] },\n ];\n}\n","import { readInvestigation } from \"./record.ts\";\nimport { fail } from \"../../core/errors.ts\";\nimport { executionActors } from \"./execution.ts\";\nimport { independenceConflicts } from \"../../common/independence.ts\";\nimport { closeInvestigation, investigationCeremonies } from \"./ceremonies.ts\";\nimport { investigationIteration } from \"./invariants.ts\";\nimport { investigationRules } from \"./rules.ts\";\nimport { investigationRoles } from \"./roles.ts\";\nimport { investigationStages } from \"./stages.ts\";\nimport { isExhausted } from \"../../core/budget.ts\";\nimport type { Methodology } from \"../../core/types.ts\";\nimport { validateInvestigationConfig, type InvestigationConfig } from \"./config.ts\";\nexport { validateInvestigationConfig };\nexport type { InvestigationConfig };\nexport type * from \"./state.ts\";\nexport function investigation(): Methodology<InvestigationConfig> {\n return {\n name: \"investigation\",\n validateConfig: validateInvestigationConfig,\n lockedConfigKeys: [\"question\", \"maxRounds\", \"budget\"],\n vocabulary: {\n backlog: \"Questions\",\n item: \"Investigation artifact\",\n stage: \"Investigation phase\",\n iteration: \"Investigation budget\",\n increment: \"Conclusion\",\n ceremony: \"Investigation ceremony\",\n gate: \"Independent conclusion review\",\n },\n defaultStages: investigationStages,\n defaultRoles: investigationRoles,\n requiredCapabilities: [\"facilitate\", \"define-acceptance\", \"deliver\", \"verify\", \"review\"],\n exclusiveCapabilities: [],\n humanDefaults: { gates: \"none\" },\n ceremonies: investigationCeremonies(investigation),\n plannerOptions: (state) => ({\n schedulerMode: \"level\",\n concurrencyCap: 1,\n roleFor: (item) => {\n const r = readInvestigation(state)?.rounds.find((candidate) => candidate.item === item.id);\n const prior = readInvestigation(state)?.rounds.find(\n (p) => p.experiment.id === r?.experiment.replayOf,\n );\n const excluded = prior ? executionActors(state, prior.item) : [];\n const roles = Object.values(state.roles);\n const selected =\n (!prior\n ? roles.find(\n (role) =>\n role.capabilities.includes(\"deliver\") &&\n role.capabilities.includes(\"define-acceptance\"),\n )\n : undefined) ??\n roles.find(\n (role) =>\n role.capabilities.includes(\"deliver\") &&\n !independenceConflicts(role.id, excluded).length,\n );\n if (!selected)\n fail(\n \"missing-capability\",\n `No eligible executor for experiment item \"${item.id}\"`,\n prior\n ? `register an independent deliver-capable role that did not execute \"${prior.item}\"`\n : \"register a role with deliver capability\",\n { items: [item.id] },\n );\n return selected.id;\n },\n estimateMode: \"per-call\",\n fallbackTokensPerWeight: 1,\n }),\n candidates: (s) => {\n // read the record once, not once per item (U10 F2)\n const x = readInvestigation(s);\n const round = x?.rounds.at(-1)?.item;\n return x?.phase === \"observe\" &&\n !isExhausted((s.config as InvestigationConfig).budget, investigationIteration(s).spent)\n ? Object.values(s.items).filter(\n (i) => i.id === round && i.stage === \"execute\" && i.status === \"todo\",\n )\n : [];\n },\n afterComplete: (state, item, now) => {\n const x = readInvestigation(state);\n const iteration = state.iterations.find((it) => it.id === \"investigation\");\n if (\n x?.phase !== \"observe\" ||\n x.rounds.at(-1)?.item !== item ||\n state.items[item]?.status === \"done\" ||\n !iteration ||\n !isExhausted(iteration.budget, iteration.spent)\n )\n return state;\n return closeInvestigation(\n state,\n x,\n { by: \"investigation\", now },\n \"stopped\",\n `budget exhausted before experiment item \"${item}\" completed; start a new investigation with sufficient budget`,\n );\n },\n invariants: (s) => [\n `Question: ${(s.config as InvestigationConfig).question}`,\n \"Execute only the preregistered procedure; retain raw observation provenance; report invalid runs.\",\n ],\n rules: investigationRules(),\n metrics: (s) => ({\n rounds: readInvestigation(s)?.rounds.length ?? 0,\n validRuns: readInvestigation(s)?.rounds.filter((r) => r.result?.valid).length ?? 0,\n invalidRuns:\n readInvestigation(s)?.rounds.filter((r) => r.result && !r.result.valid).length ?? 0,\n }),\n report: (s) => ({\n phase: readInvestigation(s)?.phase ?? \"intake\",\n outcome: readInvestigation(s)?.outcome ?? null,\n rounds: readInvestigation(s)?.rounds.length ?? 0,\n conclusion: readInvestigation(s)?.conclusion ?? null,\n stopReason: readInvestigation(s)?.stopReason ?? null,\n }),\n };\n}\n"]}
1
+ {"version":3,"sources":["../src/methodologies/investigation/record.ts","../src/methodologies/investigation/execution.ts","../src/methodologies/investigation/invariants.ts","../src/methodologies/investigation/config.ts","../src/methodologies/investigation/ceremonies.ts","../src/methodologies/investigation/rules.ts","../src/methodologies/investigation/roles.ts","../src/methodologies/investigation/stages.ts","../src/methodologies/investigation/index.ts"],"names":["readInvestigation","s","readExt","writeInvestigation","x","writeExt","executionActors","state","item","event","transition","freshOutputRefs","completion","index","output","brokenInvestigation","what","fail","lastRound","investigationIteration","it","validateInvestigationConfig","raw","c","k","v","reject","name","message","fix","sameHypothesis","a","b","frozenChanges","text","refs","extraKey","keys","extraKeyIn","list","authorize","by","cap","roleOf","save","i","appendEvent","nowOf","closeInvestigation","outcome","reason","at","n","candidate","r","moveItem","investigationCeremonies","factory","built","methodology","make","phase","fn","applyAction","bad","addItem","h","extra","isExhausted","e","extraExperiment","p","prior","id","iteration","o","ref","entry","conclusion","independenceConflicts","target","replayRefs","investigationRules","round","investigationRoles","investigationStages","investigation","excluded","roles","selected","role","now"],"mappings":"2QAKO,IAAMA,EAAqBC,CAAAA,EAChCC,mBAAAA,CAAQD,EAAG,eAAe,CAAA,CAGfE,EAAqB,CAACF,CAAAA,CAAkBG,CAAAA,GACnDC,mBAAAA,CAASJ,EAAG,eAAA,CAAiBG,CAAC,ECDzB,SAASE,CAAAA,CAAgBC,EAAsBC,CAAAA,CAAwB,CAC5E,OAAO,CACL,GAAG,IAAI,GAAA,CAAI,CACT,GAAGD,CAAAA,CAAM,OACN,MAAA,CACEE,CAAAA,EAAUA,EAAM,IAAA,GAAS,gBAAA,EAAqBA,EAAM,OAAA,CAAuB,EAAA,GAAOD,CACrF,CAAA,CACC,GAAA,CAAKC,GAAUA,CAAAA,CAAM,EAAE,CAAA,CAC1B,GAAA,CAAIF,EAAM,KAAA,CAAMC,CAAI,GAAG,WAAA,EAAe,IACnC,MAAA,CAAQE,CAAAA,EAAeA,EAAW,EAAA,CAAG,MAAA,GAAW,aAAa,CAAA,CAC7D,GAAA,CAAKA,GAAeA,CAAAA,CAAW,EAAE,CACtC,CAAC,CACH,CACF,CAGO,SAASC,CAAAA,CAAgBJ,CAAAA,CAAsBC,EAAwB,CAC5E,IAAII,EACJ,IAAA,IAASC,CAAAA,CAAQN,EAAM,MAAA,CAAO,MAAA,CAAS,EAAGM,CAAAA,EAAS,CAAA,CAAGA,IAAS,CAC7D,IAAMJ,EAAQF,CAAAA,CAAM,MAAA,CAAOM,CAAK,CAAA,CAChC,GAAIJ,CAAAA,CAAM,IAAA,GAAS,kBAAqBA,CAAA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EAAE,MAAA,CAAO,KAAK,EAAE,MAAA,EAAU,CACtF,GACA,MAAA,CAASrD,CAAAA,GAAO,CACd,KAAA,CAAOD,CAAAA,CAAkBC,CAAC,CAAA,EAAG,KAAA,EAAS,SACtC,OAAA,CAASD,CAAAA,CAAkBC,CAAC,CAAA,EAAG,OAAA,EAAW,IAAA,CAC1C,MAAA,CAAQD,EAAkBC,CAAC,CAAA,EAAG,OAAO,MAAA,EAAU,CAAA,CAC/C,WAAYD,CAAAA,CAAkBC,CAAC,GAAG,UAAA,EAAc,IAAA,CAChD,WAAYD,CAAAA,CAAkBC,CAAC,GAAG,UAAA,EAAc,IAClD,EACF,CACF","file":"chunk-76ITDJDM.cjs","sourcesContent":["import { readExt, writeExt } from \"../../interface/ext.ts\";\nimport type { WorkflowState } from \"../../core/types.ts\";\nimport type { InvestigationState } from \"./state.ts\";\n\n/** The investigation record: `ext.investigation`, or the legacy field of a state written before 1.2. */\nexport const readInvestigation = (s: WorkflowState): InvestigationState | undefined =>\n readExt(s, \"investigation\");\n\n/** Stores the investigation record in `ext.investigation` and its deprecated legacy mirror (spec 26). */\nexport const writeInvestigation = (s: WorkflowState, x: InvestigationState): WorkflowState =>\n writeExt(s, \"investigation\", x);\n","import type { Handoff, Verdict, WorkflowState } from \"../../core/types.ts\";\n\ninterface Completion {\n id: string;\n verdict: Verdict;\n produced: Handoff[\"produced\"];\n}\n\n/** Completion actors come from validated handoffs, never caller-supplied accounting identity. */\nexport function executionActors(state: WorkflowState, item: string): string[] {\n return [\n ...new Set([\n ...state.events\n .filter(\n (event) => event.type === \"item.completed\" && (event.payload as Completion).id === item,\n )\n .map((event) => event.by),\n ...(state.items[item]?.transitions ?? [])\n .filter((transition) => transition.to.status === \"in_progress\")\n .map((transition) => transition.by),\n ]),\n ];\n}\n\n/** Only outputs of the latest successful completion can establish observation provenance. */\nexport function freshOutputRefs(state: WorkflowState, item: string): string[] {\n let completion: Completion | undefined;\n for (let index = state.events.length - 1; index >= 0; index--) {\n const event = state.events[index]!;\n if (event.type === \"item.completed\" && (event.payload as Completion).id === item) {\n completion = event.payload as Completion;\n break;\n }\n }\n return completion && [\"done\", \"needs-review\"].includes(completion.verdict)\n ? completion.produced\n .filter((output) => output.kind === \"experiment-output\")\n .map((output) => output.ref)\n : [];\n}\n","import { fail } from \"../../core/errors.ts\";\nimport type { Iteration, WorkflowState } from \"../../core/types.ts\";\nimport type { InvestigationState } from \"./state.ts\";\n\n/** A loaded state that breaks an invariant the ceremonies keep (a hand-edited or damaged file). */\nexport function brokenInvestigation(what: string): never {\n return fail(\n \"invalid-input\",\n `the investigation state is inconsistent: ${what}`,\n \"restore .workflow/state.json from git, or start a new investigation\",\n );\n}\n\n/** The latest round; the phases after preregister always have one. */\nexport function lastRound(x: InvestigationState): InvestigationState[\"rounds\"][number] {\n return x.rounds.at(-1) ?? brokenInvestigation(`phase ${x.phase} has no round`);\n}\n\n/** The `investigation` iteration intake opens; its budget bounds every round. */\nexport function investigationIteration(s: WorkflowState<string>): Iteration {\n return (\n s.iterations.find((it) => it.id === \"investigation\") ??\n brokenInvestigation('there is no \"investigation\" iteration')\n );\n}\n","import { fail } from \"../../core/errors.ts\";\nimport type { Budget } from \"../../core/types.ts\";\nexport interface InvestigationConfig {\n question: string;\n maxRounds: number;\n budget: Budget;\n}\nexport function validateInvestigationConfig(raw: unknown): InvestigationConfig {\n const c = raw as InvestigationConfig;\n if (\n !c ||\n typeof c !== \"object\" ||\n Array.isArray(c) ||\n typeof c.question !== \"string\" ||\n !c.question.trim() ||\n !Number.isSafeInteger(c.maxRounds) ||\n c.maxRounds < 1 ||\n !c.budget ||\n typeof c.budget !== \"object\" ||\n Array.isArray(c.budget) ||\n !Object.keys(c.budget).length ||\n Object.entries(c.budget).some(\n ([k, v]) =>\n ![\"tokens\", \"turns\", \"wallclockMs\"].includes(k) ||\n typeof v !== \"number\" ||\n !Number.isFinite(v) ||\n v <= 0,\n )\n )\n fail(\n \"config-invalid\",\n \"investigation requires question, positive maxRounds and a finite positive budget\",\n \"provide bounded investigation config\",\n );\n return { question: c.question, maxRounds: c.maxRounds, budget: { ...c.budget } };\n}\n","import { readInvestigation, writeInvestigation } from \"./record.ts\";\nimport { executionActors, freshOutputRefs } from \"./execution.ts\";\nimport { independenceConflicts } from \"../../common/independence.ts\";\nimport { frozenChanges } from \"../../common/frozen.ts\";\nimport { fail } from \"../../core/errors.ts\";\nimport { brokenInvestigation, investigationIteration, lastRound } from \"./invariants.ts\";\nimport { roleOf } from \"../../core/roles/lookup.ts\";\nimport { addItem } from \"../../core/items/record.ts\";\nimport { moveItem } from \"../../core/items/move.ts\";\nimport { applyAction } from \"../../core/methodology.ts\";\nimport { appendEvent, nowOf } from \"../../core/state.ts\";\nimport { isExhausted } from \"../../core/budget.ts\";\nimport type {\n Capability,\n Ceremony,\n CeremonyInput,\n Methodology,\n WorkflowState,\n} from \"../../core/types.ts\";\nimport { validateInvestigationConfig, type InvestigationConfig } from \"./config.ts\";\nimport type {\n BeliefUpdate,\n Experiment,\n Hypothesis,\n InvestigationConclusion,\n InvestigationState,\n Observation,\n} from \"./state.ts\";\nfunction reject(s: WorkflowState, name: string, message: string, fix: string): never {\n const x = readInvestigation(s);\n return fail(\"invalid-input\", `${name} (phase ${x?.phase ?? \"intake\"}): ${message}`, fix, {\n items: x ? [x.item, ...(x.rounds.at(-1) ? [x.rounds.at(-1)!.item] : [])] : [],\n });\n}\nconst sameHypothesis = (a: Hypothesis | undefined, b: Hypothesis | undefined) =>\n !!a && !!b && !frozenChanges(a, b, [\"id\", \"claim\", \"falsifiedBy\"]).length;\nconst text = (v: unknown): v is string => typeof v === \"string\" && v.trim().length > 0;\nconst refs = (v: unknown): v is string[] =>\n Array.isArray(v) && v.length > 0 && v.every(text) && new Set(v).size === v.length;\n/** First key of a caller record outside its contract; stored records are closed objects (state schema). */\nconst extraKey = (v: unknown, keys: readonly string[]): string | undefined =>\n v && typeof v === \"object\" && !Array.isArray(v)\n ? Object.keys(v).find((k) => !keys.includes(k))\n : undefined;\nconst extraKeyIn = (list: unknown, keys: readonly string[]): string | undefined =>\n Array.isArray(list) ? list.map((v) => extraKey(v, keys)).find(Boolean) : undefined;\nfunction authorize(s: WorkflowState, by: string, cap: Capability) {\n if (!roleOf(s, by)?.capabilities.includes(cap))\n fail(\n \"missing-capability\",\n `${by} needs ${cap}`,\n \"use a registered role with the required capability\",\n );\n}\nfunction save(s: WorkflowState, x: InvestigationState, i: CeremonyInput, name: string) {\n return appendEvent(\n writeInvestigation(s, x),\n `investigation.${name}`,\n i.by,\n { ...x },\n nowOf(i.now),\n );\n}\nexport function closeInvestigation(\n s: WorkflowState,\n x: InvestigationState,\n i: CeremonyInput,\n outcome: \"stopped\" | \"resolved\" | \"inconclusive\",\n reason?: string,\n) {\n const at = nowOf(i.now);\n let n = save(\n s,\n { ...x, phase: \"closed\", outcome, ...(reason ? { stopReason: reason } : {}) },\n i,\n outcome,\n );\n n = {\n ...n,\n iterations: n.iterations.map((it) =>\n it.id === \"investigation\"\n ? { ...it, endedAt: at, outcome: outcome === \"stopped\" ? \"cancelled\" : \"completed\" }\n : it,\n ),\n };\n for (const item of Object.values(n.items).filter(\n (candidate) => candidate.id === x.item || x.rounds.some((r) => r.item === candidate.id),\n ))\n if (item.status !== \"done\" && item.status !== \"dropped\")\n n = moveItem(\n n,\n item.id,\n { status: outcome === \"resolved\" && item.id === x.item ? \"done\" : \"dropped\" },\n i.by,\n at,\n );\n return n;\n}\nexport function investigationCeremonies(\n factory: () => Methodology<InvestigationConfig>,\n): Record<string, Ceremony> {\n let built: Methodology<InvestigationConfig> | undefined;\n const methodology = () => (built ??= factory());\n const make =\n (\n name: string,\n cap: Capability,\n phase: string | undefined,\n fn: (\n s: WorkflowState,\n x: InvestigationState,\n i: CeremonyInput,\n bad: (message: string, fix: string) => never,\n ) => WorkflowState,\n ): Ceremony =>\n (s, i) => {\n authorize(s, i.by, cap);\n const x = readInvestigation(s);\n if (!x || x.phase === \"closed\")\n reject(s, name, \"no active investigation\", \"start a new investigation with intake {item}\");\n if (phase && x.phase !== phase && !(name === \"hypotheses\" && x.phase === \"preregister\"))\n reject(\n s,\n name,\n `expected ${phase}, got ${x.phase}`,\n `finish phase ${x.phase} before calling ${name}; ${name} requires phase ${phase}`,\n );\n return applyAction(s, methodology(), { type: `ceremony.${name}`, by: i.by, payload: i }, () =>\n fn(s, x, i, (message, fix) => reject(s, name, message, fix)),\n );\n };\n return {\n intake(s, i) {\n authorize(s, i.by, \"facilitate\");\n const bad = (message: string, fix: string) => reject(s, \"intake\", message, fix);\n if (s.methodology !== \"investigation\")\n bad(\n `workflow methodology is ${s.methodology}, not investigation`,\n \"init a workflow with the investigation methodology before intake\",\n );\n if (readInvestigation(s))\n bad(\n \"investigation already started\",\n \"use the existing investigation or initialize a new workflow\",\n );\n if (!text(i.item))\n bad(\"item is required\", \"set intake.item to a unique investigation item ID\");\n const c = validateInvestigationConfig(s.config);\n return applyAction(\n s,\n methodology(),\n { type: \"ceremony.intake\", by: i.by, payload: i },\n () => {\n let n = addItem(\n s,\n {\n id: i.item as string,\n title: c.question,\n acceptance: [\"Independent evidence-based conclusion\"],\n stage: \"intake\",\n },\n i.by,\n i.now,\n );\n n = {\n ...n,\n iterations: [\n ...n.iterations,\n {\n id: \"investigation\",\n goal: c.question,\n budget: { ...c.budget },\n spent: { tokens: 0, turns: 0, wallclockMs: 0 },\n startedAt: nowOf(i.now),\n committed: [],\n carryover: [],\n },\n ],\n };\n return save(\n n,\n {\n item: i.item as string,\n phase: \"hypotheses\",\n hypotheses: [],\n rounds: [],\n contributors: [i.by],\n },\n i,\n \"intake\",\n );\n },\n );\n },\n hypotheses: make(\"hypotheses\", \"define-acceptance\", \"hypotheses\", (s, x, i, bad) => {\n const h = i.hypotheses as Hypothesis[];\n const extra = extraKeyIn(h, [\"id\", \"claim\", \"falsifiedBy\"]);\n if (extra)\n bad(\n `unknown key \"${extra}\" in a hypotheses entry`,\n \"use only id, claim and falsifiedBy in each hypotheses entry\",\n );\n if (\n !Array.isArray(h) ||\n !h.length ||\n h.some((v) => !v || !text(v.id) || !text(v.claim) || !text(v.falsifiedBy)) ||\n new Set(h.map((v) => v.id)).size !== h.length ||\n (h.length < 2 && !text(i.singleHypothesisRationale))\n )\n bad(\n \"provide competing falsifiable hypotheses or single-testable rationale\",\n \"set hypotheses to unique {id, claim, falsifiedBy} entries; supply singleHypothesisRationale when there is only one\",\n );\n return save(\n s,\n {\n ...x,\n hypotheses: h.map((v) => ({ id: v.id, claim: v.claim, falsifiedBy: v.falsifiedBy })),\n ...(text(i.singleHypothesisRationale)\n ? { singleHypothesisRationale: i.singleHypothesisRationale }\n : {}),\n contributors: [...new Set([...x.contributors, i.by])],\n phase: \"preregister\",\n },\n i,\n \"hypotheses\",\n );\n }),\n preregister: make(\"preregister\", \"define-acceptance\", \"preregister\", (s, x, i, bad) => {\n const c = validateInvestigationConfig(s.config),\n it = s.iterations.find((v) => v.id === \"investigation\");\n if (x.rounds.length >= c.maxRounds || !it || isExhausted(c.budget, it.spent))\n bad(\n `round limit or budget exhausted (${x.rounds.length} of ${c.maxRounds} rounds used)`,\n \"call stop {reason} to close this investigation, or start a new one with a larger maxRounds or budget\",\n );\n const e = i.experiment as Experiment;\n const extraExperiment =\n extraKey(e, [\"id\", \"procedureRef\", \"predictions\", \"replayOf\"]) ??\n extraKeyIn(e?.predictions, [\"hypothesis\", \"prediction\"]);\n if (extraExperiment)\n bad(\n `unknown key \"${extraExperiment}\" in experiment`,\n \"use only id, procedureRef, predictions [{hypothesis, prediction}] and replayOf in experiment\",\n );\n if (\n !e ||\n !text(e.id) ||\n !text(e.procedureRef) ||\n x.rounds.some((r) => r.experiment.id === e.id) ||\n !Array.isArray(e.predictions) ||\n e.predictions.length !== x.hypotheses.length ||\n x.hypotheses.some(\n (h) =>\n e.predictions.filter((p) => p?.hypothesis === h.id && text(p.prediction)).length !== 1,\n ) ||\n new Set(e.predictions.map((p) => p.prediction)).size !== e.predictions.length\n )\n bad(\n \"preregister unique experiment with differing predictions for every hypothesis\",\n \"set experiment.id to a new ID, experiment.procedureRef, and one distinct experiment.predictions entry per hypothesis\",\n );\n if (e.replayOf) {\n const prior = x.rounds.find((r) => r.experiment.id === e.replayOf && r.result?.valid);\n if (\n !prior ||\n frozenChanges(prior.experiment, e, [\"procedureRef\"]).length ||\n prior.hypotheses.length !== x.hypotheses.length ||\n x.hypotheses.some(\n (h) =>\n !sameHypothesis(\n h,\n prior.hypotheses.find((p) => p.id === h.id),\n ),\n ) ||\n e.predictions.some(\n (p) =>\n !prior.experiment.predictions.some(\n (q) => !frozenChanges(q, p, [\"hypothesis\", \"prediction\"]).length,\n ),\n )\n )\n bad(\n \"replay must repeat the procedure, predictions and hypotheses of a prior valid experiment\",\n \"set experiment.replayOf to a valid prior experiment with identical procedureRef, predictions and hypothesis definitions\",\n );\n }\n const id = `${x.item}-run-${x.rounds.length + 1}`;\n let n = addItem(\n s,\n {\n id,\n title: `Experiment ${e.id}`,\n stage: \"execute\",\n acceptance: [e.procedureRef],\n iteration: \"investigation\",\n },\n i.by,\n i.now,\n );\n n = {\n ...n,\n iterations: n.iterations.map((iteration) =>\n iteration.id === \"investigation\"\n ? { ...iteration, committed: [...iteration.committed, id] }\n : iteration,\n ),\n };\n return save(\n n,\n {\n ...x,\n phase: \"observe\",\n rounds: [\n ...x.rounds,\n {\n experiment: {\n id: e.id,\n procedureRef: e.procedureRef,\n predictions: e.predictions.map((p) => ({\n hypothesis: p.hypothesis,\n prediction: p.prediction,\n })),\n ...(e.replayOf ? { replayOf: e.replayOf } : {}),\n },\n hypotheses: x.hypotheses.map((v) => ({ ...v })),\n item: id,\n by: i.by,\n },\n ],\n contributors: [...new Set([...x.contributors, i.by])],\n },\n i,\n \"preregister\",\n );\n }),\n observe: make(\"observe\", \"verify\", \"observe\", (s, x, i, bad) => {\n const r = lastRound(x),\n o = i.result as Observation;\n const extra = extraKey(o, [\"id\", \"valid\", \"summary\", \"provenanceRefs\"]);\n if (extra)\n bad(\n `unknown key \"${extra}\" in result`,\n \"use only id, valid, summary and provenanceRefs in result\",\n );\n if (\n i.experiment !== r.experiment.id ||\n !o ||\n !text(o.id) ||\n typeof o.valid !== \"boolean\" ||\n !text(o.summary) ||\n !refs(o.provenanceRefs) ||\n x.rounds.some((prior) => prior.result?.id === o.id)\n )\n bad(\n \"observation needs current experiment, unique result and provenance\",\n \"set experiment to the active experiment ID and result to {id, valid, summary, provenanceRefs} with a new result.id\",\n );\n if (s.items[r.item]?.status !== \"done\")\n bad(\n \"complete experiment execution before recording observations\",\n \"dispatch and complete the active experiment item before calling observe\",\n );\n if (!freshOutputRefs(s, r.item).some((ref) => o.provenanceRefs.includes(ref)))\n bad(\n \"observation must link fresh experiment-output evidence from the latest completion\",\n `include an experiment-output ref produced by the latest successful completion of item \"${r.item}\" in result.provenanceRefs`,\n );\n return save(\n s,\n {\n ...x,\n phase: \"update-belief\",\n rounds: x.rounds.map((v) =>\n v === r\n ? {\n ...v,\n result: {\n id: o.id,\n valid: o.valid,\n summary: o.summary,\n provenanceRefs: [...o.provenanceRefs],\n },\n }\n : v,\n ),\n contributors: [...new Set([...x.contributors, i.by, ...executionActors(s, r.item)])],\n },\n i,\n \"observe\",\n );\n }),\n \"update-belief\": make(\"update-belief\", \"define-acceptance\", \"update-belief\", (s, x, i, bad) => {\n const r = lastRound(x),\n a = i.assessments as BeliefUpdate[\"assessments\"];\n const extra = extraKeyIn(a, [\"hypothesis\", \"assessment\", \"reason\"]);\n if (extra)\n bad(\n `unknown key \"${extra}\" in an assessments entry`,\n \"use only hypothesis, assessment and reason in each assessments entry\",\n );\n if (\n i.result !== r.result?.id ||\n !Array.isArray(a) ||\n a.length !== x.hypotheses.length ||\n x.hypotheses.some(\n (h) =>\n a.filter(\n (v) =>\n v?.hypothesis === h.id &&\n [\"supported\", \"refuted\", \"uncertain\"].includes(v.assessment) &&\n text(v.reason),\n ).length !== 1,\n ) ||\n ![\"round\", \"conclusion\"].includes(i.next as string)\n )\n bad(\n \"belief update must assess every hypothesis against current result\",\n \"set result to the latest result ID, assessments to one {hypothesis, assessment, reason} per hypothesis, and next to round or conclusion\",\n );\n const result = r.result ?? brokenInvestigation(`round ${r.experiment.id} has no result`);\n if (!result.valid && a.some((v) => v.assessment !== \"uncertain\"))\n bad(\n \"invalid experiments cannot support beliefs\",\n \"set every assessment to uncertain for an invalid experiment result\",\n );\n let n = save(\n s,\n {\n ...x,\n phase: i.next === \"round\" ? \"preregister\" : \"conclusion\",\n rounds: x.rounds.map((v) =>\n v === r\n ? {\n ...v,\n update: {\n result: i.result as string,\n assessments: a.map((entry) => ({\n hypothesis: entry.hypothesis,\n assessment: entry.assessment,\n reason: entry.reason,\n })),\n },\n }\n : v,\n ),\n contributors: [...new Set([...x.contributors, i.by])],\n },\n i,\n \"belief-updated\",\n );\n const it = investigationIteration(n);\n if (\n i.next === \"round\" &&\n (x.rounds.length >= validateInvestigationConfig(s.config).maxRounds ||\n isExhausted(it.budget, it.spent))\n )\n n = closeInvestigation(\n n,\n readInvestigation(n)!,\n i,\n \"stopped\",\n \"budget or round limit exhausted\",\n );\n return n;\n }),\n conclude: make(\"conclude\", \"define-acceptance\", \"conclusion\", (s, x, i, bad) => {\n const c = i as unknown as InvestigationConclusion;\n if (\n ![\"resolved\", \"inconclusive\"].includes(c.outcome) ||\n !text(c.summary) ||\n !refs(c.evidenceRefs) ||\n c.evidenceRefs.some((ref) => !x.rounds.some((r) => r.result?.provenanceRefs.includes(ref)))\n )\n bad(\n \"conclusion needs observed evidence references\",\n \"set outcome, summary and evidenceRefs to references preserved in recorded observations\",\n );\n if (\n c.outcome === \"resolved\" &&\n (!text(c.supportedHypothesis) ||\n !x.rounds\n .slice(-1)\n .some(\n (r) =>\n r.result?.valid &&\n r.update?.assessments.some(\n (a) => a.hypothesis === c.supportedHypothesis && a.assessment === \"supported\",\n ),\n ))\n )\n bad(\n \"resolved conclusion needs a supported hypothesis\",\n \"set supportedHypothesis to a hypothesis supported by the latest valid round, or choose outcome inconclusive\",\n );\n return save(\n s,\n {\n ...x,\n phase: \"review\",\n conclusion: {\n outcome: c.outcome,\n summary: c.summary,\n evidenceRefs: [...c.evidenceRefs],\n ...(c.supportedHypothesis ? { supportedHypothesis: c.supportedHypothesis } : {}),\n by: i.by,\n },\n contributors: [...new Set([...x.contributors, i.by])],\n },\n i,\n \"conclusion\",\n );\n }),\n \"review-conclusion\": make(\"review-conclusion\", \"review\", \"review\", (s, x, i, bad) => {\n const conclusion = x.conclusion ?? brokenInvestigation(\"phase review has no conclusion\");\n if (independenceConflicts(i.by, x.contributors).length)\n bad(\n \"conclusion reviewer must be independent of investigation contributors\",\n \"use a review-capable role that did not contribute to or execute this investigation\",\n );\n if (typeof i.approve !== \"boolean\" || !text(i.reason))\n bad(\n \"review needs approval and reason\",\n \"set approve to a boolean and reason to a nonempty review explanation\",\n );\n if (!i.approve) {\n const target = i.next ?? \"conclusion\";\n if (target !== \"round\" && target !== \"conclusion\")\n bad(\n \"review rejection next must be round or conclusion\",\n \"set next to round for more evidence or conclusion for a revised conclusion\",\n );\n const n = save(\n s,\n {\n ...x,\n phase: target === \"round\" ? \"preregister\" : \"conclusion\",\n reviewHistory: [\n ...(x.reviewHistory ?? []),\n {\n by: i.by,\n reason: i.reason as string,\n approve: false,\n next: target as \"round\" | \"conclusion\",\n replayRefs: [],\n },\n ],\n },\n i,\n \"review-rejected\",\n );\n const iteration = investigationIteration(s);\n if (\n target === \"round\" &&\n (x.rounds.length >= validateInvestigationConfig(s.config).maxRounds ||\n isExhausted(iteration.budget, iteration.spent))\n )\n return closeInvestigation(\n n,\n readInvestigation(n)!,\n i,\n \"stopped\",\n \"budget or round limit exhausted after review requested another round\",\n );\n return n;\n }\n const replayRefs = Array.isArray(i.replayRefs) ? i.replayRefs : [];\n if (\n conclusion.outcome === \"resolved\" &&\n (!refs(replayRefs) ||\n !x.rounds.some(\n (r) =>\n r.experiment.replayOf &&\n !independenceConflicts(\n executionActors(s, r.item),\n executionActors(\n s,\n (\n x.rounds.find((p) => p.experiment.id === r.experiment.replayOf) ??\n brokenInvestigation(\n `round ${r.experiment.id} replays the unknown experiment ${r.experiment.replayOf}`,\n )\n ).item,\n ),\n ).length &&\n sameHypothesis(\n r.hypotheses.find((h) => h.id === conclusion.supportedHypothesis),\n lastRound(x).hypotheses.find((h) => h.id === conclusion.supportedHypothesis),\n ) &&\n r.result?.valid &&\n replayRefs.includes(r.result.id) &&\n r.update?.assessments.some(\n (a) =>\n a.hypothesis === conclusion.supportedHypothesis && a.assessment === \"supported\",\n ),\n ))\n )\n bad(\n \"resolved conclusion requires valid replay result and supporting belief update\",\n \"set replayRefs to a valid independent replay result supporting the latest supported hypothesis definition, or reject with next round\",\n );\n return closeInvestigation(\n s,\n {\n ...x,\n review: { by: i.by, reason: i.reason as string, replayRefs: replayRefs as string[] },\n reviewHistory: [\n ...(x.reviewHistory ?? []),\n {\n by: i.by,\n reason: i.reason as string,\n approve: true,\n replayRefs: replayRefs as string[],\n },\n ],\n },\n i,\n conclusion.outcome,\n );\n }),\n stop: make(\"stop\", \"facilitate\", undefined, (s, x, i, bad) => {\n if (!text(i.reason))\n bad(\n \"stop needs reason\",\n \"set reason to a nonempty explanation for stopping this investigation\",\n );\n return closeInvestigation(s, x, i, \"stopped\", i.reason as string);\n }),\n };\n}\n","import { readInvestigation } from \"./record.ts\";\nimport { executionActors } from \"./execution.ts\";\nimport { independenceConflicts } from \"../../common/independence.ts\";\nimport type { Rule } from \"../../core/types.ts\";\nexport function investigationRules(): Rule[] {\n return [\n {\n id: \"independent-replay\",\n severity: \"error\",\n check(s, a) {\n if (a.type !== \"item.complete\") return [];\n const round = readInvestigation(s)?.rounds.find(\n (r) => r.item === (a.payload as { item?: string })?.item,\n );\n const prior = readInvestigation(s)?.rounds.find(\n (r) => r.experiment.id === round?.experiment.replayOf,\n );\n return prior && independenceConflicts(a.by, executionActors(s, prior.item)).length\n ? [\n {\n rule: \"independent-replay\",\n item: round!.item,\n severity: \"error\",\n message: \"Replay executor also executed the original experiment\",\n fix: \"assign a different deliver-capable role\",\n },\n ]\n : [];\n },\n },\n {\n id: \"investigation-execution-only\",\n severity: \"error\",\n check(s, a) {\n if (a.type !== \"item.complete\") return [];\n const p = a.payload as { item: string };\n const x = readInvestigation(s);\n return x?.phase === \"observe\" && x.rounds.at(-1)?.item === p.item\n ? []\n : [\n {\n rule: \"investigation-execution-only\",\n item: p.item,\n severity: \"error\",\n message: \"Only the active preregistered experiment can complete\",\n fix: `complete only the active experiment item in phase observe; current phase is ${x?.phase ?? \"intake\"}`,\n },\n ];\n },\n },\n ];\n}\n","import type { Role } from \"../../core/types.ts\";\nexport function investigationRoles(): Role[] {\n return [\n {\n id: \"replay-worker\",\n name: \"Independent replay worker\",\n modelTier: \"small\",\n capabilities: [\"deliver\", \"verify\"],\n canApprove: [],\n inputs: [\"preregistered-experiment\"],\n outputs: [\"experiment-output\"],\n do_not: [\"Do not change the replay procedure\"],\n },\n {\n id: \"investigator\",\n name: \"Investigator\",\n modelTier: \"large\",\n capabilities: [\"facilitate\", \"define-acceptance\", \"deliver\", \"verify\"],\n canApprove: [],\n inputs: [\"question\", \"prior-results\"],\n outputs: [\"hypotheses\", \"preregistered-experiment\", \"belief-update\"],\n do_not: [\"Do not revise predictions after execution\", \"Do not approve your own conclusions\"],\n },\n {\n id: \"conclusion-reviewer\",\n name: \"Independent conclusion reviewer\",\n modelTier: \"large\",\n capabilities: [\"review\"],\n canApprove: [\"investigation-conclusion\"],\n inputs: [\"evidence\", \"replay\", \"conclusion\"],\n outputs: [\"conclusion-review\"],\n do_not: [\"Do not approve unsupported conclusions\"],\n },\n ];\n}\n","import type { Stage } from \"../../core/types.ts\";\nexport function investigationStages(): Stage[] {\n return [\n {\n id: \"intake\",\n name: \"Intake\",\n entryPolicy: [],\n exitPolicy: [{ kind: \"acceptance-written\" }],\n },\n {\n id: \"execute\",\n name: \"Execute preregistered experiment\",\n entryPolicy: [{ kind: \"acceptance-written\" }, { kind: \"no-open-blockers\" }],\n exitPolicy: [{ kind: \"evidence\", evidenceKind: \"experiment-output\" }],\n },\n { id: \"observed\", name: \"Execution recorded\", entryPolicy: [], exitPolicy: [] },\n ];\n}\n","import { readInvestigation } from \"./record.ts\";\nimport { fail } from \"../../core/errors.ts\";\nimport { executionActors } from \"./execution.ts\";\nimport { independenceConflicts } from \"../../common/independence.ts\";\nimport { closeInvestigation, investigationCeremonies } from \"./ceremonies.ts\";\nimport { investigationIteration } from \"./invariants.ts\";\nimport { investigationRules } from \"./rules.ts\";\nimport { investigationRoles } from \"./roles.ts\";\nimport { investigationStages } from \"./stages.ts\";\nimport { isExhausted } from \"../../core/budget.ts\";\nimport type { Methodology } from \"../../core/types.ts\";\nimport { validateInvestigationConfig, type InvestigationConfig } from \"./config.ts\";\nexport { validateInvestigationConfig };\nexport type { InvestigationConfig };\nexport type * from \"./state.ts\";\nexport function investigation(): Methodology<InvestigationConfig> {\n return {\n name: \"investigation\",\n validateConfig: validateInvestigationConfig,\n lockedConfigKeys: [\"question\", \"maxRounds\", \"budget\"],\n vocabulary: {\n backlog: \"Questions\",\n item: \"Investigation artifact\",\n stage: \"Investigation phase\",\n iteration: \"Investigation budget\",\n increment: \"Conclusion\",\n ceremony: \"Investigation ceremony\",\n gate: \"Independent conclusion review\",\n },\n defaultStages: investigationStages,\n defaultRoles: investigationRoles,\n requiredCapabilities: [\"facilitate\", \"define-acceptance\", \"deliver\", \"verify\", \"review\"],\n exclusiveCapabilities: [],\n humanDefaults: { gates: \"none\" },\n ceremonies: investigationCeremonies(investigation),\n plannerOptions: (state) => ({\n schedulerMode: \"level\",\n concurrencyCap: 1,\n roleFor: (item) => {\n const r = readInvestigation(state)?.rounds.find((candidate) => candidate.item === item.id);\n const prior = readInvestigation(state)?.rounds.find(\n (p) => p.experiment.id === r?.experiment.replayOf,\n );\n const excluded = prior ? executionActors(state, prior.item) : [];\n const roles = Object.values(state.roles);\n const selected =\n (!prior\n ? roles.find(\n (role) =>\n role.capabilities.includes(\"deliver\") &&\n role.capabilities.includes(\"define-acceptance\"),\n )\n : undefined) ??\n roles.find(\n (role) =>\n role.capabilities.includes(\"deliver\") &&\n !independenceConflicts(role.id, excluded).length,\n );\n if (!selected)\n fail(\n \"missing-capability\",\n `No eligible executor for experiment item \"${item.id}\"`,\n prior\n ? `register an independent deliver-capable role that did not execute \"${prior.item}\"`\n : \"register a role with deliver capability\",\n { items: [item.id] },\n );\n return selected.id;\n },\n estimateMode: \"per-call\",\n fallbackTokensPerWeight: 1,\n }),\n candidates: (s) => {\n // read the record once, not once per item (U10 F2)\n const x = readInvestigation(s);\n const round = x?.rounds.at(-1)?.item;\n return x?.phase === \"observe\" &&\n !isExhausted((s.config as InvestigationConfig).budget, investigationIteration(s).spent)\n ? Object.values(s.items).filter(\n (i) => i.id === round && i.stage === \"execute\" && i.status === \"todo\",\n )\n : [];\n },\n afterComplete: (state, item, now) => {\n const x = readInvestigation(state);\n const iteration = state.iterations.find((it) => it.id === \"investigation\");\n if (\n x?.phase !== \"observe\" ||\n x.rounds.at(-1)?.item !== item ||\n state.items[item]?.status === \"done\" ||\n !iteration ||\n !isExhausted(iteration.budget, iteration.spent)\n )\n return state;\n return closeInvestigation(\n state,\n x,\n { by: \"investigation\", now },\n \"stopped\",\n `budget exhausted before experiment item \"${item}\" completed; start a new investigation with sufficient budget`,\n );\n },\n invariants: (s) => [\n `Question: ${(s.config as InvestigationConfig).question}`,\n \"Execute only the preregistered procedure; retain raw observation provenance; report invalid runs.\",\n ],\n rules: investigationRules(),\n metrics: (s) => ({\n rounds: readInvestigation(s)?.rounds.length ?? 0,\n validRuns: readInvestigation(s)?.rounds.filter((r) => r.result?.valid).length ?? 0,\n invalidRuns:\n readInvestigation(s)?.rounds.filter((r) => r.result && !r.result.valid).length ?? 0,\n }),\n report: (s) => ({\n phase: readInvestigation(s)?.phase ?? \"intake\",\n outcome: readInvestigation(s)?.outcome ?? null,\n rounds: readInvestigation(s)?.rounds.length ?? 0,\n conclusion: readInvestigation(s)?.conclusion ?? null,\n stopReason: readInvestigation(s)?.stopReason ?? null,\n }),\n };\n}\n"]}