mirror of
https://github.com/shareAI-lab/analysis_claude_code.git
synced 2026-08-06 12:03:37 +08:00
docs: align snip_compact README guards with code
Match the snip_compact teaching snippet (en/zh/ja) to code.py: add the `head_end > 0` head guard and the `tail_start > 0 and tail_start < len(messages)` tail bounds check before indexing messages, mirroring the reactive_compact alignment. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011UJumwVeBXSGYh8nSzoVTF
This commit is contained in:
@@ -46,10 +46,12 @@ def snip_compact(messages, max_messages=50):
|
||||
if len(messages) <= max_messages:
|
||||
return messages
|
||||
head_end, tail_start = 3, len(messages) - (max_messages - 3)
|
||||
if _message_has_tool_use(messages[head_end - 1]):
|
||||
if head_end > 0 and _message_has_tool_use(messages[head_end - 1]):
|
||||
while head_end < len(messages) and _is_tool_result_message(messages[head_end]):
|
||||
head_end += 1
|
||||
if _is_tool_result_message(messages[tail_start]) and _message_has_tool_use(messages[tail_start - 1]):
|
||||
if (tail_start > 0 and tail_start < len(messages)
|
||||
and _is_tool_result_message(messages[tail_start])
|
||||
and _message_has_tool_use(messages[tail_start - 1])):
|
||||
tail_start -= 1
|
||||
snipped = tail_start - head_end
|
||||
placeholder = {"role": "user", "content": f"[snipped {snipped} messages from conversation middle]"}
|
||||
|
||||
Reference in New Issue
Block a user