@lute-lang/runtime 0.40.0 → 0.41.1

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.
package/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # @lute-lang/runtime
2
+
3
+ The Lute runtime for TypeScript hosts, in [Effect](https://effect.website) 4:
4
+ load a bundle compiled by `lute compile --all`, drive the resumable step
5
+ function, query the state (`view`, `evaluate`, `def`, `gate`, `candidates`, …),
6
+ and replay input logs, on Bun and in browsers.
7
+
8
+ ```console
9
+ bun add @lute-lang/runtime effect@4.0.2 @effect/platform-bun@4.0.2
10
+ # or, for a browser application:
11
+ bun add @lute-lang/runtime effect@4.0.2 @effect/platform-browser@4.0.2
12
+ ```
13
+
14
+ The host guide — sessions, the `Program` API, errors, state interchangeability,
15
+ replay, and local dogfooding with packed tarballs — is
16
+ [`docs/runtime/typescript-runtime.md`](https://github.com/journeyWorker/lute/blob/main/docs/runtime/typescript-runtime.md).
17
+
18
+ ## Building from the repository
19
+
20
+ The package wraps the wasm binding of `crates/lute-runtime-wasm`. In
21
+ `packages/runtime`:
22
+
23
+ ```console
24
+ bun install
25
+ bun run wasm:build # debug binding -> src/wasm/
26
+ bun run build # dist/: ESM entry points, declarations, the binding
27
+ bun run typecheck
28
+ bun run test # builds the binding first (incremental)
29
+ ```
30
+
31
+ `bun run wasm:build:release` builds the release binding and optimizes it with
32
+ `wasm-opt -O`; a published package ships that one.
33
+
34
+ ### Tools
35
+
36
+ `wasm:build` needs Rust with the `wasm32-unknown-unknown` target and
37
+ **`wasm-bindgen` 0.2.126** — exactly the binding crate's `wasm-bindgen`
38
+ version. The script resolves it in this order:
39
+
40
+ 1. `$WASM_BINDGEN`, a path to the binary;
41
+ 2. `wasm-bindgen` on `PATH`;
42
+ 3. the wasm-pack cache entry of the pinned version,
43
+ `<cache>/.wasm-pack/wasm-bindgen-cargo-install-0.2.126/wasm-bindgen`
44
+ (`wasm-bindgen.exe` on Windows), where `<cache>` is `~/Library/Caches` on
45
+ macOS, `$XDG_CACHE_HOME` or `~/.cache` on Linux, and `%LOCALAPPDATA%` on
46
+ Windows — wasm-pack leaves it there after any build of a crate pinned to
47
+ that version.
48
+
49
+ When none resolves, or the binary cannot be run or reports another version,
50
+ the script prints
51
+
52
+ ```text
53
+ wasm-build: need wasm-bindgen 0.2.126 (set WASM_BINDGEN, put it on PATH, or cargo install --locked wasm-bindgen-cli --version 0.2.126)
54
+ ```
55
+
56
+ and exits 1. Install it with
57
+ `cargo install --locked wasm-bindgen-cli --version 0.2.126`.
58
+
59
+ `wasm:build:release` also needs binaryen's `wasm-opt`, from `$WASM_OPT` or
60
+ `PATH`.
61
+
62
+ The contract schemas under `src/generated/` are generated from the Rust types:
63
+ `bun run contract:gen` regenerates them and `bun run contract:check` fails on
64
+ drift. Never edit them by hand.
package/dist/Bundle.d.ts CHANGED
@@ -1,17 +1,230 @@
1
1
  /**
2
2
  * A compiled bundle: `project.index.json` and every artifact it lists, keyed
3
3
  * by the index's `artifact` paths — the output of `lute compile --all`
4
- * (spec 0.38.0 §4.1). The runtime validates it on load.
4
+ * (spec 0.38.0 §4.1). The index is typed by the generated `Ir.projectIndex`
5
+ * (spec 0.41.0 §4.4); the runtime validates the whole bundle on load.
5
6
  */
6
7
  import { Schema } from "effect";
8
+ import * as Ir from "./generated/Ir.js";
7
9
  export declare const Bundle: Schema.Struct<{
8
- readonly index: Schema.Codec<Schema.Json, Schema.Json, never, never>;
10
+ readonly index: Schema.Struct<{
11
+ readonly beats: Schema.optionalKey<Schema.$Array<Schema.suspend<Schema.Struct<{
12
+ readonly advances: Schema.optionalKey<Schema.Union<readonly [Schema.Literals<readonly ["slot", "day"]>, Schema.Int]>>;
13
+ readonly document: Schema.String;
14
+ readonly forKind: Schema.optionalKey<Schema.suspend<Schema.Struct<{
15
+ readonly kind: Schema.String;
16
+ readonly members: Schema.$Array<Schema.String>;
17
+ }>>>;
18
+ readonly id: Schema.String;
19
+ readonly kind: Schema.Literals<readonly ["scene", "entry", "bundle"]>;
20
+ readonly on: Schema.String;
21
+ readonly once: Schema.optionalKey<Schema.String>;
22
+ readonly priority: Schema.Int;
23
+ readonly share: Schema.optionalKey<Schema.String>;
24
+ readonly spentBy: Schema.optionalKey<Schema.String>;
25
+ readonly target: Schema.optionalKey<Schema.String>;
26
+ readonly targetKind: Schema.optionalKey<Schema.suspend<Schema.Struct<{
27
+ readonly kind: Schema.String;
28
+ readonly prefix: Schema.String;
29
+ readonly members: Schema.$Array<Schema.String>;
30
+ }>>>;
31
+ readonly title: Schema.optionalKey<Schema.String>;
32
+ readonly when: Schema.optionalKey<Schema.String>;
33
+ }>>>>;
34
+ readonly bridgeResults: Schema.optionalKey<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.suspend<Schema.Codec<Ir.fieldType, Ir.fieldType, never, never>>>>>;
35
+ readonly capabilitySnapshot: Schema.String;
36
+ readonly cast: Schema.optionalKey<Schema.$Record<Schema.String, Schema.String>>;
37
+ readonly clock: Schema.optionalKey<Schema.suspend<Schema.Struct<{
38
+ readonly day: Schema.String;
39
+ readonly slot: Schema.optionalKey<Schema.String>;
40
+ readonly slots: Schema.optionalKey<Schema.$Array<Schema.String>>;
41
+ readonly raise: Schema.optionalKey<Schema.Union<readonly [Schema.String, Schema.Struct<{
42
+ readonly slot: Schema.optionalKey<Schema.String>;
43
+ readonly dayStart: Schema.optionalKey<Schema.String>;
44
+ readonly dayEnd: Schema.optionalKey<Schema.String>;
45
+ }>]>>;
46
+ readonly raiseAtStart: Schema.optionalKey<Schema.Literal<true>>;
47
+ readonly week: Schema.optionalKey<Schema.Struct<{
48
+ readonly length: Schema.Int;
49
+ readonly first: Schema.Int;
50
+ readonly labels: Schema.optionalKey<Schema.$Array<Schema.String>>;
51
+ }>>;
52
+ readonly last: Schema.optionalKey<Schema.Struct<{
53
+ readonly day: Schema.Int;
54
+ readonly slot: Schema.optionalKey<Schema.String>;
55
+ }>>;
56
+ readonly days: Schema.optionalKey<Schema.Int>;
57
+ }>>>;
58
+ readonly defs: Schema.optionalKey<Schema.$Record<Schema.String, Schema.suspend<Schema.Struct<{
59
+ readonly authored: Schema.optionalKey<Schema.String>;
60
+ readonly cel: Schema.String;
61
+ readonly expr: Schema.Codec<Schema.Json, Schema.Json, never, never>;
62
+ readonly host: Schema.optionalKey<Schema.Boolean>;
63
+ readonly params: Schema.optionalKey<Schema.$Array<Schema.Struct<{
64
+ readonly name: Schema.String;
65
+ readonly type: Schema.suspend<Schema.Codec<Ir.fieldType, Ir.fieldType, never, never>>;
66
+ }>>>;
67
+ }>>>>;
68
+ readonly documents: Schema.$Array<Schema.suspend<Schema.Struct<{
69
+ readonly artifact: Schema.String;
70
+ readonly key: Schema.String;
71
+ readonly kind: Schema.Literals<readonly ["scene", "quest", "lore"]>;
72
+ readonly path: Schema.String;
73
+ }>>>;
74
+ readonly entities: Schema.$Array<Schema.suspend<Schema.Struct<{
75
+ readonly name: Schema.String;
76
+ readonly members: Schema.optionalKey<Schema.$Array<Schema.String>>;
77
+ readonly open: Schema.Boolean;
78
+ readonly labels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.String>>;
79
+ readonly labelForms: Schema.optionalKey<Schema.suspend<Schema.$Record<Schema.String, Schema.Struct<{
80
+ readonly start: Schema.optionalKey<Schema.String>;
81
+ readonly indefinite: Schema.optionalKey<Schema.String>;
82
+ }>>>>;
83
+ }>>>;
84
+ readonly entries: Schema.optionalKey<Schema.$Array<Schema.suspend<Schema.Struct<{
85
+ readonly category: Schema.optionalKey<Schema.String>;
86
+ readonly document: Schema.String;
87
+ readonly id: Schema.String;
88
+ readonly order: Schema.optionalKey<Schema.Int>;
89
+ readonly series: Schema.optionalKey<Schema.String>;
90
+ readonly target: Schema.optionalKey<Schema.String>;
91
+ }>>>>;
92
+ readonly enums: Schema.$Array<Schema.suspend<Schema.Struct<{
93
+ readonly name: Schema.String;
94
+ readonly members: Schema.$Array<Schema.String>;
95
+ readonly labels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.String>>;
96
+ }>>>;
97
+ readonly gates: Schema.optionalKey<Schema.$Array<Schema.Struct<{
98
+ readonly occasion: Schema.String;
99
+ readonly raisedWhen: Schema.suspend<Schema.Struct<{
100
+ readonly cel: Schema.String;
101
+ readonly expr: Schema.Codec<Schema.Json, Schema.Json, never, never>;
102
+ readonly authored: Schema.optionalKey<Schema.String>;
103
+ }>>;
104
+ }>>>;
105
+ readonly identityRenames: Schema.optionalKey<Schema.$Array<Schema.Struct<{
106
+ readonly from: Schema.String;
107
+ readonly to: Schema.String;
108
+ }>>>;
109
+ readonly irVersion: Schema.String;
110
+ readonly occasions: Schema.optionalKey<Schema.$Record<Schema.String, Schema.suspend<Schema.Struct<{
111
+ readonly judge: Schema.optionalKey<Schema.Literals<readonly ["after", "before"]>>;
112
+ readonly outsideRun: Schema.optionalKey<Schema.Boolean>;
113
+ readonly payload: Schema.optionalKey<Schema.$Record<Schema.String, Schema.suspend<Schema.Codec<Ir.fieldType, Ir.fieldType, never, never>>>>;
114
+ readonly select: Schema.Literals<readonly ["first", "all", "sequence"]>;
115
+ readonly target: Schema.Union<readonly [Schema.Boolean, Schema.Struct<{
116
+ readonly entity: Schema.String;
117
+ readonly members: Schema.optionalKey<Schema.$Array<Schema.String>>;
118
+ readonly prefix: Schema.String;
119
+ }>]>;
120
+ }>>>>;
121
+ readonly outsideRun: Schema.optionalKey<Schema.$Array<Schema.String>>;
122
+ readonly prereqEdges: Schema.$Array<Schema.suspend<Schema.Struct<{
123
+ readonly node: Schema.String;
124
+ readonly after: Schema.optionalKey<Schema.String>;
125
+ readonly follows: Schema.optionalKey<Schema.String>;
126
+ readonly formula: Schema.optionalKey<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
127
+ }>>>;
128
+ readonly relations: Schema.$Array<Schema.suspend<Schema.Struct<{
129
+ readonly name: Schema.String;
130
+ readonly args: Schema.$Array<Schema.String>;
131
+ readonly tier: Schema.optionalKey<Schema.String>;
132
+ readonly derive: Schema.Boolean;
133
+ readonly reserved: Schema.Boolean;
134
+ readonly key: Schema.optionalKey<Schema.$Array<Schema.Int>>;
135
+ readonly excludes: Schema.optionalKey<Schema.$Array<Schema.String>>;
136
+ }>>>;
137
+ readonly requiredSemantics: Schema.$Array<Schema.String>;
138
+ readonly rules: Schema.$Array<Schema.suspend<Schema.Struct<{
139
+ readonly head: Schema.suspend<Schema.Struct<{
140
+ readonly relation: Schema.String;
141
+ readonly terms: Schema.$Array<Schema.suspend<Schema.toTaggedUnion<"kind", readonly [Schema.Struct<{
142
+ readonly kind: Schema.Literal<"var">;
143
+ readonly name: Schema.String;
144
+ }>, Schema.Struct<{
145
+ readonly kind: Schema.Literal<"const">;
146
+ readonly value: Schema.String;
147
+ }>]>>>;
148
+ }>>;
149
+ readonly body: Schema.$Array<Schema.suspend<Schema.toTaggedUnion<"kind", readonly [Schema.Struct<{
150
+ readonly kind: Schema.Literal<"atom">;
151
+ readonly atom: Schema.suspend<Schema.Struct<{
152
+ readonly relation: Schema.String;
153
+ readonly terms: Schema.$Array<Schema.suspend<Schema.toTaggedUnion<"kind", readonly [Schema.Struct<{
154
+ readonly kind: Schema.Literal<"var">;
155
+ readonly name: Schema.String;
156
+ }>, Schema.Struct<{
157
+ readonly kind: Schema.Literal<"const">;
158
+ readonly value: Schema.String;
159
+ }>]>>>;
160
+ }>>;
161
+ readonly negated: Schema.Boolean;
162
+ }>, Schema.Struct<{
163
+ readonly kind: Schema.Literal<"guard">;
164
+ readonly cel: Schema.suspend<Schema.Struct<{
165
+ readonly cel: Schema.String;
166
+ readonly expr: Schema.Codec<Schema.Json, Schema.Json, never, never>;
167
+ readonly authored: Schema.optionalKey<Schema.String>;
168
+ }>>;
169
+ }>, Schema.Struct<{
170
+ readonly kind: Schema.Literal<"cmp">;
171
+ readonly lhs: Schema.suspend<Schema.toTaggedUnion<"kind", readonly [Schema.Struct<{
172
+ readonly kind: Schema.Literal<"var">;
173
+ readonly name: Schema.String;
174
+ }>, Schema.Struct<{
175
+ readonly kind: Schema.Literal<"const">;
176
+ readonly value: Schema.String;
177
+ }>]>>;
178
+ readonly rhs: Schema.suspend<Schema.toTaggedUnion<"kind", readonly [Schema.Struct<{
179
+ readonly kind: Schema.Literal<"var">;
180
+ readonly name: Schema.String;
181
+ }>, Schema.Struct<{
182
+ readonly kind: Schema.Literal<"const">;
183
+ readonly value: Schema.String;
184
+ }>]>>;
185
+ readonly negated: Schema.Boolean;
186
+ }>, Schema.Struct<{
187
+ readonly kind: Schema.Literal<"count">;
188
+ readonly atom: Schema.suspend<Schema.Struct<{
189
+ readonly relation: Schema.String;
190
+ readonly terms: Schema.$Array<Schema.suspend<Schema.toTaggedUnion<"kind", readonly [Schema.Struct<{
191
+ readonly kind: Schema.Literal<"var">;
192
+ readonly name: Schema.String;
193
+ }>, Schema.Struct<{
194
+ readonly kind: Schema.Literal<"const">;
195
+ readonly value: Schema.String;
196
+ }>]>>>;
197
+ }>>;
198
+ readonly distinct: Schema.optionalKey<Schema.$Array<Schema.String>>;
199
+ readonly op: Schema.Literals<readonly ["==", "!=", "<", "<=", ">", ">="]>;
200
+ readonly n: Schema.Int;
201
+ }>]>>>;
202
+ readonly raw: Schema.String;
203
+ }>>>;
204
+ readonly seasons: Schema.optionalKey<Schema.$Array<Schema.Struct<{
205
+ readonly live: Schema.suspend<Schema.Struct<{
206
+ readonly cel: Schema.String;
207
+ readonly expr: Schema.Codec<Schema.Json, Schema.Json, never, never>;
208
+ readonly authored: Schema.optionalKey<Schema.String>;
209
+ }>>;
210
+ readonly name: Schema.String;
211
+ }>>>;
212
+ readonly seedFacts: Schema.$Array<Schema.suspend<Schema.Struct<{
213
+ readonly relation: Schema.String;
214
+ readonly args: Schema.$Array<Schema.String>;
215
+ }>>>;
216
+ readonly stateDomains: Schema.optionalKey<Schema.$Record<Schema.String, Schema.suspend<Schema.Struct<{
217
+ readonly kind: Schema.String;
218
+ readonly members: Schema.$Array<Schema.String>;
219
+ }>>>>;
220
+ readonly terminal: Schema.optionalKey<Schema.suspend<Schema.Struct<{
221
+ readonly cel: Schema.String;
222
+ readonly expr: Schema.Codec<Schema.Json, Schema.Json, never, never>;
223
+ readonly authored: Schema.optionalKey<Schema.String>;
224
+ }>>>;
225
+ readonly terminalPersists: Schema.optionalKey<Schema.Boolean>;
226
+ readonly worldEvents: Schema.optionalKey<Schema.$Array<Schema.String>>;
227
+ }>;
9
228
  readonly artifacts: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>;
10
229
  }>;
11
230
  export type Bundle = typeof Bundle.Type;
12
- /** The part of `project.index.json` a loader reads: where each artifact is. */
13
- export declare const IndexDocuments: Schema.Struct<{
14
- readonly documents: Schema.$Array<Schema.Struct<{
15
- readonly artifact: Schema.String;
16
- }>>;
17
- }>;
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import { Context, Effect, FileSystem, Layer, Path } from "effect";
7
7
  import * as HttpClient from "effect/http/HttpClient";
8
- import { Bundle } from "./Bundle.js";
8
+ import type { Bundle } from "./Bundle.js";
9
9
  import type { BundleError } from "./Errors.js";
10
10
  declare const BundleSource_base: Context.ServiceClass<BundleSource, "@lute-lang/runtime/BundleSource", {
11
11
  readonly load: Effect.Effect<Bundle, BundleError>;
package/dist/Errors.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The typed failures of the runtime (spec 0.40.0 §5.3).
2
+ * The typed failures of the runtime (spec 0.40.0 §5.3, 0.41.0 §6.3).
3
3
  *
4
4
  * A rejected input is an expected failure: each runtime code is its own
5
5
  * tagged error, carrying the runtime's `code` and `message`. A code this
@@ -46,7 +46,7 @@ declare const InvalidInput_base: Schema.Class<InvalidInput, Schema.TaggedStruct<
46
46
  readonly code: Schema.Literal<"E-RUNTIME-INPUT">;
47
47
  readonly message: Schema.String;
48
48
  }>, import("effect/Cause").YieldableError>;
49
- /** `E-RUNTIME-INPUT`: a seed or input names something the project lacks. */
49
+ /** `E-RUNTIME-INPUT`: a seed, input or query names something the project lacks. */
50
50
  export declare class InvalidInput extends InvalidInput_base {
51
51
  }
52
52
  declare const RuntimeHalted_base: Schema.Class<RuntimeHalted, Schema.TaggedStruct<"RuntimeHalted", {
@@ -77,13 +77,47 @@ declare const SnapshotVersionMismatch_base: Schema.Class<SnapshotVersionMismatch
77
77
  /** `E-RUNTIME-SNAPSHOT-VERSION`: the snapshot is of another Event minor. */
78
78
  export declare class SnapshotVersionMismatch extends SnapshotVersionMismatch_base {
79
79
  }
80
+ declare const OccasionGateClosed_base: Schema.Class<OccasionGateClosed, Schema.TaggedStruct<"OccasionGateClosed", {
81
+ readonly code: Schema.Literal<"E-OCCASION-GATE">;
82
+ readonly message: Schema.String;
83
+ }>, import("effect/Cause").YieldableError>;
84
+ /**
85
+ * `E-OCCASION-GATE`: the engine would not make this raise — the occasion's
86
+ * `raisedWhen` is false, or the game is over and the occasion is not
87
+ * `outsideRun` (spec 0.41.0 §5.2). The state is unchanged, the input's own
88
+ * writes included; `Program.gate` answers the same rule beforehand.
89
+ */
90
+ export declare class OccasionGateClosed extends OccasionGateClosed_base {
91
+ }
80
92
  /** Every rejection the runtime returns. */
81
- export type RuntimeRejection = RuntimeBusy | RequestMismatch | OptionUnavailable | BridgeShapeMismatch | InvalidInput | TimeoutUnavailable | RuntimeHalted | IrVersionMismatch | SnapshotProjectMismatch | SnapshotVersionMismatch;
93
+ export type RuntimeRejection = RuntimeBusy | RequestMismatch | OptionUnavailable | BridgeShapeMismatch | InvalidInput | TimeoutUnavailable | RuntimeHalted | IrVersionMismatch | SnapshotProjectMismatch | SnapshotVersionMismatch | OccasionGateClosed;
82
94
  /**
83
95
  * Fail with the typed error of a runtime rejection; a code this package does
84
96
  * not know dies.
85
97
  */
86
98
  export declare const fromRejected: (rejected: Rejected) => Effect.Effect<never, RuntimeRejection>;
99
+ declare const EvaluationError_base: Schema.Class<EvaluationError, Schema.TaggedStruct<"EvaluationError", {
100
+ readonly code: Schema.Literal<"E-RUNTIME-EVAL">;
101
+ readonly message: Schema.String;
102
+ }>, import("effect/Cause").YieldableError>;
103
+ /** `E-RUNTIME-EVAL`: a queried condition evaluates to an error (spec 0.41.0 §5.1). */
104
+ export declare class EvaluationError extends EvaluationError_base {
105
+ }
106
+ /**
107
+ * Every rejection a condition query (`Program.evaluate`, `Program.def`)
108
+ * returns: a malformed expression, an unknown def name or a misfit argument,
109
+ * or an evaluation error.
110
+ */
111
+ export type QueryRejection = InvalidInput | EvaluationError;
112
+ /**
113
+ * Fail with the typed error of a query rejection; any other code dies.
114
+ */
115
+ export declare const fromQueryRejected: (rejected: Rejected) => Effect.Effect<never, QueryRejection>;
116
+ /**
117
+ * Fail with the typed error of a `Program.gate` rejection (an occasion the
118
+ * bundle does not declare); any other code dies.
119
+ */
120
+ export declare const fromGateRejected: (rejected: Rejected) => Effect.Effect<never, InvalidInput>;
87
121
  declare const BundleNotFound_base: Schema.Class<BundleNotFound, Schema.TaggedStruct<"BundleNotFound", {
88
122
  readonly path: Schema.String;
89
123
  readonly message: Schema.String;
@@ -6,6 +6,7 @@
6
6
  import { Context, Effect, Layer, Schema } from "effect";
7
7
  import * as KeyValueStore from "effect/persistence/KeyValueStore";
8
8
  import { InputLogError } from "./Errors.js";
9
+ import * as Contract from "./generated/Contract.js";
9
10
  export declare const LogEntry: Schema.Union<readonly [Schema.Struct<{
10
11
  readonly seed: Schema.Struct<{
11
12
  readonly derive: Schema.optionalKey<Schema.Boolean>;
@@ -45,10 +46,11 @@ export declare const LogEntry: Schema.Union<readonly [Schema.Struct<{
45
46
  readonly request: Schema.Int;
46
47
  readonly type: Schema.Literal<"awaitChoice">;
47
48
  }>, Schema.Struct<{
49
+ readonly attrs: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>;
48
50
  readonly document: Schema.String;
49
- readonly fields: Schema.$Record<Schema.String, Schema.String>;
50
51
  readonly position: Schema.String;
51
52
  readonly request: Schema.Int;
53
+ readonly results: Schema.$Record<Schema.String, Schema.suspend<Schema.Codec<Contract.fieldType, Contract.fieldType, never, never>>>;
52
54
  readonly tag: Schema.String;
53
55
  readonly type: Schema.Literal<"awaitBridge">;
54
56
  }>, Schema.Struct<{
@@ -72,6 +74,16 @@ export declare const LogEntry: Schema.Union<readonly [Schema.Struct<{
72
74
  readonly bridge: Schema.Struct<{
73
75
  readonly fields: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>;
74
76
  readonly tag: Schema.String;
77
+ readonly writes: Schema.optionalKey<Schema.suspend<Schema.Struct<{
78
+ readonly accept: Schema.optionalKey<Schema.$Array<Schema.String>>;
79
+ readonly facts: Schema.optionalKey<Schema.$Array<Schema.String>>;
80
+ readonly retract: Schema.optionalKey<Schema.$Array<Schema.String>>;
81
+ readonly state: Schema.optionalKey<Schema.$Array<Schema.suspend<Schema.Struct<{
82
+ readonly add: Schema.optionalKey<Schema.NullOr<Schema.Number>>;
83
+ readonly path: Schema.String;
84
+ readonly value: Schema.optionalKey<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
85
+ }>>>>;
86
+ }>>>;
75
87
  }>;
76
88
  }>]>>>;
77
89
  readonly before: Schema.suspend<Schema.Struct<{
@@ -180,6 +192,16 @@ export declare const LogEntry: Schema.Union<readonly [Schema.Struct<{
180
192
  readonly fields: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>;
181
193
  readonly request: Schema.Int;
182
194
  readonly type: Schema.Literal<"bridgeResult">;
195
+ readonly writes: Schema.optionalKey<Schema.suspend<Schema.Struct<{
196
+ readonly accept: Schema.optionalKey<Schema.$Array<Schema.String>>;
197
+ readonly facts: Schema.optionalKey<Schema.$Array<Schema.String>>;
198
+ readonly retract: Schema.optionalKey<Schema.$Array<Schema.String>>;
199
+ readonly state: Schema.optionalKey<Schema.$Array<Schema.suspend<Schema.Struct<{
200
+ readonly add: Schema.optionalKey<Schema.NullOr<Schema.Number>>;
201
+ readonly path: Schema.String;
202
+ readonly value: Schema.optionalKey<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
203
+ }>>>>;
204
+ }>>>;
183
205
  }>, Schema.Struct<{
184
206
  readonly by: Schema.suspend<Schema.Union<readonly [Schema.String, Schema.Int, Schema.Struct<{
185
207
  readonly to: Schema.String;
@@ -251,10 +273,11 @@ export declare const LogEntry: Schema.Union<readonly [Schema.Struct<{
251
273
  readonly request: Schema.Int;
252
274
  readonly type: Schema.Literal<"awaitChoice">;
253
275
  }>, Schema.Struct<{
276
+ readonly attrs: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>;
254
277
  readonly document: Schema.String;
255
- readonly fields: Schema.$Record<Schema.String, Schema.String>;
256
278
  readonly position: Schema.String;
257
279
  readonly request: Schema.Int;
280
+ readonly results: Schema.$Record<Schema.String, Schema.suspend<Schema.Codec<Contract.fieldType, Contract.fieldType, never, never>>>;
258
281
  readonly tag: Schema.String;
259
282
  readonly type: Schema.Literal<"awaitBridge">;
260
283
  }>, Schema.Struct<{
@@ -405,6 +428,16 @@ export declare const LogEntry: Schema.Union<readonly [Schema.Struct<{
405
428
  readonly fields: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>;
406
429
  readonly request: Schema.Int;
407
430
  readonly type: Schema.Literal<"bridgeResult">;
431
+ readonly writes: Schema.optionalKey<Schema.suspend<Schema.Struct<{
432
+ readonly accept: Schema.optionalKey<Schema.$Array<Schema.String>>;
433
+ readonly facts: Schema.optionalKey<Schema.$Array<Schema.String>>;
434
+ readonly retract: Schema.optionalKey<Schema.$Array<Schema.String>>;
435
+ readonly state: Schema.optionalKey<Schema.$Array<Schema.suspend<Schema.Struct<{
436
+ readonly add: Schema.optionalKey<Schema.NullOr<Schema.Number>>;
437
+ readonly path: Schema.String;
438
+ readonly value: Schema.optionalKey<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
439
+ }>>>>;
440
+ }>>>;
408
441
  }>, Schema.Struct<{
409
442
  readonly by: Schema.suspend<Schema.Union<readonly [Schema.String, Schema.Int, Schema.Struct<{
410
443
  readonly to: Schema.String;
package/dist/Program.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  /**
2
- * A loaded bundle and the runtime's step function over it (spec 0.40.0 §5.1).
2
+ * A loaded bundle and the runtime's step function over it (spec 0.40.0 §5.1,
3
+ * 0.41.0 §6).
3
4
  *
4
5
  * Every value crossing the binding is encoded and decoded with the contract
5
6
  * schemas generated from the Rust types. JSON the binding returns that does
6
7
  * not decode is contract drift — a defect.
7
8
  */
8
- import { Effect, Option } from "effect";
9
+ import { Effect, Option, Schema } from "effect";
9
10
  import * as Errors from "./Errors.js";
10
11
  import * as Contract from "./generated/Contract.js";
11
12
  import type * as Glue from "./wasm/lute_runtime_wasm.js";
@@ -14,6 +15,11 @@ declare const TypeId = "~@lute-lang/runtime/RuntimeState";
14
15
  * An opaque, immutable runtime state. Stepping from it never invalidates it,
15
16
  * so a host may keep earlier states (undo, branching). Its serialized form
16
17
  * is {@link Program.snapshot}.
18
+ *
19
+ * A state is valid for every `Program` loaded from a bundle with the
20
+ * fingerprint of the program that created it (spec 0.41.0 §6.2): a host may
21
+ * query the state of a session it does not drive with its own program of
22
+ * that bundle. Handing it to a program of another fingerprint is a defect.
17
23
  */
18
24
  export interface RuntimeState {
19
25
  readonly [TypeId]: typeof TypeId;
@@ -38,6 +44,28 @@ export interface Program {
38
44
  readonly view: (state: RuntimeState, options?: {
39
45
  readonly facts?: boolean;
40
46
  }) => Effect.Effect<Contract.WorldView>;
47
+ /**
48
+ * Evaluate an IR `exprNode` — the `expr` of any `{cel, expr}` pair the IR
49
+ * carries, such as an objective's `visibleWhen.expr`, or the output of
50
+ * `lute expr` — over the state, as the runtime's walk reads a guard (spec
51
+ * 0.41.0 §5.1). A `param` node is not admitted: it is `InvalidInput`.
52
+ */
53
+ readonly evaluate: (state: RuntimeState, expr: Schema.Json) => Effect.Effect<Contract.Evaluation, Errors.QueryRejection>;
54
+ /**
55
+ * Evaluate the bundle's index def `name` over the state, binding its
56
+ * parameters to `args` in declaration order — one JSON scalar each, absent
57
+ * for a parameterless def (spec 0.41.0 §5.1). A wrong arity or an argument
58
+ * that does not fit its parameter type is `InvalidInput`.
59
+ */
60
+ readonly def: (state: RuntimeState, name: string, args?: ReadonlyArray<string | number | boolean>) => Effect.Effect<Contract.Evaluation, Errors.QueryRejection>;
61
+ /**
62
+ * Whether a `raiseOccasion` of `occasion` (for `target`) with no writes
63
+ * would pass the seam now (spec 0.41.0 §5.2): `open: false` without
64
+ * `unresolved` is decided closed (its `raisedWhen` is false, or the game
65
+ * is over and the occasion is not `outsideRun`); with `unresolved`, it is
66
+ * undecided. An occasion the bundle does not declare is `InvalidInput`.
67
+ */
68
+ readonly gate: (state: RuntimeState, occasion: string, target?: string) => Effect.Effect<Contract.Gate, Errors.InvalidInput>;
41
69
  }
42
70
  /** Fail with a rejection the binding returned as JSON. */
43
71
  export declare const rejection: (json: string) => Effect.Effect<never, Errors.RuntimeRejection>;
package/dist/Session.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  /**
2
- * One running playthrough (spec 0.40.0 §5.2): the host sends inputs, watches
3
- * the state, and subscribes to events and awaits. The session adds no game
4
- * policy — it answers nothing and paces nothing.
2
+ * One running playthrough (spec 0.40.0 §5.2, 0.41.0 §6.2): the host sends
3
+ * inputs, watches the state, subscribes to events and awaits, and queries the
4
+ * state through the session's program. The session adds no game policy — it
5
+ * answers nothing and paces nothing.
5
6
  */
6
7
  import { Context, Effect, Layer, Scope, Stream, SubscriptionRef } from "effect";
7
8
  import { BundleSource } from "./BundleSource.js";
@@ -9,16 +10,23 @@ import type { BundleError, InputLogError, RuntimeRejection } from "./Errors.js";
9
10
  import type { Await, Event, Input, Output, Seed, Snapshot, Stage } from "./generated/Contract.js";
10
11
  import { InputLog } from "./InputLog.js";
11
12
  import { LuteRuntime } from "./LuteRuntime.js";
12
- import type { RuntimeState } from "./Program.js";
13
+ import type { Program, RuntimeState } from "./Program.js";
13
14
  /** Where the session stands: its state, stage, and what it waits for. */
14
15
  export interface SessionState {
15
16
  readonly state: RuntimeState;
16
17
  readonly stage: Stage;
17
18
  readonly await: Await;
18
19
  }
19
- declare const Session_base: Context.ServiceClass<Session, "@lute-lang/runtime/Session", {
20
+ /** The session service. */
21
+ export interface SessionShape {
20
22
  /** The program's fingerprint (what snapshots carry). */
21
23
  readonly fingerprint: string;
24
+ /**
25
+ * The program the layer loaded, valid for the session's scope: run
26
+ * `view`, `evaluate`, `def`, `gate`, `candidates` … over `current`'s state
27
+ * without loading the bundle a second time.
28
+ */
29
+ readonly program: Program;
22
30
  /** The output of `begin`; for a restored session, no events and the snapshot's await. */
23
31
  readonly started: Output;
24
32
  /**
@@ -39,7 +47,8 @@ declare const Session_base: Context.ServiceClass<Session, "@lute-lang/runtime/Se
39
47
  readonly save: Effect.Effect<Snapshot>;
40
48
  /** Continue from a snapshot; the input log restarts from it. */
41
49
  readonly restore: (snapshot: Snapshot) => Effect.Effect<void, RuntimeRejection | InputLogError>;
42
- }>;
50
+ }
51
+ declare const Session_base: Context.ServiceClass<Session, "@lute-lang/runtime/Session", SessionShape>;
43
52
  export declare class Session extends Session_base {
44
53
  }
45
54
  /** How a session starts: from a seed, or from a snapshot. */
package/dist/browser.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  fromBytes,
8
8
  layer,
9
9
  layer2
10
- } from "./index-wshk3yvw.js";
10
+ } from "./index-tecmws3f.js";
11
11
 
12
12
  // src/browser.ts
13
13
  import * as BrowserKeyValueStore from "@effect/platform-browser/BrowserKeyValueStore";
package/dist/bun.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  fromBytes,
7
7
  layer,
8
8
  layer2
9
- } from "./index-wshk3yvw.js";
9
+ } from "./index-tecmws3f.js";
10
10
 
11
11
  // src/bun.ts
12
12
  import * as BunServices from "@effect/platform-bun/BunServices";