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