Skip to content

Conversation

@hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented Feb 7, 2026

Summary

Replaces the search_and_replace tool with a new edit tool that uses a flat, single-operation parameter model (file_path, old_string, new_string, replace_all), replacing the old batch operations array. Keeps search_and_replace as a backward-compatible alias so models that reference it (e.g. MiniMax via includedTools) continue to work without changes. Unifies the chat UI rendering for all edit-family tool events.

Behavioral note: The old search_and_replace accepted an array of operations per call (with partial-success semantics). The new edit tool handles exactly one replacement per invocation, enforces uniqueness by default, and rejects no-op edits where old_string === new_string.

Changes

  • New edit tool definition (src/core/prompts/tools/native-tools/edit.ts) with file_path, old_string, new_string, replace_all parameters
  • New EditTool execution handler (src/core/tools/EditTool.ts) with replace_all support, uniqueness checking, and identical-string guard
  • Alias system: Added search_and_replace: "edit" to TOOL_ALIASES — models with includedTools: ["search_and_replace"] get the edit tool renamed as search_and_replace
  • Parser updates: NativeToolCallParser.ts handles both "edit" and "search_and_replace" tool names with the new parameter structure
  • Execution routing: presentAssistantMessage.ts routes both tool names to EditTool
  • Alias resolution in validation: isToolAllowedForMode now resolves aliases when checking customTools and toolRequirements, ensuring search_and_replace in includedTools correctly maps to edit
  • Backward compat wrapper: SearchAndReplaceTool.ts reduced to a 2-line re-export from EditTool
  • Types: Added "edit" to toolNames, "replace_all" to toolParamNames, updated NativeToolArgs for both edit and search_and_replace
  • Removed legacy XML tool markup detection: The containsXmlToolMarkup() guardrail in presentAssistantMessage.ts has been removed — it was a leftover from the XML-to-native tool calling migration that added maintenance burden (short tool names like "edit" caused false positives on words like <editor>) without meaningful benefit since all tool calling is now native
  • Unified chat UI: All edit-family tool events (editedExistingFile, appliedDiff, newFileCreated, searchAndReplace, search_and_replace, search_replace, edit, edit_file, apply_patch, apply_diff) render through a single branch in ChatRow.tsx with consistent diff icon, header text, and batch-diff support
  • apply_patch partial preview fix: Partial approval rows now extract a deterministic non-empty path from patch headers, falling back to the workspace basename — eliminates blank initial approval rows during streaming

Test Results

  • 7 targeted test files: 105/105 passing
  • Full src/ suite: 341 passed (29 pre-existing failures from missing @ai-sdk/amazon-bedrock — unrelated)
  • packages/types: 170/170 passing

Test details

  • 16 new EditTool tests covering basic replacement, replace_all, uniqueness errors, no-match errors, identical-string guard, missing params, approval flow, partial blocks, error recovery, and file tracking
  • searchAndReplaceTool.spec.ts reduced to alias verification (searchAndReplaceTool === editTool)
  • New applyPatchTool.partial.spec.ts for partial path extraction (header parsing, multi-file determinism, truncated-header stability, fallback, outside-workspace detection)
  • ChatRow.diff-actions.spec.tsx rewritten to verify unified edit rendering, jump-to-file for newFileCreated, protected/outside-workspace messaging, and batch diff handling
  • CI stability: deterministic timestamps in HistoryPreview.spec.tsx, increased cache-clear timeout in custom-tool-registry.spec.ts

Important

Introduces a new edit tool to replace search_and_replace, unifies edit-related UI, and updates tests for backward compatibility.

  • Behavior:
    • Introduces edit tool with parameters file_path, old_string, new_string, replace_all.
    • edit tool replaces search_and_replace, which remains as an alias for backward compatibility.
    • Enforces uniqueness by default and rejects no-op edits.
  • UI:
    • Unifies chat UI for edit-related tools in ChatRow.tsx.
    • Consistent rendering for editedExistingFile, appliedDiff, newFileCreated, searchAndReplace, edit, etc.
  • Code Changes:
    • Adds EditTool in EditTool.ts.
    • Removes legacy XML tool markup detection in presentAssistantMessage.ts.
    • Updates NativeToolCallParser.ts to handle edit and search_and_replace with new parameters.
    • Updates validateToolUse to resolve tool aliases.
  • Testing:
    • Adds tests for EditTool in editTool.spec.ts.
    • Updates ChatRow.diff-actions.spec.tsx to verify unified edit rendering.
    • Ensures backward compatibility with searchAndReplaceTool.spec.ts.

This description was created by Ellipsis for a3361d8. You can customize this summary. It will automatically update as commits are pushed.

@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. Enhancement New feature or request labels Feb 7, 2026
@roomote
Copy link
Contributor

roomote bot commented Feb 7, 2026

Rooviewer Clock   See task

All previously flagged issues are now resolved. No new issues in latest commit.

  • Delete orphaned src/core/prompts/tools/native-tools/search_and_replace.ts (old parameter schema, no longer imported)
  • containsXmlToolMarkup false-positive risk: "edit" in the tool-name list matches <editor>, <editable>, etc. after lowercasing -- fixed with hasTagReference boundary checking
  • Unified edit-family branch in ChatRow.tsx drops the onJumpToFile prop that newFileCreated previously passed to CodeAccordian -- fixed with onJumpToCreatedFile memo
  • EditTool.ts: String.prototype.replace() interprets special $-patterns ($$, $&, $`, $') in the replacement string -- fixed with function replacer () => normalizedNew
Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@hannesrudolph hannesrudolph force-pushed the feat/rename-search-and-replace-to-edit branch from 01335c6 to 0a1377c Compare February 8, 2026 00:32
@hannesrudolph hannesrudolph force-pushed the feat/rename-search-and-replace-to-edit branch from 52ad6f3 to 285a161 Compare February 8, 2026 03:44
@hannesrudolph hannesrudolph changed the title feat: rename search_and_replace tool to edit with new parameter structure feat: rename search_and_replace tool to edit and unify edit-family UI Feb 9, 2026
…ture

- Add new 'edit' tool with file_path, old_string, new_string, replace_all params
- Keep search_and_replace as backward-compatible alias via TOOL_ALIASES
- Create EditTool execution handler with replace_all and uniqueness checking
- Update NativeToolCallParser for both edit and search_and_replace names
- Update presentAssistantMessage routing for both tool names
- Add alias resolution to isToolAllowedForMode for customTools validation
- Reduce SearchAndReplaceTool.ts to re-export wrapper from EditTool
- Add 16 new EditTool tests, update searchAndReplaceTool tests
- MiniMax includedTools: ['search_and_replace'] continues to work via alias
- route edit/search/patch-related tool events through the appliedDiff chat UI branch

- ensure apply_patch partial rows emit a deterministic non-empty path

- add apply_patch partial regression tests

- expand ChatRow diff-actions tests for unified behavior
@hannesrudolph hannesrudolph force-pushed the feat/rename-search-and-replace-to-edit branch from 09a6b8a to 793be28 Compare February 10, 2026 00:24
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or request lgtm This PR has been approved by a maintainer size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants