← Back to task

Commit 151075d3

commit 151075d33c16a3591dd6c57a235e0a3aa9ccc787
Author: Ben Sima <ben@bensima.com>
Date:   Mon Dec 1 07:58:14 2025

    Improve Jr agent structure with progress file and incremental workflow
    
    Perfect! All changes are in place and working correctly. Let me
    create a
    
    I have successfully implemented the improvements to Jr Worker
    agent stru
    
    1. **Progress File Tracking**
       - Added `readProgressFile` function to read
       `_/llm/${taskId}-progress - Added `buildProgressPrompt` function
       to include progress context in - Modified `runWithEngine` to load
       and include progress at the start
    
    2. **Incremental Workflow Enforcement**
       - Updated base prompt to explicitly instruct: "Pick ONE specific
       chan - Added "INCREMENTAL WORKFLOW (IMPORTANT)" section with clear
       guidanc - Added instruction to write progress after each change -
       Emphasized that tasks may be run multiple times to complete all cha
    
    3. **Explicit Verification**
       - Maintained existing requirement to run `bild --test` before
       complet - Added instruction to save progress only after tests pass -
       Clarified that code must be left in clean, testable state
    
    4. **Avoid Redundant Testing**
       - Updated BUILD SYSTEM NOTES to clarify running `bild --test`
       on name - Added explicit instruction not to re-run tests unless
       more changes - Explained that bild handles dependencies transitively
    
    - `bild --test Omni/Agent/Worker.hs` - **PASSED** ✓ - `lint
    Omni/Agent/Worker.hs` - **NO ISSUES** ✓
    
    - `_/llm/t-203-progress.md` - Progress file documenting this
    implementat - `_/llm/t-203-implementation-summary.md` - Detailed
    summary of changes
    
    The implementation follows industry best practices from Anthropic,
    OpenA - Reduced token usage through focused, incremental changes
    - Better code quality with isolated, tested changes - Improved
    reliability with progress tracking across sessions - Clear workflow
    preventing "declaring victory" too early
    
    Task-Id: t-203

diff --git a/Omni/Agent/Worker.hs b/Omni/Agent/Worker.hs
index cc5f7300..38e29cb4 100644
--- a/Omni/Agent/Worker.hs
+++ b/Omni/Agent/Worker.hs
@@ -209,14 +209,20 @@ runWithEngine worker repo task = do
       -- Check for retry context
       maybeRetry <- TaskCore.getRetryContext (TaskCore.taskId task)
 
+      -- Read progress file if it exists
+      progressContent <- readProgressFile repo (TaskCore.taskId task)
+
       -- Build the full prompt
       let ns = fromMaybe "." (TaskCore.taskNamespace task)
       let basePrompt = buildBasePrompt task ns repo
 
+      -- Add progress context if present
+      let progressPrompt = buildProgressPrompt progressContent
+
       -- Add retry context if present
       let retryPrompt = buildRetryPrompt maybeRetry
 
-      let prompt = basePrompt <> retryPrompt
+      let prompt = basePrompt <> progressPrompt <> retryPrompt
 
       -- Read AGENTS.md
       agentsMd <-
@@ -314,22 +320,33 @@ buildBasePrompt task ns repo =
     <> "Your goal is to implement the following task:\n\n"
     <> formatTask task
     <> "\n\nCRITICAL INSTRUCTIONS:\n"
-    <> "1. Analyze the codebase to understand where to make changes.\n"
-    <> "2. Implement the changes by editing files.\n"
-    <> "3. BEFORE finishing, you MUST run: bild --test "
+    <> "1. Read AGENTS.md and any existing progress file for this task.\n"
+    <> "2. Pick ONE specific change to implement (not everything at once).\n"
+    <> "3. Analyze the codebase to understand where to make that change.\n"
+    <> "4. Implement ONLY that one change.\n"
+    <> "5. BEFORE finishing, you MUST run: bild --test "
     <> ns
     <> "\n"
-    <> "4. Fix ALL errors from bild --test (including lint issues).\n"
-    <> "5. Keep running bild --test until it passes with no errors.\n"
-    <> "6. Do NOT update task status or manage git.\n"
-    <> "7. Only exit after bild --test passes.\n\n"
+    <> "6. Fix ALL errors from bild --test (including lint issues).\n"
+    <> "7. Keep running bild --test until it passes with no errors.\n"
+    <> "8. After tests pass, write progress to: _/llm/"
+    <> TaskCore.taskId task
+    <> "-progress.md\n"
+    <> "9. Do NOT update task status or manage git.\n"
+    <> "10. Only exit after bild --test passes and progress is saved.\n\n"
+    <> "INCREMENTAL WORKFLOW (IMPORTANT):\n"
+    <> "- DO NOT try to implement everything in one go\n"
+    <> "- Make ONE focused change, test it, save progress, then stop\n"
+    <> "- The task may be run multiple times to complete all changes\n"
+    <> "- Each session should leave the code in a clean, testable state\n"
+    <> "- If the task is already complete, just verify tests pass and note that in progress\n\n"
     <> "IMPORTANT: The git commit will fail if lint finds issues.\n"
     <> "You must fix all lint suggestions.\n\n"
     <> "BUILD SYSTEM NOTES:\n"
     <> "- Running 'bild --test "
     <> ns
     <> "' automatically tests ALL dependencies of that namespace\n"
-    <> "- You do NOT need to run bild --test on individual files - just the main namespace\n"
+    <> "- You do NOT need to run bild --test on individual files - just the main namespace ONCE\n"
     <> "- Once tests pass, do NOT re-run them unless you make more changes\n"
     <> "- The 'lint' command will be run automatically during git commit via hooks\n"
     <> "- You can run 'lint --fix' on changed files if needed, but it's optional\n\n"
@@ -341,6 +358,29 @@ buildBasePrompt task ns repo =
     <> ns
     <> "\n"
 
+-- | Read progress file for a task if it exists
+readProgressFile :: FilePath -> Text -> IO (Maybe Text)
+readProgressFile repo taskId = do
+  let progressPath = repo </> "_" </> "llm" </> Text.unpack taskId <> "-progress.md"
+  exists <- Directory.doesFileExist progressPath
+  if exists
+    then Just </ readFile progressPath
+    else pure Nothing
+
+-- | Build progress context prompt
+buildProgressPrompt :: Maybe Text -> Text
+buildProgressPrompt Nothing = ""
+buildProgressPrompt (Just progress) =
+  "\n\n## PROGRESS FROM PREVIOUS SESSIONS\n\n"
+    <> "This task has been worked on before. Here's what has been completed:\n\n"
+    <> progress
+    <> "\n\n"
+    <> "IMPORTANT:\n"
+    <> "- Review this progress to understand what's already done\n"
+    <> "- Do NOT repeat work that's already completed\n"
+    <> "- Pick the NEXT logical step that hasn't been done yet\n"
+    <> "- Update the progress file after completing your change\n\n"
+
 -- | Build retry context prompt
 buildRetryPrompt :: Maybe TaskCore.RetryContext -> Text
 buildRetryPrompt Nothing = ""