opencode
opencode copied to clipboard
Plugin loader incorrectly appends @latest to GitHub references
Description
When using a GitHub-hosted plugin like github:owner/repo, OpenCode appends @latest to form github:owner/repo@latest, which Bun cannot resolve.
Root Cause
In packages/opencode/src/plugin/index.ts:
const lastAtIndex = plugin.lastIndexOf("@")
const pkg = lastAtIndex > 0 ? plugin.substring(0, lastAtIndex) : plugin
const version = lastAtIndex > 0 ? plugin.substring(lastAtIndex + 1) : "latest"
plugin = await BunProc.install(pkg, version) // becomes pkg + "@" + version
This creates github:owner/repo@latest which Bun fails to resolve with:
error: GET https://api.github.com/repos//latest/tarball/ - 404
error: github:owner/repo@latest failed to resolve
Bun's GitHub Dependency Format
According to Bun documentation, GitHub dependencies use # for version/tag specifiers, not @:
{
"lodash": "git+ssh://github.com/lodash/lodash.git#4.17.21",
"zod": "github:colinhacks/zod"
}
The @ syntax is only for npm registry packages.
Reproduction
bun add "github:lodash/lodash@latest"
# error: GET https://api.github.com/repos//latest/tarball/ - 404
bun add "github:lodash/lodash"
# Success - installs from default branch
bun add "github:lodash/lodash#main"
# Success - installs from main branch
Suggested Fix
Check if the plugin string starts with github: or git+ before appending version:
const isGitDependency = plugin.startsWith("github:") || plugin.startsWith("git+") || plugin.startsWith("git://")
if (isGitDependency) {
// Don't append @latest for git dependencies
// Or use # instead: pkg + "#" + version
plugin = await BunProc.install(pkg, undefined)
} else {
plugin = await BunProc.install(pkg, version)
}
Workaround
Publish the plugin to npm registry instead of using GitHub reference.