Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions astrbot/core/tools/computer_tools/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,11 @@ async def call(
)
if not normalized_path:
raise ValueError("`path` must be a non-empty string.")
if local_env and os.path.isdir(normalized_path):
return (
f"Error: '{normalized_path}' is a directory, not a file. "
"Use a file path instead, or use 'astrbot_execute_shell' to list directory contents."
)
Comment thread
Fronut marked this conversation as resolved.
Comment thread
Fronut marked this conversation as resolved.
offset, limit = self._validate_read_window(offset, limit)
sb = await get_booter(
context.context.context,
Expand Down
20 changes: 20 additions & 0 deletions tests/test_computer_fs_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,3 +620,23 @@ async def test_grep_tool_applies_result_limit(
assert "match-2" in result
assert "match-3" not in result
assert "[Truncated to first 2 result groups.]" in result


@pytest.mark.asyncio
async def test_file_read_tool_rejects_directory_with_clear_message(
monkeypatch: pytest.MonkeyPatch,
tmp_path,
):
"""FileReadTool should return a helpful message when given a directory path."""
workspace = _setup_local_fs_tools(monkeypatch, tmp_path)
subdir = workspace / "my-directory"
subdir.mkdir()

result = await fs_tools.FileReadTool().call(
_make_context(),
path="my-directory",
)

assert "is a directory, not a file" in result
assert "my-directory" in result
assert "'astrbot_execute_shell'" in result
Loading