From cd4df25878ad0908d10a01298a24a7ba002252b1 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Mon, 24 Nov 2025 21:53:27 -0500 Subject: feat: implement t-1o2egbj8o0n.3 I have implemented the `jr work` command in `Omni/Jr.hs`. **Changes:** 1. **Modified `Omni/Jr.hs`**: * Added necessary imports (`Omni.Agent.Core`, `Omni.Agent.Worker`, `System.Directory`, `System.FilePath`, `Data.Text`). * Updated the Docopt usage to include `jr work []`. * Implemented the `work` command handler in the `move` function to initialize a `Worker` and call `Worker.start`, mirroring the logic in `Omni/Agent.hs`. * Added unit tests to verify parsing of the `work` command with and without a task ID. **Verification:** * Ran `bild --test Omni/Jr.hs` which passed, confirming the code compiles and tests pass. * Ran `lint Omni/Jr.hs` which passed. * Verified `_/bin/jr --help` shows the new command. I am now ready to exit. --- Omni/Jr.hs | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'Omni/Jr.hs') diff --git a/Omni/Jr.hs b/Omni/Jr.hs index b4b8941..db22fdc 100644 --- a/Omni/Jr.hs +++ b/Omni/Jr.hs @@ -7,11 +7,16 @@ module Omni.Jr where import Alpha +import qualified Data.Text as Text +import qualified Omni.Agent.Core as AgentCore +import qualified Omni.Agent.Worker as AgentWorker import qualified Omni.Cli as Cli import qualified Omni.Task as Task import qualified Omni.Test as Test import qualified System.Console.Docopt as Docopt +import qualified System.Directory as Directory import System.Environment (withArgs) +import System.FilePath (takeFileName) main :: IO () main = Cli.main plan @@ -32,7 +37,7 @@ jr Usage: jr task [...] - jr work [...] + jr work [] jr test jr (-h | --help) @@ -50,12 +55,41 @@ move args let extraArgs = Cli.getAllArgs args (Cli.argument "args") withArgs extraArgs Task.main | args `Cli.has` Cli.command "work" = do - putText "Work command not implemented yet" + -- Always run in current directory + let path = "." + + -- Infer name from current directory + absPath <- Directory.getCurrentDirectory + let name = Text.pack (takeFileName absPath) + + let worker = + AgentCore.Worker + { AgentCore.workerName = name, + AgentCore.workerPid = Nothing, + AgentCore.workerStatus = AgentCore.Idle, + AgentCore.workerPath = path + } + + let taskId = fmap Text.pack (Cli.getArg args (Cli.argument "task-id")) + + AgentWorker.start worker taskId | otherwise = putText (str <| Docopt.usage help) test :: Test.Tree test = Test.group "Omni.Jr" - [ Test.unit "can run tests" <| True Test.@?= True + [ Test.unit "can run tests" <| True Test.@?= True, + Test.unit "can parse work command" <| do + let result = Docopt.parseArgs help ["work"] + case result of + Left err -> Test.assertFailure <| "Failed to parse 'work': " <> show err + Right args -> args `Cli.has` Cli.command "work" Test.@?= True, + Test.unit "can parse work command with task id" <| do + let result = Docopt.parseArgs help ["work", "t-123"] + case result of + Left err -> Test.assertFailure <| "Failed to parse 'work t-123': " <> show err + Right args -> do + args `Cli.has` Cli.command "work" Test.@?= True + Cli.getArg args (Cli.argument "task-id") Test.@?= Just "t-123" ] -- cgit v1.2.3