@sparkleideas/integration 3.5.2-patch.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.
package/README.md ADDED
@@ -0,0 +1,270 @@
1
+ # @claude-flow/integration
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@claude-flow/integration.svg)](https://www.npmjs.com/package/@claude-flow/integration)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@claude-flow/integration.svg)](https://www.npmjs.com/package/@claude-flow/integration)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)
7
+ [![ADR-001](https://img.shields.io/badge/ADR--001-Compliant-green.svg)](https://github.com/ruvnet/claude-flow)
8
+
9
+ > Deep agentic-flow@alpha integration module for Claude Flow V3 - ADR-001 compliance, code deduplication, SONA adapter, and Flash Attention coordinator.
10
+
11
+ ## Features
12
+
13
+ - **ADR-001 Compliance** - Eliminates 10,000+ duplicate lines by building on agentic-flow
14
+ - **SONA Adapter** - Seamless integration with SONA learning systems
15
+ - **Flash Attention** - 2.49x-7.47x speedup with attention coordination
16
+ - **SDK Bridge** - Version negotiation and API compatibility layer
17
+ - **Feature Flags** - Dynamic feature enabling/disabling
18
+ - **Runtime Detection** - Auto-select optimal runtime (NAPI, WASM, JS)
19
+ - **Graceful Fallback** - Works with or without agentic-flow installed
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ npm install @claude-flow/integration
25
+
26
+ # Optional: Install agentic-flow for optimal performance
27
+ npm install agentic-flow@alpha
28
+ ```
29
+
30
+ ## Quick Start
31
+
32
+ ```typescript
33
+ import { AgenticFlowBridge, createAgenticFlowBridge } from '@claude-flow/integration';
34
+
35
+ // Create and initialize bridge
36
+ const bridge = await createAgenticFlowBridge({
37
+ features: {
38
+ enableSONA: true,
39
+ enableFlashAttention: true,
40
+ enableAgentDB: true
41
+ }
42
+ });
43
+
44
+ // Check if agentic-flow is connected
45
+ if (bridge.isAgenticFlowConnected()) {
46
+ console.log('Using optimized agentic-flow implementation');
47
+ } else {
48
+ console.log('Using local fallback implementation');
49
+ }
50
+
51
+ // Get SONA adapter
52
+ const sona = await bridge.getSONAAdapter();
53
+ await sona.setMode('balanced');
54
+
55
+ // Get Attention coordinator
56
+ const attention = await bridge.getAttentionCoordinator();
57
+ const result = await attention.compute({ query, key, value });
58
+ ```
59
+
60
+ ## API Reference
61
+
62
+ ### AgenticFlowBridge
63
+
64
+ ```typescript
65
+ import { AgenticFlowBridge } from '@claude-flow/integration';
66
+
67
+ const bridge = new AgenticFlowBridge({
68
+ sona: {
69
+ mode: 'balanced',
70
+ learningRate: 0.001,
71
+ similarityThreshold: 0.7
72
+ },
73
+ attention: {
74
+ mechanism: 'flash',
75
+ numHeads: 8,
76
+ flashOptLevel: 2
77
+ },
78
+ agentdb: {
79
+ dimension: 1536,
80
+ indexType: 'hnsw',
81
+ metric: 'cosine'
82
+ },
83
+ features: {
84
+ enableSONA: true,
85
+ enableFlashAttention: true,
86
+ enableAgentDB: true
87
+ },
88
+ runtimePreference: ['napi', 'wasm', 'js'],
89
+ lazyLoad: true,
90
+ debug: false
91
+ });
92
+
93
+ await bridge.initialize();
94
+
95
+ // Component access
96
+ const sona = await bridge.getSONAAdapter();
97
+ const attention = await bridge.getAttentionCoordinator();
98
+ const sdk = await bridge.getSDKBridge();
99
+
100
+ // Feature management
101
+ bridge.isFeatureEnabled('enableSONA');
102
+ await bridge.enableFeature('enableFlashAttention');
103
+ await bridge.disableFeature('enableAgentDB');
104
+
105
+ // Health & status
106
+ const status = bridge.getStatus();
107
+ const health = await bridge.healthCheck();
108
+ const flags = bridge.getFeatureFlags();
109
+
110
+ // Direct agentic-flow access (when available)
111
+ const core = bridge.getAgenticFlowCore();
112
+ if (core) {
113
+ const patterns = await core.sona.findPatterns(query);
114
+ }
115
+
116
+ // Cleanup
117
+ await bridge.shutdown();
118
+ ```
119
+
120
+ ### SONA Adapter
121
+
122
+ ```typescript
123
+ const sona = await bridge.getSONAAdapter();
124
+
125
+ // Mode management
126
+ await sona.setMode('real-time'); // 'real-time' | 'balanced' | 'research' | 'edge' | 'batch'
127
+
128
+ // Pattern operations
129
+ const patternId = await sona.storePattern({
130
+ context: 'code-review',
131
+ strategy: 'analyze-then-comment',
132
+ embedding: vector
133
+ });
134
+
135
+ const patterns = await sona.findPatterns(queryEmbedding, {
136
+ limit: 5,
137
+ threshold: 0.7
138
+ });
139
+
140
+ // Statistics
141
+ const stats = await sona.getStats();
142
+ ```
143
+
144
+ ### Attention Coordinator
145
+
146
+ ```typescript
147
+ const attention = await bridge.getAttentionCoordinator();
148
+
149
+ // Set attention mechanism
150
+ await attention.setMechanism('flash'); // 'flash' | 'standard' | 'linear'
151
+
152
+ // Compute attention
153
+ const result = await attention.compute({
154
+ query: queryTensor,
155
+ key: keyTensor,
156
+ value: valueTensor,
157
+ mask: optionalMask
158
+ });
159
+
160
+ // Get metrics
161
+ const metrics = await attention.getMetrics();
162
+ // { avgLatencyMs, speedupRatio, memoryUsage }
163
+ ```
164
+
165
+ ### SDK Bridge
166
+
167
+ ```typescript
168
+ const sdk = await bridge.getSDKBridge();
169
+
170
+ // Version negotiation
171
+ const version = sdk.getVersion();
172
+ const isCompatible = sdk.isCompatible('0.1.0');
173
+
174
+ // Health check
175
+ await sdk.ping();
176
+ ```
177
+
178
+ ## Feature Flags
179
+
180
+ ```typescript
181
+ const flags = bridge.getFeatureFlags();
182
+
183
+ {
184
+ enableSONA: true, // SONA learning integration
185
+ enableFlashAttention: true, // Flash Attention optimization
186
+ enableAgentDB: true, // AgentDB vector storage
187
+ enableTrajectoryTracking: true,// Trajectory recording
188
+ enableGNN: true, // Graph Neural Network
189
+ enableIntelligenceBridge: true,// Intelligence bridge
190
+ enableQUICTransport: false, // QUIC transport (experimental)
191
+ enableNightlyLearning: false, // Background learning
192
+ enableAutoConsolidation: true // Auto memory consolidation
193
+ }
194
+ ```
195
+
196
+ ## Runtime Detection
197
+
198
+ The bridge automatically selects the best runtime:
199
+
200
+ | Runtime | Performance | Requirements |
201
+ |---------|-------------|--------------|
202
+ | **NAPI** | Optimal | Native bindings, non-Windows or x64 |
203
+ | **WASM** | Good | WebAssembly support |
204
+ | **JS** | Fallback | Always available |
205
+
206
+ ```typescript
207
+ const status = bridge.getStatus();
208
+ console.log(status.runtime);
209
+ // { runtime: 'napi', platform: 'linux', arch: 'x64', performanceTier: 'optimal' }
210
+ ```
211
+
212
+ ## Event System
213
+
214
+ ```typescript
215
+ bridge.on('initialized', ({ duration, components, agenticFlowConnected }) => {
216
+ console.log(`Initialized in ${duration}ms`);
217
+ });
218
+
219
+ bridge.on('agentic-flow:connected', ({ version, features }) => {
220
+ console.log(`Connected to agentic-flow ${version}`);
221
+ });
222
+
223
+ bridge.on('agentic-flow:fallback', ({ reason }) => {
224
+ console.log(`Using fallback: ${reason}`);
225
+ });
226
+
227
+ bridge.on('feature-enabled', ({ feature }) => {
228
+ console.log(`Enabled: ${feature}`);
229
+ });
230
+
231
+ bridge.on('health-check', ({ results }) => {
232
+ console.log(`Health: ${JSON.stringify(results)}`);
233
+ });
234
+ ```
235
+
236
+ ## Performance Targets
237
+
238
+ | Metric | Target |
239
+ |--------|--------|
240
+ | Flash Attention speedup | 2.49x-7.47x |
241
+ | AgentDB search | 150x-12,500x faster |
242
+ | SONA adaptation | <0.05ms |
243
+ | Memory reduction | 50-75% |
244
+
245
+ ## TypeScript Types
246
+
247
+ ```typescript
248
+ import type {
249
+ IntegrationConfig,
250
+ IntegrationStatus,
251
+ RuntimeInfo,
252
+ ComponentHealth,
253
+ FeatureFlags,
254
+ AgenticFlowCore
255
+ } from '@claude-flow/integration';
256
+ ```
257
+
258
+ ## Peer Dependencies
259
+
260
+ - `agentic-flow@^0.1.0` (optional, for optimal performance)
261
+
262
+ ## Related Packages
263
+
264
+ - [@claude-flow/neural](../neural) - SONA learning module
265
+ - [@claude-flow/memory](../memory) - AgentDB memory
266
+ - [@claude-flow/performance](../performance) - Benchmarking
267
+
268
+ ## License
269
+
270
+ MIT
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@sparkleideas/integration",
3
+ "version": "3.5.2-patch.1",
4
+ "type": "module",
5
+ "description": "Integration module - agentic-flow@alpha deep integration, ADR-001 compliance, TokenOptimizer",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": "./dist/index.js",
10
+ "./token-optimizer": "./dist/token-optimizer.js",
11
+ "./*": "./dist/*.js"
12
+ },
13
+ "scripts": {
14
+ "test": "vitest run",
15
+ "build": "tsc"
16
+ },
17
+ "keywords": [
18
+ "claude-flow",
19
+ "agentic-flow",
20
+ "token-optimizer",
21
+ "agent-booster",
22
+ "reasoningbank",
23
+ "anti-drift",
24
+ "swarm"
25
+ ],
26
+ "peerDependencies": {
27
+ "@sparkleideas/agentic-flow": "^2.0.0-alpha"
28
+ },
29
+ "devDependencies": {
30
+ "vitest": "^4.0.16"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public",
34
+ "tag": "v3alpha"
35
+ },
36
+ "optionalDependencies": {
37
+ "agent-booster": "^0.2.2"
38
+ },
39
+ "claude-flow": {
40
+ "optionalComponents": {
41
+ "TokenOptimizer": {
42
+ "description": "Token reduction via agentic-flow Agent Booster integration",
43
+ "savings": "30-50%",
44
+ "features": [
45
+ "ReasoningBank",
46
+ "cache",
47
+ "anti-drift-config"
48
+ ],
49
+ "requires": [
50
+ "agentic-flow"
51
+ ]
52
+ }
53
+ }
54
+ }
55
+ }
@@ -0,0 +1,271 @@
1
+ /**
2
+ * AgentAdapter Test Suite
3
+ *
4
+ * Tests for ADR-001 agent adapter and delegation patterns
5
+ */
6
+
7
+ import { describe, it, expect, beforeEach, afterEach } from 'vitest';
8
+ import { AgentAdapter, createAgentAdapter } from '../agent-adapter.js';
9
+ import { AgenticFlowAgent } from '../agentic-flow-agent.js';
10
+
11
+ describe('AgentAdapter', () => {
12
+ let adapter: AgentAdapter;
13
+
14
+ beforeEach(async () => {
15
+ adapter = new AgentAdapter({
16
+ enableSync: true,
17
+ autoConvert: true,
18
+ fallbackOnError: true,
19
+ debug: false,
20
+ });
21
+
22
+ await adapter.initialize();
23
+ });
24
+
25
+ afterEach(async () => {
26
+ if (adapter) {
27
+ await adapter.shutdown();
28
+ }
29
+ });
30
+
31
+ describe('Initialization', () => {
32
+ it('should initialize successfully', async () => {
33
+ const freshAdapter = new AgentAdapter();
34
+ await freshAdapter.initialize();
35
+
36
+ expect(freshAdapter).toBeDefined();
37
+
38
+ await freshAdapter.shutdown();
39
+ });
40
+
41
+ it('should be idempotent on multiple initialize calls', async () => {
42
+ await adapter.initialize();
43
+ await adapter.initialize();
44
+
45
+ expect(adapter).toBeDefined();
46
+ });
47
+ });
48
+
49
+ describe('Agent Creation with Delegation', () => {
50
+ it('should create an agent with delegation support', async () => {
51
+ const agent = await adapter.createWithDelegation({
52
+ id: 'delegated-agent-1',
53
+ name: 'Delegated Agent',
54
+ type: 'coder',
55
+ capabilities: ['code-generation'],
56
+ maxConcurrentTasks: 3,
57
+ priority: 5,
58
+ });
59
+
60
+ expect(agent).toBeInstanceOf(AgenticFlowAgent);
61
+ expect(agent.id).toBe('delegated-agent-1');
62
+ expect(agent.status).toBe('idle'); // Should be initialized
63
+ });
64
+
65
+ it('should track created agents', async () => {
66
+ const agent1 = await adapter.createWithDelegation({
67
+ id: 'agent-1',
68
+ name: 'Agent 1',
69
+ type: 'coder',
70
+ capabilities: [],
71
+ maxConcurrentTasks: 1,
72
+ priority: 1,
73
+ });
74
+
75
+ const agent2 = await adapter.createWithDelegation({
76
+ id: 'agent-2',
77
+ name: 'Agent 2',
78
+ type: 'tester',
79
+ capabilities: [],
80
+ maxConcurrentTasks: 1,
81
+ priority: 1,
82
+ });
83
+
84
+ const allAgents = adapter.getAllAgents();
85
+ expect(allAgents).toHaveLength(2);
86
+ expect(allAgents).toContain(agent1);
87
+ expect(allAgents).toContain(agent2);
88
+ });
89
+ });
90
+
91
+ describe('Agent Retrieval', () => {
92
+ let testAgent: AgenticFlowAgent;
93
+
94
+ beforeEach(async () => {
95
+ testAgent = await adapter.createWithDelegation({
96
+ id: 'retrieval-agent',
97
+ name: 'Retrieval Test Agent',
98
+ type: 'researcher',
99
+ capabilities: ['research'],
100
+ maxConcurrentTasks: 2,
101
+ priority: 3,
102
+ });
103
+ });
104
+
105
+ it('should retrieve agent by ID', () => {
106
+ const retrieved = adapter.getAgent('retrieval-agent');
107
+
108
+ expect(retrieved).toBe(testAgent);
109
+ });
110
+
111
+ it('should return undefined for non-existent agent', () => {
112
+ const retrieved = adapter.getAgent('non-existent-agent');
113
+
114
+ expect(retrieved).toBeUndefined();
115
+ });
116
+
117
+ it('should get all agents', () => {
118
+ const allAgents = adapter.getAllAgents();
119
+
120
+ expect(allAgents).toHaveLength(1);
121
+ expect(allAgents[0]).toBe(testAgent);
122
+ });
123
+ });
124
+
125
+ describe('Agent Removal', () => {
126
+ it('should remove an agent', async () => {
127
+ const agent = await adapter.createWithDelegation({
128
+ id: 'removal-agent',
129
+ name: 'Removal Test',
130
+ type: 'coder',
131
+ capabilities: [],
132
+ maxConcurrentTasks: 1,
133
+ priority: 1,
134
+ });
135
+
136
+ expect(adapter.getAgent('removal-agent')).toBe(agent);
137
+
138
+ const removed = await adapter.removeAgent('removal-agent');
139
+
140
+ expect(removed).toBe(true);
141
+ expect(adapter.getAgent('removal-agent')).toBeUndefined();
142
+ });
143
+
144
+ it('should return false when removing non-existent agent', async () => {
145
+ const removed = await adapter.removeAgent('non-existent');
146
+
147
+ expect(removed).toBe(false);
148
+ });
149
+ });
150
+
151
+ describe('Agent Conversion from @sparkleideas/agentic-flow', () => {
152
+ it('should convert @sparkleideas/agentic-flow agent format', () => {
153
+ const mockAgenticFlowAgent = {
154
+ id: 'mock-agent-1',
155
+ name: 'Mock Agent',
156
+ type: 'coder',
157
+ status: 'ready',
158
+ config: {
159
+ capabilities: ['code-generation', 'refactoring'],
160
+ maxConcurrentTasks: 3,
161
+ priority: 5,
162
+ },
163
+ };
164
+
165
+ const result = adapter.fromAgenticFlow(mockAgenticFlowAgent);
166
+
167
+ expect(result.success).toBe(true);
168
+ expect(result.agent).toBeInstanceOf(AgenticFlowAgent);
169
+ expect(result.agent.id).toBe('mock-agent-1');
170
+ expect(result.agent.name).toBe('Mock Agent');
171
+ expect(result.warnings).toHaveLength(0);
172
+ });
173
+
174
+ it('should handle conversion warnings for unknown agent types', () => {
175
+ const mockAgenticFlowAgent = {
176
+ id: 'mock-agent-2',
177
+ name: 'Mock Agent',
178
+ type: 'unknown-type',
179
+ status: 'ready',
180
+ config: {
181
+ capabilities: [],
182
+ },
183
+ };
184
+
185
+ const result = adapter.fromAgenticFlow(mockAgenticFlowAgent);
186
+
187
+ expect(result.success).toBe(true);
188
+ expect(result.warnings.length).toBeGreaterThan(0);
189
+ expect(result.warnings[0]).toContain('unknown-type');
190
+ });
191
+ });
192
+
193
+ describe('Agent Conversion to @sparkleideas/agentic-flow', () => {
194
+ it('should convert Claude Flow agent to @sparkleideas/agentic-flow format', async () => {
195
+ const agent = await adapter.createWithDelegation({
196
+ id: 'convert-agent',
197
+ name: 'Convert Test',
198
+ type: 'coder',
199
+ capabilities: ['code-generation'],
200
+ maxConcurrentTasks: 2,
201
+ priority: 4,
202
+ });
203
+
204
+ const agenticFlowFormat = adapter.toAgenticFlow(agent);
205
+
206
+ expect(agenticFlowFormat.id).toBe('convert-agent');
207
+ expect(agenticFlowFormat.name).toBe('Convert Test');
208
+ expect(agenticFlowFormat.type).toBe('coder');
209
+ expect(agenticFlowFormat.config).toBeDefined();
210
+ });
211
+ });
212
+
213
+ describe('Delegation Status', () => {
214
+ it('should track delegation status', async () => {
215
+ const agent = await adapter.createWithDelegation({
216
+ id: 'delegation-check-agent',
217
+ name: 'Delegation Check',
218
+ type: 'coder',
219
+ capabilities: [],
220
+ maxConcurrentTasks: 1,
221
+ priority: 1,
222
+ });
223
+
224
+ // Note: isDelegated will be false unless @sparkleideas/agentic-flow is actually available
225
+ const isDelegated = adapter.isDelegated('delegation-check-agent');
226
+
227
+ expect(typeof isDelegated).toBe('boolean');
228
+ });
229
+ });
230
+
231
+ describe('Shutdown', () => {
232
+ it('should shutdown all managed agents', async () => {
233
+ await adapter.createWithDelegation({
234
+ id: 'shutdown-agent-1',
235
+ name: 'Shutdown Test 1',
236
+ type: 'coder',
237
+ capabilities: [],
238
+ maxConcurrentTasks: 1,
239
+ priority: 1,
240
+ });
241
+
242
+ await adapter.createWithDelegation({
243
+ id: 'shutdown-agent-2',
244
+ name: 'Shutdown Test 2',
245
+ type: 'tester',
246
+ capabilities: [],
247
+ maxConcurrentTasks: 1,
248
+ priority: 1,
249
+ });
250
+
251
+ expect(adapter.getAllAgents()).toHaveLength(2);
252
+
253
+ await adapter.shutdown();
254
+
255
+ expect(adapter.getAllAgents()).toHaveLength(0);
256
+ });
257
+ });
258
+ });
259
+
260
+ describe('createAgentAdapter', () => {
261
+ it('should create and initialize an adapter', async () => {
262
+ const adapter = await createAgentAdapter({
263
+ enableSync: true,
264
+ debug: false,
265
+ });
266
+
267
+ expect(adapter).toBeInstanceOf(AgentAdapter);
268
+
269
+ await adapter.shutdown();
270
+ });
271
+ });