2025-04-18 17:44:24 -07:00
/ * *
* @license
* Copyright 2025 Google LLC
* SPDX - License - Identifier : Apache - 2.0
* /
2025-04-18 11:12:18 -07:00
import yargs from 'yargs/yargs' ;
import { hideBin } from 'yargs/helpers' ;
import process from 'node:process' ;
2025-04-19 19:45:42 +01:00
import {
Config ,
2025-05-23 08:53:22 -07:00
loadServerHierarchicalMemory ,
2025-05-31 12:49:28 -07:00
setGeminiMdFilename as setServerGeminiMdFilename ,
getCurrentGeminiMdFilename ,
2025-06-02 22:05:45 +02:00
ApprovalMode ,
2025-06-13 01:25:42 -07:00
DEFAULT_GEMINI_MODEL ,
DEFAULT_GEMINI_EMBEDDING_MODEL ,
2025-06-13 20:25:59 -04:00
FileDiscoveryService ,
Add telemetry command and refactor telemetry settings (#1060)
#750
### Telemetry Settings
Refactors telemetry configuration to use a nested `telemetry` object in `settings.json`, for example:
```json
{
"telemetry": {
"enabled": true,
"target": "gcp"
"log-prompts": "true"
},
"sandbox": false
}
```
The above includes
- Centralized telemetry settings under a `telemetry` object in `settings.json`.
- CLI flags for the `gemini` command to override all telemetry sub-settings:
- `--telemetry` / `--no-telemetry`
- `--telemetry-target <local|gcp>`
- `--telemetry-otlp-endpoint <URL>`
- `--telemetry-log-prompts` / `--no-telemetry-log-prompts`
- Updates `packages/cli/src/config/config.ts` and `packages/core/src/config/config.ts` to read from the new settings structure and respect the new CLI flags.
- Modifies `scripts/handle-telemetry.js`, `scripts/local_telemetry.js`, and `scripts/telemetry_utils.js` to align with the new settings structure.
- Updates `docs/core/telemetry.md` to reflect the new settings structure, CLI flags, and order of precedence.
- Renames `logUserPromptsEnabled` to `logPrompts` for brevity.
### `npm run telemetry`
Add a new `npm run telemetry` command that uses `scripts/telemetry.js`, automates the entire process of setting up a local and GCP telemetry pipelines, including configuring the necessary settings in the `.gemini/settings.json` workspace file and installing required binaries (e.g. `otelcol-contrib`).
---
```shell
$ npm run telemetry -- --target=gcp
> gemini-cli@0.1.0 telemetry
> node scripts/telemetry.js --target=gcp
⚙️ Using command-line target: gcp
🚀 Running telemetry script for target: gcp.
✨ Starting Local Telemetry Exporter for Google Cloud ✨
⚙️ Enabled telemetry in workspace settings.
🔧 Set telemetry OTLP endpoint to http://localhost:4317.
🎯 Set telemetry target to gcp.
✅ Workspace settings updated.
✅ Using Google Cloud Project ID: foo-bar
🔑 Please ensure you are authenticated with Google Cloud:
- Run `gcloud auth application-default login` OR ensure `GOOGLE_APPLICATION_CREDENTIALS` environment variable points to a valid service account key.
- The account needs "Cloud Trace Agent", "Monitoring Metric Writer", and "Logs Writer" roles.
✅ otelcol-contrib already exists at /Users/jerop/github/gemini-cli/.gemini/otel/bin/otelcol-contrib
🧹 Cleaning up old processes and logs...
✅ Deleted old GCP collector log.
📄 Wrote OTEL collector config to /Users/jerop/github/gemini-cli/.gemini/otel/collector-gcp.yaml
🚀 Starting OTEL collector for GCP... Logs: /Users/jerop/github/gemini-cli/.gemini/otel/collector-gcp.log
⏳ Waiting for OTEL collector to start (PID: 17013)...
✅ OTEL collector started successfully on port 4317.
✨ Local OTEL collector for GCP is running.
🚀 To send telemetry, run the Gemini CLI in a separate terminal window.
📄 Collector logs are being written to: /Users/jerop/github/gemini-cli/.gemini/otel/collector-gcp.log
📊 View your telemetry data in Google Cloud Console:
- Logs: https://console.cloud.google.com/logs/query;query=logName%3D%22projects%2Ffoo-bar%2Flogs%2Fgemini_cli%22?project=foo-bar
- Metrics: https://console.cloud.google.com/monitoring/metrics-explorer?project=foo-bar
- Traces: https://console.cloud.google.com/traces/list?project=foo-bar
Press Ctrl+C to exit.
^C
👋 Shutting down...
⚙️ Disabled telemetry in workspace settings.
🔧 Cleared telemetry OTLP endpoint.
🎯 Cleared telemetry target.
✅ Workspace settings updated.
🛑 Stopping otelcol-contrib (PID: 17013)...
✅ otelcol-contrib stopped.
```
2025-06-15 00:47:32 -04:00
TelemetryTarget ,
2025-06-25 05:41:11 -07:00
} from '@google/gemini-cli-core' ;
2025-05-02 08:15:46 -07:00
import { Settings } from './settings.js' ;
2025-06-19 16:52:22 -07:00
2025-07-08 12:57:34 -04:00
import { Extension , filterActiveExtensions } from './extension.js' ;
2025-06-16 01:13:39 -05:00
import { getCliVersion } from '../utils/version.js' ;
2025-06-18 10:01:00 -07:00
import { loadSandboxConfig } from './sandboxConfig.js' ;
2025-04-18 11:12:18 -07:00
2025-05-14 12:37:17 -07:00
// Simple console logger for now - replace with actual logger if available
const logger = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
debug : ( . . . args : any [ ] ) = > console . debug ( '[DEBUG]' , . . . args ) ,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
warn : ( . . . args : any [ ] ) = > console . warn ( '[WARN]' , . . . args ) ,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
error : ( . . . args : any [ ] ) = > console . error ( '[ERROR]' , . . . args ) ,
} ;
2025-04-18 11:12:18 -07:00
interface CliArgs {
model : string | undefined ;
2025-05-02 08:15:46 -07:00
sandbox : boolean | string | undefined ;
2025-06-18 10:01:00 -07:00
'sandbox-image' : string | undefined ;
2025-05-15 11:38:33 -07:00
debug : boolean | undefined ;
prompt : string | undefined ;
2025-05-15 11:44:56 -07:00
all_files : boolean | undefined ;
2025-05-30 22:18:01 +00:00
show_memory_usage : boolean | undefined ;
2025-06-02 22:05:45 +02:00
yolo : boolean | undefined ;
2025-06-05 16:04:25 -04:00
telemetry : boolean | undefined ;
2025-06-20 00:39:15 -04:00
checkpointing : boolean | undefined ;
Add telemetry command and refactor telemetry settings (#1060)
#750
### Telemetry Settings
Refactors telemetry configuration to use a nested `telemetry` object in `settings.json`, for example:
```json
{
"telemetry": {
"enabled": true,
"target": "gcp"
"log-prompts": "true"
},
"sandbox": false
}
```
The above includes
- Centralized telemetry settings under a `telemetry` object in `settings.json`.
- CLI flags for the `gemini` command to override all telemetry sub-settings:
- `--telemetry` / `--no-telemetry`
- `--telemetry-target <local|gcp>`
- `--telemetry-otlp-endpoint <URL>`
- `--telemetry-log-prompts` / `--no-telemetry-log-prompts`
- Updates `packages/cli/src/config/config.ts` and `packages/core/src/config/config.ts` to read from the new settings structure and respect the new CLI flags.
- Modifies `scripts/handle-telemetry.js`, `scripts/local_telemetry.js`, and `scripts/telemetry_utils.js` to align with the new settings structure.
- Updates `docs/core/telemetry.md` to reflect the new settings structure, CLI flags, and order of precedence.
- Renames `logUserPromptsEnabled` to `logPrompts` for brevity.
### `npm run telemetry`
Add a new `npm run telemetry` command that uses `scripts/telemetry.js`, automates the entire process of setting up a local and GCP telemetry pipelines, including configuring the necessary settings in the `.gemini/settings.json` workspace file and installing required binaries (e.g. `otelcol-contrib`).
---
```shell
$ npm run telemetry -- --target=gcp
> gemini-cli@0.1.0 telemetry
> node scripts/telemetry.js --target=gcp
⚙️ Using command-line target: gcp
🚀 Running telemetry script for target: gcp.
✨ Starting Local Telemetry Exporter for Google Cloud ✨
⚙️ Enabled telemetry in workspace settings.
🔧 Set telemetry OTLP endpoint to http://localhost:4317.
🎯 Set telemetry target to gcp.
✅ Workspace settings updated.
✅ Using Google Cloud Project ID: foo-bar
🔑 Please ensure you are authenticated with Google Cloud:
- Run `gcloud auth application-default login` OR ensure `GOOGLE_APPLICATION_CREDENTIALS` environment variable points to a valid service account key.
- The account needs "Cloud Trace Agent", "Monitoring Metric Writer", and "Logs Writer" roles.
✅ otelcol-contrib already exists at /Users/jerop/github/gemini-cli/.gemini/otel/bin/otelcol-contrib
🧹 Cleaning up old processes and logs...
✅ Deleted old GCP collector log.
📄 Wrote OTEL collector config to /Users/jerop/github/gemini-cli/.gemini/otel/collector-gcp.yaml
🚀 Starting OTEL collector for GCP... Logs: /Users/jerop/github/gemini-cli/.gemini/otel/collector-gcp.log
⏳ Waiting for OTEL collector to start (PID: 17013)...
✅ OTEL collector started successfully on port 4317.
✨ Local OTEL collector for GCP is running.
🚀 To send telemetry, run the Gemini CLI in a separate terminal window.
📄 Collector logs are being written to: /Users/jerop/github/gemini-cli/.gemini/otel/collector-gcp.log
📊 View your telemetry data in Google Cloud Console:
- Logs: https://console.cloud.google.com/logs/query;query=logName%3D%22projects%2Ffoo-bar%2Flogs%2Fgemini_cli%22?project=foo-bar
- Metrics: https://console.cloud.google.com/monitoring/metrics-explorer?project=foo-bar
- Traces: https://console.cloud.google.com/traces/list?project=foo-bar
Press Ctrl+C to exit.
^C
👋 Shutting down...
⚙️ Disabled telemetry in workspace settings.
🔧 Cleared telemetry OTLP endpoint.
🎯 Cleared telemetry target.
✅ Workspace settings updated.
🛑 Stopping otelcol-contrib (PID: 17013)...
✅ otelcol-contrib stopped.
```
2025-06-15 00:47:32 -04:00
telemetryTarget : string | undefined ;
telemetryOtlpEndpoint : string | undefined ;
telemetryLogPrompts : boolean | undefined ;
2025-07-07 12:47:27 -07:00
'allowed-mcp-server-names' : string | undefined ;
2025-07-08 12:57:34 -04:00
extensions : string [ ] | undefined ;
listExtensions : boolean | undefined ;
2025-04-18 11:12:18 -07:00
}
2025-05-01 01:00:53 +00:00
async function parseArguments ( ) : Promise < CliArgs > {
const argv = await yargs ( hideBin ( process . argv ) )
2025-07-07 21:13:31 -04:00
. scriptName ( 'gemini' )
. usage (
'$0 [options]' ,
'Gemini CLI - Launch an interactive CLI, use -p/--prompt for non-interactive mode' ,
)
2025-04-18 11:12:18 -07:00
. option ( 'model' , {
alias : 'm' ,
type : 'string' ,
2025-05-15 11:38:33 -07:00
description : ` Model ` ,
2025-05-17 17:28:44 -07:00
default : process . env . GEMINI_MODEL || DEFAULT_GEMINI_MODEL ,
2025-04-18 11:12:18 -07:00
} )
2025-05-15 11:38:33 -07:00
. option ( 'prompt' , {
alias : 'p' ,
type : 'string' ,
description : 'Prompt. Appended to input on stdin (if any).' ,
} )
2025-05-02 08:15:46 -07:00
. option ( 'sandbox' , {
alias : 's' ,
type : 'boolean' ,
2025-05-15 11:38:33 -07:00
description : 'Run in sandbox?' ,
2025-05-02 08:15:46 -07:00
} )
2025-06-18 10:01:00 -07:00
. option ( 'sandbox-image' , {
type : 'string' ,
description : 'Sandbox image URI.' ,
} )
2025-05-15 11:38:33 -07:00
. option ( 'debug' , {
alias : 'd' ,
2025-04-20 20:20:40 +01:00
type : 'boolean' ,
2025-05-15 11:38:33 -07:00
description : 'Run in debug mode?' ,
2025-04-20 20:20:40 +01:00
default : false ,
} )
2025-05-15 11:44:56 -07:00
. option ( 'all_files' , {
2025-05-15 11:38:33 -07:00
alias : 'a' ,
2025-04-24 16:08:29 -07:00
type : 'boolean' ,
2025-05-15 11:38:33 -07:00
description : 'Include ALL files in context?' ,
2025-04-24 16:08:29 -07:00
default : false ,
} )
2025-05-30 22:18:01 +00:00
. option ( 'show_memory_usage' , {
type : 'boolean' ,
description : 'Show memory usage in status bar' ,
default : false ,
} )
2025-06-02 22:05:45 +02:00
. option ( 'yolo' , {
alias : 'y' ,
type : 'boolean' ,
description :
'Automatically accept all actions (aka YOLO mode, see https://www.youtube.com/watch?v=xvFZjo5PgG0 for more details)?' ,
default : false ,
} )
2025-06-05 16:04:25 -04:00
. option ( 'telemetry' , {
type : 'boolean' ,
Add telemetry command and refactor telemetry settings (#1060)
#750
### Telemetry Settings
Refactors telemetry configuration to use a nested `telemetry` object in `settings.json`, for example:
```json
{
"telemetry": {
"enabled": true,
"target": "gcp"
"log-prompts": "true"
},
"sandbox": false
}
```
The above includes
- Centralized telemetry settings under a `telemetry` object in `settings.json`.
- CLI flags for the `gemini` command to override all telemetry sub-settings:
- `--telemetry` / `--no-telemetry`
- `--telemetry-target <local|gcp>`
- `--telemetry-otlp-endpoint <URL>`
- `--telemetry-log-prompts` / `--no-telemetry-log-prompts`
- Updates `packages/cli/src/config/config.ts` and `packages/core/src/config/config.ts` to read from the new settings structure and respect the new CLI flags.
- Modifies `scripts/handle-telemetry.js`, `scripts/local_telemetry.js`, and `scripts/telemetry_utils.js` to align with the new settings structure.
- Updates `docs/core/telemetry.md` to reflect the new settings structure, CLI flags, and order of precedence.
- Renames `logUserPromptsEnabled` to `logPrompts` for brevity.
### `npm run telemetry`
Add a new `npm run telemetry` command that uses `scripts/telemetry.js`, automates the entire process of setting up a local and GCP telemetry pipelines, including configuring the necessary settings in the `.gemini/settings.json` workspace file and installing required binaries (e.g. `otelcol-contrib`).
---
```shell
$ npm run telemetry -- --target=gcp
> gemini-cli@0.1.0 telemetry
> node scripts/telemetry.js --target=gcp
⚙️ Using command-line target: gcp
🚀 Running telemetry script for target: gcp.
✨ Starting Local Telemetry Exporter for Google Cloud ✨
⚙️ Enabled telemetry in workspace settings.
🔧 Set telemetry OTLP endpoint to http://localhost:4317.
🎯 Set telemetry target to gcp.
✅ Workspace settings updated.
✅ Using Google Cloud Project ID: foo-bar
🔑 Please ensure you are authenticated with Google Cloud:
- Run `gcloud auth application-default login` OR ensure `GOOGLE_APPLICATION_CREDENTIALS` environment variable points to a valid service account key.
- The account needs "Cloud Trace Agent", "Monitoring Metric Writer", and "Logs Writer" roles.
✅ otelcol-contrib already exists at /Users/jerop/github/gemini-cli/.gemini/otel/bin/otelcol-contrib
🧹 Cleaning up old processes and logs...
✅ Deleted old GCP collector log.
📄 Wrote OTEL collector config to /Users/jerop/github/gemini-cli/.gemini/otel/collector-gcp.yaml
🚀 Starting OTEL collector for GCP... Logs: /Users/jerop/github/gemini-cli/.gemini/otel/collector-gcp.log
⏳ Waiting for OTEL collector to start (PID: 17013)...
✅ OTEL collector started successfully on port 4317.
✨ Local OTEL collector for GCP is running.
🚀 To send telemetry, run the Gemini CLI in a separate terminal window.
📄 Collector logs are being written to: /Users/jerop/github/gemini-cli/.gemini/otel/collector-gcp.log
📊 View your telemetry data in Google Cloud Console:
- Logs: https://console.cloud.google.com/logs/query;query=logName%3D%22projects%2Ffoo-bar%2Flogs%2Fgemini_cli%22?project=foo-bar
- Metrics: https://console.cloud.google.com/monitoring/metrics-explorer?project=foo-bar
- Traces: https://console.cloud.google.com/traces/list?project=foo-bar
Press Ctrl+C to exit.
^C
👋 Shutting down...
⚙️ Disabled telemetry in workspace settings.
🔧 Cleared telemetry OTLP endpoint.
🎯 Cleared telemetry target.
✅ Workspace settings updated.
🛑 Stopping otelcol-contrib (PID: 17013)...
✅ otelcol-contrib stopped.
```
2025-06-15 00:47:32 -04:00
description :
'Enable telemetry? This flag specifically controls if telemetry is sent. Other --telemetry-* flags set specific values but do not enable telemetry on their own.' ,
} )
. option ( 'telemetry-target' , {
type : 'string' ,
choices : [ 'local' , 'gcp' ] ,
description :
'Set the telemetry target (local or gcp). Overrides settings files.' ,
} )
. option ( 'telemetry-otlp-endpoint' , {
type : 'string' ,
description :
'Set the OTLP endpoint for telemetry. Overrides environment variables and settings files.' ,
} )
. option ( 'telemetry-log-prompts' , {
type : 'boolean' ,
description :
'Enable or disable logging of user prompts for telemetry. Overrides settings files.' ,
2025-06-05 16:04:25 -04:00
} )
2025-06-20 00:39:15 -04:00
. option ( 'checkpointing' , {
2025-06-11 15:33:09 -04:00
alias : 'c' ,
type : 'boolean' ,
description : 'Enables checkpointing of file edits' ,
default : false ,
} )
2025-07-07 12:47:27 -07:00
. option ( 'allowed-mcp-server-names' , {
2025-07-07 09:45:58 -07:00
type : 'string' ,
description : 'Allowed MCP server names' ,
} )
2025-07-08 12:57:34 -04:00
. option ( 'extensions' , {
alias : 'e' ,
type : 'array' ,
string : true ,
description :
'A list of extensions to use. If not provided, all extensions are used.' ,
} )
. option ( 'list-extensions' , {
alias : 'l' ,
type : 'boolean' ,
description : 'List all available extensions and exit.' ,
} )
2025-06-18 09:57:17 -07:00
. version ( await getCliVersion ( ) ) // This will enable the --version flag based on package.json
2025-06-16 01:13:39 -05:00
. alias ( 'v' , 'version' )
2025-04-18 11:12:18 -07:00
. help ( )
. alias ( 'h' , 'help' )
2025-04-19 19:45:42 +01:00
. strict ( ) . argv ;
2025-05-14 12:37:17 -07:00
2025-06-03 13:47:53 -07:00
return argv ;
2025-05-14 12:37:17 -07:00
}
2025-05-23 08:53:22 -07:00
// This function is now a thin wrapper around the server's implementation.
// It's kept in the CLI for now as App.tsx directly calls it for memory refresh.
// TODO: Consider if App.tsx should get memory via a server call or if Config should refresh itself.
2025-05-14 12:37:17 -07:00
export async function loadHierarchicalGeminiMemory (
currentWorkingDirectory : string ,
debugMode : boolean ,
2025-06-13 20:25:59 -04:00
fileService : FileDiscoveryService ,
2025-06-11 13:34:35 -07:00
extensionContextFilePaths : string [ ] = [ ] ,
2025-05-14 15:19:45 -07:00
) : Promise < { memoryContent : string ; fileCount : number } > {
2025-05-23 08:53:22 -07:00
if ( debugMode ) {
2025-05-14 12:37:17 -07:00
logger . debug (
2025-05-23 08:53:22 -07:00
` CLI: Delegating hierarchical memory load to server for CWD: ${ currentWorkingDirectory } ` ,
2025-05-14 12:37:17 -07:00
) ;
}
2025-05-23 08:53:22 -07:00
// Directly call the server function.
// The server function will use its own homedir() for the global path.
2025-06-11 13:34:35 -07:00
return loadServerHierarchicalMemory (
currentWorkingDirectory ,
debugMode ,
2025-06-13 20:25:59 -04:00
fileService ,
2025-06-11 13:34:35 -07:00
extensionContextFilePaths ,
) ;
2025-04-18 11:12:18 -07:00
}
2025-06-02 13:55:54 -07:00
export async function loadCliConfig (
settings : Settings ,
2025-06-13 13:57:00 -07:00
extensions : Extension [ ] ,
2025-06-11 04:46:39 +00:00
sessionId : string ,
2025-06-07 11:12:30 -07:00
) : Promise < Config > {
2025-05-01 01:00:53 +00:00
const argv = await parseArguments ( ) ;
2025-07-08 12:34:17 -07:00
const debugMode =
argv . debug ||
[ process . env . DEBUG , process . env . DEBUG_MODE ] . some (
( v ) = > v === 'true' || v === '1' ,
) ;
2025-05-14 12:37:17 -07:00
2025-07-08 12:57:34 -04:00
const activeExtensions = filterActiveExtensions (
extensions ,
argv . extensions || [ ] ,
) ;
2025-05-31 12:49:28 -07:00
// Set the context filename in the server's memoryTool module BEFORE loading memory
// TODO(b/343434939): This is a bit of a hack. The contextFileName should ideally be passed
// directly to the Config constructor in core, and have core handle setGeminiMdFilename.
// However, loadHierarchicalGeminiMemory is called *before* createServerConfig.
if ( settings . contextFileName ) {
setServerGeminiMdFilename ( settings . contextFileName ) ;
} else {
// Reset to default if not provided in settings.
setServerGeminiMdFilename ( getCurrentGeminiMdFilename ( ) ) ;
}
2025-07-08 12:57:34 -04:00
const extensionContextFilePaths = activeExtensions . flatMap (
( e ) = > e . contextFiles ,
) ;
2025-06-11 13:34:35 -07:00
2025-06-13 20:25:59 -04:00
const fileService = new FileDiscoveryService ( process . cwd ( ) ) ;
2025-05-23 08:53:22 -07:00
// Call the (now wrapper) loadHierarchicalGeminiMemory which calls the server's version
2025-05-14 15:19:45 -07:00
const { memoryContent , fileCount } = await loadHierarchicalGeminiMemory (
2025-05-14 12:37:17 -07:00
process . cwd ( ) ,
debugMode ,
2025-06-13 20:25:59 -04:00
fileService ,
2025-06-11 13:34:35 -07:00
extensionContextFilePaths ,
2025-05-14 12:37:17 -07:00
) ;
2025-04-19 19:45:42 +01:00
2025-07-08 12:57:34 -04:00
let mcpServers = mergeMcpServers ( settings , activeExtensions ) ;
const excludeTools = mergeExcludeTools ( settings , activeExtensions ) ;
2025-06-10 15:48:39 -07:00
2025-07-07 12:47:27 -07:00
if ( argv [ 'allowed-mcp-server-names' ] ) {
2025-07-07 09:45:58 -07:00
const allowedNames = new Set (
2025-07-07 12:47:27 -07:00
argv [ 'allowed-mcp-server-names' ] . split ( ',' ) . filter ( Boolean ) ,
2025-07-07 09:45:58 -07:00
) ;
if ( allowedNames . size > 0 ) {
mcpServers = Object . fromEntries (
Object . entries ( mcpServers ) . filter ( ( [ key ] ) = > allowedNames . has ( key ) ) ,
) ;
} else {
mcpServers = { } ;
}
}
2025-06-18 10:01:00 -07:00
const sandboxConfig = await loadSandboxConfig ( settings , argv ) ;
2025-06-07 13:49:00 -07:00
return new Config ( {
2025-06-11 04:46:39 +00:00
sessionId ,
2025-06-07 13:38:05 -07:00
embeddingModel : DEFAULT_GEMINI_EMBEDDING_MODEL ,
2025-06-18 10:01:00 -07:00
sandbox : sandboxConfig ,
2025-05-29 20:51:17 +00:00
targetDir : process.cwd ( ) ,
2025-05-14 12:37:17 -07:00
debugMode ,
2025-05-29 20:51:17 +00:00
question : argv.prompt || '' ,
fullContext : argv.all_files || false ,
coreTools : settings.coreTools || undefined ,
2025-07-01 16:13:46 -07:00
excludeTools ,
2025-05-29 20:51:17 +00:00
toolDiscoveryCommand : settings.toolDiscoveryCommand ,
toolCallCommand : settings.toolCallCommand ,
mcpServerCommand : settings.mcpServerCommand ,
2025-06-10 15:48:39 -07:00
mcpServers ,
2025-05-29 20:51:17 +00:00
userMemory : memoryContent ,
geminiMdFileCount : fileCount ,
2025-06-02 22:05:45 +02:00
approvalMode : argv.yolo || false ? ApprovalMode.YOLO : ApprovalMode.DEFAULT ,
2025-05-31 12:49:28 -07:00
showMemoryUsage :
argv . show_memory_usage || settings . showMemoryUsage || false ,
2025-06-04 00:46:57 -07:00
accessibility : settings.accessibility ,
Add telemetry command and refactor telemetry settings (#1060)
#750
### Telemetry Settings
Refactors telemetry configuration to use a nested `telemetry` object in `settings.json`, for example:
```json
{
"telemetry": {
"enabled": true,
"target": "gcp"
"log-prompts": "true"
},
"sandbox": false
}
```
The above includes
- Centralized telemetry settings under a `telemetry` object in `settings.json`.
- CLI flags for the `gemini` command to override all telemetry sub-settings:
- `--telemetry` / `--no-telemetry`
- `--telemetry-target <local|gcp>`
- `--telemetry-otlp-endpoint <URL>`
- `--telemetry-log-prompts` / `--no-telemetry-log-prompts`
- Updates `packages/cli/src/config/config.ts` and `packages/core/src/config/config.ts` to read from the new settings structure and respect the new CLI flags.
- Modifies `scripts/handle-telemetry.js`, `scripts/local_telemetry.js`, and `scripts/telemetry_utils.js` to align with the new settings structure.
- Updates `docs/core/telemetry.md` to reflect the new settings structure, CLI flags, and order of precedence.
- Renames `logUserPromptsEnabled` to `logPrompts` for brevity.
### `npm run telemetry`
Add a new `npm run telemetry` command that uses `scripts/telemetry.js`, automates the entire process of setting up a local and GCP telemetry pipelines, including configuring the necessary settings in the `.gemini/settings.json` workspace file and installing required binaries (e.g. `otelcol-contrib`).
---
```shell
$ npm run telemetry -- --target=gcp
> gemini-cli@0.1.0 telemetry
> node scripts/telemetry.js --target=gcp
⚙️ Using command-line target: gcp
🚀 Running telemetry script for target: gcp.
✨ Starting Local Telemetry Exporter for Google Cloud ✨
⚙️ Enabled telemetry in workspace settings.
🔧 Set telemetry OTLP endpoint to http://localhost:4317.
🎯 Set telemetry target to gcp.
✅ Workspace settings updated.
✅ Using Google Cloud Project ID: foo-bar
🔑 Please ensure you are authenticated with Google Cloud:
- Run `gcloud auth application-default login` OR ensure `GOOGLE_APPLICATION_CREDENTIALS` environment variable points to a valid service account key.
- The account needs "Cloud Trace Agent", "Monitoring Metric Writer", and "Logs Writer" roles.
✅ otelcol-contrib already exists at /Users/jerop/github/gemini-cli/.gemini/otel/bin/otelcol-contrib
🧹 Cleaning up old processes and logs...
✅ Deleted old GCP collector log.
📄 Wrote OTEL collector config to /Users/jerop/github/gemini-cli/.gemini/otel/collector-gcp.yaml
🚀 Starting OTEL collector for GCP... Logs: /Users/jerop/github/gemini-cli/.gemini/otel/collector-gcp.log
⏳ Waiting for OTEL collector to start (PID: 17013)...
✅ OTEL collector started successfully on port 4317.
✨ Local OTEL collector for GCP is running.
🚀 To send telemetry, run the Gemini CLI in a separate terminal window.
📄 Collector logs are being written to: /Users/jerop/github/gemini-cli/.gemini/otel/collector-gcp.log
📊 View your telemetry data in Google Cloud Console:
- Logs: https://console.cloud.google.com/logs/query;query=logName%3D%22projects%2Ffoo-bar%2Flogs%2Fgemini_cli%22?project=foo-bar
- Metrics: https://console.cloud.google.com/monitoring/metrics-explorer?project=foo-bar
- Traces: https://console.cloud.google.com/traces/list?project=foo-bar
Press Ctrl+C to exit.
^C
👋 Shutting down...
⚙️ Disabled telemetry in workspace settings.
🔧 Cleared telemetry OTLP endpoint.
🎯 Cleared telemetry target.
✅ Workspace settings updated.
🛑 Stopping otelcol-contrib (PID: 17013)...
✅ otelcol-contrib stopped.
```
2025-06-15 00:47:32 -04:00
telemetry : {
enabled : argv.telemetry ? ? settings . telemetry ? . enabled ,
target : ( argv . telemetryTarget ? ?
settings . telemetry ? . target ) as TelemetryTarget ,
otlpEndpoint :
argv . telemetryOtlpEndpoint ? ?
process . env . OTEL_EXPORTER_OTLP_ENDPOINT ? ?
settings . telemetry ? . otlpEndpoint ,
logPrompts : argv.telemetryLogPrompts ? ? settings . telemetry ? . logPrompts ,
} ,
2025-06-23 20:29:31 -04:00
usageStatisticsEnabled : settings.usageStatisticsEnabled ? ? true ,
Ignore folders files (#651)
# Add .gitignore-Aware File Filtering to gemini-cli
This pull request introduces .gitignore-based file filtering to the gemini-cli, ensuring that git-ignored files are automatically excluded from file-related operations and suggestions throughout the CLI. The update enhances usability, reduces noise from build artifacts and dependencies, and provides new configuration options for fine-tuning file discovery.
Key Improvements
.gitignore File Filtering
All @ (at) commands, file completions, and core discovery tools now honor .gitignore patterns by default.
Git-ignored files (such as node_modules/, dist/, .env, and .git) are excluded from results unless explicitly overridden.
The behavior can be customized via a new fileFiltering section in settings.json, including options for:
Turning .gitignore respect on/off.
Adding custom ignore patterns.
Allowing or excluding build artifacts.
Configuration & Documentation Updates
settings.json schema extended with fileFiltering options.
Documentation updated to explain new filtering controls and usage patterns.
Testing
New and updated integration/unit tests for file filtering logic, configuration merging, and edge cases.
Test coverage ensures .gitignore filtering works as intended across different workflows.
Internal Refactoring
Core file discovery logic refactored for maintainability and extensibility.
Underlying tools (ls, glob, read-many-files) now support git-aware filtering out of the box.
Co-authored-by: N. Taylor Mullen <ntaylormullen@google.com>
2025-06-03 21:40:46 -07:00
// Git-aware file filtering settings
2025-06-21 18:23:35 -07:00
fileFiltering : {
respectGitIgnore : settings.fileFiltering?.respectGitIgnore ,
enableRecursiveFileSearch :
settings . fileFiltering ? . enableRecursiveFileSearch ,
} ,
2025-06-20 00:39:15 -04:00
checkpointing : argv.checkpointing || settings . checkpointing ? . enabled ,
2025-06-12 17:17:29 -07:00
proxy :
process . env . HTTPS_PROXY ||
process . env . https_proxy ||
process . env . HTTP_PROXY ||
process . env . http_proxy ,
cwd : process.cwd ( ) ,
2025-06-13 20:25:59 -04:00
fileDiscoveryService : fileService ,
2025-06-14 00:00:24 -07:00
bugCommand : settings.bugCommand ,
2025-06-19 16:52:22 -07:00
model : argv.model ! ,
2025-06-22 16:17:05 -07:00
extensionContextFilePaths ,
2025-07-08 12:57:34 -04:00
listExtensions : argv.listExtensions || false ,
activeExtensions : activeExtensions.map ( ( e ) = > ( {
name : e.config.name ,
version : e.config.version ,
} ) ) ,
2025-06-07 13:49:00 -07:00
} ) ;
2025-04-18 11:12:18 -07:00
}
2025-06-07 16:17:27 -07:00
2025-06-13 13:57:00 -07:00
function mergeMcpServers ( settings : Settings , extensions : Extension [ ] ) {
2025-06-13 14:51:29 -07:00
const mcpServers = { . . . ( settings . mcpServers || { } ) } ;
2025-06-10 15:48:39 -07:00
for ( const extension of extensions ) {
2025-06-13 13:57:00 -07:00
Object . entries ( extension . config . mcpServers || { } ) . forEach (
( [ key , server ] ) = > {
if ( mcpServers [ key ] ) {
logger . warn (
` Skipping extension MCP config for server with key " ${ key } " as it already exists. ` ,
) ;
return ;
}
mcpServers [ key ] = server ;
} ,
) ;
2025-06-10 15:48:39 -07:00
}
return mcpServers ;
}
2025-07-01 16:13:46 -07:00
function mergeExcludeTools (
settings : Settings ,
extensions : Extension [ ] ,
) : string [ ] {
const allExcludeTools = new Set ( settings . excludeTools || [ ] ) ;
for ( const extension of extensions ) {
for ( const tool of extension . config . excludeTools || [ ] ) {
allExcludeTools . add ( tool ) ;
}
}
return [ . . . allExcludeTools ] ;
}