claude-dev-env 8.124.0 → 8.126.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 +1 -0
- package/bin/ever-registered-hooks.test.mjs +4 -0
- package/bin/install-constants.mjs +5 -0
- package/bin/install-constants.test.mjs +29 -0
- package/bin/install.mjs +15 -15
- package/bin/install.test.mjs +6 -2
- package/bin/profile-stop-gate.mjs +99 -70
- package/bin/profile-stop-gate.test.mjs +230 -12
- package/docs/agents-guidance/asks.md +1 -1
- package/docs/rule-guides/question-presentation.md +1 -1
- package/hooks/blocking/closing_reply_judge.py +332 -0
- package/hooks/blocking/closing_reply_shapes.py +365 -0
- package/hooks/blocking/conftest.py +84 -0
- package/hooks/blocking/open_tasks_stop_gate.py +247 -10
- package/hooks/blocking/open_tasks_transcript.py +25 -2
- package/hooks/blocking/open_tasks_transcript_records.py +10 -0
- package/hooks/blocking/question_brief_gate.py +6 -4
- package/hooks/blocking/test_closing_reply_judge.py +246 -0
- package/hooks/blocking/test_closing_reply_shapes.py +247 -0
- package/hooks/blocking/test_open_tasks_stop_gate.py +562 -0
- package/hooks/blocking/test_open_tasks_transcript.py +23 -0
- package/hooks/blocking/test_open_tasks_transcript_records.py +14 -0
- package/hooks/blocking/test_question_brief_gate.py +22 -0
- package/hooks/features/conduct-gates.md +7 -3
- package/hooks/hooks.json +6 -1
- package/hooks/hooks_constants/closing_reply_judge_constants.py +143 -0
- package/hooks/hooks_constants/open_tasks_stop_gate_constants.py +93 -0
- package/hooks/hooks_constants/test_hook_time_budget.py +7 -0
- package/hooks/once_per_session.py +65 -1
- package/hooks/test_once_per_session.py +35 -0
- package/package.json +1 -1
- package/scripts/gh_artifact_upload.py +3 -3
- package/scripts/policy_lint/adapter_configuration.py +6 -0
- package/scripts/policy_lint/config/constants.py +1 -0
- package/scripts/tests/test_adapter_configuration.py +8 -0
- package/scripts/tests/test_gh_artifact_upload.py +18 -0
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
"""Find two closing-reply shapes the user corrected: a promised later report, and open items sent as a list.
|
|
2
|
+
|
|
3
|
+
The open tasks Stop gate reads the reply a turn ends with. Two shapes in it
|
|
4
|
+
leave work with the user that the agent could carry itself::
|
|
5
|
+
|
|
6
|
+
flag: The benchmark table will be posted when you get back.
|
|
7
|
+
flag: I'll report back once CI ends.
|
|
8
|
+
flag: What I deferred: followed by 3 or more list or table items
|
|
9
|
+
ok: No report will follow.
|
|
10
|
+
ok: I'll merge each lint fix once the bots report back.
|
|
11
|
+
ok: Changed files: followed by 5 bullets
|
|
12
|
+
ok: Deferred: followed by 2 bullets
|
|
13
|
+
|
|
14
|
+
The promise patterns are ``when you're / are / get / come back``; a report,
|
|
15
|
+
summary, write-up, recap, or result that "will be here / waiting / ready /
|
|
16
|
+
posted" or "will follow / land / arrive / come"; ``I'll`` or ``I will``
|
|
17
|
+
report, post, send, share, update you, let you know, follow up, circle back,
|
|
18
|
+
check back, or get back to you before when, once, after, later, tomorrow, or
|
|
19
|
+
in the morning; and ``I'll report back``. A match is skipped when no, not,
|
|
20
|
+
never, none, or nothing comes before it in its sentence.
|
|
21
|
+
|
|
22
|
+
An open-item list is a run of item lines: bullets, numbered lines, and table
|
|
23
|
+
body rows. A run goes on across blank lines, indented lines, and a table's
|
|
24
|
+
header and separator rows. Its lead is the nearest non-blank line above it.
|
|
25
|
+
The lead loses its code spans and its double-quoted text first. It must
|
|
26
|
+
name open work (deferred, sidestepped, remaining, outstanding, still open,
|
|
27
|
+
open items, next steps, follow-ups, to-dos, pending, parked, and the like)
|
|
28
|
+
and hold no no, none, nothing, nobody, or zero. A lead whose every open-work
|
|
29
|
+
word has a completion word in its clause names done work, and so does a lead
|
|
30
|
+
whose last word is a completion word that is not negated::
|
|
31
|
+
|
|
32
|
+
flag: Remaining work after the merged fixes: "after" ends the clause
|
|
33
|
+
flag: What I fixed and what I deferred: "and" ends the clause
|
|
34
|
+
flag: Follow-ups not yet merged: a negated completion word
|
|
35
|
+
flag: Remaining tasks, not done: a negated last word
|
|
36
|
+
ok: I fixed the three follow-ups you flagged:
|
|
37
|
+
ok: All pending checks passed:
|
|
38
|
+
ok: Remaining tasks, now done: the last word is "done"
|
|
39
|
+
|
|
40
|
+
The completion words are fixed, closed, resolved, removed, passed, passes,
|
|
41
|
+
completed, merged, landed, addressed, finished, cleared, shipped, handled,
|
|
42
|
+
done, and covers. Not, never, or a word ending in n't before one, with an
|
|
43
|
+
optional yet or been, negates it. A clause ends at punctuation, a dash, or
|
|
44
|
+
and, or, but, while, after, before, besides, except, beyond, or plus.
|
|
45
|
+
|
|
46
|
+
Fences, HTML blocks, quoted lines, and code spans are left out of both checks,
|
|
47
|
+
and the list lead also loses its double-quoted text.
|
|
48
|
+
|
|
49
|
+
The typed prompt can ask for either shape. Before the ask check, the prompt
|
|
50
|
+
loses its ``<system-reminder>`` blocks, its ``>`` quoted lines, its code
|
|
51
|
+
spans, and any double-quoted text that holds a space. An ask counts unless a
|
|
52
|
+
negator (no, not, never, none, nothing, without, don't, do not, no need,
|
|
53
|
+
never mind) comes before it in its clause; clauses end at ``. ! ? ; ,`` or a
|
|
54
|
+
line break, and a new clause starts at the word "then". A report ask is a verb
|
|
55
|
+
ask (report back, summarize, update me, let me know, tell me when, once, or
|
|
56
|
+
how), or a bare report, summary, or recap in a clause that also names a later
|
|
57
|
+
time (when, once, after, later, tomorrow, then, at the end). A prompt that
|
|
58
|
+
opens with a harness envelope, such as ``<task-notification>``, never asks::
|
|
59
|
+
|
|
60
|
+
exempts the promise: "report back when the run ends"
|
|
61
|
+
exempts the promise: "don't stop until it is merged, then give me a summary"
|
|
62
|
+
exempts the list: "list the deferred items as bullets"
|
|
63
|
+
no exemption: "no report needed, just finish"
|
|
64
|
+
no exemption: "Fix the report page."
|
|
65
|
+
no exemption: "no list please, ask me instead"
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
from __future__ import annotations
|
|
69
|
+
|
|
70
|
+
import re
|
|
71
|
+
import sys
|
|
72
|
+
from pathlib import Path
|
|
73
|
+
from typing import NamedTuple
|
|
74
|
+
|
|
75
|
+
hooks_root_directory = str(Path(__file__).resolve().parent.parent)
|
|
76
|
+
if hooks_root_directory not in sys.path:
|
|
77
|
+
sys.path.insert(0, hooks_root_directory)
|
|
78
|
+
blocking_directory = str(Path(__file__).resolve().parent)
|
|
79
|
+
if blocking_directory not in sys.path:
|
|
80
|
+
sys.path.insert(0, blocking_directory)
|
|
81
|
+
|
|
82
|
+
from final_reply_gate import blocks_masked, prose_paragraphs
|
|
83
|
+
from hooks_constants.final_reply_gate_constants import (
|
|
84
|
+
ALL_HTML_BLOCK_CLOSER_PATTERNS,
|
|
85
|
+
CARRIAGE_RETURN_LINE_BREAK,
|
|
86
|
+
HTML_BLOCK_OPENER_PATTERN,
|
|
87
|
+
LINE_BREAK,
|
|
88
|
+
)
|
|
89
|
+
from hooks_constants.open_tasks_stop_gate_constants import (
|
|
90
|
+
ALL_ASK_ONLY_ENVELOPE_MARKERS,
|
|
91
|
+
ALL_PROMISED_REPORT_PATTERNS,
|
|
92
|
+
ASK_NEGATOR_PATTERN,
|
|
93
|
+
BACKTICK_TEXT_PATTERN,
|
|
94
|
+
ALL_INDENTED_LINE_PREFIXES,
|
|
95
|
+
COMPLETION_NEGATOR_GROUP,
|
|
96
|
+
COMPLETION_WORD_PATTERN,
|
|
97
|
+
DONE_LEAD_TAIL_PATTERN,
|
|
98
|
+
GOVERNANCE_BREAK_PATTERN,
|
|
99
|
+
LATER_TIME_PATTERN,
|
|
100
|
+
LEAD_NEGATOR_PATTERN,
|
|
101
|
+
LEAD_QUOTED_TEXT_PATTERN,
|
|
102
|
+
LIST_ASK_PATTERN,
|
|
103
|
+
OPEN_ITEM_LEAD_PATTERN,
|
|
104
|
+
OPEN_ITEM_LIST_MINIMUM,
|
|
105
|
+
PROMISE_NEGATOR_PATTERN,
|
|
106
|
+
PROMPT_CLAUSE_SPLIT_PATTERN,
|
|
107
|
+
QUOTED_PROMPT_LINE_PATTERN,
|
|
108
|
+
QUOTED_REPLY_LINE_PATTERN,
|
|
109
|
+
REMOVED_PROMPT_TEXT,
|
|
110
|
+
REPLY_SENTENCE_END_PATTERN,
|
|
111
|
+
REPORT_NOUN_ASK_PATTERN,
|
|
112
|
+
REPORT_VERB_ASK_PATTERN,
|
|
113
|
+
SPACED_QUOTE_PATTERN,
|
|
114
|
+
)
|
|
115
|
+
from hooks_constants.question_brief_gate_constants import (
|
|
116
|
+
TABLE_ROW_LINE_PATTERN,
|
|
117
|
+
TABLE_SEPARATOR_LINE_PATTERN,
|
|
118
|
+
)
|
|
119
|
+
from hooks_constants.spawn_readiness_hook_constants import ALL_HARNESS_ENVELOPE_MARKERS
|
|
120
|
+
from open_task_asks import prompt_without_reminders
|
|
121
|
+
from question_brief_gate import is_item_line, lines_outside_code_fences
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class OpenItemList(NamedTuple):
|
|
125
|
+
"""A run of open items in a closing reply: the lead line above it, and how many items it holds."""
|
|
126
|
+
|
|
127
|
+
lead: str
|
|
128
|
+
item_count: int
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def _prompt_asks_for(
|
|
132
|
+
prompt_text: str, ask_pattern: re.Pattern[str], clause_pattern: re.Pattern[str] | None
|
|
133
|
+
) -> bool:
|
|
134
|
+
stripped_text = prompt_without_reminders(prompt_text)
|
|
135
|
+
if stripped_text.startswith((*ALL_HARNESS_ENVELOPE_MARKERS, *ALL_ASK_ONLY_ENVELOPE_MARKERS)):
|
|
136
|
+
return False
|
|
137
|
+
cleaned_text = QUOTED_PROMPT_LINE_PATTERN.sub(REMOVED_PROMPT_TEXT, stripped_text)
|
|
138
|
+
cleaned_text = BACKTICK_TEXT_PATTERN.sub(REMOVED_PROMPT_TEXT, cleaned_text)
|
|
139
|
+
cleaned_text = SPACED_QUOTE_PATTERN.sub(REMOVED_PROMPT_TEXT, cleaned_text)
|
|
140
|
+
return any(
|
|
141
|
+
ASK_NEGATOR_PATTERN.search(each_clause[: each_ask.start()]) is None
|
|
142
|
+
for each_clause in PROMPT_CLAUSE_SPLIT_PATTERN.split(cleaned_text)
|
|
143
|
+
if clause_pattern is None or clause_pattern.search(each_clause) is not None
|
|
144
|
+
for each_ask in ask_pattern.finditer(each_clause)
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _prompt_asks_for_report(prompt_text: str) -> bool:
|
|
149
|
+
return _prompt_asks_for(prompt_text, REPORT_VERB_ASK_PATTERN, None) or _prompt_asks_for(
|
|
150
|
+
prompt_text, REPORT_NOUN_ASK_PATTERN, LATER_TIME_PATTERN
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def prompt_asks_for_list(prompt_text: str) -> bool:
|
|
155
|
+
"""Return True when the typed prompt asks for a list, by the ask rules above.
|
|
156
|
+
|
|
157
|
+
::
|
|
158
|
+
|
|
159
|
+
"list the deferred items as bullets" -> True
|
|
160
|
+
"don't list them, just fix them" -> False
|
|
161
|
+
"Fix the build" -> False
|
|
162
|
+
"""
|
|
163
|
+
return _prompt_asks_for(prompt_text, LIST_ASK_PATTERN, None)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def _sentence_before(paragraph_text: str, match_start: int) -> str:
|
|
167
|
+
all_sentence_ends = list(REPLY_SENTENCE_END_PATTERN.finditer(paragraph_text, 0, match_start))
|
|
168
|
+
sentence_start = all_sentence_ends[-1].end() if all_sentence_ends else 0
|
|
169
|
+
return paragraph_text[sentence_start:match_start]
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def promised_report_phrase(reply_text: str, prompt_text: str) -> str | None:
|
|
173
|
+
"""Return the words in the closing reply that promise the user a later report, or None.
|
|
174
|
+
|
|
175
|
+
::
|
|
176
|
+
|
|
177
|
+
"The benchmark table will be posted when you get back." -> "when you get back"
|
|
178
|
+
"I'll report back once CI ends." -> "I'll report back"
|
|
179
|
+
"No report will follow." -> None
|
|
180
|
+
the promise, after the prompt "report back when the run ends" -> None
|
|
181
|
+
|
|
182
|
+
Args:
|
|
183
|
+
reply_text: The closing reply the turn ends with.
|
|
184
|
+
prompt_text: The prompt that started the turn.
|
|
185
|
+
|
|
186
|
+
Returns:
|
|
187
|
+
The matched promise, or None when the reply holds none or the prompt asked for a report.
|
|
188
|
+
"""
|
|
189
|
+
if _prompt_asks_for_report(prompt_text):
|
|
190
|
+
return None
|
|
191
|
+
all_promises = (
|
|
192
|
+
_unnegated_promise(each_paragraph) for each_paragraph in prose_paragraphs(reply_text)
|
|
193
|
+
)
|
|
194
|
+
return next((each_promise for each_promise in all_promises if each_promise is not None), None)
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def _unnegated_promise(paragraph_text: str) -> str | None:
|
|
198
|
+
all_matches = (
|
|
199
|
+
each_match
|
|
200
|
+
for each_pattern in ALL_PROMISED_REPORT_PATTERNS
|
|
201
|
+
for each_match in each_pattern.finditer(paragraph_text)
|
|
202
|
+
)
|
|
203
|
+
return next(
|
|
204
|
+
(
|
|
205
|
+
each_match.group()
|
|
206
|
+
for each_match in all_matches
|
|
207
|
+
if PROMISE_NEGATOR_PATTERN.search(_sentence_before(paragraph_text, each_match.start()))
|
|
208
|
+
is None
|
|
209
|
+
),
|
|
210
|
+
None,
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def _html_block_closer_for(opener: re.Match[str]) -> re.Pattern[str]:
|
|
215
|
+
return ALL_HTML_BLOCK_CLOSER_PATTERNS[opener.lastgroup or ""]
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def _is_run_line(line: str, next_line: str) -> bool:
|
|
219
|
+
if QUOTED_REPLY_LINE_PATTERN.match(line):
|
|
220
|
+
return False
|
|
221
|
+
return is_item_line(line, next_line) or bool(
|
|
222
|
+
TABLE_ROW_LINE_PATTERN.match(line) or TABLE_SEPARATOR_LINE_PATTERN.match(line)
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def _is_run_continuation(line: str) -> bool:
|
|
227
|
+
return not line.strip() or line.startswith(ALL_INDENTED_LINE_PREFIXES)
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def _line_after(all_lines: list[str], line_index: int) -> str:
|
|
231
|
+
return all_lines[line_index + 1] if line_index + 1 < len(all_lines) else ""
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def _is_item_at(all_lines: list[str], line_index: int) -> bool:
|
|
235
|
+
line = all_lines[line_index]
|
|
236
|
+
next_line = _line_after(all_lines, line_index)
|
|
237
|
+
return _is_run_line(line, next_line) and is_item_line(line, next_line)
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def _continues_run_at(all_lines: list[str], line_index: int) -> bool:
|
|
241
|
+
line = all_lines[line_index]
|
|
242
|
+
return _is_run_line(line, _line_after(all_lines, line_index)) or _is_run_continuation(line)
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def _item_run_at(all_lines: list[str], run_start: int) -> tuple[int, int]:
|
|
246
|
+
item_count = 0
|
|
247
|
+
line_index = run_start
|
|
248
|
+
while line_index < len(all_lines) and _continues_run_at(all_lines, line_index):
|
|
249
|
+
item_count += _is_item_at(all_lines, line_index)
|
|
250
|
+
line_index += 1
|
|
251
|
+
return line_index, item_count
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def _lead_above(all_lines: list[str], run_start: int) -> str:
|
|
255
|
+
return next(
|
|
256
|
+
(each_line.strip() for each_line in reversed(all_lines[:run_start]) if each_line.strip()),
|
|
257
|
+
"",
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def _reply_lines(reply_text: str) -> list[str]:
|
|
262
|
+
line_feed_text = reply_text.replace(CARRIAGE_RETURN_LINE_BREAK, LINE_BREAK)
|
|
263
|
+
return lines_outside_code_fences(
|
|
264
|
+
blocks_masked(line_feed_text, HTML_BLOCK_OPENER_PATTERN, _html_block_closer_for)
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def _governs(lead: str, open_match: re.Match[str], completion_match: re.Match[str]) -> bool:
|
|
269
|
+
if completion_match.group(COMPLETION_NEGATOR_GROUP) is not None:
|
|
270
|
+
return False
|
|
271
|
+
if completion_match.start() < open_match.end() and open_match.start() < completion_match.end():
|
|
272
|
+
return False
|
|
273
|
+
gap_start = min(open_match.end(), completion_match.end())
|
|
274
|
+
gap_end = max(open_match.start(), completion_match.start())
|
|
275
|
+
return GOVERNANCE_BREAK_PATTERN.search(lead, gap_start, gap_end) is None
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def _ends_in_done_word(lead: str, all_completion_matches: list[re.Match[str]]) -> bool:
|
|
279
|
+
if not all_completion_matches:
|
|
280
|
+
return False
|
|
281
|
+
last_completion_match = all_completion_matches[-1]
|
|
282
|
+
if last_completion_match.group(COMPLETION_NEGATOR_GROUP) is not None:
|
|
283
|
+
return False
|
|
284
|
+
return DONE_LEAD_TAIL_PATTERN.fullmatch(lead, last_completion_match.end()) is not None
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def _is_open_item_lead(lead: str) -> bool:
|
|
288
|
+
unquoted_lead = LEAD_QUOTED_TEXT_PATTERN.sub(REMOVED_PROMPT_TEXT, lead)
|
|
289
|
+
if LEAD_NEGATOR_PATTERN.search(unquoted_lead) is not None:
|
|
290
|
+
return False
|
|
291
|
+
all_completion_matches = list(COMPLETION_WORD_PATTERN.finditer(unquoted_lead))
|
|
292
|
+
if _ends_in_done_word(unquoted_lead, all_completion_matches):
|
|
293
|
+
return False
|
|
294
|
+
return any(
|
|
295
|
+
not any(
|
|
296
|
+
_governs(unquoted_lead, each_open_match, each_completion_match)
|
|
297
|
+
for each_completion_match in all_completion_matches
|
|
298
|
+
)
|
|
299
|
+
for each_open_match in OPEN_ITEM_LEAD_PATTERN.finditer(unquoted_lead)
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
def _next_filled_line_index(all_lines: list[str], line_index: int) -> int | None:
|
|
304
|
+
return next(
|
|
305
|
+
(each_next for each_next in range(line_index + 1, len(all_lines)) if all_lines[each_next].strip()),
|
|
306
|
+
None,
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
def item_count_under(reply_text: str, lead: str) -> int:
|
|
311
|
+
"""Return how many items the run under the lead line holds, or every item line in the reply when no run follows it.
|
|
312
|
+
|
|
313
|
+
::
|
|
314
|
+
|
|
315
|
+
"Open calls:" over 3 bullets, then 2 more bullets elsewhere -> 3
|
|
316
|
+
a lead the reply holds on no line above a run -> 5
|
|
317
|
+
|
|
318
|
+
The lead matches the first line that holds its first line of text.
|
|
319
|
+
Fences, HTML blocks, and quoted lines are left out, as in ``open_item_list``.
|
|
320
|
+
"""
|
|
321
|
+
all_lines = _reply_lines(reply_text)
|
|
322
|
+
all_lead_lines = lead.strip().splitlines()
|
|
323
|
+
lead_line = all_lead_lines[0].strip() if all_lead_lines else ""
|
|
324
|
+
for each_index, each_line in enumerate(all_lines):
|
|
325
|
+
if not lead_line or lead_line not in each_line:
|
|
326
|
+
continue
|
|
327
|
+
run_start = _next_filled_line_index(all_lines, each_index)
|
|
328
|
+
if run_start is not None and _is_run_line(all_lines[run_start], _line_after(all_lines, run_start)):
|
|
329
|
+
return _item_run_at(all_lines, run_start)[1]
|
|
330
|
+
break
|
|
331
|
+
return sum(_is_item_at(all_lines, each_index) for each_index in range(len(all_lines)))
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def open_item_list(reply_text: str, prompt_text: str) -> OpenItemList | None:
|
|
335
|
+
"""Return the first run of 3 or more open items under an open-item lead in the closing reply, or None.
|
|
336
|
+
|
|
337
|
+
::
|
|
338
|
+
|
|
339
|
+
"What I deferred:" over 5 numbered lines -> OpenItemList("What I deferred:", 5)
|
|
340
|
+
"Open items:" over a table with 3 body rows -> OpenItemList("Open items:", 3)
|
|
341
|
+
"Changed files:" over 5 bullets -> None
|
|
342
|
+
"Nothing deferred." over 3 bullets -> None
|
|
343
|
+
the list, after the prompt "list the deferred items as bullets" -> None
|
|
344
|
+
|
|
345
|
+
Args:
|
|
346
|
+
reply_text: The closing reply the turn ends with.
|
|
347
|
+
prompt_text: The prompt that started the turn.
|
|
348
|
+
|
|
349
|
+
Returns:
|
|
350
|
+
The lead and the item count, or None when no run qualifies or the prompt asked for a list.
|
|
351
|
+
"""
|
|
352
|
+
if prompt_asks_for_list(prompt_text):
|
|
353
|
+
return None
|
|
354
|
+
all_lines = _reply_lines(reply_text)
|
|
355
|
+
line_index = 0
|
|
356
|
+
while line_index < len(all_lines):
|
|
357
|
+
if not _is_run_line(all_lines[line_index], _line_after(all_lines, line_index)):
|
|
358
|
+
line_index += 1
|
|
359
|
+
continue
|
|
360
|
+
run_end, item_count = _item_run_at(all_lines, line_index)
|
|
361
|
+
lead = _lead_above(all_lines, line_index)
|
|
362
|
+
if item_count >= OPEN_ITEM_LIST_MINIMUM and _is_open_item_lead(lead):
|
|
363
|
+
return OpenItemList(lead, item_count)
|
|
364
|
+
line_index = run_end
|
|
365
|
+
return None
|
|
@@ -90,3 +90,87 @@ def multi_edit_payload() -> Callable[[str, list[dict[str, str]]], str]:
|
|
|
90
90
|
)
|
|
91
91
|
|
|
92
92
|
return _multi_edit_payload
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
UNPINNED_WHICH = shutil.which
|
|
96
|
+
STUB_SCRIPT_TEMPLATE = """#!{python}
|
|
97
|
+
import json, os, pathlib, sys, time
|
|
98
|
+
state = pathlib.Path(os.environ["JUDGE_STUB_STATE"])
|
|
99
|
+
record = {{
|
|
100
|
+
"argv": sys.argv[1:],
|
|
101
|
+
"stdin": sys.stdin.read(),
|
|
102
|
+
"cwd_entries": os.listdir(os.getcwd()),
|
|
103
|
+
"review_child": os.environ.get("CLAUDE_TURN_REVIEW_CHILD"),
|
|
104
|
+
"disable_claude_mds": os.environ.get("CLAUDE_CODE_DISABLE_CLAUDE_MDS"),
|
|
105
|
+
"disable_auto_memory": os.environ.get("CLAUDE_CODE_DISABLE_AUTO_MEMORY"),
|
|
106
|
+
"parent_session_id": os.environ.get("CLAUDE_CODE_SESSION_ID"),
|
|
107
|
+
}}
|
|
108
|
+
with (state / "calls.jsonl").open("a") as calls:
|
|
109
|
+
calls.write(json.dumps(record) + "\\n")
|
|
110
|
+
time.sleep(float((state / "sleep.txt").read_text()))
|
|
111
|
+
sys.stdout.write((state / "answer.txt").read_text())
|
|
112
|
+
sys.exit(int((state / "exit.txt").read_text()))
|
|
113
|
+
"""
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
class JudgeStub:
|
|
117
|
+
"""The state folder a stub ``claude`` reads its answer from and writes its calls to."""
|
|
118
|
+
|
|
119
|
+
def __init__(self, state_folder: Path) -> None:
|
|
120
|
+
self.state_folder = state_folder
|
|
121
|
+
self.answer(
|
|
122
|
+
verdict={
|
|
123
|
+
"promised_report": False,
|
|
124
|
+
"promise_span": "",
|
|
125
|
+
"decisions_as_list": False,
|
|
126
|
+
"list_span": "",
|
|
127
|
+
}
|
|
128
|
+
)
|
|
129
|
+
(state_folder / "sleep.txt").write_text("0")
|
|
130
|
+
(state_folder / "exit.txt").write_text("0")
|
|
131
|
+
|
|
132
|
+
def answer(
|
|
133
|
+
self,
|
|
134
|
+
verdict: dict[str, object] | None = None,
|
|
135
|
+
result: str | None = None,
|
|
136
|
+
**all_outer_fields: object,
|
|
137
|
+
) -> None:
|
|
138
|
+
result_text = result if result is not None else json.dumps(verdict)
|
|
139
|
+
outer_answer = {
|
|
140
|
+
"type": "result",
|
|
141
|
+
"is_error": False,
|
|
142
|
+
"result": result_text,
|
|
143
|
+
**all_outer_fields,
|
|
144
|
+
}
|
|
145
|
+
(self.state_folder / "answer.txt").write_text(json.dumps(outer_answer))
|
|
146
|
+
|
|
147
|
+
def raw_stdout(self, stdout_text: str) -> None:
|
|
148
|
+
(self.state_folder / "answer.txt").write_text(stdout_text)
|
|
149
|
+
|
|
150
|
+
def sleep(self, seconds: float) -> None:
|
|
151
|
+
(self.state_folder / "sleep.txt").write_text(str(seconds))
|
|
152
|
+
|
|
153
|
+
def exit_code(self, code: int) -> None:
|
|
154
|
+
(self.state_folder / "exit.txt").write_text(str(code))
|
|
155
|
+
|
|
156
|
+
def calls(self) -> list[dict[str, object]]:
|
|
157
|
+
calls_path = self.state_folder / "calls.jsonl"
|
|
158
|
+
if not calls_path.is_file():
|
|
159
|
+
return []
|
|
160
|
+
return [json.loads(each_line) for each_line in calls_path.read_text().splitlines()]
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
@pytest.fixture
|
|
164
|
+
def judge_stub(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> JudgeStub:
|
|
165
|
+
"""Put a stub ``claude`` first on PATH that records each call and prints the answer the test sets."""
|
|
166
|
+
executable_folder = tmp_path / "bin"
|
|
167
|
+
executable_folder.mkdir()
|
|
168
|
+
stub_path = executable_folder / "claude"
|
|
169
|
+
stub_path.write_text(STUB_SCRIPT_TEMPLATE.format(python=sys.executable))
|
|
170
|
+
stub_path.chmod(0o755)
|
|
171
|
+
state_folder = tmp_path / "state"
|
|
172
|
+
state_folder.mkdir()
|
|
173
|
+
monkeypatch.setenv("PATH", str(executable_folder))
|
|
174
|
+
monkeypatch.setattr(shutil, "which", UNPINNED_WHICH)
|
|
175
|
+
monkeypatch.setenv("JUDGE_STUB_STATE", str(state_folder))
|
|
176
|
+
return JudgeStub(state_folder)
|