Skip to content

Commit 6984ee7

Browse files
committed
refactor: better specificity in method
1 parent 989d929 commit 6984ee7

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/agent_chat_cli/core/actions.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ def __init__(self, app: "AgentChatCLIApp") -> None:
1717
def quit(self) -> None:
1818
self.app.exit()
1919

20-
async def add_message_to_chat(self, type: MessageType, content: str) -> None:
20+
async def add_message_to_chat_history(
21+
self, type: MessageType, content: str
22+
) -> None:
2123
match type:
2224
case MessageType.USER:
2325
message = Message.user(content)
@@ -39,7 +41,7 @@ async def submit_user_message(self, message: str) -> None:
3941
await self._query(message)
4042

4143
async def post_system_message(self, message: str) -> None:
42-
await self.add_message_to_chat(MessageType.SYSTEM, message)
44+
await self.add_message_to_chat_history(MessageType.SYSTEM, message)
4345

4446
async def render_message(self, message) -> None:
4547
await self.app.renderer.render_message(message)

src/agent_chat_cli/core/renderer.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,18 @@ async def _render_system_message(self, message: AgentMessage) -> None:
102102
message.data if isinstance(message.data, str) else str(message.data)
103103
)
104104

105-
await self.app.actions.add_message_to_chat(MessageType.SYSTEM, system_content)
105+
await self.app.actions.add_message_to_chat_history(
106+
MessageType.SYSTEM, system_content
107+
)
106108

107109
async def _render_user_message(self, message: AgentMessage) -> None:
108110
user_content = (
109111
message.data if isinstance(message.data, str) else str(message.data)
110112
)
111113

112-
await self.app.actions.add_message_to_chat(MessageType.USER, user_content)
114+
await self.app.actions.add_message_to_chat_history(
115+
MessageType.USER, user_content
116+
)
113117

114118
async def _render_tool_permission_request(self, message: AgentMessage) -> None:
115119
log_json(

tests/core/test_actions.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async def test_adds_user_message(self, mock_agent_loop, mock_config):
4242
async with app.run_test():
4343
chat_history = app.query_one(ChatHistory)
4444

45-
await app.actions.add_message_to_chat(MessageType.USER, "Hello")
45+
await app.actions.add_message_to_chat_history(MessageType.USER, "Hello")
4646

4747
widgets = chat_history.query(UserMessage)
4848
assert len(widgets) == 1
@@ -53,7 +53,9 @@ async def test_adds_system_message(self, mock_agent_loop, mock_config):
5353
async with app.run_test():
5454
chat_history = app.query_one(ChatHistory)
5555

56-
await app.actions.add_message_to_chat(MessageType.SYSTEM, "System alert")
56+
await app.actions.add_message_to_chat_history(
57+
MessageType.SYSTEM, "System alert"
58+
)
5759

5860
widgets = chat_history.query(SystemMessage)
5961
assert len(widgets) == 1
@@ -64,7 +66,9 @@ async def test_adds_agent_message(self, mock_agent_loop, mock_config):
6466
async with app.run_test():
6567
chat_history = app.query_one(ChatHistory)
6668

67-
await app.actions.add_message_to_chat(MessageType.AGENT, "I can help")
69+
await app.actions.add_message_to_chat_history(
70+
MessageType.AGENT, "I can help"
71+
)
6872

6973
widgets = chat_history.query(AgentMessage)
7074
assert len(widgets) == 1
@@ -74,7 +78,9 @@ async def test_raises_for_unsupported_type(self, mock_agent_loop, mock_config):
7478
app = AgentChatCLIApp()
7579
async with app.run_test():
7680
with pytest.raises(ValueError, match="Unsupported message type"):
77-
await app.actions.add_message_to_chat(MessageType.TOOL, "tool content")
81+
await app.actions.add_message_to_chat_history(
82+
MessageType.TOOL, "tool content"
83+
)
7884

7985

8086
class TestActionsPostSystemMessage:

0 commit comments

Comments
 (0)