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

Method constructor

packages/core/src/tools/edit.ts:424–468  ·  view source on GitHub ↗
(private readonly config: Config)

Source from the content-addressed store, hash-verified

422{
423 static readonly Name = 'replace';
424 constructor(private readonly config: Config) {
425 super(
426 EditTool.Name,
427 'Edit',
428 `Replaces text within a file. By default, replaces a single occurrence, but can replace multiple occurrences when \`expected_replacements\` is specified. This tool requires providing significant context around the change to ensure precise targeting. Always use the ${ReadFileTool.Name} tool to examine the file's current content before attempting a text replacement.
429
430 The user has the ability to modify the \`new_string\` content. If modified, this will be stated in the response.
431
432Expectation for required parameters:
4331. \`file_path\` MUST be an absolute path; otherwise an error will be thrown.
4342. \`old_string\` MUST be the exact literal text to replace (including all whitespace, indentation, newlines, and surrounding code etc.).
4353. \`new_string\` MUST be the exact literal text to replace \`old_string\` with (also including all whitespace, indentation, newlines, and surrounding code etc.). Ensure the resulting code is correct and idiomatic.
4364. NEVER escape \`old_string\` or \`new_string\`, that would break the exact literal text requirement.
437**Important:** If ANY of the above are not satisfied, the tool will fail. CRITICAL for \`old_string\`: Must uniquely identify the single instance to change. Include at least 3 lines of context BEFORE and AFTER the target text, matching whitespace and indentation precisely. If this string matches multiple locations, or does not match exactly, the tool will fail.
438**Multiple replacements:** Set \`expected_replacements\` to the number of occurrences you want to replace. The tool will replace ALL occurrences that match \`old_string\` exactly. Ensure the number of replacements matches your expectation.`,
439 Kind.Edit,
440 {
441 properties: {
442 file_path: {
443 description:
444 "The absolute path to the file to modify. Must start with '/'.",
445 type: 'string',
446 },
447 old_string: {
448 description:
449 'The exact literal text to replace, preferably unescaped. For single replacements (default), include at least 3 lines of context BEFORE and AFTER the target text, matching whitespace and indentation precisely. For multiple replacements, specify expected_replacements parameter. If this string is not the exact literal text (i.e. you escaped it) or does not match exactly, the tool will fail.',
450 type: 'string',
451 },
452 new_string: {
453 description:
454 'The exact literal text to replace `old_string` with, preferably unescaped. Provide the EXACT text. Ensure the resulting code is correct and idiomatic.',
455 type: 'string',
456 },
457 expected_replacements: {
458 type: 'number',
459 description:
460 'Number of replacements expected. Defaults to 1 if not specified. Use when you want to replace multiple occurrences.',
461 minimum: 1,
462 },
463 },
464 required: ['file_path', 'old_string', 'new_string'],
465 type: 'object',
466 },
467 );
468 }
469
470 /**
471 * Validates the parameters for the Edit tool

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected