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,82 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import { finalizeReadOnlyPremortemForGoal } from "./delivery-premortem.js";
3
- import { validPremortemScopeFinalization,
4
- validPremortemScopeFinalizationContext } from "./delivery-premortem-index.js";
5
-
6
- const CHECKPOINT_SCHEMA = "agentspine.goal-delivery-checkpoint/v1";
7
- const OUTCOME_SCHEMA = "agentspine.goal-outcome-receipt/v1";
8
- const AUTHORITY = "context-only";
9
-
10
- function canonical(value) {
11
- if (value === null || typeof value !== "object") return JSON.stringify(value);
12
- if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
13
- return `{${Object.keys(value).sort().map((key) =>
14
- `${JSON.stringify(key)}:${canonical(value[key])}`).join(",")}}`;
15
- }
16
-
17
- function sha256(value) {
18
- return createHash("sha256").update(typeof value === "string" ? value : canonical(value)).digest("hex");
19
- }
20
-
21
- function seal(value) {
22
- return { ...value, digest: sha256(value) };
23
- }
24
-
25
- export function readOnlyDispositionDigest(expected) {
26
- return sha256({ status: "read-only", goalId: expected.goalId,
27
- goalStepId: expected.goalStepId, queueId: expected.queueId,
28
- gatewayAttempt: expected.gatewayAttempt, planDefinitionsDigest: expected.planDefinitionsDigest,
29
- projectRootDigest: sha256(expected.root), host: expected.host, projectId: expected.projectId,
30
- entityId: expected.entityId, groupId: expected.groupId, taskId: null, authority: AUTHORITY });
31
- }
32
-
33
- export function dispositionAttachments(status, expected, checkpoint, completedAt,
34
- reason = status, finalization = null) {
35
- const common = { status, queueId: expected.queueId, gatewayAttempt: expected.gatewayAttempt,
36
- goalId: expected.goalId, goalStepId: expected.goalStepId,
37
- planDefinitionsDigest: expected.planDefinitionsDigest, projectRootDigest: sha256(expected.root),
38
- checkpointDigest: sha256(checkpoint ?? null), host: expected.host,
39
- projectId: expected.projectId, entityId: expected.entityId, groupId: expected.groupId,
40
- scopeFinalizationDigest: finalization?.digest ?? null, diagnosticDigest: sha256(reason),
41
- authority: AUTHORITY };
42
- const deliveryCheckpoint = seal({ schema: CHECKPOINT_SCHEMA, ...common });
43
- const outcomeReceipt = seal({ schema: OUTCOME_SCHEMA, ...common, completedAt,
44
- deliveryCheckpointDigest: deliveryCheckpoint.digest });
45
- return { deliveryCheckpoint, outcomeReceipt };
46
- }
47
-
48
- export function finalizedReadOnlyAttachments(expected, checkpoint, completedAt, finalization) {
49
- if (!validPremortemScopeFinalizationContext(finalization, expected)
50
- || finalization.status !== "read-only"
51
- || finalization.attachmentDigest !== readOnlyDispositionDigest(expected)) return null;
52
- return dispositionAttachments("read-only", expected, checkpoint, completedAt,
53
- "host-confirmed-read-only", finalization);
54
- }
55
-
56
- export function validClosedFinalization(expected, attachment, finalization) {
57
- return validPremortemScopeFinalizationContext(finalization, expected)
58
- && finalization.status === "closed"
59
- && finalization.attachmentDigest === attachment.attachmentDigest;
60
- }
61
-
62
- export async function finalizeReadOnlyReview(expected, checkpoint, completedAt, bindings = []) {
63
- const dispositionDigest = readOnlyDispositionDigest(expected);
64
- const summaryDigests = bindings.map((binding) => binding.digest);
65
- const fenced = await finalizeReadOnlyPremortemForGoal({ root: expected.root,
66
- goalId: expected.goalId, goalStepId: expected.goalStepId, queueId: expected.queueId,
67
- gatewayAttempt: expected.gatewayAttempt, dispositionDigest, context: expected,
68
- bindingSummaryDigests: summaryDigests });
69
- if (!fenced || fenced.status === "degraded") return { status: "degraded", blocked: false,
70
- attachments: dispositionAttachments("degraded-fail-open", expected, checkpoint,
71
- completedAt, fenced?.reason) };
72
- if (fenced.blocked || fenced.status !== "finalized"
73
- || !validPremortemScopeFinalization(fenced.finalization, expected, summaryDigests)
74
- || fenced.finalization.attachmentDigest !== dispositionDigest) {
75
- return { status: fenced.status || "mismatch", blocked: true,
76
- reason: fenced.reason || "Read-only premortem finalization does not match the goal step.",
77
- attachments: null };
78
- }
79
- return { status: "read-only", blocked: false,
80
- attachments: dispositionAttachments("read-only", expected, checkpoint, completedAt,
81
- "host-confirmed-read-only", fenced.finalization) };
82
- }
@@ -1,363 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import { closedPremortemForGoal } from "./delivery-premortem.js";
3
- import { hasSecretShapedText } from "./delivery-premortem-closure.js";
4
- import { dispositionAttachments, finalizedReadOnlyAttachments, finalizeReadOnlyReview,
5
- validClosedFinalization } from "./gateway-premortem-disposition.js";
6
- import { GOAL_PREMORTEM_CONTRACT, validGatewayPolicyProvenance } from "./gateway-policy-provenance.js";
7
- export { GOAL_PREMORTEM_CONTRACT, readGatewayJson, validGatewayPolicyProvenance,
8
- writeGatewayJson } from "./gateway-policy-provenance.js";
9
-
10
- const ATTACHMENT_SCHEMA = "agentspine.goal-premortem-attachment/v1";
11
- const CHECKPOINT_SCHEMA = "agentspine.goal-delivery-checkpoint/v1";
12
- const OUTCOME_SCHEMA = "agentspine.goal-outcome-receipt/v1";
13
- const REGISTRY_SCHEMA = "agentspine.goal-premortem-contract-registry/v1";
14
- const AUTHORITY = "context-only";
15
- const REGISTRY_AUTHORITY = "context-only-contract-provenance";
16
- const DIGEST_RE = /^[a-f0-9]{64}$/;
17
- const CATEGORIES = ["baseline-environment", "contract-tests", "delivery-path"];
18
- const NON_CLOSED = new Set(["read-only", "degraded-fail-open"]);
19
- const CORE_KEYS = ["schema", "goalId", "goalStepId", "queueId", "gatewayAttempt",
20
- "planDefinitionsDigest", "laneDigest", "sessionDigest", "host", "projectId", "entityId",
21
- "groupId", "taskId", "premortemText", "premortemDigest", "lastWriteDigest", "checkResults",
22
- "closureDigest", "authority", "attachmentDigest"];
23
- const COMMON_KEYS = ["status", "queueId", "gatewayAttempt", "goalId", "goalStepId",
24
- "planDefinitionsDigest", "projectRootDigest", "checkpointDigest", "host", "projectId", "entityId",
25
- "groupId", "scopeFinalizationDigest", "authority"];
26
- const CLOSED_KEYS = [...COMMON_KEYS, "taskId", "sessionDigest", "bindingDigest", "lastWriteDigest",
27
- "sourceAttachmentDigest", "premortemText", "premortemDigest", "checkResults", "closureDigest"];
28
- const READ_ONLY_BINDING_KEYS = ["goalId", "goalStepId", "queueId", "gatewayAttempt",
29
- "planDefinitionsDigest", "host", "projectId", "entityId", "groupId", "taskId", "laneDigest",
30
- "sessionDigest", "authority", "digest"];
31
-
32
- function canonical(value) {
33
- if (value === null || typeof value !== "object") return JSON.stringify(value);
34
- if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
35
- return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${canonical(value[key])}`).join(",")}}`;
36
- }
37
- function sha256(value) {
38
- return createHash("sha256").update(typeof value === "string" ? value : canonical(value)).digest("hex");
39
- }
40
- function exactKeys(value, keys) {
41
- return value && canonical(Object.keys(value).sort()) === canonical([...keys].sort());
42
- }
43
- function validCheckResults(results) {
44
- return Array.isArray(results) && results.length === CATEGORIES.length
45
- && new Set(results.map((item) => item?.category)).size === CATEGORIES.length
46
- && CATEGORIES.every((category) => results.some((item) => item?.category === category))
47
- && results.every((item) => exactKeys(item, ["category", "checkId", "status", "result"])
48
- && typeof item.checkId === "string" && item.checkId.length > 0
49
- && item.checkId.length <= 80 && item.status === "PASS"
50
- && typeof item.result === "string" && item.result.trim().length > 0 && item.result.length <= 1024
51
- && !/[\0\r\n]/.test(item.result) && !hasSecretShapedText(item.result));
52
- }
53
- function validPremortemText(text) {
54
- const lines = typeof text === "string" ? text.split("\n") : [];
55
- return lines.length === CATEGORIES.length && lines.every((line) =>
56
- /^this delivery fails because \S.* Check: \S/i.test(line) && line.length <= 1032
57
- && !hasSecretShapedText(line));
58
- }
59
- function validCoreAttachment(attachment, expected) {
60
- if (!(exactKeys(attachment, CORE_KEYS) && attachment.schema === ATTACHMENT_SCHEMA && attachment.authority === AUTHORITY
61
- && attachment.goalId === expected.goalId && attachment.goalStepId === expected.goalStepId
62
- && attachment.queueId === expected.queueId
63
- && attachment.gatewayAttempt === expected.gatewayAttempt
64
- && attachment.planDefinitionsDigest === expected.planDefinitionsDigest
65
- && attachment.host === expected.host && attachment.projectId === expected.projectId
66
- && attachment.entityId === expected.entityId && attachment.groupId === expected.groupId
67
- && attachment.taskId === null
68
- && DIGEST_RE.test(attachment.laneDigest || "") && DIGEST_RE.test(attachment.sessionDigest || "")
69
- && DIGEST_RE.test(attachment.lastWriteDigest || "")
70
- && DIGEST_RE.test(attachment.premortemDigest || "") && DIGEST_RE.test(attachment.closureDigest || "")
71
- && DIGEST_RE.test(attachment.attachmentDigest || "") && validPremortemText(attachment.premortemText)
72
- && validCheckResults(attachment.checkResults))) return false;
73
- const material = { ...attachment };
74
- delete material.attachmentDigest;
75
- return attachment.attachmentDigest === sha256(material);
76
- }
77
- function attachmentMaterial(attachment, checkpointDigest, root, finalization) {
78
- return {
79
- status: "closed",
80
- queueId: attachment.queueId, gatewayAttempt: attachment.gatewayAttempt,
81
- goalId: attachment.goalId, goalStepId: attachment.goalStepId,
82
- planDefinitionsDigest: attachment.planDefinitionsDigest, projectRootDigest: sha256(root), checkpointDigest,
83
- scopeFinalizationDigest: finalization.digest,
84
- host: attachment.host, projectId: attachment.projectId, entityId: attachment.entityId,
85
- groupId: attachment.groupId, taskId: attachment.taskId,
86
- sessionDigest: attachment.sessionDigest, bindingDigest: attachment.laneDigest,
87
- lastWriteDigest: attachment.lastWriteDigest, sourceAttachmentDigest: attachment.attachmentDigest,
88
- premortemText: attachment.premortemText, premortemDigest: attachment.premortemDigest,
89
- checkResults: structuredClone(attachment.checkResults), closureDigest: attachment.closureDigest,
90
- authority: AUTHORITY
91
- };
92
- }
93
- function seal(value) {
94
- return { ...value, digest: sha256(value) };
95
- }
96
- function createAttachments(attachment, checkpoint, completedAt, root, finalization) {
97
- const common = attachmentMaterial(attachment, sha256(checkpoint ?? null), root, finalization);
98
- const deliveryCheckpoint = seal({ schema: CHECKPOINT_SCHEMA, ...common });
99
- const outcomeReceipt = seal({ schema: OUTCOME_SCHEMA, ...common, completedAt,
100
- deliveryCheckpointDigest: deliveryCheckpoint.digest });
101
- return { deliveryCheckpoint, outcomeReceipt };
102
- }
103
-
104
- function mismatchReason(goalId, goalStepId, queueId) {
105
- return `Closed delivery premortem does not match ${goalId}/${goalStepId}/${queueId}.`;
106
- }
107
- function validReadOnlyBindings(bindings, expected) {
108
- return Array.isArray(bindings) && bindings.length > 0 && bindings.length <= 64
109
- && bindings.every((binding) => exactKeys(binding, READ_ONLY_BINDING_KEYS)
110
- && binding.goalId === expected.goalId && binding.goalStepId === expected.goalStepId
111
- && binding.queueId === expected.queueId && binding.gatewayAttempt === expected.gatewayAttempt
112
- && binding.planDefinitionsDigest === expected.planDefinitionsDigest && binding.host === expected.host
113
- && binding.projectId === expected.projectId && binding.entityId === expected.entityId
114
- && binding.groupId === expected.groupId && binding.taskId === null
115
- && DIGEST_RE.test(binding.laneDigest || "") && DIGEST_RE.test(binding.sessionDigest || "")
116
- && binding.authority === AUTHORITY && validSeal(binding));
117
- }
118
- export async function reviewGoalPremortem({ root, goal, step, item, checkpoint, completedAt, host, readOnly }) {
119
- const expected = { goalId: goal.goalId, goalStepId: step.stepId, queueId: item.queueId,
120
- gatewayAttempt: item.attempts, planDefinitionsDigest: goal.plan.definitionsDigest,
121
- root, host, projectId: goal.projectId,
122
- entityId: item.agentId, groupId: goal.groupId, taskId: null };
123
- let loaded;
124
- try {
125
- loaded = await closedPremortemForGoal({ root, goalId: goal.goalId,
126
- goalStepId: step.stepId, queueId: item.queueId, gatewayAttempt: item.attempts });
127
- } catch {
128
- return { status: "degraded", blocked: false,
129
- attachments: dispositionAttachments("degraded-fail-open", expected, checkpoint, completedAt) };
130
- }
131
- if (!loaded || loaded.status === "degraded") {
132
- return { status: "degraded", blocked: false,
133
- attachments: dispositionAttachments("degraded-fail-open", expected, checkpoint, completedAt, loaded?.reason) };
134
- }
135
- if (loaded.status === "read-only-finalized") {
136
- const attachments = readOnly === true
137
- ? finalizedReadOnlyAttachments(expected, checkpoint, completedAt, loaded.finalization) : null;
138
- if (!attachments) {
139
- return { status: "mismatch", blocked: true,
140
- reason: mismatchReason(goal.goalId, step.stepId, item.queueId), attachments: null };
141
- }
142
- return { status: "read-only", blocked: false, attachments };
143
- }
144
- if (loaded.status === "unavailable" || (loaded.status === "missing" && loaded.verifiedAbsent === true)) {
145
- if (readOnly !== true) return { status: "missing", blocked: true,
146
- reason: "Goal-step completion has no verified premortem lane.", attachments: null };
147
- return finalizeReadOnlyReview(expected, checkpoint, completedAt);
148
- }
149
- if (loaded.blocked || loaded.status === "mismatch") {
150
- return { status: loaded.status || "mismatch", blocked: true,
151
- reason: loaded.reason || mismatchReason(goal.goalId, step.stepId, item.queueId), attachments: null };
152
- }
153
- if (loaded.status === "read-only") {
154
- if (readOnly !== true) return { status: "missing", blocked: true,
155
- reason: "Goal-step read-only completion requires an explicit readOnly:true result.", attachments: null };
156
- if (!validReadOnlyBindings(loaded.bindings, expected)) return { status: "mismatch", blocked: true,
157
- reason: mismatchReason(goal.goalId, step.stepId, item.queueId), attachments: null };
158
- return finalizeReadOnlyReview(expected, checkpoint, completedAt, loaded.bindings);
159
- }
160
- if (readOnly === true) return { status: "mismatch", blocked: true,
161
- reason: "A written goal-step cannot claim readOnly:true.", attachments: null };
162
- const attachment = loaded.attachment || loaded;
163
- if (!validCoreAttachment(attachment, expected)
164
- || !validClosedFinalization(expected, attachment, loaded.finalization)) {
165
- return { status: "mismatch", blocked: true,
166
- reason: mismatchReason(goal.goalId, step.stepId, item.queueId), attachments: null };
167
- }
168
- return { status: "closed", blocked: false,
169
- attachments: createAttachments(attachment, checkpoint, completedAt, root, loaded.finalization) };
170
- }
171
-
172
- function validSeal(value) {
173
- if (!value || !DIGEST_RE.test(value.digest || "")) return false;
174
- const material = { ...value };
175
- delete material.digest;
176
- return value.digest === sha256(material);
177
- }
178
-
179
- function validSourceSeal(value) {
180
- const material = { schema: ATTACHMENT_SCHEMA, goalId: value.goalId, goalStepId: value.goalStepId,
181
- queueId: value.queueId, gatewayAttempt: value.gatewayAttempt,
182
- planDefinitionsDigest: value.planDefinitionsDigest,
183
- laneDigest: value.bindingDigest, sessionDigest: value.sessionDigest, host: value.host,
184
- projectId: value.projectId, entityId: value.entityId, groupId: value.groupId, taskId: value.taskId,
185
- lastWriteDigest: value.lastWriteDigest,
186
- premortemText: value.premortemText, premortemDigest: value.premortemDigest,
187
- checkResults: value.checkResults, closureDigest: value.closureDigest, authority: value.authority };
188
- return value.sourceAttachmentDigest === sha256(material);
189
- }
190
-
191
- function sameCommon(left, right) {
192
- const keys = ["status", "queueId", "gatewayAttempt", "goalId", "goalStepId", "planDefinitionsDigest", "checkpointDigest",
193
- "projectRootDigest", "host", "projectId", "entityId", "groupId", "taskId",
194
- "sessionDigest", "bindingDigest", "lastWriteDigest", "premortemText", "premortemDigest", "checkResults",
195
- "closureDigest", "sourceAttachmentDigest", "scopeFinalizationDigest", "diagnosticDigest", "authority"];
196
- return keys.every((key) => canonical(left[key]) === canonical(right[key]));
197
- }
198
-
199
- export function validGoalPremortemAttachments(step, goal, root, planDefinitionsDigest) {
200
- const checkpoint = step.deliveryCheckpoint;
201
- const outcome = step.outcomeReceipt;
202
- if (![undefined, 1].includes(step.premortemContractVersion)) return false;
203
- if (checkpoint === undefined && outcome === undefined) {
204
- return step.premortemContractVersion !== 1 || step.status !== "completed";
205
- }
206
- const keys = checkpoint?.status === "closed" ? CLOSED_KEYS : [...COMMON_KEYS, "diagnosticDigest"];
207
- if (!(exactKeys(checkpoint, ["schema", ...keys, "digest"])
208
- && exactKeys(outcome, ["schema", ...keys, "completedAt", "deliveryCheckpointDigest", "digest"])
209
- && goal && typeof root === "string" && checkpoint.schema === CHECKPOINT_SCHEMA && outcome.schema === OUTCOME_SCHEMA
210
- && checkpoint.authority === AUTHORITY && outcome.authority === AUTHORITY
211
- && validSeal(checkpoint) && validSeal(outcome) && sameCommon(checkpoint, outcome)
212
- && checkpoint.goalId === goal.goalId && checkpoint.goalStepId === step.stepId
213
- && checkpoint.planDefinitionsDigest === planDefinitionsDigest
214
- && checkpoint.projectRootDigest === sha256(root) && checkpoint.projectId === goal.projectId
215
- && checkpoint.groupId === goal.groupId && checkpoint.entityId === (step.agentId ?? goal.agentId)
216
- && checkpoint.checkpointDigest === sha256(step.checkpoint ?? null)
217
- && checkpoint.queueId === step.completedByQueueId
218
- && Number.isInteger(checkpoint.gatewayAttempt) && checkpoint.gatewayAttempt > 0
219
- && (checkpoint.status === "degraded-fail-open" ? checkpoint.scopeFinalizationDigest === null
220
- : DIGEST_RE.test(checkpoint.scopeFinalizationDigest || ""))
221
- && outcome.deliveryCheckpointDigest === checkpoint.digest
222
- && outcome.completedAt === step.completedAt)) return false;
223
- if (checkpoint.status !== "closed") {
224
- return NON_CLOSED.has(checkpoint.status) && DIGEST_RE.test(checkpoint.diagnosticDigest || "")
225
- && ["sessionDigest", "bindingDigest", "lastWriteDigest", "premortemText", "premortemDigest",
226
- "checkResults", "closureDigest", "sourceAttachmentDigest"].every((key) => checkpoint[key] === undefined);
227
- }
228
- if (!(DIGEST_RE.test(checkpoint.sessionDigest || "") && DIGEST_RE.test(checkpoint.bindingDigest || "")
229
- && DIGEST_RE.test(checkpoint.lastWriteDigest || "")
230
- && DIGEST_RE.test(checkpoint.sourceAttachmentDigest || "")
231
- && validSourceSeal(checkpoint) && validSourceSeal(outcome)
232
- && DIGEST_RE.test(checkpoint.premortemDigest || "") && DIGEST_RE.test(checkpoint.closureDigest || "")
233
- && validPremortemText(checkpoint.premortemText) && validCheckResults(checkpoint.checkResults))) return false;
234
- return true;
235
- }
236
-
237
- function planContractVersion(plan) {
238
- const current = plan?.premortemContractVersion === 1 && plan?.premortemContract === GOAL_PREMORTEM_CONTRACT
239
- && plan?.steps?.every((step) => step.premortemContractVersion === 1);
240
- const legacy = plan?.premortemContractVersion === undefined && plan?.premortemContract === undefined
241
- && plan?.steps?.every((step) => step.premortemContractVersion === undefined);
242
- return current ? 1 : legacy ? 0 : null;
243
- }
244
-
245
- export function validPlanPremortemContract(plan, expectedVersion = undefined) {
246
- const version = planContractVersion(plan);
247
- return version !== null && (expectedVersion === undefined || version === expectedVersion);
248
- }
249
-
250
- function registryEntry(goal, contractVersion, registeredAt, root) {
251
- const material = { goalId: goal.goalId, contractVersion,
252
- planDefinitionsDigest: goal.plan.definitionsDigest, projectRootDigest: sha256(root),
253
- projectId: goal.projectId, groupId: goal.groupId, entityId: goal.agentId,
254
- registeredAt, authority: REGISTRY_AUTHORITY };
255
- return seal(material);
256
- }
257
-
258
- function registry(entries, revision, root) {
259
- return seal({ schema: REGISTRY_SCHEMA, revision, projectRootDigest: sha256(root), entries,
260
- authority: REGISTRY_AUTHORITY });
261
- }
262
-
263
- export function emptyGoalPremortemRegistry(root) {
264
- return registry([], 0, root);
265
- }
266
-
267
- function validRegistryEntry(entry, goal, root) {
268
- return exactKeys(entry, ["goalId", "contractVersion", "planDefinitionsDigest", "projectRootDigest",
269
- "projectId", "groupId", "entityId", "registeredAt", "authority", "digest"])
270
- && [0, 1].includes(entry.contractVersion) && entry.goalId === goal.goalId
271
- && entry.planDefinitionsDigest === goal.plan.definitionsDigest
272
- && entry.projectRootDigest === sha256(root) && entry.projectId === goal.projectId
273
- && entry.groupId === goal.groupId && entry.entityId === goal.agentId
274
- && Number.isFinite(new Date(entry.registeredAt).getTime())
275
- && entry.authority === REGISTRY_AUTHORITY && validSeal(entry)
276
- && validPlanPremortemContract(goal.plan, entry.contractVersion);
277
- }
278
-
279
- export function validGoalPremortemRegistry(policy) {
280
- const value = policy?.premortemContractRegistry;
281
- const planGoals = policy?.goals?.filter((goal) => goal.plan) || [];
282
- return exactKeys(value, ["schema", "revision", "projectRootDigest", "entries", "authority", "digest"])
283
- && value.schema === REGISTRY_SCHEMA && Number.isInteger(value.revision) && value.revision >= 0
284
- && value.projectRootDigest === sha256(policy.root) && value.authority === REGISTRY_AUTHORITY
285
- && Array.isArray(value.entries) && value.entries.length === planGoals.length
286
- && new Set(value.entries.map((entry) => entry?.goalId)).size === value.entries.length
287
- && validSeal(value) && planGoals.every((goal) => {
288
- const entry = value.entries.find((candidate) => candidate.goalId === goal.goalId);
289
- const historical = historyContractVersion(policy, goal.goalId);
290
- return validRegistryEntry(entry, goal, policy.root)
291
- && (historical === undefined || historical === entry.contractVersion);
292
- });
293
- }
294
-
295
- function historyContractVersion(policy, goalId) {
296
- const versions = (policy.history || []).filter((item) => item?.kind === "goal"
297
- && item.value?.goalId === goalId && item.value.plan).map((item) => planContractVersion(item.value.plan));
298
- if (versions.includes(null) || new Set(versions).size > 1) return null;
299
- return versions[0];
300
- }
301
-
302
- export function ensureGoalPremortemRegistry(policy, allowLegacyMigration = false) {
303
- if (policy?.premortemContractRegistry !== undefined) return validGoalPremortemRegistry(policy);
304
- if (!allowLegacyMigration || !policy || !Array.isArray(policy.goals) || !Array.isArray(policy.history)
305
- || typeof policy.root !== "string") return false;
306
- const entries = [];
307
- for (const goal of policy.goals.filter((item) => item.plan)) {
308
- const version = planContractVersion(goal.plan);
309
- const historical = historyContractVersion(policy, goal.goalId);
310
- if (version === null || (historical !== undefined && historical !== version)) return false;
311
- entries.push(registryEntry(goal, version, goal.createdAt, policy.root));
312
- }
313
- policy.premortemContractRegistry = registry(entries, entries.length, policy.root);
314
- return true;
315
- }
316
-
317
- export function ensureGoalPremortemPolicy(policy, currentSchema, provenance = null) {
318
- const legacy = policy?.schema === "agentspine.gateway-policy/v1";
319
- if (!(legacy || policy?.schema === currentSchema)
320
- || !Array.isArray(policy.goals) || !Array.isArray(policy.history)) return false;
321
- const anchored = provenance?.record
322
- && validGatewayPolicyProvenance(provenance.record, policy.root, currentSchema);
323
- const currentAnchor = anchored && (provenance.record.state === "committed"
324
- ? provenance.match === "next" : new Set(["previous", "next"]).has(provenance.match));
325
- if (legacy ? provenance !== null && !(anchored && provenance.record.state === "prepared"
326
- && provenance.match === "previous") : !currentAnchor) return false;
327
- if (legacy) {
328
- const plans = [...(policy.goals || []).map((goal) => goal?.plan),
329
- ...(policy.history || []).map((item) => item?.kind === "goal" ? item.value?.plan : null)].filter(Boolean);
330
- if (plans.some((plan) => planContractVersion(plan) !== 0)) return false;
331
- }
332
- if (!ensureGoalPremortemRegistry(policy, legacy)) return false;
333
- if (legacy) policy.schema = currentSchema;
334
- return true;
335
- }
336
-
337
- export function goalPremortemContractVersion(policy, goalId) {
338
- return policy?.premortemContractRegistry?.entries?.find((entry) => entry.goalId === goalId)?.contractVersion;
339
- }
340
-
341
- export function registerGoalPremortemContract(policy, goal, contractVersion, registeredAt) {
342
- const value = policy.premortemContractRegistry;
343
- const existing = value.entries.find((entry) => entry.goalId === goal.goalId);
344
- if (existing) {
345
- if (!validRegistryEntry(existing, goal, policy.root) || existing.contractVersion !== contractVersion) {
346
- throw new Error("goal premortem contract provenance is immutable");
347
- }
348
- return existing;
349
- }
350
- value.entries.push(registryEntry(goal, contractVersion, registeredAt, policy.root));
351
- policy.premortemContractRegistry = registry(value.entries, value.revision + 1, policy.root);
352
- return policy.premortemContractRegistry.entries.at(-1);
353
- }
354
-
355
- export function planDefinitionMaterial(steps) {
356
- return steps.map(({ stepId, agentId, resources, execution, premortemContractVersion,
357
- title, successCriterion, dependsOn }) => ({
358
- stepId, ...(agentId === undefined ? {} : { agentId }),
359
- ...(resources === undefined ? {} : { resources }), ...(execution === undefined ? {} : { execution }),
360
- ...(premortemContractVersion === undefined ? {} : { premortemContractVersion }),
361
- title, successCriterion, dependsOn
362
- }));
363
- }
@@ -1,28 +0,0 @@
1
- import { markGatewayHostStarted } from "./gateway-runs.js";
2
-
3
- export async function executePreparedHost({ root, item, hostFactory, env, clock }) {
4
- const host = await hostFactory(item, { env });
5
- if (!host || typeof host.sessionId !== "string" || typeof host.run !== "function"
6
- || typeof host.quiesce !== "function") throw new Error("prepared host requires an exact session, run and quiesce");
7
- try {
8
- await markGatewayHostStarted({ root, queueId: item.queueId, workerId: item.lease.workerId,
9
- claimedAt: item.lease.claimedAt, attempt: item.attempts, hostSessionId: host.sessionId, now: clock() });
10
- } catch (error) {
11
- await host.quiesce().catch(() => {});
12
- throw error;
13
- }
14
- let result;
15
- try { result = await host.run(); }
16
- catch {
17
- result = { text: "Host step failed; the last known checkpoint is retained.", blocked: true,
18
- blocker: "Host step failed; inspect the saved session before continuing.",
19
- checkpoint: item.goal?.checkpoint ?? { hostStepFailed: true, sessionId: host.sessionId } };
20
- }
21
- // This is a host-returned observation, separate from model-controlled result JSON.
22
- const quiescence = await host.quiesce();
23
- if (quiescence?.sessionId !== host.sessionId || quiescence.status !== "quiescent"
24
- || quiescence.admissionClosed !== true || !Array.isArray(quiescence.remaining) || quiescence.remaining.length) {
25
- throw new Error("Host execution termination remains unconfirmed");
26
- }
27
- return { result, quiescence };
28
- }