profiles_config.py 1.3 KB

1234567891011121314151617181920212223242526272829
  1. """Migrate a new profile's copied config document (``hermes_cli.profiles`` creation helper)."""
  2. from __future__ import annotations
  3. import contextlib
  4. from pathlib import Path
  5. from hermes_cli.config_backend import config_exists, supports_file_tooling
  6. def _migrate_profile_config_if_outdated(profile_dir: Path) -> None:
  7. """Migrate a copied config.yaml to the current schema (non-interactive, scoped to the new
  8. profile); otherwise the first desktop/doctor view shows a scary ``v0 -> latest`` warning."""
  9. if not supports_file_tooling():
  10. return # no local config.yaml to migrate: a remote backend migrates in memory on read (D12)
  11. if not config_exists(profile_dir / "config.yaml"):
  12. return
  13. # Creation must not fail over an unmigratable old config; `hermes doctor --fix` surfaces
  14. # the detailed error in the target profile.
  15. with contextlib.suppress(Exception):
  16. from hermes_constants import reset_hermes_home_override, set_hermes_home_override
  17. from hermes_cli.config import check_config_version, migrate_config
  18. token = set_hermes_home_override(str(profile_dir))
  19. try:
  20. current_ver, latest_ver = check_config_version()
  21. if current_ver < latest_ver:
  22. migrate_config(interactive=False, quiet=True)
  23. finally:
  24. reset_hermes_home_override(token)