avana-cli 2.11.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.
- package/CHANGELOG.md +32 -0
- package/LICENSE +21 -0
- package/README.md +584 -0
- package/dist/cli.d.ts +7 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +153 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/install.d.ts +6 -0
- package/dist/commands/install.d.ts.map +1 -0
- package/dist/commands/install.js +101 -0
- package/dist/commands/install.js.map +1 -0
- package/dist/commands/scan.d.ts +19 -0
- package/dist/commands/scan.d.ts.map +1 -0
- package/dist/commands/scan.js +383 -0
- package/dist/commands/scan.js.map +1 -0
- package/dist/commands/uninstall.d.ts +6 -0
- package/dist/commands/uninstall.d.ts.map +1 -0
- package/dist/commands/uninstall.js +80 -0
- package/dist/commands/uninstall.js.map +1 -0
- package/dist/index.d.ts +97 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +475 -0
- package/dist/index.js.map +1 -0
- package/dist/rules/additional-patterns.d.ts +12 -0
- package/dist/rules/additional-patterns.d.ts.map +1 -0
- package/dist/rules/additional-patterns.js +170 -0
- package/dist/rules/additional-patterns.js.map +1 -0
- package/dist/rules/code-patterns.d.ts +26 -0
- package/dist/rules/code-patterns.d.ts.map +1 -0
- package/dist/rules/code-patterns.js +220 -0
- package/dist/rules/code-patterns.js.map +1 -0
- package/dist/rules/secret-patterns.d.ts +28 -0
- package/dist/rules/secret-patterns.d.ts.map +1 -0
- package/dist/rules/secret-patterns.js +1729 -0
- package/dist/rules/secret-patterns.js.map +1 -0
- package/dist/scanners/secret-scanner.d.ts +34 -0
- package/dist/scanners/secret-scanner.d.ts.map +1 -0
- package/dist/scanners/secret-scanner.js +281 -0
- package/dist/scanners/secret-scanner.js.map +1 -0
- package/dist/types/index.d.ts +116 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +7 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/error-handler.d.ts +126 -0
- package/dist/utils/error-handler.d.ts.map +1 -0
- package/dist/utils/error-handler.js +222 -0
- package/dist/utils/error-handler.js.map +1 -0
- package/dist/utils/exit-codes.d.ts +52 -0
- package/dist/utils/exit-codes.d.ts.map +1 -0
- package/dist/utils/exit-codes.js +89 -0
- package/dist/utils/exit-codes.js.map +1 -0
- package/dist/utils/file-stream-scanner.d.ts +31 -0
- package/dist/utils/file-stream-scanner.d.ts.map +1 -0
- package/dist/utils/file-stream-scanner.js +159 -0
- package/dist/utils/file-stream-scanner.js.map +1 -0
- package/dist/utils/file-type-detector.d.ts +45 -0
- package/dist/utils/file-type-detector.d.ts.map +1 -0
- package/dist/utils/file-type-detector.js +237 -0
- package/dist/utils/file-type-detector.js.map +1 -0
- package/dist/utils/ignore-pattern-manager.d.ts +61 -0
- package/dist/utils/ignore-pattern-manager.d.ts.map +1 -0
- package/dist/utils/ignore-pattern-manager.js +204 -0
- package/dist/utils/ignore-pattern-manager.js.map +1 -0
- package/dist/utils/json-output-formatter.d.ts +232 -0
- package/dist/utils/json-output-formatter.d.ts.map +1 -0
- package/dist/utils/json-output-formatter.js +367 -0
- package/dist/utils/json-output-formatter.js.map +1 -0
- package/dist/utils/logger.d.ts +181 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +414 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/markdown-output-formatter.d.ts +65 -0
- package/dist/utils/markdown-output-formatter.d.ts.map +1 -0
- package/dist/utils/markdown-output-formatter.js +316 -0
- package/dist/utils/markdown-output-formatter.js.map +1 -0
- package/dist/utils/memory-manager.d.ts +77 -0
- package/dist/utils/memory-manager.d.ts.map +1 -0
- package/dist/utils/memory-manager.js +157 -0
- package/dist/utils/memory-manager.js.map +1 -0
- package/dist/utils/parallel-scanner-worker.d.ts +19 -0
- package/dist/utils/parallel-scanner-worker.d.ts.map +1 -0
- package/dist/utils/parallel-scanner-worker.js +51 -0
- package/dist/utils/parallel-scanner-worker.js.map +1 -0
- package/dist/utils/parallel-scanner.d.ts +82 -0
- package/dist/utils/parallel-scanner.d.ts.map +1 -0
- package/dist/utils/parallel-scanner.js +229 -0
- package/dist/utils/parallel-scanner.js.map +1 -0
- package/dist/utils/pattern-validator.d.ts +108 -0
- package/dist/utils/pattern-validator.d.ts.map +1 -0
- package/dist/utils/pattern-validator.js +315 -0
- package/dist/utils/pattern-validator.js.map +1 -0
- package/dist/utils/progress-reporter.d.ts +68 -0
- package/dist/utils/progress-reporter.d.ts.map +1 -0
- package/dist/utils/progress-reporter.js +194 -0
- package/dist/utils/progress-reporter.js.map +1 -0
- package/dist/utils/result-cache.d.ts +99 -0
- package/dist/utils/result-cache.d.ts.map +1 -0
- package/dist/utils/result-cache.js +335 -0
- package/dist/utils/result-cache.js.map +1 -0
- package/package.json +80 -0
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Markdown Output Formatter
|
|
4
|
+
* Formats scan results as readable Markdown reports
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.MarkdownOutputFormatter = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* Markdown Output Formatter class
|
|
10
|
+
* Formats security scan results as readable Markdown reports
|
|
11
|
+
*/
|
|
12
|
+
class MarkdownOutputFormatter {
|
|
13
|
+
options;
|
|
14
|
+
constructor(options = {}) {
|
|
15
|
+
this.options = {
|
|
16
|
+
includeMetadata: options.includeMetadata ?? true,
|
|
17
|
+
includeSummary: options.includeSummary ?? true,
|
|
18
|
+
includeDetails: options.includeDetails ?? true,
|
|
19
|
+
includeRecommendations: options.includeRecommendations ?? true,
|
|
20
|
+
groupBySeverity: options.groupBySeverity ?? true,
|
|
21
|
+
maxIssuesPerSeverity: options.maxIssuesPerSeverity ?? 50,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Format scan results as Markdown
|
|
26
|
+
*/
|
|
27
|
+
format(result, securityScore) {
|
|
28
|
+
const sections = [];
|
|
29
|
+
// Header
|
|
30
|
+
sections.push(this.formatHeader(result, securityScore));
|
|
31
|
+
// Metadata
|
|
32
|
+
if (this.options.includeMetadata) {
|
|
33
|
+
sections.push(this.formatMetadata(result));
|
|
34
|
+
}
|
|
35
|
+
// Summary
|
|
36
|
+
if (this.options.includeSummary) {
|
|
37
|
+
sections.push(this.formatSummary(result));
|
|
38
|
+
}
|
|
39
|
+
// Issues
|
|
40
|
+
if (this.options.includeDetails) {
|
|
41
|
+
sections.push(this.formatIssues(result.issues));
|
|
42
|
+
}
|
|
43
|
+
// Recommendations
|
|
44
|
+
if (this.options.includeRecommendations) {
|
|
45
|
+
sections.push(this.formatRecommendations(result, securityScore));
|
|
46
|
+
}
|
|
47
|
+
return sections.join('\n\n');
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Format the report header
|
|
51
|
+
*/
|
|
52
|
+
formatHeader(result, securityScore) {
|
|
53
|
+
const timestamp = new Date(result.timestamp).toLocaleString();
|
|
54
|
+
const scoreText = securityScore !== undefined ? ` (Score: ${securityScore}/100)` : '';
|
|
55
|
+
return `# 🔒 Avana Security Scan Report${scoreText}
|
|
56
|
+
|
|
57
|
+
**Generated:** ${timestamp}
|
|
58
|
+
**Status:** ${result.issues.length === 0 ? '✅ No Issues Found' : '⚠️ Issues Detected'}`;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Format metadata section
|
|
62
|
+
*/
|
|
63
|
+
formatMetadata(result) {
|
|
64
|
+
return `## 📊 Scan Metadata
|
|
65
|
+
|
|
66
|
+
| Metric | Value |
|
|
67
|
+
|--------|-------|
|
|
68
|
+
| **Duration** | ${result.duration}ms |
|
|
69
|
+
| **Files Scanned** | ${result.filesScanned} |
|
|
70
|
+
| **Total Issues** | ${result.issues.length} |
|
|
71
|
+
| **Timestamp** | ${result.timestamp} |`;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Format summary section
|
|
75
|
+
*/
|
|
76
|
+
formatSummary(result) {
|
|
77
|
+
const { critical, high, medium, low, info } = result.summary;
|
|
78
|
+
let summary = `## 📈 Issue Summary
|
|
79
|
+
|
|
80
|
+
| Severity | Count | Icon |
|
|
81
|
+
|----------|-------|------|
|
|
82
|
+
| **Critical** | ${critical} | 🔴 |
|
|
83
|
+
| **High** | ${high} | 🟠 |
|
|
84
|
+
| **Medium** | ${medium} | 🟡 |
|
|
85
|
+
| **Low** | ${low} | 🟢 |
|
|
86
|
+
| **Info** | ${info} | ℹ️ |`;
|
|
87
|
+
// Add severity distribution chart (simple text-based)
|
|
88
|
+
if (result.issues.length > 0) {
|
|
89
|
+
summary += '\n\n### Severity Distribution\n\n```\n';
|
|
90
|
+
const total = result.issues.length;
|
|
91
|
+
const criticalBar = '█'.repeat(Math.round((critical / total) * 20));
|
|
92
|
+
const highBar = '█'.repeat(Math.round((high / total) * 20));
|
|
93
|
+
const mediumBar = '█'.repeat(Math.round((medium / total) * 20));
|
|
94
|
+
const lowBar = '█'.repeat(Math.round((low / total) * 20));
|
|
95
|
+
summary += `Critical: ${criticalBar} ${critical}\n`;
|
|
96
|
+
summary += `High: ${highBar} ${high}\n`;
|
|
97
|
+
summary += `Medium: ${mediumBar} ${medium}\n`;
|
|
98
|
+
summary += `Low: ${lowBar} ${low}\n`;
|
|
99
|
+
summary += '```';
|
|
100
|
+
}
|
|
101
|
+
return summary;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Format issues section
|
|
105
|
+
*/
|
|
106
|
+
formatIssues(issues) {
|
|
107
|
+
if (issues.length === 0) {
|
|
108
|
+
return '## ✅ No Issues Found\n\nGreat job! No security issues were detected in your codebase.';
|
|
109
|
+
}
|
|
110
|
+
let issuesSection = '## 🚨 Detected Issues\n';
|
|
111
|
+
if (this.options.groupBySeverity) {
|
|
112
|
+
issuesSection += this.formatIssuesBySeverity(issues);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
issuesSection += this.formatIssuesList(issues);
|
|
116
|
+
}
|
|
117
|
+
return issuesSection;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Format issues grouped by severity
|
|
121
|
+
*/
|
|
122
|
+
formatIssuesBySeverity(issues) {
|
|
123
|
+
const severityOrder = ['critical', 'high', 'medium', 'low', 'info'];
|
|
124
|
+
const severityIcons = {
|
|
125
|
+
critical: '🔴',
|
|
126
|
+
high: '🟠',
|
|
127
|
+
medium: '🟡',
|
|
128
|
+
low: '🟢',
|
|
129
|
+
info: 'ℹ️'
|
|
130
|
+
};
|
|
131
|
+
let output = '';
|
|
132
|
+
for (const severity of severityOrder) {
|
|
133
|
+
const severityIssues = issues.filter(issue => issue.severity === severity);
|
|
134
|
+
if (severityIssues.length === 0)
|
|
135
|
+
continue;
|
|
136
|
+
const icon = severityIcons[severity];
|
|
137
|
+
const title = severity.charAt(0).toUpperCase() + severity.slice(1);
|
|
138
|
+
output += `\n### ${icon} ${title} Severity (${severityIssues.length} issues)\n\n`;
|
|
139
|
+
const issuesToShow = severityIssues.slice(0, this.options.maxIssuesPerSeverity);
|
|
140
|
+
for (let i = 0; i < issuesToShow.length; i++) {
|
|
141
|
+
const issue = issuesToShow[i];
|
|
142
|
+
output += this.formatSingleIssue(issue, i + 1);
|
|
143
|
+
}
|
|
144
|
+
if (severityIssues.length > this.options.maxIssuesPerSeverity) {
|
|
145
|
+
const remaining = severityIssues.length - this.options.maxIssuesPerSeverity;
|
|
146
|
+
output += `\n*... and ${remaining} more ${severity} severity issues*\n`;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return output;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Format issues as a simple list
|
|
153
|
+
*/
|
|
154
|
+
formatIssuesList(issues) {
|
|
155
|
+
let output = '\n';
|
|
156
|
+
const issuesToShow = issues.slice(0, this.options.maxIssuesPerSeverity);
|
|
157
|
+
for (let i = 0; i < issuesToShow.length; i++) {
|
|
158
|
+
output += this.formatSingleIssue(issuesToShow[i], i + 1);
|
|
159
|
+
}
|
|
160
|
+
if (issues.length > this.options.maxIssuesPerSeverity) {
|
|
161
|
+
const remaining = issues.length - this.options.maxIssuesPerSeverity;
|
|
162
|
+
output += `\n*... and ${remaining} more issues*\n`;
|
|
163
|
+
}
|
|
164
|
+
return output;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Format a single issue
|
|
168
|
+
*/
|
|
169
|
+
formatSingleIssue(issue, index) {
|
|
170
|
+
const severityIcon = {
|
|
171
|
+
critical: '🔴',
|
|
172
|
+
high: '🟠',
|
|
173
|
+
medium: '🟡',
|
|
174
|
+
low: '🟢',
|
|
175
|
+
info: 'ℹ️'
|
|
176
|
+
}[issue.severity];
|
|
177
|
+
let output = `#### ${index}. ${severityIcon} ${issue.title}\n\n`;
|
|
178
|
+
// Issue details table
|
|
179
|
+
output += '| Detail | Value |\n';
|
|
180
|
+
output += '|--------|-------|\n';
|
|
181
|
+
output += `| **File** | \`${issue.file}\` |\n`;
|
|
182
|
+
output += `| **Line** | ${issue.line} |\n`;
|
|
183
|
+
output += `| **Severity** | ${severityIcon} ${issue.severity.toUpperCase()} |\n`;
|
|
184
|
+
output += `| **Type** | ${issue.type} |\n`;
|
|
185
|
+
if (issue.description) {
|
|
186
|
+
output += `| **Description** | ${issue.description} |\n`;
|
|
187
|
+
}
|
|
188
|
+
// Code context if available
|
|
189
|
+
if (issue.code) {
|
|
190
|
+
output += '\n**Code Context:**\n\n```\n';
|
|
191
|
+
output += issue.code;
|
|
192
|
+
output += '\n```\n';
|
|
193
|
+
}
|
|
194
|
+
// Suggestion if available
|
|
195
|
+
if (issue.suggestion) {
|
|
196
|
+
output += `\n**💡 Recommendation:** ${issue.suggestion}\n`;
|
|
197
|
+
}
|
|
198
|
+
output += '\n---\n\n';
|
|
199
|
+
return output;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Format recommendations section
|
|
203
|
+
*/
|
|
204
|
+
formatRecommendations(result, securityScore) {
|
|
205
|
+
let recommendations = '## 💡 Recommendations\n\n';
|
|
206
|
+
const totalIssues = result.summary.critical + result.summary.high + result.summary.medium + result.summary.low + result.summary.info;
|
|
207
|
+
if (totalIssues === 0) {
|
|
208
|
+
recommendations += `### ✅ Excellent Security Posture
|
|
209
|
+
|
|
210
|
+
Your codebase shows no security issues! Here are some tips to maintain this level:
|
|
211
|
+
|
|
212
|
+
- **Regular Scans**: Run Avana regularly, especially before commits
|
|
213
|
+
- **Team Training**: Ensure all team members understand secure coding practices
|
|
214
|
+
- **Dependency Updates**: Keep dependencies updated to avoid known vulnerabilities
|
|
215
|
+
- **Code Reviews**: Include security considerations in your code review process`;
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
const { critical, high, medium, low } = result.summary;
|
|
219
|
+
if (critical > 0) {
|
|
220
|
+
recommendations += `### 🚨 **URGENT: Critical Issues Detected**
|
|
221
|
+
|
|
222
|
+
You have **${critical} critical** security issue(s) that require immediate attention:
|
|
223
|
+
|
|
224
|
+
- **Stop deployment** until these are resolved
|
|
225
|
+
- **Review all critical issues** listed above
|
|
226
|
+
- **Implement fixes** as suggested
|
|
227
|
+
- **Re-scan** to verify fixes
|
|
228
|
+
|
|
229
|
+
`;
|
|
230
|
+
}
|
|
231
|
+
if (high > 0) {
|
|
232
|
+
recommendations += `### ⚠️ **High Priority Issues**
|
|
233
|
+
|
|
234
|
+
You have **${high} high** severity issue(s):
|
|
235
|
+
|
|
236
|
+
- **Address within 24-48 hours**
|
|
237
|
+
- **Review security implications** carefully
|
|
238
|
+
- **Test fixes thoroughly** before deployment
|
|
239
|
+
|
|
240
|
+
`;
|
|
241
|
+
}
|
|
242
|
+
if (medium > 0 || low > 0) {
|
|
243
|
+
recommendations += `### 📋 **General Improvements**
|
|
244
|
+
|
|
245
|
+
You have **${medium} medium** and **${low} low** severity issues:
|
|
246
|
+
|
|
247
|
+
- **Plan fixes** in upcoming development cycles
|
|
248
|
+
- **Consider security impact** during code reviews
|
|
249
|
+
- **Document any accepted risks**
|
|
250
|
+
|
|
251
|
+
`;
|
|
252
|
+
}
|
|
253
|
+
// Score-based recommendations
|
|
254
|
+
if (securityScore !== undefined) {
|
|
255
|
+
if (securityScore < 50) {
|
|
256
|
+
recommendations += `### 🔴 **Security Score: ${securityScore}/100 - Critical**
|
|
257
|
+
|
|
258
|
+
Your security score is critically low. Immediate action required:
|
|
259
|
+
|
|
260
|
+
1. **Address all critical and high issues** immediately
|
|
261
|
+
2. **Implement security training** for the development team
|
|
262
|
+
3. **Establish security review process** for all code changes
|
|
263
|
+
4. **Consider security audit** by external experts`;
|
|
264
|
+
}
|
|
265
|
+
else if (securityScore < 80) {
|
|
266
|
+
recommendations += `### 🟡 **Security Score: ${securityScore}/100 - Needs Improvement**
|
|
267
|
+
|
|
268
|
+
Your security score indicates room for improvement:
|
|
269
|
+
|
|
270
|
+
1. **Prioritize high and medium issues**
|
|
271
|
+
2. **Establish regular security scanning**
|
|
272
|
+
3. **Improve secure coding practices**
|
|
273
|
+
4. **Consider automated security testing**`;
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
recommendations += `### 🟢 **Security Score: ${securityScore}/100 - Good**
|
|
277
|
+
|
|
278
|
+
Your security score is good! To maintain and improve:
|
|
279
|
+
|
|
280
|
+
1. **Address remaining issues** when possible
|
|
281
|
+
2. **Maintain regular scanning habits**
|
|
282
|
+
3. **Keep security practices up to date**
|
|
283
|
+
4. **Share knowledge** with your team`;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
// General best practices
|
|
288
|
+
recommendations += `
|
|
289
|
+
|
|
290
|
+
### 🛡️ **Security Best Practices**
|
|
291
|
+
|
|
292
|
+
- **Never commit secrets** to version control
|
|
293
|
+
- **Use environment variables** for sensitive configuration
|
|
294
|
+
- **Implement proper access controls** for production systems
|
|
295
|
+
- **Regular security training** for all developers
|
|
296
|
+
- **Automated security scanning** in CI/CD pipelines
|
|
297
|
+
- **Keep dependencies updated** and monitor for vulnerabilities
|
|
298
|
+
|
|
299
|
+
### 🔧 **Using Avana Effectively**
|
|
300
|
+
|
|
301
|
+
- **Pre-commit hooks**: Run \`avana install\` to catch issues before commits
|
|
302
|
+
- **CI/CD integration**: Add Avana to your build pipeline
|
|
303
|
+
- **Regular scans**: Schedule periodic security scans
|
|
304
|
+
- **Team adoption**: Ensure all team members use Avana consistently`;
|
|
305
|
+
return recommendations;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Generate a filename for the markdown report
|
|
309
|
+
*/
|
|
310
|
+
generateFilename(prefix = 'avana-security-report') {
|
|
311
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-').split('T')[0];
|
|
312
|
+
return `${prefix}-${timestamp}.md`;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
exports.MarkdownOutputFormatter = MarkdownOutputFormatter;
|
|
316
|
+
//# sourceMappingURL=markdown-output-formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-output-formatter.js","sourceRoot":"","sources":["../../src/utils/markdown-output-formatter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAgBH;;;GAGG;AACH,MAAa,uBAAuB;IAC1B,OAAO,CAA4B;IAE3C,YAAY,UAA2B,EAAE;QACvC,IAAI,CAAC,OAAO,GAAG;YACb,eAAe,EAAE,OAAO,CAAC,eAAe,IAAI,IAAI;YAChD,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,IAAI;YAC9C,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,IAAI;YAC9C,sBAAsB,EAAE,OAAO,CAAC,sBAAsB,IAAI,IAAI;YAC9D,eAAe,EAAE,OAAO,CAAC,eAAe,IAAI,IAAI;YAChD,oBAAoB,EAAE,OAAO,CAAC,oBAAoB,IAAI,EAAE;SACzD,CAAC;IACJ,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,MAAkB,EAAE,aAAsB;QAC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Aa;;;;;;;mDAOnB,CAAC;gBAC5C,CAAC;qBAAM,IAAI,aAAa,GAAG,EAAE,EAAE,CAAC;oBAC9B,eAAe,IAAI,4BAA4B,aAAa;;;;;;;2CAO3B,CAAC;gBACpC,CAAC;qBAAM,CAAC;oBACN,eAAe,IAAI,4BAA4B,aAAa;;;;;;;sCAOhC,CAAC;gBAC/B,CAAC;YACH,CAAC;QACH,CAAC;QAED,yBAAyB;QACzB,eAAe,IAAI;;;;;;;;;;;;;;;;oEAgB6C,CAAC;QAEjE,OAAO,eAAe,CAAC;IACzB,CAAC;IAED;;OAEG;IACI,gBAAgB,CAAC,SAAiB,uBAAuB;QAC9D,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/E,OAAO,GAAG,MAAM,IAAI,SAAS,KAAK,CAAC;IACrC,CAAC;CACF;AA9VD,0DA8VC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Manager
|
|
3
|
+
* Monitors and manages memory usage during scanning operations
|
|
4
|
+
*/
|
|
5
|
+
export interface MemoryStats {
|
|
6
|
+
currentUsage: number;
|
|
7
|
+
maxUsage: number;
|
|
8
|
+
gcCount: number;
|
|
9
|
+
limit: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class MemoryManager {
|
|
12
|
+
private maxUsage;
|
|
13
|
+
private gcCount;
|
|
14
|
+
private readonly limit;
|
|
15
|
+
private readonly gcThreshold;
|
|
16
|
+
constructor(limitMB?: number);
|
|
17
|
+
/**
|
|
18
|
+
* Get current memory usage in bytes without updating maxUsage
|
|
19
|
+
*/
|
|
20
|
+
private getCurrentUsageRaw;
|
|
21
|
+
/**
|
|
22
|
+
* Get current memory usage in bytes
|
|
23
|
+
*/
|
|
24
|
+
getCurrentUsage(): number;
|
|
25
|
+
/**
|
|
26
|
+
* Check if memory usage is within limits
|
|
27
|
+
* Returns true if within limits, false if exceeded
|
|
28
|
+
*/
|
|
29
|
+
checkLimit(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Manually trigger garbage collection
|
|
32
|
+
*/
|
|
33
|
+
triggerGC(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Get comprehensive memory statistics
|
|
36
|
+
*/
|
|
37
|
+
getStats(): MemoryStats;
|
|
38
|
+
/**
|
|
39
|
+
* Format memory size in human-readable format
|
|
40
|
+
*/
|
|
41
|
+
formatMemorySize(bytes: number): string;
|
|
42
|
+
/**
|
|
43
|
+
* Get memory usage percentage
|
|
44
|
+
*/
|
|
45
|
+
getUsagePercentage(): number;
|
|
46
|
+
/**
|
|
47
|
+
* Check if memory usage is approaching the limit
|
|
48
|
+
*/
|
|
49
|
+
isApproachingLimit(): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Reset statistics (useful for testing)
|
|
52
|
+
*/
|
|
53
|
+
reset(): void;
|
|
54
|
+
/**
|
|
55
|
+
* Create a memory checkpoint for monitoring
|
|
56
|
+
*/
|
|
57
|
+
createCheckpoint(label: string): MemoryCheckpoint;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Memory checkpoint for tracking memory usage at specific points
|
|
61
|
+
*/
|
|
62
|
+
export declare class MemoryCheckpoint {
|
|
63
|
+
readonly label: string;
|
|
64
|
+
readonly startUsage: number;
|
|
65
|
+
readonly timestamp: number;
|
|
66
|
+
constructor(label: string, startUsage: number);
|
|
67
|
+
/**
|
|
68
|
+
* Calculate memory difference since checkpoint
|
|
69
|
+
*/
|
|
70
|
+
getDifference(currentUsage: number): number;
|
|
71
|
+
/**
|
|
72
|
+
* Get duration since checkpoint in milliseconds
|
|
73
|
+
*/
|
|
74
|
+
getDuration(): number;
|
|
75
|
+
}
|
|
76
|
+
export declare const memoryManager: MemoryManager;
|
|
77
|
+
//# sourceMappingURL=memory-manager.d.ts.map
|
|
@@ -0,0 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,eAAsB,CAAC"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Memory Manager
|
|
4
|
+
* Monitors and manages memory usage during scanning operations
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.memoryManager = exports.MemoryCheckpoint = exports.MemoryManager = void 0;
|
|
8
|
+
class MemoryManager {
|
|
9
|
+
maxUsage = 0;
|
|
10
|
+
gcCount = 0;
|
|
11
|
+
limit;
|
|
12
|
+
gcThreshold;
|
|
13
|
+
constructor(limitMB = 500) {
|
|
14
|
+
this.limit = limitMB * 1024 * 1024; // Convert MB to bytes
|
|
15
|
+
this.gcThreshold = limitMB * 0.8 * 1024 * 1024; // 80% of limit
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get current memory usage in bytes without updating maxUsage
|
|
19
|
+
*/
|
|
20
|
+
getCurrentUsageRaw() {
|
|
21
|
+
const memUsage = process.memoryUsage();
|
|
22
|
+
return memUsage.heapUsed;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Get current memory usage in bytes
|
|
26
|
+
*/
|
|
27
|
+
getCurrentUsage() {
|
|
28
|
+
const currentUsage = this.getCurrentUsageRaw();
|
|
29
|
+
// Track maximum usage
|
|
30
|
+
if (currentUsage > this.maxUsage) {
|
|
31
|
+
this.maxUsage = currentUsage;
|
|
32
|
+
}
|
|
33
|
+
return currentUsage;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Check if memory usage is within limits
|
|
37
|
+
* Returns true if within limits, false if exceeded
|
|
38
|
+
*/
|
|
39
|
+
checkLimit() {
|
|
40
|
+
const currentUsage = this.getCurrentUsage();
|
|
41
|
+
// Trigger GC if approaching threshold
|
|
42
|
+
if (currentUsage > this.gcThreshold) {
|
|
43
|
+
this.triggerGC();
|
|
44
|
+
}
|
|
45
|
+
return currentUsage <= this.limit;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Manually trigger garbage collection
|
|
49
|
+
*/
|
|
50
|
+
triggerGC() {
|
|
51
|
+
if (global.gc) {
|
|
52
|
+
global.gc();
|
|
53
|
+
this.gcCount++;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
// If --expose-gc flag not used, we can't force GC
|
|
57
|
+
// But we can suggest it by creating memory pressure
|
|
58
|
+
const before = this.getCurrentUsage();
|
|
59
|
+
// Create some temporary objects to trigger natural GC
|
|
60
|
+
const temp = new Array(1000).fill(null).map(() => ({ data: new Array(100) }));
|
|
61
|
+
temp.length = 0; // Clear reference
|
|
62
|
+
const after = this.getCurrentUsage();
|
|
63
|
+
if (after < before) {
|
|
64
|
+
this.gcCount++;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get comprehensive memory statistics
|
|
70
|
+
*/
|
|
71
|
+
getStats() {
|
|
72
|
+
const currentUsage = this.getCurrentUsageRaw();
|
|
73
|
+
// Update maxUsage if needed
|
|
74
|
+
if (currentUsage > this.maxUsage) {
|
|
75
|
+
this.maxUsage = currentUsage;
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
currentUsage,
|
|
79
|
+
maxUsage: this.maxUsage,
|
|
80
|
+
gcCount: this.gcCount,
|
|
81
|
+
limit: this.limit
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Format memory size in human-readable format
|
|
86
|
+
*/
|
|
87
|
+
formatMemorySize(bytes) {
|
|
88
|
+
const units = ['B', 'KB', 'MB', 'GB'];
|
|
89
|
+
let size = bytes;
|
|
90
|
+
let unitIndex = 0;
|
|
91
|
+
while (size >= 1024 && unitIndex < units.length - 1) {
|
|
92
|
+
size /= 1024;
|
|
93
|
+
unitIndex++;
|
|
94
|
+
}
|
|
95
|
+
return `${size.toFixed(2)} ${units[unitIndex]}`;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get memory usage percentage
|
|
99
|
+
*/
|
|
100
|
+
getUsagePercentage() {
|
|
101
|
+
const currentUsage = this.getCurrentUsage();
|
|
102
|
+
const percentage = (currentUsage / this.limit) * 100;
|
|
103
|
+
// Cap at 100% for display purposes
|
|
104
|
+
return Math.min(Math.round(percentage), 100);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Check if memory usage is approaching the limit
|
|
108
|
+
*/
|
|
109
|
+
isApproachingLimit() {
|
|
110
|
+
const currentUsage = this.getCurrentUsage();
|
|
111
|
+
return currentUsage > this.gcThreshold;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Reset statistics (useful for testing)
|
|
115
|
+
*/
|
|
116
|
+
reset() {
|
|
117
|
+
this.maxUsage = 0;
|
|
118
|
+
this.gcCount = 0;
|
|
119
|
+
// Note: We can't reset actual memory usage, only our tracking
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Create a memory checkpoint for monitoring
|
|
123
|
+
*/
|
|
124
|
+
createCheckpoint(label) {
|
|
125
|
+
return new MemoryCheckpoint(label, this.getCurrentUsage());
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.MemoryManager = MemoryManager;
|
|
129
|
+
/**
|
|
130
|
+
* Memory checkpoint for tracking memory usage at specific points
|
|
131
|
+
*/
|
|
132
|
+
class MemoryCheckpoint {
|
|
133
|
+
label;
|
|
134
|
+
startUsage;
|
|
135
|
+
timestamp;
|
|
136
|
+
constructor(label, startUsage) {
|
|
137
|
+
this.label = label;
|
|
138
|
+
this.startUsage = startUsage;
|
|
139
|
+
this.timestamp = Date.now();
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Calculate memory difference since checkpoint
|
|
143
|
+
*/
|
|
144
|
+
getDifference(currentUsage) {
|
|
145
|
+
return currentUsage - this.startUsage;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Get duration since checkpoint in milliseconds
|
|
149
|
+
*/
|
|
150
|
+
getDuration() {
|
|
151
|
+
return Date.now() - this.timestamp;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.MemoryCheckpoint = MemoryCheckpoint;
|
|
155
|
+
// Global memory manager instance
|
|
156
|
+
exports.memoryManager = new MemoryManager();
|
|
157
|
+
//# sourceMappingURL=memory-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-manager.js","sourceRoot":"","sources":["../../src/utils/memory-manager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AASH,MAAa,aAAa;IAChB,QAAQ,GAAW,CAAC,CAAC;IACrB,OAAO,GAAW,CAAC,CAAC;IACX,KAAK,CAAS;IACd,WAAW,CAAS;IAErC,YAAY,UAAkB,GAAG;QAC/B,IAAI,CAAC,KAAK,GAAG,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,sBAAsB;QAC1D,IAAI,CAAC,WAAW,GAAG,OAAO,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,eAAe;IACjE,CAAC;IAED;;OAEG;IACK,kBAAkB;QACxB,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;QACvC,OAAO,QAAQ,CAAC,QAAQ,CAAC;IAC3B,CAAC;IAED;;OAEG;IACI,eAAe;QACpB,MAAM,YAAY,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAE/C,sBAAsB;QACtB,IAAI,YAAY,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;YACjC,IAAI,CAAC,QAAQ,GAAG,YAAY,CAAC;QAC/B,CAAC;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;IAED;;;OAGG;IACI,UAAU;QACf,MAAM,YAAY,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QAE5C,sCAAsC;QACtC,IAAI,YAAY,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;YACpC,IAAI,CAAC,SAAS,EAAE,CAAC;QACnB,CAAC;Q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U,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC9B,CAAC;IAED;;OAEG;IACI,aAAa,CAAC,YAAoB;QACvC,OAAO,YAAY,GAAG,IAAI,CAAC,UAAU,CAAC;IACxC,CAAC;IAED;;OAEG;IACI,WAAW;QAChB,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC;IACrC,CAAC;CACF;AAxBD,4CAwBC;AAED,iCAAiC;AACpB,QAAA,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parallel Scanner Worker
|
|
3
|
+
* Worker thread script for parallel file scanning
|
|
4
|
+
*/
|
|
5
|
+
export interface WorkerData {
|
|
6
|
+
files: string[];
|
|
7
|
+
patterns: any[];
|
|
8
|
+
ignorePatterns: string[];
|
|
9
|
+
}
|
|
10
|
+
export interface WorkerMessage {
|
|
11
|
+
type: 'result' | 'error' | 'complete';
|
|
12
|
+
data?: {
|
|
13
|
+
file: string;
|
|
14
|
+
issues: any[];
|
|
15
|
+
error?: string;
|
|
16
|
+
};
|
|
17
|
+
error?: string;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=parallel-scanner-worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parallel-scanner-worker.d.ts","sourceRoot":"","sources":["../../src/utils/parallel-scanner-worker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,EAAE,GAAG,EAAE,CAAC;IAChB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,QAAQ,GAAG,OAAO,GAAG,UAAU,CAAC;IACtC,IAAI,CAAC,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,GAAG,EAAE,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Parallel Scanner Worker
|
|
4
|
+
* Worker thread script for parallel file scanning
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const worker_threads_1 = require("worker_threads");
|
|
8
|
+
const secret_scanner_1 = require("../scanners/secret-scanner");
|
|
9
|
+
if (worker_threads_1.parentPort) {
|
|
10
|
+
try {
|
|
11
|
+
const { files, patterns, ignorePatterns } = worker_threads_1.workerData;
|
|
12
|
+
const scanner = new secret_scanner_1.SecretScanner();
|
|
13
|
+
// Process each file
|
|
14
|
+
for (const file of files) {
|
|
15
|
+
try {
|
|
16
|
+
// Pass patterns to scanFile method (synchronous)
|
|
17
|
+
const issues = scanner.scanFile(file, patterns);
|
|
18
|
+
worker_threads_1.parentPort.postMessage({
|
|
19
|
+
type: 'result',
|
|
20
|
+
data: {
|
|
21
|
+
file,
|
|
22
|
+
issues
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
worker_threads_1.parentPort.postMessage({
|
|
28
|
+
type: 'result',
|
|
29
|
+
data: {
|
|
30
|
+
file,
|
|
31
|
+
issues: [],
|
|
32
|
+
error: error instanceof Error ? error.message : String(error)
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// Signal completion
|
|
38
|
+
worker_threads_1.parentPort.postMessage({
|
|
39
|
+
type: 'complete'
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (worker_threads_1.parentPort) {
|
|
44
|
+
worker_threads_1.parentPort.postMessage({
|
|
45
|
+
type: 'error',
|
|
46
|
+
error: error instanceof Error ? error.message : String(error)
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=parallel-scanner-worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parallel-scanner-worker.js","sourceRoot":"","sources":["../../src/utils/parallel-scanner-worker.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAEH,mDAAwD;AACxD,+DAA2D;AAkB3D,IAAI,2BAAU,EAAE,CAAC;IACf,IAAI,CAAC;QACH,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,2BAAwB,CAAC;QAErE,MAAM,OAAO,GAAG,IAAI,8BAAa,EAAE,CAAC;QAEpC,oBAAoB;QACpB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,CAAC;gBACH,iDAAiD;gBACjD,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;gBAEhD,2BAAU,CAAC,WAAW,CAAC;oBACrB,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE;wBACJ,IAAI;wBACJ,MAAM;qBACP;iBACe,CAAC,CAAC;YACtB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,2BAAU,CAAC,WAAW,CAAC;oBACrB,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE;wBACJ,IAAI;wBACJ,MAAM,EAAE,EAAE;wBACV,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;qBAC9D;iBACe,CAAC,CAAC;YACtB,CAAC;QACH,CAAC;QAED,oBAAoB;QACpB,2BAAU,CAAC,WAAW,CAAC;YACrB,IAAI,EAAE,UAAU;SACA,CAAC,CAAC;IAEtB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAA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