ruvector 0.1.68 → 0.1.70
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 +1844 -16
- package/bin/cli.js +148 -8
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -2233,12 +2233,7 @@ class Intelligence {
|
|
|
2233
2233
|
}
|
|
2234
2234
|
|
|
2235
2235
|
load() {
|
|
2236
|
-
|
|
2237
|
-
if (fs.existsSync(this.intelPath)) {
|
|
2238
|
-
return JSON.parse(fs.readFileSync(this.intelPath, 'utf-8'));
|
|
2239
|
-
}
|
|
2240
|
-
} catch {}
|
|
2241
|
-
return {
|
|
2236
|
+
const defaults = {
|
|
2242
2237
|
patterns: {},
|
|
2243
2238
|
memories: [],
|
|
2244
2239
|
trajectories: [],
|
|
@@ -2248,6 +2243,25 @@ class Intelligence {
|
|
|
2248
2243
|
edges: [],
|
|
2249
2244
|
stats: { total_patterns: 0, total_memories: 0, total_trajectories: 0, total_errors: 0, session_count: 0, last_session: 0 }
|
|
2250
2245
|
};
|
|
2246
|
+
try {
|
|
2247
|
+
if (fs.existsSync(this.intelPath)) {
|
|
2248
|
+
const data = JSON.parse(fs.readFileSync(this.intelPath, 'utf-8'));
|
|
2249
|
+
// Merge with defaults to ensure all fields exist
|
|
2250
|
+
return {
|
|
2251
|
+
patterns: data.patterns || defaults.patterns,
|
|
2252
|
+
memories: data.memories || defaults.memories,
|
|
2253
|
+
trajectories: data.trajectories || defaults.trajectories,
|
|
2254
|
+
errors: data.errors || defaults.errors,
|
|
2255
|
+
file_sequences: data.file_sequences || defaults.file_sequences,
|
|
2256
|
+
agents: data.agents || defaults.agents,
|
|
2257
|
+
edges: data.edges || defaults.edges,
|
|
2258
|
+
stats: { ...defaults.stats, ...(data.stats || {}) },
|
|
2259
|
+
// Preserve learning data if present
|
|
2260
|
+
learning: data.learning || undefined
|
|
2261
|
+
};
|
|
2262
|
+
}
|
|
2263
|
+
} catch {}
|
|
2264
|
+
return defaults;
|
|
2251
2265
|
}
|
|
2252
2266
|
|
|
2253
2267
|
save() {
|
|
@@ -2374,11 +2388,14 @@ class Intelligence {
|
|
|
2374
2388
|
// Q-learning operations - enhanced with SONA trajectory tracking
|
|
2375
2389
|
getQ(state, action) {
|
|
2376
2390
|
const key = `${state}|${action}`;
|
|
2391
|
+
if (!this.data.patterns) this.data.patterns = {};
|
|
2377
2392
|
return this.data.patterns[key]?.q_value ?? 0;
|
|
2378
2393
|
}
|
|
2379
2394
|
|
|
2380
2395
|
updateQ(state, action, reward) {
|
|
2381
2396
|
const key = `${state}|${action}`;
|
|
2397
|
+
if (!this.data.patterns) this.data.patterns = {};
|
|
2398
|
+
if (!this.data.stats) this.data.stats = { total_patterns: 0, total_memories: 0, total_trajectories: 0, total_errors: 0, session_count: 0, last_session: 0 };
|
|
2382
2399
|
if (!this.data.patterns[key]) {
|
|
2383
2400
|
this.data.patterns[key] = { state, action, q_value: 0, visits: 0, last_update: 0 };
|
|
2384
2401
|
}
|
|
@@ -2398,6 +2415,8 @@ class Intelligence {
|
|
|
2398
2415
|
learn(state, action, outcome, reward) {
|
|
2399
2416
|
const id = `traj_${this.now()}`;
|
|
2400
2417
|
this.updateQ(state, action, reward);
|
|
2418
|
+
if (!this.data.trajectories) this.data.trajectories = [];
|
|
2419
|
+
if (!this.data.stats) this.data.stats = { total_patterns: 0, total_memories: 0, total_trajectories: 0, total_errors: 0, session_count: 0, last_session: 0 };
|
|
2401
2420
|
this.data.trajectories.push({ id, state, action, outcome, reward, timestamp: this.now() });
|
|
2402
2421
|
if (this.data.trajectories.length > 1000) this.data.trajectories.splice(0, 200);
|
|
2403
2422
|
this.data.stats.total_trajectories = this.data.trajectories.length;
|
|
@@ -2634,6 +2653,25 @@ class Intelligence {
|
|
|
2634
2653
|
// Ignore engine errors on session end
|
|
2635
2654
|
}
|
|
2636
2655
|
|
|
2656
|
+
// Auto-compress patterns if enabled (v2.1)
|
|
2657
|
+
try {
|
|
2658
|
+
if (process.env.RUVECTOR_AUTO_COMPRESS === 'true' || process.env.RUVECTOR_TENSOR_COMPRESS === 'true') {
|
|
2659
|
+
const TensorCompressClass = require('../dist/core/tensor-compress').default;
|
|
2660
|
+
if (TensorCompressClass && this.data.compressedPatterns) {
|
|
2661
|
+
const compress = new TensorCompressClass({ autoCompress: false });
|
|
2662
|
+
compress.import(this.data.compressedPatterns);
|
|
2663
|
+
const stats = compress.recompressAll();
|
|
2664
|
+
this.data.compressedPatterns = compress.export();
|
|
2665
|
+
// Only log if significant savings
|
|
2666
|
+
if (stats.savingsPercent > 10 && stats.totalTensors > 5) {
|
|
2667
|
+
// Silently compress, no console output to avoid hook noise
|
|
2668
|
+
}
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2671
|
+
} catch (e) {
|
|
2672
|
+
// Ignore compression errors on session end
|
|
2673
|
+
}
|
|
2674
|
+
|
|
2637
2675
|
// Save all data
|
|
2638
2676
|
try {
|
|
2639
2677
|
this.save();
|
|
@@ -2749,11 +2787,23 @@ hooksCmd.command('init')
|
|
|
2749
2787
|
// Environment variables for intelligence (unless --minimal or --no-env)
|
|
2750
2788
|
if (!opts.minimal && opts.env !== false) {
|
|
2751
2789
|
settings.env = settings.env || {};
|
|
2790
|
+
// Core intelligence settings
|
|
2752
2791
|
settings.env.RUVECTOR_INTELLIGENCE_ENABLED = settings.env.RUVECTOR_INTELLIGENCE_ENABLED || 'true';
|
|
2753
2792
|
settings.env.RUVECTOR_LEARNING_RATE = settings.env.RUVECTOR_LEARNING_RATE || '0.1';
|
|
2754
2793
|
settings.env.RUVECTOR_MEMORY_BACKEND = settings.env.RUVECTOR_MEMORY_BACKEND || 'rvlite';
|
|
2755
2794
|
settings.env.INTELLIGENCE_MODE = settings.env.INTELLIGENCE_MODE || 'treatment';
|
|
2756
|
-
|
|
2795
|
+
// v2.0 capabilities
|
|
2796
|
+
settings.env.RUVECTOR_AST_ENABLED = settings.env.RUVECTOR_AST_ENABLED || 'true';
|
|
2797
|
+
settings.env.RUVECTOR_DIFF_EMBEDDINGS = settings.env.RUVECTOR_DIFF_EMBEDDINGS || 'true';
|
|
2798
|
+
settings.env.RUVECTOR_COVERAGE_ROUTING = settings.env.RUVECTOR_COVERAGE_ROUTING || 'true';
|
|
2799
|
+
settings.env.RUVECTOR_GRAPH_ALGORITHMS = settings.env.RUVECTOR_GRAPH_ALGORITHMS || 'true';
|
|
2800
|
+
settings.env.RUVECTOR_SECURITY_SCAN = settings.env.RUVECTOR_SECURITY_SCAN || 'true';
|
|
2801
|
+
// v2.1 learning & compression
|
|
2802
|
+
settings.env.RUVECTOR_MULTI_ALGORITHM = settings.env.RUVECTOR_MULTI_ALGORITHM || 'true';
|
|
2803
|
+
settings.env.RUVECTOR_DEFAULT_ALGORITHM = settings.env.RUVECTOR_DEFAULT_ALGORITHM || 'double-q';
|
|
2804
|
+
settings.env.RUVECTOR_TENSOR_COMPRESS = settings.env.RUVECTOR_TENSOR_COMPRESS || 'true';
|
|
2805
|
+
settings.env.RUVECTOR_AUTO_COMPRESS = settings.env.RUVECTOR_AUTO_COMPRESS || 'true';
|
|
2806
|
+
console.log(chalk.blue(' ✓ Environment variables configured (v2.1 with multi-algorithm learning)'));
|
|
2757
2807
|
}
|
|
2758
2808
|
|
|
2759
2809
|
// Permissions based on detected project type (unless --minimal or --no-permissions)
|
|
@@ -5107,10 +5157,98 @@ hooksCmd.command('pretrain')
|
|
|
5107
5157
|
console.log(chalk.yellow(` ⚠ Graph analysis skipped: ${e.message}`));
|
|
5108
5158
|
}
|
|
5109
5159
|
|
|
5160
|
+
// Phase 10: Initialize multi-algorithm learning engine
|
|
5161
|
+
console.log(chalk.yellow('\n🎯 Phase 10: Initializing multi-algorithm learning engine...\n'));
|
|
5162
|
+
|
|
5163
|
+
try {
|
|
5164
|
+
if (loadLearningModules() && LearningEngineClass) {
|
|
5165
|
+
const engine = new LearningEngineClass();
|
|
5166
|
+
|
|
5167
|
+
// Configure optimal algorithms for each task type based on repo analysis
|
|
5168
|
+
engine.configure('agent-routing', { algorithm: 'double-q', learningRate: 0.1, epsilon: 0.1 });
|
|
5169
|
+
engine.configure('error-avoidance', { algorithm: 'sarsa', learningRate: 0.05, epsilon: 0.05 });
|
|
5170
|
+
engine.configure('confidence-scoring', { algorithm: 'actor-critic', learningRate: 0.01 });
|
|
5171
|
+
engine.configure('trajectory-learning', { algorithm: 'decision-transformer', sequenceLength: 20 });
|
|
5172
|
+
engine.configure('context-ranking', { algorithm: 'ppo', clipRange: 0.2 });
|
|
5173
|
+
engine.configure('memory-recall', { algorithm: 'td-lambda', lambda: 0.8 });
|
|
5174
|
+
|
|
5175
|
+
// Bootstrap with initial experiences from file patterns
|
|
5176
|
+
let bootstrapCount = 0;
|
|
5177
|
+
for (const [state, actions] of Object.entries(intel.data.patterns || {})) {
|
|
5178
|
+
for (const [action, value] of Object.entries(actions)) {
|
|
5179
|
+
if (value > 0.3) { // Only strong patterns
|
|
5180
|
+
engine.update('agent-routing', {
|
|
5181
|
+
state,
|
|
5182
|
+
action,
|
|
5183
|
+
reward: value,
|
|
5184
|
+
nextState: state,
|
|
5185
|
+
done: true
|
|
5186
|
+
});
|
|
5187
|
+
bootstrapCount++;
|
|
5188
|
+
}
|
|
5189
|
+
}
|
|
5190
|
+
}
|
|
5191
|
+
|
|
5192
|
+
intel.data.learning = engine.export();
|
|
5193
|
+
stats.learningBootstrap = bootstrapCount;
|
|
5194
|
+
console.log(chalk.green(` ✓ Configured 6 task-specific algorithms`));
|
|
5195
|
+
console.log(chalk.green(` ✓ Bootstrapped with ${bootstrapCount} initial experiences`));
|
|
5196
|
+
console.log(chalk.dim(' Algorithms: double-q, sarsa, actor-critic, decision-transformer, ppo, td-lambda'));
|
|
5197
|
+
} else {
|
|
5198
|
+
console.log(chalk.dim(' ⏭️ LearningEngine not available'));
|
|
5199
|
+
}
|
|
5200
|
+
} catch (e) {
|
|
5201
|
+
console.log(chalk.yellow(` ⚠ Learning engine init skipped: ${e.message}`));
|
|
5202
|
+
}
|
|
5203
|
+
|
|
5204
|
+
// Phase 11: Initialize TensorCompress for pattern storage
|
|
5205
|
+
console.log(chalk.yellow('\n📦 Phase 11: Initializing TensorCompress for efficient storage...\n'));
|
|
5206
|
+
|
|
5207
|
+
try {
|
|
5208
|
+
if (loadLearningModules() && TensorCompressClass) {
|
|
5209
|
+
const compress = new TensorCompressClass({
|
|
5210
|
+
autoCompress: false,
|
|
5211
|
+
hotThreshold: 0.8,
|
|
5212
|
+
warmThreshold: 0.4,
|
|
5213
|
+
coolThreshold: 0.1,
|
|
5214
|
+
coldThreshold: 0.01
|
|
5215
|
+
});
|
|
5216
|
+
|
|
5217
|
+
// Store any existing embeddings with compression
|
|
5218
|
+
let compressed = 0;
|
|
5219
|
+
if (intel.data.memories) {
|
|
5220
|
+
for (let i = 0; i < intel.data.memories.length; i++) {
|
|
5221
|
+
const mem = intel.data.memories[i];
|
|
5222
|
+
if (mem.embedding && Array.isArray(mem.embedding)) {
|
|
5223
|
+
compress.store(`memory_${i}`, mem.embedding, 'pq8');
|
|
5224
|
+
compressed++;
|
|
5225
|
+
}
|
|
5226
|
+
}
|
|
5227
|
+
}
|
|
5228
|
+
|
|
5229
|
+
if (compressed > 0) {
|
|
5230
|
+
const compStats = compress.recompressAll();
|
|
5231
|
+
intel.data.compressedPatterns = compress.export();
|
|
5232
|
+
stats.compressed = compressed;
|
|
5233
|
+
stats.compressionSavings = compStats.savingsPercent;
|
|
5234
|
+
console.log(chalk.green(` ✓ Compressed ${compressed} embeddings`));
|
|
5235
|
+
console.log(chalk.green(` ✓ Memory savings: ${compStats.savingsPercent.toFixed(1)}%`));
|
|
5236
|
+
} else {
|
|
5237
|
+
intel.data.compressedPatterns = compress.export();
|
|
5238
|
+
console.log(chalk.green(` ✓ TensorCompress initialized (ready for future embeddings)`));
|
|
5239
|
+
}
|
|
5240
|
+
console.log(chalk.dim(' Levels: none (hot), half (warm), pq8 (cool), pq4 (cold), binary (archive)'));
|
|
5241
|
+
} else {
|
|
5242
|
+
console.log(chalk.dim(' ⏭️ TensorCompress not available'));
|
|
5243
|
+
}
|
|
5244
|
+
} catch (e) {
|
|
5245
|
+
console.log(chalk.yellow(` ⚠ TensorCompress init skipped: ${e.message}`));
|
|
5246
|
+
}
|
|
5247
|
+
|
|
5110
5248
|
// Save all learning data
|
|
5111
5249
|
intel.data.pretrained = {
|
|
5112
5250
|
date: new Date().toISOString(),
|
|
5113
|
-
version: '2.
|
|
5251
|
+
version: '2.1',
|
|
5114
5252
|
stats: stats
|
|
5115
5253
|
};
|
|
5116
5254
|
intel.save();
|
|
@@ -5127,6 +5265,8 @@ hooksCmd.command('pretrain')
|
|
|
5127
5265
|
if (stats.coverage) console.log(` 🧪 Coverage: ${stats.coverage.lines.toFixed(1)}% lines`);
|
|
5128
5266
|
if (stats.neural?.attention) console.log(` 🧠 10 attention mechanisms available`);
|
|
5129
5267
|
if (stats.graph) console.log(` 🔗 ${stats.graph.communities} code communities detected`);
|
|
5268
|
+
if (stats.learningBootstrap) console.log(` 🎯 ${stats.learningBootstrap} learning experiences bootstrapped`);
|
|
5269
|
+
if (stats.compressionSavings) console.log(` 📦 ${stats.compressionSavings.toFixed(1)}% compression savings`);
|
|
5130
5270
|
console.log(chalk.dim('\nThe intelligence layer will now provide better recommendations.'));
|
|
5131
5271
|
});
|
|
5132
5272
|
|