| 91 | } |
| 92 | |
| 93 | func runProjectInit(cmd *cobra.Command, _ []string) error { |
| 94 | if projectInitNoSpec && projectInitNoAgent && projectInitNoTemplates { |
| 95 | return fmt.Errorf("--no-spec, --no-agent, and --no-templates cannot all be set (nothing to do)") |
| 96 | } |
| 97 | |
| 98 | root := projectInitRoot |
| 99 | isTTY := projectInitIsTTY() |
| 100 | quiet := GetGlobalFlags().Quiet |
| 101 | |
| 102 | // Resolve task directory: flag > prompt > default |
| 103 | taskDirPath, err := resolveInitTaskDir(cmd, isTTY) |
| 104 | if err != nil { |
| 105 | return err |
| 106 | } |
| 107 | |
| 108 | // Resolve agents: flags > prompt > default (Claude) |
| 109 | resolveInitAgents(isTTY) |
| 110 | |
| 111 | // Resolve templates: flags > prompt > default (yes) |
| 112 | resolveInitTemplates(isTTY) |
| 113 | |
| 114 | // Resolve ID strategy: flag > prompt > default (sequential) |
| 115 | idStrategy, err := resolveInitIDStrategy(cmd, isTTY) |
| 116 | if err != nil { |
| 117 | return err |
| 118 | } |
| 119 | |
| 120 | // Collect files split by destination |
| 121 | rootFiles, taskDirFiles := collectInitFiles(idStrategy) |
| 122 | |
| 123 | // --stdout mode: print everything and exit |
| 124 | if projectInitStdout { |
| 125 | allFiles := append(rootFiles, taskDirFiles...) |
| 126 | return printFilesToStdout(allFiles) |
| 127 | } |
| 128 | |
| 129 | taskDirAbs := taskDirPath |
| 130 | if !filepath.IsAbs(taskDirAbs) { |
| 131 | taskDirAbs = filepath.Join(root, taskDirPath) |
| 132 | } |
| 133 | |
| 134 | // Show confirmation before writing |
| 135 | if isTTY && !quiet { |
| 136 | if !confirmInitPlan(root, taskDirAbs, rootFiles, taskDirFiles) { |
| 137 | fmt.Fprintln(os.Stderr, "Cancelled.") |
| 138 | return nil |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | return writeProjectFiles(root, taskDirAbs, taskDirPath, idStrategy, rootFiles, taskDirFiles, quiet) |
| 143 | } |
| 144 | |
| 145 | // writeProjectFiles creates directories, config, and all init files. |
| 146 | func writeProjectFiles(root, taskDirAbs, taskDirPath string, idStrategy idStrategyConfig, rootFiles, taskDirFiles []fileToWrite, quiet bool) error { |