/**
 * sessions-sidecar — per-work session manifest (ADR-008 §2).
 *
 * A work used to be single-session: one chat (`work.yaml.cliSessionId` +
 * `chat.jsonl`) and one ephemeral pty. ADR-008 moves identity to
 * `(workId, sessionId)`, so each work now owns a *list* of sessions persisted
 * in an append-only `~/.autoviral/works/{workId}/.sessions.jsonl` sidecar.
 *
 * Why append-only (not inline in work.yaml): `updateWork` rewrites the whole
 * yaml on every mutation, so a growing inline session list would amplify writes
 * and widen the clobber window on the shared work doc. Each state change
 * (rename / archive / delete / lastActive bump) is a NEW appended record;
 * replay collapses by `id` (last-write-wins). A periodic compaction may rewrite
 * the file later — out of scope here.
 *
 * `sessionId` here is OUR id (server-minted, short, stable — `s_1`, `s_2` …),
 * distinct from `cliSessionId` (claude's immutable `--resume` UUID). Each chat
 * session owns its own `cliSessionId`; a terminal session's id just names the
 * pty lineage.
 *
 * Pure I/O over a JSONL file — no WsBridge / PtyPool coupling, so it is unit
 * testable in isolation. `dataDir` is injectable so tests don't touch the real
 * `~/.autoviral`.
 */
export type SessionSurface = "chat" | "terminal";
export interface SessionRecord {
    /** Server-minted stable id, unique per (workId, surface) — e.g. "s_1". */
    id: string;
    surface: SessionSurface;
    /** Chat only: claude's `--resume` UUID. Undefined for terminal sessions. */
    cliSessionId?: string;
    /**
     * B7(a)-lite (PRD-0009) — the PROMPT_VERSION the agent of THIS session was
     * last taught up to. Stored per-session (here, beside cliSessionId) because
     * ADR-008 gives every session its own CLI lineage, so each one trails
     * teaching independently. On resume, if this < the current PROMPT_VERSION the
     * bridge `--append-system-prompt`s the intervening changelog and bumps this.
     * Fresh sessions record the current version at creation. Undefined on legacy
     * records ⇒ treated as version 0 (full changelog injected on next resume).
     */
    lastInjectedPromptVersion?: number;
    createdAt: string;
    lastActive: string;
    /** First user line / cwd — a human-readable label for the session strip. */
    preview: string;
    archived: boolean;
    /** Hard-deleted tombstone — collapsed out of `listSessions()`. */
    deleted?: boolean;
}
/** Patch shape for an append that mutates an existing record. */
export type SessionPatch = Partial<Omit<SessionRecord, "id" | "surface" | "createdAt">>;
/**
 * Stateless reader/writer over one work's `.sessions.jsonl`. Construct per
 * work; cheap (no I/O until a method is called). `dataDir` defaults to the
 * configured data dir but is injectable for tests.
 */
export declare class SessionSidecar {
    private readonly workId;
    private readonly file;
    constructor(workId: string, dataDir?: string);
    /**
     * Replay the sidecar into the current set of records. Last-write-wins by id;
     * tombstoned (`deleted`) records are dropped. Order follows first-seen id so
     * the session strip is stable across reloads. Returns [] when the file is
     * absent or unreadable (a fresh / legacy work).
     */
    list(): Promise<SessionRecord[]>;
    /** Read a single session by id (or undefined). */
    get(id: string): Promise<SessionRecord | undefined>;
    /** Append a full record (create or full overwrite). Ensures the work dir. */
    append(record: SessionRecord): Promise<void>;
    /**
     * Append a patch over an existing record — reads current state, merges, and
     * appends the merged record (still append-only; replay collapses to the last
     * write). No-op returning undefined if the id is unknown.
     */
    patch(id: string, patch: SessionPatch): Promise<SessionRecord | undefined>;
    /**
     * Mint the next stable id for a surface — `s_<n>` where n is one past the
     * highest existing numeric suffix across BOTH active and tombstoned records
     * (so a deleted id is never reused). Chat and terminal namespaces are
     * independent: a work can have chat `s_1` and terminal `s_1` side by side.
     */
    nextSessionId(surface: SessionSurface): Promise<string>;
    /**
     * Create + persist a fresh session record for a surface, minting its id.
     * `preview` and `cliSessionId` are optional seed values.
     */
    create(surface: SessionSurface, opts: {
        now: string;
        preview?: string;
        cliSessionId?: string;
        id?: string;
    }): Promise<SessionRecord>;
    /** Bump lastActive (and optionally preview / cliSessionId) on touch. */
    touch(id: string, now: string, extra?: SessionPatch): Promise<void>;
    /** Flag archived=true; keeps the record + its chat log on disk. */
    archive(id: string): Promise<SessionRecord | undefined>;
    /** Flag archived=false — used when an archived session is reopened. */
    restore(id: string, now: string): Promise<SessionRecord | undefined>;
    /**
     * Hard-delete: append a tombstone so the record collapses out of `list()`.
     * Removing the on-disk `chat-{sessionId}.jsonl` is the caller's job (it knows
     * the legacy-vs-new filename mapping). Tombstones still bump the id counter so
     * the deleted id is never re-minted.
     */
    delete(id: string): Promise<boolean>;
    /** Replay including tombstones — used only by id-minting. */
    private listAllIncludingDeleted;
    /** Remove the sidecar file entirely (test helper / work-delete cleanup). */
    destroy(): Promise<void>;
}
/**
 * Default idle-TTL before a session is auto-archived on boot/sweep
 * (ADR-008 §5). 7 days; injectable so tests don't wait.
 */
export declare const SESSION_IDLE_TTL_MS: number;
/**
 * Compute which sessions are idle past `ttlMs` relative to `nowMs`. Pure —
 * the caller disposes their in-memory WsSession/pty for each returned id and
 * flags `archived` via the sidecar. Already-archived sessions are skipped.
 */
export declare function findIdleSessions(records: SessionRecord[], nowMs: number, ttlMs: number): SessionRecord[];
//# sourceMappingURL=sessions-sidecar.d.ts.map