aboutsummaryrefslogtreecommitdiffstats
path: root/claude_logbook/terminal.py
diff options
context:
space:
mode:
authorElvis Claros Castro <elvis@claros.ar>2026-10-03 12:05:23 -0300
committerElvis Claros Castro <elvis@claros.ar>2026-10-03 12:05:23 -0300
commit471e20a03503d3951a6fe12c1f3a354043a42e05 (patch)
tree1f9021f803d24cca19b694bab001492c3918565c /claude_logbook/terminal.py
parentd3d0416b45698b9d40700b2196400542dc77c9ce (diff)
downloadclaude-logbook-471e20a03503d3951a6fe12c1f3a354043a42e05.tar.gz
claude-logbook-471e20a03503d3951a6fe12c1f3a354043a42e05.zip
Manage permission rules, extra directories and folder trust
-P lists the allow/ask/deny rules and additionalDirectories of the user, project and local settings, plus hasTrustDialogAccepted from ~/.claude.json. --allow, --ask, --deny, --remove-rule, --add-dir, --remove-dir, --trust and --untrust edit them in place, keeping every other key, the file mode and the trailing newline; --dry-run shows the change without making it.
Diffstat (limited to 'claude_logbook/terminal.py')
-rw-r--r--claude_logbook/terminal.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/claude_logbook/terminal.py b/claude_logbook/terminal.py
index 8ecd070..65af046 100644
--- a/claude_logbook/terminal.py
+++ b/claude_logbook/terminal.py
@@ -7,6 +7,7 @@ import subprocess
import sys
import textwrap
+from .config import is_empty
from .sessions import parse_ts
MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
@@ -370,3 +371,60 @@ def print_audit(report, st, out):
print(file=out)
return total
+
+
+# ──────────────────────────────── permissions ────────────────────────────
+
+RULE_COLOR = {"allow": "amber", "ask": "blue", "deny": "copper", "dirs": "grey",
+ "mode": "grey"}
+
+
+def _print_rules(r, st, out, indent):
+ for key in ("allow", "ask", "deny", "dirs"):
+ color = getattr(st, RULE_COLOR[key])
+ for i, item in enumerate(r[key]):
+ label = key if i == 0 else ""
+ print(f"{indent}{st.faint}{label:<6}{st.reset} {color}{item}{st.reset}",
+ file=out)
+ if r["mode"]:
+ print(f"{indent}{st.faint}{'mode':<6}{st.reset} {r['mode']}", file=out)
+
+
+def short_home(path):
+ home = os.path.expanduser("~")
+ return "~" + path[len(home):] if path == home or path.startswith(home + "/") else path
+
+
+def trust_label(p, st):
+ if p["trusted"]:
+ return f"{st.amber}trusted{st.reset}"
+ if p["parent"]:
+ return f"{st.faint}not trusted · parent {short_home(p['parent'])} is{st.reset}"
+ return f"{st.copper}not trusted{st.reset}"
+
+
+def print_permissions(view, st, out, show_all=False):
+ """User scope, then each project with rules (or every one if show_all)."""
+ user = view["user"]
+ print(f"{st.bold}user{st.reset} {st.faint}{short_home(user['path'])}{st.reset}",
+ file=out)
+ if is_empty(user["rules"]):
+ print(f" {st.faint}no rules{st.reset}", file=out)
+ else:
+ _print_rules(user["rules"], st, out, " ")
+
+ shown = 0
+ for p in view["projects"]:
+ with_rules = [s for s in p["scopes"] if not is_empty(s["rules"])]
+ if not with_rules and not show_all:
+ continue
+ shown += 1
+ gone = "" if p["exists"] else f" {st.faint}(directory gone){st.reset}"
+ print(f"\n{st.ink}{short_home(p['path'])}{st.reset} {trust_label(p, st)}{gone}",
+ file=out)
+ for s in with_rules:
+ name = os.path.relpath(s["path"], p["path"])
+ print(f" {st.grey}{s['scope']:<7}{st.reset} {st.faint}{name}{st.reset}",
+ file=out)
+ _print_rules(s["rules"], st, out, " ")
+ return shown