claude-dev-env 8.114.6 → 8.114.8

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
+ )
@@ -1,6 +1,9 @@
1
1
  from datetime import timedelta
2
2
 
3
- from hooks_constants.usage_pace_constants import ALL_RATE_WINDOW_LENGTHS
3
+ from hooks_constants.usage_pace_constants import (
4
+ ALL_OPTIONAL_WINDOW_NAMES,
5
+ ALL_RATE_WINDOW_LENGTHS,
6
+ )
4
7
 
5
8
 
6
9
  def test_usage_pace_windows_have_expected_lengths() -> None:
@@ -8,3 +11,7 @@ def test_usage_pace_windows_have_expected_lengths() -> None:
8
11
  "five_hour": timedelta(hours=5),
9
12
  "seven_day": timedelta(days=7),
10
13
  }
14
+
15
+
16
+ def test_usage_pace_treats_only_the_five_hour_window_as_optional() -> None:
17
+ assert ALL_OPTIONAL_WINDOW_NAMES == {"five_hour"}
@@ -30,6 +30,7 @@ ALL_RATE_WINDOW_LENGTHS = (
30
30
  ("five_hour", timedelta(hours=5)),
31
31
  ("seven_day", timedelta(days=7)),
32
32
  )
33
+ ALL_OPTIONAL_WINDOW_NAMES = frozenset({"five_hour"})
33
34
  PERCENT_SCALE = 100.0
34
35
  PERCENT_DECIMAL_PLACES = 1
35
36
  MINIMUM_ELAPSED_PERCENT_FOR_PACE = 10.0
@@ -105,7 +105,9 @@ def test_should_report_under_pace_when_every_window_trails() -> None:
105
105
  @pytest.mark.parametrize(
106
106
  "broken_payload",
107
107
  [
108
- {"seven_day": {"utilization": 20.0, "resets_at": WEEKLY_RESET}},
108
+ {"five_hour": {"utilization": 1.0, "resets_at": FIVE_HOUR_RESET}},
109
+ {"five_hour": None, "seven_day": None},
110
+ {},
109
111
  {
110
112
  "five_hour": {"utilization": None, "resets_at": FIVE_HOUR_RESET},
111
113
  "seven_day": {"utilization": 1.0, "resets_at": WEEKLY_RESET},
@@ -123,6 +125,42 @@ def test_should_treat_a_missing_or_unreadable_window_as_unreadable(
123
125
  measure_account_pace(broken_payload, NOW)
124
126
 
125
127
 
128
+ @pytest.mark.parametrize(
129
+ "weekly_only_payload",
130
+ [
131
+ {"five_hour": None, "seven_day": {"utilization": 93.0, "resets_at": WEEKLY_RESET}},
132
+ {"seven_day": {"utilization": 93.0, "resets_at": WEEKLY_RESET}},
133
+ ],
134
+ )
135
+ def test_should_measure_only_the_weekly_window_when_the_account_has_no_five_hour_window(
136
+ weekly_only_payload: dict[str, object],
137
+ ) -> None:
138
+ all_window_paces = measure_account_pace(weekly_only_payload, NOW)
139
+ assert [each.name for each in all_window_paces] == ["seven_day"]
140
+ verdict = build_verdict(all_window_paces, NOW)
141
+ assert verdict["over_pace"] is True
142
+ assert [each["window"] for each in verdict["windows"]] == ["seven_day"]
143
+
144
+
145
+ def test_should_report_under_pace_when_a_weekly_only_account_trails_the_clock() -> None:
146
+ weekly_only_payload = {
147
+ "five_hour": None,
148
+ "seven_day": {"utilization": 20.0, "resets_at": WEEKLY_RESET},
149
+ }
150
+ verdict = build_verdict(measure_account_pace(weekly_only_payload, NOW), NOW)
151
+ assert verdict["over_pace"] is False
152
+ assert [each["window"] for each in verdict["windows"]] == ["seven_day"]
153
+
154
+
155
+ def test_should_still_reject_a_five_hour_window_that_is_present_but_unreadable() -> None:
156
+ broken_five_hour_payload = {
157
+ "five_hour": {"utilization": 1.0},
158
+ "seven_day": {"utilization": 1.0, "resets_at": WEEKLY_RESET},
159
+ }
160
+ with pytest.raises(UsageUnreadable):
161
+ measure_account_pace(broken_five_hour_payload, NOW)
162
+
163
+
126
164
  def test_should_exit_zero_with_the_verdict_when_over_pace(tmp_path: Path) -> None:
127
165
  exit_code, verdict = _run_script(tmp_path, _payload(3.0, 93.0))
128
166
  assert exit_code == 0
@@ -135,8 +173,28 @@ def test_should_exit_one_when_under_pace(tmp_path: Path) -> None:
135
173
  assert verdict["over_pace"] is False
136
174
 
137
175
 
176
+ def test_should_exit_zero_for_a_weekly_only_account_running_ahead(tmp_path: Path) -> None:
177
+ exit_code, verdict = _run_script(
178
+ tmp_path,
179
+ {"five_hour": None, "seven_day": {"utilization": 93.0, "resets_at": WEEKLY_RESET}},
180
+ )
181
+ assert exit_code == 0
182
+ assert verdict["over_pace"] is True
183
+ assert [each["window"] for each in verdict["windows"]] == ["seven_day"]
184
+
185
+
186
+ def test_should_exit_one_for_a_weekly_only_account_under_pace(tmp_path: Path) -> None:
187
+ exit_code, verdict = _run_script(
188
+ tmp_path,
189
+ {"five_hour": None, "seven_day": {"utilization": 20.0, "resets_at": WEEKLY_RESET}},
190
+ )
191
+ assert exit_code == 1
192
+ assert verdict["over_pace"] is False
193
+ assert [each["window"] for each in verdict["windows"]] == ["seven_day"]
194
+
195
+
138
196
  def test_should_exit_two_with_a_null_verdict_when_unreadable(tmp_path: Path) -> None:
139
197
  exit_code, verdict = _run_script(tmp_path, {"five_hour": None})
140
198
  assert exit_code == 2
141
199
  assert verdict["over_pace"] is None
142
- assert verdict["error"] == "usage response has no five_hour window"
200
+ assert verdict["error"] == "usage response has no seven_day window"
@@ -12,10 +12,12 @@
12
12
 
13
13
  A window is over pace when at least 10% of it has elapsed and its used percent
14
14
  exceeds the percent already elapsed. The floor keeps a window's first minutes,
15
- where any spend outruns the clock, from reading as over pace. The account is over pace when any window is. The script reads
16
- the OAuth usage endpoint with the session ingress bearer token, the same probe
17
- the usage-pause skill's ``resolve_usage_window.py`` uses. It never prints or
18
- stores the token.
15
+ where any spend outruns the clock, from reading as over pace. The account is
16
+ over pace when any window is. An account with only a weekly window reports
17
+ ``five_hour`` as null or leaves it out, and the verdict then covers the weekly
18
+ window alone. The script reads the OAuth usage endpoint with the session
19
+ ingress bearer token, the same probe the usage-pause skill's
20
+ ``resolve_usage_window.py`` uses. It never prints or stores the token.
19
21
 
20
22
  Exit codes: 0 over pace, 1 under pace, 2 unreadable. ``--payload-file`` and
21
23
  ``--now`` replace the live probe and the clock for a deterministic run.
@@ -39,6 +41,7 @@ if hooks_root_directory not in sys.path:
39
41
  sys.path.insert(0, hooks_root_directory)
40
42
 
41
43
  from hooks_constants.usage_pace_constants import (
44
+ ALL_OPTIONAL_WINDOW_NAMES,
42
45
  ALL_RATE_WINDOW_LENGTHS,
43
46
  ANTHROPIC_BETA_HEADER,
44
47
  AUTHORIZATION_HEADER,
@@ -169,22 +172,34 @@ def measure_window_pace(
169
172
  def measure_account_pace(
170
173
  all_usage_buckets: dict[str, object], now: datetime
171
174
  ) -> list[WindowPace]:
172
- """Measure every rate window the verdict covers.
175
+ """Measure every rate window the account has.
176
+
177
+ ::
178
+
179
+ {"five_hour": None, "seven_day": {...}} -> [seven_day]
180
+ {"five_hour": {...}, "seven_day": {...}} -> [five_hour, seven_day]
181
+
182
+ The five-hour window is optional because accounts with only a weekly
183
+ window report it as null or leave it out. The weekly window is required.
173
184
 
174
185
  Args:
175
186
  all_usage_buckets: The decoded usage response body.
176
187
  now: The time the pace is measured at.
177
188
 
178
189
  Returns:
179
- One WindowPace per rate window, five-hour first.
190
+ One WindowPace per rate window the account has, five-hour first.
180
191
 
181
192
  Raises:
182
- UsageUnreadable: Any covered window is missing or unreadable.
193
+ UsageUnreadable: A required window is missing, or a window that is
194
+ present is unreadable.
183
195
  """
184
- return [
185
- measure_window_pace(each_name, each_length, all_usage_buckets.get(each_name), now)
186
- for each_name, each_length in ALL_RATE_WINDOW_LENGTHS
187
- ]
196
+ all_window_paces: list[WindowPace] = []
197
+ for each_name, each_length in ALL_RATE_WINDOW_LENGTHS:
198
+ each_bucket = all_usage_buckets.get(each_name)
199
+ if each_bucket is None and each_name in ALL_OPTIONAL_WINDOW_NAMES:
200
+ continue
201
+ all_window_paces.append(measure_window_pace(each_name, each_length, each_bucket, now))
202
+ return all_window_paces
188
203
 
189
204
 
190
205
  def build_verdict(
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.8",
4
4
  "description": "Claude Code development standards — rules, hooks, agents, commands, and skills",
5
5
  "type": "module",
6
6
  "bin": {