mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-28 06:51:16 +08:00
fix(tui): stabilize live todo panel count and anchor position
Two bugs surfaced together while the model fired the todo tool: 1. Count flickered (e.g. 3 → 1 → 3) because tool.start echoed args.todos as the live state. With merge=true (or any partial replacement) args.todos is just the items being updated, not the full list. Drop the early echo — tool.complete already carries the canonical full list from the tool result. 2. After turn end the panel jumped from under the user prompt to below thinking/tools because archiveDoneTodos() was pushed AFTER segments in finalMessages. Prepend the archive trail msg so it sits right after the user prompt — same visual slot the live panel occupied during streaming.
This commit is contained in:
@@ -1040,13 +1040,14 @@ def _on_tool_start(sid: str, tool_call_id: str, name: str, args: dict):
|
|||||||
pass
|
pass
|
||||||
session.setdefault("tool_started_at", {})[tool_call_id] = time.time()
|
session.setdefault("tool_started_at", {})[tool_call_id] = time.time()
|
||||||
if _tool_progress_enabled(sid):
|
if _tool_progress_enabled(sid):
|
||||||
payload = {"tool_id": tool_call_id, "name": name, "context": _tool_ctx(name, args)}
|
# Don't echo args.todos on tool.start — for merge=true (or partial
|
||||||
if name == "todo" and isinstance(args, dict) and isinstance(args.get("todos"), list):
|
# replacement) it's only the items being updated, not the full list,
|
||||||
payload["todos"] = args.get("todos")
|
# and would flicker the live count. tool.complete is the source of
|
||||||
|
# truth (always returns the full list from the tool result).
|
||||||
_emit(
|
_emit(
|
||||||
"tool.start",
|
"tool.start",
|
||||||
sid,
|
sid,
|
||||||
payload,
|
{"tool_id": tool_call_id, "name": name, "context": _tool_ctx(name, args)},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -537,10 +537,10 @@ export function createGatewayEventHandler(ctx: GatewayEventHandlerContext): (ev:
|
|||||||
const { finalMessages, finalText, wasInterrupted } = turnController.recordMessageComplete(ev.payload ?? {})
|
const { finalMessages, finalText, wasInterrupted } = turnController.recordMessageComplete(ev.payload ?? {})
|
||||||
|
|
||||||
if (!wasInterrupted) {
|
if (!wasInterrupted) {
|
||||||
// Archive the todo list FIRST so it sits above the final assistant
|
// Defensive: turnController.recordMessageComplete already prepends
|
||||||
// text in the transcript — same position it held during streaming.
|
// the archive at the head of finalMessages. This is a no-op in the
|
||||||
// Otherwise the panel would visibly jump from "above live answer" to
|
// normal path (state.todos is empty) but covers any edge where
|
||||||
// "below final answer" at message.complete.
|
// todos linger past the controller archive.
|
||||||
archiveTodosAtTurnEnd().forEach(appendMessage)
|
archiveTodosAtTurnEnd().forEach(appendMessage)
|
||||||
|
|
||||||
const msgs: Msg[] = finalMessages.length ? finalMessages : [{ role: 'assistant', text: finalText }]
|
const msgs: Msg[] = finalMessages.length ? finalMessages : [{ role: 'assistant', text: finalText }]
|
||||||
|
|||||||
@@ -469,9 +469,12 @@ class TurnController {
|
|||||||
...(tools.length && { tools })
|
...(tools.length && { tools })
|
||||||
}
|
}
|
||||||
|
|
||||||
const finalMessages = hasDetails(finalDetails) ? [...segments, finalDetails] : [...segments]
|
// Archive todos FIRST so the trail msg sits right after the user prompt,
|
||||||
|
// not between thinking/tools and the final assistant text. Keeps the
|
||||||
finalMessages.push(...archiveDoneTodos())
|
// panel visually anchored where it lived during streaming.
|
||||||
|
const archived = archiveDoneTodos()
|
||||||
|
const body = hasDetails(finalDetails) ? [...segments, finalDetails] : segments
|
||||||
|
const finalMessages: Msg[] = [...archived, ...body]
|
||||||
|
|
||||||
if (finalText) {
|
if (finalText) {
|
||||||
finalMessages.push({ role: 'assistant', text: finalText })
|
finalMessages.push({ role: 'assistant', text: finalText })
|
||||||
|
|||||||
Reference in New Issue
Block a user