/** * Extracts the response: everything after the "❯ " echo in the * transcript, minus the final input box and status lines. */ export declare function extractResponse(buffer: string, prompt: string): string; export interface TuiDialogOption { n: number; label: string; hint: string; /** Multi-select only: state of the [ ] / [✔] checkbox. */ checked?: boolean; } export interface TuiDialog { question: string; options: TuiDialogOption[]; /** * True for multi-select questions: digits toggle checkboxes, submission * goes through Tab (Submit page) then Enter. In single-select mode, * pressing the digit selects and validates directly. */ multi: boolean; } /** * The identity of a rendered dialog, to tell "still the same question" from * "a new one". * * The screen is re-read several times a second and a dialog's pixels move * constantly (footer clock, cursor, the ❯ travelling between options), so the * raw screen is useless as an identity. What must NOT change silently is the * question and the set of labels; the ❯ position and the checkbox states are * excluded on purpose — the user moving the cursor is not a new question. */ export declare function dialogKey(d: TuiDialog): string; /** * The resume-from-summary prompt, which is auto-answered at startup and must * never reach a client (invariant 4). A stale copy would otherwise flash before * the auto-answer lands. */ export declare function isResumeSummaryDialog(d: TuiDialog): boolean; /** * Detects an interactive TUI dialog (multiple-choice question, permission * prompt…): numbered options, one of which carries the "❯" selector. */ export declare function detectDialog(screen: string): TuiDialog | null; /** * The text of a transcript line IF it is a real human prompt, else null. * * A `type: "user"` line is not necessarily someone speaking: Claude Code also * writes tool results, system reminders (`<…>`) and interruptions there. The * rule was copied verbatim into `loadHistory` and `sessionPreview`; it lives * here so a third caller cannot re-derive it slightly wrong (one of them counts * turns, the other dated turns). */ export declare function userPromptText(e: any): string | null; export interface HistoryTurn { role: "user" | "assistant"; text: string; /** * When the turn was written (ms epoch), taken from the .jsonl line's * `timestamp`. Same source as `TailEvent.at`, so a replayed turn and the same * turn seen live show the SAME time. Absent on older transcripts. */ at?: number; /** * A HIDDEN user prompt (a scheduled `cron` fire, or a parent notification) * ran between this assistant turn and the one before it. Both are dropped from * the replay, which would otherwise let this turn MERGE into the previous one * (they become adjacent) — a daily report gluing itself onto an unrelated * earlier answer under a single label. The client keeps this turn's own label * when the flag is set. Mirrors `TailEvent.afterInternal` for the live path. */ afterInternal?: true; /** * For a USER turn: who sent it and from where, recovered from the stripped * `⟦platform · time · who⟧` header. `origin` is the platform (telegram / web / * cli), `from` the sender's name when known. The client feeds them to * `echoAuthor` for the SAME label the live echo shows — without them a replayed * Telegram message came back as the generic "pilot". Absent on a plain prompt. */ from?: string; origin?: string; } /** * Reads a session transcript back from its .jsonl file * (~/.claude/projects//.jsonl) so the history can * be replayed when resuming the session. */ export declare function loadHistory(cwd: string, sessionId: string): HistoryTurn[]; export interface SessionInfo { id: string; /** Last activity, in ms since epoch (file mtime). */ mtime: number; /** First real user prompt of the session, truncated. */ preview: string; } /** * Lists the resumable sessions of a directory (newest first), with the * first user prompt as a preview so a session can be recognized by more * than its id. */ export declare function listSessions(cwd: string): SessionInfo[]; /** * When the session's last REAL prompt was written (ms epoch), or null. * * That is the current turn's origin: a turn starts with a prompt (human, cron, * or another client driving it) and ends when the agent falls silent. So we * ignore technical `user` lines — a tool result arrives MID-turn and would date * the origin a few seconds before now. */ export declare function lastPromptAt(cwd: string, sessionId: string): number | null; /** Beyond this, we refuse to believe the transcript (see `resumedTurnStart`). */ export declare const MAX_RESUMED_TURN_MS: number; /** * The origin to display for a turn the server finds ALREADY RUNNING — after a * restart (i.e. every auto-update), the tmux agent having carried on without it. * * `turnStartedAt` lives in memory: restarting from `now` reset the stopwatch * while the agent had been thinking for ten minutes. The transcript, though, * survived — so we take its last prompt's time. * * Two deliberate refusals, because a wrong duration is worse than a reset one: * a timestamp in the FUTURE (the machine's clock changed in between) and a * prompt that is too OLD — the latter marking an already finished turn, whose * age we would otherwise display as a duration. */ export declare function resumedTurnStart(nowMs: number, promptAt: number | null, maxAgeMs?: number): number; /** * Finds the id of the most recent session of a directory: Claude Code * writes each session to ~/.claude/projects//.jsonl. */ export declare function findSessionId(cwd: string): string | null;