mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-30 06:41:51 +00:00
fix(windows): hide local subprocess consoles
Apply Windows CREATE_NO_WINDOW flags to foreground local terminal subprocesses and tracked background processes so Hermes operations do not flash or steal focus with extra console windows.
This commit is contained in:
parent
f007ef8ab5
commit
95683c0283
2 changed files with 8 additions and 1 deletions
|
|
@ -12,6 +12,7 @@ import time
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from tools.environments.base import BaseEnvironment, _pipe_stdin
|
from tools.environments.base import BaseEnvironment, _pipe_stdin
|
||||||
|
from hermes_cli._subprocess_compat import windows_hide_flags
|
||||||
|
|
||||||
_IS_WINDOWS = platform.system() == "Windows"
|
_IS_WINDOWS = platform.system() == "Windows"
|
||||||
|
|
||||||
|
|
@ -519,6 +520,8 @@ class LocalEnvironment(BaseEnvironment):
|
||||||
|
|
||||||
_popen_cwd = self.cwd
|
_popen_cwd = self.cwd
|
||||||
|
|
||||||
|
_popen_kwargs = {"creationflags": windows_hide_flags()} if _IS_WINDOWS else {}
|
||||||
|
|
||||||
proc = subprocess.Popen(
|
proc = subprocess.Popen(
|
||||||
args,
|
args,
|
||||||
text=True,
|
text=True,
|
||||||
|
|
@ -531,6 +534,7 @@ class LocalEnvironment(BaseEnvironment):
|
||||||
preexec_fn=None if _IS_WINDOWS else os.setsid,
|
preexec_fn=None if _IS_WINDOWS else os.setsid,
|
||||||
creationflags=subprocess.CREATE_NO_WINDOW if _IS_WINDOWS else 0,
|
creationflags=subprocess.CREATE_NO_WINDOW if _IS_WINDOWS else 0,
|
||||||
cwd=_popen_cwd,
|
cwd=_popen_cwd,
|
||||||
|
**_popen_kwargs,
|
||||||
)
|
)
|
||||||
if not _IS_WINDOWS:
|
if not _IS_WINDOWS:
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ import uuid
|
||||||
|
|
||||||
_IS_WINDOWS = platform.system() == "Windows"
|
_IS_WINDOWS = platform.system() == "Windows"
|
||||||
from tools.environments.local import _find_shell, _resolve_safe_cwd, _sanitize_subprocess_env
|
from tools.environments.local import _find_shell, _resolve_safe_cwd, _sanitize_subprocess_env
|
||||||
|
from hermes_cli._subprocess_compat import windows_hide_flags
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from typing import Any, Dict, List, Optional
|
from typing import Any, Dict, List, Optional
|
||||||
|
|
||||||
|
|
@ -549,6 +550,8 @@ class ProcessRegistry:
|
||||||
# stdout is a pipe, hiding output from process(action="poll")).
|
# stdout is a pipe, hiding output from process(action="poll")).
|
||||||
bg_env = _sanitize_subprocess_env(os.environ, env_vars)
|
bg_env = _sanitize_subprocess_env(os.environ, env_vars)
|
||||||
bg_env["PYTHONUNBUFFERED"] = "1"
|
bg_env["PYTHONUNBUFFERED"] = "1"
|
||||||
|
_popen_kwargs = {"creationflags": windows_hide_flags()} if _IS_WINDOWS else {}
|
||||||
|
|
||||||
proc = subprocess.Popen(
|
proc = subprocess.Popen(
|
||||||
[user_shell, "-lic", f"set +m; {command}"],
|
[user_shell, "-lic", f"set +m; {command}"],
|
||||||
text=True,
|
text=True,
|
||||||
|
|
@ -560,7 +563,7 @@ class ProcessRegistry:
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
stdin=subprocess.DEVNULL,
|
stdin=subprocess.DEVNULL,
|
||||||
preexec_fn=None if _IS_WINDOWS else os.setsid,
|
preexec_fn=None if _IS_WINDOWS else os.setsid,
|
||||||
creationflags=subprocess.CREATE_NO_WINDOW if _IS_WINDOWS else 0,
|
**_popen_kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
session.process = proc
|
session.process = proc
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue