summaryrefslogtreecommitdiff
path: root/Omni/Agent/Worker.hs
diff options
context:
space:
mode:
authorBen Sima <ben@bensima.com>2025-11-29 23:03:03 -0500
committerBen Sima <ben@bensima.com>2025-11-29 23:03:03 -0500
commit6c9af097bd18bce2a0c0939484818c4074de37ae (patch)
tree6d7355407f157c213fe4e320bb3aa0fe4f8cd34a /Omni/Agent/Worker.hs
parentc74182c97355696db9028160bea2398df64d4246 (diff)
Inject relevant facts into coder agent context
All checks pass. The implementation is complete: 1. Added imports for `Data.List` and `Omni.Fact` 2. Added `getRelevantFacts` function that retrieves facts for the task's 3. Added `formatFacts` and `formatFact` functions to format facts for in 4. Updated `runAmp` to call `getRelevantFacts`, format them, and append Task-Id: t-186
Diffstat (limited to 'Omni/Agent/Worker.hs')
-rw-r--r--Omni/Agent/Worker.hs36
1 files changed, 36 insertions, 0 deletions
diff --git a/Omni/Agent/Worker.hs b/Omni/Agent/Worker.hs
index c07ed71..424a838 100644
--- a/Omni/Agent/Worker.hs
+++ b/Omni/Agent/Worker.hs
@@ -7,12 +7,14 @@ import Alpha
import qualified Data.Aeson as Aeson
import qualified Data.Aeson.Key as AesonKey
import qualified Data.ByteString.Lazy as BSL
+import qualified Data.List as List
import qualified Data.Text as Text
import qualified Data.Text.Encoding as TE
import qualified Data.Text.IO as TIO
import qualified Data.Time
import qualified Omni.Agent.Core as Core
import qualified Omni.Agent.Log as AgentLog
+import qualified Omni.Fact as Fact
import qualified Omni.Task.Core as TaskCore
import qualified System.Directory as Directory
import qualified System.Exit as Exit
@@ -269,10 +271,15 @@ runAmp repo task = do
then Just </ readFile (repo </> "AGENTS.md")
else pure Nothing
+ -- Get relevant facts from the knowledge base
+ relevantFacts <- getRelevantFacts task
+ let factsSection = formatFacts relevantFacts
+
let fullPrompt =
prompt
<> "\n\nREPOSITORY GUIDELINES (AGENTS.md):\n"
<> agentsMd
+ <> factsSection
-- Remove old log file
exists <- Directory.doesFileExist logFile
@@ -358,6 +365,35 @@ formatCommitMessage task ampOutput =
cleaned = [Text.take 72 ln | ln <- lns]
in Text.intercalate "\n" cleaned
+-- | Get facts relevant to a task based on namespace/project
+getRelevantFacts :: TaskCore.Task -> IO [TaskCore.Fact]
+getRelevantFacts task = do
+ let namespace = fromMaybe "Omni" (TaskCore.taskNamespace task)
+ projectFacts <- Fact.getFactsByProject namespace
+ let sorted = List.sortBy (comparing (Down <. TaskCore.factConfidence)) projectFacts
+ pure (take 10 sorted)
+
+-- | Format facts for inclusion in the prompt
+formatFacts :: [TaskCore.Fact] -> Text
+formatFacts [] = ""
+formatFacts facts =
+ Text.unlines
+ [ "\n\nKNOWLEDGE BASE FACTS:",
+ "(These are learned patterns/conventions from previous work)",
+ ""
+ ]
+ <> Text.unlines (map formatFact facts)
+
+-- | Format a single fact for the prompt
+formatFact :: TaskCore.Fact -> Text
+formatFact f =
+ "- "
+ <> TaskCore.factContent f
+ <> ( if null (TaskCore.factRelatedFiles f)
+ then ""
+ else " [" <> Text.intercalate ", " (TaskCore.factRelatedFiles f) <> "]"
+ )
+
monitorLog :: FilePath -> Process.ProcessHandle -> IO ()
monitorLog path ph = do
waitForFile path