fix(tools): keep searches scoped and results resumable

This commit is contained in:
chengyongru authored and chengyongru committed 2026-09-23 14:04:08 +08:00
1 parent a721806a50
commit c8ed6a1209
4 files changed
+423 -65

No files matched your search

+14 -4
View File
@@ -364,7 +364,6 @@ def timestamp() -> str:
_UNSAFE_CHARS = re.compile(r'[<>:"/\\|?*]')
_TOOL_RESULT_PREVIEW_CHARS = 1200
_TOOL_RESULTS_DIR = ".nanobot/tool-results"
_TOOL_RESULT_RETENTION_SECS = 7 * 24 * 60 * 60
_TOOL_RESULT_MAX_BUCKETS = 32
@@ -602,12 +601,23 @@ def maybe_persist_tool_result(
if not path.exists():
_write_text_atomic(path, content)
preview = content[:_TOOL_RESULT_PREVIEW_CHARS]
reference_path = str(path.resolve())
overhead = len(_render_tool_result_reference(
reference_path, original_size=len(content), preview="", truncated_preview=True,
))
available = max(0, max_chars - overhead)
separator = "\n...\n"
tail_chars = min(1200, max(0, (available - len(separator)) // 4))
if tail_chars:
head_chars = available - tail_chars - len(separator)
preview = content[:head_chars] + separator + content[-tail_chars:]
else:
preview = content[:available]
return _render_tool_result_reference(
str(path.resolve()),
reference_path,
original_size=len(content),
preview=preview,
truncated_preview=len(content) > _TOOL_RESULT_PREVIEW_CHARS,
truncated_preview=True,
max_chars=max_chars,
)