The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(desktop): raise a bot's Screen tab when it starts using its desktop (opt-in)
teknium1437e7456f5ee
diff --git a/apps/desktop/src/plugins/hermes-bots/bot-row.tsx b/apps/desktop/src/plugins/hermes-bots/bot-row.tsxindex 613fd64215d..621ad396479 100644--- a/apps/desktop/src/plugins/hermes-bots/bot-row.tsx+++ b/apps/desktop/src/plugins/hermes-bots/bot-row.tsx@@ -11,6 +11,7 @@ import {coarseElapsed,Codicon,ContextMenu,+ ContextMenuCheckboxItem,ContextMenuContent,ContextMenuItem,ContextMenuSeparator,@@ -323,6 +324,23 @@ export function BotRow({ bot, onDelete, onEdit, onGroup, onNewSection, showHandl<ContextMenuContent><ContextMenuItem onSelect={() => void openRosterBot(bot)}>{b.bot.openBotChat}</ContextMenuItem><ContextMenuItem onSelect={() => openBotScreen(bot, meta)}>{b.screen.menu}</ContextMenuItem>+ <ContextMenuCheckboxItem+ checked={Boolean(meta?.screenAutoOpen)}+ onSelect={() => {+ void ensureBotMetadata(bot)+ .then(current => {+ const next = !current.screenAutoOpen+ void saveBotMeta(bot, { screenAutoOpen: next })+ host.notify({+ kind: 'info',+ message: next ? b.screen.autoOpenOnToast(displayName(bot, current)) : b.screen.autoOpenOffToast(displayName(bot, current))+ })+ })+ .catch(error => host.notifyError?.(error, b.bot.metadataLoadFailed))+ }}+ >+ {b.screen.autoOpenMenu}+ </ContextMenuCheckboxItem><ContextMenuSeparator /><ContextMenuItemonSelect={() => {diff --git a/apps/desktop/src/plugins/hermes-bots/i18n.ts b/apps/desktop/src/plugins/hermes-bots/i18n.tsindex a70fcf877e0..2cd8e3078c9 100644--- a/apps/desktop/src/plugins/hermes-bots/i18n.ts+++ b/apps/desktop/src/plugins/hermes-bots/i18n.ts@@ -290,6 +290,9 @@ type BotsMessages = {portalUnsupported: stringportalUnavailable: stringunavailableTitle: string+ autoOpenMenu: string+ autoOpenOnToast: (name: string) => string+ autoOpenOffToast: (name: string) => stringstoppedTitle: stringstoppedBody: stringstart: string@@ -590,6 +593,9 @@ const en: BotsMessages = {portalUnsupported: 'Not available on this host',portalUnavailable: 'Update the bot\u2019s Hermes to use Screen',unavailableTitle: 'Screen needs a newer Hermes',+ autoOpenMenu: 'Open Screen when the bot uses it',+ autoOpenOnToast: name => `${name}’s Screen opens when it starts using its desktop`,+ autoOpenOffToast: name => `${name}’s Screen stays closed until you open it`,stoppedTitle: 'Screen is off',stoppedBody: 'Start this bot\u2019s desktop to watch what it does and take over when it needs you.',start: 'Start screen',@@ -885,6 +891,9 @@ const ja: BotsMessages = {portalUnsupported: 'このホストでは利用できません',portalUnavailable: 'Screen を使うにはボットの Hermes を更新してください',unavailableTitle: 'Screen には新しい Hermes が必要です',+ autoOpenMenu: 'ボットが画面を使い始めたら Screen を開く',+ autoOpenOnToast: name => `${name} がデスクトップを使い始めると Screen が開きます`,+ autoOpenOffToast: name => `${name} の Screen は手動で開くまで閉じたままです`,stoppedTitle: '画面はオフです',stoppedBody: 'このボットのデスクトップを起動すると、動作を見守り、必要なときに操作を引き継げます。',start: '画面を起動',@@ -1175,6 +1184,9 @@ const zh: BotsMessages = {portalUnsupported: '此主机不可用',portalUnavailable: '更新机器人的 Hermes 以使用屏幕',unavailableTitle: '屏幕需要更新版的 Hermes',+ autoOpenMenu: '机器人使用屏幕时自动打开',+ autoOpenOnToast: name => `${name} 开始使用桌面时会自动打开屏幕`,+ autoOpenOffToast: name => `${name} 的屏幕将保持关闭,直到你手动打开`,stoppedTitle: '屏幕已关闭',stoppedBody: '启动此机器人的桌面,观看它的操作,并在需要时接管。',start: '启动屏幕',@@ -1465,6 +1477,9 @@ const zhHant: BotsMessages = {portalUnsupported: '此主機不可用',portalUnavailable: '更新機器人的 Hermes 以使用螢幕',unavailableTitle: '螢幕需要較新版的 Hermes',+ autoOpenMenu: '機器人使用螢幕時自動開啟',+ autoOpenOnToast: name => `${name} 開始使用桌面時會自動開啟螢幕`,+ autoOpenOffToast: name => `${name} 的螢幕將保持關閉,直到你手動開啟`,stoppedTitle: '螢幕已關閉',stoppedBody: '啟動此機器人的桌面,觀看它的操作,並在需要時接手。',start: '啟動螢幕',diff --git a/apps/desktop/src/plugins/hermes-bots/plugin.tsx b/apps/desktop/src/plugins/hermes-bots/plugin.tsxindex 8bdaae39357..98fb65b68a3 100644--- a/apps/desktop/src/plugins/hermes-bots/plugin.tsx+++ b/apps/desktop/src/plugins/hermes-bots/plugin.tsx@@ -69,6 +69,7 @@ import {sessionOwnsWorkspace} from './roster-pane'import { botRosterMeta, botWorkspaceOwnerKey, setBotsWorkspaceOwner } from './routing'+import { startScreenAutoRaise } from './screen-autoraise'import { ProfileGroupScreenPortal } from './screen-portal'import { startHideSweepScheduler } from './session-sweep'import { bumpBotOpenGeneration, getBotOpenGeneration, ID, setPluginCtx } from './shared'@@ -107,6 +108,8 @@ export default {// The cross-connection relay rides every gateway socket this Desktop// holds: roster sync + envelope drain/deliver/reply loops.startBotRelay()+ // Opt-in per bot: raise a bot's Screen tab on its first live screen tool call.+ const stopScreenAutoRaise = startScreenAutoRaise()// Disabling the plugin (or a hot reload) must actually stop the clock —// before this, the rAF loop + 1Hz document scan ran until app restart.@@ -114,6 +117,7 @@ export default {ctx.onDispose(disposeLocales)ctx.onDispose(stopFaceClock)ctx.onDispose(stopBotRelay)+ ctx.onDispose(stopScreenAutoRaise)}// @-mention autocomplete: typing "@rese…" in ANY composer offers thediff --git a/apps/desktop/src/plugins/hermes-bots/screen-autoraise.test.ts b/apps/desktop/src/plugins/hermes-bots/screen-autoraise.test.tsnew file mode 100644index 00000000000..d761a70ddb0--- /dev/null+++ b/apps/desktop/src/plugins/hermes-bots/screen-autoraise.test.ts@@ -0,0 +1,82 @@+/**+ * Screen auto-raise contract: a live screen-tool call on an opted-in bot raises+ * its Screen tab once; a manual Close holds through the burst; no opt-in, a+ * foreign profile, or a non-screen tool never raises.+ */+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'++import type { RosterRow } from './types'++const opened: string[] = []+let meta: Record<string, { screenAutoOpen?: boolean }> = {}++vi.mock('@hermes/plugin-sdk', () => ({ host: { onEvent: () => () => undefined } }))+vi.mock('./data', () => ({+ $botMeta: { get: () => meta },+ $lastRoster: { get: () => roster },+ botSelectionKey: (bot: RosterRow) => bot.name+}))+vi.mock('./routing', () => ({+ botRosterMeta: (bot: RosterRow) => meta[bot.name],+ resolveBotConnectionRoute: (bot: RosterRow) => ({+ status: 'resolved',+ route: { connectionId: 'local', mode: 'local', profile: bot.name, targetProfile: bot.name }+ })+}))+vi.mock('./screen-open', () => ({+ openBotScreen: (bot: RosterRow) => {+ opened.push(bot.name)+ },+ screenPaneId: (bot: RosterRow) => `screen:${bot.name}`+}))++const roster = [{ name: 'parker', sourceScoped: true }, { name: 'alfred', sourceScoped: true }] as RosterRow[]++const toolStart = (profile: string, name: string, connectionId?: string) =>+ ({ type: 'tool.start', profile, connectionId, session_id: 's1', payload: { tool_id: 't', name } }) as never++describe('screen auto-raise', () => {+ beforeEach(async () => {+ opened.length = 0+ meta = { parker: { screenAutoOpen: true }, alfred: {} }+ const mod = await import('./screen-autoraise')+ mod.resetScreenAutoRaise()+ })++ afterEach(() => {+ vi.resetModules()+ })++ it('raises once per burst for an opted-in bot, and a Close holds until the burst is over', async () => {+ const { AUTO_RAISE_COOLDOWN_MS, handleScreenToolStart, noteScreenTabClosed, noteScreenTabOpened } = await import(+ './screen-autoraise'+ )++ const t0 = 1_000_000++ expect(handleScreenToolStart(toolStart('parker', 'computer_use'), t0)).toBe(true)+ noteScreenTabOpened(roster[0])+ // The tab is open: further calls in the run never re-front it.+ expect(handleScreenToolStart(toolStart('parker', 'browser_navigate'), t0 + 1_000)).toBe(false)++ // The user closes it mid-run: the very next click of the same run must not reopen it.+ noteScreenTabClosed(roster[0], t0 + 2_000)+ expect(handleScreenToolStart(toolStart('parker', 'computer_use'), t0 + 3_000)).toBe(false)+ expect(handleScreenToolStart(toolStart('parker', 'computer_use'), t0 + AUTO_RAISE_COOLDOWN_MS)).toBe(false)++ // A fresh run after a quiet gap may raise again.+ expect(handleScreenToolStart(toolStart('parker', 'computer_use'), t0 + 2_000 + AUTO_RAISE_COOLDOWN_MS)).toBe(true)+ expect(opened).toEqual(['parker', 'parker'])+ })++ it('never raises without the opt-in, for a non-screen tool, or for a profile no bot owns', async () => {+ const { handleScreenToolStart } = await import('./screen-autoraise')++ expect(handleScreenToolStart(toolStart('alfred', 'computer_use'), 5)).toBe(false)+ expect(handleScreenToolStart(toolStart('parker', 'terminal'), 5)).toBe(false)+ expect(handleScreenToolStart(toolStart('nobody', 'computer_use'), 5)).toBe(false)+ // Same profile name on a different source is a different bot.+ expect(handleScreenToolStart(toolStart('parker', 'computer_use', 'ssh-box'), 5)).toBe(false)+ expect(opened).toEqual([])+ })+})diff --git a/apps/desktop/src/plugins/hermes-bots/screen-autoraise.ts b/apps/desktop/src/plugins/hermes-bots/screen-autoraise.tsnew file mode 100644index 00000000000..a5c85adcdc1--- /dev/null+++ b/apps/desktop/src/plugins/hermes-bots/screen-autoraise.ts@@ -0,0 +1,162 @@+/**+ * Raise a bot's Screen tab the moment the bot starts driving its desktop, so+ * you watch it work instead of finding out afterwards. Opt-in per bot+ * (`BotMeta.screenAutoOpen`, row context menu): the Desktop rule is "offer,+ * don't hijack", and a tab appearing because a background bot touched its+ * screen is a hijack unless the user asked for exactly that.+ *+ * What counts as "started driving": a live `tool.start` for a screen tool+ * (computer_use, the browser tools) on a session the bot owns. Live means+ * arriving on the socket now; replayed history never opens anything — the+ * reconnect replay in `@hermes/shared` re-dispatches parked frames, so a+ * seq-gated ring is not enough and the wake is also rate-limited per bot.+ *+ * Fencing rules, in order:+ * - the tab is already open → nothing (never re-front over what you moved to)+ * - a manual Close holds until the NEXT fresh screen use, never re-raises+ * mid-burst: a user closing the tab while the bot clicks around has said+ * "not now", and the next tool.start of the same run must respect that+ * - one wake per bot per 30 s+ * Opening never moves keyboard focus: `openBotScreen` reveals the pane, and the+ * viewer only grabs keys when the human takes over.+ */++import { host } from '@hermes/plugin-sdk'+import type { RpcEvent } from '@hermes/plugin-sdk'++import { $botMeta, $lastRoster, botSelectionKey } from './data'+import { botRosterMeta, resolveBotConnectionRoute } from './routing'+import { openBotScreen, screenPaneId } from './screen-open'+import type { RosterRow } from './types'++/** Tools whose first call means the bot is now using its screen. Browser tools count:+ * on a Bot Screen host the headed Chromium is on that desktop. */+const SCREEN_TOOL_PREFIXES = ['computer_use', 'browser_']++export const AUTO_RAISE_COOLDOWN_MS = 30_000++/** Per-bot wake bookkeeping, keyed by `botSelectionKey`. */+interface RaiseState {+ lastRaisedAt: number+ /** Set when the user closed the tab; cleared by a quiet gap, so the next burst may raise again. */+ closedAt: number+}++const raiseState = new Map<string, RaiseState>()+/** Bot keys whose Screen tab is open right now (mirrors `screen-open`'s tab map without coupling to it). */+const openTabs = new Set<string>()++export function isScreenTool(name: string | undefined): boolean {+ return typeof name === 'string' && SCREEN_TOOL_PREFIXES.some(prefix => name.startsWith(prefix))+}++/** Resolve the roster row that owns an event: same source connection (a local/legacy+ * event carries no tag and matches a `local` route) and the event's profile. */+export function botForEvent(roster: RosterRow[], event: Pick<RpcEvent, 'connectionId' | 'profile'>): RosterRow | null {+ const profile = (event.profile ?? '').trim()++ if (!profile) {+ return null+ }++ for (const bot of roster) {+ const resolved = resolveBotConnectionRoute(bot)++ if (resolved.status === 'owner_removed') {+ continue+ }++ const route = resolved.route+ const botProfile = route ? route.targetProfile || route.profile : bot.name+ const expected = route?.connectionId ?? null+ const actual = event.connectionId ?? null+ const sameSource = expected === actual || (expected === 'local' && actual === null) || (expected === null && actual === 'local')++ if (sameSource && botProfile === profile) {+ return bot+ }+ }++ return null+}++/** Pure decision: should a live screen tool.start for `bot` raise its tab now? */+export function shouldAutoRaise(+ bot: RosterRow,+ now: number,+ state: RaiseState | undefined,+ tabOpen: boolean,+ meta = $botMeta.get()+): boolean {+ if (!botRosterMeta(bot, meta)?.screenAutoOpen || tabOpen) {+ return false+ }++ if (!state) {+ return true+ }++ // A Close during a burst holds through the burst: the gap must be at least one cooldown.+ if (state.closedAt && now - state.closedAt < AUTO_RAISE_COOLDOWN_MS) {+ return false+ }++ return now - state.lastRaisedAt >= AUTO_RAISE_COOLDOWN_MS+}++export function noteScreenTabOpened(bot: RosterRow): void {+ openTabs.add(botSelectionKey(bot))+}++export function noteScreenTabClosed(bot: RosterRow, now = Date.now()): void {+ const key = botSelectionKey(bot)++ openTabs.delete(key)+ raiseState.set(key, { lastRaisedAt: raiseState.get(key)?.lastRaisedAt ?? 0, closedAt: now })+}++export function handleScreenToolStart(event: RpcEvent, now = Date.now()): boolean {+ const payload = event.payload as { name?: string } | undefined++ if (!isScreenTool(payload?.name)) {+ return false+ }++ const bot = botForEvent($lastRoster.get(), event)++ if (!bot) {+ return false+ }++ const key = botSelectionKey(bot)++ if (!shouldAutoRaise(bot, now, raiseState.get(key), openTabs.has(key))) {+ return false+ }++ raiseState.set(key, { lastRaisedAt: now, closedAt: 0 })+ openBotScreen(bot, botRosterMeta(bot, $botMeta.get()) ?? null)++ return true+}++/** Wire the listener; returns the disposer. Feature-detected on older shells. */+export function startScreenAutoRaise(): () => void {+ if (typeof host.onEvent !== 'function') {+ return () => undefined+ }++ return host.onEvent('tool.start', (event: RpcEvent) => {+ handleScreenToolStart(event)+ })+}++/** Test seam. */+export function resetScreenAutoRaise(): void {+ raiseState.clear()+ openTabs.clear()+}++export function screenTabPaneId(bot: RosterRow): string {+ return screenPaneId(bot)+}diff --git a/apps/desktop/src/plugins/hermes-bots/screen-open.tsx b/apps/desktop/src/plugins/hermes-bots/screen-open.tsxindex 9d05539c4d8..69e237e9901 100644--- a/apps/desktop/src/plugins/hermes-bots/screen-open.tsx+++ b/apps/desktop/src/plugins/hermes-bots/screen-open.tsx@@ -8,6 +8,7 @@ import { host } from '@hermes/plugin-sdk'import { botSelectionKey } from './data'import { botsText } from './i18n'import { displayName } from './labels'+import { noteScreenTabClosed, noteScreenTabOpened } from './screen-autoraise'import { BotScreenPane } from './screen-pane'import { ID } from './shared'import type { BotMeta, RosterRow } from './types'@@ -39,8 +40,10 @@ export function openBotScreen(bot: RosterRow, meta?: BotMeta | null): void {render: () => <BotScreenPane bot={bot} />,onClose: () => {openTabs.delete(key)+ noteScreenTabClosed(bot)}})openTabs.set(key, close)+ noteScreenTabOpened(bot)}diff --git a/apps/desktop/src/plugins/hermes-bots/types.ts b/apps/desktop/src/plugins/hermes-bots/types.tsindex c5eff2606d9..5d787d1edf7 100644--- a/apps/desktop/src/plugins/hermes-bots/types.ts+++ b/apps/desktop/src/plugins/hermes-bots/types.ts@@ -80,6 +80,8 @@ export interface BotMeta {/** Legacy single-group scalar, projected alongside `groups`. */group?: null | stringpinned?: boolean+ /** Raise this bot's Screen tab when it starts driving its desktop (`screen-autoraise.ts`). Opt-in per bot. */+ screenAutoOpen?: booleanshape?: stringtitle?: string/** Creation timestamp in ms. Deliberately not copied when duplicating a bot. */diff --git a/apps/desktop/src/sdk/index.ts b/apps/desktop/src/sdk/index.tsindex c924f28b787..ac49ded0680 100644--- a/apps/desktop/src/sdk/index.ts+++ b/apps/desktop/src/sdk/index.ts@@ -1672,6 +1672,7 @@ export { ColorSwatches } from '@/components/ui/color-swatches'export { ConfirmDialog } from '@/components/ui/confirm-dialog'export {ContextMenu,+ ContextMenuCheckboxItem,ContextMenuContent,ContextMenuItem,ContextMenuSeparator,diff --git a/website/docs/user-guide/features/bot-screen.md b/website/docs/user-guide/features/bot-screen.mdindex 3a08307ed85..52c7962a667 100644--- a/website/docs/user-guide/features/bot-screen.md+++ b/website/docs/user-guide/features/bot-screen.md@@ -111,7 +111,13 @@ Every bot's computer is one click away in three places of Hermes Desktop:desktop (refreshed every few seconds while the pane is visible) with who holdscontrol; click the picture to expand into live access. While the screen is offor not installed the same box says so and offers Start / Install.-- **Bots → right-click a bot → Open Screen**.+- **Bots → right-click a bot → Open Screen**. The same menu has **Open Screen+ when the bot uses it**: with it checked, the Screen tab comes forward on the+ bot's first `computer_use` or browser call of a run, so you watch it work+ instead of finding out afterwards. Off by default, per bot. It raises the+ tab without taking your keyboard focus, never fires for replayed history,+ at most once every 30 seconds, and if you close the tab mid-run it stays+ closed until the bot's next run.- **Sessions sidebar**, grouped by gateway / profile: the same **Screen** boxsits under each profile's header, so a profile's machine is reachable fromits conversations too.