mirror of
https://github.com/shareAI-lab/analysis_claude_code.git
synced 2026-09-20 12:13:38 +08:00
fix: preserve latest tool result batch during compaction
This commit is contained in:
@@ -331,7 +331,20 @@ class ContextCompactor:
|
||||
for block in message["content"]
|
||||
if isinstance(block, dict) and block.get("type") == "tool_result"
|
||||
]
|
||||
for block in results[:-self.KEEP_RECENT_RESULTS]:
|
||||
latest_batch = []
|
||||
for message in reversed(messages):
|
||||
content = message.get("content")
|
||||
if message.get("role") != "user" or not isinstance(content, list):
|
||||
continue
|
||||
latest_batch = [
|
||||
block for block in content
|
||||
if isinstance(block, dict) and block.get("type") == "tool_result"
|
||||
]
|
||||
if latest_batch:
|
||||
break
|
||||
latest_batch_ids = {id(block) for block in latest_batch}
|
||||
older_results = [block for block in results if id(block) not in latest_batch_ids]
|
||||
for block in older_results[:-self.KEEP_RECENT_RESULTS]:
|
||||
content = str(block.get("content", ""))
|
||||
if len(content) <= 120:
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user