Skip to content
Closed
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
25 changes: 13 additions & 12 deletions libs/code/deepagents_code/tui/widgets/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1982,18 +1982,19 @@ def _format_ls_output( # noqa: PLR6301 # Grouped as method for widget cohesion

@staticmethod
def _compact_line_gutter(output: str) -> str:
r"""Tighten `read_file`'s cat -n line-number gutter for display.

The tool emits `f"{line_num:6d}\t{line}"` — a 6-wide right-justified
number plus a tab — so even single-digit line numbers carry five
leading spaces and the tab pushes content to a distant tab stop. The
model needs that raw format for edits, but the TUI renders a compact
gutter instead: numbers right-justified to the widest number actually
present, then two spaces, mirroring how grep/glob results sit flush
left. Source indentation after the gutter is preserved untouched.

Lines that don't match the cat -n shape (e.g. test fixtures or
non-numbered output) are passed through unchanged.
r"""Tighten legacy `read_file` cat-n line-number gutters for display.

Older tool output used `f"{line_num:6d}\t{line}"` — a 6-wide
right-justified number plus a tab — so even single-digit line numbers
carried five leading spaces and the tab pushed content to a distant tab
stop. The TUI renders that legacy gutter in the newer compact shape:
numbers right-justified to the widest number actually present, then two
spaces, mirroring how grep/glob results sit flush left. Source
indentation after the gutter is preserved untouched.

Lines that don't match the legacy cat-n shape (e.g. current compact
read output, test fixtures, or non-numbered output) are passed through
unchanged.

Returns:
The output with compacted gutters, or the original string if no
Expand Down
12 changes: 6 additions & 6 deletions libs/code/tests/unit_tests/tui/widgets/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2760,14 +2760,14 @@ def test_format_file_output_preview_budget_hit_on_separator(self) -> None:
def test_format_output_compacts_line_number_gutter(self) -> None:
r"""Line-number gutters are tightened, all rows aligned to one column.

`read_file` emits `f"{line_num:6d}\t{line}"` — a 6-wide right-justified
number plus a tab — which renders far from the line numbers and (when
the first row's padding was stripped) misaligned. The TUI recomputes a
compact gutter: numbers right-justified to the widest number present,
two spaces, then the original source indentation.
Legacy `read_file` output used `f"{line_num:6d}\t{line}"` — a 6-wide
right-justified number plus a tab — which renders far from the line
numbers and (when the first row's padding was stripped) misaligned. The
TUI recomputes a compact gutter: numbers right-justified to the widest
number present, two spaces, then the original source indentation.
"""
msg = ToolCallMessage("read_file", {"path": "/tmp/a.py"})
# cat -n style: 6-wide right-justified number + tab + source line.
# Legacy cat-n style: 6-wide right-justified number + tab + source line.
output = ' 1\t"""doc"""\n 2\t\n 3\t indented'
result = msg._format_output(output, is_preview=False)

Expand Down
Loading