Skip to content

feat(bun): track provider packages for automatic cleanup#10275

Open
jerome-benoit wants to merge 15 commits intoanomalyco:devfrom
jerome-benoit:feat/provider-package-tracking
Open

feat(bun): track provider packages for automatic cleanup#10275
jerome-benoit wants to merge 15 commits intoanomalyco:devfrom
jerome-benoit:feat/provider-package-tracking

Conversation

@jerome-benoit
Copy link
Contributor

@jerome-benoit jerome-benoit commented Jan 23, 2026

Fixes #10276

What changed

Track provider→package mappings in package.json under opencode.providers. Reference counting ensures packages are only removed when no provider uses them.

Key changes:

  • Add opencode.providers section to track which provider uses which package
  • Cleanup old packages only after successful install (not before)
  • Check if other providers still use a package before removing it
  • Handle version=latest with PackageRegistry.isOutdated() for proper staleness detection
  • Refactor helpers: readPackageJson, writePackageJson, track, cleanup, resolveVersion, finalize

How to verify

cd packages/opencode
bun test ./test/bun.test.ts
bun test --coverage ./test/bun.test.ts

19 tests cover the full decision tree for BunProc.install().

Copilot AI review requested due to automatic review settings January 23, 2026 16:45
@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds automatic tracking and cleanup of npm packages used by providers to prevent accumulation of unused dependencies when providers switch SDKs.

Changes:

  • Adds provider-to-package tracking in package.json under opencode.providers section
  • Modifies BunProc.install() to accept an optional providerID parameter for tracking
  • Implements automatic removal of old packages when a provider switches to a different SDK
  • Adds OPENCODE_TEST_CACHE environment variable for test isolation

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
packages/opencode/src/bun/index.ts Implements provider tracking logic, package switching detection, and automatic cleanup of old packages
packages/opencode/src/provider/provider.ts Passes model.providerID to BunProc.install() to enable tracking
packages/opencode/src/global/index.ts Adds dynamic getter for cache path that respects OPENCODE_TEST_CACHE env var
packages/opencode/test/bun.test.ts Adds 10 integration tests covering provider tracking, package switching, and backward compatibility

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

jerome-benoit and others added 9 commits February 4, 2026 20:02
When a provider switches SDK packages, the old package is now automatically
removed to avoid accumulating unused dependencies in the cache.

- Add provider tracking in package.json under opencode.providers section
- Modify BunProc.install() to accept optional providerID parameter
- Remove old package when provider switches to a different SDK
- Add comprehensive integration tests for provider tracking
- Don't remove package if other providers still use it
- Fix version comparison to handle "latest" correctly
- Add test for shared package scenario
@jerome-benoit jerome-benoit force-pushed the feat/provider-package-tracking branch from efaf2f4 to 29ccd76 Compare February 4, 2026 19:04
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.

Provider SDK packages accumulate in cache when switching

1 participant