fix(tui-go): make the write/edit output-panel number meaningful

The collapsed tool row showed "tool output (N chars)" where N was len() of the
raw unified diff — i.e. the diff blob's *byte* length (headers, @@, +/-/context
all counted), labelled "chars". That number corresponded to nothing the operator
cares about, and len() is bytes not characters.

- Summarise a write/edit by the diff's row count instead — "· diff (7 rows) —
  ^x to view" — matching exactly what the ^x modal reports. Non-diff output (the
  defensive fallback) now counts runes, not bytes, so "N chars" is truthful.
  Retire itoaLen (the byte-count-as-"len" footgun).
- Harden the (+a −b) line counts in diffSummary: guard the file header with the
  trailing space ("+++ "/"--- "), so a changed line whose content starts with
  "++"/"--" is counted instead of mistaken for a header. Apply the same guard in
  parseUnifiedDiff so such a line is rendered (and counted) rather than dropped.

tool_summary_test.go covers the diff-row summary, the rune (not byte) count, and
the ++/-- content-line edge case.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-22 10:09:56 +00:00
parent 035f7df704
commit 4e4d7c186a
4 changed files with 65 additions and 5 deletions
+4 -1
View File
@@ -53,7 +53,10 @@ func parseUnifiedDiff(diff string) []diffRow {
}
for _, ln := range strings.Split(strings.TrimRight(diff, "\n"), "\n") {
switch {
case strings.HasPrefix(ln, "+++"), strings.HasPrefix(ln, "---"),
// File headers carry a trailing space ("+++ b/x"); requiring it means a real
// changed line whose content starts with "++"/"--" isn't mistaken for a header
// and silently dropped from the rendered diff (and its row count).
case strings.HasPrefix(ln, "+++ "), strings.HasPrefix(ln, "--- "),
strings.HasPrefix(ln, "diff "), strings.HasPrefix(ln, "index "):
continue
case strings.HasPrefix(ln, "@@"):