/** * 多模型共识算法纯逻辑(零平台依赖)。 * 从 oh-my-opencode-cohub/src/tools/council.ts 搬移 A 类 + B 类函数与常量。 * C 类(依赖 @opencode-ai/sdk / @opencode-ai/plugin)不搬。 */ /** 失败分类(搬自 quality.ts) */ export type FailureCategory = "timeout" | "empty" | "error" | "quality-low"; /** 重试决策结果(搬自 council.ts T2 decision table) */ export type RetryAction = "retry" | "needs-human" | "give-up" | "budget-exhausted"; /** 结构化摘要(搬自 council.ts CouncillorSummary) */ export interface CouncillorSummary { conclusions: string[]; entities: string[]; } /** 共识检测输入(搬自 council.ts ConsensusInput) */ export interface ConsensusInput { name: string; summary: CouncillorSummary; } /** 共识检测结果(搬自 council.ts ConsensusResult) */ export interface ConsensusResult { consensus: boolean; agreementScores: Record; averageAgreement: number; } /** * 最小化 councillor 配置引用(搬自 council.ts CouncillorConfig 的结构等价接口)。 * 仅保留 adaptiveKey 所需的字段。 */ export interface CouncillorModelRef { model: string; variant?: string; } /** * 最小化 councillor 结果条目(搬自 council.ts 内部 CouncillorResult 的结构等价接口)。 * 原类型未 export;此处定义为共享层兼容接口,供 formatCouncillorResults 等函数使用。 */ export interface CouncillorResult { name: string; model: string; status: string; result?: string; error?: string; summary?: CouncillorSummary; } /** Per-category retry limits(empty 保留 legacy councillor_retries 默认) */ export declare const RETRY_LIMITS: Record; export declare const CONCLUSION_MARKERS: string[]; export declare const ENTITY_MARKERS: string[]; export declare const STOPWORDS: Set; export declare const VARIANT_ORDER: readonly ["max", "high", "medium", "low"]; export declare function tokenize(text: string): string[]; /** Jaccard overlap between two token sets. */ export declare function jaccard(x: string[], y: string[]): number; /** Downgrade a variant one step ("max" -> "high" -> "medium" -> "low" -> undefined). */ export declare function downgradeVariant(variant?: string): string | undefined; /** * Parse "provider/model" reference. * Returns null if format is invalid. */ export declare function parseModelReference(model: string): { providerID: string; modelID: string; } | null; /** * Build a human-readable model composition string. * e.g. "expert1: gpt-4, expert2: claude-3" */ export declare function formatModelComposition(councillorResults: CouncillorResult[]): string; /** * T8: 自适应参数表的 (strategy, agent) 键。 * strategy 取 councillor 的 variant 档位(未配置时为 "default"),agent 取模型引用; * 与 tracker computeStats 的 (strategy, agent) 聚合维度对齐。 */ export declare function adaptiveKey(config: CouncillorModelRef): string; /** * Merge the user prompt with the optional councillor-specific prompt prefix. */ export declare function formatCouncillorPrompt(userPrompt: string, councillorPrompt?: string): string; /** * Shared retry budget (T4): a total retry counter plus an elapsed-time cap. * Both runCouncillorWithRetry retries and serial extra rounds draw from it. */ export declare class RetryBudget { retriesLeft: number; readonly maxElapsedMs: number; readonly startedAt: number; constructor(maxTotalRetries: number, maxElapsedMs: number, startedAt?: number); elapsedMs(): number; expired(): boolean; /** Consume one retry slot; returns false when exhausted or expired. */ consumeRetry(): boolean; } /** Map an error message to a failure category. */ export declare function classifyFailure(message: string): FailureCategory; /** * Heuristically extract a structured summary (conclusion sentences + key * entity/decision sentences) from a councillor response text. */ export declare function extractCouncillorSummary(text: string): CouncillorSummary; /** * Pairwise agreement between two summaries: 0.5 * conclusion overlap * + 0.5 * entity overlap (Jaccard on tokens). */ export declare function pairwiseAgreement(a: CouncillorSummary, b: CouncillorSummary): number; /** * Compute consensus across councillor summaries. * Converged when >= ceil(2n/3) councillors have an average pairwise * agreement at or above the threshold. */ export declare function computeConsensus(inputs: ConsensusInput[], threshold: number): ConsensusResult; /** * T2 retry decision table. * - consecutiveStreak >= 2 of the same category -> needs-human * - per-category retry limit reached -> give-up * - shared budget exhausted -> budget-exhausted * - otherwise -> retry */ export declare function decideRetryAction(category: FailureCategory, consecutiveStreak: number, categoryRetriesUsed: number, budgetAvailable: boolean, categoryLimit?: number): RetryAction; /** Append retry guidance to the prompt based on the failure category. */ export declare function appendRetryContext(prompt: string, category: FailureCategory): string; /** * Format all councillor results into a single structured text block that the * council agent can synthesize. */ export declare function formatCouncillorResults(originalPrompt: string, councillorResults: CouncillorResult[]): string; /** * P1-4: 构建 serial 模式第二轮起的协商 prompt —— 将上一轮其他成员的意见 * 注入,要求当前 councillor 回应并修正或坚持立场,驱动收敛。 */ export declare function buildDeliberationPrompt(originalPrompt: string, previousRound: CouncillorResult[], currentName: string): string; //# sourceMappingURL=consensus.d.ts.map