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.
* 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.
* feat(engine): compiled engine for columnar graphs and policies
New engine for decisions and policies built on the lane VM: a compiled
graph plan that evaluates batches column-wise (typed kernels where
expressions allow, lane programs otherwise), a row runner for batch and
single-row evaluation, and a compiled policy runtime with a columnar pass.
- Decision::evaluate_columns / Workspace::evaluate_columns return one
ColumnarOutput type; diagnostics live in zen_engine::diagnostics
- rows the plan cannot finish are deferred to the row runner and never
re-run nodes; sub-decisions run inside the parent plan; date input
schemas stay on the plan
- DecisionEngine keeps compiled graphs, sub-decisions and policies per key
while the loader returns the same content
- failed $dictionary imports are retried, not cached
- the old engine stays available behind the driver feature for
comparisons; there is no fallback to it
- benchmark harness (tests/bench_matrix.rs) comparing old and new across
the spec corpus, fixtures and policies
* refactor(engine): isolate compiled engine from release node and graph code
Release code outside core/engine/src/compiled is restored to release/2.2.
The compiled engine keeps its own copy of the node, graph and JS function
implementation under compiled/host and reaches release only through types
and pure helpers. Release files gain only additive hooks: the
ZEN_CONFIG.compiled runtime flag (off by default), per-instance
interpreted()/compiled_engine() on Decision, DecisionEngine and
PolicyWorkspace, and the batch and columnar entry points.
- the driver feature and the modified old engine are removed; tests compare
the compiled engine against the unmodified release engine
- compiled-only behaviour (#7 empty collect columns, #16 collect order,
BC1 thrown-object message) is allowlisted in the comparisons
- #14 (policy whitespace cells) is dropped: release analysis rejects it
- goldens re-recorded from the release engine
- spec 42 nested-chain case lowered to depth 200: the release engine's JS
conversion overflows a 2 MB debug thread at depth 500
* fix(engine): keep interpreted engines interpreted and tighten engine comparisons
- DecisionEngine::interpreted() now holds while ZEN_CONFIG.compiled is on:
decisions it creates (get_decision, create_decision, evaluation) carry its
engine, and its release path runs in an interpreting scope so the
Workspace built by the lazy policy path stays interpreted too
- policy batches (DecisionEngine and PolicyWorkspace) deep-copy their inputs
like graph batches, so callers' contexts are no longer written into
- release test files run on the release engine again: the compiled-by-default
ctor moved out of tests/support into tests/compiled_default, included only
by the compiled test suites
- spec `engines` notes are structured ({modes, intended, why}); unlisted modes
are still compared with the reference, intended modes are checked against
the spec, and open differences fail once they match the reference again.
Stale notes found this way were removed; golden skips are per mode, and
generated rows no longer inherit the first case's note
* fix(engine): platform-independent spec suite ids and rustfmt
- spec suite file paths are joined with '/', so suite ids and golden keys
match on Windows (backslash paths missed every recorded golden)
- engine spec json5 files are checked out with LF line endings
- cargo fmt
* fix(engine): bound table gap analysis memory, analyse expression columns
Missing-case detection built the full atom/row partition for every column
before charging the work budget. Nested ranges (`> 1`, `> 2`, ...) make that
partition quadratic, so large tables (tens of thousands of rows) allocated
gigabytes before giving up, exhausting the 1GB WASM memory. The partition
size is now counted first and the budget checked before building it; results
are unchanged (50k rows: ~10GB/28s -> ~650MB/1s natively).
Columns without a field whose filled cells are all conditions on one field
(`age > 50`, `age > 30`) are now analysed like field columns on that field:
duplicates, unreachable rows, missing cases and compression. Compressed and
missing-case cells are written back as full expressions (`age > 30`).
Columns mixing fields or using non-analysable expressions stay opaque.
* chore(engine): remove comments from table analysis changes
* 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.
* feat: declared dates as date values
- graph format:date/date-time inputs and policy date properties arrive as
dates that keep their original text for output, string() and string
functions
- d() keeps the instant of offset/Z strings, resolves DST gaps and accepts
ISO forms without offset, compact, slash-separated, YYYY-MM and YYYY
- dates compare with date strings in ==, !=, <, >, in and contains, and
concatenate with strings; deprecated date helpers accept dates
- string(date), type() reports date, and date-to-string at string inputs
* fix: close review gaps in date inputs
- parse new date formats by exact shape; keep master formats first and
guard DST-gap and extreme-year overflows
- text-carrying dates act as strings for object keys, in-object, index,
slice, concatenation and bool
- deprecated helpers fall back to the date instant; time() accepts dates
- schema-less child inputs receive date text; dates satisfy string
parameters and slicing in the type checker
- convert policy input before validation so dates are parsed once;
share rewrite helpers between graph and policy conversion
* fix: align date text, unions, references and child inputs
- every valid date exposes a text form (original or RFC3339), so string
functions and slicing on computed dates match the type checker
- date and string types merge to string; reference ids typed as dates
resolve through their text
- input nodes convert declared dates and hand every other converted date
back as its original text, following combinators only for structure
- date format checks no longer allocate
- 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
* fix: scope policy evaluation to the import closure
A policy is now analysed and evaluated together with the policies it
imports (transitively), instead of every policy connected to it by imports
in either direction. Importers and siblings no longer leak into each other:
compiled evaluate() of an imported policy used to run its importers' and
siblings' blocks.
- Evaluation gate analyses the entry's import closure as one unit, so a
child may read fields and reference entities its importer declares when
evaluated through that importer
- compile() reports a policy that is only valid through an importer with
kind "policyImportOnly" instead of failing it as a plain "policy"; errors
are computed once per key
- Scope diagnostics (duplicate writers, input overrides, data model and
dictionary collisions, cycles) are reported for the whole closure, and
conflicts introduced by combining imports are reported on the importer
- Single-entity scope checks run per import closure instead of workspace-wide
* fix: unknown import relationship targets and renames across imports
- An unresolved relationship/reference target inside an imported policy now
blocks the importer's evaluation and compile(), as on master; the check was
still limited to the policy being analysed, so the importer compiled and
the broken child was reported as "policyImportOnly"
- Rename and find-references analyse each policy's expressions in every
importer's context too, so reads of a field declared by an importer are
found in the imported policy again
* fix: return errors instead of panicking in memory loader and v1 functions
- MemoryLoader recovers from a poisoned lock. Previously a panic during
one add() (e.g. a failing content conversion) made every later
add/get/remove/keys call panic for the rest of the process
- v1 function node returns an error when its JS bootstrap fails instead
of unwrapping. The 500ms interrupt budget starts before the runtime and
bundled libraries load, so a slow or loaded host could interrupt the
bootstrap and panic
* chore: bump setup-android to v3 in uniffi workflow
Only platform-tools is installed; Gradle fetches the platform and build tools the AAR build needs.