ruvector 0.1.78 → 0.1.80
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/workers/code-analyzer.db +0 -0
- package/bin/cli.js +309 -0
- package/dist/core/intelligence-engine.d.ts +21 -0
- package/dist/core/intelligence-engine.d.ts.map +1 -1
- package/dist/core/intelligence-engine.js +71 -0
- package/dist/workers/benchmark.d.ts +44 -0
- package/dist/workers/benchmark.d.ts.map +1 -0
- package/dist/workers/benchmark.js +230 -0
- package/dist/workers/index.d.ts +10 -0
- package/dist/workers/index.d.ts.map +1 -0
- package/dist/workers/index.js +25 -0
- package/dist/workers/native-worker.d.ts +76 -0
- package/dist/workers/native-worker.d.ts.map +1 -0
- package/dist/workers/native-worker.js +489 -0
- package/dist/workers/types.d.ts +69 -0
- package/dist/workers/types.d.ts.map +1 -0
- package/dist/workers/types.js +7 -0
- package/package.json +1 -1
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Native Worker Runner for RuVector
|
|
4
|
+
*
|
|
5
|
+
* Direct integration with:
|
|
6
|
+
* - ONNX embedder (384d, SIMD-accelerated)
|
|
7
|
+
* - VectorDB (HNSW indexing)
|
|
8
|
+
* - Intelligence engine (Q-learning, memory)
|
|
9
|
+
*
|
|
10
|
+
* No delegation to external tools - pure ruvector execution.
|
|
11
|
+
*/
|
|
12
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
15
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
16
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
17
|
+
}
|
|
18
|
+
Object.defineProperty(o, k2, desc);
|
|
19
|
+
}) : (function(o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k;
|
|
21
|
+
o[k2] = m[k];
|
|
22
|
+
}));
|
|
23
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
24
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
25
|
+
}) : function(o, v) {
|
|
26
|
+
o["default"] = v;
|
|
27
|
+
});
|
|
28
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
29
|
+
var ownKeys = function(o) {
|
|
30
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
31
|
+
var ar = [];
|
|
32
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
33
|
+
return ar;
|
|
34
|
+
};
|
|
35
|
+
return ownKeys(o);
|
|
36
|
+
};
|
|
37
|
+
return function (mod) {
|
|
38
|
+
if (mod && mod.__esModule) return mod;
|
|
39
|
+
var result = {};
|
|
40
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
41
|
+
__setModuleDefault(result, mod);
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
44
|
+
})();
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.NativeWorker = void 0;
|
|
47
|
+
exports.createSecurityWorker = createSecurityWorker;
|
|
48
|
+
exports.createAnalysisWorker = createAnalysisWorker;
|
|
49
|
+
exports.createLearningWorker = createLearningWorker;
|
|
50
|
+
const fs = __importStar(require("fs"));
|
|
51
|
+
const path = __importStar(require("path"));
|
|
52
|
+
const glob_1 = require("glob");
|
|
53
|
+
const onnx_embedder_1 = require("../core/onnx-embedder");
|
|
54
|
+
// Lazy imports for optional dependencies
|
|
55
|
+
let VectorDb = null;
|
|
56
|
+
let intelligence = null;
|
|
57
|
+
async function loadOptionalDeps() {
|
|
58
|
+
try {
|
|
59
|
+
const core = await Promise.resolve().then(() => __importStar(require('@ruvector/core')));
|
|
60
|
+
VectorDb = core.VectorDb;
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
// VectorDB not available
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
const intel = await Promise.resolve().then(() => __importStar(require('../core/intelligence-engine')));
|
|
67
|
+
intelligence = intel;
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
// Intelligence not available
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Native Worker Runner
|
|
75
|
+
*/
|
|
76
|
+
class NativeWorker {
|
|
77
|
+
constructor(config) {
|
|
78
|
+
this.vectorDb = null;
|
|
79
|
+
this.findings = [];
|
|
80
|
+
this.stats = {
|
|
81
|
+
filesAnalyzed: 0,
|
|
82
|
+
patternsFound: 0,
|
|
83
|
+
embeddingsGenerated: 0,
|
|
84
|
+
vectorsStored: 0,
|
|
85
|
+
};
|
|
86
|
+
this.config = config;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Initialize worker with capabilities
|
|
90
|
+
*/
|
|
91
|
+
async init() {
|
|
92
|
+
await loadOptionalDeps();
|
|
93
|
+
// Initialize ONNX embedder if needed
|
|
94
|
+
if (this.config.capabilities?.onnxEmbeddings) {
|
|
95
|
+
await (0, onnx_embedder_1.initOnnxEmbedder)();
|
|
96
|
+
}
|
|
97
|
+
// Initialize VectorDB if needed
|
|
98
|
+
if (this.config.capabilities?.vectorDb && VectorDb) {
|
|
99
|
+
const dbPath = path.join(process.cwd(), '.ruvector', 'workers', `${this.config.name}.db`);
|
|
100
|
+
fs.mkdirSync(path.dirname(dbPath), { recursive: true });
|
|
101
|
+
this.vectorDb = new VectorDb({
|
|
102
|
+
dimensions: 384,
|
|
103
|
+
storagePath: dbPath,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Run all phases in sequence
|
|
109
|
+
*/
|
|
110
|
+
async run(targetPath = '.') {
|
|
111
|
+
const startTime = performance.now();
|
|
112
|
+
const phaseResults = [];
|
|
113
|
+
await this.init();
|
|
114
|
+
let context = { targetPath, files: [], patterns: [], embeddings: [] };
|
|
115
|
+
for (const phaseConfig of this.config.phases) {
|
|
116
|
+
const phaseStart = performance.now();
|
|
117
|
+
try {
|
|
118
|
+
context = await this.executePhase(phaseConfig.type, context, phaseConfig.config);
|
|
119
|
+
phaseResults.push({
|
|
120
|
+
phase: phaseConfig.type,
|
|
121
|
+
success: true,
|
|
122
|
+
data: this.summarizePhaseData(phaseConfig.type, context),
|
|
123
|
+
timeMs: performance.now() - phaseStart,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
phaseResults.push({
|
|
128
|
+
phase: phaseConfig.type,
|
|
129
|
+
success: false,
|
|
130
|
+
data: null,
|
|
131
|
+
timeMs: performance.now() - phaseStart,
|
|
132
|
+
error: error.message,
|
|
133
|
+
});
|
|
134
|
+
// Continue to next phase on error (fault-tolerant)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const totalTimeMs = performance.now() - startTime;
|
|
138
|
+
return {
|
|
139
|
+
worker: this.config.name,
|
|
140
|
+
success: phaseResults.every(p => p.success),
|
|
141
|
+
phases: phaseResults,
|
|
142
|
+
totalTimeMs,
|
|
143
|
+
summary: {
|
|
144
|
+
filesAnalyzed: this.stats.filesAnalyzed,
|
|
145
|
+
patternsFound: this.stats.patternsFound,
|
|
146
|
+
embeddingsGenerated: this.stats.embeddingsGenerated,
|
|
147
|
+
vectorsStored: this.stats.vectorsStored,
|
|
148
|
+
findings: this.findings,
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Execute a single phase
|
|
154
|
+
*/
|
|
155
|
+
async executePhase(type, context, config) {
|
|
156
|
+
switch (type) {
|
|
157
|
+
case 'file-discovery':
|
|
158
|
+
return this.phaseFileDiscovery(context, config);
|
|
159
|
+
case 'pattern-extraction':
|
|
160
|
+
return this.phasePatternExtraction(context, config);
|
|
161
|
+
case 'embedding-generation':
|
|
162
|
+
return this.phaseEmbeddingGeneration(context, config);
|
|
163
|
+
case 'vector-storage':
|
|
164
|
+
return this.phaseVectorStorage(context, config);
|
|
165
|
+
case 'similarity-search':
|
|
166
|
+
return this.phaseSimilaritySearch(context, config);
|
|
167
|
+
case 'security-scan':
|
|
168
|
+
return this.phaseSecurityScan(context, config);
|
|
169
|
+
case 'complexity-analysis':
|
|
170
|
+
return this.phaseComplexityAnalysis(context, config);
|
|
171
|
+
case 'summarization':
|
|
172
|
+
return this.phaseSummarization(context, config);
|
|
173
|
+
default:
|
|
174
|
+
throw new Error(`Unknown phase: ${type}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Phase: File Discovery
|
|
179
|
+
*/
|
|
180
|
+
async phaseFileDiscovery(context, config) {
|
|
181
|
+
const patterns = config?.patterns || ['**/*.ts', '**/*.js', '**/*.tsx', '**/*.jsx'];
|
|
182
|
+
const exclude = config?.exclude || ['**/node_modules/**', '**/dist/**', '**/.git/**'];
|
|
183
|
+
const files = [];
|
|
184
|
+
for (const pattern of patterns) {
|
|
185
|
+
const matches = await (0, glob_1.glob)(pattern, {
|
|
186
|
+
cwd: context.targetPath,
|
|
187
|
+
ignore: exclude,
|
|
188
|
+
nodir: true,
|
|
189
|
+
});
|
|
190
|
+
files.push(...matches.map(f => path.join(context.targetPath, f)));
|
|
191
|
+
}
|
|
192
|
+
this.stats.filesAnalyzed = files.length;
|
|
193
|
+
return { ...context, files };
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Phase: Pattern Extraction
|
|
197
|
+
*/
|
|
198
|
+
async phasePatternExtraction(context, config) {
|
|
199
|
+
const patterns = [];
|
|
200
|
+
const patternTypes = config?.types || ['function', 'class', 'import', 'export', 'todo'];
|
|
201
|
+
for (const file of context.files.slice(0, 100)) {
|
|
202
|
+
try {
|
|
203
|
+
const content = fs.readFileSync(file, 'utf-8');
|
|
204
|
+
// Extract functions
|
|
205
|
+
if (patternTypes.includes('function')) {
|
|
206
|
+
const funcMatches = content.match(/(?:async\s+)?function\s+(\w+)|(?:const|let|var)\s+(\w+)\s*=\s*(?:async\s*)?\(/g) || [];
|
|
207
|
+
patterns.push(...funcMatches.map(m => ({ type: 'function', match: m, file })));
|
|
208
|
+
}
|
|
209
|
+
// Extract classes
|
|
210
|
+
if (patternTypes.includes('class')) {
|
|
211
|
+
const classMatches = content.match(/class\s+(\w+)/g) || [];
|
|
212
|
+
patterns.push(...classMatches.map(m => ({ type: 'class', match: m, file })));
|
|
213
|
+
}
|
|
214
|
+
// Extract imports
|
|
215
|
+
if (patternTypes.includes('import')) {
|
|
216
|
+
const importMatches = content.match(/import\s+.*?from\s+['"][^'"]+['"]/g) || [];
|
|
217
|
+
patterns.push(...importMatches.map(m => ({ type: 'import', match: m, file })));
|
|
218
|
+
}
|
|
219
|
+
// Extract TODOs
|
|
220
|
+
if (patternTypes.includes('todo')) {
|
|
221
|
+
const todoMatches = content.match(/\/\/\s*(TODO|FIXME|HACK|XXX):.*/gi) || [];
|
|
222
|
+
patterns.push(...todoMatches.map(m => ({ type: 'todo', match: m, file })));
|
|
223
|
+
// Add findings for TODOs
|
|
224
|
+
todoMatches.forEach(m => {
|
|
225
|
+
this.findings.push({
|
|
226
|
+
type: 'info',
|
|
227
|
+
message: m,
|
|
228
|
+
file,
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
// Skip unreadable files
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
this.stats.patternsFound = patterns.length;
|
|
238
|
+
return { ...context, patterns };
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Phase: Embedding Generation (ONNX)
|
|
242
|
+
*/
|
|
243
|
+
async phaseEmbeddingGeneration(context, config) {
|
|
244
|
+
if (!(0, onnx_embedder_1.isReady)()) {
|
|
245
|
+
await (0, onnx_embedder_1.initOnnxEmbedder)();
|
|
246
|
+
}
|
|
247
|
+
const embeddings = [];
|
|
248
|
+
const batchSize = config?.batchSize || 32;
|
|
249
|
+
// Collect texts to embed
|
|
250
|
+
const texts = [];
|
|
251
|
+
// Embed file content summaries
|
|
252
|
+
for (const file of context.files.slice(0, 50)) {
|
|
253
|
+
try {
|
|
254
|
+
const content = fs.readFileSync(file, 'utf-8');
|
|
255
|
+
const summary = content.slice(0, 512); // First 512 chars
|
|
256
|
+
texts.push({ text: summary, file });
|
|
257
|
+
}
|
|
258
|
+
catch {
|
|
259
|
+
// Skip
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
// Embed patterns
|
|
263
|
+
for (const pattern of context.patterns.slice(0, 100)) {
|
|
264
|
+
texts.push({ text: pattern.match, file: pattern.file });
|
|
265
|
+
}
|
|
266
|
+
// Batch embed
|
|
267
|
+
for (let i = 0; i < texts.length; i += batchSize) {
|
|
268
|
+
const batch = texts.slice(i, i + batchSize);
|
|
269
|
+
const results = await (0, onnx_embedder_1.embedBatch)(batch.map(t => t.text));
|
|
270
|
+
for (let j = 0; j < results.length; j++) {
|
|
271
|
+
embeddings.push({
|
|
272
|
+
text: batch[j].text,
|
|
273
|
+
embedding: results[j].embedding,
|
|
274
|
+
file: batch[j].file,
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
this.stats.embeddingsGenerated = embeddings.length;
|
|
279
|
+
return { ...context, embeddings };
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Phase: Vector Storage
|
|
283
|
+
*/
|
|
284
|
+
async phaseVectorStorage(context, config) {
|
|
285
|
+
if (!this.vectorDb) {
|
|
286
|
+
return context;
|
|
287
|
+
}
|
|
288
|
+
let stored = 0;
|
|
289
|
+
for (const item of context.embeddings) {
|
|
290
|
+
try {
|
|
291
|
+
await this.vectorDb.insert({
|
|
292
|
+
vector: new Float32Array(item.embedding),
|
|
293
|
+
metadata: {
|
|
294
|
+
text: item.text.slice(0, 200),
|
|
295
|
+
file: item.file,
|
|
296
|
+
worker: this.config.name,
|
|
297
|
+
timestamp: Date.now(),
|
|
298
|
+
},
|
|
299
|
+
});
|
|
300
|
+
stored++;
|
|
301
|
+
}
|
|
302
|
+
catch {
|
|
303
|
+
// Skip duplicates/errors
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
this.stats.vectorsStored = stored;
|
|
307
|
+
return context;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Phase: Similarity Search
|
|
311
|
+
*/
|
|
312
|
+
async phaseSimilaritySearch(context, config) {
|
|
313
|
+
if (!this.vectorDb || context.embeddings.length === 0) {
|
|
314
|
+
return context;
|
|
315
|
+
}
|
|
316
|
+
const query = config?.query || context.embeddings[0]?.text;
|
|
317
|
+
if (!query)
|
|
318
|
+
return context;
|
|
319
|
+
const queryResult = await (0, onnx_embedder_1.embed)(query);
|
|
320
|
+
const results = await this.vectorDb.search({
|
|
321
|
+
vector: new Float32Array(queryResult.embedding),
|
|
322
|
+
k: config?.k || 5,
|
|
323
|
+
});
|
|
324
|
+
return { ...context, searchResults: results };
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Phase: Security Scan
|
|
328
|
+
*/
|
|
329
|
+
async phaseSecurityScan(context, config) {
|
|
330
|
+
const securityPatterns = [
|
|
331
|
+
{ pattern: /password\s*=\s*['"][^'"]+['"]/gi, severity: 'high', type: 'Hardcoded password' },
|
|
332
|
+
{ pattern: /api[_-]?key\s*=\s*['"][^'"]+['"]/gi, severity: 'high', type: 'Hardcoded API key' },
|
|
333
|
+
{ pattern: /secret\s*=\s*['"][^'"]+['"]/gi, severity: 'high', type: 'Hardcoded secret' },
|
|
334
|
+
{ pattern: /eval\s*\(/g, severity: 'medium', type: 'eval() usage' },
|
|
335
|
+
{ pattern: /dangerouslySetInnerHTML/g, severity: 'medium', type: 'XSS risk' },
|
|
336
|
+
{ pattern: /SELECT\s+.*\s+FROM.*\+/gi, severity: 'high', type: 'SQL injection risk' },
|
|
337
|
+
{ pattern: /exec\s*\(/g, severity: 'medium', type: 'Command execution' },
|
|
338
|
+
];
|
|
339
|
+
for (const file of context.files.slice(0, 100)) {
|
|
340
|
+
try {
|
|
341
|
+
const content = fs.readFileSync(file, 'utf-8');
|
|
342
|
+
const lines = content.split('\n');
|
|
343
|
+
for (const { pattern, severity, type } of securityPatterns) {
|
|
344
|
+
let match;
|
|
345
|
+
const regex = new RegExp(pattern.source, pattern.flags);
|
|
346
|
+
while ((match = regex.exec(content)) !== null) {
|
|
347
|
+
const lineNum = content.slice(0, match.index).split('\n').length;
|
|
348
|
+
this.findings.push({
|
|
349
|
+
type: 'security',
|
|
350
|
+
message: `${type}: ${match[0].slice(0, 50)}...`,
|
|
351
|
+
file,
|
|
352
|
+
line: lineNum,
|
|
353
|
+
severity: severity === 'high' ? 3 : 2,
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
catch {
|
|
359
|
+
// Skip
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return context;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Phase: Complexity Analysis
|
|
366
|
+
*/
|
|
367
|
+
async phaseComplexityAnalysis(context, config) {
|
|
368
|
+
const complexityThreshold = config?.threshold || 10;
|
|
369
|
+
const complexFiles = [];
|
|
370
|
+
for (const file of context.files.slice(0, 50)) {
|
|
371
|
+
try {
|
|
372
|
+
const content = fs.readFileSync(file, 'utf-8');
|
|
373
|
+
// Simple cyclomatic complexity approximation
|
|
374
|
+
const branches = (content.match(/\bif\b/g)?.length || 0) +
|
|
375
|
+
(content.match(/\belse\b/g)?.length || 0) +
|
|
376
|
+
(content.match(/\bfor\b/g)?.length || 0) +
|
|
377
|
+
(content.match(/\bwhile\b/g)?.length || 0) +
|
|
378
|
+
(content.match(/\bswitch\b/g)?.length || 0) +
|
|
379
|
+
(content.match(/\bcase\b/g)?.length || 0) +
|
|
380
|
+
(content.match(/\bcatch\b/g)?.length || 0) +
|
|
381
|
+
(content.match(/\?\?/g)?.length || 0) +
|
|
382
|
+
(content.match(/\?/g)?.length || 0);
|
|
383
|
+
const complexity = branches + 1;
|
|
384
|
+
if (complexity > complexityThreshold) {
|
|
385
|
+
complexFiles.push({ file, complexity });
|
|
386
|
+
this.findings.push({
|
|
387
|
+
type: 'warning',
|
|
388
|
+
message: `High complexity: ${complexity} (threshold: ${complexityThreshold})`,
|
|
389
|
+
file,
|
|
390
|
+
severity: complexity > 20 ? 3 : 2,
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
catch {
|
|
395
|
+
// Skip
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return { ...context, complexFiles };
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Phase: Summarization
|
|
402
|
+
*/
|
|
403
|
+
async phaseSummarization(context, config) {
|
|
404
|
+
const summary = {
|
|
405
|
+
filesAnalyzed: context.files?.length || 0,
|
|
406
|
+
patternsFound: context.patterns?.length || 0,
|
|
407
|
+
embeddingsGenerated: context.embeddings?.length || 0,
|
|
408
|
+
findingsCount: this.findings.length,
|
|
409
|
+
findingsByType: {
|
|
410
|
+
info: this.findings.filter(f => f.type === 'info').length,
|
|
411
|
+
warning: this.findings.filter(f => f.type === 'warning').length,
|
|
412
|
+
error: this.findings.filter(f => f.type === 'error').length,
|
|
413
|
+
security: this.findings.filter(f => f.type === 'security').length,
|
|
414
|
+
},
|
|
415
|
+
topFindings: this.findings.slice(0, 10),
|
|
416
|
+
};
|
|
417
|
+
return { ...context, summary };
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Summarize phase data for results
|
|
421
|
+
*/
|
|
422
|
+
summarizePhaseData(type, context) {
|
|
423
|
+
switch (type) {
|
|
424
|
+
case 'file-discovery':
|
|
425
|
+
return { filesFound: context.files?.length || 0 };
|
|
426
|
+
case 'pattern-extraction':
|
|
427
|
+
return { patternsFound: context.patterns?.length || 0 };
|
|
428
|
+
case 'embedding-generation':
|
|
429
|
+
return { embeddingsGenerated: context.embeddings?.length || 0 };
|
|
430
|
+
case 'vector-storage':
|
|
431
|
+
return { vectorsStored: this.stats.vectorsStored };
|
|
432
|
+
case 'similarity-search':
|
|
433
|
+
return { resultsFound: context.searchResults?.length || 0 };
|
|
434
|
+
case 'security-scan':
|
|
435
|
+
return { securityFindings: this.findings.filter(f => f.type === 'security').length };
|
|
436
|
+
case 'complexity-analysis':
|
|
437
|
+
return { complexFiles: context.complexFiles?.length || 0 };
|
|
438
|
+
case 'summarization':
|
|
439
|
+
return context.summary;
|
|
440
|
+
default:
|
|
441
|
+
return {};
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
exports.NativeWorker = NativeWorker;
|
|
446
|
+
/**
|
|
447
|
+
* Quick worker factory functions
|
|
448
|
+
*/
|
|
449
|
+
function createSecurityWorker(name = 'security-scanner') {
|
|
450
|
+
return new NativeWorker({
|
|
451
|
+
name,
|
|
452
|
+
description: 'Security vulnerability scanner',
|
|
453
|
+
phases: [
|
|
454
|
+
{ type: 'file-discovery', config: { patterns: ['**/*.ts', '**/*.js', '**/*.tsx', '**/*.jsx'] } },
|
|
455
|
+
{ type: 'security-scan' },
|
|
456
|
+
{ type: 'summarization' },
|
|
457
|
+
],
|
|
458
|
+
capabilities: { onnxEmbeddings: false, vectorDb: false },
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
function createAnalysisWorker(name = 'code-analyzer') {
|
|
462
|
+
return new NativeWorker({
|
|
463
|
+
name,
|
|
464
|
+
description: 'Code analysis with embeddings',
|
|
465
|
+
phases: [
|
|
466
|
+
{ type: 'file-discovery' },
|
|
467
|
+
{ type: 'pattern-extraction' },
|
|
468
|
+
{ type: 'embedding-generation' },
|
|
469
|
+
{ type: 'vector-storage' },
|
|
470
|
+
{ type: 'complexity-analysis' },
|
|
471
|
+
{ type: 'summarization' },
|
|
472
|
+
],
|
|
473
|
+
capabilities: { onnxEmbeddings: true, vectorDb: true },
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
function createLearningWorker(name = 'pattern-learner') {
|
|
477
|
+
return new NativeWorker({
|
|
478
|
+
name,
|
|
479
|
+
description: 'Pattern learning with vector storage',
|
|
480
|
+
phases: [
|
|
481
|
+
{ type: 'file-discovery' },
|
|
482
|
+
{ type: 'pattern-extraction' },
|
|
483
|
+
{ type: 'embedding-generation' },
|
|
484
|
+
{ type: 'vector-storage' },
|
|
485
|
+
{ type: 'summarization' },
|
|
486
|
+
],
|
|
487
|
+
capabilities: { onnxEmbeddings: true, vectorDb: true, intelligenceMemory: true },
|
|
488
|
+
});
|
|
489
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native Worker Types for RuVector
|
|
3
|
+
*
|
|
4
|
+
* Deep integration with ONNX embeddings, VectorDB, and intelligence engine.
|
|
5
|
+
*/
|
|
6
|
+
export interface WorkerConfig {
|
|
7
|
+
name: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
phases: PhaseConfig[];
|
|
10
|
+
capabilities?: WorkerCapabilities;
|
|
11
|
+
timeout?: number;
|
|
12
|
+
parallel?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface PhaseConfig {
|
|
15
|
+
type: PhaseType;
|
|
16
|
+
config?: Record<string, any>;
|
|
17
|
+
}
|
|
18
|
+
export type PhaseType = 'file-discovery' | 'pattern-extraction' | 'embedding-generation' | 'vector-storage' | 'similarity-search' | 'security-scan' | 'complexity-analysis' | 'summarization';
|
|
19
|
+
export interface WorkerCapabilities {
|
|
20
|
+
onnxEmbeddings?: boolean;
|
|
21
|
+
vectorDb?: boolean;
|
|
22
|
+
intelligenceMemory?: boolean;
|
|
23
|
+
parallelProcessing?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface PhaseResult {
|
|
26
|
+
phase: PhaseType;
|
|
27
|
+
success: boolean;
|
|
28
|
+
data: any;
|
|
29
|
+
timeMs: number;
|
|
30
|
+
error?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface WorkerResult {
|
|
33
|
+
worker: string;
|
|
34
|
+
success: boolean;
|
|
35
|
+
phases: PhaseResult[];
|
|
36
|
+
totalTimeMs: number;
|
|
37
|
+
summary?: WorkerSummary;
|
|
38
|
+
}
|
|
39
|
+
export interface WorkerSummary {
|
|
40
|
+
filesAnalyzed: number;
|
|
41
|
+
patternsFound: number;
|
|
42
|
+
embeddingsGenerated: number;
|
|
43
|
+
vectorsStored: number;
|
|
44
|
+
findings: Finding[];
|
|
45
|
+
}
|
|
46
|
+
export interface Finding {
|
|
47
|
+
type: 'info' | 'warning' | 'error' | 'security';
|
|
48
|
+
message: string;
|
|
49
|
+
file?: string;
|
|
50
|
+
line?: number;
|
|
51
|
+
severity?: number;
|
|
52
|
+
}
|
|
53
|
+
export interface BenchmarkResult {
|
|
54
|
+
name: string;
|
|
55
|
+
iterations: number;
|
|
56
|
+
results: {
|
|
57
|
+
min: number;
|
|
58
|
+
max: number;
|
|
59
|
+
avg: number;
|
|
60
|
+
p50: number;
|
|
61
|
+
p95: number;
|
|
62
|
+
p99: number;
|
|
63
|
+
};
|
|
64
|
+
throughput?: {
|
|
65
|
+
itemsPerSecond: number;
|
|
66
|
+
mbPerSecond?: number;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/workers/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC9B;AAED,MAAM,MAAM,SAAS,GACjB,gBAAgB,GAChB,oBAAoB,GACpB,sBAAsB,GACtB,gBAAgB,GAChB,mBAAmB,GACnB,eAAe,GACf,qBAAqB,GACrB,eAAe,CAAC;AAEpB,MAAM,WAAW,kBAAkB;IACjC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,SAAS,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,GAAG,CAAC;IACV,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,aAAa,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,UAAU,CAAC;IAChD,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE;QACP,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IACF,UAAU,CAAC,EAAE;QACX,cAAc,EAAE,MAAM,CAAC;QACvB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;CACH"}
|