detached 4c37e30

feat(tui): show changed file count on multi-file tool results (#238)

commit
4c37e30c2bfbe51787227b5eaad34461209a68d1
author
bnema · · 2026-09-30 16:24 UTC
committer
GitHub · · 2026-09-30 16:24 UTC
parent
4ce882c
signature
GPG UnverifiedB5690EEEBB952194 The key is unknown
2 files · +46 -0
M packages/tui/view.go +10 -0
@@ -1127,6 +1127,7 @@ func (v *View) renderMessage(m provider.Message, width int, turnOpen bool) []str
11271127 if v.toolCallLabels != nil {
11281128 label = v.toolCallLabels[tr.CallID]
11291129 }
1130+ label += mutatedFilesSuffix(tr.Context.Mutates)
11301131 // Each tool result owns a complete box: top edge with
11311132 // the call's label, body rows wrapped in vertical
11321133 // edges, bottom edge to close. The label is looked up
@@ -2534,6 +2535,15 @@ func (v *View) renderBashResult(lines []string, width int, defaultColor Terminal
25342535 return out
25352536 }
25362537
2538+// mutatedFilesSuffix labels a tool result that changed several files, so a
2539+// project-wide rewrite shows its scope. Single-file edits stay unlabeled.
2540+func mutatedFilesSuffix(paths []string) string {
2541+ if len(paths) < 2 {
2542+ return ""
2543+ }
2544+ return fmt.Sprintf(" · %d files changed", len(paths))
2545+}
2546+
25372547 // astRewriteArgs reports whether a completed AST call requested mutation.
25382548 func astRewriteArgs(name string, raw json.RawMessage) bool {
25392549 if !strings.EqualFold(name, "ast") {
@@ -1127,6 +1127,7 @@ func (v *View) renderMessage(m provider.Message, width int, turnOpen bool) []str
1127 if v.toolCallLabels != nil {1127 if v.toolCallLabels != nil {
1128 label = v.toolCallLabels[tr.CallID]1128 label = v.toolCallLabels[tr.CallID]
1129 }1129 }
1130+ label += mutatedFilesSuffix(tr.Context.Mutates)
1130 // Each tool result owns a complete box: top edge with1131 // Each tool result owns a complete box: top edge with
1131 // the call's label, body rows wrapped in vertical1132 // the call's label, body rows wrapped in vertical
1132 // edges, bottom edge to close. The label is looked up1133 // edges, bottom edge to close. The label is looked up
@@ -2534,6 +2535,15 @@ func (v *View) renderBashResult(lines []string, width int, defaultColor Terminal
2534 return out2535 return out
2535 }2536 }
2536 2537
2538+// mutatedFilesSuffix labels a tool result that changed several files, so a
2539+// project-wide rewrite shows its scope. Single-file edits stay unlabeled.
2540+func mutatedFilesSuffix(paths []string) string {
2541+ if len(paths) < 2 {
2542+ return ""
2543+ }
2544+ return fmt.Sprintf(" · %d files changed", len(paths))
2545+}
2546+
2537 // astRewriteArgs reports whether a completed AST call requested mutation.2547 // astRewriteArgs reports whether a completed AST call requested mutation.
2538 func astRewriteArgs(name string, raw json.RawMessage) bool {2548 func astRewriteArgs(name string, raw json.RawMessage) bool {
2539 if !strings.EqualFold(name, "ast") {2549 if !strings.EqualFold(name, "ast") {
M packages/tui/view_tool_overlay_test.go +36 -0
@@ -218,6 +218,42 @@ func TestCompletedASTRewriteRendersPersistentDiff(t *testing.T) {
218218 }
219219 }
220220
221+func TestMultiFileRewriteLabelShowsChangedFileCount(t *testing.T) {
222+ args := json.RawMessage(`{"pattern":"old($A)","language":"go","path":"src","rewrite":"new($A)"}`)
223+ for _, tc := range []struct {
224+ name string
225+ mutates []string
226+ want bool
227+ }{
228+ {"several files", []string{"src/a.go", "src/b.go", "src/c.go"}, true},
229+ {"single file", []string{"src/a.go"}, false},
230+ } {
231+ t.Run(tc.name, func(t *testing.T) {
232+ for _, flat := range []bool{false, true} {
233+ v := View{
234+ Theme: Dark,
235+ FlatTools: flat,
236+ Messages: []provider.Message{
237+ {Role: provider.RoleAssistant, Content: []provider.Content{provider.ToolCallBlock{ID: "toolu_ast", Name: "ast", Arguments: args}}},
238+ {Role: provider.RoleTool, Content: []provider.Content{provider.ToolResultBlock{
239+ CallID: "toolu_ast",
240+ Content: []provider.Content{provider.TextBlock{Text: "-old(value)\n+new(value)\n"}},
241+ Context: provider.ToolContext{Mutates: tc.mutates},
242+ }}},
243+ },
244+ }
245+ plain := stripANSI(strings.Join(v.Build(80), "\n"))
246+ if got := strings.Contains(plain, "ast src · 3 files changed"); got != tc.want {
247+ t.Fatalf("flat=%v: file count shown = %v, want %v:\n%s", flat, got, tc.want, plain)
248+ }
249+ if strings.Contains(plain, "files changed") != tc.want {
250+ t.Fatalf("flat=%v: unexpected file count label:\n%s", flat, plain)
251+ }
252+ }
253+ })
254+ }
255+}
256+
221257 func TestASTSearchResultIsNotForcedIntoDiffRendering(t *testing.T) {
222258 args := json.RawMessage(`{"pattern":"old($A)","language":"go","path":"sample.go"}`)
223259 v := View{
@@ -218,6 +218,42 @@ func TestCompletedASTRewriteRendersPersistentDiff(t *testing.T) {
218 }218 }
219 }219 }
220 220
221+func TestMultiFileRewriteLabelShowsChangedFileCount(t *testing.T) {
222+ args := json.RawMessage(`{"pattern":"old($A)","language":"go","path":"src","rewrite":"new($A)"}`)
223+ for _, tc := range []struct {
224+ name string
225+ mutates []string
226+ want bool
227+ }{
228+ {"several files", []string{"src/a.go", "src/b.go", "src/c.go"}, true},
229+ {"single file", []string{"src/a.go"}, false},
230+ } {
231+ t.Run(tc.name, func(t *testing.T) {
232+ for _, flat := range []bool{false, true} {
233+ v := View{
234+ Theme: Dark,
235+ FlatTools: flat,
236+ Messages: []provider.Message{
237+ {Role: provider.RoleAssistant, Content: []provider.Content{provider.ToolCallBlock{ID: "toolu_ast", Name: "ast", Arguments: args}}},
238+ {Role: provider.RoleTool, Content: []provider.Content{provider.ToolResultBlock{
239+ CallID: "toolu_ast",
240+ Content: []provider.Content{provider.TextBlock{Text: "-old(value)\n+new(value)\n"}},
241+ Context: provider.ToolContext{Mutates: tc.mutates},
242+ }}},
243+ },
244+ }
245+ plain := stripANSI(strings.Join(v.Build(80), "\n"))
246+ if got := strings.Contains(plain, "ast src · 3 files changed"); got != tc.want {
247+ t.Fatalf("flat=%v: file count shown = %v, want %v:\n%s", flat, got, tc.want, plain)
248+ }
249+ if strings.Contains(plain, "files changed") != tc.want {
250+ t.Fatalf("flat=%v: unexpected file count label:\n%s", flat, plain)
251+ }
252+ }
253+ })
254+ }
255+}
256+
221 func TestASTSearchResultIsNotForcedIntoDiffRendering(t *testing.T) {257 func TestASTSearchResultIsNotForcedIntoDiffRendering(t *testing.T) {
222 args := json.RawMessage(`{"pattern":"old($A)","language":"go","path":"sample.go"}`)258 args := json.RawMessage(`{"pattern":"old($A)","language":"go","path":"sample.go"}`)
223 v := View{259 v := View{

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 476

↑↓ moveenter openesc close