@lapxo/bound 0.2.4 → 0.2.6

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 (333) hide show
  1. package/CITATION.cff +1 -1
  2. package/README.md +20 -3
  3. package/TARGET.bound +85 -47
  4. package/dist/cli/accept.js +61 -590
  5. package/dist/cli/act-result.js +3 -103
  6. package/dist/cli/args.js +3 -44
  7. package/dist/cli/custodian.js +2 -29
  8. package/dist/cli/host.js +4 -32
  9. package/dist/cli/names.js +1 -12
  10. package/dist/cli/native-descendant.js +1 -19
  11. package/dist/cli/native.js +3 -60
  12. package/dist/cli/observe.js +1 -13
  13. package/dist/cli/owner.js +3 -139
  14. package/dist/cli/pass.js +22 -321
  15. package/dist/cli/place.js +6 -282
  16. package/dist/cli/release-result.js +3 -80
  17. package/dist/cli/retained-judgment.js +1 -25
  18. package/dist/cli/standing-result.js +4 -19
  19. package/dist/cli/takes.js +10 -112
  20. package/dist/cli/verb.d.ts +1 -2
  21. package/dist/cli/verb.js +85 -684
  22. package/dist/engine/computation.js +2 -0
  23. package/dist/engine/conformance.js +4 -0
  24. package/dist/engine/encoding.js +1 -2
  25. package/dist/engine/index.d.ts +1 -13
  26. package/dist/engine/index.js +2 -11
  27. package/dist/engine/object.js +1 -38
  28. package/dist/engine/ports.js +2 -117
  29. package/dist/fold/admission-history.js +1 -17
  30. package/dist/fold/bootstrap-anchor.js +1 -28
  31. package/dist/fold/ceilings.js +1 -142
  32. package/dist/fold/claims.js +2 -132
  33. package/dist/fold/closed.js +24 -235
  34. package/dist/fold/configures.js +1 -25
  35. package/dist/fold/digests.js +10 -226
  36. package/dist/fold/evidence.js +1 -22
  37. package/dist/fold/fold-worker.js +1 -13
  38. package/dist/fold/kept.js +12 -173
  39. package/dist/fold/keys.js +3 -91
  40. package/dist/fold/laid.js +3 -90
  41. package/dist/fold/nos.js +1 -48
  42. package/dist/fold/object.js +1 -2
  43. package/dist/fold/observed.js +28 -534
  44. package/dist/fold/opened.js +1 -33
  45. package/dist/fold/own.js +3 -217
  46. package/dist/fold/paid.js +1 -92
  47. package/dist/fold/place-inputs.js +1 -70
  48. package/dist/fold/places.js +3 -100
  49. package/dist/fold/rank.js +1 -9
  50. package/dist/fold/reach.js +1 -83
  51. package/dist/fold/readers.js +6 -142
  52. package/dist/fold/receipts.js +1 -47
  53. package/dist/fold/region-declarations.js +1 -13
  54. package/dist/fold/region.js +8 -286
  55. package/dist/fold/release-policy.js +1 -101
  56. package/dist/fold/resolved.js +6 -145
  57. package/dist/fold/roles.js +2 -59
  58. package/dist/fold/second.js +4 -71
  59. package/dist/fold/shards.js +12 -100
  60. package/dist/fold/signed.js +3 -81
  61. package/dist/fold/signers.js +1 -54
  62. package/dist/fold/stranger.js +6 -24
  63. package/dist/fold/views.js +1 -66
  64. package/dist/fold/wire.js +1 -46
  65. package/dist/fold/zoom.js +3 -81
  66. package/dist/host/act-cost.js +1 -25
  67. package/dist/host/adapters/keys/ed25519.js +1 -30
  68. package/dist/host/adapters/modules/javascript.js +1 -50
  69. package/dist/host/adapters/transport/http.js +1 -28
  70. package/dist/host/admitted-place.js +1 -35
  71. package/dist/host/archive.js +1 -152
  72. package/dist/host/call-context.js +1 -14
  73. package/dist/host/capsule-process.js +2 -62
  74. package/dist/host/capsule.js +9 -171
  75. package/dist/host/cell-receipts.js +12 -128
  76. package/dist/host/command-server.js +4 -0
  77. package/dist/host/commit-result.js +1 -5
  78. package/dist/host/content-needed.js +1 -8
  79. package/dist/host/content-store.js +1 -31
  80. package/dist/host/contextual-place.js +2 -72
  81. package/dist/host/digest.js +2 -15
  82. package/dist/host/hash.js +1 -9
  83. package/dist/host/host-controls.js +1 -19
  84. package/dist/host/in-process-act.js +3 -84
  85. package/dist/host/in-process-context.js +3 -91
  86. package/dist/host/in-process-root.js +6 -84
  87. package/dist/host/in-process.js +4 -55
  88. package/dist/host/index.d.ts +1 -15
  89. package/dist/host/index.js +1 -7
  90. package/dist/host/io.js +1 -11
  91. package/dist/host/lifetime.js +1 -79
  92. package/dist/host/located.js +6 -105
  93. package/dist/host/native/authority-card-view.js +5 -0
  94. package/dist/host/native/authority-card.js +1 -0
  95. package/dist/host/native/bounded-file.js +1 -32
  96. package/dist/host/native/command.js +1 -91
  97. package/dist/host/native/control-bridge-worker.js +2 -88
  98. package/dist/host/native/control-bridge.js +1 -110
  99. package/dist/host/native/control-selection.js +1 -32
  100. package/dist/host/native/custody.js +1 -91
  101. package/dist/host/native/deadline.js +1 -28
  102. package/dist/host/native/descendants.js +1 -528
  103. package/dist/host/native/generated-custodian.js +5 -267
  104. package/dist/host/native/generated.js +1 -379
  105. package/dist/host/native/image.js +1 -45
  106. package/dist/host/native/installed-package.d.ts +1 -0
  107. package/dist/host/native/installed-package.js +5 -0
  108. package/dist/host/native/jobs.js +2 -148
  109. package/dist/host/native/loader.js +1 -269
  110. package/dist/host/native/materialize.js +1 -175
  111. package/dist/host/native/module-closure.js +1 -130
  112. package/dist/host/native/module-delivery.d.ts +1 -62
  113. package/dist/host/native/module-delivery.js +1 -151
  114. package/dist/host/native/module-inventory.js +2 -0
  115. package/dist/host/native/module-syntax.js +1 -69
  116. package/dist/host/native/native-binary.js +1 -115
  117. package/dist/host/native/native-program.js +1 -72
  118. package/dist/host/native/node-jobs.js +3 -187
  119. package/dist/host/native/node-launch.js +1 -159
  120. package/dist/host/native/preload.js +1 -45
  121. package/dist/host/native/probes.js +1 -0
  122. package/dist/host/native/reading-witness-admission.js +5 -0
  123. package/dist/host/native/reading.js +1 -249
  124. package/dist/host/native/receipt-environment.js +1 -41
  125. package/dist/host/native/references.js +1 -30
  126. package/dist/host/native/root.js +1 -37
  127. package/dist/host/native/route.js +1 -216
  128. package/dist/host/native/runtime.js +1 -9
  129. package/dist/host/native-place-state.js +1 -0
  130. package/dist/host/native-reader-context.js +1 -8
  131. package/dist/host/native-receiver.js +1 -25
  132. package/dist/host/objects.js +1 -38
  133. package/dist/host/order.js +1 -2
  134. package/dist/host/persistent-host.js +1 -0
  135. package/dist/host/physical-lines.d.ts +1 -0
  136. package/dist/host/physical-lines.js +1 -0
  137. package/dist/host/place-act-transaction.js +4 -78
  138. package/dist/host/place-clock-selection.js +5 -124
  139. package/dist/host/ports/ingress.js +2 -57
  140. package/dist/host/ports/local-act.js +5 -183
  141. package/dist/host/ports/place-act.js +1 -134
  142. package/dist/host/ports/publication.js +1 -56
  143. package/dist/host/ports/signing.js +1 -74
  144. package/dist/host/ports/store.js +1 -18
  145. package/dist/host/ports/transport.js +1 -48
  146. package/dist/host/process-lifetime.js +1 -17
  147. package/dist/host/profile-composition.d.ts +1 -0
  148. package/dist/host/profile-composition.js +2 -0
  149. package/dist/host/provide.js +1 -183
  150. package/dist/host/read-only.js +1 -9
  151. package/dist/host/reading-closures.js +7 -227
  152. package/dist/host/reading-context.js +1 -53
  153. package/dist/host/reading-identity-types.js +0 -0
  154. package/dist/host/reading-identity.js +3 -0
  155. package/dist/host/reading-preparation.js +6 -0
  156. package/dist/host/reference-authenticated.d.ts +1 -40
  157. package/dist/host/reference-authenticated.js +3 -100
  158. package/dist/host/reference-contracts.js +1 -6
  159. package/dist/host/reference-export.js +6 -81
  160. package/dist/host/reference-native-api.d.ts +1 -3
  161. package/dist/host/reference-native-api.js +1 -3
  162. package/dist/host/reference-native.js +1 -74
  163. package/dist/host/reference-profile.js +1 -63
  164. package/dist/host/reference-standing.js +2 -18
  165. package/dist/host/reference.js +1 -24
  166. package/dist/host/refusals.js +2 -43
  167. package/dist/host/release.js +4 -256
  168. package/dist/host/root-clock-source.js +1 -307
  169. package/dist/host/selected-capsules.js +1 -50
  170. package/dist/host/selected-topos.js +1 -80
  171. package/dist/host/signature-era.js +1 -12
  172. package/dist/host/signing.js +2 -48
  173. package/dist/host/source-content.js +2 -111
  174. package/dist/host/standing-carrier.js +1 -18
  175. package/dist/host/standing-projection.js +1 -50
  176. package/dist/host/timing.js +1 -7
  177. package/dist/host/walk.js +20 -193
  178. package/dist/host/work-trace.js +1 -0
  179. package/dist/judge/late.js +1 -33
  180. package/dist/judge/take.js +2 -75
  181. package/dist/judge/widening.js +1 -25
  182. package/dist/land/act.js +8 -336
  183. package/dist/land/alias.js +1 -41
  184. package/dist/land/held.js +1 -23
  185. package/dist/land/inert.js +1 -33
  186. package/dist/land/leaving.js +1 -55
  187. package/dist/land/ledger.js +6 -188
  188. package/dist/land/owned.js +4 -66
  189. package/dist/land/sign.js +1 -53
  190. package/dist/land/standing-pin.js +1 -49
  191. package/dist/land/vouched.js +1 -112
  192. package/dist/land/withdraw.js +1 -24
  193. package/dist/observe/files.js +1 -88
  194. package/dist/observe/identity.js +1 -61
  195. package/dist/observe/match.js +1 -8
  196. package/dist/observe/regions.js +7 -306
  197. package/dist/observe/run.js +1 -41
  198. package/dist/observe/runner.js +4 -101
  199. package/dist/public-types.d.ts +2019 -0
  200. package/dist/render/capsule.js +1 -30
  201. package/dist/render/field.js +1 -40
  202. package/dist/render/names.js +1 -4
  203. package/dist/render/open.js +1 -61
  204. package/dist/render/page.js +1 -7
  205. package/dist/render/receipt-projection.js +1 -0
  206. package/dist/render/receipts.js +1 -47
  207. package/dist/render/shape.js +1 -74
  208. package/dist/render/target.js +4 -52
  209. package/dist/render/view.js +7 -197
  210. package/dist/vendor/bundle.json +1 -0
  211. package/dist/vendor/library14.js +1 -0
  212. package/dist/vendor/object-provider.js +42 -0
  213. package/dist/vendor/runtime.js +61 -0
  214. package/dist/wasm/adapter.d.ts +1 -51
  215. package/dist/wasm/adapter.js +1 -180
  216. package/dist/wasm/node-worker.js +1 -13
  217. package/dist/wasm/object.js +1 -76
  218. package/dist/wasm/worker.js +1 -7
  219. package/docs/contracts/authenticated-reference.publication.json +1 -1
  220. package/docs/contracts/authority-preflight.md +17 -0
  221. package/docs/contracts/authority-preflight.publication.json +25 -0
  222. package/docs/contracts/closure-delivery.md +1 -1
  223. package/docs/contracts/closure-delivery.publication.json +1 -1
  224. package/docs/contracts/conformance.json +142 -0
  225. package/docs/contracts/determinism.bound +9 -0
  226. package/docs/contracts/engine-object-projection.publication.json +1 -1
  227. package/docs/contracts/engine.md +21 -1
  228. package/docs/contracts/installed-package.md +21 -0
  229. package/docs/contracts/installed-package.publication.json +25 -0
  230. package/docs/contracts/materialized-leaf-sequence.md +15 -0
  231. package/docs/contracts/materialized-leaf-sequence.publication.json +25 -0
  232. package/docs/contracts/module-inventory.md +15 -0
  233. package/docs/contracts/module-inventory.publication.json +25 -0
  234. package/docs/contracts/native-host.md +29 -1
  235. package/docs/contracts/native-host.publication.json +4 -4
  236. package/docs/contracts/native-probes.md +13 -0
  237. package/docs/contracts/native-probes.publication.json +25 -0
  238. package/docs/contracts/native-publication.inventory.json +10 -1
  239. package/docs/contracts/native-view-batch.md +17 -0
  240. package/docs/contracts/native-view-batch.publication.json +25 -0
  241. package/docs/contracts/optional-wasm-adapter.publication.json +1 -1
  242. package/docs/contracts/physical-lines.md +19 -0
  243. package/docs/contracts/physical-lines.publication.json +25 -0
  244. package/docs/contracts/profile-composition.md +17 -0
  245. package/docs/contracts/profile-composition.publication.json +25 -0
  246. package/docs/contracts/profile-preparation-native-meaning.md +9 -0
  247. package/docs/contracts/publication.md +12 -0
  248. package/docs/contracts/reading-identity.md +61 -0
  249. package/docs/contracts/reading-identity.publication.json +25 -0
  250. package/docs/contracts/reading-witness-admission.md +49 -0
  251. package/docs/contracts/readme.publication.json +1 -1
  252. package/docs/contracts/reference-port.md +11 -0
  253. package/docs/contracts/reference-port.publication.json +1 -1
  254. package/docs/contracts/refusals.bound +346 -94
  255. package/docs/contracts/refusals.md +119 -39
  256. package/docs/contracts/refusals.publication.json +2 -2
  257. package/docs/contracts/views.md +8 -0
  258. package/docs/reference.md +9 -0
  259. package/licenses/wasm/{fast-text-encoding.txt → NOTICE.txt} +111 -0
  260. package/package.json +84 -34
  261. package/receipts.bound +12952 -10449
  262. package/samples/authority-preflight/no.json +6 -0
  263. package/samples/authority-preflight/yes.json +30 -0
  264. package/samples/engine-alphabet/reader.js +3 -1457
  265. package/samples/engine-alphabet/receipts.bound +7 -7
  266. package/samples/engine-interval/reader.js +3 -1457
  267. package/samples/engine-interval/receipts.bound +7 -7
  268. package/samples/installed-package/consumer.mjs +29 -0
  269. package/samples/installed-package/fixture.json +48 -0
  270. package/samples/installed-package/no.json +10 -0
  271. package/samples/installed-package/yes.json +52 -0
  272. package/samples/materialized-leaf-sequence/no.json +11 -0
  273. package/samples/materialized-leaf-sequence/yes.json +10 -0
  274. package/samples/module-inventory/yes.json +28 -0
  275. package/samples/native/physical-line-reader.mjs +1 -0
  276. package/samples/native/physical-line-reader.source.mjs +13 -0
  277. package/samples/native-host/no.json +6 -1
  278. package/samples/native-host/yes.json +18 -1
  279. package/samples/native-probes/inputs/inspection.json +28 -0
  280. package/samples/native-probes/no.json +7 -0
  281. package/samples/native-probes/yes.json +28 -0
  282. package/samples/native-view-batch/no.json +14 -0
  283. package/samples/native-view-batch/yes.json +10 -0
  284. package/samples/no/engine-order/reader.js +3 -1457
  285. package/samples/no/module-inventory/no.json +10 -0
  286. package/samples/physical-lines/no.json +5 -0
  287. package/samples/physical-lines/yes.json +9 -0
  288. package/samples/profile-composition/no.json +6 -0
  289. package/samples/profile-composition/yes.json +14 -0
  290. package/samples/reading-identity/no.json +26 -0
  291. package/samples/reading-identity/yes.json +69 -0
  292. package/vectors/native/authority-preflight.vector.json +55 -0
  293. package/vectors/native/installed-package.vector.json +31 -0
  294. package/vectors/native/materialized-leaf-sequence.vector.json +31 -0
  295. package/vectors/native/module-inventory.vector.json +56 -0
  296. package/vectors/native/native-host.vector.json +214 -0
  297. package/vectors/native/native-probes.vector.json +31 -0
  298. package/vectors/native/native-view-batch.vector.json +31 -0
  299. package/vectors/native/physical-lines.vector.json +105 -0
  300. package/vectors/native/profile-composition.vector.json +53 -0
  301. package/vectors/native/reading-identity.vector.json +139 -0
  302. package/vectors/native/refusals.vector.json +138 -0
  303. package/vendor/syntax/LICENSE.md +7 -0
  304. package/vendor/syntax/parser.js +1 -0
  305. package/.github/workflows/release.yml +0 -67
  306. package/.github/workflows/test.yml +0 -35
  307. package/dist/engine/object.d.ts +0 -17
  308. package/dist/engine/ports.d.ts +0 -37
  309. package/dist/fold/claims.d.ts +0 -29
  310. package/dist/host/call-context.d.ts +0 -20
  311. package/dist/host/commit-result.d.ts +0 -6
  312. package/dist/host/in-process-act.d.ts +0 -82
  313. package/dist/host/in-process-context.d.ts +0 -46
  314. package/dist/host/in-process-root.d.ts +0 -117
  315. package/dist/host/in-process.d.ts +0 -41
  316. package/dist/host/native/module-closure.d.ts +0 -35
  317. package/dist/host/native-receiver.d.ts +0 -19
  318. package/dist/host/place-act-transaction.d.ts +0 -24
  319. package/dist/host/place-clock-selection.d.ts +0 -55
  320. package/dist/host/ports/local-act.d.ts +0 -44
  321. package/dist/host/ports/place-act.d.ts +0 -49
  322. package/dist/host/ports/publication.d.ts +0 -10
  323. package/dist/host/reference-export.d.ts +0 -33
  324. package/dist/host/reference-native.d.ts +0 -30
  325. package/dist/host/reference-profile.d.ts +0 -23
  326. package/dist/host/refusals.d.ts +0 -14
  327. package/dist/host/root-clock-source.d.ts +0 -86
  328. package/licenses/wasm/jitl-quickjs-ffi-types.txt +0 -21
  329. package/licenses/wasm/jitl-quickjs-wasmfile-release-sync.txt +0 -47
  330. package/licenses/wasm/quickjs-emscripten-core.txt +0 -21
  331. package/licenses/wasm/topos.txt +0 -21
  332. /package/{licenses/wasm/bound.txt → dist/vendor/28cba430228db1c04f446c93f81b09a2705d6bf3e222d35adbe5a4cee4061884.LICENSE} +0 -0
  333. /package/{licenses/wasm/obligations.txt → dist/vendor/7aca161279d14bc0e054dcc281cd110aeb95be2e026b42fdf527a260e58b2aae.LICENSE} +0 -0
@@ -1,590 +1,61 @@
1
- import { BoundRefusal } from "../host/refusals.js";
2
- import { assertHostNotCancelled as notCancelled } from "../host/host-controls.js";
3
- import { authorityAtEpoch } from '@lapxo/topos/wire';
4
- import { requireEffects } from "../host/read-only.js";
5
- import { hostOutput } from "../host/call-context.js";
6
- import { assertProspectiveRootClockSelection } from "../host/root-clock-source.js";
7
- import { hasContextualPlace, landContextualPlace } from "../host/contextual-place.js";
8
- import { commitLocalAct, intactLocalAct, committedLocalActs } from "../host/ports/local-act.js";
9
- import { withoutEffects } from "../host/read-only.js";
10
- import { admittedLine } from "../host/selected-topos.js";
11
- import { timing } from "../host/timing.js";
12
- import { admittedObjects } from "../host/objects.js";
13
- import { existsSync, rmdirSync, rmSync } from 'node:fs';
14
- import { dirname, join, basename } from 'node:path';
15
- import { closeReceipts, instrumentKeep, instrumentKept } from "../fold/closed.js";
16
- import { bytesDigest, fullDigest, instrumentOf, signaturesOf } from "../fold/digests.js";
17
- import { canonical, LOCK, parse, actIdentity, actResultProfile } from '@lapxo/topos/wire';
18
- import { fieldOf, isConfig, foldClaims, sayingOf, selfName } from "../fold/claims.js";
19
- import { isReaderLock } from "../fold/observed.js";
20
- import { authorityFor, publicKeyOf, rootSigner, writerFor } from "../fold/signers.js";
21
- import { lockLines, lockStanding } from "../fold/keys.js";
22
- import { keepVerdict, keptVerdict, land, landBlob, ledgerLines, storeOf } from "../land/ledger.js";
23
- import { signConsentLot, verifiesOwnerLine } from "../land/sign.js";
24
- import { signerFor } from "../host/signing.js";
25
- import { appliedIn, ownLockOf } from "../fold/signed.js";
26
- import { wordOf } from "../fold/wire.js";
27
- import { hasVouchedTree, landCoordinates, locationsOf, vouchedCoordinates } from "../land/vouched.js";
28
- import { entriesIn, observeFile } from "../observe/files.js";
29
- import { coneOf, standingOf } from "./place.js";
30
- import { ownLock, ownRoot } from "../observe/runner.js";
31
- import { widenedWithoutWitness } from "../judge/widening.js";
32
- import { retractedTogether, withdrawal } from "../land/withdraw.js";
33
- import { isCeiling } from "../fold/configures.js";
34
- import { inertIn } from "../land/inert.js";
35
- import { landSaid } from "./pass.js";
36
- import { underTheLock, underTheRegions, underAuthorityRegions, underRootProjection } from "../land/act.js";
37
- import { openedBy } from "../fold/opened.js";
38
- import { touchedBy } from "../fold/reach.js";
39
- import { landOwned, ownedOf } from "../land/owned.js";
40
- import { layReleases } from "../host/release.js";
41
- import { foundableIn, placesIn } from "../fold/places.js";
42
- import { outsideTheirCapsule } from "../fold/own.js";
43
- import { lateFacts } from "../judge/late.js";
44
- import { paidOf } from "../fold/paid.js";
45
- import { aliasPinned } from "../land/alias.js";
46
- import { admitStandingPins } from "../land/standing-pin.js";
47
- import { coordinatesWithdrawn } from "../land/leaving.js";
48
- import { ownerOf, epochOf, localActLines, forksItself, forksJoinedBy, renderInto, sideOf, signedDemands, signedOwnerLines } from "./owner.js";
49
- import { claimLinesIn, entryOf, namedPlaces, placesOfFile, positionalsOf, valueOf } from "./args.js";
50
- import { FLAGS } from "./names.js";
51
- import { judgeDemand, landTake } from "./takes.js";
52
- /** Admission reads an existing evidence snapshot; acquiring observations belongs to fold. */
53
- function admissionEvidence(root, signed, standing) {
54
- return withoutEffects(() => {
55
- const store = storeOf(root);
56
- assertProspectiveRootClockSelection(root, signed);
57
- const reads = !signed.some(isReaderLock) && signed.some(isCeiling);
58
- const fold = reads ? coneOf(root, entryOf(root), signed.filter(isCeiling)) : { standing, observed: [], own: {}, kept: true };
59
- const inert = inertIn(signed, { standing: fold.standing, ceiling: isCeiling, signsReader: !reads, observed: fold.observed, own: fold.own, epoch: epochOf([...lockLines(store), ...signed]) });
60
- if (inert.length)
61
- throw Error('REFUSE·inert no existing reading meets these ceilings; fold the declared inputs first');
62
- const coordinates = coordinatesWithdrawn(root, store, signed, [...signed, ...standing]);
63
- if (coordinates.refused.length)
64
- throw Error(`REFUSE·withdraw a file is still read: ${coordinates.refused.map(one => `${one.path} by ${one.by}`).join(' · ')}`);
65
- const view = `${wordOf(standing, 'families', 'view')}/`;
66
- const judged = signed.filter(one => isConfig(one) && fieldOf(one, 'role') === 'demands' && fieldOf(one, 'value') !== 'withdraw' && !fieldOf(one, 'scope').startsWith(view)).map(one => {
67
- const scope = fieldOf(one, 'scope');
68
- const alreadyDemanded = standing.some(held => isConfig(held) && fieldOf(held, 'role') === 'demands'
69
- && fieldOf(held, 'value') !== 'withdraw' && fieldOf(held, 'scope') === scope
70
- && fieldOf(held, 'form') === fieldOf(one, 'form') && fieldOf(held, 'measure') === fieldOf(one, 'measure'));
71
- // Declaring an obligation is not a claim to have discharged it.
72
- return alreadyDemanded ? judgeDemand(root, one)
73
- : { kind: 'owed', scope, why: 'new demand declared; no conformance reading is claimed' };
74
- });
75
- const refused = judged.filter(one => one.kind === 'refused' || (one.kind === 'judged' && one.verdict.kind === 'refuse'));
76
- if (refused.length)
77
- throw Error(`REFUSE·takes ${refused.map(one => `${one.scope}: ${one.kind === 'judged' ? one.verdict.why : one.kind === 'refused' ? one.why : ''}`).join(' · ')}`);
78
- return { coordinates, judged, fold };
79
- });
80
- }
81
- /** One witness rule for prospective admission and the locked act. */
82
- function refusesWidening(signed, standing) {
83
- const widened = widenedWithoutWitness(signed, standing, isCeiling, wordOf(standing, 'at-classes', 'witness'));
84
- if (widened.length) {
85
- for (const line of widened)
86
- hostOutput('error', `WIDER ${fieldOf(line, 'scope')} · ${fieldOf(line, 'value')}\n`);
87
- hostOutput('error', `${selfName()}: REFUSE·widening nothing landed · a ceiling that admits more than it did gives back freedom the lock had spent: sign it under a witness that names what made the old ceiling wrong\n`);
88
- return true;
89
- }
90
- return false;
91
- }
92
- /** Admission-only checks; observation and mutation belong to the later act. */
93
- function refusesAdmission(root, signed, standing) {
94
- if (refusesWidening(signed, standing))
95
- return true;
96
- const store = storeOf(root);
97
- const outside = outsideTheirCapsule(root, standing, signed);
98
- for (const line of outside)
99
- hostOutput('error', `OUTSIDE ${fieldOf(line, 'scope')} · ${fieldOf(line, 'value')}\n`);
100
- if (outside.length) {
101
- hostOutput('error', `${selfName()}: REFUSE·outside nothing landed · a reader or a capsule lands in the capsule of its world, never in the wire or the instrument\n`);
102
- return true;
103
- }
104
- const forks = forksJoinedBy(store, signed).filter(fork => forksItself(fork.lines) || fork.lines.filter(line => signed.includes(line)).length > 1);
105
- if (forks.length) {
106
- for (const fork of forks) {
107
- hostOutput('error', `FORK ${fork.key}\n`);
108
- for (const line of fork.lines)
109
- hostOutput('error', ` ${signed.includes(line) ? 'new ' : 'held'} by=${fieldOf(line, 'by')} ${sideOf(line, lockLines(store))}\n`);
110
- }
111
- hostOutput('error', `${selfName()}: REFUSE·fork nothing landed · one signer never forks itself, and one act never forks itself: withdraw the held side in this batch, or sign the other reading under its own scope\n`);
112
- return true;
113
- }
114
- const held = aliasPinned(root, signed);
115
- if (held.length) {
116
- for (const one of held)
117
- hostOutput('error', `ALIAS ${one.scope} · ${one.digest} · ${one.by.join(' ')}\n`);
118
- hostOutput('error', `${selfName()}: REFUSE·alias nothing landed · an alias is withdrawn only when no pin names its digest\n`);
119
- return true;
120
- }
121
- return false;
122
- }
123
- function refusesStandingPins(root, lines) {
124
- try {
125
- admitStandingPins(root, lines);
126
- return false;
127
- }
128
- catch (error) {
129
- hostOutput('error', `${selfName()}: ${error instanceof Error ? error.message : String(error)}\n`);
130
- return true;
131
- }
132
- }
133
- /** A batch signed as accept signs it: at the next epoch, by the key it names, each line read by the wire it would land under. */
134
- export async function signedBatch(root, args, files, host) {
135
- const byFile = host ? [[[], host.records]] : files.map((file) => [placesOfFile(file), claimLinesIn(file)]);
136
- const proposed = byFile.flatMap(([, lines]) => lines);
137
- if (!proposed.length) {
138
- hostOutput('error', `${selfName()}: a batch is a file with claim lines\n`);
139
- return { kind: 'exit', code: 2 };
140
- }
141
- const drafted = proposed.filter((line) => !fieldOf(line, 'sig'));
142
- const bare = drafted.filter((line) => fieldOf(line, 'epoch') || !['', 'target'].includes(fieldOf(line, 'by')));
143
- if (bare.length) {
144
- for (const line of bare)
145
- hostOutput('error', `BARE ${fieldOf(line, 'scope')} · by=${fieldOf(line, 'by') || '∅'}${fieldOf(line, 'epoch') ? ` epoch=${fieldOf(line, 'epoch')}` : ''}\n`);
146
- hostOutput('error', `${selfName()}: REFUSE·bare nothing landed · ${bare.length} lines name a signer or an epoch they were not signed with: a drafted line proposes by=target and sign signs it, a line a lane signed carries its sig\n`);
147
- return { kind: 'exit', code: 1 };
148
- }
149
- const store = storeOf(root);
150
- const destinations = [...new Set([...namedPlaces(args), ...byFile.flatMap(([heads]) => heads)])];
151
- const rooted = lockStanding(store);
152
- const stray = destinations.filter(one => !placesIn(root).includes(one) && !foundableIn(root, rooted, wordOf(rooted, 'families', 'region'), one));
153
- if (stray.length) {
154
- hostOutput('error', `${selfName()}: REFUSE·place nothing landed · ${stray.join(', ')} is no place of the tree, and no line of the root founds it: --place names the own lock a line lands in\n`);
155
- return { kind: 'exit', code: 2 };
156
- }
157
- const local = localActLines(root, destinations);
158
- const base = { digest: fullDigest(store, local), places: destinations };
159
- const epoch = epochOf(local) + 1;
160
- const stale = proposed.filter((line) => fieldOf(line, 'sig')).flatMap((line) => ((by, key) => (key === undefined || !verifiesOwnerLine(line, key, signaturesOf(store).admitted)
161
- ? [`${fieldOf(line, 'scope')} · the signature does not hold for ${by || '∅'}`]
162
- : []))(fieldOf(line, 'by'), publicKeyOf(root, fieldOf(line, 'by'))));
163
- if (stale.length) {
164
- for (const one of stale)
165
- hostOutput('error', `SIGNED ${one}\n`);
166
- hostOutput('error', `${selfName()}: REFUSE·signed nothing landed · ${stale.length} lines a lane signed stand at no epoch this act\n`);
167
- return { kind: 'exit', code: 1 };
168
- }
169
- const [named, places] = [namedPlaces(args), placesIn(root)];
170
- const inLock = new Set(lockLines(store).map(sayingOf));
171
- const inPlace = new Map(places.map((place) => [place, new Set(appliedIn(root, place).map(sayingOf))]));
172
- const deliveryAuthority = authorityFor(lockLines(store), rootSigner(root), signaturesOf(store).admitted);
173
- const delivered = (line) => Boolean(fieldOf(line, 'sig'))
174
- && deliveryAuthority.of(line).kind === 'admitted'
175
- && ledgerLines(store, fieldOf(line, 'by')).includes(line);
176
- const held = (line, at = named.length ? named : byFile.flatMap(([heads, lines]) => (lines.includes(line) ? heads : []))) => at.length
177
- ? at.every((place) => inPlace.get(place)?.has(sayingOf(line)))
178
- : delivered(line) || inLock.has(sayingOf(line)) || places.some((place) => inPlace.get(place)?.has(sayingOf(line)));
179
- if (proposed.every((line) => held(line))) {
180
- if (proposed.some(line => !isConfig(line))) {
181
- try {
182
- await admittedObjects(root, [...signedOwnerLines(store), ...proposed]);
183
- }
184
- catch (e) {
185
- hostOutput('error', `${selfName()}: ${String(e)} · nothing landed\n`);
186
- return { kind: 'exit', code: 1 };
187
- }
188
- }
189
- return { kind: 'once', proposed };
190
- }
191
- const outdated = proposed.filter(line => fieldOf(line, 'sig') && isConfig(line) && Number(fieldOf(line, 'epoch')) !== epoch);
192
- if (outdated.length) {
193
- for (const line of outdated)
194
- hostOutput('error', `SIGNED ${fieldOf(line, 'scope')} · signed by ${fieldOf(line, 'by')} at epoch ${fieldOf(line, 'epoch')}, and this act lands at ${epoch}: sign it again\n`);
195
- hostOutput('error', `${selfName()}: REFUSE·signed nothing landed · ${outdated.length} lines a lane signed stand at no epoch this act\n`);
196
- return { kind: 'exit', code: 1 };
197
- }
198
- const keyFile = host ? undefined : valueOf(args, FLAGS.keyFile);
199
- const keyId = host?.keyId ?? valueOf(args, FLAGS.key) ?? ownerOf(store);
200
- const publicKey = drafted.length ? publicKeyOf(root, keyId) : undefined;
201
- if (drafted.length && !publicKey) {
202
- hostOutput('error', `${selfName()}: unknown key ${keyId} — name it in ${selfName()}.keys\n`);
203
- return { kind: 'exit', code: 2 };
204
- }
205
- let signed = proposed.filter((line) => fieldOf(line, 'sig'));
206
- if (host && drafted.length) {
207
- notCancelled(host.signal);
208
- const selected = authorityFor(lockLines(store), rootSigner(root), signaturesOf(store).admitted).admitted.find(s => s.id === keyId);
209
- for (const line of drafted) {
210
- const parsed = parse(line);
211
- if (parsed.kind !== 'fact' || !selected || authorityAtEpoch({ ...parsed.value.fields, by: keyId, epoch: String(epoch) }, selected, epoch, fieldOf(line, 'scope'), 'authority').kind !== 'admitted')
212
- throw new BoundRefusal('host/receiver-authority', 'REFUSE·host/receiver-authority');
213
- }
214
- }
215
- if (drafted.length) {
216
- let invoke;
217
- try {
218
- invoke = signerFor([...lockStanding(store), ...destinations.flatMap(place => ownLockOf(root, place))], keyId, host?.signer.name ?? valueOf(args, FLAGS.signer), keyFile, host?.signer);
219
- }
220
- catch (error) {
221
- hostOutput('error', `${selfName()}: ${error instanceof Error ? error.message : 'REFUSE·signer unavailable'}\n`);
222
- return { kind: 'exit', code: 1 };
223
- }
224
- const got = await signConsentLot(drafted, { epoch, by: keyId, algorithm: signaturesOf(store).era }, publicKey, signaturesOf(store).admitted, invoke);
225
- if (got.kind === 'refuse') {
226
- hostOutput('error', `${selfName()}: ${got.why}\n`);
227
- return { kind: 'exit', code: 1 };
228
- }
229
- let index = 0;
230
- signed = proposed.map(line => fieldOf(line, 'sig') ? line : got.lines[index++]);
231
- }
232
- const wireLines = [...signedOwnerLines(store), ...signed].flatMap((line) => {
233
- const got = parse(line);
234
- return got.kind === 'fact' ? [got.value.fields] : [];
235
- });
236
- for (const line of signed) {
237
- const got = admittedLine(line, wireLines, Number(fieldOf(line, 'epoch')), foldClaims(signedOwnerLines(store)).standing.filter(one => fieldOf(one, 'scope').startsWith('uses/') && fieldOf(one, 'value') !== 'withdraw'));
238
- if (got.kind !== 'fact') {
239
- hostOutput('error', `${selfName()}: REFUSE·wire ${fieldOf(line, 'scope')} · ${got.why} · nothing landed\n`);
240
- return { kind: 'exit', code: 1 };
241
- }
242
- }
243
- if (refusesStandingPins(root, signed))
244
- return { kind: 'exit', code: 1 };
245
- const taken = retractedTogether(signed);
246
- if (taken.length) {
247
- for (const pair of taken) {
248
- hostOutput('error', `WITHDRAW ${sayingOf(pair.withdraw)}\n`);
249
- hostOutput('error', `NEW ${sayingOf(pair.line)}\n`);
250
- }
251
- hostOutput('error', `${selfName()}: REFUSE·withdraw nothing landed · a withdraw matches a new line in this batch, so it takes that line too\n`);
252
- return { kind: 'exit', code: 1 };
253
- }
254
- const authority = authorityFor([...lockLines(store), ...signed], rootSigner(root), signaturesOf(store).admitted);
255
- const ownership = ownedOf(root, signed, line => authority.of(line).kind === 'admitted', by => authority.admitted.find(one => one.id === by)?.coverage ?? [], named, line => { const heads = byFile.flatMap(([heads, lines]) => lines.some(draft => sayingOf(draft) === sayingOf(line)) ? heads : []); return heads.length ? heads : undefined; });
256
- if (ownership.nowhere.length) {
257
- for (const line of ownership.nowhere)
258
- hostOutput('error', `${selfName()}: REFUSE·signer ${keyId} uncovered ${fieldOf(line, 'scope')} · nothing signed for delivery\n`);
259
- return { kind: 'exit', code: 1 };
260
- }
261
- if (ownership.forked.length) {
262
- for (const one of ownership.forked)
263
- hostOutput('error', `FORKED ${one.place}/${LOCK} · ${one.key} · the lot would leave two standing claims where the lock had one\n`);
264
- hostOutput('error', `${selfName()}: REFUSE·forked nothing landed · ${ownership.forked.length} claims an own lot would fork: a lot for many places lands the same lines at each, and lines meant for one place go in a lot of their own\n`);
265
- return { kind: 'exit', code: 1 };
266
- }
267
- if (refusesAdmission(root, ownership.ledger, lockStanding(store)))
268
- return { kind: 'exit', code: 1 };
269
- if (signed.some(line => !isConfig(line))) {
270
- try {
271
- await admittedObjects(root, [...signedOwnerLines(store), ...signed], text => hostOutput('out', text + '\n'));
272
- }
273
- catch (e) {
274
- hostOutput('error', `${selfName()}: ${e instanceof Error ? e.message : String(e)} · nothing landed\n`);
275
- return { kind: 'exit', code: 1 };
276
- }
277
- }
278
- try {
279
- admissionEvidence(root, ownership.ledger, lockStanding(store));
280
- }
281
- catch (error) {
282
- hostOutput('error', `${selfName()}: ${error instanceof Error ? error.message : String(error)} · nothing landed\n`);
283
- return { kind: 'exit', code: 1 };
284
- }
285
- return { kind: 'signed', signed, epoch, base, ...(drafted.length ? { keyId } : {}) };
286
- }
287
- /**
288
- * accept is one act under the descent of its lines. Every place, then the root where they join, only when those lines
289
- * rest on every place; a line in one place's own lock is that place. It signs the batch at the epoch the lock
290
- * stands at, folds it, judges every take of it, and lands only when all of it holds. A batch refused lands nothing.
291
- * What a batch would move is read before it with `--as rank <batch>`. A cycle's lanes each sign
292
- * their batch with `bound sign` at the epoch the act lands at, and one land takes them all, each line in its signer's
293
- * ledger once it verifies against that signer: one signer never forks itself, and one act never forks itself.
294
- */
295
- export async function accept(root, args) {
296
- const started = Date.now();
297
- const contextFiles = positionalsOf(args);
298
- if (contextFiles.length === 1 && hasContextualPlace(root) && !claimLinesIn(contextFiles[0]).length) {
299
- if (namedPlaces(args).length || valueOf(args, FLAGS.key) || valueOf(args, FLAGS.keyFile) || valueOf(args, FLAGS.signer))
300
- throw Error('REFUSE·contextual place accepts one already signed context envelope');
301
- const result = await landContextualPlace(root, contextFiles[0]);
302
- hostOutput('out', JSON.stringify({ profile: 'place-act-context@1', identity: result.identity, status: result.kind, context: result.context, receipts: result.receipts }) + '\n');
303
- return 0;
304
- }
305
- const named = namedPlaces(args);
306
- const placed = positionalsOf(args).reduce((all, file) => ((places) => (places.length ? claimLinesIn(file).reduce((got, line) => got.set(sayingOf(line), [...new Set([...(got.get(sayingOf(line)) ?? []), ...places])]), all) : all))(placesOfFile(file)), new Map());
307
- const batch = await signedBatch(root, args, positionalsOf(args));
308
- return finishAcceptance(root, args, batch, placed, started);
309
- }
310
- /** Root host boundary, sharing signing, wire, coverage, takes and publication
311
- * with accept(). No file is manufactured for a batch of already-owned bytes. */
312
- export async function acceptRootRecords(root, host) {
313
- requireEffects('Root lot admission');
314
- notCancelled(host.signal);
315
- if (!actResultProfile(lockStanding(storeOf(root))))
316
- throw new BoundRefusal('host/act', 'REFUSE·Root host requires the admitted atomic result profile');
317
- const started = Date.now(), batch = await signedBatch(root, [], [], host);
318
- return finishAcceptance(root, [], batch, new Map(), started, host);
319
- }
320
- async function finishAcceptance(root, args, batch, placed, started, host) {
321
- const named = namedPlaces(args);
322
- if (batch.kind === 'exit')
323
- return batch.code;
324
- if (batch.kind === 'once')
325
- return underTheLock(storeOf(root), 'land', () => repaid(root, batch.proposed, started));
326
- const store = storeOf(root);
327
- const authority = authorityFor([...lockLines(store), ...batch.signed], rootSigner(root), signaturesOf(store).admitted);
328
- const owned = ownedOf(root, batch.signed, (line) => authority.of(line).kind === 'admitted', (by) => authority.admitted.find((one) => one.id === by)?.coverage ?? [], named, (line) => placed.get(sayingOf(line)));
329
- if (owned.nowhere.length) {
330
- for (const line of owned.nowhere)
331
- hostOutput('error', `NOWHERE ${fieldOf(line, 'scope')} · ${((got) => (got.kind === 'admitted' ? 'admitted' : got.why))(authority.of(line))}, and ${named.length ? `no place of ${named.join(', ')} takes it` : 'no one own lock it covers takes it: name the places with --place'}\n`);
332
- hostOutput('error', `${selfName()}: REFUSE·nowhere nothing landed · ${owned.nowhere.length} lines neither the ledger nor an own lock admits: a line is landed signed where it stands, never written in bare\n`);
333
- return 1;
334
- }
335
- const places = placesIn(root);
336
- const pinned = [...new Set([...owned.own.keys(), ...named])];
337
- const touched = pinned.length === 0 && owned.ledger.length ? touchedBy(root, places, owned.ledger, lockStanding(store)) : [];
338
- const every = pinned.length === 0 && touched.length === places.length && places.length > 0;
339
- const regions = (pinned.length ? pinned : every ? places : touched).filter((one) => places.includes(one));
340
- const where = every ? 'every place · then the root, where the places join' : regions.length ? regions.map((one) => `${one}/`).join(' · ') : 'the root alone, where the places join';
341
- hostOutput('out', `ACTS ${where} · ${owned.ledger.length} lines to the ledger${[...owned.own].map(([place, lines]) => ` · ${lines.length} to ${place}'s own lock`).join('')} · before the lock\n`);
342
- const asked = Date.now();
343
- // Root-ledger writes may change grants or inherited policies. Child-only
344
- // lots read that authority through publication, without excluding siblings.
345
- const rootWrite = owned.ledger.length > 0 || every || regions.length === 0;
346
- const enter = rootWrite ? underTheRegions : underAuthorityRegions;
347
- return enter(store, rootWrite ? [...regions, ''] : regions, 'land', () => acceptNow(root, { ...batch, signed: owned.ledger, records: batch.signed }, started, owned, asked, regions, host));
348
- }
349
- async function acceptNow(root, batch, started, owned, asked = started, descent = [], host) {
350
- const waited = Date.now() - asked;
351
- if (waited > 60000)
352
- hostOutput('out', `RED wait ${Math.round(waited / 1000)} s for the lock before the act · a wait over a minute is a red\n`);
353
- const spent = [`sign ${asked - started}`, `wait ${waited}`];
354
- const took = timing(spent);
355
- const { signed, epoch } = batch;
356
- if (refusesStandingPins(root, batch.records ?? signed))
357
- return 1;
358
- const store = storeOf(root);
359
- const currentBase = fullDigest(store, localActLines(root, batch.base.places));
360
- if (currentBase !== batch.base.digest) {
361
- hostOutput('error', `${selfName()}: REFUSE·base moved ${batch.base.digest} → ${currentBase} · nothing landed\n`);
362
- return 1;
363
- }
364
- try {
365
- assertProspectiveRootClockSelection(root, signed);
366
- }
367
- catch (error) {
368
- hostOutput('error', `${selfName()}: ${error instanceof Error ? error.message : String(error)} · nothing landed\n`);
369
- return 1;
370
- }
371
- if (signed.some(line => !isConfig(line))) {
372
- try {
373
- await admittedObjects(root, [...signedOwnerLines(store), ...signed]);
374
- }
375
- catch (e) {
376
- hostOutput('error', `${selfName()}: ${e instanceof Error ? e.message : String(e)} · nothing landed\n`);
377
- return 1;
378
- }
379
- }
380
- const snapshot = took('lines', () => standingOf(root));
381
- if (refusesAdmission(root, signed, snapshot.standing))
382
- return 1;
383
- let evidence;
384
- try {
385
- evidence = took('evidence', () => admissionEvidence(root, signed, snapshot.standing));
386
- }
387
- catch (error) {
388
- hostOutput('error', `${selfName()}: ${error instanceof Error ? error.message : String(error)} · nothing landed\n`);
389
- return 1;
390
- }
391
- const fold = evidence.fold;
392
- const authority = took('authority', () => authorityFor([...lockLines(store), ...signed], rootSigner(root), signaturesOf(store).admitted));
393
- for (const line of signed) {
394
- const verdict = authority.of(line);
395
- if (verdict.kind !== 'admitted') {
396
- hostOutput('error', `${selfName()}: ${verdict.kind === 'refuse' ? verdict.why : `REFUSE·authority grey: ${verdict.why}`}\n`);
397
- return 1;
398
- }
399
- }
400
- const withdraws = signed.filter((line) => fieldOf(line, 'value') === 'withdraw');
401
- const coordinates = evidence.coordinates;
402
- const withdrawn = withdraws.length ? withdrawal(withdraws, lockLines(store)) : null;
403
- const view = `${wordOf(fold.standing, 'families', 'view')}/`;
404
- const lot = fullDigest(store, signed);
405
- const tree = hasVouchedTree(store)
406
- ? fullDigest(store, [...vouchedCoordinates(store)].sort(([a], [b]) => a.localeCompare(b)).map(([coordinate, digest]) => `${coordinate} ${digest}`))
407
- : 'key' in fold && typeof fold.key === 'string' ? fold.key : fullDigest(store, fold.standing);
408
- const cached = keptTakes(keptVerdict(store, tree, lot));
409
- const judged = cached ?? evidence.judged;
410
- if (!cached)
411
- keepVerdict(store, tree, lot, judged.map(packTake));
412
- const refused = judged.filter((one) => one.kind === 'refused' || (one.kind === 'judged' && one.verdict.kind === 'refuse'));
413
- if (refused.length) {
414
- for (const one of refused)
415
- hostOutput('out', `REFUSE take ${one.scope} · ${one.kind === 'judged' ? one.verdict.why : one.kind === 'refused' ? one.why : ''}\n`);
416
- hostOutput('error', `${selfName()}: REFUSE·takes nothing landed · ${refused.length} takes refused: a batch lands whole or not at all\n`);
417
- return 1;
418
- }
419
- const told = took('told', () => standingOf(root, undefined, signed));
420
- for (const name of openedBy(descent, told.standing, signed))
421
- hostOutput('error', `OPEN ${name}\n`);
422
- if (owned.own.size)
423
- layReleases(store, root, told.standing, store);
424
- const resultProfile = actResultProfile(snapshot.standing);
425
- let landed = [];
426
- if (resultProfile) {
427
- const records = batch.records ?? signed;
428
- const placements = [...(signed.length ? [{ place: '.', records: signed }] : []), ...[...owned.own].map(([place, records]) => ({ place: `${place}/${LOCK}`, records }))];
429
- const digest = (bytes) => bytesDigest(store, new TextEncoder().encode(bytes));
430
- const identity = actIdentity(records, { ...resultProfile, digest, placements, localEpoch: epoch });
431
- const folder = writerFor(snapshot.standing, 'fold');
432
- if (!folder)
433
- throw Error('REFUSE·act native result requires a declared fold identity');
434
- const receipt = canonical({ scope: resultProfile.scope, at: resultProfile.context, role: 'writes', form: 'alphabet', measure: 'digest', value: identity, by: folder, epoch: String(epoch) });
435
- const bundle = { records: records.join('\n') + '\n', receipt: receipt + '\n', placements: placements.map(p => ({ place: p.place, records: p.records.join('\n') + '\n' })) };
436
- notCancelled(host?.signal);
437
- host?.prepared?.(identity);
438
- notCancelled(host?.signal);
439
- const committed = await commitLocalAct(store, identity, descent, async () => bundle, intactLocalAct, host?.storage, host?.signal);
440
- host?.committed?.(identity, committed, committed.kind);
441
- // Commitment precedes projections and conformance work. If either fails,
442
- // this public identity still names the admitted act; it is never rollback.
443
- hostOutput('out', `ACT ${identity} · epoch ${epoch} · admitted · conformance not asserted\n`);
444
- for (const line of records)
445
- hostOutput('out', line + '\n');
446
- hostOutput('out', receipt + '\n');
447
- landed = [{ at: 'committed act ' + identity, appended: records.length }];
448
- }
449
- else
450
- landed = took('land', () => [...new Set(signed.map(line => fieldOf(line, 'by')))].map(by => land(store, by, signed.filter(line => fieldOf(line, 'by') === by))));
451
- for (const [place, lines] of owned.own)
452
- landOwned(root, place, lines, resultProfile !== undefined);
453
- return underRootProjection(store, 'projection', async () => {
454
- landSaid(store, writerFor(told.standing, 'fold'), []);
455
- for (const line of signed) {
456
- const value = fieldOf(line, 'value');
457
- if (!/^[a-z0-9-]+:[0-9a-f]{32,}$/.test(value))
458
- continue;
459
- for (const need of locationsOf(fieldOf(line, 'needs')).locations) {
460
- const at = join(root, need);
461
- const bytes = observeFile(at);
462
- if (bytes === undefined)
463
- continue;
464
- if (bytesDigest(store, bytes) === value)
465
- landBlob(store, value, bytes);
466
- }
467
- }
468
- if (coordinates.taken.length) {
469
- for (const path of coordinates.taken) {
470
- if (existsSync(join(root, path)))
471
- rmSync(join(root, path), { recursive: true });
472
- for (let dir = dirname(path); dir !== '.' && existsSync(join(root, dir)) && !entriesIn(join(root, dir)).length; dir = dirname(dir))
473
- rmdirSync(join(root, dir));
474
- }
475
- landCoordinates(store, new Map(), coordinates.taken, `withdraw:epoch-${epoch}`);
476
- for (const path of coordinates.taken)
477
- hostOutput('out', `GONE ${path} · withdrawn by its line\n`);
478
- }
479
- for (const one of judged)
480
- landTake(root, one, []);
481
- const standingAsked = [...signed, ...fold.standing].filter((line) => fieldOf(line, 'role') === 'demands' && fieldOf(line, 'value') !== 'withdraw');
482
- const paidScopes = new Set(paidOf(store, standingAsked, fold.observed, view).paid.map((line) => fieldOf(line, 'scope')));
483
- const late = lateFacts(store, [...signed, ...fold.standing], paidScopes);
484
- if (late.length) {
485
- land(store, 'judge', late);
486
- for (const line of late)
487
- if (fieldOf(line, 'measure') !== 'cone')
488
- hostOutput('out', `LATE ${fieldOf(line, 'scope')} · answered from the landed cone\n`);
489
- }
490
- if (signed.some((line) => fieldOf(line, 'scope').startsWith(`${basename(ownRoot())}/`) && !fieldOf(line, 'scope').split('/').slice(1, -1).includes('uses'))) {
491
- const code = instrumentOf(store, entryOf(root), told.standing, root, ownLock());
492
- if (instrumentKept(store) !== code) {
493
- const open = await closeReceipts(root, store);
494
- instrumentKeep(store, code);
495
- hostOutput('error', `open by instrument · ${open.length}\n`);
496
- }
497
- }
498
- const rendered = took('render', () => renderInto(root, store));
499
- hostOutput('out', `RENDER 0\n`);
500
- const own = new Set([...owned.own.values()].flat()).size;
501
- const perLine = Math.round((Date.now() - started) / Math.max(1, signed.length + own));
502
- const folder = writerFor(fold.standing, 'fold');
503
- const beat = (ms, at) => canonical({ scope: 'beat/accept', role: 'writes', form: 'interval', measure: 'ms', value: `${ms}..${ms}`, by: folder ?? '', at: `place:${at}` });
504
- if (folder !== undefined)
505
- land(store, folder, [beat(perLine, 'line'), beat(1, fold.kept ? 'kept' : 'folded'), beat(Date.now() - started, 'total')]);
506
- hostOutput('out', `FACT signed ${signed.length + own} · landed ${landed.length ? landed.map((one) => `${one.appended} in ${one.at}`).join(' · ') : '0'}${[...owned.own].map(([place, lines]) => ` · ${lines.length} in ${place}/${LOCK}`).join('')} · epoch ${epoch}\n`
507
- + `TARGET ${rendered.standing} claims · ${rendered.forks.length} forks · ${rendered.vacuous.length} vacuous · ${rendered.grey.length} grey · ${rendered.refused.length} refused · readings · no encounters computed · ${Date.now() - started} ms\n`
508
- + `SPENT ${spent.join(' ms · ')} ms · ${signed.length} lines\n`);
509
- if (withdrawn) {
510
- hostOutput('out', `WITHDRAW ${withdrawn.taken.length} taken · ${withdrawn.exact.length} exact on distributive scales · ${withdrawn.open.length} on open scales, not computed\n`);
511
- for (const line of withdrawn.inexact)
512
- hostOutput('out', `INEXACT ${fieldOf(line, 'scope')} · its scale is not distributive: what the others hold is not what they held without it\n`);
513
- }
514
- return 0;
515
- });
516
- }
517
- /**
518
- * A batch landed twice is one: nothing of it lands again. What it left unpaid is judged again, the way it would be now:
519
- * each of its demands the fold counts unpaid is taken, and the takes land only when all of it holds.
520
- */
521
- function repaid(root, proposed, started) {
522
- const store = storeOf(root);
523
- const prior = committedLocalActs(store).find(act => { const lines = act.bundle.records.trimEnd().split('\n'); return lines.length === proposed.length && lines.every((line, i) => line === proposed[i]); });
524
- if (prior) {
525
- hostOutput('out', `ACT ${prior.identity} · epoch ${fieldOf(prior.bundle.receipt.trim(), 'epoch')} · admitted · replay\n` + prior.bundle.records + prior.bundle.receipt);
526
- }
527
- const asked = new Set(proposed.filter((line) => fieldOf(line, 'role') === 'demands').map((line) => fieldOf(line, 'scope')));
528
- const view = `${wordOf(foldClaims(signedOwnerLines(store)).standing, 'families', 'view')}/`;
529
- const standingAsked = signedDemands(store).filter((line) => asked.has(fieldOf(line, 'scope')) && !fieldOf(line, 'scope').startsWith(view));
530
- const owed = paidOf(store, standingAsked, [], view).missing;
531
- if (!owed.length) {
532
- hostOutput('out', `ONCE ${proposed.length} lines · every one already landed and every demand of it paid: a batch landed twice is one, nothing landed\n`);
533
- return 0;
534
- }
535
- const judged = owed.map((line) => judgeDemand(root, line));
536
- hostOutput('out', `ONCE ${proposed.length} lines · every one already landed · ${owed.length} of its demands unpaid, judged again\n`);
537
- if (judged.every((one) => one.kind === 'owed')) {
538
- for (const one of judged)
539
- landTake(root, one, []);
540
- return 0;
541
- }
542
- const refused = judged.filter((one) => one.kind === 'refused' || (one.kind === 'judged' && one.verdict.kind === 'refuse'));
543
- if (refused.length) {
544
- for (const one of refused)
545
- hostOutput('out', `REFUSE take ${one.scope} · ${one.kind === 'judged' ? one.verdict.why : one.kind === 'refused' ? one.why : ''}\n`);
546
- hostOutput('error', `${selfName()}: REFUSE·takes nothing landed · ${refused.length} takes refused: what a batch left unpaid is paid whole or not at all\n`);
547
- return 1;
548
- }
549
- const standing = standingOf(root);
550
- for (const one of judged)
551
- landTake(root, one, []);
552
- landSaid(store, writerFor(standing.standing, 'fold'), []);
553
- const unpaidStanding = standing.standing.filter((line) => fieldOf(line, 'role') === 'demands' && fieldOf(line, 'value') !== 'withdraw');
554
- const paidScopes = new Set(paidOf(store, unpaidStanding, [], `${wordOf(standing.standing, 'families', 'view')}/`).paid.map((line) => fieldOf(line, 'scope')));
555
- const late = lateFacts(store, standing.standing, paidScopes);
556
- if (late.length) {
557
- land(store, 'judge', late);
558
- for (const line of late)
559
- if (fieldOf(line, 'measure') !== 'cone')
560
- hostOutput('out', `LATE ${fieldOf(line, 'scope')} · answered from the landed cone\n`);
561
- }
562
- const rendered = renderInto(root, store);
563
- hostOutput('out', `RENDER 0\n`);
564
- hostOutput('out', `TARGET ${rendered.standing} claims · ${rendered.forks.length} forks · ${rendered.vacuous.length} vacuous · ${rendered.grey.length} grey · ${rendered.refused.length} refused · readings · no encounters computed · ${Date.now() - started} ms\n`);
565
- return 0;
566
- }
567
- function packTake(one) {
568
- return one.kind === 'judged'
569
- ? { kind: one.kind, scope: one.scope, demand: one.demand, locations: one.locations, before: [...one.before], after: [...one.after], verdict: one.verdict, ignored: [...one.ignored] }
570
- : one;
571
- }
572
- function keptTakes(raw) {
573
- if (raw === undefined)
574
- return undefined;
575
- const out = [];
576
- for (const one of raw) {
577
- if (one === null || typeof one !== 'object' || !('kind' in one) || !('scope' in one))
578
- return undefined;
579
- const row = one;
580
- if (row.kind !== 'judged') {
581
- out.push(row);
582
- continue;
583
- }
584
- out.push({
585
- kind: 'judged', scope: row.scope, demand: row.demand, locations: row.locations,
586
- before: new Map(row.before), after: new Map(row.after), verdict: row.verdict, ignored: new Map(row.ignored), started: Date.now(),
587
- });
588
- }
589
- return out;
590
- }
1
+ var ze=Object.defineProperty;var S=(n,t)=>ze(n,"name",{value:t,configurable:!0});import{readingWitnessAdmission as He}from"../host/native/reading-witness-admission.js";import{BoundRefusal as I}from"../host/refusals.js";import{assertHostNotCancelled as de}from"../host/host-controls.js";import{library14_authorityAtEpoch as Ve}from"../vendor/runtime.js";import{requireEffects as Je}from"../host/read-only.js";import{hostOutput as s}from"../host/call-context.js";import{assertProspectiveRootClockSelection as ye}from"../host/root-clock-source.js";import{hasContextualPlace as Xe,landContextualPlace as Qe}from"../host/contextual-place.js";import{commitLocalAct as Ye,intactLocalAct as Ze,committedLocalActs as en}from"../host/ports/local-act.js";import{withoutEffects as nn}from"../host/read-only.js";import{admittedLine as tn}from"../host/selected-topos.js";import{timing as rn}from"../host/timing.js";import{admittedObjects as ue}from"../host/objects.js";import{existsSync as ve,rmdirSync as on,rmSync as sn}from"node:fs";import{dirname as Ee,join as H,basename as dn}from"node:path";import{closeReceipts as an,instrumentKeep as cn,instrumentKept as ln}from"../fold/closed.js";import{bytesDigest as be,fullDigest as Z,instrumentOf as fn,signaturesOf as N}from"../fold/digests.js";import{library14_canonical as Se,library14_LOCK as Re,library14_parse as xe,library14_actIdentity as un,library14_actResultProfile as Fe}from"../vendor/runtime.js";import{fieldOf as o,isConfig as V,foldClaims as je,sayingOf as C,selfName as y}from"../fold/claims.js";import{isReaderLock as mn}from"../fold/observed.js";import{authorityFor as ee,publicKeyOf as Oe,rootSigner as ne,writerFor as ae}from"../fold/signers.js";import{lockLines as M,lockStanding as G}from"../fold/keys.js";import{keepVerdict as hn,keptVerdict as gn,land as ce,landBlob as pn,ledgerLines as wn,storeOf as L}from"../land/ledger.js";import{signConsentLot as kn,verifiesOwnerLine as $n}from"../land/sign.js";import{signerFor as yn}from"../host/signing.js";import{appliedIn as vn,ownLockOf as En,withOwnPreview as bn}from"../fold/signed.js";import{wordOf as J}from"../fold/wire.js";import{hasVouchedTree as Sn,landCoordinates as Rn,locationsOf as xn,vouchedCoordinates as Fn}from"../land/vouched.js";import{entriesIn as jn,observeFile as On}from"../observe/files.js";import{coneOf as An,standingOf as me}from"./place.js";import{ownLock as Cn,ownRoot as Dn}from"../observe/runner.js";import{widenedWithoutWitness as Un}from"../judge/widening.js";import{retractedTogether as Ln,withdrawal as Tn}from"../land/withdraw.js";import{isCeiling as le}from"../fold/configures.js";import{inertIn as In}from"../land/inert.js";import{landSaid as Ae}from"./pass.js";import{currentActSignal as he,underTheLock as Nn,underTheRegions as Mn,underAuthorityRegions as Pn,underRootProjection as Wn,underRootAuthority as Bn}from"../land/act.js";import{openedBy as Gn}from"../fold/opened.js";import{touchedBy as Kn}from"../fold/reach.js";import{landOwned as _n,ownedOf as Ce}from"../land/owned.js";import{layReleases as qn}from"../host/release.js";import{foundableIn as zn,placesIn as ge}from"../fold/places.js";import{outsideTheirCapsule as Hn}from"../fold/own.js";import{lateFacts as De}from"../judge/late.js";import{paidOf as pe}from"../fold/paid.js";import{aliasPinned as Vn}from"../land/alias.js";import{admitStandingPins as Ue}from"../land/standing-pin.js";import{coordinatesWithdrawn as Jn}from"../land/leaving.js";import{ownerOf as Xn,epochOf as Le,localActLines as Te,forksItself as Qn,forksJoinedBy as Yn,renderInto as Ie,signedDemands as Zn,signedOwnerLines as te}from"./owner.js";import{claimLinesIn as we,entryOf as Ne,namedPlaces as ie,placesOfFile as Me,positionalsOf as ke,valueOf as X}from"./args.js";import{FLAGS as Q}from"./names.js";import{judgeDemand as Pe,landTake as $e}from"./takes.js";function et(n,t,d,r){if(!Number.isSafeInteger(r))throw new I("admission/clock","REFUSE\xB7admission clock is required");return nn(()=>{const m=L(n);ye(n,t);const p=!t.some(mn)&&t.some(le),u=p?An(n,Ne(n),t.filter(le)):{standing:d,observed:[],own:{},kept:!0};if(In(t,{standing:u.standing,ceiling:le,signsReader:!p,observed:u.observed,own:u.own,epoch:Le([...M(m),...t])}).length)throw new I("admission/inert","REFUSE\xB7inert no existing reading meets these ceilings; fold the declared inputs first");const f=Jn(n,m,t,[...t,...d]);if(f.refused.length)throw new I("admission/withdraw",`REFUSE\xB7withdraw a file is still read: ${f.refused.map(i=>`${i.path} by ${i.by}`).join(" \xB7 ")}`);const h=`${J(G(m),"families","view")}/`,a=t.filter(i=>V(i)&&o(i,"role")==="demands"&&o(i,"value")!=="withdraw"&&!o(i,"scope").startsWith(h)).map(i=>{const j=o(i,"scope");return d.some(E=>V(E)&&o(E,"role")==="demands"&&o(E,"value")!=="withdraw"&&o(E,"scope")===j&&o(E,"form")===o(i,"form")&&o(E,"measure")===o(i,"measure"))?Pe(n,i,{now:r}):{kind:"owed",scope:j,why:"new demand declared; no conformance reading is claimed"}}),g=a.filter(i=>i.kind==="refused"||i.kind==="judged"&&i.verdict.kind==="refuse");if(g.length)throw new I("admission/takes",`REFUSE\xB7takes ${g.map(i=>`${i.scope}: ${i.kind==="judged"?i.verdict.why:i.kind==="refused"?i.why:""}`).join(" \xB7 ")}`);return{coordinates:f,judged:a,fold:u}})}S(et,"admissionEvidence");function We(n,t,d,r){try{return{kind:"fact",evidence:et(n,t,d,r)}}catch(m){return{kind:"refuse",code:m instanceof I?m.code:"admission/evidence",diagnostic:m instanceof Error?m.message:String(m)}}}S(We,"admissionEvidenceResult");function nt(n,t,d){return n.every(d)?[]:n.filter(r=>o(r,"sig")&&V(r)&&Number(o(r,"epoch"))!==t)}S(nt,"configurationEpochCheck");function tt(n,t,d=[],r){const m=L(n),p=te(m),u=je(p).standing,k=[...p,...t].flatMap(g=>{const i=xe(g);return i.kind==="fact"?[i.value.fields]:[]});for(const g of t){const i=tn(g,k,Number(o(g,"epoch")),u.filter(j=>o(j,"scope").startsWith("uses/")&&o(j,"value")!=="withdraw"));if(i.kind!=="fact")return{kind:"refuse",code:"wire",evidence:[g,i],diagnostic:i.why}}try{Ue(n,t)}catch(g){return{kind:"refuse",code:"standing-pin",evidence:t,diagnostic:g instanceof Error?g.message:String(g)}}const f=Ln(t);if(f.length)return{kind:"refuse",code:"withdraw",evidence:f,diagnostic:"a withdrawal takes a new line in the same batch"};const h=ee([...M(m),...t],ne(n),N(m).admitted),a=bn(n,()=>Ce(n,t,g=>h.of(g).kind==="admitted",g=>h.admitted.find(i=>i.id===g)?.coverage??[],d,r));return a.nowhere.length?{kind:"refuse",code:"signer",evidence:a.nowhere,diagnostic:"the requested records are not covered at their selected destination"}:a.forked.length?{kind:"refuse",code:"forked",evidence:a.forked,diagnostic:"the lot would fork a selected own lock"}:{kind:"fact",ownership:a}}S(tt,"configurationAdmissionGuards");function it(n,t,d,r=d,m="."){const p=He(n,t,d,r,m);if(p.kind==="ask")return p;if(p.kind==="refuse")return{kind:"refuse",code:p.code,evidence:p.evidence,diagnostic:p.why};const u=Un(t,d,le,J(r,"at-classes","witness"));return u.length?{kind:"ask",code:"widening",evidence:u,needs:u.map(k=>"witness:"+o(k,"scope"))}:{kind:"fact",evidence:p.evidence}}S(it,"admissionWideningChecks");function rt(n,t,d){const r=it(n,t,d);if(r.kind!=="fact")return r;const m=L(n),p=Hn(n,d,t);if(p.length)return{kind:"refuse",code:"outside",evidence:p,diagnostic:"a reader or capsule lands in its own world"};const u=Yn(m,t).filter(f=>Qn(f.lines)||f.lines.filter(h=>t.includes(h)).length>1);if(u.length)return{kind:"refuse",code:"fork",evidence:u,diagnostic:"one signer and one act cannot fork themselves"};const k=Vn(n,t);return k.length?{kind:"refuse",code:"alias",evidence:k,diagnostic:"an alias is still named by a pin"}:{kind:"fact",evidence:r.evidence}}S(rt,"admissionChecks");function Be(n,t,d){const r=rt(n,t,d);if(r.kind==="fact")return!1;if(r.kind==="ask"&&r.code==="reading-witness")s("error",`${y()}: REFUSE\xB7reading-witness ${r.needs.join(" \xB7 ")} \xB7 nothing landed
2
+ `);else if(r.kind==="ask"){for(const m of r.evidence)s("error",`WIDER ${o(m,"scope")} \xB7 ${o(m,"value")}
3
+ `);s("error",`${y()}: REFUSE\xB7widening nothing landed \xB7 a ceiling that admits more than it did gives back freedom the lock had spent: sign it under a witness that names what made the old ceiling wrong
4
+ `)}else s("error",`${y()}: REFUSE\xB7${r.code} nothing landed \xB7 ${r.diagnostic}
5
+ `);return!0}S(Be,"refusesAdmission");function ot(n,t){try{return Ue(n,t),!1}catch(d){return s("error",`${y()}: ${d instanceof Error?d.message:String(d)}
6
+ `),!0}}S(ot,"refusesStandingPins");async function Ge(n,t,d,r){const m=r?[[[],r.records]]:d.map(e=>[Me(e),we(e)]),p=m.flatMap(([,e])=>e);if(!p.length)return s("error",`${y()}: a batch is a file with claim lines
7
+ `),{kind:"exit",code:2};const u=p.filter(e=>!o(e,"sig")),k=u.filter(e=>o(e,"epoch")||!["","target"].includes(o(e,"by")));if(k.length){for(const e of k)s("error",`BARE ${o(e,"scope")} \xB7 by=${o(e,"by")||"\u2205"}${o(e,"epoch")?` epoch=${o(e,"epoch")}`:""}
8
+ `);return s("error",`${y()}: REFUSE\xB7bare nothing landed \xB7 ${k.length} lines name a signer or an epoch they were not signed with: a drafted line proposes by=target and sign signs it, a line a lane signed carries its sig
9
+ `),{kind:"exit",code:1}}const f=L(n),h=[...new Set([...ie(t),...m.flatMap(([e])=>e)])],a=G(f),g=h.filter(e=>!ge(n).includes(e)&&!zn(n,a,J(a,"families","region"),e));if(g.length)return s("error",`${y()}: REFUSE\xB7place nothing landed \xB7 ${g.join(", ")} is no place of the tree, and no line of the root founds it: --place names the own lock a line lands in
10
+ `),{kind:"exit",code:2};const i=Te(n,h),j={digest:Z(f,i),places:h},v=Le(i)+1,E=p.filter(e=>o(e,"sig")).flatMap(e=>((w,R)=>R===void 0||!$n(e,R,N(f).admitted)?[`${o(e,"scope")} \xB7 the signature does not hold for ${w||"\u2205"}`]:[])(o(e,"by"),Oe(n,o(e,"by"))));if(E.length){for(const e of E)s("error",`SIGNED ${e}
11
+ `);return s("error",`${y()}: REFUSE\xB7signed nothing landed \xB7 ${E.length} lines a lane signed stand at no epoch this act
12
+ `),{kind:"exit",code:1}}const[c,x]=[ie(t),ge(n)],K=new Set(M(f).map(C)),b=new Map(x.map(e=>[e,new Set(vn(n,e).map(C))])),O=ee(M(f),ne(n),N(f).admitted),P=S(e=>!!o(e,"sig")&&O.of(e).kind==="admitted"&&wn(f,o(e,"by")).includes(e),"delivered"),re=S((e,w=c.length?c:m.flatMap(([R,$])=>$.includes(e)?R:[]))=>w.length?w.every(R=>b.get(R)?.has(C(e))):P(e)||K.has(C(e))||x.some(R=>b.get(R)?.has(C(e))),"held");if(p.every(e=>re(e))){if(p.some(e=>!V(e)))try{await ue(n,[...te(f),...p])}catch(e){return s("error",`${y()}: ${String(e)} \xB7 nothing landed
13
+ `),{kind:"exit",code:1}}return{kind:"once",proposed:p}}const _=nt(p,v,re);if(_.length){for(const e of _)s("error",`SIGNED ${o(e,"scope")} \xB7 signed by ${o(e,"by")} at epoch ${o(e,"epoch")}, and this act lands at ${v}: sign it again
14
+ `);return s("error",`${y()}: REFUSE\xB7signed nothing landed \xB7 ${_.length} lines a lane signed stand at no epoch this act
15
+ `),{kind:"exit",code:1}}const oe=r?void 0:X(t,Q.keyFile),A=r?.keyId??X(t,Q.key)??Xn(f),q=u.length?Oe(n,A):void 0;if(u.length&&!q)return s("error",`${y()}: unknown key ${A} \u2014 name it in ${y()}.keys
16
+ `),{kind:"exit",code:2};let D=p.filter(e=>o(e,"sig"));if(r&&u.length){de(r.signal);const e=ee(M(f),ne(n),N(f).admitted).admitted.find(w=>w.id===A);for(const w of u){const R=xe(w);if(R.kind!=="fact"||!e||Ve({...R.value.fields,by:A,epoch:String(v)},e,v,o(w,"scope"),"authority").kind!=="admitted")throw new I("host/receiver-authority","REFUSE\xB7host/receiver-authority")}}if(u.length){let e;try{e=yn([...G(f),...h.flatMap($=>En(n,$))],A,r?.signer.name??X(t,Q.signer),oe,r?.signer)}catch($){if($ instanceof I)throw $;return s("error",`${y()}: ${$ instanceof Error?$.message:"REFUSE\xB7signer unavailable"}
17
+ `),{kind:"exit",code:1}}const w=await kn(u,{epoch:v,by:A,algorithm:N(f).era},q,N(f).admitted,e);if(w.kind==="refuse")return s("error",`${y()}: ${w.why}
18
+ `),{kind:"exit",code:1};let R=0;D=p.map($=>o($,"sig")?$:w.lines[R++])}const U=tt(n,D,c,e=>{const w=m.flatMap(([R,$])=>$.some(B=>C(B)===C(e))?R:[]);return w.length?w:void 0});if(U.kind==="refuse")return s("error",`${y()}: REFUSE\xB7${U.code} ${U.diagnostic} \xB7 nothing landed
19
+ `),{kind:"exit",code:1};const T=U.ownership;if(Be(n,T.ledger,G(f)))return{kind:"exit",code:1};if(D.some(e=>!V(e)))try{await ue(n,[...te(f),...D],e=>s("out",e+`
20
+ `))}catch(e){return s("error",`${y()}: ${e instanceof Error?e.message:String(e)} \xB7 nothing landed
21
+ `),{kind:"exit",code:1}}const W=await Bn(f,"prospective admission evidence",()=>We(n,T.ledger,G(f),Date.now()));return W.kind==="refuse"?(s("error",`${y()}: ${W.diagnostic} \xB7 nothing landed
22
+ `),{kind:"exit",code:1}):{kind:"signed",signed:D,epoch:v,base:j,...u.length?{keyId:A}:{}}}S(Ge,"signedBatch");async function ci(n,t){const d=Date.now(),r=ke(t);if(r.length===1&&Xe(n)&&!we(r[0]).length){if(ie(t).length||X(t,Q.key)||X(t,Q.keyFile)||X(t,Q.signer))throw Error("REFUSE\xB7contextual place accepts one already signed context envelope");const k=await Qe(n,r[0]);return s("out",JSON.stringify({profile:"place-act-context@1",identity:k.identity,status:k.kind,context:k.context,receipts:k.receipts})+`
23
+ `),0}const m=ie(t),p=ke(t).reduce((k,f)=>(h=>h.length?we(f).reduce((a,g)=>a.set(C(g),[...new Set([...a.get(C(g))??[],...h])]),k):k)(Me(f)),new Map),u=await Ge(n,t,ke(t));return Ke(n,t,u,p,d)}S(ci,"accept");async function li(n,t){if(Je("Root lot admission"),de(t.signal),!Fe(G(L(n))))throw new I("host/act","REFUSE\xB7Root host requires the admitted atomic result profile");const d=Date.now(),r=await Ge(n,[],[],t);return Ke(n,[],r,new Map,d,t)}S(li,"acceptRootRecords");async function Ke(n,t,d,r,m,p){const u=ie(t);if(d.kind==="exit")return d.code;if(d.kind==="once")return Nn(L(n),"land",()=>dt(n,d.proposed,m));const k=L(n),f=ee([...M(k),...d.signed],ne(n),N(k).admitted),h=Ce(n,d.signed,b=>f.of(b).kind==="admitted",b=>f.admitted.find(O=>O.id===b)?.coverage??[],u,b=>r.get(C(b)));if(h.nowhere.length){for(const b of h.nowhere)s("error",`NOWHERE ${o(b,"scope")} \xB7 ${(O=>O.kind==="admitted"?"admitted":O.why)(f.of(b))}, and ${u.length?`no place of ${u.join(", ")} takes it`:"no one own lock it covers takes it: name the places with --place"}
24
+ `);return s("error",`${y()}: REFUSE\xB7nowhere nothing landed \xB7 ${h.nowhere.length} lines neither the ledger nor an own lock admits: a line is landed signed where it stands, never written in bare
25
+ `),1}const a=ge(n),g=[...new Set([...h.own.keys(),...u])],i=g.length===0&&h.ledger.length?Kn(n,a,h.ledger,G(k)):[],j=g.length===0&&i.length===a.length&&a.length>0,v=(g.length?g:j?a:i).filter(b=>a.includes(b)),E=j?"every place \xB7 then the root, where the places join":v.length?v.map(b=>`${b}/`).join(" \xB7 "):"the root alone, where the places join";s("out",`ACTS ${E} \xB7 ${h.ledger.length} lines to the ledger${[...h.own].map(([b,O])=>` \xB7 ${O.length} to ${b}'s own lock`).join("")} \xB7 before the lock
26
+ `);const c=Date.now(),x=h.ledger.length>0||j||v.length===0;return(x?Mn:Pn)(k,x?[...v,""]:v,"land",()=>st(n,{...d,signed:h.ledger,records:d.signed},m,h,c,v,p))}S(Ke,"finishAcceptance");async function st(n,t,d,r,m=d,p=[],u){const k=Date.now()-m;k>6e4&&s("out",`RED wait ${Math.round(k/1e3)} s for the lock before the act \xB7 a wait over a minute is a red
27
+ `);const f=[`sign ${m-d}`,`wait ${k}`],h=rn(f),{signed:a,epoch:g}=t;if(ot(n,t.records??a))return 1;const i=L(n),j=Z(i,Te(n,t.base.places));if(j!==t.base.digest)return s("error",`${y()}: REFUSE\xB7base moved ${t.base.digest} \u2192 ${j} \xB7 nothing landed
28
+ `),1;try{ye(n,a)}catch(e){return s("error",`${y()}: ${e instanceof Error?e.message:String(e)} \xB7 nothing landed
29
+ `),1}if(a.some(e=>!V(e)))try{await ue(n,[...te(i),...a])}catch(e){return s("error",`${y()}: ${e instanceof Error?e.message:String(e)} \xB7 nothing landed
30
+ `),1}const v=h("lines",()=>me(n));if(Be(n,a,v.standing))return 1;let E;const c=h("evidence",()=>We(n,a,v.standing,Date.now()));if(c.kind==="refuse")return s("error",`${y()}: ${c.diagnostic} \xB7 nothing landed
31
+ `),1;E=c.evidence;const x=E.fold,K=h("authority",()=>ee([...M(i),...a],ne(n),N(i).admitted));for(const e of a){const w=K.of(e);if(w.kind!=="admitted")return s("error",`${y()}: ${w.kind==="refuse"?w.why:`REFUSE\xB7authority grey: ${w.why}`}
32
+ `),1}const b=a.filter(e=>o(e,"value")==="withdraw"),O=E.coordinates,P=b.length?Tn(b,M(i)):null,re=`${J(x.standing,"families","view")}/`,_=Z(i,a),oe=Sn(i)?Z(i,[...Fn(i)].sort(([e],[w])=>e.localeCompare(w)).map(([e,w])=>`${e} ${w}`)):"key"in x&&typeof x.key=="string"?x.key:Z(i,x.standing),A=ct(gn(i,oe,_)),q=A??E.judged;A||hn(i,oe,_,q.map(at));const D=q.filter(e=>e.kind==="refused"||e.kind==="judged"&&e.verdict.kind==="refuse");if(D.length){for(const e of D)s("out",`REFUSE take ${e.scope} \xB7 ${e.kind==="judged"?e.verdict.why:e.kind==="refused"?e.why:""}
33
+ `);return s("error",`${y()}: REFUSE\xB7takes nothing landed \xB7 ${D.length} takes refused: a batch lands whole or not at all
34
+ `),1}const U=h("told",()=>me(n,void 0,a));for(const e of Gn(p,U.standing,a))s("error",`OPEN ${e}
35
+ `);r.own.size&&qn(i,n,U.standing,i);const T=Fe(v.standing);let W=[];if(T){const e=t.records??a,w=[...a.length?[{place:".",records:a}]:[],...[...r.own].map(([l,F])=>({place:`${l}/${Re}`,records:F}))],$=un(e,{...T,digest:S(l=>be(i,new TextEncoder().encode(l)),"digest"),placements:w,localEpoch:g}),B=ae(v.standing,"fold");if(!B)throw Error("REFUSE\xB7act native result requires a declared fold identity");const se=Se({scope:T.scope,at:T.context,role:"writes",form:"alphabet",measure:"digest",value:$,by:B,epoch:String(g)}),Y={records:e.join(`
36
+ `)+`
37
+ `,receipt:se+`
38
+ `,placements:w.map(l=>({place:l.place,records:l.records.join(`
39
+ `)+`
40
+ `}))};de(u?.signal??he()),u?.prepared?.($),de(u?.signal??he());const z=await Ye(i,$,p,async()=>Y,Ze,u?.storage,u?.signal??he());u?.committed?.($,z,z.kind),s("out",`ACT ${$} \xB7 epoch ${g} \xB7 admitted \xB7 conformance not asserted
41
+ `);for(const l of e)s("out",l+`
42
+ `);s("out",se+`
43
+ `),W=[{at:"committed act "+$,appended:e.length}]}else W=h("land",()=>[...new Set(a.map(e=>o(e,"by")))].map(e=>ce(i,e,a.filter(w=>o(w,"by")===e))));for(const[e,w]of r.own)_n(n,e,w,T!==void 0);return Wn(i,"projection",async()=>{Ae(i,ae(U.standing,"fold"),[]);for(const l of a){const F=o(l,"value");if(/^[a-z0-9-]+:[0-9a-f]{32,}$/.test(F))for(const _e of xn(o(l,"needs")).locations){const qe=H(n,_e),fe=On(qe);fe!==void 0&&be(i,fe)===F&&pn(i,F,fe)}}if(O.taken.length){for(const l of O.taken){ve(H(n,l))&&sn(H(n,l),{recursive:!0});for(let F=Ee(l);F!=="."&&ve(H(n,F))&&!jn(H(n,F)).length;F=Ee(F))on(H(n,F))}Rn(i,new Map,O.taken,`withdraw:epoch-${g}`);for(const l of O.taken)s("out",`GONE ${l} \xB7 withdrawn by its line
44
+ `)}for(const l of q)$e(n,l,[]);const e=[...a,...x.standing].filter(l=>o(l,"role")==="demands"&&o(l,"value")!=="withdraw"),w=new Set(pe(i,e,x.observed,re).paid.map(l=>o(l,"scope"))),R=De(i,[...a,...x.standing],w);if(R.length){ce(i,"judge",R);for(const l of R)o(l,"measure")!=="cone"&&s("out",`LATE ${o(l,"scope")} \xB7 answered from the landed cone
45
+ `)}if(a.some(l=>o(l,"scope").startsWith(`${dn(Dn())}/`)&&!o(l,"scope").split("/").slice(1,-1).includes("uses"))){const l=fn(i,Ne(n),U.standing,n,Cn());if(ln(i)!==l){const F=await an(n,i);cn(i,l),s("error",`open by instrument \xB7 ${F.length}
46
+ `)}}const $=h("render",()=>Ie(n,i));s("out",`RENDER 0
47
+ `);const B=new Set([...r.own.values()].flat()).size,se=Math.round((Date.now()-d)/Math.max(1,a.length+B)),Y=ae(x.standing,"fold"),z=S((l,F)=>Se({scope:"beat/accept",role:"writes",form:"interval",measure:"ms",value:`${l}..${l}`,by:Y??"",at:`place:${F}`}),"beat");if(Y!==void 0&&ce(i,Y,[z(se,"line"),z(1,x.kept?"kept":"folded"),z(Date.now()-d,"total")]),s("out",`FACT signed ${a.length+B} \xB7 landed ${W.length?W.map(l=>`${l.appended} in ${l.at}`).join(" \xB7 "):"0"}${[...r.own].map(([l,F])=>` \xB7 ${F.length} in ${l}/${Re}`).join("")} \xB7 epoch ${g}
48
+ TARGET ${$.standing} claims \xB7 ${$.forks.length} forks \xB7 ${$.vacuous.length} vacuous \xB7 ${$.grey.length} grey \xB7 ${$.refused.length} refused \xB7 readings \xB7 no encounters computed \xB7 ${Date.now()-d} ms
49
+ SPENT ${f.join(" ms \xB7 ")} ms \xB7 ${a.length} lines
50
+ `),P){s("out",`WITHDRAW ${P.taken.length} taken \xB7 ${P.exact.length} exact on distributive scales \xB7 ${P.open.length} on open scales, not computed
51
+ `);for(const l of P.inexact)s("out",`INEXACT ${o(l,"scope")} \xB7 its scale is not distributive: what the others hold is not what they held without it
52
+ `)}return 0})}S(st,"acceptNow");function dt(n,t,d){const r=L(n),m=en(r).find(c=>{const x=c.bundle.records.trimEnd().split(`
53
+ `);return x.length===t.length&&x.every((K,b)=>K===t[b])});m&&s("out",`ACT ${m.identity} \xB7 epoch ${o(m.bundle.receipt.trim(),"epoch")} \xB7 admitted \xB7 replay
54
+ `+m.bundle.records+m.bundle.receipt);const p=new Set(t.filter(c=>o(c,"role")==="demands").map(c=>o(c,"scope"))),u=`${J(je(te(r)).standing,"families","view")}/`,k=Zn(r).filter(c=>p.has(o(c,"scope"))&&!o(c,"scope").startsWith(u)),f=pe(r,k,[],u).missing;if(!f.length)return s("out",`ONCE ${t.length} lines \xB7 every one already landed and every demand of it paid: a batch landed twice is one, nothing landed
55
+ `),0;const h=f.map(c=>Pe(n,c));if(s("out",`ONCE ${t.length} lines \xB7 every one already landed \xB7 ${f.length} of its demands unpaid, judged again
56
+ `),h.every(c=>c.kind==="owed")){for(const c of h)$e(n,c,[]);return 0}const a=h.filter(c=>c.kind==="refused"||c.kind==="judged"&&c.verdict.kind==="refuse");if(a.length){for(const c of a)s("out",`REFUSE take ${c.scope} \xB7 ${c.kind==="judged"?c.verdict.why:c.kind==="refused"?c.why:""}
57
+ `);return s("error",`${y()}: REFUSE\xB7takes nothing landed \xB7 ${a.length} takes refused: what a batch left unpaid is paid whole or not at all
58
+ `),1}const g=me(n);for(const c of h)$e(n,c,[]);Ae(r,ae(g.standing,"fold"),[]);const i=g.standing.filter(c=>o(c,"role")==="demands"&&o(c,"value")!=="withdraw"),j=new Set(pe(r,i,[],`${J(g.standing,"families","view")}/`).paid.map(c=>o(c,"scope"))),v=De(r,g.standing,j);if(v.length){ce(r,"judge",v);for(const c of v)o(c,"measure")!=="cone"&&s("out",`LATE ${o(c,"scope")} \xB7 answered from the landed cone
59
+ `)}const E=Ie(n,r);return s("out",`RENDER 0
60
+ `),s("out",`TARGET ${E.standing} claims \xB7 ${E.forks.length} forks \xB7 ${E.vacuous.length} vacuous \xB7 ${E.grey.length} grey \xB7 ${E.refused.length} refused \xB7 readings \xB7 no encounters computed \xB7 ${Date.now()-d} ms
61
+ `),0}S(dt,"repaid");function at(n){return n.kind==="judged"?{kind:n.kind,scope:n.scope,demand:n.demand,locations:n.locations,before:[...n.before],after:[...n.after],verdict:n.verdict,ignored:[...n.ignored]}:n}S(at,"packTake");function ct(n){if(n===void 0)return;const t=[];for(const d of n){if(d===null||typeof d!="object"||!("kind"in d)||!("scope"in d))return;const r=d;if(r.kind!=="judged"){t.push(r);continue}t.push({kind:"judged",scope:r.scope,demand:r.demand,locations:r.locations,before:new Map(r.before),after:new Map(r.after),verdict:r.verdict,ignored:new Map(r.ignored),started:Date.now()})}return t}S(ct,"keptTakes");export{ci as accept,li as acceptRootRecords,rt as admissionChecks,et as admissionEvidence,We as admissionEvidenceResult,it as admissionWideningChecks,tt as configurationAdmissionGuards,nt as configurationEpochCheck,Ge as signedBatch};