fix(tui): accept goal requests during active turns (#5981)

* fix(tui): accept goal requests during active turns

* fix(goal): reuse live input routing and remove busy guards

* test(goal): cover followup streams across iteration budgets

* refactor(goal): expand slash commands into hidden agent input

* fix(goal): keep generated input permission scoped to users

* refactor(agent): encapsulate goal input permission scope

* refactor(goal): preserve task text without prompt wrapper

* test(goal): consolidate coverage and exercise restart recovery

* test(goal): wait for recovery reply without task registry race
This commit is contained in:
chengyongru authored and GitHub committed 2026-09-30 13:08:13 +08:00
1 parent b46d4dfd7d
commit 99ba062a97
15 files changed
+613 -360

No files matched your search

+11 -5
View File
@@ -8,18 +8,22 @@ from dataclasses import dataclass, field
from difflib import get_close_matches
from typing import TYPE_CHECKING, Any, Awaitable, Callable
from nanobot.bus.events import OutboundMessage
from nanobot.bus.events import InboundMessage, OutboundMessage
if TYPE_CHECKING:
from nanobot.agent.loop import AgentLoop
from nanobot.bus.events import InboundMessage
from nanobot.session.manager import Session
from nanobot.utils.llm_runtime import LLMRuntime
Handler = Callable[["CommandContext"], Awaitable["OutboundMessage | None"]]
Handler = Callable[["CommandContext"], Awaitable["InboundMessage | OutboundMessage | None"]]
_BOT_SUFFIX_RE = re.compile(r"^[A-Za-z0-9_]+$")
def command_text(message: InboundMessage) -> str:
"""Return routable text; command-generated agent input must not be dispatched again."""
return "" if message.metadata.get("original_command") else message.content.strip()
def normalize_command_text(text: str) -> str:
"""Normalize slash-command transport variants before routing.
@@ -99,7 +103,7 @@ class CommandRouter:
return True
return cmd.startswith("/")
async def dispatch_priority(self, ctx: CommandContext) -> OutboundMessage | None:
async def dispatch_priority(self, ctx: CommandContext) -> InboundMessage | OutboundMessage | None:
"""Dispatch a priority command. Called from run() without the lock."""
ctx.raw = normalize_command_text(ctx.raw)
handler = self._priority.get(ctx.raw.lower())
@@ -107,8 +111,10 @@ class CommandRouter:
return await handler(ctx)
return None
async def dispatch(self, ctx: CommandContext) -> OutboundMessage | None:
async def dispatch(self, ctx: CommandContext) -> InboundMessage | OutboundMessage | None:
"""Try exact and prefix handlers, then reject invalid slash commands."""
if ctx.msg.metadata.get("original_command"):
return None
ctx.raw = normalize_command_text(ctx.raw)
cmd = ctx.raw.lower()