ruvector 0.1.65 → 0.1.67
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/.ruvector/intelligence.json +133 -0
- package/README.md +169 -20
- package/bin/cli.js +450 -2
- package/bin/mcp-server.js +337 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +8 -1
- package/dist/core/learning-engine.d.ts +160 -0
- package/dist/core/learning-engine.d.ts.map +1 -0
- package/dist/core/learning-engine.js +589 -0
- package/dist/core/tensor-compress.d.ts +134 -0
- package/dist/core/tensor-compress.d.ts.map +1 -0
- package/dist/core/tensor-compress.js +432 -0
- package/package.json +1 -1
- package/ruvector.db +0 -0
package/bin/mcp-server.js
CHANGED
|
@@ -737,6 +737,124 @@ const TOOLS = [
|
|
|
737
737
|
properties: {},
|
|
738
738
|
required: []
|
|
739
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
|
+
}
|
|
740
858
|
}
|
|
741
859
|
];
|
|
742
860
|
|
|
@@ -1525,6 +1643,225 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
1525
1643
|
return { content: [{ type: 'text', text: JSON.stringify({ success: true, ...gnnInfo }, null, 2) }] };
|
|
1526
1644
|
}
|
|
1527
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
|
+
|
|
1528
1865
|
default:
|
|
1529
1866
|
return {
|
|
1530
1867
|
content: [{
|
package/dist/core/index.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ export * from './ast-parser';
|
|
|
19
19
|
export * from './diff-embeddings';
|
|
20
20
|
export * from './coverage-router';
|
|
21
21
|
export * from './graph-algorithms';
|
|
22
|
+
export * from './tensor-compress';
|
|
23
|
+
export * from './learning-engine';
|
|
22
24
|
export { default as gnnWrapper } from './gnn-wrapper';
|
|
23
25
|
export { default as attentionFallbacks } from './attention-fallbacks';
|
|
24
26
|
export { default as agentdbFast } from './agentdb-fast';
|
|
@@ -32,4 +34,6 @@ export { default as CodeGraph } from './graph-wrapper';
|
|
|
32
34
|
export { default as RuvectorCluster } from './cluster-wrapper';
|
|
33
35
|
export { default as CodeParser } from './ast-parser';
|
|
34
36
|
export { CodeParser as ASTParser } from './ast-parser';
|
|
37
|
+
export { default as TensorCompress } from './tensor-compress';
|
|
38
|
+
export { default as LearningEngine } from './learning-engine';
|
|
35
39
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBA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AO,IAAI,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AAGrD,OAAO,EAAE,UAAU,IAAI,SAAS,EAAE,MAAM,cAAc,CAAC;AAGvD,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/core/index.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
23
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.ASTParser = exports.CodeParser = exports.RuvectorCluster = exports.CodeGraph = exports.SemanticRouter = exports.ExtendedWorkerPool = exports.ParallelIntelligence = exports.OnnxEmbedder = exports.IntelligenceEngine = exports.Sona = exports.agentdbFast = exports.attentionFallbacks = exports.gnnWrapper = void 0;
|
|
26
|
+
exports.LearningEngine = exports.TensorCompress = exports.ASTParser = exports.CodeParser = exports.RuvectorCluster = exports.CodeGraph = exports.SemanticRouter = exports.ExtendedWorkerPool = exports.ParallelIntelligence = exports.OnnxEmbedder = exports.IntelligenceEngine = exports.Sona = exports.agentdbFast = exports.attentionFallbacks = exports.gnnWrapper = void 0;
|
|
27
27
|
__exportStar(require("./gnn-wrapper"), exports);
|
|
28
28
|
__exportStar(require("./attention-fallbacks"), exports);
|
|
29
29
|
__exportStar(require("./agentdb-fast"), exports);
|
|
@@ -39,6 +39,8 @@ __exportStar(require("./ast-parser"), exports);
|
|
|
39
39
|
__exportStar(require("./diff-embeddings"), exports);
|
|
40
40
|
__exportStar(require("./coverage-router"), exports);
|
|
41
41
|
__exportStar(require("./graph-algorithms"), exports);
|
|
42
|
+
__exportStar(require("./tensor-compress"), exports);
|
|
43
|
+
__exportStar(require("./learning-engine"), exports);
|
|
42
44
|
// Re-export default objects for convenience
|
|
43
45
|
var gnn_wrapper_1 = require("./gnn-wrapper");
|
|
44
46
|
Object.defineProperty(exports, "gnnWrapper", { enumerable: true, get: function () { return __importDefault(gnn_wrapper_1).default; } });
|
|
@@ -67,3 +69,8 @@ Object.defineProperty(exports, "CodeParser", { enumerable: true, get: function (
|
|
|
67
69
|
// Alias for backward compatibility
|
|
68
70
|
var ast_parser_2 = require("./ast-parser");
|
|
69
71
|
Object.defineProperty(exports, "ASTParser", { enumerable: true, get: function () { return ast_parser_2.CodeParser; } });
|
|
72
|
+
// New v2.1 modules
|
|
73
|
+
var tensor_compress_1 = require("./tensor-compress");
|
|
74
|
+
Object.defineProperty(exports, "TensorCompress", { enumerable: true, get: function () { return __importDefault(tensor_compress_1).default; } });
|
|
75
|
+
var learning_engine_1 = require("./learning-engine");
|
|
76
|
+
Object.defineProperty(exports, "LearningEngine", { enumerable: true, get: function () { return __importDefault(learning_engine_1).default; } });
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-Algorithm Learning Engine
|
|
3
|
+
* Supports 9 RL algorithms for intelligent hooks optimization
|
|
4
|
+
*/
|
|
5
|
+
export type LearningAlgorithm = 'q-learning' | 'sarsa' | 'double-q' | 'actor-critic' | 'ppo' | 'decision-transformer' | 'monte-carlo' | 'td-lambda' | 'dqn';
|
|
6
|
+
export type TaskType = 'agent-routing' | 'error-avoidance' | 'confidence-scoring' | 'trajectory-learning' | 'context-ranking' | 'memory-recall';
|
|
7
|
+
export interface LearningConfig {
|
|
8
|
+
algorithm: LearningAlgorithm;
|
|
9
|
+
learningRate: number;
|
|
10
|
+
discountFactor: number;
|
|
11
|
+
epsilon: number;
|
|
12
|
+
lambda?: number;
|
|
13
|
+
clipRange?: number;
|
|
14
|
+
entropyCoef?: number;
|
|
15
|
+
sequenceLength?: number;
|
|
16
|
+
}
|
|
17
|
+
export interface Experience {
|
|
18
|
+
state: string;
|
|
19
|
+
action: string;
|
|
20
|
+
reward: number;
|
|
21
|
+
nextState: string;
|
|
22
|
+
done: boolean;
|
|
23
|
+
timestamp?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface LearningTrajectory {
|
|
26
|
+
experiences: Experience[];
|
|
27
|
+
totalReward: number;
|
|
28
|
+
completed: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface AlgorithmStats {
|
|
31
|
+
algorithm: LearningAlgorithm;
|
|
32
|
+
updates: number;
|
|
33
|
+
avgReward: number;
|
|
34
|
+
convergenceScore: number;
|
|
35
|
+
lastUpdate: number;
|
|
36
|
+
}
|
|
37
|
+
export declare class LearningEngine {
|
|
38
|
+
private configs;
|
|
39
|
+
private qTables;
|
|
40
|
+
private qTables2;
|
|
41
|
+
private eligibilityTraces;
|
|
42
|
+
private actorWeights;
|
|
43
|
+
private criticValues;
|
|
44
|
+
private trajectories;
|
|
45
|
+
private stats;
|
|
46
|
+
private rewardHistory;
|
|
47
|
+
constructor();
|
|
48
|
+
/**
|
|
49
|
+
* Configure algorithm for a specific task type
|
|
50
|
+
*/
|
|
51
|
+
configure(task: TaskType, config: Partial<LearningConfig>): void;
|
|
52
|
+
/**
|
|
53
|
+
* Get current configuration for a task
|
|
54
|
+
*/
|
|
55
|
+
getConfig(task: TaskType): LearningConfig;
|
|
56
|
+
/**
|
|
57
|
+
* Update Q-value using the appropriate algorithm
|
|
58
|
+
*/
|
|
59
|
+
update(task: TaskType, experience: Experience): number;
|
|
60
|
+
/**
|
|
61
|
+
* Get best action for a state
|
|
62
|
+
*/
|
|
63
|
+
getBestAction(task: TaskType, state: string, actions: string[]): {
|
|
64
|
+
action: string;
|
|
65
|
+
confidence: number;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Get action probabilities (for Actor-Critic and PPO)
|
|
69
|
+
*/
|
|
70
|
+
getActionProbabilities(state: string, actions: string[]): Map<string, number>;
|
|
71
|
+
/**
|
|
72
|
+
* Standard Q-Learning: Q(s,a) += α * (r + γ * max_a' Q(s',a') - Q(s,a))
|
|
73
|
+
*/
|
|
74
|
+
private qLearningUpdate;
|
|
75
|
+
/**
|
|
76
|
+
* SARSA: On-policy, more conservative
|
|
77
|
+
* Q(s,a) += α * (r + γ * Q(s',a') - Q(s,a))
|
|
78
|
+
*/
|
|
79
|
+
private sarsaUpdate;
|
|
80
|
+
/**
|
|
81
|
+
* Double Q-Learning: Reduces overestimation bias
|
|
82
|
+
* Uses two Q-tables, randomly updates one using the other for target
|
|
83
|
+
*/
|
|
84
|
+
private doubleQUpdate;
|
|
85
|
+
/**
|
|
86
|
+
* Actor-Critic: Policy gradient with value baseline
|
|
87
|
+
*/
|
|
88
|
+
private actorCriticUpdate;
|
|
89
|
+
/**
|
|
90
|
+
* PPO: Clipped policy gradient for stable training
|
|
91
|
+
*/
|
|
92
|
+
private ppoUpdate;
|
|
93
|
+
/**
|
|
94
|
+
* TD(λ): Temporal difference with eligibility traces
|
|
95
|
+
*/
|
|
96
|
+
private tdLambdaUpdate;
|
|
97
|
+
/**
|
|
98
|
+
* Monte Carlo: Full episode learning
|
|
99
|
+
*/
|
|
100
|
+
private monteCarloUpdate;
|
|
101
|
+
/**
|
|
102
|
+
* Decision Transformer: Sequence modeling for trajectories
|
|
103
|
+
*/
|
|
104
|
+
private decisionTransformerUpdate;
|
|
105
|
+
/**
|
|
106
|
+
* DQN: Deep Q-Network (simplified without actual neural network)
|
|
107
|
+
* Uses experience replay and target network concepts
|
|
108
|
+
*/
|
|
109
|
+
private dqnUpdate;
|
|
110
|
+
private getQTable;
|
|
111
|
+
private getQTable2;
|
|
112
|
+
private getEligibilityTraces;
|
|
113
|
+
private softmaxConfidence;
|
|
114
|
+
private addToCurrentTrajectory;
|
|
115
|
+
private sampleFromReplay;
|
|
116
|
+
private updateStats;
|
|
117
|
+
/**
|
|
118
|
+
* Get statistics for all algorithms
|
|
119
|
+
*/
|
|
120
|
+
getStats(): Map<LearningAlgorithm, AlgorithmStats>;
|
|
121
|
+
/**
|
|
122
|
+
* Get statistics summary
|
|
123
|
+
*/
|
|
124
|
+
getStatsSummary(): {
|
|
125
|
+
bestAlgorithm: LearningAlgorithm;
|
|
126
|
+
totalUpdates: number;
|
|
127
|
+
avgReward: number;
|
|
128
|
+
algorithms: AlgorithmStats[];
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Export state for persistence
|
|
132
|
+
*/
|
|
133
|
+
export(): {
|
|
134
|
+
qTables: Record<string, Record<string, number>>;
|
|
135
|
+
qTables2: Record<string, Record<string, number>>;
|
|
136
|
+
criticValues: Record<string, number>;
|
|
137
|
+
trajectories: LearningTrajectory[];
|
|
138
|
+
stats: Record<string, AlgorithmStats>;
|
|
139
|
+
configs: Record<string, LearningConfig>;
|
|
140
|
+
rewardHistory: number[];
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Import state from persistence
|
|
144
|
+
*/
|
|
145
|
+
import(data: ReturnType<LearningEngine['export']>): void;
|
|
146
|
+
/**
|
|
147
|
+
* Clear all learning data
|
|
148
|
+
*/
|
|
149
|
+
clear(): void;
|
|
150
|
+
/**
|
|
151
|
+
* Get available algorithms
|
|
152
|
+
*/
|
|
153
|
+
static getAlgorithms(): {
|
|
154
|
+
algorithm: LearningAlgorithm;
|
|
155
|
+
description: string;
|
|
156
|
+
bestFor: string;
|
|
157
|
+
}[];
|
|
158
|
+
}
|
|
159
|
+
export default LearningEngine;
|
|
160
|
+
//# sourceMappingURL=learning-engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"learning-engine.d.ts","sourceRoot":"","sources":["../../src/core/learning-engine.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH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