CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes45downloads
userStartupWarnings.ts76 linesDownload Raw Back to utils
1/**2 * @license3 * Copyright 2025 Google LLC4 * SPDX-License-Identifier: Apache-2.05 */6 7import fs from 'node:fs/promises';8import path from 'node:path';9import { canUseRipgrep } from '@qwen-code/qwen-code-core';10 11type WarningCheckOptions = {12  workspaceRoot: string;13  useRipgrep: boolean;14  useBuiltinRipgrep: boolean;15};16 17type WarningCheck = {18  id: string;19  check: (options: WarningCheckOptions) => Promise<string | null>;20};21 22// Individual warning checks23const rootDirectoryCheck: WarningCheck = {24  id: 'root-directory',25  check: async (options: WarningCheckOptions) => {26    try {27      const workspaceRealPath = await fs.realpath(options.workspaceRoot);28      const errorMessage =29        'Warning: You are running Qwen Code in the root directory. Your entire folder structure will be used for context. It is strongly recommended to run in a project-specific directory.';30 31      // Check for Unix root directory32      if (path.dirname(workspaceRealPath) === workspaceRealPath) {33        return errorMessage;34      }35 36      return null;37    } catch (_err: unknown) {38      return 'Could not verify the current directory due to a file system error.';39    }40  },41};42 43const ripgrepAvailabilityCheck: WarningCheck = {44  id: 'ripgrep-availability',45  check: async (options: WarningCheckOptions) => {46    if (!options.useRipgrep) {47      return null;48    }49 50    try {51      const isAvailable = await canUseRipgrep(options.useBuiltinRipgrep);52      if (!isAvailable) {53        return 'Ripgrep not available: Please install ripgrep globally to enable faster file content search. Falling back to built-in grep.';54      }55      return null;56    } catch (error) {57      return `Ripgrep not available: ${error instanceof Error ? error.message : 'Unknown error'}. Falling back to built-in grep.`;58    }59  },60};61 62// All warning checks63const WARNING_CHECKS: readonly WarningCheck[] = [64  rootDirectoryCheck,65  ripgrepAvailabilityCheck,66];67 68export async function getUserStartupWarnings(69  options: WarningCheckOptions,70): Promise<string[]> {71  const results = await Promise.all(72    WARNING_CHECKS.map((check) => check.check(options)),73  );74  return results.filter((msg) => msg !== null);75}76 
basant307/AI_Governance_Project · CoolFace