HERMES-GIELIE/static
Nathan Esquenazi c778c1eb0c fix: profile switch fails with 'does not exist' when server starts on non-default profile
Root cause: _DEFAULT_HERMES_HOME was evaluated at module import time from
os.getenv('HERMES_HOME'). HERMES_HOME is a MUTABLE env var -- init_profile_state()
at server startup calls _set_hermes_home() which writes to os.environ['HERMES_HOME'].
If the sticky active_profile file pointed to e.g. 'webui', HERMES_HOME was set to
~/.hermes/profiles/webui BEFORE api/profiles.py imported. So _DEFAULT_HERMES_HOME
resolved to ~/.hermes/profiles/webui. Then switch_profile('webui') computed:
  home = ~/.hermes/profiles/webui / 'profiles' / 'webui'
       = ~/.hermes/profiles/webui/profiles/webui  -- doesn't exist -> 404 ValueError

Fix: replace the one-liner assignment with _resolve_base_hermes_home() which:
  1. Checks HERMES_BASE_HOME env var (explicit override)
  2. Checks HERMES_HOME -- but if it looks like a profiles/ subdir (parent.name ==
     'profiles'), walks up two levels to the actual base
  3. Falls back to Path.home() / '.hermes'

This means the server can start with HERMES_HOME pointing to any profile and
_DEFAULT_HERMES_HOME will still correctly point to ~/.hermes.

Also fix: api() helper in workspace.js was throwing new Error(await res.text())
which surfaced raw JSON to the UI: 'Switch failed: {"error":"Profile X does not exist."}'
Now parses the JSON and extracts j.error so the toast shows clean human-readable text.

Regression tests added in test_sprint23.py:
- test_profile_switch_base_home_not_subdir: static analysis verifying the resolver
- test_api_helper_returns_clean_error_message: verifies api() parses JSON errors
- test_profile_switch_resolve_base_home_logic: verifies the profiles/ subdir detection

Tests: 426 passed, 0 failed.
2026-04-03 19:29:24 +00:00
..
boot.js feat: multi-profile support -- create, switch, delete profiles from web UI (Issue #28) 2026-04-03 10:50:21 -07:00
commands.js feat: Sprint 17 -- workspace breadcrumbs, slash commands, send key setting 2026-04-03 04:13:38 -07:00
index.html feat: Sprint 23 -- profile/workspace/model coherence 2026-04-03 11:46:15 -07:00
messages.js feat: polish send button — hidden until content, icon-circle, pop-in animation 2026-04-03 07:20:16 -07:00
panels.js feat: Sprint 23 -- profile/workspace/model coherence 2026-04-03 11:46:15 -07:00
sessions.js feat: Sprint 23 -- profile/workspace/model coherence 2026-04-03 11:46:15 -07:00
style.css feat: multi-profile support -- create, switch, delete profiles from web UI (Issue #28) 2026-04-03 10:50:21 -07:00
ui.js feat: multi-profile support -- create, switch, delete profiles from web UI (Issue #28) 2026-04-03 10:50:21 -07:00
workspace.js fix: profile switch fails with 'does not exist' when server starts on non-default profile 2026-04-03 19:29:24 +00:00