replace
Refactor code using AST, regex, or text patterns, preview unified diffs by default, then apply changes safely to files.
Instructions
Structural code refactoring and replacement engine. Supports AST rewrite or Regex/Text replacement. By default, runs in dryRun mode producing a unified diff preview to ensure safe operations before writing changes to disk.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | Directory or file to perform replacement in (default: '.') | . |
| type | No | Replacement engine: 'ast' (default structural rewrite), 'regex', 'text' | ast |
| query | Yes | Target search pattern to replace (AST pattern or regex) | |
| dryRun | No | If true (default), outputs unified diff preview without modifying files on disk | |
| fileType | No | File type filter | |
| language | No | Programming language for AST mode (auto-detected if omitted) | |
| noIgnore | No | Whether to search inside gitignored files | |
| filePattern | No | Glob pattern to filter files | |
| replacement | Yes | Replacement string or AST rewrite pattern | |
| excludePattern | No | Glob pattern to exclude | |
| maxReplacements | No | Safety guardrail: maximum number of matches to replace (default: 50) |