From 5539f2b343251a9fb789f6e40dc07d94f84b7e10 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Thu, 17 Sep 2026 10:13:07 +0000 Subject: [PATCH] fix(telegram): require the truncation wrapper before treating a count as metadata MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review found that a bare "showing 3/197 lines" inside ordinary output was accepted as truncation metadata and replaced by a summary, hiding the real result. Both built-in producers wrap the notice as "[truncated: …]" (internal/tools/builtin/truncate.go), so the wrapper is now required rather than tolerated: it is the only marker separating a notice the tool printed from content that merely mentions a count. --- internal/gateway/stream.go | 16 +++++++++++++--- internal/gateway/tool_render_report_test.go | 10 ++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/internal/gateway/stream.go b/internal/gateway/stream.go index 63c46f35e..4a49dad1f 100644 --- a/internal/gateway/stream.go +++ b/internal/gateway/stream.go @@ -153,10 +153,20 @@ type truncationNotice struct { } // parseTruncationNotice reads "/ lines" out of a truncation -// notice, accepting both the plain and the "showing last" form and tolerating -// the surrounding "[truncated: … ]" wrapper. +// notice, accepting both the plain and the "showing last" form. +// +// The "[truncated: … ]" wrapper is required, not tolerated. It is the only +// marker that distinguishes a notice the tool printed from ordinary output that +// happens to contain the same phrasing: both built-in producers emit the +// wrapper (internal/tools/builtin/truncate.go), so a bare "showing 3/197 lines" +// inside a log or a document is content and must be left alone rather than +// replaced by a summary. func parseTruncationNotice(line string) (truncationNotice, bool) { - _, rest, found := strings.Cut(line, "showing ") + _, rest, found := strings.Cut(line, "[truncated: ") + if !found { + return truncationNotice{}, false + } + _, rest, found = strings.Cut(rest, "showing ") if !found { return truncationNotice{}, false } diff --git a/internal/gateway/tool_render_report_test.go b/internal/gateway/tool_render_report_test.go index f5b5d2e4d..50db5af63 100644 --- a/internal/gateway/tool_render_report_test.go +++ b/internal/gateway/tool_render_report_test.go @@ -103,6 +103,16 @@ func TestToolPreviewDescribesTheResult(t *testing.T) { output: "/home/example/go/pkg/mod/github.com/x/y@v1.0/z.go\npackage y", want: "package y", }, + { + // Only the built-in truncation producers emit this phrasing, and + // they always wrap it as "[truncated: …]". Accepting the phrasing on + // its own would rewrite genuine output that merely mentions a count + // as if it were a truncation notice, hiding the real result. + name: "ordinary text mentioning a line count is not truncation metadata", + tool: "shell", + output: "the log said showing 3/197 lines before it continued\nand trailing output", + want: "the log said showing 3/197 lines before it continued", + }, { name: "empty output is reported as completed without a preview", tool: "shell",