Skip to content

Add bundle update awareness: outdated, update commands and async check#48

Open
shwetank-dev wants to merge 5 commits intomainfrom
issue-37-cli-add-bundle-update-awareness
Open

Add bundle update awareness: outdated, update commands and async check#48
shwetank-dev wants to merge 5 commits intomainfrom
issue-37-cli-add-bundle-update-awareness

Conversation

@shwetank-dev
Copy link
Collaborator

Summary

Closes #37

  • Extract shared cache helpers into utils/cache.ts — moves getCacheDir, getCacheMetadata, writeCacheMetadata out of run.ts into a shared module for reuse across commands
  • Add async update check during mpak run — fire-and-forget background check against the registry after spawning the MCP server. Throttled to once per hour via lastCheckedAt in cache metadata. Prints a notice to stderr if a newer version exists
  • Add mpak outdated / mpak bundle outdated — scans ~/.mpak/cache/, checks each cached registry bundle against the registry in parallel, prints a table of bundles with newer versions available. Supports --json
  • Add mpak update / mpak bundle update — with a package name, downloads the latest version and replaces the cache. Without args, runs the outdated check first and updates all stale bundles sequentially. Continues on partial failure. Supports --json
  • New shared helpers in cache.ts: listCachedBundles() (scans cache, skips _local/, reads manifest + meta), downloadAndExtract() (download + zip bomb check + extract + write metadata)
  • 24 new tests covering listCachedBundles (10 tests with real temp dirs), getOutdatedBundles (6 tests with mocked SDK), and handleUpdate (8 tests with mocked dependencies)

Test plan

  • pnpm typecheck passes
  • pnpm lint passes
  • pnpm test passes (132 tests, 10 test files)
  • mpak outdated works against real cache (3 cached bundles, all up to date)
  • mpak outdated --json outputs valid JSON
  • mpak update works (reports all up to date)
  • mpak update --json outputs valid JSON
  • mpak bundle outdated and mpak bundle update aliases work
  • Test with an actually outdated bundle (manually downgrade cache metadata)

🤖 Generated with Claude Code

shwetank-dev and others added 4 commits March 15, 2026 16:04
Move getCacheDir, getCacheMetadata, writeCacheMetadata, and
CacheMetadata interface from run.ts into a shared utils/cache.ts
module. This prepares for the new `outdated` and `update` commands
(#37) which need the same cache utilities.

No behavior change — run.ts imports from the new location and
all existing tests pass with updated imports.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
After spawning the MCP server, fire a non-blocking background check
against the registry. If the cached version differs from latest,
print an update notice to stderr. Uses a 1-hour TTL (lastCheckedAt
field in .mpak-meta.json) to avoid hitting the registry on every run.
Errors are silently swallowed. Local bundles skip the check entirely.

The exit handler waits up to 3s for the check to complete before
calling process.exit(), so the notice and metadata write aren't lost.

Refs #37

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds two new CLI commands for bundle update awareness:

- `mpak outdated` / `mpak bundle outdated`: scans ~/.mpak/cache/,
  checks each cached registry bundle against the registry, and prints
  a table of bundles with newer versions available. Supports --json.

- `mpak update [@scope/name]` / `mpak bundle update [@scope/name]`:
  with a name, downloads the latest version and replaces the cache.
  Without args, runs the outdated check first and updates all stale
  bundles sequentially.

New shared helpers in cache.ts:
- listCachedBundles(): scans cache dir, skips _local/, reads
  manifest.json + .mpak-meta.json from each entry
- downloadAndExtract(): reusable download+extract+write-metadata flow
  with zip bomb protection

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- cache.test.ts (10 tests): listCachedBundles() using real temp dirs.
  Covers empty/missing cache, multiple bundles, _local/ skipping,
  missing or corrupt manifest/meta files, non-directory entries,
  and verifying name is read from manifest not directory name.

- outdated.test.ts (6 tests): getOutdatedBundles() with mocked SDK
  client. Covers empty cache, all-up-to-date, identifying outdated
  bundles with correct versions, alphabetical sorting, skipping
  bundles deleted from registry, and parallel checking.

- update.test.ts (8 tests): handleUpdate() with mocked
  downloadAndExtract and getOutdatedBundles. Covers single-bundle
  update, update-all, JSON output for both modes, continuation on
  partial failure, and not calling getOutdatedBundles in single mode.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
return results.sort((a, b) => a.name.localeCompare(b.name));
}

export async function handleOutdated(options: OutdatedOptions = {}): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handleOutdated calls listCachedBundles twice — outdated.ts:51 calls listCachedBundles() to check if empty, then getOutdatedBundles() at line 54 calls it again internally. could pass the list in, or just let getOutdatedBundles return empty.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Split downloadAndExtract into resolveBundle + downloadAndExtract so
run.ts can check the resolved version against cache before downloading.
Extract shared extractZip helper (with zip bomb protection) used by both
registry and local bundle paths, eliminating duplicate security-critical
code from run.ts. Remove redundant listCachedBundles call in outdated.ts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mgoldsborough mgoldsborough added the qa-reviewed QA review completed with no critical issues label Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

qa-reviewed QA review completed with no critical issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI: Add bundle update awareness (outdated check, update command)

2 participants