@lapxo/bound 0.2.5 → 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 (237) hide show
  1. package/CITATION.cff +1 -1
  2. package/README.md +20 -3
  3. package/TARGET.bound +75 -42
  4. package/dist/cli/accept.js +59 -70
  5. package/dist/cli/act-result.js +3 -3
  6. package/dist/cli/args.js +1 -1
  7. package/dist/cli/host.js +1 -1
  8. package/dist/cli/native.js +1 -1
  9. package/dist/cli/pass.js +22 -21
  10. package/dist/cli/place.js +6 -6
  11. package/dist/cli/release-result.js +3 -3
  12. package/dist/cli/retained-judgment.js +1 -1
  13. package/dist/cli/standing-result.js +3 -3
  14. package/dist/cli/takes.js +10 -10
  15. package/dist/cli/verb.js +79 -77
  16. package/dist/engine/computation.js +1 -1
  17. package/dist/engine/index.js +1 -1
  18. package/dist/engine/object.js +1 -1
  19. package/dist/engine/ports.js +1 -1
  20. package/dist/fold/admission-history.js +1 -1
  21. package/dist/fold/ceilings.js +1 -1
  22. package/dist/fold/claims.js +2 -2
  23. package/dist/fold/closed.js +1 -1
  24. package/dist/fold/configures.js +1 -1
  25. package/dist/fold/digests.js +10 -10
  26. package/dist/fold/evidence.js +1 -1
  27. package/dist/fold/keys.js +3 -3
  28. package/dist/fold/laid.js +1 -1
  29. package/dist/fold/observed.js +27 -26
  30. package/dist/fold/opened.js +1 -1
  31. package/dist/fold/own.js +3 -3
  32. package/dist/fold/paid.js +1 -1
  33. package/dist/fold/place-inputs.js +1 -1
  34. package/dist/fold/places.js +1 -1
  35. package/dist/fold/reach.js +1 -1
  36. package/dist/fold/readers.js +1 -1
  37. package/dist/fold/region.js +1 -1
  38. package/dist/fold/release-policy.js +1 -1
  39. package/dist/fold/resolved.js +1 -1
  40. package/dist/fold/roles.js +1 -1
  41. package/dist/fold/shards.js +8 -8
  42. package/dist/fold/signed.js +3 -3
  43. package/dist/fold/signers.js +1 -1
  44. package/dist/fold/stranger.js +6 -6
  45. package/dist/fold/wire.js +1 -1
  46. package/dist/fold/zoom.js +1 -1
  47. package/dist/host/act-cost.js +1 -1
  48. package/dist/host/adapters/keys/ed25519.js +1 -1
  49. package/dist/host/adapters/transport/http.js +1 -1
  50. package/dist/host/admitted-place.js +1 -1
  51. package/dist/host/call-context.js +1 -1
  52. package/dist/host/capsule-process.js +1 -1
  53. package/dist/host/capsule.js +1 -1
  54. package/dist/host/cell-receipts.js +1 -1
  55. package/dist/host/command-server.js +4 -0
  56. package/dist/host/content-store.js +1 -1
  57. package/dist/host/contextual-place.js +1 -1
  58. package/dist/host/digest.js +1 -1
  59. package/dist/host/host-controls.js +1 -1
  60. package/dist/host/in-process-act.js +1 -1
  61. package/dist/host/in-process-context.js +1 -1
  62. package/dist/host/in-process-root.js +1 -1
  63. package/dist/host/in-process.js +1 -1
  64. package/dist/host/index.d.ts +1 -1
  65. package/dist/host/index.js +1 -1
  66. package/dist/host/located.js +6 -6
  67. package/dist/host/native/authority-card-view.js +5 -0
  68. package/dist/host/native/authority-card.js +1 -0
  69. package/dist/host/native/command.js +1 -1
  70. package/dist/host/native/custody.js +1 -1
  71. package/dist/host/native/generated-custodian.js +1 -1
  72. package/dist/host/native/installed-package.d.ts +1 -0
  73. package/dist/host/native/installed-package.js +5 -0
  74. package/dist/host/native/module-delivery.d.ts +1 -1
  75. package/dist/host/native/module-delivery.js +1 -1
  76. package/dist/host/native/module-inventory.js +2 -0
  77. package/dist/host/native/module-syntax.js +1 -1
  78. package/dist/host/native/native-binary.js +1 -1
  79. package/dist/host/native/probes.js +1 -0
  80. package/dist/host/native/reading-witness-admission.js +5 -0
  81. package/dist/host/native/reading.js +1 -1
  82. package/dist/host/native/route.js +1 -1
  83. package/dist/host/native-place-state.js +1 -0
  84. package/dist/host/native-receiver.js +1 -1
  85. package/dist/host/objects.js +1 -1
  86. package/dist/host/persistent-host.js +1 -0
  87. package/dist/host/physical-lines.d.ts +1 -0
  88. package/dist/host/physical-lines.js +1 -0
  89. package/dist/host/place-act-transaction.js +1 -1
  90. package/dist/host/place-clock-selection.js +1 -1
  91. package/dist/host/ports/local-act.js +1 -1
  92. package/dist/host/ports/place-act.js +1 -1
  93. package/dist/host/ports/store.js +1 -1
  94. package/dist/host/ports/transport.js +1 -1
  95. package/dist/host/profile-composition.d.ts +1 -0
  96. package/dist/host/profile-composition.js +2 -0
  97. package/dist/host/reading-closures.js +6 -6
  98. package/dist/host/reading-context.js +1 -1
  99. package/dist/host/reading-identity.js +2 -2
  100. package/dist/host/reading-preparation.js +1 -1
  101. package/dist/host/reference-authenticated.d.ts +1 -1
  102. package/dist/host/reference-authenticated.js +1 -1
  103. package/dist/host/reference-export.js +1 -1
  104. package/dist/host/reference-native-api.d.ts +1 -1
  105. package/dist/host/reference-native-api.js +1 -1
  106. package/dist/host/reference-native.js +1 -1
  107. package/dist/host/reference-standing.js +1 -1
  108. package/dist/host/reference.js +1 -1
  109. package/dist/host/refusals.js +2 -2
  110. package/dist/host/release.js +1 -1
  111. package/dist/host/root-clock-source.js +1 -1
  112. package/dist/host/selected-capsules.js +1 -1
  113. package/dist/host/selected-topos.js +1 -1
  114. package/dist/host/signing.js +2 -2
  115. package/dist/host/source-content.js +1 -1
  116. package/dist/host/standing-carrier.js +1 -1
  117. package/dist/host/standing-projection.js +1 -1
  118. package/dist/host/timing.js +1 -1
  119. package/dist/host/walk.js +1 -1
  120. package/dist/host/work-trace.js +1 -0
  121. package/dist/judge/late.js +1 -1
  122. package/dist/judge/take.js +1 -1
  123. package/dist/judge/widening.js +1 -1
  124. package/dist/land/act.js +6 -6
  125. package/dist/land/alias.js +1 -1
  126. package/dist/land/held.js +1 -1
  127. package/dist/land/ledger.js +5 -6
  128. package/dist/land/sign.js +1 -1
  129. package/dist/land/standing-pin.js +1 -1
  130. package/dist/land/vouched.js +1 -1
  131. package/dist/land/withdraw.js +1 -1
  132. package/dist/observe/files.js +1 -1
  133. package/dist/observe/identity.js +1 -1
  134. package/dist/observe/match.js +1 -1
  135. package/dist/observe/regions.js +1 -1
  136. package/dist/observe/run.js +1 -2
  137. package/dist/observe/runner.js +1 -1
  138. package/dist/public-types.d.ts +945 -40
  139. package/dist/render/capsule.js +1 -1
  140. package/dist/render/field.js +1 -1
  141. package/dist/render/open.js +1 -1
  142. package/dist/render/page.js +1 -1
  143. package/dist/render/receipt-projection.js +1 -0
  144. package/dist/render/receipts.js +1 -1
  145. package/dist/render/shape.js +1 -1
  146. package/dist/render/target.js +4 -4
  147. package/dist/render/view.js +5 -5
  148. package/dist/vendor/bundle.json +1 -1
  149. package/dist/vendor/library14.js +1 -0
  150. package/dist/vendor/runtime.js +53 -30
  151. package/dist/wasm/adapter.d.ts +1 -1
  152. package/docs/contracts/authenticated-reference.publication.json +1 -1
  153. package/docs/contracts/authority-preflight.md +17 -0
  154. package/docs/contracts/authority-preflight.publication.json +25 -0
  155. package/docs/contracts/installed-package.md +21 -0
  156. package/docs/contracts/installed-package.publication.json +25 -0
  157. package/docs/contracts/materialized-leaf-sequence.md +15 -0
  158. package/docs/contracts/materialized-leaf-sequence.publication.json +25 -0
  159. package/docs/contracts/module-inventory.md +15 -0
  160. package/docs/contracts/module-inventory.publication.json +25 -0
  161. package/docs/contracts/native-host.md +29 -1
  162. package/docs/contracts/native-host.publication.json +4 -4
  163. package/docs/contracts/native-probes.md +13 -0
  164. package/docs/contracts/native-probes.publication.json +25 -0
  165. package/docs/contracts/native-publication.inventory.json +9 -1
  166. package/docs/contracts/native-view-batch.md +17 -0
  167. package/docs/contracts/native-view-batch.publication.json +25 -0
  168. package/docs/contracts/physical-lines.md +19 -0
  169. package/docs/contracts/physical-lines.publication.json +25 -0
  170. package/docs/contracts/profile-composition.md +17 -0
  171. package/docs/contracts/profile-composition.publication.json +25 -0
  172. package/docs/contracts/profile-preparation-native-meaning.md +9 -0
  173. package/docs/contracts/publication.md +12 -0
  174. package/docs/contracts/reading-identity.md +26 -2
  175. package/docs/contracts/reading-identity.publication.json +4 -4
  176. package/docs/contracts/reading-witness-admission.md +49 -0
  177. package/docs/contracts/readme.publication.json +1 -1
  178. package/docs/contracts/reference-port.md +11 -0
  179. package/docs/contracts/reference-port.publication.json +1 -1
  180. package/docs/contracts/refusals.bound +346 -145
  181. package/docs/contracts/refusals.md +119 -54
  182. package/docs/contracts/refusals.publication.json +2 -2
  183. package/docs/reference.md +8 -0
  184. package/licenses/wasm/{fast-text-encoding.txt → NOTICE.txt} +111 -0
  185. package/package.json +69 -8
  186. package/receipts.bound +12921 -11722
  187. package/samples/authority-preflight/no.json +6 -0
  188. package/samples/authority-preflight/yes.json +30 -0
  189. package/samples/engine-alphabet/reader.js +3 -1457
  190. package/samples/engine-alphabet/receipts.bound +7 -7
  191. package/samples/engine-interval/reader.js +3 -1457
  192. package/samples/engine-interval/receipts.bound +7 -7
  193. package/samples/installed-package/consumer.mjs +29 -0
  194. package/samples/installed-package/fixture.json +48 -0
  195. package/samples/installed-package/no.json +10 -0
  196. package/samples/installed-package/yes.json +52 -0
  197. package/samples/materialized-leaf-sequence/no.json +11 -0
  198. package/samples/materialized-leaf-sequence/yes.json +10 -0
  199. package/samples/module-inventory/yes.json +28 -0
  200. package/samples/native/physical-line-reader.mjs +1 -0
  201. package/samples/native/physical-line-reader.source.mjs +13 -0
  202. package/samples/native-host/no.json +6 -1
  203. package/samples/native-host/yes.json +18 -1
  204. package/samples/native-probes/inputs/inspection.json +28 -0
  205. package/samples/native-probes/no.json +7 -0
  206. package/samples/native-probes/yes.json +28 -0
  207. package/samples/native-view-batch/no.json +14 -0
  208. package/samples/native-view-batch/yes.json +10 -0
  209. package/samples/no/engine-order/reader.js +3 -1457
  210. package/samples/no/module-inventory/no.json +10 -0
  211. package/samples/physical-lines/no.json +5 -0
  212. package/samples/physical-lines/yes.json +9 -0
  213. package/samples/profile-composition/no.json +6 -0
  214. package/samples/profile-composition/yes.json +14 -0
  215. package/samples/reading-identity/no.json +7 -1
  216. package/samples/reading-identity/yes.json +24 -1
  217. package/vectors/native/authority-preflight.vector.json +55 -0
  218. package/vectors/native/installed-package.vector.json +31 -0
  219. package/vectors/native/materialized-leaf-sequence.vector.json +31 -0
  220. package/vectors/native/module-inventory.vector.json +56 -0
  221. package/vectors/native/native-host.vector.json +214 -0
  222. package/vectors/native/native-probes.vector.json +31 -0
  223. package/vectors/native/native-view-batch.vector.json +31 -0
  224. package/vectors/native/physical-lines.vector.json +105 -0
  225. package/vectors/native/profile-composition.vector.json +53 -0
  226. package/vectors/native/reading-identity.vector.json +38 -0
  227. package/vectors/native/refusals.vector.json +36 -2
  228. package/dist/vendor/library11.js +0 -1
  229. package/dist/vendor/sources.json +0 -1
  230. package/licenses/wasm/bound.txt +0 -21
  231. package/licenses/wasm/jitl-quickjs-ffi-types.txt +0 -21
  232. package/licenses/wasm/jitl-quickjs-wasmfile-release-sync.txt +0 -47
  233. package/licenses/wasm/obligations.txt +0 -21
  234. package/licenses/wasm/quickjs-emscripten-core.txt +0 -21
  235. package/licenses/wasm/topos.txt +0 -21
  236. /package/dist/vendor/{50086958553b9376d600583f7dff354196bfeb41170fc6d1482ca7bea7c493e2.LICENSE → 28cba430228db1c04f446c93f81b09a2705d6bf3e222d35adbe5a4cee4061884.LICENSE} +0 -0
  237. /package/dist/vendor/{b3e938d28f88a1851af303a40c749e12ebd5a686daac4f0b343b5cdd2e040419.LICENSE → 7aca161279d14bc0e054dcc281cd110aeb95be2e026b42fdf527a260e58b2aae.LICENSE} +0 -0
@@ -1,1457 +1,3 @@
1
- // work/bound-0.1.9/repository/node_modules/@lapxo/topos/dist/wire/outcome.js
2
- var fact = (value) => ({ kind: "fact", value });
3
- var abstain = (why) => ({ kind: "abstain", why });
4
- var refuse = (why, named) => ({ kind: "refuse", why, ...named === void 0 ? {} : { named } });
5
-
6
- // work/bound-0.1.9/repository/node_modules/@lapxo/topos/dist/wire/values.js
7
- function unpipe(value) {
8
- const out = [];
9
- let at = "";
10
- for (let i = 0; i < value.length; i++) {
11
- const c = value[i];
12
- if (c === "\\") {
13
- const next = value[i + 1];
14
- if (next !== "|" && next !== "\\")
15
- return null;
16
- at += next;
17
- i += 1;
18
- } else if (c === "|") {
19
- out.push(at);
20
- at = "";
21
- } else {
22
- at += c;
23
- }
24
- }
25
- out.push(at);
26
- return out;
27
- }
28
- var OPEN = "*";
29
- var num = (s) => {
30
- if (!/^-?\d+(\.\d+)?$/.test(s))
31
- return null;
32
- const n = Number(s);
33
- return isFinite(n) ? n : null;
34
- };
35
- function decimal(n) {
36
- if (!isFinite(n))
37
- throw new Error(`REFUSE\xB7wire decimal: \`${n}\` is not a finite number`);
38
- const got = /^(-?)(\d)(?:\.(\d+))?e([+-])(\d+)$/.exec(String(n));
39
- if (got === null)
40
- return String(n);
41
- const [, sign2 = "", lead = "", rest = "", ahead = "", exp = "0"] = got;
42
- return ahead === "+" ? `${sign2}${lead}${rest}${"0".repeat(Number(exp) - rest.length)}` : `${sign2}0.${"0".repeat(Number(exp) - 1)}${lead}${rest}`;
43
- }
44
- var GRAMMARS = {
45
- interval: (value) => {
46
- const at = value.indexOf("..");
47
- if (at < 0)
48
- return null;
49
- const lo = value.slice(0, at);
50
- const hi = value.slice(at + 2);
51
- const l = lo === OPEN ? null : num(lo);
52
- const h = hi === OPEN ? null : num(hi);
53
- if (lo !== OPEN && l === null || hi !== OPEN && h === null)
54
- return null;
55
- return { kind: "interval", lo: l, hi: h };
56
- },
57
- alphabet: (value) => {
58
- const values = unpipe(value);
59
- return values === null ? null : { kind: "enumerated", values };
60
- },
61
- ladder: (value) => {
62
- const parts2 = unpipe(value);
63
- if (parts2 === null || parts2.length !== 2)
64
- return null;
65
- return { kind: "band", floor: parts2[0] ?? "", ceiling: parts2[1] ?? "" };
66
- }
67
- };
68
- function boundOf(form2, value, grammars) {
69
- const extra = Array.isArray(grammars) ? grammars.find((g) => g.form === form2) : void 0;
70
- if (extra)
71
- return extra.parse(value);
72
- return GRAMMARS[form2]?.(value) ?? null;
73
- }
74
- var BOUND_FORMS = Object.keys(GRAMMARS);
75
- var REF_RELATIONS = ["within", "copies", "derives"];
76
-
77
- // work/bound-0.1.9/repository/node_modules/@lapxo/topos/dist/wire/line.js
78
- var PROTOCOL = "bound-lock/1";
79
- var NEEDS_QUOTE = /[ ="\n\\]/;
80
- function escape(value) {
81
- if (!NEEDS_QUOTE.test(value))
82
- return value;
83
- return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n")}"`;
84
- }
85
- function unescape(token) {
86
- if (!token.startsWith('"'))
87
- return NEEDS_QUOTE.test(token) ? null : token;
88
- if (token.length < 2 || !token.endsWith('"'))
89
- return null;
90
- const body = token.slice(1, -1);
91
- let out = "";
92
- for (let i = 0; i < body.length; i++) {
93
- const c = body[i];
94
- if (c !== "\\") {
95
- if (c === '"')
96
- return null;
97
- out += c;
98
- continue;
99
- }
100
- const next = body[i + 1];
101
- if (next === '"')
102
- out += '"';
103
- else if (next === "\\")
104
- out += "\\";
105
- else if (next === "n")
106
- out += "\n";
107
- else
108
- return null;
109
- i += 1;
110
- }
111
- return out;
112
- }
113
- var UTF8 = new TextEncoder();
114
- function byBytes(a, b) {
115
- const x = UTF8.encode(a);
116
- const y = UTF8.encode(b);
117
- for (let i = 0; i < x.length && i < y.length; i++) {
118
- if (x[i] !== y[i])
119
- return x[i] - y[i];
120
- }
121
- return x.length - y.length;
122
- }
123
- var unwritten = (fields) => fields["form"] === "interval" && fields["value"] !== void 0 && fields["value"] !== "withdraw" && boundOf("interval", fields["value"]) === null;
124
- function canonical(fields, version = "1") {
125
- if (unwritten(fields))
126
- throw new Error(`REFUSE\xB7wire canonical: \`${fields["value"]}\` is no interval the wire writes: two ends, each decimal or *`);
127
- const keys = Object.keys(fields).sort(byBytes);
128
- const tokens = keys.map((k) => `${k}=${escape(fields[k])}`);
129
- return [`${PROTOCOL.split("/")[0]}/${version}`, ...tokens].join(" ");
130
- }
131
- var ABSENT = "-";
132
- function parse(text, options = {}) {
133
- if (text.includes("\n")) {
134
- return refuse("a line is one line \u2014 a newline in a value must be escaped as `\\n`");
135
- }
136
- const space = text.indexOf(" ");
137
- const envelope = space === -1 ? text : text.slice(0, space);
138
- const [name, version] = envelope.split("/");
139
- if (name !== PROTOCOL.split("/")[0] || !version) {
140
- return refuse(`no \`bound-lock/<v>\` envelope \u2014 found \`${envelope.slice(0, 24)}\``);
141
- }
142
- if (version !== PROTOCOL.split("/")[1]) {
143
- return abstain(`\`bound-lock/${version}\` is a version this reader does not know`);
144
- }
145
- const fields = {};
146
- const writtenKeys = /* @__PURE__ */ new Set();
147
- for (const token of tokensOf(space === -1 ? "" : text.slice(space + 1))) {
148
- if (token === null)
149
- return refuse("a quoted value is not closed");
150
- const at = token.indexOf("=");
151
- if (at <= 0)
152
- return refuse(`\`${token.slice(0, 24)}\` is not \`key=value\``);
153
- const key = token.slice(0, at);
154
- if (writtenKeys.has(key))
155
- return refuse(`\`${key}\` appears twice \u2014 one line, one value per key`);
156
- writtenKeys.add(key);
157
- const value = unescape(token.slice(at + 1));
158
- if (value === null)
159
- return refuse(`\`${key}\` has an escaping this format does not define`);
160
- if (value !== ABSENT)
161
- fields[key] = value;
162
- }
163
- if (unwritten(fields))
164
- return refuse(`\`${fields["value"]}\` is no interval the wire reads: two ends, each decimal or *`);
165
- return fact({ version, fields, ...options.preserveKeys ? { keys: [...writtenKeys] } : {} });
166
- }
167
- function* tokensOf(rest) {
168
- let at = 0;
169
- while (at < rest.length) {
170
- while (rest[at] === " ")
171
- at += 1;
172
- if (at >= rest.length)
173
- return;
174
- let end = at;
175
- let quoted = false;
176
- while (end < rest.length && (quoted || rest[end] !== " ")) {
177
- if (rest[end] === "\\" && quoted)
178
- end += 1;
179
- else if (rest[end] === '"')
180
- quoted = !quoted;
181
- end += 1;
182
- }
183
- if (quoted) {
184
- yield null;
185
- return;
186
- }
187
- yield rest.slice(at, end);
188
- at = end;
189
- }
190
- }
191
-
192
- // work/bound-0.1.9/repository/node_modules/@lapxo/topos/dist/wire/grammar.js
193
- var [FORBID, EMPTY, MEMBER, PAIR, STEP, AT, EVERY, ESCAPE] = ["not:", "none", "|", "=", "/", "@", "*", "\\"];
194
- var refuse2 = (grammar, why) => {
195
- throw new Error(`REFUSE\xB7wire ${grammar}: ${why}`);
196
- };
197
- function alphabet(given) {
198
- if (typeof given !== "string") {
199
- const written2 = given.members.map((one) => one.split(ESCAPE).join(ESCAPE + ESCAPE).split(MEMBER).join(ESCAPE + MEMBER)).join(MEMBER);
200
- if (given.polarity === "forbid")
201
- return FORBID + written2;
202
- return written2.startsWith(FORBID) || written2 === EMPTY ? refuse2("alphabet", "a permitted alphabet neither begins with not: nor is the one word none") : written2 || EMPTY;
203
- }
204
- const forbid = given.startsWith(FORBID);
205
- const body = forbid ? given.slice(FORBID.length) : given;
206
- const members = !forbid && body === EMPTY ? [] : unpipe(body) ?? refuse2("alphabet", "a backslash escapes only a pipe or itself");
207
- return { polarity: forbid ? "forbid" : "permit", members: members.filter((one) => one !== "") };
208
- }
209
-
210
- // work/bound-0.1.9/repository/node_modules/@lapxo/obligations/dist/lattice/errors.js
211
- var UnitError = class _UnitError extends Error {
212
- code;
213
- detail;
214
- constructor(code, message, detail = {}) {
215
- super(message);
216
- this.name = "UnitError";
217
- this.code = code;
218
- this.detail = Object.freeze({ ...detail });
219
- Object.setPrototypeOf(this, _UnitError.prototype);
220
- }
221
- };
222
-
223
- // work/bound-0.1.9/repository/node_modules/@lapxo/obligations/dist/lattice/order.js
224
- function build(levels, join2, meet) {
225
- const n = levels.length;
226
- for (let i = 0; i < n; i++) {
227
- if (levels.indexOf(levels[i]) !== i) {
228
- throw new UnitError("DUPLICATE_LEVEL", `the level \`${levels[i]}\` is declared twice`, {
229
- level: levels[i]
230
- });
231
- }
232
- }
233
- const index = new Map(levels.map((l, i) => [l, i]));
234
- const leq = (a, b) => join2[a][b] === b;
235
- const total = levels.every((_, i) => levels.every((__, j) => join2[i][j] === i || join2[i][j] === j));
236
- let simple = true;
237
- for (let x = 0; x < n && simple; x++) {
238
- for (let y = 0; y < n && simple; y++) {
239
- for (let z = 0; z < n; z++) {
240
- if (meet[x][join2[y][z]] !== join2[meet[x][y]][meet[x][z]]) {
241
- simple = false;
242
- break;
243
- }
244
- }
245
- }
246
- }
247
- const all = [...levels.keys()];
248
- const bottomIx = all.find((i) => all.every((j) => leq(i, j))) ?? 0;
249
- const topIx = all.find((i) => all.every((j) => leq(j, i))) ?? n - 1;
250
- const joinIrr = all.filter((j) => j !== bottomIx && all.filter((x) => x !== j && leq(x, j)).reduce((acc, x) => join2[acc][x], bottomIx) !== j);
251
- const meetIrr = all.filter((m) => m !== topIx && all.filter((x) => x !== m && leq(m, x)).reduce((acc, x) => meet[acc][x], topIx) !== m);
252
- const seen = /* @__PURE__ */ new Set();
253
- const allDebits = [];
254
- for (const x of [...joinIrr, ...meetIrr]) {
255
- if (!seen.has(x)) {
256
- seen.add(x);
257
- allDebits.push(x);
258
- }
259
- }
260
- return {
261
- levels,
262
- isLadder: total,
263
- isSimple: simple,
264
- bottomIx,
265
- topIx,
266
- bottom: levels[bottomIx],
267
- top: levels[topIx],
268
- leq,
269
- higher: (a, b) => join2[a][b],
270
- lower: (a, b) => meet[a][b],
271
- rank(level) {
272
- const r = index.get(level);
273
- if (r === void 0) {
274
- throw new UnitError("UNKNOWN_LEVEL", `no level \`${level}\` in this scale`, {
275
- level,
276
- levels
277
- });
278
- }
279
- return r;
280
- },
281
- stateOf(floor, ceiling) {
282
- if (!leq(floor, ceiling))
283
- return "CONFLICT";
284
- if (floor !== bottomIx)
285
- return "REQUIRED";
286
- if (ceiling !== topIx)
287
- return "FORBIDDEN";
288
- return "FREE";
289
- },
290
- joins: () => joinIrr.slice(),
291
- limits: () => meetIrr.slice(),
292
- debits: () => allDebits.slice(),
293
- intervalHeight(lo, hi) {
294
- if (!leq(lo, hi))
295
- return null;
296
- const inside = all.filter((x) => leq(lo, x) && leq(x, hi));
297
- const covers = (x) => inside.filter((y) => y !== x && leq(x, y) && !inside.some((z) => z !== x && z !== y && leq(x, z) && leq(z, y)));
298
- const long = /* @__PURE__ */ new Map([[lo, 0]]);
299
- const short = /* @__PURE__ */ new Map([[lo, 0]]);
300
- const walk = [...inside].sort((a, b) => inside.filter((z) => leq(z, a)).length - inside.filter((z) => leq(z, b)).length);
301
- for (const x of walk) {
302
- const lx = long.get(x);
303
- const sx = short.get(x);
304
- if (lx === void 0 || sx === void 0)
305
- continue;
306
- for (const y of covers(x)) {
307
- long.set(y, Math.max(long.get(y) ?? lx + 1, lx + 1));
308
- short.set(y, Math.min(short.get(y) ?? sx + 1, sx + 1));
309
- }
310
- }
311
- const l = long.get(hi);
312
- return l !== void 0 && l === short.get(hi) ? l : null;
313
- }
314
- };
315
- }
316
- function chain(levels) {
317
- if (!Array.isArray(levels) || levels.length === 0) {
318
- throw new UnitError("EMPTY_CHAIN", "a chain needs at least one level");
319
- }
320
- const n = levels.length;
321
- const grid = (f) => [...Array(n)].map((_, i) => [...Array(n)].map((__, j) => f(i, j)));
322
- return build(levels, grid(Math.max), grid(Math.min));
323
- }
324
- function order(levels, leq) {
325
- if (!Array.isArray(levels) || levels.length === 0) {
326
- throw new UnitError("EMPTY_CHAIN", "an order needs at least one level");
327
- }
328
- const n = levels.length;
329
- const bound = (a, b, up) => {
330
- const bs = [...Array(n).keys()].filter((x) => up ? leq[a][x] && leq[b][x] : leq[x][a] && leq[x][b]);
331
- const least = bs.filter((x) => bs.every((y) => up ? leq[x][y] : leq[y][x]));
332
- if (least.length !== 1) {
333
- throw new UnitError("MALFORMED", `\`${levels[a]}\` and \`${levels[b]}\` have ${least.length} ${up ? "lowest common" : "highest common"} bounds, so this is not a usable scale`, { levels: [levels[a], levels[b]] });
334
- }
335
- return least[0];
336
- };
337
- const grid = (up) => [...Array(n)].map((_, i) => [...Array(n)].map((__, j) => bound(i, j, up)));
338
- return build(levels, grid(true), grid(false));
339
- }
340
-
341
- // work/bound-0.1.9/repository/node_modules/@lapxo/obligations/dist/debit/unit.js
342
- function unit(subject, bounds) {
343
- return { subject, floor: bounds.floor, ceiling: bounds.ceiling };
344
- }
345
- var permitAll = (c, subject) => unit(subject, { floor: c.bottom, ceiling: c.top });
346
- function state(c, u) {
347
- return c.stateOf(c.rank(u.floor), c.rank(u.ceiling));
348
- }
349
- function band(c, units, from, onFloor, onCeiling) {
350
- let floor = from.floor;
351
- let ceiling = from.ceiling;
352
- for (const u of units) {
353
- floor = onFloor(floor, c.rank(u.floor));
354
- ceiling = onCeiling(ceiling, c.rank(u.ceiling));
355
- }
356
- return { subject: units[0].subject, floor: c.levels[floor], ceiling: c.levels[ceiling] };
357
- }
358
- function fuse(c, units) {
359
- if (units.length === 0)
360
- return permitAll(c, "");
361
- return band(c, units, { floor: c.bottomIx, ceiling: c.topIx }, (a, b) => c.higher(a, b), (a, b) => c.lower(a, b));
362
- }
363
- function entails(c, a, b) {
364
- const [af, ac] = [c.rank(a.floor), c.rank(a.ceiling)];
365
- const [bf, bc] = [c.rank(b.floor), c.rank(b.ceiling)];
366
- return c.leq(bf, af) && c.leq(ac, bc);
367
- }
368
-
369
- // work/bound-0.1.9/repository/node_modules/@lapxo/obligations/dist/debit/packed.js
370
- var WIDTH = 32;
371
-
372
- // work/bound-0.1.9/repository/node_modules/@lapxo/obligations/dist/debit/masks.js
373
- function chunkCount(n) {
374
- if (n <= 0)
375
- return 0;
376
- return Math.ceil(n / WIDTH);
377
- }
378
- var WideMask = class _WideMask {
379
- words;
380
- width;
381
- constructor(width, words) {
382
- this.width = width;
383
- this.words = words ?? new Uint32Array(chunkCount(width));
384
- }
385
- static fromTokens(tokens, allowed) {
386
- const m = new _WideMask(tokens.length);
387
- tokens.forEach((t, i) => {
388
- if (allowed.has(t))
389
- m.set(i);
390
- });
391
- return m;
392
- }
393
- set(bit) {
394
- if (bit < 0 || bit >= this.width) {
395
- throw new UnitError("MALFORMED", `bit ${bit} is outside a mask of width ${this.width}`, {
396
- bit,
397
- width: this.width
398
- });
399
- }
400
- this.words[bit >> 5] |= 1 << (bit & 31);
401
- }
402
- has(bit) {
403
- if (bit < 0 || bit >= this.width)
404
- return false;
405
- return (this.words[bit >> 5] & 1 << (bit & 31)) !== 0;
406
- }
407
- and(other) {
408
- const w = Math.max(this.width, other.width);
409
- const out = new _WideMask(w);
410
- const n = Math.min(this.words.length, other.words.length);
411
- for (let i = 0; i < n; i++)
412
- out.words[i] = this.words[i] & other.words[i];
413
- return out;
414
- }
415
- or(other) {
416
- const w = Math.max(this.width, other.width);
417
- const out = new _WideMask(w);
418
- for (let i = 0; i < out.words.length; i++) {
419
- out.words[i] = (this.words[i] ?? 0) | (other.words[i] ?? 0);
420
- }
421
- return out;
422
- }
423
- difference(other) {
424
- const w = Math.max(this.width, other.width);
425
- const out = new _WideMask(w);
426
- for (let i = 0; i < out.words.length; i++) {
427
- out.words[i] = (this.words[i] ?? 0) & ~(other.words[i] ?? 0);
428
- }
429
- const spare = w % 32;
430
- if (spare !== 0 && out.words.length > 0) {
431
- out.words[out.words.length - 1] &= (1 << spare) - 1;
432
- }
433
- return out;
434
- }
435
- subsetOf(other) {
436
- const n = Math.max(this.words.length, other.words.length);
437
- for (let i = 0; i < n; i++) {
438
- const a = this.words[i] ?? 0;
439
- const b = other.words[i] ?? 0;
440
- if ((a & ~b) !== 0)
441
- return false;
442
- }
443
- return true;
444
- }
445
- size() {
446
- let n = 0;
447
- for (let i = 0; i < this.width; i++)
448
- if (this.has(i))
449
- n++;
450
- return n;
451
- }
452
- members(tokens) {
453
- return tokens.filter((_, i) => this.has(i));
454
- }
455
- static filled(width) {
456
- const m = new _WideMask(width);
457
- if (width <= 0)
458
- return m;
459
- m.words.fill(4294967295);
460
- const spare = width % 32;
461
- if (spare !== 0)
462
- m.words[m.words.length - 1] = (1 << spare) - 1;
463
- return m;
464
- }
465
- };
466
-
467
- // work/bound-0.1.9/repository/node_modules/@lapxo/obligations/dist/lattice/scale-lattice.js
468
- function fromScale(c) {
469
- const inhabited = (x) => state(c, x) !== "CONFLICT";
470
- return {
471
- top: permitAll(c, ""),
472
- bottom: { subject: "", floor: c.levels[c.topIx] ?? "", ceiling: c.levels[c.bottomIx] ?? "" },
473
- leq: (a, b) => entails(c, a, b),
474
- meet: (a, b) => fuse(c, [a, b]),
475
- join: (a, b) => {
476
- if (!inhabited(a))
477
- return b;
478
- if (!inhabited(b))
479
- return a;
480
- return {
481
- subject: a.subject || b.subject,
482
- floor: c.levels[c.lower(c.rank(a.floor), c.rank(b.floor))] ?? a.floor,
483
- ceiling: c.levels[c.higher(c.rank(a.ceiling), c.rank(b.ceiling))] ?? a.ceiling
484
- };
485
- },
486
- show: (x) => `[${x.floor}, ${x.ceiling}]`,
487
- inhabited
488
- };
489
- }
490
- function subsets(tokens) {
491
- return {
492
- bottom: new WideMask(tokens.length),
493
- top: WideMask.filled(tokens.length),
494
- leq: (a, b) => a.subsetOf(b),
495
- meet: (a, b) => a.and(b),
496
- join: (a, b) => a.or(b),
497
- show: (x) => x.members(tokens).join(","),
498
- inhabited: (x) => x.size() > 0
499
- };
500
- }
501
-
502
- // work/bound-0.1.9/repository/node_modules/@lapxo/obligations/dist/lattice/forms.js
503
- function intervals(lo, hi) {
504
- const low = Math.min(lo, hi);
505
- const high = Math.max(lo, hi);
506
- return {
507
- bottom: { lo: high, hi: low },
508
- top: { lo: low, hi: high },
509
- leq(a, b) {
510
- if (a.lo > a.hi)
511
- return true;
512
- if (b.lo > b.hi)
513
- return false;
514
- return b.lo <= a.lo && a.hi <= b.hi;
515
- },
516
- meet(a, b) {
517
- return { lo: Math.max(a.lo, b.lo), hi: Math.min(a.hi, b.hi) };
518
- },
519
- join(a, b) {
520
- if (a.lo > a.hi)
521
- return b;
522
- if (b.lo > b.hi)
523
- return a;
524
- return { lo: Math.min(a.lo, b.lo), hi: Math.max(a.hi, b.hi) };
525
- },
526
- show(x) {
527
- return x.lo > x.hi ? "empty" : `${x.lo}..${x.hi}`;
528
- },
529
- inhabited(x) {
530
- return x.lo <= x.hi;
531
- }
532
- };
533
- }
534
- function form(f) {
535
- const held = { lattice: f.lattice, parse: f.parse, emit: f.emit, count: f.count, show: f.show, points: f.points };
536
- const lacking = Object.entries(held).find(([, fn]) => typeof fn !== "function");
537
- if (lacking)
538
- throw new Error(`form \`${f.id}\` declared no ${lacking[0]}`);
539
- return f;
540
- }
541
- var rec = (x) => x !== null && typeof x === "object" ? x : {};
542
- function strings(x) {
543
- return Array.isArray(x) ? x.map(String) : [];
544
- }
545
- var drawn = (seed) => {
546
- let s = seed >>> 0;
547
- return () => {
548
- s = s + 1831565813 >>> 0;
549
- let t = Math.imul(s ^ s >>> 15, s | 1);
550
- t ^= t + Math.imul(t ^ t >>> 7, t | 61);
551
- return ((t ^ t >>> 14) >>> 0) / 4294967296;
552
- };
553
- };
554
- var picked = (draw, xs) => xs[Math.floor(draw() * xs.length)];
555
- function bandCount(levels, folded) {
556
- if (levels.length === 0)
557
- return { kind: "refused", why: "a ladder with no levels cannot be counted" };
558
- const c = chain(levels);
559
- const f = c.rank(folded.floor);
560
- const cl = c.rank(folded.ceiling);
561
- if (!c.leq(f, cl))
562
- return { kind: "finite", n: 0 };
563
- const n = levels.filter((_, i) => c.leq(f, i) && c.leq(i, cl)).length;
564
- return { kind: "finite", n };
565
- }
566
- var BAND = {
567
- parse(params, demand) {
568
- const L = this.lattice(params);
569
- const d = rec(demand);
570
- return {
571
- subject: String(d.subject ?? ""),
572
- floor: String(d.floor ?? L.top.floor),
573
- ceiling: String(d.ceiling ?? L.top.ceiling)
574
- };
575
- },
576
- emit(_params, value) {
577
- return { subject: value.subject, floor: value.floor, ceiling: value.ceiling };
578
- },
579
- count(folded, params) {
580
- return bandCount(strings(rec(params).levels), folded);
581
- },
582
- points(params, seed, n) {
583
- const L = this.lattice(params);
584
- const levels = strings(rec(params).levels);
585
- const draw = drawn(seed);
586
- const band2 = (floor, ceiling) => ({ subject: "", floor, ceiling });
587
- return Array.from({ length: n }, () => {
588
- const [a, b] = [picked(draw, levels), picked(draw, levels)];
589
- return [band2(a, b), band2(b, a)].find((x) => L.inhabited(x)) ?? band2(a, a);
590
- });
591
- }
592
- };
593
- var ladderForm = form({
594
- id: "ladder",
595
- lattice(params) {
596
- const levels = strings(rec(params).levels);
597
- if (levels.length === 0)
598
- throw new Error("ladder needs levels");
599
- return fromScale(chain(levels));
600
- },
601
- ...BAND,
602
- show(value) {
603
- return value.floor === value.ceiling ? value.floor : `${value.floor}..${value.ceiling}`;
604
- }
605
- });
606
- var alphabetForm = form({
607
- id: "alphabet",
608
- lattice(params) {
609
- return subsets(strings(rec(params).tokens));
610
- },
611
- parse(params, demand) {
612
- const tokens = strings(rec(params).tokens);
613
- const d = rec(demand);
614
- const want = d.want !== void 0 ? strings(d.want) : tokens;
615
- return WideMask.fromTokens(tokens, new Set(want));
616
- },
617
- emit(params, value) {
618
- return { want: value.members(strings(rec(params).tokens)) };
619
- },
620
- count(folded) {
621
- return { kind: "finite", n: folded.size() };
622
- },
623
- show(value) {
624
- return `${value.size()}`;
625
- },
626
- points(params, seed, n) {
627
- const tokens = strings(rec(params).tokens);
628
- const draw = drawn(seed);
629
- return Array.from({ length: n }, () => WideMask.fromTokens(tokens, new Set(tokens.filter(() => draw() < 0.5))));
630
- }
631
- });
632
- var continuousForm = form({
633
- id: "continuous",
634
- lattice(params) {
635
- const p = rec(params);
636
- return intervals(Number(p.lo ?? 0), Number(p.hi ?? 1));
637
- },
638
- parse(params, demand) {
639
- const L = this.lattice(params);
640
- const d = rec(demand);
641
- return {
642
- lo: d.lo === void 0 ? L.top.lo : Number(d.lo),
643
- hi: d.hi === void 0 ? L.top.hi : Number(d.hi)
644
- };
645
- },
646
- emit(_params, value) {
647
- return { lo: value.lo, hi: value.hi };
648
- },
649
- count() {
650
- return { kind: "refused", why: "a continuous band has no count; prefer not to exist over inventing one" };
651
- },
652
- show(value) {
653
- return value.lo > value.hi ? "empty" : `${value.lo}..${value.hi}`;
654
- },
655
- points(params, seed, n) {
656
- const p = rec(params);
657
- const lo = Number(p.lo ?? 0);
658
- const hi = Number(p.hi ?? 1);
659
- const draw = drawn(seed);
660
- const at = () => lo + Math.round(draw() * (hi - lo));
661
- return Array.from({ length: n }, () => ({ lo: at(), hi: at() }));
662
- }
663
- });
664
- var latticeForm = form({
665
- id: "lattice",
666
- lattice(params) {
667
- const p = rec(params);
668
- const levels = strings(p.levels);
669
- const leq = p.leq;
670
- if (levels.length && leq)
671
- return fromScale(order(levels, leq));
672
- throw new Error("lattice needs levels+leq");
673
- },
674
- ...BAND,
675
- show(value) {
676
- return `${value.floor}..${value.ceiling}`;
677
- }
678
- });
679
- var FORM_IMPLEMENTATIONS = [ladderForm, alphabetForm, continuousForm, latticeForm];
680
- var FORMS = [...FORM_IMPLEMENTATIONS];
681
-
682
- // work/bound-0.1.9/repository/node_modules/@lapxo/obligations/dist/field/field.js
683
- function coordinate(name, steps = "/") {
684
- const at = name.split(new RegExp(`[${steps.replace(/[.*+?^${}()|[\]\\-]/g, "\\$&")}]`)).filter((s) => s !== "");
685
- while (at[at.length - 1] === "*" || at[at.length - 1] === "**")
686
- at.pop();
687
- return at;
688
- }
689
-
690
- // work/bound-0.1.9/repository/node_modules/@lapxo/obligations/dist/lattice/obligatory.js
691
- function cell(at, epoch = 0, seen = [], restsOn = []) {
692
- return { at: coordinate(at), epoch, seen, restsOn };
693
- }
694
- function mark(one) {
695
- if (one.widens !== void 0 && one.reach === "travels") {
696
- throw new UnitError("widening-travels", "obligations: REFUSE\xB7widening-travels a widening stands where it was witnessed and never travels to what rests there", { pole: one.pole });
697
- }
698
- return one.takes === void 0 ? one : { ...one, sign: -1 };
699
- }
700
- function live(lines) {
701
- const taken = new Set(lines.flatMap((line) => line.takes === void 0 ? [] : [line.takes]));
702
- return lines.filter((line) => line.takes === void 0 && (line.id === void 0 || !taken.has(line.id)));
703
- }
704
- function restOf(c, world = /* @__PURE__ */ new Map()) {
705
- const own = c.at.join("/");
706
- const out = [];
707
- const held = /* @__PURE__ */ new Set();
708
- const edge = [...c.restsOn];
709
- for (let i = 0; i < edge.length; i += 1) {
710
- const name = edge[i];
711
- if (name === own)
712
- throw new UnitError("rest-cycle", `obligations: REFUSE\xB7rest ${own} rests on itself: an order of rest with a cycle has no fold to reach`, { at: own });
713
- if (held.has(name))
714
- continue;
715
- held.add(name);
716
- out.push(name);
717
- edge.push(...world.get(name)?.restsOn ?? []);
718
- }
719
- return out;
720
- }
721
- function parts(L, c, world = /* @__PURE__ */ new Map()) {
722
- const rest = restOf(c, world);
723
- const above = rest.flatMap((name) => live(world.get(name)?.marks ?? []).filter((one) => one.reach === "travels" && one.widens === void 0));
724
- const marks = [...live(c.marks ?? []), ...above].sort((a, b) => (a.at ?? 0) - (b.at ?? 0));
725
- let required = L.top;
726
- let signed = L.top;
727
- for (const one of marks) {
728
- if (one.pole === "floor")
729
- required = L.meet(required, one.span);
730
- else
731
- signed = one.widens === void 0 ? L.meet(signed, one.span) : L.join(signed, one.span);
732
- }
733
- const origins = live(c.seen);
734
- const held = origins.reduce((acc, claim) => L.meet(acc, claim.span), L.top);
735
- return { floor: L.meet(required, held), ceiling: L.meet(signed, held), origins, rest, required, signed };
736
- }
737
- function state2(L, c, world = /* @__PURE__ */ new Map()) {
738
- const { floor, ceiling, origins, required, signed } = parts(L, c, world);
739
- if (!L.inhabited(L.meet(required, signed)))
740
- return "CONFLICT";
741
- if (new Set(origins.map((claim) => claim.origin)).size < 2)
742
- return "REQUIRED";
743
- if (!L.inhabited(origins.reduce((acc, claim) => L.meet(acc, claim.span), L.top)))
744
- return "CONFLICT";
745
- return L.inhabited(L.meet(floor, ceiling)) ? "FREE" : "FORBIDDEN";
746
- }
747
-
748
- // work/bound-0.1.9/repository/node_modules/@lapxo/topos/dist/wire/object-record.js
749
- function coordinateText(value) {
750
- return value !== "" && !/[\s\\|]/.test(value) && value.split("/").every((s) => s !== "" && s !== "." && s !== ".." && s !== "*" && s !== "**");
751
- }
752
- function restCoordinates(text) {
753
- try {
754
- const read = alphabet(text);
755
- if (read.polarity !== "permit" || read.members.some((one) => !coordinateText(one)))
756
- return void 0;
757
- const sorted = [...new Set(read.members)].sort(byBytes);
758
- if (alphabet({ polarity: "permit", members: sorted }) !== text)
759
- return void 0;
760
- return sorted;
761
- } catch {
762
- return void 0;
763
- }
764
- }
765
- var COMMON = ["type", "scope", "id", "epoch", "by", "sig"];
766
- function objectFromFields(fields, keys, schema, globalFields, forms) {
767
- const bad = (why, key) => refuse(why, key);
768
- if (keys.includes("at"))
769
- return bad("object records carry no at: order is epoch and a local join witness is widens", "at");
770
- const type = fields.type;
771
- if (!schema.types.has(type ?? "") || !["cell", "claim", "mark"].includes(type ?? ""))
772
- return bad("an object record names a declared type: cell, claim or mark", "type");
773
- if (!/^(0|[1-9][0-9]*)$/.test(fields.epoch ?? "") || !Number.isSafeInteger(Number(fields.epoch)))
774
- return bad("an object record carries an exactly supported logical epoch", "epoch");
775
- if (Number(fields.epoch) < schema.activation)
776
- return bad(`an object epoch precedes typed-wire activation ${schema.activation}`, "epoch");
777
- let row;
778
- if (type === "cell")
779
- row = "cell";
780
- else if (fields.sign === "-1")
781
- row = `${type}/negative`;
782
- else if (fields.sign !== "+1")
783
- return bad("a claim or mark names sign=+1 or sign=-1", "sign");
784
- else if (type === "claim")
785
- row = "claim/positive";
786
- else if (fields.pole === "floor" && fields.reach === "travels" && fields.widens === void 0)
787
- row = "mark/floor-travelling";
788
- else if (fields.pole === "ceiling" && fields.reach === "travels" && fields.widens === void 0)
789
- row = "mark/travelling";
790
- else if (fields.pole === "ceiling" && fields.reach === "local")
791
- row = "mark/local";
792
- else
793
- return bad("a positive mark is ceiling/travels, ceiling/local with widens, or floor/travels without widens", "pole");
794
- const required = schema.required.get(row);
795
- const allowed = schema.allowed.get(row);
796
- if (!required || !allowed || schema.common.size === 0 || schema.configuration.size === 0 || [...schema.common].some((k) => !required.has(k) || !allowed.has(k)) || [...required].some((k) => !allowed.has(k)))
797
- return bad(`typed wire has no complete required/allowed contract for ${row}`, "type");
798
- for (const key of COMMON)
799
- if (fields[key] === void 0 || fields[key] === "")
800
- return bad(`an object record has no ${key}`, key);
801
- for (const key of keys)
802
- if (!globalFields.has(key) || !allowed.has(key))
803
- return bad(`\`${key}=\` is not allowed on ${row}`, key);
804
- for (const key of required)
805
- if (!allowed.has(key) || fields[key] === void 0 || fields[key] === "")
806
- return bad(`a ${row} record has no declared required \`${key}\``, key);
807
- if (!coordinateText(fields.scope))
808
- return bad("scope is a canonical cell coordinate", "scope");
809
- if (type === "cell") {
810
- if (!forms.has(fields.form))
811
- return bad("the cell names no admitted form", "form");
812
- if (restCoordinates(fields.restsOn) === void 0)
813
- return bad("cell restsOn is none or a canonical alphabet of coordinates", "restsOn");
814
- }
815
- return fact({ record: type, fields: { ...fields } });
816
- }
817
-
818
- // work/bound-0.1.9/repository/node_modules/@lapxo/topos/dist/wire/sig.js
819
- function parseSignature(value) {
820
- const colon = value.lastIndexOf(":");
821
- if (colon <= 0 || colon === value.length - 1)
822
- return null;
823
- return { algorithm: value.slice(0, colon), raw: value.slice(colon + 1) };
824
- }
825
-
826
- // work/bound-0.1.9/repository/node_modules/@lapxo/topos/dist/wire/claimline.js
827
- var ENVELOPE = /* @__PURE__ */ new Set(["sig", "expires", "repo", "by", "epoch"]);
828
- var WITHDRAW = "withdraw";
829
- var WIRE = "wire/";
830
- var WAS = "audit/wire/";
831
- function listOf(scope) {
832
- if (scope.startsWith(WAS))
833
- return scope.slice(WAS.length);
834
- if (scope.startsWith(WIRE))
835
- return scope.slice(WIRE.length);
836
- return void 0;
837
- }
838
- function epochOf(fields) {
839
- const value = fields["epoch"] ?? "";
840
- return /^\d+$/.test(value) ? Number(value) : 0;
841
- }
842
- function names(withdraw, line) {
843
- return Object.keys(withdraw).filter((k) => k !== "value" && !ENVELOPE.has(k)).every((k) => line[k] === withdraw[k]);
844
- }
845
- function wireAt(lines, epoch) {
846
- const mine = lines.filter((f) => listOf(f["scope"] ?? "") !== void 0 && epochOf(f) <= epoch);
847
- const withdrawals = mine.filter((f) => f["value"] === WITHDRAW);
848
- const candidates = /* @__PURE__ */ new Map();
849
- for (const f of mine) {
850
- if (f["value"] === WITHDRAW || withdrawals.some((w) => names(w, f)))
851
- continue;
852
- const key = (listOf(f["scope"] ?? "") ?? "") + "\0" + (f["by"] ?? "");
853
- const held = candidates.get(key) ?? [];
854
- const newest = held.length ? epochOf(held[0]) : -1;
855
- if (epochOf(f) > newest)
856
- candidates.set(key, [f]);
857
- else if (epochOf(f) === newest)
858
- candidates.set(key, [...held, f]);
859
- }
860
- const live2 = [...candidates.values()].flatMap((rows) => rows.some((f) => (f["scope"] ?? "").startsWith(WIRE)) ? rows.filter((f) => (f["scope"] ?? "").startsWith(WIRE)) : rows);
861
- const values = /* @__PURE__ */ new Map();
862
- for (const f of live2) {
863
- const key = listOf(f["scope"] ?? "") ?? "", prior = values.get(key);
864
- if (prior !== void 0 && prior !== f["value"])
865
- throw Error(`REFUSE\xB7wire wire/${key} has conflicting live declarations`);
866
- values.set(key, f["value"] ?? "");
867
- }
868
- const standing = /* @__PURE__ */ new Map();
869
- for (const f of mine) {
870
- const key = listOf(f["scope"] ?? "") ?? "";
871
- if (f["value"] === WITHDRAW || withdrawals.some((w) => names(w, f)))
872
- continue;
873
- const held = standing.get(key);
874
- const newer = held === void 0 || epochOf(f) > epochOf(held) || epochOf(f) === epochOf(held) && (f["scope"] ?? "").startsWith(WIRE) && (held["scope"] ?? "").startsWith(WAS);
875
- if (newer)
876
- standing.set(key, f);
877
- }
878
- if (!standing.size)
879
- return null;
880
- const ids = (name) => new Set((standing.get(name)?.["value"] ?? "").split("|").filter(Boolean));
881
- const formOf = new Map([...standing].filter(([name]) => name.startsWith("form/")).map(([name, f]) => [name.slice("form/".length), f["value"] ?? ""]));
882
- const lists = new Map([...standing.keys()].filter((name) => !name.includes("/")).map((name) => [name, ids(name)]));
883
- return {
884
- epoch,
885
- ...standing.has("object/types") ? { object: {
886
- activation: epochOf(standing.get("object/types")),
887
- types: ids("object/types"),
888
- common: ids("object/common"),
889
- reserved: ids("object/reserved"),
890
- configuration: ids("object/allowed/config"),
891
- required: new Map([...standing.keys()].filter((k) => k.startsWith("object/required/")).map((k) => [k.slice("object/required/".length), ids(k)])),
892
- allowed: new Map([...standing.keys()].filter((k) => k.startsWith("object/allowed/")).map((k) => [k.slice("object/allowed/".length), ids(k)]))
893
- } } : {},
894
- fields: ids("fields"),
895
- required: ids("required"),
896
- roles: ids("roles"),
897
- forms: ids("forms"),
898
- classes: ids("at-classes"),
899
- digests: new Set([...ids("digest-algorithms")].map((one) => one.split(":")[0])),
900
- signatures: ids("signature-algorithms"),
901
- formOf,
902
- lists
903
- };
904
- }
905
- function admittedDigest(value, wire) {
906
- const colon = value.indexOf(":");
907
- return colon > 0 && wire.digests.has(value.slice(0, colon)) && /^[0-9a-f]+$/i.test(value.slice(colon + 1));
908
- }
909
- function isRegion(need) {
910
- if (need.startsWith("/") || /[\s\\]/.test(need))
911
- return false;
912
- const steps = need.split("/").filter((step) => step !== "");
913
- return steps.length > 0 && steps.every((step, i) => step !== "." && step !== ".." && (!step.includes("*") || i === steps.length - 1));
914
- }
915
- var FIELD_FORMS = {
916
- region: (value) => value.split("|").filter(Boolean).every(isRegion),
917
- class: (value, wire) => {
918
- const colon = value.indexOf(":");
919
- if (colon <= 0 || !wire.classes.has(value.slice(0, colon)))
920
- return false;
921
- const rest = value.slice(colon + 1);
922
- return !/^[a-z0-9-]+:[0-9a-f]{16,}$/i.test(rest) || admittedDigest(rest, wire);
923
- },
924
- signature: (value, wire) => {
925
- const got = parseSignature(value);
926
- if (got === null || !wire.signatures.has(got.algorithm))
927
- return false;
928
- const era = got.algorithm.slice(got.algorithm.lastIndexOf(":") + 1);
929
- return admittedDigest(got.algorithm, wire) || got.algorithm.includes(":") && (wire.lists.get("era")?.has(era) ?? false);
930
- },
931
- count: (value) => /^\d+$/.test(value)
932
- };
933
- function debit(field, why) {
934
- return refuse(why, field);
935
- }
936
- function fromLine(text, wire, grammars) {
937
- const line = parse(text, { preserveKeys: true });
938
- if (line.kind !== "fact") {
939
- return line.kind === "abstain" ? abstain(line.why) : refuse(line.why, line.named);
940
- }
941
- const f = line.value.fields;
942
- const keys = line.value.keys;
943
- if (keys.includes("type")) {
944
- if (!wire?.object)
945
- return refuse("typed object grammar is not admitted at this epoch", "type");
946
- if (!wire.object.configuration.size || !wire.object.reserved.size || [...wire.object.reserved].some((k) => wire.object.configuration.has(k)))
947
- return refuse("typed wire has no closed configuration/object field contract", "type");
948
- const got = objectFromFields(f, keys, wire.object, wire.fields, wire.forms);
949
- if (got.kind !== "fact")
950
- return got;
951
- if (!FIELD_FORMS.signature(f.sig, wire))
952
- return refuse("object signature grammar is not admitted", "sig");
953
- if (got.value.record === "cell" && !admittedDigest(f.topos, wire))
954
- return refuse("cell topos is not an admitted digest", "topos");
955
- if (got.value.record === "cell" && (f.restsOn ?? "").split("|").some((name) => admittedDigest(name, wire)))
956
- return refuse("cell restsOn names coordinates, not byte digests", "restsOn");
957
- return got;
958
- }
959
- if (wire) {
960
- if (wire.object) {
961
- if (!wire.object.configuration.size || !wire.object.reserved.size || [...wire.object.reserved].some((k) => wire.object.configuration.has(k)))
962
- return refuse("typed wire has no closed configuration/object field contract", "type");
963
- const reserved = keys.find((k) => wire.object.reserved.has(k) || !wire.object.configuration.has(k));
964
- if (reserved)
965
- return refuse(`\`${reserved}=\` is an object-only field: untyped configuration cannot carry it`, reserved);
966
- }
967
- for (const k of Object.keys(f))
968
- if (!wire.fields.has(k))
969
- return debit(k, `\`${k}=\` is not a field of the wire at epoch ${wire.epoch}`);
970
- for (const k of wire.required)
971
- if (f[k] === void 0)
972
- return debit(k, `a claim with no \`${k}\``);
973
- for (const [k, form2] of wire.formOf) {
974
- const v = f[k];
975
- if (v === void 0)
976
- continue;
977
- const ids = wire.lists.get(form2);
978
- const reads = FIELD_FORMS[form2] ?? (ids ? (value) => ids.has(value) : void 0);
979
- if (!reads)
980
- return abstain(`\`${k}\` takes the form ${form2}, which this reader does not know`);
981
- if (!reads(v, wire))
982
- return debit(k, `\`${k}=${v}\` is not a ${form2} of the wire at epoch ${wire.epoch}`);
983
- }
984
- if (f.role !== void 0 && !wire.roles.has(f.role))
985
- return abstain(`\`role=${f.role}\` is a role this wire does not name`);
986
- if (!wire.forms.has(f.form ?? ""))
987
- return abstain(`\`form=${f.form}\` is a form this wire does not name`);
988
- }
989
- const listed = Array.isArray(grammars) ? grammars : void 0;
990
- const bound = f.value === WITHDRAW ? { kind: "enumerated", values: [WITHDRAW] } : boundOf(f.form ?? "", f.value ?? "", listed);
991
- if (bound === null) {
992
- const mine = BOUND_FORMS.includes(f.form ?? "") || (listed?.some((g) => g.form === f.form) ?? false);
993
- return mine ? debit("value", `\`${f.value}\` is not a ${f.form}`) : abstain(`\`form=${f.form}\` is a form this reader does not know`);
994
- }
995
- const role = f.role === "writes" ? "writes" : f.role === "demands" ? "demands" : "reads";
996
- const extra = {};
997
- for (const [k, v] of Object.entries(f)) {
998
- if (["scope", "measure", "form", "value", "by", "at", "role", "unit", "multiplicity", "epoch", "ref", "to", "ref_by"].includes(k))
999
- continue;
1000
- extra[k] = v;
1001
- }
1002
- const rel = f.ref;
1003
- const to = f.to === void 0 ? null : unpipe(f.to);
1004
- const reference = rel && to && REF_RELATIONS.includes(rel) ? { rel, to, by: f.ref_by === "declared" ? "declared" : "inferred" } : null;
1005
- return fact({
1006
- scope: f.scope ?? "",
1007
- measure: f.measure ?? "",
1008
- bound,
1009
- role,
1010
- by: f.by ?? "",
1011
- at: f.at ?? "",
1012
- ...f.unit !== void 0 ? { unit: f.unit } : {},
1013
- ...f.multiplicity === "one" || f.multiplicity === "many" || f.multiplicity === "unknown" ? { multiplicity: f.multiplicity } : {},
1014
- ...f.epoch !== void 0 ? { epoch: f.epoch } : {},
1015
- ...reference ? { reference } : {},
1016
- extra
1017
- });
1018
- }
1019
- var EPOCHS = intervals(-Infinity, Infinity);
1020
- var QUORUMS = intervals(1, Infinity);
1021
-
1022
- // work/bound-0.1.9/repository/node_modules/@lapxo/topos/dist/wire/record-kind.js
1023
- function recordKind(text) {
1024
- const got = parse(text, { preserveKeys: true });
1025
- if (got.kind !== "fact")
1026
- return got;
1027
- if (!got.value.keys.includes("type"))
1028
- return fact("config");
1029
- const type = got.value.fields.type;
1030
- return type === "cell" || type === "claim" || type === "mark" ? fact(type) : refuse("an explicit type names cell, claim or mark", "type");
1031
- }
1032
-
1033
- // work/bound-0.1.9/repository/node_modules/@lapxo/topos/dist/wire/object-history.js
1034
- function objectHistory(lines) {
1035
- const parsed = [];
1036
- for (const text of lines) {
1037
- const p = parse(text);
1038
- if (p.kind !== "fact")
1039
- return p;
1040
- parsed.push(p.value.fields);
1041
- }
1042
- const objects = [], configuration = [];
1043
- for (let i = 0; i < lines.length; i++) {
1044
- const k = recordKind(lines[i]);
1045
- if (k.kind !== "fact")
1046
- return k;
1047
- if (k.value === "config") {
1048
- configuration.push(parsed[i]);
1049
- continue;
1050
- }
1051
- const got = fromLine(lines[i], wireAt(parsed, Number(parsed[i].epoch)));
1052
- if (got.kind !== "fact")
1053
- return got;
1054
- if (!("record" in got.value))
1055
- throw Error("typed history returned configuration");
1056
- objects.push(got.value);
1057
- }
1058
- return fact({ objects, configuration });
1059
- }
1060
-
1061
- // work/topos-0.1.17/repository/dist/wire/outcome.js
1062
- var fact2 = (value) => ({ kind: "fact", value });
1063
- var refuse3 = (why, named) => ({ kind: "refuse", why, ...named === void 0 ? {} : { named } });
1064
-
1065
- // work/topos-0.1.17/repository/dist/wire/values.js
1066
- function unpipe2(value) {
1067
- const out = [];
1068
- let at = "";
1069
- for (let i = 0; i < value.length; i++) {
1070
- const c = value[i];
1071
- if (c === "\\") {
1072
- const next = value[i + 1];
1073
- if (next !== "|" && next !== "\\")
1074
- return null;
1075
- at += next;
1076
- i += 1;
1077
- } else if (c === "|") {
1078
- out.push(at);
1079
- at = "";
1080
- } else {
1081
- at += c;
1082
- }
1083
- }
1084
- out.push(at);
1085
- return out;
1086
- }
1087
- var OPEN2 = "*";
1088
- var num2 = (s) => {
1089
- if (!/^-?\d+(\.\d+)?$/.test(s))
1090
- return null;
1091
- const n = Number(s);
1092
- return isFinite(n) ? n : null;
1093
- };
1094
- var GRAMMARS2 = {
1095
- interval: (value) => {
1096
- const at = value.indexOf("..");
1097
- if (at < 0)
1098
- return null;
1099
- const lo = value.slice(0, at);
1100
- const hi = value.slice(at + 2);
1101
- const l = lo === OPEN2 ? null : num2(lo);
1102
- const h = hi === OPEN2 ? null : num2(hi);
1103
- if (lo !== OPEN2 && l === null || hi !== OPEN2 && h === null)
1104
- return null;
1105
- return { kind: "interval", lo: l, hi: h };
1106
- },
1107
- alphabet: (value) => {
1108
- const values = unpipe2(value);
1109
- return values === null ? null : { kind: "enumerated", values };
1110
- },
1111
- ladder: (value) => {
1112
- const parts2 = unpipe2(value);
1113
- if (parts2 === null || parts2.length !== 2)
1114
- return null;
1115
- return { kind: "band", floor: parts2[0] ?? "", ceiling: parts2[1] ?? "" };
1116
- }
1117
- };
1118
- function boundOf2(form2, value, grammars) {
1119
- const extra = Array.isArray(grammars) ? grammars.find((g) => g.form === form2) : void 0;
1120
- if (extra)
1121
- return extra.parse(value);
1122
- return GRAMMARS2[form2]?.(value) ?? null;
1123
- }
1124
- var BOUND_FORMS2 = Object.keys(GRAMMARS2);
1125
-
1126
- // work/topos-0.1.17/repository/dist/wire/line.js
1127
- var PROTOCOL2 = "bound-lock/1";
1128
- var NEEDS_QUOTE2 = /[ ="\n\\]/;
1129
- function escape2(value) {
1130
- if (!NEEDS_QUOTE2.test(value))
1131
- return value;
1132
- return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n")}"`;
1133
- }
1134
- var UTF82 = new TextEncoder();
1135
- function byBytes2(a, b) {
1136
- const x = UTF82.encode(a);
1137
- const y = UTF82.encode(b);
1138
- for (let i = 0; i < x.length && i < y.length; i++) {
1139
- if (x[i] !== y[i])
1140
- return x[i] - y[i];
1141
- }
1142
- return x.length - y.length;
1143
- }
1144
- var unwritten2 = (fields) => fields["form"] === "interval" && fields["value"] !== void 0 && fields["value"] !== "withdraw" && boundOf2("interval", fields["value"]) === null;
1145
- function canonical2(fields, version = "1") {
1146
- if (unwritten2(fields))
1147
- throw new Error(`REFUSE\xB7wire canonical: \`${fields["value"]}\` is no interval the wire writes: two ends, each decimal or *`);
1148
- const keys = Object.keys(fields).sort(byBytes2);
1149
- const tokens = keys.map((k) => `${k}=${escape2(fields[k])}`);
1150
- return [`${PROTOCOL2.split("/")[0]}/${version}`, ...tokens].join(" ");
1151
- }
1152
- function signedBytes(fields, version = "1") {
1153
- const { sig: _sig, ...rest } = fields;
1154
- return canonical2(rest, version);
1155
- }
1156
-
1157
- // work/topos-0.1.17/repository/dist/wire/grammar.js
1158
- var [FORBID2, EMPTY2, MEMBER2, PAIR2, STEP2, AT2, EVERY2, ESCAPE2] = ["not:", "none", "|", "=", "/", "@", "*", "\\"];
1159
- var refuse4 = (grammar, why) => {
1160
- throw new Error(`REFUSE\xB7wire ${grammar}: ${why}`);
1161
- };
1162
- function alphabet2(given) {
1163
- if (typeof given !== "string") {
1164
- const written2 = given.members.map((one) => one.split(ESCAPE2).join(ESCAPE2 + ESCAPE2).split(MEMBER2).join(ESCAPE2 + MEMBER2)).join(MEMBER2);
1165
- if (given.polarity === "forbid")
1166
- return FORBID2 + written2;
1167
- return written2.startsWith(FORBID2) || written2 === EMPTY2 ? refuse4("alphabet", "a permitted alphabet neither begins with not: nor is the one word none") : written2 || EMPTY2;
1168
- }
1169
- const forbid = given.startsWith(FORBID2);
1170
- const body = forbid ? given.slice(FORBID2.length) : given;
1171
- const members = !forbid && body === EMPTY2 ? [] : unpipe2(body) ?? refuse4("alphabet", "a backslash escapes only a pipe or itself");
1172
- return { polarity: forbid ? "forbid" : "permit", members: members.filter((one) => one !== "") };
1173
- }
1174
-
1175
- // work/topos-0.1.17/repository/dist/wire/object-record.js
1176
- function coordinateText2(value) {
1177
- return value !== "" && !/[\s\\|]/.test(value) && value.split("/").every((s) => s !== "" && s !== "." && s !== ".." && s !== "*" && s !== "**");
1178
- }
1179
- function restCoordinates2(text) {
1180
- try {
1181
- const read = alphabet2(text);
1182
- if (read.polarity !== "permit" || read.members.some((one) => !coordinateText2(one)))
1183
- return void 0;
1184
- const sorted = [...new Set(read.members)].sort(byBytes2);
1185
- if (alphabet2({ polarity: "permit", members: sorted }) !== text)
1186
- return void 0;
1187
- return sorted;
1188
- } catch {
1189
- return void 0;
1190
- }
1191
- }
1192
-
1193
- // work/bound-0.2.0/order-candidate/dist/wire/object-context.js
1194
- function validateObjectContext(records, context2) {
1195
- const fail = (why) => refuse3(`object context: ${why}`);
1196
- const ids = /* @__PURE__ */ new Map();
1197
- for (const record of records) {
1198
- if (!context2.admit(record))
1199
- return fail(`signature or authority does not admit ${record.fields.id}`);
1200
- const prior = ids.get(record.fields.id);
1201
- if (prior && signedBytes(prior.fields) !== signedBytes(record.fields))
1202
- return fail(`record ID collision ${record.fields.id}`);
1203
- if (!prior)
1204
- ids.set(record.fields.id, record);
1205
- }
1206
- const unique = [...ids.values()];
1207
- const position = new Map(unique.map((record, index) => [record.fields.id, index]));
1208
- const cells = /* @__PURE__ */ new Map();
1209
- for (const record of unique.filter((r) => r.record === "cell")) {
1210
- if (cells.has(record.fields.scope))
1211
- return fail(`cell definition is not unique at ${record.fields.scope}`);
1212
- cells.set(record.fields.scope, record);
1213
- }
1214
- const selected = /* @__PURE__ */ new Map();
1215
- for (const [scope, record] of cells) {
1216
- try {
1217
- const got = context2.resolve(record);
1218
- if (got.digest !== record.fields.topos || got.form.id !== record.fields.form)
1219
- return fail(`selected digest/form does not match ${scope}`);
1220
- got.form.lattice(got.params);
1221
- selected.set(scope, got);
1222
- } catch (error) {
1223
- return fail(`codec/pin/decoder stop at ${scope}: ${String(error)}`);
1224
- }
1225
- }
1226
- const edges = /* @__PURE__ */ new Map();
1227
- for (const [scope, record] of cells) {
1228
- const rest = restCoordinates2(record.fields.restsOn);
1229
- if (rest === void 0)
1230
- return fail(`invalid declared rest at ${scope}`);
1231
- for (const parent of rest) {
1232
- const ancestor = cells.get(parent);
1233
- if (!ancestor)
1234
- return fail(`missing rest target ${parent}`);
1235
- if (Number(ancestor.fields.epoch) > Number(record.fields.epoch))
1236
- return fail(`rest target ${parent} did not exist at cell declaration`);
1237
- if (["topos", "form", "params", "measure"].some((k) => ancestor.fields[k] !== record.fields[k]))
1238
- return fail(`incompatible rest component ${scope}/${parent}`);
1239
- }
1240
- edges.set(scope, rest);
1241
- }
1242
- const colour = /* @__PURE__ */ new Map();
1243
- for (const scope of cells.keys()) {
1244
- if (colour.get(scope) === 2)
1245
- continue;
1246
- const stack = [{ name: scope, exit: false }];
1247
- while (stack.length) {
1248
- const next = stack.pop();
1249
- if (next.exit) {
1250
- colour.set(next.name, 2);
1251
- continue;
1252
- }
1253
- if (colour.get(next.name) === 1)
1254
- return fail(`declared rest cycle reachable from ${scope}`);
1255
- if (colour.get(next.name) === 2)
1256
- continue;
1257
- colour.set(next.name, 1);
1258
- stack.push({ name: next.name, exit: true });
1259
- for (const parent of [...edges.get(next.name)].reverse())
1260
- stack.push({ name: parent, exit: false });
1261
- }
1262
- }
1263
- for (const record of unique.filter((r) => r.record !== "cell")) {
1264
- const f = record.fields;
1265
- const own = cells.get(f.scope);
1266
- if (!own || Number(own.fields.epoch) > Number(f.epoch) || Number(own.fields.epoch) === Number(f.epoch) && position.get(own.fields.id) > position.get(f.id))
1267
- return fail(`cell not declared before ${f.id}`);
1268
- if (f.sign === "-1") {
1269
- const target = ids.get(f.takes);
1270
- if (!target || target.record !== record.record || target.fields.scope !== f.scope || target.fields.sign !== "+1" || target.fields.by !== f.by || Number(target.fields.epoch) >= Number(f.epoch))
1271
- return fail(`unauthorized or incompatible withdrawal target ${f.takes}`);
1272
- } else {
1273
- const codec = selected.get(f.scope);
1274
- try {
1275
- codec.form.parse(codec.params, f.value);
1276
- } catch (error) {
1277
- return fail(`span codec stop at ${f.id}: ${String(error)}`);
1278
- }
1279
- if (record.record === "claim" && !context2.origin(f.origin, f.by, f.scope))
1280
- return fail(`origin is not attested for ${f.id}`);
1281
- if (f.widens !== void 0 && !context2.witness(f.widens, f.by, f.scope))
1282
- return fail(`join witness is not admitted for ${f.id}`);
1283
- }
1284
- }
1285
- for (const scope of cells.keys()) {
1286
- const rest = /* @__PURE__ */ new Set();
1287
- const pending = [...edges.get(scope)];
1288
- while (pending.length) {
1289
- const name = pending.pop();
1290
- if (rest.has(name))
1291
- continue;
1292
- rest.add(name);
1293
- pending.push(...edges.get(name));
1294
- }
1295
- const marks = unique.filter((r) => r.record === "mark" && r.fields.sign === "+1" && r.fields.pole === "ceiling" && (r.fields.scope === scope || rest.has(r.fields.scope) && r.fields.reach === "travels"));
1296
- const epochs = /* @__PURE__ */ new Map();
1297
- for (const m of marks)
1298
- epochs.set(m.fields.epoch, [...epochs.get(m.fields.epoch) ?? [], m]);
1299
- for (const same of epochs.values())
1300
- if (same.length > 1 && same.some((m) => m.fields.widens !== void 0))
1301
- return fail(`ambiguous same-epoch ceiling acts at ${scope}`);
1302
- }
1303
- return fact2(unique);
1304
- }
1305
-
1306
- // work/bound-0.1.9/repository/node_modules/@lapxo/obligations/dist/field/join.js
1307
- function join(L, c, span2, witness, at) {
1308
- if (witness === "")
1309
- throw new UnitError("join-unwitnessed", "obligations: REFUSE\xB7join a widening lands only with a witness or the signatures of whoever rests on the old bound");
1310
- return { ...c, marks: [...c.marks ?? [], mark({ pole: "ceiling", reach: "local", span: L.meet(L.top, span2), widens: witness, ...at === void 0 ? {} : { at } })] };
1311
- }
1312
-
1313
- // work/bound-0.1.9/repository/node_modules/@lapxo/obligations/dist/field/observe.js
1314
- function observe(c, claim, s = claim.takes === void 0 ? 1 : -1) {
1315
- const takes = s === 1 ? void 0 : claim.takes ?? claim.id;
1316
- if (s === 1 && claim.takes !== void 0)
1317
- throw new UnitError("sign-mismatch", "obligations: REFUSE\xB7observe a claim that takes another back is observed at \u22121, never at +1");
1318
- if (s === -1 && takes === void 0)
1319
- throw new UnitError("withdrawal-unnamed", "obligations: REFUSE\xB7observe a withdrawal names the claim it takes back, never a value that looks like it");
1320
- const line = takes === void 0 ? claim : { origin: claim.origin, span: claim.span, sign: -1, takes, ...claim.at === void 0 ? {} : { at: claim.at } };
1321
- return { ...c, epoch: Math.max(c.epoch, claim.at ?? c.epoch), seen: [...c.seen, line] };
1322
- }
1323
-
1324
- // work/bound-0.1.9/repository/node_modules/@lapxo/obligations/dist/field/require.js
1325
- function require2(L, world, name, span2, line = {}) {
1326
- const held = world.get(name) ?? cell(name);
1327
- return new Map([...world, [name, { ...held, marks: [...held.marks ?? [], mark({ pole: "floor", reach: "travels", span: L.meet(L.top, span2), ...line })] }]]);
1328
- }
1329
-
1330
- // work/bound-0.1.9/repository/node_modules/@lapxo/obligations/dist/field/sign.js
1331
- function sign(L, world, name, span2, line = {}) {
1332
- const held = world.get(name) ?? cell(name);
1333
- return new Map([...world, [name, { ...held, marks: [...held.marks ?? [], mark({ pole: "ceiling", reach: "travels", span: L.meet(L.top, span2), ...line })] }]]);
1334
- }
1335
-
1336
- // work/bound-0.2.0/engine-candidate/src/engine/object.ts
1337
- function objectFold(records, context2) {
1338
- let world = /* @__PURE__ */ new Map();
1339
- const definitions = new Map(records.filter((r) => r.record === "cell").map((r) => [r.fields.scope, r]));
1340
- const codecs = new Map([...definitions].map(([name, c]) => [name, context2.resolve(c)]));
1341
- const ids = new Map(records.map((r) => [r.fields.id, r]));
1342
- for (const record of [...records].sort((a, b) => Number(a.fields.epoch) - Number(b.fields.epoch))) {
1343
- const f = record.fields, name = f.scope, at = Number(f.epoch);
1344
- if (record.record === "cell") {
1345
- world = new Map([...world, [name, cell(name, at, [], restCoordinates(f.restsOn))]]);
1346
- continue;
1347
- }
1348
- const codec = codecs.get(name), L = codec.form.lattice(codec.params), held = world.get(name);
1349
- if (record.record === "claim") {
1350
- const target = f.sign === "-1" ? ids.get(f.takes).fields : f;
1351
- const changed = observe(held, { id: f.id, at, origin: target.origin, span: codec.form.parse(codec.params, target.value), ...f.takes ? { takes: f.takes } : {} }, f.sign === "-1" ? -1 : 1);
1352
- const seen = [...changed.seen];
1353
- seen[seen.length - 1] = { ...seen.at(-1), id: f.id };
1354
- world = new Map([...world, [name, { ...changed, seen }]]);
1355
- } else if (f.sign === "-1") {
1356
- const target = ids.get(f.takes).fields;
1357
- world = new Map([...world, [name, { ...held, marks: [...held.marks ?? [], mark({ id: f.id, at, takes: f.takes, pole: target.pole, reach: "local", span: codec.form.parse(codec.params, target.value) })] }]]);
1358
- } else if (f.widens !== void 0) {
1359
- const changed = join(L, held, codec.form.parse(codec.params, f.value), f.widens, at);
1360
- const marks = [...changed.marks ?? []];
1361
- marks[marks.length - 1] = { ...marks.at(-1), id: f.id };
1362
- world = new Map([...world, [name, { ...changed, marks }]]);
1363
- } else {
1364
- const span2 = codec.form.parse(codec.params, f.value);
1365
- world = f.pole === "floor" ? require2(L, world, name, span2, { id: f.id, at }) : sign(L, world, name, span2, { id: f.id, at });
1366
- }
1367
- }
1368
- return [...world].map(([name, c]) => {
1369
- const codec = codecs.get(name), L = codec.form.lattice(codec.params);
1370
- return { cell: name, state: state2(L, c, world), parts: parts(L, c, world), rest: restOf(c, world), ownMarks: live(c.marks ?? []).map((m) => m.id), ownClaims: live(c.seen).map((s) => ({ id: s.id, origin: s.origin })), marks: live(c.marks ?? []), claims: live(c.seen) };
1371
- });
1372
- }
1373
-
1374
- // work/bound-0.1.9/repository/node_modules/@lapxo/topos/dist/forms/form.js
1375
- var paramsOf = (params) => params !== null && typeof params === "object" ? params : {};
1376
- function refuseForm(id, why) {
1377
- throw new Error(`REFUSE\xB7form ${id}: ${why}`);
1378
- }
1379
- function numberAt(id, params, name) {
1380
- const held = paramsOf(params)[name];
1381
- if (typeof held !== "number" || !isFinite(held))
1382
- refuseForm(id, `takes ${name} as a number, and a value it is not given is not invented`);
1383
- return held;
1384
- }
1385
- function wordsAt(id, params, name) {
1386
- const held = paramsOf(params)[name];
1387
- if (!Array.isArray(held) || !held.length || held.some((one) => typeof one !== "string"))
1388
- refuseForm(id, `takes ${name} as a list of words`);
1389
- return held;
1390
- }
1391
- var written = (words) => alphabet({ polarity: "permit", members: [...new Set(words)].sort(byBytes) });
1392
- function bandOf(id, whole, text) {
1393
- if (text === "empty")
1394
- return { lo: whole.hi, hi: whole.lo };
1395
- const read = (value) => ((got) => got.kind === "fact" && got.value.bound.kind === "interval" ? { lo: got.value.bound.lo ?? whole.lo, hi: got.value.bound.hi ?? whole.hi } : void 0)(fromLine(canonical({ form: "interval", value }), null));
1396
- return read(text) ?? read(`${text}..${text}`) ?? refuseForm(id, `\`${text}\` is not a band: lo..hi or one end, each a number or *`);
1397
- }
1398
- var bandText = (value) => ((end) => value.lo > value.hi ? "empty" : `${end(value.lo)}..${end(value.hi)}`)((n) => isFinite(n) ? decimal(n) : "*");
1399
-
1400
- // work/bound-0.1.9/repository/node_modules/@lapxo/topos/dist/forms/alphabet.js
1401
- var tokensOf2 = (params) => ({ tokens: wordsAt("alphabet", params, "tokens") });
1402
- var alphabetOfForm = {
1403
- id: "alphabet",
1404
- lattice: (params) => alphabetForm.lattice(tokensOf2(params)),
1405
- parse(params, text) {
1406
- const { tokens } = tokensOf2(params);
1407
- const read = alphabet(text);
1408
- const stray = read.members.find((one) => !tokens.includes(one));
1409
- if (stray !== void 0)
1410
- refuseForm("alphabet", `\`${stray}\` is not one of its tokens`);
1411
- return WideMask.fromTokens(tokens, new Set(read.polarity === "forbid" ? tokens.filter((one) => !read.members.includes(one)) : read.members));
1412
- },
1413
- emit: (params, value) => written(value.members(tokensOf2(params).tokens)),
1414
- show: (params, value) => alphabetForm.lattice(tokensOf2(params)).show(value),
1415
- points: (params, seed, n) => alphabetForm.points(tokensOf2(params), seed, n)
1416
- };
1417
-
1418
- // work/bound-0.1.9/repository/node_modules/@lapxo/topos/dist/forms/interval.js
1419
- var span = (params) => ({ lo: numberAt("interval", params, "lo"), hi: numberAt("interval", params, "hi") });
1420
- var intervalForm = {
1421
- id: "interval",
1422
- lattice: (params) => continuousForm.lattice(span(params)),
1423
- parse: (params, text) => bandOf("interval", span(params), text),
1424
- emit: (_params, value) => bandText(value),
1425
- show: (params, value) => continuousForm.lattice(span(params)).show(value),
1426
- points: (params, seed, n) => continuousForm.points(span(params), seed, n)
1427
- };
1428
-
1429
- // work/bound-0.2.0/engine-candidate/tools/samples/typed-provider.mjs
1430
- function context({ digest, records, admit }) {
1431
- const granted = (family, id, by, scope) => records.filter((row) => row.scope === `${family}/${id}` && row.value === id && row.by === by && admit(row) && (row.condition ?? "").split("|").includes(scope)).length === 1;
1432
- return {
1433
- resolve(cell2) {
1434
- const form2 = [intervalForm, alphabetOfForm].find((one) => one.id === cell2.fields.form);
1435
- if (!form2) throw Error("REFUSE\xB7codec sample has no selected form");
1436
- return { digest, form: form2, params: JSON.parse(cell2.fields.params) };
1437
- },
1438
- origin: (id, by, scope) => granted("evidence/origin", id, by, scope),
1439
- witness: (id, by, scope) => granted("evidence/witness", id, by, scope)
1440
- };
1441
- }
1442
-
1443
- // work/bound-0.2.0/api-public-places/reader-entry.ts
1444
- function observe2(bytes) {
1445
- const sample = JSON.parse(new TextDecoder().decode(bytes));
1446
- const history = objectHistory(sample.history);
1447
- if (history.kind !== "fact") throw Error("REFUSE\xB7" + history.why);
1448
- const context2 = context({ digest: sample.pin, records: history.value.configuration, admit: () => true });
1449
- const checked = validateObjectContext(history.value.objects, { ...context2, admit: () => true });
1450
- if (checked.kind !== "fact") throw Error("REFUSE\xB7" + checked.why);
1451
- const actual = objectFold(checked.value, context2);
1452
- if (JSON.stringify(actual) !== JSON.stringify(sample.expected)) throw Error("REFUSE\xB7engine projection differs from captured native output");
1453
- return [{ scope: "conformance/engine-object/" + sample.name, role: "writes", measure: "count", bound: { kind: "interval", lo: 0, hi: 0 } }];
1454
- }
1455
- export {
1456
- observe2 as observe
1457
- };
1
+ function Se(e,t="/"){let r=e.split(new RegExp(`[${t.replace(/[.*+?^${}()|[\]\\-]/g,"\\$&")}]`)).filter(n=>n!=="");for(;r[r.length-1]==="*"||r[r.length-1]==="**";)r.pop();return r}var y=class e extends Error{code;detail;constructor(t,r,n={}){super(r),this.name="UnitError",this.code=t,this.detail=Object.freeze({...n}),Object.setPrototypeOf(this,e.prototype)}};function j(e,t=0,r=[],n=[]){return{at:Se(e),epoch:t,seen:r,restsOn:n}}function S(e){if(e.widens!==void 0&&e.reach==="travels")throw new y("widening-travels","obligations: REFUSE\xB7widening-travels a widening stands where it was witnessed and never travels to what rests there",{pole:e.pole});return e.takes===void 0?e:{...e,sign:-1}}function M(e){let t=new Set(e.flatMap(r=>r.takes===void 0?[]:[r.takes]));return e.filter(r=>r.takes===void 0&&(r.id===void 0||!t.has(r.id)))}function B(e,t=new Map){let r=e.at.join("/"),n=[],o=new Set,i=[...e.restsOn],f=new Map;for(let c=0;c<i.length;c+=1){let p=i[c];if(p===r)throw new y("rest-cycle",`obligations: REFUSE\xB7rest ${r} rests on itself: an order of rest with a cycle has no fold to reach`,{at:r});if(o.has(p))continue;o.add(p),n.push(p);let a=t.get(p)?.restsOn??[];f.set(p,a);for(let s of a)i.push(s)}let l=new Map;for(let c of n){if(l.has(c))continue;l.set(c,"visiting");let p=[{name:c,next:0}];for(;p.length;){let a=p[p.length-1],s=f.get(a.name);if(a.next===s.length){l.set(a.name,"done"),p.pop();continue}let m=s[a.next++],d=l.get(m);if(d==="visiting")throw new y("rest-cycle",`obligations: REFUSE\xB7rest ${r} reaches a cycle at ${m}: an order of rest with a cycle has no fold to reach`,{at:r});d===void 0&&(l.set(m,"visiting"),p.push({name:m,next:0}))}}return n}function J(e,t,r=new Map){let n=B(t,r),o=n.flatMap(a=>M(r.get(a)?.marks??[]).filter(s=>s.reach==="travels"&&s.widens===void 0)),i=[...M(t.marks??[]),...o].sort((a,s)=>(a.at??0)-(s.at??0)),f=e.top,l=e.top;for(let a of i)a.pole==="floor"?f=e.meet(f,a.span):l=a.widens===void 0?e.meet(l,a.span):e.join(l,a.span);let c=M(t.seen),p=c.reduce((a,s)=>e.meet(a,s.span),e.top);return{floor:e.meet(f,p),ceiling:e.meet(l,p),origins:c,rest:n,required:f,signed:l}}function ae(e,t,r=new Map){let{floor:n,ceiling:o,origins:i,required:f,signed:l}=J(e,t,r);return e.inhabited(e.meet(f,l))?new Set(i.map(c=>c.origin)).size<2?"REQUIRED":e.inhabited(i.reduce((c,p)=>e.meet(c,p.span),e.top))?e.inhabited(e.meet(n,o))?"FREE":"FORBIDDEN":"CONFLICT":"CONFLICT"}var Fe=32;function Re(e){return e<=0?0:Math.ceil(e/Fe)}var O=class e{words;width;constructor(t,r){this.width=t,this.words=r??new Uint32Array(Re(t))}static fromTokens(t,r){let n=new e(t.length);return t.forEach((o,i)=>{r.has(o)&&n.set(i)}),n}set(t){if(t<0||t>=this.width)throw new y("MALFORMED",`bit ${t} is outside a mask of width ${this.width}`,{bit:t,width:this.width});this.words[t>>5]|=1<<(t&31)}has(t){return t<0||t>=this.width?!1:(this.words[t>>5]&1<<(t&31))!==0}and(t){let r=Math.max(this.width,t.width),n=new e(r),o=Math.min(this.words.length,t.words.length);for(let i=0;i<o;i++)n.words[i]=this.words[i]&t.words[i];return n}or(t){let r=Math.max(this.width,t.width),n=new e(r);for(let o=0;o<n.words.length;o++)n.words[o]=(this.words[o]??0)|(t.words[o]??0);return n}difference(t){let r=Math.max(this.width,t.width),n=new e(r);for(let i=0;i<n.words.length;i++)n.words[i]=(this.words[i]??0)&~(t.words[i]??0);let o=r%32;return o!==0&&n.words.length>0&&(n.words[n.words.length-1]&=(1<<o)-1),n}subsetOf(t){let r=Math.max(this.words.length,t.words.length);for(let n=0;n<r;n++){let o=this.words[n]??0,i=t.words[n]??0;if((o&~i)!==0)return!1}return!0}size(){let t=0;for(let r=0;r<this.width;r++)this.has(r)&&t++;return t}members(t){return t.filter((r,n)=>this.has(n))}static filled(t){let r=new e(t);if(t<=0)return r;r.words.fill(4294967295);let n=t%32;return n!==0&&(r.words[r.words.length-1]=(1<<n)-1),r}};function ft(e,t){return{subject:e,floor:t.floor,ceiling:t.ceiling}}var le=(e,t)=>ft(t,{floor:e.bottom,ceiling:e.top});function Ie(e,t){return e.stateOf(e.rank(t.floor),e.rank(t.ceiling))}function ut(e,t,r,n,o){let i=r.floor,f=r.ceiling;for(let l of t)i=n(i,e.rank(l.floor)),f=o(f,e.rank(l.ceiling));return{subject:t[0].subject,floor:e.levels[i],ceiling:e.levels[f]}}function Ae(e,t){return t.length===0?le(e,""):ut(e,t,{floor:e.bottomIx,ceiling:e.topIx},(r,n)=>e.higher(r,n),(r,n)=>e.lower(r,n))}function je(e,t,r){let[n,o]=[e.rank(t.floor),e.rank(t.ceiling)],[i,f]=[e.rank(r.floor),e.rank(r.ceiling)];return e.leq(i,n)&&e.leq(o,f)}function ce(e){let t=r=>Ie(e,r)!=="CONFLICT";return{top:le(e,""),bottom:{subject:"",floor:e.levels[e.topIx]??"",ceiling:e.levels[e.bottomIx]??""},leq:(r,n)=>je(e,r,n),meet:(r,n)=>Ae(e,[r,n]),join:(r,n)=>t(r)?t(n)?{subject:r.subject||n.subject,floor:e.levels[e.lower(e.rank(r.floor),e.rank(n.floor))]??r.floor,ceiling:e.levels[e.higher(e.rank(r.ceiling),e.rank(n.ceiling))]??r.ceiling}:r:n,show:r=>`[${r.floor}, ${r.ceiling}]`,inhabited:t}}function Ne(e){return{bottom:new O(e.length),top:O.filled(e.length),leq:(t,r)=>t.subsetOf(r),meet:(t,r)=>t.and(r),join:(t,r)=>t.or(r),show:t=>t.members(e).join(","),inhabited:t=>t.size()>0}}function Ce(e,t,r){let n=e.length;for(let u=0;u<n;u++)if(e.indexOf(e[u])!==u)throw new y("DUPLICATE_LEVEL",`the level \`${e[u]}\` is declared twice`,{level:e[u]});let o=new Map(e.map((u,h)=>[u,h])),i=(u,h)=>t[u][h]===h,f=e.every((u,h)=>e.every((b,A)=>t[h][A]===h||t[h][A]===A)),l=!0;for(let u=0;u<n&&l;u++)for(let h=0;h<n&&l;h++)for(let b=0;b<n;b++)if(r[u][t[h][b]]!==t[r[u][h]][r[u][b]]){l=!1;break}let c=[...e.keys()],p=c.find(u=>c.every(h=>i(u,h)))??0,a=c.find(u=>c.every(h=>i(h,u)))??n-1,s=c.filter(u=>u!==p&&c.filter(h=>h!==u&&i(h,u)).reduce((h,b)=>t[h][b],p)!==u),m=c.filter(u=>u!==a&&c.filter(h=>h!==u&&i(u,h)).reduce((h,b)=>r[h][b],a)!==u),d=new Set,g=[];for(let u of[...s,...m])d.has(u)||(d.add(u),g.push(u));return{levels:e,isLadder:f,isSimple:l,bottomIx:p,topIx:a,bottom:e[p],top:e[a],leq:i,higher:(u,h)=>t[u][h],lower:(u,h)=>r[u][h],rank(u){let h=o.get(u);if(h===void 0)throw new y("UNKNOWN_LEVEL",`no level \`${u}\` in this scale`,{level:u,levels:e});return h},stateOf(u,h){return i(u,h)?u!==p?"REQUIRED":h!==a?"FORBIDDEN":"FREE":"CONFLICT"},joins:()=>s.slice(),limits:()=>m.slice(),debits:()=>g.slice(),intervalHeight(u,h){if(!i(u,h))return null;let b=c.filter(x=>i(u,x)&&i(x,h)),A=x=>b.filter($=>$!==x&&i(x,$)&&!b.some(E=>E!==x&&E!==$&&i(x,E)&&i(E,$))),H=new Map([[u,0]]),Q=new Map([[u,0]]),ct=[...b].sort((x,$)=>b.filter(E=>i(E,x)).length-b.filter(E=>i(E,$)).length);for(let x of ct){let $=H.get(x),E=Q.get(x);if(!($===void 0||E===void 0))for(let V of A(x))H.set(V,Math.max(H.get(V)??$+1,$+1)),Q.set(V,Math.min(Q.get(V)??E+1,E+1))}let se=H.get(h);return se!==void 0&&se===Q.get(h)?se:null}}}function fe(e){if(!Array.isArray(e)||e.length===0)throw new y("EMPTY_CHAIN","a chain needs at least one level");let t=e.length,r=n=>[...Array(t)].map((o,i)=>[...Array(t)].map((f,l)=>n(i,l)));return Ce(e,r(Math.max),r(Math.min))}function Te(e,t){if(!Array.isArray(e)||e.length===0)throw new y("EMPTY_CHAIN","an order needs at least one level");let r=e.length,n=(i,f,l)=>{let c=[...Array(r).keys()].filter(a=>l?t[i][a]&&t[f][a]:t[a][i]&&t[a][f]),p=c.filter(a=>c.every(s=>l?t[a][s]:t[s][a]));if(p.length!==1)throw new y("MALFORMED",`\`${e[i]}\` and \`${e[f]}\` have ${p.length} ${l?"lowest common":"highest common"} bounds, so this is not a usable scale`,{levels:[e[i],e[f]]});return p[0]},o=i=>[...Array(r)].map((f,l)=>[...Array(r)].map((c,p)=>n(l,p,i)));return Ce(e,o(!0),o(!1))}function W(e,t){let r=Math.min(e,t),n=Math.max(e,t);return{bottom:{lo:n,hi:r},top:{lo:r,hi:n},leq(o,i){return o.lo>o.hi?!0:i.lo>i.hi?!1:i.lo<=o.lo&&o.hi<=i.hi},meet(o,i){return{lo:Math.max(o.lo,i.lo),hi:Math.min(o.hi,i.hi)}},join(o,i){return o.lo>o.hi?i:i.lo>i.hi?o:{lo:Math.min(o.lo,i.lo),hi:Math.max(o.hi,i.hi)}},show(o){return o.lo>o.hi?"empty":`${o.lo}..${o.hi}`},inhabited(o){return o.lo<=o.hi}}}function Y(e){let t={lattice:e.lattice,parse:e.parse,emit:e.emit,count:e.count,show:e.show,points:e.points},r=Object.entries(t).find(([,n])=>typeof n!="function");if(r)throw new Error(`form \`${e.id}\` declared no ${r[0]}`);return e}var k=e=>e!==null&&typeof e=="object"?e:{};function F(e){return Array.isArray(e)?e.map(String):[]}var ue=e=>{let t=e>>>0;return()=>{t=t+1831565813>>>0;let r=Math.imul(t^t>>>15,t|1);return r^=r+Math.imul(r^r>>>7,r|61),((r^r>>>14)>>>0)/4294967296}},qe=(e,t)=>t[Math.floor(e()*t.length)];function dt(e,t){if(e.length===0)return{kind:"refused",why:"a ladder with no levels cannot be counted"};let r=fe(e),n=r.rank(t.floor),o=r.rank(t.ceiling);return r.leq(n,o)?{kind:"finite",n:e.filter((f,l)=>r.leq(n,l)&&r.leq(l,o)).length}:{kind:"finite",n:0}}var De={parse(e,t){let r=this.lattice(e),n=k(t);return{subject:String(n.subject??""),floor:String(n.floor??r.top.floor),ceiling:String(n.ceiling??r.top.ceiling)}},emit(e,t){return{subject:t.subject,floor:t.floor,ceiling:t.ceiling}},count(e,t){return dt(F(k(t).levels),e)},points(e,t,r){let n=this.lattice(e),o=F(k(e).levels),i=ue(t),f=(l,c)=>({subject:"",floor:l,ceiling:c});return Array.from({length:r},()=>{let[l,c]=[qe(i,o),qe(i,o)];return[f(l,c),f(c,l)].find(p=>n.inhabited(p))??f(l,l)})}},Ue=Y({id:"ladder",lattice(e){let t=F(k(e).levels);if(t.length===0)throw new Error("ladder needs levels");return ce(fe(t))},...De,show(e){return e.floor===e.ceiling?e.floor:`${e.floor}..${e.ceiling}`}}),C=Y({id:"alphabet",lattice(e){return Ne(F(k(e).tokens))},parse(e,t){let r=F(k(e).tokens),n=k(t),o=n.want!==void 0?F(n.want):r;return O.fromTokens(r,new Set(o))},emit(e,t){return{want:t.members(F(k(e).tokens))}},count(e){return{kind:"finite",n:e.size()}},show(e){return`${e.size()}`},points(e,t,r){let n=F(k(e).tokens),o=ue(t);return Array.from({length:r},()=>O.fromTokens(n,new Set(n.filter(()=>o()<.5))))}}),T=Y({id:"continuous",lattice(e){let t=k(e);return W(Number(t.lo??0),Number(t.hi??1))},parse(e,t){let r=this.lattice(e),n=k(t);return{lo:n.lo===void 0?r.top.lo:Number(n.lo),hi:n.hi===void 0?r.top.hi:Number(n.hi)}},emit(e,t){return{lo:t.lo,hi:t.hi}},count(){return{kind:"refused",why:"a continuous band has no count; prefer not to exist over inventing one"}},show(e){return e.lo>e.hi?"empty":`${e.lo}..${e.hi}`},points(e,t,r){let n=k(e),o=Number(n.lo??0),i=Number(n.hi??1),f=ue(t),l=()=>o+Math.round(f()*(i-o));return Array.from({length:r},()=>({lo:l(),hi:l()}))}}),Be=Y({id:"lattice",lattice(e){let t=k(e),r=F(t.levels),n=t.leq;if(r.length&&n)return ce(Te(r,n));throw new Error("lattice needs levels+leq")},...De,show(e){return`${e.floor}..${e.ceiling}`}}),We=[Ue,C,T,Be],pt=[...We];function de(e,t,r,n,o){if(n==="")throw new y("join-unwitnessed","obligations: REFUSE\xB7join a widening lands only with a witness or the signatures of whoever rests on the old bound");return{...t,marks:[...t.marks??[],S({pole:"ceiling",reach:"local",span:e.meet(e.top,r),widens:n,...o===void 0?{}:{at:o}})]}}function pe(e,t,r=t.takes===void 0?1:-1){let n=r===1?void 0:t.takes??t.id;if(r===1&&t.takes!==void 0)throw new y("sign-mismatch","obligations: REFUSE\xB7observe a claim that takes another back is observed at \u22121, never at +1");if(r===-1&&n===void 0)throw new y("withdrawal-unnamed","obligations: REFUSE\xB7observe a withdrawal names the claim it takes back, never a value that looks like it");let o=n===void 0?t:{origin:t.origin,span:t.span,sign:-1,takes:n,...t.at===void 0?{}:{at:t.at}};return{...e,epoch:Math.max(e.epoch,t.at??e.epoch),seen:[...e.seen,o]}}function me(e,t,r,n,o={}){let i=t.get(r)??j(r);return new Map([...t,[r,{...i,marks:[...i.marks??[],S({pole:"floor",reach:"travels",span:e.meet(e.top,n),...o})]}]])}function he(e,t,r,n,o={}){let i=t.get(r)??j(r);return new Map([...t,[r,{...i,marks:[...i.marks??[],S({pole:"ceiling",reach:"travels",span:e.meet(e.top,n),...o})]}]])}var v=e=>({kind:"fact",value:e}),I=e=>({kind:"abstain",why:e}),w=(e,t)=>({kind:"refuse",why:e,...t===void 0?{}:{named:t}});function q(e){let t=[],r="";for(let n=0;n<e.length;n++){let o=e[n];if(o==="\\"){let i=e[n+1];if(i!=="|"&&i!=="\\")return null;r+=i,n+=1}else o==="|"?(t.push(r),r=""):r+=o}return t.push(r),t}var G="*",Le=e=>{if(!/^-?\d+(\.\d+)?$/.test(e))return null;let t=Number(e);return isFinite(t)?t:null};function _e(e){if(!isFinite(e))throw new Error(`REFUSE\xB7wire decimal: \`${e}\` is not a finite number`);let t=/^(-?)(\d)(?:\.(\d+))?e([+-])(\d+)$/.exec(String(e));if(t===null)return String(e);let[,r="",n="",o="",i="",f="0"]=t;return i==="+"?`${r}${n}${o}${"0".repeat(Number(f)-o.length)}`:`${r}0.${"0".repeat(Number(f)-1)}${n}${o}`}var Pe={interval:e=>{let t=e.indexOf("..");if(t<0)return null;let r=e.slice(0,t),n=e.slice(t+2),o=r===G?null:Le(r),i=n===G?null:Le(n);return r!==G&&o===null||n!==G&&i===null?null:{kind:"interval",lo:o,hi:i}},alphabet:e=>{let t=q(e);return t===null?null:{kind:"enumerated",values:t}},ladder:e=>{let t=q(e);return t===null||t.length!==2?null:{kind:"band",floor:t[0]??"",ceiling:t[1]??""}}};function X(e,t,r){let n=Array.isArray(r)?r.find(o=>o.form===e):void 0;return n?n.parse(t):Pe[e]?.(t)??null}var ze=Object.keys(Pe),Ke=["within","copies","derives"];var ge="bound-lock/1",Qe=/[ ="\n\\]/;function mt(e){return Qe.test(e)?`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n")}"`:e}function ht(e){if(!e.startsWith('"'))return Qe.test(e)?null:e;if(e.length<2||!e.endsWith('"'))return null;let t=e.slice(1,-1),r="";for(let n=0;n<t.length;n++){let o=t[n];if(o!=="\\"){if(o==='"')return null;r+=o;continue}let i=t[n+1];if(i==='"')r+='"';else if(i==="\\")r+="\\";else if(i==="n")r+=`
2
+ `;else return null;n+=1}return r}var He=new TextEncoder;function L(e,t){let r=He.encode(e),n=He.encode(t);for(let o=0;o<r.length&&o<n.length;o++)if(r[o]!==n[o])return r[o]-n[o];return r.length-n.length}var Ve=e=>e.form==="interval"&&e.value!==void 0&&e.value!=="withdraw"&&X("interval",e.value)===null;function we(e,t="1"){if(Ve(e))throw new Error(`REFUSE\xB7wire canonical: \`${e.value}\` is no interval the wire writes: two ends, each decimal or *`);let n=Object.keys(e).sort(L).map(o=>`${o}=${mt(e[o])}`);return[`${ge.split("/")[0]}/${t}`,...n].join(" ")}function ye(e,t="1"){let{sig:r,...n}=e;return we(n,t)}var gt="-";function D(e,t={}){if(e.includes(`
3
+ `))return w("a line is one line \u2014 a newline in a value must be escaped as `\\n`");let r=e.indexOf(" "),n=r===-1?e:e.slice(0,r),[o,i]=n.split("/");if(o!==ge.split("/")[0]||!i)return w(`no \`bound-lock/<v>\` envelope \u2014 found \`${n.slice(0,24)}\``);if(i!==ge.split("/")[1])return I(`\`bound-lock/${i}\` is a version this reader does not know`);let f={},l=new Set;for(let c of wt(r===-1?"":e.slice(r+1))){if(c===null)return w("a quoted value is not closed");let p=c.indexOf("=");if(p<=0)return w(`\`${c.slice(0,24)}\` is not \`key=value\``);let a=c.slice(0,p);if(l.has(a))return w(`\`${a}\` appears twice \u2014 one line, one value per key`);l.add(a);let s=ht(c.slice(p+1));if(s===null)return w(`\`${a}\` has an escaping this format does not define`);s!==gt&&(f[a]=s)}return Ve(f)?w(`\`${f.value}\` is no interval the wire reads: two ends, each decimal or *`):v({version:i,fields:f,...t.preserveKeys?{keys:[...l]}:{}})}function*wt(e){let t=0;for(;t<e.length;){for(;e[t]===" ";)t+=1;if(t>=e.length)return;let r=t,n=!1;for(;r<e.length&&(n||e[r]!==" ");)e[r]==="\\"&&n?r+=1:e[r]==='"'&&(n=!n),r+=1;if(n){yield null;return}yield e.slice(t,r),t=r}}var[Z,be,xe,cr,fr,ur,dr,ee]=["not:","none","|","=","/","@","*","\\"],Je=(e,t)=>{throw new Error(`REFUSE\xB7wire ${e}: ${t}`)};function N(e){if(typeof e!="string"){let o=e.members.map(i=>i.split(ee).join(ee+ee).split(xe).join(ee+xe)).join(xe);return e.polarity==="forbid"?Z+o:o.startsWith(Z)||o===be?Je("alphabet","a permitted alphabet neither begins with not: nor is the one word none"):o||be}let t=e.startsWith(Z),r=t?e.slice(Z.length):e,n=!t&&r===be?[]:q(r)??Je("alphabet","a backslash escapes only a pipe or itself");return{polarity:t?"forbid":"permit",members:n.filter(o=>o!=="")}}function Ye(e){return e!==""&&!/[\s\\|]/.test(e)&&e.split("/").every(t=>t!==""&&t!=="."&&t!==".."&&t!=="*"&&t!=="**")}function U(e){try{let t=N(e);if(t.polarity!=="permit"||t.members.some(n=>!Ye(n)))return;let r=[...new Set(t.members)].sort(L);return N({polarity:"permit",members:r})!==e?void 0:r}catch{return}}var yt=["type","scope","id","epoch","by","sig"];function Ge(e,t,r,n,o){let i=(a,s)=>w(a,s);if(t.includes("at"))return i("object records carry no at: order is epoch and a local join witness is widens","at");let f=e.type;if(!r.types.has(f??"")||!["cell","claim","mark"].includes(f??""))return i("an object record names a declared type: cell, claim or mark","type");if(!/^(0|[1-9][0-9]*)$/.test(e.epoch??"")||!Number.isSafeInteger(Number(e.epoch)))return i("an object record carries an exactly supported logical epoch","epoch");if(Number(e.epoch)<r.activation)return i(`an object epoch precedes typed-wire activation ${r.activation}`,"epoch");let l;if(f==="cell")l="cell";else if(e.sign==="-1")l=`${f}/negative`;else{if(e.sign!=="+1")return i("a claim or mark names sign=+1 or sign=-1","sign");if(f==="claim")l="claim/positive";else if(e.pole==="floor"&&e.reach==="travels"&&e.widens===void 0)l="mark/floor-travelling";else if(e.pole==="ceiling"&&e.reach==="travels"&&e.widens===void 0)l="mark/travelling";else if(e.pole==="ceiling"&&e.reach==="local")l="mark/local";else return i("a positive mark is ceiling/travels, ceiling/local with widens, or floor/travels without widens","pole")}let c=r.required.get(l),p=r.allowed.get(l);if(!c||!p||r.common.size===0||r.configuration.size===0||[...r.common].some(a=>!c.has(a)||!p.has(a))||[...c].some(a=>!p.has(a)))return i(`typed wire has no complete required/allowed contract for ${l}`,"type");for(let a of yt)if(e[a]===void 0||e[a]==="")return i(`an object record has no ${a}`,a);for(let a of t)if(!n.has(a)||!p.has(a))return i(`\`${a}=\` is not allowed on ${l}`,a);for(let a of c)if(!p.has(a)||e[a]===void 0||e[a]==="")return i(`a ${l} record has no declared required \`${a}\``,a);if(!Ye(e.scope))return i("scope is a canonical cell coordinate","scope");if(f==="cell"){if(!o.has(e.form))return i("the cell names no admitted form","form");if(U(e.restsOn)===void 0)return i("cell restsOn is none or a canonical alphabet of coordinates","restsOn")}return v({record:f,fields:{...e}})}function Xe(e){let t=e.lastIndexOf(":");return t<=0||t===e.length-1?null:{algorithm:e.slice(0,t),raw:e.slice(t+1)}}var bt=new Set(["sig","expires","repo","by","epoch"]),_="withdraw",P="wire/",ke="audit/wire/";function te(e){if(e.startsWith(ke))return e.slice(ke.length);if(e.startsWith(P))return e.slice(P.length)}function R(e){let t=e.epoch??"";return/^\d+$/.test(t)?Number(t):0}function Ze(e,t){return Object.keys(e).filter(r=>r!=="value"&&!bt.has(r)).every(r=>t[r]===e[r])}function tt(e,t){let r=e.filter(s=>te(s.scope??"")!==void 0&&R(s)<=t),n=r.filter(s=>s.value===_),o=new Map;for(let s of r){if(s.value===_||n.some(u=>Ze(u,s)))continue;let m=(te(s.scope??"")??"")+"\0"+(s.by??""),d=o.get(m)??[],g=d.length?R(d[0]):-1;R(s)>g?o.set(m,[s]):R(s)===g&&o.set(m,[...d,s])}let i=[...o.values()].flatMap(s=>s.some(m=>(m.scope??"").startsWith(P))?s.filter(m=>(m.scope??"").startsWith(P)):s),f=new Map;for(let s of i){let m=te(s.scope??"")??"",d=f.get(m);if(d!==void 0&&d!==s.value)throw Error(`REFUSE\xB7wire wire/${m} has conflicting live declarations`);f.set(m,s.value??"")}let l=new Map;for(let s of r){let m=te(s.scope??"")??"";if(s.value===_||n.some(u=>Ze(u,s)))continue;let d=l.get(m);(d===void 0||R(s)>R(d)||R(s)===R(d)&&(s.scope??"").startsWith(P)&&(d.scope??"").startsWith(ke))&&l.set(m,s)}if(!l.size)return null;let c=s=>new Set((l.get(s)?.value??"").split("|").filter(Boolean)),p=new Map([...l].filter(([s])=>s.startsWith("form/")).map(([s,m])=>[s.slice(5),m.value??""])),a=new Map([...l.keys()].filter(s=>!s.includes("/")).map(s=>[s,c(s)]));return{epoch:t,...l.has("object/types")?{object:{activation:R(l.get("object/types")),types:c("object/types"),common:c("object/common"),reserved:c("object/reserved"),configuration:c("object/allowed/config"),required:new Map([...l.keys()].filter(s=>s.startsWith("object/required/")).map(s=>[s.slice(16),c(s)])),allowed:new Map([...l.keys()].filter(s=>s.startsWith("object/allowed/")).map(s=>[s.slice(15),c(s)]))}}:{},fields:c("fields"),required:c("required"),roles:c("roles"),forms:c("forms"),classes:c("at-classes"),digests:new Set([...c("digest-algorithms")].map(s=>s.split(":")[0])),signatures:c("signature-algorithms"),formOf:p,lists:a}}function ne(e,t){let r=e.indexOf(":");return r>0&&t.digests.has(e.slice(0,r))&&/^[0-9a-f]+$/i.test(e.slice(r+1))}function xt(e){if(e.startsWith("/")||/[\s\\]/.test(e))return!1;let t=e.split("/").filter(r=>r!=="");return t.length>0&&t.every((r,n)=>r!=="."&&r!==".."&&(!r.includes("*")||n===t.length-1))}var et={region:e=>e.split("|").filter(Boolean).every(xt),class:(e,t)=>{let r=e.indexOf(":");if(r<=0||!t.classes.has(e.slice(0,r)))return!1;let n=e.slice(r+1);return!/^[a-z0-9-]+:[0-9a-f]{16,}$/i.test(n)||ne(n,t)},signature:(e,t)=>{let r=Xe(e);if(r===null||!t.signatures.has(r.algorithm))return!1;let n=r.algorithm.slice(r.algorithm.lastIndexOf(":")+1);return ne(r.algorithm,t)||r.algorithm.includes(":")&&(t.lists.get("era")?.has(n)??!1)},count:e=>/^\d+$/.test(e)};function re(e,t){return w(t,e)}function oe(e,t,r){let n=D(e,{preserveKeys:!0});if(n.kind!=="fact")return n.kind==="abstain"?I(n.why):w(n.why,n.named);let o=n.value.fields,i=n.value.keys;if(i.includes("type")){if(!t?.object)return w("typed object grammar is not admitted at this epoch","type");if(!t.object.configuration.size||!t.object.reserved.size||[...t.object.reserved].some(g=>t.object.configuration.has(g)))return w("typed wire has no closed configuration/object field contract","type");let d=Ge(o,i,t.object,t.fields,t.forms);return d.kind!=="fact"?d:et.signature(o.sig,t)?d.value.record==="cell"&&!ne(o.topos,t)?w("cell topos is not an admitted digest","topos"):d.value.record==="cell"&&(o.restsOn??"").split("|").some(g=>ne(g,t))?w("cell restsOn names coordinates, not byte digests","restsOn"):d:w("object signature grammar is not admitted","sig")}if(t){if(t.object){if(!t.object.configuration.size||!t.object.reserved.size||[...t.object.reserved].some(g=>t.object.configuration.has(g)))return w("typed wire has no closed configuration/object field contract","type");let d=i.find(g=>t.object.reserved.has(g)||!t.object.configuration.has(g));if(d)return w(`\`${d}=\` is an object-only field: untyped configuration cannot carry it`,d)}for(let d of Object.keys(o))if(!t.fields.has(d))return re(d,`\`${d}=\` is not a field of the wire at epoch ${t.epoch}`);for(let d of t.required)if(o[d]===void 0)return re(d,`a claim with no \`${d}\``);for(let[d,g]of t.formOf){let u=o[d];if(u===void 0)continue;let h=t.lists.get(g),b=et[g]??(h?A=>h.has(A):void 0);if(!b)return I(`\`${d}\` takes the form ${g}, which this reader does not know`);if(!b(u,t))return re(d,`\`${d}=${u}\` is not a ${g} of the wire at epoch ${t.epoch}`)}if(o.role!==void 0&&!t.roles.has(o.role))return I(`\`role=${o.role}\` is a role this wire does not name`);if(!t.forms.has(o.form??""))return I(`\`form=${o.form}\` is a form this wire does not name`)}let f=Array.isArray(r)?r:void 0,l=o.value===_?{kind:"enumerated",values:[_]}:X(o.form??"",o.value??"",f);if(l===null)return ze.includes(o.form??"")||(f?.some(g=>g.form===o.form)??!1)?re("value",`\`${o.value}\` is not a ${o.form}`):I(`\`form=${o.form}\` is a form this reader does not know`);let c=o.role==="writes"?"writes":o.role==="demands"?"demands":"reads",p={};for(let[d,g]of Object.entries(o))["scope","measure","form","value","by","at","role","unit","multiplicity","epoch","ref","to","ref_by"].includes(d)||(p[d]=g);let a=o.ref,s=o.to===void 0?null:q(o.to),m=a&&s&&Ke.includes(a)?{rel:a,to:s,by:o.ref_by==="declared"?"declared":"inferred"}:null;return v({scope:o.scope??"",measure:o.measure??"",bound:l,role:c,by:o.by??"",at:o.at??"",...o.unit!==void 0?{unit:o.unit}:{},...o.multiplicity==="one"||o.multiplicity==="many"||o.multiplicity==="unknown"?{multiplicity:o.multiplicity}:{},...o.epoch!==void 0?{epoch:o.epoch}:{},...m?{reference:m}:{},extra:p})}var Ir=W(-1/0,1/0),Ar=W(1,1/0);function ve(e,t){let r=a=>w(`object context: ${a}`),n=new Map;for(let a of e){if(!t.admit(a))return r(`signature or authority does not admit ${a.fields.id}`);let s=n.get(a.fields.id);if(s&&ye(s.fields)!==ye(a.fields))return r(`record ID collision ${a.fields.id}`);s||n.set(a.fields.id,a)}let o=[...n.values()],i=new Map(o.map((a,s)=>[a.fields.id,s])),f=new Map;for(let a of o.filter(s=>s.record==="cell")){if(f.has(a.fields.scope))return r(`cell definition is not unique at ${a.fields.scope}`);f.set(a.fields.scope,a)}let l=new Map;for(let[a,s]of f)try{let m=t.resolve(s);if(m.digest!==s.fields.topos||m.form.id!==s.fields.form)return r(`selected digest/form does not match ${a}`);m.form.lattice(m.params),l.set(a,m)}catch(m){return r(`codec/pin/decoder stop at ${a}: ${String(m)}`)}let c=new Map;for(let[a,s]of f){let m=U(s.fields.restsOn);if(m===void 0)return r(`invalid declared rest at ${a}`);for(let d of m){let g=f.get(d);if(!g)return r(`missing rest target ${d}`);if(Number(g.fields.epoch)>Number(s.fields.epoch))return r(`rest target ${d} did not exist at cell declaration`);if(["topos","form","params","measure"].some(u=>g.fields[u]!==s.fields[u]))return r(`incompatible rest component ${a}/${d}`)}c.set(a,m)}let p=new Map;for(let a of f.keys()){if(p.get(a)===2)continue;let s=[{name:a,exit:!1}];for(;s.length;){let m=s.pop();if(m.exit){p.set(m.name,2);continue}if(p.get(m.name)===1)return r(`declared rest cycle reachable from ${a}`);if(p.get(m.name)!==2){p.set(m.name,1),s.push({name:m.name,exit:!0});for(let d of[...c.get(m.name)].reverse())s.push({name:d,exit:!1})}}}for(let a of o.filter(s=>s.record!=="cell")){let s=a.fields,m=f.get(s.scope);if(!m||Number(m.fields.epoch)>Number(s.epoch)||Number(m.fields.epoch)===Number(s.epoch)&&i.get(m.fields.id)>i.get(s.id))return r(`cell not declared before ${s.id}`);if(s.sign==="-1"){let d=n.get(s.takes);if(!d||d.record!==a.record||d.fields.scope!==s.scope||d.fields.sign!=="+1"||d.fields.by!==s.by||Number(d.fields.epoch)>=Number(s.epoch))return r(`unauthorized or incompatible withdrawal target ${s.takes}`)}else{let d=l.get(s.scope);try{d.form.parse(d.params,s.value)}catch(g){return r(`span codec stop at ${s.id}: ${String(g)}`)}if(a.record==="claim"&&!t.origin(s.origin,s.by,s.scope))return r(`origin is not attested for ${s.id}`);if(s.widens!==void 0&&!t.witness(s.widens,s.by,s.scope))return r(`join witness is not admitted for ${s.id}`)}}for(let a of f.keys()){let s=new Set,m=[...c.get(a)];for(;m.length;){let u=m.pop();s.has(u)||(s.add(u),m.push(...c.get(u)))}let d=o.filter(u=>u.record==="mark"&&u.fields.sign==="+1"&&u.fields.pole==="ceiling"&&(u.fields.scope===a||s.has(u.fields.scope)&&u.fields.reach==="travels")),g=new Map;for(let u of d)g.set(u.fields.epoch,[...g.get(u.fields.epoch)??[],u]);for(let u of g.values())if(u.length>1&&u.some(h=>h.fields.widens!==void 0))return r(`ambiguous same-epoch ceiling acts at ${a}`)}return v(o)}function rt(e){let t=D(e,{preserveKeys:!0});if(t.kind!=="fact")return t;if(!t.value.keys.includes("type"))return v("config");let r=t.value.fields.type;return r==="cell"||r==="claim"||r==="mark"?v(r):w("an explicit type names cell, claim or mark","type")}function Ee(e){let t=[];for(let o of e){let i=D(o);if(i.kind!=="fact")return i;t.push(i.value.fields)}let r=[],n=[];for(let o=0;o<e.length;o++){let i=rt(e[o]);if(i.kind!=="fact")return i;if(i.value==="config"){n.push(t[o]);continue}let f=oe(e[o],tt(t,Number(t[o].epoch)));if(f.kind!=="fact")return f;if(!("record"in f.value))throw Error("typed history returned configuration");r.push(f.value)}return v({objects:r,configuration:n})}function nt(e,t){let r=new Map,n=new Map(e.filter(f=>f.record==="cell").map(f=>[f.fields.scope,f])),o=new Map([...n].map(([f,l])=>[f,t.resolve(l)])),i=new Map(e.map(f=>[f.fields.id,f]));for(let f of[...e].sort((l,c)=>Number(l.fields.epoch)-Number(c.fields.epoch))){let l=f.fields,c=l.scope,p=Number(l.epoch);if(f.record==="cell"){r=new Map([...r,[c,j(c,p,[],U(l.restsOn))]]);continue}let a=o.get(c),s=a.form.lattice(a.params),m=r.get(c);if(f.record==="claim"){let d=l.sign==="-1"?i.get(l.takes).fields:l,g=pe(m,{id:l.id,at:p,origin:d.origin,span:a.form.parse(a.params,d.value),...l.takes?{takes:l.takes}:{}},l.sign==="-1"?-1:1),u=[...g.seen];u[u.length-1]={...u.at(-1),id:l.id},r=new Map([...r,[c,{...g,seen:u}]])}else if(l.sign==="-1"){let d=i.get(l.takes).fields;r=new Map([...r,[c,{...m,marks:[...m.marks??[],S({id:l.id,at:p,takes:l.takes,pole:d.pole,reach:"local",span:a.form.parse(a.params,d.value)})]}]])}else if(l.widens!==void 0){let d=de(s,m,a.form.parse(a.params,l.value),l.widens,p),g=[...d.marks??[]];g[g.length-1]={...g.at(-1),id:l.id},r=new Map([...r,[c,{...d,marks:g}]])}else{let d=a.form.parse(a.params,l.value);r=l.pole==="floor"?me(s,r,c,d,{id:l.id,at:p}):he(s,r,c,d,{id:l.id,at:p})}}return[...r].map(([f,l])=>{let c=o.get(f),p=c.form.lattice(c.params);return{cell:f,state:ae(p,l,r),parts:J(p,l,r),rest:B(l,r),ownMarks:M(l.marks??[]).map(a=>a.id),ownClaims:M(l.seen).map(a=>({id:a.id,origin:a.origin})),marks:M(l.marks??[]),claims:M(l.seen)}})}var ot=e=>e!==null&&typeof e=="object"?e:{};function z(e,t){throw new Error(`REFUSE\xB7form ${e}: ${t}`)}function Oe(e,t,r){let n=ot(t)[r];return(typeof n!="number"||!isFinite(n))&&z(e,`takes ${r} as a number, and a value it is not given is not invented`),n}function it(e,t,r){let n=ot(t)[r];return(!Array.isArray(n)||!n.length||n.some(o=>typeof o!="string"))&&z(e,`takes ${r} as a list of words`),n}var st=e=>N({polarity:"permit",members:[...new Set(e)].sort(L)});function at(e,t,r){if(r==="empty")return{lo:t.hi,hi:t.lo};let n=o=>(i=>i.kind==="fact"&&i.value.bound.kind==="interval"?{lo:i.value.bound.lo??t.lo,hi:i.value.bound.hi??t.hi}:void 0)(oe(we({form:"interval",value:o}),null));return n(r)??n(`${r}..${r}`)??z(e,`\`${r}\` is not a band: lo..hi or one end, each a number or *`)}var lt=e=>(t=>e.lo>e.hi?"empty":`${t(e.lo)}..${t(e.hi)}`)(t=>isFinite(t)?_e(t):"*");var K=e=>({tokens:it("alphabet",e,"tokens")}),$e={id:"alphabet",lattice:e=>C.lattice(K(e)),parse(e,t){let{tokens:r}=K(e),n=N(t),o=n.members.find(i=>!r.includes(i));return o!==void 0&&z("alphabet",`\`${o}\` is not one of its tokens`),O.fromTokens(r,new Set(n.polarity==="forbid"?r.filter(i=>!n.members.includes(i)):n.members))},emit:(e,t)=>st(t.members(K(e).tokens)),show:(e,t)=>C.lattice(K(e)).show(t),points:(e,t,r)=>C.points(K(e),t,r)};var ie=e=>({lo:Oe("interval",e,"lo"),hi:Oe("interval",e,"hi")}),Me={id:"interval",lattice:e=>T.lattice(ie(e)),parse:(e,t)=>at("interval",ie(e),t),emit:(e,t)=>lt(t),show:(e,t)=>T.lattice(ie(e)).show(t),points:(e,t,r)=>T.points(ie(e),t,r)};function wn(e){let t=JSON.parse(new TextDecoder().decode(e)),r=Ee(t.history);if(r.kind!=="fact")throw Error("REFUSE\xB7"+r.why);let n=(l,c,p,a)=>r.value.configuration.filter(s=>s.scope===`${l}/${c}`&&s.value===c&&s.by===p&&(s.condition??"").split("|").includes(a)).length===1,o={resolve(l){let c=[Me,$e].find(p=>p.id===l.fields.form);if(!c)throw Error("REFUSE\xB7codec sample has no selected form");return{digest:t.pin,form:c,params:JSON.parse(l.fields.params)}},origin:(l,c,p)=>n("evidence/origin",l,c,p),witness:(l,c,p)=>n("evidence/witness",l,c,p)},i=ve(r.value.objects,{...o,admit:()=>!0});if(i.kind!=="fact")throw Error("REFUSE\xB7"+i.why);let f=nt(i.value,o);if(JSON.stringify(f)!==JSON.stringify(t.expected))throw Error("REFUSE\xB7engine projection differs from captured native output");return[{scope:"conformance/engine-object/"+t.name,role:"writes",measure:"count",bound:{kind:"interval",lo:0,hi:0}}]}export{wn as observe};