From fb313bd8d1e0034ffc08b86135bc01d083836a69 Mon Sep 17 00:00:00 2001 From: Tim O'Brien Date: Wed, 6 May 2026 05:39:55 +0000 Subject: [PATCH] fix(tool_hints): pass max_length to abbreviate_path for is_path tools The is_path branch in _fmt_known was not passing max_length to abbreviate_path, so read_file, write_file, edit, list_dir, and web_fetch always truncated paths at 40 chars regardless of config. Now all three branches (is_path, is_command, fallback) honor the configured toolHintMaxLength. --- nanobot/utils/tool_hints.py | 2 +- tests/agent/test_tool_hint.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/nanobot/utils/tool_hints.py b/nanobot/utils/tool_hints.py index 75d3e3521..289870665 100644 --- a/nanobot/utils/tool_hints.py +++ b/nanobot/utils/tool_hints.py @@ -86,7 +86,7 @@ def _fmt_known(tc, fmt: tuple, max_length: int = 40) -> str: if val is None: return tc.name if fmt[2]: # is_path - val = abbreviate_path(val) + val = abbreviate_path(val, max_len=max_length) elif fmt[3]: # is_command val = _abbreviate_command(val, max_len=max_length) return fmt[1].format(val) diff --git a/tests/agent/test_tool_hint.py b/tests/agent/test_tool_hint.py index ff73fbb5c..174eb208d 100644 --- a/tests/agent/test_tool_hint.py +++ b/tests/agent/test_tool_hint.py @@ -289,3 +289,24 @@ class TestToolHintMaxLength: result = _hint([_tc("mcp_github__fetch", {"url": long_url})], max_length=80) result_40 = _hint([_tc("mcp_github__fetch", {"url": long_url})], max_length=40) assert len(result) >= len(result_40) + + def test_path_type_respects_max_length(self): + """Path-type tools (read_file, write_file, etc.) should honor max_length.""" + long_path = "/home/user/.local/share/uv/tools/nanobot/agent/loop.py" + short = _hint([_tc("read_file", {"path": long_path})], max_length=40) + long = _hint([_tc("read_file", {"path": long_path})], max_length=120) + assert len(long) > len(short) + + def test_edit_path_respects_max_length(self): + """edit (is_path=True) should honor max_length, not stay hardcoded at 40.""" + long_path = "/home/user/projects/nanobot/src/agent/loop.py" + short = _hint([_tc("edit", {"file_path": long_path})], max_length=40) + long = _hint([_tc("edit", {"file_path": long_path})], max_length=120) + assert len(long) > len(short) + + def test_list_dir_path_respects_max_length(self): + """list_dir (is_path=True) should honor max_length.""" + long_path = "/home/user/.local/share/uv/tools/nanobot/" + short = _hint([_tc("list_dir", {"path": long_path})], max_length=40) + long = _hint([_tc("list_dir", {"path": long_path})], max_length=120) + assert len(long) > len(short)