blun-king-cli 9.1.643 → 9.1.645

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