blun-king-cli 9.1.643 → 9.1.645

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 (268) hide show
  1. package/CHANGELOG.md +19 -123
  2. package/LIESMICH.txt +17 -45
  3. package/README.md +15 -76
  4. package/RELEASE-9.1.645.md +29 -0
  5. package/bin/blun.js +3 -3
  6. package/bin/king.js +3 -3
  7. package/bin/launcher-mode.js +125 -126
  8. package/bin/launcher-runtime.js +603 -616
  9. package/bin/plugin-bootstrap.js +339 -405
  10. package/bin/rename-private-staging.cjs +2 -2
  11. package/bin/retired-bundled-plugins.cjs +84 -0
  12. package/bin/startup-security-host.cjs +105 -0
  13. package/bin/startup-security.cjs +9 -105
  14. package/bin/startup-warning-policy.cjs +22 -0
  15. package/bin/update-lease-installer.cjs +125 -0
  16. package/bin/update-lease-sockets.cjs +228 -0
  17. package/bin/update-lease.js +22 -327
  18. package/bin/verify-bundled-agent-sources.cjs +2 -4
  19. package/blun.mjs +77 -180
  20. package/bundled-agent-sources.json +1 -552
  21. package/package.json +3 -6
  22. package/tool-liveness642/receipt.json +1 -1
  23. package/worker-host.mjs +62 -120
  24. package/agent-spine-plugin/.claude-plugin/marketplace.json +0 -20
  25. package/agent-spine-plugin/.claude-plugin/plugin.json +0 -14
  26. package/agent-spine-plugin/.codex-plugin/plugin.json +0 -47
  27. package/agent-spine-plugin/.mcp.json +0 -8
  28. package/agent-spine-plugin/CHANGELOG.md +0 -1614
  29. package/agent-spine-plugin/LICENSE +0 -186
  30. package/agent-spine-plugin/README.md +0 -432
  31. package/agent-spine-plugin/assets/agentspine-banner.svg +0 -32
  32. package/agent-spine-plugin/bin/agentspine-mcp.js +0 -4
  33. package/agent-spine-plugin/bin/agentspine.js +0 -7
  34. package/agent-spine-plugin/blun.plugin.json +0 -68
  35. package/agent-spine-plugin/docs/acceptance.md +0 -61
  36. package/agent-spine-plugin/docs/artifact-evaluation.md +0 -93
  37. package/agent-spine-plugin/docs/host-integration.md +0 -193
  38. package/agent-spine-plugin/docs/preflight-recall.md +0 -71
  39. package/agent-spine-plugin/docs/preservation-contract.md +0 -53
  40. package/agent-spine-plugin/docs/quality-gates.md +0 -50
  41. package/agent-spine-plugin/docs/session-timeline.md +0 -112
  42. package/agent-spine-plugin/docs/source-roots.md +0 -113
  43. package/agent-spine-plugin/docs/world-model.md +0 -119
  44. package/agent-spine-plugin/hooks/codex.json +0 -47
  45. package/agent-spine-plugin/hooks/hooks.json +0 -106
  46. package/agent-spine-plugin/hooks/version.json +0 -5
  47. package/agent-spine-plugin/package.json +0 -77
  48. package/agent-spine-plugin/scripts/check-codex-install.js +0 -226
  49. package/agent-spine-plugin/scripts/check-hosts.js +0 -208
  50. package/agent-spine-plugin/scripts/check-install-hook.js +0 -227
  51. package/agent-spine-plugin/scripts/check-install-selfstarter.js +0 -154
  52. package/agent-spine-plugin/scripts/check-install.js +0 -478
  53. package/agent-spine-plugin/scripts/check-line-budget.js +0 -58
  54. package/agent-spine-plugin/scripts/check-syntax.js +0 -29
  55. package/agent-spine-plugin/scripts/github-actions.js +0 -11
  56. package/agent-spine-plugin/scripts/hermetic-process.js +0 -191
  57. package/agent-spine-plugin/scripts/release-check.js +0 -150
  58. package/agent-spine-plugin/scripts/run-acceptance.js +0 -19
  59. package/agent-spine-plugin/scripts/run-checks.js +0 -50
  60. package/agent-spine-plugin/scripts/run-tests-hermetic.js +0 -112
  61. package/agent-spine-plugin/skills/agent-spine/SKILL.md +0 -99
  62. package/agent-spine-plugin/spine-example/1-identity.md +0 -12
  63. package/agent-spine-plugin/spine-example/2-voice.md +0 -6
  64. package/agent-spine-plugin/spine-example/3-conduct.md +0 -8
  65. package/agent-spine-plugin/spine-example/4-history.md +0 -4
  66. package/agent-spine-plugin/src/cli-agent.js +0 -315
  67. package/agent-spine-plugin/src/cli-attention.js +0 -95
  68. package/agent-spine-plugin/src/cli-autonomy.js +0 -36
  69. package/agent-spine-plugin/src/cli-common.js +0 -71
  70. package/agent-spine-plugin/src/cli-continuity.js +0 -116
  71. package/agent-spine-plugin/src/cli-core.js +0 -128
  72. package/agent-spine-plugin/src/cli-diagnostics.js +0 -291
  73. package/agent-spine-plugin/src/cli-host.js +0 -21
  74. package/agent-spine-plugin/src/cli-learning.js +0 -320
  75. package/agent-spine-plugin/src/cli-premortem.js +0 -16
  76. package/agent-spine-plugin/src/cli-sharing.js +0 -230
  77. package/agent-spine-plugin/src/cli.js +0 -181
  78. package/agent-spine-plugin/src/codex-reader-launcher.js +0 -182
  79. package/agent-spine-plugin/src/hook.js +0 -500
  80. package/agent-spine-plugin/src/index.js +0 -108
  81. package/agent-spine-plugin/src/lib/acceptance.js +0 -435
  82. package/agent-spine-plugin/src/lib/action-lesson-recall.js +0 -118
  83. package/agent-spine-plugin/src/lib/attention-context.js +0 -167
  84. package/agent-spine-plugin/src/lib/attention-events.js +0 -113
  85. package/agent-spine-plugin/src/lib/attention-privacy.js +0 -72
  86. package/agent-spine-plugin/src/lib/attention-schema.js +0 -164
  87. package/agent-spine-plugin/src/lib/attention-storage.js +0 -93
  88. package/agent-spine-plugin/src/lib/attention.js +0 -164
  89. package/agent-spine-plugin/src/lib/audit-premortem.js +0 -223
  90. package/agent-spine-plugin/src/lib/audit.js +0 -401
  91. package/agent-spine-plugin/src/lib/authentication.js +0 -515
  92. package/agent-spine-plugin/src/lib/autonomy-policy.js +0 -110
  93. package/agent-spine-plugin/src/lib/autonomy-store.js +0 -202
  94. package/agent-spine-plugin/src/lib/autonomy.js +0 -8
  95. package/agent-spine-plugin/src/lib/briefing.js +0 -493
  96. package/agent-spine-plugin/src/lib/catalog-document-read.js +0 -51
  97. package/agent-spine-plugin/src/lib/catalog.js +0 -167
  98. package/agent-spine-plugin/src/lib/channel-continuity.js +0 -19
  99. package/agent-spine-plugin/src/lib/channel-runtime.js +0 -665
  100. package/agent-spine-plugin/src/lib/codex-installation.js +0 -231
  101. package/agent-spine-plugin/src/lib/codex-skill-installation.js +0 -211
  102. package/agent-spine-plugin/src/lib/context.js +0 -156
  103. package/agent-spine-plugin/src/lib/continuity.js +0 -338
  104. package/agent-spine-plugin/src/lib/coordination.js +0 -577
  105. package/agent-spine-plugin/src/lib/delivery-agent-usage.js +0 -231
  106. package/agent-spine-plugin/src/lib/delivery-assignment.js +0 -220
  107. package/agent-spine-plugin/src/lib/delivery-command-actions.js +0 -462
  108. package/agent-spine-plugin/src/lib/delivery-knowledge.js +0 -78
  109. package/agent-spine-plugin/src/lib/delivery-premortem-binding.js +0 -107
  110. package/agent-spine-plugin/src/lib/delivery-premortem-closure.js +0 -171
  111. package/agent-spine-plugin/src/lib/delivery-premortem-codec.js +0 -45
  112. package/agent-spine-plugin/src/lib/delivery-premortem-correction.js +0 -101
  113. package/agent-spine-plugin/src/lib/delivery-premortem-file.js +0 -21
  114. package/agent-spine-plugin/src/lib/delivery-premortem-index.js +0 -493
  115. package/agent-spine-plugin/src/lib/delivery-premortem-inspection.js +0 -37
  116. package/agent-spine-plugin/src/lib/delivery-premortem-recovery.js +0 -120
  117. package/agent-spine-plugin/src/lib/delivery-premortem-rejection.js +0 -65
  118. package/agent-spine-plugin/src/lib/delivery-premortem-results.js +0 -28
  119. package/agent-spine-plugin/src/lib/delivery-premortem-session-guard.js +0 -46
  120. package/agent-spine-plugin/src/lib/delivery-premortem-write-ledger.js +0 -285
  121. package/agent-spine-plugin/src/lib/delivery-premortem.js +0 -499
  122. package/agent-spine-plugin/src/lib/delivery-shell-heredoc.js +0 -115
  123. package/agent-spine-plugin/src/lib/delivery-shell-substitutions.js +0 -111
  124. package/agent-spine-plugin/src/lib/delivery-shell-wrapper.js +0 -64
  125. package/agent-spine-plugin/src/lib/delivery-target.js +0 -73
  126. package/agent-spine-plugin/src/lib/delivery-verification.js +0 -445
  127. package/agent-spine-plugin/src/lib/documents.js +0 -239
  128. package/agent-spine-plugin/src/lib/feed-transport.js +0 -499
  129. package/agent-spine-plugin/src/lib/filesystem-retry.js +0 -34
  130. package/agent-spine-plugin/src/lib/gateway-common.js +0 -68
  131. package/agent-spine-plugin/src/lib/gateway-control.js +0 -370
  132. package/agent-spine-plugin/src/lib/gateway-delivery.js +0 -103
  133. package/agent-spine-plugin/src/lib/gateway-execution.js +0 -350
  134. package/agent-spine-plugin/src/lib/gateway-group-response.js +0 -128
  135. package/agent-spine-plugin/src/lib/gateway-host-fencing.js +0 -92
  136. package/agent-spine-plugin/src/lib/gateway-host-lifecycle.js +0 -193
  137. package/agent-spine-plugin/src/lib/gateway-inspection.js +0 -85
  138. package/agent-spine-plugin/src/lib/gateway-knowledge.js +0 -129
  139. package/agent-spine-plugin/src/lib/gateway-policy-provenance.js +0 -197
  140. package/agent-spine-plugin/src/lib/gateway-premortem-disposition.js +0 -82
  141. package/agent-spine-plugin/src/lib/gateway-premortem.js +0 -363
  142. package/agent-spine-plugin/src/lib/gateway-prepared-host.js +0 -28
  143. package/agent-spine-plugin/src/lib/gateway-runs.js +0 -345
  144. package/agent-spine-plugin/src/lib/gateway-runtime-identity.js +0 -31
  145. package/agent-spine-plugin/src/lib/gateway-runtime-records.js +0 -21
  146. package/agent-spine-plugin/src/lib/gateway-runtime.js +0 -18
  147. package/agent-spine-plugin/src/lib/gateway-state-transaction.js +0 -356
  148. package/agent-spine-plugin/src/lib/gateway-state.js +0 -344
  149. package/agent-spine-plugin/src/lib/graph.js +0 -337
  150. package/agent-spine-plugin/src/lib/hook-artifact-guards.js +0 -356
  151. package/agent-spine-plugin/src/lib/hook-audit.js +0 -43
  152. package/agent-spine-plugin/src/lib/hook-briefing-use.js +0 -78
  153. package/agent-spine-plugin/src/lib/hook-context.js +0 -441
  154. package/agent-spine-plugin/src/lib/hook-final-message.js +0 -26
  155. package/agent-spine-plugin/src/lib/hook-input.js +0 -27
  156. package/agent-spine-plugin/src/lib/hook-output.js +0 -284
  157. package/agent-spine-plugin/src/lib/hook-premortem.js +0 -257
  158. package/agent-spine-plugin/src/lib/hook-process-advisory.js +0 -36
  159. package/agent-spine-plugin/src/lib/hook-protection.js +0 -95
  160. package/agent-spine-plugin/src/lib/hook-stop-verification.js +0 -84
  161. package/agent-spine-plugin/src/lib/hook-timeline.js +0 -102
  162. package/agent-spine-plugin/src/lib/host-instruction-budget.js +0 -11
  163. package/agent-spine-plugin/src/lib/https-transport.js +0 -392
  164. package/agent-spine-plugin/src/lib/identifier-analysis.js +0 -446
  165. package/agent-spine-plugin/src/lib/indexed-memory-offline.js +0 -40
  166. package/agent-spine-plugin/src/lib/indexed-memory.js +0 -298
  167. package/agent-spine-plugin/src/lib/knowledge-evidence.js +0 -431
  168. package/agent-spine-plugin/src/lib/learning-applications.js +0 -441
  169. package/agent-spine-plugin/src/lib/learning-artifact-evaluator.js +0 -114
  170. package/agent-spine-plugin/src/lib/learning-candidates.js +0 -274
  171. package/agent-spine-plugin/src/lib/learning-context.js +0 -137
  172. package/agent-spine-plugin/src/lib/learning-delivery-contracts.js +0 -310
  173. package/agent-spine-plugin/src/lib/learning-evaluation-contracts.js +0 -350
  174. package/agent-spine-plugin/src/lib/learning-evaluation-registration.js +0 -372
  175. package/agent-spine-plugin/src/lib/learning-evaluation-revocation.js +0 -292
  176. package/agent-spine-plugin/src/lib/learning-evidence-contracts.js +0 -321
  177. package/agent-spine-plugin/src/lib/learning-findings.js +0 -458
  178. package/agent-spine-plugin/src/lib/learning-measurement-contracts.js +0 -285
  179. package/agent-spine-plugin/src/lib/learning-measurements.js +0 -265
  180. package/agent-spine-plugin/src/lib/learning-outcome-contracts.js +0 -165
  181. package/agent-spine-plugin/src/lib/learning-outcomes.js +0 -343
  182. package/agent-spine-plugin/src/lib/learning-reconciliation.js +0 -290
  183. package/agent-spine-plugin/src/lib/learning-retry-contracts.js +0 -188
  184. package/agent-spine-plugin/src/lib/learning-schema.js +0 -229
  185. package/agent-spine-plugin/src/lib/learning-scope-targets.js +0 -424
  186. package/agent-spine-plugin/src/lib/learning-state-upgrade.js +0 -477
  187. package/agent-spine-plugin/src/lib/learning-status-configuration.js +0 -476
  188. package/agent-spine-plugin/src/lib/learning-storage.js +0 -203
  189. package/agent-spine-plugin/src/lib/learning-trial-recovery.js +0 -218
  190. package/agent-spine-plugin/src/lib/learning-validation-contracts.js +0 -375
  191. package/agent-spine-plugin/src/lib/learning-validation-renewal.js +0 -298
  192. package/agent-spine-plugin/src/lib/learning-validation-runtime.js +0 -234
  193. package/agent-spine-plugin/src/lib/learning.js +0 -36
  194. package/agent-spine-plugin/src/lib/lesson-recall-session.js +0 -172
  195. package/agent-spine-plugin/src/lib/mcp-autonomy-tools.js +0 -37
  196. package/agent-spine-plugin/src/lib/mcp-delivery-completion.js +0 -124
  197. package/agent-spine-plugin/src/lib/mcp-delivery-tools.js +0 -45
  198. package/agent-spine-plugin/src/lib/mcp-premortem.js +0 -68
  199. package/agent-spine-plugin/src/lib/mcp-runtime.js +0 -355
  200. package/agent-spine-plugin/src/lib/mcp-source-context.js +0 -61
  201. package/agent-spine-plugin/src/lib/mcp-timeline-tools.js +0 -240
  202. package/agent-spine-plugin/src/lib/mcp-world-tools.js +0 -52
  203. package/agent-spine-plugin/src/lib/object-transport.js +0 -206
  204. package/agent-spine-plugin/src/lib/owned-file-lock.js +0 -182
  205. package/agent-spine-plugin/src/lib/paths.js +0 -109
  206. package/agent-spine-plugin/src/lib/peer-transport.js +0 -283
  207. package/agent-spine-plugin/src/lib/persona-runtime.js +0 -581
  208. package/agent-spine-plugin/src/lib/pre-answer-timeline-recall.js +0 -104
  209. package/agent-spine-plugin/src/lib/preflight-delivery-id.js +0 -27
  210. package/agent-spine-plugin/src/lib/preflight.js +0 -688
  211. package/agent-spine-plugin/src/lib/project-portfolio.js +0 -176
  212. package/agent-spine-plugin/src/lib/runtime.js +0 -13
  213. package/agent-spine-plugin/src/lib/selfstarter-core.js +0 -382
  214. package/agent-spine-plugin/src/lib/selfstarter-jobs.js +0 -149
  215. package/agent-spine-plugin/src/lib/selfstarter-lease.js +0 -204
  216. package/agent-spine-plugin/src/lib/selfstarter-policy.js +0 -90
  217. package/agent-spine-plugin/src/lib/selfstarter-workspace.js +0 -111
  218. package/agent-spine-plugin/src/lib/selfstarter.js +0 -11
  219. package/agent-spine-plugin/src/lib/session-timeline-auth.js +0 -316
  220. package/agent-spine-plugin/src/lib/session-timeline-codex.js +0 -69
  221. package/agent-spine-plugin/src/lib/session-timeline-contract.js +0 -56
  222. package/agent-spine-plugin/src/lib/session-timeline-enrollment-source.js +0 -38
  223. package/agent-spine-plugin/src/lib/session-timeline-enrollment-storage.js +0 -128
  224. package/agent-spine-plugin/src/lib/session-timeline-enrollment-transport.js +0 -15
  225. package/agent-spine-plugin/src/lib/session-timeline-enrollment.js +0 -478
  226. package/agent-spine-plugin/src/lib/session-timeline-event-extract.js +0 -186
  227. package/agent-spine-plugin/src/lib/session-timeline-host-origin.js +0 -73
  228. package/agent-spine-plugin/src/lib/session-timeline-host-receipt.js +0 -117
  229. package/agent-spine-plugin/src/lib/session-timeline-invocation.js +0 -201
  230. package/agent-spine-plugin/src/lib/session-timeline-king.js +0 -93
  231. package/agent-spine-plugin/src/lib/session-timeline-prior.js +0 -57
  232. package/agent-spine-plugin/src/lib/session-timeline-provider.js +0 -36
  233. package/agent-spine-plugin/src/lib/session-timeline-query.js +0 -56
  234. package/agent-spine-plugin/src/lib/session-timeline-results.js +0 -56
  235. package/agent-spine-plugin/src/lib/session-timeline-root.js +0 -11
  236. package/agent-spine-plugin/src/lib/session-timeline-search.js +0 -82
  237. package/agent-spine-plugin/src/lib/session-timeline-sid-acl.js +0 -213
  238. package/agent-spine-plugin/src/lib/session-timeline-source-open.js +0 -30
  239. package/agent-spine-plugin/src/lib/session-timeline-source.js +0 -80
  240. package/agent-spine-plugin/src/lib/session-timeline-state.js +0 -45
  241. package/agent-spine-plugin/src/lib/session-timeline-transport.js +0 -42
  242. package/agent-spine-plugin/src/lib/session-timeline-windows-acl.js +0 -145
  243. package/agent-spine-plugin/src/lib/session-timeline.js +0 -462
  244. package/agent-spine-plugin/src/lib/sharing.js +0 -969
  245. package/agent-spine-plugin/src/lib/source-roots.js +0 -475
  246. package/agent-spine-plugin/src/lib/source-tree-scan.js +0 -178
  247. package/agent-spine-plugin/src/lib/sqlite-transport.js +0 -501
  248. package/agent-spine-plugin/src/lib/task-knowledge-context.js +0 -99
  249. package/agent-spine-plugin/src/lib/telegram-adapter.js +0 -119
  250. package/agent-spine-plugin/src/lib/timeline-continuation-update.js +0 -100
  251. package/agent-spine-plugin/src/lib/timeline-tool-guard.js +0 -225
  252. package/agent-spine-plugin/src/lib/timeline-user-feedback.js +0 -216
  253. package/agent-spine-plugin/src/lib/timeline-world-capture.js +0 -233
  254. package/agent-spine-plugin/src/lib/voice-runtime.js +0 -39
  255. package/agent-spine-plugin/src/lib/world-knowledge.js +0 -306
  256. package/agent-spine-plugin/src/lib/world-model.js +0 -333
  257. package/agent-spine-plugin/src/mcp.js +0 -456
  258. package/agent-spine-plugin/src/version.js +0 -1
  259. package/agent-spine-plugin/src/worker.js +0 -257
  260. package/bin/agentspine-king-goal-inbox.mjs +0 -127
  261. package/bin/agentspine-king-goal-intake.mjs +0 -106
  262. package/bin/agentspine-king-host-runner.mjs +0 -109
  263. package/bin/agentspine-king-snapshot-policy.cjs +0 -80
  264. package/bin/agentspine-king-status-policy.mjs +0 -226
  265. package/bin/agentspine-king-worker-host.mjs +0 -160
  266. package/bin/managed-plugin-selection.cjs +0 -141
  267. package/bin/verify-agent-behavior.cjs +0 -122
  268. package/bin/verify-agent-components.cjs +0 -104
@@ -1,229 +0,0 @@
1
- export const KINDS = new Set(["preference", "no-go", "goal", "correction", "personal-fact", "project-fact", "reference", "behavior"]);
2
-
3
- export const EVIDENCE_TYPES = new Set(["user-statement", "document", "interaction", "test"]);
4
-
5
- export const PRIVACY = new Set(["private", "shared", "group"]);
6
-
7
- export const STATUSES = new Set(["candidate", "accepted", "rejected", "superseded", "rolled-back"]);
8
-
9
- export const AUTO_KINDS = new Set(["project-fact", "reference"]);
10
-
11
- export const OUTCOME_AUTO_KINDS = new Set(["behavior"]);
12
-
13
- export const CONTINUITY_AUTO_KINDS = new Set(["preference", "no-go", "correction", "project-fact", "reference"]);
14
-
15
- export const OUTCOME_PHASES = new Set(["before", "after"]);
16
-
17
- export const MEASUREMENT_KINDS = new Set(["objective", "user-feedback", "model-suggestion"]);
18
-
19
- export const METRIC_DIRECTIONS = new Set(["higher", "lower"]);
20
-
21
- export const SCOPE_FIELDS = ["personaId", "userId", "tenantId", "projectId", "groupId", "taskId"];
22
-
23
- export const ID_RE = /^[A-Za-z0-9][A-Za-z0-9:_.@/-]{0,127}$/;
24
-
25
- export const DIGEST_RE = /^[a-f0-9]{64}$/;
26
-
27
- export const MAX_STATE_BYTES = 5 * 1024 * 1024;
28
-
29
- export const SECRET_RE = /-----BEGIN [A-Z ]*PRIVATE KEY-----|\b(?:sk|gh[opusu])_[A-Za-z0-9_-]{20,}\b|\bBearer\s+[A-Za-z0-9._~+/-]{20,}|\b(?:api[-_ ]?key|token|password|secret)\s*[:=]\s*\S{8,}|\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b/i;
30
-
31
- export const AUTHORITY_ASSERTION_RE = /\b(?:user|agent|person|they|he|she|i|ich|wir|nutzer|benutzer).{0,60}\b(?:may|can|is allowed|is authorized|has|have|darf|berechtigt|hat|haben).{0,50}\b(?:admin(?:istrator)?|permissions?|rights?|authorization|production access|deploy|billing|spending|policy exception|bypass|zugang|rechte|berechtigung|produktion|abrechnung|ausnahme|umgehen)\b/i;
32
-
33
- export const PROTECTED_LESSON_RE = /\b(?:security|safety|identity|authentication|authorization|permissions?|credentials?|secrets?|policy|production|deployment|payments?|billing|tool access|file access|network access|database access|sicherheit|identität|authentifizierung|berechtigungen?|zugang|richtlinie|produktion|zahlungen?)\b/i;
34
-
35
- export const EVALUATION_SCHEMAS = new Set(Array.from({ length: 29 }, (_, index) =>
36
- `agentspine.learning-evaluation/v${index + 1}`));
37
-
38
- export const COVERAGE_EVALUATIONS = new Set(Array.from({ length: 28 }, (_, index) =>
39
- `agentspine.learning-evaluation/v${index + 2}`));
40
-
41
- export const LINEAGE_EVALUATIONS = new Set(Array.from({ length: 26 }, (_, index) =>
42
- `agentspine.learning-evaluation/v${index + 4}`));
43
-
44
- export const PAIRED_EVALUATIONS = new Set(Array.from({ length: 25 }, (_, index) =>
45
- `agentspine.learning-evaluation/v${index + 5}`));
46
-
47
- export const ROOT_BOUND_EVALUATIONS = new Set(Array.from({ length: 24 }, (_, index) =>
48
- `agentspine.learning-evaluation/v${index + 6}`));
49
-
50
- export const REGISTRY_BOUND_EVALUATIONS = new Set(Array.from({ length: 23 }, (_, index) =>
51
- `agentspine.learning-evaluation/v${index + 7}`));
52
-
53
- export const INITIAL_TRIAL_EVALUATIONS = new Set(["agentspine.learning-evaluation/v8", "agentspine.learning-evaluation/v9",
54
- "agentspine.learning-evaluation/v10", "agentspine.learning-evaluation/v11", "agentspine.learning-evaluation/v12",
55
- "agentspine.learning-evaluation/v13", "agentspine.learning-evaluation/v14", "agentspine.learning-evaluation/v15",
56
- "agentspine.learning-evaluation/v16", "agentspine.learning-evaluation/v17",
57
- "agentspine.learning-evaluation/v18", "agentspine.learning-evaluation/v19",
58
- "agentspine.learning-evaluation/v20", "agentspine.learning-evaluation/v21",
59
- "agentspine.learning-evaluation/v22", "agentspine.learning-evaluation/v23",
60
- "agentspine.learning-evaluation/v24", "agentspine.learning-evaluation/v25",
61
- "agentspine.learning-evaluation/v26", "agentspine.learning-evaluation/v27",
62
- "agentspine.learning-evaluation/v28", "agentspine.learning-evaluation/v29"]);
63
-
64
- export const TARGET_BOUND_EVALUATIONS = new Set(["agentspine.learning-evaluation/v9", "agentspine.learning-evaluation/v10",
65
- "agentspine.learning-evaluation/v11", "agentspine.learning-evaluation/v12", "agentspine.learning-evaluation/v13",
66
- "agentspine.learning-evaluation/v14", "agentspine.learning-evaluation/v15", "agentspine.learning-evaluation/v16",
67
- "agentspine.learning-evaluation/v17", "agentspine.learning-evaluation/v18",
68
- "agentspine.learning-evaluation/v19", "agentspine.learning-evaluation/v20",
69
- "agentspine.learning-evaluation/v21", "agentspine.learning-evaluation/v22",
70
- "agentspine.learning-evaluation/v23", "agentspine.learning-evaluation/v24",
71
- "agentspine.learning-evaluation/v25", "agentspine.learning-evaluation/v26",
72
- "agentspine.learning-evaluation/v27", "agentspine.learning-evaluation/v28",
73
- "agentspine.learning-evaluation/v29"]);
74
-
75
- export const DEADLINE_BOUND_EVALUATIONS = new Set(["agentspine.learning-evaluation/v10", "agentspine.learning-evaluation/v11",
76
- "agentspine.learning-evaluation/v12", "agentspine.learning-evaluation/v13", "agentspine.learning-evaluation/v14",
77
- "agentspine.learning-evaluation/v15", "agentspine.learning-evaluation/v16", "agentspine.learning-evaluation/v17",
78
- "agentspine.learning-evaluation/v18", "agentspine.learning-evaluation/v19",
79
- "agentspine.learning-evaluation/v20", "agentspine.learning-evaluation/v21",
80
- "agentspine.learning-evaluation/v22", "agentspine.learning-evaluation/v23",
81
- "agentspine.learning-evaluation/v24", "agentspine.learning-evaluation/v25",
82
- "agentspine.learning-evaluation/v26", "agentspine.learning-evaluation/v27",
83
- "agentspine.learning-evaluation/v28", "agentspine.learning-evaluation/v29"]);
84
-
85
- export const TRIAL_RETRY_EVALUATIONS = new Set(["agentspine.learning-evaluation/v11", "agentspine.learning-evaluation/v12",
86
- "agentspine.learning-evaluation/v13", "agentspine.learning-evaluation/v15", "agentspine.learning-evaluation/v17",
87
- "agentspine.learning-evaluation/v19", "agentspine.learning-evaluation/v21",
88
- "agentspine.learning-evaluation/v23", "agentspine.learning-evaluation/v25",
89
- "agentspine.learning-evaluation/v27", "agentspine.learning-evaluation/v29"]);
90
-
91
- export const COMPARABLE_TRIAL_RETRY_EVALUATIONS = new Set(["agentspine.learning-evaluation/v12",
92
- "agentspine.learning-evaluation/v13", "agentspine.learning-evaluation/v15", "agentspine.learning-evaluation/v17",
93
- "agentspine.learning-evaluation/v19", "agentspine.learning-evaluation/v21",
94
- "agentspine.learning-evaluation/v23", "agentspine.learning-evaluation/v25",
95
- "agentspine.learning-evaluation/v27", "agentspine.learning-evaluation/v29"]);
96
-
97
- export const BOUNDED_TRIAL_RETRY_EVALUATIONS = new Set(["agentspine.learning-evaluation/v13",
98
- "agentspine.learning-evaluation/v15", "agentspine.learning-evaluation/v17",
99
- "agentspine.learning-evaluation/v19", "agentspine.learning-evaluation/v21",
100
- "agentspine.learning-evaluation/v23", "agentspine.learning-evaluation/v25",
101
- "agentspine.learning-evaluation/v27", "agentspine.learning-evaluation/v29"]);
102
-
103
- export const STALENESS_BOUND_EVALUATIONS = new Set(["agentspine.learning-evaluation/v14",
104
- "agentspine.learning-evaluation/v15", "agentspine.learning-evaluation/v16", "agentspine.learning-evaluation/v17",
105
- "agentspine.learning-evaluation/v18", "agentspine.learning-evaluation/v19",
106
- "agentspine.learning-evaluation/v20", "agentspine.learning-evaluation/v21",
107
- "agentspine.learning-evaluation/v22", "agentspine.learning-evaluation/v23",
108
- "agentspine.learning-evaluation/v24", "agentspine.learning-evaluation/v25",
109
- "agentspine.learning-evaluation/v26", "agentspine.learning-evaluation/v27",
110
- "agentspine.learning-evaluation/v28", "agentspine.learning-evaluation/v29"]);
111
-
112
- export const PROMOTION_BOUND_EVALUATIONS = new Set(["agentspine.learning-evaluation/v16",
113
- "agentspine.learning-evaluation/v17", "agentspine.learning-evaluation/v18",
114
- "agentspine.learning-evaluation/v19", "agentspine.learning-evaluation/v20",
115
- "agentspine.learning-evaluation/v21", "agentspine.learning-evaluation/v22",
116
- "agentspine.learning-evaluation/v23", "agentspine.learning-evaluation/v24",
117
- "agentspine.learning-evaluation/v25", "agentspine.learning-evaluation/v26",
118
- "agentspine.learning-evaluation/v27", "agentspine.learning-evaluation/v28",
119
- "agentspine.learning-evaluation/v29"]);
120
-
121
- export const CANDIDATE_ADMISSION_EVALUATIONS = new Set(["agentspine.learning-evaluation/v18",
122
- "agentspine.learning-evaluation/v19", "agentspine.learning-evaluation/v20",
123
- "agentspine.learning-evaluation/v21", "agentspine.learning-evaluation/v22",
124
- "agentspine.learning-evaluation/v23", "agentspine.learning-evaluation/v24",
125
- "agentspine.learning-evaluation/v25", "agentspine.learning-evaluation/v26",
126
- "agentspine.learning-evaluation/v27", "agentspine.learning-evaluation/v28",
127
- "agentspine.learning-evaluation/v29"]);
128
-
129
- export const CANDIDATE_EVIDENCE_BOUND_EVALUATIONS = new Set(["agentspine.learning-evaluation/v20",
130
- "agentspine.learning-evaluation/v21", "agentspine.learning-evaluation/v22",
131
- "agentspine.learning-evaluation/v23", "agentspine.learning-evaluation/v24",
132
- "agentspine.learning-evaluation/v25", "agentspine.learning-evaluation/v26",
133
- "agentspine.learning-evaluation/v27", "agentspine.learning-evaluation/v28",
134
- "agentspine.learning-evaluation/v29"]);
135
-
136
- export const BLOCKING_DEFECT_BOUND_EVALUATIONS = new Set(["agentspine.learning-evaluation/v22",
137
- "agentspine.learning-evaluation/v23", "agentspine.learning-evaluation/v24",
138
- "agentspine.learning-evaluation/v25", "agentspine.learning-evaluation/v26",
139
- "agentspine.learning-evaluation/v27", "agentspine.learning-evaluation/v28",
140
- "agentspine.learning-evaluation/v29"]);
141
-
142
- export const EVIDENCE_SOURCE_BOUND_EVALUATIONS = new Set(["agentspine.learning-evaluation/v24",
143
- "agentspine.learning-evaluation/v25", "agentspine.learning-evaluation/v26",
144
- "agentspine.learning-evaluation/v27", "agentspine.learning-evaluation/v28",
145
- "agentspine.learning-evaluation/v29"]);
146
-
147
- export const EVIDENCE_SOURCE_ATTESTED_EVALUATIONS = new Set(["agentspine.learning-evaluation/v26",
148
- "agentspine.learning-evaluation/v27", "agentspine.learning-evaluation/v28",
149
- "agentspine.learning-evaluation/v29"]);
150
-
151
- export const CANDIDATE_EVIDENCE_LINEAGE_EVALUATIONS = new Set(["agentspine.learning-evaluation/v28",
152
- "agentspine.learning-evaluation/v29"]);
153
-
154
- export const DELIVERABLE_APPLICATIONS = new Set(Array.from({ length: 6 }, (_, index) =>
155
- `agentspine.learning-application/v${index + 2}`));
156
-
157
- export const INITIAL_TRIAL_APPLICATIONS = new Set(["agentspine.learning-application/v5", "agentspine.learning-application/v6",
158
- "agentspine.learning-application/v7"]);
159
-
160
- export const TARGET_BOUND_APPLICATIONS = new Set(["agentspine.learning-application/v6", "agentspine.learning-application/v7"]);
161
-
162
- export const DEADLINE_BOUND_APPLICATIONS = new Set(["agentspine.learning-application/v7"]);
163
-
164
- export const EVIDENCE_REVOCATION_REASONS = new Set(["retracted", "source-invalid", "measurement-invalid", "duplicate", "other"]);
165
-
166
- export const MEASUREMENT_REVOCATION_REASONS = new Set(["source-invalid", "evaluator-invalid", "protocol-invalid", "duplicate", "other"]);
167
-
168
- export const DELIVERY_REVOCATION_REASONS = new Set(["host-invalid", "session-invalid", "hook-invalid", "duplicate", "other"]);
169
-
170
- export const OUTCOME_REVOCATION_REASONS = new Set(["binding-invalid", "phase-invalid", "scope-invalid", "duplicate", "other"]);
171
-
172
- export const APPLICATION_REVOCATION_REASONS = new Set(["preflight-invalid", "scope-invalid", "projection-invalid", "duplicate", "other"]);
173
-
174
- export const EVALUATION_REVOCATION_REASONS = new Set(["benchmark-invalid", "protocol-invalid", "scope-invalid", "threshold-invalid", "duplicate", "other"]);
175
-
176
- export const EVIDENCE_SOURCE_ATTESTATION_REVOCATION_REASONS = new Set([
177
- "source-class-invalid", "confirmation-invalid", "scope-invalid", "duplicate", "other"
178
- ]);
179
-
180
- export const VALIDATION_REVOCATION_REASONS = new Set(["decision-invalid", "cohort-invalid", "binding-invalid", "scope-invalid", "duplicate", "other"]);
181
-
182
- export const TRIAL_FAILURE_REVOCATION_REASONS = new Set(["clock-invalid", "host-invalid", "receipt-invalid", "scope-invalid", "duplicate", "other"]);
183
-
184
- export function defaults() {
185
- return {
186
- autoPromote: false,
187
- minConfidence: 0.85,
188
- minEvidence: 2,
189
- maxContextItems: 12,
190
- minOutcomeReceipts: 2,
191
- minImprovement: 0.05,
192
- regressionTolerance: 0,
193
- outcomeMaxAgeDays: 30,
194
- canaryReceipts: 2,
195
- canaryTtlDays: 14,
196
- initialTrialOutcomeTimeoutMinutes: 1440
197
- };
198
- }
199
-
200
- export function emptyLearning(root) {
201
- return {
202
- schema: "agentspine.learning/v1",
203
- root,
204
- config: defaults(),
205
- candidates: [],
206
- outcomes: [],
207
- measurements: [],
208
- measurementLineage: [],
209
- candidateEvidenceLineage: [],
210
- applications: [],
211
- deliveries: [],
212
- evaluations: [],
213
- evaluatorRegistry: [],
214
- evaluationBindings: [],
215
- validationLeases: [],
216
- trialFailures: [],
217
- trialFailureRevocations: [],
218
- trialRetryExhaustions: [],
219
- evaluationRevocations: [],
220
- evidenceSourceAttestationRevocations: [],
221
- validationRevocations: [],
222
- evidenceRevocations: [],
223
- measurementRevocations: [],
224
- applicationRevocations: [],
225
- deliveryRevocations: [],
226
- outcomeRevocations: [],
227
- history: []
228
- };
229
- }
@@ -1,424 +0,0 @@
1
- import { createHash, randomUUID } from "node:crypto";
2
- import {
3
- OUTCOME_PHASES, MEASUREMENT_KINDS, METRIC_DIRECTIONS, SCOPE_FIELDS, ID_RE, DIGEST_RE,
4
- EVIDENCE_REVOCATION_REASONS, MEASUREMENT_REVOCATION_REASONS, EVALUATION_REVOCATION_REASONS
5
- } from "./learning-schema.js";
6
- import {
7
- outcomePayload
8
- } from "./learning-outcome-contracts.js";
9
-
10
- export function validConfig(config) {
11
- return typeof config?.autoPromote === "boolean"
12
- && Number.isFinite(config.minConfidence) && config.minConfidence >= 0.5 && config.minConfidence <= 1
13
- && Number.isInteger(config.minEvidence) && config.minEvidence >= 1 && config.minEvidence <= 10
14
- && Number.isInteger(config.maxContextItems) && config.maxContextItems >= 1 && config.maxContextItems <= 50
15
- && Number.isInteger(config.minOutcomeReceipts) && config.minOutcomeReceipts >= 2 && config.minOutcomeReceipts <= 10
16
- && Number.isFinite(config.minImprovement) && config.minImprovement >= 0 && config.minImprovement <= 1
17
- && Number.isFinite(config.regressionTolerance) && config.regressionTolerance >= 0 && config.regressionTolerance <= 1
18
- && Number.isInteger(config.outcomeMaxAgeDays) && config.outcomeMaxAgeDays >= 1 && config.outcomeMaxAgeDays <= 365
19
- && Number.isInteger(config.canaryReceipts) && config.canaryReceipts >= 1 && config.canaryReceipts <= 10
20
- && Number.isInteger(config.canaryTtlDays) && config.canaryTtlDays >= 1 && config.canaryTtlDays <= 90
21
- && Number.isInteger(config.initialTrialOutcomeTimeoutMinutes)
22
- && config.initialTrialOutcomeTimeoutMinutes >= 5 && config.initialTrialOutcomeTimeoutMinutes <= 10080;
23
- }
24
-
25
- export function normalizeStoredScope(scope, subjectId = null, groupId = null) {
26
- const source = scope && typeof scope === "object" && !Array.isArray(scope) ? scope : {};
27
- const normalized = {};
28
- for (const field of SCOPE_FIELDS) normalized[field] = source[field] ?? null;
29
- if (normalized.groupId === null && groupId) normalized.groupId = groupId;
30
- return normalized;
31
- }
32
-
33
- export function normalizeScope(scope, subjectId = null, groupId = null) {
34
- const normalized = normalizeStoredScope(scope, subjectId, groupId);
35
- for (const [field, value] of Object.entries(normalized)) {
36
- if (value !== null && !ID_RE.test(value)) throw new Error(`scope.${field} must be a stable, whitespace-free identifier`);
37
- }
38
- return normalized;
39
- }
40
-
41
- export function scopeKey(scope) {
42
- return JSON.stringify(SCOPE_FIELDS.map((field) => scope?.[field] ?? null));
43
- }
44
-
45
- export function scopeContains(candidateScope, runtimeScope) {
46
- return SCOPE_FIELDS.every((field) => candidateScope?.[field] === null || candidateScope?.[field] === runtimeScope?.[field]);
47
- }
48
-
49
- export function exactScope(left, right) {
50
- return scopeKey(left) === scopeKey(right);
51
- }
52
-
53
- export function digest(value) {
54
- return createHash("sha256").update(JSON.stringify(value)).digest("hex");
55
- }
56
-
57
- export function learningTargetRevisionPayload(candidate) {
58
- return {
59
- id: candidate.id,
60
- kind: candidate.kind,
61
- claim: candidate.claim,
62
- subjectId: candidate.subjectId,
63
- privacy: candidate.privacy,
64
- groupId: candidate.groupId,
65
- scope: candidate.scope,
66
- evidence: candidate.evidence,
67
- confidence: candidate.confidence,
68
- supersedesId: candidate.supersedesId,
69
- requiresLocalReview: candidate.requiresLocalReview,
70
- authority: "context-only"
71
- };
72
- }
73
-
74
- export function learningTargetPayload({ learningId, revisionDigest, claimDigest, evidenceDigest, scopeDigest }) {
75
- return {
76
- schema: "agentspine.learning-target/v1",
77
- learningId,
78
- revisionDigest,
79
- claimDigest,
80
- evidenceDigest,
81
- scopeDigest,
82
- authority: "context-only"
83
- };
84
- }
85
-
86
- export function learningTargetForCandidate(candidate) {
87
- const payload = learningTargetPayload({
88
- learningId: candidate.id,
89
- revisionDigest: digest(learningTargetRevisionPayload(candidate)),
90
- claimDigest: digest(candidate.claim),
91
- evidenceDigest: digest(candidate.evidence),
92
- scopeDigest: digest(candidate.scope)
93
- });
94
- return { ...payload, digest: digest(payload) };
95
- }
96
-
97
- export function storedLearningTargetStructure(target) {
98
- if (!target || typeof target !== "object" || Array.isArray(target)) return false;
99
- const payload = learningTargetPayload(target);
100
- return target.schema === "agentspine.learning-target/v1" && ID_RE.test(target.learningId || "")
101
- && Object.keys(target).length === 8
102
- && Object.keys(target).every((field) => ["schema", "learningId", "revisionDigest", "claimDigest",
103
- "evidenceDigest", "scopeDigest", "authority", "digest"].includes(field))
104
- && [target.revisionDigest, target.claimDigest, target.evidenceDigest, target.scopeDigest]
105
- .every((value) => DIGEST_RE.test(value || ""))
106
- && target.authority === "context-only" && target.digest === digest(payload);
107
- }
108
-
109
- export function learningTargetMatchesCandidate(target, candidate) {
110
- return Boolean(candidate) && storedLearningTargetStructure(target)
111
- && target.digest === learningTargetForCandidate(candidate).digest;
112
- }
113
-
114
- export function evidenceRevocationPayload({ id, learningId, evidenceId, evidenceDigest, targetDigest, reasonCode,
115
- reasonDigest, revokedAt }) {
116
- return {
117
- schema: "agentspine.learning-evidence-revocation/v1",
118
- id,
119
- learningId,
120
- evidenceId,
121
- evidenceDigest,
122
- targetDigest,
123
- reasonCode,
124
- reasonDigest,
125
- revokedAt,
126
- authority: "context-only"
127
- };
128
- }
129
-
130
- export function storedEvidenceRevocationStructure(receipt) {
131
- if (!receipt || typeof receipt !== "object" || Array.isArray(receipt)) return false;
132
- const payload = evidenceRevocationPayload(receipt);
133
- return receipt.schema === "agentspine.learning-evidence-revocation/v1"
134
- && Object.keys(receipt).length === 11
135
- && Object.keys(receipt).every((field) => ["schema", "id", "learningId", "evidenceId", "evidenceDigest",
136
- "targetDigest", "reasonCode", "reasonDigest", "revokedAt", "authority", "digest"].includes(field))
137
- && ID_RE.test(receipt.id || "") && ID_RE.test(receipt.learningId || "") && ID_RE.test(receipt.evidenceId || "")
138
- && DIGEST_RE.test(receipt.evidenceDigest || "") && DIGEST_RE.test(receipt.targetDigest || "")
139
- && EVIDENCE_REVOCATION_REASONS.has(receipt.reasonCode) && DIGEST_RE.test(receipt.reasonDigest || "")
140
- && Number.isFinite(new Date(receipt.revokedAt).getTime()) && receipt.authority === "context-only"
141
- && receipt.digest === digest(payload);
142
- }
143
-
144
- export function evidenceRevocationMatchesState(state, receipt) {
145
- const candidate = state.candidates.find((entry) => entry.id === receipt.learningId);
146
- const evidence = candidate?.evidence.find((entry) => entry.id === receipt.evidenceId);
147
- return Boolean(candidate && evidence && digest(evidence) === receipt.evidenceDigest
148
- && learningTargetForCandidate(candidate).digest === receipt.targetDigest);
149
- }
150
-
151
- export function revokedEvidence(state, candidate) {
152
- return state.evidenceRevocations.find((receipt) => receipt.learningId === candidate?.id) || null;
153
- }
154
-
155
- export function storedOutcomeStructure(receipt) {
156
- if (!receipt || typeof receipt !== "object" || Array.isArray(receipt)) return false;
157
- const payload = outcomePayload(receipt);
158
- const legacy = receipt.schema === "agentspine.learning-outcome/v1";
159
- const bound = receipt.schema === "agentspine.learning-outcome/v2";
160
- const planned = receipt.schema === "agentspine.learning-outcome/v3";
161
- const delivered = receipt.schema === "agentspine.learning-outcome/v4";
162
- const covered = receipt.schema === "agentspine.learning-outcome/v5";
163
- const provenanceBound = receipt.schema === "agentspine.learning-outcome/v6";
164
- const lineageBound = receipt.schema === "agentspine.learning-outcome/v7";
165
- const paired = receipt.schema === "agentspine.learning-outcome/v8";
166
- const rootBound = receipt.schema === "agentspine.learning-outcome/v9";
167
- return (legacy || bound || planned || delivered || covered || provenanceBound || lineageBound || paired || rootBound) && ID_RE.test(receipt.id || "")
168
- && ID_RE.test(receipt.learningId || "") && OUTCOME_PHASES.has(receipt.phase)
169
- && SCOPE_FIELDS.every((field) => receipt.scope?.[field] === null || ID_RE.test(receipt.scope?.[field] || ""))
170
- && typeof receipt.metric?.name === "string" && receipt.metric.name.length > 0
171
- && METRIC_DIRECTIONS.has(receipt.metric?.direction)
172
- && Number.isFinite(receipt.metric?.value) && receipt.metric.value >= 0 && receipt.metric.value <= 1
173
- && Number.isInteger(receipt.metric?.blockingDefects) && receipt.metric.blockingDefects >= 0
174
- && MEASUREMENT_KINDS.has(receipt.measurement?.kind) && ID_RE.test(receipt.measurement?.evaluatorId || "")
175
- && (receipt.measurement?.sourceDigest === null || DIGEST_RE.test(receipt.measurement?.sourceDigest || ""))
176
- && (legacy ? receipt.applicationId === undefined : (receipt.phase === "before"
177
- ? receipt.applicationId === null : ID_RE.test(receipt.applicationId || "")))
178
- && (!(planned || delivered || covered || provenanceBound || lineageBound || paired || rootBound) || ID_RE.test(receipt.evaluationId || ""))
179
- && (!(delivered || covered || provenanceBound || lineageBound || paired || rootBound) || (receipt.phase === "before" ? receipt.deliveryId === null : ID_RE.test(receipt.deliveryId || "")))
180
- && (!(covered || provenanceBound || lineageBound || paired || rootBound) || (DIGEST_RE.test(receipt.coverage?.datasetDigest || "")
181
- && Number.isInteger(receipt.coverage?.caseCount) && receipt.coverage.caseCount >= 1
182
- && receipt.coverage.caseCount <= 1000000 && receipt.coverage?.authority === "context-only"))
183
- && (!(provenanceBound || lineageBound || paired || rootBound) || DIGEST_RE.test(receipt.measurement?.sourceDigest || ""))
184
- && (!(lineageBound || paired || rootBound) || (ID_RE.test(receipt.measurementReceiptId || "") && DIGEST_RE.test(receipt.measurementReceiptDigest || "")
185
- && ID_RE.test(receipt.measurement?.runId || "")))
186
- && (!rootBound || DIGEST_RE.test(receipt.measurement?.evaluatorRootDigest || ""))
187
- && receipt.authority === "context-only" && receipt.measurement?.authority === "context-only"
188
- && Number.isFinite(new Date(receipt.measuredAt).getTime()) && receipt.digest === digest(payload);
189
- }
190
-
191
- export function measurementPayload({ id, learningId, evaluationId, phase, scope, metric, measurement, coverage, measuredAt,
192
- schema = "agentspine.learning-measurement/v1" }) {
193
- return {
194
- schema, id, learningId, evaluationId, phase, scope,
195
- metric, measurement, coverage, measuredAt, authority: "context-only"
196
- };
197
- }
198
-
199
- export function storedMeasurementStructure(receipt) {
200
- if (!receipt || typeof receipt !== "object" || Array.isArray(receipt)) return false;
201
- const payload = measurementPayload(receipt);
202
- return ["agentspine.learning-measurement/v1", "agentspine.learning-measurement/v2"].includes(receipt.schema)
203
- && ID_RE.test(receipt.id || "") && ID_RE.test(receipt.learningId || "") && ID_RE.test(receipt.evaluationId || "")
204
- && OUTCOME_PHASES.has(receipt.phase)
205
- && SCOPE_FIELDS.every((field) => receipt.scope?.[field] === null || ID_RE.test(receipt.scope?.[field] || ""))
206
- && typeof receipt.metric?.name === "string" && receipt.metric.name.length > 0
207
- && METRIC_DIRECTIONS.has(receipt.metric?.direction)
208
- && Number.isFinite(receipt.metric?.value) && receipt.metric.value >= 0 && receipt.metric.value <= 1
209
- && Number.isInteger(receipt.metric?.blockingDefects) && receipt.metric.blockingDefects >= 0
210
- && MEASUREMENT_KINDS.has(receipt.measurement?.kind) && ID_RE.test(receipt.measurement?.evaluatorId || "")
211
- && ID_RE.test(receipt.measurement?.runId || "") && DIGEST_RE.test(receipt.measurement?.sourceDigest || "")
212
- && (receipt.schema !== "agentspine.learning-measurement/v2"
213
- || DIGEST_RE.test(receipt.measurement?.evaluatorRootDigest || ""))
214
- && receipt.measurement?.authority === "context-only"
215
- && DIGEST_RE.test(receipt.coverage?.datasetDigest || "")
216
- && Number.isInteger(receipt.coverage?.caseCount) && receipt.coverage.caseCount >= 1
217
- && receipt.coverage.caseCount <= 1000000 && receipt.coverage?.authority === "context-only"
218
- && Number.isFinite(new Date(receipt.measuredAt).getTime())
219
- && receipt.authority === "context-only" && receipt.digest === digest(payload);
220
- }
221
-
222
- export function measurementRevocationPayload({ id, learningId, evaluationId, evaluationDigest, measurementId,
223
- measurementDigest, outcomeId, outcomeDigest, targetDigest, reasonCode, reasonDigest, revokedAt }) {
224
- return {
225
- schema: "agentspine.learning-measurement-revocation/v1",
226
- id,
227
- learningId,
228
- evaluationId,
229
- evaluationDigest,
230
- measurementId,
231
- measurementDigest,
232
- outcomeId,
233
- outcomeDigest,
234
- targetDigest,
235
- reasonCode,
236
- reasonDigest,
237
- revokedAt,
238
- authority: "context-only"
239
- };
240
- }
241
-
242
- export function storedMeasurementRevocationStructure(receipt) {
243
- if (!receipt || typeof receipt !== "object" || Array.isArray(receipt)) return false;
244
- const payload = measurementRevocationPayload(receipt);
245
- return receipt.schema === "agentspine.learning-measurement-revocation/v1"
246
- && Object.keys(receipt).length === 15
247
- && Object.keys(receipt).every((field) => ["schema", "id", "learningId", "evaluationId", "evaluationDigest",
248
- "measurementId", "measurementDigest", "outcomeId", "outcomeDigest", "targetDigest", "reasonCode",
249
- "reasonDigest", "revokedAt", "authority", "digest"].includes(field))
250
- && ID_RE.test(receipt.id || "") && ID_RE.test(receipt.learningId || "")
251
- && ID_RE.test(receipt.evaluationId || "") && DIGEST_RE.test(receipt.evaluationDigest || "")
252
- && ID_RE.test(receipt.measurementId || "") && DIGEST_RE.test(receipt.measurementDigest || "")
253
- && ((receipt.outcomeId === null && receipt.outcomeDigest === null)
254
- || (ID_RE.test(receipt.outcomeId || "") && DIGEST_RE.test(receipt.outcomeDigest || "")))
255
- && DIGEST_RE.test(receipt.targetDigest || "") && MEASUREMENT_REVOCATION_REASONS.has(receipt.reasonCode)
256
- && DIGEST_RE.test(receipt.reasonDigest || "") && Number.isFinite(new Date(receipt.revokedAt).getTime())
257
- && receipt.authority === "context-only" && receipt.digest === digest(payload);
258
- }
259
-
260
- export function measurementRevocationMatchesState(state, receipt) {
261
- const candidate = state.candidates.find((entry) => entry.id === receipt.learningId);
262
- const evaluation = state.evaluations.find((entry) => entry.id === receipt.evaluationId);
263
- const measurement = state.measurements.find((entry) => entry.id === receipt.measurementId);
264
- const outcome = receipt.outcomeId === null ? null : state.outcomes.find((entry) => entry.id === receipt.outcomeId);
265
- return Boolean(candidate && evaluation && measurement
266
- && evaluation.digest === receipt.evaluationDigest && evaluation.learningId === candidate.id
267
- && measurement.digest === receipt.measurementDigest && measurement.learningId === candidate.id
268
- && measurement.evaluationId === evaluation.id && learningTargetForCandidate(candidate).digest === receipt.targetDigest
269
- && (receipt.outcomeId === null
270
- ? !state.outcomes.some((entry) => entry.measurementReceiptId === measurement.id)
271
- : outcome?.digest === receipt.outcomeDigest && outcome.learningId === candidate.id
272
- && outcome.evaluationId === evaluation.id && outcome.measurementReceiptId === measurement.id));
273
- }
274
-
275
- export function revokedMeasurement(state, measurementId) {
276
- return state.measurementRevocations.find((receipt) => receipt.measurementId === measurementId) || null;
277
- }
278
-
279
- export function revokedMeasurementForCandidate(state, candidate) {
280
- const revocations = state.measurementRevocations.filter((receipt) => receipt.learningId === candidate?.id);
281
- if (!revocations.length) return null;
282
- const canary = candidate?.promotion?.mode === "outcome-canary" ? candidate.promotion.canary : null;
283
- if (!canary?.evaluationId) return revocations[0];
284
- const lease = state.validationLeases.find((entry) => entry.learningId === candidate.id
285
- && entry.id === canary.validationLeaseId);
286
- const referencedMeasurements = new Set((lease?.renewalEvidence || []).map((entry) => entry.measurementId));
287
- const referencedOutcomes = new Set([
288
- ...(canary.beforeReceipts || []),
289
- ...(canary.afterReceipts || []),
290
- ...(lease?.beforeOutcomes || []).map((entry) => entry.id),
291
- ...(lease?.afterOutcomes || []).map((entry) => entry.id),
292
- ...(lease?.baselineOutcomes || []).map((entry) => entry.id)
293
- ]);
294
- return revocations.find((receipt) => receipt.learningId === candidate.id
295
- && receipt.evaluationId === canary.evaluationId
296
- && (referencedMeasurements.has(receipt.measurementId)
297
- || (receipt.outcomeId !== null && (referencedOutcomes.has(receipt.outcomeId)
298
- || canary.status === "active")))) || null;
299
- }
300
-
301
- export function measurementRunDigest(evaluatorId, runId) {
302
- return digest([evaluatorId, runId]);
303
- }
304
-
305
- export function evaluatorRootRunDigest(evaluatorRootDigest, runId) {
306
- return digest([evaluatorRootDigest, runId]);
307
- }
308
-
309
- export function evaluatorRecordPayload({ id, principalDigest, status, registeredAt, revokedAt, reason }) {
310
- return {
311
- schema: "agentspine.learning-evaluator/v1",
312
- id,
313
- principalDigest,
314
- status,
315
- registeredAt,
316
- revokedAt,
317
- reason,
318
- confirmation: "local-owner",
319
- authority: "context-only"
320
- };
321
- }
322
-
323
- export function storedEvaluatorRecordStructure(record) {
324
- if (!record || typeof record !== "object" || Array.isArray(record)) return false;
325
- const payload = evaluatorRecordPayload(record);
326
- return record.schema === "agentspine.learning-evaluator/v1" && ID_RE.test(record.id || "")
327
- && DIGEST_RE.test(record.principalDigest || "") && ["active", "revoked"].includes(record.status)
328
- && Number.isFinite(new Date(record.registeredAt).getTime())
329
- && (record.status === "active"
330
- ? record.revokedAt === null && record.reason === null
331
- : Number.isFinite(new Date(record.revokedAt).getTime()) && typeof record.reason === "string" && record.reason.length > 0)
332
- && record.confirmation === "local-owner" && record.authority === "context-only"
333
- && record.digest === digest(payload);
334
- }
335
-
336
- export function evaluationBindingPayload({ evaluationId, evaluationDigest, evaluators, boundAt }) {
337
- return {
338
- schema: "agentspine.learning-evaluator-binding/v1",
339
- evaluationId,
340
- evaluationDigest,
341
- evaluators,
342
- boundAt,
343
- authority: "context-only"
344
- };
345
- }
346
-
347
- export function storedEvaluationBindingStructure(binding) {
348
- if (!binding || typeof binding !== "object" || Array.isArray(binding)) return false;
349
- const payload = evaluationBindingPayload(binding);
350
- return binding.schema === "agentspine.learning-evaluator-binding/v1"
351
- && ID_RE.test(binding.evaluationId || "") && DIGEST_RE.test(binding.evaluationDigest || "")
352
- && Array.isArray(binding.evaluators) && binding.evaluators.length >= 2
353
- && binding.evaluators.every((entry) => ID_RE.test(entry?.evaluatorId || "")
354
- && DIGEST_RE.test(entry?.principalDigest || "") && DIGEST_RE.test(entry?.registryDigest || "")
355
- && entry?.authority === "context-only")
356
- && new Set(binding.evaluators.map((entry) => entry.evaluatorId)).size === binding.evaluators.length
357
- && new Set(binding.evaluators.map((entry) => entry.principalDigest)).size === binding.evaluators.length
358
- && Number.isFinite(new Date(binding.boundAt).getTime()) && binding.authority === "context-only"
359
- && binding.digest === digest(payload);
360
- }
361
-
362
- export function activeEvaluatorRecord(state, evaluatorId, principalDigest = null) {
363
- return state.evaluatorRegistry.find((record) => record.id === evaluatorId && record.status === "active"
364
- && (principalDigest === null || record.principalDigest === principalDigest)) || null;
365
- }
366
-
367
- export function activeEvaluationBinding(state, contract) {
368
- const binding = state.evaluationBindings.find((entry) => entry.evaluationId === contract?.id
369
- && entry.evaluationDigest === contract?.digest);
370
- if (!binding) return null;
371
- return binding.evaluators.every((entry) => {
372
- const record = activeEvaluatorRecord(state, entry.evaluatorId, entry.principalDigest);
373
- return record?.digest === entry.registryDigest;
374
- }) ? binding : null;
375
- }
376
-
377
- export function evaluationRevocationPayload({ id, learningId, evaluationId, evaluationDigest,
378
- evaluatorBindingDigest, targetDigest, reasonCode, reasonDigest, revokedAt }) {
379
- return {
380
- schema: "agentspine.learning-evaluation-revocation/v1",
381
- id,
382
- learningId,
383
- evaluationId,
384
- evaluationDigest,
385
- evaluatorBindingDigest,
386
- targetDigest,
387
- reasonCode,
388
- reasonDigest,
389
- revokedAt,
390
- authority: "context-only"
391
- };
392
- }
393
-
394
- export function storedEvaluationRevocationStructure(receipt) {
395
- if (!receipt || typeof receipt !== "object" || Array.isArray(receipt)) return false;
396
- const payload = evaluationRevocationPayload(receipt);
397
- return receipt.schema === "agentspine.learning-evaluation-revocation/v1"
398
- && Object.keys(receipt).length === 12
399
- && Object.keys(receipt).every((field) => ["schema", "id", "learningId", "evaluationId",
400
- "evaluationDigest", "evaluatorBindingDigest", "targetDigest", "reasonCode", "reasonDigest",
401
- "revokedAt", "authority", "digest"].includes(field))
402
- && ID_RE.test(receipt.id || "") && ID_RE.test(receipt.learningId || "")
403
- && ID_RE.test(receipt.evaluationId || "") && DIGEST_RE.test(receipt.evaluationDigest || "")
404
- && (receipt.evaluatorBindingDigest === null || DIGEST_RE.test(receipt.evaluatorBindingDigest || ""))
405
- && DIGEST_RE.test(receipt.targetDigest || "")
406
- && EVALUATION_REVOCATION_REASONS.has(receipt.reasonCode)
407
- && DIGEST_RE.test(receipt.reasonDigest || "") && Number.isFinite(new Date(receipt.revokedAt).getTime())
408
- && receipt.authority === "context-only" && receipt.digest === digest(payload);
409
- }
410
-
411
- export function evaluationRevocationMatchesState(state, receipt) {
412
- const candidate = state.candidates.find((entry) => entry.id === receipt.learningId);
413
- const evaluation = state.evaluations.find((entry) => entry.id === receipt.evaluationId);
414
- const binding = state.evaluationBindings.find((entry) => entry.evaluationId === receipt.evaluationId
415
- && entry.evaluationDigest === receipt.evaluationDigest) || null;
416
- return Boolean(candidate && evaluation && evaluation.learningId === candidate.id
417
- && evaluation.digest === receipt.evaluationDigest
418
- && learningTargetForCandidate(candidate).digest === receipt.targetDigest
419
- && (binding?.digest || null) === receipt.evaluatorBindingDigest);
420
- }
421
-
422
- export function revokedEvaluation(state, evaluationId) {
423
- return state.evaluationRevocations.find((receipt) => receipt.evaluationId === evaluationId) || null;
424
- }