From 0f5f00c78f8d867d2f029446e3b53f54ecbf701e Mon Sep 17 00:00:00 2001 From: Michael Panchenko Date: Tue, 1 Apr 2025 22:29:58 +0200 Subject: [PATCH] More detailed overview info cause Claude is too dumb to read docstrings --- src/serena/agent.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/serena/agent.py b/src/serena/agent.py index e4c8557f..d39ed0be 100644 --- a/src/serena/agent.py +++ b/src/serena/agent.py @@ -351,10 +351,15 @@ class GetDirOverviewTool(Tool): no content will be returned. Don't adjust unless there is really no other way to get the content required for the task. If the overview is too long, you should use a smaller directory instead, (e.g. a subdirectory). - :return: a JSON object mapping relative paths of all contained files to info about top-level symbols in the file (name, kind, line). + :return: a JSON object mapping relative paths of all contained files to info about top-level symbols in the file (name, kind, line, column). """ - result = json.dumps(self.language_server.request_dir_overview(relative_path)) - return self._limit_length(result, max_answer_chars) + path_to_symbol_infos = self.language_server.request_dir_overview(relative_path) + result = {} + for file_path, symbols in path_to_symbol_infos.items(): + result[file_path] = [_tuple_to_info(*symbol_info) for symbol_info in symbols] + + result_json_str = json.dumps(result) + return self._limit_length(result_json_str, max_answer_chars) class GetDocumentOverviewTool(Tool): @@ -372,10 +377,11 @@ class GetDocumentOverviewTool(Tool): :param max_answer_chars: if the overview is longer than this number of characters, no content will be returned. Don't adjust unless there is really no other way to get the content required for the task. - :return: a JSON object with the list of tuples (name, kind, line, column) of all top-level symbols in the file. + :return: a JSON object with the info (name, kind, line, column) of all top-level symbols in the file. """ - result = json.dumps(self.language_server.request_document_overview(relative_path)) - return self._limit_length(result, max_answer_chars) + result = self.language_server.request_document_overview(relative_path) + result_json_str = json.dumps([_tuple_to_info(*symbol_info) for symbol_info in result]) + return self._limit_length(result_json_str, max_answer_chars) class FindSymbolTool(Tool): @@ -899,3 +905,7 @@ def _print_tool_overview(tools: Iterable[type[Tool] | Tool]) -> None: for tool_name in sorted(tool_dict.keys()): tool = tool_dict[tool_name] print(f" * `{tool_name}`: {tool.get_tool_description().strip()}") + + +def _tuple_to_info(name: str, symbol_type: SymbolKind, line: int, column: int) -> dict[str, int | str]: + return {"name": name, "symbol_kind": symbol_type, "line": line, "column": column}