feat(tui): add auto-update notification system#124
Merged
Conversation
Greptile OverviewGreptile SummaryThis PR implements a passive auto-update notification system for the Cortex TUI that checks for new versions in the background and displays a banner above the input field. Key Changes
Implementation Notes
This is a lightweight notification-only implementation that complements the existing modal-based upgrade system. Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| src/cortex-tui/src/app/state.rs | Added UpdateNotificationStatus enum and three new fields (update_status, update_progress, update_version) to track auto-update state |
| src/cortex-tui/src/runner/app_runner/runner.rs | Spawns background task to check for updates using UpdateManager::check_update(), returns version and sha256 hash |
| src/cortex-tui/src/runner/event_loop/core.rs | Added update_check_task field and new tokio::select! branch to handle update check completion, updates state and shows toast notification |
| src/cortex-tui/src/views/minimal_session/view.rs | Added render_update_banner() method and integrated banner into layout above input field, shows status with icons and colors |
Sequence Diagram
sequenceDiagram
participant User
participant AppRunner
participant EventLoop
participant UpdateTask
participant UpdateManager
participant API as Cortex Software API
participant AppState
participant UI as MinimalSessionView
User->>AppRunner: Start TUI application
AppRunner->>UpdateTask: tokio::spawn(update check)
activate UpdateTask
UpdateTask->>UpdateManager: UpdateManager::new()
UpdateManager-->>UpdateTask: manager instance
UpdateTask->>UpdateManager: check_update().await
UpdateManager->>API: get_latest(channel)
API-->>UpdateManager: ReleaseInfo
UpdateManager->>UpdateManager: compare_versions()
alt Update available
UpdateManager-->>UpdateTask: Some((version, sha256))
else No update
UpdateManager-->>UpdateTask: None
end
deactivate UpdateTask
AppRunner->>EventLoop: new().with_update_check_task(task)
AppRunner->>EventLoop: run()
activate EventLoop
EventLoop->>UI: Initial render
UI-->>User: Display TUI
loop Main Event Loop
EventLoop->>EventLoop: tokio::select!
alt Update task completes
UpdateTask-->>EventLoop: Ok(Some((version, sha256)))
EventLoop->>AppState: update_status = Available
EventLoop->>AppState: update_version = version
EventLoop->>AppState: toasts.info("new version available")
EventLoop->>UI: render()
UI->>UI: render_update_banner()
UI-->>User: Show "🔄 A new version is available (X.Y.Z)"
else User input event
EventLoop->>EventLoop: handle_engine_event()
else Stream event
EventLoop->>EventLoop: handle_stream_event()
else Tool event
EventLoop->>EventLoop: handle_tool_event()
end
end
deactivate EventLoop
src/cortex-tui/src/app/state.rs
Outdated
Comment on lines
25
to
36
| /// Status of the auto-update notification system | ||
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
| pub enum UpdateNotificationStatus { | ||
| /// Update check in progress | ||
| Checking, | ||
| /// A new version is available | ||
| Available, | ||
| /// Currently downloading the update | ||
| Downloading, | ||
| /// Download complete, restart required | ||
| RestartRequired, | ||
| } |
There was a problem hiding this comment.
Defined states Checking, Downloading, and RestartRequired that aren't currently used by the implementation - only Available is ever set in core.rs:391
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cortex-tui/src/app/state.rs
Line: 25:36
Comment:
Defined states `Checking`, `Downloading`, and `RestartRequired` that aren't currently used by the implementation - only `Available` is ever set in `core.rs:391`
How can I resolve this? If you propose a fix, please make it concise.0ab95fd to
a7652b4
Compare
Add background update checking on TUI startup with visual notification: - Add UpdateStatus enum tracking: Checking, Available, Downloading, Downloaded, UpToDate, and Error states - Integrate update check in app runner on startup (background async) - Display update banner in MinimalSessionView input area showing: - 'Checking for updates...' during check - 'A new version (vX.X.X) is available' when update found - 'Downloading update...' during download - 'Restart to apply update' after download completes - Add security hardening to cortex-update: - Enforce HTTPS for update URLs (reject insecure except localhost) - Add path traversal protection in archive extraction - Use cryptographically secure random bytes for temp directories - Fix TOCTOU race condition in tar/zip extraction - Add SAFETY comments for unsafe Windows API calls - Address clippy warnings and code quality improvements
d65aa2b to
5b75003
Compare
Removed unused variants (Checking, CheckFailed, UpToDate) from UpdateStatus enum as per Greptile code review recommendation. Only variants that are actually used in the codebase are retained: NotChecked, Available, Downloading, and ReadyToRestart.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements a complete auto-update notification system for the Cortex TUI CLI that:
Features
A new version (X.Y.Z) is available- When an update is detectedDownloading... X%- During update download (with progress percentage)You must restart to run the latest version- After successful download/installationChanges
cortex-update crate (Security Fixes)
#![allow(warnings, clippy::all)]warning suppressiongetrandomcortex-tui crate (Feature Implementation)
cortex-updateas a dependencyUpdateStatusenum to track update states (NotChecked, Checking, Available, Downloading, ReadyToRestart, CheckFailed, UpToDate)update_statusandupdate_infofields toAppStaterender_update_banner()function in MinimalSessionView renderingAppRunner::run_direct_provider()Testing
cargo check -p cortex-update -p cortex-tuiScreenshots
The update banner appears above the input box in one of these styles:
↑ A new version (0.2.0) is available(accent color, bold)⟳ Downloading update... 45%(warning color)✓ You must restart to run the latest version(success color, bold)