import { type LaunchProfile } from './launchProfile.js'; import { type SpawnResult, type StrictProject } from './sessions.js'; export declare const SWEEP_MS = 30000; /** The fields read from a ~/.claude/sessions/.json. */ export interface SessionFile { pid: number; sessionId: string; cwd: string; procStart: string; kind?: string; entrypoint?: string; name?: string; nameSource?: string; } export interface Span { from: string; to: string; } export interface LedgerRow { project_id: string; cwd: string; name?: string; name_source?: string; kind: string; entrypoint: string; first_seen: string; last_seen: string; spans: Span[]; } export interface Ledger { version: 1; sessions: Record; /** Work-period start (iso) → when it was restored. */ restored_periods: Record; } export interface FleetRow { claude_session_id: string; project_id: string; cwd: string; name?: string; first_seen: string; last_seen: string; period: 'closed' | 'open'; live: boolean; default_selected: boolean; } export interface LastFleet { status: 'ok' | 'unavailable'; reason?: string; period_gap_hours: number; closed_period?: { start: string; end: string; restored_at?: string; }; open_period?: { start: string; }; sessions: FleetRow[]; } export type RestoreStatus = 'restored' | 'needs_attention' | 'skipped_live' | 'failed'; export interface RestoreRow { claude_session_id: string; project_id?: string; status: RestoreStatus; session_key?: string; attach_argv?: string[]; code?: string; error?: string; } export interface FleetDeps { sessionsDir?: () => string; fleetDir?: () => string; projects?: () => StrictProject[]; /** pid → `ps -o lstart` in UTC / C locale, for the pids still running. */ procStarts?: (pids: number[]) => Promise>; spawn?: (projectId: string, resume: string, cwd: string) => Promise; profile?: () => LaunchProfile; now?: () => number; stagger?: (ms: number) => Promise; } export declare function defaultSessionsDir(): string; export declare function defaultFleetDir(): string; /** * Every `.json` in the directory. A file that does not parse is skipped * (Claude may be mid-write). A file that parses but lacks sessionId, cwd, * procStart or pid is shape drift: reported, never guessed around. */ export declare function readSessionFiles(dir: string): { files: SessionFile[]; drift?: string; }; /** `ps` start times for the pids still running, as procStart writes them. */ export declare function psProcStarts(pids: number[]): Promise>; interface Cluster { start: number; end: number; live: boolean; ids: Set; } /** * Merge every row's spans into work periods: a gap longer than gapMs with * nothing seen splits them. A live row's last span runs to now and marks its * period live. */ export declare function workPeriods(ledger: Ledger, live: Set, gapMs: number, now: number): Cluster[]; export declare class Fleet { private ledger; private live; private status; private reason?; private lastPersist; private dirty; private sweeping; private recentlyRestored; private d; constructor(deps?: FleetDeps); private ledgerPath; private load; /** Write the ledger atomically (tmp + rename). */ persist(): void; /** One sweep. Concurrent callers share the one in flight. */ sweep(): Promise; private doSweep; /** Mark the fleet unavailable from outside (the start-up contract check). */ markUnavailable(reason: string): void; liveIds(): Set; private gapHours; /** GET /sessions/last-fleet. Computed at read time from the ledger. */ lastFleet(): LastFleet; /** * POST /sessions/restore. With no ids, the default-selected rows. Sweeps * first, so "live" is current rather than up to 30 s old. */ restore(sessionIds?: unknown): Promise<{ results: RestoreRow[]; }>; private restoreIds; /** * restore_on_start (D5). Only when nothing is live (a daemon restarted * mid-day must not drop yesterday's sessions on top of today's), and each * closed period at most once: restored_at is written BEFORE spawning, so a * daemon that crash-loops does not restore again. */ restoreOnStart(): Promise; } export declare function fleet(): Fleet; /** Test seam. */ export declare function _setFleet(f: Fleet | null): void; /** * The start-up contract check: `claude agents --json` is the documented view * of the same live set. A session it lists that the files do not is drift. * When claude itself cannot be run, the files stay authoritative. */ export declare function agentsContractCheck(f: Fleet): void; /** Start the 30 s sweep. Returns a stop function that flushes the ledger. */ export declare function startFleetSweep(): () => void; export {}; //# sourceMappingURL=fleet.d.ts.map