The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(desktop): session-list API and row-decoration slots for plugins
tobenwarrior585e296db5d9
diff --git a/apps/desktop/src/app/chat/sidebar/session-row-slots.tsx b/apps/desktop/src/app/chat/sidebar/session-row-slots.tsxnew file mode 100644index 00000000000..e274643f890--- /dev/null+++ b/apps/desktop/src/app/chat/sidebar/session-row-slots.tsx@@ -0,0 +1,52 @@+import type { FC } from 'react'+import { useMemo } from 'react'++import { useContributions } from '@/contrib'+import { ContribBoundary, ContribRender } from '@/contrib/react/boundary'+import { type SessionRowSlotContribution } from '@/lib/session-row-slots'++/**+ * One row-decoration slot (leading / trailing) for `sessionId`. Mounts every+ * registration and lets each decide — it renders its decoration, or nothing at+ * all for rows it doesn't own.+ *+ * Mounting all of them (rather than first-wins) keeps ownership per session:+ * a plugin that declines a row must not suppress the one that owns it purely+ * on registration order. Two decorations on one row render both — a visible+ * composition, not a silent drop.+ */+const SessionRowSlotEntry: FC<{+ id: string+ render: SessionRowSlotContribution['render']+ sessionId: string+}> = ({ id, render, sessionId }) => {+ // Stable component identity: ContribRender mounts this AS a component, so a+ // fresh closure per render would remount the decoration on every tick.+ const renderSlot = useMemo(() => () => render({ sessionId }), [render, sessionId])++ return (+ <ContribBoundary id={id} variant="chip">+ <ContribRender render={renderSlot} />+ </ContribBoundary>+ )+}++export const SessionRowSlot: FC<{ area: string; sessionId: string }> = ({ area, sessionId }) => {+ const contributions = useContributions(area)++ if (contributions.length === 0) {+ return null+ }++ return (+ <>+ {contributions.map(contribution => {+ const render = (contribution.data as SessionRowSlotContribution | undefined)?.render++ return render ? (+ <SessionRowSlotEntry id={contribution.id} key={`${contribution.source ?? 'core'}:${contribution.id}`} render={render} sessionId={sessionId} />+ ) : null+ })}+ </>+ )+}diff --git a/apps/desktop/src/app/chat/sidebar/session-row.test.tsx b/apps/desktop/src/app/chat/sidebar/session-row.test.tsxindex 29770f6f6c0..c45a57aa422 100644--- a/apps/desktop/src/app/chat/sidebar/session-row.test.tsx+++ b/apps/desktop/src/app/chat/sidebar/session-row.test.tsx@@ -5,9 +5,11 @@ import { atom } from 'nanostores'import type * as React from 'react'import { afterEach, describe, expect, it, vi } from 'vitest'+import { registry } from '@/contrib/registry'import type { SessionInfo } from '@/hermes'import { createClientSessionState } from '@/lib/chat-runtime'import type * as ChatRuntime from '@/lib/chat-runtime'+import { SESSION_ROW_AREAS, type SessionRowSlotProps } from '@/lib/session-row-slots'import type * as Time from '@/lib/time'import type * as ComposerStatusStore from '@/store/composer-status'import type * as SessionStore from '@/store/session'@@ -324,3 +326,71 @@ describe('SidebarSessionRow inside the sortable list', () => {expect(grabber.getAttribute('aria-pressed')).toBe('true')})})++// Row-decoration slots: a plugin decorates rows through the registry with the+// row's stored session id handed to its render — the seam the session-list API+// pairs with (see #116305 item 3).+describe('SidebarSessionRow decoration slots', () => {+ const disposers: Array<() => void> = []++ afterEach(() => {+ disposers.splice(0).forEach(dispose => dispose())+ })++ const decorate = (area: string, id: string, testId: string) =>+ disposers.push(+ registry.register({+ area,+ data: {+ render: ({ sessionId }: SessionRowSlotProps) => <span data-testid={testId}>{sessionId}</span>+ },+ id,+ source: 'disk'+ })+ )++ it('mounts leading and trailing decorations with the row session id', () => {+ act(() => {+ decorate(SESSION_ROW_AREAS.leading, 'deco-lead', 'lead-deco')+ decorate(SESSION_ROW_AREAS.trailing, 'deco-tail', 'tail-deco')+ })++ renderRow(makeSession({ id: 'row-42', title: 'Decorated' }))++ expect(screen.getByTestId('lead-deco').textContent).toBe('row-42')+ expect(screen.getByTestId('tail-deco').textContent).toBe('row-42')+ })++ it('hands the slot the DURABLE id when it differs from the live one', () => {+ act(() => {+ decorate(SESSION_ROW_AREAS.leading, 'deco-lead', 'lead-deco')+ })++ // Auto-compression rotates the live id. A plugin that remembered the live+ // one decorates this row until the next compaction and then silently stops+ // matching — so the slot hands the lineage root, the id core's own+ // pin/reorder and `host.sessions.*` address.+ renderRow(makeSession({ _lineage_root_id: 'root-9', id: 'live-9', title: 'Compressed' }))++ expect(screen.getByTestId('lead-deco').textContent).toBe('root-9')+ })++ it('renders nothing for an area with no registrations and survives an unmount', () => {+ const { container } = renderRow(makeSession({ id: 'row-7', title: 'Plain' }))++ expect(container.querySelector('[data-testid="lead-deco"]')).toBeNull()++ act(() => {+ decorate(SESSION_ROW_AREAS.leading, 'deco-lead', 'lead-deco')+ })++ // Same row, contribution arriving late: the slot mounts it in place.+ expect(screen.getByTestId('lead-deco').textContent).toBe('row-7')++ act(() => {+ disposers.splice(0).forEach(dispose => dispose())+ })++ expect(screen.queryByTestId('lead-deco')).toBeNull()+ })+})diff --git a/apps/desktop/src/app/chat/sidebar/session-row.tsx b/apps/desktop/src/app/chat/sidebar/session-row.tsxindex 63919055e0f..242b61a2a33 100644--- a/apps/desktop/src/app/chat/sidebar/session-row.tsx+++ b/apps/desktop/src/app/chat/sidebar/session-row.tsx@@ -20,6 +20,7 @@ import { triggerHaptic } from '@/lib/haptics'import { middleClickHandlers } from '@/lib/middle-click'import { displayModelName } from '@/lib/model-status-label'import { sessionProjectLabel } from '@/lib/session-project-label'+import { SESSION_ROW_AREAS } from '@/lib/session-row-slots'import { handoffOriginSource, sessionSourceLabel } from '@/lib/session-source'import { coarseElapsed } from '@/lib/time'import { useStoreSelector } from '@/lib/use-session-slice'@@ -28,6 +29,7 @@ import { $sidebarRowMeta } from '@/store/layout'import { normalizeProfileKey } from '@/store/profile'import { $projects } from '@/store/projects'import { $pullRequestsByBranch, sessionPrKey } from '@/store/pull-requests'+import { sessionPinId } from '@/store/session'import { $sessionDotStateById, hasLiveTurn, showsRunningArc } from '@/store/session-dot-state'import { $sessionListDensity } from '@/store/session-list-density'import { $openStoredSessionIds } from '@/store/session-states'@@ -50,6 +52,7 @@ import { shellOwnsPress } from './reorderable-list'import { SessionActionsMenu, SessionContextMenu } from './session-actions-menu'import { sessionRowDetails } from './session-row-details'import { resolveSessionRowClick } from './session-row-gesture'+import { SessionRowSlot } from './session-row-slots'import { useProfilePrewarm } from './use-profile-prewarm'interface SidebarSessionRowProps extends React.ComponentProps<'div'> {@@ -499,6 +502,7 @@ function SidebarSessionRowImpl({return (<>{leadNode}+ <SessionRowSlot area={SESSION_ROW_AREAS.leading} sessionId={sessionPinId(session)} />{handoffBadge}<span className="min-w-0 flex-1 self-center"><OverflowTip label={title} placement="row">@@ -534,6 +538,7 @@ function SidebarSessionRowImpl({</span>)}</span>+ <SessionRowSlot area={SESSION_ROW_AREAS.trailing} sessionId={sessionPinId(session)} /></>)}@@ -547,6 +552,7 @@ function SidebarSessionRowImpl({entire width — nothing truncates against the kebab. */}<div className="flex min-w-0 items-center gap-1.5">{leadNode}+ <SessionRowSlot area={SESSION_ROW_AREAS.leading} sessionId={sessionPinId(session)} /><spanclassName={cn('min-w-0 flex-1 truncate text-[0.6875rem] text-(--ui-text-tertiary)',@@ -556,6 +562,7 @@ function SidebarSessionRowImpl({{context}</span>{handoffBadge}+ <SessionRowSlot area={SESSION_ROW_AREAS.trailing} sessionId={sessionPinId(session)} />{actionsNode}</div>{/* Title + preview: ONE grouped cell with its own tightdiff --git a/apps/desktop/src/lib/session-row-slots.ts b/apps/desktop/src/lib/session-row-slots.tsnew file mode 100644index 00000000000..7c1fd40173b--- /dev/null+++ b/apps/desktop/src/lib/session-row-slots.ts@@ -0,0 +1,40 @@+import type { ReactNode } from 'react'++/**+ * Session-row decoration surface — the seams a plugin can decorate a sidebar+ * session row through, with the SAME registry schema as every other surface+ * (statusbar, composer, panes):+ *+ * render areas (`data`): sessionRow.leading — inline right after the+ * status dot / drag handle+ * sessionRow.trailing — inline before the row's+ * hover actions cluster+ *+ * Core keeps ownership of the row's layout, gestures, and labels — these seams+ * AUGMENT a row with a small decoration (a badge, a colour swatch, a tag), they+ * never replace it. A contribution renders `null` for rows it doesn't own, so+ * registering one costs nothing on every other row in the list.+ */++export const SESSION_ROW_AREAS = {+ leading: 'sessionRow.leading',+ trailing: 'sessionRow.trailing'+} as const++/** Props handed to a session-row decoration's `render`. */+export interface SessionRowSlotProps {+ /** The STORED (durable) id of the session the row renders — the lineage root,+ * not the live id. Auto-compression rotates the live id, so a plugin that+ * remembers `session.id` decorates the row until the next compaction and then+ * silently stops matching; the durable id is the one `host.sessions.*` and+ * core's own pin/reorder address (see `sessionPinId`). */+ sessionId: string+}++/** Payload of a `sessionRow.*` contribution's `data`. */+export interface SessionRowSlotContribution {+ /** Renders the decoration, or `null` to leave the row untouched. Mounted as+ * a component inside the contribution error boundary, so it can subscribe+ * to its own stores; a throw degrades to an inline error, not a dead row. */+ render: (props: SessionRowSlotProps) => ReactNode+}diff --git a/apps/desktop/src/sdk/index.test.ts b/apps/desktop/src/sdk/index.test.tsindex 30c751a1938..4de8d61872e 100644--- a/apps/desktop/src/sdk/index.test.ts+++ b/apps/desktop/src/sdk/index.test.ts@@ -358,3 +358,61 @@ describe('host.composer draft facade', () => {await expect(host.composer.getDraft('rt-stash')).resolves.toBe('runtime-addressed')})})++describe('host.sessions session-list mutations', () => {+ beforeEach(async () => {+ const layout = await import('@/store/layout')+ const color = await import('@/store/session-color')+ const session = await import('@/store/session')++ layout.$pinnedSessionIds.set([])+ layout.$sidebarSessionOrderIds.set([])+ layout.$sidebarSessionOrderManual.set(false)+ color.$sessionColorOverrides.set({})+ session.$sessions.set([])+ })++ it('pin/unpin write the pinned store the sidebar reads', async () => {+ const { $pinnedSessionIds } = await import('@/store/layout')++ host.sessions.pin('row-1')+ expect($pinnedSessionIds.get()).toEqual(['row-1'])++ host.sessions.pin('row-2')+ expect($pinnedSessionIds.get()).toEqual(['row-1', 'row-2'])++ host.sessions.pin('row-1', false)+ expect($pinnedSessionIds.get()).toEqual(['row-2'])+ })++ it('resolves a live id to its durable lineage root before pinning', async () => {+ const { $pinnedSessionIds } = await import('@/store/layout')+ const { $sessions } = await import('@/store/session')+ const { makeSessionInfo } = await import('@/test/session-info')++ $sessions.set([makeSessionInfo({ _lineage_root_id: 'root-9', id: 'tip-9' })])++ host.sessions.pin('tip-9')++ expect($pinnedSessionIds.get()).toEqual(['root-9'])+ })++ it('reorder persists the manual order the drag path writes', async () => {+ const { $sidebarSessionOrderIds, $sidebarSessionOrderManual } = await import('@/store/layout')++ host.sessions.reorder(['c', 'a', 'b'])++ expect($sidebarSessionOrderManual.get()).toBe(true)+ expect($sidebarSessionOrderIds.get()).toEqual(['c', 'a', 'b'])+ })++ it('setColor writes the durable-keyed colour override and clears with null', async () => {+ const { $sessionColorOverrides } = await import('@/store/session-color')++ host.sessions.setColor('row-1', '#ff8800')+ expect($sessionColorOverrides.get()).toEqual({ 'row-1': '#ff8800' })++ host.sessions.setColor('row-1', null)+ expect($sessionColorOverrides.get()).toEqual({})+ })+})diff --git a/apps/desktop/src/sdk/index.ts b/apps/desktop/src/sdk/index.tsindex 6a883783936..23d1c8d5fed 100644--- a/apps/desktop/src/sdk/index.ts+++ b/apps/desktop/src/sdk/index.ts@@ -60,6 +60,12 @@ import {retireLocalProfileGateways,type SpawnPriority} from '@/store/gateway'+import {+ pinSession,+ setSidebarSessionOrderIds,+ setSidebarSessionOrderManual,+ unpinSession+} from '@/store/layout'import { notify, notifyError } from '@/store/notifications'import {$activeGatewayProfile,@@ -90,9 +96,11 @@ import {rememberedSessionProfile,requestSessionResume,sessionMatchesStoredId,+ sessionPinId,setResumeExhaustedSessionId,setSessionOwnerHint} from '@/store/session'+import { setSessionColorOverride } from '@/store/session-color'import {$focusedRuntimeId,$focusedSessionState,@@ -647,6 +655,17 @@ async function awaitProfileActivation(// by mutation: removing it changed no test outcome.}+/** Pins and colours are keyed by the DURABLE (lineage-root) id so they survive+ * compression's session-id rotation; a row's live id resolves through+ * `$sessions` (the app's own lineage matcher), and an id that resolves to+ * nothing is passed through as-is (the stores tolerate ids for rows this+ * window hasn't loaded). */+function durableSessionPinId(storedSessionId: string): string {+ const session = $sessions.get().find(s => sessionMatchesStoredId(s, storedSessionId))++ return session ? sessionPinId(session) : storedSessionId+}+export const host = {state: {/** Runtime id of the active chat session (null on a fresh draft). */@@ -918,6 +937,41 @@ export const host = {ensureAgent: async (connectionId: null | string | undefined, profile: string): Promise<void> =>ensureGatewayAgent(connectionId ?? null, (profile ?? '').trim() || 'default'),+ /** Session-list mutations a plugin may perform on the user's behalf. Every+ * method writes the SAME stores the app's own controls write, so a plugin+ * action and a hand click can never disagree — the sidebar and the tab+ * strip re-render from those stores immediately. Ids are stored (durable)+ * session ids as a sidebar row carries them (`session.id`); a live id is+ * resolved to its durable lineage root before writing. */+ sessions: {+ /** Pin or unpin a session — the row's ⇧-click / context-menu action. A+ * pinned session moves into the Pinned section on the next render. */+ pin: (storedSessionId: string, pinned = true): void => {+ const id = durableSessionPinId(storedSessionId)++ if (pinned) {+ pinSession(id)+ } else {+ unpinSession(id)+ }+ },++ /** Replace the manual session order with `ids` (what a drag persists).+ * Ids the window hasn't loaded reconcile on the next render, exactly+ * like the app's own reorder. */+ reorder: (ids: string[]): void => {+ setSidebarSessionOrderManual(true)+ setSidebarSessionOrderIds(ids)+ },++ /** Set a session's colour override (or clear it with `null`) — the same+ * per-session colour the app's own picker writes, so a plugin swatch and+ * a hand-picked colour are one value. */+ setColor: (storedSessionId: string, color: null | string): void => {+ setSessionColorOverride(durableSessionPinId(storedSessionId), color)+ }+ },+/** 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` /@@ -1873,6 +1927,10 @@ export const TITLEBAR_AREAS = { center: 'titleBar.center', left: 'titleBar.left'* setup.runtime_check, reconciled) — pass `host.request`. Don't hand-roll* readiness from raw RPC shapes. */export { evaluateRuntimeReadiness, type RuntimeReadinessResult } from '@/lib/runtime-readiness'+/** Row-decoration slots: register a `data` contribution with a `render` for+ * `SESSION_ROW_AREAS.leading` / `.trailing` to decorate sidebar session rows+ * (the props carry the row's stored session id). */+export { SESSION_ROW_AREAS, type SessionRowSlotContribution, type SessionRowSlotProps } from '@/lib/session-row-slots'/** A sibling WebSocket beside the route's `/api/ws` (voice PCM, Bot Screen RFB):* same origin, same auth resolution as chat. */export { resolveSiblingWsUrl, type SiblingWsRoute } from '@/lib/sibling-ws-url'diff --git a/website/docs/developer-guide/desktop-plugin-sdk.md b/website/docs/developer-guide/desktop-plugin-sdk.mdindex f3610d2f356..7b8b392bc18 100644--- a/website/docs/developer-guide/desktop-plugin-sdk.md+++ b/website/docs/developer-guide/desktop-plugin-sdk.md@@ -497,6 +497,33 @@ plugin write can never land in another session's composer.`sessionId` in the table is the id the plugin's UI is bound to; for a composerslot render it is `host.state.focusedSessionId.get()`.+### Session rows — decorations + the session list API++`SESSION_ROW_AREAS` (`leading`, `trailing`) let a plugin decorate sidebar+session rows. Register a `data` contribution whose `render({ sessionId })`+returns a small element (a badge, a swatch, a tag) or `null` for rows you don't+own — registering costs nothing on every other row:++```ts+import { SESSION_ROW_AREAS, type SessionRowSlotContribution } from '@hermes/plugin-sdk'++ctx.register({+ area: SESSION_ROW_AREAS.trailing,+ id: 'my-tag',+ data: {+ render: ({ sessionId }) => (owned.has(sessionId) ? <span className="my-tag">★</span> : null)+ } satisfies SessionRowSlotContribution+})+```++Pair it with the session list API — `host.sessions.pin(id, pinned?)`,+`host.sessions.reorder(ids)`, `host.sessions.setColor(id, color | null)` — which+write the same stores the app's own controls write (so a plugin action and a+hand click can never disagree). Ids are STORED session ids: a live id is+resolved to its durable lineage root, so pins and colours survive compression's+id rotation — and the row-decoration slots hand your render that same durable id+(`_lineage_root_id ?? id`), never the live one.+### Transcript directives — inline components the model addresses`TRANSCRIPT_DIRECTIVE_AREA` makes the transcript itself a contribution area.@@ -627,6 +654,10 @@ host.profileRoutes() // [{ profile, targetProfile, connecthost.requestProfile<T>(route, method, params?, timeoutMs?, { spawnPriority? }) // registry-routed RPC; no foreground swaphost.requestProfile<T>(profile, method, params?) // legacy v1/local overloadhost.request<T>(method, params?) // active-gateway JSON-RPC — the real power+host.sessions.pin(storedSessionId, pinned?) // pin/unpin a session (default pinned=true);+ // same store the row's ⇧-click writes+host.sessions.reorder(ids) // replace the manual session order (what a drag persists)+host.sessions.setColor(storedSessionId, color | null) // per-session colour override; null clears````host.request` is the same JSON-RPC the app itself uses (sessions, config, skills,