blun-king-cli 9.1.643 → 9.1.644

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 (266) hide show
  1. package/LIESMICH.txt +18 -0
  2. package/README.md +20 -6
  3. package/bin/blun.js +3 -3
  4. package/bin/king.js +3 -3
  5. package/bin/launcher-mode.js +125 -126
  6. package/bin/launcher-runtime.js +603 -616
  7. package/bin/plugin-bootstrap.js +339 -405
  8. package/bin/rename-private-staging.cjs +2 -2
  9. package/bin/retired-bundled-plugins.cjs +84 -0
  10. package/bin/startup-security-host.cjs +105 -0
  11. package/bin/startup-security.cjs +9 -105
  12. package/bin/startup-warning-policy.cjs +22 -0
  13. package/bin/update-lease-installer.cjs +125 -0
  14. package/bin/update-lease-sockets.cjs +228 -0
  15. package/bin/update-lease.js +22 -327
  16. package/bin/verify-bundled-agent-sources.cjs +2 -4
  17. package/blun.mjs +18 -179
  18. package/bundled-agent-sources.json +1 -552
  19. package/package.json +1 -5
  20. package/tool-liveness642/receipt.json +1 -1
  21. package/worker-host.mjs +3 -119
  22. package/agent-spine-plugin/.claude-plugin/marketplace.json +0 -20
  23. package/agent-spine-plugin/.claude-plugin/plugin.json +0 -14
  24. package/agent-spine-plugin/.codex-plugin/plugin.json +0 -47
  25. package/agent-spine-plugin/.mcp.json +0 -8
  26. package/agent-spine-plugin/CHANGELOG.md +0 -1614
  27. package/agent-spine-plugin/LICENSE +0 -186
  28. package/agent-spine-plugin/README.md +0 -432
  29. package/agent-spine-plugin/assets/agentspine-banner.svg +0 -32
  30. package/agent-spine-plugin/bin/agentspine-mcp.js +0 -4
  31. package/agent-spine-plugin/bin/agentspine.js +0 -7
  32. package/agent-spine-plugin/blun.plugin.json +0 -68
  33. package/agent-spine-plugin/docs/acceptance.md +0 -61
  34. package/agent-spine-plugin/docs/artifact-evaluation.md +0 -93
  35. package/agent-spine-plugin/docs/host-integration.md +0 -193
  36. package/agent-spine-plugin/docs/preflight-recall.md +0 -71
  37. package/agent-spine-plugin/docs/preservation-contract.md +0 -53
  38. package/agent-spine-plugin/docs/quality-gates.md +0 -50
  39. package/agent-spine-plugin/docs/session-timeline.md +0 -112
  40. package/agent-spine-plugin/docs/source-roots.md +0 -113
  41. package/agent-spine-plugin/docs/world-model.md +0 -119
  42. package/agent-spine-plugin/hooks/codex.json +0 -47
  43. package/agent-spine-plugin/hooks/hooks.json +0 -106
  44. package/agent-spine-plugin/hooks/version.json +0 -5
  45. package/agent-spine-plugin/package.json +0 -77
  46. package/agent-spine-plugin/scripts/check-codex-install.js +0 -226
  47. package/agent-spine-plugin/scripts/check-hosts.js +0 -208
  48. package/agent-spine-plugin/scripts/check-install-hook.js +0 -227
  49. package/agent-spine-plugin/scripts/check-install-selfstarter.js +0 -154
  50. package/agent-spine-plugin/scripts/check-install.js +0 -478
  51. package/agent-spine-plugin/scripts/check-line-budget.js +0 -58
  52. package/agent-spine-plugin/scripts/check-syntax.js +0 -29
  53. package/agent-spine-plugin/scripts/github-actions.js +0 -11
  54. package/agent-spine-plugin/scripts/hermetic-process.js +0 -191
  55. package/agent-spine-plugin/scripts/release-check.js +0 -150
  56. package/agent-spine-plugin/scripts/run-acceptance.js +0 -19
  57. package/agent-spine-plugin/scripts/run-checks.js +0 -50
  58. package/agent-spine-plugin/scripts/run-tests-hermetic.js +0 -112
  59. package/agent-spine-plugin/skills/agent-spine/SKILL.md +0 -99
  60. package/agent-spine-plugin/spine-example/1-identity.md +0 -12
  61. package/agent-spine-plugin/spine-example/2-voice.md +0 -6
  62. package/agent-spine-plugin/spine-example/3-conduct.md +0 -8
  63. package/agent-spine-plugin/spine-example/4-history.md +0 -4
  64. package/agent-spine-plugin/src/cli-agent.js +0 -315
  65. package/agent-spine-plugin/src/cli-attention.js +0 -95
  66. package/agent-spine-plugin/src/cli-autonomy.js +0 -36
  67. package/agent-spine-plugin/src/cli-common.js +0 -71
  68. package/agent-spine-plugin/src/cli-continuity.js +0 -116
  69. package/agent-spine-plugin/src/cli-core.js +0 -128
  70. package/agent-spine-plugin/src/cli-diagnostics.js +0 -291
  71. package/agent-spine-plugin/src/cli-host.js +0 -21
  72. package/agent-spine-plugin/src/cli-learning.js +0 -320
  73. package/agent-spine-plugin/src/cli-premortem.js +0 -16
  74. package/agent-spine-plugin/src/cli-sharing.js +0 -230
  75. package/agent-spine-plugin/src/cli.js +0 -181
  76. package/agent-spine-plugin/src/codex-reader-launcher.js +0 -182
  77. package/agent-spine-plugin/src/hook.js +0 -500
  78. package/agent-spine-plugin/src/index.js +0 -108
  79. package/agent-spine-plugin/src/lib/acceptance.js +0 -435
  80. package/agent-spine-plugin/src/lib/action-lesson-recall.js +0 -118
  81. package/agent-spine-plugin/src/lib/attention-context.js +0 -167
  82. package/agent-spine-plugin/src/lib/attention-events.js +0 -113
  83. package/agent-spine-plugin/src/lib/attention-privacy.js +0 -72
  84. package/agent-spine-plugin/src/lib/attention-schema.js +0 -164
  85. package/agent-spine-plugin/src/lib/attention-storage.js +0 -93
  86. package/agent-spine-plugin/src/lib/attention.js +0 -164
  87. package/agent-spine-plugin/src/lib/audit-premortem.js +0 -223
  88. package/agent-spine-plugin/src/lib/audit.js +0 -401
  89. package/agent-spine-plugin/src/lib/authentication.js +0 -515
  90. package/agent-spine-plugin/src/lib/autonomy-policy.js +0 -110
  91. package/agent-spine-plugin/src/lib/autonomy-store.js +0 -202
  92. package/agent-spine-plugin/src/lib/autonomy.js +0 -8
  93. package/agent-spine-plugin/src/lib/briefing.js +0 -493
  94. package/agent-spine-plugin/src/lib/catalog-document-read.js +0 -51
  95. package/agent-spine-plugin/src/lib/catalog.js +0 -167
  96. package/agent-spine-plugin/src/lib/channel-continuity.js +0 -19
  97. package/agent-spine-plugin/src/lib/channel-runtime.js +0 -665
  98. package/agent-spine-plugin/src/lib/codex-installation.js +0 -231
  99. package/agent-spine-plugin/src/lib/codex-skill-installation.js +0 -211
  100. package/agent-spine-plugin/src/lib/context.js +0 -156
  101. package/agent-spine-plugin/src/lib/continuity.js +0 -338
  102. package/agent-spine-plugin/src/lib/coordination.js +0 -577
  103. package/agent-spine-plugin/src/lib/delivery-agent-usage.js +0 -231
  104. package/agent-spine-plugin/src/lib/delivery-assignment.js +0 -220
  105. package/agent-spine-plugin/src/lib/delivery-command-actions.js +0 -462
  106. package/agent-spine-plugin/src/lib/delivery-knowledge.js +0 -78
  107. package/agent-spine-plugin/src/lib/delivery-premortem-binding.js +0 -107
  108. package/agent-spine-plugin/src/lib/delivery-premortem-closure.js +0 -171
  109. package/agent-spine-plugin/src/lib/delivery-premortem-codec.js +0 -45
  110. package/agent-spine-plugin/src/lib/delivery-premortem-correction.js +0 -101
  111. package/agent-spine-plugin/src/lib/delivery-premortem-file.js +0 -21
  112. package/agent-spine-plugin/src/lib/delivery-premortem-index.js +0 -493
  113. package/agent-spine-plugin/src/lib/delivery-premortem-inspection.js +0 -37
  114. package/agent-spine-plugin/src/lib/delivery-premortem-recovery.js +0 -120
  115. package/agent-spine-plugin/src/lib/delivery-premortem-rejection.js +0 -65
  116. package/agent-spine-plugin/src/lib/delivery-premortem-results.js +0 -28
  117. package/agent-spine-plugin/src/lib/delivery-premortem-session-guard.js +0 -46
  118. package/agent-spine-plugin/src/lib/delivery-premortem-write-ledger.js +0 -285
  119. package/agent-spine-plugin/src/lib/delivery-premortem.js +0 -499
  120. package/agent-spine-plugin/src/lib/delivery-shell-heredoc.js +0 -115
  121. package/agent-spine-plugin/src/lib/delivery-shell-substitutions.js +0 -111
  122. package/agent-spine-plugin/src/lib/delivery-shell-wrapper.js +0 -64
  123. package/agent-spine-plugin/src/lib/delivery-target.js +0 -73
  124. package/agent-spine-plugin/src/lib/delivery-verification.js +0 -445
  125. package/agent-spine-plugin/src/lib/documents.js +0 -239
  126. package/agent-spine-plugin/src/lib/feed-transport.js +0 -499
  127. package/agent-spine-plugin/src/lib/filesystem-retry.js +0 -34
  128. package/agent-spine-plugin/src/lib/gateway-common.js +0 -68
  129. package/agent-spine-plugin/src/lib/gateway-control.js +0 -370
  130. package/agent-spine-plugin/src/lib/gateway-delivery.js +0 -103
  131. package/agent-spine-plugin/src/lib/gateway-execution.js +0 -350
  132. package/agent-spine-plugin/src/lib/gateway-group-response.js +0 -128
  133. package/agent-spine-plugin/src/lib/gateway-host-fencing.js +0 -92
  134. package/agent-spine-plugin/src/lib/gateway-host-lifecycle.js +0 -193
  135. package/agent-spine-plugin/src/lib/gateway-inspection.js +0 -85
  136. package/agent-spine-plugin/src/lib/gateway-knowledge.js +0 -129
  137. package/agent-spine-plugin/src/lib/gateway-policy-provenance.js +0 -197
  138. package/agent-spine-plugin/src/lib/gateway-premortem-disposition.js +0 -82
  139. package/agent-spine-plugin/src/lib/gateway-premortem.js +0 -363
  140. package/agent-spine-plugin/src/lib/gateway-prepared-host.js +0 -28
  141. package/agent-spine-plugin/src/lib/gateway-runs.js +0 -345
  142. package/agent-spine-plugin/src/lib/gateway-runtime-identity.js +0 -31
  143. package/agent-spine-plugin/src/lib/gateway-runtime-records.js +0 -21
  144. package/agent-spine-plugin/src/lib/gateway-runtime.js +0 -18
  145. package/agent-spine-plugin/src/lib/gateway-state-transaction.js +0 -356
  146. package/agent-spine-plugin/src/lib/gateway-state.js +0 -344
  147. package/agent-spine-plugin/src/lib/graph.js +0 -337
  148. package/agent-spine-plugin/src/lib/hook-artifact-guards.js +0 -356
  149. package/agent-spine-plugin/src/lib/hook-audit.js +0 -43
  150. package/agent-spine-plugin/src/lib/hook-briefing-use.js +0 -78
  151. package/agent-spine-plugin/src/lib/hook-context.js +0 -441
  152. package/agent-spine-plugin/src/lib/hook-final-message.js +0 -26
  153. package/agent-spine-plugin/src/lib/hook-input.js +0 -27
  154. package/agent-spine-plugin/src/lib/hook-output.js +0 -284
  155. package/agent-spine-plugin/src/lib/hook-premortem.js +0 -257
  156. package/agent-spine-plugin/src/lib/hook-process-advisory.js +0 -36
  157. package/agent-spine-plugin/src/lib/hook-protection.js +0 -95
  158. package/agent-spine-plugin/src/lib/hook-stop-verification.js +0 -84
  159. package/agent-spine-plugin/src/lib/hook-timeline.js +0 -102
  160. package/agent-spine-plugin/src/lib/host-instruction-budget.js +0 -11
  161. package/agent-spine-plugin/src/lib/https-transport.js +0 -392
  162. package/agent-spine-plugin/src/lib/identifier-analysis.js +0 -446
  163. package/agent-spine-plugin/src/lib/indexed-memory-offline.js +0 -40
  164. package/agent-spine-plugin/src/lib/indexed-memory.js +0 -298
  165. package/agent-spine-plugin/src/lib/knowledge-evidence.js +0 -431
  166. package/agent-spine-plugin/src/lib/learning-applications.js +0 -441
  167. package/agent-spine-plugin/src/lib/learning-artifact-evaluator.js +0 -114
  168. package/agent-spine-plugin/src/lib/learning-candidates.js +0 -274
  169. package/agent-spine-plugin/src/lib/learning-context.js +0 -137
  170. package/agent-spine-plugin/src/lib/learning-delivery-contracts.js +0 -310
  171. package/agent-spine-plugin/src/lib/learning-evaluation-contracts.js +0 -350
  172. package/agent-spine-plugin/src/lib/learning-evaluation-registration.js +0 -372
  173. package/agent-spine-plugin/src/lib/learning-evaluation-revocation.js +0 -292
  174. package/agent-spine-plugin/src/lib/learning-evidence-contracts.js +0 -321
  175. package/agent-spine-plugin/src/lib/learning-findings.js +0 -458
  176. package/agent-spine-plugin/src/lib/learning-measurement-contracts.js +0 -285
  177. package/agent-spine-plugin/src/lib/learning-measurements.js +0 -265
  178. package/agent-spine-plugin/src/lib/learning-outcome-contracts.js +0 -165
  179. package/agent-spine-plugin/src/lib/learning-outcomes.js +0 -343
  180. package/agent-spine-plugin/src/lib/learning-reconciliation.js +0 -290
  181. package/agent-spine-plugin/src/lib/learning-retry-contracts.js +0 -188
  182. package/agent-spine-plugin/src/lib/learning-schema.js +0 -229
  183. package/agent-spine-plugin/src/lib/learning-scope-targets.js +0 -424
  184. package/agent-spine-plugin/src/lib/learning-state-upgrade.js +0 -477
  185. package/agent-spine-plugin/src/lib/learning-status-configuration.js +0 -476
  186. package/agent-spine-plugin/src/lib/learning-storage.js +0 -203
  187. package/agent-spine-plugin/src/lib/learning-trial-recovery.js +0 -218
  188. package/agent-spine-plugin/src/lib/learning-validation-contracts.js +0 -375
  189. package/agent-spine-plugin/src/lib/learning-validation-renewal.js +0 -298
  190. package/agent-spine-plugin/src/lib/learning-validation-runtime.js +0 -234
  191. package/agent-spine-plugin/src/lib/learning.js +0 -36
  192. package/agent-spine-plugin/src/lib/lesson-recall-session.js +0 -172
  193. package/agent-spine-plugin/src/lib/mcp-autonomy-tools.js +0 -37
  194. package/agent-spine-plugin/src/lib/mcp-delivery-completion.js +0 -124
  195. package/agent-spine-plugin/src/lib/mcp-delivery-tools.js +0 -45
  196. package/agent-spine-plugin/src/lib/mcp-premortem.js +0 -68
  197. package/agent-spine-plugin/src/lib/mcp-runtime.js +0 -355
  198. package/agent-spine-plugin/src/lib/mcp-source-context.js +0 -61
  199. package/agent-spine-plugin/src/lib/mcp-timeline-tools.js +0 -240
  200. package/agent-spine-plugin/src/lib/mcp-world-tools.js +0 -52
  201. package/agent-spine-plugin/src/lib/object-transport.js +0 -206
  202. package/agent-spine-plugin/src/lib/owned-file-lock.js +0 -182
  203. package/agent-spine-plugin/src/lib/paths.js +0 -109
  204. package/agent-spine-plugin/src/lib/peer-transport.js +0 -283
  205. package/agent-spine-plugin/src/lib/persona-runtime.js +0 -581
  206. package/agent-spine-plugin/src/lib/pre-answer-timeline-recall.js +0 -104
  207. package/agent-spine-plugin/src/lib/preflight-delivery-id.js +0 -27
  208. package/agent-spine-plugin/src/lib/preflight.js +0 -688
  209. package/agent-spine-plugin/src/lib/project-portfolio.js +0 -176
  210. package/agent-spine-plugin/src/lib/runtime.js +0 -13
  211. package/agent-spine-plugin/src/lib/selfstarter-core.js +0 -382
  212. package/agent-spine-plugin/src/lib/selfstarter-jobs.js +0 -149
  213. package/agent-spine-plugin/src/lib/selfstarter-lease.js +0 -204
  214. package/agent-spine-plugin/src/lib/selfstarter-policy.js +0 -90
  215. package/agent-spine-plugin/src/lib/selfstarter-workspace.js +0 -111
  216. package/agent-spine-plugin/src/lib/selfstarter.js +0 -11
  217. package/agent-spine-plugin/src/lib/session-timeline-auth.js +0 -316
  218. package/agent-spine-plugin/src/lib/session-timeline-codex.js +0 -69
  219. package/agent-spine-plugin/src/lib/session-timeline-contract.js +0 -56
  220. package/agent-spine-plugin/src/lib/session-timeline-enrollment-source.js +0 -38
  221. package/agent-spine-plugin/src/lib/session-timeline-enrollment-storage.js +0 -128
  222. package/agent-spine-plugin/src/lib/session-timeline-enrollment-transport.js +0 -15
  223. package/agent-spine-plugin/src/lib/session-timeline-enrollment.js +0 -478
  224. package/agent-spine-plugin/src/lib/session-timeline-event-extract.js +0 -186
  225. package/agent-spine-plugin/src/lib/session-timeline-host-origin.js +0 -73
  226. package/agent-spine-plugin/src/lib/session-timeline-host-receipt.js +0 -117
  227. package/agent-spine-plugin/src/lib/session-timeline-invocation.js +0 -201
  228. package/agent-spine-plugin/src/lib/session-timeline-king.js +0 -93
  229. package/agent-spine-plugin/src/lib/session-timeline-prior.js +0 -57
  230. package/agent-spine-plugin/src/lib/session-timeline-provider.js +0 -36
  231. package/agent-spine-plugin/src/lib/session-timeline-query.js +0 -56
  232. package/agent-spine-plugin/src/lib/session-timeline-results.js +0 -56
  233. package/agent-spine-plugin/src/lib/session-timeline-root.js +0 -11
  234. package/agent-spine-plugin/src/lib/session-timeline-search.js +0 -82
  235. package/agent-spine-plugin/src/lib/session-timeline-sid-acl.js +0 -213
  236. package/agent-spine-plugin/src/lib/session-timeline-source-open.js +0 -30
  237. package/agent-spine-plugin/src/lib/session-timeline-source.js +0 -80
  238. package/agent-spine-plugin/src/lib/session-timeline-state.js +0 -45
  239. package/agent-spine-plugin/src/lib/session-timeline-transport.js +0 -42
  240. package/agent-spine-plugin/src/lib/session-timeline-windows-acl.js +0 -145
  241. package/agent-spine-plugin/src/lib/session-timeline.js +0 -462
  242. package/agent-spine-plugin/src/lib/sharing.js +0 -969
  243. package/agent-spine-plugin/src/lib/source-roots.js +0 -475
  244. package/agent-spine-plugin/src/lib/source-tree-scan.js +0 -178
  245. package/agent-spine-plugin/src/lib/sqlite-transport.js +0 -501
  246. package/agent-spine-plugin/src/lib/task-knowledge-context.js +0 -99
  247. package/agent-spine-plugin/src/lib/telegram-adapter.js +0 -119
  248. package/agent-spine-plugin/src/lib/timeline-continuation-update.js +0 -100
  249. package/agent-spine-plugin/src/lib/timeline-tool-guard.js +0 -225
  250. package/agent-spine-plugin/src/lib/timeline-user-feedback.js +0 -216
  251. package/agent-spine-plugin/src/lib/timeline-world-capture.js +0 -233
  252. package/agent-spine-plugin/src/lib/voice-runtime.js +0 -39
  253. package/agent-spine-plugin/src/lib/world-knowledge.js +0 -306
  254. package/agent-spine-plugin/src/lib/world-model.js +0 -333
  255. package/agent-spine-plugin/src/mcp.js +0 -456
  256. package/agent-spine-plugin/src/version.js +0 -1
  257. package/agent-spine-plugin/src/worker.js +0 -257
  258. package/bin/agentspine-king-goal-inbox.mjs +0 -127
  259. package/bin/agentspine-king-goal-intake.mjs +0 -106
  260. package/bin/agentspine-king-host-runner.mjs +0 -109
  261. package/bin/agentspine-king-snapshot-policy.cjs +0 -80
  262. package/bin/agentspine-king-status-policy.mjs +0 -226
  263. package/bin/agentspine-king-worker-host.mjs +0 -160
  264. package/bin/managed-plugin-selection.cjs +0 -141
  265. package/bin/verify-agent-behavior.cjs +0 -122
  266. package/bin/verify-agent-components.cjs +0 -104
@@ -1,477 +0,0 @@
1
- import {
2
- DIGEST_RE, PROTECTED_LESSON_RE, LINEAGE_EVALUATIONS, ROOT_BOUND_EVALUATIONS, REGISTRY_BOUND_EVALUATIONS, INITIAL_TRIAL_EVALUATIONS,
3
- TARGET_BOUND_EVALUATIONS, DEADLINE_BOUND_EVALUATIONS, TRIAL_RETRY_EVALUATIONS, STALENESS_BOUND_EVALUATIONS, CANDIDATE_ADMISSION_EVALUATIONS, CANDIDATE_EVIDENCE_LINEAGE_EVALUATIONS,
4
- DELIVERABLE_APPLICATIONS, INITIAL_TRIAL_APPLICATIONS, TARGET_BOUND_APPLICATIONS, DEADLINE_BOUND_APPLICATIONS, defaults
5
- } from "./learning-schema.js";
6
- import {
7
- normalizeStoredScope, scopeContains, exactScope, digest, learningTargetMatchesCandidate, storedEvidenceRevocationStructure,
8
- evidenceRevocationMatchesState, storedOutcomeStructure, storedMeasurementStructure, storedMeasurementRevocationStructure, measurementRevocationMatchesState, measurementRunDigest,
9
- evaluatorRootRunDigest, storedEvaluatorRecordStructure, storedEvaluationBindingStructure, storedEvaluationRevocationStructure, evaluationRevocationMatchesState
10
- } from "./learning-scope-targets.js";
11
- import {
12
- revalidationWindowMatchesState, storedValidationLeaseStructure, validationLeaseMatchesState
13
- } from "./learning-validation-contracts.js";
14
- import {
15
- storedValidationRevocationStructure, validationRevocationMatchesState
16
- } from "./learning-validation-runtime.js";
17
- import {
18
- storedMeasurementLineageStructure, storedEvidenceSourceAttestationRevocationStructure, evidenceSourceAttestationRevocationMatchesState
19
- } from "./learning-measurement-contracts.js";
20
- import {
21
- storedCandidateEvidenceLineageStructure, candidateEvidenceLineageMatchesEvaluation, candidateAdmissionMatches
22
- } from "./learning-evidence-contracts.js";
23
- import {
24
- storedEvaluationStructure, storedApplicationStructure, initialAdmissionsMatchState, storedTrialFailureStructure, trialFailureMatchesState, storedTrialFailureRevocationStructure,
25
- trialFailureRevocationMatchesState
26
- } from "./learning-evaluation-contracts.js";
27
- import {
28
- trialRetryMatchesState, storedTrialRetryExhaustionStructure, trialRetryExhaustionMatchesState, revalidationAdmissionsMatchState
29
- } from "./learning-retry-contracts.js";
30
- import {
31
- storedDeliveryStructure, storedApplicationRevocationStructure, applicationRevocationMatchesState, storedDeliveryRevocationStructure, deliveryRevocationMatchesState, storedOutcomeRevocationStructure,
32
- outcomeRevocationMatchesState
33
- } from "./learning-delivery-contracts.js";
34
-
35
- export function normalizeState(value, root) {
36
- if (!value || typeof value !== "object" || Array.isArray(value)
37
- || value.schema !== "agentspine.learning/v1" || value.root !== root
38
- || !value.config || typeof value.config !== "object" || Array.isArray(value.config)
39
- || !Array.isArray(value.candidates) || !value.candidates.every((item) => item && typeof item === "object" && Array.isArray(item.evidence))
40
- || (value.outcomes !== undefined && (!Array.isArray(value.outcomes) || !value.outcomes.every((item) => item && typeof item === "object")))
41
- || (value.measurements !== undefined && (!Array.isArray(value.measurements) || !value.measurements.every((item) => item && typeof item === "object")))
42
- || (value.measurementLineage !== undefined && (!Array.isArray(value.measurementLineage) || !value.measurementLineage.every((item) => item && typeof item === "object")))
43
- || (value.candidateEvidenceLineage !== undefined && (!Array.isArray(value.candidateEvidenceLineage)
44
- || !value.candidateEvidenceLineage.every((item) => item && typeof item === "object")))
45
- || (value.applications !== undefined && (!Array.isArray(value.applications) || !value.applications.every((item) => item && typeof item === "object")))
46
- || (value.deliveries !== undefined && (!Array.isArray(value.deliveries) || !value.deliveries.every((item) => item && typeof item === "object")))
47
- || (value.evaluations !== undefined && (!Array.isArray(value.evaluations) || !value.evaluations.every((item) => item && typeof item === "object")))
48
- || (value.evaluatorRegistry !== undefined && (!Array.isArray(value.evaluatorRegistry) || !value.evaluatorRegistry.every((item) => item && typeof item === "object")))
49
- || (value.evaluationBindings !== undefined && (!Array.isArray(value.evaluationBindings) || !value.evaluationBindings.every((item) => item && typeof item === "object")))
50
- || (value.validationLeases !== undefined && (!Array.isArray(value.validationLeases) || !value.validationLeases.every((item) => item && typeof item === "object")))
51
- || (value.trialFailures !== undefined && (!Array.isArray(value.trialFailures) || !value.trialFailures.every((item) => item && typeof item === "object")))
52
- || (value.trialFailureRevocations !== undefined && (!Array.isArray(value.trialFailureRevocations)
53
- || !value.trialFailureRevocations.every((item) => item && typeof item === "object")))
54
- || (value.trialRetryExhaustions !== undefined && (!Array.isArray(value.trialRetryExhaustions)
55
- || !value.trialRetryExhaustions.every((item) => item && typeof item === "object")))
56
- || (value.evaluationRevocations !== undefined && (!Array.isArray(value.evaluationRevocations)
57
- || !value.evaluationRevocations.every((item) => item && typeof item === "object")))
58
- || (value.evidenceSourceAttestationRevocations !== undefined
59
- && (!Array.isArray(value.evidenceSourceAttestationRevocations)
60
- || !value.evidenceSourceAttestationRevocations.every((item) => item && typeof item === "object")))
61
- || (value.validationRevocations !== undefined && (!Array.isArray(value.validationRevocations)
62
- || !value.validationRevocations.every((item) => item && typeof item === "object")))
63
- || (value.evidenceRevocations !== undefined && (!Array.isArray(value.evidenceRevocations)
64
- || !value.evidenceRevocations.every((item) => item && typeof item === "object")))
65
- || (value.measurementRevocations !== undefined && (!Array.isArray(value.measurementRevocations)
66
- || !value.measurementRevocations.every((item) => item && typeof item === "object")))
67
- || (value.applicationRevocations !== undefined && (!Array.isArray(value.applicationRevocations)
68
- || !value.applicationRevocations.every((item) => item && typeof item === "object")))
69
- || (value.deliveryRevocations !== undefined && (!Array.isArray(value.deliveryRevocations)
70
- || !value.deliveryRevocations.every((item) => item && typeof item === "object")))
71
- || (value.outcomeRevocations !== undefined && (!Array.isArray(value.outcomeRevocations)
72
- || !value.outcomeRevocations.every((item) => item && typeof item === "object")))
73
- || !Array.isArray(value.history) || !value.history.every((item) => item && typeof item === "object")) {
74
- throw new Error("learning state structure is invalid; run the audit before learning");
75
- }
76
- const normalized = {
77
- ...value,
78
- config: { ...defaults(), ...value.config },
79
- candidates: value.candidates.map((candidate) => ({
80
- ...candidate,
81
- scope: normalizeStoredScope(candidate.scope, candidate.subjectId, candidate.groupId),
82
- requiresLocalReview: candidate.requiresLocalReview ?? PROTECTED_LESSON_RE.test(candidate.claim || "")
83
- })),
84
- outcomes: value.outcomes || [],
85
- measurements: value.measurements || [],
86
- measurementLineage: value.measurementLineage || [],
87
- candidateEvidenceLineage: value.candidateEvidenceLineage || [],
88
- applications: value.applications || [],
89
- deliveries: value.deliveries || [],
90
- evaluations: value.evaluations || [],
91
- evaluatorRegistry: value.evaluatorRegistry || [],
92
- evaluationBindings: value.evaluationBindings || [],
93
- validationLeases: value.validationLeases || [],
94
- trialFailures: value.trialFailures || [],
95
- trialFailureRevocations: value.trialFailureRevocations || [],
96
- trialRetryExhaustions: value.trialRetryExhaustions || [],
97
- evaluationRevocations: value.evaluationRevocations || [],
98
- evidenceSourceAttestationRevocations: value.evidenceSourceAttestationRevocations || [],
99
- validationRevocations: value.validationRevocations || [],
100
- evidenceRevocations: value.evidenceRevocations || [],
101
- measurementRevocations: value.measurementRevocations || [],
102
- applicationRevocations: value.applicationRevocations || [],
103
- deliveryRevocations: value.deliveryRevocations || [],
104
- outcomeRevocations: value.outcomeRevocations || []
105
- };
106
- if (normalized.outcomes.some((receipt) => !storedOutcomeStructure(receipt))) {
107
- throw new Error("learning outcome state is invalid; run the audit before learning");
108
- }
109
- if (normalized.measurements.some((receipt) => !storedMeasurementStructure(receipt))) {
110
- throw new Error("learning measurement state is invalid; run the audit before learning");
111
- }
112
- if (normalized.measurementLineage.some((receipt) => !storedMeasurementLineageStructure(receipt))) {
113
- throw new Error("learning measurement lineage state is invalid; run the audit before learning");
114
- }
115
- if (normalized.candidateEvidenceLineage.some((receipt) => !storedCandidateEvidenceLineageStructure(receipt))) {
116
- throw new Error("learning candidate evidence lineage state is invalid; run the audit before learning");
117
- }
118
- const evidenceLineageDigests = new Set();
119
- const evidenceLineageIndependence = new Set();
120
- for (const receipt of normalized.candidateEvidenceLineage) {
121
- const evidenceKey = `${receipt.scopeDigest}\0${receipt.evidenceDigest}`;
122
- const independenceKey = `${receipt.scopeDigest}\0${receipt.independenceDigest}`;
123
- if (evidenceLineageDigests.has(evidenceKey) || evidenceLineageIndependence.has(independenceKey)) {
124
- throw new Error("learning candidate evidence lineage is replayed; run the audit before learning");
125
- }
126
- evidenceLineageDigests.add(evidenceKey);
127
- evidenceLineageIndependence.add(independenceKey);
128
- }
129
- if (normalized.applications.some((receipt) => !storedApplicationStructure(receipt))) {
130
- throw new Error("learning application state is invalid; run the audit before learning");
131
- }
132
- if (normalized.deliveries.some((receipt) => !storedDeliveryStructure(receipt))) {
133
- throw new Error("learning delivery state is invalid; run the audit before learning");
134
- }
135
- if (normalized.evaluations.some((contract) => !storedEvaluationStructure(contract))) {
136
- throw new Error("learning evaluation state is invalid; run the audit before learning");
137
- }
138
- if (normalized.evaluations.some((contract) => TARGET_BOUND_EVALUATIONS.has(contract.schema)
139
- && !learningTargetMatchesCandidate(contract.target,
140
- normalized.candidates.find((candidate) => candidate.id === contract.learningId)))) {
141
- throw new Error("learning evaluation target is invalid or changed; run the audit before learning");
142
- }
143
- if (normalized.evaluations.some((contract) => CANDIDATE_ADMISSION_EVALUATIONS.has(contract.schema)
144
- && !candidateAdmissionMatches(contract,
145
- normalized.candidates.find((candidate) => candidate.id === contract.learningId)))) {
146
- throw new Error("learning candidate admission is invalid or changed; run the audit before learning");
147
- }
148
- if (normalized.evaluations.some((contract) => CANDIDATE_EVIDENCE_LINEAGE_EVALUATIONS.has(contract.schema)
149
- && !candidateEvidenceLineageMatchesEvaluation(normalized, contract))) {
150
- throw new Error("learning candidate evidence lineage binding is invalid; run the audit before learning");
151
- }
152
- if (normalized.evaluatorRegistry.some((record) => !storedEvaluatorRecordStructure(record))) {
153
- throw new Error("learning evaluator registry is invalid; run the audit before learning");
154
- }
155
- if (new Set(normalized.evaluatorRegistry.map((record) => record.id)).size !== normalized.evaluatorRegistry.length
156
- || new Set(normalized.evaluatorRegistry.map((record) => record.principalDigest)).size !== normalized.evaluatorRegistry.length) {
157
- throw new Error("learning evaluator registry contains duplicate identities or roots; run the audit before learning");
158
- }
159
- if (normalized.evaluationBindings.some((binding) => !storedEvaluationBindingStructure(binding)
160
- || !normalized.evaluations.some((contract) => contract.id === binding.evaluationId
161
- && contract.digest === binding.evaluationDigest
162
- && contract.evaluatorRoots?.length === binding.evaluators.length
163
- && binding.evaluators.every((entry) => contract.evaluatorRoots.some((root) => root.evaluatorId === entry.evaluatorId
164
- && root.principalDigest === entry.principalDigest))))) {
165
- throw new Error("learning evaluator binding state is invalid; run the audit before learning");
166
- }
167
- if (new Set(normalized.evaluationBindings.map((binding) => binding.evaluationId)).size !== normalized.evaluationBindings.length) {
168
- throw new Error("learning evaluator binding is duplicated; run the audit before learning");
169
- }
170
- if (normalized.evaluations.some((contract) => REGISTRY_BOUND_EVALUATIONS.has(contract.schema)
171
- && !normalized.evaluationBindings.some((binding) => binding.evaluationId === contract.id
172
- && binding.evaluationDigest === contract.digest))) {
173
- throw new Error("learning evaluator binding is missing; run the audit before learning");
174
- }
175
- if (normalized.validationLeases.some((lease) => !storedValidationLeaseStructure(lease))) {
176
- throw new Error("learning validation lease state is invalid; run the audit before learning");
177
- }
178
- if (new Set(normalized.validationLeases.map((lease) => lease.id)).size !== normalized.validationLeases.length
179
- || new Set(normalized.validationLeases.map((lease) => lease.learningId)).size !== normalized.validationLeases.length) {
180
- throw new Error("learning validation lease is duplicated; run the audit before learning");
181
- }
182
- if (normalized.trialFailures.some((receipt) => !storedTrialFailureStructure(receipt)
183
- || !trialFailureMatchesState(normalized, receipt))
184
- || new Set(normalized.trialFailures.map((entry) => entry.applicationId)).size !== normalized.trialFailures.length) {
185
- throw new Error("learning trial failure state is invalid; run the audit before learning");
186
- }
187
- if (normalized.trialFailureRevocations.some((receipt) => !storedTrialFailureRevocationStructure(receipt)
188
- || !trialFailureRevocationMatchesState(normalized, receipt))
189
- || new Set(normalized.trialFailureRevocations.map((entry) => entry.trialFailureId)).size
190
- !== normalized.trialFailureRevocations.length) {
191
- throw new Error("learning trial failure revocation state is invalid; run the audit before learning");
192
- }
193
- const retryContracts = normalized.evaluations.filter((contract) => TRIAL_RETRY_EVALUATIONS.has(contract.schema));
194
- if (retryContracts.some((contract) => !trialRetryMatchesState(normalized, contract))
195
- || new Set(retryContracts.map((contract) => contract.retry.trialFailureRevocationId)).size
196
- !== retryContracts.length) {
197
- throw new Error("learning trial retry state is invalid; run the audit before learning");
198
- }
199
- if (normalized.trialRetryExhaustions.some((receipt) => !storedTrialRetryExhaustionStructure(receipt)
200
- || !trialRetryExhaustionMatchesState(normalized, receipt))
201
- || new Set(normalized.trialRetryExhaustions.map((entry) => entry.correctiveEvaluationId)).size
202
- !== normalized.trialRetryExhaustions.length
203
- || new Set(normalized.trialRetryExhaustions.map((entry) => entry.trialFailureId)).size
204
- !== normalized.trialRetryExhaustions.length) {
205
- throw new Error("learning trial retry exhaustion state is invalid; run the audit before learning");
206
- }
207
- if (normalized.evaluationRevocations.some((receipt) => !storedEvaluationRevocationStructure(receipt)
208
- || !evaluationRevocationMatchesState(normalized, receipt))
209
- || new Set(normalized.evaluationRevocations.map((entry) => entry.evaluationId)).size
210
- !== normalized.evaluationRevocations.length) {
211
- throw new Error("learning evaluation revocation state is invalid; run the audit before learning");
212
- }
213
- if (normalized.evidenceSourceAttestationRevocations.some((receipt) =>
214
- !storedEvidenceSourceAttestationRevocationStructure(receipt)
215
- || !evidenceSourceAttestationRevocationMatchesState(normalized, receipt))
216
- || new Set(normalized.evidenceSourceAttestationRevocations.map((entry) =>
217
- `${entry.evaluationId}\0${entry.evidenceDigest}`)).size
218
- !== normalized.evidenceSourceAttestationRevocations.length) {
219
- throw new Error("learning evidence source attestation revocation state is invalid; run the audit before learning");
220
- }
221
- if (normalized.validationRevocations.some((receipt) => !storedValidationRevocationStructure(receipt)
222
- || !validationRevocationMatchesState(normalized, receipt))
223
- || new Set(normalized.validationRevocations.map((entry) => entry.validationLeaseId)).size
224
- !== normalized.validationRevocations.length) {
225
- throw new Error("learning validation revocation state is invalid; run the audit before learning");
226
- }
227
- if (normalized.evidenceRevocations.some((receipt) => !storedEvidenceRevocationStructure(receipt)
228
- || !evidenceRevocationMatchesState(normalized, receipt))
229
- || new Set(normalized.evidenceRevocations.map((entry) => `${entry.learningId}\0${entry.evidenceId}`)).size
230
- !== normalized.evidenceRevocations.length) {
231
- throw new Error("learning evidence revocation state is invalid; run the audit before learning");
232
- }
233
- if (normalized.measurementRevocations.some((receipt) => !storedMeasurementRevocationStructure(receipt)
234
- || !measurementRevocationMatchesState(normalized, receipt))
235
- || new Set(normalized.measurementRevocations.map((entry) => entry.measurementId)).size
236
- !== normalized.measurementRevocations.length) {
237
- throw new Error("learning measurement revocation state is invalid; run the audit before learning");
238
- }
239
- if (normalized.applicationRevocations.some((receipt) => !storedApplicationRevocationStructure(receipt)
240
- || !applicationRevocationMatchesState(normalized, receipt))
241
- || new Set(normalized.applicationRevocations.map((entry) => entry.applicationId)).size
242
- !== normalized.applicationRevocations.length) {
243
- throw new Error("learning application revocation state is invalid; run the audit before learning");
244
- }
245
- if (normalized.deliveryRevocations.some((receipt) => !storedDeliveryRevocationStructure(receipt)
246
- || !deliveryRevocationMatchesState(normalized, receipt))
247
- || new Set(normalized.deliveryRevocations.map((entry) => entry.deliveryId)).size
248
- !== normalized.deliveryRevocations.length) {
249
- throw new Error("learning delivery revocation state is invalid; run the audit before learning");
250
- }
251
- if (normalized.outcomeRevocations.some((receipt) => !storedOutcomeRevocationStructure(receipt)
252
- || !outcomeRevocationMatchesState(normalized, receipt))
253
- || new Set(normalized.outcomeRevocations.map((entry) => entry.outcomeId)).size
254
- !== normalized.outcomeRevocations.length) {
255
- throw new Error("learning outcome revocation state is invalid; run the audit before learning");
256
- }
257
- if (normalized.candidates.some((candidate) => candidate.promotion?.canary?.revalidation
258
- && !revalidationWindowMatchesState(normalized, candidate))) {
259
- throw new Error("learning revalidation window state is invalid; run the audit before learning");
260
- }
261
- if (!revalidationAdmissionsMatchState(normalized)) {
262
- throw new Error("learning revalidation admission state is invalid; run the audit before learning");
263
- }
264
- if (!initialAdmissionsMatchState(normalized)) {
265
- throw new Error("learning initial trial admission state is invalid; run the audit before learning");
266
- }
267
- if (normalized.outcomes.some((receipt) => {
268
- const candidate = normalized.candidates.find((item) => item.id === receipt.learningId);
269
- return !candidate || !scopeContains(candidate.scope, receipt.scope);
270
- })) throw new Error("learning outcome scope is invalid; run the audit before learning");
271
- if (normalized.applications.some((receipt) => {
272
- const candidate = normalized.candidates.find((item) => item.id === receipt.learningId);
273
- return !candidate || !scopeContains(candidate.scope, receipt.scope);
274
- })) throw new Error("learning application scope is invalid; run the audit before learning");
275
- if (normalized.deliveries.some((receipt) => {
276
- const application = normalized.applications.find((item) => item.id === receipt.applicationId);
277
- return !application || application.learningId !== receipt.learningId
278
- || !DELIVERABLE_APPLICATIONS.has(application.schema)
279
- || application.sessionId !== receipt.sessionId || application.preflightReceiptId !== receipt.preflightReceiptId
280
- || !exactScope(application.scope, receipt.scope)
281
- || new Date(receipt.completedAt).getTime() < new Date(application.projectedAt).getTime()
282
- || new Date(receipt.completedAt).getTime() > new Date(application.deliveryExpiresAt).getTime();
283
- })) throw new Error("learning delivery binding is invalid; run the audit before learning");
284
- if (normalized.evaluations.some((contract) => {
285
- const candidate = normalized.candidates.find((item) => item.id === contract.learningId);
286
- return !candidate || !scopeContains(candidate.scope, contract.scope);
287
- })) throw new Error("learning evaluation scope is invalid; run the audit before learning");
288
- if (normalized.measurements.some((receipt) => {
289
- const candidate = normalized.candidates.find((item) => item.id === receipt.learningId);
290
- const contract = normalized.evaluations.find((item) => item.id === receipt.evaluationId);
291
- const evaluatorRoot = ROOT_BOUND_EVALUATIONS.has(contract?.schema)
292
- ? contract.evaluatorRoots.find((root) => root.evaluatorId === receipt.measurement?.evaluatorId) : null;
293
- return !candidate || !contract || !LINEAGE_EVALUATIONS.has(contract.schema)
294
- || contract.learningId !== receipt.learningId || !exactScope(contract.scope, receipt.scope)
295
- || contract.metric.name !== receipt.metric.name || contract.metric.direction !== receipt.metric.direction
296
- || !contract.evaluatorIds.includes(receipt.measurement.evaluatorId)
297
- || contract.benchmark.datasetDigest !== receipt.coverage.datasetDigest
298
- || (ROOT_BOUND_EVALUATIONS.has(contract.schema)
299
- && (receipt.schema !== "agentspine.learning-measurement/v2"
300
- || evaluatorRoot?.principalDigest !== receipt.measurement?.evaluatorRootDigest))
301
- || receipt.coverage.caseCount < contract.benchmark.minCases
302
- || !scopeContains(candidate.scope, receipt.scope)
303
- || new Date(receipt.measuredAt).getTime() < new Date(contract.registeredAt).getTime()
304
- || new Date(receipt.measuredAt).getTime() > new Date(contract.expiresAt).getTime();
305
- })) throw new Error("learning measurement binding is invalid; run the audit before learning");
306
- if (normalized.measurements.some((receipt) => {
307
- const contract = normalized.evaluations.find((entry) => entry.id === receipt.evaluationId);
308
- if (!INITIAL_TRIAL_EVALUATIONS.has(contract?.schema)) return false;
309
- const retainedByValidation = normalized.validationLeases.some((lease) =>
310
- lease?.renewalEvidence?.some((entry) => entry.measurementId === receipt.id
311
- && entry.measurementDigest === receipt.digest));
312
- if (retainedByValidation) return false;
313
- const revalidationApplication = receipt.phase === "after" ? normalized.applications.find((entry) =>
314
- entry.schema === "agentspine.learning-application/v4" && entry.learningId === receipt.learningId
315
- && entry.revalidationAdmission.evaluatorId === receipt.measurement?.evaluatorId
316
- && entry.revalidationAdmission.evaluatorRootDigest === receipt.measurement?.evaluatorRootDigest
317
- && entry.revalidationAdmission.runId === receipt.measurement?.runId) : null;
318
- if (revalidationApplication) {
319
- const delivery = normalized.deliveries.find((entry) => entry.applicationId === revalidationApplication.id);
320
- return !delivery || new Date(receipt.measuredAt).getTime() < new Date(delivery.completedAt).getTime();
321
- }
322
- const trial = contract.initialTrials?.[receipt.phase]?.find((entry) =>
323
- entry.evaluatorId === receipt.measurement?.evaluatorId);
324
- if (!trial || receipt.measurement.evaluatorRootDigest !== trial.evaluatorRootDigest
325
- || receipt.measurement.runId !== trial.runId || receipt.coverage.caseCount !== trial.caseCount) return true;
326
- if (receipt.phase !== "after") return false;
327
- const application = normalized.applications.find((entry) => INITIAL_TRIAL_APPLICATIONS.has(entry.schema)
328
- && entry.learningId === receipt.learningId && entry.initialAdmission.evaluationId === contract.id
329
- && entry.initialAdmission.evaluationDigest === contract.digest && entry.initialAdmission.slot === trial.slot
330
- && entry.initialAdmission.trialDigest === trial.trialDigest
331
- && (!TARGET_BOUND_EVALUATIONS.has(contract.schema)
332
- || (TARGET_BOUND_APPLICATIONS.has(entry.schema)
333
- && entry.initialAdmission.targetDigest === contract.target.digest)));
334
- const delivery = application && normalized.deliveries.find((entry) => entry.applicationId === application.id);
335
- return !delivery || new Date(receipt.measuredAt).getTime() < new Date(delivery.completedAt).getTime()
336
- || (DEADLINE_BOUND_APPLICATIONS.has(application.schema)
337
- && new Date(receipt.measuredAt).getTime() > new Date(application.outcomeExpiresAt).getTime());
338
- })) throw new Error("learning initial trial measurement binding is invalid; run the audit before learning");
339
- const pairedOutcomeKeys = new Set();
340
- const pairedAfterApplications = new Set();
341
- for (const receipt of normalized.outcomes) {
342
- if (!["agentspine.learning-outcome/v8", "agentspine.learning-outcome/v9"].includes(receipt.schema)) continue;
343
- const evaluatorKey = receipt.schema === "agentspine.learning-outcome/v9"
344
- ? receipt.measurement.evaluatorRootDigest : receipt.measurement.evaluatorId;
345
- const key = `${receipt.evaluationId}\0${receipt.phase}\0${evaluatorKey}`;
346
- if (pairedOutcomeKeys.has(key)) {
347
- throw new Error("learning paired evaluator outcome is duplicated; run the audit before learning");
348
- }
349
- pairedOutcomeKeys.add(key);
350
- if (receipt.phase === "after") {
351
- const applicationKey = `${receipt.evaluationId}\0${receipt.applicationId}`;
352
- if (pairedAfterApplications.has(applicationKey)) {
353
- throw new Error("learning paired outcome turn is duplicated; run the audit before learning");
354
- }
355
- pairedAfterApplications.add(applicationKey);
356
- }
357
- }
358
- if (normalized.outcomes.some((receipt) => ["agentspine.learning-outcome/v2", "agentspine.learning-outcome/v3", "agentspine.learning-outcome/v4", "agentspine.learning-outcome/v5", "agentspine.learning-outcome/v6", "agentspine.learning-outcome/v7", "agentspine.learning-outcome/v8", "agentspine.learning-outcome/v9"].includes(receipt.schema)
359
- && receipt.phase === "after" && !normalized.applications.some((application) => application.id === receipt.applicationId
360
- && application.learningId === receipt.learningId && exactScope(application.scope, receipt.scope)
361
- && new Date(receipt.measuredAt).getTime() >= new Date(application.projectedAt).getTime()
362
- && new Date(receipt.measuredAt).getTime() <= new Date(application.expiresAt).getTime()
363
- && (!DEADLINE_BOUND_APPLICATIONS.has(application.schema)
364
- || new Date(receipt.measuredAt).getTime() <= new Date(application.outcomeExpiresAt).getTime())))) {
365
- throw new Error("learning outcome application binding is invalid; run the audit before learning");
366
- }
367
- if (normalized.outcomes.some((receipt) => ["agentspine.learning-outcome/v3", "agentspine.learning-outcome/v4", "agentspine.learning-outcome/v5", "agentspine.learning-outcome/v6", "agentspine.learning-outcome/v7", "agentspine.learning-outcome/v8", "agentspine.learning-outcome/v9"].includes(receipt.schema)
368
- && !normalized.evaluations.some((contract) => contract.id === receipt.evaluationId
369
- && contract.learningId === receipt.learningId && exactScope(contract.scope, receipt.scope)
370
- && contract.metric.name === receipt.metric.name && contract.metric.direction === receipt.metric.direction
371
- && contract.evaluatorIds.includes(receipt.measurement.evaluatorId)
372
- && (receipt.schema !== "agentspine.learning-outcome/v9"
373
- || (ROOT_BOUND_EVALUATIONS.has(contract.schema)
374
- && contract.evaluatorRoots.some((root) => root.evaluatorId === receipt.measurement.evaluatorId
375
- && root.principalDigest === receipt.measurement.evaluatorRootDigest)))
376
- && new Date(receipt.measuredAt).getTime() >= new Date(contract.registeredAt).getTime()
377
- && new Date(receipt.measuredAt).getTime() <= new Date(contract.expiresAt).getTime()))) {
378
- throw new Error("learning outcome evaluation binding is invalid; run the audit before learning");
379
- }
380
- if (normalized.outcomes.some((receipt) => ["agentspine.learning-outcome/v5", "agentspine.learning-outcome/v6", "agentspine.learning-outcome/v7", "agentspine.learning-outcome/v8", "agentspine.learning-outcome/v9"].includes(receipt.schema)
381
- && !normalized.evaluations.some((contract) => contract.id === receipt.evaluationId
382
- && ((receipt.schema === "agentspine.learning-outcome/v5" && contract.schema === "agentspine.learning-evaluation/v2")
383
- || (receipt.schema === "agentspine.learning-outcome/v6" && contract.schema === "agentspine.learning-evaluation/v3")
384
- || (receipt.schema === "agentspine.learning-outcome/v7" && contract.schema === "agentspine.learning-evaluation/v4")
385
- || (receipt.schema === "agentspine.learning-outcome/v8" && contract.schema === "agentspine.learning-evaluation/v5")
386
- || (receipt.schema === "agentspine.learning-outcome/v9" && ROOT_BOUND_EVALUATIONS.has(contract.schema)))
387
- && receipt.coverage?.datasetDigest === contract.benchmark.datasetDigest
388
- && receipt.coverage?.caseCount >= contract.benchmark.minCases))) {
389
- throw new Error("learning outcome coverage binding is invalid; run the audit before learning");
390
- }
391
- const provenanceKeys = new Set();
392
- for (const receipt of normalized.outcomes) {
393
- if (receipt.schema !== "agentspine.learning-outcome/v6") continue;
394
- const key = `${receipt.evaluationId}\0${receipt.measurement?.sourceDigest || ""}`;
395
- if (!DIGEST_RE.test(receipt.measurement?.sourceDigest || "") || provenanceKeys.has(key)) {
396
- throw new Error("learning outcome provenance is missing or replayed; run the audit before learning");
397
- }
398
- provenanceKeys.add(key);
399
- }
400
- const measurementSources = new Set();
401
- const measurementRuns = new Set();
402
- const evaluatorRootRuns = new Set();
403
- const lineageIds = new Set();
404
- for (const lineage of normalized.measurementLineage) {
405
- if (measurementSources.has(lineage.sourceDigest) || measurementRuns.has(lineage.runDigest)
406
- || (lineage.schema === "agentspine.learning-measurement-lineage/v2" && evaluatorRootRuns.has(lineage.rootRunDigest))
407
- || lineageIds.has(lineage.measurementReceiptId)) {
408
- throw new Error("learning measurement lineage is replayed; run the audit before learning");
409
- }
410
- measurementSources.add(lineage.sourceDigest);
411
- measurementRuns.add(lineage.runDigest);
412
- if (lineage.schema === "agentspine.learning-measurement-lineage/v2") evaluatorRootRuns.add(lineage.rootRunDigest);
413
- lineageIds.add(lineage.measurementReceiptId);
414
- }
415
- if (normalized.measurements.some((receipt) => !normalized.measurementLineage.some((lineage) =>
416
- lineage.measurementReceiptId === receipt.id && lineage.learningId === receipt.learningId
417
- && lineage.evaluationId === receipt.evaluationId && lineage.sourceDigest === receipt.measurement.sourceDigest
418
- && lineage.runDigest === measurementRunDigest(receipt.measurement.evaluatorId, receipt.measurement.runId)
419
- && (receipt.schema !== "agentspine.learning-measurement/v2"
420
- || (lineage.schema === "agentspine.learning-measurement-lineage/v2"
421
- && lineage.evaluatorRootDigest === receipt.measurement.evaluatorRootDigest
422
- && lineage.rootRunDigest === evaluatorRootRunDigest(receipt.measurement.evaluatorRootDigest, receipt.measurement.runId)))
423
- && lineage.registeredAt === receipt.measuredAt))) {
424
- throw new Error("learning measurement lineage binding is invalid; run the audit before learning");
425
- }
426
- const consumedMeasurements = new Set();
427
- for (const receipt of normalized.outcomes) {
428
- if (!["agentspine.learning-outcome/v7", "agentspine.learning-outcome/v8", "agentspine.learning-outcome/v9"].includes(receipt.schema)) continue;
429
- const measurement = normalized.measurements.find((item) => item.id === receipt.measurementReceiptId);
430
- if (!measurement || measurement.digest !== receipt.measurementReceiptDigest
431
- || measurement.learningId !== receipt.learningId || measurement.evaluationId !== receipt.evaluationId
432
- || measurement.phase !== receipt.phase || !exactScope(measurement.scope, receipt.scope)
433
- || digest(measurement.metric) !== digest(receipt.metric) || digest(measurement.measurement) !== digest(receipt.measurement)
434
- || digest(measurement.coverage) !== digest(receipt.coverage) || measurement.measuredAt !== receipt.measuredAt
435
- || consumedMeasurements.has(measurement.id)) {
436
- throw new Error("learning outcome measurement binding is invalid or replayed; run the audit before learning");
437
- }
438
- consumedMeasurements.add(measurement.id);
439
- }
440
- if (normalized.outcomes.some((receipt) => ["agentspine.learning-outcome/v8", "agentspine.learning-outcome/v9"].includes(receipt.schema)
441
- && receipt.phase === "after" && !normalized.outcomes.some((before) =>
442
- before.schema === receipt.schema && before.phase === "before"
443
- && before.learningId === receipt.learningId && before.evaluationId === receipt.evaluationId
444
- && before.measurement.evaluatorId === receipt.measurement.evaluatorId
445
- && (receipt.schema !== "agentspine.learning-outcome/v9"
446
- || before.measurement.evaluatorRootDigest === receipt.measurement.evaluatorRootDigest)
447
- && before.measurement.kind === receipt.measurement.kind
448
- && before.coverage.caseCount === receipt.coverage.caseCount
449
- && exactScope(before.scope, receipt.scope)))) {
450
- throw new Error("learning paired outcome evaluator binding is invalid; run the audit before learning");
451
- }
452
- if (normalized.outcomes.some((receipt) => ["agentspine.learning-outcome/v4", "agentspine.learning-outcome/v5", "agentspine.learning-outcome/v6", "agentspine.learning-outcome/v7", "agentspine.learning-outcome/v8", "agentspine.learning-outcome/v9"].includes(receipt.schema)
453
- && (receipt.phase === "after" ? !normalized.deliveries.some((delivery) => delivery.id === receipt.deliveryId
454
- && delivery.applicationId === receipt.applicationId && delivery.learningId === receipt.learningId
455
- && exactScope(delivery.scope, receipt.scope)
456
- && new Date(receipt.measuredAt).getTime() >= new Date(delivery.completedAt).getTime()) : receipt.deliveryId !== null))) {
457
- throw new Error("learning outcome delivery binding is invalid; run the audit before learning");
458
- }
459
- if (normalized.candidates.some((candidate) => candidate.status === "accepted"
460
- && candidate.promotion?.mode === "outcome-canary" && candidate.promotion.canary?.evaluationId
461
- && !normalized.evaluations.some((contract) => contract.id === candidate.promotion.canary.evaluationId
462
- && contract.learningId === candidate.id && contract.digest === candidate.promotion.canary.evaluationDigest
463
- && exactScope(contract.scope, candidate.promotion.canary.scope)
464
- && (!TARGET_BOUND_EVALUATIONS.has(contract.schema)
465
- || (candidate.promotion.canary.targetDigest === contract.target.digest
466
- && learningTargetMatchesCandidate(contract.target, candidate)))
467
- && (!DEADLINE_BOUND_EVALUATIONS.has(contract.schema)
468
- || candidate.promotion.canary.completionPolicyDigest === contract.completionPolicy.digest)
469
- && (!STALENESS_BOUND_EVALUATIONS.has(contract.schema)
470
- || candidate.promotion.canary.stalenessPolicyDigest === contract.stalenessPolicy.digest)))) {
471
- throw new Error("learning canary evaluation binding is invalid; run the audit before learning");
472
- }
473
- if (normalized.validationLeases.some((lease) => !validationLeaseMatchesState(normalized, lease))) {
474
- throw new Error("learning validation lease binding is invalid; run the audit before learning");
475
- }
476
- return normalized;
477
- }