@gonzih/cc-tg 0.6.0 → 0.6.1

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/bot.d.ts CHANGED
@@ -63,4 +63,8 @@ export declare class CcTgBot {
63
63
  getMe(): Promise<TelegramBot.User>;
64
64
  stop(): void;
65
65
  }
66
+ /** Detect URLs in text, fetch each via Jina Reader, and prepend content to the prompt */
67
+ export declare function enrichPromptWithUrls(text: string): Promise<string>;
68
+ /** List available skills from ~/.claude/skills/ */
69
+ export declare function listSkills(): string;
66
70
  export declare function splitMessage(text: string, maxLen?: number): string[];
package/dist/bot.js CHANGED
@@ -29,6 +29,7 @@ const BOT_COMMANDS = [
29
29
  { command: "restart", description: "Restart the bot process in-place" },
30
30
  { command: "get_file", description: "Send a file from the server to this chat" },
31
31
  { command: "cost", description: "Show session token usage and cost" },
32
+ { command: "skills", description: "List available Claude skills with descriptions" },
32
33
  ];
33
34
  const FLUSH_DELAY_MS = 800; // debounce streaming chunks into one Telegram message
34
35
  const TYPING_INTERVAL_MS = 4000; // re-send typing action before Telegram's 5s expiry
@@ -355,9 +356,15 @@ export class CcTgBot {
355
356
  await this.replyToChat(chatId, reply, threadId);
356
357
  return;
357
358
  }
359
+ // /skills — list available Claude skills from ~/.claude/skills/
360
+ if (text === "/skills") {
361
+ await this.replyToChat(chatId, listSkills(), threadId);
362
+ return;
363
+ }
358
364
  const session = this.getOrCreateSession(chatId, threadId, threadName);
359
365
  try {
360
- const prompt = buildPromptWithReplyContext(text, msg);
366
+ const enriched = await enrichPromptWithUrls(text);
367
+ const prompt = buildPromptWithReplyContext(enriched, msg);
361
368
  session.currentPrompt = prompt;
362
369
  session.claude.sendPrompt(prompt);
363
370
  this.startTyping(chatId, session);
@@ -1291,6 +1298,85 @@ function downloadToFile(url, destPath) {
1291
1298
  }).on("error", reject);
1292
1299
  });
1293
1300
  }
1301
+ /** Fetch URL via Jina Reader and return first maxChars characters */
1302
+ function fetchUrlViaJina(url, maxChars = 2000) {
1303
+ const jinaUrl = `https://r.jina.ai/${url}`;
1304
+ return new Promise((resolve, reject) => {
1305
+ https.get(jinaUrl, (res) => {
1306
+ const chunks = [];
1307
+ res.on("data", (chunk) => chunks.push(chunk));
1308
+ res.on("end", () => {
1309
+ const text = Buffer.concat(chunks).toString("utf8");
1310
+ resolve(text.slice(0, maxChars));
1311
+ });
1312
+ res.on("error", reject);
1313
+ }).on("error", reject);
1314
+ });
1315
+ }
1316
+ /** Detect URLs in text, fetch each via Jina Reader, and prepend content to the prompt */
1317
+ export async function enrichPromptWithUrls(text) {
1318
+ const urlRegex = /https?:\/\/[^\s]+/g;
1319
+ const urls = text.match(urlRegex);
1320
+ if (!urls || urls.length === 0)
1321
+ return text;
1322
+ const prefixes = [];
1323
+ for (const url of urls) {
1324
+ // Skip jina.ai URLs to avoid recursion
1325
+ if (url.includes("r.jina.ai"))
1326
+ continue;
1327
+ try {
1328
+ const content = await fetchUrlViaJina(url);
1329
+ if (content.trim()) {
1330
+ prefixes.push(`[Web content from ${url}]:\n${content}`);
1331
+ }
1332
+ }
1333
+ catch (err) {
1334
+ console.warn(`[url-fetch] failed to fetch ${url}:`, err.message);
1335
+ }
1336
+ }
1337
+ if (prefixes.length === 0)
1338
+ return text;
1339
+ return prefixes.join("\n\n") + "\n\n" + text;
1340
+ }
1341
+ /** Parse frontmatter description from a skill markdown file */
1342
+ function parseSkillDescription(content) {
1343
+ const match = content.match(/^---\s*\n([\s\S]*?)\n---/);
1344
+ if (!match)
1345
+ return null;
1346
+ const frontmatter = match[1];
1347
+ const descMatch = frontmatter.match(/^description:\s*(.+)$/m);
1348
+ return descMatch ? descMatch[1].trim() : null;
1349
+ }
1350
+ /** List available skills from ~/.claude/skills/ */
1351
+ export function listSkills() {
1352
+ const skillsDir = join(os.homedir(), ".claude", "skills");
1353
+ if (!existsSync(skillsDir)) {
1354
+ return "No skills directory found at ~/.claude/skills/";
1355
+ }
1356
+ let files;
1357
+ try {
1358
+ files = readdirSync(skillsDir).filter((f) => f.endsWith(".md"));
1359
+ }
1360
+ catch {
1361
+ return "Could not read skills directory.";
1362
+ }
1363
+ if (files.length === 0) {
1364
+ return "No skills found in ~/.claude/skills/";
1365
+ }
1366
+ const lines = ["Available skills:"];
1367
+ for (const file of files.sort()) {
1368
+ const name = "/" + file.replace(/\.md$/, "");
1369
+ try {
1370
+ const content = readFileSync(join(skillsDir, file), "utf8");
1371
+ const description = parseSkillDescription(content);
1372
+ lines.push(description ? `${name} — ${description}` : name);
1373
+ }
1374
+ catch {
1375
+ lines.push(name);
1376
+ }
1377
+ }
1378
+ return lines.join("\n");
1379
+ }
1294
1380
  export function splitMessage(text, maxLen = 4096) {
1295
1381
  if (text.length <= maxLen)
1296
1382
  return [text];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gonzih/cc-tg",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "Claude Code Telegram bot — chat with Claude Code via Telegram",
5
5
  "type": "module",
6
6
  "bin": {