The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(git): run the remaining index-reading git calls under noninteractive_git_env
John Paul Solivabba715b42dc9
diff --git a/hermes_cli/kanban_db_workspace.py b/hermes_cli/kanban_db_workspace.pyindex 48178d33aa0..dbf1e271180 100644--- a/hermes_cli/kanban_db_workspace.py+++ b/hermes_cli/kanban_db_workspace.py@@ -50,13 +50,20 @@ _WORKSPACE_ROW_SQL = "SELECT workspace_kind, workspace_path, branch_name FROM tadef _git(repo_root: Path, *args: str, timeout: int) -> subprocess.CompletedProcess:- """``git -C repo_root args``; never raises on a non-zero exit."""+ """``git -C repo_root args``; never raises on a non-zero exit.++ :func:`noninteractive_git_env` (GHSA-7x36-8jrh-v4pw): the dispatcher runs ``worktree add``+ unattended, which executes the repo's hooks and ``core.fsmonitor``.+ """+ from hermes_cli._subprocess_compat import noninteractive_git_envreturn subprocess.run(["git", "-C", str(repo_root), *args],capture_output=True,text=True, encoding='utf-8', errors='replace',timeout=timeout,check=False,+ stdin=subprocess.DEVNULL,+ env=noninteractive_git_env(),)diff --git a/hermes_cli/worktree_gc.py b/hermes_cli/worktree_gc.pyindex e8c3c0cf627..a036ea3686d 100644--- a/hermes_cli/worktree_gc.py+++ b/hermes_cli/worktree_gc.py@@ -50,9 +50,10 @@ class BranchRecord:reason: str-def _run(cmd: list, timeout: int, cwd: Optional[str] = None) -> subprocess.CompletedProcess:+def _run(cmd: list, timeout: int, cwd: Optional[str] = None,+ env: Optional[dict] = None) -> subprocess.CompletedProcess:return subprocess.run(cmd, capture_output=True, text=True, encoding="utf-8", errors="replace",- timeout=timeout, cwd=cwd)+ timeout=timeout, cwd=cwd, env=env, stdin=subprocess.DEVNULL)@dataclass@@ -70,9 +71,11 @@ class ExternalTreeRecord:def _git(args: list, cwd: str, timeout: int = 15) -> subprocess.CompletedProcess:"""Run git, translating timeouts into returncode 124. Every verdict fails safe toward "keep"on nonzero, so a slow ``git cherry`` on a huge repo degrades to keep instead of aborting the- audit mid-list."""+ audit mid-list. :func:`noninteractive_git_env` because ``status`` executes the repo's+ ``core.fsmonitor`` (GHSA-7x36-8jrh-v4pw)."""+ from hermes_cli._subprocess_compat import noninteractive_git_envtry:- return _run(["git", *args], timeout, cwd)+ return _run(["git", *args], timeout, cwd, env=noninteractive_git_env())except subprocess.TimeoutExpired:return subprocess.CompletedProcess(args=["git", *args], returncode=124, stdout="",stderr=f"timeout after {timeout}s")diff --git a/tests/security/test_gitspawn_config_injection.py b/tests/security/test_gitspawn_config_injection.pyindex e8d24ece55b..dae8b9dabff 100644--- a/tests/security/test_gitspawn_config_injection.py+++ b/tests/security/test_gitspawn_config_injection.py@@ -189,6 +189,26 @@ def test_subagent_worktree_add_is_safe(malicious_repo, tmp_path):assert _fired(marker) == []+def test_index_reading_session_probes_are_safe(malicious_repo):+ """``status`` / ``ls-files`` read the index, which runs ``core.fsmonitor``."""+ from tools.async_delegation_recovery_hints import git_state_hint+ from tui_gateway import server+ repo, marker = malicious_repo+ assert git_state_hint(str(repo)) is not None+ assert "README" in list(server._git_repo_files(str(repo)))+ assert _fired(marker) == []+++def test_kanban_and_gc_worktree_git_is_safe(malicious_repo, tmp_path):+ from hermes_cli import kanban_db_workspace as kw+ from hermes_cli import worktree_gc+ repo, marker = malicious_repo+ kw._ensure_git_worktree(repo, tmp_path / "wt2", "safe2")+ assert (tmp_path / "wt2" / "README").exists()+ assert worktree_gc._git(["status", "--porcelain"], cwd=str(repo)).returncode == 0+ assert _fired(marker) == []++def test_noninteractive_env_pins_fsmonitor_and_hooks():env = noninteractive_git_env({})values = {diff --git a/tools/async_delegation_recovery_hints.py b/tools/async_delegation_recovery_hints.pyindex 28e901e103d..5fc89f7aba7 100644--- a/tools/async_delegation_recovery_hints.py+++ b/tools/async_delegation_recovery_hints.py@@ -15,6 +15,8 @@ import osimport subprocessfrom typing import Dict, Optional+from hermes_cli._subprocess_compat import harden_git_argv, noninteractive_git_env+TAIL_LINES = 20TAIL_CHARS = 2_000_GIT_TIMEOUT_S = 5@@ -45,11 +47,14 @@ def git_state_hint(cwd: Optional[str]) -> Optional[str]:if not cwd or not os.path.isdir(cwd):return None+ # noninteractive_git_env (GHSA-7x36-8jrh-v4pw): runs unattended in the owner's repo and+ # ``status`` refreshes the index, which executes a repo-configured ``core.fsmonitor``.def run(*args: str) -> Optional[str]:try:- out = subprocess.run(["git", "-C", cwd, *args], capture_output=True,+ out = subprocess.run(["git", "-C", cwd, *harden_git_argv(args)], capture_output=True,text=True, encoding="utf-8", errors="replace",- stdin=subprocess.DEVNULL, timeout=_GIT_TIMEOUT_S)+ stdin=subprocess.DEVNULL, timeout=_GIT_TIMEOUT_S,+ env=noninteractive_git_env())except (OSError, subprocess.SubprocessError):return Nonereturn out.stdout if out.returncode == 0 else Nonediff --git a/tui_gateway/methods_complete_helpers.py b/tui_gateway/methods_complete_helpers.pyindex d64d64e152f..d68b04423e9 100644--- a/tui_gateway/methods_complete_helpers.py+++ b/tui_gateway/methods_complete_helpers.py@@ -23,9 +23,13 @@ _fuzzy_cache: dict[str, tuple[float, list[str]]] = {}def _git_repo_files(root: str):"""Yield ``git ls-files`` paths (tracked + untracked) relative to ``root``; empty outside a- repo or on git failure/timeout. Entries above ``root`` are skipped (Cmd-P workspace scope)."""- from hermes_cli._subprocess_compat import windows_hide_flags- run_kw = dict(capture_output=True, timeout=2.0, check=False, stdin=subprocess.DEVNULL, creationflags=windows_hide_flags())+ repo or on git failure/timeout. Entries above ``root`` are skipped (Cmd-P workspace scope).++ :func:`noninteractive_git_env` (GHSA-7x36-8jrh-v4pw): runs on a keystroke in the session cwd,+ and ``ls-files`` reads the index, which executes a repo-configured ``core.fsmonitor``."""+ from hermes_cli._subprocess_compat import noninteractive_git_env, windows_hide_flags+ run_kw = dict(capture_output=True, timeout=2.0, check=False, stdin=subprocess.DEVNULL,+ creationflags=windows_hide_flags(), env=noninteractive_git_env())try:top_result = subprocess.run(["git", "-C", root, "rev-parse", "--show-toplevel"], **run_kw)if top_result.returncode != 0: