ruvector 0.1.80 → 0.1.81

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.
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Complexity Analysis Module - Consolidated code complexity metrics
3
+ *
4
+ * Single source of truth for cyclomatic complexity and code metrics.
5
+ * Used by native-worker.ts and parallel-workers.ts
6
+ */
7
+ export interface ComplexityResult {
8
+ file: string;
9
+ lines: number;
10
+ nonEmptyLines: number;
11
+ cyclomaticComplexity: number;
12
+ functions: number;
13
+ avgFunctionSize: number;
14
+ maxFunctionComplexity?: number;
15
+ }
16
+ export interface ComplexityThresholds {
17
+ complexity: number;
18
+ functions: number;
19
+ lines: number;
20
+ avgSize: number;
21
+ }
22
+ export declare const DEFAULT_THRESHOLDS: ComplexityThresholds;
23
+ /**
24
+ * Analyze complexity of a single file
25
+ */
26
+ export declare function analyzeFile(filePath: string, content?: string): ComplexityResult;
27
+ /**
28
+ * Analyze complexity of multiple files
29
+ */
30
+ export declare function analyzeFiles(files: string[], maxFiles?: number): ComplexityResult[];
31
+ /**
32
+ * Check if complexity exceeds thresholds
33
+ */
34
+ export declare function exceedsThresholds(result: ComplexityResult, thresholds?: ComplexityThresholds): boolean;
35
+ /**
36
+ * Get complexity rating
37
+ */
38
+ export declare function getComplexityRating(complexity: number): 'low' | 'medium' | 'high' | 'critical';
39
+ /**
40
+ * Filter files exceeding thresholds
41
+ */
42
+ export declare function filterComplex(results: ComplexityResult[], thresholds?: ComplexityThresholds): ComplexityResult[];
43
+ declare const _default: {
44
+ DEFAULT_THRESHOLDS: ComplexityThresholds;
45
+ analyzeFile: typeof analyzeFile;
46
+ analyzeFiles: typeof analyzeFiles;
47
+ exceedsThresholds: typeof exceedsThresholds;
48
+ getComplexityRating: typeof getComplexityRating;
49
+ filterComplex: typeof filterComplex;
50
+ };
51
+ export default _default;
52
+ //# sourceMappingURL=complexity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"complexity.d.ts","sourceRoot":"","sources":["../../src/analysis/complexity.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,oBAAoB;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,kBAAkB,EAAE,oBAKhC,CAAC;AAEF;;GAEG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAsDhF;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,QAAQ,GAAE,MAAY,GAAG,gBAAgB,EAAE,CAExF;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,gBAAgB,EACxB,UAAU,GAAE,oBAAyC,GACpD,OAAO,CAOT;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,CAK9F;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,gBAAgB,EAAE,EAC3B,UAAU,GAAE,oBAAyC,GACpD,gBAAgB,EAAE,CAEpB;;;;;;;;;AAED,wBAOE"}
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ /**
3
+ * Complexity Analysis Module - Consolidated code complexity metrics
4
+ *
5
+ * Single source of truth for cyclomatic complexity and code metrics.
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.DEFAULT_THRESHOLDS = void 0;
43
+ exports.analyzeFile = analyzeFile;
44
+ exports.analyzeFiles = analyzeFiles;
45
+ exports.exceedsThresholds = exceedsThresholds;
46
+ exports.getComplexityRating = getComplexityRating;
47
+ exports.filterComplex = filterComplex;
48
+ const fs = __importStar(require("fs"));
49
+ exports.DEFAULT_THRESHOLDS = {
50
+ complexity: 10,
51
+ functions: 30,
52
+ lines: 500,
53
+ avgSize: 50,
54
+ };
55
+ /**
56
+ * Analyze complexity of a single file
57
+ */
58
+ function analyzeFile(filePath, content) {
59
+ try {
60
+ const fileContent = content ?? (fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf-8') : '');
61
+ if (!fileContent) {
62
+ return { file: filePath, lines: 0, nonEmptyLines: 0, cyclomaticComplexity: 1, functions: 0, avgFunctionSize: 0 };
63
+ }
64
+ const lines = fileContent.split('\n');
65
+ const nonEmptyLines = lines.filter(l => l.trim().length > 0).length;
66
+ // Count branching statements for cyclomatic complexity
67
+ const branches = (fileContent.match(/\bif\b/g)?.length || 0) +
68
+ (fileContent.match(/\belse\b/g)?.length || 0) +
69
+ (fileContent.match(/\bfor\b/g)?.length || 0) +
70
+ (fileContent.match(/\bwhile\b/g)?.length || 0) +
71
+ (fileContent.match(/\bswitch\b/g)?.length || 0) +
72
+ (fileContent.match(/\bcase\b/g)?.length || 0) +
73
+ (fileContent.match(/\bcatch\b/g)?.length || 0) +
74
+ (fileContent.match(/\?\?/g)?.length || 0) +
75
+ (fileContent.match(/&&/g)?.length || 0) +
76
+ (fileContent.match(/\|\|/g)?.length || 0) +
77
+ (fileContent.match(/\?[^:]/g)?.length || 0); // Ternary
78
+ const cyclomaticComplexity = branches + 1;
79
+ // Count functions
80
+ const functionPatterns = [
81
+ /function\s+\w+/g,
82
+ /\w+\s*=\s*(?:async\s*)?\(/g,
83
+ /\w+\s*:\s*(?:async\s*)?\(/g,
84
+ /(?:async\s+)?(?:public|private|protected)?\s+\w+\s*\([^)]*\)\s*[:{]/g,
85
+ ];
86
+ let functions = 0;
87
+ for (const pattern of functionPatterns) {
88
+ functions += (fileContent.match(pattern) || []).length;
89
+ }
90
+ // Deduplicate by rough estimate
91
+ functions = Math.ceil(functions / 2);
92
+ const avgFunctionSize = functions > 0 ? Math.round(nonEmptyLines / functions) : nonEmptyLines;
93
+ return {
94
+ file: filePath,
95
+ lines: lines.length,
96
+ nonEmptyLines,
97
+ cyclomaticComplexity,
98
+ functions,
99
+ avgFunctionSize,
100
+ };
101
+ }
102
+ catch {
103
+ return { file: filePath, lines: 0, nonEmptyLines: 0, cyclomaticComplexity: 1, functions: 0, avgFunctionSize: 0 };
104
+ }
105
+ }
106
+ /**
107
+ * Analyze complexity of multiple files
108
+ */
109
+ function analyzeFiles(files, maxFiles = 100) {
110
+ return files.slice(0, maxFiles).map(f => analyzeFile(f));
111
+ }
112
+ /**
113
+ * Check if complexity exceeds thresholds
114
+ */
115
+ function exceedsThresholds(result, thresholds = exports.DEFAULT_THRESHOLDS) {
116
+ return (result.cyclomaticComplexity > thresholds.complexity ||
117
+ result.functions > thresholds.functions ||
118
+ result.lines > thresholds.lines ||
119
+ result.avgFunctionSize > thresholds.avgSize);
120
+ }
121
+ /**
122
+ * Get complexity rating
123
+ */
124
+ function getComplexityRating(complexity) {
125
+ if (complexity <= 5)
126
+ return 'low';
127
+ if (complexity <= 10)
128
+ return 'medium';
129
+ if (complexity <= 20)
130
+ return 'high';
131
+ return 'critical';
132
+ }
133
+ /**
134
+ * Filter files exceeding thresholds
135
+ */
136
+ function filterComplex(results, thresholds = exports.DEFAULT_THRESHOLDS) {
137
+ return results.filter(r => exceedsThresholds(r, thresholds));
138
+ }
139
+ exports.default = {
140
+ DEFAULT_THRESHOLDS: exports.DEFAULT_THRESHOLDS,
141
+ analyzeFile,
142
+ analyzeFiles,
143
+ exceedsThresholds,
144
+ getComplexityRating,
145
+ filterComplex,
146
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Analysis Module - Consolidated code analysis utilities
3
+ *
4
+ * Single source of truth for:
5
+ * - Security scanning
6
+ * - Complexity analysis
7
+ * - Pattern extraction
8
+ */
9
+ export * from './security';
10
+ export * from './complexity';
11
+ export * from './patterns';
12
+ export { default as security } from './security';
13
+ export { default as complexity } from './complexity';
14
+ export { default as patterns } from './patterns';
15
+ //# sourceMappingURL=index.d.ts.map
@@ -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"}