claude-flow 2.7.0-alpha → 2.7.0-alpha.1

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.
@@ -0,0 +1,179 @@
1
+ # ReasoningBank Integration Status (v2.7.0-alpha)
2
+
3
+ ## Current Status: ⚠️ Partially Implemented
4
+
5
+ ### ✅ What Works
6
+
7
+ 1. **Initialization**: `memory init --reasoningbank`
8
+ - Creates `.swarm/memory.db` database
9
+ - Initializes schema with migrations
10
+ - Fully functional
11
+
12
+ 2. **Status Check**: `memory status --reasoningbank`
13
+ - Shows database statistics
14
+ - Displays memory counts
15
+ - Fully functional
16
+
17
+ 3. **Mode Detection**: `memory detect`
18
+ - Detects available memory modes
19
+ - Shows configuration
20
+ - Fully functional
21
+
22
+ ### ❌ What Doesn't Work (v2.7.0)
23
+
24
+ **Direct CLI Memory Operations:**
25
+ - `memory store key "value" --reasoningbank` ❌
26
+ - `memory query "search" --reasoningbank` ❌
27
+
28
+ **Root Cause:** Agentic-flow's ReasoningBank doesn't expose `store/query` as CLI commands. It's designed to be used **by agents during task execution**, not as a standalone memory store.
29
+
30
+ ## How ReasoningBank Actually Works
31
+
32
+ ReasoningBank is an **agent-centric memory system**:
33
+
34
+ ```bash
35
+ # ✅ CORRECT: Use via agent execution
36
+ npx agentic-flow --agent coder --task "Build REST API using best practices"
37
+
38
+ # During execution, the agent:
39
+ # 1. Retrieves relevant memories from ReasoningBank
40
+ # 2. Uses them to inform its work
41
+ # 3. Stores new learnings back to ReasoningBank
42
+ # 4. Updates confidence scores based on success/failure
43
+ ```
44
+
45
+ ```bash
46
+ # ❌ INCORRECT: Direct CLI memory operations
47
+ npx claude-flow memory store pattern "..." --reasoningbank
48
+ # This doesn't work because ReasoningBank has no store/query CLI commands
49
+ ```
50
+
51
+ ## Working Solutions (v2.7.0)
52
+
53
+ ### Solution 1: Use Basic Memory Mode (Default)
54
+
55
+ ```bash
56
+ # Standard key-value memory (always works)
57
+ claude-flow memory store api_pattern "Use environment variables for config"
58
+ claude-flow memory query "API"
59
+ claude-flow memory stats
60
+ ```
61
+
62
+ ### Solution 2: Use ReasoningBank via Agents
63
+
64
+ ```bash
65
+ # Initialize ReasoningBank
66
+ claude-flow memory init --reasoningbank
67
+
68
+ # Use agentic-flow agents (they'll use ReasoningBank automatically)
69
+ npx agentic-flow --agent coder --task "Implement user authentication"
70
+
71
+ # The agent will:
72
+ # - Query ReasoningBank for relevant patterns
73
+ # - Learn from past successes/failures
74
+ # - Store new learnings automatically
75
+ ```
76
+
77
+ ### Solution 3: Use ReasoningBank Tools Directly
78
+
79
+ ```bash
80
+ # View available tools
81
+ npx agentic-flow reasoningbank --help
82
+
83
+ # Available commands:
84
+ npx agentic-flow reasoningbank demo # Interactive demo
85
+ npx agentic-flow reasoningbank test # Validation tests
86
+ npx agentic-flow reasoningbank status # Statistics
87
+ npx agentic-flow reasoningbank benchmark # Performance tests
88
+ npx agentic-flow reasoningbank consolidate # Memory cleanup
89
+ npx agentic-flow reasoningbank list # List memories
90
+ ```
91
+
92
+ ## Planned for v2.7.1
93
+
94
+ **Full CLI Integration:**
95
+ - Implement direct `store/query` operations
96
+ - Bridge claude-flow memory commands to ReasoningBank SDK
97
+ - Add migration tool: `memory migrate --to reasoningbank`
98
+
99
+ **Implementation Plan:**
100
+ 1. Import agentic-flow's ReasoningBank SDK directly
101
+ 2. Wrap SDK methods in claude-flow memory commands
102
+ 3. Provide seamless experience for both modes
103
+
104
+ ## Current Workaround
105
+
106
+ If you initialized ReasoningBank and want to use its learning capabilities:
107
+
108
+ ```bash
109
+ # 1. Initialize (one-time)
110
+ claude-flow memory init --reasoningbank
111
+
112
+ # 2. Use basic memory for manual storage
113
+ claude-flow memory store api_best_practice "Always validate input"
114
+
115
+ # 3. Use agentic-flow agents for AI-powered learning
116
+ npx agentic-flow --agent coder --task "Build secure API endpoints"
117
+
118
+ # The agent will:
119
+ # - Access ReasoningBank automatically
120
+ # - Learn from your basic memory entries
121
+ # - Store new learnings with confidence scores
122
+ ```
123
+
124
+ ##
125
+ Architecture
126
+
127
+ ```
128
+ ┌─────────────────────────────────────┐
129
+ │ claude-flow memory │
130
+ ├─────────────────────────────────────┤
131
+ │ │
132
+ │ Basic Mode (default) │
133
+ │ ├─ store/query/stats ✅ │
134
+ │ ├─ JSON file storage │
135
+ │ └─ Fast, simple KV store │
136
+ │ │
137
+ │ ReasoningBank Mode │
138
+ │ ├─ init ✅ │
139
+ │ ├─ status ✅ │
140
+ │ ├─ detect ✅ │
141
+ │ ├─ store ❌ (v2.7.1) │
142
+ │ └─ query ❌ (v2.7.1) │
143
+ │ │
144
+ └─────────────────────────────────────┘
145
+
146
+ ├─ Used by ─┐
147
+ │ │
148
+ ▼ ▼
149
+ ┌────────────────┐ ┌────────────────────┐
150
+ │ Basic Memory │ │ agentic-flow │
151
+ │ (JSON file) │ │ agents │
152
+ └────────────────┘ │ │
153
+ │ ├─ coder │
154
+ │ ├─ researcher │
155
+ │ ├─ reviewer │
156
+ │ └─ etc. │
157
+ │ │
158
+ │ Uses ReasoningBank │
159
+ │ automatically ✅ │
160
+ └────────────────────┘
161
+ ```
162
+
163
+ ## Summary
164
+
165
+ **v2.7.0-alpha Status:**
166
+ - ✅ ReasoningBank initialization works
167
+ - ✅ Status and monitoring work
168
+ - ❌ Direct store/query CLI not implemented
169
+ - ✅ Agent-based usage fully functional
170
+
171
+ **Recommended Approach:**
172
+ 1. Use **basic mode** for manual memory operations
173
+ 2. Use **agentic-flow agents** for AI-powered learning with ReasoningBank
174
+ 3. Wait for **v2.7.1** for full CLI integration
175
+
176
+ **Not a Bug:**
177
+ This is an **architectural limitation**, not a bug. ReasoningBank was designed for agent use, and v2.7.0 exposes that functionality correctly through agentic-flow agents.
178
+
179
+ The v2.7.1 release will add convenience CLI wrappers for direct memory operations.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-flow",
3
- "version": "2.7.0-alpha",
3
+ "version": "2.7.0-alpha.1",
4
4
  "description": "Enterprise-grade AI agent orchestration with multi-provider execution engine",
5
5
  "mcpName": "io.github.ruvnet/claude-flow",
6
6
  "main": "cli.mjs",
@@ -422,6 +422,9 @@ async function isReasoningBankInitialized() {
422
422
  async function handleReasoningBankCommand(command, subArgs, flags) {
423
423
  const initialized = await isReasoningBankInitialized();
424
424
 
425
+ // Lazy load the adapter (ES modules)
426
+ const { initializeReasoningBank, storeMemory, queryMemories, listMemories, getStatus } = await import('../../reasoningbank/reasoningbank-adapter.js');
427
+
425
428
  // Special handling for 'init' command
426
429
  if (command === 'init') {
427
430
  if (initialized) {
@@ -435,11 +438,7 @@ async function handleReasoningBankCommand(command, subArgs, flags) {
435
438
  console.log('This will create: .swarm/memory.db\n');
436
439
 
437
440
  try {
438
- const { stdout, stderr } = await execAsync('npx agentic-flow reasoningbank init', {
439
- timeout: 30000,
440
- });
441
-
442
- if (stdout) console.log(stdout);
441
+ await initializeReasoningBank();
443
442
  printSuccess('✅ ReasoningBank initialized successfully!');
444
443
  console.log('\nNext steps:');
445
444
  console.log(' 1. Store memories: memory store key "value" --reasoningbank');
@@ -448,9 +447,6 @@ async function handleReasoningBankCommand(command, subArgs, flags) {
448
447
  } catch (error) {
449
448
  printError('❌ Failed to initialize ReasoningBank');
450
449
  console.error(error.message);
451
- if (error.stderr) {
452
- console.error('Details:', error.stderr);
453
- }
454
450
  }
455
451
  return;
456
452
  }
@@ -463,21 +459,156 @@ async function handleReasoningBankCommand(command, subArgs, flags) {
463
459
  return;
464
460
  }
465
461
 
466
- // Delegate to agentic-flow reasoningbank commands
467
462
  printInfo(`🧠 Using ReasoningBank mode...`);
468
463
 
469
464
  try {
470
- const cmd = buildReasoningBankCommand(command, subArgs, flags);
471
- const { stdout, stderr } = await execAsync(cmd, { timeout: 30000 });
472
-
473
- if (stdout) console.log(stdout);
474
- if (stderr && !stderr.includes('Warning')) console.error(stderr);
465
+ // Handle different commands
466
+ switch (command) {
467
+ case 'store':
468
+ await handleReasoningBankStore(subArgs, flags, storeMemory);
469
+ break;
470
+
471
+ case 'query':
472
+ await handleReasoningBankQuery(subArgs, flags, queryMemories);
473
+ break;
474
+
475
+ case 'list':
476
+ await handleReasoningBankList(subArgs, flags, listMemories);
477
+ break;
478
+
479
+ case 'status':
480
+ await handleReasoningBankStatus(getStatus);
481
+ break;
482
+
483
+ case 'consolidate':
484
+ case 'demo':
485
+ case 'test':
486
+ case 'benchmark':
487
+ // These still use CLI commands
488
+ const cmd = `npx agentic-flow reasoningbank ${command}`;
489
+ const { stdout } = await execAsync(cmd, { timeout: 60000 });
490
+ if (stdout) console.log(stdout);
491
+ break;
492
+
493
+ default:
494
+ printError(`Unknown ReasoningBank command: ${command}`);
495
+ }
475
496
  } catch (error) {
476
497
  printError(`❌ ReasoningBank command failed`);
477
498
  console.error(error.message);
478
499
  }
479
500
  }
480
501
 
502
+ // NEW: Handle ReasoningBank store
503
+ async function handleReasoningBankStore(subArgs, flags, storeMemory) {
504
+ const key = subArgs[1];
505
+ const value = subArgs.slice(2).join(' ');
506
+
507
+ if (!key || !value) {
508
+ printError('Usage: memory store <key> <value> --reasoningbank');
509
+ return;
510
+ }
511
+
512
+ try {
513
+ const namespace = flags?.namespace || flags?.ns || getArgValue(subArgs, '--namespace') || 'default';
514
+
515
+ const memoryId = await storeMemory(key, value, {
516
+ namespace,
517
+ agent: 'memory-agent',
518
+ domain: namespace,
519
+ });
520
+
521
+ printSuccess('✅ Stored successfully in ReasoningBank');
522
+ console.log(`📝 Key: ${key}`);
523
+ console.log(`🧠 Memory ID: ${memoryId}`);
524
+ console.log(`📦 Namespace: ${namespace}`);
525
+ console.log(`💾 Size: ${new TextEncoder().encode(value).length} bytes`);
526
+ console.log(`🔍 Semantic search: enabled`);
527
+ } catch (error) {
528
+ printError(`Failed to store: ${error.message}`);
529
+ }
530
+ }
531
+
532
+ // NEW: Handle ReasoningBank query
533
+ async function handleReasoningBankQuery(subArgs, flags, queryMemories) {
534
+ const search = subArgs.slice(1).join(' ');
535
+
536
+ if (!search) {
537
+ printError('Usage: memory query <search> --reasoningbank');
538
+ return;
539
+ }
540
+
541
+ try {
542
+ const namespace = flags?.namespace || flags?.ns || getArgValue(subArgs, '--namespace');
543
+ const results = await queryMemories(search, {
544
+ domain: namespace || 'general',
545
+ limit: 10,
546
+ });
547
+
548
+ if (results.length === 0) {
549
+ printWarning('No results found');
550
+ return;
551
+ }
552
+
553
+ printSuccess(`Found ${results.length} results (semantic search):`);
554
+
555
+ for (const entry of results) {
556
+ console.log(`\n📌 ${entry.key}`);
557
+ console.log(` Namespace: ${entry.namespace}`);
558
+ console.log(` Value: ${entry.value.substring(0, 100)}${entry.value.length > 100 ? '...' : ''}`);
559
+ console.log(` Confidence: ${(entry.confidence * 100).toFixed(1)}%`);
560
+ console.log(` Usage: ${entry.usage_count} times`);
561
+ if (entry.score) {
562
+ console.log(` Match Score: ${(entry.score * 100).toFixed(1)}%`);
563
+ }
564
+ console.log(` Stored: ${new Date(entry.created_at).toLocaleString()}`);
565
+ }
566
+ } catch (error) {
567
+ printError(`Failed to query: ${error.message}`);
568
+ }
569
+ }
570
+
571
+ // NEW: Handle ReasoningBank list
572
+ async function handleReasoningBankList(subArgs, flags, listMemories) {
573
+ try {
574
+ const sort = flags?.sort || getArgValue(subArgs, '--sort') || 'created_at';
575
+ const limit = parseInt(flags?.limit || getArgValue(subArgs, '--limit') || '10');
576
+
577
+ const results = await listMemories({ sort, limit });
578
+
579
+ if (results.length === 0) {
580
+ printWarning('No memories found');
581
+ return;
582
+ }
583
+
584
+ printSuccess(`ReasoningBank memories (${results.length} shown):`);
585
+
586
+ for (const entry of results) {
587
+ console.log(`\n📌 ${entry.key}`);
588
+ console.log(` Value: ${entry.value.substring(0, 80)}${entry.value.length > 80 ? '...' : ''}`);
589
+ console.log(` Confidence: ${(entry.confidence * 100).toFixed(1)}% | Usage: ${entry.usage_count}`);
590
+ }
591
+ } catch (error) {
592
+ printError(`Failed to list: ${error.message}`);
593
+ }
594
+ }
595
+
596
+ // NEW: Handle ReasoningBank status
597
+ async function handleReasoningBankStatus(getStatus) {
598
+ try {
599
+ const stats = await getStatus();
600
+
601
+ printSuccess('📊 ReasoningBank Status:');
602
+ console.log(` Total memories: ${stats.total_memories}`);
603
+ console.log(` Average confidence: ${(stats.avg_confidence * 100).toFixed(1)}%`);
604
+ console.log(` Total usage: ${stats.total_usage}`);
605
+ console.log(` Embeddings: ${stats.total_embeddings}`);
606
+ console.log(` Trajectories: ${stats.total_trajectories}`);
607
+ } catch (error) {
608
+ printError(`Failed to get status: ${error.message}`);
609
+ }
610
+ }
611
+
481
612
  // NEW: Build agentic-flow reasoningbank command
482
613
  function buildReasoningBankCommand(command, subArgs, flags) {
483
614
  const parts = ['npx', 'agentic-flow', 'reasoningbank'];
@@ -504,6 +635,9 @@ function buildReasoningBankCommand(command, subArgs, flags) {
504
635
  }
505
636
  });
506
637
 
638
+ // Add required --agent parameter
639
+ parts.push('--agent', 'memory-agent');
640
+
507
641
  return parts.join(' ');
508
642
  }
509
643
 
@@ -0,0 +1,191 @@
1
+ /**
2
+ * ReasoningBank Adapter for Claude-Flow
3
+ *
4
+ * Wraps agentic-flow's ReasoningBank SDK for use in claude-flow memory commands
5
+ */
6
+
7
+ import { db, initialize, retrieveMemories, computeEmbedding, loadConfig } from 'agentic-flow/dist/reasoningbank/index.js';
8
+ import { v4 as uuidv4 } from 'uuid';
9
+
10
+ /**
11
+ * Initialize ReasoningBank database
12
+ */
13
+ export async function initializeReasoningBank() {
14
+ // Set database path
15
+ process.env.CLAUDE_FLOW_DB_PATH = '.swarm/memory.db';
16
+
17
+ await initialize();
18
+ return true;
19
+ }
20
+
21
+ /**
22
+ * Store a memory in ReasoningBank
23
+ */
24
+ export async function storeMemory(key, value, options = {}) {
25
+ const memoryId = `mem_${uuidv4()}`;
26
+
27
+ const memory = {
28
+ id: memoryId,
29
+ type: options.type || 'fact',
30
+ pattern_data: JSON.stringify({
31
+ key,
32
+ value,
33
+ namespace: options.namespace || 'default',
34
+ agent: options.agent || 'memory-agent',
35
+ domain: options.domain || 'general',
36
+ }),
37
+ confidence: options.confidence || 0.8,
38
+ usage_count: 0,
39
+ created_at: new Date().toISOString(),
40
+ };
41
+
42
+ // Store memory
43
+ db.upsertMemory(memory);
44
+
45
+ // Compute and store embedding for semantic search
46
+ try {
47
+ const config = loadConfig();
48
+ const embeddingModel = config.embeddings.provider || 'claude';
49
+
50
+ const embedding = await computeEmbedding(`${key}: ${value}`);
51
+ const vectorArray = new Float32Array(embedding);
52
+
53
+ db.upsertEmbedding({
54
+ memory_id: memoryId,
55
+ vector: vectorArray,
56
+ model: embeddingModel, // Dynamic model from config
57
+ dims: vectorArray.length, // Required: embedding dimensions
58
+ created_at: new Date().toISOString(),
59
+ });
60
+ } catch (error) {
61
+ console.warn('[ReasoningBank] Warning: Could not compute embedding:', error.message);
62
+ // Continue without embedding - memory is still stored
63
+ }
64
+
65
+ return memoryId;
66
+ }
67
+
68
+ /**
69
+ * Query memories from ReasoningBank
70
+ */
71
+ export async function queryMemories(searchQuery, options = {}) {
72
+ try {
73
+ // Use ReasoningBank's semantic retrieval
74
+ const memories = await retrieveMemories(searchQuery, {
75
+ domain: options.domain || 'general',
76
+ agent: options.agent || 'memory-agent',
77
+ k: options.limit || 10,
78
+ });
79
+
80
+ return memories.map(mem => {
81
+ try {
82
+ const data = JSON.parse(mem.pattern_data);
83
+ return {
84
+ id: mem.id,
85
+ key: data.key,
86
+ value: data.value,
87
+ namespace: data.namespace,
88
+ confidence: mem.confidence,
89
+ usage_count: mem.usage_count,
90
+ created_at: mem.created_at,
91
+ score: mem.score || 0,
92
+ };
93
+ } catch {
94
+ return null;
95
+ }
96
+ }).filter(Boolean);
97
+ } catch (error) {
98
+ // Fallback to simple query if semantic search fails
99
+ console.warn('[ReasoningBank] Semantic search failed, using simple query:', error.message);
100
+
101
+ const dbInstance = db.getDb();
102
+ const rows = dbInstance.prepare(`
103
+ SELECT * FROM patterns
104
+ WHERE pattern_data LIKE ?
105
+ ORDER BY confidence DESC, usage_count DESC
106
+ LIMIT ?
107
+ `).all(`%${searchQuery}%`, options.limit || 10);
108
+
109
+ return rows.map(row => {
110
+ try {
111
+ const data = JSON.parse(row.pattern_data);
112
+ return {
113
+ id: row.id,
114
+ key: data.key,
115
+ value: data.value,
116
+ namespace: data.namespace,
117
+ confidence: row.confidence,
118
+ usage_count: row.usage_count,
119
+ created_at: row.created_at,
120
+ };
121
+ } catch {
122
+ return null;
123
+ }
124
+ }).filter(Boolean);
125
+ }
126
+ }
127
+
128
+ /**
129
+ * List all memories
130
+ */
131
+ export async function listMemories(options = {}) {
132
+ const dbInstance = db.getDb();
133
+
134
+ const limit = options.limit || 10;
135
+ const sortBy = options.sort || 'created_at';
136
+ const sortOrder = options.order || 'DESC';
137
+
138
+ const rows = dbInstance.prepare(`
139
+ SELECT * FROM patterns
140
+ ORDER BY ${sortBy} ${sortOrder}
141
+ LIMIT ?
142
+ `).all(limit);
143
+
144
+ return rows.map(row => {
145
+ try {
146
+ const data = JSON.parse(row.pattern_data);
147
+ return {
148
+ id: row.id,
149
+ key: data.key,
150
+ value: data.value,
151
+ namespace: data.namespace,
152
+ confidence: row.confidence,
153
+ usage_count: row.usage_count,
154
+ created_at: row.created_at,
155
+ };
156
+ } catch {
157
+ return null;
158
+ }
159
+ }).filter(Boolean);
160
+ }
161
+
162
+ /**
163
+ * Get ReasoningBank statistics
164
+ */
165
+ export async function getStatus() {
166
+ const dbInstance = db.getDb();
167
+
168
+ const stats = dbInstance.prepare(`
169
+ SELECT
170
+ COUNT(*) as total_memories,
171
+ AVG(confidence) as avg_confidence,
172
+ SUM(usage_count) as total_usage
173
+ FROM patterns
174
+ `).get();
175
+
176
+ const embeddingCount = dbInstance.prepare(`
177
+ SELECT COUNT(*) as count FROM pattern_embeddings
178
+ `).get();
179
+
180
+ const trajectoryCount = dbInstance.prepare(`
181
+ SELECT COUNT(*) as count FROM task_trajectories
182
+ `).get();
183
+
184
+ return {
185
+ total_memories: stats.total_memories || 0,
186
+ avg_confidence: stats.avg_confidence || 0,
187
+ total_usage: stats.total_usage || 0,
188
+ total_embeddings: embeddingCount.count || 0,
189
+ total_trajectories: trajectoryCount.count || 0,
190
+ };
191
+ }