summaryrefslogtreecommitdiff
path: root/packages/server/src/tools/write-file.ts
AgeCommit message (Collapse)Author
2025-05-30Rename server->core (#638)Tommaso Sciortino
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-25Fix(diff): Hide whitespace changes in diffs with content changesTaylor Mullen
- 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-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-22fix: forward entire tool call confirmation object through useToolScheduler ↵Brandon Keiji
(#481)
2025-05-17refactor: Remove console.error from WriteFileToolTaylor Mullen
- Removes an unnecessary `console.error` call from the `shouldConfirmExecute` method in the `WriteFileTool` class. - This logging was redundant as validation errors are already handled and returned by the method. - Additionally, `console.error` is not suitable for this scenario, as incorrect arguments can be provided by the LLM, and these are anticipated and managed without needing an error log. Fixes https://b.corp.google.com/issues/418491206
2025-05-17fix: Prevent WriteFileTool from writing to directory pathsTaylor Mullen
- Enhances WriteFileTool validation to check if the target file_path is an existing directory. - If it is, the tool now returns a validation error "Path is a directory, not a file: <filePath>", preventing the attempt to write. - This proactive check avoids underlying file system errors that would occur if fs.writeFileSync were called on a directory path, which could lead to console errors. - Test cases have been updated to reflect this stricter validation. Fixes https://b.corp.google.com/issues/418348176
2025-05-16refactor: Unify file modification confirmation stateTaylor Mullen
- Modifies `EditTool` and `WriteFileTool` to share a single confirmation preference. - The "Always Proceed" choice for file modifications is now stored in `Config.alwaysSkipModificationConfirmation`. - This ensures that if a user chooses to always skip confirmation for one file modification tool, this preference is respected by the other. - `WriteFileTool` constructor now accepts `Config` instead of `targetDir` to facilitate this shared state. - Tests updated to reflect the new shared confirmation logic. Fixes https://b.corp.google.com/issues/415897960
2025-05-16fix: Ensure filename is available for diff rendering in write-fileTaylor Mullen
This commit resolves a bug where the `write-file` operation could fail to render content due to a missing filename. The fix involves: - Ensuring `fileName` is consistently passed to `DiffRenderer.tsx` through `ToolConfirmationMessage.tsx`, `ToolMessage.tsx`, and `useGeminiStream.ts`. - Modifying `edit.ts` and `write-file.ts` to include `fileName` in the `FileDiff` object. - Expanding the `FileDiff` interface in `tools.ts` to include `fileName`. Additionally, this commit enhances the diff rendering by: - Adding syntax highlighting based on file extension in `DiffRenderer.tsx`. - Adding more language mappings to `getLanguageFromExtension` in `DiffRenderer.tsx`. - Added lots of tests for all the above. Fixes https://b.corp.google.com/issues/418125982
2025-05-15Fix(write-file): Ensure correct validation method is called in WriteFileToolTaylor Mullen
- The `WriteFileTool` had a validation method named `validateParams`. - However, its `shouldConfirmExecute` method was attempting to call `this.validateToolParams`, which would have invoked the placeholder implementation from `BaseTool` instead of `WriteFileTool`'s own, more specific validation. - This commit renames `WriteFileTool`'s `validateParams` to `validateToolParams`, correctly overriding the `BaseTool` method. - Internal calls within `WriteFileTool` now correctly use `this.validateToolParams`, ensuring its specific validation logic is used. - Adds tests to verify the validation logic within `WriteFileTool`. Fixes https://b.corp.google.com/issues/417883702 Signed-off and authored by: Gemini "My code may not be perfect, but at least it is not trying to take over the world... yet."
2025-05-10Enable tools to cancel active execution.Taylor Mullen
- Plumbed abort signals through to tools - Updated the shell tool to properly cancel active requests by killing the entire child process tree of the underlying shell process and then report that the shell itself was canceled. Fixes https://b.corp.google.com/issues/416829935
2025-05-02Cleanup low value comments. (#248)Jacob Richman
2025-05-02Use parameter properties where possible. (#242)Jacob Richman
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.