reflex-quant 1.1.2 → 1.2.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.
package/README.md CHANGED
@@ -1,125 +1,515 @@
1
- # reflex-quant
1
+ <div align="center">
2
2
 
3
- An experiment: derive the smallest known reactive runtime implied by a
4
- frozen contract (semantic invariants and structural bounds, see
5
- [CONTRACT.md](CONTRACT.md)), and measure what is left. The contract was extracted
6
- from the executable spec of [Reflex](https://github.com/volynetstyle/Reflex)
7
- (provenance in [research/REPORT.md](research/REPORT.md)); it does not follow
8
- later changes of Reflex.
3
+ # ⚛ reflex-quant
9
4
 
10
- The runtime has three operational layers: the **kernel** owns the dependency
11
- machine (graph, tracking, propagation and validation); the **host** handles
12
- watcher lifecycle and delivery; and the **surface** exposes the typed API.
13
- Research instrumentation and development diagnostics are eliminated from the
14
- production build. The standalone ESM bundle is about 2.2 KB gzip.
5
+ **Reactive state in under 3 KB.**
6
+ Signals, computeds and effects that update exactly what changed, nothing more.
15
7
 
16
- - **Report:** [research/REPORT.md](research/REPORT.md). **Design log**, one
17
- counterexample per mechanism: [research/LOG.md](research/LOG.md).
18
- - **Textbook version:** branch
19
- [`padawan`](https://github.com/volynetstyle/reflex-quant/tree/padawan), the
20
- same semantics without the engineering (recursive push and pull, one
21
- exact index, no counters), written as a guided tour. It passes the same
22
- differential corpus; this branch is its lowering for speed and stack depth.
8
+ [![npm](https://img.shields.io/npm/v/reflex-quant?color=cb3837&label=npm)](https://www.npmjs.com/package/reflex-quant)
9
+ [![CI](https://github.com/volynetstyle/reflex-quant/actions/workflows/ci.yml/badge.svg)](https://github.com/volynetstyle/reflex-quant/actions/workflows/ci.yml)
10
+ [![types](https://img.shields.io/badge/types-included-3178c6)](#api-at-a-glance)
11
+ [![license](https://img.shields.io/npm/l/reflex-quant?color=blue)](LICENSE)
23
12
 
24
- ## Example
13
+ [**Website & live examples**](https://volynetstyle.github.io/reflex-quant/) ·
14
+ [How it works](https://volynetstyle.github.io/reflex-quant/reactive-runtime-anatomy/) ·
15
+ [Benchmarks](https://volynetstyle.github.io/reflex-quant/benchmarks/)
25
16
 
26
- A computation depends on exactly what its last run read, so dependencies
27
- change from run to run:
17
+ </div>
28
18
 
29
19
  ```ts
30
- import { computed, effect, get, set, signal } from "reflex-quant";
20
+ import { signal, computed, effect, get, set } from "reflex-quant";
31
21
 
32
- const full = signal(false);
22
+ const count = signal(0);
23
+ const doubled = computed(() => get(count) * 2);
24
+
25
+ effect(() => console.log(`count=${get(count)} doubled=${get(doubled)}`));
26
+ // count=0 doubled=0
27
+
28
+ set(count, 1); // count=1 doubled=2
29
+ set(count, 2); // count=2 doubled=4
30
+ ```
31
+
32
+ That covers most of it. You store values in **signals**, derive values with **computeds**, and react
33
+ to changes with **effects**. Quant tracks what each one reads, so you never
34
+ list dependencies by hand.
35
+
36
+ ## Why quant?
37
+
38
+ - 🪶 **Tiny.** About 2.7 KB min+gzip for the whole library, and no dependencies.
39
+ - 🎯 **Exact.** Dependencies are whatever the last run actually read. Take a
40
+ branch and the old dependencies drop away. Write a value that nothing
41
+ currently reads and nothing reruns.
42
+ - ⚡ **Fast.** Comparable to the fastest signal libraries on the
43
+ [benchmarks](#performance), and reordering dependencies allocates nothing.
44
+ - 🧱 **Stack-safe.** Updates travel through an explicit work stack instead of
45
+ recursion, so a 100 000-deep chain of computeds updates without overflowing
46
+ the call stack.
47
+ - 🔬 **Proven, not guessed.** Every mechanism in the runtime is backed by a test
48
+ that fails without it. Quant's invariants also found
49
+ [two real bugs in Vue's reactivity](#correctness).
50
+ - 🧩 **Framework-free.** Plain functions over plain values. You can use it in
51
+ Node, the browser, workers, or behind any UI layer.
52
+ - 🟦 **TypeScript-first.** Signals, computeds and effects are distinct types:
53
+ the compiler won't let you `set` a computed.
54
+
55
+ ## Install
56
+
57
+ ```sh
58
+ npm install reflex-quant
59
+ ```
60
+
61
+ ESM and CommonJS builds are included, along with type declarations. It needs Node.js 18+ or any modern browser.
62
+
63
+ ---
64
+
65
+ ## The 5-minute tour
66
+
67
+ ### 1. Signals hold values
68
+
69
+ ```ts
70
+ import { signal, get, set, update } from "reflex-quant";
71
+
72
+ const name = signal("Ada");
73
+
74
+ get(name); // "Ada"
75
+ set(name, "Grace"); // replace
76
+ update(name, (n) => n.toUpperCase()); // derive from current: "GRACE"
77
+ ```
78
+
79
+ ### 2. Computeds derive values, lazily and cached
80
+
81
+ A computed doesn't run until something reads it. It reruns only when a value it
82
+ read has changed.
83
+
84
+ ```ts
85
+ const price = signal(4);
86
+ const qty = signal(2);
87
+
88
+ let runs = 0;
89
+ const total = computed(() => {
90
+ runs++;
91
+ return get(price) * get(qty);
92
+ });
93
+
94
+ set(qty, 3);
95
+ set(qty, 5); // runs === 0: nobody asked yet
96
+
97
+ get(total); // 20, runs === 1
98
+ get(total); // 20, runs === 1: cached
99
+ ```
100
+
101
+ ### 3. Effects react to changes
102
+
103
+ An effect runs once right away, then again whenever something it read changes.
104
+ If it returns a function, quant calls that function before the next run and on
105
+ dispose. This is the place to clean up timers, listeners and subscriptions.
106
+
107
+ ```ts
108
+ import { effect, dispose } from "reflex-quant";
109
+
110
+ const room = signal("general");
111
+
112
+ const chat = effect(() => {
113
+ const r = get(room);
114
+ console.log("join", r);
115
+ return () => console.log("leave", r);
116
+ });
117
+ // join general
118
+
119
+ set(room, "random");
120
+ // leave general
121
+ // join random
122
+
123
+ dispose(chat);
124
+ // leave random
125
+ ```
126
+
127
+ ### 4. Dependencies follow your code
128
+
129
+ Quant doesn't use dependency arrays. Each run records exactly what it read,
130
+ so the dependencies change along with your `if` statements:
131
+
132
+ ```ts
133
+ const showFull = signal(false);
33
134
  const first = signal("Ada");
34
135
  const last = signal("Lovelace");
35
- const name = computed(() => (get(full) ? `${get(first)} ${get(last)}` : get(first)));
36
-
37
- effect(() => console.log(get(name))); // "Ada" name reads full, first
38
- set(last, "Byron"); // nothing runs: last was not read
39
- set(full, true); // "Ada Byron" name now reads last too
40
- set(full, false); // "Ada" last is dropped again
41
- set(last, "King"); // nothing runs
42
- ```
43
-
44
- When a computation reads the same sources in a different order, its
45
- existing relations are moved, not rebuilt: with 256 sources rotated every
46
- pass (`reorder.rotate-256`), quant creates and removes no relations per
47
- pass, where alien-signals relinks 255 (`node bench/structure.mjs`).
48
-
49
- ## Results
50
-
51
- - Equal to Reflex's executable spec, with three documented choices applied,
52
- on all 27,061 bounded and 18,660 recovery programs and on 100,000
53
- generated ones, with graph integrity checked after every operation.
54
- - Current Reflex is that contract plus three failure-path choices, on the
55
- same corpus. One of them drops an execution obligation that the contract
56
- (R2) says survives a failure.
57
- - All 34 mechanism ablations fail a test: 25 a semantic test, 8 only a
58
- structural bound or a representation test (the work an optimization saves, counted), 1 only a
59
- sibling-order test (a convention). The 7 ablations of the development
60
- diagnostic (C1) fail a test of the development build.
61
- - On CI (run 42287159440): within 25 % of the better of Reflex and
62
- alien-signals on all 18 scenarios, at or ahead of it on 8; geometric mean
63
- 0.97 of the better one, 0.95 of Reflex, 0.42 of alien-signals. Reorders
64
- allocate nothing. Reflex remains faster on every reorder scenario
65
- (quant 1.14–1.24 of it). The suite is this project's own; per-scenario
66
- numbers are in research/REPORT.md (Q6), the trajectory over every CI run
67
- in research/HISTORY.md.
68
-
69
- ## Surface
70
-
71
- Every operation exposes semantics the kernel and host already have; none adds
72
- a field, a flag or a branch on a hot path ([research/LOG.md](research/LOG.md) item 26).
73
-
74
- ```ts
75
- const a = signal(1);
76
- const total = computed((prev) => prev + get(a), 0); // prev: last committed value
77
- get(total); // refresh and observe
78
- peek(total); // refresh, do not observe
79
- set(a, 2);
80
- update(a, (v) => v + 1); // untracked fn, then set
81
- dispose(total); // detach; the value stays readable
82
- ```
83
-
84
- - `computed(fn, initial?)`: `prev` is the last **successfully committed** value
85
- (`initial` before the first commit; a failed run leaves it unchanged). It
86
- advances per execution, not per write: writes coalesced by a batch or by
87
- laziness are one step. Returning `prev` itself is a cutoff, so custom
88
- equality needs no comparator: `(prev) => (equal(prev, next) ? prev : next)`.
89
- Sources keep `Object.is`.
90
- - `peek(x)`: `get` without its tracking half; equal to
91
- `untracked(() => get(x))`, without the closure.
92
- - `update(s, fn)`: a write, not an observation. `fn` runs untracked, so
93
- neither `s` nor what `fn` reads becomes a dependency of the running
94
- consumer; if `fn` throws, nothing is written.
95
- - `effect(fn)`: if the call throws, it returns no handle and leaves nothing
96
- live; a cleanup its run returned has already run.
97
-
98
- ### Development build
99
-
100
- Bundlers that resolve the `development` export condition, and Node with
101
- `--conditions=development`, load `dist/index.development.js` (or `.cjs`). It
102
- diagnoses a precondition that the production build does not check (contract C1):
103
- a read or a validation that reaches a computed whose evaluation is in
104
- progress throws `Cycle detected`, instead of answering with the computed's
105
- previous value. Such a demand comes from a cycle, or from a write inside a
106
- computed whose synchronous effects read back into it. The production build
107
- pays nothing for the diagnosis; the release check verifies the split.
108
-
109
- ## Layout
136
+
137
+ const displayName = computed(() =>
138
+ get(showFull) ? `${get(first)} ${get(last)}` : get(first),
139
+ );
140
+
141
+ effect(() => console.log(get(displayName))); // "Ada"
142
+
143
+ set(last, "Byron"); // (nothing: `last` isn't being read right now)
144
+ set(showFull, true); // "Ada Byron"
145
+ set(showFull, false); // "Ada"
146
+ set(last, "King"); // (nothing again)
147
+ ```
148
+
149
+ ### 5. No glitches, no duplicate runs
150
+
151
+ When two computeds share a source, the effect still runs **once**, and it
152
+ never sees a half-updated state:
153
+
154
+ ```ts
155
+ const first = signal("Ada");
156
+ const last = signal("Lovelace");
157
+ const upper = computed(() => get(first).toUpperCase());
158
+ const initials = computed(() => get(first)[0] + get(last)[0]);
159
+
160
+ effect(() => console.log(`${get(upper)} (${get(initials)})`));
161
+ // ADA (AL)
162
+
163
+ set(first, "Grace");
164
+ // GRACE (GL) (one run, both values already fresh)
165
+ ```
166
+
167
+ ### 6. Unchanged results stop propagation
168
+
169
+ If a computed recalculates and gets the same value, everything downstream stays
170
+ put:
171
+
172
+ ```ts
173
+ const n = signal(1);
174
+ const parity = computed(() => (get(n) % 2 === 0 ? "even" : "odd"));
175
+
176
+ effect(() => console.log(get(parity))); // "odd"
177
+
178
+ set(n, 3); // (nothing: still "odd")
179
+ set(n, 4); // "even"
180
+ ```
181
+
182
+ Writing the same value to a signal is also a no-op (compared with `Object.is`).
183
+
184
+ ### 7. Batch several writes into one update
185
+
186
+ ```ts
187
+ import { batch } from "reflex-quant";
188
+
189
+ const x = signal(0);
190
+ const y = signal(0);
191
+ effect(() => console.log(`(${get(x)}, ${get(y)})`)); // (0, 0)
192
+
193
+ batch(() => {
194
+ set(x, 10);
195
+ set(y, 20);
196
+ }); // (10, 20) (one run, not two)
197
+ ```
198
+
199
+ ### 8. Read without subscribing
200
+
201
+ `peek` gives you an up-to-date value without making it a dependency.
202
+ `untracked` does the same for a whole block of code.
203
+
204
+ ```ts
205
+ import { peek, untracked } from "reflex-quant";
206
+
207
+ const query = signal("cats");
208
+ const page = signal(1);
209
+
210
+ effect(() => console.log(`search "${get(query)}" page ${peek(page)}`));
211
+ // search "cats" page 1
212
+
213
+ set(page, 2); // (nothing: page was only peeked)
214
+ set(query, "dogs"); // search "dogs" page 2
215
+ ```
216
+
217
+ ---
218
+
219
+ ## Recipes
220
+
221
+ <details open>
222
+ <summary><b>🛒 Shopping cart</b></summary>
223
+
224
+ ```ts
225
+ const items = signal([
226
+ { name: "Coffee", price: 4, qty: 2 },
227
+ { name: "Bagel", price: 3, qty: 1 },
228
+ ]);
229
+ const discount = signal(0);
230
+
231
+ const subtotal = computed(() =>
232
+ get(items).reduce((sum, i) => sum + i.price * i.qty, 0),
233
+ );
234
+ const total = computed(() => get(subtotal) * (1 - get(discount)));
235
+
236
+ effect(() => console.log(`Total: $${get(total).toFixed(2)}`));
237
+ // Total: $11.00
238
+
239
+ update(items, (list) => [...list, { name: "Juice", price: 5, qty: 1 }]);
240
+ // Total: $16.00
241
+
242
+ set(discount, 0.1);
243
+ // Total: $14.40
244
+ ```
245
+
246
+ </details>
247
+
248
+ <details>
249
+ <summary><b>✅ Todo list with a filter</b></summary>
250
+
251
+ ```ts
252
+ const todos = signal([
253
+ { text: "Write README", done: true },
254
+ { text: "Ship 1.2.0", done: false },
255
+ ]);
256
+ const filter = signal<"all" | "open" | "done">("all");
257
+
258
+ const visible = computed(() => {
259
+ const f = get(filter);
260
+ if (f === "all") return get(todos);
261
+ return get(todos).filter((t) => t.done === (f === "done"));
262
+ });
263
+ const left = computed(() => get(todos).filter((t) => !t.done).length);
264
+
265
+ effect(() =>
266
+ console.log(`${get(visible).map((t) => t.text).join(", ")} | ${get(left)} left`),
267
+ );
268
+ // Write README, Ship 1.2.0 | 1 left
269
+
270
+ set(filter, "open");
271
+ // Ship 1.2.0 | 1 left
272
+
273
+ update(todos, (list) => list.map((t) => ({ ...t, done: true })));
274
+ // | 0 left
275
+ ```
276
+
277
+ </details>
278
+
279
+ <details>
280
+ <summary><b>⏱ Debounced search</b> (with effect cleanup)</summary>
281
+
282
+ ```ts
283
+ const query = signal("");
284
+
285
+ effect(() => {
286
+ const q = get(query);
287
+ const id = setTimeout(() => fetchResults(q), 300);
288
+ return () => clearTimeout(id); // a new keystroke cancels the previous timer
289
+ });
290
+
291
+ set(query, "r");
292
+ set(query, "re");
293
+ set(query, "reflex"); // only "reflex" is fetched
294
+ ```
295
+
296
+ </details>
297
+
298
+ <details>
299
+ <summary><b>🖱 Binding to the DOM</b> (no framework)</summary>
300
+
301
+ ```ts
302
+ const count = signal(0);
303
+ const button = document.querySelector("button")!;
304
+
305
+ button.addEventListener("click", () => update(count, (n) => n + 1));
306
+
307
+ effect(() => {
308
+ button.textContent = `Clicked ${get(count)} times`;
309
+ });
310
+ ```
311
+
312
+ </details>
313
+
314
+ <details>
315
+ <summary><b>💾 Persisting to localStorage</b></summary>
316
+
317
+ ```ts
318
+ const theme = signal(localStorage.getItem("theme") ?? "light");
319
+
320
+ effect(() => localStorage.setItem("theme", get(theme)));
321
+
322
+ set(theme, "dark"); // saved
323
+ ```
324
+
325
+ </details>
326
+
327
+ <details>
328
+ <summary><b>🎛 Custom equality</b> (skip updates that don't matter)</summary>
329
+
330
+ A computed receives its previous value. If you return that same object,
331
+ dependents treat the result as unchanged and don't rerun, so you don't need a
332
+ separate comparator option:
333
+
334
+ ```ts
335
+ type Cell = { col: number; row: number };
336
+ const mouse = signal({ x: 0, y: 0 });
337
+
338
+ const cell = computed((prev: Cell | undefined) => {
339
+ const { x, y } = get(mouse);
340
+ const next = { col: Math.floor(x / 100), row: Math.floor(y / 100) };
341
+ return prev && prev.col === next.col && prev.row === next.row ? prev : next;
342
+ });
343
+
344
+ effect(() => console.log(get(cell))); // { col: 0, row: 0 }
345
+
346
+ set(mouse, { x: 10, y: 20 }); // (nothing: same cell)
347
+ set(mouse, { x: 150, y: 20 }); // { col: 1, row: 0 }
348
+ ```
349
+
350
+ </details>
351
+
352
+ ---
353
+
354
+ ## API at a glance
355
+
356
+ | Function | What it does |
357
+ | ------------------------ | --------------------------------------------------------------------------------------------- |
358
+ | `signal(value)` | Create a writable value. |
359
+ | `computed(fn, initial?)` | Create a lazy, cached derived value. `fn(prev)` receives the last committed value. |
360
+ | `effect(fn)` | Run `fn` now and again on every change it read. `fn` may return a cleanup function. Returns a handle. |
361
+ | `get(x)` | Read a signal or computed and **subscribe** the current computation to it. |
362
+ | `peek(x)` | Read the up-to-date value **without** subscribing. |
363
+ | `set(s, value)` | Write a signal. Ignored if `Object.is(old, value)`. |
364
+ | `update(s, fn)` | `set(s, fn(current))`. `fn` runs untracked. If it throws, nothing is written. |
365
+ | `batch(fn)` | Run `fn`, then deliver all its writes as a single update. Returns `fn`'s result. |
366
+ | `untracked(fn)` | Run `fn` without subscribing to anything it reads. |
367
+ | `dispose(x)` | Stop an effect (running its cleanup) or detach a computed (its last value stays readable). |
368
+ | `typeOf(x)` | `"signal"`, `"computed"` or `"effect"`, without evaluating anything. |
369
+
370
+ > **Why `get(count)` and not `count()` or `count.value`?** Here the handle *is*
371
+ > the reactive node. Quant allocates no wrapper object or getter closure, so
372
+ > each signal costs one object.
373
+
374
+ ## Good to know
375
+
376
+ **Replace values, don't mutate them.** Quant compares values with `Object.is`.
377
+ If you push into the same array, the array reference doesn't change, so nothing
378
+ updates:
379
+
380
+ ```ts
381
+ update(todos, (list) => { list.push("eggs"); return list; }); // ❌ no update
382
+ update(todos, (list) => [...list, "eggs"]); // ✅ updates
383
+ ```
384
+
385
+ **`prev` advances once per run, not once per write.** Computeds are lazy, so
386
+ several writes made before anyone reads collapse into a single run:
387
+
388
+ ```ts
389
+ const clicks = signal(0);
390
+ const history = computed((prev) => [...prev, get(clicks)], [] as number[]);
391
+
392
+ set(clicks, 1);
393
+ set(clicks, 2);
394
+ get(history); // [2] (1 was never observed)
395
+ ```
396
+
397
+ If you need every write, append to the log in the code that does the writing,
398
+ not in a computed.
399
+
400
+ **Errors don't break the graph.** If a computed throws, `get` rethrows the error
401
+ and the computed keeps its last good value as `prev`. Once its inputs are fixed,
402
+ it recovers on the next read. If an effect throws during creation, it leaves
403
+ nothing running.
404
+
405
+ **Use the development build to catch cycles.** Bundlers that resolve the
406
+ `development` export condition (Vite, webpack, and Node with
407
+ `--conditions=development`) load a build that throws `Cycle detected` when a
408
+ computed ends up reading itself. The production build skips this check and
409
+ costs nothing extra.
410
+
411
+ ## When to use something else
412
+
413
+ Quant is deliberately a **core**: values, derivations, reactions. It doesn't
414
+ include:
415
+
416
+ - deep reactive objects or proxies (`store.user.name = …`),
417
+ - async resources or suspense,
418
+ - component lifecycles or ownership scopes (`effectScope` and similar),
419
+ - a renderer.
420
+
421
+ Each of these can be built on top of quant. None of them is included, because
422
+ the [contract](CONTRACT.md) doesn't require them. If you need them out of the box, a
423
+ full framework (Vue, Solid, Preact Signals, MobX) is a better fit.
424
+
425
+ ---
426
+
427
+ ## Performance
428
+
429
+ Measured on CI against [Reflex](https://github.com/volynetstyle/Reflex) and
430
+ [alien-signals](https://github.com/stackblitz/alien-signals), with all three
431
+ runtimes on the same runner
432
+ ([run 42794143933](https://github.com/volynetstyle/reflex-quant/actions/runs/42794143933), quant 1.1.2):
433
+
434
+ - within 25 % of the faster of the two on **17 of 18** scenarios, and faster than both on **7**;
435
+ - geometric mean: **0.99×** Reflex, **0.45×** alien-signals (lower is faster);
436
+ - reorders allocate nothing. If a computation reads the same 256 sources in a
437
+ rotated order on every pass, quant creates and removes **0** links per pass
438
+ where alien-signals relinks 255 (`node bench/structure.mjs`);
439
+ - Reflex is still faster on the reorder scenarios (quant 1.20–1.21× of it) and on
440
+ `value-sort.256x32` (1.43×).
441
+
442
+ The suite is this project's own. Per-scenario numbers are on the
443
+ [benchmarks page](https://volynetstyle.github.io/reflex-quant/benchmarks/), and the
444
+ trajectory over CI runs is in [research/HISTORY.md](research/HISTORY.md).
445
+
446
+ ## Correctness
447
+
448
+ Quant is also a research project. It asks: what is the **smallest** reactive
449
+ runtime that satisfies a fixed contract? The contract is a set of semantic invariants and structural bounds in
450
+ [CONTRACT.md](CONTRACT.md). It was extracted from the executable spec of
451
+ [Reflex](https://github.com/volynetstyle/Reflex)
452
+ (provenance in [research/REPORT.md](research/REPORT.md)). A mechanism is added
453
+ only if dropping it would break the contract or the asymptotics.
454
+
455
+ - **It found real bugs in Vue.** A port of quant's invariants to Vue 3.6 exposed
456
+ two regressions in its Alien-derived reactivity core, both also reproducible
457
+ in `alien-signals` 3.2.0. One was a lost update
458
+ ([vuejs/core#16174](https://github.com/vuejs/core/issues/16174)). The other was
459
+ generational-GC retention through removed links
460
+ ([vuejs/core#16176](https://github.com/vuejs/core/issues/16176)). Both are
461
+ now fixed upstream with permanent regression tests
462
+ ([#16210](https://github.com/vuejs/core/pull/16210),
463
+ [#16211](https://github.com/vuejs/core/pull/16211)).
464
+ - **Differentially tested.** Quant gives the same answers as Reflex's executable
465
+ spec, with three documented choices applied, on all 27 061 bounded and
466
+ 18 660 recovery programs and on 100 000 generated ones. Graph integrity is
467
+ checked after every operation.
468
+ - **Nothing is optional.** Removing any of the 34 mechanisms makes a test fail:
469
+ 25 fail a semantic test, 8 fail only a structural-bound or representation test,
470
+ and 1 fails only a sibling-order test (a convention). All 7 ablations of the
471
+ development diagnostic fail a test of the development build.
472
+ - Current Reflex is the same contract plus three failure-path choices. One of
473
+ them drops an execution obligation that the contract (R2) says survives a
474
+ failure.
475
+
476
+ Read more: the [report](research/REPORT.md), the
477
+ [design log](research/LOG.md) (one counterexample per mechanism), and the
478
+ [`padawan`](https://github.com/volynetstyle/reflex-quant/tree/padawan) branch.
479
+ That branch has the same semantics without the engineering (recursive push and pull,
480
+ no counters), written as a guided tour, and it passes the same differential corpus.
481
+
482
+ ## Under the hood
483
+
484
+ The runtime has three layers:
485
+
486
+ - **kernel**: the dependency machine (graph, tracking, propagation, validation);
487
+ - **host**: effect lifecycle and delivery;
488
+ - **surface**: the typed public API. It is a thin layer: no operation adds a field,
489
+ a flag or a branch on a hot path ([research/LOG.md](research/LOG.md) item 26).
490
+
491
+ The production build strips research instrumentation and development
492
+ diagnostics. The illustrated
493
+ [anatomy page](https://volynetstyle.github.io/reflex-quant/reactive-runtime-anatomy/)
494
+ walks through each part.
110
495
 
111
496
  ```text
112
- src/ graph representation, kernel machine, host, public surface, instrumentation
497
+ src/ graph representation, kernel, host, public surface, instrumentation
113
498
  test/ differential (spec, contract spec, Reflex, quant), tracking,
114
499
  semantics, structural bounds; tools/ (QUANT_TOOLS=1)
115
500
  bench/ scenarios, adapters, build, timing (CI only), structure counters
116
- research/ evidence, design log, ablations, and historical benchmark snapshots
501
+ research/ evidence, design log, ablations, historical benchmark snapshots
117
502
  reference/ frozen Reflex implementation and provenance fixtures
503
+ site/ the website (Astro)
118
504
  ```
119
505
 
120
- ## Running
506
+ <details>
507
+ <summary><b>Contributing: build, test and benchmark</b></summary>
121
508
 
122
- For development, use Node.js 20.19 or later in the 20.x line, 22.13 or later in the 22.x line, or 24+ and npm (the published library supports Node.js 18+). Install this repository's dependencies with `npm ci`; the Reflex sources, spec harness and fixed production baseline used by the tests and benchmarks are included in `reference/reflex` and do not require a Reflex checkout. From this directory:
509
+ Development (including the site) uses Node.js 22.23.4 (see `.nvmrc`) or 24+
510
+ and npm. The published library supports Node.js 18+. Run `npm ci` to install.
511
+ The Reflex sources, spec harness and fixed production baseline live in
512
+ `reference/reflex`, so you don't need a Reflex checkout.
123
513
 
124
514
  ```sh
125
515
  npm run lint # lint production TypeScript
@@ -141,4 +531,32 @@ node bench/cost/build.mjs && node bench/cost/run.mjs regime --rounds 0
141
531
  # cost-model probes (research/COST-MODEL.md); timing on CI
142
532
  ```
143
533
 
144
- CI is split in two workflows. `.github/workflows/ci.yml` runs lint, typecheck/release build and tests as parallel jobs. `.github/workflows/benchmark.yml` builds and checksum-verifies the bundles once, then runs in parallel one timing job per mechanism (`bench/mechanisms.mjs`), the graph scenarios (`bench/scenarios.mjs`) in shards, the structural counters and the edge-churn probe. Each timing job runs all three runtimes on one runner: compare ratios within a job, never times across jobs. The Reflex benchmark baseline is fixed at commit `bf71877`; see `reference/reflex/README.md` for its provenance.
534
+ CI runs on Windows, macOS and Linux with Node 22.23.4 and 24. Each matrix job
535
+ checks declarations, release artifacts, development and production tests, cost
536
+ probe verification, and the site. Dependencies are installed from both lockfiles
537
+ with `npm ci` (root and `site/`).
538
+
539
+ `npm run check:bench` builds every cost probe and runs it in verification mode,
540
+ including the independent leaf and decomposition cells, without collecting timings.
541
+ `npm run check:bench -- --smoke` limits this to leaf and decomposition.
542
+ `npm run check:site` builds the runtime and bench bundles, compares the site's
543
+ visualizations with the runtime, builds Astro, and checks the generated internal
544
+ page and asset URLs under the deployment base. Install site dependencies first
545
+ with `npm ci --prefix site`.
546
+
547
+ `.github/workflows/benchmark.yml` verifies all cost probes before any timing job
548
+ starts, and it shares the verified bundles. Each timing job runs all three
549
+ runtimes on one runner: compare ratios within a job, never times across jobs.
550
+ Pages deployment uploads only a site that passed its checks. The Reflex
551
+ benchmark baseline is fixed at commit `bf71877`; see
552
+ `reference/reflex/README.md` for its provenance.
553
+
554
+ Before proposing a change to the runtime, read [AGENTS.md](AGENTS.md) and
555
+ [ARCHITECTURE.md](ARCHITECTURE.md). They describe the inclusion criterion
556
+ a new mechanism has to meet.
557
+
558
+ </details>
559
+
560
+ ## License
561
+
562
+ [MIT](LICENSE) © Andrii Volynets