fix: migrate cloned profile configs (#46345)
This commit is contained in:
@@ -455,6 +455,37 @@ def remove_wrapper_script(name: str) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def _migrate_profile_config_if_outdated(profile_dir: Path) -> None:
|
||||
"""Bring a copied profile config.yaml up to the current schema.
|
||||
|
||||
Profile creation can clone a config file that predates schema tracking (no
|
||||
``_config_version``) or that is simply older than the running Hermes. If we
|
||||
leave it untouched, the first desktop/doctor view of the new profile shows a
|
||||
scary ``v0 → latest`` warning even though we just created the profile. Scope
|
||||
the normal migration pipeline to the new profile and keep it non-interactive.
|
||||
"""
|
||||
config_path = profile_dir / "config.yaml"
|
||||
if not config_path.exists():
|
||||
return
|
||||
|
||||
try:
|
||||
from hermes_constants import reset_hermes_home_override, set_hermes_home_override
|
||||
from hermes_cli.config import check_config_version, migrate_config
|
||||
|
||||
token = set_hermes_home_override(str(profile_dir))
|
||||
try:
|
||||
current_ver, latest_ver = check_config_version()
|
||||
if current_ver < latest_ver:
|
||||
migrate_config(interactive=False, quiet=True)
|
||||
finally:
|
||||
reset_hermes_home_override(token)
|
||||
except Exception:
|
||||
# Profile creation should not fail because an old copied config could
|
||||
# not be migrated. The next `hermes doctor --fix` can still surface the
|
||||
# detailed error in the target profile.
|
||||
pass
|
||||
|
||||
|
||||
def find_alias_for_profile(profile_name: str) -> Optional[str]:
|
||||
"""Return the alias name of the wrapper that activates *profile_name*, or None.
|
||||
|
||||
@@ -910,6 +941,14 @@ def create_profile(
|
||||
except OSError:
|
||||
pass # best-effort — the feature still works via the empty skills/ dir
|
||||
|
||||
# Cloned configs can be older than the running Hermes (or predate schema
|
||||
# tracking entirely). Migrate config-only clones immediately so
|
||||
# desktop/status surfaces don't warn that a just-created profile is
|
||||
# v0/outdated. Leave --clone-all snapshots byte-for-byte apart from the
|
||||
# explicit runtime/history stripping above.
|
||||
if not clone_all:
|
||||
_migrate_profile_config_if_outdated(profile_dir)
|
||||
|
||||
# Persist description if the caller provided one. Done last so a
|
||||
# partial-create failure doesn't strand a description file in an
|
||||
# incomplete profile.
|
||||
|
||||
Reference in New Issue
Block a user