From b330a03a150bfc72cae0bfe6c62400c30366b95b Mon Sep 17 00:00:00 2001 From: Dominik Jain Date: Wed, 19 Nov 2025 15:04:25 +0100 Subject: [PATCH] Use new replace content functionality in EditMemoryTool Resolves #747 --- src/serena/tools/memory_tools.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/serena/tools/memory_tools.py b/src/serena/tools/memory_tools.py index e9280dc1..cc940257 100644 --- a/src/serena/tools/memory_tools.py +++ b/src/serena/tools/memory_tools.py @@ -1,4 +1,5 @@ import json +from typing import Literal from serena.tools import ReplaceContentTool, Tool @@ -70,20 +71,21 @@ class EditMemoryTool(Tool): def apply( self, memory_file_name: str, - regex: str, + needle: str, repl: str, + mode: Literal["literal", "regex"], ) -> str: r""" Replaces content matching a regular expression in a memory. :param memory_file_name: the name of the memory - :param regex: a Python-style regular expression (flags DOTALL and MULTILINE enabled, i.e. - '.' matches all characters, multi-line matching is enabled). - Apply the usual escaping as needed for reserved characters in Python-style regex. - :param repl: the string to replace the matched content with, which may contain - backreferences like \1, \2, etc. for groups matched by the regex. - Insert new content verbatim, except for backslashes, which have to be escaped. + :param needle: the string or regex pattern to search for. + If `mode` is "literal", this string will be matched exactly. + If `mode` is "regex", this string will be treated as a regular expression (syntax of Python's `re` module, + with flags DOTALL and MULTILINE enabled). + :param repl: the replacement string (verbatim). + :param mode: either "literal" or "regex", specifying how the `needle` parameter is to be interpreted. """ replace_content_tool = self.agent.get_tool(ReplaceContentTool) rel_path = self.memories_manager.get_memory_file_path(memory_file_name).relative_to(self.get_project_root()) - return replace_content_tool.replace_content(str(rel_path), regex, repl, mode="regex", require_not_ignored=False) + return replace_content_tool.replace_content(str(rel_path), needle, repl, mode=mode, require_not_ignored=False)