( plugin: string, enabled: boolean, scope?: InstallableScope, )
| 573 | * @returns Result indicating success/failure |
| 574 | */ |
| 575 | export async function setPluginEnabledOp( |
| 576 | plugin: string, |
| 577 | enabled: boolean, |
| 578 | scope?: InstallableScope, |
| 579 | ): Promise<PluginOperationResult> { |
| 580 | const operation = enabled ? 'enable' : 'disable' |
| 581 | |
| 582 | // Built-in plugins: always use user-scope settings, bypass the normal |
| 583 | // scope-resolution + installed_plugins lookup (they're not installed). |
| 584 | if (isBuiltinPluginId(plugin)) { |
| 585 | const { error } = updateSettingsForSource('userSettings', { |
| 586 | enabledPlugins: { |
| 587 | ...getSettingsForSource('userSettings')?.enabledPlugins, |
| 588 | [plugin]: enabled, |
| 589 | }, |
| 590 | }) |
| 591 | if (error) { |
| 592 | return { |
| 593 | success: false, |
| 594 | message: `Failed to ${operation} built-in plugin: ${error.message}`, |
| 595 | } |
| 596 | } |
| 597 | clearAllCaches() |
| 598 | const { name: pluginName } = parsePluginIdentifier(plugin) |
| 599 | return { |
| 600 | success: true, |
| 601 | message: `Successfully ${operation}d built-in plugin: ${pluginName}`, |
| 602 | pluginId: plugin, |
| 603 | pluginName, |
| 604 | scope: 'user', |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | if (scope) { |
| 609 | assertInstallableScope(scope) |
| 610 | } |
| 611 | |
| 612 | // ── Resolve pluginId and scope from settings ── |
| 613 | // Search across editable scopes for any mention (enabled or disabled) of |
| 614 | // this plugin. Does NOT pre-gate on installed_plugins.json. |
| 615 | let pluginId: string |
| 616 | let resolvedScope: InstallableScope |
| 617 | |
| 618 | const found = findPluginInSettings(plugin) |
| 619 | |
| 620 | if (scope) { |
| 621 | // Explicit scope: use it. Resolve pluginId from settings if possible, |
| 622 | // otherwise require a full plugin@marketplace identifier. |
| 623 | resolvedScope = scope |
| 624 | if (found) { |
| 625 | pluginId = found.pluginId |
| 626 | } else if (plugin.includes('@')) { |
| 627 | pluginId = plugin |
| 628 | } else { |
| 629 | return { |
| 630 | success: false, |
| 631 | message: `Plugin "${plugin}" not found in settings. Use plugin@marketplace format.`, |
| 632 | } |
no test coverage detected