From c3ab8403df5e5ed99e6769dcdc152408d57026a7 Mon Sep 17 00:00:00 2001 From: Omni Worker Date: Fri, 21 Nov 2025 05:14:53 -0500 Subject: feat: implement Omni.Agent.Worker loop logic Amp-Thread-ID: https://ampcode.com/threads/T-4f2905ef-a042-4880-b146-f6809ce83751 Co-authored-by: Amp --- Omni/Agent/Git.hs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'Omni/Agent/Git.hs') diff --git a/Omni/Agent/Git.hs b/Omni/Agent/Git.hs index a7afb20..7ee8a16 100644 --- a/Omni/Agent/Git.hs +++ b/Omni/Agent/Git.hs @@ -7,6 +7,10 @@ -- : dep temporary module Omni.Agent.Git ( checkout, + syncWithLive, + commit, + createBranch, + getCurrentBranch, main, test, ) @@ -136,3 +140,38 @@ git dir args = do Log.info [Text.pack err] Log.br panic <| "git command failed: git " <> show args + +syncWithLive :: FilePath -> IO () +syncWithLive repo = do + Log.info ["git", "syncing with live"] + git repo ["fetch", "origin", "live"] + + -- Try rebase, if fail, abort + let cmd = (Process.proc "git" ["rebase", "origin/live"]) {Process.cwd = Just repo} + (code, _, err) <- Process.readCreateProcessWithExitCode cmd "" + case code of + Exit.ExitSuccess -> pure () + Exit.ExitFailure _ -> do + Log.warn ["rebase failed, aborting", Text.pack err] + let abort = (Process.proc "git" ["rebase", "--abort"]) {Process.cwd = Just repo} + _ <- Process.readCreateProcessWithExitCode abort "" + panic "Sync with live failed (rebase conflict)" + +commit :: FilePath -> Text -> IO () +commit repo msg = do + Log.info ["git", "commit", msg] + git repo ["add", "."] + git repo ["commit", "-m", Text.unpack msg] + +createBranch :: FilePath -> Text -> IO () +createBranch repo branch = do + Log.info ["git", "create branch", branch] + git repo ["checkout", "-b", Text.unpack branch] + +getCurrentBranch :: FilePath -> IO Text +getCurrentBranch repo = do + let cmd = (Process.proc "git" ["branch", "--show-current"]) {Process.cwd = Just repo} + (code, out, _) <- Process.readCreateProcessWithExitCode cmd "" + case code of + Exit.ExitSuccess -> pure <| Text.strip (Text.pack out) + _ -> panic "git branch failed" -- cgit v1.2.3