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 (