UNPKG

cortexweaver

Version:

CortexWeaver is a command-line interface (CLI) tool that orchestrates a swarm of specialized AI agents, powered by Claude Code and Gemini CLI, to assist in software development. It transforms a high-level project plan (plan.md) into a series of coordinate

79 lines 2.65 kB
"use strict"; /** * Advanced Caching and Memory Management for Cognitive Canvas Navigator */ Object.defineProperty(exports, "__esModule", { value: true }); exports.CacheManager = void 0; class CacheManager { constructor() { this.cache = new Map(); this.maxCacheSize = 200; this.defaultTTL = 300000; this.cacheHits = 0; this.cacheMisses = 0; } getAdvancedCachedResult(key) { const entry = this.cache.get(key); if (!entry) { this.cacheMisses++; return null; } if (Date.now() - entry.timestamp > entry.ttl) { this.cache.delete(key); this.cacheMisses++; return null; } entry.accessCount++; entry.timestamp = Date.now(); this.cacheHits++; return entry.result; } storeIntelligentCache(key, result, cost) { if (this.cache.size >= this.maxCacheSize) { this.performIntelligentEviction(); } const ttl = Math.min(this.defaultTTL, cost * 1000 + 60000); const entry = { result, timestamp: Date.now(), ttl, accessCount: 1, cost }; this.cache.set(key, entry); } performIntelligentEviction() { const entries = Array.from(this.cache.entries()); const scored = entries.map(([key, entry]) => ({ key, score: this.calculateEvictionScore(entry) })); scored.sort((a, b) => a.score - b.score); const toRemove = Math.floor(this.maxCacheSize * 0.25); for (let i = 0; i < toRemove; i++) { this.cache.delete(scored[i].key); } } calculateEvictionScore(entry) { const age = Date.now() - entry.timestamp; const frequency = entry.accessCount; const cost = entry.cost; return (age / 1000) - (frequency * 10) - (cost * 5); } getCacheMetrics() { const totalQueries = this.cacheHits + this.cacheMisses; return { cacheHitRatio: totalQueries > 0 ? this.cacheHits / totalQueries : 0, cacheSize: this.cache.size, memoryUsage: this.cache.size * 1024 }; } generateOptimizedCacheKey(query) { const queryHash = Buffer.from(query.query).toString('base64').slice(0, 10); const contextHash = query.context ? Buffer.from(JSON.stringify(query.context)).toString('base64').slice(0, 8) : ''; return `${query.type}:${queryHash}:${contextHash}`; } } exports.CacheManager = CacheManager; //# sourceMappingURL=cache-manager.js.map