Skip to content

The agent that grows with you

fix(approval): show hidden characters on the remaining first-render prompt surfaces

Teknium33bce7b26dd4
diff --git a/acp_adapter/edit_approval.py b/acp_adapter/edit_approval.py
index 12f517472c8..6c161eeb145 100644
--- a/acp_adapter/edit_approval.py
+++ b/acp_adapter/edit_approval.py
@@ -200,9 +200,12 @@ def maybe_require_edit_approval(tool_name: str, arguments: dict[str, Any]) -> st
def build_acp_edit_tool_call(proposal: EditProposal):
"""Build the ToolCallUpdate payload for ACP request_permission."""
import acp
+ from agent.redact import redact_approval_display
+ # The title is display text; the diff keeps the raw path the client opens.
return acp.update_tool_call(
- f"edit-approval-{next(_PERMISSION_REQUEST_IDS)}", title=f"Approve edit: {proposal.path}", kind="edit",
+ f"edit-approval-{next(_PERMISSION_REQUEST_IDS)}", title=f"Approve edit: {redact_approval_display(proposal.path)}",
+ kind="edit",
status="pending",
content=[acp.tool_diff_content(path=proposal.path, old_text=proposal.old_text, new_text=proposal.new_text)],
raw_input={"tool": proposal.tool_name, "arguments": proposal.arguments},
diff --git a/agent/display.py b/agent/display.py
index daf0c0abcd8..9ac45f1e331 100644
--- a/agent/display.py
+++ b/agent/display.py
@@ -17,7 +17,7 @@ from urllib.parse import urlsplit
from utils import safe_json_loads
from agent.i18n import t
-from agent.redact import redact_sensitive_text
+from agent.redact import redact_sensitive_text, sanitize_command_for_display
from agent.tool_result_classification import (
shape_failure_error, file_mutation_result_landed, has_failure_marker, is_guardrail_refusal)
@@ -406,7 +406,9 @@ def _preview_todo_list(args: dict, _max_len: int) -> str:
def _preview_shell(key: str):
def _build(args: dict, max_len: int) -> str | None:
command = args.get(key)
- return None if command is None else _tail_trunc(summarize_shell_command(str(command)), max_len) or None
+ # Sanitize before summarizing: the spinner sits under the approval prompt and must not hide what it does.
+ return None if command is None else _tail_trunc(
+ summarize_shell_command(sanitize_command_for_display(str(command))), max_len) or None
return _build
diff --git a/tests/agent/test_approval_display_sanitize.py b/tests/agent/test_approval_display_sanitize.py
index c5160e59497..41c73ed7a45 100644
--- a/tests/agent/test_approval_display_sanitize.py
+++ b/tests/agent/test_approval_display_sanitize.py
@@ -68,3 +68,32 @@ def test_consent_descriptions_are_sanitized_on_tui_and_api_egress():
for payload in (_approval_request_payload(data), _approval_request_event("run1", data)):
assert payload["description"] == sanitize_command_for_display(data["description"])
assert "\u202e" not in payload["description"] and _TAIL in payload["description"][:200]
+
+
+def test_first_render_surfaces_get_the_display_copy_while_values_stay_raw(monkeypatch):
+ import json
+ from types import SimpleNamespace
+
+ from agent.display import build_tool_preview
+ from tools import approval_context, approval_prompt
+ from tools.clarify_tool import clarify_tool
+
+ raw = "rm -rf ./build\u200b-cache" + "\u2028" * 60 + "; " + _TAIL
+ # Selected plugin transport: command and description arrive as the display copy.
+ seen = []
+ monkeypatch.setattr(approval_context, "_get_approval_transport_config", lambda: ("phone", None))
+ monkeypatch.setattr(approval_prompt, "get_plugin_manager", lambda: SimpleNamespace(
+ get_approval_transport=lambda name: SimpleNamespace(present=lambda r: seen.append(r) or r.respond("deny"))))
+ approval_prompt._present_with_selected_transport(
+ command=raw, description="why\u202e", pattern_key="k", pattern_keys=["k"], session_key="s",
+ surface="cli", allow_session=True, allow_permanent=True)
+ assert (seen[0].command, seen[0].description) == (sanitize_command_for_display(raw), "why\\u202e")
+ # Tool-progress line under the prompt shows the hidden characters instead of collapsing them.
+ preview = build_tool_preview("terminal", {"command": raw}, max_len=0)
+ assert "\\u200b" in preview and "\\u2028 \u00d760" in preview
+ # Clarify: the surface renders the display copy; the tool result echoes the raw question and choice.
+ asked = []
+ result = json.loads(clarify_tool([{"question": raw, "choices": ["go\u200b"]}], callback=lambda qs: asked.extend(qs)
+ or {"answers": {qs[0]["qid"]: qs[0]["choices_offered"][0]}, "outcome": "submitted"}))
+ assert asked[0]["question"] == sanitize_command_for_display(raw)
+ assert result["responses"][0]["question"] == raw and result["responses"][0]["user_response"] == "go\u200b"
diff --git a/tools/clarify_tool.py b/tools/clarify_tool.py
index dc381891e0f..a4a89c358b4 100644
--- a/tools/clarify_tool.py
+++ b/tools/clarify_tool.py
@@ -116,11 +116,15 @@ def clarify_tool(questions, callback: Optional[Callable] = None) -> str:
return tool_error(error)
if callback is None:
return tool_error(_UNAVAILABLE)
+ from agent.redact import redact_approval_display
from tools.human_input_hooks import human_input_request
+ # Every surface renders the display copy of the question; the result echoes the raw text. Choices stay
+ # raw: a picked choice is the answer value.
+ shown = [{**q, "question": redact_approval_display(q["question"])} for q in normalized]
# Observers see the questions only; the answers stay in the tool result.
- with human_input_request("clarify", prompt="\n".join(q["question"] for q in normalized)) as human:
+ with human_input_request("clarify", prompt="\n".join(q["question"] for q in shown)) as human:
try:
- reply = callback(normalized)
+ reply = callback(shown)
human.outcome = str(reply.get("outcome") or "")
return _result(normalized, reply)
except Exception as exc:
diff --git a/tools/human_input_hooks.py b/tools/human_input_hooks.py
index 99c32e4d0fb..2b131134a88 100644
--- a/tools/human_input_hooks.py
+++ b/tools/human_input_hooks.py
@@ -4,7 +4,7 @@
dangerous-command approval) and ``on_human_input_resolved`` fires exactly once when the wait ends,
with the same ``request_id`` and an ``outcome``. Observers only: return values are ignored and a
failing plugin never affects the prompt. Payloads never carry what the human typed (password,
-answers), and ``prompt`` is force-redacted so credentials in a command never reach a plugin.
+answers), and ``prompt`` is force-redacted (with hidden characters shown) so credentials in a command never reach a plugin.
"""
from __future__ import annotations
@@ -28,8 +28,8 @@ class HumanInputRequest:
def _redacted(text: str) -> str:
try:
- from agent.redact import redact_sensitive_text
- return redact_sensitive_text(str(text or ""), force=True)
+ from agent.redact import redact_approval_display
+ return redact_approval_display(text, force=True)
except Exception:
logger.debug("human-input hook prompt redaction failed", exc_info=True)
return "" # never fall back to the raw text