Files
deepseek-harness/packages/session/session-format/src/filename.ts
T
Tianyi Cui c97df989ff refactor(session): share the canonical log basename and JSON snapshots
`session[.vN].jsonl` was assembled independently by the JSONL provider
(twice), the session-log export archive, and the recorded-session fixture
helpers. `dsh-session-format` now owns `sessionFormatLogFilename` and
`parseSessionFormatLogFilename`; the three consumers append only their
compression suffix, and the migration note names the owner.

`snapshotSessionFormatJson` re-implemented the lossless JSON walk that
`dsh-util-values` already publishes as `snapshotJsonValue` + `deepFreeze`,
and the frozen v0 relationship validator carried a third structural JSON
comparison next to `deepEqualJson`. Both now delegate; the format package
reports one `is not lossless JSON` diagnostic per labelled subject instead
of ten member-specific ones, and enumerable accessors whose values survive
a JSON round trip are accepted like `JSON.stringify` accepts them.
2026-09-03 21:48:09 +08:00

33 lines
1.4 KiB
TypeScript

/** Canonical raw log basename shared by every generation-addressed Session artifact. */
import { sessionFormatVersion } from './json.ts'
const CANONICAL_LOG_FILENAME = /^session(?:\.v([1-9][0-9]*))?\.jsonl$/u
/**
* Name the raw JSONL log of one immutable Session format generation. Version
* zero keeps the original `session.jsonl`; every later generation carries a
* lowercase numeric `.vN` component before the `.jsonl` suffix.
* @param version - non-negative safe integer Session format version.
* @returns the canonical basename, without any compression suffix.
*/
export function sessionFormatLogFilename(version: number): string {
const generation = sessionFormatVersion(version, 'Session log generation version')
return generation === 0 ? 'session.jsonl' : `session.v${generation}.jsonl`
}
/**
* Read the generation named by one raw JSONL log basename. Temporary,
* uppercase, leading-zero, `.v0`, and compression-suffixed names are not
* canonical.
* @param filename - one basename from a Session directory or archive.
* @returns its Session format version, or `undefined` when the name is not canonical.
*/
export function parseSessionFormatLogFilename(filename: string): number | undefined {
const match = CANONICAL_LOG_FILENAME.exec(filename)
if (match === null) return undefined
if (match[1] === undefined) return 0
const version = Number(match[1])
return Number.isSafeInteger(version) ? version : undefined
}