@ruvector/ruvllm 2.5.6 → 2.6.0

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 (71) hide show
  1. package/README.md +282 -282
  2. package/bin/cli.js +1020 -1020
  3. package/dist/cjs/benchmarks/embedding-benchmark.js +1 -1
  4. package/dist/cjs/benchmarks/index.js +1 -1
  5. package/dist/cjs/benchmarks/model-comparison.js +1 -1
  6. package/dist/cjs/benchmarks/routing-benchmark.js +1 -1
  7. package/dist/cjs/contrastive.js +70 -70
  8. package/dist/cjs/engine.js +13 -13
  9. package/dist/cjs/export.js +31 -31
  10. package/dist/cjs/federated.js +1 -1
  11. package/dist/cjs/index.js +1 -1
  12. package/dist/cjs/intelligence.js +1 -1
  13. package/dist/cjs/lora.d.ts +11 -0
  14. package/dist/cjs/lora.d.ts.map +1 -1
  15. package/dist/cjs/lora.js +16 -1
  16. package/dist/cjs/models.js +1 -1
  17. package/dist/cjs/native.js +1 -1
  18. package/dist/cjs/session.js +1 -1
  19. package/dist/cjs/simd.js +1 -1
  20. package/dist/cjs/sona.js +1 -1
  21. package/dist/cjs/streaming.js +1 -1
  22. package/dist/cjs/training.d.ts +66 -8
  23. package/dist/cjs/training.d.ts.map +1 -1
  24. package/dist/cjs/training.js +145 -15
  25. package/dist/cjs/types.d.ts +7 -0
  26. package/dist/cjs/types.d.ts.map +1 -1
  27. package/dist/cjs/types.js +1 -1
  28. package/dist/esm/benchmarks/embedding-benchmark.js +1 -1
  29. package/dist/esm/benchmarks/index.js +1 -1
  30. package/dist/esm/benchmarks/model-comparison.js +1 -1
  31. package/dist/esm/benchmarks/routing-benchmark.js +1 -1
  32. package/dist/esm/contrastive.js +70 -70
  33. package/dist/esm/engine.js +13 -13
  34. package/dist/esm/export.js +31 -31
  35. package/dist/esm/federated.js +1 -1
  36. package/dist/esm/index.js +1 -1
  37. package/dist/esm/intelligence.js +1 -1
  38. package/dist/esm/lora.d.ts +11 -0
  39. package/dist/esm/lora.d.ts.map +1 -1
  40. package/dist/esm/lora.js +16 -1
  41. package/dist/esm/models.js +1 -1
  42. package/dist/esm/native.js +1 -1
  43. package/dist/esm/session.js +1 -1
  44. package/dist/esm/simd.js +1 -1
  45. package/dist/esm/sona.js +1 -1
  46. package/dist/esm/streaming.js +1 -1
  47. package/dist/esm/training.d.ts +66 -8
  48. package/dist/esm/training.d.ts.map +1 -1
  49. package/dist/esm/training.js +145 -15
  50. package/dist/esm/types.d.ts +7 -0
  51. package/dist/esm/types.d.ts.map +1 -1
  52. package/dist/esm/types.js +1 -1
  53. package/package.json +133 -133
  54. package/scripts/ensemble-model-compare.js +287 -287
  55. package/scripts/huggingface/README.md +537 -537
  56. package/scripts/huggingface/publish.sh +112 -112
  57. package/scripts/hybrid-model-compare.js +373 -373
  58. package/scripts/improved-model-compare.js +288 -288
  59. package/scripts/optimized-model-compare.js +364 -364
  60. package/scripts/real-model-compare.js +280 -280
  61. package/scripts/training/agentic-flow-capabilities.json +329 -329
  62. package/scripts/training/claude-code-synth.js +505 -505
  63. package/scripts/training/claude-flow-capabilities.json +1322 -1322
  64. package/scripts/training/claude-hard-negatives.js +222 -222
  65. package/scripts/training/contrastive-finetune.js +517 -517
  66. package/scripts/training/ecosystem-triplets.jsonl +1466 -1466
  67. package/scripts/training/generate-ecosystem-triplets.js +1324 -1324
  68. package/scripts/training/routing-dataset.js +634 -634
  69. package/scripts/training/ruvector-capabilities.json +798 -798
  70. package/scripts/training/validate-ecosystem.js +381 -381
  71. package/scripts/training/validation-results.json +22 -22
@@ -1,1324 +1,1324 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Ecosystem Training Data Generator for RuvLTRA
4
- *
5
- * Generates comprehensive triplet training data for the Claude Flow ecosystem:
6
- * - claude-flow: Multi-agent coordination and swarm orchestration
7
- * - agentic-flow: AI workflow orchestration and ONNX embeddings
8
- * - ruvector: High-performance vector database
9
- *
10
- * Features:
11
- * - Reads capability definitions from JSON files
12
- * - Generates 5-10 natural language prompts per capability
13
- * - Creates hard negatives for contrastive learning
14
- * - Outputs combined JSONL dataset for fine-tuning
15
- */
16
-
17
- const fs = require('fs');
18
- const path = require('path');
19
-
20
- // ============================================================================
21
- // CAPABILITY DEFINITIONS
22
- // ============================================================================
23
-
24
- /**
25
- * Claude Flow V3 Capabilities
26
- * Multi-agent swarm coordination, memory, hooks, workflows
27
- */
28
- const CLAUDE_FLOW_CAPABILITIES = {
29
- name: 'claude-flow',
30
- description: 'Multi-agent swarm coordination and orchestration framework',
31
- version: '3.0.0',
32
- categories: {
33
- swarm: {
34
- description: 'Multi-agent swarm coordination and topology management',
35
- commands: {
36
- 'swarm init': {
37
- description: 'Initialize a swarm with specified topology',
38
- keywords: ['swarm', 'init', 'initialize', 'topology', 'multi-agent', 'coordination'],
39
- parameters: ['--topology', '--max-agents', '--strategy'],
40
- },
41
- 'swarm status': {
42
- description: 'Get current swarm status and agent health',
43
- keywords: ['swarm', 'status', 'health', 'agents', 'monitoring'],
44
- parameters: ['--verbose'],
45
- },
46
- 'swarm shutdown': {
47
- description: 'Gracefully shutdown the swarm',
48
- keywords: ['swarm', 'shutdown', 'stop', 'terminate', 'graceful'],
49
- parameters: ['--graceful', '--force'],
50
- },
51
- },
52
- },
53
- agent: {
54
- description: 'Agent lifecycle management',
55
- commands: {
56
- 'agent spawn': {
57
- description: 'Spawn a new agent with specified type',
58
- keywords: ['agent', 'spawn', 'create', 'start', 'worker'],
59
- parameters: ['-t', '--type', '--name', '--model'],
60
- },
61
- 'agent list': {
62
- description: 'List all active agents',
63
- keywords: ['agent', 'list', 'show', 'active', 'running'],
64
- parameters: ['--status', '--domain'],
65
- },
66
- 'agent terminate': {
67
- description: 'Terminate a specific agent',
68
- keywords: ['agent', 'terminate', 'kill', 'stop', 'remove'],
69
- parameters: ['--force'],
70
- },
71
- 'agent status': {
72
- description: 'Get status of a specific agent',
73
- keywords: ['agent', 'status', 'info', 'details', 'health'],
74
- parameters: ['--agentId'],
75
- },
76
- },
77
- },
78
- memory: {
79
- description: 'Persistent memory with vector search',
80
- commands: {
81
- 'memory store': {
82
- description: 'Store a value in memory with optional namespace',
83
- keywords: ['memory', 'store', 'save', 'persist', 'key-value'],
84
- parameters: ['--key', '--value', '--namespace', '--ttl'],
85
- },
86
- 'memory retrieve': {
87
- description: 'Retrieve a value from memory by key',
88
- keywords: ['memory', 'retrieve', 'get', 'fetch', 'read'],
89
- parameters: ['--key', '--namespace'],
90
- },
91
- 'memory search': {
92
- description: 'Semantic vector search in memory',
93
- keywords: ['memory', 'search', 'query', 'find', 'semantic', 'vector'],
94
- parameters: ['--query', '--namespace', '--limit', '--threshold'],
95
- },
96
- 'memory list': {
97
- description: 'List memory entries',
98
- keywords: ['memory', 'list', 'entries', 'keys', 'show'],
99
- parameters: ['--namespace', '--limit'],
100
- },
101
- 'memory delete': {
102
- description: 'Delete a memory entry',
103
- keywords: ['memory', 'delete', 'remove', 'clear'],
104
- parameters: ['--key', '--namespace'],
105
- },
106
- },
107
- },
108
- hooks: {
109
- description: 'Self-learning hooks and background workers',
110
- commands: {
111
- 'hooks pre-task': {
112
- description: 'Get agent suggestions before starting a task',
113
- keywords: ['hooks', 'pre-task', 'routing', 'suggestions', 'before'],
114
- parameters: ['--description', '--taskId'],
115
- },
116
- 'hooks post-task': {
117
- description: 'Record task completion for learning',
118
- keywords: ['hooks', 'post-task', 'completion', 'learning', 'after'],
119
- parameters: ['--taskId', '--success', '--quality'],
120
- },
121
- 'hooks route': {
122
- description: 'Route task to optimal agent',
123
- keywords: ['hooks', 'route', 'routing', 'optimal', 'agent'],
124
- parameters: ['--task', '--context'],
125
- },
126
- 'hooks worker dispatch': {
127
- description: 'Dispatch a background worker',
128
- keywords: ['hooks', 'worker', 'dispatch', 'background', 'trigger'],
129
- parameters: ['--trigger', '--context', '--priority'],
130
- },
131
- 'hooks metrics': {
132
- description: 'View learning metrics dashboard',
133
- keywords: ['hooks', 'metrics', 'dashboard', 'stats', 'learning'],
134
- parameters: ['--period', '--format'],
135
- },
136
- 'hooks pretrain': {
137
- description: 'Bootstrap intelligence from repository',
138
- keywords: ['hooks', 'pretrain', 'bootstrap', 'intelligence', 'analyze'],
139
- parameters: ['--path', '--depth'],
140
- },
141
- },
142
- },
143
- workflow: {
144
- description: 'Workflow execution and templates',
145
- commands: {
146
- 'workflow create': {
147
- description: 'Create a new workflow',
148
- keywords: ['workflow', 'create', 'new', 'define'],
149
- parameters: ['--name', '--steps', '--description'],
150
- },
151
- 'workflow execute': {
152
- description: 'Execute a workflow',
153
- keywords: ['workflow', 'execute', 'run', 'start'],
154
- parameters: ['--workflowId', '--variables'],
155
- },
156
- 'workflow status': {
157
- description: 'Get workflow execution status',
158
- keywords: ['workflow', 'status', 'progress', 'state'],
159
- parameters: ['--workflowId', '--verbose'],
160
- },
161
- },
162
- },
163
- hivemind: {
164
- description: 'Hive-mind collective consensus',
165
- commands: {
166
- 'hive-mind init': {
167
- description: 'Initialize hive-mind collective',
168
- keywords: ['hive-mind', 'init', 'collective', 'consensus'],
169
- parameters: ['--topology', '--queenId'],
170
- },
171
- 'hive-mind spawn': {
172
- description: 'Spawn workers and join to hive-mind',
173
- keywords: ['hive-mind', 'spawn', 'workers', 'join'],
174
- parameters: ['--count', '--prefix', '--role'],
175
- },
176
- 'hive-mind consensus': {
177
- description: 'Propose or vote on consensus',
178
- keywords: ['hive-mind', 'consensus', 'vote', 'propose'],
179
- parameters: ['--action', '--proposalId', '--vote'],
180
- },
181
- 'hive-mind broadcast': {
182
- description: 'Broadcast message to all workers',
183
- keywords: ['hive-mind', 'broadcast', 'message', 'all'],
184
- parameters: ['--message', '--priority'],
185
- },
186
- },
187
- },
188
- task: {
189
- description: 'Task creation and management',
190
- commands: {
191
- 'task create': {
192
- description: 'Create a new task',
193
- keywords: ['task', 'create', 'new', 'add'],
194
- parameters: ['--type', '--description', '--priority'],
195
- },
196
- 'task list': {
197
- description: 'List all tasks',
198
- keywords: ['task', 'list', 'show', 'all'],
199
- parameters: ['--status', '--priority'],
200
- },
201
- 'task complete': {
202
- description: 'Mark task as complete',
203
- keywords: ['task', 'complete', 'done', 'finish'],
204
- parameters: ['--taskId', '--result'],
205
- },
206
- },
207
- },
208
- session: {
209
- description: 'Session state management',
210
- commands: {
211
- 'session save': {
212
- description: 'Save current session state',
213
- keywords: ['session', 'save', 'persist', 'state'],
214
- parameters: ['--name', '--description'],
215
- },
216
- 'session restore': {
217
- description: 'Restore a saved session',
218
- keywords: ['session', 'restore', 'load', 'resume'],
219
- parameters: ['--sessionId', '--name'],
220
- },
221
- 'session list': {
222
- description: 'List saved sessions',
223
- keywords: ['session', 'list', 'saved', 'history'],
224
- parameters: ['--limit'],
225
- },
226
- },
227
- },
228
- neural: {
229
- description: 'Neural pattern training and prediction',
230
- commands: {
231
- 'neural train': {
232
- description: 'Train a neural model',
233
- keywords: ['neural', 'train', 'model', 'learning'],
234
- parameters: ['--modelType', '--epochs', '--learningRate'],
235
- },
236
- 'neural predict': {
237
- description: 'Make predictions using neural model',
238
- keywords: ['neural', 'predict', 'inference', 'model'],
239
- parameters: ['--input', '--modelId'],
240
- },
241
- 'neural patterns': {
242
- description: 'Manage neural patterns',
243
- keywords: ['neural', 'patterns', 'store', 'search'],
244
- parameters: ['--action', '--patternId'],
245
- },
246
- },
247
- },
248
- security: {
249
- description: 'Security scanning and threat detection',
250
- commands: {
251
- 'aidefence scan': {
252
- description: 'Scan input for AI manipulation threats',
253
- keywords: ['aidefence', 'scan', 'security', 'threats', 'injection'],
254
- parameters: ['--input', '--quick'],
255
- },
256
- 'aidefence analyze': {
257
- description: 'Deep analysis for threat types',
258
- keywords: ['aidefence', 'analyze', 'deep', 'threats'],
259
- parameters: ['--input', '--searchSimilar'],
260
- },
261
- 'aidefence is_safe': {
262
- description: 'Quick boolean safety check',
263
- keywords: ['aidefence', 'safe', 'check', 'validate'],
264
- parameters: ['--input'],
265
- },
266
- },
267
- },
268
- performance: {
269
- description: 'Performance profiling and optimization',
270
- commands: {
271
- 'performance benchmark': {
272
- description: 'Run performance benchmarks',
273
- keywords: ['performance', 'benchmark', 'speed', 'test'],
274
- parameters: ['--suite', '--iterations'],
275
- },
276
- 'performance profile': {
277
- description: 'Profile specific component',
278
- keywords: ['performance', 'profile', 'analyze', 'bottleneck'],
279
- parameters: ['--target', '--duration'],
280
- },
281
- 'performance optimize': {
282
- description: 'Apply performance optimizations',
283
- keywords: ['performance', 'optimize', 'improve', 'speed'],
284
- parameters: ['--target', '--aggressive'],
285
- },
286
- },
287
- },
288
- embeddings: {
289
- description: 'Vector embeddings with ONNX',
290
- commands: {
291
- 'embeddings generate': {
292
- description: 'Generate embeddings for text',
293
- keywords: ['embeddings', 'generate', 'embed', 'vector'],
294
- parameters: ['--text', '--hyperbolic'],
295
- },
296
- 'embeddings compare': {
297
- description: 'Compare similarity between texts',
298
- keywords: ['embeddings', 'compare', 'similarity', 'distance'],
299
- parameters: ['--text1', '--text2', '--metric'],
300
- },
301
- 'embeddings search': {
302
- description: 'Semantic search across stored embeddings',
303
- keywords: ['embeddings', 'search', 'semantic', 'query'],
304
- parameters: ['--query', '--topK', '--threshold'],
305
- },
306
- },
307
- },
308
- claims: {
309
- description: 'Issue claiming and coordination',
310
- commands: {
311
- 'claims claim': {
312
- description: 'Claim an issue for work',
313
- keywords: ['claims', 'claim', 'issue', 'work', 'assign'],
314
- parameters: ['--issueId', '--claimant'],
315
- },
316
- 'claims release': {
317
- description: 'Release a claim on an issue',
318
- keywords: ['claims', 'release', 'unclaim', 'free'],
319
- parameters: ['--issueId', '--reason'],
320
- },
321
- 'claims handoff': {
322
- description: 'Handoff issue to another claimant',
323
- keywords: ['claims', 'handoff', 'transfer', 'pass'],
324
- parameters: ['--issueId', '--from', '--to'],
325
- },
326
- 'claims board': {
327
- description: 'View claims board',
328
- keywords: ['claims', 'board', 'view', 'overview'],
329
- parameters: [],
330
- },
331
- },
332
- },
333
- },
334
- };
335
-
336
- /**
337
- * Agentic Flow Capabilities
338
- * AI workflow orchestration and ONNX embeddings
339
- */
340
- const AGENTIC_FLOW_CAPABILITIES = {
341
- name: 'agentic-flow',
342
- description: 'AI workflow orchestration with ONNX runtime and vector embeddings',
343
- version: '1.0.0',
344
- categories: {
345
- embeddings: {
346
- description: 'High-performance ONNX embeddings',
347
- commands: {
348
- 'embed': {
349
- description: 'Generate embeddings for text using ONNX models',
350
- keywords: ['embed', 'embedding', 'vector', 'encode', 'onnx'],
351
- parameters: ['--text', '--model', '--normalize'],
352
- },
353
- 'batch-embed': {
354
- description: 'Batch embed multiple texts efficiently',
355
- keywords: ['batch', 'embed', 'multiple', 'parallel'],
356
- parameters: ['--texts', '--concurrency'],
357
- },
358
- 'similarity': {
359
- description: 'Compute similarity between embeddings',
360
- keywords: ['similarity', 'cosine', 'distance', 'compare'],
361
- parameters: ['--a', '--b', '--metric'],
362
- },
363
- },
364
- },
365
- models: {
366
- description: 'ONNX model management',
367
- commands: {
368
- 'model load': {
369
- description: 'Load an ONNX model for inference',
370
- keywords: ['model', 'load', 'onnx', 'initialize'],
371
- parameters: ['--path', '--name'],
372
- },
373
- 'model list': {
374
- description: 'List available models',
375
- keywords: ['model', 'list', 'available', 'show'],
376
- parameters: [],
377
- },
378
- 'model info': {
379
- description: 'Get model information and metadata',
380
- keywords: ['model', 'info', 'metadata', 'details'],
381
- parameters: ['--name'],
382
- },
383
- 'model quantize': {
384
- description: 'Quantize model for faster inference',
385
- keywords: ['model', 'quantize', 'compress', 'optimize'],
386
- parameters: ['--input', '--output', '--bits'],
387
- },
388
- },
389
- },
390
- pipeline: {
391
- description: 'Workflow pipeline orchestration',
392
- commands: {
393
- 'pipeline create': {
394
- description: 'Create a new processing pipeline',
395
- keywords: ['pipeline', 'create', 'workflow', 'chain'],
396
- parameters: ['--name', '--steps'],
397
- },
398
- 'pipeline run': {
399
- description: 'Execute a pipeline with input data',
400
- keywords: ['pipeline', 'run', 'execute', 'process'],
401
- parameters: ['--name', '--input'],
402
- },
403
- 'pipeline visualize': {
404
- description: 'Visualize pipeline structure',
405
- keywords: ['pipeline', 'visualize', 'graph', 'diagram'],
406
- parameters: ['--name', '--format'],
407
- },
408
- },
409
- },
410
- cache: {
411
- description: 'Embedding cache management',
412
- commands: {
413
- 'cache set': {
414
- description: 'Store embedding in cache',
415
- keywords: ['cache', 'set', 'store', 'save'],
416
- parameters: ['--key', '--embedding'],
417
- },
418
- 'cache get': {
419
- description: 'Retrieve embedding from cache',
420
- keywords: ['cache', 'get', 'retrieve', 'fetch'],
421
- parameters: ['--key'],
422
- },
423
- 'cache clear': {
424
- description: 'Clear embedding cache',
425
- keywords: ['cache', 'clear', 'flush', 'reset'],
426
- parameters: ['--namespace'],
427
- },
428
- 'cache stats': {
429
- description: 'Get cache statistics',
430
- keywords: ['cache', 'stats', 'statistics', 'info'],
431
- parameters: [],
432
- },
433
- },
434
- },
435
- search: {
436
- description: 'Vector search operations',
437
- commands: {
438
- 'search nearest': {
439
- description: 'Find nearest neighbors to query vector',
440
- keywords: ['search', 'nearest', 'neighbors', 'knn'],
441
- parameters: ['--query', '--k', '--threshold'],
442
- },
443
- 'search range': {
444
- description: 'Range search within distance threshold',
445
- keywords: ['search', 'range', 'radius', 'threshold'],
446
- parameters: ['--query', '--radius'],
447
- },
448
- 'search hybrid': {
449
- description: 'Hybrid search combining keyword and semantic',
450
- keywords: ['search', 'hybrid', 'combined', 'keyword', 'semantic'],
451
- parameters: ['--query', '--alpha'],
452
- },
453
- },
454
- },
455
- },
456
- };
457
-
458
- /**
459
- * RuVector Capabilities
460
- * High-performance vector database
461
- */
462
- const RUVECTOR_CAPABILITIES = {
463
- name: 'ruvector',
464
- description: 'High-performance vector database with HNSW indexing',
465
- version: '0.1.0',
466
- categories: {
467
- collections: {
468
- description: 'Vector collection management',
469
- commands: {
470
- 'collection create': {
471
- description: 'Create a new vector collection',
472
- keywords: ['collection', 'create', 'new', 'database'],
473
- parameters: ['--name', '--dimension', '--metric'],
474
- },
475
- 'collection delete': {
476
- description: 'Delete a vector collection',
477
- keywords: ['collection', 'delete', 'drop', 'remove'],
478
- parameters: ['--name', '--confirm'],
479
- },
480
- 'collection info': {
481
- description: 'Get collection information',
482
- keywords: ['collection', 'info', 'stats', 'details'],
483
- parameters: ['--name'],
484
- },
485
- 'collection list': {
486
- description: 'List all collections',
487
- keywords: ['collection', 'list', 'all', 'show'],
488
- parameters: [],
489
- },
490
- },
491
- },
492
- vectors: {
493
- description: 'Vector CRUD operations',
494
- commands: {
495
- 'vector insert': {
496
- description: 'Insert vectors into collection',
497
- keywords: ['vector', 'insert', 'add', 'upsert'],
498
- parameters: ['--collection', '--vectors', '--ids'],
499
- },
500
- 'vector delete': {
501
- description: 'Delete vectors from collection',
502
- keywords: ['vector', 'delete', 'remove', 'drop'],
503
- parameters: ['--collection', '--ids'],
504
- },
505
- 'vector get': {
506
- description: 'Get vectors by ID',
507
- keywords: ['vector', 'get', 'fetch', 'retrieve'],
508
- parameters: ['--collection', '--ids'],
509
- },
510
- 'vector update': {
511
- description: 'Update existing vectors',
512
- keywords: ['vector', 'update', 'modify', 'change'],
513
- parameters: ['--collection', '--id', '--vector'],
514
- },
515
- },
516
- },
517
- search: {
518
- description: 'Vector search with HNSW',
519
- commands: {
520
- 'search knn': {
521
- description: 'K-nearest neighbor search',
522
- keywords: ['search', 'knn', 'nearest', 'similar'],
523
- parameters: ['--collection', '--query', '--k'],
524
- },
525
- 'search filter': {
526
- description: 'Filtered vector search with metadata',
527
- keywords: ['search', 'filter', 'metadata', 'conditional'],
528
- parameters: ['--collection', '--query', '--filter'],
529
- },
530
- 'search batch': {
531
- description: 'Batch search multiple queries',
532
- keywords: ['search', 'batch', 'multiple', 'parallel'],
533
- parameters: ['--collection', '--queries', '--k'],
534
- },
535
- },
536
- },
537
- index: {
538
- description: 'HNSW index management',
539
- commands: {
540
- 'index build': {
541
- description: 'Build HNSW index for collection',
542
- keywords: ['index', 'build', 'create', 'hnsw'],
543
- parameters: ['--collection', '--ef', '--m'],
544
- },
545
- 'index rebuild': {
546
- description: 'Rebuild existing index',
547
- keywords: ['index', 'rebuild', 'refresh', 'reindex'],
548
- parameters: ['--collection'],
549
- },
550
- 'index stats': {
551
- description: 'Get index statistics',
552
- keywords: ['index', 'stats', 'info', 'metrics'],
553
- parameters: ['--collection'],
554
- },
555
- 'index optimize': {
556
- description: 'Optimize index for search performance',
557
- keywords: ['index', 'optimize', 'tune', 'improve'],
558
- parameters: ['--collection', '--target'],
559
- },
560
- },
561
- },
562
- persistence: {
563
- description: 'Data persistence and backup',
564
- commands: {
565
- 'snapshot create': {
566
- description: 'Create a snapshot of collection',
567
- keywords: ['snapshot', 'create', 'backup', 'save'],
568
- parameters: ['--collection', '--path'],
569
- },
570
- 'snapshot restore': {
571
- description: 'Restore collection from snapshot',
572
- keywords: ['snapshot', 'restore', 'load', 'recover'],
573
- parameters: ['--path', '--collection'],
574
- },
575
- 'snapshot list': {
576
- description: 'List available snapshots',
577
- keywords: ['snapshot', 'list', 'backups', 'show'],
578
- parameters: ['--collection'],
579
- },
580
- },
581
- },
582
- quantization: {
583
- description: 'Vector quantization for memory efficiency',
584
- commands: {
585
- 'quantize apply': {
586
- description: 'Apply quantization to collection',
587
- keywords: ['quantize', 'apply', 'compress', 'reduce'],
588
- parameters: ['--collection', '--type', '--bits'],
589
- },
590
- 'quantize info': {
591
- description: 'Get quantization info',
592
- keywords: ['quantize', 'info', 'status', 'details'],
593
- parameters: ['--collection'],
594
- },
595
- },
596
- },
597
- },
598
- };
599
-
600
- // ============================================================================
601
- // PROMPT TEMPLATES
602
- // ============================================================================
603
-
604
- /**
605
- * Natural language prompt variations for generating diverse training data
606
- * Each template has placeholders for action, object, and description
607
- */
608
- const PROMPT_TEMPLATES = {
609
- // Direct commands
610
- direct: [
611
- '{action} {object}',
612
- '{action} the {object}',
613
- 'Please {action} {object}',
614
- 'I need to {action} {object}',
615
- ],
616
- // Request style
617
- request: [
618
- 'Can you {action} {object}?',
619
- 'Help me {action} {object}',
620
- 'I want to {action} {object}',
621
- 'Could you {action} {object} for me?',
622
- ],
623
- // Question style
624
- question: [
625
- 'How do I {action} {object}?',
626
- 'What\'s the best way to {action} {object}?',
627
- 'How can I {action} {object}?',
628
- 'Which command {desc}?',
629
- ],
630
- // Contextual
631
- contextual: [
632
- 'I\'m trying to {desc}',
633
- 'I need a way to {desc}',
634
- 'My goal is to {desc}',
635
- 'For this project, I need to {desc}',
636
- ],
637
- // Descriptive
638
- descriptive: [
639
- '{desc}',
640
- 'Help with {desc}',
641
- 'I want {desc}',
642
- 'Need {desc}',
643
- ],
644
- };
645
-
646
- /**
647
- * Action verbs mapped to capability types
648
- */
649
- const ACTION_MAPPINGS = {
650
- // Swarm/Agent actions
651
- swarm: ['initialize', 'start', 'create', 'set up', 'configure', 'launch'],
652
- agent: ['spawn', 'create', 'start', 'launch', 'deploy', 'run'],
653
- terminate: ['stop', 'kill', 'terminate', 'shutdown', 'end', 'close'],
654
- status: ['check', 'get', 'view', 'show', 'monitor', 'inspect'],
655
- list: ['list', 'show', 'display', 'enumerate', 'get all'],
656
-
657
- // Memory actions
658
- store: ['store', 'save', 'persist', 'write', 'put', 'cache'],
659
- retrieve: ['retrieve', 'get', 'fetch', 'read', 'load'],
660
- search: ['search', 'find', 'query', 'look up', 'discover'],
661
- delete: ['delete', 'remove', 'clear', 'drop', 'erase'],
662
-
663
- // Workflow actions
664
- create: ['create', 'make', 'build', 'define', 'set up'],
665
- execute: ['execute', 'run', 'start', 'trigger', 'launch'],
666
-
667
- // Vector operations
668
- embed: ['embed', 'encode', 'vectorize', 'generate embedding for'],
669
- insert: ['insert', 'add', 'upsert', 'put', 'store'],
670
- knn: ['find similar', 'search for nearest', 'query neighbors', 'find k-nearest'],
671
-
672
- // Index operations
673
- build: ['build', 'create', 'construct', 'generate'],
674
- optimize: ['optimize', 'tune', 'improve', 'speed up'],
675
- rebuild: ['rebuild', 'regenerate', 'refresh', 'recreate'],
676
- };
677
-
678
- // ============================================================================
679
- // HARD NEGATIVE PATTERNS
680
- // ============================================================================
681
-
682
- /**
683
- * Confusing command pairs for hard negative generation
684
- * These are commands that sound similar but have different purposes
685
- */
686
- const CONFUSING_PAIRS = [
687
- // Claude Flow internal confusion
688
- { cmd1: 'memory store', cmd2: 'memory search', reason: 'both involve memory' },
689
- { cmd1: 'agent spawn', cmd2: 'hive-mind spawn', reason: 'both spawn workers' },
690
- { cmd1: 'swarm init', cmd2: 'hive-mind init', reason: 'both initialize coordination' },
691
- { cmd1: 'hooks route', cmd2: 'hooks pre-task', reason: 'both involve task routing' },
692
- { cmd1: 'workflow execute', cmd2: 'task create', reason: 'both start work' },
693
- { cmd1: 'session save', cmd2: 'memory store', reason: 'both persist data' },
694
- { cmd1: 'neural train', cmd2: 'hooks pretrain', reason: 'both involve training' },
695
- { cmd1: 'embeddings search', cmd2: 'memory search', reason: 'both search semantically' },
696
- { cmd1: 'performance profile', cmd2: 'performance benchmark', reason: 'both analyze performance' },
697
- { cmd1: 'claims claim', cmd2: 'task create', reason: 'both assign work' },
698
-
699
- // Cross-tool confusion
700
- { cmd1: 'claude-flow memory search', cmd2: 'ruvector search knn', reason: 'both do vector search' },
701
- { cmd1: 'claude-flow embeddings generate', cmd2: 'agentic-flow embed', reason: 'both generate embeddings' },
702
- { cmd1: 'ruvector collection create', cmd2: 'claude-flow memory store', reason: 'both store data' },
703
- { cmd1: 'agentic-flow cache set', cmd2: 'claude-flow memory store', reason: 'both cache data' },
704
- { cmd1: 'ruvector index build', cmd2: 'claude-flow hooks pretrain', reason: 'both build indexes' },
705
- { cmd1: 'agentic-flow search hybrid', cmd2: 'ruvector search filter', reason: 'both filtered search' },
706
- { cmd1: 'claude-flow swarm init', cmd2: 'agentic-flow pipeline create', reason: 'both orchestrate work' },
707
-
708
- // Category confusion
709
- { cmd1: 'ruvector vector insert', cmd2: 'agentic-flow cache set', reason: 'both store vectors' },
710
- { cmd1: 'claude-flow agent list', cmd2: 'agentic-flow model list', reason: 'both list resources' },
711
- { cmd1: 'ruvector snapshot create', cmd2: 'claude-flow session save', reason: 'both create backups' },
712
- { cmd1: 'agentic-flow model quantize', cmd2: 'ruvector quantize apply', reason: 'both quantize' },
713
- ];
714
-
715
- // ============================================================================
716
- // TRIPLET GENERATION
717
- // ============================================================================
718
-
719
- /**
720
- * Generate natural language prompts for a capability
721
- */
722
- function generatePrompts(capability, command, config) {
723
- const prompts = [];
724
- const { description, keywords } = config;
725
-
726
- // Extract action and object from command
727
- const parts = command.split(' ');
728
- const category = parts[0];
729
- const action = parts[1] || parts[0];
730
-
731
- // Get action variations - but avoid repeating category name as action
732
- const actionVariations = ACTION_MAPPINGS[action] || [action];
733
- const primaryAction = actionVariations[0];
734
-
735
- // Create clean description for prompts
736
- const descLower = description.toLowerCase();
737
-
738
- // Avoid redundant phrases like "search search" or "status status"
739
- const isActionSameAsCategory = primaryAction.toLowerCase() === category.toLowerCase();
740
-
741
- // Direct commands: "{action} {object}"
742
- if (!isActionSameAsCategory) {
743
- prompts.push(`${primaryAction} ${category}`);
744
- prompts.push(`${primaryAction} the ${category}`);
745
- prompts.push(`I need to ${primaryAction} ${category}`);
746
- prompts.push(`Can you ${primaryAction} ${category}?`);
747
- prompts.push(`Help me ${primaryAction} ${category}`);
748
- } else {
749
- // When action == category, use description instead
750
- prompts.push(`${primaryAction}`);
751
- prompts.push(`I need to ${primaryAction}`);
752
- prompts.push(`Help me ${primaryAction}`);
753
- }
754
-
755
- // Use description-based prompts (always good quality)
756
- prompts.push(`I want to ${descLower}`);
757
- prompts.push(`How do I ${descLower}?`);
758
- prompts.push(`I need a way to ${descLower}`);
759
-
760
- // Action variations (skip if redundant)
761
- for (const actionVar of actionVariations.slice(1, 3)) {
762
- if (actionVar.toLowerCase() !== category.toLowerCase()) {
763
- prompts.push(`${actionVar} ${category}`);
764
- prompts.push(`I want to ${actionVar} ${category}`);
765
- }
766
- }
767
-
768
- // Keyword-based prompts (only use unique keywords not in action/category)
769
- const usedWords = new Set([primaryAction.toLowerCase(), category.toLowerCase(),
770
- ...actionVariations.map(a => a.toLowerCase())]);
771
- for (const keyword of keywords) {
772
- const kwLower = keyword.toLowerCase();
773
- if (!usedWords.has(kwLower) && kwLower !== category.toLowerCase()) {
774
- prompts.push(`${keyword} in ${category}`);
775
- prompts.push(`I need ${keyword} functionality`);
776
- usedWords.add(kwLower);
777
- if (usedWords.size > keywords.length + 3) break;
778
- }
779
- }
780
-
781
- // Tool-specific technical prompts
782
- prompts.push(`run ${command}`);
783
- prompts.push(`${capability} ${command}`);
784
-
785
- // Clean up prompts: remove duplicates, fix spacing, validate
786
- const cleanPrompts = [...new Set(prompts)]
787
- .map(p => p.trim().replace(/\s+/g, ' '))
788
- .filter(p => {
789
- // Filter out bad prompts
790
- if (p.length < 5) return false;
791
- if (p.includes('undefined')) return false;
792
- // Check for redundant word repetition (e.g., "status status")
793
- const words = p.toLowerCase().split(' ');
794
- for (let i = 0; i < words.length - 1; i++) {
795
- if (words[i] === words[i + 1] && words[i].length > 2) return false;
796
- }
797
- return true;
798
- })
799
- .slice(0, 10);
800
-
801
- return cleanPrompts;
802
- }
803
-
804
- /**
805
- * Find hard negatives for a command
806
- */
807
- function findHardNegatives(tool, command, allCapabilities) {
808
- const negatives = [];
809
- const fullCommand = `${tool} ${command}`;
810
-
811
- // Find from predefined confusing pairs
812
- for (const pair of CONFUSING_PAIRS) {
813
- if (pair.cmd1.includes(command) || pair.cmd2.includes(command)) {
814
- const negative = pair.cmd1.includes(command) ? pair.cmd2 : pair.cmd1;
815
- negatives.push({
816
- command: negative,
817
- reason: pair.reason,
818
- });
819
- }
820
- }
821
-
822
- // Find similar commands from other tools
823
- for (const cap of allCapabilities) {
824
- if (cap.name === tool) continue;
825
-
826
- for (const [catName, category] of Object.entries(cap.categories)) {
827
- for (const [cmdName, cmdConfig] of Object.entries(category.commands)) {
828
- // Check for keyword overlap
829
- const cmdKeywords = cmdConfig.keywords || [];
830
- const sourceConfig = getCommandConfig(tool, command, allCapabilities);
831
- const sourceKeywords = sourceConfig?.keywords || [];
832
-
833
- const overlap = cmdKeywords.filter((k) => sourceKeywords.includes(k));
834
- if (overlap.length >= 2) {
835
- negatives.push({
836
- command: `${cap.name} ${cmdName}`,
837
- reason: `keyword overlap: ${overlap.join(', ')}`,
838
- });
839
- }
840
- }
841
- }
842
- }
843
-
844
- // Find similar commands within same tool (different category)
845
- const sourceCapability = allCapabilities.find((c) => c.name === tool);
846
- if (sourceCapability) {
847
- const [sourceCategory] = command.split(' ');
848
- for (const [catName, category] of Object.entries(sourceCapability.categories)) {
849
- if (catName === sourceCategory) continue;
850
-
851
- for (const [cmdName, cmdConfig] of Object.entries(category.commands)) {
852
- // Similar action words
853
- const cmdAction = cmdName.split(' ')[1] || cmdName.split(' ')[0];
854
- const sourceAction = command.split(' ')[1] || command.split(' ')[0];
855
-
856
- if (cmdAction === sourceAction) {
857
- negatives.push({
858
- command: `${tool} ${cmdName}`,
859
- reason: `same action '${cmdAction}' different category`,
860
- });
861
- }
862
- }
863
- }
864
- }
865
-
866
- // Limit and deduplicate
867
- const seen = new Set();
868
- return negatives.filter((n) => {
869
- if (seen.has(n.command)) return false;
870
- seen.add(n.command);
871
- return true;
872
- }).slice(0, 5);
873
- }
874
-
875
- /**
876
- * Get command config from capabilities
877
- */
878
- function getCommandConfig(tool, command, allCapabilities) {
879
- const capability = allCapabilities.find((c) => c.name === tool);
880
- if (!capability) return null;
881
-
882
- for (const category of Object.values(capability.categories)) {
883
- if (category.commands[command]) {
884
- return category.commands[command];
885
- }
886
- }
887
- return null;
888
- }
889
-
890
- /**
891
- * Generate triplets for all capabilities
892
- */
893
- function generateTriplets(capabilities) {
894
- const triplets = [];
895
-
896
- for (const cap of capabilities) {
897
- for (const [catName, category] of Object.entries(cap.categories)) {
898
- for (const [cmdName, cmdConfig] of Object.entries(category.commands)) {
899
- const fullCommand = `${cap.name} ${cmdName}`;
900
- const prompts = generatePrompts(cap.name, cmdName, cmdConfig);
901
- const negatives = findHardNegatives(cap.name, cmdName, capabilities);
902
-
903
- // Create triplets
904
- for (const prompt of prompts) {
905
- // Skip malformed prompts
906
- if (!prompt || prompt.length < 5) continue;
907
-
908
- // For each prompt, create triplets with each negative
909
- if (negatives.length > 0) {
910
- for (const negative of negatives) {
911
- // Ensure negative has full tool prefix
912
- let negCommand = negative.command;
913
- if (!negCommand.includes(' ') || (!negCommand.startsWith('claude-flow') &&
914
- !negCommand.startsWith('agentic-flow') && !negCommand.startsWith('ruvector'))) {
915
- continue; // Skip incomplete negatives
916
- }
917
-
918
- // Skip if negative equals positive
919
- if (negCommand === fullCommand) continue;
920
-
921
- triplets.push({
922
- anchor: prompt,
923
- positive: fullCommand,
924
- negative: negCommand,
925
- isHard: true,
926
- category: catName,
927
- tool: cap.name,
928
- });
929
- }
930
- } else {
931
- // Create triplet with random different tool command as negative
932
- const otherCaps = capabilities.filter((c) => c.name !== cap.name);
933
- if (otherCaps.length > 0) {
934
- const randomCap = otherCaps[Math.floor(Math.random() * otherCaps.length)];
935
- const randomCatName = Object.keys(randomCap.categories)[0];
936
- const randomCmdName = Object.keys(randomCap.categories[randomCatName].commands)[0];
937
- const negCommand = `${randomCap.name} ${randomCmdName}`;
938
-
939
- // Skip if somehow equals positive
940
- if (negCommand === fullCommand) continue;
941
-
942
- triplets.push({
943
- anchor: prompt,
944
- positive: fullCommand,
945
- negative: negCommand,
946
- isHard: false,
947
- category: catName,
948
- tool: cap.name,
949
- });
950
- }
951
- }
952
- }
953
- }
954
- }
955
- }
956
-
957
- return triplets;
958
- }
959
-
960
- /**
961
- * Generate category-specific examples with rich diversity
962
- */
963
- function generateCategoryExamples() {
964
- const examples = [];
965
-
966
- // ---- SWARM COORDINATION ----
967
- const swarmExamples = [
968
- // Initialization
969
- { anchor: 'Set up a multi-agent swarm for parallel processing', positive: 'claude-flow swarm init', negatives: ['agentic-flow pipeline create', 'claude-flow agent spawn'] },
970
- { anchor: 'Initialize hierarchical agent coordination', positive: 'claude-flow swarm init', negatives: ['claude-flow hive-mind init'] },
971
- { anchor: 'Create a mesh topology swarm with 10 agents', positive: 'claude-flow swarm init', negatives: ['claude-flow hive-mind spawn'] },
972
- { anchor: 'Configure swarm consensus using raft protocol', positive: 'claude-flow swarm init', negatives: ['claude-flow hive-mind consensus'] },
973
- { anchor: 'Start a queen-led hive-mind collective', positive: 'claude-flow hive-mind init', negatives: ['claude-flow swarm init'] },
974
- { anchor: 'Coordinate multiple AI agents on a complex task', positive: 'claude-flow swarm init', negatives: ['agentic-flow pipeline create'] },
975
- { anchor: 'Set up Byzantine fault-tolerant consensus', positive: 'claude-flow hive-mind init', negatives: ['claude-flow swarm init'] },
976
- { anchor: 'Launch a distributed agent network', positive: 'claude-flow swarm init', negatives: ['claude-flow agent spawn'] },
977
- { anchor: 'Create a star topology for centralized coordination', positive: 'claude-flow swarm init', negatives: ['claude-flow hive-mind init'] },
978
- // Status/monitoring
979
- { anchor: 'Check the health of all running agents', positive: 'claude-flow swarm status', negatives: ['claude-flow agent status'] },
980
- { anchor: 'Monitor swarm performance and throughput', positive: 'claude-flow swarm status', negatives: ['claude-flow performance benchmark'] },
981
- { anchor: 'Get swarm coordination status', positive: 'claude-flow swarm status', negatives: ['claude-flow agent list'] },
982
- ];
983
-
984
- // ---- AGENT MANAGEMENT ----
985
- const agentExamples = [
986
- { anchor: 'Spawn a coder agent to implement features', positive: 'claude-flow agent spawn', negatives: ['claude-flow hive-mind spawn', 'claude-flow task create'] },
987
- { anchor: 'Create a new worker agent for this task', positive: 'claude-flow agent spawn', negatives: ['claude-flow hive-mind spawn'] },
988
- { anchor: 'Start a researcher agent to investigate', positive: 'claude-flow agent spawn', negatives: ['claude-flow task create'] },
989
- { anchor: 'List all active agents in the system', positive: 'claude-flow agent list', negatives: ['agentic-flow model list', 'ruvector collection list'] },
990
- { anchor: 'Show running agent processes', positive: 'claude-flow agent list', negatives: ['claude-flow task list'] },
991
- { anchor: 'Kill a misbehaving agent', positive: 'claude-flow agent terminate', negatives: ['claude-flow swarm shutdown'] },
992
- { anchor: 'Stop the agent that is stuck', positive: 'claude-flow agent terminate', negatives: ['claude-flow task cancel'] },
993
- { anchor: 'Get details about a specific agent', positive: 'claude-flow agent status', negatives: ['claude-flow swarm status'] },
994
- ];
995
-
996
- // ---- MEMORY OPERATIONS ----
997
- const memoryExamples = [
998
- // Store operations
999
- { anchor: 'Store learned patterns for future reference', positive: 'claude-flow memory store', negatives: ['ruvector vector insert', 'agentic-flow cache set'] },
1000
- { anchor: 'Save task completion metrics to memory', positive: 'claude-flow memory store', negatives: ['claude-flow session save'] },
1001
- { anchor: 'Persist agent decisions for analysis', positive: 'claude-flow memory store', negatives: ['ruvector vector insert'] },
1002
- { anchor: 'Cache successful code patterns', positive: 'claude-flow memory store', negatives: ['agentic-flow cache set'] },
1003
- { anchor: 'Remember this debugging solution', positive: 'claude-flow memory store', negatives: ['agentic-flow cache set'] },
1004
- { anchor: 'Store API response for later retrieval', positive: 'claude-flow memory store', negatives: ['ruvector vector insert'] },
1005
- { anchor: 'Save this configuration for reuse', positive: 'claude-flow memory store', negatives: ['claude-flow session save'] },
1006
- // Retrieve operations
1007
- { anchor: 'Get the stored pattern for authentication', positive: 'claude-flow memory retrieve', negatives: ['claude-flow memory search', 'ruvector vector get'] },
1008
- { anchor: 'Fetch previously saved configuration', positive: 'claude-flow memory retrieve', negatives: ['claude-flow session restore'] },
1009
- { anchor: 'Load cached data from memory', positive: 'claude-flow memory retrieve', negatives: ['agentic-flow cache get'] },
1010
- // Search operations
1011
- { anchor: 'Search memory for similar patterns', positive: 'claude-flow memory search', negatives: ['ruvector search knn', 'agentic-flow search nearest'] },
1012
- { anchor: 'Find relevant past solutions', positive: 'claude-flow memory search', negatives: ['ruvector search filter'] },
1013
- { anchor: 'Query semantic memory for debugging tips', positive: 'claude-flow memory search', negatives: ['agentic-flow search hybrid'] },
1014
- { anchor: 'Look up related patterns in storage', positive: 'claude-flow memory search', negatives: ['ruvector search knn'] },
1015
- ];
1016
-
1017
- // ---- VECTOR DATABASE (RUVECTOR) ----
1018
- const vectorExamples = [
1019
- // Search operations
1020
- { anchor: 'Find k-nearest matches to this embedding', positive: 'ruvector search knn', negatives: ['claude-flow memory search', 'agentic-flow search nearest'] },
1021
- { anchor: 'Search vectors with metadata filters', positive: 'ruvector search filter', negatives: ['claude-flow memory search', 'agentic-flow search hybrid'] },
1022
- { anchor: 'Perform approximate nearest neighbor search', positive: 'ruvector search knn', negatives: ['agentic-flow search nearest'] },
1023
- { anchor: 'Query the vector database for similar items', positive: 'ruvector search knn', negatives: ['claude-flow memory search'] },
1024
- { anchor: 'Find similar embeddings in the collection', positive: 'ruvector search knn', negatives: ['claude-flow embeddings search'] },
1025
- { anchor: 'Batch search multiple query vectors', positive: 'ruvector search batch', negatives: ['agentic-flow batch-embed'] },
1026
- // Collection operations
1027
- { anchor: 'Create a new vector collection for documents', positive: 'ruvector collection create', negatives: ['claude-flow memory store'] },
1028
- { anchor: 'Set up a database for embedding storage', positive: 'ruvector collection create', negatives: ['agentic-flow cache set'] },
1029
- { anchor: 'Delete the old vector collection', positive: 'ruvector collection delete', negatives: ['claude-flow memory delete'] },
1030
- { anchor: 'Get information about the collection', positive: 'ruvector collection info', negatives: ['agentic-flow model info'] },
1031
- // Vector CRUD
1032
- { anchor: 'Insert embeddings into the database', positive: 'ruvector vector insert', negatives: ['claude-flow memory store', 'agentic-flow cache set'] },
1033
- { anchor: 'Add vectors to the collection', positive: 'ruvector vector insert', negatives: ['claude-flow memory store'] },
1034
- { anchor: 'Upsert vectors with metadata', positive: 'ruvector vector insert', negatives: ['agentic-flow cache set'] },
1035
- { anchor: 'Delete vectors by ID', positive: 'ruvector vector delete', negatives: ['claude-flow memory delete'] },
1036
- // Index operations
1037
- { anchor: 'Build HNSW index for faster search', positive: 'ruvector index build', negatives: ['claude-flow hooks pretrain'] },
1038
- { anchor: 'Create search index for vectors', positive: 'ruvector index build', negatives: ['claude-flow neural train'] },
1039
- { anchor: 'Optimize index for query performance', positive: 'ruvector index optimize', negatives: ['claude-flow performance optimize'] },
1040
- { anchor: 'Rebuild search index after updates', positive: 'ruvector index rebuild', negatives: ['claude-flow hooks pretrain'] },
1041
- { anchor: 'Configure HNSW parameters for accuracy', positive: 'ruvector index build', negatives: ['ruvector quantize apply'] },
1042
- // Persistence
1043
- { anchor: 'Create a snapshot backup of vectors', positive: 'ruvector snapshot create', negatives: ['claude-flow session save'] },
1044
- { anchor: 'Restore vectors from backup', positive: 'ruvector snapshot restore', negatives: ['claude-flow session restore'] },
1045
- ];
1046
-
1047
- // ---- EMBEDDINGS (AGENTIC-FLOW) ----
1048
- const embeddingExamples = [
1049
- { anchor: 'Generate embeddings for these documents', positive: 'agentic-flow embed', negatives: ['claude-flow embeddings generate'] },
1050
- { anchor: 'Create vector representations of text', positive: 'agentic-flow embed', negatives: ['claude-flow embeddings generate'] },
1051
- { anchor: 'Encode sentences into embeddings', positive: 'agentic-flow embed', negatives: ['claude-flow embeddings generate'] },
1052
- { anchor: 'Vectorize code snippets for search', positive: 'agentic-flow embed', negatives: ['ruvector vector insert'] },
1053
- { anchor: 'Produce semantic embeddings from descriptions', positive: 'agentic-flow embed', negatives: ['claude-flow embeddings generate'] },
1054
- { anchor: 'Convert text to numerical vectors using ONNX', positive: 'agentic-flow embed', negatives: ['claude-flow embeddings generate'] },
1055
- { anchor: 'Batch embed multiple documents efficiently', positive: 'agentic-flow batch-embed', negatives: ['ruvector search batch'] },
1056
- { anchor: 'Embed large corpus in parallel', positive: 'agentic-flow batch-embed', negatives: ['ruvector vector insert'] },
1057
- { anchor: 'Compare similarity between two texts', positive: 'agentic-flow similarity', negatives: ['claude-flow embeddings compare'] },
1058
- { anchor: 'Calculate cosine distance between embeddings', positive: 'agentic-flow similarity', negatives: ['claude-flow embeddings compare'] },
1059
- // Model operations
1060
- { anchor: 'Load the ONNX model for inference', positive: 'agentic-flow model load', negatives: ['claude-flow neural train'] },
1061
- { anchor: 'List available embedding models', positive: 'agentic-flow model list', negatives: ['claude-flow agent list'] },
1062
- { anchor: 'Quantize the model for faster inference', positive: 'agentic-flow model quantize', negatives: ['ruvector quantize apply'] },
1063
- // Cache operations
1064
- { anchor: 'Cache the embedding for reuse', positive: 'agentic-flow cache set', negatives: ['claude-flow memory store'] },
1065
- { anchor: 'Get cached embedding', positive: 'agentic-flow cache get', negatives: ['claude-flow memory retrieve'] },
1066
- { anchor: 'Clear the embedding cache', positive: 'agentic-flow cache clear', negatives: ['claude-flow memory delete'] },
1067
- // Search
1068
- { anchor: 'Find nearest neighbors to query', positive: 'agentic-flow search nearest', negatives: ['ruvector search knn'] },
1069
- { anchor: 'Hybrid keyword and semantic search', positive: 'agentic-flow search hybrid', negatives: ['ruvector search filter'] },
1070
- // Pipeline
1071
- { anchor: 'Create an embedding pipeline', positive: 'agentic-flow pipeline create', negatives: ['claude-flow workflow create'] },
1072
- { anchor: 'Run the processing pipeline', positive: 'agentic-flow pipeline run', negatives: ['claude-flow workflow execute'] },
1073
- ];
1074
-
1075
- // ---- HOOKS AND LEARNING ----
1076
- const hookExamples = [
1077
- { anchor: 'Route this task to the optimal agent', positive: 'claude-flow hooks route', negatives: ['claude-flow agent spawn', 'claude-flow hooks pre-task'] },
1078
- { anchor: 'Get agent suggestions before starting work', positive: 'claude-flow hooks pre-task', negatives: ['claude-flow hooks route'] },
1079
- { anchor: 'Record task completion for learning', positive: 'claude-flow hooks post-task', negatives: ['claude-flow hooks metrics'] },
1080
- { anchor: 'Analyze codebase to bootstrap intelligence', positive: 'claude-flow hooks pretrain', negatives: ['claude-flow neural train', 'ruvector index build'] },
1081
- { anchor: 'Track metrics from completed tasks', positive: 'claude-flow hooks metrics', negatives: ['claude-flow performance benchmark'] },
1082
- { anchor: 'Pre-train routing model on repository', positive: 'claude-flow hooks pretrain', negatives: ['claude-flow neural train'] },
1083
- { anchor: 'Dispatch a background worker for optimization', positive: 'claude-flow hooks worker dispatch', negatives: ['claude-flow agent spawn'] },
1084
- { anchor: 'Log task before starting', positive: 'claude-flow hooks pre-task', negatives: ['claude-flow task create'] },
1085
- ];
1086
-
1087
- // ---- WORKFLOW AND TASKS ----
1088
- const workflowExamples = [
1089
- { anchor: 'Create a new workflow for code review', positive: 'claude-flow workflow create', negatives: ['agentic-flow pipeline create', 'claude-flow task create'] },
1090
- { anchor: 'Define a multi-step workflow', positive: 'claude-flow workflow create', negatives: ['agentic-flow pipeline create'] },
1091
- { anchor: 'Execute the deployment workflow', positive: 'claude-flow workflow execute', negatives: ['agentic-flow pipeline run'] },
1092
- { anchor: 'Run the CI/CD workflow', positive: 'claude-flow workflow execute', negatives: ['claude-flow task create'] },
1093
- { anchor: 'Check workflow execution status', positive: 'claude-flow workflow status', negatives: ['claude-flow task status'] },
1094
- { anchor: 'Create a task for the coder agent', positive: 'claude-flow task create', negatives: ['claude-flow agent spawn'] },
1095
- { anchor: 'Add a new task to the queue', positive: 'claude-flow task create', negatives: ['claude-flow workflow create'] },
1096
- { anchor: 'Mark this task as complete', positive: 'claude-flow task complete', negatives: ['claude-flow hooks post-task'] },
1097
- { anchor: 'List pending tasks', positive: 'claude-flow task list', negatives: ['claude-flow agent list'] },
1098
- ];
1099
-
1100
- // ---- SESSION AND STATE ----
1101
- const sessionExamples = [
1102
- { anchor: 'Save the current session state', positive: 'claude-flow session save', negatives: ['claude-flow memory store', 'ruvector snapshot create'] },
1103
- { anchor: 'Persist session for later continuation', positive: 'claude-flow session save', negatives: ['claude-flow memory store'] },
1104
- { anchor: 'Restore previous session', positive: 'claude-flow session restore', negatives: ['ruvector snapshot restore', 'claude-flow memory retrieve'] },
1105
- { anchor: 'Continue where I left off', positive: 'claude-flow session restore', negatives: ['claude-flow memory retrieve'] },
1106
- { anchor: 'List saved sessions', positive: 'claude-flow session list', negatives: ['claude-flow memory list'] },
1107
- ];
1108
-
1109
- // ---- NEURAL AND ML ----
1110
- const neuralExamples = [
1111
- { anchor: 'Train the routing model', positive: 'claude-flow neural train', negatives: ['claude-flow hooks pretrain'] },
1112
- { anchor: 'Train neural patterns for better routing', positive: 'claude-flow neural train', negatives: ['claude-flow hooks pretrain'] },
1113
- { anchor: 'Make prediction with neural model', positive: 'claude-flow neural predict', negatives: ['claude-flow hooks route'] },
1114
- { anchor: 'Get neural routing prediction', positive: 'claude-flow neural predict', negatives: ['agentic-flow embed'] },
1115
- { anchor: 'Store learned neural patterns', positive: 'claude-flow neural patterns', negatives: ['claude-flow memory store'] },
1116
- ];
1117
-
1118
- // ---- PERFORMANCE AND SECURITY ----
1119
- const perfExamples = [
1120
- { anchor: 'Benchmark system performance', positive: 'claude-flow performance benchmark', negatives: ['claude-flow hooks metrics'] },
1121
- { anchor: 'Profile slow operations', positive: 'claude-flow performance profile', negatives: ['claude-flow performance benchmark'] },
1122
- { anchor: 'Optimize for lower latency', positive: 'claude-flow performance optimize', negatives: ['ruvector index optimize'] },
1123
- { anchor: 'Scan input for security threats', positive: 'claude-flow aidefence scan', negatives: ['claude-flow hooks pre-task'] },
1124
- { anchor: 'Check if input is safe', positive: 'claude-flow aidefence is_safe', negatives: ['claude-flow aidefence scan'] },
1125
- { anchor: 'Analyze potential prompt injection', positive: 'claude-flow aidefence analyze', negatives: ['claude-flow hooks route'] },
1126
- ];
1127
-
1128
- // ---- CLAIMS AND COORDINATION ----
1129
- const claimsExamples = [
1130
- { anchor: 'Claim this issue for work', positive: 'claude-flow claims claim', negatives: ['claude-flow task create'] },
1131
- { anchor: 'Assign this issue to me', positive: 'claude-flow claims claim', negatives: ['claude-flow task create'] },
1132
- { anchor: 'Release my claim on this issue', positive: 'claude-flow claims release', negatives: ['claude-flow task complete'] },
1133
- { anchor: 'Hand off issue to another agent', positive: 'claude-flow claims handoff', negatives: ['claude-flow claims release'] },
1134
- { anchor: 'View the claims board', positive: 'claude-flow claims board', negatives: ['claude-flow task list'] },
1135
- ];
1136
-
1137
- // Convert all examples to triplet format
1138
- const allExampleSets = [
1139
- swarmExamples, agentExamples, memoryExamples, vectorExamples,
1140
- embeddingExamples, hookExamples, workflowExamples, sessionExamples,
1141
- neuralExamples, perfExamples, claimsExamples
1142
- ];
1143
-
1144
- for (const exampleSet of allExampleSets) {
1145
- for (const ex of exampleSet) {
1146
- const negatives = ex.negatives || [ex.negative];
1147
- for (const neg of negatives) {
1148
- examples.push({
1149
- anchor: ex.anchor,
1150
- positive: ex.positive,
1151
- negative: neg,
1152
- isHard: true,
1153
- });
1154
- }
1155
- }
1156
- }
1157
-
1158
- return examples;
1159
- }
1160
-
1161
- // ============================================================================
1162
- // MAIN GENERATION
1163
- // ============================================================================
1164
-
1165
- /**
1166
- * Save capability definitions to JSON files
1167
- */
1168
- function saveCapabilities(outputDir) {
1169
- const capabilities = [
1170
- { filename: 'claude-flow-capabilities.json', data: CLAUDE_FLOW_CAPABILITIES },
1171
- { filename: 'agentic-flow-capabilities.json', data: AGENTIC_FLOW_CAPABILITIES },
1172
- { filename: 'ruvector-capabilities.json', data: RUVECTOR_CAPABILITIES },
1173
- ];
1174
-
1175
- for (const { filename, data } of capabilities) {
1176
- const filepath = path.join(outputDir, filename);
1177
- fs.writeFileSync(filepath, JSON.stringify(data, null, 2));
1178
- console.log(` Saved ${filepath}`);
1179
- }
1180
- }
1181
-
1182
- /**
1183
- * Main entry point
1184
- */
1185
- function main() {
1186
- console.log('\n' + '='.repeat(80));
1187
- console.log(' ECOSYSTEM TRAINING DATA GENERATOR FOR RUVLTRA');
1188
- console.log('='.repeat(80) + '\n');
1189
-
1190
- const args = process.argv.slice(2);
1191
- const outputDir = path.dirname(path.resolve(__filename));
1192
- const outputFile = args.find((a) => a.startsWith('--output='))?.split('=')[1] ||
1193
- path.join(outputDir, 'ecosystem-triplets.jsonl');
1194
- const saveCapabilityFiles = args.includes('--save-capabilities');
1195
-
1196
- console.log('Configuration:');
1197
- console.log(` Output: ${outputFile}`);
1198
- console.log(` Save capability JSONs: ${saveCapabilityFiles}`);
1199
- console.log();
1200
-
1201
- // All capabilities
1202
- const allCapabilities = [
1203
- CLAUDE_FLOW_CAPABILITIES,
1204
- AGENTIC_FLOW_CAPABILITIES,
1205
- RUVECTOR_CAPABILITIES,
1206
- ];
1207
-
1208
- // Save capability definitions if requested
1209
- if (saveCapabilityFiles) {
1210
- console.log('Saving capability definitions...');
1211
- saveCapabilities(outputDir);
1212
- console.log();
1213
- }
1214
-
1215
- // Generate triplets
1216
- console.log('Generating training triplets...');
1217
-
1218
- const triplets = generateTriplets(allCapabilities);
1219
- const categoryExamples = generateCategoryExamples();
1220
-
1221
- // Combine all triplets
1222
- const allTriplets = [...triplets, ...categoryExamples];
1223
-
1224
- // Shuffle for better training
1225
- allTriplets.sort(() => Math.random() - 0.5);
1226
-
1227
- // Statistics
1228
- const stats = {
1229
- total: allTriplets.length,
1230
- byTool: {},
1231
- byCategory: {},
1232
- hardNegatives: 0,
1233
- };
1234
-
1235
- for (const t of allTriplets) {
1236
- if (t.tool) {
1237
- stats.byTool[t.tool] = (stats.byTool[t.tool] || 0) + 1;
1238
- }
1239
- if (t.category) {
1240
- stats.byCategory[t.category] = (stats.byCategory[t.category] || 0) + 1;
1241
- }
1242
- if (t.isHard) {
1243
- stats.hardNegatives++;
1244
- }
1245
- }
1246
-
1247
- // Save triplets as JSONL
1248
- const jsonlContent = allTriplets.map((t) => JSON.stringify({
1249
- anchor: t.anchor,
1250
- positive: t.positive,
1251
- negative: t.negative,
1252
- })).join('\n');
1253
-
1254
- fs.writeFileSync(outputFile, jsonlContent);
1255
-
1256
- // Print summary
1257
- console.log('\n' + '-'.repeat(60));
1258
- console.log(' GENERATION SUMMARY');
1259
- console.log('-'.repeat(60) + '\n');
1260
-
1261
- console.log(`Total triplets generated: ${stats.total}`);
1262
- console.log(`Hard negatives: ${stats.hardNegatives} (${((stats.hardNegatives / stats.total) * 100).toFixed(1)}%)`);
1263
- console.log();
1264
-
1265
- console.log('Triplets by tool:');
1266
- for (const [tool, count] of Object.entries(stats.byTool)) {
1267
- console.log(` ${tool.padEnd(20)} ${count}`);
1268
- }
1269
- console.log();
1270
-
1271
- console.log('Triplets by category:');
1272
- for (const [category, count] of Object.entries(stats.byCategory).slice(0, 10)) {
1273
- console.log(` ${category.padEnd(20)} ${count}`);
1274
- }
1275
- if (Object.keys(stats.byCategory).length > 10) {
1276
- console.log(` ... and ${Object.keys(stats.byCategory).length - 10} more categories`);
1277
- }
1278
- console.log();
1279
-
1280
- console.log(`Output saved to: ${outputFile}`);
1281
- console.log();
1282
-
1283
- // Show sample triplets
1284
- console.log('-'.repeat(60));
1285
- console.log(' SAMPLE TRIPLETS');
1286
- console.log('-'.repeat(60) + '\n');
1287
-
1288
- for (const triplet of allTriplets.slice(0, 5)) {
1289
- console.log(` Anchor: "${triplet.anchor}"`);
1290
- console.log(` Positive: ${triplet.positive}`);
1291
- console.log(` Negative: ${triplet.negative}`);
1292
- console.log();
1293
- }
1294
-
1295
- console.log('='.repeat(80));
1296
- console.log(' NEXT STEPS');
1297
- console.log('='.repeat(80) + '\n');
1298
-
1299
- console.log('1. Merge with existing training data:');
1300
- console.log(` cat ~/.ruvllm/training/ruvltra-finetuned/triplets.jsonl ${outputFile} > combined.jsonl`);
1301
- console.log();
1302
- console.log('2. Train with contrastive loss:');
1303
- console.log(' cargo run --example train_contrastive --release -- --triplets combined.jsonl --epochs 30');
1304
- console.log();
1305
- console.log('3. Evaluate routing accuracy improvement');
1306
- console.log();
1307
- }
1308
-
1309
- // Export for testing
1310
- module.exports = {
1311
- CLAUDE_FLOW_CAPABILITIES,
1312
- AGENTIC_FLOW_CAPABILITIES,
1313
- RUVECTOR_CAPABILITIES,
1314
- generatePrompts,
1315
- findHardNegatives,
1316
- generateTriplets,
1317
- generateCategoryExamples,
1318
- CONFUSING_PAIRS,
1319
- };
1320
-
1321
- // Run if called directly
1322
- if (require.main === module) {
1323
- main();
1324
- }
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Ecosystem Training Data Generator for RuvLTRA
4
+ *
5
+ * Generates comprehensive triplet training data for the Claude Flow ecosystem:
6
+ * - claude-flow: Multi-agent coordination and swarm orchestration
7
+ * - agentic-flow: AI workflow orchestration and ONNX embeddings
8
+ * - ruvector: High-performance vector database
9
+ *
10
+ * Features:
11
+ * - Reads capability definitions from JSON files
12
+ * - Generates 5-10 natural language prompts per capability
13
+ * - Creates hard negatives for contrastive learning
14
+ * - Outputs combined JSONL dataset for fine-tuning
15
+ */
16
+
17
+ const fs = require('fs');
18
+ const path = require('path');
19
+
20
+ // ============================================================================
21
+ // CAPABILITY DEFINITIONS
22
+ // ============================================================================
23
+
24
+ /**
25
+ * Claude Flow V3 Capabilities
26
+ * Multi-agent swarm coordination, memory, hooks, workflows
27
+ */
28
+ const CLAUDE_FLOW_CAPABILITIES = {
29
+ name: 'claude-flow',
30
+ description: 'Multi-agent swarm coordination and orchestration framework',
31
+ version: '3.0.0',
32
+ categories: {
33
+ swarm: {
34
+ description: 'Multi-agent swarm coordination and topology management',
35
+ commands: {
36
+ 'swarm init': {
37
+ description: 'Initialize a swarm with specified topology',
38
+ keywords: ['swarm', 'init', 'initialize', 'topology', 'multi-agent', 'coordination'],
39
+ parameters: ['--topology', '--max-agents', '--strategy'],
40
+ },
41
+ 'swarm status': {
42
+ description: 'Get current swarm status and agent health',
43
+ keywords: ['swarm', 'status', 'health', 'agents', 'monitoring'],
44
+ parameters: ['--verbose'],
45
+ },
46
+ 'swarm shutdown': {
47
+ description: 'Gracefully shutdown the swarm',
48
+ keywords: ['swarm', 'shutdown', 'stop', 'terminate', 'graceful'],
49
+ parameters: ['--graceful', '--force'],
50
+ },
51
+ },
52
+ },
53
+ agent: {
54
+ description: 'Agent lifecycle management',
55
+ commands: {
56
+ 'agent spawn': {
57
+ description: 'Spawn a new agent with specified type',
58
+ keywords: ['agent', 'spawn', 'create', 'start', 'worker'],
59
+ parameters: ['-t', '--type', '--name', '--model'],
60
+ },
61
+ 'agent list': {
62
+ description: 'List all active agents',
63
+ keywords: ['agent', 'list', 'show', 'active', 'running'],
64
+ parameters: ['--status', '--domain'],
65
+ },
66
+ 'agent terminate': {
67
+ description: 'Terminate a specific agent',
68
+ keywords: ['agent', 'terminate', 'kill', 'stop', 'remove'],
69
+ parameters: ['--force'],
70
+ },
71
+ 'agent status': {
72
+ description: 'Get status of a specific agent',
73
+ keywords: ['agent', 'status', 'info', 'details', 'health'],
74
+ parameters: ['--agentId'],
75
+ },
76
+ },
77
+ },
78
+ memory: {
79
+ description: 'Persistent memory with vector search',
80
+ commands: {
81
+ 'memory store': {
82
+ description: 'Store a value in memory with optional namespace',
83
+ keywords: ['memory', 'store', 'save', 'persist', 'key-value'],
84
+ parameters: ['--key', '--value', '--namespace', '--ttl'],
85
+ },
86
+ 'memory retrieve': {
87
+ description: 'Retrieve a value from memory by key',
88
+ keywords: ['memory', 'retrieve', 'get', 'fetch', 'read'],
89
+ parameters: ['--key', '--namespace'],
90
+ },
91
+ 'memory search': {
92
+ description: 'Semantic vector search in memory',
93
+ keywords: ['memory', 'search', 'query', 'find', 'semantic', 'vector'],
94
+ parameters: ['--query', '--namespace', '--limit', '--threshold'],
95
+ },
96
+ 'memory list': {
97
+ description: 'List memory entries',
98
+ keywords: ['memory', 'list', 'entries', 'keys', 'show'],
99
+ parameters: ['--namespace', '--limit'],
100
+ },
101
+ 'memory delete': {
102
+ description: 'Delete a memory entry',
103
+ keywords: ['memory', 'delete', 'remove', 'clear'],
104
+ parameters: ['--key', '--namespace'],
105
+ },
106
+ },
107
+ },
108
+ hooks: {
109
+ description: 'Self-learning hooks and background workers',
110
+ commands: {
111
+ 'hooks pre-task': {
112
+ description: 'Get agent suggestions before starting a task',
113
+ keywords: ['hooks', 'pre-task', 'routing', 'suggestions', 'before'],
114
+ parameters: ['--description', '--taskId'],
115
+ },
116
+ 'hooks post-task': {
117
+ description: 'Record task completion for learning',
118
+ keywords: ['hooks', 'post-task', 'completion', 'learning', 'after'],
119
+ parameters: ['--taskId', '--success', '--quality'],
120
+ },
121
+ 'hooks route': {
122
+ description: 'Route task to optimal agent',
123
+ keywords: ['hooks', 'route', 'routing', 'optimal', 'agent'],
124
+ parameters: ['--task', '--context'],
125
+ },
126
+ 'hooks worker dispatch': {
127
+ description: 'Dispatch a background worker',
128
+ keywords: ['hooks', 'worker', 'dispatch', 'background', 'trigger'],
129
+ parameters: ['--trigger', '--context', '--priority'],
130
+ },
131
+ 'hooks metrics': {
132
+ description: 'View learning metrics dashboard',
133
+ keywords: ['hooks', 'metrics', 'dashboard', 'stats', 'learning'],
134
+ parameters: ['--period', '--format'],
135
+ },
136
+ 'hooks pretrain': {
137
+ description: 'Bootstrap intelligence from repository',
138
+ keywords: ['hooks', 'pretrain', 'bootstrap', 'intelligence', 'analyze'],
139
+ parameters: ['--path', '--depth'],
140
+ },
141
+ },
142
+ },
143
+ workflow: {
144
+ description: 'Workflow execution and templates',
145
+ commands: {
146
+ 'workflow create': {
147
+ description: 'Create a new workflow',
148
+ keywords: ['workflow', 'create', 'new', 'define'],
149
+ parameters: ['--name', '--steps', '--description'],
150
+ },
151
+ 'workflow execute': {
152
+ description: 'Execute a workflow',
153
+ keywords: ['workflow', 'execute', 'run', 'start'],
154
+ parameters: ['--workflowId', '--variables'],
155
+ },
156
+ 'workflow status': {
157
+ description: 'Get workflow execution status',
158
+ keywords: ['workflow', 'status', 'progress', 'state'],
159
+ parameters: ['--workflowId', '--verbose'],
160
+ },
161
+ },
162
+ },
163
+ hivemind: {
164
+ description: 'Hive-mind collective consensus',
165
+ commands: {
166
+ 'hive-mind init': {
167
+ description: 'Initialize hive-mind collective',
168
+ keywords: ['hive-mind', 'init', 'collective', 'consensus'],
169
+ parameters: ['--topology', '--queenId'],
170
+ },
171
+ 'hive-mind spawn': {
172
+ description: 'Spawn workers and join to hive-mind',
173
+ keywords: ['hive-mind', 'spawn', 'workers', 'join'],
174
+ parameters: ['--count', '--prefix', '--role'],
175
+ },
176
+ 'hive-mind consensus': {
177
+ description: 'Propose or vote on consensus',
178
+ keywords: ['hive-mind', 'consensus', 'vote', 'propose'],
179
+ parameters: ['--action', '--proposalId', '--vote'],
180
+ },
181
+ 'hive-mind broadcast': {
182
+ description: 'Broadcast message to all workers',
183
+ keywords: ['hive-mind', 'broadcast', 'message', 'all'],
184
+ parameters: ['--message', '--priority'],
185
+ },
186
+ },
187
+ },
188
+ task: {
189
+ description: 'Task creation and management',
190
+ commands: {
191
+ 'task create': {
192
+ description: 'Create a new task',
193
+ keywords: ['task', 'create', 'new', 'add'],
194
+ parameters: ['--type', '--description', '--priority'],
195
+ },
196
+ 'task list': {
197
+ description: 'List all tasks',
198
+ keywords: ['task', 'list', 'show', 'all'],
199
+ parameters: ['--status', '--priority'],
200
+ },
201
+ 'task complete': {
202
+ description: 'Mark task as complete',
203
+ keywords: ['task', 'complete', 'done', 'finish'],
204
+ parameters: ['--taskId', '--result'],
205
+ },
206
+ },
207
+ },
208
+ session: {
209
+ description: 'Session state management',
210
+ commands: {
211
+ 'session save': {
212
+ description: 'Save current session state',
213
+ keywords: ['session', 'save', 'persist', 'state'],
214
+ parameters: ['--name', '--description'],
215
+ },
216
+ 'session restore': {
217
+ description: 'Restore a saved session',
218
+ keywords: ['session', 'restore', 'load', 'resume'],
219
+ parameters: ['--sessionId', '--name'],
220
+ },
221
+ 'session list': {
222
+ description: 'List saved sessions',
223
+ keywords: ['session', 'list', 'saved', 'history'],
224
+ parameters: ['--limit'],
225
+ },
226
+ },
227
+ },
228
+ neural: {
229
+ description: 'Neural pattern training and prediction',
230
+ commands: {
231
+ 'neural train': {
232
+ description: 'Train a neural model',
233
+ keywords: ['neural', 'train', 'model', 'learning'],
234
+ parameters: ['--modelType', '--epochs', '--learningRate'],
235
+ },
236
+ 'neural predict': {
237
+ description: 'Make predictions using neural model',
238
+ keywords: ['neural', 'predict', 'inference', 'model'],
239
+ parameters: ['--input', '--modelId'],
240
+ },
241
+ 'neural patterns': {
242
+ description: 'Manage neural patterns',
243
+ keywords: ['neural', 'patterns', 'store', 'search'],
244
+ parameters: ['--action', '--patternId'],
245
+ },
246
+ },
247
+ },
248
+ security: {
249
+ description: 'Security scanning and threat detection',
250
+ commands: {
251
+ 'aidefence scan': {
252
+ description: 'Scan input for AI manipulation threats',
253
+ keywords: ['aidefence', 'scan', 'security', 'threats', 'injection'],
254
+ parameters: ['--input', '--quick'],
255
+ },
256
+ 'aidefence analyze': {
257
+ description: 'Deep analysis for threat types',
258
+ keywords: ['aidefence', 'analyze', 'deep', 'threats'],
259
+ parameters: ['--input', '--searchSimilar'],
260
+ },
261
+ 'aidefence is_safe': {
262
+ description: 'Quick boolean safety check',
263
+ keywords: ['aidefence', 'safe', 'check', 'validate'],
264
+ parameters: ['--input'],
265
+ },
266
+ },
267
+ },
268
+ performance: {
269
+ description: 'Performance profiling and optimization',
270
+ commands: {
271
+ 'performance benchmark': {
272
+ description: 'Run performance benchmarks',
273
+ keywords: ['performance', 'benchmark', 'speed', 'test'],
274
+ parameters: ['--suite', '--iterations'],
275
+ },
276
+ 'performance profile': {
277
+ description: 'Profile specific component',
278
+ keywords: ['performance', 'profile', 'analyze', 'bottleneck'],
279
+ parameters: ['--target', '--duration'],
280
+ },
281
+ 'performance optimize': {
282
+ description: 'Apply performance optimizations',
283
+ keywords: ['performance', 'optimize', 'improve', 'speed'],
284
+ parameters: ['--target', '--aggressive'],
285
+ },
286
+ },
287
+ },
288
+ embeddings: {
289
+ description: 'Vector embeddings with ONNX',
290
+ commands: {
291
+ 'embeddings generate': {
292
+ description: 'Generate embeddings for text',
293
+ keywords: ['embeddings', 'generate', 'embed', 'vector'],
294
+ parameters: ['--text', '--hyperbolic'],
295
+ },
296
+ 'embeddings compare': {
297
+ description: 'Compare similarity between texts',
298
+ keywords: ['embeddings', 'compare', 'similarity', 'distance'],
299
+ parameters: ['--text1', '--text2', '--metric'],
300
+ },
301
+ 'embeddings search': {
302
+ description: 'Semantic search across stored embeddings',
303
+ keywords: ['embeddings', 'search', 'semantic', 'query'],
304
+ parameters: ['--query', '--topK', '--threshold'],
305
+ },
306
+ },
307
+ },
308
+ claims: {
309
+ description: 'Issue claiming and coordination',
310
+ commands: {
311
+ 'claims claim': {
312
+ description: 'Claim an issue for work',
313
+ keywords: ['claims', 'claim', 'issue', 'work', 'assign'],
314
+ parameters: ['--issueId', '--claimant'],
315
+ },
316
+ 'claims release': {
317
+ description: 'Release a claim on an issue',
318
+ keywords: ['claims', 'release', 'unclaim', 'free'],
319
+ parameters: ['--issueId', '--reason'],
320
+ },
321
+ 'claims handoff': {
322
+ description: 'Handoff issue to another claimant',
323
+ keywords: ['claims', 'handoff', 'transfer', 'pass'],
324
+ parameters: ['--issueId', '--from', '--to'],
325
+ },
326
+ 'claims board': {
327
+ description: 'View claims board',
328
+ keywords: ['claims', 'board', 'view', 'overview'],
329
+ parameters: [],
330
+ },
331
+ },
332
+ },
333
+ },
334
+ };
335
+
336
+ /**
337
+ * Agentic Flow Capabilities
338
+ * AI workflow orchestration and ONNX embeddings
339
+ */
340
+ const AGENTIC_FLOW_CAPABILITIES = {
341
+ name: 'agentic-flow',
342
+ description: 'AI workflow orchestration with ONNX runtime and vector embeddings',
343
+ version: '1.0.0',
344
+ categories: {
345
+ embeddings: {
346
+ description: 'High-performance ONNX embeddings',
347
+ commands: {
348
+ 'embed': {
349
+ description: 'Generate embeddings for text using ONNX models',
350
+ keywords: ['embed', 'embedding', 'vector', 'encode', 'onnx'],
351
+ parameters: ['--text', '--model', '--normalize'],
352
+ },
353
+ 'batch-embed': {
354
+ description: 'Batch embed multiple texts efficiently',
355
+ keywords: ['batch', 'embed', 'multiple', 'parallel'],
356
+ parameters: ['--texts', '--concurrency'],
357
+ },
358
+ 'similarity': {
359
+ description: 'Compute similarity between embeddings',
360
+ keywords: ['similarity', 'cosine', 'distance', 'compare'],
361
+ parameters: ['--a', '--b', '--metric'],
362
+ },
363
+ },
364
+ },
365
+ models: {
366
+ description: 'ONNX model management',
367
+ commands: {
368
+ 'model load': {
369
+ description: 'Load an ONNX model for inference',
370
+ keywords: ['model', 'load', 'onnx', 'initialize'],
371
+ parameters: ['--path', '--name'],
372
+ },
373
+ 'model list': {
374
+ description: 'List available models',
375
+ keywords: ['model', 'list', 'available', 'show'],
376
+ parameters: [],
377
+ },
378
+ 'model info': {
379
+ description: 'Get model information and metadata',
380
+ keywords: ['model', 'info', 'metadata', 'details'],
381
+ parameters: ['--name'],
382
+ },
383
+ 'model quantize': {
384
+ description: 'Quantize model for faster inference',
385
+ keywords: ['model', 'quantize', 'compress', 'optimize'],
386
+ parameters: ['--input', '--output', '--bits'],
387
+ },
388
+ },
389
+ },
390
+ pipeline: {
391
+ description: 'Workflow pipeline orchestration',
392
+ commands: {
393
+ 'pipeline create': {
394
+ description: 'Create a new processing pipeline',
395
+ keywords: ['pipeline', 'create', 'workflow', 'chain'],
396
+ parameters: ['--name', '--steps'],
397
+ },
398
+ 'pipeline run': {
399
+ description: 'Execute a pipeline with input data',
400
+ keywords: ['pipeline', 'run', 'execute', 'process'],
401
+ parameters: ['--name', '--input'],
402
+ },
403
+ 'pipeline visualize': {
404
+ description: 'Visualize pipeline structure',
405
+ keywords: ['pipeline', 'visualize', 'graph', 'diagram'],
406
+ parameters: ['--name', '--format'],
407
+ },
408
+ },
409
+ },
410
+ cache: {
411
+ description: 'Embedding cache management',
412
+ commands: {
413
+ 'cache set': {
414
+ description: 'Store embedding in cache',
415
+ keywords: ['cache', 'set', 'store', 'save'],
416
+ parameters: ['--key', '--embedding'],
417
+ },
418
+ 'cache get': {
419
+ description: 'Retrieve embedding from cache',
420
+ keywords: ['cache', 'get', 'retrieve', 'fetch'],
421
+ parameters: ['--key'],
422
+ },
423
+ 'cache clear': {
424
+ description: 'Clear embedding cache',
425
+ keywords: ['cache', 'clear', 'flush', 'reset'],
426
+ parameters: ['--namespace'],
427
+ },
428
+ 'cache stats': {
429
+ description: 'Get cache statistics',
430
+ keywords: ['cache', 'stats', 'statistics', 'info'],
431
+ parameters: [],
432
+ },
433
+ },
434
+ },
435
+ search: {
436
+ description: 'Vector search operations',
437
+ commands: {
438
+ 'search nearest': {
439
+ description: 'Find nearest neighbors to query vector',
440
+ keywords: ['search', 'nearest', 'neighbors', 'knn'],
441
+ parameters: ['--query', '--k', '--threshold'],
442
+ },
443
+ 'search range': {
444
+ description: 'Range search within distance threshold',
445
+ keywords: ['search', 'range', 'radius', 'threshold'],
446
+ parameters: ['--query', '--radius'],
447
+ },
448
+ 'search hybrid': {
449
+ description: 'Hybrid search combining keyword and semantic',
450
+ keywords: ['search', 'hybrid', 'combined', 'keyword', 'semantic'],
451
+ parameters: ['--query', '--alpha'],
452
+ },
453
+ },
454
+ },
455
+ },
456
+ };
457
+
458
+ /**
459
+ * RuVector Capabilities
460
+ * High-performance vector database
461
+ */
462
+ const RUVECTOR_CAPABILITIES = {
463
+ name: 'ruvector',
464
+ description: 'High-performance vector database with HNSW indexing',
465
+ version: '0.1.0',
466
+ categories: {
467
+ collections: {
468
+ description: 'Vector collection management',
469
+ commands: {
470
+ 'collection create': {
471
+ description: 'Create a new vector collection',
472
+ keywords: ['collection', 'create', 'new', 'database'],
473
+ parameters: ['--name', '--dimension', '--metric'],
474
+ },
475
+ 'collection delete': {
476
+ description: 'Delete a vector collection',
477
+ keywords: ['collection', 'delete', 'drop', 'remove'],
478
+ parameters: ['--name', '--confirm'],
479
+ },
480
+ 'collection info': {
481
+ description: 'Get collection information',
482
+ keywords: ['collection', 'info', 'stats', 'details'],
483
+ parameters: ['--name'],
484
+ },
485
+ 'collection list': {
486
+ description: 'List all collections',
487
+ keywords: ['collection', 'list', 'all', 'show'],
488
+ parameters: [],
489
+ },
490
+ },
491
+ },
492
+ vectors: {
493
+ description: 'Vector CRUD operations',
494
+ commands: {
495
+ 'vector insert': {
496
+ description: 'Insert vectors into collection',
497
+ keywords: ['vector', 'insert', 'add', 'upsert'],
498
+ parameters: ['--collection', '--vectors', '--ids'],
499
+ },
500
+ 'vector delete': {
501
+ description: 'Delete vectors from collection',
502
+ keywords: ['vector', 'delete', 'remove', 'drop'],
503
+ parameters: ['--collection', '--ids'],
504
+ },
505
+ 'vector get': {
506
+ description: 'Get vectors by ID',
507
+ keywords: ['vector', 'get', 'fetch', 'retrieve'],
508
+ parameters: ['--collection', '--ids'],
509
+ },
510
+ 'vector update': {
511
+ description: 'Update existing vectors',
512
+ keywords: ['vector', 'update', 'modify', 'change'],
513
+ parameters: ['--collection', '--id', '--vector'],
514
+ },
515
+ },
516
+ },
517
+ search: {
518
+ description: 'Vector search with HNSW',
519
+ commands: {
520
+ 'search knn': {
521
+ description: 'K-nearest neighbor search',
522
+ keywords: ['search', 'knn', 'nearest', 'similar'],
523
+ parameters: ['--collection', '--query', '--k'],
524
+ },
525
+ 'search filter': {
526
+ description: 'Filtered vector search with metadata',
527
+ keywords: ['search', 'filter', 'metadata', 'conditional'],
528
+ parameters: ['--collection', '--query', '--filter'],
529
+ },
530
+ 'search batch': {
531
+ description: 'Batch search multiple queries',
532
+ keywords: ['search', 'batch', 'multiple', 'parallel'],
533
+ parameters: ['--collection', '--queries', '--k'],
534
+ },
535
+ },
536
+ },
537
+ index: {
538
+ description: 'HNSW index management',
539
+ commands: {
540
+ 'index build': {
541
+ description: 'Build HNSW index for collection',
542
+ keywords: ['index', 'build', 'create', 'hnsw'],
543
+ parameters: ['--collection', '--ef', '--m'],
544
+ },
545
+ 'index rebuild': {
546
+ description: 'Rebuild existing index',
547
+ keywords: ['index', 'rebuild', 'refresh', 'reindex'],
548
+ parameters: ['--collection'],
549
+ },
550
+ 'index stats': {
551
+ description: 'Get index statistics',
552
+ keywords: ['index', 'stats', 'info', 'metrics'],
553
+ parameters: ['--collection'],
554
+ },
555
+ 'index optimize': {
556
+ description: 'Optimize index for search performance',
557
+ keywords: ['index', 'optimize', 'tune', 'improve'],
558
+ parameters: ['--collection', '--target'],
559
+ },
560
+ },
561
+ },
562
+ persistence: {
563
+ description: 'Data persistence and backup',
564
+ commands: {
565
+ 'snapshot create': {
566
+ description: 'Create a snapshot of collection',
567
+ keywords: ['snapshot', 'create', 'backup', 'save'],
568
+ parameters: ['--collection', '--path'],
569
+ },
570
+ 'snapshot restore': {
571
+ description: 'Restore collection from snapshot',
572
+ keywords: ['snapshot', 'restore', 'load', 'recover'],
573
+ parameters: ['--path', '--collection'],
574
+ },
575
+ 'snapshot list': {
576
+ description: 'List available snapshots',
577
+ keywords: ['snapshot', 'list', 'backups', 'show'],
578
+ parameters: ['--collection'],
579
+ },
580
+ },
581
+ },
582
+ quantization: {
583
+ description: 'Vector quantization for memory efficiency',
584
+ commands: {
585
+ 'quantize apply': {
586
+ description: 'Apply quantization to collection',
587
+ keywords: ['quantize', 'apply', 'compress', 'reduce'],
588
+ parameters: ['--collection', '--type', '--bits'],
589
+ },
590
+ 'quantize info': {
591
+ description: 'Get quantization info',
592
+ keywords: ['quantize', 'info', 'status', 'details'],
593
+ parameters: ['--collection'],
594
+ },
595
+ },
596
+ },
597
+ },
598
+ };
599
+
600
+ // ============================================================================
601
+ // PROMPT TEMPLATES
602
+ // ============================================================================
603
+
604
+ /**
605
+ * Natural language prompt variations for generating diverse training data
606
+ * Each template has placeholders for action, object, and description
607
+ */
608
+ const PROMPT_TEMPLATES = {
609
+ // Direct commands
610
+ direct: [
611
+ '{action} {object}',
612
+ '{action} the {object}',
613
+ 'Please {action} {object}',
614
+ 'I need to {action} {object}',
615
+ ],
616
+ // Request style
617
+ request: [
618
+ 'Can you {action} {object}?',
619
+ 'Help me {action} {object}',
620
+ 'I want to {action} {object}',
621
+ 'Could you {action} {object} for me?',
622
+ ],
623
+ // Question style
624
+ question: [
625
+ 'How do I {action} {object}?',
626
+ 'What\'s the best way to {action} {object}?',
627
+ 'How can I {action} {object}?',
628
+ 'Which command {desc}?',
629
+ ],
630
+ // Contextual
631
+ contextual: [
632
+ 'I\'m trying to {desc}',
633
+ 'I need a way to {desc}',
634
+ 'My goal is to {desc}',
635
+ 'For this project, I need to {desc}',
636
+ ],
637
+ // Descriptive
638
+ descriptive: [
639
+ '{desc}',
640
+ 'Help with {desc}',
641
+ 'I want {desc}',
642
+ 'Need {desc}',
643
+ ],
644
+ };
645
+
646
+ /**
647
+ * Action verbs mapped to capability types
648
+ */
649
+ const ACTION_MAPPINGS = {
650
+ // Swarm/Agent actions
651
+ swarm: ['initialize', 'start', 'create', 'set up', 'configure', 'launch'],
652
+ agent: ['spawn', 'create', 'start', 'launch', 'deploy', 'run'],
653
+ terminate: ['stop', 'kill', 'terminate', 'shutdown', 'end', 'close'],
654
+ status: ['check', 'get', 'view', 'show', 'monitor', 'inspect'],
655
+ list: ['list', 'show', 'display', 'enumerate', 'get all'],
656
+
657
+ // Memory actions
658
+ store: ['store', 'save', 'persist', 'write', 'put', 'cache'],
659
+ retrieve: ['retrieve', 'get', 'fetch', 'read', 'load'],
660
+ search: ['search', 'find', 'query', 'look up', 'discover'],
661
+ delete: ['delete', 'remove', 'clear', 'drop', 'erase'],
662
+
663
+ // Workflow actions
664
+ create: ['create', 'make', 'build', 'define', 'set up'],
665
+ execute: ['execute', 'run', 'start', 'trigger', 'launch'],
666
+
667
+ // Vector operations
668
+ embed: ['embed', 'encode', 'vectorize', 'generate embedding for'],
669
+ insert: ['insert', 'add', 'upsert', 'put', 'store'],
670
+ knn: ['find similar', 'search for nearest', 'query neighbors', 'find k-nearest'],
671
+
672
+ // Index operations
673
+ build: ['build', 'create', 'construct', 'generate'],
674
+ optimize: ['optimize', 'tune', 'improve', 'speed up'],
675
+ rebuild: ['rebuild', 'regenerate', 'refresh', 'recreate'],
676
+ };
677
+
678
+ // ============================================================================
679
+ // HARD NEGATIVE PATTERNS
680
+ // ============================================================================
681
+
682
+ /**
683
+ * Confusing command pairs for hard negative generation
684
+ * These are commands that sound similar but have different purposes
685
+ */
686
+ const CONFUSING_PAIRS = [
687
+ // Claude Flow internal confusion
688
+ { cmd1: 'memory store', cmd2: 'memory search', reason: 'both involve memory' },
689
+ { cmd1: 'agent spawn', cmd2: 'hive-mind spawn', reason: 'both spawn workers' },
690
+ { cmd1: 'swarm init', cmd2: 'hive-mind init', reason: 'both initialize coordination' },
691
+ { cmd1: 'hooks route', cmd2: 'hooks pre-task', reason: 'both involve task routing' },
692
+ { cmd1: 'workflow execute', cmd2: 'task create', reason: 'both start work' },
693
+ { cmd1: 'session save', cmd2: 'memory store', reason: 'both persist data' },
694
+ { cmd1: 'neural train', cmd2: 'hooks pretrain', reason: 'both involve training' },
695
+ { cmd1: 'embeddings search', cmd2: 'memory search', reason: 'both search semantically' },
696
+ { cmd1: 'performance profile', cmd2: 'performance benchmark', reason: 'both analyze performance' },
697
+ { cmd1: 'claims claim', cmd2: 'task create', reason: 'both assign work' },
698
+
699
+ // Cross-tool confusion
700
+ { cmd1: 'claude-flow memory search', cmd2: 'ruvector search knn', reason: 'both do vector search' },
701
+ { cmd1: 'claude-flow embeddings generate', cmd2: 'agentic-flow embed', reason: 'both generate embeddings' },
702
+ { cmd1: 'ruvector collection create', cmd2: 'claude-flow memory store', reason: 'both store data' },
703
+ { cmd1: 'agentic-flow cache set', cmd2: 'claude-flow memory store', reason: 'both cache data' },
704
+ { cmd1: 'ruvector index build', cmd2: 'claude-flow hooks pretrain', reason: 'both build indexes' },
705
+ { cmd1: 'agentic-flow search hybrid', cmd2: 'ruvector search filter', reason: 'both filtered search' },
706
+ { cmd1: 'claude-flow swarm init', cmd2: 'agentic-flow pipeline create', reason: 'both orchestrate work' },
707
+
708
+ // Category confusion
709
+ { cmd1: 'ruvector vector insert', cmd2: 'agentic-flow cache set', reason: 'both store vectors' },
710
+ { cmd1: 'claude-flow agent list', cmd2: 'agentic-flow model list', reason: 'both list resources' },
711
+ { cmd1: 'ruvector snapshot create', cmd2: 'claude-flow session save', reason: 'both create backups' },
712
+ { cmd1: 'agentic-flow model quantize', cmd2: 'ruvector quantize apply', reason: 'both quantize' },
713
+ ];
714
+
715
+ // ============================================================================
716
+ // TRIPLET GENERATION
717
+ // ============================================================================
718
+
719
+ /**
720
+ * Generate natural language prompts for a capability
721
+ */
722
+ function generatePrompts(capability, command, config) {
723
+ const prompts = [];
724
+ const { description, keywords } = config;
725
+
726
+ // Extract action and object from command
727
+ const parts = command.split(' ');
728
+ const category = parts[0];
729
+ const action = parts[1] || parts[0];
730
+
731
+ // Get action variations - but avoid repeating category name as action
732
+ const actionVariations = ACTION_MAPPINGS[action] || [action];
733
+ const primaryAction = actionVariations[0];
734
+
735
+ // Create clean description for prompts
736
+ const descLower = description.toLowerCase();
737
+
738
+ // Avoid redundant phrases like "search search" or "status status"
739
+ const isActionSameAsCategory = primaryAction.toLowerCase() === category.toLowerCase();
740
+
741
+ // Direct commands: "{action} {object}"
742
+ if (!isActionSameAsCategory) {
743
+ prompts.push(`${primaryAction} ${category}`);
744
+ prompts.push(`${primaryAction} the ${category}`);
745
+ prompts.push(`I need to ${primaryAction} ${category}`);
746
+ prompts.push(`Can you ${primaryAction} ${category}?`);
747
+ prompts.push(`Help me ${primaryAction} ${category}`);
748
+ } else {
749
+ // When action == category, use description instead
750
+ prompts.push(`${primaryAction}`);
751
+ prompts.push(`I need to ${primaryAction}`);
752
+ prompts.push(`Help me ${primaryAction}`);
753
+ }
754
+
755
+ // Use description-based prompts (always good quality)
756
+ prompts.push(`I want to ${descLower}`);
757
+ prompts.push(`How do I ${descLower}?`);
758
+ prompts.push(`I need a way to ${descLower}`);
759
+
760
+ // Action variations (skip if redundant)
761
+ for (const actionVar of actionVariations.slice(1, 3)) {
762
+ if (actionVar.toLowerCase() !== category.toLowerCase()) {
763
+ prompts.push(`${actionVar} ${category}`);
764
+ prompts.push(`I want to ${actionVar} ${category}`);
765
+ }
766
+ }
767
+
768
+ // Keyword-based prompts (only use unique keywords not in action/category)
769
+ const usedWords = new Set([primaryAction.toLowerCase(), category.toLowerCase(),
770
+ ...actionVariations.map(a => a.toLowerCase())]);
771
+ for (const keyword of keywords) {
772
+ const kwLower = keyword.toLowerCase();
773
+ if (!usedWords.has(kwLower) && kwLower !== category.toLowerCase()) {
774
+ prompts.push(`${keyword} in ${category}`);
775
+ prompts.push(`I need ${keyword} functionality`);
776
+ usedWords.add(kwLower);
777
+ if (usedWords.size > keywords.length + 3) break;
778
+ }
779
+ }
780
+
781
+ // Tool-specific technical prompts
782
+ prompts.push(`run ${command}`);
783
+ prompts.push(`${capability} ${command}`);
784
+
785
+ // Clean up prompts: remove duplicates, fix spacing, validate
786
+ const cleanPrompts = [...new Set(prompts)]
787
+ .map(p => p.trim().replace(/\s+/g, ' '))
788
+ .filter(p => {
789
+ // Filter out bad prompts
790
+ if (p.length < 5) return false;
791
+ if (p.includes('undefined')) return false;
792
+ // Check for redundant word repetition (e.g., "status status")
793
+ const words = p.toLowerCase().split(' ');
794
+ for (let i = 0; i < words.length - 1; i++) {
795
+ if (words[i] === words[i + 1] && words[i].length > 2) return false;
796
+ }
797
+ return true;
798
+ })
799
+ .slice(0, 10);
800
+
801
+ return cleanPrompts;
802
+ }
803
+
804
+ /**
805
+ * Find hard negatives for a command
806
+ */
807
+ function findHardNegatives(tool, command, allCapabilities) {
808
+ const negatives = [];
809
+ const fullCommand = `${tool} ${command}`;
810
+
811
+ // Find from predefined confusing pairs
812
+ for (const pair of CONFUSING_PAIRS) {
813
+ if (pair.cmd1.includes(command) || pair.cmd2.includes(command)) {
814
+ const negative = pair.cmd1.includes(command) ? pair.cmd2 : pair.cmd1;
815
+ negatives.push({
816
+ command: negative,
817
+ reason: pair.reason,
818
+ });
819
+ }
820
+ }
821
+
822
+ // Find similar commands from other tools
823
+ for (const cap of allCapabilities) {
824
+ if (cap.name === tool) continue;
825
+
826
+ for (const [catName, category] of Object.entries(cap.categories)) {
827
+ for (const [cmdName, cmdConfig] of Object.entries(category.commands)) {
828
+ // Check for keyword overlap
829
+ const cmdKeywords = cmdConfig.keywords || [];
830
+ const sourceConfig = getCommandConfig(tool, command, allCapabilities);
831
+ const sourceKeywords = sourceConfig?.keywords || [];
832
+
833
+ const overlap = cmdKeywords.filter((k) => sourceKeywords.includes(k));
834
+ if (overlap.length >= 2) {
835
+ negatives.push({
836
+ command: `${cap.name} ${cmdName}`,
837
+ reason: `keyword overlap: ${overlap.join(', ')}`,
838
+ });
839
+ }
840
+ }
841
+ }
842
+ }
843
+
844
+ // Find similar commands within same tool (different category)
845
+ const sourceCapability = allCapabilities.find((c) => c.name === tool);
846
+ if (sourceCapability) {
847
+ const [sourceCategory] = command.split(' ');
848
+ for (const [catName, category] of Object.entries(sourceCapability.categories)) {
849
+ if (catName === sourceCategory) continue;
850
+
851
+ for (const [cmdName, cmdConfig] of Object.entries(category.commands)) {
852
+ // Similar action words
853
+ const cmdAction = cmdName.split(' ')[1] || cmdName.split(' ')[0];
854
+ const sourceAction = command.split(' ')[1] || command.split(' ')[0];
855
+
856
+ if (cmdAction === sourceAction) {
857
+ negatives.push({
858
+ command: `${tool} ${cmdName}`,
859
+ reason: `same action '${cmdAction}' different category`,
860
+ });
861
+ }
862
+ }
863
+ }
864
+ }
865
+
866
+ // Limit and deduplicate
867
+ const seen = new Set();
868
+ return negatives.filter((n) => {
869
+ if (seen.has(n.command)) return false;
870
+ seen.add(n.command);
871
+ return true;
872
+ }).slice(0, 5);
873
+ }
874
+
875
+ /**
876
+ * Get command config from capabilities
877
+ */
878
+ function getCommandConfig(tool, command, allCapabilities) {
879
+ const capability = allCapabilities.find((c) => c.name === tool);
880
+ if (!capability) return null;
881
+
882
+ for (const category of Object.values(capability.categories)) {
883
+ if (category.commands[command]) {
884
+ return category.commands[command];
885
+ }
886
+ }
887
+ return null;
888
+ }
889
+
890
+ /**
891
+ * Generate triplets for all capabilities
892
+ */
893
+ function generateTriplets(capabilities) {
894
+ const triplets = [];
895
+
896
+ for (const cap of capabilities) {
897
+ for (const [catName, category] of Object.entries(cap.categories)) {
898
+ for (const [cmdName, cmdConfig] of Object.entries(category.commands)) {
899
+ const fullCommand = `${cap.name} ${cmdName}`;
900
+ const prompts = generatePrompts(cap.name, cmdName, cmdConfig);
901
+ const negatives = findHardNegatives(cap.name, cmdName, capabilities);
902
+
903
+ // Create triplets
904
+ for (const prompt of prompts) {
905
+ // Skip malformed prompts
906
+ if (!prompt || prompt.length < 5) continue;
907
+
908
+ // For each prompt, create triplets with each negative
909
+ if (negatives.length > 0) {
910
+ for (const negative of negatives) {
911
+ // Ensure negative has full tool prefix
912
+ let negCommand = negative.command;
913
+ if (!negCommand.includes(' ') || (!negCommand.startsWith('claude-flow') &&
914
+ !negCommand.startsWith('agentic-flow') && !negCommand.startsWith('ruvector'))) {
915
+ continue; // Skip incomplete negatives
916
+ }
917
+
918
+ // Skip if negative equals positive
919
+ if (negCommand === fullCommand) continue;
920
+
921
+ triplets.push({
922
+ anchor: prompt,
923
+ positive: fullCommand,
924
+ negative: negCommand,
925
+ isHard: true,
926
+ category: catName,
927
+ tool: cap.name,
928
+ });
929
+ }
930
+ } else {
931
+ // Create triplet with random different tool command as negative
932
+ const otherCaps = capabilities.filter((c) => c.name !== cap.name);
933
+ if (otherCaps.length > 0) {
934
+ const randomCap = otherCaps[Math.floor(Math.random() * otherCaps.length)];
935
+ const randomCatName = Object.keys(randomCap.categories)[0];
936
+ const randomCmdName = Object.keys(randomCap.categories[randomCatName].commands)[0];
937
+ const negCommand = `${randomCap.name} ${randomCmdName}`;
938
+
939
+ // Skip if somehow equals positive
940
+ if (negCommand === fullCommand) continue;
941
+
942
+ triplets.push({
943
+ anchor: prompt,
944
+ positive: fullCommand,
945
+ negative: negCommand,
946
+ isHard: false,
947
+ category: catName,
948
+ tool: cap.name,
949
+ });
950
+ }
951
+ }
952
+ }
953
+ }
954
+ }
955
+ }
956
+
957
+ return triplets;
958
+ }
959
+
960
+ /**
961
+ * Generate category-specific examples with rich diversity
962
+ */
963
+ function generateCategoryExamples() {
964
+ const examples = [];
965
+
966
+ // ---- SWARM COORDINATION ----
967
+ const swarmExamples = [
968
+ // Initialization
969
+ { anchor: 'Set up a multi-agent swarm for parallel processing', positive: 'claude-flow swarm init', negatives: ['agentic-flow pipeline create', 'claude-flow agent spawn'] },
970
+ { anchor: 'Initialize hierarchical agent coordination', positive: 'claude-flow swarm init', negatives: ['claude-flow hive-mind init'] },
971
+ { anchor: 'Create a mesh topology swarm with 10 agents', positive: 'claude-flow swarm init', negatives: ['claude-flow hive-mind spawn'] },
972
+ { anchor: 'Configure swarm consensus using raft protocol', positive: 'claude-flow swarm init', negatives: ['claude-flow hive-mind consensus'] },
973
+ { anchor: 'Start a queen-led hive-mind collective', positive: 'claude-flow hive-mind init', negatives: ['claude-flow swarm init'] },
974
+ { anchor: 'Coordinate multiple AI agents on a complex task', positive: 'claude-flow swarm init', negatives: ['agentic-flow pipeline create'] },
975
+ { anchor: 'Set up Byzantine fault-tolerant consensus', positive: 'claude-flow hive-mind init', negatives: ['claude-flow swarm init'] },
976
+ { anchor: 'Launch a distributed agent network', positive: 'claude-flow swarm init', negatives: ['claude-flow agent spawn'] },
977
+ { anchor: 'Create a star topology for centralized coordination', positive: 'claude-flow swarm init', negatives: ['claude-flow hive-mind init'] },
978
+ // Status/monitoring
979
+ { anchor: 'Check the health of all running agents', positive: 'claude-flow swarm status', negatives: ['claude-flow agent status'] },
980
+ { anchor: 'Monitor swarm performance and throughput', positive: 'claude-flow swarm status', negatives: ['claude-flow performance benchmark'] },
981
+ { anchor: 'Get swarm coordination status', positive: 'claude-flow swarm status', negatives: ['claude-flow agent list'] },
982
+ ];
983
+
984
+ // ---- AGENT MANAGEMENT ----
985
+ const agentExamples = [
986
+ { anchor: 'Spawn a coder agent to implement features', positive: 'claude-flow agent spawn', negatives: ['claude-flow hive-mind spawn', 'claude-flow task create'] },
987
+ { anchor: 'Create a new worker agent for this task', positive: 'claude-flow agent spawn', negatives: ['claude-flow hive-mind spawn'] },
988
+ { anchor: 'Start a researcher agent to investigate', positive: 'claude-flow agent spawn', negatives: ['claude-flow task create'] },
989
+ { anchor: 'List all active agents in the system', positive: 'claude-flow agent list', negatives: ['agentic-flow model list', 'ruvector collection list'] },
990
+ { anchor: 'Show running agent processes', positive: 'claude-flow agent list', negatives: ['claude-flow task list'] },
991
+ { anchor: 'Kill a misbehaving agent', positive: 'claude-flow agent terminate', negatives: ['claude-flow swarm shutdown'] },
992
+ { anchor: 'Stop the agent that is stuck', positive: 'claude-flow agent terminate', negatives: ['claude-flow task cancel'] },
993
+ { anchor: 'Get details about a specific agent', positive: 'claude-flow agent status', negatives: ['claude-flow swarm status'] },
994
+ ];
995
+
996
+ // ---- MEMORY OPERATIONS ----
997
+ const memoryExamples = [
998
+ // Store operations
999
+ { anchor: 'Store learned patterns for future reference', positive: 'claude-flow memory store', negatives: ['ruvector vector insert', 'agentic-flow cache set'] },
1000
+ { anchor: 'Save task completion metrics to memory', positive: 'claude-flow memory store', negatives: ['claude-flow session save'] },
1001
+ { anchor: 'Persist agent decisions for analysis', positive: 'claude-flow memory store', negatives: ['ruvector vector insert'] },
1002
+ { anchor: 'Cache successful code patterns', positive: 'claude-flow memory store', negatives: ['agentic-flow cache set'] },
1003
+ { anchor: 'Remember this debugging solution', positive: 'claude-flow memory store', negatives: ['agentic-flow cache set'] },
1004
+ { anchor: 'Store API response for later retrieval', positive: 'claude-flow memory store', negatives: ['ruvector vector insert'] },
1005
+ { anchor: 'Save this configuration for reuse', positive: 'claude-flow memory store', negatives: ['claude-flow session save'] },
1006
+ // Retrieve operations
1007
+ { anchor: 'Get the stored pattern for authentication', positive: 'claude-flow memory retrieve', negatives: ['claude-flow memory search', 'ruvector vector get'] },
1008
+ { anchor: 'Fetch previously saved configuration', positive: 'claude-flow memory retrieve', negatives: ['claude-flow session restore'] },
1009
+ { anchor: 'Load cached data from memory', positive: 'claude-flow memory retrieve', negatives: ['agentic-flow cache get'] },
1010
+ // Search operations
1011
+ { anchor: 'Search memory for similar patterns', positive: 'claude-flow memory search', negatives: ['ruvector search knn', 'agentic-flow search nearest'] },
1012
+ { anchor: 'Find relevant past solutions', positive: 'claude-flow memory search', negatives: ['ruvector search filter'] },
1013
+ { anchor: 'Query semantic memory for debugging tips', positive: 'claude-flow memory search', negatives: ['agentic-flow search hybrid'] },
1014
+ { anchor: 'Look up related patterns in storage', positive: 'claude-flow memory search', negatives: ['ruvector search knn'] },
1015
+ ];
1016
+
1017
+ // ---- VECTOR DATABASE (RUVECTOR) ----
1018
+ const vectorExamples = [
1019
+ // Search operations
1020
+ { anchor: 'Find k-nearest matches to this embedding', positive: 'ruvector search knn', negatives: ['claude-flow memory search', 'agentic-flow search nearest'] },
1021
+ { anchor: 'Search vectors with metadata filters', positive: 'ruvector search filter', negatives: ['claude-flow memory search', 'agentic-flow search hybrid'] },
1022
+ { anchor: 'Perform approximate nearest neighbor search', positive: 'ruvector search knn', negatives: ['agentic-flow search nearest'] },
1023
+ { anchor: 'Query the vector database for similar items', positive: 'ruvector search knn', negatives: ['claude-flow memory search'] },
1024
+ { anchor: 'Find similar embeddings in the collection', positive: 'ruvector search knn', negatives: ['claude-flow embeddings search'] },
1025
+ { anchor: 'Batch search multiple query vectors', positive: 'ruvector search batch', negatives: ['agentic-flow batch-embed'] },
1026
+ // Collection operations
1027
+ { anchor: 'Create a new vector collection for documents', positive: 'ruvector collection create', negatives: ['claude-flow memory store'] },
1028
+ { anchor: 'Set up a database for embedding storage', positive: 'ruvector collection create', negatives: ['agentic-flow cache set'] },
1029
+ { anchor: 'Delete the old vector collection', positive: 'ruvector collection delete', negatives: ['claude-flow memory delete'] },
1030
+ { anchor: 'Get information about the collection', positive: 'ruvector collection info', negatives: ['agentic-flow model info'] },
1031
+ // Vector CRUD
1032
+ { anchor: 'Insert embeddings into the database', positive: 'ruvector vector insert', negatives: ['claude-flow memory store', 'agentic-flow cache set'] },
1033
+ { anchor: 'Add vectors to the collection', positive: 'ruvector vector insert', negatives: ['claude-flow memory store'] },
1034
+ { anchor: 'Upsert vectors with metadata', positive: 'ruvector vector insert', negatives: ['agentic-flow cache set'] },
1035
+ { anchor: 'Delete vectors by ID', positive: 'ruvector vector delete', negatives: ['claude-flow memory delete'] },
1036
+ // Index operations
1037
+ { anchor: 'Build HNSW index for faster search', positive: 'ruvector index build', negatives: ['claude-flow hooks pretrain'] },
1038
+ { anchor: 'Create search index for vectors', positive: 'ruvector index build', negatives: ['claude-flow neural train'] },
1039
+ { anchor: 'Optimize index for query performance', positive: 'ruvector index optimize', negatives: ['claude-flow performance optimize'] },
1040
+ { anchor: 'Rebuild search index after updates', positive: 'ruvector index rebuild', negatives: ['claude-flow hooks pretrain'] },
1041
+ { anchor: 'Configure HNSW parameters for accuracy', positive: 'ruvector index build', negatives: ['ruvector quantize apply'] },
1042
+ // Persistence
1043
+ { anchor: 'Create a snapshot backup of vectors', positive: 'ruvector snapshot create', negatives: ['claude-flow session save'] },
1044
+ { anchor: 'Restore vectors from backup', positive: 'ruvector snapshot restore', negatives: ['claude-flow session restore'] },
1045
+ ];
1046
+
1047
+ // ---- EMBEDDINGS (AGENTIC-FLOW) ----
1048
+ const embeddingExamples = [
1049
+ { anchor: 'Generate embeddings for these documents', positive: 'agentic-flow embed', negatives: ['claude-flow embeddings generate'] },
1050
+ { anchor: 'Create vector representations of text', positive: 'agentic-flow embed', negatives: ['claude-flow embeddings generate'] },
1051
+ { anchor: 'Encode sentences into embeddings', positive: 'agentic-flow embed', negatives: ['claude-flow embeddings generate'] },
1052
+ { anchor: 'Vectorize code snippets for search', positive: 'agentic-flow embed', negatives: ['ruvector vector insert'] },
1053
+ { anchor: 'Produce semantic embeddings from descriptions', positive: 'agentic-flow embed', negatives: ['claude-flow embeddings generate'] },
1054
+ { anchor: 'Convert text to numerical vectors using ONNX', positive: 'agentic-flow embed', negatives: ['claude-flow embeddings generate'] },
1055
+ { anchor: 'Batch embed multiple documents efficiently', positive: 'agentic-flow batch-embed', negatives: ['ruvector search batch'] },
1056
+ { anchor: 'Embed large corpus in parallel', positive: 'agentic-flow batch-embed', negatives: ['ruvector vector insert'] },
1057
+ { anchor: 'Compare similarity between two texts', positive: 'agentic-flow similarity', negatives: ['claude-flow embeddings compare'] },
1058
+ { anchor: 'Calculate cosine distance between embeddings', positive: 'agentic-flow similarity', negatives: ['claude-flow embeddings compare'] },
1059
+ // Model operations
1060
+ { anchor: 'Load the ONNX model for inference', positive: 'agentic-flow model load', negatives: ['claude-flow neural train'] },
1061
+ { anchor: 'List available embedding models', positive: 'agentic-flow model list', negatives: ['claude-flow agent list'] },
1062
+ { anchor: 'Quantize the model for faster inference', positive: 'agentic-flow model quantize', negatives: ['ruvector quantize apply'] },
1063
+ // Cache operations
1064
+ { anchor: 'Cache the embedding for reuse', positive: 'agentic-flow cache set', negatives: ['claude-flow memory store'] },
1065
+ { anchor: 'Get cached embedding', positive: 'agentic-flow cache get', negatives: ['claude-flow memory retrieve'] },
1066
+ { anchor: 'Clear the embedding cache', positive: 'agentic-flow cache clear', negatives: ['claude-flow memory delete'] },
1067
+ // Search
1068
+ { anchor: 'Find nearest neighbors to query', positive: 'agentic-flow search nearest', negatives: ['ruvector search knn'] },
1069
+ { anchor: 'Hybrid keyword and semantic search', positive: 'agentic-flow search hybrid', negatives: ['ruvector search filter'] },
1070
+ // Pipeline
1071
+ { anchor: 'Create an embedding pipeline', positive: 'agentic-flow pipeline create', negatives: ['claude-flow workflow create'] },
1072
+ { anchor: 'Run the processing pipeline', positive: 'agentic-flow pipeline run', negatives: ['claude-flow workflow execute'] },
1073
+ ];
1074
+
1075
+ // ---- HOOKS AND LEARNING ----
1076
+ const hookExamples = [
1077
+ { anchor: 'Route this task to the optimal agent', positive: 'claude-flow hooks route', negatives: ['claude-flow agent spawn', 'claude-flow hooks pre-task'] },
1078
+ { anchor: 'Get agent suggestions before starting work', positive: 'claude-flow hooks pre-task', negatives: ['claude-flow hooks route'] },
1079
+ { anchor: 'Record task completion for learning', positive: 'claude-flow hooks post-task', negatives: ['claude-flow hooks metrics'] },
1080
+ { anchor: 'Analyze codebase to bootstrap intelligence', positive: 'claude-flow hooks pretrain', negatives: ['claude-flow neural train', 'ruvector index build'] },
1081
+ { anchor: 'Track metrics from completed tasks', positive: 'claude-flow hooks metrics', negatives: ['claude-flow performance benchmark'] },
1082
+ { anchor: 'Pre-train routing model on repository', positive: 'claude-flow hooks pretrain', negatives: ['claude-flow neural train'] },
1083
+ { anchor: 'Dispatch a background worker for optimization', positive: 'claude-flow hooks worker dispatch', negatives: ['claude-flow agent spawn'] },
1084
+ { anchor: 'Log task before starting', positive: 'claude-flow hooks pre-task', negatives: ['claude-flow task create'] },
1085
+ ];
1086
+
1087
+ // ---- WORKFLOW AND TASKS ----
1088
+ const workflowExamples = [
1089
+ { anchor: 'Create a new workflow for code review', positive: 'claude-flow workflow create', negatives: ['agentic-flow pipeline create', 'claude-flow task create'] },
1090
+ { anchor: 'Define a multi-step workflow', positive: 'claude-flow workflow create', negatives: ['agentic-flow pipeline create'] },
1091
+ { anchor: 'Execute the deployment workflow', positive: 'claude-flow workflow execute', negatives: ['agentic-flow pipeline run'] },
1092
+ { anchor: 'Run the CI/CD workflow', positive: 'claude-flow workflow execute', negatives: ['claude-flow task create'] },
1093
+ { anchor: 'Check workflow execution status', positive: 'claude-flow workflow status', negatives: ['claude-flow task status'] },
1094
+ { anchor: 'Create a task for the coder agent', positive: 'claude-flow task create', negatives: ['claude-flow agent spawn'] },
1095
+ { anchor: 'Add a new task to the queue', positive: 'claude-flow task create', negatives: ['claude-flow workflow create'] },
1096
+ { anchor: 'Mark this task as complete', positive: 'claude-flow task complete', negatives: ['claude-flow hooks post-task'] },
1097
+ { anchor: 'List pending tasks', positive: 'claude-flow task list', negatives: ['claude-flow agent list'] },
1098
+ ];
1099
+
1100
+ // ---- SESSION AND STATE ----
1101
+ const sessionExamples = [
1102
+ { anchor: 'Save the current session state', positive: 'claude-flow session save', negatives: ['claude-flow memory store', 'ruvector snapshot create'] },
1103
+ { anchor: 'Persist session for later continuation', positive: 'claude-flow session save', negatives: ['claude-flow memory store'] },
1104
+ { anchor: 'Restore previous session', positive: 'claude-flow session restore', negatives: ['ruvector snapshot restore', 'claude-flow memory retrieve'] },
1105
+ { anchor: 'Continue where I left off', positive: 'claude-flow session restore', negatives: ['claude-flow memory retrieve'] },
1106
+ { anchor: 'List saved sessions', positive: 'claude-flow session list', negatives: ['claude-flow memory list'] },
1107
+ ];
1108
+
1109
+ // ---- NEURAL AND ML ----
1110
+ const neuralExamples = [
1111
+ { anchor: 'Train the routing model', positive: 'claude-flow neural train', negatives: ['claude-flow hooks pretrain'] },
1112
+ { anchor: 'Train neural patterns for better routing', positive: 'claude-flow neural train', negatives: ['claude-flow hooks pretrain'] },
1113
+ { anchor: 'Make prediction with neural model', positive: 'claude-flow neural predict', negatives: ['claude-flow hooks route'] },
1114
+ { anchor: 'Get neural routing prediction', positive: 'claude-flow neural predict', negatives: ['agentic-flow embed'] },
1115
+ { anchor: 'Store learned neural patterns', positive: 'claude-flow neural patterns', negatives: ['claude-flow memory store'] },
1116
+ ];
1117
+
1118
+ // ---- PERFORMANCE AND SECURITY ----
1119
+ const perfExamples = [
1120
+ { anchor: 'Benchmark system performance', positive: 'claude-flow performance benchmark', negatives: ['claude-flow hooks metrics'] },
1121
+ { anchor: 'Profile slow operations', positive: 'claude-flow performance profile', negatives: ['claude-flow performance benchmark'] },
1122
+ { anchor: 'Optimize for lower latency', positive: 'claude-flow performance optimize', negatives: ['ruvector index optimize'] },
1123
+ { anchor: 'Scan input for security threats', positive: 'claude-flow aidefence scan', negatives: ['claude-flow hooks pre-task'] },
1124
+ { anchor: 'Check if input is safe', positive: 'claude-flow aidefence is_safe', negatives: ['claude-flow aidefence scan'] },
1125
+ { anchor: 'Analyze potential prompt injection', positive: 'claude-flow aidefence analyze', negatives: ['claude-flow hooks route'] },
1126
+ ];
1127
+
1128
+ // ---- CLAIMS AND COORDINATION ----
1129
+ const claimsExamples = [
1130
+ { anchor: 'Claim this issue for work', positive: 'claude-flow claims claim', negatives: ['claude-flow task create'] },
1131
+ { anchor: 'Assign this issue to me', positive: 'claude-flow claims claim', negatives: ['claude-flow task create'] },
1132
+ { anchor: 'Release my claim on this issue', positive: 'claude-flow claims release', negatives: ['claude-flow task complete'] },
1133
+ { anchor: 'Hand off issue to another agent', positive: 'claude-flow claims handoff', negatives: ['claude-flow claims release'] },
1134
+ { anchor: 'View the claims board', positive: 'claude-flow claims board', negatives: ['claude-flow task list'] },
1135
+ ];
1136
+
1137
+ // Convert all examples to triplet format
1138
+ const allExampleSets = [
1139
+ swarmExamples, agentExamples, memoryExamples, vectorExamples,
1140
+ embeddingExamples, hookExamples, workflowExamples, sessionExamples,
1141
+ neuralExamples, perfExamples, claimsExamples
1142
+ ];
1143
+
1144
+ for (const exampleSet of allExampleSets) {
1145
+ for (const ex of exampleSet) {
1146
+ const negatives = ex.negatives || [ex.negative];
1147
+ for (const neg of negatives) {
1148
+ examples.push({
1149
+ anchor: ex.anchor,
1150
+ positive: ex.positive,
1151
+ negative: neg,
1152
+ isHard: true,
1153
+ });
1154
+ }
1155
+ }
1156
+ }
1157
+
1158
+ return examples;
1159
+ }
1160
+
1161
+ // ============================================================================
1162
+ // MAIN GENERATION
1163
+ // ============================================================================
1164
+
1165
+ /**
1166
+ * Save capability definitions to JSON files
1167
+ */
1168
+ function saveCapabilities(outputDir) {
1169
+ const capabilities = [
1170
+ { filename: 'claude-flow-capabilities.json', data: CLAUDE_FLOW_CAPABILITIES },
1171
+ { filename: 'agentic-flow-capabilities.json', data: AGENTIC_FLOW_CAPABILITIES },
1172
+ { filename: 'ruvector-capabilities.json', data: RUVECTOR_CAPABILITIES },
1173
+ ];
1174
+
1175
+ for (const { filename, data } of capabilities) {
1176
+ const filepath = path.join(outputDir, filename);
1177
+ fs.writeFileSync(filepath, JSON.stringify(data, null, 2));
1178
+ console.log(` Saved ${filepath}`);
1179
+ }
1180
+ }
1181
+
1182
+ /**
1183
+ * Main entry point
1184
+ */
1185
+ function main() {
1186
+ console.log('\n' + '='.repeat(80));
1187
+ console.log(' ECOSYSTEM TRAINING DATA GENERATOR FOR RUVLTRA');
1188
+ console.log('='.repeat(80) + '\n');
1189
+
1190
+ const args = process.argv.slice(2);
1191
+ const outputDir = path.dirname(path.resolve(__filename));
1192
+ const outputFile = args.find((a) => a.startsWith('--output='))?.split('=')[1] ||
1193
+ path.join(outputDir, 'ecosystem-triplets.jsonl');
1194
+ const saveCapabilityFiles = args.includes('--save-capabilities');
1195
+
1196
+ console.log('Configuration:');
1197
+ console.log(` Output: ${outputFile}`);
1198
+ console.log(` Save capability JSONs: ${saveCapabilityFiles}`);
1199
+ console.log();
1200
+
1201
+ // All capabilities
1202
+ const allCapabilities = [
1203
+ CLAUDE_FLOW_CAPABILITIES,
1204
+ AGENTIC_FLOW_CAPABILITIES,
1205
+ RUVECTOR_CAPABILITIES,
1206
+ ];
1207
+
1208
+ // Save capability definitions if requested
1209
+ if (saveCapabilityFiles) {
1210
+ console.log('Saving capability definitions...');
1211
+ saveCapabilities(outputDir);
1212
+ console.log();
1213
+ }
1214
+
1215
+ // Generate triplets
1216
+ console.log('Generating training triplets...');
1217
+
1218
+ const triplets = generateTriplets(allCapabilities);
1219
+ const categoryExamples = generateCategoryExamples();
1220
+
1221
+ // Combine all triplets
1222
+ const allTriplets = [...triplets, ...categoryExamples];
1223
+
1224
+ // Shuffle for better training
1225
+ allTriplets.sort(() => Math.random() - 0.5);
1226
+
1227
+ // Statistics
1228
+ const stats = {
1229
+ total: allTriplets.length,
1230
+ byTool: {},
1231
+ byCategory: {},
1232
+ hardNegatives: 0,
1233
+ };
1234
+
1235
+ for (const t of allTriplets) {
1236
+ if (t.tool) {
1237
+ stats.byTool[t.tool] = (stats.byTool[t.tool] || 0) + 1;
1238
+ }
1239
+ if (t.category) {
1240
+ stats.byCategory[t.category] = (stats.byCategory[t.category] || 0) + 1;
1241
+ }
1242
+ if (t.isHard) {
1243
+ stats.hardNegatives++;
1244
+ }
1245
+ }
1246
+
1247
+ // Save triplets as JSONL
1248
+ const jsonlContent = allTriplets.map((t) => JSON.stringify({
1249
+ anchor: t.anchor,
1250
+ positive: t.positive,
1251
+ negative: t.negative,
1252
+ })).join('\n');
1253
+
1254
+ fs.writeFileSync(outputFile, jsonlContent);
1255
+
1256
+ // Print summary
1257
+ console.log('\n' + '-'.repeat(60));
1258
+ console.log(' GENERATION SUMMARY');
1259
+ console.log('-'.repeat(60) + '\n');
1260
+
1261
+ console.log(`Total triplets generated: ${stats.total}`);
1262
+ console.log(`Hard negatives: ${stats.hardNegatives} (${((stats.hardNegatives / stats.total) * 100).toFixed(1)}%)`);
1263
+ console.log();
1264
+
1265
+ console.log('Triplets by tool:');
1266
+ for (const [tool, count] of Object.entries(stats.byTool)) {
1267
+ console.log(` ${tool.padEnd(20)} ${count}`);
1268
+ }
1269
+ console.log();
1270
+
1271
+ console.log('Triplets by category:');
1272
+ for (const [category, count] of Object.entries(stats.byCategory).slice(0, 10)) {
1273
+ console.log(` ${category.padEnd(20)} ${count}`);
1274
+ }
1275
+ if (Object.keys(stats.byCategory).length > 10) {
1276
+ console.log(` ... and ${Object.keys(stats.byCategory).length - 10} more categories`);
1277
+ }
1278
+ console.log();
1279
+
1280
+ console.log(`Output saved to: ${outputFile}`);
1281
+ console.log();
1282
+
1283
+ // Show sample triplets
1284
+ console.log('-'.repeat(60));
1285
+ console.log(' SAMPLE TRIPLETS');
1286
+ console.log('-'.repeat(60) + '\n');
1287
+
1288
+ for (const triplet of allTriplets.slice(0, 5)) {
1289
+ console.log(` Anchor: "${triplet.anchor}"`);
1290
+ console.log(` Positive: ${triplet.positive}`);
1291
+ console.log(` Negative: ${triplet.negative}`);
1292
+ console.log();
1293
+ }
1294
+
1295
+ console.log('='.repeat(80));
1296
+ console.log(' NEXT STEPS');
1297
+ console.log('='.repeat(80) + '\n');
1298
+
1299
+ console.log('1. Merge with existing training data:');
1300
+ console.log(` cat ~/.ruvllm/training/ruvltra-finetuned/triplets.jsonl ${outputFile} > combined.jsonl`);
1301
+ console.log();
1302
+ console.log('2. Train with contrastive loss:');
1303
+ console.log(' cargo run --example train_contrastive --release -- --triplets combined.jsonl --epochs 30');
1304
+ console.log();
1305
+ console.log('3. Evaluate routing accuracy improvement');
1306
+ console.log();
1307
+ }
1308
+
1309
+ // Export for testing
1310
+ module.exports = {
1311
+ CLAUDE_FLOW_CAPABILITIES,
1312
+ AGENTIC_FLOW_CAPABILITIES,
1313
+ RUVECTOR_CAPABILITIES,
1314
+ generatePrompts,
1315
+ findHardNegatives,
1316
+ generateTriplets,
1317
+ generateCategoryExamples,
1318
+ CONFUSING_PAIRS,
1319
+ };
1320
+
1321
+ // Run if called directly
1322
+ if (require.main === module) {
1323
+ main();
1324
+ }