claude-dev-env 8.120.0 → 8.122.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/ever-registered-hooks.mjs +2 -0
- package/docs/rule-guides/question-presentation.md +4 -0
- package/hooks/advisory/auto_mode_denial_quick_fix.py +275 -27
- package/hooks/advisory/auto_mode_rule_flow_eval/auto_mode_rule_flow_cases.json +3475 -0
- package/hooks/advisory/auto_mode_rule_flow_eval/auto_mode_rule_flow_runner.py +849 -0
- package/hooks/advisory/auto_mode_rule_flow_eval/stub_allow_hook.py +20 -0
- package/hooks/advisory/auto_mode_rule_flow_eval/stub_hold_hook.py +54 -0
- package/hooks/advisory/auto_mode_rule_flow_eval/test_auto_mode_rule_flow_runner.py +143 -0
- package/hooks/advisory/test_auto_mode_denial_quick_fix.py +533 -9
- package/hooks/auto_mode_question_transcript.py +215 -0
- package/hooks/auto_mode_refusal_ledger.py +481 -0
- package/hooks/auto_mode_refusal_ledger_files.py +336 -0
- package/hooks/auto_mode_rule_steps.py +177 -0
- package/hooks/blocking/auto_mode_refusal_stop_gate.py +384 -0
- package/hooks/blocking/sent_file_question_detector.py +340 -0
- package/hooks/blocking/sent_file_question_gate.py +307 -0
- package/hooks/blocking/sent_file_scan.py +209 -0
- package/hooks/blocking/test_auto_mode_refusal_stop_gate.py +484 -0
- package/hooks/blocking/test_sent_file_question_detector.py +68 -0
- package/hooks/blocking/test_sent_file_question_gate.py +688 -0
- package/hooks/blocking/test_sent_file_scan.py +71 -0
- package/hooks/blocking/test_user_step_wording.py +46 -0
- package/hooks/blocking/user_step_wording.py +113 -15
- package/hooks/features/README.md +1 -1
- package/hooks/features/conduct-gates.md +3 -0
- package/hooks/features/session-context.md +5 -2
- package/hooks/hooks.json +15 -0
- package/hooks/hooks_constants/auto_mode_denial_quick_fix_constants.py +51 -3
- package/hooks/hooks_constants/auto_mode_refusal_ledger_constants.py +85 -0
- package/hooks/hooks_constants/auto_mode_refusal_stop_gate_constants.py +80 -0
- package/hooks/hooks_constants/auto_mode_rule_flow_runner_constants.py +225 -0
- package/hooks/hooks_constants/auto_mode_rule_steps_constants.py +82 -0
- package/hooks/hooks_constants/sent_file_question_gate_constants.py +261 -0
- package/hooks/hooks_constants/user_step_wording_constants.py +4 -0
- package/hooks/test_auto_mode_question_transcript.py +113 -0
- package/hooks/test_auto_mode_refusal_ledger.py +398 -0
- package/hooks/test_auto_mode_refusal_ledger_files.py +155 -0
- package/hooks/test_auto_mode_rule_steps.py +210 -0
- package/package.json +1 -1
- package/scripts/policy_lint/adapter_configuration.py +10 -0
- package/scripts/policy_lint/config/constants.py +2 -0
- package/scripts/tests/test_adapter_configuration.py +16 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"""Constants for the gate that keeps questions for the user out of sent files and pages."""
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"ALLOW_EXIT_CODE",
|
|
7
|
+
"ALL_ANSWER_SAVING_CAPABILITIES",
|
|
8
|
+
"ALL_BOLD_MARKS",
|
|
9
|
+
"ALL_FULL_WIDTH_QUESTION_MARKS",
|
|
10
|
+
"ALL_INDENTED_CODE_PREFIXES",
|
|
11
|
+
"ALL_QUOTED_QUESTION_ENDINGS",
|
|
12
|
+
"ALL_SKIPPED_PUBLISH_INPUT_KEYS",
|
|
13
|
+
"ANSWER_LABEL_PATTERN",
|
|
14
|
+
"ANSWER_OPENER_PATTERN",
|
|
15
|
+
"ARTIFACT_ACTION_INPUT_KEY",
|
|
16
|
+
"ARTIFACT_CAPABILITIES_INPUT_KEY",
|
|
17
|
+
"ARTIFACT_FILE_PATH_INPUT_KEY",
|
|
18
|
+
"ARTIFACT_PUBLISH_ACTION",
|
|
19
|
+
"ARTIFACT_TOOL_NAME",
|
|
20
|
+
"BINARY_READ_MODE",
|
|
21
|
+
"BLOCK_BREAK",
|
|
22
|
+
"BLOCK_EXIT_CODE",
|
|
23
|
+
"BOLD_MARK_COUNT",
|
|
24
|
+
"CHECK_BLOCK_WORD_PATTERN",
|
|
25
|
+
"CHOICE_COMMAND_PATTERN",
|
|
26
|
+
"CLOSING_TAG_MARK",
|
|
27
|
+
"CWD_KEY",
|
|
28
|
+
"EMPHASIS_CHARACTERS",
|
|
29
|
+
"EMPHASIS_PATTERN",
|
|
30
|
+
"FILE_PARTS_SEPARATOR",
|
|
31
|
+
"FILE_PART_BYTES",
|
|
32
|
+
"FILE_PATH_SEPARATOR",
|
|
33
|
+
"GATE_EVENT_NAME",
|
|
34
|
+
"HEADING_CLOSE_MARKS",
|
|
35
|
+
"HEADING_MARK",
|
|
36
|
+
"HEADING_OPENER_PATTERN",
|
|
37
|
+
"LABEL_CHOICE_PATTERN",
|
|
38
|
+
"LABEL_COLON",
|
|
39
|
+
"LINE_BREAK",
|
|
40
|
+
"LIST_MARKER_PATTERN",
|
|
41
|
+
"MAXIMUM_CHOICE_WORDS",
|
|
42
|
+
"MAXIMUM_QUOTED_CHARACTERS",
|
|
43
|
+
"MAXIMUM_SENTENCE_CHARACTERS",
|
|
44
|
+
"MAXIMUM_UTF8_CONTINUATION_BYTES",
|
|
45
|
+
"MAXIMUM_WHOLE_FILE_BYTES",
|
|
46
|
+
"NUL_BYTE",
|
|
47
|
+
"OPEN_ASK_PATTERN",
|
|
48
|
+
"PARSED_READ_BUDGET_SECONDS",
|
|
49
|
+
"PARTIAL_READ_MESSAGE",
|
|
50
|
+
"PARTIAL_READ_NOTE",
|
|
51
|
+
"PLAIN_HEADING_BREAK",
|
|
52
|
+
"PLAIN_READ_BUDGET_SECONDS",
|
|
53
|
+
"QUESTION_FOUND_MESSAGE",
|
|
54
|
+
"QUESTION_LABEL_PATTERN",
|
|
55
|
+
"QUESTION_MARK",
|
|
56
|
+
"QUESTION_SECTION_PATTERN",
|
|
57
|
+
"QUOTED_SPAN_PATTERN",
|
|
58
|
+
"QUOTE_CUT_MARK",
|
|
59
|
+
"READER_ADDRESS_PATTERN",
|
|
60
|
+
"READER_CHOICE_PATTERN",
|
|
61
|
+
"READER_WISH_PATTERN",
|
|
62
|
+
"REPLY_OPTION_PATTERN",
|
|
63
|
+
"REPLY_REQUEST_PATTERN",
|
|
64
|
+
"REQUEST_OPENER_PATTERN",
|
|
65
|
+
"RESPONSE_PROMPT_PATTERN",
|
|
66
|
+
"SCAN_TIMEOUT_MESSAGE",
|
|
67
|
+
"SENTENCE_EDGE_CHARACTERS",
|
|
68
|
+
"SENTENCE_EDGE_JOIN",
|
|
69
|
+
"SENTENCE_PATTERN",
|
|
70
|
+
"SPACE",
|
|
71
|
+
"SPACE_RUN_PATTERN",
|
|
72
|
+
"SYSTEM_MESSAGE_KEY",
|
|
73
|
+
"TABLE_CELL_SEPARATOR",
|
|
74
|
+
"TABLE_DIVIDER_CELL_PATTERN",
|
|
75
|
+
"TABLE_ROW_PATTERN",
|
|
76
|
+
"TAG_CLOSE",
|
|
77
|
+
"TAG_OPEN",
|
|
78
|
+
"TASK_BOX_MARK",
|
|
79
|
+
"TASK_BOX_PATTERN",
|
|
80
|
+
"TASK_CHECK_PATTERN",
|
|
81
|
+
"TOOL_INPUT_KEY",
|
|
82
|
+
"TOOL_NAME_KEY",
|
|
83
|
+
"TRAILING_CLOSERS",
|
|
84
|
+
"TRAILING_MARKS",
|
|
85
|
+
"UNIT_START_PATTERN",
|
|
86
|
+
"UTF8_CONTINUATION_BYTES",
|
|
87
|
+
"UTF8_ENCODING",
|
|
88
|
+
"WH_CHOICE_PATTERN",
|
|
89
|
+
"WRITER_VOICE_HEADING_PATTERN",
|
|
90
|
+
"YES_OR_NO_REQUEST_PATTERN",
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
ALLOW_EXIT_CODE = 0
|
|
94
|
+
BLOCK_EXIT_CODE = 2
|
|
95
|
+
GATE_EVENT_NAME = "PreToolUse"
|
|
96
|
+
TOOL_NAME_KEY = "tool_name"
|
|
97
|
+
TOOL_INPUT_KEY = "tool_input"
|
|
98
|
+
CWD_KEY = "cwd"
|
|
99
|
+
ARTIFACT_TOOL_NAME = "Artifact"
|
|
100
|
+
ARTIFACT_ACTION_INPUT_KEY = "action"
|
|
101
|
+
ARTIFACT_PUBLISH_ACTION = "publish"
|
|
102
|
+
ARTIFACT_FILE_PATH_INPUT_KEY = "file_path"
|
|
103
|
+
ARTIFACT_CAPABILITIES_INPUT_KEY = "capabilities"
|
|
104
|
+
ALL_SKIPPED_PUBLISH_INPUT_KEYS = ("asset", "type_url")
|
|
105
|
+
LINE_BREAK = "\n"
|
|
106
|
+
HEADING_MARK = "# "
|
|
107
|
+
QUESTION_MARK = "?"
|
|
108
|
+
TRAILING_MARKS = "*_\"'’”)] \t"
|
|
109
|
+
TABLE_CELL_SEPARATOR = "|"
|
|
110
|
+
TRAILING_CLOSERS = "*_)] \t"
|
|
111
|
+
ALL_QUOTED_QUESTION_ENDINGS = ('?"', "?'", "?’", "?”")
|
|
112
|
+
MAXIMUM_CHOICE_WORDS = 10
|
|
113
|
+
QUOTED_SPAN_PATTERN = re.compile(r'"[^"\n]{1,400}"|“[^”\n]{1,400}”')
|
|
114
|
+
HEADING_OPENER_PATTERN = re.compile(r"#{1,6}(?:[ \t]|$)")
|
|
115
|
+
HEADING_CLOSE_MARKS = "#"
|
|
116
|
+
ALL_BOLD_MARKS = ("**", "__")
|
|
117
|
+
EMPHASIS_CHARACTERS = "*_"
|
|
118
|
+
LABEL_COLON = ":"
|
|
119
|
+
ALL_INDENTED_CODE_PREFIXES = (" ", "\t")
|
|
120
|
+
ALL_FULL_WIDTH_QUESTION_MARKS = ("\uff1f", "\ufe56")
|
|
121
|
+
ALL_ANSWER_SAVING_CAPABILITIES = frozenset({"artifact", "self", "db"})
|
|
122
|
+
FILE_PART_BYTES = 131072
|
|
123
|
+
MAXIMUM_WHOLE_FILE_BYTES = 262144
|
|
124
|
+
BOLD_MARK_COUNT = 2
|
|
125
|
+
BINARY_READ_MODE = "rb"
|
|
126
|
+
NUL_BYTE = b"\x00"
|
|
127
|
+
UTF8_ENCODING = "utf-8"
|
|
128
|
+
UTF8_CONTINUATION_BYTES = range(0x80, 0xC0)
|
|
129
|
+
MAXIMUM_UTF8_CONTINUATION_BYTES = 3
|
|
130
|
+
FILE_PARTS_SEPARATOR = "\n\n"
|
|
131
|
+
MAXIMUM_QUOTED_CHARACTERS = 160
|
|
132
|
+
QUOTE_CUT_MARK = "..."
|
|
133
|
+
TABLE_ROW_PATTERN = re.compile(r"^\s*\|")
|
|
134
|
+
TABLE_DIVIDER_CELL_PATTERN = re.compile(r"^:?-+:?$")
|
|
135
|
+
LIST_MARKER_PATTERN = re.compile(r"^\s*(?:[-*+]|\d{1,3}[.)])\s+(?:\[[ xX]\]\s+)?")
|
|
136
|
+
QUESTION_LABEL_PATTERN = re.compile(r"^(?:q|question)\s*\d*\s*[:.]\s+", re.IGNORECASE)
|
|
137
|
+
ANSWER_LABEL_PATTERN = re.compile(r"^(?:a|answer)\s*\d*\s*[:.]\s+", re.IGNORECASE)
|
|
138
|
+
UNIT_START_PATTERN = re.compile(
|
|
139
|
+
r"^\s{0,3}#{1,6}\s|^\s*(?:\*\*|__)|^\s*\||^\s*(?:[-*+]|\d{1,3}[.)])\s+|^(?:q|question|a|answer)\s*\d*\s*[:.]\s+",
|
|
140
|
+
re.IGNORECASE,
|
|
141
|
+
)
|
|
142
|
+
EMPHASIS_PATTERN = re.compile(r"(?<!\w)[*_]{1,3}|[*_]{1,3}(?!\w)")
|
|
143
|
+
SPACE_RUN_PATTERN = re.compile(r"\s+")
|
|
144
|
+
SENTENCE_PATTERN = re.compile(r"\S.*?(?:[.!?][\"'’”)\]*_]*(?=\s|$)|$)")
|
|
145
|
+
QUESTION_SECTION_PATTERN = re.compile(
|
|
146
|
+
r"(?:open|pending|outstanding|unresolved|remaining|unanswered)\s+questions?(?:\s+.*)?"
|
|
147
|
+
r"|questions?\s+(?:for|to|from)\b.*"
|
|
148
|
+
r"|(?:open|pending|outstanding|unresolved|remaining)\s+decisions?(?:\s+.*)?"
|
|
149
|
+
r"|decisions?\s+(?:needed|required|pending|to\s+make|for)\b.*"
|
|
150
|
+
r"|(?:need|needs|needed)\s+(?:your|you\s+to)\b.*",
|
|
151
|
+
re.IGNORECASE,
|
|
152
|
+
)
|
|
153
|
+
READER_ADDRESS_PATTERN = re.compile(r"\b(?:you|your|yours|yourself)\b", re.IGNORECASE)
|
|
154
|
+
READER_WISH_PATTERN = re.compile(
|
|
155
|
+
r"\b(?:me|want|wants|prefer|like|approve|agree|think|mind|rather|ok|okay|happy|decide|choose|pick)\b",
|
|
156
|
+
re.IGNORECASE,
|
|
157
|
+
)
|
|
158
|
+
READER_CHOICE_PATTERN = re.compile(r"\bor\b", re.IGNORECASE)
|
|
159
|
+
REQUEST_OPENER_PATTERN = re.compile(
|
|
160
|
+
r"^(?:(?:so|and|also|then|now|ok|okay)\b,?\s+)?"
|
|
161
|
+
r"(?:(?:should|shall)\s+(?:i|we)\b"
|
|
162
|
+
r"|want\s+me\b"
|
|
163
|
+
r"|(?:ok|okay|fine)\s+(?:to|if|with)\b"
|
|
164
|
+
r"|(?:is|would)\s+(?:it|that|this)\s+(?:ok|okay|alright|fine)\b"
|
|
165
|
+
r"|(?:any\s+)?(?:objections?|preferences?|thoughts)\b"
|
|
166
|
+
r"|are\s+we\s+(?:good|ready|clear|ok|okay)\b"
|
|
167
|
+
r"|would\s+it\s+(?:make\s+sense|help|be\s+better)\b"
|
|
168
|
+
r"|(?:go\s+ahead|proceed|continue|merge|ship|approve|archive|delete|keep|drop|revert|rerun|retry)\b)",
|
|
169
|
+
re.IGNORECASE,
|
|
170
|
+
)
|
|
171
|
+
ANSWER_OPENER_PATTERN = re.compile(r"^(?:yes|no|nope|yep)(?:[.,;:!]|$)", re.IGNORECASE)
|
|
172
|
+
WH_CHOICE_PATTERN = re.compile(
|
|
173
|
+
r"^(?:which|what|when|who)\b.*?\b(?:works?\s+(?:best|better)|best|better|preferred|should\s+(?:i|we))\b",
|
|
174
|
+
re.IGNORECASE,
|
|
175
|
+
)
|
|
176
|
+
TASK_BOX_PATTERN = re.compile(r"^\s*(?:[-*+]|\d{1,3}[.)])\s+\[[ xX]\]\s")
|
|
177
|
+
PARSED_READ_BUDGET_SECONDS = 4
|
|
178
|
+
PLAIN_READ_BUDGET_SECONDS = 4
|
|
179
|
+
MAXIMUM_SENTENCE_CHARACTERS = 2000
|
|
180
|
+
SENTENCE_EDGE_CHARACTERS = 400
|
|
181
|
+
SENTENCE_EDGE_JOIN = " ... "
|
|
182
|
+
TAG_OPEN = "<"
|
|
183
|
+
TAG_CLOSE = ">"
|
|
184
|
+
CLOSING_TAG_MARK = "/"
|
|
185
|
+
BLOCK_BREAK = "\n\n"
|
|
186
|
+
PLAIN_HEADING_BREAK = "\n\n# "
|
|
187
|
+
SPACE = " "
|
|
188
|
+
TASK_CHECK_PATTERN = re.compile(
|
|
189
|
+
r"^(?:did|have)\s+you\s+(?:already\s+)?"
|
|
190
|
+
r"(?:save|saved|run|ran|test|tested|push|pushed|commit|committed|update|updated"
|
|
191
|
+
r"|add|added|remove|removed|check|checked|read|install|installed|restart|restarted"
|
|
192
|
+
r"|close|closed|fill\s+in|filled\s+in)\b",
|
|
193
|
+
re.IGNORECASE,
|
|
194
|
+
)
|
|
195
|
+
CHECK_BLOCK_WORD_PATTERN = re.compile(
|
|
196
|
+
r"\b(?:ok|okay|fine|good|sign(?:s|ed)?\s+off|approv\w*|happy|ready|want\w*|prefer\w*"
|
|
197
|
+
r"|decid\w*|decision|agree\w*|go\s+ahead|ship\w*|merg\w*|delet\w*"
|
|
198
|
+
r"|confirm\w*|choice\w*|choos\w*|chose\w*)\b",
|
|
199
|
+
re.IGNORECASE,
|
|
200
|
+
)
|
|
201
|
+
REPLY_REQUEST_PATTERN = re.compile(
|
|
202
|
+
r"^(?:please\s+)?(?:let\s+(?:me|us)\s+know|get\s+back\s+to\s+(?:me|us)"
|
|
203
|
+
r"|advise\s+(?:me|us|which|whether|if|on|how|when)"
|
|
204
|
+
r"|send\s+(?:me|us)\s+(?:your|(?:a|an|the)\s+(?:pick|choice|answer|reply|decision|preference|vote))"
|
|
205
|
+
r"|tell\s+(?:me|us)\s+(?:which|what|whether|if|how|when|where|who|your)"
|
|
206
|
+
r"|give\s+(?:me|us)\s+your)\b"
|
|
207
|
+
r"|^please\s+(?:advise|confirm|choose|pick|select|decide|approve|reply|respond)\b",
|
|
208
|
+
re.IGNORECASE,
|
|
209
|
+
)
|
|
210
|
+
CHOICE_COMMAND_PATTERN = re.compile(
|
|
211
|
+
r"^(?:reply|answer|respond|choose|pick|select|decide)\b", re.IGNORECASE
|
|
212
|
+
)
|
|
213
|
+
REPLY_OPTION_PATTERN = re.compile(
|
|
214
|
+
r"\byes\s+or\s+no\b|\bone\s+of\s+(?:the\s+)?(?:two|three|four|both|these|those|them)\b",
|
|
215
|
+
re.IGNORECASE,
|
|
216
|
+
)
|
|
217
|
+
YES_OR_NO_REQUEST_PATTERN = re.compile(
|
|
218
|
+
r"(?:^|,\s*|\bplease\s+)(?:reply|answer|respond|choose|pick)\s+(?:\w+\s+){0,3}?yes\s+or\s+no\b",
|
|
219
|
+
re.IGNORECASE,
|
|
220
|
+
)
|
|
221
|
+
LABEL_CHOICE_PATTERN = re.compile(
|
|
222
|
+
r"\b(?:[A-Z0-9]|[Oo]ption\s+\w+)\s+or\s+(?:[A-Z0-9]|[Oo]ption\s+\w+)\b"
|
|
223
|
+
)
|
|
224
|
+
TASK_BOX_MARK = "- [ ] "
|
|
225
|
+
WRITER_VOICE_HEADING_PATTERN = re.compile(
|
|
226
|
+
r"\b(?:should|shall)\s+(?:i|we)\b|\b(?:do|would|will|can)\s+you\b"
|
|
227
|
+
r"|\bwant\s+me\b|\byour\b|\bprefer\w*",
|
|
228
|
+
re.IGNORECASE,
|
|
229
|
+
)
|
|
230
|
+
SYSTEM_MESSAGE_KEY = "systemMessage"
|
|
231
|
+
FILE_PATH_SEPARATOR = ", "
|
|
232
|
+
SCAN_TIMEOUT_MESSAGE = (
|
|
233
|
+
"sent_file_question_gate could not finish reading {file_paths} within {budget_seconds} s, "
|
|
234
|
+
"with the HTML parser or with the plain tag-stripping read, "
|
|
235
|
+
"so it did not check them for questions for the user. "
|
|
236
|
+
"Ask any question through AskUserQuestion (Codex: request_user_input), not inside the file."
|
|
237
|
+
)
|
|
238
|
+
PARTIAL_READ_NOTE = (
|
|
239
|
+
" The gate read only the first and last 128 KB of {file_path}, which is over 256 KB."
|
|
240
|
+
)
|
|
241
|
+
PARTIAL_READ_MESSAGE = (
|
|
242
|
+
"sent_file_question_gate read only the first and last 128 KB of {file_paths}, "
|
|
243
|
+
"which is over 256 KB, and found no question for the user there. "
|
|
244
|
+
"The middle of the file was not checked."
|
|
245
|
+
)
|
|
246
|
+
OPEN_ASK_PATTERN = re.compile(r"^(?:can|could|may)\s+(?:i|we)\b", re.IGNORECASE)
|
|
247
|
+
RESPONSE_PROMPT_PATTERN = re.compile(
|
|
248
|
+
r"^(?:please\s+)?(?:reply|answer|respond|confirm|choose|pick|select|say|type|tell\s+me|let\s+me\s+know)\b",
|
|
249
|
+
re.IGNORECASE,
|
|
250
|
+
)
|
|
251
|
+
QUESTION_FOUND_MESSAGE = (
|
|
252
|
+
'{file_path} carries a question for the user: "{question}". '
|
|
253
|
+
"A question inside a sent file or page reaches the user with no answer card, "
|
|
254
|
+
"and the user may read only the question cards. "
|
|
255
|
+
"Ask each question through AskUserQuestion (Codex: request_user_input), one question per card, "
|
|
256
|
+
"with its context and each choice's effect in the card. "
|
|
257
|
+
"Remove the questions from the file, keep its facts and context, and send it again. "
|
|
258
|
+
"A page that collects the answer itself, such as option cards, declares the db or artifact "
|
|
259
|
+
"capability that saves the answer, and this gate lets it through. "
|
|
260
|
+
"When the line asks the user nothing, reword it as a statement."
|
|
261
|
+
)
|
|
@@ -70,6 +70,10 @@ ALL_HTML_INLINE_TAGS = frozenset(
|
|
|
70
70
|
}
|
|
71
71
|
)
|
|
72
72
|
HTML_LINE_BREAK_TAG = "br"
|
|
73
|
+
HTML_INPUT_TAG = "input"
|
|
74
|
+
HTML_INPUT_TYPE_ATTRIBUTE = "type"
|
|
75
|
+
HTML_CHECKBOX_INPUT_TYPE = "checkbox"
|
|
76
|
+
ALL_HTML_HEADING_TAGS = frozenset({"h1", "h2", "h3", "h4", "h5", "h6", "summary", "dt"})
|
|
73
77
|
HTML_SOURCE_SPACE_PATTERN = re.compile(r"[ \t\r\n\f]+")
|
|
74
78
|
HTML_SOURCE_SPACE = " "
|
|
75
79
|
HTML_BLOCK_SEPARATOR = "\n\n"
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"""Behavior tests for the AskUserQuestion transcript reader."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from auto_mode_question_transcript import (
|
|
9
|
+
AskedQuestions,
|
|
10
|
+
TranscriptCall,
|
|
11
|
+
TranscriptReading,
|
|
12
|
+
read_asked_questions,
|
|
13
|
+
read_tool_calls,
|
|
14
|
+
read_transcript,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _ask_records(tool_use_id: str, tool_use_result: object) -> list[dict[str, object]]:
|
|
19
|
+
return [
|
|
20
|
+
{
|
|
21
|
+
"type": "assistant",
|
|
22
|
+
"message": {
|
|
23
|
+
"content": [{"type": "tool_use", "id": tool_use_id, "name": "AskUserQuestion"}]
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"type": "user",
|
|
28
|
+
"toolUseResult": tool_use_result,
|
|
29
|
+
"message": {"content": [{"type": "tool_result", "tool_use_id": tool_use_id}]},
|
|
30
|
+
},
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_should_read_each_answered_ask_with_the_offset_of_its_call(tmp_path: Path) -> None:
|
|
35
|
+
transcript_path = tmp_path / "transcript.jsonl"
|
|
36
|
+
all_records = _ask_records(
|
|
37
|
+
"toolu_error", "Error: The question could not be shown."
|
|
38
|
+
) + _ask_records("toolu_ok", {"answers": {"Q?": "Allow it"}})
|
|
39
|
+
all_lines = ["not json"] + [json.dumps(each_record) for each_record in all_records]
|
|
40
|
+
transcript_path.write_text("\n".join(all_lines) + "\n", encoding="utf-8")
|
|
41
|
+
third_record_offset = sum(len(each_line) + 1 for each_line in all_lines[:3])
|
|
42
|
+
assert read_asked_questions(transcript_path) == [
|
|
43
|
+
AskedQuestions(call_offset=third_record_offset, answer_by_question={"Q?": "Allow it"})
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_should_read_nothing_from_a_missing_transcript(tmp_path: Path) -> None:
|
|
48
|
+
assert read_asked_questions(tmp_path / "missing.jsonl") == []
|
|
49
|
+
assert read_asked_questions(None) == []
|
|
50
|
+
assert read_tool_calls(tmp_path / "missing.jsonl") == []
|
|
51
|
+
assert read_tool_calls(None) == []
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _call_records(
|
|
55
|
+
tool_use_id: str, tool_name: str, tool_input: object, is_error: bool
|
|
56
|
+
) -> list[dict[str, object]]:
|
|
57
|
+
result_block: dict[str, object] = {"type": "tool_result", "tool_use_id": tool_use_id}
|
|
58
|
+
if is_error:
|
|
59
|
+
result_block["is_error"] = True
|
|
60
|
+
return [
|
|
61
|
+
{
|
|
62
|
+
"type": "assistant",
|
|
63
|
+
"message": {
|
|
64
|
+
"content": [
|
|
65
|
+
{"type": "tool_use", "id": tool_use_id, "name": tool_name, "input": tool_input}
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
{"type": "user", "message": {"content": [result_block]}},
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def test_should_read_each_finished_call_with_its_input_offset_and_error_flag(
|
|
74
|
+
tmp_path: Path,
|
|
75
|
+
) -> None:
|
|
76
|
+
transcript_path = tmp_path / "transcript.jsonl"
|
|
77
|
+
all_records = (
|
|
78
|
+
_call_records("toolu_1", "Bash", {"command": "ls"}, is_error=False)
|
|
79
|
+
+ _call_records("toolu_2", "mcp__hearthbot__ask_decision", {"question": "Q?"}, True)
|
|
80
|
+
+ [
|
|
81
|
+
{
|
|
82
|
+
"type": "assistant",
|
|
83
|
+
"message": {
|
|
84
|
+
"content": [{"type": "tool_use", "id": "toolu_3", "name": "Bash", "input": {}}]
|
|
85
|
+
},
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
)
|
|
89
|
+
all_lines = [json.dumps(each_record) for each_record in all_records]
|
|
90
|
+
transcript_path.write_text("\n".join(all_lines) + "\n", encoding="utf-8")
|
|
91
|
+
second_call_offset = sum(len(each_line) + 1 for each_line in all_lines[:2])
|
|
92
|
+
assert read_tool_calls(transcript_path) == [
|
|
93
|
+
TranscriptCall(0, "Bash", {"command": "ls"}, is_error=False),
|
|
94
|
+
TranscriptCall(
|
|
95
|
+
second_call_offset, "mcp__hearthbot__ask_decision", {"question": "Q?"}, is_error=True
|
|
96
|
+
),
|
|
97
|
+
]
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def test_should_read_asks_and_calls_in_one_pass_equal_to_the_two_readers(tmp_path: Path) -> None:
|
|
101
|
+
transcript_path = tmp_path / "transcript.jsonl"
|
|
102
|
+
all_records = _ask_records("toolu_one", {"answers": {"Q?": "Keep refusing"}})
|
|
103
|
+
transcript_path.write_text(
|
|
104
|
+
"".join(json.dumps(each_record) + "\n" for each_record in all_records), encoding="utf-8"
|
|
105
|
+
)
|
|
106
|
+
reading = read_transcript(transcript_path)
|
|
107
|
+
assert reading == TranscriptReading(
|
|
108
|
+
all_asked=read_asked_questions(transcript_path),
|
|
109
|
+
all_calls=read_tool_calls(transcript_path),
|
|
110
|
+
)
|
|
111
|
+
assert reading.all_asked == [AskedQuestions(0, {"Q?": "Keep refusing"})]
|
|
112
|
+
assert [each.tool_name for each in reading.all_calls] == ["AskUserQuestion"]
|
|
113
|
+
assert read_transcript(tmp_path / "missing.jsonl") == TranscriptReading([], [])
|