import type { CleanupPolicy } from './config'; export declare const TEAMSHARE_DIR: string; export declare const DEFAULT_CLEANUP_POLICY: { readonly enabled: true; readonly intervalHours: 6; /** * How often the cheap mirror-lease sweep runs (2026-09). The full sweep is * expensive - `noteWorktrees` walks every worktree synchronously on the * daemon's event loop - which is why it stays at 6h. But an orphaned mirror * (created by a wake that then decided not to run) used to wait for that * whole window: 5 worktrees and ~45 MB sitting on the user's disk for six * hours. The lease sweep reads one small JSON file per task and only touches * git when it is actually reclaiming, so it can run every 30 minutes. */ readonly mirrorSweepMinutes: 30; readonly sessionMaxAgeDays: 14; readonly sessionMaxSizeMb: 200; readonly logMaxSizeMb: 10; readonly tempMaxAgeDays: 7; readonly reposMaxAgeDays: 30; readonly reposMaxSizeMb: 2048; }; export type ResolvedCleanupPolicy = { enabled: boolean; intervalHours: number; mirrorSweepMinutes: number; sessionMaxAgeMs: number; sessionMaxSizeBytes: number; logMaxSizeBytes: number; tempMaxAgeMs: number; reposMaxAgeMs: number; reposMaxSizeBytes: number; }; export declare function resolveCleanupPolicy(raw?: CleanupPolicy): ResolvedCleanupPolicy; export interface CleanupTargetReport { target: string; filesDeleted: number; bytesFreed: number; errors: string[]; } export interface CleanupReport { dryRun: boolean; totalFiles: number; totalBytes: number; targets: CleanupTargetReport[]; /** Report-only observations (worktrees) - nothing was deleted. */ notes: string[]; } /** * HOW LONG A REPORT-ONLY SIZE WALK MAY RUN (2026-11-11). * * `dirSizeBytes` above is exact and UNBOUNDED, which is fine for a directory * the sweep is about to delete anyway, and catastrophic for a REPORT: one * `dirSizeBytes` per task worktree means stat() on every file of every * checkout, node_modules included. Measured on this machine: 943 MB / * 59,617 files = 25.7 s, and the worktree roots held ~5.8 GB - so the boot * sweep spent ~176 s in ONE synchronous call while the daemon was already * listening. Two boots in a row logged `[auto-upgrade] enabled` and then went * completely silent for 3 minutes: `/ping` could not answer (the event loop was * pinned), every agent socket timed out, and `teamshare-bridge status` honestly * reported "daemon not answering on it" for a daemon that was alive and busy. * * The size total is decoration ("here is how much disk these trees use"). It * must never cost the daemon its responsiveness, so the walk is DEADLINE * BOUNDED and reports `>=` when it stopped early. */ export declare const REPORT_SIZE_WALK_BUDGET_MS = 1200; interface SizeWalk { bytes: number; /** The deadline hit before the tree was fully measured. */ truncated: boolean; } /** * `dirSizeBytes`, but it gives up when `deadlineAt` (ms epoch) passes. * Checks the clock every 256 entries so the check itself is not the cost. * * Exported for `tests/boot-responsiveness.test.mjs`: the budget is the whole * point of this function and an unbudgeted regression is invisible in a build. */ export declare function dirSizeBytesWithin(dir: string, deadlineAt: number): SizeWalk; /** * Cheap mirror-lease sweep (2026-09) - the FAST pass. * * Reclaims only mirrors the daemon created and then never handed to a session * (a wake that built a mirror and was then skipped, or a spawn that threw). * These are the leaks that used to sit for a full 6h cleanup window; there is * no live work in them by definition, so removal is safe, and * `detachIsolationMirror` is still rescue-first (a dirty tree is committed to * the TASK branch before removal, never dropped). * * Deliberately NOT handled here: * - `keptForRetry` trees (a failed run's work) - the 6h pass owns those, so a * retry has a predictable window to adopt them. * - anything with a live pid or a live presence entry. * * Cheap by construction: one small JSON read per task, and git is only invoked * when a tree is actually reclaimed. No directory size walk. */ export declare function runMirrorLeaseSweep(opts?: { log?: (text: string) => void; }): Promise<{ reclaimed: number; kept: number; prunedLeases: number; }>; export interface RunCleanupOptions { dryRun?: boolean; /** Linked project folders (for worktree reporting). */ projectPaths?: string[]; /** Agent registry: config.agents ([{ agentId }] is enough). */ agents?: Array<{ agentId: string; }>; log?: (text: string) => void; } /** * Runs every cleanup rule. Never throws. */ export declare function runCleanup(policyRaw: CleanupPolicy | undefined, opts?: RunCleanupOptions): Promise; export {};