fix(backend): respect session scoping in workspace file count

get_file_count() now uses the same session scoping logic as list_files(),
ensuring consistent totals when include_all_sessions is false.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Nicholas Tindle
2026-01-27 23:22:27 -06:00
parent 56248ae7b7
commit f8b041fd63
3 changed files with 28 additions and 3 deletions

View File

@@ -156,7 +156,9 @@ class ListWorkspaceFilesTool(BaseTool):
limit=limit,
include_all_sessions=include_all_sessions,
)
total = await manager.get_file_count()
total = await manager.get_file_count(
include_all_sessions=include_all_sessions
)
file_infos = [
WorkspaceFileInfoData(

View File

@@ -213,6 +213,7 @@ async def list_workspace_files(
async def count_workspace_files(
workspace_id: str,
path_prefix: Optional[str] = None,
include_deleted: bool = False,
) -> int:
"""
@@ -220,6 +221,7 @@ async def count_workspace_files(
Args:
workspace_id: The workspace ID
path_prefix: Optional path prefix to filter (e.g., "/sessions/abc123/")
include_deleted: Whether to include soft-deleted files
Returns:
@@ -229,6 +231,12 @@ async def count_workspace_files(
if not include_deleted:
where_clause["isDeleted"] = False
if path_prefix:
# Normalize prefix
if not path_prefix.startswith("/"):
path_prefix = f"/{path_prefix}"
where_clause["path"] = {"startswith": path_prefix}
return await UserWorkspaceFile.prisma().count(where=where_clause)

View File

@@ -360,11 +360,26 @@ class WorkspaceManager:
resolved_path = self._resolve_path(path)
return await workspace_file_exists(self.workspace_id, resolved_path)
async def get_file_count(self) -> int:
async def get_file_count(self, include_all_sessions: bool = False) -> int:
"""
Get number of files in workspace.
When session_id is set and include_all_sessions is False (default),
only counts files in the current session's folder.
Args:
include_all_sessions: If True, count all files in workspace.
If False (default), only count current session's files.
Returns:
Number of files
"""
return await count_workspace_files(self.workspace_id)
# Determine the effective path prefix (same logic as list_files)
if include_all_sessions:
path_prefix = None
elif self.session_path:
path_prefix = self.session_path
else:
path_prefix = None
return await count_workspace_files(self.workspace_id, path_prefix=path_prefix)