Skip to content

Commit a18e269

Browse files
committed
fix(contrib): preserve tool names in session snapshots
1 parent aade9c0 commit a18e269

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

‎docs/contrib.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Feed raw `SessionNotification` events into one accumulator per UI controller and
1414

1515
- `apply(notification)` merges message chunks, plan updates, mode/config changes, and `tool_call` / `tool_call_update` payloads (including out-of-order updates).
1616
- `snapshot()` returns an immutable `SessionSnapshot` Pydantic model with copied tool input/output payloads.
17+
- Each tool call snapshot includes the optional programmatic `name`. An update that omits the name or sets it to `null` leaves the previous name unchanged.
1718
- `subscribe(callback)` pushes updated snapshots to subscribers whenever state changes.
1819
- `auto_reset_on_session_change` resets accumulated state automatically when a new `session_id` arrives.
1920

‎src/acp/contrib/session_state.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class _MutableToolCallState:
5050
def __init__(self, tool_call_id: str) -> None:
5151
self.tool_call_id = tool_call_id
5252
self.title: str | None = None
53+
self.name: str | None = None
5354
self.kind: ToolKind | None = None
5455
self.status: ToolCallStatus | None = None
5556
self.content: list[Any] | None = None
@@ -59,6 +60,7 @@ def __init__(self, tool_call_id: str) -> None:
5960

6061
def apply_start(self, update: ToolCallStart) -> None:
6162
self.title = update.title
63+
self.name = update.name
6264
self.kind = update.kind
6365
self.status = update.status
6466
self.content = _copy_model_list(update.content)
@@ -69,6 +71,8 @@ def apply_start(self, update: ToolCallStart) -> None:
6971
def apply_progress(self, update: ToolCallProgress) -> None:
7072
if update.title is not None:
7173
self.title = update.title
74+
if update.name is not None:
75+
self.name = update.name
7276
if update.kind is not None:
7377
self.kind = update.kind
7478
if update.status is not None:
@@ -86,6 +90,7 @@ def snapshot(self) -> ToolCallView:
8690
return ToolCallView(
8791
tool_call_id=self.tool_call_id,
8892
title=self.title,
93+
name=self.name,
8994
kind=self.kind,
9095
status=self.status,
9196
content=tuple(item.model_copy(deep=True) for item in self.content) if self.content else None,
@@ -102,6 +107,7 @@ class ToolCallView(BaseModel):
102107

103108
tool_call_id: str
104109
title: str | None
110+
name: str | None = None
105111
kind: ToolKind | None
106112
status: ToolCallStatus | None
107113
content: tuple[Any, ...] | None

‎tests/contrib/test_contrib_session_state.py‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,11 @@ def test_session_accumulator_merges_tool_calls():
8888
session_update="tool_call",
8989
tool_call_id="call-1",
9090
title="Read file",
91+
name="read_file",
9192
status="in_progress",
9293
)
93-
acc.apply(notification("s", start))
94+
first_snapshot = acc.apply(notification("s", start))
95+
assert first_snapshot.tool_calls["call-1"].name == "read_file"
9496
progress = ToolCallProgress(
9597
session_update="tool_call_update",
9698
tool_call_id="call-1",
@@ -106,9 +108,22 @@ def test_session_accumulator_merges_tool_calls():
106108
tool = snapshot.tool_calls["call-1"]
107109
assert tool.status == "completed"
108110
assert tool.title == "Read file"
111+
assert tool.name == "read_file"
109112
assert tool.content and tool.content[0].content.text == "Done"
110113

111114

115+
def test_session_accumulator_updates_tool_name_from_progress():
116+
acc = SessionAccumulator()
117+
first = acc.apply(notification("s", ToolCallProgress(tool_call_id="call-1", name="read_file")))
118+
assert first.tool_calls["call-1"].name == "read_file"
119+
120+
updated = acc.apply(notification("s", ToolCallProgress(tool_call_id="call-1", name="read_resource")))
121+
assert updated.tool_calls["call-1"].name == "read_resource"
122+
123+
unchanged = acc.apply(notification("s", ToolCallProgress(tool_call_id="call-1", name=None)))
124+
assert unchanged.tool_calls["call-1"].name == "read_resource"
125+
126+
112127
def test_session_accumulator_records_plan_and_mode():
113128
acc = SessionAccumulator()
114129
acc.apply(

0 commit comments

Comments
 (0)