The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(git): neutralize repository-named filters at the kanban, worktree-gc and recovery-hint calls
John Paul Soliva9c589b91bdb5
diff --git a/hermes_cli/kanban_db_workspace.py b/hermes_cli/kanban_db_workspace.pyindex dbf1e271180..6f7d0b2aebb 100644--- a/hermes_cli/kanban_db_workspace.py+++ b/hermes_cli/kanban_db_workspace.py@@ -52,10 +52,13 @@ _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.- :func:`noninteractive_git_env` (GHSA-7x36-8jrh-v4pw): the dispatcher runs ``worktree add``- unattended, which executes the repo's hooks and ``core.fsmonitor``.+ :func:`noninteractive_repo_git_env` (GHSA-7x36-8jrh-v4pw): the dispatcher runs ``worktree add``+ unattended, which executes the repo's hooks, ``core.fsmonitor`` and smudge filters."""- from hermes_cli._subprocess_compat import noninteractive_git_env+ from hermes_cli._subprocess_compat import noninteractive_repo_git_env+ env = noninteractive_repo_git_env(repo_root)+ if env is None:+ return subprocess.CompletedProcess(["git", "-C", str(repo_root), *args], 1, "", "git filter discovery failed")return subprocess.run(["git", "-C", str(repo_root), *args],capture_output=True,@@ -63,7 +66,7 @@ def _git(repo_root: Path, *args: str, timeout: int) -> subprocess.CompletedProcetimeout=timeout,check=False,stdin=subprocess.DEVNULL,- env=noninteractive_git_env(),+ env=env,)diff --git a/hermes_cli/worktree_gc.py b/hermes_cli/worktree_gc.pyindex a036ea3686d..48fdd65a275 100644--- a/hermes_cli/worktree_gc.py+++ b/hermes_cli/worktree_gc.py@@ -71,11 +71,15 @@ 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. :func:`noninteractive_git_env` because ``status`` executes the repo's- ``core.fsmonitor`` (GHSA-7x36-8jrh-v4pw)."""- from hermes_cli._subprocess_compat import noninteractive_git_env+ audit mid-list. :func:`noninteractive_repo_git_env` because ``status`` executes the repo's+ ``core.fsmonitor`` and clean filters (GHSA-7x36-8jrh-v4pw)."""+ from hermes_cli._subprocess_compat import noninteractive_repo_git_env+ env = noninteractive_repo_git_env(cwd)+ if env is None:+ return subprocess.CompletedProcess(args=["git", *args], returncode=1, stdout="",+ stderr="git filter discovery failed")try:- return _run(["git", *args], timeout, cwd, env=noninteractive_git_env())+ return _run(["git", *args], timeout, cwd, env=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 dae8b9dabff..3ae191ac41c 100644--- a/tests/security/test_gitspawn_config_injection.py+++ b/tests/security/test_gitspawn_config_injection.py@@ -18,6 +18,7 @@ from __future__ import annotationsimport osimport shutilimport subprocess+import timefrom pathlib import Pathimport pytest@@ -209,6 +210,33 @@ def test_kanban_and_gc_worktree_git_is_safe(malicious_repo, tmp_path):assert _fired(marker) == []+def test_repo_named_filters_never_run_from_kanban_gc_or_hints(tmp_path):+ """A filter driver is named by ``.gitattributes``, so the fixed env pins cannot reach it:+ ``worktree add`` runs its smudge command and ``status`` its clean command."""+ from hermes_cli import kanban_db_workspace as kw+ from hermes_cli import worktree_gc+ from tools.async_delegation_recovery_hints import git_state_hint+ clean = {**os.environ, "GIT_CONFIG_GLOBAL": os.devnull, "GIT_CONFIG_SYSTEM": os.devnull, "GIT_CONFIG_NOSYSTEM": "1"}+ repo, marker = tmp_path / "repo", (tmp_path / "FILTER").as_posix()+ subprocess.run(["git", "init", "-q", str(repo)], check=True, env=clean)+ (repo / "README").write_text("hi\n")+ (repo / ".gitattributes").write_text("README filter=evil\n")+ ident = ["-c", "user.email=a@b", "-c", "user.name=a"]+ subprocess.run(["git", "-C", str(repo), *ident, "add", "."], check=True, env=clean)+ subprocess.run(["git", "-C", str(repo), *ident, "commit", "-qm", "init"], check=True, env=clean)+ for key, value in {"filter.evil.smudge": f"touch '{marker}.smudge'; cat",+ "filter.evil.clean": f"touch '{marker}.clean'; cat", "filter.evil.required": "true"}.items():+ subprocess.run(["git", "-C", str(repo), "config", key, value], check=True, env=clean)++ kw._ensure_git_worktree(repo, tmp_path / "wt", "safe")+ assert (tmp_path / "wt" / "README").read_text() == "hi\n"+ (repo / "README").write_text("hi\n") # same size, new mtime: status must re-hash it+ os.utime(repo / "README", (time.time() + 60, time.time() + 60))+ assert worktree_gc._git(["status", "--porcelain"], cwd=str(repo)).returncode == 0+ assert git_state_hint(str(repo)) is not None+ assert sorted(p.name for p in tmp_path.glob("FILTER.*")) == []++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 5fc89f7aba7..15001f9a369 100644--- a/tools/async_delegation_recovery_hints.py+++ b/tools/async_delegation_recovery_hints.py@@ -15,7 +15,7 @@ import osimport subprocessfrom typing import Dict, Optional-from hermes_cli._subprocess_compat import harden_git_argv, noninteractive_git_env+from hermes_cli._subprocess_compat import harden_git_argv, noninteractive_repo_git_envTAIL_LINES = 20TAIL_CHARS = 2_000@@ -47,14 +47,17 @@ 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``.+ # noninteractive_repo_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`` and clean filters.+ env = noninteractive_repo_git_env(cwd)+ if env is None:+ return None+def run(*args: str) -> Optional[str]:try: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,- env=noninteractive_git_env())+ stdin=subprocess.DEVNULL, timeout=_GIT_TIMEOUT_S, env=env)except (OSError, subprocess.SubprocessError):return Nonereturn out.stdout if out.returncode == 0 else None