summaryrefslogtreecommitdiff
path: root/Omni/Agent/Worker.hs
diff options
context:
space:
mode:
authorOmni Worker <bot@omni.agent>2025-11-21 18:07:54 -0500
committerOmni Worker <bot@omni.agent>2025-11-21 18:07:54 -0500
commit75d71e31caad0d81e1f7179134e63a6d2a24a146 (patch)
tree80237a656621fb1a33cb8f1ced707c796b2d7173 /Omni/Agent/Worker.hs
parent45521bda259c54458404ca8cda18615f0d36b492 (diff)
feat(agent): implement smart base branch selection
Amp-Thread-ID: https://ampcode.com/threads/T-79499d9e-f4f4-40de-893c-524c32a45483 Co-authored-by: Amp <amp@ampcode.com>
Diffstat (limited to 'Omni/Agent/Worker.hs')
-rw-r--r--Omni/Agent/Worker.hs32
1 files changed, 31 insertions, 1 deletions
diff --git a/Omni/Agent/Worker.hs b/Omni/Agent/Worker.hs
index 511f309..23dd759 100644
--- a/Omni/Agent/Worker.hs
+++ b/Omni/Agent/Worker.hs
@@ -66,7 +66,16 @@ processTask worker task = do
currentBranch <- Git.getCurrentBranch repo
if currentBranch == taskBranch
then Log.info ["worker", "resuming branch", taskBranch]
- else Git.createBranch repo taskBranch
+ else do
+ -- Determine base branch from dependencies
+ baseBranch <- findBaseBranch repo task
+ if baseBranch /= "live"
+ then do
+ Log.info ["worker", "basing", taskBranch, "on", baseBranch]
+ Git.checkout repo baseBranch
+ else Log.info ["worker", "basing", taskBranch, "on live"]
+
+ Git.createBranch repo taskBranch
-- Run Amp
exitCode <- runAmp repo task
@@ -154,6 +163,27 @@ formatTask t =
<> "Updated: "
<> Text.pack (show (TaskCore.taskUpdatedAt t))
<> "\n"
+ <> maybe "" (\d -> "Description:\n" <> d <> "\n\n") (TaskCore.taskDescription t)
<> (if null (TaskCore.taskDependencies t) then "" else "\nDependencies:\n" <> Text.unlines (map formatDep (TaskCore.taskDependencies t)))
where
formatDep dep = " - " <> TaskCore.depId dep <> " [" <> Text.pack (show (TaskCore.depType dep)) <> "]"
+
+findBaseBranch :: FilePath -> TaskCore.Task -> IO Text
+findBaseBranch repo task = do
+ let deps = TaskCore.taskDependencies task
+ -- Filter for blocking dependencies
+ let blockingDeps = filter (\d -> TaskCore.depType d == TaskCore.Blocks || TaskCore.depType d == TaskCore.ParentChild) deps
+
+ -- Check if any have unmerged branches
+ candidates <- flip filterM blockingDeps <| \dep -> do
+ let branch = "task/" <> TaskCore.depId dep
+ exists <- Git.branchExists repo branch
+ if exists
+ then do
+ merged <- Git.isMerged repo branch "live"
+ pure (not merged)
+ else pure False
+
+ case candidates of
+ (candidate : _) -> pure ("task/" <> TaskCore.depId candidate)
+ [] -> pure "live"