From 75410c78e780c762268c660912f3e5554ea6550b Mon Sep 17 00:00:00 2001 From: Michael Panchenko Date: Fri, 12 Jun 2026 18:08:11 +0200 Subject: [PATCH] Use depth=-1 to enable lang-specific default for overview tools --- CHANGELOG.md | 1 + src/serena/tools/jetbrains_tools.py | 11 +++++++++-- src/serena/tools/symbol_tools.py | 12 +++++++++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3795e43..29582122 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ Status of the `main` branch. Changes prior to the next official version change w * Tools: - New tool: `replace_in_files` + - `get_symbols_overview`, `jet_brains_get_symbols_overview`: Improved default for `depth` parameter - Add tool parameter alias support, adding `name_path` as an alias for `name_path_pattern` in `find_symbol` tools - Allow `query_project` tool to access read-only tools that are not enabled in the current configuration - Make tool call errors surface explicitly as errors at the MCP protocol level diff --git a/src/serena/tools/jetbrains_tools.py b/src/serena/tools/jetbrains_tools.py index 3e71c45f..c29d58ce 100644 --- a/src/serena/tools/jetbrains_tools.py +++ b/src/serena/tools/jetbrains_tools.py @@ -323,7 +323,7 @@ class JetBrainsGetSymbolsOverviewTool(Tool, ToolMarkerSymbolicRead, ToolMarkerOp def apply( self, relative_path: str, - depth: int = 0, + depth: int = -1, max_answer_chars: int = -1, include_file_documentation: bool = False, ) -> str: @@ -335,10 +335,17 @@ class JetBrainsGetSymbolsOverviewTool(Tool, ToolMarkerSymbolicRead, ToolMarkerOp or by using the `list_dir` and `find_file` tools (or similar). :param relative_path: the relative path to the file to get the overview of - :param depth: depth up to which descendants shall be retrieved (e.g., use 1 to also retrieve immediate children). + :param depth: depth up to which descendants shall be retrieved. + Default (-1) results in a language specific choice: 1 for java and kotlin and 0 for other languages :param max_answer_chars: max characters for the result (-1 for default). If exceeded, no content/a shortened result is returned. :param include_file_documentation: whether to include the file's docstring. Default False. """ + if depth == -1: + if relative_path.endswith((".java", ".kt")): + depth = 1 + else: + depth = 0 + relative_path = self._sanitize_input_param(relative_path) with JetBrainsPluginClient.from_project(self.project) as client: symbol_overview = client.get_symbols_overview( diff --git a/src/serena/tools/symbol_tools.py b/src/serena/tools/symbol_tools.py index 7c11fce4..a5d12d54 100644 --- a/src/serena/tools/symbol_tools.py +++ b/src/serena/tools/symbol_tools.py @@ -40,20 +40,26 @@ class GetSymbolsOverviewTool(Tool, ToolMarkerSymbolicRead): symbol_dict_grouper = LanguageServerSymbolDictGrouper(["kind"], ["kind"], collapse_singleton=True) - def apply(self, relative_path: str, depth: int = 0, max_answer_chars: int = -1) -> str: + def apply(self, relative_path: str, depth: int = -1, max_answer_chars: int = -1) -> str: """ Use this tool to get a high-level understanding of the code symbols in a file. This should be the first tool to call when you want to understand a new file, unless you already know what you are looking for. :param relative_path: the relative path to the file to get the overview of - :param depth: depth up to which descendants of top-level symbols shall be retrieved - (e.g. 1 retrieves immediate children). Default 0. + :param depth: depth up to which descendants shall be retrieved. + Default (-1) results in a language specific choice: 1 for java and kotlin and 0 for other languages :param max_answer_chars: if the overview is longer than this number of characters, no content will be returned. -1 means the default value from the config will be used. Don't adjust unless there is really no other way to get the content required for the task. :return: a JSON object containing symbols grouped by kind in a compact format. """ + if depth == -1: + if relative_path.endswith((".java", ".kt")): + depth = 1 + else: + depth = 0 + result = self.get_symbol_overview(relative_path, depth=depth) # capture kind names and depth-0 snapshots before grouping, which mutates the dicts