/** * Hidden-Session Judge — task completion verification. * * Pattern sourced from dzianisv/opencode-plugins (reflection-3.ts). * Uses heuristic detectors first (no LLM cost), then optional LLM judge * in a hidden session. 0-risk: all operations wrapped in try-catch. * * Key design decisions: * - Opt-in only (hiddenJudge.enabled = false by default — judge consumes LLM tokens) * - Heuristic-only fallback when client.session.create() is unavailable * - Max 3 retries per task (Reflexion-style, Shinn et al. 2023) * - Ephemeral: no persistent storage of judge evaluations * - Anti-recursion: judge never evaluates judge sessions */ import type { TaskContext } from '../utils/judge-prompt.js'; export interface HiddenJudgeConfig { enabled?: boolean; maxRetries?: number; minToolCalls?: number; writeRatioThreshold?: number; } export interface JudgeEvaluation { verdict: 'complete' | 'incomplete'; source: 'heuristic' | 'llm'; reason: string; } export interface EvaluateParams { sessionId: string; client: any; taskContext: TaskContext; } /** * Hidden judge service that evaluates task completion. * Uses heuristic detectors first, then optional LLM judge via hidden session. */ export declare class HiddenJudgeService { private config; /** Track retry counts per task to prevent infinite judge loops */ private retryCounts; constructor(config: HiddenJudgeConfig); /** * Main entry point — evaluate task completion and inject feedback if needed. * 0-risk: never throws, always returns gracefully. */ evaluateAndFeedback(params: EvaluateParams): Promise; /** * Run LLM judge in a hidden session. * Falls back gracefully if hidden session creation is unavailable. */ private runLLMJudge; /** * Inject judge feedback into the main session. * Uses session.prompt with synthetic parts to avoid polluting context. */ private injectFeedback; /** * Clean up retry tracking for a session. */ clearRetryCount(sessionId: string): void; private isEnabled; }