-
Notifications
You must be signed in to change notification settings - Fork 0
feat: executable rules and hierarchy validation #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| # Executable Rules | ||
|
|
||
| Rules are JSONata expressions embedded in a schema's `_metadata.rules` block. Each rule is evaluated against applicable nodes at validation time and must return `true` to pass. Rules encode checks that JSON Schema structural validation cannot express — cross-node consistency, quantitative thresholds, and qualitative best practices. | ||
|
|
||
| For how rules fit into the broader schema metadata, see [docs/schemas.md](schemas.md). | ||
|
|
||
| ## Rule Categories | ||
|
|
||
| Rules are grouped into categories under `_metadata.rules`. Categories are informational — they determine how violations are labelled and grouped in output, but do not affect how the rule is evaluated. Use `scope` to control evaluation mode. | ||
|
|
||
| | Category | Purpose | | ||
| |---|---| | ||
| | `validation` | Structural correctness — a violation means the node is incorrect and should be fixed | | ||
| | `coherence` | Cross-node checks — for flagging conflicts or contradictions between nodes | | ||
| | `workflow` | Process discipline checks — for keeping the tree in an operational working state (active counts, status consistency) | | ||
| | `bestPractice` | Advisory guidance — signals the space may benefit from additional work | | ||
|
|
||
| ## Rule Object Structure | ||
|
|
||
| | Field | Required | Description | | ||
| |---|---|---| | ||
| | `id` | yes | Unique identifier (kebab-case) | | ||
| | `description` | yes | Human-readable description of what the rule checks | | ||
| | `check` | yes | JSONata expression that must evaluate to `true` to pass | | ||
| | `type` | no | If set, only applies to nodes of this resolved type | | ||
| | `scope` | no | Set to `'global'` to evaluate the rule once against the full node set | | ||
|
|
||
| Rules without `scope: 'global'` are evaluated once per applicable node (all nodes, or only those matching `type`). A global rule is evaluated once and produces at most one violation for the space — use this for aggregate checks, like counts, across all nodes. | ||
|
|
||
| ## JSONata Expression Context | ||
|
|
||
| Each expression is evaluated once per applicable node with the following input: | ||
|
|
||
| | Variable | Description | | ||
| |---|---| | ||
| | `nodes` | Array of all nodes in the space | | ||
| | `current` | The node being evaluated | | ||
| | `parent` | The resolved parent node — absent if no parent was resolved | | ||
|
|
||
| Nodes include all node properties (title, type, status, parent wikilink, etc.) plus two resolved fields: `resolvedType` (canonical type after alias resolution) and `resolvedParentTitle` (parent title after resolving any links). | ||
|
|
||
| Prefer `resolvedType` over `type` for type comparisons. When aliases are in use, `type` reflects the raw frontmatter value and may not match canonical names. | ||
|
|
||
| ### Referencing `current` inside predicates | ||
|
|
||
| Inside a predicate (`nodes[...]`), bare names refer to fields on each item. Use `$$` (JSONata root) to reach outer-scope variables: | ||
|
|
||
| ```jsonata | ||
| // Count solutions whose parent title matches the current node's title | ||
| $count(nodes[resolvedParentTitle=$$.current.title and resolvedType='solution']) | ||
| ``` | ||
|
|
||
| ### `parent` vs `current.parent` | ||
|
|
||
| - `parent` — the resolved parent **node object**; absent if the parent was not found in the space | ||
| - `current.parent` — the raw wikilink string from frontmatter (e.g. `[[My Outcome]]`) | ||
|
|
||
| Use `$exists(parent)` to test whether the current node has a resolved parent: | ||
|
|
||
| ```jsonata | ||
| $exists(parent) = false // true for root nodes | ||
| ``` | ||
|
|
||
| ## Examples | ||
|
|
||
| ```json | ||
| { | ||
| "workflow": [ | ||
| { | ||
| "id": "active-outcome-count", | ||
| "description": "Only one outcome should be active at a time", | ||
| "scope": "global", | ||
| "check": "$count(nodes[resolvedType='outcome' and status='active']) <= 1" | ||
| }, | ||
| { | ||
| "id": "active-node-parent-active", | ||
| "description": "An active node's parent should also be active", | ||
| "check": "current.status != 'active' or $exists(parent) = false or parent.status = 'active'" | ||
| } | ||
| ], | ||
| "bestPractice": [ | ||
| { | ||
| "id": "solution-quantity", | ||
| "description": "Explore multiple candidate solutions (aim for at least three) for the target opportunity", | ||
| "type": "opportunity", | ||
| "check": "(current.status != 'exploring' and current.status != 'active') or $count(nodes[resolvedParentTitle=$$.current.title and resolvedType='solution']) >= 3" | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| The first workflow rule uses `scope: 'global'` — evaluated once against the whole space, producing at most one violation. The second runs per-node with no `type` filter, checking every node. The best-practice rule only runs against `opportunity` nodes where status is `exploring` or `active`, using `resolvedParentTitle` to count child solutions. |
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't coherence. Add a
workflowcategory for both of these rules.Coherence is more for things like "the goal is to make $10M" when "the opportunity is to rebuild the design system". Coherence rules are likely to be more qualitative.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also add a workflow check that an active (status) node should have an active (status) parent.
Ideally this goes into _shared but we don't have a way to merge rules yet - now we have a reason to want #17 (comment)