claude-dev-env 8.117.3 → 8.117.5
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/_shared/pr-loop/scripts/pyproject.toml +1 -1
- package/_shared/process-tree/scripts/pyproject.toml +1 -1
- package/bin/cde.mjs +4 -3
- package/bin/cde.test.mjs +87 -1
- package/bin/codex-compat.mjs +4 -3
- package/bin/codex-compat.test.mjs +91 -1
- package/bin/install-plan.mjs +2 -1
- package/bin/install.mjs +24 -7
- package/bin/install.plan.test.mjs +15 -0
- package/bin/install.test.mjs +61 -0
- package/bin/python-probe.mjs +42 -0
- package/bin/python-probe.test.mjs +19 -2
- package/docs/references/advisor-tool.md +2 -0
- package/docs/rule-guides/features-start-with-an-eval.md +3 -3
- package/docs/rule-guides/proof-before-pull-request.md +2 -2
- package/hooks/blocking/bash_pre_tool_use_dispatcher.py +11 -4
- package/hooks/blocking/build_eval_before_eval_write_gate.py +10 -4
- package/hooks/blocking/followup_pr_dedupe.py +381 -64
- package/hooks/blocking/gate_child_process.py +187 -0
- package/hooks/blocking/gate_run_reads.py +116 -35
- package/hooks/blocking/merge_review_gate.py +93 -10
- package/hooks/blocking/merge_review_gate_parts/create_folders.py +346 -0
- package/hooks/blocking/merge_review_gate_parts/create_options.py +86 -0
- package/hooks/blocking/merge_review_gate_parts/folder_state.py +107 -0
- package/hooks/blocking/merge_review_gate_parts/open_request.py +199 -64
- package/hooks/blocking/merge_review_gate_parts/quoted_lines.py +283 -0
- package/hooks/blocking/merge_review_gate_parts/wrapped_creates.py +126 -0
- package/hooks/blocking/pr_lifecycle_skill_gate.py +61 -18
- package/hooks/blocking/pre_tool_use_dispatcher.py +25 -3
- package/hooks/blocking/pull_request_proof.py +5 -51
- package/hooks/blocking/pull_request_proof_edit_gate.py +19 -5
- package/hooks/blocking/test_bash_pre_tool_use_dispatcher.py +54 -0
- package/hooks/blocking/test_build_eval_before_eval_write_gate.py +64 -0
- package/hooks/blocking/test_followup_pr_dedupe.py +464 -1
- package/hooks/blocking/test_gate_child_process.py +64 -0
- package/hooks/blocking/test_gate_run_reads.py +364 -4
- package/hooks/blocking/test_merge_review_gate.py +832 -39
- package/hooks/blocking/test_pr_lifecycle_skill_gate.py +130 -4
- package/hooks/blocking/test_pre_tool_use_dispatcher.py +64 -0
- package/hooks/blocking/test_pull_request_proof.py +16 -0
- package/hooks/blocking/test_pull_request_proof_edit_gate.py +60 -0
- package/hooks/blocking/tests/test_create_folders.py +290 -0
- package/hooks/blocking/tests/test_create_options.py +34 -0
- package/hooks/blocking/tests/test_folder_state.py +40 -0
- package/hooks/blocking/tests/test_open_request.py +350 -44
- package/hooks/blocking/tests/test_quoted_lines.py +86 -0
- package/hooks/blocking/tests/test_wrapped_creates.py +42 -0
- package/hooks/features/bash-dispatchers.md +1 -1
- package/hooks/features/conduct-gates.md +7 -7
- package/hooks/features/session-context.md +3 -3
- package/hooks/features/write-edit-blocking.md +3 -3
- package/hooks/hooks_constants/advisor_rules_prompt_constants.py +14 -6
- package/hooks/hooks_constants/build_eval_before_eval_write_gate_constants.py +5 -0
- package/hooks/hooks_constants/followup_pr_dedupe_constants.py +34 -1
- package/hooks/hooks_constants/gate_fault.py +52 -0
- package/hooks/hooks_constants/gate_fault_constants.py +13 -0
- package/hooks/hooks_constants/gate_run_reads_constants.py +9 -1
- package/hooks/hooks_constants/merge_review_gate_constants.py +94 -1
- package/hooks/hooks_constants/piped_pytest_blocker_constants.py +2 -0
- package/hooks/hooks_constants/pr_lifecycle_skill_gate_constants.py +6 -1
- package/hooks/hooks_constants/pre_tool_use_stdin.py +23 -3
- package/hooks/hooks_constants/shell_command_pipeline.py +68 -8
- package/hooks/hooks_constants/shell_command_segments.py +2 -2
- package/hooks/hooks_constants/shell_command_wrappers.py +3 -2
- package/hooks/hooks_constants/test_followup_pr_dedupe_constants.py +7 -0
- package/hooks/hooks_constants/test_gate_fault.py +41 -0
- package/hooks/hooks_constants/test_piped_pytest_blocker_constants.py +5 -0
- package/hooks/hooks_constants/test_pr_lifecycle_skill_gate_constants.py +10 -0
- package/hooks/hooks_constants/test_pre_tool_use_stdin.py +97 -0
- package/hooks/hooks_constants/test_shell_command_pipeline.py +55 -0
- package/hooks/hooks_constants/test_shell_command_segments.py +15 -0
- package/hooks/hooks_constants/test_shell_command_wrappers.py +6 -0
- package/hooks/hooks_constants/transcript_skill_scan_constants.py +6 -0
- package/hooks/pyproject.toml +2 -3
- package/hooks/session/advisor_rules_prompt.py +53 -9
- package/hooks/session/test_advisor_rules_prompt.py +70 -4
- package/hooks/test_python_floor.py +197 -0
- package/hooks/test_transcript_skill_scan.py +324 -0
- package/hooks/transcript_skill_scan.py +233 -2
- package/package.json +1 -1
|
@@ -1,23 +1,33 @@
|
|
|
1
1
|
"""Find a skill invocation after the last transcript compaction, or one with a given first argument anywhere.
|
|
2
2
|
|
|
3
|
+
A reader gives a large transcript's lines newest first, so a recent invocation answers without reading the whole file.
|
|
4
|
+
|
|
3
5
|
It also lists the tool calls made since the last user prompt, each with whether its result came back without an error.
|
|
4
6
|
"""
|
|
5
7
|
|
|
6
8
|
from __future__ import annotations
|
|
7
9
|
|
|
10
|
+
import io
|
|
8
11
|
import json
|
|
9
12
|
import re
|
|
10
|
-
from collections.abc import Collection, Iterable, Iterator
|
|
11
|
-
from
|
|
13
|
+
from collections.abc import Callable, Collection, Iterable, Iterator
|
|
14
|
+
from io import SEEK_END
|
|
15
|
+
from typing import BinaryIO, NamedTuple
|
|
12
16
|
|
|
13
17
|
from hooks_constants.transcript_skill_scan_constants import (
|
|
18
|
+
ALL_LINE_BREAK_BYTES,
|
|
14
19
|
ASSISTANT_ENTRY_TYPE,
|
|
20
|
+
CARRIAGE_RETURN_BYTE,
|
|
15
21
|
COMMAND_ARGUMENTS_PATTERN,
|
|
16
22
|
COMPACT_BOUNDARY_SUBTYPE,
|
|
23
|
+
FORWARD_COPY_BYTE_CAP,
|
|
17
24
|
IS_ERROR_FIELD,
|
|
18
25
|
META_ENTRY_FIELD,
|
|
26
|
+
NEWLINE_BYTE,
|
|
19
27
|
SKILL_TOOL_NAME,
|
|
20
28
|
TOOL_RESULT_BLOCK_TYPE,
|
|
29
|
+
TRANSCRIPT_BLOCK_BYTES,
|
|
30
|
+
TRANSCRIPT_LINE_BYTE_CAP,
|
|
21
31
|
TOOL_USE_BLOCK_TYPE,
|
|
22
32
|
TOOL_USE_ID_FIELD,
|
|
23
33
|
USER_ENTRY_TYPE,
|
|
@@ -171,6 +181,227 @@ def is_skill_loaded_after_last_compaction(
|
|
|
171
181
|
return skill_invocation_status(all_transcript_lines, skill_names, slash_command_markers)[1]
|
|
172
182
|
|
|
173
183
|
|
|
184
|
+
def is_skill_loaded_after_last_compaction_newest_first(
|
|
185
|
+
all_lines_newest_first: Iterable[str],
|
|
186
|
+
skill_names: Collection[str],
|
|
187
|
+
slash_command_markers: Collection[str],
|
|
188
|
+
) -> bool:
|
|
189
|
+
"""Return whether a matching invocation follows the last compact boundary, reading the newest line first.
|
|
190
|
+
|
|
191
|
+
::
|
|
192
|
+
|
|
193
|
+
newest first: load, ..., compact boundary -> True
|
|
194
|
+
newest first: compact boundary, ..., load -> False
|
|
195
|
+
no load and no compact boundary -> False
|
|
196
|
+
|
|
197
|
+
The first load or compact boundary met decides. The answer equals
|
|
198
|
+
``is_skill_loaded_after_last_compaction`` on the same lines in file order.
|
|
199
|
+
|
|
200
|
+
Args:
|
|
201
|
+
all_lines_newest_first: JSON transcript entries, one per line, newest first.
|
|
202
|
+
skill_names: Accepted skill names, with plugin prefixes accepted.
|
|
203
|
+
slash_command_markers: Accepted user command tags.
|
|
204
|
+
"""
|
|
205
|
+
for each_line in all_lines_newest_first:
|
|
206
|
+
all_entry_fields = _relevant_entry(each_line, skill_names)
|
|
207
|
+
if all_entry_fields is None:
|
|
208
|
+
continue
|
|
209
|
+
if all_entry_fields.get("subtype") == COMPACT_BOUNDARY_SUBTYPE:
|
|
210
|
+
return False
|
|
211
|
+
if _invokes_skill(all_entry_fields, skill_names, slash_command_markers):
|
|
212
|
+
return True
|
|
213
|
+
return False
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def _always_reads() -> bool:
|
|
217
|
+
return True
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def _notes_nothing() -> None:
|
|
221
|
+
return None
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
class ScanCaps(NamedTuple):
|
|
225
|
+
"""The byte caps a newest-first read holds to, and what it calls when one is passed.
|
|
226
|
+
|
|
227
|
+
::
|
|
228
|
+
|
|
229
|
+
a line over line_byte_cap -> the read stops; on_cap_passed runs once
|
|
230
|
+
a copied stream over forward_copy_byte_cap -> no lines; on_cap_passed runs once
|
|
231
|
+
"""
|
|
232
|
+
|
|
233
|
+
line_byte_cap: int = TRANSCRIPT_LINE_BYTE_CAP
|
|
234
|
+
forward_copy_byte_cap: int = FORWARD_COPY_BYTE_CAP
|
|
235
|
+
on_cap_passed: Callable[[], None] = _notes_nothing
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def _block_ending_at(
|
|
239
|
+
transcript: BinaryIO, end: int, block_size: int
|
|
240
|
+
) -> tuple[int, bytes]:
|
|
241
|
+
start = max(0, end - block_size)
|
|
242
|
+
transcript.seek(start)
|
|
243
|
+
block = transcript.read(end - start)
|
|
244
|
+
if start > 0 and block.startswith(NEWLINE_BYTE):
|
|
245
|
+
transcript.seek(start - 1)
|
|
246
|
+
if transcript.read(1) == CARRIAGE_RETURN_BYTE:
|
|
247
|
+
return start - 1, CARRIAGE_RETURN_BYTE + block
|
|
248
|
+
return start, block
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def _blocks_newest_first(
|
|
252
|
+
transcript: BinaryIO, block_size: int, keeps_reading: Callable[[], bool]
|
|
253
|
+
) -> Iterator[tuple[int, bytes]]:
|
|
254
|
+
end = transcript.seek(0, SEEK_END)
|
|
255
|
+
while end > 0 and keeps_reading():
|
|
256
|
+
end, block = _block_ending_at(transcript, end, block_size)
|
|
257
|
+
yield end, block
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def _block_pieces(block: bytes) -> list[bytes]:
|
|
261
|
+
all_pieces = block.splitlines()
|
|
262
|
+
if block.endswith(ALL_LINE_BREAK_BYTES):
|
|
263
|
+
all_pieces.append(b"")
|
|
264
|
+
return all_pieces
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def _complete_lines(
|
|
268
|
+
all_pieces: list[bytes], all_newer_parts: list[bytes], is_file_end: bool
|
|
269
|
+
) -> list[bytes]:
|
|
270
|
+
newest_line = all_pieces[-1] + b"".join(reversed(all_newer_parts))
|
|
271
|
+
all_older_lines = list(reversed(all_pieces[1:-1]))
|
|
272
|
+
return (
|
|
273
|
+
[newest_line, *all_older_lines]
|
|
274
|
+
if newest_line or not is_file_end
|
|
275
|
+
else all_older_lines
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def _lines_within_cap(
|
|
280
|
+
all_lines: list[bytes], may_pass_cap: bool, caps: ScanCaps
|
|
281
|
+
) -> tuple[list[bytes], bool]:
|
|
282
|
+
if not may_pass_cap:
|
|
283
|
+
return all_lines, True
|
|
284
|
+
for each_index, each_line in enumerate(all_lines):
|
|
285
|
+
if len(each_line) > caps.line_byte_cap:
|
|
286
|
+
return all_lines[:each_index], False
|
|
287
|
+
return all_lines, True
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def _byte_lines_newest_first(
|
|
291
|
+
transcript: BinaryIO,
|
|
292
|
+
block_size: int,
|
|
293
|
+
keeps_reading: Callable[[], bool],
|
|
294
|
+
caps: ScanCaps,
|
|
295
|
+
) -> Iterator[bytes]:
|
|
296
|
+
all_newer_parts: list[bytes] = []
|
|
297
|
+
newer_byte_count = 0
|
|
298
|
+
is_file_end = True
|
|
299
|
+
oldest_start = 0
|
|
300
|
+
for each_start, each_block in _blocks_newest_first(
|
|
301
|
+
transcript, block_size, keeps_reading
|
|
302
|
+
):
|
|
303
|
+
oldest_start = each_start
|
|
304
|
+
all_pieces = _block_pieces(each_block)
|
|
305
|
+
is_within_cap = True
|
|
306
|
+
if len(all_pieces) > 1:
|
|
307
|
+
all_lines = _complete_lines(all_pieces, all_newer_parts, is_file_end)
|
|
308
|
+
may_pass_cap = len(each_block) + newer_byte_count > caps.line_byte_cap
|
|
309
|
+
all_lines, is_within_cap = _lines_within_cap(all_lines, may_pass_cap, caps)
|
|
310
|
+
yield from all_lines
|
|
311
|
+
is_file_end, all_newer_parts, newer_byte_count = False, [], 0
|
|
312
|
+
all_newer_parts.append(all_pieces[0])
|
|
313
|
+
newer_byte_count += len(all_pieces[0])
|
|
314
|
+
if not is_within_cap or newer_byte_count > caps.line_byte_cap:
|
|
315
|
+
caps.on_cap_passed()
|
|
316
|
+
return
|
|
317
|
+
oldest_line = b"".join(reversed(all_newer_parts))
|
|
318
|
+
if oldest_start == 0 and (oldest_line or not is_file_end):
|
|
319
|
+
yield oldest_line
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
def _open_line_byte_count(block: bytes, earlier_open_byte_count: int) -> int:
|
|
323
|
+
last_break = max(block.rfind(NEWLINE_BYTE), block.rfind(CARRIAGE_RETURN_BYTE))
|
|
324
|
+
return (
|
|
325
|
+
earlier_open_byte_count + len(block)
|
|
326
|
+
if last_break < 0
|
|
327
|
+
else len(block) - last_break - 1
|
|
328
|
+
)
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
def _forward_copy(
|
|
332
|
+
transcript: BinaryIO,
|
|
333
|
+
block_size: int,
|
|
334
|
+
keeps_reading: Callable[[], bool],
|
|
335
|
+
caps: ScanCaps,
|
|
336
|
+
) -> BinaryIO:
|
|
337
|
+
copy = io.BytesIO()
|
|
338
|
+
open_line_byte_count = 0
|
|
339
|
+
while keeps_reading():
|
|
340
|
+
block = transcript.read(block_size)
|
|
341
|
+
if not block:
|
|
342
|
+
return copy
|
|
343
|
+
open_line_byte_count = _open_line_byte_count(block, open_line_byte_count)
|
|
344
|
+
is_over_copy_cap = copy.tell() + len(block) > caps.forward_copy_byte_cap
|
|
345
|
+
if is_over_copy_cap or open_line_byte_count > caps.line_byte_cap:
|
|
346
|
+
caps.on_cap_passed()
|
|
347
|
+
break
|
|
348
|
+
copy.write(block)
|
|
349
|
+
return io.BytesIO()
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
def _seeks_to_end(transcript: BinaryIO) -> bool:
|
|
353
|
+
if not transcript.seekable():
|
|
354
|
+
return False
|
|
355
|
+
try:
|
|
356
|
+
transcript.seek(0, SEEK_END)
|
|
357
|
+
except OSError:
|
|
358
|
+
return False
|
|
359
|
+
return True
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
def _seekable_byte_lines(
|
|
363
|
+
transcript: BinaryIO,
|
|
364
|
+
block_size: int,
|
|
365
|
+
keeps_reading: Callable[[], bool],
|
|
366
|
+
caps: ScanCaps,
|
|
367
|
+
) -> Iterator[bytes]:
|
|
368
|
+
if not _seeks_to_end(transcript):
|
|
369
|
+
transcript = _forward_copy(transcript, block_size, keeps_reading, caps)
|
|
370
|
+
yield from _byte_lines_newest_first(transcript, block_size, keeps_reading, caps)
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
def transcript_lines_newest_first(
|
|
374
|
+
transcript: BinaryIO,
|
|
375
|
+
encoding: str,
|
|
376
|
+
errors: str,
|
|
377
|
+
block_size: int = TRANSCRIPT_BLOCK_BYTES,
|
|
378
|
+
keeps_reading: Callable[[], bool] = _always_reads,
|
|
379
|
+
caps: ScanCaps | None = None,
|
|
380
|
+
) -> Iterator[str]:
|
|
381
|
+
"""Yield each line of a binary transcript, newest first, split where text mode splits it.
|
|
382
|
+
|
|
383
|
+
::
|
|
384
|
+
|
|
385
|
+
b"one\\ntwo\\r\\nthree\\rfour" -> "four", "three", "two", "one"
|
|
386
|
+
|
|
387
|
+
``\\n``, ``\\r\\n`` and a lone ``\\r`` end lines. A no from ``keeps_reading``, or a passed
|
|
388
|
+
cap, stops the reader. A transcript that cannot seek to its end is copied forward first.
|
|
389
|
+
|
|
390
|
+
Args:
|
|
391
|
+
transcript: The transcript opened in binary mode.
|
|
392
|
+
encoding: The text encoding of the transcript.
|
|
393
|
+
errors: The decode errors policy, such as ``"replace"``.
|
|
394
|
+
block_size: The bytes read from the file at a time.
|
|
395
|
+
keeps_reading: Whether the reader may read one more block.
|
|
396
|
+
caps: The byte caps, or None for the default ``ScanCaps()``.
|
|
397
|
+
"""
|
|
398
|
+
scan_caps = ScanCaps() if caps is None else caps
|
|
399
|
+
all_byte_lines = _seekable_byte_lines(
|
|
400
|
+
transcript, block_size, keeps_reading, scan_caps
|
|
401
|
+
)
|
|
402
|
+
return (each_line.decode(encoding, errors) for each_line in all_byte_lines)
|
|
403
|
+
|
|
404
|
+
|
|
174
405
|
def _is_user_prompt(all_entry_fields: dict[str, object]) -> bool:
|
|
175
406
|
message = all_entry_fields.get("message")
|
|
176
407
|
if all_entry_fields.get("type") != USER_ENTRY_TYPE or all_entry_fields.get(META_ENTRY_FIELD):
|