agentic-flow 1.7.3 → 1.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/.claude/agents/test-neural.md +0 -5
  2. package/.claude/answer.md +1 -0
  3. package/.claude/settings.json +19 -20
  4. package/CHANGELOG.md +0 -117
  5. package/README.md +17 -81
  6. package/dist/agentdb/benchmarks/comprehensive-benchmark.js +664 -0
  7. package/dist/agentdb/benchmarks/frontier-benchmark.js +419 -0
  8. package/dist/agentdb/benchmarks/reflexion-benchmark.js +370 -0
  9. package/dist/agentdb/cli/agentdb-cli.js +717 -0
  10. package/dist/agentdb/controllers/CausalMemoryGraph.js +322 -0
  11. package/dist/agentdb/controllers/CausalRecall.js +281 -0
  12. package/dist/agentdb/controllers/EmbeddingService.js +118 -0
  13. package/dist/agentdb/controllers/ExplainableRecall.js +387 -0
  14. package/dist/agentdb/controllers/NightlyLearner.js +382 -0
  15. package/dist/agentdb/controllers/ReflexionMemory.js +239 -0
  16. package/dist/agentdb/controllers/SkillLibrary.js +276 -0
  17. package/dist/agentdb/controllers/frontier-index.js +9 -0
  18. package/dist/agentdb/controllers/index.js +8 -0
  19. package/dist/agentdb/index.js +32 -0
  20. package/dist/agentdb/optimizations/BatchOperations.js +198 -0
  21. package/dist/agentdb/optimizations/QueryOptimizer.js +225 -0
  22. package/dist/agentdb/optimizations/index.js +7 -0
  23. package/dist/agentdb/tests/frontier-features.test.js +665 -0
  24. package/dist/cli-proxy.js +2 -33
  25. package/dist/mcp/standalone-stdio.js +200 -4
  26. package/dist/memory/SharedMemoryPool.js +211 -0
  27. package/dist/memory/index.js +6 -0
  28. package/dist/reasoningbank/AdvancedMemory.js +239 -0
  29. package/dist/reasoningbank/HybridBackend.js +305 -0
  30. package/dist/reasoningbank/index-new.js +87 -0
  31. package/dist/reasoningbank/index.js +23 -44
  32. package/dist/utils/cli.js +0 -22
  33. package/docs/AGENTDB_TESTING.md +411 -0
  34. package/docs/v1.7.1-QUICK-START.md +399 -0
  35. package/package.json +4 -4
  36. package/scripts/run-validation.sh +165 -0
  37. package/scripts/test-agentdb.sh +153 -0
  38. package/.claude/skills/agentdb-memory-patterns/SKILL.md +0 -166
  39. package/.claude/skills/agentdb-vector-search/SKILL.md +0 -126
  40. package/.claude/skills/agentic-flow/agentdb-memory-patterns/SKILL.md +0 -166
  41. package/.claude/skills/agentic-flow/agentdb-vector-search/SKILL.md +0 -126
  42. package/.claude/skills/agentic-flow/reasoningbank-intelligence/SKILL.md +0 -201
  43. package/.claude/skills/agentic-flow/swarm-orchestration/SKILL.md +0 -179
  44. package/.claude/skills/reasoningbank-intelligence/SKILL.md +0 -201
  45. package/.claude/skills/skill-builder/README.md +0 -308
  46. package/.claude/skills/skill-builder/SKILL.md +0 -910
  47. package/.claude/skills/skill-builder/docs/SPECIFICATION.md +0 -358
  48. package/.claude/skills/skill-builder/resources/schemas/skill-frontmatter.schema.json +0 -41
  49. package/.claude/skills/skill-builder/resources/templates/full-skill.template +0 -118
  50. package/.claude/skills/skill-builder/resources/templates/minimal-skill.template +0 -38
  51. package/.claude/skills/skill-builder/scripts/generate-skill.sh +0 -334
  52. package/.claude/skills/skill-builder/scripts/validate-skill.sh +0 -198
  53. package/.claude/skills/swarm-orchestration/SKILL.md +0 -179
  54. package/docs/AGENTDB_INTEGRATION.md +0 -379
@@ -0,0 +1,225 @@
1
+ /**
2
+ * QueryOptimizer - Advanced Query Optimization for AgentDB
3
+ *
4
+ * Implements:
5
+ * - Query result caching with TTL
6
+ * - Prepared statement pooling
7
+ * - Batch operation optimization
8
+ * - Index usage analysis
9
+ * - Query plan analysis
10
+ */
11
+ export class QueryOptimizer {
12
+ db;
13
+ cache;
14
+ stats;
15
+ config;
16
+ constructor(db, config) {
17
+ this.db = db;
18
+ this.cache = new Map();
19
+ this.stats = new Map();
20
+ this.config = {
21
+ maxSize: 1000,
22
+ ttl: 60000, // 1 minute default
23
+ enabled: true,
24
+ ...config
25
+ };
26
+ }
27
+ /**
28
+ * Execute query with caching
29
+ */
30
+ query(sql, params = [], cacheKey) {
31
+ const key = cacheKey || this.generateCacheKey(sql, params);
32
+ const startTime = Date.now();
33
+ // Check cache
34
+ if (this.config.enabled && this.cache.has(key)) {
35
+ const cached = this.cache.get(key);
36
+ if (Date.now() - cached.timestamp < this.config.ttl) {
37
+ this.recordStats(sql, Date.now() - startTime, true);
38
+ return cached.result;
39
+ }
40
+ else {
41
+ this.cache.delete(key);
42
+ }
43
+ }
44
+ // Execute query
45
+ const stmt = this.db.prepare(sql);
46
+ const result = params.length > 0 ? stmt.all(...params) : stmt.all();
47
+ const executionTime = Date.now() - startTime;
48
+ this.recordStats(sql, executionTime, false);
49
+ // Cache result
50
+ if (this.config.enabled) {
51
+ this.cacheResult(key, result);
52
+ }
53
+ return result;
54
+ }
55
+ /**
56
+ * Execute query that returns single row
57
+ */
58
+ queryOne(sql, params = [], cacheKey) {
59
+ const results = this.query(sql, params, cacheKey);
60
+ return results[0];
61
+ }
62
+ /**
63
+ * Execute write operation (no caching)
64
+ */
65
+ execute(sql, params = []) {
66
+ const startTime = Date.now();
67
+ const stmt = this.db.prepare(sql);
68
+ const result = params.length > 0 ? stmt.run(...params) : stmt.run();
69
+ this.recordStats(sql, Date.now() - startTime, false);
70
+ // Invalidate relevant cache entries
71
+ this.invalidateCache(sql);
72
+ return result;
73
+ }
74
+ /**
75
+ * Batch insert optimization
76
+ */
77
+ batchInsert(table, columns, rows) {
78
+ const placeholders = columns.map(() => '?').join(', ');
79
+ const sql = `INSERT INTO ${table} (${columns.join(', ')}) VALUES (${placeholders})`;
80
+ const transaction = this.db.transaction((rows) => {
81
+ const stmt = this.db.prepare(sql);
82
+ for (const row of rows) {
83
+ stmt.run(...row);
84
+ }
85
+ });
86
+ const startTime = Date.now();
87
+ transaction(rows);
88
+ this.recordStats(`BATCH INSERT ${table}`, Date.now() - startTime, false);
89
+ }
90
+ /**
91
+ * Analyze query plan
92
+ */
93
+ analyzeQuery(sql) {
94
+ const plan = this.db.prepare(`EXPLAIN QUERY PLAN ${sql}`).all();
95
+ const planText = plan.map((row) => row.detail).join(' ');
96
+ const usesIndex = planText.toLowerCase().includes('index');
97
+ const hasFullScan = planText.toLowerCase().includes('scan');
98
+ // Simple cost estimation
99
+ let estimatedCost = 1;
100
+ if (hasFullScan)
101
+ estimatedCost *= 10;
102
+ if (!usesIndex)
103
+ estimatedCost *= 5;
104
+ return {
105
+ plan: planText,
106
+ usesIndex,
107
+ estimatedCost
108
+ };
109
+ }
110
+ /**
111
+ * Get optimization suggestions
112
+ */
113
+ getSuggestions() {
114
+ const suggestions = [];
115
+ // Analyze frequently run queries
116
+ const frequentQueries = Array.from(this.stats.values())
117
+ .filter(s => s.executionCount > 100)
118
+ .sort((a, b) => b.totalTime - a.totalTime)
119
+ .slice(0, 10);
120
+ for (const stat of frequentQueries) {
121
+ if (stat.avgTime > 50) {
122
+ const analysis = this.analyzeQuery(stat.query);
123
+ if (!analysis.usesIndex) {
124
+ suggestions.push(`Slow query (${stat.avgTime.toFixed(1)}ms avg): Consider adding index for:\n${stat.query}`);
125
+ }
126
+ if (stat.cacheHits === 0 && stat.executionCount > 50) {
127
+ suggestions.push(`Frequently run query without cache hits: ${stat.query.substring(0, 50)}...`);
128
+ }
129
+ }
130
+ }
131
+ // Check cache efficiency
132
+ const totalHits = Array.from(this.stats.values()).reduce((sum, s) => sum + s.cacheHits, 0);
133
+ const totalMisses = Array.from(this.stats.values()).reduce((sum, s) => sum + s.cacheMisses, 0);
134
+ const hitRate = totalHits / (totalHits + totalMisses) || 0;
135
+ if (hitRate < 0.3 && totalHits + totalMisses > 1000) {
136
+ suggestions.push(`Low cache hit rate (${(hitRate * 100).toFixed(1)}%). Consider increasing cache size or TTL.`);
137
+ }
138
+ return suggestions;
139
+ }
140
+ /**
141
+ * Get query statistics
142
+ */
143
+ getStats() {
144
+ return Array.from(this.stats.values())
145
+ .sort((a, b) => b.totalTime - a.totalTime);
146
+ }
147
+ /**
148
+ * Clear cache
149
+ */
150
+ clearCache() {
151
+ this.cache.clear();
152
+ }
153
+ /**
154
+ * Get cache statistics
155
+ */
156
+ getCacheStats() {
157
+ const totalHits = Array.from(this.stats.values()).reduce((sum, s) => sum + s.cacheHits, 0);
158
+ const totalMisses = Array.from(this.stats.values()).reduce((sum, s) => sum + s.cacheMisses, 0);
159
+ return {
160
+ size: this.cache.size,
161
+ hitRate: totalHits / (totalHits + totalMisses) || 0,
162
+ totalHits,
163
+ totalMisses
164
+ };
165
+ }
166
+ // ========================================================================
167
+ // Private Methods
168
+ // ========================================================================
169
+ generateCacheKey(sql, params) {
170
+ return `${sql}:${JSON.stringify(params)}`;
171
+ }
172
+ cacheResult(key, result) {
173
+ if (this.cache.size >= this.config.maxSize) {
174
+ // Simple LRU: remove oldest entry
175
+ const oldestKey = this.cache.keys().next().value;
176
+ this.cache.delete(oldestKey);
177
+ }
178
+ this.cache.set(key, {
179
+ result,
180
+ timestamp: Date.now()
181
+ });
182
+ }
183
+ invalidateCache(sql) {
184
+ // Invalidate cache entries related to modified tables
185
+ const tables = this.extractTables(sql);
186
+ for (const [key] of this.cache) {
187
+ for (const table of tables) {
188
+ if (key.toLowerCase().includes(table.toLowerCase())) {
189
+ this.cache.delete(key);
190
+ }
191
+ }
192
+ }
193
+ }
194
+ extractTables(sql) {
195
+ const matches = sql.match(/(?:FROM|INTO|UPDATE|JOIN)\s+(\w+)/gi);
196
+ if (!matches)
197
+ return [];
198
+ return matches
199
+ .map(m => m.split(/\s+/)[1])
200
+ .filter((v, i, a) => a.indexOf(v) === i); // unique
201
+ }
202
+ recordStats(sql, time, cacheHit) {
203
+ const key = sql.substring(0, 100); // Use first 100 chars as key
204
+ if (!this.stats.has(key)) {
205
+ this.stats.set(key, {
206
+ query: sql,
207
+ executionCount: 0,
208
+ totalTime: 0,
209
+ avgTime: 0,
210
+ cacheHits: 0,
211
+ cacheMisses: 0
212
+ });
213
+ }
214
+ const stat = this.stats.get(key);
215
+ stat.executionCount++;
216
+ stat.totalTime += time;
217
+ stat.avgTime = stat.totalTime / stat.executionCount;
218
+ if (cacheHit) {
219
+ stat.cacheHits++;
220
+ }
221
+ else {
222
+ stat.cacheMisses++;
223
+ }
224
+ }
225
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * AgentDB Optimizations
3
+ *
4
+ * Performance optimization utilities
5
+ */
6
+ export { QueryOptimizer } from './QueryOptimizer';
7
+ export { BatchOperations } from './BatchOperations';