diff --git a/cptr/env.py b/cptr/env.py index 253b269..28ce9b6 100644 --- a/cptr/env.py +++ b/cptr/env.py @@ -25,6 +25,7 @@ CHAT_MAX_ITERATIONS = int(os.environ.get("CHAT_MAX_ITERATIONS", "2048")) ENABLE_CHAT_RECONCILE_ON_STARTUP: bool = os.environ.get( "ENABLE_CHAT_RECONCILE_ON_STARTUP", "true" ).lower() in ("true", "1", "yes") +CHAT_TOOL_MAX_CHARS = int(os.environ.get("CHAT_TOOL_MAX_CHARS", "50000")) # ── AI stream settings ────────────────────────────────────── STREAM_CONNECT_TIMEOUT_SECONDS = float(os.environ.get("CPTR_STREAM_CONNECT_TIMEOUT", "30")) diff --git a/cptr/utils/tools.py b/cptr/utils/tools.py index 094766d..91c4be3 100644 --- a/cptr/utils/tools.py +++ b/cptr/utils/tools.py @@ -14,6 +14,7 @@ import os import uuid from pathlib import Path from typing import get_type_hints +from cptr.env import CHAT_TOOL_MAX_CHARS # ── Background task state ─────────────────────────────────── @@ -145,11 +146,6 @@ async def list_directory( except OSError: sz = 0 entries.append(f"{rel / f} ({_human_size(sz)})") - if len(entries) > 500: - entries.append("... (truncated at 500)") - break - if len(entries) > 500: - break else: for item in sorted(full.iterdir()): if item.name in ignore: @@ -167,7 +163,8 @@ async def list_directory( sz = 0 entries.append(f"{item.name} ({_human_size(sz)})") - return "\n".join(entries) if entries else "(empty directory)" + res = "\n".join(entries) if entries else "(empty directory)" + return _truncate_output(res, max_chars=CHAT_TOOL_MAX_CHARS) async def search_files( @@ -199,7 +196,7 @@ async def search_files( # ripgrep not installed, fall back to Python res = await _search_python(query, full, case_insensitive) - return _truncate_output(res, max_chars=30_000) + return _truncate_output(res, max_chars=CHAT_TOOL_MAX_CHARS) async def _search_rg(