UNPKG

agentsqripts

Version:

Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems

272 lines (232 loc) 12.7 kB
/** * @file Central configuration constants - Single source of truth for all hardcoded values * @description Single responsibility: Define ALL constants and environment variables used across AgentSqripts * * ATTENTION DEVELOPERS: This file stores all hardcoded constants in the app so we have a single source * of truth for variable names, and LLMs cannot mutate variable names. New values may be added, but * existing values must not be modified, deleted, or moved. Values are grouped by category when first * introduced. Group them under an existing category if one exists, or start a new section (with a * comment header) if it's a new category. Do not move or re-categorize existing values. Ensure that * no duplicates or slight variations of existing values are added. All environment variables are * defined here (example: const envVar = process.env.ENV_VAR) and exported for use from here on the * same line using the export keyword. No where else in the codebase should cite and use environment * variables directly but should import them from here. Don't move or re-categorize existing values. * If a variable/value is a duplicate or unused you may not delete it but may flag it with a comment "REMOVE?". * Remember in all this, never edit a constant once it resides in localVars.js; never create a section * whose header already exists. * * When importing these variables into other files that use them, import the entire object and not just * the variable needed (What I mean is import as: const localVars = require('../config/localVars'); * and use as localVars.variable in context that use a variable. DO NOT import as: * const { variable } = require('../config/localVars'); as this becomes a huge and messy list.); * this avoids merge conflicts that are huge and confusing to analyze the many imported variables from localVars.js. */ // ═══════════════════════════════════════════════════════════════════════ // ENVIRONMENT VARIABLES // ═══════════════════════════════════════════════════════════════════════ const NODE_ENV = process.env.NODE_ENV; // ═══════════════════════════════════════════════════════════════════════ // ERROR HANDLING CONSTANTS // ═══════════════════════════════════════════════════════════════════════ const DEFAULT_ERROR_MESSAGE = 'An unexpected error occurred'; const ERROR_CONTEXT_FORMATSTRING = 'formatString function'; // ═══════════════════════════════════════════════════════════════════════ // TESTING CONSTANTS // ═══════════════════════════════════════════════════════════════════════ const TEST_SUCCESS_MESSAGE = '✓'; const TEST_FAILURE_MESSAGE = '✗'; // ═══════════════════════════════════════════════════════════════════════ // FILE EXTENSIONS AND PATTERNS // ═══════════════════════════════════════════════════════════════════════ const DEFAULT_INDEX_FILES = ['index.ts', 'index.js']; const DEFAULT_TARGET_DIRS = ['src/utils', 'src/helpers', 'src/shared', 'lib', 'utils', 'helpers', 'src/lib', 'app/utils', 'app/lib']; const FRONTEND_EXTENSIONS = ['.js', '.jsx', '.ts', '.tsx', '.vue', '.svelte']; const BACKEND_EXTENSIONS = ['.js', '.ts', '.py', '.php', '.rb', '.go', '.java']; const VALID_EXTENSIONS = ['.js', '.ts', '.jsx', '.tsx', '.py', '.java', '.cs', '.php']; const DEFAULT_EXTENSIONS = ['.js', '.ts', '.jsx', '.tsx']; const DEFAULT_CONFIG = { extensions: DEFAULT_EXTENSIONS, excludePatterns: ['node_modules', '.git', 'dist', 'build'], includeTests: false }; // ═══════════════════════════════════════════════════════════════════════ // PATTERN MATCHING CONSTANTS // ═══════════════════════════════════════════════════════════════════════ const PATTERNS = { SQL_INJECTION: /\b(SELECT|INSERT|UPDATE|DELETE|DROP|CREATE|ALTER)\b.*\+.*\+/gi, XSS_PATTERNS: /(innerHTML|outerHTML|document\.write)\s*[\+=]\s*[^;]+/gi, EVAL_USAGE: /\beval\s*\(/gi, EXEC_USAGE: /\bexec\s*\(/gi }; // ═══════════════════════════════════════════════════════════════════════ // SRP ANALYSIS KEYWORDS // ═══════════════════════════════════════════════════════════════════════ const DEFAULT_KEYWORD_CLUSTERS = { authentication: ['auth', 'login', 'password', 'token', 'session', 'user', 'credential'], database: ['db', 'sql', 'query', 'table', 'record', 'model', 'schema'], validation: ['validate', 'check', 'verify', 'sanitize', 'filter', 'clean'], fileOperations: ['file', 'read', 'write', 'path', 'directory', 'folder'], networking: ['http', 'request', 'response', 'api', 'endpoint', 'url'], ui: ['render', 'display', 'view', 'component', 'element', 'dom'], logging: ['log', 'debug', 'error', 'warn', 'info', 'trace'], configuration: ['config', 'setting', 'option', 'parameter', 'env'] }; // ═══════════════════════════════════════════════════════════════════════ // WET CODE ANALYSIS CONFIG // ═══════════════════════════════════════════════════════════════════════ const WET_CODE_CONFIG = { minSimilarityThreshold: 0.8, minLineCount: 5, excludePatterns: ['test', 'spec', '__tests__'], includeComments: false }; const WET_PATTERNS = { 'exact_duplicate': { effort: 1, impact: '90-100% code reduction for duplicated sections', severity: 'HIGH', category: 'Exact Match' }, 'similar_logic': { effort: 2, impact: '60-80% code reduction with parameterization', severity: 'MEDIUM', category: 'Similar Logic' }, 'repeated_pattern': { effort: 2, impact: '50-70% reduction through abstraction', severity: 'MEDIUM', category: 'Pattern' }, 'copy_paste': { effort: 1, impact: '70-90% reduction through consolidation', severity: 'HIGH', category: 'Copy-Paste' }, 'boilerplate': { effort: 3, impact: '40-60% reduction through templating', severity: 'MEDIUM', category: 'Boilerplate' } }; // ═══════════════════════════════════════════════════════════════════════ // UI PROBLEM ANALYSIS CONFIG // ═══════════════════════════════════════════════════════════════════════ const UI_CONFIG = { accessibilityCheck: true, performanceAnalysis: true, responsiveDesign: true, semanticHtml: true }; const UI_PROBLEM_PATTERNS = { MISSING_ALT: /<img(?![^>]*alt=)/gi, INLINE_STYLES: /style\s*=\s*["'][^"']*["']/gi, DEPRECATED_TAGS: /<(font|center|big|small|strike|tt)\b/gi, ACCESSIBILITY_ISSUES: /onclick\s*=(?![^>]*role=)/gi }; // ═══════════════════════════════════════════════════════════════════════ // BUG DETECTION CONFIG // ═══════════════════════════════════════════════════════════════════════ const BUG_CONFIG = { strictMode: true, checkAsyncAwait: true, validateVariables: true, checkNullUndefined: true }; const BUG_PATTERNS = { NULL_UNDEFINED: /\b(null|undefined)\b/g, ASYNC_WITHOUT_AWAIT: /async\s+function[^{]*\{(?![^}]*await)/g, CONSOLE_LOG: /console\.(log|error|warn|info)/g, EVAL_DANGEROUS: /\beval\s*\(/g }; // ═══════════════════════════════════════════════════════════════════════ // SECURITY PATTERNS // ═══════════════════════════════════════════════════════════════════════ const COMMON_PATTERNS = { SQL_INJECTION: { pattern: /\b(SELECT|INSERT|UPDATE|DELETE|DROP|CREATE|ALTER)\b.*[\+\$\{]/gi, severity: 'HIGH', cwe: 'CWE-89' }, XSS: { pattern: /(innerHTML|outerHTML|document\.write)\s*[\+=]/gi, severity: 'HIGH', cwe: 'CWE-79' } }; const JAVASCRIPT_PATTERNS = { EVAL_USAGE: { pattern: /\beval\s*\(/gi, severity: 'HIGH', cwe: 'CWE-95' }, PROTOTYPE_POLLUTION: { pattern: /__proto__|constructor\.prototype/gi, severity: 'MEDIUM', cwe: 'CWE-1321' } }; const PYTHON_PATTERNS = { COMMAND_INJECTION: { pattern: /os\.(system|popen|exec)/gi, severity: 'HIGH', cwe: 'CWE-78' } }; // ═══════════════════════════════════════════════════════════════════════ // INTEGRATION PATTERNS // ═══════════════════════════════════════════════════════════════════════ const INTEGRATION_PATTERNS = { API_ENDPOINT_MISMATCH: /fetch\(['"]([^'"]+)['"]\)/g, MISSING_ERROR_HANDLING: /fetch\([^)]+\)(?!\s*\.catch)/g, CORS_ISSUES: /Access-Control-Allow-Origin/gi, AUTH_TOKEN_EXPOSURE: /(api[_-]?key|token|auth)['"]\s*:\s*['"][^'"]*['"]/gi }; // ═══════════════════════════════════════════════════════════════════════ // PERFORMANCE PATTERNS // ═══════════════════════════════════════════════════════════════════════ const PERFORMANCE_PATTERNS = { NESTED_LOOPS: /for\s*\([^}]*\{[^}]*for\s*\(/g, SYNC_IN_ASYNC: /fs\.readFileSync|fs\.writeFileSync/g, DOM_QUERIES_LOOP: /for\s*\([^}]*document\.querySelector/g, INEFFICIENT_REGEX: /\/.*\*.*\+.*\//g }; module.exports = { // Environment NODE_ENV, // Error Handling DEFAULT_ERROR_MESSAGE, ERROR_CONTEXT_FORMATSTRING, // Testing TEST_SUCCESS_MESSAGE, TEST_FAILURE_MESSAGE, // File Extensions DEFAULT_INDEX_FILES, DEFAULT_TARGET_DIRS, FRONTEND_EXTENSIONS, BACKEND_EXTENSIONS, VALID_EXTENSIONS, DEFAULT_EXTENSIONS, DEFAULT_CONFIG, // Patterns PATTERNS, // Analysis Configs WET_CODE_CONFIG, UI_CONFIG, BUG_CONFIG, // SRP Keywords DEFAULT_KEYWORD_CLUSTERS, // Security Patterns COMMON_PATTERNS, JAVASCRIPT_PATTERNS, PYTHON_PATTERNS, // Other Patterns WET_PATTERNS, BUG_PATTERNS, INTEGRATION_PATTERNS, PERFORMANCE_PATTERNS, UI_PROBLEM_PATTERNS };