blob: 63e0d8fe7628e153c96315958d70752b4d3fa76a [file] [log] [blame]
iomodob6d9eb92025-07-24 20:54:45 +04001package commands
2
3import (
user5a7d60d2025-07-27 21:22:04 +04004 "fmt"
iomodob6d9eb92025-07-24 20:54:45 +04005 "log/slog"
6 "os"
iomodob6d9eb92025-07-24 20:54:45 +04007
user5a7d60d2025-07-27 21:22:04 +04008 "github.com/iomodo/staff/agent"
9 "github.com/iomodo/staff/config"
10 "github.com/iomodo/staff/git"
11 "github.com/iomodo/staff/tm"
12 "github.com/iomodo/staff/tm/git_tm"
iomodob6d9eb92025-07-24 20:54:45 +040013 "github.com/spf13/cobra"
14)
15
16// Command is an abstraction of the cobra Command
17type Command = cobra.Command
18
user5a7d60d2025-07-27 21:22:04 +040019// Global variables for the MVP
20var (
iomodo50598c62025-07-27 22:06:32 +040021 agentManager *agent.Manager
user5a7d60d2025-07-27 21:22:04 +040022 taskManager tm.TaskManager
23 cfg *config.Config
24)
25
iomodob6d9eb92025-07-24 20:54:45 +040026// Run function starts the application
27func Run(args []string) error {
28 rootCmd.SetArgs(args)
29 return rootCmd.Execute()
30}
31
user5a7d60d2025-07-27 21:22:04 +040032// rootCmd is the main command for Staff MVP
iomodob6d9eb92025-07-24 20:54:45 +040033var rootCmd = &cobra.Command{
user5a7d60d2025-07-27 21:22:04 +040034 Use: "staff",
35 Short: "Staff - AI Multi-Agent Development System",
36 Long: `Staff MVP - AI agents that autonomously handle development tasks and create GitHub PRs.
37
38Examples:
39 staff create-task "Add user authentication" --priority high --agent backend-engineer
40 staff start-agent backend-engineer
41 staff list-tasks
42 staff list-agents`,
43 PersistentPreRunE: initializeApp,
iomodob6d9eb92025-07-24 20:54:45 +040044}
45
user5a7d60d2025-07-27 21:22:04 +040046func init() {
47 // Add all commands
48 rootCmd.AddCommand(createTaskCmd)
49 rootCmd.AddCommand(assignTaskCmd)
50 rootCmd.AddCommand(startAgentCmd)
51 rootCmd.AddCommand(stopAgentCmd)
52 rootCmd.AddCommand(listTasksCmd)
53 rootCmd.AddCommand(listAgentsCmd)
54 rootCmd.AddCommand(configCheckCmd)
55 rootCmd.AddCommand(cleanupClonesCmd)
56 rootCmd.AddCommand(versionCmd)
57}
58
59// initializeApp loads configuration and sets up managers
60func initializeApp(cmd *cobra.Command, args []string) error {
61 // Skip initialization for help and version commands
62 if cmd.Name() == "help" || cmd.Name() == "version" {
63 return nil
iomodob6d9eb92025-07-24 20:54:45 +040064 }
iomodob6d9eb92025-07-24 20:54:45 +040065
user5a7d60d2025-07-27 21:22:04 +040066 // Load configuration
67 var err error
68 cfg, err = config.LoadConfigWithEnvOverrides("config.yaml")
69 if err != nil {
70 return fmt.Errorf("failed to load config: %w", err)
71 }
iomodob6d9eb92025-07-24 20:54:45 +040072
user5a7d60d2025-07-27 21:22:04 +040073 // Initialize task manager
iomodob6d9eb92025-07-24 20:54:45 +040074 logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
user5a7d60d2025-07-27 21:22:04 +040075 Level: slog.LevelInfo,
iomodob6d9eb92025-07-24 20:54:45 +040076 }))
77
iomodo50598c62025-07-27 22:06:32 +040078 gitInterface := git.DefaultGit("../")
79 taskManager = git_tm.NewGitTaskManagerWithLogger(gitInterface, "../", logger)
user5a7d60d2025-07-27 21:22:04 +040080
81 // Initialize agent manager
iomodo50598c62025-07-27 22:06:32 +040082 agentManager, err = agent.NewManager(cfg, taskManager)
iomodob6d9eb92025-07-24 20:54:45 +040083 if err != nil {
user5a7d60d2025-07-27 21:22:04 +040084 return fmt.Errorf("failed to initialize agent manager: %w", err)
iomodob6d9eb92025-07-24 20:54:45 +040085 }
86
user5a7d60d2025-07-27 21:22:04 +040087 return nil
iomodob6d9eb92025-07-24 20:54:45 +040088}