Add subtasks

Change-Id: Ica6afd9eef38bcf29135bf2c8a2e4bf0407ccfa1
diff --git a/server/cmd/commands/generate_subtasks.go b/server/cmd/commands/generate_subtasks.go
new file mode 100644
index 0000000..c907b82
--- /dev/null
+++ b/server/cmd/commands/generate_subtasks.go
@@ -0,0 +1,95 @@
+package commands
+
+import (
+	"fmt"
+	"log"
+
+	"github.com/spf13/cobra"
+)
+
+var generateSubtasksCmd = &cobra.Command{
+	Use:   "generate-subtasks [task-id]",
+	Short: "Generate subtasks for a given task using LLM analysis",
+	Long: `Analyze a task and generate proposed subtasks using LLM analysis.
+This creates a PR with the proposed subtasks that can be reviewed and merged.
+
+Example:
+  staff generate-subtasks task-123456-abcdef`,
+	Args: cobra.ExactArgs(1),
+	RunE: runGenerateSubtasks,
+}
+
+func init() {
+	rootCmd.AddCommand(generateSubtasksCmd)
+}
+
+func runGenerateSubtasks(cmd *cobra.Command, args []string) error {
+	taskID := args[0]
+
+	// Get the task
+	task, err := taskManager.GetTask(taskID)
+	if err != nil {
+		return fmt.Errorf("failed to get task: %w", err)
+	}
+
+	fmt.Printf("Generating subtasks for task: %s\n", task.Title)
+	fmt.Printf("Description: %s\n", task.Description)
+	fmt.Printf("Priority: %s\n\n", task.Priority)
+
+	// Check if subtasks already generated
+	if task.SubtasksGenerated {
+		fmt.Printf("⚠️ Subtasks already generated for this task\n")
+		if task.SubtasksPRURL != "" {
+			fmt.Printf("PR URL: %s\n", task.SubtasksPRURL)
+		}
+		return nil
+	}
+
+	// Force subtask generation by temporarily marking as high priority
+	originalPriority := task.Priority
+	task.Priority = "high"
+
+	// Get the manager's subtask service and generate
+	if agentManager == nil {
+		return fmt.Errorf("agent manager not initialized")
+	}
+
+	// This is a bit of a hack to access private method, but for testing...
+	log.Printf("Starting subtask analysis for task %s...", taskID)
+	
+	// We'll call this through the normal task processing flow
+	// by creating a dummy agent to trigger the subtask generation
+	agentStatus := agentManager.GetAgentStatus()
+	if len(agentStatus) == 0 {
+		return fmt.Errorf("no agents available")
+	}
+
+	// Get first available agent
+	var agentName string
+	for name := range agentStatus {
+		agentName = name
+		break
+	}
+
+	fmt.Printf("🤖 Using agent '%s' for subtask analysis...\n\n", agentName)
+
+	// Create a simple approach: assign task to agent and let it process
+	task.Assignee = agentName
+	task.Priority = originalPriority // Restore original priority
+	
+	if err := taskManager.UpdateTask(task); err != nil {
+		return fmt.Errorf("failed to update task assignment: %w", err)
+	}
+
+	fmt.Printf("✅ Task assigned to agent '%s' for subtask generation\n", agentName)
+	fmt.Printf("💡 Start the server to see subtask generation in action:\n")
+	fmt.Printf("   staff server --config config-fake.yaml\n\n")
+	fmt.Printf("📋 The agent will:\n")
+	fmt.Printf("   1. Analyze the task requirements\n")
+	fmt.Printf("   2. Generate proposed subtasks with LLM\n")
+	fmt.Printf("   3. Create a PR with subtask proposals\n")
+	fmt.Printf("   4. Wait for PR review and approval\n")
+	fmt.Printf("   5. Create actual subtasks when PR is merged\n")
+
+	return nil
+}
\ No newline at end of file