Title
Implement Memory History Storage Service with Database Backend Integration
Description
Create a dedicated storage service for tracking memory operations history using the existing storage backend
infrastructure. This service will provide persistence for memory operation audit trails with support for
multi-tenant and project-scoped storage.
Background
The cipher project needs to track memory operations for audit trails, analytics, and debugging purposes. The
implementation should leverage the existing dual-backend storage architecture (cache + database) and follow
established patterns in src/core/storage/.
Requirements
- Support for SQLite and PostgreSQL backends
- Integration with existing StorageManager
- Efficient querying and filtering capabilities
- Thread-safe operations
- Proper error handling following existing patterns
Implementation Details
Files to Create
- src/core/storage/memory-history/index.ts - Main service export
- src/core/storage/memory-history/service.ts - Core service implementation
- src/core/storage/memory-history/types.ts - Type definitions
- src/core/storage/memory-history/schema.ts - Database schema definitions
Database Schema
interface MemoryHistoryEntry {
id: string; // Unique identifier (UUID)
projectId: string; // Project scope identifier
memoryId: string; // Reference to memory entry
name: string; // Descriptive operation name
tags: string[]; // Categorization tags
userId?: string; // User identifier (optional)
operation: MemoryOperation; // Operation type
timestamp: string; // ISO timestamp
metadata: Record<string, any>; // Flexible metadata storage
success: boolean; // Operation success status
error?: string; // Error details if failed
sessionId?: string; // Session correlation
duration?: number; // Operation duration in ms
}
type MemoryOperation = 'ADD' | 'UPDATE' | 'DELETE' | 'SEARCH' | 'RETRIEVE';
Service Interface
interface MemoryHistoryService {
// Core operations
recordOperation(entry: MemoryHistoryEntry): Promise;
getHistory(filters: HistoryFilters): Promise<MemoryHistoryEntry[]>;
// Query operations
getByProjectId(projectId: string, options?: QueryOptions): Promise<MemoryHistoryEntry[]>;
getByUserId(userId: string, options?: QueryOptions): Promise<MemoryHistoryEntry[]>;
getByTags(tags: string[], options?: QueryOptions): Promise<MemoryHistoryEntry[]>;
getByTimeRange(startTime: string, endTime: string, options?: QueryOptions): Promise<MemoryHistoryEntry[]>;
// Analytics
getOperationStats(projectId?: string, userId?: string): Promise<OperationStats>;
getSuccessRate(projectId?: string, userId?: string): Promise<number>;
// Connection management
connect(): Promise<void>;
disconnect(): Promise<void>;
isConnected(): boolean;
}
Acceptance Criteria
- Service implements all required interface methods
- Database schema supports all required fields
- Integration with existing storage manager works
- Supports filtering by projectId, userId, tags, timeRange
- Proper error handling with existing error types
- Performance optimized for high-frequency operations
- Connection management follows existing patterns
- Thread-safe operations
Testing Requirements
- Unit tests for all service methods
- Integration tests with SQLite backend
- Integration tests with PostgreSQL backend
- Performance tests for high-volume operations
- Error handling test scenarios
- Concurrent access tests
Title
Implement Memory History Storage Service with Database Backend Integration
Description
Create a dedicated storage service for tracking memory operations history using the existing storage backend
infrastructure. This service will provide persistence for memory operation audit trails with support for
multi-tenant and project-scoped storage.
Background
The cipher project needs to track memory operations for audit trails, analytics, and debugging purposes. The
implementation should leverage the existing dual-backend storage architecture (cache + database) and follow
established patterns in src/core/storage/.
Requirements
Implementation Details
Files to Create
Database Schema
interface MemoryHistoryEntry {
id: string; // Unique identifier (UUID)
projectId: string; // Project scope identifier
memoryId: string; // Reference to memory entry
name: string; // Descriptive operation name
tags: string[]; // Categorization tags
userId?: string; // User identifier (optional)
operation: MemoryOperation; // Operation type
timestamp: string; // ISO timestamp
metadata: Record<string, any>; // Flexible metadata storage
success: boolean; // Operation success status
error?: string; // Error details if failed
sessionId?: string; // Session correlation
duration?: number; // Operation duration in ms
}
type MemoryOperation = 'ADD' | 'UPDATE' | 'DELETE' | 'SEARCH' | 'RETRIEVE';
Service Interface
interface MemoryHistoryService {
// Core operations
recordOperation(entry: MemoryHistoryEntry): Promise;
getHistory(filters: HistoryFilters): Promise<MemoryHistoryEntry[]>;
}
Acceptance Criteria
Testing Requirements