claude-dev-env 8.109.7 → 8.110.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/.agents/agents/reference/pr-description-illustrative-voice.md +1 -0
- package/.agents/skills/pull-request/reference/body-sections.md +2 -2
- package/bin/install-pstack-plugin.mjs +80 -14
- package/bin/install-pstack-plugin.test.mjs +111 -40
- package/bin/install.mjs +23 -20
- package/bin/install.test.mjs +22 -17
- package/docs/rule-guides/proof-before-pull-request.md +1 -1
- package/hooks/blocking/body_flowchart.py +152 -0
- package/hooks/blocking/pr_lifecycle_skill_gate.py +5 -0
- package/hooks/blocking/pull_request_proof.py +67 -2
- package/hooks/blocking/reply_length_gate.py +17 -1
- package/hooks/blocking/test_body_flowchart.py +99 -0
- package/hooks/blocking/test_pr_lifecycle_skill_gate.py +6 -2
- package/hooks/blocking/test_pull_request_proof.py +98 -0
- package/hooks/blocking/test_reply_length_gate.py +120 -0
- package/hooks/features/conduct-gates.md +1 -1
- package/hooks/hooks_constants/body_flowchart_constants.py +18 -0
- package/hooks/hooks_constants/pull_request_proof_constants.py +8 -0
- package/hooks/hooks_constants/reply_length_gate_constants.py +1 -0
- package/hooks/hooks_constants/test_visual_reply_rules_constants.py +1 -0
- package/hooks/hooks_constants/visual_reply_rules_constants.py +19 -0
- package/hooks/test_visual_reply_rules.py +93 -0
- package/hooks/visual_reply_rules.py +61 -1
- package/package.json +1 -1
- package/rules/visual-reply-rules.json +5 -0
- package/scripts/durable_post_lint.py +15 -0
- package/scripts/durable_post_lint_config/config/constants.py +5 -0
- package/scripts/test_durable_post_lint.py +140 -1
|
@@ -1153,3 +1153,123 @@ def test_should_number_nested_violations_once_in_one_refusal(
|
|
|
1153
1153
|
assert all_numbered_lines[1].count("16 words") == 1
|
|
1154
1154
|
assert all_numbered_lines[2].count("16 words") == 1
|
|
1155
1155
|
assert reply_length_gate.EM_DASH_MESSAGE in all_numbered_lines[3]
|
|
1156
|
+
|
|
1157
|
+
|
|
1158
|
+
RESULTS_TABLE_REPLY = (
|
|
1159
|
+
"| Check | Result |\n"
|
|
1160
|
+
"|---|---|\n"
|
|
1161
|
+
"| Unit tests | 65 passed |\n"
|
|
1162
|
+
)
|
|
1163
|
+
RESULTS_LINE_REPLY = "The run shows 65 passed, 0 failed, and 3 skipped."
|
|
1164
|
+
RESULTS_PICTURE_DENIAL = "reports results with no picture attached"
|
|
1165
|
+
CHART_ATTACHMENT = {"kind": "file", "ref": "/mnt/project-files/tests/chart.svg"}
|
|
1166
|
+
|
|
1167
|
+
|
|
1168
|
+
def test_should_deny_a_results_table_with_no_picture_and_name_the_picture_rule(
|
|
1169
|
+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
1170
|
+
) -> None:
|
|
1171
|
+
exit_code, error_text = run_gate(
|
|
1172
|
+
monkeypatch, capsys, POST_TOOL_NAME, {"text": RESULTS_TABLE_REPLY}
|
|
1173
|
+
)
|
|
1174
|
+
assert exit_code == reply_length_gate.BLOCK_EXIT_CODE
|
|
1175
|
+
assert RESULTS_PICTURE_DENIAL in error_text
|
|
1176
|
+
|
|
1177
|
+
|
|
1178
|
+
def test_should_deny_three_figures_with_no_picture_and_name_the_picture_rule(
|
|
1179
|
+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
1180
|
+
) -> None:
|
|
1181
|
+
exit_code, error_text = run_gate(
|
|
1182
|
+
monkeypatch, capsys, POST_TOOL_NAME, {"text": RESULTS_LINE_REPLY}
|
|
1183
|
+
)
|
|
1184
|
+
assert exit_code == reply_length_gate.BLOCK_EXIT_CODE
|
|
1185
|
+
assert RESULTS_PICTURE_DENIAL in error_text
|
|
1186
|
+
|
|
1187
|
+
|
|
1188
|
+
def test_should_allow_the_same_results_with_a_chart_attached(
|
|
1189
|
+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
1190
|
+
) -> None:
|
|
1191
|
+
exit_code, error_text = run_gate(
|
|
1192
|
+
monkeypatch,
|
|
1193
|
+
capsys,
|
|
1194
|
+
POST_TOOL_NAME,
|
|
1195
|
+
{"text": RESULTS_LINE_REPLY, "attached_outputs": [CHART_ATTACHMENT]},
|
|
1196
|
+
)
|
|
1197
|
+
assert (exit_code, error_text) == (0, "")
|
|
1198
|
+
|
|
1199
|
+
|
|
1200
|
+
def test_should_allow_the_same_results_with_a_markdown_picture(
|
|
1201
|
+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
1202
|
+
) -> None:
|
|
1203
|
+
exit_code, error_text = run_gate(
|
|
1204
|
+
monkeypatch,
|
|
1205
|
+
capsys,
|
|
1206
|
+
POST_TOOL_NAME,
|
|
1207
|
+
{"text": f"{RESULTS_LINE_REPLY}\n\n"},
|
|
1208
|
+
)
|
|
1209
|
+
assert (exit_code, error_text) == (0, "")
|
|
1210
|
+
|
|
1211
|
+
|
|
1212
|
+
def test_should_allow_an_edit_of_a_results_message_because_the_edit_tool_attaches_nothing(
|
|
1213
|
+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
1214
|
+
) -> None:
|
|
1215
|
+
exit_code, error_text = run_gate(
|
|
1216
|
+
monkeypatch, capsys, UPDATE_TOOL_NAME, {"text": RESULTS_LINE_REPLY}
|
|
1217
|
+
)
|
|
1218
|
+
assert (exit_code, error_text) == (0, "")
|
|
1219
|
+
|
|
1220
|
+
|
|
1221
|
+
def test_should_allow_results_with_a_published_page_attached(
|
|
1222
|
+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
1223
|
+
) -> None:
|
|
1224
|
+
exit_code, error_text = run_gate(
|
|
1225
|
+
monkeypatch,
|
|
1226
|
+
capsys,
|
|
1227
|
+
POST_TOOL_NAME,
|
|
1228
|
+
{
|
|
1229
|
+
"text": RESULTS_LINE_REPLY,
|
|
1230
|
+
"attached_outputs": [{"kind": "frame", "ref": "https://claude.ai/artifact/dashboard"}],
|
|
1231
|
+
},
|
|
1232
|
+
)
|
|
1233
|
+
assert (exit_code, error_text) == (0, "")
|
|
1234
|
+
|
|
1235
|
+
|
|
1236
|
+
def test_should_deny_results_whose_only_attachment_is_not_a_picture(
|
|
1237
|
+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
1238
|
+
) -> None:
|
|
1239
|
+
exit_code, error_text = run_gate(
|
|
1240
|
+
monkeypatch,
|
|
1241
|
+
capsys,
|
|
1242
|
+
POST_TOOL_NAME,
|
|
1243
|
+
{
|
|
1244
|
+
"text": RESULTS_LINE_REPLY,
|
|
1245
|
+
"attached_outputs": [{"kind": "file", "ref": "/mnt/project-files/tests/results.md"}],
|
|
1246
|
+
},
|
|
1247
|
+
)
|
|
1248
|
+
assert exit_code == reply_length_gate.BLOCK_EXIT_CODE
|
|
1249
|
+
assert RESULTS_PICTURE_DENIAL in error_text
|
|
1250
|
+
|
|
1251
|
+
|
|
1252
|
+
def test_should_allow_two_figures_with_no_picture(
|
|
1253
|
+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
1254
|
+
) -> None:
|
|
1255
|
+
exit_code, error_text = run_gate(
|
|
1256
|
+
monkeypatch, capsys, POST_TOOL_NAME, {"text": "The run shows 65 passed and 3 skipped."}
|
|
1257
|
+
)
|
|
1258
|
+
assert (exit_code, error_text) == (0, "")
|
|
1259
|
+
|
|
1260
|
+
|
|
1261
|
+
def test_should_not_count_figures_in_code_spans_or_pull_request_links(
|
|
1262
|
+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
1263
|
+
) -> None:
|
|
1264
|
+
exit_code, error_text = run_gate(
|
|
1265
|
+
monkeypatch,
|
|
1266
|
+
capsys,
|
|
1267
|
+
POST_TOOL_NAME,
|
|
1268
|
+
{
|
|
1269
|
+
"text": (
|
|
1270
|
+
"Ran `pytest -k 1` and `pytest -k 2` and `pytest -k 3`, "
|
|
1271
|
+
"see [pull request](https://github.com/jl-cmd-projects/claude-dev-env/pull/2224)."
|
|
1272
|
+
)
|
|
1273
|
+
},
|
|
1274
|
+
)
|
|
1275
|
+
assert (exit_code, error_text) == (0, "")
|
|
@@ -4,7 +4,7 @@ This family stops a chat reply, edited message, or tool call when its payload br
|
|
|
4
4
|
|
|
5
5
|
## Checks
|
|
6
6
|
|
|
7
|
-
- `blocking/reply_length_gate.py` caps chat reply length, denies a configured banned word, requires a readable link when the text names a pull request number, and denies a causal claim in a reply that cites no code span, output block, or link. It denies a sentence that guesses, estimates, hedges a duration, or admits a skipped check, such as "I didn't confirm this one." It denies a cited Actions run, pull request, or run, job, or check id that no successful tool result in the transcript shows; a subagent's report is the result of its Agent call. A question card from `AskUserQuestion` gets the banned word check and `unvalidated_claim_violation`, like a decision card. One refusal names every broken rule and every offending sentence, numbered, and ends with "Fix every item above in your next write." With visual reply mode on, it also runs the checks in `visual_reply_rules.py` from the rule list in `rules/visual-reply-rules.json`: no abbreviation or tracker number outside a link, a widget or page before a reply of more than one sentence, and no anchor link inside widget code. The mode is off by default; `~/.claude/visual-reply-mode.json` with `{"enabled": true}` turns the mode checks on.
|
|
7
|
+
- `blocking/reply_length_gate.py` caps chat reply length, denies a configured banned word, requires a readable link when the text names a pull request number, and denies a causal claim in a reply that cites no code span, output block, or link. It denies a sentence that guesses, estimates, hedges a duration, or admits a skipped check, such as "I didn't confirm this one." It denies a cited Actions run, pull request, or run, job, or check id that no successful tool result in the transcript shows; a subagent's report is the result of its Agent call. A question card from `AskUserQuestion` gets the banned word check and `unvalidated_claim_violation`, like a decision card. One refusal names every broken rule and every offending sentence, numbered, and ends with "Fix every item above in your next write." With visual reply mode on, it also runs the checks in `visual_reply_rules.py` from the rule list in `rules/visual-reply-rules.json`: no abbreviation or tracker number outside a link, a widget or page before a reply of more than one sentence, and no anchor link inside widget code. The mode is off by default; `~/.claude/visual-reply-mode.json` with `{"enabled": true}` turns the mode checks on. The results-picture check runs with the mode off too. A reply with a markdown table, or more than two figures, needs a picture: an attached `.svg`, `.png`, `.jpg`, `.jpeg`, `.gif`, or `.webp` file, an attached `frame` output such as a published page, or a markdown picture outside code. The check reads the attached name only, so it does not confirm that the file exists. It skips an edit of a posted message, because the edit tool attaches nothing, and the closing reply of a turn, which `blocking/final_reply_gate.py` does not run it on.
|
|
8
8
|
- `blocking/final_reply_gate.py` applies the banned words, `unvalidated_claim_violation`, and `unseen_citation_violation` from the reply gate to the reply a session ends its turn with. Its `windows_path_violation` blocks a path the terminal would render without one of its backslashes.
|
|
9
9
|
- `blocking/open_tasks_stop_gate.py` holds the end of a turn once when the prompt that started it asks for work, the turn ran a work tool, and the turn made no tracker call: TaskCreate, TaskUpdate, TodoWrite, the Codex `update_plan`, or the desktop `mcp__ccd_turn__update_plan`. A work tool is any tool but a tracker call, the session title tool, `AskUserQuestion`, a hearthbot decision card, Codex `request_user_input`, `ToolSearch`, `TaskList`, or `TaskGet`. It never reads the reply text. `open_task_asks.is_ask` decides whether a prompt asks for work: a question-only prompt, an acknowledgement such as `thanks!`, an empty prompt, a prompt of only `<system-reminder>` blocks, and an envelope such as `<agent-message>` or `<task-notification>` do not. `blocking/open_tasks_transcript.py` replays the transcript for it: the turn's prompt, its tool calls, and the task list. `session_task_items` merges the task store with the transcript items whose subject the store does not hold, for the session title gate.
|
|
10
10
|
- `session/tracking_nudge.py` adds one `additionalContext` note to a prompt that asks for work. The note asks for a task list item. When the title shows the red flag or the check mark, it also asks for the hourglass before other work. It never blocks.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import re
|
|
2
|
+
|
|
3
|
+
FENCE_OPEN_PATTERN: re.Pattern[str] = re.compile(r"^[\s>]*(`{3,}|~{3,})[ \t]*(\S*)(.*)$")
|
|
4
|
+
FENCE_PREFIX_CHARACTERS = " \t>"
|
|
5
|
+
FENCE_MARKER_GROUP = 1
|
|
6
|
+
INFO_STRING_GROUP = 2
|
|
7
|
+
INFO_TAIL_GROUP = 3
|
|
8
|
+
BACKTICK_FENCE_CHARACTER = "`"
|
|
9
|
+
FRONT_MATTER_DELIMITER = "---"
|
|
10
|
+
MERMAID_INFO_STRING = "mermaid"
|
|
11
|
+
FLOWCHART_FIRST_LINE_PATTERN: re.Pattern[str] = re.compile(r"^flowchart\b")
|
|
12
|
+
MERMAID_COMMENT_PREFIX = "%%"
|
|
13
|
+
TRAILING_COMMENT_PATTERN: re.Pattern[str] = re.compile(r"%%.*$")
|
|
14
|
+
EDGE_LABEL_PATTERN: re.Pattern[str] = re.compile(r"\|[^|]*\|")
|
|
15
|
+
NODE_TEXT_PATTERN: re.Pattern[str] = re.compile(r'"[^"]*"|\[[^\]]*\]|\([^)]*\)|\{[^}]*\}')
|
|
16
|
+
FLOWCHART_EDGE_PATTERN: re.Pattern[str] = re.compile(
|
|
17
|
+
r"\S.*?(?:<?-->|<?==+>|-\.+->|-\.+-|---+|===+|--[ox])\s*\S"
|
|
18
|
+
)
|
|
@@ -212,3 +212,11 @@ GATE_EDIT_BEFORE_ROUTE_REASON = (
|
|
|
212
212
|
)
|
|
213
213
|
WINDOWS_PATH_SEPARATOR = "\\"
|
|
214
214
|
POSIX_PATH_SEPARATOR = "/"
|
|
215
|
+
WHAT_THIS_DOES_HEADING_PATTERN = r"^(#{1,6})[ \t]+what this does[ \t]*#*[ \t]*$"
|
|
216
|
+
MISSING_FLOWCHART_REASON = (
|
|
217
|
+
"This pull request body has no flowchart under its 'What this does' heading. Draw"
|
|
218
|
+
" the flow before the change and after it as a fenced mermaid block whose first line"
|
|
219
|
+
" starts with 'flowchart' and that holds at least two nodes joined by an arrow."
|
|
220
|
+
" Keep the chart under 'What this does', put plain sentences around it, and draw a"
|
|
221
|
+
" short chart for a one-step change."
|
|
222
|
+
)
|
|
@@ -7,6 +7,7 @@ MAXIMUM_WORDS_PER_SENTENCE = 15
|
|
|
7
7
|
ALL_CHECKED_TOOL_NAMES = frozenset(
|
|
8
8
|
{"mcp__hearthbot__reply", "mcp__hearthbot__post_message", "mcp__hearthbot__update_message"}
|
|
9
9
|
)
|
|
10
|
+
ALL_EDIT_TOOL_NAMES = frozenset({"mcp__hearthbot__update_message"})
|
|
10
11
|
DECISION_CARD_TOOL_NAME = "mcp__hearthbot__ask_decision"
|
|
11
12
|
CARD_TEXT_SEPARATOR = "\n"
|
|
12
13
|
ALL_DECISION_CARD_PROSE_KEYS = ("question", "context")
|
|
@@ -27,6 +27,7 @@ def test_rule_key_constants_name_rules_in_the_shipped_rule_list() -> None:
|
|
|
27
27
|
constants.ABBREVIATIONS_RULE_KEY,
|
|
28
28
|
constants.ONE_ITEM_RULE_KEY,
|
|
29
29
|
constants.FLOWCHART_RULE_KEY,
|
|
30
|
+
constants.RESULTS_PICTURE_RULE_KEY,
|
|
30
31
|
} <= all_shipped_keys
|
|
31
32
|
assert constants.ALLOWED_CAPITALIZED_WORDS_KEY in rules_document
|
|
32
33
|
assert constants.LOWERCASE_ABBREVIATIONS_KEY in rules_document
|
|
@@ -20,6 +20,7 @@ MODE_SWITCH_ENABLED_KEY = "enabled"
|
|
|
20
20
|
NO_PICTURE_RULE_KEY = "no_picture"
|
|
21
21
|
ABBREVIATIONS_RULE_KEY = "abbreviations"
|
|
22
22
|
ONE_ITEM_RULE_KEY = "one_item"
|
|
23
|
+
RESULTS_PICTURE_RULE_KEY = "results_picture"
|
|
23
24
|
|
|
24
25
|
WIDGET_TOOL_NAME_SUFFIX = "__post_widget"
|
|
25
26
|
ARTIFACT_TOOL_NAME = "Artifact"
|
|
@@ -46,6 +47,23 @@ FLOWCHART_DIAMOND_PATTERN = re.compile(
|
|
|
46
47
|
r"<polygon\b|<path\b[^>]*\bd=[\"']M[^\"']*L[^\"']*L[^\"']*L[^\"']*Z[\"']", re.IGNORECASE
|
|
47
48
|
)
|
|
48
49
|
|
|
50
|
+
ATTACHED_OUTPUTS_KEY = "attached_outputs"
|
|
51
|
+
OUTPUT_KIND_KEY = "kind"
|
|
52
|
+
OUTPUT_FILE_KIND = "file"
|
|
53
|
+
OUTPUT_FRAME_KIND = "frame"
|
|
54
|
+
OUTPUT_REF_KEY = "ref"
|
|
55
|
+
ALL_PICTURE_SUFFIXES = (".svg", ".png", ".jpg", ".jpeg", ".gif", ".webp")
|
|
56
|
+
MAXIMUM_FIGURES_WITHOUT_PICTURE = 2
|
|
57
|
+
TABLE_SEPARATOR_PATTERN = re.compile(
|
|
58
|
+
r"^\s*\|?\s*:?-{3,}:?\s*\|\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)*\|?\s*$", re.MULTILINE
|
|
59
|
+
)
|
|
60
|
+
FIGURE_PATTERN = re.compile(r"(?<![\w.#/:])(?<!\w-)(?!\d{7})\d+(?:[.,]\d+)*(?:%|x\b)?(?![\w:-])")
|
|
61
|
+
LIST_NUMBER_PATTERN = re.compile(r"^\s*\d+[.)](?=\s)", re.MULTILINE)
|
|
62
|
+
MARKDOWN_PICTURE_PATTERN = re.compile(
|
|
63
|
+
r"!\[[^\]]*\]\([^)\s]+\.(?:svg|png|jpe?g|gif|webp)(?:\?[^)\s]*)?(?:\s+\"[^\"]*\")?\)",
|
|
64
|
+
re.IGNORECASE,
|
|
65
|
+
)
|
|
66
|
+
|
|
49
67
|
TRANSCRIPT_ENCODING = "utf-8"
|
|
50
68
|
ENTRY_TYPE_KEY = "type"
|
|
51
69
|
USER_ENTRY_TYPE = "user"
|
|
@@ -74,3 +92,4 @@ WIDGET_ANCHOR_MESSAGE = (
|
|
|
74
92
|
"A link sits inside the widget code, and a widget link does not open in the Claude app."
|
|
75
93
|
" Remove the anchor and put the page link in the reply text."
|
|
76
94
|
)
|
|
95
|
+
RESULTS_PICTURE_MESSAGE = "This reply reports results with no picture attached. {reminder}"
|
|
@@ -11,9 +11,12 @@ if _hooks_directory not in sys.path:
|
|
|
11
11
|
from hooks_constants.visual_reply_rules_constants import RULES_FILE_PATH
|
|
12
12
|
from visual_reply_rules import (
|
|
13
13
|
abbreviation_violation,
|
|
14
|
+
attaches_picture,
|
|
14
15
|
load_rules,
|
|
15
16
|
mode_enabled,
|
|
16
17
|
replies_sent_this_turn,
|
|
18
|
+
reports_results,
|
|
19
|
+
results_picture_violation,
|
|
17
20
|
second_reply_violation,
|
|
18
21
|
successful_result_text,
|
|
19
22
|
visual_shown_this_turn,
|
|
@@ -51,6 +54,28 @@ def test_load_rules_returns_none_when_a_needed_rule_is_missing(tmp_path: Path) -
|
|
|
51
54
|
assert load_rules(rules_path) is None
|
|
52
55
|
|
|
53
56
|
|
|
57
|
+
def test_load_rules_returns_none_when_only_the_results_picture_rule_is_missing(tmp_path: Path) -> None:
|
|
58
|
+
all_other_keys = ("one_item", "no_picture", "abbreviations")
|
|
59
|
+
rules_path = tmp_path / "rules.json"
|
|
60
|
+
rules_path.write_text(
|
|
61
|
+
json.dumps({"rules": [{"key": each, "label": "Label", "reminder": "Remind."} for each in all_other_keys]}),
|
|
62
|
+
encoding="utf-8",
|
|
63
|
+
)
|
|
64
|
+
assert load_rules(rules_path) is None
|
|
65
|
+
rules_path.write_text(
|
|
66
|
+
json.dumps(
|
|
67
|
+
{
|
|
68
|
+
"rules": [
|
|
69
|
+
{"key": each, "label": "Label", "reminder": "Remind."}
|
|
70
|
+
for each in (*all_other_keys, "results_picture")
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
),
|
|
74
|
+
encoding="utf-8",
|
|
75
|
+
)
|
|
76
|
+
assert load_rules(rules_path) is not None
|
|
77
|
+
|
|
78
|
+
|
|
54
79
|
def test_mode_is_off_without_a_switch_file(tmp_path: Path) -> None:
|
|
55
80
|
assert mode_enabled(tmp_path) is False
|
|
56
81
|
|
|
@@ -240,3 +265,71 @@ def test_successful_result_text_joins_only_results_without_an_error(tmp_path: Pa
|
|
|
240
265
|
transcript_path.write_text("\n".join(json.dumps(each) for each in all_entries), encoding="utf-8")
|
|
241
266
|
assert successful_result_text(str(transcript_path)) == "run 222 ok\nrun 333 ok"
|
|
242
267
|
assert successful_result_text(str(tmp_path / "missing.jsonl")) is None
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def test_reports_results_flags_a_markdown_table_and_three_figures() -> None:
|
|
271
|
+
assert reports_results("| Check | Result |\n|---|---|\n| Unit tests | passed |")
|
|
272
|
+
assert reports_results("The run shows 65 passed, 0 failed, and 3 skipped.")
|
|
273
|
+
assert not reports_results("The run shows 65 passed and 3 skipped.")
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def test_reports_results_counts_a_multiplier_such_as_2_5x_as_a_figure() -> None:
|
|
277
|
+
assert reports_results("Latency fell 2.5x and throughput rose 3x and errors fell 4x.")
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def test_reports_results_counts_no_figure_in_a_long_run_or_job_identifier() -> None:
|
|
281
|
+
assert not reports_results("Run 24011273, job 24011274 and check 24011275 are green.")
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
def test_reports_results_counts_a_negative_figure_as_a_figure() -> None:
|
|
285
|
+
assert reports_results("Deltas were -2, -5 and -7 this week.")
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def test_reports_results_counts_no_figure_in_a_date_or_a_pull_request_number() -> None:
|
|
289
|
+
assert not reports_results("Shipped on 2026-10-29 in #2224.")
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
def test_reports_results_counts_no_figure_in_a_clock_time_or_a_list_number() -> None:
|
|
293
|
+
assert not reports_results("The run started at 10:30 and ended at 11:45.")
|
|
294
|
+
assert not reports_results("1. Checked the hook.\n2. Checked the rule.\n3. Checked the test.")
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def test_reports_results_flags_a_markdown_table_written_without_leading_pipes() -> None:
|
|
298
|
+
assert reports_results("Check | Result\n--- | ---\nUnit tests | passed")
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
def test_attaches_picture_ignores_a_picture_shown_only_inside_a_code_fence() -> None:
|
|
302
|
+
assert not attaches_picture("Example:\n```\n\n```\nDone.", {})
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def test_attaches_picture_accepts_a_markdown_picture_with_a_title_or_a_query_string() -> None:
|
|
306
|
+
assert attaches_picture('Results.\n\n', {})
|
|
307
|
+
assert attaches_picture("Results.\n\n", {})
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
def test_attaches_picture_accepts_an_image_file_or_a_markdown_picture_only() -> None:
|
|
311
|
+
assert attaches_picture("Results.", {"attached_outputs": [{"kind": "file", "ref": "/mnt/chart.svg"}]})
|
|
312
|
+
assert attaches_picture("", {})
|
|
313
|
+
assert not attaches_picture("Results.", {"attached_outputs": [{"kind": "file", "ref": "results.md"}]})
|
|
314
|
+
assert not attaches_picture("Results.", {"attached_outputs": [{"kind": "link", "ref": "https://x.example/c.png"}]})
|
|
315
|
+
assert not attaches_picture("Results.", {})
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def test_attaches_picture_accepts_a_published_frame_of_any_name() -> None:
|
|
319
|
+
assert attaches_picture(
|
|
320
|
+
"Results.", {"attached_outputs": [{"kind": "frame", "ref": "https://claude.ai/artifact/dashboard"}]}
|
|
321
|
+
)
|
|
322
|
+
assert not attaches_picture(
|
|
323
|
+
"Results.", {"attached_outputs": [{"kind": "other", "ref": "https://claude.ai/artifact/dashboard"}]}
|
|
324
|
+
)
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
def test_results_picture_violation_names_the_picture_rule_and_allows_an_attached_chart() -> None:
|
|
328
|
+
assert SHIPPED_RULES is not None
|
|
329
|
+
results_text = "The run shows 65 passed, 0 failed, and 3 skipped."
|
|
330
|
+
violation = results_picture_violation(results_text, results_text, {}, SHIPPED_RULES)
|
|
331
|
+
assert violation is not None
|
|
332
|
+
assert "reports results with no picture attached" in violation
|
|
333
|
+
chart_input = {"attached_outputs": [{"kind": "file", "ref": "chart.svg"}]}
|
|
334
|
+
assert results_picture_violation(results_text, results_text, chart_input, SHIPPED_RULES) is None
|
|
335
|
+
assert results_picture_violation(results_text, results_text, {}, None) is None
|
|
@@ -71,7 +71,21 @@ from hooks_constants.visual_reply_rules_constants import (
|
|
|
71
71
|
WIDGET_INPUT_KEY,
|
|
72
72
|
WIDGET_ANCHOR_PATTERN,
|
|
73
73
|
WIDGET_TOOL_NAME_SUFFIX,
|
|
74
|
+
ALL_PICTURE_SUFFIXES,
|
|
75
|
+
ATTACHED_OUTPUTS_KEY,
|
|
76
|
+
FIGURE_PATTERN,
|
|
77
|
+
LIST_NUMBER_PATTERN,
|
|
78
|
+
MARKDOWN_PICTURE_PATTERN,
|
|
79
|
+
MAXIMUM_FIGURES_WITHOUT_PICTURE,
|
|
80
|
+
OUTPUT_FILE_KIND,
|
|
81
|
+
OUTPUT_FRAME_KIND,
|
|
82
|
+
OUTPUT_KIND_KEY,
|
|
83
|
+
OUTPUT_REF_KEY,
|
|
84
|
+
RESULTS_PICTURE_MESSAGE,
|
|
85
|
+
RESULTS_PICTURE_RULE_KEY,
|
|
86
|
+
TABLE_SEPARATOR_PATTERN,
|
|
74
87
|
)
|
|
88
|
+
from hooks_constants.reply_length_gate_constants import FENCED_BLOCK_PATTERN, INLINE_CODE_PATTERN
|
|
75
89
|
|
|
76
90
|
|
|
77
91
|
@dataclass(frozen=True)
|
|
@@ -118,7 +132,12 @@ def load_rules(rules_path: Path = RULES_FILE_PATH) -> VisualReplyRules | None:
|
|
|
118
132
|
if isinstance(each, dict)
|
|
119
133
|
and all(field in each for field in (RULE_KEY_FIELD, RULE_LABEL_FIELD, RULE_REMINDER_FIELD))
|
|
120
134
|
)
|
|
121
|
-
all_needed_keys = {
|
|
135
|
+
all_needed_keys = {
|
|
136
|
+
ONE_ITEM_RULE_KEY,
|
|
137
|
+
NO_PICTURE_RULE_KEY,
|
|
138
|
+
ABBREVIATIONS_RULE_KEY,
|
|
139
|
+
RESULTS_PICTURE_RULE_KEY,
|
|
140
|
+
}
|
|
122
141
|
if not all_needed_keys <= {each.key for each in all_rules}:
|
|
123
142
|
return None
|
|
124
143
|
return VisualReplyRules(
|
|
@@ -352,3 +371,44 @@ def visual_violation(
|
|
|
352
371
|
return NO_VISUAL_MESSAGE.format(
|
|
353
372
|
sentence_count=sentence_count, reminder=rules.reminder(NO_PICTURE_RULE_KEY)
|
|
354
373
|
)
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
def reports_results(prose_text: str) -> bool:
|
|
377
|
+
"""Return True when the prose holds a markdown table or more figures than a reply may state without a picture.
|
|
378
|
+
|
|
379
|
+
The caller removes code spans, links, and URLs first, so figures inside them do not count.
|
|
380
|
+
"""
|
|
381
|
+
if TABLE_SEPARATOR_PATTERN.search(prose_text):
|
|
382
|
+
return True
|
|
383
|
+
all_figures = FIGURE_PATTERN.findall(LIST_NUMBER_PATTERN.sub(" ", prose_text))
|
|
384
|
+
return len(all_figures) > MAXIMUM_FIGURES_WITHOUT_PICTURE
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
def attaches_picture(reply_text: str, all_tool_input: dict[str, object]) -> bool:
|
|
388
|
+
"""Return True when the call attaches an image file or a published page, or embeds a markdown picture outside code."""
|
|
389
|
+
all_attached_outputs = all_tool_input.get(ATTACHED_OUTPUTS_KEY)
|
|
390
|
+
has_attached_picture = isinstance(all_attached_outputs, list) and any(
|
|
391
|
+
isinstance(each_output, dict)
|
|
392
|
+
and (
|
|
393
|
+
each_output.get(OUTPUT_KIND_KEY) == OUTPUT_FRAME_KIND
|
|
394
|
+
or (
|
|
395
|
+
each_output.get(OUTPUT_KIND_KEY) == OUTPUT_FILE_KIND
|
|
396
|
+
and str(each_output.get(OUTPUT_REF_KEY, "")).casefold().endswith(ALL_PICTURE_SUFFIXES)
|
|
397
|
+
)
|
|
398
|
+
)
|
|
399
|
+
for each_output in all_attached_outputs
|
|
400
|
+
)
|
|
401
|
+
without_code = INLINE_CODE_PATTERN.sub(" ", FENCED_BLOCK_PATTERN.sub(" ", reply_text))
|
|
402
|
+
return has_attached_picture or MARKDOWN_PICTURE_PATTERN.search(without_code) is not None
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
def results_picture_violation(
|
|
406
|
+
prose_text: str,
|
|
407
|
+
reply_text: str,
|
|
408
|
+
all_tool_input: dict[str, object],
|
|
409
|
+
rules: VisualReplyRules | None,
|
|
410
|
+
) -> str | None:
|
|
411
|
+
"""Return the deny reason for a reply that reports results with no picture attached, or None."""
|
|
412
|
+
if rules is None or not reports_results(prose_text) or attaches_picture(reply_text, all_tool_input):
|
|
413
|
+
return None
|
|
414
|
+
return RESULTS_PICTURE_MESSAGE.format(reminder=rules.reminder(RESULTS_PICTURE_RULE_KEY))
|
package/package.json
CHANGED
|
@@ -34,6 +34,11 @@
|
|
|
34
34
|
"key": "use_flowchart",
|
|
35
35
|
"label": "Use the flowchart",
|
|
36
36
|
"reminder": "Show the status as the status flowchart from docs/templates/artifact-page/status-flowchart.html: done steps, yes-or-no checks, stuck steps with recheck loops, and the next step, each opening its detail on click, unless the person asked for another shape."
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"key": "results_picture",
|
|
40
|
+
"label": "Results with no picture",
|
|
41
|
+
"reminder": "Show results in one chart rendered with the pele renderer, saved as an SVG or PNG file and passed in attached_outputs, with every label and number on it."
|
|
37
42
|
}
|
|
38
43
|
],
|
|
39
44
|
"allowed_capitalized_words": [
|
|
@@ -42,6 +42,8 @@ from durable_post_lint_config.config.constants import (
|
|
|
42
42
|
INVALID_ACTION_MESSAGE,
|
|
43
43
|
INVALID_TITLE_CODE,
|
|
44
44
|
INVALID_TITLE_MESSAGE,
|
|
45
|
+
MISSING_FLOWCHART_CODE,
|
|
46
|
+
MISSING_FLOWCHART_MESSAGE,
|
|
45
47
|
MISSING_HEADING_CODE,
|
|
46
48
|
MISSING_HEADING_MESSAGE_TEMPLATE,
|
|
47
49
|
PATH_ANCHOR_CHARACTER,
|
|
@@ -64,10 +66,12 @@ if _hooks_directory not in sys.path:
|
|
|
64
66
|
sys.path.insert(0, _hooks_directory)
|
|
65
67
|
|
|
66
68
|
from blocking.pull_request_proof import (
|
|
69
|
+
has_flowchart_under_what_this_does,
|
|
67
70
|
checkout_is_for,
|
|
68
71
|
missing_eval_section_reason,
|
|
69
72
|
missing_existing_work_reason,
|
|
70
73
|
missing_proof_reason,
|
|
74
|
+
what_this_does_section,
|
|
71
75
|
)
|
|
72
76
|
from blocking.reply_length_gate import comment_length_violation
|
|
73
77
|
|
|
@@ -160,6 +164,14 @@ def _description_heading_findings(body_text: str) -> list[DurablePostFinding]:
|
|
|
160
164
|
]
|
|
161
165
|
|
|
162
166
|
|
|
167
|
+
def _description_flowchart_findings(body_text: str) -> list[DurablePostFinding]:
|
|
168
|
+
if what_this_does_section(body_text) is None or has_flowchart_under_what_this_does(body_text):
|
|
169
|
+
return []
|
|
170
|
+
return [
|
|
171
|
+
DurablePostFinding(
|
|
172
|
+
code=MISSING_FLOWCHART_CODE, message=MISSING_FLOWCHART_MESSAGE
|
|
173
|
+
)
|
|
174
|
+
]
|
|
163
175
|
def _checkout_directory(head_branch: str | None, repository: str | None) -> str:
|
|
164
176
|
current_directory = str(Path.cwd())
|
|
165
177
|
if head_branch and repository and checkout_is_for(current_directory, repository):
|
|
@@ -292,6 +304,9 @@ def _body_findings(
|
|
|
292
304
|
all_findings.extend(
|
|
293
305
|
_pull_request_proof_findings(title, body_text, head_branch, repository)
|
|
294
306
|
)
|
|
307
|
+
if action in (ACTION_PR_CREATE, ACTION_PR_EDIT):
|
|
308
|
+
all_findings.extend(_description_flowchart_findings(body_text)
|
|
309
|
+
)
|
|
295
310
|
if action == ACTION_GITHUB_MCP_COMMENT:
|
|
296
311
|
all_findings.extend(_comment_length_findings(body_text))
|
|
297
312
|
all_findings.extend(_contrast_framing_findings(body_text))
|
|
@@ -88,6 +88,11 @@ INVALID_TITLE_MESSAGE = (
|
|
|
88
88
|
)
|
|
89
89
|
MISSING_HEADING_CODE = "missing-pr-description-heading"
|
|
90
90
|
MISSING_HEADING_MESSAGE_TEMPLATE = "body is missing required heading: {heading}"
|
|
91
|
+
MISSING_FLOWCHART_CODE = "missing-pr-description-flowchart"
|
|
92
|
+
MISSING_FLOWCHART_MESSAGE = (
|
|
93
|
+
"## What this does needs a mermaid flowchart that draws the flow before "
|
|
94
|
+
"and after the change"
|
|
95
|
+
)
|
|
91
96
|
TITLE_NOT_ALLOWED_MESSAGE = "this action does not accept a title"
|
|
92
97
|
TITLE_REQUIRED_MESSAGE = "pr-create requires a title"
|
|
93
98
|
VOLATILE_PATH_CODE = "volatile-local-path"
|
|
@@ -18,10 +18,16 @@ from hooks_constants.pull_request_proof_constants import (
|
|
|
18
18
|
)
|
|
19
19
|
|
|
20
20
|
SCRIPT_PATH = Path(__file__).resolve().parent / "durable_post_lint.py"
|
|
21
|
-
|
|
21
|
+
FLOWCHART_BLOCK = """```mermaid
|
|
22
|
+
flowchart LR
|
|
23
|
+
before[Text-only body] --> after[Body with a flowchart]
|
|
24
|
+
```"""
|
|
25
|
+
VALID_PR_BODY = f"""## What this does
|
|
22
26
|
|
|
23
27
|
What this does text.
|
|
24
28
|
|
|
29
|
+
{FLOWCHART_BLOCK}
|
|
30
|
+
|
|
25
31
|
## Scope
|
|
26
32
|
|
|
27
33
|
Scope text.
|
|
@@ -205,6 +211,139 @@ def test_pr_body_reports_each_missing_heading(missing_heading: str) -> None:
|
|
|
205
211
|
]
|
|
206
212
|
|
|
207
213
|
|
|
214
|
+
def _flowchart_codes(action: str, body_text: str) -> list[str]:
|
|
215
|
+
return [
|
|
216
|
+
each_finding.code
|
|
217
|
+
for each_finding in durable_post_lint.lint_durable_post(
|
|
218
|
+
action=action,
|
|
219
|
+
title="feat: add durable post linting",
|
|
220
|
+
body_text=body_text,
|
|
221
|
+
)
|
|
222
|
+
if each_finding.code == durable_post_lint.MISSING_FLOWCHART_CODE
|
|
223
|
+
]
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def should_accept_a_create_body_with_a_flowchart_under_what_this_does() -> None:
|
|
227
|
+
assert _flowchart_codes("pr-create", VALID_PR_BODY) == []
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def should_report_a_create_body_with_no_flowchart() -> None:
|
|
231
|
+
body_text = VALID_PR_BODY.replace(FLOWCHART_BLOCK, "")
|
|
232
|
+
all_findings = durable_post_lint.lint_durable_post(
|
|
233
|
+
action="pr-create",
|
|
234
|
+
title="feat: add durable post linting",
|
|
235
|
+
body_text=body_text,
|
|
236
|
+
)
|
|
237
|
+
assert [each_finding.message for each_finding in all_findings] == [
|
|
238
|
+
durable_post_lint.MISSING_FLOWCHART_MESSAGE
|
|
239
|
+
]
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def should_report_a_flowchart_placed_under_another_heading() -> None:
|
|
243
|
+
body_text = VALID_PR_BODY.replace(FLOWCHART_BLOCK, "").replace(
|
|
244
|
+
"Scope text.", f"Scope text.\n\n{FLOWCHART_BLOCK}"
|
|
245
|
+
)
|
|
246
|
+
assert _flowchart_codes("pr-create", body_text) == [
|
|
247
|
+
durable_post_lint.MISSING_FLOWCHART_CODE
|
|
248
|
+
]
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
@pytest.mark.parametrize(
|
|
252
|
+
"diagram_opening",
|
|
253
|
+
["sequenceDiagram", "graph LR", "classDiagram", "pie title Pets"],
|
|
254
|
+
)
|
|
255
|
+
def should_report_a_mermaid_block_of_another_diagram_type(
|
|
256
|
+
diagram_opening: str,
|
|
257
|
+
) -> None:
|
|
258
|
+
other_block = f"```mermaid\n{diagram_opening}\n a --> b\n```"
|
|
259
|
+
body_text = VALID_PR_BODY.replace(FLOWCHART_BLOCK, other_block)
|
|
260
|
+
assert _flowchart_codes("pr-create", body_text) == [
|
|
261
|
+
durable_post_lint.MISSING_FLOWCHART_CODE
|
|
262
|
+
]
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def should_report_a_flowchart_fenced_under_another_language() -> None:
|
|
266
|
+
body_text = VALID_PR_BODY.replace("```mermaid", "```text")
|
|
267
|
+
assert _flowchart_codes("pr-create", body_text) == [
|
|
268
|
+
durable_post_lint.MISSING_FLOWCHART_CODE
|
|
269
|
+
]
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
@pytest.mark.parametrize(
|
|
273
|
+
"block_lines",
|
|
274
|
+
[
|
|
275
|
+
"flowchart LR",
|
|
276
|
+
"flowchart LR\n only_node",
|
|
277
|
+
"flowchart LR\n a\n b",
|
|
278
|
+
"flowchart LR\n a --> ",
|
|
279
|
+
],
|
|
280
|
+
)
|
|
281
|
+
def should_report_a_flowchart_with_no_arrow_between_two_nodes(
|
|
282
|
+
block_lines: str,
|
|
283
|
+
) -> None:
|
|
284
|
+
thin_block = f"```mermaid\n{block_lines}\n```"
|
|
285
|
+
body_text = VALID_PR_BODY.replace(FLOWCHART_BLOCK, thin_block)
|
|
286
|
+
assert _flowchart_codes("pr-create", body_text) == [
|
|
287
|
+
durable_post_lint.MISSING_FLOWCHART_CODE
|
|
288
|
+
]
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
@pytest.mark.parametrize(
|
|
292
|
+
"block_lines",
|
|
293
|
+
[
|
|
294
|
+
"flowchart TD\n a --> b",
|
|
295
|
+
"flowchart LR\n a -->|yes| b --> c",
|
|
296
|
+
"flowchart LR\n a --- b",
|
|
297
|
+
"flowchart LR\n a -.-> b",
|
|
298
|
+
"flowchart LR\n a ==> b",
|
|
299
|
+
"flowchart LR\n subgraph one\n a[Start] --> b[End]\n end",
|
|
300
|
+
],
|
|
301
|
+
)
|
|
302
|
+
def should_accept_each_flowchart_arrow_form(block_lines: str) -> None:
|
|
303
|
+
body_text = VALID_PR_BODY.replace(
|
|
304
|
+
FLOWCHART_BLOCK, f"```mermaid\n{block_lines}\n```"
|
|
305
|
+
)
|
|
306
|
+
assert _flowchart_codes("pr-create", body_text) == []
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def should_accept_a_tilde_fenced_flowchart() -> None:
|
|
310
|
+
body_text = VALID_PR_BODY.replace("```mermaid", "~~~mermaid").replace(
|
|
311
|
+
"```", "~~~"
|
|
312
|
+
)
|
|
313
|
+
assert _flowchart_codes("pr-create", body_text) == []
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
def should_report_an_unclosed_flowchart_fence() -> None:
|
|
317
|
+
body_text = VALID_PR_BODY.replace(FLOWCHART_BLOCK, FLOWCHART_BLOCK[:-3])
|
|
318
|
+
assert _flowchart_codes("pr-create", body_text) == [
|
|
319
|
+
durable_post_lint.MISSING_FLOWCHART_CODE
|
|
320
|
+
]
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
def should_report_an_edit_body_that_has_the_heading_and_no_flowchart() -> None:
|
|
324
|
+
body_text = VALID_PR_BODY.replace(FLOWCHART_BLOCK, "")
|
|
325
|
+
assert _flowchart_codes("pr-edit", body_text) == [
|
|
326
|
+
durable_post_lint.MISSING_FLOWCHART_CODE
|
|
327
|
+
]
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
def should_accept_an_edit_body_with_a_flowchart() -> None:
|
|
331
|
+
assert _flowchart_codes("pr-edit", VALID_PR_BODY) == []
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def should_not_ask_a_release_automation_body_for_a_flowchart() -> None:
|
|
335
|
+
all_findings = durable_post_lint.lint_durable_post(
|
|
336
|
+
action="pr-create",
|
|
337
|
+
title="chore(main): release claude-dev-env 1.0.0",
|
|
338
|
+
body_text=(
|
|
339
|
+
":robot: I have created a release\n\n## What this does\n\nText.\n\n"
|
|
340
|
+
"This PR was generated with [Release Please](https://github.com/x)."
|
|
341
|
+
),
|
|
342
|
+
head_branch="release-please--branches--main",
|
|
343
|
+
)
|
|
344
|
+
assert all_findings == ()
|
|
345
|
+
|
|
346
|
+
|
|
208
347
|
def should_accept_an_edit_body_without_the_reader_headings() -> None:
|
|
209
348
|
all_findings = durable_post_lint.lint_durable_post(
|
|
210
349
|
action="pr-edit",
|