From 714421c2da4f5d6b9c1c7060fdf5c47ba1c965ca Mon Sep 17 00:00:00 2001 From: Jerop Kipruto Date: Sun, 15 Jun 2025 16:24:53 -0400 Subject: Add file operation telemetry (#1068) Introduces telemetry for file create, read, and update operations. This change adds the `gemini_cli.file.operation.count` metric, recorded by the `read-file`, `read-many-files`, and `write-file` tools. The metric includes the following attributes: - `operation` (string: `create`, `read`, `update`): The type of file operation. - `lines` (optional, Int): Number of lines in the file. - `mimetype` (optional, string): Mimetype of the file. - `extension` (optional, string): File extension of the file. Here is a stacked bar chart of file operations by extension (`js`, `ts`, `md`): ![image](https://github.com/user-attachments/assets/3e8f8ea9-6155-4186-863c-075cc47647c5) Here is a stacked bar chart of file operations by type (`create`, `read`, `update`): ![image](https://github.com/user-attachments/assets/3fcf491d-31d0-4ba8-80e6-7fd2bd9c7c27) #750 cc @allenhutchison as discussed --- packages/core/src/utils/fileUtils.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'packages/core/src/utils/fileUtils.ts') diff --git a/packages/core/src/utils/fileUtils.ts b/packages/core/src/utils/fileUtils.ts index d726c053..cb4d333a 100644 --- a/packages/core/src/utils/fileUtils.ts +++ b/packages/core/src/utils/fileUtils.ts @@ -16,6 +16,16 @@ const MAX_LINE_LENGTH_TEXT_FILE = 2000; // Default values for encoding and separator format export const DEFAULT_ENCODING: BufferEncoding = 'utf-8'; +/** + * Looks up the specific MIME type for a file path. + * @param filePath Path to the file. + * @returns The specific MIME type string (e.g., 'text/python', 'application/javascript') or undefined if not found or ambiguous. + */ +export function getSpecificMimeType(filePath: string): string | undefined { + const lookedUpMime = mime.lookup(filePath); + return typeof lookedUpMime === 'string' ? lookedUpMime : undefined; +} + /** * Checks if a path is within a given root directory. * @param pathToCheck The absolute path to check. -- cgit v1.2.3