What happened?
The Gemini CLI's write_file tool consistently fails with a JavaScript error "Cannot read properties of undefined (reading 'indexOf')" when used in conjunction with the agentic.nvim Neovim plugin. This error occurs specifically within the gemini-cli Node.js process when processing incoming notifications from the vscode-ide-companion (which acts as the gemini-acp bridge). The failure is particularly noticeable when attempting to write to new files via the diff interaction.
[2026-02-01 13:29:30] [agentic.acp.acp_client:235] Gemini ACP response: {
jsonrpc = "2.0",
method = "session/update",
params = {
sessionId = "eb30a893-13bb-4870-b63a-835a2465ae45",
update = {
content = { {
content = {
text = "Cannot read properties of undefined (reading 'indexOf')",
type = "text"
},
type = "content"
} },
sessionUpdate = "tool_call_update",
status = "failed",
toolCallId = "write_file-1769981340295"
}
}
}
Root Cause
The vscode-ide-companion (acting as the gemini-acp bridge) is inadvertently sending malformed data to gemini-cli. Specifically, in its diff-manager.ts file, when the acceptDiff or cancelDiff methods are invoked after a user interaction with a diff view, it constructs IdeDiffAcceptedNotificationSchema or IdeDiffRejectedNotificationSchema notifications. The content field within these notifications is populated directly from rightDoc.getText(). If vscode.TextDocument.getText() returns undefined (which can happen in certain edge cases for newly created, unsaved, or ambiguous document states within VS Code), this undefined value is passed as the content. The gemini-cli's Model Context Protocol (MCP) SDK client, upon receiving this notification, attempts to perform a string operation (like .indexOf) on this undefined content field, leading to the "Cannot read properties of undefined (reading 'indexOf')" runtime error.
Proposed Solution
Modify packages/vscode-ide-companion/src/diff-manager.ts to ensure that the content field in the IdeDiffAcceptedNotificationSchema and IdeDiffRejectedNotificationSchema notifications is always a string. This can be achieved by providing a default empty string value if rightDoc.getText() returns undefined or another falsy value.
Specific Change (Example):
In packages/vscode-ide-companion/src/diff-manager.ts, within the acceptDiff and cancelDiff methods, change:
const modifiedContent = rightDoc.getText();
to:
`
What did you expect to happen?
write_file tool works correctly
Client information
Client Information
Run gemini to enter the interactive CLI, then run the /about command.
> /about
│ CLI Version 0.26.0 │
│ Git Commit a380b4219 │
│ Model auto-gemini-2.5 │
│ Sandbox no sandbox │
│ OS darwin │
Login information
google account oauth
Anything else we need to know?
No response
What happened?
The Gemini CLI's
write_filetool consistently fails with a JavaScript error "Cannot read properties of undefined (reading 'indexOf')" when used in conjunction with theagentic.nvimNeovim plugin. This error occurs specifically within thegemini-cliNode.js process when processing incoming notifications from thevscode-ide-companion(which acts as thegemini-acpbridge). The failure is particularly noticeable when attempting to write to new files via the diff interaction.Root Cause
The
vscode-ide-companion(acting as thegemini-acpbridge) is inadvertently sending malformed data togemini-cli. Specifically, in itsdiff-manager.tsfile, when theacceptDifforcancelDiffmethods are invoked after a user interaction with a diff view, it constructsIdeDiffAcceptedNotificationSchemaorIdeDiffRejectedNotificationSchemanotifications. Thecontentfield within these notifications is populated directly fromrightDoc.getText(). Ifvscode.TextDocument.getText()returnsundefined(which can happen in certain edge cases for newly created, unsaved, or ambiguous document states within VS Code), thisundefinedvalue is passed as thecontent. Thegemini-cli's Model Context Protocol (MCP) SDK client, upon receiving this notification, attempts to perform a string operation (like.indexOf) on thisundefinedcontentfield, leading to the "Cannot read properties of undefined (reading 'indexOf')" runtime error.Proposed Solution
Modify
packages/vscode-ide-companion/src/diff-manager.tsto ensure that thecontentfield in theIdeDiffAcceptedNotificationSchemaandIdeDiffRejectedNotificationSchemanotifications is always a string. This can be achieved by providing a default empty string value ifrightDoc.getText()returnsundefinedor another falsy value.Specific Change (Example):
In
packages/vscode-ide-companion/src/diff-manager.ts, within theacceptDiffandcancelDiffmethods, change:const modifiedContent = rightDoc.getText();to:
`
What did you expect to happen?
write_file tool works correctly
Client information
Client Information
Run
geminito enter the interactive CLI, then run the/aboutcommand.Login information
google account oauth
Anything else we need to know?
No response