refactor: remove redundant comments and docstrings (#6527)
* refactor: remove redundant comments and docstrings * fix(signal): annotate async context manager as a generator
This commit is contained in:
1 parent
cb3ba45317
commit
a4d2430140
922 files changed
+406
-7738
No files matched your search
@@ -1,5 +1,3 @@
|
||||
"""Tool hint formatting for concise, human-readable tool call display."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
@@ -26,7 +24,6 @@ _TOOL_FORMATS: dict[str, tuple[list[str], str, bool, bool]] = {
|
||||
"list_dir": (["path"], "ls {}", True, False),
|
||||
}
|
||||
|
||||
# Matches file paths embedded in shell commands, including quoted paths with spaces.
|
||||
_PATH_IN_CMD_RE = re.compile(
|
||||
r'"(?P<double>(?:[A-Za-z]:[/\\]|~/|/)[^"]+)"'
|
||||
r"|'(?P<single>(?:[A-Za-z]:[/\\]|~/|/)[^']+)'"
|
||||
@@ -83,7 +80,6 @@ def format_tool_hints(tool_calls: list[ToolCallRequest], max_length: int = 40) -
|
||||
|
||||
|
||||
def _get_args(tc: ToolCallRequest) -> dict[str, object]:
|
||||
"""Extract args dict from tc.arguments, handling list/dict/None/empty."""
|
||||
if tc.arguments is None:
|
||||
return {}
|
||||
arguments = tc.arguments
|
||||
@@ -97,7 +93,6 @@ def _get_args(tc: ToolCallRequest) -> dict[str, object]:
|
||||
|
||||
|
||||
def _extract_arg(tc: ToolCallRequest, key_args: list[str]) -> str | None:
|
||||
"""Extract the first available value from preferred key names."""
|
||||
args = _get_args(tc)
|
||||
for key in key_args:
|
||||
val = args.get(key)
|
||||
@@ -116,25 +111,21 @@ def _extract_arg(tc: ToolCallRequest, key_args: list[str]) -> str | None:
|
||||
|
||||
|
||||
def _fmt_known(tc: ToolCallRequest, fmt: ToolFormat, max_length: int = 40) -> str:
|
||||
"""Format a registered tool using its template."""
|
||||
if not fmt[0] and "{}" not in fmt[1]:
|
||||
return fmt[1]
|
||||
val = _extract_arg(tc, fmt[0])
|
||||
if val is None:
|
||||
return tc.name
|
||||
if fmt[2]: # is_path
|
||||
if fmt[2]:
|
||||
val = abbreviate_path(val, max_len=max_length)
|
||||
elif fmt[3]: # is_command
|
||||
elif fmt[3]:
|
||||
val = _abbreviate_command(val, max_len=max_length)
|
||||
elif len(val) > max_length:
|
||||
# Plain values (grep patterns, search queries, ...) have no path or
|
||||
# command structure to fold, so fall back to a hard truncation.
|
||||
val = val[:max_length - 1] + "\u2026"
|
||||
return fmt[1].format(val)
|
||||
|
||||
|
||||
def _abbreviate_command(cmd: str, max_len: int = 40) -> str:
|
||||
"""Abbreviate paths in a command string, then truncate."""
|
||||
path_max = max(max_len // 2, 25)
|
||||
|
||||
def _replace_path(match: re.Match[str]) -> str:
|
||||
@@ -151,7 +142,6 @@ def _abbreviate_command(cmd: str, max_len: int = 40) -> str:
|
||||
|
||||
|
||||
def _fmt_mcp(tc: ToolCallRequest, max_length: int = 40) -> str:
|
||||
"""Format MCP tool as server::tool."""
|
||||
name = tc.name
|
||||
if "__" in name:
|
||||
parts = name.split("__", 1)
|
||||
@@ -172,7 +162,6 @@ def _fmt_mcp(tc: ToolCallRequest, max_length: int = 40) -> str:
|
||||
|
||||
|
||||
def _fmt_fallback(tc: ToolCallRequest, max_length: int = 40) -> str:
|
||||
"""Original formatting logic for unregistered tools."""
|
||||
args = _get_args(tc)
|
||||
val = next(iter(args.values()), None)
|
||||
if not isinstance(val, str):
|
||||
|
||||
Reference in new issue
Block a user