import type { StableId } from "../config/types.js"; export declare const SMART_ROUTING_SCHEMA_VERSION: 2; export declare const SMART_ROUTING_STORAGE_VERSION: 1; export type SmartRoutingMode = "NORMAL" | "SUGGEST_MISSION" | "AUTO_MISSION"; export type LocalSignalPath = "simple" | "complex" | "ambiguous"; export declare const LOCAL_SIGNAL_CODES: readonly ["explanation_only", "question_only", "action_requested", "repository_scope", "mutation", "investigation", "multi_step", "multiple_deliverables", "tests_requested", "independent_verification", "audit_review", "debug_and_fix", "iteration_until_success", "release_deployment", "high_consequence", "destructive_sensitive", "multiple_roles", "research_and_implementation", "explicit_goal"]; export type LocalSignalCode = (typeof LOCAL_SIGNAL_CODES)[number]; export type RoutingReasonCode = LocalSignalCode | "smart_routing_disabled" | "triage_unavailable" | "triage_fallback" | "triage_low_confidence" | "routing_memory_hit" | "routing_memory_conflict" | "routing_memory_bypassed_complexity"; export interface LocalSignalAnalysis { readonly missionScore: number; readonly confidence: number; readonly signals: readonly LocalSignalCode[]; readonly path: LocalSignalPath; } export interface SmartRoutingSettings { readonly schemaVersion: typeof SMART_ROUTING_SCHEMA_VERSION; readonly enabled: boolean; readonly aiTriageEnabled: boolean; readonly routingMemoryEnabled: boolean; readonly learnFromRoutingChoices: boolean; readonly primaryRouteId?: StableId; readonly fallbackRouteId?: StableId; } export interface StoredSmartRoutingSettings { readonly storageVersion: typeof SMART_ROUTING_STORAGE_VERSION; readonly generation: number; readonly savedAt: string; readonly settings: SmartRoutingSettings; } export type SmartRoutingSettingsLoadStatus = "missing" | "valid" | "corrupt"; export interface SmartRoutingSettingsLoadResult { readonly status: SmartRoutingSettingsLoadStatus; readonly settings: SmartRoutingSettings; readonly generation: number; readonly savedAt?: string; readonly repairRequired: boolean; readonly diagnostics: readonly string[]; } export interface SmartRoutingSettingsMutationResult { readonly changed: boolean; readonly generation: number; readonly previousGeneration?: number; readonly historyPath?: string; } export declare const createDefaultSmartRoutingSettings: () => SmartRoutingSettings; export declare const validateSmartRoutingSettings: (value: unknown) => SmartRoutingSettings; /** Versioned, atomic, rollback-capable settings persistence kept separate from the legacy ConfigV1 envelope. */ export declare class SmartRoutingSettingsStore { private readonly root; private readonly activeFile; private readonly historyDir; private readonly retention; private queue; constructor(options: { readonly root: string; readonly activeFile?: string; readonly retention?: number; }); load(): Promise; initialize(settings?: SmartRoutingSettings): Promise; save(settings: SmartRoutingSettings, options?: { readonly expectedGeneration?: number; }): Promise; update(mutator: (draft: SmartRoutingSettings) => SmartRoutingSettings | void | Promise): Promise; restore(generation: number, options?: { readonly expectedGeneration?: number; }): Promise; private enqueue; private loadUnlocked; private readActive; private commit; private readHistory; private pruneHistory; private assertExpected; } export declare const MAX_ROUTING_INPUT_LENGTH = 32000; export declare const containsPersian: (value: string) => boolean; export declare function analyzeLocalSignals(prompt: string): LocalSignalAnalysis; export declare const ROUTING_REASON_LABELS: Readonly>; export declare function formatRoutingReasons(codes: readonly RoutingReasonCode[], locale?: "en" | "fa", max?: number): string; export interface TriageRequest { readonly prompt: string; readonly local: Pick; } export declare const MAX_TRIAGE_PROMPT_LENGTH = 16384; export type TriageFailureClass = "auth" | "quota" | "timeout" | "unavailable" | "malformed" | "protocol" | "transport" | "cancelled"; export declare class TriageCapabilityError extends Error { readonly failureClass: TriageFailureClass; constructor(failureClass: TriageFailureClass, message?: string); } export interface TriageResult { readonly recommendedMode: "normal" | "mission"; readonly confidence: number; readonly reasons: readonly RoutingReasonCode[]; } export interface TriageClient { classify(request: TriageRequest, routeId: StableId, signal: AbortSignal): Promise; } export declare const TRIAGE_SYSTEM_PROMPT: string; export declare const buildTriagePrompt: (request: TriageRequest) => string; export declare function parseTriageResult(value: unknown): TriageResult; export interface SmartRoutingDecision { readonly mode: SmartRoutingMode; readonly local: LocalSignalAnalysis; readonly confidence: number; readonly reasonCodes: readonly RoutingReasonCode[]; readonly triage?: { readonly calls: number; readonly fallbackUsed: boolean; readonly primaryRouteId?: StableId; readonly routeId?: StableId; readonly failureClass?: TriageFailureClass; readonly latencyMs: number; }; readonly memory?: { readonly source?: "explicit" | "learned"; readonly action?: "mission" | "normal"; readonly confidence?: number; readonly similarity?: number; readonly conflict?: boolean; readonly ruleId?: string; }; } export interface SmartRoutingContext { readonly memoryRecommendation?: { readonly mode?: SmartRoutingMode; readonly reasonCodes?: readonly string[]; readonly source?: "explicit" | "learned"; readonly action?: "mission" | "normal"; readonly confidence?: number; readonly similarity?: number; readonly conflict?: boolean; readonly ruleId?: string; }; } export interface SmartRouterOptions { readonly settings: SmartRoutingSettings | (() => SmartRoutingSettings | Promise); readonly triageClient?: TriageClient; readonly triageTimeoutMs?: number; } export declare class SmartRouter { private readonly options; private readonly timeoutMs; constructor(options: SmartRouterOptions); decide(prompt: string, signal?: AbortSignal, context?: SmartRoutingContext): Promise; private fromTriage; private degraded; } export declare const routingReasonCodes: (analysis: LocalSignalAnalysis) => readonly LocalSignalCode[];