/** * SelfProposalEngine — Phase 2.2 * * Concrete MetamorphosisEngine that reads activity.log, parses structured * log entries, detects semantic patterns, generates governance proposals * (type: 'metamorphosis'), and submits them through the full 3-agent + * Dynamo governance pipeline. * * Safety constraints: * - Max proposals per hour (default 1, configurable) * - Circuit breaker: after N consecutive failures, halt for cooldown (default 3/24h) * - Only proposes changes to whitelisted targets * - All proposals go through full governance with metamorphosisThreshold (default 0.7) * - Detection thresholds are configurable (not hard-coded) * * Coupling note: currently triggered by PostProcessor.onPhase(). A future * refactor should extract log-reading into a dedicated LogReader that can * run on its own schedule or fs.watch, decoupling from PostProcessor lifecycle. */ import type { MetamorphosisEngine, MetamorphosisProposal } from '../../types/metamorphosis.js'; export interface SelfProposalConfig { maxProposalsPerHour?: number; circuitBreakerThreshold?: number; circuitBreakerCooldownHours?: number; activityLogPath?: string; whitelistedTargets?: string[]; /** Number of recent log lines to analyze (default: 100) */ maxLogLines?: number; /** Minimum error entries to trigger an error-handling proposal (default: 5) */ errorThreshold?: number; /** Minimum warning entries to trigger a monitoring proposal (default: 10) */ warningThreshold?: number; /** Minimum governance rejections of same type to trigger a pattern proposal (default: 3) */ governanceRejectionThreshold?: number; /** Minimum confidence for generated proposals (default: 0.7) */ proposalConfidence?: number; /** Metamorphosis score threshold for approval (default: 0.7) */ metamorphosisThreshold?: number; /** Project root for resolving whitelisted target paths (default: process.cwd()) */ projectRoot?: string; } export interface SelfEvolutionMetrics { totalProposals: number; recentProposals: number; consecutiveFailures: number; circuitBreakerActive: boolean; circuitBreakerUntil: number; successRate: number; } export declare class SelfProposalEngine implements MetamorphosisEngine { readonly name = "self-proposal"; private config; private proposalHistory; private consecutiveFailures; private circuitBreakerUntil; constructor(config?: SelfProposalConfig); onPhase(phase: string, context: unknown): Promise; onProposal(proposal: MetamorphosisProposal): Promise; private isCircuitBreakerActive; private isRateLimited; getMetrics(): SelfEvolutionMetrics; private evaluateAndPropose; /** * Detect actionable patterns from parsed activity log entries. * Uses structured parsing instead of raw string matching to handle * the actual xray log format: * ISO_TIMESTAMP [jobId] [traceId.spanId] [component] action - STATUS | {details} */ detectPatterns(entries: string[]): MetamorphosisProposal[]; /** * Apply an approved self-evolution proposal by recording the change * in a state file within the first matching whitelisted target directory. * Returns true if the change was written and verified, false otherwise. */ private applySelfProposal; private submitProposal; /** * Post-apply audit for Term 72 (Self-Evolution Traceability). * For 0xray-tagged proposals (framework self-evolution), asserts that * frameworkLogger entries exist with full provenance: * - source proposal ID * - governance vote results / finalDecision / averageConfidence * - metamorphosisScore * Logs the audit outcome via frameworkLogger. */ private audit0xrayProposalTraceability; }