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,84 +0,0 @@
1
- import { deliveryActorSession, recordDeliveryPause, verifyDeliveryStop } from "./delivery-verification.js";
2
- import { blockStop } from "./hook-output.js";
3
- import { verifyHookPremortemStop } from "./hook-premortem.js";
4
-
5
- function explicitStopEventId(input) {
6
- for (const candidate of [input?.event_id, input?.hook_event_id]) {
7
- if (typeof candidate === "string" && candidate) return candidate;
8
- }
9
- return null;
10
- }
11
-
12
- function stopArguments(input, root, scope) {
13
- return {
14
- root,
15
- host: scope.host,
16
- sessionId: deliveryActorSession(input),
17
- scope,
18
- // Timestamps identify neither a host event nor a pause: two distinct Stop
19
- // deliveries may share one. Only an explicit host-provided event id can
20
- // make a pause idempotent or be honored by a later completion.
21
- eventId: explicitStopEventId(input)
22
- };
23
- }
24
-
25
- function blockedResult(deliveryVerification, premortem = null) {
26
- return {
27
- blocked: true,
28
- reason: deliveryVerification.reason,
29
- deliveryVerification,
30
- premortem
31
- };
32
- }
33
-
34
- export function denyHookStop(payload, event, reason, details) {
35
- if (payload) return { blocked: true, reason, ...details };
36
- blockStop(event, reason);
37
- }
38
-
39
- export async function verifyHookStopContracts({ input, root, scope, recordPause = false,
40
- completionFence = false, afterDeliveryVerification = null,
41
- afterPremortemVerification = null }) {
42
- const argumentsForStop = stopArguments(input, root, scope);
43
- const deliveryVerification = recordPause
44
- ? await recordDeliveryPause(argumentsForStop)
45
- : await verifyDeliveryStop(argumentsForStop);
46
- if (deliveryVerification.blocked) return blockedResult(deliveryVerification);
47
- if (typeof afterDeliveryVerification === "function") await afterDeliveryVerification();
48
-
49
- const premortem = await verifyHookPremortemStop({
50
- input,
51
- root,
52
- scope,
53
- paused: deliveryVerification.status === "paused-job",
54
- consume: completionFence
55
- });
56
- if (premortem.blocked) {
57
- return { blocked: true, reason: premortem.reason, deliveryVerification, premortem };
58
- }
59
- if (typeof afterPremortemVerification === "function") await afterPremortemVerification();
60
-
61
- const finalDeliveryVerification = completionFence
62
- ? await verifyDeliveryStop(argumentsForStop)
63
- : deliveryVerification;
64
- if (finalDeliveryVerification.blocked) {
65
- return blockedResult(finalDeliveryVerification, premortem);
66
- }
67
- const digestPattern = /^[a-f0-9]{64}$/;
68
- if (completionFence && digestPattern.test(deliveryVerification.stateDigest || "")
69
- && digestPattern.test(finalDeliveryVerification.stateDigest || "")
70
- && deliveryVerification.stateDigest !== finalDeliveryVerification.stateDigest) {
71
- return blockedResult({
72
- ...finalDeliveryVerification,
73
- status: "changed",
74
- blocked: true,
75
- reason: "AgentSpine delivery evidence changed during Stop; retry completion against the latest state."
76
- }, premortem);
77
- }
78
- return {
79
- blocked: false,
80
- reason: null,
81
- deliveryVerification: finalDeliveryVerification,
82
- premortem
83
- };
84
- }
@@ -1,102 +0,0 @@
1
- import { sessionTimelineLifecycleHint } from "./session-timeline.js";
2
- import { issueHostTranscriptReceipt } from "./session-timeline-enrollment.js";
3
- import { consumeTimelineHostOrigin } from "./session-timeline-host-origin.js";
4
- import {
5
- automaticPreAnswerTimelineRecall, timelineRecallNotFound
6
- } from "./pre-answer-timeline-recall.js";
7
- import {
8
- timelineHostForRuntime, timelineHostHome, timelineProtocolFromRuntime, timelineSourceFromRuntime
9
- } from "./session-timeline-provider.js";
10
-
11
- const AUTHORITY = "context-only";
12
-
13
- function unavailable(reason) {
14
- return { schema: "agentspine.session-timeline/v1", status: "unavailable", reason, authority: AUTHORITY };
15
- }
16
-
17
- function hasRawTimelineGroupSignal(input) {
18
- try {
19
- if (!input || typeof input !== "object" || Array.isArray(input)) return false;
20
- const nested = input.agent_spine_scope;
21
- const values = [input.groupId, input.group_id];
22
- if (nested && typeof nested === "object" && !Array.isArray(nested)) {
23
- values.push(nested.groupId, nested.group_id);
24
- }
25
- return values.some((value) => value !== undefined && value !== null && value !== "");
26
- } catch {
27
- return false;
28
- }
29
- }
30
-
31
- function groupSuppressed(reason) {
32
- return { schema: "agentspine.session-timeline/v1", status: "group-suppressed", reason, authority: AUTHORITY };
33
- }
34
-
35
- function receiptObservation(receipt) {
36
- return { schema: "agentspine.session-timeline-host-receipt/v1",
37
- status: receipt.status === "pending" ? "pending" : "unavailable", reason: receipt.reason || null,
38
- expiresAt: receipt.expiresAt || null, authority: AUTHORITY };
39
- }
40
-
41
- export async function observeHostTranscriptReceipt({ root, event, input, scope, hostHome, hostOrigin = null, clock = null }) {
42
- if (event !== "UserPromptSubmit") return receiptObservation({ status: "not-applicable" });
43
- if (hasRawTimelineGroupSignal(input)) return receiptObservation({ status: "unavailable", reason: "raw-group-scope" });
44
- if (!scope || scope.groupId !== null) return receiptObservation({ status: "unavailable", reason: "computed-group-scope" });
45
- const host = timelineHostForRuntime(scope.host, process.env);
46
- const receipt = await issueHostTranscriptReceipt({ root, host, sessionId: input.session_id ?? input.sessionId,
47
- scope, transcriptPath: timelineSourceFromRuntime(host, input), hostHome: timelineHostHome(host) ?? hostHome,
48
- event, eventId: input.event_id ?? input.hook_event_id,
49
- hostOrigin, clock, environment: process.env });
50
- return receiptObservation(receipt);
51
- }
52
-
53
- export async function captureSessionTimelineLifecycle({
54
- root, event, input, scope, hostHome, hostOrigin = null, clock = null, turnId = null, prompt
55
- }) {
56
- if (hasRawTimelineGroupSignal(input)) return groupSuppressed("raw-group-scope");
57
- if (!scope || scope.groupId !== null) return groupSuppressed("computed-group-scope");
58
- let hostReceipt = null;
59
- if (event === "UserPromptSubmit" && hostOrigin) {
60
- try { hostReceipt = await observeHostTranscriptReceipt({ root, event, input, scope, hostHome, hostOrigin, clock }); }
61
- catch (error) {
62
- hostReceipt = { schema: "agentspine.session-timeline-host-receipt/v1", status: "degraded", reason: error.message,
63
- expiresAt: null, authority: AUTHORITY };
64
- }
65
- }
66
- const result = (value) => hostReceipt ? { ...value, hostReceipt } : value;
67
- const host = timelineHostForRuntime(scope.host, process.env);
68
- if (!host || (host === "king" && !timelineProtocolFromRuntime(host))) return unavailable("host-not-supported");
69
- const session = input.session_id ?? input.sessionId;
70
- const lifecycle = await sessionTimelineLifecycleHint({ root, host,
71
- sessionId: session, scope, environment: process.env });
72
- if (event !== "UserPromptSubmit" || !hostOrigin) return result(lifecycle);
73
- const preAnswerRecall = lifecycle.priorSessions?.available
74
- ? await automaticPreAnswerTimelineRecall({
75
- root, host, sessionId: session, scope, hostHome, eventId: input.event_id ?? input.hook_event_id,
76
- turnId, prompt,
77
- environment: process.env
78
- }) : timelineRecallNotFound();
79
- const prior = lifecycle.priorSessions;
80
- return result({ ...lifecycle, priorSessions: prior && { available: prior.available, sessions: prior.sessions,
81
- indexedEvents: prior.indexedEvents, freshness: prior.freshness, authority: prior.authority }, preAnswerRecall });
82
- }
83
-
84
- export async function finalizeUserPromptSessionTimeline({
85
- root, input, scope, resolvedSources, preflight, prompt, now = new Date()
86
- }) {
87
- const consumed = await consumeTimelineHostOrigin({ event: "UserPromptSubmit", input, scope, resolvedSources,
88
- preflight, prompt, environment: process.env, now });
89
- if (!consumed?.consumed) return { preflightConsumed: false, briefingOrigin: null,
90
- timeline: unavailable("preflight-receipt-unavailable") };
91
- try {
92
- return { preflightConsumed: true, briefingOrigin: consumed.briefingOrigin,
93
- timeline: await captureSessionTimelineLifecycle({
94
- root, event: "UserPromptSubmit", input, scope, hostHome: resolvedSources.hostHome,
95
- hostOrigin: consumed.origin, clock: () => new Date(now), turnId: preflight.receipt.id, prompt
96
- }) };
97
- } catch (error) {
98
- return { preflightConsumed: true, briefingOrigin: consumed.briefingOrigin, timeline: {
99
- schema: "agentspine.session-timeline/v1", status: "degraded", reason: error.message, authority: AUTHORITY
100
- } };
101
- }
102
- }
@@ -1,11 +0,0 @@
1
- const STANDARD = 8192;
2
- export const KING_SOURCE_BYTES = 4194304;
3
- const KING_TOTAL = 8388608;
4
- export const isKingHost = (env = process.env) => !!(env.BLUN_PLUGIN_ROOT && env.BLUN_HOME);
5
-
6
- export function instructionBudget(host, usedBytes = 0, env = process.env) {
7
- const hardLimitBytes = host === "codex" && isKingHost(env) ? KING_TOTAL
8
- : host === "claude" ? 16384 : host === "codex" ? 32768 : STANDARD;
9
- return { mode: usedBytes > STANDARD ? `${host}-required-overflow` : "standard",
10
- standardBytes: STANDARD, hardLimitBytes, usedBytes, overflowBytes: Math.max(0, usedBytes - STANDARD) };
11
- }
@@ -1,392 +0,0 @@
1
- import { createHash, randomUUID } from "node:crypto";
2
- import { lookup as dnsLookup } from "node:dns/promises";
3
- import { lstat, mkdir, mkdtemp, open, readFile, realpath, rm, writeFile } from "node:fs/promises";
4
- import { request as httpsRequest } from "node:https";
5
- import { BlockList, isIP } from "node:net";
6
- import { tmpdir } from "node:os";
7
- import { basename, dirname, join, resolve } from "node:path";
8
- import { verifyEnvelope } from "./authentication.js";
9
- import { buildCatalog } from "./catalog.js";
10
- import { isInside } from "./paths.js";
11
- import { pullShared, readDirectoryExchange, validateSharedEvent } from "./sharing.js";
12
-
13
- const SCHEMA = "agentspine.https-snapshot/v1";
14
- const CONFIRMATION = "local-share-confirmed";
15
- const MAX_EVENTS = 2000;
16
- const MAX_SNAPSHOT_BYTES = 21 * 1024 * 1024;
17
- const MAX_TOKEN_BYTES = 8192;
18
- const ID_RE = /^[A-Za-z0-9][A-Za-z0-9:_.@/-]{0,127}$/;
19
- const DIGEST_RE = /^[a-f0-9]{64}$/;
20
- const TOKEN_ENV_RE = /^[A-Z_][A-Z0-9_]{0,127}$/;
21
-
22
- const blockedAddresses = new BlockList();
23
- const publicIpv6 = new BlockList();
24
- publicIpv6.addSubnet("2000::", 3, "ipv6");
25
- for (const [network, prefix] of [
26
- ["0.0.0.0", 8], ["10.0.0.0", 8], ["100.64.0.0", 10], ["127.0.0.0", 8],
27
- ["169.254.0.0", 16], ["172.16.0.0", 12], ["192.0.0.0", 24], ["192.0.2.0", 24],
28
- ["192.168.0.0", 16], ["198.18.0.0", 15], ["198.51.100.0", 24],
29
- ["203.0.113.0", 24], ["224.0.0.0", 4], ["240.0.0.0", 4]
30
- ]) blockedAddresses.addSubnet(network, prefix, "ipv4");
31
- for (const [network, prefix] of [
32
- ["::", 128], ["::1", 128], ["64:ff9b::", 96],
33
- ["100::", 64], ["2001::", 32], ["2001:2::", 48], ["2001:10::", 28],
34
- ["2001:20::", 28], ["2001:db8::", 32], ["2002::", 16], ["3fff::", 20],
35
- ["fc00::", 7], ["fe80::", 10], ["ff00::", 8]
36
- ]) blockedAddresses.addSubnet(network, prefix, "ipv6");
37
-
38
- function canonical(value) {
39
- if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
40
- if (value && typeof value === "object") {
41
- return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${canonical(value[key])}`).join(",")}}`;
42
- }
43
- return JSON.stringify(value);
44
- }
45
-
46
- function digest(value) {
47
- return createHash("sha256").update(canonical(value)).digest("hex");
48
- }
49
-
50
- function exactKeys(value, expected) {
51
- if (!value || typeof value !== "object" || Array.isArray(value)) return false;
52
- const actual = Object.keys(value).sort();
53
- const wanted = [...expected].sort();
54
- return actual.length === wanted.length && actual.every((key, index) => key === wanted[index]);
55
- }
56
-
57
- function validDate(value) {
58
- return typeof value === "string" && value.length > 0 && Number.isFinite(new Date(value).getTime());
59
- }
60
-
61
- function withoutDigest(value) {
62
- const { digest: _digest, ...body } = value;
63
- return body;
64
- }
65
-
66
- function eventId(document) {
67
- const payload = document?.schema === "agentspine.signed-envelope/v1" ? document.payload : null;
68
- return payload?.id;
69
- }
70
-
71
- function eventFilename(id) {
72
- return `${createHash("sha256").update(id).digest("hex")}.json`;
73
- }
74
-
75
- async function prospectiveCanonicalPath(path) {
76
- let ancestor = path;
77
- const missing = [];
78
- while (true) {
79
- try {
80
- const canonicalAncestor = await realpath(ancestor);
81
- return resolve(canonicalAncestor, ...missing.reverse());
82
- } catch (error) {
83
- if (error.code !== "ENOENT") throw error;
84
- const parent = dirname(ancestor);
85
- if (parent === ancestor) throw error;
86
- missing.push(basename(ancestor));
87
- ancestor = parent;
88
- }
89
- }
90
- }
91
-
92
- export function validateHttpsEndpoint(value) {
93
- let endpoint;
94
- try {
95
- endpoint = new URL(value);
96
- } catch {
97
- throw new Error("HTTPS snapshot URL is invalid");
98
- }
99
- if (endpoint.protocol !== "https:") throw new Error("HTTPS snapshots require an https:// URL");
100
- if (endpoint.username || endpoint.password) throw new Error("credentials must not be embedded in an HTTPS snapshot URL");
101
- if (endpoint.search || endpoint.hash) throw new Error("HTTPS snapshot URLs cannot contain a query or fragment");
102
- if (!endpoint.hostname || endpoint.pathname.endsWith("/")) {
103
- throw new Error("HTTPS snapshot URL must identify one explicit JSON resource");
104
- }
105
- return endpoint;
106
- }
107
-
108
- function addressBlocked(address) {
109
- const family = isIP(address);
110
- if (!family) throw new Error(`DNS returned an invalid address: ${address}`);
111
- if (family === 6 && !publicIpv6.check(address, "ipv6")) return true;
112
- return blockedAddresses.check(address, family === 4 ? "ipv4" : "ipv6");
113
- }
114
-
115
- async function within(promise, milliseconds, message) {
116
- let timer;
117
- try {
118
- return await Promise.race([
119
- promise,
120
- new Promise((_resolve, reject) => {
121
- timer = setTimeout(() => reject(new Error(message)), milliseconds);
122
- })
123
- ]);
124
- } finally {
125
- clearTimeout(timer);
126
- }
127
- }
128
-
129
- export async function resolveHttpsEndpoint(endpoint, {
130
- allowPrivateNetwork = false, lookup = dnsLookup
131
- } = {}) {
132
- const parsed = endpoint instanceof URL ? endpoint : validateHttpsEndpoint(endpoint);
133
- const lookupHostname = parsed.hostname.startsWith("[") && parsed.hostname.endsWith("]")
134
- ? parsed.hostname.slice(1, -1) : parsed.hostname;
135
- const literalFamily = isIP(lookupHostname);
136
- const answers = literalFamily
137
- ? [{ address: lookupHostname, family: literalFamily }]
138
- : await lookup(lookupHostname, { all: true, verbatim: true });
139
- if (!Array.isArray(answers) || answers.length === 0) throw new Error("HTTPS snapshot host did not resolve");
140
- for (const answer of answers) {
141
- if (!answer || isIP(answer.address) !== Number(answer.family)) throw new Error("HTTPS snapshot DNS result is invalid");
142
- if (!allowPrivateNetwork && addressBlocked(answer.address)) {
143
- throw new Error("HTTPS snapshot host resolves to a private, local, reserved, or documentation address");
144
- }
145
- }
146
- return {
147
- endpoint: parsed, lookupHostname,
148
- addresses: answers.map((answer) => ({ address: answer.address, family: Number(answer.family) }))
149
- };
150
- }
151
-
152
- function bearerToken(tokenEnv, environment) {
153
- if (tokenEnv === null || tokenEnv === undefined) return null;
154
- if (!TOKEN_ENV_RE.test(tokenEnv)) throw new Error("tokenEnv must be an uppercase environment variable name");
155
- const value = environment[tokenEnv];
156
- if (typeof value !== "string" || !value) throw new Error(`HTTPS snapshot token environment variable is missing: ${tokenEnv}`);
157
- if (Buffer.byteLength(value) > MAX_TOKEN_BYTES || /[\0-\x1f\x7f]/.test(value)) {
158
- throw new Error("HTTPS snapshot bearer token is invalid");
159
- }
160
- return value;
161
- }
162
-
163
- export async function fetchHttpsSnapshot({
164
- url, tokenEnv = null, timeoutMs = 10000, allowPrivateNetwork = false,
165
- confirmation = null, environment = process.env, lookup = dnsLookup, request = httpsRequest
166
- }) {
167
- if (!Number.isInteger(timeoutMs) || timeoutMs < 1000 || timeoutMs > 30000) {
168
- throw new Error("HTTPS snapshot timeout must be between 1000 and 30000 milliseconds");
169
- }
170
- if (allowPrivateNetwork && confirmation !== CONFIRMATION) {
171
- throw new Error("private-network HTTPS access requires explicit local owner confirmation");
172
- }
173
- const resolved = await within(
174
- resolveHttpsEndpoint(validateHttpsEndpoint(url), { allowPrivateNetwork, lookup }),
175
- timeoutMs,
176
- "HTTPS snapshot DNS resolution timed out"
177
- );
178
- const token = bearerToken(tokenEnv, environment);
179
- const selected = resolved.addresses[0];
180
- const headers = {
181
- accept: "application/json",
182
- "accept-encoding": "identity",
183
- "user-agent": "AgentSpine/0.1 HTTPS snapshot transport"
184
- };
185
- if (token) headers.authorization = `Bearer ${token}`;
186
- const body = await new Promise((resolvePromise, rejectPromise) => {
187
- let deadline;
188
- const reject = (error) => {
189
- clearTimeout(deadline);
190
- rejectPromise(error);
191
- };
192
- const resolve = (value) => {
193
- clearTimeout(deadline);
194
- resolvePromise(value);
195
- };
196
- const requestOptions = {
197
- protocol: "https:", hostname: resolved.lookupHostname,
198
- port: resolved.endpoint.port || 443,
199
- path: resolved.endpoint.pathname, method: "GET", headers,
200
- agent: false, autoSelectFamily: false,
201
- servername: isIP(resolved.lookupHostname) ? undefined : resolved.lookupHostname,
202
- lookup: (_hostname, options, callback) => {
203
- const family = typeof options === "object" && options.family ? Number(options.family) : 0;
204
- const usable = family ? resolved.addresses.find((item) => item.family === family) : selected;
205
- if (!usable) return callback(new Error("no vetted DNS address matches the requested family"));
206
- return callback(null, usable.address, usable.family);
207
- }
208
- };
209
- const active = request(requestOptions, (response) => {
210
- const status = Number(response.statusCode || 0);
211
- if (status >= 300 && status < 400) {
212
- response.resume();
213
- reject(new Error("HTTPS snapshot redirects are not followed"));
214
- return;
215
- }
216
- if (status !== 200) {
217
- response.resume();
218
- reject(new Error(`HTTPS snapshot request failed with status ${status}`));
219
- return;
220
- }
221
- const contentType = String(response.headers["content-type"] || "").toLowerCase();
222
- if (!/^application\/(?:json|[a-z0-9.+-]+\+json)(?:\s*;|$)/.test(contentType)) {
223
- response.resume();
224
- reject(new Error("HTTPS snapshot response must use an application/json content type"));
225
- return;
226
- }
227
- const encoding = String(response.headers["content-encoding"] || "identity").toLowerCase();
228
- if (encoding !== "identity") {
229
- response.resume();
230
- reject(new Error("compressed HTTPS snapshots are rejected to keep byte limits exact"));
231
- return;
232
- }
233
- const declared = Number(response.headers["content-length"] || 0);
234
- if (declared && (!Number.isSafeInteger(declared) || declared > MAX_SNAPSHOT_BYTES)) {
235
- response.resume();
236
- reject(new Error("HTTPS snapshot exceeds the 21 MiB response limit"));
237
- return;
238
- }
239
- const chunks = [];
240
- let bytes = 0;
241
- response.on("data", (chunk) => {
242
- bytes += chunk.length;
243
- if (bytes > MAX_SNAPSHOT_BYTES) {
244
- active.destroy(new Error("HTTPS snapshot exceeds the 21 MiB response limit"));
245
- return;
246
- }
247
- chunks.push(chunk);
248
- });
249
- response.on("end", () => resolve(Buffer.concat(chunks)));
250
- response.on("error", reject);
251
- });
252
- active.setTimeout(timeoutMs, () => active.destroy(new Error("HTTPS snapshot request timed out")));
253
- deadline = setTimeout(() => active.destroy(new Error("HTTPS snapshot request timed out")), timeoutMs);
254
- active.on("error", reject);
255
- active.end();
256
- });
257
- let snapshot;
258
- try {
259
- snapshot = JSON.parse(body.toString("utf8"));
260
- } catch {
261
- throw new Error("HTTPS snapshot response is not valid JSON");
262
- }
263
- return {
264
- snapshot: validateHttpsSnapshot(snapshot),
265
- endpoint: `${resolved.endpoint.origin}${resolved.endpoint.pathname}`,
266
- authenticatedRequest: Boolean(token)
267
- };
268
- }
269
-
270
- export function validateHttpsSnapshot(snapshot) {
271
- if (!exactKeys(snapshot, [
272
- "schema", "snapshotId", "scopeId", "adapterId", "generatedAt",
273
- "manifest", "events", "authority", "digest"
274
- ]) || snapshot.schema !== SCHEMA || !ID_RE.test(snapshot.snapshotId || "")
275
- || !ID_RE.test(snapshot.scopeId || "") || !ID_RE.test(snapshot.adapterId || "")
276
- || !validDate(snapshot.generatedAt) || snapshot.authority !== "context-only"
277
- || !DIGEST_RE.test(snapshot.digest || "") || digest(withoutDigest(snapshot)) !== snapshot.digest
278
- || !Array.isArray(snapshot.events) || snapshot.events.length > MAX_EVENTS) {
279
- throw new Error("HTTPS snapshot is invalid or has failed its integrity check");
280
- }
281
- if (Buffer.byteLength(JSON.stringify(snapshot)) > MAX_SNAPSHOT_BYTES) {
282
- throw new Error("HTTPS snapshot exceeds the 21 MiB validation limit");
283
- }
284
- const verifiedManifest = verifyEnvelope(snapshot.manifest, "manifest");
285
- if (verifiedManifest.payload?.scopeId !== snapshot.scopeId
286
- || verifiedManifest.payload?.adapterId !== snapshot.adapterId
287
- || verifiedManifest.payload?.adapter !== "directory") {
288
- throw new Error("HTTPS snapshot metadata does not match its signed manifest");
289
- }
290
- const seen = new Map();
291
- for (const document of snapshot.events) {
292
- const verified = verifyEnvelope(document, "event");
293
- const event = validateSharedEvent(verified.payload, snapshot.scopeId);
294
- const previous = seen.get(event.id);
295
- if (previous && previous !== event.digest) throw new Error(`HTTPS snapshot event ID collision: ${event.id}`);
296
- if (previous) throw new Error(`HTTPS snapshot contains duplicate event: ${event.id}`);
297
- seen.set(event.id, event.digest);
298
- }
299
- return snapshot;
300
- }
301
-
302
- export async function buildHttpsSnapshot({
303
- root = process.cwd(), directory, snapshotId = `snapshot:${randomUUID()}`, now = new Date()
304
- }) {
305
- if (!ID_RE.test(snapshotId || "")) throw new Error("snapshotId must be a stable, whitespace-free identifier");
306
- const exchange = await readDirectoryExchange({ root, directory, requireAuthenticated: true });
307
- const generatedAt = new Date(now).toISOString();
308
- if (!validDate(generatedAt)) throw new Error("now must be a valid date");
309
- const body = {
310
- schema: SCHEMA, snapshotId, scopeId: exchange.scopeId, adapterId: exchange.adapterId,
311
- generatedAt, manifest: exchange.manifest, events: exchange.events,
312
- authority: "context-only"
313
- };
314
- return validateHttpsSnapshot({ ...body, digest: digest(body) });
315
- }
316
-
317
- export async function exportHttpsSnapshot({
318
- root = process.cwd(), directory, output, snapshotId = `snapshot:${randomUUID()}`,
319
- confirmation, now = new Date()
320
- }) {
321
- if (confirmation !== CONFIRMATION) throw new Error("HTTPS snapshot export requires explicit local owner confirmation");
322
- if (!output || typeof output !== "string") throw new Error("HTTPS snapshot output path is required");
323
- const snapshot = await buildHttpsSnapshot({ root, directory, snapshotId, now });
324
- const catalog = await buildCatalog(root);
325
- const target = resolve(output);
326
- const prospectiveTarget = await prospectiveCanonicalPath(target);
327
- if (isInside(catalog.root, prospectiveTarget)) {
328
- throw new Error("HTTPS snapshot output must remain outside the scanned project");
329
- }
330
- let parent = dirname(target);
331
- await mkdir(parent, { recursive: true, mode: 0o700 });
332
- parent = await realpath(parent);
333
- if (isInside(catalog.root, parent)) {
334
- throw new Error("HTTPS snapshot output must remain outside the scanned project");
335
- }
336
- try {
337
- await lstat(target);
338
- throw new Error("HTTPS snapshot output already exists; choose a new path");
339
- } catch (error) {
340
- if (error.code !== "ENOENT") throw error;
341
- }
342
- const content = `${JSON.stringify(snapshot, null, 2)}\n`;
343
- if (Buffer.byteLength(content) > MAX_SNAPSHOT_BYTES) throw new Error("HTTPS snapshot exceeds the 21 MiB export limit");
344
- const handle = await open(target, "wx", 0o600);
345
- try {
346
- await handle.writeFile(content, "utf8");
347
- await handle.sync();
348
- } finally {
349
- await handle.close();
350
- }
351
- return {
352
- created: true, output: target, snapshotId: snapshot.snapshotId,
353
- scopeId: snapshot.scopeId, adapterId: snapshot.adapterId,
354
- events: snapshot.events.length, digest: snapshot.digest,
355
- authority: "context-only"
356
- };
357
- }
358
-
359
- export async function importHttpsSnapshot({ root = process.cwd(), snapshot, now = new Date() }) {
360
- const validated = validateHttpsSnapshot(structuredClone(snapshot));
361
- const directory = await mkdtemp(join(tmpdir(), "agentspine-https-snapshot-"));
362
- try {
363
- const eventsDirectory = join(directory, "events");
364
- await mkdir(eventsDirectory, { mode: 0o700 });
365
- await writeFile(
366
- join(directory, ".agentspine-exchange.json"),
367
- `${JSON.stringify(validated.manifest, null, 2)}\n`, { mode: 0o600 }
368
- );
369
- for (const document of validated.events) {
370
- const id = eventId(document);
371
- await writeFile(join(eventsDirectory, eventFilename(id)), `${JSON.stringify(document, null, 2)}\n`, {
372
- mode: 0o600, flag: "wx"
373
- });
374
- }
375
- const result = await pullShared({ root, directory, requireAuthenticated: true, now });
376
- return {
377
- ...result, transport: "https-snapshot", snapshotId: validated.snapshotId,
378
- snapshotDigest: validated.digest, authority: "context-only"
379
- };
380
- } finally {
381
- await rm(directory, { recursive: true, force: true });
382
- }
383
- }
384
-
385
- export async function pullHttpsSnapshot(options) {
386
- const fetched = await fetchHttpsSnapshot(options);
387
- const imported = await importHttpsSnapshot({ root: options.root, snapshot: fetched.snapshot, now: options.now });
388
- return {
389
- ...imported, endpoint: fetched.endpoint,
390
- authenticatedRequest: fetched.authenticatedRequest
391
- };
392
- }