feat(tools): stream shell_run output live into the TUI

This commit is contained in:
loveuer
2026-08-13 13:56:24 +08:00
parent 28195519d1
commit 47671f3098
8 changed files with 302 additions and 28 deletions
+15 -3
View File
@@ -683,15 +683,27 @@ func (m *model) mergeToolLog(text string) bool {
if incoming.output == "" {
return false
}
incomingHeader, _, ok := strings.Cut(text, "\n[output]\n")
if !ok {
return false
}
for i := len(m.messages) - 1; i >= 0; i-- {
if m.messages[i].role != roleTool {
continue
}
existing := parseToolLog(m.messages[i].content)
if existing.name == incoming.name && existing.args == incoming.args && existing.output == "" {
m.messages[i].content = text
return true
if existing.name != incoming.name || existing.args != incoming.args {
continue
}
if !strings.Contains(m.messages[i].content, "\n[output]\n") {
// Placeholder card from the tool-start log; first chunk fills it.
m.messages[i].content = text
} else {
// Streaming tools send incremental chunks; append the raw delta
// so line boundaries are preserved inside the same card.
m.messages[i].content += strings.TrimPrefix(text, incomingHeader+"\n[output]\n")
}
return true
}
return false
}