From a4a733d965c6d54f5b436c33aefa306a48463492 Mon Sep 17 00:00:00 2001 From: chengyongru Date: Thu, 24 Sep 2026 11:34:14 +0800 Subject: [PATCH] refactor(tools): remove unused global file state compatibility --- nanobot/agent/tools/file_state.py | 35 --------------------------- tests/tools/test_edit_advanced.py | 9 ------- tests/tools/test_edit_enhancements.py | 8 ------ tests/tools/test_read_enhancements.py | 7 ------ 4 files changed, 59 deletions(-) diff --git a/nanobot/agent/tools/file_state.py b/nanobot/agent/tools/file_state.py index bb60a5faa..686ee8b99 100644 --- a/nanobot/agent/tools/file_state.py +++ b/nanobot/agent/tools/file_state.py @@ -100,10 +100,6 @@ class FileStates: """Return the raw ReadState entry for a path, or None.""" return self._state.get(str(Path(path).resolve())) - def raw_state(self) -> dict[str, ReadState]: - """Return the mutable backing map for legacy compatibility.""" - return self._state - def clear(self) -> None: """Clear all tracked state (useful for testing).""" self._state.clear() @@ -156,34 +152,3 @@ def bind_file_states(file_states: FileStates) -> Token[FileStates | None]: def reset_file_states(token: Token[FileStates | None]) -> None: _current_file_states.reset(token) - - -# Module-level default instance, retained for backward compatibility with -# tests and callers that reach in directly. Per-session callers should hold -# their own FileStates instance instead of touching this one. -_default = FileStates() - - -def record_read(path: str | Path, offset: int = 1, limit: int | None = None) -> None: - _default.record_read(path, offset=offset, limit=limit) - - -def record_write(path: str | Path) -> None: - _default.record_write(path) - - -def is_unchanged(path: str | Path, offset: int = 1, limit: int | None = None) -> bool: - return _default.is_unchanged(path, offset=offset, limit=limit) - - -def clear() -> None: - _default.clear() - - -# Legacy attribute for callers that reached into the module-level dict -# directly (filesystem.py used to do this). Kept as a property-like accessor -# so existing imports keep working. -def __getattr__(name: str): - if name == "_state": - return _default.raw_state() - raise AttributeError(name) diff --git a/tests/tools/test_edit_advanced.py b/tests/tools/test_edit_advanced.py index 08675aa22..26323a3d1 100644 --- a/tests/tools/test_edit_advanced.py +++ b/tests/tools/test_edit_advanced.py @@ -12,17 +12,8 @@ import os import pytest -from nanobot.agent.tools import file_state from nanobot.agent.tools.filesystem import EditFileTool, ReadFileTool - -@pytest.fixture(autouse=True) -def _clear_file_state(): - file_state.clear() - yield - file_state.clear() - - # --------------------------------------------------------------------------- # Delete-line newline cleanup # --------------------------------------------------------------------------- diff --git a/tests/tools/test_edit_enhancements.py b/tests/tools/test_edit_enhancements.py index fbf08b43c..4b2ebcf29 100644 --- a/tests/tools/test_edit_enhancements.py +++ b/tests/tools/test_edit_enhancements.py @@ -13,14 +13,6 @@ from nanobot.agent.tools.filesystem import EditFileTool, ReadFileTool # Helpers # --------------------------------------------------------------------------- -@pytest.fixture(autouse=True) -def _clear_file_state(): - """Reset global read-state between tests.""" - file_state.clear() - yield - file_state.clear() - - # --------------------------------------------------------------------------- # Read-independent editing # --------------------------------------------------------------------------- diff --git a/tests/tools/test_read_enhancements.py b/tests/tools/test_read_enhancements.py index 5e3c91bbc..756618c61 100644 --- a/tests/tools/test_read_enhancements.py +++ b/tests/tools/test_read_enhancements.py @@ -23,13 +23,6 @@ def _document_source(text: str) -> DocumentLineSource: return DocumentLineSource(lines) -@pytest.fixture(autouse=True) -def _clear_file_state(): - file_state.clear() - yield - file_state.clear() - - # --------------------------------------------------------------------------- # Description fix # ---------------------------------------------------------------------------