PHASE_2_2_PLAN.md
1 # Phase 2.2: Status Updates Implementation 2 3 **Goal:** Add real-time provider and shell status updates 4 5 **Estimated Time:** 1-2 hours 6 7 --- 8 9 ## Tasks 10 11 ### 2.2.1: Parse Config Output 12 13 **Implement config parsing:** 14 15 ```go 16 // backend.go 17 type ConfigStatus struct { 18 Provider string 19 Model string 20 BaseURL string 21 ShellCwd string 22 } 23 24 func parseKamajiConfig(output string) ConfigStatus { 25 // Parse output from `kamaji config` 26 // Example output: 27 // provider: ollama 28 // base_url: http://192.222.50.154:11434 29 // model: gpt-oss:120b 30 31 status := ConfigStatus{} 32 lines := strings.Split(output, "\n") 33 for _, line := range lines { 34 parts := strings.SplitN(line, ":", 2) 35 if len(parts) != 2 { 36 continue 37 } 38 key := strings.TrimSpace(parts[0]) 39 value := strings.TrimSpace(parts[1]) 40 41 switch key { 42 case "provider": 43 status.Provider = value 44 case "model": 45 status.Model = value 46 case "base_url": 47 status.BaseURL = value 48 } 49 } 50 return status 51 } 52 ``` 53 54 ### 2.2.2: Add Status Message Types 55 56 ```go 57 // model.go 58 type statusUpdateMsg struct { 59 Provider string 60 Model string 61 ShellCwd string 62 } 63 ``` 64 65 ### 2.2.3: Periodic Status Polling 66 67 ```go 68 // backend.go 69 func pollStatus() tea.Cmd { 70 return func() tea.Msg { 71 cmd := exec.Command("kamaji", "config") 72 output, err := cmd.CombinedOutput() 73 if err != nil { 74 return nil // Silently fail 75 } 76 77 status := parseKamajiConfig(string(output)) 78 79 // Get shell CWD (from Python's persistent state) 80 // For now, use current directory 81 cwd, _ := os.Getwd() 82 status.ShellCwd = cwd 83 84 return statusUpdateMsg{ 85 Provider: status.Provider, 86 Model: status.Model, 87 ShellCwd: status.ShellCwd, 88 } 89 } 90 } 91 92 // Start periodic polling 93 func startStatusPolling() tea.Cmd { 94 return tea.Tick(time.Second*5, func(t time.Time) tea.Msg { 95 return pollStatus()() 96 }) 97 } 98 ``` 99 100 ### 2.2.4: Update Model on Status Change 101 102 ```go 103 // update.go 104 case statusUpdateMsg: 105 m.provider = msg.Provider 106 m.model = msg.Model 107 m.shellCwd = msg.ShellCwd 108 return m, startStatusPolling() // Continue polling 109 ``` 110 111 ### 2.2.5: Initialize Polling on Startup 112 113 ```go 114 // model.go - in Init() 115 func (m model) Init() tea.Cmd { 116 return tea.Batch( 117 textarea.Blink, 118 pollStatus(), // Initial status 119 startStatusPolling(), // Start periodic updates 120 ) 121 } 122 ``` 123 124 --- 125 126 ## Implementation 127 128 Let me implement this now: 129 130 ```go 131 // File: backend.go additions 132 ``` 133 134 --- 135 136 ## Testing 137 138 ```bash 139 # Test 1: Start TUI 140 ./kamaji-tui 141 142 # Should see provider/model in status bar 143 144 # Test 2: Change provider (in another terminal) 145 kamaji config set provider amazonq 146 147 # After ~5 seconds, status bar should update 148 149 # Test 3: Verify shell CWD updates 150 # (Will need to implement Python shell state reading) 151 ``` 152 153 --- 154 155 ## Next: Implementation Now 156 157 Let's code this...