31 lines
923 B
JavaScript
31 lines
923 B
JavaScript
/**
|
|
* Telemetry for compressed tools usage tracking
|
|
* Logs to ~/.local/share/mcp/compressed-tools.jsonl
|
|
*/
|
|
import { appendFileSync, mkdirSync, existsSync } from "fs";
|
|
import { homedir } from "os";
|
|
import { join } from "path";
|
|
const LOG_DIR = join(homedir(), ".local", "share", "mcp");
|
|
const LOG_FILE = join(LOG_DIR, "compressed-tools.jsonl");
|
|
// Ensure log directory exists
|
|
if (!existsSync(LOG_DIR)) {
|
|
mkdirSync(LOG_DIR, { recursive: true });
|
|
}
|
|
export function logTelemetry(event) {
|
|
const entry = {
|
|
timestamp: new Date().toISOString(),
|
|
...event,
|
|
};
|
|
try {
|
|
appendFileSync(LOG_FILE, JSON.stringify(entry) + "\n");
|
|
}
|
|
catch {
|
|
// Silently fail - telemetry should never break the tool
|
|
}
|
|
}
|
|
export function calculateCompressionRatio(original, compressed) {
|
|
if (original === 0)
|
|
return 0;
|
|
return Math.round((1 - compressed / original) * 100 * 10) / 10;
|
|
}
|