/** * Orphan cleanup logic extracted from index.ts. * * Scans session-tracker directory for orphan child session directories * and moves them to quarantine (instead of deleting). Integrates with * OrphanQuarantine protocol. * * @module session-tracker/orphan-cleanup */ import type { OpenCodeClient } from "../../shared/session-api.js"; import type { HierarchyIndex } from "./persistence/hierarchy-index.js"; import type { SessionRouter } from "./session-router.js"; import type { OrphanQuarantine } from "./persistence/orphan-quarantine.js"; /** * Result of an orphan cleanup operation. */ export interface OrphanCleanupResult { /** Session IDs that were quarantined. */ quarantined: string[]; /** Session IDs that were skipped (not orphans). */ skipped: number; /** Errors encountered during cleanup. */ errors: string[]; } /** * Manages detection and quarantine of orphan child session directories. */ export declare class OrphanCleanup { private client; private projectRoot; private hierarchyIndex; private sessionRouter; private quarantine; /** * @param deps - Injected dependencies. */ constructor(deps: { client: OpenCodeClient; projectRoot: string; hierarchyIndex?: HierarchyIndex; sessionRouter: SessionRouter; quarantine: OrphanQuarantine; }); /** * Checks whether a session has a continuity tree entry on disk. * Returns true if session-continuity.json exists for the session. * * G-6 guardrail: prevents quarantining legitimate children that * happen to have continuity tree entries but are classified as orphans. * * @param sessionID - The session identifier to check. * @returns True if continuity file exists. */ private checkContinuityTree; /** * Scans for and quarantines orphan child session directories. * * An orphan is a directory whose session ID is classified as a child * in the hierarchy index. Instead of deleting, directories are moved * to the quarantine directory for auditability. * * Enhanced checks: * - HierarchyIndex.isChild() check (primary) * - Missing session-continuity.json + classified as child (secondary fallback) * - Manifest verification before quarantining * - Audit logging with reason for each action * * Best-effort: individual failures are silently skipped. * * @returns Result summary with quarantined count and errors. */ cleanupOrphanDirectories(): Promise; /** * Preserves nested child records from an orphan child directory before it is * moved to quarantine. * * If an L1 child incorrectly has its own `session-continuity.json`, its L2 * child records are merged into the root main session hierarchy and manifest. * Any child `.json` files found in the orphan directory are moved into the * root main directory. This prevents cleanup from erasing delegated-session * history that should have lived under the root main session all along. * * @param orphanSessionID - Child session directory being quarantined. */ private preserveOrphanHierarchy; /** * Moves a child JSON record from an orphan child directory into root main. * Existing root records are preserved and never overwritten. * * @param orphanSessionID - Orphan directory session ID. * @param rootMainSessionID - Root main directory owner. * @param childFile - Child JSON filename. */ private moveChildJsonToRoot; /** * Reads and parses a JSON file, returning undefined on any error. * * @param filePath - JSON file path. */ private readJson; /** * Creates a default root session continuity index. * * @param sessionID - Root main session ID. */ private createDefaultIndex; /** * Creates a default root hierarchy manifest. * * @param rootMainSessionID - Root main session ID. */ private createDefaultManifest; /** * Removes orphaned `*.tmp.*` files from the session-tracker root. * * These accumulate when writes are interrupted (process killed between * writeFile and rename in atomicWriteJson/atomicAppendMarkdown). * Safe to remove — they're atomic-write intermediates, never the * authoritative file. */ cleanupOrphanedTmpFiles(): Promise; } //# sourceMappingURL=orphan-cleanup.d.ts.map