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

Method switchToPRD

internal/tui/app.go:1994–2095  ·  view source on GitHub ↗

switchToPRD switches to a different PRD (view only - does not stop other loops).

(name, prdPath string)

Source from the content-addressed store, hash-verified

1992
1993// switchToPRD switches to a different PRD (view only - does not stop other loops).
1994func (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++

Callers 2

UpdateMethod · 0.95
handlePickerKeysMethod · 0.95

Calls 15

stopWatcherMethod · 0.95
listenForPRDChangesMethod · 0.95
LoadPRDFunction · 0.92
NewWatcherFunction · 0.92
NewProgressWatcherFunction · 0.92
ParseProgressFunction · 0.92
ProgressPathFunction · 0.92
tickElapsedFunction · 0.85
GetInstanceMethod · 0.80
RegisterMethod · 0.80
SetCurrentPRDMethod · 0.80

Tested by

no test coverage detected