switchToPRD switches to a different PRD (view only - does not stop other loops).
(name, prdPath string)
| 1992 | |
| 1993 | // switchToPRD switches to a different PRD (view only - does not stop other loops). |
| 1994 | func (a App) switchToPRD(name, prdPath string) (tea.Model, tea.Cmd) { |
| 1995 | // Stop current watcher (but NOT the loop - it can keep running) |
| 1996 | a.stopWatcher() |
| 1997 | |
| 1998 | // Load the new PRD |
| 1999 | newPRD, err := prd.LoadPRD(prdPath) |
| 2000 | if err != nil { |
| 2001 | a.lastActivity = "Error loading PRD: " + err.Error() |
| 2002 | a.viewMode = ViewDashboard |
| 2003 | return a, nil |
| 2004 | } |
| 2005 | |
| 2006 | // Register with manager if not already registered |
| 2007 | if instance := a.manager.GetInstance(name); instance == nil { |
| 2008 | a.manager.Register(name, prdPath) |
| 2009 | } |
| 2010 | |
| 2011 | // Create new watcher for the new PRD |
| 2012 | newWatcher, err := prd.NewWatcher(prdPath) |
| 2013 | if err != nil { |
| 2014 | a.lastActivity = "Warning: file watcher failed" |
| 2015 | } else { |
| 2016 | a.watcher = newWatcher |
| 2017 | if err := a.watcher.Start(); err != nil { |
| 2018 | a.lastActivity = "Warning: file watcher failed to start" |
| 2019 | } |
| 2020 | } |
| 2021 | |
| 2022 | // Create new progress watcher and load initial progress |
| 2023 | newProgressWatcher, err := prd.NewProgressWatcher(prdPath) |
| 2024 | if err == nil { |
| 2025 | a.progressWatcher = newProgressWatcher |
| 2026 | _ = a.progressWatcher.Start() |
| 2027 | } |
| 2028 | a.progress, _ = prd.ParseProgress(prd.ProgressPath(prdPath)) |
| 2029 | |
| 2030 | // Get the state from the manager for this PRD |
| 2031 | loopState, iteration, loopErr := a.manager.GetState(name) |
| 2032 | appState := StateReady |
| 2033 | switch loopState { |
| 2034 | case loop.LoopStateRunning: |
| 2035 | appState = StateRunning |
| 2036 | case loop.LoopStatePaused: |
| 2037 | appState = StatePaused |
| 2038 | case loop.LoopStateStopped: |
| 2039 | appState = StateStopped |
| 2040 | case loop.LoopStateComplete: |
| 2041 | appState = StateComplete |
| 2042 | case loop.LoopStateError: |
| 2043 | appState = StateError |
| 2044 | } |
| 2045 | |
| 2046 | // Only recalculate max iterations if no loop is currently running for this PRD |
| 2047 | if instance := a.manager.GetInstance(name); instance == nil || instance.State != loop.LoopStateRunning { |
| 2048 | remaining := 0 |
| 2049 | for _, story := range newPRD.UserStories { |
| 2050 | if !story.Passes { |
| 2051 | remaining++ |
no test coverage detected