claude-dev-env 8.124.0 → 8.125.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/profile-stop-gate.mjs +5 -7
- package/bin/profile-stop-gate.test.mjs +29 -1
- 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 +4 -3
- package/hooks/hooks.json +1 -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
|
@@ -60,8 +60,40 @@ gate checks that a read ran, and leaves which item it read to the agent. Each
|
|
|
60
60
|
such hold tells the agent to read the live state of every item it shows as
|
|
61
61
|
open, and to end the turn when the wording hands the user no step.
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
The closing reply also gets two checks of its own: a promised later report,
|
|
64
|
+
and open items sent as a list. On a Claude Code stop with ``claude`` on PATH,
|
|
65
|
+
one model call in ``closing_reply_judge.py`` reads the reply; Codex and Cursor
|
|
66
|
+
stops, and a host with no ``claude``, use the phrase checks that
|
|
67
|
+
``closing_reply_shapes.py`` describes. A judge that times out or gives no
|
|
68
|
+
usable verdict lets the stop go ahead. A stop inside a judge or review child
|
|
69
|
+
(``CLAUDE_TURN_REVIEW_CHILD=1``) goes ahead at once. The gate holds the turn
|
|
70
|
+
once::
|
|
71
|
+
|
|
72
|
+
block: "The benchmark table will be posted when you get back." no typed prompt asked for a report
|
|
73
|
+
block: "What I deferred:" over 3 or more items no question tool call this turn
|
|
74
|
+
allow: the same list after an AskUserQuestion call
|
|
75
|
+
allow: the same promise after the prompt "report back when the run ends"
|
|
76
|
+
allow: any reply when the transcript cannot be read
|
|
77
|
+
|
|
78
|
+
Such a hold names what it found and the steps, then one line that ends the
|
|
79
|
+
turn, then when the reply may stay as it is::
|
|
80
|
+
|
|
81
|
+
promise only -> "Then send the reworked reply and end the turn. Leave the promise as it is only when ..."
|
|
82
|
+
list present -> "Then send a short reply that names what you did and end the turn. Leave the list as it is only when ..."
|
|
83
|
+
|
|
84
|
+
One reason carries every finding. A Claude Code stop that a Stop hook already
|
|
85
|
+
held (``stop_hook_active``) gets only the closing-reply checks, and those hold
|
|
86
|
+
at most once per turn::
|
|
87
|
+
|
|
88
|
+
block: another hook held, then "I'll report back once CI ends." first such stop this turn
|
|
89
|
+
allow: the same stop again the turn's marker exists
|
|
90
|
+
allow: a stop after this gate held the turn its feedback sits in the turn
|
|
91
|
+
allow: a Codex turn, a prompt record with no ``uuid``, or a marker that cannot be kept
|
|
92
|
+
|
|
93
|
+
The marker is a file in the temp folder named for the session and the ``uuid``
|
|
94
|
+
of the prompt record that started the turn. A hold on the first stop writes it
|
|
95
|
+
too, so the gate costs at most one extra step per turn. The judge runs only
|
|
96
|
+
while the turn has no marker, so a stop after the hold makes no second call.
|
|
65
97
|
|
|
66
98
|
A hold exits with code 2 and writes the reason to stdout and stderr. Claude
|
|
67
99
|
Code marks a held stop with ``stop_hook_active``. Codex turns the reason into
|
|
@@ -77,6 +109,7 @@ from __future__ import annotations
|
|
|
77
109
|
import os
|
|
78
110
|
import sys
|
|
79
111
|
from pathlib import Path
|
|
112
|
+
from typing import NamedTuple
|
|
80
113
|
|
|
81
114
|
hooks_root_directory = str(Path(__file__).resolve().parent.parent)
|
|
82
115
|
if hooks_root_directory not in sys.path:
|
|
@@ -91,11 +124,24 @@ from hooks_constants.pre_tool_use_stdin import read_hook_input_dictionary_from_s
|
|
|
91
124
|
from hooks_constants.setup_project_paths_constants import DECODE_ERRORS_POLICY
|
|
92
125
|
from hooks_constants.once_per_session_constants import SESSION_ID_KEY
|
|
93
126
|
from hooks_constants.stop_hook_hold import hold_stop
|
|
127
|
+
from once_per_session import claim_turn_showing, is_turn_claimed
|
|
94
128
|
from open_task_asks import claude_home, is_ask
|
|
95
129
|
from open_tasks_transcript import TaskItem, TranscriptReplay, normalized_text, parsed_object, replayed_transcript
|
|
96
130
|
from user_step_wording import file_waiting_phrase, waiting_phrase
|
|
131
|
+
from closing_reply_shapes import item_count_under, open_item_list, promised_report_phrase
|
|
132
|
+
from closing_reply_judge import JudgeVerdict, is_judge_available, judged_verdict, log_no_verdict
|
|
133
|
+
from turn_review_transcript import _last_assistant_message_text, _ReversedTranscript
|
|
134
|
+
from hooks_constants.closing_reply_judge_constants import (
|
|
135
|
+
MARKER_UNREADABLE_REASON,
|
|
136
|
+
NO_TURN_KEY_REASON,
|
|
137
|
+
TRANSCRIPT_UNREADABLE_REASON,
|
|
138
|
+
)
|
|
139
|
+
from hooks_constants.spawn_readiness_hook_constants import CODEX_TURN_ID_KEY
|
|
140
|
+
from hooks_constants.turn_review_gate_constants import REVIEW_CHILD_ENVIRONMENT_VARIABLE, REVIEW_CHILD_MARKER
|
|
97
141
|
from hooks_constants.open_tasks_stop_gate_constants import (
|
|
142
|
+
ALL_OWN_REASON_OPENINGS,
|
|
98
143
|
ALLOW_EXIT_CODE,
|
|
144
|
+
CLOSING_REPLY_HOLD_MARKER_NAME,
|
|
99
145
|
COMPLETED_ITEMS_REASON_TEMPLATE,
|
|
100
146
|
COMPLETED_STATUS,
|
|
101
147
|
CURSOR_COMPLETED_STATUS,
|
|
@@ -106,6 +152,12 @@ from hooks_constants.open_tasks_stop_gate_constants import (
|
|
|
106
152
|
INCOMPLETE_STATUSES,
|
|
107
153
|
KEEP_REPLY_INSTRUCTION,
|
|
108
154
|
NO_STEP_INSTRUCTION,
|
|
155
|
+
OPEN_ITEM_LIST_KEEP_CONDITION,
|
|
156
|
+
OPEN_ITEM_LIST_REASON_TEMPLATE,
|
|
157
|
+
PROMISED_REPORT_KEEP_CONDITION,
|
|
158
|
+
PROMISED_REPORT_REASON_TEMPLATE,
|
|
159
|
+
REWORKED_REPLY_INSTRUCTION,
|
|
160
|
+
SHORT_REPLY_INSTRUCTION,
|
|
109
161
|
STOP_HOOK_ACTIVE_KEY,
|
|
110
162
|
TASK_FILE_GLOB,
|
|
111
163
|
TASK_ID_KEY,
|
|
@@ -219,6 +271,11 @@ def turn_waiting_phrase(all_hook_input_fields: dict[str, object], replay: Transc
|
|
|
219
271
|
return next((each_phrase for each_phrase in all_file_phrases if each_phrase is not None), None)
|
|
220
272
|
|
|
221
273
|
|
|
274
|
+
def _has_readable_transcript(all_hook_input_fields: dict[str, object]) -> bool:
|
|
275
|
+
transcript_path = all_hook_input_fields.get(TRANSCRIPT_PATH_KEY)
|
|
276
|
+
return isinstance(transcript_path, str) and Path(transcript_path).is_file()
|
|
277
|
+
|
|
278
|
+
|
|
222
279
|
def user_step_reasons(all_hook_input_fields: dict[str, object], replay: TranscriptReplay) -> list[str]:
|
|
223
280
|
"""Return a reason for each thing a turn skipped before it told the user something waits on them.
|
|
224
281
|
|
|
@@ -231,8 +288,7 @@ def user_step_reasons(all_hook_input_fields: dict[str, object], replay: Transcri
|
|
|
231
288
|
|
|
232
289
|
A session whose transcript cannot be read gives no reason.
|
|
233
290
|
"""
|
|
234
|
-
|
|
235
|
-
if not isinstance(transcript_path, str) or not Path(transcript_path).is_file():
|
|
291
|
+
if not _has_readable_transcript(all_hook_input_fields):
|
|
236
292
|
return []
|
|
237
293
|
all_reasons = [
|
|
238
294
|
each_reason
|
|
@@ -257,14 +313,180 @@ def tracker_reasons(all_hook_input_fields: dict[str, object], replay: Transcript
|
|
|
257
313
|
return all_reasons if stale_reason is None else [*all_reasons, stale_reason]
|
|
258
314
|
|
|
259
315
|
|
|
316
|
+
class ClosingReplyFinding(NamedTuple):
|
|
317
|
+
"""One closing-reply shape the gate found: what it found and the steps, the line that ends the turn, and when to keep the reply."""
|
|
318
|
+
|
|
319
|
+
reason: str
|
|
320
|
+
closing_instruction: str
|
|
321
|
+
keep_condition: str
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
def _promise_finding(promise_phrase: str) -> ClosingReplyFinding:
|
|
325
|
+
return ClosingReplyFinding(
|
|
326
|
+
PROMISED_REPORT_REASON_TEMPLATE.format(phrase=promise_phrase),
|
|
327
|
+
REWORKED_REPLY_INSTRUCTION,
|
|
328
|
+
PROMISED_REPORT_KEEP_CONDITION,
|
|
329
|
+
)
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
def _list_finding(lead: str, item_count: int) -> ClosingReplyFinding:
|
|
333
|
+
return ClosingReplyFinding(
|
|
334
|
+
OPEN_ITEM_LIST_REASON_TEMPLATE.format(count=item_count, lead=lead),
|
|
335
|
+
SHORT_REPLY_INSTRUCTION,
|
|
336
|
+
OPEN_ITEM_LIST_KEEP_CONDITION,
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
def is_judged_payload(all_hook_input_fields: dict[str, object], replay: TranscriptReplay) -> bool:
|
|
341
|
+
"""Return True for a Claude Code stop on a host with ``claude`` on PATH, and False for Codex and Cursor stops.
|
|
342
|
+
|
|
343
|
+
A Codex stop is one whose payload carries ``turn_id`` or whose turn a Codex rollout record started.
|
|
344
|
+
"""
|
|
345
|
+
if all_hook_input_fields.get(CURSOR_CONVERSATION_ID_KEY) or all_hook_input_fields.get(CODEX_TURN_ID_KEY):
|
|
346
|
+
return False
|
|
347
|
+
if replay.is_codex_turn:
|
|
348
|
+
return False
|
|
349
|
+
return is_judge_available()
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
def _judged_reply_text(all_hook_input_fields: dict[str, object]) -> str:
|
|
353
|
+
payload_reply = all_hook_input_fields.get(LAST_ASSISTANT_MESSAGE_KEY)
|
|
354
|
+
if isinstance(payload_reply, str) and payload_reply.strip():
|
|
355
|
+
return payload_reply
|
|
356
|
+
return _last_assistant_message_text(_ReversedTranscript(all_hook_input_fields))
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
def _verdict_findings(verdict: JudgeVerdict, reply_text: str) -> list[ClosingReplyFinding]:
|
|
360
|
+
all_findings: list[ClosingReplyFinding] = []
|
|
361
|
+
if verdict.promise_span:
|
|
362
|
+
all_findings.append(_promise_finding(verdict.promise_span))
|
|
363
|
+
if verdict.list_span:
|
|
364
|
+
all_findings.append(_list_finding(verdict.list_span, item_count_under(reply_text, verdict.list_span)))
|
|
365
|
+
return all_findings
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
def _judged_findings(all_hook_input_fields: dict[str, object], replay: TranscriptReplay) -> list[ClosingReplyFinding]:
|
|
369
|
+
if not _has_readable_transcript(all_hook_input_fields):
|
|
370
|
+
log_no_verdict(TRANSCRIPT_UNREADABLE_REASON)
|
|
371
|
+
return []
|
|
372
|
+
if replay.turn_key is None:
|
|
373
|
+
log_no_verdict(NO_TURN_KEY_REASON)
|
|
374
|
+
return []
|
|
375
|
+
is_claimed = is_turn_claimed(CLOSING_REPLY_HOLD_MARKER_NAME, all_hook_input_fields, replay.turn_key)
|
|
376
|
+
if is_claimed is None:
|
|
377
|
+
log_no_verdict(MARKER_UNREADABLE_REASON)
|
|
378
|
+
if is_claimed is not False:
|
|
379
|
+
return []
|
|
380
|
+
reply_text = _judged_reply_text(all_hook_input_fields)
|
|
381
|
+
if not reply_text:
|
|
382
|
+
return []
|
|
383
|
+
verdict = judged_verdict(replay.turn_prompt_text, reply_text, replay.has_turn_question_tool)
|
|
384
|
+
return [] if verdict is None else _verdict_findings(verdict, reply_text)
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
def closing_reply_findings(
|
|
388
|
+
all_hook_input_fields: dict[str, object], replay: TranscriptReplay
|
|
389
|
+
) -> list[ClosingReplyFinding]:
|
|
390
|
+
"""Return a finding for a promised later report and one for open items sent as a list in the closing reply.
|
|
391
|
+
|
|
392
|
+
::
|
|
393
|
+
|
|
394
|
+
"The benchmark table will be posted when you get back." -> the promised report finding
|
|
395
|
+
"What I deferred:" over 5 items, no question call -> the open item list finding
|
|
396
|
+
the same list after an AskUserQuestion call -> []
|
|
397
|
+
|
|
398
|
+
A Claude Code stop on a host with ``claude`` on PATH asks the judge in
|
|
399
|
+
``closing_reply_judge.py`` once, and only while this turn holds no
|
|
400
|
+
closing-reply hold yet. Its reply is ``last_assistant_message``, or the
|
|
401
|
+
transcript's last assistant text when that field is empty. A judge that
|
|
402
|
+
gives no verdict gives no finding. Codex and Cursor stops, and a host with
|
|
403
|
+
no ``claude``, use the phrase checks in ``closing_reply_shapes.py``. A
|
|
404
|
+
session whose transcript cannot be read gives no finding.
|
|
405
|
+
"""
|
|
406
|
+
if is_judged_payload(all_hook_input_fields, replay):
|
|
407
|
+
return _judged_findings(all_hook_input_fields, replay)
|
|
408
|
+
reply_text = all_hook_input_fields.get(LAST_ASSISTANT_MESSAGE_KEY)
|
|
409
|
+
if not isinstance(reply_text, str) or not _has_readable_transcript(all_hook_input_fields):
|
|
410
|
+
return []
|
|
411
|
+
all_findings: list[ClosingReplyFinding] = []
|
|
412
|
+
promise_phrase = promised_report_phrase(reply_text, replay.turn_prompt_text)
|
|
413
|
+
if promise_phrase is not None:
|
|
414
|
+
all_findings.append(_promise_finding(promise_phrase))
|
|
415
|
+
item_list = None if replay.has_turn_question_tool else open_item_list(reply_text, replay.turn_prompt_text)
|
|
416
|
+
if item_list is not None:
|
|
417
|
+
all_findings.append(_list_finding(item_list.lead, item_list.item_count))
|
|
418
|
+
return all_findings
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
def _closing_lines(has_step_reason: bool, all_reply_findings: list[ClosingReplyFinding]) -> list[str]:
|
|
422
|
+
if all_reply_findings:
|
|
423
|
+
return [
|
|
424
|
+
all_reply_findings[-1].closing_instruction,
|
|
425
|
+
*(each_finding.keep_condition for each_finding in all_reply_findings),
|
|
426
|
+
]
|
|
427
|
+
return [NO_STEP_INSTRUCTION if has_step_reason else KEEP_REPLY_INSTRUCTION]
|
|
428
|
+
|
|
429
|
+
|
|
260
430
|
def turn_block_reason(all_hook_input_fields: dict[str, object], replay: TranscriptReplay) -> str | None:
|
|
261
|
-
"""Return one reason that carries every finding on the turn, or None when the turn may end.
|
|
431
|
+
"""Return one reason that carries every finding on the turn, or None when the turn may end.
|
|
432
|
+
|
|
433
|
+
::
|
|
434
|
+
|
|
435
|
+
tracker finding only -> the finding, then "Then end the turn. Leave the reply as it stands."
|
|
436
|
+
promise and list findings -> both findings, the list's closing line, then both keep conditions
|
|
437
|
+
|
|
438
|
+
"end the turn" appears once in every reason.
|
|
439
|
+
"""
|
|
262
440
|
all_tracker_reasons = tracker_reasons(all_hook_input_fields, replay)
|
|
263
441
|
all_step_reasons = user_step_reasons(all_hook_input_fields, replay)
|
|
264
|
-
|
|
442
|
+
all_reply_findings = closing_reply_findings(all_hook_input_fields, replay)
|
|
443
|
+
all_reasons = [
|
|
444
|
+
*all_tracker_reasons,
|
|
445
|
+
*all_step_reasons,
|
|
446
|
+
*(each_finding.reason for each_finding in all_reply_findings),
|
|
447
|
+
]
|
|
448
|
+
if not all_reasons:
|
|
265
449
|
return None
|
|
266
|
-
|
|
267
|
-
|
|
450
|
+
return WORD_SEPARATOR.join([*all_reasons, *_closing_lines(bool(all_step_reasons), all_reply_findings)])
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
def _closing_reply_reason(all_reply_findings: list[ClosingReplyFinding]) -> str:
|
|
454
|
+
return WORD_SEPARATOR.join(
|
|
455
|
+
[*(each_finding.reason for each_finding in all_reply_findings), *_closing_lines(False, all_reply_findings)]
|
|
456
|
+
)
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
def _has_turn_hold_from_this_gate(replay: TranscriptReplay) -> bool:
|
|
460
|
+
return any(
|
|
461
|
+
each_opening in each_feedback
|
|
462
|
+
for each_feedback in replay.turn_stop_feedback_texts
|
|
463
|
+
for each_opening in ALL_OWN_REASON_OPENINGS
|
|
464
|
+
)
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
def continued_stop_reason(all_hook_input_fields: dict[str, object], replay: TranscriptReplay) -> str | None:
|
|
468
|
+
"""Return the closing-reply reason for a Claude Code stop that a Stop hook already held, at most once per turn.
|
|
469
|
+
|
|
470
|
+
::
|
|
471
|
+
|
|
472
|
+
another hook held, the reply promises a report, first time this turn -> the promised report reason
|
|
473
|
+
the same turn again -> None
|
|
474
|
+
a stop after this gate held the turn -> None
|
|
475
|
+
no turn key, a Cursor payload, or a marker that cannot be kept -> None
|
|
476
|
+
|
|
477
|
+
The turn key is the ``uuid`` of the prompt record that started the turn.
|
|
478
|
+
Tracker and user-step reasons stay off such a stop.
|
|
479
|
+
"""
|
|
480
|
+
if all_hook_input_fields.get(CURSOR_CONVERSATION_ID_KEY) or replay.turn_key is None:
|
|
481
|
+
return None
|
|
482
|
+
if _has_turn_hold_from_this_gate(replay):
|
|
483
|
+
return None
|
|
484
|
+
all_reply_findings = closing_reply_findings(all_hook_input_fields, replay)
|
|
485
|
+
if not all_reply_findings:
|
|
486
|
+
return None
|
|
487
|
+
if claim_turn_showing(CLOSING_REPLY_HOLD_MARKER_NAME, all_hook_input_fields, replay.turn_key) is not True:
|
|
488
|
+
return None
|
|
489
|
+
return _closing_reply_reason(all_reply_findings)
|
|
268
490
|
|
|
269
491
|
|
|
270
492
|
def is_held_stop(all_hook_input_fields: dict[str, object]) -> bool:
|
|
@@ -279,11 +501,26 @@ def is_held_stop(all_hook_input_fields: dict[str, object]) -> bool:
|
|
|
279
501
|
return has_sent_followup or (stop_status is not None and stop_status != CURSOR_COMPLETED_STATUS)
|
|
280
502
|
|
|
281
503
|
|
|
504
|
+
def _stop_block_reason(all_hook_input_fields: dict[str, object]) -> str | None:
|
|
505
|
+
if os.environ.get(REVIEW_CHILD_ENVIRONMENT_VARIABLE) == REVIEW_CHILD_MARKER:
|
|
506
|
+
return None
|
|
507
|
+
is_claude_held_stop = all_hook_input_fields.get(STOP_HOOK_ACTIVE_KEY) is True
|
|
508
|
+
if is_held_stop(all_hook_input_fields) and not is_claude_held_stop:
|
|
509
|
+
return None
|
|
510
|
+
replay = replayed_transcript(all_hook_input_fields.get(TRANSCRIPT_PATH_KEY))
|
|
511
|
+
if is_claude_held_stop:
|
|
512
|
+
return continued_stop_reason(all_hook_input_fields, replay)
|
|
513
|
+
block_reason = turn_block_reason(all_hook_input_fields, replay)
|
|
514
|
+
if block_reason is not None and replay.turn_key is not None:
|
|
515
|
+
claim_turn_showing(CLOSING_REPLY_HOLD_MARKER_NAME, all_hook_input_fields, replay.turn_key)
|
|
516
|
+
return block_reason
|
|
517
|
+
|
|
518
|
+
|
|
282
519
|
def main() -> int:
|
|
283
520
|
hook_input = read_hook_input_dictionary_from_stdin()
|
|
284
|
-
if hook_input is None
|
|
521
|
+
if hook_input is None:
|
|
285
522
|
return ALLOW_EXIT_CODE
|
|
286
|
-
block_reason =
|
|
523
|
+
block_reason = _stop_block_reason(hook_input)
|
|
287
524
|
if block_reason is None:
|
|
288
525
|
return ALLOW_EXIT_CODE
|
|
289
526
|
log_hook_block(Path(__file__).name, HOOK_EVENT_NAME, block_reason)
|
|
@@ -31,6 +31,12 @@ The replay also notes what the current turn did::
|
|
|
31
31
|
word such as ``get``, ``list`` or ``read`` and no
|
|
32
32
|
write word such as ``update``
|
|
33
33
|
turn_sent_file_paths the paths the turn's SendUserFile calls sent
|
|
34
|
+
turn_key the ``uuid`` of the Claude Code prompt record that
|
|
35
|
+
started the turn, or None for a Codex turn or a
|
|
36
|
+
record with no ``uuid``
|
|
37
|
+
turn_stop_feedback_texts the text of each ``Stop hook feedback`` record
|
|
38
|
+
the turn holds
|
|
39
|
+
is_codex_turn a Codex ``response_item`` user message started the turn
|
|
34
40
|
|
|
35
41
|
Across the whole session, the replay also notes whether a tracker tool exists::
|
|
36
42
|
|
|
@@ -91,6 +97,7 @@ from hooks_constants.open_tasks_stop_gate_constants import (
|
|
|
91
97
|
PENDING_STATUS,
|
|
92
98
|
PROMPT_SNAPSHOT_ATTACHMENT_TYPE,
|
|
93
99
|
RECORD_TYPE_KEY,
|
|
100
|
+
RECORD_UUID_KEY,
|
|
94
101
|
TASK_CREATED_PATTERN,
|
|
95
102
|
TASK_CREATE_TOOL_NAME,
|
|
96
103
|
TASK_ID_KEY,
|
|
@@ -125,6 +132,7 @@ from open_tasks_transcript_records import (
|
|
|
125
132
|
is_read_tool_name,
|
|
126
133
|
send_call_file_paths,
|
|
127
134
|
is_assistant_record,
|
|
135
|
+
stop_feedback_text,
|
|
128
136
|
listed_tool_names,
|
|
129
137
|
)
|
|
130
138
|
|
|
@@ -250,6 +258,9 @@ class TranscriptReplay:
|
|
|
250
258
|
self.has_turn_question_tool = False
|
|
251
259
|
self.has_turn_read_tool = False
|
|
252
260
|
self.turn_sent_file_paths: list[str] = []
|
|
261
|
+
self.turn_key: str | None = None
|
|
262
|
+
self.turn_stop_feedback_texts: list[str] = []
|
|
263
|
+
self.is_codex_turn = False
|
|
253
264
|
self.all_tool_listing_types: set[str] = set()
|
|
254
265
|
self.has_tracker_tool = False
|
|
255
266
|
|
|
@@ -271,13 +282,25 @@ class TranscriptReplay:
|
|
|
271
282
|
self.has_turn_question_tool = False
|
|
272
283
|
self.has_turn_read_tool = False
|
|
273
284
|
self.turn_sent_file_paths = []
|
|
285
|
+
self.turn_key = None
|
|
286
|
+
self.turn_stop_feedback_texts = []
|
|
287
|
+
self.is_codex_turn = False
|
|
274
288
|
|
|
275
289
|
def apply_record(self, all_record_fields: dict[str, object]) -> None:
|
|
276
290
|
prompt_text = codex_prompt_text(all_record_fields)
|
|
277
|
-
if prompt_text is None:
|
|
278
|
-
prompt_text = claude_prompt_text(all_record_fields)
|
|
279
291
|
if prompt_text is not None:
|
|
280
292
|
self.start_turn(prompt_text)
|
|
293
|
+
self.is_codex_turn = True
|
|
294
|
+
return
|
|
295
|
+
prompt_text = claude_prompt_text(all_record_fields)
|
|
296
|
+
if prompt_text is not None:
|
|
297
|
+
self.start_turn(prompt_text)
|
|
298
|
+
prompt_uuid = all_record_fields.get(RECORD_UUID_KEY)
|
|
299
|
+
self.turn_key = prompt_uuid if isinstance(prompt_uuid, str) and prompt_uuid else None
|
|
300
|
+
return
|
|
301
|
+
feedback_text = stop_feedback_text(all_record_fields)
|
|
302
|
+
if feedback_text is not None:
|
|
303
|
+
self.turn_stop_feedback_texts.append(feedback_text)
|
|
281
304
|
return
|
|
282
305
|
tool_listing = listed_tool_names(all_record_fields)
|
|
283
306
|
if tool_listing is not None:
|
|
@@ -121,6 +121,16 @@ def claude_prompt_text(all_record_fields: dict[str, object]) -> str | None:
|
|
|
121
121
|
return prompt_text
|
|
122
122
|
|
|
123
123
|
|
|
124
|
+
def stop_feedback_text(all_record_fields: dict[str, object]) -> str | None:
|
|
125
|
+
"""Return the text of a Claude Code ``Stop hook feedback`` user record, flagged ``isMeta`` or not, or None."""
|
|
126
|
+
message_body = all_record_fields.get(MESSAGE_KEY)
|
|
127
|
+
if USER_RECORD_TYPE != all_record_fields.get(RECORD_TYPE_KEY) or not isinstance(message_body, dict):
|
|
128
|
+
return None
|
|
129
|
+
content_value = message_body.get(CONTENT_KEY)
|
|
130
|
+
feedback_text = content_value if isinstance(content_value, str) else _text_of_blocks(_content_blocks(all_record_fields))
|
|
131
|
+
return feedback_text if feedback_text.lstrip().startswith(STOP_HOOK_FEEDBACK_PREFIX) else None
|
|
132
|
+
|
|
133
|
+
|
|
124
134
|
def _codex_payload(all_record_fields: dict[str, object]) -> dict[str, object] | None:
|
|
125
135
|
payload_body = all_record_fields.get(CODEX_PAYLOAD_KEY)
|
|
126
136
|
if all_record_fields.get(RECORD_TYPE_KEY) != CODEX_RESPONSE_ITEM_TYPE or not isinstance(payload_body, dict):
|
|
@@ -254,7 +254,8 @@ def brief_before_question(all_entries: Iterable[dict], tool_use_id: str) -> str
|
|
|
254
254
|
return None
|
|
255
255
|
|
|
256
256
|
|
|
257
|
-
def
|
|
257
|
+
def lines_outside_code_fences(brief_text: str) -> list[str]:
|
|
258
|
+
"""Return each line of the text that sits outside a code fence; the fence lines themselves are left out."""
|
|
258
259
|
all_outside_lines: list[str] = []
|
|
259
260
|
is_inside_fence = False
|
|
260
261
|
for each_line in brief_text.splitlines():
|
|
@@ -266,7 +267,8 @@ def _lines_outside_code_fences(brief_text: str) -> list[str]:
|
|
|
266
267
|
return all_outside_lines
|
|
267
268
|
|
|
268
269
|
|
|
269
|
-
def
|
|
270
|
+
def is_item_line(line: str, next_line: str) -> bool:
|
|
271
|
+
"""Return True for a bullet, a numbered line, or a table body row; a table header or separator row is no item."""
|
|
270
272
|
if LIST_ITEM_LINE_PATTERN.match(line):
|
|
271
273
|
return True
|
|
272
274
|
return bool(
|
|
@@ -288,9 +290,9 @@ def count_list_items(brief_text: str) -> int:
|
|
|
288
290
|
"| # | What |\\n|---|---|\\n| 1 | x |" -> 1
|
|
289
291
|
"```\\n- a\\n- b\\n```" -> 0
|
|
290
292
|
"""
|
|
291
|
-
all_lines =
|
|
293
|
+
all_lines = lines_outside_code_fences(brief_text)
|
|
292
294
|
return sum(
|
|
293
|
-
|
|
295
|
+
is_item_line(each_line, each_next_line)
|
|
294
296
|
for each_line, each_next_line in zip(all_lines, [*all_lines[1:], ""], strict=False)
|
|
295
297
|
)
|
|
296
298
|
|