pyddock 0.3.3__tar.gz → 0.3.4__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.3 → pyddock-0.3.4}/PKG-INFO +4 -2
- {pyddock-0.3.3 → pyddock-0.3.4}/README.md +3 -1
- {pyddock-0.3.3 → pyddock-0.3.4}/publish-to-pypi.ps1 +9 -3
- {pyddock-0.3.3 → pyddock-0.3.4}/pyproject.toml +1 -1
- {pyddock-0.3.3 → pyddock-0.3.4}/src/pyddock/server.py +59 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/src/pyddock/tools/fs_append.py +8 -3
- {pyddock-0.3.3 → pyddock-0.3.4}/src/pyddock/tools/fs_delete.py +8 -3
- pyddock-0.3.4/src/pyddock/tools/fs_find.py +203 -0
- pyddock-0.3.4/src/pyddock/tools/fs_grep.py +279 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/src/pyddock/tools/read_file.py +8 -3
- {pyddock-0.3.3 → pyddock-0.3.4}/src/pyddock/tools/stat_file.py +8 -3
- {pyddock-0.3.3 → pyddock-0.3.4}/src/pyddock/tools/str_replace.py +8 -3
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/test_file_tools.py +330 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/uv.lock +1 -1
- {pyddock-0.3.3 → pyddock-0.3.4}/.gitignore +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/.hypothesis/.gitignore +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/.hypothesis/constants/106d94c8123c0256 +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/.hypothesis/constants/1685e03b3aa38c02 +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/.hypothesis/constants/1deca112ec6f2f3c +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/.hypothesis/constants/2488a3a95c48acfb +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/.hypothesis/constants/2a94d83a13979745 +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/.hypothesis/constants/499f1d5a639a382a +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/.hypothesis/constants/4ee6f24fa151b65d +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/.hypothesis/constants/5b1b2189b70f5ef2 +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/.hypothesis/constants/5d6f8b26b2137fe1 +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/.hypothesis/constants/61f9b905d7da14e0 +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/.hypothesis/constants/67a7f4ab2d372f23 +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/.hypothesis/constants/6c6f5083ece3f86b +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/.hypothesis/constants/827e18b40f235443 +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/.hypothesis/constants/8401e4039d635fbc +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/.hypothesis/constants/8490e7baefc8c8c3 +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/.hypothesis/constants/a7c132b836381d0d +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/.hypothesis/constants/b395547bc71e5c52 +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/.hypothesis/constants/ca50661510a40488 +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/.hypothesis/tmp/tmpl8oe65gb +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/.hypothesis/tmp/tmpqwper0dp +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/.hypothesis/unicode_data/15.1.0/charmap.json.gz +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/.hypothesis/unicode_data/15.1.0/codec-utf-8.json.gz +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/LICENSE +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/src/pyddock/__init__.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/src/pyddock/_audit_enforcement.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/src/pyddock/_base.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/src/pyddock/_enforcement.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/src/pyddock/_fs_enforcement.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/src/pyddock/_import_hook.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/src/pyddock/_prewarm.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/src/pyddock/_process_utils.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/src/pyddock/_proxies.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/src/pyddock/_runtime.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/src/pyddock/_subprocess_patch.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/src/pyddock/ast_validator.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/src/pyddock/cli.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/src/pyddock/config.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/src/pyddock/default_config.toml +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/src/pyddock/executor.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/src/pyddock/script_registry.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/src/pyddock/shell_executor.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/src/pyddock/tools/__init__.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/src/pyddock/venv_manager.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/__init__.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/_config_helpers.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/test_ast_properties.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/test_attr_reflection_hardening.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/test_audit_hook_backstop.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/test_chmod_integration.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/test_config.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/test_deny_always_wins.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/test_deny_messages.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/test_env_policy.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/test_executor.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/test_filesystem_guards.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/test_jailbreak_regression.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/test_proxy_properties.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/test_realistic.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/test_runtime.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/test_sandbox_escape_hardening.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/test_security_guards.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/test_server.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/test_shell_arg_paths.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/test_shell_executor.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/test_shell_properties.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/test_subprocess_enforcement.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/test_subprocess_properties.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/test_subst_trusted_path.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/test_trusted_prefixes_uv_cache.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/tests/test_venv_stamp.py +0 -0
- {pyddock-0.3.3 → pyddock-0.3.4}/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.4
|
|
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
|
|
@@ -55,7 +55,7 @@ pyddock provides Python execution and shell command access with declarative poli
|
|
|
55
55
|
"pyddock": {
|
|
56
56
|
"command": "uvx",
|
|
57
57
|
"args": ["pyddock", "serve", "--workspace", "<path-to-workspace>"],
|
|
58
|
-
"autoApprove": ["run_python","run_shell","fs_readfile","fs_stat","fs_append","fs_delete","fs_str_replace"]
|
|
58
|
+
"autoApprove": ["run_python","run_shell","fs_readfile","fs_stat","fs_find","fs_grep","fs_append","fs_delete","fs_str_replace"]
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -109,6 +109,8 @@ Pyddock also exposes file I/O tools that execute through the same sandbox as `ru
|
|
|
109
109
|
|
|
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
|
+
- **`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.
|
|
112
114
|
- **`fs_append`** — Append to a file (creates if missing). Returns a unified diff.
|
|
113
115
|
- **`fs_delete`** — Delete a file or empty directory. Returns a unified diff of removed content.
|
|
114
116
|
- **`fs_str_replace`** — Find-and-replace exact text (unique match required). Returns a unified diff, or match diagnostics on failure.
|
|
@@ -31,7 +31,7 @@ pyddock provides Python execution and shell command access with declarative poli
|
|
|
31
31
|
"pyddock": {
|
|
32
32
|
"command": "uvx",
|
|
33
33
|
"args": ["pyddock", "serve", "--workspace", "<path-to-workspace>"],
|
|
34
|
-
"autoApprove": ["run_python","run_shell","fs_readfile","fs_stat","fs_append","fs_delete","fs_str_replace"]
|
|
34
|
+
"autoApprove": ["run_python","run_shell","fs_readfile","fs_stat","fs_find","fs_grep","fs_append","fs_delete","fs_str_replace"]
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -85,6 +85,8 @@ Pyddock also exposes file I/O tools that execute through the same sandbox as `ru
|
|
|
85
85
|
|
|
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
|
+
- **`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.
|
|
88
90
|
- **`fs_append`** — Append to a file (creates if missing). Returns a unified diff.
|
|
89
91
|
- **`fs_delete`** — Delete a file or empty directory. Returns a unified diff of removed content.
|
|
90
92
|
- **`fs_str_replace`** — Find-and-replace exact text (unique match required). Returns a unified diff, or match diagnostics on failure.
|
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
$ErrorActionPreference = "Stop"
|
|
4
4
|
|
|
5
|
+
# Determine project name from the git repo root
|
|
6
|
+
$repoRoot = git rev-parse --show-toplevel 2>$null
|
|
7
|
+
if ($LASTEXITCODE -ne 0 -or -not $repoRoot) { throw "Not inside a git repository" }
|
|
8
|
+
$ProjectName = Split-Path -Leaf $repoRoot
|
|
9
|
+
Write-Host "Project name: $ProjectName"
|
|
10
|
+
|
|
5
11
|
# Clean dist
|
|
6
12
|
Write-Host "Cleaning dist/..."
|
|
7
13
|
if (Test-Path dist) { Remove-Item -Recurse -Force dist }
|
|
@@ -18,15 +24,15 @@ if ($LASTEXITCODE -ne 0) { throw "testpypi upload failed" }
|
|
|
18
24
|
|
|
19
25
|
# Hint for testing
|
|
20
26
|
Write-Host "`nTo test from testpypi:"
|
|
21
|
-
Write-Host " uvx --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/
|
|
27
|
+
Write-Host " uvx --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ $ProjectName"
|
|
22
28
|
|
|
23
29
|
# Pause for confirmation
|
|
24
30
|
$response = Read-Host "`nType 'y' to upload to pypi (anything else aborts)"
|
|
25
31
|
if ($response -ne 'y') { Write-Host "Aborted."; exit 0 }
|
|
26
32
|
|
|
27
33
|
# Upload to pypi
|
|
28
|
-
Write-Host "> uvx twine upload --repository
|
|
29
|
-
uvx twine upload --repository
|
|
34
|
+
Write-Host "> uvx twine upload --repository $ProjectName dist/*"
|
|
35
|
+
uvx twine upload --repository $ProjectName dist/*
|
|
30
36
|
if ($LASTEXITCODE -ne 0) { throw "pypi upload failed" }
|
|
31
37
|
|
|
32
38
|
Write-Host "`nDone!"
|
|
@@ -350,6 +350,65 @@ def create_server(workspace: Path | None = None, debug: bool = False) -> FastMCP
|
|
|
350
350
|
"end_line": end_line,
|
|
351
351
|
})
|
|
352
352
|
|
|
353
|
+
_fs_find_desc = (
|
|
354
|
+
"Find files by name. Approximately: [p for p in os.walk(path) if file_glob matches]\n"
|
|
355
|
+
"\n"
|
|
356
|
+
"file_glob is a glob (e.g. '*.py', '**/test_*.py') matched against filenames\n"
|
|
357
|
+
"under path (default: workspace root, must be a directory). Hidden\n"
|
|
358
|
+
"dot-directories are pruned before descending (an explicit leading '.' in\n"
|
|
359
|
+
"file_glob, e.g. '.env', still matches hidden files); exclude_regex\n"
|
|
360
|
+
"(optional) prunes more by relative path. Returns matching relative paths,\n"
|
|
361
|
+
"one per line, capped at max_results (default: 100)."
|
|
362
|
+
)
|
|
363
|
+
|
|
364
|
+
@mcp.tool(name="fs_find", description=_fs_find_desc)
|
|
365
|
+
async def fs_find(
|
|
366
|
+
file_glob: str,
|
|
367
|
+
path: str | None = None,
|
|
368
|
+
exclude_regex: str | None = None,
|
|
369
|
+
max_results: int | None = None,
|
|
370
|
+
) -> str:
|
|
371
|
+
if not file_glob or not file_glob.strip():
|
|
372
|
+
return "Error: 'file_glob' is required and must be non-empty."
|
|
373
|
+
return await registry.execute("fs_find", {
|
|
374
|
+
"file_glob": file_glob,
|
|
375
|
+
"path": path,
|
|
376
|
+
"exclude_regex": exclude_regex,
|
|
377
|
+
"max_results": max_results,
|
|
378
|
+
})
|
|
379
|
+
|
|
380
|
+
_fs_grep_desc = (
|
|
381
|
+
"Search file contents by regex (always case-insensitive). Approximately:\n"
|
|
382
|
+
"fs_find() then re.search(grep_regex, line, re.IGNORECASE) per line of\n"
|
|
383
|
+
"each matched file.\n"
|
|
384
|
+
"\n"
|
|
385
|
+
"grep_regex is searched within each file matched by file_glob (glob,\n"
|
|
386
|
+
"default '*') under path (default: workspace root). Returns\n"
|
|
387
|
+
"'path:line: content' per match, capped at max_results (default: 100)\n"
|
|
388
|
+
"and 300 chars per line.\n"
|
|
389
|
+
"\n"
|
|
390
|
+
"Binary files are skipped when scanning a directory path. A single named\n"
|
|
391
|
+
"file is always searched."
|
|
392
|
+
)
|
|
393
|
+
|
|
394
|
+
@mcp.tool(name="fs_grep", description=_fs_grep_desc)
|
|
395
|
+
async def fs_grep(
|
|
396
|
+
grep_regex: str,
|
|
397
|
+
file_glob: str | None = None,
|
|
398
|
+
path: str | None = None,
|
|
399
|
+
exclude_regex: str | None = None,
|
|
400
|
+
max_results: int | None = None,
|
|
401
|
+
) -> str:
|
|
402
|
+
if not grep_regex:
|
|
403
|
+
return "Error: 'grep_regex' is required and must be non-empty."
|
|
404
|
+
return await registry.execute("fs_grep", {
|
|
405
|
+
"grep_regex": grep_regex,
|
|
406
|
+
"file_glob": file_glob,
|
|
407
|
+
"path": path,
|
|
408
|
+
"exclude_regex": exclude_regex,
|
|
409
|
+
"max_results": max_results,
|
|
410
|
+
})
|
|
411
|
+
|
|
353
412
|
return mcp
|
|
354
413
|
|
|
355
414
|
|
|
@@ -19,11 +19,16 @@ workspace_root = _PARAMS["workspace_root"]
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
def resolve_path(raw_path: str) -> Path:
|
|
22
|
-
"""Resolve a user-provided path to absolute, relative to workspace root.
|
|
23
|
-
|
|
22
|
+
"""Resolve a user-provided path to absolute, relative to workspace root.
|
|
23
|
+
|
|
24
|
+
Expands a leading '~' (home directory) before resolving, mirroring how
|
|
25
|
+
[filesystem] scope paths (writable_paths/readable_paths) are resolved.
|
|
26
|
+
"""
|
|
27
|
+
expanded = os.path.expanduser(raw_path)
|
|
28
|
+
p = Path(expanded)
|
|
24
29
|
if p.is_absolute():
|
|
25
30
|
return Path(os.path.abspath(str(p)))
|
|
26
|
-
return Path(os.path.abspath(str(Path(workspace_root) /
|
|
31
|
+
return Path(os.path.abspath(str(Path(workspace_root) / expanded)))
|
|
27
32
|
|
|
28
33
|
|
|
29
34
|
def generate_diff(old_lines: list[str], new_lines: list[str], filename: str) -> str:
|
|
@@ -20,11 +20,16 @@ _MAX_DELETE_DIFF_BYTES = 16_384 # 16 KB truncation for delete diffs
|
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
def resolve_path(raw_path: str) -> Path:
|
|
23
|
-
"""Resolve a user-provided path to absolute, relative to workspace root.
|
|
24
|
-
|
|
23
|
+
"""Resolve a user-provided path to absolute, relative to workspace root.
|
|
24
|
+
|
|
25
|
+
Expands a leading '~' (home directory) before resolving, mirroring how
|
|
26
|
+
[filesystem] scope paths (writable_paths/readable_paths) are resolved.
|
|
27
|
+
"""
|
|
28
|
+
expanded = os.path.expanduser(raw_path)
|
|
29
|
+
p = Path(expanded)
|
|
25
30
|
if p.is_absolute():
|
|
26
31
|
return Path(os.path.abspath(str(p)))
|
|
27
|
-
return Path(os.path.abspath(str(Path(workspace_root) /
|
|
32
|
+
return Path(os.path.abspath(str(Path(workspace_root) / expanded)))
|
|
28
33
|
|
|
29
34
|
|
|
30
35
|
def generate_diff(old_lines: list[str], new_lines: list[str], filename: str) -> str:
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"""fs_find tool script.
|
|
2
|
+
|
|
3
|
+
Find files by name under a directory. Approximately:
|
|
4
|
+
[p for p in os.walk(path) if file_glob matches]
|
|
5
|
+
|
|
6
|
+
Hidden dot-directories (and their contents) are pruned before descending —
|
|
7
|
+
they are never walked, not just filtered from results — so this stays fast
|
|
8
|
+
on large ignored trees like .venv/ or node_modules/. An optional
|
|
9
|
+
exclude_regex prunes/excludes additional entries the same way. A file_glob
|
|
10
|
+
whose final segment starts with '.' (e.g. '.env') explicitly matches hidden
|
|
11
|
+
files despite the pruning, mirroring shell glob semantics where '*' does not
|
|
12
|
+
match a leading dot but an explicit pattern does. Returns matching paths
|
|
13
|
+
(relative to the workspace root when possible), one per line, capped at
|
|
14
|
+
max_results.
|
|
15
|
+
"""
|
|
16
|
+
import os
|
|
17
|
+
import re
|
|
18
|
+
import sys
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
|
|
21
|
+
# --- Parameters ---
|
|
22
|
+
file_glob = _PARAMS["file_glob"]
|
|
23
|
+
path_str = _PARAMS.get("path") or "."
|
|
24
|
+
exclude_regex = _PARAMS.get("exclude_regex")
|
|
25
|
+
max_results = _PARAMS.get("max_results") or 100
|
|
26
|
+
workspace_root = _PARAMS["workspace_root"]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def resolve_path(raw_path: str) -> Path:
|
|
30
|
+
"""Resolve a user-provided path to absolute, relative to workspace root.
|
|
31
|
+
|
|
32
|
+
Expands a leading '~' (home directory) before resolving, mirroring how
|
|
33
|
+
[filesystem] scope paths (writable_paths/readable_paths) are resolved.
|
|
34
|
+
"""
|
|
35
|
+
expanded = os.path.expanduser(raw_path)
|
|
36
|
+
p = Path(expanded)
|
|
37
|
+
if p.is_absolute():
|
|
38
|
+
return Path(os.path.abspath(str(p)))
|
|
39
|
+
return Path(os.path.abspath(str(Path(workspace_root) / expanded)))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def display_path(p: Path) -> str:
|
|
43
|
+
"""Format a path for output: relative to workspace root when possible."""
|
|
44
|
+
try:
|
|
45
|
+
rel = p.relative_to(workspace_root)
|
|
46
|
+
return str(rel).replace("\\", "/")
|
|
47
|
+
except ValueError:
|
|
48
|
+
return str(p)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def translate_glob(pattern: str) -> str:
|
|
52
|
+
"""Translate a glob pattern to an anchored regex.
|
|
53
|
+
|
|
54
|
+
Supports '*' (any run of non-separator chars), '?' (one non-separator
|
|
55
|
+
char), '[seq]'/'[!seq]' character classes, and '**' as a recursive
|
|
56
|
+
any-depth-of-segments wildcard. Matched against a forward-slash path.
|
|
57
|
+
"""
|
|
58
|
+
i, n = 0, len(pattern)
|
|
59
|
+
out: list[str] = []
|
|
60
|
+
while i < n:
|
|
61
|
+
c = pattern[i]
|
|
62
|
+
i += 1
|
|
63
|
+
if c == "*":
|
|
64
|
+
if i < n and pattern[i] == "*":
|
|
65
|
+
i += 1
|
|
66
|
+
if i < n and pattern[i] == "/":
|
|
67
|
+
i += 1
|
|
68
|
+
out.append("(?:.*/)?")
|
|
69
|
+
else:
|
|
70
|
+
out.append(".*")
|
|
71
|
+
else:
|
|
72
|
+
out.append("[^/]*")
|
|
73
|
+
elif c == "?":
|
|
74
|
+
out.append("[^/]")
|
|
75
|
+
elif c == "[":
|
|
76
|
+
j = i
|
|
77
|
+
if j < n and pattern[j] == "!":
|
|
78
|
+
j += 1
|
|
79
|
+
if j < n and pattern[j] == "]":
|
|
80
|
+
j += 1
|
|
81
|
+
while j < n and pattern[j] != "]":
|
|
82
|
+
j += 1
|
|
83
|
+
if j >= n:
|
|
84
|
+
out.append(re.escape("["))
|
|
85
|
+
else:
|
|
86
|
+
stuff = pattern[i:j]
|
|
87
|
+
if stuff.startswith("!"):
|
|
88
|
+
stuff = "^" + stuff[1:]
|
|
89
|
+
out.append("[" + stuff + "]")
|
|
90
|
+
i = j + 1
|
|
91
|
+
else:
|
|
92
|
+
out.append(re.escape(c))
|
|
93
|
+
return "^" + "".join(out) + "$"
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def is_hidden(name: str) -> bool:
|
|
97
|
+
"""True if a single path component is dot-prefixed."""
|
|
98
|
+
return name.startswith(".")
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def rel_posix(base: Path, dirpath: str) -> str:
|
|
102
|
+
"""Relative path from base to dirpath, forward-slash, '' at base itself."""
|
|
103
|
+
rel = os.path.relpath(dirpath, str(base))
|
|
104
|
+
if rel == ".":
|
|
105
|
+
return ""
|
|
106
|
+
return rel.replace("\\", "/")
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
# --- Main ---
|
|
110
|
+
if not file_glob:
|
|
111
|
+
print("file_glob must be non-empty.", file=sys.stderr)
|
|
112
|
+
sys.exit(1)
|
|
113
|
+
|
|
114
|
+
exclude_re = None
|
|
115
|
+
if exclude_regex:
|
|
116
|
+
try:
|
|
117
|
+
exclude_re = re.compile(exclude_regex)
|
|
118
|
+
except re.error as e:
|
|
119
|
+
print(f"Invalid exclude_regex '{exclude_regex}': {e}", file=sys.stderr)
|
|
120
|
+
sys.exit(1)
|
|
121
|
+
|
|
122
|
+
# Matching strategy mirrors Path.rglob(): a pattern with no '/' matches the
|
|
123
|
+
# filename at any depth; a pattern containing '/' matches the full relative
|
|
124
|
+
# path from `path` (e.g. '**/test_*.py').
|
|
125
|
+
match_basename_only = "/" not in file_glob
|
|
126
|
+
file_regex = re.compile(translate_glob(file_glob))
|
|
127
|
+
|
|
128
|
+
# A glob whose final segment starts with '.' explicitly targets hidden files
|
|
129
|
+
# (e.g. '.env', '**/.env') — mirrors shell semantics where '*' does not match
|
|
130
|
+
# a leading dot but an explicit pattern does. Hidden DIRECTORIES are still
|
|
131
|
+
# pruned regardless (performance); point `path` directly at one to search
|
|
132
|
+
# inside it.
|
|
133
|
+
allow_hidden_files = file_glob.rsplit("/", 1)[-1].startswith(".")
|
|
134
|
+
|
|
135
|
+
path = resolve_path(path_str)
|
|
136
|
+
|
|
137
|
+
if not path.exists():
|
|
138
|
+
print(f"Path not found: '{path_str}'", file=sys.stderr)
|
|
139
|
+
sys.exit(1)
|
|
140
|
+
|
|
141
|
+
if not path.is_dir():
|
|
142
|
+
print(f"'{path_str}' is not a directory. fs_find searches directories.", file=sys.stderr)
|
|
143
|
+
sys.exit(1)
|
|
144
|
+
|
|
145
|
+
results: list[Path] = []
|
|
146
|
+
truncated = False
|
|
147
|
+
skipped_hidden = 0
|
|
148
|
+
skipped_excluded = 0
|
|
149
|
+
|
|
150
|
+
for dirpath, dirnames, filenames in os.walk(path):
|
|
151
|
+
if truncated:
|
|
152
|
+
break
|
|
153
|
+
rel_dir = rel_posix(path, dirpath)
|
|
154
|
+
|
|
155
|
+
# Prune hidden / excluded subdirectories BEFORE os.walk descends into
|
|
156
|
+
# them — this is what keeps large ignored trees (.venv/, node_modules/)
|
|
157
|
+
# from ever being scanned at all.
|
|
158
|
+
kept_dirnames = []
|
|
159
|
+
for d in dirnames:
|
|
160
|
+
if is_hidden(d):
|
|
161
|
+
skipped_hidden += 1
|
|
162
|
+
continue
|
|
163
|
+
rel_sub = f"{rel_dir}/{d}" if rel_dir else d
|
|
164
|
+
if exclude_re is not None and exclude_re.search(rel_sub):
|
|
165
|
+
skipped_excluded += 1
|
|
166
|
+
continue
|
|
167
|
+
kept_dirnames.append(d)
|
|
168
|
+
dirnames[:] = kept_dirnames
|
|
169
|
+
|
|
170
|
+
for f in filenames:
|
|
171
|
+
if is_hidden(f) and not allow_hidden_files:
|
|
172
|
+
skipped_hidden += 1
|
|
173
|
+
continue
|
|
174
|
+
rel_file = f"{rel_dir}/{f}" if rel_dir else f
|
|
175
|
+
if exclude_re is not None and exclude_re.search(rel_file):
|
|
176
|
+
skipped_excluded += 1
|
|
177
|
+
continue
|
|
178
|
+
target = f if match_basename_only else rel_file
|
|
179
|
+
if not file_regex.match(target):
|
|
180
|
+
continue
|
|
181
|
+
results.append(Path(dirpath) / f)
|
|
182
|
+
if len(results) >= max_results:
|
|
183
|
+
truncated = True
|
|
184
|
+
break
|
|
185
|
+
|
|
186
|
+
notes = []
|
|
187
|
+
if truncated:
|
|
188
|
+
notes.append(f"Showing first {max_results} results. Narrow file_glob or path to see more.")
|
|
189
|
+
if skipped_hidden:
|
|
190
|
+
notes.append(f"{skipped_hidden} hidden file(s)/dir(s) skipped.")
|
|
191
|
+
if skipped_excluded:
|
|
192
|
+
notes.append(f"{skipped_excluded} excluded file(s)/dir(s) skipped.")
|
|
193
|
+
|
|
194
|
+
if not results:
|
|
195
|
+
msg = f"No files matching '{file_glob}' found under '{path_str}'."
|
|
196
|
+
if notes:
|
|
197
|
+
msg += " (" + " ".join(notes) + ")"
|
|
198
|
+
print(msg)
|
|
199
|
+
else:
|
|
200
|
+
output = "\n".join(display_path(p) for p in results)
|
|
201
|
+
if notes:
|
|
202
|
+
output += "\n\n[" + " ".join(notes) + "]"
|
|
203
|
+
print(output)
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"""fs_grep tool script.
|
|
2
|
+
|
|
3
|
+
Search file contents by regex (always case-insensitive). Approximately:
|
|
4
|
+
fs_find() then re.search(grep_regex, line, re.IGNORECASE) per line of each
|
|
5
|
+
matched file.
|
|
6
|
+
|
|
7
|
+
Hidden dot-directories are pruned before descending (see fs_find); an
|
|
8
|
+
optional exclude_regex prunes/excludes additional entries the same way. A
|
|
9
|
+
file_glob whose final segment starts with '.' (e.g. '.env') explicitly
|
|
10
|
+
matches hidden files despite the pruning, mirroring shell glob semantics
|
|
11
|
+
where '*' does not match a leading dot but an explicit pattern does.
|
|
12
|
+
|
|
13
|
+
Binary files are skipped when scanning a directory path (sniffed from the
|
|
14
|
+
same read used for matching — no separate open). A single named file is
|
|
15
|
+
always searched, binary or not.
|
|
16
|
+
"""
|
|
17
|
+
import os
|
|
18
|
+
import re
|
|
19
|
+
import sys
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
|
|
22
|
+
# --- Parameters ---
|
|
23
|
+
grep_regex = _PARAMS["grep_regex"]
|
|
24
|
+
file_glob = _PARAMS.get("file_glob") or "*"
|
|
25
|
+
path_str = _PARAMS.get("path") or "."
|
|
26
|
+
exclude_regex = _PARAMS.get("exclude_regex")
|
|
27
|
+
max_results = _PARAMS.get("max_results") or 100
|
|
28
|
+
workspace_root = _PARAMS["workspace_root"]
|
|
29
|
+
|
|
30
|
+
# --- Constants ---
|
|
31
|
+
_SNIFF_BYTES = 8192 # bytes inspected for the binary heuristic
|
|
32
|
+
_MAX_LINE_CHARS = 300 # cap per matched line so one huge line can't dominate output
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def resolve_path(raw_path: str) -> Path:
|
|
36
|
+
"""Resolve a user-provided path to absolute, relative to workspace root.
|
|
37
|
+
|
|
38
|
+
Expands a leading '~' (home directory) before resolving, mirroring how
|
|
39
|
+
[filesystem] scope paths (writable_paths/readable_paths) are resolved.
|
|
40
|
+
"""
|
|
41
|
+
expanded = os.path.expanduser(raw_path)
|
|
42
|
+
p = Path(expanded)
|
|
43
|
+
if p.is_absolute():
|
|
44
|
+
return Path(os.path.abspath(str(p)))
|
|
45
|
+
return Path(os.path.abspath(str(Path(workspace_root) / expanded)))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def display_path(p: Path) -> str:
|
|
49
|
+
"""Format a path for output: relative to workspace root when possible."""
|
|
50
|
+
try:
|
|
51
|
+
rel = p.relative_to(workspace_root)
|
|
52
|
+
return str(rel).replace("\\", "/")
|
|
53
|
+
except ValueError:
|
|
54
|
+
return str(p)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def translate_glob(pattern: str) -> str:
|
|
58
|
+
"""Translate a glob pattern to an anchored regex.
|
|
59
|
+
|
|
60
|
+
Supports '*' (any run of non-separator chars), '?' (one non-separator
|
|
61
|
+
char), '[seq]'/'[!seq]' character classes, and '**' as a recursive
|
|
62
|
+
any-depth-of-segments wildcard. Matched against a forward-slash path.
|
|
63
|
+
"""
|
|
64
|
+
i, n = 0, len(pattern)
|
|
65
|
+
out: list[str] = []
|
|
66
|
+
while i < n:
|
|
67
|
+
c = pattern[i]
|
|
68
|
+
i += 1
|
|
69
|
+
if c == "*":
|
|
70
|
+
if i < n and pattern[i] == "*":
|
|
71
|
+
i += 1
|
|
72
|
+
if i < n and pattern[i] == "/":
|
|
73
|
+
i += 1
|
|
74
|
+
out.append("(?:.*/)?")
|
|
75
|
+
else:
|
|
76
|
+
out.append(".*")
|
|
77
|
+
else:
|
|
78
|
+
out.append("[^/]*")
|
|
79
|
+
elif c == "?":
|
|
80
|
+
out.append("[^/]")
|
|
81
|
+
elif c == "[":
|
|
82
|
+
j = i
|
|
83
|
+
if j < n and pattern[j] == "!":
|
|
84
|
+
j += 1
|
|
85
|
+
if j < n and pattern[j] == "]":
|
|
86
|
+
j += 1
|
|
87
|
+
while j < n and pattern[j] != "]":
|
|
88
|
+
j += 1
|
|
89
|
+
if j >= n:
|
|
90
|
+
out.append(re.escape("["))
|
|
91
|
+
else:
|
|
92
|
+
stuff = pattern[i:j]
|
|
93
|
+
if stuff.startswith("!"):
|
|
94
|
+
stuff = "^" + stuff[1:]
|
|
95
|
+
out.append("[" + stuff + "]")
|
|
96
|
+
i = j + 1
|
|
97
|
+
else:
|
|
98
|
+
out.append(re.escape(c))
|
|
99
|
+
return "^" + "".join(out) + "$"
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def is_hidden(name: str) -> bool:
|
|
103
|
+
"""True if a single path component is dot-prefixed."""
|
|
104
|
+
return name.startswith(".")
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def rel_posix(base: Path, dirpath: str) -> str:
|
|
108
|
+
"""Relative path from base to dirpath, forward-slash, '' at base itself."""
|
|
109
|
+
rel = os.path.relpath(dirpath, str(base))
|
|
110
|
+
if rel == ".":
|
|
111
|
+
return ""
|
|
112
|
+
return rel.replace("\\", "/")
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def truncate_line(line: str) -> str:
|
|
116
|
+
"""Cap a matched line at _MAX_LINE_CHARS, marking truncation."""
|
|
117
|
+
if len(line) <= _MAX_LINE_CHARS:
|
|
118
|
+
return line
|
|
119
|
+
return line[:_MAX_LINE_CHARS] + " [truncated: line too long]"
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def read_text_or_skip_reason(p: Path) -> tuple[str | None, str | None]:
|
|
123
|
+
"""Read a file once, sniffing for binary content in the same pass.
|
|
124
|
+
|
|
125
|
+
Returns (text, None) on success, or (None, reason) where reason is
|
|
126
|
+
"binary" or "unreadable". A single open() call: binary files stop after
|
|
127
|
+
the first _SNIFF_BYTES (no wasted read of large binary blobs); text
|
|
128
|
+
files reuse the already-read prefix instead of reopening.
|
|
129
|
+
"""
|
|
130
|
+
try:
|
|
131
|
+
with open(p, "rb") as f:
|
|
132
|
+
chunk = f.read(_SNIFF_BYTES)
|
|
133
|
+
if b"\x00" in chunk:
|
|
134
|
+
return None, "binary"
|
|
135
|
+
rest = f.read()
|
|
136
|
+
except OSError:
|
|
137
|
+
# Covers PermissionError (blocked by a filesystem guard, e.g.
|
|
138
|
+
# ~/.ssh/) and other read failures (deleted mid-walk, broken
|
|
139
|
+
# symlink, etc.).
|
|
140
|
+
return None, "unreadable"
|
|
141
|
+
return (chunk + rest).decode("utf-8", errors="replace"), None
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
# --- Main ---
|
|
145
|
+
if not grep_regex:
|
|
146
|
+
print("grep_regex must be non-empty.", file=sys.stderr)
|
|
147
|
+
sys.exit(1)
|
|
148
|
+
|
|
149
|
+
try:
|
|
150
|
+
regex = re.compile(grep_regex, re.IGNORECASE)
|
|
151
|
+
except re.error as e:
|
|
152
|
+
print(f"Invalid grep_regex '{grep_regex}': {e}", file=sys.stderr)
|
|
153
|
+
sys.exit(1)
|
|
154
|
+
|
|
155
|
+
exclude_re = None
|
|
156
|
+
if exclude_regex:
|
|
157
|
+
try:
|
|
158
|
+
exclude_re = re.compile(exclude_regex)
|
|
159
|
+
except re.error as e:
|
|
160
|
+
print(f"Invalid exclude_regex '{exclude_regex}': {e}", file=sys.stderr)
|
|
161
|
+
sys.exit(1)
|
|
162
|
+
|
|
163
|
+
# Matching strategy mirrors Path.rglob() (see fs_find.py's translate_glob).
|
|
164
|
+
match_basename_only = "/" not in file_glob
|
|
165
|
+
file_regex = re.compile(translate_glob(file_glob))
|
|
166
|
+
|
|
167
|
+
# A glob whose final segment starts with '.' explicitly targets hidden files
|
|
168
|
+
# (e.g. '.env', '**/.env') — mirrors shell semantics where '*' does not match
|
|
169
|
+
# a leading dot but an explicit pattern does. Hidden DIRECTORIES are still
|
|
170
|
+
# pruned regardless (performance); point `path` directly at one to search
|
|
171
|
+
# inside it.
|
|
172
|
+
allow_hidden_files = file_glob.rsplit("/", 1)[-1].startswith(".")
|
|
173
|
+
|
|
174
|
+
path = resolve_path(path_str)
|
|
175
|
+
|
|
176
|
+
if not path.exists():
|
|
177
|
+
print(f"Path not found: '{path_str}'", file=sys.stderr)
|
|
178
|
+
sys.exit(1)
|
|
179
|
+
|
|
180
|
+
matches: list[str] = []
|
|
181
|
+
skipped_hidden = 0
|
|
182
|
+
skipped_excluded = 0
|
|
183
|
+
skipped_binary = 0
|
|
184
|
+
skipped_unreadable = 0
|
|
185
|
+
truncated = False
|
|
186
|
+
|
|
187
|
+
if path.is_file():
|
|
188
|
+
# A directly named file is always searched — bypasses hidden/exclude/glob
|
|
189
|
+
# filtering and the binary sniff. Covers grepping a partially corrupted
|
|
190
|
+
# log file, or a dotfile named explicitly.
|
|
191
|
+
try:
|
|
192
|
+
text = path.read_text(encoding="utf-8", errors="replace")
|
|
193
|
+
except OSError:
|
|
194
|
+
skipped_unreadable += 1
|
|
195
|
+
text = None
|
|
196
|
+
|
|
197
|
+
if text is not None:
|
|
198
|
+
label = display_path(path)
|
|
199
|
+
for line_num, line in enumerate(text.splitlines(), start=1):
|
|
200
|
+
if regex.search(line):
|
|
201
|
+
matches.append(f"{label}:{line_num}: {truncate_line(line)}")
|
|
202
|
+
if len(matches) >= max_results:
|
|
203
|
+
truncated = True
|
|
204
|
+
break
|
|
205
|
+
else:
|
|
206
|
+
# Single pass: walk, filter, and match together so max_results can stop
|
|
207
|
+
# the walk early instead of enumerating the entire (pruned) tree first.
|
|
208
|
+
for dirpath, dirnames, filenames in os.walk(path):
|
|
209
|
+
if truncated:
|
|
210
|
+
break
|
|
211
|
+
rel_dir = rel_posix(path, dirpath)
|
|
212
|
+
|
|
213
|
+
# Prune hidden / excluded subdirectories BEFORE os.walk descends into
|
|
214
|
+
# them — never walked, not just filtered from results.
|
|
215
|
+
kept_dirnames = []
|
|
216
|
+
for d in dirnames:
|
|
217
|
+
if is_hidden(d):
|
|
218
|
+
skipped_hidden += 1
|
|
219
|
+
continue
|
|
220
|
+
rel_sub = f"{rel_dir}/{d}" if rel_dir else d
|
|
221
|
+
if exclude_re is not None and exclude_re.search(rel_sub):
|
|
222
|
+
skipped_excluded += 1
|
|
223
|
+
continue
|
|
224
|
+
kept_dirnames.append(d)
|
|
225
|
+
dirnames[:] = kept_dirnames
|
|
226
|
+
|
|
227
|
+
for f in filenames:
|
|
228
|
+
if is_hidden(f) and not allow_hidden_files:
|
|
229
|
+
skipped_hidden += 1
|
|
230
|
+
continue
|
|
231
|
+
rel_file = f"{rel_dir}/{f}" if rel_dir else f
|
|
232
|
+
if exclude_re is not None and exclude_re.search(rel_file):
|
|
233
|
+
skipped_excluded += 1
|
|
234
|
+
continue
|
|
235
|
+
target = f if match_basename_only else rel_file
|
|
236
|
+
if not file_regex.match(target):
|
|
237
|
+
continue
|
|
238
|
+
|
|
239
|
+
candidate = Path(dirpath) / f
|
|
240
|
+
text, reason = read_text_or_skip_reason(candidate)
|
|
241
|
+
if reason == "binary":
|
|
242
|
+
skipped_binary += 1
|
|
243
|
+
continue
|
|
244
|
+
if reason == "unreadable":
|
|
245
|
+
skipped_unreadable += 1
|
|
246
|
+
continue
|
|
247
|
+
|
|
248
|
+
label = display_path(candidate)
|
|
249
|
+
for line_num, line in enumerate(text.splitlines(), start=1):
|
|
250
|
+
if regex.search(line):
|
|
251
|
+
matches.append(f"{label}:{line_num}: {truncate_line(line)}")
|
|
252
|
+
if len(matches) >= max_results:
|
|
253
|
+
truncated = True
|
|
254
|
+
break
|
|
255
|
+
if truncated:
|
|
256
|
+
break
|
|
257
|
+
|
|
258
|
+
notes = []
|
|
259
|
+
if truncated:
|
|
260
|
+
notes.append(f"Showing first {max_results} matches. Narrow grep_regex or path to see more.")
|
|
261
|
+
if skipped_binary:
|
|
262
|
+
notes.append(f"{skipped_binary} binary file(s) skipped.")
|
|
263
|
+
if skipped_unreadable:
|
|
264
|
+
notes.append(f"{skipped_unreadable} unreadable file(s) skipped (permission denied or I/O error).")
|
|
265
|
+
if skipped_hidden:
|
|
266
|
+
notes.append(f"{skipped_hidden} hidden file(s)/dir(s) skipped.")
|
|
267
|
+
if skipped_excluded:
|
|
268
|
+
notes.append(f"{skipped_excluded} excluded file(s)/dir(s) skipped.")
|
|
269
|
+
|
|
270
|
+
if not matches:
|
|
271
|
+
msg = f"No matches for '{grep_regex}' found under '{path_str}'."
|
|
272
|
+
if notes:
|
|
273
|
+
msg += " (" + " ".join(notes) + ")"
|
|
274
|
+
print(msg)
|
|
275
|
+
else:
|
|
276
|
+
output = "\n".join(matches)
|
|
277
|
+
if notes:
|
|
278
|
+
output += "\n\n[" + " ".join(notes) + "]"
|
|
279
|
+
print(output)
|