The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(bot-screen): live desktop preview as the hero of a bot's Scheduled Jobs pane
teknium1d357efea7bd0
diff --git a/apps/desktop/src/plugins/hermes-bots/cron.tsx b/apps/desktop/src/plugins/hermes-bots/cron.tsxindex 74ec2deb2ae..c786f276d8f 100644--- a/apps/desktop/src/plugins/hermes-bots/cron.tsx+++ b/apps/desktop/src/plugins/hermes-bots/cron.tsx@@ -45,7 +45,7 @@ import { labeled } from './dialog-parts'import { botsText, useBots } from './i18n'import { displayName } from './labels'import { botConnectionRoute, botRosterMeta, requestForBot } from './routing'-import { ScreenPortal } from './screen-portal'+import { ScreenHero } from './screen-hero'import { ID } from './shared'import type { BotMeta, RosterRow, RoutineJob } from './types'@@ -1241,6 +1241,9 @@ export function RoutinesPane() {return (<div className="flex h-full flex-col">+ <div className="px-3 pt-3">+ <ScreenHero bot={owner} meta={meta} />+ </div><div className="flex items-center gap-2 px-3 pt-3 pb-2"><BotFace color={avatarColor(color, bot)} image={image} name={bot} shape={shape} size={22} /><div className="min-w-0 flex-1">@@ -1266,9 +1269,6 @@ export function RoutinesPane() {</Tip></div><div className="mx-3 border-t border-(--ui-stroke-secondary)" />- <div className="px-3 pt-2">- <ScreenPortal bot={owner} meta={meta} />- </div>{staleNotice ? (<div className="mx-3 mt-2 rounded-md bg-(--chrome-action-hover) px-2 py-1.5 text-[0.6875rem] text-(--ui-text-tertiary)">{staleNotice}diff --git a/apps/desktop/src/plugins/hermes-bots/i18n.ts b/apps/desktop/src/plugins/hermes-bots/i18n.tsindex 43550dd1ddc..5eef7a47735 100644--- a/apps/desktop/src/plugins/hermes-bots/i18n.ts+++ b/apps/desktop/src/plugins/hermes-bots/i18n.ts@@ -239,6 +239,12 @@ type BotsMessages = {noPackageManager: stringportalTitle: stringportalOpen: string+ heroStopped: string+ heroNotInstalled: string+ heroConnecting: string+ heroOpenLive: string+ heroInstall: string+ heroStart: stringportalWatching: stringportalYouControl: stringportalOtherControls: string@@ -499,6 +505,12 @@ const en: BotsMessages = {noPackageManager: 'No supported package manager (apt, dnf, pacman) was found on the gateway host.',portalTitle: 'Screen',portalOpen: 'Open',+ heroStopped: 'Screen is off',+ heroNotInstalled: 'Not installed on this host',+ heroConnecting: 'Checking the screen…',+ heroOpenLive: 'Open live',+ heroInstall: 'Install',+ heroStart: 'Start',portalWatching: 'Live · bot in control',portalYouControl: 'Live · you are in control',portalOtherControls: 'Live · another viewer in control',@@ -754,6 +766,12 @@ const ja: BotsMessages = {noPackageManager: 'ゲートウェイホストに対応するパッケージマネージャー (apt, dnf, pacman) が見つかりません。',portalTitle: 'スクリーン',portalOpen: '開く',+ heroStopped: '画面は停止中',+ heroNotInstalled: 'このホストには未インストール',+ heroConnecting: '画面を確認中…',+ heroOpenLive: 'ライブで開く',+ heroInstall: 'インストール',+ heroStart: '開始',portalWatching: 'ライブ · ボットが操作中',portalYouControl: 'ライブ · あなたが操作中',portalOtherControls: 'ライブ · 別のビューアーが操作中',@@ -1004,6 +1022,12 @@ const zh: BotsMessages = {noPackageManager: '网关主机上未找到受支持的包管理器(apt、dnf、pacman)。',portalTitle: '屏幕',portalOpen: '打开',+ heroStopped: '屏幕已关闭',+ heroNotInstalled: '此主机未安装',+ heroConnecting: '正在检查屏幕…',+ heroOpenLive: '实时打开',+ heroInstall: '安装',+ heroStart: '启动',portalWatching: '直播 · 机器人控制中',portalYouControl: '直播 · 你在控制',portalOtherControls: '直播 · 其他查看者控制中',@@ -1254,6 +1278,12 @@ const zhHant: BotsMessages = {noPackageManager: '閘道主機上找不到受支援的套件管理器(apt、dnf、pacman)。',portalTitle: '螢幕',portalOpen: '開啟',+ heroStopped: '螢幕已關閉',+ heroNotInstalled: '此主機未安裝',+ heroConnecting: '正在檢查螢幕…',+ heroOpenLive: '即時開啟',+ heroInstall: '安裝',+ heroStart: '啟動',portalWatching: '直播 · 機器人控制中',portalYouControl: '直播 · 您在控制',portalOtherControls: '直播 · 其他檢視者控制中',diff --git a/apps/desktop/src/plugins/hermes-bots/screen-hero.tsx b/apps/desktop/src/plugins/hermes-bots/screen-hero.tsxnew file mode 100644index 00000000000..1154668df7f--- /dev/null+++ b/apps/desktop/src/plugins/hermes-bots/screen-hero.tsx@@ -0,0 +1,147 @@+/**+ * Screen hero — the big preview of a bot's computer at the top of its pane.+ *+ * Shows a live thumbnail (one `display.thumbnail` JPEG every few seconds while+ * the screen runs and the hero is on screen), or an honest placeholder for+ * stopped / not installed / unsupported. Clicking it opens the full Screen pane+ * where the user can take over.+ */++import { Codicon } from '@hermes/plugin-sdk'+import { useEffect, useRef, useState } from 'react'++import { useBots } from './i18n'+import { displayRequest } from './screen-connection'+import { openBotScreen } from './screen-open'+import { type PortalTone, useScreenPortalState } from './screen-portal'+import type { BotMeta, RosterRow } from './types'++const REFRESH_MS = 4000++function useLiveThumbnail(bot: RosterRow, running: boolean) {+ const [dataUrl, setDataUrl] = useState<string | null>(null)+ const boxRef = useRef<HTMLButtonElement | null>(null)++ useEffect(() => {+ if (!running) {+ setDataUrl(null)++ return+ }++ let cancelled = false+ let timer: number | null = null+ let visible = true++ const observer =+ typeof IntersectionObserver === 'undefined'+ ? null+ : new IntersectionObserver(entries => {+ visible = entries.some(entry => entry.isIntersecting)+ })++ if (observer && boxRef.current) {+ observer.observe(boxRef.current)+ }++ const tick = () => {+ if (cancelled) {+ return+ }++ if (!visible || document.hidden) {+ timer = window.setTimeout(tick, REFRESH_MS)++ return+ }++ void displayRequest<{ data_url: string | null }>(bot, 'display.thumbnail')+ .then(result => {+ if (!cancelled) {+ setDataUrl(result.data_url)+ }+ })+ .catch(() => {+ /* transient: the next tick retries; the last good frame stays up */+ })+ .finally(() => {+ if (!cancelled) {+ timer = window.setTimeout(tick, REFRESH_MS)+ }+ })+ }++ tick()++ return () => {+ cancelled = true+ observer?.disconnect()++ if (timer !== null) {+ window.clearTimeout(timer)+ }+ }+ }, [bot, running])++ return { dataUrl, boxRef }+}++const TONE_RING: Partial<Record<PortalTone, string>> = {+ human: 'ring-2 ring-red-500/80',+ other: 'ring-2 ring-amber-500/70'+}++export function ScreenHero({ bot, meta }: { bot: RosterRow; meta?: BotMeta | null }) {+ const t = useBots()+ const { tone } = useScreenPortalState(bot)+ const running = tone === 'live' || tone === 'human' || tone === 'other'+ const { dataUrl, boxRef } = useLiveThumbnail(bot, running)++ if (tone === 'unsupported') {+ return null+ }++ const caption = {+ live: t.screen.portalWatching,+ human: t.screen.portalYouControl,+ other: t.screen.portalOtherControls,+ off: t.screen.heroStopped,+ missing: t.screen.heroNotInstalled,+ unsupported: t.screen.portalUnsupported,+ unknown: t.screen.heroConnecting+ }[tone]++ const cta = running ? t.screen.heroOpenLive : tone === 'missing' ? t.screen.heroInstall : tone === 'off' ? t.screen.heroStart : ''++ return (+ <button+ aria-label={`${t.screen.portalTitle}: ${caption}`}+ className={`group relative block w-full overflow-hidden rounded-lg border border-(--ui-stroke-secondary) bg-black text-left ${TONE_RING[tone] ?? ''}`}+ onClick={() => openBotScreen(bot, meta ?? null)}+ ref={boxRef}+ style={{ aspectRatio: '16 / 10' }}+ type="button"+ >+ {dataUrl ? (+ <img alt="" className="absolute inset-0 size-full object-cover" draggable={false} src={dataUrl} />+ ) : (+ <span className="absolute inset-0 grid place-items-center bg-[radial-gradient(ellipse_at_center,rgba(255,255,255,0.08),transparent_70%)]">+ <Codicon className="text-[2.25rem] text-white/30" name={running ? 'loading' : tone === 'missing' ? 'cloud-download' : 'vm'} />+ </span>+ )}++ <span className="absolute inset-x-0 bottom-0 flex items-center gap-2 bg-gradient-to-t from-black/85 to-black/0 px-2.5 pb-2 pt-6 text-white">+ <span className={`size-2 shrink-0 rounded-full ${running ? (tone === 'live' ? 'bg-emerald-400' : tone === 'human' ? 'bg-red-400' : 'bg-amber-400') : 'bg-white/40'}`} />+ <span className="min-w-0 flex-1">+ <span className="block truncate text-xs font-medium">{t.screen.portalTitle}</span>+ <span className="block truncate text-[0.65rem] text-white/70">{caption}</span>+ </span>+ {cta ? (+ <span className="flex shrink-0 items-center gap-1 rounded-md bg-white/15 px-2 py-1 text-[0.65rem] font-medium backdrop-blur-sm transition-colors group-hover:bg-white/25">+ {cta} <Codicon name="arrow-right" />+ </span>+ ) : null}+ </span>+ </button>+ )+}diff --git a/tests/tools/test_bot_desktop_thumbnail.py b/tests/tools/test_bot_desktop_thumbnail.pynew file mode 100644index 00000000000..97865c3ce72--- /dev/null+++ b/tests/tools/test_bot_desktop_thumbnail.py@@ -0,0 +1,14 @@+"""Bot Desktop thumbnail: a stopped screen yields no frame and never touches X."""++from __future__ import annotations++import sys++from tools.bot_desktop import runtime, thumbnail+++def test_no_running_screen_returns_none_without_grabbing(monkeypatch):+ monkeypatch.setattr(runtime, "published_env", lambda: {"DISPLAY": ":99"})+ monkeypatch.setattr(runtime, "_launcher_pid", lambda: None)+ monkeypatch.setitem(sys.modules, "PIL.ImageGrab", None) # an import would now fail loudly+ assert thumbnail.thumbnail_data_url() is Nonediff --git a/tools/bot_desktop/thumbnail.py b/tools/bot_desktop/thumbnail.pynew file mode 100644index 00000000000..ee41e6ffbc9--- /dev/null+++ b/tools/bot_desktop/thumbnail.py@@ -0,0 +1,41 @@+"""Thumbnail of a bot's screen: one JPEG grab of the profile's Xvnc display.++Feeds the Screen hero in Hermes Desktop (the big preview at the top of a bot's pane). Read-only:+it never touches the lease, so a human in control is not disturbed and the bot is not blocked.+"""++from __future__ import annotations++import base64+import io+import os+from typing import Optional++from tools.bot_desktop import runtime++THUMB_MAX = (960, 600)+++def thumbnail_data_url(max_size: tuple[int, int] = THUMB_MAX, quality: int = 72) -> Optional[str]:+ """``data:image/jpeg;base64,...`` of the running screen, or ``None`` when no screen is up."""+ env = runtime.published_env()+ display = env.get("DISPLAY")+ if not display or runtime._launcher_pid() is None:+ return None+ from PIL import ImageGrab # Pillow is a hard dependency; import lazily to keep status calls cheap++ # Xlib reads XAUTHORITY from the process env; the launcher publishes a per-profile cookie file.+ previous = os.environ.get("XAUTHORITY")+ if env.get("XAUTHORITY"):+ os.environ["XAUTHORITY"] = env["XAUTHORITY"]+ try:+ image = ImageGrab.grab(xdisplay=display)+ finally:+ if previous is None:+ os.environ.pop("XAUTHORITY", None)+ else:+ os.environ["XAUTHORITY"] = previous+ image.thumbnail(max_size)+ buf = io.BytesIO()+ image.convert("RGB").save(buf, "JPEG", quality=quality, optimize=True)+ return "data:image/jpeg;base64," + base64.b64encode(buf.getvalue()).decode("ascii")diff --git a/tui_gateway/methods_display.py b/tui_gateway/methods_display.pyindex 7e853e0f7e1..043b8bc9077 100644--- a/tui_gateway/methods_display.py+++ b/tui_gateway/methods_display.py@@ -56,6 +56,17 @@ def _(rid, params: dict) -> dict:return _err(rid, _DISPLAY_ERR, str(e))+@method("display.thumbnail")+@_profile_scoped+def _(rid, params: dict) -> dict:+ """One JPEG grab of the bot's screen (``data_url``: null while stopped). Read-only: no lease change."""+ try:+ from tools.bot_desktop.thumbnail import thumbnail_data_url+ return _ok(rid, {"data_url": thumbnail_data_url()})+ except Exception as e:+ return _err(rid, _DISPLAY_ERR, str(e))++@method("display.start")@_profile_scopeddef _(rid, params: dict) -> dict:diff --git a/website/docs/user-guide/features/bot-screen.md b/website/docs/user-guide/features/bot-screen.mdindex 37c2db1a72d..796e0179c93 100644--- a/website/docs/user-guide/features/bot-screen.md+++ b/website/docs/user-guide/features/bot-screen.md@@ -45,9 +45,11 @@ hosted-agent products).Every bot's computer is one click away in three places of Hermes Desktop:-- **Bots → a bot → Scheduled Jobs**: the **Screen** box at the top of the pane- (above the routines) shows whether the screen is running and who holds- control; click it to open.+- **Bots → a bot → Scheduled Jobs**: the bot's screen is the hero at the very+ top of the pane, above the title and the routines: a live preview of the+ desktop (refreshed every few seconds while the pane is visible) with who holds+ control; click the picture to expand into live access. While the screen is off+ or not installed the same box says so and offers Start / Install.- **Bots → right-click a bot → Open Screen**.- **Sessions sidebar**, grouped by gateway / profile: the same **Screen** boxsits under each profile's header, so a profile's machine is reachable from