mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-02 16:57:36 +08:00
fix(terminal): suppress declare -x stdout leak when sourcing snapshot on macOS
On macOS (bash 3.2 and certain Homebrew builds), sourcing a file containing declare -x statements prints each declaration to stdout. The session snapshot (written by export -p) is full of these, so every command execution prepends ~60 lines of env vars into the LLM's context window, wasting tokens and potentially exceeding context limits (issue #15459). Fix: redirect both stdout and stderr to /dev/null when sourcing the snapshot. The source builtin still sets the variables in the current shell — only the print output is suppressed. On Linux this is already silent, so the redirect is harmless. Fixes #15459
This commit is contained in:
committed by
Teknium
parent
8258f4dcb7
commit
a52ed70608
@@ -386,9 +386,14 @@ class BaseEnvironment(ABC):
|
||||
|
||||
parts = []
|
||||
|
||||
# Source snapshot (env vars from previous commands)
|
||||
# Source snapshot (env vars from previous commands).
|
||||
# Redirect stdout to /dev/null because on macOS, sourcing a file
|
||||
# that contains `declare -x` statements prints each declaration to
|
||||
# stdout, leaking 60+ lines of env vars into the LLM context
|
||||
# (issue #15459). On Linux this is silent, so the redirect is
|
||||
# harmless there.
|
||||
if self._snapshot_ready:
|
||||
parts.append(f"source {self._snapshot_path} 2>/dev/null || true")
|
||||
parts.append(f"source {self._snapshot_path} > /dev/null 2>&1 || true")
|
||||
|
||||
# Preserve bare ``~`` expansion, but rewrite ``~/...`` through
|
||||
# ``$HOME`` so suffixes with spaces remain a single shell word.
|
||||
|
||||
Reference in New Issue
Block a user