The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): ignore-existing skips discovered runtimes without repeating install
brooklyn!de236c6a7fbc
diff --git a/apps/desktop/electron/backend-resolution.test.ts b/apps/desktop/electron/backend-resolution.test.tsnew file mode 100644index 00000000000..93510e0a645--- /dev/null+++ b/apps/desktop/electron/backend-resolution.test.ts@@ -0,0 +1,141 @@+import assert from 'node:assert/strict'++import { test } from 'vitest'++import {+ isIgnoreExisting,+ postBootstrapResolveOptions,+ selectBackendRung,+ type BackendResolutionInput+} from './backend-resolution'++function discovered(overrides: Partial<BackendResolutionInput> = {}): BackendResolutionInput {+ return {+ ignoreExisting: false,+ justInstalled: false,+ bootstrapRepairRequested: false,+ hasExplicitRoot: false,+ hasUnpackagedSource: false,+ activeRuntimeUsable: false,+ hasExplicitCommand: false,+ hasPathHermes: false,+ hasSystemPython: false,+ ...overrides+ }+}++test('ignore-existing is exactly the string 1', () => {+ assert.equal(isIgnoreExisting('1'), true)+ assert.equal(isIgnoreExisting('true'), false)+ assert.equal(isIgnoreExisting('0'), false)+ assert.equal(isIgnoreExisting(''), false)+ assert.equal(isIgnoreExisting(undefined), false)+})++test('ignore-existing skips the active runtime and system python, not only hermes on PATH', () => {+ // The flag used to wrap only the PATH probe. A usable managed install at+ // ACTIVE_HERMES_ROOT, or a system Python that can import hermes_cli, still+ // started a local serve.+ assert.equal(+ selectBackendRung(+ discovered({+ ignoreExisting: true,+ activeRuntimeUsable: true,+ hasPathHermes: true,+ hasSystemPython: true+ })+ ),+ 'onboarding'+ )+})++test('explicit root and an unpackaged source checkout stay above the ignore-existing gate', () => {+ const ignored = {+ ignoreExisting: true,+ activeRuntimeUsable: true,+ hasPathHermes: true,+ hasSystemPython: true+ }++ assert.equal(selectBackendRung(discovered({ ...ignored, hasExplicitRoot: true })), 'explicit-root')+ assert.equal(selectBackendRung(discovered({ ...ignored, hasUnpackagedSource: true })), 'unpackaged-source')+})++test('an explicit hermes command is not a discovered runtime', () => {+ assert.equal(+ selectBackendRung(+ discovered({+ ignoreExisting: true,+ activeRuntimeUsable: true,+ hasExplicitCommand: true,+ hasPathHermes: true,+ hasSystemPython: true+ })+ ),+ 'explicit-command'+ )+})++test('the post-bootstrap re-resolve uses the runtime just installed instead of repeating onboarding', () => {+ const ignored = discovered({+ ignoreExisting: true,+ activeRuntimeUsable: true,+ hasPathHermes: true,+ hasSystemPython: true+ })++ assert.equal(selectBackendRung(ignored), 'onboarding')+ assert.equal(+ selectBackendRung({+ ...ignored,+ justInstalled: postBootstrapResolveOptions().justInstalled+ }),+ 'active'+ )+})++test('a just-installed runtime that is not usable does not fall back to a discovered runtime or repeat onboarding', () => {+ assert.equal(+ selectBackendRung(+ discovered({+ ignoreExisting: true,+ justInstalled: true,+ activeRuntimeUsable: false,+ hasPathHermes: true,+ hasSystemPython: true+ })+ ),+ 'installed-unusable'+ )+})++test('without the flag a usable active runtime still wins, and repair still bypasses it', () => {+ assert.equal(+ selectBackendRung(+ discovered({+ activeRuntimeUsable: true,+ hasPathHermes: true,+ hasSystemPython: true+ })+ ),+ 'active'+ )+ assert.equal(+ selectBackendRung(+ discovered({+ bootstrapRepairRequested: true,+ activeRuntimeUsable: true,+ hasPathHermes: true+ })+ ),+ 'path'+ )+ assert.equal(+ selectBackendRung(+ discovered({+ hasSystemPython: true+ })+ ),+ 'system-python'+ )+})diff --git a/apps/desktop/electron/backend-resolution.ts b/apps/desktop/electron/backend-resolution.tsnew file mode 100644index 00000000000..82100c8e731--- /dev/null+++ b/apps/desktop/electron/backend-resolution.ts@@ -0,0 +1,143 @@+/**+ * Precedence for Desktop backend resolution below the two explicit source+ * rungs (HERMES_DESKTOP_HERMES_ROOT and an unpackaged checkout).+ *+ * HERMES_DESKTOP_IGNORE_EXISTING=1 skips discovered rungs — the managed+ * install, `hermes` on PATH, and system Python — so no local serve starts+ * and the caller falls through to connect/onboarding. It does not skip an+ * explicit HERMES_DESKTOP_HERMES command.+ *+ * The post-bootstrap re-resolve must pass `justInstalled`. Otherwise the+ * flag would skip the runtime this process just installed and the installer+ * would see onboarding again and repeat.+ */+export type BackendRung =+ | 'explicit-root'+ | 'unpackaged-source'+ | 'active'+ | 'explicit-command'+ | 'path'+ | 'system-python'+ | 'onboarding'+ | 'installed-unusable'++export interface BackendResolutionInput {+ ignoreExisting: boolean+ justInstalled: boolean+ bootstrapRepairRequested: boolean+ hasExplicitRoot: boolean+ hasUnpackagedSource: boolean+ activeRuntimeUsable: boolean+ hasExplicitCommand: boolean+ hasPathHermes: boolean+ hasSystemPython: boolean+}++const NO_CANDIDATES: BackendResolutionInput = {+ ignoreExisting: false,+ justInstalled: false,+ bootstrapRepairRequested: false,+ hasExplicitRoot: false,+ hasUnpackagedSource: false,+ activeRuntimeUsable: false,+ hasExplicitCommand: false,+ hasPathHermes: false,+ hasSystemPython: false+}++export const INSTALLED_RUNTIME_UNUSABLE =+ 'Hermes install finished, but the new runtime could not be resolved. Desktop will not start the installer again.'++export function isIgnoreExisting(value: string | undefined): boolean {+ return value === '1'+}++/** Options the re-resolve after a successful bootstrap must pass. */+export function postBootstrapResolveOptions(): { justInstalled: true } {+ return { justInstalled: true }+}++export function selectBackendRung(input: BackendResolutionInput): BackendRung {+ if (input.hasExplicitRoot) {+ return 'explicit-root'+ }++ if (input.hasUnpackagedSource) {+ return 'unpackaged-source'+ }++ const skipDiscovered = input.ignoreExisting && !input.justInstalled++ if (input.activeRuntimeUsable && !input.bootstrapRepairRequested && !skipDiscovered) {+ return 'active'+ }++ if (input.hasExplicitCommand) {+ return 'explicit-command'+ }++ if (!input.ignoreExisting && input.hasPathHermes) {+ return 'path'+ }++ if (!input.ignoreExisting && input.hasSystemPython) {+ return 'system-python'+ }++ // The installer already ran. Onboarding here would start it again; PATH and+ // system Python are the discovered runtimes the flag promised to skip.+ if (input.ignoreExisting && input.justInstalled) {+ return 'installed-unusable'+ }++ return 'onboarding'+}++export function shouldProbeActiveRuntime(input: {+ ignoreExisting: boolean+ justInstalled: boolean+ bootstrapRepairRequested: boolean+}): boolean {+ return (+ selectBackendRung({+ ...NO_CANDIDATES,+ ...input,+ activeRuntimeUsable: true+ }) === 'active'+ )+}++export function shouldProbeDiscoveredPath(input: { ignoreExisting: boolean }): boolean {+ return (+ selectBackendRung({+ ...NO_CANDIDATES,+ ignoreExisting: input.ignoreExisting,+ hasPathHermes: true+ }) === 'path'+ )+}++export function shouldProbeSystemPython(input: { ignoreExisting: boolean }): boolean {+ return (+ selectBackendRung({+ ...NO_CANDIDATES,+ ignoreExisting: input.ignoreExisting,+ hasSystemPython: true+ }) === 'system-python'+ )+}++export function unresolvedDiscoveredRuntime(input: {+ ignoreExisting: boolean+ justInstalled: boolean+}): 'onboarding' | 'installed-unusable' {+ const rung = selectBackendRung({+ ...NO_CANDIDATES,+ ignoreExisting: input.ignoreExisting,+ justInstalled: input.justInstalled,+ hasPathHermes: true,+ hasSystemPython: true+ })++ return rung === 'installed-unusable' ? 'installed-unusable' : 'onboarding'+}diff --git a/hermes_cli/subcommands/gui.py b/hermes_cli/subcommands/gui.pyindex 2a789694fbc..79cb45a14d3 100644--- a/hermes_cli/subcommands/gui.py+++ b/hermes_cli/subcommands/gui.py@@ -23,7 +23,10 @@ def build_gui_parser(subparsers, *, cmd_gui: Callable) -> None:help="Enable deterministic desktop boot delays for validating startup UI")gui_parser.add_argument("--ignore-existing", action="store_true",- help="Force Desktop to ignore any hermes CLI already on PATH during backend resolution")+ help="Ignore discovered local runtimes (active install, hermes on PATH, "+ "system Python) so no local backend starts; fall through to connect or "+ "onboarding. Explicit --hermes-root still wins. A runtime this launch "+ "just installed is still used.")gui_parser.add_argument("--hermes-root",help="Override the Hermes source root used by Desktop (sets HERMES_DESKTOP_HERMES_ROOT)")diff --git a/website/docs/reference/environment-variables.md b/website/docs/reference/environment-variables.mdindex de81c258257..ac8b90c381e 100644--- a/website/docs/reference/environment-variables.md+++ b/website/docs/reference/environment-variables.md@@ -580,7 +580,7 @@ Three dashboard-auth providers ship in the box. For a remote Hermes Desktop conn| `HERMES_DESKTOP_REMOTE_URL` | (Desktop side) Base URL of the remote backend, e.g. `http://host:9119`. When set, overrides the in-app Gateway URL; you still sign in from the Gateway settings panel (OAuth redirect or username/password, whichever the backend advertises). || `HERMES_DESKTOP_HERMES` | Desktop backend command override. Used by packagers/Nix or troubleshooting to point Electron at a specific `hermes` executable before checking the mutable managed install. || `HERMES_DESKTOP_HERMES_ROOT` | Desktop source-checkout override used by `hermes desktop --hermes-root`; checked before the packaged first-launch install or an existing `hermes` on `PATH`. |-| `HERMES_DESKTOP_IGNORE_EXISTING` | Set to `1` to make Desktop ignore an existing `hermes` on `PATH` during backend resolution. Equivalent to `hermes desktop --ignore-existing`. |+| `HERMES_DESKTOP_IGNORE_EXISTING` | Set to `1` to make Desktop ignore every discovered local runtime (the managed install, a `hermes` on `PATH`, and a system-Python `hermes_cli`) during backend resolution, so no local backend starts and Desktop falls through to connect or onboarding. Explicit `HERMES_DESKTOP_HERMES_ROOT`, an unpackaged source checkout, and `HERMES_DESKTOP_HERMES` still win. A runtime this launch just installed is still used. Equivalent to `hermes desktop --ignore-existing`. || `HERMES_DESKTOP_CWD` | Initial project directory for Desktop chat sessions. Set by `hermes desktop --cwd`. || `HERMES_DESKTOP_PYTHON` | Absolute path to a Python interpreter for the backend, checked before Electron auto-resolves one for the source checkout. Used by worktree dev helpers (see [TUI & Desktop from Worktrees](../developer-guide/worktree-ui-dev.md)) to reuse a shared venv. || `HERMES_DESKTOP_DEV_SERVER` | Vite dev-server URL the Electron shell loads instead of the packaged bundle (e.g. `http://127.0.0.1:5174`). Set automatically by `npm run dev`; only relevant when hacking on the app. |