@neurolint/cli
Version:
NeuroLint CLI for React/Next.js modernization with advanced 6-layer orchestration and intelligent AST transformations
119 lines (104 loc) • 2.87 kB
JavaScript
/**
* CLI Telemetry
* Optional usage tracking for monitoring and improvements
*/
const { NeuroLintAPIClient } = require('./api-client');
class TelemetryTracker {
constructor(options = {}) {
this.enabled = options.enabled !== false; // Default to enabled
this.apiClient = new NeuroLintAPIClient();
this.userId = options.userId || null;
}
/**
* Track command usage
*/
async trackCommand(command, options = {}) {
if (!this.enabled) return;
try {
const telemetryData = {
action: 'command_executed',
userId: this.userId,
command: command,
layersUsed: options.layers || [],
executionTime: options.executionTime || 0,
success: options.success !== false,
errorType: options.errorType || null,
metadata: {
version: '1.2.0',
platform: process.platform,
nodeVersion: process.version,
...options.metadata
}
};
// Send telemetry (fire and forget)
this.apiClient.request('/api/monitoring/usage', {
method: 'POST',
body: telemetryData
}).catch(error => {
// Silent fail for telemetry
console.debug('Telemetry failed:', error.message);
});
} catch (error) {
// Silent fail for telemetry
console.debug('Telemetry error:', error.message);
}
}
/**
* Track analysis usage
*/
async trackAnalysis(result, options = {}) {
if (!this.enabled) return;
try {
await this.trackCommand('analyze', {
success: result.success,
executionTime: result.metadata?.executionTime,
layers: options.layers,
metadata: {
filesProcessed: result.analysis?.layerResults?.length || 0,
issuesFound: result.analysis?.issues?.length || 0
}
});
} catch (error) {
console.debug('Analysis telemetry error:', error.message);
}
}
/**
* Track fix usage
*/
async trackFix(result, options = {}) {
if (!this.enabled) return;
try {
await this.trackCommand('fix', {
success: result.success,
executionTime: result.metadata?.executionTime,
layers: result.analysis?.layersApplied,
metadata: {
changesApplied: result.changes?.hasChanges || false,
lineChanges: result.changes?.lineChanges || 0,
improvements: result.analysis?.improvements?.length || 0
}
});
} catch (error) {
console.debug('Fix telemetry error:', error.message);
}
}
/**
* Enable or disable telemetry
*/
setEnabled(enabled) {
this.enabled = enabled;
}
/**
* Set user ID for tracking
*/
setUserId(userId) {
this.userId = userId;
}
/**
* Check if telemetry is enabled
*/
isEnabled() {
return this.enabled;
}
}
module.exports = { TelemetryTracker };