claude-dev-env 8.24.0 → 8.25.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.
@@ -31,7 +31,7 @@ A keep marker is the one comment that may be added and kept: a comment that open
31
31
 
32
32
  The staged policy lint reports each of these through `code_rules_enforcer.py` and names the specific breach; exact patterns and exemption lists live in that module:
33
33
 
34
- no new comments · imports at top · logging format args (`log_*("...", arg)`) · no `%s`/`%d` printf tokens in a `str.format`-logger message (`log_*` imported from `automation_logging`; `str.format` drops the args — use `{}`) · no magic values in production bodies (0, 1, -1 exempt) · UPPER_SNAKE constants only in `config/` (exempt: `config/*`; `/migrations/`; Workflow registries: path contains any of these substrings — `/workflow/`, `_tab.py`, `/states.py`, or `/modules.py`, each matching independently as a substring, so `pkg/states.py` qualifies while a top-level `states.py` follows the standard `config/` rule; test files — path or filename matches `test_`, `_test.`, `.spec.`, `conftest`, or `/tests/`) · no hardcoded user home paths · guarded `sys.path.insert` · banned identifiers (`ctx`, `cfg`, `msg`, `btn`, `idx`, `cnt`, `tmp`, `elem`, `val`) · banned function prefixes (`handle_`, `process_`, `manage_`, `do_`) · no type escape hatches (`Any` import, `cast()`, inline `Any`, a parameter typed bare `object` whose body reads `param.attribute`) outside boundary files · no bare/broad `except` · no `Any` in signatures or class attributes · no stub bodies (`pass`/`...`/`raise NotImplementedError`) outside abstract/Protocol · TypedDict `_encode_*`/`_decode_*` companions in the same module · no test-mode branching in production (use dependency injection) · no thin wrapper modules · Google-style docstrings on public functions with `Args:` matching the signature · boolean names prefixed `is_`/`has_`/`should_`/`can_`/`was_`/`did_` (assignments AND bool-typed parameters) · must-check returns (`find_and_click`, `write_outcome`) assigned and checked · known pytest fixture parameters in test files annotated with their single documented type (`tmp_path: Path`, `monkeypatch: pytest.MonkeyPatch`, `capsys`, `caplog`, `request`, …) · known pytest fixture parameters a test function declares but never references (drop the unused parameter — pytest still pays its setup cost) · JavaScript/TypeScript boolean declarations (`const`/`let`/`var` bound to a boolean literal or negation) and `@param {boolean}` JSDoc names prefixed `is`/`has`/`should`/`can`/`was`/`did` (camelCase forms) · banned identifiers as `.mjs`/`.js` declaration names (`result`, `data`, `ctx`, `msg`, …), scoped to changed lines · in test files, banned identifiers fire on changed lines, and pytest-collectable `test_*` functions need a return annotation · unused module-level imports and unsorted import blocks are ruff's job (F401, isort I001), not this hook's · a `hooks/blocking/` command classifier anchors its multi-word command regex to the command start (`^`/`\A`) or tokenizes the first word (`shlex.split`), never matching a command as a bare substring
34
+ no new comments · imports at top · logging format args (`log_*("...", arg)`) · no magic values in production bodies (0, 1, -1 exempt) · UPPER_SNAKE constants only in `config/` (exempt: `config/*`; `/migrations/`; Workflow registries: path contains any of these substrings — `/workflow/`, `_tab.py`, `/states.py`, or `/modules.py`, each matching independently as a substring, so `pkg/states.py` qualifies while a top-level `states.py` follows the standard `config/` rule; test files — path or filename matches `test_`, `_test.`, `.spec.`, `conftest`, or `/tests/`) · no hardcoded user home paths · guarded `sys.path.insert` · banned identifiers (`ctx`, `cfg`, `msg`, `btn`, `idx`, `cnt`, `tmp`, `elem`, `val`) · banned function prefixes (`handle_`, `process_`, `manage_`, `do_`) · no type escape hatches (`Any` import, `cast()`, inline `Any`, a parameter typed bare `object` whose body reads `param.attribute`) outside boundary files · no bare/broad `except` · no `Any` in signatures or class attributes · no stub bodies (`pass`/`...`/`raise NotImplementedError`) outside abstract/Protocol · TypedDict `_encode_*`/`_decode_*` companions in the same module · no test-mode branching in production (use dependency injection) · no thin wrapper modules · Google-style docstrings on public functions with `Args:` matching the signature · boolean names prefixed `is_`/`has_`/`should_`/`can_`/`was_`/`did_` (assignments AND bool-typed parameters) · known pytest fixture parameters in test files annotated with their single documented type (`tmp_path: Path`, `monkeypatch: pytest.MonkeyPatch`, `capsys`, `caplog`, `request`, …) · known pytest fixture parameters a test function declares but never references (drop the unused parameter — pytest still pays its setup cost) · JavaScript/TypeScript boolean declarations (`const`/`let`/`var` bound to a boolean literal or negation) and `@param {boolean}` JSDoc names prefixed `is`/`has`/`should`/`can`/`was`/`did` (camelCase forms) · banned identifiers as `.mjs`/`.js` declaration names (`result`, `data`, `ctx`, `msg`, …), scoped to changed lines · in test files, banned identifiers fire on changed lines, and pytest-collectable `test_*` functions need a return annotation · unused module-level imports and unsorted import blocks belong to ruff (F401, isort I001) · a `hooks/blocking/` command classifier anchors its multi-word command regex to the command start (`^`/`\A`) or tokenizes the first word (`shlex.split`), never matching a command as a bare substring
35
35
 
36
36
  Test files follow the comment policy above; other test-specific exemptions are listed here. The one annotation the test-file exemption does NOT cover is a known pytest builtin fixture parameter: `tmp_path`, `monkeypatch`, `capsys`, `capfd`, `caplog`, `request`, and `tmp_path_factory` each have a single documented injected type, so the gate requires that annotation (`tmp_path: Path`) even inside a test file. The same set of fixtures is also subject to a use check: a pytest-collected test function that declares one of these parameters and never references it in its body fails the gate, because pytest materializes the fixture's setup (the temp directory, the monkeypatch context, the output capture) on every run whether or not the body reads the value — drop the unused parameter. A parameter counts as referenced when its name is read, augmented-assigned, or deleted anywhere in the body, including inside a nested function or comprehension. Only pytest-collectable functions are inspected — those at module top level or defined directly in a class body; a function nested inside another function's body is a local helper pytest never collects, so its fixture-named parameter is exempt. A `@pytest.fixture`-decorated function is exempt from the use check, since injecting one fixture into another purely to order its setup is intentional. Ordinary test parameters stay exempt from both checks.
37
37
 
@@ -1,4 +1,4 @@
1
- """Boolean naming-prefix and ignored must-check-return checks."""
1
+ """Boolean naming-prefix checks."""
2
2
 
3
3
  import ast
4
4
  import sys
@@ -21,12 +21,8 @@ from code_rules_shared import ( # noqa: E402
21
21
  is_workflow_registry_file,
22
22
  )
23
23
 
24
- from hooks_constants.blocking_check_limits import ( # noqa: E402
25
- MAX_IGNORED_MUST_CHECK_RETURN_ISSUES,
26
- )
27
24
  from hooks_constants.code_rules_enforcer_constants import ( # noqa: E402
28
25
  ALL_BOOLEAN_NAME_PREFIXES,
29
- ALL_MUST_CHECK_RETURN_FUNCTION_NAMES,
30
26
  ALL_SELF_AND_CLS_PARAMETER_NAMES,
31
27
  UPPER_SNAKE_CONSTANT_PATTERN,
32
28
  )
@@ -271,80 +267,3 @@ def _called_terminal_name(call_node: ast.Call) -> str | None:
271
267
  if isinstance(callee, ast.Attribute):
272
268
  return callee.attr
273
269
  return None
274
-
275
-
276
- def check_ignored_must_check_return(
277
- content: str,
278
- file_path: str,
279
- all_changed_lines: set[int] | None = None,
280
- defer_scope_to_caller: bool = False,
281
- ) -> list[str]:
282
- """Flag bare-expression calls whose discarded return is the only failure signal.
283
-
284
- Functions in ``ALL_MUST_CHECK_RETURN_FUNCTION_NAMES`` report success or failure
285
- solely through their return value. A bare-statement call discards that value,
286
- so the caller silently proceeds on failure. Bare ``ast.Expr`` calls are flagged,
287
- including a bare ``await``-wrapped call (``await find_and_click(...)`` as a
288
- statement); an assigned or branched-on call is exempt.
289
-
290
- The caller passes the reconstructed full file as *content* so ``ast.parse``
291
- sees a complete module rather than an Edit's ``new_string`` fragment, which is
292
- rarely valid standalone Python (a bare ``await find_and_click(...)`` line is a
293
- SyntaxError on its own). Findings are then scoped to *all_changed_lines* so an
294
- Edit blocks on the discarded return it just introduced while a pre-existing
295
- violation on an untouched line does not block the edit.
296
-
297
- Args:
298
- content: The source text to inspect — the reconstructed full file on an
299
- Edit so the parse succeeds.
300
- file_path: The path the source will be written to, used for exemptions.
301
- all_changed_lines: Post-edit line numbers the current edit touched, or
302
- None to treat the whole file as in scope. When provided, a violation
303
- blocks only when the bare call's line intersects the changed lines.
304
- defer_scope_to_caller: When True, return every violation so the
305
- commit/push gate's ``split_violations_by_scope`` can scope by added
306
- line.
307
-
308
- Returns:
309
- One issue per discarded must-check return, scoped to the changed lines
310
- unless *defer_scope_to_caller* is True or *all_changed_lines* is None. When
311
- *defer_scope_to_caller* is True every violation is returned uncapped so the
312
- gate can scope by added line and apply its own ceiling; otherwise the
313
- terminal result is capped at the module limit.
314
- """
315
- if is_test_file(file_path):
316
- return []
317
- try:
318
- tree = ast.parse(content)
319
- except SyntaxError:
320
- return []
321
- all_violations_in_walk_order: list[tuple[range, str]] = []
322
- for each_node in ast.walk(tree):
323
- if not isinstance(each_node, ast.Expr):
324
- continue
325
- expression_value = each_node.value
326
- call_node = (
327
- expression_value.value
328
- if isinstance(expression_value, ast.Await)
329
- else expression_value
330
- )
331
- if not isinstance(call_node, ast.Call):
332
- continue
333
- called_name = _called_terminal_name(call_node)
334
- if called_name is None or called_name not in ALL_MUST_CHECK_RETURN_FUNCTION_NAMES:
335
- continue
336
- end_line_number = each_node.end_lineno or each_node.lineno
337
- line_span = range(each_node.lineno, end_line_number + 1)
338
- message = (
339
- f"Line {each_node.lineno}: return value of {called_name}() is discarded - "
340
- "assign and check it (the boolean/outcome is the only failure signal)"
341
- )
342
- all_violations_in_walk_order.append((line_span, message))
343
- scoped_issues = _scope_violations_to_changed_lines(
344
- all_violations_in_walk_order,
345
- all_changed_lines,
346
- defer_scope_to_caller,
347
- )
348
- if defer_scope_to_caller:
349
- return scoped_issues
350
- return scoped_issues[:MAX_IGNORED_MUST_CHECK_RETURN_ISSUES]
@@ -46,7 +46,6 @@ from code_rules_blast_radius import ( # noqa: E402
46
46
  )
47
47
  from code_rules_boolean_mustcheck import ( # noqa: E402
48
48
  check_boolean_naming,
49
- check_ignored_must_check_return,
50
49
  )
51
50
  from code_rules_command_dispatch import ( # noqa: E402
52
51
  check_unanchored_command_dispatch,
@@ -86,7 +85,6 @@ from code_rules_imports_logging import ( # noqa: E402
86
85
  check_library_print,
87
86
  check_logging_adjacent_string_literals,
88
87
  check_logging_fstrings,
89
- check_logging_printf_tokens,
90
88
  check_naive_datetime_construction,
91
89
  check_windows_api_none,
92
90
  )
@@ -329,7 +327,6 @@ def _python_comment_and_logging_issues(context: _ValidationContext) -> list[str]
329
327
  all_issues.extend(check_comment_changes(old_content, content, file_path))
330
328
  all_issues.extend(check_imports_at_top(content))
331
329
  all_issues.extend(check_logging_fstrings(content))
332
- all_issues.extend(check_logging_printf_tokens(content, file_path))
333
330
  all_issues.extend(check_logging_adjacent_string_literals(content, file_path))
334
331
  all_issues.extend(check_windows_api_none(content))
335
332
  all_issues.extend(check_naive_datetime_construction(content, file_path))
@@ -450,9 +447,6 @@ def _python_boolean_and_test_assertion_issues(context: _ValidationContext) -> li
450
447
  )
451
448
  changed, defer = context.all_changed_lines, context.defer_scope_to_caller
452
449
  all_issues = check_boolean_naming(effective_content, file_path, changed, defer)
453
- all_issues.extend(
454
- check_ignored_must_check_return(effective_content, file_path, changed, defer)
455
- )
456
450
  all_issues.extend(check_skip_decorators_in_tests(content, file_path))
457
451
  all_issues.extend(
458
452
  check_tests_use_isolated_filesystem_paths(
@@ -1,4 +1,4 @@
1
- """Import and logging convention checks: check_imports_at_top, check_logging_fstrings, check_logging_printf_tokens, check_logging_adjacent_string_literals, check_windows_api_none, check_naive_datetime_construction, check_e2e_test_naming, check_js_resume_task_enumeration_coverage, check_js_returns_object_schemaless_branch, check_js_sibling_return_object_key_drift, check_js_bare_flag_return_directive, and check_library_print."""
1
+ """Import and logging convention checks: check_imports_at_top, check_logging_fstrings, check_logging_adjacent_string_literals, check_windows_api_none, check_naive_datetime_construction, check_e2e_test_naming, check_js_resume_task_enumeration_coverage, check_js_returns_object_schemaless_branch, check_js_sibling_return_object_key_drift, check_js_bare_flag_return_directive, and check_library_print."""
2
2
 
3
3
  import ast
4
4
  import re
@@ -25,7 +25,6 @@ from code_rules_shared import ( # noqa: E402
25
25
 
26
26
  from hooks_constants.blocking_check_limits import ( # noqa: E402
27
27
  ALL_ALWAYS_NAIVE_DATETIME_CONSTRUCTORS,
28
- ALL_FORMAT_LOGGER_FUNCTION_NAMES,
29
28
  DATETIME_CLASS_ATTRIBUTE_NAME,
30
29
  FROMTIMESTAMP_POSITIONAL_TIMEZONE_ARGUMENT_COUNT,
31
30
  MAX_E2E_TEST_NAMING_ISSUES,
@@ -35,7 +34,6 @@ from hooks_constants.blocking_check_limits import ( # noqa: E402
35
34
  MAX_JS_SIBLING_RETURN_OBJECT_KEY_DRIFT_ISSUES,
36
35
  MAX_LOGGING_ADJACENT_LITERAL_ISSUES,
37
36
  MAX_LOGGING_FSTRING_ISSUES,
38
- MAX_LOGGING_PRINTF_TOKEN_ISSUES,
39
37
  MAX_NAIVE_DATETIME_ISSUES,
40
38
  MAX_WINDOWS_API_NONE_ISSUES,
41
39
  MINIMUM_RESUME_TASK_ENUMERATION_ITEMS,
@@ -87,9 +85,7 @@ from hooks_constants.code_rules_enforcer_constants import ( # noqa: E402
87
85
  JSDOC_RETURNS_STRUCTURED_OBJECT_PROMISE_PATTERN,
88
86
  LOGGING_FSTRING_PATTERN,
89
87
  LOGGING_HELPER_FUNCTION_NAME_PATTERN,
90
- LOGGING_PRINTF_TOKEN_PATTERN,
91
88
  LOGGING_RECEIVER_NAME_PATTERN,
92
- MINIMUM_FORMAT_LOGGER_ARGUMENT_COUNT,
93
89
  NOT_INSIDE_TYPE_CHECKING_BLOCK,
94
90
  RESUME_TASK_ENUMERATION_PATTERN,
95
91
  RETURN_CALL_OPENING_PARENTHESIS_PATTERN,
@@ -280,121 +276,6 @@ def check_logging_fstrings(content: str) -> list[str]:
280
276
  return issues
281
277
 
282
278
 
283
- def _format_logger_names_imported(tree: ast.Module) -> set[str]:
284
- """Return the local names bound to automation_logging log helpers.
285
-
286
- Scans every ``from ... import ...`` statement for an import whose module
287
- path contains ``automation_logging`` and collects the local binding of each
288
- imported ``log_*`` helper (the alias when ``as`` is present, otherwise the
289
- imported name). Only these names identify a str.format-logger call; a
290
- ``log_*`` helper from any other module is not collected, because a
291
- ``%``-style logger formats its tokens correctly.
292
-
293
- Args:
294
- tree: The parsed module to scan for logger imports.
295
-
296
- Returns:
297
- The set of local names bound to automation_logging log helpers.
298
- """
299
- bound_names: set[str] = set()
300
- for each_node in ast.walk(tree):
301
- if not isinstance(each_node, ast.ImportFrom):
302
- continue
303
- if each_node.module is None or "automation_logging" not in each_node.module:
304
- continue
305
- for each_alias in each_node.names:
306
- if each_alias.name in ALL_FORMAT_LOGGER_FUNCTION_NAMES:
307
- bound_names.add(each_alias.asname or each_alias.name)
308
- return bound_names
309
-
310
-
311
- def _printf_token_log_call_line(
312
- node: ast.AST, all_format_logger_names: set[str]
313
- ) -> int | None:
314
- """Return the line of a format-logger call carrying a printf token, else None.
315
-
316
- Args:
317
- node: The AST node to inspect.
318
- all_format_logger_names: Local names bound to automation_logging log
319
- helpers.
320
-
321
- Returns:
322
- The 1-based line number when ``node`` is a bare-name call to a format
323
- logger that has at least one format argument after the message and
324
- whose first string-literal argument carries a printf token; otherwise
325
- None. A call with only the message and no format arguments never runs
326
- ``.format(*args)``, so its token prints intact and is not flagged.
327
- """
328
- if not isinstance(node, ast.Call):
329
- return None
330
- function_reference = node.func
331
- if (
332
- not isinstance(function_reference, ast.Name)
333
- or function_reference.id not in all_format_logger_names
334
- ):
335
- return None
336
- if len(node.args) < MINIMUM_FORMAT_LOGGER_ARGUMENT_COUNT:
337
- return None
338
- message_argument = node.args[0]
339
- if not isinstance(message_argument, ast.Constant) or not isinstance(
340
- message_argument.value, str
341
- ):
342
- return None
343
- if not LOGGING_PRINTF_TOKEN_PATTERN.search(message_argument.value):
344
- return None
345
- return node.lineno
346
-
347
-
348
- def check_logging_printf_tokens(content: str, file_path: str) -> list[str]:
349
- """Flag printf tokens in a str.format-logger (automation_logging) message.
350
-
351
- The ``shared_utils.automation_logging`` helpers (``log_info``, ``log_error``,
352
- ...) format with ``str.format`` (``{}`` placeholders) only when format
353
- arguments follow the message (``message.format(*args) if args else
354
- message``), so a printf-style token such as ``%s`` in the message literal is
355
- never substituted: the format arguments are dropped and the literal token
356
- prints. The check fires only in a file that imports one of those helpers
357
- from an ``automation_logging`` module, and only for a bare-name call to such
358
- a helper that passes at least one format argument after the message and
359
- whose first argument is a string literal carrying a token. A call with only
360
- the message and no format arguments never runs ``.format``, so its token
361
- prints intact and is left alone. An attribute call (``logger.info``) or a
362
- ``log_*`` helper from any other module formats ``%``-tokens correctly and is
363
- left alone. Test files are exempt so a test may exercise the malformed shape.
364
-
365
- Args:
366
- content: The Python source under validation.
367
- file_path: The destination path, used to skip test files and non-Python.
368
-
369
- Returns:
370
- One issue line per offending call, capped at the configured maximum.
371
- """
372
- if is_test_file(file_path):
373
- return []
374
- if get_file_extension(file_path) not in ALL_PYTHON_EXTENSIONS:
375
- return []
376
- try:
377
- tree = ast.parse(content)
378
- except SyntaxError:
379
- return []
380
- all_format_logger_names = _format_logger_names_imported(tree)
381
- if not all_format_logger_names:
382
- return []
383
- issues: list[str] = []
384
- for each_node in ast.walk(tree):
385
- offending_line = _printf_token_log_call_line(each_node, all_format_logger_names)
386
- if offending_line is None:
387
- continue
388
- issues.append(
389
- f"Line {offending_line}: printf token in a str.format logger "
390
- "message - the automation_logging helpers format with str.format; "
391
- "use {} placeholders (the %-arguments are silently dropped)"
392
- )
393
- if len(issues) >= MAX_LOGGING_PRINTF_TOKEN_ISSUES:
394
- break
395
- return issues
396
-
397
-
398
279
  def _logging_call_receiver_name(receiver_node: ast.expr) -> str | None:
399
280
  """Return the trailing identifier of a logging-call receiver expression, else None.
400
281
 
@@ -4,6 +4,11 @@
4
4
  The gate reads the ``text`` field of the chat tools that post to the user.
5
5
  It denies the call when the text holds more than MAXIMUM_SENTENCE_COUNT
6
6
  sentences, or a sentence longer than MAXIMUM_WORDS_PER_SENTENCE words.
7
+ It also denies a pull request number the reader cannot open::
8
+
9
+ flag: Both land in PR 5256.
10
+ flag: It merged in #4347.
11
+ ok: Both land in [PR 5256](https://github.com/owner/repo/pull/5256).
7
12
  Each non-empty line counts as its own sentence, so a list counts one
8
13
  sentence per item. URLs, markdown link targets, inline code spans, and
9
14
  fenced blocks carry no words.
@@ -34,6 +39,7 @@ from hooks_constants.reply_length_gate_constants import (
34
39
  LINE_BREAK_PATTERN,
35
40
  LINK_TARGET_PATTERN,
36
41
  LONG_SENTENCE_MESSAGE,
42
+ MARKDOWN_LINK_PATTERN,
37
43
  MAXIMUM_SENTENCE_COUNT,
38
44
  MAXIMUM_WORDS_PER_SENTENCE,
39
45
  RETRY_INSTRUCTION,
@@ -44,6 +50,8 @@ from hooks_constants.reply_length_gate_constants import (
44
50
  TOO_MANY_SENTENCES_MESSAGE,
45
51
  TOOL_INPUT_KEY,
46
52
  TOOL_NAME_KEY,
53
+ UNLINKED_PULL_REQUEST_MESSAGE,
54
+ UNLINKED_PULL_REQUEST_PATTERN,
47
55
  URL_PATTERN,
48
56
  WORD_PATTERN,
49
57
  WORD_SEPARATOR,
@@ -87,6 +95,17 @@ def length_violation(reply_text: str) -> str | None:
87
95
  return None
88
96
 
89
97
 
98
+ def unlinked_pull_request_violation(reply_text: str) -> str | None:
99
+ """Return the deny reason for a pull request number outside a link, or None."""
100
+ without_fences = FENCED_BLOCK_PATTERN.sub(" ", reply_text)
101
+ without_code = INLINE_CODE_PATTERN.sub(" ", without_fences)
102
+ without_links = MARKDOWN_LINK_PATTERN.sub(" ", without_code)
103
+ unlinked_match = UNLINKED_PULL_REQUEST_PATTERN.search(URL_PATTERN.sub(" ", without_links))
104
+ if unlinked_match is None:
105
+ return None
106
+ return UNLINKED_PULL_REQUEST_MESSAGE.format(reference=unlinked_match.group(0))
107
+
108
+
90
109
  def main() -> int:
91
110
  hook_input = read_hook_input_dictionary_from_stdin()
92
111
  if hook_input is None:
@@ -100,7 +119,7 @@ def main() -> int:
100
119
  reply_text = tool_input.get(TEXT_KEY)
101
120
  if not isinstance(reply_text, str):
102
121
  return ALLOW_EXIT_CODE
103
- violation = length_violation(reply_text)
122
+ violation = length_violation(reply_text) or unlinked_pull_request_violation(reply_text)
104
123
  if violation is None:
105
124
  return ALLOW_EXIT_CODE
106
125
  block_reason = violation + RETRY_INSTRUCTION
@@ -49,7 +49,6 @@ ALL_SCOPE_AWARE_RULE_NAMES = frozenset(
49
49
  "check_docstring_runon_sentence",
50
50
  "check_docstring_prose_wall_without_illustration",
51
51
  "check_boolean_naming",
52
- "check_ignored_must_check_return",
53
52
  "check_tests_use_isolated_filesystem_paths",
54
53
  "check_return_annotations",
55
54
  "check_function_length",
@@ -70,7 +69,6 @@ NARROW_EDIT_ACCEPTED_RULE_NAMES = frozenset(
70
69
  "check_join_separator_string_magic",
71
70
  "check_banned_noun_word_boundary",
72
71
  "check_boolean_naming",
73
- "check_ignored_must_check_return",
74
72
  }
75
73
  )
76
74
 
@@ -80,7 +78,6 @@ EXPECTED_RULE_TEXT_BY_NAME = {
80
78
  "check_join_separator_string_magic": "string separator",
81
79
  "check_banned_noun_word_boundary": "Identifier",
82
80
  "check_boolean_naming": "Boolean",
83
- "check_ignored_must_check_return": "return value",
84
81
  }
85
82
 
86
83
 
@@ -139,19 +136,6 @@ ALL_REQUIRED_RULE_FIXTURES = (
139
136
  expected_marker="ready",
140
137
  rule_name="check_boolean_naming",
141
138
  ),
142
- NarrowEditFixture(
143
- old_fragment=(
144
- "def submit_form() -> None:\n"
145
- " if find_and_click('#submit'):\n"
146
- " return\n"
147
- ),
148
- new_fragment=(
149
- "def submit_form() -> None:\n"
150
- " find_and_click('#submit')\n"
151
- ),
152
- expected_marker="find_and_click",
153
- rule_name="check_ignored_must_check_return",
154
- ),
155
139
  )
156
140
 
157
141
 
@@ -191,3 +191,47 @@ def test_should_allow_a_call_without_text(
191
191
  def test_should_allow_empty_stdin(monkeypatch: pytest.MonkeyPatch) -> None:
192
192
  monkeypatch.setattr("sys.stdin", io.TextIOWrapper(io.BytesIO(b"")))
193
193
  assert reply_length_gate.main() == 0
194
+
195
+
196
+ def test_should_deny_a_pr_number_with_no_link_and_name_it(
197
+ monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
198
+ ) -> None:
199
+ exit_code, stderr_text = run_gate(
200
+ monkeypatch, capsys, REPLY_TOOL_NAME, {"text": "Both land in PR 5256."}
201
+ )
202
+ assert exit_code == 2
203
+ assert "PR 5256" in stderr_text
204
+
205
+
206
+ def test_should_deny_a_bare_hash_number(
207
+ monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
208
+ ) -> None:
209
+ exit_code, stderr_text = run_gate(
210
+ monkeypatch, capsys, POST_TOOL_NAME, {"text": "It merged in #4347."}
211
+ )
212
+ assert exit_code == 2
213
+ assert "#4347" in stderr_text
214
+
215
+
216
+ def test_should_allow_a_pr_number_inside_its_link(
217
+ monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
218
+ ) -> None:
219
+ exit_code, stderr_text = run_gate(
220
+ monkeypatch,
221
+ capsys,
222
+ REPLY_TOOL_NAME,
223
+ {"text": "Both land in [PR 5256](https://github.com/owner/repo/pull/5256)."},
224
+ )
225
+ assert (exit_code, stderr_text) == (0, "")
226
+
227
+
228
+ def test_should_allow_a_bare_pull_request_url(
229
+ monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
230
+ ) -> None:
231
+ exit_code, _ = run_gate(
232
+ monkeypatch,
233
+ capsys,
234
+ REPLY_TOOL_NAME,
235
+ {"text": "Pull request: https://github.com/owner/repo/pull/5256"},
236
+ )
237
+ assert exit_code == 0
@@ -22,12 +22,10 @@ MAX_DOCSTRING_FORMAT_ISSUES: int = 5
22
22
  MAX_DOCSTRING_ARGS_SIGNATURE_ISSUES: int = 5
23
23
  MAX_CLASS_DOCSTRING_PUBLIC_METHOD_ISSUES: int = 5
24
24
  MINIMUM_PUBLIC_METHODS_FOR_CLASS_DOCSTRING_BREADTH: int = 2
25
- MAX_IGNORED_MUST_CHECK_RETURN_ISSUES: int = 5
26
25
  MAX_TYPE_ESCAPE_HATCH_ISSUES: int = 5
27
26
  MAX_THIN_WRAPPER_ISSUES: int = 1
28
27
  MAX_ZERO_PAYLOAD_ALIAS_ISSUES: int = 3
29
28
  MAX_LOGGING_FSTRING_ISSUES: int = 3
30
- MAX_LOGGING_PRINTF_TOKEN_ISSUES: int = 3
31
29
  MAX_LOGGING_ADJACENT_LITERAL_ISSUES: int = 3
32
30
  MAX_CONFIG_DUPLICATE_PATH_ANCHOR_ISSUES: int = 3
33
31
  MAX_WINDOWS_API_NONE_ISSUES: int = 3
@@ -204,17 +202,6 @@ DOCSTRING_REFERENCE_MARKER_WINDOW: int = 2
204
202
  ALL_GENERIC_CHECK_NAME_TOKENS: frozenset[str] = frozenset(
205
203
  {"check", "checks", "test", "tests", "in", "for", "and", "the"}
206
204
  )
207
- ALL_FORMAT_LOGGER_FUNCTION_NAMES: frozenset[str] = frozenset(
208
- {
209
- "log_debug",
210
- "log_info",
211
- "log_ok",
212
- "log_error",
213
- "log_warning",
214
- "log_batch",
215
- "log_background",
216
- }
217
- )
218
205
  DOCSTRING_RUNON_SENTENCE_WORD_LIMIT: int = 30
219
206
  MAX_DOCSTRING_RUNON_SENTENCE_ISSUES: int = 5
220
207
  ALL_DOCSTRING_RUNON_JOINER_MARKERS: tuple[str, ...] = ("—", " -- ", ";")
@@ -72,8 +72,6 @@ ALL_POLARITY_ANTONYM_TOKEN_PAIRS: tuple[tuple[str, str], ...] = (
72
72
  )
73
73
  POLARITY_TOKEN_BOUNDARY_PATTERN: str = r"(?:^|_)%s(?:_|$)"
74
74
 
75
- ALL_MUST_CHECK_RETURN_FUNCTION_NAMES: frozenset[str] = frozenset({"find_and_click", "write_outcome"})
76
-
77
75
  DOCSTRING_ARG_ENTRY_PATTERN: re.Pattern[str] = re.compile(r"^([A-Za-z_][A-Za-z0-9_]*)\s*[:(]")
78
76
  DOCSTRING_PLURAL_FAMILY_STOP_PATTERN: re.Pattern[str] = re.compile(
79
77
  r"\bthe\s+([a-z][a-z]+)\s+stops\b"
@@ -211,14 +209,10 @@ LOGGING_FSTRING_PATTERN = re.compile(
211
209
  r'|(?:logger|logging|log)\.(?:debug|info|warning|error|critical|exception))'
212
210
  r'\s*\(\s*(?:[rR][fF]|[fF][rR]?)["\']'
213
211
  )
214
- LOGGING_PRINTF_TOKEN_PATTERN: re.Pattern[str] = re.compile(
215
- r"(?<!%)%[#0\- +]?[0-9.*]*[sdrixfgeEcoX](?![a-zA-Z])"
216
- )
217
212
  ADJACENT_STRING_LITERAL_PATTERN: re.Pattern[str] = re.compile(
218
213
  r'(?<!["\'])[rRbBfFuU]{0,2}(?:"(?:[^"\\\n]|\\.)*"|\'(?:[^\'\\\n]|\\.)*\')'
219
214
  r'\s*[rRbBfFuU]{0,2}(?:"(?:[^"\\\n]|\\.)*"|\'(?:[^\'\\\n]|\\.)*\')(?!["\'])'
220
215
  )
221
- MINIMUM_FORMAT_LOGGER_ARGUMENT_COUNT = 2
222
216
  ALL_LOGGING_CALL_METHOD_NAMES: frozenset[str] = frozenset(
223
217
  {"debug", "info", "warning", "error", "critical", "exception"}
224
218
  )
@@ -1,19 +1,17 @@
1
- """Resolve local identity values for NAS ssh and PII exempt-repo hooks.
1
+ """Resolve local identity values for the PII hooks.
2
2
 
3
- The enforcer hooks ship into ``~/.claude/`` and cannot read a repository file,
4
- so they read real machine values from the environment or a git-ignored file in
5
- the Claude home directory. This module supplies NAS host/user/port, the two
6
- NAS deny messages that quote those values, and the owner/repo slug set used by
7
- ``pii_exempt_repository_slugs`` (``CLAUDE_PII_EXEMPT_REPOS`` /
8
- ``pii_exempt_repositories``). The committed NAS defaults are placeholders.
3
+ The hooks ship into ``~/.claude/`` and cannot read a repository file, so they
4
+ read machine values from the environment or a git-ignored file in the Claude
5
+ home directory. This module supplies the NAS host the PII scanner allowlists
6
+ and the owner/repo slug set used by ``pii_exempt_repository_slugs``
7
+ (``CLAUDE_PII_EXEMPT_REPOS`` / ``pii_exempt_repositories``). The committed NAS
8
+ host default is a placeholder.
9
9
 
10
10
  ::
11
11
 
12
12
  CLAUDE_NAS_HOST set to a host -> nas_host() returns that host
13
- CLAUDE_NAS_SSH_PORT set to 2200 -> nas_ssh_port() returns 2200
14
13
  CLAUDE_PII_EXEMPT_REPOS="Owner/repo" -> {"owner/repo"}
15
14
  (env unset, no file) -> nas_host() == "nas.example.local"
16
- nas_ssh_port() == 22
17
15
  pii_exempt_repository_slugs() == frozenset()
18
16
 
19
17
  Each value comes from its environment variable, then
@@ -32,19 +30,11 @@ PII_EXEMPT_REPOS_ENV_VAR = "CLAUDE_PII_EXEMPT_REPOS"
32
30
  PII_EXEMPT_REPOS_JSON_KEY = "pii_exempt_repositories"
33
31
  PII_EXEMPT_REPOS_SEPARATOR = ","
34
32
  PII_ALLOWLISTED_VALUES_JSON_KEY = "pii_allowlisted_values"
35
- NAS_SSH_USER_ENV_VAR = "CLAUDE_NAS_SSH_USER"
36
- NAS_SSH_PORT_ENV_VAR = "CLAUDE_NAS_SSH_PORT"
37
33
  NAS_JSON_KEY = "nas"
38
34
  NAS_HOST_JSON_KEY = "host"
39
- NAS_SSH_USER_JSON_KEY = "ssh_user"
40
- NAS_SSH_PORT_JSON_KEY = "ssh_port"
41
35
  CLAUDE_HOME_DIRECTORY_NAME = ".claude"
42
36
  LOCAL_IDENTITY_FILE_NAME = "local-identity.json"
43
37
  PLACEHOLDER_NAS_HOST = "nas.example.local"
44
- PLACEHOLDER_NAS_SSH_USER = "operator"
45
- PLACEHOLDER_NAS_SSH_PORT = 22
46
- OPENSSH_INVOCATION_EXAMPLE_BINARY = '"/c/Windows/System32/OpenSSH/ssh.exe"'
47
- NAS_SSH_RULE_REFERENCE = "~/.claude/rules/nas-ssh-invocation.md"
48
38
 
49
39
 
50
40
  def _local_identity_file_path() -> Path:
@@ -178,106 +168,3 @@ def nas_host() -> str:
178
168
  if isinstance(stored_host, str) and stored_host:
179
169
  return stored_host
180
170
  return PLACEHOLDER_NAS_HOST
181
-
182
-
183
- def nas_ssh_user() -> str:
184
- """Return the ssh user the enforcer expects for the NAS.
185
-
186
- ::
187
-
188
- CLAUDE_NAS_SSH_USER set to a user -> that user
189
- (env unset, no file) -> "operator"
190
-
191
- The environment variable wins, then the git-ignored file, then the
192
- placeholder default.
193
-
194
- Returns:
195
- The ssh login name for the NAS.
196
- """
197
- user_from_environment = os.environ.get(NAS_SSH_USER_ENV_VAR)
198
- if user_from_environment:
199
- return user_from_environment
200
- stored_user = _nas_section_from_local_file().get(NAS_SSH_USER_JSON_KEY)
201
- if isinstance(stored_user, str) and stored_user:
202
- return stored_user
203
- return PLACEHOLDER_NAS_SSH_USER
204
-
205
-
206
- def nas_ssh_port() -> int:
207
- """Return the ssh port the enforcer expects for the NAS.
208
-
209
- ::
210
-
211
- CLAUDE_NAS_SSH_PORT set to 2200 -> 2200
212
- (env unset, no file) -> 22
213
-
214
- The environment variable wins, then the git-ignored file, then the
215
- placeholder default.
216
-
217
- Returns:
218
- The ssh port number for the NAS.
219
- """
220
- port_from_environment = os.environ.get(NAS_SSH_PORT_ENV_VAR)
221
- if port_from_environment and port_from_environment.isdigit():
222
- return int(port_from_environment)
223
- stored_port = _nas_section_from_local_file().get(NAS_SSH_PORT_JSON_KEY)
224
- if isinstance(stored_port, int):
225
- return stored_port
226
- return PLACEHOLDER_NAS_SSH_PORT
227
-
228
-
229
- def _openssh_invocation_example() -> str:
230
- return (
231
- f"{OPENSSH_INVOCATION_EXAMPLE_BINARY} -o BatchMode=yes -o ConnectTimeout=10 "
232
- f'-p {nas_ssh_port()} {nas_ssh_user()}@{nas_host()} "<cmd>"'
233
- )
234
-
235
-
236
- def bare_ssh_binary_deny_message() -> str:
237
- """Return the deny message for a bare ssh-family word aimed at the NAS.
238
-
239
- ::
240
-
241
- ssh -p 22 operator@nas.example.local "ls" -> this message text
242
- (the text quotes the resolved host, user, and port)
243
-
244
- Names the Git Bash MSYS-ssh hang and points at the Windows OpenSSH binary
245
- with batch mode on.
246
-
247
- Returns:
248
- The full deny-message text for the bare ssh-family case.
249
- """
250
- return (
251
- f"BLOCKED [nas-ssh-binary]: Git Bash's MSYS ssh reads ~/.ssh/id_ed25519 as "
252
- f"world-readable through its ACL mapping, rejects the key as bad permissions, "
253
- f"and falls back to an interactive password prompt that hangs unattended "
254
- f"sessions against the NAS at {nas_host()}.\n\n"
255
- f"Use the Windows OpenSSH binary, which authenticates the key without prompting:\n"
256
- f" {_openssh_invocation_example()}\n\n"
257
- f"See {NAS_SSH_RULE_REFERENCE} for full guidance."
258
- )
259
-
260
-
261
- def missing_batch_mode_deny_message() -> str:
262
- """Return the deny message for the OpenSSH binary without batch mode.
263
-
264
- ::
265
-
266
- "..ssh.exe" -p 22 operator@nas.example.local "ls" -> this message text
267
- (the text quotes the resolved host, user, and port)
268
-
269
- Names the interactive-prompt hang and asks for ``-o BatchMode=yes`` so a key
270
- failure exits loudly.
271
-
272
- Returns:
273
- The full deny-message text for the missing-batch-mode case.
274
- """
275
- return (
276
- f"BLOCKED [nas-ssh-binary]: this NAS ssh command uses the Windows OpenSSH binary "
277
- f"but omits -o BatchMode=yes, so an authentication regression falls back to an "
278
- f"interactive password prompt that hangs unattended sessions against the NAS at "
279
- f"{nas_host()}.\n\n"
280
- f"Add -o BatchMode=yes so a key failure exits loudly rather than prompting:\n"
281
- f" {_openssh_invocation_example()}\n\n"
282
- f"See {NAS_SSH_RULE_REFERENCE} for full guidance."
283
- )