Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(command): explain empty dream runs
chengyongrudcf76117ab39
diff --git a/nanobot/command/builtin.py b/nanobot/command/builtin.pyindex 6280e2dfe..d94fc4db9 100644--- a/nanobot/command/builtin.py+++ b/nanobot/command/builtin.py@@ -326,7 +326,8 @@ async def cmd_dream(ctx: CommandContext) -> OutboundMessage:if result is None:await loop.bus.publish_outbound(OutboundMessage(channel=msg.channel, chat_id=msg.chat_id,- content="Dream: nothing to process.",+ content=_format_dream_no_input_message(),+ metadata={"render_as": "text"},))returnprompt, last_cursor = result@@ -374,6 +375,23 @@ async def cmd_dream(ctx: CommandContext) -> OutboundMessage:)+def _format_dream_no_input_message() -> str:+ return "\n".join([+ "Dream has no conversation history to process yet.",+ "",+ "Dream reads new entries from `memory/history.jsonl` after the current Dream cursor.",+ (+ "Short chats only reach that file after token compaction or idle auto-compact, "+ "so a fresh or short WebUI chat may leave Dream with no input."+ ),+ "",+ "Next steps:",+ "- Enable `agents.defaults.idleCompactAfterMinutes` so completed chats become Dream input automatically.",+ "- Compact the current chat into memory once that manual action is available.",+ "- If you expected history to exist, check whether `memory/history.jsonl` has new entries after the Dream cursor.",+ ])++def _extract_changed_files(diff: str) -> list[str]:"""Extract changed file paths from a unified diff."""files: list[str] = []diff --git a/tests/command/test_builtin_dream.py b/tests/command/test_builtin_dream.pyindex 7b1835feb..1a15055d7 100644--- a/tests/command/test_builtin_dream.py+++ b/tests/command/test_builtin_dream.py@@ -1,23 +1,32 @@from __future__ import annotations+import asynciofrom types import SimpleNamespaceimport pytestfrom nanobot.bus.events import InboundMessage-from nanobot.command.builtin import cmd_dream_log, cmd_dream_restore+from nanobot.command.builtin import cmd_dream, cmd_dream_log, cmd_dream_restorefrom nanobot.command.router import CommandContextfrom nanobot.utils.gitstore import CommitInfoclass _FakeStore:- def __init__(self, git, last_dream_cursor: int = 1):+ def __init__(self, git, last_dream_cursor: int = 1, dream_prompt_result=None):self.git = gitself._last_dream_cursor = last_dream_cursor+ self._dream_prompt_result = dream_prompt_result+ self.compact_history_called = Falsedef get_last_dream_cursor(self) -> int:return self._last_dream_cursor+ def build_dream_prompt(self):+ return self._dream_prompt_result++ def compact_history(self) -> None:+ self.compact_history_called = True+class _FakeGit:def __init__(@@ -45,6 +54,17 @@ class _FakeGit:def revert(self, sha: str) -> str | None:return self._revert_result+ def auto_commit(self, message: str) -> str | None:+ return None+++class _FakeBus:+ def __init__(self):+ self.outbound = []++ async def publish_outbound(self, message):+ self.outbound.append(message)+def _make_ctx(raw: str, git: _FakeGit, *, args: str = "", last_dream_cursor: int = 1) -> CommandContext:msg = InboundMessage(channel="cli", sender_id="u1", chat_id="direct", content=raw)@@ -53,6 +73,38 @@ def _make_ctx(raw: str, git: _FakeGit, *, args: str = "", last_dream_cursor: intreturn CommandContext(msg=msg, session=None, key=msg.session_key, raw=raw, args=args, loop=loop)+def _make_dream_ctx(tmp_path) -> tuple[CommandContext, _FakeBus]:+ msg = InboundMessage(channel="cli", sender_id="u1", chat_id="direct", content="/dream")+ store = _FakeStore(_FakeGit(initialized=False), dream_prompt_result=None)+ bus = _FakeBus()+ sessions_dir = tmp_path / "sessions"+ sessions_dir.mkdir()+ loop = SimpleNamespace(+ bus=bus,+ context=SimpleNamespace(memory=store, timezone="UTC"),+ sessions=SimpleNamespace(sessions_dir=sessions_dir),+ )+ ctx = CommandContext(msg=msg, session=None, key=msg.session_key, raw="/dream", args="", loop=loop)+ return ctx, bus+++async def test_dream_no_history_explains_how_to_create_input(tmp_path) -> None:+ ctx, bus = _make_dream_ctx(tmp_path)++ immediate = await cmd_dream(ctx)+ await asyncio.sleep(0)++ assert immediate.content == "Dreaming..."+ assert len(bus.outbound) == 1+ content = bus.outbound[0].content+ assert "Dream has no conversation history to process yet." in content+ assert "`memory/history.jsonl`" in content+ assert "idle auto-compact" in content+ assert "Dream cursor" in content+ assert "agents.defaults.idleCompactAfterMinutes" in content++@pytest.mark.asyncioasync def test_dream_log_latest_is_more_user_friendly() -> None:commit = CommitInfo(sha="abcd1234", message="dream: 2026-04-04, 2 change(s)", timestamp="2026-04-04 12:00")