From dc27770f9e117cb8c00730d99e6283b054a3d7b9 Mon Sep 17 00:00:00 2001 From: Alessandro <155005371+3clyp50@users.noreply.github.com> Date: Sat, 5 Dec 2026 06:56:43 +0100 Subject: [PATCH] Show host execution output and readable delegation steps Connected-host code execution now writes its result into the step log, so the expanded step shows what ran. ACP delegation prints each tool call once it finishes, with its final one-line title, and separates the answer. The cwd argument also expands ~. --- plugins/_a0_acp/AGENTS.md | 1 + .../skills/acp-agents/scripts/acp_agent.py | 12 ++++--- plugins/_a0_acp/tests/test_acp_agent.py | 9 ++++-- plugins/_code_execution/AGENTS.md | 2 +- .../tools/code_execution_tool.py | 5 ++- tests/test_code_execution_destinations.py | 31 +++++++++++++++++++ 6 files changed, 50 insertions(+), 10 deletions(-) diff --git a/plugins/_a0_acp/AGENTS.md b/plugins/_a0_acp/AGENTS.md index 6ebc06f6a..c89240eb1 100644 --- a/plugins/_a0_acp/AGENTS.md +++ b/plugins/_a0_acp/AGENTS.md @@ -20,6 +20,7 @@ - When a program is missing from PATH on POSIX hosts, the script retries with PATH from the user's login shell, because hosts started from a GUI (A0 Launcher) miss what shell rc files add. - `auth_required` (-32000) prints a request for the user to sign in with the agent's own login. Agent stderr is shown only when a run fails. - `session=` continues through `session/resume`, then `session/load` with replay suppressed, else a new session. Output ends with `[ session <id>, stop reason: <reason>]`. +- Each tool call prints one `· <title>` line when it completes or fails, using its latest title folded to one line of at most 100 characters; a blank line separates those lines from the answer. - The skill's account rules (no sign-in, credentials, vendor calls or account switching; whole tasks only) bind every delegation. ## Work Guidance diff --git a/plugins/_a0_acp/skills/acp-agents/scripts/acp_agent.py b/plugins/_a0_acp/skills/acp-agents/scripts/acp_agent.py index b257e713f..fbb3225a9 100644 --- a/plugins/_a0_acp/skills/acp-agents/scripts/acp_agent.py +++ b/plugins/_a0_acp/skills/acp-agents/scripts/acp_agent.py @@ -34,7 +34,7 @@ class AcpError(Exception): def run(agent, message, cwd=None, session=None, permissions="all", command=None, env=None): """Send ``message`` to ``agent``; pass a printed ``session`` id to continue that session.""" title, argv, extra_env, needs = AGENTS.get(agent, (agent, None, {}, [])) - argv, cwd = list(command or argv or []), os.path.realpath(cwd or os.getcwd()) + argv, cwd = list(command or argv or []), os.path.realpath(os.path.expanduser(cwd or os.getcwd())) if not argv: return print(f"Unknown agent {agent!r}. Known: {', '.join(AGENTS)}; pass command=[...] for others.") env = {**os.environ, **extra_env, **(env or {})} @@ -62,7 +62,7 @@ def run(agent, message, cwd=None, session=None, permissions="all", command=None, if client.session_id: client.send(method="session/cancel", params={"sessionId": client.session_id}) raise - print("".join(client.answer).strip() or "(no answer)") + print("\n" * bool(client.seen) + ("".join(client.answer).strip() or "(no answer)")) print(f"\n[{title} session {session_id}, stop reason: {stop.get('stopReason')}]") @@ -125,12 +125,14 @@ class _Client: kind = update.get("sessionUpdate") if kind in ("tool_call", "tool_call_update"): call_id = update.get("toolCallId") - self.calls[call_id] = {**self.calls.get(call_id, {}), **{k: v for k, v in update.items() if v is not None}} - if update.get("title") and call_id not in self.seen and not self.replaying: + call = self.calls[call_id] = {**self.calls.get(call_id, {}), **{k: v for k, v in update.items() if v is not None}} + # Titles sharpen while a call runs ("Terminal" becomes the command), so print them when it ends. + if call.get("status") in ("completed", "failed") and call.get("title") and call_id not in self.seen and not self.replaying: self.seen.add(call_id) if self.answer and not self.answer[-1].endswith("\n\n"): self.answer.append("\n\n") - print(f"· {update['title']}", flush=True) + title = " ".join(call["title"].split()) + print(f"· {title[:100]}{'…' * (len(title) > 100)}", flush=True) elif kind == "agent_message_chunk" and not self.replaying: content = update.get("content") or {} if content.get("type") == "text": diff --git a/plugins/_a0_acp/tests/test_acp_agent.py b/plugins/_a0_acp/tests/test_acp_agent.py index abda8a9f3..b76813d9e 100644 --- a/plugins/_a0_acp/tests/test_acp_agent.py +++ b/plugins/_a0_acp/tests/test_acp_agent.py @@ -14,11 +14,14 @@ def send(**msg): print(json.dumps({"jsonrpc": "2.0", **msg}), flush=True) def ask(id, kind, path): - call = {"toolCallId": id, "title": kind, "kind": kind, "locations": [{"path": path}]} + call = {"toolCallId": id, "title": "Working", "kind": kind, "locations": [{"path": path}]} send(method="session/update", params={"sessionId": "s1", "update": {"sessionUpdate": "tool_call", **call}}) send(id=id, method="session/request_permission", params={"sessionId": "s1", "toolCall": {"toolCallId": id}, "options": [{"optionId": "yes", "name": "Allow", "kind": "allow_once"}, {"optionId": "no", "name": "Reject", "kind": "reject_once"}]}) - return json.loads(sys.stdin.readline())["result"]["outcome"].get("optionId", "cancelled") + outcome = json.loads(sys.stdin.readline())["result"]["outcome"].get("optionId", "cancelled") + done = {"toolCallId": id, "title": f"{kind}\n {path}", "status": "completed"} + send(method="session/update", params={"sessionId": "s1", "update": {"sessionUpdate": "tool_call_update", **done}}) + return outcome for line in sys.stdin: msg = json.loads(line) @@ -52,7 +55,7 @@ def test_delegation_applies_the_policy_and_continues_sessions(tmp_path, capsys): first = _run(tmp_path, capsys, permissions="edits") again = _run(tmp_path, capsys, session="s1") - assert "· edit" in first and "fix it -> ['yes', 'no', 'no']" in first + assert "· edit a.py\n" in first and "Working" not in first and "\n\nfix it -> ['yes', 'no', 'no']" in first assert first.rstrip().endswith("[fake session s1, stop reason: end_turn]") assert "fix it -> ['yes', 'yes', 'yes']" in again and "old reply" not in again diff --git a/plugins/_code_execution/AGENTS.md b/plugins/_code_execution/AGENTS.md index 9d32b1c1b..7bd4e7cf7 100644 --- a/plugins/_code_execution/AGENTS.md +++ b/plugins/_code_execution/AGENTS.md @@ -20,7 +20,7 @@ - Keep command previews compact in rendered execution output. `code-exe-handler.js` restores a matching command prefix from the already-masked `kvps.code` for Copy Output and step details, preserving command whitespace and the output body. Existing log size limits remain; copying cannot recover text already discarded by those limits. - Normalize logged `code` to display text before title and copy operations. Rejected malformed arguments can remain in stored logs; streaming and replay must render them without changing the original arguments. - Keep session concurrency, timeout, streaming, and reset behavior predictable. -- Record the resolved destination and session in code execution logs for step details, including omitted session defaults. +- Record the resolved destination and session in code execution logs for step details, including omitted session defaults. Connected-host results are also written to the step's log content. - Execution runtimes (`terminal`, `python`, `nodejs`) require a string `code` argument. Reject missing or non-string code with `RepairableException` before configuring or resetting shells; output polling and reset do not require code. Verify with `tests/test_code_execution_arguments.py`. - A direct parallel code job retains its worker and loop-bound shell until the command ends or is cancelled. Output timeouts publish model-facing progress to the registered job and continue polling; callers use parallel job IDs. Close parallel shells explicitly on that worker loop on completion or cancellation, including partially connected shells. Top-level sessions retain their ordinary timeout/output/reset behavior. - Execute multi-line terminal input as one current-shell compound so intermediate prompts cannot mark queued work complete; preserve `cd`, exports, and other shell state. diff --git a/plugins/_code_execution/tools/code_execution_tool.py b/plugins/_code_execution/tools/code_execution_tool.py index 8cc81c19f..e70ff8f9b 100644 --- a/plugins/_code_execution/tools/code_execution_tool.py +++ b/plugins/_code_execution/tools/code_execution_tool.py @@ -105,7 +105,10 @@ class CodeExecution(Tool): from plugins._a0_connector.helpers.host_execution import HostExecution ensure_retired_host_tool_allowed(self.agent, "code_execution_remote", tool_args=self.args) - return await HostExecution(self.agent, self.args, allow_running=self.allow_running).execute() + response = await HostExecution(self.agent, self.args, allow_running=self.allow_running).execute() + if getattr(self, "log", None): + self.log.update(content=response.message) + return response config = plugins.get_plugin_config("_code_execution", agent=self.agent) or {} if self.destination.kind == "local": diff --git a/tests/test_code_execution_destinations.py b/tests/test_code_execution_destinations.py index 016ee090b..b35b9dca7 100644 --- a/tests/test_code_execution_destinations.py +++ b/tests/test_code_execution_destinations.py @@ -194,3 +194,34 @@ def test_execution_logs_resolved_destination_and_session(monkeypatch, destinatio assert (tool.log.kvps["execution_destination"], tool.log.kvps["session"]) == expected assert tool.log.kvps["code"] == "echo test" + + +def test_host_execution_output_reaches_the_step_log(monkeypatch): + from helpers import tool_policy + from helpers.log import Log + from plugins._a0_connector.helpers import host_execution + from plugins._code_execution.tools import code_execution_tool + + async def resolve(agent, requested): + return ExecutionDestination("host", "host", "Connected host", "") + + class FakeHostExecution: + def __init__(self, agent, args, *, allow_running=False): + pass + + async def execute(self): + return SimpleNamespace(message="4 tests passed", break_loop=False) + + tool = object.__new__(CodeExecution) + tool.agent = SimpleNamespace(handle_intervention=lambda: asyncio.sleep(0)) + tool.args = {"runtime": "python", "code": "print(1)", "destination": "host"} + tool.allow_running = False + tool.log = Log().log(type="code_exe", kvps=tool.args) + monkeypatch.setattr(code_execution_tool, "resolve_code_execution_destination", resolve) + monkeypatch.setattr(code_execution_tool, "ensure_retired_host_tool_allowed", lambda *a, **k: None, raising=False) + monkeypatch.setattr(tool_policy, "ensure_retired_host_tool_allowed", lambda *a, **k: None) + monkeypatch.setattr(host_execution, "HostExecution", FakeHostExecution) + + asyncio.run(tool._execute(None)) + + assert tool.log.content == "4 tests passed"