Skip to content

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

Closed
srnnkls wants to merge 7 commits into
mainfrom
claude/cue-lattice-variables-483077
Closed

feat(evaluator): add @bind lattice variables for path equality constraints#25
srnnkls wants to merge 7 commits into
mainfrom
claude/cue-lattice-variables-483077

Conversation

@srnnkls

@srnnkls srnnkls commented Jun 28, 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.

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_014XbvJUbcX5KEQUBMEA4zGq

claude added 5 commits June 28, 2026 10:10
…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
srnnkls force-pushed the claude/cue-lattice-variables-483077 branch from 5513046 to d7170b3 Compare June 28, 2026 21:19
claude added 2 commits June 29, 2026 04:47
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
@srnnkls srnnkls closed this Jun 30, 2026
@srnnkls
srnnkls deleted the claude/cue-lattice-variables-483077 branch June 30, 2026 08:32
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.

2 participants