refactor(backend/chat): Move glob/os imports to top-level in SDK service

This commit is contained in:
Zamil Majdy
2026-02-10 16:55:15 +04:00
parent f562d9a277
commit acf932bf4f
2 changed files with 2 additions and 19 deletions

View File

@@ -1,8 +1,10 @@
"""Claude Agent SDK service layer for CoPilot chat completions."""
import asyncio
import glob
import json
import logging
import os
import uuid
from collections.abc import AsyncGenerator
from typing import Any
@@ -54,9 +56,6 @@ _SDK_TOOL_RESULTS_GLOB = "/root/.claude/projects/*/tool-results/*"
def _cleanup_sdk_tool_results() -> None:
"""Remove SDK tool-result files to prevent disk accumulation."""
import glob
import os
for path in glob.glob(_SDK_TOOL_RESULTS_GLOB):
try:
os.remove(path)

View File

@@ -17,10 +17,6 @@ from backend.api.features.chat.tools.base import BaseTool
logger = logging.getLogger(__name__)
# Safety-net truncation for extreme tool results (e.g. infinite loops).
# Normal oversized results are handled by the SDK via the Read tool.
MAX_TOOL_RESULT_CHARS = 500_000
# Allowed base directory for the Read tool (SDK saves oversized tool results here)
_SDK_TOOL_RESULTS_DIR = "/root/.claude/"
@@ -107,18 +103,6 @@ def create_tool_handler(base_tool: BaseTool):
else json.dumps(result.output)
)
# Safety-net truncation for extreme results (e.g. infinite loops).
# Normal oversized results are handled by the SDK + our Read tool.
if len(text) > MAX_TOOL_RESULT_CHARS:
logger.warning(
f"Tool {base_tool.name} result truncated: "
f"{len(text)} -> {MAX_TOOL_RESULT_CHARS} chars"
)
text = (
text[:MAX_TOOL_RESULT_CHARS]
+ f"\n\n... [truncated — {len(text) - MAX_TOOL_RESULT_CHARS} chars omitted]"
)
return {
"content": [{"type": "text", "text": text}],
"isError": not result.success,