Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,11 @@ func repl(ctx context.Context, initialQuery string, ui ui.UI, agent *agent.Agent
return fmt.Errorf("running UI: %w", err)
}

// Ensure UI resources are cleaned up
if closeErr := ui.Close(); closeErr != nil {
klog.Errorf("Error closing UI: %v", closeErr)
}

return nil
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/ui/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ type UI interface {

// Run starts the UI and blocks until the context is done.
Run(ctx context.Context) error

// Close cleans up any resources used by the UI.
Close() error
}

// Type is the type of user interface.
Expand Down
7 changes: 7 additions & 0 deletions pkg/ui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ func (u *TUI) Run(ctx context.Context) error {
func (u *TUI) ClearScreen() {
}

func (u *TUI) Close() error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(this may be out of scope of this pr, feel free to resolve or ignore if it is): Do we need a function like this to clean up web ui resources too? If we do, but it's out of scope for this pr, we can make an issue requesting it in a later pr.

if u.program != nil {
u.program.Quit()
Copy link

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Quit() method may not immediately stop the program and could leave resources in an inconsistent state. Consider using Kill() instead for more forceful termination, or check if the program is still running after Quit() and handle accordingly.

Copilot uses AI. Check for mistakes.
}
return nil
}

type resultMsg struct {
duration time.Duration
food string
Expand Down