/** * Abstract base class for output strategies. * Enforces consistent interface, validation, execution tracing, and error handling. */ import type { RenderOptions } from "../output-strategy.js"; import { ExecutionTrace } from "./execution-trace.js"; import type { StrategyResult, ValidationError, ValidationResult } from "./types.js"; /** * Configuration for BaseStrategy behavior. */ export interface StrategyConfig { /** Enable execution tracing (default: true) */ enableTrace?: boolean; /** Fail fast on first validation error (default: false) */ failFast?: boolean; /** Maximum execution time in ms (default: 30000) */ timeoutMs?: number; /** Enable verbose logging (default: false) */ verbose?: boolean; } /** * Abstract base class for all output strategies. * * Enforces a consistent interface across all strategy implementations: * - Input validation via `validate()` * - Core logic via `execute()` * - Template method pattern via `run()` * - Execution tracing via `ExecutionTrace` * * All 7 strategies (SpecKit, TOGAF, ADR, RFC, Enterprise, SDD, Chat) * MUST extend this class. * * @typeParam TInput - Strategy input type (e.g., SessionState) * @typeParam TOutput - Strategy output type (e.g., OutputArtifacts) * * @example * ```typescript * class SpecKitStrategy extends BaseStrategy { * validate(input: SessionState): ValidationResult { * // Validate session state * } * * async execute(input: SessionState): Promise { * // Generate SpecKit documents * } * } * ``` */ export declare abstract class BaseStrategy { /** Execution trace for this strategy invocation */ protected trace: ExecutionTrace; /** Configuration for this strategy */ protected readonly config: Required; /** Strategy name for logging */ protected abstract readonly name: string; /** Strategy version */ protected abstract readonly version: string; constructor(config?: StrategyConfig); /** * Validate the input before execution. * * MUST be implemented by subclasses to perform input validation. * Called automatically by `run()` before `execute()`. * * @param input - Strategy input to validate * @returns Validation result with errors and warnings */ abstract validate(input: TInput): ValidationResult; /** * Check if this strategy supports rendering a specific domain type. * * MUST be implemented by subclasses to indicate which domain types * this strategy can render. * * @param domainType - The domain type identifier (e.g., "SessionState") * @returns True if this strategy can render the domain type */ abstract supports(domainType: string): boolean; /** * Execute the strategy's core logic. * * MUST be implemented by subclasses to perform the main work. * Only called if `validate()` passes. * * @param input - Validated strategy input * @returns Strategy output * @throws Error if execution fails */ abstract execute(input: TInput, options?: Partial): Promise; /** * Run the strategy with validation and tracing. * * This is the main entry point for strategy execution. * Implements the Template Method pattern: * 1. Record start * 2. Validate input * 3. Execute if valid * 4. Record result * * @param input - Strategy input * @returns Strategy result with output or errors */ run(input: TInput, options?: Partial): Promise>; /** * Validate input with tracing. */ private validateWithTrace; /** * Execute with timeout protection. */ private executeWithTimeout; /** * Build error result for validation failures. */ private buildErrorResult; /** * Handle execution errors. */ private handleExecutionError; /** * Normalize validation results based on configuration. */ private normalizeValidationResult; /** * Get input keys for logging (avoids logging full input). */ private getInputKeys; private getInputType; } /** * Type guard for StrategyResult success. */ export declare function isSuccessResult(result: StrategyResult): result is StrategyResult & { success: true; data: T; }; /** * Type guard for StrategyResult failure. */ export declare function isErrorResult(result: StrategyResult): result is StrategyResult & { success: false; errors: ValidationError[]; }; //# sourceMappingURL=base-strategy.d.ts.map