@lapxo/bound 0.2.4 → 0.2.5

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 (250) hide show
  1. package/CITATION.cff +1 -1
  2. package/TARGET.bound +44 -39
  3. package/dist/cli/accept.js +72 -590
  4. package/dist/cli/act-result.js +3 -103
  5. package/dist/cli/args.js +3 -44
  6. package/dist/cli/custodian.js +2 -29
  7. package/dist/cli/host.js +4 -32
  8. package/dist/cli/names.js +1 -12
  9. package/dist/cli/native-descendant.js +1 -19
  10. package/dist/cli/native.js +3 -60
  11. package/dist/cli/observe.js +1 -13
  12. package/dist/cli/owner.js +3 -139
  13. package/dist/cli/pass.js +21 -321
  14. package/dist/cli/place.js +6 -282
  15. package/dist/cli/release-result.js +3 -80
  16. package/dist/cli/retained-judgment.js +1 -25
  17. package/dist/cli/standing-result.js +4 -19
  18. package/dist/cli/takes.js +10 -112
  19. package/dist/cli/verb.d.ts +1 -2
  20. package/dist/cli/verb.js +83 -684
  21. package/dist/engine/computation.js +2 -0
  22. package/dist/engine/conformance.js +4 -0
  23. package/dist/engine/encoding.js +1 -2
  24. package/dist/engine/index.d.ts +1 -13
  25. package/dist/engine/index.js +2 -11
  26. package/dist/engine/object.js +1 -38
  27. package/dist/engine/ports.js +2 -117
  28. package/dist/fold/admission-history.js +1 -17
  29. package/dist/fold/bootstrap-anchor.js +1 -28
  30. package/dist/fold/ceilings.js +1 -142
  31. package/dist/fold/claims.js +2 -132
  32. package/dist/fold/closed.js +24 -235
  33. package/dist/fold/configures.js +1 -25
  34. package/dist/fold/digests.js +10 -226
  35. package/dist/fold/evidence.js +1 -22
  36. package/dist/fold/fold-worker.js +1 -13
  37. package/dist/fold/kept.js +12 -173
  38. package/dist/fold/keys.js +3 -91
  39. package/dist/fold/laid.js +3 -90
  40. package/dist/fold/nos.js +1 -48
  41. package/dist/fold/object.js +1 -2
  42. package/dist/fold/observed.js +27 -534
  43. package/dist/fold/opened.js +1 -33
  44. package/dist/fold/own.js +3 -217
  45. package/dist/fold/paid.js +1 -92
  46. package/dist/fold/place-inputs.js +1 -70
  47. package/dist/fold/places.js +3 -100
  48. package/dist/fold/rank.js +1 -9
  49. package/dist/fold/reach.js +1 -83
  50. package/dist/fold/readers.js +6 -142
  51. package/dist/fold/receipts.js +1 -47
  52. package/dist/fold/region-declarations.js +1 -13
  53. package/dist/fold/region.js +8 -286
  54. package/dist/fold/release-policy.js +1 -101
  55. package/dist/fold/resolved.js +6 -145
  56. package/dist/fold/roles.js +2 -59
  57. package/dist/fold/second.js +4 -71
  58. package/dist/fold/shards.js +12 -100
  59. package/dist/fold/signed.js +3 -81
  60. package/dist/fold/signers.js +1 -54
  61. package/dist/fold/stranger.js +6 -24
  62. package/dist/fold/views.js +1 -66
  63. package/dist/fold/wire.js +1 -46
  64. package/dist/fold/zoom.js +3 -81
  65. package/dist/host/act-cost.js +1 -25
  66. package/dist/host/adapters/keys/ed25519.js +1 -30
  67. package/dist/host/adapters/modules/javascript.js +1 -50
  68. package/dist/host/adapters/transport/http.js +1 -28
  69. package/dist/host/admitted-place.js +1 -35
  70. package/dist/host/archive.js +1 -152
  71. package/dist/host/call-context.js +1 -14
  72. package/dist/host/capsule-process.js +2 -62
  73. package/dist/host/capsule.js +9 -171
  74. package/dist/host/cell-receipts.js +12 -128
  75. package/dist/host/commit-result.js +1 -5
  76. package/dist/host/content-needed.js +1 -8
  77. package/dist/host/content-store.js +1 -31
  78. package/dist/host/contextual-place.js +2 -72
  79. package/dist/host/digest.js +2 -15
  80. package/dist/host/hash.js +1 -9
  81. package/dist/host/host-controls.js +1 -19
  82. package/dist/host/in-process-act.js +3 -84
  83. package/dist/host/in-process-context.js +3 -91
  84. package/dist/host/in-process-root.js +6 -84
  85. package/dist/host/in-process.js +4 -55
  86. package/dist/host/index.d.ts +1 -15
  87. package/dist/host/index.js +1 -7
  88. package/dist/host/io.js +1 -11
  89. package/dist/host/lifetime.js +1 -79
  90. package/dist/host/located.js +6 -105
  91. package/dist/host/native/bounded-file.js +1 -32
  92. package/dist/host/native/command.js +1 -91
  93. package/dist/host/native/control-bridge-worker.js +2 -88
  94. package/dist/host/native/control-bridge.js +1 -110
  95. package/dist/host/native/control-selection.js +1 -32
  96. package/dist/host/native/custody.js +1 -91
  97. package/dist/host/native/deadline.js +1 -28
  98. package/dist/host/native/descendants.js +1 -528
  99. package/dist/host/native/generated-custodian.js +5 -267
  100. package/dist/host/native/generated.js +1 -379
  101. package/dist/host/native/image.js +1 -45
  102. package/dist/host/native/jobs.js +2 -148
  103. package/dist/host/native/loader.js +1 -269
  104. package/dist/host/native/materialize.js +1 -175
  105. package/dist/host/native/module-closure.js +1 -130
  106. package/dist/host/native/module-delivery.d.ts +1 -62
  107. package/dist/host/native/module-delivery.js +1 -151
  108. package/dist/host/native/module-syntax.js +1 -69
  109. package/dist/host/native/native-binary.js +1 -115
  110. package/dist/host/native/native-program.js +1 -72
  111. package/dist/host/native/node-jobs.js +3 -187
  112. package/dist/host/native/node-launch.js +1 -159
  113. package/dist/host/native/preload.js +1 -45
  114. package/dist/host/native/reading.js +1 -249
  115. package/dist/host/native/receipt-environment.js +1 -41
  116. package/dist/host/native/references.js +1 -30
  117. package/dist/host/native/root.js +1 -37
  118. package/dist/host/native/route.js +1 -216
  119. package/dist/host/native/runtime.js +1 -9
  120. package/dist/host/native-reader-context.js +1 -8
  121. package/dist/host/native-receiver.js +1 -25
  122. package/dist/host/objects.js +1 -38
  123. package/dist/host/order.js +1 -2
  124. package/dist/host/place-act-transaction.js +4 -78
  125. package/dist/host/place-clock-selection.js +5 -124
  126. package/dist/host/ports/ingress.js +2 -57
  127. package/dist/host/ports/local-act.js +5 -183
  128. package/dist/host/ports/place-act.js +1 -134
  129. package/dist/host/ports/publication.js +1 -56
  130. package/dist/host/ports/signing.js +1 -74
  131. package/dist/host/ports/store.js +1 -18
  132. package/dist/host/ports/transport.js +1 -48
  133. package/dist/host/process-lifetime.js +1 -17
  134. package/dist/host/provide.js +1 -183
  135. package/dist/host/read-only.js +1 -9
  136. package/dist/host/reading-closures.js +7 -227
  137. package/dist/host/reading-context.js +1 -53
  138. package/dist/host/reading-identity-types.js +0 -0
  139. package/dist/host/reading-identity.js +3 -0
  140. package/dist/host/reading-preparation.js +6 -0
  141. package/dist/host/reference-authenticated.d.ts +1 -40
  142. package/dist/host/reference-authenticated.js +3 -100
  143. package/dist/host/reference-contracts.js +1 -6
  144. package/dist/host/reference-export.js +6 -81
  145. package/dist/host/reference-native-api.d.ts +1 -3
  146. package/dist/host/reference-native-api.js +1 -3
  147. package/dist/host/reference-native.js +1 -74
  148. package/dist/host/reference-profile.js +1 -63
  149. package/dist/host/reference-standing.js +2 -18
  150. package/dist/host/reference.js +1 -24
  151. package/dist/host/refusals.js +2 -43
  152. package/dist/host/release.js +4 -256
  153. package/dist/host/root-clock-source.js +1 -307
  154. package/dist/host/selected-capsules.js +1 -50
  155. package/dist/host/selected-topos.js +1 -80
  156. package/dist/host/signature-era.js +1 -12
  157. package/dist/host/signing.js +2 -48
  158. package/dist/host/source-content.js +2 -111
  159. package/dist/host/standing-carrier.js +1 -18
  160. package/dist/host/standing-projection.js +1 -50
  161. package/dist/host/timing.js +1 -7
  162. package/dist/host/walk.js +20 -193
  163. package/dist/judge/late.js +1 -33
  164. package/dist/judge/take.js +2 -75
  165. package/dist/judge/widening.js +1 -25
  166. package/dist/land/act.js +8 -336
  167. package/dist/land/alias.js +1 -41
  168. package/dist/land/held.js +1 -23
  169. package/dist/land/inert.js +1 -33
  170. package/dist/land/leaving.js +1 -55
  171. package/dist/land/ledger.js +7 -188
  172. package/dist/land/owned.js +4 -66
  173. package/dist/land/sign.js +1 -53
  174. package/dist/land/standing-pin.js +1 -49
  175. package/dist/land/vouched.js +1 -112
  176. package/dist/land/withdraw.js +1 -24
  177. package/dist/observe/files.js +1 -88
  178. package/dist/observe/identity.js +1 -61
  179. package/dist/observe/match.js +1 -8
  180. package/dist/observe/regions.js +7 -306
  181. package/dist/observe/run.js +2 -41
  182. package/dist/observe/runner.js +4 -101
  183. package/dist/public-types.d.ts +1114 -0
  184. package/dist/render/capsule.js +1 -30
  185. package/dist/render/field.js +1 -40
  186. package/dist/render/names.js +1 -4
  187. package/dist/render/open.js +1 -61
  188. package/dist/render/page.js +1 -7
  189. package/dist/render/receipts.js +1 -47
  190. package/dist/render/shape.js +1 -74
  191. package/dist/render/target.js +4 -52
  192. package/dist/render/view.js +7 -197
  193. package/dist/vendor/50086958553b9376d600583f7dff354196bfeb41170fc6d1482ca7bea7c493e2.LICENSE +21 -0
  194. package/dist/vendor/b3e938d28f88a1851af303a40c749e12ebd5a686daac4f0b343b5cdd2e040419.LICENSE +21 -0
  195. package/dist/vendor/bundle.json +1 -0
  196. package/dist/vendor/library11.js +1 -0
  197. package/dist/vendor/object-provider.js +42 -0
  198. package/dist/vendor/runtime.js +38 -0
  199. package/dist/vendor/sources.json +1 -0
  200. package/dist/wasm/adapter.d.ts +1 -51
  201. package/dist/wasm/adapter.js +1 -180
  202. package/dist/wasm/node-worker.js +1 -13
  203. package/dist/wasm/object.js +1 -76
  204. package/dist/wasm/worker.js +1 -7
  205. package/docs/contracts/closure-delivery.md +1 -1
  206. package/docs/contracts/closure-delivery.publication.json +1 -1
  207. package/docs/contracts/conformance.json +142 -0
  208. package/docs/contracts/determinism.bound +9 -0
  209. package/docs/contracts/engine-object-projection.publication.json +1 -1
  210. package/docs/contracts/engine.md +21 -1
  211. package/docs/contracts/native-publication.inventory.json +2 -1
  212. package/docs/contracts/optional-wasm-adapter.publication.json +1 -1
  213. package/docs/contracts/reading-identity.md +37 -0
  214. package/docs/contracts/reading-identity.publication.json +25 -0
  215. package/docs/contracts/refusals.bound +51 -0
  216. package/docs/contracts/refusals.md +18 -3
  217. package/docs/contracts/refusals.publication.json +2 -2
  218. package/docs/contracts/views.md +8 -0
  219. package/docs/reference.md +1 -0
  220. package/package.json +23 -34
  221. package/receipts.bound +11627 -10323
  222. package/samples/reading-identity/no.json +20 -0
  223. package/samples/reading-identity/yes.json +46 -0
  224. package/vectors/native/reading-identity.vector.json +101 -0
  225. package/vectors/native/refusals.vector.json +104 -0
  226. package/vendor/syntax/LICENSE.md +7 -0
  227. package/vendor/syntax/parser.js +1 -0
  228. package/.github/workflows/release.yml +0 -67
  229. package/.github/workflows/test.yml +0 -35
  230. package/dist/engine/object.d.ts +0 -17
  231. package/dist/engine/ports.d.ts +0 -37
  232. package/dist/fold/claims.d.ts +0 -29
  233. package/dist/host/call-context.d.ts +0 -20
  234. package/dist/host/commit-result.d.ts +0 -6
  235. package/dist/host/in-process-act.d.ts +0 -82
  236. package/dist/host/in-process-context.d.ts +0 -46
  237. package/dist/host/in-process-root.d.ts +0 -117
  238. package/dist/host/in-process.d.ts +0 -41
  239. package/dist/host/native/module-closure.d.ts +0 -35
  240. package/dist/host/native-receiver.d.ts +0 -19
  241. package/dist/host/place-act-transaction.d.ts +0 -24
  242. package/dist/host/place-clock-selection.d.ts +0 -55
  243. package/dist/host/ports/local-act.d.ts +0 -44
  244. package/dist/host/ports/place-act.d.ts +0 -49
  245. package/dist/host/ports/publication.d.ts +0 -10
  246. package/dist/host/reference-export.d.ts +0 -33
  247. package/dist/host/reference-native.d.ts +0 -30
  248. package/dist/host/reference-profile.d.ts +0 -23
  249. package/dist/host/refusals.d.ts +0 -14
  250. package/dist/host/root-clock-source.d.ts +0 -86
@@ -1,590 +1,72 @@
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 _e=Object.defineProperty;var F=(n,r)=>_e(n,"name",{value:r,configurable:!0});import{BoundRefusal as $e}from"../host/refusals.js";import{assertHostNotCancelled as oe}from"../host/host-controls.js";import{library11_authorityAtEpoch as He}from"../vendor/runtime.js";import{requireEffects as qe}from"../host/read-only.js";import{hostOutput as o}from"../host/call-context.js";import{assertProspectiveRootClockSelection as ke}from"../host/root-clock-source.js";import{hasContextualPlace as ze,landContextualPlace as Ve}from"../host/contextual-place.js";import{commitLocalAct as Je,intactLocalAct as Xe,committedLocalActs as Qe}from"../host/ports/local-act.js";import{withoutEffects as Ye}from"../host/read-only.js";import{admittedLine as Ze}from"../host/selected-topos.js";import{timing as en}from"../host/timing.js";import{admittedObjects as le}from"../host/objects.js";import{existsSync as ye,rmdirSync as nn,rmSync as tn}from"node:fs";import{dirname as Ee,join as H,basename as rn}from"node:path";import{closeReceipts as on,instrumentKeep as sn,instrumentKept as an}from"../fold/closed.js";import{bytesDigest as ve,fullDigest as Y,instrumentOf as dn,signaturesOf as I}from"../fold/digests.js";import{library11_canonical as be,library11_LOCK as fe,library11_parse as Se,library11_actIdentity as cn,library11_actResultProfile as Re}from"../vendor/runtime.js";import{fieldOf as t,isConfig as q,foldClaims as Fe,sayingOf as D,selfName as k}from"../fold/claims.js";import{isReaderLock as ln}from"../fold/observed.js";import{authorityFor as Z,publicKeyOf as xe,rootSigner as ee,writerFor as ie}from"../fold/signers.js";import{lockLines as C,lockStanding as z}from"../fold/keys.js";import{keepVerdict as fn,keptVerdict as un,land as se,landBlob as hn,ledgerLines as mn,storeOf as N}from"../land/ledger.js";import{signConsentLot as pn,verifiesOwnerLine as gn}from"../land/sign.js";import{signerFor as wn}from"../host/signing.js";import{appliedIn as $n,ownLockOf as kn}from"../fold/signed.js";import{wordOf as V}from"../fold/wire.js";import{hasVouchedTree as yn,landCoordinates as En,locationsOf as vn,vouchedCoordinates as bn}from"../land/vouched.js";import{entriesIn as Sn,observeFile as Rn}from"../observe/files.js";import{coneOf as Fn,standingOf as ue}from"./place.js";import{ownLock as xn,ownRoot as jn}from"../observe/runner.js";import{widenedWithoutWitness as On}from"../judge/widening.js";import{retractedTogether as Un,withdrawal as An}from"../land/withdraw.js";import{isCeiling as ae}from"../fold/configures.js";import{inertIn as Dn}from"../land/inert.js";import{landSaid as je}from"./pass.js";import{underTheLock as Ln,underTheRegions as Tn,underAuthorityRegions as Cn,underRootProjection as In}from"../land/act.js";import{openedBy as Nn}from"../fold/opened.js";import{touchedBy as Mn}from"../fold/reach.js";import{landOwned as Wn,ownedOf as Oe}from"../land/owned.js";import{layReleases as Pn}from"../host/release.js";import{foundableIn as Bn,placesIn as he}from"../fold/places.js";import{outsideTheirCapsule as Kn}from"../fold/own.js";import{lateFacts as Ue}from"../judge/late.js";import{paidOf as me}from"../fold/paid.js";import{aliasPinned as Gn}from"../land/alias.js";import{admitStandingPins as _n}from"../land/standing-pin.js";import{coordinatesWithdrawn as Hn}from"../land/leaving.js";import{ownerOf as qn,epochOf as Ae,localActLines as De,forksItself as zn,forksJoinedBy as Vn,renderInto as Le,sideOf as Jn,signedDemands as Xn,signedOwnerLines as J}from"./owner.js";import{claimLinesIn as pe,entryOf as Te,namedPlaces as ne,placesOfFile as Ce,positionalsOf as ge,valueOf as X}from"./args.js";import{FLAGS as Q}from"./names.js";import{judgeDemand as Ie,landTake as we}from"./takes.js";function Ne(n,r,c){return Ye(()=>{const i=N(n);ke(n,r);const S=!r.some(ln)&&r.some(ae),y=S?Fn(n,Te(n),r.filter(ae)):{standing:c,observed:[],own:{},kept:!0};if(Dn(r,{standing:y.standing,ceiling:ae,signsReader:!S,observed:y.observed,own:y.own,epoch:Ae([...C(i),...r])}).length)throw Error("REFUSE\xB7inert no existing reading meets these ceilings; fold the declared inputs first");const m=Hn(n,i,r,[...r,...c]);if(m.refused.length)throw Error(`REFUSE\xB7withdraw a file is still read: ${m.refused.map(d=>`${d.path} by ${d.by}`).join(" \xB7 ")}`);const l=`${V(c,"families","view")}/`,g=r.filter(d=>q(d)&&t(d,"role")==="demands"&&t(d,"value")!=="withdraw"&&!t(d,"scope").startsWith(l)).map(d=>{const h=t(d,"scope");return c.some($=>q($)&&t($,"role")==="demands"&&t($,"value")!=="withdraw"&&t($,"scope")===h&&t($,"form")===t(d,"form")&&t($,"measure")===t(d,"measure"))?Ie(n,d):{kind:"owed",scope:h,why:"new demand declared; no conformance reading is claimed"}}),f=g.filter(d=>d.kind==="refused"||d.kind==="judged"&&d.verdict.kind==="refuse");if(f.length)throw Error(`REFUSE\xB7takes ${f.map(d=>`${d.scope}: ${d.kind==="judged"?d.verdict.why:d.kind==="refused"?d.why:""}`).join(" \xB7 ")}`);return{coordinates:m,judged:g,fold:y}})}F(Ne,"admissionEvidence");function Qn(n,r){const c=On(n,r,ae,V(r,"at-classes","witness"));if(c.length){for(const i of c)o("error",`WIDER ${t(i,"scope")} \xB7 ${t(i,"value")}
2
+ `);return o("error",`${k()}: 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
3
+ `),!0}return!1}F(Qn,"refusesWidening");function Me(n,r,c){if(Qn(r,c))return!0;const i=N(n),S=Kn(n,c,r);for(const m of S)o("error",`OUTSIDE ${t(m,"scope")} \xB7 ${t(m,"value")}
4
+ `);if(S.length)return o("error",`${k()}: REFUSE\xB7outside nothing landed \xB7 a reader or a capsule lands in the capsule of its world, never in the wire or the instrument
5
+ `),!0;const y=Vn(i,r).filter(m=>zn(m.lines)||m.lines.filter(l=>r.includes(l)).length>1);if(y.length){for(const m of y){o("error",`FORK ${m.key}
6
+ `);for(const l of m.lines)o("error",` ${r.includes(l)?"new ":"held"} by=${t(l,"by")} ${Jn(l,C(i))}
7
+ `)}return o("error",`${k()}: REFUSE\xB7fork nothing landed \xB7 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
8
+ `),!0}const w=Gn(n,r);if(w.length){for(const m of w)o("error",`ALIAS ${m.scope} \xB7 ${m.digest} \xB7 ${m.by.join(" ")}
9
+ `);return o("error",`${k()}: REFUSE\xB7alias nothing landed \xB7 an alias is withdrawn only when no pin names its digest
10
+ `),!0}return!1}F(Me,"refusesAdmission");function We(n,r){try{return _n(n,r),!1}catch(c){return o("error",`${k()}: ${c instanceof Error?c.message:String(c)}
11
+ `),!0}}F(We,"refusesStandingPins");async function Pe(n,r,c,i){const S=i?[[[],i.records]]:c.map(e=>[Ce(e),pe(e)]),y=S.flatMap(([,e])=>e);if(!y.length)return o("error",`${k()}: a batch is a file with claim lines
12
+ `),{kind:"exit",code:2};const w=y.filter(e=>!t(e,"sig")),m=w.filter(e=>t(e,"epoch")||!["","target"].includes(t(e,"by")));if(m.length){for(const e of m)o("error",`BARE ${t(e,"scope")} \xB7 by=${t(e,"by")||"\u2205"}${t(e,"epoch")?` epoch=${t(e,"epoch")}`:""}
13
+ `);return o("error",`${k()}: REFUSE\xB7bare nothing landed \xB7 ${m.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
14
+ `),{kind:"exit",code:1}}const l=N(n),g=[...new Set([...ne(r),...S.flatMap(([e])=>e)])],f=z(l),d=g.filter(e=>!he(n).includes(e)&&!Bn(n,f,V(f,"families","region"),e));if(d.length)return o("error",`${k()}: REFUSE\xB7place nothing landed \xB7 ${d.join(", ")} is no place of the tree, and no line of the root founds it: --place names the own lock a line lands in
15
+ `),{kind:"exit",code:2};const h=De(n,g),L={digest:Y(l,h),places:g},$=Ae(h)+1,x=y.filter(e=>t(e,"sig")).flatMap(e=>((p,b)=>b===void 0||!gn(e,b,I(l).admitted)?[`${t(e,"scope")} \xB7 the signature does not hold for ${p||"\u2205"}`]:[])(t(e,"by"),xe(n,t(e,"by"))));if(x.length){for(const e of x)o("error",`SIGNED ${e}
16
+ `);return o("error",`${k()}: REFUSE\xB7signed nothing landed \xB7 ${x.length} lines a lane signed stand at no epoch this act
17
+ `),{kind:"exit",code:1}}const[s,T]=[ne(r),he(n)],M=new Set(C(l).map(D)),v=new Map(T.map(e=>[e,new Set($n(n,e).map(D))])),U=Z(C(l),ee(n),I(l).admitted),de=F(e=>!!t(e,"sig")&&U.of(e).kind==="admitted"&&mn(l,t(e,"by")).includes(e),"delivered"),te=F((e,p=s.length?s:S.flatMap(([b,j])=>j.includes(e)?b:[]))=>p.length?p.every(b=>v.get(b)?.has(D(e))):de(e)||M.has(D(e))||T.some(b=>v.get(b)?.has(D(e))),"held");if(y.every(e=>te(e))){if(y.some(e=>!q(e)))try{await le(n,[...J(l),...y])}catch(e){return o("error",`${k()}: ${String(e)} \xB7 nothing landed
18
+ `),{kind:"exit",code:1}}return{kind:"once",proposed:y}}const K=y.filter(e=>t(e,"sig")&&q(e)&&Number(t(e,"epoch"))!==$);if(K.length){for(const e of K)o("error",`SIGNED ${t(e,"scope")} \xB7 signed by ${t(e,"by")} at epoch ${t(e,"epoch")}, and this act lands at ${$}: sign it again
19
+ `);return o("error",`${k()}: REFUSE\xB7signed nothing landed \xB7 ${K.length} lines a lane signed stand at no epoch this act
20
+ `),{kind:"exit",code:1}}const re=i?void 0:X(r,Q.keyFile),A=i?.keyId??X(r,Q.key)??qn(l),G=w.length?xe(n,A):void 0;if(w.length&&!G)return o("error",`${k()}: unknown key ${A} \u2014 name it in ${k()}.keys
21
+ `),{kind:"exit",code:2};let O=y.filter(e=>t(e,"sig"));if(i&&w.length){oe(i.signal);const e=Z(C(l),ee(n),I(l).admitted).admitted.find(p=>p.id===A);for(const p of w){const b=Se(p);if(b.kind!=="fact"||!e||He({...b.value.fields,by:A,epoch:String($)},e,$,t(p,"scope"),"authority").kind!=="admitted")throw new $e("host/receiver-authority","REFUSE\xB7host/receiver-authority")}}if(w.length){let e;try{e=wn([...z(l),...g.flatMap(j=>kn(n,j))],A,i?.signer.name??X(r,Q.signer),re,i?.signer)}catch(j){return o("error",`${k()}: ${j instanceof Error?j.message:"REFUSE\xB7signer unavailable"}
22
+ `),{kind:"exit",code:1}}const p=await pn(w,{epoch:$,by:A,algorithm:I(l).era},G,I(l).admitted,e);if(p.kind==="refuse")return o("error",`${k()}: ${p.why}
23
+ `),{kind:"exit",code:1};let b=0;O=y.map(j=>t(j,"sig")?j:p.lines[b++])}const W=[...J(l),...O].flatMap(e=>{const p=Se(e);return p.kind==="fact"?[p.value.fields]:[]});for(const e of O){const p=Ze(e,W,Number(t(e,"epoch")),Fe(J(l)).standing.filter(b=>t(b,"scope").startsWith("uses/")&&t(b,"value")!=="withdraw"));if(p.kind!=="fact")return o("error",`${k()}: REFUSE\xB7wire ${t(e,"scope")} \xB7 ${p.why} \xB7 nothing landed
24
+ `),{kind:"exit",code:1}}if(We(n,O))return{kind:"exit",code:1};const P=Un(O);if(P.length){for(const e of P)o("error",`WITHDRAW ${D(e.withdraw)}
25
+ `),o("error",`NEW ${D(e.line)}
26
+ `);return o("error",`${k()}: REFUSE\xB7withdraw nothing landed \xB7 a withdraw matches a new line in this batch, so it takes that line too
27
+ `),{kind:"exit",code:1}}const a=Z([...C(l),...O],ee(n),I(l).admitted),E=Oe(n,O,e=>a.of(e).kind==="admitted",e=>a.admitted.find(p=>p.id===e)?.coverage??[],s,e=>{const p=S.flatMap(([b,j])=>j.some(B=>D(B)===D(e))?b:[]);return p.length?p:void 0});if(E.nowhere.length){for(const e of E.nowhere)o("error",`${k()}: REFUSE\xB7signer ${A} uncovered ${t(e,"scope")} \xB7 nothing signed for delivery
28
+ `);return{kind:"exit",code:1}}if(E.forked.length){for(const e of E.forked)o("error",`FORKED ${e.place}/${fe} \xB7 ${e.key} \xB7 the lot would leave two standing claims where the lock had one
29
+ `);return o("error",`${k()}: REFUSE\xB7forked nothing landed \xB7 ${E.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
30
+ `),{kind:"exit",code:1}}if(Me(n,E.ledger,z(l)))return{kind:"exit",code:1};if(O.some(e=>!q(e)))try{await le(n,[...J(l),...O],e=>o("out",e+`
31
+ `))}catch(e){return o("error",`${k()}: ${e instanceof Error?e.message:String(e)} \xB7 nothing landed
32
+ `),{kind:"exit",code:1}}try{Ne(n,E.ledger,z(l))}catch(e){return o("error",`${k()}: ${e instanceof Error?e.message:String(e)} \xB7 nothing landed
33
+ `),{kind:"exit",code:1}}return{kind:"signed",signed:O,epoch:$,base:L,...w.length?{keyId:A}:{}}}F(Pe,"signedBatch");async function er(n,r){const c=Date.now(),i=ge(r);if(i.length===1&&ze(n)&&!pe(i[0]).length){if(ne(r).length||X(r,Q.key)||X(r,Q.keyFile)||X(r,Q.signer))throw Error("REFUSE\xB7contextual place accepts one already signed context envelope");const m=await Ve(n,i[0]);return o("out",JSON.stringify({profile:"place-act-context@1",identity:m.identity,status:m.kind,context:m.context,receipts:m.receipts})+`
34
+ `),0}const S=ne(r),y=ge(r).reduce((m,l)=>(g=>g.length?pe(l).reduce((f,d)=>f.set(D(d),[...new Set([...f.get(D(d))??[],...g])]),m):m)(Ce(l)),new Map),w=await Pe(n,r,ge(r));return Be(n,r,w,y,c)}F(er,"accept");async function nr(n,r){if(qe("Root lot admission"),oe(r.signal),!Re(z(N(n))))throw new $e("host/act","REFUSE\xB7Root host requires the admitted atomic result profile");const c=Date.now(),i=await Pe(n,[],[],r);return Be(n,[],i,new Map,c,r)}F(nr,"acceptRootRecords");async function Be(n,r,c,i,S,y){const w=ne(r);if(c.kind==="exit")return c.code;if(c.kind==="once")return Ln(N(n),"land",()=>Zn(n,c.proposed,S));const m=N(n),l=Z([...C(m),...c.signed],ee(n),I(m).admitted),g=Oe(n,c.signed,v=>l.of(v).kind==="admitted",v=>l.admitted.find(U=>U.id===v)?.coverage??[],w,v=>i.get(D(v)));if(g.nowhere.length){for(const v of g.nowhere)o("error",`NOWHERE ${t(v,"scope")} \xB7 ${(U=>U.kind==="admitted"?"admitted":U.why)(l.of(v))}, and ${w.length?`no place of ${w.join(", ")} takes it`:"no one own lock it covers takes it: name the places with --place"}
35
+ `);return o("error",`${k()}: REFUSE\xB7nowhere nothing landed \xB7 ${g.nowhere.length} lines neither the ledger nor an own lock admits: a line is landed signed where it stands, never written in bare
36
+ `),1}const f=he(n),d=[...new Set([...g.own.keys(),...w])],h=d.length===0&&g.ledger.length?Mn(n,f,g.ledger,z(m)):[],L=d.length===0&&h.length===f.length&&f.length>0,$=(d.length?d:L?f:h).filter(v=>f.includes(v)),x=L?"every place \xB7 then the root, where the places join":$.length?$.map(v=>`${v}/`).join(" \xB7 "):"the root alone, where the places join";o("out",`ACTS ${x} \xB7 ${g.ledger.length} lines to the ledger${[...g.own].map(([v,U])=>` \xB7 ${U.length} to ${v}'s own lock`).join("")} \xB7 before the lock
37
+ `);const s=Date.now(),T=g.ledger.length>0||L||$.length===0;return(T?Tn:Cn)(m,T?[...$,""]:$,"land",()=>Yn(n,{...c,signed:g.ledger,records:c.signed},S,g,s,$,y))}F(Be,"finishAcceptance");async function Yn(n,r,c,i,S=c,y=[],w){const m=Date.now()-S;m>6e4&&o("out",`RED wait ${Math.round(m/1e3)} s for the lock before the act \xB7 a wait over a minute is a red
38
+ `);const l=[`sign ${S-c}`,`wait ${m}`],g=en(l),{signed:f,epoch:d}=r;if(We(n,r.records??f))return 1;const h=N(n),L=Y(h,De(n,r.base.places));if(L!==r.base.digest)return o("error",`${k()}: REFUSE\xB7base moved ${r.base.digest} \u2192 ${L} \xB7 nothing landed
39
+ `),1;try{ke(n,f)}catch(a){return o("error",`${k()}: ${a instanceof Error?a.message:String(a)} \xB7 nothing landed
40
+ `),1}if(f.some(a=>!q(a)))try{await le(n,[...J(h),...f])}catch(a){return o("error",`${k()}: ${a instanceof Error?a.message:String(a)} \xB7 nothing landed
41
+ `),1}const $=g("lines",()=>ue(n));if(Me(n,f,$.standing))return 1;let x;try{x=g("evidence",()=>Ne(n,f,$.standing))}catch(a){return o("error",`${k()}: ${a instanceof Error?a.message:String(a)} \xB7 nothing landed
42
+ `),1}const s=x.fold,T=g("authority",()=>Z([...C(h),...f],ee(n),I(h).admitted));for(const a of f){const E=T.of(a);if(E.kind!=="admitted")return o("error",`${k()}: ${E.kind==="refuse"?E.why:`REFUSE\xB7authority grey: ${E.why}`}
43
+ `),1}const M=f.filter(a=>t(a,"value")==="withdraw"),v=x.coordinates,U=M.length?An(M,C(h)):null,de=`${V(s.standing,"families","view")}/`,te=Y(h,f),K=yn(h)?Y(h,[...bn(h)].sort(([a],[E])=>a.localeCompare(E)).map(([a,E])=>`${a} ${E}`)):"key"in s&&typeof s.key=="string"?s.key:Y(h,s.standing),re=nt(un(h,K,te)),A=re??x.judged;re||fn(h,K,te,A.map(et));const G=A.filter(a=>a.kind==="refused"||a.kind==="judged"&&a.verdict.kind==="refuse");if(G.length){for(const a of G)o("out",`REFUSE take ${a.scope} \xB7 ${a.kind==="judged"?a.verdict.why:a.kind==="refused"?a.why:""}
44
+ `);return o("error",`${k()}: REFUSE\xB7takes nothing landed \xB7 ${G.length} takes refused: a batch lands whole or not at all
45
+ `),1}const O=g("told",()=>ue(n,void 0,f));for(const a of Nn(y,O.standing,f))o("error",`OPEN ${a}
46
+ `);i.own.size&&Pn(h,n,O.standing,h);const W=Re($.standing);let P=[];if(W){const a=r.records??f,E=[...f.length?[{place:".",records:f}]:[],...[...i.own].map(([u,R])=>({place:`${u}/${fe}`,records:R}))],p=cn(a,{...W,digest:F(u=>ve(h,new TextEncoder().encode(u)),"digest"),placements:E,localEpoch:d}),b=ie($.standing,"fold");if(!b)throw Error("REFUSE\xB7act native result requires a declared fold identity");const j=be({scope:W.scope,at:W.context,role:"writes",form:"alphabet",measure:"digest",value:p,by:b,epoch:String(d)}),B={records:a.join(`
47
+ `)+`
48
+ `,receipt:j+`
49
+ `,placements:E.map(u=>({place:u.place,records:u.records.join(`
50
+ `)+`
51
+ `}))};oe(w?.signal),w?.prepared?.(p),oe(w?.signal);const _=await Je(h,p,y,async()=>B,Xe,w?.storage,w?.signal);w?.committed?.(p,_,_.kind),o("out",`ACT ${p} \xB7 epoch ${d} \xB7 admitted \xB7 conformance not asserted
52
+ `);for(const u of a)o("out",u+`
53
+ `);o("out",j+`
54
+ `),P=[{at:"committed act "+p,appended:a.length}]}else P=g("land",()=>[...new Set(f.map(a=>t(a,"by")))].map(a=>se(h,a,f.filter(E=>t(E,"by")===a))));for(const[a,E]of i.own)Wn(n,a,E,W!==void 0);return In(h,"projection",async()=>{je(h,ie(O.standing,"fold"),[]);for(const u of f){const R=t(u,"value");if(/^[a-z0-9-]+:[0-9a-f]{32,}$/.test(R))for(const Ke of vn(t(u,"needs")).locations){const Ge=H(n,Ke),ce=Rn(Ge);ce!==void 0&&ve(h,ce)===R&&hn(h,R,ce)}}if(v.taken.length){for(const u of v.taken){ye(H(n,u))&&tn(H(n,u),{recursive:!0});for(let R=Ee(u);R!=="."&&ye(H(n,R))&&!Sn(H(n,R)).length;R=Ee(R))nn(H(n,R))}En(h,new Map,v.taken,`withdraw:epoch-${d}`);for(const u of v.taken)o("out",`GONE ${u} \xB7 withdrawn by its line
55
+ `)}for(const u of A)we(n,u,[]);const a=[...f,...s.standing].filter(u=>t(u,"role")==="demands"&&t(u,"value")!=="withdraw"),E=new Set(me(h,a,s.observed,de).paid.map(u=>t(u,"scope"))),e=Ue(h,[...f,...s.standing],E);if(e.length){se(h,"judge",e);for(const u of e)t(u,"measure")!=="cone"&&o("out",`LATE ${t(u,"scope")} \xB7 answered from the landed cone
56
+ `)}if(f.some(u=>t(u,"scope").startsWith(`${rn(jn())}/`)&&!t(u,"scope").split("/").slice(1,-1).includes("uses"))){const u=dn(h,Te(n),O.standing,n,xn());if(an(h)!==u){const R=await on(n,h);sn(h,u),o("error",`open by instrument \xB7 ${R.length}
57
+ `)}}const p=g("render",()=>Le(n,h));o("out",`RENDER 0
58
+ `);const b=new Set([...i.own.values()].flat()).size,j=Math.round((Date.now()-c)/Math.max(1,f.length+b)),B=ie(s.standing,"fold"),_=F((u,R)=>be({scope:"beat/accept",role:"writes",form:"interval",measure:"ms",value:`${u}..${u}`,by:B??"",at:`place:${R}`}),"beat");if(B!==void 0&&se(h,B,[_(j,"line"),_(1,s.kept?"kept":"folded"),_(Date.now()-c,"total")]),o("out",`FACT signed ${f.length+b} \xB7 landed ${P.length?P.map(u=>`${u.appended} in ${u.at}`).join(" \xB7 "):"0"}${[...i.own].map(([u,R])=>` \xB7 ${R.length} in ${u}/${fe}`).join("")} \xB7 epoch ${d}
59
+ TARGET ${p.standing} claims \xB7 ${p.forks.length} forks \xB7 ${p.vacuous.length} vacuous \xB7 ${p.grey.length} grey \xB7 ${p.refused.length} refused \xB7 readings \xB7 no encounters computed \xB7 ${Date.now()-c} ms
60
+ SPENT ${l.join(" ms \xB7 ")} ms \xB7 ${f.length} lines
61
+ `),U){o("out",`WITHDRAW ${U.taken.length} taken \xB7 ${U.exact.length} exact on distributive scales \xB7 ${U.open.length} on open scales, not computed
62
+ `);for(const u of U.inexact)o("out",`INEXACT ${t(u,"scope")} \xB7 its scale is not distributive: what the others hold is not what they held without it
63
+ `)}return 0})}F(Yn,"acceptNow");function Zn(n,r,c){const i=N(n),S=Qe(i).find(s=>{const T=s.bundle.records.trimEnd().split(`
64
+ `);return T.length===r.length&&T.every((M,v)=>M===r[v])});S&&o("out",`ACT ${S.identity} \xB7 epoch ${t(S.bundle.receipt.trim(),"epoch")} \xB7 admitted \xB7 replay
65
+ `+S.bundle.records+S.bundle.receipt);const y=new Set(r.filter(s=>t(s,"role")==="demands").map(s=>t(s,"scope"))),w=`${V(Fe(J(i)).standing,"families","view")}/`,m=Xn(i).filter(s=>y.has(t(s,"scope"))&&!t(s,"scope").startsWith(w)),l=me(i,m,[],w).missing;if(!l.length)return o("out",`ONCE ${r.length} lines \xB7 every one already landed and every demand of it paid: a batch landed twice is one, nothing landed
66
+ `),0;const g=l.map(s=>Ie(n,s));if(o("out",`ONCE ${r.length} lines \xB7 every one already landed \xB7 ${l.length} of its demands unpaid, judged again
67
+ `),g.every(s=>s.kind==="owed")){for(const s of g)we(n,s,[]);return 0}const f=g.filter(s=>s.kind==="refused"||s.kind==="judged"&&s.verdict.kind==="refuse");if(f.length){for(const s of f)o("out",`REFUSE take ${s.scope} \xB7 ${s.kind==="judged"?s.verdict.why:s.kind==="refused"?s.why:""}
68
+ `);return o("error",`${k()}: REFUSE\xB7takes nothing landed \xB7 ${f.length} takes refused: what a batch left unpaid is paid whole or not at all
69
+ `),1}const d=ue(n);for(const s of g)we(n,s,[]);je(i,ie(d.standing,"fold"),[]);const h=d.standing.filter(s=>t(s,"role")==="demands"&&t(s,"value")!=="withdraw"),L=new Set(me(i,h,[],`${V(d.standing,"families","view")}/`).paid.map(s=>t(s,"scope"))),$=Ue(i,d.standing,L);if($.length){se(i,"judge",$);for(const s of $)t(s,"measure")!=="cone"&&o("out",`LATE ${t(s,"scope")} \xB7 answered from the landed cone
70
+ `)}const x=Le(n,i);return o("out",`RENDER 0
71
+ `),o("out",`TARGET ${x.standing} claims \xB7 ${x.forks.length} forks \xB7 ${x.vacuous.length} vacuous \xB7 ${x.grey.length} grey \xB7 ${x.refused.length} refused \xB7 readings \xB7 no encounters computed \xB7 ${Date.now()-c} ms
72
+ `),0}F(Zn,"repaid");function et(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}F(et,"packTake");function nt(n){if(n===void 0)return;const r=[];for(const c of n){if(c===null||typeof c!="object"||!("kind"in c)||!("scope"in c))return;const i=c;if(i.kind!=="judged"){r.push(i);continue}r.push({kind:"judged",scope:i.scope,demand:i.demand,locations:i.locations,before:new Map(i.before),after:new Map(i.after),verdict:i.verdict,ignored:new Map(i.ignored),started:Date.now()})}return r}F(nt,"keptTakes");export{er as accept,nr as acceptRootRecords,Pe as signedBatch};