summaryrefslogtreecommitdiff
path: root/Omni/Agent/Worker.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Omni/Agent/Worker.hs')
-rw-r--r--Omni/Agent/Worker.hs28
1 files changed, 13 insertions, 15 deletions
diff --git a/Omni/Agent/Worker.hs b/Omni/Agent/Worker.hs
index eef59d7..9f9e3bb 100644
--- a/Omni/Agent/Worker.hs
+++ b/Omni/Agent/Worker.hs
@@ -5,7 +5,6 @@
module Omni.Agent.Worker where
import Alpha
-import Control.Concurrent (forkIO, killThread)
import qualified Data.Text as Text
import qualified Data.Text.IO as TIO
import qualified Omni.Agent.Core as Core
@@ -61,7 +60,7 @@ processTask worker task = do
AgentLog.updateActivity ("Claiming task " <> tid)
-- Claim task
- TaskCore.updateTaskStatus tid TaskCore.InProgress
+ TaskCore.updateTaskStatus tid TaskCore.InProgress []
-- Commit claim locally
Git.commit repo ("task: claim " <> tid)
@@ -97,7 +96,7 @@ processTask worker task = do
AgentLog.log "Agent finished successfully"
-- Update status to Review (bundled with feature commit)
- TaskCore.updateTaskStatus tid TaskCore.Review
+ TaskCore.updateTaskStatus tid TaskCore.Review []
-- Commit changes
-- We should check if there are changes, but 'git add .' is safe.
@@ -114,12 +113,11 @@ processTask worker task = do
Git.syncWithLive repo
-- Update status to Review (for signaling)
- TaskCore.updateTaskStatus tid TaskCore.Review
+ TaskCore.updateTaskStatus tid TaskCore.Review []
Git.commit repo ("task: review " <> tid)
-
+
AgentLog.log ("[✓] Task " <> tid <> " completed")
AgentLog.update (\s -> s {AgentLog.statusTask = Nothing})
-
Exit.ExitFailure code -> do
AgentLog.log ("Agent failed with code " <> tshow code)
AgentLog.updateActivity "Agent failed, retrying..."
@@ -147,7 +145,7 @@ runAmp repo task = do
<> "'.\n"
let logFile = repo </> "_/llm/amp.log"
-
+
-- Remove old log file
exists <- Directory.doesFileExist logFile
when exists (Directory.removeFile logFile)
@@ -159,9 +157,9 @@ runAmp repo task = do
let cp = (Process.proc "amp" args) {Process.cwd = Just repo}
(_, _, _, ph) <- Process.createProcess cp
-
- tid <- forkIO $ monitorLog logFile ph
-
+
+ tid <- forkIO <| monitorLog logFile ph
+
exitCode <- Process.waitForProcess ph
killThread tid
pure exitCode
@@ -199,11 +197,11 @@ formatTask t =
monitorLog :: FilePath -> Process.ProcessHandle -> IO ()
monitorLog path ph = do
waitForFile path
- IO.withFile path IO.ReadMode $ \h -> do
+ IO.withFile path IO.ReadMode <| \h -> do
IO.hSetBuffering h IO.LineBuffering
- loop h
+ go h
where
- loop h = do
+ go h = do
eof <- IO.hIsEOF h
if eof
then do
@@ -211,12 +209,12 @@ monitorLog path ph = do
case mExit of
Nothing -> do
threadDelay 100000 -- 0.1s
- loop h
+ go h
Just _ -> pure ()
else do
line <- TIO.hGetLine h
AgentLog.processLogLine line
- loop h
+ go h
waitForFile :: FilePath -> IO ()
waitForFile path = do