()
| 31 | } |
| 32 | |
| 33 | function writeToolCallMetricsConfig() { |
| 34 | const outputPath = path.resolve('src/telemetry/tool_call_metrics.json'); |
| 35 | |
| 36 | const dir = path.dirname(outputPath); |
| 37 | if (!fs.existsSync(dir)) { |
| 38 | throw new Error(`Error: Directory ${dir} does not exist.`); |
| 39 | } |
| 40 | |
| 41 | // Avoid 'as ParsedArguments' by using parseArguments |
| 42 | const fullTools = createTools(parseArguments('0.0.0', ['', ''])); |
| 43 | const slimTools = createTools(parseArguments('0.0.0', ['', '', '--slim'])); |
| 44 | |
| 45 | const allTools = [...fullTools, ...slimTools]; |
| 46 | |
| 47 | if (!HaveUniqueNames(allTools)) { |
| 48 | throw new Error('Error: Duplicate tool names found.'); |
| 49 | } |
| 50 | |
| 51 | let existingMetrics: ToolMetric[] = []; |
| 52 | if (fs.existsSync(outputPath)) { |
| 53 | try { |
| 54 | existingMetrics = JSON.parse( |
| 55 | fs.readFileSync(outputPath, 'utf8'), |
| 56 | ) as ToolMetric[]; |
| 57 | } catch { |
| 58 | console.warn( |
| 59 | `Warning: Failed to parse existing metrics from ${outputPath}. Starting fresh.`, |
| 60 | ); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | const newMetrics = generateToolMetrics(allTools); |
| 65 | const mergedMetrics = applyToExistingMetrics(existingMetrics, newMetrics); |
| 66 | |
| 67 | fs.writeFileSync(outputPath, JSON.stringify(mergedMetrics, null, 2) + '\n'); |
| 68 | |
| 69 | console.log( |
| 70 | `Successfully wrote ${mergedMetrics.length} total tool metrics (including deprecated ones) to ${outputPath}`, |
| 71 | ); |
| 72 | } |
| 73 | |
| 74 | function writeFlagUsageMetrics() { |
| 75 | const outputPath = path.resolve('src/telemetry/flag_usage_metrics.json'); |
no test coverage detected