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
+2 -2
View File
@@ -425,9 +425,9 @@ func diffSummary(diff string) (path string, added, removed int) {
if p != "" && p != "/dev/null" {
path = p
}
case strings.HasPrefix(ln, "+") && !strings.HasPrefix(ln, "+++"):
case strings.HasPrefix(ln, "+") && !strings.HasPrefix(ln, "+++ "):
added++
case strings.HasPrefix(ln, "-") && !strings.HasPrefix(ln, "---"):
case strings.HasPrefix(ln, "-") && !strings.HasPrefix(ln, "--- "):
removed++
}
}