2026-06-08 10:08:25 -07:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
"""Check that subprocess calls in TUI-context code specify stdin=.
|
|
|
|
|
|
|
|
|
|
When Hermes runs in TUI mode, the gateway child process communicates with
|
|
|
|
|
the Node.js parent over a JSON-RPC protocol on stdin. Subprocess calls that
|
|
|
|
|
inherit this fd can cause the gateway to exit with stdin EOF during tool
|
|
|
|
|
execution (issue #14036, PR #39257).
|
|
|
|
|
|
|
|
|
|
This script checks that all subprocess.run() and subprocess.Popen() calls
|
2026-10-06 21:52:20 +05:30
|
|
|
in TUI-context files (agent/, tools/, plugins/, tui_gateway/,
|
|
|
|
|
optional-skills/) explicitly set stdin= to prevent fd inheritance.
|
2026-06-08 10:08:25 -07:00
|
|
|
|
|
|
|
|
Exit codes:
|
|
|
|
|
0 — all calls are safe
|
|
|
|
|
1 — violations found
|
|
|
|
|
2 — script error
|
|
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
|
python scripts/check_subprocess_stdin.py [--fix]
|
|
|
|
|
|
|
|
|
|
With --fix, prints the commands to add stdin=subprocess.DEVNULL to each
|
|
|
|
|
violation (does not modify files).
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
fix(compat): pointers resolve to the object that MOVED, not a same-named stranger; stdin checker binds stdin= to the splatted definition
Review findings on #102117 (independent reviewer + itsflownium):
* hermes_cli.kanban_db.connect / connect_closing pointed at hermes_cli.projects_db (different DB, no
board= parameter). The compat generator ranked candidate homes by path proximity when a name is
defined in several modules. Now it requires shape compatibility with the BASE definition (same
literal for constants, superset of parameter names for defs) and prefers the facade's own
<stem>_* sibling. Same class fixed for tools.tts_tool.DEFAULT_XAI_BASE_URL (-> tts_tool_providers),
and 17 constants/defs that had been pointed at same-named strangers (Matrix MAX_MESSAGE_LENGTH ->
Signal's 8000, tts MAX_TEXT_LENGTH -> BlueBubbles', honcho/retaindb/supermemory *_SCHEMA -> another
plugin's schema, ...) are now restored from BASE verbatim instead.
* send_yuanbao_direct (restored-def): body called adapter._outbound.send_direct, which HEAD moved to
the sender; rewritten to adapter._outbound.sender.send_direct.
* COMPAT_MANIFEST.md states the scope explicitly: public top-level names only; private names and
test monkeypatch seams are not preserved.
* scripts/check_subprocess_stdin.py: _splat_carries_stdin looked 30 lines ahead in the file text
and was satisfied by an unrelated later stdin=; it now finds the splatted name's definition via AST
and requires stdin inside that expression/body.
Tests: tests/test_compat_manifest_targets.py (pointer identity vs the facade's sibling; kanban
connect(board=) opens a Kanban DB, not projects.db; both FAIL on the previous layer),
test_subprocess_stdin_guard gains the false-negative probe, and the MoA -Q quiet-output contract
tests are back (tests/agent/test_moa_quiet_reference_output.py) against build_moa_facade.
2026-09-03 22:00:01 -07:00
|
|
|
import ast
|
2026-06-08 10:08:25 -07:00
|
|
|
import os
|
|
|
|
|
import sys
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
# Directories that run inside the TUI gateway child process.
|
|
|
|
|
TUI_CONTEXT_DIRS = [
|
|
|
|
|
"agent/",
|
|
|
|
|
"tools/",
|
|
|
|
|
"plugins/",
|
|
|
|
|
"tui_gateway/",
|
2026-10-06 21:52:20 +05:30
|
|
|
# Optional-skill scripts can run inside the backend process (a command
|
|
|
|
|
# builder calling a skill helper on a backend thread); their children would
|
|
|
|
|
# inherit the JSON-RPC stdin too.
|
|
|
|
|
"optional-skills/",
|
2026-06-08 10:08:25 -07:00
|
|
|
]
|
|
|
|
|
|
2026-07-20 05:12:01 +08:00
|
|
|
# User plugin roots — scanned at runtime if they exist. Plugins load from
|
2026-07-20 12:44:10 +05:30
|
|
|
# ``get_hermes_home() / "plugins"`` (user) and ``./.hermes/plugins/`` (project,
|
|
|
|
|
# gated behind ``HERMES_ENABLE_PROJECT_PLUGINS``) — see
|
|
|
|
|
# ``hermes_cli/plugins.py:10-12``. The guard only checked the bundled
|
|
|
|
|
# ``plugins/`` dir, missing user-installed code that spawns subprocesses
|
|
|
|
|
# (gap reported in #67639).
|
|
|
|
|
#
|
|
|
|
|
# Import is deferred to ``main()`` (after ``os.chdir(repo_root)``) because
|
|
|
|
|
# this script runs as a standalone subprocess — ``hermes_constants`` isn't
|
|
|
|
|
# on ``sys.path`` until the repo root is added.
|
2026-07-20 05:12:01 +08:00
|
|
|
|
|
|
|
|
# subprocess and os APIs that inherit stdin by default when called without
|
2026-10-06 23:32:31 +05:30
|
|
|
# an explicit stdin= argument, keyed by the module name the call is made on.
|
|
|
|
|
# Calls are found as ast.Call nodes, so arguments that start on the next line
|
|
|
|
|
# are checked too.
|
|
|
|
|
_INHERITING_CALLS = {
|
|
|
|
|
"subprocess": {"run", "Popen", "call", "check_output", "check_call"},
|
|
|
|
|
"os": {"system"},
|
|
|
|
|
"asyncio": {"create_subprocess_exec", "create_subprocess_shell"},
|
|
|
|
|
}
|
2026-07-20 05:12:01 +08:00
|
|
|
|
2026-06-08 10:08:25 -07:00
|
|
|
# Files with intentional stdin= override (e.g. input= creates a pipe).
|
|
|
|
|
# Format: "filepath:line" or just "filepath" to skip the whole file.
|
|
|
|
|
KNOWN_SAFE = {
|
|
|
|
|
"agent/shell_hooks.py", # uses input=stdin_json, creates a pipe
|
|
|
|
|
"plugins/security-guidance/patterns.py", # subprocess mentions are in reminder strings, not calls
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-08 22:12:18 -07:00
|
|
|
# Inline marker that exempts a single subprocess call from this check.
|
|
|
|
|
# Put it in a comment on (or within) the call when the process MUST inherit
|
|
|
|
|
# stdin — e.g. an interactive login the user explicitly invokes. Travels with
|
|
|
|
|
# the line, so it survives edits that shift line numbers (unlike a pinned
|
|
|
|
|
# file:line entry).
|
|
|
|
|
EXEMPT_MARKER = "noqa: subprocess-stdin"
|
|
|
|
|
|
2026-10-06 21:52:20 +05:30
|
|
|
# Directory names skipped at any depth below a context dir. Matching against the
|
|
|
|
|
# path relative to that dir keeps a skill's own ``scripts/`` folder in scope.
|
|
|
|
|
SKIP_DIRS = {"tests"}
|
2026-06-08 10:08:25 -07:00
|
|
|
|
|
|
|
|
|
2026-10-06 23:32:31 +05:30
|
|
|
def _definition_sets_stdin(tree: ast.AST, name: str) -> bool:
|
|
|
|
|
"""True when ``name`` is defined in the file (assignment or ``def``) and that
|
|
|
|
|
definition's OWN expression/body sets ``stdin=``.
|
fix(integration): restore subprocess encoding/stdin guards dropped in simplification
Simplification workers collapsed subprocess call sites into shared kwargs
helpers and dropped the Windows/TUI safety kwargs on the way:
- encoding='utf-8', errors='replace' restored on text=True runs in
copilot_acp_client, hermes_cli/setup (vercel install), managed_uv
(codesign steps), local_runtime/hardware._stdout, a2a adapter.
- stdin=subprocess.DEVNULL restored on copilot probe, verify/runner
_SUBPROCESS_KW, iron_proxy._run, google_meet playwright/system_profiler,
simplex convert, whatsapp _RUN_TEXT, mem0 ollama serve Popen.
google_meet sudo/brew install keeps inherited stdin (user-confirmed,
may prompt) — marked noqa: subprocess-stdin.
- Windows-safe SIGKILL: getattr(signal, 'SIGKILL', SIGTERM) in
verify/runner; photon _kill call re-marked windows-footgun: ok
(unreachable on win32).
- scripts/check_subprocess_stdin.py now recognizes **kwargs splats
(**_KW / **_kw(...)) ONLY when the same-file definition provably sets
stdin= — covers tui_gateway _capture_run_kwargs/run_kw. Parity test added.
2026-09-02 16:36:10 -07:00
|
|
|
|
|
|
|
|
Shared kwargs helpers (``_RUN_KW = dict(..., stdin=DEVNULL)``, ``def _run_kwargs(): return
|
|
|
|
|
dict(..., stdin=DEVNULL)``) legitimately carry the guard; we only accept them when the
|
fix(compat): pointers resolve to the object that MOVED, not a same-named stranger; stdin checker binds stdin= to the splatted definition
Review findings on #102117 (independent reviewer + itsflownium):
* hermes_cli.kanban_db.connect / connect_closing pointed at hermes_cli.projects_db (different DB, no
board= parameter). The compat generator ranked candidate homes by path proximity when a name is
defined in several modules. Now it requires shape compatibility with the BASE definition (same
literal for constants, superset of parameter names for defs) and prefers the facade's own
<stem>_* sibling. Same class fixed for tools.tts_tool.DEFAULT_XAI_BASE_URL (-> tts_tool_providers),
and 17 constants/defs that had been pointed at same-named strangers (Matrix MAX_MESSAGE_LENGTH ->
Signal's 8000, tts MAX_TEXT_LENGTH -> BlueBubbles', honcho/retaindb/supermemory *_SCHEMA -> another
plugin's schema, ...) are now restored from BASE verbatim instead.
* send_yuanbao_direct (restored-def): body called adapter._outbound.send_direct, which HEAD moved to
the sender; rewritten to adapter._outbound.sender.send_direct.
* COMPAT_MANIFEST.md states the scope explicitly: public top-level names only; private names and
test monkeypatch seams are not preserved.
* scripts/check_subprocess_stdin.py: _splat_carries_stdin looked 30 lines ahead in the file text
and was satisfied by an unrelated later stdin=; it now finds the splatted name's definition via AST
and requires stdin inside that expression/body.
Tests: tests/test_compat_manifest_targets.py (pointer identity vs the facade's sibling; kanban
connect(board=) opens a Kanban DB, not projects.db; both FAIL on the previous layer),
test_subprocess_stdin_guard gains the false-negative probe, and the MoA -Q quiet-output contract
tests are back (tests/agent/test_moa_quiet_reference_output.py) against build_moa_facade.
2026-09-03 22:00:01 -07:00
|
|
|
definition provably sets stdin= — never on the helper's name alone, and never because an
|
|
|
|
|
unrelated later call in the file happens to pass ``stdin=``.
|
fix(integration): restore subprocess encoding/stdin guards dropped in simplification
Simplification workers collapsed subprocess call sites into shared kwargs
helpers and dropped the Windows/TUI safety kwargs on the way:
- encoding='utf-8', errors='replace' restored on text=True runs in
copilot_acp_client, hermes_cli/setup (vercel install), managed_uv
(codesign steps), local_runtime/hardware._stdout, a2a adapter.
- stdin=subprocess.DEVNULL restored on copilot probe, verify/runner
_SUBPROCESS_KW, iron_proxy._run, google_meet playwright/system_profiler,
simplex convert, whatsapp _RUN_TEXT, mem0 ollama serve Popen.
google_meet sudo/brew install keeps inherited stdin (user-confirmed,
may prompt) — marked noqa: subprocess-stdin.
- Windows-safe SIGKILL: getattr(signal, 'SIGKILL', SIGTERM) in
verify/runner; photon _kill call re-marked windows-footgun: ok
(unreachable on win32).
- scripts/check_subprocess_stdin.py now recognizes **kwargs splats
(**_KW / **_kw(...)) ONLY when the same-file definition provably sets
stdin= — covers tui_gateway _capture_run_kwargs/run_kw. Parity test added.
2026-09-02 16:36:10 -07:00
|
|
|
"""
|
2026-10-06 23:32:31 +05:30
|
|
|
node = None
|
|
|
|
|
for n in ast.walk(tree):
|
|
|
|
|
if isinstance(n, (ast.FunctionDef, ast.AsyncFunctionDef)) and n.name == name:
|
|
|
|
|
node = n
|
|
|
|
|
break
|
|
|
|
|
if isinstance(n, (ast.Assign, ast.AnnAssign)):
|
|
|
|
|
targets = n.targets if isinstance(n, ast.Assign) else [n.target]
|
|
|
|
|
if any(isinstance(t, ast.Name) and t.id == name for t in targets):
|
|
|
|
|
node = n.value if n.value is not None else n
|
fix(compat): pointers resolve to the object that MOVED, not a same-named stranger; stdin checker binds stdin= to the splatted definition
Review findings on #102117 (independent reviewer + itsflownium):
* hermes_cli.kanban_db.connect / connect_closing pointed at hermes_cli.projects_db (different DB, no
board= parameter). The compat generator ranked candidate homes by path proximity when a name is
defined in several modules. Now it requires shape compatibility with the BASE definition (same
literal for constants, superset of parameter names for defs) and prefers the facade's own
<stem>_* sibling. Same class fixed for tools.tts_tool.DEFAULT_XAI_BASE_URL (-> tts_tool_providers),
and 17 constants/defs that had been pointed at same-named strangers (Matrix MAX_MESSAGE_LENGTH ->
Signal's 8000, tts MAX_TEXT_LENGTH -> BlueBubbles', honcho/retaindb/supermemory *_SCHEMA -> another
plugin's schema, ...) are now restored from BASE verbatim instead.
* send_yuanbao_direct (restored-def): body called adapter._outbound.send_direct, which HEAD moved to
the sender; rewritten to adapter._outbound.sender.send_direct.
* COMPAT_MANIFEST.md states the scope explicitly: public top-level names only; private names and
test monkeypatch seams are not preserved.
* scripts/check_subprocess_stdin.py: _splat_carries_stdin looked 30 lines ahead in the file text
and was satisfied by an unrelated later stdin=; it now finds the splatted name's definition via AST
and requires stdin inside that expression/body.
Tests: tests/test_compat_manifest_targets.py (pointer identity vs the facade's sibling; kanban
connect(board=) opens a Kanban DB, not projects.db; both FAIL on the previous layer),
test_subprocess_stdin_guard gains the false-negative probe, and the MoA -Q quiet-output contract
tests are back (tests/agent/test_moa_quiet_reference_output.py) against build_moa_facade.
2026-09-03 22:00:01 -07:00
|
|
|
break
|
2026-10-06 23:32:31 +05:30
|
|
|
return node is not None and _sets_stdin(node)
|
|
|
|
|
|
|
|
|
|
|
2026-10-06 23:51:18 +05:30
|
|
|
def _is_stdin_key(node: ast.AST | None) -> bool:
|
|
|
|
|
return isinstance(node, ast.Constant) and node.value == "stdin"
|
|
|
|
|
|
|
|
|
|
|
2026-10-06 23:32:31 +05:30
|
|
|
def _sets_stdin(node: ast.AST) -> bool:
|
2026-10-06 23:51:18 +05:30
|
|
|
"""stdin is set as a keyword (``dict(stdin=...)``), a dict-literal key (``{"stdin": ...}``),
|
|
|
|
|
a subscript store (``kw["stdin"] = ...``) or ``kw.setdefault("stdin", ...)``. A ``"stdin"``
|
|
|
|
|
string anywhere else (a value, a path) does not count."""
|
|
|
|
|
for sub in ast.walk(node):
|
|
|
|
|
if isinstance(sub, ast.keyword) and sub.arg == "stdin":
|
|
|
|
|
return True
|
|
|
|
|
if isinstance(sub, ast.Dict) and any(_is_stdin_key(key) for key in sub.keys):
|
|
|
|
|
return True
|
|
|
|
|
if isinstance(sub, ast.Subscript) and isinstance(sub.ctx, ast.Store) and _is_stdin_key(sub.slice):
|
|
|
|
|
return True
|
|
|
|
|
if (isinstance(sub, ast.Call) and isinstance(sub.func, ast.Attribute)
|
|
|
|
|
and sub.func.attr == "setdefault" and sub.args and _is_stdin_key(sub.args[0])):
|
|
|
|
|
return True
|
|
|
|
|
return False
|
2026-10-06 23:32:31 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
def _is_inheriting_call(call: ast.Call) -> bool:
|
|
|
|
|
"""``subprocess.run(...)``, ``os.system(...)`` etc., including ``x.subprocess.run(...)``."""
|
|
|
|
|
func = call.func
|
|
|
|
|
if not isinstance(func, ast.Attribute):
|
|
|
|
|
return False
|
|
|
|
|
owner = func.value
|
|
|
|
|
owner_name = owner.id if isinstance(owner, ast.Name) else getattr(owner, "attr", None)
|
|
|
|
|
return func.attr in _INHERITING_CALLS.get(owner_name, ())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _call_is_safe(call: ast.Call, tree: ast.AST) -> bool:
|
|
|
|
|
for kw in call.keywords:
|
|
|
|
|
# stdin= set, or input= (creates a pipe).
|
|
|
|
|
if kw.arg in ("stdin", "input"):
|
|
|
|
|
return True
|
|
|
|
|
if kw.arg is not None:
|
|
|
|
|
continue
|
2026-10-06 23:51:18 +05:30
|
|
|
# Inline splat that sets it: ``**dict(stdin=...)`` / ``**{"stdin": ...}``.
|
|
|
|
|
if _sets_stdin(kw.value):
|
|
|
|
|
return True
|
2026-10-06 23:32:31 +05:30
|
|
|
# ``**name`` / ``**name(...)`` splat: safe when the same-file definition sets stdin=.
|
|
|
|
|
value = kw.value.func if isinstance(kw.value, ast.Call) else kw.value
|
2026-10-06 23:51:18 +05:30
|
|
|
if isinstance(value, ast.Name) and _definition_sets_stdin(tree, value.id):
|
2026-10-06 23:32:31 +05:30
|
|
|
return True
|
|
|
|
|
return False
|
fix(integration): restore subprocess encoding/stdin guards dropped in simplification
Simplification workers collapsed subprocess call sites into shared kwargs
helpers and dropped the Windows/TUI safety kwargs on the way:
- encoding='utf-8', errors='replace' restored on text=True runs in
copilot_acp_client, hermes_cli/setup (vercel install), managed_uv
(codesign steps), local_runtime/hardware._stdout, a2a adapter.
- stdin=subprocess.DEVNULL restored on copilot probe, verify/runner
_SUBPROCESS_KW, iron_proxy._run, google_meet playwright/system_profiler,
simplex convert, whatsapp _RUN_TEXT, mem0 ollama serve Popen.
google_meet sudo/brew install keeps inherited stdin (user-confirmed,
may prompt) — marked noqa: subprocess-stdin.
- Windows-safe SIGKILL: getattr(signal, 'SIGKILL', SIGTERM) in
verify/runner; photon _kill call re-marked windows-footgun: ok
(unreachable on win32).
- scripts/check_subprocess_stdin.py now recognizes **kwargs splats
(**_KW / **_kw(...)) ONLY when the same-file definition provably sets
stdin= — covers tui_gateway _capture_run_kwargs/run_kw. Parity test added.
2026-09-02 16:36:10 -07:00
|
|
|
|
|
|
|
|
|
2026-06-08 10:08:25 -07:00
|
|
|
def find_subprocess_calls(content: str, filepath: str) -> list[dict]:
|
2026-07-20 05:12:01 +08:00
|
|
|
"""Find all subprocess/os/asyncio calls missing stdin= in content."""
|
2026-06-08 10:08:25 -07:00
|
|
|
lines = content.split("\n")
|
2026-10-06 23:32:31 +05:30
|
|
|
try:
|
|
|
|
|
tree = ast.parse(content)
|
|
|
|
|
except SyntaxError as exc:
|
|
|
|
|
# Fail closed: an unparsable file cannot be shown to be safe.
|
|
|
|
|
return [{"file": filepath, "line": exc.lineno or 1, "snippet": f"SyntaxError: {exc.msg}"}]
|
2026-06-08 10:08:25 -07:00
|
|
|
|
2026-10-06 23:32:31 +05:30
|
|
|
violations = []
|
|
|
|
|
for node in ast.walk(tree):
|
|
|
|
|
if not isinstance(node, ast.Call) or not _is_inheriting_call(node):
|
2026-06-08 10:08:25 -07:00
|
|
|
continue
|
2026-10-06 23:32:31 +05:30
|
|
|
if _call_is_safe(node, tree):
|
2026-06-08 10:08:25 -07:00
|
|
|
continue
|
2026-10-06 23:32:31 +05:30
|
|
|
# Inline exemption marker on the call itself or within the few comment
|
|
|
|
|
# lines immediately above it → the call intentionally inherits stdin.
|
|
|
|
|
start, end = node.lineno - 1, node.end_lineno or node.lineno
|
|
|
|
|
if EXEMPT_MARKER in "\n".join(lines[max(0, start - 4):end]):
|
2026-06-08 10:08:25 -07:00
|
|
|
continue
|
2026-10-06 23:32:31 +05:30
|
|
|
violations.append({
|
|
|
|
|
"file": filepath,
|
|
|
|
|
"line": node.lineno,
|
|
|
|
|
"snippet": lines[start].strip()[:120],
|
|
|
|
|
})
|
2026-06-08 10:08:25 -07:00
|
|
|
|
2026-10-06 23:32:31 +05:30
|
|
|
violations.sort(key=lambda v: v["line"])
|
2026-06-08 10:08:25 -07:00
|
|
|
return violations
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main() -> int:
|
|
|
|
|
fix_mode = "--fix" in sys.argv
|
|
|
|
|
repo_root = Path(__file__).resolve().parent.parent
|
|
|
|
|
os.chdir(repo_root)
|
|
|
|
|
|
2026-07-20 12:44:10 +05:30
|
|
|
# Add repo root to sys.path so we can import hermes_constants (this script
|
|
|
|
|
# runs as a standalone subprocess, not as a module).
|
|
|
|
|
sys.path.insert(0, str(repo_root))
|
|
|
|
|
from hermes_constants import get_hermes_home
|
|
|
|
|
|
2026-06-08 10:08:25 -07:00
|
|
|
all_violations = []
|
|
|
|
|
|
|
|
|
|
for tui_dir in TUI_CONTEXT_DIRS:
|
|
|
|
|
dirpath = repo_root / tui_dir
|
|
|
|
|
if not dirpath.exists():
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
for py_file in dirpath.rglob("*.py"):
|
|
|
|
|
rel = str(py_file.relative_to(repo_root))
|
|
|
|
|
|
fix(tests): make the test suite pass on Windows without regressing Linux
Gate the POSIX-only and symlink-only tests with the linux_only and
require_symlinks markers. Fix the real cross-platform bugs:
- file_operations: use the translate_path flag, send snippets as base64, and
use sys.executable (the MS Store python3 stub and the list2cmdline
backslash collapse both broke snippets)
- approval: treat backslash as a Windows path separator, not an escape
- registry, browser_registry, secret_sources, plugins: normalize scope-key case
- checkpoint_manager, plugins_cmd: clear read-only bits before delete
- deadline: make MAX_SAFE_TIMEOUT_S fit the Windows limit
- image_routing, acp, cua_backend, daytona: fix Windows and POSIX paths
- hermes_state: match backslash in the retag LIKE clause
- kanban, disk-cleanup: match drive paths and split command arguments
- scripts: emit host separators through as_posix
207 test files are gated or isolated.
2026-08-27 07:34:01 -07:00
|
|
|
# Skip known-safe files. ``relative_to`` returns a host-separated
|
|
|
|
|
# path (backslashes on Windows) while KNOWN_SAFE is forward-slash.
|
|
|
|
|
if py_file.relative_to(repo_root).as_posix() in KNOWN_SAFE:
|
2026-06-08 10:08:25 -07:00
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
# Skip test files inside tools/ etc.
|
2026-10-06 21:52:20 +05:30
|
|
|
if SKIP_DIRS & set(py_file.relative_to(dirpath).parts):
|
2026-06-08 10:08:25 -07:00
|
|
|
continue
|
|
|
|
|
|
2026-08-29 21:23:00 -04:00
|
|
|
content = py_file.read_text(encoding="utf-8-sig")
|
2026-06-08 10:08:25 -07:00
|
|
|
violations = find_subprocess_calls(content, rel)
|
|
|
|
|
all_violations.extend(violations)
|
|
|
|
|
|
2026-07-20 12:44:10 +05:30
|
|
|
# Scan user plugin directories (Gap 1: guard missed user-installed
|
|
|
|
|
# plugins in get_hermes_home()/plugins/ and project plugins in
|
|
|
|
|
# ./.hermes/plugins/, where code like ori/hooks.py can spawn
|
|
|
|
|
# subprocesses with inherited stdin — #67639).
|
|
|
|
|
plugin_roots: list[Path] = [get_hermes_home() / "plugins"]
|
|
|
|
|
if os.environ.get("HERMES_ENABLE_PROJECT_PLUGINS"):
|
|
|
|
|
plugin_roots.append(Path.cwd() / ".hermes" / "plugins")
|
2026-07-20 05:12:01 +08:00
|
|
|
seen_roots: set[Path] = set()
|
2026-07-20 12:44:10 +05:30
|
|
|
for plugin_root in plugin_roots:
|
2026-07-20 05:12:01 +08:00
|
|
|
resolved = plugin_root.resolve()
|
|
|
|
|
if resolved in seen_roots or not resolved.is_dir():
|
|
|
|
|
continue
|
|
|
|
|
seen_roots.add(resolved)
|
|
|
|
|
|
|
|
|
|
for py_file in resolved.rglob("*.py"):
|
|
|
|
|
rel = str(py_file)
|
|
|
|
|
if py_file.name in ("conftest.py",) or "/tests/" in rel:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
try:
|
2026-08-29 21:23:00 -04:00
|
|
|
content = py_file.read_text(encoding="utf-8-sig")
|
2026-07-20 05:12:01 +08:00
|
|
|
except Exception:
|
|
|
|
|
continue
|
|
|
|
|
violations = find_subprocess_calls(content, rel)
|
|
|
|
|
all_violations.extend(violations)
|
|
|
|
|
|
2026-06-08 10:08:25 -07:00
|
|
|
if all_violations:
|
|
|
|
|
print(f"❌ {len(all_violations)} subprocess calls missing stdin=:")
|
|
|
|
|
for v in all_violations:
|
|
|
|
|
print(f" {v['file']}:{v['line']}: {v['snippet']}")
|
|
|
|
|
if fix_mode:
|
|
|
|
|
print("\nAdd stdin=subprocess.DEVNULL to each call above.")
|
|
|
|
|
return 1
|
|
|
|
|
else:
|
|
|
|
|
print("✅ All TUI-context subprocess calls have explicit stdin=")
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
sys.exit(main())
|