



























@@ -1,3 +1,6 @@
1+// Session artifact filename classifiers and archive timestamp helpers.
2+// Cleanup, disk-budget, and usage accounting use these predicates to avoid deleting live transcripts.
3+14import { timestampMsToIsoFileStamp } from "@openclaw/normalization-core/number-coercion";
25import { escapeRegExp } from "../../shared/regexp.js";
36@@ -18,6 +21,7 @@ function hasArchiveSuffix(fileName: string, reason: SessionArchiveReason): boole
1821return ARCHIVE_TIMESTAMP_RE.test(raw);
1922}
202324+/** Returns true for archived session artifacts and legacy store backup names. */
2125export function isSessionArchiveArtifactName(fileName: string): boolean {
2226if (LEGACY_STORE_BACKUP_RE.test(fileName)) {
2327return true;
@@ -59,6 +63,7 @@ export function isSessionStoreTempArtifactName(fileName: string, storeBasename:
5963return sessionStoreTempPattern(storeBasename).test(fileName);
6064}
616566+/** Parses a compaction checkpoint transcript filename into session/checkpoint ids. */
6267export function parseCompactionCheckpointTranscriptFileName(fileName: string): {
6368sessionId: string;
6469checkpointId: string;
@@ -69,22 +74,27 @@ export function parseCompactionCheckpointTranscriptFileName(fileName: string): {
6974return sessionId && checkpointId ? { sessionId, checkpointId } : null;
7075}
717677+/** Returns true when a filename is a compaction checkpoint transcript. */
7278export function isCompactionCheckpointTranscriptFileName(fileName: string): boolean {
7379return parseCompactionCheckpointTranscriptFileName(fileName) !== null;
7480}
758182+/** Returns true for trajectory runtime jsonl artifacts. */
7683export function isTrajectoryRuntimeArtifactName(fileName: string): boolean {
7784return fileName.endsWith(".trajectory.jsonl");
7885}
798687+/** Returns true for trajectory pointer artifacts. */
8088export function isTrajectoryPointerArtifactName(fileName: string): boolean {
8189return fileName.endsWith(".trajectory-path.json");
8290}
839192+/** Returns true for any trajectory-related session artifact. */
8493export function isTrajectorySessionArtifactName(fileName: string): boolean {
8594return isTrajectoryRuntimeArtifactName(fileName) || isTrajectoryPointerArtifactName(fileName);
8695}
879697+/** Returns true for primary session transcript files that represent live session history. */
8898export function isPrimarySessionTranscriptFileName(fileName: string): boolean {
8999if (fileName === "sessions.json") {
90100return false;
@@ -101,13 +111,15 @@ export function isPrimarySessionTranscriptFileName(fileName: string): boolean {
101111return !isSessionArchiveArtifactName(fileName);
102112}
103113114+/** Returns true for transcript files counted in usage, including reset/deleted archives. */
104115export function isUsageCountedSessionTranscriptFileName(fileName: string): boolean {
105116if (isPrimarySessionTranscriptFileName(fileName)) {
106117return true;
107118}
108119return hasArchiveSuffix(fileName, "reset") || hasArchiveSuffix(fileName, "deleted");
109120}
110121122+/** Extracts the session id from a usage-counted transcript filename. */
111123export function parseUsageCountedSessionIdFromFileName(fileName: string): string | null {
112124if (isPrimarySessionTranscriptFileName(fileName)) {
113125return fileName.slice(0, -".jsonl".length);
@@ -122,6 +134,7 @@ export function parseUsageCountedSessionIdFromFileName(fileName: string): string
122134return null;
123135}
124136137+/** Formats an archive timestamp that is safe for filenames. */
125138export function formatSessionArchiveTimestamp(nowMs = Date.now()): string {
126139return timestampMsToIsoFileStamp(nowMs);
127140}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。