blob: 63e0d8fe7628e153c96315958d70752b4d3fa76a [file] [log] [blame]
package commands
import (
"fmt"
"log/slog"
"os"
"github.com/iomodo/staff/agent"
"github.com/iomodo/staff/config"
"github.com/iomodo/staff/git"
"github.com/iomodo/staff/tm"
"github.com/iomodo/staff/tm/git_tm"
"github.com/spf13/cobra"
)
// Command is an abstraction of the cobra Command
type Command = cobra.Command
// Global variables for the MVP
var (
agentManager *agent.Manager
taskManager tm.TaskManager
cfg *config.Config
)
// Run function starts the application
func Run(args []string) error {
rootCmd.SetArgs(args)
return rootCmd.Execute()
}
// rootCmd is the main command for Staff MVP
var rootCmd = &cobra.Command{
Use: "staff",
Short: "Staff - AI Multi-Agent Development System",
Long: `Staff MVP - AI agents that autonomously handle development tasks and create GitHub PRs.
Examples:
staff create-task "Add user authentication" --priority high --agent backend-engineer
staff start-agent backend-engineer
staff list-tasks
staff list-agents`,
PersistentPreRunE: initializeApp,
}
func init() {
// Add all commands
rootCmd.AddCommand(createTaskCmd)
rootCmd.AddCommand(assignTaskCmd)
rootCmd.AddCommand(startAgentCmd)
rootCmd.AddCommand(stopAgentCmd)
rootCmd.AddCommand(listTasksCmd)
rootCmd.AddCommand(listAgentsCmd)
rootCmd.AddCommand(configCheckCmd)
rootCmd.AddCommand(cleanupClonesCmd)
rootCmd.AddCommand(versionCmd)
}
// initializeApp loads configuration and sets up managers
func initializeApp(cmd *cobra.Command, args []string) error {
// Skip initialization for help and version commands
if cmd.Name() == "help" || cmd.Name() == "version" {
return nil
}
// Load configuration
var err error
cfg, err = config.LoadConfigWithEnvOverrides("config.yaml")
if err != nil {
return fmt.Errorf("failed to load config: %w", err)
}
// Initialize task manager
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelInfo,
}))
gitInterface := git.DefaultGit("../")
taskManager = git_tm.NewGitTaskManagerWithLogger(gitInterface, "../", logger)
// Initialize agent manager
agentManager, err = agent.NewManager(cfg, taskManager)
if err != nil {
return fmt.Errorf("failed to initialize agent manager: %w", err)
}
return nil
}