archicore 0.1.0

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.
Files changed (118) hide show
  1. package/README.md +530 -0
  2. package/dist/analyzers/dead-code.d.ts +95 -0
  3. package/dist/analyzers/dead-code.js +327 -0
  4. package/dist/analyzers/duplication.d.ts +90 -0
  5. package/dist/analyzers/duplication.js +344 -0
  6. package/dist/analyzers/security.d.ts +79 -0
  7. package/dist/analyzers/security.js +484 -0
  8. package/dist/architecture/index.d.ts +35 -0
  9. package/dist/architecture/index.js +249 -0
  10. package/dist/cli/commands/analyzers.d.ts +6 -0
  11. package/dist/cli/commands/analyzers.js +431 -0
  12. package/dist/cli/commands/export.d.ts +6 -0
  13. package/dist/cli/commands/export.js +78 -0
  14. package/dist/cli/commands/index.d.ts +8 -0
  15. package/dist/cli/commands/index.js +8 -0
  16. package/dist/cli/commands/init.d.ts +26 -0
  17. package/dist/cli/commands/init.js +140 -0
  18. package/dist/cli/commands/interactive.d.ts +7 -0
  19. package/dist/cli/commands/interactive.js +522 -0
  20. package/dist/cli/commands/projects.d.ts +6 -0
  21. package/dist/cli/commands/projects.js +249 -0
  22. package/dist/cli/index.d.ts +7 -0
  23. package/dist/cli/index.js +7 -0
  24. package/dist/cli/ui/box.d.ts +17 -0
  25. package/dist/cli/ui/box.js +62 -0
  26. package/dist/cli/ui/colors.d.ts +49 -0
  27. package/dist/cli/ui/colors.js +86 -0
  28. package/dist/cli/ui/index.d.ts +9 -0
  29. package/dist/cli/ui/index.js +9 -0
  30. package/dist/cli/ui/prompt.d.ts +34 -0
  31. package/dist/cli/ui/prompt.js +122 -0
  32. package/dist/cli/ui/spinner.d.ts +29 -0
  33. package/dist/cli/ui/spinner.js +80 -0
  34. package/dist/cli/ui/table.d.ts +33 -0
  35. package/dist/cli/ui/table.js +84 -0
  36. package/dist/cli/utils/config.d.ts +23 -0
  37. package/dist/cli/utils/config.js +73 -0
  38. package/dist/cli/utils/index.d.ts +6 -0
  39. package/dist/cli/utils/index.js +6 -0
  40. package/dist/cli/utils/session.d.ts +27 -0
  41. package/dist/cli/utils/session.js +117 -0
  42. package/dist/cli.d.ts +8 -0
  43. package/dist/cli.js +295 -0
  44. package/dist/code-index/ast-parser.d.ts +16 -0
  45. package/dist/code-index/ast-parser.js +330 -0
  46. package/dist/code-index/dependency-graph.d.ts +16 -0
  47. package/dist/code-index/dependency-graph.js +161 -0
  48. package/dist/code-index/index.d.ts +44 -0
  49. package/dist/code-index/index.js +124 -0
  50. package/dist/code-index/symbol-extractor.d.ts +13 -0
  51. package/dist/code-index/symbol-extractor.js +150 -0
  52. package/dist/export/index.d.ts +92 -0
  53. package/dist/export/index.js +676 -0
  54. package/dist/github/github-service.d.ts +146 -0
  55. package/dist/github/github-service.js +609 -0
  56. package/dist/impact-engine/index.d.ts +25 -0
  57. package/dist/impact-engine/index.js +284 -0
  58. package/dist/index.d.ts +60 -0
  59. package/dist/index.js +149 -0
  60. package/dist/metrics/index.d.ts +136 -0
  61. package/dist/metrics/index.js +525 -0
  62. package/dist/orchestrator/deepseek-optimizer.d.ts +67 -0
  63. package/dist/orchestrator/deepseek-optimizer.js +320 -0
  64. package/dist/orchestrator/index.d.ts +34 -0
  65. package/dist/orchestrator/index.js +305 -0
  66. package/dist/pr-guardian/index.d.ts +143 -0
  67. package/dist/pr-guardian/index.js +553 -0
  68. package/dist/refactoring/index.d.ts +108 -0
  69. package/dist/refactoring/index.js +580 -0
  70. package/dist/rules-engine/index.d.ts +129 -0
  71. package/dist/rules-engine/index.js +482 -0
  72. package/dist/semantic-memory/embedding-service.d.ts +24 -0
  73. package/dist/semantic-memory/embedding-service.js +120 -0
  74. package/dist/semantic-memory/index.d.ts +45 -0
  75. package/dist/semantic-memory/index.js +206 -0
  76. package/dist/semantic-memory/vector-store.d.ts +27 -0
  77. package/dist/semantic-memory/vector-store.js +166 -0
  78. package/dist/server/index.d.ts +28 -0
  79. package/dist/server/index.js +141 -0
  80. package/dist/server/middleware/api-auth.d.ts +43 -0
  81. package/dist/server/middleware/api-auth.js +256 -0
  82. package/dist/server/routes/admin.d.ts +5 -0
  83. package/dist/server/routes/admin.js +123 -0
  84. package/dist/server/routes/api.d.ts +7 -0
  85. package/dist/server/routes/api.js +362 -0
  86. package/dist/server/routes/auth.d.ts +16 -0
  87. package/dist/server/routes/auth.js +191 -0
  88. package/dist/server/routes/developer.d.ts +8 -0
  89. package/dist/server/routes/developer.js +439 -0
  90. package/dist/server/routes/github.d.ts +7 -0
  91. package/dist/server/routes/github.js +495 -0
  92. package/dist/server/routes/upload.d.ts +7 -0
  93. package/dist/server/routes/upload.js +196 -0
  94. package/dist/server/services/api-key-service.d.ts +81 -0
  95. package/dist/server/services/api-key-service.js +281 -0
  96. package/dist/server/services/auth-service.d.ts +40 -0
  97. package/dist/server/services/auth-service.js +315 -0
  98. package/dist/server/services/project-service.d.ts +123 -0
  99. package/dist/server/services/project-service.js +533 -0
  100. package/dist/server/services/token-service.d.ts +107 -0
  101. package/dist/server/services/token-service.js +416 -0
  102. package/dist/server/services/upload-service.d.ts +93 -0
  103. package/dist/server/services/upload-service.js +464 -0
  104. package/dist/types/api.d.ts +188 -0
  105. package/dist/types/api.js +86 -0
  106. package/dist/types/github.d.ts +335 -0
  107. package/dist/types/github.js +5 -0
  108. package/dist/types/index.d.ts +265 -0
  109. package/dist/types/index.js +32 -0
  110. package/dist/types/user.d.ts +69 -0
  111. package/dist/types/user.js +42 -0
  112. package/dist/utils/file-utils.d.ts +20 -0
  113. package/dist/utils/file-utils.js +163 -0
  114. package/dist/utils/logger.d.ts +17 -0
  115. package/dist/utils/logger.js +41 -0
  116. package/dist/watcher/index.d.ts +125 -0
  117. package/dist/watcher/index.js +397 -0
  118. package/package.json +71 -0
@@ -0,0 +1,484 @@
1
+ /**
2
+ * Security Analyzer
3
+ *
4
+ * Обнаружение уязвимостей безопасности:
5
+ * - SQL Injection
6
+ * - XSS (Cross-Site Scripting)
7
+ * - Command Injection
8
+ * - Path Traversal
9
+ * - Hardcoded Secrets
10
+ * - Insecure Dependencies
11
+ * - OWASP Top 10
12
+ */
13
+ import { Logger } from '../utils/logger.js';
14
+ export class SecurityAnalyzer {
15
+ vulnerabilityPatterns = [
16
+ // SQL Injection
17
+ {
18
+ type: 'sql-injection',
19
+ pattern: /(?:query|execute|raw)\s*\(\s*[`'"]\s*(?:SELECT|INSERT|UPDATE|DELETE|DROP).*\$\{|\+\s*\w+/gi,
20
+ severity: 'critical',
21
+ title: 'Potential SQL Injection',
22
+ description: 'User input may be directly concatenated into SQL query',
23
+ cwe: 'CWE-89',
24
+ owasp: 'A03:2021-Injection',
25
+ remediation: 'Use parameterized queries or prepared statements'
26
+ },
27
+ {
28
+ type: 'sql-injection',
29
+ pattern: /\.query\s*\(\s*`[^`]*\$\{[^}]+\}[^`]*`/g,
30
+ severity: 'critical',
31
+ title: 'SQL Injection via Template Literal',
32
+ description: 'Template literal with interpolation used in SQL query',
33
+ cwe: 'CWE-89',
34
+ owasp: 'A03:2021-Injection',
35
+ remediation: 'Use parameterized queries: query($1, [param])'
36
+ },
37
+ // XSS
38
+ {
39
+ type: 'xss',
40
+ pattern: /innerHTML\s*=\s*(?!\s*['"`])/g,
41
+ severity: 'high',
42
+ title: 'Potential XSS via innerHTML',
43
+ description: 'Setting innerHTML with dynamic content can lead to XSS',
44
+ cwe: 'CWE-79',
45
+ owasp: 'A03:2021-Injection',
46
+ remediation: 'Use textContent or sanitize HTML with DOMPurify'
47
+ },
48
+ {
49
+ type: 'xss',
50
+ pattern: /document\.write\s*\(/g,
51
+ severity: 'high',
52
+ title: 'XSS via document.write',
53
+ description: 'document.write() can execute arbitrary scripts',
54
+ cwe: 'CWE-79',
55
+ owasp: 'A03:2021-Injection',
56
+ remediation: 'Use DOM manipulation methods instead'
57
+ },
58
+ {
59
+ type: 'xss',
60
+ pattern: /dangerouslySetInnerHTML\s*=\s*\{\s*\{\s*__html\s*:/g,
61
+ severity: 'medium',
62
+ title: 'React dangerouslySetInnerHTML',
63
+ description: 'Ensure HTML is properly sanitized before use',
64
+ cwe: 'CWE-79',
65
+ owasp: 'A03:2021-Injection',
66
+ remediation: 'Sanitize HTML with DOMPurify before setting'
67
+ },
68
+ // Command Injection
69
+ {
70
+ type: 'command-injection',
71
+ pattern: /(?:exec|spawn|execSync|spawnSync)\s*\([^)]*\$\{|\+\s*\w+/g,
72
+ severity: 'critical',
73
+ title: 'Potential Command Injection',
74
+ description: 'User input may be passed to shell command',
75
+ cwe: 'CWE-78',
76
+ owasp: 'A03:2021-Injection',
77
+ remediation: 'Validate and sanitize input, use spawn with array args'
78
+ },
79
+ {
80
+ type: 'command-injection',
81
+ pattern: /child_process.*exec\s*\(\s*`/g,
82
+ severity: 'critical',
83
+ title: 'Shell Command with Template',
84
+ description: 'Shell command constructed from template literal',
85
+ cwe: 'CWE-78',
86
+ owasp: 'A03:2021-Injection',
87
+ remediation: 'Use execFile or spawn with argument array'
88
+ },
89
+ // Path Traversal
90
+ {
91
+ type: 'path-traversal',
92
+ pattern: /(?:readFile|writeFile|createReadStream|access|stat|unlink)\s*\([^)]*(?:req\.|params\.|query\.|body\.)/g,
93
+ severity: 'high',
94
+ title: 'Potential Path Traversal',
95
+ description: 'User input may be used in file path without validation',
96
+ cwe: 'CWE-22',
97
+ owasp: 'A01:2021-Broken Access Control',
98
+ remediation: 'Validate path with path.normalize() and check prefix'
99
+ },
100
+ {
101
+ type: 'path-traversal',
102
+ pattern: /\.\.\/|\.\.\\|\.\.[/\\]/g,
103
+ severity: 'medium',
104
+ title: 'Directory Traversal Pattern',
105
+ description: 'Path contains directory traversal sequence',
106
+ cwe: 'CWE-22',
107
+ owasp: 'A01:2021-Broken Access Control',
108
+ remediation: 'Use path.resolve() and validate against base directory'
109
+ },
110
+ // Insecure Randomness
111
+ {
112
+ type: 'insecure-random',
113
+ pattern: /Math\.random\s*\(\)/g,
114
+ severity: 'medium',
115
+ title: 'Insecure Random Number Generator',
116
+ description: 'Math.random() is not cryptographically secure',
117
+ cwe: 'CWE-330',
118
+ owasp: 'A02:2021-Cryptographic Failures',
119
+ remediation: 'Use crypto.randomBytes() or crypto.randomUUID()',
120
+ contextCheck: (code) => {
121
+ // Не ругаемся если это не для безопасности
122
+ return code.includes('token') || code.includes('secret') ||
123
+ code.includes('password') || code.includes('auth') ||
124
+ code.includes('session') || code.includes('key');
125
+ }
126
+ },
127
+ // Weak Cryptography
128
+ {
129
+ type: 'weak-crypto',
130
+ pattern: /createHash\s*\(\s*['"](?:md5|sha1)['"]\s*\)/g,
131
+ severity: 'medium',
132
+ title: 'Weak Hash Algorithm',
133
+ description: 'MD5 and SHA1 are considered weak for security',
134
+ cwe: 'CWE-328',
135
+ owasp: 'A02:2021-Cryptographic Failures',
136
+ remediation: 'Use SHA-256 or stronger: createHash("sha256")'
137
+ },
138
+ {
139
+ type: 'weak-crypto',
140
+ pattern: /createCipher\s*\(\s*['"](?:des|rc4|rc2)['"]/gi,
141
+ severity: 'high',
142
+ title: 'Weak Encryption Algorithm',
143
+ description: 'DES, RC4, RC2 are deprecated encryption algorithms',
144
+ cwe: 'CWE-327',
145
+ owasp: 'A02:2021-Cryptographic Failures',
146
+ remediation: 'Use AES-256-GCM: createCipheriv("aes-256-gcm", ...)'
147
+ },
148
+ // Open Redirect
149
+ {
150
+ type: 'open-redirect',
151
+ pattern: /(?:redirect|location\.href|window\.location)\s*=?\s*(?:req\.|params\.|query\.)/g,
152
+ severity: 'medium',
153
+ title: 'Potential Open Redirect',
154
+ description: 'User-controlled URL in redirect can lead to phishing',
155
+ cwe: 'CWE-601',
156
+ owasp: 'A01:2021-Broken Access Control',
157
+ remediation: 'Validate redirect URL against whitelist of allowed domains'
158
+ },
159
+ // SSRF
160
+ {
161
+ type: 'ssrf',
162
+ pattern: /(?:fetch|axios|request|http\.get)\s*\([^)]*(?:req\.|params\.|query\.|body\.)/g,
163
+ severity: 'high',
164
+ title: 'Potential Server-Side Request Forgery',
165
+ description: 'User input used in server-side HTTP request',
166
+ cwe: 'CWE-918',
167
+ owasp: 'A10:2021-SSRF',
168
+ remediation: 'Validate URLs against whitelist, block internal IPs'
169
+ },
170
+ // Prototype Pollution
171
+ {
172
+ type: 'prototype-pollution',
173
+ pattern: /\[(?:req\.|params\.|query\.|body\.)[^\]]+\]\s*=/g,
174
+ severity: 'high',
175
+ title: 'Potential Prototype Pollution',
176
+ description: 'User-controlled object key assignment',
177
+ cwe: 'CWE-1321',
178
+ owasp: 'A03:2021-Injection',
179
+ remediation: 'Validate keys against whitelist, use Object.create(null)'
180
+ },
181
+ {
182
+ type: 'prototype-pollution',
183
+ pattern: /Object\.assign\s*\(\s*\{\s*\}\s*,\s*(?:req\.|params\.|query\.|body\.)/g,
184
+ severity: 'medium',
185
+ title: 'Object.assign with User Input',
186
+ description: 'Merging user input can lead to prototype pollution',
187
+ cwe: 'CWE-1321',
188
+ owasp: 'A03:2021-Injection',
189
+ remediation: 'Use structured cloning or explicit property copying'
190
+ },
191
+ // Regex DoS
192
+ {
193
+ type: 'regex-dos',
194
+ pattern: /new RegExp\s*\([^)]*(?:req\.|params\.|query\.|body\.)/g,
195
+ severity: 'medium',
196
+ title: 'ReDoS via User Input',
197
+ description: 'User-controlled regex can cause denial of service',
198
+ cwe: 'CWE-1333',
199
+ owasp: 'A03:2021-Injection',
200
+ remediation: 'Avoid user input in regex, use safe-regex library'
201
+ },
202
+ // Sensitive Data Exposure
203
+ {
204
+ type: 'sensitive-data-exposure',
205
+ pattern: /console\.log\s*\([^)]*(?:password|secret|token|key|credential|auth)/gi,
206
+ severity: 'medium',
207
+ title: 'Sensitive Data in Logs',
208
+ description: 'Sensitive information may be exposed in logs',
209
+ cwe: 'CWE-532',
210
+ owasp: 'A09:2021-Security Logging Failures',
211
+ remediation: 'Remove sensitive data from logs, use masking'
212
+ },
213
+ // Missing Security Headers
214
+ {
215
+ type: 'security-misconfiguration',
216
+ pattern: /cors\s*\(\s*\{\s*origin\s*:\s*['"]\*['"]/g,
217
+ severity: 'medium',
218
+ title: 'Overly Permissive CORS',
219
+ description: 'CORS allows any origin',
220
+ cwe: 'CWE-942',
221
+ owasp: 'A05:2021-Security Misconfiguration',
222
+ remediation: 'Specify allowed origins explicitly'
223
+ },
224
+ // Insecure Deserialization
225
+ {
226
+ type: 'insecure-deserialization',
227
+ pattern: /eval\s*\(/g,
228
+ severity: 'critical',
229
+ title: 'Use of eval()',
230
+ description: 'eval() can execute arbitrary code',
231
+ cwe: 'CWE-95',
232
+ owasp: 'A08:2021-Software and Data Integrity',
233
+ remediation: 'Avoid eval(), use JSON.parse() or safer alternatives'
234
+ },
235
+ {
236
+ type: 'insecure-deserialization',
237
+ pattern: /new Function\s*\(/g,
238
+ severity: 'high',
239
+ title: 'Dynamic Function Creation',
240
+ description: 'new Function() can execute arbitrary code',
241
+ cwe: 'CWE-95',
242
+ owasp: 'A08:2021-Software and Data Integrity',
243
+ remediation: 'Avoid dynamic code execution'
244
+ }
245
+ ];
246
+ secretPatterns = [
247
+ // API Keys
248
+ {
249
+ type: 'api-key',
250
+ pattern: /['"](?:api[_-]?key|apikey)\s*['"]\s*[:=]\s*['"][a-zA-Z0-9_\-]{20,}['"]/gi,
251
+ confidence: 'high'
252
+ },
253
+ {
254
+ type: 'api-key',
255
+ pattern: /(?:OPENAI|ANTHROPIC|DEEPSEEK|STRIPE|SENDGRID|TWILIO|GITHUB|GITLAB)[_]?(?:API)?[_]?KEY\s*[:=]\s*['"][^'"]+['"]/gi,
256
+ confidence: 'high'
257
+ },
258
+ // AWS
259
+ {
260
+ type: 'aws-key',
261
+ pattern: /AKIA[0-9A-Z]{16}/g,
262
+ confidence: 'high'
263
+ },
264
+ {
265
+ type: 'aws-key',
266
+ pattern: /aws[_-]?(?:secret|access)[_-]?key\s*[:=]\s*['"][^'"]{20,}['"]/gi,
267
+ confidence: 'high'
268
+ },
269
+ // Passwords
270
+ {
271
+ type: 'password',
272
+ pattern: /['"]?(?:password|passwd|pwd)\s*['"]\s*[:=]\s*['"][^'"]{8,}['"]/gi,
273
+ confidence: 'high'
274
+ },
275
+ {
276
+ type: 'password',
277
+ pattern: /(?:DB|DATABASE|MYSQL|POSTGRES|MONGO)[_]?PASSWORD\s*[:=]\s*['"][^'"]+['"]/gi,
278
+ confidence: 'high'
279
+ },
280
+ // Private Keys
281
+ {
282
+ type: 'private-key',
283
+ pattern: /-----BEGIN (?:RSA |EC |DSA )?PRIVATE KEY-----/g,
284
+ confidence: 'high'
285
+ },
286
+ {
287
+ type: 'private-key',
288
+ pattern: /-----BEGIN OPENSSH PRIVATE KEY-----/g,
289
+ confidence: 'high'
290
+ },
291
+ // JWT
292
+ {
293
+ type: 'jwt-secret',
294
+ pattern: /(?:jwt|jws)[_-]?secret\s*[:=]\s*['"][^'"]{10,}['"]/gi,
295
+ confidence: 'high'
296
+ },
297
+ {
298
+ type: 'jwt-secret',
299
+ pattern: /eyJ[a-zA-Z0-9_-]*\.eyJ[a-zA-Z0-9_-]*\.[a-zA-Z0-9_-]*/g,
300
+ confidence: 'medium'
301
+ },
302
+ // Database URLs
303
+ {
304
+ type: 'database-url',
305
+ pattern: /(?:mongodb|postgres|mysql|redis):\/\/[^:]+:[^@]+@[^\s'"]+/gi,
306
+ confidence: 'high'
307
+ },
308
+ // OAuth
309
+ {
310
+ type: 'oauth-secret',
311
+ pattern: /(?:client|app)[_-]?secret\s*[:=]\s*['"][a-zA-Z0-9_\-]{20,}['"]/gi,
312
+ confidence: 'high'
313
+ },
314
+ // Generic Secrets
315
+ {
316
+ type: 'generic-secret',
317
+ pattern: /['"]?secret[_-]?(?:key|token)?\s*['"]\s*[:=]\s*['"][^'"]{10,}['"]/gi,
318
+ confidence: 'medium'
319
+ },
320
+ {
321
+ type: 'generic-secret',
322
+ pattern: /['"]?(?:auth|access)[_-]?token\s*['"]\s*[:=]\s*['"][^'"]{20,}['"]/gi,
323
+ confidence: 'medium'
324
+ }
325
+ ];
326
+ /**
327
+ * Анализ безопасности
328
+ */
329
+ async analyze(fileContents) {
330
+ Logger.progress('Analyzing security vulnerabilities...');
331
+ const vulnerabilities = [];
332
+ const secrets = [];
333
+ let idCounter = 0;
334
+ for (const [filePath, content] of fileContents) {
335
+ // Пропускаем не-исходные файлы
336
+ if (!filePath.match(/\.(ts|js|tsx|jsx|py|rb|php|java|go)$/))
337
+ continue;
338
+ const lines = content.split('\n');
339
+ // Проверяем паттерны уязвимостей
340
+ for (const pattern of this.vulnerabilityPatterns) {
341
+ const matches = content.matchAll(pattern.pattern);
342
+ for (const match of matches) {
343
+ // Проверяем контекст если нужно
344
+ if (pattern.contextCheck) {
345
+ const contextStart = Math.max(0, (match.index || 0) - 100);
346
+ const contextEnd = Math.min(content.length, (match.index || 0) + 200);
347
+ const context = content.substring(contextStart, contextEnd);
348
+ if (!pattern.contextCheck(context, match))
349
+ continue;
350
+ }
351
+ const line = this.getLineNumber(content, match.index || 0);
352
+ const codeLine = lines[line - 1] || '';
353
+ vulnerabilities.push({
354
+ id: `SEC-${++idCounter}`,
355
+ type: pattern.type,
356
+ severity: pattern.severity,
357
+ title: pattern.title,
358
+ description: pattern.description,
359
+ file: filePath,
360
+ line,
361
+ code: codeLine.trim().substring(0, 100),
362
+ cwe: pattern.cwe,
363
+ owasp: pattern.owasp,
364
+ remediation: pattern.remediation
365
+ });
366
+ }
367
+ }
368
+ // Проверяем секреты
369
+ for (const pattern of this.secretPatterns) {
370
+ const matches = content.matchAll(pattern.pattern);
371
+ for (const match of matches) {
372
+ const line = this.getLineNumber(content, match.index || 0);
373
+ const codeLine = lines[line - 1] || '';
374
+ // Пропускаем если это комментарий или пример
375
+ if (codeLine.trim().startsWith('//') || codeLine.trim().startsWith('#'))
376
+ continue;
377
+ if (codeLine.includes('example') || codeLine.includes('placeholder'))
378
+ continue;
379
+ if (codeLine.includes('process.env') || codeLine.includes('getenv'))
380
+ continue;
381
+ secrets.push({
382
+ type: pattern.type,
383
+ file: filePath,
384
+ line,
385
+ preview: this.maskSecret(match[0]),
386
+ confidence: pattern.confidence
387
+ });
388
+ }
389
+ }
390
+ }
391
+ // Убираем дубликаты
392
+ const uniqueVulns = this.deduplicateVulnerabilities(vulnerabilities);
393
+ const uniqueSecrets = this.deduplicateSecrets(secrets);
394
+ const summary = this.calculateSummary(uniqueVulns, uniqueSecrets);
395
+ Logger.success(`Security analysis complete: ${uniqueVulns.length} vulnerabilities, ${uniqueSecrets.length} secrets`);
396
+ return {
397
+ vulnerabilities: uniqueVulns,
398
+ secrets: uniqueSecrets,
399
+ summary
400
+ };
401
+ }
402
+ /**
403
+ * Получить номер строки по индексу
404
+ */
405
+ getLineNumber(content, index) {
406
+ return content.substring(0, index).split('\n').length;
407
+ }
408
+ /**
409
+ * Маскировка секрета
410
+ */
411
+ maskSecret(secret) {
412
+ if (secret.length <= 10) {
413
+ return '*'.repeat(secret.length);
414
+ }
415
+ const visible = 4;
416
+ return secret.substring(0, visible) + '*'.repeat(secret.length - visible * 2) + secret.substring(secret.length - visible);
417
+ }
418
+ /**
419
+ * Удаление дубликатов уязвимостей
420
+ */
421
+ deduplicateVulnerabilities(vulnerabilities) {
422
+ const seen = new Set();
423
+ return vulnerabilities.filter(v => {
424
+ const key = `${v.file}:${v.line}:${v.type}`;
425
+ if (seen.has(key))
426
+ return false;
427
+ seen.add(key);
428
+ return true;
429
+ });
430
+ }
431
+ /**
432
+ * Удаление дубликатов секретов
433
+ */
434
+ deduplicateSecrets(secrets) {
435
+ const seen = new Set();
436
+ return secrets.filter(s => {
437
+ const key = `${s.file}:${s.line}:${s.type}`;
438
+ if (seen.has(key))
439
+ return false;
440
+ seen.add(key);
441
+ return true;
442
+ });
443
+ }
444
+ /**
445
+ * Подсчёт статистики
446
+ */
447
+ calculateSummary(vulnerabilities, secrets) {
448
+ const critical = vulnerabilities.filter(v => v.severity === 'critical').length;
449
+ const high = vulnerabilities.filter(v => v.severity === 'high').length;
450
+ const medium = vulnerabilities.filter(v => v.severity === 'medium').length;
451
+ const low = vulnerabilities.filter(v => v.severity === 'low').length;
452
+ // Risk Score: 0-100 (выше = хуже)
453
+ const riskScore = Math.min(100, Math.round(critical * 25 + high * 15 + medium * 5 + low * 1 +
454
+ secrets.filter(s => s.confidence === 'high').length * 20 +
455
+ secrets.filter(s => s.confidence === 'medium').length * 10));
456
+ let grade;
457
+ if (riskScore === 0) {
458
+ grade = 'A';
459
+ }
460
+ else if (riskScore <= 20) {
461
+ grade = 'B';
462
+ }
463
+ else if (riskScore <= 50) {
464
+ grade = 'C';
465
+ }
466
+ else if (riskScore <= 80) {
467
+ grade = 'D';
468
+ }
469
+ else {
470
+ grade = 'F';
471
+ }
472
+ return {
473
+ totalVulnerabilities: vulnerabilities.length,
474
+ critical,
475
+ high,
476
+ medium,
477
+ low,
478
+ secretsFound: secrets.length,
479
+ riskScore,
480
+ grade
481
+ };
482
+ }
483
+ }
484
+ //# sourceMappingURL=security.js.map
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Architecture Knowledge Layer
3
+ *
4
+ * Слой архитектурных знаний:
5
+ * - Bounded Contexts (границы контекстов)
6
+ * - Domain Entities (доменные сущности)
7
+ * - Architectural Rules (архитектурные правила)
8
+ * - Invariants (инварианты)
9
+ */
10
+ import { ArchitectureModel, BoundedContext, DomainEntity, ArchitecturalRule, Invariant, RuleViolation, ValidationContext } from '../types/index.js';
11
+ export declare class ArchitectureKnowledge {
12
+ private model;
13
+ private configPath;
14
+ constructor(configPath?: string);
15
+ load(): Promise<void>;
16
+ save(): Promise<void>;
17
+ getModel(): ArchitectureModel;
18
+ addBoundedContext(context: BoundedContext): void;
19
+ addEntity(entity: DomainEntity): void;
20
+ addRule(rule: ArchitecturalRule): void;
21
+ addInvariant(invariant: Invariant): void;
22
+ validateArchitecture(context: ValidationContext): RuleViolation[];
23
+ private validateBoundedContexts;
24
+ private validateInvariants;
25
+ private checkDependency;
26
+ getBoundedContext(name: string): BoundedContext | undefined;
27
+ getEntity(name: string): DomainEntity | undefined;
28
+ getContextForFile(filePath: string): BoundedContext | null;
29
+ private initializeDefaults;
30
+ private createDefaultRules;
31
+ private detectCircularDependencies;
32
+ generateReport(): string;
33
+ }
34
+ export * from '../types/index.js';
35
+ //# sourceMappingURL=index.d.ts.map