/** Durable transcript markers for significant gaps in session activity. */ import { formatVerbose } from "./format.ts"; /** Four hours: short pauses stay quiet, while a resumed work period is explicit. */ export const DEFAULT_GAP_THRESHOLD_MS = 4 * 60 * 60 * 1_000; export interface TimeShift { readonly fromMs: number; readonly toMs: number; readonly durationMs: number; } /** Return a time shift when both endpoints are valid and the configured threshold is reached. */ export function timeShift( fromMs: number | undefined, toMs: number, thresholdMs: number = DEFAULT_GAP_THRESHOLD_MS, ): TimeShift | undefined { if ( fromMs === undefined || !Number.isFinite(fromMs) || !Number.isFinite(toMs) || !Number.isFinite(thresholdMs) || fromMs <= 0 || toMs < fromMs || thresholdMs < 0 ) { return; } const durationMs = toMs - fromMs; if (durationMs < thresholdMs) return; return { fromMs, toMs, durationMs }; } /** Stable, model-readable text that also serves as the human session notice. */ export function renderTimeShift(shift: TimeShift): string { return `[time-shift from="${new Date(shift.fromMs).toISOString()}" to="${new Date(shift.toMs).toISOString()}" duration="${formatVerbose(shift.durationMs)}"]`; }