@gonzih/cc-tg 0.2.6 → 0.2.7
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 +7 -0
- package/dist/bot.js +87 -0
- package/package.json +8 -2
package/dist/bot.d.ts
CHANGED
|
@@ -31,6 +31,13 @@ export declare class CcTgBot {
|
|
|
31
31
|
private extractToolName;
|
|
32
32
|
private handleCron;
|
|
33
33
|
private handleCronEdit;
|
|
34
|
+
/** Find cc-agent PIDs via pgrep. Returns array of numeric PIDs. */
|
|
35
|
+
private findCcAgentPids;
|
|
36
|
+
/** Kill cc-agent PIDs with SIGTERM. Returns the list of killed PIDs. */
|
|
37
|
+
private killCcAgent;
|
|
38
|
+
private handleReloadMcp;
|
|
39
|
+
private handleMcpVersion;
|
|
40
|
+
private handleClearNpxCache;
|
|
34
41
|
private killSession;
|
|
35
42
|
stop(): void;
|
|
36
43
|
}
|
package/dist/bot.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import TelegramBot from "node-telegram-bot-api";
|
|
6
6
|
import { existsSync, createWriteStream, mkdirSync } from "fs";
|
|
7
7
|
import { resolve, basename, join } from "path";
|
|
8
|
+
import { execSync } from "child_process";
|
|
8
9
|
import https from "https";
|
|
9
10
|
import http from "http";
|
|
10
11
|
import { ClaudeProcess, extractText } from "./claude.js";
|
|
@@ -17,6 +18,9 @@ const BOT_COMMANDS = [
|
|
|
17
18
|
{ command: "status", description: "Check if a session is active" },
|
|
18
19
|
{ command: "help", description: "Show all available commands" },
|
|
19
20
|
{ command: "cron", description: "Manage cron jobs — add/list/edit/remove/clear" },
|
|
21
|
+
{ command: "reload_mcp", description: "Restart the cc-agent MCP server process" },
|
|
22
|
+
{ command: "mcp_version", description: "Show cc-agent npm version and npx cache info" },
|
|
23
|
+
{ command: "clear_npx_cache", description: "Clear npx cache and restart MCP to pick up latest version" },
|
|
20
24
|
];
|
|
21
25
|
const FLUSH_DELAY_MS = 800; // debounce streaming chunks into one Telegram message
|
|
22
26
|
const TYPING_INTERVAL_MS = 4000; // re-send typing action before Telegram's 5s expiry
|
|
@@ -112,6 +116,21 @@ export class CcTgBot {
|
|
|
112
116
|
await this.handleCron(chatId, text);
|
|
113
117
|
return;
|
|
114
118
|
}
|
|
119
|
+
// /reload_mcp — kill cc-agent process so Claude Code auto-restarts it
|
|
120
|
+
if (text === "/reload_mcp") {
|
|
121
|
+
await this.handleReloadMcp(chatId);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
// /mcp_version — show published npm version and cached npx entries
|
|
125
|
+
if (text === "/mcp_version") {
|
|
126
|
+
await this.handleMcpVersion(chatId);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
// /clear_npx_cache — wipe ~/.npm/_npx/ then restart cc-agent
|
|
130
|
+
if (text === "/clear_npx_cache") {
|
|
131
|
+
await this.handleClearNpxCache(chatId);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
115
134
|
const session = this.getOrCreateSession(chatId);
|
|
116
135
|
try {
|
|
117
136
|
session.claude.sendPrompt(text);
|
|
@@ -519,6 +538,74 @@ export class CcTgBot {
|
|
|
519
538
|
"/cron edit <#> schedule every <N><unit>\n" +
|
|
520
539
|
"/cron edit <#> prompt <new prompt>");
|
|
521
540
|
}
|
|
541
|
+
/** Find cc-agent PIDs via pgrep. Returns array of numeric PIDs. */
|
|
542
|
+
findCcAgentPids() {
|
|
543
|
+
try {
|
|
544
|
+
const out = execSync("pgrep -f cc-agent", { encoding: "utf8" }).trim();
|
|
545
|
+
return out.split("\n").map((s) => parseInt(s.trim(), 10)).filter((n) => !isNaN(n) && n > 0);
|
|
546
|
+
}
|
|
547
|
+
catch {
|
|
548
|
+
// pgrep exits with code 1 when no match — that's fine
|
|
549
|
+
return [];
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
/** Kill cc-agent PIDs with SIGTERM. Returns the list of killed PIDs. */
|
|
553
|
+
killCcAgent() {
|
|
554
|
+
const pids = this.findCcAgentPids();
|
|
555
|
+
for (const pid of pids) {
|
|
556
|
+
try {
|
|
557
|
+
process.kill(pid, "SIGTERM");
|
|
558
|
+
console.log(`[mcp] sent SIGTERM to cc-agent pid=${pid}`);
|
|
559
|
+
}
|
|
560
|
+
catch (err) {
|
|
561
|
+
console.warn(`[mcp] failed to kill pid=${pid}:`, err.message);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
return pids;
|
|
565
|
+
}
|
|
566
|
+
async handleReloadMcp(chatId) {
|
|
567
|
+
const pids = this.killCcAgent();
|
|
568
|
+
if (pids.length === 0) {
|
|
569
|
+
await this.bot.sendMessage(chatId, "No cc-agent process found. MCP will start fresh on the next agent call.");
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
await this.bot.sendMessage(chatId, `Sent SIGTERM to cc-agent (pid${pids.length > 1 ? "s" : ""}: ${pids.join(", ")}).\nMCP restarted. New process will load on next agent call.`);
|
|
573
|
+
}
|
|
574
|
+
async handleMcpVersion(chatId) {
|
|
575
|
+
let npmVersion = "unknown";
|
|
576
|
+
let cacheEntries = "(unavailable)";
|
|
577
|
+
try {
|
|
578
|
+
npmVersion = execSync("npm view @gonzih/cc-agent version", { encoding: "utf8" }).trim();
|
|
579
|
+
}
|
|
580
|
+
catch (err) {
|
|
581
|
+
npmVersion = `error: ${err.message.split("\n")[0]}`;
|
|
582
|
+
}
|
|
583
|
+
try {
|
|
584
|
+
const home = process.env.HOME ?? "~";
|
|
585
|
+
const cacheOut = execSync(`ls "${home}/.npm/_npx/" 2>/dev/null | head -5`, { encoding: "utf8", shell: "/bin/sh" }).trim();
|
|
586
|
+
cacheEntries = cacheOut || "(empty)";
|
|
587
|
+
}
|
|
588
|
+
catch {
|
|
589
|
+
cacheEntries = "(empty or not found)";
|
|
590
|
+
}
|
|
591
|
+
await this.bot.sendMessage(chatId, `cc-agent npm version: ${npmVersion}\n\nnpx cache (~/.npm/_npx/):\n${cacheEntries}`);
|
|
592
|
+
}
|
|
593
|
+
async handleClearNpxCache(chatId) {
|
|
594
|
+
try {
|
|
595
|
+
const home = process.env.HOME ?? "~";
|
|
596
|
+
execSync(`rm -rf "${home}/.npm/_npx/"`, { encoding: "utf8", shell: "/bin/sh" });
|
|
597
|
+
console.log("[mcp] cleared ~/.npm/_npx/");
|
|
598
|
+
}
|
|
599
|
+
catch (err) {
|
|
600
|
+
await this.bot.sendMessage(chatId, `Failed to clear npx cache: ${err.message}`);
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
const pids = this.killCcAgent();
|
|
604
|
+
const pidNote = pids.length > 0
|
|
605
|
+
? ` Sent SIGTERM to pid${pids.length > 1 ? "s" : ""}: ${pids.join(", ")}.`
|
|
606
|
+
: " No cc-agent process found (will start fresh on next call).";
|
|
607
|
+
await this.bot.sendMessage(chatId, `NPX cache cleared and MCP restarted.${pidNote} Will pick up latest npm version on next call.`);
|
|
608
|
+
}
|
|
522
609
|
killSession(chatId, keepCrons = true) {
|
|
523
610
|
const session = this.sessions.get(chatId);
|
|
524
611
|
if (session) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gonzih/cc-tg",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "Claude Code Telegram bot — chat with Claude Code via Telegram",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -30,6 +30,12 @@
|
|
|
30
30
|
"bugs": {
|
|
31
31
|
"url": "https://github.com/Gonzih/cc-tg/issues"
|
|
32
32
|
},
|
|
33
|
-
"keywords": [
|
|
33
|
+
"keywords": [
|
|
34
|
+
"claude",
|
|
35
|
+
"claude-code",
|
|
36
|
+
"telegram",
|
|
37
|
+
"bot",
|
|
38
|
+
"ai"
|
|
39
|
+
],
|
|
34
40
|
"license": "MIT"
|
|
35
41
|
}
|