mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-13 03:52:00 +00:00
fix(cli): honor positive tool preview length
This commit is contained in:
parent
eef23354a5
commit
6d9b30632d
2 changed files with 52 additions and 2 deletions
|
|
@ -852,13 +852,15 @@ def get_cute_tool_message(
|
||||||
s = str(s)
|
s = str(s)
|
||||||
if _tool_preview_max_len == 0:
|
if _tool_preview_max_len == 0:
|
||||||
return s # no limit
|
return s # no limit
|
||||||
return (s[:n-3] + "...") if len(s) > n else s
|
limit = _tool_preview_max_len
|
||||||
|
return (s[:limit-3] + "...") if len(s) > limit else s
|
||||||
|
|
||||||
def _path(p, n=35):
|
def _path(p, n=35):
|
||||||
p = str(p)
|
p = str(p)
|
||||||
if _tool_preview_max_len == 0:
|
if _tool_preview_max_len == 0:
|
||||||
return p # no limit
|
return p # no limit
|
||||||
return ("..." + p[-(n-3):]) if len(p) > n else p
|
limit = _tool_preview_max_len
|
||||||
|
return ("..." + p[-(limit-3):]) if len(p) > limit else p
|
||||||
|
|
||||||
def _wrap(line: str) -> str:
|
def _wrap(line: str) -> str:
|
||||||
"""Apply skin tool prefix and failure suffix."""
|
"""Apply skin tool prefix and failure suffix."""
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,21 @@ from agent.display import (
|
||||||
build_tool_preview,
|
build_tool_preview,
|
||||||
capture_local_edit_snapshot,
|
capture_local_edit_snapshot,
|
||||||
extract_edit_diff,
|
extract_edit_diff,
|
||||||
|
get_cute_tool_message,
|
||||||
|
set_tool_preview_max_len,
|
||||||
_render_inline_unified_diff,
|
_render_inline_unified_diff,
|
||||||
_summarize_rendered_diff_sections,
|
_summarize_rendered_diff_sections,
|
||||||
render_edit_diff_with_delta,
|
render_edit_diff_with_delta,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def reset_tool_preview_max_len():
|
||||||
|
set_tool_preview_max_len(0)
|
||||||
|
yield
|
||||||
|
set_tool_preview_max_len(0)
|
||||||
|
|
||||||
|
|
||||||
class TestBuildToolPreview:
|
class TestBuildToolPreview:
|
||||||
"""Tests for build_tool_preview defensive handling and normal operation."""
|
"""Tests for build_tool_preview defensive handling and normal operation."""
|
||||||
|
|
||||||
|
|
@ -102,6 +111,45 @@ class TestBuildToolPreview:
|
||||||
assert build_tool_preview("terminal", []) is None
|
assert build_tool_preview("terminal", []) is None
|
||||||
|
|
||||||
|
|
||||||
|
class TestCuteToolMessagePreviewLength:
|
||||||
|
def test_terminal_preview_unlimited_when_config_is_zero(self):
|
||||||
|
set_tool_preview_max_len(0)
|
||||||
|
command = "curl -s http://localhost:9222/json/list | jq -r '.[] | select(.type==\"page\")' | head -5"
|
||||||
|
|
||||||
|
line = get_cute_tool_message("terminal", {"command": command}, 0.1)
|
||||||
|
|
||||||
|
assert command in line
|
||||||
|
assert "..." not in line
|
||||||
|
|
||||||
|
def test_terminal_preview_uses_positive_configured_limit(self):
|
||||||
|
set_tool_preview_max_len(80)
|
||||||
|
command = "curl -s http://localhost:9222/json/list | jq -r '.[] | select(.type==\"page\")' | head -5"
|
||||||
|
|
||||||
|
line = get_cute_tool_message("terminal", {"command": command}, 0.1)
|
||||||
|
|
||||||
|
assert command[:77] in line
|
||||||
|
assert "..." in line
|
||||||
|
assert "head -5" not in line
|
||||||
|
|
||||||
|
def test_search_files_preview_uses_positive_configured_limit_not_default(self):
|
||||||
|
set_tool_preview_max_len(80)
|
||||||
|
pattern = "function.formatToolCall.context.preview.compactPreview.maxLength.truncate"
|
||||||
|
|
||||||
|
line = get_cute_tool_message("search_files", {"pattern": pattern}, 0.1)
|
||||||
|
|
||||||
|
assert pattern in line
|
||||||
|
assert "..." not in line
|
||||||
|
|
||||||
|
def test_path_preview_uses_positive_configured_limit_not_default(self):
|
||||||
|
set_tool_preview_max_len(80)
|
||||||
|
path = "/tmp/hermes-test-preview-length/deeply/nested/path/test-output.txt"
|
||||||
|
|
||||||
|
line = get_cute_tool_message("read_file", {"path": path}, 0.1)
|
||||||
|
|
||||||
|
assert path in line
|
||||||
|
assert "..." not in line
|
||||||
|
|
||||||
|
|
||||||
class TestEditDiffPreview:
|
class TestEditDiffPreview:
|
||||||
def test_extract_edit_diff_for_patch(self):
|
def test_extract_edit_diff_for_patch(self):
|
||||||
diff = extract_edit_diff("patch", '{"success": true, "diff": "--- a/x\\n+++ b/x\\n"}')
|
diff = extract_edit_diff("patch", '{"success": true, "diff": "--- a/x\\n+++ b/x\\n"}')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue