mirror of
https://github.com/NCBM/plyngent.git
synced 2026-07-23 05:55:16 +08:00
ci/lint: ruff format todo stack and related CLI/agent files
This commit is contained in:
@@ -371,11 +371,7 @@ async def run_chat_loop(
|
|||||||
assistant = _last_assistant(messages, pre_len)
|
assistant = _last_assistant(messages, pre_len)
|
||||||
tool_calls = assistant.tool_calls
|
tool_calls = assistant.tool_calls
|
||||||
if tool_calls is UNSET or not tool_calls or tools is None:
|
if tool_calls is UNSET or not tool_calls or tools is None:
|
||||||
if (
|
if todo_stack is not None and todo_stack.needs_review() and not todo_review_injected:
|
||||||
todo_stack is not None
|
|
||||||
and todo_stack.needs_review()
|
|
||||||
and not todo_review_injected
|
|
||||||
):
|
|
||||||
todo_review_injected = True
|
todo_review_injected = True
|
||||||
# Non-user control identity so retry/history don't treat this as human input.
|
# Non-user control identity so retry/history don't treat this as human input.
|
||||||
messages.append(DeveloperChatMessage(content=todo_stack.review_prompt()))
|
messages.append(DeveloperChatMessage(content=todo_stack.review_prompt()))
|
||||||
|
|||||||
@@ -98,11 +98,11 @@ class TodoStack:
|
|||||||
frame_items = msgspec.convert(frame.get("items"), type=list[TodoItem])
|
frame_items = msgspec.convert(frame.get("items"), type=list[TodoItem])
|
||||||
items.extend(frame_items)
|
items.extend(frame_items)
|
||||||
return cls(TodoStackData(items=items, next_id=next_id))
|
return cls(TodoStackData(items=items, next_id=next_id))
|
||||||
except (msgspec.ValidationError, TypeError, ValueError):
|
except msgspec.ValidationError, TypeError, ValueError:
|
||||||
return cls()
|
return cls()
|
||||||
try:
|
try:
|
||||||
data = msgspec.convert(raw, type=TodoStackData)
|
data = msgspec.convert(raw, type=TodoStackData)
|
||||||
except (msgspec.ValidationError, TypeError, ValueError):
|
except msgspec.ValidationError, TypeError, ValueError:
|
||||||
return cls()
|
return cls()
|
||||||
if data.next_id < 1:
|
if data.next_id < 1:
|
||||||
data = msgspec.structs.replace(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("["):
|
if text.startswith("["):
|
||||||
try:
|
try:
|
||||||
data: object = msgspec.json.decode(text.encode())
|
data: object = msgspec.json.decode(text.encode())
|
||||||
except (msgspec.DecodeError, UnicodeEncodeError):
|
except msgspec.DecodeError, UnicodeEncodeError:
|
||||||
data = None
|
data = None
|
||||||
if isinstance(data, list):
|
if isinstance(data, list):
|
||||||
out = [
|
out = [item.strip() for item in cast("list[object]", data) if isinstance(item, str) and item.strip()]
|
||||||
item.strip()
|
|
||||||
for item in cast("list[object]", data)
|
|
||||||
if isinstance(item, str) and item.strip()
|
|
||||||
]
|
|
||||||
if out:
|
if out:
|
||||||
return out
|
return out
|
||||||
parts: list[str] = []
|
parts: list[str] = []
|
||||||
|
|||||||
@@ -62,11 +62,7 @@ class HistoryLimitType(click.ParamType):
|
|||||||
def shell_complete(self, ctx: click.Context, param: click.Parameter, incomplete: str) -> list[CompletionItem]:
|
def shell_complete(self, ctx: click.Context, param: click.Parameter, incomplete: str) -> list[CompletionItem]:
|
||||||
del ctx, param
|
del ctx, param
|
||||||
tokens = ("last", "1", "5", "10", "20")
|
tokens = ("last", "1", "5", "10", "20")
|
||||||
return [
|
return [CompletionItem(token) for token in tokens if incomplete == "" or token.startswith(incomplete.lower())]
|
||||||
CompletionItem(token)
|
|
||||||
for token in tokens
|
|
||||||
if incomplete == "" or token.startswith(incomplete.lower())
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
HELP_FOOTER = (
|
HELP_FOOTER = (
|
||||||
|
|||||||
@@ -124,9 +124,7 @@ class ReplState:
|
|||||||
loop = asyncio.get_running_loop()
|
loop = asyncio.get_running_loop()
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
return
|
return
|
||||||
task = loop.create_task(
|
task = loop.create_task(self.memory.update_session_todo_stack(self.session_id, self.todo_stack.to_raw()))
|
||||||
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.
|
# Keep a strong ref until done so the task is not GC'd mid-flight.
|
||||||
self._todo_persist_tasks.add(task)
|
self._todo_persist_tasks.add(task)
|
||||||
task.add_done_callback(self._todo_persist_tasks.discard)
|
task.add_done_callback(self._todo_persist_tasks.discard)
|
||||||
|
|||||||
@@ -191,12 +191,7 @@ async def test_loop_injects_todo_review_when_untouched() -> None:
|
|||||||
async for _event in agent.run("do stuff"):
|
async for _event in agent.run("do stuff"):
|
||||||
pass
|
pass
|
||||||
assert client.calls >= 2
|
assert client.calls >= 2
|
||||||
assert any(
|
assert any(isinstance(m, DeveloperChatMessage) and "Todo stack review" in m.content for m in agent.messages)
|
||||||
isinstance(m, DeveloperChatMessage) and "Todo stack review" in m.content
|
assert not any(isinstance(m, UserChatMessage) and "Todo stack review" in m.content for m in agent.messages)
|
||||||
for m in agent.messages
|
|
||||||
)
|
|
||||||
assert not any(
|
|
||||||
isinstance(m, UserChatMessage) and "Todo stack review" in m.content for m in agent.messages
|
|
||||||
)
|
|
||||||
finally:
|
finally:
|
||||||
set_todo_stack(None)
|
set_todo_stack(None)
|
||||||
|
|||||||
Reference in New Issue
Block a user