## Summary The AI chat history tab in the navigation drawer (and the corresponding "New chat" icon in the mobile bottom bar) were rendered for every authenticated user, regardless of whether they had `AI_SETTINGS` permission. The actual chat content load is already gated — see `AgentChatThreadInitializationEffect` — but the entry points were not, so users without AI access saw a tab they could open and find empty. This regressed when the `IS_AI_ENABLED` feature flag was removed in #19916. The flag check was the only gate; nothing replaced it with a permission check. ## Fix Three small changes, all using `useHasPermissionFlag(PermissionFlagType.AI_SETTINGS)`: - **`MainNavigationDrawerTabsRow`** — return `null` when the user lacks AI access. This row only contains AI controls (the chat history tab pill + the "New chat" button), so without AI access there is nothing meaningful to render. - **`MainNavigationDrawer`** — only render `NavigationDrawerAiChatContent` when the user has AI access **and** the active tab is `AI_CHAT_HISTORY`. This is defensive: with the tabs row hidden the user can no longer switch to AI, but the active-tab atom could still carry `AI_CHAT_HISTORY` from a previous state (notably right after stopping impersonation of a user who had AI). Without this guard, the AI panel would briefly stay rendered. - **`MobileNavigationBar`** — drop the `newAiChat` item when the user lacks AI access. Surfaced by the same customer report that motivated #20088 (stop-impersonation state cleanup), but this is a separate, pre-existing bug — admins without AI permission see the tab regardless of impersonation. ## Test plan - [ ] As a user **with** `AI_SETTINGS` permission, verify the AI chat tab and "New chat" button still appear and work in both the desktop sidebar and mobile bottom bar - [ ] As a user **without** `AI_SETTINGS` permission, verify: - the tabs row at the top of the sidebar is gone (only the navigation menu shows below) - the "New chat" mobile bottom-bar icon is gone - the AI chat panel does not appear even after navigating away from a state where it was previously active 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Run yarn dev while server running on port 3000