claude-dev-env 8.117.0 → 8.117.1

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.
@@ -2,17 +2,22 @@
2
2
 
3
3
  The prompt hooks use this module to learn two facts about a session::
4
4
 
5
- attachment.tools[].name / attachment.entries[].name (tool listing)
6
- attachment.addedNames / attachment.readdedNames (deferred tools)
5
+ attachment.tools[].name (full inline listing)
7
6
  assistant tool_use name (an earlier call)
7
+ attachment.addedNames / attachment.readdedNames /
8
+ attachment.entries[].name (deferred tools)
8
9
  -> the session has a ``mcp__*__set_session_title`` tool
9
10
 
10
11
  main-chain title call whose result came back without an error
11
12
  -> the title the session shows
12
13
 
13
- A later ``removedNames`` entry takes a title tool away again. A title call on a
14
- sidechain entry belongs to a subagent and does not count, and neither does a
15
- title the format gate denied.
14
+ A ``tools`` listing is the whole inline tool set, so the inline title names
15
+ come from the latest listing and the title calls after it. A session whose
16
+ tool set changes mid-run, such as one that leaves a remote connection, holds
17
+ no title tool its latest listing leaves out. A ``removedNames`` entry takes a
18
+ title tool away. Only main-chain entries count: a sidechain entry
19
+ records a subagent's tools and title calls, and a title the format gate denied
20
+ does not count either.
16
21
  """
17
22
 
18
23
  from __future__ import annotations
@@ -21,8 +26,7 @@ import json
21
26
  from pathlib import Path
22
27
 
23
28
  from hooks_constants.session_title_constants import (
24
- ALL_TOOL_LISTING_NAME_KEYS,
25
- ALL_TOOL_LISTING_RECORD_KEYS,
29
+ ALL_DEFERRED_TOOL_KEYS,
26
30
  ASSISTANT_ENTRY_TYPE,
27
31
  ATTACHMENT_KEY,
28
32
  BLOCK_ID_KEY,
@@ -31,6 +35,7 @@ from hooks_constants.session_title_constants import (
31
35
  CONTENT_KEY,
32
36
  DECODE_ERRORS_POLICY,
33
37
  ENTRY_TYPE_KEY,
38
+ FULL_TOOL_LISTING_KEY,
34
39
  IS_ERROR_KEY,
35
40
  MESSAGE_KEY,
36
41
  REMOVED_NAMES_KEY,
@@ -79,12 +84,19 @@ def _title_names(all_values: object) -> list[str]:
79
84
 
80
85
 
81
86
  def _apply_tool_listing(
82
- all_available_names: dict[str, None], all_attachment_fields: dict[str, object]
87
+ all_inline_names: dict[str, None],
88
+ all_deferred_names: dict[str, None],
89
+ all_attachment_fields: dict[str, object],
83
90
  ) -> None:
84
- for each_key in (*ALL_TOOL_LISTING_NAME_KEYS, *ALL_TOOL_LISTING_RECORD_KEYS):
85
- all_available_names.update(dict.fromkeys(_title_names(all_attachment_fields.get(each_key))))
91
+ full_tool_listing = all_attachment_fields.get(FULL_TOOL_LISTING_KEY)
92
+ if isinstance(full_tool_listing, list):
93
+ all_inline_names.clear()
94
+ all_inline_names.update(dict.fromkeys(_title_names(full_tool_listing)))
95
+ for each_key in ALL_DEFERRED_TOOL_KEYS:
96
+ all_deferred_names.update(dict.fromkeys(_title_names(all_attachment_fields.get(each_key))))
86
97
  for each_removed_name in _title_names(all_attachment_fields.get(REMOVED_NAMES_KEY)):
87
- all_available_names.pop(each_removed_name, None)
98
+ all_inline_names.pop(each_removed_name, None)
99
+ all_deferred_names.pop(each_removed_name, None)
88
100
 
89
101
 
90
102
  def available_title_tools(all_entries: list[dict[str, object]]) -> list[str]:
@@ -93,22 +105,31 @@ def available_title_tools(all_entries: list[dict[str, object]]) -> list[str]:
93
105
  ::
94
106
 
95
107
  attachment {"tools": [{"name": "mcp__x__set_session_title"}]} -> ["mcp__x__set_session_title"]
108
+ then attachment {"tools": [{"name": "Bash"}]} -> []
96
109
  then attachment {"removedNames": ["mcp__x__set_session_title"]} -> []
110
+ attachment {"addedNames": [...]}, then {"tools": [Bash]} -> the deferred name
97
111
  no listing and no call -> []
98
112
 
113
+ A ``tools`` listing is the full inline tool set, so the inline names come
114
+ from the latest listing and the title calls after it. Deferred names change only through
115
+ ``addedNames``, ``readdedNames``, ``entries`` and ``removedNames``. Only
116
+ main-chain entries count, because a sidechain entry records a subagent's
117
+ tools.
118
+
99
119
  Args:
100
120
  all_entries: The transcript entries, oldest first.
101
121
 
102
122
  Returns:
103
- The title tool names, in the order the transcript first named them.
123
+ The title tool names, inline names first.
104
124
  """
105
- available_names: dict[str, None] = {}
106
- for each_entry in all_entries:
125
+ inline_names: dict[str, None] = {}
126
+ deferred_names: dict[str, None] = {}
127
+ for each_entry in _main_chain(all_entries):
107
128
  attachment = each_entry.get(ATTACHMENT_KEY)
108
129
  if isinstance(attachment, dict):
109
- _apply_tool_listing(available_names, attachment)
110
- available_names.update(dict.fromkeys(_title_names(_tool_use_blocks(each_entry))))
111
- return list(available_names)
130
+ _apply_tool_listing(inline_names, deferred_names, attachment)
131
+ inline_names.update(dict.fromkeys(_title_names(_tool_use_blocks(each_entry))))
132
+ return list(dict.fromkeys([*inline_names, *deferred_names]))
112
133
 
113
134
 
114
135
  def _main_chain(all_entries: list[dict[str, object]]) -> list[dict[str, object]]:
@@ -23,6 +23,13 @@ DEFERRED_LISTING = {
23
23
  "type": "attachment",
24
24
  "attachment": {"type": "deferred_tools_delta", "addedNames": [DESKTOP_TITLE_TOOL]},
25
25
  }
26
+ LATER_LISTING_WITHOUT_TITLE_TOOL = {
27
+ "type": "attachment",
28
+ "attachment": {
29
+ "type": "prompt_snapshot",
30
+ "tools": [{"name": "Bash"}, {"name": "ToolSearch"}],
31
+ },
32
+ }
26
33
  REMOVAL_LISTING = {
27
34
  "type": "attachment",
28
35
  "attachment": {"type": "deferred_tools_delta", "removedNames": [DESKTOP_TITLE_TOOL]},
@@ -78,6 +85,30 @@ def test_should_drop_a_title_tool_a_later_delta_removes() -> None:
78
85
  assert available_title_tools([DEFERRED_LISTING, REMOVAL_LISTING]) == []
79
86
 
80
87
 
88
+ @pytest.mark.parametrize(
89
+ "all_earlier_entries",
90
+ [
91
+ [SNAPSHOT_LISTING],
92
+ [SNAPSHOT_LISTING, title_call("t1", HOURGLASS_TITLE), title_result("t1")],
93
+ ],
94
+ )
95
+ def test_should_drop_an_inline_title_tool_a_later_full_listing_leaves_out(
96
+ all_earlier_entries: list[dict[str, object]],
97
+ ) -> None:
98
+ all_entries = [*all_earlier_entries, LATER_LISTING_WITHOUT_TITLE_TOOL]
99
+ assert available_title_tools(all_entries) == []
100
+
101
+
102
+ def test_should_keep_a_deferred_title_tool_across_a_later_full_listing() -> None:
103
+ all_entries = [DEFERRED_LISTING, LATER_LISTING_WITHOUT_TITLE_TOOL]
104
+ assert available_title_tools(all_entries) == [DESKTOP_TITLE_TOOL]
105
+
106
+
107
+ def test_should_ignore_a_tool_listing_on_a_sidechain() -> None:
108
+ sidechain_listing = {**LATER_LISTING_WITHOUT_TITLE_TOOL, "isSidechain": True}
109
+ assert available_title_tools([SNAPSHOT_LISTING, sidechain_listing]) == [REMOTE_TITLE_TOOL]
110
+
111
+
81
112
  def test_should_return_the_last_main_chain_title_that_came_back_without_an_error() -> None:
82
113
  all_entries = [
83
114
  title_call("t1", HOURGLASS_TITLE),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-dev-env",
3
- "version": "8.117.0",
3
+ "version": "8.117.1",
4
4
  "description": "Claude Code development standards — rules, hooks, agents, commands, and skills",
5
5
  "type": "module",
6
6
  "bin": {
@@ -293,7 +293,8 @@ def read_published_meters(account: Account) -> Meters | None:
293
293
  CLAUDE_USAGE_READINGS_DIR=/readings, account home .../alpha
294
294
  /readings/meters-ALPHA.json {"read_at": "<5 minutes ago>", "accounts": [{"name": "alpha",
295
295
  "meters": {"weekly_percent_left": 45.0, ...}}]}
296
- -> Meters(weekly_percent_left=45.0, ...), and the usage endpoint is not called
296
+ -> Meters(weekly_percent_left=45.0, ..., measured_at=<5 minutes ago>),
297
+ and the usage endpoint is not called
297
298
 
298
299
  A reading matches an account when its ``name`` equals the account home's folder name.
299
300
  A reading older than ``PUBLISHED_USAGE_MAX_AGE_SECONDS``, or dated more than
@@ -303,7 +304,8 @@ def read_published_meters(account: Account) -> Meters | None:
303
304
  account: Account whose meter is read.
304
305
 
305
306
  Returns:
306
- The published meters, or None when the folder is unset or holds no fresh reading for the account.
307
+ The published meters with the reading's ``read_at`` as their ``measured_at``, or None
308
+ when the folder is unset or holds no fresh reading for the account.
307
309
  """
308
310
  folder_text = os.environ.get(PUBLISHED_USAGE_DIRECTORY_ENV_VAR)
309
311
  if not folder_text:
@@ -316,8 +318,11 @@ def read_published_meters(account: Account) -> Meters | None:
316
318
  ]
317
319
  if not all_matches:
318
320
  return None
319
- newest_row = max(all_matches, key=lambda each_match: each_match[0])[1]
320
- return _meters_from_payload(newest_row.get("meters"))
321
+ newest_read_at, newest_row = max(all_matches, key=lambda each_match: each_match[0])
322
+ meters = _meters_from_payload(newest_row.get("meters"))
323
+ if meters is None:
324
+ return None
325
+ return dataclasses.replace(meters, measured_at=newest_read_at)
321
326
 
322
327
 
323
328
  def _fresh_published_rows(folder: Path, now: datetime) -> Iterator[tuple[datetime, dict[str, object]]]:
@@ -622,7 +627,7 @@ def _read_one_account(account: Account, adapter: ProductAdapter, all_cache: dict
622
627
  next_probe = datetime.fromtimestamp(retry_at, timezone.utc) if is_held else None
623
628
  return Reading(account, cached_meters, cached_reason if isinstance(cached_reason, str) else None, measured, next_probe), False
624
629
  meters, unread_reason, is_rate_limited = read_meters_with_backoff(adapter.read_meters, account)
625
- measured_at = now.timestamp()
630
+ measured_at = _measured_timestamp(meters, now)
626
631
  is_rate_limited = account.product is Product.CLAUDE and is_rate_limited
627
632
  last_good = _last_good_meters(cached, now) if is_rate_limited else None
628
633
  if last_good is not None:
@@ -634,6 +639,20 @@ def _read_one_account(account: Account, adapter: ProductAdapter, all_cache: dict
634
639
  return Reading(account, meters, unread_reason, datetime.fromtimestamp(measured_at, timezone.utc), next_probe), True
635
640
 
636
641
 
642
+ def _measured_timestamp(meters: Meters | None, now: datetime) -> float:
643
+ """Return when *meters* were measured, never later than *now*.
644
+
645
+ ::
646
+
647
+ probe read at 12:00 -> 12:00 (now)
648
+ published reading read at 11:31 -> 11:31
649
+ published reading dated 12:02 (skewed) -> 12:00 (now)
650
+ """
651
+ if meters is None or meters.measured_at is None:
652
+ return now.timestamp()
653
+ return min(meters.measured_at, now).timestamp()
654
+
655
+
637
656
  def _last_good_meters(all_cached_fields: dict[str, object], now: datetime) -> tuple[Meters, float] | None:
638
657
  unread_reason = all_cached_fields.get("unread_reason")
639
658
  if unread_reason is not None and not (isinstance(unread_reason, str) and "HTTP Error 429" in unread_reason):
@@ -228,6 +228,7 @@ class Meters:
228
228
  has_credits: bool = False
229
229
  is_credits_unlimited: bool = False
230
230
  credit_balance: float | None = None
231
+ measured_at: datetime | None = field(default=None, compare=False)
231
232
 
232
233
  @property
233
234
  def tightest_percent_left(self) -> float | None:
@@ -14,6 +14,15 @@ APPROVED_TEST_PATHS_BY_PRODUCTION_PATH: dict[
14
14
  ),
15
15
  }
16
16
  ),
17
+ PurePosixPath(
18
+ ".claude/hillclimb/subagent-effort-routing/routing_eval_support/config/constants.py"
19
+ ): frozenset(
20
+ {
21
+ PurePosixPath(
22
+ ".claude/hillclimb/subagent-effort-routing/test_grading.py"
23
+ ),
24
+ }
25
+ ),
17
26
  PurePosixPath("packages/claude-dev-env/bin/install-constants.mjs"): frozenset(
18
27
  {
19
28
  PurePosixPath("packages/claude-dev-env/bin/install.cursor-rules.test.mjs"),
@@ -71,6 +80,15 @@ APPROVED_TEST_PATHS_BY_PRODUCTION_PATH: dict[
71
80
  ),
72
81
  }
73
82
  ),
83
+ PurePosixPath(
84
+ "packages/claude-dev-env/hooks/hooks_constants/once_per_session_constants.py"
85
+ ): frozenset(
86
+ {
87
+ PurePosixPath(
88
+ "packages/claude-dev-env/hooks/test_once_per_session.py"
89
+ ),
90
+ }
91
+ ),
74
92
  PurePosixPath(
75
93
  "packages/claude-dev-env/hooks/hooks_constants/post_tool_use_dispatcher_constants.py"
76
94
  ): frozenset(
@@ -80,6 +98,15 @@ APPROVED_TEST_PATHS_BY_PRODUCTION_PATH: dict[
80
98
  ),
81
99
  }
82
100
  ),
101
+ PurePosixPath(
102
+ "packages/claude-dev-env/hooks/hooks_constants/subagent_effort_route_constants.py"
103
+ ): frozenset(
104
+ {
105
+ PurePosixPath(
106
+ "packages/claude-dev-env/hooks/routing/test_subagent_effort_route.py"
107
+ ),
108
+ }
109
+ ),
83
110
  PurePosixPath(
84
111
  "packages/claude-dev-env/scripts/automatic_advisory/checkout.py"
85
112
  ): frozenset(
@@ -285,13 +285,54 @@ def test_should_read_claude_meters_from_a_fresh_published_reading_without_a_prob
285
285
  assert meters.weekly_resets_at == datetime(2026, 10, 10, 6, tzinfo=timezone.utc)
286
286
 
287
287
 
288
+ def _read_published_account(
289
+ monkeypatch: pytest.MonkeyPatch, tmp_path: Path, published_at: datetime, now: datetime
290
+ ) -> tuple[object, dict[str, object]]:
291
+ readings_folder = tmp_path / "readings"
292
+ _write_published_reading(readings_folder, "alpha", published_at)
293
+ monkeypatch.setenv("CLAUDE_USAGE_READINGS_DIR", str(readings_folder))
294
+ monkeypatch.setattr(support, "probe_account_meters", lambda *_: pytest.fail("probe despite a fresh published reading"))
295
+ account = Account(Product.CLAUDE, "one", tmp_path / "alpha")
296
+ adapter = ProductAdapter(lambda: (account,), support.read_claude_meters, "CLAUDE_CONFIG_DIR", ())
297
+ state = support._load_state(support.broker_state_path())
298
+ reading = support.read_accounts(Product.CLAUDE, adapter, all_state=state, now=now)[0]
299
+ return reading, state["meters"][support._state_key(account)]
300
+
301
+
302
+ def test_should_report_a_published_reading_with_its_own_read_time(
303
+ monkeypatch: pytest.MonkeyPatch, tmp_path: Path
304
+ ) -> None:
305
+ now = datetime.now(timezone.utc).replace(microsecond=0)
306
+ published_at = now - timedelta(minutes=29)
307
+
308
+ reading, saved_entry = _read_published_account(monkeypatch, tmp_path, published_at, now)
309
+
310
+ assert reading.meters.weekly_percent_left == 45.0
311
+ assert reading.measured_at == published_at
312
+ assert saved_entry["measured_at"] == published_at.timestamp()
313
+ assert saved_entry["read_at"] == now.timestamp()
314
+
315
+
316
+ def test_should_not_date_a_published_reading_after_the_read(
317
+ monkeypatch: pytest.MonkeyPatch, tmp_path: Path
318
+ ) -> None:
319
+ now = datetime.now(timezone.utc).replace(microsecond=0)
320
+
321
+ reading, saved_entry = _read_published_account(monkeypatch, tmp_path, now + timedelta(minutes=2), now)
322
+
323
+ assert reading.meters.weekly_percent_left == 45.0
324
+ assert reading.measured_at == now
325
+ assert saved_entry["measured_at"] == now.timestamp()
326
+
327
+
288
328
  def test_should_use_the_newest_of_two_published_readings_for_one_account(
289
329
  monkeypatch: pytest.MonkeyPatch, tmp_path: Path
290
330
  ) -> None:
291
331
  readings_folder = tmp_path / "readings"
292
332
  _write_published_reading(readings_folder, "alpha", datetime.now(timezone.utc) - timedelta(minutes=20))
293
333
  newer = json.loads((readings_folder / "meters-ALPHA.json").read_text(encoding="utf-8"))
294
- newer["read_at"] = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
334
+ newer_read_at = datetime.now(timezone.utc).replace(microsecond=0)
335
+ newer["read_at"] = newer_read_at.strftime("%Y-%m-%dT%H:%M:%SZ")
295
336
  newer["accounts"][0]["meters"]["weekly_percent_left"] = 12.0
296
337
  (readings_folder / "meters-ZULU.json").write_text(json.dumps(newer), encoding="utf-8")
297
338
  monkeypatch.setenv("CLAUDE_USAGE_READINGS_DIR", str(readings_folder))
@@ -299,6 +340,7 @@ def test_should_use_the_newest_of_two_published_readings_for_one_account(
299
340
  meters = support.read_published_meters(Account(Product.CLAUDE, "one", tmp_path / "alpha"))
300
341
 
301
342
  assert meters.weekly_percent_left == 12.0
343
+ assert meters.measured_at == newer_read_at
302
344
 
303
345
 
304
346
  def test_should_find_no_published_meters_when_no_readings_folder_is_named(
@@ -248,6 +248,30 @@ def test_cursor_verifier_constants_require_the_changed_driver_suite(
248
248
  ) == ()
249
249
 
250
250
 
251
+ def test_constants_behind_a_differently_named_suite_require_that_changed_suite(
252
+ tmp_path: Path,
253
+ ) -> None:
254
+ all_suite_paths_by_constants_path = {
255
+ PurePosixPath(
256
+ ".claude/hillclimb/subagent-effort-routing/routing_eval_support/config/constants.py"
257
+ ): PurePosixPath(".claude/hillclimb/subagent-effort-routing/test_grading.py"),
258
+ PurePosixPath(
259
+ "packages/claude-dev-env/hooks/hooks_constants/once_per_session_constants.py"
260
+ ): PurePosixPath("packages/claude-dev-env/hooks/test_once_per_session.py"),
261
+ PurePosixPath(
262
+ "packages/claude-dev-env/hooks/hooks_constants/subagent_effort_route_constants.py"
263
+ ): PurePosixPath(
264
+ "packages/claude-dev-env/hooks/routing/test_subagent_effort_route.py"
265
+ ),
266
+ }
267
+ for each_constants_path, each_suite_path in all_suite_paths_by_constants_path.items():
268
+ constants_change = _body_change_at(each_constants_path)
269
+ assert _diagnostic_paths(tmp_path, constants_change) == (each_constants_path,)
270
+ assert _diagnostic_paths(
271
+ tmp_path, constants_change, _body_change_at(each_suite_path)
272
+ ) == ()
273
+
274
+
251
275
  def test_pairing_rejects_an_unrelated_module_beside_a_changed_approved_suite(
252
276
  tmp_path: Path,
253
277
  ) -> None: