claude-dev-env 8.115.0 → 8.116.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/install.prompt-context.test.mjs +5 -6
- package/docs/rule-guides/verified-work.md +1 -1
- package/hooks/advisory/commit_and_pull_request_words.py +346 -0
- package/hooks/advisory/piece_clauses.py +248 -0
- package/hooks/advisory/pieces_per_level_analysis.py +192 -0
- package/hooks/advisory/pieces_per_level_note.py +265 -0
- package/hooks/advisory/test_commit_and_pull_request_words.py +126 -0
- package/hooks/advisory/test_piece_clauses.py +183 -0
- package/hooks/advisory/test_pieces_per_level_note.py +389 -0
- package/hooks/advisory/test_pieces_per_level_note_bounds.py +215 -0
- package/hooks/advisory/test_pieces_per_level_note_deadline.py +282 -0
- package/hooks/blocking/final_reply_gate.py +7 -29
- package/hooks/blocking/test_final_reply_gate.py +4 -196
- package/hooks/features/README.md +1 -1
- package/hooks/features/conduct-gates.md +5 -12
- package/hooks/features/session-context.md +4 -1
- package/hooks/hooks.json +10 -41
- package/hooks/hooks_constants/background_silence_prompt_constants.py +2 -0
- package/hooks/hooks_constants/pieces_per_level_note_constants.py +255 -0
- package/hooks/hooks_constants/resolve_thread_reply_gate_constants.py +0 -8
- package/hooks/hooks_constants/shell_command_wrappers.py +20 -8
- package/hooks/hooks_constants/test_shell_command_wrappers.py +7 -0
- package/hooks/session/background_silence_prompt.py +1 -1
- package/hooks/test_context_budget_hooks.py +0 -1
- package/package.json +1 -1
- package/scripts/durable_post_lint.py +0 -12
- package/scripts/durable_post_lint_config/config/constants.py +1 -2
- package/scripts/policy_lint/adapter_configuration.py +0 -2
- package/scripts/policy_lint/config/constants.py +0 -2
- package/scripts/test_durable_post_lint.py +0 -53
- package/scripts/tests/test_adapter_configuration.py +0 -16
- package/scripts/tests/test_verified_work_rule.py +13 -0
- package/hooks/blocking/chat_reply_gate.py +0 -260
- package/hooks/blocking/reply_length_gate.py +0 -804
- package/hooks/blocking/test_chat_reply_gate.py +0 -302
- package/hooks/blocking/test_reply_length_gate.py +0 -1324
- package/hooks/hooks_constants/chat_reply_gate_constants.py +0 -60
- package/hooks/hooks_constants/reply_length_gate_constants.py +0 -203
- package/hooks/hooks_constants/test_reply_length_gate_constants.py +0 -81
- package/hooks/hooks_constants/test_visual_reply_rules_constants.py +0 -50
- package/hooks/hooks_constants/visual_reply_rules_constants.py +0 -106
- package/hooks/test_visual_reply_rules.py +0 -362
- package/hooks/visual_reply_rules.py +0 -478
- package/rules/visual-reply-rules.json +0 -56
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"""Constants for the chat reply gate UserPromptSubmit and MessageDisplay hook."""
|
|
2
|
-
|
|
3
|
-
from hooks_constants.reply_length_gate_constants import (
|
|
4
|
-
MAXIMUM_SENTENCE_COUNT,
|
|
5
|
-
MAXIMUM_WORDS_PER_SENTENCE,
|
|
6
|
-
)
|
|
7
|
-
|
|
8
|
-
HOOK_EVENT_NAME_INPUT_KEY = "hook_event_name"
|
|
9
|
-
MESSAGE_DISPLAY_EVENT_NAME = "MessageDisplay"
|
|
10
|
-
USER_PROMPT_SUBMIT_EVENT_NAME = "UserPromptSubmit"
|
|
11
|
-
SESSION_END_EVENT_NAME = "SessionEnd"
|
|
12
|
-
SESSION_ID_KEY = "session_id"
|
|
13
|
-
MESSAGE_ID_KEY = "message_id"
|
|
14
|
-
DELTA_KEY = "delta"
|
|
15
|
-
FINAL_KEY = "final"
|
|
16
|
-
DISPLAY_CONTENT_KEY = "displayContent"
|
|
17
|
-
STATE_FILE_ENCODING = "utf-8"
|
|
18
|
-
HELD_TEXT_FILE_PREFIX = "claude-chat-reply-held-"
|
|
19
|
-
SHOWN_DRAFT_FILE_PREFIX = "claude-chat-reply-shown-"
|
|
20
|
-
STATE_FILE_SUFFIX = ".txt"
|
|
21
|
-
REPLY_LIMIT_REMINDER = (
|
|
22
|
-
f"Your reply to the user is final and gets no second pass. Keep it to {MAXIMUM_SENTENCE_COUNT}"
|
|
23
|
-
f" sentences or fewer, each {MAXIMUM_WORDS_PER_SENTENCE} words or fewer."
|
|
24
|
-
" Each line and each list item counts as one sentence, so prefer short prose over lists."
|
|
25
|
-
" Lead with the outcome and cut detail the user did not ask for."
|
|
26
|
-
" No colon in the middle of a sentence, and no em dash."
|
|
27
|
-
" Put any pull request number inside a markdown link."
|
|
28
|
-
" A sentence with so, because, caused, due to, therefore, or means needs inline code, a URL, or a link in it."
|
|
29
|
-
" Never write real, really, genuine, actual, actually, likely, probably, seems, maybe, perhaps, may be, or might be."
|
|
30
|
-
" Count your sentences before you send."
|
|
31
|
-
)
|
|
32
|
-
SHOWN_DRAFT_PREFIX = "\n\nThe user saw your last reply condensed to this text, so build on it:\n\n"
|
|
33
|
-
SHOWN_DRAFT_HEADING = SHOWN_DRAFT_PREFIX.lstrip()
|
|
34
|
-
REPLY_LIMIT_ONCE_MARKER_NAME = "chat_reply_limit"
|
|
35
|
-
DRAFTER_GUARD_ENV_VAR = "CHAT_REPLY_DRAFTER_ACTIVE"
|
|
36
|
-
DRAFTER_MODEL_ENV_VAR = "CHAT_REPLY_DRAFTER_MODEL"
|
|
37
|
-
DEFAULT_DRAFTER_MODEL = "haiku"
|
|
38
|
-
DRAFTER_TIMEOUT_SECONDS = 45
|
|
39
|
-
MAXIMUM_DRAFT_ATTEMPTS = 2
|
|
40
|
-
DRAFTER_RESULT_KEY = "result"
|
|
41
|
-
DRAFTER_ERROR_KEY = "is_error"
|
|
42
|
-
DRAFTER_EXECUTABLE_NAME = "claude"
|
|
43
|
-
CLAUDE_SESSION_ID_ENV_VAR = "CLAUDE_CODE_SESSION_ID"
|
|
44
|
-
DRAFTER_REQUEST_TEMPLATE = "Rule the reply broke: {violation}\n\nReply to rewrite:\n\n{reply_text}"
|
|
45
|
-
DRAFTER_RULES = (
|
|
46
|
-
f"Rewrite the reply below so it obeys every rule. At most {MAXIMUM_SENTENCE_COUNT} sentences,"
|
|
47
|
-
f" each at most {MAXIMUM_WORDS_PER_SENTENCE} words. Each line and each list item counts as one sentence."
|
|
48
|
-
" Keep the outcome, the recommendation, and any number, path, or command the user needs."
|
|
49
|
-
" Drop background the user did not ask for."
|
|
50
|
-
" No colon in the middle of a sentence. No em dash."
|
|
51
|
-
" Write a pull request number only inside a markdown link."
|
|
52
|
-
" A sentence that gives a cause, with so, because, caused, due to, therefore, or means,"
|
|
53
|
-
" must hold its own evidence as inline code, a URL, or a markdown link. Otherwise state the fact without the cause word."
|
|
54
|
-
" Never use these words: real, really, genuine, actual, actually, likely, probably, seems, maybe, perhaps,"
|
|
55
|
-
" might be, may be, appears to, suspect, guess, presumably."
|
|
56
|
-
" Speak as the original author to the original reader."
|
|
57
|
-
" Never mention the rule, the length, or this rewrite."
|
|
58
|
-
" Never add, drop, or change a fact, a command, a flag, or a file name; leave out a whole point instead."
|
|
59
|
-
" Return only the rewritten reply, with no preface."
|
|
60
|
-
)
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
"""Constants for the reply length gate PreToolUse hook."""
|
|
2
|
-
|
|
3
|
-
import re
|
|
4
|
-
|
|
5
|
-
MAXIMUM_SENTENCE_COUNT = 50
|
|
6
|
-
MAXIMUM_WORDS_PER_SENTENCE = 35
|
|
7
|
-
ALL_CHECKED_TOOL_NAMES = frozenset(
|
|
8
|
-
{"mcp__hearthbot__reply", "mcp__hearthbot__post_message", "mcp__hearthbot__update_message"}
|
|
9
|
-
)
|
|
10
|
-
ALL_EDIT_TOOL_NAMES = frozenset({"mcp__hearthbot__update_message"})
|
|
11
|
-
DECISION_CARD_TOOL_NAME = "mcp__hearthbot__ask_decision"
|
|
12
|
-
CARD_TEXT_SEPARATOR = "\n"
|
|
13
|
-
ALL_DECISION_CARD_PROSE_KEYS = ("question", "context")
|
|
14
|
-
DECISION_CARD_OPTIONS_KEY = "options"
|
|
15
|
-
ALL_DECISION_OPTION_PROSE_KEYS = ("label", "consequence")
|
|
16
|
-
DECISION_CARD_CONTEXT_KEY = "context"
|
|
17
|
-
MAXIMUM_CARD_CONTEXT_SENTENCE_COUNT = 2
|
|
18
|
-
ALL_DECISION_CARD_LENGTH_KEYS = ("question", "context", "reason")
|
|
19
|
-
ALL_DECISION_OPTION_LENGTH_KEYS = ("consequence",)
|
|
20
|
-
QUESTION_CARD_TOOL_NAME = "AskUserQuestion"
|
|
21
|
-
QUESTION_CARD_QUESTIONS_KEY = "questions"
|
|
22
|
-
ALL_QUESTION_CARD_PROSE_KEYS = ("question", "header")
|
|
23
|
-
ALL_QUESTION_OPTION_PROSE_KEYS = ("label", "description")
|
|
24
|
-
TOOL_NAME_KEY = "tool_name"
|
|
25
|
-
TOOL_INPUT_KEY = "tool_input"
|
|
26
|
-
TEXT_KEY = "text"
|
|
27
|
-
TRANSCRIPT_PATH_KEY = "transcript_path"
|
|
28
|
-
HOOK_EVENT_NAME = "PreToolUse"
|
|
29
|
-
ALLOW_EXIT_CODE = 0
|
|
30
|
-
BLOCK_EXIT_CODE = 2
|
|
31
|
-
FENCED_BLOCK_PATTERN = re.compile(r"```.*?(?:```|\Z)", re.DOTALL)
|
|
32
|
-
INLINE_CODE_PATTERN = re.compile(r"`[^`\n]*`")
|
|
33
|
-
LINK_TARGET_PATTERN = re.compile(r"\]\([^)\s]*\)")
|
|
34
|
-
URL_PATTERN = re.compile(r"(?:https?://|www\.)\S+")
|
|
35
|
-
MARKDOWN_LINK_PATTERN = re.compile(r"\[[^\]\n]*\]\([^)\s]*\)")
|
|
36
|
-
UNLINKED_PULL_REQUEST_PATTERN = re.compile(
|
|
37
|
-
r"\b(?:PRs?|pull requests?)\s*#?\d+|(?<![\w/&])#\d+", re.IGNORECASE
|
|
38
|
-
)
|
|
39
|
-
MID_SENTENCE_COLON_PATTERN = re.compile(r":[ \t]+\S")
|
|
40
|
-
EM_DASH_PATTERN = re.compile("\u2014")
|
|
41
|
-
LINE_BREAK_PATTERN = re.compile(r"\n+")
|
|
42
|
-
SENTENCE_END_PATTERN = re.compile(r"(?<=[.!?])\s+")
|
|
43
|
-
WORD_PATTERN = re.compile(r"[A-Za-z0-9]+(?:['.,-][A-Za-z0-9]+)*")
|
|
44
|
-
SENTENCE_PREVIEW_WORD_COUNT = 6
|
|
45
|
-
WORD_SEPARATOR = " "
|
|
46
|
-
SENTENCE_PREVIEW_SUFFIX = "..."
|
|
47
|
-
RETRY_INSTRUCTION = " Cut the text and resend the call."
|
|
48
|
-
FIX_EVERY_ITEM_INSTRUCTION = " Fix every item above in your next write."
|
|
49
|
-
FINDING_SEPARATOR = "\n"
|
|
50
|
-
TOO_MANY_SENTENCES_MESSAGE = "Reply too long: {sentence_count} sentences, limit {sentence_limit}."
|
|
51
|
-
CARD_CONTEXT_TOO_LONG_MESSAGE = (
|
|
52
|
-
"Card context too long: {sentence_count} sentences, limit {sentence_limit}."
|
|
53
|
-
)
|
|
54
|
-
CARD_CONTEXT_LIST_MESSAGE = "Card context holds a list of items, and a card cannot format a list."
|
|
55
|
-
CARD_LIST_ITEM_PATTERN = re.compile(r"^[ \t]*(?:[-*+]|\d+[.)])[ \t]+\S", re.MULTILINE)
|
|
56
|
-
CARD_FORMAT_FLOW_INSTRUCTION = (
|
|
57
|
-
" For a list or several items, publish an Artifact page with a tap button per item"
|
|
58
|
-
" and a Send button, with the capability that republishes its state so the watching"
|
|
59
|
-
" session wakes. Then send a short reply that links the page."
|
|
60
|
-
)
|
|
61
|
-
UNLINKED_PULL_REQUEST_MESSAGE = 'Pull request "{reference}" has no link. Write it as [PR N](https://github.com/<owner>/<repo>/pull/N).'
|
|
62
|
-
MID_SENTENCE_COLON_MESSAGE = (
|
|
63
|
-
"A colon joins two clauses on one line. Write two sentences, or end the line with the colon"
|
|
64
|
-
" and put the list on the lines below."
|
|
65
|
-
)
|
|
66
|
-
EM_DASH_MESSAGE = "An em dash is in the text. Use a period or a comma."
|
|
67
|
-
CAUSAL_CLAIM_PATTERN = re.compile(
|
|
68
|
-
r"(?:^|,)\s*so\b(?!\s+far\b)|\b(?:because|caused|causes|due to|therefore|which means|that means)\b",
|
|
69
|
-
re.IGNORECASE,
|
|
70
|
-
)
|
|
71
|
-
ALL_EVIDENCE_PATTERNS = (INLINE_CODE_PATTERN, URL_PATTERN, MARKDOWN_LINK_PATTERN)
|
|
72
|
-
UNSOURCED_CAUSE_MESSAGE = (
|
|
73
|
-
'Cause with no source: "{sentence}". Quote the log line or output in backticks,'
|
|
74
|
-
" or link the run or file and line that shows it."
|
|
75
|
-
)
|
|
76
|
-
ALL_DEFAULT_BANNED_WORDS = (
|
|
77
|
-
"real",
|
|
78
|
-
"really",
|
|
79
|
-
"in reality",
|
|
80
|
-
"genuine",
|
|
81
|
-
"genuinely",
|
|
82
|
-
"actual",
|
|
83
|
-
"actually",
|
|
84
|
-
"likely",
|
|
85
|
-
"unlikely",
|
|
86
|
-
"probably",
|
|
87
|
-
"seems",
|
|
88
|
-
"seem",
|
|
89
|
-
"seemingly",
|
|
90
|
-
"suspect",
|
|
91
|
-
"guess",
|
|
92
|
-
"my theory",
|
|
93
|
-
"maybe",
|
|
94
|
-
"perhaps",
|
|
95
|
-
"presumably",
|
|
96
|
-
"might be",
|
|
97
|
-
"may be",
|
|
98
|
-
"appears to",
|
|
99
|
-
"i believe",
|
|
100
|
-
"not sure",
|
|
101
|
-
"unsure",
|
|
102
|
-
)
|
|
103
|
-
BANNED_WORD_PART_SEPARATOR = r"\s+"
|
|
104
|
-
BANNED_WORD_PATTERN_TEMPLATE = r"(?<![A-Za-z0-9]){word_pattern}(?![A-Za-z0-9])"
|
|
105
|
-
BANNED_WORDS_JSON_KEY = "banned_words"
|
|
106
|
-
BANNED_WORDS_FILE_NAME = "reply-banned-words.json"
|
|
107
|
-
BANNED_WORDS_PATH_ENV_VAR = "CLAUDE_REPLY_BANNED_WORDS_PATH"
|
|
108
|
-
CLAUDE_HOME_DIRECTORY_NAME = ".claude"
|
|
109
|
-
CONFIG_FILE_ENCODING = "utf-8"
|
|
110
|
-
BANNED_WORD_MESSAGE = 'Banned word "{banned_word}". Delete it and name the evidence: the log line, the check, the file and line.'
|
|
111
|
-
LONG_SENTENCE_MESSAGE = (
|
|
112
|
-
'Sentence too long: {word_count} words, limit {word_limit}: "{sentence_preview}".'
|
|
113
|
-
)
|
|
114
|
-
CURLY_APOSTROPHE = "\u2019"
|
|
115
|
-
STRAIGHT_APOSTROPHE = "'"
|
|
116
|
-
QUANTITY_PATTERN = (
|
|
117
|
-
r"(?:\d+(?:\.\d+)?|an?|one|two|three|four|five|six|seven|eight|nine|ten"
|
|
118
|
-
r"|eleven|twelve|(?:thir|four|fif|six|seven|eigh|nine)teen"
|
|
119
|
-
r"|twenty|thirty|forty(?:-five)?|fifty|sixty|seventy|eighty|ninety"
|
|
120
|
-
r"|(?:an?\s+|one\s+)?hundred|half an?|a couple(?: of)?|a few|several)"
|
|
121
|
-
)
|
|
122
|
-
DURATION_UNIT_PATTERN = r"(?:hours?|hrs?|minutes?|mins?|seconds?|secs?|days?|weeks?)"
|
|
123
|
-
NEGATION_PATTERN = (
|
|
124
|
-
r"(?:(?:did|have|has|could|was|were|is|are)(?:\s+not|n't)|can(?:not|'t)|not\s+yet|never)"
|
|
125
|
-
)
|
|
126
|
-
FIRST_PERSON_PATTERN = r"(?:i|we)"
|
|
127
|
-
CHECK_VERB_PATTERN = r"(?:confirm|verif(?:y|ied)|validate|check|test)(?:ed)?"
|
|
128
|
-
CHECKED_PARTICIPLE_PATTERN = r"(?:confirmed|verified|validated|tested|checked(?!\s+(?:in|out)\b))"
|
|
129
|
-
PASSIVE_NEGATION_PATTERN = (
|
|
130
|
-
r"(?:(?:has|have)(?:\s+not|n't)(?:\s+yet)?\s+been"
|
|
131
|
-
r"|(?:was|were|is|are)(?:\s+not|n't)(?:\s+yet)?(?:\s+been)?"
|
|
132
|
-
r"|can(?:not|'t)\s+be)"
|
|
133
|
-
)
|
|
134
|
-
FILLER_WORDS_PATTERN = r"(?:(?!(?:a|an|the|what|which|something|anything)\b)\w+\s+){0,2}"
|
|
135
|
-
UNVALIDATED_CLAIM_PATTERN = re.compile(
|
|
136
|
-
r"\b(?:guess(?:es|ed|ing)?|estimat(?:e|es|ed|ing)|eta|ballpark"
|
|
137
|
-
r"|assum(?:e|es|ed|ing)|i think|i expect"
|
|
138
|
-
r"|un(?:confirmed|verified|validated|checked|tested))\b"
|
|
139
|
-
rf"|\b{FIRST_PERSON_PATTERN}\s+{NEGATION_PATTERN}\s+{FILLER_WORDS_PATTERN}{CHECK_VERB_PATTERN}\b"
|
|
140
|
-
rf"|\b{FIRST_PERSON_PATTERN}\s+{NEGATION_PATTERN}\s+{FILLER_WORDS_PATTERN}run\b(?!\s+(?:into|out)\b)"
|
|
141
|
-
rf"|\b{PASSIVE_NEGATION_PATTERN}\s+(?:{CHECKED_PARTICIPLE_PATTERN}|run)\b",
|
|
142
|
-
re.IGNORECASE,
|
|
143
|
-
)
|
|
144
|
-
DURATION_CLAIM_PATTERN = re.compile(
|
|
145
|
-
rf"\btakes?\s+(?:about\s+)?{QUANTITY_PATTERN}\s+{DURATION_UNIT_PATTERN}\b"
|
|
146
|
-
rf"|\b{QUANTITY_PATTERN}\s+(?:more\s+)?{DURATION_UNIT_PATTERN}\s+(?:left|remaining|to go)\b"
|
|
147
|
-
rf"|\b(?:about|around|approximately|roughly|another)\s+{QUANTITY_PATTERN}\s+{DURATION_UNIT_PATTERN}\b"
|
|
148
|
-
rf"|\b{QUANTITY_PATTERN}\s*(?:to|-|or)\s*{QUANTITY_PATTERN}\s+{DURATION_UNIT_PATTERN}\b",
|
|
149
|
-
re.IGNORECASE,
|
|
150
|
-
)
|
|
151
|
-
UNVALIDATED_CLAIM_MESSAGE = (
|
|
152
|
-
'No tool validated this: "{claim}". Run the check yourself or through a subagent,'
|
|
153
|
-
" then state what the run, log line, output, or file and line shows. When you cannot run it"
|
|
154
|
-
" this turn, report it as `Open: <check> - <next step>`."
|
|
155
|
-
)
|
|
156
|
-
CITED_NUMBER_PATTERN = re.compile(
|
|
157
|
-
r"/actions/runs/(\d+)|/pull/(?P<pull_number>\d+)|\b(?:run|job|check)\s+#?(\d{5,})\b",
|
|
158
|
-
re.IGNORECASE,
|
|
159
|
-
)
|
|
160
|
-
CITED_PULL_NUMBER_GROUP = "pull_number"
|
|
161
|
-
CITED_NUMBER_IN_RESULT_TEMPLATE = r"(?<!\d){number}(?!\d)"
|
|
162
|
-
PULL_LINK_IN_HOOK_TEXT_TEMPLATE = r"/pull/{number}(?!\d)"
|
|
163
|
-
UNSEEN_CITATION_MESSAGE = (
|
|
164
|
-
'The text cites "{citation}", and no tool result in this session shows it.'
|
|
165
|
-
" Read it yourself or through a subagent first."
|
|
166
|
-
)
|
|
167
|
-
ALL_REPLY_QUOTING_MESSAGES = (
|
|
168
|
-
UNSEEN_CITATION_MESSAGE,
|
|
169
|
-
UNVALIDATED_CLAIM_MESSAGE,
|
|
170
|
-
UNSOURCED_CAUSE_MESSAGE,
|
|
171
|
-
LONG_SENTENCE_MESSAGE,
|
|
172
|
-
)
|
|
173
|
-
MESSAGE_PLACEHOLDER_PATTERN = re.compile(r"\\\{\w+\\\}")
|
|
174
|
-
REPLY_ECHO_PATTERN = re.compile(
|
|
175
|
-
"|".join(
|
|
176
|
-
MESSAGE_PLACEHOLDER_PATTERN.sub(".*?", re.escape(each_message))
|
|
177
|
-
for each_message in ALL_REPLY_QUOTING_MESSAGES
|
|
178
|
-
)
|
|
179
|
-
)
|
|
180
|
-
|
|
181
|
-
ADDITIONAL_CONTEXT_KEY = "additionalContext"
|
|
182
|
-
ALL_CHECKED_MCP_TOOL_NAMES = frozenset(
|
|
183
|
-
{
|
|
184
|
-
"mcp__github__add_issue_comment",
|
|
185
|
-
"mcp__github__update_issue_comment",
|
|
186
|
-
"mcp__github__add_reply_to_pull_request_comment",
|
|
187
|
-
"mcp__github__add_comment_to_pending_review",
|
|
188
|
-
"mcp__github__pull_request_review_write",
|
|
189
|
-
}
|
|
190
|
-
)
|
|
191
|
-
BASH_TOOL_NAME = "Bash"
|
|
192
|
-
COMMAND_KEY = "command"
|
|
193
|
-
SHELL_OPERATOR_CHARACTERS = frozenset("&|;")
|
|
194
|
-
GH_PROGRAM_NAME = "gh"
|
|
195
|
-
ALL_GH_COMMENT_GROUPS = frozenset({"pr", "issue"})
|
|
196
|
-
ALL_GH_COMMENT_ACTIONS = frozenset({"comment", "review"})
|
|
197
|
-
ALL_GH_BODY_FLAGS = frozenset({"--body", "-b"})
|
|
198
|
-
GH_BODY_FLAG_PREFIX = "--body="
|
|
199
|
-
DETAILS_BLOCK_PATTERN = re.compile(r"<details\b.*?</details>", re.IGNORECASE | re.DOTALL)
|
|
200
|
-
COMMENT_RETRY_INSTRUCTION = (
|
|
201
|
-
f" A comment on GitHub holds at most {MAXIMUM_SENTENCE_COUNT} short sentences."
|
|
202
|
-
" Put detail in the pull request body, a code block, or a collapsed <details> block, then post again."
|
|
203
|
-
)
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
from hooks_constants import reply_length_gate_constants as constants
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
def test_gate_limits_replies_to_fifty_sentences_of_thirty_five_words() -> None:
|
|
5
|
-
assert (constants.MAXIMUM_SENTENCE_COUNT, constants.MAXIMUM_WORDS_PER_SENTENCE) == (50, 35)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def test_gate_checks_the_three_chat_tools_that_post_to_the_user() -> None:
|
|
9
|
-
assert constants.ALL_CHECKED_TOOL_NAMES == frozenset(
|
|
10
|
-
{"mcp__hearthbot__reply", "mcp__hearthbot__post_message", "mcp__hearthbot__update_message"}
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def test_reply_echo_pattern_matches_each_message_that_quotes_the_reply() -> None:
|
|
15
|
-
quoted = 'See "the /pull/8127 link" there'
|
|
16
|
-
all_messages = [
|
|
17
|
-
constants.UNSEEN_CITATION_MESSAGE.format(citation="/pull/8127"),
|
|
18
|
-
constants.UNVALIDATED_CLAIM_MESSAGE.format(claim=quoted),
|
|
19
|
-
constants.UNSOURCED_CAUSE_MESSAGE.format(sentence=quoted),
|
|
20
|
-
constants.LONG_SENTENCE_MESSAGE.format(word_count=40, word_limit=35, sentence_preview=quoted),
|
|
21
|
-
]
|
|
22
|
-
for each_message in all_messages:
|
|
23
|
-
assert constants.REPLY_ECHO_PATTERN.sub("", f"before {each_message} after") == "before after"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
def test_cited_number_pattern_names_the_pull_request_group() -> None:
|
|
27
|
-
all_pull_numbers = [
|
|
28
|
-
each_match[constants.CITED_PULL_NUMBER_GROUP]
|
|
29
|
-
for each_match in constants.CITED_NUMBER_PATTERN.finditer("see https://github.com/o/r/pull/42, run 123456")
|
|
30
|
-
]
|
|
31
|
-
assert all_pull_numbers == ["42", None]
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
def test_gate_exit_codes_match_the_hook_contract() -> None:
|
|
35
|
-
assert (constants.ALLOW_EXIT_CODE, constants.BLOCK_EXIT_CODE) == (0, 2)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
def test_default_banned_words_hold_the_hedges_and_intensifiers() -> None:
|
|
39
|
-
assert {"likely", "probably", "seems", "real", "actually", "genuine"} <= set(
|
|
40
|
-
constants.ALL_DEFAULT_BANNED_WORDS
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
def test_gate_checks_the_project_decision_card_tool() -> None:
|
|
45
|
-
assert constants.DECISION_CARD_TOOL_NAME == "mcp__hearthbot__ask_decision"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
def test_default_banned_words_hold_the_added_hedge_phrases() -> None:
|
|
49
|
-
assert {
|
|
50
|
-
"maybe",
|
|
51
|
-
"perhaps",
|
|
52
|
-
"presumably",
|
|
53
|
-
"might be",
|
|
54
|
-
"may be",
|
|
55
|
-
"appears to",
|
|
56
|
-
"i believe",
|
|
57
|
-
"not sure",
|
|
58
|
-
"unsure",
|
|
59
|
-
} <= set(constants.ALL_DEFAULT_BANNED_WORDS)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
def test_gate_reads_only_the_prose_fields_of_a_decision_card() -> None:
|
|
63
|
-
assert (
|
|
64
|
-
constants.ALL_DECISION_CARD_PROSE_KEYS,
|
|
65
|
-
constants.DECISION_CARD_OPTIONS_KEY,
|
|
66
|
-
constants.ALL_DECISION_OPTION_PROSE_KEYS,
|
|
67
|
-
) == (("question", "context"), "options", ("label", "consequence"))
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
def test_colon_pattern_matches_a_colon_with_prose_after_it_on_the_line() -> None:
|
|
71
|
-
assert constants.MID_SENTENCE_COLON_PATTERN.search("matters: one message")
|
|
72
|
-
assert constants.MID_SENTENCE_COLON_PATTERN.search("at 9:47") is None
|
|
73
|
-
assert constants.MID_SENTENCE_COLON_PATTERN.search("items:\n- one") is None
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
def test_gate_caps_card_context_at_two_sentences_and_checks_card_length_fields() -> None:
|
|
77
|
-
assert (
|
|
78
|
-
constants.MAXIMUM_CARD_CONTEXT_SENTENCE_COUNT,
|
|
79
|
-
constants.ALL_DECISION_CARD_LENGTH_KEYS,
|
|
80
|
-
constants.ALL_DECISION_OPTION_LENGTH_KEYS,
|
|
81
|
-
) == (2, ("question", "context", "reason"), ("consequence",))
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
import re
|
|
3
|
-
|
|
4
|
-
from hooks_constants import visual_reply_rules_constants as constants
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def test_hook_text_attachment_types_leave_out_blocking_errors() -> None:
|
|
8
|
-
assert "hook_blocking_error" not in constants.ALL_HOOK_TEXT_ATTACHMENT_TYPES
|
|
9
|
-
assert "hook_additional_context" in constants.ALL_HOOK_TEXT_ATTACHMENT_TYPES
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def test_rules_file_path_points_at_the_shipped_rule_list() -> None:
|
|
13
|
-
assert constants.RULES_FILE_PATH.is_file()
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def test_capitalized_abbreviation_pattern_needs_two_capitals() -> None:
|
|
17
|
-
assert constants.CAPITALIZED_ABBREVIATION_PATTERN.findall("CI and PRs, not Item or I") == ["CI", "PRs"]
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def test_tracker_number_pattern_reads_items_issues_and_cards() -> None:
|
|
21
|
-
assert [
|
|
22
|
-
each.group(0) for each in constants.TRACKER_NUMBER_PATTERN.finditer("issue 5735, item #6, card 2")
|
|
23
|
-
] == ["issue 5735", "item #6", "card 2"]
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
def test_rule_key_constants_name_rules_in_the_shipped_rule_list() -> None:
|
|
27
|
-
rules_document = json.loads(constants.RULES_FILE_PATH.read_text(encoding=constants.RULES_FILE_ENCODING))
|
|
28
|
-
all_shipped_keys = {each_rule[constants.RULE_KEY_FIELD] for each_rule in rules_document[constants.RULES_LIST_KEY]}
|
|
29
|
-
|
|
30
|
-
assert {
|
|
31
|
-
constants.NO_PICTURE_RULE_KEY,
|
|
32
|
-
constants.ABBREVIATIONS_RULE_KEY,
|
|
33
|
-
constants.ONE_ITEM_RULE_KEY,
|
|
34
|
-
constants.FLOWCHART_RULE_KEY,
|
|
35
|
-
constants.RESULTS_PICTURE_RULE_KEY,
|
|
36
|
-
} <= all_shipped_keys
|
|
37
|
-
assert constants.ALLOWED_CAPITALIZED_WORDS_KEY in rules_document
|
|
38
|
-
assert constants.LOWERCASE_ABBREVIATIONS_KEY in rules_document
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
def test_lowercase_abbreviation_template_matches_the_word_on_its_own_only() -> None:
|
|
42
|
-
pattern = re.compile(constants.LOWERCASE_ABBREVIATION_TEMPLATE.format(abbreviation=re.escape("repo")))
|
|
43
|
-
|
|
44
|
-
assert pattern.findall("the repo, my repos, a repo2 tag") == ["repo"]
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
def test_widget_anchor_pattern_matches_a_link_and_skips_other_tags() -> None:
|
|
48
|
-
assert constants.WIDGET_ANCHOR_PATTERN.search('<A class="x" HREF="https://example.com">')
|
|
49
|
-
assert constants.WIDGET_ANCHOR_PATTERN.search('<abbr title="a">') is None
|
|
50
|
-
assert constants.WIDGET_ANCHOR_PATTERN.search("<a>no link</a>") is None
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"""Constants for the visual reply mode checks in the reply length gate."""
|
|
2
|
-
|
|
3
|
-
import re
|
|
4
|
-
from pathlib import Path
|
|
5
|
-
|
|
6
|
-
RULES_FILE_PATH = (
|
|
7
|
-
Path(__file__).resolve().parent.parent.parent / "rules" / "visual-reply-rules.json"
|
|
8
|
-
)
|
|
9
|
-
RULES_FILE_ENCODING = "utf-8"
|
|
10
|
-
RULES_LIST_KEY = "rules"
|
|
11
|
-
RULE_KEY_FIELD = "key"
|
|
12
|
-
RULE_LABEL_FIELD = "label"
|
|
13
|
-
RULE_REMINDER_FIELD = "reminder"
|
|
14
|
-
ALLOWED_CAPITALIZED_WORDS_KEY = "allowed_capitalized_words"
|
|
15
|
-
LOWERCASE_ABBREVIATIONS_KEY = "lowercase_abbreviations"
|
|
16
|
-
|
|
17
|
-
MODE_SWITCH_FILE_NAME = "visual-reply-mode.json"
|
|
18
|
-
MODE_SWITCH_ENABLED_KEY = "enabled"
|
|
19
|
-
|
|
20
|
-
NO_PICTURE_RULE_KEY = "no_picture"
|
|
21
|
-
ABBREVIATIONS_RULE_KEY = "abbreviations"
|
|
22
|
-
ONE_ITEM_RULE_KEY = "one_item"
|
|
23
|
-
RESULTS_PICTURE_RULE_KEY = "results_picture"
|
|
24
|
-
|
|
25
|
-
WIDGET_TOOL_NAME_SUFFIX = "__post_widget"
|
|
26
|
-
ARTIFACT_TOOL_NAME = "Artifact"
|
|
27
|
-
ALL_VISUAL_TOOL_NAME_SUFFIXES = (WIDGET_TOOL_NAME_SUFFIX, ARTIFACT_TOOL_NAME)
|
|
28
|
-
ALL_REPLY_TOOL_NAME_SUFFIXES = ("__reply", "__post_message")
|
|
29
|
-
MAXIMUM_REPLIES_PER_TURN = 1
|
|
30
|
-
MAXIMUM_SENTENCES_WITHOUT_VISUAL = 1
|
|
31
|
-
|
|
32
|
-
CAPITALIZED_ABBREVIATION_PATTERN = re.compile(
|
|
33
|
-
r"(?<![A-Za-z0-9])(?=[A-Z0-9]*[A-Z][A-Z0-9]*[A-Z])[A-Z0-9]{2,}s?(?![A-Za-z0-9])"
|
|
34
|
-
)
|
|
35
|
-
LOWERCASE_ABBREVIATION_TEMPLATE = r"(?<![A-Za-z0-9]){abbreviation}(?![A-Za-z0-9])"
|
|
36
|
-
TRACKER_NUMBER_PATTERN = re.compile(
|
|
37
|
-
r"\b(?:issues?|items?|cards?|tickets?|tasks?)\s*#?\d+", re.IGNORECASE
|
|
38
|
-
)
|
|
39
|
-
WIDGET_ANCHOR_PATTERN = re.compile(r"<a\b[^>]*\bhref\s*=", re.IGNORECASE)
|
|
40
|
-
FLOWCHART_RULE_KEY = "not_flowchart"
|
|
41
|
-
WIDGET_CODE_KEY = "widget_code"
|
|
42
|
-
WIDGET_INPUT_KEY = "input"
|
|
43
|
-
FLOWCHART_SVG_PATTERN = re.compile(r"<svg\b", re.IGNORECASE)
|
|
44
|
-
FLOWCHART_ARROW_PATTERN = re.compile(r"marker-end", re.IGNORECASE)
|
|
45
|
-
FLOWCHART_MARKER_BLOCK_PATTERN = re.compile(r"<marker\b[^>]*(?<!/)>.*?</marker>", re.IGNORECASE | re.DOTALL)
|
|
46
|
-
FLOWCHART_DIAMOND_PATTERN = re.compile(
|
|
47
|
-
r"<polygon\b|<path\b[^>]*\bd=[\"']M[^\"']*L[^\"']*L[^\"']*L[^\"']*Z[\"']", re.IGNORECASE
|
|
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
|
-
|
|
67
|
-
TRANSCRIPT_ENCODING = "utf-8"
|
|
68
|
-
ENTRY_TYPE_KEY = "type"
|
|
69
|
-
USER_ENTRY_TYPE = "user"
|
|
70
|
-
ASSISTANT_ENTRY_TYPE = "assistant"
|
|
71
|
-
MESSAGE_KEY = "message"
|
|
72
|
-
CONTENT_KEY = "content"
|
|
73
|
-
BLOCK_TYPE_KEY = "type"
|
|
74
|
-
BLOCK_NAME_KEY = "name"
|
|
75
|
-
TEXT_BLOCK_TYPE = "text"
|
|
76
|
-
TOOL_USE_BLOCK_TYPE = "tool_use"
|
|
77
|
-
TOOL_RESULT_BLOCK_TYPE = "tool_result"
|
|
78
|
-
BLOCK_ID_KEY = "id"
|
|
79
|
-
TOOL_USE_ID_KEY = "tool_use_id"
|
|
80
|
-
IS_ERROR_KEY = "is_error"
|
|
81
|
-
IS_META_KEY = "isMeta"
|
|
82
|
-
BLOCK_TEXT_KEY = "text"
|
|
83
|
-
RESULT_TEXT_SEPARATOR = "\n"
|
|
84
|
-
ATTACHMENT_ENTRY_TYPE = "attachment"
|
|
85
|
-
ATTACHMENT_KEY = "attachment"
|
|
86
|
-
QUEUED_COMMAND_ATTACHMENT_TYPE = "queued_command"
|
|
87
|
-
ALL_HOOK_TEXT_ATTACHMENT_TYPES = frozenset(
|
|
88
|
-
{"hook_additional_context", "hook_system_message", QUEUED_COMMAND_ATTACHMENT_TYPE}
|
|
89
|
-
)
|
|
90
|
-
ALL_ATTACHMENT_TEXT_KEYS = ("content", "prompt")
|
|
91
|
-
ALL_HOOK_MESSAGE_PREFIXES = ("Stop hook feedback:", "<system-reminder>")
|
|
92
|
-
ORIGIN_KEY = "origin"
|
|
93
|
-
ORIGIN_KIND_KEY = "kind"
|
|
94
|
-
TASK_NOTIFICATION_ORIGIN_KIND = "task-notification"
|
|
95
|
-
|
|
96
|
-
ABBREVIATION_MESSAGE = 'Abbreviation "{abbreviation}" in the text. {reminder}'
|
|
97
|
-
TRACKER_NUMBER_MESSAGE = 'Tracker number "{reference}" in the text. {reminder}'
|
|
98
|
-
VIOLATION_LINE_SEPARATOR = "\n"
|
|
99
|
-
NO_VISUAL_MESSAGE = "This reply has {sentence_count} sentences and no visual this turn. {reminder}"
|
|
100
|
-
SECOND_REPLY_MESSAGE = "A reply already went out this turn. {reminder}"
|
|
101
|
-
NOT_FLOWCHART_MESSAGE = "This widget is not a flowchart. {reminder}"
|
|
102
|
-
WIDGET_ANCHOR_MESSAGE = (
|
|
103
|
-
"A link sits inside the widget code, and a widget link does not open in the Claude app."
|
|
104
|
-
" Remove the anchor and put the page link in the reply text."
|
|
105
|
-
)
|
|
106
|
-
RESULTS_PICTURE_MESSAGE = "This reply reports results with no picture attached. {reminder}"
|