From 2158e02cc5e38307c216a4d175c4e09ee431bf5e Mon Sep 17 00:00:00 2001 From: ghgoodreau Date: Fri, 6 Nov 2026 12:32:29 -0600 Subject: [PATCH 001/207] feat(desktop): promote redesigned agent workspace with classic recovery --- apps/desktop/README.md | 14 +- apps/desktop/e2e/core/harness.ts | 9 +- apps/desktop/e2e/core/portal-artwork.spec.ts | 62 ++ apps/desktop/src/api/sessions.ts | 6 +- apps/desktop/src/app/agent-settings/copy.ts | 317 +++++++++ .../src/app/agent-settings/data.test.ts | 32 + apps/desktop/src/app/agent-settings/data.ts | 49 ++ .../src/app/agent-settings/directory.test.tsx | 42 ++ .../src/app/agent-settings/directory.tsx | 80 +++ .../src/app/agent-settings/entry.test.tsx | 35 + apps/desktop/src/app/agent-settings/entry.tsx | 30 + apps/desktop/src/app/agent-settings/index.tsx | 361 +++++++++++ .../agent-settings/routine-dialog.test.tsx | 90 +++ .../src/app/agent-settings/routine-dialog.tsx | 134 ++++ .../src/app/agent-settings/scope.test.tsx | 63 ++ apps/desktop/src/app/agents/index.tsx | 2 +- apps/desktop/src/app/artifacts/index.tsx | 14 +- .../src/app/artifacts/remote-open.test.tsx | 132 ++-- .../desktop/src/app/artifacts/search.test.tsx | 39 ++ .../catalog/catalog-discovery.css | 21 + .../src/app/capabilities/index.test.tsx | 8 +- apps/desktop/src/app/capabilities/index.tsx | 10 +- .../app/capabilities/ui/capability-search.css | 17 + .../ui/capability-search.test.tsx | 39 ++ .../app/capabilities/ui/capability-search.tsx | 36 +- .../src/app/chat/compact-tab-menu.test.tsx | 4 + .../src/app/chat/composer/chat-bar-parts.tsx | 11 + .../hooks/use-composer-metrics.test.tsx | 29 +- .../composer/hooks/use-composer-metrics.ts | 6 +- apps/desktop/src/app/chat/composer/index.tsx | 5 +- apps/desktop/src/app/chat/index.tsx | 20 +- apps/desktop/src/app/chat/landing.css | 33 + apps/desktop/src/app/chat/landing.test.tsx | 30 + apps/desktop/src/app/chat/landing.tsx | 13 + .../app/chat/preview-tile-live-body.test.tsx | 7 +- .../chat/right-rail/preview-browser-bar.tsx | 161 +++-- .../app/chat/right-rail/preview-pane.test.tsx | 19 +- .../src/app/chat/right-rail/preview-pane.tsx | 6 +- .../src/app/chat/sidebar/ia-metrics.test.tsx | 131 ++++ apps/desktop/src/app/chat/sidebar/index.tsx | 47 +- .../sidebar/portal/portal-pinned-empty.tsx | 27 + .../chat/sidebar/portal/portal-sidebar.css | 278 ++++++++ .../chat/sidebar/portal/portal-sidebar.tsx | 131 ++++ .../sidebar/search-result-to-session.test.ts | 2 +- .../chat/sidebar/search-result-to-session.ts | 39 ++ .../chat/sidebar/session-actions-menu.test.ts | 14 + .../sidebar/session-actions-menu.test.tsx | 13 + .../app/chat/sidebar/session-actions-menu.tsx | 76 ++- .../chat/sidebar/session-row-actions.test.tsx | 6 +- .../src/app/chat/sidebar/session-row.test.tsx | 6 +- .../src/app/chat/sidebar/sessions-section.tsx | 8 +- .../chat/sidebar/simplified-agent-list.tsx | 223 +++++++ .../sidebar/simplified-agent-sidebar.test.tsx | 609 ++++++++++++++++++ .../sidebar/simplified-bot-chat-row.test.tsx | 90 +++ .../chat/sidebar/simplified-bot-chat-row.tsx | 65 ++ .../sidebar/simplified-gateway-header.tsx | 92 +++ .../sidebar/simplified-global-nav.test.tsx | 87 +++ .../chat/sidebar/simplified-global-nav.tsx | 137 ++++ .../sidebar/simplified-new-session-copy.ts | 56 ++ .../sidebar/simplified-new-session-model.ts | 48 ++ .../sidebar/simplified-new-session.test.tsx | 244 +++++++ .../chat/sidebar/simplified-new-session.tsx | 234 +++++++ .../sidebar/simplified-pinned-sessions.tsx | 46 ++ .../sidebar/simplified-plugin-pages.test.tsx | 166 +++++ .../sidebar/simplified-session-identity.ts | 6 + .../chat/sidebar/simplified-session-list.tsx | 203 ++++++ .../chat/sidebar/simplified-session-model.ts | 55 ++ .../chat/sidebar/simplified-settings-menu.tsx | 189 ++++++ .../chat/sidebar/strip-fts-markers.test.ts | 2 +- .../src/app/chat/sidebar/use-agent-sidebar.ts | 174 +++++ .../chat/sidebar/use-ia-navigation-metrics.ts | 91 +++ .../app/chat/sidebar/use-ia-search-metrics.ts | 44 ++ .../app/chat/sidebar/use-simplified-agents.ts | 107 +++ .../use-simplified-pin-writes.test.tsx | 218 +++++++ .../chat/sidebar/use-simplified-pin-writes.ts | 212 ++++++ .../sidebar/use-simplified-plugin-pages.tsx | 42 ++ .../use-simplified-session-search.test.tsx | 65 ++ .../sidebar/use-simplified-session-search.ts | 78 +++ .../desktop/src/app/command-center/header.tsx | 52 ++ apps/desktop/src/app/command-center/index.tsx | 51 +- .../app/command-center/open-session.test.tsx | 15 +- apps/desktop/src/app/contrib/controller.tsx | 66 +- .../src/app/contrib/developer-rail.test.tsx | 172 +++++ .../src/app/contrib/developer-rail.tsx | 96 +++ .../app/contrib/hooks/use-desktop-metrics.ts | 2 + .../src/app/contrib/main-window-overlays.tsx | 42 ++ .../simplified-navigation-surface.test.tsx | 114 ++++ .../contrib/simplified-navigation-surface.tsx | 41 ++ .../app/contrib/surfaces.app-routes.test.tsx | 2 + .../app/contrib/surfaces.late-routes.test.tsx | 2 + .../desktop/src/app/contrib/surfaces.test.tsx | 2 + apps/desktop/src/app/contrib/surfaces.tsx | 10 +- apps/desktop/src/app/contrib/types.ts | 3 +- apps/desktop/src/app/contrib/wiring.tsx | 71 +- .../contrib/workspace-page-header.test.tsx | 17 +- apps/desktop/src/app/cron/index.test.tsx | 16 +- apps/desktop/src/app/cron/index.tsx | 13 +- apps/desktop/src/app/floating-hud.ts | 2 +- .../app/hooks/use-keybinds-browser.test.tsx | 23 + apps/desktop/src/app/hooks/use-keybinds.ts | 2 + apps/desktop/src/app/master-detail.tsx | 2 +- apps/desktop/src/app/messaging/index.tsx | 2 +- .../overlay-breadcrumb-header.test.tsx | 43 ++ .../overlays/overlay-breadcrumb-header.tsx | 78 ++- .../src/app/overlays/overlay-split-layout.tsx | 6 +- .../src/app/overlays/overlay-view.test.tsx | 66 ++ .../desktop/src/app/overlays/overlay-view.tsx | 68 +- .../desktop/src/app/overlays/page-toolbar.tsx | 28 + apps/desktop/src/app/overlays/panel.css | 49 ++ apps/desktop/src/app/overlays/panel.test.tsx | 47 +- apps/desktop/src/app/overlays/panel.tsx | 35 +- apps/desktop/src/app/page-search-shell.css | 11 + .../src/app/page-search-shell.test.tsx | 87 +++ apps/desktop/src/app/page-search-shell.tsx | 148 ++++- apps/desktop/src/app/profiles/index.test.tsx | 7 +- apps/desktop/src/app/profiles/index.tsx | 19 +- .../app/redesign/composer-surface-backing.tsx | 23 + .../src/app/redesign/portal-artwork.css | 20 + .../src/app/redesign/portal-chrome.test.tsx | 123 ++++ .../src/app/redesign/portal-composer-edge.css | 75 +++ .../redesign/portal-conversation-header.tsx | 93 +++ .../src/app/redesign/portal-status-menu.tsx | 33 + .../app/redesign/portal-zone-header.test.tsx | 62 ++ .../app/redesign/use-portal-redesign.test.tsx | 51 ++ .../src/app/redesign/use-portal-redesign.ts | 8 + .../src/app/right-sidebar/review/index.tsx | 2 +- .../src/app/session-import/index.test.tsx | 17 + apps/desktop/src/app/session-import/index.tsx | 20 +- .../src/app/session-import/session-import.css | 17 + .../hooks/use-session-actions/index.ts | 28 +- .../remove-archived-session.test.tsx | 8 + .../session/hooks/use-session-list-actions.ts | 3 + .../src/app/settings/appearance-settings.tsx | 36 +- .../src/app/settings/config-settings.test.tsx | 59 +- .../src/app/settings/config-settings.tsx | 2 +- apps/desktop/src/app/settings/index.tsx | 5 +- .../app/settings/interface-mode-settings.tsx | 53 ++ .../app/settings/redesign-navigation.test.ts | 64 ++ .../src/app/settings/redesign-navigation.ts | 63 ++ .../src/app/settings/settings-manifest.ts | 5 + .../simplified-agent-feedback.test.tsx | 66 ++ .../settings/simplified-agent-feedback.tsx | 47 ++ .../src/app/settings/subpage-navigation.tsx | 7 +- .../src/app/shell/gateway-menu-panel.tsx | 20 +- .../app/shell/hooks/use-statusbar-items.tsx | 10 +- .../src/app/shell/statusbar-controls.tsx | 31 +- .../src/app/shell/titlebar-controls.test.tsx | 19 +- .../src/app/shell/titlebar-controls.tsx | 6 + apps/desktop/src/app/starmap/index.tsx | 6 +- apps/desktop/src/app/webhooks/index.tsx | 2 +- apps/desktop/src/assets/chat-landing.webp | Bin 0 -> 346400 bytes apps/desktop/src/assets/portal-wing.svg | 2 + apps/desktop/src/components/model-picker.tsx | 3 + .../src/components/onboarding/flow.tsx | 10 +- .../src/components/onboarding/index.tsx | 80 +-- .../src/components/onboarding/surface.css | 29 + .../components/onboarding/surface.test.tsx | 124 ++++ .../src/components/onboarding/surface.tsx | 82 +++ .../tree/renderer/compact-tab-picker.test.tsx | 4 + .../tree/renderer/keep-alive-panes.test.tsx | 5 +- .../renderer/main-placement-floor.test.tsx | 13 +- .../tree/renderer/narrow-overlays.test.tsx | 10 + .../tree/renderer/narrow-overlays.tsx | 18 +- .../renderer/tab-close-affordance.test.tsx | 7 +- .../pane-shell/tree/renderer/tree-group.tsx | 13 +- .../renderer/tree-split-sash-preview.test.tsx | 13 +- .../desktop/src/components/ui/dialog.test.tsx | 44 ++ apps/desktop/src/components/ui/dialog.tsx | 38 +- .../desktop/src/components/ui/fade-scroll.tsx | 11 +- apps/desktop/src/components/ui/popover.tsx | 2 + .../src/components/ui/search-field.tsx | 5 +- apps/desktop/src/i18n/ar.ts | 2 + apps/desktop/src/i18n/de.ts | 2 + apps/desktop/src/i18n/en.ts | 2 + apps/desktop/src/i18n/es.ts | 2 + apps/desktop/src/i18n/fr.ts | 2 + apps/desktop/src/i18n/ja.ts | 2 + apps/desktop/src/i18n/ru.ts | 2 + apps/desktop/src/i18n/simplified-agents.ts | 205 ++++++ apps/desktop/src/i18n/types.ts | 3 +- apps/desktop/src/i18n/zh-hant.ts | 2 + apps/desktop/src/i18n/zh.ts | 2 + apps/desktop/src/lib/session-export.ts | 4 +- apps/desktop/src/lib/ui-preferences/keys.ts | 1 + .../plugins/hermes-bots/plugin-panes.test.tsx | 22 +- .../src/plugins/hermes-bots/plugin.tsx | 103 +-- apps/desktop/src/sdk/index.ts | 4 +- .../src/store/desktop-metrics-daily.test.ts | 38 ++ .../src/store/desktop-metrics-daily.ts | 31 + .../desktop/src/store/desktop-metrics.test.ts | 29 + apps/desktop/src/store/desktop-metrics.ts | 65 +- apps/desktop/src/store/ia-metrics-contract.ts | 77 +++ apps/desktop/src/store/ia-metrics.test.ts | 65 ++ apps/desktop/src/store/ia-metrics.ts | 41 ++ apps/desktop/src/store/ia-pin-metrics.test.ts | 92 +++ apps/desktop/src/store/ia-pin-metrics.ts | 62 ++ apps/desktop/src/store/preview.ts | 8 +- .../src/store/profile-rail-prefs.test.tsx | 6 +- apps/desktop/src/store/profile.ts | 8 + apps/desktop/src/store/session-pin-sync.ts | 14 + .../src/store/simplified-agent-mode.test.ts | 47 ++ .../src/store/simplified-agent-mode.ts | 27 + .../src/store/simplified-new-session.ts | 10 + .../src/store/titlebar-app-actions.test.ts | 8 + .../desktop/src/store/titlebar-app-actions.ts | 9 +- apps/desktop/src/styles.css | 19 + apps/desktop/src/themes/context.tsx | 2 +- apps/desktop/src/themes/portal.test.ts | 22 + apps/desktop/src/themes/portal.ts | 91 +++ apps/desktop/src/themes/presets.ts | 2 + apps/shared/src/gateway-contract.generated.ts | 2 +- apps/shared/src/gateway-contract.openrpc.json | 3 +- contributors/emails/ghgoodreau@protonmail.com | 2 + .../hermes.shared_metrics.v4.schema.json | 413 +++++++++++- .../observability/shared_metrics_contract.py | 35 +- .../shared_metrics_desktop_contract.py | 56 ++ locales/_keys.desktop.json | 21 + .../hermes_cli/test_shared_metrics_desktop.py | 45 ++ .../contracts/config_free_tier_control.py | 2 +- .../developer-guide/desktop-plugin-sdk.md | 7 + .../developer-guide/relay-shared-metrics.md | 92 ++- website/docs/user-guide/desktop.md | 74 +++ 222 files changed, 10599 insertions(+), 740 deletions(-) create mode 100644 apps/desktop/e2e/core/portal-artwork.spec.ts create mode 100644 apps/desktop/src/app/agent-settings/copy.ts create mode 100644 apps/desktop/src/app/agent-settings/data.test.ts create mode 100644 apps/desktop/src/app/agent-settings/data.ts create mode 100644 apps/desktop/src/app/agent-settings/directory.test.tsx create mode 100644 apps/desktop/src/app/agent-settings/directory.tsx create mode 100644 apps/desktop/src/app/agent-settings/entry.test.tsx create mode 100644 apps/desktop/src/app/agent-settings/entry.tsx create mode 100644 apps/desktop/src/app/agent-settings/index.tsx create mode 100644 apps/desktop/src/app/agent-settings/routine-dialog.test.tsx create mode 100644 apps/desktop/src/app/agent-settings/routine-dialog.tsx create mode 100644 apps/desktop/src/app/agent-settings/scope.test.tsx create mode 100644 apps/desktop/src/app/artifacts/search.test.tsx create mode 100644 apps/desktop/src/app/capabilities/ui/capability-search.css create mode 100644 apps/desktop/src/app/capabilities/ui/capability-search.test.tsx create mode 100644 apps/desktop/src/app/chat/landing.css create mode 100644 apps/desktop/src/app/chat/landing.test.tsx create mode 100644 apps/desktop/src/app/chat/landing.tsx create mode 100644 apps/desktop/src/app/chat/sidebar/ia-metrics.test.tsx create mode 100644 apps/desktop/src/app/chat/sidebar/portal/portal-pinned-empty.tsx create mode 100644 apps/desktop/src/app/chat/sidebar/portal/portal-sidebar.css create mode 100644 apps/desktop/src/app/chat/sidebar/portal/portal-sidebar.tsx create mode 100644 apps/desktop/src/app/chat/sidebar/search-result-to-session.ts create mode 100644 apps/desktop/src/app/chat/sidebar/simplified-agent-list.tsx create mode 100644 apps/desktop/src/app/chat/sidebar/simplified-agent-sidebar.test.tsx create mode 100644 apps/desktop/src/app/chat/sidebar/simplified-bot-chat-row.test.tsx create mode 100644 apps/desktop/src/app/chat/sidebar/simplified-bot-chat-row.tsx create mode 100644 apps/desktop/src/app/chat/sidebar/simplified-gateway-header.tsx create mode 100644 apps/desktop/src/app/chat/sidebar/simplified-global-nav.test.tsx create mode 100644 apps/desktop/src/app/chat/sidebar/simplified-global-nav.tsx create mode 100644 apps/desktop/src/app/chat/sidebar/simplified-new-session-copy.ts create mode 100644 apps/desktop/src/app/chat/sidebar/simplified-new-session-model.ts create mode 100644 apps/desktop/src/app/chat/sidebar/simplified-new-session.test.tsx create mode 100644 apps/desktop/src/app/chat/sidebar/simplified-new-session.tsx create mode 100644 apps/desktop/src/app/chat/sidebar/simplified-pinned-sessions.tsx create mode 100644 apps/desktop/src/app/chat/sidebar/simplified-plugin-pages.test.tsx create mode 100644 apps/desktop/src/app/chat/sidebar/simplified-session-identity.ts create mode 100644 apps/desktop/src/app/chat/sidebar/simplified-session-list.tsx create mode 100644 apps/desktop/src/app/chat/sidebar/simplified-session-model.ts create mode 100644 apps/desktop/src/app/chat/sidebar/simplified-settings-menu.tsx create mode 100644 apps/desktop/src/app/chat/sidebar/use-agent-sidebar.ts create mode 100644 apps/desktop/src/app/chat/sidebar/use-ia-navigation-metrics.ts create mode 100644 apps/desktop/src/app/chat/sidebar/use-ia-search-metrics.ts create mode 100644 apps/desktop/src/app/chat/sidebar/use-simplified-agents.ts create mode 100644 apps/desktop/src/app/chat/sidebar/use-simplified-pin-writes.test.tsx create mode 100644 apps/desktop/src/app/chat/sidebar/use-simplified-pin-writes.ts create mode 100644 apps/desktop/src/app/chat/sidebar/use-simplified-plugin-pages.tsx create mode 100644 apps/desktop/src/app/chat/sidebar/use-simplified-session-search.test.tsx create mode 100644 apps/desktop/src/app/chat/sidebar/use-simplified-session-search.ts create mode 100644 apps/desktop/src/app/command-center/header.tsx create mode 100644 apps/desktop/src/app/contrib/developer-rail.test.tsx create mode 100644 apps/desktop/src/app/contrib/developer-rail.tsx create mode 100644 apps/desktop/src/app/contrib/main-window-overlays.tsx create mode 100644 apps/desktop/src/app/contrib/simplified-navigation-surface.test.tsx create mode 100644 apps/desktop/src/app/contrib/simplified-navigation-surface.tsx create mode 100644 apps/desktop/src/app/overlays/overlay-breadcrumb-header.test.tsx create mode 100644 apps/desktop/src/app/overlays/overlay-view.test.tsx create mode 100644 apps/desktop/src/app/overlays/page-toolbar.tsx create mode 100644 apps/desktop/src/app/overlays/panel.css create mode 100644 apps/desktop/src/app/page-search-shell.css create mode 100644 apps/desktop/src/app/page-search-shell.test.tsx create mode 100644 apps/desktop/src/app/redesign/composer-surface-backing.tsx create mode 100644 apps/desktop/src/app/redesign/portal-artwork.css create mode 100644 apps/desktop/src/app/redesign/portal-chrome.test.tsx create mode 100644 apps/desktop/src/app/redesign/portal-composer-edge.css create mode 100644 apps/desktop/src/app/redesign/portal-conversation-header.tsx create mode 100644 apps/desktop/src/app/redesign/portal-status-menu.tsx create mode 100644 apps/desktop/src/app/redesign/portal-zone-header.test.tsx create mode 100644 apps/desktop/src/app/redesign/use-portal-redesign.test.tsx create mode 100644 apps/desktop/src/app/redesign/use-portal-redesign.ts create mode 100644 apps/desktop/src/app/session-import/session-import.css create mode 100644 apps/desktop/src/app/settings/interface-mode-settings.tsx create mode 100644 apps/desktop/src/app/settings/redesign-navigation.test.ts create mode 100644 apps/desktop/src/app/settings/redesign-navigation.ts create mode 100644 apps/desktop/src/app/settings/simplified-agent-feedback.test.tsx create mode 100644 apps/desktop/src/app/settings/simplified-agent-feedback.tsx create mode 100644 apps/desktop/src/assets/chat-landing.webp create mode 100644 apps/desktop/src/assets/portal-wing.svg create mode 100644 apps/desktop/src/components/onboarding/surface.css create mode 100644 apps/desktop/src/components/onboarding/surface.test.tsx create mode 100644 apps/desktop/src/components/onboarding/surface.tsx create mode 100644 apps/desktop/src/i18n/simplified-agents.ts create mode 100644 apps/desktop/src/store/desktop-metrics-daily.test.ts create mode 100644 apps/desktop/src/store/desktop-metrics-daily.ts create mode 100644 apps/desktop/src/store/ia-metrics-contract.ts create mode 100644 apps/desktop/src/store/ia-metrics.test.ts create mode 100644 apps/desktop/src/store/ia-metrics.ts create mode 100644 apps/desktop/src/store/ia-pin-metrics.test.ts create mode 100644 apps/desktop/src/store/ia-pin-metrics.ts create mode 100644 apps/desktop/src/store/simplified-agent-mode.test.ts create mode 100644 apps/desktop/src/store/simplified-agent-mode.ts create mode 100644 apps/desktop/src/store/simplified-new-session.ts create mode 100644 apps/desktop/src/themes/portal.test.ts create mode 100644 apps/desktop/src/themes/portal.ts create mode 100644 contributors/emails/ghgoodreau@protonmail.com create mode 100644 hermes_cli/observability/shared_metrics_desktop_contract.py diff --git a/apps/desktop/README.md b/apps/desktop/README.md index 796ac383f0c7f..4d1142e77e2fa 100644 --- a/apps/desktop/README.md +++ b/apps/desktop/README.md @@ -86,7 +86,7 @@ Want to hack on the app itself? Install workspace deps from the repo root once, ```bash pnpm install # from repo root — links apps/desktop, web, apps/shared cd apps/desktop -pnpm run dev # Vite renderer + Electron, which boots the Python backend +pnpm run dev # Vite renderer + native Electron, attaching to the canonical gateway ``` Point the app at a specific source checkout, or sandbox it away from your real config: @@ -127,9 +127,10 @@ The app has three boundaries: filesystem/git/window capabilities, and exposes a narrow preload bridge. - **React** owns the Desktop routes, panes, interaction state, and `@assistant-ui/react` transcript. -- **Hermes Agent** runs as a headless `hermes serve` process and exposes the - `tui_gateway` JSON-RPC/WebSocket API. The renderer connects through - [`apps/shared`](../shared/), which is also used by the browser dashboard. +- **Hermes Agent** is owned by the canonical gateway. Local startup runs + `hermes gateway ensure --json` and uses private control tickets for its + JSON-RPC/WebSocket API. Closing Desktop disconnects the viewer, not the gateway. + The renderer connects through [`apps/shared`](../shared/). A bundled artifact uses its payload. If that payload is unusable, the app reports damage rather than installing a second checkout. It does not adopt @@ -138,9 +139,8 @@ an arbitrary `hermes` command on PATH or a system Python installation. Non-bundled builds can use the explicit source-root override, development checkout, completed managed install, or `HERMES_DESKTOP_HERMES` deployment override before offering bootstrap. Candidates are probed before use. -A runtime that predates `serve` falls back to headless -`dashboard --no-open`. This is compatibility for the backend command only and -does not launch or embed the dashboard UI. +The runtime must support the canonical gateway protocol. Missing capabilities +surface as a recovery error, not a parallel `serve` process or relabeled session. The Electron orchestration entry point is `electron/main.ts`; pure resolution, probe, hardening, and platform policies live in focused modules beside it. The diff --git a/apps/desktop/e2e/core/harness.ts b/apps/desktop/e2e/core/harness.ts index 0b65f90c99cd2..de56e5254dc70 100644 --- a/apps/desktop/e2e/core/harness.ts +++ b/apps/desktop/e2e/core/harness.ts @@ -207,9 +207,16 @@ export async function launchCoreApp(env: Record): Promise<{ app: throw new Error("Desktop dist not built: run 'pnpm run build' in apps/desktop first") } + // Select Ozone before launch; an entrypoint relaunch breaks Playwright's process attachment. + const args = [DESKTOP_ROOT, '--disable-gpu', '--no-sandbox'] + + if (process.platform === 'linux' && (env.WAYLAND_DISPLAY || env.XDG_SESSION_TYPE === 'wayland')) { + args.push(`--ozone-platform=${env.ELECTRON_OZONE_PLATFORM_HINT === 'x11' ? 'x11' : 'wayland'}`) + } + const app = await _electron.launch({ executablePath: resolveElectronBinary([DESKTOP_ROOT, REPO_ROOT]), - args: [DESKTOP_ROOT, '--disable-gpu', '--no-sandbox'], + args, env, cwd: DESKTOP_ROOT }) diff --git a/apps/desktop/e2e/core/portal-artwork.spec.ts b/apps/desktop/e2e/core/portal-artwork.spec.ts new file mode 100644 index 0000000000000..99cf9b68e5cbf --- /dev/null +++ b/apps/desktop/e2e/core/portal-artwork.spec.ts @@ -0,0 +1,62 @@ +import { readFileSync } from 'node:fs' + +import { expect, test } from '@playwright/test' + +const css = readFileSync(new URL('../../src/app/redesign/portal-artwork.css', import.meta.url), 'utf8') + .replace('../../assets/portal-wing.svg', '/wing.svg') + +const wing = readFileSync(new URL('../../src/assets/portal-wing.svg', import.meta.url), 'utf8') + +for (const dark of [false, true]) { + for (const glass of [false, true]) { + test(`Portal wing stays faint: ${dark ? 'dark' : 'light'}, ${glass ? 'glass' : 'opaque'}`, async ({ page }) => { + const base = dark ? 16 : 240 + await page.setViewportSize({ width: 600, height: 600 }) + await page.route('https://portal.test/**', route => route.fulfill(route.request().url().endsWith('/wing.svg') + ? { contentType: 'image/svg+xml', body: wing } + : { contentType: 'text/html', body: ` + +
` })) + await page.goto('https://portal.test/') + + for (const nextDark of [dark, !dark]) { + const nextBase = nextDark ? 16 : 240 + await page.evaluate(({ nextDark, nextBase, glass }) => { + document.documentElement.classList.toggle('dark', nextDark) + document.documentElement.style.colorScheme = nextDark ? 'dark' : 'light' + document.documentElement.style.setProperty('--ui-chat-surface-background', glass ? 'transparent' : `rgb(${nextBase} ${nextBase} ${nextBase})`) + document.body.style.backgroundColor = `rgb(${nextBase} ${nextBase} ${nextBase})` + }, { nextDark, nextBase, glass }) + const pixels = await page.screenshot() + + const delta = await page.evaluate(async ({ png, base }) => { + const image = new Image() + image.src = `data:image/png;base64,${png}` + await image.decode() + const canvas = document.createElement('canvas') + canvas.width = image.width + canvas.height = image.height + const context = canvas.getContext('2d')! + context.drawImage(image, 0, 0) + const rgba = context.getImageData(0, 0, image.width, image.height).data + let peak = 0 + + for (let i = 0; i < rgba.length; i++) { + if (i % 4 !== 3) {peak = Math.max(peak, Math.abs(rgba[i]! - base))} + } + + return peak + }, { png: pixels.toString('base64'), base: nextBase }) + + expect(delta, 'The wing should remain visible').toBeGreaterThan(0) + expect(delta, 'Glass must not expose the full-strength artwork').toBeLessThanOrEqual(10) + } + }) + } +} diff --git a/apps/desktop/src/api/sessions.ts b/apps/desktop/src/api/sessions.ts index 2066cb8ac86d5..1246ea992e708 100644 --- a/apps/desktop/src/api/sessions.ts +++ b/apps/desktop/src/api/sessions.ts @@ -398,7 +398,7 @@ export function mutateSessionFenced(key: string, read: () => Promise(id: string, method: 'PATCH' | 'DELETE', payload: Record, profile?: ProfileScope): Promise { +export function mutateSessionHttp(id: string, method: 'PATCH' | 'DELETE', payload: Record, profile?: ProfileScope): Promise { // Null is the window's v1 route (its primary, local or remote); defaulting it to // the registry's 'local' source would pin a remote primary's edits to this machine. const scope = { connectionId: getApiRequestConnection(), ...sessionScoped(profile) } @@ -423,8 +423,8 @@ function mutateSessionHttp(id: string, method: 'PATCH' | 'DELETE', payload: R return mutateSessionFenced(key, () => hermesApi({ ...scope, path: `${path}/mutation-snapshot${suffix}` }), send) } -export function setSessionArchived(id: string, archived: boolean, profile?: string | null): Promise<{ ok: boolean }> { - return mutateSessionHttp(id, 'PATCH', { archived, ...(archived ? { pinned: false } : {}) }, sessionWriteProfile(profile)) +export function setSessionArchived(id: string, archived: boolean, profile?: ProfileScope): Promise<{ ok: boolean }> { + return mutateSessionHttp(id, 'PATCH', { archived, ...(archived ? { pinned: false } : {}) }, profile && typeof profile === 'object' ? profile : sessionWriteProfile(profile)) } export function setSessionPinnedRemote(id: string, pinned: boolean, profile?: string | null): Promise<{ ok: boolean }> { diff --git a/apps/desktop/src/app/agent-settings/copy.ts b/apps/desktop/src/app/agent-settings/copy.ts new file mode 100644 index 0000000000000..84eb39ca70b5d --- /dev/null +++ b/apps/desktop/src/app/agent-settings/copy.ts @@ -0,0 +1,317 @@ +import { isBundledLocale, useI18n } from '@/i18n' +import type { BundledLocale } from '@/i18n/types' + +const copy = { + en: { + back: 'Back to chat', + capabilities: 'Capabilities', + tools: 'Tools', + skills: 'Skills', + connectors: 'Connectors & MCP', + memory: 'Memory', + provider: 'Provider', + connections: 'Connections', + voice: 'Voice', + model: 'Model', + primary: 'Primary', + fallbacks: 'Fallback providers', + routines: 'Routines', + addRoutine: 'Add routine', + approvals: 'Approvals & access', + approvalMode: 'Approval mode', + access: 'Gateway access', + recent: 'Recent sessions', + noSessions: 'No recent sessions', + noRoutines: 'No routines yet', + openAgent: 'Open agent', + unavailable: 'Unavailable', + retry: 'Retry', + name: 'Name', + schedule: 'Schedule', + prompt: 'Prompt', + enabled: 'Enabled', + configured: 'Configured', + connected: 'Connected', + disconnected: 'Disconnected', + scriptRoutine: 'This routine runs a script; its script is preserved.', + localDelivery: 'Results are saved locally.' + }, + fr: { + back: 'Retour au chat', + capabilities: 'Capacités', + tools: 'Outils', + skills: 'Compétences', + connectors: 'Connecteurs et MCP', + memory: 'Mémoire', + provider: 'Fournisseur', + connections: 'Connexions', + voice: 'Voix', + model: 'Modèle', + primary: 'Principal', + fallbacks: 'Fournisseurs de secours', + routines: 'Routines', + addRoutine: 'Ajouter une routine', + approvals: 'Approbations et accès', + approvalMode: 'Mode d’approbation', + access: 'Accès à la passerelle', + recent: 'Sessions récentes', + noSessions: 'Aucune session récente', + noRoutines: 'Aucune routine', + openAgent: 'Ouvrir l’agent', + unavailable: 'Indisponible', + retry: 'Réessayer', + name: 'Nom', + schedule: 'Planification', + prompt: 'Instruction', + enabled: 'Activé', + configured: 'Configuré', + connected: 'Connecté', + disconnected: 'Déconnecté', + scriptRoutine: 'Cette routine exécute un script ; son script est conservé.', + localDelivery: 'Les résultats sont enregistrés localement.' + }, + de: { + back: 'Zurück zum Chat', + capabilities: 'Fähigkeiten', + tools: 'Werkzeuge', + skills: 'Skills', + connectors: 'Konnektoren & MCP', + memory: 'Gedächtnis', + provider: 'Anbieter', + connections: 'Verbindungen', + voice: 'Sprache', + model: 'Modell', + primary: 'Primär', + fallbacks: 'Ersatzanbieter', + routines: 'Routinen', + addRoutine: 'Routine hinzufügen', + approvals: 'Freigaben & Zugriff', + approvalMode: 'Freigabemodus', + access: 'Gateway-Zugriff', + recent: 'Letzte Sitzungen', + noSessions: 'Keine letzten Sitzungen', + noRoutines: 'Noch keine Routinen', + openAgent: 'Agent öffnen', + unavailable: 'Nicht verfügbar', + retry: 'Erneut versuchen', + name: 'Name', + schedule: 'Zeitplan', + prompt: 'Anweisung', + enabled: 'Aktiviert', + configured: 'Konfiguriert', + connected: 'Verbunden', + disconnected: 'Getrennt', + scriptRoutine: 'Diese Routine führt ein Skript aus; das Skript bleibt erhalten.', + localDelivery: 'Ergebnisse werden lokal gespeichert.' + }, + es: { + back: 'Volver al chat', + capabilities: 'Capacidades', + tools: 'Herramientas', + skills: 'Habilidades', + connectors: 'Conectores y MCP', + memory: 'Memoria', + provider: 'Proveedor', + connections: 'Conexiones', + voice: 'Voz', + model: 'Modelo', + primary: 'Principal', + fallbacks: 'Proveedores alternativos', + routines: 'Rutinas', + addRoutine: 'Añadir rutina', + approvals: 'Aprobaciones y acceso', + approvalMode: 'Modo de aprobación', + access: 'Acceso a la puerta de enlace', + recent: 'Sesiones recientes', + noSessions: 'No hay sesiones recientes', + noRoutines: 'No hay rutinas todavía', + openAgent: 'Abrir agente', + unavailable: 'No disponible', + retry: 'Reintentar', + name: 'Nombre', + schedule: 'Programación', + prompt: 'Instrucción', + enabled: 'Activado', + configured: 'Configurado', + connected: 'Conectado', + disconnected: 'Desconectado', + scriptRoutine: 'Esta rutina ejecuta un script; el script se conserva.', + localDelivery: 'Los resultados se guardan localmente.' + }, + ja: { + back: 'チャットに戻る', + capabilities: '機能', + tools: 'ツール', + skills: 'スキル', + connectors: 'コネクターとMCP', + memory: 'メモリ', + provider: 'プロバイダー', + connections: '接続', + voice: '音声', + model: 'モデル', + primary: 'プライマリ', + fallbacks: 'フォールバックプロバイダー', + routines: 'ルーチン', + addRoutine: 'ルーチンを追加', + approvals: '承認とアクセス', + approvalMode: '承認モード', + access: 'ゲートウェイへのアクセス', + recent: '最近のセッション', + noSessions: '最近のセッションはありません', + noRoutines: 'ルーチンはまだありません', + openAgent: 'エージェントを開く', + unavailable: '利用不可', + retry: '再試行', + name: '名前', + schedule: 'スケジュール', + prompt: '指示', + enabled: '有効', + configured: '設定済み', + connected: '接続済み', + disconnected: '未接続', + scriptRoutine: 'このルーチンはスクリプトを実行します。スクリプトは保持されます。', + localDelivery: '結果はローカルに保存されます。' + }, + zh: { + back: '返回聊天', + capabilities: '能力', + tools: '工具', + skills: '技能', + connectors: '连接器与 MCP', + memory: '记忆', + provider: '提供商', + connections: '连接', + voice: '语音', + model: '模型', + primary: '主要模型', + fallbacks: '备用提供商', + routines: '例行任务', + addRoutine: '添加例行任务', + approvals: '审批与访问', + approvalMode: '审批模式', + access: '网关访问', + recent: '最近会话', + noSessions: '暂无最近会话', + noRoutines: '暂无例行任务', + openAgent: '打开智能体', + unavailable: '不可用', + retry: '重试', + name: '名称', + schedule: '计划', + prompt: '指令', + enabled: '已启用', + configured: '已配置', + connected: '已连接', + disconnected: '未连接', + scriptRoutine: '此任务运行脚本,脚本将被保留。', + localDelivery: '结果保存在本地。' + }, + 'zh-hant': { + back: '返回聊天', + capabilities: '能力', + tools: '工具', + skills: '技能', + connectors: '連接器與 MCP', + memory: '記憶', + provider: '提供者', + connections: '連線', + voice: '語音', + model: '模型', + primary: '主要模型', + fallbacks: '備用提供者', + routines: '例行任務', + addRoutine: '新增例行任務', + approvals: '核准與存取', + approvalMode: '核准模式', + access: '閘道存取', + recent: '最近工作階段', + noSessions: '尚無最近工作階段', + noRoutines: '尚無例行任務', + openAgent: '開啟代理', + unavailable: '無法使用', + retry: '重試', + name: '名稱', + schedule: '排程', + prompt: '指令', + enabled: '已啟用', + configured: '已設定', + connected: '已連線', + disconnected: '未連線', + scriptRoutine: '此任務執行指令碼,指令碼將保留。', + localDelivery: '結果儲存在本機。' + }, + ru: { + back: 'Назад к чату', + capabilities: 'Возможности', + tools: 'Инструменты', + skills: 'Навыки', + connectors: 'Коннекторы и MCP', + memory: 'Память', + provider: 'Провайдер', + connections: 'Подключения', + voice: 'Голос', + model: 'Модель', + primary: 'Основная', + fallbacks: 'Резервные провайдеры', + routines: 'Регулярные задачи', + addRoutine: 'Добавить задачу', + approvals: 'Подтверждения и доступ', + approvalMode: 'Режим подтверждения', + access: 'Доступ к шлюзу', + recent: 'Недавние сеансы', + noSessions: 'Нет недавних сеансов', + noRoutines: 'Задач пока нет', + openAgent: 'Открыть агента', + unavailable: 'Недоступно', + retry: 'Повторить', + name: 'Название', + schedule: 'Расписание', + prompt: 'Инструкция', + enabled: 'Включено', + configured: 'Настроено', + connected: 'Подключено', + disconnected: 'Отключено', + scriptRoutine: 'Эта задача запускает скрипт; скрипт будет сохранён.', + localDelivery: 'Результаты сохраняются локально.' + }, + ar: { + back: 'العودة إلى المحادثة', + capabilities: 'الإمكانات', + tools: 'الأدوات', + skills: 'المهارات', + connectors: 'الموصلات وMCP', + memory: 'الذاكرة', + provider: 'المزوّد', + connections: 'الاتصالات', + voice: 'الصوت', + model: 'النموذج', + primary: 'الأساسي', + fallbacks: 'المزوّدون البدلاء', + routines: 'المهام الدورية', + addRoutine: 'إضافة مهمة دورية', + approvals: 'الموافقات والوصول', + approvalMode: 'وضع الموافقة', + access: 'الوصول إلى البوابة', + recent: 'الجلسات الأخيرة', + noSessions: 'لا توجد جلسات حديثة', + noRoutines: 'لا توجد مهام دورية بعد', + openAgent: 'فتح الوكيل', + unavailable: 'غير متاح', + retry: 'إعادة المحاولة', + name: 'الاسم', + schedule: 'الجدول', + prompt: 'التعليمات', + enabled: 'مفعّل', + configured: 'تم الإعداد', + connected: 'متصل', + disconnected: 'غير متصل', + scriptRoutine: 'تشغّل هذه المهمة برنامجًا نصيًا؛ سيُحفظ البرنامج النصي.', + localDelivery: 'تُحفظ النتائج محليًا.' + } +} satisfies Record> + +export function useAgentSettingsCopy() { + const { locale } = useI18n() + + return isBundledLocale(locale) ? copy[locale] : copy.en +} diff --git a/apps/desktop/src/app/agent-settings/data.test.ts b/apps/desktop/src/app/agent-settings/data.test.ts new file mode 100644 index 0000000000000..1dbd7f1ef7cee --- /dev/null +++ b/apps/desktop/src/app/agent-settings/data.test.ts @@ -0,0 +1,32 @@ +import { afterEach, expect, it, vi } from 'vitest' + +import * as client from '@/api/client' + +import { getAgentMessaging, getAgentRecentSessions, getAgentRoutines, saveAgentRoutine } from './data' + +afterEach(() => vi.restoreAllMocks()) + +it('pins every read and routine write to the named gateway and profile', async () => { + const request = vi.spyOn(client, 'hermesApi').mockResolvedValue({}) + + for (const connectionId of ['alpha', 'beta']) { + const owner = { connectionId, profile: 'research' } + await getAgentRoutines(owner) + await getAgentMessaging(owner) + await getAgentRecentSessions(owner) + await saveAgentRoutine(owner, { prompt: 'Review notes', schedule: '0 9 * * *', deliver: 'local' }) + await saveAgentRoutine(owner, { name: 'Updated' }, 'same-job') + } + + expect(request).toHaveBeenCalledTimes(10) + + for (const [index, [call]] of request.mock.calls.entries()) { + expect(call.connectionId).toBe(index < 5 ? 'alpha' : 'beta') + expect(call.profile).toBe('research') + expect(call.path).toContain('profile=research') + } + + expect(request.mock.calls[4][0]).toEqual( + expect.objectContaining({ method: 'PUT', body: { updates: { name: 'Updated' } } }) + ) +}) diff --git a/apps/desktop/src/app/agent-settings/data.ts b/apps/desktop/src/app/agent-settings/data.ts new file mode 100644 index 0000000000000..ea518f1f039e4 --- /dev/null +++ b/apps/desktop/src/app/agent-settings/data.ts @@ -0,0 +1,49 @@ +import { capabilityScoped, hermesApi } from '@/api/client' +import type { + CronJob, + CronJobCreatePayload, + CronJobUpdates, + MessagingPlatformsResponse, + PaginatedSessions +} from '@/hermes' + +export interface AgentSettingsOwner { + connectionId?: string + profile: string +} + +export const agentSettingsKey = (owner: AgentSettingsOwner) => + ['agent-settings', owner.connectionId ?? '', owner.profile] as const + +export function getAgentRoutines(owner: AgentSettingsOwner): Promise { + return hermesApi({ ...capabilityScoped(owner), path: `/api/cron/jobs?profile=${encodeURIComponent(owner.profile)}` }) +} + +export function getAgentMessaging(owner: AgentSettingsOwner): Promise { + return hermesApi({ + ...capabilityScoped(owner), + path: `/api/messaging/platforms?profile=${encodeURIComponent(owner.profile)}` + }) +} + +export function getAgentRecentSessions(owner: AgentSettingsOwner): Promise { + return hermesApi({ + ...capabilityScoped(owner), + path: `/api/profiles/sessions?profile=${encodeURIComponent(owner.profile)}&limit=5&offset=0&archived=exclude&order=recent` + }) +} + +export function saveAgentRoutine( + owner: AgentSettingsOwner, + values: CronJobCreatePayload | CronJobUpdates, + id?: string +): Promise { + const path = id ? `/api/cron/jobs/${encodeURIComponent(id)}` : '/api/cron/jobs' + + return hermesApi({ + ...capabilityScoped(owner), + path: `${path}?profile=${encodeURIComponent(owner.profile)}`, + method: id ? 'PUT' : 'POST', + body: id ? { updates: values } : values + }) +} diff --git a/apps/desktop/src/app/agent-settings/directory.test.tsx b/apps/desktop/src/app/agent-settings/directory.test.tsx new file mode 100644 index 0000000000000..0f57ffd9c17da --- /dev/null +++ b/apps/desktop/src/app/agent-settings/directory.test.tsx @@ -0,0 +1,42 @@ +import { cleanup, fireEvent, render, screen } from '@testing-library/react' +import { MemoryRouter, useLocation } from 'react-router' +import { afterEach, expect, it, vi } from 'vitest' + +import { AgentDirectory } from './directory' + +vi.mock('../chat/sidebar/use-fleet-roster', () => ({ useFleetRoster: () => {} })) +vi.mock('../chat/sidebar/use-simplified-agents', () => ({ + useSimplifiedAgents: () => ({ agents: [ + { id: 'a', label: 'Research', profile: 'research', connectionId: 'alpha', gateway: 'Laptop' }, + { id: 'b', label: 'Research', profile: 'research', connectionId: 'beta', gateway: 'Studio' } + ] }) +})) +afterEach(cleanup) + +function Route() { + const location = useLocation() + + return {location.pathname}{location.search} +} + +it('opens the selected gateway/profile identity even when agent names match', () => { + render() + fireEvent.click(screen.getByRole('button', { name: 'Agent settings: Research · Studio' })) + expect(screen.getByLabelText('route').textContent).toBe('/settings?agent=research&connection=beta') +}) + +it('filters by gateway and retains the profile management destination', () => { + render() + fireEvent.change(screen.getByRole('textbox'), { target: { value: 'Laptop' } }) + expect(screen.queryByRole('button', { name: 'Agent settings: Research · Studio' })).toBeNull() + expect(screen.getByRole('button', { name: 'Agent settings: Research · Laptop' })).toBeTruthy() + fireEvent.click(screen.getByRole('button', { name: 'Manage profiles…' })) + expect(screen.getByLabelText('route').textContent).toBe('/profiles?manage=true') +}) + +it('explains an empty search without asking users to select a missing profile', () => { + render() + fireEvent.change(screen.getByRole('textbox'), { target: { value: 'missing gateway' } }) + expect(screen.getByText('No matching results found.')).toBeTruthy() + expect(screen.queryByText('Select a profile to view its details.')).toBeNull() +}) diff --git a/apps/desktop/src/app/agent-settings/directory.tsx b/apps/desktop/src/app/agent-settings/directory.tsx new file mode 100644 index 0000000000000..58b532bbf71ef --- /dev/null +++ b/apps/desktop/src/app/agent-settings/directory.tsx @@ -0,0 +1,80 @@ +import { useStore } from '@nanostores/react' +import { useState } from 'react' +import { useNavigate } from 'react-router' + +import { Button } from '@/components/ui/button' +import { Codicon } from '@/components/ui/codicon' +import { ProfileGlyph } from '@/components/ui/profile-glyph' +import { RowButton } from '@/components/ui/row-button' +import { SearchField } from '@/components/ui/search-field' +import { useI18n } from '@/i18n' +import { resolveProfileColor } from '@/lib/profile-color' +import { $profileColors } from '@/store/profile' + +import { useFleetRoster } from '../chat/sidebar/use-fleet-roster' +import { useSimplifiedAgents } from '../chat/sidebar/use-simplified-agents' +import { Panel, PanelEmpty, PanelHeader } from '../overlays/panel' +import { PROFILES_ROUTE, SETTINGS_ROUTE } from '../routes' + +export function AgentDirectory({ onClose }: { onClose: () => void }) { + const { t } = useI18n() + const navigate = useNavigate() + const colors = useStore($profileColors) + const [query, setQuery] = useState('') + useFleetRoster(true) + const { agents } = useSimplifiedAgents([]) + const needle = query.trim().toLocaleLowerCase() + const visible = agents.filter(agent => `${agent.label} ${agent.gateway}`.toLocaleLowerCase().includes(needle)) + + return ( + + navigate(`${PROFILES_ROUTE}?manage=true`)} variant="secondary"> + {t.profiles.manageProfiles} + + } + title={t.simplifiedAgents.agents} + /> + +
+ {visible.length === 0 ? ( + + ) : ( +
+ {visible.map(agent => ( + { + const params = new URLSearchParams({ agent: agent.profile }) + + if (agent.connectionId) {params.set('connection', agent.connectionId)} + navigate(`${SETTINGS_ROUTE}?${params}`) + }} + > + + + {agent.label} + {agent.gateway} + + + + ))} +
+ )} +
+
+ ) +} diff --git a/apps/desktop/src/app/agent-settings/entry.test.tsx b/apps/desktop/src/app/agent-settings/entry.test.tsx new file mode 100644 index 0000000000000..78dbef2fd806c --- /dev/null +++ b/apps/desktop/src/app/agent-settings/entry.test.tsx @@ -0,0 +1,35 @@ +import { act, cleanup, render, screen } from '@testing-library/react' +import { MemoryRouter } from 'react-router' +import { afterEach, expect, it, vi } from 'vitest' + +import { $agentSidebarChoice } from '@/store/simplified-agent-mode' + +import { SettingsView } from './entry' + +vi.mock('../settings', () => ({ SettingsView: () =>
Original settings
})) +vi.mock('./index', () => ({ + AgentSettingsView: ({ owner }: { owner: { connectionId?: string; profile: string } }) => ( +
+ {owner.connectionId}:{owner.profile} +
+ ) +})) +afterEach(() => { + cleanup() + $agentSidebarChoice.set(false) +}) + +it('keeps the original screen when v2 is off and gates an existing agent URL immediately', async () => { + $agentSidebarChoice.set(false) + render( + + {}} /> + + ) + expect(screen.getByText('Original settings')).toBeTruthy() + act(() => $agentSidebarChoice.set(true)) + expect(await screen.findByText('beta:research')).toBeTruthy() + act(() => $agentSidebarChoice.set(false)) + expect(screen.getByText('Original settings')).toBeTruthy() + expect(screen.queryByText('beta:research')).toBeNull() +}) diff --git a/apps/desktop/src/app/agent-settings/entry.tsx b/apps/desktop/src/app/agent-settings/entry.tsx new file mode 100644 index 0000000000000..7081e8eb08461 --- /dev/null +++ b/apps/desktop/src/app/agent-settings/entry.tsx @@ -0,0 +1,30 @@ +import { useStore } from '@nanostores/react' +import { lazy, Suspense } from 'react' +import { useLocation } from 'react-router' + +import { PageLoader } from '@/components/page-loader' +import { $simplifiedAgentMode } from '@/store/simplified-agent-mode' + +import { SettingsView as ClassicSettingsView } from '../settings' +import type { SettingsPageProps } from '../settings/types' + +const AgentSettingsView = lazy(async () => ({ default: (await import('./index')).AgentSettingsView })) + +/** The existing settings route stays unchanged unless v2 explicitly names an agent. */ +export function SettingsView(props: SettingsPageProps) { + const enabled = useStore($simplifiedAgentMode) + const { search } = useLocation() + const params = new URLSearchParams(search) + const profile = params.get('agent') + const connectionId = params.get('connection') || undefined + + if (!enabled || !profile) { + return + } + + return ( + }> + + + ) +} diff --git a/apps/desktop/src/app/agent-settings/index.tsx b/apps/desktop/src/app/agent-settings/index.tsx new file mode 100644 index 0000000000000..89802afe74bec --- /dev/null +++ b/apps/desktop/src/app/agent-settings/index.tsx @@ -0,0 +1,361 @@ +import { useStore } from '@nanostores/react' +import { useQuery } from '@tanstack/react-query' +import { useEffect, useState } from 'react' +import type { ReactNode } from 'react' +import { useLocation, useNavigate } from 'react-router' + +import { $apiRequestScope } from '@/api/client' +import { PageLoader } from '@/components/page-loader' +import { Button } from '@/components/ui/button' +import { Codicon } from '@/components/ui/codicon' +import { ProfileGlyph } from '@/components/ui/profile-glyph' +import { RowButton } from '@/components/ui/row-button' +import type { CronJob } from '@/hermes' +import { useI18n } from '@/i18n' +import { sessionTitle } from '@/lib/chat-runtime' +import { resolveProfileColor } from '@/lib/profile-color' +import { asText } from '@/lib/text' +import { $connectionsRegistry } from '@/store/connection-registry-state' +import { $activeConnectionId, selectConnection } from '@/store/connections' +import { $fleetRoster } from '@/store/fleet-roster' +import { $activeGatewayProfile, $profileColors, $profiles, ensureGatewayProfile } from '@/store/profile' +import { setSettingsScope } from '@/store/settings-scope' + +import { CapabilitiesView } from '../capabilities' +import { useSkillsQuery } from '../capabilities/skills/skills-data' +import { useToolsetsQuery } from '../capabilities/toolsets/toolsets-data' +import { gatewayLabel } from '../chat/sidebar/gateway-group-model' +import { useHermesConfigRecord } from '../hooks/use-config-record' +import { MessagingView } from '../messaging' +import { openSession } from '../open-session' +import { Panel, PanelHeader, PanelSectionLabel } from '../overlays/panel' +import { SETTINGS_ROUTE } from '../routes' +import { SettingsView as ClassicSettingsView } from '../settings' +import { getNested, toolNames } from '../settings/helpers' +import { settingsScopeLabel } from '../settings/profile-scope' +import type { SettingsPageProps } from '../settings/types' + +import { useAgentSettingsCopy } from './copy' +import { + agentSettingsKey, + type AgentSettingsOwner, + getAgentMessaging, + getAgentRecentSessions, + getAgentRoutines +} from './data' +import { RoutineDialog } from './routine-dialog' + +interface AgentSettingsViewProps extends SettingsPageProps { + owner: AgentSettingsOwner +} + +/** Existing editors use the active gateway. Gate them before rendering, never silently retarget. */ +export function AgentSettingsView(props: AgentSettingsViewProps) { + const c = useAgentSettingsCopy() + const { t } = useI18n() + const apiScope = useStore($apiRequestScope) + const active = useStore($activeConnectionId) + const profile = useStore($activeGatewayProfile) + const registry = useStore($connectionsRegistry) + const [error, setError] = useState('') + const [opening, setOpening] = useState(false) + const [scopeReady, setScopeReady] = useState(false) + + const matches = + (!props.owner.connectionId || props.owner.connectionId === (apiScope.connectionId ?? active)) && + profile === props.owner.profile + + useEffect(() => { + if (matches) {setSettingsScope(props.owner.profile)} + setScopeReady(matches) + }, [matches, props.owner.profile]) + + async function activate() { + setOpening(true) + setError('') + + try { + if (props.owner.connectionId && registry?.connections.some(item => item.id === props.owner.connectionId)) { + await selectConnection(props.owner.connectionId, { profile: props.owner.profile }) + } else if (!props.owner.connectionId || props.owner.connectionId === (apiScope.connectionId ?? active)) { + await ensureGatewayProfile(props.owner.profile) + } else { + throw new Error(c.unavailable) + } + } catch (err) { + setError(err instanceof Error ? err.message : t.errors.genericFailure) + } finally { + setOpening(false) + } + } + + if (!matches) + {return ( + + + + {error &&

{error}

} +
+ )} + + return scopeReady ? : +} + +function Section({ title, children }: { title: string; children: ReactNode }) { + return ( +
+ {title} +
{children}
+
+ ) +} + +function SettingRow({ title, detail, onClick }: { title: string; detail?: ReactNode; onClick: () => void }) { + return ( + + {title} + {detail} + + + ) +} + +function AgentSettingsContent({ owner, ...props }: AgentSettingsViewProps) { + const { t } = useI18n() + const c = useAgentSettingsCopy() + const navigate = useNavigate() + const { search } = useLocation() + const params = new URLSearchParams(search) + const panel = params.get('panel') + const profiles = useStore($profiles) + const colors = useStore($profileColors) + const roster = useStore($fleetRoster) + const registry = useStore($connectionsRegistry) + const profile = profiles.find(item => item.name === owner.profile) + const label = profile ? settingsScopeLabel(profile) : owner.profile + + const gateway = + roster?.sources.find(source => source.connectionId === owner.connectionId)?.label ?? + gatewayLabel(owner.connectionId ?? 'local', registry, t.settings.gateway.webappHostTitle) + + const config = useHermesConfigRecord(owner) + const skills = useSkillsQuery(owner) + const tools = useToolsetsQuery(owner) + const jobs = useQuery({ queryKey: [...agentSettingsKey(owner), 'routines'], queryFn: () => getAgentRoutines(owner) }) + + const messaging = useQuery({ + queryKey: [...agentSettingsKey(owner), 'messaging'], + queryFn: () => getAgentMessaging(owner) + }) + + const recent = useQuery({ + queryKey: [...agentSettingsKey(owner), 'recent'], + queryFn: () => getAgentRecentSessions(owner) + }) + + const [routine, setRoutine] = useState(null) + const value = (path: string) => (config.isError ? c.unavailable : asText(getNested(config.data ?? {}, path)) || '—') + + const pending = (failed: boolean, loading: boolean, detail: ReactNode) => + failed ? c.unavailable : loading ? t.sidebar.loading : detail + + function openPanel(next: string | null, tab?: string, page?: string) { + setSettingsScope(owner.profile) + const query = new URLSearchParams({ agent: owner.profile }) + + if (owner.connectionId) {query.set('connection', owner.connectionId)} + + if (next) {query.set('panel', next)} + + if (tab) {query.set('tab', tab)} + + if (page) {query.set('page', page)} + navigate(`${SETTINGS_ROUTE}?${query}`) + } + + const settings = (tab: string, page?: string) => openPanel('settings', `config:${tab}`, page) + const back = () => openPanel(null) + + if (panel === 'settings') {return } + + if (panel === 'capabilities' || panel === 'messaging') + {return ( + + + +
+ {panel === 'capabilities' ? ( + + ) : ( + + )} +
+
+ )} + + const fallbacks = getNested(config.data ?? {}, 'fallback_providers') + const failed = [config, skills, tools, jobs, messaging, recent].some(query => query.isError) + + return ( + + + + + {label} + + } + /> + {failed && ( +
+ {c.unavailable} + +
+ )} +
+
+
+ tool.enabled).flatMap(toolNames)).size)} + onClick={() => openPanel('capabilities', 'toolsets')} + title={c.tools} + /> + openPanel('capabilities', 'skills')} + title={c.skills} + /> + openPanel('capabilities', 'connectors')} title={c.connectors} /> + openPanel('capabilities', 'plugins')} title={t.skills.tabPlugins} /> +
+
+ settings('memory')} title={c.provider} /> +
+
+ {(messaging.data?.platforms ?? []) + .filter(platform => platform.id === 'telegram' || platform.id === 'discord' || platform.configured) + .map(platform => ( + openPanel('messaging')} + title={platform.name} + /> + ))} + {!messaging.data && ( + openPanel('messaging')} + title={c.connections} + /> + )} + settings('voice')} title={c.voice} /> +
+
+ settings('model', 'main')} + title={c.primary} + /> + settings('model', 'fallbacks')} + title={c.fallbacks} + /> +
+
+
+
+ + {jobs.data?.map(job => ( + setRoutine(job)} + title={job.name || job.id} + /> + ))} + {!jobs.data?.length && ( +

+ {pending(jobs.isError, jobs.isPending, c.noRoutines)} +

+ )} +
+
+ settings('safety', 'approvals')} + title={c.approvalMode} + /> + openPanel('settings', 'web-access')} title={c.access} /> +
+
+ {recent.data?.sessions + .filter(session => !session.hidden && !session.archived) + .map(session => ( + + openSession(session.id, navigate, 'in-place', { + workspaceMode: 'sessions', + ...(owner.connectionId + ? { ownerRoute: { connectionId: owner.connectionId, profile: owner.profile } } + : {}) + }) + } + title={sessionTitle(session)} + /> + ))} + {!recent.data?.sessions.filter(session => !session.hidden && !session.archived).length && ( +

+ {pending(recent.isError, recent.isPending, c.noSessions)} +

+ )} +
+
+
+ {routine && ( + setRoutine(null)} + onSaved={() => { + void jobs.refetch() + }} + owner={owner} + /> + )} +
+ ) +} diff --git a/apps/desktop/src/app/agent-settings/routine-dialog.test.tsx b/apps/desktop/src/app/agent-settings/routine-dialog.test.tsx new file mode 100644 index 0000000000000..87ed3018b630f --- /dev/null +++ b/apps/desktop/src/app/agent-settings/routine-dialog.test.tsx @@ -0,0 +1,90 @@ +import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react' +import { afterEach, expect, it, vi } from 'vitest' + +import * as client from '@/api/client' + +import { RoutineDialog } from './routine-dialog' + +afterEach(() => { + cleanup() + vi.restoreAllMocks() +}) + +it('saves a new routine on the captured owner and leaves failures editable', async () => { + const request = vi + .spyOn(client, 'hermesApi') + .mockRejectedValueOnce(new Error('Invalid schedule')) + .mockResolvedValueOnce({ id: 'saved' }) + + const close = vi.fn() + const saved = vi.fn() + render() + fireEvent.change(screen.getByLabelText('Name'), { target: { value: 'Daily review' } }) + fireEvent.change(screen.getByLabelText('Schedule'), { target: { value: '0 9 * * *' } }) + fireEvent.change(screen.getByLabelText('Prompt'), { target: { value: 'Review my notes' } }) + fireEvent.click(screen.getByRole('button', { name: 'Save' })) + expect((await screen.findByRole('alert')).textContent).toContain('Invalid schedule') + expect(close).not.toHaveBeenCalled() + fireEvent.click(screen.getByRole('button', { name: 'Save' })) + await waitFor(() => expect(saved).toHaveBeenCalledOnce()) + expect(request).toHaveBeenLastCalledWith( + expect.objectContaining({ + connectionId: 'remote', + profile: 'research', + path: '/api/cron/jobs?profile=research', + method: 'POST', + body: { name: 'Daily review', schedule: '0 9 * * *', prompt: 'Review my notes', deliver: 'local' } + }) + ) + expect(close).toHaveBeenCalledOnce() +}) + +it('edits script routine metadata without overwriting its script or resending a display-only schedule', async () => { + const request = vi.spyOn(client, 'hermesApi').mockResolvedValue({}) + const saved = vi.fn() + render( + {}} + onSaved={saved} + owner={{ connectionId: 'alpha', profile: 'research' }} + /> + ) + fireEvent.change(screen.getByLabelText('Name'), { target: { value: 'Renamed' } }) + fireEvent.click(screen.getByRole('button', { name: 'Save' })) + await waitFor(() => expect(saved).toHaveBeenCalledOnce()) + expect(request).toHaveBeenCalledWith( + expect.objectContaining({ body: { updates: { name: 'Renamed', enabled: true } } }) + ) +}) + +it('keeps an in-flight save visible and restores editing after failure', async () => { + let reject!: (reason: Error) => void + vi.spyOn(client, 'hermesApi').mockImplementation( + () => + new Promise((_resolve, fail) => { + reject = fail + }) + ) + const close = vi.fn() + const saved = vi.fn() + render() + fireEvent.change(screen.getByLabelText('Schedule'), { target: { value: '0 9 * * *' } }) + fireEvent.change(screen.getByLabelText('Prompt'), { target: { value: 'Review my notes' } }) + fireEvent.click(screen.getByRole('button', { name: 'Save' })) + expect(screen.getByRole('button', { name: 'Cancel' }).hasAttribute('disabled')).toBe(true) + expect(screen.getByLabelText('Prompt').closest('fieldset')?.disabled).toBe(true) + expect(screen.queryByRole('button', { name: 'Close' })).toBeNull() + fireEvent.click(screen.getByRole('button', { name: 'Cancel' })) + fireEvent.keyDown(window.document, { key: 'Escape' }) + expect(close).not.toHaveBeenCalled() + await act(async () => { + reject(new Error('Save failed')) + }) + expect(screen.getByRole('alert').textContent).toContain('Save failed') + expect(screen.getByRole('button', { name: 'Cancel' }).hasAttribute('disabled')).toBe(false) + expect(screen.getByLabelText('Prompt').closest('fieldset')?.disabled).toBe(false) + expect(saved).not.toHaveBeenCalled() + fireEvent.click(screen.getByRole('button', { name: 'Cancel' })) + expect(close).toHaveBeenCalledOnce() +}) diff --git a/apps/desktop/src/app/agent-settings/routine-dialog.tsx b/apps/desktop/src/app/agent-settings/routine-dialog.tsx new file mode 100644 index 0000000000000..4d1f2c9b3509d --- /dev/null +++ b/apps/desktop/src/app/agent-settings/routine-dialog.tsx @@ -0,0 +1,134 @@ +import { useState } from 'react' + +import { Button } from '@/components/ui/button' +import { Checkbox } from '@/components/ui/checkbox' +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle +} from '@/components/ui/dialog' +import { Input } from '@/components/ui/input' +import { Textarea } from '@/components/ui/textarea' +import type { CronJob } from '@/hermes' +import { useI18n } from '@/i18n' + +import { useAgentSettingsCopy } from './copy' +import { type AgentSettingsOwner, saveAgentRoutine } from './data' + +interface RoutineDialogProps { + owner: AgentSettingsOwner + job?: CronJob + onClose: () => void + onSaved: () => void +} + +export function RoutineDialog({ owner, job, onClose, onSaved }: RoutineDialogProps) { + const { t } = useI18n() + const c = useAgentSettingsCopy() + const initialSchedule = job?.schedule?.expr || job?.schedule_display || job?.schedule?.display || '' + const [name, setName] = useState(job?.name || '') + const [schedule, setSchedule] = useState(initialSchedule) + const [prompt, setPrompt] = useState(job?.prompt || '') + const [enabled, setEnabled] = useState(job?.enabled ?? true) + const [saving, setSaving] = useState(false) + const [error, setError] = useState('') + const script = Boolean(job?.script || job?.no_agent) + + async function save(event: React.FormEvent) { + event.preventDefault() + + if (saving) { + return + } + + setSaving(true) + setError('') + + try { + const values = job + ? { + name: name.trim(), + enabled, + ...(schedule !== initialSchedule ? { schedule: schedule.trim() } : {}), + ...(!script ? { prompt: prompt.trim() } : {}) + } + : { name: name.trim(), schedule: schedule.trim(), prompt: prompt.trim(), deliver: 'local' } + + await saveAgentRoutine(owner, values, job?.id) + onSaved() + onClose() + } catch (err) { + setError(err instanceof Error ? err.message : t.errors.genericFailure) + } finally { + setSaving(false) + } + } + + return ( + { + if (!open && !saving) { + onClose() + } + }} + open + > + + + {job ? c.routines : c.addRoutine} + + {owner.profile} + {!job && ` · ${c.localDelivery}`} + + +
+
+ + + {script ? ( +

{c.scriptRoutine}

+ ) : ( +