CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes45downloads
BuiltinCommandLoader.ts188 linesDownload Raw Back to services
1/**2 * @license3 * Copyright 2025 Google LLC4 * SPDX-License-Identifier: Apache-2.05 */6 7import type { ICommandLoader } from './types.js';8import type { SlashCommand } from '../ui/commands/types.js';9import type { Config } from '@qwen-code/qwen-code-core';10import { aboutCommand } from '../ui/commands/aboutCommand.js';11import { tasksCommand } from '../ui/commands/tasksCommand.js';12import { workflowsCommand } from '../ui/commands/workflowsCommand.js';13import { agentsCommand } from '../ui/commands/agentsCommand.js';14import { arenaCommand } from '../ui/commands/arenaCommand.js';15import { approvalModeCommand } from '../ui/commands/approvalModeCommand.js';16import { authCommand } from '../ui/commands/authCommand.js';17import { branchCommand } from '../ui/commands/branchCommand.js';18import { btwCommand } from '../ui/commands/btwCommand.js';19import { bugCommand } from '../ui/commands/bugCommand.js';20import { cdCommand } from '../ui/commands/cdCommand.js';21import { clearCommand } from '../ui/commands/clearCommand.js';22import { configCommand } from '../ui/commands/config-command.js';23import { deleteCommand } from '../ui/commands/deleteCommand.js';24import { compressCommand } from '../ui/commands/compressCommand.js';25import { compressFastCommand } from '../ui/commands/compressFastCommand.js';26import { contextCommand } from '../ui/commands/contextCommand.js';27import { copyCommand } from '../ui/commands/copyCommand.js';28import { docsCommand } from '../ui/commands/docsCommand.js';29import { doctorCommand } from '../ui/commands/doctorCommand.js';30import { diffCommand } from '../ui/commands/diffCommand.js';31import { directoryCommand } from '../ui/commands/directoryCommand.js';32import { editorCommand } from '../ui/commands/editorCommand.js';33import { effortCommand } from '../ui/commands/effort-command.js';34import { exportCommand } from '../ui/commands/exportCommand.js';35import { forkCommand } from '../ui/commands/forkCommand.js';36import { extensionsCommand } from '../ui/commands/extensionsCommand.js';37import { goalCommand } from '../ui/commands/goalCommand.js';38import { helpCommand } from '../ui/commands/helpCommand.js';39import { historyCommand } from '../ui/commands/historyCommand.js';40import { hooksCommand } from '../ui/commands/hooksCommand.js';41import { ideCommand } from '../ui/commands/ideCommand.js';42import { importConfigCommand } from '../ui/commands/importConfigCommand.js';43import { createDebugLogger } from '@qwen-code/qwen-code-core';44import { initCommand } from '../ui/commands/initCommand.js';45import { languageCommand } from '../ui/commands/languageCommand.js';46import { mcpCommand } from '../ui/commands/mcpCommand.js';47import { dreamCommand } from '../ui/commands/dreamCommand.js';48import { forgetCommand } from '../ui/commands/forgetCommand.js';49import { memoryCommand } from '../ui/commands/memoryCommand.js';50import { modelCommand } from '../ui/commands/modelCommand.js';51import { rememberCommand } from '../ui/commands/rememberCommand.js';52import { planCommand } from '../ui/commands/planCommand.js';53import { permissionsCommand } from '../ui/commands/permissionsCommand.js';54import { trustCommand } from '../ui/commands/trustCommand.js';55import { quitCommand } from '../ui/commands/quitCommand.js';56import { recapCommand } from '../ui/commands/recapCommand.js';57import { renameCommand } from '../ui/commands/renameCommand.js';58import { restoreCommand } from '../ui/commands/restoreCommand.js';59import { resumeCommand } from '../ui/commands/resumeCommand.js';60import { rewindCommand } from '../ui/commands/rewindCommand.js';61import { settingsCommand } from '../ui/commands/settingsCommand.js';62import { skillsCommand } from '../ui/commands/skillsCommand.js';63import { statsCommand } from '../ui/commands/statsCommand.js';64import { summaryCommand } from '../ui/commands/summaryCommand.js';65import { terminalSetupCommand } from '../ui/commands/terminalSetupCommand.js';66import { themeCommand } from '../ui/commands/themeCommand.js';67import { toolsCommand } from '../ui/commands/toolsCommand.js';68import { vimCommand } from '../ui/commands/vimCommand.js';69import { voiceCommand } from '../ui/commands/voice-command.js';70import { setupGithubCommand } from '../ui/commands/setupGithubCommand.js';71import { insightCommand } from '../ui/commands/insightCommand.js';72import { statuslineCommand } from '../ui/commands/statuslineCommand.js';73import { lspCommand } from '../ui/commands/lspCommand.js';74 75const builtinDebugLogger = createDebugLogger('BUILTIN_COMMAND_LOADER');76 77/**78 * Loads the core, hard-coded slash commands that are an integral part79 * of the Qwen Code application.80 */81export class BuiltinCommandLoader implements ICommandLoader {82  constructor(private config: Config | null) {}83 84  /**85   * Gathers all raw built-in command definitions, injects dependencies where86   * needed (e.g., config) and filters out any that are not available.87   *88   * @param _signal An AbortSignal (unused for this synchronous loader).89   * @returns A promise that resolves to an array of `SlashCommand` objects.90   */91  async loadCommands(_signal: AbortSignal): Promise<SlashCommand[]> {92    // Load ideCommand separately with error handling so that a failure93    // (e.g., platform-specific process detection on Windows) does not94    // prevent ALL built-in commands from loading.95    let resolvedIdeCommand: SlashCommand | null = null;96    try {97      resolvedIdeCommand = await ideCommand();98    } catch (error) {99      builtinDebugLogger.warn(100        'Failed to load IDE command:',101        error instanceof Error ? error.message : String(error),102      );103    }104 105    const allDefinitions: Array<SlashCommand | null> = [106      aboutCommand,107      agentsCommand,108      tasksCommand,109      // Gated behind isWorkflowsEnabled — feature flag honors110      // QWEN_CODE_ENABLE_WORKFLOWS (opt-in) and QWEN_CODE_DISABLE_WORKFLOWS111      // (kill switch). When the flag is off the command vanishes entirely112      // from typeahead and help, matching the established convention for113      // experimental builtins.114      this.config?.isWorkflowsEnabled() ? workflowsCommand : null,115      arenaCommand,116      approvalModeCommand,117      authCommand,118      branchCommand,119      btwCommand,120      forkCommand,121      bugCommand,122      cdCommand,123      clearCommand,124      compressCommand,125      compressFastCommand,126      configCommand,127      contextCommand,128      copyCommand,129      diffCommand,130      deleteCommand,131      docsCommand,132      doctorCommand,133      directoryCommand,134      editorCommand,135      effortCommand,136      exportCommand,137      extensionsCommand,138      helpCommand,139      historyCommand,140      hooksCommand,141      resolvedIdeCommand,142      importConfigCommand,143      initCommand,144      languageCommand,145      mcpCommand,146      ...(this.config?.isManagedMemoryAvailable()147        ? [dreamCommand, forgetCommand]148        : []),149      goalCommand,150      memoryCommand,151      modelCommand,152      rememberCommand,153      planCommand,154      permissionsCommand,155      ...(this.config?.getFolderTrust() ? [trustCommand] : []),156      quitCommand,157      recapCommand,158      renameCommand,159      restoreCommand(this.config),160      resumeCommand,161      rewindCommand,162      skillsCommand,163      statsCommand,164      summaryCommand,165      themeCommand,166      toolsCommand,167      settingsCommand,168      vimCommand,169      voiceCommand,170      setupGithubCommand,171      terminalSetupCommand,172      insightCommand,173      statuslineCommand,174      ...(this.config?.isLspEnabled() ? [lspCommand] : []),175    ];176 177    return allDefinitions178      .filter((cmd): cmd is SlashCommand => cmd !== null)179      .map((cmd) => ({180        ...cmd,181        source: 'builtin-command' as const,182        sourceLabel: 'Built-in',183        modelInvocable: false,184        userInvocable: cmd.userInvocable ?? true,185      }));186  }187}188 
basant307/AI_Governance_Project · CoolFace