import type { AgentMessage } from "@earendil-works/pi-agent-core";
import type { FileEntry } from "./session-manager.ts";
/** The file a persisted base was read from. A rewrite through rename, or any other file at that path, differs. */
export interface FileIdentity {
    readonly path: string;
    readonly dev: string;
    readonly ino: string;
}
/** The first `count` entries of a session file as one load or rewrite left them, named without holding them (R3.C1.1). */
export interface PersistedBase {
    readonly fileIdentity: FileIdentity;
    readonly count: number;
    readonly idFingerprint: string;
    /** RULING-72: the counted lines' content as the load read them (`BaseContentHash`); any later edit changes it. */
    readonly contentFingerprint: string;
}
export type TranscriptUnavailableReason = "transition_over_worker_frame_limit" | "transcript_file_identity_unavailable" | "transcript_tail_trimmed" | "transcript_tail_over_byte_limit" | "transcript_ancestry_over_byte_limit" | "transcript_entry_unidentified";
export interface TranscriptPersistence {
    readonly fileIdentity: FileIdentity;
    readonly count: number;
}
/**
 * A committed change that removes, replaces or reinstalls whole messages of the active path, named by entry id
 * (RULING-33 condition 2). Messages are owned JSON, the public message each entry contributes.
 */
export type TranscriptFlow = {
    readonly kind: "edit";
    readonly targetId: string;
    readonly message: AgentMessage;
} | {
    readonly kind: "context_edit_removal";
    readonly targetId: string;
} | {
    readonly kind: "compaction";
    readonly removedIds: readonly string[];
} | {
    readonly kind: "branch";
    readonly removedIds: readonly string[];
    readonly installed: readonly {
        readonly id: string;
        readonly message: AgentMessage;
    }[];
};
/**
 * One committed change of a manager's transcript, recorded after the commit and never before persistence.
 * Entry values are owned JSON: the manager mutates its entry objects later (mirror trimming re-parents them).
 */
export type TranscriptTransition = {
    readonly kind: "replace";
    readonly base: PersistedBase | null;
} | {
    readonly kind: "append";
    readonly id: string;
    /** The entry's engine kind and parent link: what a cut keeps of the entry once persistence released its text. */
    readonly type: string;
    readonly parentId: string | null;
    readonly entry?: string;
    readonly persistence?: TranscriptPersistence;
    readonly owningMessageId?: string;
    readonly recoveryEpoch?: string;
    readonly flow?: TranscriptFlow;
} | {
    readonly kind: "persisted";
    readonly persistence: TranscriptPersistence;
} | {
    readonly kind: "leaf";
    readonly leafId: string | null;
    readonly flow?: TranscriptFlow;
} | {
    readonly kind: "unavailable";
    readonly reason: TranscriptUnavailableReason;
};
export type PersistedBaseError = "base_file_missing" | "base_file_replaced" | "base_file_truncated" | "base_fingerprint_mismatch";
export type PersistedBaseRead = {
    readonly ok: true;
    readonly entries: readonly FileEntry[];
} | {
    readonly ok: false;
    readonly error: PersistedBaseError;
};
/** The committed transcript changes a consumer has not taken yet; it exists only once a consumer began it. */
export declare class TranscriptJournal {
    private pending;
    record(...transitions: TranscriptTransition[]): void;
    drain(): TranscriptTransition[];
}
/** One entry's part of `idFingerprint`, whatever the parsed line holds; the recovery base scan hashes the same. */
export declare const fingerprintLine: (entry: FileEntry) => string;
/** Describe the loaded/written entries now; the owning descriptor supplies their identity asynchronously. */
export declare function captureTranscriptBase(entries: readonly FileEntry[]): {
    readonly count: number;
    readonly idFingerprint: string;
    readonly history: number;
};
/**
 * Reads `base` through its captured identity only. It stops at `count`, so a legal append after the base is never
 * read, and a replaced, truncated or rewritten file is a typed failure, never a full or current-file read.
 */
export declare function readPersistedBase(base: PersistedBase, acceptedIds?: readonly string[]): PersistedBaseRead;
/**
 * A manager's whole transcript as transitions: its persisted base, each entry not on that base as its own append,
 * then its leaf. `unpersisted` is undefined when a trimmed mirror no longer holds those entries.
 */
export declare function snapshotTranscript(state: {
    readonly base: PersistedBase | null;
    readonly unpersisted: readonly FileEntry[] | undefined;
    readonly leafId: string | null;
    readonly own: (entry: FileEntry) => string;
    readonly persistence?: TranscriptPersistence;
}): TranscriptTransition[];
//# sourceMappingURL=session-transcript-journal.d.ts.map