Skip to content

chore(tools): Support per-pattern regex mode in fs_modify_file#876

Merged
JeanMertz merged 1 commit into
mainfrom
fs-modify-file-fix
Jul 24, 2026
Merged

chore(tools): Support per-pattern regex mode in fs_modify_file#876
JeanMertz merged 1 commit into
mainfrom
fs-modify-file-fix

Conversation

@JeanMertz

Copy link
Copy Markdown
Collaborator

Patterns passed to fs_modify_file can now set their own regex flag, overriding the call-level replace_using_regex. This lets a single call mix literal and regex patterns instead of forcing all patterns into the same mode:

{
  "path": "src/lib.rs",
  "patterns": [
    {"old": "stream().await", "new": "stream()"},
    {"old": "fn (\w+)_old", "new": "fn ${1}_new", "regex": true}
  ],
  "replace_using_regex": false
}

Fixes two related bugs in regex mode. A regex that compiled but matched nothing was previously reported as applied even though no replacement happened; it is now reported as not found alongside literal-mode misses. A regex that failed to compile silently skipped the pattern with no feedback; it now surfaces as an "Invalid regex patterns" section in the report, separate from "Patterns not found", so callers can tell a typo in the regex apart from a pattern that simply is not present.

The find_blocked_regex_patterns guard against overly-broad patterns (e.g. bare .*) now only applies to patterns actually running in regex mode, respecting the same per-pattern override. Tool docs and the JSON schema are updated to describe the new regex field and to warn that parentheses are capture groups, not literal characters, in regex mode.

Patterns passed to `fs_modify_file` can now set their own `regex` flag,
overriding the call-level `replace_using_regex`. This lets a single
call mix literal and regex patterns instead of forcing all patterns
into the same mode:

```json
{
  "path": "src/lib.rs",
  "patterns": [
    {"old": "stream().await", "new": "stream()"},
    {"old": "fn (\w+)_old", "new": "fn ${1}_new", "regex": true}
  ],
  "replace_using_regex": false
}
```

Fixes two related bugs in regex mode. A regex that compiled but
matched nothing was previously reported as applied even though no
replacement happened; it is now reported as not found alongside
literal-mode misses. A regex that failed to compile silently skipped
the pattern with no feedback; it now surfaces as an "Invalid regex
patterns" section in the report, separate from "Patterns not found",
so callers can tell a typo in the regex apart from a pattern that
simply is not present.

The `find_blocked_regex_patterns` guard against overly-broad patterns
(e.g. bare `.*`) now only applies to patterns actually running in
regex mode, respecting the same per-pattern override. Tool docs and
the JSON schema are updated to describe the new `regex` field and to
warn that parentheses are capture groups, not literal characters, in
regex mode.

Signed-off-by: Jean Mertz <git@jeanmertz.com>
@JeanMertz
JeanMertz merged commit 1a7e313 into main Jul 24, 2026
16 checks passed
@JeanMertz
JeanMertz deleted the fs-modify-file-fix branch July 24, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant