/** * Copyright (c) 2025 Elara AI Pty Ltd * Licensed under BSL 1.1. See LICENSE for details. */ import type { RepoStore, GcObjectEntry, StorageBackend } from '../interfaces.js'; /** * Options for garbage collection */ export interface GcOptions { /** * Minimum age in milliseconds for files to be considered for deletion. * Files younger than this are skipped to avoid race conditions with concurrent writes. * Default: 60000 (1 minute) */ minAge?: number; /** * If true, only report what would be deleted without actually deleting. * Default: false */ dryRun?: boolean; } /** * Result of garbage collection */ export interface GcResult { /** Number of objects deleted */ deletedObjects: number; /** Number of orphaned staging files deleted */ deletedPartials: number; /** Number of objects retained */ retainedObjects: number; /** Number of files skipped due to being too young */ skippedYoung: number; /** Total bytes freed */ bytesFreed: number; } /** * Result from sweepBatch — pure decision, no side effects. */ export interface SweepBatchResult { /** Hashes of objects to delete */ toDelete: string[]; /** Number of objects retained (reachable) */ retained: number; /** Number of objects skipped due to being too young */ skippedYoung: number; /** Total bytes that would be freed */ bytesFreed: number; } /** * Collect all root hashes from packages, workspaces, and executions. * * Calls each gcScan*Roots method with pagination support. * Adding a new root scan method to RepoStore requires updating this function. */ export declare function collectAllRoots(store: RepoStore, repo: string): Promise>; /** * Trace the object graph from roots using iterative DFS with schema-aware traversal. * * Decodes each object using BEAST2 self-describing format and extracts child * hashes based on the detected object type (Package, Task, or Tree). Objects * known to be leaves (values, IR blobs) are marked reachable without reading. * * @param readObject - Function to read an object by hash (returns null if missing) * @param roots - Set of root hashes to start from * @returns Set of all reachable hashes */ export declare function markReachable(readObject: (hash: string) => Promise, roots: Set): Promise>; /** * Pure decision function: determine which objects to delete. * * No side effects — trivially testable. Caller decides whether to * actually delete (supports dry-run by skipping gcDeleteObjects). * * @param objects - Object entries from gcScanObjects * @param reachable - Set of reachable hashes from markReachable * @param minAge - Minimum age in ms; objects younger than this are skipped * @returns Decision result with toDelete list and stats */ export declare function sweepBatch(objects: GcObjectEntry[], reachable: Set, minAge: number): SweepBatchResult; /** * Run garbage collection on an e3 repository. * * Works with any StorageBackend — no instanceof checks. * * @param storage - Storage backend * @param repo - Repository identifier * @param options - GC options * @returns GC result with statistics */ export declare function repoGc(storage: StorageBackend, repo: string, options?: GcOptions): Promise; //# sourceMappingURL=gc.d.ts.map