feat: policy engine#450
Merged
Merged
Conversation
ivanmiletic
approved these changes
Jun 23, 2026
This was referenced Jun 24, 2026
Closed
Closed
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Policy engine
This PR adds the Policy engine, a second way to author logic in ZEN that runs next to the existing JDM decision graphs.
The difference is in how execution order is decided. In a graph you place nodes and connect them yourself, so the wiring is the order. A policy is declarative: you write a set of blocks, each one reads some properties and writes others, and the engine works out the dependencies between them, sorts them, and runs them. Nothing is wired by hand.
Policy definition
Inspecting evaluation (answering "Why?")
What a policy looks like
A policy document is a list of blocks plus a list of imports, so one policy can build on another. There are five block types:
Block types the engine doesn't recognise are kept as-is through a load/save cycle, so a frontend can attach layout or other metadata without the engine touching it.
Authoring layer
Most of the code here is the authoring support, exposed through PolicyWorkspace. It works like a language server for policies:
anyleft in a resolved type is an error.Evaluation
evaluate runs a policy against an input. It is demand-driven: pass a set of goals and it only runs the blocks needed to produce those outputs. Turn on trace to record how each value was derived, and enhanceTrace adds the operand values behind each expression for a trace viewer. If a block fails, evaluation returns the partial trace alongside the error instead of throwing, so you can see how far it got and why it stopped.
Bindings and loaders
The Node.js binding exposes the full PolicyWorkspace API. The Python, UniFFI and C bindings will be updated later to include a new loader config (static map, filesystem path, or zip) that pre-loads and pre-compiles decisions up front.