@iowarp/clio-coder 0.3.7 → 0.3.8

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 (223) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +7 -2
  3. package/dist/{acp-SK4MD6MM.js → acp-U67UHUK2.js} +13 -13
  4. package/dist/{agents-2FN2K6ME.js → agents-YU6SGALZ.js} +35 -33
  5. package/dist/assets/codewiki.json +1 -1
  6. package/dist/{auth-QIYZWM5I.js → auth-5ZPJOIVG.js} +32 -24
  7. package/dist/builtins-C6JMZVV6.js +17 -0
  8. package/dist/{chunk-YD734TPH.js → chunk-26LEYJZH.js} +2 -2
  9. package/dist/{chunk-TSHXZTOQ.js → chunk-2HEJ2F35.js} +5 -5
  10. package/dist/{chunk-WJHBC77E.js → chunk-2HFZQUHL.js} +5 -5
  11. package/dist/{chunk-FO5ZOVUY.js → chunk-3BINW3FP.js} +5 -5
  12. package/dist/{chunk-EOOQZZDE.js → chunk-4SPRNWDE.js} +18 -18
  13. package/dist/{chunk-EBEFWSGL.js → chunk-5DHKRSMQ.js} +7 -7
  14. package/dist/{chunk-OBMAI2DP.js → chunk-5H3GB5BO.js} +11 -9
  15. package/dist/{chunk-JTSEDYVQ.js → chunk-5Q2VVUKB.js} +7 -7
  16. package/dist/{chunk-VQNODYQ4.js → chunk-7RFXX52T.js} +294 -3704
  17. package/dist/{chunk-XEGB6BCN.js → chunk-7RGZWPB6.js} +5 -5
  18. package/dist/{chunk-GH5622CP.js → chunk-A2NJGIB3.js} +2 -2
  19. package/dist/{chunk-CEYBNUGC.js → chunk-A3WNZD3P.js} +323 -27
  20. package/dist/{chunk-D4MDIG46.js → chunk-B5CSFE7B.js} +7 -7
  21. package/dist/{chunk-2SFS6XQE.js → chunk-DGSYXYMX.js} +3 -2
  22. package/dist/{chunk-ZWLZP4ZT.js → chunk-DYIM5TJT.js} +98 -12
  23. package/dist/{chunk-KCMKRQX4.js → chunk-E77JEWSD.js} +42 -49
  24. package/dist/{chunk-J7PIKKWC.js → chunk-EMYUUSFG.js} +7 -7
  25. package/dist/{chunk-JRIO5UD2.js → chunk-EQ63NRB7.js} +5 -5
  26. package/dist/{chunk-UVDSQ6LW.js → chunk-FBVTI2TJ.js} +74 -28
  27. package/dist/{chunk-BMWK7ZIZ.js → chunk-FHJEP5SW.js} +13 -13
  28. package/dist/{chunk-FOT2FX5J.js → chunk-GN57SG4G.js} +7 -7
  29. package/dist/{chunk-SROCI7ZU.js → chunk-GPIEI3LY.js} +5 -5
  30. package/dist/{chunk-UFQ3F4FW.js → chunk-GU2UIAFZ.js} +4 -4
  31. package/dist/{chunk-UND3GU2L.js → chunk-H7IXIC72.js} +2 -2
  32. package/dist/{chunk-VREKEFLL.js → chunk-HLE42MG7.js} +3 -3
  33. package/dist/{chunk-465YSENW.js → chunk-IFBNV6H6.js} +3 -3
  34. package/dist/{chunk-LADCF22A.js → chunk-IGWKHNIQ.js} +113 -54
  35. package/dist/chunk-IIZWH4XA.js +172 -0
  36. package/dist/{chunk-UHXRNZ2J.js → chunk-IJ7RPIYJ.js} +4 -4
  37. package/dist/{chunk-M4AKACEO.js → chunk-J3YUBZWY.js} +2 -2
  38. package/dist/{chunk-AB4XIIVB.js → chunk-JOZYP4GM.js} +6 -6
  39. package/dist/{chunk-ZGH7FGS5.js → chunk-K4XHGFR5.js} +742 -12
  40. package/dist/{chunk-EELBMBT6.js → chunk-KTYTFRMB.js} +62 -5
  41. package/dist/chunk-LU7P4LHA.js +33 -0
  42. package/dist/{chunk-DQA7QLMD.js → chunk-ME6CCNFO.js} +9 -24
  43. package/dist/{chunk-KZ2H5X4G.js → chunk-MXKJU4JB.js} +88 -14
  44. package/dist/{chunk-DMD2AGVS.js → chunk-N22QMJKY.js} +20 -18
  45. package/dist/chunk-NMPKI6XL.js +3006 -0
  46. package/dist/chunk-NUGM5KR6.js +165 -0
  47. package/dist/{chunk-5C77SEEY.js → chunk-P43ETTHK.js} +2 -2
  48. package/dist/{chunk-JNXPYBB4.js → chunk-PMDBGQSJ.js} +2 -2
  49. package/dist/chunk-PT7HYKEM.js +165 -0
  50. package/dist/{chunk-GEYXPTRF.js → chunk-RWSI4YD7.js} +2 -2
  51. package/dist/{chunk-C4JBQ5SR.js → chunk-TANS5ZJS.js} +6 -6
  52. package/dist/{chunk-YTYFXUI3.js → chunk-TB5666IT.js} +9 -9
  53. package/dist/{chunk-UUANF5CR.js → chunk-TLQJPP24.js} +375 -687
  54. package/dist/{chunk-OB5HIGJY.js → chunk-TT36MB5S.js} +2 -1
  55. package/dist/{chunk-DJNLUABN.js → chunk-TTHACPOM.js} +135 -17
  56. package/dist/{chunk-6M7VS3J3.js → chunk-TYPGUK6W.js} +4 -4
  57. package/dist/{chunk-THKY7CD7.js → chunk-U6MBIEMB.js} +108 -24
  58. package/dist/{chunk-PD3MESLB.js → chunk-VAWNZU7Z.js} +4 -4
  59. package/dist/{chunk-IR4CFBFN.js → chunk-VCBR6CU7.js} +12 -12
  60. package/dist/{chunk-WHJYKASB.js → chunk-VHN4MY6O.js} +2 -2
  61. package/dist/{chunk-MXI6J5JF.js → chunk-VWZOAB7K.js} +10 -10
  62. package/dist/{chunk-QCTRSGHQ.js → chunk-WLFILSD5.js} +36 -36
  63. package/dist/{chunk-5UJ6ECTS.js → chunk-WNIJTQQK.js} +6 -6
  64. package/dist/{chunk-4DWFMQDR.js → chunk-WSB3FPX7.js} +68 -20
  65. package/dist/{chunk-3HAPLH5M.js → chunk-WWCZ5F23.js} +112 -10
  66. package/dist/{chunk-X2KV5FXT.js → chunk-WXY7KU3G.js} +2 -2
  67. package/dist/{chunk-PPAMZ32Z.js → chunk-XK56QHLX.js} +6 -1
  68. package/dist/{chunk-DOOEX22V.js → chunk-XWSF374K.js} +4 -4
  69. package/dist/{chunk-6TUKSZVF.js → chunk-YS5VLNH5.js} +8 -8
  70. package/dist/{chunk-ZZMN5OM4.js → chunk-ZNLWCMVZ.js} +2 -2
  71. package/dist/{chunk-WHGPSPT5.js → chunk-ZVJ5BLO2.js} +2 -2
  72. package/dist/cli/index.js +31 -31
  73. package/dist/{clio-WBVQEBKO.js → clio-QVTYJ57A.js} +8 -8
  74. package/dist/code-nav-FGGFIE7L.js +2 -2
  75. package/dist/codewiki/build-worker.js +4 -4
  76. package/dist/{components-F7OEATSO.js → components-ZFA3SAER.js} +8 -8
  77. package/dist/{config-TRBL3RCF.js → config-LW5IJFQN.js} +58 -53
  78. package/dist/{configure-OLCVPHNM.js → configure-7XIZCOU4.js} +26 -21
  79. package/dist/{context-XEWE3MOJ.js → context-L3WL3X7K.js} +47 -41
  80. package/dist/{context-WFPKQSM6.js → context-N52ZA626.js} +22 -22
  81. package/dist/{context-MJIJ6GOX.js → context-Y6Y7QPR6.js} +12 -12
  82. package/dist/{context-clear-KNOS2JPB.js → context-clear-MBQRLSDQ.js} +47 -41
  83. package/dist/{context-index-SSR5ECNE.js → context-index-HVMFQHK3.js} +5 -5
  84. package/dist/{context-working-set-EUXAZI6N.js → context-working-set-GS6DSO7F.js} +14 -14
  85. package/dist/{dispatch-runner-B7MTOVKL.js → dispatch-runner-22ZCNOM3.js} +83 -55
  86. package/dist/{docs-FLJTIDSE.js → docs-7LQ23DLM.js} +8 -8
  87. package/dist/{doctor-RN4YKO2X.js → doctor-M7YEDGAE.js} +24 -20
  88. package/dist/{eval-RUBJVSNQ.js → eval-BEC2WHDA.js} +71 -19
  89. package/dist/{evidence-JZNBUOQZ.js → evidence-REJUMSKM.js} +62 -56
  90. package/dist/{evolve-FJVC4KKI.js → evolve-PY5ZBA5K.js} +41 -35
  91. package/dist/{extensions-IQL36S7K.js → extensions-HVKU65YU.js} +6 -6
  92. package/dist/{fleet-BDKYJFCP.js → fleet-7WZEWRFA.js} +72 -67
  93. package/dist/{fleet-commands-ZFIWZSB3.js → fleet-commands-UVHWM76J.js} +10 -10
  94. package/dist/{fleet-graph-Y6HPXIVF.js → fleet-graph-6ULH7PES.js} +13 -13
  95. package/dist/{fleet-preflight-BHSNPBMH.js → fleet-preflight-J53T6CCE.js} +5 -5
  96. package/dist/{fleet-validate-BIYREGIK.js → fleet-validate-72PC4SLA.js} +17 -17
  97. package/dist/{init-LQUB5COQ.js → init-OG3TPGQG.js} +61 -56
  98. package/dist/{library-NJAHIGG4.js → library-CNTMPLRF.js} +18 -18
  99. package/dist/{memory-OG6HOYKM.js → memory-6IS7F275.js} +43 -37
  100. package/dist/{models-5ZG5XY7J.js → models-ENRJDA5W.js} +33 -28
  101. package/dist/{monitor-TJ7AMTGB.js → monitor-XLDVO7TN.js} +56 -38
  102. package/dist/{orchestrator-WZYB54DM.js → orchestrator-6KSPYRHA.js} +421 -303
  103. package/dist/{paths-XUC7GS6E.js → paths-DBXMZMDU.js} +5 -5
  104. package/dist/registry-LG64LTF4.js +11 -0
  105. package/dist/{reset-PXQT45IY.js → reset-RZ4ER727.js} +10 -10
  106. package/dist/{run-FQ74YF62.js → run-Y2CNK5RU.js} +79 -74
  107. package/dist/{share-FW7SVCL3.js → share-A55GYP6Z.js} +16 -16
  108. package/dist/{skills-7E7IRB3R.js → skills-ALC5J6AT.js} +19 -19
  109. package/dist/{skills-eval-LI75W6OK.js → skills-eval-JPBEBYQU.js} +52 -47
  110. package/dist/support-MIETYA5E.js +38 -0
  111. package/dist/{targets-4CIFKCTW.js → targets-VGNXIR3S.js} +42 -33
  112. package/dist/{terminal-lease-WUZY7ZV5.js → terminal-lease-WOBR64YA.js} +3 -3
  113. package/dist/{uninstall-7FV7IP4E.js → uninstall-ZJF5H5ZN.js} +8 -8
  114. package/dist/{upgrade-K2HVIVMQ.js → upgrade-FUSUAGHR.js} +27 -25
  115. package/dist/{usage-GTZELZQX.js → usage-N4MKVHKD.js} +51 -46
  116. package/dist/{verifiers-RLAHT27O.js → verifiers-YAWOJ3H2.js} +13 -13
  117. package/dist/{verify-BX3BRKH5.js → verify-LTDHYBGY.js} +9 -9
  118. package/dist/{wiki-generate-ASIFASCN.js → wiki-generate-6M7GHTBJ.js} +66 -61
  119. package/dist/worker/entry.js +68 -61
  120. package/docs/alcf-provider.md +1 -1
  121. package/docs/architecture.md +1 -1
  122. package/docs/artifact-versions.md +6 -5
  123. package/docs/built-in-agents.md +1 -1
  124. package/docs/commands-and-modes.md +2 -2
  125. package/docs/configuration-and-targets.md +8 -3
  126. package/docs/context-engine.md +1 -1
  127. package/docs/documentation-guide.md +1 -1
  128. package/docs/eval-runner.md +1 -1
  129. package/docs/evals-internal.md +1 -1
  130. package/docs/evidence-and-memory.md +70 -6
  131. package/docs/evolution.md +1 -1
  132. package/docs/extensions-and-sharing.md +1 -1
  133. package/docs/fleet-dispatch.md +34 -9
  134. package/docs/glossary.md +21 -1
  135. package/docs/installation-and-lifecycle.md +1 -1
  136. package/docs/middleware-and-components.md +1 -1
  137. package/docs/model-catalog.md +1 -1
  138. package/docs/observability.md +2 -2
  139. package/docs/proactive-memory.md +1 -1
  140. package/docs/prompt-envelope-and-tools.md +4 -2
  141. package/docs/provider-adapter-cookbook.md +1 -1
  142. package/docs/release-cut-checklist.md +41 -38
  143. package/docs/safety-model.md +1 -1
  144. package/docs/scientific-validation.md +1 -1
  145. package/docs/skills-marketplace.md +1 -1
  146. package/docs/tool-usage.md +1 -1
  147. package/docs/trace-store.md +1 -1
  148. package/docs/tui-design.md +1 -1
  149. package/docs/worker-dispatch-mechanics.md +1 -1
  150. package/package.json +1 -2
  151. package/src/cli/argv.ts +5 -0
  152. package/src/cli/configure.ts +107 -23
  153. package/src/cli/doctor.ts +5 -1
  154. package/src/cli/evidence.ts +30 -25
  155. package/src/cli/fleet-preflight.ts +2 -12
  156. package/src/cli/shared.ts +1 -0
  157. package/src/cli/targets.ts +4 -1
  158. package/src/cli/validate-model.ts +60 -5
  159. package/src/core/bus-events.ts +25 -0
  160. package/src/core/commit-attribution.ts +4 -4
  161. package/src/core/path-boundary.ts +100 -0
  162. package/src/domains/agents/extension.ts +2 -11
  163. package/src/domains/agents/fleet-contract.ts +30 -12
  164. package/src/domains/agents/recipe.ts +7 -1
  165. package/src/domains/agents/registry.ts +73 -5
  166. package/src/domains/agents/result-contract.ts +128 -17
  167. package/src/domains/agents/write-boundary.ts +15 -50
  168. package/src/domains/context/project-rules.ts +51 -1
  169. package/src/domains/dispatch/assignment-reconcile.ts +22 -5
  170. package/src/domains/dispatch/assignment-store.ts +151 -14
  171. package/src/domains/dispatch/contract.ts +15 -1
  172. package/src/domains/dispatch/delegation-plan.ts +2 -5
  173. package/src/domains/dispatch/execution-role.ts +9 -1
  174. package/src/domains/dispatch/extension.ts +156 -67
  175. package/src/domains/dispatch/fleet-run.ts +57 -3
  176. package/src/domains/dispatch/gate-role-prompts.ts +38 -0
  177. package/src/domains/dispatch/index.ts +3 -1
  178. package/src/domains/dispatch/intent-requirements.ts +40 -0
  179. package/src/domains/dispatch/intent.ts +84 -8
  180. package/src/domains/dispatch/path-scope.ts +370 -0
  181. package/src/domains/dispatch/receipt-integrity.ts +2 -1
  182. package/src/domains/dispatch/types.ts +14 -7
  183. package/src/domains/dispatch/validation.ts +6 -3
  184. package/src/domains/dispatch/write-boundary-enforcer.ts +45 -0
  185. package/src/domains/dispatch/write-boundary.ts +201 -22
  186. package/src/domains/eval/metrics/evidence.ts +79 -2
  187. package/src/domains/eval/runners/clio-run.ts +12 -2
  188. package/src/domains/evidence/build.ts +69 -11
  189. package/src/domains/evidence/index.ts +21 -0
  190. package/src/domains/evidence/provenance.ts +46 -11
  191. package/src/domains/evidence/trust-projection.ts +274 -0
  192. package/src/domains/evidence/trust-status.ts +145 -17
  193. package/src/domains/evidence/types.ts +4 -0
  194. package/src/domains/extensions/discovery.ts +88 -1
  195. package/src/domains/extensions/resources.ts +20 -8
  196. package/src/domains/extensions/state.ts +6 -2
  197. package/src/domains/extensions/types.ts +4 -1
  198. package/src/domains/lifecycle/doctor.ts +140 -1
  199. package/src/domains/prompts/contract.ts +3 -5
  200. package/src/domains/providers/extension.ts +30 -2
  201. package/src/domains/resources/common-loader.ts +3 -0
  202. package/src/domains/resources/prompts/loader.ts +119 -14
  203. package/src/domains/safety/policy-engine.ts +5 -5
  204. package/src/domains/safety/run-effects.ts +64 -1
  205. package/src/domains/safety/scope.ts +7 -12
  206. package/src/engine/acp/server.ts +4 -1
  207. package/src/engine/prompt-templates.ts +18 -1
  208. package/src/engine/worker-runtime.ts +6 -3
  209. package/src/interactive/dispatch-board.ts +53 -3
  210. package/src/interactive/interactive-event-projection.ts +14 -0
  211. package/src/interactive/overlays/settings.ts +141 -47
  212. package/src/interactive/slash-commands.ts +7 -2
  213. package/src/interactive/view/artifacts.ts +42 -9
  214. package/src/interactive/view/view-overlay.ts +15 -3
  215. package/src/interactive/worker-receipts.ts +14 -2
  216. package/src/interactive/worker-stream.ts +8 -0
  217. package/src/tools/dispatch-admission.ts +12 -13
  218. package/src/tools/dispatch-arguments.ts +27 -0
  219. package/src/tools/dispatch-plan.ts +29 -0
  220. package/src/tools/dispatch-runner.ts +48 -13
  221. package/src/tools/monitor.ts +13 -0
  222. package/src/tools/worker-evidence.ts +19 -13
  223. package/src/worker/spec-contract.ts +2 -1
@@ -3,23 +3,23 @@ import {
3
3
  ROUTE_POLICY_VERSION,
4
4
  isRouteDecisionAgentSelection,
5
5
  isRoutingIntent
6
- } from "./chunk-5C77SEEY.js";
6
+ } from "./chunk-P43ETTHK.js";
7
7
  import {
8
8
  isExecutionRole
9
- } from "./chunk-UND3GU2L.js";
9
+ } from "./chunk-H7IXIC72.js";
10
10
  import {
11
11
  assertSafeId
12
12
  } from "./chunk-R346GLFC.js";
13
+ import {
14
+ readClioVersion,
15
+ resolvePackageRoot
16
+ } from "./chunk-IWHMRKLL.js";
13
17
  import {
14
18
  require_dist
15
19
  } from "./chunk-APJ265NV.js";
16
20
  import {
17
21
  safeResourceWrite
18
22
  } from "./chunk-WEPFGWHJ.js";
19
- import {
20
- readClioVersion,
21
- resolvePackageRoot
22
- } from "./chunk-IWHMRKLL.js";
23
23
  import {
24
24
  __toESM,
25
25
  init_esm_shims
@@ -28,7 +28,7 @@ import {
28
28
  // src/domains/dispatch/receipt-integrity.ts
29
29
  init_esm_shims();
30
30
  import { createHash } from "node:crypto";
31
- var RUN_RECEIPT_INTEGRITY_VERSION = 19;
31
+ var RUN_RECEIPT_INTEGRITY_VERSION = 20;
32
32
  var RUN_RECEIPT_INTEGRITY_ALGORITHM = "sha256";
33
33
  function sha256(input) {
34
34
  return createHash("sha256").update(input, "utf8").digest("hex");
@@ -82,6 +82,7 @@ var RECEIPT_INTEGRITY_FIELD_COVERAGE = {
82
82
  requestOrigin: true,
83
83
  task: true,
84
84
  intent: true,
85
+ pathScope: true,
85
86
  // Historical receipts omit this field, so their receipt and ledger payloads remain unchanged.
86
87
  budget: true,
87
88
  targetId: true,
@@ -869,6 +870,574 @@ function readArray2(record, source, field) {
869
870
  return value;
870
871
  }
871
872
 
873
+ // src/domains/evidence/trust-status.ts
874
+ init_esm_shims();
875
+ var TRUST_STATUS_VERSION = 1;
876
+ var TRUST_STATUS_MAX_ARTIFACT_REFERENCES = 16;
877
+ var TRUST_STATUS_MAX_IDENTIFIER_LENGTH = 512;
878
+ var TRUST_STATUS_AXES = [
879
+ "artifactIntegrity",
880
+ "validationGrounding",
881
+ "independentReview",
882
+ "contextProvenance",
883
+ "autonomyEnforcement",
884
+ "completionEvidence"
885
+ ];
886
+ var TRUST_STATUS_STATES = {
887
+ artifactIntegrity: ["verified", "failed", "absent", "unknown", "not_applicable"],
888
+ validationGrounding: ["validated", "failed", "ungrounded", "absent", "unknown", "not_applicable"],
889
+ independentReview: ["passed", "failed", "inconclusive", "not_independent", "absent", "unknown", "not_applicable"],
890
+ contextProvenance: ["recorded", "invalid", "absent", "unknown", "not_applicable"],
891
+ autonomyEnforcement: ["enforced", "approximated", "bypassed", "absent", "unknown", "not_applicable"],
892
+ completionEvidence: ["evidenced", "incomplete", "limited", "absent", "unknown", "not_applicable"]
893
+ };
894
+ var SELF_REPORTED_ARTIFACT_KINDS = /* @__PURE__ */ new Set([
895
+ "finish_contract_evidence",
896
+ "run_receipt"
897
+ ]);
898
+ var AXIS_STATES = {
899
+ artifactIntegrity: new Set(TRUST_STATUS_STATES.artifactIntegrity),
900
+ validationGrounding: new Set(TRUST_STATUS_STATES.validationGrounding),
901
+ independentReview: new Set(TRUST_STATUS_STATES.independentReview),
902
+ contextProvenance: new Set(TRUST_STATUS_STATES.contextProvenance),
903
+ autonomyEnforcement: new Set(TRUST_STATUS_STATES.autonomyEnforcement),
904
+ completionEvidence: new Set(TRUST_STATUS_STATES.completionEvidence)
905
+ };
906
+ var AXIS_SOURCES = {
907
+ artifactIntegrity: /* @__PURE__ */ new Set(["receipt_integrity_verification", "compatibility"]),
908
+ validationGrounding: /* @__PURE__ */ new Set(["run_receipt", "evidence_bundle", "compatibility"]),
909
+ independentReview: /* @__PURE__ */ new Set(["gate_decision", "compatibility"]),
910
+ contextProvenance: /* @__PURE__ */ new Set(["run_receipt", "evidence_bundle", "compatibility"]),
911
+ autonomyEnforcement: /* @__PURE__ */ new Set(["run_receipt", "compatibility"]),
912
+ completionEvidence: /* @__PURE__ */ new Set(["finish_contract", "compatibility"])
913
+ };
914
+ var SOURCE_AUTHORITIES = {
915
+ receipt_integrity_verification: /* @__PURE__ */ new Set(["clio"]),
916
+ run_receipt: /* @__PURE__ */ new Set(["clio", "validator", "runtime", "external_system", "unknown"]),
917
+ gate_decision: /* @__PURE__ */ new Set(["clio", "reviewer", "operator", "unknown"]),
918
+ evidence_bundle: /* @__PURE__ */ new Set(["clio"]),
919
+ finish_contract: /* @__PURE__ */ new Set(["clio"]),
920
+ compatibility: /* @__PURE__ */ new Set(["clio", "unknown"])
921
+ };
922
+ var ABSENCE_REASONS = /* @__PURE__ */ new Set([
923
+ "not_recorded",
924
+ "not_observed",
925
+ "artifact_missing",
926
+ "historical_format"
927
+ ]);
928
+ var SOURCE_KINDS = /* @__PURE__ */ new Set([
929
+ "receipt_integrity_verification",
930
+ "run_receipt",
931
+ "gate_decision",
932
+ "evidence_bundle",
933
+ "finish_contract",
934
+ "compatibility"
935
+ ]);
936
+ var AUTHORITY_KINDS = /* @__PURE__ */ new Set([
937
+ "clio",
938
+ "validator",
939
+ "reviewer",
940
+ "operator",
941
+ "runtime",
942
+ "external_system",
943
+ "unknown"
944
+ ]);
945
+ var ARTIFACT_KINDS = /* @__PURE__ */ new Set([
946
+ "run_receipt",
947
+ "validation_result",
948
+ "gate_decision",
949
+ "briefing",
950
+ "project_context",
951
+ "autonomy_policy",
952
+ "finish_contract_evidence",
953
+ "evidence_bundle",
954
+ "session_entry"
955
+ ]);
956
+ function isRecord3(value) {
957
+ return typeof value === "object" && value !== null && !Array.isArray(value);
958
+ }
959
+ function hasExactKeys(value, keys) {
960
+ const expected = new Set(keys);
961
+ return Object.keys(value).length === expected.size && Object.keys(value).every((key) => expected.has(key));
962
+ }
963
+ function isTrustStatusIdentifier(value) {
964
+ if (typeof value !== "string" || value.trim().length === 0 || value.length > TRUST_STATUS_MAX_IDENTIFIER_LENGTH) {
965
+ return false;
966
+ }
967
+ for (const character of value) {
968
+ const codePoint = character.codePointAt(0);
969
+ if (codePoint !== void 0 && (codePoint < 32 || codePoint === 127)) return false;
970
+ }
971
+ return true;
972
+ }
973
+ function compareArtifactReferences(left, right) {
974
+ const leftKey = `${left.kind}\0${left.id}\0${left.digest?.value ?? ""}`;
975
+ const rightKey = `${right.kind}\0${right.id}\0${right.digest?.value ?? ""}`;
976
+ return leftKey < rightKey ? -1 : leftKey > rightKey ? 1 : 0;
977
+ }
978
+ function normalizeArtifactReference(value, path) {
979
+ if (!isRecord3(value)) throw new Error(`${path} must be an object`);
980
+ if (!hasExactKeys(value, value.digest === void 0 ? ["kind", "id"] : ["kind", "id", "digest"])) {
981
+ throw new Error(`${path} has unknown or missing fields`);
982
+ }
983
+ if (typeof value.kind !== "string" || !ARTIFACT_KINDS.has(value.kind)) {
984
+ throw new Error(`${path}.kind is invalid`);
985
+ }
986
+ if (!isTrustStatusIdentifier(value.id)) throw new Error(`${path}.id is invalid`);
987
+ const reference = { kind: value.kind, id: value.id };
988
+ if (value.digest !== void 0) {
989
+ if (!isRecord3(value.digest) || !hasExactKeys(value.digest, ["algorithm", "value"]) || value.digest.algorithm !== "sha256" || typeof value.digest.value !== "string" || !/^[a-f0-9]{64}$/u.test(value.digest.value)) {
990
+ throw new Error(`${path}.digest is invalid`);
991
+ }
992
+ reference.digest = { algorithm: "sha256", value: value.digest.value };
993
+ }
994
+ return reference;
995
+ }
996
+ function normalizeAttributedStatus(axis, value) {
997
+ if (!hasExactKeys(value, ["state", "source", "authority", "artifacts"])) {
998
+ throw new Error(`${axis} has unknown or missing fields`);
999
+ }
1000
+ if (!isRecord3(value.source) || !hasExactKeys(value.source, ["kind", "id"])) {
1001
+ throw new Error(`${axis}.source is invalid`);
1002
+ }
1003
+ if (typeof value.source.kind !== "string" || !SOURCE_KINDS.has(value.source.kind) || !AXIS_SOURCES[axis].has(value.source.kind) || !isTrustStatusIdentifier(value.source.id)) {
1004
+ throw new Error(`${axis}.source is invalid`);
1005
+ }
1006
+ if (!isRecord3(value.authority) || !hasExactKeys(value.authority, ["kind", "id"])) {
1007
+ throw new Error(`${axis}.authority is invalid`);
1008
+ }
1009
+ if (typeof value.authority.kind !== "string" || !AUTHORITY_KINDS.has(value.authority.kind) || !SOURCE_AUTHORITIES[value.source.kind].has(
1010
+ value.authority.kind
1011
+ ) || !isTrustStatusIdentifier(value.authority.id)) {
1012
+ throw new Error(`${axis}.authority is invalid`);
1013
+ }
1014
+ if (value.source.kind === "compatibility" && value.state !== "unknown" && value.state !== "not_applicable") {
1015
+ throw new Error(`${axis} compatibility source cannot establish ${value.state}`);
1016
+ }
1017
+ if (!Array.isArray(value.artifacts) || value.artifacts.length > TRUST_STATUS_MAX_ARTIFACT_REFERENCES) {
1018
+ throw new Error(`${axis}.artifacts exceeds the bounded reference list`);
1019
+ }
1020
+ const artifacts = value.artifacts.map(
1021
+ (entry, index) => normalizeArtifactReference(entry, `${axis}.artifacts[${index}]`)
1022
+ );
1023
+ artifacts.sort(compareArtifactReferences);
1024
+ for (let index = 1; index < artifacts.length; index += 1) {
1025
+ if (compareArtifactReferences(
1026
+ artifacts[index - 1],
1027
+ artifacts[index]
1028
+ ) === 0) {
1029
+ throw new Error(`${axis}.artifacts contains a duplicate reference`);
1030
+ }
1031
+ }
1032
+ return {
1033
+ state: value.state,
1034
+ source: { kind: value.source.kind, id: value.source.id },
1035
+ authority: { kind: value.authority.kind, id: value.authority.id },
1036
+ artifacts
1037
+ };
1038
+ }
1039
+ function normalizeAxis(axis, value) {
1040
+ if (!isRecord3(value) || typeof value.state !== "string" || !AXIS_STATES[axis].has(value.state)) {
1041
+ throw new Error(`${axis}.state is invalid`);
1042
+ }
1043
+ if (value.state === "absent") {
1044
+ if (!hasExactKeys(value, ["state", "reason"]) || typeof value.reason !== "string" || !ABSENCE_REASONS.has(value.reason)) {
1045
+ throw new Error(`${axis} absent state is invalid`);
1046
+ }
1047
+ return { state: "absent", reason: value.reason };
1048
+ }
1049
+ return normalizeAttributedStatus(axis, value);
1050
+ }
1051
+ function normalizeTrustStatus(value) {
1052
+ if (!isRecord3(value) || !hasExactKeys(value, ["version", ...TRUST_STATUS_AXES])) {
1053
+ throw new Error("trust status has unknown or missing fields");
1054
+ }
1055
+ if (value.version !== TRUST_STATUS_VERSION) throw new Error("trust status version is invalid");
1056
+ return {
1057
+ version: TRUST_STATUS_VERSION,
1058
+ artifactIntegrity: normalizeAxis("artifactIntegrity", value.artifactIntegrity),
1059
+ validationGrounding: normalizeAxis("validationGrounding", value.validationGrounding),
1060
+ independentReview: normalizeAxis("independentReview", value.independentReview),
1061
+ contextProvenance: normalizeAxis("contextProvenance", value.contextProvenance),
1062
+ autonomyEnforcement: normalizeAxis("autonomyEnforcement", value.autonomyEnforcement),
1063
+ completionEvidence: normalizeAxis("completionEvidence", value.completionEvidence)
1064
+ };
1065
+ }
1066
+ function absentTrustStatus(reason) {
1067
+ return { state: "absent", reason };
1068
+ }
1069
+ function composeTrustStatus(...projections) {
1070
+ const axes = {
1071
+ artifactIntegrity: absentTrustStatus("not_recorded"),
1072
+ validationGrounding: absentTrustStatus("not_recorded"),
1073
+ independentReview: absentTrustStatus("not_recorded"),
1074
+ contextProvenance: absentTrustStatus("not_recorded"),
1075
+ autonomyEnforcement: absentTrustStatus("not_recorded"),
1076
+ completionEvidence: absentTrustStatus("not_recorded")
1077
+ };
1078
+ for (const projection of projections) {
1079
+ if (projection.artifactIntegrity !== void 0) axes.artifactIntegrity = projection.artifactIntegrity;
1080
+ if (projection.validationGrounding !== void 0) axes.validationGrounding = projection.validationGrounding;
1081
+ if (projection.independentReview !== void 0) axes.independentReview = projection.independentReview;
1082
+ if (projection.contextProvenance !== void 0) axes.contextProvenance = projection.contextProvenance;
1083
+ if (projection.autonomyEnforcement !== void 0) axes.autonomyEnforcement = projection.autonomyEnforcement;
1084
+ if (projection.completionEvidence !== void 0) axes.completionEvidence = projection.completionEvidence;
1085
+ }
1086
+ return normalizeTrustStatus({ version: TRUST_STATUS_VERSION, ...axes });
1087
+ }
1088
+ function sha256Reference(kind, id, digest) {
1089
+ const reference = { kind, id };
1090
+ if (digest !== void 0 && /^[a-f0-9]{64}$/u.test(digest)) {
1091
+ reference.digest = { algorithm: "sha256", value: digest };
1092
+ }
1093
+ return reference;
1094
+ }
1095
+ function receiptReference(receipt) {
1096
+ return sha256Reference("run_receipt", receipt.runId, receipt.integrity?.digest);
1097
+ }
1098
+ function attributed(state, source, authority, artifacts) {
1099
+ return { state, source, authority, artifacts: [...artifacts].sort(compareArtifactReferences) };
1100
+ }
1101
+ function receiptSource(receipt) {
1102
+ return { kind: "run_receipt", id: receipt.runId };
1103
+ }
1104
+ function compatibilitySource(receipt, field) {
1105
+ return { kind: "compatibility", id: `run_receipt:${receipt.runId}:${field}` };
1106
+ }
1107
+ var DISPATCH_AUTHORITY = { kind: "clio", id: "dispatch" };
1108
+ var COMPATIBILITY_AUTHORITY = { kind: "unknown", id: "historical-persisted-format" };
1109
+ function retiredReceiptIntegrity(integrity) {
1110
+ if (!isRecord3(integrity)) return null;
1111
+ const version = integrity.version;
1112
+ if (typeof version !== "number" || !Number.isInteger(version) || version < 1) return null;
1113
+ if (version >= RUN_RECEIPT_INTEGRITY_VERSION) return null;
1114
+ return { receiptVersion: version, supportedVersion: RUN_RECEIPT_INTEGRITY_VERSION };
1115
+ }
1116
+ function retiredReceiptIntegrityReason(retired) {
1117
+ return `receipt integrity v${retired.receiptVersion} is retired; this build verifies v${retired.supportedVersion}; the receipt is not read as evidence`;
1118
+ }
1119
+ function verifyReceiptIntegrityOutcome(receipt, envelope) {
1120
+ const retired = retiredReceiptIntegrity(receipt.integrity);
1121
+ if (retired !== null) return { ok: false, reason: retiredReceiptIntegrityReason(retired), retired };
1122
+ return verifyReceiptIntegrity(receipt, envelope);
1123
+ }
1124
+ var RETIRED_INTEGRITY_SOURCE = /:integrity-v(\d+)-retired$/u;
1125
+ function retiredIntegritySourceId(runId, receiptVersion) {
1126
+ return `run_receipt:${runId}:integrity-v${receiptVersion}-retired`;
1127
+ }
1128
+ function retiredIntegrityVersionOf(status) {
1129
+ if (status.state !== "unknown" || status.source.kind !== "compatibility") return null;
1130
+ const match = RETIRED_INTEGRITY_SOURCE.exec(status.source.id);
1131
+ return match === null ? null : Number(match[1]);
1132
+ }
1133
+ function adaptReceiptIntegrityStatus(receipt, verification) {
1134
+ if (receipt === null || receipt === void 0) return absentTrustStatus("artifact_missing");
1135
+ const artifacts = [receiptReference(receipt)];
1136
+ if (verification !== void 0 && !verification.ok && verification.retired !== void 0) {
1137
+ return attributed(
1138
+ "unknown",
1139
+ { kind: "compatibility", id: retiredIntegritySourceId(receipt.runId, verification.retired.receiptVersion) },
1140
+ COMPATIBILITY_AUTHORITY,
1141
+ artifacts
1142
+ );
1143
+ }
1144
+ if (verification === void 0 || verification.ok && receipt.integrity === void 0) {
1145
+ return attributed(
1146
+ "unknown",
1147
+ {
1148
+ kind: "compatibility",
1149
+ id: `run_receipt:${receipt.runId}:${receipt.integrity === void 0 ? "integrity-missing" : "integrity-unchecked"}`
1150
+ },
1151
+ COMPATIBILITY_AUTHORITY,
1152
+ artifacts
1153
+ );
1154
+ }
1155
+ return attributed(
1156
+ verification.ok ? "verified" : "failed",
1157
+ { kind: "receipt_integrity_verification", id: receipt.runId },
1158
+ { kind: "clio", id: "receipt-integrity" },
1159
+ artifacts
1160
+ );
1161
+ }
1162
+ function validationArtifacts(receipt) {
1163
+ const artifacts = [receiptReference(receipt)];
1164
+ for (const fact of receipt.quality?.typedValidations ?? []) {
1165
+ artifacts.push(sha256Reference("validation_result", fact.sourceId, fact.validatorDigest));
1166
+ }
1167
+ const resultContract = receipt.quality?.resultContract;
1168
+ if (resultContract !== null && resultContract !== void 0) {
1169
+ artifacts.push(sha256Reference("validation_result", resultContract.sourceId, resultContract.validatorDigest));
1170
+ }
1171
+ return uniqueBoundedReferences(artifacts);
1172
+ }
1173
+ function qualityHasFailure(quality) {
1174
+ if (quality === void 0) return false;
1175
+ if (quality.typedValidations.some((fact) => !fact.passed)) return true;
1176
+ return quality.resultContract?.conformance === "fail" || quality.resultContract?.quality === "fail";
1177
+ }
1178
+ function qualityHasValidation(quality) {
1179
+ if (quality === void 0) return false;
1180
+ if (quality.typedValidations.some((fact) => fact.passed)) return true;
1181
+ return quality.resultContract?.quality === "pass";
1182
+ }
1183
+ function verificationStatus(verification, receipt, artifacts) {
1184
+ if (verification.state === "verified") {
1185
+ return attributed("validated", receiptSource(receipt), { kind: "validator", id: verification.basis }, artifacts);
1186
+ }
1187
+ if (verification.state === "unverified") return absentTrustStatus("not_observed");
1188
+ if (verification.state === "not_applicable") {
1189
+ return attributed("not_applicable", receiptSource(receipt), DISPATCH_AUTHORITY, artifacts);
1190
+ }
1191
+ return attributed(
1192
+ "unknown",
1193
+ receiptSource(receipt),
1194
+ verification.basis === "acp-external-unobserved" ? { kind: "external_system", id: "acp-delegation" } : COMPATIBILITY_AUTHORITY,
1195
+ artifacts
1196
+ );
1197
+ }
1198
+ function adaptRunReceiptValidationStatus(receipt) {
1199
+ if (receipt === null || receipt === void 0) return absentTrustStatus("artifact_missing");
1200
+ const artifacts = validationArtifacts(receipt);
1201
+ if (receipt.hostVerification?.status === "rejected") {
1202
+ return attributed("failed", receiptSource(receipt), { kind: "validator", id: "host-verification" }, artifacts);
1203
+ }
1204
+ if (receipt.hostVerification?.status === "verified") {
1205
+ return attributed("validated", receiptSource(receipt), { kind: "validator", id: "host-verification" }, artifacts);
1206
+ }
1207
+ if (qualityHasFailure(receipt.quality)) {
1208
+ return attributed("failed", receiptSource(receipt), { kind: "validator", id: "receipt-quality" }, artifacts);
1209
+ }
1210
+ if ((receipt.validationGrounding?.ungrounded.length ?? 0) > 0 || receipt.validationGrounding !== void 0 && receipt.validationGrounding.claimed > receipt.validationGrounding.grounded) {
1211
+ return attributed("ungrounded", receiptSource(receipt), { kind: "validator", id: "command-grounding" }, artifacts);
1212
+ }
1213
+ if (qualityHasValidation(receipt.quality)) {
1214
+ return attributed("validated", receiptSource(receipt), { kind: "validator", id: "receipt-quality" }, artifacts);
1215
+ }
1216
+ if (receipt.verification !== void 0) {
1217
+ return verificationStatus(receipt.verification, receipt, artifacts);
1218
+ }
1219
+ return attributed("unknown", compatibilitySource(receipt, "verification"), COMPATIBILITY_AUTHORITY, artifacts);
1220
+ }
1221
+ function validBriefing(briefing) {
1222
+ return Number.isSafeInteger(briefing.bytes) && briefing.bytes >= 0 && /^[a-f0-9]{64}$/u.test(briefing.contentHash);
1223
+ }
1224
+ function validBoundedProjectContext(context) {
1225
+ return context.tier === "bounded" && Number.isSafeInteger(context.chars) && (context.chars ?? -1) >= 0 && typeof context.contentHash === "string" && /^[a-f0-9]{64}$/u.test(context.contentHash);
1226
+ }
1227
+ var NONE_TIER_SECTIONS = ["workspace-root"];
1228
+ function validNoneTierProjectContext(context) {
1229
+ return context.tier === "none" && context.sections !== void 0 && context.sections.length === NONE_TIER_SECTIONS.length && context.sections.every((section) => NONE_TIER_SECTIONS.includes(section)) && Number.isSafeInteger(context.chars) && (context.chars ?? -1) >= 0 && typeof context.contentHash === "string" && /^[a-f0-9]{64}$/u.test(context.contentHash);
1230
+ }
1231
+ function recordedProjectContextHash(context) {
1232
+ if (context === void 0) return void 0;
1233
+ if (context.tier === "bounded") return validBoundedProjectContext(context) ? context.contentHash : void 0;
1234
+ return validNoneTierProjectContext(context) ? context.contentHash : void 0;
1235
+ }
1236
+ function contextArtifacts(receipt) {
1237
+ const artifacts = [receiptReference(receipt)];
1238
+ if (receipt.briefing !== void 0 && validBriefing(receipt.briefing)) {
1239
+ artifacts.push(sha256Reference("briefing", `${receipt.runId}:briefing`, receipt.briefing.contentHash));
1240
+ }
1241
+ const recordedHash = recordedProjectContextHash(receipt.projectContext);
1242
+ if (recordedHash !== void 0) {
1243
+ artifacts.push(sha256Reference("project_context", `${receipt.runId}:project-context`, recordedHash));
1244
+ }
1245
+ return uniqueBoundedReferences(artifacts);
1246
+ }
1247
+ function adaptRunReceiptContextStatus(receipt) {
1248
+ if (receipt === null || receipt === void 0) return absentTrustStatus("artifact_missing");
1249
+ const artifacts = contextArtifacts(receipt);
1250
+ const source = receiptSource(receipt);
1251
+ const briefingInvalid = receipt.briefing !== void 0 && !validBriefing(receipt.briefing);
1252
+ if (briefingInvalid) return attributed("invalid", source, DISPATCH_AUTHORITY, artifacts);
1253
+ const context = receipt.projectContext;
1254
+ if (context === void 0) {
1255
+ if (receipt.briefing !== void 0) return attributed("recorded", source, DISPATCH_AUTHORITY, artifacts);
1256
+ return attributed("unknown", compatibilitySource(receipt, "projectContext"), COMPATIBILITY_AUTHORITY, artifacts);
1257
+ }
1258
+ if (context.tier === "none") {
1259
+ const bare = context.chars === void 0 && context.contentHash === void 0 && context.sections === void 0;
1260
+ if (bare) {
1261
+ return receipt.briefing === void 0 ? attributed("not_applicable", source, DISPATCH_AUTHORITY, artifacts) : attributed("recorded", source, DISPATCH_AUTHORITY, artifacts);
1262
+ }
1263
+ return attributed(
1264
+ validNoneTierProjectContext(context) ? "recorded" : "invalid",
1265
+ source,
1266
+ DISPATCH_AUTHORITY,
1267
+ artifacts
1268
+ );
1269
+ }
1270
+ return attributed(validBoundedProjectContext(context) ? "recorded" : "invalid", source, DISPATCH_AUTHORITY, artifacts);
1271
+ }
1272
+ function adaptRunReceiptAutonomyStatus(receipt) {
1273
+ if (receipt === null || receipt === void 0) return absentTrustStatus("artifact_missing");
1274
+ const enforcement = receipt.autonomyEnforcement;
1275
+ const artifacts = [receiptReference(receipt)];
1276
+ if (enforcement === void 0) {
1277
+ return attributed("unknown", compatibilitySource(receipt, "autonomyEnforcement"), COMPATIBILITY_AUTHORITY, artifacts);
1278
+ }
1279
+ artifacts.push({ kind: "autonomy_policy", id: `${receipt.runId}:${enforcement.autonomy}` });
1280
+ const authority = enforcement.grade === "mediated" ? { kind: "clio", id: "safety-autonomy" } : { kind: "runtime", id: enforcement.externalMode ?? "external-runtime" };
1281
+ const state = enforcement.dangerousBypass === true || enforcement.grade === "bypassed" ? "bypassed" : enforcement.grade === "approximated" ? "approximated" : "enforced";
1282
+ return attributed(state, receiptSource(receipt), authority, artifacts);
1283
+ }
1284
+ function receiptClaimsAreAuthenticated(receipt, integrity) {
1285
+ return receipt?.integrity !== void 0 && integrity?.ok === true;
1286
+ }
1287
+ function unauthenticatedReceiptProjection(receipt, integrity) {
1288
+ if (receipt === null || receipt === void 0) {
1289
+ return {
1290
+ validationGrounding: absentTrustStatus("artifact_missing"),
1291
+ contextProvenance: absentTrustStatus("artifact_missing"),
1292
+ autonomyEnforcement: absentTrustStatus("artifact_missing")
1293
+ };
1294
+ }
1295
+ if (receipt.integrity === void 0) {
1296
+ const artifacts = [receiptReference(receipt)];
1297
+ return {
1298
+ validationGrounding: attributed(
1299
+ "unknown",
1300
+ compatibilitySource(receipt, "canonical-projection"),
1301
+ COMPATIBILITY_AUTHORITY,
1302
+ artifacts
1303
+ ),
1304
+ contextProvenance: attributed(
1305
+ "unknown",
1306
+ compatibilitySource(receipt, "canonical-projection"),
1307
+ COMPATIBILITY_AUTHORITY,
1308
+ artifacts
1309
+ ),
1310
+ autonomyEnforcement: attributed(
1311
+ "unknown",
1312
+ compatibilitySource(receipt, "canonical-projection"),
1313
+ COMPATIBILITY_AUTHORITY,
1314
+ artifacts
1315
+ )
1316
+ };
1317
+ }
1318
+ if (integrity !== void 0 && !integrity.ok && integrity.retired !== void 0) {
1319
+ return {
1320
+ validationGrounding: absentTrustStatus("historical_format"),
1321
+ contextProvenance: absentTrustStatus("historical_format"),
1322
+ autonomyEnforcement: absentTrustStatus("historical_format")
1323
+ };
1324
+ }
1325
+ return {
1326
+ validationGrounding: absentTrustStatus("not_observed"),
1327
+ contextProvenance: absentTrustStatus("not_observed"),
1328
+ autonomyEnforcement: absentTrustStatus("not_observed")
1329
+ };
1330
+ }
1331
+ function adaptRunReceiptTrustStatus(receipt, options = {}) {
1332
+ const authenticated = receiptClaimsAreAuthenticated(receipt, options.integrity);
1333
+ const receiptProjection = authenticated ? {
1334
+ validationGrounding: adaptRunReceiptValidationStatus(receipt),
1335
+ contextProvenance: adaptRunReceiptContextStatus(receipt),
1336
+ autonomyEnforcement: adaptRunReceiptAutonomyStatus(receipt)
1337
+ } : unauthenticatedReceiptProjection(receipt, options.integrity);
1338
+ return composeTrustStatus({
1339
+ artifactIntegrity: adaptReceiptIntegrityStatus(receipt, options.integrity),
1340
+ ...receiptProjection,
1341
+ independentReview: absentTrustStatus(receipt === null || receipt === void 0 ? "artifact_missing" : "not_recorded"),
1342
+ completionEvidence: absentTrustStatus(
1343
+ receipt === null || receipt === void 0 ? "artifact_missing" : "not_recorded"
1344
+ )
1345
+ });
1346
+ }
1347
+ function inspectRunReceiptTrustStatus(receipt, envelope) {
1348
+ let integrity;
1349
+ if (receipt === null || receipt === void 0) {
1350
+ integrity = { ok: false, reason: "receipt unavailable" };
1351
+ } else if (envelope === null || envelope === void 0) {
1352
+ integrity = { ok: false, reason: "run ledger envelope unavailable" };
1353
+ } else {
1354
+ try {
1355
+ integrity = verifyReceiptIntegrityOutcome(receipt, envelope);
1356
+ } catch (error) {
1357
+ integrity = {
1358
+ ok: false,
1359
+ reason: `receipt invalid: ${error instanceof Error ? error.message : String(error)}`
1360
+ };
1361
+ }
1362
+ }
1363
+ return {
1364
+ integrity,
1365
+ status: adaptRunReceiptTrustStatus(receipt, { integrity })
1366
+ };
1367
+ }
1368
+ function gateReference(artifact) {
1369
+ return sha256Reference("gate_decision", artifact.id, artifact.integrity.digest);
1370
+ }
1371
+ function gateAuthority(artifact) {
1372
+ if (artifact.outcome === "operator-confirmed") return { kind: "operator", id: "gate-confirmation" };
1373
+ if (artifact.outcome === "full-auto-applied") return { kind: "clio", id: "full-auto-gate-policy" };
1374
+ return { kind: "reviewer", id: artifact.decider?.runId ?? "unavailable-decider" };
1375
+ }
1376
+ function adaptGateDecisionReviewStatus(artifact, subjectRunId, verification) {
1377
+ if (artifact === null || artifact === void 0) return absentTrustStatus("artifact_missing");
1378
+ const source = { kind: "gate_decision", id: artifact.id };
1379
+ const artifacts = [gateReference(artifact)];
1380
+ const authority = gateAuthority(artifact);
1381
+ if (!artifact.subjects.some((subject) => subject.runId === subjectRunId)) return absentTrustStatus("not_recorded");
1382
+ if (verification === void 0 || !verification.ok) {
1383
+ return attributed(
1384
+ "unknown",
1385
+ source,
1386
+ verification === void 0 ? COMPATIBILITY_AUTHORITY : { kind: "unknown", id: "unauthenticated-gate-artifact" },
1387
+ artifacts
1388
+ );
1389
+ }
1390
+ if (artifact.decider === void 0 || artifact.correlation === void 0) {
1391
+ if (artifact.outcome === "operator-confirmed" || artifact.outcome === "full-auto-applied") {
1392
+ return attributed("not_applicable", source, authority, artifacts);
1393
+ }
1394
+ return attributed("inconclusive", source, authority, artifacts);
1395
+ }
1396
+ if (!artifact.correlation.independent) return attributed("not_independent", source, authority, artifacts);
1397
+ if (artifact.outcome === "pass") return attributed("passed", source, authority, artifacts);
1398
+ if (artifact.outcome === "fail") return attributed("failed", source, authority, artifacts);
1399
+ if (artifact.outcome === "winner") {
1400
+ return attributed(
1401
+ artifact.winner?.subject.runId === subjectRunId ? "passed" : "failed",
1402
+ source,
1403
+ authority,
1404
+ artifacts
1405
+ );
1406
+ }
1407
+ return attributed("inconclusive", source, authority, artifacts);
1408
+ }
1409
+ function adaptGroundedEvidenceValidationStatus(input) {
1410
+ const observed = (input.artifacts ?? []).filter((artifact) => !SELF_REPORTED_ARTIFACT_KINDS.has(artifact.kind));
1411
+ if (observed.length === 0) return absentTrustStatus("not_observed");
1412
+ return attributed(
1413
+ "validated",
1414
+ { kind: "evidence_bundle", id: `${input.evidenceId}:${input.runId}` },
1415
+ { kind: "clio", id: "evidence-grounding" },
1416
+ uniqueBoundedReferences([{ kind: "evidence_bundle", id: input.evidenceId }, ...observed])
1417
+ );
1418
+ }
1419
+ function adaptFinishContractCompletionStatus(assessment, options = {}) {
1420
+ const artifacts = uniqueBoundedReferences(
1421
+ options.artifacts ?? assessment.evidence.map((evidence, index) => ({
1422
+ kind: evidence.turnId === void 0 ? "finish_contract_evidence" : "session_entry",
1423
+ id: evidence.turnId ?? `${evidence.kind}:${index + 1}`
1424
+ }))
1425
+ );
1426
+ const source = { kind: "finish_contract", id: options.sourceId ?? assessment.reason };
1427
+ const authority = { kind: "clio", id: "finish-contract" };
1428
+ if (assessment.reason === "no_mutation") return attributed("not_applicable", source, authority, artifacts);
1429
+ if (assessment.reason === "validation_evidence") return attributed("evidenced", source, authority, artifacts);
1430
+ if (assessment.reason === "explicit_limitation") return attributed("limited", source, authority, artifacts);
1431
+ return attributed("incomplete", source, authority, artifacts);
1432
+ }
1433
+ function uniqueBoundedReferences(references) {
1434
+ const sorted = [...references].sort(compareArtifactReferences);
1435
+ const unique = sorted.filter(
1436
+ (reference, index) => index === 0 || compareArtifactReferences(sorted[index - 1], reference) !== 0
1437
+ );
1438
+ return unique.slice(0, TRUST_STATUS_MAX_ARTIFACT_REFERENCES);
1439
+ }
1440
+
872
1441
  // src/domains/eval/provenance.ts
873
1442
  init_esm_shims();
874
1443
  import { spawnSync } from "node:child_process";
@@ -939,7 +1508,7 @@ function parseEvalTaskFileYaml(raw) {
939
1508
  }
940
1509
  function validateEvalTaskFile(value) {
941
1510
  const issues = [];
942
- if (!isRecord3(value)) {
1511
+ if (!isRecord4(value)) {
943
1512
  return { valid: false, issues: [{ path: "$", message: "expected object" }] };
944
1513
  }
945
1514
  if (value.version !== EVAL_TASK_FILE_VERSION) {
@@ -975,7 +1544,7 @@ var EvalTaskFileError = class extends Error {
975
1544
  }
976
1545
  };
977
1546
  function parseTask(value, path, issues) {
978
- if (!isRecord3(value)) {
1547
+ if (!isRecord4(value)) {
979
1548
  issues.push({ path, message: "expected object" });
980
1549
  return null;
981
1550
  }
@@ -1049,13 +1618,158 @@ function readPositiveInteger(record, path, field, issues) {
1049
1618
  }
1050
1619
  return value;
1051
1620
  }
1052
- function isRecord3(value) {
1621
+ function isRecord4(value) {
1053
1622
  return typeof value === "object" && value !== null && !Array.isArray(value);
1054
1623
  }
1055
1624
  function sha256Hex(content) {
1056
1625
  return createHash3("sha256").update(content, "utf8").digest("hex");
1057
1626
  }
1058
1627
 
1628
+ // src/domains/evidence/trust-projection.ts
1629
+ init_esm_shims();
1630
+ var TRUST_SUMMARY_VERSION = 1;
1631
+ var TRUST_SUMMARY_MAX_REFS = 8;
1632
+ var TRUST_STATE_WORDS = {
1633
+ artifactIntegrity: {
1634
+ verified: "sealed",
1635
+ failed: "seal broken",
1636
+ absent: "no receipt",
1637
+ unknown: "seal unchecked",
1638
+ not_applicable: "seal not applicable"
1639
+ },
1640
+ validationGrounding: {
1641
+ validated: "grounded",
1642
+ failed: "validation failed",
1643
+ ungrounded: "inferred: validation claimed, none observed",
1644
+ absent: "no validation observed",
1645
+ unknown: "validation unknown",
1646
+ not_applicable: "validation not applicable"
1647
+ },
1648
+ independentReview: {
1649
+ passed: "independently reviewed: pass",
1650
+ failed: "independently reviewed: fail",
1651
+ inconclusive: "independent review inconclusive",
1652
+ not_independent: "review not independent",
1653
+ absent: "not independently reviewed",
1654
+ unknown: "independent review unknown",
1655
+ not_applicable: "independent review not applicable"
1656
+ },
1657
+ contextProvenance: {
1658
+ recorded: "context recorded",
1659
+ invalid: "context record invalid",
1660
+ absent: "context not recorded",
1661
+ unknown: "context unknown",
1662
+ not_applicable: "context not applicable"
1663
+ },
1664
+ autonomyEnforcement: {
1665
+ enforced: "mediated",
1666
+ approximated: "approximated",
1667
+ bypassed: "bypassed",
1668
+ absent: "autonomy not recorded",
1669
+ unknown: "autonomy unknown",
1670
+ not_applicable: "autonomy not applicable"
1671
+ },
1672
+ completionEvidence: {
1673
+ evidenced: "completion evidenced",
1674
+ incomplete: "completion unevidenced",
1675
+ limited: "completion limited",
1676
+ absent: "completion not recorded",
1677
+ unknown: "completion unknown",
1678
+ not_applicable: "completion not applicable"
1679
+ }
1680
+ };
1681
+ function trustStateWord(axis, state) {
1682
+ const words = TRUST_STATE_WORDS[axis];
1683
+ return words[state] ?? words.unknown ?? "unknown";
1684
+ }
1685
+ function authorityOf(status, axis) {
1686
+ const entry = status[axis];
1687
+ return entry.state === "absent" ? null : `${entry.authority.kind}:${entry.authority.id}`;
1688
+ }
1689
+ function integrityClause(status) {
1690
+ const retired = retiredIntegrityVersionOf(status.artifactIntegrity);
1691
+ if (retired !== null) return `seal v${retired} retired (this build verifies v${RUN_RECEIPT_INTEGRITY_VERSION})`;
1692
+ return trustStateWord("artifactIntegrity", status.artifactIntegrity.state);
1693
+ }
1694
+ function validationClause(status) {
1695
+ const entry = status.validationGrounding;
1696
+ const word = trustStateWord("validationGrounding", entry.state);
1697
+ if (entry.state === "absent") return word;
1698
+ if (entry.state === "validated" || entry.state === "failed") return `${word} by ${entry.authority.id}`;
1699
+ if (entry.state === "unknown" && entry.authority.kind !== "unknown") return `${word} (${entry.authority.id})`;
1700
+ return word;
1701
+ }
1702
+ function autonomyClause(status) {
1703
+ const entry = status.autonomyEnforcement;
1704
+ const word = trustStateWord("autonomyEnforcement", entry.state);
1705
+ if (entry.state !== "approximated" && entry.state !== "bypassed") return word;
1706
+ return `${word} (${entry.authority.id})`;
1707
+ }
1708
+ function formatTrustSummary(status) {
1709
+ return [
1710
+ integrityClause(status),
1711
+ validationClause(status),
1712
+ trustStateWord("independentReview", status.independentReview.state),
1713
+ autonomyClause(status),
1714
+ trustStateWord("contextProvenance", status.contextProvenance.state),
1715
+ trustStateWord("completionEvidence", status.completionEvidence.state)
1716
+ ].join("; ");
1717
+ }
1718
+ function formatTrustSummaryLine(status) {
1719
+ return `trust v${TRUST_SUMMARY_VERSION}: ${formatTrustSummary(status)}`;
1720
+ }
1721
+ function formatTrustAxes(status) {
1722
+ return [`trust_status=v${status.version}`, ...TRUST_STATUS_AXES.map((axis) => `${axis}:${status[axis].state}`)].join(
1723
+ " "
1724
+ );
1725
+ }
1726
+ function isUnanswered(status, axis) {
1727
+ const state = status[axis].state;
1728
+ return state === "absent" || state === "unknown";
1729
+ }
1730
+ function trustVerdict(status) {
1731
+ const integrity = status.artifactIntegrity.state;
1732
+ const validation = status.validationGrounding.state;
1733
+ const review = status.independentReview.state;
1734
+ const autonomy = status.autonomyEnforcement.state;
1735
+ if (integrity === "failed" || autonomy === "bypassed" || validation === "failed" || validation === "ungrounded" || review === "failed" || review === "not_independent" || status.contextProvenance.state === "invalid") {
1736
+ return "compromised";
1737
+ }
1738
+ if (integrity !== "verified") return "unknown";
1739
+ if (review === "passed") return "reviewed";
1740
+ if (validation === "validated") return "grounded";
1741
+ return "unverified";
1742
+ }
1743
+ function claimantOf(status) {
1744
+ const state = status.validationGrounding.state;
1745
+ if (state === "absent" || state === "ungrounded") return "worker";
1746
+ return authorityOf(status, "validationGrounding") ?? "worker";
1747
+ }
1748
+ function referenceKey(reference) {
1749
+ return `${reference.kind}:${reference.id}`;
1750
+ }
1751
+ function trustSummaryReferences(status) {
1752
+ const keys = /* @__PURE__ */ new Set();
1753
+ for (const axis of TRUST_STATUS_AXES) {
1754
+ const entry = status[axis];
1755
+ if (entry.state === "absent") continue;
1756
+ for (const reference of entry.artifacts) keys.add(referenceKey(reference));
1757
+ }
1758
+ return [...keys].sort().slice(0, TRUST_SUMMARY_MAX_REFS);
1759
+ }
1760
+ function summarizeTrustStatus(status) {
1761
+ const axes = Object.fromEntries(TRUST_STATUS_AXES.map((axis) => [axis, status[axis].state]));
1762
+ return {
1763
+ version: TRUST_SUMMARY_VERSION,
1764
+ verdict: trustVerdict(status),
1765
+ text: formatTrustSummary(status),
1766
+ axes,
1767
+ claimant: claimantOf(status),
1768
+ unknown: TRUST_STATUS_AXES.filter((axis) => isUnanswered(status, axis)),
1769
+ refs: trustSummaryReferences(status)
1770
+ };
1771
+ }
1772
+
1059
1773
  export {
1060
1774
  RUN_RECEIPT_INTEGRITY_VERSION,
1061
1775
  RUN_RECEIPT_INTEGRITY_ALGORITHM,
@@ -1071,9 +1785,25 @@ export {
1071
1785
  writeEvalArtifactV4,
1072
1786
  loadEvalArtifactV4,
1073
1787
  parseEvalArtifactV4,
1788
+ TRUST_STATUS_AXES,
1789
+ isTrustStatusIdentifier,
1790
+ normalizeTrustStatus,
1791
+ composeTrustStatus,
1792
+ retiredReceiptIntegrity,
1793
+ retiredReceiptIntegrityReason,
1794
+ retiredIntegrityVersionOf,
1795
+ adaptRunReceiptTrustStatus,
1796
+ inspectRunReceiptTrustStatus,
1797
+ adaptGateDecisionReviewStatus,
1798
+ adaptGroundedEvidenceValidationStatus,
1799
+ adaptFinishContractCompletionStatus,
1074
1800
  evalClioProvenance,
1075
1801
  evalEnvironmentProvenance,
1076
1802
  loadEvalTaskFile,
1077
- EvalTaskFileError
1803
+ EvalTaskFileError,
1804
+ formatTrustSummary,
1805
+ formatTrustSummaryLine,
1806
+ formatTrustAxes,
1807
+ summarizeTrustStatus
1078
1808
  };
1079
- //# sourceMappingURL=chunk-ZGH7FGS5.js.map
1809
+ //# sourceMappingURL=chunk-K4XHGFR5.js.map