feat(cli): warn when a newer spec-kit release is available (#1320)
Summary
Addresses #1320 β when explicitly opted in, the CLI prints a one-line upgrade hint on launch if a newer release is available. Off by default; enabled with SPECIFY_ENABLE_UPDATE_CHECK=1. Even when enabled, suppressed in CI (CI=1) and when stdout is not a TTY. Cached for 24h in the platform user-cache dir. Every network / parse failure is swallowed β the user's command is never failed by the check.
Motivation
Observed in the wild: users running older CLIs (for example v0.3.0 still installed from PyPI, or v0.4.2 as in #2185) hit No matching release asset found for claude when they try specify init --ai claude. The legacy asset-download path was removed in the Stage 6 migration (#2063) and the release workflow stopped producing those assets starting v0.4.5, so old clients have no recovery path and no signal that the fix is to upgrade the CLI. A launch-time update warning turns this silent failure into actionable guidance.
This PR implements the spec in #1320 with one deliberate change requested in review: opt-in instead of opt-out, so air-gapped / network-constrained environments never reach GitHub by default.
- Check latest release on launch (only when opted in)
- Display upgrade command
- Env-var opt-in (
SPECIFY_ENABLE_UPDATE_CHECK=1) - Graceful offline handling
- Cache β€ 1 check per 24h
Changes
src/specify_cli/__init__.py
- New private helpers (near
get_speckit_version()):_parse_version_tuple()β tolerant parser (drops PEP 440 pre/post/dev/local segments)_update_check_cache_path()/_read_update_check_cache()/_write_update_check_cache()β JSON cache inplatformdirs.user_cache_dir("specify-cli")(UTF-8)_fetch_latest_version()βurllib.requestGET with 2s timeout; never raises_should_skip_update_check()β opt-in gate plus CI / non-TTY guards_check_for_updates()β top-level wrapper; all errors swallowed
callback()invokes_check_for_updates()for any non-versioninvocation (including barespecify);versionalready prints the installed version, so we skip there to avoid double-printing.- No new third-party deps β
platformdirsis already a declared dependency.
tests/test_update_check.py
New tests covering:
- Version-tuple parsing (happy paths, PEP 440 tails, garbage input,
None) - Cache read/write (fresh, stale, missing, corrupt, round-trip)
urlopensuccess / network error / malformed JSON / missing tag- End-to-end helper behavior: warning text, no-op when up-to-date, cache-hit skips network, network failure is silent, opt-in default-off short-circuits,
CI=1wins over the opt-in flag (with a pinnedisatty()so the CI guard is what's actually being tested)
CHANGELOG.md
Entry under ## [Unreleased].
docs/installation.md
"Update Notifications" subsection documenting the opt-in env var and the suppression conditions (CI, non-TTY).
Test plan
- [x]
uv run pytest tests/test_update_check.pyβ 27 passed - [x] Manual smoke test β
SPECIFY_ENABLE_UPDATE_CHECK=1against a simulated outdated version: warning rendered, cache written, second invocation hit cache and skipped network - [x] Default invocation (no env var) β banner renders, no warning, no network call
Manual warning output
β A new spec-kit version is available: v0.6.2 (you have v0.3.0)
Upgrade: uv tool install specify-cli --force --from git+https://github.com/github/[email protected]
(unset SPECIFY_ENABLE_UPDATE_CHECK to disable this check)
Notes for reviewers
- Review feedback addressed across two rounds (commits
1ffcbf9β81a7418βe45a36aβb75e55f):- Opt-out β opt-in via
SPECIFY_ENABLE_UPDATE_CHECK(per @mnriem) - Type annotation
str | Noneon_parse_version_tuple - Explicit
encoding="utf-8"on cache read/write - Doc/comment wording: "never fails the command" (cache-miss adds bounded startup latency)
- Update check now runs on bare
specifytoo test_ci_suppresses_even_when_opted_inpinsisatty()=Trueso it actually verifies the CI guard
- Opt-out β opt-in via
- Related (out of scope): #2185 is a downstream symptom of the same class of problem this PR mitigates.
Hi @mnriem β round-2 Copilot feedback addressed in b75e55f:
- Test brittleness (
tests/test_update_check.py:271):test_ci_suppresses_even_when_opted_innow pinssys.stdout.isatty()=True, so it actually verifies the CI guard instead of short-circuiting on the TTY check (verified locally β removing the CI guard makes the test fail). - PR description / spec mismatch (
src/specify_cli/__init__.py:1797): rewrote the PR body so it matches the shipped opt-in behavior (SPECIFY_ENABLE_UPDATE_CHECK=1) β the previous body still referenced the original opt-out wording.
All 27 tests in tests/test_update_check.py pass. Ready for another look whenever you have a moment, thanks!
Resolved merge conflict with main in d8c16f7. Only CHANGELOG.md had a real conflict β kept the existing ## [Unreleased] entry (the update-check feature) above the new ## [0.8.1] section that landed on main. src/specify_cli/__init__.py and docs/installation.md auto-merged cleanly. Verified locally: tests/test_update_check.py β 27/27 pass; remaining suite β 838 passed, 29 skipped, 2 unrelated pre-existing failures in tests/test_workflows.py (Gemini CLI quota timeouts, not caused by this PR).
Please address Copilot feedback. If not applicable, please explain why
@mnriem β also rebased onto current main and integrated with #2550 (_version.py extraction). The update-check
helpers now live in _version.py next to _get_installed_version / _fetch_latest_release_tag / _is_newer, which
we reuse instead of duplicating. Behavior identical (same opt-in env var, same 24h TTL, same negative caching). PR no
longer shows as DIRTY.
Tests:
tests/test_update_check.pyβ 15/15 pass (negative-cache coverage preserved through the move)tests/test_version_imports.py,tests/test_console_imports.py,tests/test_utils_assets_imports.py,tests/test_cli_version.pyβ 16/16 pass
Ready for another look, thanks!
Addressed the latest Copilot feedback in c3e063d:
- Moved startup update-check imports to the top of
_version.pyto satisfy Ruff E402. - Wrapped malformed/unexpected
_fetch_latest_release_tag()failures so they write a negative cache entry before returning. - Updated the install docs to match the current 5s fetch timeout.
- Tightened wording from "never blocks" to "never fails" and added regression coverage for exception-backed negative caching.
Checks:
uvx ruff check src tests/test_update_check.pyPYTHONPATH=src uv run --extra test pytest tests/test_update_check.py tests/test_version_imports.py tests/test_console_imports.py tests/test_cli_version.pyβ 29 passed
Addressed the latest Copilot feedback and updated the branch with current upstream/main:
- Reworded the startup update-check comments/docstring from βone-lineβ to βupgrade guidanceβ to match the current three-line output.
- Changed the upgrade command to use the exact GitHub release tag (
latest_tag) instead of hard-coding avprefix, with regression coverage for tags withoutv. - Added cache validation so malformed
latestvalues are treated as cache misses, plus regression coverage that verifies the helper fetches again. - Updated the changelog wording from
CI=1to βwhenCIis setβ. - Merged current
upstream/mainand resolved the changelog conflict; GitHub now reports the PR as mergeable.
Checks:
uvx ruff check src tests/test_update_check.pyPYTHONPATH=src uv run --extra test pytest tests/test_update_check.py tests/test_version_imports.py tests/test_console_imports.py tests/test_utils_assets_imports.py tests/test_cli_version.py -qβ 35 passed
Ready for another look, thanks!
Please address Copilot feedback
Addressed in 8be289d:
- Hardened
_write_update_check_cache()against symlink-based file overwrites β destination and parent are checked withis_symlink(), and the write itself usesos.open(..., O_NOFOLLOW, 0o600)so the kernel refuses to follow a symlink even under a TOCTOU race. New regression tests cover both a symlinked cache file and a symlinked parent directory. - Reverted CHANGELOG.md to
origin/mainper your request β happy to keep the changelog out of feature PRs going forward.
Please address Copilot feedback
Please address Copilot feedback and revert changes to CHANGELOG.md
@mnriem Addressed the latest Copilot feedback in 0facef1 and synced the branch with current main in d134ea1:
- Symlink-hardening tests now skip via
pytest.skipwhen the platform or user cannot create symlinks. - The update-check cache writer now uses
os.fdopen(...).write()so the full JSON payload is written instead of relying on a singleos.write()call. - Removed this branch's
CHANGELOG.mdentry as requested; the PR diff no longer includes the changelog.
Checks: tests/test_update_check.py, tests/test_version_imports.py, tests/test_console_imports.py, tests/test_utils_assets_imports.py, and tests/test_cli_version.py β 45 passed; git diff --check upstream/main HEAD passed.
Posted on behalf of @ATelbay by OpenAI Codex.
Please address Copilot feedback