@dollhousemcp/mcp-server
Version:
DollhouseMCP - A Model Context Protocol (MCP) server that enables dynamic AI persona management from markdown files, allowing Claude and other compatible AI assistants to activate and switch between different behavioral personas.
128 lines • 4.19 kB
TypeScript
/**
* Pattern Extraction for Memory Security
*
* Part of Issue #1314 Phase 1: Memory Security Architecture
* Enhanced in Issue #1321 Phase 2: Pattern Encryption
*
* PURPOSE:
* Identifies and extracts dangerous patterns from memory content for
* sanitized display with AES-256-GCM encryption (Phase 2).
*
* PHASE 1 SCOPE:
* - Identify pattern locations in content
* - Generate pattern metadata (severity, description, location)
* - Create sanitized content with pattern references
* - Prepare structure for Phase 2 encryption
*
* PHASE 2 SCOPE:
* - AES-256-GCM encryption of extracted patterns
* - Key derivation from system secret
* - Secure pattern storage and retrieval
* - GCM authentication tags for integrity
*
* REFACTOR NOTE:
* Converted from static class to instance-based for DI architecture compatibility.
* PatternExtractor now requires PatternEncryptor dependency injected via constructor
* for proper lifecycle management and testability.
*
* @module PatternExtractor
*/
import type { ContentValidationResult } from '../contentValidator.js';
import type { SanitizedPattern } from './BackgroundValidator.js';
import { PatternEncryptor } from '../encryption/PatternEncryptor.js';
/**
* Pattern match information from validation
*/
export interface PatternMatch {
/** The actual pattern text that was matched */
pattern: string;
/** The type/category of pattern */
type: string;
/** Severity level */
severity: 'critical' | 'high' | 'medium' | 'low';
/** Start position in content */
startOffset: number;
/** Length of the pattern */
length: number;
/** Human-readable description */
description: string;
}
/**
* Result of pattern extraction
*/
export interface ExtractionResult {
/** Sanitized content with pattern references */
sanitizedContent: string;
/** Extracted pattern metadata */
patterns: SanitizedPattern[];
/** Number of patterns extracted */
patternCount: number;
}
/**
* PatternExtractor service
*
* Extracts dangerous patterns from memory content and creates
* sanitized versions suitable for display to LLMs.
*
* DI-COMPATIBLE: Instance-based service for dependency injection.
*/
export declare class PatternExtractor {
private readonly encryptor;
private patternCounter;
/**
* Create a new PatternExtractor instance
*
* @param encryptor - PatternEncryptor instance for encrypting extracted patterns
*/
constructor(encryptor: PatternEncryptor);
/**
* Extract patterns from content based on validation results
*
* @param content - Original content containing patterns
* @param validationResult - Validation result with detected patterns
* @returns Extraction result with sanitized content and pattern metadata
*/
extractPatterns(content: string, validationResult: ContentValidationResult): ExtractionResult;
/**
* Find all pattern matches in content
*
* This uses heuristics to locate the detected patterns within the content.
* The ContentValidator tells us what patterns were detected, but not where.
* We need to search for them.
*/
private findPatternMatches;
/**
* Search for a specific pattern type in content
*
* Uses common patterns and heuristics to locate dangerous content
*/
private searchForPattern;
/**
* Create a sanitized pattern object with metadata
*
* Phase 2: Now encrypts patterns using AES-256-GCM
*/
private createSanitizedPattern;
/**
* Create sanitized content by replacing patterns with references
*/
private createSanitizedContent;
/**
* Get human-readable description for a pattern type
*/
private getPatternDescription;
/**
* Get safety instruction based on severity
*/
private getSafetyInstruction;
/**
* Reset the pattern counter (useful for testing)
*/
resetCounter(): void;
/**
* Dispose of the extractor and clean up resources
* Implements cleanup for proper DI lifecycle management
*/
dispose(): Promise<void>;
}
//# sourceMappingURL=PatternExtractor.d.ts.map