morpheus-cli 0.4.8 → 0.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -356,9 +356,18 @@ export class TelegramAdapter {
356
356
  await fs.writeFile(filePath, buffer);
357
357
  return filePath;
358
358
  }
359
+ /**
360
+ * Escapes a string for Telegram MarkdownV2 format.
361
+ * All special characters outside code spans must be escaped with a backslash.
362
+ */
363
+ escapeMarkdownV2(text) {
364
+ // Characters that must be escaped in MarkdownV2 outside of code/pre blocks
365
+ return text.replace(/([_*[\]()~`>#+\-=|{}.!\\])/g, '\\$1');
366
+ }
359
367
  /**
360
368
  * Sends a proactive message to all allowed Telegram users.
361
369
  * Used by the webhook notification system to push results.
370
+ * Tries plain text first to avoid Markdown parse errors from LLM output.
362
371
  */
363
372
  async sendMessage(text) {
364
373
  if (!this.isConnected || !this.bot) {
@@ -370,9 +379,14 @@ export class TelegramAdapter {
370
379
  this.display.log('No allowed Telegram users configured — skipping notification.', { source: 'Telegram', level: 'warning' });
371
380
  return;
372
381
  }
382
+ // Truncate to Telegram's 4096 char limit
383
+ const MAX_LEN = 4096;
384
+ const safeText = text.length > MAX_LEN ? text.slice(0, MAX_LEN - 3) + '...' : text;
373
385
  for (const userId of allowedUsers) {
374
386
  try {
375
- await this.bot.telegram.sendMessage(userId, text, { parse_mode: 'Markdown' });
387
+ // Send as plain text LLM output often has unbalanced markdown that
388
+ // causes "Can't find end of entity" errors with parse_mode: 'Markdown'.
389
+ await this.bot.telegram.sendMessage(userId, safeText);
376
390
  }
377
391
  catch (err) {
378
392
  this.display.log(`Failed to send message to Telegram user ${userId}: ${err.message}`, { source: 'Telegram', level: 'error' });
@@ -85,7 +85,7 @@ Analyze the payload above and follow the instructions provided. Be concise and a
85
85
  try {
86
86
  const icon = status === 'completed' ? '✅' : '❌';
87
87
  const truncated = result.length > 3500 ? result.slice(0, 3500) + '…' : result;
88
- const message = `${icon} *Webhook: ${webhookName}*\n\n${truncated}`;
88
+ const message = `${icon} Webhook: ${webhookName}\n\n${truncated}`;
89
89
  await adapter.sendMessage(message);
90
90
  }
91
91
  catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "morpheus-cli",
3
- "version": "0.4.8",
3
+ "version": "0.4.9",
4
4
  "description": "Morpheus is a local AI agent for developers, running as a CLI daemon that connects to LLMs, local tools, and MCPs, enabling interaction via Terminal, Telegram, and Discord. Inspired by the character Morpheus from *The Matrix*, the project acts as an intelligent orchestrator, bridging the gap between the developer and complex systems.",
5
5
  "bin": {
6
6
  "morpheus": "./bin/morpheus.js"