Add support for 'update' command to the CLI to update itself#154
Add support for 'update' command to the CLI to update itself#154vincent-psarga merged 11 commits intomainfrom
Conversation
Greptile SummaryThis PR adds a self-update capability to the CLI, allowing users to run Key improvements from previous review feedback:
Implementation highlights:
All previously flagged issues have been addressed, and the implementation includes thorough test coverage. Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
Start([User runs update command]) --> CheckRuntime{Running via<br/>JS runtime?}
CheckRuntime -->|Yes - Local npm| LocalMsg[Show: update via<br/>npm update]
CheckRuntime -->|Yes - Global| GlobalMsg[Show: use standalone<br/>or npm install -g]
LocalMsg --> Exit1[Exit 1]
GlobalMsg --> Exit1
CheckRuntime -->|No| DetectMode{Executable<br/>or npm?}
DetectMode -->|Executable| FetchGH[Fetch latest from<br/>GitHub releases]
DetectMode -->|npm| FetchNpm[Fetch latest from<br/>npm registry]
FetchGH --> Validate[Filter & sort<br/>valid semver]
FetchNpm --> Compare{Latest ><br/>Current?}
Validate --> Compare
Compare -->|No| UpToDate[Already up to date]
UpToDate --> Exit0[Exit 0]
Compare -->|Yes| CheckOnly{--check<br/>flag?}
CheckOnly -->|Yes| ShowUpdate[Show available<br/>update]
ShowUpdate --> Exit1
CheckOnly -->|No| UpdateType{Update<br/>method?}
UpdateType -->|Executable| Download[Download binary<br/>to temp file]
Download --> AtomicReplace[Atomic rename<br/>over current]
AtomicReplace --> SetPerms[Set executable<br/>permissions]
SetPerms --> Success[Update successful]
UpdateType -->|npm| RunNpm[Run npm install -g]
RunNpm --> Success
Success --> Exit0
Last reviewed commit: f10cfad |
- Replace string equality with semver.gt() for correct handling of versions like 0.9.0 vs 0.10.0 - Fix test names to follow verb-first naming convention - Add test for current version newer than latest Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…order Explicitly sort CLI releases using semver.rcompare to ensure the latest version is selected regardless of GitHub API response ordering. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add checkOnly boolean flag to IUpdateHandlerDependencies - Skip download/npm install when --check-update is passed - Add tests for check-only mode (update available and up to date) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@greptile thoughts on the "--check-update" flag? |
|
Looking at the implementation, the What works well:
Suggestions:
The implementation in updateHandler.ts handles it cleanly: if (deps.checkOnly) {
return; // Exit after logging version comparison
}Overall, it's a good addition. The only change I'd strongly recommend is shortening the flag to just |
- Rename flag from --check-update to --check for brevity - Exit with code 1 when update is available in check-only mode - Exit with code 0 when already up to date (enables scripting) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@greptile can you report on the updated version? |
|
Great news! Both of your key suggestions have been implemented: ✅ Changes Made1. Flag shortened to check: flag({
long: 'check',
description: 'Only check if a newer version is available without performing the update',
}),Usage is now: 2. Exit codes implemented
This makes it script-friendly: if packmind-cli update --check; then
echo "Up to date!"
else
echo "Update available"
fiThe implementation is clean and follows the conventional pattern you recommended. The handler checks the version, logs the result, and exits appropriately in check-only mode before attempting any actual update. |
…runtime Detects if the CLI is running via node/bun/deno and blocks the update command to prevent accidental global npm installs or binary overwrites. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When the CLI is installed as a local project dependency, the update guard now suggests `npm update @packmind/cli` instead of the generic global install message. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|



Explanation
Let users easily update the CLI to its latest version.
Type of Change
Affected Components
Testing
TODO List