feat(evaluator): add @bind lattice variables for path equality constraints#26
Merged
Conversation
…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
force-pushed
the
feat/cue-lattice-variables
branch
from
June 30, 2026 08:48
ed46234 to
8500e02
Compare
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.
Introduce @Bind(Var) attributes on
whenclause fields to express thattwo 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:
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
letclauses andif/forcomprehensions insidewhen(E0506/E0507), where they evaluate against the pattern rather than the input.