UNPKG

gemini-code-flow

Version:

AI-powered development orchestration for Gemini CLI - adapted from Claude Code Flow by ruvnet

107 lines 3.61 kB
"use strict"; /** * Memory Manager for Gemini Code Flow * Adapted from Claude Code Flow by ruvnet */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.MemoryManager = void 0; const fs_extra_1 = __importDefault(require("fs-extra")); const path_1 = __importDefault(require("path")); class MemoryManager { memoryPath; cache = new Map(); initialized = false; constructor(memoryPath) { this.memoryPath = memoryPath; } /** * Initialize the memory manager */ async initialize() { if (this.initialized) return; // Ensure directory exists await fs_extra_1.default.ensureDir(path_1.default.dirname(this.memoryPath)); // Load existing memory if (await fs_extra_1.default.pathExists(this.memoryPath)) { try { const data = await fs_extra_1.default.readJson(this.memoryPath); Object.entries(data).forEach(([key, entries]) => { this.cache.set(key, entries); }); } catch (error) { console.warn('Failed to load memory:', error instanceof Error ? error.message : 'Unknown error'); } } this.initialized = true; } /** * Store a memory entry */ async store(entry) { const memoryEntry = { id: `mem-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, timestamp: new Date(), ...entry, }; const key = entry.agentId || 'global'; const entries = this.cache.get(key) || []; entries.push(memoryEntry); this.cache.set(key, entries); // Auto-save periodically this.scheduleSave(); } /** * Get context for a specific mode */ async getContext(mode) { const allEntries = Array.from(this.cache.values()).flat(); return allEntries .filter(entry => entry.tags.includes(mode)) .sort((a, b) => b.timestamp.getTime() - a.timestamp.getTime()) .slice(0, 10) // Last 10 relevant entries .map(entry => ({ type: entry.type, summary: typeof entry.content === 'string' ? entry.content.substring(0, 200) + '...' : JSON.stringify(entry.content).substring(0, 200) + '...', timestamp: entry.timestamp, })); } /** * Search memory entries */ async search(query, tags) { const allEntries = Array.from(this.cache.values()).flat(); return allEntries.filter(entry => { const contentMatch = JSON.stringify(entry.content).toLowerCase().includes(query.toLowerCase()); const tagsMatch = !tags || tags.some(tag => entry.tags.includes(tag)); return contentMatch && tagsMatch; }); } /** * Flush memory to disk */ async flush() { const data = Object.fromEntries(this.cache.entries()); await fs_extra_1.default.writeJson(this.memoryPath, data, { spaces: 2 }); } /** * Schedule periodic saves */ scheduleSave() { if (this.saveTimeout) return; this.saveTimeout = setTimeout(async () => { await this.flush(); this.saveTimeout = null; }, 5000); // Save every 5 seconds } saveTimeout = null; } exports.MemoryManager = MemoryManager; //# sourceMappingURL=memory-manager.js.map