Files
cline/cli
Robin Newhouse dd35448a9d fix: DiffViewProvider line boundary validation and trailing newline preservation (#8651)
* fix: DiffViewProvider line boundary validation and content concatenation

Two bugs in DiffViewProvider caused file editing failures:

1. **Line boundary validation errors (#8423, #8429)**
   JetBrains hosts using gRPC strictly validate line numbers. When
   truncateDocument() was called with a line number >= document line count,
   it caused "truncateDocument INTERNAL: Wrong line" errors. This occurred
   when new content had >= lines than the original, making truncation
   unnecessary but still attempted.

2. **Content concatenation on final update**
   When replacing content without a trailing newline, the old content at
   line N+1 was concatenated to the new content. For example, writing
   "Hello World" to a file containing "line1\nline2\n" resulted in
   "Hello Worldline2" instead of just "Hello World".

1. Added `getDocumentLineCount()` abstract method to all DiffViewProvider
   implementations to query the current document line count.

2. Added `safelyTruncateDocument()` private helper that validates line
   numbers before calling truncateDocument():
   ```typescript
   private async safelyTruncateDocument(lineNumber: number): Promise<void> {
     const lineCount = await this.getDocumentLineCount()
     if (lineNumber < lineCount) {
       await this.truncateDocument(lineNumber)
     }
   }
   ```

3. Extended the replacement range on final update to cover the entire
   document, preventing content concatenation:
   ```typescript
   const endLine = isFinal
     ? await this.getDocumentLineCount()
     : currentLine + 1
   ```

- src/integrations/editor/DiffViewProvider.ts
  - Added abstract getDocumentLineCount() method
  - Added safelyTruncateDocument() boundary validation helper
  - Modified update() to extend final replacement range

- src/hosts/vscode/VscodeDiffViewProvider.ts
  - Implemented getDocumentLineCount() using editor.document.lineCount

- src/hosts/external/ExternalDiffviewProvider.ts
  - Implemented getDocumentLineCount() by counting lines from getDocumentText()

- src/integrations/editor/FileEditProvider.ts
  - Implemented getDocumentLineCount() from documentContent

- src/integrations/editor/__tests__/DiffViewProvider.test.ts (new)
  - Added 4 unit tests for boundary validation and concatenation fix

Fixes #8423, #8429

* fix: preserve trailing newlines in file edits

Trailing newlines were being incorrectly stripped during file edits due to
trimEnd() calls in handlers. This caused files to lose their final newline
even when the original file had one.

Changes:
- Remove trimEnd() from WriteToFileToolHandler and ApplyPatchHandler that
  was stripping trailing newlines before content reached the editor
- Remove dead code in DiffViewProvider.update() that tried to restore
  newlines after the document was already written
- Add trailing newline fix-up in VscodeDiffViewProvider to handle VS Code's
  applyEdit sometimes normalizing newlines on full-document replacements
- Fix FileEditProvider.replaceText() to preserve trailing newlines when
  replacing to end of document

* fix: preserve trailing newlines in diff text ops

Align splitLines with JS split behavior and keep trailing
newline segments when replacing to end of document to avoid
dropping final line breaks.
2026-01-16 17:02:27 -08:00
..
2025-10-14 20:54:50 -07:00
2025-12-19 14:14:21 -08:00
2025-10-15 03:02:25 -07:00

Cline CLI

/_____/\ /_/\      /_______/\/__/\ /__/\ /_____/\
\:::__\/ \:\ \     \__.::._\/\::\_\\  \ \\::::_\/_
 \:\ \  __\:\ \       \::\ \  \:. `-\  \ \\:\/___/\
  \:\ \/_/\\:\ \____  _\::\ \__\:. _    \ \\::___\/_
   \:\_\ \ \\:\/___/\/__\::\__/\\. \`-\  \ \\:\____/\
    \_____\/ \_____\/\________\/ \__\/ \__\/ \_____\/

Autonomous coding agent CLI - capable of creating/editing files, running commands, using the browser, and more.

Installation

Install Cline globally using npm:

npm install -g cline

Usage

cline

This will start the Cline CLI interface where you can interact with the autonomous coding agent.

Features

  • Autonomous Coding: AI-powered code generation, editing, and refactoring
  • File Operations: Create, read, update, and delete files and directories
  • Command Execution: Run shell commands and scripts
  • Browser Automation: Interact with web pages and applications
  • Multi-Model Support: Works with Anthropic Claude, OpenAI GPT, and other AI models
  • MCP Integration: Extensible through Model Context Protocol servers
  • Project Understanding: Analyzes codebases to provide context-aware assistance

Requirements

  • Node.js 18.0.0 or higher
  • Supported platforms: macOS, Linux. Windows soon
  • Supported architectures: x64, arm64

Configuration

Cline can be configured through:

  • Environment variables
  • Configuration files
  • Command-line arguments

See the main documentation for detailed configuration options.

License

Apache-2.0 - see LICENSE for details.

Support