blun-king-cli 9.1.643 → 9.1.644

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (266) hide show
  1. package/LIESMICH.txt +18 -0
  2. package/README.md +20 -6
  3. package/bin/blun.js +3 -3
  4. package/bin/king.js +3 -3
  5. package/bin/launcher-mode.js +125 -126
  6. package/bin/launcher-runtime.js +603 -616
  7. package/bin/plugin-bootstrap.js +339 -405
  8. package/bin/rename-private-staging.cjs +2 -2
  9. package/bin/retired-bundled-plugins.cjs +84 -0
  10. package/bin/startup-security-host.cjs +105 -0
  11. package/bin/startup-security.cjs +9 -105
  12. package/bin/startup-warning-policy.cjs +22 -0
  13. package/bin/update-lease-installer.cjs +125 -0
  14. package/bin/update-lease-sockets.cjs +228 -0
  15. package/bin/update-lease.js +22 -327
  16. package/bin/verify-bundled-agent-sources.cjs +2 -4
  17. package/blun.mjs +18 -179
  18. package/bundled-agent-sources.json +1 -552
  19. package/package.json +1 -5
  20. package/tool-liveness642/receipt.json +1 -1
  21. package/worker-host.mjs +3 -119
  22. package/agent-spine-plugin/.claude-plugin/marketplace.json +0 -20
  23. package/agent-spine-plugin/.claude-plugin/plugin.json +0 -14
  24. package/agent-spine-plugin/.codex-plugin/plugin.json +0 -47
  25. package/agent-spine-plugin/.mcp.json +0 -8
  26. package/agent-spine-plugin/CHANGELOG.md +0 -1614
  27. package/agent-spine-plugin/LICENSE +0 -186
  28. package/agent-spine-plugin/README.md +0 -432
  29. package/agent-spine-plugin/assets/agentspine-banner.svg +0 -32
  30. package/agent-spine-plugin/bin/agentspine-mcp.js +0 -4
  31. package/agent-spine-plugin/bin/agentspine.js +0 -7
  32. package/agent-spine-plugin/blun.plugin.json +0 -68
  33. package/agent-spine-plugin/docs/acceptance.md +0 -61
  34. package/agent-spine-plugin/docs/artifact-evaluation.md +0 -93
  35. package/agent-spine-plugin/docs/host-integration.md +0 -193
  36. package/agent-spine-plugin/docs/preflight-recall.md +0 -71
  37. package/agent-spine-plugin/docs/preservation-contract.md +0 -53
  38. package/agent-spine-plugin/docs/quality-gates.md +0 -50
  39. package/agent-spine-plugin/docs/session-timeline.md +0 -112
  40. package/agent-spine-plugin/docs/source-roots.md +0 -113
  41. package/agent-spine-plugin/docs/world-model.md +0 -119
  42. package/agent-spine-plugin/hooks/codex.json +0 -47
  43. package/agent-spine-plugin/hooks/hooks.json +0 -106
  44. package/agent-spine-plugin/hooks/version.json +0 -5
  45. package/agent-spine-plugin/package.json +0 -77
  46. package/agent-spine-plugin/scripts/check-codex-install.js +0 -226
  47. package/agent-spine-plugin/scripts/check-hosts.js +0 -208
  48. package/agent-spine-plugin/scripts/check-install-hook.js +0 -227
  49. package/agent-spine-plugin/scripts/check-install-selfstarter.js +0 -154
  50. package/agent-spine-plugin/scripts/check-install.js +0 -478
  51. package/agent-spine-plugin/scripts/check-line-budget.js +0 -58
  52. package/agent-spine-plugin/scripts/check-syntax.js +0 -29
  53. package/agent-spine-plugin/scripts/github-actions.js +0 -11
  54. package/agent-spine-plugin/scripts/hermetic-process.js +0 -191
  55. package/agent-spine-plugin/scripts/release-check.js +0 -150
  56. package/agent-spine-plugin/scripts/run-acceptance.js +0 -19
  57. package/agent-spine-plugin/scripts/run-checks.js +0 -50
  58. package/agent-spine-plugin/scripts/run-tests-hermetic.js +0 -112
  59. package/agent-spine-plugin/skills/agent-spine/SKILL.md +0 -99
  60. package/agent-spine-plugin/spine-example/1-identity.md +0 -12
  61. package/agent-spine-plugin/spine-example/2-voice.md +0 -6
  62. package/agent-spine-plugin/spine-example/3-conduct.md +0 -8
  63. package/agent-spine-plugin/spine-example/4-history.md +0 -4
  64. package/agent-spine-plugin/src/cli-agent.js +0 -315
  65. package/agent-spine-plugin/src/cli-attention.js +0 -95
  66. package/agent-spine-plugin/src/cli-autonomy.js +0 -36
  67. package/agent-spine-plugin/src/cli-common.js +0 -71
  68. package/agent-spine-plugin/src/cli-continuity.js +0 -116
  69. package/agent-spine-plugin/src/cli-core.js +0 -128
  70. package/agent-spine-plugin/src/cli-diagnostics.js +0 -291
  71. package/agent-spine-plugin/src/cli-host.js +0 -21
  72. package/agent-spine-plugin/src/cli-learning.js +0 -320
  73. package/agent-spine-plugin/src/cli-premortem.js +0 -16
  74. package/agent-spine-plugin/src/cli-sharing.js +0 -230
  75. package/agent-spine-plugin/src/cli.js +0 -181
  76. package/agent-spine-plugin/src/codex-reader-launcher.js +0 -182
  77. package/agent-spine-plugin/src/hook.js +0 -500
  78. package/agent-spine-plugin/src/index.js +0 -108
  79. package/agent-spine-plugin/src/lib/acceptance.js +0 -435
  80. package/agent-spine-plugin/src/lib/action-lesson-recall.js +0 -118
  81. package/agent-spine-plugin/src/lib/attention-context.js +0 -167
  82. package/agent-spine-plugin/src/lib/attention-events.js +0 -113
  83. package/agent-spine-plugin/src/lib/attention-privacy.js +0 -72
  84. package/agent-spine-plugin/src/lib/attention-schema.js +0 -164
  85. package/agent-spine-plugin/src/lib/attention-storage.js +0 -93
  86. package/agent-spine-plugin/src/lib/attention.js +0 -164
  87. package/agent-spine-plugin/src/lib/audit-premortem.js +0 -223
  88. package/agent-spine-plugin/src/lib/audit.js +0 -401
  89. package/agent-spine-plugin/src/lib/authentication.js +0 -515
  90. package/agent-spine-plugin/src/lib/autonomy-policy.js +0 -110
  91. package/agent-spine-plugin/src/lib/autonomy-store.js +0 -202
  92. package/agent-spine-plugin/src/lib/autonomy.js +0 -8
  93. package/agent-spine-plugin/src/lib/briefing.js +0 -493
  94. package/agent-spine-plugin/src/lib/catalog-document-read.js +0 -51
  95. package/agent-spine-plugin/src/lib/catalog.js +0 -167
  96. package/agent-spine-plugin/src/lib/channel-continuity.js +0 -19
  97. package/agent-spine-plugin/src/lib/channel-runtime.js +0 -665
  98. package/agent-spine-plugin/src/lib/codex-installation.js +0 -231
  99. package/agent-spine-plugin/src/lib/codex-skill-installation.js +0 -211
  100. package/agent-spine-plugin/src/lib/context.js +0 -156
  101. package/agent-spine-plugin/src/lib/continuity.js +0 -338
  102. package/agent-spine-plugin/src/lib/coordination.js +0 -577
  103. package/agent-spine-plugin/src/lib/delivery-agent-usage.js +0 -231
  104. package/agent-spine-plugin/src/lib/delivery-assignment.js +0 -220
  105. package/agent-spine-plugin/src/lib/delivery-command-actions.js +0 -462
  106. package/agent-spine-plugin/src/lib/delivery-knowledge.js +0 -78
  107. package/agent-spine-plugin/src/lib/delivery-premortem-binding.js +0 -107
  108. package/agent-spine-plugin/src/lib/delivery-premortem-closure.js +0 -171
  109. package/agent-spine-plugin/src/lib/delivery-premortem-codec.js +0 -45
  110. package/agent-spine-plugin/src/lib/delivery-premortem-correction.js +0 -101
  111. package/agent-spine-plugin/src/lib/delivery-premortem-file.js +0 -21
  112. package/agent-spine-plugin/src/lib/delivery-premortem-index.js +0 -493
  113. package/agent-spine-plugin/src/lib/delivery-premortem-inspection.js +0 -37
  114. package/agent-spine-plugin/src/lib/delivery-premortem-recovery.js +0 -120
  115. package/agent-spine-plugin/src/lib/delivery-premortem-rejection.js +0 -65
  116. package/agent-spine-plugin/src/lib/delivery-premortem-results.js +0 -28
  117. package/agent-spine-plugin/src/lib/delivery-premortem-session-guard.js +0 -46
  118. package/agent-spine-plugin/src/lib/delivery-premortem-write-ledger.js +0 -285
  119. package/agent-spine-plugin/src/lib/delivery-premortem.js +0 -499
  120. package/agent-spine-plugin/src/lib/delivery-shell-heredoc.js +0 -115
  121. package/agent-spine-plugin/src/lib/delivery-shell-substitutions.js +0 -111
  122. package/agent-spine-plugin/src/lib/delivery-shell-wrapper.js +0 -64
  123. package/agent-spine-plugin/src/lib/delivery-target.js +0 -73
  124. package/agent-spine-plugin/src/lib/delivery-verification.js +0 -445
  125. package/agent-spine-plugin/src/lib/documents.js +0 -239
  126. package/agent-spine-plugin/src/lib/feed-transport.js +0 -499
  127. package/agent-spine-plugin/src/lib/filesystem-retry.js +0 -34
  128. package/agent-spine-plugin/src/lib/gateway-common.js +0 -68
  129. package/agent-spine-plugin/src/lib/gateway-control.js +0 -370
  130. package/agent-spine-plugin/src/lib/gateway-delivery.js +0 -103
  131. package/agent-spine-plugin/src/lib/gateway-execution.js +0 -350
  132. package/agent-spine-plugin/src/lib/gateway-group-response.js +0 -128
  133. package/agent-spine-plugin/src/lib/gateway-host-fencing.js +0 -92
  134. package/agent-spine-plugin/src/lib/gateway-host-lifecycle.js +0 -193
  135. package/agent-spine-plugin/src/lib/gateway-inspection.js +0 -85
  136. package/agent-spine-plugin/src/lib/gateway-knowledge.js +0 -129
  137. package/agent-spine-plugin/src/lib/gateway-policy-provenance.js +0 -197
  138. package/agent-spine-plugin/src/lib/gateway-premortem-disposition.js +0 -82
  139. package/agent-spine-plugin/src/lib/gateway-premortem.js +0 -363
  140. package/agent-spine-plugin/src/lib/gateway-prepared-host.js +0 -28
  141. package/agent-spine-plugin/src/lib/gateway-runs.js +0 -345
  142. package/agent-spine-plugin/src/lib/gateway-runtime-identity.js +0 -31
  143. package/agent-spine-plugin/src/lib/gateway-runtime-records.js +0 -21
  144. package/agent-spine-plugin/src/lib/gateway-runtime.js +0 -18
  145. package/agent-spine-plugin/src/lib/gateway-state-transaction.js +0 -356
  146. package/agent-spine-plugin/src/lib/gateway-state.js +0 -344
  147. package/agent-spine-plugin/src/lib/graph.js +0 -337
  148. package/agent-spine-plugin/src/lib/hook-artifact-guards.js +0 -356
  149. package/agent-spine-plugin/src/lib/hook-audit.js +0 -43
  150. package/agent-spine-plugin/src/lib/hook-briefing-use.js +0 -78
  151. package/agent-spine-plugin/src/lib/hook-context.js +0 -441
  152. package/agent-spine-plugin/src/lib/hook-final-message.js +0 -26
  153. package/agent-spine-plugin/src/lib/hook-input.js +0 -27
  154. package/agent-spine-plugin/src/lib/hook-output.js +0 -284
  155. package/agent-spine-plugin/src/lib/hook-premortem.js +0 -257
  156. package/agent-spine-plugin/src/lib/hook-process-advisory.js +0 -36
  157. package/agent-spine-plugin/src/lib/hook-protection.js +0 -95
  158. package/agent-spine-plugin/src/lib/hook-stop-verification.js +0 -84
  159. package/agent-spine-plugin/src/lib/hook-timeline.js +0 -102
  160. package/agent-spine-plugin/src/lib/host-instruction-budget.js +0 -11
  161. package/agent-spine-plugin/src/lib/https-transport.js +0 -392
  162. package/agent-spine-plugin/src/lib/identifier-analysis.js +0 -446
  163. package/agent-spine-plugin/src/lib/indexed-memory-offline.js +0 -40
  164. package/agent-spine-plugin/src/lib/indexed-memory.js +0 -298
  165. package/agent-spine-plugin/src/lib/knowledge-evidence.js +0 -431
  166. package/agent-spine-plugin/src/lib/learning-applications.js +0 -441
  167. package/agent-spine-plugin/src/lib/learning-artifact-evaluator.js +0 -114
  168. package/agent-spine-plugin/src/lib/learning-candidates.js +0 -274
  169. package/agent-spine-plugin/src/lib/learning-context.js +0 -137
  170. package/agent-spine-plugin/src/lib/learning-delivery-contracts.js +0 -310
  171. package/agent-spine-plugin/src/lib/learning-evaluation-contracts.js +0 -350
  172. package/agent-spine-plugin/src/lib/learning-evaluation-registration.js +0 -372
  173. package/agent-spine-plugin/src/lib/learning-evaluation-revocation.js +0 -292
  174. package/agent-spine-plugin/src/lib/learning-evidence-contracts.js +0 -321
  175. package/agent-spine-plugin/src/lib/learning-findings.js +0 -458
  176. package/agent-spine-plugin/src/lib/learning-measurement-contracts.js +0 -285
  177. package/agent-spine-plugin/src/lib/learning-measurements.js +0 -265
  178. package/agent-spine-plugin/src/lib/learning-outcome-contracts.js +0 -165
  179. package/agent-spine-plugin/src/lib/learning-outcomes.js +0 -343
  180. package/agent-spine-plugin/src/lib/learning-reconciliation.js +0 -290
  181. package/agent-spine-plugin/src/lib/learning-retry-contracts.js +0 -188
  182. package/agent-spine-plugin/src/lib/learning-schema.js +0 -229
  183. package/agent-spine-plugin/src/lib/learning-scope-targets.js +0 -424
  184. package/agent-spine-plugin/src/lib/learning-state-upgrade.js +0 -477
  185. package/agent-spine-plugin/src/lib/learning-status-configuration.js +0 -476
  186. package/agent-spine-plugin/src/lib/learning-storage.js +0 -203
  187. package/agent-spine-plugin/src/lib/learning-trial-recovery.js +0 -218
  188. package/agent-spine-plugin/src/lib/learning-validation-contracts.js +0 -375
  189. package/agent-spine-plugin/src/lib/learning-validation-renewal.js +0 -298
  190. package/agent-spine-plugin/src/lib/learning-validation-runtime.js +0 -234
  191. package/agent-spine-plugin/src/lib/learning.js +0 -36
  192. package/agent-spine-plugin/src/lib/lesson-recall-session.js +0 -172
  193. package/agent-spine-plugin/src/lib/mcp-autonomy-tools.js +0 -37
  194. package/agent-spine-plugin/src/lib/mcp-delivery-completion.js +0 -124
  195. package/agent-spine-plugin/src/lib/mcp-delivery-tools.js +0 -45
  196. package/agent-spine-plugin/src/lib/mcp-premortem.js +0 -68
  197. package/agent-spine-plugin/src/lib/mcp-runtime.js +0 -355
  198. package/agent-spine-plugin/src/lib/mcp-source-context.js +0 -61
  199. package/agent-spine-plugin/src/lib/mcp-timeline-tools.js +0 -240
  200. package/agent-spine-plugin/src/lib/mcp-world-tools.js +0 -52
  201. package/agent-spine-plugin/src/lib/object-transport.js +0 -206
  202. package/agent-spine-plugin/src/lib/owned-file-lock.js +0 -182
  203. package/agent-spine-plugin/src/lib/paths.js +0 -109
  204. package/agent-spine-plugin/src/lib/peer-transport.js +0 -283
  205. package/agent-spine-plugin/src/lib/persona-runtime.js +0 -581
  206. package/agent-spine-plugin/src/lib/pre-answer-timeline-recall.js +0 -104
  207. package/agent-spine-plugin/src/lib/preflight-delivery-id.js +0 -27
  208. package/agent-spine-plugin/src/lib/preflight.js +0 -688
  209. package/agent-spine-plugin/src/lib/project-portfolio.js +0 -176
  210. package/agent-spine-plugin/src/lib/runtime.js +0 -13
  211. package/agent-spine-plugin/src/lib/selfstarter-core.js +0 -382
  212. package/agent-spine-plugin/src/lib/selfstarter-jobs.js +0 -149
  213. package/agent-spine-plugin/src/lib/selfstarter-lease.js +0 -204
  214. package/agent-spine-plugin/src/lib/selfstarter-policy.js +0 -90
  215. package/agent-spine-plugin/src/lib/selfstarter-workspace.js +0 -111
  216. package/agent-spine-plugin/src/lib/selfstarter.js +0 -11
  217. package/agent-spine-plugin/src/lib/session-timeline-auth.js +0 -316
  218. package/agent-spine-plugin/src/lib/session-timeline-codex.js +0 -69
  219. package/agent-spine-plugin/src/lib/session-timeline-contract.js +0 -56
  220. package/agent-spine-plugin/src/lib/session-timeline-enrollment-source.js +0 -38
  221. package/agent-spine-plugin/src/lib/session-timeline-enrollment-storage.js +0 -128
  222. package/agent-spine-plugin/src/lib/session-timeline-enrollment-transport.js +0 -15
  223. package/agent-spine-plugin/src/lib/session-timeline-enrollment.js +0 -478
  224. package/agent-spine-plugin/src/lib/session-timeline-event-extract.js +0 -186
  225. package/agent-spine-plugin/src/lib/session-timeline-host-origin.js +0 -73
  226. package/agent-spine-plugin/src/lib/session-timeline-host-receipt.js +0 -117
  227. package/agent-spine-plugin/src/lib/session-timeline-invocation.js +0 -201
  228. package/agent-spine-plugin/src/lib/session-timeline-king.js +0 -93
  229. package/agent-spine-plugin/src/lib/session-timeline-prior.js +0 -57
  230. package/agent-spine-plugin/src/lib/session-timeline-provider.js +0 -36
  231. package/agent-spine-plugin/src/lib/session-timeline-query.js +0 -56
  232. package/agent-spine-plugin/src/lib/session-timeline-results.js +0 -56
  233. package/agent-spine-plugin/src/lib/session-timeline-root.js +0 -11
  234. package/agent-spine-plugin/src/lib/session-timeline-search.js +0 -82
  235. package/agent-spine-plugin/src/lib/session-timeline-sid-acl.js +0 -213
  236. package/agent-spine-plugin/src/lib/session-timeline-source-open.js +0 -30
  237. package/agent-spine-plugin/src/lib/session-timeline-source.js +0 -80
  238. package/agent-spine-plugin/src/lib/session-timeline-state.js +0 -45
  239. package/agent-spine-plugin/src/lib/session-timeline-transport.js +0 -42
  240. package/agent-spine-plugin/src/lib/session-timeline-windows-acl.js +0 -145
  241. package/agent-spine-plugin/src/lib/session-timeline.js +0 -462
  242. package/agent-spine-plugin/src/lib/sharing.js +0 -969
  243. package/agent-spine-plugin/src/lib/source-roots.js +0 -475
  244. package/agent-spine-plugin/src/lib/source-tree-scan.js +0 -178
  245. package/agent-spine-plugin/src/lib/sqlite-transport.js +0 -501
  246. package/agent-spine-plugin/src/lib/task-knowledge-context.js +0 -99
  247. package/agent-spine-plugin/src/lib/telegram-adapter.js +0 -119
  248. package/agent-spine-plugin/src/lib/timeline-continuation-update.js +0 -100
  249. package/agent-spine-plugin/src/lib/timeline-tool-guard.js +0 -225
  250. package/agent-spine-plugin/src/lib/timeline-user-feedback.js +0 -216
  251. package/agent-spine-plugin/src/lib/timeline-world-capture.js +0 -233
  252. package/agent-spine-plugin/src/lib/voice-runtime.js +0 -39
  253. package/agent-spine-plugin/src/lib/world-knowledge.js +0 -306
  254. package/agent-spine-plugin/src/lib/world-model.js +0 -333
  255. package/agent-spine-plugin/src/mcp.js +0 -456
  256. package/agent-spine-plugin/src/version.js +0 -1
  257. package/agent-spine-plugin/src/worker.js +0 -257
  258. package/bin/agentspine-king-goal-inbox.mjs +0 -127
  259. package/bin/agentspine-king-goal-intake.mjs +0 -106
  260. package/bin/agentspine-king-host-runner.mjs +0 -109
  261. package/bin/agentspine-king-snapshot-policy.cjs +0 -80
  262. package/bin/agentspine-king-status-policy.mjs +0 -226
  263. package/bin/agentspine-king-worker-host.mjs +0 -160
  264. package/bin/managed-plugin-selection.cjs +0 -141
  265. package/bin/verify-agent-behavior.cjs +0 -122
  266. package/bin/verify-agent-components.cjs +0 -104
@@ -1,274 +0,0 @@
1
- import { createHash, randomUUID } from "node:crypto";
2
- import { loadGraph } from "./graph.js";
3
- import {
4
- KINDS, ID_RE, DIGEST_RE, PROTECTED_LESSON_RE, TARGET_BOUND_EVALUATIONS, EVIDENCE_REVOCATION_REASONS
5
- } from "./learning-schema.js";
6
- import {
7
- normalizeScope, exactScope, digest, learningTargetForCandidate, evidenceRevocationPayload, revokedEvidence,
8
- revokedMeasurementForCandidate, evaluatorRecordPayload
9
- } from "./learning-scope-targets.js";
10
- import {
11
- revokedOutcomeForCandidate
12
- } from "./learning-delivery-contracts.js";
13
- import {
14
- date, safeText, assertSafeClaim, validateScope, mutation, preserve,
15
- normalizeEvidence, evidenceConfidence
16
- } from "./learning-storage.js";
17
-
18
- export async function proposeLearning({
19
- root = process.cwd(), id = `learning:${randomUUID()}`, kind, claim, subjectId = null,
20
- privacy = "private", groupId = null, scope = null, evidence, supersedesId = null, now = new Date(),
21
- catalog: providedCatalog = null
22
- }) {
23
- if (!ID_RE.test(id)) throw new Error("id must be a stable, whitespace-free identifier");
24
- if (!KINDS.has(kind)) throw new Error(`unsupported learning kind: ${kind}`);
25
- claim = safeText(claim, "claim", 1000);
26
- assertSafeClaim(claim);
27
- const normalizedScope = normalizeScope(scope, subjectId, groupId);
28
- if (normalizedScope.groupId !== (groupId ?? null)) throw new Error("scope.groupId must match the privacy groupId");
29
- const timestamp = date(now, "now");
30
- return mutation(root, async (state, catalog, learningPath) => {
31
- if (state.candidates.some((candidate) => candidate.id === id)) {
32
- throw new Error("learning candidate IDs are immutable; add evidence or propose a superseding candidate");
33
- }
34
- const { graph } = await loadGraph(catalog.root, catalog);
35
- validateScope(privacy, groupId, graph, subjectId);
36
- const duplicate = state.candidates.find((candidate) => candidate.kind === kind
37
- && candidate.claim === claim && exactScope(candidate.scope, normalizedScope)
38
- && candidate.privacy === privacy && candidate.status !== "rejected" && candidate.status !== "rolled-back");
39
- if (duplicate) return { candidate: duplicate, learningPath, unchanged: true };
40
- const normalizedEvidence = normalizeEvidence(evidence, catalog, timestamp);
41
- const superseded = supersedesId ? state.candidates.find((candidate) => candidate.id === supersedesId) : null;
42
- if (supersedesId && (!superseded || superseded.status !== "accepted")) {
43
- throw new Error(`supersedesId must reference an accepted learning: ${supersedesId}`);
44
- }
45
- if (superseded && (superseded.kind !== kind || superseded.subjectId !== subjectId || superseded.privacy !== privacy
46
- || superseded.groupId !== groupId || !exactScope(superseded.scope, normalizedScope))) {
47
- throw new Error("a superseding candidate must keep kind, subject, and privacy scope");
48
- }
49
- const conflictsWith = state.candidates.filter((candidate) => candidate.kind === kind
50
- && candidate.claim !== claim && exactScope(candidate.scope, normalizedScope)
51
- && ["candidate", "accepted"].includes(candidate.status) && candidate.id !== supersedesId)
52
- .map((candidate) => candidate.id).sort();
53
- if (conflictsWith.length) {
54
- state.candidates = state.candidates.map((candidate) => conflictsWith.includes(candidate.id)
55
- ? { ...candidate, conflictsWith: [...new Set([...(candidate.conflictsWith || []), id])].sort(), updatedAt: timestamp }
56
- : candidate);
57
- }
58
- const candidate = {
59
- id,
60
- kind,
61
- claim,
62
- subjectId,
63
- privacy,
64
- groupId,
65
- scope: normalizedScope,
66
- status: "candidate",
67
- evidence: [normalizedEvidence],
68
- confidence: normalizedEvidence.confidence,
69
- supersedesId,
70
- supersededIds: [],
71
- conflictsWith,
72
- requiresLocalReview: PROTECTED_LESSON_RE.test(claim),
73
- automatic: false,
74
- createdAt: timestamp,
75
- updatedAt: timestamp,
76
- acceptedAt: null,
77
- authority: "context-only"
78
- };
79
- state.candidates.push(candidate);
80
- state.candidates.sort((a, b) => a.id.localeCompare(b.id));
81
- return { candidate, learningPath };
82
- }, providedCatalog);
83
- }
84
-
85
- export async function addLearningEvidence({
86
- root = process.cwd(), id, evidence, now = new Date(), catalog: providedCatalog = null
87
- }) {
88
- if (!ID_RE.test(id || "")) throw new Error("id is required");
89
- const timestamp = date(now, "now");
90
- return mutation(root, (state, catalog, learningPath) => {
91
- const previous = state.candidates.find((candidate) => candidate.id === id);
92
- if (!previous) throw new Error(`unknown learning candidate: ${id}`);
93
- if (previous.status !== "candidate") throw new Error("evidence can only be added to an unreviewed candidate");
94
- if (revokedEvidence(state, previous)) {
95
- throw new Error("revoked evidence freezes this learning target; propose a superseding candidate instead");
96
- }
97
- if (state.measurementRevocations.some((receipt) => receipt.learningId === id)) {
98
- throw new Error("revoked measurement evidence freezes this learning target; propose a superseding candidate instead");
99
- }
100
- if (state.outcomeRevocations.some((receipt) => receipt.learningId === id)) {
101
- throw new Error("revoked outcome evidence freezes this learning target; propose a superseding candidate instead");
102
- }
103
- if (state.evaluations.some((contract) => contract.learningId === id
104
- && TARGET_BOUND_EVALUATIONS.has(contract.schema))) {
105
- throw new Error("evaluated learning target is immutable; propose a superseding candidate and evaluation contract");
106
- }
107
- const item = normalizeEvidence(evidence, catalog, timestamp);
108
- if (previous.evidence.some((entry) => entry.id === item.id)) throw new Error(`duplicate evidence id: ${item.id}`);
109
- preserve(state, "learning-candidate", previous, timestamp);
110
- const candidate = {
111
- ...previous,
112
- evidence: [...previous.evidence, item],
113
- confidence: evidenceConfidence([...previous.evidence, item]),
114
- updatedAt: timestamp,
115
- authority: "context-only"
116
- };
117
- state.candidates = state.candidates.map((entry) => entry.id === id ? candidate : entry);
118
- return { candidate, learningPath };
119
- }, providedCatalog);
120
- }
121
-
122
- export async function revokeLearningEvidence({
123
- root = process.cwd(), learningId, evidenceId, reasonCode, reason,
124
- confirmation, now = new Date()
125
- }) {
126
- if (confirmation !== "local-evidence-revocation-confirmed") {
127
- throw new Error("evidence revocation requires explicit local confirmation");
128
- }
129
- if (!ID_RE.test(learningId || "") || !ID_RE.test(evidenceId || "")) {
130
- throw new Error("learningId and evidenceId must be stable identifiers");
131
- }
132
- if (!EVIDENCE_REVOCATION_REASONS.has(reasonCode)) {
133
- throw new Error("reasonCode must be retracted, source-invalid, measurement-invalid, duplicate, or other");
134
- }
135
- const revokeReason = safeText(reason, "reason", 500);
136
- const timestamp = date(now, "now");
137
- return mutation(root, (state, _catalog, learningPath) => {
138
- const candidate = state.candidates.find((entry) => entry.id === learningId);
139
- if (!candidate) throw new Error(`unknown learning candidate: ${learningId}`);
140
- const evidence = candidate.evidence.find((entry) => entry.id === evidenceId);
141
- if (!evidence) throw new Error(`unknown learning evidence: ${evidenceId}`);
142
- const targetDigest = learningTargetForCandidate(candidate).digest;
143
- const id = `evidence-revocation:${createHash("sha256")
144
- .update(`${learningId}\0${evidenceId}\0${targetDigest}`).digest("hex").slice(0, 32)}`;
145
- const existing = state.evidenceRevocations.find((entry) => entry.learningId === learningId
146
- && entry.evidenceId === evidenceId);
147
- const reasonDigest = digest(revokeReason);
148
- if (existing) {
149
- if (existing.reasonCode !== reasonCode || existing.reasonDigest !== reasonDigest
150
- || existing.evidenceDigest !== digest(evidence) || existing.targetDigest !== targetDigest) {
151
- throw new Error("learning evidence revocations are immutable");
152
- }
153
- return { receipt: existing, learningPath, unchanged: true, authority: "context-only" };
154
- }
155
- const payload = evidenceRevocationPayload({
156
- id, learningId, evidenceId, evidenceDigest: digest(evidence), targetDigest, reasonCode,
157
- reasonDigest, revokedAt: timestamp
158
- });
159
- const receipt = { ...payload, digest: digest(payload) };
160
- state.evidenceRevocations.push(receipt);
161
- state.evidenceRevocations.sort((a, b) => a.id.localeCompare(b.id));
162
- return { receipt, learningPath, unchanged: false, authority: "context-only" };
163
- });
164
- }
165
-
166
- export function acceptCandidate(state, candidate, timestamp, automatic, promotion = null) {
167
- preserve(state, "learning-candidate", candidate, timestamp);
168
- const superseded = candidate.supersedesId
169
- ? state.candidates.find((entry) => entry.id === candidate.supersedesId && entry.status === "accepted")
170
- : null;
171
- if (candidate.supersedesId && !superseded) throw new Error("the learning being superseded is no longer active");
172
- if (superseded) {
173
- preserve(state, "learning-candidate", superseded, timestamp);
174
- state.candidates = state.candidates.map((entry) => entry.id === superseded.id
175
- ? { ...entry, status: "superseded", updatedAt: timestamp, authority: "context-only" }
176
- : entry);
177
- }
178
- const accepted = {
179
- ...candidate,
180
- status: "accepted",
181
- supersededIds: superseded ? [superseded.id] : [],
182
- automatic,
183
- promotion,
184
- acceptedAt: timestamp,
185
- updatedAt: timestamp,
186
- authority: "context-only"
187
- };
188
- state.candidates = state.candidates.map((entry) => entry.id === candidate.id ? accepted : entry);
189
- return accepted;
190
- }
191
-
192
- export async function reviewLearning({
193
- root = process.cwd(), id, decision, reason, confirmedByUser = false, now = new Date()
194
- }) {
195
- if (!ID_RE.test(id || "")) throw new Error("id is required");
196
- if (!new Set(["accept", "reject"]).has(decision)) throw new Error("decision must be accept or reject");
197
- const reviewReason = safeText(reason, "reason", 500);
198
- const timestamp = date(now, "now");
199
- return mutation(root, (state, _catalog, learningPath) => {
200
- const candidate = state.candidates.find((entry) => entry.id === id);
201
- if (!candidate) throw new Error(`unknown learning candidate: ${id}`);
202
- if (candidate.status !== "candidate") throw new Error("only an unreviewed candidate can be reviewed");
203
- if (decision === "accept") {
204
- if (!confirmedByUser) throw new Error("acceptance requires explicit user confirmation");
205
- if (revokedEvidence(state, candidate)) throw new Error("learning evidence was revoked; propose a new candidate before acceptance");
206
- if (revokedMeasurementForCandidate(state, candidate)) {
207
- throw new Error("learning measurement was revoked; propose a new candidate before acceptance");
208
- }
209
- if (revokedOutcomeForCandidate(state, candidate)) {
210
- throw new Error("learning outcome was revoked; propose a new candidate before acceptance");
211
- }
212
- const accepted = acceptCandidate(state, candidate, timestamp, false, null);
213
- accepted.review = { decision, reason: reviewReason, confirmedByUser: true, reviewedAt: timestamp, authority: "context-only" };
214
- return { candidate: accepted, learningPath };
215
- }
216
- preserve(state, "learning-candidate", candidate, timestamp);
217
- const rejected = {
218
- ...candidate,
219
- status: "rejected",
220
- updatedAt: timestamp,
221
- review: { decision, reason: reviewReason, confirmedByUser: false, reviewedAt: timestamp, authority: "context-only" },
222
- authority: "context-only"
223
- };
224
- state.candidates = state.candidates.map((entry) => entry.id === id ? rejected : entry);
225
- return { candidate: rejected, learningPath };
226
- });
227
- }
228
-
229
- export function distinctEvidence(candidate) {
230
- return new Set(candidate.evidence.map((item) => item.sourceSha256 || item.sourceDocument || item.id)).size;
231
- }
232
-
233
- export async function registerLearningEvaluator({
234
- root = process.cwd(), id, principalDigest, confirmLocalEvaluator = false, now = new Date()
235
- }) {
236
- if (!confirmLocalEvaluator) throw new Error("evaluator registration requires explicit local confirmation");
237
- if (!ID_RE.test(id || "")) throw new Error("evaluator id must be a stable identifier");
238
- if (!DIGEST_RE.test(principalDigest || "")) throw new Error("evaluator principalDigest must be SHA-256");
239
- const timestamp = date(now, "now");
240
- return mutation(root, (state, _catalog, learningPath) => {
241
- const existing = state.evaluatorRegistry.find((record) => record.id === id || record.principalDigest === principalDigest);
242
- if (existing) {
243
- if (existing.id === id && existing.principalDigest === principalDigest && existing.status === "active") {
244
- return { evaluator: existing, learningPath, unchanged: true };
245
- }
246
- throw new Error("evaluator IDs and principal roots are immutable; register a new distinct evaluator instead");
247
- }
248
- const payload = evaluatorRecordPayload({ id, principalDigest, status: "active", registeredAt: timestamp,
249
- revokedAt: null, reason: null });
250
- const evaluator = { ...payload, digest: digest(payload) };
251
- state.evaluatorRegistry.push(evaluator);
252
- state.evaluatorRegistry.sort((a, b) => a.id.localeCompare(b.id));
253
- return { evaluator, learningPath, unchanged: false };
254
- });
255
- }
256
-
257
- export async function revokeLearningEvaluator({
258
- root = process.cwd(), id, reason, confirmLocalEvaluator = false, now = new Date()
259
- }) {
260
- if (!confirmLocalEvaluator) throw new Error("evaluator revocation requires explicit local confirmation");
261
- if (!ID_RE.test(id || "")) throw new Error("evaluator id must be a stable identifier");
262
- const revokeReason = safeText(reason, "reason", 500);
263
- const timestamp = date(now, "now");
264
- return mutation(root, (state, _catalog, learningPath) => {
265
- const previous = state.evaluatorRegistry.find((record) => record.id === id);
266
- if (!previous) throw new Error(`unknown learning evaluator: ${id}`);
267
- if (previous.status !== "active") throw new Error("learning evaluator is already revoked");
268
- preserve(state, "learning-evaluator", previous, timestamp);
269
- const payload = evaluatorRecordPayload({ ...previous, status: "revoked", revokedAt: timestamp, reason: revokeReason });
270
- const evaluator = { ...payload, digest: digest(payload) };
271
- state.evaluatorRegistry = state.evaluatorRegistry.map((record) => record.id === id ? evaluator : record);
272
- return { evaluator, learningPath };
273
- });
274
- }
@@ -1,137 +0,0 @@
1
- import { buildCatalog } from "./catalog.js";
2
- import { loadGraph } from "./graph.js";
3
- import {
4
- KINDS
5
- } from "./learning-schema.js";
6
- import {
7
- validConfig, normalizeScope, scopeContains, exactScope
8
- } from "./learning-scope-targets.js";
9
- import {
10
- canaryValidity
11
- } from "./learning-validation-runtime.js";
12
- import {
13
- date, integer, loadLearning
14
- } from "./learning-storage.js";
15
-
16
- export function groupEntities(graph, groupId, includePrivate) {
17
- const result = new Set();
18
- if (!groupId) return result;
19
- result.add(groupId);
20
- for (const edge of graph.entityEdges) {
21
- if (edge.relation !== "member-of" || (!includePrivate && edge.privacy === "private")) continue;
22
- if (edge.to === groupId) result.add(edge.from);
23
- if (edge.from === groupId) result.add(edge.to);
24
- }
25
- return result;
26
- }
27
-
28
- export function visible(candidate, entities, audience, includePrivate, groupId) {
29
- if (candidate.privacy === "private" && !includePrivate) return false;
30
- if (candidate.privacy === "group" && (!groupId || candidate.groupId !== groupId)) return false;
31
- if (candidate.privacy === "group" && candidate.subjectId && !audience.has(candidate.subjectId)) return false;
32
- const subject = candidate.subjectId ? entities.get(candidate.subjectId) : null;
33
- if (subject?.privacy === "private" && !includePrivate) return false;
34
- if (subject?.privacy === "group" && !audience.has(subject.id)) return false;
35
- return true;
36
- }
37
-
38
- export async function learningContext({
39
- root = process.cwd(), includePrivate = false, groupId = null, kinds = null,
40
- subjectIds = null, scope = null, maxItems = null, catalog: providedCatalog = null, now = new Date(),
41
- taskFocus = null
42
- } = {}) {
43
- const catalog = providedCatalog || await buildCatalog(root);
44
- const { learning } = await loadLearning(catalog.root, catalog);
45
- if (!validConfig(learning.config)) throw new Error("learning configuration is invalid; run the audit before using learned context");
46
- const { graph } = await loadGraph(catalog.root, catalog);
47
- const entities = new Map(graph.entities.map((entity) => [entity.id, entity]));
48
- if (groupId !== null) {
49
- const group = entities.get(groupId);
50
- if (!group || group.kind !== "group") throw new Error(`unknown group entity: ${groupId}`);
51
- }
52
- const audience = groupEntities(graph, groupId, includePrivate);
53
- const runtimeScope = normalizeScope(scope, null, groupId);
54
- const kindFilter = kinds === null ? null : new Set(kinds);
55
- if (kindFilter && [...kindFilter].some((kind) => !KINDS.has(kind))) throw new Error("kinds contains an unsupported learning kind");
56
- const subjectFilter = subjectIds === null ? null : new Set(subjectIds);
57
- const limit = maxItems === null ? learning.config.maxContextItems : integer(maxItems, "maxItems", 0, 50);
58
- const timestamp = date(now, "now");
59
- const applicable = learning.candidates
60
- .filter((candidate) => candidate.status === "accepted")
61
- .filter((candidate) => scope === null || scopeContains(candidate.scope, runtimeScope))
62
- .filter((candidate) => candidate.promotion?.mode !== "outcome-canary"
63
- || exactScope(candidate.promotion.canary.scope, runtimeScope))
64
- .filter((candidate) => !kindFilter || kindFilter.has(candidate.kind))
65
- .filter((candidate) => !subjectFilter || subjectFilter.has(candidate.subjectId))
66
- .filter((candidate) => candidate.privacy !== "group" || (groupId && candidate.groupId === groupId));
67
- const invalidCanaries = new Map(applicable.map((candidate) => [candidate.id,
68
- canaryValidity(learning, candidate, timestamp)]).filter(([, validity]) => ![
69
- "not-applicable", "current-active", "current-validated", "legacy-validated"
70
- ].includes(validity.status)));
71
- const revokedTrialFailureCandidates = learning.candidates
72
- .filter((candidate) => candidate.status === "rolled-back"
73
- && learning.trialFailureRevocations.some((receipt) => receipt.learningId === candidate.id))
74
- .filter((candidate) => scope === null || scopeContains(candidate.scope, runtimeScope))
75
- .filter((candidate) => !kindFilter || kindFilter.has(candidate.kind))
76
- .filter((candidate) => !subjectFilter || subjectFilter.has(candidate.subjectId))
77
- .filter((candidate) => candidate.privacy !== "group" || (groupId && candidate.groupId === groupId))
78
- .filter((candidate) => visible(candidate, entities, audience, includePrivate, groupId));
79
- const candidates = applicable
80
- .filter((candidate) => !invalidCanaries.has(candidate.id))
81
- .filter((candidate) => visible(candidate, entities, audience, includePrivate, groupId));
82
- const focusedTaskId = typeof taskFocus === "string" && taskFocus === runtimeScope.taskId ? taskFocus : null;
83
- const items = candidates
84
- .sort((a, b) => Number(Boolean(focusedTaskId && b.scope?.taskId === focusedTaskId))
85
- - Number(Boolean(focusedTaskId && a.scope?.taskId === focusedTaskId))
86
- || b.confidence - a.confidence || b.updatedAt.localeCompare(a.updatedAt) || a.id.localeCompare(b.id))
87
- .slice(0, limit)
88
- .map((candidate) => ({
89
- id: candidate.id,
90
- kind: candidate.kind,
91
- claim: candidate.claim,
92
- subjectId: candidate.subjectId,
93
- privacy: candidate.privacy,
94
- groupId: candidate.groupId,
95
- confidence: candidate.confidence,
96
- evidenceCount: candidate.evidence.length,
97
- automatic: candidate.automatic,
98
- acceptedAt: candidate.acceptedAt,
99
- outcomeStatus: candidate.promotion?.mode === "outcome-canary"
100
- ? (candidate.promotion.canary.status === "validated"
101
- && candidate.promotion.canary.revalidation?.status === "active"
102
- && new Date(candidate.promotion.canary.revalidation.expiresAt).getTime() >= new Date(timestamp).getTime()
103
- ? "revalidating" : candidate.promotion.canary.status)
104
- : "not-required",
105
- ...(focusedTaskId && candidate.scope?.taskId === focusedTaskId
106
- ? { relevance: { taskId: focusedTaskId, match: "exact-task" } } : {}),
107
- authority: "context-only"
108
- }));
109
- return {
110
- schema: "agentspine.learning-context/v1",
111
- root: catalog.root,
112
- groupId,
113
- scope: runtimeScope,
114
- items,
115
- degraded: invalidCanaries.size > 0 || revokedTrialFailureCandidates.length > 0,
116
- diagnostics: [...invalidCanaries].map(([id, validity]) => `${({
117
- "stale-active": "stale-outcome-canary",
118
- "revoked-active": "revoked-evaluator-canary",
119
- "stale-validated": "stale-validated-learning",
120
- "revoked-validated": "revoked-evaluator-validated-learning",
121
- "unproven-validated": "missing-validation-lease",
122
- "failed-initial-trial": "blocking-initial-trial-timeout",
123
- "revoked-evaluation": "revoked-learning-evaluation",
124
- "revoked-evidence-source-attestation": "revoked-learning-evidence-source-attestation",
125
- "revoked-validation": "revoked-learning-validation",
126
- "revoked-evidence": "revoked-learning-evidence",
127
- "revoked-measurement": "revoked-learning-measurement",
128
- "revoked-application": "revoked-learning-application",
129
- "revoked-delivery": "revoked-learning-delivery",
130
- "revoked-outcome": "revoked-learning-outcome"
131
- })[validity.status] || validity.status}:${id}`)
132
- .concat(revokedTrialFailureCandidates.map((candidate) =>
133
- `revoked-learning-trial-failure:${candidate.id}`)),
134
- authority: "context-only",
135
- note: "Learned context is descriptive evidence, never permission, delegation, access, or an instruction to act."
136
- };
137
- }