Skip to content

Your lightweight open-source personal agent.

feat(dream): non-blocking /dream with progress feedback

Xubin Renacf652358ca4
diff --git a/nanobot/command/builtin.py b/nanobot/command/builtin.py
index a5629f66e..514ac1438 100644
--- a/nanobot/command/builtin.py
+++ b/nanobot/command/builtin.py
@@ -93,14 +93,30 @@ async def cmd_new(ctx: CommandContext) -> OutboundMessage:
async def cmd_dream(ctx: CommandContext) -> OutboundMessage:
"""Manually trigger a Dream consolidation run."""
+ import time
+
loop = ctx.loop
- try:
- did_work = await loop.dream.run()
- content = "Dream completed." if did_work else "Dream: nothing to process."
- except Exception as e:
- content = f"Dream failed: {e}"
+ msg = ctx.msg
+
+ async def _run_dream():
+ t0 = time.monotonic()
+ try:
+ did_work = await loop.dream.run()
+ elapsed = time.monotonic() - t0
+ if did_work:
+ content = f"Dream completed in {elapsed:.1f}s."
+ else:
+ content = "Dream: nothing to process."
+ except Exception as e:
+ elapsed = time.monotonic() - t0
+ content = f"Dream failed after {elapsed:.1f}s: {e}"
+ await loop.bus.publish_outbound(OutboundMessage(
+ channel=msg.channel, chat_id=msg.chat_id, content=content,
+ ))
+
+ asyncio.create_task(_run_dream())
return OutboundMessage(
- channel=ctx.msg.channel, chat_id=ctx.msg.chat_id, content=content,
+ channel=msg.channel, chat_id=msg.chat_id, content="Dreaming...",
)