diff --git a/agent-node/src/agent_node/skills/shell_bridge.py b/agent-node/src/agent_node/skills/shell_bridge.py index 95e6d14..c67d455 100644 --- a/agent-node/src/agent_node/skills/shell_bridge.py +++ b/agent-node/src/agent_node/skills/shell_bridge.py @@ -153,11 +153,15 @@ # Stream terminal output back (with stealth filtering) if on_event: stealth_out = decoded - if "__CORTEX_FIN_SH_" in decoded: - import re - # We remove any line that contains our internal marker to hide plumbing from user. - # This covers both the initial command echo and the exit code output. - stealth_out = re.sub(r'.*__CORTEX_FIN_SH_.*[\r\n]*', '', decoded) + import re + # Remove the short source command payload from the PTY echo + if " source " in stealth_out and "ctx_" in stealth_out: + stealth_out = re.sub(r'.*source .*ctx_\d+\.sh.*[\r\n]*', '', stealth_out) + + if "__CORTEX_FIN_SH_" in stealth_out: + # Remove any line that contains our internal marker from the output stream. + # This covers both the fallback echo and the actual execution exit code emission. + stealth_out = re.sub(r'.*__CORTEX_FIN_SH_.*[\r\n]*', '', stealth_out) if stealth_out: # Phase 3: Client-Side Truncation (Stream Rate Limiting) @@ -323,12 +327,21 @@ sess["result"] = result_container sess["cancel_event"] = threading.Event() - # Input injection: execute command then echo marker and exit code + # Input injection: execute command via sourced script to hide plumbing from ZLE/Readline echo try: - # 12-factor bash: ( cmd ) ; echo marker $? - # We use "" concatenation in the echo command to ensure the marker literal - # DOES NOT appear in the PTY input echo, preventing premature completion. - full_input = f"({cmd}) ; echo \"__CORTEX_FIN_SH_\"\"{marker_id}__\" $?\n" + import tempfile + script_path = os.path.join(tempfile.gettempdir(), f"ctx_{marker_id}.sh") + script_content = f"{cmd}\n__ctx_exit=$?\necho \"__CORTEX_FIN_SH_{marker_id}__\" $__ctx_exit\nrm -f {script_path}\n" + try: + with open(script_path, "w") as f: + f.write(script_content) + # Space prefix often hides it from shell history. Extremely short payload prevents ZLE line-wrap scrambling! + full_input = f" source {script_path}\n" + except Exception as e: + print(f" [🐚⚠️] Failed to write injection script dictating fallback: {e}") + # Fallback if writing file natively fails for some system reason + full_input = f"({cmd}) ; echo \"__CORTEX_FIN_SH_\"\"{marker_id}__\" $?\n" + os.write(sess["fd"], full_input.encode("utf-8")) # Wait for completion (triggered by reader) OR cancellation