-
Notifications
You must be signed in to change notification settings - Fork 6.6k
feat(opencode): add plugin management CLI commands #7611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
|
The following comment was made by an LLM, it may be inaccurate: No duplicate PRs found |
6766492 to
988c76c
Compare
Add `opencode plugin` subcommand with: - list: List installed plugins with current/latest version comparison - update [name]: Update all or specific plugin to latest version - add <name>: Add a plugin to config - remove <name>: Remove a plugin from config Implementation details: - Use Config.getPluginName() for consistent name extraction - URL-encode scoped packages for npm registry fetches - Normalize user input (e.g., '[email protected]' matches 'foo') - Validate config.plugin is array before processing - Atomic config writes (temp file + rename) - Proper error handling and status reporting - Fix spinner lifecycle (stop before re-start) - Show 'latest unknown' when registry fetch fails Fixes anomalyco#6159
988c76c to
10e0f75
Compare
henry-hsieh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is pretty helpful to install plugins without open TUI. I have some suggestions to the changes.
| async function fetchLatestVersion(pkg: string): Promise<string | null> { | ||
| try { | ||
| const encodedPkg = encodeURIComponent(pkg).replace("%40", "@") | ||
| const response = await fetch(`https://registry.npmjs.org/${encodedPkg}/latest`, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the registry should respect how the npm is configured like this code block.
| async function readGlobalConfig(): Promise<{ filePath: string; data: Config.Info }> { | ||
| const filePath = path.join(Global.Path.config, "opencode.json") | ||
| try { | ||
| const text = await fs.readFile(filePath, "utf-8") | ||
| const data = JSON.parse(text) as Config.Info | ||
| return { filePath, data } | ||
| } catch (err: unknown) { | ||
| if ((err as NodeJS.ErrnoException).code === "ENOENT") { | ||
| return { filePath, data: {} } | ||
| } | ||
| throw err | ||
| } | ||
| } | ||
|
|
||
| async function writeGlobalConfig(filePath: string, data: Config.Info): Promise<void> { | ||
| await fs.mkdir(path.dirname(filePath), { recursive: true }) | ||
| const tempPath = `${filePath}.tmp.${process.pid}` | ||
| await fs.writeFile(tempPath, JSON.stringify(data, null, 2)) | ||
| await fs.rename(tempPath, filePath) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Directly modifying global config seems a little weird. OpenCode merges several configs into one internal config.
I think following 3 configs should be considered:
Global config (~/.config/opencode/opencode.json) - user preferences
Custom config (OPENCODE_CONFIG env var) - custom overrides
Project config (opencode.json in project) - project-specific settings
Summary
Add CLI commands for managing OpenCode plugins, addressing the need for easy plugin updates without manual config editing.
Fixes #6159
Changes
Add
opencode pluginsubcommand with:list- List installed plugins with current/latest version comparisonupdate [name]- Update all or specific plugin to latest versionadd <name>- Add a plugin to configremove <name>- Remove a plugin from configImplementation Details
Config.getPluginName()for consistent name extraction,BunProc.install()for package installation@scope/pkg→%40scope%2Fpkg)update [email protected]andremove [email protected]correctly matchfoopluginpluginfieldDemo Output
How to verify
Testing Done
plugin list- shows installed plugins with version infoplugin list- shows "latest unknown" when fetch failsplugin update- updates all plugins to latestplugin update <name>- updates specific pluginplugin update <name>@<version>- normalizes input correctlyplugin add <name>- installs and adds plugin to configplugin add <name>@<version>- installs specific versionplugin remove <name>- removes plugin from configplugin remove <name>@<version>- normalizes input correctly