SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]
Fix: Show exactly $window many lines (not $window + 1)
Kilian Lieret57a5f0a45b5d
diff --git a/tests/tools/test_default_utils.py b/tests/tools/test_default_utils.pyindex ca18b14c..cdd8fa65 100644--- a/tests/tools/test_default_utils.py+++ b/tests/tools/test_default_utils.py@@ -47,18 +47,18 @@ def test_windowed_file(windowed_file):assert wfile.window == 10assert wfile.n_lines == 100a, b = wfile.line_range- assert b - a == wfile.window- assert wfile.line_range == (10, 20)+ assert b - a == wfile.window - 1+ assert wfile.line_range == (10, 19)wfile.print_window()wfile.replace_in_window("10", "Hello, world!")assert wfile.n_lines == 100- assert wfile.line_range == (7, 17)+ assert wfile.line_range == (7, 16)wfile.first_line = 50wfile.print_window()wfile.replace_in_window("50", "Hello, world!")wfile.print_window()# Line 50 is now the 2nd line of the new window- assert wfile.line_range == (47, 57)+ assert wfile.line_range == (47, 56)with pytest.raises(default_utils.TextNotFound):wfile.replace_in_window("asdf", "Hello, world!")@@ -119,8 +119,7 @@ _DEFAULT_WINDOW_OUTPUT = """[File: {path} (100 lines total)]18:1719:1820:19-21:20-(79 more lines below)+(80 more lines below)"""diff --git a/tools/defaults/lib/default_utils.py b/tools/defaults/lib/default_utils.pyindex 9579964e..f9353c32 100644--- a/tools/defaults/lib/default_utils.py+++ b/tools/defaults/lib/default_utils.py@@ -151,12 +151,13 @@ class WindowedFile:@propertydef line_range(self) -> tuple[int, int]:- """Return first and last line (inclusive) of the window.- `line_range[1] - line_range[0] == window` as long as there are+ """Return first and last line (inclusive) of the display window, such+ that exactly `window` many lines are displayed.+ This means `line_range[1] - line_range[0] == window-1` as long as there areat least `window` lines in the file. `first_line` does the handlingof making sure that we don't go out of bounds."""- return self.first_line, min(self.first_line + self.window, self.n_lines - 1)+ return self.first_line, min(self.first_line + self.window - 1, self.n_lines - 1)def get_window_text(self, *, line_numbers: bool = False, status_line: bool = False, pre_post_line: bool = False