import { StorageManager } from './storage.js';
import { EvalHarnessStatus, validateEvalBenchmarkPack, EvalBaselineDeltaReport, EvalCiGateReport } from './evals.js';
import { GraphHealthReport } from './graph.js';
import { SessionIntegrityReport, SessionRepairPlan, SessionRepairApplyResult } from './session-integrity.js';
import { PluginConfig } from './types.js';
import './page-versioning.js';
import './consolidation-operator.js';
import './memory-projection-store-CY8TU40w.js';
import 'better-sqlite3';
import './index-1qIcnbG1.js';

interface QmdRuntimeLike {
    probe(): Promise<boolean>;
    isAvailable(): boolean;
    ensureCollection(memoryDir: string): Promise<"present" | "missing" | "unknown" | "skipped">;
    debugStatus(): string;
}
interface ConversationIndexLike {
    getConversationIndexHealth(): Promise<{
        enabled: boolean;
        backend: "qmd" | "faiss";
        status: "ok" | "degraded" | "disabled";
        chunkDocCount: number;
        lastUpdateAt: string | null;
        qmdAvailable?: boolean;
        faiss?: {
            ok: boolean;
            status: "ok" | "degraded" | "error";
            indexPath: string;
            message?: string;
            manifest?: {
                version: number;
                modelId: string;
                normalizedModelId: string;
                dimension: number;
                chunkCount: number;
                updatedAt: string;
                lastSuccessfulRebuildAt: string;
            };
        };
    }>;
    rebuildConversationIndex(sessionKey?: string, hours?: number, opts?: {
        embed?: boolean;
    }): Promise<{
        chunks: number;
        skipped: boolean;
        reason?: string;
        embedded?: boolean;
        rebuilt?: boolean;
    }>;
}
interface OperatorToolkitOrchestrator extends ConversationIndexLike {
    config: PluginConfig;
    storage: StorageManager;
    qmd: QmdRuntimeLike;
}
interface OperatorConfigLoadResult {
    found: boolean;
    path: string;
    parsed: boolean;
    memoryDir?: string;
    workspaceDir?: string;
    error?: string;
}
interface OperatorSetupReport {
    schemaVersion: 1;
    generatedAt: string;
    config: OperatorConfigLoadResult;
    memoryDir: string;
    workspaceDir: string;
    directories: Array<{
        path: string;
        exists: boolean;
        writable: boolean;
    }>;
    qmd: {
        enabled: boolean;
        available: boolean;
        collectionState: "present" | "missing" | "unknown" | "skipped";
        debugStatus: string;
    };
    nativeKnowledge: {
        enabled: boolean;
        includeFiles: string[];
        curatedIncludeSync: {
            statePath: string;
            exists: boolean;
            updatedAt: string | null;
            fileCount: number;
            activeChunkCount: number;
            deletedFileCount: number;
        };
        openclawWorkspaceAdapterEnabled: boolean;
        obsidianVaultAdapterEnabled: boolean;
        obsidianSync: {
            statePath: string;
            exists: boolean;
            updatedAt: string | null;
            vaultCount: number;
            activeChunkCount: number;
            deletedNoteCount: number;
        };
        openclawWorkspaceSync: {
            statePath: string;
            exists: boolean;
            updatedAt: string | null;
            fileCount: number;
            activeChunkCount: number;
            deletedFileCount: number;
        };
    };
    explicitCapture: {
        captureMode: string;
        enabled: boolean;
        memoryDocPath: string;
        memoryDocExists: boolean;
        memoryDocInstalled: boolean;
        memoryDocUpdated: boolean;
        memoryDocRemoved: boolean;
        preview: string | null;
    };
    nextSteps: string[];
    verificationCommands: string[];
}
interface OperatorDoctorCheck {
    key: string;
    status: "ok" | "warn" | "error";
    summary: string;
    remediation?: string;
    details?: unknown;
}
interface OperatorConfigReviewFinding {
    key: string;
    status: "recommend" | "problem";
    setting: string;
    currentValue: string;
    defaultValue: string;
    recommendedValue: string;
    summary: string;
    rationale: string;
}
interface OperatorConfigReviewReport {
    schemaVersion: 1;
    generatedAt: string;
    ok: boolean;
    config: OperatorConfigLoadResult;
    profile: {
        memoryOsPreset?: string;
        searchBackend: string;
        qmdEnabled: boolean;
        qmdDaemonEnabled: boolean;
        nativeKnowledgeEnabled: boolean;
        fileHygieneEnabled: boolean;
        conversationIndexEnabled: boolean;
    };
    summary: {
        recommend: number;
        problem: number;
    };
    findings: OperatorConfigReviewFinding[];
}
interface OperatorDoctorReport {
    schemaVersion: 1;
    generatedAt: string;
    ok: boolean;
    summary: {
        ok: number;
        warn: number;
        error: number;
    };
    config: OperatorConfigLoadResult;
    checks: OperatorDoctorCheck[];
}
interface OperatorInventoryNamespaceSummary {
    namespace: string;
    memoryCount: number;
    entityCount: number;
}
interface OperatorInventoryReport {
    schemaVersion: 1;
    generatedAt: string;
    memoryDir: string;
    totals: {
        memories: number;
        entities: number;
        namespaces: number;
        reviewQueue: number;
        storageBytes: number;
    };
    categories: Record<string, number>;
    statuses: Record<string, number>;
    namespaces: OperatorInventoryNamespaceSummary[];
    ageBands: Record<string, number>;
    profile: {
        exists: boolean;
        chars: number;
        lines: number;
    };
    storageFootprint: {
        bytes: number;
        byTopLevel: Record<string, number>;
    };
    archivePressure: {
        archived: number;
        pendingReview: number;
        quarantined: number;
        rejected: number;
    };
    conversationIndex: {
        enabled: boolean;
        backend: "qmd" | "faiss";
        status: "ok" | "degraded" | "disabled";
        chunkDocCount: number;
        lastUpdateAt: string | null;
    };
    nativeKnowledge: {
        enabled: boolean;
        curatedIncludeSync: {
            exists: boolean;
            updatedAt: string | null;
            fileCount: number;
            activeChunkCount: number;
            deletedFileCount: number;
        };
        obsidianSync: {
            exists: boolean;
            updatedAt: string | null;
            vaultCount: number;
            activeChunkCount: number;
            deletedNoteCount: number;
        };
        openclawWorkspaceSync: {
            exists: boolean;
            updatedAt: string | null;
            fileCount: number;
            activeChunkCount: number;
            deletedFileCount: number;
        };
    };
}
interface BenchmarkRecallReport {
    schemaVersion: 1;
    generatedAt: string;
    mode: "status" | "validate" | "baseline-report" | "ci-gate" | "snapshot";
    status: EvalHarnessStatus;
    validate?: Awaited<ReturnType<typeof validateEvalBenchmarkPack>>;
    baselineReport?: EvalBaselineDeltaReport;
    ciGate?: EvalCiGateReport;
    snapshot?: {
        targetPath: string;
        snapshotId: string;
    };
}
interface OperatorRepairReport {
    schemaVersion: 1;
    generatedAt: string;
    dryRun: boolean;
    sessionCheck: SessionIntegrityReport;
    sessionRepairPlan: SessionRepairPlan;
    sessionRepairApply: SessionRepairApplyResult;
    graphHealth: GraphHealthReport;
}
interface OperatorSetupOptions {
    orchestrator: OperatorToolkitOrchestrator;
    installCaptureInstructions?: boolean;
    captureInstructionsMode?: "preview" | "install" | "remove";
    configPath?: string;
    now?: Date;
}
interface OperatorDoctorOptions {
    orchestrator: OperatorToolkitOrchestrator;
    configPath?: string;
    now?: Date;
}
interface OperatorConfigReviewOptions {
    orchestrator: OperatorToolkitOrchestrator;
    configPath?: string;
    now?: Date;
}
interface OperatorInventoryOptions {
    orchestrator: OperatorToolkitOrchestrator;
    now?: Date;
}
interface BenchmarkRecallOptions {
    config: Pick<PluginConfig, "memoryDir" | "evalStoreDir" | "evalHarnessEnabled" | "evalShadowModeEnabled" | "benchmarkBaselineSnapshotsEnabled" | "benchmarkDeltaReporterEnabled" | "memoryRedTeamBenchEnabled">;
    validatePath?: string;
    baseEvalStoreDir?: string;
    candidateEvalStoreDir?: string;
    snapshotId?: string;
    createSnapshot?: boolean;
    snapshotNotes?: string;
    gitRef?: string;
    createdAt?: string;
    now?: Date;
}
interface OperatorRepairOptions {
    config: Pick<PluginConfig, "memoryDir" | "entityGraphEnabled" | "timeGraphEnabled" | "causalGraphEnabled">;
    apply?: boolean;
    dryRun?: boolean;
    allowSessionFileRepair?: boolean;
    sessionFilesDir?: string;
    now?: Date;
}
declare function runOperatorSetup(options: OperatorSetupOptions): Promise<OperatorSetupReport>;
declare function runOperatorConfigReview(options: OperatorConfigReviewOptions): Promise<OperatorConfigReviewReport>;
declare function runOperatorDoctor(options: OperatorDoctorOptions): Promise<OperatorDoctorReport>;
/**
 * Count memories that pre-date the Memory Worth counters introduced in issue
 * #560 — i.e., neither `mw_success` nor `mw_fail` is set on the frontmatter.
 *
 * Only memories whose category is eligible for Memory Worth (see
 * `MEMORY_WORTH_ELIGIBLE_CATEGORIES`) are considered. Procedures, corrections,
 * and other kinds that are not instrumented are excluded entirely — they're
 * neither "legacy" nor "instrumented" for the purposes of this audit. The
 * total in the returned details reflects only eligible memories.
 *
 * Returned as an `ok` check regardless of count, since legacy memories are
 * fully functional (readers treat missing counters as zero observations). The
 * numbers are informational for operators following the #560 rollout.
 *
 * Exported so unit tests can exercise the classification logic without
 * booting a full orchestrator.
 */
declare function summarizeMemoryWorthLegacyCounters(storage: StorageManager): Promise<OperatorDoctorCheck>;
/**
 * Summarize the recent buffer-surprise telemetry distribution for the
 * Doctor report (issue #563 PR 3).
 *
 * Reports mean/median/p90 surprise scores and the triggered-flush rate
 * over the most recent window of ledger rows. An empty ledger is the
 * expected state until `bufferSurpriseTriggerEnabled` is turned on — the
 * check never escalates beyond `ok` / `warn` (ledger unreadable).
 *
 * Exported so tests can exercise the formatting without booting a real
 * orchestrator.
 */
declare function summarizeBufferSurpriseDistribution(storage: StorageManager, config: PluginConfig): Promise<OperatorDoctorCheck>;
/**
 * Summarize hot/cold tier distribution for the Doctor report
 * (issue #686 retention-completion).
 *
 * Shows:
 *   - hot vs cold memory counts
 *   - forgotten-memory count
 *   - top per-status breakdown
 *   - recent migrations in the last 7 days (from the tier-migration journal)
 *   - top demotion reasons from the journal
 *
 * Always returns an `ok` check — this section is informational, never
 * a gate. A missing journal or unreadable corpus is surfaced as a note,
 * not an error.
 *
 * Exported so tests can exercise the summarizer without a full orchestrator.
 */
declare function summarizeTierDistribution(storage: StorageManager): Promise<OperatorDoctorCheck>;
/**
 * Dreams phases doctor check (issue #678 PR 2/4).
 *
 * Reports per-phase: enabled status, cadence, threshold values, and last-run
 * timestamp sourced from `meta.json` (the existing maintenance ledger).
 *
 * Last-run mapping (best available in PR 2; PR 3/4 will emit per-phase events):
 *   light sleep → `meta.lastExtractionAt`   (lifecycle pass runs with extraction)
 *   REM         → `meta.lastConsolidationAt` (semantic consolidation)
 *   deep sleep  → latest governance run manifest when present, otherwise null
 */
declare function summarizeDreamsPhases(config: Pick<PluginConfig, "memoryDir" | "dreamsPhases">, storage?: StorageManager): Promise<OperatorDoctorCheck>;
/**
 * Observation throughput check for `remnic doctor` (issue #685).
 *
 * Reads the extraction-judge verdict ledger to surface:
 *  - total observations (verdicts) recorded
 *  - accept / reject / defer breakdown
 *  - most-recent `observedAt` timestamp
 *
 * The check is purely informational (always `ok`): a missing or empty
 * ledger is the expected state on a fresh install and is never an error.
 * This closes the `*(future)*` item deferred in `docs/trace-to-primitive.md`.
 */
declare function summarizeObservationThroughput(memoryDir: string): Promise<OperatorDoctorCheck>;
declare function summarizeConsolidationProvenance(storage: StorageManager, config: Pick<PluginConfig, "memoryDir"> & {
    versioningSidecarDir?: string;
}): Promise<OperatorDoctorCheck>;
declare function runOperatorInventory(options: OperatorInventoryOptions): Promise<OperatorInventoryReport>;
declare function runBenchmarkRecall(options: BenchmarkRecallOptions): Promise<BenchmarkRecallReport>;
declare function runOperatorRepair(options: OperatorRepairOptions): Promise<OperatorRepairReport>;

export { type BenchmarkRecallOptions, type BenchmarkRecallReport, type OperatorConfigLoadResult, type OperatorConfigReviewFinding, type OperatorConfigReviewOptions, type OperatorConfigReviewReport, type OperatorDoctorCheck, type OperatorDoctorOptions, type OperatorDoctorReport, type OperatorInventoryNamespaceSummary, type OperatorInventoryOptions, type OperatorInventoryReport, type OperatorRepairOptions, type OperatorRepairReport, type OperatorSetupOptions, type OperatorSetupReport, type OperatorToolkitOrchestrator, runBenchmarkRecall, runOperatorConfigReview, runOperatorDoctor, runOperatorInventory, runOperatorRepair, runOperatorSetup, summarizeBufferSurpriseDistribution, summarizeConsolidationProvenance, summarizeDreamsPhases, summarizeMemoryWorthLegacyCounters, summarizeObservationThroughput, summarizeTierDistribution };
