fix: review filename sanitize and tool output
This commit is contained in:
parent
66b846ee37
commit
463d89f295
@ -85,6 +85,7 @@ logger = setup_logger(__name__)
|
|||||||
DISABLE_LENGTH_CHECK = True
|
DISABLE_LENGTH_CHECK = True
|
||||||
|
|
||||||
class MainTerminalToolsReadMixin:
|
class MainTerminalToolsReadMixin:
|
||||||
|
@staticmethod
|
||||||
def _clamp_int(value, default, min_value=None, max_value=None):
|
def _clamp_int(value, default, min_value=None, max_value=None):
|
||||||
"""将输入转换为整数并限制范围。"""
|
"""将输入转换为整数并限制范围。"""
|
||||||
if value is None:
|
if value is None:
|
||||||
@ -99,6 +100,7 @@ class MainTerminalToolsReadMixin:
|
|||||||
num = min(max_value, num)
|
num = min(max_value, num)
|
||||||
return num
|
return num
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
def _parse_optional_line(value, field_name: str):
|
def _parse_optional_line(value, field_name: str):
|
||||||
"""解析可选的行号参数。"""
|
"""解析可选的行号参数。"""
|
||||||
if value is None:
|
if value is None:
|
||||||
@ -111,12 +113,14 @@ class MainTerminalToolsReadMixin:
|
|||||||
return None, f"{field_name} 必须大于等于1"
|
return None, f"{field_name} 必须大于等于1"
|
||||||
return number, None
|
return number, None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
def _truncate_text_block(text: str, max_chars: int):
|
def _truncate_text_block(text: str, max_chars: int):
|
||||||
"""对单段文本应用字符限制。"""
|
"""对单段文本应用字符限制。"""
|
||||||
if max_chars and len(text) > max_chars:
|
if max_chars and len(text) > max_chars:
|
||||||
return text[:max_chars], True, max_chars
|
return text[:max_chars], True, max_chars
|
||||||
return text, False, len(text)
|
return text, False, len(text)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
def _limit_text_chunks(chunks: List[Dict], text_key: str, max_chars: int):
|
def _limit_text_chunks(chunks: List[Dict], text_key: str, max_chars: int):
|
||||||
"""对多个文本片段应用全局字符限制。"""
|
"""对多个文本片段应用全局字符限制。"""
|
||||||
if max_chars is None or max_chars <= 0:
|
if max_chars is None or max_chars <= 0:
|
||||||
|
|||||||
@ -54,6 +54,7 @@ from .context import with_terminal, get_gui_manager, get_upload_guard, build_upl
|
|||||||
from .utils_common import (
|
from .utils_common import (
|
||||||
build_review_lines,
|
build_review_lines,
|
||||||
debug_log,
|
debug_log,
|
||||||
|
_sanitize_filename_component,
|
||||||
log_backend_chunk,
|
log_backend_chunk,
|
||||||
log_frontend_chunk,
|
log_frontend_chunk,
|
||||||
log_streaming_debug_entry,
|
log_streaming_debug_entry,
|
||||||
|
|||||||
@ -355,17 +355,22 @@ def _plain_command_output(result_data: Dict[str, Any]) -> str:
|
|||||||
partial_output_note = "已返回当前输出,命令可能仍在运行"
|
partial_output_note = "已返回当前输出,命令可能仍在运行"
|
||||||
partial_no_output_note = "未捕获输出,命令可能仍在运行"
|
partial_no_output_note = "未捕获输出,命令可能仍在运行"
|
||||||
else:
|
else:
|
||||||
appended = False
|
timeout_seconds = None
|
||||||
# 1) 优先使用数值型 timeout
|
|
||||||
if isinstance(timeout, (int, float)) and timeout > 0:
|
if isinstance(timeout, (int, float)) and timeout > 0:
|
||||||
prefixes.append(f"[timeout after {int(timeout)}s]")
|
timeout_seconds = int(timeout)
|
||||||
appended = True
|
elif isinstance(timeout, str):
|
||||||
# 2) 字符串数字
|
stripped = timeout.strip()
|
||||||
elif isinstance(timeout, str) and timeout.strip().isdigit():
|
if stripped.isdigit():
|
||||||
prefixes.append(f"[timeout after {int(timeout.strip())}s]")
|
timeout_seconds = int(stripped)
|
||||||
appended = True
|
else:
|
||||||
if not appended:
|
digits = "".join(ch for ch in stripped if ch.isdigit())
|
||||||
prefixes.append("[timeout]")
|
if digits:
|
||||||
|
timeout_seconds = int(digits)
|
||||||
|
|
||||||
|
if timeout_seconds and timeout_seconds >= 60:
|
||||||
|
prefixes.append(f"[partial_output ~{timeout_seconds}s]")
|
||||||
|
partial_output_note = f"已等待约{timeout_seconds}秒,命令可能仍在运行"
|
||||||
|
partial_no_output_note = f"已等待约{timeout_seconds}秒未捕获输出,命令可能仍在运行"
|
||||||
elif status in {"killed"}:
|
elif status in {"killed"}:
|
||||||
prefixes.append("[killed]")
|
prefixes.append("[killed]")
|
||||||
elif status in {"awaiting_input"}:
|
elif status in {"awaiting_input"}:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user