Skip to content

feat(app): add startup auto-update for interactive commands#96

Merged
andrewmelchor merged 2 commits intomainfrom
feat(app)/auto-update
Mar 1, 2026
Merged

feat(app): add startup auto-update for interactive commands#96
andrewmelchor merged 2 commits intomainfrom
feat(app)/auto-update

Conversation

@andrewmelchor
Copy link
Copy Markdown
Member

Adds automatic update checks and optional auto-updates on startup for interactive commands (open, tui, web). Updates are cached for 24 hours and failed upgrades trigger a 24-hour backoff before retrying.

Details

New Features:

  • Startup auto-update - treq open, treq tui, and treq web now automatically check for updates on startup
  • Auto-upgrade support - For known install methods, updates can be automatically applied in the background (takes effect on next run)
  • CLI flags - Added --auto-update and --no-auto-update flags to all interactive commands (default: enabled)
  • Environment variable - Set TREQ_AUTO_UPDATE=0 to globally disable auto-updates
  • Smart caching - Update checks are cached for 24 hours in ~/.treq/auto-update.json
  • Backoff logic - Failed upgrade attempts are backed off for 24 hours before retrying

Implements automatic update checks and optional auto-upgrade for
treq open, tui, and web commands. Features include:
- 24-hour check caching in ~/.treq/auto-update.json
- 24-hour backoff for failed upgrade attempts
- --auto-update/--no-auto-update CLI flags (default: enabled)
- TREQ_AUTO_UPDATE environment variable support
- TUI toast notifications for update states
- Comprehensive test coverage for new update module
@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Feb 27, 2026

Greptile Summary

This PR implements automatic update functionality for interactive commands (treq open, treq tui, treq web). The implementation adds comprehensive semver parsing and comparison logic to prevent downgrades, ensuring only strictly newer versions are installed.

Key Changes:

  • Version comparison: Added proper semver parsing with prerelease support to prevent accidental downgrades or reinstalls of the same version
  • Smart caching: Update checks cached for 24 hours in ~/.treq/auto-update.json to reduce network calls
  • Backoff logic: Failed upgrade attempts trigger a 24-hour backoff before retry to prevent infinite loops
  • User control: CLI flags (--auto-update/--no-auto-update) and environment variable (TREQ_AUTO_UPDATE) for opt-out
  • Non-blocking: Updates run in background, never blocking application startup
  • UI integration: TUI shows toast notifications for update outcomes; web command logs to console

Implementation Quality:

  • Comprehensive test coverage including edge cases (caching, backoff, version comparison scenarios)
  • Robust error handling with graceful degradation (best-effort state writes)
  • Type-safe implementation with well-defined outcome types
  • Proper state management with normalization and validation

Confidence Score: 5/5

  • This PR is safe to merge with no identified risks
  • The implementation is well-designed with proper version comparison logic, comprehensive test coverage, robust error handling, and user control options. The auto-update feature is non-blocking and includes smart caching and backoff mechanisms. No logical errors, security issues, or potential bugs were identified during review.
  • No files require special attention

Important Files Changed

Filename Overview
packages/app/src/update/auto-update.ts Added semver parsing, version comparison, and auto-update orchestration with proper error handling and backoff logic
packages/app/src/update/state.ts Implemented state persistence with validation and best-effort file I/O
packages/app/src/cmd/web.ts Added --auto-update flag and runs update check in background after server starts
packages/app/src/tui/context/update.tsx React context that runs auto-update on mount and displays toast notifications for different outcomes
packages/app/test/update/auto-update.test.ts Comprehensive tests covering caching, backoff, version comparison, and all outcome scenarios

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    Start[Interactive Command Starts] --> CheckEnabled{Auto-update enabled?}
    CheckEnabled -->|No| Disabled[Status: disabled]
    CheckEnabled -->|Yes| CheckInteractive{Process is TTY?}
    CheckInteractive -->|No| NonInteractive[Status: disabled - non_interactive]
    CheckInteractive -->|Yes| GetMethod[Detect install method]
    
    GetMethod --> CheckCache{Cache valid?<br/>< 24h old}
    CheckCache -->|Yes| UseCache[Use cached version]
    CheckCache -->|No| FetchLatest[Fetch latest from npm]
    
    FetchLatest -->|Error| Failed1[Status: failed - check phase]
    FetchLatest -->|Success| SaveCache[Save to cache]
    SaveCache --> UseCache
    
    UseCache --> CompareVersion{Version comparison}
    CompareVersion -->|Current >= Latest| UpToDate[Status: up_to_date]
    CompareVersion -->|Latest > Current| CheckMethod{Install method known?}
    
    CheckMethod -->|Unknown| Manual[Status: available_manual]
    CheckMethod -->|Known| CheckBackoff{Recent failure?<br/>< 24h}
    
    CheckBackoff -->|Yes| Backoff[Status: backoff_skipped]
    CheckBackoff -->|No| RunUpgrade[Run upgrade command]
    
    RunUpgrade -->|Success| Updated[Status: updated<br/>Save success state]
    RunUpgrade -->|Error| Failed2[Status: failed - upgrade<br/>Save failure state]
Loading

Last reviewed commit: 3603e92

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f49af07782

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@andrewmelchor andrewmelchor merged commit 2e90d86 into main Mar 1, 2026
2 checks passed
@andrewmelchor andrewmelchor deleted the feat(app)/auto-update branch March 1, 2026 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant