Blacklist image/binary files from list_vault by default
Excludes .webp, .png, .jpg, .gif, .svg, .pdf, .mp4, .mp3, .mov, .excalidraw, .bmp, .ico, .tiff, .heic, .avif — the model can't read these anyway and they were the remaining bulk of the 53K payload after the .obsidian purge. New exclude_extensions param with sensible default blacklist. Pass exclude_extensions=[] to see everything.
This commit is contained in:
parent
517a79deea
commit
5c0ee23350
1 changed files with 27 additions and 9 deletions
36
server.py
36
server.py
|
|
@ -41,6 +41,9 @@ def resolve_vaults_root(cli_arg: str | None = None) -> Path:
|
||||||
VAULTS_ROOT: Path = Path(".") # set on startup
|
VAULTS_ROOT: Path = Path(".") # set on startup
|
||||||
OBSIDIAN_HIDDEN = {".obsidian", ".trash", ".git", ".DS_Store", "node_modules"}
|
OBSIDIAN_HIDDEN = {".obsidian", ".trash", ".git", ".DS_Store", "node_modules"}
|
||||||
MARKDOWN_EXT = {".md", ".markdown"}
|
MARKDOWN_EXT = {".md", ".markdown"}
|
||||||
|
DEFAULT_EXCLUDE_EXT = {".webp", ".png", ".jpg", ".jpeg", ".gif", ".svg",
|
||||||
|
".pdf", ".mp4", ".mp3", ".mov", ".excalidraw", ".bmp",
|
||||||
|
".ico", ".tiff", ".heic", ".avif"}
|
||||||
|
|
||||||
|
|
||||||
# ── Helpers ───────────────────────────────────────────────────────────────
|
# ── Helpers ───────────────────────────────────────────────────────────────
|
||||||
|
|
@ -187,14 +190,17 @@ def list_vault(
|
||||||
recursive: bool = False,
|
recursive: bool = False,
|
||||||
include_files: bool = True,
|
include_files: bool = True,
|
||||||
include_directories: bool = True,
|
include_directories: bool = True,
|
||||||
file_extensions: list[str] | None = None,
|
file_extensions: list[str] | None = None, # None = all; pass ['.md'] for notes only
|
||||||
|
exclude_extensions: list[str] | None = None, # None = default image blacklist (see below)
|
||||||
include_hidden: bool = False,
|
include_hidden: bool = False,
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
"""FILESYSTEM TOOL (not memory) — Index files and folders in vault on disk. Use to see structure before reading docs.
|
"""FILESYSTEM TOOL (not memory) — Index files and folders in vault on disk. Use to see structure before reading docs.
|
||||||
|
|
||||||
Returns a lean listing (name + path + type only). Use get_file_info for
|
Returns a lean listing (name + path + type only). Image/binary files (.webp,
|
||||||
size/date/counts on a specific file. Hidden dirs (.obsidian, .git, .trash)
|
.png, .jpg, .gif, .svg, .pdf, .mp4, .mp3, .mov, .excalidraw) are excluded by
|
||||||
are excluded by default.
|
default — the model can't read them anyway. Pass exclude_extensions=[] to see
|
||||||
|
everything. Use get_file_info for size/date/counts on a specific file.
|
||||||
|
Hidden dirs are excluded by default.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
vault_name: Name of the vault (subdirectory name under vaults root)
|
vault_name: Name of the vault (subdirectory name under vaults root)
|
||||||
|
|
@ -204,14 +210,18 @@ def list_vault(
|
||||||
recursive: If True, list all nested contents recursively.
|
recursive: If True, list all nested contents recursively.
|
||||||
include_files: Include files in results (default True).
|
include_files: Include files in results (default True).
|
||||||
include_directories: Include directories in results (default True).
|
include_directories: Include directories in results (default True).
|
||||||
file_extensions: Optional filter — only return files with these extensions
|
file_extensions: Filter files by extension. Pass ['.md'] for notes only,
|
||||||
(e.g. ['.md', '.canvas']). Case-insensitive.
|
['.md', '.canvas'] for notes + canvases, or omit/None for all files.
|
||||||
|
exclude_extensions: Extensions to EXCLUDE. Defaults to binary/image types
|
||||||
|
(webp, png, jpg, gif, svg, pdf, mp4, mp3, mov, excalidraw).
|
||||||
|
Pass [] to disable the blacklist.
|
||||||
include_hidden: If True, include .obsidian config directory (default False).
|
include_hidden: If True, include .obsidian config directory (default False).
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
list_vault("obsidian-skt") → root index
|
list_vault("obsidian-skt") → all files (images excluded) at root
|
||||||
list_vault("obsidian-skt", "", True) → recursive index
|
list_vault("obsidian-skt", file_extensions=['.md']) → notes only
|
||||||
list_vault("obsidian-skt", "NPCs") → subfolder
|
list_vault("obsidian-skt", "", True, file_extensions=['.md']) → all notes recursively
|
||||||
|
list_vault("obsidian-skt", exclude_extensions=[]) → everything including images
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
directories: [{name, path, type}]
|
directories: [{name, path, type}]
|
||||||
|
|
@ -229,6 +239,12 @@ def list_vault(
|
||||||
if not target.exists():
|
if not target.exists():
|
||||||
return {"error": f"Path not found: {path or '/'}", "vault": vault_name}
|
return {"error": f"Path not found: {path or '/'}", "vault": vault_name}
|
||||||
|
|
||||||
|
# Resolve exclude list: explicit arg > default image blacklist
|
||||||
|
if exclude_extensions is None:
|
||||||
|
exclude_set = DEFAULT_EXCLUDE_EXT
|
||||||
|
else:
|
||||||
|
exclude_set = {e.lower() for e in exclude_extensions}
|
||||||
|
|
||||||
directories = []
|
directories = []
|
||||||
files = []
|
files = []
|
||||||
|
|
||||||
|
|
@ -256,6 +272,8 @@ def list_vault(
|
||||||
ext_lower = entry.suffix.lower()
|
ext_lower = entry.suffix.lower()
|
||||||
if not any(ext_lower == fe.lower() for fe in file_extensions):
|
if not any(ext_lower == fe.lower() for fe in file_extensions):
|
||||||
continue
|
continue
|
||||||
|
if entry.suffix.lower() in exclude_set:
|
||||||
|
continue
|
||||||
files.append(info)
|
files.append(info)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue