ruvector 0.2.23 → 0.2.25
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 +211 -63
- 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 +156 -0
- package/dist/core/adaptive-embedder.d.ts.map +1 -0
- package/dist/core/adaptive-embedder.js +838 -0
- package/dist/core/agentdb-fast.d.ts +149 -0
- package/dist/core/agentdb-fast.d.ts.map +1 -0
- package/dist/core/agentdb-fast.js +301 -0
- package/dist/core/ast-parser.d.ts +108 -0
- package/dist/core/ast-parser.d.ts.map +1 -0
- package/dist/core/ast-parser.js +602 -0
- package/dist/core/attention-fallbacks.d.ts +321 -0
- package/dist/core/attention-fallbacks.d.ts.map +1 -0
- package/dist/core/attention-fallbacks.js +552 -0
- package/dist/core/cluster-wrapper.d.ts +148 -0
- package/dist/core/cluster-wrapper.d.ts.map +1 -0
- package/dist/core/cluster-wrapper.js +271 -0
- package/dist/core/coverage-router.d.ts +88 -0
- package/dist/core/coverage-router.d.ts.map +1 -0
- package/dist/core/coverage-router.js +315 -0
- package/dist/core/diff-embeddings.d.ts +93 -0
- package/dist/core/diff-embeddings.d.ts.map +1 -0
- package/dist/core/diff-embeddings.js +334 -0
- package/dist/core/diskann-wrapper.d.ts +53 -0
- package/dist/core/diskann-wrapper.d.ts.map +1 -0
- package/dist/core/diskann-wrapper.js +105 -0
- package/dist/core/gnn-wrapper.d.ts +143 -0
- package/dist/core/gnn-wrapper.d.ts.map +1 -0
- package/dist/core/gnn-wrapper.js +213 -0
- package/dist/core/graph-algorithms.d.ts +83 -0
- package/dist/core/graph-algorithms.d.ts.map +1 -0
- package/dist/core/graph-algorithms.js +514 -0
- package/dist/core/graph-wrapper.d.ts +147 -0
- package/dist/core/graph-wrapper.d.ts.map +1 -0
- package/dist/core/graph-wrapper.js +299 -0
- package/dist/core/index.d.ts +50 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +92 -0
- package/dist/core/intelligence-engine.d.ts +258 -0
- package/dist/core/intelligence-engine.d.ts.map +1 -0
- package/dist/core/intelligence-engine.js +1030 -0
- 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/neural-embeddings.d.ts +393 -0
- package/dist/core/neural-embeddings.d.ts.map +1 -0
- package/dist/core/neural-embeddings.js +1091 -0
- package/dist/core/neural-perf.d.ts +331 -0
- package/dist/core/neural-perf.d.ts.map +1 -0
- package/dist/core/neural-perf.js +704 -0
- package/dist/core/onnx/pkg/package.json +3 -0
- package/dist/core/onnx-embedder.d.ts +105 -0
- package/dist/core/onnx-embedder.d.ts.map +1 -0
- package/dist/core/onnx-embedder.js +410 -0
- package/dist/core/onnx-optimized.d.ts +109 -0
- package/dist/core/onnx-optimized.d.ts.map +1 -0
- package/dist/core/onnx-optimized.js +419 -0
- package/dist/core/parallel-intelligence.d.ts +109 -0
- package/dist/core/parallel-intelligence.d.ts.map +1 -0
- package/dist/core/parallel-intelligence.js +340 -0
- package/dist/core/parallel-workers.d.ts +177 -0
- package/dist/core/parallel-workers.d.ts.map +1 -0
- package/dist/core/parallel-workers.js +783 -0
- package/dist/core/router-wrapper.d.ts +75 -0
- package/dist/core/router-wrapper.d.ts.map +1 -0
- package/dist/core/router-wrapper.js +243 -0
- package/dist/core/rvf-wrapper.d.ts +86 -0
- package/dist/core/rvf-wrapper.d.ts.map +1 -0
- package/dist/core/rvf-wrapper.js +102 -0
- package/dist/core/sona-wrapper.d.ts +226 -0
- package/dist/core/sona-wrapper.d.ts.map +1 -0
- package/dist/core/sona-wrapper.js +282 -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/dist/index.d.ts +106 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +258 -0
- package/dist/services/embedding-service.d.ts +136 -0
- package/dist/services/embedding-service.d.ts.map +1 -0
- package/dist/services/embedding-service.js +294 -0
- package/dist/services/index.d.ts +6 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +26 -0
- package/dist/types.d.ts +145 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -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 +490 -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 +8 -7
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/analysis/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAG3B,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Analysis Module - Consolidated code analysis utilities
|
|
4
|
+
*
|
|
5
|
+
* Single source of truth for:
|
|
6
|
+
* - Security scanning
|
|
7
|
+
* - Complexity analysis
|
|
8
|
+
* - Pattern extraction
|
|
9
|
+
*/
|
|
10
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
13
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
14
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
17
|
+
}) : (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
o[k2] = m[k];
|
|
20
|
+
}));
|
|
21
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
22
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
23
|
+
};
|
|
24
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
25
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.patterns = exports.complexity = exports.security = void 0;
|
|
29
|
+
__exportStar(require("./security"), exports);
|
|
30
|
+
__exportStar(require("./complexity"), exports);
|
|
31
|
+
__exportStar(require("./patterns"), exports);
|
|
32
|
+
// Re-export defaults for convenience
|
|
33
|
+
var security_1 = require("./security");
|
|
34
|
+
Object.defineProperty(exports, "security", { enumerable: true, get: function () { return __importDefault(security_1).default; } });
|
|
35
|
+
var complexity_1 = require("./complexity");
|
|
36
|
+
Object.defineProperty(exports, "complexity", { enumerable: true, get: function () { return __importDefault(complexity_1).default; } });
|
|
37
|
+
var patterns_1 = require("./patterns");
|
|
38
|
+
Object.defineProperty(exports, "patterns", { enumerable: true, get: function () { return __importDefault(patterns_1).default; } });
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pattern Extraction Module - Consolidated code pattern detection
|
|
3
|
+
*
|
|
4
|
+
* Single source of truth for extracting functions, imports, exports, etc.
|
|
5
|
+
* Used by native-worker.ts and parallel-workers.ts
|
|
6
|
+
*/
|
|
7
|
+
export interface PatternMatch {
|
|
8
|
+
type: 'function' | 'class' | 'import' | 'export' | 'todo' | 'variable' | 'type';
|
|
9
|
+
match: string;
|
|
10
|
+
file: string;
|
|
11
|
+
line?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface FilePatterns {
|
|
14
|
+
file: string;
|
|
15
|
+
language: string;
|
|
16
|
+
functions: string[];
|
|
17
|
+
classes: string[];
|
|
18
|
+
imports: string[];
|
|
19
|
+
exports: string[];
|
|
20
|
+
todos: string[];
|
|
21
|
+
variables: string[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Detect language from file extension
|
|
25
|
+
*/
|
|
26
|
+
export declare function detectLanguage(file: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Extract function names from content
|
|
29
|
+
*/
|
|
30
|
+
export declare function extractFunctions(content: string): string[];
|
|
31
|
+
/**
|
|
32
|
+
* Extract class names from content
|
|
33
|
+
*/
|
|
34
|
+
export declare function extractClasses(content: string): string[];
|
|
35
|
+
/**
|
|
36
|
+
* Extract import statements from content
|
|
37
|
+
*/
|
|
38
|
+
export declare function extractImports(content: string): string[];
|
|
39
|
+
/**
|
|
40
|
+
* Extract export statements from content
|
|
41
|
+
*/
|
|
42
|
+
export declare function extractExports(content: string): string[];
|
|
43
|
+
/**
|
|
44
|
+
* Extract TODO/FIXME comments from content
|
|
45
|
+
*/
|
|
46
|
+
export declare function extractTodos(content: string): string[];
|
|
47
|
+
/**
|
|
48
|
+
* Extract all patterns from a file
|
|
49
|
+
*/
|
|
50
|
+
export declare function extractAllPatterns(filePath: string, content?: string): FilePatterns;
|
|
51
|
+
/**
|
|
52
|
+
* Extract patterns from multiple files
|
|
53
|
+
*/
|
|
54
|
+
export declare function extractFromFiles(files: string[], maxFiles?: number): FilePatterns[];
|
|
55
|
+
/**
|
|
56
|
+
* Convert FilePatterns to PatternMatch array (for native-worker compatibility)
|
|
57
|
+
*/
|
|
58
|
+
export declare function toPatternMatches(patterns: FilePatterns): PatternMatch[];
|
|
59
|
+
declare const _default: {
|
|
60
|
+
detectLanguage: typeof detectLanguage;
|
|
61
|
+
extractFunctions: typeof extractFunctions;
|
|
62
|
+
extractClasses: typeof extractClasses;
|
|
63
|
+
extractImports: typeof extractImports;
|
|
64
|
+
extractExports: typeof extractExports;
|
|
65
|
+
extractTodos: typeof extractTodos;
|
|
66
|
+
extractAllPatterns: typeof extractAllPatterns;
|
|
67
|
+
extractFromFiles: typeof extractFromFiles;
|
|
68
|
+
toPatternMatches: typeof toPatternMatches;
|
|
69
|
+
};
|
|
70
|
+
export default _default;
|
|
71
|
+
//# sourceMappingURL=patterns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patterns.d.ts","sourceRoot":"","sources":["../../src/analysis/patterns.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,UAAU,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,CAAC;IAChF,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAUnD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CA2B1D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAmBxD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAmBxD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAuBxD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAUtD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,YAAY,CA0BnF;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,QAAQ,GAAE,MAAY,GAAG,YAAY,EAAE,CAExF;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,YAAY,GAAG,YAAY,EAAE,CAoBvE;;;;;;;;;;;;AAED,wBAUE"}
|
|
@@ -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
|
+
};
|