NewAppWithOptions creates a new App with the given PRD and options. If maxIter <= 0, it will be calculated dynamically based on remaining stories.
(prdPath string, maxIter int, provider loop.Provider)
| 247 | // NewAppWithOptions creates a new App with the given PRD and options. |
| 248 | // If maxIter <= 0, it will be calculated dynamically based on remaining stories. |
| 249 | func NewAppWithOptions(prdPath string, maxIter int, provider loop.Provider) (*App, error) { |
| 250 | p, err := prd.LoadPRD(prdPath) |
| 251 | if err != nil { |
| 252 | return nil, err |
| 253 | } |
| 254 | |
| 255 | // Calculate dynamic default if maxIter <= 0 |
| 256 | if maxIter <= 0 { |
| 257 | remaining := 0 |
| 258 | for _, story := range p.UserStories { |
| 259 | if !story.Passes { |
| 260 | remaining++ |
| 261 | } |
| 262 | } |
| 263 | maxIter = remaining + 5 |
| 264 | if maxIter < 5 { |
| 265 | maxIter = 5 |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | // Extract PRD name from path (directory name or filename without extension) |
| 270 | prdName := filepath.Base(filepath.Dir(prdPath)) |
| 271 | if prdName == "." || prdName == "/" { |
| 272 | prdName = filepath.Base(prdPath) |
| 273 | } |
| 274 | |
| 275 | // Create file watcher |
| 276 | watcher, err := prd.NewWatcher(prdPath) |
| 277 | if err != nil { |
| 278 | return nil, err |
| 279 | } |
| 280 | |
| 281 | // Determine base directory for PRD picker |
| 282 | // If path contains .chief/prds/, go up to the project root (4 levels up from prd.json) |
| 283 | // .chief/prds/<name>/prd.json -> .chief/prds/<name> -> .chief/prds -> .chief -> project root |
| 284 | baseDir := filepath.Dir(filepath.Dir(filepath.Dir(filepath.Dir(prdPath)))) |
| 285 | if !strings.Contains(prdPath, ".chief/prds/") { |
| 286 | // Fallback to current working directory |
| 287 | baseDir, _ = os.Getwd() |
| 288 | } |
| 289 | |
| 290 | // Load project config |
| 291 | cfg, err := config.Load(baseDir) |
| 292 | if err != nil { |
| 293 | cfg = config.Default() |
| 294 | } |
| 295 | |
| 296 | // Prune stale worktrees on startup (clean git's internal tracking) |
| 297 | if git.IsGitRepo(baseDir) { |
| 298 | _ = git.PruneWorktrees(baseDir) |
| 299 | } |
| 300 | |
| 301 | // Create progress watcher and load initial progress |
| 302 | progressWatcher, _ := prd.NewProgressWatcher(prdPath) |
| 303 | progress, _ := prd.ParseProgress(prd.ProgressPath(prdPath)) |
| 304 | |
| 305 | // Create loop manager for parallel PRD execution |
| 306 | manager := loop.NewManager(maxIter, provider) |
no test coverage detected