| package commands |
| |
| import ( |
| "context" |
| "fmt" |
| "os" |
| "os/signal" |
| "syscall" |
| "time" |
| |
| "github.com/spf13/cobra" |
| ) |
| |
| var startAgentCmd = &cobra.Command{ |
| Use: "start-agent [agent-name]", |
| Short: "Start an agent to process tasks", |
| Long: `Start a specific agent to continuously process assigned tasks. |
| |
| The agent will: |
| 1. Check for assigned tasks every 30 seconds |
| 2. Process tasks using the configured LLM |
| 3. Create GitHub PRs for solutions |
| 4. Mark tasks as completed |
| |
| Examples: |
| staff start-agent backend-engineer |
| staff start-agent frontend-engineer`, |
| Args: cobra.ExactArgs(1), |
| RunE: runStartAgent, |
| } |
| |
| var ( |
| agentInterval time.Duration = 30 * time.Second |
| ) |
| |
| func init() { |
| startAgentCmd.Flags().DurationVar(&agentInterval, "interval", 30*time.Second, "Task check interval") |
| } |
| |
| func runStartAgent(cmd *cobra.Command, args []string) error { |
| agentName := args[0] |
| |
| // Check if agent exists in configuration |
| var agentExists bool |
| for _, agent := range cfg.Agents { |
| if agent.Name == agentName { |
| agentExists = true |
| break |
| } |
| } |
| |
| if !agentExists { |
| return fmt.Errorf("agent '%s' not found in configuration", agentName) |
| } |
| |
| fmt.Printf("Starting agent: %s\n", agentName) |
| fmt.Printf("Task check interval: %v\n", agentInterval) |
| fmt.Printf("Press Ctrl+C to stop the agent\n\n") |
| |
| // Set up signal handling for graceful shutdown |
| ctx, cancel := context.WithCancel(context.Background()) |
| defer cancel() |
| |
| sigChan := make(chan os.Signal, 1) |
| signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) |
| |
| go func() { |
| <-sigChan |
| fmt.Printf("\nReceived shutdown signal, stopping agent...\n") |
| cancel() |
| }() |
| |
| // Start the agent |
| err := agentManager.StartAgent(agentName, agentInterval) |
| if err != nil { |
| return fmt.Errorf("failed to start agent: %w", err) |
| } |
| |
| // Wait for context cancellation (Ctrl+C) |
| <-ctx.Done() |
| |
| fmt.Printf("Agent %s stopped\n", agentName) |
| return nil |
| } |