chore: remove old and unused code

This commit is contained in:
2026-08-03 13:08:18 +02:00
parent 312b25fd39
commit 4fcc479779
17 changed files with 325 additions and 142 deletions

View File

@@ -26,14 +26,16 @@ const (
)
type aiPreparedMsg struct {
preview AIPreview
threadID string
err error
generation uint64
preview AIPreview
threadID string
err error
}
type aiCompletedMsg struct {
result AIResult
err error
generation uint64
result AIResult
err error
}
type aiStatusMsg struct {
@@ -41,15 +43,24 @@ type aiStatusMsg struct {
}
type aiProgressMsg struct {
progress AIRunProgress
generation uint64
progress AIRunProgress
}
type aiProviderTestCompletedMsg struct {
model string
err error
generation uint64
model string
err error
}
type aiAnimationTickMsg time.Time
type aiAnimationTickMsg struct {
generation uint64
}
func (m *App) nextAIGeneration() uint64 {
m.aiGeneration++
return m.aiGeneration
}
func (m *App) openAIMenu() {
if m.screen == prScreen {
@@ -97,6 +108,7 @@ func (m *App) beginAIPrepare(threadID, message string) tea.Cmd {
}
ctx, cancel := context.WithCancel(context.Background())
m.aiCancel = cancel
generation := m.nextAIGeneration()
controller, details := m.ai, m.details
m.aiMode = aiPreparing
m.err = nil
@@ -112,9 +124,11 @@ func (m *App) beginAIPrepare(threadID, message string) tea.Cmd {
}
prepare := func() tea.Msg {
preview, err := controller.Prepare(ctx, details, threadID, message)
return aiPreparedMsg{preview: preview, threadID: threadID, err: err}
return aiPreparedMsg{
generation: generation, preview: preview, threadID: threadID, err: err,
}
}
return tea.Batch(prepare, nextAIAnimationTick())
return tea.Batch(prepare, nextAIAnimationTick(generation))
}
func (m *App) returnFromAIPrepareFailure(threadID string) {
@@ -133,6 +147,7 @@ func (m *App) beginAIRun() tea.Cmd {
}
ctx, cancel := context.WithCancel(context.Background())
m.aiCancel = cancel
generation := m.nextAIGeneration()
controller, preview := m.ai, m.aiPreview
m.aiMode = aiBusy
m.aiSpinner = 0
@@ -146,18 +161,21 @@ func (m *App) beginAIRun() tea.Cmd {
m.aiEvents = events
work := func() tea.Msg {
go func() {
defer close(events)
result, err := controller.RunWithProgress(ctx, preview, func(progress AIRunProgress) {
select {
case events <- aiProgressMsg{progress: progress}:
case events <- aiProgressMsg{generation: generation, progress: progress}:
default:
}
})
events <- aiCompletedMsg{result: result, err: err}
close(events)
select {
case events <- aiCompletedMsg{generation: generation, result: result, err: err}:
case <-ctx.Done():
}
}()
return <-events
}
return tea.Batch(work, nextAIAnimationTick())
return tea.Batch(work, nextAIAnimationTick(generation))
}
func (m *App) beginAIProviderTest() tea.Cmd {
@@ -168,6 +186,7 @@ func (m *App) beginAIProviderTest() tea.Cmd {
}
ctx, cancel := context.WithCancel(context.Background())
m.aiCancel = cancel
generation := m.nextAIGeneration()
controller := m.ai
m.aiMode = aiProviderTestBusy
m.aiSpinner = 0
@@ -181,18 +200,23 @@ func (m *App) beginAIProviderTest() tea.Cmd {
m.aiEvents = events
work := func() tea.Msg {
go func() {
defer close(events)
model, err := controller.TestProvider(ctx, func(progress AIRunProgress) {
select {
case events <- aiProgressMsg{progress: progress}:
case events <- aiProgressMsg{generation: generation, progress: progress}:
default:
}
})
events <- aiProviderTestCompletedMsg{model: model, err: err}
close(events)
select {
case events <- aiProviderTestCompletedMsg{
generation: generation, model: model, err: err,
}:
case <-ctx.Done():
}
}()
return <-events
}
return tea.Batch(work, nextAIAnimationTick())
return tea.Batch(work, nextAIAnimationTick(generation))
}
func waitAIEvent(events <-chan tea.Msg) tea.Cmd {
@@ -204,9 +228,9 @@ func waitAIEvent(events <-chan tea.Msg) tea.Cmd {
}
}
func nextAIAnimationTick() tea.Cmd {
return tea.Tick(100*time.Millisecond, func(at time.Time) tea.Msg {
return aiAnimationTickMsg(at)
func nextAIAnimationTick(generation uint64) tea.Cmd {
return tea.Tick(100*time.Millisecond, func(time.Time) tea.Msg {
return aiAnimationTickMsg{generation: generation}
})
}
@@ -215,7 +239,7 @@ func (m App) updateAI(msg tea.Msg) (tea.Model, tea.Cmd, bool) {
case tea.WindowSizeMsg:
return m, nil, false
case aiPreparedMsg:
if m.aiMode != aiPreparing {
if msg.generation != m.aiGeneration || m.aiMode != aiPreparing {
return m, nil, true
}
m.aiCancel = nil
@@ -230,15 +254,19 @@ func (m App) updateAI(msg tea.Msg) (tea.Model, tea.Cmd, bool) {
}
return m, nil, true
case aiAnimationTickMsg:
if msg.generation != m.aiGeneration {
return m, nil, true
}
switch m.aiMode {
case aiPreparing, aiBusy, aiProviderTestBusy:
m.aiSpinner++
return m, nextAIAnimationTick(), true
return m, nextAIAnimationTick(msg.generation), true
default:
return m, nil, true
}
case aiProgressMsg:
if m.aiMode != aiBusy && m.aiMode != aiProviderTestBusy {
if msg.generation != m.aiGeneration ||
(m.aiMode != aiBusy && m.aiMode != aiProviderTestBusy) {
return m, nil, true
}
m.aiProgress = msg.progress
@@ -247,7 +275,7 @@ func (m App) updateAI(msg tea.Msg) (tea.Model, tea.Cmd, bool) {
m.aiStatus, m.aiStatusBusy = msg.status, false
return m, nil, true
case aiCompletedMsg:
if m.aiMode != aiBusy {
if msg.generation != m.aiGeneration || m.aiMode != aiBusy {
return m, nil, true
}
m.aiCancel, m.aiEvents = nil, nil
@@ -281,7 +309,7 @@ func (m App) updateAI(msg tea.Msg) (tea.Model, tea.Cmd, bool) {
m.recordHealth("AI provider", healthOK, healthMessage)
return m, nil, true
case aiProviderTestCompletedMsg:
if m.aiMode != aiProviderTestBusy {
if msg.generation != m.aiGeneration || m.aiMode != aiProviderTestBusy {
return m, nil, true
}
m.aiCancel, m.aiEvents = nil, nil
@@ -322,6 +350,7 @@ func (m App) updateAI(msg tea.Msg) (tea.Model, tea.Cmd, bool) {
m.aiCancel()
m.aiCancel = nil
}
m.nextAIGeneration()
m.aiMode, m.aiInput, m.writeThreadID, m.aiEvents = aiNone, "", "", nil
m.aiInputEditor = textEditor{}
return m, nil, true