Skip to content

The agent that grows with you

fix(acp): project the owner's todo.updated as the native plan update

Teknium79aed999c54c
diff --git a/acp_adapter/gateway_server.py b/acp_adapter/gateway_server.py
index 8fe4a300a1d..ff24da04893 100644
--- a/acp_adapter/gateway_server.py
+++ b/acp_adapter/gateway_server.py
@@ -749,8 +749,8 @@ class GatewayACPAgent(acp.Agent):
if task:
task.cancel()
return
- if kind == "reasoning.delta":
- await self._project_reasoning(editor_id, payload)
+ if kind in {"reasoning.delta", "todo.updated"}:
+ await self._project_side_update(kind, editor_id, payload)
return
# In-process turns publish ``tool_name``; managed workers publish ``name``.
tool_name = payload.get("tool_name") or payload.get("name") or "tool"
@@ -809,12 +809,24 @@ class GatewayACPAgent(acp.Agent):
finally:
self._settling.discard(aid)
- async def _project_reasoning(self, editor_id, payload):
- """The model's reasoning as thought chunks, as the in-process server streamed it. It never enters the
- reply's segments, so ``message.complete``'s final remainder is unchanged."""
- text = _text(payload)
- if text and self._conn:
- await self._conn.session_update(session_id=editor_id, update=acp.update_agent_thought_text(text))
+ async def _project_side_update(self, kind, editor_id, payload):
+ """Turn events outside the reply text, as the in-process server projected them.
+
+ ``reasoning.delta``: the model's reasoning as thought chunks. It never enters the reply's segments,
+ so ``message.complete``'s final remainder is unchanged.
+ ``todo.updated``: the owner's full todo snapshot (published for a LOCAL session's turn, which an ACP
+ session is) as the native ``plan`` update Zed renders as its task panel (#134889 ACP-5)."""
+ if kind == "reasoning.delta":
+ text = _text(payload)
+ update = acp.update_agent_thought_text(text) if text else None
+ else:
+ import json
+ from acp_adapter.events import _build_plan_update_from_todo_result
+ todos = payload.get("todos")
+ update = _build_plan_update_from_todo_result(json.dumps({"todos": todos})) \
+ if isinstance(todos, list) else None
+ if update is not None and self._conn:
+ await self._conn.session_update(session_id=editor_id, update=update)
async def _project_session_state(self, kind, sid, editor_id, payload):
if kind == "session.usage":
diff --git a/tests/acp_adapter/test_gateway_event_mapping.py b/tests/acp_adapter/test_gateway_event_mapping.py
new file mode 100644
index 00000000000..5abcdb90ed3
--- /dev/null
+++ b/tests/acp_adapter/test_gateway_event_mapping.py
@@ -0,0 +1,60 @@
+"""The gateway's turn events reach the editor as the in-process ACP agent projected them (#134889
+ACP-5, ACP-15): native plan updates, the executor's tool verdict, closed tool and permission bubbles,
+and ``messageId`` on assistant chunks."""
+import asyncio
+import json
+from types import SimpleNamespace
+from unittest.mock import AsyncMock
+
+import pytest
+from acp.schema import AgentPlanUpdate, AllowedOutcome, DeniedOutcome
+
+from acp_adapter.gateway_server import GatewayACPAgent
+
+TODOS = [{'id': '1', 'content': 'write the test', 'status': 'completed'},
+ {'id': '2', 'content': 'fix the bug', 'status': 'in_progress'},
+ {'id': '3', 'content': 'drop the hack', 'status': 'cancelled'}]
+
+
+def agent():
+ agent = GatewayACPAgent()
+ agent._snapshots['s'] = {}
+ agent._gateway = AsyncMock()
+ agent._conn = AsyncMock()
+ return agent
+
+
+def updates(agent):
+ return [call.kwargs['update'] for call in agent._conn.session_update.await_args_list]
+
+
+async def project(agent, kind, payload, aid='a'):
+ await agent._project({'session_id': 's', 'type': kind, 'admission_id': aid, 'payload': payload})
+
+
+async def test_todo_updated_becomes_the_native_plan_update():
+ """The owner publishes ``todo.updated`` for a local viewer's turn (an ACP session is LOCAL);
+ the in-process agent sent Zed's task panel a ``plan`` update from the todo result."""
+ editor = agent()
+ await project(editor, 'todo.updated', {'todos': TODOS, 'revision': 2})
+ (plan,) = updates(editor)
+ assert isinstance(plan, AgentPlanUpdate)
+ assert [(e.content, e.status) for e in plan.entries] == [
+ ('write the test', 'completed'), ('fix the bug', 'in_progress'), ('[cancelled] drop the hack', 'completed')]
+
+
+def test_an_acp_session_turn_publishes_todo_updated():
+ """The real owner path: a LOCAL (ACP-created) turn's todo tool completion publishes ``todo.updated``."""
+ from gateway.config import Platform
+ from gateway.run_turn_runner import TurnRunner
+ published = []
+ turn = object.__new__(TurnRunner)
+ turn._ctx = SimpleNamespace(source=SimpleNamespace(platform=Platform.LOCAL, chat_id='chat'),
+ _voice_ack_guild=[None], _native_slack_task_cards=False, progress_mode='all')
+ turn._approval_owner = (SimpleNamespace(sessions={'s': SimpleNamespace(tool_progress_mode=None)}), 's', 1)
+ turn._publish_execution = lambda kind, payload: published.append((kind, payload)) or True
+ turn._publish_api_tool = lambda *a, **k: None
+ turn.combined_tool_start_callback('t1', 'todo', {'todos': TODOS})
+ turn.combined_tool_complete_callback('t1', 'todo', {'todos': TODOS}, json.dumps({'todos': TODOS, 'revision': 2}))
+ assert ('todo.updated', {'todos': TODOS, 'revision': 2}) in published