claude-dev-env 8.114.6 → 8.114.7

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.
@@ -27,9 +27,9 @@ On exit 0 the script prints one JSON object:
27
27
  | Field | Meaning |
28
28
  |---|---|
29
29
  | `source` | `probe` or `override` |
30
- | `reset_at` | When the 5-hour window resets (ISO-8601, local zone) |
31
- | `seconds_until_reset` | The wait the stage plan covers |
32
- | `stages_seconds` | The ScheduleWakeup stage durations, in firing order |
30
+ | `reset_at` | When the 5-hour window resets (ISO-8601, local zone). Null when the account has no 5-hour window |
31
+ | `seconds_until_reset` | The wait the stage plan covers (0 when `reset_at` is null) |
32
+ | `stages_seconds` | The ScheduleWakeup stage durations, in firing order (empty when `reset_at` is null) |
33
33
  | `session_utilization` | Percent of the 5-hour window spent (null on override) |
34
34
  | `weekly_utilization` | Percent of the weekly window spent (null on override) |
35
35
  | `weekly_resets_at` | When the weekly window resets (null on override) |
@@ -46,7 +46,7 @@ In short: the resolver picks a bearer token, probes the OAuth usage endpoint the
46
46
  - **Desktop host** (the `CLAUDE_CODE_ENTRYPOINT` variable is `claude-desktop`): the resolver does not read the CLI credential file, which belongs to a different authentication session than the one the desktop app counts usage against. It uses the session ingress token when one is set, and otherwise takes the manual-override path.
47
47
  - **Every other host**: the resolver reads the Claude Code CLI's stored OAuth access token first (honored only while unexpired), then the session ingress bearer token file named by `CLAUDE_SESSION_INGRESS_TOKEN_FILE` (cloud sessions) when the credential token is unavailable. The credential file lives under the directory `CLAUDE_CONFIG_DIR` names when that variable is set — a profile-isolated session's own account — else the home-directory default; the home file on a multi-profile machine can belong to a different account, whose meter is the wrong one to read.
48
48
 
49
- Fallbacks, in order: both token sources unavailable (expired/unreadable credential and no ingress file), a failed request, or a response with no readable session-window reset time all end in exit 2 — the manual-override ask above. The manual path works with no probe at all, so the skill functions even when both token sources are unavailable.
49
+ Fallbacks, in order: both token sources unavailable (expired/unreadable credential and no ingress file), a failed request, or a response with no readable window all end in exit 2 — the manual-override ask above. A reply with only a weekly window is not a failure: it exits 0 with a null `reset_at`. The manual path works with no probe at all, so the skill functions even when both token sources are unavailable.
50
50
 
51
51
  Why this probe and not the others:
52
52
 
@@ -59,6 +59,8 @@ Why this probe and not the others:
59
59
 
60
60
  When `weekly_near_cap` is true, WARN the user — report `weekly_utilization` and `weekly_resets_at` — and stop. No pause choreography runs around the weekly limit; waiting out a weekly window is its own later build.
61
61
 
62
+ A null `reset_at` with an empty `stages_seconds` says the account has no 5-hour window. Skip Step 2, since there is nothing to wait out, and still apply this guard to the weekly fields.
63
+
62
64
  ## Step 2 — the pause chain
63
65
 
64
66
  Before the first sleep:
@@ -64,6 +64,7 @@ from usage_pause_constants.resolve_usage_window_constants import (
64
64
  MINIMUM_STAGE_SECONDS,
65
65
  MINUTES_PER_HOUR,
66
66
  NOON_HOUR,
67
+ NO_FIVE_HOUR_WINDOW_LOG_MESSAGE,
67
68
  OAUTH_BETA_HEADER_NAME,
68
69
  OAUTH_BETA_HEADER_VALUE,
69
70
  OAUTH_USAGE_ENDPOINT_URL,
@@ -414,7 +415,7 @@ def extract_usage_windows(all_usage_buckets: dict[str, object]) -> UsageWindows:
414
415
 
415
416
  def build_pause_plan(
416
417
  source: str,
417
- reset_at: datetime,
418
+ reset_at: datetime | None,
418
419
  now: datetime,
419
420
  session_utilization: float | None,
420
421
  weekly_utilization: float | None,
@@ -422,9 +423,19 @@ def build_pause_plan(
422
423
  ) -> dict[str, object]:
423
424
  """Assemble the resolver's JSON-ready output for one resolved reset time.
424
425
 
426
+ ::
427
+
428
+ reset_at = <74 minutes out> -> seconds_until_reset 4440, three stages
429
+ reset_at = None -> seconds_until_reset 0, no stages
430
+
431
+ An account with no 5-hour window has nothing to wait out, so a None
432
+ reset time yields a null reset, a zero wait, and an empty stage plan
433
+ while the weekly meters and the near-cap flag still report.
434
+
425
435
  Args:
426
436
  source: Where the reset time came from, probe or override.
427
- reset_at: When the 5-hour window resets.
437
+ reset_at: When the 5-hour window resets, or None when the account
438
+ has no 5-hour window.
428
439
  now: The current local time the wait is measured from.
429
440
  session_utilization: Percent of the 5-hour window spent, when known.
430
441
  weekly_utilization: Percent of the weekly window spent, when known.
@@ -435,16 +446,21 @@ def build_pause_plan(
435
446
  stage plan, both utilization meters, the weekly reset time, and the
436
447
  weekly near-cap flag.
437
448
  """
438
- seconds_until_reset = max(int((reset_at - now).total_seconds()), 0)
449
+ seconds_until_reset = (
450
+ max(int((reset_at - now).total_seconds()), 0) if reset_at is not None else 0
451
+ )
452
+ stages_seconds = (
453
+ plan_wakeup_stages(seconds_until_reset) if reset_at is not None else []
454
+ )
439
455
  weekly_near_cap = (
440
456
  weekly_utilization is not None
441
457
  and weekly_utilization >= WEEKLY_UTILIZATION_WARN_THRESHOLD
442
458
  )
443
459
  return {
444
460
  RESULT_KEY_SOURCE: source,
445
- RESULT_KEY_RESET_AT: reset_at.isoformat(),
461
+ RESULT_KEY_RESET_AT: reset_at.isoformat() if reset_at is not None else None,
446
462
  RESULT_KEY_SECONDS_UNTIL_RESET: seconds_until_reset,
447
- RESULT_KEY_STAGES_SECONDS: plan_wakeup_stages(seconds_until_reset),
463
+ RESULT_KEY_STAGES_SECONDS: stages_seconds,
448
464
  RESULT_KEY_SESSION_UTILIZATION: session_utilization,
449
465
  RESULT_KEY_WEEKLY_UTILIZATION: weekly_utilization,
450
466
  RESULT_KEY_WEEKLY_RESETS_AT: weekly_resets_at.isoformat()
@@ -585,6 +601,18 @@ def main() -> int:
585
601
  )
586
602
  )
587
603
  return EXIT_CODE_RESOLVED
604
+ return _resolve_from_probe(arguments, now)
605
+
606
+
607
+ def _has_no_resolvable_window(windows: UsageWindows) -> bool:
608
+ has_session_meter = windows.session_utilization is not None
609
+ has_weekly_window = (
610
+ windows.weekly_utilization is not None or windows.weekly_resets_at is not None
611
+ )
612
+ return has_session_meter or not has_weekly_window
613
+
614
+
615
+ def _resolve_from_probe(arguments: argparse.Namespace, now: datetime) -> int:
588
616
  credentials_path = (
589
617
  Path(arguments.credentials_path)
590
618
  if arguments.credentials_path
@@ -605,7 +633,9 @@ def main() -> int:
605
633
  return _emit_error(f"usage probe failed: {probe_error}")
606
634
  windows = extract_usage_windows(usage_payload)
607
635
  if windows.session_resets_at is None:
608
- return _emit_error("usage response carried no five_hour reset time")
636
+ if _has_no_resolvable_window(windows):
637
+ return _emit_error("usage response carried no five_hour reset time")
638
+ logger.info(NO_FIVE_HOUR_WINDOW_LOG_MESSAGE)
609
639
  print(
610
640
  json.dumps(
611
641
  build_pause_plan(
@@ -487,6 +487,109 @@ class TestBuildPausePlan:
487
487
  assert resolved_payload["reset_at"] == reset_at.isoformat()
488
488
 
489
489
 
490
+ class TestBuildPausePlanWithoutSessionWindow:
491
+ def should_plan_no_wait_and_keep_weekly_meters(self) -> None:
492
+ resolver = load_resolver_module()
493
+ now = local_now()
494
+ weekly_resets_at = now + timedelta(days=3)
495
+ resolved_payload = resolver.build_pause_plan(
496
+ "probe", None, now, None, 92.0, weekly_resets_at
497
+ )
498
+ assert resolved_payload["reset_at"] is None
499
+ assert resolved_payload["seconds_until_reset"] == 0
500
+ assert resolved_payload["stages_seconds"] == []
501
+ assert resolved_payload["weekly_near_cap"] is True
502
+ assert resolved_payload["weekly_resets_at"] == weekly_resets_at.isoformat()
503
+
504
+
505
+ class TestWeeklyOnlyUsageReply:
506
+ @pytest.fixture
507
+ def run_probe_with_reply(
508
+ self, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
509
+ ):
510
+ def run(usage_reply: dict[str, object]) -> tuple[int, dict[str, object]]:
511
+ resolver = load_resolver_module()
512
+ monkeypatch.setattr(sys, "argv", ["resolve_usage_window.py"])
513
+ monkeypatch.setattr(
514
+ resolver, "resolve_access_token", lambda credentials_path, now: "stub"
515
+ )
516
+ monkeypatch.setattr(
517
+ resolver, "_fetch_usage_payload", lambda access_token: usage_reply
518
+ )
519
+ exit_code = resolver.main()
520
+ return exit_code, json.loads(capsys.readouterr().out)
521
+
522
+ return run
523
+
524
+ def should_resolve_with_no_wait_when_five_hour_is_null(
525
+ self, run_probe_with_reply
526
+ ) -> None:
527
+ exit_code, resolved_payload = run_probe_with_reply(
528
+ {
529
+ "five_hour": None,
530
+ "seven_day": {
531
+ "utilization": 63,
532
+ "resets_at": "2026-07-12T00:00:00+00:00",
533
+ },
534
+ }
535
+ )
536
+ assert exit_code == 0
537
+ assert resolved_payload["source"] == "probe"
538
+ assert resolved_payload["reset_at"] is None
539
+ assert resolved_payload["seconds_until_reset"] == 0
540
+ assert resolved_payload["stages_seconds"] == []
541
+ assert resolved_payload["session_utilization"] is None
542
+ assert resolved_payload["weekly_utilization"] == 63.0
543
+ assert resolved_payload["weekly_near_cap"] is False
544
+
545
+ def should_flag_weekly_near_cap_when_five_hour_is_null(
546
+ self, run_probe_with_reply
547
+ ) -> None:
548
+ exit_code, resolved_payload = run_probe_with_reply(
549
+ {
550
+ "five_hour": None,
551
+ "seven_day": {
552
+ "utilization": 95,
553
+ "resets_at": "2026-07-12T00:00:00+00:00",
554
+ },
555
+ }
556
+ )
557
+ assert exit_code == 0
558
+ assert resolved_payload["weekly_near_cap"] is True
559
+ assert resolved_payload["weekly_resets_at"] is not None
560
+
561
+ def should_resolve_when_five_hour_key_is_absent(self, run_probe_with_reply) -> None:
562
+ exit_code, resolved_payload = run_probe_with_reply(
563
+ {"seven_day": {"utilization": 20, "resets_at": "2026-07-12T00:00:00+00:00"}}
564
+ )
565
+ assert exit_code == 0
566
+ assert resolved_payload["stages_seconds"] == []
567
+
568
+ def should_still_exit_two_when_no_window_is_readable(
569
+ self, run_probe_with_reply
570
+ ) -> None:
571
+ exit_code, resolved_payload = run_probe_with_reply(
572
+ {"five_hour": None, "seven_day": None}
573
+ )
574
+ assert exit_code == 2
575
+ assert "error" in resolved_payload
576
+
577
+ def should_still_exit_two_when_five_hour_has_utilization_but_no_reset(
578
+ self, run_probe_with_reply
579
+ ) -> None:
580
+ exit_code, resolved_payload = run_probe_with_reply(
581
+ {
582
+ "five_hour": {"utilization": 30},
583
+ "seven_day": {
584
+ "utilization": 20,
585
+ "resets_at": "2026-07-12T00:00:00+00:00",
586
+ },
587
+ }
588
+ )
589
+ assert exit_code == 2
590
+ assert "error" in resolved_payload
591
+
592
+
490
593
  class TestCommandLine:
491
594
  def run_resolver(
492
595
  self,
@@ -70,3 +70,6 @@ EXIT_CODE_RESOLVED = 0
70
70
  EXIT_CODE_PROBE_UNAVAILABLE = 2
71
71
 
72
72
  LOGGING_FORMAT = "%(levelname)s %(name)s: %(message)s"
73
+ NO_FIVE_HOUR_WINDOW_LOG_MESSAGE = (
74
+ "usage response has no five_hour window; nothing to wait out, reporting the weekly window only"
75
+ )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-dev-env",
3
- "version": "8.114.6",
3
+ "version": "8.114.7",
4
4
  "description": "Claude Code development standards — rules, hooks, agents, commands, and skills",
5
5
  "type": "module",
6
6
  "bin": {