sub-pool-client 0.1.0__tar.gz → 0.1.2__tar.gz

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.
Files changed (21) hide show
  1. {sub_pool_client-0.1.0 → sub_pool_client-0.1.2}/.github/workflows/publish.yml +1 -1
  2. {sub_pool_client-0.1.0 → sub_pool_client-0.1.2}/PKG-INFO +13 -5
  3. {sub_pool_client-0.1.0 → sub_pool_client-0.1.2}/README.md +10 -2
  4. {sub_pool_client-0.1.0 → sub_pool_client-0.1.2}/examples/hello.py +4 -4
  5. {sub_pool_client-0.1.0 → sub_pool_client-0.1.2}/meta/README.md +1 -1
  6. {sub_pool_client-0.1.0 → sub_pool_client-0.1.2}/meta/pyproject.toml +2 -2
  7. {sub_pool_client-0.1.0 → sub_pool_client-0.1.2}/pyproject.toml +2 -2
  8. {sub_pool_client-0.1.0 → sub_pool_client-0.1.2}/sub_pool_client/_cli_core.py +28 -6
  9. {sub_pool_client-0.1.0 → sub_pool_client-0.1.2}/sub_pool_client/_cli_provider.py +31 -0
  10. {sub_pool_client-0.1.0 → sub_pool_client-0.1.2}/sub_pool_client/_shared.py +7 -0
  11. {sub_pool_client-0.1.0 → sub_pool_client-0.1.2}/sub_pool_client/_version.py +2 -2
  12. {sub_pool_client-0.1.0 → sub_pool_client-0.1.2}/sub_pool_client/client.py +2 -0
  13. {sub_pool_client-0.1.0 → sub_pool_client-0.1.2}/sub_pool_client/codex.py +2 -0
  14. {sub_pool_client-0.1.0 → sub_pool_client-0.1.2}/.gitignore +0 -0
  15. {sub_pool_client-0.1.0 → sub_pool_client-0.1.2}/examples/codex_hello.py +0 -0
  16. {sub_pool_client-0.1.0 → sub_pool_client-0.1.2}/sub_pool_client/__init__.py +0 -0
  17. {sub_pool_client-0.1.0 → sub_pool_client-0.1.2}/sub_pool_client/_health_watcher.py +0 -0
  18. {sub_pool_client-0.1.0 → sub_pool_client-0.1.2}/sub_pool_client/_swap.py +0 -0
  19. {sub_pool_client-0.1.0 → sub_pool_client-0.1.2}/sub_pool_client/cli_claude.py +0 -0
  20. {sub_pool_client-0.1.0 → sub_pool_client-0.1.2}/sub_pool_client/cli_codex.py +0 -0
  21. {sub_pool_client-0.1.0 → sub_pool_client-0.1.2}/sub_pool_client/errors.py +0 -0
@@ -6,7 +6,7 @@ name: publish
6
6
  # doesn't go out without a click).
7
7
  #
8
8
  # Trusted Publishing — no long-lived tokens. Two pending publishers
9
- # need to be registered (owner=Zephyroam, repo=sub-pool-client,
9
+ # need to be registered (owner=subs-pool, repo=sub-pool-client,
10
10
  # workflow=publish.yml):
11
11
  #
12
12
  # - PyPI env=pypi project=sub-pool-client
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sub-pool-client
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: Python client + `sp-claude` / `sp-codex` CLIs for a sub-pool credential broker.
5
- Project-URL: Homepage, https://github.com/Zephyroam/sub-pool-client
6
- Project-URL: Repository, https://github.com/Zephyroam/sub-pool-client
5
+ Project-URL: Homepage, https://github.com/subs-pool/sub-pool-client
6
+ Project-URL: Repository, https://github.com/subs-pool/sub-pool-client
7
7
  Requires-Python: >=3.12
8
8
  Requires-Dist: claude-agent-sdk>=0.1.63
9
9
  Requires-Dist: click>=8.1
@@ -37,9 +37,17 @@ only sees lease lifecycles.
37
37
  ## Install
38
38
 
39
39
  ```bash
40
- pip install git+https://github.com/Zephyroam/sub-pool-client
40
+ pip install sub-pool-client
41
41
  # or
42
- uv pip install git+https://github.com/Zephyroam/sub-pool-client
42
+ uv pip install sub-pool-client
43
+ ```
44
+
45
+ [![PyPI](https://img.shields.io/pypi/v/sub-pool-client.svg)](https://pypi.org/project/sub-pool-client/)
46
+
47
+ Latest release tracks `main`. To install from source instead:
48
+
49
+ ```bash
50
+ pip install git+https://github.com/subs-pool/sub-pool-client
43
51
  ```
44
52
 
45
53
  ## Environment
@@ -25,9 +25,17 @@ only sees lease lifecycles.
25
25
  ## Install
26
26
 
27
27
  ```bash
28
- pip install git+https://github.com/Zephyroam/sub-pool-client
28
+ pip install sub-pool-client
29
29
  # or
30
- uv pip install git+https://github.com/Zephyroam/sub-pool-client
30
+ uv pip install sub-pool-client
31
+ ```
32
+
33
+ [![PyPI](https://img.shields.io/pypi/v/sub-pool-client.svg)](https://pypi.org/project/sub-pool-client/)
34
+
35
+ Latest release tracks `main`. To install from source instead:
36
+
37
+ ```bash
38
+ pip install git+https://github.com/subs-pool/sub-pool-client
31
39
  ```
32
40
 
33
41
  ## Environment
@@ -1,10 +1,10 @@
1
1
  """Minimal end-to-end usage (credential-broker mode).
2
2
 
3
3
  Before running:
4
- 1. Install: uv pip install -e .
5
- 2. Have a running sub-pool server with at least one connected Claude
6
- account and an API key.
7
- 3. Run: SUB_POOL_URL=http://localhost:8787 \
4
+ 1. Install: uv pip install -e . -e ./client
5
+ 2. Run pool: docker compose up -d (from the sub-pool deployment dir)
6
+ 3. Log in an account via the admin UI + create an API key
7
+ 4. Run: SUB_POOL_URL=http://localhost:8787 \
8
8
  SUB_POOL_KEY=cp-... \
9
9
  python examples/hello.py
10
10
 
@@ -17,5 +17,5 @@ pip install sub-pool-client
17
17
  Then either use the CLIs (`sp-claude`, `sp-codex`) or the Python SDK
18
18
  (`from sub_pool_client import PooledClient, PooledCodexClient`).
19
19
 
20
- See <https://github.com/Zephyroam/sub-pool-client> for the full client
20
+ See <https://github.com/subs-pool/sub-pool-client> for the full client
21
21
  docs.
@@ -7,8 +7,8 @@ requires-python = ">=3.12"
7
7
  dependencies = ["sub-pool-client"]
8
8
 
9
9
  [project.urls]
10
- Homepage = "https://github.com/Zephyroam/sub-pool-client"
11
- Repository = "https://github.com/Zephyroam/sub-pool-client"
10
+ Homepage = "https://github.com/subs-pool/sub-pool-client"
11
+ Repository = "https://github.com/subs-pool/sub-pool-client"
12
12
 
13
13
  [build-system]
14
14
  requires = ["hatchling"]
@@ -11,8 +11,8 @@ dependencies = [
11
11
  ]
12
12
 
13
13
  [project.urls]
14
- Homepage = "https://github.com/Zephyroam/sub-pool-client"
15
- Repository = "https://github.com/Zephyroam/sub-pool-client"
14
+ Homepage = "https://github.com/subs-pool/sub-pool-client"
15
+ Repository = "https://github.com/subs-pool/sub-pool-client"
16
16
 
17
17
  [project.scripts]
18
18
  sp-claude = "sub_pool_client.cli_claude:main"
@@ -90,13 +90,29 @@ class Config:
90
90
 
91
91
  @classmethod
92
92
  def load(cls) -> "Config | None":
93
- if not CONFIG_PATH.exists():
94
- return None
95
- import tomllib
96
- data = tomllib.loads(CONFIG_PATH.read_text())
93
+ """Resolve pool_url + api_key from env vars first, falling back
94
+ to `~/.sub-pool/cli.toml`. Per-provider sections (bin paths /
95
+ default accounts) come from the TOML only — env vars cover the
96
+ pool credentials, which is what CI / Docker / ephemeral runs
97
+ actually need.
98
+
99
+ Returns None only when neither source supplies both pool_url
100
+ AND api_key — that's the "go run --setup" signal in main().
101
+ """
102
+ env_url = (os.environ.get("SUB_POOL_URL") or "").strip()
103
+ env_key = (os.environ.get("SUB_POOL_KEY") or "").strip()
104
+
105
+ data: dict = {}
106
+ if CONFIG_PATH.exists():
107
+ import tomllib
108
+ data = tomllib.loads(CONFIG_PATH.read_text())
109
+
97
110
  pool = data.get("pool") or {}
98
- if not pool.get("url") or not pool.get("api_key"):
111
+ pool_url = env_url or (pool.get("url") or "")
112
+ api_key = env_key or (pool.get("api_key") or "")
113
+ if not pool_url or not api_key:
99
114
  return None
115
+
100
116
  per_provider: dict[str, dict[str, str]] = {}
101
117
  for name in ("claude", "codex"):
102
118
  section = data.get(name)
@@ -105,7 +121,7 @@ class Config:
105
121
  k: str(v) for k, v in section.items()
106
122
  if isinstance(v, (str, int, float))
107
123
  }
108
- return cls(pool_url=pool["url"], api_key=pool["api_key"],
124
+ return cls(pool_url=pool_url, api_key=api_key,
109
125
  per_provider=per_provider)
110
126
 
111
127
  def write(self) -> None:
@@ -270,6 +286,12 @@ def setup_session_dir(
270
286
  """
271
287
  home.mkdir(parents=True, exist_ok=True)
272
288
  os.chmod(home, 0o700)
289
+ # Seed any first-run state the provider needs in its persistent
290
+ # home (claude wants a `.claude.json` so Code's onboarding wizard
291
+ # is skipped on the leased REPL). Runs before the symlink loop so
292
+ # the seeded file shows up in the session dir too.
293
+ if provider.init_home is not None:
294
+ provider.init_home(home)
273
295
  for entry in home.iterdir():
274
296
  if _is_per_session(entry.name, provider.cred_skip_prefixes):
275
297
  continue
@@ -57,6 +57,32 @@ def _write_codex_auth(path: Path, lease: dict) -> None:
57
57
  _atomic_write_json(path, auth)
58
58
 
59
59
 
60
+ def _seed_claude_home(home: Path) -> None:
61
+ """Pre-write a minimal `.claude.json` so Claude Code's first-run
62
+ onboarding wizard does not appear inside the leased REPL.
63
+
64
+ Claude Code gates its onboarding wizard on the presence of
65
+ `hasCompletedOnboarding` in `$CLAUDE_CONFIG_DIR/.claude.json` —
66
+ not on whether `.credentials.json` already holds a valid OAuth
67
+ token. Worse, the wizard's "Sign in with Claude account" path
68
+ starts a *new* browser OAuth flow rather than reusing the leased
69
+ `.credentials.json`, so falling into the wizard wipes out the
70
+ pool's credential entirely.
71
+
72
+ Idempotent: only writes when no `.claude.json` exists yet. If a
73
+ future Claude Code release changes the wizard contract, deleting
74
+ `~/.sub-pool/claude-home/.claude.json` and re-running sp-claude
75
+ is enough to inspect the new schema by hand.
76
+ """
77
+ claude_json = home / ".claude.json"
78
+ if claude_json.exists():
79
+ return
80
+ _atomic_write_json(claude_json, {
81
+ "hasCompletedOnboarding": True,
82
+ "lastOnboardingVersion": "2.1.144",
83
+ })
84
+
85
+
60
86
  def _atomic_write_json(path: Path, payload: Any) -> None:
61
87
  """Create at 0o600 from the start (no readable window) and atomic-rename."""
62
88
  tmp = path.with_suffix(path.suffix + ".tmp")
@@ -102,6 +128,10 @@ class CliProvider:
102
128
  # Pluggable credential writer — kept on the provider so the engine
103
129
  # never has to switch on `name`.
104
130
  write_credentials: Callable[[Path, dict], None]
131
+ # Optional first-run hook called on the persistent home dir before
132
+ # symlinks get laid down. Used by Claude to seed a no-onboarding
133
+ # `.claude.json`; Codex doesn't need it.
134
+ init_home: Callable[[Path], None] | None = None
105
135
 
106
136
 
107
137
  CLAUDE = CliProvider(
@@ -118,6 +148,7 @@ CLAUDE = CliProvider(
118
148
  ),
119
149
  lease_body_extras={},
120
150
  write_credentials=_write_claude_credentials,
151
+ init_home=_seed_claude_home,
121
152
  )
122
153
 
123
154
 
@@ -77,6 +77,11 @@ class Meta:
77
77
  # Stays None when no leader has been elected yet (e.g. during
78
78
  # bring-up, or after a graceful leader exit before a takeover).
79
79
  poll_leader: int | None = None
80
+ # Account name returned by the pool for this lease. Persisted so
81
+ # late-arriving holders that JOIN an existing lease can report the
82
+ # right account through `client.account` — they never saw the
83
+ # original `POST /credentials/lease` response themselves.
84
+ account: str | None = None
80
85
 
81
86
  @classmethod
82
87
  def from_json(cls, d: dict) -> "Meta":
@@ -84,6 +89,7 @@ class Meta:
84
89
  lease_id=d.get("lease_id"),
85
90
  holders=list(d.get("holders") or []),
86
91
  poll_leader=d.get("poll_leader"),
92
+ account=d.get("account"),
87
93
  )
88
94
 
89
95
  def to_json(self) -> dict:
@@ -91,6 +97,7 @@ class Meta:
91
97
  "lease_id": self.lease_id,
92
98
  "holders": self.holders or [],
93
99
  "poll_leader": self.poll_leader,
100
+ "account": self.account,
94
101
  }
95
102
 
96
103
 
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '0.1.0'
22
- __version_tuple__ = version_tuple = (0, 1, 0)
21
+ __version__ = version = '0.1.2'
22
+ __version_tuple__ = version_tuple = (0, 1, 2)
23
23
 
24
24
  __commit_id__ = commit_id = None
@@ -175,6 +175,7 @@ class PooledClient(ClaudeSDKClient):
175
175
  if meta.lease_id and meta.holders:
176
176
  # Active lease already present — reuse it.
177
177
  self._lease_id = meta.lease_id
178
+ self._lease_account = meta.account
178
179
  # Always append (one entry per __aenter__, not per pid)
179
180
  # so N `async with` in the same pid are refcounted by
180
181
  # N removes on exit.
@@ -203,6 +204,7 @@ class PooledClient(ClaudeSDKClient):
203
204
  bundle.get("expires_at") or lease.get("token_expires_at") or 0.0
204
205
  )
205
206
  meta.lease_id = self._lease_id
207
+ meta.account = self._lease_account
206
208
  meta.holders = [my_pid]
207
209
  meta.poll_leader = my_pid
208
210
  self._is_first_holder = True
@@ -204,6 +204,7 @@ class PooledCodexClient:
204
204
  if meta.lease_id and meta.holders:
205
205
  # Active lease already present — reuse it.
206
206
  self._lease_id = meta.lease_id
207
+ self._lease_account = meta.account
207
208
  meta.holders.append(my_pid)
208
209
  # locked_meta cleared dead-pid leaders, so poll_leader is
209
210
  # either a live pid or None. Claim leadership right away
@@ -228,6 +229,7 @@ class PooledCodexClient:
228
229
  self._lease_request_id = lease.get("request_id")
229
230
  self._token_expires_at = float(lease.get("token_expires_at") or 0.0)
230
231
  meta.lease_id = self._lease_id
232
+ meta.account = self._lease_account
231
233
  meta.holders = [my_pid]
232
234
  meta.poll_leader = my_pid
233
235
  self._is_poll_leader = True