Skip to content
Merged
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
8 changes: 4 additions & 4 deletions src/codegen/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ def version_callback(value: bool):

# Check for updates on startup (non-blocking)
try:
from codegen.cli.commands.update import check_for_updates_on_startup

# Only check on actual command runs, not completions
# Only check when no arguments are passed (just "codegen" to launch TUI)
import sys

if not any(arg in sys.argv for arg in ["--help", "-h", "completion", "--version"]):
from codegen.cli.commands.update import check_for_updates_on_startup

if len(sys.argv) == 1:
check_for_updates_on_startup()
except ImportError:
pass # Update check dependencies not available
Expand Down
3 changes: 2 additions & 1 deletion src/codegen/cli/commands/update/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from rich.console import Console

import codegen
from .updater import UpdateManager, check_for_updates_on_startup

from .updater import UpdateManager

console = Console()

Expand Down
24 changes: 16 additions & 8 deletions src/codegen/cli/commands/update/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

# Update configuration
UPDATE_CHECK_FILE = Path.home() / ".codegen" / "update_check.json"
UPDATE_CHECK_INTERVAL = timedelta(hours=24) # Check for updates once per day
UPDATE_CHECK_INTERVAL = timedelta(hours=12) # Check for updates once per day


class InstallMethod(Enum):
Expand Down Expand Up @@ -219,7 +219,7 @@ def _save_last_check_time(self) -> None:
with open(UPDATE_CHECK_FILE, "w") as f:
json.dump({"last_check": datetime.now().isoformat()}, f)

def perform_update(self, target_version: Optional[str] = None, dry_run: bool = False) -> bool:
def perform_update(self, target_version: Optional[str] = None, dry_run: bool = False, skip_confirmation: bool = False) -> bool:
"""Perform the update to a specific version or latest."""
current_version = self._get_current_version()

Expand Down Expand Up @@ -248,8 +248,8 @@ def perform_update(self, target_version: Optional[str] = None, dry_run: bool = F
if dry_run:
return True

# Confirm update
if not self._confirm_update():
# Confirm update (skip if already confirmed)
if not skip_confirmation and not self._confirm_update():
self.console.print("[yellow]Update cancelled[/yellow]")
return False

Expand Down Expand Up @@ -382,15 +382,23 @@ def _update_via_homebrew(self, target: Version) -> bool:


def check_for_updates_on_startup() -> None:
"""Check for updates on CLI startup (non-blocking)."""
"""Check for updates on CLI startup with blocking prompt."""
try:
# Only check if we haven't checked recently
manager = UpdateManager()
result = manager.check_for_updates(force=False)
result = manager.check_for_updates(force=True)

if result.update_available:
console.print(f"\n[cyan]ℹ️ A new version of Codegen CLI is available: {result.latest_version}[/cyan]")
console.print("[dim]Run 'codegen update' to upgrade[/dim]\n")
console.print(f"\n[cyan]ℹ️ A new version of Codegen CLI is available: {result.current_version} → {result.latest_version}[/cyan]")

if manager.perform_update():
Copy link

Choose a reason for hiding this comment

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

Bug: Update Check Confusion and Double Prompt

The check_for_updates_on_startup function always initiates an update check (force=True) and then unconditionally triggers the update prompt and process (if True:). This results in confusing messages like "X → None" when no update is available, and a double confirmation prompt because perform_update() doesn't pass skip_confirmation=True.

Fix in Cursor Fix in Web

console.print("\n[green]✓ Update completed successfully![/green]")
console.print("[yellow]Please restart your terminal or run a new codegen command to use the updated version.[/yellow]\n")
# Exit after successful update
sys.exit(0)
else:
console.print("\n[red]Update failed. Please try running 'codegen update' manually.[/red]\n")

except Exception:
# Silently ignore update check failures on startup
pass
Loading