MCPcopy Create free account
hub / github.com/anus-dev/ANUS / applyReplacement

Function applyReplacement

packages/core/src/tools/edit.ts:33–51  ·  view source on GitHub ↗
(
  currentContent: string | null,
  oldString: string,
  newString: string,
  isNewFile: boolean,
)

Source from the content-addressed store, hash-verified

31import { IDEConnectionStatus } from '../ide/ide-client.js';
32
33export function applyReplacement(
34 currentContent: string | null,
35 oldString: string,
36 newString: string,
37 isNewFile: boolean,
38): string {
39 if (isNewFile) {
40 return newString;
41 }
42 if (currentContent === null) {
43 // Should not happen if not a new file, but defensively return empty or newString if oldString is also empty
44 return oldString === '' ? newString : '';
45 }
46 // If oldString is empty and it's not a new file, do not modify the content.
47 if (oldString === '' && !isNewFile) {
48 return currentContent;
49 }
50 return currentContent.replaceAll(oldString, newString);
51}
52
53/**
54 * Parameters for the Edit tool

Callers 3

calculateEditMethod · 0.85
getModifyContextMethod · 0.85
edit.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected