fix(agent): address code review findings for tool hint enhancement

- C1: Fix IndexError on empty list arguments via _get_args() helper
- I1: Remove redundant branch in _fmt_known
- I2: Export abbreviate_path from nanobot.utils.__init__
- I3: Fix _abbreviate_url negative-budget format consistency
- S1: Move FORMATS to class-level _TOOL_HINT_FORMATS constant
- S2: Add list_dir to FORMATS registry (ls path)
- G1-G5: Add tests for empty list args, None args, URL edge cases,
  mixed folding groups, and list_dir format
This commit is contained in:
chengyongru
2026-04-07 15:15:07 +08:00
committed by Xubin Ren
parent b1d3c00deb
commit 3e3a7654f8
5 changed files with 107 additions and 23 deletions
+2 -1
View File
@@ -89,7 +89,8 @@ def _abbreviate_url(url: str, max_len: int = 40) -> str:
budget = max_len - len(domain) - len(basename) - 4 # "…/" + "/"
if budget < 0:
return domain + "/\u2026" + basename[: max_len - len(domain) - 4]
trunc = max_len - len(domain) - 5 # "…/" + "/"
return domain + "/\u2026/" + (basename[:trunc] if trunc > 0 else "")
# Build abbreviated path
kept: list[str] = []