import { MemoryEngine } from './memory.js';
import { PatternRegistry, type PatternCard, type PatternSearchResult } from './pattern-registry.js';
import { RuntimeRegistry, type RuntimeRegistrySnapshot } from './runtime-registry.js';
import { RagCollectionStore, type RagCollectionSummary, type RagIngestInput, type RagRetrievalHit } from './rag-collections.js';
import { TokenSupremacyEngine, type ReadingPlan } from './token-supremacy.js';
export type KnowledgeSourceClass = 'repo' | 'memory' | 'rag' | 'patterns' | 'runtime';
export type ModelTier = 'low' | 'high';
export type KnowledgeFabricStage = 'a' | 'b' | 'c';
export interface SourceMixDecision {
    dominantSource: KnowledgeSourceClass;
    weights: Record<KnowledgeSourceClass, number>;
    reasons: string[];
}
export interface TokenBudgetAllocation {
    totalBudget: number;
    bySource: Record<KnowledgeSourceClass, number>;
    byStage: Record<'bootstrap' | 'planning' | 'mutation' | 'verification' | 'continuation', number>;
    dropped: Array<{
        sourceClass: KnowledgeSourceClass;
        label: string;
        reason: string;
    }>;
}
export interface ContextProvenanceEntry {
    sourceClass: KnowledgeSourceClass;
    id: string;
    label: string;
    summary: string;
    tokens: number;
    stage: string;
    selected: boolean;
    reason: string;
    score: number;
}
export interface ContextProvenanceTrace {
    entries: ContextProvenanceEntry[];
}
export interface ModelTierPolicy {
    lowTierStages: string[];
    highTierStages: string[];
    escalationRules: string[];
}
export interface ModelTierTrace {
    stage: string;
    tier: ModelTier;
    reason: string;
    escalated: boolean;
}
export interface KnowledgeFabricBundle {
    runtimeId: string;
    sessionId: string;
    task: string;
    generatedAt: number;
    stage: KnowledgeFabricStage;
    cache: {
        key: string;
        hit: boolean;
        reused: boolean;
    };
    sourceMix: SourceMixDecision;
    tokenBudget: TokenBudgetAllocation;
    provenance: ContextProvenanceTrace;
    modelTierPolicy: ModelTierPolicy;
    modelTierTrace: ModelTierTrace[];
    repo: {
        candidateFiles: string[];
        selectedFiles: string[];
        readingPlan?: ReadingPlan;
    };
    memory: {
        matches: string[];
    };
    rag: {
        attachedCollections: RagCollectionSummary[];
        hits: RagRetrievalHit[];
    };
    patterns: {
        selected: PatternSearchResult[];
        shortlist: PatternCard[];
    };
    runtime: {
        priorObjectives: string[];
        skipReasons: string[];
        lastToolCalls: string[];
        lastRunId?: string;
    };
    recommendations: {
        skills: string[];
        workflows: string[];
        hooks: string[];
        automations: string[];
        crews: string[];
        specialists: string[];
    };
    summary: string;
}
export interface KnowledgeFabricSnapshot {
    runtimeId: string;
    sessionId: string;
    generatedAt: number;
    task: string;
    stage: KnowledgeFabricStage;
    cache: KnowledgeFabricBundle['cache'];
    sourceMix: SourceMixDecision;
    tokenBudget: TokenBudgetAllocation;
    attachedCollections: RagCollectionSummary[];
    patternHits: Array<{
        patternId: string;
        name: string;
        score: number;
    }>;
    selectedFiles: string[];
    candidateFiles: string[];
    recommendations: KnowledgeFabricBundle['recommendations'];
    modelTierPolicy: ModelTierPolicy;
    modelTierTrace: ModelTierTrace[];
    provenance: ContextProvenanceTrace;
    summary: string;
}
interface MemoryMatchWithQuality {
    content: string;
    confidence: number;
    entropy: number;
    trust: number;
}
interface ComposeInput {
    runtimeId: string;
    sessionId: string;
    task: string;
    candidateFiles: string[];
    memoryMatches: string[];
    memoryMatchesWithQuality?: MemoryMatchWithQuality[];
    fileBoosts?: Map<string, number>;
    runtimeSnapshot?: RuntimeRegistrySnapshot;
    tokenBudget?: number;
    intent?: {
        riskClass?: string;
        complexity?: number;
        taskType?: string;
    };
    stageHint?: KnowledgeFabricStage;
}
export declare class KnowledgeFabricEngine {
    private readonly repoRoot;
    private readonly stateDir;
    private readonly tokenEngine;
    private readonly runtimeRegistry;
    private readonly ragCollections;
    private readonly patternRegistry;
    private readonly memory?;
    private readonly bundleCache;
    private readonly snapshotCache;
    constructor(options?: {
        repoRoot?: string;
        stateRoot?: string;
        memory?: MemoryEngine;
        runtimeRegistry?: RuntimeRegistry;
        tokenEngine?: TokenSupremacyEngine;
        ragCollections?: RagCollectionStore;
        patternRegistry?: PatternRegistry;
    });
    compose(input: ComposeInput): Promise<KnowledgeFabricBundle>;
    private composeStage;
    private determineStage;
    private buildCacheKey;
    listCollections(): RagCollectionSummary[];
    getCollection(collectionId: string): import("./rag-collections.js").RagCollection;
    createCollection(input: {
        name: string;
        description?: string;
        tags?: string[];
        scope?: 'session' | 'project';
    }): import("./rag-collections.js").RagCollection;
    ingestCollection(collectionId: string, inputs: RagIngestInput[]): Promise<{
        collection: import("./rag-collections.js").RagCollection;
        sourcesAdded: number;
        chunksAdded: number;
    }>;
    attachCollection(collectionId: string, runtimeId: string, sessionId?: string): import("./rag-collections.js").RagCollection;
    detachCollection(collectionId: string, runtimeId?: string, sessionId?: string): import("./rag-collections.js").RagCollection;
    deleteCollection(collectionId: string): boolean;
    ensureBootstrapCollection(input: {
        runtimeId: string;
        sessionId: string;
        candidateFiles: string[];
    }): Promise<RagCollectionSummary | undefined>;
    listPatterns(): PatternCard[];
    searchPatterns(query: string, limit?: number): PatternSearchResult[];
    recordPatternOutcome(patternId: string, success: boolean): void;
    getSessionSnapshot(runtimeId: string): KnowledgeFabricSnapshot | undefined;
    getProvenance(runtimeId: string): ContextProvenanceTrace;
    getTokensBySource(runtimeId: string): Record<string, number>;
    getModelTiers(runtimeId: string): {
        policy?: ModelTierPolicy;
        trace: ModelTierTrace[];
    };
    private persistBundle;
    private persistBundleAsync;
    private pruneRuntimeSnapshotsAsync;
    private buildSourceMix;
    private allocateTokenBudget;
    private buildRecommendations;
    private buildModelTierPolicy;
    private buildModelTierTrace;
    private buildProvenance;
    private summarizeBundle;
}
export {};
