Skip to content

feat(evaluator): add @bind lattice variables for path equality constraints#26

Merged
srnnkls merged 6 commits into
mainfrom
feat/cue-lattice-variables
Jun 30, 2026
Merged

feat(evaluator): add @bind lattice variables for path equality constraints#26
srnnkls merged 6 commits into
mainfrom
feat/cue-lattice-variables

Conversation

@srnnkls

@srnnkls srnnkls commented Jun 30, 2026

Copy link
Copy Markdown
Owner

Introduce @Bind(Var) attributes on when clause fields to express that
two input paths must resolve to equal concrete values. Variables are
deferred lattice points: subsumption checks the static pattern first,
then a post-Subsume pass groups bindings by variable name and verifies
mutual subsumption of the resolved values.

New files:

  • config/bind.go: Binding type, AST extraction (extractBindings/walkBindings/parseBindAttr)
  • evaluator/bind.go: checkBindings, resolvePath, allEqual, E0601 diagnostic

Also adds predeclared CUE type identifiers (string, int, bool, etc.) to
the lint's allowed set — the standalone parser doesn't mark them via
IsPredeclared(), so they previously false-positived as E0501.

Also rejects let clauses and if/for comprehensions inside when
(E0506/E0507), where they evaluate against the pattern rather than the input.

srnnkls added 6 commits June 30, 2026 10:43
…aints

Introduce @Bind(Var) attributes on `when` clause fields to express that
two input paths must resolve to equal concrete values. Variables are
deferred lattice points: subsumption checks the static pattern first,
then a post-Subsume pass groups bindings by variable name and verifies
mutual subsumption of the resolved values.

New files:
- config/bind.go: Binding type, AST extraction (extractBindings/walkBindings/parseBindAttr)
- evaluator/bind.go: checkBindings, resolvePath, allEqual, E0601 diagnostic

Also adds predeclared CUE type identifiers (string, int, bool, etc.) to
the lint's allowed set — the standalone parser doesn't mark them via
IsPredeclared(), so they previously false-positived as E0501.
Add E0601 diagnostic test (diagnostics.md) and policy-level bind tests
(policies.md) exercising the match/no-match/structural-mismatch paths.
Fixture rules under tests/diagnostics_rules_bind/ and tests/policies_bind/.

Fix walkBindings to descend through BinaryExpr nodes — stdlib-imported
rules use `hook.#PreToolUse & tool.#Bash & { ... }`, which wraps the
struct literal in a BinaryExpr chain. Without this fix, @Bind attributes
inside such rules were silently ignored.

Add @Bind section to README documenting syntax, semantics, and the
sub-path indexing feature.
Replace "commands[0] == targets[0]" pattern (which produced the absurd
"cat cat" test case) with two realistic patterns:

- Self-referencing copy/move: targets[0] == targets[1] catches
  `cp file.txt file.txt` or `mv src.go src.go`.
- Deleting the working directory: cwd == targets[0] catches
  `rm -rf /home/user/project` when run from that directory.

Update scrut tests, fixture rules, and README accordingly.
…06, E0507)

`let` clauses and comprehension guards inside `when` evaluate against
the pattern's types, not the input's concrete values, causing rules to
silently match inputs they shouldn't. The lint now rejects both at load
time with clear diagnostics explaining the misfire and how to rewrite.
Document that `let` and `if`/`for` inside `when` are now rejected at
load time, add the new codes to the error table, and mention them in
the troubleshooting section.
The README is a terse reference; @Bind belongs in the guide where the
rationale and examples have room. The GUIDE section leads with the
motivating case (cwd == target), explains the two-pass mechanism, and
covers the sub-path syntax — without the contrived self-copy example.
@srnnkls
srnnkls force-pushed the feat/cue-lattice-variables branch from ed46234 to 8500e02 Compare June 30, 2026 08:48
@srnnkls
srnnkls merged commit ed7d08a into main Jun 30, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant