import type { CountedBuckets, ContextPressure, DayUsage, RouteUsage } from '../shared/types.js'; /** Everything one session log contributes, detached from the fold's maps. */ export interface SessionSummary { /** Session id from the log header, falling back to the directory name. */ id: string; /** Session title, when the log carries one. */ title?: string; /** Absolute working directory recorded in the header. */ cwd: string; /** Agent preset the session was seeded with, when recorded. */ agentPreset?: string; /** Epoch milliseconds the session was created. */ createdAt: number; /** Epoch milliseconds of the newest event. */ updatedAt: number; /** Turns started in the log. */ turns: number; /** Assistant settlements recorded; one per `(turn, step)` slot. */ responses: number; /** Wall-clock duration of the longest completed turn, in milliseconds. */ longestTurnMs: number; /** Whole-log totals. */ totals: CountedBuckets; /** Per-route totals, heaviest first. */ routes: RouteUsage[]; /** Per-day totals, oldest first. */ days: DayUsage[]; /** Newest context occupancy. */ context?: ContextPressure; /** Reasoning effort per request, keyed by label. */ efforts: Record; /** Skill invocations, keyed by skill name. */ skills: Record; /** Lines that failed to parse; a truncated live tail is normal. */ malformedLines: number; /** zstd frames that failed to decode; normally only the truncated tail. */ failedFrames: number; /** * Highest durable sequence number seen. * * The harness stamps every event with a monotonic `seq`, so this is the * log's position: a rewrite that was interrupted stops at a lower one, which * is how {@link SessionScanner} picks between format versions. */ maxSeq: number; /** Log-format version this summary was read from. */ version: number; } /** * Recursively collect every session log, grouped by session directory. * @param sessionsRoot - Absolute path to `$DSH_HOME/sessions`. * @returns One array of log paths per session directory, newest version first. */ export declare function discoverSessionLogs(sessionsRoot: string): string[][]; /** * Choose between the format versions of one session. * * The furthest durable position wins, because a log's `seq` is its own * completeness proof. A lower `failedFrames` breaks a tie, and the higher * version breaks the remaining one. * @param candidates - Summaries read from each version, newest version first. * @returns The summary a reader should trust. */ export declare function pickBestVersion(candidates: readonly SessionSummary[]): SessionSummary; /** A memoizing reader over the session store. */ export declare class SessionScanner { private readonly cache; /** IANA zone the cache was built for; a change forces a full re-read. */ private timeZone; /** Absolute path to `$DSH_HOME/sessions`. */ private readonly sessionsRoot; /** * @param sessionsRoot - Absolute path to `$DSH_HOME/sessions`. */ constructor(sessionsRoot: string); /** * Read every session summary, reusing unchanged logs. * * Each session directory contributes exactly ONE summary: every format * version present is decoded (from cache where possible) and * {@link pickBestVersion} chooses. A file whose size and `mtimeMs` are * unchanged is served from memory. * * The time zone participates in day bucketing, so a zone change invalidates * the whole cache rather than silently returning wrongly-bucketed days. * @param timeZone - IANA zone used for day keys. * @returns Summaries plus non-fatal read problems. */ read(timeZone: string): { summaries: SessionSummary[]; warnings: string[]; }; }