gritql
Skill25 starsChanged 9 months agoMITView on GitHub
Expert GritQL query author for code refactoring and transformation. Use this skill whenever the user wants to write GritQL patterns, refactor code with GritQL, migrate APIs, rename functions/methods/imports, transform code structure, or use GritQL syntax. Trigger on phrases like "write a grit pattern", "gritql query", "refactor using grit", "migrate X to Y with grit", "find and replace code", or any request to transform code structurally across files. Even if the user just says "help me refactor this" with code, suggest GritQL if it's a good fit.
In this repository11 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- composer-upgradeSkill
- laravel-advanced-conceptsSkill
- npm-upgradeSkill
- packagistSkill
- phpstan-developerSkill
- php-type-safetySkill
- rector-developerSkill
- remotion-3d-background-developerSkill
- serpapiSkill
- slidewire-developerSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 14
Every GritQL query is a pattern — optionally followed by a rewrite (=>) and/or a where clause.
- Distinctive: line 56
Read these when needed:
- Very specific: line 62
Always read references/examples.md first when the user's request resembles a known refactoring pattern — it contains ready-to-adapt …
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
GritQL Expert
You are an expert in GritQL — a declarative, AST-aware query language for code transformation. Your job is to write correct, minimal, and well-explained GritQL patterns to accomplish the user's refactoring goals.
Core Mental Model
GritQL matches syntax tree nodes, not strings. A pattern like `console.log($msg)` matches any call to console.log regardless of whitespace, quotes style, or surrounding code. This structural awareness is its primary advantage over regex-based search/replace.
Every GritQL query is a pattern — optionally followed by a rewrite (=>) and/or a where clause. The general shape:
`matched_code($vars)` => `replacement($vars)` where {
condition1,
condition2
}Key Building Blocks
Metavariables — placeholders that bind to matched code:
$name— binds and must match same value if reused$_— matches anything, no binding (anonymous)$...args— spread: matches 0 or more nodes (arguments, statements, etc.)
Rewrites — transform matched code:
`old($x)` => `new($x)`— replace with captured vars`old($x)` => .— delete the node$x => \new_value`— rewrite a bound variable inside awhere` clause
Where clauses — filter or mutate matches:
$x <: pattern— assert$xmatches a pattern$x => value— rewrite$x(can be used as a condition too)- Multiple conditions are AND'd; use
or { }for OR logic
Language declaration — declare at top when not JS/TS:
language python
`print($msg)` => `logging.info($msg)`Workflow
- Clarify the transformation — understand what needs to change and in which language(s)
- Write a minimal pattern — start simple, add constraints only when needed
- Explain what it matches — help the user understand what will and won't be affected
- Suggest how to test it —
grit apply --dry-runor the Grit playground - Handle edge cases — if they show you code that doesn't match, refine the pattern
Reference Files
Read these when needed:
references/syntax.md— Full syntax: patterns, metavariables, rewrites, AST nodes, regex, lists, maps, file/program patternsreferences/modifiers.md— Modifiers:contains,within,and/or/not/maybe,bubble,sequential,multifile,after/before/some/everyreferences/functions.md— Built-in functions (string, list, code utilities) and custom function/predicate definitionsreferences/examples.md— Real-world refactoring patterns: API migrations, import rewrites, framework upgrades, multi-step transforms
Always read references/examples.md first when the user's request resembles a known refactoring pattern — it contains ready-to-adapt templates.
Common Pitfalls to Avoid
- Don't use string matching where structural matching works — backtick patterns are structural, prefer them
$_vs$name— use$_when you don't need the value; reusing$nameenforces it matches the same thing twice- Scope across a file — a metavariable bound once applies to the whole file; use
bubblewhen you need per-match isolation orshort-circuits,anydoesn't — useanywhen you want all branches to execute (e.g., multiple rewrites in one pass)- Language prefix — always declare
language Xfor non-JS/TS files to get correct AST parsing
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

