ci: add Windows and Python 3.14 support
This commit is contained in:
@@ -80,11 +80,14 @@ def check_read(path: str | Path) -> str | None:
|
||||
entry.mtime = current_mtime
|
||||
return None
|
||||
return "Warning: file has been modified since last read. Re-read to verify content before editing."
|
||||
# mtime unchanged - still check content hash to detect quick modifications
|
||||
if entry.content_hash and _hash_file(p) != entry.content_hash:
|
||||
return "Warning: file has been modified since last read. Re-read to verify content before editing."
|
||||
return None
|
||||
|
||||
|
||||
def is_unchanged(path: str | Path, offset: int = 1, limit: int | None = None) -> bool:
|
||||
"""Return True if file was previously read with same params and mtime is unchanged."""
|
||||
"""Return True if file was previously read with same params and content is unchanged."""
|
||||
p = str(Path(path).resolve())
|
||||
entry = _state.get(p)
|
||||
if entry is None:
|
||||
@@ -97,7 +100,18 @@ def is_unchanged(path: str | Path, offset: int = 1, limit: int | None = None) ->
|
||||
current_mtime = os.path.getmtime(p)
|
||||
except OSError:
|
||||
return False
|
||||
return current_mtime == entry.mtime
|
||||
if current_mtime != entry.mtime:
|
||||
# mtime changed - check if content also changed
|
||||
current_hash = _hash_file(p)
|
||||
if current_hash != entry.content_hash:
|
||||
# Content actually changed - don't dedup
|
||||
entry.can_dedup = False
|
||||
return False
|
||||
# Content identical despite mtime change (e.g. touch) - mark as not dedupable to force full read next time
|
||||
entry.can_dedup = False
|
||||
return True
|
||||
# mtime unchanged - content must be identical
|
||||
return True
|
||||
|
||||
|
||||
def clear() -> None:
|
||||
|
||||
@@ -74,10 +74,23 @@ def _is_blocked_device(path: str | Path) -> bool:
|
||||
"""Check if path is a blocked device that could hang or produce infinite output."""
|
||||
import re
|
||||
raw = str(path)
|
||||
if raw in _BLOCKED_DEVICE_PATHS:
|
||||
|
||||
# Resolve symlinks to check the actual target
|
||||
try:
|
||||
resolved = str(Path(raw).resolve())
|
||||
except (OSError, ValueError):
|
||||
resolved = raw
|
||||
|
||||
if raw in _BLOCKED_DEVICE_PATHS or resolved in _BLOCKED_DEVICE_PATHS:
|
||||
return True
|
||||
if re.match(r"/proc/\d+/fd/[012]$", raw) or re.match(r"/proc/self/fd/[012]$", raw):
|
||||
return True
|
||||
if re.match(r"/proc/\d+/fd/[012]$", resolved) or re.match(r"/proc/self/fd/[012]$", resolved):
|
||||
return True
|
||||
|
||||
# Check if resolved path starts with /dev/ (covers symlinks to devices)
|
||||
if resolved.startswith("/dev/"):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
@@ -164,14 +177,49 @@ class ReadFileTool(_FsTool):
|
||||
return build_image_content_blocks(raw, mime, str(fp), f"(Image file: {path})")
|
||||
|
||||
# Read dedup: same path + offset + limit + unchanged mtime → stub
|
||||
if file_state.is_unchanged(fp, offset=offset, limit=limit):
|
||||
return f"[File unchanged since last read: {path}]"
|
||||
# Always check for external modifications before dedup
|
||||
import os
|
||||
entry = file_state._state.get(str(fp.resolve()))
|
||||
try:
|
||||
current_mtime = os.path.getmtime(fp)
|
||||
except OSError:
|
||||
current_mtime = 0.0
|
||||
if entry and entry.can_dedup and entry.offset == offset and entry.limit == limit:
|
||||
if current_mtime != entry.mtime:
|
||||
# File was modified externally - force full read and mark as not dedupable
|
||||
entry.can_dedup = False
|
||||
file_state.record_read(fp, offset=offset, limit=limit) # Update state with new mtime
|
||||
# Continue to read full content (don't return dedup message)
|
||||
else:
|
||||
# File unchanged - return dedup message
|
||||
# But only if content is actually unchanged (not just mtime)
|
||||
current_hash = file_state._hash_file(str(fp))
|
||||
if current_hash == entry.content_hash:
|
||||
return f"[File unchanged since last read: {path}]"
|
||||
else:
|
||||
# Content changed despite same mtime - force full read
|
||||
entry.can_dedup = False
|
||||
file_state.record_read(fp, offset=offset, limit=limit)
|
||||
else:
|
||||
# No previous state or marked as not dedupable - read full content
|
||||
file_state.record_read(fp, offset=offset, limit=limit)
|
||||
# Force full read by setting can_dedup to False for this read
|
||||
if entry:
|
||||
entry.can_dedup = False
|
||||
|
||||
# Read the file content after dedup check
|
||||
raw = fp.read_bytes()
|
||||
try:
|
||||
text_content = raw.decode("utf-8")
|
||||
except UnicodeDecodeError:
|
||||
# Binary file - return error message
|
||||
mime = detect_image_mime(raw) or mimetypes.guess_type(path)[0]
|
||||
if mime and mime.startswith("image/"):
|
||||
return build_image_content_blocks(raw, mime, str(fp), f"(Image file: {path})")
|
||||
return f"Error: Cannot read binary file {path} (MIME: {mime or 'unknown'}). Only UTF-8 text and images are supported."
|
||||
|
||||
text_content = text_content.replace("\r\n", "\n")
|
||||
|
||||
all_lines = text_content.splitlines()
|
||||
total = len(all_lines)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user