siyuan-cli 1.1.0__py3-none-any.whl

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.
siyuan_cli/__init__.py ADDED
@@ -0,0 +1,7 @@
1
+ """siyuan-cli — SiYuan Note command-line tool.
2
+
3
+ Package for interacting with SiYuan Note's HTTP API.
4
+ Create, read, search, and manage notes, blocks, tags, and assets.
5
+ """
6
+
7
+ __version__ = "1.1.0"
siyuan_cli/__main__.py ADDED
@@ -0,0 +1,5 @@
1
+ """Entry point for `python3 -m siyuan_cli`."""
2
+
3
+ from siyuan_cli.cli import main
4
+
5
+ main()
siyuan_cli/audit.py ADDED
@@ -0,0 +1,44 @@
1
+ """Audit trail for destructive operations in siyuan-cli."""
2
+
3
+ import json
4
+ import os
5
+ import time
6
+ from typing import Any
7
+
8
+ AUDIT_FILE = os.path.expanduser("~/.siyuan/audit.log")
9
+
10
+
11
+ def _format_ts() -> str:
12
+ """ISO 8601 timestamp."""
13
+ return time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime())
14
+
15
+
16
+ def log_destructive(
17
+ action: str,
18
+ target: str,
19
+ detail: dict[str, Any] | None = None,
20
+ confirmed_via: str = "",
21
+ ) -> None:
22
+ """Log a destructive operation to the audit trail.
23
+
24
+ Args:
25
+ action: Human-readable action (e.g. "DELETE_DOC", "REMOVE_NOTEBOOK").
26
+ target: The resource identifier (document path, block ID, notebook ID).
27
+ detail: Optional extra context (e.g. notebook ID, timestamp).
28
+ confirmed_via: How the user confirmed (e.g. "--yes", "interactive").
29
+ """
30
+ entry: dict[str, Any] = {
31
+ "ts": _format_ts(),
32
+ "action": action,
33
+ "target": target,
34
+ }
35
+ if detail:
36
+ entry["detail"] = detail
37
+ if confirmed_via:
38
+ entry["confirmed"] = confirmed_via
39
+
40
+ parent = os.path.dirname(AUDIT_FILE)
41
+ if not os.path.isdir(parent):
42
+ os.makedirs(parent, mode=0o700)
43
+ with open(AUDIT_FILE, "a", encoding="utf-8") as f:
44
+ f.write(json.dumps(entry, ensure_ascii=False) + "\n")