Skip to content

feat: auto-update CLI on major version gap#77

Open
ali-wljray wants to merge 2 commits into
mainfrom
feat/auto-update
Open

feat: auto-update CLI on major version gap#77
ali-wljray wants to merge 2 commits into
mainfrom
feat/auto-update

Conversation

@ali-wljray

@ali-wljray ali-wljray commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add auto-update logic that automatically upgrades the CLI when a significant version gap is detected, instead of just showing a notification banner.

Auto-update trigger conditions

The CLI will auto-update when either condition is met:

  1. Major version bump — the latest major version > current major version (e.g. 2.0.0 vs 1.x.x)
  2. Large minor gap — same major version, but latest.minor - current.minor > 3 (e.g. 1.7.0 vs 1.3.0)

For smaller version differences, the existing "Update available" banner is preserved.

示例输出效果

大版本自动更新时:

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ⚡ Major update detected: 1.2.3 → 2.0.0
  Auto-updating to keep your CLI up to date...
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  ✓ Update complete: 1.2.3 → 2.0.0
  Run bl --version to verify.

Changes

packages/cli/src/utils/update-checker.ts

  • Added isMajorUpgrade(latest, current) — determines if the version gap warrants auto-update
  • Added performAutoUpdate(currentVersion, latestVersion) — executes the auto-update flow:
    • Friendly visual banner distinguishing "Major update" vs "Significant update"
    • Runs npm install -g bailian-cli@latest
    • Verifies the installed version
    • Updates local cache (update-state.json)
    • Syncs agent skill (npx skills add modelstudioai/cli --all -g -y)
    • Graceful fallback on failure with manual update instructions

packages/cli/src/main.ts

  • Post-command update notification now branches:
    • Major upgrade → calls performAutoUpdate() for automatic upgrade
    • Minor upgrade → shows the existing notification banner

Design decisions

  • Auto-update runs after the user's command completes, so it never blocks the current operation
  • All errors are silently handled — auto-update failure never crashes the CLI
  • CI / non-TTY environments are skipped (inherits existing checkForUpdate guard)
  • The update banner uses distinct messaging for major vs significant updates

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.

2 participants