/** * RetentionPolicyService - Generic retention policy enforcement (Issue #51) * * This service manages retention policies across ALL element types, ensuring that: * 1. Nothing is auto-deleted without explicit user consent * 2. Users have full visibility into what would be deleted * 3. Each element type can have its own retention strategy * 4. Compliance use cases (legal, GDPR, etc.) are supported when enabled * * IMPORTANT: Retention enforcement is DISABLED by default. * Users must explicitly enable it in config.yml if they want automatic cleanup. * * Architecture: * - This service is element-type agnostic * - Element-specific logic is delegated to IRetentionStrategy implementations * - Strategies are registered per element type * - Designed to support 50+ element types * * @module RetentionPolicyService */ import { ConfigManager, RetentionPolicyConfig } from '../../config/ConfigManager.js'; import { ElementType } from '../../portfolio/types.js'; import { IRetentionStrategy, IRetainableItem, ElementRetentionConfig, RetentionEnforcementResult, RetentionSummary, EnforcementOptions } from './types.js'; /** * Generic retention policy service supporting multiple element types */ export declare class RetentionPolicyService { private configManager; private strategies; constructor(configManager: ConfigManager); /** * Register a retention strategy for an element type * Call this during DI setup for each element type that supports retention */ registerStrategy(strategy: IRetentionStrategy): void; /** * Get the strategy for an element type */ getStrategy(elementType: ElementType | string): IRetentionStrategy | undefined; /** * Get registered element types */ getRegisteredTypes(): string[]; /** * Get the global retention policy configuration */ getGlobalConfig(): RetentionPolicyConfig; /** * Get retention configuration for a specific element type * Merges global defaults with any type-specific overrides */ getElementConfig(elementType: ElementType | string): ElementRetentionConfig; /** * Check if retention enforcement is globally enabled */ isEnabled(): boolean; /** * Check if enforcement should happen on load for a given element type */ shouldEnforceOnLoad(elementType?: ElementType | string): boolean; /** * Check if enforcement requires confirmation */ requiresConfirmation(): boolean; /** * Check if dry run should be performed first */ shouldDryRunFirst(): boolean; /** * Check items for retention status without modifying anything * Works with any element type that has a registered strategy */ checkItems(elementType: ElementType | string, items: Map): RetentionSummary; /** * Preview what would be deleted (dry run) * Works with any element type */ preview(elementType: ElementType | string, element: unknown): RetentionEnforcementResult; /** * Enforce retention policy on an element * Works with any element type that has a registered strategy * * @param elementType - The type of element (e.g., 'memory', 'agent') * @param element - The element instance to enforce retention on * @param options - Enforcement options including force, failFast, and callbacks * @returns Result including items checked/removed, affected items, and any warnings * * ## Partial Failure Behavior * * By default, the method continues processing after individual item removal failures: * - Failed items are logged and added to `result.warnings[]` * - Successfully removed items are counted in `result.itemsRemoved` * - `result.success` remains true unless all items fail * * This allows maximum cleanup even when some items cannot be removed (e.g., file locks). * * ### Atomic Mode (failFast: true) * * For scenarios requiring all-or-nothing behavior, use `options.failFast: true`: * - Stops immediately on first removal error * - Sets `result.success = false` and `result.error` with details * - No further items are processed after the failure * * **WARNING**: With failFast, any items removed before the failure will NOT be rolled back. * True transactional semantics are not supported. * * @example * // Default: continue on errors * const result = await service.enforce('memory', myMemory, { force: true }); * if (result.warnings.length > 0) console.log('Some items failed:', result.warnings); * * @example * // Fail fast: stop on first error * const result = await service.enforce('memory', myMemory, { force: true, failFast: true }); * if (!result.success) console.log('Failed:', result.error); */ enforce(elementType: ElementType | string, element: unknown, options?: EnforcementOptions): Promise; /** * Get a human-readable status message about retention */ getStatusMessage(elementType?: ElementType | string): string; /** * Normalize element type to consistent string key * SECURITY: Applies Unicode normalization to prevent bypass attacks */ private normalizeElementType; } //# sourceMappingURL=RetentionPolicyService.d.ts.map