Why ast-grep
Some conventions are structural: “never call this function here”, “always pass this option”. A model can spot them, but it can also miss one or imagine one. An ast-grep rule matches the syntax tree, so a match is proof. A finding that cites a rule the run matched skips the model check and posts. The example is a checkout service with one convention: amounts are integer cents handled by theMoney helper, never floats.
Step 1 — Write the rules in the repository
Commit a rule file on your default branch. Kodus reads it from each pull request’s target branch, so a pull request can’t loosen the rules it is checked against.rules/money.yml
message is what the comment quotes as the rule, so write it for the person reading the pull request.
Write the reasoning down once in a doc too, for the cases a pattern can’t catch:
docs/money.md
Step 2 — Create the agent
New agent → Templates → Blank, then:Name
Instructions
Step 3 — Point it at the rules
Under Tools → Advanced → Structural search (ast-grep rules), enter the path on a single line:2 rules in rules/money.yml: no-parsefloat-amount, no-tofixed-amount. You can paste the YAML inline instead of a path; the rules then live in the agent, not in the repository.
Step 4 — Comments
Click Save.
Step 5 — Try it
Run Try it on a pull request that adds aparseFloat on a price. The finding is kept, and its comment cites the rule:
docs/money.md quotes the doc instead, and is dropped if the quote isn’t in the doc on the target branch.
Checklist
- Rule file committed on the default branch
- Each rule has an
id, aruleand a readablemessage - The field’s hint lists every rule
- Globs cover only the code the convention applies to
- Tried on a pull request with a known violation