Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions hermes_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5975,7 +5975,17 @@ def load_env() -> Dict[str, str]:
for line in lines:
line = line.strip()
if line and not line.startswith('#') and '=' in line:
key, _, value = line.partition('=')
raw_line = line
# Strip 'export ' (bash) and 'set ' (cmd) shell prefixes so
# .env files written with ``export KEY=VALUE`` syntax are
# parsed correctly. Without this, get_env_value("NOTION_API_KEY")
# returns None for ``export NOTION_API_KEY=xxx`` because the
# key would be "export NOTION_API_KEY".
for _sh_prefix in ('export ', 'set '):
if raw_line.lower().startswith(_sh_prefix):
raw_line = raw_line[len(_sh_prefix):]
break
key, _, value = raw_line.partition('=')
env_vars[key.strip()] = value.strip().strip('"\'')

if cache_key is not None:
Expand Down Expand Up @@ -6192,7 +6202,14 @@ def save_env_value(key: str, value: str):
# Find and update or append
found = False
for i, line in enumerate(lines):
if line.strip().startswith(f"{key}="):
stripped = line.strip()
# Match KEY=VALUE, export KEY=VALUE, set KEY=VALUE
check = stripped
for _p in ('export ', 'set '):
if check.lower().startswith(_p):
check = check[len(_p):]
break
if check.startswith(f"{key}="):
lines[i] = f"{key}={value}\n"
found = True
break
Expand Down Expand Up @@ -6271,7 +6288,16 @@ def remove_env_value(key: str) -> bool:
lines = f.readlines()
lines = _sanitize_env_lines(lines)

new_lines = [line for line in lines if not line.strip().startswith(f"{key}=")]
new_lines = []
for line in lines:
stripped = line.strip()
check = stripped
for _p in ('export ', 'set '):
if check.lower().startswith(_p):
check = check[len(_p):]
break
if not check.startswith(f"{key}="):
new_lines.append(line)
found = len(new_lines) < len(lines)

if found:
Expand Down
8 changes: 7 additions & 1 deletion tools/skills_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,13 @@ def load_env() -> Dict[str, str]:
for line in f:
line = line.strip()
if line and not line.startswith("#") and "=" in line:
key, _, value = line.partition("=")
raw_line = line
# Strip shell export/set prefixes
for _p in ('export ', 'set '):
if raw_line.lower().startswith(_p):
raw_line = raw_line[len(_p):]
break
key, _, value = raw_line.partition("=")
env_vars[key.strip()] = value.strip().strip("\"'")
return env_vars

Expand Down