Skip to main content
How Mouse Works

The Find-Then-Edit Workflow

Use find_in_file to locate targets precisely before making edits: search first, then operate

Overview

Mouse's find_in_file tool provides pattern matching within files, returning match locations with line numbers, column positions, and surrounding context. When combined with edit operations, this creates a powerful find-then-edit workflow: locate exactly what needs to change, then make the change with precision.

This is the recommended approach for complex edits where the assistant needs to identify target locations before deciding how to modify them.

Why Search Before Editing

With built-in tools, finding content and editing content are separate concerns handled by different mechanisms. Often the assistant reads the entire file, scans for patterns visually, and then constructs a string replacement call. This is fragile because the assistant may misjudge line numbers or match the wrong occurrence.

Mouse's find_in_file returns structured results:

  • Line numbers for each match, usable directly in edit operations
  • Column positions for character-level targeting
  • Surrounding context to confirm the match is correct
  • Match counts to verify coverage (e.g., "found 12 occurrences across the file")

The assistant uses these results to construct precise, targeted edit operations with confidence in the positions.

The Workflow

The assistant uses find_in_file to locate all targets:

{
  "filePath": "/path/to/file.ts",
  "pattern": "expect(result.status).toBe(201)",
  "isRegex": false
}

Mouse returns each match with its line number, column range, and a few characters of surrounding context.

Step 2: Verify

If a match needs more surrounding context (for example, to confirm whether it's inside a function body or a comment), the assistant can call jump_to_line_n with the match's line number to see a focused viewport around that exact location. This is more efficient than reading the entire file or guessing at broad line ranges, because the assistant retrieves only the context it needs without wasting tokens on irrelevant content.

The assistant reviews the matches to confirm they're correct targets. If using regex, the assistant can refine the pattern and search again without any file modification.

Step 3: Edit

The assistant uses the match locations to construct exact edit operations:

{
  "operation": "replace",
  "find": "expect(result.status).toBe(201)",
  "replace": "expect(result.status).toBe(200)"
}

Or, for more precision, using the line and column information from the search results:

{
  "operation": "replace_range",
  "region": [
    [45, 32],
    [45, 35]
  ],
  "content": "200"
}

Column Analysis for Rectangular Edits

When find_in_file is called with showColumns: true, the response includes column analysis with a rect notation, a copy-paste ready specification for rectangular editing:

rect: [[10, 29], 13, 41]

This describes a rectangle starting at row 10, column 29, with width 13 and height 41. The assistant can copy this directly into an ADJUST operation:

{
  "operation": "adjust",
  "rect": [[10, 29], 13, 41],
  "move": [0, 82]
}

This zero-calculation workflow is designed for columnar operations on tabular data, CSV files, and aligned content: the assistant finds the column region, gets the rect notation, and moves it where it needs to go.

Regex Support

find_in_file supports full regex patterns with:

  • Capture groups
  • Character classes and quantifiers
  • Alternation
  • Anchors
  • Lookahead and lookbehind

Patterns are validated for security and bounded execution to prevent ReDoS attacks.

NOTE

Mouse's edit operations (INSERT, REPLACE, DELETE, etc.) use literal text matching only. Regex is not supported in edit operations themselves. Use find_in_file with regex to locate patterns, then use the resulting line and column positions for precise edits.

Staged Searching

When the Dialog Box state is active (staged changes pending), find_in_file can search either the original file or the staged version:

  • staged: false (default): Search the file as it exists on disk
  • staged: true : Search the file as it would appear after saving staged changes

This allows the assistant to verify that staged edits produced the expected result by searching for patterns that should (or shouldn't) appear in the staged content.

When to Use Find-Then-Edit

  • Updating multiple occurrences of a pattern across a file
  • Validating targets before making irreversible changes
  • Working with tabular data where column positions matter
  • Complex refactors where the assistant needs to understand the file's structure before editing
  • Post-edit verification to confirm that staged changes contain (or no longer contain) specific patterns