File size: 25,736 Bytes
52efc7b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 | /**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {
debugLogger,
listExtensions,
getErrorMessage,
type ExtensionInstallMetadata,
} from '@google/gemini-cli-core';
import type { ExtensionUpdateInfo } from '../../config/extension.js';
import {
emptyIcon,
MessageType,
type HistoryItemExtensionsList,
type HistoryItemInfo,
} from '../types.js';
import {
type CommandContext,
type SlashCommand,
type SlashCommandActionReturn,
CommandKind,
} from './types.js';
import open from 'open';
import process from 'node:process';
import {
ExtensionManager,
inferInstallMetadata,
} from '../../config/extension-manager.js';
import { SettingScope } from '../../config/settings.js';
import { McpServerEnablementManager } from '../../config/mcp/mcpServerEnablement.js';
import { theme } from '../semantic-colors.js';
import { stat } from 'node:fs/promises';
import { ExtensionSettingScope } from '../../config/extensions/extensionSettings.js';
import { type ConfigLogger } from '../../commands/extensions/utils.js';
import { ConfigExtensionDialog } from '../components/ConfigExtensionDialog.js';
import { ExtensionRegistryView } from '../components/views/ExtensionRegistryView.js';
import React from 'react';
function showMessageIfNoExtensions(
context: CommandContext,
extensions: unknown[],
): boolean {
if (extensions.length === 0) {
context.ui.addItem({
type: MessageType.INFO,
text: 'No extensions installed. Run `/extensions explore` to check out the gallery.',
});
return true;
}
return false;
}
async function listAction(context: CommandContext) {
const extensions = context.services.agentContext?.config
? listExtensions(context.services.agentContext.config)
: [];
if (showMessageIfNoExtensions(context, extensions)) {
return;
}
const historyItem: HistoryItemExtensionsList = {
type: MessageType.EXTENSIONS_LIST,
extensions,
};
context.ui.addItem(historyItem);
}
function updateAction(context: CommandContext, args: string): Promise<void> {
const updateArgs = args.split(' ').filter((value) => value.length > 0);
const all = updateArgs.length === 1 && updateArgs[0] === '--all';
const names = all ? null : updateArgs;
if (!all && names?.length === 0) {
context.ui.addItem({
type: MessageType.ERROR,
text: 'Usage: /extensions update <extension-names>|--all',
});
return Promise.resolve();
}
let resolveUpdateComplete: (updateInfo: ExtensionUpdateInfo[]) => void;
const updateComplete = new Promise<ExtensionUpdateInfo[]>(
(resolve) => (resolveUpdateComplete = resolve),
);
const extensions = context.services.agentContext?.config
? listExtensions(context.services.agentContext.config)
: [];
if (showMessageIfNoExtensions(context, extensions)) {
return Promise.resolve();
}
const historyItem: HistoryItemExtensionsList = {
type: MessageType.EXTENSIONS_LIST,
extensions,
};
// eslint-disable-next-line @typescript-eslint/no-floating-promises
updateComplete.then((updateInfos) => {
if (updateInfos.length === 0) {
context.ui.addItem({
type: MessageType.INFO,
text: 'No extensions to update.',
});
}
context.ui.addItem(historyItem);
context.ui.setPendingItem(null);
});
try {
context.ui.setPendingItem(historyItem);
context.ui.dispatchExtensionStateUpdate({
type: 'SCHEDULE_UPDATE',
payload: {
all,
names,
onComplete: (updateInfos) => {
resolveUpdateComplete(updateInfos);
},
},
});
if (names?.length) {
const extensions = listExtensions(context.services.agentContext!.config);
for (const name of names) {
const extension = extensions.find(
(extension) => extension.name === name,
);
if (!extension) {
context.ui.addItem({
type: MessageType.ERROR,
text: `Extension ${name} not found.`,
});
continue;
}
}
}
} catch (error) {
resolveUpdateComplete!([]);
context.ui.addItem({
type: MessageType.ERROR,
text: getErrorMessage(error),
});
}
return updateComplete.then((_) => {});
}
async function restartAction(
context: CommandContext,
args: string,
): Promise<void> {
const extensionLoader =
context.services.agentContext?.config.getExtensionLoader();
if (!extensionLoader) {
context.ui.addItem({
type: MessageType.ERROR,
text: "Extensions are not yet loaded, can't restart yet",
});
return;
}
const extensions = extensionLoader.getExtensions();
if (showMessageIfNoExtensions(context, extensions)) {
return;
}
const restartArgs = args.split(' ').filter((value) => value.length > 0);
const all = restartArgs.length === 1 && restartArgs[0] === '--all';
const names = all ? null : restartArgs;
if (!all && names?.length === 0) {
context.ui.addItem({
type: MessageType.ERROR,
text: 'Usage: /extensions reload <extension-names>|--all',
});
return Promise.resolve();
}
let extensionsToRestart = extensionLoader
.getExtensions()
.filter((extension) => extension.isActive);
if (names) {
extensionsToRestart = extensionsToRestart.filter((extension) =>
names.includes(extension.name),
);
if (names.length !== extensionsToRestart.length) {
const notFound = names.filter(
(name) =>
!extensionsToRestart.some((extension) => extension.name === name),
);
if (notFound.length > 0) {
context.ui.addItem({
type: MessageType.WARNING,
text: `Extension(s) not found or not active: ${notFound.join(', ')}`,
});
}
}
}
if (extensionsToRestart.length === 0) {
// We will have logged a different message above already.
return;
}
const s = extensionsToRestart.length > 1 ? 's' : '';
const reloadingMessage = {
type: MessageType.INFO,
text: `Reloading ${extensionsToRestart.length} extension${s}...`,
color: theme.text.primary,
};
context.ui.addItem(reloadingMessage);
const results = await Promise.allSettled(
extensionsToRestart.map(async (extension) => {
if (extension.isActive) {
await extensionLoader.restartExtension(extension);
context.ui.dispatchExtensionStateUpdate({
type: 'RESTARTED',
payload: {
name: extension.name,
},
});
}
}),
);
const failures = results.filter(
(result): result is PromiseRejectedResult => result.status === 'rejected',
);
if (failures.length < extensionsToRestart.length) {
try {
await context.services.agentContext?.config.reloadSkills();
await context.services.agentContext?.config.getAgentRegistry()?.reload();
} catch (error) {
context.ui.addItem({
type: MessageType.ERROR,
text: `Failed to reload skills or agents: ${getErrorMessage(error)}`,
});
}
}
if (failures.length > 0) {
const errorMessages = failures
.map((failure, index) => {
const extensionName = extensionsToRestart[index].name;
return `${extensionName}: ${getErrorMessage(failure.reason)}`;
})
.join('\n ');
context.ui.addItem({
type: MessageType.ERROR,
text: `Failed to reload some extensions:\n ${errorMessages}`,
});
} else {
const infoItem: HistoryItemInfo = {
type: MessageType.INFO,
text: `${extensionsToRestart.length} extension${s} reloaded successfully`,
icon: emptyIcon,
color: theme.text.primary,
};
context.ui.addItem(infoItem);
}
}
async function exploreAction(
context: CommandContext,
): Promise<SlashCommandActionReturn | void> {
const settings = context.services.settings.merged;
const useRegistryUI = settings.experimental?.extensionRegistry;
if (useRegistryUI) {
const extensionManager =
context.services.agentContext?.config.getExtensionLoader();
if (extensionManager instanceof ExtensionManager) {
return {
type: 'custom_dialog' as const,
component: React.createElement(ExtensionRegistryView, {
onSelect: async (extension, requestConsentOverride) => {
debugLogger.log(`Selected extension: ${extension.extensionName}`);
await installAction(context, extension.url, requestConsentOverride);
context.ui.removeComponent();
},
onLink: async (extension, requestConsentOverride) => {
debugLogger.log(`Linking extension: ${extension.extensionName}`);
await linkAction(context, extension.url, requestConsentOverride);
context.ui.removeComponent();
},
onClose: () => context.ui.removeComponent(),
extensionManager,
}),
};
}
}
const extensionsUrl = 'https://geminicli.com/extensions/';
// Only check for NODE_ENV for explicit test mode, not for unit test framework
if (process.env['NODE_ENV'] === 'test') {
context.ui.addItem({
type: MessageType.INFO,
text: `Would open extensions page in your browser: ${extensionsUrl} (skipped in test environment)`,
});
} else if (
process.env['SANDBOX'] &&
process.env['SANDBOX'] !== 'sandbox-exec'
) {
context.ui.addItem({
type: MessageType.INFO,
text: `View available extensions at ${extensionsUrl}`,
});
} else {
context.ui.addItem({
type: MessageType.INFO,
text: `Opening extensions page in your browser: ${extensionsUrl}`,
});
try {
await open(extensionsUrl);
} catch {
context.ui.addItem({
type: MessageType.ERROR,
text: `Failed to open browser. Check out the extensions gallery at ${extensionsUrl}`,
});
}
}
}
function getEnableDisableContext(
context: CommandContext,
argumentsString: string,
): {
extensionManager: ExtensionManager;
names: string[];
scope: SettingScope;
} | null {
const extensionLoader =
context.services.agentContext?.config.getExtensionLoader();
if (!(extensionLoader instanceof ExtensionManager)) {
debugLogger.error(
`Cannot ${context.invocation?.name} extensions in this environment`,
);
return null;
}
const parts = argumentsString.split(' ');
const name = parts[0];
if (
name === '' ||
!(
(parts.length === 2 && parts[1].startsWith('--scope=')) || // --scope=<scope>
(parts.length === 3 && parts[1] === '--scope') // --scope <scope>
)
) {
context.ui.addItem({
type: MessageType.ERROR,
text: `Usage: /extensions ${context.invocation?.name} <extension> [--scope=<user|workspace|session>]`,
});
return null;
}
let scope: SettingScope;
// Transform `--scope=<scope>` to `--scope <scope>`.
if (parts.length === 2) {
parts.push(...parts[1].split('='));
parts.splice(1, 1);
}
switch (parts[2].toLowerCase()) {
case 'workspace':
scope = SettingScope.Workspace;
break;
case 'user':
scope = SettingScope.User;
break;
case 'session':
scope = SettingScope.Session;
break;
default:
context.ui.addItem({
type: MessageType.ERROR,
text: `Unsupported scope ${parts[2]}, should be one of "user", "workspace", or "session"`,
});
debugLogger.error();
return null;
}
let names: string[] = [];
if (name === '--all') {
let extensions = extensionLoader.getExtensions();
if (context.invocation?.name === 'enable') {
extensions = extensions.filter((ext) => !ext.isActive);
}
if (context.invocation?.name === 'disable') {
extensions = extensions.filter((ext) => ext.isActive);
}
names = extensions.map((ext) => ext.name);
} else {
names = [name];
}
return {
extensionManager: extensionLoader,
names,
scope,
};
}
async function disableAction(context: CommandContext, args: string) {
const enableContext = getEnableDisableContext(context, args);
if (!enableContext) return;
const { names, scope, extensionManager } = enableContext;
for (const name of names) {
await extensionManager.disableExtension(name, scope);
context.ui.addItem({
type: MessageType.INFO,
text: `Extension "${name}" disabled for the scope "${scope}"`,
});
}
}
async function enableAction(context: CommandContext, args: string) {
const enableContext = getEnableDisableContext(context, args);
if (!enableContext) return;
const { names, scope, extensionManager } = enableContext;
for (const name of names) {
await extensionManager.enableExtension(name, scope);
context.ui.addItem({
type: MessageType.INFO,
text: `Extension "${name}" enabled for the scope "${scope}"`,
});
// Auto-enable any disabled MCP servers for this extension
const extension = extensionManager
.getExtensions()
.find((e) => e.name === name);
if (extension?.mcpServers) {
const mcpEnablementManager = McpServerEnablementManager.getInstance();
const mcpClientManager =
context.services.agentContext?.config.getMcpClientManager();
const enabledServers = await mcpEnablementManager.autoEnableServers(
Object.keys(extension.mcpServers ?? {}),
);
if (mcpClientManager && enabledServers.length > 0) {
const restartPromises = enabledServers.map((serverName) =>
mcpClientManager.restartServer(serverName).catch((error) => {
context.ui.addItem({
type: MessageType.WARNING,
text: `Failed to restart MCP server '${serverName}': ${getErrorMessage(error)}`,
});
}),
);
await Promise.all(restartPromises);
}
if (enabledServers.length > 0) {
context.ui.addItem({
type: MessageType.INFO,
text: `Re-enabled MCP servers: ${enabledServers.join(', ')}`,
});
}
}
}
}
async function installAction(
context: CommandContext,
args: string,
requestConsentOverride?: (consent: string) => Promise<boolean>,
) {
const extensionLoader =
context.services.agentContext?.config.getExtensionLoader();
if (!(extensionLoader instanceof ExtensionManager)) {
debugLogger.error(
`Cannot ${context.invocation?.name} extensions in this environment`,
);
return;
}
const source = args.trim();
if (!source) {
context.ui.addItem({
type: MessageType.ERROR,
text: `Usage: /extensions install <source>`,
});
return;
}
// Validate that the source is either a valid URL or a valid file path.
let isValid = false;
try {
// Check if it's a valid URL.
new URL(source);
isValid = true;
} catch {
// If not a URL, check for characters that are disallowed in file paths
// and could be used for command injection.
if (!/[;&|`'"]/.test(source)) {
isValid = true;
}
}
if (!isValid) {
context.ui.addItem({
type: MessageType.ERROR,
text: `Invalid source: ${source}`,
});
return;
}
context.ui.addItem({
type: MessageType.INFO,
text: `Installing extension from "${source}"...`,
});
try {
const installMetadata = await inferInstallMetadata(source);
const extension = await extensionLoader.installOrUpdateExtension(
installMetadata,
undefined,
requestConsentOverride,
);
context.ui.addItem({
type: MessageType.INFO,
text: `Extension "${extension.name}" installed successfully.`,
});
} catch (error) {
context.ui.addItem({
type: MessageType.ERROR,
text: `Failed to install extension from "${source}": ${getErrorMessage(
error,
)}`,
});
}
}
async function linkAction(
context: CommandContext,
args: string,
requestConsentOverride?: (consent: string) => Promise<boolean>,
) {
const extensionLoader =
context.services.agentContext?.config.getExtensionLoader();
if (!(extensionLoader instanceof ExtensionManager)) {
debugLogger.error(
`Cannot ${context.invocation?.name} extensions in this environment`,
);
return;
}
const sourceFilepath = args.trim();
if (!sourceFilepath) {
context.ui.addItem({
type: MessageType.ERROR,
text: `Usage: /extensions link <source>`,
});
return;
}
if (/[;&|`'"]/.test(sourceFilepath)) {
context.ui.addItem({
type: MessageType.ERROR,
text: `Source file path contains disallowed characters: ${sourceFilepath}`,
});
return;
}
try {
await stat(sourceFilepath);
} catch (error) {
context.ui.addItem({
type: MessageType.ERROR,
text: `Invalid source: ${sourceFilepath}`,
});
debugLogger.error(
`Failed to stat path "${sourceFilepath}": ${getErrorMessage(error)}`,
);
return;
}
context.ui.addItem({
type: MessageType.INFO,
text: `Linking extension from "${sourceFilepath}"...`,
});
try {
const installMetadata: ExtensionInstallMetadata = {
source: sourceFilepath,
type: 'link',
};
const extension = await extensionLoader.installOrUpdateExtension(
installMetadata,
undefined,
requestConsentOverride,
);
context.ui.addItem({
type: MessageType.INFO,
text: `Extension "${extension.name}" linked successfully.`,
});
} catch (error) {
context.ui.addItem({
type: MessageType.ERROR,
text: `Failed to link extension from "${sourceFilepath}": ${getErrorMessage(
error,
)}`,
});
}
}
async function uninstallAction(context: CommandContext, args: string) {
const extensionLoader =
context.services.agentContext?.config.getExtensionLoader();
if (!(extensionLoader instanceof ExtensionManager)) {
debugLogger.error(
`Cannot ${context.invocation?.name} extensions in this environment`,
);
return;
}
const uninstallArgs = args.split(' ').filter((value) => value.length > 0);
const all = uninstallArgs.includes('--all');
const names = uninstallArgs.filter((a) => !a.startsWith('--'));
if (!all && names.length === 0) {
context.ui.addItem({
type: MessageType.ERROR,
text: `Usage: /extensions uninstall <extension-names...>|--all`,
});
return;
}
let namesToUninstall: string[] = [];
if (all) {
namesToUninstall = extensionLoader.getExtensions().map((ext) => ext.name);
} else {
namesToUninstall = names;
}
if (namesToUninstall.length === 0) {
context.ui.addItem({
type: MessageType.INFO,
text: all ? 'No extensions installed.' : 'No extension name provided.',
});
return;
}
for (const extensionName of namesToUninstall) {
context.ui.addItem({
type: MessageType.INFO,
text: `Uninstalling extension "${extensionName}"...`,
});
try {
await extensionLoader.uninstallExtension(extensionName, false);
context.ui.addItem({
type: MessageType.INFO,
text: `Extension "${extensionName}" uninstalled successfully.`,
});
} catch (error) {
context.ui.addItem({
type: MessageType.ERROR,
text: `Failed to uninstall extension "${extensionName}": ${getErrorMessage(
error,
)}`,
});
}
}
}
async function configAction(context: CommandContext, args: string) {
const parts = args.trim().split(/\s+/).filter(Boolean);
let scope = ExtensionSettingScope.USER;
const scopeEqIndex = parts.findIndex((p) => p.startsWith('--scope='));
if (scopeEqIndex > -1) {
const scopeVal = parts[scopeEqIndex].split('=')[1];
if (scopeVal === 'workspace') {
scope = ExtensionSettingScope.WORKSPACE;
} else if (scopeVal === 'user') {
scope = ExtensionSettingScope.USER;
}
parts.splice(scopeEqIndex, 1);
} else {
const scopeIndex = parts.indexOf('--scope');
if (scopeIndex > -1) {
const scopeVal = parts[scopeIndex + 1];
if (scopeVal === 'workspace' || scopeVal === 'user') {
scope =
scopeVal === 'workspace'
? ExtensionSettingScope.WORKSPACE
: ExtensionSettingScope.USER;
parts.splice(scopeIndex, 2);
}
}
}
const otherArgs = parts;
const name = otherArgs[0];
const setting = otherArgs[1];
if (name) {
if (name.includes('/') || name.includes('\\') || name.includes('..')) {
context.ui.addItem({
type: MessageType.ERROR,
text: 'Invalid extension name. Names cannot contain path separators or "..".',
});
return;
}
}
const extensionManager =
context.services.agentContext?.config.getExtensionLoader();
if (!(extensionManager instanceof ExtensionManager)) {
debugLogger.error(
`Cannot ${context.invocation?.name} extensions in this environment`,
);
return;
}
const logger: ConfigLogger = {
log: (message: string) => {
context.ui.addItem({ type: MessageType.INFO, text: message.trim() });
},
error: (message: string) =>
context.ui.addItem({ type: MessageType.ERROR, text: message }),
};
return {
type: 'custom_dialog' as const,
component: React.createElement(ConfigExtensionDialog, {
extensionManager,
onClose: () => context.ui.removeComponent(),
extensionName: name,
settingKey: setting,
scope,
configureAll: !name && !setting,
loggerAdapter: logger,
}),
};
}
/**
* Exported for testing.
*/
export function completeExtensions(
context: CommandContext,
partialArg: string,
) {
let extensions = context.services.agentContext?.config.getExtensions() ?? [];
if (context.invocation?.name === 'enable') {
extensions = extensions.filter((ext) => !ext.isActive);
}
if (
context.invocation?.name === 'disable' ||
context.invocation?.name === 'restart' ||
context.invocation?.name === 'reload'
) {
extensions = extensions.filter((ext) => ext.isActive);
}
const extensionNames = extensions.map((ext) => ext.name);
const suggestions = extensionNames.filter((name) =>
name.startsWith(partialArg),
);
if ('--all'.startsWith(partialArg) || 'all'.startsWith(partialArg)) {
suggestions.unshift('--all');
}
return suggestions;
}
export function completeExtensionsAndScopes(
context: CommandContext,
partialArg: string,
) {
return completeExtensions(context, partialArg).flatMap((s) => [
`${s} --scope user`,
`${s} --scope workspace`,
`${s} --scope session`,
]);
}
const listExtensionsCommand: SlashCommand = {
name: 'list',
description: 'List active extensions',
kind: CommandKind.BUILT_IN,
autoExecute: true,
takesArgs: false,
action: listAction,
};
const updateExtensionsCommand: SlashCommand = {
name: 'update',
description: 'Update extensions. Usage: update <extension-names>|--all',
kind: CommandKind.BUILT_IN,
autoExecute: false,
action: updateAction,
completion: completeExtensions,
};
const disableCommand: SlashCommand = {
name: 'disable',
description: 'Disable an extension',
kind: CommandKind.BUILT_IN,
autoExecute: false,
action: disableAction,
completion: completeExtensionsAndScopes,
};
const enableCommand: SlashCommand = {
name: 'enable',
description: 'Enable an extension',
kind: CommandKind.BUILT_IN,
autoExecute: false,
action: enableAction,
completion: completeExtensionsAndScopes,
};
const installCommand: SlashCommand = {
name: 'install',
description: 'Install an extension from a git repo or local path',
kind: CommandKind.BUILT_IN,
autoExecute: false,
action: installAction,
};
const linkCommand: SlashCommand = {
name: 'link',
description: 'Link an extension from a local path',
kind: CommandKind.BUILT_IN,
autoExecute: false,
action: linkAction,
};
const uninstallCommand: SlashCommand = {
name: 'uninstall',
altNames: ['delete'],
description: 'Uninstall an extension',
kind: CommandKind.BUILT_IN,
autoExecute: false,
action: uninstallAction,
completion: completeExtensions,
};
const exploreExtensionsCommand: SlashCommand = {
name: 'explore',
description: 'Open extensions page in your browser',
kind: CommandKind.BUILT_IN,
autoExecute: true,
takesArgs: false,
action: exploreAction,
};
const reloadCommand: SlashCommand = {
name: 'reload',
altNames: ['restart'],
description: 'Reload all extensions',
kind: CommandKind.BUILT_IN,
autoExecute: false,
action: restartAction,
completion: completeExtensions,
};
const configCommand: SlashCommand = {
name: 'config',
description: 'Configure extension settings',
kind: CommandKind.BUILT_IN,
autoExecute: false,
action: configAction,
};
import { parseSlashCommand } from '../../utils/commands.js';
export function extensionsCommand(
enableExtensionReloading?: boolean,
): SlashCommand {
const conditionalCommands = enableExtensionReloading
? [
disableCommand,
enableCommand,
installCommand,
uninstallCommand,
linkCommand,
configCommand,
]
: [];
const subCommands = [
listExtensionsCommand,
updateExtensionsCommand,
exploreExtensionsCommand,
reloadCommand,
...conditionalCommands,
];
return {
name: 'extensions',
description: 'Manage extensions',
kind: CommandKind.BUILT_IN,
autoExecute: false,
subCommands,
action: async (context, args) => {
if (args) {
const parsed = parseSlashCommand(`/${args}`, subCommands);
if (parsed.commandToExecute?.action) {
return parsed.commandToExecute.action(context, parsed.args);
}
}
// Default to list if no subcommand is provided
return listExtensionsCommand.action!(context, args);
},
};
}
|