claude-dev-env 8.117.2 → 8.117.4

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.
Files changed (77) hide show
  1. package/_shared/pr-loop/scripts/pyproject.toml +1 -1
  2. package/_shared/process-tree/scripts/pyproject.toml +1 -1
  3. package/bin/cde.mjs +4 -3
  4. package/bin/cde.test.mjs +87 -1
  5. package/bin/codex-compat.mjs +4 -3
  6. package/bin/codex-compat.test.mjs +91 -1
  7. package/bin/install-plan.mjs +2 -1
  8. package/bin/install.mjs +24 -7
  9. package/bin/install.plan.test.mjs +15 -0
  10. package/bin/install.test.mjs +61 -0
  11. package/bin/python-probe.mjs +42 -0
  12. package/bin/python-probe.test.mjs +19 -2
  13. package/docs/rule-guides/features-start-with-an-eval.md +3 -3
  14. package/docs/rule-guides/proof-before-pull-request.md +2 -2
  15. package/hooks/blocking/bash_pre_tool_use_dispatcher.py +11 -4
  16. package/hooks/blocking/build_eval_before_eval_write_gate.py +10 -4
  17. package/hooks/blocking/followup_pr_dedupe.py +381 -64
  18. package/hooks/blocking/gate_child_process.py +187 -0
  19. package/hooks/blocking/gate_run_reads.py +116 -35
  20. package/hooks/blocking/merge_review_gate.py +93 -10
  21. package/hooks/blocking/merge_review_gate_parts/create_folders.py +346 -0
  22. package/hooks/blocking/merge_review_gate_parts/create_options.py +86 -0
  23. package/hooks/blocking/merge_review_gate_parts/folder_state.py +107 -0
  24. package/hooks/blocking/merge_review_gate_parts/open_request.py +199 -64
  25. package/hooks/blocking/merge_review_gate_parts/quoted_lines.py +283 -0
  26. package/hooks/blocking/merge_review_gate_parts/wrapped_creates.py +126 -0
  27. package/hooks/blocking/pr_lifecycle_skill_gate.py +61 -18
  28. package/hooks/blocking/pre_tool_use_dispatcher.py +25 -3
  29. package/hooks/blocking/pull_request_proof.py +5 -51
  30. package/hooks/blocking/pull_request_proof_edit_gate.py +19 -5
  31. package/hooks/blocking/test_bash_pre_tool_use_dispatcher.py +54 -0
  32. package/hooks/blocking/test_build_eval_before_eval_write_gate.py +64 -0
  33. package/hooks/blocking/test_followup_pr_dedupe.py +464 -1
  34. package/hooks/blocking/test_gate_child_process.py +64 -0
  35. package/hooks/blocking/test_gate_run_reads.py +364 -4
  36. package/hooks/blocking/test_merge_review_gate.py +832 -39
  37. package/hooks/blocking/test_pr_lifecycle_skill_gate.py +130 -4
  38. package/hooks/blocking/test_pre_tool_use_dispatcher.py +64 -0
  39. package/hooks/blocking/test_pull_request_proof.py +16 -0
  40. package/hooks/blocking/test_pull_request_proof_edit_gate.py +60 -0
  41. package/hooks/blocking/tests/test_create_folders.py +290 -0
  42. package/hooks/blocking/tests/test_create_options.py +34 -0
  43. package/hooks/blocking/tests/test_folder_state.py +40 -0
  44. package/hooks/blocking/tests/test_open_request.py +350 -44
  45. package/hooks/blocking/tests/test_quoted_lines.py +86 -0
  46. package/hooks/blocking/tests/test_wrapped_creates.py +42 -0
  47. package/hooks/features/bash-dispatchers.md +1 -1
  48. package/hooks/features/conduct-gates.md +7 -7
  49. package/hooks/features/write-edit-blocking.md +3 -3
  50. package/hooks/hooks_constants/build_eval_before_eval_write_gate_constants.py +5 -0
  51. package/hooks/hooks_constants/followup_pr_dedupe_constants.py +34 -1
  52. package/hooks/hooks_constants/gate_fault.py +52 -0
  53. package/hooks/hooks_constants/gate_fault_constants.py +13 -0
  54. package/hooks/hooks_constants/gate_run_reads_constants.py +9 -1
  55. package/hooks/hooks_constants/merge_review_gate_constants.py +94 -1
  56. package/hooks/hooks_constants/piped_pytest_blocker_constants.py +2 -0
  57. package/hooks/hooks_constants/pr_lifecycle_skill_gate_constants.py +6 -1
  58. package/hooks/hooks_constants/pre_tool_use_stdin.py +23 -3
  59. package/hooks/hooks_constants/shell_command_pipeline.py +68 -8
  60. package/hooks/hooks_constants/shell_command_segments.py +2 -2
  61. package/hooks/hooks_constants/shell_command_wrappers.py +3 -2
  62. package/hooks/hooks_constants/test_followup_pr_dedupe_constants.py +7 -0
  63. package/hooks/hooks_constants/test_gate_fault.py +41 -0
  64. package/hooks/hooks_constants/test_piped_pytest_blocker_constants.py +5 -0
  65. package/hooks/hooks_constants/test_pr_lifecycle_skill_gate_constants.py +10 -0
  66. package/hooks/hooks_constants/test_pre_tool_use_stdin.py +97 -0
  67. package/hooks/hooks_constants/test_shell_command_pipeline.py +55 -0
  68. package/hooks/hooks_constants/test_shell_command_segments.py +15 -0
  69. package/hooks/hooks_constants/test_shell_command_wrappers.py +6 -0
  70. package/hooks/hooks_constants/transcript_skill_scan_constants.py +6 -0
  71. package/hooks/pyproject.toml +2 -3
  72. package/hooks/test_python_floor.py +197 -0
  73. package/hooks/test_transcript_skill_scan.py +324 -0
  74. package/hooks/transcript_skill_scan.py +233 -2
  75. package/hooks/validators/code_quality_checks.py +119 -17
  76. package/hooks/validators/test_code_quality_checks.py +110 -4
  77. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  """Code quality checks validator.
2
2
 
3
3
  Implements:
4
- - Check 30: Function too long (max 30 lines), production files only
4
+ - Check 30: Function too long (max 30 lines of logic), production files only
5
5
  - Check 31: Nesting too deep (max 2 levels)
6
6
  - Check 32: File too long (max 400 lines), production files only
7
7
 
@@ -10,10 +10,15 @@ surface it covers, and a linear list of assertions is what a reader wants there,
10
10
  so capping its length pushes a contributor to split a suite for the counter
11
11
  rather than for the reader. ``magic_value_checks`` short-circuits on the same
12
12
  category through the same helper.
13
+
14
+ The function cap counts lines of logic. A docstring is context a reader needs,
15
+ so its lines, blank lines and comment-only lines stay out of the count.
13
16
  """
14
17
 
15
18
  import ast
19
+ import io
16
20
  import sys
21
+ import tokenize
17
22
  from pathlib import Path
18
23
  from typing import List
19
24
 
@@ -26,24 +31,121 @@ MAX_NESTING_DEPTH = 2
26
31
  MAX_FILE_LINES = 400
27
32
 
28
33
 
29
- def check_function_length(tree: ast.AST, filename: str) -> List[Violation]:
30
- violations: List[Violation] = []
34
+ def _docstring_line_numbers(tree: ast.AST) -> frozenset[int]:
35
+ """Return each line that a function or class docstring covers."""
36
+ all_docstring_lines: set[int] = set()
37
+ for each_node in ast.walk(tree):
38
+ if not isinstance(each_node, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)):
39
+ continue
40
+ first_statement = each_node.body[0]
41
+ if (
42
+ isinstance(first_statement, ast.Expr)
43
+ and isinstance(first_statement.value, ast.Constant)
44
+ and isinstance(first_statement.value.value, str)
45
+ ):
46
+ last_line = first_statement.end_lineno or first_statement.lineno
47
+ all_docstring_lines.update(range(first_statement.lineno, last_line + 1))
48
+ return frozenset(all_docstring_lines)
49
+
50
+
51
+ def _holds_logic(token: tokenize.TokenInfo, all_docstring_lines: frozenset[int]) -> bool:
52
+ """Return True for a token of code: no comment, layout token or docstring."""
53
+ all_layout_token_types = (
54
+ tokenize.COMMENT,
55
+ tokenize.NL,
56
+ tokenize.NEWLINE,
57
+ tokenize.INDENT,
58
+ tokenize.DEDENT,
59
+ tokenize.ENCODING,
60
+ tokenize.ENDMARKER,
61
+ )
62
+ if token.type in all_layout_token_types:
63
+ return False
64
+ is_docstring = (
65
+ token.type == tokenize.STRING
66
+ and token.start[0] in all_docstring_lines
67
+ and token.end[0] in all_docstring_lines
68
+ )
69
+ return not is_docstring
70
+
71
+
72
+ def _logic_line_numbers(tree: ast.AST, source: str) -> frozenset[int] | None:
73
+ """Return each line that holds code, or None when the source cannot be tokenized.
74
+
75
+ ::
76
+
77
+ def area(width, height): -> logic
78
+ '''Return the area.''' -> docstring, left out
79
+ -> blank, left out
80
+ # width times height -> comment only, left out
81
+ return width * height # ok -> logic
82
+
83
+ Every line of a string that runs over several lines counts, apart from a
84
+ docstring. Line ends are read the way the parser reads them, so a line
85
+ number here names the same line as a node's ``lineno``.
86
+ """
87
+ all_docstring_lines = _docstring_line_numbers(tree)
88
+ try:
89
+ all_tokens = list(tokenize.generate_tokens(io.StringIO(source, newline=None).readline))
90
+ except (tokenize.TokenError, SyntaxError):
91
+ return None
92
+ return frozenset(
93
+ each_line
94
+ for each_token in all_tokens
95
+ if _holds_logic(each_token, all_docstring_lines)
96
+ for each_line in range(each_token.start[0], each_token.end[0] + 1)
97
+ )
98
+
99
+
100
+ def _logic_line_count(
101
+ node: ast.FunctionDef | ast.AsyncFunctionDef, all_logic_lines: frozenset[int] | None
102
+ ) -> int:
103
+ """Return how many lines of logic the function holds, its nested definitions included.
104
+
105
+ Without a set of logic lines, every line from ``def`` to the last statement counts.
106
+ """
107
+ all_span_lines = range(node.lineno, (node.end_lineno or node.lineno) + 1)
108
+ if all_logic_lines is None:
109
+ return len(all_span_lines)
110
+ return sum(1 for each_line in all_span_lines if each_line in all_logic_lines)
111
+
112
+
113
+ def check_function_length(tree: ast.AST, filename: str, source: str) -> List[Violation]:
114
+ """Flag each production function that holds more than 30 lines of logic.
115
+
116
+ ::
117
+
118
+ 5 lines of logic under a 60-line docstring -> no finding
119
+ 31 lines of logic -> "Function 'run' is 31 lines (max 30)"
31
120
 
121
+ The count leaves out the docstring of the function and of each definition
122
+ nested in it, blank lines and comment-only lines. A test file gets no finding.
123
+
124
+ Args:
125
+ tree: The parsed module.
126
+ filename: The path the finding names, also read for the test file exemption.
127
+ source: The text the tree was parsed from.
128
+
129
+ Returns:
130
+ One violation for each function over the cap, at its ``def`` line.
131
+ """
32
132
  if is_test_file(filename):
33
- return violations
133
+ return []
34
134
 
35
- for node in ast.walk(tree):
36
- if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
37
- if node.end_lineno and node.lineno:
38
- length = node.end_lineno - node.lineno + 1
39
- if length > MAX_FUNCTION_LINES:
40
- violations.append(
41
- Violation(
42
- filename,
43
- node.lineno,
44
- f"Function '{node.name}' is {length} lines (max {MAX_FUNCTION_LINES})",
45
- )
46
- )
135
+ all_logic_lines = _logic_line_numbers(tree, source)
136
+ violations: List[Violation] = []
137
+ for each_node in ast.walk(tree):
138
+ if not isinstance(each_node, (ast.FunctionDef, ast.AsyncFunctionDef)):
139
+ continue
140
+ length = _logic_line_count(each_node, all_logic_lines)
141
+ if length > MAX_FUNCTION_LINES:
142
+ violations.append(
143
+ Violation(
144
+ filename,
145
+ each_node.lineno,
146
+ f"Function '{each_node.name}' is {length} lines (max {MAX_FUNCTION_LINES})",
147
+ )
148
+ )
47
149
 
48
150
  return violations
49
151
 
@@ -116,7 +218,7 @@ def validate_file(file_path: Path) -> List[Violation]:
116
218
  except Exception as error:
117
219
  return violations + [Violation(filename, 0, f"Error: {error}")]
118
220
 
119
- violations.extend(check_function_length(tree, filename))
221
+ violations.extend(check_function_length(tree, filename, source))
120
222
  violations.extend(check_nesting_depth(tree, filename))
121
223
 
122
224
  return violations
@@ -10,6 +10,7 @@ from .code_quality_checks import (
10
10
  check_function_length,
11
11
  check_nesting_depth,
12
12
  check_file_length,
13
+ validate_file,
13
14
  )
14
15
  from .validator_base import Violation
15
16
 
@@ -81,12 +82,12 @@ def process(items):
81
82
  class TestFunctionLength:
82
83
  def test_short_function_passes(self) -> None:
83
84
  tree = ast.parse(GOOD_SHORT_FUNCTION)
84
- violations = check_function_length(tree, "test.py")
85
+ violations = check_function_length(tree, "test.py", GOOD_SHORT_FUNCTION)
85
86
  assert violations == []
86
87
 
87
88
  def test_long_function_fails(self) -> None:
88
89
  tree = ast.parse(BAD_LONG_FUNCTION)
89
- violations = check_function_length(tree, "test.py")
90
+ violations = check_function_length(tree, "test.py", BAD_LONG_FUNCTION)
90
91
  assert len(violations) == 1
91
92
  assert "30" in violations[0].message or "lines" in violations[0].message.lower()
92
93
 
@@ -132,12 +133,14 @@ class TestFileLength:
132
133
  class TestTestFileExemption:
133
134
  def test_long_function_in_a_test_file_passes(self) -> None:
134
135
  tree = ast.parse(BAD_LONG_FUNCTION)
135
- violations = check_function_length(tree, "packages/app/test_widget.py")
136
+ violations = check_function_length(
137
+ tree, "packages/app/test_widget.py", BAD_LONG_FUNCTION
138
+ )
136
139
  assert violations == []
137
140
 
138
141
  def test_long_function_outside_a_test_file_still_fails(self) -> None:
139
142
  tree = ast.parse(BAD_LONG_FUNCTION)
140
- violations = check_function_length(tree, "packages/app/widget.py")
143
+ violations = check_function_length(tree, "packages/app/widget.py", BAD_LONG_FUNCTION)
141
144
  assert len(violations) == 1
142
145
 
143
146
  def test_long_test_file_passes(self, tmp_path: Path) -> None:
@@ -149,3 +152,106 @@ class TestTestFileExemption:
149
152
  temp_path = tmp_path / "conftest.py"
150
153
  temp_path.write_text("x = 1\n" * 450, encoding="utf-8")
151
154
  assert check_file_length(temp_path) == []
155
+
156
+
157
+ def _docstring_lines(line_count: int) -> list[str]:
158
+ if line_count == 0:
159
+ return []
160
+ all_detail_lines = [f" Detail line {each_index}." for each_index in range(line_count - 2)]
161
+ return [' """Summarize the work.', *all_detail_lines, ' """']
162
+
163
+
164
+ def _function_source(logic_line_count: int, docstring_line_count: int = 0) -> str:
165
+ all_assignment_lines = [
166
+ f" value_{each_index} = {each_index}" for each_index in range(logic_line_count - 2)
167
+ ]
168
+ all_lines = [
169
+ "def process():",
170
+ *_docstring_lines(docstring_line_count),
171
+ *all_assignment_lines,
172
+ " return 0",
173
+ ]
174
+ return "\n".join(all_lines) + "\n"
175
+
176
+
177
+ def _function_length_messages(source: str) -> list[str]:
178
+ all_violations = check_function_length(ast.parse(source), "packages/app/widget.py", source)
179
+ return [each_violation.message for each_violation in all_violations]
180
+
181
+
182
+ @pytest.fixture
183
+ def production_directory(tmp_path_factory: pytest.TempPathFactory) -> Path:
184
+ return tmp_path_factory.mktemp("production")
185
+
186
+
187
+ class TestFunctionLogicLineCount:
188
+ def test_five_logic_lines_under_a_sixty_line_docstring_pass(
189
+ self, production_directory: Path
190
+ ) -> None:
191
+ production_path = production_directory / "widget.py"
192
+ production_path.write_text(
193
+ _function_source(logic_line_count=5, docstring_line_count=60), encoding="utf-8"
194
+ )
195
+ assert validate_file(production_path) == []
196
+
197
+ def test_thirty_one_logic_lines_fail(self, production_directory: Path) -> None:
198
+ production_path = production_directory / "widget.py"
199
+ production_path.write_text(_function_source(logic_line_count=31), encoding="utf-8")
200
+ all_messages = [each_violation.message for each_violation in validate_file(production_path)]
201
+ assert all_messages == ["Function 'process' is 31 lines (max 30)"]
202
+
203
+ def test_thirty_logic_lines_pass(self) -> None:
204
+ assert _function_length_messages(_function_source(logic_line_count=30)) == []
205
+
206
+ def test_the_message_counts_logic_lines_only(self) -> None:
207
+ source = _function_source(logic_line_count=31, docstring_line_count=60)
208
+ assert _function_length_messages(source) == ["Function 'process' is 31 lines (max 30)"]
209
+
210
+ def test_blank_and_comment_only_lines_are_left_out(self) -> None:
211
+ all_padded_lines: list[str] = []
212
+ for each_line in _function_source(logic_line_count=30).splitlines():
213
+ all_padded_lines.extend([each_line, "", " # a note between two steps"])
214
+ assert _function_length_messages("\n".join(all_padded_lines) + "\n") == []
215
+
216
+ def test_a_line_with_code_and_a_trailing_comment_counts(self) -> None:
217
+ all_commented_lines = [
218
+ f"{each_line} # a note"
219
+ for each_line in _function_source(logic_line_count=31).splitlines()
220
+ ]
221
+ assert _function_length_messages("\n".join(all_commented_lines) + "\n") == [
222
+ "Function 'process' is 31 lines (max 30)"
223
+ ]
224
+
225
+ def test_each_line_of_a_multi_line_string_counts(self) -> None:
226
+ all_text_lines = ["first", "", *[f"row {each_index}" for each_index in range(27)]]
227
+ all_lines = [
228
+ "def process():",
229
+ ' text = """' + all_text_lines[0],
230
+ *all_text_lines[1:],
231
+ ' """',
232
+ " return text",
233
+ ]
234
+ assert _function_length_messages("\n".join(all_lines) + "\n") == [
235
+ "Function 'process' is 32 lines (max 30)"
236
+ ]
237
+
238
+ def test_a_nested_function_adds_its_logic_and_leaves_out_its_docstring(self) -> None:
239
+ all_nested_lines = [
240
+ " def helper():",
241
+ *[f" {each_line}" for each_line in _docstring_lines(40)],
242
+ " return 1",
243
+ ]
244
+ all_outer_lines = _function_source(logic_line_count=29).splitlines()
245
+ all_lines = [all_outer_lines[0], *all_nested_lines, *all_outer_lines[1:]]
246
+ assert _function_length_messages("\n".join(all_lines) + "\n") == [
247
+ "Function 'process' is 31 lines (max 30)"
248
+ ]
249
+
250
+ def test_mixed_line_endings_keep_each_line_in_place(self) -> None:
251
+ all_lines = _function_source(logic_line_count=31, docstring_line_count=10).splitlines()
252
+ all_line_endings = ("\r\n", "\n", "\r")
253
+ source = "".join(
254
+ each_line + all_line_endings[each_index % len(all_line_endings)]
255
+ for each_index, each_line in enumerate(all_lines)
256
+ )
257
+ assert _function_length_messages(source) == ["Function 'process' is 31 lines (max 30)"]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-dev-env",
3
- "version": "8.117.2",
3
+ "version": "8.117.4",
4
4
  "description": "Claude Code development standards — rules, hooks, agents, commands, and skills",
5
5
  "type": "module",
6
6
  "bin": {