blun-king-cli 9.1.643 → 9.1.644

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (266) hide show
  1. package/LIESMICH.txt +18 -0
  2. package/README.md +20 -6
  3. package/bin/blun.js +3 -3
  4. package/bin/king.js +3 -3
  5. package/bin/launcher-mode.js +125 -126
  6. package/bin/launcher-runtime.js +603 -616
  7. package/bin/plugin-bootstrap.js +339 -405
  8. package/bin/rename-private-staging.cjs +2 -2
  9. package/bin/retired-bundled-plugins.cjs +84 -0
  10. package/bin/startup-security-host.cjs +105 -0
  11. package/bin/startup-security.cjs +9 -105
  12. package/bin/startup-warning-policy.cjs +22 -0
  13. package/bin/update-lease-installer.cjs +125 -0
  14. package/bin/update-lease-sockets.cjs +228 -0
  15. package/bin/update-lease.js +22 -327
  16. package/bin/verify-bundled-agent-sources.cjs +2 -4
  17. package/blun.mjs +18 -179
  18. package/bundled-agent-sources.json +1 -552
  19. package/package.json +1 -5
  20. package/tool-liveness642/receipt.json +1 -1
  21. package/worker-host.mjs +3 -119
  22. package/agent-spine-plugin/.claude-plugin/marketplace.json +0 -20
  23. package/agent-spine-plugin/.claude-plugin/plugin.json +0 -14
  24. package/agent-spine-plugin/.codex-plugin/plugin.json +0 -47
  25. package/agent-spine-plugin/.mcp.json +0 -8
  26. package/agent-spine-plugin/CHANGELOG.md +0 -1614
  27. package/agent-spine-plugin/LICENSE +0 -186
  28. package/agent-spine-plugin/README.md +0 -432
  29. package/agent-spine-plugin/assets/agentspine-banner.svg +0 -32
  30. package/agent-spine-plugin/bin/agentspine-mcp.js +0 -4
  31. package/agent-spine-plugin/bin/agentspine.js +0 -7
  32. package/agent-spine-plugin/blun.plugin.json +0 -68
  33. package/agent-spine-plugin/docs/acceptance.md +0 -61
  34. package/agent-spine-plugin/docs/artifact-evaluation.md +0 -93
  35. package/agent-spine-plugin/docs/host-integration.md +0 -193
  36. package/agent-spine-plugin/docs/preflight-recall.md +0 -71
  37. package/agent-spine-plugin/docs/preservation-contract.md +0 -53
  38. package/agent-spine-plugin/docs/quality-gates.md +0 -50
  39. package/agent-spine-plugin/docs/session-timeline.md +0 -112
  40. package/agent-spine-plugin/docs/source-roots.md +0 -113
  41. package/agent-spine-plugin/docs/world-model.md +0 -119
  42. package/agent-spine-plugin/hooks/codex.json +0 -47
  43. package/agent-spine-plugin/hooks/hooks.json +0 -106
  44. package/agent-spine-plugin/hooks/version.json +0 -5
  45. package/agent-spine-plugin/package.json +0 -77
  46. package/agent-spine-plugin/scripts/check-codex-install.js +0 -226
  47. package/agent-spine-plugin/scripts/check-hosts.js +0 -208
  48. package/agent-spine-plugin/scripts/check-install-hook.js +0 -227
  49. package/agent-spine-plugin/scripts/check-install-selfstarter.js +0 -154
  50. package/agent-spine-plugin/scripts/check-install.js +0 -478
  51. package/agent-spine-plugin/scripts/check-line-budget.js +0 -58
  52. package/agent-spine-plugin/scripts/check-syntax.js +0 -29
  53. package/agent-spine-plugin/scripts/github-actions.js +0 -11
  54. package/agent-spine-plugin/scripts/hermetic-process.js +0 -191
  55. package/agent-spine-plugin/scripts/release-check.js +0 -150
  56. package/agent-spine-plugin/scripts/run-acceptance.js +0 -19
  57. package/agent-spine-plugin/scripts/run-checks.js +0 -50
  58. package/agent-spine-plugin/scripts/run-tests-hermetic.js +0 -112
  59. package/agent-spine-plugin/skills/agent-spine/SKILL.md +0 -99
  60. package/agent-spine-plugin/spine-example/1-identity.md +0 -12
  61. package/agent-spine-plugin/spine-example/2-voice.md +0 -6
  62. package/agent-spine-plugin/spine-example/3-conduct.md +0 -8
  63. package/agent-spine-plugin/spine-example/4-history.md +0 -4
  64. package/agent-spine-plugin/src/cli-agent.js +0 -315
  65. package/agent-spine-plugin/src/cli-attention.js +0 -95
  66. package/agent-spine-plugin/src/cli-autonomy.js +0 -36
  67. package/agent-spine-plugin/src/cli-common.js +0 -71
  68. package/agent-spine-plugin/src/cli-continuity.js +0 -116
  69. package/agent-spine-plugin/src/cli-core.js +0 -128
  70. package/agent-spine-plugin/src/cli-diagnostics.js +0 -291
  71. package/agent-spine-plugin/src/cli-host.js +0 -21
  72. package/agent-spine-plugin/src/cli-learning.js +0 -320
  73. package/agent-spine-plugin/src/cli-premortem.js +0 -16
  74. package/agent-spine-plugin/src/cli-sharing.js +0 -230
  75. package/agent-spine-plugin/src/cli.js +0 -181
  76. package/agent-spine-plugin/src/codex-reader-launcher.js +0 -182
  77. package/agent-spine-plugin/src/hook.js +0 -500
  78. package/agent-spine-plugin/src/index.js +0 -108
  79. package/agent-spine-plugin/src/lib/acceptance.js +0 -435
  80. package/agent-spine-plugin/src/lib/action-lesson-recall.js +0 -118
  81. package/agent-spine-plugin/src/lib/attention-context.js +0 -167
  82. package/agent-spine-plugin/src/lib/attention-events.js +0 -113
  83. package/agent-spine-plugin/src/lib/attention-privacy.js +0 -72
  84. package/agent-spine-plugin/src/lib/attention-schema.js +0 -164
  85. package/agent-spine-plugin/src/lib/attention-storage.js +0 -93
  86. package/agent-spine-plugin/src/lib/attention.js +0 -164
  87. package/agent-spine-plugin/src/lib/audit-premortem.js +0 -223
  88. package/agent-spine-plugin/src/lib/audit.js +0 -401
  89. package/agent-spine-plugin/src/lib/authentication.js +0 -515
  90. package/agent-spine-plugin/src/lib/autonomy-policy.js +0 -110
  91. package/agent-spine-plugin/src/lib/autonomy-store.js +0 -202
  92. package/agent-spine-plugin/src/lib/autonomy.js +0 -8
  93. package/agent-spine-plugin/src/lib/briefing.js +0 -493
  94. package/agent-spine-plugin/src/lib/catalog-document-read.js +0 -51
  95. package/agent-spine-plugin/src/lib/catalog.js +0 -167
  96. package/agent-spine-plugin/src/lib/channel-continuity.js +0 -19
  97. package/agent-spine-plugin/src/lib/channel-runtime.js +0 -665
  98. package/agent-spine-plugin/src/lib/codex-installation.js +0 -231
  99. package/agent-spine-plugin/src/lib/codex-skill-installation.js +0 -211
  100. package/agent-spine-plugin/src/lib/context.js +0 -156
  101. package/agent-spine-plugin/src/lib/continuity.js +0 -338
  102. package/agent-spine-plugin/src/lib/coordination.js +0 -577
  103. package/agent-spine-plugin/src/lib/delivery-agent-usage.js +0 -231
  104. package/agent-spine-plugin/src/lib/delivery-assignment.js +0 -220
  105. package/agent-spine-plugin/src/lib/delivery-command-actions.js +0 -462
  106. package/agent-spine-plugin/src/lib/delivery-knowledge.js +0 -78
  107. package/agent-spine-plugin/src/lib/delivery-premortem-binding.js +0 -107
  108. package/agent-spine-plugin/src/lib/delivery-premortem-closure.js +0 -171
  109. package/agent-spine-plugin/src/lib/delivery-premortem-codec.js +0 -45
  110. package/agent-spine-plugin/src/lib/delivery-premortem-correction.js +0 -101
  111. package/agent-spine-plugin/src/lib/delivery-premortem-file.js +0 -21
  112. package/agent-spine-plugin/src/lib/delivery-premortem-index.js +0 -493
  113. package/agent-spine-plugin/src/lib/delivery-premortem-inspection.js +0 -37
  114. package/agent-spine-plugin/src/lib/delivery-premortem-recovery.js +0 -120
  115. package/agent-spine-plugin/src/lib/delivery-premortem-rejection.js +0 -65
  116. package/agent-spine-plugin/src/lib/delivery-premortem-results.js +0 -28
  117. package/agent-spine-plugin/src/lib/delivery-premortem-session-guard.js +0 -46
  118. package/agent-spine-plugin/src/lib/delivery-premortem-write-ledger.js +0 -285
  119. package/agent-spine-plugin/src/lib/delivery-premortem.js +0 -499
  120. package/agent-spine-plugin/src/lib/delivery-shell-heredoc.js +0 -115
  121. package/agent-spine-plugin/src/lib/delivery-shell-substitutions.js +0 -111
  122. package/agent-spine-plugin/src/lib/delivery-shell-wrapper.js +0 -64
  123. package/agent-spine-plugin/src/lib/delivery-target.js +0 -73
  124. package/agent-spine-plugin/src/lib/delivery-verification.js +0 -445
  125. package/agent-spine-plugin/src/lib/documents.js +0 -239
  126. package/agent-spine-plugin/src/lib/feed-transport.js +0 -499
  127. package/agent-spine-plugin/src/lib/filesystem-retry.js +0 -34
  128. package/agent-spine-plugin/src/lib/gateway-common.js +0 -68
  129. package/agent-spine-plugin/src/lib/gateway-control.js +0 -370
  130. package/agent-spine-plugin/src/lib/gateway-delivery.js +0 -103
  131. package/agent-spine-plugin/src/lib/gateway-execution.js +0 -350
  132. package/agent-spine-plugin/src/lib/gateway-group-response.js +0 -128
  133. package/agent-spine-plugin/src/lib/gateway-host-fencing.js +0 -92
  134. package/agent-spine-plugin/src/lib/gateway-host-lifecycle.js +0 -193
  135. package/agent-spine-plugin/src/lib/gateway-inspection.js +0 -85
  136. package/agent-spine-plugin/src/lib/gateway-knowledge.js +0 -129
  137. package/agent-spine-plugin/src/lib/gateway-policy-provenance.js +0 -197
  138. package/agent-spine-plugin/src/lib/gateway-premortem-disposition.js +0 -82
  139. package/agent-spine-plugin/src/lib/gateway-premortem.js +0 -363
  140. package/agent-spine-plugin/src/lib/gateway-prepared-host.js +0 -28
  141. package/agent-spine-plugin/src/lib/gateway-runs.js +0 -345
  142. package/agent-spine-plugin/src/lib/gateway-runtime-identity.js +0 -31
  143. package/agent-spine-plugin/src/lib/gateway-runtime-records.js +0 -21
  144. package/agent-spine-plugin/src/lib/gateway-runtime.js +0 -18
  145. package/agent-spine-plugin/src/lib/gateway-state-transaction.js +0 -356
  146. package/agent-spine-plugin/src/lib/gateway-state.js +0 -344
  147. package/agent-spine-plugin/src/lib/graph.js +0 -337
  148. package/agent-spine-plugin/src/lib/hook-artifact-guards.js +0 -356
  149. package/agent-spine-plugin/src/lib/hook-audit.js +0 -43
  150. package/agent-spine-plugin/src/lib/hook-briefing-use.js +0 -78
  151. package/agent-spine-plugin/src/lib/hook-context.js +0 -441
  152. package/agent-spine-plugin/src/lib/hook-final-message.js +0 -26
  153. package/agent-spine-plugin/src/lib/hook-input.js +0 -27
  154. package/agent-spine-plugin/src/lib/hook-output.js +0 -284
  155. package/agent-spine-plugin/src/lib/hook-premortem.js +0 -257
  156. package/agent-spine-plugin/src/lib/hook-process-advisory.js +0 -36
  157. package/agent-spine-plugin/src/lib/hook-protection.js +0 -95
  158. package/agent-spine-plugin/src/lib/hook-stop-verification.js +0 -84
  159. package/agent-spine-plugin/src/lib/hook-timeline.js +0 -102
  160. package/agent-spine-plugin/src/lib/host-instruction-budget.js +0 -11
  161. package/agent-spine-plugin/src/lib/https-transport.js +0 -392
  162. package/agent-spine-plugin/src/lib/identifier-analysis.js +0 -446
  163. package/agent-spine-plugin/src/lib/indexed-memory-offline.js +0 -40
  164. package/agent-spine-plugin/src/lib/indexed-memory.js +0 -298
  165. package/agent-spine-plugin/src/lib/knowledge-evidence.js +0 -431
  166. package/agent-spine-plugin/src/lib/learning-applications.js +0 -441
  167. package/agent-spine-plugin/src/lib/learning-artifact-evaluator.js +0 -114
  168. package/agent-spine-plugin/src/lib/learning-candidates.js +0 -274
  169. package/agent-spine-plugin/src/lib/learning-context.js +0 -137
  170. package/agent-spine-plugin/src/lib/learning-delivery-contracts.js +0 -310
  171. package/agent-spine-plugin/src/lib/learning-evaluation-contracts.js +0 -350
  172. package/agent-spine-plugin/src/lib/learning-evaluation-registration.js +0 -372
  173. package/agent-spine-plugin/src/lib/learning-evaluation-revocation.js +0 -292
  174. package/agent-spine-plugin/src/lib/learning-evidence-contracts.js +0 -321
  175. package/agent-spine-plugin/src/lib/learning-findings.js +0 -458
  176. package/agent-spine-plugin/src/lib/learning-measurement-contracts.js +0 -285
  177. package/agent-spine-plugin/src/lib/learning-measurements.js +0 -265
  178. package/agent-spine-plugin/src/lib/learning-outcome-contracts.js +0 -165
  179. package/agent-spine-plugin/src/lib/learning-outcomes.js +0 -343
  180. package/agent-spine-plugin/src/lib/learning-reconciliation.js +0 -290
  181. package/agent-spine-plugin/src/lib/learning-retry-contracts.js +0 -188
  182. package/agent-spine-plugin/src/lib/learning-schema.js +0 -229
  183. package/agent-spine-plugin/src/lib/learning-scope-targets.js +0 -424
  184. package/agent-spine-plugin/src/lib/learning-state-upgrade.js +0 -477
  185. package/agent-spine-plugin/src/lib/learning-status-configuration.js +0 -476
  186. package/agent-spine-plugin/src/lib/learning-storage.js +0 -203
  187. package/agent-spine-plugin/src/lib/learning-trial-recovery.js +0 -218
  188. package/agent-spine-plugin/src/lib/learning-validation-contracts.js +0 -375
  189. package/agent-spine-plugin/src/lib/learning-validation-renewal.js +0 -298
  190. package/agent-spine-plugin/src/lib/learning-validation-runtime.js +0 -234
  191. package/agent-spine-plugin/src/lib/learning.js +0 -36
  192. package/agent-spine-plugin/src/lib/lesson-recall-session.js +0 -172
  193. package/agent-spine-plugin/src/lib/mcp-autonomy-tools.js +0 -37
  194. package/agent-spine-plugin/src/lib/mcp-delivery-completion.js +0 -124
  195. package/agent-spine-plugin/src/lib/mcp-delivery-tools.js +0 -45
  196. package/agent-spine-plugin/src/lib/mcp-premortem.js +0 -68
  197. package/agent-spine-plugin/src/lib/mcp-runtime.js +0 -355
  198. package/agent-spine-plugin/src/lib/mcp-source-context.js +0 -61
  199. package/agent-spine-plugin/src/lib/mcp-timeline-tools.js +0 -240
  200. package/agent-spine-plugin/src/lib/mcp-world-tools.js +0 -52
  201. package/agent-spine-plugin/src/lib/object-transport.js +0 -206
  202. package/agent-spine-plugin/src/lib/owned-file-lock.js +0 -182
  203. package/agent-spine-plugin/src/lib/paths.js +0 -109
  204. package/agent-spine-plugin/src/lib/peer-transport.js +0 -283
  205. package/agent-spine-plugin/src/lib/persona-runtime.js +0 -581
  206. package/agent-spine-plugin/src/lib/pre-answer-timeline-recall.js +0 -104
  207. package/agent-spine-plugin/src/lib/preflight-delivery-id.js +0 -27
  208. package/agent-spine-plugin/src/lib/preflight.js +0 -688
  209. package/agent-spine-plugin/src/lib/project-portfolio.js +0 -176
  210. package/agent-spine-plugin/src/lib/runtime.js +0 -13
  211. package/agent-spine-plugin/src/lib/selfstarter-core.js +0 -382
  212. package/agent-spine-plugin/src/lib/selfstarter-jobs.js +0 -149
  213. package/agent-spine-plugin/src/lib/selfstarter-lease.js +0 -204
  214. package/agent-spine-plugin/src/lib/selfstarter-policy.js +0 -90
  215. package/agent-spine-plugin/src/lib/selfstarter-workspace.js +0 -111
  216. package/agent-spine-plugin/src/lib/selfstarter.js +0 -11
  217. package/agent-spine-plugin/src/lib/session-timeline-auth.js +0 -316
  218. package/agent-spine-plugin/src/lib/session-timeline-codex.js +0 -69
  219. package/agent-spine-plugin/src/lib/session-timeline-contract.js +0 -56
  220. package/agent-spine-plugin/src/lib/session-timeline-enrollment-source.js +0 -38
  221. package/agent-spine-plugin/src/lib/session-timeline-enrollment-storage.js +0 -128
  222. package/agent-spine-plugin/src/lib/session-timeline-enrollment-transport.js +0 -15
  223. package/agent-spine-plugin/src/lib/session-timeline-enrollment.js +0 -478
  224. package/agent-spine-plugin/src/lib/session-timeline-event-extract.js +0 -186
  225. package/agent-spine-plugin/src/lib/session-timeline-host-origin.js +0 -73
  226. package/agent-spine-plugin/src/lib/session-timeline-host-receipt.js +0 -117
  227. package/agent-spine-plugin/src/lib/session-timeline-invocation.js +0 -201
  228. package/agent-spine-plugin/src/lib/session-timeline-king.js +0 -93
  229. package/agent-spine-plugin/src/lib/session-timeline-prior.js +0 -57
  230. package/agent-spine-plugin/src/lib/session-timeline-provider.js +0 -36
  231. package/agent-spine-plugin/src/lib/session-timeline-query.js +0 -56
  232. package/agent-spine-plugin/src/lib/session-timeline-results.js +0 -56
  233. package/agent-spine-plugin/src/lib/session-timeline-root.js +0 -11
  234. package/agent-spine-plugin/src/lib/session-timeline-search.js +0 -82
  235. package/agent-spine-plugin/src/lib/session-timeline-sid-acl.js +0 -213
  236. package/agent-spine-plugin/src/lib/session-timeline-source-open.js +0 -30
  237. package/agent-spine-plugin/src/lib/session-timeline-source.js +0 -80
  238. package/agent-spine-plugin/src/lib/session-timeline-state.js +0 -45
  239. package/agent-spine-plugin/src/lib/session-timeline-transport.js +0 -42
  240. package/agent-spine-plugin/src/lib/session-timeline-windows-acl.js +0 -145
  241. package/agent-spine-plugin/src/lib/session-timeline.js +0 -462
  242. package/agent-spine-plugin/src/lib/sharing.js +0 -969
  243. package/agent-spine-plugin/src/lib/source-roots.js +0 -475
  244. package/agent-spine-plugin/src/lib/source-tree-scan.js +0 -178
  245. package/agent-spine-plugin/src/lib/sqlite-transport.js +0 -501
  246. package/agent-spine-plugin/src/lib/task-knowledge-context.js +0 -99
  247. package/agent-spine-plugin/src/lib/telegram-adapter.js +0 -119
  248. package/agent-spine-plugin/src/lib/timeline-continuation-update.js +0 -100
  249. package/agent-spine-plugin/src/lib/timeline-tool-guard.js +0 -225
  250. package/agent-spine-plugin/src/lib/timeline-user-feedback.js +0 -216
  251. package/agent-spine-plugin/src/lib/timeline-world-capture.js +0 -233
  252. package/agent-spine-plugin/src/lib/voice-runtime.js +0 -39
  253. package/agent-spine-plugin/src/lib/world-knowledge.js +0 -306
  254. package/agent-spine-plugin/src/lib/world-model.js +0 -333
  255. package/agent-spine-plugin/src/mcp.js +0 -456
  256. package/agent-spine-plugin/src/version.js +0 -1
  257. package/agent-spine-plugin/src/worker.js +0 -257
  258. package/bin/agentspine-king-goal-inbox.mjs +0 -127
  259. package/bin/agentspine-king-goal-intake.mjs +0 -106
  260. package/bin/agentspine-king-host-runner.mjs +0 -109
  261. package/bin/agentspine-king-snapshot-policy.cjs +0 -80
  262. package/bin/agentspine-king-status-policy.mjs +0 -226
  263. package/bin/agentspine-king-worker-host.mjs +0 -160
  264. package/bin/managed-plugin-selection.cjs +0 -141
  265. package/bin/verify-agent-behavior.cjs +0 -122
  266. package/bin/verify-agent-components.cjs +0 -104
@@ -1,52 +0,0 @@
1
- const stableId = {
2
- type: "string",
3
- pattern: "^[a-z][a-z0-9-]{0,31}:[A-Za-z0-9][A-Za-z0-9._/-]{0,190}$"
4
- };
5
-
6
- const nullableStableId = { anyOf: [stableId, { type: "null" }] };
7
-
8
- export const worldModelTools = [
9
- {
10
- name: "record_world_assertion",
11
- description: "Persist one provenance-bound world, user, relationship, or team assertion outside source files. Optional typed knowledge distinguishes facts, user preferences, decisions, task state, and error lessons. In an authenticated portal task, task-subject knowledge is bound to the gateway's opaque portal/thread route; tool arguments cannot claim that route. Measurements and explicit user feedback become context-only facts; model output remains a proposal. Authority predicates and secret-shaped structured knowledge are rejected.",
12
- inputSchema: {
13
- type: "object", additionalProperties: false,
14
- required: ["id", "subjectId", "predicate", "value", "evidenceKind", "evidenceId", "evidenceDigest", "observedAt"],
15
- properties: {
16
- root: { type: "string" }, id: stableId, subjectId: stableId,
17
- predicate: { type: "string", pattern: "^[a-z][a-z0-9.-]{0,127}$" },
18
- value: {},
19
- evidenceKind: { type: "string", enum: ["objective-measurement", "explicit-user-feedback", "model-suggestion"] },
20
- evidenceId: stableId,
21
- evidenceDigest: { type: "string", pattern: "^[a-f0-9]{64}$" },
22
- knowledgeKind: {
23
- type: "string",
24
- enum: ["fact", "user-preference", "decision", "task-state", "error-lesson"]
25
- },
26
- sessionRef: { type: "string", pattern: "^session-ref:[a-f0-9]{32}$" },
27
- messageRef: stableId,
28
- observedAt: { type: "string", format: "date-time" },
29
- expiresAt: { anyOf: [{ type: "string", format: "date-time" }, { type: "null" }] },
30
- projectId: nullableStableId, groupId: nullableStableId,
31
- privacy: { type: "string", enum: ["private", "shared", "group"] },
32
- supersedes: { type: "array", maxItems: 50, uniqueItems: true, items: stableId },
33
- reason: { type: "string", maxLength: 500 }
34
- }
35
- }
36
- },
37
- {
38
- name: "world_context",
39
- description: "Read privacy-filtered world context. Conflicts, expiry, and suggestions remain separate; continuationTaskId adds bounded, sourced task-relevant knowledge. An authenticated portal process automatically restricts task continuation to its opaque gateway route; route references are not accepted as tool input.",
40
- inputSchema: {
41
- type: "object", additionalProperties: false,
42
- properties: {
43
- root: { type: "string" }, subjectId: nullableStableId,
44
- projectId: nullableStableId, groupId: nullableStableId,
45
- includePrivate: { type: "boolean" }, includeKnowledgeHistory: { type: "boolean" },
46
- continuationTaskId: nullableStableId,
47
- maxItems: { type: "integer", minimum: 1, maximum: 500 },
48
- now: { type: "string", format: "date-time" }
49
- }
50
- }
51
- }
52
- ];
@@ -1,206 +0,0 @@
1
- import { lookup as dnsLookup } from "node:dns/promises";
2
- import { request as httpsRequest } from "node:https";
3
- import { isIP } from "node:net";
4
- import {
5
- buildHttpsSnapshot, fetchHttpsSnapshot, resolveHttpsEndpoint, validateHttpsSnapshot
6
- } from "./https-transport.js";
7
-
8
- const CONFIRMATION = "local-share-confirmed";
9
- const MAX_TOKEN_BYTES = 8192;
10
- const MAX_RESPONSE_BYTES = 16 * 1024;
11
- const TOKEN_ENV_RE = /^[A-Z_][A-Z0-9_]{0,127}$/;
12
- const DIGEST_RE = /^[a-f0-9]{64}$/;
13
-
14
- function bearerToken(tokenEnv, environment) {
15
- if (tokenEnv === null || tokenEnv === undefined) return null;
16
- if (!TOKEN_ENV_RE.test(tokenEnv)) throw new Error("tokenEnv must be an uppercase environment variable name");
17
- const value = environment[tokenEnv];
18
- if (typeof value !== "string" || !value) {
19
- throw new Error(`HTTPS object token environment variable is missing: ${tokenEnv}`);
20
- }
21
- if (Buffer.byteLength(value) > MAX_TOKEN_BYTES || /[\0-\x1f\x7f]/.test(value)) {
22
- throw new Error("HTTPS object bearer token is invalid");
23
- }
24
- return value;
25
- }
26
-
27
- function timeout(value) {
28
- if (!Number.isInteger(value) || value < 1000 || value > 30000) {
29
- throw new Error("HTTPS object timeout must be between 1000 and 30000 milliseconds");
30
- }
31
- return value;
32
- }
33
-
34
- async function within(promise, milliseconds, message) {
35
- let timer;
36
- try {
37
- return await Promise.race([
38
- promise,
39
- new Promise((_resolve, reject) => {
40
- timer = setTimeout(() => reject(new Error(message)), milliseconds);
41
- })
42
- ]);
43
- } finally {
44
- clearTimeout(timer);
45
- }
46
- }
47
-
48
- export function validateHttpsObjectBase(value) {
49
- let endpoint;
50
- try {
51
- endpoint = new URL(value);
52
- } catch {
53
- throw new Error("HTTPS object base URL is invalid");
54
- }
55
- if (endpoint.protocol !== "https:") throw new Error("HTTPS object publishing requires an https:// URL");
56
- if (endpoint.username || endpoint.password) {
57
- throw new Error("credentials must not be embedded in an HTTPS object base URL");
58
- }
59
- if (endpoint.search || endpoint.hash) {
60
- throw new Error("HTTPS object base URLs cannot contain a query or fragment");
61
- }
62
- if (!endpoint.hostname || /%(?:2f|5c)/i.test(endpoint.pathname)) {
63
- throw new Error("HTTPS object base URL contains an ambiguous path");
64
- }
65
- endpoint.pathname = endpoint.pathname.replace(/\/+$/, "");
66
- return endpoint;
67
- }
68
-
69
- export function httpsObjectUrl(baseUrl, snapshotDigest) {
70
- if (!DIGEST_RE.test(snapshotDigest || "")) throw new Error("snapshot digest is invalid");
71
- const endpoint = validateHttpsObjectBase(baseUrl);
72
- endpoint.pathname = `${endpoint.pathname}/objects/${snapshotDigest}.json`;
73
- return endpoint.toString();
74
- }
75
-
76
- async function upload({
77
- url, body, digest, token, timeoutMs, allowPrivateNetwork, lookup, request
78
- }) {
79
- const resolved = await within(
80
- resolveHttpsEndpoint(url, { allowPrivateNetwork, lookup }),
81
- timeoutMs,
82
- "HTTPS object DNS resolution timed out"
83
- );
84
- const selected = resolved.addresses[0];
85
- const headers = {
86
- accept: "application/json",
87
- "accept-encoding": "identity",
88
- "content-length": String(body.length),
89
- "content-type": "application/vnd.agentspine.snapshot+json",
90
- "if-none-match": "*",
91
- "user-agent": "AgentSpine/0.1 HTTPS object transport",
92
- "x-agentspine-digest": `sha256:${digest}`
93
- };
94
- if (token) headers.authorization = `Bearer ${token}`;
95
- return new Promise((resolvePromise, rejectPromise) => {
96
- let deadline;
97
- let settled = false;
98
- const reject = (error) => {
99
- if (settled) return;
100
- settled = true;
101
- clearTimeout(deadline);
102
- rejectPromise(error);
103
- };
104
- const resolve = (value) => {
105
- if (settled) return;
106
- settled = true;
107
- clearTimeout(deadline);
108
- resolvePromise(value);
109
- };
110
- const options = {
111
- protocol: "https:", hostname: resolved.lookupHostname,
112
- port: resolved.endpoint.port || 443,
113
- path: resolved.endpoint.pathname, method: "PUT", headers,
114
- agent: false, autoSelectFamily: false,
115
- servername: isIP(resolved.lookupHostname) ? undefined : resolved.lookupHostname,
116
- lookup: (_hostname, lookupOptions, callback) => {
117
- const family = typeof lookupOptions === "object" && lookupOptions.family
118
- ? Number(lookupOptions.family) : 0;
119
- const usable = family
120
- ? resolved.addresses.find((item) => item.family === family)
121
- : selected;
122
- if (!usable) return callback(new Error("no vetted DNS address matches the requested family"));
123
- return callback(null, usable.address, usable.family);
124
- }
125
- };
126
- const active = request(options, (response) => {
127
- const status = Number(response.statusCode || 0);
128
- if (status >= 300 && status < 400 && status !== 412) {
129
- response.resume();
130
- reject(new Error("HTTPS object redirects are not followed"));
131
- return;
132
- }
133
- const chunks = [];
134
- let bytes = 0;
135
- response.on("data", (chunk) => {
136
- bytes += chunk.length;
137
- if (bytes > MAX_RESPONSE_BYTES) {
138
- active.destroy(new Error("HTTPS object response exceeds the 16 KiB limit"));
139
- return;
140
- }
141
- chunks.push(chunk);
142
- });
143
- response.on("end", () => {
144
- if (![201, 204, 412].includes(status)) {
145
- reject(new Error(`HTTPS object publish failed with status ${status}`));
146
- return;
147
- }
148
- resolve({ status, responseBytes: bytes });
149
- });
150
- response.on("error", reject);
151
- });
152
- active.setTimeout(timeoutMs, () => active.destroy(new Error("HTTPS object publish timed out")));
153
- deadline = setTimeout(() => active.destroy(new Error("HTTPS object publish timed out")), timeoutMs);
154
- active.on("error", reject);
155
- active.end(body);
156
- });
157
- }
158
-
159
- export async function putHttpsSnapshot({
160
- baseUrl, snapshot, tokenEnv = null, timeoutMs = 10000,
161
- allowPrivateNetwork = false, confirmation = null,
162
- environment = process.env, lookup = dnsLookup, request = httpsRequest
163
- }) {
164
- if (confirmation !== CONFIRMATION) {
165
- throw new Error("HTTPS object publishing requires explicit local owner confirmation");
166
- }
167
- timeout(timeoutMs);
168
- const validated = validateHttpsSnapshot(structuredClone(snapshot));
169
- const objectUrl = httpsObjectUrl(baseUrl, validated.digest);
170
- const token = bearerToken(tokenEnv, environment);
171
- const body = Buffer.from(JSON.stringify(validated));
172
- const result = await upload({
173
- url: objectUrl, body, digest: validated.digest, token, timeoutMs,
174
- allowPrivateNetwork, lookup, request
175
- });
176
- const fetched = await fetchHttpsSnapshot({
177
- url: objectUrl, tokenEnv, timeoutMs, allowPrivateNetwork,
178
- confirmation, environment, lookup, request
179
- });
180
- if (fetched.snapshot.digest !== validated.digest) {
181
- throw new Error("HTTPS object read-back does not match the published snapshot");
182
- }
183
- return {
184
- created: result.status !== 412,
185
- alreadyExisted: result.status === 412,
186
- verified: true,
187
- objectUrl,
188
- snapshotId: validated.snapshotId,
189
- snapshotDigest: validated.digest,
190
- scopeId: validated.scopeId,
191
- adapterId: validated.adapterId,
192
- events: validated.events.length,
193
- authenticatedWrite: Boolean(token),
194
- authority: "context-only"
195
- };
196
- }
197
-
198
- export async function publishHttpsSnapshot({
199
- root = process.cwd(), directory, baseUrl, snapshotId, now = new Date(), ...options
200
- }) {
201
- if (options.confirmation !== CONFIRMATION) {
202
- throw new Error("HTTPS object publishing requires explicit local owner confirmation");
203
- }
204
- const snapshot = await buildHttpsSnapshot({ root, directory, snapshotId, now });
205
- return putHttpsSnapshot({ baseUrl, snapshot, ...options });
206
- }
@@ -1,182 +0,0 @@
1
- import { randomUUID } from "node:crypto";
2
- import { open, readFile, stat, unlink, utimes } from "node:fs/promises";
3
- import { isFileLockContention, isTransientLockMetadataError } from "./filesystem-retry.js";
4
-
5
- const LOCK_SCHEMA = "agentspine.owned-file-lock/v1";
6
- const LOCAL_TAILS = new Map();
7
-
8
- function delay(milliseconds) {
9
- return new Promise((resolve) => setTimeout(resolve, milliseconds));
10
- }
11
-
12
- async function serialize(path, task) {
13
- const previous = LOCAL_TAILS.get(path) || Promise.resolve();
14
- let release;
15
- const current = new Promise(resolve => { release = resolve; });
16
- const tail = previous.catch(() => {}).then(() => current);
17
- LOCAL_TAILS.set(path, tail);
18
- await previous.catch(() => {});
19
- try { return await task(); }
20
- finally {
21
- release();
22
- if (LOCAL_TAILS.get(path) === tail) LOCAL_TAILS.delete(path);
23
- }
24
- }
25
-
26
- function lockPayload(token, acquiredAt, leaseMs) {
27
- return {
28
- schema: LOCK_SCHEMA,
29
- token,
30
- acquiredAt,
31
- leaseMs,
32
- authority: "state-coordination-only"
33
- };
34
- }
35
-
36
- async function readOwner(path) {
37
- try {
38
- const value = JSON.parse(await readFile(path, "utf8"));
39
- if (!value || typeof value !== "object" || Array.isArray(value)
40
- || value.schema !== LOCK_SCHEMA || typeof value.token !== "string") return null;
41
- return value;
42
- } catch (error) {
43
- if (error.code === "ENOENT" || error instanceof SyntaxError) return null;
44
- throw error;
45
- }
46
- }
47
-
48
- function sameFile(left, right) {
49
- return left.dev === right.dev && left.ino === right.ino && left.size === right.size
50
- && left.mtimeMs === right.mtimeMs && left.ctimeMs === right.ctimeMs;
51
- }
52
-
53
- async function removeStaleLock(path, staleAfterMs, assertPath = null) {
54
- let before;
55
- try {
56
- await assertPath?.();
57
- before = await stat(path);
58
- } catch (error) {
59
- if (isTransientLockMetadataError(error)) return false;
60
- throw error;
61
- }
62
- if (Date.now() - before.mtimeMs <= staleAfterMs) return false;
63
- await readOwner(path);
64
- let after;
65
- try {
66
- await assertPath?.();
67
- after = await stat(path);
68
- } catch (error) {
69
- if (isTransientLockMetadataError(error)) return false;
70
- throw error;
71
- }
72
- if (!sameFile(before, after) || Date.now() - after.mtimeMs <= staleAfterMs) return false;
73
- try {
74
- await assertPath?.();
75
- await unlink(path);
76
- await assertPath?.();
77
- return true;
78
- } catch (error) {
79
- if (isFileLockContention(error) || isTransientLockMetadataError(error)) return false;
80
- throw error;
81
- }
82
- }
83
-
84
- async function acquire(path, task, {
85
- staleAfterMs = 15000,
86
- heartbeatIntervalMs = 1000,
87
- retryDelayMs = 25,
88
- maxAttempts = 80,
89
- assertPath = null
90
- } = {}) {
91
- if (typeof task !== "function") throw new Error("owned file lock requires a task");
92
- if (!Number.isInteger(staleAfterMs) || staleAfterMs < 50
93
- || !Number.isInteger(heartbeatIntervalMs) || heartbeatIntervalMs < 10
94
- || heartbeatIntervalMs * 3 >= staleAfterMs
95
- || !Number.isInteger(retryDelayMs) || retryDelayMs < 1
96
- || !Number.isInteger(maxAttempts) || maxAttempts < 1) {
97
- throw new Error("owned file lock timing is invalid");
98
- }
99
- const token = randomUUID();
100
- const acquiredAt = new Date().toISOString();
101
- let acquired = false; let recovered = false;
102
- for (let attempt = 0; attempt < maxAttempts; attempt += 1) {
103
- let handle; let created = false;
104
- try {
105
- await assertPath?.();
106
- handle = await open(path, "wx", 0o600);
107
- created = true;
108
- const payload = `${JSON.stringify(lockPayload(token, acquiredAt, staleAfterMs))}\n`;
109
- await handle.writeFile(payload, "utf8");
110
- await assertPath?.();
111
- acquired = true;
112
- break;
113
- } catch (error) {
114
- if (!isFileLockContention(error)) {
115
- if (handle) {
116
- await handle.close();
117
- handle = null;
118
- try {
119
- await assertPath?.();
120
- if (created) await unlink(path);
121
- } catch (cleanupError) {
122
- if (cleanupError.code !== "ENOENT") error.cleanupError = cleanupError;
123
- }
124
- }
125
- throw error;
126
- }
127
- recovered ||= await removeStaleLock(path, staleAfterMs, assertPath);
128
- if (attempt + 1 < maxAttempts) await delay(retryDelayMs);
129
- } finally {
130
- await handle?.close();
131
- }
132
- }
133
- if (!acquired) throw new Error("state is busy; retry shortly");
134
-
135
- let ownershipError = null;
136
- let heartbeat = Promise.resolve();
137
- const assertOwned = async () => {
138
- if (ownershipError) throw ownershipError;
139
- await assertPath?.();
140
- const owner = await readOwner(path);
141
- await assertPath?.();
142
- if (!owner || owner.token !== token) {
143
- ownershipError = new Error("state lock ownership was lost; mutation aborted");
144
- throw ownershipError;
145
- }
146
- };
147
- const renew = async () => {
148
- await assertOwned();
149
- const now = new Date();
150
- await utimes(path, now, now);
151
- await assertPath?.();
152
- };
153
- const timer = setInterval(() => {
154
- heartbeat = heartbeat.then(renew).catch((error) => { ownershipError ||= error; });
155
- }, heartbeatIntervalMs);
156
- timer.unref?.();
157
-
158
- try {
159
- const result = await task({ token, acquiredAt, recovered, assertOwned });
160
- await assertOwned();
161
- return result;
162
- } finally {
163
- clearInterval(timer);
164
- await heartbeat;
165
- const owner = await (async () => {
166
- await assertPath?.();
167
- return readOwner(path);
168
- })().catch(() => null);
169
- if (owner?.token === token) {
170
- await (async () => {
171
- await assertPath?.();
172
- await unlink(path);
173
- })().catch((error) => {
174
- if (error.code !== "ENOENT") throw error;
175
- });
176
- }
177
- }
178
- }
179
-
180
- export function withOwnedFileLock(path, task, options) {
181
- return serialize(path, () => acquire(path, task, options));
182
- }
@@ -1,109 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import { realpathSync } from "node:fs";
3
- import { homedir } from "node:os";
4
- import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
5
- import { lstat, mkdir, realpath } from "node:fs/promises";
6
-
7
- export async function canonicalPath(input = process.cwd()) {
8
- return realpath(resolve(input));
9
- }
10
-
11
- export async function findProjectRoot(input = process.cwd()) {
12
- if (process.env.AGENTSPINE_ROOT) return canonicalPath(process.env.AGENTSPINE_ROOT);
13
- let cursor = await canonicalPath(input);
14
- while (true) {
15
- try {
16
- await lstat(join(cursor, ".git"));
17
- return cursor;
18
- } catch (error) {
19
- if (error.code !== "ENOENT") throw error;
20
- }
21
- const parent = dirname(cursor);
22
- if (parent === cursor) return canonicalPath(input);
23
- cursor = parent;
24
- }
25
- }
26
-
27
- export function isInside(parent, child, pathApi = { relative, isAbsolute, sep }) {
28
- const value = pathApi.relative(parent, child);
29
- return value === "" || (!pathApi.isAbsolute(value) && !value.startsWith(`..${pathApi.sep}`) && value !== "..");
30
- }
31
-
32
- export function ancestorsBetween(root, cwd) {
33
- const result = [];
34
- let cursor = resolve(cwd);
35
- while (isInside(root, cursor)) {
36
- result.push(cursor);
37
- if (cursor === root) break;
38
- const next = dirname(cursor);
39
- if (next === cursor) break;
40
- cursor = next;
41
- }
42
- return result.reverse();
43
- }
44
-
45
- export function stateRoot(env = process.env) {
46
- if (env.AGENTSPINE_STATE_DIR) return resolve(env.AGENTSPINE_STATE_DIR);
47
- if (process.platform === "win32") {
48
- return join(env.LOCALAPPDATA || env.APPDATA || homedir(), "AgentSpine");
49
- }
50
- return join(env.XDG_STATE_HOME || join(homedir(), ".local", "state"), "agentspine");
51
- }
52
-
53
- export function comparablePath(value) {
54
- let cursor = resolve(value);
55
- const missing = [];
56
- let canonical = cursor;
57
- while (true) {
58
- try {
59
- canonical = realpathSync.native(cursor);
60
- break;
61
- } catch (error) {
62
- if (error.code !== "ENOENT") break;
63
- const parent = dirname(cursor);
64
- if (parent === cursor) break;
65
- missing.unshift(basename(cursor));
66
- cursor = parent;
67
- }
68
- }
69
- canonical = join(canonical, ...missing);
70
- return canonical.replace(/[\\/]+$/, "");
71
- }
72
-
73
- function samePath(left, right) {
74
- const normalize = comparablePath;
75
- const a = normalize(left);
76
- const b = normalize(right);
77
- return process.platform === "win32" ? a.toLowerCase() === b.toLowerCase() : a === b;
78
- }
79
-
80
- export function isUserHomeRoot(root, env = process.env) {
81
- const candidates = [homedir(), env.HOME, env.USERPROFILE,
82
- env.HOMEDRIVE && env.HOMEPATH ? `${env.HOMEDRIVE}${env.HOMEPATH}` : null]
83
- .filter((value) => typeof value === "string" && value && isAbsolute(value));
84
- return candidates.some((candidate) => samePath(root, candidate));
85
- }
86
-
87
- export function statePathIsScanExcluded(catalog, path, env = process.env) {
88
- if (!catalog || catalog.schema !== "agentspine.catalog/v1" || typeof path !== "string") return false;
89
- const localStateRoot = stateRoot(env);
90
- const pathBelongsToState = isInside(localStateRoot, path);
91
- const canonicalRoot = comparablePath(catalog.root);
92
- const canonicalStateRoot = comparablePath(localStateRoot);
93
- if (!pathBelongsToState && !isInside(canonicalRoot, comparablePath(path))) return true;
94
- if (pathBelongsToState && !isInside(canonicalRoot, canonicalStateRoot)) return true;
95
- return catalog.scanPolicy?.stateRoot === "excluded"
96
- && isUserHomeRoot(canonicalRoot, env)
97
- && isInside(canonicalRoot, canonicalStateRoot)
98
- && pathBelongsToState;
99
- }
100
-
101
- export function projectId(root) {
102
- return createHash("sha256").update(root).digest("hex").slice(0, 20);
103
- }
104
-
105
- export async function projectStateDir(root) {
106
- const target = join(stateRoot(), "projects", projectId(root));
107
- await mkdir(target, { recursive: true, mode: 0o700 });
108
- return target;
109
- }