batonsh 0.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.
baton/__init__.py ADDED
@@ -0,0 +1,54 @@
1
+ """Python SDK for Baton — drive the multi-agent daemon (batond) from scripts.
2
+
3
+ import baton
4
+
5
+ with baton.connect() as client: # starts the project daemon if needed
6
+ run = client.run_state()
7
+ seq = run.last_seq
8
+ client.submit("fix the flaky test in tests/api")
9
+ run.wait_idle(timeout=600, since_seq=seq)
10
+ for a in run.agents.values():
11
+ print(a.name, a.status, a.diff, "$%.2f" % a.cost)
12
+ """
13
+
14
+ from ._discovery import discover_socket, find_project_root, project_paths
15
+ from .client import (
16
+ CONTROL_PROTOCOL_VERSION,
17
+ BatonError,
18
+ BatonTimeoutError,
19
+ Client,
20
+ Conflict,
21
+ ConnectionClosed,
22
+ InvalidParams,
23
+ NotFound,
24
+ Subscription,
25
+ Unavailable,
26
+ VersionMismatch,
27
+ connect,
28
+ )
29
+ from .run import BUSY_STATUSES, Agent, Approval, RunState, Workspace
30
+
31
+ __version__ = "0.1.0"
32
+
33
+ __all__ = [
34
+ "CONTROL_PROTOCOL_VERSION",
35
+ "BUSY_STATUSES",
36
+ "Agent",
37
+ "Approval",
38
+ "BatonError",
39
+ "BatonTimeoutError",
40
+ "Client",
41
+ "ConnectionClosed",
42
+ "Conflict",
43
+ "InvalidParams",
44
+ "NotFound",
45
+ "Unavailable",
46
+ "VersionMismatch",
47
+ "RunState",
48
+ "Subscription",
49
+ "Workspace",
50
+ "connect",
51
+ "discover_socket",
52
+ "find_project_root",
53
+ "project_paths",
54
+ ]
baton/_discovery.py ADDED
@@ -0,0 +1,50 @@
1
+ """Project root and socket discovery (mirrors @batonsh/kernel findProjectRoot / projectPaths)."""
2
+
3
+ import os
4
+ from typing import Dict, Optional
5
+
6
+
7
+ def find_project_root(start: Optional[str] = None) -> str:
8
+ """Walk up from ``start`` looking for ``.baton/config.toml``, then ``.git``; falls back to ``start``."""
9
+ begin = os.path.abspath(start if start is not None else os.getcwd())
10
+ d = begin
11
+ git_root = None
12
+ while True:
13
+ if os.path.exists(os.path.join(d, ".baton", "config.toml")):
14
+ return d
15
+ if git_root is None and os.path.exists(os.path.join(d, ".git")):
16
+ git_root = d
17
+ parent = os.path.dirname(d)
18
+ if parent == d:
19
+ break
20
+ d = parent
21
+ return git_root if git_root is not None else begin
22
+
23
+
24
+ def project_paths(root: str) -> Dict[str, str]:
25
+ d = os.path.join(root, ".baton")
26
+ run = os.path.join(d, "run")
27
+ return {
28
+ "dir": d,
29
+ "config": os.path.join(d, "config.toml"),
30
+ "state": os.path.join(d, "state.db"),
31
+ "run": run,
32
+ "socket": os.path.join(run, "baton.sock"),
33
+ "pid_file": os.path.join(run, "batond.pid"),
34
+ "log": os.path.join(run, "batond.log"),
35
+ "worktrees": os.path.join(d, "worktrees"),
36
+ }
37
+
38
+
39
+ def discover_socket(project_root: str) -> str:
40
+ """The daemon's socket: ``.baton/run/socket-path`` (long project paths) or ``.baton/run/baton.sock``."""
41
+ paths = project_paths(project_root)
42
+ alt = os.path.join(paths["run"], "socket-path")
43
+ try:
44
+ with open(alt, "r", encoding="utf-8") as f:
45
+ p = f.read().strip()
46
+ if p:
47
+ return p
48
+ except OSError:
49
+ pass
50
+ return paths["socket"]