From 6f4b2c97a24967508f3970b46999052fd1f44e67 Mon Sep 17 00:00:00 2001 From: Omni Worker Date: Fri, 21 Nov 2025 22:22:07 -0500 Subject: fix(agent): simple ascii status bar to avoid xterm errors Amp-Thread-ID: https://ampcode.com/threads/T-79499d9e-f4f4-40de-893c-524c32a45483 Co-authored-by: Amp --- Omni/Agent/Log.hs | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/Omni/Agent/Log.hs b/Omni/Agent/Log.hs index 6541551..afaf1da 100644 --- a/Omni/Agent/Log.hs +++ b/Omni/Agent/Log.hs @@ -6,11 +6,11 @@ module Omni.Agent.Log where import Alpha +import Data.IORef (IORef, modifyIORef', newIORef, readIORef, writeIORef) import qualified Data.Text.IO as TIO import qualified System.Console.ANSI as ANSI import qualified System.IO as IO import System.IO.Unsafe (unsafePerformIO) -import Data.IORef (IORef, newIORef, readIORef, writeIORef, modifyIORef') -- | Status of the agent for the UI data Status = Status @@ -42,6 +42,7 @@ currentStatus = unsafePerformIO (newIORef (emptyStatus "Unknown")) -- | Initialize the status bar system init :: Text -> IO () init workerName = do + IO.hSetBuffering IO.stderr IO.LineBuffering writeIORef currentStatus (emptyStatus workerName) -- Reserve 2 lines at bottom IO.hPutStrLn IO.stderr "" @@ -66,10 +67,10 @@ log msg = do ANSI.hCursorDown IO.stderr 1 ANSI.hClearLine IO.stderr ANSI.hCursorUp IO.stderr 1 - + -- Print message (scrolls screen) TIO.hPutStrLn IO.stderr msg - + -- Re-render status bars at bottom -- (Since we scrolled, we are now on the line above where the first status line should be) render @@ -78,26 +79,33 @@ log msg = do render :: IO () render = do Status {..} <- readIORef currentStatus - + -- Line 1: Meta -- [Worker: name] Task: t-123 | Files: 3 | Credits: $0.45 | Time: 05:23 let taskStr = maybe "None" identity statusTask - meta = "[Worker: " <> statusWorker <> "] Task: " <> taskStr - <> " | Files: " <> tshow statusFiles - <> " | Credits: $" <> tshow statusCredits - <> " | Time: " <> statusTime - + meta = + "[Worker: " + <> statusWorker + <> "] Task: " + <> taskStr + <> " | Files: " + <> tshow statusFiles + <> " | Credits: $" + <> tshow statusCredits + <> " | Time: " + <> statusTime + ANSI.hSetCursorColumn IO.stderr 0 ANSI.hClearLine IO.stderr TIO.hPutStr IO.stderr meta - + -- Line 2: Activity - -- [14:05:22] 🤖 Thinking... + -- [14:05:22] > Thinking... ANSI.hCursorDown IO.stderr 1 ANSI.hSetCursorColumn IO.stderr 0 ANSI.hClearLine IO.stderr - TIO.hPutStr IO.stderr ("🤖 " <> statusActivity) - + TIO.hPutStr IO.stderr ("> " <> statusActivity) + -- Return cursor to line 1 ANSI.hCursorUp IO.stderr 1 IO.hFlush IO.stderr -- cgit v1.2.3