diff --git a/backend/packages/harness/deerflow/sandbox/search.py b/backend/packages/harness/deerflow/sandbox/search.py index 90e0c1b8ae..70bb77e50f 100644 --- a/backend/packages/harness/deerflow/sandbox/search.py +++ b/backend/packages/harness/deerflow/sandbox/search.py @@ -118,8 +118,7 @@ def should_ignore_name(name: str) -> bool: def _names_user_data(pattern: str) -> bool: - name = pattern.rsplit("/", 1)[-1] - return any(fnmatch.fnmatchcase(name, candidate) for candidate in USER_DATA_PATTERNS) + return any(fnmatch.fnmatchcase(part, candidate) for part in pattern.split("/") for candidate in USER_DATA_PATTERNS) def ignore_rules_for(search_root: Path, *, glob: str | None = None, user_data: bool = False) -> IgnoreRules: diff --git a/backend/tests/test_sandbox_search_user_files.py b/backend/tests/test_sandbox_search_user_files.py index 92567d4b5c..f9233e3632 100644 --- a/backend/tests/test_sandbox_search_user_files.py +++ b/backend/tests/test_sandbox_search_user_files.py @@ -12,6 +12,8 @@ from __future__ import annotations from pathlib import Path from types import SimpleNamespace +import pytest + from deerflow.sandbox.local.list_dir import list_dir from deerflow.sandbox.local.local_sandbox import LocalSandbox, PathMapping from deerflow.sandbox.search import ( @@ -79,6 +81,33 @@ def test_an_explicit_glob_wins_inside_a_checkout(tmp_path: Path) -> None: assert [Path(match.path).name for match in matches] == ["app.log"] +@pytest.mark.parametrize("directory", ["logs", ".cache", "reports.log"]) +@pytest.mark.parametrize("recursive", [False, True]) +def test_explicit_data_directory_globs_reach_local_sandbox_files(tmp_path: Path, directory: str, recursive: bool) -> None: + checkout = tmp_path / "checkout" + target = checkout / directory / "report.txt" + target.parent.mkdir(parents=True) + target.write_bytes(b"FATAL diagnostic\n") + for hidden in (".git", "node_modules"): + noise = checkout / hidden / directory / "noise.txt" + noise.parent.mkdir(parents=True) + noise.write_bytes(b"FATAL repository noise\n") + (target.parent / ".upload-pending.part").write_bytes(b"FATAL incomplete\n") + sandbox = LocalSandbox("local", [PathMapping("/mnt/skills/public", str(checkout))]) + root = "/mnt/skills/public" + pattern = f"{'**/' if recursive else ''}{directory}/*" + + files, truncated = sandbox.glob(root, pattern) + assert files == [f"{root}/{directory}/report.txt"] + assert not truncated + matches, truncated = sandbox.grep(root, "FATAL", glob=pattern) + assert [(match.path, match.line) for match in matches] == [(f"{root}/{directory}/report.txt", "FATAL diagnostic")] + assert not truncated + # An unfiltered search still treats these directories as repository noise. + assert sandbox.glob(root, "**/*")[0] == [] + assert sandbox.grep(root, "FATAL")[0] == [] + + def test_a_file_named_as_the_root_is_read_above_the_size_bound(tmp_path: Path) -> None: uploads = tmp_path / "uploads" uploads.mkdir() diff --git a/docs/guide/sandbox.md b/docs/guide/sandbox.md index 8209fd2a45..e70705d725 100644 --- a/docs/guide/sandbox.md +++ b/docs/guide/sandbox.md @@ -26,6 +26,12 @@ filtering and read-only mounts still apply. Configured category mounts such as category mount stops the root search, and the Gateway warning log identifies its virtual path. +Explicit `glob` patterns and `grep` file filters can name data directories such +as `logs/*.txt`, `**/logs/*.txt` or `.cache/*.txt`, even outside the user-data +mounts. Generic searches keep ignoring those directories outside user data. +Repository metadata, dependency directories and in-flight `.upload-*.part` +files remain filtered. + Sandbox references in conversation state are server-owned. External run and thread-state APIs reject caller-supplied `sandbox` values; when restoring a checkpoint, the runtime resolves the reference against the authenticated user