@amalgm/shell 0.1.164-preview.36072132286 → 0.1.164-preview.36809057014

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 (475) hide show
  1. package/PURPOSE.md +642 -128
  2. package/README.md +10 -8
  3. package/dist/accepted-tail.d.ts +26 -0
  4. package/dist/accepted-tail.js +37 -0
  5. package/dist/accepted-tail.js.map +1 -0
  6. package/dist/agent-execution.d.ts +16 -1
  7. package/dist/agent-execution.js +13 -5
  8. package/dist/agent-execution.js.map +1 -1
  9. package/dist/apply-cleanup.d.ts +28 -0
  10. package/dist/apply-cleanup.js +166 -0
  11. package/dist/apply-cleanup.js.map +1 -0
  12. package/dist/apply-recovery.d.ts +47 -0
  13. package/dist/apply-recovery.js +99 -0
  14. package/dist/apply-recovery.js.map +1 -0
  15. package/dist/apply-rows.d.ts +72 -0
  16. package/dist/apply-rows.js +150 -0
  17. package/dist/apply-rows.js.map +1 -0
  18. package/dist/apply-saves.d.ts +85 -0
  19. package/dist/apply-saves.js +238 -0
  20. package/dist/apply-saves.js.map +1 -0
  21. package/dist/boot.js +2 -1
  22. package/dist/boot.js.map +1 -1
  23. package/dist/capture-work.d.ts +8 -0
  24. package/dist/capture-work.js +67 -0
  25. package/dist/capture-work.js.map +1 -0
  26. package/dist/cargo-group.d.ts +45 -0
  27. package/dist/cargo-group.js +88 -0
  28. package/dist/cargo-group.js.map +1 -0
  29. package/dist/channel-session.d.ts +4 -2
  30. package/dist/channel-session.js +4 -3
  31. package/dist/channel-session.js.map +1 -1
  32. package/dist/chat-composition.d.ts +2 -0
  33. package/dist/chat-composition.js +1 -0
  34. package/dist/chat-composition.js.map +1 -1
  35. package/dist/cli.js +20 -1
  36. package/dist/cli.js.map +1 -1
  37. package/dist/construct-apply-host.d.ts +4 -2
  38. package/dist/construct-apply-host.js +8 -3
  39. package/dist/construct-apply-host.js.map +1 -1
  40. package/dist/construct-door.js +1 -1
  41. package/dist/construct-door.js.map +1 -1
  42. package/dist/construct-ledger.d.ts +6 -1
  43. package/dist/construct-ledger.js +21 -33
  44. package/dist/construct-ledger.js.map +1 -1
  45. package/dist/content-cache-collection.d.ts +18 -0
  46. package/dist/content-cache-collection.js +99 -0
  47. package/dist/content-cache-collection.js.map +1 -0
  48. package/dist/content-cache-host.d.ts +83 -17
  49. package/dist/content-cache-host.js +335 -95
  50. package/dist/content-cache-host.js.map +1 -1
  51. package/dist/content-cache-namespace.d.ts +59 -0
  52. package/dist/content-cache-namespace.js +210 -0
  53. package/dist/content-cache-namespace.js.map +1 -0
  54. package/dist/content-cache-ownership.d.ts +13 -0
  55. package/dist/content-cache-ownership.js +75 -0
  56. package/dist/content-cache-ownership.js.map +1 -0
  57. package/dist/content-cache-retention.d.ts +23 -0
  58. package/dist/content-cache-retention.js +195 -0
  59. package/dist/content-cache-retention.js.map +1 -0
  60. package/dist/content-capture-pool.d.ts +287 -0
  61. package/dist/content-capture-pool.js +461 -0
  62. package/dist/content-capture-pool.js.map +1 -0
  63. package/dist/content-capture-worker.d.ts +8 -0
  64. package/dist/content-capture-worker.js +109 -0
  65. package/dist/content-capture-worker.js.map +1 -0
  66. package/dist/content-clock.d.ts +42 -0
  67. package/dist/content-clock.js +166 -0
  68. package/dist/content-clock.js.map +1 -0
  69. package/dist/content-direct.d.ts +2 -0
  70. package/dist/content-direct.js +12 -0
  71. package/dist/content-direct.js.map +1 -1
  72. package/dist/content-failure.d.ts +18 -0
  73. package/dist/content-failure.js +38 -0
  74. package/dist/content-failure.js.map +1 -0
  75. package/dist/content-stream-thread.d.ts +60 -0
  76. package/dist/content-stream-thread.js +95 -0
  77. package/dist/content-stream-thread.js.map +1 -0
  78. package/dist/content-stream-worker.d.ts +7 -0
  79. package/dist/content-stream-worker.js +52 -0
  80. package/dist/content-stream-worker.js.map +1 -0
  81. package/dist/declaration-absorption.d.ts +37 -0
  82. package/dist/declaration-absorption.js +119 -0
  83. package/dist/declaration-absorption.js.map +1 -0
  84. package/dist/declaration-chain.d.ts +36 -0
  85. package/dist/declaration-chain.js +96 -0
  86. package/dist/declaration-chain.js.map +1 -0
  87. package/dist/declaration-commit.d.ts +31 -0
  88. package/dist/declaration-commit.js +49 -0
  89. package/dist/declaration-commit.js.map +1 -0
  90. package/dist/declaration-hold.d.ts +22 -0
  91. package/dist/declaration-hold.js +24 -0
  92. package/dist/declaration-hold.js.map +1 -0
  93. package/dist/declaration-journal.d.ts +62 -0
  94. package/dist/declaration-journal.js +99 -0
  95. package/dist/declaration-journal.js.map +1 -0
  96. package/dist/declaration-save.d.ts +31 -0
  97. package/dist/declaration-save.js +134 -0
  98. package/dist/declaration-save.js.map +1 -0
  99. package/dist/detection/accepted-result.d.ts +19 -1
  100. package/dist/detection/accepted-result.js +36 -5
  101. package/dist/detection/accepted-result.js.map +1 -1
  102. package/dist/detection/admission-save.d.ts +55 -0
  103. package/dist/detection/admission-save.js +48 -0
  104. package/dist/detection/admission-save.js.map +1 -0
  105. package/dist/detection/admission-units.d.ts +66 -0
  106. package/dist/detection/admission-units.js +322 -0
  107. package/dist/detection/admission-units.js.map +1 -0
  108. package/dist/detection/alias-discovery.d.ts +12 -0
  109. package/dist/detection/alias-discovery.js +80 -0
  110. package/dist/detection/alias-discovery.js.map +1 -0
  111. package/dist/detection/alias-examination.d.ts +30 -0
  112. package/dist/detection/alias-examination.js +49 -0
  113. package/dist/detection/alias-examination.js.map +1 -0
  114. package/dist/detection/apply-ownership.d.ts +81 -0
  115. package/dist/detection/apply-ownership.js +232 -0
  116. package/dist/detection/apply-ownership.js.map +1 -0
  117. package/dist/detection/basis-advanced.d.ts +11 -0
  118. package/dist/detection/basis-advanced.js +26 -0
  119. package/dist/detection/basis-advanced.js.map +1 -0
  120. package/dist/detection/capture-outcome.d.ts +16 -0
  121. package/dist/detection/capture-outcome.js +92 -0
  122. package/dist/detection/capture-outcome.js.map +1 -0
  123. package/dist/detection/container-membership.d.ts +32 -0
  124. package/dist/detection/container-membership.js +49 -0
  125. package/dist/detection/container-membership.js.map +1 -0
  126. package/dist/detection/detect-cancelled.d.ts +6 -0
  127. package/dist/detection/detect-cancelled.js +10 -0
  128. package/dist/detection/detect-cancelled.js.map +1 -0
  129. package/dist/detection/directory-proof.d.ts +47 -0
  130. package/dist/detection/directory-proof.js +77 -0
  131. package/dist/detection/directory-proof.js.map +1 -0
  132. package/dist/detection/disposition-rows.d.ts +18 -0
  133. package/dist/detection/disposition-rows.js +29 -0
  134. package/dist/detection/disposition-rows.js.map +1 -0
  135. package/dist/detection/dispositions.d.ts +130 -0
  136. package/dist/detection/dispositions.js +248 -0
  137. package/dist/detection/dispositions.js.map +1 -0
  138. package/dist/detection/git-notice.d.ts +88 -0
  139. package/dist/detection/git-notice.js +444 -0
  140. package/dist/detection/git-notice.js.map +1 -0
  141. package/dist/detection/ground-proof.d.ts +130 -0
  142. package/dist/detection/ground-proof.js +274 -0
  143. package/dist/detection/ground-proof.js.map +1 -0
  144. package/dist/detection/ground-reader.d.ts +29 -0
  145. package/dist/detection/ground-reader.js +102 -0
  146. package/dist/detection/ground-reader.js.map +1 -0
  147. package/dist/detection/held-territory.d.ts +51 -0
  148. package/dist/detection/held-territory.js +205 -0
  149. package/dist/detection/held-territory.js.map +1 -0
  150. package/dist/detection/identity-discovery.d.ts +45 -0
  151. package/dist/detection/identity-discovery.js +287 -0
  152. package/dist/detection/identity-discovery.js.map +1 -0
  153. package/dist/detection/maintenance-sweep.d.ts +108 -0
  154. package/dist/detection/maintenance-sweep.js +325 -0
  155. package/dist/detection/maintenance-sweep.js.map +1 -0
  156. package/dist/detection/name-reach.d.ts +12 -0
  157. package/dist/detection/name-reach.js +28 -0
  158. package/dist/detection/name-reach.js.map +1 -0
  159. package/dist/detection/notebook-basis.d.ts +5 -7
  160. package/dist/detection/notebook-basis.js +6 -7
  161. package/dist/detection/notebook-basis.js.map +1 -1
  162. package/dist/detection/owed-selection.d.ts +51 -0
  163. package/dist/detection/owed-selection.js +169 -0
  164. package/dist/detection/owed-selection.js.map +1 -0
  165. package/dist/detection/portable.d.ts +34 -34
  166. package/dist/detection/portable.js +67 -93
  167. package/dist/detection/portable.js.map +1 -1
  168. package/dist/detection/reconciliation-coverage.d.ts +7 -0
  169. package/dist/detection/reconciliation-coverage.js +16 -0
  170. package/dist/detection/reconciliation-coverage.js.map +1 -0
  171. package/dist/detection/repository-publication.d.ts +20 -0
  172. package/dist/detection/repository-publication.js +79 -0
  173. package/dist/detection/repository-publication.js.map +1 -0
  174. package/dist/detection/repository-routes.d.ts +43 -0
  175. package/dist/detection/repository-routes.js +97 -0
  176. package/dist/detection/repository-routes.js.map +1 -0
  177. package/dist/detection/root-examination.d.ts +94 -0
  178. package/dist/detection/root-examination.js +523 -0
  179. package/dist/detection/root-examination.js.map +1 -0
  180. package/dist/detection/runtime.d.ts +131 -64
  181. package/dist/detection/runtime.js +808 -1103
  182. package/dist/detection/runtime.js.map +1 -1
  183. package/dist/detection/scoped-identity-port.d.ts +34 -0
  184. package/dist/detection/scoped-identity-port.js +81 -0
  185. package/dist/detection/scoped-identity-port.js.map +1 -0
  186. package/dist/detection/seal-law.d.ts +66 -0
  187. package/dist/detection/seal-law.js +116 -0
  188. package/dist/detection/seal-law.js.map +1 -0
  189. package/dist/detection/sharing-policy.d.ts +11 -0
  190. package/dist/detection/sharing-policy.js +32 -0
  191. package/dist/detection/sharing-policy.js.map +1 -0
  192. package/dist/detection/thread-database.d.ts +4 -0
  193. package/dist/detection/thread-database.js +30 -0
  194. package/dist/detection/thread-database.js.map +1 -0
  195. package/dist/detection/unreadable.d.ts +11 -0
  196. package/dist/detection/unreadable.js +9 -0
  197. package/dist/detection/unreadable.js.map +1 -0
  198. package/dist/detection/verified-content.d.ts +6 -0
  199. package/dist/detection/verified-content.js +12 -0
  200. package/dist/detection/verified-content.js.map +1 -0
  201. package/dist/detection/walk-law.d.ts +34 -0
  202. package/dist/detection/walk-law.js +55 -0
  203. package/dist/detection/walk-law.js.map +1 -0
  204. package/dist/development/fly-guest.js +2 -1
  205. package/dist/development/fly-guest.js.map +1 -1
  206. package/dist/entity-apply-host.d.ts +29 -13
  207. package/dist/entity-apply-host.js +1426 -461
  208. package/dist/entity-apply-host.js.map +1 -1
  209. package/dist/entity-apply-store.d.ts +77 -30
  210. package/dist/entity-apply-store.js +221 -516
  211. package/dist/entity-apply-store.js.map +1 -1
  212. package/dist/entity-record-observability.js +2 -0
  213. package/dist/entity-record-observability.js.map +1 -1
  214. package/dist/entity-record-saves.d.ts +20 -0
  215. package/dist/entity-record-saves.js +91 -0
  216. package/dist/entity-record-saves.js.map +1 -0
  217. package/dist/entity-record-store.d.ts +15 -7
  218. package/dist/entity-record-store.js +57 -117
  219. package/dist/entity-record-store.js.map +1 -1
  220. package/dist/files-register-host.d.ts +22 -3
  221. package/dist/files-register-host.js +70 -31
  222. package/dist/files-register-host.js.map +1 -1
  223. package/dist/filesystem.js +3 -2
  224. package/dist/filesystem.js.map +1 -1
  225. package/dist/git-binding.d.ts +65 -0
  226. package/dist/git-binding.js +220 -0
  227. package/dist/git-binding.js.map +1 -0
  228. package/dist/git-capture.d.ts +39 -0
  229. package/dist/git-capture.js +86 -0
  230. package/dist/git-capture.js.map +1 -0
  231. package/dist/git-card.d.ts +12 -0
  232. package/dist/git-card.js +123 -0
  233. package/dist/git-card.js.map +1 -0
  234. package/dist/git-checkpoint-construction.d.ts +41 -0
  235. package/dist/git-checkpoint-construction.js +96 -0
  236. package/dist/git-checkpoint-construction.js.map +1 -0
  237. package/dist/git-checkpoint-preparation.d.ts +37 -0
  238. package/dist/git-checkpoint-preparation.js +145 -0
  239. package/dist/git-checkpoint-preparation.js.map +1 -0
  240. package/dist/git-command.d.ts +61 -8
  241. package/dist/git-command.js +217 -63
  242. package/dist/git-command.js.map +1 -1
  243. package/dist/git-configuration.d.ts +40 -0
  244. package/dist/git-configuration.js +217 -0
  245. package/dist/git-configuration.js.map +1 -0
  246. package/dist/git-evidence.d.ts +61 -0
  247. package/dist/git-evidence.js +181 -0
  248. package/dist/git-evidence.js.map +1 -0
  249. package/dist/git-index-entries.d.ts +15 -0
  250. package/dist/git-index-entries.js +44 -0
  251. package/dist/git-index-entries.js.map +1 -0
  252. package/dist/git-index-format.d.ts +35 -0
  253. package/dist/git-index-format.js +293 -0
  254. package/dist/git-index-format.js.map +1 -0
  255. package/dist/git-index-witness.d.ts +33 -0
  256. package/dist/git-index-witness.js +69 -0
  257. package/dist/git-index-witness.js.map +1 -0
  258. package/dist/git-literal-host.d.ts +82 -0
  259. package/dist/git-literal-host.js +172 -0
  260. package/dist/git-literal-host.js.map +1 -0
  261. package/dist/git-literal-read.d.ts +88 -0
  262. package/dist/git-literal-read.js +170 -0
  263. package/dist/git-literal-read.js.map +1 -0
  264. package/dist/git-literal-replay.d.ts +33 -0
  265. package/dist/git-literal-replay.js +268 -0
  266. package/dist/git-literal-replay.js.map +1 -0
  267. package/dist/git-native-file.d.ts +42 -0
  268. package/dist/git-native-file.js +145 -0
  269. package/dist/git-native-file.js.map +1 -0
  270. package/dist/git-native-index.d.ts +21 -0
  271. package/dist/git-native-index.js +44 -0
  272. package/dist/git-native-index.js.map +1 -0
  273. package/dist/git-operation-host.d.ts +48 -0
  274. package/dist/git-operation-host.js +127 -0
  275. package/dist/git-operation-host.js.map +1 -0
  276. package/dist/git-private-index.d.ts +11 -0
  277. package/dist/git-private-index.js +42 -0
  278. package/dist/git-private-index.js.map +1 -0
  279. package/dist/git-private-repository.d.ts +4 -0
  280. package/dist/git-private-repository.js +69 -0
  281. package/dist/git-private-repository.js.map +1 -0
  282. package/dist/git-private-view.d.ts +39 -0
  283. package/dist/git-private-view.js +162 -0
  284. package/dist/git-private-view.js.map +1 -0
  285. package/dist/git-ref-store.d.ts +12 -0
  286. package/dist/git-ref-store.js +68 -0
  287. package/dist/git-ref-store.js.map +1 -0
  288. package/dist/git-registration-host.d.ts +20 -30
  289. package/dist/git-registration-host.js +86 -249
  290. package/dist/git-registration-host.js.map +1 -1
  291. package/dist/git-repository-host.d.ts +148 -22
  292. package/dist/git-repository-host.js +633 -650
  293. package/dist/git-repository-host.js.map +1 -1
  294. package/dist/git-worktree-host.d.ts +2 -0
  295. package/dist/git-worktree-host.js +16 -0
  296. package/dist/git-worktree-host.js.map +1 -0
  297. package/dist/graph-publication.d.ts +75 -0
  298. package/dist/graph-publication.js +203 -0
  299. package/dist/graph-publication.js.map +1 -0
  300. package/dist/ground-basis.d.ts +242 -0
  301. package/dist/ground-basis.js +1023 -0
  302. package/dist/ground-basis.js.map +1 -0
  303. package/dist/ground-checkpoint-worker.d.ts +1 -0
  304. package/dist/ground-checkpoint-worker.js +84 -0
  305. package/dist/ground-checkpoint-worker.js.map +1 -0
  306. package/dist/ground-checkpoints.d.ts +16 -0
  307. package/dist/ground-checkpoints.js +45 -0
  308. package/dist/ground-checkpoints.js.map +1 -0
  309. package/dist/ground-coordination.d.ts +107 -3
  310. package/dist/ground-coordination.js +249 -24
  311. package/dist/ground-coordination.js.map +1 -1
  312. package/dist/ground-database.d.ts +42 -0
  313. package/dist/ground-database.js +290 -0
  314. package/dist/ground-database.js.map +1 -0
  315. package/dist/ground-differences.d.ts +23 -0
  316. package/dist/ground-differences.js +47 -0
  317. package/dist/ground-differences.js.map +1 -0
  318. package/dist/ground-holders.d.ts +4 -0
  319. package/dist/ground-holders.js +15 -0
  320. package/dist/ground-holders.js.map +1 -0
  321. package/dist/ground-initialization-worker.d.ts +1 -0
  322. package/dist/ground-initialization-worker.js +20 -0
  323. package/dist/ground-initialization-worker.js.map +1 -0
  324. package/dist/ground-initialization.d.ts +35 -0
  325. package/dist/ground-initialization.js +102 -0
  326. package/dist/ground-initialization.js.map +1 -0
  327. package/dist/ground-install-saves.d.ts +63 -0
  328. package/dist/ground-install-saves.js +139 -0
  329. package/dist/ground-install-saves.js.map +1 -0
  330. package/dist/ground-inventory-schema.d.ts +18 -0
  331. package/dist/ground-inventory-schema.js +168 -0
  332. package/dist/ground-inventory-schema.js.map +1 -0
  333. package/dist/ground-profile.d.ts +7 -0
  334. package/dist/ground-profile.js +52 -0
  335. package/dist/ground-profile.js.map +1 -0
  336. package/dist/ground-root-index.d.ts +2 -1
  337. package/dist/ground-root-index.js +16 -14
  338. package/dist/ground-root-index.js.map +1 -1
  339. package/dist/ground-row.d.ts +62 -0
  340. package/dist/ground-row.js +70 -0
  341. package/dist/ground-row.js.map +1 -0
  342. package/dist/ground-save-ops.d.ts +44 -0
  343. package/dist/ground-save-ops.js +41 -0
  344. package/dist/ground-save-ops.js.map +1 -0
  345. package/dist/ground-saver-worker.d.ts +1 -0
  346. package/dist/ground-saver-worker.js +156 -0
  347. package/dist/ground-saver-worker.js.map +1 -0
  348. package/dist/ground-saver.d.ts +75 -0
  349. package/dist/ground-saver.js +216 -0
  350. package/dist/ground-saver.js.map +1 -0
  351. package/dist/ground-store.d.ts +84 -0
  352. package/dist/ground-store.js +473 -0
  353. package/dist/ground-store.js.map +1 -0
  354. package/dist/ground-territory.d.ts +130 -0
  355. package/dist/ground-territory.js +511 -0
  356. package/dist/ground-territory.js.map +1 -0
  357. package/dist/index.d.ts +1 -1
  358. package/dist/index.js.map +1 -1
  359. package/dist/installation/ownership.d.ts +0 -2
  360. package/dist/installation/ownership.js +3 -15
  361. package/dist/installation/ownership.js.map +1 -1
  362. package/dist/machine-host.d.ts +3 -2
  363. package/dist/machine-host.js +28 -16
  364. package/dist/machine-host.js.map +1 -1
  365. package/dist/materialized-graph.d.ts +7 -7
  366. package/dist/materialized-graph.js +11 -23
  367. package/dist/materialized-graph.js.map +1 -1
  368. package/dist/module-thread.d.ts +9 -0
  369. package/dist/module-thread.js +10 -0
  370. package/dist/module-thread.js.map +1 -0
  371. package/dist/native/fsevents-stream.node +0 -0
  372. package/dist/physical-path-witness.d.ts +64 -0
  373. package/dist/physical-path-witness.js +168 -0
  374. package/dist/physical-path-witness.js.map +1 -0
  375. package/dist/register-upload-fusion.d.ts +5 -4
  376. package/dist/register-upload-fusion.js +9 -6
  377. package/dist/register-upload-fusion.js.map +1 -1
  378. package/dist/registry-graph.d.ts +3 -2
  379. package/dist/registry-graph.js +9 -6
  380. package/dist/registry-graph.js.map +1 -1
  381. package/dist/registry-page-cache.d.ts +5 -2
  382. package/dist/registry-page-cache.js.map +1 -1
  383. package/dist/repository-identity-steps.d.ts +5 -0
  384. package/dist/repository-identity-steps.js +33 -0
  385. package/dist/repository-identity-steps.js.map +1 -0
  386. package/dist/runtime-node-flags.d.ts +10 -0
  387. package/dist/runtime-node-flags.js +11 -0
  388. package/dist/runtime-node-flags.js.map +1 -0
  389. package/dist/service/adapter.d.ts +1 -1
  390. package/dist/service/adapter.js +1 -1
  391. package/dist/service/adapter.js.map +1 -1
  392. package/dist/service/cli.js +16 -20
  393. package/dist/service/cli.js.map +1 -1
  394. package/dist/service/control.d.ts +2 -2
  395. package/dist/service/keepalive.d.ts +4 -11
  396. package/dist/service/keepalive.js +65 -118
  397. package/dist/service/keepalive.js.map +1 -1
  398. package/dist/service/policy.d.ts +36 -0
  399. package/dist/service/policy.js +25 -0
  400. package/dist/service/policy.js.map +1 -0
  401. package/dist/service/portable.d.ts +1 -1
  402. package/dist/service/portable.js +1 -1
  403. package/dist/service/portable.js.map +1 -1
  404. package/dist/service/recovery.d.ts +10 -9
  405. package/dist/service/recovery.js +29 -19
  406. package/dist/service/recovery.js.map +1 -1
  407. package/dist/service/windows-action.d.ts +5 -3
  408. package/dist/service/windows-action.js +6 -9
  409. package/dist/service/windows-action.js.map +1 -1
  410. package/dist/service/windows-task.js +5 -5
  411. package/dist/service/windows-task.js.map +1 -1
  412. package/dist/sharing-admission.d.ts +17 -0
  413. package/dist/sharing-admission.js +128 -0
  414. package/dist/sharing-admission.js.map +1 -0
  415. package/dist/snapshot-delivery-baseline.d.ts +12 -3
  416. package/dist/snapshot-delivery-baseline.js +41 -42
  417. package/dist/snapshot-delivery-baseline.js.map +1 -1
  418. package/dist/source-proof.d.ts +36 -0
  419. package/dist/source-proof.js +70 -0
  420. package/dist/source-proof.js.map +1 -0
  421. package/dist/source-signature.d.ts +56 -0
  422. package/dist/source-signature.js +56 -0
  423. package/dist/source-signature.js.map +1 -0
  424. package/dist/source-witness.d.ts +15 -0
  425. package/dist/source-witness.js +29 -0
  426. package/dist/source-witness.js.map +1 -0
  427. package/dist/sqlite-durability.d.ts +31 -0
  428. package/dist/sqlite-durability.js +28 -0
  429. package/dist/sqlite-durability.js.map +1 -0
  430. package/dist/sqlite.d.ts +8 -2
  431. package/dist/sqlite.js +27 -4
  432. package/dist/sqlite.js.map +1 -1
  433. package/dist/sync-address.d.ts +19 -0
  434. package/dist/sync-address.js +52 -0
  435. package/dist/sync-address.js.map +1 -0
  436. package/dist/sync-setting.d.ts +15 -0
  437. package/dist/sync-setting.js +13 -0
  438. package/dist/sync-setting.js.map +1 -1
  439. package/dist/turns.d.ts +42 -0
  440. package/dist/turns.js +112 -0
  441. package/dist/turns.js.map +1 -0
  442. package/dist/updates/bootstrap.d.ts +53 -7
  443. package/dist/updates/bootstrap.js +224 -137
  444. package/dist/updates/bootstrap.js.map +1 -1
  445. package/dist/updates/controller.d.ts +8 -0
  446. package/dist/updates/controller.js +27 -3
  447. package/dist/updates/controller.js.map +1 -1
  448. package/dist/updates/store.d.ts +3 -0
  449. package/dist/updates/store.js +12 -0
  450. package/dist/updates/store.js.map +1 -1
  451. package/dist/user-ground-host.d.ts +364 -69
  452. package/dist/user-ground-host.js +5231 -3366
  453. package/dist/user-ground-host.js.map +1 -1
  454. package/dist/watching/fsevents.d.ts +52 -1
  455. package/dist/watching/fsevents.js +60 -25
  456. package/dist/watching/fsevents.js.map +1 -1
  457. package/dist/watching/host.d.ts +129 -5
  458. package/dist/watching/host.js +433 -80
  459. package/dist/watching/host.js.map +1 -1
  460. package/dist/watching/index.d.ts +1 -1
  461. package/dist/wire-binary.d.ts +3 -2
  462. package/dist/wire-binary.js +10 -8
  463. package/dist/wire-binary.js.map +1 -1
  464. package/dist/wire-client.d.ts +3 -4
  465. package/dist/wire-client.js +18 -44
  466. package/dist/wire-client.js.map +1 -1
  467. package/dist/wire-outbox.d.ts +34 -0
  468. package/dist/wire-outbox.js +127 -0
  469. package/dist/wire-outbox.js.map +1 -0
  470. package/dist/workspace-host.d.ts +4 -0
  471. package/dist/workspace-host.js +12 -1
  472. package/dist/workspace-host.js.map +1 -1
  473. package/examinations/fixtures/private-wire-authority.js +133 -10
  474. package/npm-shrinkwrap.json +43 -56
  475. package/package.json +26 -13
@@ -1,115 +1,61 @@
1
- /** Persistent SQLite effects for Live's Inbox -> Apply -> Verify rail. */
2
- import { createHash } from "node:crypto";
3
- import { assertApplyIntent, assertRecord, canonicalVersion, decodeAcceptedEntityRecord, membershipHash, portableFileMode, sameRecords, } from "@amalgm/live";
4
- import { ensureSnapshotDeliveryBaselineTable } from "./snapshot-delivery-baseline.js";
5
- const sha256Hex = (input) => createHash("sha256").update(input).digest("hex");
6
- const GROUND_COLUMNS = [
7
- "uuid", "resource_id", "root_uuid", "type", "parent_uuid", "name", "status", "version",
8
- "payload_version", "transport_version", "relative_path", "absolute_path", "device_number",
9
- "inode", "byte_size", "modified_time_ms", "changed_time_ms", "filesystem_mode",
10
- "content_verified_at_ms",
11
- ].join(", ");
12
- const rowValues = (row) => [
13
- row.record.uuid,
14
- row.resourceId,
15
- row.rootUUID,
16
- row.record.type,
17
- row.record.parentUUID,
18
- row.record.name,
19
- row.record.status,
20
- row.record.version,
21
- row.record.payloadVersion,
22
- row.record.transportVersion,
23
- row.relativePath,
24
- row.absolutePath,
25
- row.deviceNumber,
26
- row.inode,
27
- row.byteSize,
28
- row.modifiedTimeMs,
29
- row.changedTimeMs,
30
- row.filesystemMode,
31
- row.contentVerifiedAtMs,
32
- ];
33
- const sameIntent = (left, right) => left.authorityId === right.authorityId
34
- && left.entityId === right.entityId
35
- && left.fromSequence === right.fromSequence
36
- && left.throughSequence === right.throughSequence
37
- && left.targetMutationId === right.targetMutationId
38
- && left.targetState === right.targetState
39
- && left.targetType === right.targetType;
1
+ /** Persistent SQLite effects for Live's Inbox -> Apply -> Verify rail. Reads
2
+ * run on this connection; every write is a save on the ground file's saver
3
+ * thread (apply-saves.ts). */
4
+ import { randomUUID } from "node:crypto";
5
+ import { assertRecord, decodeAcceptedEntityRecord, isConstructType, } from "@amalgm/live";
6
+ import { applyResolution, hasLocalWorkAfter, ownedCleanup, ownPublication, readIntent, readRetirement, recoveryLocation, requireIntent, sameIntent, snapshotHistory, } from "./apply-rows.js";
7
+ import { save } from "./ground-saver.js";
8
+ import { closePhysically, sourceProofs, witnessProof } from "./source-proof.js";
9
+ import { cachedStatement } from "./sqlite.js";
10
+ import { turnBoundary } from "./turns.js";
40
11
  /**
41
12
  * Apply has one persistent database owner. Verify hands this owner the exact
42
- * rows it just proved; completion writes those rows, cursors, Inbox resolution,
43
- * and intent removal in one SQLite transaction.
13
+ * rows it just proved; completion writes those rows, cursors, Inbox resolution
14
+ * and the terminal disposition in one save.
44
15
  */
45
16
  export class EntityApplySqliteStore {
46
17
  #database;
18
+ #file;
47
19
  #now;
48
20
  #onIntentFinished;
21
+ #onAttemptFailed;
22
+ #onOwnPublicationResolved;
49
23
  #isLocallyEligible;
24
+ #holdsOwnPlacement;
50
25
  #verified = new Map();
51
- #candidateEntities;
52
- #state;
53
- #inboxAfter;
54
- #intent;
55
- #intentByEntity;
56
- #authorityForEntity;
57
- #targetRecord;
58
- #localRelevance;
59
- #localWork;
60
- #insertIntent;
61
- #updateIntent;
62
- #deleteIntent;
63
- #resolveInbox;
64
- #upsertState;
65
- #upsertEntity;
66
- #upsertNotebook;
67
- #deleteEntity;
68
- #deleteNotebook;
69
- #entitySlot;
70
- #notebookAtUuid;
71
- #notebookChildren;
72
- #updateEntityVersion;
73
- #updateNotebookVersion;
74
- #materializedMatches;
75
- #resolveMaterializedHistory;
76
- #baselineRows;
77
- #baselineIntents;
78
- #snapshotBaseline;
26
+ #cleanupProof = new Map();
79
27
  constructor(database, options = {}) {
80
28
  this.#database = database;
29
+ this.#file = database.name;
81
30
  this.#now = options.now ?? Date.now;
82
31
  this.#onIntentFinished = options.onIntentFinished ?? (() => undefined);
32
+ this.#onAttemptFailed = options.onAttemptFailed ?? (() => undefined);
33
+ this.#onOwnPublicationResolved = options.onOwnPublicationResolved ?? (() => undefined);
83
34
  this.#isLocallyEligible = options.isLocallyEligible ?? (() => true);
84
- database.pragma("busy_timeout = 5000");
85
- database.pragma("journal_mode = WAL");
86
- database.pragma("synchronous = FULL");
87
- ensureSnapshotDeliveryBaselineTable(database);
88
- database.exec(`
89
- CREATE TABLE IF NOT EXISTS entity_apply_state (
90
- entity_id TEXT PRIMARY KEY,
91
- authority_id TEXT NOT NULL,
92
- resolved_through INTEGER NOT NULL CHECK(resolved_through >= 0),
93
- materialized_sequence INTEGER,
94
- materialized_record_json TEXT,
95
- CHECK((materialized_sequence IS NULL AND materialized_record_json IS NULL)
96
- OR (materialized_sequence > 0 AND materialized_record_json IS NOT NULL))
97
- );
98
- CREATE TABLE IF NOT EXISTS entity_apply_intents (
99
- entity_id TEXT PRIMARY KEY,
100
- authority_id TEXT NOT NULL,
101
- intent_json TEXT NOT NULL
102
- );
103
- CREATE INDEX IF NOT EXISTS record_inbox_apply
104
- ON record_inbox(authority_id, entity_id, global_sequence);
105
- CREATE INDEX IF NOT EXISTS record_inbox_entity_apply
106
- ON record_inbox(entity_id, global_sequence DESC);
107
- `);
108
- const inboxColumns = new Set(database.prepare("PRAGMA table_info(record_inbox)").all().map(({ name }) => name));
109
- if (!inboxColumns.has("resolved_at")) {
110
- database.exec("ALTER TABLE record_inbox ADD COLUMN resolved_at INTEGER");
35
+ this.#holdsOwnPlacement = options.holdsOwnPlacement ?? (() => false);
36
+ }
37
+ /** Only an explicitly installed snapshot watermark resolves startup history.
38
+ * Sharing-baseline equality is never evidence of current disk contents.
39
+ * Any existing physical recovery obligation must survive this adoption. */
40
+ async adoptSnapshotHistory(mayRetire = () => false) {
41
+ const history = snapshotHistory(this.#database);
42
+ const candidates = new Map();
43
+ for (const intent of [...history.intents,
44
+ ...history.rows.flatMap(row => readIntent(this.#database, row.entityId) ?? [])]) {
45
+ if (!readRetirement(this.#database, intent))
46
+ candidates.set(intent.entityId, intent);
47
+ }
48
+ const retirable = [...candidates.values()].filter(intent => mayRetire(intent));
49
+ const { value } = await save(this.#file, "apply.adoptSnapshotHistory", { retirable });
50
+ for (const intent of value.supersededIntents) {
51
+ const staged = this.#verified.get(intent.entityId);
52
+ if (staged && sameIntent(staged.intent, intent))
53
+ this.#verified.delete(intent.entityId);
111
54
  }
112
- this.#candidateEntities = database.prepare(`
55
+ return value;
56
+ }
57
+ readApplyWork(limit, afterCursor) {
58
+ const all = cachedStatement(this.#database, `
113
59
  SELECT entity_id AS entityId FROM entity_apply_intents
114
60
  UNION
115
61
  SELECT inbox.entity_id AS entityId
@@ -117,255 +63,7 @@ export class EntityApplySqliteStore {
117
63
  LEFT JOIN entity_apply_state state ON state.entity_id = inbox.entity_id
118
64
  WHERE inbox.global_sequence > COALESCE(state.resolved_through, 0)
119
65
  ORDER BY entityId
120
- `);
121
- this.#state = database.prepare(`
122
- SELECT resolved_through AS resolvedThrough,
123
- materialized_sequence AS materializedSequence,
124
- materialized_record_json AS materializedRecordJson
125
- FROM entity_apply_state WHERE authority_id = ? AND entity_id = ?
126
- `);
127
- this.#inboxAfter = database.prepare(`
128
- SELECT record_json AS recordJson, delivery_sequence AS deliverySequence
129
- FROM record_inbox
130
- WHERE authority_id = ? AND entity_id = ? AND global_sequence > ?
131
- ORDER BY global_sequence
132
- `);
133
- this.#snapshotBaseline = database.prepare(`
134
- SELECT delivery_sequence AS deliverySequence
135
- FROM authority_snapshot_baselines WHERE authority_id = ?
136
- `);
137
- this.#intent = database.prepare(`
138
- SELECT intent_json AS intentJson FROM entity_apply_intents
139
- WHERE authority_id = ? AND entity_id = ?
140
- `);
141
- this.#intentByEntity = database.prepare(`
142
- SELECT intent_json AS intentJson FROM entity_apply_intents WHERE entity_id = ?
143
- `);
144
- this.#authorityForEntity = database.prepare(`
145
- SELECT authority_id AS authorityId FROM record_inbox
146
- WHERE entity_id = ? ORDER BY global_sequence DESC LIMIT 1
147
- `);
148
- this.#targetRecord = database.prepare(`
149
- SELECT record_json AS recordJson FROM record_inbox
150
- WHERE authority_id = ? AND entity_id = ? AND global_sequence = ?
151
- `);
152
- this.#localRelevance = database.prepare(`
153
- SELECT 1 AS present FROM entities WHERE uuid = ?
154
- UNION ALL
155
- SELECT 1 AS present FROM detection_notebook WHERE uuid = ?
156
- LIMIT 1
157
- `);
158
- this.#localWork = database.prepare(`
159
- SELECT 1 AS present FROM record_outbox
160
- WHERE authority_id = ? AND entity_id = ?
161
- AND (status = 'pending' OR global_sequence > ?)
162
- LIMIT 1
163
- `);
164
- this.#insertIntent = database.prepare(`
165
- INSERT INTO entity_apply_intents(entity_id, authority_id, intent_json)
166
- VALUES (?, ?, ?)
167
- `);
168
- this.#updateIntent = database.prepare(`
169
- UPDATE entity_apply_intents SET intent_json = ?
170
- WHERE authority_id = ? AND entity_id = ?
171
- `);
172
- this.#deleteIntent = database.prepare(`
173
- DELETE FROM entity_apply_intents WHERE authority_id = ? AND entity_id = ?
174
- `);
175
- this.#resolveInbox = database.prepare(`
176
- UPDATE record_inbox SET resolved_at = ?
177
- WHERE authority_id = ? AND entity_id = ?
178
- AND global_sequence > ? AND global_sequence <= ?
179
- `);
180
- this.#upsertState = database.prepare(`
181
- INSERT INTO entity_apply_state(
182
- entity_id, authority_id, resolved_through,
183
- materialized_sequence, materialized_record_json
184
- ) VALUES (?, ?, ?, ?, ?)
185
- ON CONFLICT(entity_id) DO UPDATE SET
186
- authority_id = excluded.authority_id,
187
- resolved_through = excluded.resolved_through,
188
- materialized_sequence = excluded.materialized_sequence,
189
- materialized_record_json = excluded.materialized_record_json
190
- `);
191
- const upsert = (table) => database.prepare(`
192
- INSERT INTO ${table}(${GROUND_COLUMNS})
193
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
194
- ON CONFLICT(uuid) DO UPDATE SET
195
- resource_id = excluded.resource_id,
196
- root_uuid = excluded.root_uuid,
197
- type = excluded.type,
198
- parent_uuid = excluded.parent_uuid,
199
- name = excluded.name,
200
- status = excluded.status,
201
- version = excluded.version,
202
- payload_version = excluded.payload_version,
203
- transport_version = excluded.transport_version,
204
- relative_path = excluded.relative_path,
205
- absolute_path = excluded.absolute_path,
206
- device_number = excluded.device_number,
207
- inode = excluded.inode,
208
- byte_size = excluded.byte_size,
209
- modified_time_ms = excluded.modified_time_ms,
210
- changed_time_ms = excluded.changed_time_ms,
211
- filesystem_mode = excluded.filesystem_mode,
212
- content_verified_at_ms = excluded.content_verified_at_ms
213
- `);
214
- this.#upsertEntity = upsert("entities");
215
- this.#upsertNotebook = upsert("detection_notebook");
216
- this.#deleteEntity = database.prepare("DELETE FROM entities WHERE uuid = ?");
217
- this.#deleteNotebook = database.prepare("DELETE FROM detection_notebook WHERE uuid = ?");
218
- this.#entitySlot = database.prepare(`
219
- SELECT uuid, type, payload_version AS payloadVersion,
220
- absolute_path AS absolutePath FROM entities
221
- WHERE resource_id = ? AND root_uuid = ? AND relative_path = ?
222
- `);
223
- this.#notebookAtUuid = database.prepare(`
224
- SELECT uuid, type, parent_uuid AS parentUUID, name, status
225
- FROM detection_notebook WHERE uuid = ?
226
- `);
227
- this.#notebookChildren = database.prepare(`
228
- SELECT uuid, name FROM detection_notebook
229
- WHERE parent_uuid = ? AND status = 'active' ORDER BY name, uuid
230
- `);
231
- this.#updateEntityVersion = database.prepare("UPDATE entities SET version = ? WHERE uuid = ?");
232
- this.#updateNotebookVersion = database.prepare("UPDATE detection_notebook SET version = ? WHERE uuid = ?");
233
- this.#materializedMatches = database.prepare(`
234
- SELECT inbox.authority_id AS authorityId,
235
- inbox.entity_id AS entityId,
236
- inbox.global_sequence AS globalSequence,
237
- inbox.record_json AS recordJson,
238
- intent.intent_json AS intentJson,
239
- notebook.type,
240
- notebook.parent_uuid AS parentUUID,
241
- notebook.name,
242
- notebook.status,
243
- notebook.version,
244
- notebook.payload_version AS payloadVersion,
245
- notebook.filesystem_mode AS filesystemMode,
246
- notebook.transport_version AS transportVersion
247
- FROM detection_notebook AS notebook
248
- JOIN record_inbox AS inbox
249
- ON inbox.authority_id = notebook.resource_id
250
- AND inbox.entity_id = notebook.uuid
251
- AND inbox.global_sequence = (
252
- SELECT MAX(candidate.global_sequence)
253
- FROM record_inbox AS candidate
254
- WHERE candidate.authority_id = notebook.resource_id
255
- AND candidate.entity_id = notebook.uuid
256
- AND json_extract(candidate.record_json, '$.resultState') = notebook.version
257
- )
258
- LEFT JOIN entity_apply_intents AS intent
259
- ON intent.entity_id = inbox.entity_id
260
- AND intent.authority_id = inbox.authority_id
261
- LEFT JOIN entity_apply_state AS state
262
- ON state.entity_id = inbox.entity_id
263
- AND state.authority_id = inbox.authority_id
264
- WHERE (? IS NULL OR notebook.root_uuid = ?)
265
- AND (inbox.resolved_at IS NULL
266
- OR intent.intent_json IS NOT NULL
267
- OR state.entity_id IS NULL
268
- OR state.materialized_sequence IS NULL
269
- OR state.materialized_sequence < inbox.global_sequence)
270
- ORDER BY inbox.entity_id
271
- `);
272
- this.#resolveMaterializedHistory = database.prepare(`
273
- UPDATE record_inbox SET resolved_at = ?
274
- WHERE authority_id = ? AND entity_id = ? AND global_sequence <= ?
275
- AND resolved_at IS NULL
276
- `);
277
- this.#baselineRows = database.prepare(`
278
- SELECT inbox.authority_id AS authorityId,
279
- inbox.entity_id AS entityId,
280
- MAX(inbox.global_sequence) AS resolvedThrough
281
- FROM record_inbox AS inbox
282
- JOIN authority_snapshot_baselines AS baseline
283
- ON baseline.authority_id = inbox.authority_id
284
- LEFT JOIN entity_apply_state AS state
285
- ON state.authority_id = inbox.authority_id
286
- AND state.entity_id = inbox.entity_id
287
- WHERE inbox.delivery_sequence <= baseline.delivery_sequence
288
- AND inbox.global_sequence > COALESCE(state.resolved_through, 0)
289
- GROUP BY inbox.authority_id, inbox.entity_id
290
- `);
291
- this.#baselineIntents = database.prepare(`
292
- SELECT intent.intent_json AS intentJson
293
- FROM entity_apply_intents AS intent
294
- JOIN record_inbox AS target
295
- ON target.authority_id = intent.authority_id
296
- AND target.entity_id = intent.entity_id
297
- AND target.global_sequence = json_extract(intent.intent_json, '$.throughSequence')
298
- JOIN authority_snapshot_baselines AS baseline
299
- ON baseline.authority_id = intent.authority_id
300
- WHERE target.delivery_sequence <= baseline.delivery_sequence
301
- `);
302
- }
303
- /**
304
- * A verified notebook row is the last exact materialization this machine
305
- * proved. When retained Inbox history contains that same complete result,
306
- * the disk does not need to replay it: adopt the newest equal sequence as
307
- * Apply's baseline and leave every later different result as ordinary work.
308
- *
309
- * This runs before the installed root becomes eligible to Apply, or before
310
- * the Apply rail starts. Returned superseded intents let the host remove any
311
- * private preparation left by an interrupted older process.
312
- */
313
- adoptVerifiedMaterialization(rootUUID = null) {
314
- const supersededIntents = [];
315
- let settledRecords = 0;
316
- this.#database.transaction(() => {
317
- for (const row of this.#baselineRows.all()) {
318
- const prior = this.#state.get(row.authorityId, row.entityId);
319
- this.#upsertState.run(row.entityId, row.authorityId, row.resolvedThrough, prior?.materializedSequence ?? null, prior?.materializedRecordJson ?? null);
320
- }
321
- for (const { intentJson } of this.#baselineIntents.all()) {
322
- const intent = JSON.parse(intentJson);
323
- assertApplyIntent(intent);
324
- this.#deleteIntent.run(intent.authorityId, intent.entityId);
325
- this.#verified.delete(intent.entityId);
326
- supersededIntents.push(intent);
327
- }
328
- })();
329
- const matches = this.#materializedMatches.all(rootUUID, rootUUID);
330
- this.#database.transaction(() => {
331
- for (const match of matches) {
332
- const accepted = decodeAcceptedEntityRecord(match.recordJson);
333
- const notebook = {
334
- uuid: match.entityId,
335
- type: match.type,
336
- parentUUID: match.parentUUID,
337
- name: match.name,
338
- status: match.status,
339
- version: match.version,
340
- payloadVersion: match.payloadVersion,
341
- fileMode: portableFileMode(match.type, match.filesystemMode),
342
- transportVersion: match.transportVersion,
343
- };
344
- if (!sameRecords([notebook], [accepted.change.result]))
345
- continue;
346
- const prior = this.#state.get(match.authorityId, match.entityId);
347
- if (!prior || prior.resolvedThrough <= match.globalSequence) {
348
- this.#upsertState.run(match.entityId, match.authorityId, match.globalSequence, match.globalSequence, JSON.stringify(accepted.change.result));
349
- }
350
- settledRecords += this.#resolveMaterializedHistory.run(this.#now(), match.authorityId, match.entityId, match.globalSequence).changes;
351
- if (match.intentJson) {
352
- const intent = JSON.parse(match.intentJson);
353
- assertApplyIntent(intent);
354
- if (intent.throughSequence <= match.globalSequence) {
355
- this.#deleteIntent.run(intent.authorityId, intent.entityId);
356
- this.#verified.delete(intent.entityId);
357
- supersededIntents.push(intent);
358
- }
359
- }
360
- }
361
- })();
362
- return Object.freeze({
363
- settledRecords,
364
- supersededIntents: Object.freeze(supersededIntents),
365
- });
366
- }
367
- readApplyWork(limit, afterCursor) {
368
- const all = this.#candidateEntities.all()
66
+ `).all()
369
67
  .map(({ entityId }) => entityId)
370
68
  .filter((entityId) => afterCursor === null || entityId > afterCursor);
371
69
  const materializable = [];
@@ -389,197 +87,204 @@ export class EntityApplySqliteStore {
389
87
  });
390
88
  }
391
89
  #readApplyWork(entityId) {
392
- const intent = this.#readIntent(entityId);
90
+ const intent = readIntent(this.#database, entityId);
393
91
  const authorityId = intent?.authorityId ?? this.#authorityFor(entityId);
394
92
  if (!authorityId)
395
93
  return null;
396
- const state = this.#state.get(authorityId, entityId);
397
- let resolvedThrough = state?.resolvedThrough ?? 0;
398
- const rows = this.#inboxAfter.all(authorityId, entityId, resolvedThrough);
399
- const baseline = this.#snapshotBaseline.get(authorityId);
400
- const first = rows[0];
401
- if (!state && first && baseline
402
- && first.deliverySequence > baseline.deliverySequence) {
403
- const firstRecord = decodeAcceptedEntityRecord(first.recordJson);
404
- resolvedThrough = firstRecord.globalSequence - 1;
405
- }
94
+ const { state, resolvedThrough, rows } = applyResolution(this.#database, authorityId, entityId);
95
+ const materialized = state?.materializedSequence && state.materializedRecordJson
96
+ ? { globalSequence: state.materializedSequence, record: assertRecord(JSON.parse(state.materializedRecordJson)) }
97
+ : null;
98
+ const retired = intent ? readRetirement(this.#database, intent) : null;
99
+ if (retired)
100
+ return { authorityId, entityId, resolvedThrough, materialized, records: [], intent, retirement: retired.retirement };
406
101
  const records = rows.map(({ recordJson }) => decodeAcceptedEntityRecord(recordJson));
407
- if (records.length === 0)
408
- return null;
409
- const target = records.at(-1);
410
- const local = this.#localRelevance.get(entityId, entityId) !== undefined
411
- || (target.change.result.parentUUID !== null
412
- && this.#localRelevance.get(target.change.result.parentUUID, target.change.result.parentUUID) !== undefined);
413
- if (!local || !this.#isLocallyEligible(target.change.result))
414
- return null;
415
- return {
416
- authorityId,
417
- entityId,
418
- resolvedThrough,
419
- materialized: state?.materializedSequence && state.materializedRecordJson
420
- ? {
421
- globalSequence: state.materializedSequence,
422
- record: assertRecord(JSON.parse(state.materializedRecordJson)),
423
- }
424
- : null,
425
- records,
426
- intent,
427
- };
102
+ if (!intent) {
103
+ const target = records.at(-1);
104
+ if (!target)
105
+ return null;
106
+ const parent = target.change.result.parentUUID;
107
+ if (!(this.#locallyPresent(entityId) || (parent !== null && this.#locallyPresent(parent)))
108
+ || !this.#isLocallyEligible(target.change.result))
109
+ return null;
110
+ }
111
+ return { authorityId, entityId, resolvedThrough, materialized, records, intent };
112
+ }
113
+ #locallyPresent(uuid) {
114
+ return cachedStatement(this.#database, `SELECT 1 FROM entities WHERE uuid = ?
115
+ UNION ALL SELECT 1 FROM detection_notebook WHERE uuid = ? LIMIT 1`).get(uuid, uuid) !== undefined;
116
+ }
117
+ #authorityFor(entityId) {
118
+ const row = cachedStatement(this.#database, `SELECT authority_id AS authorityId FROM record_inbox
119
+ WHERE entity_id = ? ORDER BY global_sequence DESC LIMIT 1`).get(entityId);
120
+ return row?.authorityId ?? null;
428
121
  }
429
122
  hasLocalWorkAfter(authorityId, entityId, targetSequence) {
430
- return this.#localWork.get(authorityId, entityId, targetSequence) !== undefined;
123
+ return hasLocalWorkAfter(this.#database, authorityId, entityId, targetSequence);
431
124
  }
432
- beginIntent(intent) {
433
- assertApplyIntent(intent);
434
- const existing = this.#readIntent(intent.entityId, intent.authorityId);
435
- if (existing) {
436
- if (!sameIntent(existing, intent) || existing.phase !== intent.phase) {
437
- throw new Error(`entity ${intent.entityId} already has a different Apply intent`);
438
- }
439
- return;
440
- }
441
- this.#insertIntent.run(intent.entityId, intent.authorityId, JSON.stringify(intent));
125
+ /** The save re-answers every database condition; placement is disk, so
126
+ * it is proved here before the save is posted. Apply settles a page's
127
+ * bookkeeping together, so each proof and each answer is a turn boundary:
128
+ * one saver batch answers many resolutions, and no number of them runs in
129
+ * one activation. */
130
+ async resolveOwnPublication(work, target) {
131
+ await turnBoundary();
132
+ const publication = { authorityId: work.authorityId, entityId: work.entityId, resolvedThrough: work.resolvedThrough,
133
+ globalSequence: target.globalSequence, mutationId: target.mutationId };
134
+ const own = ownPublication(this.#database, publication);
135
+ // The history still starts where the work saw it and ends at the target,
136
+ // so the work's records through the target are exactly what it settles.
137
+ if (!own || !this.#holdsOwnPlacement(own.accepted.change.result, work.records.filter(record => record.globalSequence <= target.globalSequence)))
138
+ return false;
139
+ const { value: resolved } = await save(this.#file, "apply.resolveOwnPublication", { ...publication, resolvedAt: this.#now() });
140
+ await turnBoundary();
141
+ if (resolved)
142
+ this.#onOwnPublicationResolved(target);
143
+ return resolved;
144
+ }
145
+ async beginIntent(intent) {
146
+ await save(this.#file, "apply.beginIntent", intent);
442
147
  }
443
- setIntentPhase(intent) {
444
- assertApplyIntent(intent);
445
- const existing = this.#requireIntent(intent);
446
- if (!sameIntent(existing, intent))
447
- throw new Error("Apply phase update changed intent identity");
448
- const updated = this.#updateIntent.run(JSON.stringify(intent), intent.authorityId, intent.entityId);
449
- if (updated.changes !== 1)
450
- throw new Error("Apply intent phase was not durable");
148
+ recoveryLocation(intent) {
149
+ return recoveryLocation(this.#database, intent);
150
+ }
151
+ /** Publish where this attempt's recovery receipt lives, unless another
152
+ * unfinished operation owns part of its scope. The save decides against
153
+ * every binding posted before it. */
154
+ async bindRecoveryLocation(intent, directory, scope) {
155
+ return (await save(this.#file, "apply.bindRecovery", { intent, directory, scope })).value;
156
+ }
157
+ async setIntentPhase(intent) {
158
+ await save(this.#file, "apply.setIntentPhase", intent);
451
159
  }
452
160
  cancelIntent(intent) {
453
- const existing = this.#requireIntent(intent);
454
- if (!sameIntent(existing, intent))
455
- throw new Error("Apply cancel changed intent identity");
456
- this.#verified.delete(intent.entityId);
457
- this.#deleteIntent.run(intent.authorityId, intent.entityId);
458
- this.#onIntentFinished(intent);
161
+ return this.#commitRetirement(intent, { kind: "cancelled" });
459
162
  }
460
- stageVerification(intent, rows, removals = []) {
461
- this.#requireIntent(intent);
462
- this.#verified.set(intent.entityId, Object.freeze({
463
- rows: Object.freeze([...rows]),
464
- removals: Object.freeze([...new Set(removals)]),
465
- }));
163
+ stageRetirement(intent, purpose, description, evidence = {}) {
164
+ requireIntent(this.#database, intent);
165
+ const { repair, proof = witnessProof([]), attribution = null } = evidence;
166
+ if ((description.contract === "amalgm.apply-no-ground@1") !== isConstructType(intent.targetType)) {
167
+ throw new Error("Apply cleanup disposition does not belong to its entity type");
168
+ }
169
+ if (repair && (purpose.kind !== "cancelled" || isConstructType(intent.targetType))) {
170
+ throw new Error("Apply placement repair belongs only to cancelled filesystem effects");
171
+ }
172
+ this.#cleanupProof.set(intent.entityId, { intent: Object.freeze({ ...intent }),
173
+ purpose: Object.freeze({ ...purpose }), description: JSON.parse(JSON.stringify(description)), proof, attribution,
174
+ ...(repair ? { repair: { ...repair, rows: Object.freeze(repair.rows.map(row => Object.freeze({ ...row }))) } } : {}) });
175
+ }
176
+ cleanupDescription(retirement) {
177
+ return ownedCleanup(this.#database, retirement);
178
+ }
179
+ async acknowledgeCleanup(retirement) {
180
+ await save(this.#file, "apply.acknowledgeCleanup", retirement);
181
+ }
182
+ /** Verify's rows as data: each repository observation's proof closes with
183
+ * the Verify proof, never on the saver thread. */
184
+ stageVerification(intent, ground, basis, proof) {
185
+ requireIntent(this.#database, intent);
186
+ if (isConstructType(intent.targetType))
187
+ throw new Error("construct verification cannot claim filesystem ground");
188
+ const detach = (rows) => Object.freeze(rows.map(({ repositoryObservation, ...row }) => Object.freeze({ ...row, record: Object.freeze({ ...row.record }),
189
+ ...(repositoryObservation ? { repositoryObservation: dataOf(repositoryObservation) } : {}) })));
190
+ this.#verified.set(intent.entityId, { intent: Object.freeze({ ...intent }), basis, proof,
191
+ ground: Object.freeze({ observed: detach(ground.observed), shared: detach(ground.shared),
192
+ removedObserved: Object.freeze([...new Set(ground.removedObserved)]),
193
+ removedShared: Object.freeze([...new Set(ground.removedShared)]),
194
+ }) });
195
+ }
196
+ /** Product verification has no filesystem projection. The product remains
197
+ * the owner of its running state and ledger; this stages its exact receipt. */
198
+ stageConstructVerification(intent, target) {
199
+ requireIntent(this.#database, intent);
200
+ if (!isConstructType(intent.targetType) || target.uuid !== intent.entityId
201
+ || target.type !== intent.targetType || target.version !== intent.targetState) {
202
+ throw new Error("construct Verify does not describe its exact Apply target");
203
+ }
204
+ this.#verified.set(intent.entityId, { intent: Object.freeze({ ...intent }), ground: null, basis: null,
205
+ proof: witnessProof([]) });
466
206
  }
467
207
  completeIntent(intent, completion) {
208
+ return this.#commitRetirement(intent, completion);
209
+ }
210
+ async #commitRetirement(intent, completion) {
211
+ const verified = this.#verified.get(intent.entityId), cleanup = this.#cleanupProof.get(intent.entityId);
468
212
  try {
469
- const existing = this.#requireIntent(intent);
470
- if (!sameIntent(existing, intent) || existing.phase !== "revealed") {
471
- throw new Error("Apply completion does not match its revealed intent");
472
- }
473
- const prior = this.#state.get(intent.authorityId, intent.entityId);
474
- const verified = this.#verified.get(intent.entityId);
475
- if (completion.kind === "materialized" && !verified) {
476
- throw new Error("Apply completion has no exact Verify evidence");
477
- }
478
- const targetRow = this.#targetRecord.get(intent.authorityId, intent.entityId, intent.throughSequence);
479
- if (!targetRow)
480
- throw new Error("Apply target disappeared from its retained Inbox");
481
- const target = decodeAcceptedEntityRecord(targetRow.recordJson);
482
- this.#database.transaction(() => {
483
- if (completion.kind === "materialized") {
484
- const membershipContainers = new Set();
485
- for (const uuid of verified.removals) {
486
- const old = this.#notebookAtUuid.get(uuid);
487
- if (old?.parentUUID)
488
- membershipContainers.add(old.parentUUID);
489
- this.#deleteEntity.run(uuid);
490
- this.#deleteNotebook.run(uuid);
491
- }
492
- for (const row of verified.rows) {
493
- const old = this.#notebookAtUuid.get(row.record.uuid);
494
- if (old?.parentUUID)
495
- membershipContainers.add(old.parentUUID);
496
- if (row.record.parentUUID)
497
- membershipContainers.add(row.record.parentUUID);
498
- if (row.record.type === "workspace" || row.record.type === "folder") {
499
- membershipContainers.add(row.record.uuid);
500
- }
501
- this.#deleteEntity.run(row.record.uuid);
502
- }
503
- for (const row of verified.rows) {
504
- if (row.record.status === "active") {
505
- try {
506
- this.#upsertEntity.run(...rowValues(row));
507
- }
508
- catch (error) {
509
- const occupant = this.#entitySlot.get(row.resourceId, row.rootUUID, row.relativePath);
510
- throw new Error(`Apply projection could not place ${row.record.uuid} at `
511
- + `${row.rootUUID}:${row.relativePath}; occupied by `
512
- + `${occupant?.uuid ?? "no retained row"} (${occupant?.absolutePath ?? "unknown"}); `
513
- + `incoming=${row.record.type}:${row.record.payloadVersion ?? "none"}; `
514
- + `occupant=${occupant?.type ?? "none"}:${occupant?.payloadVersion ?? "none"}`, { cause: error });
515
- }
516
- }
517
- else {
518
- this.#deleteEntity.run(row.record.uuid);
519
- }
520
- this.#upsertNotebook.run(...rowValues(row));
521
- }
522
- this.#refreshMembershipVersions(membershipContainers);
523
- }
524
- this.#resolveInbox.run(this.#now(), intent.authorityId, intent.entityId, intent.fromSequence, intent.throughSequence);
525
- this.#upsertState.run(intent.entityId, intent.authorityId, intent.throughSequence, completion.kind === "materialized"
526
- ? intent.throughSequence
527
- : prior?.materializedSequence ?? null, completion.kind === "materialized"
528
- ? JSON.stringify(target.change.result)
529
- : prior?.materializedRecordJson ?? null);
530
- const removed = this.#deleteIntent.run(intent.authorityId, intent.entityId);
531
- if (removed.changes !== 1)
532
- throw new Error("Apply intent disappeared before completion");
533
- })();
534
- this.#verified.delete(intent.entityId);
213
+ const retirement = await this.#commitTerminalOutcome(intent, completion, verified, cleanup);
214
+ this.#release(intent, verified, cleanup);
215
+ return retirement;
535
216
  }
536
- finally {
537
- this.#onIntentFinished(intent);
217
+ catch (error) {
218
+ // Only this attempt's own staged evidence retires with its failure.
219
+ this.#release(intent, verified, cleanup);
220
+ this.#onAttemptFailed(intent);
221
+ throw error;
538
222
  }
539
223
  }
540
- close() {
541
- this.#database.close();
542
- }
543
- /** Container versions are a projection of the final notebook graph. An
544
- * independently ordered folder receipt may name membership from before a
545
- * child receipt; it can never overwrite the membership already present on
546
- * this machine. No container record is emitted for this derivation. */
547
- #refreshMembershipVersions(uuids) {
548
- for (const uuid of uuids) {
549
- const row = this.#notebookAtUuid.get(uuid);
550
- if (!row || (row.type !== "workspace" && row.type !== "folder"))
551
- continue;
552
- const children = this.#notebookChildren.all(uuid);
553
- const version = canonicalVersion({
554
- type: row.type,
555
- parentUUID: row.parentUUID,
556
- name: row.name,
557
- status: row.status,
558
- payloadVersion: membershipHash(children, sha256Hex),
559
- }, sha256Hex);
560
- this.#updateEntityVersion.run(version, uuid);
561
- this.#updateNotebookVersion.run(version, uuid);
224
+ #release(intent, verified, cleanup) {
225
+ if (verified && this.#verified.get(intent.entityId) === verified && sameIntent(verified.intent, intent)) {
226
+ this.#verified.delete(intent.entityId);
227
+ }
228
+ if (cleanup && this.#cleanupProof.get(intent.entityId) === cleanup && sameIntent(cleanup.intent, intent)) {
229
+ this.#cleanupProof.delete(intent.entityId);
562
230
  }
563
231
  }
564
- #authorityFor(entityId) {
565
- const row = this.#authorityForEntity.get(entityId);
566
- return row?.authorityId ?? null;
232
+ /** Every terminal prerequisite, read from local state now. Semantic closing
233
+ * awaits, so the commit asks again afterwards rather than trusting a read
234
+ * taken before the wait. */
235
+ #terminalPrerequisites(intent, completion, verified, cleanup) {
236
+ const repeated = readRetirement(this.#database, intent);
237
+ if (repeated) {
238
+ if (repeated.retirement.purpose.kind !== completion.kind)
239
+ throw new Error("Apply terminal purpose cannot change");
240
+ return { repeated: repeated.retirement };
241
+ }
242
+ const existing = requireIntent(this.#database, intent);
243
+ if (completion.kind !== "cancelled" && existing.phase !== "revealed") {
244
+ throw new Error("Apply completion does not match its revealed intent");
245
+ }
246
+ if (completion.kind === "materialized" && (!verified || !sameIntent(verified.intent, intent)
247
+ || this.#verified.get(intent.entityId) !== verified)) {
248
+ throw new Error("Apply completion has no exact Verify evidence");
249
+ }
250
+ if (!cleanup || !sameIntent(cleanup.intent, intent) || cleanup.purpose.kind !== completion.kind
251
+ || this.#cleanupProof.get(intent.entityId) !== cleanup)
252
+ throw new Error("Apply retirement has no proven cleanup description");
253
+ return { cleanup };
567
254
  }
568
- #readIntent(entityId, authorityId) {
569
- const row = authorityId
570
- ? this.#intent.get(authorityId, entityId)
571
- : this.#intentByEntity.get(entityId);
572
- if (!row)
573
- return null;
574
- const intent = JSON.parse(row.intentJson);
575
- assertApplyIntent(intent);
576
- return intent;
255
+ async #commitTerminalOutcome(intent, completion, verified, staged) {
256
+ const opening = this.#terminalPrerequisites(intent, completion, verified, staged);
257
+ if ("repeated" in opening)
258
+ return opening.repeated;
259
+ // Git and other slow owners re-answer first; native witnesses and
260
+ // ownership close as the save is posted, and the save re-reads every
261
+ // database fact the outcome depends on.
262
+ const proofs = [opening.cleanup.proof, ...(opening.cleanup.repair ? [opening.cleanup.repair.proof] : []),
263
+ ...(completion.kind === "materialized" ? [verified.proof] : [])];
264
+ await sourceProofs(proofs).semantic();
265
+ const closing = this.#terminalPrerequisites(intent, completion, verified, staged);
266
+ if ("repeated" in closing)
267
+ return closing.repeated;
268
+ const { cleanup } = closing;
269
+ for (const proof of proofs)
270
+ closePhysically(proof);
271
+ const retirement = { token: randomUUID(), intent, purpose: completion };
272
+ const ground = completion.kind === "materialized" && verified?.ground && verified.basis
273
+ ? { ground: verified.ground, basis: verified.basis.toData() } : null;
274
+ await save(this.#file, "apply.retire", {
275
+ retirement,
276
+ cleanup: cleanup.description,
277
+ attribution: cleanup.attribution?.toData() ?? null,
278
+ repair: cleanup.repair ? { rows: cleanup.repair.rows, basis: cleanup.repair.basis.toData() } : null,
279
+ verified: ground,
280
+ resolvedAt: this.#now(),
281
+ });
282
+ this.#onIntentFinished(intent);
283
+ return retirement;
577
284
  }
578
- #requireIntent(intent) {
579
- const existing = this.#readIntent(intent.entityId, intent.authorityId);
580
- if (!existing)
581
- throw new Error(`entity ${intent.entityId} has no durable Apply intent`);
582
- return existing;
285
+ close() {
286
+ this.#database.close();
583
287
  }
584
288
  }
289
+ const dataOf = ({ proof: _proof, ...pair }) => pair;
585
290
  //# sourceMappingURL=entity-apply-store.js.map