ruvector 0.1.64 → 0.1.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/mcp-server.js CHANGED
@@ -565,6 +565,296 @@ const TOOLS = [
565
565
  properties: {},
566
566
  required: []
567
567
  }
568
+ },
569
+ // ============================================
570
+ // NEW CAPABILITY TOOLS (AST, Diff, Coverage, Graph, Security, RAG)
571
+ // ============================================
572
+ {
573
+ name: 'hooks_ast_analyze',
574
+ description: 'Parse file AST and extract symbols, imports, complexity metrics',
575
+ inputSchema: {
576
+ type: 'object',
577
+ properties: {
578
+ file: { type: 'string', description: 'File path to analyze' }
579
+ },
580
+ required: ['file']
581
+ }
582
+ },
583
+ {
584
+ name: 'hooks_ast_complexity',
585
+ description: 'Get cyclomatic and cognitive complexity metrics for files',
586
+ inputSchema: {
587
+ type: 'object',
588
+ properties: {
589
+ files: { type: 'array', items: { type: 'string' }, description: 'Files to analyze' },
590
+ threshold: { type: 'number', description: 'Warn if complexity exceeds threshold', default: 10 }
591
+ },
592
+ required: ['files']
593
+ }
594
+ },
595
+ {
596
+ name: 'hooks_diff_analyze',
597
+ description: 'Analyze git diff with semantic embeddings and risk scoring',
598
+ inputSchema: {
599
+ type: 'object',
600
+ properties: {
601
+ commit: { type: 'string', description: 'Commit hash (defaults to staged changes)' }
602
+ },
603
+ required: []
604
+ }
605
+ },
606
+ {
607
+ name: 'hooks_diff_classify',
608
+ description: 'Classify change type (feature, bugfix, refactor, docs, test, config)',
609
+ inputSchema: {
610
+ type: 'object',
611
+ properties: {
612
+ commit: { type: 'string', description: 'Commit hash (defaults to HEAD)' }
613
+ },
614
+ required: []
615
+ }
616
+ },
617
+ {
618
+ name: 'hooks_diff_similar',
619
+ description: 'Find similar past commits based on diff embeddings',
620
+ inputSchema: {
621
+ type: 'object',
622
+ properties: {
623
+ top_k: { type: 'number', description: 'Number of results', default: 5 },
624
+ commits: { type: 'number', description: 'Recent commits to search', default: 50 }
625
+ },
626
+ required: []
627
+ }
628
+ },
629
+ {
630
+ name: 'hooks_coverage_route',
631
+ description: 'Get coverage-aware agent routing for a file',
632
+ inputSchema: {
633
+ type: 'object',
634
+ properties: {
635
+ file: { type: 'string', description: 'File to analyze' }
636
+ },
637
+ required: ['file']
638
+ }
639
+ },
640
+ {
641
+ name: 'hooks_coverage_suggest',
642
+ description: 'Suggest tests for files based on coverage data',
643
+ inputSchema: {
644
+ type: 'object',
645
+ properties: {
646
+ files: { type: 'array', items: { type: 'string' }, description: 'Files to analyze' }
647
+ },
648
+ required: ['files']
649
+ }
650
+ },
651
+ {
652
+ name: 'hooks_graph_mincut',
653
+ description: 'Find optimal code boundaries using MinCut algorithm (Stoer-Wagner)',
654
+ inputSchema: {
655
+ type: 'object',
656
+ properties: {
657
+ files: { type: 'array', items: { type: 'string' }, description: 'Files to analyze' }
658
+ },
659
+ required: ['files']
660
+ }
661
+ },
662
+ {
663
+ name: 'hooks_graph_cluster',
664
+ description: 'Detect code communities using spectral or Louvain clustering',
665
+ inputSchema: {
666
+ type: 'object',
667
+ properties: {
668
+ files: { type: 'array', items: { type: 'string' }, description: 'Files to analyze' },
669
+ method: { type: 'string', enum: ['spectral', 'louvain'], default: 'louvain' },
670
+ clusters: { type: 'number', description: 'Number of clusters (spectral only)', default: 3 }
671
+ },
672
+ required: ['files']
673
+ }
674
+ },
675
+ {
676
+ name: 'hooks_security_scan',
677
+ description: 'Parallel security vulnerability scan for common issues',
678
+ inputSchema: {
679
+ type: 'object',
680
+ properties: {
681
+ files: { type: 'array', items: { type: 'string' }, description: 'Files to scan' }
682
+ },
683
+ required: ['files']
684
+ }
685
+ },
686
+ {
687
+ name: 'hooks_rag_context',
688
+ description: 'Get RAG-enhanced context for a query with optional reranking',
689
+ inputSchema: {
690
+ type: 'object',
691
+ properties: {
692
+ query: { type: 'string', description: 'Query for context' },
693
+ top_k: { type: 'number', description: 'Number of results', default: 5 },
694
+ rerank: { type: 'boolean', description: 'Rerank results by relevance', default: false }
695
+ },
696
+ required: ['query']
697
+ }
698
+ },
699
+ {
700
+ name: 'hooks_git_churn',
701
+ description: 'Analyze git churn to find hot spots',
702
+ inputSchema: {
703
+ type: 'object',
704
+ properties: {
705
+ days: { type: 'number', description: 'Number of days to analyze', default: 30 },
706
+ top: { type: 'number', description: 'Top N files', default: 10 }
707
+ },
708
+ required: []
709
+ }
710
+ },
711
+ {
712
+ name: 'hooks_route_enhanced',
713
+ description: 'Enhanced routing using AST complexity, coverage, and diff analysis signals',
714
+ inputSchema: {
715
+ type: 'object',
716
+ properties: {
717
+ task: { type: 'string', description: 'Task description' },
718
+ file: { type: 'string', description: 'File context' }
719
+ },
720
+ required: ['task']
721
+ }
722
+ },
723
+ {
724
+ name: 'hooks_attention_info',
725
+ description: 'Get available attention mechanisms and their configurations',
726
+ inputSchema: {
727
+ type: 'object',
728
+ properties: {},
729
+ required: []
730
+ }
731
+ },
732
+ {
733
+ name: 'hooks_gnn_info',
734
+ description: 'Get GNN layer capabilities and configuration',
735
+ inputSchema: {
736
+ type: 'object',
737
+ properties: {},
738
+ required: []
739
+ }
740
+ },
741
+ // Learning Engine Tools (v2.1)
742
+ {
743
+ name: 'hooks_learning_config',
744
+ description: 'Configure learning algorithms for different tasks. Supports 9 algorithms: q-learning, sarsa, double-q, actor-critic, ppo, decision-transformer, monte-carlo, td-lambda, dqn',
745
+ inputSchema: {
746
+ type: 'object',
747
+ properties: {
748
+ task: {
749
+ type: 'string',
750
+ description: 'Task type: agent-routing, error-avoidance, confidence-scoring, trajectory-learning, context-ranking, memory-recall',
751
+ enum: ['agent-routing', 'error-avoidance', 'confidence-scoring', 'trajectory-learning', 'context-ranking', 'memory-recall']
752
+ },
753
+ algorithm: {
754
+ type: 'string',
755
+ description: 'Learning algorithm',
756
+ enum: ['q-learning', 'sarsa', 'double-q', 'actor-critic', 'ppo', 'decision-transformer', 'monte-carlo', 'td-lambda', 'dqn']
757
+ },
758
+ learningRate: { type: 'number', description: 'Learning rate (0.0-1.0)' },
759
+ discountFactor: { type: 'number', description: 'Discount factor gamma (0.0-1.0)' },
760
+ epsilon: { type: 'number', description: 'Exploration rate (0.0-1.0)' }
761
+ },
762
+ required: []
763
+ }
764
+ },
765
+ {
766
+ name: 'hooks_learning_stats',
767
+ description: 'Get learning algorithm statistics and performance metrics',
768
+ inputSchema: {
769
+ type: 'object',
770
+ properties: {},
771
+ required: []
772
+ }
773
+ },
774
+ {
775
+ name: 'hooks_learning_update',
776
+ description: 'Record a learning experience for a specific task',
777
+ inputSchema: {
778
+ type: 'object',
779
+ properties: {
780
+ task: { type: 'string', description: 'Task type' },
781
+ state: { type: 'string', description: 'Current state' },
782
+ action: { type: 'string', description: 'Action taken' },
783
+ reward: { type: 'number', description: 'Reward received (-1 to 1)' },
784
+ nextState: { type: 'string', description: 'Next state (optional)' },
785
+ done: { type: 'boolean', description: 'Episode is done' }
786
+ },
787
+ required: ['task', 'state', 'action', 'reward']
788
+ }
789
+ },
790
+ {
791
+ name: 'hooks_learn',
792
+ description: 'Combined learning action: record experience and get best action recommendation',
793
+ inputSchema: {
794
+ type: 'object',
795
+ properties: {
796
+ state: { type: 'string', description: 'Current state' },
797
+ action: { type: 'string', description: 'Action taken (optional)' },
798
+ reward: { type: 'number', description: 'Reward (-1 to 1, optional)' },
799
+ actions: { type: 'array', items: { type: 'string' }, description: 'Available actions for recommendation' },
800
+ task: { type: 'string', description: 'Task type', default: 'agent-routing' }
801
+ },
802
+ required: ['state']
803
+ }
804
+ },
805
+ {
806
+ name: 'hooks_algorithms_list',
807
+ description: 'List all available learning algorithms with descriptions',
808
+ inputSchema: {
809
+ type: 'object',
810
+ properties: {},
811
+ required: []
812
+ }
813
+ },
814
+ // TensorCompress Tools
815
+ {
816
+ name: 'hooks_compress',
817
+ description: 'Compress pattern storage using TensorCompress. Provides up to 10x memory savings.',
818
+ inputSchema: {
819
+ type: 'object',
820
+ properties: {
821
+ force: { type: 'boolean', description: 'Force recompression of all patterns' }
822
+ },
823
+ required: []
824
+ }
825
+ },
826
+ {
827
+ name: 'hooks_compress_stats',
828
+ description: 'Get TensorCompress statistics: memory savings, compression levels, tensor counts',
829
+ inputSchema: {
830
+ type: 'object',
831
+ properties: {},
832
+ required: []
833
+ }
834
+ },
835
+ {
836
+ name: 'hooks_compress_store',
837
+ description: 'Store an embedding with adaptive compression',
838
+ inputSchema: {
839
+ type: 'object',
840
+ properties: {
841
+ key: { type: 'string', description: 'Storage key' },
842
+ vector: { type: 'array', items: { type: 'number' }, description: 'Vector to store' },
843
+ level: { type: 'string', description: 'Compression level', enum: ['none', 'half', 'pq8', 'pq4', 'binary'] }
844
+ },
845
+ required: ['key', 'vector']
846
+ }
847
+ },
848
+ {
849
+ name: 'hooks_compress_get',
850
+ description: 'Retrieve a compressed embedding',
851
+ inputSchema: {
852
+ type: 'object',
853
+ properties: {
854
+ key: { type: 'string', description: 'Storage key' }
855
+ },
856
+ required: ['key']
857
+ }
568
858
  }
569
859
  ];
570
860
 
@@ -1168,6 +1458,410 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
1168
1458
  };
1169
1459
  }
1170
1460
 
1461
+ // ============================================
1462
+ // NEW CAPABILITY TOOL HANDLERS
1463
+ // ============================================
1464
+
1465
+ case 'hooks_ast_analyze': {
1466
+ try {
1467
+ const output = execSync(`npx ruvector hooks ast-analyze "${args.file}" --json`, { encoding: 'utf-8', timeout: 30000 });
1468
+ return { content: [{ type: 'text', text: output }] };
1469
+ } catch (e) {
1470
+ return { content: [{ type: 'text', text: JSON.stringify({ success: false, error: e.message }, null, 2) }] };
1471
+ }
1472
+ }
1473
+
1474
+ case 'hooks_ast_complexity': {
1475
+ try {
1476
+ const filesArg = args.files.map(f => `"${f}"`).join(' ');
1477
+ const output = execSync(`npx ruvector hooks ast-complexity ${filesArg} --threshold ${args.threshold || 10}`, { encoding: 'utf-8', timeout: 60000 });
1478
+ return { content: [{ type: 'text', text: output }] };
1479
+ } catch (e) {
1480
+ return { content: [{ type: 'text', text: JSON.stringify({ success: false, error: e.message }, null, 2) }] };
1481
+ }
1482
+ }
1483
+
1484
+ case 'hooks_diff_analyze': {
1485
+ try {
1486
+ const cmd = args.commit ? `npx ruvector hooks diff-analyze "${args.commit}" --json` : 'npx ruvector hooks diff-analyze --json';
1487
+ const output = execSync(cmd, { encoding: 'utf-8', timeout: 60000 });
1488
+ return { content: [{ type: 'text', text: output }] };
1489
+ } catch (e) {
1490
+ return { content: [{ type: 'text', text: JSON.stringify({ success: false, error: e.message }, null, 2) }] };
1491
+ }
1492
+ }
1493
+
1494
+ case 'hooks_diff_classify': {
1495
+ try {
1496
+ const cmd = args.commit ? `npx ruvector hooks diff-classify "${args.commit}"` : 'npx ruvector hooks diff-classify';
1497
+ const output = execSync(cmd, { encoding: 'utf-8', timeout: 30000 });
1498
+ return { content: [{ type: 'text', text: output }] };
1499
+ } catch (e) {
1500
+ return { content: [{ type: 'text', text: JSON.stringify({ success: false, error: e.message }, null, 2) }] };
1501
+ }
1502
+ }
1503
+
1504
+ case 'hooks_diff_similar': {
1505
+ try {
1506
+ const output = execSync(`npx ruvector hooks diff-similar -k ${args.top_k || 5} --commits ${args.commits || 50}`, { encoding: 'utf-8', timeout: 120000 });
1507
+ return { content: [{ type: 'text', text: output }] };
1508
+ } catch (e) {
1509
+ return { content: [{ type: 'text', text: JSON.stringify({ success: false, error: e.message }, null, 2) }] };
1510
+ }
1511
+ }
1512
+
1513
+ case 'hooks_coverage_route': {
1514
+ try {
1515
+ const output = execSync(`npx ruvector hooks coverage-route "${args.file}"`, { encoding: 'utf-8', timeout: 15000 });
1516
+ return { content: [{ type: 'text', text: output }] };
1517
+ } catch (e) {
1518
+ return { content: [{ type: 'text', text: JSON.stringify({ success: false, error: e.message }, null, 2) }] };
1519
+ }
1520
+ }
1521
+
1522
+ case 'hooks_coverage_suggest': {
1523
+ try {
1524
+ const filesArg = args.files.map(f => `"${f}"`).join(' ');
1525
+ const output = execSync(`npx ruvector hooks coverage-suggest ${filesArg}`, { encoding: 'utf-8', timeout: 30000 });
1526
+ return { content: [{ type: 'text', text: output }] };
1527
+ } catch (e) {
1528
+ return { content: [{ type: 'text', text: JSON.stringify({ success: false, error: e.message }, null, 2) }] };
1529
+ }
1530
+ }
1531
+
1532
+ case 'hooks_graph_mincut': {
1533
+ try {
1534
+ const filesArg = args.files.map(f => `"${f}"`).join(' ');
1535
+ const output = execSync(`npx ruvector hooks graph-mincut ${filesArg}`, { encoding: 'utf-8', timeout: 60000 });
1536
+ return { content: [{ type: 'text', text: output }] };
1537
+ } catch (e) {
1538
+ return { content: [{ type: 'text', text: JSON.stringify({ success: false, error: e.message }, null, 2) }] };
1539
+ }
1540
+ }
1541
+
1542
+ case 'hooks_graph_cluster': {
1543
+ try {
1544
+ const filesArg = args.files.map(f => `"${f}"`).join(' ');
1545
+ const method = args.method || 'louvain';
1546
+ const clusters = args.clusters || 3;
1547
+ const output = execSync(`npx ruvector hooks graph-cluster ${filesArg} --method ${method} --clusters ${clusters}`, { encoding: 'utf-8', timeout: 60000 });
1548
+ return { content: [{ type: 'text', text: output }] };
1549
+ } catch (e) {
1550
+ return { content: [{ type: 'text', text: JSON.stringify({ success: false, error: e.message }, null, 2) }] };
1551
+ }
1552
+ }
1553
+
1554
+ case 'hooks_security_scan': {
1555
+ try {
1556
+ const filesArg = args.files.map(f => `"${f}"`).join(' ');
1557
+ const output = execSync(`npx ruvector hooks security-scan ${filesArg}`, { encoding: 'utf-8', timeout: 120000 });
1558
+ return { content: [{ type: 'text', text: output }] };
1559
+ } catch (e) {
1560
+ return { content: [{ type: 'text', text: JSON.stringify({ success: false, error: e.message }, null, 2) }] };
1561
+ }
1562
+ }
1563
+
1564
+ case 'hooks_rag_context': {
1565
+ try {
1566
+ let cmd = `npx ruvector hooks rag-context "${args.query}" -k ${args.top_k || 5}`;
1567
+ if (args.rerank) cmd += ' --rerank';
1568
+ const output = execSync(cmd, { encoding: 'utf-8', timeout: 30000 });
1569
+ return { content: [{ type: 'text', text: output }] };
1570
+ } catch (e) {
1571
+ return { content: [{ type: 'text', text: JSON.stringify({ success: false, error: e.message }, null, 2) }] };
1572
+ }
1573
+ }
1574
+
1575
+ case 'hooks_git_churn': {
1576
+ try {
1577
+ const output = execSync(`npx ruvector hooks git-churn --days ${args.days || 30} --top ${args.top || 10}`, { encoding: 'utf-8', timeout: 30000 });
1578
+ return { content: [{ type: 'text', text: output }] };
1579
+ } catch (e) {
1580
+ return { content: [{ type: 'text', text: JSON.stringify({ success: false, error: e.message }, null, 2) }] };
1581
+ }
1582
+ }
1583
+
1584
+ case 'hooks_route_enhanced': {
1585
+ try {
1586
+ let cmd = `npx ruvector hooks route-enhanced "${args.task}"`;
1587
+ if (args.file) cmd += ` --file "${args.file}"`;
1588
+ const output = execSync(cmd, { encoding: 'utf-8', timeout: 30000 });
1589
+ return { content: [{ type: 'text', text: output }] };
1590
+ } catch (e) {
1591
+ return { content: [{ type: 'text', text: JSON.stringify({ success: false, error: e.message }, null, 2) }] };
1592
+ }
1593
+ }
1594
+
1595
+ case 'hooks_attention_info': {
1596
+ // Return info about available attention mechanisms
1597
+ let attentionInfo = { available: false, mechanisms: [] };
1598
+ try {
1599
+ const attention = require('@ruvector/attention');
1600
+ attentionInfo = {
1601
+ available: true,
1602
+ version: attention.version || '1.0.0',
1603
+ mechanisms: [
1604
+ { name: 'DotProductAttention', description: 'Basic scaled dot-product attention' },
1605
+ { name: 'MultiHeadAttention', description: 'Multi-head self-attention with parallel heads' },
1606
+ { name: 'FlashAttention', description: 'Memory-efficient attention with tiling' },
1607
+ { name: 'HyperbolicAttention', description: 'Attention in Poincaré ball hyperbolic space' },
1608
+ { name: 'LinearAttention', description: 'O(n) linear complexity attention' },
1609
+ { name: 'MoEAttention', description: 'Mixture-of-Experts sparse attention' },
1610
+ { name: 'GraphRoPeAttention', description: 'Rotary position embeddings for graphs' },
1611
+ { name: 'DualSpaceAttention', description: 'Euclidean + Hyperbolic hybrid' },
1612
+ { name: 'LocalGlobalAttention', description: 'Sliding window + global tokens' }
1613
+ ],
1614
+ hyperbolic: { expMap: true, logMap: true, mobiusAddition: true, poincareDistance: true }
1615
+ };
1616
+ } catch (e) {
1617
+ attentionInfo = { available: false, error: 'Attention package not installed' };
1618
+ }
1619
+ return { content: [{ type: 'text', text: JSON.stringify({ success: true, ...attentionInfo }, null, 2) }] };
1620
+ }
1621
+
1622
+ case 'hooks_gnn_info': {
1623
+ // Return info about GNN capabilities
1624
+ let gnnInfo = { available: false, layers: [] };
1625
+ try {
1626
+ const gnn = require('@ruvector/gnn');
1627
+ gnnInfo = {
1628
+ available: true,
1629
+ version: gnn.version || '1.0.0',
1630
+ layers: [
1631
+ { name: 'RuvectorLayer', description: 'Differentiable vector search layer' },
1632
+ { name: 'TensorCompress', description: 'Tensor compression for embeddings' }
1633
+ ],
1634
+ features: [
1635
+ 'differentiableSearch - Gradient-based vector search',
1636
+ 'hierarchicalForward - Multi-scale graph processing',
1637
+ 'getCompressionLevel - Adaptive compression'
1638
+ ]
1639
+ };
1640
+ } catch (e) {
1641
+ gnnInfo = { available: false, error: 'GNN package not installed' };
1642
+ }
1643
+ return { content: [{ type: 'text', text: JSON.stringify({ success: true, ...gnnInfo }, null, 2) }] };
1644
+ }
1645
+
1646
+ // Learning Engine Handlers (v2.1)
1647
+ case 'hooks_learning_config': {
1648
+ let LearningEngine;
1649
+ try {
1650
+ LearningEngine = require('../dist/core/learning-engine').default;
1651
+ } catch (e) {
1652
+ return { content: [{ type: 'text', text: JSON.stringify({ success: false, error: 'LearningEngine not available' }) }] };
1653
+ }
1654
+
1655
+ const engine = new LearningEngine();
1656
+ if (intel.learning) engine.import(intel.learning);
1657
+
1658
+ if (args.task && args.algorithm) {
1659
+ const config = {};
1660
+ if (args.algorithm) config.algorithm = args.algorithm;
1661
+ if (args.learningRate !== undefined) config.learningRate = args.learningRate;
1662
+ if (args.discountFactor !== undefined) config.discountFactor = args.discountFactor;
1663
+ if (args.epsilon !== undefined) config.epsilon = args.epsilon;
1664
+ engine.configure(args.task, config);
1665
+ intel.learning = engine.export();
1666
+ intel.save();
1667
+ }
1668
+
1669
+ const tasks = ['agent-routing', 'error-avoidance', 'confidence-scoring', 'trajectory-learning', 'context-ranking', 'memory-recall'];
1670
+ const configs = {};
1671
+ for (const task of tasks) {
1672
+ configs[task] = engine.getConfig(task);
1673
+ }
1674
+ return { content: [{ type: 'text', text: JSON.stringify({ success: true, configs }, null, 2) }] };
1675
+ }
1676
+
1677
+ case 'hooks_learning_stats': {
1678
+ let LearningEngine;
1679
+ try {
1680
+ LearningEngine = require('../dist/core/learning-engine').default;
1681
+ } catch (e) {
1682
+ return { content: [{ type: 'text', text: JSON.stringify({ success: false, error: 'LearningEngine not available' }) }] };
1683
+ }
1684
+
1685
+ const engine = new LearningEngine();
1686
+ if (intel.learning) engine.import(intel.learning);
1687
+
1688
+ const summary = engine.getStatsSummary();
1689
+ return { content: [{ type: 'text', text: JSON.stringify({ success: true, ...summary }, null, 2) }] };
1690
+ }
1691
+
1692
+ case 'hooks_learning_update': {
1693
+ let LearningEngine;
1694
+ try {
1695
+ LearningEngine = require('../dist/core/learning-engine').default;
1696
+ } catch (e) {
1697
+ return { content: [{ type: 'text', text: JSON.stringify({ success: false, error: 'LearningEngine not available' }) }] };
1698
+ }
1699
+
1700
+ const engine = new LearningEngine();
1701
+ if (intel.learning) engine.import(intel.learning);
1702
+
1703
+ const experience = {
1704
+ state: args.state,
1705
+ action: args.action,
1706
+ reward: args.reward,
1707
+ nextState: args.nextState || args.state,
1708
+ done: args.done || false,
1709
+ timestamp: Date.now()
1710
+ };
1711
+
1712
+ const delta = engine.update(args.task, experience);
1713
+ intel.learning = engine.export();
1714
+ intel.save();
1715
+
1716
+ return { content: [{ type: 'text', text: JSON.stringify({
1717
+ success: true,
1718
+ task: args.task,
1719
+ experience,
1720
+ delta,
1721
+ algorithm: engine.getConfig(args.task).algorithm
1722
+ }, null, 2) }] };
1723
+ }
1724
+
1725
+ case 'hooks_learn': {
1726
+ let LearningEngine;
1727
+ try {
1728
+ LearningEngine = require('../dist/core/learning-engine').default;
1729
+ } catch (e) {
1730
+ return { content: [{ type: 'text', text: JSON.stringify({ success: false, error: 'LearningEngine not available' }) }] };
1731
+ }
1732
+
1733
+ const engine = new LearningEngine();
1734
+ if (intel.learning) engine.import(intel.learning);
1735
+
1736
+ const task = args.task || 'agent-routing';
1737
+ let result = { success: true };
1738
+
1739
+ if (args.action && args.reward !== undefined) {
1740
+ const experience = {
1741
+ state: args.state,
1742
+ action: args.action,
1743
+ reward: args.reward,
1744
+ nextState: args.state,
1745
+ done: true,
1746
+ timestamp: Date.now()
1747
+ };
1748
+ const delta = engine.update(task, experience);
1749
+ result.recorded = { experience, delta, algorithm: engine.getConfig(task).algorithm };
1750
+ }
1751
+
1752
+ if (args.actions && args.actions.length > 0) {
1753
+ const best = engine.getBestAction(task, args.state, args.actions);
1754
+ result.recommendation = best;
1755
+ }
1756
+
1757
+ intel.learning = engine.export();
1758
+ intel.save();
1759
+
1760
+ return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
1761
+ }
1762
+
1763
+ case 'hooks_algorithms_list': {
1764
+ let LearningEngine;
1765
+ try {
1766
+ LearningEngine = require('../dist/core/learning-engine').default;
1767
+ } catch (e) {
1768
+ return { content: [{ type: 'text', text: JSON.stringify({ success: false, error: 'LearningEngine not available' }) }] };
1769
+ }
1770
+
1771
+ const algorithms = LearningEngine.getAlgorithms();
1772
+ return { content: [{ type: 'text', text: JSON.stringify({
1773
+ success: true,
1774
+ algorithms: algorithms.map(a => ({
1775
+ name: a.algorithm,
1776
+ description: a.description,
1777
+ bestFor: a.bestFor
1778
+ }))
1779
+ }, null, 2) }] };
1780
+ }
1781
+
1782
+ // TensorCompress Handlers
1783
+ case 'hooks_compress': {
1784
+ let TensorCompress;
1785
+ try {
1786
+ TensorCompress = require('../dist/core/tensor-compress').default;
1787
+ } catch (e) {
1788
+ return { content: [{ type: 'text', text: JSON.stringify({ success: false, error: 'TensorCompress not available' }) }] };
1789
+ }
1790
+
1791
+ const compress = new TensorCompress({ autoCompress: false });
1792
+ if (intel.compressedPatterns) compress.import(intel.compressedPatterns);
1793
+
1794
+ const stats = compress.recompressAll();
1795
+ intel.compressedPatterns = compress.export();
1796
+ intel.save();
1797
+
1798
+ return { content: [{ type: 'text', text: JSON.stringify({ success: true, message: 'Compression complete', ...stats }, null, 2) }] };
1799
+ }
1800
+
1801
+ case 'hooks_compress_stats': {
1802
+ let TensorCompress;
1803
+ try {
1804
+ TensorCompress = require('../dist/core/tensor-compress').default;
1805
+ } catch (e) {
1806
+ return { content: [{ type: 'text', text: JSON.stringify({ success: false, error: 'TensorCompress not available' }) }] };
1807
+ }
1808
+
1809
+ const compress = new TensorCompress({ autoCompress: false });
1810
+ if (intel.compressedPatterns) compress.import(intel.compressedPatterns);
1811
+
1812
+ const stats = compress.getStats();
1813
+ return { content: [{ type: 'text', text: JSON.stringify({ success: true, ...stats }, null, 2) }] };
1814
+ }
1815
+
1816
+ case 'hooks_compress_store': {
1817
+ let TensorCompress;
1818
+ try {
1819
+ TensorCompress = require('../dist/core/tensor-compress').default;
1820
+ } catch (e) {
1821
+ return { content: [{ type: 'text', text: JSON.stringify({ success: false, error: 'TensorCompress not available' }) }] };
1822
+ }
1823
+
1824
+ const compress = new TensorCompress({ autoCompress: false });
1825
+ if (intel.compressedPatterns) compress.import(intel.compressedPatterns);
1826
+
1827
+ compress.store(args.key, args.vector, args.level);
1828
+ intel.compressedPatterns = compress.export();
1829
+ intel.save();
1830
+
1831
+ const stats = compress.getStats();
1832
+ return { content: [{ type: 'text', text: JSON.stringify({
1833
+ success: true,
1834
+ key: args.key,
1835
+ level: args.level || 'auto',
1836
+ originalDim: args.vector.length,
1837
+ totalTensors: stats.totalTensors
1838
+ }, null, 2) }] };
1839
+ }
1840
+
1841
+ case 'hooks_compress_get': {
1842
+ let TensorCompress;
1843
+ try {
1844
+ TensorCompress = require('../dist/core/tensor-compress').default;
1845
+ } catch (e) {
1846
+ return { content: [{ type: 'text', text: JSON.stringify({ success: false, error: 'TensorCompress not available' }) }] };
1847
+ }
1848
+
1849
+ const compress = new TensorCompress({ autoCompress: false });
1850
+ if (intel.compressedPatterns) compress.import(intel.compressedPatterns);
1851
+
1852
+ const vector = compress.get(args.key);
1853
+ if (!vector) {
1854
+ return { content: [{ type: 'text', text: JSON.stringify({ success: false, error: 'Key not found' }) }] };
1855
+ }
1856
+
1857
+ return { content: [{ type: 'text', text: JSON.stringify({
1858
+ success: true,
1859
+ key: args.key,
1860
+ vector: Array.from(vector),
1861
+ dimension: vector.length
1862
+ }, null, 2) }] };
1863
+ }
1864
+
1171
1865
  default:
1172
1866
  return {
1173
1867
  content: [{