The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(git): neutralize repository-named filters in subagent finalization, worktree reclaim and hermes -w
John Paul Soliva1ff01f4cf7a4
diff --git a/hermes_cli/worktree_ops.py b/hermes_cli/worktree_ops.pyindex 3975fe0b9f5..45e3dc7f147 100644--- a/hermes_cli/worktree_ops.py+++ b/hermes_cli/worktree_ops.py@@ -376,12 +376,18 @@ def _worktree_add(repo_root: str, wt_path: Path, branch_name: str, base_ref: strEvery failed attempt is swept with ``_cleanup_failed_worktree_add`` so the retry is not poisoned."""- from hermes_cli._subprocess_compat import noninteractive_git_env+ from hermes_cli._subprocess_compat import noninteractive_repo_git_env++ # The checkout runs repo-named smudge filters too; refuse when they cannot be neutralized.+ env = noninteractive_repo_git_env(repo_root)+ if env is None:+ _cprint("\033[31m✗ Failed to create worktree: could not read the repository's filter config\033[0m")+ return Nonedef _add(cfg):# 120s: on a multi-agent box the ~10k-file checkout contends for disk (113s measured under load).return _git([*cfg, "worktree", "add", str(wt_path), "-b", branch_name, base_ref], repo_root,- timeout=120, stdin=subprocess.DEVNULL, env=noninteractive_git_env())+ timeout=120, stdin=subprocess.DEVNULL, env=env)# checkout.workers parallelizes materialization; older git ignores unknown -c keys.try:@@ -546,8 +552,14 @@ def _worktree_is_dirty(worktree_path: str, repo_root, timeout: int = 10) -> boolignored: they are our own scaffolding, and counting them would keep every worktree of such arepo forever."""+ from hermes_cli._subprocess_compat import noninteractive_repo_git_envtry:- result = _git(["status", "--porcelain", "-z"], worktree_path, timeout=timeout)+ # Reclaimers run this unattended; status reads the index (core.fsmonitor, clean filters).+ env = noninteractive_repo_git_env(worktree_path)+ if env is None:+ return True+ result = _git(["status", "--porcelain", "-z"], worktree_path, timeout=timeout,+ stdin=subprocess.DEVNULL, env=env)if result.returncode != 0:return Trueentries = [e for e in result.stdout.split("\0") if e]diff --git a/tests/security/test_gitspawn_config_injection.py b/tests/security/test_gitspawn_config_injection.pyindex e7bb2dd0637..4f8cd907928 100644--- a/tests/security/test_gitspawn_config_injection.py+++ b/tests/security/test_gitspawn_config_injection.py@@ -193,9 +193,9 @@ def test_subagent_worktree_add_is_safe(malicious_repo, tmp_path):def test_index_reading_probes_and_kanban_gc_git_are_safe(malicious_repo, tmp_path):"""``status`` / ``ls-files`` / ``worktree add`` read the index, which runs ``core.fsmonitor``;``worktree add`` also runs the repository's hooks. Recovery hint, completion probe, kanban- worktree and worktree-gc ``status``."""+ worktree, worktree-gc ``status`` and the reclaimers' dirty probe (kanban teardown)."""from hermes_cli import kanban_db_workspace as kw- from hermes_cli import worktree_gc+ from hermes_cli import worktree_gc, worktree_opsfrom tools.async_delegation_recovery_hints import git_state_hintfrom tui_gateway import serverrepo, marker = malicious_repo@@ -204,7 +204,9 @@ def test_index_reading_probes_and_kanban_gc_git_are_safe(malicious_repo, tmp_patkw._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+ dirty = worktree_ops._worktree_is_dirty(str(tmp_path / "wt2"))assert _fired(marker) == []+ assert dirty is False # the probe ran: a skipped one reads as dirtydef test_repo_named_filters_never_run_from_kanban_gc_or_hints(tmp_path):@@ -237,6 +239,15 @@ def test_repo_named_filters_never_run_from_kanban_gc_or_hints(tmp_path):assert "- Status:" in build_coding_workspace_block(repo)sub = create_subagent_worktree(str(repo), "filters")assert sub is not None and (Path(sub["path"]) / "README").read_text() == "hi\n"+ # The subagent's automatic finalization and kanban teardown re-hash a touched file (status);+ # hermes -w checks out a worktree of its own.+ from hermes_cli import worktree_ops+ from tools.subagent_worktree import finalize_subagent_worktree+ for tree in (Path(sub["path"]), tmp_path / "wt"):+ os.utime(tree / "README", (time.time() + 120, time.time() + 120))+ assert "inspection_failed" not in finalize_subagent_worktree(sub, prune=False)+ assert worktree_ops._worktree_is_dirty(str(tmp_path / "wt")) is False+ assert worktree_ops._worktree_add(str(repo), tmp_path / "wt-w", "hermes/filters", "HEAD", "HEAD")assert sorted(p.name for p in tmp_path.glob("FILTER.*")) == []diff --git a/tools/subagent_worktree.py b/tools/subagent_worktree.pyindex f63191db9d8..d60ecab29fe 100644--- a/tools/subagent_worktree.py+++ b/tools/subagent_worktree.py@@ -152,13 +152,18 @@ def finalize_subagent_worktree(info: Dict[str, str], *, prune: bool = True) -> Dif not base_commit:return mark_worktree_payload_unproven(payload, "no base_commit recorded — commit count unmeasurable", unmeasured="commits")+ # The status probe re-hashes files the child touched, which runs repo-named clean filters.+ from hermes_cli._subprocess_compat import noninteractive_repo_git_env+ probe_env = noninteractive_repo_git_env(path)+ if probe_env is None:+ return mark_worktree_payload_unproven(payload, "filter discovery failed", unmeasured="dirty")failed, unmeasured = [], []probes = (("commits", "rev-list", ["rev-list", "--count", f"{base_commit}..HEAD"],lambda s: int(s or 0)),("dirty", "status", ["status", "--porcelain"], bool))try:for field, label, args, parse in probes:- res = _run_git(args, cwd=path)+ res = _run_git(args, cwd=path, env=probe_env)if res.returncode == 0:payload[field] = parse(res.stdout.strip())else: