@playfast/reform-proof 0.0.7 → 0.0.8

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/src/index.ts ADDED
@@ -0,0 +1,301 @@
1
+ import { Effect } from 'effect'
2
+ import type { YieldWrap } from 'effect/Utils'
3
+ import { AssertionFailed } from './errors'
4
+ import { ProofRunner, type ProofRunnerApi, proofRunnerLayer, withProofRunner } from './runner'
5
+ import type {
6
+ CompositionClass,
7
+ CompositionService,
8
+ Scene,
9
+ SlotInstance,
10
+ Trigger,
11
+ UiCapture,
12
+ UiContract,
13
+ } from '@playfast/reform'
14
+
15
+ // reform-proof — the stability story for AI authorship. Product behaviour is
16
+ // declared as human-readable requirements (the definition) and proven by tests
17
+ // (the implementation), the same split as the rest of reform. A proof drives the
18
+ // real reduce loop through a headless FACADE: no DOM, no text matching. It reads
19
+ // the props each composition computed and calls the contract's events as
20
+ // callbacks — exactly what the production UI receives. HOW a proof runs is the
21
+ // injectable `ProofRunner` layer (./runner); the headless engine (./engine) is its
22
+ // default. `Proof.run`/`Proof.driver` resolve that layer, so the vitest adapter
23
+ // can drive the very same proofs as native tests.
24
+
25
+ // The injectable execution seam is re-exported so adapters can resolve it.
26
+ export { ProofRunner, proofRunnerLayer, withProofRunner }
27
+ export type { ProofRunnerApi }
28
+
29
+ // ---------------------------------------------------------------------------
30
+ // Definitions: ProductRequirement + Product
31
+ // ---------------------------------------------------------------------------
32
+
33
+ /** Any composition, used where the contract type is irrelevant. */
34
+ type AnyComposition = CompositionClass<any, any>
35
+
36
+ export interface RequirementManifest<Comp extends AnyComposition, Statement extends string> {
37
+ readonly kind: 'ProductRequirement'
38
+ readonly name: Statement
39
+ /** The human-readable behavioural statement; doubles as the manifest name. */
40
+ readonly statement: Statement
41
+ /** The composition this requirement specifies — its contract types the facade. */
42
+ readonly composition: Comp
43
+ }
44
+
45
+ export interface RequirementClass<Comp extends AnyComposition, Statement extends string> {
46
+ new (): {}
47
+ readonly manifest: RequirementManifest<Comp, Statement>
48
+ }
49
+
50
+ export interface ProductManifest<Comp extends AnyComposition> {
51
+ readonly kind: 'Product'
52
+ readonly name: string
53
+ readonly composition: Comp
54
+ readonly requirements: ReadonlyArray<RequirementClass<Comp, string>>
55
+ }
56
+
57
+ export interface ProductClass<Comp extends AnyComposition = AnyComposition> {
58
+ new (): {}
59
+ readonly manifest: ProductManifest<Comp>
60
+ }
61
+
62
+ /**
63
+ * A named, human-readable behavioural statement bound to the composition it
64
+ * specifies. The composition types the proof facade; the statement's literal
65
+ * type is re-stated (and enforced) at `Proof.implement`.
66
+ */
67
+ const makeRequirement = <Comp extends AnyComposition, const Statement extends string>(
68
+ composition: Comp,
69
+ statement: Statement,
70
+ ): RequirementClass<Comp, Statement> =>
71
+ Object.assign(class {}, {
72
+ manifest: { kind: 'ProductRequirement' as const, name: statement, statement, composition },
73
+ })
74
+
75
+ export const ProductRequirement: { readonly make: typeof makeRequirement } = {
76
+ make: makeRequirement,
77
+ }
78
+
79
+ /**
80
+ * Group a composition with the full list of requirements that specify it. The
81
+ * shared `Comp` type-checks that every requirement targets this composition.
82
+ */
83
+ const makeProduct = <Comp extends AnyComposition>(
84
+ composition: Comp,
85
+ config: { readonly requirements: ReadonlyArray<RequirementClass<Comp, string>> },
86
+ ): ProductClass<Comp> =>
87
+ Object.assign(class {}, {
88
+ manifest: {
89
+ kind: 'Product' as const,
90
+ name: composition.manifest.name,
91
+ composition,
92
+ requirements: config.requirements,
93
+ },
94
+ })
95
+
96
+ export const Product: { readonly make: typeof makeProduct } = { make: makeProduct }
97
+
98
+ // ---------------------------------------------------------------------------
99
+ // Assertions — Effect-returning matchers; a failed match fails the proof.
100
+ // ---------------------------------------------------------------------------
101
+
102
+ const deepEqual = (a: unknown, b: unknown): boolean =>
103
+ Object.is(a, b) || JSON.stringify(a) === JSON.stringify(b)
104
+
105
+ const fail = (message: string): Effect.Effect<never> =>
106
+ Effect.sync(() => {
107
+ throw new AssertionFailed({ detail: message })
108
+ })
109
+
110
+ export const expect = <A>(actual: A) => ({
111
+ toBe: (expected: A): Effect.Effect<void> =>
112
+ Object.is(actual, expected)
113
+ ? Effect.void
114
+ : fail(`expected ${JSON.stringify(actual)} to be ${JSON.stringify(expected)}`),
115
+ toEqual: (expected: A): Effect.Effect<void> =>
116
+ deepEqual(actual, expected)
117
+ ? Effect.void
118
+ : fail(`expected ${JSON.stringify(actual)} to equal ${JSON.stringify(expected)}`),
119
+ toContain: (expected: A extends ReadonlyArray<infer E> ? E : unknown): Effect.Effect<void> =>
120
+ Array.isArray(actual) && actual.some((item) => deepEqual(item, expected))
121
+ ? Effect.void
122
+ : fail(`expected ${JSON.stringify(actual)} to contain ${JSON.stringify(expected)}`),
123
+ })
124
+
125
+ // ---------------------------------------------------------------------------
126
+ // Facade — a headless view over the live composition tree
127
+ // ---------------------------------------------------------------------------
128
+
129
+ // --- Contract projection: derive the facade's exact shape from a UI contract ---
130
+
131
+ /** The event payloads of a contract, keyed by event name. */
132
+ type EventsOf<C extends UiContract> = C extends { events: infer E } ? E : Record<never, never>
133
+ /** The slot instances of a contract, keyed by slot name. */
134
+ type SlotsOf<C extends UiContract> = C extends { slots: infer S } ? S : Record<never, never>
135
+ /** The payload a trigger accepts. */
136
+ type PayloadOf<T> = T extends Trigger<infer P> ? P : never
137
+ /** The UI contract a composition resolves. */
138
+ export type ContractOf<Comp> = Comp extends CompositionClass<any, infer C> ? C : never
139
+ /** The child contract a slot stands for — the contract of the composition it holds. */
140
+ type ContractOfSlot<S> = S extends SlotInstance<infer Comp> ? ContractOf<Comp> : never
141
+
142
+ /** The contract's events as facade actions: payload in, dispatch-and-settle Effect out. */
143
+ export type ActionsOf<C extends UiContract> = {
144
+ readonly [K in keyof EventsOf<C>]: (
145
+ payload: PayloadOf<EventsOf<C>[K]>,
146
+ ) => Effect.Effect<void, never, CompositionService>
147
+ }
148
+ /** The contract's slots as child facades, each typed by the child's own contract. */
149
+ export type SlotFacadesOf<C extends UiContract> = {
150
+ readonly [K in keyof SlotsOf<C>]: SlotFacade<ContractOfSlot<SlotsOf<C>[K]>>
151
+ }
152
+
153
+ /** The Effect a facade action returns: dispatch the event, then settle. */
154
+ export type Action = (payload: unknown) => Effect.Effect<void, never, CompositionService>
155
+
156
+ /**
157
+ * The handle a proof drives — the same surface the production UI receives, fully
158
+ * typed from the composition's contract `C`: read state (`props`), trigger events
159
+ * (`actions`), reach children (`slots`), and wait for the next frame (`frame`).
160
+ * Each access yields a real Effect/SlotFacade against the running engine.
161
+ */
162
+ export interface Facade<C extends UiContract> {
163
+ /** Re-render the tree and read the props this node last computed. */
164
+ readonly props: Effect.Effect<C['props'], never, CompositionService>
165
+ /** The contract's events as callables; calling one dispatches and settles. */
166
+ readonly actions: ActionsOf<C>
167
+ /** Child composition facades, keyed by slot name. */
168
+ readonly slots: SlotFacadesOf<C>
169
+ /** Settle the engine and re-render — wait for the next stable frame. */
170
+ readonly frame: Effect.Effect<void, never, CompositionService>
171
+ }
172
+
173
+ /** A slot may hold many instances (a list); it is also usable as its first one. */
174
+ export interface SlotFacade<C extends UiContract> extends Facade<C> {
175
+ readonly first: Effect.Effect<Facade<C>, never, CompositionService>
176
+ readonly at: (index: number) => Effect.Effect<Facade<C>, never, CompositionService>
177
+ readonly all: Effect.Effect<ReadonlyArray<Facade<C>>, never, CompositionService>
178
+ }
179
+
180
+ // ---------------------------------------------------------------------------
181
+ // Proofs + suite
182
+ // ---------------------------------------------------------------------------
183
+
184
+ /** The generator a proof body produces — its yielded effects run on the engine. */
185
+ type ProofGenerator = Generator<
186
+ YieldWrap<Effect.Effect<unknown, unknown, CompositionService>>,
187
+ void,
188
+ unknown
189
+ >
190
+
191
+ /** An erased facade — the runtime shape before the contract type is re-attached. */
192
+ type AnyFacade = Facade<UiContract>
193
+
194
+ /** The erased body stored on a `Proof` value; `implement` types the contract in. */
195
+ export type ProofBody = (app: AnyFacade) => ProofGenerator
196
+
197
+ export interface Proof {
198
+ readonly requirement: RequirementClass<AnyComposition, string>
199
+ /** The scene this proof runs against: its closed wiring + boot events. */
200
+ readonly scene: Scene
201
+ readonly body: ProofBody
202
+ }
203
+
204
+ export interface ProofSuite {
205
+ /** Brand so adapters can duck-type a suite among a module's exports. */
206
+ readonly kind: 'ProofSuite'
207
+ readonly product: ProductClass
208
+ readonly proofs: ReadonlyArray<Proof>
209
+ }
210
+
211
+ export interface ProofResult {
212
+ readonly requirement: string
213
+ readonly ok: boolean
214
+ readonly error?: string
215
+ }
216
+
217
+ export interface SuiteResult {
218
+ readonly product: string
219
+ readonly results: ReadonlyArray<ProofResult>
220
+ readonly ok: boolean
221
+ }
222
+
223
+ /**
224
+ * Implement (prove) a requirement by driving the facade against a scene. A proof
225
+ * is a VALUE. The scene supplies the runtime (its closed `provide` + `boot`) and
226
+ * the composition that types the facade; its contract must equal the
227
+ * requirement's composition contract, so a scene for the wrong composition — or
228
+ * one whose contract has drifted — is a compile error. The `app` facade is fully
229
+ * typed from that contract.
230
+ */
231
+ const implement = <Comp extends AnyComposition>(
232
+ requirement: RequirementClass<Comp, string>,
233
+ scene: Scene<ContractOf<Comp>>,
234
+ body: (app: Facade<ContractOf<Comp>>) => ProofGenerator,
235
+ ): Proof => ({ requirement, scene, body: body as ProofBody })
236
+
237
+ /** Compose proofs with the product whose requirements they prove. */
238
+ const suite = (
239
+ product: ProductClass,
240
+ config: { readonly proofs: ReadonlyArray<Proof> },
241
+ ): ProofSuite => ({ kind: 'ProofSuite', product, proofs: config.proofs })
242
+
243
+ const isRecord = (value: unknown): value is Record<string, unknown> =>
244
+ typeof value === 'object' && value !== null
245
+
246
+ /** Duck-type a `ProofSuite` among arbitrary module exports (the adapter's seam). */
247
+ export const isProofSuite = (value: unknown): value is ProofSuite =>
248
+ isRecord(value) && value['kind'] === 'ProofSuite' && Array.isArray(value['proofs'])
249
+
250
+ /**
251
+ * Run every proof against a fresh runtime, returning per-requirement results.
252
+ * Each proof gets its own environment, so nothing leaks between proofs. Execution
253
+ * goes through the injected `ProofRunner` (the headless engine by default).
254
+ */
255
+ const run = (proofSuite: ProofSuite): Promise<SuiteResult> =>
256
+ withProofRunner(async (runner: ProofRunnerApi) => {
257
+ const results: ProofResult[] = []
258
+ for (const proof of proofSuite.proofs) {
259
+ results.push(await runner.executeProof(proof))
260
+ }
261
+ return { product: proofSuite.product.manifest.name, results, ok: results.every((r) => r.ok) }
262
+ })
263
+
264
+ // ---------------------------------------------------------------------------
265
+ // Driver: step a proof for the editor's Test-play timeline
266
+ // ---------------------------------------------------------------------------
267
+
268
+ /** One step of a driven proof: the rendered tree captured right after the
269
+ * proof's i-th yielded effect settled. Index 0 is the booted, pre-drive tree. */
270
+ export interface StepFrame {
271
+ readonly index: number
272
+ readonly captures: ReadonlyArray<UiCapture>
273
+ }
274
+
275
+ export interface DriveResult {
276
+ readonly requirement: string
277
+ readonly frames: ReadonlyArray<StepFrame>
278
+ readonly ok: boolean
279
+ readonly error?: string
280
+ }
281
+
282
+ export interface ProofDriver {
283
+ readonly requirement: string
284
+ /** Run the proof, snapshotting the captured tree after each yielded step. */
285
+ readonly run: () => Promise<DriveResult>
286
+ }
287
+
288
+ /** A driver per proof in the suite — the editor's Test-play entry point. Each
289
+ * `run` resolves the same `ProofRunner` layer and steps that proof. */
290
+ const driver = (proofSuite: ProofSuite): ReadonlyArray<ProofDriver> =>
291
+ proofSuite.proofs.map((proof) => ({
292
+ requirement: proof.requirement.manifest.statement,
293
+ run: () => withProofRunner((runner: ProofRunnerApi) => runner.driveProof(proof)),
294
+ }))
295
+
296
+ export const Proof: {
297
+ readonly implement: typeof implement
298
+ readonly suite: typeof suite
299
+ readonly run: typeof run
300
+ readonly driver: typeof driver
301
+ } = { implement, suite, run, driver }
package/src/runner.ts ADDED
@@ -0,0 +1,42 @@
1
+ import { Context, Effect, Layer } from 'effect'
2
+ import { driveProof, executeProof } from './engine'
3
+ import type { DriveResult, Proof, ProofResult } from './index'
4
+
5
+ // reform-proof runner — the injectable seam HOW a proof is executed. The proof
6
+ // system depends on this layer rather than calling the engine directly, so the
7
+ // execution strategy can be swapped (the vitest adapter resolves the same layer to
8
+ // run each proof as a native test). The default layer is the headless engine in
9
+ // ./engine; mirrors the Tag + Layer house style of reform's `CaptureSink` and
10
+ // `Notifications` services.
11
+
12
+ export interface ProofRunnerApi {
13
+ /** Run a proof to completion, returning its pass/fail result. */
14
+ readonly executeProof: (proof: Proof) => Promise<ProofResult>
15
+ /** Step a proof a frame at a time (the editor's Test-play timeline). */
16
+ readonly driveProof: (proof: Proof) => Promise<DriveResult>
17
+ }
18
+
19
+ const ProofRunnerBase: Context.TagClass<ProofRunner, 'reform-proof/ProofRunner', ProofRunnerApi> =
20
+ Context.Tag('reform-proof/ProofRunner')<ProofRunner, ProofRunnerApi>()
21
+
22
+ /** The service identity for the proof execution strategy. */
23
+ export class ProofRunner extends ProofRunnerBase {}
24
+
25
+ /** The default runner: the headless engine that drives the real reduce loop. */
26
+ export const proofRunnerLayer: Layer.Layer<ProofRunner> = Layer.succeed(ProofRunner, {
27
+ executeProof,
28
+ driveProof,
29
+ })
30
+
31
+ /**
32
+ * Resolve the `ProofRunner` from `proofRunnerLayer` and use it — the single seam
33
+ * the proof system (`Proof.run`/`Proof.driver`) and the vitest adapter both run
34
+ * through, so every proof executes via the same injectable engine.
35
+ */
36
+ export const withProofRunner = <A>(use: (runner: ProofRunnerApi) => Promise<A>): Promise<A> =>
37
+ Effect.runPromise(
38
+ ProofRunner.pipe(
39
+ Effect.flatMap((runner) => Effect.promise(() => use(runner))),
40
+ Effect.provide(proofRunnerLayer),
41
+ ),
42
+ )
package/dist/engine.d.ts DELETED
@@ -1,18 +0,0 @@
1
- import type { DriveResult, Proof, ProofResult } from './index';
2
- /**
3
- * Run one proof against a fresh runtime, returning its pass/fail result. Each
4
- * proof gets its own isolated environment, so nothing leaks between proofs. Boots
5
- * the scene as the host would, settles, then runs the proof body to completion.
6
- */
7
- export declare const executeProof: (proof: Proof) => Promise<ProofResult>;
8
- /**
9
- * Drive one proof a step at a time, recording a `StepFrame` after each yielded
10
- * effect settles. Reuses the same makeFacade runtime/facade/settle as
11
- * `executeProof`, but instead of handing the body to `Effect.gen` (which runs it
12
- * to completion), it pumps the generator by hand — `gen.next(value)` yields the
13
- * next effect, we run it on the live runtime, snapshot the sink, and feed the
14
- * result back. So the editor gets the per-step timeline with no change to the
15
- * proof authoring API.
16
- */
17
- export declare const driveProof: (proof: Proof) => Promise<DriveResult>;
18
- //# sourceMappingURL=engine.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAU,WAAW,EAAU,KAAK,EAAE,WAAW,EAAyB,MAAM,SAAS,CAAA;AA0PrG;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAU,OAAO,KAAK,KAAG,OAAO,CAAC,WAAW,CAqBpE,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU,GAAU,OAAO,KAAK,KAAG,OAAO,CAAC,WAAW,CAkClE,CAAA"}
package/dist/engine.js DELETED
@@ -1,259 +0,0 @@
1
- import { Effect, Layer, ManagedRuntime } from 'effect';
2
- import { yieldWrapGet } from 'effect/Utils';
3
- import { isValidElement } from 'react';
4
- import { UnknownAction, UnknownSlot } from './errors';
5
- import { Bus, CaptureSink, Composition, isFeatureBinding, publish, } from '@playfast/reform';
6
- // The drain loop, channels, RPC, and reducers run on forked fibers, so a
7
- // dispatched event takes an unknown number of ticks to flow through. Each poll
8
- // first drains COOPERATIVELY — a burst of `yieldNow` lets those forked fibers
9
- // cascade (event → channel → procedure → in-memory RPC → fact → reducer) with no
10
- // real time — so a synchronous flow reaches its final state within one poll. A
11
- // real-time `sleep` is still paid each poll to remain the correctness authority
12
- // for a genuinely time-delayed client (the cooperative drain alone could read a
13
- // flow waiting on a real timer as falsely "stable" and settle early). The render
14
- // then re-runs until the captured tree stops changing, bounded so a stuck flow
15
- // fails fast instead of hanging.
16
- const SETTLE_DRAIN = 30;
17
- const SETTLE_STEP = '1 milli';
18
- const SETTLE_MAX_RENDERS = 100;
19
- /** Cooperatively run forked engine fibers to a fixpoint without advancing real time. */
20
- const settleDrain = Effect.yieldNow().pipe(Effect.repeatN(SETTLE_DRAIN));
21
- // A keyed view backed by a getter — the only place dynamic keys are needed.
22
- const keyed = (get) => {
23
- const target = Object.create(null);
24
- return new Proxy(target, { get: (_t, key) => get(String(key)) });
25
- };
26
- const uiNameOf = (comp) => comp.manifest.ui.manifest.name;
27
- const makeSink = () => {
28
- // A const holder whose array we swap on reset (no reassigned binding).
29
- const state = { captures: [] };
30
- return {
31
- api: { record: (capture) => state.captures.push(capture) },
32
- get captures() {
33
- return state.captures;
34
- },
35
- reset: () => {
36
- state.captures = [];
37
- },
38
- };
39
- };
40
- /**
41
- * Build a proof's runtime layer: the scene's closed wiring with the capture sink
42
- * merged in, so `Ui`'s `serviceOption(CaptureSink)` finds it and records each
43
- * render (absent in production, the same layer renders to React). The scene's
44
- * `provide` is typed to the host-read subset (`MountedServices`); a proof also
45
- * resolves slot-binding tags (`CompositionClass`), which the same closed layer
46
- * supplies at runtime — restate that broader `RuntimeServices` surface here. This
47
- * is the one erasure boundary, the same seam the react host crosses when it reads
48
- * a slot tag with the requirement erased.
49
- */
50
- const proofLayer = (scene, sink) => {
51
- const sceneLayer = scene.provide.reduce((a, b) => Layer.merge(a, b));
52
- return Layer.provideMerge(sceneLayer, Layer.succeed(CaptureSink, sink.api));
53
- };
54
- /**
55
- * Walk a rendered node tree and invoke any slot components it contains (JSX
56
- * defers them to the host; headless we drive them ourselves), enqueuing the
57
- * child each stands for. Slot components are matched by identity, so this never
58
- * calls — and never needs hooks from — ordinary components.
59
- */
60
- const drive = (node, enqueueBy) => {
61
- if (Array.isArray(node)) {
62
- for (const child of node)
63
- drive(child, enqueueBy);
64
- return;
65
- }
66
- if (!isValidElement(node))
67
- return;
68
- if (node.type instanceof Function) {
69
- const enqueue = enqueueBy.get(node.type);
70
- if (enqueue !== undefined) {
71
- enqueue(node.props);
72
- return;
73
- }
74
- }
75
- drive(node.props.children, enqueueBy);
76
- };
77
- const makeFacade = (runtime, root, sink) => {
78
- // Slot bindings (`provide(slot, composition)`) are static, so resolve the
79
- // whole child tree once, up front — keeping `renderTree` and slot navigation
80
- // synchronous (no nested runtime drive).
81
- const bindings = new Map();
82
- // A slot's child is a plain composition or a `FeatureBinding`. A proof drives the
83
- // composition the feature mounts; for a `default` feature that composition's logic
84
- // is already live (its eager `.live` was merged into the scene by `provide`), so
85
- // unwrapping is all that's needed. (Driving a `lazy` feature — load gap +
86
- // placeholders — is the proof host's Part B increment; until then a scene wires
87
- // features as `default`, the eagerly-resolvable form.)
88
- const childComposition = (child) => isFeatureBinding(child) ? child.composition : child;
89
- const collect = (comp) => Effect.gen(function* () {
90
- for (const slotClass of Object.values(comp.manifest.slots ?? {})) {
91
- if (bindings.has(slotClass))
92
- continue;
93
- const child = childComposition(yield* slotClass.tag);
94
- bindings.set(slotClass, child);
95
- yield* collect(child);
96
- }
97
- });
98
- runtime.runSync(collect(root));
99
- // One breadth-first render of the whole tree. Each view reports its
100
- // `(props, events)` to the sink; each slot it renders enqueues a child (built
101
- // on the next level), so a single sweep renders everything.
102
- const renderLevel = (frontier) => Effect.gen(function* () {
103
- if (frontier.length === 0)
104
- return;
105
- const next = [];
106
- for (const { comp, props } of frontier) {
107
- const service = yield* comp.tag;
108
- // A slot renders to a deferred component (JSX `<slots.Item/>`); map each
109
- // back to the child it stands for so the tree walk can enqueue it.
110
- const enqueueBy = new Map();
111
- const slots = {
112
- slot: (name) => {
113
- const slotClass = comp.manifest.slots?.[name];
114
- const child = slotClass && bindings.get(slotClass);
115
- const component = () => null;
116
- if (child)
117
- enqueueBy.set(component, (childProps) => next.push({ comp: child, props: childProps }));
118
- return component;
119
- },
120
- };
121
- const env = { props, tracker: { add: () => { } }, slots };
122
- const node = yield* Composition.render(service, env);
123
- drive(node, enqueueBy);
124
- }
125
- yield* renderLevel(next);
126
- });
127
- const renderTree = Effect.gen(function* () {
128
- sink.reset();
129
- yield* renderLevel([{ comp: root, props: {} }]);
130
- });
131
- const capturesFor = (name) => sink.captures.filter((capture) => capture.name === name);
132
- // A cheap fingerprint of the rendered tree; when two successive renders match,
133
- // the engine has stopped producing new state and the read is safe.
134
- const fingerprint = () => JSON.stringify(sink.captures.map((capture) => [capture.name, capture.props]));
135
- // Re-render until the tree is stable for two consecutive renders, or give up.
136
- const settleFrom = (previous, remaining) => Effect.gen(function* () {
137
- if (remaining === 0)
138
- return;
139
- yield* settleDrain;
140
- yield* Effect.sleep(SETTLE_STEP);
141
- yield* renderTree;
142
- const current = fingerprint();
143
- if (current === previous)
144
- return;
145
- yield* settleFrom(current, remaining - 1);
146
- });
147
- const settle = Effect.gen(function* () {
148
- yield* settleDrain;
149
- yield* renderTree;
150
- yield* settleFrom(fingerprint(), SETTLE_MAX_RENDERS);
151
- });
152
- const triggerOf = (name, index, event) => {
153
- const trigger = capturesFor(name)[index]?.events[event];
154
- if (trigger === undefined) {
155
- throw new UnknownAction({ composition: name, action: event, rendered: capturesFor(name).length });
156
- }
157
- return trigger;
158
- };
159
- const nodeFacade = (name, index, comp) => ({
160
- props: Effect.map(renderTree, () => capturesFor(name)[index]?.props),
161
- // `keyed` resolves event/slot names at runtime; cast the string-keyed proxy
162
- // to the contract-typed surface. This is the one reflection boundary, the
163
- // same seam as `definitionClass` — every name the proxy serves is a real
164
- // contract member, so the cast is sound.
165
- actions: keyed((event) => (payload) => renderTree.pipe(Effect.flatMap(() => Effect.sync(() => triggerOf(name, index, event)(payload))), Effect.flatMap(() => settle))),
166
- slots: keyed((slotName) => slotFacade(comp, slotName)),
167
- frame: settle,
168
- });
169
- const slotFacade = (parent, slotName) => {
170
- const slotClass = parent.manifest.slots?.[slotName];
171
- const child = slotClass && bindings.get(slotClass);
172
- if (child === undefined) {
173
- throw new UnknownSlot({ parent: uiNameOf(parent), slot: slotName });
174
- }
175
- const childName = uiNameOf(child);
176
- const at = (index) => Effect.as(renderTree, nodeFacade(childName, index, child));
177
- const first = nodeFacade(childName, 0, child);
178
- return {
179
- first: at(0),
180
- at,
181
- all: Effect.map(renderTree, () => capturesFor(childName).map((_capture, index) => nodeFacade(childName, index, child))),
182
- // Used directly, a slot behaves as its first instance.
183
- props: first.props,
184
- actions: first.actions,
185
- slots: first.slots,
186
- frame: first.frame,
187
- };
188
- };
189
- return { facade: nodeFacade(uiNameOf(root), 0, root), settle };
190
- };
191
- /**
192
- * Run one proof against a fresh runtime, returning its pass/fail result. Each
193
- * proof gets its own isolated environment, so nothing leaks between proofs. Boots
194
- * the scene as the host would, settles, then runs the proof body to completion.
195
- */
196
- export const executeProof = async (proof) => {
197
- const sink = makeSink();
198
- const runtime = ManagedRuntime.make(proofLayer(proof.scene, sink));
199
- try {
200
- const { facade, settle } = makeFacade(runtime, proof.scene.composition, sink);
201
- await runtime.runPromise(Effect.forEach(proof.scene.boot ?? [], (event) => publish('High', event)).pipe(Effect.flatMap(() => settle)));
202
- await runtime.runPromise(Effect.gen(() => proof.body(facade)));
203
- return { requirement: proof.requirement.manifest.statement, ok: true };
204
- }
205
- catch (error) {
206
- return {
207
- requirement: proof.requirement.manifest.statement,
208
- ok: false,
209
- error: error instanceof Error ? error.message : String(error),
210
- };
211
- }
212
- finally {
213
- await runtime.dispose();
214
- }
215
- };
216
- /**
217
- * Drive one proof a step at a time, recording a `StepFrame` after each yielded
218
- * effect settles. Reuses the same makeFacade runtime/facade/settle as
219
- * `executeProof`, but instead of handing the body to `Effect.gen` (which runs it
220
- * to completion), it pumps the generator by hand — `gen.next(value)` yields the
221
- * next effect, we run it on the live runtime, snapshot the sink, and feed the
222
- * result back. So the editor gets the per-step timeline with no change to the
223
- * proof authoring API.
224
- */
225
- export const driveProof = async (proof) => {
226
- const sink = makeSink();
227
- const runtime = ManagedRuntime.make(proofLayer(proof.scene, sink));
228
- const frames = [];
229
- const statement = proof.requirement.manifest.statement;
230
- try {
231
- const { facade, settle } = makeFacade(runtime, proof.scene.composition, sink);
232
- await runtime.runPromise(Effect.forEach(proof.scene.boot ?? [], (event) => publish('High', event)).pipe(Effect.flatMap(() => settle)));
233
- frames.push({ index: 0, captures: [...sink.captures] });
234
- const generator = proof.body(facade);
235
- // Pump the generator: run each yielded effect on the runtime, snapshot, recur.
236
- const pump = async (input, index) => {
237
- const step = generator.next(input);
238
- if (step.done === true)
239
- return;
240
- const value = await runtime.runPromise(yieldWrapGet(step.value));
241
- frames.push({ index, captures: [...sink.captures] });
242
- await pump(value, index + 1);
243
- };
244
- await pump(undefined, 1);
245
- return { requirement: statement, frames, ok: true };
246
- }
247
- catch (error) {
248
- return {
249
- requirement: statement,
250
- frames,
251
- ok: false,
252
- error: error instanceof Error ? error.message : String(error),
253
- };
254
- }
255
- finally {
256
- await runtime.dispose();
257
- }
258
- };
259
- //# sourceMappingURL=engine.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACrD,OAAO,EACL,GAAG,EACH,WAAW,EAEX,WAAW,EAGX,gBAAgB,EAEhB,OAAO,GASR,MAAM,kBAAkB,CAAA;AAezB,yEAAyE;AACzE,+EAA+E;AAC/E,8EAA8E;AAC9E,iFAAiF;AACjF,+EAA+E;AAC/E,gFAAgF;AAChF,gFAAgF;AAChF,iFAAiF;AACjF,+EAA+E;AAC/E,iCAAiC;AACjC,MAAM,YAAY,GAAG,EAAE,CAAA;AACvB,MAAM,WAAW,GAAG,SAAS,CAAA;AAC7B,MAAM,kBAAkB,GAAG,GAAG,CAAA;AAE9B,wFAAwF;AACxF,MAAM,WAA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