blun-king-cli 9.1.566 → 9.1.569

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 (262) hide show
  1. package/agent-spine-plugin/.claude-plugin/marketplace.json +1 -1
  2. package/agent-spine-plugin/.claude-plugin/plugin.json +1 -1
  3. package/agent-spine-plugin/.codex-plugin/plugin.json +2 -1
  4. package/agent-spine-plugin/CHANGELOG.md +1581 -0
  5. package/agent-spine-plugin/README.md +30 -4
  6. package/agent-spine-plugin/blun.plugin.json +3 -3
  7. package/agent-spine-plugin/docs/acceptance.md +61 -0
  8. package/agent-spine-plugin/docs/assignment-continuation.md +48 -0
  9. package/agent-spine-plugin/docs/host-integration.md +178 -0
  10. package/agent-spine-plugin/docs/preflight-recall.md +69 -0
  11. package/agent-spine-plugin/docs/preservation-contract.md +53 -0
  12. package/agent-spine-plugin/docs/quality-gates.md +50 -0
  13. package/agent-spine-plugin/docs/releasing.md +85 -0
  14. package/agent-spine-plugin/docs/session-timeline.md +251 -0
  15. package/agent-spine-plugin/docs/source-roots.md +113 -0
  16. package/agent-spine-plugin/docs/structured-completion.md +67 -0
  17. package/agent-spine-plugin/docs/world-model.md +94 -0
  18. package/agent-spine-plugin/hooks/codex.json +2 -2
  19. package/agent-spine-plugin/hooks/hooks.json +1 -1
  20. package/agent-spine-plugin/hooks/version.json +1 -1
  21. package/agent-spine-plugin/package.json +13 -3
  22. package/agent-spine-plugin/scripts/check-codex-install.js +226 -0
  23. package/agent-spine-plugin/scripts/check-hosts.js +14 -5
  24. package/agent-spine-plugin/scripts/check-install-hook.js +226 -0
  25. package/agent-spine-plugin/scripts/check-install-selfstarter.js +154 -0
  26. package/agent-spine-plugin/scripts/check-install.js +478 -0
  27. package/agent-spine-plugin/scripts/check-line-budget.js +58 -0
  28. package/agent-spine-plugin/scripts/check-syntax.js +29 -0
  29. package/agent-spine-plugin/scripts/github-actions.js +11 -0
  30. package/agent-spine-plugin/scripts/hermetic-process.js +183 -0
  31. package/agent-spine-plugin/scripts/release-check.js +145 -0
  32. package/agent-spine-plugin/scripts/run-acceptance.js +19 -0
  33. package/agent-spine-plugin/scripts/run-checks.js +47 -0
  34. package/agent-spine-plugin/scripts/run-tests-hermetic.js +89 -0
  35. package/agent-spine-plugin/skills/agent-spine/SKILL.md +16 -2
  36. package/agent-spine-plugin/spine-example/1-identity.md +12 -0
  37. package/agent-spine-plugin/spine-example/2-voice.md +6 -0
  38. package/agent-spine-plugin/spine-example/3-conduct.md +8 -0
  39. package/agent-spine-plugin/spine-example/4-history.md +4 -0
  40. package/agent-spine-plugin/src/cli-agent.js +296 -0
  41. package/agent-spine-plugin/src/cli-attention.js +95 -0
  42. package/agent-spine-plugin/src/cli-autonomy.js +36 -0
  43. package/agent-spine-plugin/src/cli-common.js +71 -0
  44. package/agent-spine-plugin/src/cli-continuity.js +116 -0
  45. package/agent-spine-plugin/src/cli-core.js +128 -0
  46. package/agent-spine-plugin/src/cli-diagnostics.js +291 -0
  47. package/agent-spine-plugin/src/cli-host.js +21 -0
  48. package/agent-spine-plugin/src/cli-learning.js +305 -0
  49. package/agent-spine-plugin/src/cli-premortem.js +16 -0
  50. package/agent-spine-plugin/src/cli-sharing.js +230 -0
  51. package/agent-spine-plugin/src/cli.js +40 -1350
  52. package/agent-spine-plugin/src/codex-reader-launcher.js +182 -0
  53. package/agent-spine-plugin/src/hook.js +185 -567
  54. package/agent-spine-plugin/src/index.js +16 -2
  55. package/agent-spine-plugin/src/lib/acceptance.js +113 -11
  56. package/agent-spine-plugin/src/lib/action-lesson-recall.js +53 -0
  57. package/agent-spine-plugin/src/lib/attention-context.js +167 -0
  58. package/agent-spine-plugin/src/lib/attention-events.js +113 -0
  59. package/agent-spine-plugin/src/lib/attention-privacy.js +72 -0
  60. package/agent-spine-plugin/src/lib/attention-schema.js +164 -0
  61. package/agent-spine-plugin/src/lib/attention-storage.js +93 -0
  62. package/agent-spine-plugin/src/lib/attention.js +9 -600
  63. package/agent-spine-plugin/src/lib/audit-premortem.js +223 -0
  64. package/agent-spine-plugin/src/lib/audit.js +56 -6
  65. package/agent-spine-plugin/src/lib/autonomy-policy.js +110 -0
  66. package/agent-spine-plugin/src/lib/autonomy-store.js +202 -0
  67. package/agent-spine-plugin/src/lib/autonomy.js +8 -0
  68. package/agent-spine-plugin/src/lib/briefing.js +67 -4
  69. package/agent-spine-plugin/src/lib/catalog-document-read.js +51 -0
  70. package/agent-spine-plugin/src/lib/catalog.js +1 -1
  71. package/agent-spine-plugin/src/lib/codex-installation.js +231 -0
  72. package/agent-spine-plugin/src/lib/codex-skill-installation.js +211 -0
  73. package/agent-spine-plugin/src/lib/context.js +3 -1
  74. package/agent-spine-plugin/src/lib/delivery-agent-usage.js +224 -0
  75. package/agent-spine-plugin/src/lib/delivery-assignment.js +220 -0
  76. package/agent-spine-plugin/src/lib/delivery-command-actions.js +453 -0
  77. package/agent-spine-plugin/src/lib/delivery-knowledge.js +78 -0
  78. package/agent-spine-plugin/src/lib/delivery-premortem-binding.js +107 -0
  79. package/agent-spine-plugin/src/lib/delivery-premortem-closure.js +171 -0
  80. package/agent-spine-plugin/src/lib/delivery-premortem-codec.js +45 -0
  81. package/agent-spine-plugin/src/lib/delivery-premortem-correction.js +101 -0
  82. package/agent-spine-plugin/src/lib/delivery-premortem-file.js +21 -0
  83. package/agent-spine-plugin/src/lib/delivery-premortem-index.js +493 -0
  84. package/agent-spine-plugin/src/lib/delivery-premortem-inspection.js +37 -0
  85. package/agent-spine-plugin/src/lib/delivery-premortem-recovery.js +120 -0
  86. package/agent-spine-plugin/src/lib/delivery-premortem-rejection.js +65 -0
  87. package/agent-spine-plugin/src/lib/delivery-premortem-results.js +28 -0
  88. package/agent-spine-plugin/src/lib/delivery-premortem-session-guard.js +46 -0
  89. package/agent-spine-plugin/src/lib/delivery-premortem-write-ledger.js +285 -0
  90. package/agent-spine-plugin/src/lib/delivery-premortem.js +499 -0
  91. package/agent-spine-plugin/src/lib/delivery-shell-heredoc.js +115 -0
  92. package/agent-spine-plugin/src/lib/delivery-shell-substitutions.js +111 -0
  93. package/agent-spine-plugin/src/lib/delivery-shell-wrapper.js +64 -0
  94. package/agent-spine-plugin/src/lib/delivery-target.js +73 -0
  95. package/agent-spine-plugin/src/lib/delivery-verification.js +445 -0
  96. package/agent-spine-plugin/src/lib/documents.js +27 -5
  97. package/agent-spine-plugin/src/lib/filesystem-retry.js +2 -0
  98. package/agent-spine-plugin/src/lib/gateway-common.js +68 -0
  99. package/agent-spine-plugin/src/lib/gateway-control.js +302 -0
  100. package/agent-spine-plugin/src/lib/gateway-delivery.js +103 -0
  101. package/agent-spine-plugin/src/lib/gateway-execution.js +350 -0
  102. package/agent-spine-plugin/src/lib/gateway-host-lifecycle.js +185 -0
  103. package/agent-spine-plugin/src/lib/gateway-inspection.js +85 -0
  104. package/agent-spine-plugin/src/lib/gateway-knowledge.js +129 -0
  105. package/agent-spine-plugin/src/lib/gateway-policy-provenance.js +197 -0
  106. package/agent-spine-plugin/src/lib/gateway-premortem-disposition.js +82 -0
  107. package/agent-spine-plugin/src/lib/gateway-premortem.js +363 -0
  108. package/agent-spine-plugin/src/lib/gateway-runs.js +300 -0
  109. package/agent-spine-plugin/src/lib/gateway-runtime-identity.js +31 -0
  110. package/agent-spine-plugin/src/lib/gateway-runtime-records.js +21 -0
  111. package/agent-spine-plugin/src/lib/gateway-runtime.js +18 -1623
  112. package/agent-spine-plugin/src/lib/gateway-state-transaction.js +356 -0
  113. package/agent-spine-plugin/src/lib/gateway-state.js +342 -0
  114. package/agent-spine-plugin/src/lib/hook-artifact-guards.js +356 -0
  115. package/agent-spine-plugin/src/lib/hook-audit.js +16 -2
  116. package/agent-spine-plugin/src/lib/hook-briefing-use.js +68 -0
  117. package/agent-spine-plugin/src/lib/hook-context.js +424 -0
  118. package/agent-spine-plugin/src/lib/hook-final-message.js +26 -0
  119. package/agent-spine-plugin/src/lib/hook-input.js +27 -0
  120. package/agent-spine-plugin/src/lib/hook-output.js +140 -0
  121. package/agent-spine-plugin/src/lib/hook-premortem.js +257 -0
  122. package/agent-spine-plugin/src/lib/hook-process-advisory.js +37 -0
  123. package/agent-spine-plugin/src/lib/hook-protection.js +95 -0
  124. package/agent-spine-plugin/src/lib/hook-stop-verification.js +84 -0
  125. package/agent-spine-plugin/src/lib/hook-timeline.js +91 -0
  126. package/agent-spine-plugin/src/lib/identifier-analysis.js +446 -0
  127. package/agent-spine-plugin/src/lib/indexed-memory.js +23 -6
  128. package/agent-spine-plugin/src/lib/knowledge-evidence.js +431 -0
  129. package/agent-spine-plugin/src/lib/learning-applications.js +441 -0
  130. package/agent-spine-plugin/src/lib/learning-candidates.js +274 -0
  131. package/agent-spine-plugin/src/lib/learning-context.js +130 -0
  132. package/agent-spine-plugin/src/lib/learning-delivery-contracts.js +310 -0
  133. package/agent-spine-plugin/src/lib/learning-evaluation-contracts.js +350 -0
  134. package/agent-spine-plugin/src/lib/learning-evaluation-registration.js +372 -0
  135. package/agent-spine-plugin/src/lib/learning-evaluation-revocation.js +292 -0
  136. package/agent-spine-plugin/src/lib/learning-evidence-contracts.js +321 -0
  137. package/agent-spine-plugin/src/lib/learning-findings.js +458 -0
  138. package/agent-spine-plugin/src/lib/learning-measurement-contracts.js +285 -0
  139. package/agent-spine-plugin/src/lib/learning-measurements.js +265 -0
  140. package/agent-spine-plugin/src/lib/learning-outcome-contracts.js +165 -0
  141. package/agent-spine-plugin/src/lib/learning-outcomes.js +343 -0
  142. package/agent-spine-plugin/src/lib/learning-reconciliation.js +290 -0
  143. package/agent-spine-plugin/src/lib/learning-retry-contracts.js +188 -0
  144. package/agent-spine-plugin/src/lib/learning-schema.js +229 -0
  145. package/agent-spine-plugin/src/lib/learning-scope-targets.js +424 -0
  146. package/agent-spine-plugin/src/lib/learning-state-upgrade.js +477 -0
  147. package/agent-spine-plugin/src/lib/learning-status-configuration.js +476 -0
  148. package/agent-spine-plugin/src/lib/learning-storage.js +203 -0
  149. package/agent-spine-plugin/src/lib/learning-trial-recovery.js +218 -0
  150. package/agent-spine-plugin/src/lib/learning-validation-contracts.js +375 -0
  151. package/agent-spine-plugin/src/lib/learning-validation-renewal.js +298 -0
  152. package/agent-spine-plugin/src/lib/learning-validation-runtime.js +234 -0
  153. package/agent-spine-plugin/src/lib/learning.js +36 -6923
  154. package/agent-spine-plugin/src/lib/lesson-recall-session.js +172 -0
  155. package/agent-spine-plugin/src/lib/mcp-autonomy-tools.js +37 -0
  156. package/agent-spine-plugin/src/lib/mcp-delivery-completion.js +124 -0
  157. package/agent-spine-plugin/src/lib/mcp-delivery-tools.js +45 -0
  158. package/agent-spine-plugin/src/lib/mcp-premortem.js +68 -0
  159. package/agent-spine-plugin/src/lib/mcp-runtime.js +269 -0
  160. package/agent-spine-plugin/src/lib/mcp-source-context.js +51 -0
  161. package/agent-spine-plugin/src/lib/mcp-timeline-tools.js +164 -0
  162. package/agent-spine-plugin/src/lib/mcp-world-tools.js +52 -0
  163. package/agent-spine-plugin/src/lib/owned-file-lock.js +30 -10
  164. package/agent-spine-plugin/src/lib/project-portfolio.js +176 -0
  165. package/agent-spine-plugin/src/lib/selfstarter-core.js +382 -0
  166. package/agent-spine-plugin/src/lib/selfstarter-jobs.js +149 -0
  167. package/agent-spine-plugin/src/lib/selfstarter-lease.js +204 -0
  168. package/agent-spine-plugin/src/lib/selfstarter-policy.js +90 -0
  169. package/agent-spine-plugin/src/lib/selfstarter-workspace.js +111 -0
  170. package/agent-spine-plugin/src/lib/selfstarter.js +11 -911
  171. package/agent-spine-plugin/src/lib/session-timeline-auth.js +316 -0
  172. package/agent-spine-plugin/src/lib/session-timeline-codex.js +58 -0
  173. package/agent-spine-plugin/src/lib/session-timeline-contract.js +48 -0
  174. package/agent-spine-plugin/src/lib/session-timeline-enrollment-source.js +41 -0
  175. package/agent-spine-plugin/src/lib/session-timeline-enrollment-storage.js +132 -0
  176. package/agent-spine-plugin/src/lib/session-timeline-enrollment-transport.js +17 -0
  177. package/agent-spine-plugin/src/lib/session-timeline-enrollment.js +500 -0
  178. package/agent-spine-plugin/src/lib/session-timeline-event-extract.js +157 -0
  179. package/agent-spine-plugin/src/lib/session-timeline-host-origin.js +74 -0
  180. package/agent-spine-plugin/src/lib/session-timeline-host-receipt.js +117 -0
  181. package/agent-spine-plugin/src/lib/session-timeline-invocation.js +201 -0
  182. package/agent-spine-plugin/src/lib/session-timeline-king.js +79 -0
  183. package/agent-spine-plugin/src/lib/session-timeline-prior.js +59 -0
  184. package/agent-spine-plugin/src/lib/session-timeline-provider.js +34 -0
  185. package/agent-spine-plugin/src/lib/session-timeline-query.js +55 -0
  186. package/agent-spine-plugin/src/lib/session-timeline-results.js +31 -0
  187. package/agent-spine-plugin/src/lib/session-timeline-root.js +11 -0
  188. package/agent-spine-plugin/src/lib/session-timeline-search.js +82 -0
  189. package/agent-spine-plugin/src/lib/session-timeline-sid-acl.js +217 -0
  190. package/agent-spine-plugin/src/lib/session-timeline-source.js +83 -0
  191. package/agent-spine-plugin/src/lib/session-timeline-state.js +45 -0
  192. package/agent-spine-plugin/src/lib/session-timeline-transport.js +50 -0
  193. package/agent-spine-plugin/src/lib/session-timeline-windows-acl.js +148 -0
  194. package/agent-spine-plugin/src/lib/session-timeline.js +453 -0
  195. package/agent-spine-plugin/src/lib/source-roots.js +69 -136
  196. package/agent-spine-plugin/src/lib/source-tree-scan.js +178 -0
  197. package/agent-spine-plugin/src/lib/task-knowledge-context.js +78 -0
  198. package/agent-spine-plugin/src/lib/timeline-tool-guard.js +202 -0
  199. package/agent-spine-plugin/src/lib/world-knowledge.js +249 -0
  200. package/agent-spine-plugin/src/lib/world-model.js +278 -0
  201. package/agent-spine-plugin/src/mcp.js +20 -161
  202. package/agent-spine-plugin/src/version.js +1 -1
  203. package/agent-spine-plugin/src/worker.js +22 -5
  204. package/bin/agent-resume-snapshot.cjs +2 -2
  205. package/bin/agentspine-king-goal-inbox.mjs +111 -0
  206. package/bin/agentspine-king-goal-intake.mjs +106 -0
  207. package/bin/baseline-skill-performance-policy.cjs +1 -16
  208. package/bin/core-bootstrap.js +2 -0
  209. package/bin/curiosity-scout-policy.cjs +5 -1
  210. package/bin/input-draft-persistence.cjs +2 -2
  211. package/bin/king-tui-function-contract.json +33 -0
  212. package/bin/launcher-restart-policy.cjs +150 -0
  213. package/bin/launcher-runtime.js +56 -44
  214. package/bin/managed-context-startup-policy.cjs +27 -0
  215. package/bin/managed-plugin-selection.cjs +116 -0
  216. package/bin/mistake-relevance-policy.cjs +1 -1
  217. package/bin/observer-hooks.cjs +14 -0
  218. package/bin/oversized-context-offload-policy.cjs +86 -0
  219. package/bin/plugin-bootstrap.js +7 -40
  220. package/bin/proactive-compaction-policy.cjs +1 -1
  221. package/bin/provider-model-refresh-deadline.cjs +53 -0
  222. package/bin/provider-model-refresh-policy.cjs +107 -0
  223. package/bin/release-artifact-freeze-policy.cjs +30 -0
  224. package/bin/repeated-user-message-projection.cjs +3 -126
  225. package/bin/research-page-result.cjs +74 -0
  226. package/bin/runtime-exit-ledger.cjs +1 -0
  227. package/bin/session-compaction-policy.cjs +84 -0
  228. package/bin/skill-listing-performance-policy.cjs +2 -2
  229. package/bin/standard-tools-bootstrap.js +0 -37
  230. package/bin/subagent-skill-policy.cjs +3 -1
  231. package/bin/telegram-approval-relay.cjs +12 -7
  232. package/bin/telegram-private-conversation-policy.cjs +3 -2
  233. package/bin/telegram-queue-handoff-policy.cjs +24 -0
  234. package/bin/thinking-activity-status-policy.cjs +1 -1
  235. package/bin/thinking-only-guard.cjs +16 -12
  236. package/bin/tool-call-loop-policy.cjs +0 -2
  237. package/bin/tool-result-offload-policy.cjs +11 -2
  238. package/bin/tui-functional-contract.cjs +55 -0
  239. package/bin/update-notice.js +18 -14
  240. package/bin/user-message-offload-policy.cjs +1 -1
  241. package/bin/user-prompt-hook-origin-policy.cjs +34 -0
  242. package/bin/windows-node-crash-dump.cjs +110 -0
  243. package/blun.mjs +2517 -1048
  244. package/codebase-index/codebase_index.py +4 -3
  245. package/package.json +3 -17
  246. package/standard-skills/research-evidence/SKILL.md +39 -0
  247. package/standard-skills/research-evidence/references/evidence-format.md +82 -0
  248. package/standard-skills/research-evidence/scripts/evidence-collection.cjs +254 -0
  249. package/standard-skills/research-evidence/scripts/score-report.cjs +112 -0
  250. package/standard-skills/web-lesen/SKILL.md +37 -22
  251. package/standard-skills/web-lesen/scripts/crawl_public.py +376 -0
  252. package/telegram-plugin/DELIVERY.md +36 -0
  253. package/telegram-plugin/bin/telegram-approval-relay.cjs +13 -7
  254. package/telegram-plugin/bin/telegram-launcher-status-queue.cjs +122 -0
  255. package/telegram-plugin/bin/telegram-private-conversation-policy.cjs +3 -2
  256. package/telegram-plugin/bin/telegram-reply-parts.cjs +149 -0
  257. package/telegram-plugin/dist/bridge.mjs +11 -57
  258. package/telegram-plugin/dist/mcp-server.mjs +33 -4
  259. package/agent-spine-plugin/skill/SKILL.md +0 -76
  260. package/bin/mnemo-connect-heartbeat.cjs +0 -204
  261. package/bin/mnemo-tool-agent-policy.cjs +0 -22
  262. package/telegram-plugin/bin/telegram-mnemo-capture.cjs +0 -297
@@ -0,0 +1,458 @@
1
+ import {
2
+ KINDS, EVIDENCE_TYPES, PRIVACY, STATUSES, AUTO_KINDS, OUTCOME_AUTO_KINDS,
3
+ CONTINUITY_AUTO_KINDS, SCOPE_FIELDS, ID_RE, DIGEST_RE, SECRET_RE, AUTHORITY_ASSERTION_RE,
4
+ LINEAGE_EVALUATIONS, ROOT_BOUND_EVALUATIONS, REGISTRY_BOUND_EVALUATIONS, TRIAL_RETRY_EVALUATIONS, CANDIDATE_ADMISSION_EVALUATIONS, CANDIDATE_EVIDENCE_LINEAGE_EVALUATIONS,
5
+ DELIVERABLE_APPLICATIONS
6
+ } from "./learning-schema.js";
7
+ import {
8
+ validConfig, scopeContains, exactScope, digest, storedEvidenceRevocationStructure, evidenceRevocationMatchesState,
9
+ storedOutcomeStructure, storedMeasurementStructure, storedMeasurementRevocationStructure, measurementRevocationMatchesState, revokedMeasurementForCandidate, measurementRunDigest,
10
+ evaluatorRootRunDigest, activeEvaluationBinding, storedEvaluationRevocationStructure, evaluationRevocationMatchesState
11
+ } from "./learning-scope-targets.js";
12
+ import {
13
+ revokedEvaluationForCandidate, storedRevalidationWindowStructure, revalidationWindowMatchesState, storedValidationLeaseStructure, validationLeaseMatchesState
14
+ } from "./learning-validation-contracts.js";
15
+ import {
16
+ storedValidationRevocationStructure, validationRevocationMatchesState, revokedValidationForCandidate
17
+ } from "./learning-validation-runtime.js";
18
+ import {
19
+ storedMeasurementLineageStructure, storedEvidenceSourceAttestationRevocationStructure, evidenceSourceAttestationRevocationMatchesState, revokedEvidenceSourceAttestationForCandidate
20
+ } from "./learning-measurement-contracts.js";
21
+ import {
22
+ storedCandidateEvidenceLineageStructure, candidateEvidenceLineageMatchesEvaluation, candidateAdmissionMatches
23
+ } from "./learning-evidence-contracts.js";
24
+ import {
25
+ storedEvaluationStructure, storedApplicationStructure, storedTrialFailureStructure, trialFailureMatchesState, storedTrialFailureRevocationStructure, trialFailureRevocationMatchesState
26
+ } from "./learning-evaluation-contracts.js";
27
+ import {
28
+ trialRetryMatchesState, storedTrialRetryExhaustionStructure, trialRetryExhaustionMatchesState
29
+ } from "./learning-retry-contracts.js";
30
+ import {
31
+ storedDeliveryStructure, storedApplicationRevocationStructure, applicationRevocationMatchesState, revokedApplicationForCandidate, storedDeliveryRevocationStructure, deliveryRevocationMatchesState,
32
+ revokedDeliveryForCandidate, storedOutcomeRevocationStructure, outcomeRevocationMatchesState, revokedOutcomeForCandidate
33
+ } from "./learning-delivery-contracts.js";
34
+ import {
35
+ isGroupMember, evidenceConfidence
36
+ } from "./learning-storage.js";
37
+ import {
38
+ distinctEvidence
39
+ } from "./learning-candidates.js";
40
+
41
+ export function learningFindings(learning, graph) {
42
+ const findings = [];
43
+ if (!validConfig(learning.config)) findings.push("invalid-config");
44
+ const groups = new Set(graph.entities.filter((entity) => entity.kind === "group").map((entity) => entity.id));
45
+ for (const candidate of learning.candidates) {
46
+ if (!KINDS.has(candidate.kind) || !STATUSES.has(candidate.status) || !PRIVACY.has(candidate.privacy)) findings.push(`invalid-candidate:${candidate.id}`);
47
+ const nested = [...(candidate.evidence || []), candidate.review, candidate.rollback, candidate.promotion].filter(Boolean);
48
+ if (candidate.authority !== "context-only" || nested.some((item) => item.authority !== "context-only")) findings.push(`authority:${candidate.id}`);
49
+ if (SECRET_RE.test(candidate.claim || "") || AUTHORITY_ASSERTION_RE.test(candidate.claim || "")) findings.push(`unsafe-claim:${candidate.id}`);
50
+ if (candidate.evidence?.some((item) => SECRET_RE.test(item.summary || ""))) findings.push(`unsafe-evidence:${candidate.id}`);
51
+ const evidenceValid = candidate.evidence.length > 0 && candidate.evidence.every((item) => (
52
+ ID_RE.test(item.id || "") && EVIDENCE_TYPES.has(item.type)
53
+ && typeof item.summary === "string" && item.summary.length > 0
54
+ && Number.isFinite(item.confidence) && item.confidence >= 0 && item.confidence <= 1
55
+ && Number.isFinite(new Date(item.observedAt).getTime())
56
+ && (item.type !== "document" || (item.sourceDocument && /^[a-f0-9]{64}$/.test(item.sourceSha256 || "")))
57
+ ));
58
+ if (!evidenceValid || !Number.isFinite(candidate.confidence)
59
+ || Math.abs(candidate.confidence - evidenceConfidence(candidate.evidence)) > 1e-12) {
60
+ findings.push(`invalid-evidence:${candidate.id}`);
61
+ }
62
+ if (candidate.privacy === "group" && (!groups.has(candidate.groupId) || !isGroupMember(graph, candidate.groupId, candidate.subjectId))) findings.push(`invalid-group:${candidate.id}`);
63
+ if (!candidate.scope || Object.keys(candidate.scope).some((field) => !SCOPE_FIELDS.includes(field))
64
+ || Object.values(candidate.scope || {}).some((value) => value !== null && !ID_RE.test(value))) findings.push(`invalid-scope:${candidate.id}`);
65
+ if (candidate.status === "accepted") {
66
+ if ((learning.evidenceRevocations || []).some((receipt) => receipt.learningId === candidate.id)) {
67
+ findings.push(`revoked-evidence:${candidate.id}`);
68
+ }
69
+ if (revokedMeasurementForCandidate(learning, candidate)) findings.push(`revoked-measurement:${candidate.id}`);
70
+ if (revokedApplicationForCandidate(learning, candidate)) findings.push(`revoked-application:${candidate.id}`);
71
+ if (revokedDeliveryForCandidate(learning, candidate)) findings.push(`revoked-delivery:${candidate.id}`);
72
+ if (revokedOutcomeForCandidate(learning, candidate)) findings.push(`revoked-outcome:${candidate.id}`);
73
+ const canaryEvaluation = candidate.promotion?.canary?.evaluationId
74
+ ? (learning.evaluations || []).find((contract) => contract.id === candidate.promotion.canary.evaluationId)
75
+ : null;
76
+ const manualProof = candidate.automatic === false
77
+ && candidate.review?.decision === "accept" && candidate.review?.confirmedByUser === true;
78
+ const automaticProof = candidate.automatic === true
79
+ && ((AUTO_KINDS.has(candidate.kind)
80
+ && candidate.promotion?.mode === "automatic-low-risk"
81
+ && candidate.confidence >= candidate.promotion?.minConfidence
82
+ && distinctEvidence(candidate) >= candidate.promotion?.minEvidence
83
+ && candidate.promotion?.evidenceCount >= candidate.promotion?.minEvidence)
84
+ || (CONTINUITY_AUTO_KINDS.has(candidate.kind)
85
+ && candidate.promotion?.mode === "automatic-continuity-low-risk"
86
+ && candidate.promotion?.localOptIn === true
87
+ && candidate.confidence >= candidate.promotion?.minConfidence
88
+ && candidate.promotion?.directness >= candidate.promotion?.minDirectness
89
+ && distinctEvidence(candidate) >= candidate.promotion?.minEvidence
90
+ && candidate.promotion?.evidenceCount >= candidate.promotion?.minEvidence)
91
+ || (OUTCOME_AUTO_KINDS.has(candidate.kind)
92
+ && candidate.promotion?.mode === "outcome-canary"
93
+ && candidate.requiresLocalReview === false
94
+ && ["active", "validated"].includes(candidate.promotion?.canary?.status)
95
+ && candidate.confidence >= candidate.promotion?.minConfidence
96
+ && distinctEvidence(candidate) >= candidate.promotion?.minEvidence
97
+ && candidate.promotion?.canary?.beforeReceipts?.length >= (canaryEvaluation?.thresholds.beforeReceipts
98
+ ?? learning.config.minOutcomeReceipts)
99
+ && (!candidate.promotion?.canary?.evaluationId
100
+ || (canaryEvaluation && canaryEvaluation.digest === candidate.promotion.canary.evaluationDigest))));
101
+ if (!candidate.acceptedAt || (!manualProof && !automaticProof)) findings.push(`invalid-acceptance:${candidate.id}`);
102
+ if (candidate.promotion?.mode === "outcome-canary" && ["active", "validated"].includes(candidate.promotion?.canary?.status)
103
+ && new Date(candidate.promotion.canary.expiresAt).getTime() <= Date.now()) findings.push(`stale-canary:${candidate.id}`);
104
+ if (candidate.promotion?.mode === "outcome-canary" && ["active", "validated"].includes(candidate.promotion?.canary?.status)
105
+ && REGISTRY_BOUND_EVALUATIONS.has(canaryEvaluation?.schema)
106
+ && !activeEvaluationBinding(learning, canaryEvaluation)) findings.push(`inactive-evaluator-canary:${candidate.id}`);
107
+ if (revokedEvaluationForCandidate(learning, candidate)) findings.push(`revoked-evaluation:${candidate.id}`);
108
+ if (revokedEvidenceSourceAttestationForCandidate(learning, candidate)) {
109
+ findings.push(`revoked-evidence-source-attestation:${candidate.id}`);
110
+ }
111
+ if (revokedValidationForCandidate(learning, candidate)) findings.push(`revoked-validation:${candidate.id}`);
112
+ if (candidate.promotion?.mode === "outcome-canary" && candidate.promotion?.canary?.status === "validated"
113
+ && REGISTRY_BOUND_EVALUATIONS.has(canaryEvaluation?.schema)
114
+ && !(learning.validationLeases || []).some((lease) => lease.id === candidate.promotion.canary.validationLeaseId
115
+ && lease.digest === candidate.promotion.canary.validationLeaseDigest
116
+ && storedValidationLeaseStructure(lease) && validationLeaseMatchesState(learning, lease))) {
117
+ findings.push(`missing-validation-lease:${candidate.id}`);
118
+ }
119
+ const revalidation = candidate.promotion?.canary?.revalidation;
120
+ const predecessorValidation = revalidation ? (learning.validationLeases || []).find((lease) =>
121
+ lease.id === revalidation.predecessorValidationId
122
+ && lease.digest === revalidation.predecessorValidationDigest && lease.learningId === candidate.id) : null;
123
+ const revalidationBaselineReferences = predecessorValidation?.schema === "agentspine.learning-validation/v1"
124
+ ? predecessorValidation.beforeOutcomes : predecessorValidation?.baselineOutcomes;
125
+ const revalidationRoots = (revalidationBaselineReferences || []).map((reference) =>
126
+ (learning.outcomes || []).find((outcome) => outcome.id === reference.id && outcome.digest === reference.digest))
127
+ .filter(Boolean).sort((a, b) => a.measurement.evaluatorId.localeCompare(b.measurement.evaluatorId))
128
+ .map((outcome) => outcome.measurement.evaluatorRootDigest);
129
+ if (revalidation && (candidate.promotion?.canary?.status !== "validated"
130
+ || !storedRevalidationWindowStructure(revalidation) || !predecessorValidation
131
+ || !revalidationWindowMatchesState(learning, candidate)
132
+ || (["agentspine.learning-revalidation-window/v2", "agentspine.learning-revalidation-window/v3",
133
+ "agentspine.learning-revalidation-window/v4"]
134
+ .includes(revalidation.schema)
135
+ && (revalidation.selection.requiredDeliveries !== revalidationRoots.length
136
+ || revalidation.selection.evaluatorRoots.some((entry, index) =>
137
+ entry.evaluatorRootDigest !== revalidationRoots[index]))))) {
138
+ findings.push(`invalid-revalidation:${candidate.id}`);
139
+ }
140
+ }
141
+ }
142
+ const outcomeIds = new Set();
143
+ for (const receipt of learning.outcomes || []) {
144
+ const candidate = learning.candidates.find((item) => item.id === receipt.learningId);
145
+ const valid = storedOutcomeStructure(receipt) && candidate && scopeContains(candidate.scope, receipt.scope);
146
+ if (!valid || outcomeIds.has(receipt.id)) findings.push(`invalid-outcome:${receipt.id || "unknown"}`);
147
+ outcomeIds.add(receipt.id);
148
+ }
149
+ const evaluationIds = new Set();
150
+ for (const contract of learning.evaluations || []) {
151
+ const candidate = learning.candidates.find((item) => item.id === contract.learningId);
152
+ const valid = storedEvaluationStructure(contract) && candidate && scopeContains(candidate.scope, contract.scope)
153
+ && (!CANDIDATE_ADMISSION_EVALUATIONS.has(contract.schema)
154
+ || candidateAdmissionMatches(contract, candidate));
155
+ if (!valid || evaluationIds.has(contract.id)) findings.push(`invalid-evaluation:${contract.id || "unknown"}`);
156
+ if (REGISTRY_BOUND_EVALUATIONS.has(contract.schema)) {
157
+ const binding = (learning.evaluationBindings || []).find((entry) => entry.evaluationId === contract.id);
158
+ if (!binding || binding.evaluationDigest !== contract.digest) findings.push(`invalid-evaluator-binding:${contract.id}`);
159
+ }
160
+ evaluationIds.add(contract.id);
161
+ }
162
+ const candidateEvidenceDigests = new Set();
163
+ const candidateEvidenceIndependence = new Set();
164
+ for (const lineage of learning.candidateEvidenceLineage || []) {
165
+ const evidenceKey = `${lineage.scopeDigest}\0${lineage.evidenceDigest}`;
166
+ const independenceKey = `${lineage.scopeDigest}\0${lineage.independenceDigest}`;
167
+ const valid = storedCandidateEvidenceLineageStructure(lineage);
168
+ if (!valid || candidateEvidenceDigests.has(evidenceKey)
169
+ || candidateEvidenceIndependence.has(independenceKey)) {
170
+ findings.push(`invalid-candidate-evidence-lineage:${lineage.evaluationId || "unknown"}`);
171
+ }
172
+ candidateEvidenceDigests.add(evidenceKey);
173
+ candidateEvidenceIndependence.add(independenceKey);
174
+ }
175
+ for (const contract of (learning.evaluations || [])
176
+ .filter((entry) => CANDIDATE_EVIDENCE_LINEAGE_EVALUATIONS.has(entry.schema))) {
177
+ if (!candidateEvidenceLineageMatchesEvaluation(learning, contract)) {
178
+ findings.push(`invalid-candidate-evidence-lineage-binding:${contract.id || "unknown"}`);
179
+ }
180
+ }
181
+ const validationLeaseIds = new Set();
182
+ const validatedLearningIds = new Set();
183
+ for (const lease of learning.validationLeases || []) {
184
+ const valid = storedValidationLeaseStructure(lease) && validationLeaseMatchesState(learning, lease);
185
+ if (!valid || validationLeaseIds.has(lease.id) || validatedLearningIds.has(lease.learningId)) {
186
+ findings.push(`invalid-validation-lease:${lease.id || "unknown"}`);
187
+ }
188
+ validationLeaseIds.add(lease.id);
189
+ validatedLearningIds.add(lease.learningId);
190
+ }
191
+ const trialFailureIds = new Set();
192
+ const failedApplications = new Set();
193
+ for (const receipt of learning.trialFailures || []) {
194
+ const valid = storedTrialFailureStructure(receipt) && trialFailureMatchesState(learning, receipt);
195
+ if (!valid || trialFailureIds.has(receipt.id) || failedApplications.has(receipt.applicationId)) {
196
+ findings.push(`invalid-trial-failure:${receipt.id || "unknown"}`);
197
+ }
198
+ trialFailureIds.add(receipt.id);
199
+ failedApplications.add(receipt.applicationId);
200
+ }
201
+ const trialFailureRevocationIds = new Set();
202
+ const revokedTrialFailureIds = new Set();
203
+ for (const receipt of learning.trialFailureRevocations || []) {
204
+ const valid = storedTrialFailureRevocationStructure(receipt)
205
+ && trialFailureRevocationMatchesState(learning, receipt);
206
+ if (!valid || trialFailureRevocationIds.has(receipt.id)
207
+ || revokedTrialFailureIds.has(receipt.trialFailureId)) {
208
+ findings.push(`invalid-trial-failure-revocation:${receipt.id || "unknown"}`);
209
+ }
210
+ trialFailureRevocationIds.add(receipt.id);
211
+ revokedTrialFailureIds.add(receipt.trialFailureId);
212
+ }
213
+ const retryRevocationIds = new Set();
214
+ for (const contract of (learning.evaluations || []).filter((entry) => TRIAL_RETRY_EVALUATIONS.has(entry.schema))) {
215
+ if (!trialRetryMatchesState(learning, contract)
216
+ || retryRevocationIds.has(contract.retry?.trialFailureRevocationId)) {
217
+ findings.push(`invalid-trial-retry:${contract.id || "unknown"}`);
218
+ }
219
+ retryRevocationIds.add(contract.retry?.trialFailureRevocationId);
220
+ }
221
+ const trialRetryExhaustionIds = new Set();
222
+ const exhaustedCorrectiveEvaluations = new Set();
223
+ const exhaustedTrialFailures = new Set();
224
+ for (const receipt of learning.trialRetryExhaustions || []) {
225
+ const valid = storedTrialRetryExhaustionStructure(receipt)
226
+ && trialRetryExhaustionMatchesState(learning, receipt);
227
+ if (!valid || trialRetryExhaustionIds.has(receipt.id)
228
+ || exhaustedCorrectiveEvaluations.has(receipt.correctiveEvaluationId)
229
+ || exhaustedTrialFailures.has(receipt.trialFailureId)) {
230
+ findings.push(`invalid-trial-retry-exhaustion:${receipt.id || "unknown"}`);
231
+ }
232
+ trialRetryExhaustionIds.add(receipt.id);
233
+ exhaustedCorrectiveEvaluations.add(receipt.correctiveEvaluationId);
234
+ exhaustedTrialFailures.add(receipt.trialFailureId);
235
+ }
236
+ const evaluationRevocationIds = new Set();
237
+ const revokedEvaluationIds = new Set();
238
+ for (const receipt of learning.evaluationRevocations || []) {
239
+ const valid = storedEvaluationRevocationStructure(receipt) && evaluationRevocationMatchesState(learning, receipt);
240
+ if (!valid || evaluationRevocationIds.has(receipt.id) || revokedEvaluationIds.has(receipt.evaluationId)) {
241
+ findings.push(`invalid-evaluation-revocation:${receipt.id || "unknown"}`);
242
+ }
243
+ evaluationRevocationIds.add(receipt.id);
244
+ revokedEvaluationIds.add(receipt.evaluationId);
245
+ }
246
+ const evidenceSourceAttestationRevocationIds = new Set();
247
+ const revokedEvidenceSourceAttestations = new Set();
248
+ for (const receipt of learning.evidenceSourceAttestationRevocations || []) {
249
+ const key = `${receipt.evaluationId}\0${receipt.evidenceDigest}`;
250
+ const valid = storedEvidenceSourceAttestationRevocationStructure(receipt)
251
+ && evidenceSourceAttestationRevocationMatchesState(learning, receipt);
252
+ if (!valid || evidenceSourceAttestationRevocationIds.has(receipt.id)
253
+ || revokedEvidenceSourceAttestations.has(key)) {
254
+ findings.push(`invalid-evidence-source-attestation-revocation:${receipt.id || "unknown"}`);
255
+ }
256
+ evidenceSourceAttestationRevocationIds.add(receipt.id);
257
+ revokedEvidenceSourceAttestations.add(key);
258
+ }
259
+ const validationRevocationIds = new Set();
260
+ const revokedValidationLeaseIds = new Set();
261
+ for (const receipt of learning.validationRevocations || []) {
262
+ const valid = storedValidationRevocationStructure(receipt) && validationRevocationMatchesState(learning, receipt);
263
+ if (!valid || validationRevocationIds.has(receipt.id)
264
+ || revokedValidationLeaseIds.has(receipt.validationLeaseId)) {
265
+ findings.push(`invalid-validation-revocation:${receipt.id || "unknown"}`);
266
+ }
267
+ validationRevocationIds.add(receipt.id);
268
+ revokedValidationLeaseIds.add(receipt.validationLeaseId);
269
+ }
270
+ const evidenceRevocationIds = new Set();
271
+ const revokedEvidenceKeys = new Set();
272
+ for (const receipt of learning.evidenceRevocations || []) {
273
+ const key = `${receipt.learningId}\0${receipt.evidenceId}`;
274
+ const valid = storedEvidenceRevocationStructure(receipt) && evidenceRevocationMatchesState(learning, receipt);
275
+ if (!valid || evidenceRevocationIds.has(receipt.id) || revokedEvidenceKeys.has(key)) {
276
+ findings.push(`invalid-evidence-revocation:${receipt.id || "unknown"}`);
277
+ }
278
+ evidenceRevocationIds.add(receipt.id);
279
+ revokedEvidenceKeys.add(key);
280
+ }
281
+ const measurementRevocationIds = new Set();
282
+ const revokedMeasurementIds = new Set();
283
+ for (const receipt of learning.measurementRevocations || []) {
284
+ const valid = storedMeasurementRevocationStructure(receipt) && measurementRevocationMatchesState(learning, receipt);
285
+ if (!valid || measurementRevocationIds.has(receipt.id) || revokedMeasurementIds.has(receipt.measurementId)) {
286
+ findings.push(`invalid-measurement-revocation:${receipt.id || "unknown"}`);
287
+ }
288
+ measurementRevocationIds.add(receipt.id);
289
+ revokedMeasurementIds.add(receipt.measurementId);
290
+ }
291
+ const applicationRevocationIds = new Set();
292
+ const revokedApplicationIds = new Set();
293
+ for (const receipt of learning.applicationRevocations || []) {
294
+ const valid = storedApplicationRevocationStructure(receipt) && applicationRevocationMatchesState(learning, receipt);
295
+ if (!valid || applicationRevocationIds.has(receipt.id) || revokedApplicationIds.has(receipt.applicationId)) {
296
+ findings.push(`invalid-application-revocation:${receipt.id || "unknown"}`);
297
+ }
298
+ applicationRevocationIds.add(receipt.id);
299
+ revokedApplicationIds.add(receipt.applicationId);
300
+ }
301
+ const deliveryRevocationIds = new Set();
302
+ const revokedDeliveryIds = new Set();
303
+ for (const receipt of learning.deliveryRevocations || []) {
304
+ const valid = storedDeliveryRevocationStructure(receipt) && deliveryRevocationMatchesState(learning, receipt);
305
+ if (!valid || deliveryRevocationIds.has(receipt.id) || revokedDeliveryIds.has(receipt.deliveryId)) {
306
+ findings.push(`invalid-delivery-revocation:${receipt.id || "unknown"}`);
307
+ }
308
+ deliveryRevocationIds.add(receipt.id);
309
+ revokedDeliveryIds.add(receipt.deliveryId);
310
+ }
311
+ const outcomeRevocationIds = new Set();
312
+ const revokedOutcomeIds = new Set();
313
+ for (const receipt of learning.outcomeRevocations || []) {
314
+ const valid = storedOutcomeRevocationStructure(receipt) && outcomeRevocationMatchesState(learning, receipt);
315
+ if (!valid || outcomeRevocationIds.has(receipt.id) || revokedOutcomeIds.has(receipt.outcomeId)) {
316
+ findings.push(`invalid-outcome-revocation:${receipt.id || "unknown"}`);
317
+ }
318
+ outcomeRevocationIds.add(receipt.id);
319
+ revokedOutcomeIds.add(receipt.outcomeId);
320
+ }
321
+ const measurementIds = new Set();
322
+ const measurementSources = new Set();
323
+ const measurementRuns = new Set();
324
+ const evaluatorRootRuns = new Set();
325
+ const measurementLineageIds = new Set();
326
+ for (const lineage of learning.measurementLineage || []) {
327
+ const valid = storedMeasurementLineageStructure(lineage);
328
+ if (!valid || measurementLineageIds.has(lineage.measurementReceiptId)) {
329
+ findings.push(`invalid-measurement-lineage:${lineage.measurementReceiptId || "unknown"}`);
330
+ }
331
+ if (measurementSources.has(lineage.sourceDigest) || measurementRuns.has(lineage.runDigest)
332
+ || (lineage.schema === "agentspine.learning-measurement-lineage/v2" && evaluatorRootRuns.has(lineage.rootRunDigest))) {
333
+ findings.push(`replayed-measurement-lineage:${lineage.measurementReceiptId || "unknown"}`);
334
+ }
335
+ measurementLineageIds.add(lineage.measurementReceiptId);
336
+ measurementSources.add(lineage.sourceDigest);
337
+ measurementRuns.add(lineage.runDigest);
338
+ if (lineage.schema === "agentspine.learning-measurement-lineage/v2") evaluatorRootRuns.add(lineage.rootRunDigest);
339
+ }
340
+ for (const receipt of learning.measurements || []) {
341
+ const candidate = learning.candidates.find((item) => item.id === receipt.learningId);
342
+ const contract = (learning.evaluations || []).find((item) => item.id === receipt.evaluationId);
343
+ const lineage = (learning.measurementLineage || []).find((item) => item.measurementReceiptId === receipt.id);
344
+ const valid = storedMeasurementStructure(receipt) && candidate && contract
345
+ && LINEAGE_EVALUATIONS.has(contract.schema)
346
+ && contract.learningId === receipt.learningId
347
+ && exactScope(contract.scope, receipt.scope) && scopeContains(candidate.scope, receipt.scope)
348
+ && lineage?.sourceDigest === receipt.measurement?.sourceDigest
349
+ && lineage?.runDigest === measurementRunDigest(receipt.measurement?.evaluatorId, receipt.measurement?.runId)
350
+ && (receipt.schema !== "agentspine.learning-measurement/v2"
351
+ || (ROOT_BOUND_EVALUATIONS.has(contract.schema)
352
+ && contract.evaluatorRoots.some((root) => root.evaluatorId === receipt.measurement?.evaluatorId
353
+ && root.principalDigest === receipt.measurement?.evaluatorRootDigest)
354
+ && lineage?.schema === "agentspine.learning-measurement-lineage/v2"
355
+ && lineage?.evaluatorRootDigest === receipt.measurement?.evaluatorRootDigest
356
+ && lineage?.rootRunDigest === evaluatorRootRunDigest(receipt.measurement?.evaluatorRootDigest, receipt.measurement?.runId)))
357
+ && lineage?.registeredAt === receipt.measuredAt;
358
+ if (!valid || measurementIds.has(receipt.id)) findings.push(`invalid-measurement:${receipt.id || "unknown"}`);
359
+ measurementIds.add(receipt.id);
360
+ }
361
+ const applicationIds = new Set();
362
+ for (const receipt of learning.applications || []) {
363
+ const candidate = learning.candidates.find((item) => item.id === receipt.learningId);
364
+ const valid = storedApplicationStructure(receipt) && candidate && scopeContains(candidate.scope, receipt.scope);
365
+ if (!valid || applicationIds.has(receipt.id)) findings.push(`invalid-application:${receipt.id || "unknown"}`);
366
+ if (DELIVERABLE_APPLICATIONS.has(receipt.schema)
367
+ && new Date(receipt.deliveryExpiresAt).getTime() < Date.now()
368
+ && !(learning.deliveries || []).some((delivery) => delivery.applicationId === receipt.id)
369
+ && !failedApplications.has(receipt.id)) {
370
+ findings.push(`stale-undelivered-application:${receipt.id}`);
371
+ }
372
+ applicationIds.add(receipt.id);
373
+ }
374
+ const deliveryIds = new Set();
375
+ for (const receipt of learning.deliveries || []) {
376
+ const candidate = learning.candidates.find((item) => item.id === receipt.learningId);
377
+ const application = learning.applications.find((item) => item.id === receipt.applicationId);
378
+ const valid = storedDeliveryStructure(receipt) && candidate && application
379
+ && application.learningId === receipt.learningId && application.sessionId === receipt.sessionId
380
+ && exactScope(application.scope, receipt.scope) && scopeContains(candidate.scope, receipt.scope);
381
+ if (!valid || deliveryIds.has(receipt.id)) findings.push(`invalid-delivery:${receipt.id || "unknown"}`);
382
+ deliveryIds.add(receipt.id);
383
+ }
384
+ for (const receipt of learning.outcomes || []) {
385
+ if (["agentspine.learning-outcome/v2", "agentspine.learning-outcome/v3", "agentspine.learning-outcome/v4", "agentspine.learning-outcome/v5", "agentspine.learning-outcome/v6", "agentspine.learning-outcome/v7", "agentspine.learning-outcome/v8", "agentspine.learning-outcome/v9"].includes(receipt.schema) && receipt.phase === "after"
386
+ && !applicationIds.has(receipt.applicationId)) findings.push(`unbound-outcome:${receipt.id}`);
387
+ if (["agentspine.learning-outcome/v3", "agentspine.learning-outcome/v4", "agentspine.learning-outcome/v5", "agentspine.learning-outcome/v6", "agentspine.learning-outcome/v7", "agentspine.learning-outcome/v8", "agentspine.learning-outcome/v9"].includes(receipt.schema) && !evaluationIds.has(receipt.evaluationId)) {
388
+ findings.push(`unplanned-outcome:${receipt.id}`);
389
+ }
390
+ if (["agentspine.learning-outcome/v4", "agentspine.learning-outcome/v5", "agentspine.learning-outcome/v6", "agentspine.learning-outcome/v7", "agentspine.learning-outcome/v8", "agentspine.learning-outcome/v9"].includes(receipt.schema) && receipt.phase === "after"
391
+ && !deliveryIds.has(receipt.deliveryId)) findings.push(`undelivered-outcome:${receipt.id}`);
392
+ if (["agentspine.learning-outcome/v5", "agentspine.learning-outcome/v6", "agentspine.learning-outcome/v7", "agentspine.learning-outcome/v8", "agentspine.learning-outcome/v9"].includes(receipt.schema)) {
393
+ const contract = (learning.evaluations || []).find((item) => item.id === receipt.evaluationId);
394
+ if (!contract
395
+ || (receipt.schema === "agentspine.learning-outcome/v5" && contract.schema !== "agentspine.learning-evaluation/v2")
396
+ || (receipt.schema === "agentspine.learning-outcome/v6" && contract.schema !== "agentspine.learning-evaluation/v3")
397
+ || (receipt.schema === "agentspine.learning-outcome/v7" && contract.schema !== "agentspine.learning-evaluation/v4")
398
+ || (receipt.schema === "agentspine.learning-outcome/v8" && contract.schema !== "agentspine.learning-evaluation/v5")
399
+ || (receipt.schema === "agentspine.learning-outcome/v9" && !ROOT_BOUND_EVALUATIONS.has(contract.schema))
400
+ || receipt.coverage?.datasetDigest !== contract.benchmark.datasetDigest
401
+ || receipt.coverage?.caseCount < contract.benchmark.minCases) findings.push(`invalid-coverage:${receipt.id}`);
402
+ }
403
+ if (receipt.schema === "agentspine.learning-outcome/v6" && !DIGEST_RE.test(receipt.measurement?.sourceDigest || "")) {
404
+ findings.push(`invalid-provenance:${receipt.id}`);
405
+ }
406
+ if (["agentspine.learning-outcome/v7", "agentspine.learning-outcome/v8", "agentspine.learning-outcome/v9"].includes(receipt.schema)) {
407
+ const source = (learning.measurements || []).find((item) => item.id === receipt.measurementReceiptId);
408
+ if (!source || source.digest !== receipt.measurementReceiptDigest) findings.push(`unbound-measurement:${receipt.id}`);
409
+ }
410
+ }
411
+ const pairedOutcomeKeys = new Set();
412
+ const pairedAfterApplications = new Set();
413
+ for (const receipt of learning.outcomes || []) {
414
+ if (!["agentspine.learning-outcome/v8", "agentspine.learning-outcome/v9"].includes(receipt.schema)) continue;
415
+ const evaluatorKey = receipt.schema === "agentspine.learning-outcome/v9"
416
+ ? receipt.measurement.evaluatorRootDigest : receipt.measurement.evaluatorId;
417
+ const key = `${receipt.evaluationId}\0${receipt.phase}\0${evaluatorKey}`;
418
+ if (pairedOutcomeKeys.has(key)) findings.push(`duplicate-paired-evaluator:${receipt.id}`);
419
+ pairedOutcomeKeys.add(key);
420
+ if (receipt.phase === "after") {
421
+ const applicationKey = `${receipt.evaluationId}\0${receipt.applicationId}`;
422
+ if (pairedAfterApplications.has(applicationKey)) findings.push(`duplicate-paired-turn:${receipt.id}`);
423
+ pairedAfterApplications.add(applicationKey);
424
+ }
425
+ }
426
+ for (const receipt of learning.outcomes || []) {
427
+ if (!["agentspine.learning-outcome/v8", "agentspine.learning-outcome/v9"].includes(receipt.schema) || receipt.phase !== "after") continue;
428
+ const pairedBefore = learning.outcomes.some((before) => before.schema === receipt.schema
429
+ && before.phase === "before" && before.learningId === receipt.learningId
430
+ && before.evaluationId === receipt.evaluationId
431
+ && before.measurement.evaluatorId === receipt.measurement.evaluatorId
432
+ && (receipt.schema !== "agentspine.learning-outcome/v9"
433
+ || before.measurement.evaluatorRootDigest === receipt.measurement.evaluatorRootDigest)
434
+ && before.measurement.kind === receipt.measurement.kind
435
+ && before.coverage.caseCount === receipt.coverage.caseCount
436
+ && exactScope(before.scope, receipt.scope));
437
+ if (!pairedBefore) findings.push(`unpaired-evaluator-outcome:${receipt.id}`);
438
+ }
439
+ const provenanceKeys = new Set();
440
+ for (const receipt of learning.outcomes || []) {
441
+ if (receipt.schema !== "agentspine.learning-outcome/v6") continue;
442
+ const key = `${receipt.evaluationId}\0${receipt.measurement.sourceDigest}`;
443
+ if (provenanceKeys.has(key)) findings.push(`replayed-provenance:${receipt.id}`);
444
+ provenanceKeys.add(key);
445
+ }
446
+ for (const entry of learning.history) {
447
+ const value = entry.value || {};
448
+ const nested = [...(value.evidence || []), value.review, value.rollback, value.promotion].filter(Boolean);
449
+ if (entry.authority !== "context-only" || value.authority !== "context-only" || nested.some((item) => item.authority !== "context-only")) {
450
+ findings.push(`history-authority:${entry.recordId || "unknown"}`);
451
+ }
452
+ if (SECRET_RE.test(value.claim || "") || AUTHORITY_ASSERTION_RE.test(value.claim || "")
453
+ || value.evidence?.some((item) => SECRET_RE.test(item.summary || ""))) {
454
+ findings.push(`unsafe-history:${entry.recordId || "unknown"}`);
455
+ }
456
+ }
457
+ return findings;
458
+ }