elevate: only pass env diff to keep notifications readable

This commit is contained in:
Levi Neely 2026-07-27 09:52:58 +02:00
parent 971c8a988d
commit 0c6ea9cca2
1 changed files with 13 additions and 5 deletions

View File

@ -346,14 +346,22 @@ def handle(conn):
def _wrap_with_env(cmd, env):
"""Wrap a command with explicit env setup.
"""Wrap a command with env vars that differ from the adapter's own env.
Produces: env -i K1=V1 K2=V2 ... bash -c 'original command'
This ensures the command runs with exactly the caller's environment.
Only exports the delta so the command string stays readable in
superpowerd notifications. Vars that match the session env are
already inherited.
"""
import shlex
parts = ["env", "-i"]
for k, v in sorted(env.items()):
adapter_env = os.environ
diff = {}
for k, v in env.items():
if adapter_env.get(k) != v:
diff[k] = v
if not diff:
return cmd
parts = ["env"]
for k, v in sorted(diff.items()):
parts.append(f"{k}={v}")
parts.extend(["bash", "-c", cmd])
return " ".join(shlex.quote(p) for p in parts)