claude-dev-env 8.115.0 → 8.116.0
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.
- package/docs/rule-guides/verified-work.md +1 -1
- package/hooks/advisory/commit_and_pull_request_words.py +346 -0
- package/hooks/advisory/piece_clauses.py +248 -0
- package/hooks/advisory/pieces_per_level_analysis.py +192 -0
- package/hooks/advisory/pieces_per_level_note.py +265 -0
- package/hooks/advisory/test_commit_and_pull_request_words.py +126 -0
- package/hooks/advisory/test_piece_clauses.py +183 -0
- package/hooks/advisory/test_pieces_per_level_note.py +389 -0
- package/hooks/advisory/test_pieces_per_level_note_bounds.py +215 -0
- package/hooks/advisory/test_pieces_per_level_note_deadline.py +282 -0
- package/hooks/features/README.md +1 -1
- package/hooks/features/session-context.md +4 -1
- package/hooks/hooks.json +10 -0
- package/hooks/hooks_constants/pieces_per_level_note_constants.py +255 -0
- package/hooks/hooks_constants/shell_command_wrappers.py +20 -8
- package/hooks/hooks_constants/test_shell_command_wrappers.py +7 -0
- package/package.json +1 -1
- package/scripts/tests/test_verified_work_rule.py +13 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
"""Patterns and note text for the pieces-per-level PreToolUse note.
|
|
2
|
+
|
|
3
|
+
Groups: the payload keys the hook reads, the commit and pull request option
|
|
4
|
+
names, the patterns that find verb-led clauses in a subject and topics in a
|
|
5
|
+
pull request body, and the note text. The note is context only.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import re
|
|
11
|
+
|
|
12
|
+
TOOL_NAME_KEY = "tool_name"
|
|
13
|
+
TOOL_INPUT_KEY = "tool_input"
|
|
14
|
+
COMMAND_INPUT_KEY = "command"
|
|
15
|
+
WORKING_DIRECTORY_KEY = "cwd"
|
|
16
|
+
PRE_TOOL_USE_EVENT_NAME = "PreToolUse"
|
|
17
|
+
ADDITIONAL_CONTEXT_KEY = "additionalContext"
|
|
18
|
+
TITLE_INPUT_KEY = "title"
|
|
19
|
+
BODY_INPUT_KEY = "body"
|
|
20
|
+
|
|
21
|
+
EXECUTABLE_SUFFIX = ".exe"
|
|
22
|
+
GIT_PROGRAM_NAME = "git"
|
|
23
|
+
GIT_COMMIT_WORD = "commit"
|
|
24
|
+
GH_PROGRAM_NAME = "gh"
|
|
25
|
+
ALL_GH_CREATE_WORDS = ("pr", "create")
|
|
26
|
+
ALL_QUICK_SCAN_WORDS = ("commit", "create", "pull_request")
|
|
27
|
+
ALL_SHELL_CONTROL_TOKENS = frozenset({"&&", "||", ";", "|", "&", "|&"})
|
|
28
|
+
BACKSLASH = "\\"
|
|
29
|
+
DOUBLED_BACKSLASH = "\\\\"
|
|
30
|
+
LONG_OPTION_PREFIX = "--"
|
|
31
|
+
OPTION_VALUE_SEPARATOR = "="
|
|
32
|
+
SHORT_OPTION_PREFIX = "-"
|
|
33
|
+
ALL_MESSAGE_LONG_OPTIONS = frozenset({"--message"})
|
|
34
|
+
ALL_FILE_LONG_OPTIONS = frozenset({"--file"})
|
|
35
|
+
MESSAGE_SHORT_FLAG = "m"
|
|
36
|
+
MESSAGE_KIND = "message"
|
|
37
|
+
FILE_KIND = "file"
|
|
38
|
+
FILE_SHORT_OPTION = "-F"
|
|
39
|
+
STANDARD_INPUT_PATH = "-"
|
|
40
|
+
MESSAGE_PARAGRAPH_SEPARATOR = "\n\n"
|
|
41
|
+
SHORT_CLUSTER_MINIMUM_LENGTH = 2
|
|
42
|
+
MAXIMUM_COMMAND_CHARACTERS = 8_000
|
|
43
|
+
MAXIMUM_FILE_BYTES = 65_536
|
|
44
|
+
MAXIMUM_PROGRAM_MENTIONS = 16
|
|
45
|
+
MAXIMUM_WRAPPED_TEXTS = 8
|
|
46
|
+
MAXIMUM_SUBSTITUTION_MARKERS = 16
|
|
47
|
+
MAXIMUM_TITLE_CHARACTERS = 300
|
|
48
|
+
MAXIMUM_BODY_CHARACTERS = 20_000
|
|
49
|
+
MAXIMUM_LINE_CHARACTERS = 500
|
|
50
|
+
TOTAL_DEADLINE_SECONDS = 1.0
|
|
51
|
+
EXIT_WAIT_SECONDS = 0.2
|
|
52
|
+
DEADLINE_ENVIRONMENT_VARIABLE = "PIECES_NOTE_TEST_DEADLINE_SECONDS"
|
|
53
|
+
ANALYZE_FLAG = "--analyze"
|
|
54
|
+
ANALYSIS_MODULE_NAME = "pieces_per_level_analysis"
|
|
55
|
+
CREATE_NO_WINDOW_ATTRIBUTE = "CREATE_NO_WINDOW"
|
|
56
|
+
PARSE_CACHE_SIZE = 2
|
|
57
|
+
ALL_SUBSTITUTION_MARKERS = ("$(", "`")
|
|
58
|
+
|
|
59
|
+
HEREDOC_MESSAGE_PATTERN = re.compile(
|
|
60
|
+
r"^\s*\$\(\s*cat\s+<<-?\s*(?P<quote>['\"]?)(?P<tag>\w+)(?P=quote)[ \t]*\n(?P<text>.*?)\n[ \t]*(?P=tag)[ \t]*\n?\s*\)\s*$",
|
|
61
|
+
re.DOTALL,
|
|
62
|
+
)
|
|
63
|
+
GIT_WORD_PATTERN = re.compile(r"\bgit\b")
|
|
64
|
+
COMMIT_WORD_PATTERN = re.compile(r"\bcommit\b")
|
|
65
|
+
HEREDOC_START_PATTERN = re.compile(
|
|
66
|
+
r"(?:-\w*m|--message)[ =]+\"?\$\(\s*cat\s+<<-?\s*(?P<quote>['\"]?)(?P<tag>\w+)(?P=quote)[ \t]*$"
|
|
67
|
+
)
|
|
68
|
+
HEREDOC_TAG_GROUP = "tag"
|
|
69
|
+
HEREDOC_TEXT_GROUP = "text"
|
|
70
|
+
LINE_LEADING_WORD_PATTERN = re.compile(r"[ \t]*(\w*)")
|
|
71
|
+
LINE_SEPARATOR = "\n"
|
|
72
|
+
CARRIAGE_RETURN = "\r"
|
|
73
|
+
CARRIAGE_RETURN_LINE_FEED = "\r\n"
|
|
74
|
+
MINIMUM_HEREDOC_BODY_LINE_OFFSET = 2
|
|
75
|
+
|
|
76
|
+
CONVENTIONAL_SUBJECT_PATTERN = re.compile(
|
|
77
|
+
r"^[a-z]+(?:\([^)\n]*\))?!?:[ \t]+(?P<description>\S.*)$", re.IGNORECASE
|
|
78
|
+
)
|
|
79
|
+
DESCRIPTION_GROUP = "description"
|
|
80
|
+
CODE_SPAN_PATTERN = re.compile(r"`[^`\n]*`")
|
|
81
|
+
PARENTHESIS_PATTERN = re.compile(r"\([^)\n]*\)")
|
|
82
|
+
QUOTED_TEXT_PATTERN = re.compile(r"\"[^\"\n]*\"|'[^'\n]*'")
|
|
83
|
+
MASKED_TEXT = "text"
|
|
84
|
+
REMOVED_TEXT = ""
|
|
85
|
+
MINIMUM_CLAUSE_WORD_COUNT = 1
|
|
86
|
+
CLAUSE_SEPARATOR_PATTERN = re.compile(r"\s*;\s*|\s*,\s*(?:and\s+)?|\s+and\s+", re.IGNORECASE)
|
|
87
|
+
WORD_EDGE_CHARACTERS = ".,;:!?\"'`*_()"
|
|
88
|
+
MINIMUM_PIECE_COUNT = 2
|
|
89
|
+
MAXIMUM_NAMED_PIECES = 6
|
|
90
|
+
MAXIMUM_PIECE_CHARACTERS = 80
|
|
91
|
+
PIECE_TRUNCATION_SUFFIX = "..."
|
|
92
|
+
|
|
93
|
+
ALL_ADJUNCT_WORDS = frozenset({"with", "using", "via", "without", "including", "plus"})
|
|
94
|
+
ALL_LEADING_ADVERBS = frozenset(
|
|
95
|
+
{"always", "also", "now", "never", "then", "only", "just", "finally", "still"}
|
|
96
|
+
)
|
|
97
|
+
ALL_PIECE_VERBS = frozenset(
|
|
98
|
+
{
|
|
99
|
+
"accept",
|
|
100
|
+
"add",
|
|
101
|
+
"align",
|
|
102
|
+
"allow",
|
|
103
|
+
"apply",
|
|
104
|
+
"ask",
|
|
105
|
+
"bind",
|
|
106
|
+
"block",
|
|
107
|
+
"build",
|
|
108
|
+
"bump",
|
|
109
|
+
"cache",
|
|
110
|
+
"center",
|
|
111
|
+
"change",
|
|
112
|
+
"check",
|
|
113
|
+
"clean",
|
|
114
|
+
"clear",
|
|
115
|
+
"close",
|
|
116
|
+
"collapse",
|
|
117
|
+
"convert",
|
|
118
|
+
"copy",
|
|
119
|
+
"create",
|
|
120
|
+
"darken",
|
|
121
|
+
"delete",
|
|
122
|
+
"detect",
|
|
123
|
+
"disable",
|
|
124
|
+
"draw",
|
|
125
|
+
"drop",
|
|
126
|
+
"emit",
|
|
127
|
+
"enable",
|
|
128
|
+
"end",
|
|
129
|
+
"ensure",
|
|
130
|
+
"expand",
|
|
131
|
+
"extract",
|
|
132
|
+
"fetch",
|
|
133
|
+
"finish",
|
|
134
|
+
"fix",
|
|
135
|
+
"format",
|
|
136
|
+
"handle",
|
|
137
|
+
"hide",
|
|
138
|
+
"ignore",
|
|
139
|
+
"install",
|
|
140
|
+
"keep",
|
|
141
|
+
"lighten",
|
|
142
|
+
"link",
|
|
143
|
+
"list",
|
|
144
|
+
"load",
|
|
145
|
+
"log",
|
|
146
|
+
"make",
|
|
147
|
+
"mark",
|
|
148
|
+
"merge",
|
|
149
|
+
"move",
|
|
150
|
+
"name",
|
|
151
|
+
"open",
|
|
152
|
+
"parse",
|
|
153
|
+
"pass",
|
|
154
|
+
"pin",
|
|
155
|
+
"point",
|
|
156
|
+
"prevent",
|
|
157
|
+
"print",
|
|
158
|
+
"publish",
|
|
159
|
+
"put",
|
|
160
|
+
"read",
|
|
161
|
+
"record",
|
|
162
|
+
"refactor",
|
|
163
|
+
"register",
|
|
164
|
+
"reject",
|
|
165
|
+
"remove",
|
|
166
|
+
"rename",
|
|
167
|
+
"render",
|
|
168
|
+
"replace",
|
|
169
|
+
"require",
|
|
170
|
+
"reset",
|
|
171
|
+
"resize",
|
|
172
|
+
"restore",
|
|
173
|
+
"retry",
|
|
174
|
+
"return",
|
|
175
|
+
"rewrite",
|
|
176
|
+
"route",
|
|
177
|
+
"run",
|
|
178
|
+
"save",
|
|
179
|
+
"scale",
|
|
180
|
+
"send",
|
|
181
|
+
"set",
|
|
182
|
+
"show",
|
|
183
|
+
"simplify",
|
|
184
|
+
"skip",
|
|
185
|
+
"split",
|
|
186
|
+
"start",
|
|
187
|
+
"stop",
|
|
188
|
+
"store",
|
|
189
|
+
"support",
|
|
190
|
+
"switch",
|
|
191
|
+
"sync",
|
|
192
|
+
"tell",
|
|
193
|
+
"tidy",
|
|
194
|
+
"track",
|
|
195
|
+
"trim",
|
|
196
|
+
"unpin",
|
|
197
|
+
"update",
|
|
198
|
+
"upgrade",
|
|
199
|
+
"use",
|
|
200
|
+
"validate",
|
|
201
|
+
"verify",
|
|
202
|
+
"wait",
|
|
203
|
+
"wire",
|
|
204
|
+
"wrap",
|
|
205
|
+
"write",
|
|
206
|
+
}
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
WHAT_THIS_DOES_SECTION_NAME = "What this does"
|
|
210
|
+
TOPIC_BULLET_PATTERN = re.compile(r"^[-*+][ \t]+(?:\*\*|__)(?P<topic>[^*_\n]+?)(?:\*\*|__)")
|
|
211
|
+
TOPIC_GROUP = "topic"
|
|
212
|
+
TOPIC_EDGE_CHARACTERS = " \t:.-"
|
|
213
|
+
ALL_LABEL_TOPICS = frozenset(
|
|
214
|
+
{"before", "after", "why", "who notices", "now", "then", "today", "effect", "note", "context"}
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
PROOF_LEAD_CHARACTERS = " \t>-*+_`#"
|
|
218
|
+
PROOF_NUMBER_PATTERN = re.compile(r"^\d+[.)]\s*")
|
|
219
|
+
WITHOUT_LINE_PATTERN = re.compile(r"^without\b")
|
|
220
|
+
WITH_LINE_PATTERN = re.compile(r"^with\b(?!out)")
|
|
221
|
+
WITH_SAME_LINE_PATTERN = re.compile(r"[;,.]\s+[*_`]*with\b(?!out)")
|
|
222
|
+
MINIMUM_PROOF_PAIR_COUNT = 2
|
|
223
|
+
|
|
224
|
+
COMMIT_KIND = "commit"
|
|
225
|
+
PULL_REQUEST_KIND = "pull request"
|
|
226
|
+
PIECE_SEPARATOR = "; "
|
|
227
|
+
MORE_PIECES_TEMPLATE = "and {count} more"
|
|
228
|
+
PROOF_PAIRS_PIECE_TEMPLATE = "{count} without/with proof pairs under Proof in practice"
|
|
229
|
+
QUOTED_PIECE_TEMPLATE = '"{piece}"'
|
|
230
|
+
|
|
231
|
+
COMMIT_NEXT_COMMAND = (
|
|
232
|
+
"The commit that is running holds every piece. To split it, run `git reset --soft HEAD~1`, "
|
|
233
|
+
"then `git add <paths of the first piece>` and commit, then put the next piece on its own "
|
|
234
|
+
"level with `gt create` (or `git switch -c <next-branch>` without Graphite)."
|
|
235
|
+
)
|
|
236
|
+
PULL_REQUEST_NEXT_COMMAND = (
|
|
237
|
+
"Next command: `gt create` (or `git switch -c <next-branch>` from the previous level) for "
|
|
238
|
+
"each further piece, then open one pull request per level with `gh pr create --base "
|
|
239
|
+
"<previous-branch>`."
|
|
240
|
+
)
|
|
241
|
+
NOTE_TEMPLATE = (
|
|
242
|
+
"Your own words name several pieces in this {kind}: {pieces}. Each piece gets its own "
|
|
243
|
+
"commit and its own stack level, committed as its verifier passes, so a reviewer reads "
|
|
244
|
+
"one purpose at a time. {next_command} This note is context only, and the {kind} runs."
|
|
245
|
+
)
|
|
246
|
+
ALL_NEXT_COMMAND_BY_KIND = {
|
|
247
|
+
COMMIT_KIND: COMMIT_NEXT_COMMAND,
|
|
248
|
+
PULL_REQUEST_KIND: PULL_REQUEST_NEXT_COMMAND,
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
COMMIT_MESSAGE_FLAG_PATTERN = re.compile(r"(?<!\S)(?:-[A-Za-z]*m|--message|-F|--file)(?![\w-])")
|
|
252
|
+
BODY_OPTION_PATTERN = re.compile(r"(?<!\S)(?:--body|--body-file|-b|-F|--file)(?![\w-])")
|
|
253
|
+
PULL_REQUEST_CREATE_PATTERN = re.compile(r"\bpr\s+create\b")
|
|
254
|
+
PULL_REQUEST_SCRIPT_CREATE_PATTERN = re.compile(r"\bpull_request\.py\b\s+create\b")
|
|
255
|
+
CLAUSE_SEPARATOR_PRECHECK_PATTERN = re.compile(r"[,;]|\band\b", re.IGNORECASE)
|
|
@@ -330,12 +330,22 @@ def _inner_commands(command: str, all_command_segments: list[list[str]]) -> list
|
|
|
330
330
|
return [each_command for each_command in all_inner_commands if each_command is not None]
|
|
331
331
|
|
|
332
332
|
|
|
333
|
-
def
|
|
333
|
+
def _command_segments(command: str) -> list[list[str]]:
|
|
334
|
+
return [
|
|
335
|
+
each_segment for each_segment, _following_operator in pipeline_segments_for_command(command)
|
|
336
|
+
]
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
def _all_wrapped_command_parses(
|
|
340
|
+
command: str, maximum_texts: int | None = None
|
|
341
|
+
) -> list[tuple[str, list[list[str]]]]:
|
|
334
342
|
"""Return each command text with its segments, the command first, each text parsed once.
|
|
335
343
|
|
|
336
344
|
The texts after the command are the command string every shell wrapper,
|
|
337
345
|
evaluating program and command substitution inside it runs, unwrapped in
|
|
338
346
|
turn to ``MAXIMUM_UNWRAP_DEPTH`` levels. A text met twice is parsed once.
|
|
347
|
+
With ``maximum_texts`` set, no further text is parsed or unwrapped once that
|
|
348
|
+
many are held.
|
|
339
349
|
"""
|
|
340
350
|
all_parses: list[tuple[str, list[list[str]]]] = []
|
|
341
351
|
all_seen_texts: set[str] = set()
|
|
@@ -345,11 +355,10 @@ def _all_wrapped_command_parses(command: str) -> list[tuple[str, list[list[str]]
|
|
|
345
355
|
if each_text in all_seen_texts or each_depth > MAXIMUM_UNWRAP_DEPTH:
|
|
346
356
|
continue
|
|
347
357
|
all_seen_texts.add(each_text)
|
|
348
|
-
all_command_segments =
|
|
349
|
-
each_segment
|
|
350
|
-
for each_segment, _following_operator in pipeline_segments_for_command(each_text)
|
|
351
|
-
]
|
|
358
|
+
all_command_segments = _command_segments(each_text)
|
|
352
359
|
all_parses.append((each_text, all_command_segments))
|
|
360
|
+
if maximum_texts is not None and len(all_parses) >= maximum_texts:
|
|
361
|
+
break
|
|
353
362
|
all_pending_texts.extend(
|
|
354
363
|
(each_inner_command, each_depth + 1)
|
|
355
364
|
for each_inner_command in _inner_commands(each_text, all_command_segments)
|
|
@@ -357,15 +366,18 @@ def _all_wrapped_command_parses(command: str) -> list[tuple[str, list[list[str]]
|
|
|
357
366
|
return all_parses
|
|
358
367
|
|
|
359
368
|
|
|
360
|
-
def all_wrapped_command_texts(command: str) -> list[str]:
|
|
369
|
+
def all_wrapped_command_texts(command: str, maximum_texts: int | None = None) -> list[str]:
|
|
361
370
|
"""Return the command plus each command string a wrapper or substitution inside it runs.
|
|
362
371
|
|
|
363
372
|
The segments come from the quote-aware pipeline parser, so the quoted
|
|
364
373
|
script in ``powershell -Command "git add -A; git push"`` stays whole until
|
|
365
374
|
its own turn. Nested wrappers and ``$(...)`` or backtick substitutions
|
|
366
|
-
unwrap in turn.
|
|
375
|
+
unwrap in turn. With ``maximum_texts`` set, the list stops at that many texts.
|
|
367
376
|
"""
|
|
368
|
-
return [
|
|
377
|
+
return [
|
|
378
|
+
each_text
|
|
379
|
+
for each_text, _all_segments in _all_wrapped_command_parses(command, maximum_texts)
|
|
380
|
+
]
|
|
369
381
|
|
|
370
382
|
|
|
371
383
|
def all_wrapped_command_segments(command: str) -> list[list[str]]:
|
|
@@ -29,6 +29,13 @@ def test_should_return_the_command_string_a_shell_wrapper_runs(
|
|
|
29
29
|
assert inner_command in all_command_texts
|
|
30
30
|
|
|
31
31
|
|
|
32
|
+
def test_should_stop_the_list_at_the_text_count_cap() -> None:
|
|
33
|
+
command = "bash -c \"pwsh -Command 'git push'\""
|
|
34
|
+
assert shell_command_wrappers.all_wrapped_command_texts(command, 1) == [command]
|
|
35
|
+
assert len(shell_command_wrappers.all_wrapped_command_texts(command, 2)) == 2
|
|
36
|
+
assert len(shell_command_wrappers.all_wrapped_command_texts(command)) > 2
|
|
37
|
+
|
|
38
|
+
|
|
32
39
|
def test_should_return_only_the_command_when_no_wrapper_runs() -> None:
|
|
33
40
|
assert shell_command_wrappers.all_wrapped_command_texts("git push") == ["git push"]
|
|
34
41
|
|
package/package.json
CHANGED
|
@@ -87,3 +87,16 @@ def test_the_pull_request_skill_points_its_decision_tree_at_the_delivery_section
|
|
|
87
87
|
assert "independent piece" not in decision_tree
|
|
88
88
|
assert "`gt create`" not in decision_tree
|
|
89
89
|
assert "a plain branch from the previous level" not in decision_tree
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def test_the_enforcement_section_names_the_note_and_keeps_it_non_blocking() -> None:
|
|
93
|
+
enforcement_text = GUIDE_PATH.read_text(encoding="utf-8").split("## Enforcement", 1)[1]
|
|
94
|
+
assert "hooks/advisory/pieces_per_level_note.py" in enforcement_text
|
|
95
|
+
assert "it never denies or exits non-zero" in enforcement_text
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def test_the_enforcement_section_points_to_the_feature_page_for_the_note_details() -> None:
|
|
99
|
+
enforcement_text = GUIDE_PATH.read_text(encoding="utf-8").split("## Enforcement", 1)[1]
|
|
100
|
+
assert "(../../hooks/features/session-context.md)" in enforcement_text
|
|
101
|
+
assert "wall-clock deadline" not in enforcement_text
|
|
102
|
+
assert "split the commit or the pull request" not in enforcement_text
|