summaryrefslogtreecommitdiff
path: root/packages/server/src/utils
AgeCommit message (Collapse)Author
2025-05-30Rename server->core (#638)Tommaso Sciortino
2025-05-30feat: Implement retry with backoff for API calls (#613)N. Taylor Mullen
2025-05-30Change ReadFile to not have a result display.Taylor Mullen
- It's verbose on its own; however, if file content is truncated we'll indicate that in the result display.
2025-05-29Refactor read-file and support images. (#480)Jacob Richman
2025-05-27feat: Allow cancellation of in-progress Gemini requests and pre-execution checksTaylor Mullen
- 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-26Fix(chat): Finalize next speaker detection logicTaylor Mullen
- 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-26Fix(chat): Prevent empty model response after function callTaylor Mullen
- 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-26Refactor(chat): Introduce custom Chat class for future modificationsTaylor Mullen
- 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-25Fix(test): Improve write-file and editCorrector test suitesTaylor Mullen
- 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-25Fix(write-file): Correct over-escaping and improve content generationTaylor Mullen
- 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-25Ensure edit correction isn't re-done after confirm.Taylor Mullen
- 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-25Trim edits if possible.Taylor Mullen
- 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-25Upon finding > 1 occurrences do not attempt auto-correction.Taylor Mullen
- 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-25refactor: Decouple new_string correction from old_stringTaylor Mullen
- 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-25refactor: Correct Gemini's over-escaped new_string in replace toolTaylor Mullen
- 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-25refactor: Improve editCorrector logic and type safetyTaylor Mullen
- 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-23infra: emit errors on no-explicit-any eslint rule (#516)Brandon Keiji
2025-05-23fix: Update dependencies to resolve deprecation warningsTaylor Mullen
2025-05-23Refactor(server): Centralize GEMINI.md discovery logic in server (#498)Allen Hutchison
2025-05-22Fix: Prevent hang in large directories by using BFS for getFolderStru… (#470)Allen Hutchison
Co-authored-by: N. Taylor Mullen <[email protected]>
2025-05-22fix: forward entire tool call confirmation object through useToolScheduler ↵Brandon Keiji
(#481)
2025-05-19ui tweaks (#442)Olcan
2025-05-12feat: Enhance `replace` tool reliability with multi-stage edit correctionTaylor Mullen
This commit significantly improves the `replace` tool's robustness by introducing a multi-stage correction mechanism. This directly addresses challenges with LLM-generated tool inputs, particularly the over-escaping of strings sometimes observed with Gemini models, and other minor discrepancies that previously led to failed edits. The correction process is as follows: 1. **Targeted Unescaping:** The system first applies a specialized unescaping function to the `old_string` and `new_string` to counteract common LLM-induced escaping patterns. 2. **LLM-Powered Discrepancy Resolution:** If a unique match for the `old_string` is still not found, the system leverages a Gemini model (`gemini-2.5-flash-preview-04-17`) to: * Identify the most probable intended `old_string` in the file by intelligently correcting minor formatting or escaping differences. * Adjust the `new_string` to correspond with any corrections made to the `old_string`, maintaining the original edit's intent. This enhancement makes the `replace` tool more resilient and effective, leading to a higher success rate for automated code modifications. The `expected_replacements` parameter has been removed as the tool now focuses on finding a single, unique, and correctable match. The tool's description and error reporting have been updated to reflect these new capabilities. Fixes https://b.corp.google.com/issues/416933027
2025-05-11Workaround model bug where it returns invalid history items.Taylor Mullen
- Currently there's a bug in the API (or SDK?) where the SDK endpoint will commonly fail with: ``` Error: Failed to generate JSON content: got status: 400 Bad Request. {"error":{"code":400,"message":"* GenerateContentRequest.contents[5].parts: contents.parts must not be empty.\n","status":"INVALID_ARGUMENT"}} ``` - At times the model will respond with an empty parts list where if we send that back up to the API endpoint it explodes with the above. Using a curated history seems like a total hack around this prolbem, and even in the SDK (i'm following up on this), BUT helps mitigate this issue.
2025-05-11Remove terminal tool and dependencies.Taylor Mullen
- We now solely use the shell tool. This deletes all content around the legacy terminal tool so we can focus on improving the new Shell tool. - Remove instances from sandboxing, tests, utilities etc.
2025-05-10Log server information on error.Taylor Mullen
- The goal of this is to enable us to better diagnose server issues when they occur. - Added tests because why not.
2025-05-10Don't prematurely end convo w/ Gemini.Taylor Mullen
- There seems to be a root model bug where the model will preemptively bail on conversations without trying harder. Typically the stops are VERY obvious and bug-looking where you need to prmopt the model to "continue". - This PR attempts to fix the above by running a 2.0-flash request (don't need somethign more powerful) at the end of every full interaction to see who should speak (user or model). - Add tests for nextSpeakerChecker Fixes https://b.corp.google.com/issues/416826051
2025-05-02Cleanup low value comments. (#248)Jacob Richman
2025-05-01Support escaping spaces in file paths. (#241)Jacob Richman
2025-04-26Prevent console.warn's for tool calls.Taylor Mullen
- Added helper for extracting text content from responses without warning. See fixed issue for more detail: https://b.corp.google.com/issues/414005146
2025-04-23remove dead code (#131)Olcan
2025-04-22Initiate the GeminiClient with a configJaana Dogan
Also address the open readability improvement comments from #104.
2025-04-21Simplify GeminiClient (#101)Jaana Dogan
Doing some more clean-up: * Remove confusing continue/break * Handle empty result * Rename the file just client.js
2025-04-21fix: remove circular dependency in background terminal analyzer (#94)Brandon Keiji
2025-04-21Remove duplicate CLI tools module, remove the global tool registry (#89)Jaana Dogan
2025-04-21Remove redundant else branches (#86)Jaana Dogan
Else branches are an anti pattern especially if you can easily return from the previous branch. Over time, else branches cause deep nesting and make code unreadable and unmaintainable. Remove elses where possible.
2025-04-21Fix Gemini Code's (GC) smarts.Taylor Mullen
- The tl;dr; is that GC couldn't see what the user was saying when tool call events happened in response. The rason why this was happening was because we were instantly invoking tools that the model told us to invoke and then instantly re-requesting. This resulted in the bug because the genai APIs can't update the chat history before a full response has been completed (doesn't know how to update if it's incomplete). - To address the above issue I had to do quite the large refactor. The gist is that now turns truly drive everything on the server (vs. a server client split). This ensured that when we got tool invocations we could control when/how re-requesting would happen and then also ensure that history was updated. This change also meant that the server would act as an event publisher to enable the client to react to events rather than try and weave in complex logic between the events. - A BIG change that this changeset incudes is the removal of all of the CLI tools in favor of the server tools. - Removed some dead code as part of this - **NOTE: Confirmations are still broken (they were broken prior to this); however, I've set them up to be able to work in the future, I'll dot hat in a follow up to be less breaking to others.** Fixes https://b.corp.google.com/issues/412320087
2025-04-19Starting to modularize into separate cli / server packages. (#55)Evan Senter
* Starting to move a lot of code into packages/server * More of the massive refactor, builds and runs, some issues though. * Fixing outstanding issue with double messages. * Fixing a minor UI issue. * Fixing the build post-merge. * Running formatting. * Addressing comments.