fix(skills): literal HOME replacement; ~/$VAR still expands the variable

`re.sub` with the home path as a template string parsed backslashes as
escapes (re.error dropped the whole injected config block); use a callable.
The early `~/…` return also skipped `expandvars`, leaving `~/$LEAF` half
resolved. Prefix-substitute and fall through to normal expansion instead.
This commit is contained in:
teknium1
2026-09-12 08:09:23 -07:00
committed by Teknium
parent 86211492d1
commit 66dbb656be
2 changed files with 10 additions and 6 deletions
+5 -5
View File
@@ -715,11 +715,11 @@ def _expand_skill_config_path(value: str) -> str:
"""
subprocess_home = get_subprocess_home()
if subprocess_home:
if value == "~":
return subprocess_home
if value.startswith(("~/", "~\\")):
return os.path.join(subprocess_home, value[2:])
value = _HOME_VAR_RE.sub(subprocess_home, value)
if value == "~" or value.startswith(("~/", "~\\")):
value = subprocess_home + value[1:]
# Callable replacement: a literal template would parse backslashes in the home path
# as regex escapes.
value = _HOME_VAR_RE.sub(lambda _m: subprocess_home, value)
return os.path.expanduser(os.path.expandvars(value))