@gonzih/cc-tg 0.3.5 → 0.3.6
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 +2 -0
- package/dist/bot.js +3 -0
- package/dist/index.js +34 -2
- package/package.json +2 -1
package/dist/bot.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Telegram bot that routes messages to/from a Claude Code subprocess.
|
|
3
3
|
* One ClaudeProcess per chat_id — sessions are isolated per user.
|
|
4
4
|
*/
|
|
5
|
+
import TelegramBot from "node-telegram-bot-api";
|
|
5
6
|
export interface BotOptions {
|
|
6
7
|
telegramToken: string;
|
|
7
8
|
claudeToken?: string;
|
|
@@ -49,6 +50,7 @@ export declare class CcTgBot {
|
|
|
49
50
|
private handleGetFile;
|
|
50
51
|
private callCcAgentTool;
|
|
51
52
|
private killSession;
|
|
53
|
+
getMe(): Promise<TelegramBot.User>;
|
|
52
54
|
stop(): void;
|
|
53
55
|
}
|
|
54
56
|
export declare function splitMessage(text: string, maxLen?: number): string[];
|
package/dist/bot.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -15,10 +15,17 @@
|
|
|
15
15
|
* CWD — working directory for Claude Code (default: process.cwd())
|
|
16
16
|
*/
|
|
17
17
|
import { createServer, createConnection } from "net";
|
|
18
|
-
import { unlinkSync } from "fs";
|
|
18
|
+
import { unlinkSync, readFileSync } from "fs";
|
|
19
19
|
import { tmpdir } from "os";
|
|
20
|
-
import
|
|
20
|
+
import os from "os";
|
|
21
|
+
import { join, dirname } from "path";
|
|
22
|
+
import { fileURLToPath } from "url";
|
|
21
23
|
import { CcTgBot } from "./bot.js";
|
|
24
|
+
import { Registry, startControlServer } from "@gonzih/agent-ops";
|
|
25
|
+
import { Redis } from "ioredis";
|
|
26
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
27
|
+
const __dirname = dirname(__filename);
|
|
28
|
+
const pkg = JSON.parse(readFileSync(join(__dirname, "../package.json"), "utf-8"));
|
|
22
29
|
// Make lock socket unique per bot token so multiple users on the same machine don't collide
|
|
23
30
|
const _tokenHash = Buffer.from(process.env.TELEGRAM_BOT_TOKEN ?? "default").toString("base64").replace(/[^a-z0-9]/gi, "").slice(0, 16);
|
|
24
31
|
const LOCK_SOCKET = join(tmpdir(), `cc-tg-${_tokenHash}.sock`);
|
|
@@ -105,6 +112,31 @@ const bot = new CcTgBot({
|
|
|
105
112
|
allowedUserIds,
|
|
106
113
|
groupChatIds,
|
|
107
114
|
});
|
|
115
|
+
// agent-ops: optional self-registration + HTTP control endpoint
|
|
116
|
+
if (process.env.CC_AGENT_OPS_PORT) {
|
|
117
|
+
const botInfo = await bot.getMe();
|
|
118
|
+
const redis = new Redis(process.env.REDIS_URL || "redis://localhost:6379");
|
|
119
|
+
const registry = new Registry(redis);
|
|
120
|
+
const namespace = process.env.CC_AGENT_NAMESPACE || "default";
|
|
121
|
+
await registry.register({
|
|
122
|
+
namespace,
|
|
123
|
+
hostname: os.hostname(),
|
|
124
|
+
user: os.userInfo().username,
|
|
125
|
+
pid: String(process.pid),
|
|
126
|
+
version: pkg.version,
|
|
127
|
+
cwd: process.env.CWD || process.cwd(),
|
|
128
|
+
control_port: process.env.CC_AGENT_OPS_PORT,
|
|
129
|
+
bot_username: botInfo.username ?? "",
|
|
130
|
+
started_at: new Date().toISOString(),
|
|
131
|
+
});
|
|
132
|
+
setInterval(() => registry.heartbeat(namespace), 60_000);
|
|
133
|
+
startControlServer(Number(process.env.CC_AGENT_OPS_PORT), {
|
|
134
|
+
namespace,
|
|
135
|
+
version: pkg.version,
|
|
136
|
+
logFile: process.env.CC_AGENT_LOG_FILE || process.env.LOG_FILE,
|
|
137
|
+
});
|
|
138
|
+
console.log(`[ops] control server on port ${process.env.CC_AGENT_OPS_PORT}`);
|
|
139
|
+
}
|
|
108
140
|
process.on("SIGINT", () => {
|
|
109
141
|
console.log("\nShutting down...");
|
|
110
142
|
bot.stop();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gonzih/cc-tg",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "Claude Code Telegram bot — chat with Claude Code via Telegram",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"dist/"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
+
"@gonzih/agent-ops": "^0.1.0",
|
|
21
22
|
"node-telegram-bot-api": "^0.66.0"
|
|
22
23
|
},
|
|
23
24
|
"devDependencies": {
|