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

Method getModifyContext

packages/core/src/tools/edit.ts:503–543  ·  view source on GitHub ↗
(_: AbortSignal)

Source from the content-addressed store, hash-verified

501 }
502
503 getModifyContext(_: AbortSignal): ModifyContext<EditToolParams> {
504 return {
505 getFilePath: (params: EditToolParams) => params.file_path,
506 getCurrentContent: async (params: EditToolParams): Promise<string> => {
507 try {
508 return fs.readFileSync(params.file_path, 'utf8');
509 } catch (err) {
510 if (!isNodeError(err) || err.code !== 'ENOENT') throw err;
511 return '';
512 }
513 },
514 getProposedContent: async (params: EditToolParams): Promise<string> => {
515 try {
516 const currentContent = fs.readFileSync(params.file_path, 'utf8');
517 return applyReplacement(
518 currentContent,
519 params.old_string,
520 params.new_string,
521 params.old_string === '' && currentContent === '',
522 );
523 } catch (err) {
524 if (!isNodeError(err) || err.code !== 'ENOENT') throw err;
525 return '';
526 }
527 },
528 createUpdatedParams: (
529 oldContent: string,
530 modifiedProposedContent: string,
531 originalParams: EditToolParams,
532 ): EditToolParams => {
533 const content = originalParams.new_string;
534 return {
535 ...originalParams,
536 ai_proposed_string: content,
537 old_string: oldContent,
538 new_string: modifiedProposedContent,
539 modified_by_user: true,
540 };
541 },
542 };
543 }
544}

Callers

nothing calls this directly

Calls 2

isNodeErrorFunction · 0.85
applyReplacementFunction · 0.85

Tested by

no test coverage detected