| iomodo | d9ff8da | 2025-07-28 11:42:22 +0400 | [diff] [blame] | 1 | package commands |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "log" |
| 6 | |
| 7 | "github.com/spf13/cobra" |
| 8 | ) |
| 9 | |
| 10 | var generateSubtasksCmd = &cobra.Command{ |
| 11 | Use: "generate-subtasks [task-id]", |
| 12 | Short: "Generate subtasks for a given task using LLM analysis", |
| 13 | Long: `Analyze a task and generate proposed subtasks using LLM analysis. |
| 14 | This creates a PR with the proposed subtasks that can be reviewed and merged. |
| 15 | |
| 16 | Example: |
| 17 | staff generate-subtasks task-123456-abcdef`, |
| 18 | Args: cobra.ExactArgs(1), |
| 19 | RunE: runGenerateSubtasks, |
| 20 | } |
| 21 | |
| 22 | func init() { |
| 23 | rootCmd.AddCommand(generateSubtasksCmd) |
| 24 | } |
| 25 | |
| 26 | func runGenerateSubtasks(cmd *cobra.Command, args []string) error { |
| 27 | taskID := args[0] |
| 28 | |
| 29 | // Get the task |
| 30 | task, err := taskManager.GetTask(taskID) |
| 31 | if err != nil { |
| 32 | return fmt.Errorf("failed to get task: %w", err) |
| 33 | } |
| 34 | |
| 35 | fmt.Printf("Generating subtasks for task: %s\n", task.Title) |
| 36 | fmt.Printf("Description: %s\n", task.Description) |
| 37 | fmt.Printf("Priority: %s\n\n", task.Priority) |
| 38 | |
| 39 | // Check if subtasks already generated |
| 40 | if task.SubtasksGenerated { |
| 41 | fmt.Printf("⚠️ Subtasks already generated for this task\n") |
| 42 | if task.SubtasksPRURL != "" { |
| 43 | fmt.Printf("PR URL: %s\n", task.SubtasksPRURL) |
| 44 | } |
| 45 | return nil |
| 46 | } |
| 47 | |
| 48 | // Force subtask generation by temporarily marking as high priority |
| 49 | originalPriority := task.Priority |
| 50 | task.Priority = "high" |
| 51 | |
| 52 | // Get the manager's subtask service and generate |
| 53 | if agentManager == nil { |
| 54 | return fmt.Errorf("agent manager not initialized") |
| 55 | } |
| 56 | |
| 57 | // This is a bit of a hack to access private method, but for testing... |
| 58 | log.Printf("Starting subtask analysis for task %s...", taskID) |
| 59 | |
| 60 | // We'll call this through the normal task processing flow |
| 61 | // by creating a dummy agent to trigger the subtask generation |
| 62 | agentStatus := agentManager.GetAgentStatus() |
| 63 | if len(agentStatus) == 0 { |
| 64 | return fmt.Errorf("no agents available") |
| 65 | } |
| 66 | |
| 67 | // Get first available agent |
| 68 | var agentName string |
| 69 | for name := range agentStatus { |
| 70 | agentName = name |
| 71 | break |
| 72 | } |
| 73 | |
| 74 | fmt.Printf("🤖 Using agent '%s' for subtask analysis...\n\n", agentName) |
| 75 | |
| 76 | // Create a simple approach: assign task to agent and let it process |
| 77 | task.Assignee = agentName |
| 78 | task.Priority = originalPriority // Restore original priority |
| 79 | |
| 80 | if err := taskManager.UpdateTask(task); err != nil { |
| 81 | return fmt.Errorf("failed to update task assignment: %w", err) |
| 82 | } |
| 83 | |
| 84 | fmt.Printf("✅ Task assigned to agent '%s' for subtask generation\n", agentName) |
| 85 | fmt.Printf("💡 Start the server to see subtask generation in action:\n") |
| 86 | fmt.Printf(" staff server --config config-fake.yaml\n\n") |
| 87 | fmt.Printf("📋 The agent will:\n") |
| 88 | fmt.Printf(" 1. Analyze the task requirements\n") |
| 89 | fmt.Printf(" 2. Generate proposed subtasks with LLM\n") |
| 90 | fmt.Printf(" 3. Create a PR with subtask proposals\n") |
| 91 | fmt.Printf(" 4. Wait for PR review and approval\n") |
| 92 | fmt.Printf(" 5. Create actual subtasks when PR is merged\n") |
| 93 | |
| 94 | return nil |
| 95 | } |