blun-king-cli 9.1.642 → 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 (273) 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 +78 -193
  18. package/bundled-agent-sources.json +1 -552
  19. package/package.json +4 -6
  20. package/tool-liveness642/index.cjs +7 -0
  21. package/tool-liveness642/queue-delivery.cjs +109 -0
  22. package/tool-liveness642/receipt.json +40 -0
  23. package/tool-liveness642/shell-yield.cjs +43 -0
  24. package/tool-liveness642/task-wait.cjs +45 -0
  25. package/versionierung/BELEG.json +43 -0
  26. package/versionierung/LIESMICH.md +5 -0
  27. package/versionierung/urspruenglicher-overlay-beleg.json +39 -0
  28. package/worker-host.mjs +48 -128
  29. package/agent-spine-plugin/.claude-plugin/marketplace.json +0 -20
  30. package/agent-spine-plugin/.claude-plugin/plugin.json +0 -14
  31. package/agent-spine-plugin/.codex-plugin/plugin.json +0 -47
  32. package/agent-spine-plugin/.mcp.json +0 -8
  33. package/agent-spine-plugin/CHANGELOG.md +0 -1614
  34. package/agent-spine-plugin/LICENSE +0 -186
  35. package/agent-spine-plugin/README.md +0 -432
  36. package/agent-spine-plugin/assets/agentspine-banner.svg +0 -32
  37. package/agent-spine-plugin/bin/agentspine-mcp.js +0 -4
  38. package/agent-spine-plugin/bin/agentspine.js +0 -7
  39. package/agent-spine-plugin/blun.plugin.json +0 -68
  40. package/agent-spine-plugin/docs/acceptance.md +0 -61
  41. package/agent-spine-plugin/docs/artifact-evaluation.md +0 -93
  42. package/agent-spine-plugin/docs/host-integration.md +0 -193
  43. package/agent-spine-plugin/docs/preflight-recall.md +0 -71
  44. package/agent-spine-plugin/docs/preservation-contract.md +0 -53
  45. package/agent-spine-plugin/docs/quality-gates.md +0 -50
  46. package/agent-spine-plugin/docs/session-timeline.md +0 -112
  47. package/agent-spine-plugin/docs/source-roots.md +0 -113
  48. package/agent-spine-plugin/docs/world-model.md +0 -119
  49. package/agent-spine-plugin/hooks/codex.json +0 -47
  50. package/agent-spine-plugin/hooks/hooks.json +0 -106
  51. package/agent-spine-plugin/hooks/version.json +0 -5
  52. package/agent-spine-plugin/package.json +0 -77
  53. package/agent-spine-plugin/scripts/check-codex-install.js +0 -226
  54. package/agent-spine-plugin/scripts/check-hosts.js +0 -208
  55. package/agent-spine-plugin/scripts/check-install-hook.js +0 -227
  56. package/agent-spine-plugin/scripts/check-install-selfstarter.js +0 -154
  57. package/agent-spine-plugin/scripts/check-install.js +0 -478
  58. package/agent-spine-plugin/scripts/check-line-budget.js +0 -58
  59. package/agent-spine-plugin/scripts/check-syntax.js +0 -29
  60. package/agent-spine-plugin/scripts/github-actions.js +0 -11
  61. package/agent-spine-plugin/scripts/hermetic-process.js +0 -191
  62. package/agent-spine-plugin/scripts/release-check.js +0 -150
  63. package/agent-spine-plugin/scripts/run-acceptance.js +0 -19
  64. package/agent-spine-plugin/scripts/run-checks.js +0 -50
  65. package/agent-spine-plugin/scripts/run-tests-hermetic.js +0 -112
  66. package/agent-spine-plugin/skills/agent-spine/SKILL.md +0 -99
  67. package/agent-spine-plugin/spine-example/1-identity.md +0 -12
  68. package/agent-spine-plugin/spine-example/2-voice.md +0 -6
  69. package/agent-spine-plugin/spine-example/3-conduct.md +0 -8
  70. package/agent-spine-plugin/spine-example/4-history.md +0 -4
  71. package/agent-spine-plugin/src/cli-agent.js +0 -315
  72. package/agent-spine-plugin/src/cli-attention.js +0 -95
  73. package/agent-spine-plugin/src/cli-autonomy.js +0 -36
  74. package/agent-spine-plugin/src/cli-common.js +0 -71
  75. package/agent-spine-plugin/src/cli-continuity.js +0 -116
  76. package/agent-spine-plugin/src/cli-core.js +0 -128
  77. package/agent-spine-plugin/src/cli-diagnostics.js +0 -291
  78. package/agent-spine-plugin/src/cli-host.js +0 -21
  79. package/agent-spine-plugin/src/cli-learning.js +0 -320
  80. package/agent-spine-plugin/src/cli-premortem.js +0 -16
  81. package/agent-spine-plugin/src/cli-sharing.js +0 -230
  82. package/agent-spine-plugin/src/cli.js +0 -181
  83. package/agent-spine-plugin/src/codex-reader-launcher.js +0 -182
  84. package/agent-spine-plugin/src/hook.js +0 -500
  85. package/agent-spine-plugin/src/index.js +0 -108
  86. package/agent-spine-plugin/src/lib/acceptance.js +0 -435
  87. package/agent-spine-plugin/src/lib/action-lesson-recall.js +0 -118
  88. package/agent-spine-plugin/src/lib/attention-context.js +0 -167
  89. package/agent-spine-plugin/src/lib/attention-events.js +0 -113
  90. package/agent-spine-plugin/src/lib/attention-privacy.js +0 -72
  91. package/agent-spine-plugin/src/lib/attention-schema.js +0 -164
  92. package/agent-spine-plugin/src/lib/attention-storage.js +0 -93
  93. package/agent-spine-plugin/src/lib/attention.js +0 -164
  94. package/agent-spine-plugin/src/lib/audit-premortem.js +0 -223
  95. package/agent-spine-plugin/src/lib/audit.js +0 -401
  96. package/agent-spine-plugin/src/lib/authentication.js +0 -515
  97. package/agent-spine-plugin/src/lib/autonomy-policy.js +0 -110
  98. package/agent-spine-plugin/src/lib/autonomy-store.js +0 -202
  99. package/agent-spine-plugin/src/lib/autonomy.js +0 -8
  100. package/agent-spine-plugin/src/lib/briefing.js +0 -493
  101. package/agent-spine-plugin/src/lib/catalog-document-read.js +0 -51
  102. package/agent-spine-plugin/src/lib/catalog.js +0 -167
  103. package/agent-spine-plugin/src/lib/channel-continuity.js +0 -19
  104. package/agent-spine-plugin/src/lib/channel-runtime.js +0 -665
  105. package/agent-spine-plugin/src/lib/codex-installation.js +0 -231
  106. package/agent-spine-plugin/src/lib/codex-skill-installation.js +0 -211
  107. package/agent-spine-plugin/src/lib/context.js +0 -156
  108. package/agent-spine-plugin/src/lib/continuity.js +0 -338
  109. package/agent-spine-plugin/src/lib/coordination.js +0 -577
  110. package/agent-spine-plugin/src/lib/delivery-agent-usage.js +0 -231
  111. package/agent-spine-plugin/src/lib/delivery-assignment.js +0 -220
  112. package/agent-spine-plugin/src/lib/delivery-command-actions.js +0 -462
  113. package/agent-spine-plugin/src/lib/delivery-knowledge.js +0 -78
  114. package/agent-spine-plugin/src/lib/delivery-premortem-binding.js +0 -107
  115. package/agent-spine-plugin/src/lib/delivery-premortem-closure.js +0 -171
  116. package/agent-spine-plugin/src/lib/delivery-premortem-codec.js +0 -45
  117. package/agent-spine-plugin/src/lib/delivery-premortem-correction.js +0 -101
  118. package/agent-spine-plugin/src/lib/delivery-premortem-file.js +0 -21
  119. package/agent-spine-plugin/src/lib/delivery-premortem-index.js +0 -493
  120. package/agent-spine-plugin/src/lib/delivery-premortem-inspection.js +0 -37
  121. package/agent-spine-plugin/src/lib/delivery-premortem-recovery.js +0 -120
  122. package/agent-spine-plugin/src/lib/delivery-premortem-rejection.js +0 -65
  123. package/agent-spine-plugin/src/lib/delivery-premortem-results.js +0 -28
  124. package/agent-spine-plugin/src/lib/delivery-premortem-session-guard.js +0 -46
  125. package/agent-spine-plugin/src/lib/delivery-premortem-write-ledger.js +0 -285
  126. package/agent-spine-plugin/src/lib/delivery-premortem.js +0 -499
  127. package/agent-spine-plugin/src/lib/delivery-shell-heredoc.js +0 -115
  128. package/agent-spine-plugin/src/lib/delivery-shell-substitutions.js +0 -111
  129. package/agent-spine-plugin/src/lib/delivery-shell-wrapper.js +0 -64
  130. package/agent-spine-plugin/src/lib/delivery-target.js +0 -73
  131. package/agent-spine-plugin/src/lib/delivery-verification.js +0 -445
  132. package/agent-spine-plugin/src/lib/documents.js +0 -239
  133. package/agent-spine-plugin/src/lib/feed-transport.js +0 -499
  134. package/agent-spine-plugin/src/lib/filesystem-retry.js +0 -34
  135. package/agent-spine-plugin/src/lib/gateway-common.js +0 -68
  136. package/agent-spine-plugin/src/lib/gateway-control.js +0 -370
  137. package/agent-spine-plugin/src/lib/gateway-delivery.js +0 -103
  138. package/agent-spine-plugin/src/lib/gateway-execution.js +0 -350
  139. package/agent-spine-plugin/src/lib/gateway-group-response.js +0 -128
  140. package/agent-spine-plugin/src/lib/gateway-host-fencing.js +0 -92
  141. package/agent-spine-plugin/src/lib/gateway-host-lifecycle.js +0 -193
  142. package/agent-spine-plugin/src/lib/gateway-inspection.js +0 -85
  143. package/agent-spine-plugin/src/lib/gateway-knowledge.js +0 -129
  144. package/agent-spine-plugin/src/lib/gateway-policy-provenance.js +0 -197
  145. package/agent-spine-plugin/src/lib/gateway-premortem-disposition.js +0 -82
  146. package/agent-spine-plugin/src/lib/gateway-premortem.js +0 -363
  147. package/agent-spine-plugin/src/lib/gateway-prepared-host.js +0 -28
  148. package/agent-spine-plugin/src/lib/gateway-runs.js +0 -345
  149. package/agent-spine-plugin/src/lib/gateway-runtime-identity.js +0 -31
  150. package/agent-spine-plugin/src/lib/gateway-runtime-records.js +0 -21
  151. package/agent-spine-plugin/src/lib/gateway-runtime.js +0 -18
  152. package/agent-spine-plugin/src/lib/gateway-state-transaction.js +0 -356
  153. package/agent-spine-plugin/src/lib/gateway-state.js +0 -344
  154. package/agent-spine-plugin/src/lib/graph.js +0 -337
  155. package/agent-spine-plugin/src/lib/hook-artifact-guards.js +0 -356
  156. package/agent-spine-plugin/src/lib/hook-audit.js +0 -43
  157. package/agent-spine-plugin/src/lib/hook-briefing-use.js +0 -78
  158. package/agent-spine-plugin/src/lib/hook-context.js +0 -441
  159. package/agent-spine-plugin/src/lib/hook-final-message.js +0 -26
  160. package/agent-spine-plugin/src/lib/hook-input.js +0 -27
  161. package/agent-spine-plugin/src/lib/hook-output.js +0 -284
  162. package/agent-spine-plugin/src/lib/hook-premortem.js +0 -257
  163. package/agent-spine-plugin/src/lib/hook-process-advisory.js +0 -36
  164. package/agent-spine-plugin/src/lib/hook-protection.js +0 -95
  165. package/agent-spine-plugin/src/lib/hook-stop-verification.js +0 -84
  166. package/agent-spine-plugin/src/lib/hook-timeline.js +0 -102
  167. package/agent-spine-plugin/src/lib/host-instruction-budget.js +0 -11
  168. package/agent-spine-plugin/src/lib/https-transport.js +0 -392
  169. package/agent-spine-plugin/src/lib/identifier-analysis.js +0 -446
  170. package/agent-spine-plugin/src/lib/indexed-memory-offline.js +0 -40
  171. package/agent-spine-plugin/src/lib/indexed-memory.js +0 -298
  172. package/agent-spine-plugin/src/lib/knowledge-evidence.js +0 -431
  173. package/agent-spine-plugin/src/lib/learning-applications.js +0 -441
  174. package/agent-spine-plugin/src/lib/learning-artifact-evaluator.js +0 -114
  175. package/agent-spine-plugin/src/lib/learning-candidates.js +0 -274
  176. package/agent-spine-plugin/src/lib/learning-context.js +0 -137
  177. package/agent-spine-plugin/src/lib/learning-delivery-contracts.js +0 -310
  178. package/agent-spine-plugin/src/lib/learning-evaluation-contracts.js +0 -350
  179. package/agent-spine-plugin/src/lib/learning-evaluation-registration.js +0 -372
  180. package/agent-spine-plugin/src/lib/learning-evaluation-revocation.js +0 -292
  181. package/agent-spine-plugin/src/lib/learning-evidence-contracts.js +0 -321
  182. package/agent-spine-plugin/src/lib/learning-findings.js +0 -458
  183. package/agent-spine-plugin/src/lib/learning-measurement-contracts.js +0 -285
  184. package/agent-spine-plugin/src/lib/learning-measurements.js +0 -265
  185. package/agent-spine-plugin/src/lib/learning-outcome-contracts.js +0 -165
  186. package/agent-spine-plugin/src/lib/learning-outcomes.js +0 -343
  187. package/agent-spine-plugin/src/lib/learning-reconciliation.js +0 -290
  188. package/agent-spine-plugin/src/lib/learning-retry-contracts.js +0 -188
  189. package/agent-spine-plugin/src/lib/learning-schema.js +0 -229
  190. package/agent-spine-plugin/src/lib/learning-scope-targets.js +0 -424
  191. package/agent-spine-plugin/src/lib/learning-state-upgrade.js +0 -477
  192. package/agent-spine-plugin/src/lib/learning-status-configuration.js +0 -476
  193. package/agent-spine-plugin/src/lib/learning-storage.js +0 -203
  194. package/agent-spine-plugin/src/lib/learning-trial-recovery.js +0 -218
  195. package/agent-spine-plugin/src/lib/learning-validation-contracts.js +0 -375
  196. package/agent-spine-plugin/src/lib/learning-validation-renewal.js +0 -298
  197. package/agent-spine-plugin/src/lib/learning-validation-runtime.js +0 -234
  198. package/agent-spine-plugin/src/lib/learning.js +0 -36
  199. package/agent-spine-plugin/src/lib/lesson-recall-session.js +0 -172
  200. package/agent-spine-plugin/src/lib/mcp-autonomy-tools.js +0 -37
  201. package/agent-spine-plugin/src/lib/mcp-delivery-completion.js +0 -124
  202. package/agent-spine-plugin/src/lib/mcp-delivery-tools.js +0 -45
  203. package/agent-spine-plugin/src/lib/mcp-premortem.js +0 -68
  204. package/agent-spine-plugin/src/lib/mcp-runtime.js +0 -355
  205. package/agent-spine-plugin/src/lib/mcp-source-context.js +0 -61
  206. package/agent-spine-plugin/src/lib/mcp-timeline-tools.js +0 -240
  207. package/agent-spine-plugin/src/lib/mcp-world-tools.js +0 -52
  208. package/agent-spine-plugin/src/lib/object-transport.js +0 -206
  209. package/agent-spine-plugin/src/lib/owned-file-lock.js +0 -182
  210. package/agent-spine-plugin/src/lib/paths.js +0 -109
  211. package/agent-spine-plugin/src/lib/peer-transport.js +0 -283
  212. package/agent-spine-plugin/src/lib/persona-runtime.js +0 -581
  213. package/agent-spine-plugin/src/lib/pre-answer-timeline-recall.js +0 -104
  214. package/agent-spine-plugin/src/lib/preflight-delivery-id.js +0 -27
  215. package/agent-spine-plugin/src/lib/preflight.js +0 -688
  216. package/agent-spine-plugin/src/lib/project-portfolio.js +0 -176
  217. package/agent-spine-plugin/src/lib/runtime.js +0 -13
  218. package/agent-spine-plugin/src/lib/selfstarter-core.js +0 -382
  219. package/agent-spine-plugin/src/lib/selfstarter-jobs.js +0 -149
  220. package/agent-spine-plugin/src/lib/selfstarter-lease.js +0 -204
  221. package/agent-spine-plugin/src/lib/selfstarter-policy.js +0 -90
  222. package/agent-spine-plugin/src/lib/selfstarter-workspace.js +0 -111
  223. package/agent-spine-plugin/src/lib/selfstarter.js +0 -11
  224. package/agent-spine-plugin/src/lib/session-timeline-auth.js +0 -316
  225. package/agent-spine-plugin/src/lib/session-timeline-codex.js +0 -69
  226. package/agent-spine-plugin/src/lib/session-timeline-contract.js +0 -56
  227. package/agent-spine-plugin/src/lib/session-timeline-enrollment-source.js +0 -38
  228. package/agent-spine-plugin/src/lib/session-timeline-enrollment-storage.js +0 -128
  229. package/agent-spine-plugin/src/lib/session-timeline-enrollment-transport.js +0 -15
  230. package/agent-spine-plugin/src/lib/session-timeline-enrollment.js +0 -478
  231. package/agent-spine-plugin/src/lib/session-timeline-event-extract.js +0 -186
  232. package/agent-spine-plugin/src/lib/session-timeline-host-origin.js +0 -73
  233. package/agent-spine-plugin/src/lib/session-timeline-host-receipt.js +0 -117
  234. package/agent-spine-plugin/src/lib/session-timeline-invocation.js +0 -201
  235. package/agent-spine-plugin/src/lib/session-timeline-king.js +0 -93
  236. package/agent-spine-plugin/src/lib/session-timeline-prior.js +0 -57
  237. package/agent-spine-plugin/src/lib/session-timeline-provider.js +0 -36
  238. package/agent-spine-plugin/src/lib/session-timeline-query.js +0 -56
  239. package/agent-spine-plugin/src/lib/session-timeline-results.js +0 -56
  240. package/agent-spine-plugin/src/lib/session-timeline-root.js +0 -11
  241. package/agent-spine-plugin/src/lib/session-timeline-search.js +0 -82
  242. package/agent-spine-plugin/src/lib/session-timeline-sid-acl.js +0 -213
  243. package/agent-spine-plugin/src/lib/session-timeline-source-open.js +0 -30
  244. package/agent-spine-plugin/src/lib/session-timeline-source.js +0 -80
  245. package/agent-spine-plugin/src/lib/session-timeline-state.js +0 -45
  246. package/agent-spine-plugin/src/lib/session-timeline-transport.js +0 -42
  247. package/agent-spine-plugin/src/lib/session-timeline-windows-acl.js +0 -145
  248. package/agent-spine-plugin/src/lib/session-timeline.js +0 -462
  249. package/agent-spine-plugin/src/lib/sharing.js +0 -969
  250. package/agent-spine-plugin/src/lib/source-roots.js +0 -475
  251. package/agent-spine-plugin/src/lib/source-tree-scan.js +0 -178
  252. package/agent-spine-plugin/src/lib/sqlite-transport.js +0 -501
  253. package/agent-spine-plugin/src/lib/task-knowledge-context.js +0 -99
  254. package/agent-spine-plugin/src/lib/telegram-adapter.js +0 -119
  255. package/agent-spine-plugin/src/lib/timeline-continuation-update.js +0 -100
  256. package/agent-spine-plugin/src/lib/timeline-tool-guard.js +0 -225
  257. package/agent-spine-plugin/src/lib/timeline-user-feedback.js +0 -216
  258. package/agent-spine-plugin/src/lib/timeline-world-capture.js +0 -233
  259. package/agent-spine-plugin/src/lib/voice-runtime.js +0 -39
  260. package/agent-spine-plugin/src/lib/world-knowledge.js +0 -306
  261. package/agent-spine-plugin/src/lib/world-model.js +0 -333
  262. package/agent-spine-plugin/src/mcp.js +0 -456
  263. package/agent-spine-plugin/src/version.js +0 -1
  264. package/agent-spine-plugin/src/worker.js +0 -257
  265. package/bin/agentspine-king-goal-inbox.mjs +0 -127
  266. package/bin/agentspine-king-goal-intake.mjs +0 -106
  267. package/bin/agentspine-king-host-runner.mjs +0 -109
  268. package/bin/agentspine-king-snapshot-policy.cjs +0 -80
  269. package/bin/agentspine-king-status-policy.mjs +0 -226
  270. package/bin/agentspine-king-worker-host.mjs +0 -160
  271. package/bin/managed-plugin-selection.cjs +0 -141
  272. package/bin/verify-agent-behavior.cjs +0 -122
  273. 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
- }