feat(cli): display custom profile alias names in profile list/show (#40371)

profile list and profile show assumed the wrapper script is always named
after the profile (wrapper_dir / name). When a custom alias exists — e.g.
`hermes profile alias steve --name qiaobusi` creates ~/.local/bin/qiaobusi
pointing at `hermes -p steve` — the display silently showed the profile
name (or nothing) instead of the alias the user actually typed.

The custom-alias *creation* path (create_wrapper_script(name, target)) was
added later; the *display* path was never updated to match.

Add find_alias_for_profile() — a reverse lookup that scans the wrapper dir
for our own wrappers (alias-named file containing 'hermes -p <profile>'),
prefers a custom alias over the profile-named one, strips .bat on Windows,
and sorts for deterministic output. Populate ProfileInfo.alias_name and wire
it into the three display sites (profile describe, list, show).

Credit: salvages the intent of #11506 by wss434631143, reimplemented on
current main against the post-#11506 custom-alias (--name/target) mechanism.

Tests: 6 new (profile-named, custom-name, none, unrelated-file rejection,
windows .bat strip, list_profiles surfacing). All 123 in test_profiles pass.
E2E verified against the real CLI for both custom and profile-named aliases.
This commit is contained in:
kshitij
2026-06-06 08:08:07 +00:00
committed by GitHub
parent c79b6f23e6
commit 5af899c7ca
3 changed files with 123 additions and 7 deletions
+10 -5
View File
@@ -11676,7 +11676,8 @@ def cmd_profile(args):
)
print(f"Skills: {p.skill_count} installed")
if p.alias_path:
print(f"Alias: {p.name} → hermes -p {p.name}")
alias_display = p.alias_name or p.name
print(f"Alias: {alias_display} → hermes -p {p.name}")
break
print()
return
@@ -11708,7 +11709,7 @@ def cmd_profile(args):
name = p.name
model = (p.model or "")[:26]
gw = "running" if p.gateway_running else "stopped"
alias = p.name if p.alias_path else ""
alias = (p.alias_name or p.name) if p.alias_path else ""
if p.is_default:
alias = ""
if p.distribution_name:
@@ -11958,6 +11959,8 @@ def cmd_profile(args):
_check_gateway_running,
_count_skills,
_read_distribution_meta,
_get_wrapper_dir,
find_alias_for_profile,
)
if not profile_exists(name):
@@ -11968,7 +11971,7 @@ def cmd_profile(args):
gw = _check_gateway_running(profile_dir)
skills = _count_skills(profile_dir)
dist_name, dist_version, dist_source = _read_distribution_meta(profile_dir)
wrapper = _get_wrapper_dir() / name
alias_name = find_alias_for_profile(name)
print(f"\nProfile: {name}")
print(f"Path: {profile_dir}")
@@ -11987,8 +11990,10 @@ def cmd_profile(args):
if dist_source:
print(f"Installed from: {dist_source}")
print(f" (run `hermes profile info {name}` for full manifest)")
if wrapper.exists():
print(f"Alias: {wrapper}")
if alias_name:
is_windows = sys.platform == "win32"
wrapper = _get_wrapper_dir() / (f"{alias_name}.bat" if is_windows else alias_name)
print(f"Alias: {alias_name} → hermes -p {name} ({wrapper})")
print()
elif action == "alias":