feat(evaluator): add @bind lattice variables for path equality constraints#25
Closed
srnnkls wants to merge 7 commits into
Closed
feat(evaluator): add @bind lattice variables for path equality constraints#25srnnkls wants to merge 7 commits into
srnnkls wants to merge 7 commits into
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. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014XbvJUbcX5KEQUBMEA4zGq
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.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014XbvJUbcX5KEQUBMEA4zGq
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. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014XbvJUbcX5KEQUBMEA4zGq
…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. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014XbvJUbcX5KEQUBMEA4zGq
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. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014XbvJUbcX5KEQUBMEA4zGq
srnnkls
force-pushed
the
claude/cue-lattice-variables-483077
branch
from
June 28, 2026 21:19
5513046 to
d7170b3
Compare
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. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014XbvJUbcX5KEQUBMEA4zGq
`len()` inside `when` computes over the pattern's materialised value (e.g. `[]` for open lists), not the input's, so the result is always a fixed constant. Reject at load time with E0508 and guide users toward `list.MatchN` instead. - Add E0508 diagnostic code with help text - Reject `len` CallExpr in lintWhen walker - Remove `len` from permittedUniverseBuiltins - Remove now-unreachable evaluator test for len-inert-under-subsumption - Add unit test, fixture rule, and scrut integration test - Update AGENTS.md and GUIDE.md Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014XbvJUbcX5KEQUBMEA4zGq
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.
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_014XbvJUbcX5KEQUBMEA4zGq