google-gemini / google-gemini/gemini-cli
ACP marks edits to existing empty files as additions
- Dominant language
- TypeScript
- Stars
- 107k
- Forks
- 14.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 45
Description
### What happened?
In ACP mode, Gemini CLI labels an edit to an existing empty file as a file addition in the diff metadata.
Both the permission-preview path and the completed tool-result path choose the diff kind by checking whether `originalContent` is falsy. For an existing empty file, `originalContent` is `''`, so the emitted metadata incorrectly contains `_meta.kind: "add"` even though the tool result has `isNewFile: false`.
This can cause ACP clients to present an ordinary modification as a newly added file.
Minimal regression test:
```ts
const toolResult: ToolResult = {
llmContent: '',
returnDisplay: {
fileDiff: '',
fileName: 'empty.txt',
filePath: '/workspace/empty.txt',
originalContent: '',
newContent: 'content',
isNewFile: false,
},
};
expect(toToolCallContent(toolResult)).toMatchObject({
type: 'diff',
_meta: { kind: 'modify' },
});
```
Run with:
```console
./node_modules/.bin/vitest run src/acp/acpUtils.test.ts --root packages/cli
```
The test fails on the latest `main`:
```text
Expected: "modify"
Received: "add"
```
The same falsy-content check also appears in the permission-preview conversion:
- `packages/cli/src/acp/acpUtils.ts` (completed tool results)
- `packages/cli/src/acp/acpSession.ts` (permission previews)
`FileDiff` already includes an `isNewFile` field that distinguishes a new file from an existing empty file.
### What did you expect to happen?
ACP diff metadata should use `kind: "modify"` when `isNewFile` is false, including when the existing file is empty. Only actual new files should use `kind: "add"`.
### Client information
Client Information
Source audit against:
- Gemini CLI version: `0.60.0-nightly.20260901.g0bd1d4397`
- Commit: `85aca163f6c73ac6ce380b5447359146b8adcae4`
- Platform: macOS 26.5.2, arm64
- Node.js: v22.18.0
### Login information
Not applicable. The bug is reproduced in the local ACP result conversion without authentication or a model request.
### Anything else we need to know?
I searched open and closed issues and pull requests using the ACP component, empty-file symptom, diff kind, `isNewFile`, and `originalContent` terms and did not find a matching report or implementation.
I would be happy to prepare a small fix and regression coverage after maintainer approval.
Contributor guide
Research direction
Start with the completed-result conversion in packages/cli/src/acp/acpUtils.ts and the permission-preview conversion in packages/cli/src/acp/acpSession.ts, then run the focused test in packages/cli/src/acp/acpUtils.test.ts. Add regression coverage for an existing empty file and verify both ACP paths report kind "modify" for it while actual new files remain "add".
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 91/100