/** * Per-session scratch + tool-output workspace. * * Each chat/history session owns a unique folder under the OS temp root: * * {tmpdir}/clai/{code}-{DD}-{MM}-{YYYY}-{HH}-{MM}-{SS}/ * temp/ ← tool run outputs (fs.list, shell.exec, recon, …) * … ← agent scratch (findings.md, engagement notes, …) * * `code` is a 6-digit hexadecimal id. The timestamp is local wall-clock * of session creation so operators can spot folders by eye. Folder names * use only [0-9a-f-] so they are safe on Windows, macOS, and Linux. * * The active workspace is process-global (one live TUI/REPL session). * History records store `workspaceFolder` + `workspaceCode` so resume * rebinds the same directory when it still exists (or recreates it). */ export interface SessionWorkspace { /** 6-char lowercase hex code (session workspace id). */ readonly code: string; /** Folder name only, e.g. `a3f9c1-18-07-2026-14-24-23`. */ readonly folderName: string; /** Absolute path to the session workspace root (scratch). */ readonly rootDir: string; /** Absolute path to `{root}/temp` (tool output artifacts). */ readonly tempDir: string; } /** Regex for the 6-hex workspace code. */ export declare const SESSION_CODE_RE: RegExp; /** Regex for a full session folder name (code + local timestamp). */ export declare const SESSION_FOLDER_RE: RegExp; /** Generate a cryptographically random 6-digit hexadecimal code. */ export declare function generateSessionCode(): string; export declare function isValidSessionCode(code: string): boolean; export declare function isValidSessionFolderName(name: string): boolean; /** * Build `{code}-{DD}-{MM}-{YYYY}-{HH}-{MM}-{SS}` using local time. * Example: `a3f9c1-25-08-2003-22-45-56`. */ export declare function formatSessionFolderName(code: string, at?: Date): string; /** Parent of all session workspaces: `{tmpdir}/clai`. */ export declare function getSessionWorkspaceParent(): string; export declare function sessionWorkspaceRoot(folderName: string): string; export declare function sessionTempDir(folderName: string): string; /** Create root + temp directories (idempotent, cross-platform). */ export declare function ensureSessionWorkspaceDirs(ws: SessionWorkspace): void; /** * Mint a new unique session workspace. Retries the 6-hex code if the * folder name already exists for the same second (astronomically rare). */ export declare function mintSessionWorkspace(at?: Date): SessionWorkspace; /** * Restore a previously persisted workspace. Recreates dirs if the OS * cleaned temp; accepts a folder name even when the code field is missing * (older partial records) by parsing the leading 6 hex digits. */ export declare function restoreSessionWorkspace(folderName: string, code?: string | undefined): SessionWorkspace; export declare function getActiveSessionWorkspace(): SessionWorkspace | undefined; export declare function bindSessionWorkspace(ws: SessionWorkspace): SessionWorkspace; /** * Start (or rebind) the active session workspace. * - With a prior folder name → restore/recreate that session's dirs. * - Without → mint a fresh unique workspace. */ export declare function beginSessionWorkspace(existing?: { folderName?: string | undefined; code?: string | undefined; }): SessionWorkspace; /** Drop the active binding (tests / process teardown). Does not delete files. */ export declare function clearActiveSessionWorkspace(): void; export declare function removeSessionWorkspaceFolder(folderName: string): boolean; /** Absolute scratch root for the active session, if any. */ export declare function getActiveSessionScratchDir(): string | undefined; /** Absolute tool-output dir for the active session, if any. */ export declare function getActiveSessionTempDir(): string | undefined; /** * True when `path` lives under the session workspace parent (`…/clai/`). * Used by cleanup and safety checks. */ export declare function isUnderSessionWorkspaceParent(path: string): boolean;