/** * Session management utilities */ import type { SessionLog, NdjsonRecord } from '../../shared/utils/index.js'; export type { SessionLog, NdjsonWorkflowStart, NdjsonWorkflowCallStart, NdjsonWorkflowCallComplete, NdjsonStepStart, NdjsonStepComplete, NdjsonWorkflowComplete, NdjsonWorkflowAbort, NdjsonPhaseStart, NdjsonPhaseComplete, NdjsonPhaseJudgeStage, NdjsonInteractiveStart, NdjsonInteractiveEnd, NdjsonCompanionReviewRound, NdjsonCompanionQueueCoalesced, NdjsonCompanionCall, NdjsonCompanionReviewSkipped, NdjsonCompanionReviewMode, NdjsonCompanionReviewTrigger, NdjsonParallelMetadata, NdjsonRecord, } from '../../shared/utils/index.js'; /** Failure information extracted from session log */ export interface FailureInfo { /** Last step that completed successfully */ lastCompletedStep: string | null; /** Step that was in progress when failure occurred */ failedStep: string | null; /** Total iterations consumed */ iterations: number; /** Error message from workflow_abort record */ errorMessage: string | null; /** Session ID extracted from log file name */ sessionId: string | null; } /** * Parse NDJSON session-log content without resolving the source path again. * * @param content - UTF-8 content read from a session-log descriptor * @param sourcePath - Path used only to identify the source in parse errors * @returns The parsed session log, or null if the content is empty or has no workflow_start record * @throws Error if a record cannot be parsed or validated */ export declare function parseNdjsonLogContent(content: string, sourcePath: string): SessionLog | null; /** * Manages session lifecycle: ID generation, NDJSON logging, * and session log creation/loading. */ export declare class SessionManager { /** Append a single NDJSON line to a log file */ appendNdjsonLine(filepath: string, record: NdjsonRecord): void; /** Initialize an NDJSON log file with the workflow_start record */ initNdjsonLog(sessionId: string, task: string, workflowName: string, options: { logsDir: string; startTime?: string; }): string; /** * Load an NDJSON log file and convert it to a SessionLog. * * @param filepath - Path to the NDJSON session log file * @returns The parsed session log, or null if the file is missing, empty, or contains no workflow_start record * @throws Error if the file cannot be read or contains an invalid NDJSON record */ loadNdjsonLog(filepath: string): SessionLog | null; /** Generate a session ID */ generateSessionId(): string; /** Generate report directory name from task and timestamp */ generateReportDir(task: string): string; /** Create a new session log */ createSessionLog(task: string, projectDir: string, workflowName: string, options?: { startTime: string; }): SessionLog; /** Create a finalized copy of a session log (immutable) */ finalizeSessionLog(log: SessionLog, status: 'completed' | 'aborted'): SessionLog; /** Load session log from a .jsonl file */ loadSessionLog(filepath: string): SessionLog | null; } /** * Append one NDJSON session record to a log file. * * @param filepath - Path to the session log file * @param record - NDJSON record to append * @throws Error if the record cannot be appended or the log directory cannot be recreated */ export declare function appendNdjsonLine(filepath: string, record: NdjsonRecord): void; /** * Initialize an NDJSON session log with a workflow-start record. * * @param sessionId - Session identifier used for the log filename * @param task - Task associated with the session * @param workflowName - Workflow associated with the session * @param options - Log directory and optional workflow start time * @returns Path to the initialized session log * @throws Error if the log directory or initial record cannot be written */ export declare function initNdjsonLog(sessionId: string, task: string, workflowName: string, options: { logsDir: string; startTime?: string; }): string; /** * Load an NDJSON log file and convert it to a session log. * * @param filepath - Path to the NDJSON session log file * @returns The parsed session log, or null if the file is missing, empty, or contains no workflow_start record * @throws Error if the file cannot be read or contains an invalid NDJSON record */ export declare function loadNdjsonLog(filepath: string): SessionLog | null; /** * Generate a timestamped random session identifier. * * @returns A session identifier suitable for an NDJSON log filename */ export declare function generateSessionId(): string; /** * Generate a report directory name from a task. * * @param task - Task used to derive the report directory name * @returns The generated report directory name */ export declare function generateReportDir(task: string): string; /** * Create an empty running session log. * * @param task - Task associated with the session * @param projectDir - Project directory associated with the session * @param workflowName - Workflow associated with the session * @param options - Optional session start time * @returns A running session log with zero iterations and an empty history */ export declare function createSessionLog(task: string, projectDir: string, workflowName: string, options?: { startTime: string; }): SessionLog; /** * Finalize a session log without mutating the input. * * @param log - Session log to finalize * @param status - Terminal status to assign * @returns A finalized copy with the supplied status and an end time */ export declare function finalizeSessionLog(log: SessionLog, status: 'completed' | 'aborted'): SessionLog; /** * Load a session log from an NDJSON `.jsonl` file. * * @param filepath - Path to the NDJSON session log file * @returns The parsed session log, or null if the file is missing, empty, or contains no workflow_start record * @throws Error if the file cannot be read or contains an invalid NDJSON record; parse errors include the filepath */ export declare function loadSessionLog(filepath: string): SessionLog | null; /** * Extract failure information from an NDJSON session log file. * * @param filepath - Path to the .jsonl session log file * @returns FailureInfo or null if file doesn't exist or is empty * @throws Error if the file cannot be read or a record cannot be parsed; parse errors include the filepath */ export declare function extractFailureInfo(filepath: string): FailureInfo | null; /** * Parse and validate one NDJSON session record while adding its source path to parse errors. * * @param line - A single NDJSON line * @param filepath - Path of the session log containing the line * @returns The validated NDJSON session record * @throws Error if the line is invalid JSON or does not match a supported record shape */ export declare function parseNdjsonRecordWithPath(line: string, filepath: string): NdjsonRecord; /** * Parse and validate one NDJSON session record. * * @param line - A single NDJSON line * @returns The validated NDJSON session record * @throws Error if the line is invalid JSON or does not match a supported record shape */ export declare function parseNdjsonRecord(line: string): NdjsonRecord; //# sourceMappingURL=session.d.ts.map