summaryrefslogtreecommitdiff
path: root/Omni/Agent.hs
diff options
context:
space:
mode:
authorBen Sima <ben@bensima.com>2025-11-24 13:59:34 -0500
committerBen Sima <ben@bensima.com>2025-11-24 13:59:34 -0500
commitea466775a6b12dce67b789aa98d2c40a9c913a97 (patch)
treecf021707fc1afb974ae5d4ff582273ca5a0b1659 /Omni/Agent.hs
parent5ddaf58a46c832b2f937cebac1ec2a9368bd51e9 (diff)
Simplify agent command
I think the cd'ing and stuff was messing with the direnv assumptions.
Diffstat (limited to 'Omni/Agent.hs')
-rw-r--r--Omni/Agent.hs51
1 files changed, 10 insertions, 41 deletions
diff --git a/Omni/Agent.hs b/Omni/Agent.hs
index d94949c..070e3fb 100644
--- a/Omni/Agent.hs
+++ b/Omni/Agent.hs
@@ -21,7 +21,7 @@ import qualified System.Console.Docopt as Docopt
import qualified System.Directory as Directory
import qualified System.Environment as Env
import qualified System.Exit as Exit
-import System.FilePath ((</>))
+import System.FilePath (takeFileName)
import qualified System.IO as IO
import qualified System.IO.Temp as Temp
@@ -43,10 +43,9 @@ help =
agent
Usage:
- agent start <name> [--path=<path>]
+ agent start
agent harvest [--path=<path>]
agent merge-driver <ours> <theirs>
- agent setup <name>
agent test
agent --help
@@ -58,11 +57,12 @@ Options:
move :: Cli.Arguments -> IO ()
move args
| args `Cli.has` Cli.command "start" = do
- name <-
- Cli.getArg args (Cli.argument "name") |> \case
- Just n -> pure (Text.pack n)
- Nothing -> panic "Name required"
- let path = Cli.getArgWithDefault args "." (Cli.longOption "path")
+ -- Always run in current directory
+ let path = "."
+
+ -- Infer name from current directory
+ absPath <- Directory.getCurrentDirectory
+ let name = Text.pack (takeFileName absPath)
let worker =
Core.Worker
@@ -75,7 +75,6 @@ move args
Worker.start worker
| args `Cli.has` Cli.command "harvest" = harvest args
| args `Cli.has` Cli.command "merge-driver" = mergeDriver args
- | args `Cli.has` Cli.command "setup" = setup args
| otherwise = putStrLn (Cli.usage help)
getArgOrExit :: Cli.Arguments -> Docopt.Option -> IO String
@@ -135,31 +134,6 @@ mergeDriver args = do
TaskCore.importTasks theirs
Exit.exitSuccess
-setup :: Cli.Arguments -> IO ()
-setup args = do
- nameStr <- getArgOrExit args (Cli.argument "name")
- let name = Text.pack nameStr
- root <- Git.getRepoRoot "."
- let worktreePath = root <> "/../" <> nameStr
-
- putText <| "Creating worktree '" <> Text.pack worktreePath <> "' on branch '" <> name <> "' (from live)..."
-
- -- git worktree add -b <name> <path> live
- Git.runGit root ["worktree", "add", "-b", nameStr, worktreePath, "live"]
-
- -- Copy .envrc.local if exists
- let envrc = root </> ".envrc.local"
- exists <- Directory.doesFileExist envrc
- when exists <| do
- putText "Copying .envrc.local..."
- Directory.copyFile envrc (worktreePath </> ".envrc.local")
-
- -- Config git
- Git.runGit worktreePath ["config", "user.name", "Omni Worker"]
- Git.runGit worktreePath ["config", "user.email", "bot@omni.agent"]
-
- putText <| "Worker setup complete at " <> Text.pack worktreePath
-
test :: Test.Tree
test = Test.group "Omni.Agent" [unitTests, logTests]
@@ -178,7 +152,7 @@ unitTests =
Test.group
"Unit tests"
[ Test.unit "can parse start command" <| do
- let result = Docopt.parseArgs help ["start", "worker-1"]
+ let result = Docopt.parseArgs help ["start"]
case result of
Left err -> Test.assertFailure <| "Failed to parse 'start': " <> show err
Right args -> args `Cli.has` Cli.command "start" Test.@?= True,
@@ -186,10 +160,5 @@ unitTests =
let result = Docopt.parseArgs help ["harvest"]
case result of
Left err -> Test.assertFailure <| "Failed to parse 'harvest': " <> show err
- Right args -> args `Cli.has` Cli.command "harvest" Test.@?= True,
- Test.unit "can parse setup command" <| do
- let result = Docopt.parseArgs help ["setup", "worker-2"]
- case result of
- Left err -> Test.assertFailure <| "Failed to parse 'setup': " <> show err
- Right args -> args `Cli.has` Cli.command "setup" Test.@?= True
+ Right args -> args `Cli.has` Cli.command "harvest" Test.@?= True
]