pyddock 0.3.4__tar.gz → 0.3.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyddock-0.3.4 → pyddock-0.3.5}/PKG-INFO +2 -2
- {pyddock-0.3.4 → pyddock-0.3.5}/README.md +1 -1
- {pyddock-0.3.4 → pyddock-0.3.5}/pyproject.toml +1 -1
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/server.py +3 -1
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/tools/fs_grep.py +15 -1
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/test_file_tools.py +25 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/uv.lock +1 -1
- {pyddock-0.3.4 → pyddock-0.3.5}/.gitignore +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/.hypothesis/.gitignore +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/.hypothesis/constants/106d94c8123c0256 +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/.hypothesis/constants/1685e03b3aa38c02 +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/.hypothesis/constants/1deca112ec6f2f3c +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/.hypothesis/constants/2488a3a95c48acfb +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/.hypothesis/constants/2a94d83a13979745 +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/.hypothesis/constants/499f1d5a639a382a +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/.hypothesis/constants/4ee6f24fa151b65d +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/.hypothesis/constants/5b1b2189b70f5ef2 +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/.hypothesis/constants/5d6f8b26b2137fe1 +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/.hypothesis/constants/61f9b905d7da14e0 +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/.hypothesis/constants/67a7f4ab2d372f23 +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/.hypothesis/constants/6c6f5083ece3f86b +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/.hypothesis/constants/827e18b40f235443 +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/.hypothesis/constants/8401e4039d635fbc +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/.hypothesis/constants/8490e7baefc8c8c3 +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/.hypothesis/constants/a7c132b836381d0d +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/.hypothesis/constants/b395547bc71e5c52 +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/.hypothesis/constants/ca50661510a40488 +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/.hypothesis/tmp/tmpl8oe65gb +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/.hypothesis/tmp/tmpqwper0dp +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/.hypothesis/unicode_data/15.1.0/charmap.json.gz +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/.hypothesis/unicode_data/15.1.0/codec-utf-8.json.gz +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/LICENSE +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/publish-to-pypi.ps1 +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/__init__.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/_audit_enforcement.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/_base.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/_enforcement.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/_fs_enforcement.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/_import_hook.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/_prewarm.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/_process_utils.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/_proxies.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/_runtime.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/_subprocess_patch.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/ast_validator.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/cli.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/config.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/default_config.toml +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/executor.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/script_registry.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/shell_executor.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/tools/__init__.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/tools/fs_append.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/tools/fs_delete.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/tools/fs_find.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/tools/read_file.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/tools/stat_file.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/tools/str_replace.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/src/pyddock/venv_manager.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/__init__.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/_config_helpers.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/test_ast_properties.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/test_attr_reflection_hardening.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/test_audit_hook_backstop.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/test_chmod_integration.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/test_config.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/test_deny_always_wins.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/test_deny_messages.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/test_env_policy.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/test_executor.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/test_filesystem_guards.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/test_jailbreak_regression.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/test_proxy_properties.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/test_realistic.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/test_runtime.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/test_sandbox_escape_hardening.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/test_security_guards.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/test_server.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/test_shell_arg_paths.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/test_shell_executor.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/test_shell_properties.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/test_subprocess_enforcement.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/test_subprocess_properties.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/test_subst_trusted_path.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/test_trusted_prefixes_uv_cache.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/test_venv_stamp.py +0 -0
- {pyddock-0.3.4 → pyddock-0.3.5}/tests/test_workspace_imports.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyddock
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.5
|
|
4
4
|
Summary: MCP server that gives AI agents pre-approved Python, shell, and file I/O tools with declarative policy controls
|
|
5
5
|
Project-URL: Homepage, https://github.com/portablestew/pyddock
|
|
6
6
|
Project-URL: Repository, https://github.com/portablestew/pyddock
|
|
@@ -110,7 +110,7 @@ Pyddock also exposes file I/O tools that execute through the same sandbox as `ru
|
|
|
110
110
|
- **`fs_readfile`** — Read a text file. Lines are 1-indexed; negative start = tail. Truncates large output with a continuation hint.
|
|
111
111
|
- **`fs_stat`** — File metadata (exists, type, size, line count, modified). Returns `exists: false` for missing paths.
|
|
112
112
|
- **`fs_find`** — Find files by name (`file_glob` match, recursive). Prunes hidden dot-directories and `exclude_regex` matches before descending (never walked, not just filtered), so large ignored trees (`.venv/`, `node_modules/`) stay fast. Returns matching relative paths, capped at `max_results`.
|
|
113
|
-
- **`fs_grep`** — Search file contents by `grep_regex` (always case-insensitive). Same hidden-directory pruning and `exclude_regex` as `fs_find`. Returns `path:line: content` per match, capped at `max_results` and 300 chars per line. Skips binary files when scanning a directory; always searches a directly named file.
|
|
113
|
+
- **`fs_grep`** — Search file contents by `grep_regex` (always case-insensitive). Same hidden-directory pruning and `exclude_regex` as `fs_find`. Returns `path:line: content` per match, capped at `max_results` and 300 chars per line, with an optional `max_results_per_file` cap. Skips binary files when scanning a directory; always searches a directly named file.
|
|
114
114
|
- **`fs_append`** — Append to a file (creates if missing). Returns a unified diff.
|
|
115
115
|
- **`fs_delete`** — Delete a file or empty directory. Returns a unified diff of removed content.
|
|
116
116
|
- **`fs_str_replace`** — Find-and-replace exact text (unique match required). Returns a unified diff, or match diagnostics on failure.
|
|
@@ -86,7 +86,7 @@ Pyddock also exposes file I/O tools that execute through the same sandbox as `ru
|
|
|
86
86
|
- **`fs_readfile`** — Read a text file. Lines are 1-indexed; negative start = tail. Truncates large output with a continuation hint.
|
|
87
87
|
- **`fs_stat`** — File metadata (exists, type, size, line count, modified). Returns `exists: false` for missing paths.
|
|
88
88
|
- **`fs_find`** — Find files by name (`file_glob` match, recursive). Prunes hidden dot-directories and `exclude_regex` matches before descending (never walked, not just filtered), so large ignored trees (`.venv/`, `node_modules/`) stay fast. Returns matching relative paths, capped at `max_results`.
|
|
89
|
-
- **`fs_grep`** — Search file contents by `grep_regex` (always case-insensitive). Same hidden-directory pruning and `exclude_regex` as `fs_find`. Returns `path:line: content` per match, capped at `max_results` and 300 chars per line. Skips binary files when scanning a directory; always searches a directly named file.
|
|
89
|
+
- **`fs_grep`** — Search file contents by `grep_regex` (always case-insensitive). Same hidden-directory pruning and `exclude_regex` as `fs_find`. Returns `path:line: content` per match, capped at `max_results` and 300 chars per line, with an optional `max_results_per_file` cap. Skips binary files when scanning a directory; always searches a directly named file.
|
|
90
90
|
- **`fs_append`** — Append to a file (creates if missing). Returns a unified diff.
|
|
91
91
|
- **`fs_delete`** — Delete a file or empty directory. Returns a unified diff of removed content.
|
|
92
92
|
- **`fs_str_replace`** — Find-and-replace exact text (unique match required). Returns a unified diff, or match diagnostics on failure.
|
|
@@ -385,7 +385,7 @@ def create_server(workspace: Path | None = None, debug: bool = False) -> FastMCP
|
|
|
385
385
|
"grep_regex is searched within each file matched by file_glob (glob,\n"
|
|
386
386
|
"default '*') under path (default: workspace root). Returns\n"
|
|
387
387
|
"'path:line: content' per match, capped at max_results (default: 100)\n"
|
|
388
|
-
"and 300 chars per line.\n"
|
|
388
|
+
"and 300 chars per line. Optional max_results_per_file caps matches per file.\n"
|
|
389
389
|
"\n"
|
|
390
390
|
"Binary files are skipped when scanning a directory path. A single named\n"
|
|
391
391
|
"file is always searched."
|
|
@@ -398,6 +398,7 @@ def create_server(workspace: Path | None = None, debug: bool = False) -> FastMCP
|
|
|
398
398
|
path: str | None = None,
|
|
399
399
|
exclude_regex: str | None = None,
|
|
400
400
|
max_results: int | None = None,
|
|
401
|
+
max_results_per_file: int | None = None,
|
|
401
402
|
) -> str:
|
|
402
403
|
if not grep_regex:
|
|
403
404
|
return "Error: 'grep_regex' is required and must be non-empty."
|
|
@@ -407,6 +408,7 @@ def create_server(workspace: Path | None = None, debug: bool = False) -> FastMCP
|
|
|
407
408
|
"path": path,
|
|
408
409
|
"exclude_regex": exclude_regex,
|
|
409
410
|
"max_results": max_results,
|
|
411
|
+
"max_results_per_file": max_results_per_file,
|
|
410
412
|
})
|
|
411
413
|
|
|
412
414
|
return mcp
|
|
@@ -13,6 +13,8 @@ where '*' does not match a leading dot but an explicit pattern does.
|
|
|
13
13
|
Binary files are skipped when scanning a directory path (sniffed from the
|
|
14
14
|
same read used for matching — no separate open). A single named file is
|
|
15
15
|
always searched, binary or not.
|
|
16
|
+
|
|
17
|
+
max_results_per_file (optional) caps matches per individual file.
|
|
16
18
|
"""
|
|
17
19
|
import os
|
|
18
20
|
import re
|
|
@@ -25,6 +27,7 @@ file_glob = _PARAMS.get("file_glob") or "*"
|
|
|
25
27
|
path_str = _PARAMS.get("path") or "."
|
|
26
28
|
exclude_regex = _PARAMS.get("exclude_regex")
|
|
27
29
|
max_results = _PARAMS.get("max_results") or 100
|
|
30
|
+
max_results_per_file = _PARAMS.get("max_results_per_file")
|
|
28
31
|
workspace_root = _PARAMS["workspace_root"]
|
|
29
32
|
|
|
30
33
|
# --- Constants ---
|
|
@@ -196,12 +199,16 @@ if path.is_file():
|
|
|
196
199
|
|
|
197
200
|
if text is not None:
|
|
198
201
|
label = display_path(path)
|
|
202
|
+
file_match_count = 0
|
|
199
203
|
for line_num, line in enumerate(text.splitlines(), start=1):
|
|
200
204
|
if regex.search(line):
|
|
201
205
|
matches.append(f"{label}:{line_num}: {truncate_line(line)}")
|
|
206
|
+
file_match_count += 1
|
|
202
207
|
if len(matches) >= max_results:
|
|
203
208
|
truncated = True
|
|
204
209
|
break
|
|
210
|
+
if max_results_per_file and file_match_count >= max_results_per_file:
|
|
211
|
+
break
|
|
205
212
|
else:
|
|
206
213
|
# Single pass: walk, filter, and match together so max_results can stop
|
|
207
214
|
# the walk early instead of enumerating the entire (pruned) tree first.
|
|
@@ -246,18 +253,25 @@ else:
|
|
|
246
253
|
continue
|
|
247
254
|
|
|
248
255
|
label = display_path(candidate)
|
|
256
|
+
file_match_count = 0
|
|
249
257
|
for line_num, line in enumerate(text.splitlines(), start=1):
|
|
250
258
|
if regex.search(line):
|
|
251
259
|
matches.append(f"{label}:{line_num}: {truncate_line(line)}")
|
|
260
|
+
file_match_count += 1
|
|
252
261
|
if len(matches) >= max_results:
|
|
253
262
|
truncated = True
|
|
254
263
|
break
|
|
264
|
+
if max_results_per_file and file_match_count >= max_results_per_file:
|
|
265
|
+
break
|
|
255
266
|
if truncated:
|
|
256
267
|
break
|
|
257
268
|
|
|
258
269
|
notes = []
|
|
259
270
|
if truncated:
|
|
260
|
-
notes.append(
|
|
271
|
+
notes.append(
|
|
272
|
+
f"Showing first {max_results} matches. To see more: narrow path, "
|
|
273
|
+
f"grep_regex, or set max_results_per_file."
|
|
274
|
+
)
|
|
261
275
|
if skipped_binary:
|
|
262
276
|
notes.append(f"{skipped_binary} binary file(s) skipped.")
|
|
263
277
|
if skipped_unreadable:
|
|
@@ -618,6 +618,31 @@ class TestFsGrep:
|
|
|
618
618
|
assert "Showing first 3 matches" in result
|
|
619
619
|
assert result.count("needle") == 3
|
|
620
620
|
|
|
621
|
+
def test_max_results_per_file_caps_matches_within_a_file(self, ws: Path, registry: ScriptToolRegistry):
|
|
622
|
+
"""max_results_per_file limits matches contributed by a single file
|
|
623
|
+
during a directory scan, preserving breadth across other files."""
|
|
624
|
+
dense = ws / "dense.txt"
|
|
625
|
+
dense.write_text("needle\n" * 10, encoding="utf-8")
|
|
626
|
+
sparse = ws / "sparse.txt"
|
|
627
|
+
sparse.write_text("needle\n", encoding="utf-8")
|
|
628
|
+
|
|
629
|
+
result = run(registry, "fs_grep", {
|
|
630
|
+
"grep_regex": "needle", "path": str(ws), "max_results_per_file": 2,
|
|
631
|
+
})
|
|
632
|
+
assert result.count("dense.txt") == 2
|
|
633
|
+
assert "sparse.txt" in result
|
|
634
|
+
|
|
635
|
+
def test_max_results_per_file_applies_to_directly_named_file(self, ws: Path, registry: ScriptToolRegistry):
|
|
636
|
+
"""max_results_per_file also caps matches when path names a single
|
|
637
|
+
file directly, not just during a directory walk."""
|
|
638
|
+
f = ws / "dense.txt"
|
|
639
|
+
f.write_text("needle\n" * 10, encoding="utf-8")
|
|
640
|
+
|
|
641
|
+
result = run(registry, "fs_grep", {
|
|
642
|
+
"grep_regex": "needle", "path": str(f), "max_results_per_file": 3,
|
|
643
|
+
})
|
|
644
|
+
assert result.count("dense.txt") == 3
|
|
645
|
+
|
|
621
646
|
|
|
622
647
|
# =============================================================================
|
|
623
648
|
# Sandbox enforcement tests
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|