fix(profiles): honor tombstones in exists/backfill and tighten named-home detection

Treat tombstoned leftover dirs as gone for exists/-p/use, skip them in
env backfill, replace only empty shells on recreate, and stop treating a
default home that merely contains a profiles path segment as named.
This commit is contained in:
EndeavorYen
2026-08-20 01:11:31 +08:00
committed by Teknium
parent 7e34522454
commit af2dc685fc
3 changed files with 95 additions and 4 deletions
+12 -1
View File
@@ -234,11 +234,22 @@ _DELETED_PROFILES_DIR = ".deleted"
def named_profile_home(path: str | Path) -> Path | None:
"""Return ``<root>/profiles/<name>`` when *path* is that home or under it."""
"""Return ``<root>/profiles/<name>`` when *path* is that home or under it.
A named profile home is only ``.../profiles/<id>`` where ``<id>`` does
not start with ``.``. A default Hermes home whose path merely contains a
``profiles`` segment (e.g. ``/tmp/foo/profiles/notahome/.hermes``) is not
a named profile. ``.../profiles/worker/logs`` still resolves to
``.../profiles/worker``.
"""
current = Path(path)
for candidate in (current, *current.parents):
if candidate.parent.name == "profiles" and not candidate.name.startswith("."):
return candidate
# Stop at a default Hermes home so a coincidental ``profiles/``
# ancestor is not treated as a named-profile root.
if candidate.name == ".hermes":
return None
return None