Skip to content

Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.

fix(bots): results live in the bot's own thread — never dumped into the asking session

Salman Qureshi3b59c5e4fbfa
diff --git a/src/bots/bot-manager.test.ts b/src/bots/bot-manager.test.ts
index 6ed900fc..b2dccd38 100644
--- a/src/bots/bot-manager.test.ts
+++ b/src/bots/bot-manager.test.ts
@@ -91,10 +91,10 @@ describe('BotManager queue + turn lifecycle', () => {
it('runs a chat turn to completion, journals it, and notifies', async () => {
mockedGenerateText.mockResolvedValue({ text: 'done', finishReason: 'stop', usage: { inputTokens: 10, outputTokens: 5 } } as any);
seedBot(store, 'researcher');
- const notifications: string[] = [];
- manager['notify'] = async (_t, _c, message) => { notifications.push(message); };
+ const delivered: Array<{ target: string; message: string }> = [];
+ manager['notify'] = async (_t, target, message) => { delivered.push({ target, message }); };
- const result = manager.enqueue('researcher', { trigger: 'chat', prompt: 'Summarize the market' });
+ const result = manager.enqueue('researcher', { trigger: 'chat', prompt: 'Summarize the market', source: { channelType: 'cli', channelId: 'current' } });
expect(result.accepted).toBe(true);
// pump is synchronous-ish; the turn runs as a detached promise — wait for it
await vi.waitFor(() => {
@@ -102,7 +102,12 @@ describe('BotManager queue + turn lifecycle', () => {
expect(records.length).toBe(1);
expect(records[0].state).toBe('completed');
});
- expect(notifications.some(n => n.includes('researcher'.toUpperCase()) || n.includes('RESEARCHER'))).toBe(true);
+ // Hermes/OpenClaw contract: the full result lands in the bot's OWN thread;
+ // the requesting session gets at most a one-line pointer.
+ await vi.waitFor(() => {
+ expect(delivered.some(d => d.target === 'bot:researcher' && d.message.includes('done'))).toBe(true);
+ expect(delivered.some(d => d.message.includes('finished its task') && d.message.includes('/bots open researcher'))).toBe(true);
+ });
const summary = manager.getStatusSummaries().find(s => s.id === 'researcher');
expect(summary?.state).toBe('idle');
expect(summary?.lastRunState).toBe('completed');
diff --git a/src/bots/bot-manager.ts b/src/bots/bot-manager.ts
index 3ecdcaa6..badf2618 100644
--- a/src/bots/bot-manager.ts
+++ b/src/bots/bot-manager.ts
@@ -422,18 +422,37 @@ export class BotManager {
this.queue.settle(job.id, 'done');
}
- // Deliver the outcome — including halts (a stopped run must report
- // that it stopped, never vanish silently, §2.6). Jobs without a source
- // (cron/API) deliver to the bot's own thread via the `bot:<id>` targetId.
+ // Deliver the outcome — Hermes/OpenClaw model (BOTS-ARCHITECTURE §3.1):
+ // the FULL result always lands in the BOT'S OWN thread; the session
+ // that asked for it gets only a one-line pointer. Remote channels
+ // (Telegram/web) are the exception — the user cannot open bot threads
+ // from there, so the full result is delivered in that chat. Halts
+ // report too (a stopped run must announce it stopped, §2.6).
if (this.notify && job.trigger !== 'mailbox') {
- const channelType = job.source?.channelType ?? 'cli';
- const channelId = job.source?.channelId ?? `bot:${botId}`;
+ const botThread = `bot:${botId}`;
const icon = output.status === 'completed' ? '🤖' : output.status === 'failed' ? '❌' : output.status === 'halted' ? '⏹' : '⏸';
- const text = output.status === 'halted'
- ? `⏹ **${manifest.name}** run ${job.id} was stopped by you — no further output. It is recorded in \`/bots journal ${botId}\`.`
- : `${icon} **${manifest.name}** (${job.trigger}): ${output.output.slice(0, 800)}`;
- await this.notify(channelType, channelId, text).catch((e) =>
- logger.warn({ e, botId }, 'Bot completion notify failed'));
+ const fullText = output.status === 'halted'
+ ? `⏹ Run ${job.id} was stopped by you — no further output. It is recorded in \`/bots journal ${botId}\`.`
+ : `${icon} (${job.trigger}): ${output.output.slice(0, 800)}`;
+ // 1. Full result → the bot's own thread, always.
+ await this.notify('cli', botThread, fullText).catch((e) =>
+ logger.warn({ e, botId }, 'Bot result deliver to bot thread failed'));
+ // 2. Requesting surface: pointer line for TUI sessions; full result
+ // for remote channels (their user can't open bot threads).
+ const sourceChannelType = job.source?.channelType ?? 'cli';
+ const sourceChannelId = job.source?.channelId;
+ if (sourceChannelId && sourceChannelId !== botThread) {
+ if (sourceChannelType === 'cli') {
+ const pointer = output.status === 'completed'
+ ? `🤖 **${manifest.name}** finished its task — full result in its chat (\`/bots open ${botId}\`).`
+ : `🤖 **${manifest.name}** run ended (${output.status}) — details in \`/bots open ${botId}\`.`;
+ await this.notify('cli', sourceChannelId, pointer).catch((e) =>
+ logger.warn({ e, botId }, 'Bot pointer notify failed'));
+ } else {
+ await this.notify(sourceChannelType, sourceChannelId, fullText).catch((e) =>
+ logger.warn({ e, botId }, 'Bot remote-channel result notify failed'));
+ }
+ }
}
} catch (err: any) {
logger.error({ botId, jobId: job.id, err: err?.message }, 'Bot turn crashed');