Skip to content

fix(edit_match): prefer literal paths over glob#133

Open
tobwen wants to merge 2 commits into
cortexkit:mainfrom
tobwen:edit-match-literal-brackets
Open

fix(edit_match): prefer literal paths over glob#133
tobwen wants to merge 2 commits into
cortexkit:mainfrom
tobwen:edit-match-literal-brackets

Conversation

@tobwen

@tobwen tobwen commented Jun 19, 2026

Copy link
Copy Markdown

Fixes #132

What and why?

Existing paths with brackets are now treated as literal files instead of glob patterns. Falls back to glob when the path doesn't exist or validation fails.


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.


Summary by cubic

Prefer literal paths over globs in edit_match when the path exists on disk, even if it contains [ ] * ? { }. We now fall back to glob only when the path doesn’t exist.

  • Bug Fixes
    • Added should_treat_as_glob to prefer literal when validate_path resolves an existing path; use glob only if the candidate doesn’t exist. On validate_path errors (including path_outside_root and unknown), defer to the single-file flow so errors surface correctly.
    • Added regression tests for bracketed literal paths (absolute and relative) and a sanity test for parentheses.

Written for commit 56ca4d5. Summary will update on new commits.

Review in cubic

Greptile Summary

This PR fixes issue #132 by introducing should_treat_as_glob, which replaces the old bare is_glob_pattern character-scan with a disk-existence check: if validate_path resolves the path to something that already exists on disk, it is treated as a literal file even when the name contains [, ], *, ?, or {.

  • edit_match.rs: should_treat_as_glob calls ctx.validate_path to canonicalize the path and then checks candidate.exists(); path_outside_root and any other validation errors both return false, correctly deferring to handle_single_file_edit_match (which re-validates and surfaces the proper error).
  • edit_test.rs: Three new integration tests cover absolute bracketed paths, relative bracketed paths (with restrict_to_project_root), and a parentheses sanity check.

Confidence Score: 5/5

Safe to merge — the change is a targeted, well-tested fix that only affects paths containing glob metacharacters.

The new should_treat_as_glob function mirrors the exact same path-resolution logic that handle_single_file_edit_match uses internally, so the literal-vs-glob decision stays consistent with how the file is ultimately opened. The catch-all error arm returns false (not true), so unknown future validation errors fall through to the single-file handler and surface as proper error responses rather than being silently swallowed into a glob dispatch. Three integration tests cover the primary regression scenario (absolute and relative bracketed paths) plus a non-metacharacter sanity case.

No files require special attention.

Important Files Changed

Filename Overview
crates/aft/src/commands/edit_match.rs Replaces the raw is_glob_pattern check with should_treat_as_glob, which prefers literal path handling when validate_path resolves an existing path on disk. Logic is sound: path_outside_root and other validation errors correctly fall through to the single-file handler rather than promoting to glob.
crates/aft/tests/integration/edit_test.rs Adds three regression / sanity tests: absolute bracketed path, relative bracketed path (with project root configured), and parentheses (non-glob chars, sanity only). Coverage is adequate for the targeted fix.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[handle_edit_match] --> B{should_treat_as_glob?}
    B -->|is_glob_pattern = false| C[return false\nliteral path]
    B -->|is_glob_pattern = true| D[ctx.validate_path]
    D -->|Ok path| E{candidate.exists?}
    E -->|yes - file exists| F[return false\nprefer literal]
    E -->|no - file absent| G[return true\nuse glob]
    D -->|Err path_outside_root| H[return false\ndefer to single-file]
    D -->|Err other| I[log debug\nreturn false\ndefer to single-file]
    C --> J[handle_single_file_edit_match]
    F --> J
    H --> J
    I --> J
    G --> K[handle_glob_edit_match]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[handle_edit_match] --> B{should_treat_as_glob?}
    B -->|is_glob_pattern = false| C[return false\nliteral path]
    B -->|is_glob_pattern = true| D[ctx.validate_path]
    D -->|Ok path| E{candidate.exists?}
    E -->|yes - file exists| F[return false\nprefer literal]
    E -->|no - file absent| G[return true\nuse glob]
    D -->|Err path_outside_root| H[return false\ndefer to single-file]
    D -->|Err other| I[log debug\nreturn false\ndefer to single-file]
    C --> J[handle_single_file_edit_match]
    F --> J
    H --> J
    I --> J
    G --> K[handle_glob_edit_match]
Loading

Reviews (2): Last reviewed commit: "fix(edit_match): fail-safe on unknown va..." | Re-trigger Greptile

Existing paths with brackets are now treated as literal files
instead of glob patterns. Falls back to glob when the path
does not exist or validation fails.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

Comment thread crates/aft/src/commands/edit_match.rs
Addresses Greptile P2: the Err(_) => true catch-all silently routed
unknown validate_path errors to the glob handler. Return false instead
so the single-file handler re-validates and surfaces the error.
Dead code today (all errors use path_outside_root), zero behavior change.
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.

(bug) AFT tools don't handle file paths that contain brackets like () []

1 participant