From 5dc7d441118029a2ffdeab037de6d98bc8f6947d Mon Sep 17 00:00:00 2001 From: Alex Blank Date: Thu, 4 Jun 2026 16:23:40 +0200 Subject: [PATCH] feat: improve session naming with workspace-aware scoped numbering When a workspace is provided, auto-generated display names now use workspace.name instead of repo.name: 'myworkspace / VS Code Server' # first 'myworkspace / VS Code Server #2' # second Without a workspace, naming falls back to repo.name: 'myrepo / VS Code Server' 'myrepo / VS Code Server #2' The counter is scoped to workspace+tool_type (or repo+tool_type), so different tool types for the same workspace/repo are numbered independently. This replaces the old format of 'project / repo / tool #N' which was always repo-based and included the project name even though the sidebar already groups by project. Quality gates: py_compile passed, ruff passed. --- apps/api/src/api/tool/tool_instances.py | 30 +++++++++++++++++-------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/apps/api/src/api/tool/tool_instances.py b/apps/api/src/api/tool/tool_instances.py index 77f159c..5206d08 100644 --- a/apps/api/src/api/tool/tool_instances.py +++ b/apps/api/src/api/tool/tool_instances.py @@ -853,19 +853,31 @@ async def create_instance( # Generate unique name instance_name = f"{tool_type.name}-{repo.name}-{uuid.uuid4().hex[:8]}" - # Auto-generate display name with numbering when duplicates exist + # Auto-generate display name with scoped numbering. + # When a workspace is provided, use workspace name + tool type. + # Otherwise fall back to repo name + tool type. if data.display_name: instance_display = data.display_name else: - auto_name = f"{_project.name} / {repo.name} / {tool_type.display_name}" - result = await session.execute( - select(ToolInstance).where( - ToolInstance.project_id == project_id, - ToolInstance.repository_id == repo_id, - ToolInstance.tool_type_id == tool_type_id, - ToolInstance.owner_id == user_id, + scope_name = workspace.name if workspace else repo.name + auto_name = f"{scope_name} / {tool_type.display_name}" + + if workspace: + count_query = ( + select(ToolInstance) + .where(ToolInstance.workspace_id == workspace_id) + .where(ToolInstance.tool_type_id == tool_type_id) + .where(ToolInstance.owner_id == user_id) ) - ) + else: + count_query = ( + select(ToolInstance) + .where(ToolInstance.repository_id == repo_id) + .where(ToolInstance.tool_type_id == tool_type_id) + .where(ToolInstance.owner_id == user_id) + ) + + result = await session.execute(count_query) existing_count = len(result.scalars().all()) if existing_count > 0: instance_display = f"{auto_name} #{existing_count + 1}"