/**
 * PreCompactionFlush — Save important context to MEMORY.md *before* Claude Code
 * compaction collapses working memory.
 *
 * Architecture (Option A — server-side, agent-noninterruptive):
 *   1. Claude Code emits PreCompact hook → instar's hook-event-reporter POSTs
 *      to /hooks/events → HookEventReceiver emits 'PreCompact' event.
 *   2. This class listens on that event. On each fire, it:
 *      a. Locates the agent's transcript jsonl using Claude Code's standard
 *         path convention: ~/.claude/projects/<encoded-cwd>/<session-id>.jsonl
 *      b. Reads the last N chars of the transcript (default 30KB) — bounded
 *         to keep the LLM call cheap.
 *      c. Sends a fact-extraction prompt to the shared intelligence provider
 *         (subscription path, no per-call cost on default config).
 *      d. Parses the response. Acceptable shapes: JSON array, JSON object
 *         with `facts` array, or markdown bullet list. Any valid fact has
 *         `slug` (kebab-case, ≤48 chars) and `body` (≤500 chars).
 *      e. For each parsed fact, writes a new file under
 *         `<projectDir>/.instar/memory/learning_<ts>_<slug>.md` with the
 *         standard memory frontmatter (type=learning).
 *      f. Appends a one-line index entry to `<projectDir>/.instar/MEMORY.md`
 *         if a "## Learnings" or similar section exists (best-effort).
 *      g. Writes a structured audit entry to
 *         `<projectDir>/.instar/audit/pre-compaction-flush.jsonl`.
 *
 * Safety properties:
 *   - Default `enabled: false` — flush is opt-in. The behavior change is
 *     additive and the audit log surfaces every fire, so operators can
 *     observe before enabling.
 *   - `maxFactsPerFlush` (default 5) caps the blast radius if the LLM
 *     hallucinates a long list.
 *   - All writes are best-effort: any single failure (transcript missing,
 *     LLM error, file write race) is audited and returns; never throws.
 *   - Calls run async/detached from the hook caller. The hook itself
 *     returns immediately so compaction is never delayed.
 *
 * Spec: docs/specs/OPENCLAW-IMPORT-PRE-COMPACTION-FLUSH-SPEC.md
 */
import type { IntelligenceProvider } from './types.js';
export interface PreCompactionFlushConfig {
    /** Master switch. Default false. */
    enabled: boolean;
    /** Maximum facts written per flush. Default 5. Hard cap for safety. */
    maxFactsPerFlush: number;
    /** Max chars of transcript tail to send to the LLM. Default 30000. */
    transcriptCharBudget: number;
}
export declare const DEFAULT_PRE_COMPACTION_FLUSH_CONFIG: PreCompactionFlushConfig;
export interface PreCompactionFlushDeps {
    intelligence: IntelligenceProvider | null;
    /** Agent's project root — the dir that contains `.instar/`. */
    projectDir: string;
    /** Stable agent label, used in audit entries. */
    agentLabel?: string;
    /** Optional override for transcript root (testing). Defaults to ~/.claude/projects. */
    claudeProjectsRoot?: string;
    /**
     * Runtime that produced this session. Drives transcript-path resolution
     * via FrameworkSessionStore (portability audit Gap 3). Defaults to
     * 'claude-code' — the historical behavior, so Claude installs are
     * byte-for-byte unchanged.
     */
    framework?: 'claude-code' | 'codex-cli' | 'gemini-cli' | 'pi-cli';
    /** Optional override for the Codex sessions root (testing). */
    codexSessionsRoot?: string;
    /** Optional override for the Gemini home dir (testing). */
    geminiHome?: string;
    /** Now provider — overridable for tests. */
    now?: () => Date;
}
export interface PreCompactPayload {
    event?: string;
    session_id?: string;
    transcript_path?: string;
    trigger?: string;
}
export interface ParsedFact {
    slug: string;
    body: string;
}
export type FlushOutcome = 'ok' | 'disabled' | 'no-intelligence' | 'no-session-id' | 'no-transcript' | 'no-facts' | 'parse-failure' | 'provider-error' | 'write-error';
export interface FlushAuditEntry {
    flushId: string;
    sessionId: string;
    trigger?: string;
    at: string;
    outcome: FlushOutcome;
    factsWritten?: number;
    durationMs?: number;
    reason?: string;
}
export declare class PreCompactionFlush {
    private readonly deps;
    private readonly config;
    constructor(deps: PreCompactionFlushDeps, config: PreCompactionFlushConfig);
    /**
     * Handle a PreCompact event. Fire-and-forget; never throws to the caller.
     * Returns the audit entry it wrote (for tests).
     */
    handle(payload: PreCompactPayload): Promise<FlushAuditEntry>;
    /** Build the flush prompt. Exported as a member for test inspection. */
    buildPrompt(transcriptTail: string): string;
    /** Parse the LLM response into facts. Accepts JSON array, JSON object with `facts`, or markdown. */
    parseFacts(response: string): ParsedFact[];
    private coerceFact;
    private resolveTranscriptPath;
    private readTranscriptTail;
    private writeFact;
    private appendMemoryIndex;
    private writeAudit;
}
//# sourceMappingURL=PreCompactionFlush.d.ts.map