ctrlshiftleft
Version:
AI-powered toolkit for embedding QA and security testing into development workflows
199 lines (198 loc) • 6.15 kB
TypeScript
/**
* Enhanced File Watcher for ctrl.shift.left
*
* This module provides advanced file watching capabilities with AI-powered security analysis,
* designed to integrate with developer workflows, including Cursor AI and other code generation tools.
*/
import { EventEmitter } from 'events';
/**
* Options for the enhanced watcher
*/
export interface EnhancedWatcherOptions {
/** Glob patterns to include */
include?: string[];
/** Glob patterns to exclude */
exclude?: string[];
/** Debounce delay in milliseconds */
debounceMs?: number;
/** Whether to generate tests on file changes */
generateTests?: boolean;
/** Whether to analyze security on file changes */
analyzeSecurity?: boolean;
/** Whether to use AI-enhanced security analysis */
useAIAnalysis?: boolean;
/** Whether to generate checklists on file changes */
generateChecklists?: boolean;
/** Output directory for generated tests */
testOutputDir?: string;
/** Output directory for security reports */
securityOutputDir?: string;
/** Output directory for checklists */
checklistOutputDir?: string;
/** Test format (playwright or selenium) */
testFormat?: 'playwright' | 'selenium';
/** Browser to use for running tests */
browser?: string;
/** Whether to run browser in headless mode */
headless?: boolean;
/** OpenAI API key for AI-enhanced security analysis */
openAIApiKey?: string;
/** Minimum file size change (in bytes) to trigger analysis */
minFileSizeChange?: number;
/** Maximum concurrent tasks */
maxConcurrentTasks?: number;
/** Whether to report progress in real-time */
reportProgress?: boolean;
/** Specific file types to generate tests for */
testableFileTypes?: string[];
/** Specific file types to analyze for security */
securityFileTypes?: string[];
}
/**
* File change event details
*/
export interface FileChangeEvent {
/** Type of event (add, change, unlink) */
type: 'add' | 'change' | 'unlink';
/** Path to the file that changed */
path: string;
/** Timestamp of the event */
timestamp: number;
}
/**
* Analysis result
*/
export interface AnalysisResult {
/** Path to the analyzed file */
filePath: string;
/** Whether the analysis was successful */
success: boolean;
/** Type of analysis performed */
type: 'test' | 'security' | 'checklist';
/** Output file path (if applicable) */
outputPath?: string;
/** Error message (if applicable) */
error?: string;
/** Analysis duration in milliseconds */
duration: number;
/** Timestamp when the analysis was completed */
timestamp: number;
}
/**
* Enhanced file watcher for real-time QA and security feedback
* Designed to work alongside IDE extensions and tools like Cursor AI
*/
export declare class EnhancedWatcher extends EventEmitter {
private options;
private watcher;
private testGenerator;
private testRunner;
private checklistGenerator;
private processingFiles;
private fileContents;
private taskQueue;
private isProcessingQueue;
private activeTasks;
private stopping;
/**
* Create a new enhanced watcher
* @param options Watcher options
*/
constructor(options?: EnhancedWatcherOptions);
/**
* Check if AI-enhanced security analysis is available
* @returns Boolean indicating if AI analysis is available
*/
isAIAvailable(): boolean;
/**
* Start watching files
* @param directoryPath Path to the directory to watch
* @returns Function to stop watching
*/
watch(directoryPath: string): () => void;
/**
* Stop watching files
*/
stop(): Promise<void>;
/**
* Manually analyze a file
* @param filePath Path to the file to analyze
* @param analysisTypes Types of analysis to perform
*/
analyzeFile(filePath: string, analysisTypes?: {
generateTests?: boolean;
analyzeSecurity?: boolean;
useAI?: boolean;
generateChecklists?: boolean;
}): Promise<AnalysisResult[]>;
/**
* Handle file change events
* @param eventType Type of event (add, change, unlink)
* @param filePath Path to the changed file
*/
private handleFileChange;
/**
* Add a task to the queue for a file
* @param file File path
* @param task Task function
*/
private addToTaskQueue;
/**
* Process tasks in the queue
*/
private processTaskQueue;
/**
* Generate tests for a file
* @param filePath Path to the file
* @returns Analysis result
*/
private generateTestsForFile;
/**
* Analyze security of a file
* @param filePath Path to the file
* @param useAI Whether to use AI-enhanced analysis
* @returns Analysis result
*/
private analyzeFileSecurity;
/**
* Generate checklist for a file
* @param filePath Path to the file
* @returns Analysis result
*/
private generateChecklistForFile;
/**
* Check if file content has changed significantly
* @param filePath Path to the file
* @returns Whether the content has changed significantly
*/
private hasContentChangedSignificantly;
/**
* Check if a file should be processed
* @param filePath Path to the file
* @param eventType Type of event
* @returns Whether the file should be processed
*/
private shouldProcessFile;
/**
* Check if a file is testable
* @param filePath Path to the file
* @returns Whether the file is testable
*/
private isTestableFile;
/**
* Check if a file can be analyzed for security
* @param filePath Path to the file
* @returns Whether the file can be analyzed for security
*/
private isSecurityAnalyzableFile;
/**
* Ensure all output directories exist
*/
private ensureOutputDirectories;
/**
* Log watcher configuration
* @param watchPath Path being watched
*/
private logConfiguration;
}
export default EnhancedWatcher;