feat(parser): expose per-command groups in parsed.calls#24
Merged
Conversation
The flat parsed.commands/targets lists cannot bind a verb to the target it
acts on, so `cat README && rm .env` puts a read verb and a secret into the
same lists and a rule keying off both over-matches. parsed.calls groups each
invocation with its own command, subcommand, action, targets, and flags, so a
rule can match a single call that both runs a read verb and targets a secret.
This is parse-time pre-joining, not a relational match: the engine still
matches by subsumption, and list.MatchN(>0, {command, targets}) over calls is
an ordinary existential over one struct's fields. calls_join_test pins it —
the flat shape matches both `cat .env` and `cat README && rm .env`; the join
matches only the genuine read.
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.
Problem
The flat
parsed.commands/parsed.targetslists can't say which target agiven command acts on. So
cat README && rm .envdrops a read verb (cat) anda secret (
.env) into the same flat lists — a rule keying off "a read verband a secret target" fires even though nothing reads the secret. The join is
inexpressible because the relationship was flattened away before the rule sees it.
Fix
Add
parsed.calls: each invocation grouped with its owncommand,subcommand,action,targets, andflags. A rule can now match a singlecall that both runs a read verb and targets a secret:
This is parse-time pre-joining, not a relational match. The engine still
matches by subsumption;
list.MatchN(>0, {command, targets})overcallsis anordinary existential over one struct's fields, so it stays within what
subsumption can verify. The flat lists are unchanged and remain deny-safe.
Tests
internal/parser/bash_calls_test.go— per-command grouping (compound lines,read-of-secret, subcommand + flags).
internal/contract/calls_join_test.go— end-to-end subsumption proof mirroringthe evaluator's
When.Subsume(input, …): fed real parser output, the flatshape matches both
cat .envandcat README && rm .env; the join matchesonly the genuine read.
#Parsedschema gainscalls?(open-typed per the R5 rule); the bidirectionaldrift test pins it in sync with
parser.Parsed.The author-facing doc for the field lives with the GUIDE in #23 (GUIDE.md isn't
on
mainyet); it'll land there rather than duplicate the file into this PR.