Skip to content

The agent that grows with you

fix(desktop): Bots sidebar highlight and Cronjobs tile now follow the chat on screen

Teknium23c1c9815ff4
diff --git a/apps/desktop/src/plugins/hermes-bots/plugin.js b/apps/desktop/src/plugins/hermes-bots/plugin.js
index 1f5257f18c3..55be4d168fe 100644
--- a/apps/desktop/src/plugins/hermes-bots/plugin.js
+++ b/apps/desktop/src/plugins/hermes-bots/plugin.js
@@ -181,6 +181,16 @@ const $lastJobs = atom([])
* (the bot you're actually chatting with) and roster clicks. */
const $selectedBot = atom('default')
+/** Owner profile of the chat the user is LOOKING AT. Newer desktops expose
+ * `host.state.focusedSessionProfile` (the focused session row's stamped
+ * owner, gateway profile for drafts); older builds fall back to the gateway
+ * profile atom — the socket's home — which is the previous behavior. The
+ * distinction matters because tab/tile focus moves WITHOUT swapping the
+ * gateway socket: with only the socket atom, opening another bot's chat in
+ * a tab left the roster highlight (and the Cronjobs tile) on whichever bot
+ * the socket happened to be homed on. */
+const $focusedBotProfile = host.state.focusedSessionProfile || host.state.profile
+
/** Optional secondary navigation inside the Bots pane. Primary row clicks still
* open the bot's canonical chat; this state opens its stored-session browser. */
const $botSessionsWorkspace = atom(null)
@@ -4640,10 +4650,16 @@ function activeBots(roster, activeProfile, gatewayState, now = Date.now()) {
function BotRow({ bot, onDelete, onEdit, onGroup }) {
const activeProfile = useValue(host.state.profile)
+ const focusedProfile = useValue($focusedBotProfile)
const meta = botRosterMeta(bot, useValue($botMeta))
const groups = botGroups(meta)
const last = bot.last_session
- const isActive = !bot.remoteSource && bot.name === activeProfile
+ // Highlight follows the chat on screen (focused session's owner), not the
+ // gateway socket's home — a focused tab doesn't swap the socket, and on the
+ // old keying the wrong bot stayed highlighted while you read another's chat.
+ const isActive = !bot.remoteSource && bot.name === focusedProfile
+ // Turn-busy is a SOCKET fact: only the gateway-home profile can be mid-turn.
+ const isGatewayHome = !bot.remoteSource && bot.name === activeProfile
const { shape, color, image } = botAppearance(bot.name, meta)
// Keep user photos/pets. Drop the 160px SVG backfill so the math face can move.
const photo = Boolean(image && !isBackfilledFacePng(image))
@@ -4652,7 +4668,7 @@ function BotRow({ bot, onDelete, onEdit, onGroup }) {
// Work pose only when this bot is actually doing something: the active
// profile while the gateway is busy, or a bot that wrote within the
// liveness window. Not every bot whenever the gateway is busy.
- const botMood = (isActive && gatewayState === 'busy') || activeNow ? 'work' : 'idle'
+ const botMood = (isGatewayHome && gatewayState === 'busy') || activeNow ? 'work' : 'idle'
// Subscribe on every render. A source switch turns the same keyed row from
// thin to rich; conditionally calling useValue here breaks React hook order.
const unreadByName = useValue($botUnread)
@@ -7448,11 +7464,13 @@ function CreateRoutineDialog({ bot, open, onClose }) {
function RoutinesPane() {
const selected = useValue($selectedBot)
- const gatewayProfile = useValue(host.state.profile)
- // The tile maps to the bot you're chatting with: the live gateway profile
- // is the truth once a chat opens; $selectedBot covers the gap between a
- // roster click and the profile swap landing.
- const bot = (gatewayProfile || selected || 'default').trim() || 'default'
+ const focusedProfile = useValue($focusedBotProfile)
+ // The tile maps to the bot you're chatting with: the focused chat's owner
+ // profile is the truth once a chat opens (on older desktops without the
+ // focused-owner atom this is the live gateway profile, the previous
+ // behavior); $selectedBot covers the gap between a roster click and the
+ // focus/profile swap landing.
+ const bot = (focusedProfile || selected || 'default').trim() || 'default'
const meta = useValue($botMeta)[bot]
const { shape, color, image } = botAppearance(bot, meta)
const { data, error, isLoading, refetch } = useRoutines(bot)
@@ -9820,11 +9838,15 @@ export default {
/* no storage — rooms start empty */
}
- // Routines follow the chat you're in: track the live gateway profile.
+ // Routines follow the chat you're in: track the focused chat's owner
+ // profile (falls back to the live gateway profile on older desktops —
+ // see $focusedBotProfile). Keying this off the socket's home alone left
+ // the unread-suppression and Routines scope on the wrong bot whenever a
+ // focused tab showed another profile's chat.
// Capture the unbinds: without them a disable → re-enable cycle stacks a
// duplicate listener per cycle (same survives-disable class as the face
// clock before its onDispose hook — these kept firing until app restart).
- const unbindProfileListener = host.state.profile.listen(profile => {
+ const unbindProfileListener = $focusedBotProfile.listen(profile => {
if (profile && typeof profile === 'string') {
$selectedBot.set(profile)
}
diff --git a/apps/desktop/src/plugins/hermes-bots/tests/focused-bot-highlight.test.mjs b/apps/desktop/src/plugins/hermes-bots/tests/focused-bot-highlight.test.mjs
new file mode 100644
index 00000000000..e8f30f2441d
--- /dev/null
+++ b/apps/desktop/src/plugins/hermes-bots/tests/focused-bot-highlight.test.mjs
@@ -0,0 +1,53 @@
+import assert from 'node:assert/strict'
+import { readFileSync } from 'node:fs'
+import test from 'node:test'
+
+const source = readFileSync(new URL('../plugin.js', import.meta.url), 'utf8')
+
+// The roster highlight and the Routines (Cronjobs) tile must follow the chat
+// the user is LOOKING AT — the focused session's owner profile — not the
+// gateway socket's home. Tab/tile focus moves without swapping the socket, so
+// keying these off `host.state.profile` alone highlighted (and scoped the
+// Cronjobs panel to) the wrong bot whenever a focused tab showed another
+// profile's chat (community report: Newsanalyst chat open, Hermes highlighted).
+
+test('$focusedBotProfile prefers the focused-session owner atom and falls back to the gateway profile', () => {
+ assert.match(
+ source,
+ /const \$focusedBotProfile = host\.state\.focusedSessionProfile \|\| host\.state\.profile/,
+ 'feature-detected: newer desktops expose focusedSessionProfile; older builds keep the previous gateway-profile behavior'
+ )
+})
+
+test('BotRow keys the highlight off the focused profile, not the socket home', () => {
+ const rowStart = source.indexOf('function BotRow(')
+ assert.ok(rowStart >= 0)
+ const row = source.slice(rowStart, rowStart + 2000)
+
+ assert.match(row, /const focusedProfile = useValue\(\$focusedBotProfile\)/)
+ assert.match(row, /const isActive = !bot\.remoteSource && bot\.name === focusedProfile/)
+})
+
+test('BotRow keeps turn-busy (work mood) a socket fact', () => {
+ const rowStart = source.indexOf('function BotRow(')
+ const row = source.slice(rowStart, rowStart + 3000)
+
+ // Only the gateway-home profile can actually be mid-turn: the mood must NOT
+ // switch to the focus-keyed identity.
+ assert.match(row, /const isGatewayHome = !bot\.remoteSource && bot\.name === activeProfile/)
+ assert.match(row, /const botMood = \(isGatewayHome && gatewayState === 'busy'\) \|\| activeNow \? 'work' : 'idle'/)
+})
+
+test('RoutinesPane scopes the Cronjobs tile to the focused chat owner', () => {
+ const paneStart = source.indexOf('function RoutinesPane(')
+ assert.ok(paneStart >= 0)
+ const pane = source.slice(paneStart, paneStart + 1200)
+
+ assert.match(pane, /const focusedProfile = useValue\(\$focusedBotProfile\)/)
+ assert.match(pane, /const bot = \(focusedProfile \|\| selected \|\| 'default'\)\.trim\(\) \|\| 'default'/)
+ assert.ok(!/useValue\(host\.state\.profile\)/.test(pane), 'the tile must not read the socket-home atom directly')
+})
+
+test('the $selectedBot tracker listens on the focused profile ladder (unbind captured)', () => {
+ assert.match(source, /const unbindProfileListener = \$focusedBotProfile\.listen\(profile => \{/)
+})
diff --git a/apps/desktop/src/plugins/hermes-bots/tests/profile-prewarm.test.mjs b/apps/desktop/src/plugins/hermes-bots/tests/profile-prewarm.test.mjs
index 4c7db313fa9..9cff637fb52 100644
--- a/apps/desktop/src/plugins/hermes-bots/tests/profile-prewarm.test.mjs
+++ b/apps/desktop/src/plugins/hermes-bots/tests/profile-prewarm.test.mjs
@@ -41,6 +41,7 @@ function renderBotRow(input = 'alpha') {
ROSTER_KEY: ['hermes-bots', 'roster'],
$botMeta: atom({}),
$botUnread: atom({}),
+ $focusedBotProfile: atom('default'),
$lastRoster: atom([]),
$selectedBot: atom('default'),
botAppearance: () => ({ shape: 'round', color: '#000', image: null }),
@@ -168,6 +169,7 @@ test('behavior: remote default does not open this-device chat when the source di
ROSTER_KEY: ['hermes-bots', 'roster'],
$botMeta: atom({ default: { chat: 'this-device-chat' } }),
$botUnread: atom({}),
+ $focusedBotProfile: atom('default'),
$lastRoster: atom([]),
$selectedBot: atom('default'),
botAppearance: () => ({ shape: 'round', color: '#000', image: null }),
diff --git a/apps/desktop/src/sdk/host-state.test.ts b/apps/desktop/src/sdk/host-state.test.ts
index 68dc8918dd0..b372fd73258 100644
--- a/apps/desktop/src/sdk/host-state.test.ts
+++ b/apps/desktop/src/sdk/host-state.test.ts
@@ -129,6 +129,56 @@ describe('host.state focused-session atoms', () => {
})
})
+describe('host.state.focusedSessionProfile', () => {
+ beforeEach(() => {
+ window.localStorage.clear()
+ vi.resetModules()
+ })
+
+ afterEach(() => {
+ vi.resetModules()
+ })
+
+ async function setup() {
+ const { host } = await import('@/sdk/index')
+ const profile = await import('@/store/profile')
+ const session = await import('@/store/session')
+ const states = await import('@/store/session-states')
+
+ return { host, profile, session, states }
+ }
+
+ it('is a readonly atom that falls back to the gateway profile with no focused session', async () => {
+ const { host, profile } = await setup()
+
+ expect(typeof host.state.focusedSessionProfile.get).toBe('function')
+ expect(typeof host.state.focusedSessionProfile.listen).toBe('function')
+
+ profile.$activeGatewayProfile.set('newsanalyst')
+ expect(host.state.focusedSessionProfile.get()).toBe('newsanalyst')
+ profile.$activeGatewayProfile.set('default')
+ })
+
+ it('resolves the focused session to the owner stamped on its session row, not the socket home', async () => {
+ const { host, profile, session } = await setup()
+
+ // The gateway socket is homed on default (e.g. cold start), but the chat
+ // on screen belongs to newsanalyst — the readout must say newsanalyst.
+ profile.$activeGatewayProfile.set('default')
+ session.$sessions.set([{ id: 'news-1', profile: 'newsanalyst' } as never])
+ session.$selectedStoredSessionId.set('news-1')
+
+ expect(host.state.focusedSessionProfile.get()).toBe('newsanalyst')
+
+ // An uncached/unstamped id inherits the gateway profile (the old ladder).
+ session.$selectedStoredSessionId.set('unknown-id')
+ expect(host.state.focusedSessionProfile.get()).toBe('default')
+
+ session.$sessions.set([])
+ session.$selectedStoredSessionId.set(null)
+ })
+})
+
describe('host.state busy vs gateway', () => {
afterEach(() => {
$sessionStates.set({})
diff --git a/apps/desktop/src/sdk/index.ts b/apps/desktop/src/sdk/index.ts
index 6ffdd1b2974..d3e75aac356 100644
--- a/apps/desktop/src/sdk/index.ts
+++ b/apps/desktop/src/sdk/index.ts
@@ -65,6 +65,8 @@ import {
$gatewayState,
$messages,
$selectedStoredSessionId,
+ $sessions,
+ rememberedSessionProfile,
requestSessionResume,
setResumeExhaustedSessionId
} from '@/store/session'
@@ -105,6 +107,23 @@ const $focusedAwaitingResponse = focusedTurnFlag(
PRIMARY_SESSION_VIEW.$awaitingResponse
)
+/**
+ * Owner profile of the FOCUSED chat. The gateway-routing atom
+ * (`$activeGatewayProfile`) answers "which backend is the live socket homed
+ * on" — but tab/tile focus moves without swapping the socket, and a cold
+ * start can restore a route into a session the booting gateway doesn't own.
+ * Any per-bot readout (roster highlight, a bot-scoped panel) must follow the
+ * chat the user is LOOKING AT, so this resolves the focused stored session to
+ * the owner stamped on its session row (the cross-profile aggregator tags
+ * every row) and only falls back to the gateway profile for a draft or an
+ * uncached id — the same ladder the remembered-navigation key and the HUD use.
+ */
+const $focusedSessionProfile = computed(
+ [$focusedStoredSessionId, $sessions, $activeGatewayProfile],
+ (focused, sessions, activeProfile) =>
+ normalizeProfileKey(rememberedSessionProfile(sessions, focused, activeProfile))
+)
+
export interface PluginProfileRoute {
connectionId: string
mode: 'local' | 'remote'
@@ -317,6 +336,11 @@ export const host = {
* primary. Prefer this over `activeSessionId` for any readout that
* should follow the user between tiles (context, tokens, cost). */
focusedSessionId: readonlyAtom<null | string>($focusedRuntimeId),
+ /** Owner profile of the focused chat (session-row stamp, falling back to
+ * the gateway profile for drafts/uncached ids). Prefer this over
+ * `profile` for any readout keyed to the bot/profile the user is looking
+ * at — tab focus moves without swapping the gateway socket. */
+ focusedSessionProfile: readonlyAtom<string>($focusedSessionProfile),
/** Stored (durable) id of the focused session — for navigation and
* session-list matching, where runtime ids don't survive reloads. */
focusedStoredSessionId: readonlyAtom<null | string>($focusedStoredSessionId),
diff --git a/apps/desktop/src/sdk/profile-routing.test.ts b/apps/desktop/src/sdk/profile-routing.test.ts
index 26ca655169b..34dc7b61176 100644
--- a/apps/desktop/src/sdk/profile-routing.test.ts
+++ b/apps/desktop/src/sdk/profile-routing.test.ts
@@ -28,6 +28,12 @@ vi.mock('@/store/session', async () => {
$gatewayState: atom('open'),
$messages: atom([]),
$selectedStoredSessionId: atom(null),
+ $sessions: atom([]),
+ rememberedSessionProfile: (
+ _sessions: unknown,
+ _sessionId: null | string,
+ activeProfile: null | string
+ ) => (activeProfile ?? '').trim() || 'default',
requestSessionResume: vi.fn(),
setResumeExhaustedSessionId: vi.fn()
}
diff --git a/skills/autonomous-ai-agents/hermes-agent/references/desktop-plugins.md b/skills/autonomous-ai-agents/hermes-agent/references/desktop-plugins.md
index aee4e65d14b..dcf17298796 100644
--- a/skills/autonomous-ai-agents/hermes-agent/references/desktop-plugins.md
+++ b/skills/autonomous-ai-agents/hermes-agent/references/desktop-plugins.md
@@ -58,7 +58,10 @@ The ONLY import surface is `@hermes/plugin-sdk` (plus `react` /
`awaitingResponse`, `busyBySession`, `cwd`, `gateway` (socket state, not
turn-busy), `model`, `profile`, `viewport`, plus the tile-aware focused
session atoms: `focusedSessionId` (runtime id — key for `session.*` RPC),
- `focusedStoredSessionId` (durable id — navigation / list matching), and
+ `focusedStoredSessionId` (durable id — navigation / list matching),
+ `focusedSessionProfile` (owner profile of the focused chat — prefer over
+ `profile` for per-bot/profile readouts; `profile` is the gateway socket's
+ home, which does not move with tab focus), and
`focusedUsage` (live streamed `UsageStats` of the focused session, no RPC
needed). `busy` is true while the focused chat is working after a send
(thinking and streaming). `awaitingResponse` is true until the first
diff --git a/website/docs/developer-guide/desktop-plugin-sdk.md b/website/docs/developer-guide/desktop-plugin-sdk.md
index a111e7e8003..5a4c0dc4ed2 100644
--- a/website/docs/developer-guide/desktop-plugin-sdk.md
+++ b/website/docs/developer-guide/desktop-plugin-sdk.md
@@ -434,6 +434,7 @@ host.state.awaitingResponse // ReadableAtom<boolean> true until the first assis
host.state.busy // ReadableAtom<boolean> focused chat is working after a send
host.state.busyBySession // ReadableAtom<Record<string, boolean>> runtime id → mid-turn
host.state.focusedSessionId // ReadableAtom<string | null> (runtime id of the FOCUSED session — tile-aware; prefer for session.* RPC)
+host.state.focusedSessionProfile // ReadableAtom<string> (owner profile of the focused chat — prefer over `profile` for per-bot/profile readouts)
host.state.focusedStoredSessionId // ReadableAtom<string | null> (durable id — navigation / session-list matching)
host.state.focusedUsage // ReadableAtom<UsageStats | null> (live streamed usage of the focused session, no RPC needed)
host.state.cwd // ReadableAtom<string>