Skip to content

The agent that grows with you

fix(display): memory progress lines render operations[] batches

Teknium1c39127d37f7
diff --git a/agent/display.py b/agent/display.py
index 6c590cad6d1..14cb2ffff50 100644
--- a/agent/display.py
+++ b/agent/display.py
@@ -416,13 +416,24 @@ def _preview_read_file(args: dict, max_len: int) -> str | None:
return None if label is None else _tail_trunc(f"{label} {_read_file_line_label(args)}".strip(), max_len) or None
+def _memory_first_op(args: dict) -> tuple[dict, str]:
+ """The op a memory progress line shows and a ``" (N more)"`` suffix for the rest of an
+ ``operations[]`` batch (the advertised shape); legacy top-level single-op args are their own op."""
+ ops = args.get("operations")
+ if not isinstance(ops, list) or not ops:
+ return args, ""
+ first = ops[0] if isinstance(ops[0], dict) else {}
+ return first, (f" ({t('cli.shared.n_more', count=len(ops) - 1)})" if len(ops) > 1 else "")
+
+
def _preview_memory(args: dict, _max_len: int) -> str:
- action, target = args.get("action", ""), args.get("target", "")
+ op, more = _memory_first_op(args)
+ action, target = op.get("action", ""), args.get("target", "")
if action == "add":
- return f"+{target}: \"{_clip(_oneline(args.get('content', '')), 25)}\""
+ return f"+{target}: \"{_clip(_oneline(op.get('content') or op.get('new_text') or ''), 25)}\"{more}"
if action in ("replace", "patch", "remove"):
- old = _oneline(args.get("old_text") or "") or t("display.preview.missing_old_text")
- return f"{'-' if action == 'remove' else '~'}{target}: \"{old[:20]}\""
+ old = _oneline(op.get("old_text") or "") or t("display.preview.missing_old_text")
+ return f"{'-' if action == 'remove' else '~'}{target}: \"{old[:20]}\"{more}"
return action
@@ -1163,12 +1174,14 @@ def _cute_todo_list(a: dict, result) -> str:
def _cute_memory(a: dict, _r) -> str:
- action, target = a.get("action", "?"), a.get("target", "")
+ op, more = _memory_first_op(a)
+ action, target = op.get("action", "?"), a.get("target", "")
if action == "add":
- return _cute_row("🧠", "memory", f"+{target}: \"{_cute_trunc(a.get('content', ''))}\"")
+ content = op.get("content") or op.get("new_text") or ""
+ return _cute_row("🧠", "memory", f"+{target}: \"{_cute_trunc(content)}\"{more}")
if action in ("replace", "patch", "remove"):
- old = a.get("old_text") or t("display.preview.missing_old_text")
- return _cute_row("🧠", "memory", f"{'-' if action == 'remove' else '~'}{target}: \"{_cute_trunc(old)}\"")
+ old = op.get("old_text") or t("display.preview.missing_old_text")
+ return _cute_row("🧠", "memory", f"{'-' if action == 'remove' else '~'}{target}: \"{_cute_trunc(old)}\"{more}")
return _cute_row("🧠", "memory", str(action))
diff --git a/tests/agent/test_display.py b/tests/agent/test_display.py
index ac4e2b06c8d..afd74c46130 100644
--- a/tests/agent/test_display.py
+++ b/tests/agent/test_display.py
@@ -57,6 +57,17 @@ class TestBuildToolPreview:
assert build_tool_preview("memory", args) == '~memory: "port 8080"'
assert '~memory: "port 8080"' in get_cute_tool_message("memory", args, 0.1)
+ def test_memory_operations_batch_previews_its_first_op_and_the_rest_count(self):
+ # operations[] is the memory tool's only advertised shape, so progress lines read it.
+ one = {"target": "user", "operations": [{"action": "add", "content": "Name: Alice"}]}
+ assert build_tool_preview("memory", one) == '+user: "Name: Alice"'
+ assert '+user: "Name: Alice"' in get_cute_tool_message("memory", one, 0.1)
+ three = {"target": "memory", "operations": [
+ {"action": "remove", "old_text": "port 8080"}, {"action": "add", "content": "a"},
+ {"action": "patch", "old_text": "b", "content": "c"}]}
+ assert build_tool_preview("memory", three) == '-memory: "port 8080" (2 more)'
+ assert '-memory: "port 8080" (2 more)' in get_cute_tool_message("memory", three, 0.1)
+
def test_browser_type_preview_redacts_api_key(self):
secret = "sk-proj-ABCD1234567890EFGH"
result = build_tool_preview("browser_type", {"ref": "@e3", "text": secret})