feat(config): add toolHintMaxLength to control tool hint truncation

Add  to  config (default: 40, range: 20-500).
Controls how many characters of tool hints are shown in progress updates
(e.g. '$ cd …/project && npm test').

Set to 120+ to see full commands instead of truncated hints:

```json
{
  "agents": {
    "defaults": {
      "toolHintMaxLength": 120
    }
  }
}
```

- Thread max_length through format_tool_hints → _fmt_known/_fmt_mcp/_fmt_fallback
- Make path abbreviation in _abbreviate_command proportional to max_length
- Add TestToolHintMaxLength test class with 5 tests
- All 41 existing tests pass
This commit is contained in:
Tim O'Brien
2026-05-06 21:18:39 +08:00
committed by Xubin Ren
parent 653de4a7ef
commit daa4a25c9b
4 changed files with 62 additions and 18 deletions
+37 -2
View File
@@ -8,9 +8,9 @@ def _tc(name: str, args) -> ToolCallRequest:
return ToolCallRequest(id="c1", name=name, arguments=args)
def _hint(calls):
def _hint(calls, max_length=40):
"""Shortcut for format_tool_hints."""
return format_tool_hints(calls)
return format_tool_hints(calls, max_length=max_length)
class TestToolHintKnownTools:
@@ -254,3 +254,38 @@ class TestToolHintMixedFolding:
assert "\u00d7" not in result
parts = result.split(", ")
assert len(parts) == 5
class TestToolHintMaxLength:
"""Test max_length parameter controls truncation of tool hints."""
def test_exec_default_truncates_at_40(self):
cmd = "cd /very/long/path/to/some/project && npm run build && npm test"
result = _hint([_tc("exec", {"command": cmd})], max_length=40)
assert len(result) <= 50 # "$ " prefix + 40 + ellipsis
assert "\u2026" in result
def test_exec_larger_max_length_shows_more(self):
cmd = "cd /very/long/path/to/some/project && npm run build && npm test"
short = _hint([_tc("exec", {"command": cmd})], max_length=40)
long = _hint([_tc("exec", {"command": cmd})], max_length=120)
assert len(long) > len(short)
assert "npm test" in long
def test_exec_max_length_120_shows_full_command(self):
cmd = "cd /home/user/project && npm install && npm run build"
result = _hint([_tc("exec", {"command": cmd})], max_length=120)
assert "npm run build" in result
def test_fallback_respects_max_length(self):
long_val = "a" * 100
result = _hint([_tc("custom_tool", {"data": long_val})], max_length=60)
assert "\u2026" in result
result_40 = _hint([_tc("custom_tool", {"data": long_val})], max_length=40)
assert len(result) > len(result_40)
def test_mcp_respects_max_length(self):
long_url = "https://example.com/very/long/path/to/resource"
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)