@delt/claude-alarm 0.8.1 → 0.8.2

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.
package/dist/index.js CHANGED
@@ -210,7 +210,7 @@ import fs from "fs";
210
210
  import path2 from "path";
211
211
  import { randomUUID } from "crypto";
212
212
  var TELEGRAM_API = "https://api.telegram.org/bot";
213
- var TelegramBot = class {
213
+ var TelegramBot = class _TelegramBot {
214
214
  config;
215
215
  offset = 0;
216
216
  polling = false;
@@ -442,33 +442,45 @@ ${this.mdToHtml(message)}`;
442
442
  }
443
443
  /** Send a permission request with inline buttons */
444
444
  async sendPermissionRequest(sessionId, sessionLabel, requestId, toolName, description, inputPreview) {
445
+ const isNotify = toolName.endsWith("__notify") || toolName === "notify";
445
446
  let preview = inputPreview;
447
+ let kind = "code";
448
+ let lang = "";
446
449
  let truncated = false;
447
450
  try {
448
451
  const p = JSON.parse(inputPreview);
449
- if (p.command) preview = `$ ${p.command}`;
450
- else if (p.title && p.message) preview = p.message;
451
- else if (p.file_path) {
452
+ if (p.command) {
453
+ preview = `$ ${p.command}`;
454
+ lang = "bash";
455
+ } else if (p.title && p.message) {
456
+ preview = p.message;
457
+ kind = "prose";
458
+ } else if (p.file_path) {
452
459
  preview = p.file_path;
460
+ lang = this.langOf(p.file_path);
453
461
  if (p.content) {
454
462
  preview += "\n" + p.content.slice(0, 3e3);
455
463
  if (p.content.length > 500) truncated = true;
456
464
  }
457
465
  } else if (p.content && typeof p.content === "string") {
458
466
  preview = p.content.slice(0, 3e3);
467
+ if (isNotify) kind = "prose";
459
468
  if (p.content.length > 500) truncated = true;
460
469
  }
461
470
  } catch {
462
471
  truncated = true;
463
472
  const cmdMatch = inputPreview.match(/"command"\s*:\s*"((?:[^"\\]|\\.)*)"/);
464
473
  const contentMatch = inputPreview.match(/"content"\s*:\s*"((?:[^"\\]|\\.)*)"/);
465
- if (cmdMatch) preview = `$ ${cmdMatch[1]}`;
466
- else if (contentMatch) preview = contentMatch[1].slice(0, 3e3);
474
+ if (cmdMatch) {
475
+ preview = `$ ${cmdMatch[1]}`;
476
+ lang = "bash";
477
+ } else if (contentMatch) preview = contentMatch[1].slice(0, 3e3);
467
478
  }
468
479
  const truncNote = truncated ? "\n\n<i>...truncated</i>" : "";
469
480
  const previewSlice = preview.slice(0, 3e3);
470
481
  const isShort = !previewSlice.includes("\n") && previewSlice.length < 100;
471
- const previewHtml = isShort ? `<code>${this.escHtml(previewSlice)}</code>` : this.escHtml(previewSlice);
482
+ const langAttr = lang ? ` class="language-${lang}"` : "";
483
+ const previewHtml = kind === "prose" ? this.mdToHtml(previewSlice) : isShort ? `<code>${this.escHtml(previewSlice)}</code>` : `<pre><code${langAttr}>${this.escHtml(previewSlice)}</code></pre>`;
472
484
  let displayTool = toolName;
473
485
  if ((toolName.endsWith("__notify") || toolName === "notify") && inputPreview) {
474
486
  try {
@@ -568,6 +580,40 @@ ${label}`);
568
580
  escHtml(s) {
569
581
  return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
570
582
  }
583
+ static LANG_BY_EXT = {
584
+ js: "javascript",
585
+ mjs: "javascript",
586
+ cjs: "javascript",
587
+ jsx: "javascript",
588
+ ts: "typescript",
589
+ tsx: "typescript",
590
+ py: "python",
591
+ rb: "ruby",
592
+ go: "go",
593
+ java: "java",
594
+ kt: "kotlin",
595
+ rs: "rust",
596
+ php: "php",
597
+ cs: "csharp",
598
+ sh: "bash",
599
+ bash: "bash",
600
+ zsh: "bash",
601
+ ps1: "powershell",
602
+ json: "json",
603
+ yml: "yaml",
604
+ yaml: "yaml",
605
+ xml: "xml",
606
+ sql: "sql",
607
+ md: "markdown",
608
+ html: "html",
609
+ vue: "html",
610
+ css: "css",
611
+ scss: "scss"
612
+ };
613
+ langOf(path5) {
614
+ const m = /\.([a-z0-9]+)$/i.exec(path5 || "");
615
+ return m ? _TelegramBot.LANG_BY_EXT[m[1].toLowerCase()] ?? "" : "";
616
+ }
571
617
  /** Convert markdown to Telegram HTML (escape first, then apply formatting) */
572
618
  mdToHtml(s) {
573
619
  let text = s.replace(