fix(telegram): require the truncation wrapper before treating a count as metadata
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.
This commit is contained in:
1 parent
d783bebf37
commit
5539f2b343
2 files changed
+23
-3
No files matched your search
@@ -153,10 +153,20 @@ type truncationNotice struct {
|
||||
}
|
||||
|
||||
// parseTruncationNotice reads "<shown>/<total> 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
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in new issue
Block a user