Skip to content

Conversation

@kiloconnect
Copy link
Contributor

@kiloconnect kiloconnect bot commented Jan 2, 2026

Summary

This PR adds caching functionality to the CLI version update checker to avoid checking the npm registry on every invocation.

Changes

  • Caching Implementation: Added file-based cache stored in ~/.kilocode/cli/global/version-check-cache.json
  • Cache Duration: 24 hours (configurable via CACHE_DURATION_MS constant)
  • Error Handling: Gracefully handles cache corruption, file system errors, and network failures
  • Fallback Strategy: Falls back to cached data when npm registry is unavailable
  • Test Coverage: Comprehensive test suite covering all caching scenarios

Requirements Met

✅ Performs async check at CLI startup (already existed)
✅ Uses npm registry API via package-json package (already existed)
✅ Displays helpful update message (already existed)
✅ Non-blocking async operation (already existed)
✅ Handles errors gracefully (already existed + enhanced)
NEW: Rate-limiting via 24-hour cache to avoid checking on every invocation

Technical Details

The cache stores:

  • lastChecked: Timestamp of last check
  • latestVersion: Latest version from npm
  • isOutdated: Boolean indicating if update is available

Cache validation:

  • Checks if cache file exists and is valid JSON
  • Validates cache structure (correct types)
  • Checks if cache age is less than 24 hours
  • Falls back to npm registry if cache is invalid or expired

Testing

Added comprehensive test suite (cli/src/utils/__tests__/auto-update.test.ts) covering:

  • Fresh npm fetch when no cache exists
  • Cache hit when cache is valid
  • Cache miss when cache is expired
  • Error handling for corrupted cache
  • Error handling for network failures
  • Fallback to cached data on errors
  • File system error handling

Performance Impact

  • Before: npm registry API call on every CLI invocation
  • After: npm registry API call once per 24 hours
  • Benefit: Reduced network requests, faster CLI startup, better offline experience

- Implement file-based cache for version check results
- Cache stored in ~/.kilocode/cli/global/version-check-cache.json
- Reduces npm registry API calls from every invocation to once per day
- Gracefully handles cache corruption and network errors
- Falls back to cached data on API failures
- Add comprehensive test coverage for caching logic

Resolves requirement for rate-limiting version checks
@changeset-bot
Copy link

changeset-bot bot commented Jan 2, 2026

🦋 Changeset detected

Latest commit: 05ebcac

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@kilocode/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@olearycrew olearycrew closed this Jan 2, 2026
@kiloconnect
Copy link
Contributor Author

kiloconnect bot commented Jan 2, 2026

✅ No Issues Found

3 files reviewed | Confidence: 95% | Recommendation: Merge

Review Details

Files:

  • .changeset/cli-version-check-caching.md - Proper changeset format
  • cli/src/utils/auto-update.ts - Caching implementation
  • cli/src/utils/__tests__/auto-update.test.ts - Comprehensive test suite

Checked: Security, bugs, performance, error handling

Highlights:

  • ✅ Proper error handling with silent failures for optional caching
  • ✅ Cache validation checks types of all fields before use
  • ✅ Graceful fallback to cached data on network errors
  • ✅ Directory creation ensured before writing cache
  • ✅ Comprehensive test coverage (13 test cases)
  • ✅ Proper kilocode_change markers per AGENTS.md guidelines
  • ✅ Changeset included with correct @kilocode/cli: patch format

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