diff --git a/session/session.go b/session/session.go index 10fd0a3..7322412 100644 --- a/session/session.go +++ b/session/session.go @@ -147,17 +147,15 @@ func (sess *Session) startEventLog() { sess.AppendLog(FormatEvent(ev)) case "tool": - // Tool events can stream (multiple chunks with same name) or - // arrive as a single final result. Write header on first chunk, - // then append content. Duplicate final result is suppressed. + // Tool events: empty content = header-only (stream start), + // non-empty while streaming = chunk, non-empty without streaming = full result. if streamingRole == "tool" { - // Continuation of streaming tool output. - if ev.Content != "" { - sess.AppendLog([]byte(ev.Content)) - } else { - // Empty content = final result marker; streaming is done. + if ev.Content == "" { + // End of stream. sess.AppendLog([]byte("\n")) streamingRole = "" + } else { + sess.AppendLog([]byte(ev.Content)) } return } @@ -165,12 +163,14 @@ func (sess *Session) startEventLog() { sess.AppendLog([]byte("\n")) streamingRole = "" } - // First tool event — write header and start streaming. - sess.AppendLog([]byte("[tool:" + ev.Name + "]\n")) - if ev.Content != "" { - sess.AppendLog([]byte(ev.Content)) + if ev.Content == "" { + // Stream start: write header, enter streaming mode. + sess.AppendLog([]byte("[tool:" + ev.Name + "]\n")) + streamingRole = "tool" + } else { + // Non-streamed tool result (fast tool, no streaming happened). + sess.AppendLog(FormatEvent(ev)) } - streamingRole = "tool" case "call": if streamingRole != "" {