feat(update-check): show extension update notice on exit#1236
Merged
feat(update-check): show extension update notice on exit#1236
Conversation
The CLI exit hook already prints "Update available" when a newer @jackwener/opencli is on npm. Extension updates were only surfaced inside `opencli doctor`, so users running normal browser commands had no signal that the Chrome extension was out of date. Solution piggybacks on the existing 24h background fetch: - Daemon writes the live extensionVersion + lastSeenAt into the shared cache on every hello handshake (rare event, one fs.writeFileSync). - CLI exit hook reads the cache it already loads and prints an extra extension notice when a newer release is available and the cache is fresh (<7d). - writeCache becomes a read-merge-write so the daemon's currentExtensionVersion and the CLI's npm latestVersion don't clobber each other. Net cost on the CLI hot path: zero new I/O, zero new daemon contact. The notice formatter is split into a pure helper (buildUpdateNotices) so the staleness window, equality, and combined-notice cases are unit-tested without touching disk or stderr.
Self-review caught a TypeError path: if the daemon's hello handler runs `recordExtensionVersion` before the CLI's npm fetch ever populated the cache, the resulting cache file has only `currentExtensionVersion` + `extensionLastSeenAt` and no `latestVersion`. The next CLI run then fed `undefined` into `isNewer`, which calls `.replace(...)` on it. - Mark `lastCheck` and `latestVersion` optional in the cache schema (the merge pattern means either side may write first). - Guard the CLI notice on `cache.latestVersion` being defined before comparing. - Guard `checkForUpdateBackground`'s 24h short-circuit on `lastCheck` being defined. - Add a test for the daemon-only cache case.
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
extensionVersion+lastSeenAtinto the shared~/.opencli/update-check.jsoncache on each hello handshake.Extension update availableline when a newer release is in cache andlastSeenAtis within the last 7 days.writeCacheis now a read-merge-write so the daemon'scurrentExtensionVersionand the CLI's npmlatestVersionwrites don't clobber each other.Why
Today only
opencli doctorsurfaces extension drift. Users running normal browser commands have no signal that the Chrome extension is out of date. The shared cache already containslatestExtensionVersion(refreshed every 24h via the existing GitHub fetch); we just needed the current installed extension version to compare against, and the daemon already knows it from the hello handshake.Cost
fs.writeFileSync(small JSON) per extension reconnect — a rare event.Staleness guard
If the user hasn't run a browser command in a week,
extensionLastSeenAtbecomes stale and we suppress the notice rather than risk reporting an outdatedcurrentExtensionVersion. The window isEXTENSION_STALE_MS = 7 days.Test plan
npm run typecheckOPENCLI_DAEMON_PORT=29125 npx vitest run src/update-check.test.ts src/daemon.test.ts src/commands/daemon.test.ts src/doctor.test.ts src/browser/daemon-client.test.ts src/browser.test.ts— 67/67 passingbuildUpdateNotices: empty cache, CLI-only notice, ext-only notice, stale-window suppression, equal-version suppression, both-out-of-date.