Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
fix(telegram): prompt timeouts announce their outcome; taps settle cards; cap status notices
Salman Qureshi33c72d3f6d6a
diff --git a/src/channels/telegram-prompts.test.ts b/src/channels/telegram-prompts.test.tsnew file mode 100644index 00000000..7f4df8f8--- /dev/null+++ b/src/channels/telegram-prompts.test.ts@@ -0,0 +1,247 @@+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import { TelegramChannel } from './telegram.js';++/**+ * Telegram inline-keyboard prompts (ROADMAP P0.8, #23).+ *+ * - A prompt nobody answers is decided FOR the user after 2 min; the card must+ * say so (outcome written back in place, keyboard removed, card kept).+ * - A tap on Allow / Deny / Continue / Stop / a choice must remove the keyboard+ * and append the chosen outcome — the same treatment as the choice path.+ * - The status card's notice list must not grow unbounded with heartbeats.+ */++const TARGET = 'telegram:4242';+const CHAT_ID = 4242;++type MockBot = {+ api: {+ sendMessage: ReturnType<typeof vi.fn>;+ editMessageText: ReturnType<typeof vi.fn>;+ deleteMessage: ReturnType<typeof vi.fn>;+ };+};++function makeChannel(): { channel: TelegramChannel; bot: MockBot } {+ const config = { channels: { telegram: { admins: [], members: [], pendingRequests: [] } } } as any;+ const channel = new TelegramChannel(config);+ let nextMessageId = 100;+ const bot: MockBot = {+ api: {+ sendMessage: vi.fn(async () => ({ message_id: nextMessageId++ })),+ editMessageText: vi.fn(async () => true),+ deleteMessage: vi.fn(async () => true),+ },+ };+ (channel as any).bot = bot;+ return { channel, bot };+}++function makeTapCtx(data: string) {+ return {+ callbackQuery: { data },+ answerCallbackQuery: vi.fn(async () => true),+ editMessageReplyMarkup: vi.fn(async () => true),+ };+}++/** The callback_data of the n-th button on the last sent keyboard. */+function sentButtonData(bot: MockBot, index: number): string {+ const call = bot.api.sendMessage.mock.calls.at(-1)!;+ const keyboard = call[2].reply_markup.inline_keyboard.flat();+ return keyboard[index].callback_data;+}++async function flush(): Promise<void> {+ // settlePromptCard runs fire-and-forget after resolve — let it finish.+ for (let i = 0; i < 5; i++) await Promise.resolve();+}++describe('Telegram prompt timeouts write the outcome back into the card', () => {+ beforeEach(() => vi.useFakeTimers());+ afterEach(() => vi.useRealTimers());++ it('askPermission: no answer in 2 min → "no", card says Deny, keyboard removed, card kept', async () => {+ const { channel, bot } = makeChannel();+ const pending = channel.askPermission('Run **rm -rf build**?', TARGET);+ await vi.advanceTimersByTimeAsync(0);+ expect(bot.api.sendMessage).toHaveBeenCalledTimes(1);++ await vi.advanceTimersByTimeAsync(120_000);+ expect(await pending).toBe('no');+ await flush();++ expect(bot.api.editMessageText).toHaveBeenCalledTimes(1);+ const [chatId, messageId, text, opts] = bot.api.editMessageText.mock.calls[0];+ expect(chatId).toBe(CHAT_ID);+ expect(messageId).toBe(100);+ expect(text).toContain('rm -rf build'); // original question preserved+ expect(text).toContain('⏱ No answer in 2 min — treated as <b>Deny</b>');+ expect(opts.reply_markup).toBeUndefined(); // keyboard gone+ expect(bot.api.deleteMessage).not.toHaveBeenCalled(); // card kept+ });++ it('presentChoicePrompt: no answer → first option, card names the recommended option', async () => {+ const { channel, bot } = makeChannel();+ const pending = channel.presentChoicePrompt('Which?', [+ { value: 'quick', label: 'Quick answer' },+ { value: 'deep', label: 'Deep research' },+ ], TARGET);+ await vi.advanceTimersByTimeAsync(120_000);+ expect(await pending).toBe('quick');+ await flush();++ const text = bot.api.editMessageText.mock.calls[0][2];+ expect(text).toContain('Which?');+ expect(text).toContain('continued with the recommended option: <b>Quick answer</b>');+ expect(bot.api.deleteMessage).not.toHaveBeenCalled();+ });++ it('askToContinue: no answer → false, card says stopped', async () => {+ const { channel, bot } = makeChannel();+ const pending = channel.askToContinue('Keep going?', TARGET);+ await vi.advanceTimersByTimeAsync(120_000);+ expect(await pending).toBe(false);+ await flush();++ const text = bot.api.editMessageText.mock.calls[0][2];+ expect(text).toContain('⏱ No answer in 2 min — <b>stopped</b>');+ expect(bot.api.deleteMessage).not.toHaveBeenCalled();+ });++ it('askPermissionMode: no answer → ask-me, card says so', async () => {+ const { channel, bot } = makeChannel();+ const pending = channel.askPermissionMode(TARGET);+ await vi.advanceTimersByTimeAsync(120_000);+ expect(await pending).toBe('ask-me');+ await flush();+ expect(bot.api.editMessageText.mock.calls[0][2]).toContain('defaulting to <b>Ask Me</b>');+ });++ it('falls back to plain text when the HTML edit is rejected', async () => {+ const { channel, bot } = makeChannel();+ bot.api.editMessageText.mockRejectedValueOnce(new Error("can't parse entities"));+ const pending = channel.askToContinue('Keep going?', TARGET);+ await vi.advanceTimersByTimeAsync(120_000);+ await pending;+ await flush();++ expect(bot.api.editMessageText).toHaveBeenCalledTimes(2);+ const [, , plain, opts] = bot.api.editMessageText.mock.calls[1];+ expect(plain).toContain('⏱ No answer in 2 min — stopped');+ expect(plain).not.toContain('<b>');+ expect(opts).toBeUndefined();+ });+});++describe('Telegram inline-keyboard taps settle the card (#23)', () => {+ beforeEach(() => vi.useFakeTimers());+ afterEach(() => vi.useRealTimers());++ it('Always tap → "always", keyboard removed and outcome appended; timeout no longer fires', async () => {+ const { channel, bot } = makeChannel();+ const pending = channel.askPermission('Run build?', TARGET);+ await vi.advanceTimersByTimeAsync(0);++ const ctx = makeTapCtx(sentButtonData(bot, 1)); // Allow, Always, Deny+ expect(ctx.callbackQuery.data).toMatch(/:always$/);+ await (channel as any).handleCallbackQuery(ctx);+ expect(await pending).toBe('always');+ await flush();++ expect(ctx.answerCallbackQuery).toHaveBeenCalledWith({ text: 'Approved' });+ expect(bot.api.editMessageText).toHaveBeenCalledTimes(1);+ const [, , text, opts] = bot.api.editMessageText.mock.calls[0];+ expect(text).toContain('Run build?');+ expect(text).toContain('✅ <b>Always allowed</b>');+ expect(opts.reply_markup).toBeUndefined();+ expect(bot.api.deleteMessage).not.toHaveBeenCalled();++ // The 2-minute timer was cleared — no second edit, no "no answer" text.+ await vi.advanceTimersByTimeAsync(120_000);+ await flush();+ expect(bot.api.editMessageText).toHaveBeenCalledTimes(1);+ });++ it('Deny tap → "no", card says Denied', async () => {+ const { channel, bot } = makeChannel();+ const pending = channel.askPermission('Run build?', TARGET);+ await vi.advanceTimersByTimeAsync(0);++ const ctx = makeTapCtx(sentButtonData(bot, 2));+ await (channel as any).handleCallbackQuery(ctx);+ expect(await pending).toBe('no');+ await flush();++ expect(ctx.answerCallbackQuery).toHaveBeenCalledWith({ text: 'Denied' });+ expect(bot.api.editMessageText.mock.calls[0][2]).toContain('🚫 <b>Denied</b>');+ });++ it('Continue / Stop taps settle the continue card', async () => {+ const { channel, bot } = makeChannel();+ const pending = channel.askToContinue('Keep going?', TARGET);+ await vi.advanceTimersByTimeAsync(0);++ await (channel as any).handleCallbackQuery(makeTapCtx(sentButtonData(bot, 0)));+ expect(await pending).toBe(true);+ await flush();+ expect(bot.api.editMessageText.mock.calls[0][2]).toContain('▶️ <b>Continuing</b>');+ expect(bot.api.editMessageText.mock.calls[0][3].reply_markup).toBeUndefined();+ });++ it('choice tap → value, card says which option was selected', async () => {+ const { channel, bot } = makeChannel();+ const pending = channel.presentChoicePrompt('Which?', [+ { value: 'quick', label: 'Quick answer' },+ { value: 'deep', label: 'Deep research' },+ ], TARGET);+ await vi.advanceTimersByTimeAsync(0);++ const ctx = makeTapCtx(sentButtonData(bot, 1));+ await (channel as any).handleCallbackQuery(ctx);+ expect(await pending).toBe('deep');+ await flush();++ expect(ctx.answerCallbackQuery).toHaveBeenCalledWith({ text: 'Selected' });+ const [, , text, opts] = bot.api.editMessageText.mock.calls[0];+ expect(text).toContain('✅ Selected: <b>Deep research</b>');+ expect(opts.reply_markup).toBeUndefined();++ // Timeout must not override the tap.+ await vi.advanceTimersByTimeAsync(120_000);+ await flush();+ expect(bot.api.editMessageText).toHaveBeenCalledTimes(1);+ });++ it('a second tap on a settled card answers "Expired" and edits nothing', async () => {+ const { channel, bot } = makeChannel();+ const pending = channel.askPermission('Run build?', TARGET);+ await vi.advanceTimersByTimeAsync(0);+ const data = sentButtonData(bot, 0);++ await (channel as any).handleCallbackQuery(makeTapCtx(data));+ expect(await pending).toBe('yes');+ await flush();++ const again = makeTapCtx(data);+ await (channel as any).handleCallbackQuery(again);+ expect(again.answerCallbackQuery).toHaveBeenCalledWith({ text: 'Expired' });+ expect(bot.api.editMessageText).toHaveBeenCalledTimes(1);+ });+});++describe('Telegram status card notices are capped', () => {+ it('keeps only the last 8 stored notice lines after a refresh', async () => {+ const { channel } = makeChannel();+ const key = TARGET;+ const notices = Array.from({ length: 30 }, (_, i) => `☿ heartbeat ${i}`);+ (channel as any).statusNotices.set(key, notices);++ await (channel as any).refreshStatusCard(key);++ const stored: string[] = (channel as any).statusNotices.get(key);+ expect(stored).toHaveLength(8);+ expect(stored[0]).toBe('☿ heartbeat 22');+ expect(stored.at(-1)).toBe('☿ heartbeat 29');+ });+});diff --git a/src/channels/telegram.ts b/src/channels/telegram.tsindex c4a5dcb4..545d3845 100644--- a/src/channels/telegram.ts+++ b/src/channels/telegram.ts@@ -66,6 +66,12 @@ export class TelegramChannel extends BaseChannel {private statusNotices = new Map<string, string[]>();/** Maximum number of notice lines to show in the status card */private static readonly MAX_STATUS_NOTICES = 3;+ /** Maximum number of notice lines retained per task (heartbeats arrive every 20-60s) */+ private static readonly MAX_STORED_STATUS_NOTICES = 8;+ /** How long an inline-keyboard prompt waits before answering for the user */+ private static readonly PROMPT_TIMEOUT_MS = 120_000;+ /** Sent prompt cards (permission / choice / continue), keyed by prompt id, so the outcome can be written back in place */+ private promptCards = new Map<string, { chatId: number; messageId: number; html: string }>();constructor(private config: MercuryConfig) {super();@@ -235,44 +241,7 @@ export class TelegramChannel extends BaseChannel {this.emit(msg);});- bot.on('callback_query:data', async (ctx) => {- const data = ctx.callbackQuery.data;- if (data.startsWith(`${ACCESS_ACTION_PREFIX}:`)) {- await this.handleAccessCallback(ctx, data);- return;- }-- if (data.startsWith(`${MEMORY_ACTION_PREFIX}:`)) {- await this.handleMemoryCallback(ctx, data);- return;- }-- if (data.startsWith('choice:')) {- const [, id, value] = data.split(':');- const resolver = id ? this.pendingChoices.get(id) : undefined;- if (!resolver) {- await ctx.answerCallbackQuery({ text: 'Expired' });- return;- }-- this.pendingChoices.delete(id);- resolver(value ?? '');- await ctx.answerCallbackQuery({ text: 'Selected' });- await ctx.editMessageReplyMarkup({ reply_markup: undefined }).catch((e: any) => logger.debug({ e }, 'telegram editMessageReplyMarkup failed'));- return;- }-- const resolver = this.pendingApprovals.get(data);- if (!resolver) {- await ctx.answerCallbackQuery({ text: 'Expired' });- return;- }-- this.pendingApprovals.delete(data);- resolver();- const action = data.split(':')[1];- await ctx.answerCallbackQuery({ text: action === 'no' ? 'Denied' : 'Approved' });- });+ bot.on('callback_query:data', (ctx) => this.handleCallbackQuery(ctx));bot.catch((err) => {logger.error({ err: err.message }, 'Telegram bot error');@@ -635,6 +604,95 @@ export class TelegramChannel extends BaseChannel {}}+ /** Inline-keyboard taps (approvals, choices, access/memory admin actions). */+ private async handleCallbackQuery(ctx: any): Promise<void> {+ const data: string = ctx.callbackQuery.data;+ if (data.startsWith(`${ACCESS_ACTION_PREFIX}:`)) {+ await this.handleAccessCallback(ctx, data);+ return;+ }++ if (data.startsWith(`${MEMORY_ACTION_PREFIX}:`)) {+ await this.handleMemoryCallback(ctx, data);+ return;+ }++ if (data.startsWith('choice:')) {+ const [, id, value] = data.split(':');+ const resolver = id ? this.pendingChoices.get(id) : undefined;+ if (!resolver) {+ await ctx.answerCallbackQuery({ text: 'Expired' });+ return;+ }++ this.pendingChoices.delete(id);+ // The resolver settles the card: outcome appended, keyboard removed.+ resolver(value ?? '');+ await ctx.answerCallbackQuery({ text: 'Selected' });+ return;+ }++ const resolver = this.pendingApprovals.get(data);+ if (!resolver) {+ await ctx.answerCallbackQuery({ text: 'Expired' });+ return;+ }++ this.pendingApprovals.delete(data);+ // The resolver settles the card: outcome appended, keyboard removed (#23).+ resolver();+ const action = data.slice(data.lastIndexOf(':') + 1);+ await ctx.answerCallbackQuery({ text: action === 'no' ? 'Denied' : 'Approved' });+ }++ /**+ * Send a prompt card with an inline keyboard. Returns the message id (or+ * undefined when sending failed) and remembers the card so the outcome can be+ * written back into it later.+ */+ private async sendPromptCard(id: string, chatId: number, targetId: string | undefined, html: string, keyboard: InlineKeyboard): Promise<number | undefined> {+ if (!this.bot) return undefined;+ let sentMsgId: number | undefined;+ try {+ const msg = await this.bot.api.sendMessage(chatId, html, { parse_mode: 'HTML', reply_markup: keyboard });+ sentMsgId = msg.message_id;+ } catch {+ const msg = await this.bot.api.sendMessage(chatId, this.stripHtml(html), { reply_markup: keyboard });+ sentMsgId = msg.message_id;+ }+ if (sentMsgId) {+ this.trackEphemeral(targetId, sentMsgId);+ this.promptCards.set(id, { chatId, messageId: sentMsgId, html });+ }+ return sentMsgId;+ }++ /**+ * Write the outcome of a prompt into its card: the inline keyboard is removed+ * and `outcomeHtml` is appended below the original question. The card stays+ * in the chat (it is still ephemeral — cleaned up when the task completes) so+ * the user can see what was decided, including decisions made FOR them on+ * timeout.+ */+ private async settlePromptCard(id: string, outcomeHtml: string): Promise<void> {+ const card = this.promptCards.get(id);+ this.promptCards.delete(id);+ if (!card || !this.bot) return;+ const html = `${card.html}\n\n${outcomeHtml}`;+ try {+ await this.bot.api.editMessageText(card.chatId, card.messageId, html, { parse_mode: 'HTML' });+ } catch (err: any) {+ const description = String(err?.description || err?.message || '');+ if (description.includes('message is not modified')) return;+ await this.bot.api.editMessageText(card.chatId, card.messageId, this.stripHtml(html))+ .catch((e: any) => logger.debug({ e }, 'telegram settlePromptCard failed'));+ }+ }++ private static timeoutOutcome(decision: string): string {+ return `⏱ No answer in 2 min — ${decision}`;+ }+async askPermission(prompt: string, targetId?: string): Promise<string> {const chatIds = this.resolveTargetChatIds(targetId);const chatId = chatIds[0];@@ -646,44 +704,29 @@ export class TelegramChannel extends BaseChannel {.text('Always', `${id}:always`).text('Deny', `${id}:no`);- const html = mdToTelegram(prompt);- let sentMsgId: number | undefined;+ await this.sendPromptCard(id, chatId, targetId, mdToTelegram(prompt), keyboard);- try {- const msg = await this.bot.api.sendMessage(chatId, html, {- parse_mode: 'HTML',- reply_markup: keyboard,- });- sentMsgId = msg.message_id;- } catch {- const msg = await this.bot.api.sendMessage(chatId, this.stripHtml(html), {- reply_markup: keyboard,- });- sentMsgId = msg.message_id;- }-- if (sentMsgId) this.trackEphemeral(targetId, sentMsgId);+ const outcomes: Record<string, string> = {+ yes: '✅ <b>Allowed</b>',+ always: '✅ <b>Always allowed</b>',+ no: '🚫 <b>Denied</b>',+ };return new Promise((resolve) => {- const cleanup = (result: string) => {- this.pendingApprovals.delete(`${id}:yes`);- this.pendingApprovals.delete(`${id}:always`);- this.pendingApprovals.delete(`${id}:no`);- // Delete the permission card immediately- if (sentMsgId) this.deleteEphemeralMessage(targetId, sentMsgId);+ const actions = Object.keys(outcomes);+ const settle = (result: string, outcomeHtml: string) => {+ clearTimeout(timer);+ for (const action of actions) this.pendingApprovals.delete(`${id}:${action}`);+ void this.settlePromptCard(id, outcomeHtml);resolve(result);};- this.pendingApprovals.set(`${id}:yes`, () => cleanup('yes'));- this.pendingApprovals.set(`${id}:always`, () => cleanup('always'));- this.pendingApprovals.set(`${id}:no`, () => cleanup('no'));-- setTimeout(() => {- this.pendingApprovals.delete(`${id}:yes`);- this.pendingApprovals.delete(`${id}:always`);- this.pendingApprovals.delete(`${id}:no`);- if (sentMsgId) this.deleteEphemeralMessage(targetId, sentMsgId);- resolve('no');- }, 120_000);+ for (const action of actions) {+ this.pendingApprovals.set(`${id}:${action}`, () => settle(action, outcomes[action]));+ }+ const timer = setTimeout(+ () => settle('no', TelegramChannel.timeoutOutcome('treated as <b>Deny</b>')),+ TelegramChannel.PROMPT_TIMEOUT_MS,+ );});}@@ -702,22 +745,23 @@ export class TelegramChannel extends BaseChannel {}}- const html = mdToTelegram(question);- try {- const msg = await this.bot.api.sendMessage(chatId, html, { parse_mode: 'HTML', reply_markup: keyboard });- this.trackEphemeral(targetId, msg.message_id);- } catch {- const msg = await this.bot.api.sendMessage(chatId, this.stripHtml(html), { reply_markup: keyboard });- this.trackEphemeral(targetId, msg.message_id);- }+ await this.sendPromptCard(id, chatId, targetId, mdToTelegram(question), keyboard);++ const labelFor = (value: string) => this.escapeHtml(options.find(o => o.value === value)?.label || value);return new Promise((resolve) => {- this.pendingChoices.set(id, resolve);- setTimeout(() => {- if (!this.pendingChoices.has(id)) return;+ const settle = (value: string, outcomeHtml: string) => {+ clearTimeout(timer);this.pendingChoices.delete(id);- resolve(options[0]?.value || '');- }, 120_000);+ void this.settlePromptCard(id, outcomeHtml);+ resolve(value);+ };+ this.pendingChoices.set(id, (value) => settle(value, `✅ Selected: <b>${labelFor(value)}</b>`));+ const timer = setTimeout(() => {+ if (!this.pendingChoices.has(id)) return;+ const fallback = options[0]?.value || '';+ settle(fallback, TelegramChannel.timeoutOutcome(`continued with the recommended option: <b>${labelFor(fallback)}</b>`));+ }, TelegramChannel.PROMPT_TIMEOUT_MS);});}@@ -731,38 +775,22 @@ export class TelegramChannel extends BaseChannel {.text('Continue', `${id}:yes`).text('Stop', `${id}:no`);- let sentMsgId: number | undefined;- try {- const msg = await this.bot.api.sendMessage(chatId, mdToTelegram(question), {- parse_mode: 'HTML',- reply_markup: keyboard,- });- sentMsgId = msg.message_id;- } catch {- const msg = await this.bot.api.sendMessage(chatId, question, {- reply_markup: keyboard,- });- sentMsgId = msg.message_id;- }-- if (sentMsgId) this.trackEphemeral(targetId, sentMsgId);+ await this.sendPromptCard(id, chatId, targetId, mdToTelegram(question), keyboard);return new Promise((resolve) => {- const cleanup = (result: boolean) => {+ const settle = (result: boolean, outcomeHtml: string) => {+ clearTimeout(timer);this.pendingApprovals.delete(`${id}:yes`);this.pendingApprovals.delete(`${id}:no`);- if (sentMsgId) this.deleteEphemeralMessage(targetId, sentMsgId);+ void this.settlePromptCard(id, outcomeHtml);resolve(result);};- this.pendingApprovals.set(`${id}:yes`, () => cleanup(true));- this.pendingApprovals.set(`${id}:no`, () => cleanup(false));-- setTimeout(() => {- this.pendingApprovals.delete(`${id}:yes`);- this.pendingApprovals.delete(`${id}:no`);- if (sentMsgId) this.deleteEphemeralMessage(targetId, sentMsgId);- resolve(false);- }, 120_000);+ this.pendingApprovals.set(`${id}:yes`, () => settle(true, '▶️ <b>Continuing</b>'));+ this.pendingApprovals.set(`${id}:no`, () => settle(false, '⏹ <b>Stopped</b>'));+ const timer = setTimeout(+ () => settle(false, TelegramChannel.timeoutOutcome('<b>stopped</b>')),+ TelegramChannel.PROMPT_TIMEOUT_MS,+ );});}@@ -778,38 +806,22 @@ export class TelegramChannel extends BaseChannel {const html = `<b>Permission Mode</b>\nHow should Mercury handle risky actions this session?\n\n🔒 <b>Ask Me</b> — confirm before file writes, commands, and scope changes\n✅ <b>Allow All</b> — auto-approve everything (scopes, commands, loops)`;- let sentMsgId: number | undefined;- try {- const msg = await this.bot.api.sendMessage(chatId, html, {- parse_mode: 'HTML',- reply_markup: keyboard,- });- sentMsgId = msg.message_id;- } catch {- const msg = await this.bot.api.sendMessage(chatId, this.stripHtml(html), {- reply_markup: keyboard,- });- sentMsgId = msg.message_id;- }-- if (sentMsgId) this.trackEphemeral(targetId, sentMsgId);+ await this.sendPromptCard(id, chatId, targetId, html, keyboard);return new Promise((resolve) => {- const cleanup = (result: PermissionMode) => {+ const settle = (result: PermissionMode, outcomeHtml: string) => {+ clearTimeout(timer);this.pendingApprovals.delete(`${id}:ask-me`);this.pendingApprovals.delete(`${id}:allow-all`);- if (sentMsgId) this.deleteEphemeralMessage(targetId, sentMsgId);+ void this.settlePromptCard(id, outcomeHtml);resolve(result);};- this.pendingApprovals.set(`${id}:ask-me`, () => cleanup('ask-me'));- this.pendingApprovals.set(`${id}:allow-all`, () => cleanup('allow-all'));-- setTimeout(() => {- this.pendingApprovals.delete(`${id}:ask-me`);- this.pendingApprovals.delete(`${id}:allow-all`);- if (sentMsgId) this.deleteEphemeralMessage(targetId, sentMsgId);- resolve('ask-me');- }, 120_000);+ this.pendingApprovals.set(`${id}:ask-me`, () => settle('ask-me', '🔒 <b>Ask Me</b> selected'));+ this.pendingApprovals.set(`${id}:allow-all`, () => settle('allow-all', '✅ <b>Allow All</b> selected'));+ const timer = setTimeout(+ () => settle('ask-me', TelegramChannel.timeoutOutcome('defaulting to <b>Ask Me</b>')),+ TelegramChannel.PROMPT_TIMEOUT_MS,+ );});}@@ -1428,6 +1440,11 @@ export class TelegramChannel extends BaseChannel {const step = this.stepCounters.get(key) || 0;const history = this.stepHistory.get(key) || [];const notices = this.statusNotices.get(key) || [];+ // Heartbeat lines arrive every 20-60s for the whole task — keep only the tail+ // so the stored list (and the card) stays short.+ if (notices.length > TelegramChannel.MAX_STORED_STATUS_NOTICES) {+ notices.splice(0, notices.length - TelegramChannel.MAX_STORED_STATUS_NOTICES);+ }const recentHistory = history.slice(-5);const recentNotices = notices.slice(-TelegramChannel.MAX_STATUS_NOTICES);