import path from 'path'; import axios from 'axios'; import { Logger } from '../utils/logger.js'; export class StatsReporter { private projectId: string; private apiUrl: string; private apiKey: string; private watchPath: string; private verbose: boolean; constructor(config: { projectId: string; apiUrl: string; apiKey: string; watchPath: string; verbose?: boolean }) { this.projectId = config.projectId; this.apiUrl = config.apiUrl; this.apiKey = config.apiKey; this.watchPath = config.watchPath; this.verbose = !!config.verbose; } public async report(filePath: string, lineCount: number) { const relativePath = path.relative(this.watchPath, filePath); try { await axios.post(`${this.apiUrl}/api/v1/projects/${this.projectId}/stats`, { filePath: relativePath, lineCount, complexityScore: 0 // Placeholder for future cyclomatic complexity }, { headers: { Authorization: `Bearer ${this.apiKey}` } }); } catch (e: any) { if (this.verbose) Logger.warn(`Failed to report stats for ${relativePath}: ${e.message}`); } } }