The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(desktop): sidebar nav visibility and order for plugins
tobenwarrior632a5cd1c84f
diff --git a/apps/desktop/src/app/chat/sidebar/chat-sidebar.integration.test.tsx b/apps/desktop/src/app/chat/sidebar/chat-sidebar.integration.test.tsxindex b5a0b76a920..3e236dd0e4e 100644--- a/apps/desktop/src/app/chat/sidebar/chat-sidebar.integration.test.tsx+++ b/apps/desktop/src/app/chat/sidebar/chat-sidebar.integration.test.tsx@@ -20,6 +20,7 @@ import {$workspaceCwdOwner} from '@/store/session'import { $removedSessionIds } from '@/store/session-removal'+import { $sidebarHiddenNavIds } from '@/store/sidebar-nav'import { makeSessionInfo } from '@/test/session-info'import { type AppView, ROUTES_AREA, SIDEBAR_NAV_AREA } from '../../routes'@@ -111,6 +112,7 @@ describe('ChatSidebar navigation activity', () => {$removedSessionIds.set(new Set())$layoutTree.set(null)noteActiveTreeGroup(null)+ $sidebarHiddenNavIds.set([])})it('keeps navigation and session activity coherent with the focused pane', () => {@@ -174,6 +176,23 @@ describe('ChatSidebar navigation activity', () => {expectOnlyCurrent(null)expectOnlySelectedSession(null)})++ it('drops a nav row hidden through the nav preference (host.sidebar.hide)', () => {+ renderSidebar('/kanban', 'extension')+ expect(screen.getByRole('button', { name: 'Kanban' })).toBeTruthy()++ act(() => {+ $sidebarHiddenNavIds.set(['kanban-nav'])+ })+ expect(screen.queryByRole('button', { name: 'Kanban' })).toBeNull()+ // A hidden row is a preference, not a removal: the sibling nav row stays.+ expect(screen.getByRole('button', { name: 'Reports' })).toBeTruthy()++ act(() => {+ $sidebarHiddenNavIds.set([])+ })+ expect(screen.getByRole('button', { name: 'Kanban' })).toBeTruthy()+ })})// Entering a project is a scope switch: the conversation main is showing keepsdiff --git a/apps/desktop/src/app/chat/sidebar/index.tsx b/apps/desktop/src/app/chat/sidebar/index.tsxindex 39202f4ca75..ba5e9da72eb 100644--- a/apps/desktop/src/app/chat/sidebar/index.tsx+++ b/apps/desktop/src/app/chat/sidebar/index.tsx@@ -134,6 +134,7 @@ import { $focusedSessionIsTile, $focusedStoredSessionId, $workingSessionIds } frimport { ackAllSessionsRead } from '@/store/session-unread'import { markSessionUnread } from '@/store/session-unread-remote'import { $archivedSessions, loadArchivedSessions } from '@/store/sidebar-archive'+import { $sidebarHiddenNavIds, $sidebarNavOrderIds, orderSidebarNav } from '@/store/sidebar-nav'import { $sidebarSessionRankIds } from '@/store/sidebar-sort'import {@@ -431,9 +432,18 @@ export function ChatSidebar({const interfaceMode = useStore($interfaceMode)const showsAdvancedChrome = useStore($showsAdvancedChrome)+ // Nav preferences (host.sidebar): a plugin may hide rows or re-order them.+ // Applied here, at render, so the preference never mutates the default list.+ // They persist across a plugin disable → enable cycle by design (see+ // store/sidebar-nav.ts) — which also means they outlive a plugin that is+ // removed, so a row it hid stays hidden until something clears the store.+ const hiddenNavIds = useStore($sidebarHiddenNavIds)+ const navOrderIds = useStore($sidebarNavOrderIds)+const navItems = useMemo(- () => [...SIDEBAR_NAV, ...contributedNav].filter(shownInMode(interfaceMode)),- [contributedNav, interfaceMode]+ () =>+ orderSidebarNav([...SIDEBAR_NAV, ...contributedNav].filter(shownInMode(interfaceMode)), hiddenNavIds, navOrderIds),+ [contributedNav, hiddenNavIds, interfaceMode, navOrderIds])const panesFlipped = useStore($panesFlipped)diff --git a/apps/desktop/src/sdk/index.test.ts b/apps/desktop/src/sdk/index.test.tsindex 796bb948e09..c5cb6b111a3 100644--- a/apps/desktop/src/sdk/index.test.ts+++ b/apps/desktop/src/sdk/index.test.ts@@ -449,3 +449,30 @@ describe('host.sessions session-list mutations', () => {expect($sessionColorOverrides.get()).toEqual({})})})++describe('host.sidebar nav preferences', () => {+ beforeEach(async () => {+ const nav = await import('@/store/sidebar-nav')++ nav.$sidebarHiddenNavIds.set([])+ nav.$sidebarNavOrderIds.set([])+ })++ it('hide/unhide write the hidden-nav store', async () => {+ const { $sidebarHiddenNavIds } = await import('@/store/sidebar-nav')++ host.sidebar.hide('cron')+ expect($sidebarHiddenNavIds.get()).toEqual(['cron'])++ host.sidebar.hide('cron', false)+ expect($sidebarHiddenNavIds.get()).toEqual([])+ })++ it('setOrder writes the manual nav order', async () => {+ const { $sidebarNavOrderIds } = await import('@/store/sidebar-nav')++ host.sidebar.setOrder(['artifacts', 'cron'])++ expect($sidebarNavOrderIds.get()).toEqual(['artifacts', 'cron'])+ })+})diff --git a/apps/desktop/src/sdk/index.ts b/apps/desktop/src/sdk/index.tsindex 29a05b2d922..25a2c065eb3 100644--- a/apps/desktop/src/sdk/index.ts+++ b/apps/desktop/src/sdk/index.ts@@ -103,6 +103,7 @@ import {focusWorkspaceOwnerSessionTile,sessionTileDelegate} from '@/store/session-states'+import { setSidebarNavHidden, setSidebarNavOrder } from '@/store/sidebar-nav'import { runGatewayRestart } from '@/store/system-actions'import type { PaginatedSessions, UsageStats } from '@/types/hermes'@@ -922,6 +923,33 @@ export const host = {/** Session-list mutations (pin, reorder, colour) — see `./sessions`. */sessions: sessionsHost,+ /** Sidebar nav preferences — hide or re-order the sidebar's nav rows (core+ * built-ins and contributed rows alike), the way a sidebar-manager plugin+ * wants to. Core still owns rendering: a preference only ever moves or drops+ * a row that would otherwise render, and an id naming a row that no longer+ * exists is inert.+ *+ * Preferences PERSIST (a disable → enable cycle must not scramble the layout+ * the user chose), which means they also outlive the plugin that wrote them:+ * a row this call hid stays hidden after the plugin is removed. Clearing one+ * is the writer's job — `hide(id, false)` / `setOrder([])` — since the store+ * does not yet record which plugin wrote a preference.+ *+ * Ids are the rows' own ids (`SIDEBAR_NAV` built-ins like `'capabilities'`,+ * or a contributed nav contribution's id). */+ sidebar: {+ /** Hide or show one nav row. */+ hide: (navId: string, hidden = true): void => {+ setSidebarNavHidden(navId, hidden)+ },++ /** Replace the manual nav order with `ids`. Rows the order does not name+ * keep their default relative order after the named ones. */+ setOrder: (ids: string[]): void => {+ setSidebarNavOrder(ids)+ }+ },+/** Open a stored session the way core surfaces do. A plugin/Bot Mode open* is navigation, not a workspace or chrome API-home switch —* keepAllProfilesScope defaults true so `$activeGatewayProfile` /diff --git a/apps/desktop/src/store/sidebar-nav.test.ts b/apps/desktop/src/store/sidebar-nav.test.tsnew file mode 100644index 00000000000..e3e38d8b349--- /dev/null+++ b/apps/desktop/src/store/sidebar-nav.test.ts@@ -0,0 +1,63 @@+import { afterEach, describe, expect, it } from 'vitest'++import {+ $sidebarHiddenNavIds,+ $sidebarNavOrderIds,+ orderSidebarNav,+ setSidebarNavHidden,+ setSidebarNavOrder+} from './sidebar-nav'++afterEach(() => {+ $sidebarHiddenNavIds.set([])+ $sidebarNavOrderIds.set([])+})++const rows = [{ id: 'a' }, { id: 'b' }, { id: 'c' }, { id: 'd' }]++describe('orderSidebarNav', () => {+ it('keeps the default order when nothing is hidden or ordered', () => {+ expect(orderSidebarNav(rows, [], []).map(r => r.id)).toEqual(['a', 'b', 'c', 'd'])+ })++ it('drops hidden ids and ignores unknown ones', () => {+ expect(orderSidebarNav(rows, ['b', 'missing'], []).map(r => r.id)).toEqual(['a', 'c', 'd'])+ })++ it('names ordered ids first, in that order; unnamed rows keep their default order after', () => {+ expect(orderSidebarNav(rows, [], ['c', 'a']).map(r => r.id)).toEqual(['c', 'a', 'b', 'd'])+ })++ it('an ordered id that is also hidden stays hidden (hide wins)', () => {+ expect(orderSidebarNav(rows, ['c'], ['c', 'a']).map(r => r.id)).toEqual(['a', 'b', 'd'])+ })++ it('preserves the row objects themselves, not copies', () => {+ const [first] = orderSidebarNav(rows, [], ['b'])++ expect(first).toBe(rows[1])+ })+})++describe('sidebar nav preference setters', () => {+ it('hide is idempotent and reversible', () => {+ setSidebarNavHidden('cron')+ setSidebarNavHidden('cron')+ expect($sidebarHiddenNavIds.get()).toEqual(['cron'])++ setSidebarNavHidden('cron', false)+ setSidebarNavHidden('cron', false)+ expect($sidebarHiddenNavIds.get()).toEqual([])+ })++ it('ignores blank ids', () => {+ setSidebarNavHidden(' ')+ expect($sidebarHiddenNavIds.get()).toEqual([])+ })++ it('setOrder trims, drops blanks and dedupes', () => {+ setSidebarNavOrder([' b ', '', 'a', 'b'])++ expect($sidebarNavOrderIds.get()).toEqual(['b', 'a'])+ })+})diff --git a/apps/desktop/src/store/sidebar-nav.ts b/apps/desktop/src/store/sidebar-nav.tsnew file mode 100644index 00000000000..0afe353b1f7--- /dev/null+++ b/apps/desktop/src/store/sidebar-nav.ts@@ -0,0 +1,91 @@+import { Codecs, persistentAtom } from '@/lib/persisted'++// Sidebar-nav preferences — the store behind `host.sidebar`. A plugin (the+// sidebar manager) hides rows or re-orders them; core still owns rendering, so+// a preference only ever moves or drops a row that would otherwise render, and+// an id naming a row that no longer exists is inert.+//+// These PERSIST, deliberately: a disable → enable cycle must not scramble the+// layout the user chose. The consequence is that they outlive the plugin that+// wrote them — a row hidden by a plugin stays hidden after that plugin is+// removed, and there is no core UI that restores it. The escape hatch is the+// API that wrote it (`host.sidebar.hide(id, false)`, or clearing+// `hermes.desktop.sidebarNavHidden.v1` / `...NavOrder.v1`), which means the+// plugin that owns the preference is the one that can hand it back. Scoping a+// preference to its writer needs the plugin's identity in this store, which the+// host API does not carry yet.+export const $sidebarHiddenNavIds = persistentAtom<string[]>(+ 'hermes.desktop.sidebarNavHidden.v1',+ [],+ Codecs.stringArray+)++export const $sidebarNavOrderIds = persistentAtom<string[]>('hermes.desktop.sidebarNavOrder.v1', [], Codecs.stringArray)++/** Hide or show one nav row (idempotent; empty ids are ignored). */+export function setSidebarNavHidden(navId: string, hidden = true): void {+ const id = navId.trim()++ if (!id) {+ return+ }++ const prev = $sidebarHiddenNavIds.get()+ const present = prev.includes(id)++ if (present === hidden) {+ return+ }++ $sidebarHiddenNavIds.set(hidden ? [...prev, id] : prev.filter(existing => existing !== id))+}++/** Replace the manual nav order with `ids` (deduped, blanks dropped). Rows the+ * order does not name keep their default relative order after the named ones. */+export function setSidebarNavOrder(ids: string[]): void {+ const seen = new Set<string>()+ const next: string[] = []++ for (const raw of ids) {+ const id = (raw || '').trim()++ if (id && !seen.has(id)) {+ seen.add(id)+ next.push(id)+ }+ }++ $sidebarNavOrderIds.set(next)+}++/** Apply hidden + order to the nav rows. Pure so the semantics are testable+ * without a DOM: hidden ids drop out; ids named in `order` come first in that+ * exact order; rows the order does not name keep their default relative order+ * after them. Unknown ids in either list are inert. */+export function orderSidebarNav<T extends { id: string }>(+ items: readonly T[],+ hidden: readonly string[],+ order: readonly string[]+): T[] {+ const hiddenSet = new Set(hidden)+ const byId = new Map(items.map(item => [item.id, item]))+ const placed = new Set<string>()+ const ordered: T[] = []++ for (const id of order) {+ const item = byId.get(id)++ if (item && !hiddenSet.has(id) && !placed.has(id)) {+ ordered.push(item)+ placed.add(id)+ }+ }++ for (const item of items) {+ if (!hiddenSet.has(item.id) && !placed.has(item.id)) {+ ordered.push(item)+ }+ }++ return ordered+}diff --git a/website/docs/developer-guide/desktop-plugin-sdk.md b/website/docs/developer-guide/desktop-plugin-sdk.mdindex 57a297700c3..e29081c7894 100644--- a/website/docs/developer-guide/desktop-plugin-sdk.md+++ b/website/docs/developer-guide/desktop-plugin-sdk.md@@ -702,6 +702,9 @@ host.sessions.pin(storedSessionId, pinned?, index?) // pin/unpin (default pinnehost.sessions.reorder(ids) // replace the manual Recents order (what a drag persists); [] resetshost.sessions.reorderPinned(ids) // permute the Pinned section (the pinned drag path)host.sessions.setColor(storedSessionId, color | null) // per-session colour override; null clears+host.sidebar.hide(navId, hidden?) // hide/show a sidebar nav row (built-in or contributed)+host.sidebar.setOrder(ids) // nav rows in `ids` order first; unnamed rows keep+ // their default order after them````host.request` is the same JSON-RPC the app itself uses (sessions, config, skills,