build: Add telemetry compiled output
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
30
dist/index.js
vendored
30
dist/index.js
vendored
@@ -18,6 +18,7 @@ import { execSync } from "child_process";
|
|||||||
import { compressRead } from "./compressors/read.js";
|
import { compressRead } from "./compressors/read.js";
|
||||||
import { compressGrep } from "./compressors/grep.js";
|
import { compressGrep } from "./compressors/grep.js";
|
||||||
import { compressGlob } from "./compressors/glob.js";
|
import { compressGlob } from "./compressors/glob.js";
|
||||||
|
import { logTelemetry, calculateCompressionRatio } from "./telemetry.js";
|
||||||
// Configuration from environment
|
// Configuration from environment
|
||||||
const COMPRESSION_LEVEL = process.env.COMPRESSION_LEVEL || "medium";
|
const COMPRESSION_LEVEL = process.env.COMPRESSION_LEVEL || "medium";
|
||||||
// Compression presets
|
// Compression presets
|
||||||
@@ -155,6 +156,15 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|||||||
removeComments: !args?.keepComments,
|
removeComments: !args?.keepComments,
|
||||||
};
|
};
|
||||||
const result = compressRead(content, path, options);
|
const result = compressRead(content, path, options);
|
||||||
|
// Log telemetry
|
||||||
|
logTelemetry({
|
||||||
|
tool: "compressed_read",
|
||||||
|
inputSize: result.originalLines,
|
||||||
|
outputSize: result.compressedLines,
|
||||||
|
compressionRatio: calculateCompressionRatio(result.originalLines, result.compressedLines),
|
||||||
|
path,
|
||||||
|
success: true,
|
||||||
|
});
|
||||||
return {
|
return {
|
||||||
content: [
|
content: [
|
||||||
{
|
{
|
||||||
@@ -191,6 +201,16 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|||||||
maxMatchesPerFile: args?.maxMatchesPerFile || preset.grep.maxMatchesPerFile,
|
maxMatchesPerFile: args?.maxMatchesPerFile || preset.grep.maxMatchesPerFile,
|
||||||
};
|
};
|
||||||
const result = compressGrep(output, options);
|
const result = compressGrep(output, options);
|
||||||
|
// Log telemetry
|
||||||
|
logTelemetry({
|
||||||
|
tool: "compressed_grep",
|
||||||
|
inputSize: result.originalMatches,
|
||||||
|
outputSize: result.compressedMatches,
|
||||||
|
compressionRatio: calculateCompressionRatio(result.originalMatches, result.compressedMatches),
|
||||||
|
path: searchPath,
|
||||||
|
pattern,
|
||||||
|
success: true,
|
||||||
|
});
|
||||||
return {
|
return {
|
||||||
content: [
|
content: [
|
||||||
{
|
{
|
||||||
@@ -233,6 +253,16 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|||||||
maxFiles: args?.maxFiles || preset.glob.maxFiles,
|
maxFiles: args?.maxFiles || preset.glob.maxFiles,
|
||||||
};
|
};
|
||||||
const result = compressGlob(paths, options);
|
const result = compressGlob(paths, options);
|
||||||
|
// Log telemetry
|
||||||
|
logTelemetry({
|
||||||
|
tool: "compressed_glob",
|
||||||
|
inputSize: paths.length,
|
||||||
|
outputSize: result.compressedCount,
|
||||||
|
compressionRatio: calculateCompressionRatio(paths.length, result.compressedCount),
|
||||||
|
path: basePath,
|
||||||
|
pattern,
|
||||||
|
success: true,
|
||||||
|
});
|
||||||
return {
|
return {
|
||||||
content: [
|
content: [
|
||||||
{
|
{
|
||||||
|
|||||||
17
dist/telemetry.d.ts
vendored
Normal file
17
dist/telemetry.d.ts
vendored
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
/**
|
||||||
|
* Telemetry for compressed tools usage tracking
|
||||||
|
* Logs to ~/.local/share/mcp/compressed-tools.jsonl
|
||||||
|
*/
|
||||||
|
export interface TelemetryEvent {
|
||||||
|
timestamp: string;
|
||||||
|
tool: "compressed_read" | "compressed_grep" | "compressed_glob";
|
||||||
|
inputSize: number;
|
||||||
|
outputSize: number;
|
||||||
|
compressionRatio: number;
|
||||||
|
path?: string;
|
||||||
|
pattern?: string;
|
||||||
|
success: boolean;
|
||||||
|
error?: string;
|
||||||
|
}
|
||||||
|
export declare function logTelemetry(event: Omit<TelemetryEvent, "timestamp">): void;
|
||||||
|
export declare function calculateCompressionRatio(original: number, compressed: number): number;
|
||||||
30
dist/telemetry.js
vendored
Normal file
30
dist/telemetry.js
vendored
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user