claude-dev-env 8.109.8 → 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.
@@ -46,5 +46,6 @@ The person running the loop asked for a full look, so every pass gets a full loo
46
46
  - Use picture words: hand it, open it, find it, check it, save it, skip it, stop, call by name.
47
47
  - Prefer spoken results: “found it,” “missing,” “duplicated,” “couldn’t.”
48
48
  - Keep `What this does` short and concrete.
49
+ - Draw the flow before and after the change under `What this does` as a fenced `mermaid` flowchart with at least two nodes and one arrow.
49
50
  - Put proof only in `Proof in practice`.
50
51
  - Explain jargon immediately or replace it.
@@ -4,7 +4,7 @@ A reviewer reads the body in place of the code. The body says what the change do
4
4
 
5
5
  | Section | Holds |
6
6
  |---|---|
7
- | `## What this does` | Two or three plain sentences: the behavior before, the behavior after, and who notices. Written for a reviewer who has not read the worker's conversation. |
7
+ | `## What this does` | Two or three plain sentences: the behavior before, the behavior after, and who notices. Written for a reviewer who has not read the worker's conversation. A fenced `mermaid` flowchart under this heading draws the flow before and after the change; a one-step change gets a short chart. |
8
8
  | `## What changed` | One bullet per area of the diff, in plain words. |
9
9
  | `## Existing work` | What already did part of the job, with a link or file and line, and what this change adds. Or the places searched. |
10
10
  | `## Proof in practice` | Each command in backticks, and the output without the change and with it. The run on the target the change exists to fix is here before the pull request opens. |
@@ -15,4 +15,4 @@ A reviewer reads the body in place of the code. The body says what the change do
15
15
 
16
16
  A repository's own sections, such as a request record or a session link, follow these. Optional `## Why now` and `## After merge` sections go after What this does and after How to revert.
17
17
 
18
- `pull_request.py template` writes the headings in this order into a new body, and appends each missing heading to the end of a body that already has some. `durable_post_lint.py` reports a create body missing What this does, Risk, or How to revert, and the proof gate holds one missing Existing work, Proof in practice, or Eval for a `feat` title.
18
+ `pull_request.py template` writes the headings in this order into a new body, and appends each missing heading to the end of a body that already has some. `durable_post_lint.py` reports a create body missing What this does, Risk, or How to revert, and reports a create or edit body whose What this does section holds no flowchart: a closed `mermaid` block whose first line starts with `flowchart` and that joins two nodes with an arrow. The proof gate holds one missing Existing work, Proof in practice, or Eval for a `feat` title, and holds a create body, or an edit body that has a What this does heading, with no flowchart there.
@@ -40,7 +40,7 @@ When you cannot prove it, leave the pull request unopened. Tell the owner in thr
40
40
 
41
41
  ## Enforcement
42
42
 
43
- `hooks/blocking/pull_request_proof.py` reads the body of each new pull request before it opens. `pr_lifecycle_skill_gate.py` runs it on `gh pr create`, the `pull_request.py create` script, and each `mcp__*__create_pull_request` tool. The gate denies the call when the body has no "Proof in practice" heading, or when the text under that heading names no command in backticks. The gate also denies a section whose only commands run a test runner, such as `pytest`, `python -m unittest`, `uv run pytest`, `npm test`, `npx vitest`, `jest`, `go test` or `cargo test`. Quotes around a runner word, interpreter flags before `-m`, and `coverage run -m unittest` are still test runs. A command is an inline backticked span or a `$ ` line inside a fenced block. A span that starts with a path and line, such as `gate.py:12`, is not a command. A span that holds one path or file name, such as `src/x.py`, is not a command unless that span runs a test runner, such as `py.test` or `pytest.exe`. A test run piped into `tee`, `tail`, `head`, `grep` or `cat` is still a test run. The deny quotes the line "Unit tests are welcome as extra evidence. The live run is the proof." and asks for a run of the changed thing the way its user runs it, without the change and with it. The gate also denies a section whose prose says part of the change is not proven, not tested or not verified, with "yet", "been" or "fully" allowed after the "not", or says unproven, untested or unverified. The line passes only for a workflow file the branch adds, when the body's "After merge" heading plans that file's first run; `pull_request_proof.py` and `hooks_constants/pull_request_proof_constants.py` hold the exact conditions. Otherwise the deny quotes that line, and asks for the run before the pull request opens, or for the line under a "Not covered" heading when the change does not target it. The same denial covers a proof line that opens with "not run", "not exercised" or "not executed" (a "yet" or "been" may follow the "not") or says "has not been run". A proof line with a merge word (merge, merged, merges or merging, so post-merge too) is denied with its own reason: run the check on the branch, and put a file or command name that contains merge in backticks. A step that needs the merged code to exist goes under a "Not covered" heading at the same level as the proof heading, as a line that opens with "not run". `UNPROVEN_ADMISSION_PATTERN` and `MERGE_WORD_PATTERN` list the shapes. Words inside backticks or a fenced block are quoted output and do not count. A section with one command that is not a test run, and no such line, passes. A `gh pr create` with no `--body` or `--body-file` is denied with a request for the body. A body edit through `update_pull_request`, `gh pr edit` or the `pull_request.py edit` script gets the same checks on its proof section that a new pull request gets, so an edit cannot swap in a proof that a new pull request would be denied. An edit with no proof section passes. A body the gate cannot read passes, such as an inline multi-line `--body`, a body from standard input, or a body written through `gh api`. Merges and pushes pass.
43
+ `hooks/blocking/pull_request_proof.py` reads the body of each new pull request before it opens. `pr_lifecycle_skill_gate.py` runs it on `gh pr create`, the `pull_request.py create` script, and each `mcp__*__create_pull_request` tool. The gate denies the call when the body has no "Proof in practice" heading, or when the text under that heading names no command in backticks. The gate also denies a section whose only commands run a test runner, such as `pytest`, `python -m unittest`, `uv run pytest`, `npm test`, `npx vitest`, `jest`, `go test` or `cargo test`. Quotes around a runner word, interpreter flags before `-m`, and `coverage run -m unittest` are still test runs. A command is an inline backticked span or a `$ ` line inside a fenced block. A span that starts with a path and line, such as `gate.py:12`, is not a command. A span that holds one path or file name, such as `src/x.py`, is not a command unless that span runs a test runner, such as `py.test` or `pytest.exe`. A test run piped into `tee`, `tail`, `head`, `grep` or `cat` is still a test run. The deny quotes the line "Unit tests are welcome as extra evidence. The live run is the proof." and asks for a run of the changed thing the way its user runs it, without the change and with it. The gate also denies a section whose prose says part of the change is not proven, not tested or not verified, with "yet", "been" or "fully" allowed after the "not", or says unproven, untested or unverified. The line passes only for a workflow file the branch adds, when the body's "After merge" heading plans that file's first run; `pull_request_proof.py` and `hooks_constants/pull_request_proof_constants.py` hold the exact conditions. Otherwise the deny quotes that line, and asks for the run before the pull request opens, or for the line under a "Not covered" heading when the change does not target it. The same denial covers a proof line that opens with "not run", "not exercised" or "not executed" (a "yet" or "been" may follow the "not") or says "has not been run". A proof line with a merge word (merge, merged, merges or merging, so post-merge too) is denied with its own reason: run the check on the branch, and put a file or command name that contains merge in backticks. A step that needs the merged code to exist goes under a "Not covered" heading at the same level as the proof heading, as a line that opens with "not run". `UNPROVEN_ADMISSION_PATTERN` and `MERGE_WORD_PATTERN` list the shapes. Words inside backticks or a fenced block are quoted output and do not count. A section with one command that is not a test run, and no such line, passes. A `gh pr create` with no `--body` or `--body-file` is denied with a request for the body. A body edit through `update_pull_request`, `gh pr edit` or the `pull_request.py edit` script gets the same checks on its proof section that a new pull request gets, so an edit cannot swap in a proof that a new pull request would be denied. An edit with no proof section passes. The gate also denies a new pull request whose "What this does" section holds no flowchart: a closed `mermaid` block whose first line starts with `flowchart` and that joins two nodes with an arrow. A body edit meets the same check when its body carries a "What this does" heading. A body the gate cannot read passes, such as an inline multi-line `--body`, a body from standard input, or a body written through `gh api`. Merges and pushes pass.
44
44
 
45
45
  When the checked-out branch changes a file people see (`.html`, `.htm`, `.css`, `.scss`, `.tsx`, `.jsx`, `.vue`, `.svelte`), the gate also denies a body whose proof section holds no picture: a markdown image, an image URL, or an Artifact page link that shows the screenshots. Render the change, read the screenshot, and put it in the section, so the reader sees what you looked at. A page the branch only moves to another folder or name that ends the same way, with every byte kept (`R100` in `git diff --name-status`), changes nothing people see, so the gate leaves it out; a moved page that also changed, or a file that becomes a page by a change of name ending, still needs the picture. When git in the session directory cannot list the branch's changed files, the gate asks for the picture as well.
46
46
 
@@ -0,0 +1,152 @@
1
+ """Find fenced lines and the mermaid flowchart in a pull request body."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Iterator
6
+ from typing import NamedTuple
7
+
8
+ from hooks_constants.body_flowchart_constants import (
9
+ BACKTICK_FENCE_CHARACTER,
10
+ EDGE_LABEL_PATTERN,
11
+ FENCE_MARKER_GROUP,
12
+ FENCE_PREFIX_CHARACTERS,
13
+ FENCE_OPEN_PATTERN,
14
+ FLOWCHART_EDGE_PATTERN,
15
+ FLOWCHART_FIRST_LINE_PATTERN,
16
+ FRONT_MATTER_DELIMITER,
17
+ INFO_STRING_GROUP,
18
+ INFO_TAIL_GROUP,
19
+ MERMAID_COMMENT_PREFIX,
20
+ MERMAID_INFO_STRING,
21
+ NODE_TEXT_PATTERN,
22
+ TRAILING_COMMENT_PATTERN,
23
+ )
24
+
25
+
26
+ def _opening_fence(line: str) -> tuple[str, str] | None:
27
+ fence_match = FENCE_OPEN_PATTERN.match(line)
28
+ if fence_match is None:
29
+ return None
30
+ marker = fence_match.group(FENCE_MARKER_GROUP)
31
+ info_text = fence_match.group(INFO_STRING_GROUP) + fence_match.group(INFO_TAIL_GROUP)
32
+ if marker[0] == BACKTICK_FENCE_CHARACTER and BACKTICK_FENCE_CHARACTER in info_text:
33
+ return None
34
+ return marker, fence_match.group(INFO_STRING_GROUP)
35
+
36
+
37
+ def _closes_fence(line: str, open_fence: str) -> bool:
38
+ stripped_line = line.lstrip(FENCE_PREFIX_CHARACTERS).rstrip()
39
+ return len(stripped_line) >= len(open_fence) and set(stripped_line) == {open_fence[0]}
40
+
41
+
42
+ def _closing_index(all_lines: list[str], start_index: int, open_fence: str) -> int | None:
43
+ return next(
44
+ (each_index for each_index in range(start_index, len(all_lines)) if _closes_fence(all_lines[each_index], open_fence)),
45
+ None,
46
+ )
47
+
48
+
49
+ class FenceSpan(NamedTuple):
50
+ open_index: int
51
+ close_index: int | None
52
+ info_string: str
53
+
54
+
55
+ def _fence_spans(all_lines: list[str]) -> Iterator[FenceSpan]:
56
+ line_index = 0
57
+ while line_index < len(all_lines):
58
+ opening = _opening_fence(all_lines[line_index])
59
+ if opening is None:
60
+ line_index += 1
61
+ continue
62
+ marker, info_string = opening
63
+ close_index = _closing_index(all_lines, line_index + 1, marker)
64
+ yield FenceSpan(line_index, close_index, info_string)
65
+ if close_index is None:
66
+ return
67
+ line_index = close_index + 1
68
+
69
+
70
+ def fenced_line_flags(all_lines: list[str]) -> list[bool]:
71
+ """Return one flag per line: whether the line is a fence line or sits between two.
72
+
73
+ ::
74
+
75
+ ["a", "```", "# b", "```", "c"] -> [False, True, True, True, False]
76
+ ["a", "```", "# b"] -> [False, False, False]
77
+
78
+ A fence that never closes turns every flag to False, so one stray fence
79
+ leaves the body readable as plain text. A closing fence is a run of the
80
+ opening fence character at least as long as the opening run.
81
+
82
+ Args:
83
+ all_lines: The body split into lines.
84
+ """
85
+ all_flags = [False] * len(all_lines)
86
+ for each_span in _fence_spans(all_lines):
87
+ close_index = each_span.close_index
88
+ if close_index is None:
89
+ return [False] * len(all_lines)
90
+ all_flags[each_span.open_index : close_index + 1] = [True] * (close_index - each_span.open_index + 1)
91
+ return all_flags
92
+
93
+
94
+ def _closed_mermaid_blocks(section: str) -> Iterator[list[str]]:
95
+ all_lines = section.splitlines()
96
+ for each_span in _fence_spans(all_lines):
97
+ if each_span.close_index is not None and each_span.info_string.lower() == MERMAID_INFO_STRING:
98
+ yield [
99
+ each_line.lstrip(FENCE_PREFIX_CHARACTERS).rstrip()
100
+ for each_line in all_lines[each_span.open_index + 1 : each_span.close_index]
101
+ ]
102
+
103
+
104
+ def _without_labels(line: str) -> str:
105
+ return EDGE_LABEL_PATTERN.sub("", NODE_TEXT_PATTERN.sub("", TRAILING_COMMENT_PATTERN.sub("", line)))
106
+
107
+
108
+ def _without_front_matter(all_block_lines: list[str]) -> list[str]:
109
+ if not all_block_lines or all_block_lines[0] != FRONT_MATTER_DELIMITER:
110
+ return all_block_lines
111
+ closing_offset = next(
112
+ (each_index for each_index, each_line in enumerate(all_block_lines[1:], start=1) if each_line == FRONT_MATTER_DELIMITER),
113
+ None,
114
+ )
115
+ return [] if closing_offset is None else all_block_lines[closing_offset + 1 :]
116
+
117
+
118
+ def _is_flowchart(all_block_lines: list[str]) -> bool:
119
+ all_diagram_lines = [
120
+ each_line
121
+ for each_line in _without_front_matter(all_block_lines)
122
+ if each_line and not each_line.startswith(MERMAID_COMMENT_PREFIX)
123
+ ]
124
+ if not all_diagram_lines:
125
+ return False
126
+ if FLOWCHART_FIRST_LINE_PATTERN.match(all_diagram_lines[0]) is None:
127
+ return False
128
+ return any(
129
+ FLOWCHART_EDGE_PATTERN.search(_without_labels(each_line)) is not None
130
+ for each_line in all_diagram_lines
131
+ )
132
+
133
+
134
+ def section_has_flowchart(section: str) -> bool:
135
+ """Return whether a section holds a closed mermaid block that draws a flowchart.
136
+
137
+ ::
138
+
139
+ "```mermaid\\nflowchart LR\\n a --> b\\n```" -> True
140
+ "```mermaid\\nflowchart LR; a --> b\\n```" -> True
141
+ "```mermaid\\nsequenceDiagram\\n a->>b: hi\\n```" -> False
142
+ "```mermaid\\nflowchart LR\\n a\\n```" -> False
143
+ "```mermaid\\nflowchart LR\\n a --> b" -> False
144
+
145
+ The block opens with a fence whose info string is mermaid. Its first line,
146
+ after any front matter, starts with flowchart, and a line joins two nodes
147
+ with an arrow.
148
+
149
+ Args:
150
+ section: The text under one pull request description heading.
151
+ """
152
+ return any(_is_flowchart(each_block) for each_block in _closed_mermaid_blocks(section))
@@ -71,6 +71,7 @@ from blocking.pull_request_proof import (
71
71
  is_feature_pull_request,
72
72
  missing_eval_section_reason,
73
73
  missing_existing_work_reason,
74
+ missing_flowchart_reason,
74
75
  missing_look_reason,
75
76
  missing_proof_reason,
76
77
  )
@@ -336,6 +337,7 @@ def decision_for(all_payload_fields: dict[str, object]) -> dict[str, object] | N
336
337
  proof, or a body edit, holds a merge word -> DEFERRED_PROOF_REASON
337
338
  body edit whose proof has no command or only tests -> MISSING_PROOF_REASON or TEST_ONLY_PROOF_REASON
338
339
  new pull request with no existing-work section -> MISSING_EXISTING_WORK_REASON
340
+ pull request with no flowchart in What this does -> MISSING_FLOWCHART_REASON
339
341
  feature pull request with no eval section -> MISSING_EVAL_SECTION_REASON
340
342
  changed page whose proof shows no picture -> MISSING_LOOK_REASON
341
343
  feature pull request, no /claude-api build-eval -> MISSING_BUILD_EVAL_REASON
@@ -354,6 +356,9 @@ def decision_for(all_payload_fields: dict[str, object]) -> dict[str, object] | N
354
356
  search_reason = missing_existing_work_reason(all_payload_fields)
355
357
  if search_reason is not None:
356
358
  return deny_decision(search_reason)
359
+ flowchart_reason = missing_flowchart_reason(all_payload_fields)
360
+ if flowchart_reason is not None:
361
+ return deny_decision(flowchart_reason)
357
362
  eval_reason = missing_eval_section_reason(all_payload_fields)
358
363
  if eval_reason is not None:
359
364
  return deny_decision(eval_reason)
@@ -14,6 +14,7 @@ hooks_directory = str(Path(__file__).resolve().parent.parent)
14
14
  if hooks_directory not in sys.path:
15
15
  sys.path.insert(0, hooks_directory)
16
16
 
17
+ from blocking.body_flowchart import fenced_line_flags, section_has_flowchart
17
18
  from blocking.followup_pr_dedupe import body_from_arguments, create_tool_fields, title_from_arguments
18
19
  from hooks_constants.pr_lifecycle_skill_gate_constants import SHELL_TOOL_NAMES, UPDATE_PULL_REQUEST_TOOL_SUFFIX
19
20
  from hooks_constants.pull_request_proof_constants import (
@@ -50,6 +51,7 @@ from hooks_constants.pull_request_proof_constants import (
50
51
  REPOSITORY_ENDPOINT_TEMPLATE,
51
52
  REPOSITORY_FLAG_ASSIGNMENT_PREFIX,
52
53
  UNREADABLE_CHANGES_REASON,
54
+ WHAT_THIS_DOES_HEADING_PATTERN,
53
55
  EVAL_HEADING_PATTERN,
54
56
  EXISTING_WORK_HEADING_PATTERN,
55
57
  FEATURE_TITLE_PATTERN,
@@ -58,6 +60,7 @@ from hooks_constants.pull_request_proof_constants import (
58
60
  MISSING_BODY_REASON,
59
61
  MISSING_EVAL_SECTION_REASON,
60
62
  MISSING_EXISTING_WORK_REASON,
63
+ MISSING_FLOWCHART_REASON,
61
64
  MISSING_LOOK_REASON,
62
65
  MISSING_PROOF_REASON,
63
66
  NEW_WORKFLOW_PATH_PATTERN,
@@ -118,8 +121,9 @@ def _heading_level(line: str, heading_pattern: str) -> int | None:
118
121
 
119
122
 
120
123
  def _lines_until_heading(all_lines: list[str], heading_level: int) -> list[str]:
124
+ all_fenced_flags = fenced_line_flags(all_lines)
121
125
  for each_index, each_line in enumerate(all_lines):
122
- next_level = _heading_level(each_line, NEXT_HEADING_PATTERN)
126
+ next_level = None if all_fenced_flags[each_index] else _heading_level(each_line, NEXT_HEADING_PATTERN)
123
127
  if next_level is not None and next_level <= heading_level:
124
128
  return all_lines[:each_index]
125
129
  return all_lines
@@ -127,8 +131,9 @@ def _lines_until_heading(all_lines: list[str], heading_level: int) -> list[str]:
127
131
 
128
132
  def _section_text(body: str, heading_pattern: str) -> str | None:
129
133
  all_lines = body.splitlines()
134
+ all_fenced_flags = fenced_line_flags(all_lines)
130
135
  for each_index, each_line in enumerate(all_lines):
131
- heading_level = _heading_level(each_line, heading_pattern)
136
+ heading_level = None if all_fenced_flags[each_index] else _heading_level(each_line, heading_pattern)
132
137
  if heading_level is not None:
133
138
  all_section_lines = _lines_until_heading(all_lines[each_index + 1 :], heading_level)
134
139
  return LINE_SEPARATOR.join(all_section_lines).strip()
@@ -148,6 +153,21 @@ def proof_section(body: str) -> str | None:
148
153
  return _section_text(body, PROOF_HEADING_PATTERN)
149
154
 
150
155
 
156
+ def what_this_does_section(body: str) -> str | None:
157
+ """Return the text under the body's 'What this does' heading, or None.
158
+
159
+ ::
160
+
161
+ "## What this does\\nBefore, after.\\n## Risk" -> "Before, after."
162
+ "## Summary\\nno what-this-does heading" -> None
163
+
164
+ The section runs to the next heading of the same or a higher level. A line
165
+ that starts with a hash inside a fenced block is code, not a heading. When any fence
166
+ in the body never closes, every fence reads as plain text.
167
+ """
168
+ return _section_text(body, WHAT_THIS_DOES_HEADING_PATTERN)
169
+
170
+
151
171
  def section_under_existing_work(body: str) -> str | None:
152
172
  """Return the text under the body's 'Existing work' heading, or None.
153
173
 
@@ -664,6 +684,51 @@ def missing_existing_work_reason(all_payload_fields: Mapping[str, object]) -> st
664
684
  return None
665
685
 
666
686
 
687
+ def has_flowchart_under_what_this_does(body: str) -> bool:
688
+ """Return whether the body's 'What this does' section holds a mermaid flowchart.
689
+
690
+ ::
691
+
692
+ "## What this does\\n```mermaid\\nflowchart LR\\n a --> b\\n```" -> True
693
+ "## What this does\\nwords only" -> False
694
+ "## Summary\\nno what-this-does heading" -> False
695
+
696
+ Args:
697
+ body: The pull request body.
698
+ """
699
+ section = what_this_does_section(body)
700
+ return section is not None and section_has_flowchart(section)
701
+
702
+
703
+ def missing_flowchart_reason(all_payload_fields: Mapping[str, object]) -> str | None:
704
+ """Return a deny reason when a pull request body has no flowchart under 'What this does', else None.
705
+
706
+ ::
707
+
708
+ MCP create, flowchart under the heading -> None
709
+ MCP create, text only under the heading -> MISSING_FLOWCHART_REASON
710
+ MCP create, no 'What this does' heading -> MISSING_FLOWCHART_REASON
711
+ update_pull_request, heading and no flowchart -> MISSING_FLOWCHART_REASON
712
+ update_pull_request, no 'What this does' heading -> None
713
+ a create with --fill, any other tool -> None
714
+
715
+ A new pull request needs the flowchart. A body edit needs it only when the
716
+ body carries the heading, so an edit to an older body passes. A create
717
+ command whose body this gate cannot read passes here, because
718
+ missing_proof_reason denies it first.
719
+
720
+ Args:
721
+ all_payload_fields: The parsed PreToolUse input.
722
+ """
723
+ for each_body in _create_bodies(all_payload_fields):
724
+ if each_body is not None and not has_flowchart_under_what_this_does(each_body):
725
+ return MISSING_FLOWCHART_REASON
726
+ for each_body in _edit_bodies(all_payload_fields):
727
+ if what_this_does_section(each_body) is not None and not has_flowchart_under_what_this_does(each_body):
728
+ return MISSING_FLOWCHART_REASON
729
+ return None
730
+
731
+
667
732
  class ChangedFile(NamedTuple):
668
733
  path: str
669
734
  old_path: str
@@ -70,6 +70,10 @@ in the turn. A turn sends one reply, so a reply after a delivered reply in
70
70
  the same turn is denied. A widget may hold no anchor link, since a widget
71
71
  link does not open in the Claude app.
72
72
 
73
+ A reply that reports results, a markdown table or three or more figures outside
74
+ links and code, needs one picture: an image file in ``attached_outputs``, or a
75
+ markdown image. This check runs whether or not the visual mode is on.
76
+
73
77
  A length limit is a smell elsewhere in this package, recorded and fixed in a
74
78
  later pass. A posted reply reaches the user the moment it sends and has no
75
79
  later pass, so this gate denies it and the model resends a shorter one.
@@ -97,6 +101,7 @@ from visual_reply_rules import (
97
101
  abbreviation_violation,
98
102
  load_rules,
99
103
  mode_enabled,
104
+ results_picture_violation,
100
105
  second_reply_violation,
101
106
  successful_result_text,
102
107
  visual_violation,
@@ -127,6 +132,7 @@ from hooks_constants.reply_length_gate_constants import (
127
132
  ALL_DECISION_OPTION_LENGTH_KEYS,
128
133
  ALL_DECISION_OPTION_PROSE_KEYS,
129
134
  ALL_DEFAULT_BANNED_WORDS,
135
+ ALL_EDIT_TOOL_NAMES,
130
136
  ALL_EVIDENCE_PATTERNS,
131
137
  ALL_QUESTION_CARD_PROSE_KEYS,
132
138
  ALL_QUESTION_OPTION_PROSE_KEYS,
@@ -580,7 +586,17 @@ def _text_violation(
580
586
  reply_text = all_tool_input.get(TEXT_KEY)
581
587
  if not isinstance(reply_text, str):
582
588
  return None
583
- violation = reply_violation(reply_text, transcript_path, mode_rules)
589
+ all_checks = [lambda: reply_violation(reply_text, transcript_path, mode_rules)]
590
+ if tool_name not in ALL_EDIT_TOOL_NAMES:
591
+ all_checks.append(
592
+ lambda: results_picture_violation(
593
+ prose_outside_links(reply_text),
594
+ reply_text,
595
+ all_tool_input,
596
+ mode_rules if mode_rules is not None else load_rules(),
597
+ )
598
+ )
599
+ violation = collected_violations(all_checks)
584
600
  return None if violation is None else (violation, reply_text)
585
601
 
586
602
 
@@ -0,0 +1,99 @@
1
+ """Behavior tests for the mermaid flowchart reader of a pull request description section."""
2
+
3
+ import sys
4
+ from pathlib import Path
5
+
6
+ import pytest
7
+
8
+ HOOKS_DIRECTORY = Path(__file__).resolve().parent.parent
9
+ if str(HOOKS_DIRECTORY) not in sys.path:
10
+ sys.path.insert(0, str(HOOKS_DIRECTORY))
11
+
12
+ from blocking.body_flowchart import fenced_line_flags, section_has_flowchart
13
+
14
+
15
+ def _block(*all_lines: str, fence: str = "```") -> str:
16
+ return "\n".join([f"{fence}mermaid", *all_lines, fence])
17
+
18
+
19
+ @pytest.mark.parametrize(
20
+ "block",
21
+ [
22
+ _block("flowchart LR", " a --> b"),
23
+ _block("flowchart TD", " a[Start] -->|yes| b[End]"),
24
+ _block("flowchart LR", " a --> b --> c"),
25
+ _block("flowchart LR", " a --- b"),
26
+ _block("flowchart LR", " a -.-> b"),
27
+ _block("flowchart LR", " a ==> b"),
28
+ _block("flowchart LR; a --> b"),
29
+ "````mermaid\nflowchart LR\n a --> b\n`````",
30
+ "> ```mermaid\n> flowchart LR\n> a --> b\n> ```",
31
+ _block("---", "title: Flow", "---", "flowchart LR", " a --> b"),
32
+ "1. Flow:\n\n ```mermaid\n flowchart LR\n a --> b\n ```",
33
+ "```js```\n\n" + _block("flowchart LR", " a --> b"),
34
+ _block("flowchart LR", " a === b"),
35
+ _block("flowchart LR", " a -.- b"),
36
+ _block("flowchart LR", " a -..-> b"),
37
+ _block("flowchart LR", ' a["run --output x"] --> b[End]'),
38
+ _block("flowchart LR", " subgraph one", " a --> b", " end"),
39
+ _block("%% a note", "flowchart LR", "", " a --> b"),
40
+ _block("flowchart LR", " a --> b", fence="~~~"),
41
+ "Before the chart.\n\n" + _block("flowchart LR", " a --> b") + "\n\nAfter it.",
42
+ ],
43
+ )
44
+ def should_accept_a_closed_mermaid_flowchart_with_an_arrow(block: str) -> None:
45
+ assert section_has_flowchart(block)
46
+
47
+
48
+ @pytest.mark.parametrize(
49
+ "section",
50
+ [
51
+ "",
52
+ "Plain sentences and no chart.",
53
+ _block("sequenceDiagram", " a->>b: hi"),
54
+ _block("graph LR", " a --> b"),
55
+ _block("classDiagram", " a --> b"),
56
+ _block("flowchart LR"),
57
+ _block("---", "title: Flow", "---"),
58
+ _block("---", "flowchart LR", " a --> b"),
59
+ _block("flowchart LR", " a %% --> b"),
60
+ _block("flowchart LR", " only_node"),
61
+ _block("flowchart LR", " a", " b"),
62
+ _block("flowchart LR", " a --> "),
63
+ _block("flowchart LR", " a -->|label|"),
64
+ _block("flowchart LR", ' a["run --output x"]'),
65
+ _block("flowchart LR", " a[Start --> End]"),
66
+ _block("a --> b", "flowchart LR"),
67
+ "```text\nflowchart LR\n a --> b\n```",
68
+ "```mermaid\nflowchart LR\n a --> b",
69
+ "````text\n```mermaid\nflowchart LR\n a --> b\n```\n````",
70
+ "```mermaid\nflowchart LR\n a --> b\n``",
71
+ ],
72
+ )
73
+ def should_reject_a_section_without_a_closed_mermaid_flowchart_edge(section: str) -> None:
74
+ assert not section_has_flowchart(section)
75
+
76
+
77
+ def should_find_a_flowchart_after_a_block_of_another_diagram_type() -> None:
78
+ section = (
79
+ _block("sequenceDiagram", " a->>b: hi") + "\n\n" + _block("flowchart LR", " a --> b")
80
+ )
81
+ assert section_has_flowchart(section)
82
+
83
+
84
+ @pytest.mark.parametrize(
85
+ ("all_lines", "expected_flags"),
86
+ [
87
+ (["a", "```", "# b", "```", "c"], [False, True, True, True, False]),
88
+ (["a", "```", "# b"], [False, False, False]),
89
+ (["```", "x", "```", "# h", "~~~", "y", "~~~"], [True, True, True, False, True, True, True]),
90
+ (["````", "```", "# h", "```", "````", "# after"], [True, True, True, True, True, False]),
91
+ (["```", "x", "```", "```", "dangling"], [False] * 5),
92
+ (["> ```", "> # h", "> ```"], [True, True, True]),
93
+ (["plain", "# heading"], [False, False]),
94
+ ],
95
+ )
96
+ def should_flag_each_line_of_a_closed_fence_and_none_when_a_fence_stays_open(
97
+ all_lines: list[str], expected_flags: list[bool]
98
+ ) -> None:
99
+ assert fenced_line_flags(all_lines) == expected_flags
@@ -20,8 +20,12 @@ from hooks_constants.pull_request_proof_constants import (
20
20
  UNPROVEN_PROOF_REASON,
21
21
  )
22
22
 
23
+ WHAT_THIS_DOES_SECTION = (
24
+ "## What this does\nDraws the flow before and after.\n\n"
25
+ "```mermaid\nflowchart LR\n before --> after\n```\n\n"
26
+ )
23
27
  PROVEN_FOLLOWUP_BODY = (
24
- "Follow-up to #1731\n\n## Existing work\nNothing found in open or merged pull requests.\n\n"
28
+ "Follow-up to #1731\n\n" + WHAT_THIS_DOES_SECTION + "## Existing work\nNothing found in open or merged pull requests.\n\n"
25
29
  "## Proof in practice\nRan `python probe.py`.\n"
26
30
  )
27
31
 
@@ -370,7 +374,7 @@ def test_loaded_skill_denies_a_body_edit_that_adds_an_unrun_proof_line(tmp_path:
370
374
 
371
375
 
372
376
  EVALUATED_BODY = (
373
- "## Existing work\nNothing found in open or merged pull requests.\n\n"
377
+ WHAT_THIS_DOES_SECTION + "## Existing work\nNothing found in open or merged pull requests.\n\n"
374
378
  "## Proof in practice\nRan `python probe.py`.\n\n"
375
379
  "## Eval\nTen labeled cases, exact-match grader. Ran `python eval.py`: 10/10.\n"
376
380
  )
@@ -19,6 +19,7 @@ from hooks_constants.pull_request_proof_constants import (
19
19
  MISSING_BODY_REASON,
20
20
  MISSING_EVAL_SECTION_REASON,
21
21
  MISSING_EXISTING_WORK_REASON,
22
+ MISSING_FLOWCHART_REASON,
22
23
  MISSING_PROOF_REASON,
23
24
  TEST_ONLY_PROOF_REASON,
24
25
  UNPROVEN_PROOF_REASON,
@@ -346,6 +347,103 @@ def test_other_pull_request_commands_should_pass_the_existing_work_check() -> No
346
347
  assert gate.missing_existing_work_reason(_shell(each_command)) is None
347
348
 
348
349
 
350
+ FLOWCHART_BLOCK = "```mermaid\nflowchart LR\n before --> after\n```"
351
+ CHARTED_BODY = f"## What this does\nDraws the flow.\n\n{FLOWCHART_BLOCK}\n\n## Risk\nLow.\n"
352
+ CREATE_WITH_BODY_FILE = "gh pr create --title 't' --body-file body.md"
353
+
354
+
355
+ def _mcp_update(body: object) -> dict[str, object]:
356
+ return {
357
+ "tool_name": "mcp__github__update_pull_request",
358
+ "tool_input": {"owner": "o", "repo": "r", "pullNumber": 1, "body": body},
359
+ }
360
+
361
+
362
+ def test_what_this_does_section_should_stop_at_a_heading_of_the_same_level() -> None:
363
+ body = "### What this does\nBefore.\n#### Child\nkept\n### Risk\ndropped"
364
+ assert gate.what_this_does_section(body) == "Before.\n#### Child\nkept"
365
+
366
+
367
+ def test_what_this_does_section_should_return_none_without_the_heading() -> None:
368
+ assert gate.what_this_does_section(UNPROVEN_BODY) is None
369
+
370
+
371
+ def test_what_this_does_section_should_not_end_at_a_hash_line_inside_a_fenced_block() -> None:
372
+ body = f"## What this does\n```bash\n# old flow\nx\n```\n{FLOWCHART_BLOCK}\n## Risk\nLow.\n"
373
+ assert gate.has_flowchart_under_what_this_does(body)
374
+
375
+
376
+ def test_unclosed_fence_should_not_swallow_the_next_heading() -> None:
377
+ body = "## Proof in practice\nRan `python probe.py`.\n```\nout\n## Not covered\nnot run: x"
378
+ assert gate.proof_section(body) == "Ran `python probe.py`.\n```\nout"
379
+
380
+
381
+ def test_what_this_does_heading_inside_a_fenced_block_should_not_start_the_section() -> None:
382
+ body = f"```\n## What this does\n```\n\n{CHARTED_BODY}"
383
+ assert gate.has_flowchart_under_what_this_does(body)
384
+
385
+
386
+ def test_has_flowchart_under_what_this_does_should_read_only_that_section() -> None:
387
+ assert gate.has_flowchart_under_what_this_does(CHARTED_BODY)
388
+ assert not gate.has_flowchart_under_what_this_does(f"## What this does\nWords.\n\n## Risk\n{FLOWCHART_BLOCK}\n")
389
+ assert not gate.has_flowchart_under_what_this_does(f"{FLOWCHART_BLOCK}\n")
390
+
391
+
392
+ def test_mcp_create_with_a_flowchart_under_what_this_does_should_pass() -> None:
393
+ assert gate.missing_flowchart_reason(_mcp_create(CHARTED_BODY)) is None
394
+
395
+
396
+ def test_mcp_create_with_text_only_under_what_this_does_should_be_denied() -> None:
397
+ body = "## What this does\nDraws the flow in words.\n\n## Risk\nLow.\n"
398
+ assert gate.missing_flowchart_reason(_mcp_create(body)) == MISSING_FLOWCHART_REASON
399
+
400
+
401
+ def test_mcp_create_without_a_what_this_does_heading_should_be_denied() -> None:
402
+ assert gate.missing_flowchart_reason(_mcp_create(SEARCHED_BODY)) == MISSING_FLOWCHART_REASON
403
+
404
+
405
+ def test_mcp_create_with_the_flowchart_under_another_heading_should_be_denied() -> None:
406
+ body = f"## What this does\nWords.\n\n## Risk\n{FLOWCHART_BLOCK}\n"
407
+ assert gate.missing_flowchart_reason(_mcp_create(body)) == MISSING_FLOWCHART_REASON
408
+
409
+
410
+ def test_mcp_create_with_a_sequence_diagram_should_be_denied() -> None:
411
+ body = "## What this does\n```mermaid\nsequenceDiagram\n a->>b: hi\n```\n"
412
+ assert gate.missing_flowchart_reason(_mcp_create(body)) == MISSING_FLOWCHART_REASON
413
+
414
+
415
+ def test_body_file_create_without_a_flowchart_should_be_denied(tmp_path: Path) -> None:
416
+ (tmp_path / "body.md").write_text("## What this does\nWords only.\n", encoding="utf-8")
417
+ assert gate.missing_flowchart_reason(_shell(CREATE_WITH_BODY_FILE, tmp_path)) == MISSING_FLOWCHART_REASON
418
+
419
+
420
+ def test_body_file_create_with_a_flowchart_should_pass(tmp_path: Path) -> None:
421
+ (tmp_path / "body.md").write_text(CHARTED_BODY, encoding="utf-8")
422
+ assert gate.missing_flowchart_reason(_shell(CREATE_WITH_BODY_FILE, tmp_path)) is None
423
+
424
+
425
+ def test_flowchart_check_should_skip_an_unreadable_shell_body_and_deny_an_empty_mcp_body() -> None:
426
+ assert gate.missing_flowchart_reason(_shell("gh pr create --fill")) is None
427
+ assert gate.missing_flowchart_reason(_mcp_create(None)) == MISSING_FLOWCHART_REASON
428
+
429
+
430
+ def test_edit_with_the_heading_and_no_flowchart_should_be_denied() -> None:
431
+ body = "## What this does\nWords only.\n"
432
+ assert gate.missing_flowchart_reason(_mcp_update(body)) == MISSING_FLOWCHART_REASON
433
+
434
+
435
+ def test_edit_with_a_flowchart_should_pass() -> None:
436
+ assert gate.missing_flowchart_reason(_mcp_update(CHARTED_BODY)) is None
437
+
438
+
439
+ def test_edit_of_an_older_body_without_the_heading_should_pass() -> None:
440
+ assert gate.missing_flowchart_reason(_mcp_update(SEARCHED_BODY)) is None
441
+
442
+
443
+ def test_other_tools_should_pass_the_flowchart_check() -> None:
444
+ assert gate.missing_flowchart_reason(_shell("git push origin main")) is None
445
+
446
+
349
447
  def _repository_with_change(tmp_path: Path, changed_file_name: str) -> Path:
350
448
  origin_path = tmp_path / "origin"
351
449
  clone_path = tmp_path / "clone"
@@ -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![Results chart](/mnt/project-files/tests/chart.png)"},
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![Chart](chart.png)\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![Chart](chart.png "Results")', {})
307
+ assert attaches_picture("Results.\n\n![Chart](https://x.example/c.png?w=2)", {})
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("![Chart](chart.png)", {})
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 = {ONE_ITEM_RULE_KEY, NO_PICTURE_RULE_KEY, ABBREVIATIONS_RULE_KEY}
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-dev-env",
3
- "version": "8.109.8",
3
+ "version": "8.110.0",
4
4
  "description": "Claude Code development standards — rules, hooks, agents, commands, and skills",
5
5
  "type": "module",
6
6
  "bin": {
@@ -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
- VALID_PR_BODY = """## What this does
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",