From fedadbe74babde083261ec82f2272ea730f53d4a Mon Sep 17 00:00:00 2001 From: Willie Date: Sat, 3 Oct 2026 21:11:10 +0800 Subject: [PATCH] fix(ui): keep memory connection states current and compact (#359) * fix(ui): keep memory connection states current and compact Disconnecting a target on the AGENTS.md tab did not refresh the memory tab, so for up to two minutes the target still showed as configured and could not be selected in the connect dialog. The guidance query now never serves a cached copy and refetches when the dialog opens. The side panel listed every target with its file path, which grew taller than the notes beside it. It now shows the same logo stack as Hooks and only lists targets that need a fix. The connect dialog uses the bordered target list from the AGENTS.md connect confirmation, and the review step gives before/after the same fixed height. * fix(ui): show why a memory target needs attention without hover The reason a target is broken (modified, malformed, not synced, ...) was only in a title tooltip, which keyboard and touch users cannot open, while the connect dialog disabled the row with a generic "Needs attention". Show the specific reason as the row's status text in both the side panel and the dialog. --- .../components/memory/MemoryGuidance.test.tsx | 14 +++++ ui/src/components/memory/MemoryGuidance.tsx | 54 ++++++++++++------- 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/ui/src/components/memory/MemoryGuidance.test.tsx b/ui/src/components/memory/MemoryGuidance.test.tsx index 6193cb14a..83ea971a0 100644 --- a/ui/src/components/memory/MemoryGuidance.test.tsx +++ b/ui/src/components/memory/MemoryGuidance.test.tsx @@ -47,3 +47,17 @@ it('returns to selection after a stale preview instead of reapplying silently', expect(within(screen.getByRole('dialog')).getByRole('button', { name: 'Review changes' })).toBeInTheDocument(); expect(api.applyMemoryGuidance).toHaveBeenCalledTimes(1); }); + +it('rechecks target states when the dialog opens', async () => { + vi.mocked(api.getMemoryGuidance).mockResolvedValueOnce({ scope: 'global', instructions: 'Read the notes', targets: [{ name: 'codex', state: 'configured' }] }); + const user = userEvent.setup(); renderGuidance(); + await user.click(await screen.findByRole('button', { name: 'Connect to agents' })); + expect(await screen.findByRole('checkbox', { name: /codex/ })).toBeEnabled(); +}); + +it('shows why a broken target cannot be connected without hovering', async () => { + vi.mocked(api.getMemoryGuidance).mockResolvedValue({ scope: 'global', instructions: 'Read the notes', targets: [{ name: 'codex', state: 'broken', detail: 'modified' }] }); + const user = userEvent.setup(); renderGuidance(); + await user.click(await screen.findByRole('button', { name: 'Connect to agents' })); + expect(within(screen.getByRole('dialog')).getByRole('checkbox', { name: /codex.*modified by hand/i })).toBeDisabled(); +}); diff --git a/ui/src/components/memory/MemoryGuidance.tsx b/ui/src/components/memory/MemoryGuidance.tsx index 055b287a5..550c339ca 100644 --- a/ui/src/components/memory/MemoryGuidance.tsx +++ b/ui/src/components/memory/MemoryGuidance.tsx @@ -9,7 +9,6 @@ import { queryKeys } from '../../lib/queryKeys'; import { shortenHome } from '../../lib/paths'; import AgentIcon from '../AgentIcon'; import Button from '../Button'; -import { Checkbox } from '../Checkbox'; import CodeView from '../CodeView'; import CopyButton from '../CopyButton'; import DialogShell from '../DialogShell'; @@ -18,7 +17,8 @@ import Tooltip from '../Tooltip'; export default function MemoryGuidance({ initialized, instructions }: { initialized: boolean; instructions: string }) { const t = useT(); const client = useQueryClient(); - const guidance = useQuery({ queryKey: [...queryKeys.memory.all, 'guidance'], queryFn: api.getMemoryGuidance, enabled: initialized }); + // States follow assignments and files that other tabs and the CLI change, so never trust a cached copy. + const guidance = useQuery({ queryKey: [...queryKeys.memory.all, 'guidance'], queryFn: api.getMemoryGuidance, enabled: initialized, staleTime: 0 }); const [open, setOpen] = useState(false); const [selected, setSelected] = useState([]); const [plan, setPlan] = useState(null); @@ -45,6 +45,9 @@ export default function MemoryGuidance({ initialized, instructions }: { initiali finally { setBusy(false); } }; const prompt = t('memory.checkPrompt'); + const targets = guidance.data?.targets ?? []; + // The specific reason beats the generic state; it must be readable without hovering. + const statusText = (target: (typeof targets)[number]) => target.detail ? t(`memory.connectionDetail.${target.detail}`, undefined, target.detail) : t(`memory.connection.${target.state}`); return (