fix(codeagent-wrapper): remove 150-char truncation limit for KeyOutput in summary mode

maxLen=0 in extractKeyOutputFromLines now means unlimited, so the
orchestrator receives the agent's full concluding summary instead of
a 150-character stub. Negative maxLen still returns empty. Structured
summary format and log-path-only behaviour are preserved.

Generated with SWE-Agent.ai

Co-Authored-By: SWE-Agent.ai <noreply@swe-agent.ai>
This commit is contained in:
cexll
2026-03-03 11:12:02 +08:00
parent 08877af530
commit 64886d36e0
3 changed files with 41 additions and 6 deletions

View File

@@ -545,7 +545,7 @@ func runParallelMode(cmd *cobra.Command, args []string, opts *cliOptions, v *vip
results[i].CoverageNum = extractCoverageNum(results[i].Coverage)
results[i].FilesChanged = extractFilesChangedFromLines(lines)
results[i].TestsPassed, results[i].TestsFailed = extractTestResultsFromLines(lines)
results[i].KeyOutput = extractKeyOutputFromLines(lines, 150)
results[i].KeyOutput = extractKeyOutputFromLines(lines, 0)
}
if err := writeStructuredOutput(outputPath, results); err != nil {

View File

@@ -479,11 +479,19 @@ func extractNumberBefore(s string, idx int) int {
}
// extractKeyOutputFromLines extracts key output from pre-split lines.
// maxLen=0 means unlimited; maxLen<0 returns "".
func extractKeyOutputFromLines(lines []string, maxLen int) string {
if len(lines) == 0 || maxLen <= 0 {
if len(lines) == 0 || maxLen < 0 {
return ""
}
mayTruncate := func(s string) string {
if maxLen == 0 {
return s
}
return safeTruncate(s, maxLen)
}
// Priority 1: Look for explicit summary lines
for _, line := range lines {
line = strings.TrimSpace(line)
@@ -498,7 +506,7 @@ func extractKeyOutputFromLines(lines []string, maxLen int) string {
}
content = strings.TrimSpace(content)
if len(content) > 0 {
return safeTruncate(content, maxLen)
return mayTruncate(content)
}
}
}
@@ -514,10 +522,10 @@ func extractKeyOutputFromLines(lines []string, maxLen int) string {
if len(line) < 20 {
continue
}
return safeTruncate(line, maxLen)
return mayTruncate(line)
}
// Fallback: truncate entire message
// Fallback: return entire message
clean := strings.TrimSpace(strings.Join(lines, "\n"))
return safeTruncate(clean, maxLen)
return mayTruncate(clean)
}

View File

@@ -122,6 +122,33 @@ func TestSafeTruncate(t *testing.T) {
}
}
func TestExtractKeyOutputFromLines(t *testing.T) {
tests := []struct {
name string
lines []string
maxLen int
want string
}{
{"empty lines returns empty", []string{}, 0, ""},
{"negative maxLen returns empty", []string{"hello world"}, -1, ""},
{"unlimited: summary prefix returned in full", []string{"Summary: all done with a very long description that exceeds 150 characters and should not be cut off at all"}, 0, "all done with a very long description that exceeds 150 characters and should not be cut off at all"},
{"unlimited: first meaningful line returned in full", []string{"this is a meaningful line that is longer than twenty chars and should not be truncated"}, 0, "this is a meaningful line that is longer than twenty chars and should not be truncated"},
{"unlimited: skips noise lines", []string{"---", "# heading", "short", "this is a meaningful line longer than twenty chars"}, 0, "this is a meaningful line longer than twenty chars"},
{"limited: summary prefix truncated", []string{"Summary: hello world truncated"}, 10, "hello w..."},
{"limited: first meaningful line truncated", []string{"this is a long meaningful line that will be truncated"}, 20, "this is a long me..."},
{"unlimited: fallback joins all lines", []string{"short", "also short"}, 0, "short\nalso short"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := extractKeyOutputFromLines(tt.lines, tt.maxLen)
if got != tt.want {
t.Fatalf("extractKeyOutputFromLines(%v, %d) = %q, want %q", tt.lines, tt.maxLen, got, tt.want)
}
})
}
}
func TestSanitizeOutput(t *testing.T) {
tests := []struct {
name string