claude-dev-env 8.110.2 → 8.110.3
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.
- package/.agents/skills/usage-pause/scripts/resolve_usage_window.py +3 -1
- package/.agents/skills/usage-pause/scripts/test_resolve_usage_window.py +14 -0
- package/docs/second-claude-account.md +6 -3
- package/package.json +1 -1
- package/scripts/dev_env_scripts_constants/account_broker_constants.py +5 -19
- package/scripts/test_account_broker.py +13 -0
|
@@ -263,7 +263,9 @@ def read_oauth_access_token(credentials_path: Path, now: datetime) -> str | None
|
|
|
263
263
|
logger.warning("credential file is missing the token or its expiry")
|
|
264
264
|
return None
|
|
265
265
|
if expires_at_milliseconds <= now.timestamp() * MILLISECONDS_PER_SECOND:
|
|
266
|
-
logger.warning(
|
|
266
|
+
logger.warning(
|
|
267
|
+
"stored access token at %s is expired; probe unavailable", credentials_path
|
|
268
|
+
)
|
|
267
269
|
return None
|
|
268
270
|
return access_token
|
|
269
271
|
|
|
@@ -174,6 +174,20 @@ class TestReadOauthAccessToken:
|
|
|
174
174
|
write_credentials(credentials_path, past_milliseconds)
|
|
175
175
|
assert resolver.read_oauth_access_token(credentials_path, now) is None
|
|
176
176
|
|
|
177
|
+
def should_name_the_credential_file_when_its_token_expired(
|
|
178
|
+
self, tmp_path: Path, caplog: pytest.LogCaptureFixture
|
|
179
|
+
) -> None:
|
|
180
|
+
resolver = load_resolver_module()
|
|
181
|
+
now = local_now()
|
|
182
|
+
credentials_path = tmp_path / ".credentials.json"
|
|
183
|
+
past_milliseconds = int((now - timedelta(hours=1)).timestamp() * 1000)
|
|
184
|
+
write_credentials(credentials_path, past_milliseconds)
|
|
185
|
+
with caplog.at_level(logging.WARNING):
|
|
186
|
+
resolver.read_oauth_access_token(credentials_path, now)
|
|
187
|
+
assert [each_record.getMessage() for each_record in caplog.records] == [
|
|
188
|
+
f"stored access token at {credentials_path} is expired; probe unavailable"
|
|
189
|
+
]
|
|
190
|
+
|
|
177
191
|
def should_not_warn_when_credential_file_missing(
|
|
178
192
|
self, tmp_path: Path, caplog: pytest.LogCaptureFixture
|
|
179
193
|
) -> None:
|
|
@@ -47,7 +47,9 @@ room.
|
|
|
47
47
|
|
|
48
48
|
When no account has room, the job waits until the next account reset, or for one
|
|
49
49
|
hour when no reset is known. An unreadable meter never picks its account, and
|
|
50
|
-
the wait reason names each account whose meter could not be read.
|
|
50
|
+
the wait reason names each account whose meter could not be read. A window the
|
|
51
|
+
usage endpoint returns as `null` holds no account back, but an account needs at
|
|
52
|
+
least one window with a percent to have room.
|
|
51
53
|
|
|
52
54
|
```
|
|
53
55
|
python packages/claude-dev-env/scripts/account_broker.py choose --product claude
|
|
@@ -55,7 +57,8 @@ python packages/claude-dev-env/scripts/account_broker.py choose --product claude
|
|
|
55
57
|
|
|
56
58
|
The JSON output has a `decision` object and an `accounts` list. Each account's
|
|
57
59
|
`meters` holds its remaining percent and reset time for the 5-hour window and
|
|
58
|
-
the week. An
|
|
59
|
-
`unread_reason` holds the failure text when the reader raised one. A
|
|
60
|
+
the week. An account whose meter could not be read has `meters` of `null`, and
|
|
61
|
+
its `unread_reason` holds the failure text when the reader raised one. A window
|
|
62
|
+
with no data has a `null` percent inside a read `meters` object. A wait decision has
|
|
60
63
|
`action: "wait"` and a `resets_at` timestamp. The broker exits with code 3 on
|
|
61
64
|
wait. The worker writes the same reset time to its report.
|
package/package.json
CHANGED
|
@@ -282,14 +282,6 @@ def _claude_blocking_flags(meters: Meters, is_main: bool) -> tuple[bool, bool]:
|
|
|
282
282
|
)
|
|
283
283
|
|
|
284
284
|
|
|
285
|
-
def _claude_extra_tier(meters: Meters | None) -> str | None:
|
|
286
|
-
if meters is None or meters.tightest_percent_left is None:
|
|
287
|
-
return None
|
|
288
|
-
if any(_claude_blocking_flags(meters, is_main=False)):
|
|
289
|
-
return None
|
|
290
|
-
return "normal"
|
|
291
|
-
|
|
292
|
-
|
|
293
285
|
def _codex_tier(meters: Meters | None) -> str | None:
|
|
294
286
|
if meters is None or meters.tightest_percent_left is None:
|
|
295
287
|
return None
|
|
@@ -334,21 +326,15 @@ def _rank_key(reading: Reading) -> tuple[bool, int, bool, float]:
|
|
|
334
326
|
return (priority is None, priority or 0, not is_pro_plan, -(room if room is not None else -1.0))
|
|
335
327
|
|
|
336
328
|
|
|
337
|
-
def
|
|
338
|
-
|
|
329
|
+
def _claude_has_room(reading: Reading) -> bool:
|
|
330
|
+
meters = reading.meters
|
|
331
|
+
return (
|
|
339
332
|
meters is not None
|
|
340
|
-
and meters.
|
|
341
|
-
and meters.
|
|
342
|
-
and not any(_claude_blocking_flags(meters, is_main=True))
|
|
333
|
+
and meters.tightest_percent_left is not None
|
|
334
|
+
and not any(_claude_blocking_flags(meters, reading.account.is_main))
|
|
343
335
|
)
|
|
344
336
|
|
|
345
337
|
|
|
346
|
-
def _claude_has_room(reading: Reading) -> bool:
|
|
347
|
-
if reading.account.is_main:
|
|
348
|
-
return _main_has_room(reading.meters)
|
|
349
|
-
return _claude_extra_tier(reading.meters) is not None
|
|
350
|
-
|
|
351
|
-
|
|
352
338
|
def _choose_claude(all_available: Sequence[Reading], preferred_command: str | None) -> Decision | None:
|
|
353
339
|
all_with_room = [each_reading for each_reading in all_available if _claude_has_room(each_reading)]
|
|
354
340
|
for each_reading in all_with_room:
|
|
@@ -233,6 +233,19 @@ def test_should_pick_main_when_it_is_the_only_readable_account() -> None:
|
|
|
233
233
|
assert decision.account == main.account
|
|
234
234
|
|
|
235
235
|
|
|
236
|
+
def test_should_pick_main_when_its_5_hour_meter_is_null_and_its_week_has_room() -> None:
|
|
237
|
+
main = Reading(
|
|
238
|
+
_account("main", Product.CLAUDE, main=True),
|
|
239
|
+
Meters(None, None, 96.0, NOW + timedelta(days=5)),
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
decision = choose_from_readings(Product.CLAUDE, (main,), now=NOW)
|
|
243
|
+
|
|
244
|
+
assert decision.action == "run"
|
|
245
|
+
assert decision.account == main.account
|
|
246
|
+
assert decision.reason == "main has 96% left"
|
|
247
|
+
|
|
248
|
+
|
|
236
249
|
def test_should_wait_for_main_5_hour_reset_while_its_week_resets_days_away() -> None:
|
|
237
250
|
short_reset = NOW + timedelta(hours=2)
|
|
238
251
|
main = Reading(
|