Skip to content

"CLI-Anything: Making ALL Software Agent-Native" -- CLI-Hub: https://clianything.cc/

Python

fix: correct search endpoint, remove dead api_patch, add error catch-all

Doruk Özgen617fcf3d15fb
diff --git a/obsidian/agent-harness/cli_anything/obsidian/core/search.py b/obsidian/agent-harness/cli_anything/obsidian/core/search.py
index 9b6ad9723..c237ca525 100644
--- a/obsidian/agent-harness/cli_anything/obsidian/core/search.py
+++ b/obsidian/agent-harness/cli_anything/obsidian/core/search.py
@@ -4,18 +4,17 @@ from cli_anything.obsidian.utils.obsidian_backend import api_post
def search_query(base_url: str, api_key: str, query: str) -> dict:
- """Search vault using Obsidian's simple text search.
+ """Search vault using Obsidian's search engine.
Args:
base_url: API base URL.
api_key: Bearer token.
- query: Search query string.
+ query: Search query string (Obsidian search syntax).
Returns:
- List of search results with filename, score, and matches.
+ Search results from Obsidian.
"""
- return api_post(base_url, "/search/simple/", api_key,
- params={"query": query, "contextLength": 100})
+ return api_post(base_url, "/search/", api_key, data={"query": query})
def search_simple(base_url: str, api_key: str, query: str,
diff --git a/obsidian/agent-harness/cli_anything/obsidian/obsidian_cli.py b/obsidian/agent-harness/cli_anything/obsidian/obsidian_cli.py
index 91f7d4877..76ad86041 100644
--- a/obsidian/agent-harness/cli_anything/obsidian/obsidian_cli.py
+++ b/obsidian/agent-harness/cli_anything/obsidian/obsidian_cli.py
@@ -89,6 +89,13 @@ def handle_error(func):
click.echo(f"Error: {e}", err=True)
if not _repl_mode:
sys.exit(1)
+ except Exception as e:
+ if _json_output:
+ click.echo(json.dumps({"error": str(e), "type": type(e).__name__}))
+ else:
+ click.echo(f"Error: {e}", err=True)
+ if not _repl_mode:
+ sys.exit(1)
wrapper.__name__ = func.__name__
wrapper.__doc__ = func.__doc__
return wrapper
diff --git a/obsidian/agent-harness/cli_anything/obsidian/tests/test_core.py b/obsidian/agent-harness/cli_anything/obsidian/tests/test_core.py
index a404e7aa7..0c7e2d6e4 100644
--- a/obsidian/agent-harness/cli_anything/obsidian/tests/test_core.py
+++ b/obsidian/agent-harness/cli_anything/obsidian/tests/test_core.py
@@ -122,19 +122,6 @@ class TestBackend:
result = api_put("https://localhost:27124", "/vault/test.md", "test-key", content="# Hello")
assert result == {"status": "ok"}
- @patch("cli_anything.obsidian.utils.obsidian_backend.requests.patch")
- def test_api_patch(self, mock_patch):
- from cli_anything.obsidian.utils.obsidian_backend import api_patch
- mock_resp = MagicMock()
- mock_resp.status_code = 200
- mock_resp.content = b'{"status": "ok"}'
- mock_resp.headers = {"content-type": "application/json"}
- mock_resp.json.return_value = {"status": "ok"}
- mock_resp.raise_for_status.return_value = None
- mock_patch.return_value = mock_resp
- result = api_patch("https://localhost:27124", "/vault/test.md", "test-key",
- content="appended text", position="end")
- assert result == {"status": "ok"}
# ── Core module tests ────────────────────────────────────────────
@@ -218,8 +205,8 @@ class TestSearchModule:
mock_api.return_value = [{"filename": "note.md", "score": 0.9}]
result = search_query("https://localhost:27124", "test-key", "test query")
mock_api.assert_called_once_with(
- "https://localhost:27124", "/search/simple/", "test-key",
- params={"query": "test query", "contextLength": 100}
+ "https://localhost:27124", "/search/", "test-key",
+ data={"query": "test query"}
)
@patch("cli_anything.obsidian.core.search.api_post")
diff --git a/obsidian/agent-harness/cli_anything/obsidian/utils/obsidian_backend.py b/obsidian/agent-harness/cli_anything/obsidian/utils/obsidian_backend.py
index 9be3275c8..77f99ea5a 100644
--- a/obsidian/agent-harness/cli_anything/obsidian/utils/obsidian_backend.py
+++ b/obsidian/agent-harness/cli_anything/obsidian/utils/obsidian_backend.py
@@ -145,39 +145,6 @@ def api_delete(base_url: str, endpoint: str, api_key: str,
) from e
-def api_patch(base_url: str, endpoint: str, api_key: str,
- content: str = "", position: str = "end",
- timeout: int = 30) -> Any:
- """Perform a PATCH request for appending/prepending content."""
- url = f"{base_url.rstrip('/')}{endpoint}"
- try:
- headers = _headers(api_key, content_type="text/markdown")
- headers["Content-Insertion-Position"] = position
- resp = requests.patch(url, headers=headers,
- data=content.encode("utf-8"),
- timeout=timeout, verify=False)
- resp.raise_for_status()
- if resp.status_code == 204 or not resp.content:
- return {"status": "ok"}
- ct = resp.headers.get("content-type", "")
- if "application/json" in ct:
- return resp.json()
- return {"status": "ok"}
- except requests.exceptions.ConnectionError as e:
- raise RuntimeError(
- f"Cannot connect to Obsidian REST API at {base_url}. "
- "Is Obsidian running with the Local REST API plugin enabled?"
- ) from e
- except requests.exceptions.HTTPError as e:
- raise RuntimeError(
- f"Obsidian API error {resp.status_code} on PATCH {endpoint}: {resp.text}"
- ) from e
- except requests.exceptions.Timeout as e:
- raise RuntimeError(
- f"Request to Obsidian timed out: PATCH {endpoint}"
- ) from e
-
-
def is_available(api_key: str, base_url: str = DEFAULT_BASE_URL) -> bool:
"""Check if Obsidian REST API is reachable."""
try: