ruvector 0.1.67 → 0.1.69

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.
@@ -127,7 +127,8 @@
127
127
  "total_memories": 0,
128
128
  "total_trajectories": 0,
129
129
  "total_errors": 0,
130
- "session_count": 0,
131
- "last_session": 0
132
- }
130
+ "session_count": 2,
131
+ "last_session": 1767194641
132
+ },
133
+ "trajectories": []
133
134
  }
package/bin/cli.js CHANGED
@@ -2609,22 +2609,56 @@ class Intelligence {
2609
2609
  }
2610
2610
 
2611
2611
  sessionEnd() {
2612
- // Ensure stats exists with defaults
2612
+ // Ensure data structure exists with defaults
2613
+ if (!this.data) {
2614
+ this.data = { patterns: {}, memories: [], trajectories: [], errors: [], agents: {}, edges: [], stats: {} };
2615
+ }
2613
2616
  if (!this.data.stats) {
2614
2617
  this.data.stats = { total_patterns: 0, total_memories: 0, total_trajectories: 0, total_errors: 0, session_count: 0, last_session: 0 };
2615
2618
  }
2619
+ if (!this.data.trajectories) {
2620
+ this.data.trajectories = [];
2621
+ }
2622
+
2616
2623
  const lastSession = this.data.stats.last_session || 0;
2617
2624
  const duration = this.now() - (this.sessionStartTime || lastSession);
2618
- const actions = (this.data.trajectories || []).filter(t => t.timestamp >= lastSession).length;
2625
+ const actions = this.data.trajectories.filter(t => t && t.timestamp >= lastSession).length;
2619
2626
 
2620
2627
  // Force learning cycle (only if engine already initialized)
2621
- const eng = this.getEngineIfReady();
2622
- if (eng) {
2623
- eng.forceLearn();
2628
+ try {
2629
+ const eng = this.getEngineIfReady();
2630
+ if (eng) {
2631
+ eng.forceLearn();
2632
+ }
2633
+ } catch (e) {
2634
+ // Ignore engine errors on session end
2635
+ }
2636
+
2637
+ // Auto-compress patterns if enabled (v2.1)
2638
+ try {
2639
+ if (process.env.RUVECTOR_AUTO_COMPRESS === 'true' || process.env.RUVECTOR_TENSOR_COMPRESS === 'true') {
2640
+ const TensorCompressClass = require('../dist/core/tensor-compress').default;
2641
+ if (TensorCompressClass && this.data.compressedPatterns) {
2642
+ const compress = new TensorCompressClass({ autoCompress: false });
2643
+ compress.import(this.data.compressedPatterns);
2644
+ const stats = compress.recompressAll();
2645
+ this.data.compressedPatterns = compress.export();
2646
+ // Only log if significant savings
2647
+ if (stats.savingsPercent > 10 && stats.totalTensors > 5) {
2648
+ // Silently compress, no console output to avoid hook noise
2649
+ }
2650
+ }
2651
+ }
2652
+ } catch (e) {
2653
+ // Ignore compression errors on session end
2624
2654
  }
2625
2655
 
2626
2656
  // Save all data
2627
- this.save();
2657
+ try {
2658
+ this.save();
2659
+ } catch (e) {
2660
+ // Ignore save errors on session end
2661
+ }
2628
2662
 
2629
2663
  return { duration, actions };
2630
2664
  }
@@ -2734,11 +2768,23 @@ hooksCmd.command('init')
2734
2768
  // Environment variables for intelligence (unless --minimal or --no-env)
2735
2769
  if (!opts.minimal && opts.env !== false) {
2736
2770
  settings.env = settings.env || {};
2771
+ // Core intelligence settings
2737
2772
  settings.env.RUVECTOR_INTELLIGENCE_ENABLED = settings.env.RUVECTOR_INTELLIGENCE_ENABLED || 'true';
2738
2773
  settings.env.RUVECTOR_LEARNING_RATE = settings.env.RUVECTOR_LEARNING_RATE || '0.1';
2739
2774
  settings.env.RUVECTOR_MEMORY_BACKEND = settings.env.RUVECTOR_MEMORY_BACKEND || 'rvlite';
2740
2775
  settings.env.INTELLIGENCE_MODE = settings.env.INTELLIGENCE_MODE || 'treatment';
2741
- console.log(chalk.blue(' ✓ Environment variables configured'));
2776
+ // v2.0 capabilities
2777
+ settings.env.RUVECTOR_AST_ENABLED = settings.env.RUVECTOR_AST_ENABLED || 'true';
2778
+ settings.env.RUVECTOR_DIFF_EMBEDDINGS = settings.env.RUVECTOR_DIFF_EMBEDDINGS || 'true';
2779
+ settings.env.RUVECTOR_COVERAGE_ROUTING = settings.env.RUVECTOR_COVERAGE_ROUTING || 'true';
2780
+ settings.env.RUVECTOR_GRAPH_ALGORITHMS = settings.env.RUVECTOR_GRAPH_ALGORITHMS || 'true';
2781
+ settings.env.RUVECTOR_SECURITY_SCAN = settings.env.RUVECTOR_SECURITY_SCAN || 'true';
2782
+ // v2.1 learning & compression
2783
+ settings.env.RUVECTOR_MULTI_ALGORITHM = settings.env.RUVECTOR_MULTI_ALGORITHM || 'true';
2784
+ settings.env.RUVECTOR_DEFAULT_ALGORITHM = settings.env.RUVECTOR_DEFAULT_ALGORITHM || 'double-q';
2785
+ settings.env.RUVECTOR_TENSOR_COMPRESS = settings.env.RUVECTOR_TENSOR_COMPRESS || 'true';
2786
+ settings.env.RUVECTOR_AUTO_COMPRESS = settings.env.RUVECTOR_AUTO_COMPRESS || 'true';
2787
+ console.log(chalk.blue(' ✓ Environment variables configured (v2.1 with multi-algorithm learning)'));
2742
2788
  }
2743
2789
 
2744
2790
  // Permissions based on detected project type (unless --minimal or --no-permissions)
@@ -5092,10 +5138,98 @@ hooksCmd.command('pretrain')
5092
5138
  console.log(chalk.yellow(` ⚠ Graph analysis skipped: ${e.message}`));
5093
5139
  }
5094
5140
 
5141
+ // Phase 10: Initialize multi-algorithm learning engine
5142
+ console.log(chalk.yellow('\n🎯 Phase 10: Initializing multi-algorithm learning engine...\n'));
5143
+
5144
+ try {
5145
+ if (loadLearningModules() && LearningEngineClass) {
5146
+ const engine = new LearningEngineClass();
5147
+
5148
+ // Configure optimal algorithms for each task type based on repo analysis
5149
+ engine.configure('agent-routing', { algorithm: 'double-q', learningRate: 0.1, epsilon: 0.1 });
5150
+ engine.configure('error-avoidance', { algorithm: 'sarsa', learningRate: 0.05, epsilon: 0.05 });
5151
+ engine.configure('confidence-scoring', { algorithm: 'actor-critic', learningRate: 0.01 });
5152
+ engine.configure('trajectory-learning', { algorithm: 'decision-transformer', sequenceLength: 20 });
5153
+ engine.configure('context-ranking', { algorithm: 'ppo', clipRange: 0.2 });
5154
+ engine.configure('memory-recall', { algorithm: 'td-lambda', lambda: 0.8 });
5155
+
5156
+ // Bootstrap with initial experiences from file patterns
5157
+ let bootstrapCount = 0;
5158
+ for (const [state, actions] of Object.entries(intel.data.patterns || {})) {
5159
+ for (const [action, value] of Object.entries(actions)) {
5160
+ if (value > 0.3) { // Only strong patterns
5161
+ engine.update('agent-routing', {
5162
+ state,
5163
+ action,
5164
+ reward: value,
5165
+ nextState: state,
5166
+ done: true
5167
+ });
5168
+ bootstrapCount++;
5169
+ }
5170
+ }
5171
+ }
5172
+
5173
+ intel.data.learning = engine.export();
5174
+ stats.learningBootstrap = bootstrapCount;
5175
+ console.log(chalk.green(` ✓ Configured 6 task-specific algorithms`));
5176
+ console.log(chalk.green(` ✓ Bootstrapped with ${bootstrapCount} initial experiences`));
5177
+ console.log(chalk.dim(' Algorithms: double-q, sarsa, actor-critic, decision-transformer, ppo, td-lambda'));
5178
+ } else {
5179
+ console.log(chalk.dim(' ⏭️ LearningEngine not available'));
5180
+ }
5181
+ } catch (e) {
5182
+ console.log(chalk.yellow(` ⚠ Learning engine init skipped: ${e.message}`));
5183
+ }
5184
+
5185
+ // Phase 11: Initialize TensorCompress for pattern storage
5186
+ console.log(chalk.yellow('\n📦 Phase 11: Initializing TensorCompress for efficient storage...\n'));
5187
+
5188
+ try {
5189
+ if (loadLearningModules() && TensorCompressClass) {
5190
+ const compress = new TensorCompressClass({
5191
+ autoCompress: false,
5192
+ hotThreshold: 0.8,
5193
+ warmThreshold: 0.4,
5194
+ coolThreshold: 0.1,
5195
+ coldThreshold: 0.01
5196
+ });
5197
+
5198
+ // Store any existing embeddings with compression
5199
+ let compressed = 0;
5200
+ if (intel.data.memories) {
5201
+ for (let i = 0; i < intel.data.memories.length; i++) {
5202
+ const mem = intel.data.memories[i];
5203
+ if (mem.embedding && Array.isArray(mem.embedding)) {
5204
+ compress.store(`memory_${i}`, mem.embedding, 'pq8');
5205
+ compressed++;
5206
+ }
5207
+ }
5208
+ }
5209
+
5210
+ if (compressed > 0) {
5211
+ const compStats = compress.recompressAll();
5212
+ intel.data.compressedPatterns = compress.export();
5213
+ stats.compressed = compressed;
5214
+ stats.compressionSavings = compStats.savingsPercent;
5215
+ console.log(chalk.green(` ✓ Compressed ${compressed} embeddings`));
5216
+ console.log(chalk.green(` ✓ Memory savings: ${compStats.savingsPercent.toFixed(1)}%`));
5217
+ } else {
5218
+ intel.data.compressedPatterns = compress.export();
5219
+ console.log(chalk.green(` ✓ TensorCompress initialized (ready for future embeddings)`));
5220
+ }
5221
+ console.log(chalk.dim(' Levels: none (hot), half (warm), pq8 (cool), pq4 (cold), binary (archive)'));
5222
+ } else {
5223
+ console.log(chalk.dim(' ⏭️ TensorCompress not available'));
5224
+ }
5225
+ } catch (e) {
5226
+ console.log(chalk.yellow(` ⚠ TensorCompress init skipped: ${e.message}`));
5227
+ }
5228
+
5095
5229
  // Save all learning data
5096
5230
  intel.data.pretrained = {
5097
5231
  date: new Date().toISOString(),
5098
- version: '2.0',
5232
+ version: '2.1',
5099
5233
  stats: stats
5100
5234
  };
5101
5235
  intel.save();
@@ -5112,6 +5246,8 @@ hooksCmd.command('pretrain')
5112
5246
  if (stats.coverage) console.log(` 🧪 Coverage: ${stats.coverage.lines.toFixed(1)}% lines`);
5113
5247
  if (stats.neural?.attention) console.log(` 🧠 10 attention mechanisms available`);
5114
5248
  if (stats.graph) console.log(` 🔗 ${stats.graph.communities} code communities detected`);
5249
+ if (stats.learningBootstrap) console.log(` 🎯 ${stats.learningBootstrap} learning experiences bootstrapped`);
5250
+ if (stats.compressionSavings) console.log(` 📦 ${stats.compressionSavings.toFixed(1)}% compression savings`);
5115
5251
  console.log(chalk.dim('\nThe intelligence layer will now provide better recommendations.'));
5116
5252
  });
5117
5253
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ruvector",
3
- "version": "0.1.67",
3
+ "version": "0.1.69",
4
4
  "description": "High-performance vector database for Node.js with automatic native/WASM fallback",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/ruvector.db CHANGED
Binary file