diff --git a/src/goose/toolkit/developer.py b/src/goose/toolkit/developer.py index 4c2f1888e..fd3fa1853 100644 --- a/src/goose/toolkit/developer.py +++ b/src/goose/toolkit/developer.py @@ -19,6 +19,7 @@ # Global dictionary to store the last read timestamps last_read_timestamps: Dict[str, float] = {} + def keep_unsafe_command_prompt(command: str) -> PromptType: command_text = Text(command, style="bold red") message = ( diff --git a/tests/toolkit/test_developer.py b/tests/toolkit/test_developer.py index a3a291afd..60a26caf2 100644 --- a/tests/toolkit/test_developer.py +++ b/tests/toolkit/test_developer.py @@ -93,3 +93,21 @@ def test_write_file(temp_dir, developer_toolkit): content = "Hello World" developer_toolkit.write_file(test_file.as_posix(), content) assert test_file.read_text() == content + + +def test_write_file_prevent_write_if_changed(temp_dir, developer_toolkit): + test_file = temp_dir / "test.txt" + content = "Hello World" + updated_content = "Hello Universe" + + # Initial write to record the timestamp + developer_toolkit.write_file(test_file.as_posix(), content) + developer_toolkit.read_file(test_file.as_posix()) + + # Modify file externally to simulate change + test_file.write_text(updated_content) + + # Try to write through toolkit and check response + result = developer_toolkit.write_file(test_file.as_posix(), content) + assert result.endswith("has been modified since it was last read. Not writing to file.") + assert test_file.read_text() == updated_content