From 47973e945efa2cdbdb8f3404d467d7f1abc62b0a Mon Sep 17 00:00:00 2001 From: Fahad Date: Sun, 5 Oct 2025 08:19:46 +0400 Subject: [PATCH] refactor: include file modification dates too --- AGENTS.md | 7 ++++++- utils/file_utils.py | 18 +++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 5225ded..2a1606c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -18,9 +18,14 @@ Authoritative documentation and samples live in `docs/`, and runtime diagnostics - `python communication_simulator_test.py --quick` – smoke-test orchestration across tools and providers. - `./run_integration_tests.sh [--with-simulator]` – exercise provider-dependent flows against remote or Ollama models. +Run code quality checks: +```bash +.zen_venv/bin/activate && ./code_quality_checks.sh +``` + For example, this is how we run an individual / all tests: -``` +```bash .zen_venv/bin/activate && pytest tests/test_auto_mode_model_listing.py -q .zen_venv/bin/activate && pytest -q ``` diff --git a/utils/file_utils.py b/utils/file_utils.py index d9de8ce..cc05408 100644 --- a/utils/file_utils.py +++ b/utils/file_utils.py @@ -40,6 +40,7 @@ multi-turn file handling: import json import logging import os +from datetime import datetime, timezone from pathlib import Path from typing import Optional @@ -463,11 +464,17 @@ def read_file_content( return content, estimate_tokens(content) # Check file size to prevent memory exhaustion - file_size = path.stat().st_size + stat_result = path.stat() + file_size = stat_result.st_size logger.debug(f"[FILES] File size for {file_path}: {file_size:,} bytes") if file_size > max_size: logger.debug(f"[FILES] File too large: {file_path} ({file_size:,} > {max_size:,} bytes)") - content = f"\n--- FILE TOO LARGE: {file_path} ---\nFile size: {file_size:,} bytes (max: {max_size:,})\n--- END FILE ---\n" + modified_at = datetime.fromtimestamp(stat_result.st_mtime, tz=timezone.utc).strftime("%Y-%m-%d %H:%M:%S %Z") + content = ( + f"\n--- FILE TOO LARGE: {file_path} (Last modified: {modified_at}) ---\n" + f"File size: {file_size:,} bytes (max: {max_size:,})\n" + "--- END FILE ---\n" + ) return content, estimate_tokens(content) # Determine if we should add line numbers @@ -495,7 +502,12 @@ def read_file_content( # NOTE: These markers ("--- BEGIN FILE: ... ---") are distinct from git diff markers # ("--- BEGIN DIFF: ... ---") to allow AI to distinguish between complete file content # vs. partial diff content when files appear in both sections - formatted = f"\n--- BEGIN FILE: {file_path} ---\n{file_content}\n--- END FILE: {file_path} ---\n" + modified_at = datetime.fromtimestamp(stat_result.st_mtime, tz=timezone.utc).strftime("%Y-%m-%d %H:%M:%S %Z") + formatted = ( + f"\n--- BEGIN FILE: {file_path} (Last modified: {modified_at}) ---\n" + f"{file_content}\n" + f"--- END FILE: {file_path} ---\n" + ) tokens = estimate_tokens(formatted) logger.debug(f"[FILES] Formatted content for {file_path}: {len(formatted)} chars, {tokens} tokens") return formatted, tokens