Skip to content

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

Python

fix: read doc-tree entries from files key instead of tree (SiYuan API shape)

hitofe27d44825ac
diff --git a/siyuan/agent-harness/cli_anything/siyuan/siyuan_cli.py b/siyuan/agent-harness/cli_anything/siyuan/siyuan_cli.py
index 814dac1e6..a1c62552c 100644
--- a/siyuan/agent-harness/cli_anything/siyuan/siyuan_cli.py
+++ b/siyuan/agent-harness/cli_anything/siyuan/siyuan_cli.py
@@ -262,12 +262,12 @@ def _handle_repl_command(skin: Any, cmd: str) -> None:
for d in items])
elif sub == "tree" and len(parts) >= 3:
tree = client.list_doc_tree(parts[2])
- items = tree.get("tree", []) if isinstance(tree, dict) else tree
+ items = tree.get("files", []) if isinstance(tree, dict) else tree
if json_mode:
click.echo(json.dumps(items, ensure_ascii=False))
else:
- skin.table(["ID", "Title", "Path"],
- [[t.get("id", ""), t.get("title", ""), t.get("path", "")]
+ skin.table(["ID", "Name", "Path"],
+ [[t.get("id", ""), t.get("name", ""), t.get("path", "")]
for t in items])
elif sub == "get" and len(parts) >= 3:
hpath = client.get_hpath_by_id(parts[2])
@@ -486,13 +486,13 @@ def doc_list(ctx: SiYuanContext, notebook_id: str, path: str):
def doc_tree(ctx: SiYuanContext, notebook_id: str, path: str, depth: int):
"""List document tree."""
tree = ctx.client.list_doc_tree(notebook_id, path=path, max_depth=depth)
- items = tree.get("tree", []) if isinstance(tree, dict) else tree
+ items = tree.get("files", []) if isinstance(tree, dict) else tree
if ctx.json_output:
click.echo(json.dumps(items, ensure_ascii=False))
else:
for t in items:
indent = " " * t.get("depth", 0)
- click.echo(f"{indent}{t.get('title', '')} ({t.get('id', '')})")
+ click.echo(f"{indent}{t.get('name', '')} ({t.get('id', '')})")
@doc.command("get")
diff --git a/siyuan/agent-harness/cli_anything/siyuan/tests/test_cli_commands.py b/siyuan/agent-harness/cli_anything/siyuan/tests/test_cli_commands.py
index 6452ece99..780a4e317 100644
--- a/siyuan/agent-harness/cli_anything/siyuan/tests/test_cli_commands.py
+++ b/siyuan/agent-harness/cli_anything/siyuan/tests/test_cli_commands.py
@@ -141,12 +141,12 @@ class TestDocListCommand:
class TestDocTreeCommand:
- def test_doc_tree_returns_tree(self, runner, mock_ctx):
- """doc tree handles API returning dict with 'tree' key."""
+ def test_doc_tree_returns_files(self, runner, mock_ctx):
+ """doc tree handles API returning dict with 'files' key."""
mock_ctx.client.list_doc_tree.return_value = {
- "tree": [
- {"id": "doc1", "title": "根文档", "depth": 0},
- {"id": "doc2", "title": "子文档", "depth": 1},
+ "files": [
+ {"id": "doc1", "name": "根文档", "depth": 0},
+ {"id": "doc2", "name": "子文档", "depth": 1},
],
}
with patch("cli_anything.siyuan.siyuan_cli.SiYuanContext", return_value=mock_ctx):
@@ -156,10 +156,10 @@ class TestDocTreeCommand:
assert "子文档" in result.output
def test_doc_tree_json(self, runner, mock_ctx):
- """--json doc tree returns raw tree array."""
+ """--json doc tree returns raw files array."""
mock_ctx.json_output = True
mock_ctx.client.list_doc_tree.return_value = {
- "tree": [{"id": "doc1", "title": "Root"}],
+ "files": [{"id": "doc1", "name": "Root"}],
}
with patch("cli_anything.siyuan.siyuan_cli.SiYuanContext", return_value=mock_ctx):
result = runner.invoke(cli, ["--json", "doc", "tree", "nb1"])