plexus.cli.shared.file_editor module

Implementation of the file editing tool protocol for Plexus’s self-improving AI agents.

This module implements the file editing tool protocol as defined in: https://docs.anthropic.com/en/docs/build-with-claude/tool-use/text-editor-tool

The file editing capabilities are a critical component of Plexus’s agent-based data processing system, enabling AI agents to modify and improve their own code. This is part of Plexus’s self-improving AI architecture described at: https://plexus.anth.us/solutions/platform

The FileEditor class provides the following operations: - Viewing file contents - Replacing text - Inserting text - Creating new files - Undoing changes

Each operation includes automatic backup creation and error handling to ensure safe file modifications by AI agents.

class plexus.cli.shared.file_editor.FileEditor(debug: bool = False)

Bases: object

A class to handle file editing operations for LLM tool calls.

Initialize the FileEditor.

Args:

debug: Whether to enable debug mode with more verbose output

__init__(debug: bool = False)

Initialize the FileEditor.

Args:

debug: Whether to enable debug mode with more verbose output

create(file_path: str, file_text: str = '') str

Create a new file with the specified content.

Args:

file_path: Path to the file to create file_text: Content to write to the file (default: empty string)

Returns:

str: Success or error message

insert(file_path: str, insert_line: int, new_str: str) str

Insert text at a specific line in a file.

Args:

file_path: Path to the file to edit insert_line: Line number to insert at (0-based) new_str: Text to insert

Returns:

A status message indicating success or failure

str_replace(file_path: str, old_str: str, new_str: str = '') str

Replace text in a file.

Args:

file_path: Path to the file to edit old_str: Text to replace new_str: Text to replace with (can be empty to delete the old_str)

Returns:

A status message indicating success or failure

Raises:

FileNotFoundError: If the file does not exist

undo_edit(file_path: str) str

Undo the last edit made to a file.

Args:

file_path: Path to the file to undo changes for

Returns:

A status message indicating success or failure

view(file_path: str) str

View the contents of a file.

Args:

file_path: Path to the file to view

Returns:

The contents of the file as a string

Raises:

FileNotFoundError: If the file does not exist