@sparkleideas/plugins 3.0.0-alpha.10

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 (80) hide show
  1. package/README.md +401 -0
  2. package/__tests__/collection-manager.test.ts +332 -0
  3. package/__tests__/dependency-graph.test.ts +434 -0
  4. package/__tests__/enhanced-plugin-registry.test.ts +488 -0
  5. package/__tests__/plugin-registry.test.ts +368 -0
  6. package/__tests__/ruvector-bridge.test.ts +2429 -0
  7. package/__tests__/ruvector-integration.test.ts +1602 -0
  8. package/__tests__/ruvector-migrations.test.ts +1099 -0
  9. package/__tests__/ruvector-quantization.test.ts +846 -0
  10. package/__tests__/ruvector-streaming.test.ts +1088 -0
  11. package/__tests__/sdk.test.ts +325 -0
  12. package/__tests__/security.test.ts +348 -0
  13. package/__tests__/utils/ruvector-test-utils.ts +860 -0
  14. package/examples/plugin-creator/index.ts +636 -0
  15. package/examples/plugin-creator/plugin-creator.test.ts +312 -0
  16. package/examples/ruvector/README.md +288 -0
  17. package/examples/ruvector/attention-patterns.ts +394 -0
  18. package/examples/ruvector/basic-usage.ts +288 -0
  19. package/examples/ruvector/docker-compose.yml +75 -0
  20. package/examples/ruvector/gnn-analysis.ts +501 -0
  21. package/examples/ruvector/hyperbolic-hierarchies.ts +557 -0
  22. package/examples/ruvector/init-db.sql +119 -0
  23. package/examples/ruvector/quantization.ts +680 -0
  24. package/examples/ruvector/self-learning.ts +447 -0
  25. package/examples/ruvector/semantic-search.ts +576 -0
  26. package/examples/ruvector/streaming-large-data.ts +507 -0
  27. package/examples/ruvector/transactions.ts +594 -0
  28. package/examples/ruvector-plugins/hook-pattern-library.ts +486 -0
  29. package/examples/ruvector-plugins/index.ts +79 -0
  30. package/examples/ruvector-plugins/intent-router.ts +354 -0
  31. package/examples/ruvector-plugins/mcp-tool-optimizer.ts +424 -0
  32. package/examples/ruvector-plugins/reasoning-bank.ts +657 -0
  33. package/examples/ruvector-plugins/ruvector-plugins.test.ts +518 -0
  34. package/examples/ruvector-plugins/semantic-code-search.ts +498 -0
  35. package/examples/ruvector-plugins/shared/index.ts +20 -0
  36. package/examples/ruvector-plugins/shared/vector-utils.ts +257 -0
  37. package/examples/ruvector-plugins/sona-learning.ts +445 -0
  38. package/package.json +97 -0
  39. package/src/collections/collection-manager.ts +661 -0
  40. package/src/collections/index.ts +56 -0
  41. package/src/collections/official/index.ts +1040 -0
  42. package/src/core/base-plugin.ts +416 -0
  43. package/src/core/plugin-interface.ts +215 -0
  44. package/src/hooks/index.ts +685 -0
  45. package/src/index.ts +378 -0
  46. package/src/integrations/agentic-flow.ts +743 -0
  47. package/src/integrations/index.ts +88 -0
  48. package/src/integrations/ruvector/ARCHITECTURE.md +1245 -0
  49. package/src/integrations/ruvector/attention-advanced.ts +1040 -0
  50. package/src/integrations/ruvector/attention-executor.ts +782 -0
  51. package/src/integrations/ruvector/attention-mechanisms.ts +757 -0
  52. package/src/integrations/ruvector/attention.ts +1063 -0
  53. package/src/integrations/ruvector/gnn.ts +3050 -0
  54. package/src/integrations/ruvector/hyperbolic.ts +1948 -0
  55. package/src/integrations/ruvector/index.ts +394 -0
  56. package/src/integrations/ruvector/migrations/001_create_extension.sql +135 -0
  57. package/src/integrations/ruvector/migrations/002_create_vector_tables.sql +259 -0
  58. package/src/integrations/ruvector/migrations/003_create_indices.sql +328 -0
  59. package/src/integrations/ruvector/migrations/004_create_functions.sql +598 -0
  60. package/src/integrations/ruvector/migrations/005_create_attention_functions.sql +654 -0
  61. package/src/integrations/ruvector/migrations/006_create_gnn_functions.sql +728 -0
  62. package/src/integrations/ruvector/migrations/007_create_hyperbolic_functions.sql +762 -0
  63. package/src/integrations/ruvector/migrations/index.ts +35 -0
  64. package/src/integrations/ruvector/migrations/migrations.ts +647 -0
  65. package/src/integrations/ruvector/quantization.ts +2036 -0
  66. package/src/integrations/ruvector/ruvector-bridge.ts +2000 -0
  67. package/src/integrations/ruvector/self-learning.ts +2376 -0
  68. package/src/integrations/ruvector/streaming.ts +1737 -0
  69. package/src/integrations/ruvector/types.ts +1945 -0
  70. package/src/providers/index.ts +643 -0
  71. package/src/registry/dependency-graph.ts +568 -0
  72. package/src/registry/enhanced-plugin-registry.ts +994 -0
  73. package/src/registry/plugin-registry.ts +604 -0
  74. package/src/sdk/index.ts +563 -0
  75. package/src/security/index.ts +594 -0
  76. package/src/types/index.ts +446 -0
  77. package/src/workers/index.ts +700 -0
  78. package/tmp.json +0 -0
  79. package/tsconfig.json +25 -0
  80. package/vitest.config.ts +23 -0
package/README.md ADDED
@@ -0,0 +1,401 @@
1
+ # @claude-flow/plugins
2
+
3
+ **Unified Plugin SDK for Claude Flow V3**
4
+
5
+ A comprehensive plugin development framework providing workers, hooks, providers, and security utilities for building Claude Flow extensions.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @claude-flow/plugins
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ### Create a Plugin with the Builder
16
+
17
+ ```typescript
18
+ import { PluginBuilder, HookEvent, HookPriority } from '@claude-flow/plugins';
19
+
20
+ const myPlugin = new PluginBuilder('my-awesome-plugin', '1.0.0')
21
+ .withDescription('My awesome plugin for Claude Flow')
22
+ .withAuthor('Your Name')
23
+ .withMCPTools([
24
+ {
25
+ name: 'greet',
26
+ description: 'Greet a user',
27
+ inputSchema: {
28
+ type: 'object',
29
+ properties: {
30
+ name: { type: 'string', description: 'Name to greet' }
31
+ },
32
+ required: ['name']
33
+ },
34
+ handler: async (input) => ({
35
+ content: [{ type: 'text', text: `Hello, ${input.name}!` }]
36
+ })
37
+ }
38
+ ])
39
+ .withHooks([
40
+ {
41
+ event: HookEvent.PostTaskComplete,
42
+ priority: HookPriority.Normal,
43
+ handler: async (ctx) => {
44
+ console.log('Task completed:', ctx.data);
45
+ return { success: true };
46
+ }
47
+ }
48
+ ])
49
+ .build();
50
+
51
+ // Register with the default registry
52
+ import { getDefaultRegistry } from '@claude-flow/plugins';
53
+ await getDefaultRegistry().register(myPlugin);
54
+ ```
55
+
56
+ ### Quick Plugin Creators
57
+
58
+ ```typescript
59
+ import { createToolPlugin, createHooksPlugin, createWorkerPlugin } from '@claude-flow/plugins';
60
+
61
+ // Tool-only plugin
62
+ const toolPlugin = createToolPlugin('my-tools', '1.0.0', [
63
+ { name: 'tool1', description: '...', inputSchema: {...}, handler: async () => {...} }
64
+ ]);
65
+
66
+ // Hooks-only plugin
67
+ const hooksPlugin = createHooksPlugin('my-hooks', '1.0.0', [
68
+ { event: HookEvent.PreTaskExecute, handler: async (ctx) => ({ success: true }) }
69
+ ]);
70
+
71
+ // Worker plugin
72
+ const workerPlugin = createWorkerPlugin('my-workers', '1.0.0', [
73
+ { type: 'coder', name: 'main-coder', capabilities: ['code-generation'] }
74
+ ]);
75
+ ```
76
+
77
+ ## Features
78
+
79
+ ### 🔧 MCP Tool Builder
80
+
81
+ ```typescript
82
+ import { MCPToolBuilder } from '@claude-flow/plugins';
83
+
84
+ const tool = new MCPToolBuilder('calculate')
85
+ .withDescription('Perform calculations')
86
+ .addStringParam('expression', 'Math expression', { required: true })
87
+ .addBooleanParam('verbose', 'Show steps', { default: false })
88
+ .withHandler(async (input) => {
89
+ const result = eval(input.expression); // Use a safe evaluator in production!
90
+ return { content: [{ type: 'text', text: `Result: ${result}` }] };
91
+ })
92
+ .build();
93
+ ```
94
+
95
+ ### 🎣 Hook System
96
+
97
+ ```typescript
98
+ import { HookBuilder, HookFactory, HookRegistry, HookEvent, HookPriority } from '@claude-flow/plugins';
99
+
100
+ // Create a custom hook with conditions
101
+ const hook = new HookBuilder(HookEvent.PreAgentSpawn)
102
+ .withName('validate-agent')
103
+ .withPriority(HookPriority.High)
104
+ .when((ctx) => ctx.data?.type === 'coder')
105
+ .transform((data) => ({ ...data, validated: true }))
106
+ .handle(async (ctx) => {
107
+ // Validation logic
108
+ return { success: true, data: ctx.data, modified: true };
109
+ })
110
+ .build();
111
+
112
+ // Pre-built hook factories
113
+ const logger = HookFactory.createLogger(HookEvent.PostTaskComplete, console);
114
+ const rateLimiter = HookFactory.createRateLimiter(HookEvent.PreToolCall, { maxPerMinute: 100 });
115
+ const validator = HookFactory.createValidator(HookEvent.PreAgentSpawn, (data) => data.type !== undefined);
116
+ ```
117
+
118
+ ### 👷 Worker Pool
119
+
120
+ ```typescript
121
+ import { WorkerPool, WorkerFactory } from '@claude-flow/plugins';
122
+
123
+ // Create a worker pool
124
+ const pool = new WorkerPool({
125
+ minWorkers: 2,
126
+ maxWorkers: 10,
127
+ taskQueueSize: 100
128
+ });
129
+
130
+ // Spawn workers using factory
131
+ const coder = await pool.spawn(WorkerFactory.createCoder('main-coder'));
132
+ const reviewer = await pool.spawn(WorkerFactory.createReviewer('code-reviewer'));
133
+ const tester = await pool.spawn(WorkerFactory.createTester('test-runner'));
134
+
135
+ // Submit tasks
136
+ const result = await pool.submit({
137
+ id: 'task-1',
138
+ type: 'code-generation',
139
+ input: { prompt: 'Write a function...' }
140
+ });
141
+
142
+ // Shutdown
143
+ await pool.shutdown();
144
+ ```
145
+
146
+ ### 🤖 LLM Provider Integration
147
+
148
+ ```typescript
149
+ import { ProviderRegistry, ProviderFactory, BaseLLMProvider } from '@claude-flow/plugins';
150
+
151
+ const registry = new ProviderRegistry({
152
+ fallbackChain: ['anthropic', 'openai'],
153
+ costOptimization: true
154
+ });
155
+
156
+ // Register built-in providers
157
+ class ClaudeProvider extends BaseLLMProvider {
158
+ constructor() {
159
+ super(ProviderFactory.createClaude());
160
+ }
161
+
162
+ async complete(request) {
163
+ // Implementation
164
+ }
165
+ }
166
+
167
+ registry.register(new ClaudeProvider());
168
+
169
+ // Execute with automatic fallback
170
+ const response = await registry.execute({
171
+ model: 'claude-sonnet-4-20250514',
172
+ messages: [{ role: 'user', content: 'Hello!' }]
173
+ });
174
+ ```
175
+
176
+ ### 🔗 Agentic Flow Integration
177
+
178
+ ```typescript
179
+ import { AgenticFlowBridge, AgentDBBridge } from '@claude-flow/plugins';
180
+
181
+ // Swarm coordination
182
+ const agentic = new AgenticFlowBridge({ maxConcurrentAgents: 15 });
183
+ await agentic.initializeSwarm({ type: 'hierarchical', maxAgents: 15 });
184
+
185
+ const agent = await agentic.spawnAgent({
186
+ type: 'coder',
187
+ capabilities: ['typescript', 'react']
188
+ });
189
+
190
+ const result = await agentic.orchestrateTask({
191
+ taskType: 'code-generation',
192
+ input: { prompt: '...' },
193
+ agentId: agent.id
194
+ });
195
+
196
+ // Vector storage with AgentDB
197
+ const agentdb = new AgentDBBridge({ dimensions: 1536, indexType: 'hnsw' });
198
+ await agentdb.initialize();
199
+
200
+ await agentdb.store('doc-1', embeddings, { type: 'document' });
201
+ const similar = await agentdb.search(queryVector, { limit: 10 });
202
+ ```
203
+
204
+ ### 🔒 Security Utilities
205
+
206
+ ```typescript
207
+ import { Security, createRateLimiter, createResourceLimiter } from '@claude-flow/plugins';
208
+
209
+ // Input validation
210
+ const name = Security.validateString(input, { minLength: 1, maxLength: 100 });
211
+ const count = Security.validateNumber(input, { min: 0, max: 1000, integer: true });
212
+ const path = Security.validatePath(input, { allowedExtensions: ['.ts', '.js'] });
213
+
214
+ // Safe path creation (prevents traversal attacks)
215
+ const safePath = Security.safePath('/project', 'src', userInput);
216
+
217
+ // Safe JSON parsing (prevents prototype pollution)
218
+ const data = Security.safeJsonParse<Config>(jsonString);
219
+
220
+ // Command validation
221
+ const cmd = Security.validateCommand('npm install', { allowedCommands: new Set(['npm', 'npx']) });
222
+
223
+ // Rate limiting
224
+ const limiter = createRateLimiter({ maxTokens: 100, refillRate: 10, refillInterval: 1000 });
225
+ if (limiter.tryAcquire()) {
226
+ // Proceed
227
+ }
228
+
229
+ // Resource limiting
230
+ const resourceLimiter = createResourceLimiter({ maxMemoryMB: 512, maxExecutionTime: 30000 });
231
+ const result = await resourceLimiter.enforce(async () => {
232
+ // Heavy computation
233
+ });
234
+ ```
235
+
236
+ ## API Reference
237
+
238
+ ### Core Exports
239
+
240
+ | Export | Description |
241
+ |--------|-------------|
242
+ | `PluginBuilder` | Fluent builder for creating plugins |
243
+ | `BasePlugin` | Abstract base class for plugins |
244
+ | `PluginRegistry` | Plugin lifecycle management |
245
+ | `getDefaultRegistry()` | Get the default plugin registry |
246
+
247
+ ### SDK Builders
248
+
249
+ | Export | Description |
250
+ |--------|-------------|
251
+ | `MCPToolBuilder` | Build MCP tools with parameters |
252
+ | `HookBuilder` | Build hooks with conditions and transformers |
253
+ | `WorkerBuilder` | Build worker definitions |
254
+
255
+ ### Quick Creators
256
+
257
+ | Export | Description |
258
+ |--------|-------------|
259
+ | `createToolPlugin()` | Create a tool-only plugin |
260
+ | `createHooksPlugin()` | Create a hooks-only plugin |
261
+ | `createWorkerPlugin()` | Create a worker plugin |
262
+ | `createProviderPlugin()` | Create a provider plugin |
263
+
264
+ ### Hook System
265
+
266
+ | Export | Description |
267
+ |--------|-------------|
268
+ | `HookRegistry` | Central hook management |
269
+ | `HookExecutor` | Execute hooks with patterns |
270
+ | `HookFactory` | Pre-built hook creators |
271
+ | `HookEvent` | All hook event types |
272
+ | `HookPriority` | Hook priority levels |
273
+
274
+ ### Workers
275
+
276
+ | Export | Description |
277
+ |--------|-------------|
278
+ | `WorkerPool` | Managed worker pool |
279
+ | `WorkerInstance` | Individual worker |
280
+ | `WorkerFactory` | Worker definition factory |
281
+
282
+ ### Providers
283
+
284
+ | Export | Description |
285
+ |--------|-------------|
286
+ | `ProviderRegistry` | LLM provider management |
287
+ | `BaseLLMProvider` | Base provider implementation |
288
+ | `ProviderFactory` | Provider definition factory |
289
+
290
+ ### Integrations
291
+
292
+ | Export | Description |
293
+ |--------|-------------|
294
+ | `AgenticFlowBridge` | agentic-flow@alpha integration |
295
+ | `AgentDBBridge` | AgentDB vector storage |
296
+
297
+ ### Security
298
+
299
+ | Export | Description |
300
+ |--------|-------------|
301
+ | `Security` | All security utilities |
302
+ | `validateString/Number/Boolean/Array/Enum` | Input validators |
303
+ | `safePath/safePathAsync` | Path security |
304
+ | `safeJsonParse/safeJsonStringify` | JSON security |
305
+ | `createRateLimiter` | Rate limiting |
306
+ | `createResourceLimiter` | Resource limiting |
307
+
308
+ ## Hook Events
309
+
310
+ ```typescript
311
+ enum HookEvent {
312
+ // Session lifecycle
313
+ SessionStart = 'session:start',
314
+ SessionEnd = 'session:end',
315
+
316
+ // Agent lifecycle
317
+ PreAgentSpawn = 'agent:pre-spawn',
318
+ PostAgentSpawn = 'agent:post-spawn',
319
+ PreAgentTerminate = 'agent:pre-terminate',
320
+ PostAgentTerminate = 'agent:post-terminate',
321
+
322
+ // Task lifecycle
323
+ PreTaskExecute = 'task:pre-execute',
324
+ PostTaskComplete = 'task:post-complete',
325
+ TaskError = 'task:error',
326
+
327
+ // Tool lifecycle
328
+ PreToolCall = 'tool:pre-call',
329
+ PostToolCall = 'tool:post-call',
330
+
331
+ // Memory operations
332
+ PreMemoryStore = 'memory:pre-store',
333
+ PostMemoryStore = 'memory:post-store',
334
+ PreMemoryRetrieve = 'memory:pre-retrieve',
335
+ PostMemoryRetrieve = 'memory:post-retrieve',
336
+
337
+ // Swarm coordination
338
+ SwarmInitialized = 'swarm:initialized',
339
+ SwarmShutdown = 'swarm:shutdown',
340
+ ConsensusReached = 'swarm:consensus-reached',
341
+
342
+ // File operations
343
+ PreFileRead = 'file:pre-read',
344
+ PostFileRead = 'file:post-read',
345
+ PreFileWrite = 'file:pre-write',
346
+ PostFileWrite = 'file:post-write',
347
+
348
+ // Commands
349
+ PreCommand = 'command:pre-execute',
350
+ PostCommand = 'command:post-execute',
351
+
352
+ // Learning
353
+ PatternLearned = 'learning:pattern-learned',
354
+ PatternApplied = 'learning:pattern-applied',
355
+ }
356
+ ```
357
+
358
+ ## Hook Priorities
359
+
360
+ ```typescript
361
+ enum HookPriority {
362
+ Critical = 1000, // Run first, can abort
363
+ High = 750, // Important hooks
364
+ Normal = 500, // Default priority
365
+ Low = 250, // Less important
366
+ Deferred = 0, // Run last
367
+ }
368
+ ```
369
+
370
+ ## Worker Types
371
+
372
+ - `coder` - Code implementation
373
+ - `reviewer` - Code review
374
+ - `tester` - Test generation/execution
375
+ - `researcher` - Information gathering
376
+ - `planner` - Task planning
377
+ - `coordinator` - Multi-agent coordination
378
+ - `security` - Security analysis
379
+ - `performance` - Performance optimization
380
+ - `specialized` - Custom capabilities
381
+ - `long-running` - Background tasks
382
+
383
+ ## Performance
384
+
385
+ | Metric | Target | Actual |
386
+ |--------|--------|--------|
387
+ | Plugin load time | < 50ms | ~20ms |
388
+ | Hook execution | < 1ms | ~0.5ms |
389
+ | Worker spawn | < 100ms | ~50ms |
390
+ | Vector search (10K) | < 10ms | ~5ms |
391
+
392
+ ## Testing
393
+
394
+ ```bash
395
+ npm test # Run all tests
396
+ npm run test:watch # Watch mode
397
+ ```
398
+
399
+ ## License
400
+
401
+ MIT