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
19 changes: 14 additions & 5 deletions cecli/tools/read_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,20 @@ def execute(cls, coder, show, **kwargs):
num_lines = len(lines)

if num_lines == 0:
# Handle empty file case
output_lines = [f"File {rel_path} is empty."]
if show_index > 0:
all_outputs.append("")
all_outputs.extend(output_lines)
new_context_details.append(
"\n".join(
[
f"File {rel_path} is empty.",
(
"Next: use EditText with start_line @000 and end_line @000 to"
" write content, or ContextManager to scaffold — do not call"
" ReadRange again on this empty file."
),
]
)
)
new_context_retrieved.append(rel_path)
cls._last_read_turn[abs_path] = coder.turn_count
continue
# 4. Determine line range
start_line_idx = -1
Expand Down
28 changes: 28 additions & 0 deletions tests/tools/test_get_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,31 @@ def test_multiline_pattern_search(coder_with_file):

assert "Retrieved context for 1 operation(s)" in result
coder.io.tool_error.assert_not_called()


def test_empty_file_includes_edit_hint(tmp_path):
empty = tmp_path / "pubspec.yaml"
empty.write_text("")
coder = DummyCoder(tmp_path)

from unittest.mock import patch

with patch("cecli.helpers.conversation.ConversationService") as conv:
conv.get_files.return_value.clear_ranges = Mock()
conv.get_files.return_value.push_range = Mock()
conv.get_chunks.return_value.add_file_context_messages = Mock()
result = read_range.Tool.execute(
coder,
show=[
{
"file_path": "pubspec.yaml",
"start_text": "@000",
"end_text": "@000",
}
],
)

assert "pubspec.yaml is empty" in result
assert "EditText" in result
assert "readrange again" in result.lower()
coder.io.tool_error.assert_not_called()
Loading