ruvector 0.1.80 → 0.1.82
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/cli.js +182 -39
- package/dist/analysis/complexity.d.ts +52 -0
- package/dist/analysis/complexity.d.ts.map +1 -0
- package/dist/analysis/complexity.js +146 -0
- package/dist/analysis/index.d.ts +15 -0
- package/dist/analysis/index.d.ts.map +1 -0
- package/dist/analysis/index.js +38 -0
- package/dist/analysis/patterns.d.ts +71 -0
- package/dist/analysis/patterns.d.ts.map +1 -0
- package/dist/analysis/patterns.js +243 -0
- package/dist/analysis/security.d.ts +51 -0
- package/dist/analysis/security.d.ts.map +1 -0
- package/dist/analysis/security.js +139 -0
- package/dist/core/adaptive-embedder.d.ts +148 -0
- package/dist/core/adaptive-embedder.d.ts.map +1 -0
- package/dist/core/adaptive-embedder.js +594 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +6 -1
- package/dist/core/parallel-workers.d.ts +2 -8
- package/dist/core/parallel-workers.d.ts.map +1 -1
- package/dist/workers/native-worker.d.ts +3 -3
- package/dist/workers/native-worker.d.ts.map +1 -1
- package/dist/workers/native-worker.js +45 -87
- package/package.json +1 -1
- package/.agentic-flow/intelligence.db +0 -0
- package/.agentic-flow/vectors.db +0 -0
- package/.agentic-flow/workers.db +0 -0
- package/.claude-flow/metrics/agent-metrics.json +0 -1
- package/.claude-flow/metrics/performance.json +0 -87
- package/.claude-flow/metrics/task-metrics.json +0 -10
- package/.ruvector/intelligence.json +0 -5289
- package/.ruvector/workers/code-analyzer.db +0 -0
- package/ruvector.db +0 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Pattern Extraction Module - Consolidated code pattern detection
|
|
4
|
+
*
|
|
5
|
+
* Single source of truth for extracting functions, imports, exports, etc.
|
|
6
|
+
* Used by native-worker.ts and parallel-workers.ts
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.detectLanguage = detectLanguage;
|
|
43
|
+
exports.extractFunctions = extractFunctions;
|
|
44
|
+
exports.extractClasses = extractClasses;
|
|
45
|
+
exports.extractImports = extractImports;
|
|
46
|
+
exports.extractExports = extractExports;
|
|
47
|
+
exports.extractTodos = extractTodos;
|
|
48
|
+
exports.extractAllPatterns = extractAllPatterns;
|
|
49
|
+
exports.extractFromFiles = extractFromFiles;
|
|
50
|
+
exports.toPatternMatches = toPatternMatches;
|
|
51
|
+
const fs = __importStar(require("fs"));
|
|
52
|
+
/**
|
|
53
|
+
* Detect language from file extension
|
|
54
|
+
*/
|
|
55
|
+
function detectLanguage(file) {
|
|
56
|
+
const ext = file.split('.').pop()?.toLowerCase() || '';
|
|
57
|
+
const langMap = {
|
|
58
|
+
ts: 'typescript', tsx: 'typescript', js: 'javascript', jsx: 'javascript',
|
|
59
|
+
rs: 'rust', py: 'python', go: 'go', java: 'java', rb: 'ruby',
|
|
60
|
+
cpp: 'cpp', c: 'c', h: 'c', hpp: 'cpp', cs: 'csharp',
|
|
61
|
+
md: 'markdown', json: 'json', yaml: 'yaml', yml: 'yaml',
|
|
62
|
+
sql: 'sql', sh: 'shell', bash: 'shell', zsh: 'shell',
|
|
63
|
+
};
|
|
64
|
+
return langMap[ext] || ext || 'unknown';
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Extract function names from content
|
|
68
|
+
*/
|
|
69
|
+
function extractFunctions(content) {
|
|
70
|
+
const patterns = [
|
|
71
|
+
/function\s+(\w+)/g,
|
|
72
|
+
/const\s+(\w+)\s*=\s*(?:async\s*)?\([^)]*\)\s*=>/g,
|
|
73
|
+
/let\s+(\w+)\s*=\s*(?:async\s*)?\([^)]*\)\s*=>/g,
|
|
74
|
+
/(?:async\s+)?(?:public|private|protected)?\s+(\w+)\s*\([^)]*\)\s*[:{]/g,
|
|
75
|
+
/(\w+)\s*:\s*(?:async\s*)?\([^)]*\)\s*=>/g,
|
|
76
|
+
/def\s+(\w+)\s*\(/g, // Python
|
|
77
|
+
/fn\s+(\w+)\s*[<(]/g, // Rust
|
|
78
|
+
/func\s+(\w+)\s*\(/g, // Go
|
|
79
|
+
];
|
|
80
|
+
const funcs = new Set();
|
|
81
|
+
const reserved = new Set(['if', 'for', 'while', 'switch', 'catch', 'try', 'else', 'return', 'new', 'class', 'function', 'async', 'await']);
|
|
82
|
+
for (const pattern of patterns) {
|
|
83
|
+
const regex = new RegExp(pattern.source, pattern.flags);
|
|
84
|
+
let match;
|
|
85
|
+
while ((match = regex.exec(content)) !== null) {
|
|
86
|
+
const name = match[1];
|
|
87
|
+
if (name && !reserved.has(name) && name.length > 1) {
|
|
88
|
+
funcs.add(name);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return Array.from(funcs);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Extract class names from content
|
|
96
|
+
*/
|
|
97
|
+
function extractClasses(content) {
|
|
98
|
+
const patterns = [
|
|
99
|
+
/class\s+(\w+)/g,
|
|
100
|
+
/interface\s+(\w+)/g,
|
|
101
|
+
/type\s+(\w+)\s*=/g,
|
|
102
|
+
/enum\s+(\w+)/g,
|
|
103
|
+
/struct\s+(\w+)/g,
|
|
104
|
+
];
|
|
105
|
+
const classes = new Set();
|
|
106
|
+
for (const pattern of patterns) {
|
|
107
|
+
const regex = new RegExp(pattern.source, pattern.flags);
|
|
108
|
+
let match;
|
|
109
|
+
while ((match = regex.exec(content)) !== null) {
|
|
110
|
+
if (match[1])
|
|
111
|
+
classes.add(match[1]);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return Array.from(classes);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Extract import statements from content
|
|
118
|
+
*/
|
|
119
|
+
function extractImports(content) {
|
|
120
|
+
const patterns = [
|
|
121
|
+
/import\s+.*?from\s+['"]([^'"]+)['"]/g,
|
|
122
|
+
/import\s+['"]([^'"]+)['"]/g,
|
|
123
|
+
/require\s*\(['"]([^'"]+)['"]\)/g,
|
|
124
|
+
/from\s+(\w+)\s+import/g, // Python
|
|
125
|
+
/use\s+(\w+(?:::\w+)*)/g, // Rust
|
|
126
|
+
];
|
|
127
|
+
const imports = [];
|
|
128
|
+
for (const pattern of patterns) {
|
|
129
|
+
const regex = new RegExp(pattern.source, pattern.flags);
|
|
130
|
+
let match;
|
|
131
|
+
while ((match = regex.exec(content)) !== null) {
|
|
132
|
+
if (match[1])
|
|
133
|
+
imports.push(match[1]);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return [...new Set(imports)];
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Extract export statements from content
|
|
140
|
+
*/
|
|
141
|
+
function extractExports(content) {
|
|
142
|
+
const patterns = [
|
|
143
|
+
/export\s+(?:default\s+)?(?:class|function|const|let|var|interface|type|enum)\s+(\w+)/g,
|
|
144
|
+
/export\s*\{\s*([^}]+)\s*\}/g,
|
|
145
|
+
/module\.exports\s*=\s*(\w+)/g,
|
|
146
|
+
/exports\.(\w+)\s*=/g,
|
|
147
|
+
/pub\s+(?:fn|struct|enum|type)\s+(\w+)/g, // Rust
|
|
148
|
+
];
|
|
149
|
+
const exports = [];
|
|
150
|
+
for (const pattern of patterns) {
|
|
151
|
+
const regex = new RegExp(pattern.source, pattern.flags);
|
|
152
|
+
let match;
|
|
153
|
+
while ((match = regex.exec(content)) !== null) {
|
|
154
|
+
if (match[1]) {
|
|
155
|
+
// Handle grouped exports: export { a, b, c }
|
|
156
|
+
const names = match[1].split(',').map(s => s.trim().split(/\s+as\s+/)[0].trim());
|
|
157
|
+
exports.push(...names.filter(n => n && /^\w+$/.test(n)));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return [...new Set(exports)];
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Extract TODO/FIXME comments from content
|
|
165
|
+
*/
|
|
166
|
+
function extractTodos(content) {
|
|
167
|
+
const pattern = /\/\/\s*(TODO|FIXME|HACK|XXX|BUG|NOTE):\s*(.+)/gi;
|
|
168
|
+
const todos = [];
|
|
169
|
+
let match;
|
|
170
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
171
|
+
todos.push(`${match[1]}: ${match[2].trim()}`);
|
|
172
|
+
}
|
|
173
|
+
return todos;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Extract all patterns from a file
|
|
177
|
+
*/
|
|
178
|
+
function extractAllPatterns(filePath, content) {
|
|
179
|
+
try {
|
|
180
|
+
const fileContent = content ?? (fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf-8') : '');
|
|
181
|
+
return {
|
|
182
|
+
file: filePath,
|
|
183
|
+
language: detectLanguage(filePath),
|
|
184
|
+
functions: extractFunctions(fileContent),
|
|
185
|
+
classes: extractClasses(fileContent),
|
|
186
|
+
imports: extractImports(fileContent),
|
|
187
|
+
exports: extractExports(fileContent),
|
|
188
|
+
todos: extractTodos(fileContent),
|
|
189
|
+
variables: [], // Could add variable extraction if needed
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
return {
|
|
194
|
+
file: filePath,
|
|
195
|
+
language: detectLanguage(filePath),
|
|
196
|
+
functions: [],
|
|
197
|
+
classes: [],
|
|
198
|
+
imports: [],
|
|
199
|
+
exports: [],
|
|
200
|
+
todos: [],
|
|
201
|
+
variables: [],
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Extract patterns from multiple files
|
|
207
|
+
*/
|
|
208
|
+
function extractFromFiles(files, maxFiles = 100) {
|
|
209
|
+
return files.slice(0, maxFiles).map(f => extractAllPatterns(f));
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Convert FilePatterns to PatternMatch array (for native-worker compatibility)
|
|
213
|
+
*/
|
|
214
|
+
function toPatternMatches(patterns) {
|
|
215
|
+
const matches = [];
|
|
216
|
+
for (const func of patterns.functions) {
|
|
217
|
+
matches.push({ type: 'function', match: func, file: patterns.file });
|
|
218
|
+
}
|
|
219
|
+
for (const cls of patterns.classes) {
|
|
220
|
+
matches.push({ type: 'class', match: cls, file: patterns.file });
|
|
221
|
+
}
|
|
222
|
+
for (const imp of patterns.imports) {
|
|
223
|
+
matches.push({ type: 'import', match: imp, file: patterns.file });
|
|
224
|
+
}
|
|
225
|
+
for (const exp of patterns.exports) {
|
|
226
|
+
matches.push({ type: 'export', match: exp, file: patterns.file });
|
|
227
|
+
}
|
|
228
|
+
for (const todo of patterns.todos) {
|
|
229
|
+
matches.push({ type: 'todo', match: todo, file: patterns.file });
|
|
230
|
+
}
|
|
231
|
+
return matches;
|
|
232
|
+
}
|
|
233
|
+
exports.default = {
|
|
234
|
+
detectLanguage,
|
|
235
|
+
extractFunctions,
|
|
236
|
+
extractClasses,
|
|
237
|
+
extractImports,
|
|
238
|
+
extractExports,
|
|
239
|
+
extractTodos,
|
|
240
|
+
extractAllPatterns,
|
|
241
|
+
extractFromFiles,
|
|
242
|
+
toPatternMatches,
|
|
243
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security Analysis Module - Consolidated security scanning
|
|
3
|
+
*
|
|
4
|
+
* Single source of truth for security patterns and vulnerability detection.
|
|
5
|
+
* Used by native-worker.ts and parallel-workers.ts
|
|
6
|
+
*/
|
|
7
|
+
export interface SecurityPattern {
|
|
8
|
+
pattern: RegExp;
|
|
9
|
+
rule: string;
|
|
10
|
+
severity: 'low' | 'medium' | 'high' | 'critical';
|
|
11
|
+
message: string;
|
|
12
|
+
suggestion?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface SecurityFinding {
|
|
15
|
+
file: string;
|
|
16
|
+
line: number;
|
|
17
|
+
severity: 'low' | 'medium' | 'high' | 'critical';
|
|
18
|
+
rule: string;
|
|
19
|
+
message: string;
|
|
20
|
+
match?: string;
|
|
21
|
+
suggestion?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Default security patterns for vulnerability detection
|
|
25
|
+
*/
|
|
26
|
+
export declare const SECURITY_PATTERNS: SecurityPattern[];
|
|
27
|
+
/**
|
|
28
|
+
* Scan a single file for security issues
|
|
29
|
+
*/
|
|
30
|
+
export declare function scanFile(filePath: string, content?: string, patterns?: SecurityPattern[]): SecurityFinding[];
|
|
31
|
+
/**
|
|
32
|
+
* Scan multiple files for security issues
|
|
33
|
+
*/
|
|
34
|
+
export declare function scanFiles(files: string[], patterns?: SecurityPattern[], maxFiles?: number): SecurityFinding[];
|
|
35
|
+
/**
|
|
36
|
+
* Get severity score (for sorting/filtering)
|
|
37
|
+
*/
|
|
38
|
+
export declare function getSeverityScore(severity: string): number;
|
|
39
|
+
/**
|
|
40
|
+
* Sort findings by severity (highest first)
|
|
41
|
+
*/
|
|
42
|
+
export declare function sortBySeverity(findings: SecurityFinding[]): SecurityFinding[];
|
|
43
|
+
declare const _default: {
|
|
44
|
+
SECURITY_PATTERNS: SecurityPattern[];
|
|
45
|
+
scanFile: typeof scanFile;
|
|
46
|
+
scanFiles: typeof scanFiles;
|
|
47
|
+
getSeverityScore: typeof getSeverityScore;
|
|
48
|
+
sortBySeverity: typeof sortBySeverity;
|
|
49
|
+
};
|
|
50
|
+
export default _default;
|
|
51
|
+
//# sourceMappingURL=security.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../src/analysis/security.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAC;IACjD,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAC;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,EAAE,eAAe,EA0B9C,CAAC;AAEF;;GAEG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,EAChB,QAAQ,GAAE,eAAe,EAAsB,GAC9C,eAAe,EAAE,CA4BnB;AAED;;GAEG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,MAAM,EAAE,EACf,QAAQ,GAAE,eAAe,EAAsB,EAC/C,QAAQ,GAAE,MAAY,GACrB,eAAe,EAAE,CAQnB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAQzD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,eAAe,EAAE,GAAG,eAAe,EAAE,CAE7E;;;;;;;;AAED,wBAME"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Security Analysis Module - Consolidated security scanning
|
|
4
|
+
*
|
|
5
|
+
* Single source of truth for security patterns and vulnerability detection.
|
|
6
|
+
* Used by native-worker.ts and parallel-workers.ts
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.SECURITY_PATTERNS = void 0;
|
|
43
|
+
exports.scanFile = scanFile;
|
|
44
|
+
exports.scanFiles = scanFiles;
|
|
45
|
+
exports.getSeverityScore = getSeverityScore;
|
|
46
|
+
exports.sortBySeverity = sortBySeverity;
|
|
47
|
+
const fs = __importStar(require("fs"));
|
|
48
|
+
/**
|
|
49
|
+
* Default security patterns for vulnerability detection
|
|
50
|
+
*/
|
|
51
|
+
exports.SECURITY_PATTERNS = [
|
|
52
|
+
// Critical: Hardcoded secrets
|
|
53
|
+
{ pattern: /password\s*=\s*['"][^'"]+['"]/gi, rule: 'no-hardcoded-password', severity: 'critical', message: 'Hardcoded password detected', suggestion: 'Use environment variables or secret management' },
|
|
54
|
+
{ pattern: /api[_-]?key\s*=\s*['"][^'"]+['"]/gi, rule: 'no-hardcoded-apikey', severity: 'critical', message: 'Hardcoded API key detected', suggestion: 'Use environment variables' },
|
|
55
|
+
{ pattern: /secret\s*=\s*['"][^'"]+['"]/gi, rule: 'no-hardcoded-secret', severity: 'critical', message: 'Hardcoded secret detected', suggestion: 'Use environment variables or secret management' },
|
|
56
|
+
{ pattern: /private[_-]?key\s*=\s*['"][^'"]+['"]/gi, rule: 'no-hardcoded-private-key', severity: 'critical', message: 'Hardcoded private key detected', suggestion: 'Use secure key management' },
|
|
57
|
+
// High: Code execution risks
|
|
58
|
+
{ pattern: /eval\s*\(/g, rule: 'no-eval', severity: 'high', message: 'Avoid eval() - code injection risk', suggestion: 'Use safer alternatives like JSON.parse()' },
|
|
59
|
+
{ pattern: /exec\s*\(/g, rule: 'no-exec', severity: 'high', message: 'Avoid exec() - command injection risk', suggestion: 'Use execFile or spawn with args array' },
|
|
60
|
+
{ pattern: /Function\s*\(/g, rule: 'no-function-constructor', severity: 'high', message: 'Avoid Function constructor - code injection risk' },
|
|
61
|
+
{ pattern: /child_process.*exec\(/g, rule: 'no-shell-exec', severity: 'high', message: 'Shell execution detected', suggestion: 'Use execFile or spawn instead' },
|
|
62
|
+
// High: SQL injection
|
|
63
|
+
{ pattern: /SELECT\s+.*\s+FROM.*\+/gi, rule: 'sql-injection-risk', severity: 'high', message: 'Potential SQL injection - string concatenation in query', suggestion: 'Use parameterized queries' },
|
|
64
|
+
{ pattern: /`SELECT.*\$\{/gi, rule: 'sql-injection-template', severity: 'high', message: 'Template literal in SQL query', suggestion: 'Use parameterized queries' },
|
|
65
|
+
// Medium: XSS risks
|
|
66
|
+
{ pattern: /dangerouslySetInnerHTML/g, rule: 'xss-risk', severity: 'medium', message: 'XSS risk: dangerouslySetInnerHTML', suggestion: 'Sanitize content before rendering' },
|
|
67
|
+
{ pattern: /innerHTML\s*=/g, rule: 'no-inner-html', severity: 'medium', message: 'Avoid innerHTML - XSS risk', suggestion: 'Use textContent or sanitize content' },
|
|
68
|
+
{ pattern: /document\.write\s*\(/g, rule: 'no-document-write', severity: 'medium', message: 'Avoid document.write - XSS risk' },
|
|
69
|
+
// Medium: Other risks
|
|
70
|
+
{ pattern: /\$\{.*\}/g, rule: 'template-injection', severity: 'low', message: 'Template literal detected - verify no injection' },
|
|
71
|
+
{ pattern: /new\s+RegExp\s*\([^)]*\+/g, rule: 'regex-injection', severity: 'medium', message: 'Dynamic RegExp - potential ReDoS risk', suggestion: 'Validate/sanitize regex input' },
|
|
72
|
+
{ pattern: /\.on\s*\(\s*['"]error['"]/g, rule: 'unhandled-error', severity: 'low', message: 'Error handler detected - verify proper error handling' },
|
|
73
|
+
];
|
|
74
|
+
/**
|
|
75
|
+
* Scan a single file for security issues
|
|
76
|
+
*/
|
|
77
|
+
function scanFile(filePath, content, patterns = exports.SECURITY_PATTERNS) {
|
|
78
|
+
const findings = [];
|
|
79
|
+
try {
|
|
80
|
+
const fileContent = content ?? (fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf-8') : '');
|
|
81
|
+
if (!fileContent)
|
|
82
|
+
return findings;
|
|
83
|
+
for (const { pattern, rule, severity, message, suggestion } of patterns) {
|
|
84
|
+
const regex = new RegExp(pattern.source, pattern.flags);
|
|
85
|
+
let match;
|
|
86
|
+
while ((match = regex.exec(fileContent)) !== null) {
|
|
87
|
+
const lineNum = fileContent.slice(0, match.index).split('\n').length;
|
|
88
|
+
findings.push({
|
|
89
|
+
file: filePath,
|
|
90
|
+
line: lineNum,
|
|
91
|
+
severity,
|
|
92
|
+
rule,
|
|
93
|
+
message,
|
|
94
|
+
match: match[0].slice(0, 50),
|
|
95
|
+
suggestion,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
// Skip unreadable files
|
|
102
|
+
}
|
|
103
|
+
return findings;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Scan multiple files for security issues
|
|
107
|
+
*/
|
|
108
|
+
function scanFiles(files, patterns = exports.SECURITY_PATTERNS, maxFiles = 100) {
|
|
109
|
+
const findings = [];
|
|
110
|
+
for (const file of files.slice(0, maxFiles)) {
|
|
111
|
+
findings.push(...scanFile(file, undefined, patterns));
|
|
112
|
+
}
|
|
113
|
+
return findings;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Get severity score (for sorting/filtering)
|
|
117
|
+
*/
|
|
118
|
+
function getSeverityScore(severity) {
|
|
119
|
+
switch (severity) {
|
|
120
|
+
case 'critical': return 4;
|
|
121
|
+
case 'high': return 3;
|
|
122
|
+
case 'medium': return 2;
|
|
123
|
+
case 'low': return 1;
|
|
124
|
+
default: return 0;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Sort findings by severity (highest first)
|
|
129
|
+
*/
|
|
130
|
+
function sortBySeverity(findings) {
|
|
131
|
+
return [...findings].sort((a, b) => getSeverityScore(b.severity) - getSeverityScore(a.severity));
|
|
132
|
+
}
|
|
133
|
+
exports.default = {
|
|
134
|
+
SECURITY_PATTERNS: exports.SECURITY_PATTERNS,
|
|
135
|
+
scanFile,
|
|
136
|
+
scanFiles,
|
|
137
|
+
getSeverityScore,
|
|
138
|
+
sortBySeverity,
|
|
139
|
+
};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AdaptiveEmbedder - Micro-LoRA Style Optimization for ONNX Embeddings
|
|
3
|
+
*
|
|
4
|
+
* Applies continual learning techniques to frozen ONNX embeddings:
|
|
5
|
+
*
|
|
6
|
+
* 1. MICRO-LORA ADAPTERS
|
|
7
|
+
* - Low-rank projection layers (rank 2-8) on top of frozen embeddings
|
|
8
|
+
* - Domain-specific fine-tuning with minimal parameters
|
|
9
|
+
* - ~0.1% of base model parameters
|
|
10
|
+
*
|
|
11
|
+
* 2. CONTRASTIVE LEARNING
|
|
12
|
+
* - Files edited together → embeddings closer
|
|
13
|
+
* - Semantic clustering from trajectories
|
|
14
|
+
* - Online learning from user behavior
|
|
15
|
+
*
|
|
16
|
+
* 3. EWC++ (Elastic Weight Consolidation)
|
|
17
|
+
* - Prevents catastrophic forgetting
|
|
18
|
+
* - Consolidates important adaptations
|
|
19
|
+
* - Fisher information regularization
|
|
20
|
+
*
|
|
21
|
+
* 4. MEMORY-AUGMENTED RETRIEVAL
|
|
22
|
+
* - Episodic memory for context-aware embeddings
|
|
23
|
+
* - Attention over past similar embeddings
|
|
24
|
+
* - Domain prototype learning
|
|
25
|
+
*
|
|
26
|
+
* Architecture:
|
|
27
|
+
* ONNX(text) → [frozen 384d] → LoRA_A → LoRA_B → [adapted 384d]
|
|
28
|
+
* (384×r) (r×384)
|
|
29
|
+
*/
|
|
30
|
+
export interface AdaptiveConfig {
|
|
31
|
+
/** LoRA rank (lower = fewer params, higher = more expressive) */
|
|
32
|
+
loraRank?: number;
|
|
33
|
+
/** Learning rate for online updates */
|
|
34
|
+
learningRate?: number;
|
|
35
|
+
/** EWC regularization strength */
|
|
36
|
+
ewcLambda?: number;
|
|
37
|
+
/** Number of domain prototypes to maintain */
|
|
38
|
+
numPrototypes?: number;
|
|
39
|
+
/** Enable contrastive learning from co-edits */
|
|
40
|
+
contrastiveLearning?: boolean;
|
|
41
|
+
/** Temperature for contrastive loss */
|
|
42
|
+
contrastiveTemp?: number;
|
|
43
|
+
/** Memory capacity for episodic retrieval */
|
|
44
|
+
memoryCapacity?: number;
|
|
45
|
+
}
|
|
46
|
+
export interface LoRAWeights {
|
|
47
|
+
A: number[][];
|
|
48
|
+
B: number[][];
|
|
49
|
+
bias?: number[];
|
|
50
|
+
}
|
|
51
|
+
export interface DomainPrototype {
|
|
52
|
+
domain: string;
|
|
53
|
+
centroid: number[];
|
|
54
|
+
count: number;
|
|
55
|
+
variance: number;
|
|
56
|
+
}
|
|
57
|
+
export interface AdaptiveStats {
|
|
58
|
+
baseModel: string;
|
|
59
|
+
dimension: number;
|
|
60
|
+
loraRank: number;
|
|
61
|
+
loraParams: number;
|
|
62
|
+
adaptations: number;
|
|
63
|
+
prototypes: number;
|
|
64
|
+
memorySize: number;
|
|
65
|
+
ewcConsolidations: number;
|
|
66
|
+
contrastiveUpdates: number;
|
|
67
|
+
}
|
|
68
|
+
export declare class AdaptiveEmbedder {
|
|
69
|
+
private config;
|
|
70
|
+
private lora;
|
|
71
|
+
private prototypes;
|
|
72
|
+
private episodic;
|
|
73
|
+
private onnxReady;
|
|
74
|
+
private dimension;
|
|
75
|
+
private adaptationCount;
|
|
76
|
+
private ewcCount;
|
|
77
|
+
private contrastiveCount;
|
|
78
|
+
private coEditBuffer;
|
|
79
|
+
constructor(config?: AdaptiveConfig);
|
|
80
|
+
/**
|
|
81
|
+
* Initialize ONNX backend
|
|
82
|
+
*/
|
|
83
|
+
init(): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Generate adaptive embedding
|
|
86
|
+
* Pipeline: ONNX → LoRA → Prototype Adjustment → Episodic Augmentation
|
|
87
|
+
*/
|
|
88
|
+
embed(text: string, options?: {
|
|
89
|
+
domain?: string;
|
|
90
|
+
useEpisodic?: boolean;
|
|
91
|
+
storeInMemory?: boolean;
|
|
92
|
+
}): Promise<number[]>;
|
|
93
|
+
/**
|
|
94
|
+
* Batch embed with adaptation
|
|
95
|
+
*/
|
|
96
|
+
embedBatch(texts: string[], options?: {
|
|
97
|
+
domain?: string;
|
|
98
|
+
}): Promise<number[][]>;
|
|
99
|
+
/**
|
|
100
|
+
* Learn from co-edit pattern (contrastive learning)
|
|
101
|
+
* Files edited together should have similar embeddings
|
|
102
|
+
*/
|
|
103
|
+
learnCoEdit(file1: string, content1: string, file2: string, content2: string): Promise<number>;
|
|
104
|
+
/**
|
|
105
|
+
* Process co-edit batch with contrastive loss
|
|
106
|
+
*/
|
|
107
|
+
private processCoEditBatch;
|
|
108
|
+
/**
|
|
109
|
+
* Learn from trajectory outcome (reinforcement-like)
|
|
110
|
+
*/
|
|
111
|
+
learnFromOutcome(context: string, action: string, success: boolean, quality?: number): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* EWC consolidation - prevent forgetting important adaptations
|
|
114
|
+
*/
|
|
115
|
+
consolidate(): Promise<void>;
|
|
116
|
+
/**
|
|
117
|
+
* Fallback hash embedding
|
|
118
|
+
*/
|
|
119
|
+
private hashEmbed;
|
|
120
|
+
private normalize;
|
|
121
|
+
/**
|
|
122
|
+
* Get statistics
|
|
123
|
+
*/
|
|
124
|
+
getStats(): AdaptiveStats;
|
|
125
|
+
/**
|
|
126
|
+
* Export learned weights
|
|
127
|
+
*/
|
|
128
|
+
export(): {
|
|
129
|
+
lora: LoRAWeights;
|
|
130
|
+
prototypes: DomainPrototype[];
|
|
131
|
+
stats: AdaptiveStats;
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Import learned weights
|
|
135
|
+
*/
|
|
136
|
+
import(data: {
|
|
137
|
+
lora?: LoRAWeights;
|
|
138
|
+
prototypes?: DomainPrototype[];
|
|
139
|
+
}): void;
|
|
140
|
+
/**
|
|
141
|
+
* Reset adaptations
|
|
142
|
+
*/
|
|
143
|
+
reset(): void;
|
|
144
|
+
}
|
|
145
|
+
export declare function getAdaptiveEmbedder(config?: AdaptiveConfig): AdaptiveEmbedder;
|
|
146
|
+
export declare function initAdaptiveEmbedder(config?: AdaptiveConfig): Promise<AdaptiveEmbedder>;
|
|
147
|
+
export default AdaptiveEmbedder;
|
|
148
|
+
//# sourceMappingURL=adaptive-embedder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adaptive-embedder.d.ts","sourceRoot":"","sources":["../../src/core/adaptive-embedder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAQH,MAAM,WAAW,cAAc;IAC7B,iEAAiE;IACjE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uCAAuC;IACvC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kCAAkC;IAClC,SAAS,CAAC,EAAE,M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