playmaker-cli 0.4.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.
playmaker/config.py ADDED
@@ -0,0 +1,30 @@
1
+ """Read-only access to ~/.playmaker/config.toml."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import tomllib
6
+ from functools import lru_cache
7
+ from typing import Any
8
+
9
+ from playmaker.state import CONFIG_PATH
10
+
11
+
12
+ @lru_cache(maxsize=1)
13
+ def load_config() -> dict[str, Any]:
14
+ """Parse config.toml once per process; missing or broken file -> {}."""
15
+ try:
16
+ with CONFIG_PATH.open("rb") as fh:
17
+ return tomllib.load(fh)
18
+ except (OSError, tomllib.TOMLDecodeError):
19
+ return {}
20
+
21
+
22
+ def agent_setting(agent: str, key: str, default: Any = None) -> Any:
23
+ """Look up [agents.<agent>] <key>, falling back to `default`."""
24
+ return load_config().get("agents", {}).get(agent, {}).get(key, default)
25
+
26
+
27
+ def setting(section: str, key: str, default: Any = None) -> Any:
28
+ """Look up [<section>] <key>, falling back to `default`."""
29
+ value = load_config().get(section, {})
30
+ return value.get(key, default) if isinstance(value, dict) else default
playmaker/notify.py ADDED
@@ -0,0 +1,82 @@
1
+ """macOS notifications.
2
+
3
+ Prefers `terminal-notifier` (clickable — opens a file in the editor on click;
4
+ distinct sounds) and falls back to `osascript` (no click) when it is absent.
5
+ Silent best-effort: never raises into the dispatch path.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import shlex
11
+ import shutil
12
+ import subprocess
13
+
14
+ from playmaker.config import setting
15
+
16
+ # Fallback app used to open agent output when a notification is clicked;
17
+ # override with `editor = "..."` under [notifications] in config.toml.
18
+ DEFAULT_OPEN_WITH_APP = "Zed"
19
+
20
+
21
+ def open_with_app() -> str:
22
+ return str(setting("notifications", "editor", DEFAULT_OPEN_WITH_APP))
23
+
24
+
25
+ def notify(
26
+ title: str,
27
+ message: str,
28
+ *,
29
+ sound: bool = True,
30
+ sound_name: str = "Blow",
31
+ open_path: str | None = None,
32
+ group: str | None = None,
33
+ ) -> None:
34
+ """Fire a macOS notification.
35
+
36
+ `open_path` — file to open in the configured editor when the banner is
37
+ clicked (terminal-notifier only). `group` — coalesce key; same group
38
+ replaces.
39
+ """
40
+ if shutil.which("terminal-notifier"):
41
+ _terminal_notifier(title, message, sound, sound_name, open_path, group)
42
+ else:
43
+ _osascript(title, message, sound, sound_name)
44
+
45
+
46
+ def _terminal_notifier(
47
+ title: str,
48
+ message: str,
49
+ sound: bool,
50
+ sound_name: str,
51
+ open_path: str | None,
52
+ group: str | None,
53
+ ) -> None:
54
+ args = ["terminal-notifier", "-title", title, "-message", message]
55
+ if sound:
56
+ args += ["-sound", sound_name]
57
+ if group:
58
+ args += ["-group", group]
59
+ if open_path:
60
+ # Click → open the file in the editor. Absolute `open` path: -execute
61
+ # runs under a minimal PATH.
62
+ cmd = f"/usr/bin/open -a {shlex.quote(open_with_app())} {shlex.quote(open_path)}"
63
+ args += ["-execute", cmd]
64
+ try:
65
+ subprocess.run(args, capture_output=True, timeout=5)
66
+ except (FileNotFoundError, subprocess.TimeoutExpired):
67
+ pass
68
+
69
+
70
+ def _osascript(title: str, message: str, sound: bool, sound_name: str) -> None:
71
+ safe_title = title.replace('"', "'")
72
+ safe_msg = message.replace('"', "'")
73
+ sound_clause = f' sound name "{sound_name}"' if sound else ""
74
+ script = f'display notification "{safe_msg}" with title "{safe_title}"{sound_clause}'
75
+ try:
76
+ subprocess.run(["osascript", "-e", script], capture_output=True, timeout=5)
77
+ except (FileNotFoundError, subprocess.TimeoutExpired):
78
+ pass
79
+
80
+
81
+ def shell_quote(value: str) -> str:
82
+ return shlex.quote(value)