@vfarcic/dot-ai
Version:
AI-powered development productivity platform that enhances software development workflows through intelligent automation and AI-driven assistance
114 lines (113 loc) • 3.65 kB
JavaScript
;
/**
* Memory System Module
*
* Handles learning, context management, and recommendation storage
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.MemorySystem = void 0;
class MemorySystem {
storage = new Map();
successPatterns = new Map();
failurePatterns = new Map();
context = new Map();
initialized = false;
async initialize() {
// Initialize storage (in production, this would connect to persistent storage)
this.initialized = true;
}
async store(key, data) {
this.storage.set(key, data);
}
async retrieve(key) {
return this.storage.get(key) || null;
}
async learnSuccess(type, config) {
const pattern = {
type,
config,
timestamp: new Date()
};
const existing = this.successPatterns.get(type) || [];
existing.push(pattern);
this.successPatterns.set(type, existing);
}
async learnFailure(type, config, error) {
const pattern = {
type,
config,
error,
timestamp: new Date()
};
const existing = this.failurePatterns.get(type) || [];
existing.push(pattern);
this.failurePatterns.set(type, existing);
}
async getSuccessPatterns(type) {
return this.successPatterns.get(type) || [];
}
async getFailurePatterns(type) {
return this.failurePatterns.get(type) || [];
}
async getRecommendations(type, partialConfig) {
const successPatterns = await this.getSuccessPatterns(type);
const recommendations = [];
// Simple recommendation algorithm
for (const pattern of successPatterns) {
const similarity = this.calculateSimilarity(partialConfig, pattern.config);
if (similarity >= 0.5) {
recommendations.push({
suggestion: `Consider using configuration similar to successful ${type}`,
confidence: similarity,
based_on: [`Success pattern from ${pattern.timestamp.toISOString()}`]
});
}
}
return recommendations;
}
async storePattern(type, pattern) {
// Store pattern as a success by default
await this.learnSuccess(type, pattern);
}
async retrievePattern(type) {
const patterns = await this.getSuccessPatterns(type);
return patterns.map(p => p.config);
}
async storeLessons(type, lessons) {
// Store lessons in the general storage
await this.store(`lessons-${type}`, lessons);
}
calculateSimilarity(config1, config2) {
// Simple similarity calculation
const keys1 = Object.keys(config1);
const keys2 = Object.keys(config2);
const commonKeys = keys1.filter(key => keys2.includes(key));
if (keys1.length === 0 && keys2.length === 0)
return 1;
if (keys1.length === 0 || keys2.length === 0)
return 0;
return commonKeys.length / Math.max(keys1.length, keys2.length);
}
async setContext(key, value) {
this.context.set(key, value);
}
async getContext() {
const result = {};
for (const [key, value] of this.context.entries()) {
result[key] = value;
}
return result;
}
async clearContext(key) {
if (key) {
this.context.delete(key);
}
else {
this.context.clear();
}
}
isInitialized() {
return this.initialized;
}
}
exports.MemorySystem = MemorySystem;