refactor(command): remove history command
This commit is contained in:
1 parent
efec4a608d
commit
c927808aff
30 files changed
+58
-278
No files matched your search
@@ -198,7 +198,6 @@ if DISCORD_AVAILABLE:
|
||||
("stop", "Stop the current task", "/stop"),
|
||||
("restart", "Restart the bot", "/restart"),
|
||||
("status", "Show bot status", "/status"),
|
||||
("history", "Show recent conversation messages", "/history"),
|
||||
)
|
||||
|
||||
for name, description, command_text in commands:
|
||||
|
||||
@@ -1180,7 +1180,7 @@ async def test_slash_new_is_blocked_for_disallowed_user() -> None:
|
||||
assert handled == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize("slash_name", ["stop", "restart", "status", "history", "model"])
|
||||
@pytest.mark.parametrize("slash_name", ["stop", "restart", "status", "model"])
|
||||
@pytest.mark.asyncio
|
||||
async def test_slash_commands_forward_via_handle_message(slash_name: str) -> None:
|
||||
channel = DiscordChannel(DiscordConfig(enabled=True, allow_from=["*"]), MessageBus())
|
||||
|
||||
@@ -576,7 +576,6 @@ class TelegramChannel(BaseChannel):
|
||||
BotCommand("stop", "Stop the current task"),
|
||||
BotCommand("restart", "Restart the bot"),
|
||||
BotCommand("status", "Show bot status"),
|
||||
BotCommand("history", "Show recent conversation messages"),
|
||||
BotCommand("goal", "Start a sustained objective (long-running task)"),
|
||||
BotCommand("trigger", "Create a named local trigger"),
|
||||
BotCommand("pairing", "Manage DM pairing (approve/deny/list)"),
|
||||
@@ -594,7 +593,7 @@ class TelegramChannel(BaseChannel):
|
||||
# Telegram-safe aliases are normalized before reaching the core router.
|
||||
# Canonical hyphenated commands stay on a separate handler (below).
|
||||
TELEGRAM_BUS_SLASH_COMMAND_RE = re.compile(
|
||||
rf"^/(?:new|compact|stop|restart|status|dream|history|goal|trigger|pairing|model|skill"
|
||||
rf"^/(?:new|compact|stop|restart|status|dream|goal|trigger|pairing|model|skill"
|
||||
rf"|{_command_alternation(_TELEGRAM_COMMAND_ALIASES)}"
|
||||
rf"|{_command_alternation(_TELEGRAM_BUS_CANONICAL_COMMANDS)})(?:@\w+)?(?:\s+[\s\S]*)?$"
|
||||
)
|
||||
|
||||
@@ -374,7 +374,6 @@ async def test_start_creates_separate_pools_with_proxy(monkeypatch) -> None:
|
||||
assert builder.get_updates_request_value.inner is poll_req
|
||||
assert callable(app.updater.start_polling_kwargs["error_callback"])
|
||||
assert any(cmd.command == "status" for cmd in app.bot.commands)
|
||||
assert any(cmd.command == "history" for cmd in app.bot.commands)
|
||||
assert any(cmd.command == "skill" for cmd in app.bot.commands)
|
||||
assert any(cmd.command == "dream" for cmd in app.bot.commands)
|
||||
assert any(cmd.command == "dream_log" for cmd in app.bot.commands)
|
||||
@@ -2532,8 +2531,8 @@ async def test_forward_command_normalizes_telegram_safe_dream_aliases() -> None:
|
||||
|
||||
def test_telegram_bus_slash_command_regex_matches_agent_loop_commands() -> None:
|
||||
pat = TelegramChannel.TELEGRAM_BUS_SLASH_COMMAND_RE
|
||||
assert pat.fullmatch("/history")
|
||||
assert pat.fullmatch("/history 5")
|
||||
assert pat.fullmatch("/dream_log")
|
||||
assert pat.fullmatch("/dream_log abc123")
|
||||
assert pat.fullmatch("/goal ship the feature")
|
||||
assert pat.fullmatch("/trigger")
|
||||
assert pat.fullmatch("/trigger PR review")
|
||||
|
||||
@@ -5034,9 +5034,8 @@ async def test_commands_api_returns_slash_command_metadata(bus: MagicMock, start
|
||||
assert commands["/stop"]["title"] == "Stop current task"
|
||||
assert commands["/new"]["lifecycle"] == "finalize_active_turn"
|
||||
assert commands["/stop"]["lifecycle"] == "stop_active_turn"
|
||||
assert commands["/history"]["lifecycle"] == "side_channel"
|
||||
assert commands["/history"]["arg_hint"] == "[n]"
|
||||
assert commands["/history"]["accepts_args"] is True
|
||||
assert commands["/dream-log"]["lifecycle"] == "side_channel"
|
||||
assert commands["/dream-log"]["accepts_args"] is True
|
||||
assert commands["/goal"]["lifecycle"] == "agent_turn_with_args"
|
||||
assert commands["/goal"]["accepts_args"] is True
|
||||
assert all("description" in row for row in body["commands"])
|
||||
|
||||
@@ -6,7 +6,7 @@ import subprocess
|
||||
import sys
|
||||
from contextlib import suppress
|
||||
from dataclasses import replace
|
||||
from typing import TYPE_CHECKING, Any, cast
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from loguru import logger
|
||||
|
||||
@@ -71,14 +71,6 @@ CORE_COMMAND_SPECS: tuple[BuiltinCommandSpec, ...] = (
|
||||
"[preset]",
|
||||
accepts_args=True,
|
||||
),
|
||||
BuiltinCommandSpec(
|
||||
"/history",
|
||||
"Show conversation history",
|
||||
"Print the last N persisted conversation messages.",
|
||||
"history",
|
||||
"[n]",
|
||||
accepts_args=True,
|
||||
),
|
||||
BuiltinCommandSpec(
|
||||
"/trigger",
|
||||
"Create named local trigger",
|
||||
@@ -765,71 +757,6 @@ async def cmd_dream_restore(ctx: CommandContext) -> OutboundMessage:
|
||||
)
|
||||
|
||||
|
||||
_HISTORY_DEFAULT_COUNT = 10
|
||||
_HISTORY_MAX_COUNT = 50
|
||||
_HISTORY_MAX_CONTENT_CHARS = 200
|
||||
|
||||
|
||||
def _format_history_message(msg: dict[str, Any]) -> str | None:
|
||||
role = msg.get("role")
|
||||
if role not in ("user", "assistant"):
|
||||
return None
|
||||
content = msg.get("content") or ""
|
||||
if isinstance(content, list):
|
||||
parts = [
|
||||
text
|
||||
for block in cast(list[object], content)
|
||||
if (item := cast(dict[str, Any], block) if isinstance(block, dict) else None)
|
||||
and item.get("type") == "text"
|
||||
and isinstance(text := item.get("text"), str)
|
||||
]
|
||||
content = " ".join(parts)
|
||||
content = str(content).strip()
|
||||
if not content:
|
||||
return None
|
||||
if len(content) > _HISTORY_MAX_CONTENT_CHARS:
|
||||
content = content[:_HISTORY_MAX_CONTENT_CHARS] + "…"
|
||||
label = "👤 You" if role == "user" else "🤖 Bot"
|
||||
return f"{label}: {content}"
|
||||
|
||||
|
||||
async def cmd_history(ctx: CommandContext) -> OutboundMessage:
|
||||
"""Show the last N messages of the current session (default 10, max 50).
|
||||
|
||||
Usage: /history [count]
|
||||
"""
|
||||
count = _HISTORY_DEFAULT_COUNT
|
||||
if ctx.args.strip():
|
||||
try:
|
||||
count = max(1, min(int(ctx.args.strip()), _HISTORY_MAX_COUNT))
|
||||
except ValueError:
|
||||
return OutboundMessage(
|
||||
channel=ctx.msg.channel, chat_id=ctx.msg.chat_id,
|
||||
content="Usage: /history [count] — e.g. /history 5 (default: 10, max: 50)",
|
||||
metadata=dict(ctx.msg.metadata or {}),
|
||||
)
|
||||
|
||||
session = ctx.session or await ctx.loop.sessions.state.get(ctx.key)
|
||||
history = session.get_history(max_messages=0, include_runtime_context=False)
|
||||
visible = [_format_history_message(m) for m in history]
|
||||
visible = [m for m in visible if m is not None]
|
||||
recent = visible[-count:]
|
||||
|
||||
if not recent:
|
||||
return OutboundMessage(
|
||||
channel=ctx.msg.channel, chat_id=ctx.msg.chat_id,
|
||||
content="No conversation history yet.",
|
||||
metadata=dict(ctx.msg.metadata or {}),
|
||||
)
|
||||
|
||||
header = f"Last {len(recent)} message(s):\n"
|
||||
return OutboundMessage(
|
||||
channel=ctx.msg.channel, chat_id=ctx.msg.chat_id,
|
||||
content=header + "\n".join(recent),
|
||||
metadata={**dict(ctx.msg.metadata or {}), "render_as": "text"},
|
||||
)
|
||||
|
||||
|
||||
async def cmd_pairing(ctx: CommandContext) -> OutboundMessage:
|
||||
"""List, approve, deny or revoke pairing requests."""
|
||||
from nanobot.pairing import PAIRING_COMMAND_META_KEY, handle_pairing_command
|
||||
@@ -941,8 +868,6 @@ def register_core_commands(router: CommandRouter) -> None:
|
||||
router.exact("/status", cmd_status)
|
||||
router.exact("/model", cmd_model)
|
||||
router.prefix("/model ", cmd_model)
|
||||
router.exact("/history", cmd_history)
|
||||
router.prefix("/history ", cmd_history)
|
||||
router.exact("/trigger", cmd_trigger)
|
||||
router.prefix("/trigger ", cmd_trigger)
|
||||
router.exact("/dream", cmd_dream)
|
||||
|
||||
@@ -58,4 +58,4 @@ async def cmd_goal(ctx: CommandInput) -> CommandExpansion | OutboundMessage:
|
||||
def register_goal_command(router: CommandRouter) -> None:
|
||||
"""Register the exact usage and task-bearing forms of /goal."""
|
||||
router.input_command(GOAL_COMMAND, cmd_goal)
|
||||
router.add_spec(GOAL_COMMAND_SPEC, after="/history")
|
||||
router.add_spec(GOAL_COMMAND_SPEC, after="/model")
|
||||
Reference in new issue
Block a user