MCPcopy Create free account
hub / github.com/MiniCodeMonkey/chief / NewAppWithOptions

Function NewAppWithOptions

internal/tui/app.go:249–346  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
249func 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)

Callers 2

runTUIWithOptionsFunction · 0.92
NewAppFunction · 0.85

Calls 15

SetBaseDirMethod · 0.95
SetConfigMethod · 0.95
RegisterMethod · 0.95
LoadPRDFunction · 0.92
NewWatcherFunction · 0.92
LoadFunction · 0.92
DefaultFunction · 0.92
IsGitRepoFunction · 0.92
PruneWorktreesFunction · 0.92
NewProgressWatcherFunction · 0.92
ParseProgressFunction · 0.92
ProgressPathFunction · 0.92

Tested by

no test coverage detected