From 29cbe2d8cb9c3b17dcd9241dfe279c9e3f20d5f2 Mon Sep 17 00:00:00 2001 From: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Date: Wed, 8 Jul 2026 18:44:54 -0700 Subject: [PATCH] Show empty sessions by default in AI Vault Panel (#7853) * Show empty sessions by default in AI Vault Panel Change the default state of `hideEmptySessions` from true to false, and update the active filter count calculation to treat false as the new default. * Centralize AI Vault view defaults and fix reset state alignment Consolidate the default values for sorting, grouping, and hiding empty sessions into a single place. This prevents inconsistencies between the initial state, the badge count adjustment checks, and the "Reset" view action, where the reset previously toggled hideEmptySessions to true contrary to the initial false value. * Count agent adjustments by membership instead of list length Ensure that swapping one agent for another (which keeps the total array length the same) is correctly identified as a deviation from the default of having all agents enabled. --- .../components/right-sidebar/AiVaultPanel.tsx | 30 ++++---- .../ai-vault-view-defaults.test.ts | 72 +++++++++++++++++++ .../right-sidebar/ai-vault-view-defaults.ts | 29 ++++++++ 3 files changed, 119 insertions(+), 12 deletions(-) create mode 100644 src/renderer/src/components/right-sidebar/ai-vault-view-defaults.test.ts create mode 100644 src/renderer/src/components/right-sidebar/ai-vault-view-defaults.ts diff --git a/src/renderer/src/components/right-sidebar/AiVaultPanel.tsx b/src/renderer/src/components/right-sidebar/AiVaultPanel.tsx index 4a6bccec9..c03192f40 100644 --- a/src/renderer/src/components/right-sidebar/AiVaultPanel.tsx +++ b/src/renderer/src/components/right-sidebar/AiVaultPanel.tsx @@ -20,6 +20,12 @@ import { getRestorableAiVaultScope, normalizeAiVaultScopeForContext } from './ai-vault-scope-state' +import { + countAiVaultViewAdjustments, + DEFAULT_AI_VAULT_GROUP, + DEFAULT_AI_VAULT_HIDE_EMPTY_SESSIONS, + DEFAULT_AI_VAULT_SORT +} from './ai-vault-view-defaults' import { buildAiVaultProjectContext } from './ai-vault-session-projects' import { resolveAiVaultSessionResumeActions, @@ -68,9 +74,9 @@ export default function AiVaultPanel(): React.JSX.Element { useAiVaultOriginalPaneActions() const [query, setQuery] = useState('') const [scope, setScope] = useState(DEFAULT_AI_VAULT_SCOPE) - const [sort, setSort] = useState('updated') - const [group, setGroup] = useState('project') - const [hideEmptySessions, setHideEmptySessions] = useState(true) + const [sort, setSort] = useState(DEFAULT_AI_VAULT_SORT) + const [group, setGroup] = useState(DEFAULT_AI_VAULT_GROUP) + const [hideEmptySessions, setHideEmptySessions] = useState(DEFAULT_AI_VAULT_HIDE_EMPTY_SESSIONS) const [agents, setAgents] = useState([...AI_VAULT_AGENTS]) const [collapsedGroups, setCollapsedGroups] = useState>(() => new Set()) const userChangedScopeRef = useRef(false) @@ -155,12 +161,12 @@ export default function AiVaultPanel(): React.JSX.Element { targetState: resumeTargetState, agentCmdOverrides }) - const hasAllAgentsSelected = agents.length === AI_VAULT_AGENTS.length - const viewAdjustmentCount = - (hasAllAgentsSelected ? 0 : 1) + - (sort === 'updated' ? 0 : 1) + - (group === 'project' ? 0 : 1) + - (hideEmptySessions ? 0 : 1) + const viewAdjustmentCount = countAiVaultViewAdjustments({ + agents, + sort, + group, + hideEmptySessions + }) // Workspace is the preferred default, but unavailable context still falls back to All. useEffect(() => { @@ -286,9 +292,9 @@ export default function AiVaultPanel(): React.JSX.Element { const resetViewOptions = useCallback(() => { setAgents([...AI_VAULT_AGENTS]) - setSort('updated') - setGroup('project') - setHideEmptySessions(true) + setSort(DEFAULT_AI_VAULT_SORT) + setGroup(DEFAULT_AI_VAULT_GROUP) + setHideEmptySessions(DEFAULT_AI_VAULT_HIDE_EMPTY_SESSIONS) }, []) const handleScopeChange = useCallback((nextScope: AiVaultScope) => { diff --git a/src/renderer/src/components/right-sidebar/ai-vault-view-defaults.test.ts b/src/renderer/src/components/right-sidebar/ai-vault-view-defaults.test.ts new file mode 100644 index 000000000..e45bdd386 --- /dev/null +++ b/src/renderer/src/components/right-sidebar/ai-vault-view-defaults.test.ts @@ -0,0 +1,72 @@ +import { describe, expect, it } from 'vitest' +import { AI_VAULT_AGENTS } from '../../../../shared/ai-vault-types' +import { + countAiVaultViewAdjustments, + DEFAULT_AI_VAULT_GROUP, + DEFAULT_AI_VAULT_HIDE_EMPTY_SESSIONS, + DEFAULT_AI_VAULT_SORT +} from './ai-vault-view-defaults' + +describe('ai-vault-view-defaults', () => { + it('shows empty sessions by default', () => { + expect(DEFAULT_AI_VAULT_HIDE_EMPTY_SESSIONS).toBe(false) + }) + + it('counts zero adjustments for the default view', () => { + expect( + countAiVaultViewAdjustments({ + agents: [...AI_VAULT_AGENTS], + sort: DEFAULT_AI_VAULT_SORT, + group: DEFAULT_AI_VAULT_GROUP, + hideEmptySessions: DEFAULT_AI_VAULT_HIDE_EMPTY_SESSIONS + }) + ).toBe(0) + }) + + it('treats hiding empty sessions as an adjustment from the new default', () => { + expect( + countAiVaultViewAdjustments({ + agents: [...AI_VAULT_AGENTS], + sort: DEFAULT_AI_VAULT_SORT, + group: DEFAULT_AI_VAULT_GROUP, + hideEmptySessions: true + }) + ).toBe(1) + }) + + it('does not count showing empty sessions as an adjustment', () => { + expect( + countAiVaultViewAdjustments({ + agents: [...AI_VAULT_AGENTS], + sort: DEFAULT_AI_VAULT_SORT, + group: DEFAULT_AI_VAULT_GROUP, + hideEmptySessions: false + }) + ).toBe(0) + }) + + it('counts an equal-length agent swap as an adjustment', () => { + // A swap keeps the array length but drops a default agent (here the first) for a duplicate. + const swapped = [...AI_VAULT_AGENTS.slice(1), AI_VAULT_AGENTS[1]] + expect(swapped).toHaveLength(AI_VAULT_AGENTS.length) + expect( + countAiVaultViewAdjustments({ + agents: swapped, + sort: DEFAULT_AI_VAULT_SORT, + group: DEFAULT_AI_VAULT_GROUP, + hideEmptySessions: DEFAULT_AI_VAULT_HIDE_EMPTY_SESSIONS + }) + ).toBe(1) + }) + + it('counts other non-default view options independently', () => { + expect( + countAiVaultViewAdjustments({ + agents: ['claude'], + sort: 'created', + group: 'agent', + hideEmptySessions: true + }) + ).toBe(4) + }) +}) diff --git a/src/renderer/src/components/right-sidebar/ai-vault-view-defaults.ts b/src/renderer/src/components/right-sidebar/ai-vault-view-defaults.ts new file mode 100644 index 000000000..9b1bfd8b2 --- /dev/null +++ b/src/renderer/src/components/right-sidebar/ai-vault-view-defaults.ts @@ -0,0 +1,29 @@ +import { + AI_VAULT_AGENTS, + type AiVaultAgent, + type AiVaultGroup, + type AiVaultSort +} from '../../../../shared/ai-vault-types' + +// Why: hide-empty used to default true; keep initial state, badge count, and Reset view +// on one constant so a default flip cannot leave Reset pointing at the old value. +export const DEFAULT_AI_VAULT_HIDE_EMPTY_SESSIONS = false +export const DEFAULT_AI_VAULT_SORT: AiVaultSort = 'updated' +export const DEFAULT_AI_VAULT_GROUP: AiVaultGroup = 'project' + +export function countAiVaultViewAdjustments(options: { + agents: readonly AiVaultAgent[] + sort: AiVaultSort + group: AiVaultGroup + hideEmptySessions: boolean +}): number { + // Why: count by membership, not length — an agent swap keeps the array length but + // still deviates from the default of every agent enabled. + const allAgentsEnabled = AI_VAULT_AGENTS.every((agent) => options.agents.includes(agent)) + return ( + (allAgentsEnabled ? 0 : 1) + + (options.sort === DEFAULT_AI_VAULT_SORT ? 0 : 1) + + (options.group === DEFAULT_AI_VAULT_GROUP ? 0 : 1) + + (options.hideEmptySessions === DEFAULT_AI_VAULT_HIDE_EMPTY_SESSIONS ? 0 : 1) + ) +}