* fix(expression): copy values that read the node's own output on the compiled path
* fix(expression): match a date against every text cell naming it
* test(engine): cover the fixed version differences on every evaluation path
* fix(engine): keep the table index and compiled plan off tables whose cells read the last tested value
* fix(engine): give batch rows the node values and replaced fields a single row sees
* test(engine): cover the batch and table differences on every evaluation path
* fix(engine): read declared date inputs in the evaluation's time zone
* fix(engine): keep script dates right beyond 2099, at extreme years and for object arguments
* fix(engine): name script modules alike on every traced batch row
* fix(expression): keep typed batch results and errors equal to the row engine
* fix(engine): keep loop items, traced table fields and batch node values equal to version 1
* fix(engine): record table references in batch traces when a rule has a description
* fix(nodejs): convert decision results, policy traces and handler values without aborting on large integers
* fix(nodejs): reject fractional engine versions
* test(engine): cover null leaves in multi-row batches
* fix(engine): keep a null written under a missing or scalar parent in multi-row batches
A layer over an upstream patched shape treated every null leaf as absent,
so obj.a = null over a row without obj (or with obj = 1) never created
{obj: {a: null}} for downstream reads, and an all-null column was dropped
outright. A dotted null leaf now stays present on the rows whose parent
is not an object before the write, matching version 1's merge.
* fix(engine): merge a parent reached by duplicate edges once in multi-row batches
Version 1 merges a node's output onto itself as a no-op when two edges
from the same node meet at a target, so nested nulls survive. The batch
path gathered the parent twice as separate copies and re-applied the
patch, deleting those nulls and letting a dangling node's value win over
a null written on the twice-connected branch. Consecutive duplicate
parents now merge once.
* fix(engine): let a later table output replace an earlier one under it in batches
A rule writing res, res.k and then res again keeps only the last res in
version 1, because the final write replaces the object that res.k went
into. The compiled table folded the duplicate paths into one slot per
path and re-inserted res.k on top. Non-collect outputs that a later
non-collect output of the same rule replaces are now left out.
* fix(engine): share common ancestry when batch rows merge related parents
Version 1 merges parent outputs copy-on-write: a pass-through node shares
every subtree it did not change with its input, and merging two values
that share an object skips it. So a nested null written once and reached
through two branches survives the join, and an input null survives a
pass-through that changed nothing. The batch path rebuilt each parent's
rows separately, lost that sharing and deleted those nulls. When parents
share a base or leading layers and the merged parent can hold a null,
the join now derives their rows from the shared prefix with the same
copy-on-write merge; other joins stay columnar. Traced batch rows derive
pass-through outputs from their merged input the same way.
* fix(engine): keep one materialization per node so batch joins see shared rows
Gathering a node's rows for each consumer, and clearing a table's
unmatched rows before a pass-through, materialized the same node output
more than once, so a pass-through built from one copy no longer shared
objects with the copy merged at the join, and the version 1 rule that a
shared object merges as a no-op could not apply. Gathered copies of a
node on the same rows now share one materialization, a cleared copy
reuses its source's rows, layers keep their identity when picked to a
row subset, and input rows match by object identity. The final output
still materializes its own copy, since cleaning it mutates in place.
* test(engine): cover policy columns for a tested value that fails
* fix(engine): return column traces in the legacy format when it is requested
* fix(engine): return an error instead of building a cyclic value when an expression entry writes an object into itself on version 2
An entry such as `a.c = obj` after `a = obj` wrote the object into itself,
and merging, cloning, comparing, tracing or serialising the result then
overflowed the stack. The hosted expression node now checks, before each
write, whether the value reaches the object it is written into and fails the
row with "cyclic value at <key>". Compiled nodes that write a possibly
container value under a key an earlier entry set are routed through the same
row evaluation, so every path (first call, repeated, compiled, batch,
columnar, traced) reports the error for that row only.
* test(engine): cover a script returning a cyclic object on version 2
Ignored until the version 2 JS runtime rejects cyclic results; it hangs today.
* fix(engine): match version 1 in script globals and dates, stop idle or cyclic scripts, and load date support lazily
* fix(engine): leave version 1 table indexes as released and give version 2 its own
* fix(engine): show the tested value under its key when a table reads the whole root
* fix(engine): copy values read through $ and leave written-back keys alone, as version 1 merges them
* perf(engine): keep tables whose outputs read the tested value on the compiled plan
* test(engine): record pinned Date results across zones, DST gaps and far years
* perf(engine): pin Date in Rust instead of a JavaScript shim on version 2
Function nodes on version 2 replaced Date with a JavaScript module whose
local getters, setters and string methods rebuilt every field through
native calls and allocations, and whose lazy half cost about 45 us to
load on the first Date use of each evaluation.
The pinned constructor, Date.now, Date.parse, Math.random and the zone
dependent prototype methods are now callable Rust classes built with the
safe rquickjs API. They read the time value through the native getTime,
compute fields and offsets with chrono-tz in Rust (fixed offset zones
skip the lookup, the last instant's fields are cached per evaluation)
and keep QuickJS's Date for storage and everything zone independent.
The constructor is a bound function so calls and constructions are
told apart exactly. The prototype methods are still installed on the
first construction or parse, now in about 6 us.
Results are unchanged: recorded per-zone results, version parity and
the isolation spec pass as before.
* fix(engine): keep the machine time zone out of parsed script dates
* feat(engine): select the engine with a version option
* ci: run the two feature sets as parallel jobs
* refactor(engine): drop the global compiled switch
* feat(engine): pin the clock through options instead of the environment
The __ZEN_MOCK_UTC_TIME variable and the ZEN_EXPRESSION_CONFIG lane flag are
gone. Isolate takes with_now and with_lane, and the interpreted engine now
honours the now option in expressions, so tests pass the instant explicitly.
* test(engine): count trace paths per thread and drop the trace test lock
* ci: run tests with nextest
* test(engine): share golden trace outcomes between variants
* feat(trace): trace format v1 with TraceCollector on the compiled engine
Adds trace format v1 to the compiled engine, recorded by explicit trace
recorders and written natively. The interpreted engine keeps the legacy
trace.
- EvaluationOptions.trace is a TraceFormat (off, v1, legacy). Legacy
traces are produced directly from the same recording.
- zen_engine::trace exposes convert, restore and inspect for
stored documents, with redaction and truncation markers.
- The trace header takes evaluatedAt, timezone and seed from the
evaluation context, so an evaluation replays from its own trace.
- Batch and columnar evaluations record events as columns and write one
document per row.
- Bindings accept the trace format (true, 'v1', 'legacy'); the Node
binding ships TypeScript types for the v1 document.
- Golden, fixture and damaged-document tests cover byte identity with the
legacy trace, restore, interop with the reference fixtures and
malformed input.
* perf(trace): build columnar request rows once with precomputed paths
* perf(trace): write a node's edits from its written columns
* perf(trace): capture node columns instead of row values in the columnar plan
* perf(trace): reuse a node's rendered body for rows with the same rule and cell values
* perf(trace): size the batch trace buffer up front, key node bodies on typed column words, share request rows as the input
* perf(trace): read the request from input columns and build request rows only on demand
* perf(trace): key node bodies on per-column codes and precompute node heads and result labels
* perf(trace): keep first-hit table facts and their referenced fields as columns
* perf(trace): write per-row expression results in the batch writer
* perf(columnar): write result rows as JSON straight from output columns
* perf(trace): keep collect-policy rule hits as columns and reuse hit text
* perf(trace): pack loop results from columns and resolve result column accessors once per batch
* perf(trace): share row-wise node outputs with the trace when nothing can alias them
* perf(trace): pack lists without a string per distinct item
* perf(trace): write new lists from columns and decide references by where a list came from
* perf(trace): write wide list items from columns while the list has never been built
* perf(trace): read list cells once while rendering
* feat(trace): list table inputs once per node and key rule cells by column id
* feat(trace): name matched policy table rows by rule id
* feat(trace): store loop results as one column per key
* build: optimise test builds
* feat(engine): explicit evaluation context with now, timezone and seed
The compiled engine evaluates against an explicit EvaluationContext
instead of the host clock, host zone and an unseeded random source.
- zen_expression::context: EvaluationContext holds now (read once on
first use, shared by every row of a batch), the time zone (supplied
or the host zone cached per process), the locale, the seed (drawn on
the first draw) and per-row and per-item random streams created only
when a row or item draws. rows/picked/items/item/at narrow it with an
Rc clone; at and item allocate nothing. RowContext is the borrowed
per-row view builtins, kernels and function hosts read.
- the context is passed explicitly through the lane VM (LaneRunner,
Session, kernels, cells, builtins), typed Program::run, graph state,
rows, loops, sub-decisions, hosted rows, the columnar plan, policies
and their plans. There are no thread-locals for context data.
- rand draws once per lane, row and item from the row's stream, so
map(xs, rand(100)) draws per item. rand is never pure, folded,
memoised or compiled into kernels as a constant; Math.random is no
longer pure in the function purity analysis.
- function hosts (v1 and v2) install Date, Math.random and a minimal
Intl.DateTimeFormat once per runtime and read a per-call slot:
Date.now, new Date, local-time getters and setters, toString,
toLocale*String and getTimezoneOffset use the context's now, zone and
locale.
- EvaluationOptions and EvaluationSerializedOptions gain now, timezone,
seed and locale (en-US by default). Workspace gains evaluate_pinned,
evaluate_batch_pinned and evaluate_columns_pinned. In a batch, row i
draws with row_seed(seed, i) and replays alone with that seed.
- bindings: Node and Python accept and validate now, timezone, seed and
locale; C and uniffi pass them through and ignore invalid values.
- d('...') is folded at compile time only for texts with an explicit
zone; an invalid __ZEN_MOCK_UTC_TIME is ignored by the context.
- the interpreted engine and the stack VM are unchanged and ignore the
new options.
* refactor(engine): name evaluation context parameters ctx and context
* feat(engine): derive random draws from their location
A draw is now a pure function of (seed, stream, scope, field, site, n)
instead of a running counter per stream, so reordering, short-circuiting,
dead-code elimination or an extra rand elsewhere in a decision no longer
shifts other draws.
- site: occurrence index of rand( in source order, numbered at compile
time and carried on the lane call op
- field: stable label from node/rule/column/key/statement/block ids,
baked into multi-root programs at compile time or set on the context
by per-source (session) paths
- scope: chained per sub-decision call (caller node + key) and per
function node; JS Math.random uses a fixed site in that scope
- n: counter per (stream, address) for repeated evaluation only
Tables with draws run on the exact row path; fused cells and fused rules
refuse draws; object-literal expansion is skipped for drawing sources.
* refactor(expression): own the rand integer mapping
Map a draw to 0..=upper with Lemire multiply-shift and rejection, taking
further words from the same address on retry, so a dependency update can
never change rand(n) for a given seed. A negative upper bound now returns
"Invalid upper range" on both VMs instead of panicking, and the unseeded
root seed comes from a hashed counter, which drops fastrand.
* test(engine): keep evaluation context tests independent under cargo test
cargo test runs a crate's tests as threads of one process, so tests that
share process state raced:
- pinned.rs switched the global ZEN_CONFIG.compiled on and off; each
decision now picks its engine with compiled_engine() / interpreted().
- clock_reads() counted reads from every thread; it now counts the
current thread only.
- typed exact tests relied on __ZEN_MOCK_UTC_TIME, which is cached on the
first clock read by any test; they now pin now in the context.
* ci: pin Rust 1.99 for the Windows Node and UniFFI builds
Rust 1.100 makes Cargo's new build-dir layout permanent: every
dependency gets its own directory and its own -L dependency= flag.
For zen-engine with --target x86_64-pc-windows-msvc the rustc command
line passes Windows' 32,767-character limit, and sccache fails to spawn
rustc with os error 206. Cargo itself falls back to an argument file,
but sccache does not.
Other matrix entries stay on stable. Remove the pin once sccache
handles long command lines.
* refactor(engine): remove locale from the evaluation context
The locale option did not make evaluations more reproducible: QuickJS has
no ICU, so function nodes never picked up a host locale. It only added
approximate locale-aware date formatting from a hand-written table, as new
public API in every binding.
Function nodes keep the time zone of the context. toLocaleString,
toLocaleDateString and toLocaleTimeString return QuickJS's fixed format in
that zone and ignore a locale argument, as before. Intl is reduced to
DateTimeFormat().resolvedOptions(), which reports the time zone.
Drops the icu_locale_core dependency.
* test(engine): compare interpreted draws with the pinned ones
The interpreted engine's Math.random is QuickJS's own, seeded from the
clock in microseconds when a context is created. On Windows the clock is
coarser, so two evaluations in a row can get the same seed and the same
numbers. Assert instead that the interpreted engine does not return the
compiled engine's draws for the same seed.
napi 3.14 decodes a class reference only inside a native borrow scope, which a resolved loader promise does not have, so every loader returning ZenDecisionContent failed with "Value is none of these types". Decode the loader result into LoadedDecision, which copies the content Arc while the JS object is alive and keeps buffers for parsing off the JS thread.
* build(nodejs): declare the wasm32-wasip1 package as an optional dependency
cli 3.10 drops WASI packages from the root optionalDependencies when native targets exist, which would leave browser.js importing an uninstalled package. Ignore and clear the root facades pre-publish now generates.
* build(nodejs): keep the root package free of the threadless wasm facade
napi prepublish copies the 15.6MB wasm into the root package and rewrites files and exports for workerd consumers. Run it through prepublish.mjs, which keeps its optionalDependencies but restores files and exports and removes the generated root files, so the root tarball is back to ~20kB.
* feat(nodejs): replace the threaded wasm build with threadless wasm32-wasip1
The browser binding no longer needs SharedArrayBuffer or cross-origin isolation. napi moves to 3.14 / cli 3.10.8 with emnapi 2.0.0-alpha.6; the wasm build registers napi-async-runtime's current-thread backend and spawns each evaluation as a runtime task. console.sleep goes through a sleep provider so the wasm build waits on the host timer instead of tokio. CI and the Makefile build and publish @gorules/zen-engine-wasm32-wasip1 in place of the threaded package.
* ci(nodejs): test the wasm32-wasip1 binding and load test binaries in place
cli 3.10 rejects napi artifacts when any configured target is missing, so test jobs download their binary next to index.js instead of building npm dirs. A wasm test job runs the suite against the threadless binding and gates the release.
* chore(nodejs): stop tracking generated wasip1 loaders
napi build writes them alongside the wasm and CI ships them through the wasm artifact, like index.d.ts.
* ci(nodejs): build the glibc legs with cargo zigbuild directly
cli 3.10 runs cargo metadata with the requested target, which rejects the zigbuild glibc suffix. Matches the go and uniffi workflows.
* build(nodejs): keep dev dependencies installable on node 20
@octokit/request 10.0.16 (via @napi-rs/cli) pulls content-type 3, which requires node 22; pin the cli's copy to 10.0.14.
- graph input and output validation treats null optional properties as
absent (including inside anyOf/oneOf objects) and reports the real
error when validation still fails
- remove the NULLABILITY_DIVERGENCE diagnostic
- policies enforce required inputs also without goals; a path is missing
when absent or null unless a step along it is optional, checked after
reference hydration, and computed entity fields are not inputs
* feat: implement slots instead of natural language
Replace the natural-language projection (`nl`) with engine-owned slot
completion: for a cursor position the engine classifies the slot being
edited (operand, operator, literal, member access, ...) and returns typed
options, literal facts and the expected type, for policies and graphs.
- zen-expression: new `slot` module (classification, literals, operators)
and a lenient lexer mode for incomplete input; `nl` removed
- Intellisense: typed diagnostic codes with arguments, richer inspect for
hover, dedicated parser error variants (messages unchanged)
- Engine: `Workspace::cursor_scope`, `slot`, `facts`; `rename_from` and
`references_from`; editor spans in UTF-16 units; renames reach imported
policies, `$nodes` reads, child graphs and output column heads; no `$root`
completion in policies
- Node bindings: `slot`, `facts`, `cursorScope`, `slotBatch` replace
`nl`, `nlTokenize`, `nlEncodeString`, `nlTokenizeBatch`
No change to expression evaluation: the VM, compiler, functions and the
default lexer path are untouched, and parser error messages keep their text.
* fix: harden slot classification, scopes and graph expectations
- restore master execution order; slot scopes hide writes of the edited
block and its dependents instead of relying on block ranking
- token-start editing gated by slot state; operator, list and operand
spans no longer splice into neighbouring tokens
- interval-aware bracket pairing for half-open and reversed intervals
- lenient lexer recovers from unknown characters (slots only)
- graph expected type follows switch and pass-through nodes and merges
compatible output schemas
- sibling inference caps distinct values and analyses lazily
- deterministic overload return type display
* fix: order policy blocks by entity reads through closures and relationships
- record reads for `#.field` in closures so entity fields read through
lists become dependencies
- link reads through derived lists (filter/map results) to the entity
fields they carry and order the list after those fields
- evaluate entity blocks on single relationships, and demand entity
paths for plain reads through relationships
- slot scopes keep the top-level variable when hiding written fields