Systematic AST-based code refactoring using gritql for safe, validated multi-file transformations with mandatory preview and verification steps
Orchestrate large structural refactors using ast-grep to discover scope and gritql to apply transformations safely.
Use this skill for:
Don't use for:
Edit tool directlyEdit toolgit status # Must be clean
git checkout -b refactor/<description>
Run baseline build + tests before starting.
Before transforming anything, understand the full impact:
# Find all sites that will be affected
sg --pattern '$obj.oldMethod($$$)' --lang java src/
# Verify count and locations are expected
See code-ast-grep skill for full pattern syntax.
grit apply '<pattern>' --dry-run > /tmp/preview.diff
# Review ALL changes before applying
See code-gritql skill for transformation pattern syntax.
grit apply '<pattern>'
# Format
./gradlew spotlessApply # or equivalent formatter
# Compile
./gradlew compileJava compileKotlin
# Full test suite
./gradlew test testIntegration
# Review diff
git diff HEAD
git add -u
git commit -m "refactor: <clear description>"
Before completing any refactor:
| Scenario | Tool |
|----------|------|
| Find all affected code sites | ast-grep (sg) |
| Multi-file expression-level Kotlin rewrite | gritql |
| Kotlin catch/if/try block transformation | Edit (or ast-grep --rewrite YAML) |
| Multi-file structural transformation (non-Kotlin) | gritql |
| Single file, simple change | Edit |
| Same text change across files | MultiEdit |
GritQL only handles expression-level Kotlin patterns (function calls, method chains, imports). For statement-level changes — catch blocks, if statements, variable declarations, try/finally — use Edit for targeted changes or ast-grep with a YAML rule for structural multi-file rewrites. See code-gritql skill for the full Kotlin limitations list.
code-gritql skill and reference.mdcode-ast-grep skill| Skill | When to apply |
|-------|--------------|
| code-ast-grep | Discover scope of changes before applying any transformation |
| code-gritql | Apply AST-based multi-file code transformations |
| code-architecture-best-practices | Validate refactored structure against SOLID/Clean Architecture |
| code-review | Verify refactor output before merging to main branch |
| code-debugging | Diagnose test failures or build errors introduced during refactoring |
| lean-agent-loop | Iterate quality gate failures (format, compile, test) with parallel agents until all pass |
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer