import type { CompiledRule, LayerTraceEvent, LessonInput, NonCompilableEntry, NonCompilableReasonCode } from '@mmnto/totem';
/**
 * Terminal outcome of a `--upgrade <hash>` run, returned by `compileCommand`
 * so callers (like `totem doctor --pr` self-healing) can distinguish an actual
 * rule replacement from a noop / skipped / failed outcome and only report real
 * upgrades in their summaries.
 *
 * - `replaced`: compilation produced a fresh rule that replaced the stale copy
 * - `skipped`:  LLM decided the lesson is non-compilable; rule moved to
 *               nonCompilable and removed from active rules
 * - `noop`:     compile returned with no change (rare — cache hit path)
 * - `failed`:   transient error (network, rate limit, parser failure); old
 *               rule is preserved untouched
 */
export type UpgradeStatus = 'replaced' | 'skipped' | 'noop' | 'failed';
export interface UpgradeOutcome {
    hash: string;
    status: UpgradeStatus;
}
export interface CompileOptions {
    raw?: boolean;
    out?: string;
    model?: string;
    fresh?: boolean;
    force?: boolean;
    export?: boolean;
    fromCursor?: boolean;
    concurrency?: string;
    cloud?: string;
    verbose?: boolean;
    /**
     * Telemetry-driven re-compile (mmnto/totem#1131). Filters lessons to a single hash
     * (full or short prefix), bypasses the cache, and threads a non-code-ratio
     * directive into the Pipeline 2 system prompt.
     */
    upgrade?: string;
    /**
     * Working directory for this compile run (mmnto/totem#1232). Defaults to
     * `process.cwd()`. Pass an explicit path so callers like `runSelfHealing`
     * can target a project directory that differs from the process working
     * directory without relying on `process.chdir`.
     */
    cwd?: string;
    /**
     * Batch upgrade mode (mmnto/totem#1235). Used by `runSelfHealing` to avoid
     * redundant config/lesson/rules loads when upgrading N candidates. When set,
     * the single-hash `upgrade` path is skipped and all targets compile in a
     * single pass. Cannot be combined with `upgrade`, `cloud`, or `force`.
     */
    upgradeBatch?: Array<{
        hash: string;
        /** Telemetry directive to inject into the Pipeline 2 prompt for this lesson. */
        telemetryPrefix?: string;
    }>;
    /**
     * Recompute `compile-manifest.json`'s `output_hash` from the current
     * `compiled-rules.json` state without invoking the LLM or touching any
     * lessons (mmnto-ai/totem#1587). Exists to support the postmerge
     * inline-archive workflow where a curation script mutates
     * `status: 'archived'` on a rule directly; `--refresh-manifest` is the
     * blessed way to re-sync the manifest afterwards. Cannot combine with
     * `--force`.
     */
    refreshManifest?: boolean;
}
/**
 * Build the directive injected into the Sonnet system prompt for `--upgrade`.
 *
 * `unknown` is excluded from both the numerator and the denominator because it
 * holds historical / unclassified telemetry (pre-context-aware hits, or events
 * where the rule runner did not provide an `astContext`). Including it would
 * dilute the classified signal and produce misleading ratios.
 */
export declare function buildTelemetryPrefix(contextCounts: {
    code: number;
    string: number;
    comment: number;
    regex: number;
    unknown: number;
}): string;
/**
 * Value side of the in-memory `nonCompilableMap`. Carries the title plus the
 * machine-readable reasonCode (mmnto-ai/totem#1481) so prune / serialize
 * steps round-trip the full 4-tuple without a lookup.
 */
export interface NonCompilableMapValue {
    title: string;
    reasonCode: NonCompilableReasonCode;
    reason?: string;
}
/**
 * Filter stale entries from a non-compilable map against the current set of
 * lesson hashes. Returns the fresh 4-tuple list and a count of how many
 * entries were drained.
 *
 * Extracted for mmnto/totem#1281 so the no-op compile path can drain stale
 * entries too — previously the prune only ran when `toCompile.length > 0`,
 * leaving stale entries stranded on no-op runs (e.g. after a lesson was
 * removed or after a parser-bug fix invalidated old non-compilable hashes).
 * Pure function; does not mutate the input map.
 *
 * mmnto-ai/totem#1481: preserves `reasonCode` and `reason` through the
 * prune so ledger entries stay 4-tuple-shaped on disk. Dropping them back
 * to 2-tuple would silently reintroduce `'legacy-unknown'` on the next
 * load via the Read transform.
 */
export declare function pruneStaleNonCompilable(nonCompilableMap: Map<string, NonCompilableMapValue>, currentHashes: Set<string>): {
    fresh: NonCompilableEntry[];
    drained: number;
};
/**
 * Filter stale compiled rules whose source lesson has been removed from the
 * project. Returns the fresh rule list (same object references preserved to
 * keep audit lineage intact) and a count of how many rules were dropped.
 *
 * Symmetrical counterpart to `pruneStaleNonCompilable` — both helpers are
 * used by the no-op compile path (mmnto/totem#1281) so lesson removals drain
 * the compiled rule AND any stale non-compilable entry in the same run.
 * Pure function; does not mutate the input array.
 */
export declare function pruneStaleRules(rules: readonly CompiledRule[], currentHashes: Set<string>): {
    fresh: CompiledRule[];
    pruned: number;
};
/**
 * Replace-by-lessonHash if an entry with the same hash is already in the
 * array; otherwise append. Preserves array order for existing entries so
 * the compile loop's output stays stable across runs.
 *
 * Used by the --force durability path (mmnto-ai/totem#1587) and the
 * non-force add-new-rule path: all success-side pushes go through this
 * helper so transient compile failures leave old rules intact and
 * repeated successes do not double-insert.
 */
export declare function upsertRule(rules: CompiledRule[], rule: CompiledRule): void;
/**
 * Remove the first rule matching `lessonHash` from `rules`, in place.
 * No-op when no match. Used on the `--force` / upgrade skipped paths in
 * both local and cloud workers: when a lesson transitions to
 * non-compilable, any pre-existing rule for the same hash must be evicted
 * from the active set, otherwise --force leaves the old rule alive while
 * also marking the hash non-compilable (mmnto-ai/totem#1629 CR finding).
 */
export declare function removeRuleByHash(rules: CompiledRule[], lessonHash: string): void;
/**
 * Format a lesson's trace array into a single multi-line block for the
 * `--verbose` renderer. Returns a string (no trailing newline — caller
 * controls that). Output shape:
 *
 *   lesson-<hash8> "<heading>":
 *     Layer <N> (<pipeline label>) -> <outcome> (<patternHash?>)
 *       verify on example: <outcome>
 *       retry N: scheduled
 *     result: <status> (<reasonCode or detail>)
 *
 * The renderer is defensive: malformed / unknown layer numbers render as
 * "(unknown)" rather than throwing.
 */
export declare function formatVerboseTraceBlock(lesson: {
    heading: string;
    hash: string;
}, status: 'compiled' | 'skipped' | 'failed' | 'noop', reasonCode: NonCompilableReasonCode | undefined, trace: readonly LayerTraceEvent[] | undefined): string;
export interface AutoScaffoldDeps {
    fs: typeof import('node:fs');
    path: typeof import('node:path');
    testsDir: string;
    cwd: string;
    testedHashes: Set<string>;
    log: {
        info: (tag: string, msg: string) => void;
    };
    extractRuleExamples: typeof import('@mmnto/totem').extractRuleExamples;
    deriveVirtualFilePath: typeof import('@mmnto/totem').deriveVirtualFilePath;
    scaffoldFixture: typeof import('@mmnto/totem').scaffoldFixture;
    scaffoldFixturePath: typeof import('@mmnto/totem').scaffoldFixturePath;
}
/** Returns true if the fixture was written, false on failure. */
export declare function autoScaffoldFixture(lesson: LessonInput, rule: CompiledRule, deps: AutoScaffoldDeps): boolean;
export declare function compileCommand(options: CompileOptions): Promise<UpgradeOutcome | UpgradeOutcome[] | void>;
//# sourceMappingURL=compile.d.ts.map