summaryrefslogtreecommitdiff
path: root/Omni/Agent/Worker.hs
diff options
context:
space:
mode:
authorOmni Worker <bot@omni.agent>2025-11-22 05:44:37 -0500
committerOmni Worker <bot@omni.agent>2025-11-22 05:44:37 -0500
commit7b2eb67300010a1b1090635577fa86832259dd00 (patch)
treea77c5c4ea2820fe4a1d1a8656a64d2ba92101746 /Omni/Agent/Worker.hs
parent6f4b2c97a24967508f3970b46999052fd1f44e67 (diff)
task: claim t-rWclFp3vN
Diffstat (limited to 'Omni/Agent/Worker.hs')
-rw-r--r--Omni/Agent/Worker.hs35
1 files changed, 34 insertions, 1 deletions
diff --git a/Omni/Agent/Worker.hs b/Omni/Agent/Worker.hs
index 01099a0..3bf4579 100644
--- a/Omni/Agent/Worker.hs
+++ b/Omni/Agent/Worker.hs
@@ -13,7 +13,11 @@ import qualified Omni.Task.Core as TaskCore
import qualified System.Directory as Directory
import qualified System.Exit as Exit
import System.FilePath ((</>))
+import qualified System.IO as IO
import qualified System.Process as Process
+import Control.Concurrent (forkIO, killThread, threadDelay)
+import qualified Data.Text.IO as TIO
+import Control.Monad (forever)
start :: Core.Worker -> IO ()
start worker = do
@@ -144,13 +148,22 @@ runAmp repo task = do
<> "'.\n"
Directory.createDirectoryIfMissing True (repo </> "_/llm")
+ let logPath = repo </> "_/llm/amp.log"
+ -- Ensure log file is empty/exists
+ IO.writeFile logPath ""
+
+ -- Monitor log file
+ monitorThread <- forkIO (monitorLog logPath)
-- Assume amp is in PATH
let args = ["--log-level", "debug", "--log-file", "_/llm/amp.log", "--dangerously-allow-all", "-x", Text.unpack prompt]
let cp = (Process.proc "amp" args) {Process.cwd = Just repo}
(_, _, _, ph) <- Process.createProcess cp
- Process.waitForProcess ph
+ exitCode <- Process.waitForProcess ph
+
+ killThread monitorThread
+ pure exitCode
formatTask :: TaskCore.Task -> Text
formatTask t =
@@ -202,3 +215,23 @@ findBaseBranch repo task = do
case candidates of
(candidate : _) -> pure ("task/" <> TaskCore.depId candidate)
[] -> pure "live"
+
+monitorLog :: FilePath -> IO ()
+monitorLog path = do
+ -- Wait for file to exist
+ waitForFile path
+
+ IO.withFile path IO.ReadMode $ \h -> do
+ IO.hSetBuffering h IO.LineBuffering
+ forever $ do
+ eof <- IO.hIsEOF h
+ if eof
+ then threadDelay 100000 -- 0.1s
+ else do
+ line <- TIO.hGetLine h
+ AgentLog.processLogLine line
+
+waitForFile :: FilePath -> IO ()
+waitForFile p = do
+ e <- Directory.doesFileExist p
+ if e then pure () else threadDelay 100000 >> waitForFile p