1
/** Canonical raw log basename shared by every generation-addressed Session artifact. */3
import { sessionFormatVersion } from './json.ts'5
const CANONICAL_LOG_FILENAME = /^session(?:\.v([1-9][0-9]*))?\.jsonl$/u7
/**8
* Name the raw JSONL log of one immutable Session format generation. Version9
* zero keeps the original `session.jsonl`; every later generation carries a10
* lowercase numeric `.vN` component before the `.jsonl` suffix.11
* @param version - non-negative safe integer Session format version.12
* @returns the canonical basename, without any compression suffix.13
*/14
export function sessionFormatLogFilename(version: number): string {15
const generation = sessionFormatVersion(version, 'Session log generation version')16
return generation === 0 ? 'session.jsonl' : `session.v${generation}.jsonl`17
}19
/**20
* Read the generation named by one raw JSONL log basename. Temporary,21
* uppercase, leading-zero, `.v0`, and compression-suffixed names are not22
* canonical.23
* @param filename - one basename from a Session directory or archive.24
* @returns its Session format version, or `undefined` when the name is not canonical.25
*/26
export function parseSessionFormatLogFilename(filename: string): number | undefined {27
const match = CANONICAL_LOG_FILENAME.exec(filename)28
if (match === null) return undefined29
if (match[1] === undefined) return 030
const version = Number(match[1])31
return Number.isSafeInteger(version) ? version : undefined32
}