import { existsSync, mkdirSync } from "node:fs"; import { homedir } from "node:os"; import { join } from "node:path"; import type { SessionPaths } from "./types.ts"; import { MAX_FILE_SIZE } from "./config.ts"; export const DEFAULT_CHRONO_DIR = join(homedir(), ".pi", "chrono"); export let CHRONO_DIR = DEFAULT_CHRONO_DIR; export let SESSIONS_DIR = join(CHRONO_DIR, "sessions"); export let BLOBS_DIR = join(CHRONO_DIR, "blobs"); export { MAX_FILE_SIZE }; export function setChronoStorageRoot(root: string): void { CHRONO_DIR = root; SESSIONS_DIR = join(CHRONO_DIR, "sessions"); BLOBS_DIR = join(CHRONO_DIR, "blobs"); } export function ensureDirs(): void { for (const d of [CHRONO_DIR, SESSIONS_DIR, BLOBS_DIR]) { if (!existsSync(d)) mkdirSync(d, { recursive: true }); } } export function sessionPaths(sessionId: string): SessionPaths { const dir = join(SESSIONS_DIR, sessionId); return { sessionId, dir, stateFile: join(dir, "state.json"), pendingFile: join(dir, "pending-pre.json"), journalsDir: join(dir, "journals"), }; } export function ensureSessionDirs(p: SessionPaths): void { for (const d of [p.dir, p.journalsDir]) { if (!existsSync(d)) mkdirSync(d, { recursive: true }); } }