Nymbo commited on
Commit
f908fa0
·
verified ·
1 Parent(s): f058daf

Obsidian_Vault tool is easier for smaller models to understand and 1-shot

Browse files
Files changed (1) hide show
  1. Modules/Obsidian_Vault.py +21 -13
Modules/Obsidian_Vault.py CHANGED
@@ -16,25 +16,26 @@ from ._docstrings import autodoc
16
  TOOL_SUMMARY = (
17
  "Browse and search the Obsidian vault in read-only mode. "
18
  "Actions: list, read, info, search, help. "
19
- "All paths resolve within the vault root."
20
  )
21
 
22
  HELP_TEXT = (
23
  "Obsidian Vault — actions and usage\n\n"
24
  "Root: Tools/Obsidian (override with OBSIDIAN_VAULT_ROOT). "
 
25
  "Absolute paths are disabled unless UNSAFE_ALLOW_ABS_PATHS=1.\n\n"
26
  "Actions and fields:\n"
27
- "- list: path='.' (default), recursive=false, show_hidden=false, max_entries=20\n"
28
- "- read: path, offset=0, max_chars=4000 (shows next_cursor when truncated)\n"
29
  "- info: path\n"
30
  "- search: path (note or folder), query text in the Search field, recursive=false, show_hidden=false, max_entries=20, case_sensitive=false, offset=0\n"
31
  "- help: show this guide\n\n"
32
  "Errors are returned as JSON with fields: {status:'error', code, message, path?, hint?, data?}.\n\n"
33
  "Examples:\n"
34
- "- list current: action=list, path='.'\n"
35
- "- read note: action=read, path='Projects/note.md', max_chars=500\n"
36
- "- show metadata: action=info, path='Inbox'\n"
37
- "- search notes: action=search, path='Projects', query='deadline', recursive=true, max_entries=100\n"
38
  "- case-sensitive search: action=search, query='TODO', case_sensitive=true\n"
39
  "- page search results: action=search, query='TODO', offset=20\n"
40
  )
@@ -106,15 +107,22 @@ def _display_path(abs_path: str) -> str:
106
 
107
  def _resolve_path(path: str) -> tuple[str, str]:
108
  try:
109
- user_input = (path or ".").strip()
110
- raw = os.path.expanduser(user_input)
111
- if os.path.isabs(raw):
 
 
 
 
 
 
 
112
  if not ALLOW_ABS:
113
  return "", _err(
114
  "absolute_path_disabled",
115
  "Absolute paths are disabled in safe mode.",
116
  path=raw.replace("\\", "/"),
117
- hint="Use a path relative to / (e.g., Notes/index.md).",
118
  )
119
  abs_path = os.path.abspath(raw)
120
  else:
@@ -378,7 +386,7 @@ def _info(abs_path: str) -> str:
378
  @autodoc(summary=TOOL_SUMMARY)
379
  def Obsidian_Vault(
380
  action: Annotated[str, "Operation to perform: 'list', 'read', 'info', 'search', 'help'."],
381
- path: Annotated[str, "Target path, relative to the vault root." ] = ".",
382
  query: Annotated[Optional[str], "Text to search for when action=search."] = None,
383
  recursive: Annotated[bool, "Recurse into subfolders when listing/searching."] = False,
384
  show_hidden: Annotated[bool, "Include hidden files when listing/searching."] = False,
@@ -463,7 +471,7 @@ def build_interface() -> gr.Interface:
463
  choices=["list", "read", "info", "search", "help"],
464
  value="help",
465
  ),
466
- gr.Textbox(label="Path", placeholder=". or Notes/todo.md", max_lines=1, value="."),
467
  gr.Textbox(label="Search text (search)", lines=3, placeholder="Text to search for..."),
468
  gr.Checkbox(label="Recursive (list/search)", value=False),
469
  gr.Checkbox(label="Show hidden (list/search)", value=False),
 
16
  TOOL_SUMMARY = (
17
  "Browse and search the Obsidian vault in read-only mode. "
18
  "Actions: list, read, info, search, help. "
19
+ "All paths resolve within the vault root. Start paths with '/' (e.g., /Notes)."
20
  )
21
 
22
  HELP_TEXT = (
23
  "Obsidian Vault — actions and usage\n\n"
24
  "Root: Tools/Obsidian (override with OBSIDIAN_VAULT_ROOT). "
25
+ "Start paths with '/' to reference the vault root (e.g., /Projects/note.md). "
26
  "Absolute paths are disabled unless UNSAFE_ALLOW_ABS_PATHS=1.\n\n"
27
  "Actions and fields:\n"
28
+ "- list: path='/' (default), recursive=false, show_hidden=false, max_entries=20\n"
29
+ "- read: path (e.g., /Projects/note.md), offset=0, max_chars=4000 (shows next_cursor when truncated)\n"
30
  "- info: path\n"
31
  "- search: path (note or folder), query text in the Search field, recursive=false, show_hidden=false, max_entries=20, case_sensitive=false, offset=0\n"
32
  "- help: show this guide\n\n"
33
  "Errors are returned as JSON with fields: {status:'error', code, message, path?, hint?, data?}.\n\n"
34
  "Examples:\n"
35
+ "- list current: action=list, path='/'\n"
36
+ "- read note: action=read, path='/Projects/note.md', max_chars=500\n"
37
+ "- show metadata: action=info, path='/Inbox'\n"
38
+ "- search notes: action=search, path='/Projects', query='deadline', recursive=true, max_entries=100\n"
39
  "- case-sensitive search: action=search, query='TODO', case_sensitive=true\n"
40
  "- page search results: action=search, query='TODO', offset=20\n"
41
  )
 
107
 
108
  def _resolve_path(path: str) -> tuple[str, str]:
109
  try:
110
+ user_input = (path or "/").strip() or "/"
111
+ if user_input.startswith("/"):
112
+ rel_part = user_input.lstrip("/") or "."
113
+ raw = os.path.expanduser(rel_part)
114
+ treat_as_relative = True
115
+ else:
116
+ raw = os.path.expanduser(user_input)
117
+ treat_as_relative = False
118
+
119
+ if not treat_as_relative and os.path.isabs(raw):
120
  if not ALLOW_ABS:
121
  return "", _err(
122
  "absolute_path_disabled",
123
  "Absolute paths are disabled in safe mode.",
124
  path=raw.replace("\\", "/"),
125
+ hint="Use a path relative to / (e.g., /Notes/index.md).",
126
  )
127
  abs_path = os.path.abspath(raw)
128
  else:
 
386
  @autodoc(summary=TOOL_SUMMARY)
387
  def Obsidian_Vault(
388
  action: Annotated[str, "Operation to perform: 'list', 'read', 'info', 'search', 'help'."],
389
+ path: Annotated[str, "Target path, relative to the vault root." ] = "/",
390
  query: Annotated[Optional[str], "Text to search for when action=search."] = None,
391
  recursive: Annotated[bool, "Recurse into subfolders when listing/searching."] = False,
392
  show_hidden: Annotated[bool, "Include hidden files when listing/searching."] = False,
 
471
  choices=["list", "read", "info", "search", "help"],
472
  value="help",
473
  ),
474
+ gr.Textbox(label="Path", placeholder="/ or /Notes/todo.md", max_lines=1, value="/"),
475
  gr.Textbox(label="Search text (search)", lines=3, placeholder="Text to search for..."),
476
  gr.Checkbox(label="Recursive (list/search)", value=False),
477
  gr.Checkbox(label="Show hidden (list/search)", value=False),