fix(main): improve buffer size and streamline message extraction

This commit is contained in:
freespace8
2025-11-28 15:10:39 +08:00
parent 291a4e3d0a
commit aea19f0e1f

View File

@@ -347,9 +347,7 @@ func runCodexProcess(codexArgs []string, taskText string, useStdin bool, timeout
func parseJSONStream(r io.Reader) (message, threadID string) { func parseJSONStream(r io.Reader) (message, threadID string) {
scanner := bufio.NewScanner(r) scanner := bufio.NewScanner(r)
// Set larger buffer for long lines scanner.Buffer(make([]byte, 64*1024), 10*1024*1024)
buf := make([]byte, 0, 64*1024)
scanner.Buffer(buf, 1024*1024)
for scanner.Scan() { for scanner.Scan() {
line := strings.TrimSpace(scanner.Text()) line := strings.TrimSpace(scanner.Text())
@@ -369,18 +367,15 @@ func parseJSONStream(r io.Reader) (message, threadID string) {
} }
// Capture agent_message // Capture agent_message
if event.Type == "item.completed" && event.Item != nil { if event.Type == "item.completed" && event.Item != nil && event.Item.Type == "agent_message" {
if event.Item.Type == "agent_message" { if text := normalizeText(event.Item.Text); text != "" {
text := normalizeText(event.Item.Text)
if text != "" {
message = text message = text
} }
} }
} }
}
if err := scanner.Err(); err != nil { if err := scanner.Err(); err != nil && err != io.EOF {
logWarn("Scanner error: " + err.Error()) logWarn("Read stdout error: " + err.Error())
} }
return message, threadID return message, threadID