Commit Graph

650 Commits

Author SHA1 Message Date
Taylor Mullen d74c0f581b refactor: Extract MCP discovery from ToolRegistry
- Moves MCP tool discovery logic from ToolRegistry into a new, dedicated MCP client (mcp-client.ts and mcp-tool.ts).
- Updates ToolRegistry to utilize the new MCP client.
- Adds comprehensive tests for the new MCP client and its integration with ToolRegistry.

Part of https://github.com/google-gemini/gemini-cli/issues/577
2025-05-28 17:28:45 -07:00
Allen Hutchison c413988ae0
fix(ci): Only run post_coverage_comment job on pull_request events (#588) 2025-05-28 17:09:13 -07:00
Allen Hutchison 9ee5eadac0
fix(cli): Support multiple @file references in atCommandProcessor (#590) 2025-05-28 17:08:05 -07:00
Brandon Keiji fd6f6b02ea
feat: add git branch name to footer (#589) 2025-05-28 16:30:05 -07:00
Olcan 0d99398689
much improved support for background processes, avoiding termination (via SIGPIPE) or eventual blocking (e.g. due to filled OS buffers) (#586) 2025-05-28 14:45:46 -07:00
Jacob Richman 00805cb2cd
Cleanup: Remove low value StreamingContextType interface. (#585) 2025-05-28 12:46:08 -07:00
Jacob Richman 05a49702d8
Refactor: Add GeminiRespondingSpinner to make use of streamingState idiomatic (#583) 2025-05-28 11:17:19 -07:00
DeWitt Clinton 98dcf43214
Add a keybinding for ctrl+w to delete the previous word. (#582)
Adds the following new keybindings to the cli text input buffer:

- `Ctrl+W` : Delete previous word
2025-05-28 09:59:25 -07:00
DeWitt Clinton 27a773d5b2
Display git commit info in the /about section. (#567)
This change detects the most recent git commit short hash and writes it to the `GIT_COMMIT_INFO` constant in `packages/cli/src/generated/git-commit.sh`, optionally appending the string "(local modifications)" if additional local changes after that commit are detected.

If set, this string is displayed in the `/about` dialog as well as passed into the `/bug` template.

Example:

```
> /about

╭───────────────────────────────────────────────────────────────────────────╮
│                                                                           │
│ About Gemini CLI                                                          │
│                                                                           │
│ CLI Version               development                                     │
│ Git Commit                43370ab (local modifications)                   │
│ Model                     gemini-2.5-pro-preview-05-06                    │
│ Sandbox                   sandbox-exec (minimal)                          │
│ OS                        darwin v23.11.0                                 │
│                                                                           │
╰───────────────────────────────────────────────────────────────────────────╯
```

Additionally, this change updates `.gitignore` to ignore the generated files, `scripts/clean.sh` to remove them, and adds a `npm run generate` stage for this and any other generators we need to write.
2025-05-28 00:04:26 -07:00
Taylor Mullen f2f2ecf9d8 feat: Allow cancellation of in-progress Gemini requests and pre-execution checks
- Implements cancellation for Gemini requests while they are actively being processed by the model.
- Extends cancellation support to the  logic within tools. This allows users to cancel operations during the phase where the system is determining if a tool execution requires user confirmation, which can include potentially long-running pre-flight checks or LLM-based corrections.
- Underlying LLM calls for edit corrections (within  and ) and next speaker checks can now also be cancelled.
- Previously, cancellation of the main request was not possible until text started streaming, and pre-execution checks were not cancellable.
- This change leverages the updated SDK's ability to accept an abort token and threads s throughout the request, tool execution, and pre-execution check lifecycle.

Fixes https://github.com/google-gemini/gemini-cli/issues/531
2025-05-27 23:46:37 -07:00
Olcan bfeaac8441
live output from shell tool (#573) 2025-05-27 15:40:18 -07:00
Olcan 0d5f7686d7
fix tool cancellation while executing (#575) 2025-05-27 15:22:30 -07:00
Brandon Keiji c1395a8808
fix: change entrypoint from 'gemini-code' to 'gemini' in published sandbox (#574) 2025-05-27 22:19:43 +00:00
Brandon Keiji d4ae1ede39
refactor: use React strict mode (#569) 2025-05-27 14:40:46 -07:00
Olcan 16c16127e7
fix sandboxing anchor (#572) 2025-05-27 14:01:23 -07:00
Olcan 0c5673875b
improve shell tool output when cancelled in debug mode (#571) 2025-05-27 13:47:40 -07:00
Allen Hutchison 4e3c539f5e
feat: Publish test coverage summaries to PRs (#513) 2025-05-27 12:45:28 -07:00
Olcan 9595e98db8
replace error with warning if sandbox build is triggered without enabling, improve README to reduce confusion (#570) 2025-05-27 10:55:07 -07:00
sasha-gitg 3511e84dc3
fix: default to Gemini API if GEMINI_API_KEY is set and when GOOGLE_GENAI_USE_VERTEXAI is set to True (#566) 2025-05-27 10:00:07 -07:00
Taylor Mullen b3f52e215a feat: Replace SQLite with JSON logging for macOS sandbox compatibility
- Removes the sqlite3 dependency and refactors the logging mechanism to use a JSON file (logs.json) instead of a database.
- This change is a temporary workaround to address issues with macOS sandboxing that were caused by the SQLite native module.
- Storing all logs in a single JSON file may introduce scalability concerns in the future.

Fixes https://github.com/google-gemini/gemini-cli/issues/522
2025-05-26 16:13:37 -07:00
Taylor Mullen 9e1cfca53f Fix(chat): Finalize next speaker detection logic
- Enhance `checkNextSpeaker` to handle cases where the last message is a function response or an empty model message.
- If the last message is a function response, the model should speak next.
- If the last message is an empty model message, the model should speak next.
- This ensures more robust and accurate determination of the next speaker in the conversation, completing the fix for the issue.
- Updated tests.

Fixes https://github.com/google-gemini/gemini-cli/issues/551
2025-05-26 15:21:45 -07:00
Taylor Mullen c92d4edb89 Fix(chat): Ensure model responds when next speaker check indicates
- Corrects an issue where the `nextSpeakerCheck` would determine the model should speak next, but the models response was not properly propagated due to a missing `yield*` in a recursive call within `sendMessageStream`.
- This change ensures that when the model is designated as the next speaker, its generated content is correctly unwoven and returned, allowing the conversation to proceed as expected.

Part of https://github.com/google-gemini/gemini-cli/issues/551
2025-05-26 14:37:13 -07:00
Taylor Mullen 597dc86a9c Fix(chat): Prevent empty model response after function call
- Addresses a Gemini model bug where it may return an empty content object after a function response.
- Previously, the SDK attempted to inject an empty model message, which could disrupt curated history.
- This change modifies our custom  class to detect this scenario using an  utility and avoid pushing an unnecessary empty model message, thus preserving history integrity.

Workaround for https://b.corp.google.com/issues/420354090
Part of https://github.com/google-gemini/gemini-cli/issues/551
2025-05-26 14:29:24 -07:00
Taylor Mullen 480549e02e Refactor(chat): Introduce custom Chat class for future modifications
- Copied the `Chat` class from `@google/genai` into `packages/server/src/core/geminiChat.ts`.
- This change is in preparation for future modifications to the chat handling logic.
- Updated relevant files to use the new `GeminiChat` class.

Part of https://github.com/google-gemini/gemini-cli/issues/551
2025-05-26 14:20:28 -07:00
Taylor Mullen 02503a3248 Chore(deps): Upgrade @google/genai to v1.0.1
- Upgraded the @google/genai SDK from ^0.13.0 to ^1.0.1.
- Addressed a related type error in `packages/server/src/tools/edit.test.ts` by updating a type assertion.

Part of https://github.com/google-gemini/gemini-cli/issues/551
2025-05-26 14:09:43 -07:00
Taylor Mullen 70d469ccd3 Fix(diff): Hide whitespace changes in diffs with content changes
- Updated the diff generation in `edit.ts` and `write-file.ts` to include the `ignoreWhitespace: true` option.
- This ensures that whitespace-only changes are not highlighted in the diff output when there are other content modifications, making the diffs cleaner and easier to review.
- Extract default diffing options into single source of truth.

Fixes https://github.com/google-gemini/gemini-cli/issues/548
2025-05-25 22:45:53 -07:00
Taylor Mullen 8440b971f5 Fix(cli): Prevent premature input box reactivation during tool confirmation
- Introduced a 'validating' state for tool calls to prevent the input box from reappearing while waiting for a tool's `shouldConfirmExecute` method to complete.
- When a tool call is initiated, it's now immediately set to a 'validating' status. This ensures the UI remains in a busy/responding state.
- `useGeminiStream` now considers the 'validating' state as part of `StreamingState.Responding`.
- `useToolScheduler` has been updated to:
    - Set the initial status of new tool calls to 'validating'.
    - Asynchronously perform the `shouldConfirmExecute` check.
    - Transition to 'awaiting_approval' or 'scheduled' based on the check's outcome.
- This resolves an issue where a slow `shouldConfirmExecute` could lead to the input prompt becoming active again before the tool call lifecycle was fully determined. While 'validating' is currently treated similarly to 'executing' in the UI, this new state provides a foundation for more customized user experiences during this phase in the future.

Fixes https://github.com/google-gemini/gemini-cli/issues/527
2025-05-25 16:06:33 -07:00
Taylor Mullen 7408c78dbb Change tool call spinner to be different.
- This differentiates the tool calling spinner from one that matches the normal loading indiator to somethign a little more seamless.
2025-05-25 16:05:22 -07:00
Taylor Mullen 3281cbc835 Fix(test): Improve write-file and editCorrector test suites
- Enhanced  by:
  - Mocking  and  utilities (, ) to allow for more focused unit testing of .
  - Adding comprehensive tests for the private  method, covering new and existing file scenarios, as well as error handling.
  - Expanding tests for  and  to verify behavior with the new content correction logic, including diff generation and directory creation.
- Refined  by:
  - Introducing robust mocking for  and its methods (, , ) to simulate LLM interactions accurately.
  - Adding extensive test scenarios for , categorized by how  matches and how  is processed, including direct matches, unescaping, and LLM-based corrections.
  - Including tests for edge cases like no matches or multiple matches.
  - Adding a  utility for better test isolation.

Final fix for https://github.com/google-gemini/gemini-cli/issues/484
2025-05-25 15:02:08 -07:00
Taylor Mullen 5097b5a656 Fix(write-file): Correct over-escaping and improve content generation
- Leveraged existing edit correction technology from `edit.ts` to address over-escaping issues in `write-file.ts`.
- Introduced `ensureCorrectFileContent` for correcting content in new files, where a simple "replace" isnt applicable. This uses a new LLM prompt tailored for correcting potentially problematic string escaping.
- Added caching for `ensureCorrectFileContent` to optimize performance.
- Refactored `write-file.ts` to integrate these corrections, improving the reliability of file content generation and modification.

Part of https://github.com/google-gemini/gemini-cli/issues/484
2025-05-25 14:45:47 -07:00
Taylor Mullen 1a5fe16b22 Ensure edit correction isn't re-done after confirm.
- Edit corretion leans on LLM-isms to ensure we properly fix poorly escaped content. Beacues of this we need to ensure that we don't re-run edit correction in many cases.
  - To ensure this an `LruCache` has been added to capture intermediate steps of edit correction to avoid re-computations.
  - Max cache size is 50 currently. This means a user can have a muti-confirmation flow of 25 items without recomputing anything (assuming they all break edit correction).
- Laid some groundwork for future testing.

Part of https://github.com/google-gemini/gemini-cli/issues/484
2025-05-25 14:24:09 -07:00
Taylor Mullen c181fc1cf3 Correct edits even when auto-accept is enabled.
- Prior to this when a user would turn on auto-accept for edits we'd stop ensuring correct edits. This would result in a lot of back and forth by the model. This change also incoporates ensure correct edit into the normal execution flow.
- Added edit tests for this.

Part of https://github.com/google-gemini/gemini-cli/issues/484
2025-05-25 14:18:54 -07:00
Taylor Mullen 48781272ee Trim edits if possible.
- Since we're now LLM correcting a lot of problematic edits we need to also potentially trim bad edits (llms have a bad habbit of adding whitespace places).

Part of https://github.com/google-gemini/gemini-cli/issues/484
2025-05-25 14:01:52 -07:00
Taylor Mullen 2e3eeaf920 Upon finding > 1 occurrences do not attempt auto-correction.
- When correcting edits prior to this if we found more than one occurrence we would try to auto-correct the old/new strings. There's no need in this situation because the tool has already provided too vague of an old_string to act upon. Instantly return.

Part of https://github.com/google-gemini/gemini-cli/issues/484
2025-05-25 13:47:19 -07:00
Taylor Mullen ceb25c8350 refactor: Decouple new_string correction from old_string
- Previously, `new_string` was assumed to be over-escaped if `old_string` was.
- This change introduces an explicit check (`newStringPotentiallyEscaped`) to determine if `new_string` itself needs correction.
- If `new_string` is potentially escaped, its corrected using an LLM call; otherwise, the original `new_string` is used.
- This avoids unnecessary corrections to `new_string` when only `old_string` was problematic.

Part of https://github.com/google-gemini/gemini-cli/issues/484
2025-05-25 13:40:58 -07:00
Taylor Mullen 24da7b3ca6 refactor: Correct Gemini's over-escaped new_string in replace tool
- Implement a heuristic to detect and unescape `new_string` if it appears Gemini has over-escaped it, while `old_string` is correctly formatted.
- This improves the reliability of the replace tool when the model generates an incorrectly escaped replacement string.

Part of https://github.com/google-gemini/gemini-cli/issues/484
2025-05-25 13:30:08 -07:00
Taylor Mullen fa4a04157f refactor: Improve editCorrector logic and type safety
- Refactor `ensureCorrectEdit` to clarify the correction flow for `old_string` and `new_string`.
- Only correct `new_string` if it was potentially escaped; otherwise, use the original.
- Introduce `CorrectedEditParams` and `CorrectedEditResult` interfaces for better type definition.
- Relocate `countOccurrences` for better logical grouping.

Part of https://github.com/google-gemini/gemini-cli/issues/484
2025-05-25 13:18:07 -07:00
DeWitt Clinton 068b505d5e
Reduce excessive diff separators in CLI. (#535)
Increases the threshold for rendering diff separators in the CLI's diff display. Previously, a separator was shown for gaps of more than one context line, leading to excessive separators in diffs with many small changes close together (Issue #534).

By increasing `MAX_CONTEXT_LINES_WITHOUT_GAP` to 5, we allow for more context lines before a separator is added, significantly reducing visual clutter in such diffs.

Added a test case to `DiffRenderer.test.tsx` to verify that separators are not rendered for small gaps within the new threshold.
2025-05-25 10:26:51 -07:00
Taylor Mullen e297b56390 feat: Add GEMINI.md tip to UI
- Display a tip to create a GEMINI.md file if one doesn't exist.
- Pass config to Tips component so it can inspect the initial GEMINI.md
count.
2025-05-24 12:40:06 -07:00
Jacob Richman b4c16d1f56
Code review comment fixes and some refactors. (#525)
No intentional different behavior aside for tweaks suggested from the code review of #506 Refactor: Extract console message logic to custom hook

This commit refactors the console message handling from App.tsx into a new custom hook useConsoleMessages.

This change improves the testability of the console message logic and declutters the main App component.

Created useConsoleMessages.ts to encapsulate console message state and update logic.
Updated App.tsx to utilize the new useConsoleMessages hook.
Added unit tests for useConsoleMessages.ts to ensure its functionality.
I deleted and started over on LoadingIndicator.test.tsx as I spent way too much time trying to fix it before just regenerating the tests as the code was easier to write tests for from scratch and the existing tests were not that good (I added them in the previous pull request).
2025-05-24 00:44:17 -07:00
Jacob Richman 1c3d9d7623
Make console message support more robust to logging in the middle of rendering. (#521) 2025-05-23 22:51:47 -07:00
DeWitt Clinton 7a3a9066f9
Add additional readline-like keybindings. (#524)
Adds the following conventional readline-like keybindings:

  - `Ctrl+H`: Delete the previous character.
  - `Ctrl+D`: Delete the next character.

Additionally, remaps the Debug Console command from Ctrl+D to Ctrl+O, which had been first introduced in PR #486.
2025-05-23 22:13:57 -07:00
Miguel Solorio 30080b9f4e 🧹 Format 2025-05-23 16:14:37 -07:00
Miguel Solorio 2a2d041dcd Update packages/cli/src/ui/types.ts
Co-authored-by: N. Taylor Mullen <ntaylormullen@google.com>
2025-05-23 16:14:37 -07:00
Miguel Solorio 6247cb8ddd Update packages/cli/src/ui/hooks/slashCommandProcessor.ts
Co-authored-by: N. Taylor Mullen <ntaylormullen@google.com>
2025-05-23 16:14:37 -07:00
Miguel Solorio 1af19c57de Remove CLI info from footer 2025-05-23 16:14:37 -07:00
Miguel Solorio 221370acc5 Add `/about` command 2025-05-23 16:14:37 -07:00
Taylor Mullen 4a6833ef49 feat: Enable npx execution on tagged versions
- Modify root package.json to allow publishing
- Update "files" to include only essential bundled assets

This change makes it possible to use npx with tagged versions of the
gemini-cli package (e.g., npx https://github.com/google-gemini/gemini-cli@early-access).
It removes "private: true" and refines the "files" array to ensure
that only the necessary bundled assets are included when the package is
fetched by npx, optimizing download size and ensuring correct execution.
2025-05-23 15:55:29 -07:00
Brandon Keiji 197c5b2bdf
infra: emit errors on no-explicit-any eslint rule (#516) 2025-05-23 22:35:50 +00:00
Taylor Mullen 1ff083af27 fix: Update dependencies to resolve deprecation warnings 2025-05-23 14:50:00 -07:00