vibecodingmachine-core 2026.2.20-438 → 2026.2.26-1739
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/README.md +240 -0
- package/package.json +10 -2
- package/src/agents/Agent.js +300 -0
- package/src/agents/AgentAdditionService.js +311 -0
- package/src/agents/AgentCheckService.js +690 -0
- package/src/agents/AgentInstallationService.js +140 -0
- package/src/agents/AgentSetupService.js +467 -0
- package/src/agents/AgentStatus.js +183 -0
- package/src/agents/AgentVerificationService.js +634 -0
- package/src/agents/ConfigurationSchemaValidator.js +543 -0
- package/src/agents/EnvironmentConfigurationManager.js +602 -0
- package/src/agents/InstallationErrorHandler.js +372 -0
- package/src/agents/InstallationLog.js +363 -0
- package/src/agents/InstallationMethod.js +510 -0
- package/src/agents/InstallationOrchestrator.js +352 -0
- package/src/agents/InstallationProgressReporter.js +372 -0
- package/src/agents/InstallationRetryManager.js +322 -0
- package/src/agents/InstallationType.js +254 -0
- package/src/agents/OperationTypes.js +310 -0
- package/src/agents/PerformanceMetricsCollector.js +493 -0
- package/src/agents/SecurityValidationService.js +534 -0
- package/src/agents/VerificationTest.js +354 -0
- package/src/agents/VerificationType.js +226 -0
- package/src/agents/WindowsPermissionHandler.js +518 -0
- package/src/agents/config/AgentConfigManager.js +393 -0
- package/src/agents/config/AgentDefaultsRegistry.js +373 -0
- package/src/agents/config/ConfigValidator.js +281 -0
- package/src/agents/discovery/AgentDiscoveryService.js +707 -0
- package/src/agents/logging/AgentLogger.js +511 -0
- package/src/agents/status/AgentStatusManager.js +481 -0
- package/src/agents/storage/FileManager.js +454 -0
- package/src/agents/verification/AgentCommunicationTester.js +474 -0
- package/src/agents/verification/BaseVerifier.js +430 -0
- package/src/agents/verification/CommandVerifier.js +480 -0
- package/src/agents/verification/FileOperationVerifier.js +453 -0
- package/src/agents/verification/ResultAnalyzer.js +707 -0
- package/src/agents/verification/TestRequirementManager.js +495 -0
- package/src/agents/verification/VerificationRunner.js +433 -0
- package/src/agents/windows/BaseWindowsInstaller.js +441 -0
- package/src/agents/windows/ChocolateyInstaller.js +509 -0
- package/src/agents/windows/DirectInstaller.js +443 -0
- package/src/agents/windows/InstallerFactory.js +391 -0
- package/src/agents/windows/NpmInstaller.js +505 -0
- package/src/agents/windows/PowerShellInstaller.js +458 -0
- package/src/agents/windows/WinGetInstaller.js +390 -0
- package/src/analysis/analysis-reporter.js +132 -0
- package/src/analysis/boundary-detector.js +712 -0
- package/src/analysis/categorizer.js +340 -0
- package/src/analysis/codebase-scanner.js +384 -0
- package/src/analysis/line-counter.js +513 -0
- package/src/analysis/priority-calculator.js +679 -0
- package/src/analysis/report/analysis-report.js +250 -0
- package/src/analysis/report/package-analyzer.js +278 -0
- package/src/analysis/report/recommendation-generator.js +382 -0
- package/src/analysis/report/statistics-generator.js +515 -0
- package/src/analysis/reports/analysis-report-model.js +101 -0
- package/src/analysis/reports/recommendation-generator.js +283 -0
- package/src/analysis/reports/report-generators.js +191 -0
- package/src/analysis/reports/statistics-calculator.js +231 -0
- package/src/analysis/reports/trend-analyzer.js +219 -0
- package/src/analysis/strategy-generator.js +814 -0
- package/src/auto-mode/AutoModeBusinessLogic.js +836 -0
- package/src/config/refactoring-config.js +307 -0
- package/src/health-tracking/json-storage.js +38 -2
- package/src/ide-integration/applescript-manager-core.js +233 -0
- package/src/ide-integration/applescript-manager.cjs +357 -28
- package/src/ide-integration/applescript-manager.js +89 -3599
- package/src/ide-integration/cdp-manager.js +306 -0
- package/src/ide-integration/claude-code-cli-manager.cjs +1 -1
- package/src/ide-integration/continuation-handler.js +337 -0
- package/src/ide-integration/ide-status-checker.js +292 -0
- package/src/ide-integration/macos-ide-manager.js +627 -0
- package/src/ide-integration/macos-text-sender.js +528 -0
- package/src/ide-integration/response-reader.js +548 -0
- package/src/ide-integration/windows-automation-manager.js +121 -0
- package/src/ide-integration/windows-ide-manager.js +373 -0
- package/src/index.cjs +25 -3
- package/src/index.js +15 -1
- package/src/llm/direct-llm-manager.cjs +90 -2
- package/src/models/compliance-report.js +538 -0
- package/src/models/file-analysis.js +681 -0
- package/src/models/refactoring-plan.js +770 -0
- package/src/monitoring/alert-system.js +834 -0
- package/src/monitoring/compliance-progress-tracker.js +437 -0
- package/src/monitoring/continuous-scan-notifications.js +661 -0
- package/src/monitoring/continuous-scanner.js +279 -0
- package/src/monitoring/file-monitor/file-analyzer.js +262 -0
- package/src/monitoring/file-monitor/file-monitor.js +237 -0
- package/src/monitoring/file-monitor/watcher.js +194 -0
- package/src/monitoring/file-monitor.js +17 -0
- package/src/monitoring/notification-manager.js +437 -0
- package/src/monitoring/scanner-core.js +368 -0
- package/src/monitoring/scanner-events.js +214 -0
- package/src/monitoring/violation-notification-system.js +515 -0
- package/src/refactoring/boundaries/cohesion-analyzer.js +316 -0
- package/src/refactoring/boundaries/extraction-result.js +285 -0
- package/src/refactoring/boundaries/extraction-strategies.js +392 -0
- package/src/refactoring/boundaries/module-boundary.js +209 -0
- package/src/refactoring/boundary/boundary-detector.js +741 -0
- package/src/refactoring/boundary/boundary-types.js +405 -0
- package/src/refactoring/boundary/extraction-strategies.js +554 -0
- package/src/refactoring/boundary-extraction-result.js +77 -0
- package/src/refactoring/boundary-extraction-strategies.js +330 -0
- package/src/refactoring/boundary-extractor.js +384 -0
- package/src/refactoring/boundary-types.js +46 -0
- package/src/refactoring/circular/circular-dependency.js +88 -0
- package/src/refactoring/circular/cycle-detection.js +147 -0
- package/src/refactoring/circular/dependency-node.js +82 -0
- package/src/refactoring/circular/dependency-result.js +107 -0
- package/src/refactoring/circular/dependency-types.js +58 -0
- package/src/refactoring/circular/graph-builder.js +213 -0
- package/src/refactoring/circular/resolution-strategy.js +72 -0
- package/src/refactoring/circular/strategy-generator.js +229 -0
- package/src/refactoring/circular-dependency-resolver-original.js +809 -0
- package/src/refactoring/circular-dependency-resolver.js +200 -0
- package/src/refactoring/code-mover.js +761 -0
- package/src/refactoring/file-splitter.js +696 -0
- package/src/refactoring/functionality-validator.js +816 -0
- package/src/refactoring/import-manager.js +774 -0
- package/src/refactoring/module-boundary.js +107 -0
- package/src/refactoring/refactoring-executor.js +672 -0
- package/src/refactoring/refactoring-rollback.js +614 -0
- package/src/refactoring/test-validator.js +631 -0
- package/src/requirement-management/default-requirement-manager.js +321 -0
- package/src/requirement-management/requirement-file-parser.js +159 -0
- package/src/requirement-management/requirement-sequencer.js +221 -0
- package/src/rui/commands/AgentCommandParser.js +600 -0
- package/src/rui/commands/AgentCommands.js +487 -0
- package/src/rui/commands/AgentResponseFormatter.js +832 -0
- package/src/scripts/verify-full-compliance.js +269 -0
- package/src/sync/sync-engine-core.js +1 -0
- package/src/sync/sync-engine-remote-handlers.js +135 -0
- package/src/task-generation/automated-task-generator.js +351 -0
- package/src/task-generation/prioritizer.js +287 -0
- package/src/task-generation/task-list-updater.js +215 -0
- package/src/task-generation/task-management-integration.js +480 -0
- package/src/task-generation/task-manager-integration.js +270 -0
- package/src/task-generation/violation-task-generator.js +474 -0
- package/src/task-management/continuous-scan-integration.js +342 -0
- package/src/timeout-management/index.js +12 -3
- package/src/timeout-management/response-time-tracker.js +167 -0
- package/src/timeout-management/timeout-calculator.js +159 -0
- package/src/timeout-management/timeout-config-manager.js +172 -0
- package/src/utils/ast-analyzer.js +417 -0
- package/src/utils/current-requirement-manager.js +276 -0
- package/src/utils/current-requirement-operations.js +472 -0
- package/src/utils/dependency-mapper.js +456 -0
- package/src/utils/download-with-progress.js +4 -2
- package/src/utils/electron-update-checker.js +4 -1
- package/src/utils/file-size-analyzer.js +272 -0
- package/src/utils/import-updater.js +280 -0
- package/src/utils/refactoring-tools.js +512 -0
- package/src/utils/report-generator.js +569 -0
- package/src/utils/reports/report-analysis.js +218 -0
- package/src/utils/reports/report-types.js +55 -0
- package/src/utils/reports/summary-generators.js +102 -0
- package/src/utils/requirement-file-management.js +157 -0
- package/src/utils/requirement-helpers/requirement-file-ops.js +392 -0
- package/src/utils/requirement-helpers/requirement-mover.js +414 -0
- package/src/utils/requirement-helpers/requirement-parser.js +326 -0
- package/src/utils/requirement-helpers/requirement-status.js +320 -0
- package/src/utils/requirement-helpers-new.js +55 -0
- package/src/utils/requirement-helpers-refactored.js +367 -0
- package/src/utils/requirement-helpers.js +291 -1191
- package/src/utils/requirement-movement-operations.js +450 -0
- package/src/utils/requirement-movement.js +312 -0
- package/src/utils/requirement-parsing-helpers.js +56 -0
- package/src/utils/requirement-statistics.js +200 -0
- package/src/utils/requirement-text-utils.js +58 -0
- package/src/utils/rollback/rollback-handlers.js +125 -0
- package/src/utils/rollback/rollback-operation.js +63 -0
- package/src/utils/rollback/rollback-recorder.js +166 -0
- package/src/utils/rollback/rollback-state-manager.js +175 -0
- package/src/utils/rollback/rollback-types.js +33 -0
- package/src/utils/rollback/rollback-utils.js +110 -0
- package/src/utils/rollback-manager-original.js +569 -0
- package/src/utils/rollback-manager.js +202 -0
- package/src/utils/smoke-test-cli.js +362 -0
- package/src/utils/smoke-test-gui.js +351 -0
- package/src/utils/smoke-test-orchestrator.js +321 -0
- package/src/utils/smoke-test-runner.js +60 -0
- package/src/utils/smoke-test-web.js +347 -0
- package/src/utils/specification-helpers.js +39 -13
- package/src/utils/specification-migration.js +97 -0
- package/src/utils/test-runner.js +579 -0
- package/src/utils/validation-framework.js +518 -0
- package/src/validation/compliance-analyzer.js +197 -0
- package/src/validation/compliance-report-generator.js +343 -0
- package/src/validation/compliance-reporter.js +711 -0
- package/src/validation/compliance-rules.js +127 -0
- package/src/validation/constitution-validator-new.js +196 -0
- package/src/validation/constitution-validator.js +17 -0
- package/src/validation/file-validators.js +170 -0
- package/src/validation/line-limit/file-analyzer.js +201 -0
- package/src/validation/line-limit/line-limit-validator.js +208 -0
- package/src/validation/line-limit/validation-result.js +144 -0
- package/src/validation/line-limit-core.js +225 -0
- package/src/validation/line-limit-reporter.js +134 -0
- package/src/validation/line-limit-result.js +125 -0
- package/src/validation/line-limit-validator.js +41 -0
- package/src/validation/metrics-calculator.js +660 -0
- package/src/sync/sync-engine-backup.js +0 -559
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Continuous Repository Scanner
|
|
3
|
+
*
|
|
4
|
+
* Continuously scans the repository to identify files that exceed the 555-line limit
|
|
5
|
+
* and triggers appropriate actions for compliance management.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { ScannerCore } = require('./scanner-core');
|
|
9
|
+
const { ScannerEventsManager } = require('./scanner-events');
|
|
10
|
+
const { NotificationManager } = require('./notification-manager');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Continuous Scanner - Main orchestrator
|
|
14
|
+
*/
|
|
15
|
+
class ContinuousScanner {
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
this.options = {
|
|
18
|
+
autoStart: options.autoStart || false,
|
|
19
|
+
enableNotifications: options.enableNotifications !== false,
|
|
20
|
+
notificationThreshold: options.notificationThreshold || 5,
|
|
21
|
+
...options
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
this.core = new ScannerCore(options);
|
|
25
|
+
this.events = new ScannerEventsManager(options);
|
|
26
|
+
|
|
27
|
+
// Initialize notification manager
|
|
28
|
+
this.notificationManager = new NotificationManager({
|
|
29
|
+
enabled: options.enableNotifications !== false,
|
|
30
|
+
channels: options.notificationChannels || ['console', 'file'],
|
|
31
|
+
violationThreshold: options.notificationThreshold || 1,
|
|
32
|
+
criticalViolationThreshold: options.criticalNotificationThreshold || 10,
|
|
33
|
+
enableDesktop: options.enableDesktopNotifications !== false,
|
|
34
|
+
logFile: options.notificationLogFile || './logs/continuous-scan-notifications.log'
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
this._setupEventHandlers();
|
|
38
|
+
|
|
39
|
+
if (this.options.autoStart) {
|
|
40
|
+
this.start();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Start scanning
|
|
46
|
+
*/
|
|
47
|
+
start() {
|
|
48
|
+
this.core.start();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Get notification statistics
|
|
53
|
+
*/
|
|
54
|
+
getNotificationStats() {
|
|
55
|
+
if (!this.notificationSystem) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return this.notificationSystem.getStats();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Stop scanning
|
|
64
|
+
*/
|
|
65
|
+
stop() {
|
|
66
|
+
this.core.stop();
|
|
67
|
+
|
|
68
|
+
// Shutdown notification system
|
|
69
|
+
if (this.notificationSystem) {
|
|
70
|
+
this.notificationSystem.shutdown();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Get current status
|
|
76
|
+
*/
|
|
77
|
+
getStatus() {
|
|
78
|
+
return {
|
|
79
|
+
isRunning: this.core.isRunning,
|
|
80
|
+
results: this.core.getResults(),
|
|
81
|
+
violations: this.core.getViolations(),
|
|
82
|
+
eventStats: this.events.getEventStats(),
|
|
83
|
+
recentEvents: this.events.getRecentEvents(10)
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Get compliance report
|
|
89
|
+
*/
|
|
90
|
+
getComplianceReport() {
|
|
91
|
+
const results = this.core.getResults();
|
|
92
|
+
const violations = this.core.getViolations();
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
timestamp: new Date().toISOString(),
|
|
96
|
+
summary: {
|
|
97
|
+
totalFiles: results.size,
|
|
98
|
+
compliantFiles: Array.from(results.values()).filter(r => r.violations.length === 0).length,
|
|
99
|
+
nonCompliantFiles: violations.length,
|
|
100
|
+
totalViolations: violations.reduce((sum, v) => sum + v.violations.length, 0)
|
|
101
|
+
},
|
|
102
|
+
violations: violations,
|
|
103
|
+
recommendations: this._generateRecommendations(violations)
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Setup event handlers
|
|
109
|
+
*/
|
|
110
|
+
_setupEventHandlers() {
|
|
111
|
+
// Forward core events to events manager
|
|
112
|
+
this.core.on('started', () => {
|
|
113
|
+
this.events.emitWithLogging('scanner_started', {});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
this.core.on('stopped', () => {
|
|
117
|
+
this.events.emitWithLogging('scanner_stopped', {});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
this.core.on('scan_completed', async (data) => {
|
|
121
|
+
this.events.emitWithLogging('scan_completed', data);
|
|
122
|
+
|
|
123
|
+
// Handle violations through notification manager
|
|
124
|
+
if (data.violations && data.violations.length > 0) {
|
|
125
|
+
await this.notificationManager.handleNewViolations(data.violations, {
|
|
126
|
+
scanType: 'continuous',
|
|
127
|
+
timestamp: data.timestamp
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// Check for new violations
|
|
131
|
+
this.events.emitWithLogging('violations_found', {
|
|
132
|
+
count: data.violations.length,
|
|
133
|
+
violations: data.violations
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// Send legacy notifications if enabled
|
|
137
|
+
if (this.options.enableNotifications && data.violations.length >= this.options.notificationThreshold) {
|
|
138
|
+
this._sendNotification(data);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
this.core.on('error', (error) => {
|
|
144
|
+
this.events.emitWithLogging('error', error);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
this.core.on('warning', (warning) => {
|
|
148
|
+
this.events.emitWithLogging('warning', warning);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
this.core.on('event', (event) => {
|
|
152
|
+
this.events.emitWithLogging('file_event', event);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Generate unique scan ID
|
|
158
|
+
*/
|
|
159
|
+
generateScanId() {
|
|
160
|
+
return `scan-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Generate recommendations based on violations
|
|
165
|
+
*/
|
|
166
|
+
_generateRecommendations(violations) {
|
|
167
|
+
const recommendations = [];
|
|
168
|
+
|
|
169
|
+
if (violations.length === 0) {
|
|
170
|
+
recommendations.push({
|
|
171
|
+
type: 'success',
|
|
172
|
+
title: 'All Files Compliant',
|
|
173
|
+
description: 'No files exceed the 555-line limit. Great job!',
|
|
174
|
+
priority: 'low'
|
|
175
|
+
});
|
|
176
|
+
return recommendations;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Group violations by type
|
|
180
|
+
const violationTypes = {};
|
|
181
|
+
for (const violation of violations) {
|
|
182
|
+
for (const v of violation.violations) {
|
|
183
|
+
violationTypes[v.rule] = (violationTypes[v.rule] || 0) + 1;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Generate recommendations for each violation type
|
|
188
|
+
if (violationTypes.maxFileSize > 0) {
|
|
189
|
+
recommendations.push({
|
|
190
|
+
type: 'action_required',
|
|
191
|
+
title: 'Refactor Large Files',
|
|
192
|
+
description: `${violationTypes.maxFileSize} files exceed the 555-line limit`,
|
|
193
|
+
priority: 'high',
|
|
194
|
+
action: 'Use the refactoring tools to split large files into smaller modules'
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (violationTypes.noTrailingWhitespace > 5) {
|
|
199
|
+
recommendations.push({
|
|
200
|
+
type: 'suggestion',
|
|
201
|
+
title: 'Fix Trailing Whitespace',
|
|
202
|
+
description: `${violationTypes.noTrailingWhitespace} files have trailing whitespace`,
|
|
203
|
+
priority: 'medium',
|
|
204
|
+
action: 'Configure your editor to trim trailing whitespace on save'
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (violationTypes.fileEndsWithNewline > 5) {
|
|
209
|
+
recommendations.push({
|
|
210
|
+
type: 'suggestion',
|
|
211
|
+
title: 'Add Newline to File End',
|
|
212
|
+
description: `${violationTypes.fileEndsWithNewline} files don\'t end with newline`,
|
|
213
|
+
priority: 'low',
|
|
214
|
+
action: 'Configure your editor to add newline at end of file'
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return recommendations;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Get notification statistics
|
|
223
|
+
*/
|
|
224
|
+
getNotificationStats() {
|
|
225
|
+
return this.notificationManager.getStats();
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Test notification system
|
|
230
|
+
*/
|
|
231
|
+
async testNotifications() {
|
|
232
|
+
return await this.notificationManager.testNotification();
|
|
233
|
+
}
|
|
234
|
+
_sendNotification(data) {
|
|
235
|
+
// Create detailed alert for violations
|
|
236
|
+
if (data.violations.length > 0) {
|
|
237
|
+
const alert = {
|
|
238
|
+
id: `continuous-scan-${Date.now()}`,
|
|
239
|
+
category: 'file_size',
|
|
240
|
+
severity: data.violations.length > 10 ? 'critical' : 'warning',
|
|
241
|
+
title: `Continuous Scan Detected ${data.violations.length} Violations`,
|
|
242
|
+
message: `${data.violations.length} files exceed the 555-line limit detected during continuous scanning`,
|
|
243
|
+
description: `Files requiring immediate refactoring attention`,
|
|
244
|
+
filePath: 'Multiple files',
|
|
245
|
+
metadata: {
|
|
246
|
+
timestamp: new Date().toISOString(),
|
|
247
|
+
source: 'continuous-scanner',
|
|
248
|
+
scanType: 'continuous',
|
|
249
|
+
violationCount: data.violations.length,
|
|
250
|
+
violations: data.violations.map(v => ({
|
|
251
|
+
filePath: v.filePath,
|
|
252
|
+
lineCount: v.lineCount,
|
|
253
|
+
excessLines: v.lineCount - 555
|
|
254
|
+
}))
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
// Emit notification event for external handlers
|
|
259
|
+
this.events.emitWithLogging('violation_alert', alert);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Emit notification event for external handlers
|
|
263
|
+
this.events.emitWithLogging('notification_sent', {
|
|
264
|
+
type: 'violations_detected',
|
|
265
|
+
count: data.violations.length,
|
|
266
|
+
data
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Export singleton instance
|
|
272
|
+
const scanner = new ContinuousScanner();
|
|
273
|
+
|
|
274
|
+
module.exports = {
|
|
275
|
+
ContinuousScanner,
|
|
276
|
+
scanner,
|
|
277
|
+
ScannerCore,
|
|
278
|
+
ScannerEventsManager
|
|
279
|
+
};
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Analysis for Monitoring
|
|
3
|
+
*
|
|
4
|
+
* Analyzes files for compliance issues during monitoring.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const { LineLimitValidator } = require('../../validation/line-limit-validator');
|
|
10
|
+
const ConstitutionValidator = require('../../validation/constitution-validator');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* File analyzer for monitoring
|
|
14
|
+
*/
|
|
15
|
+
class MonitoringFileAnalyzer {
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
this.options = {
|
|
18
|
+
lineLimit: 555,
|
|
19
|
+
checkConstitutional: true,
|
|
20
|
+
checkCommonIssues: true,
|
|
21
|
+
...options
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
this.lineValidator = new LineLimitValidator();
|
|
25
|
+
this.constitutionValidator = new ConstitutionValidator();
|
|
26
|
+
|
|
27
|
+
// Cache analysis results to avoid repeated work
|
|
28
|
+
this.analysisCache = new Map();
|
|
29
|
+
this.cacheTimeout = options.cacheTimeout || 30000; // 30 seconds
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Analyze a file for compliance issues
|
|
34
|
+
*/
|
|
35
|
+
async analyzeFile(filePath, eventType = 'change') {
|
|
36
|
+
const cacheKey = `${filePath}:${eventType}`;
|
|
37
|
+
|
|
38
|
+
// Check cache first
|
|
39
|
+
if (this.analysisCache.has(cacheKey)) {
|
|
40
|
+
const cached = this.analysisCache.get(cacheKey);
|
|
41
|
+
if (Date.now() - cached.timestamp < this.cacheTimeout) {
|
|
42
|
+
return cached.result;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
const result = await this.performAnalysis(filePath, eventType);
|
|
48
|
+
|
|
49
|
+
// Cache the result
|
|
50
|
+
this.analysisCache.set(cacheKey, {
|
|
51
|
+
result,
|
|
52
|
+
timestamp: Date.now()
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Clean up old cache entries
|
|
56
|
+
this.cleanupCache();
|
|
57
|
+
|
|
58
|
+
return result;
|
|
59
|
+
|
|
60
|
+
} catch (error) {
|
|
61
|
+
const errorResult = {
|
|
62
|
+
filePath,
|
|
63
|
+
eventType,
|
|
64
|
+
success: false,
|
|
65
|
+
error: error.message,
|
|
66
|
+
timestamp: new Date().toISOString()
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
return errorResult;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Perform the actual file analysis
|
|
75
|
+
*/
|
|
76
|
+
async performAnalysis(filePath, eventType) {
|
|
77
|
+
const result = {
|
|
78
|
+
filePath,
|
|
79
|
+
eventType,
|
|
80
|
+
success: true,
|
|
81
|
+
timestamp: new Date().toISOString(),
|
|
82
|
+
issues: [],
|
|
83
|
+
metrics: {
|
|
84
|
+
lineCount: 0,
|
|
85
|
+
fileSize: 0,
|
|
86
|
+
lastModified: null
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
// Get file stats
|
|
92
|
+
const stats = fs.statSync(filePath);
|
|
93
|
+
result.metrics.fileSize = stats.size;
|
|
94
|
+
result.metrics.lastModified = stats.mtime.toISOString();
|
|
95
|
+
|
|
96
|
+
// Only analyze source code files
|
|
97
|
+
if (!this.shouldAnalyzeFile(filePath)) {
|
|
98
|
+
result.skipped = true;
|
|
99
|
+
result.reason = 'File type not analyzed';
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Check line limit compliance
|
|
104
|
+
if (this.options.checkLineLimit) {
|
|
105
|
+
const lineResult = this.lineValidator.validateFile(filePath, this.options.lineLimit);
|
|
106
|
+
result.metrics.lineCount = lineResult.lineCount;
|
|
107
|
+
|
|
108
|
+
if (!lineResult.isValid) {
|
|
109
|
+
result.issues.push({
|
|
110
|
+
type: 'line_limit',
|
|
111
|
+
severity: lineResult.severity,
|
|
112
|
+
message: `File exceeds ${this.options.lineLimit} line limit (${lineResult.lineCount} lines)`,
|
|
113
|
+
details: lineResult.getSummary()
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Check constitutional compliance
|
|
119
|
+
if (this.options.checkConstitutional) {
|
|
120
|
+
try {
|
|
121
|
+
const constitutionResult = this.constitutionValidator.validateFile(filePath);
|
|
122
|
+
|
|
123
|
+
if (!constitutionResult.compliant) {
|
|
124
|
+
result.issues.push({
|
|
125
|
+
type: 'constitutional',
|
|
126
|
+
severity: constitutionResult.severity || 'warning',
|
|
127
|
+
message: 'Constitutional compliance issues detected',
|
|
128
|
+
details: constitutionResult.issues || []
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
} catch (error) {
|
|
132
|
+
// Constitutional validation might fail for non-code files
|
|
133
|
+
// Don't treat this as a critical error
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Check for common issues
|
|
138
|
+
if (this.options.checkCommonIssues) {
|
|
139
|
+
const commonIssues = this.checkCommonIssues(filePath);
|
|
140
|
+
result.issues.push(...commonIssues);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
result.compliant = result.issues.length === 0;
|
|
144
|
+
|
|
145
|
+
} catch (error) {
|
|
146
|
+
result.success = false;
|
|
147
|
+
result.error = error.message;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Check if a file should be analyzed
|
|
155
|
+
*/
|
|
156
|
+
shouldAnalyzeFile(filePath) {
|
|
157
|
+
const ext = path.extname(filePath);
|
|
158
|
+
|
|
159
|
+
// Source code extensions to analyze
|
|
160
|
+
const sourceExtensions = new Set([
|
|
161
|
+
'.js', '.jsx', '.ts', '.tsx', '.vue', '.py', '.java', '.cpp', '.c', '.h',
|
|
162
|
+
'.cs', '.php', '.rb', '.go', '.rs', '.swift', '.kt', '.scala', '.sh',
|
|
163
|
+
'.html', '.css', '.scss', '.sass', '.less', '.md', '.yml', '.yaml'
|
|
164
|
+
]);
|
|
165
|
+
|
|
166
|
+
return sourceExtensions.has(ext);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Check for common file issues
|
|
171
|
+
*/
|
|
172
|
+
checkCommonIssues(filePath) {
|
|
173
|
+
const issues = [];
|
|
174
|
+
|
|
175
|
+
try {
|
|
176
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
177
|
+
const lines = content.split('\n');
|
|
178
|
+
|
|
179
|
+
// Check for trailing whitespace
|
|
180
|
+
let trailingWhitespaceCount = 0;
|
|
181
|
+
lines.forEach((line, index) => {
|
|
182
|
+
if (line.endsWith(' ') || line.endsWith('\t')) {
|
|
183
|
+
trailingWhitespaceCount++;
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
if (trailingWhitespaceCount > 0) {
|
|
188
|
+
issues.push({
|
|
189
|
+
type: 'trailing_whitespace',
|
|
190
|
+
severity: 'warning',
|
|
191
|
+
message: `File has ${trailingWhitespaceCount} lines with trailing whitespace`,
|
|
192
|
+
count: trailingWhitespaceCount
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Check if file ends with newline
|
|
197
|
+
if (content.length > 0 && !content.endsWith('\n')) {
|
|
198
|
+
issues.push({
|
|
199
|
+
type: 'missing_newline',
|
|
200
|
+
severity: 'info',
|
|
201
|
+
message: 'File does not end with newline character'
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Check for very long lines
|
|
206
|
+
let longLineCount = 0;
|
|
207
|
+
lines.forEach(line => {
|
|
208
|
+
if (line.length > 200) {
|
|
209
|
+
longLineCount++;
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
if (longLineCount > 0) {
|
|
214
|
+
issues.push({
|
|
215
|
+
type: 'long_lines',
|
|
216
|
+
severity: 'info',
|
|
217
|
+
message: `File has ${longLineCount} lines over 200 characters`,
|
|
218
|
+
count: longLineCount
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
} catch (error) {
|
|
223
|
+
// If we can't read the file, skip common issues check
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return issues;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Clean up old cache entries
|
|
231
|
+
*/
|
|
232
|
+
cleanupCache() {
|
|
233
|
+
const now = Date.now();
|
|
234
|
+
|
|
235
|
+
for (const [key, cached] of this.analysisCache.entries()) {
|
|
236
|
+
if (now - cached.timestamp > this.cacheTimeout) {
|
|
237
|
+
this.analysisCache.delete(key);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Clear the analysis cache
|
|
244
|
+
*/
|
|
245
|
+
clearCache() {
|
|
246
|
+
this.analysisCache.clear();
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Get cache statistics
|
|
251
|
+
*/
|
|
252
|
+
getCacheStats() {
|
|
253
|
+
return {
|
|
254
|
+
size: this.analysisCache.size,
|
|
255
|
+
timeout: this.cacheTimeout
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
module.exports = {
|
|
261
|
+
MonitoringFileAnalyzer
|
|
262
|
+
};
|