/** * Context Tracking for LLM Request Detection * * Part of Issue #1321 Phase 2: Memory Security Architecture * * PURPOSE: * Tracks execution context to detect if code is running within an LLM request * handler. Uses AsyncLocalStorage to maintain context across async operations. * * SECURITY: * - Prevents pattern decryption in LLM contexts * - Ensures patterns never leak to LLM responses * - Provides audit trail for context checks * * REFACTOR NOTE: * Converted from static class to instance-based for DI architecture compatibility. * ContextTracker now uses instance methods instead of static methods, allowing * proper lifecycle management and testability within DI container. * * @module ContextTracker */ /** * Execution context information */ export interface ExecutionContext { /** Context type (llm-request, background-task, test, etc.) */ type: 'llm-request' | 'background-task' | 'test' | 'unknown'; /** Request ID for correlation */ requestId?: string; /** Timestamp when context was created */ timestamp: number; /** Additional context metadata */ metadata?: Record; } /** * Context tracker using AsyncLocalStorage * * Maintains execution context across async operations to detect * LLM request handling and prevent pattern decryption in those contexts. * * DI-COMPATIBLE: Instance-based service for dependency injection. */ export declare class ContextTracker { private readonly storage; /** * Create a new ContextTracker instance */ constructor(); /** * Run a function within a specific execution context * * @param context - Execution context to set * @param fn - Function to run within the context * @returns Result of the function */ run(context: ExecutionContext, fn: () => T): T; /** * Run an async function within a specific execution context * * @param context - Execution context to set * @param fn - Async function to run within the context * @returns Promise resolving to the function result */ runAsync(context: ExecutionContext, fn: () => Promise): Promise; /** * Get the current execution context * * @returns Current context or undefined if no context is set */ getContext(): ExecutionContext | undefined; /** * Check if currently in an LLM request context * * @returns true if in LLM request context, false otherwise */ isLLMContext(): boolean; /** * Create a new execution context object * * @param type - Context type * @param metadata - Optional metadata * @returns New execution context */ createContext(type: ExecutionContext['type'], metadata?: Record): ExecutionContext; /** * Generate a unique request ID using cryptographically secure random bytes * * @returns Unique request ID */ private generateRequestId; /** * Get the current correlation ID (request-level identifier). * Returns undefined when no context is active (e.g. background timers). */ getCorrelationId(): string | undefined; /** * Clear the current context (useful for testing) */ clearContext(): void; /** * Dispose of the context tracker and clean up resources * Implements cleanup for proper DI lifecycle management */ dispose(): Promise; } //# sourceMappingURL=ContextTracker.d.ts.map