Tools::TextEditing::ReplaceTextInTextFileTool::Runner
Inherits Tools::FileHelper < LLM::Function::Runner < Reference < Object
The Runner class executes the function
Constants
CONTEXT_LINES = 2
Instance methods
Main entry point: performs the string replacement and returns structured results.
- Extracts and validates required parameters (file_path, old_str, new_str, occurrence)
- Resolves the file path and verifies it is within the allowed directory
- Rejects paths that point to the deleted-files folder
- Reads the file content
- Finds all match positions of the search text in the content
- Raises an error if no matches are found
- Raises an error if
occurrenceis out of range (positive int greater than match count) - Selects target positions based on
occurrence(specific index or all) - Replaces the text at each target position to produce new content
- Builds change hunks (before/after snippets with context) for the response
- Writes the new content to disk
- Returns a JSON-encoded success response with the file path, replacement count, and an array of change hunks