Files
hermes-agent/agent/search_policy.py
Brooklyn Nicholson 018d982bd9 fix(agent): a home working dir is a fallback, not a project
The packaged Desktop with no default project dir resolves its spawn cwd (and
TERMINAL_CWD) to $HOME, and SubdirectoryHintTracker's containment check is
then vacuously true for the whole home subtree: any AGENTS.md, CLAUDE.md or
.cursorrules under ~ is injected into tool results on first touch. The
tracker now treats a home (or container-home) working dir as a fallback, not
a project — hint discovery stays off until the session adopts a real
workspace, and _register_session_cwd re-anchors it there (same hook that
already updates agent.session_cwd). AIAgent init also prefers the session's
own cwd over the launch TERMINAL_CWD, so an agent built for a workspace
session scopes hints to it from the start. .archive joins the excluded dir
names (retired skills trees hold stale AGENTS.md copies).

Rebases the home guard from #77145 (idea + guard direction) onto the current
class shape; covers the install-tree shape #75922 targeted via the shared
home guard.

Fixes #76902
Ref: https://github.com/NousResearch/hermes-agent/issues/75839

Co-authored-by: Sahil-SS9 <218421507+Sahil-SS9@users.noreply.github.com>
2026-09-29 14:53:00 -05:00

35 lines
1.5 KiB
Python

"""Shared directory pruning policy for broad recursive scans.
These names identify version-control internals, dependency trees, generated
artifacts, caches, and backup copies that are not useful results for broad
agent-facing discovery. Ordinary search callers may still target an explicit
path; broad diagnostic probes should apply this policy to recursive walks.
"""
from __future__ import annotations
# Keep this policy conservative and name-based so it works for local and remote
# shell backends alike. The same set is used by context discovery and search
# probes; adding a directory here protects every broad recursive consumer.
SEARCH_PRUNE_DIR_NAMES = frozenset({
# Version-control internals.
".git", ".hg", ".svn",
# Dependency and vendored trees.
"node_modules", "venv", ".venv", "site-packages", "dist-packages",
"vendor", "third_party",
# Generated/build output.
"build", "dist", "target", "out", "coverage",
".next", ".turbo", ".parcel-cache", ".nuxt", ".svelte-kit",
# Archived trees: stale copies of projects that used to be live workspaces
# (~/.hermes/skills/.archive/ holds dozens of retired skills, each of which
# can carry an AGENTS.md — #76902).
".archive",
# Python and package-manager caches.
"__pycache__", ".cache", ".Trash", ".tox", ".nox", ".mypy_cache",
".pytest_cache", ".ruff_cache", ".npm", ".yarn", ".pnpm-store",
".gradle", ".m2", ".nuget",
# Backup copies.
"backups", "backup", ".backups",
})