Advertisement

← vibesdk

worker/agents/domain/values/IssueReport.ts

2.8 KB Download file
import { RuntimeError, StaticAnalysisResponse } from '../../../services/sandbox/sandboxTypes';
import { AllIssues } from '../../core/types';

/**
 * Immutable report of issues found during code generation
 * Includes runtime errors, static analysis results, and client errors
 */
export class IssueReport {
    constructor(
        public readonly runtimeErrors: RuntimeError[],
        public readonly staticAnalysis: StaticAnalysisResponse,
    ) {
        // Freeze to ensure immutability
        Object.freeze(this);
        Object.freeze(this.runtimeErrors);
        Object.freeze(this.staticAnalysis);
    }

    /**
     * Create report from all issues
     */
    static from(issues: AllIssues): IssueReport {
        return new IssueReport(
            issues.runtimeErrors || [],
            issues.staticAnalysis || { success: false, lint: { issues: [] }, typecheck: { issues: [] } },
        );
    }

    /**
     * Check if there are any issues
     */
    hasIssues(): boolean {
        return this.hasRuntimeErrors() || this.hasStaticAnalysisIssues();
    }

    /**
     * Check if there are runtime errors
     */
    hasRuntimeErrors(): boolean {
        return this.runtimeErrors.length > 0;
    }

    /**
     * Check if there are static analysis issues
     */
    hasStaticAnalysisIssues(): boolean {
        const lintIssues = this.staticAnalysis.lint?.issues?.length || 0;
        const typecheckIssues = this.staticAnalysis.typecheck?.issues?.length || 0;
        return lintIssues > 0 || typecheckIssues > 0;
    }

    /**
     * Get total issue count
     */
    getTotalIssueCount(): number {
        const runtimeCount = this.runtimeErrors.length;
        const lintCount = this.staticAnalysis.lint?.issues?.length || 0;
        const typecheckCount = this.staticAnalysis.typecheck?.issues?.length || 0;
        
        return runtimeCount + lintCount + typecheckCount;
    }

    /**
     * Get a summary of all issues
     */
    getSummary(): string {
        const parts: string[] = [];
        
        if (this.runtimeErrors.length > 0) {
            parts.push(`${this.runtimeErrors.length} runtime errors`);
        }
        
        const lintCount = this.staticAnalysis.lint?.issues?.length || 0;
        if (lintCount > 0) {
            parts.push(`${lintCount} lint issues`);
        }
        
        const typecheckCount = this.staticAnalysis.typecheck?.issues?.length || 0;
        if (typecheckCount > 0) {
            parts.push(`${typecheckCount} type errors`);
        }
        
        return parts.length > 0 ? parts.join(', ') : 'No issues found';
    }

    /**
     * Create an empty issue report
     */
    static empty(): IssueReport {
        return new IssueReport(
            [],
            { success: true, lint: { issues: [] }, typecheck: { issues: [] } },
        );
    }
}