blob: 7a4de91528061989e3f39cc23f3a4ee44f0f118a [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
iomodo8acd08d2025-07-31 16:22:08 +040024 gitInterface git.GitInterface
user5a7d60d2025-07-27 21:22:04 +040025)
26
iomodob6d9eb92025-07-24 20:54:45 +040027// Run function starts the application
28func Run(args []string) error {
29 rootCmd.SetArgs(args)
30 return rootCmd.Execute()
31}
32
user5a7d60d2025-07-27 21:22:04 +040033// rootCmd is the main command for Staff MVP
iomodob6d9eb92025-07-24 20:54:45 +040034var rootCmd = &cobra.Command{
user5a7d60d2025-07-27 21:22:04 +040035 Use: "staff",
36 Short: "Staff - AI Multi-Agent Development System",
37 Long: `Staff MVP - AI agents that autonomously handle development tasks and create GitHub PRs.
38
39Examples:
40 staff create-task "Add user authentication" --priority high --agent backend-engineer
41 staff start-agent backend-engineer
42 staff list-tasks
43 staff list-agents`,
44 PersistentPreRunE: initializeApp,
iomodob6d9eb92025-07-24 20:54:45 +040045}
46
user5a7d60d2025-07-27 21:22:04 +040047func init() {
48 // Add all commands
49 rootCmd.AddCommand(createTaskCmd)
50 rootCmd.AddCommand(assignTaskCmd)
51 rootCmd.AddCommand(startAgentCmd)
52 rootCmd.AddCommand(stopAgentCmd)
53 rootCmd.AddCommand(listTasksCmd)
54 rootCmd.AddCommand(listAgentsCmd)
55 rootCmd.AddCommand(configCheckCmd)
56 rootCmd.AddCommand(cleanupClonesCmd)
57 rootCmd.AddCommand(versionCmd)
58}
59
60// initializeApp loads configuration and sets up managers
61func initializeApp(cmd *cobra.Command, args []string) error {
62 // Skip initialization for help and version commands
63 if cmd.Name() == "help" || cmd.Name() == "version" {
64 return nil
iomodob6d9eb92025-07-24 20:54:45 +040065 }
iomodob6d9eb92025-07-24 20:54:45 +040066
user5a7d60d2025-07-27 21:22:04 +040067 // Load configuration
68 var err error
69 cfg, err = config.LoadConfigWithEnvOverrides("config.yaml")
70 if err != nil {
71 return fmt.Errorf("failed to load config: %w", err)
72 }
iomodob6d9eb92025-07-24 20:54:45 +040073
user5a7d60d2025-07-27 21:22:04 +040074 // Initialize task manager
iomodob6d9eb92025-07-24 20:54:45 +040075 logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
user5a7d60d2025-07-27 21:22:04 +040076 Level: slog.LevelInfo,
iomodob6d9eb92025-07-24 20:54:45 +040077 }))
78
iomodo8acd08d2025-07-31 16:22:08 +040079 gitInterface = git.New(cfg, logger)
iomodoa53240a2025-07-30 17:33:35 +040080 taskManager = git_tm.NewGitTaskManager(gitInterface, cfg, logger)
user5a7d60d2025-07-27 21:22:04 +040081
82 // Initialize agent manager
iomodo62da94a2025-07-28 19:01:55 +040083 agentManager, err = agent.NewManager(cfg, taskManager, logger)
iomodob6d9eb92025-07-24 20:54:45 +040084 if err != nil {
user5a7d60d2025-07-27 21:22:04 +040085 return fmt.Errorf("failed to initialize agent manager: %w", err)
iomodob6d9eb92025-07-24 20:54:45 +040086 }
87
user5a7d60d2025-07-27 21:22:04 +040088 return nil
iomodob6d9eb92025-07-24 20:54:45 +040089}