From 39f9a7f6361d30a2cf0ee407e3ec29fcade4055e Mon Sep 17 00:00:00 2001 From: worldmozara Date: Sat, 18 Jul 2026 13:22:42 +0800 Subject: [PATCH] ci/lint: ruff format todo stack and related CLI/agent files --- src/plyngent/agent/loop.py | 6 +----- src/plyngent/agent/todo_stack.py | 12 ++++-------- src/plyngent/cli/slash.py | 6 +----- src/plyngent/cli/state.py | 4 +--- tests/test_agent/test_todo_stack.py | 9 ++------- 5 files changed, 9 insertions(+), 28 deletions(-) diff --git a/src/plyngent/agent/loop.py b/src/plyngent/agent/loop.py index d3ce2f2..2446155 100644 --- a/src/plyngent/agent/loop.py +++ b/src/plyngent/agent/loop.py @@ -371,11 +371,7 @@ async def run_chat_loop( assistant = _last_assistant(messages, pre_len) tool_calls = assistant.tool_calls if tool_calls is UNSET or not tool_calls or tools is None: - if ( - todo_stack is not None - and todo_stack.needs_review() - and not todo_review_injected - ): + if todo_stack is not None and todo_stack.needs_review() and not todo_review_injected: todo_review_injected = True # Non-user control identity so retry/history don't treat this as human input. messages.append(DeveloperChatMessage(content=todo_stack.review_prompt())) diff --git a/src/plyngent/agent/todo_stack.py b/src/plyngent/agent/todo_stack.py index 84051fc..3c528d5 100644 --- a/src/plyngent/agent/todo_stack.py +++ b/src/plyngent/agent/todo_stack.py @@ -98,11 +98,11 @@ class TodoStack: frame_items = msgspec.convert(frame.get("items"), type=list[TodoItem]) items.extend(frame_items) return cls(TodoStackData(items=items, next_id=next_id)) - except (msgspec.ValidationError, TypeError, ValueError): + except msgspec.ValidationError, TypeError, ValueError: return cls() try: data = msgspec.convert(raw, type=TodoStackData) - except (msgspec.ValidationError, TypeError, ValueError): + except msgspec.ValidationError, TypeError, ValueError: return cls() if data.next_id < 1: data = msgspec.structs.replace(data, next_id=1) @@ -234,14 +234,10 @@ def parse_push_titles(raw: str) -> list[str]: if text.startswith("["): try: data: object = msgspec.json.decode(text.encode()) - except (msgspec.DecodeError, UnicodeEncodeError): + except msgspec.DecodeError, UnicodeEncodeError: data = None if isinstance(data, list): - out = [ - item.strip() - for item in cast("list[object]", data) - if isinstance(item, str) and item.strip() - ] + out = [item.strip() for item in cast("list[object]", data) if isinstance(item, str) and item.strip()] if out: return out parts: list[str] = [] diff --git a/src/plyngent/cli/slash.py b/src/plyngent/cli/slash.py index 147018e..b4aacea 100644 --- a/src/plyngent/cli/slash.py +++ b/src/plyngent/cli/slash.py @@ -62,11 +62,7 @@ class HistoryLimitType(click.ParamType): def shell_complete(self, ctx: click.Context, param: click.Parameter, incomplete: str) -> list[CompletionItem]: del ctx, param tokens = ("last", "1", "5", "10", "20") - return [ - CompletionItem(token) - for token in tokens - if incomplete == "" or token.startswith(incomplete.lower()) - ] + return [CompletionItem(token) for token in tokens if incomplete == "" or token.startswith(incomplete.lower())] HELP_FOOTER = ( diff --git a/src/plyngent/cli/state.py b/src/plyngent/cli/state.py index 43c4030..0f8ad23 100644 --- a/src/plyngent/cli/state.py +++ b/src/plyngent/cli/state.py @@ -124,9 +124,7 @@ class ReplState: loop = asyncio.get_running_loop() except RuntimeError: return - task = loop.create_task( - self.memory.update_session_todo_stack(self.session_id, self.todo_stack.to_raw()) - ) + task = loop.create_task(self.memory.update_session_todo_stack(self.session_id, self.todo_stack.to_raw())) # Keep a strong ref until done so the task is not GC'd mid-flight. self._todo_persist_tasks.add(task) task.add_done_callback(self._todo_persist_tasks.discard) diff --git a/tests/test_agent/test_todo_stack.py b/tests/test_agent/test_todo_stack.py index 7ca5adb..3404f47 100644 --- a/tests/test_agent/test_todo_stack.py +++ b/tests/test_agent/test_todo_stack.py @@ -191,12 +191,7 @@ async def test_loop_injects_todo_review_when_untouched() -> None: async for _event in agent.run("do stuff"): pass assert client.calls >= 2 - assert any( - isinstance(m, DeveloperChatMessage) and "Todo stack review" in m.content - for m in agent.messages - ) - assert not any( - isinstance(m, UserChatMessage) and "Todo stack review" in m.content for m in agent.messages - ) + assert any(isinstance(m, DeveloperChatMessage) and "Todo stack review" in m.content for m in agent.messages) + assert not any(isinstance(m, UserChatMessage) and "Todo stack review" in m.content for m in agent.messages) finally: set_todo_stack(None)