Fix CLI streaming: flush generated-code text before tool indicators

ober

35a77875285e3212e1f9959353aa4a629cb037ca

diff --git a/lib/jcode/ui/cli.sls b/lib/jcode/ui/cli.sls
index 0fc5dca..2ccbee3 100644
--- a/lib/jcode/ui/cli.sls
+++ b/lib/jcode/ui/cli.sls
@@ -273,6 +273,7 @@
   (def (md-flush!)
        (when (> (string-length *md-line-buf*) 0)
          (md-render-line *md-line-buf*)
+         (newline)
          (flush-output-port (current-output-port))
          (set! *md-line-buf* "")))
   (def (md-render-line line)
@@ -355,6 +356,8 @@
   (def (tool-indicator event name args)
        (case event
          [(start)
+          (md-flush!)
+          (when (> (string-length *md-line-buf*) 0) (newline))
           (printf "~n\x1B;[36m⟡ ~a\x1B;[0m" name)
           (let ([summary (tool-args-summary name args)])
             (when summary (printf " \x1B;[2m~a\x1B;[0m" summary)))
diff --git a/src/jcode/ui/cli.ss b/src/jcode/ui/cli.ss
index b9626ee..eee3d7d 100644
--- a/src/jcode/ui/cli.ss
+++ b/src/jcode/ui/cli.ss
@@ -277,6 +277,7 @@ EXAMPLES:
 (def (md-flush!)
   (when (> (string-length *md-line-buf*) 0)
     (md-render-line *md-line-buf*)
+    (newline)
     (flush-output-port (current-output-port))
     (set! *md-line-buf* "")))
 
@@ -345,6 +346,10 @@ EXAMPLES:
 (def (tool-indicator event name args)
   (case event
     ((start)
+     ;; Flush any pending LLM text so it appears ABOVE the tool line
+     (md-flush!)
+     (when (> (string-length *md-line-buf*) 0)
+       (newline))
      (printf "~n\x1b;[36m⟡ ~a\x1b;[0m" name)
      (let ((summary (tool-args-summary name args)))
        (when summary (printf " \x1b;[2m~a\x1b;[0m" summary)))