@cotal-ai/lang 0.24.0 → 0.25.0

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 (75) hide show
  1. package/README.md +11 -0
  2. package/dist/engine/bridge.d.ts +71 -0
  3. package/dist/engine/bridge.d.ts.map +1 -0
  4. package/dist/engine/bridge.js +277 -0
  5. package/dist/engine/bridge.js.map +1 -0
  6. package/dist/engine/ctx.d.ts +140 -0
  7. package/dist/engine/ctx.d.ts.map +1 -0
  8. package/dist/engine/ctx.js +834 -0
  9. package/dist/engine/ctx.js.map +1 -0
  10. package/dist/engine/frame.d.ts +69 -0
  11. package/dist/engine/frame.d.ts.map +1 -0
  12. package/dist/engine/frame.js +105 -0
  13. package/dist/engine/frame.js.map +1 -0
  14. package/dist/engine/host.d.ts +77 -0
  15. package/dist/engine/host.d.ts.map +1 -0
  16. package/dist/engine/host.js +134 -0
  17. package/dist/engine/host.js.map +1 -0
  18. package/dist/engine/worker-entry.d.ts +26 -0
  19. package/dist/engine/worker-entry.d.ts.map +1 -0
  20. package/dist/engine/worker-entry.js +175 -0
  21. package/dist/engine/worker-entry.js.map +1 -0
  22. package/dist/engine/worker.d.ts +156 -0
  23. package/dist/engine/worker.d.ts.map +1 -0
  24. package/dist/engine/worker.js +123 -0
  25. package/dist/engine/worker.js.map +1 -0
  26. package/dist/errors.d.ts +44 -0
  27. package/dist/errors.d.ts.map +1 -1
  28. package/dist/errors.js +97 -0
  29. package/dist/errors.js.map +1 -1
  30. package/dist/index.d.ts +10 -1
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +10 -1
  33. package/dist/index.js.map +1 -1
  34. package/dist/interpret.d.ts +7 -38
  35. package/dist/interpret.d.ts.map +1 -1
  36. package/dist/interpret.js +45 -1003
  37. package/dist/interpret.js.map +1 -1
  38. package/dist/journal.d.ts.map +1 -1
  39. package/dist/journal.js +75 -1
  40. package/dist/journal.js.map +1 -1
  41. package/dist/library.d.ts.map +1 -1
  42. package/dist/library.js +13 -1
  43. package/dist/library.js.map +1 -1
  44. package/dist/perform.d.ts +138 -0
  45. package/dist/perform.d.ts.map +1 -0
  46. package/dist/perform.js +1052 -0
  47. package/dist/perform.js.map +1 -0
  48. package/dist/pins.d.ts +28 -8
  49. package/dist/pins.d.ts.map +1 -1
  50. package/dist/pins.js +31 -11
  51. package/dist/pins.js.map +1 -1
  52. package/dist/sim.d.ts +15 -1
  53. package/dist/sim.d.ts.map +1 -1
  54. package/dist/sim.js.map +1 -1
  55. package/dist/transform/emit.d.ts +23 -0
  56. package/dist/transform/emit.d.ts.map +1 -0
  57. package/dist/transform/emit.js +934 -0
  58. package/dist/transform/emit.js.map +1 -0
  59. package/dist/transform/index.d.ts +34 -0
  60. package/dist/transform/index.d.ts.map +1 -0
  61. package/dist/transform/index.js +31 -0
  62. package/dist/transform/index.js.map +1 -0
  63. package/dist/transform/scope.d.ts +58 -0
  64. package/dist/transform/scope.d.ts.map +1 -0
  65. package/dist/transform/scope.js +500 -0
  66. package/dist/transform/scope.js.map +1 -0
  67. package/dist/transform/seam.d.ts +78 -0
  68. package/dist/transform/seam.d.ts.map +1 -0
  69. package/dist/transform/seam.js +111 -0
  70. package/dist/transform/seam.js.map +1 -0
  71. package/dist/values.d.ts +15 -0
  72. package/dist/values.d.ts.map +1 -1
  73. package/dist/values.js +79 -0
  74. package/dist/values.js.map +1 -1
  75. package/package.json +9 -4
package/README.md CHANGED
@@ -8,6 +8,17 @@ implements, and the simulator and dry run that exercise a program with no broker
8
8
  **Tier:** `packages/` (the standard). Depends on nothing else in the repo; it knows about effects,
9
9
  not about NATS. The host that runs a program on the mesh is `@cotal-ai/runtime`.
10
10
 
11
+ **Two engines.** `run`/`resume` are the tree-walker, language version `1`, and it stays the replay
12
+ engine for every run recorded under it. `engine/` is version `2`: a different language, not a faster
13
+ one, and the one fresh driver runs execute on. Each engine stamps the pins it resolves with its own
14
+ version and compares a recorded version against its own, which is why `WALKER_LANGUAGE_VERSION` and
15
+ `ENGINE_LANGUAGE_VERSION` are two constants and `LANGUAGE_VERSION` is an alias for the current
16
+ language, the engine's. A record binds only under the engine that wrote it (L5008). The engine
17
+ requires node 22 or newer and refuses below it with L1000, an implementation limit that is
18
+ deliberately not in the error catalog. A host runs a program in the engine's worker thread with the
19
+ handler either built inside it from cloneable config, or — when the handler is a live object, as a
20
+ driver's is — kept in the host with the effect seam bridged over a message port (`engine/bridge.ts`).
21
+
11
22
  The language is defined by [`spec/cotal-lang.md`](../../spec/cotal-lang.md) (normative; every
12
23
  `js` block in it is validated by this package's surface suite) and its wire footprint by
13
24
  [SPEC.md §14](../../SPEC.md#14-workflow-runs-v05). The guide is
@@ -0,0 +1,71 @@
1
+ /**
2
+ * The effect bridge: a run in the worker, its effects and its durable journal in the host.
3
+ *
4
+ * The module-named handler in `worker.ts` builds the whole effect path inside the thread, which is
5
+ * right when a handler CAN be built from cloneable config. A driver's handler cannot: it is a live
6
+ * object holding sockets, a mesh client and a lease-bound journal appender, and shipping any of
7
+ * that into the isolate that also holds the hostile program would put credentials one Compartment
8
+ * escape away from the code they exist to confine. This module is the other route: the handler and
9
+ * the durable store STAY IN THE HOST, and the thread forwards the seam over a MessagePort.
10
+ *
11
+ * WHY THIS IS SOUND, measured against the contracts rather than assumed: the durable half of the
12
+ * journal is `JournalStore.append(entry): Promise<void>`, awaited by `Journal.persist` before a
13
+ * key joins `order` and before any effect fires — an async contract, which a port hop preserves
14
+ * with the awaits lining up exactly as they line up over a PubAck today. Every `EffectHandler`
15
+ * member except `now()` is async for the same reason. What is genuinely synchronous is `now()`
16
+ * (a journal stamp) and the stop flag, and both go over shared memory: the stop buffer as it
17
+ * always has, the clock over a dedicated SharedArrayBuffer this module owns — post the request,
18
+ * `Atomics.wait`, read the answer. The handler's clock is injectable, so the bridge may not
19
+ * shortcut it with the thread's own `Date.now()`: a simulated clock bridged that way would run a
20
+ * program under two disagreeing times.
21
+ *
22
+ * WHAT CROSSES, and why every crossing is already fenced: effect requests, effect results, journal
23
+ * entries, a failure's `code`/`kind`/`message`/`detail`, and a bind's `external` — exactly the
24
+ * values the journal records, which the crossing rule (values.ts) fences at their write sites.
25
+ * Errors cross with their DOMAIN, because perform.ts grades the two domains differently: the host
26
+ * side stamps `"effect"` for an `EffectError` and `"host"` for anything else, and the thread
27
+ * rehydrates the real class so a bridged failure journals byte-for-byte as an in-process one.
28
+ *
29
+ * TWO CALLS RUN AGAINST THE ARROW, and both are part of the handler's contract rather than
30
+ * optional extras: `ctx.bind(external)` (the handler declaring the resource it just created —
31
+ * host → thread, because the journal it must reach lives in the thread; its durable append then
32
+ * comes straight back out to the host's store) and `signal.onCancel` (a race loser's cancellation
33
+ * — thread → host, fired at the mirror the host handler was given). The host never blocks its
34
+ * loop, which is what makes the one blocking wait in the thread safe: a `now()` posted while the
35
+ * host is mid-effect is answered by the port handler immediately, from a synchronous clock.
36
+ */
37
+ import type { MessagePort } from "node:worker_threads";
38
+ import type { EffectHandler } from "../effects.js";
39
+ import type { JournalStore } from "../journal.js";
40
+ /** One 16-byte SharedArrayBuffer: an Int32 answer flag at 0, the Float64 clock value at 8. */
41
+ export declare const CLOCK_BYTES = 16;
42
+ /**
43
+ * THE THREAD'S HALF: an {@link EffectHandler} and a {@link JournalStore} over the port.
44
+ *
45
+ * Owned by the worker entry. The live `EffectContext` of every in-flight effect is kept by `seq`
46
+ * so a host-initiated `bind` reaches the real context (and through it, the real journal), and so
47
+ * a cancellation fires at the host the moment the thread's signal fires.
48
+ */
49
+ export declare function bridgedSeam(port: MessagePort, clock: SharedArrayBuffer): {
50
+ handler: EffectHandler;
51
+ store: JournalStore;
52
+ };
53
+ export interface BridgeHost {
54
+ /** The buffer the thread's `now()` blocks on; hand it to the worker beside the port. */
55
+ readonly clock: SharedArrayBuffer;
56
+ /** Stop servicing. Called once the run has answered; a message after that has no run behind it. */
57
+ close(): void;
58
+ }
59
+ /**
60
+ * THE HOST'S HALF: service the thread's seam from a live handler and a live store.
61
+ *
62
+ * The context handed to the handler is rebuilt around the wire's plain data: `bind` forwards to
63
+ * the thread (where the journal lives) and its durable append comes back through `store.append`
64
+ * on this side; `signal` is a mirror the thread's cancellations flip. The host never blocks —
65
+ * every branch here either answers from a synchronous clock or awaits work it already owns.
66
+ */
67
+ export declare function serviceBridge(port: MessagePort, seam: {
68
+ readonly handler: EffectHandler;
69
+ readonly store: JournalStore;
70
+ }): BridgeHost;
71
+ //# sourceMappingURL=bridge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../src/engine/bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,eAAe,CAAC;AAElE,OAAO,KAAK,EAAgB,YAAY,EAAE,MAAM,eAAe,CAAC;AAGhE,8FAA8F;AAC9F,eAAO,MAAM,WAAW,KAAK,CAAC;AAuF9B;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,iBAAiB,GAAG;IAAE,OAAO,EAAE,aAAa,CAAC;IAAC,KAAK,EAAE,YAAY,CAAA;CAAE,CA+ExH;AAED,MAAM,WAAW,UAAU;IACzB,wFAAwF;IACxF,QAAQ,CAAC,KAAK,EAAE,iBAAiB,CAAC;IAClC,mGAAmG;IACnG,KAAK,IAAI,IAAI,CAAC;CACf;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE;IAAE,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAA;CAAE,GAAG,UAAU,CAkGpI"}
@@ -0,0 +1,277 @@
1
+ /**
2
+ * The effect bridge: a run in the worker, its effects and its durable journal in the host.
3
+ *
4
+ * The module-named handler in `worker.ts` builds the whole effect path inside the thread, which is
5
+ * right when a handler CAN be built from cloneable config. A driver's handler cannot: it is a live
6
+ * object holding sockets, a mesh client and a lease-bound journal appender, and shipping any of
7
+ * that into the isolate that also holds the hostile program would put credentials one Compartment
8
+ * escape away from the code they exist to confine. This module is the other route: the handler and
9
+ * the durable store STAY IN THE HOST, and the thread forwards the seam over a MessagePort.
10
+ *
11
+ * WHY THIS IS SOUND, measured against the contracts rather than assumed: the durable half of the
12
+ * journal is `JournalStore.append(entry): Promise<void>`, awaited by `Journal.persist` before a
13
+ * key joins `order` and before any effect fires — an async contract, which a port hop preserves
14
+ * with the awaits lining up exactly as they line up over a PubAck today. Every `EffectHandler`
15
+ * member except `now()` is async for the same reason. What is genuinely synchronous is `now()`
16
+ * (a journal stamp) and the stop flag, and both go over shared memory: the stop buffer as it
17
+ * always has, the clock over a dedicated SharedArrayBuffer this module owns — post the request,
18
+ * `Atomics.wait`, read the answer. The handler's clock is injectable, so the bridge may not
19
+ * shortcut it with the thread's own `Date.now()`: a simulated clock bridged that way would run a
20
+ * program under two disagreeing times.
21
+ *
22
+ * WHAT CROSSES, and why every crossing is already fenced: effect requests, effect results, journal
23
+ * entries, a failure's `code`/`kind`/`message`/`detail`, and a bind's `external` — exactly the
24
+ * values the journal records, which the crossing rule (values.ts) fences at their write sites.
25
+ * Errors cross with their DOMAIN, because perform.ts grades the two domains differently: the host
26
+ * side stamps `"effect"` for an `EffectError` and `"host"` for anything else, and the thread
27
+ * rehydrates the real class so a bridged failure journals byte-for-byte as an in-process one.
28
+ *
29
+ * TWO CALLS RUN AGAINST THE ARROW, and both are part of the handler's contract rather than
30
+ * optional extras: `ctx.bind(external)` (the handler declaring the resource it just created —
31
+ * host → thread, because the journal it must reach lives in the thread; its durable append then
32
+ * comes straight back out to the host's store) and `signal.onCancel` (a race loser's cancellation
33
+ * — thread → host, fired at the mirror the host handler was given). The host never blocks its
34
+ * loop, which is what makes the one blocking wait in the thread safe: a `now()` posted while the
35
+ * host is mid-effect is answered by the port handler immediately, from a synchronous clock.
36
+ */
37
+ import { EffectError } from "../effects.js";
38
+ /** One 16-byte SharedArrayBuffer: an Int32 answer flag at 0, the Float64 clock value at 8. */
39
+ export const CLOCK_BYTES = 16;
40
+ /** The ten async members of {@link EffectHandler}, the only methods the bridge will forward. */
41
+ const METHODS = [
42
+ "spawn",
43
+ "turn",
44
+ "ask",
45
+ "checkpoint",
46
+ "sleep",
47
+ "wait",
48
+ "notify",
49
+ "monitor",
50
+ "openConclave",
51
+ "closeConclave",
52
+ ];
53
+ function flatten(e) {
54
+ if (e instanceof EffectError) {
55
+ return {
56
+ domain: "effect",
57
+ name: e.name,
58
+ message: e.message,
59
+ code: e.code,
60
+ kind: e.kind,
61
+ ...(e.detail !== undefined ? { detail: e.detail } : {}),
62
+ };
63
+ }
64
+ const err = e;
65
+ return {
66
+ domain: "host",
67
+ name: typeof err?.name === "string" ? err.name : "Error",
68
+ message: typeof err?.message === "string" ? err.message : String(e),
69
+ ...(typeof err?.code === "string" ? { code: err.code } : {}),
70
+ ...(err?.indeterminate === true ? { indeterminate: true } : {}),
71
+ };
72
+ }
73
+ /**
74
+ * The thread's side of a flattened error, as the class the grading site expects.
75
+ *
76
+ * An `"effect"` failure becomes the real `EffectError`, because perform.ts records it as the
77
+ * step's outcome; a `"host"` failure becomes a plain Error carrying whatever identifying fields
78
+ * crossed, because the host domain is graded on shape, not class, and `indeterminate` must survive
79
+ * for the journal's L5010 text to say the honest thing about an append nobody saw land.
80
+ */
81
+ function rehydrate(w) {
82
+ if (w.domain === "effect")
83
+ return new EffectError(w.code ?? "L4000", w.kind ?? "handler-fault", w.message, w.detail);
84
+ const e = new Error(w.message);
85
+ e.name = w.name;
86
+ if (w.code !== undefined)
87
+ e.code = w.code;
88
+ if (w.indeterminate === true)
89
+ e.indeterminate = true;
90
+ return e;
91
+ }
92
+ /**
93
+ * THE THREAD'S HALF: an {@link EffectHandler} and a {@link JournalStore} over the port.
94
+ *
95
+ * Owned by the worker entry. The live `EffectContext` of every in-flight effect is kept by `seq`
96
+ * so a host-initiated `bind` reaches the real context (and through it, the real journal), and so
97
+ * a cancellation fires at the host the moment the thread's signal fires.
98
+ */
99
+ export function bridgedSeam(port, clock) {
100
+ const flag = new Int32Array(clock, 0, 1);
101
+ const value = new Float64Array(clock, 8, 1);
102
+ let seq = 0;
103
+ const pending = new Map();
104
+ const live = new Map();
105
+ port.on("message", (m) => {
106
+ if (m.kind === "answer") {
107
+ const p = pending.get(m.seq);
108
+ // An answer nobody is waiting for is a protocol disagreement, not a value to drop quietly.
109
+ if (p === undefined)
110
+ throw new Error(`cotal-lang effect bridge: the host answered seq ${m.seq}, which this thread never asked`);
111
+ pending.delete(m.seq);
112
+ live.delete(m.seq);
113
+ if (m.ok)
114
+ p.resolve(m.value);
115
+ else
116
+ p.reject(rehydrate(m.error));
117
+ return;
118
+ }
119
+ if (m.kind === "bind") {
120
+ const ctx = live.get(m.seq);
121
+ if (ctx === undefined) {
122
+ // The effect settled between the handler's bind and this message arriving. The handler's
123
+ // own await of `bind` is what carries the refusal; answering is all this side can do.
124
+ port.postMessage({ kind: "bind-answer", bseq: m.bseq, error: { domain: "host", name: "Error", message: `effect ${m.seq} is no longer in flight; its bind cannot reach the journal` } });
125
+ return;
126
+ }
127
+ void ctx.bind(m.external).then(() => port.postMessage({ kind: "bind-answer", bseq: m.bseq }), (e) => port.postMessage({ kind: "bind-answer", bseq: m.bseq, error: flatten(e) }));
128
+ return;
129
+ }
130
+ throw new Error(`cotal-lang effect bridge: the host sent a message kind this thread does not know (${String(m.kind)})`);
131
+ });
132
+ const call = (method, req, ctx) => {
133
+ const s = seq++;
134
+ live.set(s, ctx);
135
+ ctx.signal.onCancel((reason) => port.postMessage({ kind: "cancel", seq: s, reason }));
136
+ const answer = new Promise((resolve, reject) => pending.set(s, { resolve, reject }));
137
+ port.postMessage({
138
+ kind: "effect",
139
+ seq: s,
140
+ method,
141
+ req,
142
+ ctx: {
143
+ key: ctx.key,
144
+ requestId: ctx.requestId,
145
+ attempt: ctx.attempt,
146
+ ...(ctx.resume !== undefined ? { resume: ctx.resume } : {}),
147
+ },
148
+ });
149
+ return answer;
150
+ };
151
+ const handler = {
152
+ // The flag is cleared BEFORE the request is posted, so a host that answers before this thread
153
+ // reaches the wait leaves the flag already flipped and the wait returns "not-equal" at once.
154
+ now() {
155
+ Atomics.store(flag, 0, 0);
156
+ port.postMessage({ kind: "now" });
157
+ Atomics.wait(flag, 0, 0);
158
+ return value[0];
159
+ },
160
+ };
161
+ for (const m of METHODS) {
162
+ handler[m] = (req, ctx) => call(m, req, ctx);
163
+ }
164
+ const store = {
165
+ append(entry) {
166
+ const s = seq++;
167
+ const answer = new Promise((resolve, reject) => pending.set(s, { resolve: () => resolve(), reject }));
168
+ port.postMessage({ kind: "append", seq: s, entry });
169
+ return answer;
170
+ },
171
+ };
172
+ return { handler, store };
173
+ }
174
+ /**
175
+ * THE HOST'S HALF: service the thread's seam from a live handler and a live store.
176
+ *
177
+ * The context handed to the handler is rebuilt around the wire's plain data: `bind` forwards to
178
+ * the thread (where the journal lives) and its durable append comes back through `store.append`
179
+ * on this side; `signal` is a mirror the thread's cancellations flip. The host never blocks —
180
+ * every branch here either answers from a synchronous clock or awaits work it already owns.
181
+ */
182
+ export function serviceBridge(port, seam) {
183
+ const clock = new SharedArrayBuffer(CLOCK_BYTES);
184
+ const flag = new Int32Array(clock, 0, 1);
185
+ const value = new Float64Array(clock, 8, 1);
186
+ let bseq = 0;
187
+ const binds = new Map();
188
+ const cancels = new Map();
189
+ port.on("message", (m) => {
190
+ if (m.kind === "now") {
191
+ value[0] = seam.handler.now();
192
+ Atomics.store(flag, 0, 1);
193
+ Atomics.notify(flag, 0);
194
+ return;
195
+ }
196
+ if (m.kind === "append") {
197
+ void seam.store.append(m.entry).then(() => port.postMessage({ kind: "answer", seq: m.seq, ok: true, value: undefined }), (e) => port.postMessage({ kind: "answer", seq: m.seq, ok: false, error: flatten(e) }));
198
+ return;
199
+ }
200
+ if (m.kind === "effect") {
201
+ const seqHere = m.seq;
202
+ let cancelled = false;
203
+ let reason;
204
+ const listeners = [];
205
+ cancels.set(seqHere, {
206
+ fire: (r) => {
207
+ cancelled = true;
208
+ reason = r;
209
+ for (const fn of listeners)
210
+ fn(r);
211
+ },
212
+ });
213
+ const ctx = {
214
+ key: m.ctx.key,
215
+ requestId: m.ctx.requestId,
216
+ attempt: m.ctx.attempt,
217
+ ...(m.ctx.resume !== undefined ? { resume: m.ctx.resume } : {}),
218
+ signal: {
219
+ get cancelled() {
220
+ return cancelled;
221
+ },
222
+ get reason() {
223
+ return reason;
224
+ },
225
+ onCancel(fn) {
226
+ listeners.push(fn);
227
+ },
228
+ },
229
+ bind: (external) => {
230
+ const b = bseq++;
231
+ const answer = new Promise((resolve, reject) => binds.set(b, { resolve, reject }));
232
+ port.postMessage({ kind: "bind", bseq: b, seq: seqHere, external });
233
+ return answer;
234
+ },
235
+ };
236
+ const method = seam.handler[m.method];
237
+ // The method set is this module's own constant, so an unknown name is the two sides
238
+ // disagreeing about the protocol — refused as an answer, never dispatched dynamically.
239
+ if (!METHODS.includes(m.method) || typeof method !== "function") {
240
+ port.postMessage({ kind: "answer", seq: seqHere, ok: false, error: { domain: "host", name: "Error", message: `the effect bridge does not forward "${String(m.method)}"` } });
241
+ cancels.delete(seqHere);
242
+ return;
243
+ }
244
+ void method.call(seam.handler, m.req, ctx).then((v) => {
245
+ cancels.delete(seqHere);
246
+ port.postMessage({ kind: "answer", seq: seqHere, ok: true, value: v });
247
+ }, (e) => {
248
+ cancels.delete(seqHere);
249
+ port.postMessage({ kind: "answer", seq: seqHere, ok: false, error: flatten(e) });
250
+ });
251
+ return;
252
+ }
253
+ if (m.kind === "cancel") {
254
+ // A cancel finds its mirror only while the effect is in flight: the answer deletes the
255
+ // mirror, so the walker's post-settle blanket cancellations (aimed at arms that already
256
+ // returned) do not cross. Deliberate, and pinned by the engine suite's parked-loser cells:
257
+ // the host handler hears a cancel exactly when its effect is still open, which is the only
258
+ // time it can act on one.
259
+ cancels.get(m.seq)?.fire(m.reason);
260
+ return;
261
+ }
262
+ if (m.kind === "bind-answer") {
263
+ const b = binds.get(m.bseq);
264
+ if (b === undefined)
265
+ throw new Error(`cotal-lang effect bridge: the thread answered bind ${m.bseq}, which this host never asked`);
266
+ binds.delete(m.bseq);
267
+ if (m.error === undefined)
268
+ b.resolve();
269
+ else
270
+ b.reject(rehydrate(m.error));
271
+ return;
272
+ }
273
+ throw new Error(`cotal-lang effect bridge: the thread sent a message kind this host does not know (${String(m.kind)})`);
274
+ });
275
+ return { clock, close: () => port.close() };
276
+ }
277
+ //# sourceMappingURL=bridge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../src/engine/bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAIH,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAI5C,8FAA8F;AAC9F,MAAM,CAAC,MAAM,WAAW,GAAG,EAAE,CAAC;AAE9B,gGAAgG;AAChG,MAAM,OAAO,GAAG;IACd,OAAO;IACP,MAAM;IACN,KAAK;IACL,YAAY;IACZ,OAAO;IACP,MAAM;IACN,QAAQ;IACR,SAAS;IACT,cAAc;IACd,eAAe;CACP,CAAC;AAmCX,SAAS,OAAO,CAAC,CAAU;IACzB,IAAI,CAAC,YAAY,WAAW,EAAE,CAAC;QAC7B,OAAO;YACL,MAAM,EAAE,QAAQ;YAChB,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,OAAO,EAAE,CAAC,CAAC,OAAO;YAClB,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,GAAG,CAAC,CAAC,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACxD,CA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AAE,CAAC;;gBAClC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;YAClC,OAAO;QACT,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,qFAAqF,MAAM,CAAE,CAAwB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClJ,CAAC,CAAC,CAAC;IAEH,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,140 @@
1
+ /**
2
+ * `__ctx`: the WHOLE seam between the transformed program and the host.
3
+ *
4
+ * The transform emits a CLOSED function expression with zero free identifiers; the host
5
+ * evaluates it in a Compartment with ZERO endowments and passes this object as the call argument
6
+ * (the seam contract). So this file is the complete list of what a program can reach. Anything not
7
+ * here is not reachable, which is why the member list is a surface both sides hold each other to.
8
+ *
9
+ * Every law lives here, and every table it needs is IMPORTED. `library.ts` owns the curated method
10
+ * tables and the free builtins; `values.ts` owns freezing, birth-depth stamping and the crossing
11
+ * check; `keys.ts` owns key allocation; `journal.ts` owns the entries. Nothing in this file is a
12
+ * second copy of any of them: a copied table is a table that disagrees with the walker on its
13
+ * first edit, and the walker is the differential oracle.
14
+ *
15
+ * WHAT THIS FILE IS NOT: it is not the walker rewritten. The walker enforces these laws inline
16
+ * while it walks; here they are the host side of a native program's calls. The behaviours must be
17
+ * identical and the differential suite is what says so: same programs, walker and engine,
18
+ * identical journals (entry sequences and step keys, not merely output).
19
+ */
20
+ import { type EffectHandler } from "../effects.js";
21
+ import type { Journal } from "../journal.js";
22
+ import type { RunPins } from "../pins.js";
23
+ /**
24
+ * A static per-call-site payload the transform computes from the input AST.
25
+ *
26
+ * It exists because the engine has NO AST at run time and one journal field is a function of one:
27
+ * a settled `race` records a `branchDigest` over its unwalked arms. Without this the engine could
28
+ * not produce a byte-identical entry for any race that settled, and the differential gate would
29
+ * fail on shape rather than on behaviour.
30
+ */
31
+ export interface Site {
32
+ /** Branch key -> `digest(stripPositions(armBody))`, computed with the walker's own functions. */
33
+ readonly branchDigests?: Readonly<Record<string, unknown>>;
34
+ }
35
+ /**
36
+ * The seam. Fourteen members, and the count is the point: a member added here without a joint rule
37
+ * is a widening, and the transform's surface cell reddens on any call to a name not on this
38
+ * interface. Thirteen came with the seam contract; `callee` is the fourteenth, added under the
39
+ * adaptation invariant below.
40
+ */
41
+ export interface EngineCtx {
42
+ /** L4013 step budget, plus the yield that keeps the macrotask queue alive and applies the cut. */
43
+ fuel(): void | Promise<void>;
44
+ /**
45
+ * Read a member: L4014 (no prototype reach, curated tables), L4020, L4018 on a computed key.
46
+ *
47
+ * `binding` is the cell read, taken as a third argument rather than a fifteenth member. A binding
48
+ * the transform classified as a CELL is emitted as `get(cell, "v", "x")`, and an absent OWN key
49
+ * means the declaration has not run yet, which is L2004 for that binding by name. PRESENCE is
50
+ * `hasOwn` and not truthiness, because `v: undefined` is a binding that HAS been initialised, to
51
+ * undefined. Without the argument, `get` is byte-unchanged.
52
+ */
53
+ get(o: unknown, k: unknown, binding?: string): unknown;
54
+ /**
55
+ * Write a member: L2031, L2032, L4014, L4017, L4019. Answers `v`, as an assignment does.
56
+ *
57
+ * `binding` is the cell WRITE, taken as a fourth argument for the same reason `get` took a third.
58
+ * It is present ONLY on an ASSIGNMENT to a cell, never on the declaration's own initialising write,
59
+ * and an absent OWN key there means the declaration has not run: L2004 naming the binding, in the
60
+ * walker's assignment words, which are not the read's. The key is LEFT ABSENT by the refusal, so
61
+ * the declaration that has not run yet still initialises the binding when it does.
62
+ */
63
+ set(o: unknown, k: unknown, v: unknown, binding?: string): unknown;
64
+ /**
65
+ * Call a member. The single L4020 exception: a method is resolved AT the call and nowhere else.
66
+ *
67
+ * `optional` is `o.m?.()`, a flag rather than a fifteenth member. It guards a
68
+ * NULLISH MEMBER and nothing else (measured on the walker, `?.` softens neither L4014 nor L4011),
69
+ * and a short-circuited call evaluates NO ARGUMENT, which is why the optional form takes a thunk.
70
+ *
71
+ * `chain` is EVERYTHING WRITTEN AFTER the optional call, as a closure. A short-circuit swallows the
72
+ * whole rest of the chain, and only the host knows a short-circuit happened: measured, `o.z?.().x`
73
+ * on an absent member is `undefined` while `o.m?.().x` on a member that RETURNS undefined is L4010,
74
+ * and a guard on the returned value cannot tell those apart, so it would drop a refusal in silence.
75
+ * Handing the continuation here lets the one place that made the decision apply it.
76
+ */
77
+ call(o: unknown, k: unknown, args: unknown[] | (() => unknown[] | Promise<unknown[]>), optional?: boolean, chain?: (value: unknown) => unknown): Promise<unknown>;
78
+ /** Stamp a freshly built container with this frame's depth (L2032's runtime half). */
79
+ born<T>(v: T): T;
80
+ /** A journalled primitive. */
81
+ effect(name: string, args: unknown[], site?: Site): Promise<unknown>;
82
+ /** A free builtin: called with `args`, or READ as a value when `args` is omitted. */
83
+ free(name: string, args?: unknown[]): unknown;
84
+ /** The thenable gate, before the host's await machinery can run a program closure. */
85
+ await(v: unknown): Promise<unknown>;
86
+ /** Template interpolation: L4018, no implicit conversion. */
87
+ template(parts: readonly string[], values: readonly unknown[]): string;
88
+ /** The binary operators' coercion law (L4018) and JavaScript's meaning. `===`/`!==` stay native. */
89
+ binary(op: string, l: unknown, r: unknown): unknown;
90
+ /** `-`, `+`, `~` under the same law, and `update` for the operand of `++`/`--`. `!`/`typeof` are native. */
91
+ unary(op: string, v: unknown): unknown;
92
+ /** The iterability law (L4015): arrays and strings, nothing else. */
93
+ iter(v: unknown): unknown[];
94
+ /** The L4011 refusal at a non-function callee. Emitted behind a `typeof`, so only the refusal runs. */
95
+ callee(v: unknown): unknown;
96
+ /** At the head of every emitted catch: rethrow the uncatchable, else the program-visible error. */
97
+ caught(e: unknown): unknown;
98
+ }
99
+ /** What a run hands the seam. */
100
+ export interface EngineRun {
101
+ readonly runId: string;
102
+ readonly programHash: string;
103
+ readonly journal: Journal;
104
+ readonly handler: EffectHandler;
105
+ readonly pins: RunPins;
106
+ readonly onLog?: (line: {
107
+ scope: string;
108
+ values: readonly unknown[];
109
+ }) => void;
110
+ readonly shouldStop?: () => string | undefined;
111
+ }
112
+ /**
113
+ * The seam, plus the one thing the HOST needs from it that the program must never see.
114
+ *
115
+ * `steps()` is the count charged against the step budget, which a `RunResult` reports so a host can
116
+ * see how close a program runs to the ceiling before the ceiling is what tells it. It is deliberately
117
+ * NOT a member of {@link EngineCtx}: everything on that interface is reachable from inside the
118
+ * compartment, and a program that can read its own fuel gauge can shape its behaviour around one.
119
+ */
120
+ export declare function createEngine(run: EngineRun): {
121
+ readonly ctx: EngineCtx;
122
+ steps(): number;
123
+ };
124
+ /** The seam alone. */
125
+ export declare function createCtx(run: EngineRun): EngineCtx;
126
+ /**
127
+ * The engine broke its own contract, and no program may catch that.
128
+ *
129
+ * The one thing that reaches this today is a native `ReferenceError`. The emitted module is a closed
130
+ * expression with zero free identifiers, so nothing the program wrote can name a binding that is not
131
+ * there; a ReferenceError therefore means a TDZ read the transform's classifier missed or an emitter
132
+ * temporary read before it was bound. It is not the program's error, it is not converted to one, and
133
+ * it is never mapped to L2004 by reading its message - that mapping would make a compiler bug
134
+ * indistinguishable from the language rule it imitates.
135
+ */
136
+ export declare class EngineFault extends Error {
137
+ readonly cause: unknown;
138
+ constructor(cause: unknown);
139
+ }
140
+ //# sourceMappingURL=ctx.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ctx.d.ts","sourceRoot":"","sources":["../../src/engine/ctx.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAA0B,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAE3E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAS1C;;;;;;;GAOG;AACH,MAAM,WAAW,IAAI;IACnB,iGAAiG;IACjG,QAAQ,CAAC,aAAa,CAAC,EAAE,QAAQ,CAAC,MAAM,C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