From a527acc56c35f7b348b23c5102102ff2198a96ea Mon Sep 17 00:00:00 2001 From: canvrno <46584286+canvrno@users.noreply.github.com> Date: Wed, 14 May 2025 10:50:09 -0700 Subject: [PATCH] Feat: Workspace filter in Task History View (#3476) * Filter tasks to current workspace * Switched custom radio button to tailwind --- .changeset/fresh-houses-give.md | 5 + proto/task.proto | 1 + src/core/controller/task/getTaskHistory.ts | 40 ++++++- src/core/task/index.ts | 1 + src/shared/HistoryItem.ts | 1 + src/shared/proto/task.ts | 19 +++- .../src/components/history/HistoryView.tsx | 105 +++++++++--------- 7 files changed, 113 insertions(+), 59 deletions(-) create mode 100644 .changeset/fresh-houses-give.md diff --git a/.changeset/fresh-houses-give.md b/.changeset/fresh-houses-give.md new file mode 100644 index 00000000..fe898711 --- /dev/null +++ b/.changeset/fresh-houses-give.md @@ -0,0 +1,5 @@ +--- +"claude-dev": patch +--- + +Adds filtering for tasks tied to the current workspace diff --git a/proto/task.proto b/proto/task.proto index 0a8da19f..cc3af38c 100644 --- a/proto/task.proto +++ b/proto/task.proto @@ -67,6 +67,7 @@ message GetTaskHistoryRequest { bool favorites_only = 2; string search_query = 3; string sort_by = 4; + bool current_workspace_only = 5; } // Response for task history diff --git a/src/core/controller/task/getTaskHistory.ts b/src/core/controller/task/getTaskHistory.ts index 2c7cef3a..f27146c7 100644 --- a/src/core/controller/task/getTaskHistory.ts +++ b/src/core/controller/task/getTaskHistory.ts @@ -1,6 +1,7 @@ import { Controller } from ".." import { GetTaskHistoryRequest, TaskHistoryArray } from "../../../shared/proto/task" import { getGlobalState } from "../../storage/state" +import { getWorkspacePath, arePathsEqual } from "../../../utils/path" /** * Gets filtered task history @@ -10,22 +11,49 @@ import { getGlobalState } from "../../storage/state" */ export async function getTaskHistory(controller: Controller, request: GetTaskHistoryRequest): Promise { try { - const { favoritesOnly, searchQuery, sortBy } = request + const { favoritesOnly, currentWorkspaceOnly, searchQuery, sortBy } = request // Get task history from global state const taskHistory = ((await getGlobalState(controller.context, "taskHistory")) as any[]) || [] + const workspacePath = getWorkspacePath() // Apply filters let filteredTasks = taskHistory.filter((item) => { // Basic filter: must have timestamp and task content const hasRequiredFields = item.ts && item.task - - // Apply favorites filter if requested - if (favoritesOnly && hasRequiredFields) { - return item.isFavorited === true + if (!hasRequiredFields) { + return false } - return hasRequiredFields + // Apply favorites filter if requested + if (favoritesOnly && !item.isFavorited) { + return false + } + + // Apply current workspace filter if requested + if (currentWorkspaceOnly) { + let isInWorkspace = false + + // First check the cwdOnTaskInitialization property - Only present on tasks from this change forward + if (item.cwdOnTaskInitialization) { + if (arePathsEqual(item.cwdOnTaskInitialization, workspacePath)) { + isInWorkspace = true + } + } + + // For tasks without cwdOnTaskInitialization, check the older shadowGitConfigWorkTree property + if (!isInWorkspace && item.shadowGitConfigWorkTree) { + if (arePathsEqual(item.shadowGitConfigWorkTree, workspacePath)) { + isInWorkspace = true + } + } + + if (!isInWorkspace) { + return false + } + } + + return true }) // Apply search if provided diff --git a/src/core/task/index.ts b/src/core/task/index.ts index fba6cbb9..52403deb 100644 --- a/src/core/task/index.ts +++ b/src/core/task/index.ts @@ -314,6 +314,7 @@ export class Task { totalCost: apiMetrics.totalCost, size: taskDirSize, shadowGitConfigWorkTree: await this.checkpointTracker?.getShadowGitConfigWorkTree(), + cwdOnTaskInitialization: cwd, conversationHistoryDeletedRange: this.conversationHistoryDeletedRange, isFavorited: this.taskIsFavorited, }) diff --git a/src/shared/HistoryItem.ts b/src/shared/HistoryItem.ts index 61c9448e..023da5f9 100644 --- a/src/shared/HistoryItem.ts +++ b/src/shared/HistoryItem.ts @@ -10,6 +10,7 @@ export type HistoryItem = { size?: number shadowGitConfigWorkTree?: string + cwdOnTaskInitialization?: string conversationHistoryDeletedRange?: [number, number] isFavorited?: boolean } diff --git a/src/shared/proto/task.ts b/src/shared/proto/task.ts index af3ccada..c618eec6 100644 --- a/src/shared/proto/task.ts +++ b/src/shared/proto/task.ts @@ -50,6 +50,7 @@ export interface GetTaskHistoryRequest { favoritesOnly: boolean searchQuery: string sortBy: string + currentWorkspaceOnly: boolean } /** Response for task history */ @@ -550,7 +551,7 @@ export const DeleteNonFavoritedTasksResults: MessageFns = { @@ -567,6 +568,9 @@ export const GetTaskHistoryRequest: MessageFns = { if (message.sortBy !== "") { writer.uint32(34).string(message.sortBy) } + if (message.currentWorkspaceOnly !== false) { + writer.uint32(40).bool(message.currentWorkspaceOnly) + } return writer }, @@ -609,6 +613,14 @@ export const GetTaskHistoryRequest: MessageFns = { message.sortBy = reader.string() continue } + case 5: { + if (tag !== 40) { + break + } + + message.currentWorkspaceOnly = reader.bool() + continue + } } if ((tag & 7) === 4 || tag === 0) { break @@ -624,6 +636,7 @@ export const GetTaskHistoryRequest: MessageFns = { favoritesOnly: isSet(object.favoritesOnly) ? globalThis.Boolean(object.favoritesOnly) : false, searchQuery: isSet(object.searchQuery) ? globalThis.String(object.searchQuery) : "", sortBy: isSet(object.sortBy) ? globalThis.String(object.sortBy) : "", + currentWorkspaceOnly: isSet(object.currentWorkspaceOnly) ? globalThis.Boolean(object.currentWorkspaceOnly) : false, } }, @@ -641,6 +654,9 @@ export const GetTaskHistoryRequest: MessageFns = { if (message.sortBy !== "") { obj.sortBy = message.sortBy } + if (message.currentWorkspaceOnly !== false) { + obj.currentWorkspaceOnly = message.currentWorkspaceOnly + } return obj }, @@ -654,6 +670,7 @@ export const GetTaskHistoryRequest: MessageFns = { message.favoritesOnly = object.favoritesOnly ?? false message.searchQuery = object.searchQuery ?? "" message.sortBy = object.sortBy ?? "" + message.currentWorkspaceOnly = object.currentWorkspaceOnly ?? false return message }, } diff --git a/webview-ui/src/components/history/HistoryView.tsx b/webview-ui/src/components/history/HistoryView.tsx index b21dcb51..89bac0c8 100644 --- a/webview-ui/src/components/history/HistoryView.tsx +++ b/webview-ui/src/components/history/HistoryView.tsx @@ -17,14 +17,44 @@ type HistoryViewProps = { type SortOption = "newest" | "oldest" | "mostExpensive" | "mostTokens" | "mostRelevant" +// Tailwind-styled radio with custom icon support - works independently of VSCodeRadioGroup but looks the same +// Used for workspace and favorites filters + +interface CustomFilterRadioProps { + checked: boolean + onChange: () => void + icon: string + label: string +} + +const CustomFilterRadio = ({ checked, onChange, icon, label }: CustomFilterRadioProps) => { + return ( +
+
+ {checked &&
} +
+ +
+ {label} + +
+ ) +} + const HistoryView = ({ onDone }: HistoryViewProps) => { - const { taskHistory, totalTasksSize } = useExtensionState() + const { taskHistory, totalTasksSize, filePaths } = useExtensionState() const [searchQuery, setSearchQuery] = useState("") const [sortOption, setSortOption] = useState("newest") const [lastNonRelevantSort, setLastNonRelevantSort] = useState("newest") const [deleteAllDisabled, setDeleteAllDisabled] = useState(false) const [selectedItems, setSelectedItems] = useState([]) const [showFavoritesOnly, setShowFavoritesOnly] = useState(false) + const [showCurrentWorkspaceOnly, setShowCurrentWorkspaceOnly] = useState(false) // Keep track of pending favorite toggle operations const [pendingFavoriteToggles, setPendingFavoriteToggles] = useState>({}) @@ -39,24 +69,23 @@ const HistoryView = ({ onDone }: HistoryViewProps) => { favoritesOnly: showFavoritesOnly, searchQuery: searchQuery || undefined, sortBy: sortOption, + currentWorkspaceOnly: showCurrentWorkspaceOnly, }) setFilteredTasks(response.tasks || []) } catch (error) { console.error("Error loading task history:", error) - // Fallback to client-side filtering - setFilteredTasks( - taskHistory.filter((item) => { - const valid = item.ts && item.task - return valid && (!showFavoritesOnly || item.isFavorited) - }), - ) } - }, [showFavoritesOnly, searchQuery, sortOption, taskHistory]) + }, [showFavoritesOnly, showCurrentWorkspaceOnly, searchQuery, sortOption, taskHistory]) // Load when filters change useEffect(() => { + // Force a complete refresh when both filters are active + // to ensure proper combined filtering + if (showFavoritesOnly && showCurrentWorkspaceOnly) { + setFilteredTasks([]) + } loadTaskHistory() - }, [loadTaskHistory]) + }, [loadTaskHistory, showFavoritesOnly, showCurrentWorkspaceOnly]) const toggleFavorite = useCallback( async (taskId: string, currentValue: boolean) => { @@ -69,8 +98,8 @@ const HistoryView = ({ onDone }: HistoryViewProps) => { isFavorited: !currentValue, }) - // Refresh if favorites filter is active - if (showFavoritesOnly) { + // Refresh if either filter is active to ensure proper combined filtering + if (showFavoritesOnly || showCurrentWorkspaceOnly) { loadTaskHistory() } } catch (err) { @@ -320,46 +349,18 @@ const HistoryView = ({ onDone }: HistoryViewProps) => { Most Relevant -
setShowFavoritesOnly(!showFavoritesOnly)} - style={{ - display: "flex", - alignItems: "center", - marginLeft: "6px", - cursor: "pointer", - }}> -
- {showFavoritesOnly && ( -
- )} -
- -
- Favorites - -
+ setShowCurrentWorkspaceOnly(!showCurrentWorkspaceOnly)} + icon="workspace" + label="Workspace" + /> + setShowFavoritesOnly(!showFavoritesOnly)} + icon="star-full" + label="Favorites" + />