import type { FileEntry } from "./session-entries.js"; import { SessionManager } from "./session-manager.js"; /** Archive format version written by {@link packSession} and the only one {@link unpackSession} reads. */ export declare const SESSION_ARCHIVE_VERSION = 1; /** `customType` of the transcript entries that record a session moving between machines. */ export declare const SESSION_TRANSFER_MESSAGE_TYPE = "session-transfer"; /** `manifest.json` of a session archive. */ export interface SessionArchiveManifest { /** Archive format version ({@link SESSION_ARCHIVE_VERSION}). */ version: number; /** Session id from the journal header. */ id: string; /** Working directory recorded in the journal header on the packing machine. */ cwd: string; /** omp version that wrote the archive. */ omp: string; } /** * Structured details of a {@link SESSION_TRANSFER_MESSAGE_TYPE} entry: * - `arrived` — unpacked here from `fromCwd` on another machine into `cwd`; * - `departed` — this copy was handed to `to` and is stale from here on; * - `forked` — a stale copy (`source`) was resumed, so it continued as a fork. */ export type SessionTransferDetails = { kind: "arrived"; fromCwd: string; cwd: string; } | { kind: "departed"; to: string; } | { kind: "forked"; source: string; to: string; }; /** User-facing failure of a pack, unpack, or move marker: missing input, bad archive, live owner. */ export declare class SessionTransferError extends Error { constructor(message: string); } /** Result of {@link packSession}. */ export interface PackSessionResult { /** Absolute path of the written archive. */ archivePath: string; /** Packed session id. */ id: string; /** Blobs the transcripts reference that the local blob store no longer holds; the archive lacks them. */ missingBlobs: string[]; } /** Options for {@link unpackSession}. */ export interface UnpackSessionOptions { /** Directory the session continues in on this machine; becomes the header `cwd`. */ cwd: string; /** Session directory to land in; defaults to `cwd`'s session directory. */ sessionDir?: string; } /** * How {@link unpackSession} placed the session: * - `created` — no local copy existed; * - `replaced` — local copies were prefixes of the incoming transcript and were replaced; * - `forked` — a local copy diverged, so the incoming transcript became a fork with a new id. */ export type UnpackMode = "created" | "replaced" | "forked"; /** Result of {@link unpackSession}. */ export interface UnpackSessionResult { /** Absolute path of the unpacked session file. */ sessionFile: string; /** Id of the unpacked session (a fresh id when `mode` is `forked`). */ id: string; /** How the session was placed. */ mode: UnpackMode; } /** Transfer details of `entry`, or `undefined` when it is not a session-transfer marker. */ export declare function sessionTransferDetails(entry: FileEntry): SessionTransferDetails | undefined; /** The latest session-transfer marker in append order, if any. */ export declare function lastSessionTransfer(entries: readonly FileEntry[]): SessionTransferDetails | undefined; /** * Pack `sessionFile` with its artifacts and referenced blobs into the tar * `outPath` (written atomically). Refuses a session another live omp process * is writing; the ownership lease is held while the files are read. */ export declare function packSession(sessionFile: string, outPath: string): Promise; /** * Unpack a {@link packSession} archive so the session continues in * `options.cwd`. The archive is validated in full (manifest version, member * layout, every blob's sha256) before anything is written. Blobs go into the * local blob store; the journal and artifacts are staged in a temp directory * and moved with {@link SessionManager.openRelocated}, which rewrites the * header `cwd`. An `arrived` marker is appended. * * One live copy: local copies of the same session whose entries are a prefix * of the incoming ones are replaced (restored if placing fails); if any local * copy diverged, the incoming transcript lands as a fork with a new id whose * `parentSession` is the original id, and local copies stay untouched. */ export declare function unpackSession(archivePath: string, options: UnpackSessionOptions): Promise; /** * Append a `departed` marker to `sessionFile`: the session moved to `label` * and this copy is stale. Refuses a session another live omp process writes. */ export declare function markSessionMoved(sessionFile: string, label: string): Promise; /** * Resume guard: when `manager`'s latest transfer marker says the session moved * away, close it untouched and return a fork of it (in `sessionDir`, default: * the cwd's session directory) carrying a visible `forked` notice. Otherwise * return `manager` itself. */ export declare function forkIfMovedAway(manager: SessionManager, sessionDir?: string): Promise;