The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tools): sandbox read paths recognise SQLite sidecars as binary
kshitijk4poora3967ddbc006
diff --git a/tools/file_operations.py b/tools/file_operations.pyindex 6884dad5da8..97b951c56f2 100644--- a/tools/file_operations.py+++ b/tools/file_operations.py@@ -22,7 +22,7 @@ from abc import ABC, abstractmethodfrom typing import Optional, Dictfrom pathlib import Path-from tools.binary_extensions import BINARY_EXTENSIONS+from tools.binary_extensions import has_binary_extensionfrom agent.file_safety import get_write_denied_errorfrom tools.file_operations_common import (ExecuteResult, PatchResult, ReadResult, SearchResult, WriteResult,@@ -292,7 +292,7 @@ class ShellFileOperations(LintMixin, SearchMixin, FileOperations):def _is_likely_binary(self, path: str, content_sample: str = None) -> bool:"""Legacy text-layer binary check: extension, else >30% non-printable chars."""- if os.path.splitext(path)[1].lower() in BINARY_EXTENSIONS:+ if has_binary_extension(path):return Trueif content_sample:# Undecodable bytes arrive as U+FFFD ("printable", so the ratio misses@@ -476,7 +476,7 @@ class ShellFileOperations(LintMixin, SearchMixin, FileOperations):allows (base64 sample), else the legacy text heuristic (sample is None)."""sample_bytes = self._sample_file_bytes(path)if sample_bytes is not None:- ext_binary = os.path.splitext(path)[1].lower() in BINARY_EXTENSIONS+ ext_binary = has_binary_extension(path)return ext_binary or self._is_likely_binary_bytes(sample_bytes), sample_bytessample_output = _strip_terminal_fence_leaks(self._head(path, 1000).stdout)return self._is_likely_binary(path, sample_output), None@@ -497,7 +497,7 @@ class ShellFileOperations(LintMixin, SearchMixin, FileOperations):"""Read ``path`` as UTF-16 transcoded to UTF-8, or None (caller falls backto the binary-file error). Skips known-binary extensions and files over10 MiB. ``path`` must already be expanded."""- if os.path.splitext(path)[1].lower() in BINARY_EXTENSIONS or file_size > self._UTF16_MAX_BYTES:+ if has_binary_extension(path) or file_size > self._UTF16_MAX_BYTES:return Nonesnippet = ("import sys, json, os\n"@@ -583,7 +583,7 @@ class ShellFileOperations(LintMixin, SearchMixin, FileOperations):# Images / known-binary extensions never inline content; the sequential# path stops at the probes for them, so don't stream their bytes.- if self._is_image(path) or os.path.splitext(path)[1].lower() in BINARY_EXTENSIONS:+ if self._is_image(path) or has_binary_extension(path):return self._read_file_sequential(path, offset, limit)from tools.tool_output_limits import get_max_line_length@@ -707,7 +707,7 @@ class ShellFileOperations(LintMixin, SearchMixin, FileOperations):try:with open(full, "rb") as fh:sample = fh.read(1000)- ext_binary = os.path.splitext(path)[1].lower() in BINARY_EXTENSIONS+ ext_binary = has_binary_extension(path)if ext_binary or self._is_likely_binary_bytes(sample):return self._read_binary_file(path, offset, limit, file_size, sample)fh.seek(0)