Skip to content

The agent that grows with you

fix(desktop): sidebarNav.prefs cannot hide the Plugins row; document the real order rule and namespaced ids

teknium12553b8660bea
diff --git a/apps/desktop/src/sdk/index.ts b/apps/desktop/src/sdk/index.ts
index 8b66a347003..0ba9404519a 100644
--- a/apps/desktop/src/sdk/index.ts
+++ b/apps/desktop/src/sdk/index.ts
@@ -1913,8 +1913,10 @@ export { cn } from '@/lib/utils'
* from, and the persisted half is bucketed per profile. */
export { ackStoredSessionId, forgetSessionUnread, markSessionUnreadFinished } from '@/store/session-unread'
/** `sidebarNav.prefs`: hide / re-order the sidebar's nav rows by CONTRIBUTING a
- * preference (union of hides; first-registered order wins). A contribution,
- * not a `host.sidebar` verb, so it is attributed and dropped on disable. */
+ * preference (union of hides, `capabilities` never hidden; the first order
+ * in registry area order — lowest `order`, then registration — wins). A
+ * contribution, not a `host.sidebar` verb, so it is attributed and dropped
+ * on disable. */
export { SIDEBAR_NAV_PREFS_AREA, type SidebarNavPrefsContribution } from '@/store/sidebar-nav'
/** Live accent override — set a hex and the ACTIVE theme repaints with its
* accent family re-seeded from it (see `retintTheme`); `null` restores the
diff --git a/apps/desktop/src/store/sidebar-nav.test.ts b/apps/desktop/src/store/sidebar-nav.test.ts
index 99c55e9378e..f7bc1f5db73 100644
--- a/apps/desktop/src/store/sidebar-nav.test.ts
+++ b/apps/desktop/src/store/sidebar-nav.test.ts
@@ -1,24 +1,55 @@
import { describe, expect, it } from 'vitest'
+import { registry } from '@/contrib/registry'
+
import { applySidebarNavPrefs, SIDEBAR_NAV_PREFS_AREA } from './sidebar-nav'
-const rows = [{ id: 'a' }, { id: 'b' }, { id: 'c' }, { id: 'd' }, { id: 'e' }]
+const rows = [{ id: 'a' }, { id: 'b' }, { id: 'c' }, { id: 'd' }, { id: 'e' }, { id: 'capabilities' }]
-const prefs = (id: string, data: { hide?: string[]; order?: string[] }) => ({ area: SIDEBAR_NAV_PREFS_AREA, id, data })
+const prefs = (id: string, data: { hide?: string[]; order?: string[] }, order?: number) => ({
+ area: SIDEBAR_NAV_PREFS_AREA,
+ data,
+ id,
+ order
+})
describe('applySidebarNavPrefs', () => {
// The arbitration rule two plugins live under: neither can un-hide the
- // other's row; the first-registered order owns the placement it names and a
- // later order only places what is still unplaced; unknown ids are inert;
- // rows nobody names keep their default relative order after the named ones.
- it('unions hides and lets the first-registered order win', () => {
+ // other's row; the first contribution's order owns the placement it names
+ // and a later order only places what is still unplaced; unknown ids are
+ // inert; rows nobody names keep their default relative order after the
+ // named ones; the row that hosts the Plugins tab (a plugin's own off-switch)
+ // can be moved but never hidden.
+ it('unions hides, lets the first order win, and keeps the capabilities row', () => {
const merged = applySidebarNavPrefs(rows, [
- prefs('first', { hide: ['b'], order: ['d', 'a'] }),
+ prefs('first', { hide: ['b', 'capabilities'], order: ['d', 'a'] }),
prefs('second', { hide: ['c', 'missing'], order: ['a', 'd', 'b', 'nope'] })
])
- expect(merged.map(r => r.id)).toEqual(['d', 'a', 'e'])
+ expect(merged.map(r => r.id)).toEqual(['d', 'a', 'e', 'capabilities'])
expect(merged[0]).toBe(rows[3])
- expect(applySidebarNavPrefs(rows, []).map(r => r.id)).toEqual(['a', 'b', 'c', 'd', 'e'])
+ expect(applySidebarNavPrefs(rows, []).map(r => r.id)).toEqual(['a', 'b', 'c', 'd', 'e', 'capabilities'])
+ })
+
+ // "First" is the registry's order for the area — lowest `Contribution.order`,
+ // then registration — not registration alone; the docs state that rule.
+ it('reads contributions in registry order: lowest `order` first, then registration', () => {
+ const dispose = registry.registerMany([
+ prefs('later-wins', { order: ['e'] }, -1),
+ prefs('registered-first', { order: ['a'] })
+ ])
+
+ try {
+ expect(applySidebarNavPrefs(rows, registry.getArea(SIDEBAR_NAV_PREFS_AREA)).map(r => r.id)).toEqual([
+ 'e',
+ 'a',
+ 'b',
+ 'c',
+ 'd',
+ 'capabilities'
+ ])
+ } finally {
+ dispose()
+ }
})
})
diff --git a/apps/desktop/src/store/sidebar-nav.ts b/apps/desktop/src/store/sidebar-nav.ts
index cf551bf4e09..76974c206dd 100644
--- a/apps/desktop/src/store/sidebar-nav.ts
+++ b/apps/desktop/src/store/sidebar-nav.ts
@@ -19,23 +19,32 @@ export const SIDEBAR_NAV_PREFS_AREA = 'sidebarNav.prefs'
/** Payload (`data`) of a `sidebarNav.prefs` contribution. Ids are the nav rows'
* own ids: the core rows `'new-session' | 'capabilities' | 'messaging' |
- * 'artifacts' | 'cron'` (see `SidebarNavId`) or a `sidebar.nav` contribution's id. */
+ * 'artifacts' | 'cron'` (see `SidebarNavId`) or a `sidebar.nav` contribution's
+ * REGISTERED id — `ctx.register` namespaces it to `${pluginId}:${id}`. */
export interface SidebarNavPrefsContribution {
- /** Rows to drop. Merged as the UNION across contributions. */
+ /** Rows to drop. Merged as the UNION across contributions; `capabilities`
+ * (the row that hosts the Plugins tab) is never dropped. */
hide?: string[]
- /** Rows to place first, in this order. The first-registered contribution's
- * order wins; later ones place only ids not yet placed. */
+ /** Rows to place first, in this order. Contributions apply in the registry's
+ * area order (lowest `Contribution.order`, then registration); the first
+ * order wins, later ones place only ids not yet placed. */
order?: string[]
}
+/** Rows a preference may move but never hide: `capabilities` hosts the Plugins
+ * tab, the user's only path to a plugin's own off-switch. */
+const NEVER_HIDDEN: ReadonlySet<string> = new Set(['capabilities'])
+
const cleanIds = (ids: unknown): string[] =>
Array.isArray(ids) ? ids.filter((id): id is string => typeof id === 'string' && id.trim() !== '') : []
-/** Apply every `sidebarNav.prefs` contribution to the nav rows. Pure so the
- * arbitration is testable without a DOM: hidden = union of every `hide`
- * (hide beats order); `order` = first-registered contribution first, later
- * contributions place only ids not yet placed; rows no order names keep their
- * default relative order after the named ones; unknown ids are inert. */
+/** Apply every `sidebarNav.prefs` contribution to the nav rows, in the order
+ * given (the caller passes `registry.getArea`, so lowest `order` first, then
+ * registration). Pure so the arbitration is testable without a DOM:
+ * hidden = union of every `hide` minus `NEVER_HIDDEN` (hide beats order);
+ * `order` = first contribution first, later contributions place only ids not
+ * yet placed; rows no order names keep their default relative order after
+ * the named ones; unknown ids are inert. */
export function applySidebarNavPrefs<T extends { id: string }>(
items: readonly T[],
contributions: readonly Contribution[]
@@ -46,7 +55,11 @@ export function applySidebarNavPrefs<T extends { id: string }>(
for (const c of contributions) {
const prefs = c.data as SidebarNavPrefsContribution | undefined
- cleanIds(prefs?.hide).forEach(id => hidden.add(id))
+ cleanIds(prefs?.hide).forEach(id => {
+ if (!NEVER_HIDDEN.has(id)) {
+ hidden.add(id)
+ }
+ })
order.push(...cleanIds(prefs?.order))
}
diff --git a/website/docs/developer-guide/desktop-plugin-sdk.md b/website/docs/developer-guide/desktop-plugin-sdk.md
index 6eae0adfe70..ed5d263165a 100644
--- a/website/docs/developer-guide/desktop-plugin-sdk.md
+++ b/website/docs/developer-guide/desktop-plugin-sdk.md
@@ -666,13 +666,19 @@ ctx.register({
Nav ids are the rows' own ids. Core rows: `new-session`, `capabilities`,
`messaging`, `artifacts`, `cron` (the `SidebarNavId` type; `artifacts` and
`cron` only render in Advanced mode). A contributed row's id is its
-`SIDEBAR_NAV_AREA` contribution id.
+**registered** `SIDEBAR_NAV_AREA` id, which `ctx.register` namespaces to
+`${pluginId}:${id}` — a plugin that registered `{ id: 'kanban-nav', area:
+SIDEBAR_NAV_AREA }` as `kanban` names that row `'kanban:kanban-nav'` in
+`hide`/`order`.
**Arbitration.** Hidden rows are the **union** of every contribution's `hide`
-(no plugin can un-hide another's row; hide beats order). Order is
-**first-registered wins**: the first contribution's `order` places its rows,
-later contributions place only ids not yet placed, rows no order names keep
-their default relative order after the named ones. Unknown ids are inert.
+(no plugin can un-hide another's row; hide beats order), except
+`capabilities`: the row hosting the Plugins tab is the user's path to a
+plugin's own off-switch, so it can be moved but never hidden. Contributions
+apply in the registry's area order — **lowest `order`, then registration** —
+and the first one's `order` wins: later contributions place only ids not yet
+placed, rows no order names keep their default relative order after the
+named ones. Unknown ids are inert.
**Teardown.** The contribution lives in the registry, so disabling or reloading
the plugin disposes it and the rows come straight back — nothing to clear.