diff --git a/.prettierrc.json b/.prettierrc.json index fa9699b895..5ce969b197 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -3,5 +3,15 @@ "trailingComma": "all", "singleQuote": true, "printWidth": 80, - "tabWidth": 2 + "tabWidth": 2, + "overrides": [ + { + "files": ["**/*.md"], + "options": { + "tabWidth": 2, + "printWidth": 80, + "proseWrap": "always" + } + } + ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index ea2735760a..3661ecf9c2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,5 +13,8 @@ "[javascript]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, + "[markdown]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, "vitest.disableWorkspaceWarning": true } diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b84a0b6bb1..437ed94835 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,8 +20,8 @@ sign a new one. ### Review our Community Guidelines -This project follows [Google's Open Source Community -Guidelines](https://opensource.google/conduct/). +This project follows +[Google's Open Source Community Guidelines](https://opensource.google/conduct/). ## Contribution Process @@ -33,72 +33,106 @@ for this purpose. ### Self Assigning Issues -If you're looking for an issue to work on, check out our list of issues that are labeled ["help wanted"](https://github.com/google-gemini/gemini-cli/issues?q=is%3Aissue+state%3Aopen+label%3A%22help+wanted%22). +If you're looking for an issue to work on, check out our list of issues that are +labeled +["help wanted"](https://github.com/google-gemini/gemini-cli/issues?q=is%3Aissue+state%3Aopen+label%3A%22help+wanted%22). -To assign an issue to yourself, simply add a comment with the text `/assign`. The comment must contain only that text and nothing else. This command will assign the issue to you, provided it is not already assigned. +To assign an issue to yourself, simply add a comment with the text `/assign`. +The comment must contain only that text and nothing else. This command will +assign the issue to you, provided it is not already assigned. -Please note that you can have a maximum of 3 issues assigned to you at any given time. +Please note that you can have a maximum of 3 issues assigned to you at any given +time. ### Pull Request Guidelines -To help us review and merge your PRs quickly, please follow these guidelines. PRs that do not meet these standards may be closed. +To help us review and merge your PRs quickly, please follow these guidelines. +PRs that do not meet these standards may be closed. #### 1. Link to an Existing Issue -All PRs should be linked to an existing issue in our tracker. This ensures that every change has been discussed and is aligned with the project's goals before any code is written. +All PRs should be linked to an existing issue in our tracker. This ensures that +every change has been discussed and is aligned with the project's goals before +any code is written. - **For bug fixes:** The PR should be linked to the bug report issue. -- **For features:** The PR should be linked to the feature request or proposal issue that has been approved by a maintainer. +- **For features:** The PR should be linked to the feature request or proposal + issue that has been approved by a maintainer. -If an issue for your change doesn't exist, please **open one first** and wait for feedback before you start coding. +If an issue for your change doesn't exist, please **open one first** and wait +for feedback before you start coding. #### 2. Keep It Small and Focused -We favor small, atomic PRs that address a single issue or add a single, self-contained feature. +We favor small, atomic PRs that address a single issue or add a single, +self-contained feature. - **Do:** Create a PR that fixes one specific bug or adds one specific feature. -- **Don't:** Bundle multiple unrelated changes (e.g., a bug fix, a new feature, and a refactor) into a single PR. +- **Don't:** Bundle multiple unrelated changes (e.g., a bug fix, a new feature, + and a refactor) into a single PR. -Large changes should be broken down into a series of smaller, logical PRs that can be reviewed and merged independently. +Large changes should be broken down into a series of smaller, logical PRs that +can be reviewed and merged independently. #### 3. Use Draft PRs for Work in Progress -If you'd like to get early feedback on your work, please use GitHub's **Draft Pull Request** feature. This signals to the maintainers that the PR is not yet ready for a formal review but is open for discussion and initial feedback. +If you'd like to get early feedback on your work, please use GitHub's **Draft +Pull Request** feature. This signals to the maintainers that the PR is not yet +ready for a formal review but is open for discussion and initial feedback. #### 4. Ensure All Checks Pass -Before submitting your PR, ensure that all automated checks are passing by running `npm run preflight`. This command runs all tests, linting, and other style checks. +Before submitting your PR, ensure that all automated checks are passing by +running `npm run preflight`. This command runs all tests, linting, and other +style checks. #### 5. Update Documentation -If your PR introduces a user-facing change (e.g., a new command, a modified flag, or a change in behavior), you must also update the relevant documentation in the `/docs` directory. +If your PR introduces a user-facing change (e.g., a new command, a modified +flag, or a change in behavior), you must also update the relevant documentation +in the `/docs` directory. #### 6. Write Clear Commit Messages and a Good PR Description -Your PR should have a clear, descriptive title and a detailed description of the changes. Follow the [Conventional Commits](https://www.conventionalcommits.org/) standard for your commit messages. +Your PR should have a clear, descriptive title and a detailed description of the +changes. Follow the [Conventional Commits](https://www.conventionalcommits.org/) +standard for your commit messages. - **Good PR Title:** `feat(cli): Add --json flag to 'config get' command` - **Bad PR Title:** `Made some changes` -In the PR description, explain the "why" behind your changes and link to the relevant issue (e.g., `Fixes #123`). +In the PR description, explain the "why" behind your changes and link to the +relevant issue (e.g., `Fixes #123`). ## Forking -If you are forking the repository you will be able to run the Build, Test and Integration test workflows. However in order to make the integration tests run you'll need to add a [GitHub Repository Secret](https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository) with a value of `GEMINI_API_KEY` and set that to a valid API key that you have available. Your key and secret are private to your repo; no one without access can see your key and you cannot see any secrets related to this repo. +If you are forking the repository you will be able to run the Build, Test and +Integration test workflows. However in order to make the integration tests run +you'll need to add a +[GitHub Repository Secret](https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository) +with a value of `GEMINI_API_KEY` and set that to a valid API key that you have +available. Your key and secret are private to your repo; no one without access +can see your key and you cannot see any secrets related to this repo. -Additionally you will need to click on the `Actions` tab and enable workflows for your repository, you'll find it's the large blue button in the center of the screen. +Additionally you will need to click on the `Actions` tab and enable workflows +for your repository, you'll find it's the large blue button in the center of the +screen. ## Development Setup and Workflow -This section guides contributors on how to build, modify, and understand the development setup of this project. +This section guides contributors on how to build, modify, and understand the +development setup of this project. ### Setting Up the Development Environment **Prerequisites:** 1. **Node.js**: - - **Development:** Please use Node.js `~20.19.0`. This specific version is required due to an upstream development dependency issue. You can use a tool like [nvm](https://github.com/nvm-sh/nvm) to manage Node.js versions. - - **Production:** For running the CLI in a production environment, any version of Node.js `>=20` is acceptable. + - **Development:** Please use Node.js `~20.19.0`. This specific version is + required due to an upstream development dependency issue. You can use a + tool like [nvm](https://github.com/nvm-sh/nvm) to manage Node.js versions. + - **Production:** For running the CLI in a production environment, any + version of Node.js `>=20` is acceptable. 2. **Git** ### Build Process @@ -122,13 +156,19 @@ To build the entire project (all packages): npm run build ``` -This command typically compiles TypeScript to JavaScript, bundles assets, and prepares the packages for execution. Refer to `scripts/build.js` and `package.json` scripts for more details on what happens during the build. +This command typically compiles TypeScript to JavaScript, bundles assets, and +prepares the packages for execution. Refer to `scripts/build.js` and +`package.json` scripts for more details on what happens during the build. ### Enabling Sandboxing -[Sandboxing](#sandboxing) is highly recommended and requires, at a minimum, setting `GEMINI_SANDBOX=true` in your `~/.env` and ensuring a sandboxing provider (e.g. `macOS Seatbelt`, `docker`, or `podman`) is available. See [Sandboxing](#sandboxing) for details. +[Sandboxing](#sandboxing) is highly recommended and requires, at a minimum, +setting `GEMINI_SANDBOX=true` in your `~/.env` and ensuring a sandboxing +provider (e.g. `macOS Seatbelt`, `docker`, or `podman`) is available. See +[Sandboxing](#sandboxing) for details. -To build both the `gemini` CLI utility and the sandbox container, run `build:all` from the root directory: +To build both the `gemini` CLI utility and the sandbox container, run +`build:all` from the root directory: ```bash npm run build:all @@ -138,13 +178,17 @@ To skip building the sandbox container, you can use `npm run build` instead. ### Running -To start the Gemini CLI from the source code (after building), run the following command from the root directory: +To start the Gemini CLI from the source code (after building), run the following +command from the root directory: ```bash npm start ``` -If you'd like to run the source build outside of the gemini-cli folder, you can utilize `npm link path/to/gemini-cli/packages/cli` (see: [docs](https://docs.npmjs.com/cli/v9/commands/npm-link)) or `alias gemini="node path/to/gemini-cli/packages/cli"` to run with `gemini` +If you'd like to run the source build outside of the gemini-cli folder, you can +utilize `npm link path/to/gemini-cli/packages/cli` (see: +[docs](https://docs.npmjs.com/cli/v9/commands/npm-link)) or +`alias gemini="node path/to/gemini-cli/packages/cli"` to run with `gemini` ### Running Tests @@ -158,11 +202,14 @@ To execute the unit test suite for the project: npm run test ``` -This will run tests located in the `packages/core` and `packages/cli` directories. Ensure tests pass before submitting any changes. For a more comprehensive check, it is recommended to run `npm run preflight`. +This will run tests located in the `packages/core` and `packages/cli` +directories. Ensure tests pass before submitting any changes. For a more +comprehensive check, it is recommended to run `npm run preflight`. #### Integration Tests -The integration tests are designed to validate the end-to-end functionality of the Gemini CLI. They are not run as part of the default `npm run test` command. +The integration tests are designed to validate the end-to-end functionality of +the Gemini CLI. They are not run as part of the default `npm run test` command. To run the integration tests, use the following command: @@ -170,7 +217,8 @@ To run the integration tests, use the following command: npm run test:e2e ``` -For more detailed information on the integration testing framework, please see the [Integration Tests documentation](./docs/integration-tests.md). +For more detailed information on the integration testing framework, please see +the [Integration Tests documentation](./docs/integration-tests.md). ### Linting and Preflight Checks @@ -180,11 +228,13 @@ To ensure code quality and formatting consistency, run the preflight check: npm run preflight ``` -This command will run ESLint, Prettier, all tests, and other checks as defined in the project's `package.json`. +This command will run ESLint, Prettier, all tests, and other checks as defined +in the project's `package.json`. _ProTip_ -after cloning create a git precommit hook file to ensure your commits are always clean. +after cloning create a git precommit hook file to ensure your commits are always +clean. ```bash echo " @@ -198,17 +248,20 @@ fi #### Formatting -To separately format the code in this project by running the following command from the root directory: +To separately format the code in this project by running the following command +from the root directory: ```bash npm run format ``` -This command uses Prettier to format the code according to the project's style guidelines. +This command uses Prettier to format the code according to the project's style +guidelines. #### Linting -To separately lint the code in this project, run the following command from the root directory: +To separately lint the code in this project, run the following command from the +root directory: ```bash npm run lint @@ -216,9 +269,15 @@ npm run lint ### Coding Conventions -- Please adhere to the coding style, patterns, and conventions used throughout the existing codebase. -- Consult [GEMINI.md](https://github.com/google-gemini/gemini-cli/blob/main/GEMINI.md) (typically found in the project root) for specific instructions related to AI-assisted development, including conventions for React, comments, and Git usage. -- **Imports:** Pay special attention to import paths. The project uses ESLint to enforce restrictions on relative imports between packages. +- Please adhere to the coding style, patterns, and conventions used throughout + the existing codebase. +- Consult + [GEMINI.md](https://github.com/google-gemini/gemini-cli/blob/main/GEMINI.md) + (typically found in the project root) for specific instructions related to + AI-assisted development, including conventions for React, comments, and Git + usage. +- **Imports:** Pay special attention to import paths. The project uses ESLint to + enforce restrictions on relative imports between packages. ### Project Structure @@ -239,10 +298,16 @@ For more detailed architecture, see `docs/architecture.md`. ```bash npm run debug ``` - This command runs `node --inspect-brk dist/gemini.js` within the `packages/cli` directory, pausing execution until a debugger attaches. You can then open `chrome://inspect` in your Chrome browser to connect to the debugger. -2. In VS Code, use the "Attach" launch configuration (found in `.vscode/launch.json`). + This command runs `node --inspect-brk dist/gemini.js` within the + `packages/cli` directory, pausing execution until a debugger attaches. You + can then open `chrome://inspect` in your Chrome browser to connect to the + debugger. +2. In VS Code, use the "Attach" launch configuration (found in + `.vscode/launch.json`). -Alternatively, you can use the "Launch Program" configuration in VS Code if you prefer to launch the currently open file directly, but 'F5' is generally recommended. +Alternatively, you can use the "Launch Program" configuration in VS Code if you +prefer to launch the currently open file directly, but 'F5' is generally +recommended. To hit a breakpoint inside the sandbox container run: @@ -250,11 +315,14 @@ To hit a breakpoint inside the sandbox container run: DEBUG=1 gemini ``` -**Note:** If you have `DEBUG=true` in a project's `.env` file, it won't affect gemini-cli due to automatic exclusion. Use `.gemini/.env` files for gemini-cli specific debug settings. +**Note:** If you have `DEBUG=true` in a project's `.env` file, it won't affect +gemini-cli due to automatic exclusion. Use `.gemini/.env` files for gemini-cli +specific debug settings. ### React DevTools -To debug the CLI's React-based UI, you can use React DevTools. Ink, the library used for the CLI's interface, is compatible with React DevTools version 4.x. +To debug the CLI's React-based UI, you can use React DevTools. Ink, the library +used for the CLI's interface, is compatible with React DevTools version 4.x. 1. **Start the Gemini CLI in development mode:** @@ -262,7 +330,8 @@ To debug the CLI's React-based UI, you can use React DevTools. Ink, the library DEV=true npm start ``` -2. **Install and run React DevTools version 4.28.5 (or the latest compatible 4.x version):** +2. **Install and run React DevTools version 4.28.5 (or the latest compatible + 4.x version):** You can either install it globally: @@ -284,21 +353,58 @@ To debug the CLI's React-based UI, you can use React DevTools. Ink, the library ### macOS Seatbelt -On macOS, `gemini` uses Seatbelt (`sandbox-exec`) under a `permissive-open` profile (see `packages/cli/src/utils/sandbox-macos-permissive-open.sb`) that restricts writes to the project folder but otherwise allows all other operations and outbound network traffic ("open") by default. You can switch to a `restrictive-closed` profile (see `packages/cli/src/utils/sandbox-macos-restrictive-closed.sb`) that declines all operations and outbound network traffic ("closed") by default by setting `SEATBELT_PROFILE=restrictive-closed` in your environment or `.env` file. Available built-in profiles are `{permissive,restrictive}-{open,closed,proxied}` (see below for proxied networking). You can also switch to a custom profile `SEATBELT_PROFILE=` if you also create a file `.gemini/sandbox-macos-.sb` under your project settings directory `.gemini`. +On macOS, `gemini` uses Seatbelt (`sandbox-exec`) under a `permissive-open` +profile (see `packages/cli/src/utils/sandbox-macos-permissive-open.sb`) that +restricts writes to the project folder but otherwise allows all other operations +and outbound network traffic ("open") by default. You can switch to a +`restrictive-closed` profile (see +`packages/cli/src/utils/sandbox-macos-restrictive-closed.sb`) that declines all +operations and outbound network traffic ("closed") by default by setting +`SEATBELT_PROFILE=restrictive-closed` in your environment or `.env` file. +Available built-in profiles are `{permissive,restrictive}-{open,closed,proxied}` +(see below for proxied networking). You can also switch to a custom profile +`SEATBELT_PROFILE=` if you also create a file +`.gemini/sandbox-macos-.sb` under your project settings directory +`.gemini`. ### Container-based Sandboxing (All Platforms) -For stronger container-based sandboxing on macOS or other platforms, you can set `GEMINI_SANDBOX=true|docker|podman|` in your environment or `.env` file. The specified command (or if `true` then either `docker` or `podman`) must be installed on the host machine. Once enabled, `npm run build:all` will build a minimal container ("sandbox") image and `npm start` will launch inside a fresh instance of that container. The first build can take 20-30s (mostly due to downloading of the base image) but after that both build and start overhead should be minimal. Default builds (`npm run build`) will not rebuild the sandbox. +For stronger container-based sandboxing on macOS or other platforms, you can set +`GEMINI_SANDBOX=true|docker|podman|` in your environment or `.env` +file. The specified command (or if `true` then either `docker` or `podman`) must +be installed on the host machine. Once enabled, `npm run build:all` will build a +minimal container ("sandbox") image and `npm start` will launch inside a fresh +instance of that container. The first build can take 20-30s (mostly due to +downloading of the base image) but after that both build and start overhead +should be minimal. Default builds (`npm run build`) will not rebuild the +sandbox. -Container-based sandboxing mounts the project directory (and system temp directory) with read-write access and is started/stopped/removed automatically as you start/stop Gemini CLI. Files created within the sandbox should be automatically mapped to your user/group on host machine. You can easily specify additional mounts, ports, or environment variables by setting `SANDBOX_{MOUNTS,PORTS,ENV}` as needed. You can also fully customize the sandbox for your projects by creating the files `.gemini/sandbox.Dockerfile` and/or `.gemini/sandbox.bashrc` under your project settings directory (`.gemini`) and running `gemini` with `BUILD_SANDBOX=1` to trigger building of your custom sandbox. +Container-based sandboxing mounts the project directory (and system temp +directory) with read-write access and is started/stopped/removed automatically +as you start/stop Gemini CLI. Files created within the sandbox should be +automatically mapped to your user/group on host machine. You can easily specify +additional mounts, ports, or environment variables by setting +`SANDBOX_{MOUNTS,PORTS,ENV}` as needed. You can also fully customize the sandbox +for your projects by creating the files `.gemini/sandbox.Dockerfile` and/or +`.gemini/sandbox.bashrc` under your project settings directory (`.gemini`) and +running `gemini` with `BUILD_SANDBOX=1` to trigger building of your custom +sandbox. #### Proxied Networking -All sandboxing methods, including macOS Seatbelt using `*-proxied` profiles, support restricting outbound network traffic through a custom proxy server that can be specified as `GEMINI_SANDBOX_PROXY_COMMAND=`, where `` must start a proxy server that listens on `:::8877` for relevant requests. See `docs/examples/proxy-script.md` for a minimal proxy that only allows `HTTPS` connections to `example.com:443` (e.g. `curl https://example.com`) and declines all other requests. The proxy is started and stopped automatically alongside the sandbox. +All sandboxing methods, including macOS Seatbelt using `*-proxied` profiles, +support restricting outbound network traffic through a custom proxy server that +can be specified as `GEMINI_SANDBOX_PROXY_COMMAND=`, where `` +must start a proxy server that listens on `:::8877` for relevant requests. See +`docs/examples/proxy-script.md` for a minimal proxy that only allows `HTTPS` +connections to `example.com:443` (e.g. `curl https://example.com`) and declines +all other requests. The proxy is started and stopped automatically alongside the +sandbox. ## Manual Publish -We publish an artifact for each commit to our internal registry. But if you need to manually cut a local build, then run the following commands: +We publish an artifact for each commit to our internal registry. But if you need +to manually cut a local build, then run the following commands: ``` npm run clean diff --git a/GEMINI.md b/GEMINI.md index 82f69c8a29..74d711880f 100644 --- a/GEMINI.md +++ b/GEMINI.md @@ -1,6 +1,8 @@ ## Building and running -Before submitting any changes, it is crucial to validate them by running the full preflight check. This command will build the repository, run all tests, check for type errors, and lint the code. +Before submitting any changes, it is crucial to validate them by running the +full preflight check. This command will build the repository, run all tests, +check for type errors, and lint the code. To run the full suite of checks, execute the following command: @@ -8,33 +10,51 @@ To run the full suite of checks, execute the following command: npm run preflight ``` -This single command ensures that your changes meet all the quality gates of the project. While you can run the individual steps (`build`, `test`, `typecheck`, `lint`) separately, it is highly recommended to use `npm run preflight` to ensure a comprehensive validation. +This single command ensures that your changes meet all the quality gates of the +project. While you can run the individual steps (`build`, `test`, `typecheck`, +`lint`) separately, it is highly recommended to use `npm run preflight` to +ensure a comprehensive validation. ## Writing Tests -This project uses **Vitest** as its primary testing framework. When writing tests, aim to follow existing patterns. Key conventions include: +This project uses **Vitest** as its primary testing framework. When writing +tests, aim to follow existing patterns. Key conventions include: ### Test Structure and Framework -- **Framework**: All tests are written using Vitest (`describe`, `it`, `expect`, `vi`). -- **File Location**: Test files (`*.test.ts` for logic, `*.test.tsx` for React components) are co-located with the source files they test. +- **Framework**: All tests are written using Vitest (`describe`, `it`, `expect`, + `vi`). +- **File Location**: Test files (`*.test.ts` for logic, `*.test.tsx` for React + components) are co-located with the source files they test. - **Configuration**: Test environments are defined in `vitest.config.ts` files. -- **Setup/Teardown**: Use `beforeEach` and `afterEach`. Commonly, `vi.resetAllMocks()` is called in `beforeEach` and `vi.restoreAllMocks()` in `afterEach`. +- **Setup/Teardown**: Use `beforeEach` and `afterEach`. Commonly, + `vi.resetAllMocks()` is called in `beforeEach` and `vi.restoreAllMocks()` in + `afterEach`. ### Mocking (`vi` from Vitest) -- **ES Modules**: Mock with `vi.mock('module-name', async (importOriginal) => { ... })`. Use `importOriginal` for selective mocking. - - _Example_: `vi.mock('os', async (importOriginal) => { const actual = await importOriginal(); return { ...actual, homedir: vi.fn() }; });` -- **Mocking Order**: For critical dependencies (e.g., `os`, `fs`) that affect module-level constants, place `vi.mock` at the _very top_ of the test file, before other imports. -- **Hoisting**: Use `const myMock = vi.hoisted(() => vi.fn());` if a mock function needs to be defined before its use in a `vi.mock` factory. -- **Mock Functions**: Create with `vi.fn()`. Define behavior with `mockImplementation()`, `mockResolvedValue()`, or `mockRejectedValue()`. -- **Spying**: Use `vi.spyOn(object, 'methodName')`. Restore spies with `mockRestore()` in `afterEach`. +- **ES Modules**: Mock with + `vi.mock('module-name', async (importOriginal) => { ... })`. Use + `importOriginal` for selective mocking. + - _Example_: + `vi.mock('os', async (importOriginal) => { const actual = await importOriginal(); return { ...actual, homedir: vi.fn() }; });` +- **Mocking Order**: For critical dependencies (e.g., `os`, `fs`) that affect + module-level constants, place `vi.mock` at the _very top_ of the test file, + before other imports. +- **Hoisting**: Use `const myMock = vi.hoisted(() => vi.fn());` if a mock + function needs to be defined before its use in a `vi.mock` factory. +- **Mock Functions**: Create with `vi.fn()`. Define behavior with + `mockImplementation()`, `mockResolvedValue()`, or `mockRejectedValue()`. +- **Spying**: Use `vi.spyOn(object, 'methodName')`. Restore spies with + `mockRestore()` in `afterEach`. ### Commonly Mocked Modules -- **Node.js built-ins**: `fs`, `fs/promises`, `os` (especially `os.homedir()`), `path`, `child_process` (`execSync`, `spawn`). +- **Node.js built-ins**: `fs`, `fs/promises`, `os` (especially `os.homedir()`), + `path`, `child_process` (`execSync`, `spawn`). - **External SDKs**: `@google/genai`, `@modelcontextprotocol/sdk`. -- **Internal Project Modules**: Dependencies from other project packages are often mocked. +- **Internal Project Modules**: Dependencies from other project packages are + often mocked. ### React Component Testing (CLI UI - Ink) @@ -46,13 +66,16 @@ This project uses **Vitest** as its primary testing framework. When writing test ### Asynchronous Testing - Use `async/await`. -- For timers, use `vi.useFakeTimers()`, `vi.advanceTimersByTimeAsync()`, `vi.runAllTimersAsync()`. +- For timers, use `vi.useFakeTimers()`, `vi.advanceTimersByTimeAsync()`, + `vi.runAllTimersAsync()`. - Test promise rejections with `await expect(promise).rejects.toThrow(...)`. ### General Guidance -- When adding tests, first examine existing tests to understand and conform to established conventions. -- Pay close attention to the mocks at the top of existing test files; they reveal critical dependencies and how they are managed in a test environment. +- When adding tests, first examine existing tests to understand and conform to + established conventions. +- Pay close attention to the mocks at the top of existing test files; they + reveal critical dependencies and how they are managed in a test environment. ## Git Repo @@ -60,42 +83,101 @@ The main branch for this project is called "main" ## JavaScript/TypeScript -When contributing to this React, Node, and TypeScript codebase, please prioritize the use of plain JavaScript objects with accompanying TypeScript interface or type declarations over JavaScript class syntax. This approach offers significant advantages, especially concerning interoperability with React and overall code maintainability. +When contributing to this React, Node, and TypeScript codebase, please +prioritize the use of plain JavaScript objects with accompanying TypeScript +interface or type declarations over JavaScript class syntax. This approach +offers significant advantages, especially concerning interoperability with React +and overall code maintainability. ### Preferring Plain Objects over Classes -JavaScript classes, by their nature, are designed to encapsulate internal state and behavior. While this can be useful in some object-oriented paradigms, it often introduces unnecessary complexity and friction when working with React's component-based architecture. Here's why plain objects are preferred: +JavaScript classes, by their nature, are designed to encapsulate internal state +and behavior. While this can be useful in some object-oriented paradigms, it +often introduces unnecessary complexity and friction when working with React's +component-based architecture. Here's why plain objects are preferred: -- Seamless React Integration: React components thrive on explicit props and state management. Classes' tendency to store internal state directly within instances can make prop and state propagation harder to reason about and maintain. Plain objects, on the other hand, are inherently immutable (when used thoughtfully) and can be easily passed as props, simplifying data flow and reducing unexpected side effects. +- Seamless React Integration: React components thrive on explicit props and + state management. Classes' tendency to store internal state directly within + instances can make prop and state propagation harder to reason about and + maintain. Plain objects, on the other hand, are inherently immutable (when + used thoughtfully) and can be easily passed as props, simplifying data flow + and reducing unexpected side effects. -- Reduced Boilerplate and Increased Conciseness: Classes often promote the use of constructors, this binding, getters, setters, and other boilerplate that can unnecessarily bloat code. TypeScript interface and type declarations provide powerful static type checking without the runtime overhead or verbosity of class definitions. This allows for more succinct and readable code, aligning with JavaScript's strengths in functional programming. +- Reduced Boilerplate and Increased Conciseness: Classes often promote the use + of constructors, this binding, getters, setters, and other boilerplate that + can unnecessarily bloat code. TypeScript interface and type declarations + provide powerful static type checking without the runtime overhead or + verbosity of class definitions. This allows for more succinct and readable + code, aligning with JavaScript's strengths in functional programming. -- Enhanced Readability and Predictability: Plain objects, especially when their structure is clearly defined by TypeScript interfaces, are often easier to read and understand. Their properties are directly accessible, and there's no hidden internal state or complex inheritance chains to navigate. This predictability leads to fewer bugs and a more maintainable codebase. +- Enhanced Readability and Predictability: Plain objects, especially when their + structure is clearly defined by TypeScript interfaces, are often easier to + read and understand. Their properties are directly accessible, and there's no + hidden internal state or complex inheritance chains to navigate. This + predictability leads to fewer bugs and a more maintainable codebase. -- Simplified Immutability: While not strictly enforced, plain objects encourage an immutable approach to data. When you need to modify an object, you typically create a new one with the desired changes, rather than mutating the original. This pattern aligns perfectly with React's reconciliation process and helps prevent subtle bugs related to shared mutable state. +- Simplified Immutability: While not strictly enforced, plain objects encourage + an immutable approach to data. When you need to modify an object, you + typically create a new one with the desired changes, rather than mutating the + original. This pattern aligns perfectly with React's reconciliation process + and helps prevent subtle bugs related to shared mutable state. -- Better Serialization and Deserialization: Plain JavaScript objects are naturally easy to serialize to JSON and deserialize back, which is a common requirement in web development (e.g., for API communication or local storage). Classes, with their methods and prototypes, can complicate this process. +- Better Serialization and Deserialization: Plain JavaScript objects are + naturally easy to serialize to JSON and deserialize back, which is a common + requirement in web development (e.g., for API communication or local storage). + Classes, with their methods and prototypes, can complicate this process. ### Embracing ES Module Syntax for Encapsulation -Rather than relying on Java-esque private or public class members, which can be verbose and sometimes limit flexibility, we strongly prefer leveraging ES module syntax (`import`/`export`) for encapsulating private and public APIs. +Rather than relying on Java-esque private or public class members, which can be +verbose and sometimes limit flexibility, we strongly prefer leveraging ES module +syntax (`import`/`export`) for encapsulating private and public APIs. -- Clearer Public API Definition: With ES modules, anything that is exported is part of the public API of that module, while anything not exported is inherently private to that module. This provides a very clear and explicit way to define what parts of your code are meant to be consumed by other modules. +- Clearer Public API Definition: With ES modules, anything that is exported is + part of the public API of that module, while anything not exported is + inherently private to that module. This provides a very clear and explicit way + to define what parts of your code are meant to be consumed by other modules. -- Enhanced Testability (Without Exposing Internals): By default, unexported functions or variables are not accessible from outside the module. This encourages you to test the public API of your modules, rather than their internal implementation details. If you find yourself needing to spy on or stub an unexported function for testing purposes, it's often a "code smell" indicating that the function might be a good candidate for extraction into its own separate, testable module with a well-defined public API. This promotes a more robust and maintainable testing strategy. +- Enhanced Testability (Without Exposing Internals): By default, unexported + functions or variables are not accessible from outside the module. This + encourages you to test the public API of your modules, rather than their + internal implementation details. If you find yourself needing to spy on or + stub an unexported function for testing purposes, it's often a "code smell" + indicating that the function might be a good candidate for extraction into its + own separate, testable module with a well-defined public API. This promotes a + more robust and maintainable testing strategy. -- Reduced Coupling: Explicitly defined module boundaries through import/export help reduce coupling between different parts of your codebase. This makes it easier to refactor, debug, and understand individual components in isolation. +- Reduced Coupling: Explicitly defined module boundaries through import/export + help reduce coupling between different parts of your codebase. This makes it + easier to refactor, debug, and understand individual components in isolation. ### Avoiding `any` Types and Type Assertions; Preferring `unknown` -TypeScript's power lies in its ability to provide static type checking, catching potential errors before your code runs. To fully leverage this, it's crucial to avoid the `any` type and be judicious with type assertions. +TypeScript's power lies in its ability to provide static type checking, catching +potential errors before your code runs. To fully leverage this, it's crucial to +avoid the `any` type and be judicious with type assertions. -- **The Dangers of `any`**: Using any effectively opts out of TypeScript's type checking for that particular variable or expression. While it might seem convenient in the short term, it introduces significant risks: - - **Loss of Type Safety**: You lose all the benefits of type checking, making it easy to introduce runtime errors that TypeScript would otherwise have caught. - - **Reduced Readability and Maintainability**: Code with `any` types is harder to understand and maintain, as the expected type of data is no longer explicitly defined. - - **Masking Underlying Issues**: Often, the need for any indicates a deeper problem in the design of your code or the way you're interacting with external libraries. It's a sign that you might need to refine your types or refactor your code. +- **The Dangers of `any`**: Using any effectively opts out of TypeScript's type + checking for that particular variable or expression. While it might seem + convenient in the short term, it introduces significant risks: + - **Loss of Type Safety**: You lose all the benefits of type checking, making + it easy to introduce runtime errors that TypeScript would otherwise have + caught. + - **Reduced Readability and Maintainability**: Code with `any` types is harder + to understand and maintain, as the expected type of data is no longer + explicitly defined. + - **Masking Underlying Issues**: Often, the need for any indicates a deeper + problem in the design of your code or the way you're interacting with + external libraries. It's a sign that you might need to refine your types or + refactor your code. -- **Preferring `unknown` over `any`**: When you absolutely cannot determine the type of a value at compile time, and you're tempted to reach for any, consider using unknown instead. unknown is a type-safe counterpart to any. While a variable of type unknown can hold any value, you must perform type narrowing (e.g., using typeof or instanceof checks, or a type assertion) before you can perform any operations on it. This forces you to handle the unknown type explicitly, preventing accidental runtime errors. +- **Preferring `unknown` over `any`**: When you absolutely cannot determine the + type of a value at compile time, and you're tempted to reach for any, consider + using unknown instead. unknown is a type-safe counterpart to any. While a + variable of type unknown can hold any value, you must perform type narrowing + (e.g., using typeof or instanceof checks, or a type assertion) before you can + perform any operations on it. This forces you to handle the unknown type + explicitly, preventing accidental runtime errors. ```ts function processValue(value: unknown) { @@ -111,9 +193,23 @@ TypeScript's power lies in its ability to provide static type checking, catching } ``` -- **Type Assertions (`as Type`) - Use with Caution**: Type assertions tell the TypeScript compiler, "Trust me, I know what I'm doing; this is definitely of this type." While there are legitimate use cases (e.g., when dealing with external libraries that don't have perfect type definitions, or when you have more information than the compiler), they should be used sparingly and with extreme caution. - - **Bypassing Type Checking**: Like `any`, type assertions bypass TypeScript's safety checks. If your assertion is incorrect, you introduce a runtime error that TypeScript would not have warned you about. - - **Code Smell in Testing**: A common scenario where `any` or type assertions might be tempting is when trying to test "private" implementation details (e.g., spying on or stubbing an unexported function within a module). This is a strong indication of a "code smell" in your testing strategy and potentially your code structure. Instead of trying to force access to private internals, consider whether those internal details should be refactored into a separate module with a well-defined public API. This makes them inherently testable without compromising encapsulation. +- **Type Assertions (`as Type`) - Use with Caution**: Type assertions tell the + TypeScript compiler, "Trust me, I know what I'm doing; this is definitely of + this type." While there are legitimate use cases (e.g., when dealing with + external libraries that don't have perfect type definitions, or when you have + more information than the compiler), they should be used sparingly and with + extreme caution. + - **Bypassing Type Checking**: Like `any`, type assertions bypass TypeScript's + safety checks. If your assertion is incorrect, you introduce a runtime error + that TypeScript would not have warned you about. + - **Code Smell in Testing**: A common scenario where `any` or type assertions + might be tempting is when trying to test "private" implementation details + (e.g., spying on or stubbing an unexported function within a module). This + is a strong indication of a "code smell" in your testing strategy and + potentially your code structure. Instead of trying to force access to + private internals, consider whether those internal details should be + refactored into a separate module with a well-defined public API. This makes + them inherently testable without compromising encapsulation. ### Type narrowing `switch` clauses @@ -125,54 +221,137 @@ This helper method can be found in `packages/cli/src/utils/checks.ts` ### Embracing JavaScript's Array Operators -To further enhance code cleanliness and promote safe functional programming practices, leverage JavaScript's rich set of array operators as much as possible. Methods like `.map()`, `.filter()`, `.reduce()`, `.slice()`, `.sort()`, and others are incredibly powerful for transforming and manipulating data collections in an immutable and declarative way. +To further enhance code cleanliness and promote safe functional programming +practices, leverage JavaScript's rich set of array operators as much as +possible. Methods like `.map()`, `.filter()`, `.reduce()`, `.slice()`, +`.sort()`, and others are incredibly powerful for transforming and manipulating +data collections in an immutable and declarative way. Using these operators: -- Promotes Immutability: Most array operators return new arrays, leaving the original array untouched. This functional approach helps prevent unintended side effects and makes your code more predictable. -- Improves Readability: Chaining array operators often lead to more concise and expressive code than traditional for loops or imperative logic. The intent of the operation is clear at a glance. -- Facilitates Functional Programming: These operators are cornerstones of functional programming, encouraging the creation of pure functions that take inputs and produce outputs without causing side effects. This paradigm is highly beneficial for writing robust and testable code that pairs well with React. +- Promotes Immutability: Most array operators return new arrays, leaving the + original array untouched. This functional approach helps prevent unintended + side effects and makes your code more predictable. +- Improves Readability: Chaining array operators often lead to more concise and + expressive code than traditional for loops or imperative logic. The intent of + the operation is clear at a glance. +- Facilitates Functional Programming: These operators are cornerstones of + functional programming, encouraging the creation of pure functions that take + inputs and produce outputs without causing side effects. This paradigm is + highly beneficial for writing robust and testable code that pairs well with + React. -By consistently applying these principles, we can maintain a codebase that is not only efficient and performant but also a joy to work with, both now and in the future. +By consistently applying these principles, we can maintain a codebase that is +not only efficient and performant but also a joy to work with, both now and in +the future. ## React (mirrored and adjusted from [react-mcp-server](https://github.com/facebook/react/blob/4448b18760d867f9e009e810571e7a3b8930bb19/compiler/packages/react-mcp-server/src/index.ts#L376C1-L441C94)) ### Role -You are a React assistant that helps users write more efficient and optimizable React code. You specialize in identifying patterns that enable React Compiler to automatically apply optimizations, reducing unnecessary re-renders and improving application performance. +You are a React assistant that helps users write more efficient and optimizable +React code. You specialize in identifying patterns that enable React Compiler to +automatically apply optimizations, reducing unnecessary re-renders and improving +application performance. ### Follow these guidelines in all code you produce and suggest -Use functional components with Hooks: Do not generate class components or use old lifecycle methods. Manage state with useState or useReducer, and side effects with useEffect (or related Hooks). Always prefer functions and Hooks for any new component logic. +Use functional components with Hooks: Do not generate class components or use +old lifecycle methods. Manage state with useState or useReducer, and side +effects with useEffect (or related Hooks). Always prefer functions and Hooks for +any new component logic. -Keep components pure and side-effect-free during rendering: Do not produce code that performs side effects (like subscriptions, network requests, or modifying external variables) directly inside the component's function body. Such actions should be wrapped in useEffect or performed in event handlers. Ensure your render logic is a pure function of props and state. +Keep components pure and side-effect-free during rendering: Do not produce code +that performs side effects (like subscriptions, network requests, or modifying +external variables) directly inside the component's function body. Such actions +should be wrapped in useEffect or performed in event handlers. Ensure your +render logic is a pure function of props and state. -Respect one-way data flow: Pass data down through props and avoid any global mutations. If two components need to share data, lift that state up to a common parent or use React Context, rather than trying to sync local state or use external variables. +Respect one-way data flow: Pass data down through props and avoid any global +mutations. If two components need to share data, lift that state up to a common +parent or use React Context, rather than trying to sync local state or use +external variables. -Never mutate state directly: Always generate code that updates state immutably. For example, use spread syntax or other methods to create new objects/arrays when updating state. Do not use assignments like state.someValue = ... or array mutations like array.push() on state variables. Use the state setter (setState from useState, etc.) to update state. +Never mutate state directly: Always generate code that updates state immutably. +For example, use spread syntax or other methods to create new objects/arrays +when updating state. Do not use assignments like state.someValue = ... or array +mutations like array.push() on state variables. Use the state setter (setState +from useState, etc.) to update state. -Accurately use useEffect and other effect Hooks: whenever you think you could useEffect, think and reason harder to avoid it. useEffect is primarily only used for synchronization, for example synchronizing React with some external state. IMPORTANT - Don't setState (the 2nd value returned by useState) within a useEffect as that will degrade performance. When writing effects, include all necessary dependencies in the dependency array. Do not suppress ESLint rules or omit dependencies that the effect's code uses. Structure the effect callbacks to handle changing values properly (e.g., update subscriptions on prop changes, clean up on unmount or dependency change). If a piece of logic should only run in response to a user action (like a form submission or button click), put that logic in an event handler, not in a useEffect. Where possible, useEffects should return a cleanup function. +Accurately use useEffect and other effect Hooks: whenever you think you could +useEffect, think and reason harder to avoid it. useEffect is primarily only used +for synchronization, for example synchronizing React with some external state. +IMPORTANT - Don't setState (the 2nd value returned by useState) within a +useEffect as that will degrade performance. When writing effects, include all +necessary dependencies in the dependency array. Do not suppress ESLint rules or +omit dependencies that the effect's code uses. Structure the effect callbacks to +handle changing values properly (e.g., update subscriptions on prop changes, +clean up on unmount or dependency change). If a piece of logic should only run +in response to a user action (like a form submission or button click), put that +logic in an event handler, not in a useEffect. Where possible, useEffects should +return a cleanup function. -Follow the Rules of Hooks: Ensure that any Hooks (useState, useEffect, useContext, custom Hooks, etc.) are called unconditionally at the top level of React function components or other Hooks. Do not generate code that calls Hooks inside loops, conditional statements, or nested helper functions. Do not call Hooks in non-component functions or outside the React component rendering context. +Follow the Rules of Hooks: Ensure that any Hooks (useState, useEffect, +useContext, custom Hooks, etc.) are called unconditionally at the top level of +React function components or other Hooks. Do not generate code that calls Hooks +inside loops, conditional statements, or nested helper functions. Do not call +Hooks in non-component functions or outside the React component rendering +context. -Use refs only when necessary: Avoid using useRef unless the task genuinely requires it (such as focusing a control, managing an animation, or integrating with a non-React library). Do not use refs to store application state that should be reactive. If you do use refs, never write to or read from ref.current during the rendering of a component (except for initial setup like lazy initialization). Any ref usage should not affect the rendered output directly. +Use refs only when necessary: Avoid using useRef unless the task genuinely +requires it (such as focusing a control, managing an animation, or integrating +with a non-React library). Do not use refs to store application state that +should be reactive. If you do use refs, never write to or read from ref.current +during the rendering of a component (except for initial setup like lazy +initialization). Any ref usage should not affect the rendered output directly. -Prefer composition and small components: Break down UI into small, reusable components rather than writing large monolithic components. The code you generate should promote clarity and reusability by composing components together. Similarly, abstract repetitive logic into custom Hooks when appropriate to avoid duplicating code. +Prefer composition and small components: Break down UI into small, reusable +components rather than writing large monolithic components. The code you +generate should promote clarity and reusability by composing components +together. Similarly, abstract repetitive logic into custom Hooks when +appropriate to avoid duplicating code. -Optimize for concurrency: Assume React may render your components multiple times for scheduling purposes (especially in development with Strict Mode). Write code that remains correct even if the component function runs more than once. For instance, avoid side effects in the component body and use functional state updates (e.g., setCount(c => c + 1)) when updating state based on previous state to prevent race conditions. Always include cleanup functions in effects that subscribe to external resources. Don't write useEffects for "do this when this changes" side effects. This ensures your generated code will work with React's concurrent rendering features without issues. +Optimize for concurrency: Assume React may render your components multiple times +for scheduling purposes (especially in development with Strict Mode). Write code +that remains correct even if the component function runs more than once. For +instance, avoid side effects in the component body and use functional state +updates (e.g., setCount(c => c + 1)) when updating state based on previous state +to prevent race conditions. Always include cleanup functions in effects that +subscribe to external resources. Don't write useEffects for "do this when this +changes" side effects. This ensures your generated code will work with React's +concurrent rendering features without issues. -Optimize to reduce network waterfalls - Use parallel data fetching wherever possible (e.g., start multiple requests at once rather than one after another). Leverage Suspense for data loading and keep requests co-located with the component that needs the data. In a server-centric approach, fetch related data together in a single request on the server side (using Server Components, for example) to reduce round trips. Also, consider using caching layers or global fetch management to avoid repeating identical requests. +Optimize to reduce network waterfalls - Use parallel data fetching wherever +possible (e.g., start multiple requests at once rather than one after another). +Leverage Suspense for data loading and keep requests co-located with the +component that needs the data. In a server-centric approach, fetch related data +together in a single request on the server side (using Server Components, for +example) to reduce round trips. Also, consider using caching layers or global +fetch management to avoid repeating identical requests. -Rely on React Compiler - useMemo, useCallback, and React.memo can be omitted if React Compiler is enabled. Avoid premature optimization with manual memoization. Instead, focus on writing clear, simple components with direct data flow and side-effect-free render functions. Let the React Compiler handle tree-shaking, inlining, and other performance enhancements to keep your code base simpler and more maintainable. +Rely on React Compiler - useMemo, useCallback, and React.memo can be omitted if +React Compiler is enabled. Avoid premature optimization with manual memoization. +Instead, focus on writing clear, simple components with direct data flow and +side-effect-free render functions. Let the React Compiler handle tree-shaking, +inlining, and other performance enhancements to keep your code base simpler and +more maintainable. -Design for a good user experience - Provide clear, minimal, and non-blocking UI states. When data is loading, show lightweight placeholders (e.g., skeleton screens) rather than intrusive spinners everywhere. Handle errors gracefully with a dedicated error boundary or a friendly inline message. Where possible, render partial data as it becomes available rather than making the user wait for everything. Suspense allows you to declare the loading states in your component tree in a natural way, preventing “flash” states and improving perceived performance. +Design for a good user experience - Provide clear, minimal, and non-blocking UI +states. When data is loading, show lightweight placeholders (e.g., skeleton +screens) rather than intrusive spinners everywhere. Handle errors gracefully +with a dedicated error boundary or a friendly inline message. Where possible, +render partial data as it becomes available rather than making the user wait for +everything. Suspense allows you to declare the loading states in your component +tree in a natural way, preventing “flash” states and improving perceived +performance. ### Process 1. Analyze the user's code for optimization opportunities: - Check for React anti-patterns that prevent compiler optimization - Look for component structure issues that limit compiler effectiveness - - Think about each suggestion you are making and consult React docs for best practices + - Think about each suggestion you are making and consult React docs for best + practices 2. Provide actionable guidance: - Explain specific code changes with clear reasoning @@ -186,8 +365,10 @@ Design for a good user experience - Provide clear, minimal, and non-blocking UI ## Comments policy -Only write high-value comments if at all. Avoid talking to the user through comments. +Only write high-value comments if at all. Avoid talking to the user through +comments. ## General style requirements -Use hyphens instead of underscores in flag names (e.g. `my-flag` instead of `my_flag`). +Use hyphens instead of underscores in flag names (e.g. `my-flag` instead of +`my_flag`). diff --git a/README.md b/README.md index 39d18f13c5..432bf187ae 100644 --- a/README.md +++ b/README.md @@ -7,14 +7,19 @@ ![Gemini CLI Screenshot](./docs/assets/gemini-screenshot.png) -Gemini CLI is an open-source AI agent that brings the power of Gemini directly into your terminal. It provides lightweight access to Gemini, giving you the most direct path from your prompt to our model. +Gemini CLI is an open-source AI agent that brings the power of Gemini directly +into your terminal. It provides lightweight access to Gemini, giving you the +most direct path from your prompt to our model. ## 🚀 Why Gemini CLI? -- **🎯 Free tier**: 60 requests/min and 1,000 requests/day with personal Google account. +- **🎯 Free tier**: 60 requests/min and 1,000 requests/day with personal Google + account. - **🧠 Powerful Gemini 2.5 Pro**: Access to 1M token context window. -- **🔧 Built-in tools**: Google Search grounding, file operations, shell commands, web fetching. -- **🔌 Extensible**: MCP (Model Context Protocol) support for custom integrations. +- **🔧 Built-in tools**: Google Search grounding, file operations, shell + commands, web fetching. +- **🔌 Extensible**: MCP (Model Context Protocol) support for custom + integrations. - **💻 Terminal-first**: Designed for developers who live in the command line. - **🛡️ Open source**: Apache 2.0 licensed. @@ -52,7 +57,9 @@ See [Releases](./docs/releases.md) for more details. ### Preview -New preview releases will be published each week at UTC 2359 on Tuesdays. These releases will not have been fully vetted and may contain regressions or other outstanding issues. Please help us test and install with `preview` tag. +New preview releases will be published each week at UTC 2359 on Tuesdays. These +releases will not have been fully vetted and may contain regressions or other +outstanding issues. Please help us test and install with `preview` tag. ```bash npm install -g @google/gemini-cli@preview @@ -60,7 +67,9 @@ npm install -g @google/gemini-cli@preview ### Stable -- New stable releases will be published each week at UTC 2000 on Tuesdays, this will be the full promotion of last week's `preview` release + any bug fixes and validations. Use `latest` tag. +- New stable releases will be published each week at UTC 2000 on Tuesdays, this + will be the full promotion of last week's `preview` release + any bug fixes + and validations. Use `latest` tag. ```bash npm install -g @google/gemini-cli@latest @@ -68,7 +77,9 @@ npm install -g @google/gemini-cli@latest ### Nightly -- New releases will be published each week at UTC 0000 each day, This will be all changes from the main branch as represented at time of release. It should be assumed there are pending validations and issues. Use `nightly` tag. +- New releases will be published each week at UTC 0000 each day, This will be + all changes from the main branch as represented at time of release. It should + be assumed there are pending validations and issues. Use `nightly` tag. ```bash npm install -g @google/gemini-cli@nightly @@ -84,24 +95,33 @@ npm install -g @google/gemini-cli@nightly ### Automation & Integration -- Automate operational tasks like querying pull requests or handling complex rebases -- Use MCP servers to connect new capabilities, including [media generation with Imagen, Veo or Lyria](https://github.com/GoogleCloudPlatform/vertex-ai-creative-studio/tree/main/experiments/mcp-genmedia) +- Automate operational tasks like querying pull requests or handling complex + rebases +- Use MCP servers to connect new capabilities, including + [media generation with Imagen, Veo or Lyria](https://github.com/GoogleCloudPlatform/vertex-ai-creative-studio/tree/main/experiments/mcp-genmedia) - Run non-interactively in scripts for workflow automation ### Advanced Capabilities -- Ground your queries with built-in [Google Search](https://ai.google.dev/gemini-api/docs/grounding) for real-time information +- Ground your queries with built-in + [Google Search](https://ai.google.dev/gemini-api/docs/grounding) for real-time + information - Conversation checkpointing to save and resume complex sessions - Custom context files (GEMINI.md) to tailor behavior for your projects ### GitHub Integration -Integrate Gemini CLI directly into your GitHub workflows with [**Gemini CLI GitHub Action**](https://github.com/google-github-actions/run-gemini-cli): +Integrate Gemini CLI directly into your GitHub workflows with +[**Gemini CLI GitHub Action**](https://github.com/google-github-actions/run-gemini-cli): -- **Pull Request Reviews**: Automated code review with contextual feedback and suggestions -- **Issue Triage**: Automated labeling and prioritization of GitHub issues based on content analysis -- **On-demand Assistance**: Mention `@gemini-cli` in issues and pull requests for help with debugging, explanations, or task delegation -- **Custom Workflows**: Build automated, scheduled and on-demand workflows tailored to your team's needs +- **Pull Request Reviews**: Automated code review with contextual feedback and + suggestions +- **Issue Triage**: Automated labeling and prioritization of GitHub issues based + on content analysis +- **On-demand Assistance**: Mention `@gemini-cli` in issues and pull requests + for help with debugging, explanations, or task delegation +- **Custom Workflows**: Build automated, scheduled and on-demand workflows + tailored to your team's needs ## 🔐 Authentication Options @@ -109,7 +129,10 @@ Choose the authentication method that best fits your needs: ### Option 1: Login with Google (OAuth login using your Google Account) -**✨ Best for:** Individual developers as well as anyone who has a Gemini Code Assist License. (see [quota limits and terms of service](https://cloud.google.com/gemini/docs/quotas) for details) +**✨ Best for:** Individual developers as well as anyone who has a Gemini Code +Assist License. (see +[quota limits and terms of service](https://cloud.google.com/gemini/docs/quotas) +for details) **Benefits:** @@ -165,7 +188,8 @@ export GOOGLE_GENAI_USE_VERTEXAI=true gemini ``` -For Google Workspace accounts and other authentication methods, see the [authentication guide](./docs/get-started/authentication.md). +For Google Workspace accounts and other authentication methods, see the +[authentication guide](./docs/get-started/authentication.md). ## 🚀 Getting Started @@ -227,17 +251,25 @@ gemini ### Getting Started -- [**Quickstart Guide**](./docs/get-started/index.md) - Get up and running quickly. -- [**Authentication Setup**](./docs/get-started/authentication.md) - Detailed auth configuration. -- [**Configuration Guide**](./docs/get-started/configuration.md) - Settings and customization. -- [**Keyboard Shortcuts**](./docs/cli/keyboard-shortcuts.md) - Productivity tips. +- [**Quickstart Guide**](./docs/get-started/index.md) - Get up and running + quickly. +- [**Authentication Setup**](./docs/get-started/authentication.md) - Detailed + auth configuration. +- [**Configuration Guide**](./docs/get-started/configuration.md) - Settings and + customization. +- [**Keyboard Shortcuts**](./docs/cli/keyboard-shortcuts.md) - Productivity + tips. ### Core Features -- [**Commands Reference**](./docs/cli/commands.md) - All slash commands (`/help`, `/chat`, etc). -- [**Custom Commands**](./docs/cli/custom-commands.md) - Create your own reusable commands. -- [**Context Files (GEMINI.md)**](./docs/cli/gemini-md.md) - Provide persistent context to Gemini CLI. -- [**Checkpointing**](./docs/cli/checkpointing.md) - Save and resume conversations. +- [**Commands Reference**](./docs/cli/commands.md) - All slash commands + (`/help`, `/chat`, etc). +- [**Custom Commands**](./docs/cli/custom-commands.md) - Create your own + reusable commands. +- [**Context Files (GEMINI.md)**](./docs/cli/gemini-md.md) - Provide persistent + context to Gemini CLI. +- [**Checkpointing**](./docs/cli/checkpointing.md) - Save and resume + conversations. - [**Token Caching**](./docs/cli/token-caching.md) - Optimize token usage. ### Tools & Extensions @@ -246,29 +278,37 @@ gemini - [File System Operations](./docs/tools/file-system.md) - [Shell Commands](./docs/tools/shell.md) - [Web Fetch & Search](./docs/tools/web-fetch.md) -- [**MCP Server Integration**](./docs/tools/mcp-server.md) - Extend with custom tools. -- [**Custom Extensions**](./docs/extensions/index.md) - Build and share your own commands. +- [**MCP Server Integration**](./docs/tools/mcp-server.md) - Extend with custom + tools. +- [**Custom Extensions**](./docs/extensions/index.md) - Build and share your own + commands. ### Advanced Topics -- [**Headless Mode (Scripting)**](./docs/cli/headless.md) - Use Gemini CLI in automated workflows. +- [**Headless Mode (Scripting)**](./docs/cli/headless.md) - Use Gemini CLI in + automated workflows. - [**Architecture Overview**](./docs/architecture.md) - How Gemini CLI works. - [**IDE Integration**](./docs/ide-integration/index.md) - VS Code companion. -- [**Sandboxing & Security**](./docs/cli/sandbox.md) - Safe execution environments. -- [**Trusted Folders**](./docs/cli/trusted-folders.md) - Control execution policies by folder. -- [**Enterprise Guide**](./docs/cli/enterprise.md) - Deploy and manage in a corporate environment. +- [**Sandboxing & Security**](./docs/cli/sandbox.md) - Safe execution + environments. +- [**Trusted Folders**](./docs/cli/trusted-folders.md) - Control execution + policies by folder. +- [**Enterprise Guide**](./docs/cli/enterprise.md) - Deploy and manage in a + corporate environment. - [**Telemetry & Monitoring**](./docs/cli/telemetry.md) - Usage tracking. - [**Tools API Development**](./docs/core/tools-api.md) - Create custom tools. ### Troubleshooting & Support -- [**Troubleshooting Guide**](./docs/troubleshooting.md) - Common issues and solutions. +- [**Troubleshooting Guide**](./docs/troubleshooting.md) - Common issues and + solutions. - [**FAQ**](./docs/faq.md) - Frequently asked questions. - Use `/bug` command to report issues directly from the CLI. ### Using MCP Servers -Configure MCP servers in `~/.gemini/settings.json` to extend Gemini CLI with custom tools: +Configure MCP servers in `~/.gemini/settings.json` to extend Gemini CLI with +custom tools: ```text > @github List my open pull requests @@ -276,28 +316,35 @@ Configure MCP servers in `~/.gemini/settings.json` to extend Gemini CLI with cus > @database Run a query to find inactive users ``` -See the [MCP Server Integration guide](./docs/tools/mcp-server.md) for setup instructions. +See the [MCP Server Integration guide](./docs/tools/mcp-server.md) for setup +instructions. ## 🤝 Contributing -We welcome contributions! Gemini CLI is fully open source (Apache 2.0), and we encourage the community to: +We welcome contributions! Gemini CLI is fully open source (Apache 2.0), and we +encourage the community to: - Report bugs and suggest features. - Improve documentation. - Submit code improvements. - Share your MCP servers and extensions. -See our [Contributing Guide](./CONTRIBUTING.md) for development setup, coding standards, and how to submit pull requests. +See our [Contributing Guide](./CONTRIBUTING.md) for development setup, coding +standards, and how to submit pull requests. -Check our [Official Roadmap](https://github.com/orgs/google-gemini/projects/11) for planned features and priorities. +Check our [Official Roadmap](https://github.com/orgs/google-gemini/projects/11) +for planned features and priorities. ## 📖 Resources - **[Official Roadmap](./ROADMAP.md)** - See what's coming next. - **[Changelog](./docs/changelogs/index.md)** - See recent notable updates. -- **[NPM Package](https://www.npmjs.com/package/@google/gemini-cli)** - Package registry. -- **[GitHub Issues](https://github.com/google-gemini/gemini-cli/issues)** - Report bugs or request features. -- **[Security Advisories](https://github.com/google-gemini/gemini-cli/security/advisories)** - Security updates. +- **[NPM Package](https://www.npmjs.com/package/@google/gemini-cli)** - Package + registry. +- **[GitHub Issues](https://github.com/google-gemini/gemini-cli/issues)** - + Report bugs or request features. +- **[Security Advisories](https://github.com/google-gemini/gemini-cli/security/advisories)** - + Security updates. ### Uninstall diff --git a/ROADMAP.md b/ROADMAP.md index 5d77046f04..490416352f 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -1,63 +1,113 @@ # Gemini CLI Roadmap -The [Official Gemini CLI Roadmap](https://github.com/orgs/google-gemini/projects/11/) +The +[Official Gemini CLI Roadmap](https://github.com/orgs/google-gemini/projects/11/) -Gemini CLI is an open-source AI agent that brings the power of Gemini directly into your terminal. It provides lightweight access to Gemini, giving you the most direct path from your prompt to our model. +Gemini CLI is an open-source AI agent that brings the power of Gemini directly +into your terminal. It provides lightweight access to Gemini, giving you the +most direct path from your prompt to our model. -This document outlines our approach to the Gemini CLI roadmap. Here, you'll find our guiding principles and a breakdown of the key areas we are -focused on for development. Our roadmap is not a static list but a dynamic set of priorities that are tracked live in our GitHub Issues. +This document outlines our approach to the Gemini CLI roadmap. Here, you'll find +our guiding principles and a breakdown of the key areas we are focused on for +development. Our roadmap is not a static list but a dynamic set of priorities +that are tracked live in our GitHub Issues. -As an [Apache 2.0 open source project](https://github.com/google-gemini/gemini-cli?tab=Apache-2.0-1-ov-file#readme), we appreciate and welcome [public contributions](https://github.com/google-gemini/gemini-cli/blob/main/CONTRIBUTING.md), and will give first priority to those contributions aligned with our roadmap. If you want to propose a new feature or change to our roadmap, please start by [opening an issue for discussion](https://github.com/google-gemini/gemini-cli/issues/new/choose). +As an +[Apache 2.0 open source project](https://github.com/google-gemini/gemini-cli?tab=Apache-2.0-1-ov-file#readme), +we appreciate and welcome +[public contributions](https://github.com/google-gemini/gemini-cli/blob/main/CONTRIBUTING.md), +and will give first priority to those contributions aligned with our roadmap. If +you want to propose a new feature or change to our roadmap, please start by +[opening an issue for discussion](https://github.com/google-gemini/gemini-cli/issues/new/choose). ## Disclaimer -This roadmap represents our current thinking and is for informational purposes only. It is not a commitment or a guarantee of future delivery. The development, release, and timing of any features are subject to change, and we may update the roadmap based on community discussions as well as when our priorities evolve. +This roadmap represents our current thinking and is for informational purposes +only. It is not a commitment or a guarantee of future delivery. The development, +release, and timing of any features are subject to change, and we may update the +roadmap based on community discussions as well as when our priorities evolve. ## Guiding Principles Our development is guided by the following principles: -- **Power & Simplicity:** Deliver access to state-of-the-art Gemini models with an intuitive and easy-to-use lightweight command-line interface. -- **Extensibility:** An adaptable agent to help you with a variety of use cases and environments along with the ability to run these agents anywhere. -- **Intelligent:** Gemini CLI should be reliably ranked among the best agentic tools as measured by benchmarks like SWE Bench, Terminal Bench, and CSAT. -- **Free and Open Source:** Foster a thriving open source community where cost isn’t a barrier to personal use, and PRs get merged quickly. This means resolving and closing issues, pull requests, and discussion posts quickly. +- **Power & Simplicity:** Deliver access to state-of-the-art Gemini models with + an intuitive and easy-to-use lightweight command-line interface. +- **Extensibility:** An adaptable agent to help you with a variety of use cases + and environments along with the ability to run these agents anywhere. +- **Intelligent:** Gemini CLI should be reliably ranked among the best agentic + tools as measured by benchmarks like SWE Bench, Terminal Bench, and CSAT. +- **Free and Open Source:** Foster a thriving open source community where cost + isn’t a barrier to personal use, and PRs get merged quickly. This means + resolving and closing issues, pull requests, and discussion posts quickly. ## How the Roadmap Works -Our roadmap is managed directly through GitHub Issues. See our entry point Roadmap Issue [here](https://github.com/google-gemini/gemini-cli/issues/4191). This approach allows for transparency and gives you a direct way to learn more or get involved with any specific initiative. All our roadmap items will be tagged as Type:`Feature` and Label:`maintainer` for features we are actively working on, or Type:`Task` and Label:`maintainer` for a more detailed list of tasks. +Our roadmap is managed directly through GitHub Issues. See our entry point +Roadmap Issue [here](https://github.com/google-gemini/gemini-cli/issues/4191). +This approach allows for transparency and gives you a direct way to learn more +or get involved with any specific initiative. All our roadmap items will be +tagged as Type:`Feature` and Label:`maintainer` for features we are actively +working on, or Type:`Task` and Label:`maintainer` for a more detailed list of +tasks. Issues are organized to provide key information at a glance: - **Target Quarter:** `Milestone` denotes the anticipated delivery timeline. -- **Feature Area:** Labels such as `area/model` or `area/tooling` categorize the work. +- **Feature Area:** Labels such as `area/model` or `area/tooling` categorize the + work. - **Issue Type:** _Workstream_ => _Epics_ => _Features_ => _Tasks|Bugs_ -To see what we're working on, you can filter our issues by these dimensions. See all our items [here](https://github.com/orgs/google-gemini/projects/11/views/19) +To see what we're working on, you can filter our issues by these dimensions. See +all our items [here](https://github.com/orgs/google-gemini/projects/11/views/19) ## Focus Areas -To better organize our efforts, we categorize our work into several key feature areas. These labels are used on our GitHub Issues to help you filter and -find initiatives that interest you. +To better organize our efforts, we categorize our work into several key feature +areas. These labels are used on our GitHub Issues to help you filter and find +initiatives that interest you. -- **Authentication:** Secure user access via API keys, Gemini Code Assist login, etc. -- **Model:** Support new Gemini models, multi-modality, local execution, and performance tuning. -- **User Experience:** Improve the CLI's usability, performance, interactive features, and documentation. +- **Authentication:** Secure user access via API keys, Gemini Code Assist login, + etc. +- **Model:** Support new Gemini models, multi-modality, local execution, and + performance tuning. +- **User Experience:** Improve the CLI's usability, performance, interactive + features, and documentation. - **Tooling:** Built-in tools and the MCP ecosystem. - **Core:** Core functionality of the CLI - **Extensibility:** Bringing Gemini CLI to other surfaces e.g. GitHub. -- **Contribution:** Improve the contribution process via test automation and CI/CD pipeline enhancements. -- **Platform:** Manage installation, OS support, and the underlying CLI framework. -- **Quality:** Focus on testing, reliability, performance, and overall product quality. -- **Background Agents:** Enable long-running, autonomous tasks and proactive assistance. +- **Contribution:** Improve the contribution process via test automation and + CI/CD pipeline enhancements. +- **Platform:** Manage installation, OS support, and the underlying CLI + framework. +- **Quality:** Focus on testing, reliability, performance, and overall product + quality. +- **Background Agents:** Enable long-running, autonomous tasks and proactive + assistance. - **Security and Privacy:** For all things related to security and privacy ## How to Contribute -Gemini CLI is an open-source project, and we welcome contributions from the community! Whether you're a developer, a designer, or just an enthusiastic user you can find our [Community Guidelines here](https://github.com/google-gemini/gemini-cli/blob/main/CONTRIBUTING.md) to learn how to get started. There are many ways to get involved: +Gemini CLI is an open-source project, and we welcome contributions from the +community! Whether you're a developer, a designer, or just an enthusiastic user +you can find our +[Community Guidelines here](https://github.com/google-gemini/gemini-cli/blob/main/CONTRIBUTING.md) +to learn how to get started. There are many ways to get involved: -- **Roadmap:** Please review and find areas in our [roadmap](https://github.com/google-gemini/gemini-cli/issues/4191) that you would like to contribute to. Contributions based on this will be easiest to integrate with. -- **Report Bugs:** If you find an issue, please create a [bug](https://github.com/google-gemini/gemini-cli/issues/new?template=bug_report.yml) with as much detail as possible. If you believe it is a critical breaking issue preventing direct CLI usage, please tag it as `priority/p0`. -- **Suggest Features:** Have a great idea? We'd love to hear it! Open a [feature request](https://github.com/google-gemini/gemini-cli/issues/new?template=feature_request.yml). -- **Contribute Code:** Check out our [CONTRIBUTING.md](https://github.com/google-gemini/gemini-cli/blob/main/CONTRIBUTING.md) file for guidelines on how to submit pull requests. We have a list of "good first issues" for new contributors. -- **Write Documentation:** Help us improve our documentation, tutorials, and examples. - We are excited about the future of Gemini CLI and look forward to building it with you! +- **Roadmap:** Please review and find areas in our + [roadmap](https://github.com/google-gemini/gemini-cli/issues/4191) that you + would like to contribute to. Contributions based on this will be easiest to + integrate with. +- **Report Bugs:** If you find an issue, please create a + [bug](https://github.com/google-gemini/gemini-cli/issues/new?template=bug_report.yml) + with as much detail as possible. If you believe it is a critical breaking + issue preventing direct CLI usage, please tag it as `priority/p0`. +- **Suggest Features:** Have a great idea? We'd love to hear it! Open a + [feature request](https://github.com/google-gemini/gemini-cli/issues/new?template=feature_request.yml). +- **Contribute Code:** Check out our + [CONTRIBUTING.md](https://github.com/google-gemini/gemini-cli/blob/main/CONTRIBUTING.md) + file for guidelines on how to submit pull requests. We have a list of "good + first issues" for new contributors. +- **Write Documentation:** Help us improve our documentation, tutorials, and + examples. We are excited about the future of Gemini CLI and look forward to + building it with you! diff --git a/SECURITY.md b/SECURITY.md index 226310c275..63bf3a0f51 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -5,4 +5,5 @@ We use g.co/vulnz for our intake, and do coordination and disclosure here on GitHub (including using GitHub Security Advisory). The Google Security Team will respond within 5 working days of your report on g.co/vulnz. -[GitHub Security Advisory]: https://github.com/google-gemini/gemini-cli/security/advisories +[GitHub Security Advisory]: + https://github.com/google-gemini/gemini-cli/security/advisories diff --git a/docs/architecture.md b/docs/architecture.md index cb2841f67e..0bd3e1b1a3 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -4,10 +4,14 @@ This document provides a high-level overview of the Gemini CLI's architecture. ## Core components -The Gemini CLI is primarily composed of two main packages, along with a suite of tools that can be used by the system in the course of handling command-line input: +The Gemini CLI is primarily composed of two main packages, along with a suite of +tools that can be used by the system in the course of handling command-line +input: 1. **CLI package (`packages/cli`):** - - **Purpose:** This contains the user-facing portion of the Gemini CLI, such as handling the initial user input, presenting the final output, and managing the overall user experience. + - **Purpose:** This contains the user-facing portion of the Gemini CLI, such + as handling the initial user input, presenting the final output, and + managing the overall user experience. - **Key functions contained in the package:** - [Input processing](../cli/commands.md) - History management @@ -16,7 +20,9 @@ The Gemini CLI is primarily composed of two main packages, along with a suite of - [CLI configuration settings](../get-started/configuration.md) 2. **Core package (`packages/core`):** - - **Purpose:** This acts as the backend for the Gemini CLI. It receives requests sent from `packages/cli`, orchestrates interactions with the Gemini API, and manages the execution of available tools. + - **Purpose:** This acts as the backend for the Gemini CLI. It receives + requests sent from `packages/cli`, orchestrates interactions with the + Gemini API, and manages the execution of available tools. - **Key functions contained in the package:** - API client for communicating with the Google Gemini API - Prompt construction and management @@ -25,30 +31,50 @@ The Gemini CLI is primarily composed of two main packages, along with a suite of - Server-side configuration 3. **Tools (`packages/core/src/tools/`):** - - **Purpose:** These are individual modules that extend the capabilities of the Gemini model, allowing it to interact with the local environment (e.g., file system, shell commands, web fetching). - - **Interaction:** `packages/core` invokes these tools based on requests from the Gemini model. + - **Purpose:** These are individual modules that extend the capabilities of + the Gemini model, allowing it to interact with the local environment + (e.g., file system, shell commands, web fetching). + - **Interaction:** `packages/core` invokes these tools based on requests + from the Gemini model. ## Interaction Flow A typical interaction with the Gemini CLI follows this flow: -1. **User input:** The user types a prompt or command into the terminal, which is managed by `packages/cli`. -2. **Request to core:** `packages/cli` sends the user's input to `packages/core`. +1. **User input:** The user types a prompt or command into the terminal, which + is managed by `packages/cli`. +2. **Request to core:** `packages/cli` sends the user's input to + `packages/core`. 3. **Request processed:** The core package: - - Constructs an appropriate prompt for the Gemini API, possibly including conversation history and available tool definitions. + - Constructs an appropriate prompt for the Gemini API, possibly including + conversation history and available tool definitions. - Sends the prompt to the Gemini API. -4. **Gemini API response:** The Gemini API processes the prompt and returns a response. This response might be a direct answer or a request to use one of the available tools. +4. **Gemini API response:** The Gemini API processes the prompt and returns a + response. This response might be a direct answer or a request to use one of + the available tools. 5. **Tool execution (if applicable):** - - When the Gemini API requests a tool, the core package prepares to execute it. - - If the requested tool can modify the file system or execute shell commands, the user is first given details of the tool and its arguments, and the user must approve the execution. - - Read-only operations, such as reading files, might not require explicit user confirmation to proceed. - - Once confirmed, or if confirmation is not required, the core package executes the relevant action within the relevant tool, and the result is sent back to the Gemini API by the core package. + - When the Gemini API requests a tool, the core package prepares to execute + it. + - If the requested tool can modify the file system or execute shell + commands, the user is first given details of the tool and its arguments, + and the user must approve the execution. + - Read-only operations, such as reading files, might not require explicit + user confirmation to proceed. + - Once confirmed, or if confirmation is not required, the core package + executes the relevant action within the relevant tool, and the result is + sent back to the Gemini API by the core package. - The Gemini API processes the tool result and generates a final response. -6. **Response to CLI:** The core package sends the final response back to the CLI package. -7. **Display to user:** The CLI package formats and displays the response to the user in the terminal. +6. **Response to CLI:** The core package sends the final response back to the + CLI package. +7. **Display to user:** The CLI package formats and displays the response to + the user in the terminal. ## Key Design Principles -- **Modularity:** Separating the CLI (frontend) from the Core (backend) allows for independent development and potential future extensions (e.g., different frontends for the same backend). -- **Extensibility:** The tool system is designed to be extensible, allowing new capabilities to be added. -- **User experience:** The CLI focuses on providing a rich and interactive terminal experience. +- **Modularity:** Separating the CLI (frontend) from the Core (backend) allows + for independent development and potential future extensions (e.g., different + frontends for the same backend). +- **Extensibility:** The tool system is designed to be extensible, allowing new + capabilities to be added. +- **User experience:** The CLI focuses on providing a rich and interactive + terminal experience. diff --git a/docs/changelogs/index.md b/docs/changelogs/index.md index 85001388e7..0e113a748b 100644 --- a/docs/changelogs/index.md +++ b/docs/changelogs/index.md @@ -1,14 +1,17 @@ # Gemini CLI Changelog -Wondering what's new in Gemini CLI? This document provides key highlights and notable changes to Gemini CLI. +Wondering what's new in Gemini CLI? This document provides key highlights and +notable changes to Gemini CLI. ## v0.8.0 - Gemini CLI weekly update - 2025-09-29 - 🎉 **Announcing Gemini CLI Extensions** 🎉 - Completely customize your Gemini CLI experience to fit your workflow. - Build and share your own Gemini CLI extensions with the world. - - Launching with a growing catalog of community, partner, and Google-built extensions. - - Check extensions from [key launch partners](https://github.com/google-gemini/gemini-cli/discussions/10718). + - Launching with a growing catalog of community, partner, and Google-built + extensions. + - Check extensions from + [key launch partners](https://github.com/google-gemini/gemini-cli/discussions/10718). - Easy install: - `gemini extensions install ` - Easy management: @@ -16,89 +19,264 @@ Wondering what's new in Gemini CLI? This document provides key highlights and no - `gemini extensions enable|disable` - `gemini extensions list|update|new` - Or use commands while running with `/extensions list|update`. - - Everything you need to know: [Now open for building: Introducing Gemini CLI extensions](https://blog.google/technology/developers/gemini-cli-extensions/). + - Everything you need to know: + [Now open for building: Introducing Gemini CLI extensions](https://blog.google/technology/developers/gemini-cli-extensions/). - 🎉 **Our New Home Page & Better Documentation** 🎉 - - Check out our new home page for better getting started material, reference documentation, extensions and more! + - Check out our new home page for better getting started material, reference + documentation, extensions and more! - _Homepage:_ [https://geminicli.com](https://geminicli.com) - - ‼️*NEW documentation:* [https://geminicli.com/docs](https://geminicli.com/docs) (Have any [suggestions](https://github.com/google-gemini/gemini-cli/discussions/8722)?) - - _Extensions:_ [https://geminicli.com/extensions](https://geminicli.com/extensions) -- **Non-Interactive Allowed Tools:** `--allowed-tools` will now also work in non-interactive mode. ([pr](https://github.com/google-gemini/gemini-cli/pull/9114) by [@mistergarrison](https://github.com/mistergarrison)) -- **Terminal Title Status:** See the CLI's real-time status and thoughts directly in the terminal window's title by setting `showStatusInTitle: true`. ([pr](https://github.com/google-gemini/gemini-cli/pull/4386) by [@Fridayxiao](https://github.com/Fridayxiao)) -- **Small features, polish, reliability & bug fixes:** A large amount of changes, smaller features, UI updates, reliability and bug fixes + general polish made it in this week! + - ‼️*NEW documentation:* + [https://geminicli.com/docs](https://geminicli.com/docs) (Have any + [suggestions](https://github.com/google-gemini/gemini-cli/discussions/8722)?) + - _Extensions:_ + [https://geminicli.com/extensions](https://geminicli.com/extensions) +- **Non-Interactive Allowed Tools:** `--allowed-tools` will now also work in + non-interactive mode. + ([pr](https://github.com/google-gemini/gemini-cli/pull/9114) by + [@mistergarrison](https://github.com/mistergarrison)) +- **Terminal Title Status:** See the CLI's real-time status and thoughts + directly in the terminal window's title by setting `showStatusInTitle: true`. + ([pr](https://github.com/google-gemini/gemini-cli/pull/4386) by + [@Fridayxiao](https://github.com/Fridayxiao)) +- **Small features, polish, reliability & bug fixes:** A large amount of + changes, smaller features, UI updates, reliability and bug fixes + general + polish made it in this week! ## v0.7.0 - Gemini CLI weekly update - 2025-09-22 -- 🎉**Build your own Gemini CLI IDE plugin:** We've published a spec for creating IDE plugins to enable rich context-aware experiences and native in-editor diffing in your IDE of choice. ([pr](https://github.com/google-gemini/gemini-cli/pull/8479) by [@skeshive](https://github.com/skeshive)) +- 🎉**Build your own Gemini CLI IDE plugin:** We've published a spec for + creating IDE plugins to enable rich context-aware experiences and native + in-editor diffing in your IDE of choice. + ([pr](https://github.com/google-gemini/gemini-cli/pull/8479) by + [@skeshive](https://github.com/skeshive)) - 🎉 **Gemini CLI extensions** - - **Flutter:** An early version to help you create, build, test, and run Flutter apps with Gemini CLI ([extension](https://github.com/flutter/gemini-cli-extension)) - - **nanobanana:** Integrate nanobanana into Gemini CLI ([extension](https://github.com/gemini-cli-extensions/nanobanana)) -- **Telemetry config via environment:** Manage telemetry settings using environment variables for a more flexible setup. ([docs](https://github.com/google-gemini/gemini-cli/blob/main/docs/cli/telemetry.md#configuration), [pr](https://github.com/google-gemini/gemini-cli/pull/9113) by [@jerop](https://github.com/jerop)) -- **​​Experimental todos:** Track and display progress on complex tasks with a managed checklist. Off by default but can be enabled via `"useWriteTodos": true` ([pr](https://github.com/google-gemini/gemini-cli/pull/8761) by [@anj-s](https://github.com/anj-s)) -- **Share chat support for tools:** Using `/chat share` will now also render function calls and responses in the final markdown file. ([pr](https://github.com/google-gemini/gemini-cli/pull/8693) by [@rramkumar1](https://github.com/rramkumar1)) -- **Citations:** Now enabled for all users ([pr](https://github.com/google-gemini/gemini-cli/pull/8570) by [@scidomino](https://github.com/scidomino)) -- **Custom commands in Headless Mode:** Run custom slash commands directly from the command line in non-interactive mode: `gemini "/joke Chuck Norris"` ([pr](https://github.com/google-gemini/gemini-cli/pull/8305) by [@capachino](https://github.com/capachino)) -- **Small features, polish, reliability & bug fixes:** A large amount of changes, smaller features, UI updates, reliability and bug fixes + general polish made it in this week! + - **Flutter:** An early version to help you create, build, test, and run + Flutter apps with Gemini CLI + ([extension](https://github.com/flutter/gemini-cli-extension)) + - **nanobanana:** Integrate nanobanana into Gemini CLI + ([extension](https://github.com/gemini-cli-extensions/nanobanana)) +- **Telemetry config via environment:** Manage telemetry settings using + environment variables for a more flexible setup. + ([docs](https://github.com/google-gemini/gemini-cli/blob/main/docs/cli/telemetry.md#configuration), + [pr](https://github.com/google-gemini/gemini-cli/pull/9113) by + [@jerop](https://github.com/jerop)) +- **​​Experimental todos:** Track and display progress on complex tasks with a + managed checklist. Off by default but can be enabled via + `"useWriteTodos": true` + ([pr](https://github.com/google-gemini/gemini-cli/pull/8761) by + [@anj-s](https://github.com/anj-s)) +- **Share chat support for tools:** Using `/chat share` will now also render + function calls and responses in the final markdown file. + ([pr](https://github.com/google-gemini/gemini-cli/pull/8693) by + [@rramkumar1](https://github.com/rramkumar1)) +- **Citations:** Now enabled for all users + ([pr](https://github.com/google-gemini/gemini-cli/pull/8570) by + [@scidomino](https://github.com/scidomino)) +- **Custom commands in Headless Mode:** Run custom slash commands directly from + the command line in non-interactive mode: `gemini "/joke Chuck Norris"` + ([pr](https://github.com/google-gemini/gemini-cli/pull/8305) by + [@capachino](https://github.com/capachino)) +- **Small features, polish, reliability & bug fixes:** A large amount of + changes, smaller features, UI updates, reliability and bug fixes + general + polish made it in this week! ## v0.6.0 - Gemini CLI weekly update - 2025-09-15 -- 🎉 **Higher limits for Google AI Pro and Ultra subscribers:** We’re psyched to finally announce that Google AI Pro and AI Ultra subscribers now get access to significantly higher 2.5 quota limits for Gemini CLI! - - **Announcement:** [https://blog.google/technology/developers/gemini-cli-code-assist-higher-limits/](https://blog.google/technology/developers/gemini-cli-code-assist-higher-limits/) -- 🎉**Gemini CLI Databases and BigQuery Extensions:** Connect Gemini CLI to all of your cloud data with Gemini CLI. - - Announcement and how to get started with each of the below extensions: [https://cloud.google.com/blog/products/databases/gemini-cli-extensions-for-google-data-cloud?e=48754805](https://cloud.google.com/blog/products/databases/gemini-cli-extensions-for-google-data-cloud?e=48754805) - - **AlloyDB:** Interact, manage and observe AlloyDB for PostgreSQL databases ([manage](https://github.com/gemini-cli-extensions/alloydb#configuration), [observe](https://github.com/gemini-cli-extensions/alloydb-observability#configuration)) - - **BigQuery:** Connect and query your BigQuery datasets or utilize a sub-agent for contextual insights ([query](https://github.com/gemini-cli-extensions/bigquery-data-analytics#configuration), [sub-agent](https://github.com/gemini-cli-extensions/bigquery-conversational-analytics)) - - **Cloud SQL:** Interact, manage and observe Cloud SQL for PostgreSQL ([manage](https://github.com/gemini-cli-extensions/cloud-sql-postgresql#configuration),[ observe](https://github.com/gemini-cli-extensions/cloud-sql-postgresql-observability#configuration)), Cloud SQL for MySQL ([manage](https://github.com/gemini-cli-extensions/cloud-sql-mysql#configuration),[ observe](https://github.com/gemini-cli-extensions/cloud-sql-mysql-observability#configuration)) and Cloud SQL for SQL Server ([manage](https://github.com/gemini-cli-extensions/cloud-sql-sqlserver#configuration),[ observe](https://github.com/gemini-cli-extensions/cloud-sql-sqlserver-observability#configuration)) databases. - - **Dataplex:** Discover, manage, and govern data and AI artifacts ([extension](https://github.com/gemini-cli-extensions/dataplex#configuration)) - - **Firestore:** Interact with Firestore databases, collections and documents ([extension](https://github.com/gemini-cli-extensions/firestore-native#configuration)) - - **Looker:** Query data, run Looks and create dashboards ([extension](https://github.com/gemini-cli-extensions/looker#configuration)) - - **MySQL:** Interact with MySQL databases ([extension](https://github.com/gemini-cli-extensions/mysql#configuration)) - - **Postgres:** Interact with PostgreSQL databases ([extension](https://github.com/gemini-cli-extensions/postgres#configuration)) - - **Spanner:** Interact with Spanner databases ([extension](https://github.com/gemini-cli-extensions/spanner#configuration)) - - **SQL Server:** Interact with SQL Server databases ([extension](https://github.com/gemini-cli-extensions/sql-server#configuration)) - - **MCP Toolbox:** Configure and load custom tools for more than 30+ data sources ([extension](https://github.com/gemini-cli-extensions/mcp-toolbox#configuration)) -- **JSON output mode:** Have Gemini CLI output JSON with `--output-format json` when invoked headlessly for easy parsing and post-processing. Includes response, stats and errors. ([pr](https://github.com/google-gemini/gemini-cli/pull/8119) by [@jerop](https://github.com/jerop)) -- **Keybinding triggered approvals:** When you use shortcuts (`shift+y` or `shift+tab`) to activate YOLO/auto-edit modes any pending confirmation dialogs will now approve. ([pr](https://github.com/google-gemini/gemini-cli/pull/6665) by [@bulkypanda](https://github.com/bulkypanda)) -- **Chat sharing:** Convert the current conversation to a Markdown or JSON file with _/chat share <file.md|file.json>_ ([pr](https://github.com/google-gemini/gemini-cli/pull/8139) by [@rramkumar1](https://github.com/rramkumar1)) -- **Prompt search:** Search your prompt history using `ctrl+r`. ([pr](https://github.com/google-gemini/gemini-cli/pull/5539) by [@Aisha630](https://github.com/Aisha630)) -- **Input undo/redo:** Recover accidentally deleted text in the input prompt using `ctrl+z` (undo) and `ctrl+shift+z` (redo). ([pr](https://github.com/google-gemini/gemini-cli/pull/4625) by [@masiafrest](https://github.com/masiafrest)) -- **Loop detection confirmation:** When loops are detected you are now presented with a dialog to disable detection for the current session. ([pr](https://github.com/google-gemini/gemini-cli/pull/8231) by [@SandyTao520](https://github.com/SandyTao520)) -- **Direct to Google Cloud Telemetry:** Directly send telemetry to Google Cloud for a simpler and more streamlined setup. ([pr](https://github.com/google-gemini/gemini-cli/pull/8541) by [@jerop](https://github.com/jerop)) -- **Visual Mode Indicator Revamp:** ‘shell’, 'accept edits' and 'yolo' modes now have colors to match their impact / usage. Input box now also updates. ([shell](https://imgur.com/a/DovpVF1), [accept-edits](https://imgur.com/a/33KDz3J), [yolo](https://imgur.com/a/tbFwIWp), [pr](https://github.com/google-gemini/gemini-cli/pull/8200) by [@miguelsolorio](https://github.com/miguelsolorio)) -- **Small features, polish, reliability & bug fixes:** A large amount of changes, smaller features, UI updates, reliability and bug fixes + general polish made it in this week! +- 🎉 **Higher limits for Google AI Pro and Ultra subscribers:** We’re psyched to + finally announce that Google AI Pro and AI Ultra subscribers now get access to + significantly higher 2.5 quota limits for Gemini CLI! + - **Announcement:** + [https://blog.google/technology/developers/gemini-cli-code-assist-higher-limits/](https://blog.google/technology/developers/gemini-cli-code-assist-higher-limits/) +- 🎉**Gemini CLI Databases and BigQuery Extensions:** Connect Gemini CLI to all + of your cloud data with Gemini CLI. + - Announcement and how to get started with each of the below extensions: + [https://cloud.google.com/blog/products/databases/gemini-cli-extensions-for-google-data-cloud?e=48754805](https://cloud.google.com/blog/products/databases/gemini-cli-extensions-for-google-data-cloud?e=48754805) + - **AlloyDB:** Interact, manage and observe AlloyDB for PostgreSQL databases + ([manage](https://github.com/gemini-cli-extensions/alloydb#configuration), + [observe](https://github.com/gemini-cli-extensions/alloydb-observability#configuration)) + - **BigQuery:** Connect and query your BigQuery datasets or utilize a + sub-agent for contextual insights + ([query](https://github.com/gemini-cli-extensions/bigquery-data-analytics#configuration), + [sub-agent](https://github.com/gemini-cli-extensions/bigquery-conversational-analytics)) + - **Cloud SQL:** Interact, manage and observe Cloud SQL for PostgreSQL + ([manage](https://github.com/gemini-cli-extensions/cloud-sql-postgresql#configuration),[ observe](https://github.com/gemini-cli-extensions/cloud-sql-postgresql-observability#configuration)), + Cloud SQL for MySQL + ([manage](https://github.com/gemini-cli-extensions/cloud-sql-mysql#configuration),[ observe](https://github.com/gemini-cli-extensions/cloud-sql-mysql-observability#configuration)) + and Cloud SQL for SQL Server + ([manage](https://github.com/gemini-cli-extensions/cloud-sql-sqlserver#configuration),[ observe](https://github.com/gemini-cli-extensions/cloud-sql-sqlserver-observability#configuration)) + databases. + - **Dataplex:** Discover, manage, and govern data and AI artifacts + ([extension](https://github.com/gemini-cli-extensions/dataplex#configuration)) + - **Firestore:** Interact with Firestore databases, collections and documents + ([extension](https://github.com/gemini-cli-extensions/firestore-native#configuration)) + - **Looker:** Query data, run Looks and create dashboards + ([extension](https://github.com/gemini-cli-extensions/looker#configuration)) + - **MySQL:** Interact with MySQL databases + ([extension](https://github.com/gemini-cli-extensions/mysql#configuration)) + - **Postgres:** Interact with PostgreSQL databases + ([extension](https://github.com/gemini-cli-extensions/postgres#configuration)) + - **Spanner:** Interact with Spanner databases + ([extension](https://github.com/gemini-cli-extensions/spanner#configuration)) + - **SQL Server:** Interact with SQL Server databases + ([extension](https://github.com/gemini-cli-extensions/sql-server#configuration)) + - **MCP Toolbox:** Configure and load custom tools for more than 30+ data + sources + ([extension](https://github.com/gemini-cli-extensions/mcp-toolbox#configuration)) +- **JSON output mode:** Have Gemini CLI output JSON with `--output-format json` + when invoked headlessly for easy parsing and post-processing. Includes + response, stats and errors. + ([pr](https://github.com/google-gemini/gemini-cli/pull/8119) by + [@jerop](https://github.com/jerop)) +- **Keybinding triggered approvals:** When you use shortcuts (`shift+y` or + `shift+tab`) to activate YOLO/auto-edit modes any pending confirmation dialogs + will now approve. ([pr](https://github.com/google-gemini/gemini-cli/pull/6665) + by [@bulkypanda](https://github.com/bulkypanda)) +- **Chat sharing:** Convert the current conversation to a Markdown or JSON file + with _/chat share <file.md|file.json>_ + ([pr](https://github.com/google-gemini/gemini-cli/pull/8139) by + [@rramkumar1](https://github.com/rramkumar1)) +- **Prompt search:** Search your prompt history using `ctrl+r`. + ([pr](https://github.com/google-gemini/gemini-cli/pull/5539) by + [@Aisha630](https://github.com/Aisha630)) +- **Input undo/redo:** Recover accidentally deleted text in the input prompt + using `ctrl+z` (undo) and `ctrl+shift+z` (redo). + ([pr](https://github.com/google-gemini/gemini-cli/pull/4625) by + [@masiafrest](https://github.com/masiafrest)) +- **Loop detection confirmation:** When loops are detected you are now presented + with a dialog to disable detection for the current session. + ([pr](https://github.com/google-gemini/gemini-cli/pull/8231) by + [@SandyTao520](https://github.com/SandyTao520)) +- **Direct to Google Cloud Telemetry:** Directly send telemetry to Google Cloud + for a simpler and more streamlined setup. + ([pr](https://github.com/google-gemini/gemini-cli/pull/8541) by + [@jerop](https://github.com/jerop)) +- **Visual Mode Indicator Revamp:** ‘shell’, 'accept edits' and 'yolo' modes now + have colors to match their impact / usage. Input box now also updates. + ([shell](https://imgur.com/a/DovpVF1), + [accept-edits](https://imgur.com/a/33KDz3J), + [yolo](https://imgur.com/a/tbFwIWp), + [pr](https://github.com/google-gemini/gemini-cli/pull/8200) by + [@miguelsolorio](https://github.com/miguelsolorio)) +- **Small features, polish, reliability & bug fixes:** A large amount of + changes, smaller features, UI updates, reliability and bug fixes + general + polish made it in this week! ## v0.5.0 - Gemini CLI weekly update - 2025-09-08 -- 🎉**FastMCP + Gemini CLI**🎉: Quickly install and manage your Gemini CLI MCP servers with FastMCP ([video](https://imgur.com/a/m8QdCPh), [pr](https://github.com/jlowin/fastmcp/pull/1709) by [@jackwotherspoon](https://github.com/jackwotherspoon)**)** - - Getting started: [https://gofastmcp.com/integrations/gemini-cli](https://gofastmcp.com/integrations/gemini-cli) -- **Positional Prompt for Non-Interactive:** Seamlessly invoke Gemini CLI headlessly via `gemini "Hello"`. Synonymous with passing `-p`. ([gif](https://imgur.com/a/hcBznpB), [pr](https://github.com/google-gemini/gemini-cli/pull/7668) by [@allenhutchison](https://github.com/allenhutchison)) -- **Experimental Tool output truncation:** Enable truncating shell tool outputs and saving full output to a file by setting `"enableToolOutputTruncation": true `([pr](https://github.com/google-gemini/gemini-cli/pull/8039) by [@SandyTao520](https://github.com/SandyTao520)) -- **Edit Tool improvements:** Gemini CLI’s ability to edit files should now be far more capable. ([pr](https://github.com/google-gemini/gemini-cli/pull/7679) by [@silviojr](https://github.com/silviojr)) -- **Custom witty messages:** The feature you’ve all been waiting for… Personalized witty loading messages via `"ui": { "customWittyPhrases": ["YOLO"]}` in `settings.json`. ([pr](https://github.com/google-gemini/gemini-cli/pull/7641) by [@JayadityaGit](https://github.com/JayadityaGit)) -- **Nested .gitignore File Handling:** Nested `.gitignore` files are now respected. ([pr](https://github.com/google-gemini/gemini-cli/pull/7645) by [@gsquared94](https://github.com/gsquared94)) -- **Enforced authentication:** System administrators can now mandate a specific authentication method via `"enforcedAuthType": "oauth-personal|gemini-api-key|…"`in `settings.json`. ([pr](https://github.com/google-gemini/gemini-cli/pull/6564) by [@chrstnb](https://github.com/chrstnb)) -- **A2A development-tool extension:** An RFC for an Agent2Agent ([A2A](https://a2a-protocol.org/latest/)) powered extension for developer tool use cases. ([feedback](https://github.com/google-gemini/gemini-cli/discussions/7822), [pr](https://github.com/google-gemini/gemini-cli/pull/7817) by [@skeshive](https://github.com/skeshive)) -- **Hands on Codelab: **[https://codelabs.developers.google.com/gemini-cli-hands-on](https://codelabs.developers.google.com/gemini-cli-hands-on) -- **Small features, polish, reliability & bug fixes:** A large amount of changes, smaller features, UI updates, reliability and bug fixes + general polish made it in this week! +- 🎉**FastMCP + Gemini CLI**🎉: Quickly install and manage your Gemini CLI MCP + servers with FastMCP ([video](https://imgur.com/a/m8QdCPh), + [pr](https://github.com/jlowin/fastmcp/pull/1709) by + [@jackwotherspoon](https://github.com/jackwotherspoon)**)** + - Getting started: + [https://gofastmcp.com/integrations/gemini-cli](https://gofastmcp.com/integrations/gemini-cli) +- **Positional Prompt for Non-Interactive:** Seamlessly invoke Gemini CLI + headlessly via `gemini "Hello"`. Synonymous with passing `-p`. + ([gif](https://imgur.com/a/hcBznpB), + [pr](https://github.com/google-gemini/gemini-cli/pull/7668) by + [@allenhutchison](https://github.com/allenhutchison)) +- **Experimental Tool output truncation:** Enable truncating shell tool outputs + and saving full output to a file by setting + `"enableToolOutputTruncation": true `([pr](https://github.com/google-gemini/gemini-cli/pull/8039) + by [@SandyTao520](https://github.com/SandyTao520)) +- **Edit Tool improvements:** Gemini CLI’s ability to edit files should now be + far more capable. ([pr](https://github.com/google-gemini/gemini-cli/pull/7679) + by [@silviojr](https://github.com/silviojr)) +- **Custom witty messages:** The feature you’ve all been waiting for… + Personalized witty loading messages via + `"ui": { "customWittyPhrases": ["YOLO"]}` in `settings.json`. + ([pr](https://github.com/google-gemini/gemini-cli/pull/7641) by + [@JayadityaGit](https://github.com/JayadityaGit)) +- **Nested .gitignore File Handling:** Nested `.gitignore` files are now + respected. ([pr](https://github.com/google-gemini/gemini-cli/pull/7645) by + [@gsquared94](https://github.com/gsquared94)) +- **Enforced authentication:** System administrators can now mandate a specific + authentication method via + `"enforcedAuthType": "oauth-personal|gemini-api-key|…"`in `settings.json`. + ([pr](https://github.com/google-gemini/gemini-cli/pull/6564) by + [@chrstnb](https://github.com/chrstnb)) +- **A2A development-tool extension:** An RFC for an Agent2Agent + ([A2A](https://a2a-protocol.org/latest/)) powered extension for developer tool + use cases. + ([feedback](https://github.com/google-gemini/gemini-cli/discussions/7822), + [pr](https://github.com/google-gemini/gemini-cli/pull/7817) by + [@skeshive](https://github.com/skeshive)) +- **Hands on Codelab: + **[https://codelabs.developers.google.com/gemini-cli-hands-on](https://codelabs.developers.google.com/gemini-cli-hands-on) +- **Small features, polish, reliability & bug fixes:** A large amount of + changes, smaller features, UI updates, reliability and bug fixes + general + polish made it in this week! ## v0.4.0 - Gemini CLI weekly update - 2025-09-01 -- 🎉**Gemini CLI CloudRun and Security Integrations**🎉: Automate app deployment and security analysis with CloudRun and Security extension integrations. Once installed deploy your app to the cloud with `/deploy` and find and fix security vulnerabilities with `/security:analyze`. - - Announcement and how to get started: [https://cloud.google.com/blog/products/ai-machine-learning/automate-app-deployment-and-security-analysis-with-new-gemini-cli-extensions](https://cloud.google.com/blog/products/ai-machine-learning/automate-app-deployment-and-security-analysis-with-new-gemini-cli-extensions) +- 🎉**Gemini CLI CloudRun and Security Integrations**🎉: Automate app deployment + and security analysis with CloudRun and Security extension integrations. Once + installed deploy your app to the cloud with `/deploy` and find and fix + security vulnerabilities with `/security:analyze`. + - Announcement and how to get started: + [https://cloud.google.com/blog/products/ai-machine-learning/automate-app-deployment-and-security-analysis-with-new-gemini-cli-extensions](https://cloud.google.com/blog/products/ai-machine-learning/automate-app-deployment-and-security-analysis-with-new-gemini-cli-extensions) - **Experimental** - - **Edit Tool:** Give our new edit tool a try by setting `"useSmartEdit": true` in `settings.json`! ([feedback](https://github.com/google-gemini/gemini-cli/discussions/7758), [pr](https://github.com/google-gemini/gemini-cli/pull/6823) by [@silviojr](https://github.com/silviojr)) - - **Model talking to itself fix:** We’ve removed a model workaround that would encourage Gemini CLI to continue conversations on your behalf. This may be disruptive and can be disabled via `"skipNextSpeakerCheck": false` in your `settings.json` ([feedback](https://github.com/google-gemini/gemini-cli/discussions/6666), [pr](https://github.com/google-gemini/gemini-cli/pull/7614) by [@SandyTao520](https://github.com/SandyTao520)) - - **Prompt completion:** Get real-time AI suggestions to complete your prompts as you type. Enable it with `"general": { "enablePromptCompletion": true }` and share your feedback! ([gif](https://miro.medium.com/v2/resize:fit:2000/format:webp/1*hvegW7YXOg6N_beUWhTdxA.gif), [pr](https://github.com/google-gemini/gemini-cli/pull/4691) by [@3ks](https://github.com/3ks)) -- **Footer visibility configuration:** Customize the CLI's footer look and feel in `settings.json` ([pr](https://github.com/google-gemini/gemini-cli/pull/7419) by [@miguelsolorio](https://github.com/miguelsolorio)) + - **Edit Tool:** Give our new edit tool a try by setting + `"useSmartEdit": true` in `settings.json`! + ([feedback](https://github.com/google-gemini/gemini-cli/discussions/7758), + [pr](https://github.com/google-gemini/gemini-cli/pull/6823) by + [@silviojr](https://github.com/silviojr)) + - **Model talking to itself fix:** We’ve removed a model workaround that would + encourage Gemini CLI to continue conversations on your behalf. This may be + disruptive and can be disabled via `"skipNextSpeakerCheck": false` in your + `settings.json` + ([feedback](https://github.com/google-gemini/gemini-cli/discussions/6666), + [pr](https://github.com/google-gemini/gemini-cli/pull/7614) by + [@SandyTao520](https://github.com/SandyTao520)) + - **Prompt completion:** Get real-time AI suggestions to complete your prompts + as you type. Enable it with `"general": { "enablePromptCompletion": true }` + and share your feedback! + ([gif](https://miro.medium.com/v2/resize:fit:2000/format:webp/1*hvegW7YXOg6N_beUWhTdxA.gif), + [pr](https://github.com/google-gemini/gemini-cli/pull/4691) by + [@3ks](https://github.com/3ks)) +- **Footer visibility configuration:** Customize the CLI's footer look and feel + in `settings.json` + ([pr](https://github.com/google-gemini/gemini-cli/pull/7419) by + [@miguelsolorio](https://github.com/miguelsolorio)) - `hideCWD`: hide current working directory. - `hideSandboxStatus`: hide sandbox status. - `hideModelInfo`: hide current model information. - `hideContextSummary`: hide request context summary. -- **Citations:** For enterprise Code Assist licenses users will now see citations in their responses by default. Enable this yourself with `"showCitations": true` ([pr](https://github.com/google-gemini/gemini-cli/pull/7350) by [@scidomino](https://github.com/scidomino)) -- **Pro Quota Ddalog:** Handle daily Pro model usage limits with an interactive dialog that lets you immediately switch auth or fallback. ([pr](https://github.com/google-gemini/gemini-cli/pull/7094) by [@JayadityaGit](https://github.com/JayadityaGit)) -- **Custom commands @:** Embed local file or directory content directly into your custom command prompts using `@{path}` syntax ([gif](https://miro.medium.com/v2/resize:fit:2000/format:webp/1*GosBAo2SjMfFffAnzT7ZMg.gif), [pr](https://github.com/google-gemini/gemini-cli/pull/6716) by [@abhipatel12](https://github.com/abhipatel12)) -- **2.5 Flash Lite support:** You can now use the `gemini-2.5-flash-lite` model for Gemini CLI via `gemini -m …`. ([gif](https://miro.medium.com/v2/resize:fit:2000/format:webp/1*P4SKwnrsyBuULoHrFqsFKQ.gif), [pr](https://github.com/google-gemini/gemini-cli/pull/4652) by [@psinha40898](https://github.com/psinha40898)) -- **CLI streamlining:** We have deprecated a number of command line arguments in favor of `settings.json` alternatives. We will remove these arguments in a future release. See the PR for the full list of deprecations. ([pr](https://github.com/google-gemini/gemini-cli/pull/7360) by [@allenhutchison](https://github.com/allenhutchison)) -- **JSON session summary:** Track and save detailed CLI session statistics to a JSON file for performance analysis with `--session-summary ` ([pr](https://github.com/google-gemini/gemini-cli/pull/7347) by [@leehagoodjames](https://github.com/leehagoodjames)) -- **Robust keyboard handling:** More reliable and consistent behavior for arrow keys, special keys (Home, End, etc.), and modifier combinations across various terminals. ([pr](https://github.com/google-gemini/gemini-cli/pull/7118) by [@deepankarsharma](https://github.com/deepankarsharma)) -- **MCP loading indicator:** Provides visual feedback during CLI initialization when connecting to multiple servers. ([pr](https://github.com/google-gemini/gemini-cli/pull/6923) by [@swissspidy](https://github.com/swissspidy)) -- **Small features, polish, reliability & bug fixes:** A large amount of changes, smaller features, UI updates, reliability and bug fixes + general polish made it in this week! +- **Citations:** For enterprise Code Assist licenses users will now see + citations in their responses by default. Enable this yourself with + `"showCitations": true` + ([pr](https://github.com/google-gemini/gemini-cli/pull/7350) by + [@scidomino](https://github.com/scidomino)) +- **Pro Quota Ddalog:** Handle daily Pro model usage limits with an interactive + dialog that lets you immediately switch auth or fallback. + ([pr](https://github.com/google-gemini/gemini-cli/pull/7094) by + [@JayadityaGit](https://github.com/JayadityaGit)) +- **Custom commands @:** Embed local file or directory content directly into + your custom command prompts using `@{path}` syntax + ([gif](https://miro.medium.com/v2/resize:fit:2000/format:webp/1*GosBAo2SjMfFffAnzT7ZMg.gif), + [pr](https://github.com/google-gemini/gemini-cli/pull/6716) by + [@abhipatel12](https://github.com/abhipatel12)) +- **2.5 Flash Lite support:** You can now use the `gemini-2.5-flash-lite` model + for Gemini CLI via `gemini -m …`. + ([gif](https://miro.medium.com/v2/resize:fit:2000/format:webp/1*P4SKwnrsyBuULoHrFqsFKQ.gif), + [pr](https://github.com/google-gemini/gemini-cli/pull/4652) by + [@psinha40898](https://github.com/psinha40898)) +- **CLI streamlining:** We have deprecated a number of command line arguments in + favor of `settings.json` alternatives. We will remove these arguments in a + future release. See the PR for the full list of deprecations. + ([pr](https://github.com/google-gemini/gemini-cli/pull/7360) by + [@allenhutchison](https://github.com/allenhutchison)) +- **JSON session summary:** Track and save detailed CLI session statistics to a + JSON file for performance analysis with `--session-summary ` + ([pr](https://github.com/google-gemini/gemini-cli/pull/7347) by + [@leehagoodjames](https://github.com/leehagoodjames)) +- **Robust keyboard handling:** More reliable and consistent behavior for arrow + keys, special keys (Home, End, etc.), and modifier combinations across various + terminals. ([pr](https://github.com/google-gemini/gemini-cli/pull/7118) by + [@deepankarsharma](https://github.com/deepankarsharma)) +- **MCP loading indicator:** Provides visual feedback during CLI initialization + when connecting to multiple servers. + ([pr](https://github.com/google-gemini/gemini-cli/pull/6923) by + [@swissspidy](https://github.com/swissspidy)) +- **Small features, polish, reliability & bug fixes:** A large amount of + changes, smaller features, UI updates, reliability and bug fixes + general + polish made it in this week! diff --git a/docs/cli/checkpointing.md b/docs/cli/checkpointing.md index 5d9d29d4cf..4f8bf2f776 100644 --- a/docs/cli/checkpointing.md +++ b/docs/cli/checkpointing.md @@ -1,30 +1,49 @@ # Checkpointing -The Gemini CLI includes a Checkpointing feature that automatically saves a snapshot of your project's state before any file modifications are made by AI-powered tools. This allows you to safely experiment with and apply code changes, knowing you can instantly revert back to the state before the tool was run. +The Gemini CLI includes a Checkpointing feature that automatically saves a +snapshot of your project's state before any file modifications are made by +AI-powered tools. This allows you to safely experiment with and apply code +changes, knowing you can instantly revert back to the state before the tool was +run. ## How It Works -When you approve a tool that modifies the file system (like `write_file` or `replace`), the CLI automatically creates a "checkpoint." This checkpoint includes: +When you approve a tool that modifies the file system (like `write_file` or +`replace`), the CLI automatically creates a "checkpoint." This checkpoint +includes: -1. **A Git Snapshot:** A commit is made in a special, shadow Git repository located in your home directory (`~/.gemini/history/`). This snapshot captures the complete state of your project files at that moment. It does **not** interfere with your own project's Git repository. -2. **Conversation History:** The entire conversation you've had with the agent up to that point is saved. -3. **The Tool Call:** The specific tool call that was about to be executed is also stored. +1. **A Git Snapshot:** A commit is made in a special, shadow Git repository + located in your home directory (`~/.gemini/history/`). This + snapshot captures the complete state of your project files at that moment. + It does **not** interfere with your own project's Git repository. +2. **Conversation History:** The entire conversation you've had with the agent + up to that point is saved. +3. **The Tool Call:** The specific tool call that was about to be executed is + also stored. -If you want to undo the change or simply go back, you can use the `/restore` command. Restoring a checkpoint will: +If you want to undo the change or simply go back, you can use the `/restore` +command. Restoring a checkpoint will: - Revert all files in your project to the state captured in the snapshot. - Restore the conversation history in the CLI. -- Re-propose the original tool call, allowing you to run it again, modify it, or simply ignore it. +- Re-propose the original tool call, allowing you to run it again, modify it, or + simply ignore it. -All checkpoint data, including the Git snapshot and conversation history, is stored locally on your machine. The Git snapshot is stored in the shadow repository while the conversation history and tool calls are saved in a JSON file in your project's temporary directory, typically located at `~/.gemini/tmp//checkpoints`. +All checkpoint data, including the Git snapshot and conversation history, is +stored locally on your machine. The Git snapshot is stored in the shadow +repository while the conversation history and tool calls are saved in a JSON +file in your project's temporary directory, typically located at +`~/.gemini/tmp//checkpoints`. ## Enabling the Feature -The Checkpointing feature is disabled by default. To enable it, you can either use a command-line flag or edit your `settings.json` file. +The Checkpointing feature is disabled by default. To enable it, you can either +use a command-line flag or edit your `settings.json` file. ### Using the Command-Line Flag -You can enable checkpointing for the current session by using the `--checkpointing` flag when starting the Gemini CLI: +You can enable checkpointing for the current session by using the +`--checkpointing` flag when starting the Gemini CLI: ```bash gemini --checkpointing @@ -32,7 +51,8 @@ gemini --checkpointing ### Using the `settings.json` File -To enable checkpointing by default for all sessions, you need to edit your `settings.json` file. +To enable checkpointing by default for all sessions, you need to edit your +`settings.json` file. Add the following key to your `settings.json`: @@ -48,7 +68,8 @@ Add the following key to your `settings.json`: ## Using the `/restore` Command -Once enabled, checkpoints are created automatically. To manage them, you use the `/restore` command. +Once enabled, checkpoints are created automatically. To manage them, you use the +`/restore` command. ### List Available Checkpoints @@ -58,11 +79,15 @@ To see a list of all saved checkpoints for the current project, simply run: /restore ``` -The CLI will display a list of available checkpoint files. These file names are typically composed of a timestamp, the name of the file being modified, and the name of the tool that was about to be run (e.g., `2025-06-22T10-00-00_000Z-my-file.txt-write_file`). +The CLI will display a list of available checkpoint files. These file names are +typically composed of a timestamp, the name of the file being modified, and the +name of the tool that was about to be run (e.g., +`2025-06-22T10-00-00_000Z-my-file.txt-write_file`). ### Restore a Specific Checkpoint -To restore your project to a specific checkpoint, use the checkpoint file from the list: +To restore your project to a specific checkpoint, use the checkpoint file from +the list: ``` /restore @@ -74,4 +99,6 @@ For example: /restore 2025-06-22T10-00-00_000Z-my-file.txt-write_file ``` -After running the command, your files and conversation will be immediately restored to the state they were in when the checkpoint was created, and the original tool prompt will reappear. +After running the command, your files and conversation will be immediately +restored to the state they were in when the checkpoint was created, and the +original tool prompt will reappear. diff --git a/docs/cli/commands.md b/docs/cli/commands.md index 3b94bd7495..b5b25a682a 100644 --- a/docs/cli/commands.md +++ b/docs/cli/commands.md @@ -1,6 +1,8 @@ # CLI Commands -Gemini CLI supports several built-in commands to help you manage your session, customize the interface, and control its behavior. These commands are prefixed with a forward slash (`/`), an at symbol (`@`), or an exclamation mark (`!`). +Gemini CLI supports several built-in commands to help you manage your session, +customize the interface, and control its behavior. These commands are prefixed +with a forward slash (`/`), an at symbol (`@`), or an exclamation mark (`!`). ## Slash commands (`/`) @@ -9,19 +11,31 @@ Slash commands provide meta-level control over the CLI itself. ### Built-in Commands - **`/bug`** - - **Description:** File an issue about Gemini CLI. By default, the issue is filed within the GitHub repository for Gemini CLI. The string you enter after `/bug` will become the headline for the bug being filed. The default `/bug` behavior can be modified using the `advanced.bugCommand` setting in your `.gemini/settings.json` files. + - **Description:** File an issue about Gemini CLI. By default, the issue is + filed within the GitHub repository for Gemini CLI. The string you enter + after `/bug` will become the headline for the bug being filed. The default + `/bug` behavior can be modified using the `advanced.bugCommand` setting in + your `.gemini/settings.json` files. - **`/chat`** - - **Description:** Save and resume conversation history for branching conversation state interactively, or resuming a previous state from a later session. + - **Description:** Save and resume conversation history for branching + conversation state interactively, or resuming a previous state from a later + session. - **Sub-commands:** - **`save`** - - **Description:** Saves the current conversation history. You must add a `` for identifying the conversation state. + - **Description:** Saves the current conversation history. You must add a + `` for identifying the conversation state. - **Usage:** `/chat save ` - - **Details on Checkpoint Location:** The default locations for saved chat checkpoints are: + - **Details on Checkpoint Location:** The default locations for saved chat + checkpoints are: - Linux/macOS: `~/.gemini/tmp//` - Windows: `C:\Users\\.gemini\tmp\\` - - When you run `/chat list`, the CLI only scans these specific directories to find available checkpoints. - - **Note:** These checkpoints are for manually saving and resuming conversation states. For automatic checkpoints created before file modifications, see the [Checkpointing documentation](../cli/checkpointing.md). + - When you run `/chat list`, the CLI only scans these specific + directories to find available checkpoints. + - **Note:** These checkpoints are for manually saving and resuming + conversation states. For automatic checkpoints created before file + modifications, see the + [Checkpointing documentation](../cli/checkpointing.md). - **`resume`** - **Description:** Resumes a conversation from a previous save. - **Usage:** `/chat resume ` @@ -31,164 +45,255 @@ Slash commands provide meta-level control over the CLI itself. - **Description:** Deletes a saved conversation checkpoint. - **Usage:** `/chat delete ` - **`share`** - - **Description** Writes the current conversation to a provided Markdown or JSON file. - - **Usage** `/chat share file.md` or `/chat share file.json`. If no filename is provided, then the CLI will generate one. + - **Description** Writes the current conversation to a provided Markdown + or JSON file. + - **Usage** `/chat share file.md` or `/chat share file.json`. If no + filename is provided, then the CLI will generate one. - **`/clear`** - - **Description:** Clear the terminal screen, including the visible session history and scrollback within the CLI. The underlying session data (for history recall) might be preserved depending on the exact implementation, but the visual display is cleared. - - **Keyboard shortcut:** Press **Ctrl+L** at any time to perform a clear action. + - **Description:** Clear the terminal screen, including the visible session + history and scrollback within the CLI. The underlying session data (for + history recall) might be preserved depending on the exact implementation, + but the visual display is cleared. + - **Keyboard shortcut:** Press **Ctrl+L** at any time to perform a clear + action. - **`/compress`** - - **Description:** Replace the entire chat context with a summary. This saves on tokens used for future tasks while retaining a high level summary of what has happened. + - **Description:** Replace the entire chat context with a summary. This saves + on tokens used for future tasks while retaining a high level summary of what + has happened. - **`/copy`** - - **Description:** Copies the last output produced by Gemini CLI to your clipboard, for easy sharing or reuse. - - **Note:** This command requires platform-specific clipboard tools to be installed. - - On Linux, it requires `xclip` or `xsel`. You can typically install them using your system's package manager. - - On macOS, it requires `pbcopy`, and on Windows, it requires `clip`. These tools are typically pre-installed on their respective systems. + - **Description:** Copies the last output produced by Gemini CLI to your + clipboard, for easy sharing or reuse. + - **Note:** This command requires platform-specific clipboard tools to be + installed. + - On Linux, it requires `xclip` or `xsel`. You can typically install them + using your system's package manager. + - On macOS, it requires `pbcopy`, and on Windows, it requires `clip`. These + tools are typically pre-installed on their respective systems. - **`/directory`** (or **`/dir`**) - **Description:** Manage workspace directories for multi-directory support. - **Sub-commands:** - **`add`**: - - **Description:** Add a directory to the workspace. The path can be absolute or relative to the current working directory. Moreover, the reference from home directory is supported as well. + - **Description:** Add a directory to the workspace. The path can be + absolute or relative to the current working directory. Moreover, the + reference from home directory is supported as well. - **Usage:** `/directory add ,` - - **Note:** Disabled in restrictive sandbox profiles. If you're using that, use `--include-directories` when starting the session instead. + - **Note:** Disabled in restrictive sandbox profiles. If you're using + that, use `--include-directories` when starting the session instead. - **`show`**: - - **Description:** Display all directories added by `/directory add` and `--include-directories`. + - **Description:** Display all directories added by `/directory add` and + `--include-directories`. - **Usage:** `/directory show` - **`/editor`** - **Description:** Open a dialog for selecting supported editors. - **`/extensions`** - - **Description:** Lists all active extensions in the current Gemini CLI session. See [Gemini CLI Extensions](../extensions/index.md). + - **Description:** Lists all active extensions in the current Gemini CLI + session. See [Gemini CLI Extensions](../extensions/index.md). - **`/help`** (or **`/?`**) - - **Description:** Display help information about Gemini CLI, including available commands and their usage. + - **Description:** Display help information about Gemini CLI, including + available commands and their usage. - **`/mcp`** - - **Description:** List configured Model Context Protocol (MCP) servers, their connection status, server details, and available tools. + - **Description:** List configured Model Context Protocol (MCP) servers, their + connection status, server details, and available tools. - **Sub-commands:** - **`desc`** or **`descriptions`**: - **Description:** Show detailed descriptions for MCP servers and tools. - **`nodesc`** or **`nodescriptions`**: - **Description:** Hide tool descriptions, showing only the tool names. - **`schema`**: - - **Description:** Show the full JSON schema for the tool's configured parameters. - - **Keyboard Shortcut:** Press **Ctrl+T** at any time to toggle between showing and hiding tool descriptions. + - **Description:** Show the full JSON schema for the tool's configured + parameters. + - **Keyboard Shortcut:** Press **Ctrl+T** at any time to toggle between + showing and hiding tool descriptions. - **`/memory`** - - **Description:** Manage the AI's instructional context (hierarchical memory loaded from `GEMINI.md` files). + - **Description:** Manage the AI's instructional context (hierarchical memory + loaded from `GEMINI.md` files). - **Sub-commands:** - **`add`**: - - **Description:** Adds the following text to the AI's memory. Usage: `/memory add ` + - **Description:** Adds the following text to the AI's memory. Usage: + `/memory add ` - **`show`**: - - **Description:** Display the full, concatenated content of the current hierarchical memory that has been loaded from all `GEMINI.md` files. This lets you inspect the instructional context being provided to the Gemini model. + - **Description:** Display the full, concatenated content of the current + hierarchical memory that has been loaded from all `GEMINI.md` files. + This lets you inspect the instructional context being provided to the + Gemini model. - **`refresh`**: - - **Description:** Reload the hierarchical instructional memory from all `GEMINI.md` files found in the configured locations (global, project/ancestors, and sub-directories). This command updates the model with the latest `GEMINI.md` content. + - **Description:** Reload the hierarchical instructional memory from all + `GEMINI.md` files found in the configured locations (global, + project/ancestors, and sub-directories). This command updates the model + with the latest `GEMINI.md` content. - **`list`**: - - **Description:** Lists the paths of the GEMINI.md files in use for hierarchical memory. - - **Note:** For more details on how `GEMINI.md` files contribute to hierarchical memory, see the [CLI Configuration documentation](../get-started/configuration.md). + - **Description:** Lists the paths of the GEMINI.md files in use for + hierarchical memory. + - **Note:** For more details on how `GEMINI.md` files contribute to + hierarchical memory, see the + [CLI Configuration documentation](../get-started/configuration.md). - **`/restore`** - - **Description:** Restores the project files to the state they were in just before a tool was executed. This is particularly useful for undoing file edits made by a tool. If run without a tool call ID, it will list available checkpoints to restore from. + - **Description:** Restores the project files to the state they were in just + before a tool was executed. This is particularly useful for undoing file + edits made by a tool. If run without a tool call ID, it will list available + checkpoints to restore from. - **Usage:** `/restore [tool_call_id]` - - **Note:** Only available if the CLI is invoked with the `--checkpointing` option or configured via [settings](../get-started/configuration.md). See [Checkpointing documentation](../cli/checkpointing.md) for more details. + - **Note:** Only available if the CLI is invoked with the `--checkpointing` + option or configured via [settings](../get-started/configuration.md). See + [Checkpointing documentation](../cli/checkpointing.md) for more details. - **`/settings`** - - **Description:** Open the settings editor to view and modify Gemini CLI settings. - - **Details:** This command provides a user-friendly interface for changing settings that control the behavior and appearance of Gemini CLI. It is equivalent to manually editing the `.gemini/settings.json` file, but with validation and guidance to prevent errors. - - **Usage:** Simply run `/settings` and the editor will open. You can then browse or search for specific settings, view their current values, and modify them as desired. Changes to some settings are applied immediately, while others require a restart. + - **Description:** Open the settings editor to view and modify Gemini CLI + settings. + - **Details:** This command provides a user-friendly interface for changing + settings that control the behavior and appearance of Gemini CLI. It is + equivalent to manually editing the `.gemini/settings.json` file, but with + validation and guidance to prevent errors. + - **Usage:** Simply run `/settings` and the editor will open. You can then + browse or search for specific settings, view their current values, and + modify them as desired. Changes to some settings are applied immediately, + while others require a restart. - **`/stats`** - - **Description:** Display detailed statistics for the current Gemini CLI session, including token usage, cached token savings (when available), and session duration. Note: Cached token information is only displayed when cached tokens are being used, which occurs with API key authentication but not with OAuth authentication at this time. + - **Description:** Display detailed statistics for the current Gemini CLI + session, including token usage, cached token savings (when available), and + session duration. Note: Cached token information is only displayed when + cached tokens are being used, which occurs with API key authentication but + not with OAuth authentication at this time. - [**`/theme`**](./themes.md) - - **Description:** Open a dialog that lets you change the visual theme of Gemini CLI. + - **Description:** Open a dialog that lets you change the visual theme of + Gemini CLI. - **`/auth`** - - **Description:** Open a dialog that lets you change the authentication method. + - **Description:** Open a dialog that lets you change the authentication + method. - **`/about`** - - **Description:** Show version info. Please share this information when filing issues. + - **Description:** Show version info. Please share this information when + filing issues. - [**`/tools`**](../tools/index.md) - - **Description:** Display a list of tools that are currently available within Gemini CLI. + - **Description:** Display a list of tools that are currently available within + Gemini CLI. - **Usage:** `/tools [desc]` - **Sub-commands:** - **`desc`** or **`descriptions`**: - - **Description:** Show detailed descriptions of each tool, including each tool's name with its full description as provided to the model. + - **Description:** Show detailed descriptions of each tool, including each + tool's name with its full description as provided to the model. - **`nodesc`** or **`nodescriptions`**: - **Description:** Hide tool descriptions, showing only the tool names. - **`/privacy`** - - **Description:** Display the Privacy Notice and allow users to select whether they consent to the collection of their data for service improvement purposes. + - **Description:** Display the Privacy Notice and allow users to select + whether they consent to the collection of their data for service improvement + purposes. - **`/quit`** (or **`/exit`**) - **Description:** Exit Gemini CLI. - **`/vim`** - - **Description:** Toggle vim mode on or off. When vim mode is enabled, the input area supports vim-style navigation and editing commands in both NORMAL and INSERT modes. + - **Description:** Toggle vim mode on or off. When vim mode is enabled, the + input area supports vim-style navigation and editing commands in both NORMAL + and INSERT modes. - **Features:** - - **NORMAL mode:** Navigate with `h`, `j`, `k`, `l`; jump by words with `w`, `b`, `e`; go to line start/end with `0`, `$`, `^`; go to specific lines with `G` (or `gg` for first line) + - **NORMAL mode:** Navigate with `h`, `j`, `k`, `l`; jump by words with `w`, + `b`, `e`; go to line start/end with `0`, `$`, `^`; go to specific lines + with `G` (or `gg` for first line) - **INSERT mode:** Standard text input with escape to return to NORMAL mode - - **Editing commands:** Delete with `x`, change with `c`, insert with `i`, `a`, `o`, `O`; complex operations like `dd`, `cc`, `dw`, `cw` + - **Editing commands:** Delete with `x`, change with `c`, insert with `i`, + `a`, `o`, `O`; complex operations like `dd`, `cc`, `dw`, `cw` - **Count support:** Prefix commands with numbers (e.g., `3h`, `5w`, `10G`) - **Repeat last command:** Use `.` to repeat the last editing operation - - **Persistent setting:** Vim mode preference is saved to `~/.gemini/settings.json` and restored between sessions - - **Status indicator:** When enabled, shows `[NORMAL]` or `[INSERT]` in the footer + - **Persistent setting:** Vim mode preference is saved to + `~/.gemini/settings.json` and restored between sessions + - **Status indicator:** When enabled, shows `[NORMAL]` or `[INSERT]` in the + footer - **`/init`** - - **Description:** To help users easily create a `GEMINI.md` file, this command analyzes the current directory and generates a tailored context file, making it simpler for them to provide project-specific instructions to the Gemini agent. + - **Description:** To help users easily create a `GEMINI.md` file, this + command analyzes the current directory and generates a tailored context + file, making it simpler for them to provide project-specific instructions to + the Gemini agent. ### Custom Commands -Custom commands allow you to create personalized shortcuts for your most-used prompts. For detailed instructions on how to create, manage, and use them, please see the dedicated [Custom Commands documentation](./custom-commands.md). +Custom commands allow you to create personalized shortcuts for your most-used +prompts. For detailed instructions on how to create, manage, and use them, +please see the dedicated [Custom Commands documentation](./custom-commands.md). ## Input Prompt Shortcuts These shortcuts apply directly to the input prompt for text manipulation. - **Undo:** - - **Keyboard shortcut:** Press **Ctrl+z** to undo the last action in the input prompt. + - **Keyboard shortcut:** Press **Ctrl+z** to undo the last action in the input + prompt. - **Redo:** - - **Keyboard shortcut:** Press **Ctrl+Shift+Z** to redo the last undone action in the input prompt. + - **Keyboard shortcut:** Press **Ctrl+Shift+Z** to redo the last undone action + in the input prompt. ## At commands (`@`) -At commands are used to include the content of files or directories as part of your prompt to Gemini. These commands include git-aware filtering. +At commands are used to include the content of files or directories as part of +your prompt to Gemini. These commands include git-aware filtering. - **`@`** - - **Description:** Inject the content of the specified file or files into your current prompt. This is useful for asking questions about specific code, text, or collections of files. + - **Description:** Inject the content of the specified file or files into your + current prompt. This is useful for asking questions about specific code, + text, or collections of files. - **Examples:** - `@path/to/your/file.txt Explain this text.` - `@src/my_project/ Summarize the code in this directory.` - `What is this file about? @README.md` - **Details:** - If a path to a single file is provided, the content of that file is read. - - If a path to a directory is provided, the command attempts to read the content of files within that directory and any subdirectories. - - Spaces in paths should be escaped with a backslash (e.g., `@My\ Documents/file.txt`). - - The command uses the `read_many_files` tool internally. The content is fetched and then inserted into your query before being sent to the Gemini model. - - **Git-aware filtering:** By default, git-ignored files (like `node_modules/`, `dist/`, `.env`, `.git/`) are excluded. This behavior can be changed via the `context.fileFiltering` settings. - - **File types:** The command is intended for text-based files. While it might attempt to read any file, binary files or very large files might be skipped or truncated by the underlying `read_many_files` tool to ensure performance and relevance. The tool indicates if files were skipped. - - **Output:** The CLI will show a tool call message indicating that `read_many_files` was used, along with a message detailing the status and the path(s) that were processed. + - If a path to a directory is provided, the command attempts to read the + content of files within that directory and any subdirectories. + - Spaces in paths should be escaped with a backslash (e.g., + `@My\ Documents/file.txt`). + - The command uses the `read_many_files` tool internally. The content is + fetched and then inserted into your query before being sent to the Gemini + model. + - **Git-aware filtering:** By default, git-ignored files (like + `node_modules/`, `dist/`, `.env`, `.git/`) are excluded. This behavior can + be changed via the `context.fileFiltering` settings. + - **File types:** The command is intended for text-based files. While it + might attempt to read any file, binary files or very large files might be + skipped or truncated by the underlying `read_many_files` tool to ensure + performance and relevance. The tool indicates if files were skipped. + - **Output:** The CLI will show a tool call message indicating that + `read_many_files` was used, along with a message detailing the status and + the path(s) that were processed. - **`@` (Lone at symbol)** - - **Description:** If you type a lone `@` symbol without a path, the query is passed as-is to the Gemini model. This might be useful if you are specifically talking _about_ the `@` symbol in your prompt. + - **Description:** If you type a lone `@` symbol without a path, the query is + passed as-is to the Gemini model. This might be useful if you are + specifically talking _about_ the `@` symbol in your prompt. ### Error handling for `@` commands -- If the path specified after `@` is not found or is invalid, an error message will be displayed, and the query might not be sent to the Gemini model, or it will be sent without the file content. -- If the `read_many_files` tool encounters an error (e.g., permission issues), this will also be reported. +- If the path specified after `@` is not found or is invalid, an error message + will be displayed, and the query might not be sent to the Gemini model, or it + will be sent without the file content. +- If the `read_many_files` tool encounters an error (e.g., permission issues), + this will also be reported. ## Shell mode & passthrough commands (`!`) -The `!` prefix lets you interact with your system's shell directly from within Gemini CLI. +The `!` prefix lets you interact with your system's shell directly from within +Gemini CLI. - **`!`** - - **Description:** Execute the given `` using `bash` on Linux/macOS or `cmd.exe` on Windows. Any output or errors from the command are displayed in the terminal. + - **Description:** Execute the given `` using `bash` on + Linux/macOS or `cmd.exe` on Windows. Any output or errors from the command + are displayed in the terminal. - **Examples:** - `!ls -la` (executes `ls -la` and returns to Gemini CLI) - `!git status` (executes `git status` and returns to Gemini CLI) @@ -196,11 +301,18 @@ The `!` prefix lets you interact with your system's shell directly from within G - **`!` (Toggle shell mode)** - **Description:** Typing `!` on its own toggles shell mode. - **Entering shell mode:** - - When active, shell mode uses a different coloring and a "Shell Mode Indicator". - - While in shell mode, text you type is interpreted directly as a shell command. + - When active, shell mode uses a different coloring and a "Shell Mode + Indicator". + - While in shell mode, text you type is interpreted directly as a shell + command. - **Exiting shell mode:** - - When exited, the UI reverts to its standard appearance and normal Gemini CLI behavior resumes. + - When exited, the UI reverts to its standard appearance and normal Gemini + CLI behavior resumes. -- **Caution for all `!` usage:** Commands you execute in shell mode have the same permissions and impact as if you ran them directly in your terminal. +- **Caution for all `!` usage:** Commands you execute in shell mode have the + same permissions and impact as if you ran them directly in your terminal. -- **Environment Variable:** When a command is executed via `!` or in shell mode, the `GEMINI_CLI=1` environment variable is set in the subprocess's environment. This allows scripts or tools to detect if they are being run from within the Gemini CLI. +- **Environment Variable:** When a command is executed via `!` or in shell mode, + the `GEMINI_CLI=1` environment variable is set in the subprocess's + environment. This allows scripts or tools to detect if they are being run from + within the Gemini CLI. diff --git a/docs/cli/custom-commands.md b/docs/cli/custom-commands.md index 260874bea3..714b6dc2a6 100644 --- a/docs/cli/custom-commands.md +++ b/docs/cli/custom-commands.md @@ -1,48 +1,69 @@ # Custom Commands -Custom commands let you save and reuse your favorite or most frequently used prompts as personal shortcuts within Gemini CLI. You can create commands that are specific to a single project or commands that are available globally across all your projects, streamlining your workflow and ensuring consistency. +Custom commands let you save and reuse your favorite or most frequently used +prompts as personal shortcuts within Gemini CLI. You can create commands that +are specific to a single project or commands that are available globally across +all your projects, streamlining your workflow and ensuring consistency. ## File locations and precedence Gemini CLI discovers commands from two locations, loaded in a specific order: -1. **User Commands (Global):** Located in `~/.gemini/commands/`. These commands are available in any project you are working on. -2. **Project Commands (Local):** Located in `/.gemini/commands/`. These commands are specific to the current project and can be checked into version control to be shared with your team. +1. **User Commands (Global):** Located in `~/.gemini/commands/`. These commands + are available in any project you are working on. +2. **Project Commands (Local):** Located in + `/.gemini/commands/`. These commands are specific to the + current project and can be checked into version control to be shared with + your team. -If a command in the project directory has the same name as a command in the user directory, the **project command will always be used.** This allows projects to override global commands with project-specific versions. +If a command in the project directory has the same name as a command in the user +directory, the **project command will always be used.** This allows projects to +override global commands with project-specific versions. ## Naming and namespacing -The name of a command is determined by its file path relative to its `commands` directory. Subdirectories are used to create namespaced commands, with the path separator (`/` or `\`) being converted to a colon (`:`). +The name of a command is determined by its file path relative to its `commands` +directory. Subdirectories are used to create namespaced commands, with the path +separator (`/` or `\`) being converted to a colon (`:`). - A file at `~/.gemini/commands/test.toml` becomes the command `/test`. -- A file at `/.gemini/commands/git/commit.toml` becomes the namespaced command `/git:commit`. +- A file at `/.gemini/commands/git/commit.toml` becomes the namespaced + command `/git:commit`. ## TOML File Format (v1) -Your command definition files must be written in the TOML format and use the `.toml` file extension. +Your command definition files must be written in the TOML format and use the +`.toml` file extension. ### Required fields -- `prompt` (String): The prompt that will be sent to the Gemini model when the command is executed. This can be a single-line or multi-line string. +- `prompt` (String): The prompt that will be sent to the Gemini model when the + command is executed. This can be a single-line or multi-line string. ### Optional fields -- `description` (String): A brief, one-line description of what the command does. This text will be displayed next to your command in the `/help` menu. **If you omit this field, a generic description will be generated from the filename.** +- `description` (String): A brief, one-line description of what the command + does. This text will be displayed next to your command in the `/help` menu. + **If you omit this field, a generic description will be generated from the + filename.** ## Handling arguments -Custom commands support two powerful methods for handling arguments. The CLI automatically chooses the correct method based on the content of your command\'s `prompt`. +Custom commands support two powerful methods for handling arguments. The CLI +automatically chooses the correct method based on the content of your command\'s +`prompt`. ### 1. Context-aware injection with `{{args}}` -If your `prompt` contains the special placeholder `{{args}}`, the CLI will replace that placeholder with the text the user typed after the command name. +If your `prompt` contains the special placeholder `{{args}}`, the CLI will +replace that placeholder with the text the user typed after the command name. The behavior of this injection depends on where it is used: **A. Raw injection (outside Shell commands)** -When used in the main body of the prompt, the arguments are injected exactly as the user typed them. +When used in the main body of the prompt, the arguments are injected exactly as +the user typed them. **Example (`git/fix.toml`):** @@ -53,11 +74,16 @@ description = "Generates a fix for a given issue." prompt = "Please provide a code fix for the issue described here: {{args}}." ``` -The model receives: `Please provide a code fix for the issue described here: "Button is misaligned".` +The model receives: +`Please provide a code fix for the issue described here: "Button is misaligned".` **B. Using arguments in Shell commands (inside `!{...}` blocks)** -When you use `{{args}}` inside a shell injection block (`!{...}`), the arguments are automatically **shell-escaped** before replacement. This allows you to safely pass arguments to shell commands, ensuring the resulting command is syntactically correct and secure while preventing command injection vulnerabilities. +When you use `{{args}}` inside a shell injection block (`!{...}`), the arguments +are automatically **shell-escaped** before replacement. This allows you to +safely pass arguments to shell commands, ensuring the resulting command is +syntactically correct and secure while preventing command injection +vulnerabilities. **Example (`/grep-code.toml`):** @@ -74,22 +100,30 @@ When you run `/grep-code It\'s complicated`: 1. The CLI sees `{{args}}` used both outside and inside `!{...}`. 2. Outside: The first `{{args}}` is replaced raw with `It\'s complicated`. -3. Inside: The second `{{args}}` is replaced with the escaped version (e.g., on Linux: `"It\'s complicated"`). +3. Inside: The second `{{args}}` is replaced with the escaped version (e.g., on + Linux: `"It\'s complicated"`). 4. The command executed is `grep -r "It\'s complicated" .`. 5. The CLI prompts you to confirm this exact, secure command before execution. 6. The final prompt is sent. ### 2. Default argument handling -If your `prompt` does **not** contain the special placeholder `{{args}}`, the CLI uses a default behavior for handling arguments. +If your `prompt` does **not** contain the special placeholder `{{args}}`, the +CLI uses a default behavior for handling arguments. -If you provide arguments to the command (e.g., `/mycommand arg1`), the CLI will append the full command you typed to the end of the prompt, separated by two newlines. This allows the model to see both the original instructions and the specific arguments you just provided. +If you provide arguments to the command (e.g., `/mycommand arg1`), the CLI will +append the full command you typed to the end of the prompt, separated by two +newlines. This allows the model to see both the original instructions and the +specific arguments you just provided. -If you do **not** provide any arguments (e.g., `/mycommand`), the prompt is sent to the model exactly as it is, with nothing appended. +If you do **not** provide any arguments (e.g., `/mycommand`), the prompt is sent +to the model exactly as it is, with nothing appended. **Example (`changelog.toml`):** -This example shows how to create a robust command by defining a role for the model, explaining where to find the user's input, and specifying the expected format and behavior. +This example shows how to create a robust command by defining a role for the +model, explaining where to find the user's input, and specifying the expected +format and behavior. ```toml # In: /.gemini/commands/changelog.toml @@ -118,25 +152,45 @@ The command follows this format: `/changelog ` """ ``` -When you run `/changelog 1.2.0 added "New feature"`, the final text sent to the model will be the original prompt followed by two newlines and the command you typed. +When you run `/changelog 1.2.0 added "New feature"`, the final text sent to the +model will be the original prompt followed by two newlines and the command you +typed. ### 3. Executing Shell commands with `!{...}` -You can make your commands dynamic by executing shell commands directly within your `prompt` and injecting their output. This is ideal for gathering context from your local environment, like reading file content or checking the status of Git. +You can make your commands dynamic by executing shell commands directly within +your `prompt` and injecting their output. This is ideal for gathering context +from your local environment, like reading file content or checking the status of +Git. -When a custom command attempts to execute a shell command, Gemini CLI will now prompt you for confirmation before proceeding. This is a security measure to ensure that only intended commands can be run. +When a custom command attempts to execute a shell command, Gemini CLI will now +prompt you for confirmation before proceeding. This is a security measure to +ensure that only intended commands can be run. **How it works:** 1. **Inject commands:** Use the `!{...}` syntax. -2. **Argument substitution:** If `{{args}}` is present inside the block, it is automatically shell-escaped (see [Context-Aware Injection](#1-context-aware-injection-with-args) above). -3. **Robust parsing:** The parser correctly handles complex shell commands that include nested braces, such as JSON payloads. **Note:** The content inside `!{...}` must have balanced braces (`{` and `}`). If you need to execute a command containing unbalanced braces, consider wrapping it in an external script file and calling the script within the `!{...}` block. -4. **Security check and confirmation:** The CLI performs a security check on the final, resolved command (after arguments are escaped and substituted). A dialog will appear showing the exact command(s) to be executed. -5. **Execution and error reporting:** The command is executed. If the command fails, the output injected into the prompt will include the error messages (stderr) followed by a status line, e.g., `[Shell command exited with code 1]`. This helps the model understand the context of the failure. +2. **Argument substitution:** If `{{args}}` is present inside the block, it is + automatically shell-escaped (see + [Context-Aware Injection](#1-context-aware-injection-with-args) above). +3. **Robust parsing:** The parser correctly handles complex shell commands that + include nested braces, such as JSON payloads. **Note:** The content inside + `!{...}` must have balanced braces (`{` and `}`). If you need to execute a + command containing unbalanced braces, consider wrapping it in an external + script file and calling the script within the `!{...}` block. +4. **Security check and confirmation:** The CLI performs a security check on + the final, resolved command (after arguments are escaped and substituted). A + dialog will appear showing the exact command(s) to be executed. +5. **Execution and error reporting:** The command is executed. If the command + fails, the output injected into the prompt will include the error messages + (stderr) followed by a status line, e.g., + `[Shell command exited with code 1]`. This helps the model understand the + context of the failure. **Example (`git/commit.toml`):** -This command gets the staged git diff and uses it to ask the model to write a commit message. +This command gets the staged git diff and uses it to ask the model to write a +commit message. ````toml # In: /.gemini/commands/git/commit.toml @@ -156,24 +210,39 @@ Please generate a Conventional Commit message based on the following git diff: ```` -When you run `/git:commit`, the CLI first executes `git diff --staged`, then replaces `!{git diff --staged}` with the output of that command before sending the final, complete prompt to the model. +When you run `/git:commit`, the CLI first executes `git diff --staged`, then +replaces `!{git diff --staged}` with the output of that command before sending +the final, complete prompt to the model. ### 4. Injecting file content with `@{...}` -You can directly embed the content of a file or a directory listing into your prompt using the `@{...}` syntax. This is useful for creating commands that operate on specific files. +You can directly embed the content of a file or a directory listing into your +prompt using the `@{...}` syntax. This is useful for creating commands that +operate on specific files. **How it works:** -- **File injection**: `@{path/to/file.txt}` is replaced by the content of `file.txt`. -- **Multimodal support**: If the path points to a supported image (e.g., PNG, JPEG), PDF, audio, or video file, it will be correctly encoded and injected as multimodal input. Other binary files are handled gracefully and skipped. -- **Directory listing**: `@{path/to/dir}` is traversed and each file present within the directory and all subdirectories is inserted into the prompt. This respects `.gitignore` and `.geminiignore` if enabled. -- **Workspace-aware**: The command searches for the path in the current directory and any other workspace directories. Absolute paths are allowed if they are within the workspace. -- **Processing order**: File content injection with `@{...}` is processed _before_ shell commands (`!{...}`) and argument substitution (`{{args}}`). -- **Parsing**: The parser requires the content inside `@{...}` (the path) to have balanced braces (`{` and `}`). +- **File injection**: `@{path/to/file.txt}` is replaced by the content of + `file.txt`. +- **Multimodal support**: If the path points to a supported image (e.g., PNG, + JPEG), PDF, audio, or video file, it will be correctly encoded and injected as + multimodal input. Other binary files are handled gracefully and skipped. +- **Directory listing**: `@{path/to/dir}` is traversed and each file present + within the directory and all subdirectories is inserted into the prompt. This + respects `.gitignore` and `.geminiignore` if enabled. +- **Workspace-aware**: The command searches for the path in the current + directory and any other workspace directories. Absolute paths are allowed if + they are within the workspace. +- **Processing order**: File content injection with `@{...}` is processed + _before_ shell commands (`!{...}`) and argument substitution (`{{args}}`). +- **Parsing**: The parser requires the content inside `@{...}` (the path) to + have balanced braces (`{` and `}`). **Example (`review.toml`):** -This command injects the content of a _fixed_ best practices file (`docs/best-practices.md`) and uses the user\'s arguments to provide context for the review. +This command injects the content of a _fixed_ best practices file +(`docs/best-practices.md`) and uses the user\'s arguments to provide context for +the review. ```toml # In: /.gemini/commands/review.toml @@ -191,7 +260,9 @@ Use the following best practices when providing your review: """ ``` -When you run `/review FileCommandLoader.ts`, the `@{docs/best-practices.md}` placeholder is replaced by the content of that file, and `{{args}}` is replaced by the text you provided, before the final prompt is sent to the model. +When you run `/review FileCommandLoader.ts`, the `@{docs/best-practices.md}` +placeholder is replaced by the content of that file, and `{{args}}` is replaced +by the text you provided, before the final prompt is sent to the model. --- @@ -201,7 +272,8 @@ Let's create a global command that asks the model to refactor a piece of code. **1. Create the file and directories:** -First, ensure the user commands directory exists, then create a `refactor` subdirectory for organization and the final TOML file. +First, ensure the user commands directory exists, then create a `refactor` +subdirectory for organization and the final TOML file. ```bash mkdir -p ~/.gemini/commands/refactor @@ -210,7 +282,9 @@ touch ~/.gemini/commands/refactor/pure.toml **2. Add the content to the file:** -Open `~/.gemini/commands/refactor/pure.toml` in your editor and add the following content. We are including the optional `description` for best practice. +Open `~/.gemini/commands/refactor/pure.toml` in your editor and add the +following content. We are including the optional `description` for best +practice. ```toml # In: ~/.gemini/commands/refactor/pure.toml @@ -230,7 +304,8 @@ Your response should include: **3. Run the Command:** -That's it! You can now run your command in the CLI. First, you might add a file to the context, and then invoke your command: +That's it! You can now run your command in the CLI. First, you might add a file +to the context, and then invoke your command: ``` > @my-messy-function.js diff --git a/docs/cli/enterprise.md b/docs/cli/enterprise.md index 2322d3f440..0274e48f00 100644 --- a/docs/cli/enterprise.md +++ b/docs/cli/enterprise.md @@ -1,21 +1,37 @@ # Gemini CLI for the Enterprise -This document outlines configuration patterns and best practices for deploying and managing Gemini CLI in an enterprise environment. By leveraging system-level settings, administrators can enforce security policies, manage tool access, and ensure a consistent experience for all users. +This document outlines configuration patterns and best practices for deploying +and managing Gemini CLI in an enterprise environment. By leveraging system-level +settings, administrators can enforce security policies, manage tool access, and +ensure a consistent experience for all users. -> **A Note on Security:** The patterns described in this document are intended to help administrators create a more controlled and secure environment for using Gemini CLI. However, they should not be considered a foolproof security boundary. A determined user with sufficient privileges on their local machine may still be able to circumvent these configurations. These measures are designed to prevent accidental misuse and enforce corporate policy in a managed environment, not to defend against a malicious actor with local administrative rights. +> **A Note on Security:** The patterns described in this document are intended +> to help administrators create a more controlled and secure environment for +> using Gemini CLI. However, they should not be considered a foolproof security +> boundary. A determined user with sufficient privileges on their local machine +> may still be able to circumvent these configurations. These measures are +> designed to prevent accidental misuse and enforce corporate policy in a +> managed environment, not to defend against a malicious actor with local +> administrative rights. ## Centralized Configuration: The System Settings File -The most powerful tools for enterprise administration are the system-wide settings files. These files allow you to define a baseline configuration (`system-defaults.json`) and a set of overrides (`settings.json`) that apply to all users on a machine. For a complete overview of configuration options, see the [Configuration documentation](../get-started/configuration.md). +The most powerful tools for enterprise administration are the system-wide +settings files. These files allow you to define a baseline configuration +(`system-defaults.json`) and a set of overrides (`settings.json`) that apply to +all users on a machine. For a complete overview of configuration options, see +the [Configuration documentation](../get-started/configuration.md). -Settings are merged from four files. The precedence order for single-value settings (like `theme`) is: +Settings are merged from four files. The precedence order for single-value +settings (like `theme`) is: 1. System Defaults (`system-defaults.json`) 2. User Settings (`~/.gemini/settings.json`) 3. Workspace Settings (`/.gemini/settings.json`) 4. System Overrides (`settings.json`) -This means the System Overrides file has the final say. For settings that are arrays (`includeDirectories`) or objects (`mcpServers`), the values are merged. +This means the System Overrides file has the final say. For settings that are +arrays (`includeDirectories`) or objects (`mcpServers`), the values are merged. **Example of Merging and Precedence:** @@ -122,26 +138,39 @@ This results in the following merged configuration: **Why:** -- **`theme`**: The value from the system overrides (`system-enforced-theme`) is used, as it has the highest precedence. -- **`mcpServers`**: The objects are merged. The `corp-server` definition from the system overrides takes precedence over the user's definition. The unique `user-tool` and `project-tool` are included. -- **`includeDirectories`**: The arrays are concatenated in the order of System Defaults, User, Workspace, and then System Overrides. +- **`theme`**: The value from the system overrides (`system-enforced-theme`) is + used, as it has the highest precedence. +- **`mcpServers`**: The objects are merged. The `corp-server` definition from + the system overrides takes precedence over the user's definition. The unique + `user-tool` and `project-tool` are included. +- **`includeDirectories`**: The arrays are concatenated in the order of System + Defaults, User, Workspace, and then System Overrides. - **Location**: - **Linux**: `/etc/gemini-cli/settings.json` - **Windows**: `C:\ProgramData\gemini-cli\settings.json` - **macOS**: `/Library/Application Support/GeminiCli/settings.json` - - The path can be overridden using the `GEMINI_CLI_SYSTEM_SETTINGS_PATH` environment variable. -- **Control**: This file should be managed by system administrators and protected with appropriate file permissions to prevent unauthorized modification by users. + - The path can be overridden using the `GEMINI_CLI_SYSTEM_SETTINGS_PATH` + environment variable. +- **Control**: This file should be managed by system administrators and + protected with appropriate file permissions to prevent unauthorized + modification by users. -By using the system settings file, you can enforce the security and configuration patterns described below. +By using the system settings file, you can enforce the security and +configuration patterns described below. ## Restricting Tool Access -You can significantly enhance security by controlling which tools the Gemini model can use. This is achieved through the `tools.core` and `tools.exclude` settings. For a list of available tools, see the [Tools documentation](../tools/index.md). +You can significantly enhance security by controlling which tools the Gemini +model can use. This is achieved through the `tools.core` and `tools.exclude` +settings. For a list of available tools, see the +[Tools documentation](../tools/index.md). ### Allowlisting with `coreTools` -The most secure approach is to explicitly add the tools and commands that users are permitted to execute to an allowlist. This prevents the use of any tool not on the approved list. +The most secure approach is to explicitly add the tools and commands that users +are permitted to execute to an allowlist. This prevents the use of any tool not +on the approved list. **Example:** Allow only safe, read-only file operations and listing files. @@ -155,7 +184,8 @@ The most secure approach is to explicitly add the tools and commands that users ### Blocklisting with `excludeTools` -Alternatively, you can add specific tools that are considered dangerous in your environment to a blocklist. +Alternatively, you can add specific tools that are considered dangerous in your +environment to a blocklist. **Example:** Prevent the use of the shell tool for removing files. @@ -167,32 +197,54 @@ Alternatively, you can add specific tools that are considered dangerous in your } ``` -**Security Note:** Blocklisting with `excludeTools` is less secure than allowlisting with `coreTools`, as it relies on blocking known-bad commands, and clever users may find ways to bypass simple string-based blocks. **Allowlisting is the recommended approach.** +**Security Note:** Blocklisting with `excludeTools` is less secure than +allowlisting with `coreTools`, as it relies on blocking known-bad commands, and +clever users may find ways to bypass simple string-based blocks. **Allowlisting +is the recommended approach.** ## Managing Custom Tools (MCP Servers) -If your organization uses custom tools via [Model-Context Protocol (MCP) servers](../core/tools-api.md), it is crucial to understand how server configurations are managed to apply security policies effectively. +If your organization uses custom tools via +[Model-Context Protocol (MCP) servers](../core/tools-api.md), it is crucial to +understand how server configurations are managed to apply security policies +effectively. ### How MCP Server Configurations are Merged -Gemini CLI loads `settings.json` files from three levels: System, Workspace, and User. When it comes to the `mcpServers` object, these configurations are **merged**: +Gemini CLI loads `settings.json` files from three levels: System, Workspace, and +User. When it comes to the `mcpServers` object, these configurations are +**merged**: -1. **Merging:** The lists of servers from all three levels are combined into a single list. -2. **Precedence:** If a server with the **same name** is defined at multiple levels (e.g., a server named `corp-api` exists in both system and user settings), the definition from the highest-precedence level is used. The order of precedence is: **System > Workspace > User**. +1. **Merging:** The lists of servers from all three levels are combined into a + single list. +2. **Precedence:** If a server with the **same name** is defined at multiple + levels (e.g., a server named `corp-api` exists in both system and user + settings), the definition from the highest-precedence level is used. The + order of precedence is: **System > Workspace > User**. -This means a user **cannot** override the definition of a server that is already defined in the system-level settings. However, they **can** add new servers with unique names. +This means a user **cannot** override the definition of a server that is already +defined in the system-level settings. However, they **can** add new servers with +unique names. ### Enforcing a Catalog of Tools -The security of your MCP tool ecosystem depends on a combination of defining the canonical servers and adding their names to an allowlist. +The security of your MCP tool ecosystem depends on a combination of defining the +canonical servers and adding their names to an allowlist. ### Restricting Tools Within an MCP Server -For even greater security, especially when dealing with third-party MCP servers, you can restrict which specific tools from a server are exposed to the model. This is done using the `includeTools` and `excludeTools` properties within a server's definition. This allows you to use a subset of tools from a server without allowing potentially dangerous ones. +For even greater security, especially when dealing with third-party MCP servers, +you can restrict which specific tools from a server are exposed to the model. +This is done using the `includeTools` and `excludeTools` properties within a +server's definition. This allows you to use a subset of tools from a server +without allowing potentially dangerous ones. -Following the principle of least privilege, it is highly recommended to use `includeTools` to create an allowlist of only the necessary tools. +Following the principle of least privilege, it is highly recommended to use +`includeTools` to create an allowlist of only the necessary tools. -**Example:** Only allow the `code-search` and `get-ticket-details` tools from a third-party MCP server, even if the server offers other tools like `delete-ticket`. +**Example:** Only allow the `code-search` and `get-ticket-details` tools from a +third-party MCP server, even if the server offers other tools like +`delete-ticket`. ```json { @@ -210,15 +262,21 @@ Following the principle of least privilege, it is highly recommended to use `inc #### More Secure Pattern: Define and Add to Allowlist in System Settings -To create a secure, centrally-managed catalog of tools, the system administrator **must** do both of the following in the system-level `settings.json` file: +To create a secure, centrally-managed catalog of tools, the system administrator +**must** do both of the following in the system-level `settings.json` file: -1. **Define the full configuration** for every approved server in the `mcpServers` object. This ensures that even if a user defines a server with the same name, the secure system-level definition will take precedence. -2. **Add the names** of those servers to an allowlist using the `mcp.allowed` setting. This is a critical security step that prevents users from running any servers that are not on this list. If this setting is omitted, the CLI will merge and allow any server defined by the user. +1. **Define the full configuration** for every approved server in the + `mcpServers` object. This ensures that even if a user defines a server with + the same name, the secure system-level definition will take precedence. +2. **Add the names** of those servers to an allowlist using the `mcp.allowed` + setting. This is a critical security step that prevents users from running + any servers that are not on this list. If this setting is omitted, the CLI + will merge and allow any server defined by the user. **Example System `settings.json`:** -1. Add the _names_ of all approved servers to an allowlist. - This will prevent users from adding their own servers. +1. Add the _names_ of all approved servers to an allowlist. This will prevent + users from adding their own servers. 2. Provide the canonical _definition_ for each server on the allowlist. @@ -239,16 +297,20 @@ To create a secure, centrally-managed catalog of tools, the system administrator } ``` -This pattern is more secure because it uses both definition and an allowlist. Any server a user defines will either be overridden by the system definition (if it has the same name) or blocked because its name is not in the `mcp.allowed` list. +This pattern is more secure because it uses both definition and an allowlist. +Any server a user defines will either be overridden by the system definition (if +it has the same name) or blocked because its name is not in the `mcp.allowed` +list. ### Less Secure Pattern: Omitting the Allowlist -If the administrator defines the `mcpServers` object but fails to also specify the `mcp.allowed` allowlist, users may add their own servers. +If the administrator defines the `mcpServers` object but fails to also specify +the `mcp.allowed` allowlist, users may add their own servers. **Example System `settings.json`:** -This configuration defines servers but does not enforce the allowlist. -The administrator has NOT included the "mcp.allowed" setting. +This configuration defines servers but does not enforce the allowlist. The +administrator has NOT included the "mcp.allowed" setting. ```json { @@ -260,11 +322,16 @@ The administrator has NOT included the "mcp.allowed" setting. } ``` -In this scenario, a user can add their own server in their local `settings.json`. Because there is no `mcp.allowed` list to filter the merged results, the user's server will be added to the list of available tools and allowed to run. +In this scenario, a user can add their own server in their local +`settings.json`. Because there is no `mcp.allowed` list to filter the merged +results, the user's server will be added to the list of available tools and +allowed to run. ## Enforcing Sandboxing for Security -To mitigate the risk of potentially harmful operations, you can enforce the use of sandboxing for all tool execution. The sandbox isolates tool execution in a containerized environment. +To mitigate the risk of potentially harmful operations, you can enforce the use +of sandboxing for all tool execution. The sandbox isolates tool execution in a +containerized environment. **Example:** Force all tool execution to happen within a Docker sandbox. @@ -276,11 +343,17 @@ To mitigate the risk of potentially harmful operations, you can enforce the use } ``` -You can also specify a custom, hardened Docker image for the sandbox using the `--sandbox-image` command-line argument or by building a custom `sandbox.Dockerfile` as described in the [Sandboxing documentation](./sandbox.md). +You can also specify a custom, hardened Docker image for the sandbox using the +`--sandbox-image` command-line argument or by building a custom +`sandbox.Dockerfile` as described in the +[Sandboxing documentation](./sandbox.md). ## Controlling Network Access via Proxy -In corporate environments with strict network policies, you can configure Gemini CLI to route all outbound traffic through a corporate proxy. This can be set via an environment variable, but it can also be enforced for custom tools via the `mcpServers` configuration. +In corporate environments with strict network policies, you can configure Gemini +CLI to route all outbound traffic through a corporate proxy. This can be set via +an environment variable, but it can also be enforced for custom tools via the +`mcpServers` configuration. **Example (for an MCP Server):** @@ -301,9 +374,13 @@ In corporate environments with strict network policies, you can configure Gemini ## Telemetry and Auditing -For auditing and monitoring purposes, you can configure Gemini CLI to send telemetry data to a central location. This allows you to track tool usage and other events. For more information, see the [telemetry documentation](./telemetry.md). +For auditing and monitoring purposes, you can configure Gemini CLI to send +telemetry data to a central location. This allows you to track tool usage and +other events. For more information, see the +[telemetry documentation](./telemetry.md). -**Example:** Enable telemetry and send it to a local OTLP collector. If `otlpEndpoint` is not specified, it defaults to `http://localhost:4317`. +**Example:** Enable telemetry and send it to a local OTLP collector. If +`otlpEndpoint` is not specified, it defaults to `http://localhost:4317`. ```json { @@ -315,11 +392,15 @@ For auditing and monitoring purposes, you can configure Gemini CLI to send telem } ``` -**Note:** Ensure that `logPrompts` is set to `false` in an enterprise setting to avoid collecting potentially sensitive information from user prompts. +**Note:** Ensure that `logPrompts` is set to `false` in an enterprise setting to +avoid collecting potentially sensitive information from user prompts. ## Authentication -You can enforce a specific authentication method for all users by setting the `enforcedAuthType` in the system-level `settings.json` file. This prevents users from choosing a different authentication method. See the [Authentication docs](./authentication.md) for more details. +You can enforce a specific authentication method for all users by setting the +`enforcedAuthType` in the system-level `settings.json` file. This prevents users +from choosing a different authentication method. See the +[Authentication docs](./authentication.md) for more details. **Example:** Enforce the use of Google login for all users. @@ -329,11 +410,16 @@ You can enforce a specific authentication method for all users by setting the `e } ``` -If a user has a different authentication method configured, they will be prompted to switch to the enforced method. In non-interactive mode, the CLI will exit with an error if the configured authentication method does not match the enforced one. +If a user has a different authentication method configured, they will be +prompted to switch to the enforced method. In non-interactive mode, the CLI will +exit with an error if the configured authentication method does not match the +enforced one. ## Putting It All Together: Example System `settings.json` -Here is an example of a system `settings.json` file that combines several of the patterns discussed above to create a secure, controlled environment for Gemini CLI. +Here is an example of a system `settings.json` file that combines several of the +patterns discussed above to create a secure, controlled environment for Gemini +CLI. ```json { @@ -376,7 +462,8 @@ Here is an example of a system `settings.json` file that combines several of the This configuration: - Forces all tool execution into a Docker sandbox. -- Strictly uses an allowlist for a small set of safe shell commands and file tools. +- Strictly uses an allowlist for a small set of safe shell commands and file + tools. - Defines and allows a single corporate MCP server for custom tools. - Enables telemetry for auditing, without logging prompt content. - Redirects the `/bug` command to an internal ticketing system. diff --git a/docs/cli/gemini-ignore.md b/docs/cli/gemini-ignore.md index 58b81cbaad..b23f06b65a 100644 --- a/docs/cli/gemini-ignore.md +++ b/docs/cli/gemini-ignore.md @@ -1,22 +1,33 @@ # Ignoring Files -This document provides an overview of the Gemini Ignore (`.geminiignore`) feature of the Gemini CLI. +This document provides an overview of the Gemini Ignore (`.geminiignore`) +feature of the Gemini CLI. -The Gemini CLI includes the ability to automatically ignore files, similar to `.gitignore` (used by Git) and `.aiexclude` (used by Gemini Code Assist). Adding paths to your `.geminiignore` file will exclude them from tools that support this feature, although they will still be visible to other services (such as Git). +The Gemini CLI includes the ability to automatically ignore files, similar to +`.gitignore` (used by Git) and `.aiexclude` (used by Gemini Code Assist). Adding +paths to your `.geminiignore` file will exclude them from tools that support +this feature, although they will still be visible to other services (such as +Git). ## How it works -When you add a path to your `.geminiignore` file, tools that respect this file will exclude matching files and directories from their operations. For example, when you use the [`read_many_files`](../tools/multi-file.md) command, any paths in your `.geminiignore` file will be automatically excluded. +When you add a path to your `.geminiignore` file, tools that respect this file +will exclude matching files and directories from their operations. For example, +when you use the [`read_many_files`](../tools/multi-file.md) command, any paths +in your `.geminiignore` file will be automatically excluded. -For the most part, `.geminiignore` follows the conventions of `.gitignore` files: +For the most part, `.geminiignore` follows the conventions of `.gitignore` +files: - Blank lines and lines starting with `#` are ignored. - Standard glob patterns are supported (such as `*`, `?`, and `[]`). - Putting a `/` at the end will only match directories. -- Putting a `/` at the beginning anchors the path relative to the `.geminiignore` file. +- Putting a `/` at the beginning anchors the path relative to the + `.geminiignore` file. - `!` negates a pattern. -You can update your `.geminiignore` file at any time. To apply the changes, you must restart your Gemini CLI session. +You can update your `.geminiignore` file at any time. To apply the changes, you +must restart your Gemini CLI session. ## How to use `.geminiignore` @@ -27,7 +38,8 @@ To enable `.geminiignore`: To add a file or directory to `.geminiignore`: 1. Open your `.geminiignore` file. -2. Add the path or file you want to ignore, for example: `/archive/` or `apikeys.txt`. +2. Add the path or file you want to ignore, for example: `/archive/` or + `apikeys.txt`. ### `.geminiignore` examples diff --git a/docs/cli/gemini-md.md b/docs/cli/gemini-md.md index 1f1fb270bc..ec1907dced 100644 --- a/docs/cli/gemini-md.md +++ b/docs/cli/gemini-md.md @@ -1,30 +1,44 @@ # Provide Context with GEMINI.md Files -Context files, which use the default name `GEMINI.md`, are a powerful feature for providing instructional context to the Gemini model. You can use these files to give project-specific instructions, define a persona, or provide coding style guides to make the AI's responses more accurate and tailored to your needs. +Context files, which use the default name `GEMINI.md`, are a powerful feature +for providing instructional context to the Gemini model. You can use these files +to give project-specific instructions, define a persona, or provide coding style +guides to make the AI's responses more accurate and tailored to your needs. -Instead of repeating instructions in every prompt, you can define them once in a context file. +Instead of repeating instructions in every prompt, you can define them once in a +context file. ## Understand the context hierarchy -The CLI uses a hierarchical system to source context. It loads various context files from several locations, concatenates the contents of all found files, and sends them to the model with every prompt. The CLI loads files in the following order: +The CLI uses a hierarchical system to source context. It loads various context +files from several locations, concatenates the contents of all found files, and +sends them to the model with every prompt. The CLI loads files in the following +order: 1. **Global context file:** - **Location:** `~/.gemini/GEMINI.md` (in your user home directory). - **Scope:** Provides default instructions for all your projects. 2. **Project root and ancestor context files:** - - **Location:** The CLI searches for a `GEMINI.md` file in your current working directory and then in each parent directory up to the project root (identified by a `.git` folder). + - **Location:** The CLI searches for a `GEMINI.md` file in your current + working directory and then in each parent directory up to the project root + (identified by a `.git` folder). - **Scope:** Provides context relevant to the entire project. 3. **Sub-directory context files:** - - **Location:** The CLI also scans for `GEMINI.md` files in subdirectories below your current working directory. It respects rules in `.gitignore` and `.geminiignore`. - - **Scope:** Lets you write highly specific instructions for a particular component or module. + - **Location:** The CLI also scans for `GEMINI.md` files in subdirectories + below your current working directory. It respects rules in `.gitignore` + and `.geminiignore`. + - **Scope:** Lets you write highly specific instructions for a particular + component or module. -The CLI footer displays the number of loaded context files, which gives you a quick visual cue of the active instructional context. +The CLI footer displays the number of loaded context files, which gives you a +quick visual cue of the active instructional context. ### Example `GEMINI.md` file -Here is an example of what you can include in a `GEMINI.md` file at the root of a TypeScript project: +Here is an example of what you can include in a `GEMINI.md` file at the root of +a TypeScript project: ```markdown # Project: My TypeScript Library @@ -46,13 +60,19 @@ Here is an example of what you can include in a `GEMINI.md` file at the root of You can interact with the loaded context files by using the `/memory` command. -- **`/memory show`**: Displays the full, concatenated content of the current hierarchical memory. This lets you inspect the exact instructional context being provided to the model. -- **`/memory refresh`**: Forces a re-scan and reload of all `GEMINI.md` files from all configured locations. -- **`/memory add `**: Appends your text to your global `~/.gemini/GEMINI.md` file. This lets you add persistent memories on the fly. +- **`/memory show`**: Displays the full, concatenated content of the current + hierarchical memory. This lets you inspect the exact instructional context + being provided to the model. +- **`/memory refresh`**: Forces a re-scan and reload of all `GEMINI.md` files + from all configured locations. +- **`/memory add `**: Appends your text to your global + `~/.gemini/GEMINI.md` file. This lets you add persistent memories on the fly. ## Modularize context with imports -You can break down large `GEMINI.md` files into smaller, more manageable components by importing content from other files using the `@file.md` syntax. This feature supports both relative and absolute paths. +You can break down large `GEMINI.md` files into smaller, more manageable +components by importing content from other files using the `@file.md` syntax. +This feature supports both relative and absolute paths. **Example `GEMINI.md` with imports:** @@ -68,11 +88,14 @@ More content here. @../shared/style-guide.md ``` -For more details, see the [Memory Import Processor](../core/memport.md) documentation. +For more details, see the [Memory Import Processor](../core/memport.md) +documentation. ## Customize the context file name -While `GEMINI.md` is the default filename, you can configure this in your `settings.json` file. To specify a different name or a list of names, use the `context.fileName` property. +While `GEMINI.md` is the default filename, you can configure this in your +`settings.json` file. To specify a different name or a list of names, use the +`context.fileName` property. **Example `settings.json`:** diff --git a/docs/cli/headless.md b/docs/cli/headless.md index 45e53a2d13..31e05c34dd 100644 --- a/docs/cli/headless.md +++ b/docs/cli/headless.md @@ -244,7 +244,9 @@ Key command-line options for headless usage: | `--yolo`, `-y` | Auto-approve all actions | `gemini -p "query" --yolo` | | `--approval-mode` | Set approval mode | `gemini -p "query" --approval-mode auto_edit` | -For complete details on all available configuration options, settings files, and environment variables, see the [Configuration Guide](../get-started/configuration.md). +For complete details on all available configuration options, settings files, and +environment variables, see the +[Configuration Guide](../get-started/configuration.md). ## Examples @@ -317,7 +319,8 @@ tail -5 usage.log ## Resources -- [CLI Configuration](../get-started/configuration.md) - Complete configuration guide +- [CLI Configuration](../get-started/configuration.md) - Complete configuration + guide - [Authentication](../get-started/authentication.md) - Setup authentication - [Commands](./commands.md) - Interactive commands reference - [Tutorials](./tutorials.md) - Step-by-step automation guides diff --git a/docs/cli/index.md b/docs/cli/index.md index 3ece7321cf..6344be4eb9 100644 --- a/docs/cli/index.md +++ b/docs/cli/index.md @@ -1,30 +1,46 @@ # Gemini CLI -Within Gemini CLI, `packages/cli` is the frontend for users to send and receive prompts with the Gemini AI model and its associated tools. For a general overview of Gemini CLI, see the [main documentation page](../index.md). +Within Gemini CLI, `packages/cli` is the frontend for users to send and receive +prompts with the Gemini AI model and its associated tools. For a general +overview of Gemini CLI, see the [main documentation page](../index.md). ## Basic features -- **[Commands](./commands.md):** A reference for all built-in slash commands (e.g., `/help`, `/chat`, `/tools`). -- **[Custom Commands](./custom-commands.md):** Create your own commands and shortcuts for frequently used prompts. -- **[Headless Mode](./headless.md):** Use Gemini CLI programmatically for scripting and automation. -- **[Themes](./themes.md):** Customizing the CLI's appearance with different themes. -- **[Keyboard Shortcuts](./keyboard-shortcuts.md):** A reference for all keyboard shortcuts to improve your workflow. +- **[Commands](./commands.md):** A reference for all built-in slash commands + (e.g., `/help`, `/chat`, `/tools`). +- **[Custom Commands](./custom-commands.md):** Create your own commands and + shortcuts for frequently used prompts. +- **[Headless Mode](./headless.md):** Use Gemini CLI programmatically for + scripting and automation. +- **[Themes](./themes.md):** Customizing the CLI's appearance with different + themes. +- **[Keyboard Shortcuts](./keyboard-shortcuts.md):** A reference for all + keyboard shortcuts to improve your workflow. - **[Tutorials](./tutorials.md):** Step-by-step guides for common tasks. ## Advanced features -- **[Checkpointing](./checkpointing.md):** Automatically save and restore snapshots of your session and files. -- **[Enterprise Configuration](./enterprise.md):** Deploying and manage Gemini CLI in an enterprise environment. -- **[Sandboxing](./sandbox.md):** Isolate tool execution in a secure, containerized environment. -- **[Telemetry](./telemetry.md):** Configure observability to monitor usage and performance. +- **[Checkpointing](./checkpointing.md):** Automatically save and restore + snapshots of your session and files. +- **[Enterprise Configuration](./enterprise.md):** Deploying and manage Gemini + CLI in an enterprise environment. +- **[Sandboxing](./sandbox.md):** Isolate tool execution in a secure, + containerized environment. +- **[Telemetry](./telemetry.md):** Configure observability to monitor usage and + performance. - **[Token Caching](./token-caching.md):** Optimize API costs by caching tokens. -- **[Trusted Folders](./trusted-folders.md):** A security feature to control which projects can use the full capabilities of the CLI. -- **[Ignoring Files (.geminiignore)](./gemini-ignore.md):** Exclude specific files and directories from being accessed by tools. -- **[Context Files (GEMINI.md)](./gemini-md.md):** Provide persistent, hierarchical context to the model. +- **[Trusted Folders](./trusted-folders.md):** A security feature to control + which projects can use the full capabilities of the CLI. +- **[Ignoring Files (.geminiignore)](./gemini-ignore.md):** Exclude specific + files and directories from being accessed by tools. +- **[Context Files (GEMINI.md)](./gemini-md.md):** Provide persistent, + hierarchical context to the model. ## Non-interactive mode -Gemini CLI can be run in a non-interactive mode, which is useful for scripting and automation. In this mode, you pipe input to the CLI, it executes the command, and then it exits. +Gemini CLI can be run in a non-interactive mode, which is useful for scripting +and automation. In this mode, you pipe input to the CLI, it executes the +command, and then it exits. The following example pipes a command to Gemini CLI from your terminal: @@ -38,4 +54,5 @@ You can also use the `--prompt` or `-p` flag: gemini -p "What is fine tuning?" ``` -For comprehensive documentation on headless usage, scripting, automation, and advanced examples, see the **[Headless Mode](./headless.md)** guide. +For comprehensive documentation on headless usage, scripting, automation, and +advanced examples, see the **[Headless Mode](./headless.md)** guide. diff --git a/docs/cli/sandbox.md b/docs/cli/sandbox.md index eb1d1bf149..9e87a08b37 100644 --- a/docs/cli/sandbox.md +++ b/docs/cli/sandbox.md @@ -1,6 +1,7 @@ # Sandboxing in the Gemini CLI -This document provides a guide to sandboxing in the Gemini CLI, including prerequisites, quickstart, and configuration. +This document provides a guide to sandboxing in the Gemini CLI, including +prerequisites, quickstart, and configuration. ## Prerequisites @@ -18,30 +19,36 @@ gemini --version ## Overview of sandboxing -Sandboxing isolates potentially dangerous operations (such as shell commands or file modifications) from your host system, providing a security barrier between AI operations and your environment. +Sandboxing isolates potentially dangerous operations (such as shell commands or +file modifications) from your host system, providing a security barrier between +AI operations and your environment. The benefits of sandboxing include: - **Security**: Prevent accidental system damage or data loss. - **Isolation**: Limit file system access to project directory. - **Consistency**: Ensure reproducible environments across different systems. -- **Safety**: Reduce risk when working with untrusted code or experimental commands. +- **Safety**: Reduce risk when working with untrusted code or experimental + commands. ## Sandboxing methods -Your ideal method of sandboxing may differ depending on your platform and your preferred container solution. +Your ideal method of sandboxing may differ depending on your platform and your +preferred container solution. ### 1. macOS Seatbelt (macOS only) Lightweight, built-in sandboxing using `sandbox-exec`. -**Default profile**: `permissive-open` - restricts writes outside project directory but allows most other operations. +**Default profile**: `permissive-open` - restricts writes outside project +directory but allows most other operations. ### 2. Container-based (Docker/Podman) Cross-platform sandboxing with complete process isolation. -**Note**: Requires building the sandbox image locally or using a published image from your organization's registry. +**Note**: Requires building the sandbox image locally or using a published image +from your organization's registry. ## Quickstart @@ -67,7 +74,8 @@ gemini -p "run the test suite" 1. **Command flag**: `-s` or `--sandbox` 2. **Environment variable**: `GEMINI_SANDBOX=true|docker|podman|sandbox-exec` -3. **Settings file**: `"sandbox": true` in the `tools` object of your `settings.json` file (e.g., `{"tools": {"sandbox": true}}`). +3. **Settings file**: `"sandbox": true` in the `tools` object of your + `settings.json` file (e.g., `{"tools": {"sandbox": true}}`). ### macOS Seatbelt profiles @@ -81,7 +89,10 @@ Built-in profiles (set via `SEATBELT_PROFILE` env var): ### Custom Sandbox Flags -For container-based sandboxing, you can inject custom flags into the `docker` or `podman` command using the `SANDBOX_FLAGS` environment variable. This is useful for advanced configurations, such as disabling security features for specific use cases. +For container-based sandboxing, you can inject custom flags into the `docker` or +`podman` command using the `SANDBOX_FLAGS` environment variable. This is useful +for advanced configurations, such as disabling security features for specific +use cases. **Example (Podman)**: @@ -99,7 +110,8 @@ export SANDBOX_FLAGS="--flag1 --flag2=value" ## Linux UID/GID handling -The sandbox automatically handles user permissions on Linux. Override these permissions with: +The sandbox automatically handles user permissions on Linux. Override these +permissions with: ```bash export SANDBOX_SET_UID_GID=true # Force host UID/GID @@ -131,7 +143,9 @@ export SANDBOX_SET_UID_GID=false # Disable UID/GID mapping DEBUG=1 gemini -s -p "debug command" ``` -**Note:** If you have `DEBUG=true` in a project's `.env` file, it won't affect gemini-cli due to automatic exclusion. Use `.gemini/.env` files for gemini-cli specific debug settings. +**Note:** If you have `DEBUG=true` in a project's `.env` file, it won't affect +gemini-cli due to automatic exclusion. Use `.gemini/.env` files for gemini-cli +specific debug settings. ### Inspect sandbox diff --git a/docs/cli/telemetry.md b/docs/cli/telemetry.md index ae0947a5f8..287dba2a7d 100644 --- a/docs/cli/telemetry.md +++ b/docs/cli/telemetry.md @@ -257,13 +257,15 @@ for Gemini CLI: - `mimetype` (string, if applicable) - `extension` (string, if applicable) - `programming_language` (string, if applicable) - - `diff_stat` (json string, if applicable): A JSON string with the following members: + - `diff_stat` (json string, if applicable): A JSON string with the following + members: - `ai_added_lines` (int) - `ai_removed_lines` (int) - `user_added_lines` (int) - `user_removed_lines` (int) -- `gemini_cli.api_request`: This event occurs when making a request to Gemini API. +- `gemini_cli.api_request`: This event occurs when making a request to Gemini + API. - **Attributes**: - `model` - `request_text` (if applicable) @@ -277,7 +279,8 @@ for Gemini CLI: - `duration_ms` - `auth_type` -- `gemini_cli.api_response`: This event occurs upon receiving a response from Gemini API. +- `gemini_cli.api_response`: This event occurs upon receiving a response from + Gemini API. - **Attributes**: - `model` - `status_code` @@ -291,7 +294,8 @@ for Gemini CLI: - `response_text` (if applicable) - `auth_type` -- `gemini_cli.tool_output_truncated`: This event occurs when the output of a tool call is too large and gets truncated. +- `gemini_cli.tool_output_truncated`: This event occurs when the output of a + tool call is too large and gets truncated. - **Attributes**: - `tool_name` (string) - `original_content_length` (int) @@ -300,27 +304,32 @@ for Gemini CLI: - `lines` (int) - `prompt_id` (string) -- `gemini_cli.malformed_json_response`: This event occurs when a `generateJson` response from Gemini API cannot be parsed as a json. +- `gemini_cli.malformed_json_response`: This event occurs when a `generateJson` + response from Gemini API cannot be parsed as a json. - **Attributes**: - `model` -- `gemini_cli.flash_fallback`: This event occurs when Gemini CLI switches to flash as fallback. +- `gemini_cli.flash_fallback`: This event occurs when Gemini CLI switches to + flash as fallback. - **Attributes**: - `auth_type` -- `gemini_cli.slash_command`: This event occurs when a user executes a slash command. +- `gemini_cli.slash_command`: This event occurs when a user executes a slash + command. - **Attributes**: - `command` (string) - `subcommand` (string, if applicable) - `gemini_cli.extension_enable`: This event occurs when an extension is enabled -- `gemini_cli.extension_install`: This event occurs when an extension is installed +- `gemini_cli.extension_install`: This event occurs when an extension is + installed - **Attributes**: - `extension_name` (string) - `extension_version` (string) - `extension_source` (string) - `status` (string) -- `gemini_cli.extension_uninstall`: This event occurs when an extension is uninstalled +- `gemini_cli.extension_uninstall`: This event occurs when an extension is + uninstalled ### Metrics @@ -348,7 +357,8 @@ Metrics are numerical measurements of behavior over time. - `status_code` - `error_type` (if applicable) -- `gemini_cli.api.request.latency` (Histogram, ms): Measures API request latency. +- `gemini_cli.api.request.latency` (Histogram, ms): Measures API request + latency. - **Attributes**: - `model` - **Note**: This metric overlaps with `gen_ai.client.operation.duration` below @@ -364,44 +374,62 @@ Metrics are numerical measurements of behavior over time. - `gemini_cli.file.operation.count` (Counter, Int): Counts file operations. - **Attributes**: - - `operation` (string: "create", "read", "update"): The type of file operation. + - `operation` (string: "create", "read", "update"): The type of file + operation. - `lines` (Int, if applicable): Number of lines in the file. - `mimetype` (string, if applicable): Mimetype of the file. - `extension` (string, if applicable): File extension of the file. - - `model_added_lines` (Int, if applicable): Number of lines added/changed by the model. - - `model_removed_lines` (Int, if applicable): Number of lines removed/changed by the model. - - `user_added_lines` (Int, if applicable): Number of lines added/changed by user in AI proposed changes. - - `user_removed_lines` (Int, if applicable): Number of lines removed/changed by user in AI proposed changes. - - `programming_language` (string, if applicable): The programming language of the file. + - `model_added_lines` (Int, if applicable): Number of lines added/changed by + the model. + - `model_removed_lines` (Int, if applicable): Number of lines + removed/changed by the model. + - `user_added_lines` (Int, if applicable): Number of lines added/changed by + user in AI proposed changes. + - `user_removed_lines` (Int, if applicable): Number of lines removed/changed + by user in AI proposed changes. + - `programming_language` (string, if applicable): The programming language + of the file. -- `gemini_cli.chat_compression` (Counter, Int): Counts chat compression operations +- `gemini_cli.chat_compression` (Counter, Int): Counts chat compression + operations - **Attributes**: - `tokens_before`: (Int): Number of tokens in context prior to compression - `tokens_after`: (Int): Number of tokens in context after compression #### GenAI Semantic Convention -The following metrics comply with [OpenTelemetry GenAI semantic conventions] -for standardized observability across GenAI applications: +The following metrics comply with [OpenTelemetry GenAI semantic conventions] for +standardized observability across GenAI applications: -- `gen_ai.client.token.usage` (Histogram, token): Number of input and output tokens used per operation. +- `gen_ai.client.token.usage` (Histogram, token): Number of input and output + tokens used per operation. - **Attributes**: - - `gen_ai.operation.name` (string): The operation type (e.g., "generate_content", "chat") - - `gen_ai.provider.name` (string): The GenAI provider ("gcp.gen_ai" or "gcp.vertex_ai") + - `gen_ai.operation.name` (string): The operation type (e.g., + "generate_content", "chat") + - `gen_ai.provider.name` (string): The GenAI provider ("gcp.gen_ai" or + "gcp.vertex_ai") - `gen_ai.token.type` (string): The token type ("input" or "output") - - `gen_ai.request.model` (string, optional): The model name used for the request - - `gen_ai.response.model` (string, optional): The model name that generated the response + - `gen_ai.request.model` (string, optional): The model name used for the + request + - `gen_ai.response.model` (string, optional): The model name that generated + the response - `server.address` (string, optional): GenAI server address - `server.port` (int, optional): GenAI server port -- `gen_ai.client.operation.duration` (Histogram, s): GenAI operation duration in seconds. +- `gen_ai.client.operation.duration` (Histogram, s): GenAI operation duration in + seconds. - **Attributes**: - - `gen_ai.operation.name` (string): The operation type (e.g., "generate_content", "chat") - - `gen_ai.provider.name` (string): The GenAI provider ("gcp.gen_ai" or "gcp.vertex_ai") - - `gen_ai.request.model` (string, optional): The model name used for the request - - `gen_ai.response.model` (string, optional): The model name that generated the response + - `gen_ai.operation.name` (string): The operation type (e.g., + "generate_content", "chat") + - `gen_ai.provider.name` (string): The GenAI provider ("gcp.gen_ai" or + "gcp.vertex_ai") + - `gen_ai.request.model` (string, optional): The model name used for the + request + - `gen_ai.response.model` (string, optional): The model name that generated + the response - `server.address` (string, optional): GenAI server address - `server.port` (int, optional): GenAI server port - `error.type` (string, optional): Error type if the operation failed -[OpenTelemetry GenAI semantic conventions]: https://github.com/open-telemetry/semantic-conventions/blob/main/docs/gen-ai/gen-ai-metrics.md +[OpenTelemetry GenAI semantic conventions]: + https://github.com/open-telemetry/semantic-conventions/blob/main/docs/gen-ai/gen-ai-metrics.md diff --git a/docs/cli/themes.md b/docs/cli/themes.md index 6954946082..85db2ddd25 100644 --- a/docs/cli/themes.md +++ b/docs/cli/themes.md @@ -1,10 +1,13 @@ # Themes -Gemini CLI supports a variety of themes to customize its color scheme and appearance. You can change the theme to suit your preferences via the `/theme` command or `"theme":` configuration setting. +Gemini CLI supports a variety of themes to customize its color scheme and +appearance. You can change the theme to suit your preferences via the `/theme` +command or `"theme":` configuration setting. ## Available Themes -Gemini CLI comes with a selection of pre-defined themes, which you can list using the `/theme` command within Gemini CLI: +Gemini CLI comes with a selection of pre-defined themes, which you can list +using the `/theme` command within Gemini CLI: - **Dark Themes:** - `ANSI` @@ -25,24 +28,33 @@ Gemini CLI comes with a selection of pre-defined themes, which you can list usin 1. Enter `/theme` into Gemini CLI. 2. A dialog or selection prompt appears, listing the available themes. -3. Using the arrow keys, select a theme. Some interfaces might offer a live preview or highlight as you select. +3. Using the arrow keys, select a theme. Some interfaces might offer a live + preview or highlight as you select. 4. Confirm your selection to apply the theme. -**Note:** If a theme is defined in your `settings.json` file (either by name or by a file path), you must remove the `"theme"` setting from the file before you can change the theme using the `/theme` command. +**Note:** If a theme is defined in your `settings.json` file (either by name or +by a file path), you must remove the `"theme"` setting from the file before you +can change the theme using the `/theme` command. ### Theme Persistence -Selected themes are saved in Gemini CLI's [configuration](../get-started/configuration.md) so your preference is remembered across sessions. +Selected themes are saved in Gemini CLI's +[configuration](../get-started/configuration.md) so your preference is +remembered across sessions. --- ## Custom Color Themes -Gemini CLI allows you to create your own custom color themes by specifying them in your `settings.json` file. This gives you full control over the color palette used in the CLI. +Gemini CLI allows you to create your own custom color themes by specifying them +in your `settings.json` file. This gives you full control over the color palette +used in the CLI. ### How to Define a Custom Theme -Add a `customThemes` block to your user, project, or system `settings.json` file. Each custom theme is defined as an object with a unique name and a set of color keys. For example: +Add a `customThemes` block to your user, project, or system `settings.json` +file. Each custom theme is defined as an object with a unique name and a set of +color keys. For example: ```json { @@ -92,15 +104,23 @@ Add a `customThemes` block to your user, project, or system `settings.json` file - `Comment` - `Gray` -You can use either hex codes (e.g., `#FF0000`) **or** standard CSS color names (e.g., `coral`, `teal`, `blue`) for any color value. See [CSS color names](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#color_keywords) for a full list of supported names. +You can use either hex codes (e.g., `#FF0000`) **or** standard CSS color names +(e.g., `coral`, `teal`, `blue`) for any color value. See +[CSS color names](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#color_keywords) +for a full list of supported names. -You can define multiple custom themes by adding more entries to the `customThemes` object. +You can define multiple custom themes by adding more entries to the +`customThemes` object. ### Loading Themes from a File -In addition to defining custom themes in `settings.json`, you can also load a theme directly from a JSON file by specifying the file path in your `settings.json`. This is useful for sharing themes or keeping them separate from your main configuration. +In addition to defining custom themes in `settings.json`, you can also load a +theme directly from a JSON file by specifying the file path in your +`settings.json`. This is useful for sharing themes or keeping them separate from +your main configuration. -To load a theme from a file, set the `theme` property in your `settings.json` to the path of your theme file: +To load a theme from a file, set the `theme` property in your `settings.json` to +the path of your theme file: ```json { @@ -110,7 +130,8 @@ To load a theme from a file, set the `theme` property in your `settings.json` to } ``` -The theme file must be a valid JSON file that follows the same structure as a custom theme defined in `settings.json`. +The theme file must be a valid JSON file that follows the same structure as a +custom theme defined in `settings.json`. **Example `my-theme.json`:** @@ -136,7 +157,11 @@ The theme file must be a valid JSON file that follows the same structure as a cu } ``` -**Security Note:** For your safety, Gemini CLI will only load theme files that are located within your home directory. If you attempt to load a theme from outside your home directory, a warning will be displayed and the theme will not be loaded. This is to prevent loading potentially malicious theme files from untrusted sources. +**Security Note:** For your safety, Gemini CLI will only load theme files that +are located within your home directory. If you attempt to load a theme from +outside your home directory, a warning will be displayed and the theme will not +be loaded. This is to prevent loading potentially malicious theme files from +untrusted sources. ### Example Custom Theme @@ -144,9 +169,13 @@ The theme file must be a valid JSON file that follows the same structure as a cu ### Using Your Custom Theme -- Select your custom theme using the `/theme` command in Gemini CLI. Your custom theme will appear in the theme selection dialog. -- Or, set it as the default by adding `"theme": "MyCustomTheme"` to the `ui` object in your `settings.json`. -- Custom themes can be set at the user, project, or system level, and follow the same [configuration precedence](../get-started/configuration.md) as other settings. +- Select your custom theme using the `/theme` command in Gemini CLI. Your custom + theme will appear in the theme selection dialog. +- Or, set it as the default by adding `"theme": "MyCustomTheme"` to the `ui` + object in your `settings.json`. +- Custom themes can be set at the user, project, or system level, and follow the + same [configuration precedence](../get-started/configuration.md) as other + settings. --- diff --git a/docs/cli/token-caching.md b/docs/cli/token-caching.md index 17e103e190..9289dbc0d7 100644 --- a/docs/cli/token-caching.md +++ b/docs/cli/token-caching.md @@ -1,6 +1,9 @@ # Token Caching and Cost Optimization -Gemini CLI automatically optimizes API costs through token caching when using API key authentication (Gemini API key or Vertex AI). This feature reuses previous system instructions and context to reduce the number of tokens processed in subsequent requests. +Gemini CLI automatically optimizes API costs through token caching when using +API key authentication (Gemini API key or Vertex AI). This feature reuses +previous system instructions and context to reduce the number of tokens +processed in subsequent requests. **Token caching is available for:** @@ -9,6 +12,9 @@ Gemini CLI automatically optimizes API costs through token caching when using AP **Token caching is not available for:** -- OAuth users (Google Personal/Enterprise accounts) - the Code Assist API does not support cached content creation at this time +- OAuth users (Google Personal/Enterprise accounts) - the Code Assist API does + not support cached content creation at this time -You can view your token usage and cached token savings using the `/stats` command. When cached tokens are available, they will be displayed in the stats output. +You can view your token usage and cached token savings using the `/stats` +command. When cached tokens are available, they will be displayed in the stats +output. diff --git a/docs/cli/trusted-folders.md b/docs/cli/trusted-folders.md index 399d0d8d95..94d8410ce7 100644 --- a/docs/cli/trusted-folders.md +++ b/docs/cli/trusted-folders.md @@ -1,10 +1,14 @@ # Trusted Folders -The Trusted Folders feature is a security setting that gives you control over which projects can use the full capabilities of the Gemini CLI. It prevents potentially malicious code from running by asking you to approve a folder before the CLI loads any project-specific configurations from it. +The Trusted Folders feature is a security setting that gives you control over +which projects can use the full capabilities of the Gemini CLI. It prevents +potentially malicious code from running by asking you to approve a folder before +the CLI loads any project-specific configurations from it. ## Enabling the Feature -The Trusted Folders feature is **disabled by default**. To use it, you must first enable it in your settings. +The Trusted Folders feature is **disabled by default**. To use it, you must +first enable it in your settings. Add the following to your user `settings.json` file: @@ -20,42 +24,65 @@ Add the following to your user `settings.json` file: ## How It Works: The Trust Dialog -Once the feature is enabled, the first time you run the Gemini CLI from a folder, a dialog will automatically appear, prompting you to make a choice: +Once the feature is enabled, the first time you run the Gemini CLI from a +folder, a dialog will automatically appear, prompting you to make a choice: -- **Trust folder**: Grants full trust to the current folder (e.g., `my-project`). -- **Trust parent folder**: Grants trust to the parent directory (e.g., `safe-projects`), which automatically trusts all of its subdirectories as well. This is useful if you keep all your safe projects in one place. -- **Don't trust**: Marks the folder as untrusted. The CLI will operate in a restricted "safe mode." +- **Trust folder**: Grants full trust to the current folder (e.g., + `my-project`). +- **Trust parent folder**: Grants trust to the parent directory (e.g., + `safe-projects`), which automatically trusts all of its subdirectories as + well. This is useful if you keep all your safe projects in one place. +- **Don't trust**: Marks the folder as untrusted. The CLI will operate in a + restricted "safe mode." -Your choice is saved in a central file (`~/.gemini/trustedFolders.json`), so you will only be asked once per folder. +Your choice is saved in a central file (`~/.gemini/trustedFolders.json`), so you +will only be asked once per folder. ## Why Trust Matters: The Impact of an Untrusted Workspace -When a folder is **untrusted**, the Gemini CLI runs in a restricted "safe mode" to protect you. In this mode, the following features are disabled: +When a folder is **untrusted**, the Gemini CLI runs in a restricted "safe mode" +to protect you. In this mode, the following features are disabled: -1. **Workspace Settings are Ignored**: The CLI will **not** load the `.gemini/settings.json` file from the project. This prevents the loading of custom tools and other potentially dangerous configurations. +1. **Workspace Settings are Ignored**: The CLI will **not** load the + `.gemini/settings.json` file from the project. This prevents the loading of + custom tools and other potentially dangerous configurations. -2. **Environment Variables are Ignored**: The CLI will **not** load any `.env` files from the project. +2. **Environment Variables are Ignored**: The CLI will **not** load any `.env` + files from the project. -3. **Extension Management is Restricted**: You **cannot install, update, or uninstall** extensions. +3. **Extension Management is Restricted**: You **cannot install, update, or + uninstall** extensions. -4. **Tool Auto-Acceptance is Disabled**: You will always be prompted before any tool is run, even if you have auto-acceptance enabled globally. +4. **Tool Auto-Acceptance is Disabled**: You will always be prompted before any + tool is run, even if you have auto-acceptance enabled globally. -5. **Automatic Memory Loading is Disabled**: The CLI will not automatically load files into context from directories specified in local settings. +5. **Automatic Memory Loading is Disabled**: The CLI will not automatically + load files into context from directories specified in local settings. -Granting trust to a folder unlocks the full functionality of the Gemini CLI for that workspace. +Granting trust to a folder unlocks the full functionality of the Gemini CLI for +that workspace. ## Managing Your Trust Settings -If you need to change a decision or see all your settings, you have a couple of options: +If you need to change a decision or see all your settings, you have a couple of +options: -- **Change the Current Folder's Trust**: Run the `/permissions` command from within the CLI. This will bring up the same interactive dialog, allowing you to change the trust level for the current folder. +- **Change the Current Folder's Trust**: Run the `/permissions` command from + within the CLI. This will bring up the same interactive dialog, allowing you + to change the trust level for the current folder. -- **View All Trust Rules**: To see a complete list of all your trusted and untrusted folder rules, you can inspect the contents of the `~/.gemini/trustedFolders.json` file in your home directory. +- **View All Trust Rules**: To see a complete list of all your trusted and + untrusted folder rules, you can inspect the contents of the + `~/.gemini/trustedFolders.json` file in your home directory. ## The Trust Check Process (Advanced) -For advanced users, it's helpful to know the exact order of operations for how trust is determined: +For advanced users, it's helpful to know the exact order of operations for how +trust is determined: -1. **IDE Trust Signal**: If you are using the [IDE Integration](../ide-integration/index.md), the CLI first asks the IDE if the workspace is trusted. The IDE's response takes highest priority. +1. **IDE Trust Signal**: If you are using the + [IDE Integration](../ide-integration/index.md), the CLI first asks the IDE + if the workspace is trusted. The IDE's response takes highest priority. -2. **Local Trust File**: If the IDE is not connected, the CLI checks the central `~/.gemini/trustedFolders.json` file. +2. **Local Trust File**: If the IDE is not connected, the CLI checks the + central `~/.gemini/trustedFolders.json` file. diff --git a/docs/cli/tutorials.md b/docs/cli/tutorials.md index e156809592..ed907e21d5 100644 --- a/docs/cli/tutorials.md +++ b/docs/cli/tutorials.md @@ -4,17 +4,22 @@ This page contains tutorials for interacting with Gemini CLI. ## Setting up a Model Context Protocol (MCP) server -> [!CAUTION] -> Before using a third-party MCP server, ensure you trust its source and understand the tools it provides. Your use of third-party servers is at your own risk. +> [!CAUTION] Before using a third-party MCP server, ensure you trust its source +> and understand the tools it provides. Your use of third-party servers is at +> your own risk. -This tutorial demonstrates how to set up a MCP server, using the [GitHub MCP server](https://github.com/github/github-mcp-server) as an example. The GitHub MCP server provides tools for interacting with GitHub repositories, such as creating issues and commenting on pull requests. +This tutorial demonstrates how to set up a MCP server, using the +[GitHub MCP server](https://github.com/github/github-mcp-server) as an example. +The GitHub MCP server provides tools for interacting with GitHub repositories, +such as creating issues and commenting on pull requests. ### Prerequisites Before you begin, ensure you have the following installed and configured: - **Docker:** Install and run [Docker]. -- **GitHub Personal Access Token (PAT):** Create a new [classic] or [fine-grained] PAT with the necessary scopes. +- **GitHub Personal Access Token (PAT):** Create a new [classic] or + [fine-grained] PAT with the necessary scopes. [Docker]: https://www.docker.com/ [classic]: https://github.com/settings/tokens/new @@ -24,7 +29,10 @@ Before you begin, ensure you have the following installed and configured: #### Configure the MCP server in `settings.json` -In your project's root directory, create or open the [`.gemini/settings.json` file](../get-started/configuration.md). Within the file, add the `mcpServers` configuration block, which provides instructions for how to launch the GitHub MCP server. +In your project's root directory, create or open the +[`.gemini/settings.json` file](../get-started/configuration.md). Within the +file, add the `mcpServers` configuration block, which provides instructions for +how to launch the GitHub MCP server. ```json { @@ -49,8 +57,11 @@ In your project's root directory, create or open the [`.gemini/settings.json` fi #### Set your GitHub token -> [!CAUTION] -> Using a broadly scoped personal access token that has access to personal and private repositories can lead to information from the private repository being leaked into the public repository. We recommend using a fine-grained access token that doesn't share access to both public and private repositories. +> [!CAUTION] Using a broadly scoped personal access token that has access to +> personal and private repositories can lead to information from the private +> repository being leaked into the public repository. We recommend using a +> fine-grained access token that doesn't share access to both public and private +> repositories. Use an environment variable to store your GitHub PAT: @@ -58,11 +69,14 @@ Use an environment variable to store your GitHub PAT: GITHUB_PERSONAL_ACCESS_TOKEN="pat_YourActualGitHubTokenHere" ``` -Gemini CLI uses this value in the `mcpServers` configuration that you defined in the `settings.json` file. +Gemini CLI uses this value in the `mcpServers` configuration that you defined in +the `settings.json` file. #### Launch Gemini CLI and verify the connection -When you launch Gemini CLI, it automatically reads your configuration and launches the GitHub MCP server in the background. You can then use natural language prompts to ask Gemini CLI to perform GitHub actions. For example: +When you launch Gemini CLI, it automatically reads your configuration and +launches the GitHub MCP server in the background. You can then use natural +language prompts to ask Gemini CLI to perform GitHub actions. For example: ```bash "get all open issues assigned to me in the 'foo/bar' repo and prioritize them" diff --git a/docs/cli/uninstall.md b/docs/cli/uninstall.md index 1aa603362c..a13aabad2e 100644 --- a/docs/cli/uninstall.md +++ b/docs/cli/uninstall.md @@ -1,12 +1,16 @@ # Uninstalling the CLI -Your uninstall method depends on how you ran the CLI. Follow the instructions for either npx or a global npm installation. +Your uninstall method depends on how you ran the CLI. Follow the instructions +for either npx or a global npm installation. ## Method 1: Using npx -npx runs packages from a temporary cache without a permanent installation. To "uninstall" the CLI, you must clear this cache, which will remove gemini-cli and any other packages previously executed with npx. +npx runs packages from a temporary cache without a permanent installation. To +"uninstall" the CLI, you must clear this cache, which will remove gemini-cli and +any other packages previously executed with npx. -The npx cache is a directory named `_npx` inside your main npm cache folder. You can find your npm cache path by running `npm config get cache`. +The npx cache is a directory named `_npx` inside your main npm cache folder. You +can find your npm cache path by running `npm config get cache`. **For macOS / Linux** @@ -33,7 +37,8 @@ Remove-Item -Path (Join-Path $env:LocalAppData "npm-cache\_npx") -Recurse -Force ## Method 2: Using npm (Global Install) -If you installed the CLI globally (e.g., `npm install -g @google/gemini-cli`), use the `npm uninstall` command with the `-g` flag to remove it. +If you installed the CLI globally (e.g., `npm install -g @google/gemini-cli`), +use the `npm uninstall` command with the `-g` flag to remove it. ```bash npm uninstall -g @google/gemini-cli diff --git a/docs/core/index.md b/docs/core/index.md index cca23ef390..6276b2c4c2 100644 --- a/docs/core/index.md +++ b/docs/core/index.md @@ -1,63 +1,99 @@ # Gemini CLI Core -Gemini CLI's core package (`packages/core`) is the backend portion of Gemini CLI, handling communication with the Gemini API, managing tools, and processing requests sent from `packages/cli`. For a general overview of Gemini CLI, see the [main documentation page](../index.md). +Gemini CLI's core package (`packages/core`) is the backend portion of Gemini +CLI, handling communication with the Gemini API, managing tools, and processing +requests sent from `packages/cli`. For a general overview of Gemini CLI, see the +[main documentation page](../index.md). ## Navigating this section -- **[Core tools API](./tools-api.md):** Information on how tools are defined, registered, and used by the core. -- **[Memory Import Processor](./memport.md):** Documentation for the modular GEMINI.md import feature using @file.md syntax. +- **[Core tools API](./tools-api.md):** Information on how tools are defined, + registered, and used by the core. +- **[Memory Import Processor](./memport.md):** Documentation for the modular + GEMINI.md import feature using @file.md syntax. ## Role of the core -While the `packages/cli` portion of Gemini CLI provides the user interface, `packages/core` is responsible for: +While the `packages/cli` portion of Gemini CLI provides the user interface, +`packages/core` is responsible for: -- **Gemini API interaction:** Securely communicating with the Google Gemini API, sending user prompts, and receiving model responses. -- **Prompt engineering:** Constructing effective prompts for the Gemini model, potentially incorporating conversation history, tool definitions, and instructional context from `GEMINI.md` files. +- **Gemini API interaction:** Securely communicating with the Google Gemini API, + sending user prompts, and receiving model responses. +- **Prompt engineering:** Constructing effective prompts for the Gemini model, + potentially incorporating conversation history, tool definitions, and + instructional context from `GEMINI.md` files. - **Tool management & orchestration:** - - Registering available tools (e.g., file system tools, shell command execution). + - Registering available tools (e.g., file system tools, shell command + execution). - Interpreting tool use requests from the Gemini model. - Executing the requested tools with the provided arguments. - Returning tool execution results to the Gemini model for further processing. -- **Session and state management:** Keeping track of the conversation state, including history and any relevant context required for coherent interactions. -- **Configuration:** Managing core-specific configurations, such as API key access, model selection, and tool settings. +- **Session and state management:** Keeping track of the conversation state, + including history and any relevant context required for coherent interactions. +- **Configuration:** Managing core-specific configurations, such as API key + access, model selection, and tool settings. ## Security considerations The core plays a vital role in security: -- **API key management:** It handles the `GEMINI_API_KEY` and ensures it's used securely when communicating with the Gemini API. -- **Tool execution:** When tools interact with the local system (e.g., `run_shell_command`), the core (and its underlying tool implementations) must do so with appropriate caution, often involving sandboxing mechanisms to prevent unintended modifications. +- **API key management:** It handles the `GEMINI_API_KEY` and ensures it's used + securely when communicating with the Gemini API. +- **Tool execution:** When tools interact with the local system (e.g., + `run_shell_command`), the core (and its underlying tool implementations) must + do so with appropriate caution, often involving sandboxing mechanisms to + prevent unintended modifications. ## Chat history compression -To ensure that long conversations don't exceed the token limits of the Gemini model, the core includes a chat history compression feature. +To ensure that long conversations don't exceed the token limits of the Gemini +model, the core includes a chat history compression feature. -When a conversation approaches the token limit for the configured model, the core automatically compresses the conversation history before sending it to the model. This compression is designed to be lossless in terms of the information conveyed, but it reduces the overall number of tokens used. +When a conversation approaches the token limit for the configured model, the +core automatically compresses the conversation history before sending it to the +model. This compression is designed to be lossless in terms of the information +conveyed, but it reduces the overall number of tokens used. -You can find the token limits for each model in the [Google AI documentation](https://ai.google.dev/gemini-api/docs/models). +You can find the token limits for each model in the +[Google AI documentation](https://ai.google.dev/gemini-api/docs/models). ## Model fallback -Gemini CLI includes a model fallback mechanism to ensure that you can continue to use the CLI even if the default "pro" model is rate-limited. +Gemini CLI includes a model fallback mechanism to ensure that you can continue +to use the CLI even if the default "pro" model is rate-limited. -If you are using the default "pro" model and the CLI detects that you are being rate-limited, it automatically switches to the "flash" model for the current session. This allows you to continue working without interruption. +If you are using the default "pro" model and the CLI detects that you are being +rate-limited, it automatically switches to the "flash" model for the current +session. This allows you to continue working without interruption. ## File discovery service -The file discovery service is responsible for finding files in the project that are relevant to the current context. It is used by the `@` command and other tools that need to access files. +The file discovery service is responsible for finding files in the project that +are relevant to the current context. It is used by the `@` command and other +tools that need to access files. ## Memory discovery service -The memory discovery service is responsible for finding and loading the `GEMINI.md` files that provide context to the model. It searches for these files in a hierarchical manner, starting from the current working directory and moving up to the project root and the user's home directory. It also searches in subdirectories. +The memory discovery service is responsible for finding and loading the +`GEMINI.md` files that provide context to the model. It searches for these files +in a hierarchical manner, starting from the current working directory and moving +up to the project root and the user's home directory. It also searches in +subdirectories. -This allows you to have global, project-level, and component-level context files, which are all combined to provide the model with the most relevant information. +This allows you to have global, project-level, and component-level context +files, which are all combined to provide the model with the most relevant +information. -You can use the [`/memory` command](../cli/commands.md) to `show`, `add`, and `refresh` the content of loaded `GEMINI.md` files. +You can use the [`/memory` command](../cli/commands.md) to `show`, `add`, and +`refresh` the content of loaded `GEMINI.md` files. ## Citations -When Gemini finds it is reciting text from a source it appends the citation to the output. It is enabled by default but can be disabled with the ui.showCitations setting. +When Gemini finds it is reciting text from a source it appends the citation to +the output. It is enabled by default but can be disabled with the +ui.showCitations setting. -- When proposing an edit the citations display before giving the user the option to accept. +- When proposing an edit the citations display before giving the user the option + to accept. - Citations are always shown at the end of the model’s turn. - We deduplicate citations and display them in alphabetical order. diff --git a/docs/core/memport.md b/docs/core/memport.md index e90d195f3c..6f6575dbf9 100644 --- a/docs/core/memport.md +++ b/docs/core/memport.md @@ -1,10 +1,15 @@ # Memory Import Processor -The Memory Import Processor is a feature that allows you to modularize your GEMINI.md files by importing content from other files using the `@file.md` syntax. +The Memory Import Processor is a feature that allows you to modularize your +GEMINI.md files by importing content from other files using the `@file.md` +syntax. ## Overview -This feature enables you to break down large GEMINI.md files into smaller, more manageable components that can be reused across different contexts. The import processor supports both relative and absolute paths, with built-in safety features to prevent circular imports and ensure file access security. +This feature enables you to break down large GEMINI.md files into smaller, more +manageable components that can be reused across different contexts. The import +processor supports both relative and absolute paths, with built-in safety +features to prevent circular imports and ensure file access security. ## Syntax @@ -57,9 +62,7 @@ The imported files can themselves contain imports, creating a nested structure: ```markdown # main.md -@./header.md -@./content.md -@./footer.md +@./header.md @./content.md @./footer.md ``` ```markdown @@ -88,29 +91,40 @@ The processor automatically detects and prevents circular imports: ### File Access Security -The `validateImportPath` function ensures that imports are only allowed from specified directories, preventing access to sensitive files outside the allowed scope. +The `validateImportPath` function ensures that imports are only allowed from +specified directories, preventing access to sensitive files outside the allowed +scope. ### Maximum Import Depth -To prevent infinite recursion, there's a configurable maximum import depth (default: 5 levels). +To prevent infinite recursion, there's a configurable maximum import depth +(default: 5 levels). ## Error Handling ### Missing Files -If a referenced file doesn't exist, the import will fail gracefully with an error comment in the output. +If a referenced file doesn't exist, the import will fail gracefully with an +error comment in the output. ### File Access Errors -Permission issues or other file system errors are handled gracefully with appropriate error messages. +Permission issues or other file system errors are handled gracefully with +appropriate error messages. ## Code Region Detection -The import processor uses the `marked` library to detect code blocks and inline code spans, ensuring that `@` imports inside these regions are properly ignored. This provides robust handling of nested code blocks and complex Markdown structures. +The import processor uses the `marked` library to detect code blocks and inline +code spans, ensuring that `@` imports inside these regions are properly ignored. +This provides robust handling of nested code blocks and complex Markdown +structures. ## Import Tree Structure -The processor returns an import tree that shows the hierarchy of imported files, similar to Claude's `/memory` feature. This helps users debug problems with their GEMINI.md files by showing which files were read and their import relationships. +The processor returns an import tree that shows the hierarchy of imported files, +similar to Claude's `/memory` feature. This helps users debug problems with +their GEMINI.md files by showing which files were read and their import +relationships. Example tree structure: @@ -126,13 +140,19 @@ Memory Files L included.md ``` -The tree preserves the order that files were imported and shows the complete import chain for debugging purposes. +The tree preserves the order that files were imported and shows the complete +import chain for debugging purposes. ## Comparison to Claude Code's `/memory` (`claude.md`) Approach -Claude Code's `/memory` feature (as seen in `claude.md`) produces a flat, linear document by concatenating all included files, always marking file boundaries with clear comments and path names. It does not explicitly present the import hierarchy, but the LLM receives all file contents and paths, which is sufficient for reconstructing the hierarchy if needed. +Claude Code's `/memory` feature (as seen in `claude.md`) produces a flat, linear +document by concatenating all included files, always marking file boundaries +with clear comments and path names. It does not explicitly present the import +hierarchy, but the LLM receives all file contents and paths, which is sufficient +for reconstructing the hierarchy if needed. -Note: The import tree is mainly for clarity during development and has limited relevance to LLM consumption. +> [!NOTE] The import tree is mainly for clarity during development and has +> limited relevance to LLM consumption. ## API Reference @@ -144,10 +164,13 @@ Processes import statements in GEMINI.md content. - `content` (string): The content to process for imports - `basePath` (string): The directory path where the current file is located -- `debugMode` (boolean, optional): Whether to enable debug logging (default: false) -- `importState` (ImportState, optional): State tracking for circular import prevention +- `debugMode` (boolean, optional): Whether to enable debug logging (default: + false) +- `importState` (ImportState, optional): State tracking for circular import + prevention -**Returns:** Promise<ProcessImportsResult> - Object containing processed content and import tree +**Returns:** Promise<ProcessImportsResult> - Object containing processed +content and import tree ### `ProcessImportsResult` @@ -181,13 +204,16 @@ Validates import paths to ensure they are safe and within allowed directories. ### `findProjectRoot(startDir)` -Finds the project root by searching for a `.git` directory upwards from the given start directory. Implemented as an **async** function using non-blocking file system APIs to avoid blocking the Node.js event loop. +Finds the project root by searching for a `.git` directory upwards from the +given start directory. Implemented as an **async** function using non-blocking +file system APIs to avoid blocking the Node.js event loop. **Parameters:** - `startDir` (string): The directory to start searching from -**Returns:** Promise<string> - The project root directory (or the start directory if no `.git` is found) +**Returns:** Promise<string> - The project root directory (or the start +directory if no `.git` is found) ## Best Practices @@ -202,9 +228,12 @@ Finds the project root by searching for a `.git` directory upwards from the give ### Common Issues 1. **Import not working**: Check that the file exists and the path is correct -2. **Circular import warnings**: Review your import structure for circular references -3. **Permission errors**: Ensure the files are readable and within allowed directories -4. **Path resolution issues**: Use absolute paths if relative paths aren't resolving correctly +2. **Circular import warnings**: Review your import structure for circular + references +3. **Permission errors**: Ensure the files are readable and within allowed + directories +4. **Path resolution issues**: Use absolute paths if relative paths aren't + resolving correctly ### Debug Mode diff --git a/docs/core/tools-api.md b/docs/core/tools-api.md index 73ac903fd4..3f77c423f3 100644 --- a/docs/core/tools-api.md +++ b/docs/core/tools-api.md @@ -1,75 +1,132 @@ # Gemini CLI Core: Tools API -The Gemini CLI core (`packages/core`) features a robust system for defining, registering, and executing tools. These tools extend the capabilities of the Gemini model, allowing it to interact with the local environment, fetch web content, and perform various actions beyond simple text generation. +The Gemini CLI core (`packages/core`) features a robust system for defining, +registering, and executing tools. These tools extend the capabilities of the +Gemini model, allowing it to interact with the local environment, fetch web +content, and perform various actions beyond simple text generation. ## Core Concepts -- **Tool (`tools.ts`):** An interface and base class (`BaseTool`) that defines the contract for all tools. Each tool must have: +- **Tool (`tools.ts`):** An interface and base class (`BaseTool`) that defines + the contract for all tools. Each tool must have: - `name`: A unique internal name (used in API calls to Gemini). - `displayName`: A user-friendly name. - - `description`: A clear explanation of what the tool does, which is provided to the Gemini model. - - `parameterSchema`: A JSON schema defining the parameters that the tool accepts. This is crucial for the Gemini model to understand how to call the tool correctly. + - `description`: A clear explanation of what the tool does, which is provided + to the Gemini model. + - `parameterSchema`: A JSON schema defining the parameters that the tool + accepts. This is crucial for the Gemini model to understand how to call the + tool correctly. - `validateToolParams()`: A method to validate incoming parameters. - - `getDescription()`: A method to provide a human-readable description of what the tool will do with specific parameters before execution. - - `shouldConfirmExecute()`: A method to determine if user confirmation is required before execution (e.g., for potentially destructive operations). - - `execute()`: The core method that performs the tool's action and returns a `ToolResult`. + - `getDescription()`: A method to provide a human-readable description of what + the tool will do with specific parameters before execution. + - `shouldConfirmExecute()`: A method to determine if user confirmation is + required before execution (e.g., for potentially destructive operations). + - `execute()`: The core method that performs the tool's action and returns a + `ToolResult`. -- **`ToolResult` (`tools.ts`):** An interface defining the structure of a tool's execution outcome: - - `llmContent`: The factual content to be included in the history sent back to the LLM for context. This can be a simple string or a `PartListUnion` (an array of `Part` objects and strings) for rich content. - - `returnDisplay`: A user-friendly string (often Markdown) or a special object (like `FileDiff`) for display in the CLI. +- **`ToolResult` (`tools.ts`):** An interface defining the structure of a tool's + execution outcome: + - `llmContent`: The factual content to be included in the history sent back to + the LLM for context. This can be a simple string or a `PartListUnion` (an + array of `Part` objects and strings) for rich content. + - `returnDisplay`: A user-friendly string (often Markdown) or a special object + (like `FileDiff`) for display in the CLI. -- **Returning Rich Content:** Tools are not limited to returning simple text. The `llmContent` can be a `PartListUnion`, which is an array that can contain a mix of `Part` objects (for images, audio, etc.) and `string`s. This allows a single tool execution to return multiple pieces of rich content. +- **Returning Rich Content:** Tools are not limited to returning simple text. + The `llmContent` can be a `PartListUnion`, which is an array that can contain + a mix of `Part` objects (for images, audio, etc.) and `string`s. This allows a + single tool execution to return multiple pieces of rich content. -- **Tool Registry (`tool-registry.ts`):** A class (`ToolRegistry`) responsible for: - - **Registering Tools:** Holding a collection of all available built-in tools (e.g., `ReadFileTool`, `ShellTool`). +- **Tool Registry (`tool-registry.ts`):** A class (`ToolRegistry`) responsible + for: + - **Registering Tools:** Holding a collection of all available built-in tools + (e.g., `ReadFileTool`, `ShellTool`). - **Discovering Tools:** It can also discover tools dynamically: - - **Command-based Discovery:** If `tools.discoveryCommand` is configured in settings, this command is executed. It's expected to output JSON describing custom tools, which are then registered as `DiscoveredTool` instances. - - **MCP-based Discovery:** If `mcp.serverCommand` is configured, the registry can connect to a Model Context Protocol (MCP) server to list and register tools (`DiscoveredMCPTool`). - - **Providing Schemas:** Exposing the `FunctionDeclaration` schemas of all registered tools to the Gemini model, so it knows what tools are available and how to use them. - - **Retrieving Tools:** Allowing the core to get a specific tool by name for execution. + - **Command-based Discovery:** If `tools.discoveryCommand` is configured in + settings, this command is executed. It's expected to output JSON + describing custom tools, which are then registered as `DiscoveredTool` + instances. + - **MCP-based Discovery:** If `mcp.serverCommand` is configured, the + registry can connect to a Model Context Protocol (MCP) server to list and + register tools (`DiscoveredMCPTool`). + - **Providing Schemas:** Exposing the `FunctionDeclaration` schemas of all + registered tools to the Gemini model, so it knows what tools are available + and how to use them. + - **Retrieving Tools:** Allowing the core to get a specific tool by name for + execution. ## Built-in Tools -The core comes with a suite of pre-defined tools, typically found in `packages/core/src/tools/`. These include: +The core comes with a suite of pre-defined tools, typically found in +`packages/core/src/tools/`. These include: - **File System Tools:** - `LSTool` (`ls.ts`): Lists directory contents. - - `ReadFileTool` (`read-file.ts`): Reads the content of a single file. It takes an `absolute_path` parameter, which must be an absolute path. + - `ReadFileTool` (`read-file.ts`): Reads the content of a single file. It + takes an `absolute_path` parameter, which must be an absolute path. - `WriteFileTool` (`write-file.ts`): Writes content to a file. - `GrepTool` (`grep.ts`): Searches for patterns in files. - `GlobTool` (`glob.ts`): Finds files matching glob patterns. - - `EditTool` (`edit.ts`): Performs in-place modifications to files (often requiring confirmation). - - `ReadManyFilesTool` (`read-many-files.ts`): Reads and concatenates content from multiple files or glob patterns (used by the `@` command in CLI). + - `EditTool` (`edit.ts`): Performs in-place modifications to files (often + requiring confirmation). + - `ReadManyFilesTool` (`read-many-files.ts`): Reads and concatenates content + from multiple files or glob patterns (used by the `@` command in CLI). - **Execution Tools:** - - `ShellTool` (`shell.ts`): Executes arbitrary shell commands (requires careful sandboxing and user confirmation). + - `ShellTool` (`shell.ts`): Executes arbitrary shell commands (requires + careful sandboxing and user confirmation). - **Web Tools:** - `WebFetchTool` (`web-fetch.ts`): Fetches content from a URL. - `WebSearchTool` (`web-search.ts`): Performs a web search. - **Memory Tools:** - `MemoryTool` (`memoryTool.ts`): Interacts with the AI's memory. -Each of these tools extends `BaseTool` and implements the required methods for its specific functionality. +Each of these tools extends `BaseTool` and implements the required methods for +its specific functionality. ## Tool Execution Flow -1. **Model Request:** The Gemini model, based on the user's prompt and the provided tool schemas, decides to use a tool and returns a `FunctionCall` part in its response, specifying the tool name and arguments. +1. **Model Request:** The Gemini model, based on the user's prompt and the + provided tool schemas, decides to use a tool and returns a `FunctionCall` + part in its response, specifying the tool name and arguments. 2. **Core Receives Request:** The core parses this `FunctionCall`. 3. **Tool Retrieval:** It looks up the requested tool in the `ToolRegistry`. -4. **Parameter Validation:** The tool's `validateToolParams()` method is called. +4. **Parameter Validation:** The tool's `validateToolParams()` method is + called. 5. **Confirmation (if needed):** - The tool's `shouldConfirmExecute()` method is called. - - If it returns details for confirmation, the core communicates this back to the CLI, which prompts the user. + - If it returns details for confirmation, the core communicates this back to + the CLI, which prompts the user. - The user's decision (e.g., proceed, cancel) is sent back to the core. -6. **Execution:** If validated and confirmed (or if no confirmation is needed), the core calls the tool's `execute()` method with the provided arguments and an `AbortSignal` (for potential cancellation). -7. **Result Processing:** The `ToolResult` from `execute()` is received by the core. -8. **Response to Model:** The `llmContent` from the `ToolResult` is packaged as a `FunctionResponse` and sent back to the Gemini model so it can continue generating a user-facing response. -9. **Display to User:** The `returnDisplay` from the `ToolResult` is sent to the CLI to show the user what the tool did. +6. **Execution:** If validated and confirmed (or if no confirmation is needed), + the core calls the tool's `execute()` method with the provided arguments and + an `AbortSignal` (for potential cancellation). +7. **Result Processing:** The `ToolResult` from `execute()` is received by the + core. +8. **Response to Model:** The `llmContent` from the `ToolResult` is packaged as + a `FunctionResponse` and sent back to the Gemini model so it can continue + generating a user-facing response. +9. **Display to User:** The `returnDisplay` from the `ToolResult` is sent to + the CLI to show the user what the tool did. ## Extending with Custom Tools -While direct programmatic registration of new tools by users isn't explicitly detailed as a primary workflow in the provided files for typical end-users, the architecture supports extension through: +While direct programmatic registration of new tools by users isn't explicitly +detailed as a primary workflow in the provided files for typical end-users, the +architecture supports extension through: -- **Command-based Discovery:** Advanced users or project administrators can define a `tools.discoveryCommand` in `settings.json`. This command, when run by the Gemini CLI core, should output a JSON array of `FunctionDeclaration` objects. The core will then make these available as `DiscoveredTool` instances. The corresponding `tools.callCommand` would then be responsible for actually executing these custom tools. -- **MCP Server(s):** For more complex scenarios, one or more MCP servers can be set up and configured via the `mcpServers` setting in `settings.json`. The Gemini CLI core can then discover and use tools exposed by these servers. As mentioned, if you have multiple MCP servers, the tool names will be prefixed with the server name from your configuration (e.g., `serverAlias__actualToolName`). +- **Command-based Discovery:** Advanced users or project administrators can + define a `tools.discoveryCommand` in `settings.json`. This command, when run + by the Gemini CLI core, should output a JSON array of `FunctionDeclaration` + objects. The core will then make these available as `DiscoveredTool` + instances. The corresponding `tools.callCommand` would then be responsible for + actually executing these custom tools. +- **MCP Server(s):** For more complex scenarios, one or more MCP servers can be + set up and configured via the `mcpServers` setting in `settings.json`. The + Gemini CLI core can then discover and use tools exposed by these servers. As + mentioned, if you have multiple MCP servers, the tool names will be prefixed + with the server name from your configuration (e.g., + `serverAlias__actualToolName`). -This tool system provides a flexible and powerful way to augment the Gemini model's capabilities, making the Gemini CLI a versatile assistant for a wide range of tasks. +This tool system provides a flexible and powerful way to augment the Gemini +model's capabilities, making the Gemini CLI a versatile assistant for a wide +range of tasks. diff --git a/docs/examples/proxy-script.md b/docs/examples/proxy-script.md index 78299001ba..63445ae677 100644 --- a/docs/examples/proxy-script.md +++ b/docs/examples/proxy-script.md @@ -1,6 +1,8 @@ # Example Proxy Script -The following is an example of a proxy script that can be used with the `GEMINI_SANDBOX_PROXY_COMMAND` environment variable. This script only allows `HTTPS` connections to `example.com:443` and declines all other requests. +The following is an example of a proxy script that can be used with the +`GEMINI_SANDBOX_PROXY_COMMAND` environment variable. This script only allows +`HTTPS` connections to `example.com:443` and declines all other requests. ```javascript #!/usr/bin/env node diff --git a/docs/extensions/extension-releasing.md b/docs/extensions/extension-releasing.md index 1266448d0b..29c19b8878 100644 --- a/docs/extensions/extension-releasing.md +++ b/docs/extensions/extension-releasing.md @@ -5,55 +5,113 @@ There are two primary ways of releasing extensions to users: - [Git repository](#releasing-through-a-git-repository) - [Github Releases](#releasing-through-github-releases) -Git repository releases tend to be the simplest and most flexible approach, while GitHub releases can be more efficient on initial install as they are shipped as single archives instead of requiring a git clone which downloads each file individually. Github releases may also contain platform specific archives if you need to ship platform specific binary files. +Git repository releases tend to be the simplest and most flexible approach, +while GitHub releases can be more efficient on initial install as they are +shipped as single archives instead of requiring a git clone which downloads each +file individually. Github releases may also contain platform specific archives +if you need to ship platform specific binary files. ## Releasing through a git repository -This is the most flexible and simple option. All you need to do is create a publicly accessible git repo (such as a public github repository) and then users can install your extension using `gemini extensions install `, or for a GitHub repository they can use the simplified `gemini extensions install /` format. They can optionally depend on a specific ref (branch/tag/commit) using the `--ref=` argument, this defaults to the default branch. +This is the most flexible and simple option. All you need to do is create a +publicly accessible git repo (such as a public github repository) and then users +can install your extension using `gemini extensions install `, or +for a GitHub repository they can use the simplified +`gemini extensions install /` format. They can optionally depend on a +specific ref (branch/tag/commit) using the `--ref=` argument, this +defaults to the default branch. -Whenever commits are pushed to the ref that a user depends on, they will be prompted to update the extension. Note that this also allows for easy rollbacks, the HEAD commit is always treated as the latest version regardless of the actual version in the `gemini-extension.json` file. +Whenever commits are pushed to the ref that a user depends on, they will be +prompted to update the extension. Note that this also allows for easy rollbacks, +the HEAD commit is always treated as the latest version regardless of the actual +version in the `gemini-extension.json` file. ### Managing release channels using a git repository -Users can depend on any ref from your git repo, such as a branch or tag, which allows you to manage multiple release channels. +Users can depend on any ref from your git repo, such as a branch or tag, which +allows you to manage multiple release channels. -For instance, you can maintain a `stable` branch, which users can install this way `gemini extensions install --ref=stable`. Or, you could make this the default by treating your default branch as your stable release branch, and doing development in a different branch (for instance called `dev`). You can maintain as many branches or tags as you like, providing maximum flexibility for you and your users. +For instance, you can maintain a `stable` branch, which users can install this +way `gemini extensions install --ref=stable`. Or, you could make +this the default by treating your default branch as your stable release branch, +and doing development in a different branch (for instance called `dev`). You can +maintain as many branches or tags as you like, providing maximum flexibility for +you and your users. -Note that these `ref` arguments can be tags, branches, or even specific commits, which allows users to depend on a specific version of your extension. It is up to you how you want to manage your tags and branches. +Note that these `ref` arguments can be tags, branches, or even specific commits, +which allows users to depend on a specific version of your extension. It is up +to you how you want to manage your tags and branches. ### Example releasing flow using a git repo -While there are many options for how you want to manage releases using a git flow, we recommend treating your default branch as your "stable" release branch. This means that the default behavior for `gemini extensions install ` is to be on the stable release branch. +While there are many options for how you want to manage releases using a git +flow, we recommend treating your default branch as your "stable" release branch. +This means that the default behavior for +`gemini extensions install ` is to be on the stable release +branch. -Lets say you want to maintain three standard release channels, `stable`, `preview`, and `dev`. You would do all your standard development in the `dev` branch. When you are ready to do a preview release, you merge that branch into your `preview` branch. When you are ready to promote your preview branch to stable, you merge `preview` into your stable branch (which might be your default branch or a different branch). +Lets say you want to maintain three standard release channels, `stable`, +`preview`, and `dev`. You would do all your standard development in the `dev` +branch. When you are ready to do a preview release, you merge that branch into +your `preview` branch. When you are ready to promote your preview branch to +stable, you merge `preview` into your stable branch (which might be your default +branch or a different branch). -You can also cherry pick changes from one branch into another using `git cherry-pick`, but do note that this will result in your branches having a slightly divergent history from each other, unless you force push changes to your branches on each release to restore the history to a clean slate (which may not be possible for the default branch depending on your repository settings). If you plan on doing cherry picks, you may want to avoid having your default branch be the stable branch to avoid force-pushing to the default branch which should generally be avoided. +You can also cherry pick changes from one branch into another using +`git cherry-pick`, but do note that this will result in your branches having a +slightly divergent history from each other, unless you force push changes to +your branches on each release to restore the history to a clean slate (which may +not be possible for the default branch depending on your repository settings). +If you plan on doing cherry picks, you may want to avoid having your default +branch be the stable branch to avoid force-pushing to the default branch which +should generally be avoided. ## Releasing through Github releases -Gemini CLI extensions can be distributed through [GitHub Releases](https://docs.github.com/en/repositories/releasing-projects-on-github/about-releases). This provides a faster and more reliable initial installation experience for users, as it avoids the need to clone the repository. +Gemini CLI extensions can be distributed through +[GitHub Releases](https://docs.github.com/en/repositories/releasing-projects-on-github/about-releases). +This provides a faster and more reliable initial installation experience for +users, as it avoids the need to clone the repository. -Each release includes at least one archive file, which contains the full contents of the repo at the tag that it was linked to. Releases may also include [pre-built archives](#custom-pre-built-archives) if your extension requires some build step or has platform specific binaries attached to it. +Each release includes at least one archive file, which contains the full +contents of the repo at the tag that it was linked to. Releases may also include +[pre-built archives](#custom-pre-built-archives) if your extension requires some +build step or has platform specific binaries attached to it. -When checking for updates, gemini will just look for the "latest" release on github (you must mark it as such when creating the release), unless the user installed a specific release by passing `--ref=`. +When checking for updates, gemini will just look for the "latest" release on +github (you must mark it as such when creating the release), unless the user +installed a specific release by passing `--ref=`. -You may also install extensions with the `--pre-release` flag in order to get the latest release regardless of whether it has been marked as "latest". This allows you to test that your release works before actually pushing it to all users. +You may also install extensions with the `--pre-release` flag in order to get +the latest release regardless of whether it has been marked as "latest". This +allows you to test that your release works before actually pushing it to all +users. ### Custom pre-built archives -Custom archives must be attached directly to the github release as assets and must be fully self-contained. This means they should include the entire extension, see [archive structure](#archive-structure). +Custom archives must be attached directly to the github release as assets and +must be fully self-contained. This means they should include the entire +extension, see [archive structure](#archive-structure). -If your extension is platform-independent, you can provide a single generic asset. In this case, there should be only one asset attached to the release. +If your extension is platform-independent, you can provide a single generic +asset. In this case, there should be only one asset attached to the release. -Custom archives may also be used if you want to develop your extension within a larger repository, you can build an archive which has a different layout from the repo itself (for instance it might just be an archive of a subdirectory containing the extension). +Custom archives may also be used if you want to develop your extension within a +larger repository, you can build an archive which has a different layout from +the repo itself (for instance it might just be an archive of a subdirectory +containing the extension). #### Platform specific archives -To ensure Gemini CLI can automatically find the correct release asset for each platform, you must follow this naming convention. The CLI will search for assets in the following order: +To ensure Gemini CLI can automatically find the correct release asset for each +platform, you must follow this naming convention. The CLI will search for assets +in the following order: -1. **Platform and Architecture-Specific:** `{platform}.{arch}.{name}.{extension}` +1. **Platform and Architecture-Specific:** + `{platform}.{arch}.{name}.{extension}` 2. **Platform-Specific:** `{platform}.{name}.{extension}` -3. **Generic:** If only one asset is provided, it will be used as a generic fallback. +3. **Generic:** If only one asset is provided, it will be used as a generic + fallback. - `{name}`: The name of your extension. - `{platform}`: The operating system. Supported values are: @@ -74,13 +132,17 @@ To ensure Gemini CLI can automatically find the correct release asset for each p #### Archive structure -Archives must be fully contained extensions and have all the standard requirements - specifically the `gemini-extension.json` file must be at the root of the archive. +Archives must be fully contained extensions and have all the standard +requirements - specifically the `gemini-extension.json` file must be at the root +of the archive. -The rest of the layout should look exactly the same as a typical extension, see [extensions.md](./index.md). +The rest of the layout should look exactly the same as a typical extension, see +[extensions.md](./index.md). #### Example GitHub Actions workflow -Here is an example of a GitHub Actions workflow that builds and releases a Gemini CLI extension for multiple platforms: +Here is an example of a GitHub Actions workflow that builds and releases a +Gemini CLI extension for multiple platforms: ```yaml name: Release Extension diff --git a/docs/extensions/getting-started-extensions.md b/docs/extensions/getting-started-extensions.md index f8f7f34870..7c6fb566a7 100644 --- a/docs/extensions/getting-started-extensions.md +++ b/docs/extensions/getting-started-extensions.md @@ -1,16 +1,22 @@ # Getting Started with Gemini CLI Extensions -This guide will walk you through creating your first Gemini CLI extension. You'll learn how to set up a new extension, add a custom tool via an MCP server, create a custom command, and provide context to the model with a `GEMINI.md` file. +This guide will walk you through creating your first Gemini CLI extension. +You'll learn how to set up a new extension, add a custom tool via an MCP server, +create a custom command, and provide context to the model with a `GEMINI.md` +file. ## Prerequisites -Before you start, make sure you have the Gemini CLI installed and a basic understanding of Node.js and TypeScript. +Before you start, make sure you have the Gemini CLI installed and a basic +understanding of Node.js and TypeScript. ## Step 1: Create a New Extension -The easiest way to start is by using one of the built-in templates. We'll use the `mcp-server` example as our foundation. +The easiest way to start is by using one of the built-in templates. We'll use +the `mcp-server` example as our foundation. -Run the following command to create a new directory called `my-first-extension` with the template files: +Run the following command to create a new directory called `my-first-extension` +with the template files: ```bash gemini extensions new my-first-extension mcp-server @@ -32,7 +38,8 @@ Let's look at the key files in your new extension. ### `gemini-extension.json` -This is the manifest file for your extension. It tells Gemini CLI how to load and use your extension. +This is the manifest file for your extension. It tells Gemini CLI how to load +and use your extension. ```json { @@ -50,12 +57,17 @@ This is the manifest file for your extension. It tells Gemini CLI how to load an - `name`: The unique name for your extension. - `version`: The version of your extension. -- `mcpServers`: This section defines one or more Model Context Protocol (MCP) servers. MCP servers are how you can add new tools for the model to use. - - `command`, `args`, `cwd`: These fields specify how to start your server. Notice the use of the `${extensionPath}` variable, which Gemini CLI replaces with the absolute path to your extension's installation directory. This allows your extension to work regardless of where it's installed. +- `mcpServers`: This section defines one or more Model Context Protocol (MCP) + servers. MCP servers are how you can add new tools for the model to use. + - `command`, `args`, `cwd`: These fields specify how to start your server. + Notice the use of the `${extensionPath}` variable, which Gemini CLI replaces + with the absolute path to your extension's installation directory. This + allows your extension to work regardless of where it's installed. ### `example.ts` -This file contains the source code for your MCP server. It's a simple Node.js server that uses the `@modelcontextprotocol/sdk`. +This file contains the source code for your MCP server. It's a simple Node.js +server that uses the `@modelcontextprotocol/sdk`. ```typescript /** @@ -103,15 +115,19 @@ const transport = new StdioServerTransport(); await server.connect(transport); ``` -This server defines a single tool called `fetch_posts` that fetches data from a public API. +This server defines a single tool called `fetch_posts` that fetches data from a +public API. ### `package.json` and `tsconfig.json` -These are standard configuration files for a TypeScript project. The `package.json` file defines dependencies and a `build` script, and `tsconfig.json` configures the TypeScript compiler. +These are standard configuration files for a TypeScript project. The +`package.json` file defines dependencies and a `build` script, and +`tsconfig.json` configures the TypeScript compiler. ## Step 3: Build and Link Your Extension -Before you can use the extension, you need to compile the TypeScript code and link the extension to your Gemini CLI installation for local development. +Before you can use the extension, you need to compile the TypeScript code and +link the extension to your Gemini CLI installation for local development. 1. **Install dependencies:** @@ -126,21 +142,26 @@ Before you can use the extension, you need to compile the TypeScript code and li npm run build ``` - This will compile `example.ts` into `dist/example.js`, which is the file referenced in your `gemini-extension.json`. + This will compile `example.ts` into `dist/example.js`, which is the file + referenced in your `gemini-extension.json`. 3. **Link the extension:** - The `link` command creates a symbolic link from the Gemini CLI extensions directory to your development directory. This means any changes you make will be reflected immediately without needing to reinstall. + The `link` command creates a symbolic link from the Gemini CLI extensions + directory to your development directory. This means any changes you make + will be reflected immediately without needing to reinstall. ```bash gemini extensions link . ``` -Now, restart your Gemini CLI session. The new `fetch_posts` tool will be available. You can test it by asking: "fetch posts". +Now, restart your Gemini CLI session. The new `fetch_posts` tool will be +available. You can test it by asking: "fetch posts". ## Step 4: Add a Custom Command -Custom commands provide a way to create shortcuts for complex prompts. Let's add a command that searches for a pattern in your code. +Custom commands provide a way to create shortcuts for complex prompts. Let's add +a command that searches for a pattern in your code. 1. Create a `commands` directory and a subdirectory for your command group: @@ -159,20 +180,26 @@ Custom commands provide a way to create shortcuts for complex prompts. Let's add """ ``` - This command, `/fs:grep-code`, will take an argument, run the `grep` shell command with it, and pipe the results into a prompt for summarization. + This command, `/fs:grep-code`, will take an argument, run the `grep` shell + command with it, and pipe the results into a prompt for summarization. -After saving the file, restart the Gemini CLI. You can now run `/fs:grep-code "some pattern"` to use your new command. +After saving the file, restart the Gemini CLI. You can now run +`/fs:grep-code "some pattern"` to use your new command. ## Step 5: Add a Custom `GEMINI.md` -You can provide persistent context to the model by adding a `GEMINI.md` file to your extension. This is useful for giving the model instructions on how to behave or information about your extension's tools. Note that you may not always need this for extensions built to expose commands and prompts. +You can provide persistent context to the model by adding a `GEMINI.md` file to +your extension. This is useful for giving the model instructions on how to +behave or information about your extension's tools. Note that you may not always +need this for extensions built to expose commands and prompts. 1. Create a file named `GEMINI.md` in the root of your extension directory: ```markdown # My First Extension Instructions - You are an expert developer assistant. When the user asks you to fetch posts, use the `fetch_posts` tool. Be concise in your responses. + You are an expert developer assistant. When the user asks you to fetch + posts, use the `fetch_posts` tool. Be concise in your responses. ``` 2. Update your `gemini-extension.json` to tell the CLI to load this file: @@ -192,13 +219,17 @@ You can provide persistent context to the model by adding a `GEMINI.md` file to } ``` -Restart the CLI again. The model will now have the context from your `GEMINI.md` file in every session where the extension is active. +Restart the CLI again. The model will now have the context from your `GEMINI.md` +file in every session where the extension is active. ## Step 6: Releasing Your Extension -Once you are happy with your extension, you can share it with others. The two primary ways of releasing extensions are via a Git repository or through GitHub Releases. Using a public Git repository is the simplest method. +Once you are happy with your extension, you can share it with others. The two +primary ways of releasing extensions are via a Git repository or through GitHub +Releases. Using a public Git repository is the simplest method. -For detailed instructions on both methods, please refer to the [Extension Releasing Guide](./extension-releasing.md). +For detailed instructions on both methods, please refer to the +[Extension Releasing Guide](./extension-releasing.md). ## Conclusion @@ -210,4 +241,5 @@ You've successfully created a Gemini CLI extension! You learned how to: - Provide persistent context to the model. - Link your extension for local development. -From here, you can explore more advanced features and build powerful new capabilities into the Gemini CLI. +From here, you can explore more advanced features and build powerful new +capabilities into the Gemini CLI. diff --git a/docs/extensions/index.md b/docs/extensions/index.md index dd875e6829..d4f9c1f4c4 100644 --- a/docs/extensions/index.md +++ b/docs/extensions/index.md @@ -2,37 +2,53 @@ _This documentation is up-to-date with the v0.4.0 release._ -Gemini CLI extensions package prompts, MCP servers, and custom commands into a familiar and user-friendly format. With extensions, you can expand the capabilities of Gemini CLI and share those capabilities with others. They are designed to be easily installable and shareable. +Gemini CLI extensions package prompts, MCP servers, and custom commands into a +familiar and user-friendly format. With extensions, you can expand the +capabilities of Gemini CLI and share those capabilities with others. They are +designed to be easily installable and shareable. -See [getting started docs](getting-started-extensions.md) for a guide on creating your first extension. +See [getting started docs](getting-started-extensions.md) for a guide on +creating your first extension. -See [releasing docs](extension-releasing.md) for an advanced guide on setting up GitHub releases. +See [releasing docs](extension-releasing.md) for an advanced guide on setting up +GitHub releases. ## Extension management -We offer a suite of extension management tools using `gemini extensions` commands. +We offer a suite of extension management tools using `gemini extensions` +commands. -Note that these commands are not supported from within the CLI, although you can list installed extensions using the `/extensions list` subcommand. +Note that these commands are not supported from within the CLI, although you can +list installed extensions using the `/extensions list` subcommand. -Note that all of these commands will only be reflected in active CLI sessions on restart. +Note that all of these commands will only be reflected in active CLI sessions on +restart. ### Installing an extension -You can install an extension using `gemini extensions install` with either a GitHub URL or a local path. +You can install an extension using `gemini extensions install` with either a +GitHub URL or a local path. -Note that we create a copy of the installed extension, so you will need to run `gemini extensions update` to pull in changes from both locally-defined extensions and those on GitHub. +Note that we create a copy of the installed extension, so you will need to run +`gemini extensions update` to pull in changes from both locally-defined +extensions and those on GitHub. -NOTE: If you are installing an extension from GitHub, you'll need to have `git` installed on your machine. See [git installation instructions](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) for help. +NOTE: If you are installing an extension from GitHub, you'll need to have `git` +installed on your machine. See +[git installation instructions](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) +for help. ``` gemini extensions install https://github.com/gemini-cli-extensions/security ``` -This will install the Gemini CLI Security extension, which offers support for a `/security:analyze` command. +This will install the Gemini CLI Security extension, which offers support for a +`/security:analyze` command. ### Uninstalling an extension -To uninstall, run `gemini extensions uninstall extension-name`, so, in the case of the install example: +To uninstall, run `gemini extensions uninstall extension-name`, so, in the case +of the install example: ``` gemini extensions uninstall gemini-cli-security @@ -40,19 +56,30 @@ gemini extensions uninstall gemini-cli-security ### Disabling an extension -Extensions are, by default, enabled across all workspaces. You can disable an extension entirely or for specific workspace. +Extensions are, by default, enabled across all workspaces. You can disable an +extension entirely or for specific workspace. -For example, `gemini extensions disable extension-name` will disable the extension at the user level, so it will be disabled everywhere. `gemini extensions disable extension-name --scope=workspace` will only disable the extension in the current workspace. +For example, `gemini extensions disable extension-name` will disable the +extension at the user level, so it will be disabled everywhere. +`gemini extensions disable extension-name --scope=workspace` will only disable +the extension in the current workspace. ### Enabling an extension -You can enable extensions using `gemini extensions enable extension-name`. You can also enable an extension for a specific workspace using `gemini extensions enable extension-name --scope=workspace` from within that workspace. +You can enable extensions using `gemini extensions enable extension-name`. You +can also enable an extension for a specific workspace using +`gemini extensions enable extension-name --scope=workspace` from within that +workspace. -This is useful if you have an extension disabled at the top-level and only enabled in specific places. +This is useful if you have an extension disabled at the top-level and only +enabled in specific places. ### Updating an extension -For extensions installed from a local path or a git repository, you can explicitly update to the latest version (as reflected in the `gemini-extension.json` `version` field) with `gemini extensions update extension-name`. +For extensions installed from a local path or a git repository, you can +explicitly update to the latest version (as reflected in the +`gemini-extension.json` `version` field) with +`gemini extensions update extension-name`. You can update all extensions with: @@ -66,9 +93,12 @@ We offer commands to make extension development easier. ### Create a boilerplate extension -We offer several example extensions `context`, `custom-commands`, `exclude-tools` and `mcp-server`. You can view these examples [here](https://github.com/google-gemini/gemini-cli/tree/main/packages/cli/src/commands/extensions/examples). +We offer several example extensions `context`, `custom-commands`, +`exclude-tools` and `mcp-server`. You can view these examples +[here](https://github.com/google-gemini/gemini-cli/tree/main/packages/cli/src/commands/extensions/examples). -To copy one of these examples into a development directory using the type of your choosing, run: +To copy one of these examples into a development directory using the type of +your choosing, run: ``` gemini extensions new path/to/directory custom-commands @@ -76,9 +106,11 @@ gemini extensions new path/to/directory custom-commands ### Link a local extension -The `gemini extensions link` command will create a symbolic link from the extension installation directory to the development path. +The `gemini extensions link` command will create a symbolic link from the +extension installation directory to the development path. -This is useful so you don't have to run `gemini extensions update` every time you make changes you'd like to test. +This is useful so you don't have to run `gemini extensions update` every time +you make changes you'd like to test. ``` gemini extensions link path/to/directory @@ -88,13 +120,15 @@ gemini extensions link path/to/directory On startup, Gemini CLI looks for extensions in `/.gemini/extensions` -Extensions exist as a directory that contains a `gemini-extension.json` file. For example: +Extensions exist as a directory that contains a `gemini-extension.json` file. +For example: `/.gemini/extensions/my-extension/gemini-extension.json` ### `gemini-extension.json` -The `gemini-extension.json` file contains the configuration for the extension. The file has the following structure: +The `gemini-extension.json` file contains the configuration for the extension. +The file has the following structure: ```json { @@ -110,18 +144,42 @@ The `gemini-extension.json` file contains the configuration for the extension. T } ``` -- `name`: The name of the extension. This is used to uniquely identify the extension and for conflict resolution when extension commands have the same name as user or project commands. The name should be lowercase or numbers and use dashes instead of underscores or spaces. This is how users will refer to your extension in the CLI. Note that we expect this name to match the extension directory name. +- `name`: The name of the extension. This is used to uniquely identify the + extension and for conflict resolution when extension commands have the same + name as user or project commands. The name should be lowercase or numbers and + use dashes instead of underscores or spaces. This is how users will refer to + your extension in the CLI. Note that we expect this name to match the + extension directory name. - `version`: The version of the extension. -- `mcpServers`: A map of MCP servers to configure. The key is the name of the server, and the value is the server configuration. These servers will be loaded on startup just like MCP servers configured in a [`settings.json` file](../get-started/configuration.md). If both an extension and a `settings.json` file configure an MCP server with the same name, the server defined in the `settings.json` file takes precedence. - - Note that all MCP server configuration options are supported except for `trust`. -- `contextFileName`: The name of the file that contains the context for the extension. This will be used to load the context from the extension directory. If this property is not used but a `GEMINI.md` file is present in your extension directory, then that file will be loaded. -- `excludeTools`: An array of tool names to exclude from the model. You can also specify command-specific restrictions for tools that support it, like the `run_shell_command` tool. For example, `"excludeTools": ["run_shell_command(rm -rf)"]` will block the `rm -rf` command. Note that this differs from the MCP server `excludeTools` functionality, which can be listed in the MCP server config. +- `mcpServers`: A map of MCP servers to configure. The key is the name of the + server, and the value is the server configuration. These servers will be + loaded on startup just like MCP servers configured in a + [`settings.json` file](../get-started/configuration.md). If both an extension + and a `settings.json` file configure an MCP server with the same name, the + server defined in the `settings.json` file takes precedence. + - Note that all MCP server configuration options are supported except for + `trust`. +- `contextFileName`: The name of the file that contains the context for the + extension. This will be used to load the context from the extension directory. + If this property is not used but a `GEMINI.md` file is present in your + extension directory, then that file will be loaded. +- `excludeTools`: An array of tool names to exclude from the model. You can also + specify command-specific restrictions for tools that support it, like the + `run_shell_command` tool. For example, + `"excludeTools": ["run_shell_command(rm -rf)"]` will block the `rm -rf` + command. Note that this differs from the MCP server `excludeTools` + functionality, which can be listed in the MCP server config. -When Gemini CLI starts, it loads all the extensions and merges their configurations. If there are any conflicts, the workspace configuration takes precedence. +When Gemini CLI starts, it loads all the extensions and merges their +configurations. If there are any conflicts, the workspace configuration takes +precedence. ### Custom commands -Extensions can provide [custom commands](../cli/custom-commands.md) by placing TOML files in a `commands/` subdirectory within the extension directory. These commands follow the same format as user and project custom commands and use standard naming conventions. +Extensions can provide [custom commands](../cli/custom-commands.md) by placing +TOML files in a `commands/` subdirectory within the extension directory. These +commands follow the same format as user and project custom commands and use +standard naming conventions. **Example** @@ -143,19 +201,24 @@ Would provide these commands: ### Conflict resolution -Extension commands have the lowest precedence. When a conflict occurs with user or project commands: +Extension commands have the lowest precedence. When a conflict occurs with user +or project commands: 1. **No conflict**: Extension command uses its natural name (e.g., `/deploy`) -2. **With conflict**: Extension command is renamed with the extension prefix (e.g., `/gcp.deploy`) +2. **With conflict**: Extension command is renamed with the extension prefix + (e.g., `/gcp.deploy`) For example, if both a user and the `gcp` extension define a `deploy` command: - `/deploy` - Executes the user's deploy command -- `/gcp.deploy` - Executes the extension's deploy command (marked with `[gcp]` tag) +- `/gcp.deploy` - Executes the extension's deploy command (marked with `[gcp]` + tag) ## Variables -Gemini CLI extensions allow variable substitution in `gemini-extension.json`. This can be useful if e.g., you need the current directory to run an MCP server using `"cwd": "${extensionPath}${/}run.ts"`. +Gemini CLI extensions allow variable substitution in `gemini-extension.json`. +This can be useful if e.g., you need the current directory to run an MCP server +using `"cwd": "${extensionPath}${/}run.ts"`. **Supported variables:** diff --git a/docs/faq.md b/docs/faq.md index f8039d9b23..11da9a6e77 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -1,50 +1,71 @@ # Frequently Asked Questions (FAQ) -This page provides answers to common questions and solutions to frequent problems encountered while using Gemini CLI. +This page provides answers to common questions and solutions to frequent +problems encountered while using Gemini CLI. ## General issues ### Why am I getting an `API error: 429 - Resource exhausted`? -This error indicates that you have exceeded your API request limit. The Gemini API has rate limits to prevent abuse and ensure fair usage. +This error indicates that you have exceeded your API request limit. The Gemini +API has rate limits to prevent abuse and ensure fair usage. To resolve this, you can: -- **Check your usage:** Review your API usage in the Google AI Studio or your Google Cloud project dashboard. -- **Optimize your prompts:** If you are making many requests in a short period, try to batch your prompts or introduce delays between requests. -- **Request a quota increase:** If you consistently need a higher limit, you can request a quota increase from Google. +- **Check your usage:** Review your API usage in the Google AI Studio or your + Google Cloud project dashboard. +- **Optimize your prompts:** If you are making many requests in a short period, + try to batch your prompts or introduce delays between requests. +- **Request a quota increase:** If you consistently need a higher limit, you can + request a quota increase from Google. ### Why am I getting an `ERR_REQUIRE_ESM` error when running `npm run start`? -This error typically occurs in Node.js projects when there is a mismatch between CommonJS and ES Modules. +This error typically occurs in Node.js projects when there is a mismatch between +CommonJS and ES Modules. -This is often due to a misconfiguration in your `package.json` or `tsconfig.json`. Ensure that: +This is often due to a misconfiguration in your `package.json` or +`tsconfig.json`. Ensure that: 1. Your `package.json` has `"type": "module"`. -2. Your `tsconfig.json` has `"module": "NodeNext"` or a compatible setting in the `compilerOptions`. +2. Your `tsconfig.json` has `"module": "NodeNext"` or a compatible setting in + the `compilerOptions`. -If the problem persists, try deleting your `node_modules` directory and `package-lock.json` file, and then run `npm install` again. +If the problem persists, try deleting your `node_modules` directory and +`package-lock.json` file, and then run `npm install` again. ### Why don't I see cached token counts in my stats output? -Cached token information is only displayed when cached tokens are being used. This feature is available for API key users (Gemini API key or Google Cloud Vertex AI) but not for OAuth users (such as Google Personal/Enterprise accounts like Google Gmail or Google Workspace, respectively). This is because the Gemini Code Assist API does not support cached content creation. You can still view your total token usage using the `/stats` command in Gemini CLI. +Cached token information is only displayed when cached tokens are being used. +This feature is available for API key users (Gemini API key or Google Cloud +Vertex AI) but not for OAuth users (such as Google Personal/Enterprise accounts +like Google Gmail or Google Workspace, respectively). This is because the Gemini +Code Assist API does not support cached content creation. You can still view +your total token usage using the `/stats` command in Gemini CLI. ## Installation and updates ### How do I update Gemini CLI to the latest version? -If you installed it globally via `npm`, update it using the command `npm install -g @google/gemini-cli@latest`. If you compiled it from source, pull the latest changes from the repository, and then rebuild using the command `npm run build`. +If you installed it globally via `npm`, update it using the command +`npm install -g @google/gemini-cli@latest`. If you compiled it from source, pull +the latest changes from the repository, and then rebuild using the command +`npm run build`. ## Platform-specific issues ### Why does the CLI crash on Windows when I run a command like `chmod +x`? -Commands like `chmod` are specific to Unix-like operating systems (Linux, macOS). They are not available on Windows by default. +Commands like `chmod` are specific to Unix-like operating systems (Linux, +macOS). They are not available on Windows by default. To resolve this, you can: -- **Use Windows-equivalent commands:** Instead of `chmod`, you can use `icacls` to modify file permissions on Windows. -- **Use a compatibility layer:** Tools like Git Bash or Windows Subsystem for Linux (WSL) provide a Unix-like environment on Windows where these commands will work. +- **Use Windows-equivalent commands:** Instead of `chmod`, you can use `icacls` + to modify file permissions on Windows. +- **Use a compatibility layer:** Tools like Git Bash or Windows Subsystem for + Linux (WSL) provide a Unix-like environment on Windows where these commands + will work. ## Configuration @@ -58,16 +79,23 @@ Set the `GOOGLE_CLOUD_PROJECT` environment variable in your shell: export GOOGLE_CLOUD_PROJECT="your-project-id" ``` -To make this setting permanent, add this line to your shell's startup file (e.g., `~/.bashrc`, `~/.zshrc`). +To make this setting permanent, add this line to your shell's startup file +(e.g., `~/.bashrc`, `~/.zshrc`). ### What is the best way to store my API keys securely? -Exposing API keys in scripts or checking them into source control is a security risk. +Exposing API keys in scripts or checking them into source control is a security +risk. To store your API keys securely, you can: -- **Use a `.env` file:** Create a `.env` file in your project's `.gemini` directory (`.gemini/.env`) and store your keys there. Gemini CLI will automatically load these variables. -- **Use your system's keyring:** For the most secure storage, use your operating system's secret management tool (like macOS Keychain, Windows Credential Manager, or a secret manager on Linux). You can then have your scripts or environment load the key from the secure storage at runtime. +- **Use a `.env` file:** Create a `.env` file in your project's `.gemini` + directory (`.gemini/.env`) and store your keys there. Gemini CLI will + automatically load these variables. +- **Use your system's keyring:** For the most secure storage, use your operating + system's secret management tool (like macOS Keychain, Windows Credential + Manager, or a secret manager on Linux). You can then have your scripts or + environment load the key from the secure storage at runtime. ### Where are the Gemini CLI configuration and settings files stored? @@ -76,30 +104,51 @@ The Gemini CLI configuration is stored in two `settings.json` files: 1. In your home directory: `~/.gemini/settings.json`. 2. In your project's root directory: `./.gemini/settings.json`. -Refer to [Gemini CLI Configuration](./get-started/configuration.md) for more details. +Refer to [Gemini CLI Configuration](./get-started/configuration.md) for more +details. ## Google AI Pro/Ultra and subscription FAQs ### Where can I learn more about my Google AI Pro or Google AI Ultra subscription? -To learn more about your Google AI Pro or Google AI Ultra subscription, visit **Manage subscription** in your [subscription settings](https://one.google.com). +To learn more about your Google AI Pro or Google AI Ultra subscription, visit +**Manage subscription** in your [subscription settings](https://one.google.com). ### How do I know if I have higher limits for Google AI Pro or Ultra? -If you're subscribed to Google AI Pro or Ultra, you automatically have higher limits to Gemini Code Assist and Gemini CLI. These are shared across Gemini CLI and agent mode in the IDE. You can confirm you have higher limits by checking if you are still subscribed to Google AI Pro or Ultra in your [subscription settings](https://one.google.com). +If you're subscribed to Google AI Pro or Ultra, you automatically have higher +limits to Gemini Code Assist and Gemini CLI. These are shared across Gemini CLI +and agent mode in the IDE. You can confirm you have higher limits by checking if +you are still subscribed to Google AI Pro or Ultra in your +[subscription settings](https://one.google.com). ### What is the privacy policy for using Gemini Code Assist or Gemini CLI if I've subscribed to Google AI Pro or Ultra? -To learn more about your privacy policy and terms of service governed by your subscription, visit [Gemini Code Assist: Terms of Service and Privacy Policies](https://developers.google.com/gemini-code-assist/resources/privacy-notices). +To learn more about your privacy policy and terms of service governed by your +subscription, visit +[Gemini Code Assist: Terms of Service and Privacy Policies](https://developers.google.com/gemini-code-assist/resources/privacy-notices). ### I've upgraded to Google AI Pro or Ultra but it still says I am hitting quota limits. Is this a bug? -The higher limits in your Google AI Pro or Ultra subscription are for Gemini 2.5 across both Gemini 2.5 Pro and Flash. They are shared quota across Gemini CLI and agent mode in Gemini Code Assist IDE extensions. You can learn more about quota limits for Gemini CLI, Gemini Code Assist and agent mode in Gemini Code Assist at [Quotas and limits](https://developers.google.com/gemini-code-assist/resources/quotas). +The higher limits in your Google AI Pro or Ultra subscription are for Gemini 2.5 +across both Gemini 2.5 Pro and Flash. They are shared quota across Gemini CLI +and agent mode in Gemini Code Assist IDE extensions. You can learn more about +quota limits for Gemini CLI, Gemini Code Assist and agent mode in Gemini Code +Assist at +[Quotas and limits](https://developers.google.com/gemini-code-assist/resources/quotas). ### If I upgrade to higher limits for Gemini CLI and Gemini Code Assist by purchasing a Google AI Pro or Ultra subscription, will Gemini start using my data to improve its machine learning models? -Google does not use your data to improve Google's machine learning models if you purchase a paid plan. Note: If you decide to remain on the free version of Gemini Code Assist, Gemini Code Assist for individuals, you can also opt out of using your data to improve Google's machine learning models. See the [Gemini Code Assist for individuals privacy notice](https://developers.google.com/gemini-code-assist/resources/privacy-notice-gemini-code-assist-individuals) for more information. +Google does not use your data to improve Google's machine learning models if you +purchase a paid plan. Note: If you decide to remain on the free version of +Gemini Code Assist, Gemini Code Assist for individuals, you can also opt out of +using your data to improve Google's machine learning models. See the +[Gemini Code Assist for individuals privacy notice](https://developers.google.com/gemini-code-assist/resources/privacy-notice-gemini-code-assist-individuals) +for more information. ## Not seeing your question? -Search the [Gemini CLI Q&A discussions on GitHub](https://github.com/google-gemini/gemini-cli/discussions/categories/q-a) or [start a new discussion on GitHub](https://github.com/google-gemini/gemini-cli/discussions/new?category=q-a) +Search the +[Gemini CLI Q&A discussions on GitHub](https://github.com/google-gemini/gemini-cli/discussions/categories/q-a) +or +[start a new discussion on GitHub](https://github.com/google-gemini/gemini-cli/discussions/new?category=q-a) diff --git a/docs/get-started/authentication.md b/docs/get-started/authentication.md index bd0a2d6f39..712d6ee065 100644 --- a/docs/get-started/authentication.md +++ b/docs/get-started/authentication.md @@ -1,6 +1,7 @@ # Gemini CLI Authentication Setup -Gemini CLI requires authentication using Google's services. Before using Gemini CLI, configure **one** of the following authentication methods: +Gemini CLI requires authentication using Google's services. Before using Gemini +CLI, configure **one** of the following authentication methods: - Interactive mode: - Recommended: Login with Google @@ -11,11 +12,13 @@ Gemini CLI requires authentication using Google's services. Before using Gemini ## Quick Check: Running in Google Cloud Shell? -If you are running the Gemini CLI within a Google Cloud Shell environment, authentication is typically automatic using your Cloud Shell credentials. +If you are running the Gemini CLI within a Google Cloud Shell environment, +authentication is typically automatic using your Cloud Shell credentials. ## Authenticate in Interactive mode -When you run Gemini CLI through the command-line, Gemini CLI will provide the following options: +When you run Gemini CLI through the command-line, Gemini CLI will provide the +following options: ```bash > 1. Login with Google @@ -23,32 +26,44 @@ When you run Gemini CLI through the command-line, Gemini CLI will provide the fo > 3. Vertex AI ``` -The following sections provide instructions for each of these authentication options. +The following sections provide instructions for each of these authentication +options. ### Recommended: Login with Google -If you are running Gemini CLI on your local machine, the simplest method is logging in with your Google account. +If you are running Gemini CLI on your local machine, the simplest method is +logging in with your Google account. -> **Important:** Use this method if you are a **Google AI Pro** or **Google AI Ultra** subscriber. +> **Important:** Use this method if you are a **Google AI Pro** or **Google AI +> Ultra** subscriber. -1. Select **Login with Google**. Gemini CLI will open a login prompt using your web browser. +1. Select **Login with Google**. Gemini CLI will open a login prompt using your + web browser. - If you are a **Google AI Pro** or **Google AI Ultra** subscriber, login with the Google account associated with your subscription. + If you are a **Google AI Pro** or **Google AI Ultra** subscriber, login with + the Google account associated with your subscription. -2. Follow the on-screen instructions. Your credentials will be cached locally for future sessions. +2. Follow the on-screen instructions. Your credentials will be cached locally + for future sessions. - > **Note:** This method requires a web browser on a machine that can communicate with the terminal running the CLI (e.g., your local machine). The browser will be redirected to a `localhost` URL that the CLI listens on during setup. + > **Note:** This method requires a web browser on a machine that can + > communicate with the terminal running the CLI (e.g., your local machine). + > The browser will be redirected to a `localhost` URL that the CLI listens on + > during setup. #### (Optional) Set your Google Cloud Project -When you log in using a Google account, you may be prompted to select a `GOOGLE_CLOUD_PROJECT`. +When you log in using a Google account, you may be prompted to select a +`GOOGLE_CLOUD_PROJECT`. This can be necessary if you are: - Using a Google Workspace account. - Using a Gemini Code Assist license from the Google Developer Program. - Using a license from a Gemini Code Assist subscription. -- Using the product outside the [supported regions](https://developers.google.com/gemini-code-assist/resources/available-locations) for free individual usage. +- Using the product outside the + [supported regions](https://developers.google.com/gemini-code-assist/resources/available-locations) + for free individual usage. - A Google account holder under the age of 18. If you fall into one of these categories, you must: @@ -57,7 +72,9 @@ If you fall into one of these categories, you must: 2. [Enable the Gemini for Cloud API](https://cloud.google.com/gemini/docs/discover/set-up-gemini#enable-api). 3. [Configure necessary IAM access permissions](https://cloud.google.com/gemini/docs/discover/set-up-gemini#grant-iam). -To set the project ID, you can export either the `GOOGLE_CLOUD_PROJECT` or `GOOGLE_CLOUD_PROJECT_ID` environment variable. The CLI checks for `GOOGLE_CLOUD_PROJECT` first, then falls back to `GOOGLE_CLOUD_PROJECT_ID` : +To set the project ID, you can export either the `GOOGLE_CLOUD_PROJECT` or +`GOOGLE_CLOUD_PROJECT_ID` environment variable. The CLI checks for +`GOOGLE_CLOUD_PROJECT` first, then falls back to `GOOGLE_CLOUD_PROJECT_ID` : ```bash # Replace YOUR_PROJECT_ID with your actual Google Cloud Project ID @@ -68,13 +85,16 @@ export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID" export GOOGLE_CLOUD_PROJECT_ID="YOUR_PROJECT_ID" ``` -To make this setting persistent, see [Persisting Environment Variables](#persisting-environment-variables). +To make this setting persistent, see +[Persisting Environment Variables](#persisting-environment-variables). ### Use Gemini API Key -If you don't want to authenticate using your Google account, you can use an API key from Google AI Studio. +If you don't want to authenticate using your Google account, you can use an API +key from Google AI Studio. -1. Obtain your API key from [Google AI Studio](https://aistudio.google.com/app/apikey). +1. Obtain your API key from + [Google AI Studio](https://aistudio.google.com/app/apikey). 2. Set the `GEMINI_API_KEY` environment variable: ```bash @@ -82,13 +102,17 @@ If you don't want to authenticate using your Google account, you can use an API export GEMINI_API_KEY="YOUR_GEMINI_API_KEY" ``` -To make this setting persistent, see [Persisting Environment Variables](#persisting-environment-variables). +To make this setting persistent, see +[Persisting Environment Variables](#persisting-environment-variables). -> **Warning:** Treat API keys, especially for services like Gemini, as sensitive credentials. Protect them to prevent unauthorized access and potential misuse of the service under your account. +> **Warning:** Treat API keys, especially for services like Gemini, as sensitive +> credentials. Protect them to prevent unauthorized access and potential misuse +> of the service under your account. ### Use Vertex AI -If you intend to use Google Cloud's Vertex AI platform, you have several authentication options: +If you intend to use Google Cloud's Vertex AI platform, you have several +authentication options: - Application Default Credentials (ADC) and `gcloud`. - A Service Account JSON key. @@ -96,7 +120,9 @@ If you intend to use Google Cloud's Vertex AI platform, you have several authent #### First: Set required environment variables -Regardless of your method of authentication, you'll typically need to set the following variables: `GOOGLE_CLOUD_PROJECT` (or `GOOGLE_CLOUD_PROJECT_ID`) and `GOOGLE_CLOUD_LOCATION`. +Regardless of your method of authentication, you'll typically need to set the +following variables: `GOOGLE_CLOUD_PROJECT` (or `GOOGLE_CLOUD_PROJECT_ID`) and +`GOOGLE_CLOUD_LOCATION`. To set these variables: @@ -111,7 +137,8 @@ export GOOGLE_CLOUD_LOCATION="YOUR_PROJECT_LOCATION" Consider this method of authentication if you have Google Cloud CLI installed. -> **Note:** If you have previously set `GOOGLE_API_KEY` or `GEMINI_API_KEY`, you must unset them to use ADC: +> **Note:** If you have previously set `GOOGLE_API_KEY` or `GEMINI_API_KEY`, you +> must unset them to use ADC: ```bash unset GOOGLE_API_KEY GEMINI_API_KEY @@ -124,35 +151,46 @@ unset GOOGLE_API_KEY GEMINI_API_KEY gcloud auth application-default login ``` - See [Set up Application Default Credentials](https://cloud.google.com/docs/authentication/provide-credentials-adc) for details. + See + [Set up Application Default Credentials](https://cloud.google.com/docs/authentication/provide-credentials-adc) + for details. -3. Ensure `GOOGLE_CLOUD_PROJECT` (or `GOOGLE_CLOUD_PROJECT_ID`) and `GOOGLE_CLOUD_LOCATION` are set. +3. Ensure `GOOGLE_CLOUD_PROJECT` (or `GOOGLE_CLOUD_PROJECT_ID`) and + `GOOGLE_CLOUD_LOCATION` are set. #### B. Vertex AI - Service Account JSON key -Consider this method of authentication in non-interactive environments, CI/CD, or if your organization restricts user-based ADC or API key creation. +Consider this method of authentication in non-interactive environments, CI/CD, +or if your organization restricts user-based ADC or API key creation. -> **Note:** If you have previously set `GOOGLE_API_KEY` or `GEMINI_API_KEY`, you must unset them: +> **Note:** If you have previously set `GOOGLE_API_KEY` or `GEMINI_API_KEY`, you +> must unset them: ```bash unset GOOGLE_API_KEY GEMINI_API_KEY ``` -1. [Create a service account and key](https://cloud.google.com/iam/docs/keys-create-delete) and download the provided JSON file. Assign the "Vertex AI User" role to the service account. -2. Set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to the JSON file's absolute path: +1. [Create a service account and key](https://cloud.google.com/iam/docs/keys-create-delete) + and download the provided JSON file. Assign the "Vertex AI User" role to the + service account. +2. Set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to the JSON + file's absolute path: ```bash # Replace /path/to/your/keyfile.json with the actual path export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/keyfile.json" ``` -3. Ensure `GOOGLE_CLOUD_PROJECT` (or `GOOGLE_CLOUD_PROJECT_ID`) and `GOOGLE_CLOUD_LOCATION` are set. +3. Ensure `GOOGLE_CLOUD_PROJECT` (or `GOOGLE_CLOUD_PROJECT_ID`) and + `GOOGLE_CLOUD_LOCATION` are set. -> **Warning:** Protect your service account key file as it provides access to your resources. +> **Warning:** Protect your service account key file as it provides access to +> your resources. #### C. Vertex AI - Google Cloud API key -1. Obtain a Google Cloud API key: [Get an API Key](https://cloud.google.com/vertex-ai/generative-ai/docs/start/api-keys?usertype=newuser). +1. Obtain a Google Cloud API key: + [Get an API Key](https://cloud.google.com/vertex-ai/generative-ai/docs/start/api-keys?usertype=newuser). 2. Set the `GOOGLE_API_KEY` environment variable: ```bash @@ -160,15 +198,24 @@ unset GOOGLE_API_KEY GEMINI_API_KEY export GOOGLE_API_KEY="YOUR_GOOGLE_API_KEY" ``` - > **Note:** If you see errors like `"API keys are not supported by this API..."`, your organization might restrict API key usage for this service. Try the [Service Account JSON Key](#b-vertex-ai-service-account-json-key) or [ADC](#a-vertex-ai-application-default-credentials-adc-using-gcloud) methods instead. + > **Note:** If you see errors like + > `"API keys are not supported by this API..."`, your organization might + > restrict API key usage for this service. Try the + > [Service Account JSON Key](#b-vertex-ai-service-account-json-key) or + > [ADC](#a-vertex-ai-application-default-credentials-adc-using-gcloud) + > methods instead. -To make any of these Vertex AI environment variable settings persistent, see [Persisting Environment Variables](#persisting-environment-variables). +To make any of these Vertex AI environment variable settings persistent, see +[Persisting Environment Variables](#persisting-environment-variables). ## Persisting Environment Variables To avoid setting environment variables in every terminal session, you can: -1. **Add your environment variables to your shell configuration file:** Append the `export ...` commands to your shell's startup file (e.g., `~/.bashrc`, `~/.zshrc`, or `~/.profile`) and reload your shell (e.g., `source ~/.bashrc`). +1. **Add your environment variables to your shell configuration file:** Append + the `export ...` commands to your shell's startup file (e.g., `~/.bashrc`, + `~/.zshrc`, or `~/.profile`) and reload your shell (e.g., + `source ~/.bashrc`). ```bash # Example for .bashrc @@ -176,9 +223,14 @@ To avoid setting environment variables in every terminal session, you can: source ~/.bashrc ``` - > **Warning:** Be advised that when you export API keys or service account paths in your shell configuration file, any process executed from the shell can potentially read them. + > **Warning:** Be advised that when you export API keys or service account + > paths in your shell configuration file, any process executed from the + > shell can potentially read them. -2. **Use a `.env` file:** Create a `.gemini/.env` file in your project directory or home directory. Gemini CLI automatically loads variables from the first `.env` file it finds, searching up from the current directory, then in `~/.gemini/.env` or `~/.env`. `.gemini/.env` is recommended. +2. **Use a `.env` file:** Create a `.gemini/.env` file in your project + directory or home directory. Gemini CLI automatically loads variables from + the first `.env` file it finds, searching up from the current directory, + then in `~/.gemini/.env` or `~/.env`. `.gemini/.env` is recommended. Example for user-wide settings: @@ -194,21 +246,28 @@ To avoid setting environment variables in every terminal session, you can: ## Non-interactive mode / headless environments -Non-interative mode / headless environments will use your existing authentication method, if an existing authentication credential is cached. +Non-interative mode / headless environments will use your existing +authentication method, if an existing authentication credential is cached. -If you have not already logged in with an authentication credential (such as a Google account), you **must** configure authentication using environment variables: +If you have not already logged in with an authentication credential (such as a +Google account), you **must** configure authentication using environment +variables: 1. **Gemini API Key:** Set `GEMINI_API_KEY`. 2. **Vertex AI:** - Set `GOOGLE_GENAI_USE_VERTEXAI=true`. - **With Google Cloud API Key:** Set `GOOGLE_API_KEY`. - - **With ADC:** Ensure ADC is configured (e.g., via a service account with `GOOGLE_APPLICATION_CREDENTIALS`) and set `GOOGLE_CLOUD_PROJECT` (or `GOOGLE_CLOUD_PROJECT_ID`) and `GOOGLE_CLOUD_LOCATION`. + - **With ADC:** Ensure ADC is configured (e.g., via a service account with + `GOOGLE_APPLICATION_CREDENTIALS`) and set `GOOGLE_CLOUD_PROJECT` (or + `GOOGLE_CLOUD_PROJECT_ID`) and `GOOGLE_CLOUD_LOCATION`. -The CLI will exit with an error in non-interactive mode if no suitable environment variables are found. +The CLI will exit with an error in non-interactive mode if no suitable +environment variables are found. ## What's next? -Your authentication method affects your quotas, pricing, Terms of Service, and privacy notices. Review the following pages to learn more: +Your authentication method affects your quotas, pricing, Terms of Service, and +privacy notices. Review the following pages to learn more: - [Gemini CLI: Quotas and Pricing](../quota-and-pricing.md). - [Gemini CLI: Terms of Service and Privacy Notice](../tos-privacy.md). diff --git a/docs/get-started/configuration-v1.md b/docs/get-started/configuration-v1.md index c0d573f116..57b7014b77 100644 --- a/docs/get-started/configuration-v1.md +++ b/docs/get-started/configuration-v1.md @@ -2,66 +2,105 @@ **Note on Deprecated Configuration Format** -This document describes the legacy v1 format for the `settings.json` file. This format is now deprecated. +This document describes the legacy v1 format for the `settings.json` file. This +format is now deprecated. -- The new format will be supported in the stable release starting **[09/10/25]**. -- Automatic migration from the old format to the new format will begin on **[09/17/25]**. +- The new format will be supported in the stable release starting + **[09/10/25]**. +- Automatic migration from the old format to the new format will begin on + **[09/17/25]**. -For details on the new, recommended format, please see the [current Configuration documentation](./configuration.md). +For details on the new, recommended format, please see the +[current Configuration documentation](./configuration.md). -Gemini CLI offers several ways to configure its behavior, including environment variables, command-line arguments, and settings files. This document outlines the different configuration methods and available settings. +Gemini CLI offers several ways to configure its behavior, including environment +variables, command-line arguments, and settings files. This document outlines +the different configuration methods and available settings. ## Configuration layers -Configuration is applied in the following order of precedence (lower numbers are overridden by higher numbers): +Configuration is applied in the following order of precedence (lower numbers are +overridden by higher numbers): 1. **Default values:** Hardcoded defaults within the application. -2. **System defaults file:** System-wide default settings that can be overridden by other settings files. +2. **System defaults file:** System-wide default settings that can be + overridden by other settings files. 3. **User settings file:** Global settings for the current user. 4. **Project settings file:** Project-specific settings. -5. **System settings file:** System-wide settings that override all other settings files. -6. **Environment variables:** System-wide or session-specific variables, potentially loaded from `.env` files. +5. **System settings file:** System-wide settings that override all other + settings files. +6. **Environment variables:** System-wide or session-specific variables, + potentially loaded from `.env` files. 7. **Command-line arguments:** Values passed when launching the CLI. ## Settings files -Gemini CLI uses JSON settings files for persistent configuration. There are four locations for these files: +Gemini CLI uses JSON settings files for persistent configuration. There are four +locations for these files: - **System defaults file:** - - **Location:** `/etc/gemini-cli/system-defaults.json` (Linux), `C:\ProgramData\gemini-cli\system-defaults.json` (Windows) or `/Library/Application Support/GeminiCli/system-defaults.json` (macOS). The path can be overridden using the `GEMINI_CLI_SYSTEM_DEFAULTS_PATH` environment variable. - - **Scope:** Provides a base layer of system-wide default settings. These settings have the lowest precedence and are intended to be overridden by user, project, or system override settings. + - **Location:** `/etc/gemini-cli/system-defaults.json` (Linux), + `C:\ProgramData\gemini-cli\system-defaults.json` (Windows) or + `/Library/Application Support/GeminiCli/system-defaults.json` (macOS). The + path can be overridden using the `GEMINI_CLI_SYSTEM_DEFAULTS_PATH` + environment variable. + - **Scope:** Provides a base layer of system-wide default settings. These + settings have the lowest precedence and are intended to be overridden by + user, project, or system override settings. - **User settings file:** - **Location:** `~/.gemini/settings.json` (where `~` is your home directory). - - **Scope:** Applies to all Gemini CLI sessions for the current user. User settings override system defaults. + - **Scope:** Applies to all Gemini CLI sessions for the current user. User + settings override system defaults. - **Project settings file:** - **Location:** `.gemini/settings.json` within your project's root directory. - - **Scope:** Applies only when running Gemini CLI from that specific project. Project settings override user settings and system defaults. + - **Scope:** Applies only when running Gemini CLI from that specific project. + Project settings override user settings and system defaults. - **System settings file:** - - **Location:** `/etc/gemini-cli/settings.json` (Linux), `C:\ProgramData\gemini-cli\settings.json` (Windows) or `/Library/Application Support/GeminiCli/settings.json` (macOS). The path can be overridden using the `GEMINI_CLI_SYSTEM_SETTINGS_PATH` environment variable. - - **Scope:** Applies to all Gemini CLI sessions on the system, for all users. System settings act as overrides, taking precedence over all other settings files. May be useful for system administrators at enterprises to have controls over users' Gemini CLI setups. + - **Location:** `/etc/gemini-cli/settings.json` (Linux), + `C:\ProgramData\gemini-cli\settings.json` (Windows) or + `/Library/Application Support/GeminiCli/settings.json` (macOS). The path can + be overridden using the `GEMINI_CLI_SYSTEM_SETTINGS_PATH` environment + variable. + - **Scope:** Applies to all Gemini CLI sessions on the system, for all users. + System settings act as overrides, taking precedence over all other settings + files. May be useful for system administrators at enterprises to have + controls over users' Gemini CLI setups. -**Note on environment variables in settings:** String values within your `settings.json` files can reference environment variables using either `$VAR_NAME` or `${VAR_NAME}` syntax. These variables will be automatically resolved when the settings are loaded. For example, if you have an environment variable `MY_API_TOKEN`, you could use it in `settings.json` like this: `"apiKey": "$MY_API_TOKEN"`. +**Note on environment variables in settings:** String values within your +`settings.json` files can reference environment variables using either +`$VAR_NAME` or `${VAR_NAME}` syntax. These variables will be automatically +resolved when the settings are loaded. For example, if you have an environment +variable `MY_API_TOKEN`, you could use it in `settings.json` like this: +`"apiKey": "$MY_API_TOKEN"`. -> **Note for Enterprise Users:** For guidance on deploying and managing Gemini CLI in a corporate environment, please see the [Enterprise Configuration](../cli/enterprise.md) documentation. +> **Note for Enterprise Users:** For guidance on deploying and managing Gemini +> CLI in a corporate environment, please see the +> [Enterprise Configuration](../cli/enterprise.md) documentation. ### The `.gemini` directory in your project -In addition to a project settings file, a project's `.gemini` directory can contain other project-specific files related to Gemini CLI's operation, such as: +In addition to a project settings file, a project's `.gemini` directory can +contain other project-specific files related to Gemini CLI's operation, such as: -- [Custom sandbox profiles](#sandboxing) (e.g., `.gemini/sandbox-macos-custom.sb`, `.gemini/sandbox.Dockerfile`). +- [Custom sandbox profiles](#sandboxing) (e.g., + `.gemini/sandbox-macos-custom.sb`, `.gemini/sandbox.Dockerfile`). ### Available settings in `settings.json`: - **`contextFileName`** (string or array of strings): - - **Description:** Specifies the filename for context files (e.g., `GEMINI.md`, `AGENTS.md`). Can be a single filename or a list of accepted filenames. + - **Description:** Specifies the filename for context files (e.g., + `GEMINI.md`, `AGENTS.md`). Can be a single filename or a list of accepted + filenames. - **Default:** `GEMINI.md` - **Example:** `"contextFileName": "AGENTS.md"` - **`bugCommand`** (object): - **Description:** Overrides the default URL for the `/bug` command. - - **Default:** `"urlTemplate": "https://github.com/google-gemini/gemini-cli/issues/new?template=bug_report.yml&title={title}&info={info}"` + - **Default:** + `"urlTemplate": "https://github.com/google-gemini/gemini-cli/issues/new?template=bug_report.yml&title={title}&info={info}"` - **Properties:** - - **`urlTemplate`** (string): A URL that can contain `{title}` and `{info}` placeholders. + - **`urlTemplate`** (string): A URL that can contain `{title}` and `{info}` + placeholders. - **Example:** ```json "bugCommand": { @@ -70,12 +109,20 @@ In addition to a project settings file, a project's `.gemini` directory can cont ``` - **`fileFiltering`** (object): - - **Description:** Controls git-aware file filtering behavior for @ commands and file discovery tools. + - **Description:** Controls git-aware file filtering behavior for @ commands + and file discovery tools. - **Default:** `"respectGitIgnore": true, "enableRecursiveFileSearch": true` - **Properties:** - - **`respectGitIgnore`** (boolean): Whether to respect .gitignore patterns when discovering files. When set to `true`, git-ignored files (like `node_modules/`, `dist/`, `.env`) are automatically excluded from @ commands and file listing operations. - - **`enableRecursiveFileSearch`** (boolean): Whether to enable searching recursively for filenames under the current tree when completing @ prefixes in the prompt. - - **`disableFuzzySearch`** (boolean): When `true`, disables the fuzzy search capabilities when searching for files, which can improve performance on projects with a large number of files. + - **`respectGitIgnore`** (boolean): Whether to respect .gitignore patterns + when discovering files. When set to `true`, git-ignored files (like + `node_modules/`, `dist/`, `.env`) are automatically excluded from @ + commands and file listing operations. + - **`enableRecursiveFileSearch`** (boolean): Whether to enable searching + recursively for filenames under the current tree when completing @ + prefixes in the prompt. + - **`disableFuzzySearch`** (boolean): When `true`, disables the fuzzy search + capabilities when searching for files, which can improve performance on + projects with a large number of files. - **Example:** ```json "fileFiltering": { @@ -87,46 +134,92 @@ In addition to a project settings file, a project's `.gemini` directory can cont ### Troubleshooting File Search Performance -If you are experiencing performance issues with file searching (e.g., with `@` completions), especially in projects with a very large number of files, here are a few things you can try in order of recommendation: +If you are experiencing performance issues with file searching (e.g., with `@` +completions), especially in projects with a very large number of files, here are +a few things you can try in order of recommendation: -1. **Use `.geminiignore`:** Create a `.geminiignore` file in your project root to exclude directories that contain a large number of files that you don't need to reference (e.g., build artifacts, logs, `node_modules`). Reducing the total number of files crawled is the most effective way to improve performance. +1. **Use `.geminiignore`:** Create a `.geminiignore` file in your project root + to exclude directories that contain a large number of files that you don't + need to reference (e.g., build artifacts, logs, `node_modules`). Reducing + the total number of files crawled is the most effective way to improve + performance. -2. **Disable Fuzzy Search:** If ignoring files is not enough, you can disable fuzzy search by setting `disableFuzzySearch` to `true` in your `settings.json` file. This will use a simpler, non-fuzzy matching algorithm, which can be faster. +2. **Disable Fuzzy Search:** If ignoring files is not enough, you can disable + fuzzy search by setting `disableFuzzySearch` to `true` in your + `settings.json` file. This will use a simpler, non-fuzzy matching algorithm, + which can be faster. -3. **Disable Recursive File Search:** As a last resort, you can disable recursive file search entirely by setting `enableRecursiveFileSearch` to `false`. This will be the fastest option as it avoids a recursive crawl of your project. However, it means you will need to type the full path to files when using `@` completions. +3. **Disable Recursive File Search:** As a last resort, you can disable + recursive file search entirely by setting `enableRecursiveFileSearch` to + `false`. This will be the fastest option as it avoids a recursive crawl of + your project. However, it means you will need to type the full path to files + when using `@` completions. - **`coreTools`** (array of strings): - - **Description:** Allows you to specify a list of core tool names that should be made available to the model. This can be used to restrict the set of built-in tools. See [Built-in Tools](../core/tools-api.md#built-in-tools) for a list of core tools. You can also specify command-specific restrictions for tools that support it, like the `ShellTool`. For example, `"coreTools": ["ShellTool(ls -l)"]` will only allow the `ls -l` command to be executed. + - **Description:** Allows you to specify a list of core tool names that should + be made available to the model. This can be used to restrict the set of + built-in tools. See [Built-in Tools](../core/tools-api.md#built-in-tools) + for a list of core tools. You can also specify command-specific restrictions + for tools that support it, like the `ShellTool`. For example, + `"coreTools": ["ShellTool(ls -l)"]` will only allow the `ls -l` command to + be executed. - **Default:** All tools available for use by the Gemini model. - **Example:** `"coreTools": ["ReadFileTool", "GlobTool", "ShellTool(ls)"]`. - **`allowedTools`** (array of strings): - **Default:** `undefined` - - **Description:** A list of tool names that will bypass the confirmation dialog. This is useful for tools that you trust and use frequently. The match semantics are the same as `coreTools`. + - **Description:** A list of tool names that will bypass the confirmation + dialog. This is useful for tools that you trust and use frequently. The + match semantics are the same as `coreTools`. - **Example:** `"allowedTools": ["ShellTool(git status)"]`. - **`excludeTools`** (array of strings): - - **Description:** Allows you to specify a list of core tool names that should be excluded from the model. A tool listed in both `excludeTools` and `coreTools` is excluded. You can also specify command-specific restrictions for tools that support it, like the `ShellTool`. For example, `"excludeTools": ["ShellTool(rm -rf)"]` will block the `rm -rf` command. + - **Description:** Allows you to specify a list of core tool names that should + be excluded from the model. A tool listed in both `excludeTools` and + `coreTools` is excluded. You can also specify command-specific restrictions + for tools that support it, like the `ShellTool`. For example, + `"excludeTools": ["ShellTool(rm -rf)"]` will block the `rm -rf` command. - **Default**: No tools excluded. - **Example:** `"excludeTools": ["run_shell_command", "findFiles"]`. - - **Security Note:** Command-specific restrictions in - `excludeTools` for `run_shell_command` are based on simple string matching and can be easily bypassed. This feature is **not a security mechanism** and should not be relied upon to safely execute untrusted code. It is recommended to use `coreTools` to explicitly select commands - that can be executed. + - **Security Note:** Command-specific restrictions in `excludeTools` for + `run_shell_command` are based on simple string matching and can be easily + bypassed. This feature is **not a security mechanism** and should not be + relied upon to safely execute untrusted code. It is recommended to use + `coreTools` to explicitly select commands that can be executed. - **`allowMCPServers`** (array of strings): - - **Description:** Allows you to specify a list of MCP server names that should be made available to the model. This can be used to restrict the set of MCP servers to connect to. Note that this will be ignored if `--allowed-mcp-server-names` is set. + - **Description:** Allows you to specify a list of MCP server names that + should be made available to the model. This can be used to restrict the set + of MCP servers to connect to. Note that this will be ignored if + `--allowed-mcp-server-names` is set. - **Default:** All MCP servers are available for use by the Gemini model. - **Example:** `"allowMCPServers": ["myPythonServer"]`. - - **Security Note:** This uses simple string matching on MCP server names, which can be modified. If you're a system administrator looking to prevent users from bypassing this, consider configuring the `mcpServers` at the system settings level such that the user will not be able to configure any MCP servers of their own. This should not be used as an airtight security mechanism. + - **Security Note:** This uses simple string matching on MCP server names, + which can be modified. If you're a system administrator looking to prevent + users from bypassing this, consider configuring the `mcpServers` at the + system settings level such that the user will not be able to configure any + MCP servers of their own. This should not be used as an airtight security + mechanism. - **`excludeMCPServers`** (array of strings): - - **Description:** Allows you to specify a list of MCP server names that should be excluded from the model. A server listed in both `excludeMCPServers` and `allowMCPServers` is excluded. Note that this will be ignored if `--allowed-mcp-server-names` is set. + - **Description:** Allows you to specify a list of MCP server names that + should be excluded from the model. A server listed in both + `excludeMCPServers` and `allowMCPServers` is excluded. Note that this will + be ignored if `--allowed-mcp-server-names` is set. - **Default**: No MCP servers excluded. - **Example:** `"excludeMCPServers": ["myNodeServer"]`. - - **Security Note:** This uses simple string matching on MCP server names, which can be modified. If you're a system administrator looking to prevent users from bypassing this, consider configuring the `mcpServers` at the system settings level such that the user will not be able to configure any MCP servers of their own. This should not be used as an airtight security mechanism. + - **Security Note:** This uses simple string matching on MCP server names, + which can be modified. If you're a system administrator looking to prevent + users from bypassing this, consider configuring the `mcpServers` at the + system settings level such that the user will not be able to configure any + MCP servers of their own. This should not be used as an airtight security + mechanism. - **`autoAccept`** (boolean): - - **Description:** Controls whether the CLI automatically accepts and executes tool calls that are considered safe (e.g., read-only operations) without explicit user confirmation. If set to `true`, the CLI will bypass the confirmation prompt for tools deemed safe. + - **Description:** Controls whether the CLI automatically accepts and executes + tool calls that are considered safe (e.g., read-only operations) without + explicit user confirmation. If set to `true`, the CLI will bypass the + confirmation prompt for tools deemed safe. - **Default:** `false` - **Example:** `"autoAccept": true` @@ -136,45 +229,85 @@ If you are experiencing performance issues with file searching (e.g., with `@` c - **Example:** `"theme": "GitHub"` - **`vimMode`** (boolean): - - **Description:** Enables or disables vim mode for input editing. When enabled, the input area supports vim-style navigation and editing commands with NORMAL and INSERT modes. The vim mode status is displayed in the footer and persists between sessions. + - **Description:** Enables or disables vim mode for input editing. When + enabled, the input area supports vim-style navigation and editing commands + with NORMAL and INSERT modes. The vim mode status is displayed in the footer + and persists between sessions. - **Default:** `false` - **Example:** `"vimMode": true` - **`sandbox`** (boolean or string): - - **Description:** Controls whether and how to use sandboxing for tool execution. If set to `true`, Gemini CLI uses a pre-built `gemini-cli-sandbox` Docker image. For more information, see [Sandboxing](#sandboxing). + - **Description:** Controls whether and how to use sandboxing for tool + execution. If set to `true`, Gemini CLI uses a pre-built + `gemini-cli-sandbox` Docker image. For more information, see + [Sandboxing](#sandboxing). - **Default:** `false` - **Example:** `"sandbox": "docker"` - **`toolDiscoveryCommand`** (string): - - **Description:** Defines a custom shell command for discovering tools from your project. The shell command must return on `stdout` a JSON array of [function declarations](https://ai.google.dev/gemini-api/docs/function-calling#function-declarations). Tool wrappers are optional. + - **Description:** Defines a custom shell command for discovering tools from + your project. The shell command must return on `stdout` a JSON array of + [function declarations](https://ai.google.dev/gemini-api/docs/function-calling#function-declarations). + Tool wrappers are optional. - **Default:** Empty - **Example:** `"toolDiscoveryCommand": "bin/get_tools"` - **`toolCallCommand`** (string): - - **Description:** Defines a custom shell command for calling a specific tool that was discovered using `toolDiscoveryCommand`. The shell command must meet the following criteria: - - It must take function `name` (exactly as in [function declaration](https://ai.google.dev/gemini-api/docs/function-calling#function-declarations)) as first command line argument. - - It must read function arguments as JSON on `stdin`, analogous to [`functionCall.args`](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#functioncall). - - It must return function output as JSON on `stdout`, analogous to [`functionResponse.response.content`](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#functionresponse). + - **Description:** Defines a custom shell command for calling a specific tool + that was discovered using `toolDiscoveryCommand`. The shell command must + meet the following criteria: + - It must take function `name` (exactly as in + [function declaration](https://ai.google.dev/gemini-api/docs/function-calling#function-declarations)) + as first command line argument. + - It must read function arguments as JSON on `stdin`, analogous to + [`functionCall.args`](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#functioncall). + - It must return function output as JSON on `stdout`, analogous to + [`functionResponse.response.content`](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#functionresponse). - **Default:** Empty - **Example:** `"toolCallCommand": "bin/call_tool"` - **`mcpServers`** (object): - - **Description:** Configures connections to one or more Model-Context Protocol (MCP) servers for discovering and using custom tools. Gemini CLI attempts to connect to each configured MCP server to discover available tools. If multiple MCP servers expose a tool with the same name, the tool names will be prefixed with the server alias you defined in the configuration (e.g., `serverAlias__actualToolName`) to avoid conflicts. Note that the system might strip certain schema properties from MCP tool definitions for compatibility. At least one of `command`, `url`, or `httpUrl` must be provided. If multiple are specified, the order of precedence is `httpUrl`, then `url`, then `command`. + - **Description:** Configures connections to one or more Model-Context + Protocol (MCP) servers for discovering and using custom tools. Gemini CLI + attempts to connect to each configured MCP server to discover available + tools. If multiple MCP servers expose a tool with the same name, the tool + names will be prefixed with the server alias you defined in the + configuration (e.g., `serverAlias__actualToolName`) to avoid conflicts. Note + that the system might strip certain schema properties from MCP tool + definitions for compatibility. At least one of `command`, `url`, or + `httpUrl` must be provided. If multiple are specified, the order of + precedence is `httpUrl`, then `url`, then `command`. - **Default:** Empty - **Properties:** - **``** (object): The server parameters for the named server. - - `command` (string, optional): The command to execute to start the MCP server via standard I/O. + - `command` (string, optional): The command to execute to start the MCP + server via standard I/O. - `args` (array of strings, optional): Arguments to pass to the command. - - `env` (object, optional): Environment variables to set for the server process. - - `cwd` (string, optional): The working directory in which to start the server. - - `url` (string, optional): The URL of an MCP server that uses Server-Sent Events (SSE) for communication. - - `httpUrl` (string, optional): The URL of an MCP server that uses streamable HTTP for communication. - - `headers` (object, optional): A map of HTTP headers to send with requests to `url` or `httpUrl`. - - `timeout` (number, optional): Timeout in milliseconds for requests to this MCP server. - - `trust` (boolean, optional): Trust this server and bypass all tool call confirmations. - - `description` (string, optional): A brief description of the server, which may be used for display purposes. - - `includeTools` (array of strings, optional): List of tool names to include from this MCP server. When specified, only the tools listed here will be available from this server (allowlist behavior). If not specified, all tools from the server are enabled by default. - - `excludeTools` (array of strings, optional): List of tool names to exclude from this MCP server. Tools listed here will not be available to the model, even if they are exposed by the server. **Note:** `excludeTools` takes precedence over `includeTools` - if a tool is in both lists, it will be excluded. + - `env` (object, optional): Environment variables to set for the server + process. + - `cwd` (string, optional): The working directory in which to start the + server. + - `url` (string, optional): The URL of an MCP server that uses Server-Sent + Events (SSE) for communication. + - `httpUrl` (string, optional): The URL of an MCP server that uses + streamable HTTP for communication. + - `headers` (object, optional): A map of HTTP headers to send with + requests to `url` or `httpUrl`. + - `timeout` (number, optional): Timeout in milliseconds for requests to + this MCP server. + - `trust` (boolean, optional): Trust this server and bypass all tool call + confirmations. + - `description` (string, optional): A brief description of the server, + which may be used for display purposes. + - `includeTools` (array of strings, optional): List of tool names to + include from this MCP server. When specified, only the tools listed here + will be available from this server (allowlist behavior). If not + specified, all tools from the server are enabled by default. + - `excludeTools` (array of strings, optional): List of tool names to + exclude from this MCP server. Tools listed here will not be available to + the model, even if they are exposed by the server. **Note:** + `excludeTools` takes precedence over `includeTools` - if a tool is in + both lists, it will be excluded. - **Example:** ```json "mcpServers": { @@ -216,7 +349,9 @@ If you are experiencing performance issues with file searching (e.g., with `@` c ``` - **`checkpointing`** (object): - - **Description:** Configures the checkpointing feature, which allows you to save and restore conversation and file states. See the [Checkpointing documentation](../cli/checkpointing.md) for more details. + - **Description:** Configures the checkpointing feature, which allows you to + save and restore conversation and file states. See the + [Checkpointing documentation](../cli/checkpointing.md) for more details. - **Default:** `{"enabled": false}` - **Properties:** - **`enabled`** (boolean): When `true`, the `/restore` command is available. @@ -227,13 +362,17 @@ If you are experiencing performance issues with file searching (e.g., with `@` c - **Example:** `"preferredEditor": "vscode"` - **`telemetry`** (object) - - **Description:** Configures logging and metrics collection for Gemini CLI. For more information, see [Telemetry](../cli/telemetry.md). - - **Default:** `{"enabled": false, "target": "local", "otlpEndpoint": "http://localhost:4317", "logPrompts": true}` + - **Description:** Configures logging and metrics collection for Gemini CLI. + For more information, see [Telemetry](../cli/telemetry.md). + - **Default:** + `{"enabled": false, "target": "local", "otlpEndpoint": "http://localhost:4317", "logPrompts": true}` - **Properties:** - **`enabled`** (boolean): Whether or not telemetry is enabled. - - **`target`** (string): The destination for collected telemetry. Supported values are `local` and `gcp`. + - **`target`** (string): The destination for collected telemetry. Supported + values are `local` and `gcp`. - **`otlpEndpoint`** (string): The endpoint for the OTLP Exporter. - - **`logPrompts`** (boolean): Whether or not to include the content of user prompts in the logs. + - **`logPrompts`** (boolean): Whether or not to include the content of user + prompts in the logs. - **Example:** ```json "telemetry": { @@ -244,7 +383,8 @@ If you are experiencing performance issues with file searching (e.g., with `@` c } ``` - **`usageStatisticsEnabled`** (boolean): - - **Description:** Enables or disables the collection of usage statistics. See [Usage Statistics](#usage-statistics) for more information. + - **Description:** Enables or disables the collection of usage statistics. See + [Usage Statistics](#usage-statistics) for more information. - **Default:** `true` - **Example:** ```json @@ -261,7 +401,8 @@ If you are experiencing performance issues with file searching (e.g., with `@` c ``` - **`hideBanner`** (boolean): - - **Description:** Enables or disables the startup banner (ASCII art logo) in the CLI interface. + - **Description:** Enables or disables the startup banner (ASCII art logo) in + the CLI interface. - **Default:** `false` - **Example:** @@ -270,7 +411,9 @@ If you are experiencing performance issues with file searching (e.g., with `@` c ``` - **`maxSessionTurns`** (number): - - **Description:** Sets the maximum number of turns for a session. If the session exceeds this limit, the CLI will stop processing and start a new chat. + - **Description:** Sets the maximum number of turns for a session. If the + session exceeds this limit, the CLI will stop processing and start a new + chat. - **Default:** `-1` (unlimited) - **Example:** ```json @@ -278,7 +421,9 @@ If you are experiencing performance issues with file searching (e.g., with `@` c ``` - **`summarizeToolOutput`** (object): - - **Description:** Enables or disables the summarization of tool output. You can specify the token budget for the summarization using the `tokenBudget` setting. + - **Description:** Enables or disables the summarization of tool output. You + can specify the token budget for the summarization using the `tokenBudget` + setting. - Note: Currently only the `run_shell_command` tool is supported. - **Default:** `{}` (Disabled by default) - **Example:** @@ -291,7 +436,10 @@ If you are experiencing performance issues with file searching (e.g., with `@` c ``` - **`excludedProjectEnvVars`** (array of strings): - - **Description:** Specifies environment variables that should be excluded from being loaded from project `.env` files. This prevents project-specific environment variables (like `DEBUG=true`) from interfering with gemini-cli behavior. Variables from `.gemini/.env` files are never excluded. + - **Description:** Specifies environment variables that should be excluded + from being loaded from project `.env` files. This prevents project-specific + environment variables (like `DEBUG=true`) from interfering with gemini-cli + behavior. Variables from `.gemini/.env` files are never excluded. - **Default:** `["DEBUG", "DEBUG_MODE"]` - **Example:** ```json @@ -299,7 +447,11 @@ If you are experiencing performance issues with file searching (e.g., with `@` c ``` - **`includeDirectories`** (array of strings): - - **Description:** Specifies an array of additional absolute or relative paths to include in the workspace context. Missing directories will be skipped with a warning by default. Paths can use `~` to refer to the user's home directory. This setting can be combined with the `--include-directories` command-line flag. + - **Description:** Specifies an array of additional absolute or relative paths + to include in the workspace context. Missing directories will be skipped + with a warning by default. Paths can use `~` to refer to the user's home + directory. This setting can be combined with the `--include-directories` + command-line flag. - **Default:** `[]` - **Example:** ```json @@ -311,7 +463,10 @@ If you are experiencing performance issues with file searching (e.g., with `@` c ``` - **`loadMemoryFromIncludeDirectories`** (boolean): - - **Description:** Controls the behavior of the `/memory refresh` command. If set to `true`, `GEMINI.md` files should be loaded from all directories that are added. If set to `false`, `GEMINI.md` should only be loaded from the current directory. + - **Description:** Controls the behavior of the `/memory refresh` command. If + set to `true`, `GEMINI.md` files should be loaded from all directories that + are added. If set to `false`, `GEMINI.md` should only be loaded from the + current directory. - **Default:** `false` - **Example:** ```json @@ -319,10 +474,13 @@ If you are experiencing performance issues with file searching (e.g., with `@` c ``` - **`chatCompression`** (object): - - **Description:** Controls the settings for chat history compression, both automatic and - when manually invoked through the /compress command. + - **Description:** Controls the settings for chat history compression, both + automatic and when manually invoked through the /compress command. - **Properties:** - - **`contextPercentageThreshold`** (number): A value between 0 and 1 that specifies the token threshold for compression as a percentage of the model's total token limit. For example, a value of `0.6` will trigger compression when the chat history exceeds 60% of the token limit. + - **`contextPercentageThreshold`** (number): A value between 0 and 1 that + specifies the token threshold for compression as a percentage of the + model's total token limit. For example, a value of `0.6` will trigger + compression when the chat history exceeds 60% of the token limit. - **Example:** ```json "chatCompression": { @@ -331,7 +489,8 @@ If you are experiencing performance issues with file searching (e.g., with `@` c ``` - **`showLineNumbers`** (boolean): - - **Description:** Controls whether line numbers are displayed in code blocks in the CLI output. + - **Description:** Controls whether line numbers are displayed in code blocks + in the CLI output. - **Default:** `true` - **Example:** ```json @@ -341,8 +500,12 @@ If you are experiencing performance issues with file searching (e.g., with `@` c - **`accessibility`** (object): - **Description:** Configures accessibility features for the CLI. - **Properties:** - - **`screenReader`** (boolean): Enables screen reader mode, which adjusts the TUI for better compatibility with screen readers. This can also be enabled with the `--screen-reader` command-line flag, which will take precedence over the setting. - - **`disableLoadingPhrases`** (boolean): Disables the display of loading phrases during operations. + - **`screenReader`** (boolean): Enables screen reader mode, which adjusts + the TUI for better compatibility with screen readers. This can also be + enabled with the `--screen-reader` command-line flag, which will take + precedence over the setting. + - **`disableLoadingPhrases`** (boolean): Disables the display of loading + phrases during operations. - **Default:** `{"screenReader": false, "disableLoadingPhrases": false}` - **Example:** ```json @@ -392,28 +555,43 @@ If you are experiencing performance issues with file searching (e.g., with `@` c ## Shell History -The CLI keeps a history of shell commands you run. To avoid conflicts between different projects, this history is stored in a project-specific directory within your user's home folder. +The CLI keeps a history of shell commands you run. To avoid conflicts between +different projects, this history is stored in a project-specific directory +within your user's home folder. - **Location:** `~/.gemini/tmp//shell_history` - - `` is a unique identifier generated from your project's root path. + - `` is a unique identifier generated from your project's root + path. - The history is stored in a file named `shell_history`. ## Environment Variables & `.env` Files -Environment variables are a common way to configure applications, especially for sensitive information like API keys or for settings that might change between environments. For authentication setup, see the [Authentication documentation](./authentication.md) which covers all available authentication methods. +Environment variables are a common way to configure applications, especially for +sensitive information like API keys or for settings that might change between +environments. For authentication setup, see the +[Authentication documentation](./authentication.md) which covers all available +authentication methods. -The CLI automatically loads environment variables from an `.env` file. The loading order is: +The CLI automatically loads environment variables from an `.env` file. The +loading order is: 1. `.env` file in the current working directory. -2. If not found, it searches upwards in parent directories until it finds an `.env` file or reaches the project root (identified by a `.git` folder) or the home directory. +2. If not found, it searches upwards in parent directories until it finds an + `.env` file or reaches the project root (identified by a `.git` folder) or + the home directory. 3. If still not found, it looks for `~/.env` (in the user's home directory). -**Environment Variable Exclusion:** Some environment variables (like `DEBUG` and `DEBUG_MODE`) are automatically excluded from being loaded from project `.env` files to prevent interference with gemini-cli behavior. Variables from `.gemini/.env` files are never excluded. You can customize this behavior using the `excludedProjectEnvVars` setting in your `settings.json` file. +**Environment Variable Exclusion:** Some environment variables (like `DEBUG` and +`DEBUG_MODE`) are automatically excluded from being loaded from project `.env` +files to prevent interference with gemini-cli behavior. Variables from +`.gemini/.env` files are never excluded. You can customize this behavior using +the `excludedProjectEnvVars` setting in your `settings.json` file. - **`GEMINI_API_KEY`**: - Your API key for the Gemini API. - One of several available [authentication methods](./authentication.md). - - Set this in your shell profile (e.g., `~/.bashrc`, `~/.zshrc`) or an `.env` file. + - Set this in your shell profile (e.g., `~/.bashrc`, `~/.zshrc`) or an `.env` + file. - **`GEMINI_MODEL`**: - Specifies the default Gemini model to use. - Overrides the hardcoded default @@ -426,12 +604,18 @@ The CLI automatically loads environment variables from an `.env` file. The loadi - **`GOOGLE_CLOUD_PROJECT`**: - Your Google Cloud Project ID. - Required for using Code Assist or Vertex AI. - - If using Vertex AI, ensure you have the necessary permissions in this project. - - **Cloud Shell Note:** When running in a Cloud Shell environment, this variable defaults to a special project allocated for Cloud Shell users. If you have `GOOGLE_CLOUD_PROJECT` set in your global environment in Cloud Shell, it will be overridden by this default. To use a different project in Cloud Shell, you must define `GOOGLE_CLOUD_PROJECT` in a `.env` file. + - If using Vertex AI, ensure you have the necessary permissions in this + project. + - **Cloud Shell Note:** When running in a Cloud Shell environment, this + variable defaults to a special project allocated for Cloud Shell users. If + you have `GOOGLE_CLOUD_PROJECT` set in your global environment in Cloud + Shell, it will be overridden by this default. To use a different project in + Cloud Shell, you must define `GOOGLE_CLOUD_PROJECT` in a `.env` file. - Example: `export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"`. - **`GOOGLE_APPLICATION_CREDENTIALS`** (string): - **Description:** The path to your Google Application Credentials JSON file. - - **Example:** `export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/credentials.json"` + - **Example:** + `export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/credentials.json"` - **`OTLP_GOOGLE_CLOUD_PROJECT`**: - Your Google Cloud Project ID for Telemetry in Google Cloud - Example: `export OTLP_GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"`. @@ -444,12 +628,21 @@ The CLI automatically loads environment variables from an `.env` file. The loadi - Accepts `true`, `false`, `docker`, `podman`, or a custom command string. - **`SEATBELT_PROFILE`** (macOS specific): - Switches the Seatbelt (`sandbox-exec`) profile on macOS. - - `permissive-open`: (Default) Restricts writes to the project folder (and a few other folders, see `packages/cli/src/utils/sandbox-macos-permissive-open.sb`) but allows other operations. + - `permissive-open`: (Default) Restricts writes to the project folder (and a + few other folders, see + `packages/cli/src/utils/sandbox-macos-permissive-open.sb`) but allows other + operations. - `strict`: Uses a strict profile that declines operations by default. - - ``: Uses a custom profile. To define a custom profile, create a file named `sandbox-macos-.sb` in your project's `.gemini/` directory (e.g., `my-project/.gemini/sandbox-macos-custom.sb`). -- **`DEBUG` or `DEBUG_MODE`** (often used by underlying libraries or the CLI itself): - - Set to `true` or `1` to enable verbose debug logging, which can be helpful for troubleshooting. - - **Note:** These variables are automatically excluded from project `.env` files by default to prevent interference with gemini-cli behavior. Use `.gemini/.env` files if you need to set these for gemini-cli specifically. + - ``: Uses a custom profile. To define a custom profile, create + a file named `sandbox-macos-.sb` in your project's `.gemini/` + directory (e.g., `my-project/.gemini/sandbox-macos-custom.sb`). +- **`DEBUG` or `DEBUG_MODE`** (often used by underlying libraries or the CLI + itself): + - Set to `true` or `1` to enable verbose debug logging, which can be helpful + for troubleshooting. + - **Note:** These variables are automatically excluded from project `.env` + files by default to prevent interference with gemini-cli behavior. Use + `.gemini/.env` files if you need to set these for gemini-cli specifically. - **`NO_COLOR`**: - Set to any value to disable all color output in the CLI. - **`CLI_TITLE`**: @@ -460,13 +653,15 @@ The CLI automatically loads environment variables from an `.env` file. The loadi ## Command-Line Arguments -Arguments passed directly when running the CLI can override other configurations for that specific session. +Arguments passed directly when running the CLI can override other configurations +for that specific session. - **`--model `** (**`-m `**): - Specifies the Gemini model to use for this session. - Example: `npm start -- --model gemini-1.5-pro-latest` - **`--prompt `** (**`-p `**): - - Used to pass a prompt directly to the command. This invokes Gemini CLI in a non-interactive mode. + - Used to pass a prompt directly to the command. This invokes Gemini CLI in a + non-interactive mode. - **`--prompt-interactive `** (**`-i `**): - Starts an interactive session with the provided prompt as the initial input. - The prompt is processed within the interactive session, not before it. @@ -479,7 +674,8 @@ Arguments passed directly when running the CLI can override other configurations - **`--debug`** (**`-d`**): - Enables debug mode for this session, providing more verbose output. - **`--all-files`** (**`-a`**): - - If set, recursively includes all files within the current directory as context for the prompt. + - If set, recursively includes all files within the current directory as + context for the prompt. - **`--help`** (or **`-h`**): - Displays help information about command-line arguments. - **`--show-memory-usage`**: @@ -489,27 +685,35 @@ Arguments passed directly when running the CLI can override other configurations - **`--approval-mode `**: - Sets the approval mode for tool calls. Available modes: - `default`: Prompt for approval on each tool call (default behavior) - - `auto_edit`: Automatically approve edit tools (replace, write_file) while prompting for others + - `auto_edit`: Automatically approve edit tools (replace, write_file) while + prompting for others - `yolo`: Automatically approve all tool calls (equivalent to `--yolo`) - - Cannot be used together with `--yolo`. Use `--approval-mode=yolo` instead of `--yolo` for the new unified approach. + - Cannot be used together with `--yolo`. Use `--approval-mode=yolo` instead of + `--yolo` for the new unified approach. - Example: `gemini --approval-mode auto_edit` - **`--allowed-tools `**: - - A comma-separated list of tool names that will bypass the confirmation dialog. + - A comma-separated list of tool names that will bypass the confirmation + dialog. - Example: `gemini --allowed-tools "ShellTool(git status)"` - **`--telemetry`**: - Enables [telemetry](../cli/telemetry.md). - **`--telemetry-target`**: - - Sets the telemetry target. See [telemetry](../cli/telemetry.md) for more information. + - Sets the telemetry target. See [telemetry](../cli/telemetry.md) for more + information. - **`--telemetry-otlp-endpoint`**: - - Sets the OTLP endpoint for telemetry. See [telemetry](../cli/telemetry.md) for more information. + - Sets the OTLP endpoint for telemetry. See [telemetry](../cli/telemetry.md) + for more information. - **`--telemetry-otlp-protocol`**: - - Sets the OTLP protocol for telemetry (`grpc` or `http`). Defaults to `grpc`. See [telemetry](../cli/telemetry.md) for more information. + - Sets the OTLP protocol for telemetry (`grpc` or `http`). Defaults to `grpc`. + See [telemetry](../cli/telemetry.md) for more information. - **`--telemetry-log-prompts`**: - - Enables logging of prompts for telemetry. See [telemetry](../cli/telemetry.md) for more information. + - Enables logging of prompts for telemetry. See + [telemetry](../cli/telemetry.md) for more information. - **`--checkpointing`**: - Enables [checkpointing](../cli/checkpointing.md). - **`--extensions `** (**`-e `**): - - Specifies a list of extensions to use for the session. If not provided, all available extensions are used. + - Specifies a list of extensions to use for the session. If not provided, all + available extensions are used. - Use the special term `gemini -e none` to disable all extensions. - Example: `gemini -e my-extension -e my-other-extension` - **`--list-extensions`** (**`-l`**): @@ -518,10 +722,12 @@ Arguments passed directly when running the CLI can override other configurations - Sets the proxy for the CLI. - Example: `--proxy http://localhost:7890`. - **`--include-directories `**: - - Includes additional directories in the workspace for multi-directory support. + - Includes additional directories in the workspace for multi-directory + support. - Can be specified multiple times or as comma-separated values. - 5 directories can be added at maximum. - - Example: `--include-directories /path/to/project1,/path/to/project2` or `--include-directories /path/to/project1 --include-directories /path/to/project2` + - Example: `--include-directories /path/to/project1,/path/to/project2` or + `--include-directories /path/to/project1 --include-directories /path/to/project2` - **`--screen-reader`**: - Enables screen reader mode for accessibility. - **`--version`**: @@ -529,13 +735,24 @@ Arguments passed directly when running the CLI can override other configurations ## Context Files (Hierarchical Instructional Context) -While not strictly configuration for the CLI's _behavior_, context files (defaulting to `GEMINI.md` but configurable via the `contextFileName` setting) are crucial for configuring the _instructional context_ (also referred to as "memory") provided to the Gemini model. This powerful feature allows you to give project-specific instructions, coding style guides, or any relevant background information to the AI, making its responses more tailored and accurate to your needs. The CLI includes UI elements, such as an indicator in the footer showing the number of loaded context files, to keep you informed about the active context. +While not strictly configuration for the CLI's _behavior_, context files +(defaulting to `GEMINI.md` but configurable via the `contextFileName` setting) +are crucial for configuring the _instructional context_ (also referred to as +"memory") provided to the Gemini model. This powerful feature allows you to give +project-specific instructions, coding style guides, or any relevant background +information to the AI, making its responses more tailored and accurate to your +needs. The CLI includes UI elements, such as an indicator in the footer showing +the number of loaded context files, to keep you informed about the active +context. -- **Purpose:** These Markdown files contain instructions, guidelines, or context that you want the Gemini model to be aware of during your interactions. The system is designed to manage this instructional context hierarchically. +- **Purpose:** These Markdown files contain instructions, guidelines, or context + that you want the Gemini model to be aware of during your interactions. The + system is designed to manage this instructional context hierarchically. ### Example Context File Content (e.g., `GEMINI.md`) -Here's a conceptual example of what a context file at the root of a TypeScript project might contain: +Here's a conceptual example of what a context file at the root of a TypeScript +project might contain: ```markdown # Project: My Awesome TypeScript Library @@ -557,7 +774,8 @@ Here's a conceptual example of what a context file at the root of a TypeScript p ## Specific Component: `src/api/client.ts` - This file handles all outbound API requests. -- When adding new API call functions, ensure they include robust error handling and logging. +- When adding new API call functions, ensure they include robust error handling + and logging. - Use the existing `fetchWithRetry` utility for all GET requests. ## Regarding Dependencies: @@ -566,30 +784,61 @@ Here's a conceptual example of what a context file at the root of a TypeScript p - If a new dependency is required, please state the reason. ``` -This example demonstrates how you can provide general project context, specific coding conventions, and even notes about particular files or components. The more relevant and precise your context files are, the better the AI can assist you. Project-specific context files are highly encouraged to establish conventions and context. +This example demonstrates how you can provide general project context, specific +coding conventions, and even notes about particular files or components. The +more relevant and precise your context files are, the better the AI can assist +you. Project-specific context files are highly encouraged to establish +conventions and context. -- **Hierarchical Loading and Precedence:** The CLI implements a sophisticated hierarchical memory system by loading context files (e.g., `GEMINI.md`) from several locations. Content from files lower in this list (more specific) typically overrides or supplements content from files higher up (more general). The exact concatenation order and final context can be inspected using the `/memory show` command. The typical loading order is: +- **Hierarchical Loading and Precedence:** The CLI implements a sophisticated + hierarchical memory system by loading context files (e.g., `GEMINI.md`) from + several locations. Content from files lower in this list (more specific) + typically overrides or supplements content from files higher up (more + general). The exact concatenation order and final context can be inspected + using the `/memory show` command. The typical loading order is: 1. **Global Context File:** - - Location: `~/.gemini/` (e.g., `~/.gemini/GEMINI.md` in your user home directory). + - Location: `~/.gemini/` (e.g., `~/.gemini/GEMINI.md` in + your user home directory). - Scope: Provides default instructions for all your projects. 2. **Project Root & Ancestors Context Files:** - - Location: The CLI searches for the configured context file in the current working directory and then in each parent directory up to either the project root (identified by a `.git` folder) or your home directory. - - Scope: Provides context relevant to the entire project or a significant portion of it. + - Location: The CLI searches for the configured context file in the + current working directory and then in each parent directory up to either + the project root (identified by a `.git` folder) or your home directory. + - Scope: Provides context relevant to the entire project or a significant + portion of it. 3. **Sub-directory Context Files (Contextual/Local):** - - Location: The CLI also scans for the configured context file in subdirectories _below_ the current working directory (respecting common ignore patterns like `node_modules`, `.git`, etc.). The breadth of this search is limited to 200 directories by default, but can be configured with a `memoryDiscoveryMaxDirs` field in your `settings.json` file. - - Scope: Allows for highly specific instructions relevant to a particular component, module, or subsection of your project. -- **Concatenation & UI Indication:** The contents of all found context files are concatenated (with separators indicating their origin and path) and provided as part of the system prompt to the Gemini model. The CLI footer displays the count of loaded context files, giving you a quick visual cue about the active instructional context. -- **Importing Content:** You can modularize your context files by importing other Markdown files using the `@path/to/file.md` syntax. For more details, see the [Memory Import Processor documentation](../core/memport.md). + - Location: The CLI also scans for the configured context file in + subdirectories _below_ the current working directory (respecting common + ignore patterns like `node_modules`, `.git`, etc.). The breadth of this + search is limited to 200 directories by default, but can be configured + with a `memoryDiscoveryMaxDirs` field in your `settings.json` file. + - Scope: Allows for highly specific instructions relevant to a particular + component, module, or subsection of your project. +- **Concatenation & UI Indication:** The contents of all found context files are + concatenated (with separators indicating their origin and path) and provided + as part of the system prompt to the Gemini model. The CLI footer displays the + count of loaded context files, giving you a quick visual cue about the active + instructional context. +- **Importing Content:** You can modularize your context files by importing + other Markdown files using the `@path/to/file.md` syntax. For more details, + see the [Memory Import Processor documentation](../core/memport.md). - **Commands for Memory Management:** - - Use `/memory refresh` to force a re-scan and reload of all context files from all configured locations. This updates the AI's instructional context. - - Use `/memory show` to display the combined instructional context currently loaded, allowing you to verify the hierarchy and content being used by the AI. - - See the [Commands documentation](../cli/commands.md#memory) for full details on the `/memory` command and its sub-commands (`show` and `refresh`). + - Use `/memory refresh` to force a re-scan and reload of all context files + from all configured locations. This updates the AI's instructional context. + - Use `/memory show` to display the combined instructional context currently + loaded, allowing you to verify the hierarchy and content being used by the + AI. + - See the [Commands documentation](../cli/commands.md#memory) for full details + on the `/memory` command and its sub-commands (`show` and `refresh`). -By understanding and utilizing these configuration layers and the hierarchical nature of context files, you can effectively manage the AI's memory and tailor the Gemini CLI's responses to your specific needs and projects. +By understanding and utilizing these configuration layers and the hierarchical +nature of context files, you can effectively manage the AI's memory and tailor +the Gemini CLI's responses to your specific needs and projects. ## Sandboxing -The Gemini CLI can execute potentially unsafe operations (like shell commands and file modifications) within a sandboxed environment to protect your system. +The Gemini CLI can execute potentially unsafe operations (like shell commands +and file modifications) within a sandboxed environment to protect your system. Sandboxing is disabled by default, but you can enable it in a few ways: @@ -599,7 +848,9 @@ Sandboxing is disabled by default, but you can enable it in a few ways: By default, it uses a pre-built `gemini-cli-sandbox` Docker image. -For project-specific sandboxing needs, you can create a custom Dockerfile at `.gemini/sandbox.Dockerfile` in your project's root directory. This Dockerfile can be based on the base sandbox image: +For project-specific sandboxing needs, you can create a custom Dockerfile at +`.gemini/sandbox.Dockerfile` in your project's root directory. This Dockerfile +can be based on the base sandbox image: ```dockerfile FROM gemini-cli-sandbox @@ -610,7 +861,9 @@ FROM gemini-cli-sandbox # COPY ./my-config /app/my-config ``` -When `.gemini/sandbox.Dockerfile` exists, you can use `BUILD_SANDBOX` environment variable when running Gemini CLI to automatically build the custom sandbox image: +When `.gemini/sandbox.Dockerfile` exists, you can use `BUILD_SANDBOX` +environment variable when running Gemini CLI to automatically build the custom +sandbox image: ```bash BUILD_SANDBOX=1 gemini -s @@ -618,23 +871,34 @@ BUILD_SANDBOX=1 gemini -s ## Usage Statistics -To help us improve the Gemini CLI, we collect anonymized usage statistics. This data helps us understand how the CLI is used, identify common issues, and prioritize new features. +To help us improve the Gemini CLI, we collect anonymized usage statistics. This +data helps us understand how the CLI is used, identify common issues, and +prioritize new features. **What we collect:** -- **Tool Calls:** We log the names of the tools that are called, whether they succeed or fail, and how long they take to execute. We do not collect the arguments passed to the tools or any data returned by them. -- **API Requests:** We log the Gemini model used for each request, the duration of the request, and whether it was successful. We do not collect the content of the prompts or responses. -- **Session Information:** We collect information about the configuration of the CLI, such as the enabled tools and the approval mode. +- **Tool Calls:** We log the names of the tools that are called, whether they + succeed or fail, and how long they take to execute. We do not collect the + arguments passed to the tools or any data returned by them. +- **API Requests:** We log the Gemini model used for each request, the duration + of the request, and whether it was successful. We do not collect the content + of the prompts or responses. +- **Session Information:** We collect information about the configuration of the + CLI, such as the enabled tools and the approval mode. **What we DON'T collect:** -- **Personally Identifiable Information (PII):** We do not collect any personal information, such as your name, email address, or API keys. -- **Prompt and Response Content:** We do not log the content of your prompts or the responses from the Gemini model. -- **File Content:** We do not log the content of any files that are read or written by the CLI. +- **Personally Identifiable Information (PII):** We do not collect any personal + information, such as your name, email address, or API keys. +- **Prompt and Response Content:** We do not log the content of your prompts or + the responses from the Gemini model. +- **File Content:** We do not log the content of any files that are read or + written by the CLI. **How to opt out:** -You can opt out of usage statistics collection at any time by setting the `usageStatisticsEnabled` property to `false` in your `settings.json` file: +You can opt out of usage statistics collection at any time by setting the +`usageStatisticsEnabled` property to `false` in your `settings.json` file: ```json { diff --git a/docs/get-started/configuration.md b/docs/get-started/configuration.md index 484d2d4c65..1fe44e7388 100644 --- a/docs/get-started/configuration.md +++ b/docs/get-started/configuration.md @@ -1,56 +1,92 @@ # Gemini CLI Configuration -> **Note on Configuration Format, 9/17/25:** The format of the `settings.json` file has been updated to a new, more organized structure. +> **Note on Configuration Format, 9/17/25:** The format of the `settings.json` +> file has been updated to a new, more organized structure. > -> - The new format will be supported in the stable release starting **[09/10/25]**. -> - Automatic migration from the old format to the new format will begin on **[09/17/25]**. +> - The new format will be supported in the stable release starting +> **[09/10/25]**. +> - Automatic migration from the old format to the new format will begin on +> **[09/17/25]**. > -> For details on the previous format, please see the [v1 Configuration documentation](./configuration-v1.md). +> For details on the previous format, please see the +> [v1 Configuration documentation](./configuration-v1.md). -Gemini CLI offers several ways to configure its behavior, including environment variables, command-line arguments, and settings files. This document outlines the different configuration methods and available settings. +Gemini CLI offers several ways to configure its behavior, including environment +variables, command-line arguments, and settings files. This document outlines +the different configuration methods and available settings. ## Configuration layers -Configuration is applied in the following order of precedence (lower numbers are overridden by higher numbers): +Configuration is applied in the following order of precedence (lower numbers are +overridden by higher numbers): 1. **Default values:** Hardcoded defaults within the application. -2. **System defaults file:** System-wide default settings that can be overridden by other settings files. +2. **System defaults file:** System-wide default settings that can be + overridden by other settings files. 3. **User settings file:** Global settings for the current user. 4. **Project settings file:** Project-specific settings. -5. **System settings file:** System-wide settings that override all other settings files. -6. **Environment variables:** System-wide or session-specific variables, potentially loaded from `.env` files. +5. **System settings file:** System-wide settings that override all other + settings files. +6. **Environment variables:** System-wide or session-specific variables, + potentially loaded from `.env` files. 7. **Command-line arguments:** Values passed when launching the CLI. ## Settings files -Gemini CLI uses JSON settings files for persistent configuration. There are four locations for these files: +Gemini CLI uses JSON settings files for persistent configuration. There are four +locations for these files: - **System defaults file:** - - **Location:** `/etc/gemini-cli/system-defaults.json` (Linux), `C:\ProgramData\gemini-cli\system-defaults.json` (Windows) or `/Library/Application Support/GeminiCli/system-defaults.json` (macOS). The path can be overridden using the `GEMINI_CLI_SYSTEM_DEFAULTS_PATH` environment variable. - - **Scope:** Provides a base layer of system-wide default settings. These settings have the lowest precedence and are intended to be overridden by user, project, or system override settings. + - **Location:** `/etc/gemini-cli/system-defaults.json` (Linux), + `C:\ProgramData\gemini-cli\system-defaults.json` (Windows) or + `/Library/Application Support/GeminiCli/system-defaults.json` (macOS). The + path can be overridden using the `GEMINI_CLI_SYSTEM_DEFAULTS_PATH` + environment variable. + - **Scope:** Provides a base layer of system-wide default settings. These + settings have the lowest precedence and are intended to be overridden by + user, project, or system override settings. - **User settings file:** - **Location:** `~/.gemini/settings.json` (where `~` is your home directory). - - **Scope:** Applies to all Gemini CLI sessions for the current user. User settings override system defaults. + - **Scope:** Applies to all Gemini CLI sessions for the current user. User + settings override system defaults. - **Project settings file:** - **Location:** `.gemini/settings.json` within your project's root directory. - - **Scope:** Applies only when running Gemini CLI from that specific project. Project settings override user settings and system defaults. + - **Scope:** Applies only when running Gemini CLI from that specific project. + Project settings override user settings and system defaults. - **System settings file:** - - **Location:** `/etc/gemini-cli/settings.json` (Linux), `C:\ProgramData\gemini-cli\settings.json` (Windows) or `/Library/Application Support/GeminiCli/settings.json` (macOS). The path can be overridden using the `GEMINI_CLI_SYSTEM_SETTINGS_PATH` environment variable. - - **Scope:** Applies to all Gemini CLI sessions on the system, for all users. System settings act as overrides, taking precedence over all other settings files. May be useful for system administrators at enterprises to have controls over users' Gemini CLI setups. + - **Location:** `/etc/gemini-cli/settings.json` (Linux), + `C:\ProgramData\gemini-cli\settings.json` (Windows) or + `/Library/Application Support/GeminiCli/settings.json` (macOS). The path can + be overridden using the `GEMINI_CLI_SYSTEM_SETTINGS_PATH` environment + variable. + - **Scope:** Applies to all Gemini CLI sessions on the system, for all users. + System settings act as overrides, taking precedence over all other settings + files. May be useful for system administrators at enterprises to have + controls over users' Gemini CLI setups. -**Note on environment variables in settings:** String values within your `settings.json` files can reference environment variables using either `$VAR_NAME` or `${VAR_NAME}` syntax. These variables will be automatically resolved when the settings are loaded. For example, if you have an environment variable `MY_API_TOKEN`, you could use it in `settings.json` like this: `"apiKey": "$MY_API_TOKEN"`. +**Note on environment variables in settings:** String values within your +`settings.json` files can reference environment variables using either +`$VAR_NAME` or `${VAR_NAME}` syntax. These variables will be automatically +resolved when the settings are loaded. For example, if you have an environment +variable `MY_API_TOKEN`, you could use it in `settings.json` like this: +`"apiKey": "$MY_API_TOKEN"`. -> **Note for Enterprise Users:** For guidance on deploying and managing Gemini CLI in a corporate environment, please see the [Enterprise Configuration](../cli/enterprise.md) documentation. +> **Note for Enterprise Users:** For guidance on deploying and managing Gemini +> CLI in a corporate environment, please see the +> [Enterprise Configuration](../cli/enterprise.md) documentation. ### The `.gemini` directory in your project -In addition to a project settings file, a project's `.gemini` directory can contain other project-specific files related to Gemini CLI's operation, such as: +In addition to a project settings file, a project's `.gemini` directory can +contain other project-specific files related to Gemini CLI's operation, such as: -- [Custom sandbox profiles](#sandboxing) (e.g., `.gemini/sandbox-macos-custom.sb`, `.gemini/sandbox.Dockerfile`). +- [Custom sandbox profiles](#sandboxing) (e.g., + `.gemini/sandbox-macos-custom.sb`, `.gemini/sandbox.Dockerfile`). ### Available settings in `settings.json` -Settings are organized into categories. All settings should be placed within their corresponding top-level category object in your `settings.json` file. +Settings are organized into categories. All settings should be placed within +their corresponding top-level category object in your `settings.json` file. #### `general` @@ -84,7 +120,8 @@ Settings are organized into categories. All settings should be placed within the #### `ui` - **`ui.theme`** (string): - - **Description:** The color theme for the UI. See [Themes](../cli/themes.md) for available options. + - **Description:** The color theme for the UI. See [Themes](../cli/themes.md) + for available options. - **Default:** `undefined` - **`ui.customThemes`** (object): @@ -124,7 +161,9 @@ Settings are organized into categories. All settings should be placed within the - **Default:** `false` - **`ui.customWittyPhrases`** (array of strings): - - **Description:** A list of custom phrases to display during loading states. When provided, the CLI will cycle through these phrases instead of the default ones. + - **Description:** A list of custom phrases to display during loading states. + When provided, the CLI will cycle through these phrases instead of the + default ones. - **Default:** `[]` #### `ide` @@ -150,15 +189,23 @@ Settings are organized into categories. All settings should be placed within the - **Default:** `undefined` - **`model.maxSessionTurns`** (number): - - **Description:** Maximum number of user/model/tool turns to keep in a session. -1 means unlimited. + - **Description:** Maximum number of user/model/tool turns to keep in a + session. -1 means unlimited. - **Default:** `-1` - **`model.summarizeToolOutput`** (object): - - **Description:** Enables or disables the summarization of tool output. You can specify the token budget for the summarization using the `tokenBudget` setting. Note: Currently only the `run_shell_command` tool is supported. For example `{"run_shell_command": {"tokenBudget": 2000}}` + - **Description:** Enables or disables the summarization of tool output. You + can specify the token budget for the summarization using the `tokenBudget` + setting. Note: Currently only the `run_shell_command` tool is supported. For + example `{"run_shell_command": {"tokenBudget": 2000}}` - **Default:** `undefined` - **`model.chatCompression.contextPercentageThreshold`** (number): - - **Description:** Sets the threshold for chat history compression as a percentage of the model's total token limit. This is a value between 0 and 1 that applies to both automatic compression and the manual `/compress` command. For example, a value of `0.6` will trigger compression when the chat history exceeds 60% of the token limit. + - **Description:** Sets the threshold for chat history compression as a + percentage of the model's total token limit. This is a value between 0 and 1 + that applies to both automatic compression and the manual `/compress` + command. For example, a value of `0.6` will trigger compression when the + chat history exceeds 60% of the token limit. - **Default:** `0.7` - **`model.skipNextSpeakerCheck`** (boolean): @@ -180,11 +227,15 @@ Settings are organized into categories. All settings should be placed within the - **Default:** `200` - **`context.includeDirectories`** (array): - - **Description:** Additional directories to include in the workspace context. Missing directories will be skipped with a warning. + - **Description:** Additional directories to include in the workspace context. + Missing directories will be skipped with a warning. - **Default:** `[]` - **`context.loadFromIncludeDirectories`** (boolean): - - **Description:** Controls the behavior of the `/memory refresh` command. If set to `true`, `GEMINI.md` files should be loaded from all directories that are added. If set to `false`, `GEMINI.md` should only be loaded from the current directory. + - **Description:** Controls the behavior of the `/memory refresh` command. If + set to `true`, `GEMINI.md` files should be loaded from all directories that + are added. If set to `false`, `GEMINI.md` should only be loaded from the + current directory. - **Default:** `false` - **`context.fileFiltering.respectGitIgnore`** (boolean): @@ -196,21 +247,28 @@ Settings are organized into categories. All settings should be placed within the - **Default:** `true` - **`context.fileFiltering.enableRecursiveFileSearch`** (boolean): - - **Description:** Whether to enable searching recursively for filenames under the current tree when completing `@` prefixes in the prompt. + - **Description:** Whether to enable searching recursively for filenames under + the current tree when completing `@` prefixes in the prompt. - **Default:** `true` #### `tools` - **`tools.sandbox`** (boolean or string): - - **Description:** Sandbox execution environment (can be a boolean or a path string). + - **Description:** Sandbox execution environment (can be a boolean or a path + string). - **Default:** `undefined` - **`tools.shell.enableInteractiveShell`** (boolean): - - **Description:** Enables interactive terminal for running shell commands. If an interactive session cannot be started, it will fall back to a standard shell. + - **Description:** Enables interactive terminal for running shell commands. If + an interactive session cannot be started, it will fall back to a standard + shell. - **Default:** `true` - **`tools.core`** (array of strings): - - **Description:** This can be used to restrict the set of built-in tools [with an allowlist](../cli/enterprise.md#restricting-tool-access). See [Built-in Tools](../core/tools-api.md#built-in-tools) for a list of core tools. The match semantics are the same as `tools.allowed`. + - **Description:** This can be used to restrict the set of built-in tools + [with an allowlist](../cli/enterprise.md#restricting-tool-access). See + [Built-in Tools](../core/tools-api.md#built-in-tools) for a list of core + tools. The match semantics are the same as `tools.allowed`. - **Default:** `undefined` - **`tools.exclude`** (array of strings): @@ -218,7 +276,12 @@ Settings are organized into categories. All settings should be placed within the - **Default:** `undefined` - **`tools.allowed`** (array of strings): - - **Description:** A list of tool names that will bypass the confirmation dialog. This is useful for tools that you trust and use frequently. For example, `["run_shell_command(git)", "run_shell_command(npm test)"]` will skip the confirmation dialog to run any `git` and `npm test` commands. See [Shell Tool command restrictions](../tools/shell.md#command-restrictions) for details on prefix matching, command chaining, etc. + - **Description:** A list of tool names that will bypass the confirmation + dialog. This is useful for tools that you trust and use frequently. For + example, `["run_shell_command(git)", "run_shell_command(npm test)"]` will + skip the confirmation dialog to run any `git` and `npm test` commands. See + [Shell Tool command restrictions](../tools/shell.md#command-restrictions) + for details on prefix matching, command chaining, etc. - **Default:** `undefined` - **`tools.discoveryCommand`** (string): @@ -226,10 +289,16 @@ Settings are organized into categories. All settings should be placed within the - **Default:** `undefined` - **`tools.callCommand`** (string): - - **Description:** Defines a custom shell command for calling a specific tool that was discovered using `tools.discoveryCommand`. The shell command must meet the following criteria: - - It must take function `name` (exactly as in [function declaration](https://ai.google.dev/gemini-api/docs/function-calling#function-declarations)) as the first command line argument. - - It must read function arguments as JSON on `stdin`, analogous to [`functionCall.args`](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#functioncall). - - It must return function output as JSON on `stdout`, analogous to [`functionResponse.response.content`](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#functionresponse). + - **Description:** Defines a custom shell command for calling a specific tool + that was discovered using `tools.discoveryCommand`. The shell command must + meet the following criteria: + - It must take function `name` (exactly as in + [function declaration](https://ai.google.dev/gemini-api/docs/function-calling#function-declarations)) + as the first command line argument. + - It must read function arguments as JSON on `stdin`, analogous to + [`functionCall.args`](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#functioncall). + - It must return function output as JSON on `stdout`, analogous to + [`functionResponse.response.content`](https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference#functionresponse). - **Default:** `undefined` #### `mcp` @@ -284,38 +353,69 @@ Settings are organized into categories. All settings should be placed within the #### `mcpServers` -Configures connections to one or more Model-Context Protocol (MCP) servers for discovering and using custom tools. Gemini CLI attempts to connect to each configured MCP server to discover available tools. If multiple MCP servers expose a tool with the same name, the tool names will be prefixed with the server alias you defined in the configuration (e.g., `serverAlias__actualToolName`) to avoid conflicts. Note that the system might strip certain schema properties from MCP tool definitions for compatibility. At least one of `command`, `url`, or `httpUrl` must be provided. If multiple are specified, the order of precedence is `httpUrl`, then `url`, then `command`. +Configures connections to one or more Model-Context Protocol (MCP) servers for +discovering and using custom tools. Gemini CLI attempts to connect to each +configured MCP server to discover available tools. If multiple MCP servers +expose a tool with the same name, the tool names will be prefixed with the +server alias you defined in the configuration (e.g., +`serverAlias__actualToolName`) to avoid conflicts. Note that the system might +strip certain schema properties from MCP tool definitions for compatibility. At +least one of `command`, `url`, or `httpUrl` must be provided. If multiple are +specified, the order of precedence is `httpUrl`, then `url`, then `command`. -- **`mcpServers.`** (object): The server parameters for the named server. - - `command` (string, optional): The command to execute to start the MCP server via standard I/O. +- **`mcpServers.`** (object): The server parameters for the named + server. + - `command` (string, optional): The command to execute to start the MCP server + via standard I/O. - `args` (array of strings, optional): Arguments to pass to the command. - - `env` (object, optional): Environment variables to set for the server process. - - `cwd` (string, optional): The working directory in which to start the server. - - `url` (string, optional): The URL of an MCP server that uses Server-Sent Events (SSE) for communication. - - `httpUrl` (string, optional): The URL of an MCP server that uses streamable HTTP for communication. - - `headers` (object, optional): A map of HTTP headers to send with requests to `url` or `httpUrl`. - - `timeout` (number, optional): Timeout in milliseconds for requests to this MCP server. - - `trust` (boolean, optional): Trust this server and bypass all tool call confirmations. - - `description` (string, optional): A brief description of the server, which may be used for display purposes. - - `includeTools` (array of strings, optional): List of tool names to include from this MCP server. When specified, only the tools listed here will be available from this server (allowlist behavior). If not specified, all tools from the server are enabled by default. - - `excludeTools` (array of strings, optional): List of tool names to exclude from this MCP server. Tools listed here will not be available to the model, even if they are exposed by the server. **Note:** `excludeTools` takes precedence over `includeTools` - if a tool is in both lists, it will be excluded. + - `env` (object, optional): Environment variables to set for the server + process. + - `cwd` (string, optional): The working directory in which to start the + server. + - `url` (string, optional): The URL of an MCP server that uses Server-Sent + Events (SSE) for communication. + - `httpUrl` (string, optional): The URL of an MCP server that uses streamable + HTTP for communication. + - `headers` (object, optional): A map of HTTP headers to send with requests to + `url` or `httpUrl`. + - `timeout` (number, optional): Timeout in milliseconds for requests to this + MCP server. + - `trust` (boolean, optional): Trust this server and bypass all tool call + confirmations. + - `description` (string, optional): A brief description of the server, which + may be used for display purposes. + - `includeTools` (array of strings, optional): List of tool names to include + from this MCP server. When specified, only the tools listed here will be + available from this server (allowlist behavior). If not specified, all tools + from the server are enabled by default. + - `excludeTools` (array of strings, optional): List of tool names to exclude + from this MCP server. Tools listed here will not be available to the model, + even if they are exposed by the server. **Note:** `excludeTools` takes + precedence over `includeTools` - if a tool is in both lists, it will be + excluded. #### `telemetry` -Configures logging and metrics collection for Gemini CLI. For more information, see [Telemetry](../cli/telemetry.md). +Configures logging and metrics collection for Gemini CLI. For more information, +see [Telemetry](../cli/telemetry.md). - **Properties:** - **`enabled`** (boolean): Whether or not telemetry is enabled. - - **`target`** (string): The destination for collected telemetry. Supported values are `local` and `gcp`. + - **`target`** (string): The destination for collected telemetry. Supported + values are `local` and `gcp`. - **`otlpEndpoint`** (string): The endpoint for the OTLP Exporter. - - **`otlpProtocol`** (string): The protocol for the OTLP Exporter (`grpc` or `http`). - - **`logPrompts`** (boolean): Whether or not to include the content of user prompts in the logs. - - **`outfile`** (string): The file to write telemetry to when `target` is `local`. + - **`otlpProtocol`** (string): The protocol for the OTLP Exporter (`grpc` or + `http`). + - **`logPrompts`** (boolean): Whether or not to include the content of user + prompts in the logs. + - **`outfile`** (string): The file to write telemetry to when `target` is + `local`. - **`useCollector`** (boolean): Whether to use an external OTLP collector. ### Example `settings.json` -Here is an example of a `settings.json` file with the nested structure, new as of v0.3.0: +Here is an example of a `settings.json` file with the nested structure, new as +of v0.3.0: ```json { @@ -381,28 +481,43 @@ Here is an example of a `settings.json` file with the nested structure, new as o ## Shell History -The CLI keeps a history of shell commands you run. To avoid conflicts between different projects, this history is stored in a project-specific directory within your user's home folder. +The CLI keeps a history of shell commands you run. To avoid conflicts between +different projects, this history is stored in a project-specific directory +within your user's home folder. - **Location:** `~/.gemini/tmp//shell_history` - - `` is a unique identifier generated from your project's root path. + - `` is a unique identifier generated from your project's root + path. - The history is stored in a file named `shell_history`. ## Environment Variables & `.env` Files -Environment variables are a common way to configure applications, especially for sensitive information like API keys or for settings that might change between environments. For authentication setup, see the [Authentication documentation](./authentication.md) which covers all available authentication methods. +Environment variables are a common way to configure applications, especially for +sensitive information like API keys or for settings that might change between +environments. For authentication setup, see the +[Authentication documentation](./authentication.md) which covers all available +authentication methods. -The CLI automatically loads environment variables from an `.env` file. The loading order is: +The CLI automatically loads environment variables from an `.env` file. The +loading order is: 1. `.env` file in the current working directory. -2. If not found, it searches upwards in parent directories until it finds an `.env` file or reaches the project root (identified by a `.git` folder) or the home directory. +2. If not found, it searches upwards in parent directories until it finds an + `.env` file or reaches the project root (identified by a `.git` folder) or + the home directory. 3. If still not found, it looks for `~/.env` (in the user's home directory). -**Environment Variable Exclusion:** Some environment variables (like `DEBUG` and `DEBUG_MODE`) are automatically excluded from being loaded from project `.env` files to prevent interference with gemini-cli behavior. Variables from `.gemini/.env` files are never excluded. You can customize this behavior using the `advanced.excludedEnvVars` setting in your `settings.json` file. +**Environment Variable Exclusion:** Some environment variables (like `DEBUG` and +`DEBUG_MODE`) are automatically excluded from being loaded from project `.env` +files to prevent interference with gemini-cli behavior. Variables from +`.gemini/.env` files are never excluded. You can customize this behavior using +the `advanced.excludedEnvVars` setting in your `settings.json` file. - **`GEMINI_API_KEY`**: - Your API key for the Gemini API. - One of several available [authentication methods](./authentication.md). - - Set this in your shell profile (e.g., `~/.bashrc`, `~/.zshrc`) or an `.env` file. + - Set this in your shell profile (e.g., `~/.bashrc`, `~/.zshrc`) or an `.env` + file. - **`GEMINI_MODEL`**: - Specifies the default Gemini model to use. - Overrides the hardcoded default @@ -415,17 +530,24 @@ The CLI automatically loads environment variables from an `.env` file. The loadi - **`GOOGLE_CLOUD_PROJECT`**: - Your Google Cloud Project ID. - Required for using Code Assist or Vertex AI. - - If using Vertex AI, ensure you have the necessary permissions in this project. - - **Cloud Shell Note:** When running in a Cloud Shell environment, this variable defaults to a special project allocated for Cloud Shell users. If you have `GOOGLE_CLOUD_PROJECT` set in your global environment in Cloud Shell, it will be overridden by this default. To use a different project in Cloud Shell, you must define `GOOGLE_CLOUD_PROJECT` in a `.env` file. + - If using Vertex AI, ensure you have the necessary permissions in this + project. + - **Cloud Shell Note:** When running in a Cloud Shell environment, this + variable defaults to a special project allocated for Cloud Shell users. If + you have `GOOGLE_CLOUD_PROJECT` set in your global environment in Cloud + Shell, it will be overridden by this default. To use a different project in + Cloud Shell, you must define `GOOGLE_CLOUD_PROJECT` in a `.env` file. - Example: `export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"`. - **`GOOGLE_APPLICATION_CREDENTIALS`** (string): - **Description:** The path to your Google Application Credentials JSON file. - - **Example:** `export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/credentials.json"` + - **Example:** + `export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/credentials.json"` - **`OTLP_GOOGLE_CLOUD_PROJECT`**: - Your Google Cloud Project ID for Telemetry in Google Cloud - Example: `export OTLP_GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"`. - **`GEMINI_TELEMETRY_ENABLED`**: - - Set to `true` or `1` to enable telemetry. Any other value is treated as disabling it. + - Set to `true` or `1` to enable telemetry. Any other value is treated as + disabling it. - Overrides the `telemetry.enabled` setting. - **`GEMINI_TELEMETRY_TARGET`**: - Sets the telemetry target (`local` or `gcp`). @@ -437,13 +559,15 @@ The CLI automatically loads environment variables from an `.env` file. The loadi - Sets the OTLP protocol (`grpc` or `http`). - Overrides the `telemetry.otlpProtocol` setting. - **`GEMINI_TELEMETRY_LOG_PROMPTS`**: - - Set to `true` or `1` to enable or disable logging of user prompts. Any other value is treated as disabling it. + - Set to `true` or `1` to enable or disable logging of user prompts. Any other + value is treated as disabling it. - Overrides the `telemetry.logPrompts` setting. - **`GEMINI_TELEMETRY_OUTFILE`**: - Sets the file path to write telemetry to when the target is `local`. - Overrides the `telemetry.outfile` setting. - **`GEMINI_TELEMETRY_USE_COLLECTOR`**: - - Set to `true` or `1` to enable or disable using an external OTLP collector. Any other value is treated as disabling it. + - Set to `true` or `1` to enable or disable using an external OTLP collector. + Any other value is treated as disabling it. - Overrides the `telemetry.useCollector` setting. - **`GOOGLE_CLOUD_LOCATION`**: - Your Google Cloud Project Location (e.g., us-central1). @@ -454,12 +578,21 @@ The CLI automatically loads environment variables from an `.env` file. The loadi - Accepts `true`, `false`, `docker`, `podman`, or a custom command string. - **`SEATBELT_PROFILE`** (macOS specific): - Switches the Seatbelt (`sandbox-exec`) profile on macOS. - - `permissive-open`: (Default) Restricts writes to the project folder (and a few other folders, see `packages/cli/src/utils/sandbox-macos-permissive-open.sb`) but allows other operations. + - `permissive-open`: (Default) Restricts writes to the project folder (and a + few other folders, see + `packages/cli/src/utils/sandbox-macos-permissive-open.sb`) but allows other + operations. - `strict`: Uses a strict profile that declines operations by default. - - ``: Uses a custom profile. To define a custom profile, create a file named `sandbox-macos-.sb` in your project's `.gemini/` directory (e.g., `my-project/.gemini/sandbox-macos-custom.sb`). -- **`DEBUG` or `DEBUG_MODE`** (often used by underlying libraries or the CLI itself): - - Set to `true` or `1` to enable verbose debug logging, which can be helpful for troubleshooting. - - **Note:** These variables are automatically excluded from project `.env` files by default to prevent interference with gemini-cli behavior. Use `.gemini/.env` files if you need to set these for gemini-cli specifically. + - ``: Uses a custom profile. To define a custom profile, create + a file named `sandbox-macos-.sb` in your project's `.gemini/` + directory (e.g., `my-project/.gemini/sandbox-macos-custom.sb`). +- **`DEBUG` or `DEBUG_MODE`** (often used by underlying libraries or the CLI + itself): + - Set to `true` or `1` to enable verbose debug logging, which can be helpful + for troubleshooting. + - **Note:** These variables are automatically excluded from project `.env` + files by default to prevent interference with gemini-cli behavior. Use + `.gemini/.env` files if you need to set these for gemini-cli specifically. - **`NO_COLOR`**: - Set to any value to disable all color output in the CLI. - **`CLI_TITLE`**: @@ -470,25 +603,30 @@ The CLI automatically loads environment variables from an `.env` file. The loadi ## Command-Line Arguments -Arguments passed directly when running the CLI can override other configurations for that specific session. +Arguments passed directly when running the CLI can override other configurations +for that specific session. - **`--model `** (**`-m `**): - Specifies the Gemini model to use for this session. - Example: `npm start -- --model gemini-1.5-pro-latest` - **`--prompt `** (**`-p `**): - - Used to pass a prompt directly to the command. This invokes Gemini CLI in a non-interactive mode. - - For scripting examples, use the `--output-format json` flag to get structured output. + - Used to pass a prompt directly to the command. This invokes Gemini CLI in a + non-interactive mode. + - For scripting examples, use the `--output-format json` flag to get + structured output. - **`--prompt-interactive `** (**`-i `**): - Starts an interactive session with the provided prompt as the initial input. - The prompt is processed within the interactive session, not before it. - Cannot be used when piping input from stdin. - Example: `gemini -i "explain this code"` - **`--output-format `**: - - **Description:** Specifies the format of the CLI output for non-interactive mode. + - **Description:** Specifies the format of the CLI output for non-interactive + mode. - **Values:** - `text`: (Default) The standard human-readable output. - `json`: A machine-readable JSON output. - - **Note:** For structured output and scripting, use the `--output-format json` flag. + - **Note:** For structured output and scripting, use the + `--output-format json` flag. - **`--sandbox`** (**`-s`**): - Enables sandbox mode for this session. - **`--sandbox-image`**: @@ -496,7 +634,8 @@ Arguments passed directly when running the CLI can override other configurations - **`--debug`** (**`-d`**): - Enables debug mode for this session, providing more verbose output. - **`--all-files`** (**`-a`**): - - If set, recursively includes all files within the current directory as context for the prompt. + - If set, recursively includes all files within the current directory as + context for the prompt. - **`--help`** (or **`-h`**): - Displays help information about command-line arguments. - **`--show-memory-usage`**: @@ -506,27 +645,35 @@ Arguments passed directly when running the CLI can override other configurations - **`--approval-mode `**: - Sets the approval mode for tool calls. Available modes: - `default`: Prompt for approval on each tool call (default behavior) - - `auto_edit`: Automatically approve edit tools (replace, write_file) while prompting for others + - `auto_edit`: Automatically approve edit tools (replace, write_file) while + prompting for others - `yolo`: Automatically approve all tool calls (equivalent to `--yolo`) - - Cannot be used together with `--yolo`. Use `--approval-mode=yolo` instead of `--yolo` for the new unified approach. + - Cannot be used together with `--yolo`. Use `--approval-mode=yolo` instead of + `--yolo` for the new unified approach. - Example: `gemini --approval-mode auto_edit` - **`--allowed-tools `**: - - A comma-separated list of tool names that will bypass the confirmation dialog. + - A comma-separated list of tool names that will bypass the confirmation + dialog. - Example: `gemini --allowed-tools "ShellTool(git status)"` - **`--telemetry`**: - Enables [telemetry](../cli/telemetry.md). - **`--telemetry-target`**: - - Sets the telemetry target. See [telemetry](../cli/telemetry.md) for more information. + - Sets the telemetry target. See [telemetry](../cli/telemetry.md) for more + information. - **`--telemetry-otlp-endpoint`**: - - Sets the OTLP endpoint for telemetry. See [telemetry](../cli/telemetry.md) for more information. + - Sets the OTLP endpoint for telemetry. See [telemetry](../cli/telemetry.md) + for more information. - **`--telemetry-otlp-protocol`**: - - Sets the OTLP protocol for telemetry (`grpc` or `http`). Defaults to `grpc`. See [telemetry](../cli/telemetry.md) for more information. + - Sets the OTLP protocol for telemetry (`grpc` or `http`). Defaults to `grpc`. + See [telemetry](../cli/telemetry.md) for more information. - **`--telemetry-log-prompts`**: - - Enables logging of prompts for telemetry. See [telemetry](../cli/telemetry.md) for more information. + - Enables logging of prompts for telemetry. See + [telemetry](../cli/telemetry.md) for more information. - **`--checkpointing`**: - Enables [checkpointing](../cli/checkpointing.md). - **`--extensions `** (**`-e `**): - - Specifies a list of extensions to use for the session. If not provided, all available extensions are used. + - Specifies a list of extensions to use for the session. If not provided, all + available extensions are used. - Use the special term `gemini -e none` to disable all extensions. - Example: `gemini -e my-extension -e my-other-extension` - **`--list-extensions`** (**`-l`**): @@ -535,24 +682,38 @@ Arguments passed directly when running the CLI can override other configurations - Sets the proxy for the CLI. - Example: `--proxy http://localhost:7890`. - **`--include-directories `**: - - Includes additional directories in the workspace for multi-directory support. + - Includes additional directories in the workspace for multi-directory + support. - Can be specified multiple times or as comma-separated values. - 5 directories can be added at maximum. - - Example: `--include-directories /path/to/project1,/path/to/project2` or `--include-directories /path/to/project1 --include-directories /path/to/project2` + - Example: `--include-directories /path/to/project1,/path/to/project2` or + `--include-directories /path/to/project1 --include-directories /path/to/project2` - **`--screen-reader`**: - - Enables screen reader mode, which adjusts the TUI for better compatibility with screen readers. + - Enables screen reader mode, which adjusts the TUI for better compatibility + with screen readers. - **`--version`**: - Displays the version of the CLI. ## Context Files (Hierarchical Instructional Context) -While not strictly configuration for the CLI's _behavior_, context files (defaulting to `GEMINI.md` but configurable via the `context.fileName` setting) are crucial for configuring the _instructional context_ (also referred to as "memory") provided to the Gemini model. This powerful feature allows you to give project-specific instructions, coding style guides, or any relevant background information to the AI, making its responses more tailored and accurate to your needs. The CLI includes UI elements, such as an indicator in the footer showing the number of loaded context files, to keep you informed about the active context. +While not strictly configuration for the CLI's _behavior_, context files +(defaulting to `GEMINI.md` but configurable via the `context.fileName` setting) +are crucial for configuring the _instructional context_ (also referred to as +"memory") provided to the Gemini model. This powerful feature allows you to give +project-specific instructions, coding style guides, or any relevant background +information to the AI, making its responses more tailored and accurate to your +needs. The CLI includes UI elements, such as an indicator in the footer showing +the number of loaded context files, to keep you informed about the active +context. -- **Purpose:** These Markdown files contain instructions, guidelines, or context that you want the Gemini model to be aware of during your interactions. The system is designed to manage this instructional context hierarchically. +- **Purpose:** These Markdown files contain instructions, guidelines, or context + that you want the Gemini model to be aware of during your interactions. The + system is designed to manage this instructional context hierarchically. ### Example Context File Content (e.g., `GEMINI.md`) -Here's a conceptual example of what a context file at the root of a TypeScript project might contain: +Here's a conceptual example of what a context file at the root of a TypeScript +project might contain: ```markdown # Project: My Awesome TypeScript Library @@ -574,7 +735,8 @@ Here's a conceptual example of what a context file at the root of a TypeScript p ## Specific Component: `src/api/client.ts` - This file handles all outbound API requests. -- When adding new API call functions, ensure they include robust error handling and logging. +- When adding new API call functions, ensure they include robust error handling + and logging. - Use the existing `fetchWithRetry` utility for all GET requests. ## Regarding Dependencies: @@ -583,30 +745,62 @@ Here's a conceptual example of what a context file at the root of a TypeScript p - If a new dependency is required, please state the reason. ``` -This example demonstrates how you can provide general project context, specific coding conventions, and even notes about particular files or components. The more relevant and precise your context files are, the better the AI can assist you. Project-specific context files are highly encouraged to establish conventions and context. +This example demonstrates how you can provide general project context, specific +coding conventions, and even notes about particular files or components. The +more relevant and precise your context files are, the better the AI can assist +you. Project-specific context files are highly encouraged to establish +conventions and context. -- **Hierarchical Loading and Precedence:** The CLI implements a sophisticated hierarchical memory system by loading context files (e.g., `GEMINI.md`) from several locations. Content from files lower in this list (more specific) typically overrides or supplements content from files higher up (more general). The exact concatenation order and final context can be inspected using the `/memory show` command. The typical loading order is: +- **Hierarchical Loading and Precedence:** The CLI implements a sophisticated + hierarchical memory system by loading context files (e.g., `GEMINI.md`) from + several locations. Content from files lower in this list (more specific) + typically overrides or supplements content from files higher up (more + general). The exact concatenation order and final context can be inspected + using the `/memory show` command. The typical loading order is: 1. **Global Context File:** - - Location: `~/.gemini/` (e.g., `~/.gemini/GEMINI.md` in your user home directory). + - Location: `~/.gemini/` (e.g., + `~/.gemini/GEMINI.md` in your user home directory). - Scope: Provides default instructions for all your projects. 2. **Project Root & Ancestors Context Files:** - - Location: The CLI searches for the configured context file in the current working directory and then in each parent directory up to either the project root (identified by a `.git` folder) or your home directory. - - Scope: Provides context relevant to the entire project or a significant portion of it. + - Location: The CLI searches for the configured context file in the + current working directory and then in each parent directory up to either + the project root (identified by a `.git` folder) or your home directory. + - Scope: Provides context relevant to the entire project or a significant + portion of it. 3. **Sub-directory Context Files (Contextual/Local):** - - Location: The CLI also scans for the configured context file in subdirectories _below_ the current working directory (respecting common ignore patterns like `node_modules`, `.git`, etc.). The breadth of this search is limited to 200 directories by default, but can be configured with the `context.discoveryMaxDirs` setting in your `settings.json` file. - - Scope: Allows for highly specific instructions relevant to a particular component, module, or subsection of your project. -- **Concatenation & UI Indication:** The contents of all found context files are concatenated (with separators indicating their origin and path) and provided as part of the system prompt to the Gemini model. The CLI footer displays the count of loaded context files, giving you a quick visual cue about the active instructional context. -- **Importing Content:** You can modularize your context files by importing other Markdown files using the `@path/to/file.md` syntax. For more details, see the [Memory Import Processor documentation](../core/memport.md). + - Location: The CLI also scans for the configured context file in + subdirectories _below_ the current working directory (respecting common + ignore patterns like `node_modules`, `.git`, etc.). The breadth of this + search is limited to 200 directories by default, but can be configured + with the `context.discoveryMaxDirs` setting in your `settings.json` + file. + - Scope: Allows for highly specific instructions relevant to a particular + component, module, or subsection of your project. +- **Concatenation & UI Indication:** The contents of all found context files are + concatenated (with separators indicating their origin and path) and provided + as part of the system prompt to the Gemini model. The CLI footer displays the + count of loaded context files, giving you a quick visual cue about the active + instructional context. +- **Importing Content:** You can modularize your context files by importing + other Markdown files using the `@path/to/file.md` syntax. For more details, + see the [Memory Import Processor documentation](../core/memport.md). - **Commands for Memory Management:** - - Use `/memory refresh` to force a re-scan and reload of all context files from all configured locations. This updates the AI's instructional context. - - Use `/memory show` to display the combined instructional context currently loaded, allowing you to verify the hierarchy and content being used by the AI. - - See the [Commands documentation](../cli/commands.md#memory) for full details on the `/memory` command and its sub-commands (`show` and `refresh`). + - Use `/memory refresh` to force a re-scan and reload of all context files + from all configured locations. This updates the AI's instructional context. + - Use `/memory show` to display the combined instructional context currently + loaded, allowing you to verify the hierarchy and content being used by the + AI. + - See the [Commands documentation](../cli/commands.md#memory) for full details + on the `/memory` command and its sub-commands (`show` and `refresh`). -By understanding and utilizing these configuration layers and the hierarchical nature of context files, you can effectively manage the AI's memory and tailor the Gemini CLI's responses to your specific needs and projects. +By understanding and utilizing these configuration layers and the hierarchical +nature of context files, you can effectively manage the AI's memory and tailor +the Gemini CLI's responses to your specific needs and projects. ## Sandboxing -The Gemini CLI can execute potentially unsafe operations (like shell commands and file modifications) within a sandboxed environment to protect your system. +The Gemini CLI can execute potentially unsafe operations (like shell commands +and file modifications) within a sandboxed environment to protect your system. Sandboxing is disabled by default, but you can enable it in a few ways: @@ -616,7 +810,9 @@ Sandboxing is disabled by default, but you can enable it in a few ways: By default, it uses a pre-built `gemini-cli-sandbox` Docker image. -For project-specific sandboxing needs, you can create a custom Dockerfile at `.gemini/sandbox.Dockerfile` in your project's root directory. This Dockerfile can be based on the base sandbox image: +For project-specific sandboxing needs, you can create a custom Dockerfile at +`.gemini/sandbox.Dockerfile` in your project's root directory. This Dockerfile +can be based on the base sandbox image: ```dockerfile FROM gemini-cli-sandbox @@ -627,7 +823,9 @@ FROM gemini-cli-sandbox # COPY ./my-config /app/my-config ``` -When `.gemini/sandbox.Dockerfile` exists, you can use `BUILD_SANDBOX` environment variable when running Gemini CLI to automatically build the custom sandbox image: +When `.gemini/sandbox.Dockerfile` exists, you can use `BUILD_SANDBOX` +environment variable when running Gemini CLI to automatically build the custom +sandbox image: ```bash BUILD_SANDBOX=1 gemini -s @@ -635,23 +833,35 @@ BUILD_SANDBOX=1 gemini -s ## Usage Statistics -To help us improve the Gemini CLI, we collect anonymized usage statistics. This data helps us understand how the CLI is used, identify common issues, and prioritize new features. +To help us improve the Gemini CLI, we collect anonymized usage statistics. This +data helps us understand how the CLI is used, identify common issues, and +prioritize new features. **What we collect:** -- **Tool Calls:** We log the names of the tools that are called, whether they succeed or fail, and how long they take to execute. We do not collect the arguments passed to the tools or any data returned by them. -- **API Requests:** We log the Gemini model used for each request, the duration of the request, and whether it was successful. We do not collect the content of the prompts or responses. -- **Session Information:** We collect information about the configuration of the CLI, such as the enabled tools and the approval mode. +- **Tool Calls:** We log the names of the tools that are called, whether they + succeed or fail, and how long they take to execute. We do not collect the + arguments passed to the tools or any data returned by them. +- **API Requests:** We log the Gemini model used for each request, the duration + of the request, and whether it was successful. We do not collect the content + of the prompts or responses. +- **Session Information:** We collect information about the configuration of the + CLI, such as the enabled tools and the approval mode. **What we DON'T collect:** -- **Personally Identifiable Information (PII):** We do not collect any personal information, such as your name, email address, or API keys. -- **Prompt and Response Content:** We do not log the content of your prompts or the responses from the Gemini model. -- **File Content:** We do not log the content of any files that are read or written by the CLI. +- **Personally Identifiable Information (PII):** We do not collect any personal + information, such as your name, email address, or API keys. +- **Prompt and Response Content:** We do not log the content of your prompts or + the responses from the Gemini model. +- **File Content:** We do not log the content of any files that are read or + written by the CLI. **How to opt out:** -You can opt out of usage statistics collection at any time by setting the `usageStatisticsEnabled` property to `false` under the `privacy` category in your `settings.json` file: +You can opt out of usage statistics collection at any time by setting the +`usageStatisticsEnabled` property to `false` under the `privacy` category in +your `settings.json` file: ```json { diff --git a/docs/get-started/deployment.md b/docs/get-started/deployment.md index e535bdf4b8..1ea278ccc4 100644 --- a/docs/get-started/deployment.md +++ b/docs/get-started/deployment.md @@ -4,15 +4,18 @@ This document describes how to run Gemini CLI and its deployment architecture. ## Running Gemini CLI -There are several ways to run Gemini CLI. The option you choose depends on how you intend to use Gemini CLI. +There are several ways to run Gemini CLI. The option you choose depends on how +you intend to use Gemini CLI. -- As a standard installation. This is the most straightforward method of using Gemini CLI. +- As a standard installation. This is the most straightforward method of using + Gemini CLI. - In a sandbox. This method offers increased security and isolation. - From the source. This is recommended for contributors to the project. ### 1. Standard installation (recommended for standard users) -This is the recommended way for end-users to install Gemini CLI. It involves downloading the Gemini CLI package from the NPM registry. +This is the recommended way for end-users to install Gemini CLI. It involves +downloading the Gemini CLI package from the NPM registry. - **Global install:** @@ -35,32 +38,37 @@ This is the recommended way for end-users to install Gemini CLI. It involves dow ### 2. Run in a sandbox (Docker/Podman) -For security and isolation, Gemini CLI can be run inside a container. This is the default way that the CLI executes tools that might have side effects. +For security and isolation, Gemini CLI can be run inside a container. This is +the default way that the CLI executes tools that might have side effects. -- **Directly from the Registry:** - You can run the published sandbox image directly. This is useful for environments where you only have Docker and want to run the CLI. +- **Directly from the Registry:** You can run the published sandbox image + directly. This is useful for environments where you only have Docker and want + to run the CLI. ```bash # Run the published sandbox image docker run --rm -it us-docker.pkg.dev/gemini-code-dev/gemini-cli/sandbox:0.1.1 ``` -- **Using the `--sandbox` flag:** - If you have Gemini CLI installed locally (using the standard installation described above), you can instruct it to run inside the sandbox container. +- **Using the `--sandbox` flag:** If you have Gemini CLI installed locally + (using the standard installation described above), you can instruct it to run + inside the sandbox container. ```bash gemini --sandbox -y -p "your prompt here" ``` ### 3. Run from source (recommended for Gemini CLI contributors) -Contributors to the project will want to run the CLI directly from the source code. +Contributors to the project will want to run the CLI directly from the source +code. -- **Development Mode:** - This method provides hot-reloading and is useful for active development. +- **Development Mode:** This method provides hot-reloading and is useful for + active development. ```bash # From the root of the repository npm run start ``` -- **Production-like mode (Linked package):** - This method simulates a global installation by linking your local package. It's useful for testing a local build in a production workflow. +- **Production-like mode (Linked package):** This method simulates a global + installation by linking your local package. It's useful for testing a local + build in a production workflow. ```bash # Link the local cli package to your global node_modules @@ -74,7 +82,8 @@ Contributors to the project will want to run the CLI directly from the source co ### 4. Running the latest Gemini CLI commit from GitHub -You can run the most recently committed version of Gemini CLI directly from the GitHub repository. This is useful for testing features still in development. +You can run the most recently committed version of Gemini CLI directly from the +GitHub repository. This is useful for testing features still in development. ```bash # Execute the CLI directly from the main branch on GitHub @@ -83,32 +92,48 @@ npx https://github.com/google-gemini/gemini-cli ## Deployment architecture -The execution methods described above are made possible by the following architectural components and processes: +The execution methods described above are made possible by the following +architectural components and processes: **NPM packages** -Gemini CLI project is a monorepo that publishes two core packages to the NPM registry: +Gemini CLI project is a monorepo that publishes two core packages to the NPM +registry: - `@google/gemini-cli-core`: The backend, handling logic and tool execution. - `@google/gemini-cli`: The user-facing frontend. -These packages are used when performing the standard installation and when running Gemini CLI from the source. +These packages are used when performing the standard installation and when +running Gemini CLI from the source. **Build and packaging processes** -There are two distinct build processes used, depending on the distribution channel: +There are two distinct build processes used, depending on the distribution +channel: -- **NPM publication:** For publishing to the NPM registry, the TypeScript source code in `@google/gemini-cli-core` and `@google/gemini-cli` is transpiled into standard JavaScript using the TypeScript Compiler (`tsc`). The resulting `dist/` directory is what gets published in the NPM package. This is a standard approach for TypeScript libraries. +- **NPM publication:** For publishing to the NPM registry, the TypeScript source + code in `@google/gemini-cli-core` and `@google/gemini-cli` is transpiled into + standard JavaScript using the TypeScript Compiler (`tsc`). The resulting + `dist/` directory is what gets published in the NPM package. This is a + standard approach for TypeScript libraries. -- **GitHub `npx` execution:** When running the latest version of Gemini CLI directly from GitHub, a different process is triggered by the `prepare` script in `package.json`. This script uses `esbuild` to bundle the entire application and its dependencies into a single, self-contained JavaScript file. This bundle is created on-the-fly on the user's machine and is not checked into the repository. +- **GitHub `npx` execution:** When running the latest version of Gemini CLI + directly from GitHub, a different process is triggered by the `prepare` script + in `package.json`. This script uses `esbuild` to bundle the entire application + and its dependencies into a single, self-contained JavaScript file. This + bundle is created on-the-fly on the user's machine and is not checked into the + repository. **Docker sandbox image** -The Docker-based execution method is supported by the `gemini-cli-sandbox` container image. This image is published to a container registry and contains a pre-installed, global version of Gemini CLI. +The Docker-based execution method is supported by the `gemini-cli-sandbox` +container image. This image is published to a container registry and contains a +pre-installed, global version of Gemini CLI. ## Release process -The release process is automated through GitHub Actions. The release workflow performs the following actions: +The release process is automated through GitHub Actions. The release workflow +performs the following actions: 1. Build the NPM packages using `tsc`. 2. Publish the NPM packages to the artifact registry. diff --git a/docs/get-started/examples.md b/docs/get-started/examples.md index 3383cc25a9..bd87c16590 100644 --- a/docs/get-started/examples.md +++ b/docs/get-started/examples.md @@ -1,8 +1,10 @@ # Gemini CLI Examples -Not sure where to get started with Gemini CLI? This document covers examples on how to use Gemini CLI for a variety of tasks. +Not sure where to get started with Gemini CLI? This document covers examples on +how to use Gemini CLI for a variety of tasks. -**Note:** Results are examples intended to showcase potential use cases. Your results may vary. +**Note:** Results are examples intended to showcase potential use cases. Your +results may vary. ## Rename your photographs based on content @@ -32,7 +34,8 @@ photos/green_android_robot.png ## Explain a repository by reading its code -Scenario: You want to understand how a popular open-source utility works by inspecting its code, not just its README. +Scenario: You want to understand how a popular open-source utility works by +inspecting its code, not just its README. Give Gemini CLI the following prompt: @@ -42,25 +45,37 @@ Clone the 'chalk' repository from https://github.com/chalk/chalk, read its key s Result: Gemini will perform a sequence of actions to answer your request. -1. First, it will ask for permission to run `git clone` to download the repository. -2. Next, it will find the important source files and ask for permission to read them. +1. First, it will ask for permission to run `git clone` to download the + repository. +2. Next, it will find the important source files and ask for permission to read + them. 3. Finally, after analyzing the code, it will provide a summary. Gemini CLI will return an explanation based on the actual source code: ```markdown -The `chalk` library is a popular npm package for styling terminal output with colors. After analyzing the source code, here's how it works: +The `chalk` library is a popular npm package for styling terminal output with +colors. After analyzing the source code, here's how it works: -- **Core Functionality:** The main file sets up a chainable API. Each color or modifier (like `bold` or `italic`) is a getter that appends the corresponding ANSI escape code to an internal stack. +- **Core Functionality:** The main file sets up a chainable API. Each color or + modifier (like `bold` or `italic`) is a getter that appends the corresponding + ANSI escape code to an internal stack. -- **Chainable API:** When you call `chalk.red.bold('Hello')`, you are accessing getters. The `red` getter adds the red color code, and the `bold` getter adds the bold code. +- **Chainable API:** When you call `chalk.red.bold('Hello')`, you are accessing + getters. The `red` getter adds the red color code, and the `bold` getter adds + the bold code. -- **Output Generation:** When the chain is treated as a string (e.g., in `console.log`), a final `toString()` method is called. This method joins all the stored ANSI codes, wraps them around the input string ('Hello'), and adds a reset code at the end. This produces the final, styled string that the terminal can render. +- **Output Generation:** When the chain is treated as a string (e.g., in + `console.log`), a final `toString()` method is called. This method joins all + the stored ANSI codes, wraps them around the input string ('Hello'), and adds + a reset code at the end. This produces the final, styled string that the + terminal can render. ``` ## Combine two spreadsheets into one spreadsheet -Scenario: You have two .csv files: `Revenue - 2023.csv` and `Revenue - 2024.csv`. Each file contains monthly revenue figures, like so: +Scenario: You have two .csv files: `Revenue - 2023.csv` and +`Revenue - 2024.csv`. Each file contains monthly revenue figures, like so: ```csv January,0 @@ -85,7 +100,9 @@ Give Gemini CLI the following prompt: Combine the two .csv files into a single .csv file, with each year a different column. ``` -Result: Gemini CLI will read each file and then ask for permission to write a new file. Provide your permission and Gemini CLI will provide the following .csv: +Result: Gemini CLI will read each file and then ask for permission to write a +new file. Provide your permission and Gemini CLI will provide the following +.csv: ```csv Month,2023,2024 @@ -105,7 +122,8 @@ December,2100,9000 ## Run unit tests -Scenario: You've written a simple login page. You wish to write unit tests to ensure that your login page has code coverage. +Scenario: You've written a simple login page. You wish to write unit tests to +ensure that your login page has code coverage. Give Gemini CLI the following prompt: @@ -113,7 +131,8 @@ Give Gemini CLI the following prompt: Write unit tests for Login.js. ``` -Result: Gemini CLI will ask for permission to write a new file and create a test for your login page +Result: Gemini CLI will ask for permission to write a new file and create a test +for your login page ```javascript import React from 'react'; diff --git a/docs/get-started/index.md b/docs/get-started/index.md index f10d8f5101..6f1b059630 100644 --- a/docs/get-started/index.md +++ b/docs/get-started/index.md @@ -1,10 +1,14 @@ # Get Started with Gemini CLI -Welcome to Gemini CLI! This guide will help you install, configure, and start using the Gemini CLI to enhance your workflow right from your terminal. +Welcome to Gemini CLI! This guide will help you install, configure, and start +using the Gemini CLI to enhance your workflow right from your terminal. ## Quickstart: Install, authenticate, configure, and use Gemini CLI -Gemini CLI brings the power of advanced language models directly to your command line interface. As an AI-powered assistant, Gemini CLI can help you with a variety of tasks, from understanding and generating code to reviewing and editing documents. +Gemini CLI brings the power of advanced language models directly to your command +line interface. As an AI-powered assistant, Gemini CLI can help you with a +variety of tasks, from understanding and generating code to reviewing and +editing documents. ## Install @@ -20,31 +24,39 @@ Once Gemini CLI is installed, run Gemini CLI from your command line: gemini ``` -For more deployment options, see [Gemini CLI Execution and Deployment](./deployment.md). +For more deployment options, see +[Gemini CLI Execution and Deployment](./deployment.md). ## Authenticate -To begin using Gemini CLI, you must authenticate with a Google service. The most straightforward authentication method uses your existing Google account: +To begin using Gemini CLI, you must authenticate with a Google service. The most +straightforward authentication method uses your existing Google account: 1. Run Gemini CLI after installation: ```bash gemini ``` -2. When asked "How would you like to authenticate for this project?" select **1. Login with Google**. +2. When asked "How would you like to authenticate for this project?" select **1. + Login with Google**. 3. Select your Google account. 4. Click on **Sign in**. -For other authentication options and information, see [GeminI CLI Authentication Setup](./authentication.md). +For other authentication options and information, see +[GeminI CLI Authentication Setup](./authentication.md). ## Configure -Gemini CLI offers several ways to configure its behavior, including environment variables, command-line arguments, and settings files. +Gemini CLI offers several ways to configure its behavior, including environment +variables, command-line arguments, and settings files. -To explore your configuration options, see [Gemini CLI Configuration](./configuration.md). +To explore your configuration options, see +[Gemini CLI Configuration](./configuration.md). ## Use -Once installed and authenticated, you can start using Gemini CLI by issuing commands and prompts in your terminal. Ask it to generate code, explain files, and more. +Once installed and authenticated, you can start using Gemini CLI by issuing +commands and prompts in your terminal. Ask it to generate code, explain files, +and more. To explore the power of Gemini CLI, see [Gemini CLI examples](./examples.md). diff --git a/docs/ide-integration/ide-companion-spec.md b/docs/ide-integration/ide-companion-spec.md index dcc6dc4f8b..bb44605836 100644 --- a/docs/ide-integration/ide-companion-spec.md +++ b/docs/ide-integration/ide-companion-spec.md @@ -2,7 +2,12 @@ > Last Updated: September 15, 2025 -This document defines the contract for building a companion plugin to enable Gemini CLI's IDE mode. For VS Code, these features (native diffing, context awareness) are provided by the official extension ([marketplace](https://marketplace.visualstudio.com/items?itemName=Google.gemini-cli-vscode-ide-companion)). This specification is for contributors who wish to bring similar functionality to other editors like JetBrains IDEs, Sublime Text, etc. +This document defines the contract for building a companion plugin to enable +Gemini CLI's IDE mode. For VS Code, these features (native diffing, context +awareness) are provided by the official extension +([marketplace](https://marketplace.visualstudio.com/items?itemName=Google.gemini-cli-vscode-ide-companion)). +This specification is for contributors who wish to bring similar functionality +to other editors like JetBrains IDEs, Sublime Text, etc. ## I. The Communication Interface @@ -10,23 +15,35 @@ Gemini CLI and the IDE plugin communicate through a local communication channel. ### 1. Transport Layer: MCP over HTTP -The plugin **MUST** run a local HTTP server that implements the **Model Context Protocol (MCP)**. +The plugin **MUST** run a local HTTP server that implements the **Model Context +Protocol (MCP)**. -- **Protocol:** The server must be a valid MCP server. We recommend using an existing MCP SDK for your language of choice if available. -- **Endpoint:** The server should expose a single endpoint (e.g., `/mcp`) for all MCP communication. -- **Port:** The server **MUST** listen on a dynamically assigned port (i.e., listen on port `0`). +- **Protocol:** The server must be a valid MCP server. We recommend using an + existing MCP SDK for your language of choice if available. +- **Endpoint:** The server should expose a single endpoint (e.g., `/mcp`) for + all MCP communication. +- **Port:** The server **MUST** listen on a dynamically assigned port (i.e., + listen on port `0`). ### 2. Discovery Mechanism: The Port File -For Gemini CLI to connect, it needs to discover which IDE instance it's running in and what port your server is using. The plugin **MUST** facilitate this by creating a "discovery file." +For Gemini CLI to connect, it needs to discover which IDE instance it's running +in and what port your server is using. The plugin **MUST** facilitate this by +creating a "discovery file." -- **How the CLI Finds the File:** The CLI determines the Process ID (PID) of the IDE it's running in by traversing the process tree. It then looks for a discovery file that contains this PID in its name. -- **File Location:** The file must be created in a specific directory: `os.tmpdir()/gemini/ide/`. Your plugin must create this directory if it doesn't exist. -- **File Naming Convention:** The filename is critical and **MUST** follow the pattern: - `gemini-ide-server-${PID}-${PORT}.json` - - `${PID}`: The process ID of the parent IDE process. Your plugin must determine this PID and include it in the filename. +- **How the CLI Finds the File:** The CLI determines the Process ID (PID) of the + IDE it's running in by traversing the process tree. It then looks for a + discovery file that contains this PID in its name. +- **File Location:** The file must be created in a specific directory: + `os.tmpdir()/gemini/ide/`. Your plugin must create this directory if it + doesn't exist. +- **File Naming Convention:** The filename is critical and **MUST** follow the + pattern: `gemini-ide-server-${PID}-${PORT}.json` + - `${PID}`: The process ID of the parent IDE process. Your plugin must + determine this PID and include it in the filename. - `${PORT}`: The port your MCP server is listening on. -- **File Content & Workspace Validation:** The file **MUST** contain a JSON object with the following structure: +- **File Content & Workspace Validation:** The file **MUST** contain a JSON + object with the following structure: ```json { @@ -40,27 +57,54 @@ For Gemini CLI to connect, it needs to discover which IDE instance it's running } ``` - `port` (number, required): The port of the MCP server. - - `workspacePath` (string, required): A list of all open workspace root paths, delimited by the OS-specific path separator (`:` for Linux/macOS, `;` for Windows). The CLI uses this path to ensure it's running in the same project folder that's open in the IDE. If the CLI's current working directory is not a sub-directory of `workspacePath`, the connection will be rejected. Your plugin **MUST** provide the correct, absolute path(s) to the root of the open workspace(s). - - `authToken` (string, required): A secret token for securing the connection. The CLI will include this token in an `Authorization: Bearer ` header on all requests. + - `workspacePath` (string, required): A list of all open workspace root paths, + delimited by the OS-specific path separator (`:` for Linux/macOS, `;` for + Windows). The CLI uses this path to ensure it's running in the same project + folder that's open in the IDE. If the CLI's current working directory is not + a sub-directory of `workspacePath`, the connection will be rejected. Your + plugin **MUST** provide the correct, absolute path(s) to the root of the + open workspace(s). + - `authToken` (string, required): A secret token for securing the connection. + The CLI will include this token in an `Authorization: Bearer ` header + on all requests. - `ideInfo` (object, required): Information about the IDE. - - `name` (string, required): A short, lowercase identifier for the IDE (e.g., `vscode`, `jetbrains`). - - `displayName` (string, required): A user-friendly name for the IDE (e.g., `VS Code`, `JetBrains IDE`). + - `name` (string, required): A short, lowercase identifier for the IDE + (e.g., `vscode`, `jetbrains`). + - `displayName` (string, required): A user-friendly name for the IDE (e.g., + `VS Code`, `JetBrains IDE`). -- **Authentication:** To secure the connection, the plugin **MUST** generate a unique, secret token and include it in the discovery file. The CLI will then include this token in the `Authorization` header for all requests to the MCP server (e.g., `Authorization: Bearer a-very-secret-token`). Your server **MUST** validate this token on every request and reject any that are unauthorized. -- **Tie-Breaking with Environment Variables (Recommended):** For the most reliable experience, your plugin **SHOULD** both create the discovery file and set the `GEMINI_CLI_IDE_SERVER_PORT` environment variable in the integrated terminal. The file serves as the primary discovery mechanism, but the environment variable is crucial for tie-breaking. If a user has multiple IDE windows open for the same workspace, the CLI uses the `GEMINI_CLI_IDE_SERVER_PORT` variable to identify and connect to the correct window's server. +- **Authentication:** To secure the connection, the plugin **MUST** generate a + unique, secret token and include it in the discovery file. The CLI will then + include this token in the `Authorization` header for all requests to the MCP + server (e.g., `Authorization: Bearer a-very-secret-token`). Your server + **MUST** validate this token on every request and reject any that are + unauthorized. +- **Tie-Breaking with Environment Variables (Recommended):** For the most + reliable experience, your plugin **SHOULD** both create the discovery file and + set the `GEMINI_CLI_IDE_SERVER_PORT` environment variable in the integrated + terminal. The file serves as the primary discovery mechanism, but the + environment variable is crucial for tie-breaking. If a user has multiple IDE + windows open for the same workspace, the CLI uses the + `GEMINI_CLI_IDE_SERVER_PORT` variable to identify and connect to the correct + window's server. ## II. The Context Interface -To enable context awareness, the plugin **MAY** provide the CLI with real-time information about the user's activity in the IDE. +To enable context awareness, the plugin **MAY** provide the CLI with real-time +information about the user's activity in the IDE. ### `ide/contextUpdate` Notification -The plugin **MAY** send an `ide/contextUpdate` [notification](https://modelcontextprotocol.io/specification/2025-06-18/basic/index#notifications) to the CLI whenever the user's context changes. +The plugin **MAY** send an `ide/contextUpdate` +[notification](https://modelcontextprotocol.io/specification/2025-06-18/basic/index#notifications) +to the CLI whenever the user's context changes. -- **Triggering Events:** This notification should be sent (with a recommended debounce of 50ms) when: +- **Triggering Events:** This notification should be sent (with a recommended + debounce of 50ms) when: - A file is opened, closed, or focused. - The user's cursor position or text selection changes in the active file. -- **Payload (`IdeContext`):** The notification parameters **MUST** be an `IdeContext` object: +- **Payload (`IdeContext`):** The notification parameters **MUST** be an + `IdeContext` object: ```typescript interface IdeContext { @@ -88,28 +132,46 @@ The plugin **MAY** send an `ide/contextUpdate` [notification](https://modelconte } ``` - **Note:** The `openFiles` list should only include files that exist on disk. Virtual files (e.g., unsaved files without a path, editor settings pages) **MUST** be excluded. + **Note:** The `openFiles` list should only include files that exist on disk. + Virtual files (e.g., unsaved files without a path, editor settings pages) + **MUST** be excluded. ### How the CLI Uses This Context -After receiving the `IdeContext` object, the CLI performs several normalization and truncation steps before sending the information to the model. +After receiving the `IdeContext` object, the CLI performs several normalization +and truncation steps before sending the information to the model. -- **File Ordering:** The CLI uses the `timestamp` field to determine the most recently used files. It sorts the `openFiles` list based on this value. Therefore, your plugin **MUST** provide an accurate Unix timestamp for when a file was last focused. -- **Active File:** The CLI considers only the most recent file (after sorting) to be the "active" file. It will ignore the `isActive` flag on all other files and clear their `cursor` and `selectedText` fields. Your plugin should focus on setting `isActive: true` and providing cursor/selection details only for the currently focused file. -- **Truncation:** To manage token limits, the CLI truncates both the file list (to 10 files) and the `selectedText` (to 16KB). +- **File Ordering:** The CLI uses the `timestamp` field to determine the most + recently used files. It sorts the `openFiles` list based on this value. + Therefore, your plugin **MUST** provide an accurate Unix timestamp for when a + file was last focused. +- **Active File:** The CLI considers only the most recent file (after sorting) + to be the "active" file. It will ignore the `isActive` flag on all other files + and clear their `cursor` and `selectedText` fields. Your plugin should focus + on setting `isActive: true` and providing cursor/selection details only for + the currently focused file. +- **Truncation:** To manage token limits, the CLI truncates both the file list + (to 10 files) and the `selectedText` (to 16KB). -While the CLI handles the final truncation, it is highly recommended that your plugin also limits the amount of context it sends. +While the CLI handles the final truncation, it is highly recommended that your +plugin also limits the amount of context it sends. ## III. The Diffing Interface -To enable interactive code modifications, the plugin **MAY** expose a diffing interface. This allows the CLI to request that the IDE open a diff view, showing proposed changes to a file. The user can then review, edit, and ultimately accept or reject these changes directly within the IDE. +To enable interactive code modifications, the plugin **MAY** expose a diffing +interface. This allows the CLI to request that the IDE open a diff view, showing +proposed changes to a file. The user can then review, edit, and ultimately +accept or reject these changes directly within the IDE. ### `openDiff` Tool The plugin **MUST** register an `openDiff` tool on its MCP server. -- **Description:** This tool instructs the IDE to open a modifiable diff view for a specific file. -- **Request (`OpenDiffRequest`):** The tool is invoked via a `tools/call` request. The `arguments` field within the request's `params` **MUST** be an `OpenDiffRequest` object. +- **Description:** This tool instructs the IDE to open a modifiable diff view + for a specific file. +- **Request (`OpenDiffRequest`):** The tool is invoked via a `tools/call` + request. The `arguments` field within the request's `params` **MUST** be an + `OpenDiffRequest` object. ```typescript interface OpenDiffRequest { @@ -120,18 +182,27 @@ The plugin **MUST** register an `openDiff` tool on its MCP server. } ``` -- **Response (`CallToolResult`):** The tool **MUST** immediately return a `CallToolResult` to acknowledge the request and report whether the diff view was successfully opened. - - On Success: If the diff view was opened successfully, the response **MUST** contain empty content (i.e., `content: []`). - - On Failure: If an error prevented the diff view from opening, the response **MUST** have `isError: true` and include a `TextContent` block in the `content` array describing the error. +- **Response (`CallToolResult`):** The tool **MUST** immediately return a + `CallToolResult` to acknowledge the request and report whether the diff view + was successfully opened. + - On Success: If the diff view was opened successfully, the response **MUST** + contain empty content (i.e., `content: []`). + - On Failure: If an error prevented the diff view from opening, the response + **MUST** have `isError: true` and include a `TextContent` block in the + `content` array describing the error. - The actual outcome of the diff (acceptance or rejection) is communicated asynchronously via notifications. + The actual outcome of the diff (acceptance or rejection) is communicated + asynchronously via notifications. ### `closeDiff` Tool The plugin **MUST** register a `closeDiff` tool on its MCP server. -- **Description:** This tool instructs the IDE to close an open diff view for a specific file. -- **Request (`CloseDiffRequest`):** The tool is invoked via a `tools/call` request. The `arguments` field within the request's `params` **MUST** be an `CloseDiffRequest` object. +- **Description:** This tool instructs the IDE to close an open diff view for a + specific file. +- **Request (`CloseDiffRequest`):** The tool is invoked via a `tools/call` + request. The `arguments` field within the request's `params` **MUST** be an + `CloseDiffRequest` object. ```typescript interface CloseDiffRequest { @@ -141,14 +212,22 @@ The plugin **MUST** register a `closeDiff` tool on its MCP server. ``` - **Response (`CallToolResult`):** The tool **MUST** return a `CallToolResult`. - - On Success: If the diff view was closed successfully, the response **MUST** include a single **TextContent** block in the content array containing the file's final content before closing. - - On Failure: If an error prevented the diff view from closing, the response **MUST** have `isError: true` and include a `TextContent` block in the `content` array describing the error. + - On Success: If the diff view was closed successfully, the response **MUST** + include a single **TextContent** block in the content array containing the + file's final content before closing. + - On Failure: If an error prevented the diff view from closing, the response + **MUST** have `isError: true` and include a `TextContent` block in the + `content` array describing the error. ### `ide/diffAccepted` Notification -When the user accepts the changes in a diff view (e.g., by clicking an "Apply" or "Save" button), the plugin **MUST** send an `ide/diffAccepted` notification to the CLI. +When the user accepts the changes in a diff view (e.g., by clicking an "Apply" +or "Save" button), the plugin **MUST** send an `ide/diffAccepted` notification +to the CLI. -- **Payload:** The notification parameters **MUST** include the file path and the final content of the file. The content may differ from the original `newContent` if the user made manual edits in the diff view. +- **Payload:** The notification parameters **MUST** include the file path and + the final content of the file. The content may differ from the original + `newContent` if the user made manual edits in the diff view. ```typescript { @@ -161,9 +240,12 @@ When the user accepts the changes in a diff view (e.g., by clicking an "Apply" o ### `ide/diffRejected` Notification -When the user rejects the changes (e.g., by closing the diff view without accepting), the plugin **MUST** send an `ide/diffRejected` notification to the CLI. +When the user rejects the changes (e.g., by closing the diff view without +accepting), the plugin **MUST** send an `ide/diffRejected` notification to the +CLI. -- **Payload:** The notification parameters **MUST** include the file path of the rejected diff. +- **Payload:** The notification parameters **MUST** include the file path of the + rejected diff. ```typescript { @@ -174,7 +256,8 @@ When the user rejects the changes (e.g., by closing the diff view without accept ## IV. The Lifecycle Interface -The plugin **MUST** manage its resources and the discovery file correctly based on the IDE's lifecycle. +The plugin **MUST** manage its resources and the discovery file correctly based +on the IDE's lifecycle. - **On Activation (IDE startup/plugin enabled):** 1. Start the MCP server. diff --git a/docs/ide-integration/index.md b/docs/ide-integration/index.md index 011c3417f1..4bb4982938 100644 --- a/docs/ide-integration/index.md +++ b/docs/ide-integration/index.md @@ -1,23 +1,36 @@ # IDE Integration -Gemini CLI can integrate with your IDE to provide a more seamless and context-aware experience. This integration allows the CLI to understand your workspace better and enables powerful features like native in-editor diffing. +Gemini CLI can integrate with your IDE to provide a more seamless and +context-aware experience. This integration allows the CLI to understand your +workspace better and enables powerful features like native in-editor diffing. -Currently, the only supported IDE is [Visual Studio Code](https://code.visualstudio.com/) and other editors that support VS Code extensions. To build support for other editors, see the [IDE Companion Extension Spec](./ide-companion-spec.md). +Currently, the only supported IDE is +[Visual Studio Code](https://code.visualstudio.com/) and other editors that +support VS Code extensions. To build support for other editors, see the +[IDE Companion Extension Spec](./ide-companion-spec.md). ## Features -- **Workspace Context:** The CLI automatically gains awareness of your workspace to provide more relevant and accurate responses. This context includes: +- **Workspace Context:** The CLI automatically gains awareness of your workspace + to provide more relevant and accurate responses. This context includes: - The **10 most recently accessed files** in your workspace. - Your active cursor position. - - Any text you have selected (up to a 16KB limit; longer selections will be truncated). + - Any text you have selected (up to a 16KB limit; longer selections will be + truncated). -- **Native Diffing:** When Gemini suggests code modifications, you can view the changes directly within your IDE's native diff viewer. This allows you to review, edit, and accept or reject the suggested changes seamlessly. +- **Native Diffing:** When Gemini suggests code modifications, you can view the + changes directly within your IDE's native diff viewer. This allows you to + review, edit, and accept or reject the suggested changes seamlessly. -- **VS Code Commands:** You can access Gemini CLI features directly from the VS Code Command Palette (`Cmd+Shift+P` or `Ctrl+Shift+P`): - - `Gemini CLI: Run`: Starts a new Gemini CLI session in the integrated terminal. +- **VS Code Commands:** You can access Gemini CLI features directly from the VS + Code Command Palette (`Cmd+Shift+P` or `Ctrl+Shift+P`): + - `Gemini CLI: Run`: Starts a new Gemini CLI session in the integrated + terminal. - `Gemini CLI: Accept Diff`: Accepts the changes in the active diff editor. - - `Gemini CLI: Close Diff Editor`: Rejects the changes and closes the active diff editor. - - `Gemini CLI: View Third-Party Notices`: Displays the third-party notices for the extension. + - `Gemini CLI: Close Diff Editor`: Rejects the changes and closes the active + diff editor. + - `Gemini CLI: View Third-Party Notices`: Displays the third-party notices for + the extension. ## Installation and Setup @@ -25,11 +38,15 @@ There are three ways to set up the IDE integration: ### 1. Automatic Nudge (Recommended) -When you run Gemini CLI inside a supported editor, it will automatically detect your environment and prompt you to connect. Answering "Yes" will automatically run the necessary setup, which includes installing the companion extension and enabling the connection. +When you run Gemini CLI inside a supported editor, it will automatically detect +your environment and prompt you to connect. Answering "Yes" will automatically +run the necessary setup, which includes installing the companion extension and +enabling the connection. ### 2. Manual Installation from CLI -If you previously dismissed the prompt or want to install the extension manually, you can run the following command inside Gemini CLI: +If you previously dismissed the prompt or want to install the extension +manually, you can run the following command inside Gemini CLI: ``` /ide install @@ -41,13 +58,20 @@ This will find the correct extension for your IDE and install it. You can also install the extension directly from a marketplace. -- **For Visual Studio Code:** Install from the [VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=google.gemini-cli-vscode-ide-companion). -- **For VS Code Forks:** To support forks of VS Code, the extension is also published on the [Open VSX Registry](https://open-vsx.org/extension/google/gemini-cli-vscode-ide-companion). Follow your editor's instructions for installing extensions from this registry. +- **For Visual Studio Code:** Install from the + [VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=google.gemini-cli-vscode-ide-companion). +- **For VS Code Forks:** To support forks of VS Code, the extension is also + published on the + [Open VSX Registry](https://open-vsx.org/extension/google/gemini-cli-vscode-ide-companion). + Follow your editor's instructions for installing extensions from this + registry. -> NOTE: -> The "Gemini CLI Companion" extension may appear towards the bottom of search results. If you don't see it immediately, try scrolling down or sorting by "Newly Published". +> NOTE: The "Gemini CLI Companion" extension may appear towards the bottom of +> search results. If you don't see it immediately, try scrolling down or sorting +> by "Newly Published". > -> After manually installing the extension, you must run `/ide enable` in the CLI to activate the integration. +> After manually installing the extension, you must run `/ide enable` in the CLI +> to activate the integration. ## Usage @@ -64,23 +88,28 @@ You can control the IDE integration from within the CLI: /ide disable ``` -When enabled, Gemini CLI will automatically attempt to connect to the IDE companion extension. +When enabled, Gemini CLI will automatically attempt to connect to the IDE +companion extension. ### Checking the Status -To check the connection status and see the context the CLI has received from the IDE, run: +To check the connection status and see the context the CLI has received from the +IDE, run: ``` /ide status ``` -If connected, this command will show the IDE it's connected to and a list of recently opened files it is aware of. +If connected, this command will show the IDE it's connected to and a list of +recently opened files it is aware of. -(Note: The file list is limited to 10 recently accessed files within your workspace and only includes local files on disk.) +> [!NOTE] The file list is limited to 10 recently accessed files within your +> workspace and only includes local files on disk.) ### Working with Diffs -When you ask Gemini to modify a file, it can open a diff view directly in your editor. +When you ask Gemini to modify a file, it can open a diff view directly in your +editor. **To accept a diff**, you can perform any of the following actions: @@ -96,49 +125,78 @@ When you ask Gemini to modify a file, it can open a diff view directly in your e - Open the Command Palette and run **Gemini CLI: Close Diff Editor**. - Respond with `no` in the CLI when prompted. -You can also **modify the suggested changes** directly in the diff view before accepting them. +You can also **modify the suggested changes** directly in the diff view before +accepting them. -If you select ‘Yes, allow always’ in the CLI, changes will no longer show up in the IDE as they will be auto-accepted. +If you select ‘Yes, allow always’ in the CLI, changes will no longer show up in +the IDE as they will be auto-accepted. ## Using with Sandboxing If you are using Gemini CLI within a sandbox, please be aware of the following: -- **On macOS:** The IDE integration requires network access to communicate with the IDE companion extension. You must use a Seatbelt profile that allows network access. -- **In a Docker Container:** If you run Gemini CLI inside a Docker (or Podman) container, the IDE integration can still connect to the VS Code extension running on your host machine. The CLI is configured to automatically find the IDE server on `host.docker.internal`. No special configuration is usually required, but you may need to ensure your Docker networking setup allows connections from the container to the host. +- **On macOS:** The IDE integration requires network access to communicate with + the IDE companion extension. You must use a Seatbelt profile that allows + network access. +- **In a Docker Container:** If you run Gemini CLI inside a Docker (or Podman) + container, the IDE integration can still connect to the VS Code extension + running on your host machine. The CLI is configured to automatically find the + IDE server on `host.docker.internal`. No special configuration is usually + required, but you may need to ensure your Docker networking setup allows + connections from the container to the host. ## Troubleshooting -If you encounter issues with IDE integration, here are some common error messages and how to resolve them. +If you encounter issues with IDE integration, here are some common error +messages and how to resolve them. ### Connection Errors -- **Message:** `🔴 Disconnected: Failed to connect to IDE companion extension in [IDE Name]. Please ensure the extension is running. To install the extension, run /ide install.` - - **Cause:** Gemini CLI could not find the necessary environment variables (`GEMINI_CLI_IDE_WORKSPACE_PATH` or `GEMINI_CLI_IDE_SERVER_PORT`) to connect to the IDE. This usually means the IDE companion extension is not running or did not initialize correctly. +- **Message:** + `🔴 Disconnected: Failed to connect to IDE companion extension in [IDE Name]. Please ensure the extension is running. To install the extension, run /ide install.` + - **Cause:** Gemini CLI could not find the necessary environment variables + (`GEMINI_CLI_IDE_WORKSPACE_PATH` or `GEMINI_CLI_IDE_SERVER_PORT`) to connect + to the IDE. This usually means the IDE companion extension is not running or + did not initialize correctly. - **Solution:** - 1. Make sure you have installed the **Gemini CLI Companion** extension in your IDE and that it is enabled. - 2. Open a new terminal window in your IDE to ensure it picks up the correct environment. + 1. Make sure you have installed the **Gemini CLI Companion** extension in + your IDE and that it is enabled. + 2. Open a new terminal window in your IDE to ensure it picks up the correct + environment. -- **Message:** `🔴 Disconnected: IDE connection error. The connection was lost unexpectedly. Please try reconnecting by running /ide enable` +- **Message:** + `🔴 Disconnected: IDE connection error. The connection was lost unexpectedly. Please try reconnecting by running /ide enable` - **Cause:** The connection to the IDE companion was lost. - - **Solution:** Run `/ide enable` to try and reconnect. If the issue continues, open a new terminal window or restart your IDE. + - **Solution:** Run `/ide enable` to try and reconnect. If the issue + continues, open a new terminal window or restart your IDE. ### Configuration Errors -- **Message:** `🔴 Disconnected: Directory mismatch. Gemini CLI is running in a different location than the open workspace in [IDE Name]. Please run the CLI from one of the following directories: [List of directories]` - - **Cause:** The CLI's current working directory is outside the workspace you have open in your IDE. - - **Solution:** `cd` into the same directory that is open in your IDE and restart the CLI. +- **Message:** + `🔴 Disconnected: Directory mismatch. Gemini CLI is running in a different location than the open workspace in [IDE Name]. Please run the CLI from one of the following directories: [List of directories]` + - **Cause:** The CLI's current working directory is outside the workspace you + have open in your IDE. + - **Solution:** `cd` into the same directory that is open in your IDE and + restart the CLI. -- **Message:** `🔴 Disconnected: To use this feature, please open a workspace folder in [IDE Name] and try again.` +- **Message:** + `🔴 Disconnected: To use this feature, please open a workspace folder in [IDE Name] and try again.` - **Cause:** You have no workspace open in your IDE. - **Solution:** Open a workspace in your IDE and restart the CLI. ### General Errors -- **Message:** `IDE integration is not supported in your current environment. To use this feature, run Gemini CLI in one of these supported IDEs: [List of IDEs]` - - **Cause:** You are running Gemini CLI in a terminal or environment that is not a supported IDE. - - **Solution:** Run Gemini CLI from the integrated terminal of a supported IDE, like VS Code. +- **Message:** + `IDE integration is not supported in your current environment. To use this feature, run Gemini CLI in one of these supported IDEs: [List of IDEs]` + - **Cause:** You are running Gemini CLI in a terminal or environment that is + not a supported IDE. + - **Solution:** Run Gemini CLI from the integrated terminal of a supported + IDE, like VS Code. -- **Message:** `No installer is available for IDE. Please install the Gemini CLI Companion extension manually from the marketplace.` - - **Cause:** You ran `/ide install`, but the CLI does not have an automated installer for your specific IDE. - - **Solution:** Open your IDE's extension marketplace, search for "Gemini CLI Companion", and [install it manually](#3-manual-installation-from-a-marketplace). +- **Message:** + `No installer is available for IDE. Please install the Gemini CLI Companion extension manually from the marketplace.` + - **Cause:** You ran `/ide install`, but the CLI does not have an automated + installer for your specific IDE. + - **Solution:** Open your IDE's extension marketplace, search for "Gemini CLI + Companion", and + [install it manually](#3-manual-installation-from-a-marketplace). diff --git a/docs/index.md b/docs/index.md index 025a0f5e23..2d817836cf 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,10 +1,18 @@ # Welcome to Gemini CLI documentation -This documentation provides a comprehensive guide to installing, using, and developing Gemini CLI. This tool lets you interact with Gemini models through a command-line interface. +This documentation provides a comprehensive guide to installing, using, and +developing Gemini CLI. This tool lets you interact with Gemini models through a +command-line interface. ## Overview -Gemini CLI brings the capabilities of Gemini models to your terminal in an interactive Read-Eval-Print Loop (REPL) environment. Gemini CLI consists of a client-side application (`packages/cli`) that communicates with a local server (`packages/core`), which in turn manages requests to the Gemini API and its AI models. Gemini CLI also contains a variety of tools for tasks such as performing file system operations, running shells, and web fetching, which are managed by `packages/core`. +Gemini CLI brings the capabilities of Gemini models to your terminal in an +interactive Read-Eval-Print Loop (REPL) environment. Gemini CLI consists of a +client-side application (`packages/cli`) that communicates with a local server +(`packages/core`), which in turn manages requests to the Gemini API and its AI +models. Gemini CLI also contains a variety of tools for tasks such as performing +file system operations, running shells, and web fetching, which are managed by +`packages/core`. ## Navigating the documentation @@ -12,10 +20,13 @@ This documentation is organized into the following sections: ### Get started -- **[Gemini CLI Quickstart](./get-started/index.md):** Let's get started with Gemini CLI. +- **[Gemini CLI Quickstart](./get-started/index.md):** Let's get started with + Gemini CLI. - **[Deployment](./get-started/deployment.md):** Install and run Gemini CLI. -- **[Authentication](./get-started/authentication.md):** Authenticate Gemini CLI. -- **[Configuration](./get-started/configuration.md):** Information on configuring the CLI. +- **[Authentication](./get-started/authentication.md):** Authenticate Gemini + CLI. +- **[Configuration](./get-started/configuration.md):** Information on + configuring the CLI. - **[Examples](./get-started/examples.md):** Example usage of Gemini CLI. ### CLI @@ -26,45 +37,66 @@ This documentation is organized into the following sections: - **[Themes](./cli/themes.md):** Themes for Gemini CLI. - **[Token Caching](./cli/token-caching.md):** Token caching and optimization. - **[Tutorials](./cli/tutorials.md):** Tutorials for Gemini CLI. -- **[Checkpointing](./cli/checkpointing.md):** Documentation for the checkpointing feature. +- **[Checkpointing](./cli/checkpointing.md):** Documentation for the + checkpointing feature. - **[Telemetry](./cli/telemetry.md):** Overview of telemetry in the CLI. -- **[Trusted Folders](./cli/trusted-folders.md):** An overview of the Trusted Folders security feature. +- **[Trusted Folders](./cli/trusted-folders.md):** An overview of the Trusted + Folders security feature. ### Core -- **[Gemini CLI core overview](./core/index.md):** Information about Gemini CLI core. +- **[Gemini CLI core overview](./core/index.md):** Information about Gemini CLI + core. - **[Memport](./core/memport.md):** Using the Memory Import Processor. -- **[Tools API](./core/tools-api.md):** Information on how the core manages and exposes tools. +- **[Tools API](./core/tools-api.md):** Information on how the core manages and + exposes tools. ### Tools -- **[Gemini CLI tools overview](./tools/index.md):** Information about Gemini CLI's tools. -- **[File System Tools](./tools/file-system.md):** Documentation for the `read_file` and `write_file` tools. +- **[Gemini CLI tools overview](./tools/index.md):** Information about Gemini + CLI's tools. +- **[File System Tools](./tools/file-system.md):** Documentation for the + `read_file` and `write_file` tools. - **[MCP servers](./tools/mcp-server.md):** Using MCP servers with Gemini CLI. -- **[Multi-File Read Tool](./tools/multi-file.md):** Documentation for the `read_many_files` tool. -- **[Shell Tool](./tools/shell.md):** Documentation for the `run_shell_command` tool. -- **[Web Fetch Tool](./tools/web-fetch.md):** Documentation for the `web_fetch` tool. -- **[Web Search Tool](./tools/web-search.md):** Documentation for the `google_web_search` tool. -- **[Memory Tool](./tools/memory.md):** Documentation for the `save_memory` tool. +- **[Multi-File Read Tool](./tools/multi-file.md):** Documentation for the + `read_many_files` tool. +- **[Shell Tool](./tools/shell.md):** Documentation for the `run_shell_command` + tool. +- **[Web Fetch Tool](./tools/web-fetch.md):** Documentation for the `web_fetch` + tool. +- **[Web Search Tool](./tools/web-search.md):** Documentation for the + `google_web_search` tool. +- **[Memory Tool](./tools/memory.md):** Documentation for the `save_memory` + tool. ### Extensions -- **[Extensions](./extensions/index.md):** How to extend the CLI with new functionality. -- **[Extension Releasing](./extensions/extension-releasing.md):** How to release Gemini CLI extensions. +- **[Extensions](./extensions/index.md):** How to extend the CLI with new + functionality. +- **[Extension Releasing](./extensions/extension-releasing.md):** How to release + Gemini CLI extensions. ### IDE integration -- **[IDE Integration](./ide-integration/index.md):** Connect the CLI to your editor. -- **[IDE Companion Extension Spec](./ide-integration/ide-companion-spec.md):** Spec for building IDE companion extensions. +- **[IDE Integration](./ide-integration/index.md):** Connect the CLI to your + editor. +- **[IDE Companion Extension Spec](./ide-integration/ide-companion-spec.md):** + Spec for building IDE companion extensions. ### About the Gemini CLI project -- **[Architecture Overview](./architecture.md):** Understand the high-level design of Gemini CLI, including its components and how they interact. -- **[Contributing & Development Guide](../CONTRIBUTING.md):** Information for contributors and developers, including setup, building, testing, and coding conventions. +- **[Architecture Overview](./architecture.md):** Understand the high-level + design of Gemini CLI, including its components and how they interact. +- **[Contributing & Development Guide](../CONTRIBUTING.md):** Information for + contributors and developers, including setup, building, testing, and coding + conventions. - **[NPM](./npm.md):** Details on how the project's packages are structured. -- **[Troubleshooting Guide](./troubleshooting.md):** Find solutions to common problems. +- **[Troubleshooting Guide](./troubleshooting.md):** Find solutions to common + problems. - **[FAQ](./faq.md):** Frequently asked questions. -- **[Terms of Service and Privacy Notice](./tos-privacy.md):** Information on the terms of service and privacy notices applicable to your use of Gemini CLI. -- **[Releases](./releases.md):** Information on the project's releases and deployment cadence. +- **[Terms of Service and Privacy Notice](./tos-privacy.md):** Information on + the terms of service and privacy notices applicable to your use of Gemini CLI. +- **[Releases](./releases.md):** Information on the project's releases and + deployment cadence. We hope this documentation helps you make the most of Gemini CLI! diff --git a/docs/integration-tests.md b/docs/integration-tests.md index c3da474abd..f399c4fba8 100644 --- a/docs/integration-tests.md +++ b/docs/integration-tests.md @@ -1,16 +1,21 @@ # Integration Tests -This document provides information about the integration testing framework used in this project. +This document provides information about the integration testing framework used +in this project. ## Overview -The integration tests are designed to validate the end-to-end functionality of the Gemini CLI. They execute the built binary in a controlled environment and verify that it behaves as expected when interacting with the file system. +The integration tests are designed to validate the end-to-end functionality of +the Gemini CLI. They execute the built binary in a controlled environment and +verify that it behaves as expected when interacting with the file system. -These tests are located in the `integration-tests` directory and are run using a custom test runner. +These tests are located in the `integration-tests` directory and are run using a +custom test runner. ## Running the tests -The integration tests are not run as part of the default `npm run test` command. They must be run explicitly using the `npm run test:integration:all` script. +The integration tests are not run as part of the default `npm run test` command. +They must be run explicitly using the `npm run test:integration:all` script. The integration tests can also be run using the following shortcut: @@ -20,7 +25,12 @@ npm run test:e2e ## Running a specific set of tests -To run a subset of test files, you can use `npm run ....` where <integration test command> is either `test:e2e` or `test:integration*` and `` is any of the `.test.js` files in the `integration-tests/` directory. For example, the following command runs `list_directory.test.js` and `write_file.test.js`: +To run a subset of test files, you can use +`npm run ....` where <integration +test command> is either `test:e2e` or `test:integration*` and `` +is any of the `.test.js` files in the `integration-tests/` directory. For +example, the following command runs `list_directory.test.js` and +`write_file.test.js`: ```bash npm run test:e2e list_directory write_file @@ -36,7 +46,8 @@ npm run test:e2e -- --test-name-pattern "reads a file" ### Deflaking a test -Before adding a **new** integration test, you should test it at least 5 times with the deflake script to make sure that it is not flaky. +Before adding a **new** integration test, you should test it at least 5 times +with the deflake script to make sure that it is not flaky. ```bash npm run deflake -- --runs=5 --command="npm run test:e2e -- --test-name-pattern ''" @@ -69,11 +80,13 @@ npm run test:integration:sandbox:podman ## Diagnostics -The integration test runner provides several options for diagnostics to help track down test failures. +The integration test runner provides several options for diagnostics to help +track down test failures. ### Keeping test output -You can preserve the temporary files created during a test run for inspection. This is useful for debugging issues with file system operations. +You can preserve the temporary files created during a test run for inspection. +This is useful for debugging issues with file system operations. To keep the test output set the `KEEP_OUTPUT` environment variable to `true`. @@ -81,7 +94,8 @@ To keep the test output set the `KEEP_OUTPUT` environment variable to `true`. KEEP_OUTPUT=true npm run test:integration:sandbox:none ``` -When output is kept, the test runner will print the path to the unique directory for the test run. +When output is kept, the test runner will print the path to the unique directory +for the test run. ### Verbose output @@ -91,7 +105,9 @@ For more detailed debugging, set the `VERBOSE` environment variable to `true`. VERBOSE=true npm run test:integration:sandbox:none ``` -When using `VERBOSE=true` and `KEEP_OUTPUT=true` in the same command, the output is streamed to the console and also saved to a log file within the test's temporary directory. +When using `VERBOSE=true` and `KEEP_OUTPUT=true` in the same command, the output +is streamed to the console and also saved to a log file within the test's +temporary directory. The verbose output is formatted to clearly identify the source of the logs: @@ -103,7 +119,9 @@ The verbose output is formatted to clearly identify the source of the logs: ## Linting and formatting -To ensure code quality and consistency, the integration test files are linted as part of the main build process. You can also manually run the linter and auto-fixer. +To ensure code quality and consistency, the integration test files are linted as +part of the main build process. You can also manually run the linter and +auto-fixer. ### Running the linter @@ -113,7 +131,8 @@ To check for linting errors, run the following command: npm run lint ``` -You can include the `:fix` flag in the command to automatically fix any fixable linting errors: +You can include the `:fix` flag in the command to automatically fix any fixable +linting errors: ```bash npm run lint:fix @@ -121,9 +140,13 @@ npm run lint:fix ## Directory structure -The integration tests create a unique directory for each test run inside the `.integration-tests` directory. Within this directory, a subdirectory is created for each test file, and within that, a subdirectory is created for each individual test case. +The integration tests create a unique directory for each test run inside the +`.integration-tests` directory. Within this directory, a subdirectory is created +for each test file, and within that, a subdirectory is created for each +individual test case. -This structure makes it easy to locate the artifacts for a specific test run, file, or case. +This structure makes it easy to locate the artifacts for a specific test run, +file, or case. ``` .integration-tests/ @@ -136,9 +159,13 @@ This structure makes it easy to locate the artifacts for a specific test run, fi ## Continuous integration -To ensure the integration tests are always run, a GitHub Actions workflow is defined in `.github/workflows/e2e.yml`. This workflow automatically runs the integrations tests for pull requests against the `main` branch, or when a pull request is added to a merge queue. +To ensure the integration tests are always run, a GitHub Actions workflow is +defined in `.github/workflows/e2e.yml`. This workflow automatically runs the +integrations tests for pull requests against the `main` branch, or when a pull +request is added to a merge queue. -The workflow runs the tests in different sandboxing environments to ensure Gemini CLI is tested across each: +The workflow runs the tests in different sandboxing environments to ensure +Gemini CLI is tested across each: - `sandbox:none`: Runs the tests without any sandboxing. - `sandbox:docker`: Runs the tests in a Docker container. diff --git a/docs/issue-and-pr-automation.md b/docs/issue-and-pr-automation.md index bff71e0582..8b34512e8c 100644 --- a/docs/issue-and-pr-automation.md +++ b/docs/issue-and-pr-automation.md @@ -1,84 +1,131 @@ # Automation and Triage Processes -This document provides a detailed overview of the automated processes we use to manage and triage issues and pull requests. Our goal is to provide prompt feedback and ensure that contributions are reviewed and integrated efficiently. Understanding this automation will help you as a contributor know what to expect and how to best interact with our repository bots. +This document provides a detailed overview of the automated processes we use to +manage and triage issues and pull requests. Our goal is to provide prompt +feedback and ensure that contributions are reviewed and integrated efficiently. +Understanding this automation will help you as a contributor know what to expect +and how to best interact with our repository bots. ## Guiding Principle: Issues and Pull Requests -First and foremost, almost every Pull Request (PR) should be linked to a corresponding Issue. The issue describes the "what" and the "why" (the bug or feature), while the PR is the "how" (the implementation). This separation helps us track work, prioritize features, and maintain clear historical context. Our automation is built around this principle. +First and foremost, almost every Pull Request (PR) should be linked to a +corresponding Issue. The issue describes the "what" and the "why" (the bug or +feature), while the PR is the "how" (the implementation). This separation helps +us track work, prioritize features, and maintain clear historical context. Our +automation is built around this principle. --- ## Detailed Automation Workflows -Here is a breakdown of the specific automation workflows that run in our repository. +Here is a breakdown of the specific automation workflows that run in our +repository. ### 1. When you open an Issue: `Automated Issue Triage` -This is the first bot you will interact with when you create an issue. Its job is to perform an initial analysis and apply the correct labels. +This is the first bot you will interact with when you create an issue. Its job +is to perform an initial analysis and apply the correct labels. - **Workflow File**: `.github/workflows/gemini-automated-issue-triage.yml` - **When it runs**: Immediately after an issue is created or reopened. - **What it does**: - - It uses a Gemini model to analyze the issue's title and body against a detailed set of guidelines. - - **Applies one `area/*` label**: Categorizes the issue into a functional area of the project (e.g., `area/ux`, `area/models`, `area/platform`). - - **Applies one `kind/*` label**: Identifies the type of issue (e.g., `kind/bug`, `kind/enhancement`, `kind/question`). - - **Applies one `priority/*` label**: Assigns a priority from P0 (critical) to P3 (low) based on the described impact. - - **May apply `status/need-information`**: If the issue lacks critical details (like logs or reproduction steps), it will be flagged for more information. - - **May apply `status/need-retesting`**: If the issue references a CLI version that is more than six versions old, it will be flagged for retesting on a current version. + - It uses a Gemini model to analyze the issue's title and body against a + detailed set of guidelines. + - **Applies one `area/*` label**: Categorizes the issue into a functional area + of the project (e.g., `area/ux`, `area/models`, `area/platform`). + - **Applies one `kind/*` label**: Identifies the type of issue (e.g., + `kind/bug`, `kind/enhancement`, `kind/question`). + - **Applies one `priority/*` label**: Assigns a priority from P0 (critical) to + P3 (low) based on the described impact. + - **May apply `status/need-information`**: If the issue lacks critical details + (like logs or reproduction steps), it will be flagged for more information. + - **May apply `status/need-retesting`**: If the issue references a CLI version + that is more than six versions old, it will be flagged for retesting on a + current version. - **What you should do**: - - Fill out the issue template as completely as possible. The more detail you provide, the more accurate the triage will be. - - If the `status/need-information` label is added, please provide the requested details in a comment. + - Fill out the issue template as completely as possible. The more detail you + provide, the more accurate the triage will be. + - If the `status/need-information` label is added, please provide the + requested details in a comment. ### 2. When you open a Pull Request: `Continuous Integration (CI)` -This workflow ensures that all changes meet our quality standards before they can be merged. +This workflow ensures that all changes meet our quality standards before they +can be merged. - **Workflow File**: `.github/workflows/ci.yml` - **When it runs**: On every push to a pull request. - **What it does**: - - **Lint**: Checks that your code adheres to our project's formatting and style rules. - - **Test**: Runs our full suite of automated tests across macOS, Windows, and Linux, and on multiple Node.js versions. This is the most time-consuming part of the CI process. - - **Post Coverage Comment**: After all tests have successfully passed, a bot will post a comment on your PR. This comment provides a summary of how well your changes are covered by tests. + - **Lint**: Checks that your code adheres to our project's formatting and + style rules. + - **Test**: Runs our full suite of automated tests across macOS, Windows, and + Linux, and on multiple Node.js versions. This is the most time-consuming + part of the CI process. + - **Post Coverage Comment**: After all tests have successfully passed, a bot + will post a comment on your PR. This comment provides a summary of how well + your changes are covered by tests. - **What you should do**: - - Ensure all CI checks pass. A green checkmark ✅ will appear next to your commit when everything is successful. - - If a check fails (a red "X" ❌), click the "Details" link next to the failed check to view the logs, identify the problem, and push a fix. + - Ensure all CI checks pass. A green checkmark ✅ will appear next to your + commit when everything is successful. + - If a check fails (a red "X" ❌), click the "Details" link next to the failed + check to view the logs, identify the problem, and push a fix. ### 3. Ongoing Triage for Pull Requests: `PR Auditing and Label Sync` -This workflow runs periodically to ensure all open PRs are correctly linked to issues and have consistent labels. +This workflow runs periodically to ensure all open PRs are correctly linked to +issues and have consistent labels. - **Workflow File**: `.github/workflows/gemini-scheduled-pr-triage.yml` - **When it runs**: Every 15 minutes on all open pull requests. - **What it does**: - - **Checks for a linked issue**: The bot scans your PR description for a keyword that links it to an issue (e.g., `Fixes #123`, `Closes #456`). - - **Adds `status/need-issue`**: If no linked issue is found, the bot will add the `status/need-issue` label to your PR. This is a clear signal that an issue needs to be created and linked. - - **Synchronizes labels**: If an issue _is_ linked, the bot ensures the PR's labels perfectly match the issue's labels. It will add any missing labels and remove any that don't belong, and it will remove the `status/need-issue` label if it was present. + - **Checks for a linked issue**: The bot scans your PR description for a + keyword that links it to an issue (e.g., `Fixes #123`, `Closes #456`). + - **Adds `status/need-issue`**: If no linked issue is found, the bot will add + the `status/need-issue` label to your PR. This is a clear signal that an + issue needs to be created and linked. + - **Synchronizes labels**: If an issue _is_ linked, the bot ensures the PR's + labels perfectly match the issue's labels. It will add any missing labels + and remove any that don't belong, and it will remove the `status/need-issue` + label if it was present. - **What you should do**: - - **Always link your PR to an issue.** This is the most important step. Add a line like `Resolves #` to your PR description. - - This will ensure your PR is correctly categorized and moves through the review process smoothly. + - **Always link your PR to an issue.** This is the most important step. Add a + line like `Resolves #` to your PR description. + - This will ensure your PR is correctly categorized and moves through the + review process smoothly. ### 4. Ongoing Triage for Issues: `Scheduled Issue Triage` -This is a fallback workflow to ensure that no issue gets missed by the triage process. +This is a fallback workflow to ensure that no issue gets missed by the triage +process. - **Workflow File**: `.github/workflows/gemini-scheduled-issue-triage.yml` - **When it runs**: Every hour on all open issues. - **What it does**: - - It actively seeks out issues that either have no labels at all or still have the `status/need-triage` label. - - It then triggers the same powerful Gemini-based analysis as the initial triage bot to apply the correct labels. + - It actively seeks out issues that either have no labels at all or still have + the `status/need-triage` label. + - It then triggers the same powerful Gemini-based analysis as the initial + triage bot to apply the correct labels. - **What you should do**: - - You typically don't need to do anything. This workflow is a safety net to ensure every issue is eventually categorized, even if the initial triage fails. + - You typically don't need to do anything. This workflow is a safety net to + ensure every issue is eventually categorized, even if the initial triage + fails. ### 5. Release Automation -This workflow handles the process of packaging and publishing new versions of the Gemini CLI. +This workflow handles the process of packaging and publishing new versions of +the Gemini CLI. - **Workflow File**: `.github/workflows/release-manual.yml` -- **When it runs**: On a daily schedule for "nightly" releases, and manually for official patch/minor releases. +- **When it runs**: On a daily schedule for "nightly" releases, and manually for + official patch/minor releases. - **What it does**: - - Automatically builds the project, bumps the version numbers, and publishes the packages to npm. + - Automatically builds the project, bumps the version numbers, and publishes + the packages to npm. - Creates a corresponding release on GitHub with generated release notes. - **What you should do**: - - As a contributor, you don't need to do anything for this process. You can be confident that once your PR is merged into the `main` branch, your changes will be included in the very next nightly release. + - As a contributor, you don't need to do anything for this process. You can be + confident that once your PR is merged into the `main` branch, your changes + will be included in the very next nightly release. -We hope this detailed overview is helpful. If you have any questions about our automation or processes, please don't hesitate to ask! +We hope this detailed overview is helpful. If you have any questions about our +automation or processes, please don't hesitate to ask! diff --git a/docs/npm.md b/docs/npm.md index a8de04e2e3..77486305ad 100644 --- a/docs/npm.md +++ b/docs/npm.md @@ -1,22 +1,37 @@ # Package Overview -This monorepo contains two main packages: `@google/gemini-cli` and `@google/gemini-cli-core`. +This monorepo contains two main packages: `@google/gemini-cli` and +`@google/gemini-cli-core`. ## `@google/gemini-cli` -This is the main package for the Gemini CLI. It is responsible for the user interface, command parsing, and all other user-facing functionality. +This is the main package for the Gemini CLI. It is responsible for the user +interface, command parsing, and all other user-facing functionality. -When this package is published, it is bundled into a single executable file. This bundle includes all of the package's dependencies, including `@google/gemini-cli-core`. This means that whether a user installs the package with `npm install -g @google/gemini-cli` or runs it directly with `npx @google/gemini-cli`, they are using this single, self-contained executable. +When this package is published, it is bundled into a single executable file. +This bundle includes all of the package's dependencies, including +`@google/gemini-cli-core`. This means that whether a user installs the package +with `npm install -g @google/gemini-cli` or runs it directly with +`npx @google/gemini-cli`, they are using this single, self-contained executable. ## `@google/gemini-cli-core` -This package contains the core logic for interacting with the Gemini API. It is responsible for making API requests, handling authentication, and managing the local cache. +This package contains the core logic for interacting with the Gemini API. It is +responsible for making API requests, handling authentication, and managing the +local cache. -This package is not bundled. When it is published, it is published as a standard Node.js package with its own dependencies. This allows it to be used as a standalone package in other projects, if needed. All transpiled js code in the `dist` folder is included in the package. +This package is not bundled. When it is published, it is published as a standard +Node.js package with its own dependencies. This allows it to be used as a +standalone package in other projects, if needed. All transpiled js code in the +`dist` folder is included in the package. ## NPM Workspaces -This project uses [NPM Workspaces](https://docs.npmjs.com/cli/v10/using-npm/workspaces) to manage the packages within this monorepo. This simplifies development by allowing us to manage dependencies and run scripts across multiple packages from the root of the project. +This project uses +[NPM Workspaces](https://docs.npmjs.com/cli/v10/using-npm/workspaces) to manage +the packages within this monorepo. This simplifies development by allowing us to +manage dependencies and run scripts across multiple packages from the root of +the project. ### How it Works @@ -28,10 +43,20 @@ The root `package.json` file defines the workspaces for this project: } ``` -This tells NPM that any folder inside the `packages` directory is a separate package that should be managed as part of the workspace. +This tells NPM that any folder inside the `packages` directory is a separate +package that should be managed as part of the workspace. ### Benefits of Workspaces -- **Simplified Dependency Management**: Running `npm install` from the root of the project will install all dependencies for all packages in the workspace and link them together. This means you don't need to run `npm install` in each package's directory. -- **Automatic Linking**: Packages within the workspace can depend on each other. When you run `npm install`, NPM will automatically create symlinks between the packages. This means that when you make changes to one package, the changes are immediately available to other packages that depend on it. -- **Simplified Script Execution**: You can run scripts in any package from the root of the project using the `--workspace` flag. For example, to run the `build` script in the `cli` package, you can run `npm run build --workspace @google/gemini-cli`. +- **Simplified Dependency Management**: Running `npm install` from the root of + the project will install all dependencies for all packages in the workspace + and link them together. This means you don't need to run `npm install` in each + package's directory. +- **Automatic Linking**: Packages within the workspace can depend on each other. + When you run `npm install`, NPM will automatically create symlinks between the + packages. This means that when you make changes to one package, the changes + are immediately available to other packages that depend on it. +- **Simplified Script Execution**: You can run scripts in any package from the + root of the project using the `--workspace` flag. For example, to run the + `build` script in the `cli` package, you can run + `npm run build --workspace @google/gemini-cli`. diff --git a/docs/quota-and-pricing.md b/docs/quota-and-pricing.md index 5e5595aca6..f54af7af02 100644 --- a/docs/quota-and-pricing.md +++ b/docs/quota-and-pricing.md @@ -1,65 +1,91 @@ # Gemini CLI: Quotas and Pricing -Gemini CLI offers a generous free tier that covers the use cases for many individual developers. For enterprise / professional usage, or if you need higher limits, there are multiple possible avenues depending on what type of account you use to authenticate. +Gemini CLI offers a generous free tier that covers the use cases for many +individual developers. For enterprise / professional usage, or if you need +higher limits, there are multiple possible avenues depending on what type of +account you use to authenticate. -See [privacy and terms](./tos-privacy.md) for details on Privacy policy and Terms of Service. +See [privacy and terms](./tos-privacy.md) for details on Privacy policy and +Terms of Service. -Note: published prices are list price; additional negotiated commercial discounting may apply. +> [!NOTE] Published prices are list price; additional negotiated commercial +> discounting may apply. -This article outlines the specific quotas and pricing applicable to the Gemini CLI when using different authentication methods. +This article outlines the specific quotas and pricing applicable to the Gemini +CLI when using different authentication methods. Generally, there are three categories to choose from: - Free Usage: Ideal for experimentation and light use. -- Paid Tier (fixed price): For individual developers or enterprises who need more generous daily quotas and predictable costs. -- Pay-As-You-Go: The most flexible option for professional use, long-running tasks, or when you need full control over your usage. +- Paid Tier (fixed price): For individual developers or enterprises who need + more generous daily quotas and predictable costs. +- Pay-As-You-Go: The most flexible option for professional use, long-running + tasks, or when you need full control over your usage. ## Free Usage -Your journey begins with a generous free tier, perfect for experimentation and light use. +Your journey begins with a generous free tier, perfect for experimentation and +light use. Your free usage limits depend on your authorization type. ### Log in with Google (Gemini Code Assist for individuals) -For users who authenticate by using their Google account to access Gemini Code Assist for individuals. This includes: +For users who authenticate by using their Google account to access Gemini Code +Assist for individuals. This includes: - 1000 model requests / user / day - 60 model requests / user / minute -- Model requests will be made across the Gemini model family as determined by Gemini CLI. +- Model requests will be made across the Gemini model family as determined by + Gemini CLI. -Learn more at [Gemini Code Assist for Individuals Limits](https://developers.google.com/gemini-code-assist/resources/quotas#quotas-for-agent-mode-gemini-cli). +Learn more at +[Gemini Code Assist for Individuals Limits](https://developers.google.com/gemini-code-assist/resources/quotas#quotas-for-agent-mode-gemini-cli). ### Log in with Gemini API Key (Unpaid) -If you are using a Gemini API key, you can also benefit from a free tier. This includes: +If you are using a Gemini API key, you can also benefit from a free tier. This +includes: - 250 model requests / user / day - 10 model requests / user / minute - Model requests to Flash model only. -Learn more at [Gemini API Rate Limits](https://ai.google.dev/gemini-api/docs/rate-limits). +Learn more at +[Gemini API Rate Limits](https://ai.google.dev/gemini-api/docs/rate-limits). ### Log in with Vertex AI (Express Mode) -Vertex AI offers an Express Mode without the need to enable billing. This includes: +Vertex AI offers an Express Mode without the need to enable billing. This +includes: - 90 days before you need to enable billing. - Quotas and models are variable and specific to your account. -Learn more at [Vertex AI Express Mode Limits](https://cloud.google.com/vertex-ai/generative-ai/docs/start/express-mode/overview#quotas). +Learn more at +[Vertex AI Express Mode Limits](https://cloud.google.com/vertex-ai/generative-ai/docs/start/express-mode/overview#quotas). ## Paid tier: Higher limits for a fixed cost -If you use up your initial number of requests, you can continue to benefit from Gemini CLI by upgrading to one of the following subscriptions: +If you use up your initial number of requests, you can continue to benefit from +Gemini CLI by upgrading to one of the following subscriptions: -- [Google AI Pro and AI Ultra](https://cloud.google.com/products/gemini/pricing) by signing up at [Set up Gemini Code Assist](https://goo.gle/set-up-gemini-code-assist). This is recommended for individual developers. Quotas and pricing are based on a fixed price subscription. +- [Google AI Pro and AI Ultra](https://cloud.google.com/products/gemini/pricing) + by signing up at + [Set up Gemini Code Assist](https://goo.gle/set-up-gemini-code-assist). This + is recommended for individual developers. Quotas and pricing are based on a + fixed price subscription. For predictable costs, you can log in with Google. - Learn more at [Gemini Code Assist Quotas and Limits](https://developers.google.com/gemini-code-assist/resources/quotas) + Learn more at + [Gemini Code Assist Quotas and Limits](https://developers.google.com/gemini-code-assist/resources/quotas) -- [Purchase a Gemini Code Assist Subscription through Google Cloud ](https://cloud.google.com/gemini/docs/codeassist/overview) by signing up in the Google Cloud console. Learn more at [Set up Gemini Code Assist] (https://cloud.google.com/gemini/docs/discover/set-up-gemini) Quotas and pricing are based on a fixed price subscription with assigned license seats. For predictable costs, you can sign in with Google. +- [Purchase a Gemini Code Assist Subscription through Google Cloud ](https://cloud.google.com/gemini/docs/codeassist/overview) + by signing up in the Google Cloud console. Learn more at [Set up Gemini Code + Assist] (https://cloud.google.com/gemini/docs/discover/set-up-gemini) Quotas + and pricing are based on a fixed price subscription with assigned license + seats. For predictable costs, you can sign in with Google. This includes: - Gemini Code Assist Standard edition: @@ -68,46 +94,67 @@ If you use up your initial number of requests, you can continue to benefit from - Gemini Code Assist Enterprise edition: - 2000 model requests / user / day - 120 model requests / user / minute - - Model requests will be made across the Gemini model family as determined by Gemini CLI. + - Model requests will be made across the Gemini model family as determined by + Gemini CLI. [Learn more about Gemini Code Assist Standard and Enterprise license limits](https://developers.google.com/gemini-code-assist/resources/quotas#quotas-for-agent-mode-gemini-cli). ## Pay As You Go -If you hit your daily request limits or exhaust your Gemini Pro quota even after upgrading, the most flexible solution is to switch to a pay-as-you-go model, where you pay for the specific amount of processing you use. This is the recommended path for uninterrupted access. +If you hit your daily request limits or exhaust your Gemini Pro quota even after +upgrading, the most flexible solution is to switch to a pay-as-you-go model, +where you pay for the specific amount of processing you use. This is the +recommended path for uninterrupted access. To do this, log in using a Gemini API key or Vertex AI. - Vertex AI (Regular Mode): - - Quota: Governed by a dynamic shared quota system or pre-purchased provisioned throughput. + - Quota: Governed by a dynamic shared quota system or pre-purchased + provisioned throughput. - Cost: Based on model and token usage. -Learn more at [Vertex AI Dynamic Shared Quota](https://cloud.google.com/vertex-ai/generative-ai/docs/resources/dynamic-shared-quota) and [Vertex AI Pricing](https://cloud.google.com/vertex-ai/pricing). +Learn more at +[Vertex AI Dynamic Shared Quota](https://cloud.google.com/vertex-ai/generative-ai/docs/resources/dynamic-shared-quota) +and [Vertex AI Pricing](https://cloud.google.com/vertex-ai/pricing). - Gemini API key: - Quota: Varies by pricing tier. - Cost: Varies by pricing tier and model/token usage. -Learn more at [Gemini API Rate Limits](https://ai.google.dev/gemini-api/docs/rate-limits), [Gemini API Pricing](https://ai.google.dev/gemini-api/docs/pricing) +Learn more at +[Gemini API Rate Limits](https://ai.google.dev/gemini-api/docs/rate-limits), +[Gemini API Pricing](https://ai.google.dev/gemini-api/docs/pricing) -It’s important to highlight that when using an API key, you pay per token/call. This can be more expensive for many small calls with few tokens, but it's the only way to ensure your workflow isn't interrupted by quota limits. +It’s important to highlight that when using an API key, you pay per token/call. +This can be more expensive for many small calls with few tokens, but it's the +only way to ensure your workflow isn't interrupted by quota limits. ## Gemini for Workspace plans -These plans currently apply only to the use of Gemini web-based products provided by Google-based experiences (for example, the Gemini web app or the Flow video editor). These plans do not apply to the API usage which powers the Gemini CLI. Supporting these plans is under active consideration for future support. +These plans currently apply only to the use of Gemini web-based products +provided by Google-based experiences (for example, the Gemini web app or the +Flow video editor). These plans do not apply to the API usage which powers the +Gemini CLI. Supporting these plans is under active consideration for future +support. ## Tips to Avoid High Costs -When using a Pay as you Go API key, be mindful of your usage to avoid unexpected costs. +When using a Pay as you Go API key, be mindful of your usage to avoid unexpected +costs. -- Don't blindly accept every suggestion, especially for computationally intensive tasks like refactoring large codebases. -- Be intentional with your prompts and commands. You are paying per call, so think about the most efficient way to get the job done. +- Don't blindly accept every suggestion, especially for computationally + intensive tasks like refactoring large codebases. +- Be intentional with your prompts and commands. You are paying per call, so + think about the most efficient way to get the job done. ## Gemini API vs. Vertex -- Gemini API (gemini developer api): This is the fastest way to use the Gemini models directly. -- Vertex AI: This is the enterprise-grade platform for building, deploying, and managing Gemini models with specific security and control requirements. +- Gemini API (gemini developer api): This is the fastest way to use the Gemini + models directly. +- Vertex AI: This is the enterprise-grade platform for building, deploying, and + managing Gemini models with specific security and control requirements. ## Understanding your usage -A summary of model usage is available through the `/stats` command and presented on exit at the end of a session. +A summary of model usage is available through the `/stats` command and presented +on exit at the end of a session. diff --git a/docs/releases.md b/docs/releases.md index 57809b9595..2031bb62b0 100644 --- a/docs/releases.md +++ b/docs/releases.md @@ -2,18 +2,24 @@ ## Release Cadence and Tags -We will follow https://semver.org/ as closely as possible but will call out when or if we have to deviate from it. Our weekly releases will be minor version increments and any bug or hotfixes between releases will go out as patch versions on the most recent release. +We will follow https://semver.org/ as closely as possible but will call out when +or if we have to deviate from it. Our weekly releases will be minor version +increments and any bug or hotfixes between releases will go out as patch +versions on the most recent release. -Each Tuesday ~2000 UTC new Stable and Preview releases will be cut. The promotion flow is: +Each Tuesday ~2000 UTC new Stable and Preview releases will be cut. The +promotion flow is: - Code is committed to main and pushed each night to nightly - After no more than 1 week on main, code is promoted to the `preview` channel - After 1 week the most recent `preview` channel is promoted to `stable` channel -- Patch fixes will be produced against both `preview` and `stable` as needed, with the final 'patch' version number incrementing each time. +- Patch fixes will be produced against both `preview` and `stable` as needed, + with the final 'patch' version number incrementing each time. ### Preview -These releases will not have been fully vetted and may contain regressions or other outstanding issues. Please help us test and install with `preview` tag. +These releases will not have been fully vetted and may contain regressions or +other outstanding issues. Please help us test and install with `preview` tag. ```bash npm install -g @google/gemini-cli@preview @@ -21,7 +27,8 @@ npm install -g @google/gemini-cli@preview ### Stable -This will be the full promotion of last week's release + any bug fixes and validations. Use `latest` tag. +This will be the full promotion of last week's release + any bug fixes and +validations. Use `latest` tag. ```bash npm install -g @google/gemini-cli@latest @@ -29,7 +36,9 @@ npm install -g @google/gemini-cli@latest ### Nightly -- New releases will be published each day at UTC 0000. This will be all changes from the main branch as represented at time of release. It should be assumed there are pending validations and issues. Use `nightly` tag. +- New releases will be published each day at UTC 0000. This will be all changes + from the main branch as represented at time of release. It should be assumed + there are pending validations and issues. Use `nightly` tag. ```bash npm install -g @google/gemini-cli@nightly @@ -37,30 +46,53 @@ npm install -g @google/gemini-cli@nightly ## Weekly Release Promotion -Each Tuesday, the on-call engineer will trigger the "Promote Release" workflow. This single action automates the entire weekly release process: +Each Tuesday, the on-call engineer will trigger the "Promote Release" workflow. +This single action automates the entire weekly release process: -1. **Promotes Preview to Stable:** The workflow identifies the latest `preview` release and promotes it to `stable`. This becomes the new `latest` version on npm. -2. **Promotes Nightly to Preview:** The latest `nightly` release is then promoted to become the new `preview` version. -3. **Prepares for next Nightly:** A pull request is automatically created and merged to bump the version in `main` in preparation for the next nightly release. +1. **Promotes Preview to Stable:** The workflow identifies the latest `preview` + release and promotes it to `stable`. This becomes the new `latest` version + on npm. +2. **Promotes Nightly to Preview:** The latest `nightly` release is then + promoted to become the new `preview` version. +3. **Prepares for next Nightly:** A pull request is automatically created and + merged to bump the version in `main` in preparation for the next nightly + release. -This process ensures a consistent and reliable release cadence with minimal manual intervention. +This process ensures a consistent and reliable release cadence with minimal +manual intervention. ### Source of Truth for Versioning -To ensure the highest reliability, the release promotion process uses the **NPM registry as the single source of truth** for determining the current version of each release channel (`stable`, `preview`, and `nightly`). +To ensure the highest reliability, the release promotion process uses the **NPM +registry as the single source of truth** for determining the current version of +each release channel (`stable`, `preview`, and `nightly`). -1. **Fetch from NPM:** The workflow begins by querying NPM's `dist-tags` (`latest`, `preview`, `nightly`) to get the exact version strings for the packages currently available to users. -2. **Cross-Check for Integrity:** For each version retrieved from NPM, the workflow performs a critical integrity check: +1. **Fetch from NPM:** The workflow begins by querying NPM's `dist-tags` + (`latest`, `preview`, `nightly`) to get the exact version strings for the + packages currently available to users. +2. **Cross-Check for Integrity:** For each version retrieved from NPM, the + workflow performs a critical integrity check: - It verifies that a corresponding **git tag** exists in the repository. - It verifies that a corresponding **GitHub Release** has been created. -3. **Halt on Discrepancy:** If either the git tag or the GitHub Release is missing for a version listed on NPM, the workflow will immediately fail. This strict check prevents promotions from a broken or incomplete previous release and alerts the on-call engineer to a release state inconsistency that must be manually resolved. -4. **Calculate Next Version:** Only after these checks pass does the workflow proceed to calculate the next semantic version based on the trusted version numbers retrieved from NPM. +3. **Halt on Discrepancy:** If either the git tag or the GitHub Release is + missing for a version listed on NPM, the workflow will immediately fail. + This strict check prevents promotions from a broken or incomplete previous + release and alerts the on-call engineer to a release state inconsistency + that must be manually resolved. +4. **Calculate Next Version:** Only after these checks pass does the workflow + proceed to calculate the next semantic version based on the trusted version + numbers retrieved from NPM. -This NPM-first approach, backed by integrity checks, makes the release process highly robust and prevents the kinds of versioning discrepancies that can arise from relying solely on git history or API outputs. +This NPM-first approach, backed by integrity checks, makes the release process +highly robust and prevents the kinds of versioning discrepancies that can arise +from relying solely on git history or API outputs. ## Manual Releases -For situations requiring a release outside of the regular nightly and weekly promotion schedule, and NOT already covered by patching process, you can use the `Release: Manual` workflow. This workflow provides a direct way to publish a specific version from any branch, tag, or commit SHA. +For situations requiring a release outside of the regular nightly and weekly +promotion schedule, and NOT already covered by patching process, you can use the +`Release: Manual` workflow. This workflow provides a direct way to publish a +specific version from any branch, tag, or commit SHA. ### How to Create a Manual Release @@ -68,21 +100,33 @@ For situations requiring a release outside of the regular nightly and weekly pro 2. Select the **Release: Manual** workflow from the list. 3. Click the **Run workflow** dropdown button. 4. Fill in the required inputs: - - **Version**: The exact version to release (e.g., `v0.6.1`). This must be a valid semantic version with a `v` prefix. + - **Version**: The exact version to release (e.g., `v0.6.1`). This must be a + valid semantic version with a `v` prefix. - **Ref**: The branch, tag, or full commit SHA to release from. - - **NPM Channel**: The npm channel to publish to. The options are `preview`, `nightly`, `latest` (for stable releases), and `dev`. The default is `dev`. - - **Dry Run**: Leave as `true` to run all steps without publishing, or set to `false` to perform a live release. - - **Force Skip Tests**: Set to `true` to skip the test suite. This is not recommended for production releases. - - **Skip GitHub Release**: Set to `true` to skip creating a GitHub release and create an npm release only. + - **NPM Channel**: The npm channel to publish to. The options are `preview`, + `nightly`, `latest` (for stable releases), and `dev`. The default is + `dev`. + - **Dry Run**: Leave as `true` to run all steps without publishing, or set + to `false` to perform a live release. + - **Force Skip Tests**: Set to `true` to skip the test suite. This is not + recommended for production releases. + - **Skip GitHub Release**: Set to `true` to skip creating a GitHub release + and create an npm release only. 5. Click **Run workflow**. -The workflow will then proceed to test (if not skipped), build, and publish the release. If the workflow fails during a non-dry run, it will automatically create a GitHub issue with the failure details. +The workflow will then proceed to test (if not skipped), build, and publish the +release. If the workflow fails during a non-dry run, it will automatically +create a GitHub issue with the failure details. ## Rollback/Rollforward -In the event that a release has a critical regression, you can quickly roll back to a previous stable version or roll forward to a new patch by changing the npm `dist-tag`. The `Release: Change Tags` workflow provides a safe and controlled way to do this. +In the event that a release has a critical regression, you can quickly roll back +to a previous stable version or roll forward to a new patch by changing the npm +`dist-tag`. The `Release: Change Tags` workflow provides a safe and controlled +way to do this. -This is the preferred method for both rollbacks and rollforwards, as it does not require a full release cycle. +This is the preferred method for both rollbacks and rollforwards, as it does not +require a full release cycle. ### How to Change a Release Tag @@ -90,16 +134,22 @@ This is the preferred method for both rollbacks and rollforwards, as it does not 2. Select the **Release: Change Tags** workflow from the list. 3. Click the **Run workflow** dropdown button. 4. Fill in the required inputs: - - **Version**: The existing package version that you want to point the tag to (e.g., `0.5.0-preview-2`). This version **must** already be published to the npm registry. + - **Version**: The existing package version that you want to point the tag + to (e.g., `0.5.0-preview-2`). This version **must** already be published + to the npm registry. - **Channel**: The npm `dist-tag` to apply (e.g., `preview`, `stable`). - - **Dry Run**: Leave as `true` to log the action without making changes, or set to `false` to perform the live tag change. + - **Dry Run**: Leave as `true` to log the action without making changes, or + set to `false` to perform the live tag change. 5. Click **Run workflow**. -The workflow will then run `npm dist-tag add` for both the `@google/gemini-cli` and `@google/gemini-cli-core` packages, pointing the specified channel to the specified version. +The workflow will then run `npm dist-tag add` for both the `@google/gemini-cli` +and `@google/gemini-cli-core` packages, pointing the specified channel to the +specified version. ## Patching -If a critical bug that is already fixed on `main` needs to be patched on a `stable` or `preview` release, the process is now highly automated. +If a critical bug that is already fixed on `main` needs to be patched on a +`stable` or `preview` release, the process is now highly automated. ### How to Patch @@ -109,12 +159,14 @@ There are two ways to create a patch pull request: **Option A: From a GitHub Comment (Recommended)** -After a pull request containing the fix has been merged, a maintainer can add a comment on that same PR with the following format: +After a pull request containing the fix has been merged, a maintainer can add a +comment on that same PR with the following format: `/patch [channel]` - **channel** (optional): - - _no channel_ - patches both stable and preview channels (default, recommended for most fixes) + - _no channel_ - patches both stable and preview channels (default, + recommended for most fixes) - `both` - patches both stable and preview channels (same as default) - `stable` - patches only the stable channel - `preview` - patches only the preview channel @@ -126,11 +178,14 @@ Examples: - `/patch stable` (patches only stable) - `/patch preview` (patches only preview) -The `Release: Patch from Comment` workflow will automatically find the merge commit SHA and trigger the `Release: Patch (1) Create PR` workflow. If the PR is not yet merged, it will post a comment indicating the failure. +The `Release: Patch from Comment` workflow will automatically find the merge +commit SHA and trigger the `Release: Patch (1) Create PR` workflow. If the PR is +not yet merged, it will post a comment indicating the failure. **Option B: Manually Triggering the Workflow** -Navigate to the **Actions** tab and run the **Release: Patch (1) Create PR** workflow. +Navigate to the **Actions** tab and run the **Release: Patch (1) Create PR** +workflow. - **Commit**: The full SHA of the commit on `main` that you want to cherry-pick. - **Channel**: The channel you want to patch (`stable` or `preview`). @@ -138,22 +193,30 @@ Navigate to the **Actions** tab and run the **Release: Patch (1) Create PR** wor This workflow will automatically: 1. Find the latest release tag for the channel. -2. Create a release branch from that tag if one doesn't exist (e.g., `release/v0.5.1-pr-12345`). +2. Create a release branch from that tag if one doesn't exist (e.g., + `release/v0.5.1-pr-12345`). 3. Create a new hotfix branch from the release branch. 4. Cherry-pick your specified commit into the hotfix branch. 5. Create a pull request from the hotfix branch back to the release branch. #### 2. Review and Merge -Review the automatically created pull request(s) to ensure the cherry-pick was successful and the changes are correct. Once approved, merge the pull request. +Review the automatically created pull request(s) to ensure the cherry-pick was +successful and the changes are correct. Once approved, merge the pull request. -**Security Note:** The `release/*` branches are protected by branch protection rules. A pull request to one of these branches requires at least one review from a code owner before it can be merged. This ensures that no unauthorized code is released. +**Security Note:** The `release/*` branches are protected by branch protection +rules. A pull request to one of these branches requires at least one review from +a code owner before it can be merged. This ensures that no unauthorized code is +released. #### 2.5. Adding Multiple Commits to a Hotfix (Advanced) -If you need to include multiple fixes in a single patch release, you can add additional commits to the hotfix branch after the initial patch PR has been created: +If you need to include multiple fixes in a single patch release, you can add +additional commits to the hotfix branch after the initial patch PR has been +created: -1. **Start with the primary fix**: Use `/patch` (or `/patch both`) on the most important PR to create the initial hotfix branch and PR. +1. **Start with the primary fix**: Use `/patch` (or `/patch both`) on the most + important PR to create the initial hotfix branch and PR. 2. **Checkout the hotfix branch locally**: @@ -176,32 +239,46 @@ If you need to include multiple fixes in a single patch release, you can add add git push origin hotfix/v0.5.1/stable/cherry-pick-abc1234 ``` -5. **Test and review**: The existing patch PR will automatically update with your additional commits. Test thoroughly since you're now releasing multiple changes together. +5. **Test and review**: The existing patch PR will automatically update with + your additional commits. Test thoroughly since you're now releasing multiple + changes together. -6. **Update the PR description**: Consider updating the PR title and description to reflect that it includes multiple fixes. +6. **Update the PR description**: Consider updating the PR title and description + to reflect that it includes multiple fixes. -This approach allows you to group related fixes into a single patch release while maintaining full control over what gets included and how conflicts are resolved. +This approach allows you to group related fixes into a single patch release +while maintaining full control over what gets included and how conflicts are +resolved. #### 3. Automatic Release -Upon merging the pull request, the `Release: Patch (2) Trigger` workflow is automatically triggered. It will then start the `Release: Patch (3) Release` workflow, which will: +Upon merging the pull request, the `Release: Patch (2) Trigger` workflow is +automatically triggered. It will then start the `Release: Patch (3) Release` +workflow, which will: 1. Build and test the patched code. 2. Publish the new patch version to npm. 3. Create a new GitHub release with the patch notes. -This fully automated process ensures that patches are created and released consistently and reliably. +This fully automated process ensures that patches are created and released +consistently and reliably. #### Troubleshooting: Older Branch Workflows -**Issue**: If the patch trigger workflow fails with errors like "Resource not accessible by integration" or references to non-existent workflow files (e.g., `patch-release.yml`), this indicates the hotfix branch contains an outdated version of the workflow files. +**Issue**: If the patch trigger workflow fails with errors like "Resource not +accessible by integration" or references to non-existent workflow files (e.g., +`patch-release.yml`), this indicates the hotfix branch contains an outdated +version of the workflow files. -**Root Cause**: When a PR is merged, GitHub Actions runs the workflow definition from the **source branch** (the hotfix branch), not from the target branch (the release branch). If the hotfix branch was created from an older release branch that predates workflow improvements, it will use the old workflow logic. +**Root Cause**: When a PR is merged, GitHub Actions runs the workflow definition +from the **source branch** (the hotfix branch), not from the target branch (the +release branch). If the hotfix branch was created from an older release branch +that predates workflow improvements, it will use the old workflow logic. **Solutions**: -**Option 1: Manual Trigger (Quick Fix)** -Manually trigger the updated workflow from the branch with the latest workflow code: +**Option 1: Manual Trigger (Quick Fix)** Manually trigger the updated workflow +from the branch with the latest workflow code: ```bash # For a preview channel patch with tests skipped @@ -226,10 +303,12 @@ gh workflow run release-patch-2-trigger.yml --ref main \ --field force_skip_tests=true ``` -**Note**: Replace `` with the branch containing the latest workflow improvements (usually `main`, but could be a feature branch if testing updates). +**Note**: Replace `` with the branch containing +the latest workflow improvements (usually `main`, but could be a feature branch +if testing updates). -**Option 2: Update the Hotfix Branch** -Merge the latest main branch into your hotfix branch to get the updated workflows: +**Option 2: Update the Hotfix Branch** Merge the latest main branch into your +hotfix branch to get the updated workflows: ```bash git checkout hotfix/v0.6.0-preview.2/preview/cherry-pick-abc1234 @@ -239,8 +318,8 @@ git push Then close and reopen the PR to retrigger the workflow with the updated version. -**Option 3: Direct Release Trigger** -Skip the trigger workflow entirely and directly run the release workflow: +**Option 3: Direct Release Trigger** Skip the trigger workflow entirely and +directly run the release workflow: ```bash # Replace channel and release_ref with appropriate values @@ -253,31 +332,52 @@ gh workflow run release-patch-3-release.yml --ref main \ ### Docker -We also run a Google cloud build called [release-docker.yml](../.gcp/release-docker.yml). Which publishes the sandbox docker to match your release. This will also be moved to GH and combined with the main release file once service account permissions are sorted out. +We also run a Google cloud build called +[release-docker.yml](../.gcp/release-docker.yml). Which publishes the sandbox +docker to match your release. This will also be moved to GH and combined with +the main release file once service account permissions are sorted out. ## Release Validation -After pushing a new release smoke testing should be performed to ensure that the packages are working as expected. This can be done by installing the packages locally and running a set of tests to ensure that they are functioning correctly. +After pushing a new release smoke testing should be performed to ensure that the +packages are working as expected. This can be done by installing the packages +locally and running a set of tests to ensure that they are functioning +correctly. -- `npx -y @google/gemini-cli@latest --version` to validate the push worked as expected if you were not doing a rc or dev tag -- `npx -y @google/gemini-cli@ --version` to validate the tag pushed appropriately -- _This is destructive locally_ `npm uninstall @google/gemini-cli && npm uninstall -g @google/gemini-cli && npm cache clean --force && npm install @google/gemini-cli@` -- Smoke testing a basic run through of exercising a few llm commands and tools is recommended to ensure that the packages are working as expected. We'll codify this more in the future. +- `npx -y @google/gemini-cli@latest --version` to validate the push worked as + expected if you were not doing a rc or dev tag +- `npx -y @google/gemini-cli@ --version` to validate the tag pushed + appropriately +- _This is destructive locally_ + `npm uninstall @google/gemini-cli && npm uninstall -g @google/gemini-cli && npm cache clean --force && npm install @google/gemini-cli@` +- Smoke testing a basic run through of exercising a few llm commands and tools + is recommended to ensure that the packages are working as expected. We'll + codify this more in the future. ## Local Testing and Validation: Changes to the Packaging and Publishing Process -If you need to test the release process without actually publishing to NPM or creating a public GitHub release, you can trigger the workflow manually from the GitHub UI. +If you need to test the release process without actually publishing to NPM or +creating a public GitHub release, you can trigger the workflow manually from the +GitHub UI. -1. Go to the [Actions tab](https://github.com/google-gemini/gemini-cli/actions/workflows/release-manual.yml) of the repository. +1. Go to the + [Actions tab](https://github.com/google-gemini/gemini-cli/actions/workflows/release-manual.yml) + of the repository. 2. Click on the "Run workflow" dropdown. 3. Leave the `dry_run` option checked (`true`). 4. Click the "Run workflow" button. -This will run the entire release process but will skip the `npm publish` and `gh release create` steps. You can inspect the workflow logs to ensure everything is working as expected. +This will run the entire release process but will skip the `npm publish` and +`gh release create` steps. You can inspect the workflow logs to ensure +everything is working as expected. -It is crucial to test any changes to the packaging and publishing process locally before committing them. This ensures that the packages will be published correctly and that they will work as expected when installed by a user. +It is crucial to test any changes to the packaging and publishing process +locally before committing them. This ensures that the packages will be published +correctly and that they will work as expected when installed by a user. -To validate your changes, you can perform a dry run of the publishing process. This will simulate the publishing process without actually publishing the packages to the npm registry. +To validate your changes, you can perform a dry run of the publishing process. +This will simulate the publishing process without actually publishing the +packages to the npm registry. ```bash npm_package_version=9.9.9 SANDBOX_IMAGE_REGISTRY="registry" SANDBOX_IMAGE_NAME="thename" npm run publish:npm --dry-run @@ -290,60 +390,95 @@ This command will do the following: 3. Create the package tarballs that would be published to npm. 4. Print a summary of the packages that would be published. -You can then inspect the generated tarballs to ensure that they contain the correct files and that the `package.json` files have been updated correctly. The tarballs will be created in the root of each package's directory (e.g., `packages/cli/google-gemini-cli-0.1.6.tgz`). +You can then inspect the generated tarballs to ensure that they contain the +correct files and that the `package.json` files have been updated correctly. The +tarballs will be created in the root of each package's directory (e.g., +`packages/cli/google-gemini-cli-0.1.6.tgz`). -By performing a dry run, you can be confident that your changes to the packaging process are correct and that the packages will be published successfully. +By performing a dry run, you can be confident that your changes to the packaging +process are correct and that the packages will be published successfully. ## Release Deep Dive -The release process creates two distinct types of artifacts for different distribution channels: standard packages for the NPM registry and a single, self-contained executable for GitHub Releases. +The release process creates two distinct types of artifacts for different +distribution channels: standard packages for the NPM registry and a single, +self-contained executable for GitHub Releases. Here are the key stages: **Stage 1: Pre-Release Sanity Checks and Versioning** -- **What happens:** Before any files are moved, the process ensures the project is in a good state. This involves running tests, linting, and type-checking (`npm run preflight`). The version number in the root `package.json` and `packages/cli/package.json` is updated to the new release version. +- **What happens:** Before any files are moved, the process ensures the project + is in a good state. This involves running tests, linting, and type-checking + (`npm run preflight`). The version number in the root `package.json` and + `packages/cli/package.json` is updated to the new release version. **Stage 2: Building the Source Code for NPM** -- **What happens:** The TypeScript source code in `packages/core/src` and `packages/cli/src` is compiled into standard JavaScript. +- **What happens:** The TypeScript source code in `packages/core/src` and + `packages/cli/src` is compiled into standard JavaScript. - **File movement:** - `packages/core/src/**/*.ts` -> compiled to -> `packages/core/dist/` - `packages/cli/src/**/*.ts` -> compiled to -> `packages/cli/dist/` -- **Why:** The TypeScript code written during development needs to be converted into plain JavaScript that can be run by Node.js. The `core` package is built first as the `cli` package depends on it. +- **Why:** The TypeScript code written during development needs to be converted + into plain JavaScript that can be run by Node.js. The `core` package is built + first as the `cli` package depends on it. **Stage 3: Publishing Standard Packages to NPM** -- **What happens:** The `npm publish` command is run for the `@google/gemini-cli-core` and `@google/gemini-cli` packages. -- **Why:** This publishes them as standard Node.js packages. Users installing via `npm install -g @google/gemini-cli` will download these packages, and `npm` will handle installing the `@google/gemini-cli-core` dependency automatically. The code in these packages is not bundled into a single file. +- **What happens:** The `npm publish` command is run for the + `@google/gemini-cli-core` and `@google/gemini-cli` packages. +- **Why:** This publishes them as standard Node.js packages. Users installing + via `npm install -g @google/gemini-cli` will download these packages, and + `npm` will handle installing the `@google/gemini-cli-core` dependency + automatically. The code in these packages is not bundled into a single file. **Stage 4: Assembling and Creating the GitHub Release Asset** -This stage happens _after_ the NPM publish and creates the single-file executable that enables `npx` usage directly from the GitHub repository. +This stage happens _after_ the NPM publish and creates the single-file +executable that enables `npx` usage directly from the GitHub repository. 1. **The JavaScript Bundle is Created:** - - **What happens:** The built JavaScript from both `packages/core/dist` and `packages/cli/dist`, along with all third-party JavaScript dependencies, are bundled by `esbuild` into a single, executable JavaScript file (e.g., `gemini.js`). The `node-pty` library is excluded from this bundle as it contains native binaries. - - **Why:** This creates a single, optimized file that contains all the necessary application code. It simplifies execution for users who want to run the CLI without a full `npm install`, as all dependencies (including the `core` package) are included directly. + - **What happens:** The built JavaScript from both `packages/core/dist` and + `packages/cli/dist`, along with all third-party JavaScript dependencies, + are bundled by `esbuild` into a single, executable JavaScript file (e.g., + `gemini.js`). The `node-pty` library is excluded from this bundle as it + contains native binaries. + - **Why:** This creates a single, optimized file that contains all the + necessary application code. It simplifies execution for users who want to + run the CLI without a full `npm install`, as all dependencies (including + the `core` package) are included directly. 2. **The `bundle` Directory is Assembled:** - - **What happens:** A temporary `bundle` folder is created at the project root. The single `gemini.js` executable is placed inside it, along with other essential files. + - **What happens:** A temporary `bundle` folder is created at the project + root. The single `gemini.js` executable is placed inside it, along with + other essential files. - **File movement:** - `gemini.js` (from esbuild) -> `bundle/gemini.js` - `README.md` -> `bundle/README.md` - `LICENSE` -> `bundle/LICENSE` - `packages/cli/src/utils/*.sb` (sandbox profiles) -> `bundle/` - - **Why:** This creates a clean, self-contained directory with everything needed to run the CLI and understand its license and usage. + - **Why:** This creates a clean, self-contained directory with everything + needed to run the CLI and understand its license and usage. 3. **The GitHub Release is Created:** - - **What happens:** The contents of the `bundle` directory, including the `gemini.js` executable, are attached as assets to a new GitHub Release. - - **Why:** This makes the single-file version of the CLI available for direct download and enables the `npx https://github.com/google-gemini/gemini-cli` command, which downloads and runs this specific bundled asset. + - **What happens:** The contents of the `bundle` directory, including the + `gemini.js` executable, are attached as assets to a new GitHub Release. + - **Why:** This makes the single-file version of the CLI available for + direct download and enables the + `npx https://github.com/google-gemini/gemini-cli` command, which downloads + and runs this specific bundled asset. **Summary of Artifacts** -- **NPM:** Publishes standard, un-bundled Node.js packages. The primary artifact is the code in `packages/cli/dist`, which depends on `@google/gemini-cli-core`. -- **GitHub Release:** Publishes a single, bundled `gemini.js` file that contains all dependencies, for easy execution via `npx`. +- **NPM:** Publishes standard, un-bundled Node.js packages. The primary artifact + is the code in `packages/cli/dist`, which depends on + `@google/gemini-cli-core`. +- **GitHub Release:** Publishes a single, bundled `gemini.js` file that contains + all dependencies, for easy execution via `npx`. -This dual-artifact process ensures that both traditional `npm` users and those who prefer the convenience of `npx` have an optimized experience. +This dual-artifact process ensures that both traditional `npm` users and those +who prefer the convenience of `npx` have an optimized experience. ## Notifications @@ -355,15 +490,21 @@ this type are created. ### Modifying chat notifications -Notifications use [GitHub for Google Chat](https://workspace.google.com/marketplace/app/github_for_google_chat/536184076190). To modify the notifications, use `/github-settings` within the chat space. +Notifications use +[GitHub for Google Chat](https://workspace.google.com/marketplace/app/github_for_google_chat/536184076190). +To modify the notifications, use `/github-settings` within the chat space. -> [!WARNING] -> The following instructions describe a fragile workaround that depends on the internal structure of the chat application's UI. It is likely to break with future updates. +> [!WARNING] The following instructions describe a fragile workaround that +> depends on the internal structure of the chat application's UI. It is likely +> to break with future updates. -The list of available labels is not currently populated correctly. If you want to add a label that does not appear alphabetically in the first 30 labels in the repo, you must use your browser's developer tools to manually modify the UI: +The list of available labels is not currently populated correctly. If you want +to add a label that does not appear alphabetically in the first 30 labels in the +repo, you must use your browser's developer tools to manually modify the UI: 1. Open your browser's developer tools (e.g., Chrome DevTools). 2. In the `/github-settings` dialog, inspect the list of labels. 3. Locate one of the `
  • ` elements representing a label. -4. In the HTML, modify the `data-option-value` attribute of that `
  • ` element to the desired label name (e.g., `release-failure`). +4. In the HTML, modify the `data-option-value` attribute of that `
  • ` element + to the desired label name (e.g., `release-failure`). 5. Click on your modified label in the UI to select it, then save your settings. diff --git a/docs/tools/file-system.md b/docs/tools/file-system.md index ec741096a6..b99ec41681 100644 --- a/docs/tools/file-system.md +++ b/docs/tools/file-system.md @@ -1,51 +1,78 @@ # Gemini CLI file system tools -The Gemini CLI provides a comprehensive suite of tools for interacting with the local file system. These tools allow the Gemini model to read from, write to, list, search, and modify files and directories, all under your control and typically with confirmation for sensitive operations. +The Gemini CLI provides a comprehensive suite of tools for interacting with the +local file system. These tools allow the Gemini model to read from, write to, +list, search, and modify files and directories, all under your control and +typically with confirmation for sensitive operations. -**Note:** All file system tools operate within a `rootDirectory` (usually the current working directory where you launched the CLI) for security. Paths that you provide to these tools are generally expected to be absolute or are resolved relative to this root directory. +**Note:** All file system tools operate within a `rootDirectory` (usually the +current working directory where you launched the CLI) for security. Paths that +you provide to these tools are generally expected to be absolute or are resolved +relative to this root directory. ## 1. `list_directory` (ReadFolder) -`list_directory` lists the names of files and subdirectories directly within a specified directory path. It can optionally ignore entries matching provided glob patterns. +`list_directory` lists the names of files and subdirectories directly within a +specified directory path. It can optionally ignore entries matching provided +glob patterns. - **Tool name:** `list_directory` - **Display name:** ReadFolder - **File:** `ls.ts` - **Parameters:** - `path` (string, required): The absolute path to the directory to list. - - `ignore` (array of strings, optional): A list of glob patterns to exclude from the listing (e.g., `["*.log", ".git"]`). - - `respect_git_ignore` (boolean, optional): Whether to respect `.gitignore` patterns when listing files. Defaults to `true`. + - `ignore` (array of strings, optional): A list of glob patterns to exclude + from the listing (e.g., `["*.log", ".git"]`). + - `respect_git_ignore` (boolean, optional): Whether to respect `.gitignore` + patterns when listing files. Defaults to `true`. - **Behavior:** - Returns a list of file and directory names. - Indicates whether each entry is a directory. - Sorts entries with directories first, then alphabetically. -- **Output (`llmContent`):** A string like: `Directory listing for /path/to/your/folder:\n[DIR] subfolder1\nfile1.txt\nfile2.png` +- **Output (`llmContent`):** A string like: + `Directory listing for /path/to/your/folder:\n[DIR] subfolder1\nfile1.txt\nfile2.png` - **Confirmation:** No. ## 2. `read_file` (ReadFile) -`read_file` reads and returns the content of a specified file. This tool handles text, images (PNG, JPG, GIF, WEBP, SVG, BMP), and PDF files. For text files, it can read specific line ranges. Other binary file types are generally skipped. +`read_file` reads and returns the content of a specified file. This tool handles +text, images (PNG, JPG, GIF, WEBP, SVG, BMP), and PDF files. For text files, it +can read specific line ranges. Other binary file types are generally skipped. - **Tool name:** `read_file` - **Display name:** ReadFile - **File:** `read-file.ts` - **Parameters:** - `path` (string, required): The absolute path to the file to read. - - `offset` (number, optional): For text files, the 0-based line number to start reading from. Requires `limit` to be set. - - `limit` (number, optional): For text files, the maximum number of lines to read. If omitted, reads a default maximum (e.g., 2000 lines) or the entire file if feasible. + - `offset` (number, optional): For text files, the 0-based line number to + start reading from. Requires `limit` to be set. + - `limit` (number, optional): For text files, the maximum number of lines to + read. If omitted, reads a default maximum (e.g., 2000 lines) or the entire + file if feasible. - **Behavior:** - - For text files: Returns the content. If `offset` and `limit` are used, returns only that slice of lines. Indicates if content was truncated due to line limits or line length limits. - - For image and PDF files: Returns the file content as a base64-encoded data structure suitable for model consumption. - - For other binary files: Attempts to identify and skip them, returning a message indicating it's a generic binary file. + - For text files: Returns the content. If `offset` and `limit` are used, + returns only that slice of lines. Indicates if content was truncated due to + line limits or line length limits. + - For image and PDF files: Returns the file content as a base64-encoded data + structure suitable for model consumption. + - For other binary files: Attempts to identify and skip them, returning a + message indicating it's a generic binary file. - **Output:** (`llmContent`): - - For text files: The file content, potentially prefixed with a truncation message (e.g., `[File content truncated: showing lines 1-100 of 500 total lines...]\nActual file content...`). - - For image/PDF files: An object containing `inlineData` with `mimeType` and base64 `data` (e.g., `{ inlineData: { mimeType: 'image/png', data: 'base64encodedstring' } }`). - - For other binary files: A message like `Cannot display content of binary file: /path/to/data.bin`. + - For text files: The file content, potentially prefixed with a truncation + message (e.g., + `[File content truncated: showing lines 1-100 of 500 total lines...]\nActual file content...`). + - For image/PDF files: An object containing `inlineData` with `mimeType` and + base64 `data` (e.g., + `{ inlineData: { mimeType: 'image/png', data: 'base64encodedstring' } }`). + - For other binary files: A message like + `Cannot display content of binary file: /path/to/data.bin`. - **Confirmation:** No. ## 3. `write_file` (WriteFile) -`write_file` writes content to a specified file. If the file exists, it will be overwritten. If the file doesn't exist, it (and any necessary parent directories) will be created. +`write_file` writes content to a specified file. If the file exists, it will be +overwritten. If the file doesn't exist, it (and any necessary parent +directories) will be created. - **Tool name:** `write_file` - **Display name:** WriteFile @@ -56,42 +83,62 @@ The Gemini CLI provides a comprehensive suite of tools for interacting with the - **Behavior:** - Writes the provided `content` to the `file_path`. - Creates parent directories if they don't exist. -- **Output (`llmContent`):** A success message, e.g., `Successfully overwrote file: /path/to/your/file.txt` or `Successfully created and wrote to new file: /path/to/new/file.txt`. -- **Confirmation:** Yes. Shows a diff of changes and asks for user approval before writing. +- **Output (`llmContent`):** A success message, e.g., + `Successfully overwrote file: /path/to/your/file.txt` or + `Successfully created and wrote to new file: /path/to/new/file.txt`. +- **Confirmation:** Yes. Shows a diff of changes and asks for user approval + before writing. ## 4. `glob` (FindFiles) -`glob` finds files matching specific glob patterns (e.g., `src/**/*.ts`, `*.md`), returning absolute paths sorted by modification time (newest first). +`glob` finds files matching specific glob patterns (e.g., `src/**/*.ts`, +`*.md`), returning absolute paths sorted by modification time (newest first). - **Tool name:** `glob` - **Display name:** FindFiles - **File:** `glob.ts` - **Parameters:** - - `pattern` (string, required): The glob pattern to match against (e.g., `"*.py"`, `"src/**/*.js"`). - - `path` (string, optional): The absolute path to the directory to search within. If omitted, searches the tool's root directory. - - `case_sensitive` (boolean, optional): Whether the search should be case-sensitive. Defaults to `false`. - - `respect_git_ignore` (boolean, optional): Whether to respect .gitignore patterns when finding files. Defaults to `true`. + - `pattern` (string, required): The glob pattern to match against (e.g., + `"*.py"`, `"src/**/*.js"`). + - `path` (string, optional): The absolute path to the directory to search + within. If omitted, searches the tool's root directory. + - `case_sensitive` (boolean, optional): Whether the search should be + case-sensitive. Defaults to `false`. + - `respect_git_ignore` (boolean, optional): Whether to respect .gitignore + patterns when finding files. Defaults to `true`. - **Behavior:** - Searches for files matching the glob pattern within the specified directory. - - Returns a list of absolute paths, sorted with the most recently modified files first. - - Ignores common nuisance directories like `node_modules` and `.git` by default. -- **Output (`llmContent`):** A message like: `Found 5 file(s) matching "*.ts" within src, sorted by modification time (newest first):\nsrc/file1.ts\nsrc/subdir/file2.ts...` + - Returns a list of absolute paths, sorted with the most recently modified + files first. + - Ignores common nuisance directories like `node_modules` and `.git` by + default. +- **Output (`llmContent`):** A message like: + `Found 5 file(s) matching "*.ts" within src, sorted by modification time (newest first):\nsrc/file1.ts\nsrc/subdir/file2.ts...` - **Confirmation:** No. ## 5. `search_file_content` (SearchText) -`search_file_content` searches for a regular expression pattern within the content of files in a specified directory. Can filter files by a glob pattern. Returns the lines containing matches, along with their file paths and line numbers. +`search_file_content` searches for a regular expression pattern within the +content of files in a specified directory. Can filter files by a glob pattern. +Returns the lines containing matches, along with their file paths and line +numbers. - **Tool name:** `search_file_content` - **Display name:** SearchText - **File:** `grep.ts` - **Parameters:** - - `pattern` (string, required): The regular expression (regex) to search for (e.g., `"function\s+myFunction"`). - - `path` (string, optional): The absolute path to the directory to search within. Defaults to the current working directory. - - `include` (string, optional): A glob pattern to filter which files are searched (e.g., `"*.js"`, `"src/**/*.{ts,tsx}"`). If omitted, searches most files (respecting common ignores). + - `pattern` (string, required): The regular expression (regex) to search for + (e.g., `"function\s+myFunction"`). + - `path` (string, optional): The absolute path to the directory to search + within. Defaults to the current working directory. + - `include` (string, optional): A glob pattern to filter which files are + searched (e.g., `"*.js"`, `"src/**/*.{ts,tsx}"`). If omitted, searches most + files (respecting common ignores). - **Behavior:** - - Uses `git grep` if available in a Git repository for speed; otherwise, falls back to system `grep` or a JavaScript-based search. - - Returns a list of matching lines, each prefixed with its file path (relative to the search directory) and line number. + - Uses `git grep` if available in a Git repository for speed; otherwise, falls + back to system `grep` or a JavaScript-based search. + - Returns a list of matching lines, each prefixed with its file path (relative + to the search directory) and line number. - **Output (`llmContent`):** A formatted string of matches, e.g.: ``` Found 3 matches for pattern "myFunction" in path "." (filter: "*.ts"): @@ -108,7 +155,10 @@ The Gemini CLI provides a comprehensive suite of tools for interacting with the ## 6. `replace` (Edit) -`replace` replaces text within a file. By default, replaces a single occurrence, but can replace multiple occurrences when `expected_replacements` is specified. This tool is designed for precise, targeted changes and requires significant context around the `old_string` to ensure it modifies the correct location. +`replace` replaces text within a file. By default, replaces a single occurrence, +but can replace multiple occurrences when `expected_replacements` is specified. +This tool is designed for precise, targeted changes and requires significant +context around the `old_string` to ensure it modifies the correct location. - **Tool name:** `replace` - **Display name:** Edit @@ -117,27 +167,50 @@ The Gemini CLI provides a comprehensive suite of tools for interacting with the - `file_path` (string, required): The absolute path to the file to modify. - `old_string` (string, required): The exact literal text to replace. - **CRITICAL:** This string must uniquely identify the single instance to change. It should include at least 3 lines of context _before_ and _after_ the target text, matching whitespace and indentation precisely. If `old_string` is empty, the tool attempts to create a new file at `file_path` with `new_string` as content. + **CRITICAL:** This string must uniquely identify the single instance to + change. It should include at least 3 lines of context _before_ and _after_ + the target text, matching whitespace and indentation precisely. If + `old_string` is empty, the tool attempts to create a new file at `file_path` + with `new_string` as content. - - `new_string` (string, required): The exact literal text to replace `old_string` with. - - `expected_replacements` (number, optional): The number of occurrences to replace. Defaults to `1`. + - `new_string` (string, required): The exact literal text to replace + `old_string` with. + - `expected_replacements` (number, optional): The number of occurrences to + replace. Defaults to `1`. - **Behavior:** - - If `old_string` is empty and `file_path` does not exist, creates a new file with `new_string` as content. - - If `old_string` is provided, it reads the `file_path` and attempts to find exactly one occurrence of `old_string`. + - If `old_string` is empty and `file_path` does not exist, creates a new file + with `new_string` as content. + - If `old_string` is provided, it reads the `file_path` and attempts to find + exactly one occurrence of `old_string`. - If one occurrence is found, it replaces it with `new_string`. - - **Enhanced Reliability (Multi-Stage Edit Correction):** To significantly improve the success rate of edits, especially when the model-provided `old_string` might not be perfectly precise, the tool incorporates a multi-stage edit correction mechanism. - - If the initial `old_string` isn't found or matches multiple locations, the tool can leverage the Gemini model to iteratively refine `old_string` (and potentially `new_string`). - - This self-correction process attempts to identify the unique segment the model intended to modify, making the `replace` operation more robust even with slightly imperfect initial context. -- **Failure conditions:** Despite the correction mechanism, the tool will fail if: + - **Enhanced Reliability (Multi-Stage Edit Correction):** To significantly + improve the success rate of edits, especially when the model-provided + `old_string` might not be perfectly precise, the tool incorporates a + multi-stage edit correction mechanism. + - If the initial `old_string` isn't found or matches multiple locations, the + tool can leverage the Gemini model to iteratively refine `old_string` (and + potentially `new_string`). + - This self-correction process attempts to identify the unique segment the + model intended to modify, making the `replace` operation more robust even + with slightly imperfect initial context. +- **Failure conditions:** Despite the correction mechanism, the tool will fail + if: - `file_path` is not absolute or is outside the root directory. - `old_string` is not empty, but the `file_path` does not exist. - `old_string` is empty, but the `file_path` already exists. - `old_string` is not found in the file after attempts to correct it. - - `old_string` is found multiple times, and the self-correction mechanism cannot resolve it to a single, unambiguous match. + - `old_string` is found multiple times, and the self-correction mechanism + cannot resolve it to a single, unambiguous match. - **Output (`llmContent`):** - - On success: `Successfully modified file: /path/to/file.txt (1 replacements).` or `Created new file: /path/to/new_file.txt with provided content.` - - On failure: An error message explaining the reason (e.g., `Failed to edit, 0 occurrences found...`, `Failed to edit, expected 1 occurrences but found 2...`). -- **Confirmation:** Yes. Shows a diff of the proposed changes and asks for user approval before writing to the file. + - On success: + `Successfully modified file: /path/to/file.txt (1 replacements).` or + `Created new file: /path/to/new_file.txt with provided content.` + - On failure: An error message explaining the reason (e.g., + `Failed to edit, 0 occurrences found...`, + `Failed to edit, expected 1 occurrences but found 2...`). +- **Confirmation:** Yes. Shows a diff of the proposed changes and asks for user + approval before writing to the file. -These file system tools provide a foundation for the Gemini CLI to understand and interact with your local project context. +These file system tools provide a foundation for the Gemini CLI to understand +and interact with your local project context. diff --git a/docs/tools/index.md b/docs/tools/index.md index a56020f4de..a9fd61b748 100644 --- a/docs/tools/index.md +++ b/docs/tools/index.md @@ -1,56 +1,95 @@ # Gemini CLI tools -The Gemini CLI includes built-in tools that the Gemini model uses to interact with your local environment, access information, and perform actions. These tools enhance the CLI's capabilities, enabling it to go beyond text generation and assist with a wide range of tasks. +The Gemini CLI includes built-in tools that the Gemini model uses to interact +with your local environment, access information, and perform actions. These +tools enhance the CLI's capabilities, enabling it to go beyond text generation +and assist with a wide range of tasks. ## Overview of Gemini CLI tools -In the context of the Gemini CLI, tools are specific functions or modules that the Gemini model can request to be executed. For example, if you ask Gemini to "Summarize the contents of `my_document.txt`," the model will likely identify the need to read that file and will request the execution of the `read_file` tool. +In the context of the Gemini CLI, tools are specific functions or modules that +the Gemini model can request to be executed. For example, if you ask Gemini to +"Summarize the contents of `my_document.txt`," the model will likely identify +the need to read that file and will request the execution of the `read_file` +tool. -The core component (`packages/core`) manages these tools, presents their definitions (schemas) to the Gemini model, executes them when requested, and returns the results to the model for further processing into a user-facing response. +The core component (`packages/core`) manages these tools, presents their +definitions (schemas) to the Gemini model, executes them when requested, and +returns the results to the model for further processing into a user-facing +response. These tools provide the following capabilities: -- **Access local information:** Tools allow Gemini to access your local file system, read file contents, list directories, etc. -- **Execute commands:** With tools like `run_shell_command`, Gemini can run shell commands (with appropriate safety measures and user confirmation). +- **Access local information:** Tools allow Gemini to access your local file + system, read file contents, list directories, etc. +- **Execute commands:** With tools like `run_shell_command`, Gemini can run + shell commands (with appropriate safety measures and user confirmation). - **Interact with the web:** Tools can fetch content from URLs. -- **Take actions:** Tools can modify files, write new files, or perform other actions on your system (again, typically with safeguards). -- **Ground responses:** By using tools to fetch real-time or specific local data, Gemini's responses can be more accurate, relevant, and grounded in your actual context. +- **Take actions:** Tools can modify files, write new files, or perform other + actions on your system (again, typically with safeguards). +- **Ground responses:** By using tools to fetch real-time or specific local + data, Gemini's responses can be more accurate, relevant, and grounded in your + actual context. ## How to use Gemini CLI tools -To use Gemini CLI tools, provide a prompt to the Gemini CLI. The process works as follows: +To use Gemini CLI tools, provide a prompt to the Gemini CLI. The process works +as follows: 1. You provide a prompt to the Gemini CLI. 2. The CLI sends the prompt to the core. -3. The core, along with your prompt and conversation history, sends a list of available tools and their descriptions/schemas to the Gemini API. -4. The Gemini model analyzes your request. If it determines that a tool is needed, its response will include a request to execute a specific tool with certain parameters. -5. The core receives this tool request, validates it, and (often after user confirmation for sensitive operations) executes the tool. +3. The core, along with your prompt and conversation history, sends a list of + available tools and their descriptions/schemas to the Gemini API. +4. The Gemini model analyzes your request. If it determines that a tool is + needed, its response will include a request to execute a specific tool with + certain parameters. +5. The core receives this tool request, validates it, and (often after user + confirmation for sensitive operations) executes the tool. 6. The output from the tool is sent back to the Gemini model. -7. The Gemini model uses the tool's output to formulate its final answer, which is then sent back through the core to the CLI and displayed to you. +7. The Gemini model uses the tool's output to formulate its final answer, which + is then sent back through the core to the CLI and displayed to you. -You will typically see messages in the CLI indicating when a tool is being called and whether it succeeded or failed. +You will typically see messages in the CLI indicating when a tool is being +called and whether it succeeded or failed. ## Security and confirmation -Many tools, especially those that can modify your file system or execute commands (`write_file`, `edit`, `run_shell_command`), are designed with safety in mind. The Gemini CLI will typically: +Many tools, especially those that can modify your file system or execute +commands (`write_file`, `edit`, `run_shell_command`), are designed with safety +in mind. The Gemini CLI will typically: -- **Require confirmation:** Prompt you before executing potentially sensitive operations, showing you what action is about to be taken. -- **Utilize sandboxing:** All tools are subject to restrictions enforced by sandboxing (see [Sandboxing in the Gemini CLI](../cli/sandbox.md)). This means that when operating in a sandbox, any tools (including MCP servers) you wish to use must be available _inside_ the sandbox environment. For example, to run an MCP server through `npx`, the `npx` executable must be installed within the sandbox's Docker image or be available in the `sandbox-exec` environment. +- **Require confirmation:** Prompt you before executing potentially sensitive + operations, showing you what action is about to be taken. +- **Utilize sandboxing:** All tools are subject to restrictions enforced by + sandboxing (see [Sandboxing in the Gemini CLI](../cli/sandbox.md)). This means + that when operating in a sandbox, any tools (including MCP servers) you wish + to use must be available _inside_ the sandbox environment. For example, to run + an MCP server through `npx`, the `npx` executable must be installed within the + sandbox's Docker image or be available in the `sandbox-exec` environment. -It's important to always review confirmation prompts carefully before allowing a tool to proceed. +It's important to always review confirmation prompts carefully before allowing a +tool to proceed. ## Learn more about Gemini CLI's tools Gemini CLI's built-in tools can be broadly categorized as follows: -- **[File System Tools](./file-system.md):** For interacting with files and directories (reading, writing, listing, searching, etc.). -- **[Shell Tool](./shell.md) (`run_shell_command`):** For executing shell commands. -- **[Web Fetch Tool](./web-fetch.md) (`web_fetch`):** For retrieving content from URLs. -- **[Web Search Tool](./web-search.md) (`google_web_search`):** For searching the web. -- **[Multi-File Read Tool](./multi-file.md) (`read_many_files`):** A specialized tool for reading content from multiple files or directories. -- **[Memory Tool](./memory.md) (`save_memory`):** For saving and recalling information across sessions. +- **[File System Tools](./file-system.md):** For interacting with files and + directories (reading, writing, listing, searching, etc.). +- **[Shell Tool](./shell.md) (`run_shell_command`):** For executing shell + commands. +- **[Web Fetch Tool](./web-fetch.md) (`web_fetch`):** For retrieving content + from URLs. +- **[Web Search Tool](./web-search.md) (`google_web_search`):** For searching + the web. +- **[Multi-File Read Tool](./multi-file.md) (`read_many_files`):** A specialized + tool for reading content from multiple files or directories. +- **[Memory Tool](./memory.md) (`save_memory`):** For saving and recalling + information across sessions. Additionally, these tools incorporate: -- **[MCP servers](./mcp-server.md)**: MCP servers act as a bridge between the Gemini model and your local environment or other services like APIs. -- **[Sandboxing](../cli/sandbox.md)**: Sandboxing isolates the model and its changes from your environment to reduce potential risk. +- **[MCP servers](./mcp-server.md)**: MCP servers act as a bridge between the + Gemini model and your local environment or other services like APIs. +- **[Sandboxing](../cli/sandbox.md)**: Sandboxing isolates the model and its + changes from your environment to reduce potential risk. diff --git a/docs/tools/mcp-server.md b/docs/tools/mcp-server.md index 32338827d2..e128a895bd 100644 --- a/docs/tools/mcp-server.md +++ b/docs/tools/mcp-server.md @@ -1,38 +1,52 @@ # MCP servers with the Gemini CLI -This document provides a guide to configuring and using Model Context Protocol (MCP) servers with the Gemini CLI. +This document provides a guide to configuring and using Model Context Protocol +(MCP) servers with the Gemini CLI. ## What is an MCP server? -An MCP server is an application that exposes tools and resources to the Gemini CLI through the Model Context Protocol, allowing it to interact with external systems and data sources. MCP servers act as a bridge between the Gemini model and your local environment or other services like APIs. +An MCP server is an application that exposes tools and resources to the Gemini +CLI through the Model Context Protocol, allowing it to interact with external +systems and data sources. MCP servers act as a bridge between the Gemini model +and your local environment or other services like APIs. An MCP server enables the Gemini CLI to: -- **Discover tools:** List available tools, their descriptions, and parameters through standardized schema definitions. -- **Execute tools:** Call specific tools with defined arguments and receive structured responses. -- **Access resources:** Read data from specific resources (though the Gemini CLI primarily focuses on tool execution). +- **Discover tools:** List available tools, their descriptions, and parameters + through standardized schema definitions. +- **Execute tools:** Call specific tools with defined arguments and receive + structured responses. +- **Access resources:** Read data from specific resources (though the Gemini CLI + primarily focuses on tool execution). -With an MCP server, you can extend the Gemini CLI's capabilities to perform actions beyond its built-in features, such as interacting with databases, APIs, custom scripts, or specialized workflows. +With an MCP server, you can extend the Gemini CLI's capabilities to perform +actions beyond its built-in features, such as interacting with databases, APIs, +custom scripts, or specialized workflows. ## Core Integration Architecture -The Gemini CLI integrates with MCP servers through a sophisticated discovery and execution system built into the core package (`packages/core/src/tools/`): +The Gemini CLI integrates with MCP servers through a sophisticated discovery and +execution system built into the core package (`packages/core/src/tools/`): ### Discovery Layer (`mcp-client.ts`) The discovery process is orchestrated by `discoverMcpTools()`, which: -1. **Iterates through configured servers** from your `settings.json` `mcpServers` configuration -2. **Establishes connections** using appropriate transport mechanisms (Stdio, SSE, or Streamable HTTP) +1. **Iterates through configured servers** from your `settings.json` + `mcpServers` configuration +2. **Establishes connections** using appropriate transport mechanisms (Stdio, + SSE, or Streamable HTTP) 3. **Fetches tool definitions** from each server using the MCP protocol -4. **Sanitizes and validates** tool schemas for compatibility with the Gemini API +4. **Sanitizes and validates** tool schemas for compatibility with the Gemini + API 5. **Registers tools** in the global tool registry with conflict resolution ### Execution Layer (`mcp-tool.ts`) Each discovered MCP tool is wrapped in a `DiscoveredMCPTool` instance that: -- **Handles confirmation logic** based on server trust settings and user preferences +- **Handles confirmation logic** based on server trust settings and user + preferences - **Manages tool execution** by calling the MCP server with proper parameters - **Processes responses** for both the LLM context and user display - **Maintains connection state** and handles timeouts @@ -47,19 +61,28 @@ The Gemini CLI supports three MCP transport types: ## How to set up your MCP server -The Gemini CLI uses the `mcpServers` configuration in your `settings.json` file to locate and connect to MCP servers. This configuration supports multiple servers with different transport mechanisms. +The Gemini CLI uses the `mcpServers` configuration in your `settings.json` file +to locate and connect to MCP servers. This configuration supports multiple +servers with different transport mechanisms. ### Configure the MCP server in settings.json -You can configure MCP servers in your `settings.json` file in two main ways: through the top-level `mcpServers` object for specific server definitions, and through the `mcp` object for global settings that control server discovery and execution. +You can configure MCP servers in your `settings.json` file in two main ways: +through the top-level `mcpServers` object for specific server definitions, and +through the `mcp` object for global settings that control server discovery and +execution. #### Global MCP Settings (`mcp`) -The `mcp` object in your `settings.json` allows you to define global rules for all MCP servers. +The `mcp` object in your `settings.json` allows you to define global rules for +all MCP servers. - **`mcp.serverCommand`** (string): A global command to start an MCP server. -- **`mcp.allowed`** (array of strings): A list of MCP server names to allow. If this is set, only servers from this list (matching the keys in the `mcpServers` object) will be connected to. -- **`mcp.excluded`** (array of strings): A list of MCP server names to exclude. Servers in this list will not be connected to. +- **`mcp.allowed`** (array of strings): A list of MCP server names to allow. If + this is set, only servers from this list (matching the keys in the + `mcpServers` object) will be connected to. +- **`mcp.excluded`** (array of strings): A list of MCP server names to exclude. + Servers in this list will not be connected to. **Example:** @@ -74,7 +97,8 @@ The `mcp` object in your `settings.json` allows you to define global rules for a #### Server-Specific Configuration (`mcpServers`) -The `mcpServers` object is where you define each individual MCP server you want the CLI to connect to. +The `mcpServers` object is where you define each individual MCP server you want +the CLI to connect to. ### Configuration Structure @@ -111,22 +135,38 @@ Each server configuration supports the following properties: - **`args`** (string[]): Command-line arguments for Stdio transport - **`headers`** (object): Custom HTTP headers when using `url` or `httpUrl` -- **`env`** (object): Environment variables for the server process. Values can reference environment variables using `$VAR_NAME` or `${VAR_NAME}` syntax +- **`env`** (object): Environment variables for the server process. Values can + reference environment variables using `$VAR_NAME` or `${VAR_NAME}` syntax - **`cwd`** (string): Working directory for Stdio transport -- **`timeout`** (number): Request timeout in milliseconds (default: 600,000ms = 10 minutes) -- **`trust`** (boolean): When `true`, bypasses all tool call confirmations for this server (default: `false`) -- **`includeTools`** (string[]): List of tool names to include from this MCP server. When specified, only the tools listed here will be available from this server (allowlist behavior). If not specified, all tools from the server are enabled by default. -- **`excludeTools`** (string[]): List of tool names to exclude from this MCP server. Tools listed here will not be available to the model, even if they are exposed by the server. **Note:** `excludeTools` takes precedence over `includeTools` - if a tool is in both lists, it will be excluded. -- **`targetAudience`** (string): The OAuth Client ID allowlisted on the IAP-protected application you are trying to access. Used with `authProviderType: 'service_account_impersonation'`. -- **`targetServiceAccount`** (string): The email address of the Google Cloud Service Account to impersonate. Used with `authProviderType: 'service_account_impersonation'`. +- **`timeout`** (number): Request timeout in milliseconds (default: 600,000ms = + 10 minutes) +- **`trust`** (boolean): When `true`, bypasses all tool call confirmations for + this server (default: `false`) +- **`includeTools`** (string[]): List of tool names to include from this MCP + server. When specified, only the tools listed here will be available from this + server (allowlist behavior). If not specified, all tools from the server are + enabled by default. +- **`excludeTools`** (string[]): List of tool names to exclude from this MCP + server. Tools listed here will not be available to the model, even if they are + exposed by the server. **Note:** `excludeTools` takes precedence over + `includeTools` - if a tool is in both lists, it will be excluded. +- **`targetAudience`** (string): The OAuth Client ID allowlisted on the + IAP-protected application you are trying to access. Used with + `authProviderType: 'service_account_impersonation'`. +- **`targetServiceAccount`** (string): The email address of the Google Cloud + Service Account to impersonate. Used with + `authProviderType: 'service_account_impersonation'`. ### OAuth Support for Remote MCP Servers -The Gemini CLI supports OAuth 2.0 authentication for remote MCP servers using SSE or HTTP transports. This enables secure access to MCP servers that require authentication. +The Gemini CLI supports OAuth 2.0 authentication for remote MCP servers using +SSE or HTTP transports. This enables secure access to MCP servers that require +authentication. #### Automatic OAuth Discovery -For servers that support OAuth discovery, you can omit the OAuth configuration and let the CLI discover it automatically: +For servers that support OAuth discovery, you can omit the OAuth configuration +and let the CLI discover it automatically: ```json { @@ -187,12 +227,15 @@ Use the `/mcp auth` command to manage OAuth authentication: #### OAuth Configuration Properties - **`enabled`** (boolean): Enable OAuth for this server -- **`clientId`** (string): OAuth client identifier (optional with dynamic registration) +- **`clientId`** (string): OAuth client identifier (optional with dynamic + registration) - **`clientSecret`** (string): OAuth client secret (optional for public clients) -- **`authorizationUrl`** (string): OAuth authorization endpoint (auto-discovered if omitted) +- **`authorizationUrl`** (string): OAuth authorization endpoint (auto-discovered + if omitted) - **`tokenUrl`** (string): OAuth token endpoint (auto-discovered if omitted) - **`scopes`** (string[]): Required OAuth scopes -- **`redirectUri`** (string): Custom redirect URI (defaults to `http://localhost:7777/oauth/callback`) +- **`redirectUri`** (string): Custom redirect URI (defaults to + `http://localhost:7777/oauth/callback`) - **`tokenParamName`** (string): Query parameter name for tokens in SSE URLs - **`audiences`** (string[]): Audiences the token is valid for @@ -207,12 +250,20 @@ OAuth tokens are automatically: #### Authentication Provider Type -You can specify the authentication provider type using the `authProviderType` property: +You can specify the authentication provider type using the `authProviderType` +property: -- **`authProviderType`** (string): Specifies the authentication provider. Can be one of the following: - - **`dynamic_discovery`** (default): The CLI will automatically discover the OAuth configuration from the server. - - **`google_credentials`**: The CLI will use the Google Application Default Credentials (ADC) to authenticate with the server. When using this provider, you must specify the required scopes. - - **`service_account_impersonation`**: The CLI will impersonate a Google Cloud Service Account to authenticate with the server. This is useful for accessing IAP-protected services (this was specifically designed for Cloud Run services). +- **`authProviderType`** (string): Specifies the authentication provider. Can be + one of the following: + - **`dynamic_discovery`** (default): The CLI will automatically discover the + OAuth configuration from the server. + - **`google_credentials`**: The CLI will use the Google Application Default + Credentials (ADC) to authenticate with the server. When using this provider, + you must specify the required scopes. + - **`service_account_impersonation`**: The CLI will impersonate a Google Cloud + Service Account to authenticate with the server. This is useful for + accessing IAP-protected services (this was specifically designed for Cloud + Run services). #### Google Credentials @@ -232,21 +283,40 @@ You can specify the authentication provider type using the `authProviderType` pr #### Service Account Impersonation -To authenticate with a server using Service Account Impersonation, you must set the `authProviderType` to `service_account_impersonation` and provide the following properties: +To authenticate with a server using Service Account Impersonation, you must set +the `authProviderType` to `service_account_impersonation` and provide the +following properties: -- **`targetAudience`** (string): The OAuth Client ID allowslisted on the IAP-protected application you are trying to access. -- **`targetServiceAccount`** (string): The email address of the Google Cloud Service Account to impersonate. +- **`targetAudience`** (string): The OAuth Client ID allowslisted on the + IAP-protected application you are trying to access. +- **`targetServiceAccount`** (string): The email address of the Google Cloud + Service Account to impersonate. -The CLI will use your local Application Default Credentials (ADC) to generate an OIDC ID token for the specified service account and audience. This token will then be used to authenticate with the MCP server. +The CLI will use your local Application Default Credentials (ADC) to generate an +OIDC ID token for the specified service account and audience. This token will +then be used to authenticate with the MCP server. #### Setup Instructions -1. **[Create](https://cloud.google.com/iap/docs/oauth-client-creation) or use an existing OAuth 2.0 client ID.** To use an existing OAuth 2.0 client ID, follow the steps in [How to share OAuth Clients](https://cloud.google.com/iap/docs/sharing-oauth-clients). -2. **Add the OAuth ID to the allowlist for [programmatic access](https://cloud.google.com/iap/docs/sharing-oauth-clients#programmatic_access) for the application.** Since Cloud Run is not yet a supported resource type in gcloud iap, you must allowlist the Client ID on the project. -3. **Create a service account.** [Documentation](https://cloud.google.com/iam/docs/service-accounts-create#creating), [Cloud Console Link](https://console.cloud.google.com/iam-admin/serviceaccounts) -4. **Add both the service account and users to the IAP Policy** in the "Security" tab of the Cloud Run service itself or via gcloud. -5. **Grant all users and groups** who will access the MCP Server the necessary permissions to [impersonate the service account](https://cloud.google.com/docs/authentication/use-service-account-impersonation) (i.e., `roles/iam.serviceAccountTokenCreator`). -6. **[Enable](https://console.cloud.google.com/apis/library/iamcredentials.googleapis.com) the IAM Credentials API** for your project. +1. **[Create](https://cloud.google.com/iap/docs/oauth-client-creation) or use an + existing OAuth 2.0 client ID.** To use an existing OAuth 2.0 client ID, + follow the steps in + [How to share OAuth Clients](https://cloud.google.com/iap/docs/sharing-oauth-clients). +2. **Add the OAuth ID to the allowlist for + [programmatic access](https://cloud.google.com/iap/docs/sharing-oauth-clients#programmatic_access) + for the application.** Since Cloud Run is not yet a supported resource type + in gcloud iap, you must allowlist the Client ID on the project. +3. **Create a service account.** + [Documentation](https://cloud.google.com/iam/docs/service-accounts-create#creating), + [Cloud Console Link](https://console.cloud.google.com/iam-admin/serviceaccounts) +4. **Add both the service account and users to the IAP Policy** in the + "Security" tab of the Cloud Run service itself or via gcloud. +5. **Grant all users and groups** who will access the MCP Server the necessary + permissions to + [impersonate the service account](https://cloud.google.com/docs/authentication/use-service-account-impersonation) + (i.e., `roles/iam.serviceAccountTokenCreator`). +6. **[Enable](https://console.cloud.google.com/apis/library/iamcredentials.googleapis.com) + the IAM Credentials API** for your project. ### Example Configurations @@ -373,7 +443,8 @@ The CLI will use your local Application Default Credentials (ADC) to generate an ## Discovery Process Deep Dive -When the Gemini CLI starts, it performs MCP server discovery through the following detailed process: +When the Gemini CLI starts, it performs MCP server discovery through the +following detailed process: ### 1. Server Iteration and Connection @@ -384,8 +455,10 @@ For each configured server in `mcpServers`: - `httpUrl` → `StreamableHTTPClientTransport` - `url` → `SSEClientTransport` - `command` → `StdioClientTransport` -3. **Connection establishment:** The MCP client attempts to connect with the configured timeout -4. **Error handling:** Connection failures are logged and the server status is set to `DISCONNECTED` +3. **Connection establishment:** The MCP client attempts to connect with the + configured timeout +4. **Error handling:** Connection failures are logged and the server status is + set to `DISCONNECTED` ### 2. Tool Discovery @@ -393,18 +466,25 @@ Upon successful connection: 1. **Tool listing:** The client calls the MCP server's tool listing endpoint 2. **Schema validation:** Each tool's function declaration is validated -3. **Tool filtering:** Tools are filtered based on `includeTools` and `excludeTools` configuration -4. **Name sanitization:** Tool names are cleaned to meet Gemini API requirements: - - Invalid characters (non-alphanumeric, underscore, dot, hyphen) are replaced with underscores - - Names longer than 63 characters are truncated with middle replacement (`___`) +3. **Tool filtering:** Tools are filtered based on `includeTools` and + `excludeTools` configuration +4. **Name sanitization:** Tool names are cleaned to meet Gemini API + requirements: + - Invalid characters (non-alphanumeric, underscore, dot, hyphen) are replaced + with underscores + - Names longer than 63 characters are truncated with middle replacement + (`___`) ### 3. Conflict Resolution When multiple servers expose tools with the same name: -1. **First registration wins:** The first server to register a tool name gets the unprefixed name -2. **Automatic prefixing:** Subsequent servers get prefixed names: `serverName__toolName` -3. **Registry tracking:** The tool registry maintains mappings between server names and their tools +1. **First registration wins:** The first server to register a tool name gets + the unprefixed name +2. **Automatic prefixing:** Subsequent servers get prefixed names: + `serverName__toolName` +3. **Registry tracking:** The tool registry maintains mappings between server + names and their tools ### 4. Schema Processing @@ -412,20 +492,25 @@ Tool parameter schemas undergo sanitization for Gemini API compatibility: - **`$schema` properties** are removed - **`additionalProperties`** are stripped -- **`anyOf` with `default`** have their default values removed (Vertex AI compatibility) +- **`anyOf` with `default`** have their default values removed (Vertex AI + compatibility) - **Recursive processing** applies to nested schemas ### 5. Connection Management After discovery: -- **Persistent connections:** Servers that successfully register tools maintain their connections -- **Cleanup:** Servers that provide no usable tools have their connections closed -- **Status updates:** Final server statuses are set to `CONNECTED` or `DISCONNECTED` +- **Persistent connections:** Servers that successfully register tools maintain + their connections +- **Cleanup:** Servers that provide no usable tools have their connections + closed +- **Status updates:** Final server statuses are set to `CONNECTED` or + `DISCONNECTED` ## Tool Execution Flow -When the Gemini model decides to use an MCP tool, the following execution flow occurs: +When the Gemini model decides to use an MCP tool, the following execution flow +occurs: ### 1. Tool Invocation @@ -478,20 +563,23 @@ Upon confirmation (or trust bypass): ]; ``` -3. **Response processing:** Results are formatted for both LLM context and user display +3. **Response processing:** Results are formatted for both LLM context and user + display ### 4. Response Handling The execution result contains: - **`llmContent`:** Raw response parts for the language model's context -- **`returnDisplay`:** Formatted output for user display (often JSON in markdown code blocks) +- **`returnDisplay`:** Formatted output for user display (often JSON in markdown + code blocks) ## How to interact with your MCP server ### Using the `/mcp` Command -The `/mcp` command provides comprehensive information about your MCP server setup: +The `/mcp` command provides comprehensive information about your MCP server +setup: ```bash /mcp @@ -529,7 +617,8 @@ Discovery State: COMPLETED ### Tool Usage -Once discovered, MCP tools are available to the Gemini model like built-in tools. The model will automatically: +Once discovered, MCP tools are available to the Gemini model like built-in +tools. The model will automatically: 1. **Select appropriate tools** based on your requests 2. **Present confirmation dialogs** (unless the server is trusted) @@ -575,7 +664,8 @@ The MCP integration tracks several states: **Troubleshooting:** 1. **Verify tool registration:** Ensure your server actually registers tools -2. **Check MCP protocol:** Confirm your server implements the MCP tool listing correctly +2. **Check MCP protocol:** Confirm your server implements the MCP tool listing + correctly 3. **Review server logs:** Check stderr output for server-side errors 4. **Test tool listing:** Manually test your server's tool discovery endpoint @@ -597,53 +687,81 @@ The MCP integration tracks several states: **Solutions:** 1. **Docker-based servers:** Use Docker containers that include all dependencies -2. **Path accessibility:** Ensure server executables are available in the sandbox +2. **Path accessibility:** Ensure server executables are available in the + sandbox 3. **Network access:** Configure sandbox to allow necessary network connections -4. **Environment variables:** Verify required environment variables are passed through +4. **Environment variables:** Verify required environment variables are passed + through ### Debugging Tips 1. **Enable debug mode:** Run the CLI with `--debug` for verbose output -2. **Check stderr:** MCP server stderr is captured and logged (INFO messages filtered) +2. **Check stderr:** MCP server stderr is captured and logged (INFO messages + filtered) 3. **Test isolation:** Test your MCP server independently before integrating -4. **Incremental setup:** Start with simple tools before adding complex functionality +4. **Incremental setup:** Start with simple tools before adding complex + functionality 5. **Use `/mcp` frequently:** Monitor server status during development ## Important Notes ### Security Considerations -- **Trust settings:** The `trust` option bypasses all confirmation dialogs. Use cautiously and only for servers you completely control -- **Access tokens:** Be security-aware when configuring environment variables containing API keys or tokens -- **Sandbox compatibility:** When using sandboxing, ensure MCP servers are available within the sandbox environment -- **Private data:** Using broadly scoped personal access tokens can lead to information leakage between repositories +- **Trust settings:** The `trust` option bypasses all confirmation dialogs. Use + cautiously and only for servers you completely control +- **Access tokens:** Be security-aware when configuring environment variables + containing API keys or tokens +- **Sandbox compatibility:** When using sandboxing, ensure MCP servers are + available within the sandbox environment +- **Private data:** Using broadly scoped personal access tokens can lead to + information leakage between repositories ### Performance and Resource Management -- **Connection persistence:** The CLI maintains persistent connections to servers that successfully register tools -- **Automatic cleanup:** Connections to servers providing no tools are automatically closed -- **Timeout management:** Configure appropriate timeouts based on your server's response characteristics -- **Resource monitoring:** MCP servers run as separate processes and consume system resources +- **Connection persistence:** The CLI maintains persistent connections to + servers that successfully register tools +- **Automatic cleanup:** Connections to servers providing no tools are + automatically closed +- **Timeout management:** Configure appropriate timeouts based on your server's + response characteristics +- **Resource monitoring:** MCP servers run as separate processes and consume + system resources ### Schema Compatibility -- **Property stripping:** The system automatically removes certain schema properties (`$schema`, `additionalProperties`) for Gemini API compatibility -- **Name sanitization:** Tool names are automatically sanitized to meet API requirements -- **Conflict resolution:** Tool name conflicts between servers are resolved through automatic prefixing +- **Property stripping:** The system automatically removes certain schema + properties (`$schema`, `additionalProperties`) for Gemini API compatibility +- **Name sanitization:** Tool names are automatically sanitized to meet API + requirements +- **Conflict resolution:** Tool name conflicts between servers are resolved + through automatic prefixing -This comprehensive integration makes MCP servers a powerful way to extend the Gemini CLI's capabilities while maintaining security, reliability, and ease of use. +This comprehensive integration makes MCP servers a powerful way to extend the +Gemini CLI's capabilities while maintaining security, reliability, and ease of +use. ## Returning Rich Content from Tools -MCP tools are not limited to returning simple text. You can return rich, multi-part content, including text, images, audio, and other binary data in a single tool response. This allows you to build powerful tools that can provide diverse information to the model in a single turn. +MCP tools are not limited to returning simple text. You can return rich, +multi-part content, including text, images, audio, and other binary data in a +single tool response. This allows you to build powerful tools that can provide +diverse information to the model in a single turn. -All data returned from the tool is processed and sent to the model as context for its next generation, enabling it to reason about or summarize the provided information. +All data returned from the tool is processed and sent to the model as context +for its next generation, enabling it to reason about or summarize the provided +information. ### How It Works -To return rich content, your tool's response must adhere to the MCP specification for a [`CallToolResult`](https://modelcontextprotocol.io/specification/2025-06-18/server/tools#tool-result). The `content` field of the result should be an array of `ContentBlock` objects. The Gemini CLI will correctly process this array, separating text from binary data and packaging it for the model. +To return rich content, your tool's response must adhere to the MCP +specification for a +[`CallToolResult`](https://modelcontextprotocol.io/specification/2025-06-18/server/tools#tool-result). +The `content` field of the result should be an array of `ContentBlock` objects. +The Gemini CLI will correctly process this array, separating text from binary +data and packaging it for the model. -You can mix and match different content block types in the `content` array. The supported block types include: +You can mix and match different content block types in the `content` array. The +supported block types include: - `text` - `image` @@ -653,7 +771,8 @@ You can mix and match different content block types in the `content` array. The ### Example: Returning Text and an Image -Here is an example of a valid JSON response from an MCP tool that returns both a text description and an image: +Here is an example of a valid JSON response from an MCP tool that returns both a +text description and an image: ```json { @@ -677,15 +796,20 @@ Here is an example of a valid JSON response from an MCP tool that returns both a When the Gemini CLI receives this response, it will: -1. Extract all the text and combine it into a single `functionResponse` part for the model. +1. Extract all the text and combine it into a single `functionResponse` part + for the model. 2. Present the image data as a separate `inlineData` part. -3. Provide a clean, user-friendly summary in the CLI, indicating that both text and an image were received. +3. Provide a clean, user-friendly summary in the CLI, indicating that both text + and an image were received. -This enables you to build sophisticated tools that can provide rich, multi-modal context to the Gemini model. +This enables you to build sophisticated tools that can provide rich, multi-modal +context to the Gemini model. ## MCP Prompts as Slash Commands -In addition to tools, MCP servers can expose predefined prompts that can be executed as slash commands within the Gemini CLI. This allows you to create shortcuts for common or complex queries that can be easily invoked by name. +In addition to tools, MCP servers can expose predefined prompts that can be +executed as slash commands within the Gemini CLI. This allows you to create +shortcuts for common or complex queries that can be easily invoked by name. ### Defining Prompts on the Server @@ -740,7 +864,8 @@ This can be included in `settings.json` under `mcpServers` with: ### Invoking Prompts -Once a prompt is discovered, you can invoke it using its name as a slash command. The CLI will automatically handle parsing arguments. +Once a prompt is discovered, you can invoke it using its name as a slash +command. The CLI will automatically handle parsing arguments. ```bash /poem-writer --title="Gemini CLI" --mood="reverent" @@ -752,15 +877,25 @@ or, using positional arguments: /poem-writer "Gemini CLI" reverent ``` -When you run this command, the Gemini CLI executes the `prompts/get` method on the MCP server with the provided arguments. The server is responsible for substituting the arguments into the prompt template and returning the final prompt text. The CLI then sends this prompt to the model for execution. This provides a convenient way to automate and share common workflows. +When you run this command, the Gemini CLI executes the `prompts/get` method on +the MCP server with the provided arguments. The server is responsible for +substituting the arguments into the prompt template and returning the final +prompt text. The CLI then sends this prompt to the model for execution. This +provides a convenient way to automate and share common workflows. ## Managing MCP Servers with `gemini mcp` -While you can always configure MCP servers by manually editing your `settings.json` file, the Gemini CLI provides a convenient set of commands to manage your server configurations programmatically. These commands streamline the process of adding, listing, and removing MCP servers without needing to directly edit JSON files. +While you can always configure MCP servers by manually editing your +`settings.json` file, the Gemini CLI provides a convenient set of commands to +manage your server configurations programmatically. These commands streamline +the process of adding, listing, and removing MCP servers without needing to +directly edit JSON files. ### Adding a Server (`gemini mcp add`) -The `add` command configures a new MCP server in your `settings.json`. Based on the scope (`-s, --scope`), it will be added to either the user config `~/.gemini/settings.json` or the project config `.gemini/settings.json` file. +The `add` command configures a new MCP server in your `settings.json`. Based on +the scope (`-s, --scope`), it will be added to either the user config +`~/.gemini/settings.json` or the project config `.gemini/settings.json` file. **Command:** @@ -769,7 +904,8 @@ gemini mcp add [options] [args...] ``` - ``: A unique name for the server. -- ``: The command to execute (for `stdio`) or the URL (for `http`/`sse`). +- ``: The command to execute (for `stdio`) or the URL (for + `http`/`sse`). - `[args...]`: Optional arguments for a `stdio` command. **Options (Flags):** @@ -777,7 +913,8 @@ gemini mcp add [options] [args...] - `-s, --scope`: Configuration scope (user or project). [default: "project"] - `-t, --transport`: Transport type (stdio, sse, http). [default: "stdio"] - `-e, --env`: Set environment variables (e.g. -e KEY=value). -- `-H, --header`: Set HTTP headers for SSE and HTTP transports (e.g. -H "X-Api-Key: abc123" -H "Authorization: Bearer abc123"). +- `-H, --header`: Set HTTP headers for SSE and HTTP transports (e.g. -H + "X-Api-Key: abc123" -H "Authorization: Bearer abc123"). - `--timeout`: Set connection timeout in milliseconds. - `--trust`: Trust the server (bypass all tool call confirmation prompts). - `--description`: Set the description for the server. @@ -831,7 +968,8 @@ gemini mcp add --transport sse secure-sse https://api.example.com/sse/ --header ### Listing Servers (`gemini mcp list`) -To view all MCP servers currently configured, use the `list` command. It displays each server's name, configuration details, and connection status. +To view all MCP servers currently configured, use the `list` command. It +displays each server's name, configuration details, and connection status. **Command:** @@ -849,7 +987,8 @@ gemini mcp list ### Removing a Server (`gemini mcp remove`) -To delete a server from your configuration, use the `remove` command with the server's name. +To delete a server from your configuration, use the `remove` command with the +server's name. **Command:** @@ -863,4 +1002,5 @@ gemini mcp remove gemini mcp remove my-server ``` -This will find and delete the "my-server" entry from the `mcpServers` object in the appropriate `settings.json` file based on the scope (`-s, --scope`). +This will find and delete the "my-server" entry from the `mcpServers` object in +the appropriate `settings.json` file based on the scope (`-s, --scope`). diff --git a/docs/tools/memory.md b/docs/tools/memory.md index fa2dac5775..cbe572c5ab 100644 --- a/docs/tools/memory.md +++ b/docs/tools/memory.md @@ -4,19 +4,27 @@ This document describes the `save_memory` tool for the Gemini CLI. ## Description -Use `save_memory` to save and recall information across your Gemini CLI sessions. With `save_memory`, you can direct the CLI to remember key details across sessions, providing personalized and directed assistance. +Use `save_memory` to save and recall information across your Gemini CLI +sessions. With `save_memory`, you can direct the CLI to remember key details +across sessions, providing personalized and directed assistance. ### Arguments `save_memory` takes one argument: -- `fact` (string, required): The specific fact or piece of information to remember. This should be a clear, self-contained statement written in natural language. +- `fact` (string, required): The specific fact or piece of information to + remember. This should be a clear, self-contained statement written in natural + language. ## How to use `save_memory` with the Gemini CLI -The tool appends the provided `fact` to a special `GEMINI.md` file located in the user's home directory (`~/.gemini/GEMINI.md`). This file can be configured to have a different name. +The tool appends the provided `fact` to a special `GEMINI.md` file located in +the user's home directory (`~/.gemini/GEMINI.md`). This file can be configured +to have a different name. -Once added, the facts are stored under a `## Gemini Added Memories` section. This file is loaded as context in subsequent sessions, allowing the CLI to recall the saved information. +Once added, the facts are stored under a `## Gemini Added Memories` section. +This file is loaded as context in subsequent sessions, allowing the CLI to +recall the saved information. Usage: @@ -40,5 +48,7 @@ save_memory(fact="The project I'm currently working on is called 'gemini-cli'.") ## Important notes -- **General usage:** This tool should be used for concise, important facts. It is not intended for storing large amounts of data or conversational history. -- **Memory file:** The memory file is a plain text Markdown file, so you can view and edit it manually if needed. +- **General usage:** This tool should be used for concise, important facts. It + is not intended for storing large amounts of data or conversational history. +- **Memory file:** The memory file is a plain text Markdown file, so you can + view and edit it manually if needed. diff --git a/docs/tools/multi-file.md b/docs/tools/multi-file.md index 7aaff147dd..3855d6872e 100644 --- a/docs/tools/multi-file.md +++ b/docs/tools/multi-file.md @@ -4,34 +4,61 @@ This document describes the `read_many_files` tool for the Gemini CLI. ## Description -Use `read_many_files` to read content from multiple files specified by paths or glob patterns. The behavior of this tool depends on the provided files: +Use `read_many_files` to read content from multiple files specified by paths or +glob patterns. The behavior of this tool depends on the provided files: - For text files, this tool concatenates their content into a single string. -- For image (e.g., PNG, JPEG), PDF, audio (MP3, WAV), and video (MP4, MOV) files, it reads and returns them as base64-encoded data, provided they are explicitly requested by name or extension. +- For image (e.g., PNG, JPEG), PDF, audio (MP3, WAV), and video (MP4, MOV) + files, it reads and returns them as base64-encoded data, provided they are + explicitly requested by name or extension. -`read_many_files` can be used to perform tasks such as getting an overview of a codebase, finding where specific functionality is implemented, reviewing documentation, or gathering context from multiple configuration files. +`read_many_files` can be used to perform tasks such as getting an overview of a +codebase, finding where specific functionality is implemented, reviewing +documentation, or gathering context from multiple configuration files. -**Note:** `read_many_files` looks for files following the provided paths or glob patterns. A directory path such as `"/docs"` will return an empty result; the tool requires a pattern such as `"/docs/*"` or `"/docs/*.md"` to identify the relevant files. +**Note:** `read_many_files` looks for files following the provided paths or glob +patterns. A directory path such as `"/docs"` will return an empty result; the +tool requires a pattern such as `"/docs/*"` or `"/docs/*.md"` to identify the +relevant files. ### Arguments `read_many_files` takes the following arguments: -- `paths` (list[string], required): An array of glob patterns or paths relative to the tool's target directory (e.g., `["src/**/*.ts"]`, `["README.md", "docs/*", "assets/logo.png"]`). -- `exclude` (list[string], optional): Glob patterns for files/directories to exclude (e.g., `["**/*.log", "temp/"]`). These are added to default excludes if `useDefaultExcludes` is true. -- `include` (list[string], optional): Additional glob patterns to include. These are merged with `paths` (e.g., `["*.test.ts"]` to specifically add test files if they were broadly excluded, or `["images/*.jpg"]` to include specific image types). -- `recursive` (boolean, optional): Whether to search recursively. This is primarily controlled by `**` in glob patterns. Defaults to `true`. -- `useDefaultExcludes` (boolean, optional): Whether to apply a list of default exclusion patterns (e.g., `node_modules`, `.git`, non image/pdf binary files). Defaults to `true`. -- `respect_git_ignore` (boolean, optional): Whether to respect .gitignore patterns when finding files. Defaults to true. +- `paths` (list[string], required): An array of glob patterns or paths relative + to the tool's target directory (e.g., `["src/**/*.ts"]`, + `["README.md", "docs/*", "assets/logo.png"]`). +- `exclude` (list[string], optional): Glob patterns for files/directories to + exclude (e.g., `["**/*.log", "temp/"]`). These are added to default excludes + if `useDefaultExcludes` is true. +- `include` (list[string], optional): Additional glob patterns to include. These + are merged with `paths` (e.g., `["*.test.ts"]` to specifically add test files + if they were broadly excluded, or `["images/*.jpg"]` to include specific image + types). +- `recursive` (boolean, optional): Whether to search recursively. This is + primarily controlled by `**` in glob patterns. Defaults to `true`. +- `useDefaultExcludes` (boolean, optional): Whether to apply a list of default + exclusion patterns (e.g., `node_modules`, `.git`, non image/pdf binary files). + Defaults to `true`. +- `respect_git_ignore` (boolean, optional): Whether to respect .gitignore + patterns when finding files. Defaults to true. ## How to use `read_many_files` with the Gemini CLI -`read_many_files` searches for files matching the provided `paths` and `include` patterns, while respecting `exclude` patterns and default excludes (if enabled). +`read_many_files` searches for files matching the provided `paths` and `include` +patterns, while respecting `exclude` patterns and default excludes (if enabled). -- For text files: it reads the content of each matched file (attempting to skip binary files not explicitly requested as image/PDF) and concatenates it into a single string, with a separator `--- {filePath} ---` between the content of each file. Uses UTF-8 encoding by default. +- For text files: it reads the content of each matched file (attempting to skip + binary files not explicitly requested as image/PDF) and concatenates it into a + single string, with a separator `--- {filePath} ---` between the content of + each file. Uses UTF-8 encoding by default. - The tool inserts a `--- End of content ---` after the last file. -- For image and PDF files: if explicitly requested by name or extension (e.g., `paths: ["logo.png"]` or `include: ["*.pdf"]`), the tool reads the file and returns its content as a base64 encoded string. -- The tool attempts to detect and skip other binary files (those not matching common image/PDF types or not explicitly requested) by checking for null bytes in their initial content. +- For image and PDF files: if explicitly requested by name or extension (e.g., + `paths: ["logo.png"]` or `include: ["*.pdf"]`), the tool reads the file and + returns its content as a base64 encoded string. +- The tool attempts to detect and skip other binary files (those not matching + common image/PDF types or not explicitly requested) by checking for null bytes + in their initial content. Usage: @@ -47,13 +74,15 @@ Read all TypeScript files in the `src` directory: read_many_files(paths=["src/**/*.ts"]) ``` -Read the main README, all Markdown files in the `docs` directory, and a specific logo image, excluding a specific file: +Read the main README, all Markdown files in the `docs` directory, and a specific +logo image, excluding a specific file: ``` read_many_files(paths=["README.md", "docs/**/*.md", "assets/logo.png"], exclude=["docs/OLD_README.md"]) ``` -Read all JavaScript files but explicitly include test files and all JPEGs in an `images` folder: +Read all JavaScript files but explicitly include test files and all JPEGs in an +`images` folder: ``` read_many_files(paths=["**/*.js"], include=["**/*.test.js", "images/**/*.jpg"], useDefaultExcludes=False) @@ -62,8 +91,19 @@ read_many_files(paths=["**/*.js"], include=["**/*.test.js", "images/**/*.jpg"], ## Important notes - **Binary file handling:** - - **Image/PDF/Audio/Video files:** The tool can read common image types (PNG, JPEG, etc.), PDF, audio (mp3, wav), and video (mp4, mov) files, returning them as base64 encoded data. These files _must_ be explicitly targeted by the `paths` or `include` patterns (e.g., by specifying the exact filename like `video.mp4` or a pattern like `*.mov`). - - **Other binary files:** The tool attempts to detect and skip other types of binary files by examining their initial content for null bytes. The tool excludes these files from its output. -- **Performance:** Reading a very large number of files or very large individual files can be resource-intensive. -- **Path specificity:** Ensure paths and glob patterns are correctly specified relative to the tool's target directory. For image/PDF files, ensure the patterns are specific enough to include them. -- **Default excludes:** Be aware of the default exclusion patterns (like `node_modules`, `.git`) and use `useDefaultExcludes=False` if you need to override them, but do so cautiously. + - **Image/PDF/Audio/Video files:** The tool can read common image types (PNG, + JPEG, etc.), PDF, audio (mp3, wav), and video (mp4, mov) files, returning + them as base64 encoded data. These files _must_ be explicitly targeted by + the `paths` or `include` patterns (e.g., by specifying the exact filename + like `video.mp4` or a pattern like `*.mov`). + - **Other binary files:** The tool attempts to detect and skip other types of + binary files by examining their initial content for null bytes. The tool + excludes these files from its output. +- **Performance:** Reading a very large number of files or very large individual + files can be resource-intensive. +- **Path specificity:** Ensure paths and glob patterns are correctly specified + relative to the tool's target directory. For image/PDF files, ensure the + patterns are specific enough to include them. +- **Default excludes:** Be aware of the default exclusion patterns (like + `node_modules`, `.git`) and use `useDefaultExcludes=False` if you need to + override them, but do so cautiously. diff --git a/docs/tools/shell.md b/docs/tools/shell.md index 31ce3fed5f..f5ef32ba41 100644 --- a/docs/tools/shell.md +++ b/docs/tools/shell.md @@ -4,21 +4,31 @@ This document describes the `run_shell_command` tool for the Gemini CLI. ## Description -Use `run_shell_command` to interact with the underlying system, run scripts, or perform command-line operations. `run_shell_command` executes a given shell command, including interactive commands that require user input (e.g., `vim`, `git rebase -i`) if the `tools.shell.enableInteractiveShell` setting is set to `true`. +Use `run_shell_command` to interact with the underlying system, run scripts, or +perform command-line operations. `run_shell_command` executes a given shell +command, including interactive commands that require user input (e.g., `vim`, +`git rebase -i`) if the `tools.shell.enableInteractiveShell` setting is set to +`true`. -On Windows, commands are executed with `cmd.exe /c`. On other platforms, they are executed with `bash -c`. +On Windows, commands are executed with `cmd.exe /c`. On other platforms, they +are executed with `bash -c`. ### Arguments `run_shell_command` takes the following arguments: - `command` (string, required): The exact shell command to execute. -- `description` (string, optional): A brief description of the command's purpose, which will be shown to the user. -- `directory` (string, optional): The directory (relative to the project root) in which to execute the command. If not provided, the command runs in the project root. +- `description` (string, optional): A brief description of the command's + purpose, which will be shown to the user. +- `directory` (string, optional): The directory (relative to the project root) + in which to execute the command. If not provided, the command runs in the + project root. ## How to use `run_shell_command` with the Gemini CLI -When using `run_shell_command`, the command is executed as a subprocess. `run_shell_command` can start background processes using `&`. The tool returns detailed information about the execution, including: +When using `run_shell_command`, the command is executed as a subprocess. +`run_shell_command` can start background processes using `&`. The tool returns +detailed information about the execution, including: - `Command`: The command that was executed. - `Directory`: The directory where the command was run. @@ -57,11 +67,16 @@ run_shell_command(command="npm run dev &", description="Start development server ## Configuration -You can configure the behavior of the `run_shell_command` tool by modifying your `settings.json` file or by using the `/settings` command in the Gemini CLI. +You can configure the behavior of the `run_shell_command` tool by modifying your +`settings.json` file or by using the `/settings` command in the Gemini CLI. ### Enabling Interactive Commands -To enable interactive commands, you need to set the `tools.shell.enableInteractiveShell` setting to `true`. This will use `node-pty` for shell command execution, which allows for interactive sessions. If `node-pty` is not available, it will fall back to the `child_process` implementation, which does not support interactive commands. +To enable interactive commands, you need to set the +`tools.shell.enableInteractiveShell` setting to `true`. This will use `node-pty` +for shell command execution, which allows for interactive sessions. If +`node-pty` is not available, it will fall back to the `child_process` +implementation, which does not support interactive commands. **Example `settings.json`:** @@ -77,7 +92,9 @@ To enable interactive commands, you need to set the `tools.shell.enableInteracti ### Showing Color in Output -To show color in the shell output, you need to set the `tools.shell.showColor` setting to `true`. **Note: This setting only applies when `tools.shell.enableInteractiveShell` is enabled.** +To show color in the shell output, you need to set the `tools.shell.showColor` +setting to `true`. **Note: This setting only applies when +`tools.shell.enableInteractiveShell` is enabled.** **Example `settings.json`:** @@ -93,7 +110,9 @@ To show color in the shell output, you need to set the `tools.shell.showColor` s ### Setting the Pager -You can set a custom pager for the shell output by setting the `tools.shell.pager` setting. The default pager is `cat`. **Note: This setting only applies when `tools.shell.enableInteractiveShell` is enabled.** +You can set a custom pager for the shell output by setting the +`tools.shell.pager` setting. The default pager is `cat`. **Note: This setting +only applies when `tools.shell.enableInteractiveShell` is enabled.** **Example `settings.json`:** @@ -109,32 +128,59 @@ You can set a custom pager for the shell output by setting the `tools.shell.page ## Interactive Commands -The `run_shell_command` tool now supports interactive commands by integrating a pseudo-terminal (pty). This allows you to run commands that require real-time user input, such as text editors (`vim`, `nano`), terminal-based UIs (`htop`), and interactive version control operations (`git rebase -i`). +The `run_shell_command` tool now supports interactive commands by integrating a +pseudo-terminal (pty). This allows you to run commands that require real-time +user input, such as text editors (`vim`, `nano`), terminal-based UIs (`htop`), +and interactive version control operations (`git rebase -i`). -When an interactive command is running, you can send input to it from the Gemini CLI. To focus on the interactive shell, press `ctrl+f`. The terminal output, including complex TUIs, will be rendered correctly. +When an interactive command is running, you can send input to it from the Gemini +CLI. To focus on the interactive shell, press `ctrl+f`. The terminal output, +including complex TUIs, will be rendered correctly. ## Important notes -- **Security:** Be cautious when executing commands, especially those constructed from user input, to prevent security vulnerabilities. -- **Error handling:** Check the `Stderr`, `Error`, and `Exit Code` fields to determine if a command executed successfully. -- **Background processes:** When a command is run in the background with `&`, the tool will return immediately and the process will continue to run in the background. The `Background PIDs` field will contain the process ID of the background process. +- **Security:** Be cautious when executing commands, especially those + constructed from user input, to prevent security vulnerabilities. +- **Error handling:** Check the `Stderr`, `Error`, and `Exit Code` fields to + determine if a command executed successfully. +- **Background processes:** When a command is run in the background with `&`, + the tool will return immediately and the process will continue to run in the + background. The `Background PIDs` field will contain the process ID of the + background process. ## Environment Variables -When `run_shell_command` executes a command, it sets the `GEMINI_CLI=1` environment variable in the subprocess's environment. This allows scripts or tools to detect if they are being run from within the Gemini CLI. +When `run_shell_command` executes a command, it sets the `GEMINI_CLI=1` +environment variable in the subprocess's environment. This allows scripts or +tools to detect if they are being run from within the Gemini CLI. ## Command Restrictions -You can restrict the commands that can be executed by the `run_shell_command` tool by using the `tools.core` and `tools.exclude` settings in your configuration file. +You can restrict the commands that can be executed by the `run_shell_command` +tool by using the `tools.core` and `tools.exclude` settings in your +configuration file. -- `tools.core`: To restrict `run_shell_command` to a specific set of commands, add entries to the `core` list under the `tools` category in the format `run_shell_command()`. For example, `"tools": {"core": ["run_shell_command(git)"]}` will only allow `git` commands. Including the generic `run_shell_command` acts as a wildcard, allowing any command not explicitly blocked. -- `tools.exclude`: To block specific commands, add entries to the `exclude` list under the `tools` category in the format `run_shell_command()`. For example, `"tools": {"exclude": ["run_shell_command(rm)"]}` will block `rm` commands. +- `tools.core`: To restrict `run_shell_command` to a specific set of commands, + add entries to the `core` list under the `tools` category in the format + `run_shell_command()`. For example, + `"tools": {"core": ["run_shell_command(git)"]}` will only allow `git` + commands. Including the generic `run_shell_command` acts as a wildcard, + allowing any command not explicitly blocked. +- `tools.exclude`: To block specific commands, add entries to the `exclude` list + under the `tools` category in the format `run_shell_command()`. For + example, `"tools": {"exclude": ["run_shell_command(rm)"]}` will block `rm` + commands. The validation logic is designed to be secure and flexible: -1. **Command Chaining Disabled**: The tool automatically splits commands chained with `&&`, `||`, or `;` and validates each part separately. If any part of the chain is disallowed, the entire command is blocked. -2. **Prefix Matching**: The tool uses prefix matching. For example, if you allow `git`, you can run `git status` or `git log`. -3. **Blocklist Precedence**: The `tools.exclude` list is always checked first. If a command matches a blocked prefix, it will be denied, even if it also matches an allowed prefix in `tools.core`. +1. **Command Chaining Disabled**: The tool automatically splits commands + chained with `&&`, `||`, or `;` and validates each part separately. If any + part of the chain is disallowed, the entire command is blocked. +2. **Prefix Matching**: The tool uses prefix matching. For example, if you + allow `git`, you can run `git status` or `git log`. +3. **Blocklist Precedence**: The `tools.exclude` list is always checked first. + If a command matches a blocked prefix, it will be denied, even if it also + matches an allowed prefix in `tools.core`. ### Command Restriction Examples @@ -173,7 +219,8 @@ To block `rm` and allow all other commands: **Blocklist takes precedence** -If a command prefix is in both `tools.core` and `tools.exclude`, it will be blocked. +If a command prefix is in both `tools.core` and `tools.exclude`, it will be +blocked. ```json { @@ -189,7 +236,8 @@ If a command prefix is in both `tools.core` and `tools.exclude`, it will be bloc **Block all shell commands** -To block all shell commands, add the `run_shell_command` wildcard to `tools.exclude`: +To block all shell commands, add the `run_shell_command` wildcard to +`tools.exclude`: ```json { @@ -204,5 +252,8 @@ To block all shell commands, add the `run_shell_command` wildcard to `tools.excl ## Security Note for `excludeTools` -Command-specific restrictions in `excludeTools` for `run_shell_command` are based on simple string matching and can be easily bypassed. This feature is **not a security mechanism** and should not be relied upon to safely execute untrusted code. It is recommended to use `coreTools` to explicitly select commands -that can be executed. +Command-specific restrictions in `excludeTools` for `run_shell_command` are +based on simple string matching and can be easily bypassed. This feature is +**not a security mechanism** and should not be relied upon to safely execute +untrusted code. It is recommended to use `coreTools` to explicitly select +commands that can be executed. diff --git a/docs/tools/web-fetch.md b/docs/tools/web-fetch.md index a9647df229..e31e5660fe 100644 --- a/docs/tools/web-fetch.md +++ b/docs/tools/web-fetch.md @@ -4,19 +4,32 @@ This document describes the `web_fetch` tool for the Gemini CLI. ## Description -Use `web_fetch` to summarize, compare, or extract information from web pages. The `web_fetch` tool processes content from one or more URLs (up to 20) embedded in a prompt. `web_fetch` takes a natural language prompt and returns a generated response. +Use `web_fetch` to summarize, compare, or extract information from web pages. +The `web_fetch` tool processes content from one or more URLs (up to 20) embedded +in a prompt. `web_fetch` takes a natural language prompt and returns a generated +response. ### Arguments `web_fetch` takes one argument: -- `prompt` (string, required): A comprehensive prompt that includes the URL(s) (up to 20) to fetch and specific instructions on how to process their content. For example: `"Summarize https://example.com/article and extract key points from https://another.com/data"`. The prompt must contain at least one URL starting with `http://` or `https://`. +- `prompt` (string, required): A comprehensive prompt that includes the URL(s) + (up to 20) to fetch and specific instructions on how to process their content. + For example: + `"Summarize https://example.com/article and extract key points from https://another.com/data"`. + The prompt must contain at least one URL starting with `http://` or + `https://`. ## How to use `web_fetch` with the Gemini CLI -To use `web_fetch` with the Gemini CLI, provide a natural language prompt that contains URLs. The tool will ask for confirmation before fetching any URLs. Once confirmed, the tool will process URLs through Gemini API's `urlContext`. +To use `web_fetch` with the Gemini CLI, provide a natural language prompt that +contains URLs. The tool will ask for confirmation before fetching any URLs. Once +confirmed, the tool will process URLs through Gemini API's `urlContext`. -If the Gemini API cannot access the URL, the tool will fall back to fetching content directly from the local machine. The tool will format the response, including source attribution and citations where possible. The tool will then provide the response to the user. +If the Gemini API cannot access the URL, the tool will fall back to fetching +content directly from the local machine. The tool will format the response, +including source attribution and citations where possible. The tool will then +provide the response to the user. Usage: @@ -40,5 +53,7 @@ web_fetch(prompt="What are the differences in the conclusions of these two paper ## Important notes -- **URL processing:** `web_fetch` relies on the Gemini API's ability to access and process the given URLs. -- **Output quality:** The quality of the output will depend on the clarity of the instructions in the prompt. +- **URL processing:** `web_fetch` relies on the Gemini API's ability to access + and process the given URLs. +- **Output quality:** The quality of the output will depend on the clarity of + the instructions in the prompt. diff --git a/docs/tools/web-search.md b/docs/tools/web-search.md index 9ba56bfbd4..d42e092768 100644 --- a/docs/tools/web-search.md +++ b/docs/tools/web-search.md @@ -4,7 +4,9 @@ This document describes the `google_web_search` tool. ## Description -Use `google_web_search` to perform a web search using Google Search via the Gemini API. The `google_web_search` tool returns a summary of web results with sources. +Use `google_web_search` to perform a web search using Google Search via the +Gemini API. The `google_web_search` tool returns a summary of web results with +sources. ### Arguments @@ -14,7 +16,9 @@ Use `google_web_search` to perform a web search using Google Search via the Gemi ## How to use `google_web_search` with the Gemini CLI -The `google_web_search` tool sends a query to the Gemini API, which then performs a web search. `google_web_search` will return a generated response based on the search results, including citations and sources. +The `google_web_search` tool sends a query to the Gemini API, which then +performs a web search. `google_web_search` will return a generated response +based on the search results, including citations and sources. Usage: @@ -32,5 +36,7 @@ google_web_search(query="latest advancements in AI-powered code generation") ## Important notes -- **Response returned:** The `google_web_search` tool returns a processed summary, not a raw list of search results. -- **Citations:** The response includes citations to the sources used to generate the summary. +- **Response returned:** The `google_web_search` tool returns a processed + summary, not a raw list of search results. +- **Citations:** The response includes citations to the sources used to generate + the summary. diff --git a/docs/tos-privacy.md b/docs/tos-privacy.md index 29c8dfe626..8fda67d152 100644 --- a/docs/tos-privacy.md +++ b/docs/tos-privacy.md @@ -1,19 +1,28 @@ # Gemini CLI: Terms of Service and Privacy Notice -Gemini CLI is an open-source tool that lets you interact with Google's powerful language models directly from your command-line interface. The Terms of Service and Privacy Notices that apply to your usage of the Gemini CLI depend on the type of account you use to authenticate with Google. +Gemini CLI is an open-source tool that lets you interact with Google's powerful +language models directly from your command-line interface. The Terms of Service +and Privacy Notices that apply to your usage of the Gemini CLI depend on the +type of account you use to authenticate with Google. -This article outlines the specific terms and privacy policies applicable for different account types and authentication methods. Note: See [quotas and pricing](./quota-and-pricing.md) for the quota and pricing details that apply to your usage of the Gemini CLI. +This article outlines the specific terms and privacy policies applicable for +different account types and authentication methods. Note: See +[quotas and pricing](./quota-and-pricing.md) for the quota and pricing details +that apply to your usage of the Gemini CLI. ## How to determine your authentication method -Your authentication method refers to the method you use to log into and access the Gemini CLI. There are four ways to authenticate: +Your authentication method refers to the method you use to log into and access +the Gemini CLI. There are four ways to authenticate: - Logging in with your Google account to Gemini Code Assist for individuals -- Logging in with your Google account to Gemini Code Assist for Standard, or Enterprise Users +- Logging in with your Google account to Gemini Code Assist for Standard, or + Enterprise Users - Using an API key with Gemini Developer - Using an API key with Vertex AI GenAI API -For each of these four methods of authentication, different Terms of Service and Privacy Notices may apply. +For each of these four methods of authentication, different Terms of Service and +Privacy Notices may apply. | Authentication | Account | Terms of Service | Privacy Notice | | :---------------------------- | :------------------ | :------------------------------------------------------------------------------------------------------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | @@ -25,69 +34,135 @@ For each of these four methods of authentication, different Terms of Service and ## 1. If you have logged in with your Google account to Gemini Code Assist for individuals -For users who use their Google account to access [Gemini Code Assist for individuals](https://developers.google.com/gemini-code-assist/docs/overview#supported-features-gca), these Terms of Service and Privacy Notice documents apply: +For users who use their Google account to access +[Gemini Code Assist for individuals](https://developers.google.com/gemini-code-assist/docs/overview#supported-features-gca), +these Terms of Service and Privacy Notice documents apply: -- **Terms of Service:** Your use of the Gemini CLI is governed by the [Google Terms of Service](https://policies.google.com/terms?hl=en-US). -- **Privacy Notice:** The collection and use of your data is described in the [Gemini Code Assist Privacy Notice for individuals](https://developers.google.com/gemini-code-assist/resources/privacy-notice-gemini-code-assist-individuals). +- **Terms of Service:** Your use of the Gemini CLI is governed by the + [Google Terms of Service](https://policies.google.com/terms?hl=en-US). +- **Privacy Notice:** The collection and use of your data is described in the + [Gemini Code Assist Privacy Notice for individuals](https://developers.google.com/gemini-code-assist/resources/privacy-notice-gemini-code-assist-individuals). ## 2. If you have logged in with your Google account to Gemini Code Assist for Standard, or Enterprise Users -For users who use their Google account to access the [Standard or Enterprise edition](https://cloud.google.com/gemini/docs/codeassist/overview#editions-overview) of Gemini Code Assist, these Terms of Service and Privacy Notice documents apply: +For users who use their Google account to access the +[Standard or Enterprise edition](https://cloud.google.com/gemini/docs/codeassist/overview#editions-overview) +of Gemini Code Assist, these Terms of Service and Privacy Notice documents +apply: -- **Terms of Service:** Your use of the Gemini CLI is governed by the [Google Cloud Platform Terms of Service](https://cloud.google.com/terms). -- **Privacy Notice:** The collection and use of your data is described in the [Gemini Code Assist Privacy Notices for Standard and Enterprise Users](https://cloud.google.com/gemini/docs/codeassist/security-privacy-compliance#standard_and_enterprise_data_protection_and_privacy). +- **Terms of Service:** Your use of the Gemini CLI is governed by the + [Google Cloud Platform Terms of Service](https://cloud.google.com/terms). +- **Privacy Notice:** The collection and use of your data is described in the + [Gemini Code Assist Privacy Notices for Standard and Enterprise Users](https://cloud.google.com/gemini/docs/codeassist/security-privacy-compliance#standard_and_enterprise_data_protection_and_privacy). ## 3. If you have logged in with a Gemini API key to the Gemini Developer API -If you are using a Gemini API key for authentication with the [Gemini Developer API](https://ai.google.dev/gemini-api/docs), these Terms of Service and Privacy Notice documents apply: +If you are using a Gemini API key for authentication with the +[Gemini Developer API](https://ai.google.dev/gemini-api/docs), these Terms of +Service and Privacy Notice documents apply: -- **Terms of Service:** Your use of the Gemini CLI is governed by the [Gemini API Terms of Service](https://ai.google.dev/gemini-api/terms). These terms may differ depending on whether you are using an unpaid or paid service: - - For unpaid services, refer to the [Gemini API Terms of Service - Unpaid Services](https://ai.google.dev/gemini-api/terms#unpaid-services). - - For paid services, refer to the [Gemini API Terms of Service - Paid Services](https://ai.google.dev/gemini-api/terms#paid-services). -- **Privacy Notice:** The collection and use of your data is described in the [Google Privacy Policy](https://policies.google.com/privacy). +- **Terms of Service:** Your use of the Gemini CLI is governed by the + [Gemini API Terms of Service](https://ai.google.dev/gemini-api/terms). These + terms may differ depending on whether you are using an unpaid or paid service: + - For unpaid services, refer to the + [Gemini API Terms of Service - Unpaid Services](https://ai.google.dev/gemini-api/terms#unpaid-services). + - For paid services, refer to the + [Gemini API Terms of Service - Paid Services](https://ai.google.dev/gemini-api/terms#paid-services). +- **Privacy Notice:** The collection and use of your data is described in the + [Google Privacy Policy](https://policies.google.com/privacy). ## 4. If you have logged in with a Gemini API key to the Vertex AI GenAI API -If you are using a Gemini API key for authentication with a [Vertex AI GenAI API](https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest) backend, these Terms of Service and Privacy Notice documents apply: +If you are using a Gemini API key for authentication with a +[Vertex AI GenAI API](https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest) +backend, these Terms of Service and Privacy Notice documents apply: -- **Terms of Service:** Your use of the Gemini CLI is governed by the [Google Cloud Platform Service Terms](https://cloud.google.com/terms/service-terms/). -- **Privacy Notice:** The collection and use of your data is described in the [Google Cloud Privacy Notice](https://cloud.google.com/terms/cloud-privacy-notice). +- **Terms of Service:** Your use of the Gemini CLI is governed by the + [Google Cloud Platform Service Terms](https://cloud.google.com/terms/service-terms/). +- **Privacy Notice:** The collection and use of your data is described in the + [Google Cloud Privacy Notice](https://cloud.google.com/terms/cloud-privacy-notice). ### Usage Statistics Opt-Out -You may opt-out from sending Usage Statistics to Google by following the instructions available here: [Usage Statistics Configuration](./get-started/configuration.md#usage-statistics). +You may opt-out from sending Usage Statistics to Google by following the +instructions available here: +[Usage Statistics Configuration](./get-started/configuration.md#usage-statistics). ## Frequently Asked Questions (FAQ) for the Gemini CLI ### 1. Is my code, including prompts and answers, used to train Google's models? -Whether your code, including prompts and answers, is used to train Google's models depends on the type of authentication method you use and your account type. +Whether your code, including prompts and answers, is used to train Google's +models depends on the type of authentication method you use and your account +type. By default (if you have not opted out): -- **Google account with Gemini Code Assist for individuals**: Yes. When you use your personal Google account, the [Gemini Code Assist Privacy Notice for individuals](https://developers.google.com/gemini-code-assist/resources/privacy-notice-gemini-code-assist-individuals) applies. Under this notice, - your **prompts, answers, and related code are collected** and may be used to improve Google's products, including for model training. -- **Google account with Gemini Code Assist for Standard, or Enterprise**: No. For these accounts, your data is governed by the [Gemini Code Assist Privacy Notices](https://cloud.google.com/gemini/docs/codeassist/security-privacy-compliance#standard_and_enterprise_data_protection_and_privacy) terms, which treat your inputs as confidential. Your **prompts, answers, and related code are not collected** and are not used to train models. -- **Gemini API key via the Gemini Developer API**: Whether your code is collected or used depends on whether you are using an unpaid or paid service. - - **Unpaid services**: Yes. When you use the Gemini API key via the Gemini Developer API with an unpaid service, the [Gemini API Terms of Service - Unpaid Services](https://ai.google.dev/gemini-api/terms#unpaid-services) terms apply. Under this notice, your **prompts, answers, and related code are collected** and may be used to improve Google's products, including for model training. - - **Paid services**: No. When you use the Gemini API key via the Gemini Developer API with a paid service, the [Gemini API Terms of Service - Paid Services](https://ai.google.dev/gemini-api/terms#paid-services) terms apply, which treats your inputs as confidential. Your **prompts, answers, and related code are not collected** and are not used to train models. -- **Gemini API key via the Vertex AI GenAI API**: No. For these accounts, your data is governed by the [Google Cloud Privacy Notice](https://cloud.google.com/terms/cloud-privacy-notice) terms, which treat your inputs as confidential. Your **prompts, answers, and related code are not collected** and are not used to train models. +- **Google account with Gemini Code Assist for individuals**: Yes. When you use + your personal Google account, the + [Gemini Code Assist Privacy Notice for individuals](https://developers.google.com/gemini-code-assist/resources/privacy-notice-gemini-code-assist-individuals) + applies. Under this notice, your **prompts, answers, and related code are + collected** and may be used to improve Google's products, including for model + training. +- **Google account with Gemini Code Assist for Standard, or Enterprise**: No. + For these accounts, your data is governed by the + [Gemini Code Assist Privacy Notices](https://cloud.google.com/gemini/docs/codeassist/security-privacy-compliance#standard_and_enterprise_data_protection_and_privacy) + terms, which treat your inputs as confidential. Your **prompts, answers, and + related code are not collected** and are not used to train models. +- **Gemini API key via the Gemini Developer API**: Whether your code is + collected or used depends on whether you are using an unpaid or paid service. + - **Unpaid services**: Yes. When you use the Gemini API key via the Gemini + Developer API with an unpaid service, the + [Gemini API Terms of Service - Unpaid Services](https://ai.google.dev/gemini-api/terms#unpaid-services) + terms apply. Under this notice, your **prompts, answers, and related code + are collected** and may be used to improve Google's products, including for + model training. + - **Paid services**: No. When you use the Gemini API key via the Gemini + Developer API with a paid service, the + [Gemini API Terms of Service - Paid Services](https://ai.google.dev/gemini-api/terms#paid-services) + terms apply, which treats your inputs as confidential. Your **prompts, + answers, and related code are not collected** and are not used to train + models. +- **Gemini API key via the Vertex AI GenAI API**: No. For these accounts, your + data is governed by the + [Google Cloud Privacy Notice](https://cloud.google.com/terms/cloud-privacy-notice) + terms, which treat your inputs as confidential. Your **prompts, answers, and + related code are not collected** and are not used to train models. For more information about opting out, refer to the next question. ### 2. What are Usage Statistics and what does the opt-out control? -The **Usage Statistics** setting is the single control for all optional data collection in the Gemini CLI. +The **Usage Statistics** setting is the single control for all optional data +collection in the Gemini CLI. The data it collects depends on your account and authentication type: -- **Google account with Gemini Code Assist for individuals**: When enabled, this setting allows Google to collect both anonymous telemetry (for example, commands run and performance metrics) and **your prompts and answers, including code,** for model improvement. -- **Google account with Gemini Code Assist for Standard, or Enterprise**: This setting only controls the collection of anonymous telemetry. Your prompts and answers, including code, are never collected, regardless of this setting. -- **Gemini API key via the Gemini Developer API**: - **Unpaid services**: When enabled, this setting allows Google to collect both anonymous telemetry (like commands run and performance metrics) and **your prompts and answers, including code,** for model improvement. When disabled we will use your data as described in [How Google Uses Your Data](https://ai.google.dev/gemini-api/terms#data-use-unpaid). - **Paid services**: This setting only controls the collection of anonymous telemetry. Google logs prompts and responses for a limited period of time, solely for the purpose of detecting violations of the Prohibited Use Policy and any required legal or regulatory disclosures. -- **Gemini API key via the Vertex AI GenAI API:** This setting only controls the collection of anonymous telemetry. Your prompts and answers, including code, are never collected, regardless of this setting. +- **Google account with Gemini Code Assist for individuals**: When enabled, this + setting allows Google to collect both anonymous telemetry (for example, + commands run and performance metrics) and **your prompts and answers, + including code,** for model improvement. +- **Google account with Gemini Code Assist for Standard, or Enterprise**: This + setting only controls the collection of anonymous telemetry. Your prompts and + answers, including code, are never collected, regardless of this setting. +- **Gemini API key via the Gemini Developer API**: **Unpaid services**: When + enabled, this setting allows Google to collect both anonymous telemetry (like + commands run and performance metrics) and **your prompts and answers, + including code,** for model improvement. When disabled we will use your data + as described in + [How Google Uses Your Data](https://ai.google.dev/gemini-api/terms#data-use-unpaid). + **Paid services**: This setting only controls the collection of anonymous + telemetry. Google logs prompts and responses for a limited period of time, + solely for the purpose of detecting violations of the Prohibited Use Policy + and any required legal or regulatory disclosures. +- **Gemini API key via the Vertex AI GenAI API:** This setting only controls the + collection of anonymous telemetry. Your prompts and answers, including code, + are never collected, regardless of this setting. -Please refer to the Privacy Notice that applies to your authentication method for more information about what data is collected and how this data is used. +Please refer to the Privacy Notice that applies to your authentication method +for more information about what data is collected and how this data is used. -You can disable Usage Statistics for any account type by following the instructions in the [Usage Statistics Configuration](./get-started/configuration-v1.md#usage-statistics) documentation. +You can disable Usage Statistics for any account type by following the +instructions in the +[Usage Statistics Configuration](./get-started/configuration-v1.md#usage-statistics) +documentation. diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index e1fea31c7c..85d6b10dee 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -1,6 +1,7 @@ # Troubleshooting guide -This guide provides solutions to common issues and debugging tips, including topics on: +This guide provides solutions to common issues and debugging tips, including +topics on: - Authentication or login errors - Frequently asked questions (FAQs) @@ -10,58 +11,89 @@ This guide provides solutions to common issues and debugging tips, including top ## Authentication or login errors - **Error: `Failed to login. Message: Request contains an invalid argument`** - - Users with Google Workspace accounts or Google Cloud accounts - associated with their Gmail accounts may not be able to activate the free - tier of the Google Code Assist plan. + - Users with Google Workspace accounts or Google Cloud accounts associated + with their Gmail accounts may not be able to activate the free tier of the + Google Code Assist plan. - For Google Cloud accounts, you can work around this by setting `GOOGLE_CLOUD_PROJECT` to your project ID. - Alternatively, you can obtain the Gemini API key from - [Google AI Studio](http://aistudio.google.com/app/apikey), which also includes a - separate free tier. + [Google AI Studio](http://aistudio.google.com/app/apikey), which also + includes a separate free tier. -- **Error: `UNABLE_TO_GET_ISSUER_CERT_LOCALLY` or `unable to get local issuer certificate`** - - **Cause:** You may be on a corporate network with a firewall that intercepts and inspects SSL/TLS traffic. This often requires a custom root CA certificate to be trusted by Node.js. - - **Solution:** Set the `NODE_EXTRA_CA_CERTS` environment variable to the absolute path of your corporate root CA certificate file. +- **Error: `UNABLE_TO_GET_ISSUER_CERT_LOCALLY` or + `unable to get local issuer certificate`** + - **Cause:** You may be on a corporate network with a firewall that intercepts + and inspects SSL/TLS traffic. This often requires a custom root CA + certificate to be trusted by Node.js. + - **Solution:** Set the `NODE_EXTRA_CA_CERTS` environment variable to the + absolute path of your corporate root CA certificate file. - Example: `export NODE_EXTRA_CA_CERTS=/path/to/your/corporate-ca.crt` ## Common error messages and solutions - **Error: `EADDRINUSE` (Address already in use) when starting an MCP server.** - - **Cause:** Another process is already using the port that the MCP server is trying to bind to. - - **Solution:** - Either stop the other process that is using the port or configure the MCP server to use a different port. + - **Cause:** Another process is already using the port that the MCP server is + trying to bind to. + - **Solution:** Either stop the other process that is using the port or + configure the MCP server to use a different port. -- **Error: Command not found (when attempting to run Gemini CLI with `gemini`).** - - **Cause:** Gemini CLI is not correctly installed or it is not in your system's `PATH`. - - **Solution:** - The update depends on how you installed Gemini CLI: - - If you installed `gemini` globally, check that your `npm` global binary directory is in your `PATH`. You can update Gemini CLI using the command `npm install -g @google/gemini-cli@latest`. - - If you are running `gemini` from source, ensure you are using the correct command to invoke it (e.g., `node packages/cli/dist/index.js ...`). To update Gemini CLI, pull the latest changes from the repository, and then rebuild using the command `npm run build`. +- **Error: Command not found (when attempting to run Gemini CLI with + `gemini`).** + - **Cause:** Gemini CLI is not correctly installed or it is not in your + system's `PATH`. + - **Solution:** The update depends on how you installed Gemini CLI: + - If you installed `gemini` globally, check that your `npm` global binary + directory is in your `PATH`. You can update Gemini CLI using the command + `npm install -g @google/gemini-cli@latest`. + - If you are running `gemini` from source, ensure you are using the correct + command to invoke it (e.g., `node packages/cli/dist/index.js ...`). To + update Gemini CLI, pull the latest changes from the repository, and then + rebuild using the command `npm run build`. - **Error: `MODULE_NOT_FOUND` or import errors.** - - **Cause:** Dependencies are not installed correctly, or the project hasn't been built. + - **Cause:** Dependencies are not installed correctly, or the project hasn't + been built. - **Solution:** 1. Run `npm install` to ensure all dependencies are present. 2. Run `npm run build` to compile the project. 3. Verify that the build completed successfully with `npm run start`. - **Error: "Operation not permitted", "Permission denied", or similar.** - - **Cause:** When sandboxing is enabled, Gemini CLI may attempt operations that are restricted by your sandbox configuration, such as writing outside the project directory or system temp directory. - - **Solution:** Refer to the [Configuration: Sandboxing](./cli/sandbox.md) documentation for more information, including how to customize your sandbox configuration. + - **Cause:** When sandboxing is enabled, Gemini CLI may attempt operations + that are restricted by your sandbox configuration, such as writing outside + the project directory or system temp directory. + - **Solution:** Refer to the [Configuration: Sandboxing](./cli/sandbox.md) + documentation for more information, including how to customize your sandbox + configuration. - **Gemini CLI is not running in interactive mode in "CI" environments** - - **Issue:** The Gemini CLI does not enter interactive mode (no prompt appears) if an environment variable starting with `CI_` (e.g., `CI_TOKEN`) is set. This is because the `is-in-ci` package, used by the underlying UI framework, detects these variables and assumes a non-interactive CI environment. - - **Cause:** The `is-in-ci` package checks for the presence of `CI`, `CONTINUOUS_INTEGRATION`, or any environment variable with a `CI_` prefix. When any of these are found, it signals that the environment is non-interactive, which prevents the Gemini CLI from starting in its interactive mode. - - **Solution:** If the `CI_` prefixed variable is not needed for the CLI to function, you can temporarily unset it for the command. e.g., `env -u CI_TOKEN gemini` + - **Issue:** The Gemini CLI does not enter interactive mode (no prompt + appears) if an environment variable starting with `CI_` (e.g., `CI_TOKEN`) + is set. This is because the `is-in-ci` package, used by the underlying UI + framework, detects these variables and assumes a non-interactive CI + environment. + - **Cause:** The `is-in-ci` package checks for the presence of `CI`, + `CONTINUOUS_INTEGRATION`, or any environment variable with a `CI_` prefix. + When any of these are found, it signals that the environment is + non-interactive, which prevents the Gemini CLI from starting in its + interactive mode. + - **Solution:** If the `CI_` prefixed variable is not needed for the CLI to + function, you can temporarily unset it for the command. e.g., + `env -u CI_TOKEN gemini` - **DEBUG mode not working from project .env file** - - **Issue:** Setting `DEBUG=true` in a project's `.env` file doesn't enable debug mode for gemini-cli. - - **Cause:** The `DEBUG` and `DEBUG_MODE` variables are automatically excluded from project `.env` files to prevent interference with gemini-cli behavior. - - **Solution:** Use a `.gemini/.env` file instead, or configure the `advanced.excludedEnvVars` setting in your `settings.json` to exclude fewer variables. + - **Issue:** Setting `DEBUG=true` in a project's `.env` file doesn't enable + debug mode for gemini-cli. + - **Cause:** The `DEBUG` and `DEBUG_MODE` variables are automatically excluded + from project `.env` files to prevent interference with gemini-cli behavior. + - **Solution:** Use a `.gemini/.env` file instead, or configure the + `advanced.excludedEnvVars` setting in your `settings.json` to exclude fewer + variables. ## Exit Codes -The Gemini CLI uses specific exit codes to indicate the reason for termination. This is especially useful for scripting and automation. +The Gemini CLI uses specific exit codes to indicate the reason for termination. +This is especially useful for scripting and automation. | Exit Code | Error Type | Description | | --------- | -------------------------- | --------------------------------------------------------------------------------------------------- | @@ -74,22 +106,33 @@ The Gemini CLI uses specific exit codes to indicate the reason for termination. ## Debugging Tips - **CLI debugging:** - - Use the `--verbose` flag (if available) with CLI commands for more detailed output. - - Check the CLI logs, often found in a user-specific configuration or cache directory. + - Use the `--verbose` flag (if available) with CLI commands for more detailed + output. + - Check the CLI logs, often found in a user-specific configuration or cache + directory. - **Core debugging:** - Check the server console output for error messages or stack traces. - Increase log verbosity if configurable. - - Use Node.js debugging tools (e.g., `node --inspect`) if you need to step through server-side code. + - Use Node.js debugging tools (e.g., `node --inspect`) if you need to step + through server-side code. - **Tool issues:** - - If a specific tool is failing, try to isolate the issue by running the simplest possible version of the command or operation the tool performs. - - For `run_shell_command`, check that the command works directly in your shell first. - - For _file system tools_, verify that paths are correct and check the permissions. + - If a specific tool is failing, try to isolate the issue by running the + simplest possible version of the command or operation the tool performs. + - For `run_shell_command`, check that the command works directly in your shell + first. + - For _file system tools_, verify that paths are correct and check the + permissions. - **Pre-flight checks:** - - Always run `npm run preflight` before committing code. This can catch many common issues related to formatting, linting, and type errors. + - Always run `npm run preflight` before committing code. This can catch many + common issues related to formatting, linting, and type errors. ## Existing GitHub Issues similar to yours or creating new Issues -If you encounter an issue that was not covered here in this _Troubleshooting guide_, consider searching the Gemini CLI [Issue tracker on GitHub](https://github.com/google-gemini/gemini-cli/issues). If you can't find an issue similar to yours, consider creating a new GitHub Issue with a detailed description. Pull requests are also welcome! +If you encounter an issue that was not covered here in this _Troubleshooting +guide_, consider searching the Gemini CLI +[Issue tracker on GitHub](https://github.com/google-gemini/gemini-cli/issues). +If you can't find an issue similar to yours, consider creating a new GitHub +Issue with a detailed description. Pull requests are also welcome! diff --git a/packages/a2a-server/development-extension-rfc.md b/packages/a2a-server/development-extension-rfc.md index 5cc89c6806..6307e2d8e7 100644 --- a/packages/a2a-server/development-extension-rfc.md +++ b/packages/a2a-server/development-extension-rfc.md @@ -4,31 +4,56 @@ ### 1.1 Overview -To standardize client integrations with the Gemini CLI agent, this document proposes the `development-tool` extension for the A2A protocol. +To standardize client integrations with the Gemini CLI agent, this document +proposes the `development-tool` extension for the A2A protocol. -Rather than creating a new protocol, this specification builds upon the existing A2A protocol. As an open-source standard recently adopted by the Linux Foundation, A2A provides a robust foundation for core concepts like tasks, messages, and streaming events. This extension-based approach allows us to leverage A2A's proven architecture while defining the specific capabilities required for rich, interactive workflows with the Gemini CLI agent. +Rather than creating a new protocol, this specification builds upon the existing +A2A protocol. As an open-source standard recently adopted by the Linux +Foundation, A2A provides a robust foundation for core concepts like tasks, +messages, and streaming events. This extension-based approach allows us to +leverage A2A's proven architecture while defining the specific capabilities +required for rich, interactive workflows with the Gemini CLI agent. ### 1.2 Motivation -Recent work integrating Gemini CLI with clients like Zed and Gemini Code Assist’s agent mode has highlighted the need for a robust, standard communication protocol. Standardizing on A2A provides several key advantages: +Recent work integrating Gemini CLI with clients like Zed and Gemini Code +Assist’s agent mode has highlighted the need for a robust, standard +communication protocol. Standardizing on A2A provides several key advantages: -- **Solid Foundation**: Provides a robust, open standard that ensures a stable, predictable, and consistent integration experience across different IDEs and client surfaces. -- **Extensibility**: Creates a flexible foundation to support new tools and workflows as they emerge. -- **Ecosystem Alignment**: Aligns Gemini CLI with a growing industry standard, fostering broader interoperability. +- **Solid Foundation**: Provides a robust, open standard that ensures a stable, + predictable, and consistent integration experience across different IDEs and + client surfaces. +- **Extensibility**: Creates a flexible foundation to support new tools and + workflows as they emerge. +- **Ecosystem Alignment**: Aligns Gemini CLI with a growing industry standard, + fostering broader interoperability. ## 2. Communication Flow -The interaction follows A2A’s task-based, streaming pattern. The client sends a `message/stream` request and the agent responds with a `contextId` / `taskId` and a stream of events. `TaskStatusUpdateEvent` events are used to convey the overall state of the task. The task is complete when the agent sends a final `TaskStatusUpdateEvent` with `final: true` and a terminal status like `completed` or `failed`. +The interaction follows A2A’s task-based, streaming pattern. The client sends a +`message/stream` request and the agent responds with a `contextId` / `taskId` +and a stream of events. `TaskStatusUpdateEvent` events are used to convey the +overall state of the task. The task is complete when the agent sends a final +`TaskStatusUpdateEvent` with `final: true` and a terminal status like +`completed` or `failed`. ### 2.1 Asynchronous Responses and Notifications -Clients that may disconnect from the agent should supply a `PushNotificationConfig` to the agent with the initial `message/stream` method or subsequently with the `tasks/pushNotificationConfig/set` method so that the agent can call back when updates are ready. +Clients that may disconnect from the agent should supply a +`PushNotificationConfig` to the agent with the initial `message/stream` method +or subsequently with the `tasks/pushNotificationConfig/set` method so that the +agent can call back when updates are ready. ## 3. The `development-tool` extension ### 3.1 Overview -The `development-tool` extension establishes a communication contract for workflows between a client and the Gemini CLI agent. It consists of a specialized set of schemas, embedded within core A2A data structures, that enable the agent to stream real-time updates on its state and thought process. These schemas also provide the mechanism for the agent to request user permission before executing tools. +The `development-tool` extension establishes a communication contract for +workflows between a client and the Gemini CLI agent. It consists of a +specialized set of schemas, embedded within core A2A data structures, that +enable the agent to stream real-time updates on its state and thought process. +These schemas also provide the mechanism for the agent to request user +permission before executing tools. **Sample Agent Card** @@ -51,15 +76,24 @@ The `development-tool` extension establishes a communication contract for workfl **Versioning** -The agent card `uri` field contains an embedded semantic version. The client must extract this version to determine compatibility with the agent extension using the compatibility logic defined in Semantic Versioning 2.0.0 spec. +The agent card `uri` field contains an embedded semantic version. The client +must extract this version to determine compatibility with the agent extension +using the compatibility logic defined in Semantic Versioning 2.0.0 spec. ### 3.2 Schema Definitions -This section defines the schemas for the `development-tool` A2A extension, organized by their function within the communication flow. Note that all custom objects included in the `metadata` field (e.g. `Message.metadata`) must be keyed by the unique URI that points to that extension’s spec to prevent naming collisions with other extensions. +This section defines the schemas for the `development-tool` A2A extension, +organized by their function within the communication flow. Note that all custom +objects included in the `metadata` field (e.g. `Message.metadata`) must be keyed +by the unique URI that points to that extension’s spec to prevent naming +collisions with other extensions. **Initialization & Configuration** -The first message in a session must contain an `AgentSettings` object in its metadata. This object provides the agent with the necessary configuration information for proper initialization. Additional configuration settings (ex. MCP servers, allowed tools, etc.) can be added to this message. +The first message in a session must contain an `AgentSettings` object in its +metadata. This object provides the agent with the necessary configuration +information for proper initialization. Additional configuration settings (ex. +MCP servers, allowed tools, etc.) can be added to this message. **Schema** @@ -75,25 +109,42 @@ message AgentSettings { **Agent-to-Client Messages** -All real-time updates from the agent (including its thoughts, tool calls, and simple text replies) are streamed to the client as `TaskStatusUpdateEvents`. +All real-time updates from the agent (including its thoughts, tool calls, and +simple text replies) are streamed to the client as `TaskStatusUpdateEvents`. -Each Event contains a `Message` object, which holds the content in one of two formats: +Each Event contains a `Message` object, which holds the content in one of two +formats: -- **TextPart**: Used for standard text messages. This part requires no custom schema. -- **DataPart**: Used for complex, structured objects. Tool Calls and Thoughts are sent this way, each using their respective schemas defined below. +- **TextPart**: Used for standard text messages. This part requires no custom + schema. +- **DataPart**: Used for complex, structured objects. Tool Calls and Thoughts + are sent this way, each using their respective schemas defined below. **Tool Calls** -The `ToolCall` schema is designed to provide a structured representation of a tool’s execution lifecycle. This protocol defines a clear state machine and provides detailed schemas for common development tasks (file edits, shell commands, MCP Tool), ensuring clients can build reliable UIs without being tied to a specific agent implementation. +The `ToolCall` schema is designed to provide a structured representation of a +tool’s execution lifecycle. This protocol defines a clear state machine and +provides detailed schemas for common development tasks (file edits, shell +commands, MCP Tool), ensuring clients can build reliable UIs without being tied +to a specific agent implementation. -The core principle is that the agent sends a `ToolCall` object on every update. This makes client-side logic stateless and simple. +The core principle is that the agent sends a `ToolCall` object on every update. +This makes client-side logic stateless and simple. **Tool Call Lifecycle** -1. **Creation**: The agent sends a `ToolCall` object with `status: PENDING`. If user permission is required, the `confirmation_request` field will be populated. -2. **Confirmation**: If the client needs to confirm the message, the client will send a `ToolCallConfirmation`. If the client responds with a cancellation, execution will be skipped. -3. **Execution**: Once approved (or if no approval is required), the agent sends an update with `status: EXECUTING`. It can stream real-time progress by updating the `live_content` field. -4. **Completion**: The agent sends a final update with the status set to `SUCCEEDED`, `FAILED`, or `CANCELLED` and populates the appropriate result field. +1. **Creation**: The agent sends a `ToolCall` object with `status: PENDING`. If + user permission is required, the `confirmation_request` field will be + populated. +2. **Confirmation**: If the client needs to confirm the message, the client + will send a `ToolCallConfirmation`. If the client responds with a + cancellation, execution will be skipped. +3. **Execution**: Once approved (or if no approval is required), the agent + sends an update with `status: EXECUTING`. It can stream real-time progress + by updating the `live_content` field. +4. **Completion**: The agent sends a final update with the status set to + `SUCCEEDED`, `FAILED`, or `CANCELLED` and populates the appropriate result + field. **Schema** @@ -244,7 +295,8 @@ message AgentThought { **Event Metadata** -The `metadata` object in `TaskStatusUpdateEvent` is used by the A2A client to deserialize the `TaskStatusUpdateEvents` into their appropriate objects. +The `metadata` object in `TaskStatusUpdateEvent` is used by the A2A client to +deserialize the `TaskStatusUpdateEvents` into their appropriate objects. **Schema** @@ -280,9 +332,13 @@ message DevelopmentToolEvent { **Client-to-Agent Messages** -When the agent sends a `TaskStatusUpdateEvent` with `status.state` set to `input-required` and its message contains a `ConfirmationRequest`, the client must respond by sending a new `message/stream` request. +When the agent sends a `TaskStatusUpdateEvent` with `status.state` set to +`input-required` and its message contains a `ConfirmationRequest`, the client +must respond by sending a new `message/stream` request. -This new request must include the `contextId` and the `taskId` from the ongoing task and contain a `ToolCallConfirmation` object. This object conveys the user's decision regarding the tool call that was awaiting approval. +This new request must include the `contextId` and the `taskId` from the ongoing +task and contain a `ToolCallConfirmation` object. This object conveys the user's +decision regarding the tool call that was awaiting approval. **Schema** @@ -311,11 +367,14 @@ message ModifiedFileDetails { ### 3.3 Method Definitions -This section defines the new methods introduced by the `development-tool` extension. +This section defines the new methods introduced by the `development-tool` +extension. **Method: `commands/get`** -This method allows the client to discover slash commands supported by Gemini CLI. The client should call this method during startup to dynamically populate its command list. +This method allows the client to discover slash commands supported by Gemini +CLI. The client should call this method during startup to dynamically populate +its command list. ```proto // Response message containing the list of all top-level slash commands. @@ -349,7 +408,12 @@ message SlashCommandArgument { **Method: `command/execute`** -This method allows the client to execute a slash command. Following the initial `ExecuteSlashCommandResponse`, the agent will use the standard streaming mechanism to communicate the command's progress and output. All subsequent updates, including textual output, agent thoughts, and any required user confirmations for tool calls (like executing a shell command), will be sent as `TaskStatusUpdateEvent` messages, re-using the schemas defined above. +This method allows the client to execute a slash command. Following the initial +`ExecuteSlashCommandResponse`, the agent will use the standard streaming +mechanism to communicate the command's progress and output. All subsequent +updates, including textual output, agent thoughts, and any required user +confirmations for tool calls (like executing a shell command), will be sent as +`TaskStatusUpdateEvent` messages, re-using the schemas defined above. ```proto // Request to execute a specific slash command. @@ -390,29 +454,56 @@ message ExecuteSlashCommandResponse { ## 4. Separation of Concerns -We believe that all client-side context (ex., workspace state) and client-side tool execution (ex. read active buffers) should be routed through MCP. +We believe that all client-side context (ex., workspace state) and client-side +tool execution (ex. read active buffers) should be routed through MCP. -This approach enforces a strict separation of concerns: the A2A `development-tool` extension standardizes communication to the agent, while MCP serves as the single, authoritative interface for client-side capabilities. +This approach enforces a strict separation of concerns: the A2A +`development-tool` extension standardizes communication to the agent, while MCP +serves as the single, authoritative interface for client-side capabilities. ## Appendix ### A. Example Interaction Flow -1. **Client -> Server**: The client sends a `message/stream` request containing the initial prompt and configuration in an `AgentSettings` object. +1. **Client -> Server**: The client sends a `message/stream` request containing + the initial prompt and configuration in an `AgentSettings` object. 2. **Server -> Client**: SSE stream begins. - - **Event 1**: The server sends a `Task` object with `status.state: 'submitted'` and the new `taskId`. - - **Event 2**: The server sends a `TaskStatusUpdateEvent` with the metadata `kind` set to `'STATE_CHANGE'` and `status.state` set to `'working'`. -3. **Agent Logic**: The agent processes the prompt and decides to call the `write_file` tool, which requires user confirmation. + - **Event 1**: The server sends a `Task` object with + `status.state: 'submitted'` and the new `taskId`. + - **Event 2**: The server sends a `TaskStatusUpdateEvent` with the metadata + `kind` set to `'STATE_CHANGE'` and `status.state` set to `'working'`. +3. **Agent Logic**: The agent processes the prompt and decides to call the + `write_file` tool, which requires user confirmation. 4. **Server -> Client**: - - **Event 3**: The server sends a `TaskStatusUpdateEvent`. The metadata `kind` is `'TOOL_CALL_UPDATE'`, and the `DataPart` contains a `ToolCall` object with its `status` as `'PENDING'` and a populated `confirmation_request`. - - **Event 4**: The server sends a final `TaskStatusUpdateEvent` for this exchange. The metadata `kind` is `'STATE_CHANGE'`, the `status.state` is `'input-required'`, and `final` is `true`. The stream for this request ends. -5. **Client**: The client UI renders the confirmation prompt based on the `ToolCall` object from Event 3. The user clicks "Approve." -6. **Client -> Server**: The client sends a new `message/stream` request. It includes the `taskId` from the ongoing task and a `DataPart` containing a `ToolCallConfirmation` object (e.g., `{"tool_call_id": "...", "selected_option_id": "proceed_once"}`). + - **Event 3**: The server sends a `TaskStatusUpdateEvent`. The metadata + `kind` is `'TOOL_CALL_UPDATE'`, and the `DataPart` contains a `ToolCall` + object with its `status` as `'PENDING'` and a populated + `confirmation_request`. + - **Event 4**: The server sends a final `TaskStatusUpdateEvent` for this + exchange. The metadata `kind` is `'STATE_CHANGE'`, the `status.state` is + `'input-required'`, and `final` is `true`. The stream for this request + ends. +5. **Client**: The client UI renders the confirmation prompt based on the + `ToolCall` object from Event 3. The user clicks "Approve." +6. **Client -> Server**: The client sends a new `message/stream` request. It + includes the `taskId` from the ongoing task and a `DataPart` containing a + `ToolCallConfirmation` object (e.g., + `{"tool_call_id": "...", "selected_option_id": "proceed_once"}`). 7. **Server -> Client**: A new SSE stream begins for the second request. - - **Event 1**: The server sends a `TaskStatusUpdateEvent` with `kind: 'TOOL_CALL_UPDATE'`, containing the `ToolCall` object with its `status` now set to `'EXECUTING'`. - - **Event 2**: After the tool runs, the server sends another `TaskStatusUpdateEvent` with `kind: 'TOOL_CALL_UPDATE'`, containing the `ToolCall` with its `status` as `'SUCCEEDED'`. -8. **Agent Logic**: The agent receives the successful tool result and generates a final textual response. + - **Event 1**: The server sends a `TaskStatusUpdateEvent` with + `kind: 'TOOL_CALL_UPDATE'`, containing the `ToolCall` object with its + `status` now set to `'EXECUTING'`. + - **Event 2**: After the tool runs, the server sends another + `TaskStatusUpdateEvent` with `kind: 'TOOL_CALL_UPDATE'`, containing the + `ToolCall` with its `status` as `'SUCCEEDED'`. +8. **Agent Logic**: The agent receives the successful tool result and generates + a final textual response. 9. **Server -> Client**: - - **Event 3**: The server sends a `TaskStatusUpdateEvent` with `kind: 'TEXT_CONTENT'` and a `TextPart` containing the agent's final answer. - - **Event 4**: The server sends the final `TaskStatusUpdateEvent`. The `kind` is `'STATE_CHANGE'`, the `status.state` is `'completed'`, and `final` is `true`. The stream ends. -10. **Client**: The client displays the final answer. The task is now complete but can be continued by sending another message with the same `taskId`. + - **Event 3**: The server sends a `TaskStatusUpdateEvent` with + `kind: 'TEXT_CONTENT'` and a `TextPart` containing the agent's final + answer. + - **Event 4**: The server sends the final `TaskStatusUpdateEvent`. The + `kind` is `'STATE_CHANGE'`, the `status.state` is `'completed'`, and + `final` is `true`. The stream ends. +10. **Client**: The client displays the final answer. The task is now complete + but can be continued by sending another message with the same `taskId`. diff --git a/packages/cli/src/commands/extensions/examples/context/GEMINI.md b/packages/cli/src/commands/extensions/examples/context/GEMINI.md index 22f6bbce5e..0e8179625e 100644 --- a/packages/cli/src/commands/extensions/examples/context/GEMINI.md +++ b/packages/cli/src/commands/extensions/examples/context/GEMINI.md @@ -1,8 +1,14 @@ # Ink Library Screen Reader Guidance -When building custom components, it's important to keep accessibility in mind. While Ink provides the building blocks, ensuring your components are accessible will make your CLIs usable by a wider audience. +When building custom components, it's important to keep accessibility in mind. +While Ink provides the building blocks, ensuring your components are accessible +will make your CLIs usable by a wider audience. ## General Principles -Provide screen reader-friendly output: Use the useIsScreenReaderEnabled hook to detect if a screen reader is active. You can then render a more descriptive output for screen reader users. -Leverage ARIA props: For components that have a specific role (e.g., a checkbox or a button), use the aria-role, aria-state, and aria-label props on and to provide semantic meaning to screen readers. +Provide screen reader-friendly output: Use the useIsScreenReaderEnabled hook to +detect if a screen reader is active. You can then render a more descriptive +output for screen reader users. Leverage ARIA props: For components that have a +specific role (e.g., a checkbox or a button), use the aria-role, aria-state, and +aria-label props on and to provide semantic meaning to screen +readers. diff --git a/packages/vscode-ide-companion/README.md b/packages/vscode-ide-companion/README.md index 6e6db38d21..4765600221 100644 --- a/packages/vscode-ide-companion/README.md +++ b/packages/vscode-ide-companion/README.md @@ -1,16 +1,25 @@ # Gemini CLI Companion -The Gemini CLI Companion extension pairs with [Gemini CLI](https://github.com/google-gemini/gemini-cli). This extension is compatible with both VS Code and VS Code forks. +The Gemini CLI Companion extension pairs with +[Gemini CLI](https://github.com/google-gemini/gemini-cli). This extension is +compatible with both VS Code and VS Code forks. # Features -- Open Editor File Context: Gemini CLI gains awareness of the files you have open in your editor, providing it with a richer understanding of your project's structure and content. +- Open Editor File Context: Gemini CLI gains awareness of the files you have + open in your editor, providing it with a richer understanding of your + project's structure and content. -- Selection Context: Gemini CLI can easily access your cursor's position and selected text within the editor, giving it valuable context directly from your current work. +- Selection Context: Gemini CLI can easily access your cursor's position and + selected text within the editor, giving it valuable context directly from your + current work. -- Native Diffing: Seamlessly view, modify, and accept code changes suggested by Gemini CLI directly within the editor. +- Native Diffing: Seamlessly view, modify, and accept code changes suggested by + Gemini CLI directly within the editor. -- Launch Gemini CLI: Quickly start a new Gemini CLI session from the Command Palette (Cmd+Shift+P or Ctrl+Shift+P) by running the "Gemini CLI: Run" command. +- Launch Gemini CLI: Quickly start a new Gemini CLI session from the Command + Palette (Cmd+Shift+P or Ctrl+Shift+P) by running the "Gemini CLI: Run" + command. # Requirements @@ -21,4 +30,5 @@ To use this extension, you'll need: # Terms of Service and Privacy Notice -By installing this extension, you agree to the [Terms of Service](https://github.com/google-gemini/gemini-cli/blob/main/docs/tos-privacy.md). +By installing this extension, you agree to the +[Terms of Service](https://github.com/google-gemini/gemini-cli/blob/main/docs/tos-privacy.md). diff --git a/packages/vscode-ide-companion/development.md b/packages/vscode-ide-companion/development.md index 4a3f33e32f..afe42ae13c 100644 --- a/packages/vscode-ide-companion/development.md +++ b/packages/vscode-ide-companion/development.md @@ -2,18 +2,22 @@ ## Running the Extension -To run the extension locally for development, we recommend using the automatic watch process for continuous compilation: +To run the extension locally for development, we recommend using the automatic +watch process for continuous compilation: 1. **Install Dependencies** (from the root of the repository): ```bash npm install ``` -2. **Open in VS Code:** Open this directory (`packages/vscode-ide-companion`) in your VS Code editor. -3. **Start Watch Mode:** Run the watch script to compile the extension and monitor changes in both **esbuild** and **TypeScript**: +2. **Open in VS Code:** Open this directory (`packages/vscode-ide-companion`) + in your VS Code editor. +3. **Start Watch Mode:** Run the watch script to compile the extension and + monitor changes in both **esbuild** and **TypeScript**: ```bash npm run watch ``` -4. **Launch Host:** Press **`F5`** (or **`fn+F5`** on Mac) to open a new **Extension Development Host** window with the extension running. +4. **Launch Host:** Press **`F5`** (or **`fn+F5`** on Mac) to open a new + **Extension Development Host** window with the extension running. ### Manual Build