Commit graph

142 commits

Author SHA1 Message Date
Hannes Rudolph
a08bd766ff
refactor: remove legacy XML tool calling code (getToolDescription) (#10929)
- Remove getToolDescription() method from MultiSearchReplaceDiffStrategy
- Remove getToolDescription() from DiffStrategy interface
- Remove unused ToolDescription type from shared/tools.ts
- Remove unused eslint-disable directive
- Update test mocks to remove getToolDescription references
- Remove getToolDescription tests from multi-search-replace.spec.ts

Native tools are now defined in src/core/prompts/tools/native-tools/ using
the OpenAI function format. The removed code was dead since XML-style tool
calling was replaced with native tool calling.
2026-01-23 19:13:55 -05:00
Hannes Rudolph
526488e5b6
chore: remove MULTI_FILE_APPLY_DIFF experiment (#10925)
* chore: remove MULTI_FILE_APPLY_DIFF experiment

Remove the 'Enable concurrent file edits' experimental feature that
allowed editing multiple files in a single apply_diff call.

- Remove multiFileApplyDiff from experiment types and config
- Delete MultiFileSearchReplaceDiffStrategy class and tests
- Delete MultiApplyDiffTool wrapper and tests
- Remove experiment-specific code paths in Task.ts, generateSystemPrompt.ts, and presentAssistantMessage.ts
- Remove special handling in ExperimentalSettings.tsx
- Remove translations from all 18 locale files

The existing MultiSearchReplaceDiffStrategy continues to handle
multiple SEARCH/REPLACE blocks within a single file.

* fix: remove unused EXPERIMENT_IDS/experiments import from Task.ts

Addresses review feedback: removes the unused imports from
src/core/task/Task.ts that were left over after removing the
MULTI_FILE_APPLY_DIFF experiment routing code.
2026-01-23 18:39:24 -05:00
Hannes Rudolph
8de9337e63
chore: remove XML tool calling support (#10841)
Co-authored-by: daniel-lxs <ricciodaniel98@gmail.com>
Co-authored-by: Matt Rubens <mrubens@users.noreply.github.com>
2026-01-20 20:25:08 -05:00
Daniel
ce229012a3
refactor: remove insert_content tool (#9751)
Co-authored-by: Roo Code <roomote@roocode.com>
2025-12-03 16:33:22 -05:00
Daniel
999ea686ab
fix: resolve apply_diff performance regression from PR #9456 (#9474) 2025-11-21 17:31:47 -05:00
Daniel
a49e81f37c
fix: improve search and replace symbol parsing (#9456) 2025-11-20 23:05:14 -05:00
Hannes Rudolph
0fd7023ea7
feat(chat): Improve diff appearance in main chat view (#8932)
Co-authored-by: daniel-lxs <ricciodaniel98@gmail.com>
2025-11-06 16:18:01 -05:00
roomote[bot]
ad56791c3e
fix: preserve trailing newlines in stripLineNumbers for apply_diff (#8227)
Co-authored-by: Roo Code <roomote@roocode.com>
Co-authored-by: Matt Rubens <mrubens@users.noreply.github.com>
2025-10-24 10:16:00 -04:00
Hannes Rudolph
7ea1ae570a
fix: use CDATA sections in XML examples to prevent parser errors (#4852) (#6811) 2025-08-07 12:42:29 -04:00
Matt Rubens
ebfd384ac4
More tolerant search/replace match (#6537)
Co-authored-by: Roo Code <roomote@roocode.com>
2025-08-01 11:58:57 -04:00
Hannes Rudolph
5724cb2bbb
docs: clarify apply_diff tool descriptions to emphasize surgical edits (#6278)
Co-authored-by: Daniel Riccio <ricciodaniel98@gmail.com>
Co-authored-by: Roo Code <roomote@roocode.com>
2025-07-30 10:52:20 -04:00
roomote
cd60bb3a7e
Fixes #5206: Update apply_diff tool documentation to accurately reflect multi-file capabilities (#5232)
* Fixes #5206

* Fix failing test: Update snapshot after documentation changes

- Updated system-prompt.spec.ts snapshot to match new tool descriptions
- Changes reflect updated multi-file diff strategy documentation
- Addresses test failure mentioned in PR #5232 comment by @mrubens
2025-06-30 09:01:44 -04:00
Sam Hoang Van
5bc3af1bc3
fix: start line not working in multiple apply diff (#5019) 2025-06-22 23:33:52 -04:00
Matt Rubens
48c9bd5fae
Encourage use of start_line in multi-file diff to match legacy diff (#4777) 2025-06-17 10:40:37 -04:00
Chris Estreich
62c3914034
Farewell jest (#4607)
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
2025-06-16 21:39:45 -07:00
Daniel
feb2fa8443
Fix multi-file diff error handling and UI feedback (#4674)
fix: improve multi-file diff error handling and UI feedback

- Fix nested array issue in multi-file-search-replace strategy
- Consolidate diff error reporting to single message
- Fix infinite spinner on single file diff failures
2025-06-13 20:09:04 -04:00
Sam Hoang Van
7bed94454a
feat: Enhance apply_diff with XML for multi-file/multi-diff operations & batch UI (#3342)
* feat: add BatchDiffApproval component for multi-file diff application

- Introduced a new component `BatchDiffApproval` to handle the approval of batch changes across multiple files.
- Integrated the `BatchDiffApproval` component into `ChatRow` to display batch diff requests.
- Updated experimental settings to include a toggle for multi-file apply diff functionality.
- Enhanced localization files to support new strings related to batch changes in multiple languages.
- Updated tests to cover the new multi-file apply diff feature.

* revert this

* fix: update applyDiff parameter type to accept string or DiffItem

* refactor: keep original file name for apply diff tool

* revert this

* Update src/core/webview/__tests__/ClineProvider.test.ts

* revert this

* fix: keep the original path if the experiment is disabled

* test: add dynamic strategy selection tests for MultiSearchReplaceDiffStrategy and MultiFileSearchReplaceDiffStrategy

* fix: mock applyDiffTool module and ensure legacy tool resolves successfully in tests

* remove this

* ellipsis suggestion

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>

* refactor: mirror concurrent file reads

---------

Co-authored-by: Daniel Riccio <ricciodaniel98@gmail.com>
Co-authored-by: Daniel <57051444+daniel-lxs@users.noreply.github.com>
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
2025-06-12 12:36:34 -04:00
KJ7LNW
b39080c8c8
test: add command line test for multi-search-replace (#2220)
Adds a new test case that allows testing the multi-search-replace diff strategy directly from the command line by passing source and diff files as arguments.

This enables easier debugging and manual testing of the diff application functionality without needing to modify test code for each test case.

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
Co-authored-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-06-01 22:14:53 -04:00
KJ7LNW
53f94a7852
fix: prevent start_line/end_line in apply_diff REPLACE (#4015)
Adds validation to ensure that `:start_line:` and `:end_line:`
markers do not appear in the REPLACE section of an apply_diff
operation. These markers are only valid within the SEARCH section.

This change prevents potential errors and confusion when users
might inadvertently include these markers in the replacement content.
New tests have been added to verify this validation.

Fixes: #4013

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
Co-authored-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-05-31 16:06:41 -04:00
Chris Estreich
e66136f1aa
Add a new @roo-code/types package and use it everywhere (#3912) 2025-05-26 12:06:45 -07:00
Hannes Rudolph
a8922e0c96
Improve tool descriptions to guide proper file editing tool selection (#3943)
* Improve tool descriptions to guide proper file editing tool selection

### Problem
LLMs were frequently choosing `write_to_file` for file edits instead of more appropriate tools like `apply_diff`, `insert_content`, or `search_and_replace`. This was likely because the tool descriptions made it seem like files needed to be reconstructed rather than edited.

### Changes Made

**write_to_file tool description:**
- Clarified primary use cases: **creating new files** or **complete rewrites when intentionally required**
- Changed opening from "write full content" to "write content" to reduce emphasis on full reconstruction
- Updated parameter description to be more specific about when complete content is needed

**apply_diff tool description:**
- Enhanced description to emphasize "targeted modifications" and "precise, surgical edits"
- Clarified that multiple search/replace operations can be performed in a single call
- Removed misleading "only a single operation allowed" restriction
- Better positioned as the preferred tool for making several targeted changes efficiently

### Impact
These changes should guide LLMs toward:
- Using `write_to_file` primarily for new files or intentional complete rewrites
- Using `apply_diff` for targeted edits and modifications to existing files
- Better understanding of when each tool is most appropriate

The updated descriptions maintain necessary technical details while providing clearer guidance on tool selection without being overly prescriptive.

* Update src/core/prompts/tools/write-to-file.ts

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>

* Update src/core/prompts/tools/write-to-file.ts

Co-authored-by: Matt Rubens <mrubens@users.noreply.github.com>

* Update src/core/prompts/tools/write-to-file.ts

Co-authored-by: Matt Rubens <mrubens@users.noreply.github.com>

---------

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
Co-authored-by: Matt Rubens <mrubens@users.noreply.github.com>
2025-05-24 18:35:27 -04:00
Chris Estreich
39cd50b989
Fix linter errors (#3821) 2025-05-21 23:16:43 -07:00
Sam Hoang Van
6db30afc74
make apply_diff can deduce when line number in search part fix #2990 (#3329) 2025-05-12 23:11:01 -04:00
Chris Estreich
1924e10e72
Fix all linter errors (and fix the lint scripts too) (#2958) 2025-04-26 09:45:26 -07:00
axb
3b65023d0b
feat(diff): improve progress indicator for apply_diff tool (#2758)
Add animated dots to progress indicator based on content length
Optimize when progress updates are shown (every 10 characters)
Move searchBlockCount calculation inside conditional blocks
Skip unnecessary ask operations when toolProgressStatus is empty
2025-04-24 00:12:07 -04:00
Sam Hoang Van
f06567d579
Feat/improve insert block content (#2510)
* refactor: enhance insertGroups and insertContentTool for better handling of insertion operations

* refactor: simplify insert_content tool

- Remove operations-based implementation in favor of single line insertion
- Update parameters from operations to line and content
- Simplify insertion logic and error handling
- Update tool description and documentation
- Remove XML parsing for operations
- Clean up code and improve error messages

* refactor: remove insert_content experiment and related tests

* Remove the append_to_file tool

* Improvements to chat row and instructions

---------

Co-authored-by: Matt Rubens <mrubens@users.noreply.github.com>
2025-04-21 16:49:27 -04:00
Matt Rubens
ed102d1850
Remove the strict line bounds check from the diff (#2790) 2025-04-19 15:43:27 -04:00
Chris Estreich
f6e4e3504f
Move executeCommand out of Cline and add telemetry for shell integration errors (#2771) 2025-04-18 14:43:04 -07:00
Matt Rubens
06882f5687
Don't break if an end_line is passed into a diff (#2743) 2025-04-18 02:23:55 -04:00
Chris Estreich
471caff000
Clean up types related to tools (#2719) 2025-04-17 13:31:48 -07:00
Matt Rubens
51bcade4c5
Better string normalization for diffs (#2659) 2025-04-15 16:20:20 -04:00
Matt Rubens
1eb29be33d
Remove the end_line from the multi_diff instructions and logic (#2615) 2025-04-14 20:39:27 -04:00
Matt Rubens
b196489b97
Fix overdependence on start/end lines in diff strategy (#2567)
* Add test for issue #2556

* Fix overdependence on start/end lines in diff strategy
2025-04-14 17:09:38 -04:00
Matt Rubens
c18e25f4bc
Fall back on aggressive line number stripping in diffs (#2453)
* Add option for aggressive line number stripping

* Fall back on aggressive line number stripping in diffs
2025-04-10 00:29:50 -04:00
KJ7LNW
2779e8f703
fix: clarify difference between workspace directory and terminal working directory (#2418)
* fix: clarify difference between workspace directory and terminal working directory

This commit addresses confusion between the VS Code workspace directory and
terminal working directory. Roo was not properly distinguishing between these
concepts, leading to issues when terminal commands changed directories.

- Renamed 'Current Working Directory' to 'Current Workspace Directory' throughout
- Added clearer notice when a command changes the working directory in a terminal
- Added explanation about the difference between workspace and working directories
- Updated all tool descriptions to reference 'workspace directory'

References: https://www.reddit.com/r/RooCode/s/6L19EvsFbF
Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>

* test: update directory terminology in test files

Update terminology from 'working directory' to 'workspace directory' in tests
to reflect VSCode's concept of workspace vs working directory.

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>

---------

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
Co-authored-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-04-08 22:58:33 -04:00
Matt Rubens
9ab4a88176
Fix typo in diff prompt (#2410) 2025-04-08 11:40:10 -04:00
Hannes Rudolph
951cefc0fc
Refactor: Improve file tool context formatting and diff error guidance (#2278)
* refactor: Change read_file result format to XML

Modifies how the result of the `read_file` tool is presented
in the conversation history sent to the AI model.

Previously, the format was:
[read_file for 'path/to/file'] Result:
{content_or_error}

This commit changes the format to use XML tags for better
structure and potentially easier parsing by the model:
<file>
  <path>path/to/file</path>
  <content>
{content_or_error}
  </content>
</file>

This change only affects the `read_file` tool result formatting
within the user context message constructed in `src/core/Cline.ts`.
Other tool result formats remain unchanged.

* fix: Update error message for better clarity in multi-search-replace strategy

Refines the error message returned when no sufficiently similar match is found during the multi-search-replace operation. The message now includes a clearer instruction to use the read_file tool for obtaining the latest file content before attempting to apply the diff again.

* refactor: Update readFileTool to return results in XML format

Modifies the `readFileTool` function to format the output as XML, enhancing the structure of the returned file content. This change aligns with previous updates to ensure consistent result formatting across tools.

* refactor: Simplify result handling for tool responses in Cline

This update refines the handling of tool responses in the `Cline` class by removing the XML formatting for `read_file` results and consolidating the logic for pushing results to the user message content. The changes ensure that all tool results are processed uniformly, improving code clarity and maintainability.

* test: Update read_file tests to validate XML formatted results

This commit modifies the assertions in the `read_file` tool tests to check for the expected XML format in the results. The changes ensure that the output structure aligns with recent updates to the tool's response formatting, enhancing test accuracy and reliability.

* test: Refactor assertions in read_file tests to use expected XML variable

This commit updates the `read_file` tool tests to utilize a predefined variable for the expected XML output, improving readability and maintainability of the test code. The changes ensure consistency in the expected results across multiple test cases.
2025-04-04 18:26:25 -04:00
Povilas Kanapickas
50eed96087
fix: Improve handling of escaped markers in apply_diff (#2274)
* fix: Improve handling of escaped markers in apply_diff

unescapeMarkers() is supposed to fix escaped merge conflict markers so
that they match the code. However the function has a bug which requires
SEARCH and REPLACE strings in the markers to be replaced. This is not
part of merge conflict markers, so many valid cases were previously
missed.

* Revert test changes

* Add new test

---------

Co-authored-by: Matt Rubens <mrubens@users.noreply.github.com>
2025-04-04 00:46:51 -04:00
Povilas Kanapickas
065c5ab222
fix: Improve error message when apply_diff structure is invalid (#2260)
Currently all errors in apply_diff diff structure are assumed to be
related to merge conflicts. This is unfortunate because it is way more
likely that LLM simply made an error structuring the diff. The LLM is
then directed to fix escaping in the diff from which it doesn't recover.

It is safe to assume that missing or extra "<<<<<<< SEARCH" or ">>>>>>>
REPLACE" strings are likely bad diff structure, because while "<<<<<<<"
and ">>>>>>>" are common merge conflict markers, no tools add "SEARCH"
and "REPLACE" strings after them. This is likely output of the LLM
itself.

LLM not recovering has been observed in Claude 3.5 Sonnet and Claude 3.7
Sonnet models.

To address the issue, error message now mentions merge conflict markers
and their escaping only if it's clear that errors may come from this
source. In the rest of cases the error message repeats the expected diff
structure back to the LLM.
2025-04-03 16:43:57 -04:00
Matt Rubens
3f5f8bb81f
Remove code for old diff strategies (#2262) 2025-04-03 11:09:02 -04:00
Povilas Kanapickas
552ed0e986
chore: Add more multi-block tests for apply_diff tool (#2261) 2025-04-03 10:55:05 -04:00
Matt Rubens
3d53386f1e
Remove the experimental unified diff (#2246) 2025-04-02 23:13:46 -04:00
Hannes Rudolph
9255dc5df9
fix(diff): Handle line number stripping for deletions in apply_diff (#2193)
The multi-search-replace diff strategy previously did not correctly strip line numbers (`number | `) from the SEARCH block when the REPLACE block was empty. This occurred because the condition for stripping required both blocks to consistently have line numbers.

This prevented successful deletion operations when the SEARCH block content was copied from `read_file` output (which includes line numbers) and the REPLACE block was empty.

This commit updates the line number stripping condition in `applyDiff` to also trigger if the SEARCH block has line numbers and the REPLACE block is empty or contains only whitespace, resolving the bug.

Additionally, a new test case has been added to `multi-search-replace.test.ts` to specifically verify this deletion scenario. All tests now pass with this updated logic.
2025-04-01 15:33:27 -05:00
Steven T. Cramer
b9f4695d12
Fix Tests to run properly on Windows (#1963)
* fix: remove -p flag from test script to prevent git operation errors

The -p flag in npm-run-all was causing tests to run in parallel, which led to 'Cannot log after tests are done' errors with git operations. These errors don't appear when running test:extension alone.

The issue occurs because git-based tests create temporary directories and run async operations that can interfere with each other when executed in parallel. Running tests sequentially resolves this cleanly.

While it might increase total test time slightly, it ensures more reliable and consistent test results.

* refactor(terminal): improve mock streams and fix test issues

- Create shell-specific mock streams (bash, cmd, pwsh) with proper line ending handling
- Fix open handles in tests by properly managing timeouts
- Standardize stderr redirection across all shell implementations using stdio option
- Improve test reliability and output cleanliness

* fix(tests): add skipVerification option to PowerShell tests to debug Linux issues

* fix(tests): use explicit variable name in PowerShell test to fix Linux compatibility

* Refactor terminal tests to use purpose-based approach instead of command mapping

* Remove reference to non-existent test file

* fix: use printf instead of echo -e for more consistent behavior across platforms

* fix: use single quotes for PowerShell commands to preserve variables on Linux

* Update code-qa workflow to run tests on both Windows and Ubuntu

* fix: use platform-specific PowerShell command execution for Linux and Windows

* Fix toggleToolAlwaysAllow to handle path normalization for cross-platform compatibility

* Fix McpHub tests to handle normalized paths on Windows

* Suppress console.error messages in McpHub tests

* fix: make Bedrock ARN regex patterns Windows-compatible

Fixed an issue where AWS Bedrock tests were timing out on Windows but passing on Linux. The root cause was path separator handling in regex patterns used for model ID extraction from ARNs.

1. Updated model ID extraction regex to handle both forward slashes (Linux) and backslashes (Windows)
2. Modified ARN matching regex to be platform-independent
3. Ensured consistent region prefix handling for all supported regions

This change maintains functionality while ensuring cross-platform compatibility.

* fix: make WorkspaceTracker test cross-platform compatible

Fixed an issue where the WorkspaceTracker test 'should initialize with workspace files' was failing on Windows but passing on Linux. The problem was in the mock implementation of toRelativePath that only handled forward slashes.

- Updated the toRelativePath mock to use path.relative which properly handles platform-specific path separators
- Ensured all paths are converted to forward slashes for consistency in test assertions
- The fix maintains cross-platform compatibility while preserving the test's intent

* fix: make WorkspaceTracker tests cross-platform compatible

Fixed cross-platform compatibility issues in the WorkspaceTracker tests that were causing failures on Windows but passing on Linux:

1. Updated the toRelativePath mock implementation to:
   - Use path.relative which properly handles platform-specific path separators
   - Convert paths to forward slashes for consistency in test assertions

2. Enhanced the 'should not update file paths' test to be platform-agnostic by:
   - Using more flexible assertions that don't depend on specific path formats
   - Checking file path length and content rather than exact string matches
   - Properly typed the test assertions to fix TypeScript errors

These changes preserve the test intent while ensuring they run successfully across different operating systems.

* fix: make McpHub tests cross-platform compatible

Fixed cross-platform compatibility issues in the McpHub tests that were causing failures on Windows but passing on Linux:

1. Made the toggleToolAlwaysAllow tests more platform-agnostic by:
   - No longer relying on specific path formats which differ between Windows and Linux
   - Using the last write call instead of searching for a specific path string
   - Adding more robust assertions that verify structure instead of exact path matches
   - Properly handling array existence checks

2. These tests would fail on Windows because paths are formatted with backslashes instead of
   forward slashes, causing path equality checks to fail.

The changes maintain test intent while ensuring cross-platform compatibility.

* handle escaping of slash and quote

* fix: ensure consistent line endings in git fallback strategy

Fixed an issue where tests would fail on GitHub Windows runners but pass on local Windows machines due to line ending differences. The fix ensures consistent line ending handling by:

1. Normalizing CRLF to LF when reading files in the git fallback strategy
2. Disabling Git's automatic line ending conversion
3. Maintaining consistent line ending usage throughout text operations

* feat: run tests sequentially on Windows, parallel otherwise
2025-03-31 23:17:56 -05:00
Matt Rubens
9a13041186
Remove the single diff strategy and make multi-diff the default (#2133) 2025-03-30 23:07:31 -04:00
Chris Estreich
2303f67afb
Clean up the way we compute the current diff strategy (#2049)
* Clean up the way we compute the current diff strategy

* Add changeset
2025-03-30 02:08:37 -04:00
Eric Wheeler
04854ea048 test: add tests for escaped marker handling in multi-search-replace
Add tests that validate:
- Original content with unescaped markers
- Search content with escaped markers to match unescaped markers in original content
- Proper validation of escaped search, separator, and replace markers in diff content
- Successful application of diffs with escaped markers in search content

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-21 20:55:51 -07:00
Eric Wheeler
2032c9e45f test: add validateMarkerSequencing test cases
Tests valid and invalid marker sequences:
- validates single and multiple complete sequences
- detects out-of-order markers (separator/replace before search)
- detects incorrect sequence termination
- validates state transitions between SEARCH/SEP/REPLACE markers

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-21 20:55:51 -07:00
Eric Wheeler
4b3f711746 fix: enforce newlines between diff section separators
Require newlines between diff section markers (SEARCH, ======, REPLACE)
to prevent content confusion when searching input contains separator
markers. Error message mentions required marker newlines.

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-21 20:55:51 -07:00
Eric Wheeler
c7321b0107 fix: reject apply_diff when search matches replace content
Prevents attempting to apply diffs where search and replace content are identical,
which would result in no changes being made. Instead, provide a helpful error
message explaining why the operation was rejected.

Fixes: #1350

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
2025-03-21 20:55:51 -07:00