mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-14 08:18:36 +00:00
Corrected conditional on project existence
This commit is contained in:
1 parent
4dada35767
commit
077f50a9b9
1 file changed
+15
-20
+15
-20
@@ -21,7 +21,7 @@ from sensai.util.logging import LogTime
|
||||
from serena import serena_version
|
||||
from serena.analytics import RegisteredTokenCountEstimator, ToolUsageStats
|
||||
from serena.config.context_mode import RegisteredContext, SerenaAgentContext, SerenaAgentMode
|
||||
from serena.config.serena_config import SerenaConfig, ToolSet, get_serena_managed_in_project_dir
|
||||
from serena.config.serena_config import SerenaConfig, ToolInclusionDefinition, ToolSet, get_serena_managed_in_project_dir
|
||||
from serena.constants import (
|
||||
SERENA_LOG_FORMAT,
|
||||
)
|
||||
@@ -176,33 +176,28 @@ class SerenaAgent:
|
||||
|
||||
# determine the base toolset defining the set of exposed tools (which e.g. the MCP shall see),
|
||||
# limited by the Serena config, the context (which is fixed for the session) and JetBrains mode
|
||||
tool_inclusion_definitions = [self.serena_config, self._context]
|
||||
tool_inclusion_definitions: list[ToolInclusionDefinition] = [self.serena_config, self._context]
|
||||
if self.serena_config.jetbrains:
|
||||
tool_inclusion_definitions.append(SerenaAgentMode.from_name_internal("jetbrains"))
|
||||
|
||||
# In ide-assistant mode, apply additional tool exclusions
|
||||
if self._context.name == RegisteredContext.IDE_ASSISTANT.value:
|
||||
if self._context.name == RegisteredContext.IDE_ASSISTANT.value and project is not None:
|
||||
additional_excluded_tools = ["activate_project"]
|
||||
|
||||
# If a project is provided, check for excluded tools from project.yml
|
||||
if project is not None:
|
||||
try:
|
||||
# Try to load the project to get its excluded tools
|
||||
project_instance = None
|
||||
if os.path.isdir(project):
|
||||
project_instance = Project.load(project, autogenerate=False)
|
||||
else:
|
||||
project_instance = self.serena_config.get_project(project)
|
||||
|
||||
if project_instance is not None:
|
||||
additional_excluded_tools.extend(project_instance.project_config.excluded_tools)
|
||||
except (FileNotFoundError, ValueError):
|
||||
# If project.yml doesn't exist or can't be loaded, no additional exclusions
|
||||
pass
|
||||
|
||||
# Create a temporary ToolInclusionDefinition for ide-assistant exclusions
|
||||
from serena.config.serena_config import ToolInclusionDefinition
|
||||
try:
|
||||
# Try to load the project to get its excluded tools
|
||||
project_instance = None
|
||||
if os.path.isdir(project):
|
||||
project_instance = Project.load(project, autogenerate=False)
|
||||
else:
|
||||
project_instance = self.serena_config.get_project(project)
|
||||
|
||||
if project_instance is not None:
|
||||
additional_excluded_tools.extend(project_instance.project_config.excluded_tools)
|
||||
except (FileNotFoundError, ValueError):
|
||||
# If project.yml doesn't exist or can't be loaded, no additional exclusions
|
||||
pass
|
||||
ide_assistant_exclusions = ToolInclusionDefinition(excluded_tools=additional_excluded_tools)
|
||||
tool_inclusion_definitions.append(ide_assistant_exclusions)
|
||||
|
||||
|
||||
Reference in new issue
Block a user