Show file content preview in tool widget for write/edit calls before approval
- SHA
b2fd90ce4011a0369028e2e6cd23e7815f8abcde- Parents
-
0f650d2 - Tree
aba79a2
b2fd90c
b2fd90ce4011a0369028e2e6cd23e7815f8abcde0f650d2
aba79a2| Status | File | + | - |
|---|---|---|---|
| M |
src/loader/ui/widgets/tool_widget.py
|
17 | 1 |
src/loader/ui/widgets/tool_widget.pymodified@@ -47,7 +47,23 @@ class ToolCallWidget(Vertical): | ||
| 47 | 47 | id="tool-header", |
| 48 | 48 | classes="tool-header", |
| 49 | 49 | ) |
| 50 | - yield Static("", id="tool-summary", classes="tool-summary") | |
| 50 | + | |
| 51 | + # For write/edit tools, show the content as a pre-approval preview | |
| 52 | + initial_summary = Text() | |
| 53 | + if self.tool_name in ("write", "edit", "patch"): | |
| 54 | + content = self.tool_args.get("content", "") | |
| 55 | + file_path = self.tool_args.get("file_path", "") | |
| 56 | + if content and file_path: | |
| 57 | + initial_summary.append(f" ► {file_path}\n", style="bold") | |
| 58 | + lines = content.splitlines() | |
| 59 | + for i, line in enumerate(lines[:20]): | |
| 60 | + initial_summary.append(f" {i + 1:>3} ", style="dim") | |
| 61 | + initial_summary.append(f"{line}\n") | |
| 62 | + if len(lines) > 20: | |
| 63 | + initial_summary.append( | |
| 64 | + f" ... ({len(lines) - 20} more lines)\n", style="dim" | |
| 65 | + ) | |
| 66 | + yield Static(initial_summary, id="tool-summary", classes="tool-summary") | |
| 51 | 67 | |
| 52 | 68 | # Toggle button for expand/collapse (hidden by default until result has more lines) |
| 53 | 69 | toggle = Button("▶ Show full output", id="tool-toggle", classes="tool-toggle", variant="default") |