telegram-claude-mcp 2.0.2 → 2.0.3
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/bin/daemon-ctl.js +0 -0
- package/bin/daemon.js +0 -0
- package/bin/proxy.js +0 -0
- package/bin/setup.js +5 -1
- package/hooks-v2/hooks-config-example.json +28 -0
- package/hooks-v2/progress-post-tool.sh +61 -0
- package/hooks-v2/progress-pre-tool.sh +53 -0
- package/hooks-v2/progress-stop.sh +34 -0
- package/package.json +1 -1
- package/src/daemon/index.ts +48 -1
- package/src/daemon/telegram-multi.ts +33 -0
package/bin/daemon-ctl.js
CHANGED
|
File without changes
|
package/bin/daemon.js
CHANGED
|
File without changes
|
package/bin/proxy.js
CHANGED
|
File without changes
|
package/bin/setup.js
CHANGED
|
@@ -162,7 +162,11 @@ RESPONSE=$(curl -s -X POST "$HOOK_URL" \\
|
|
|
162
162
|
if [ $? -eq 0 ]; then
|
|
163
163
|
DECISION=$(echo "$RESPONSE" | jq -r '.decision // empty')
|
|
164
164
|
REASON=$(echo "$RESPONSE" | jq -r '.reason // empty')
|
|
165
|
-
[ "$DECISION" = "block" ] && [ -n "$REASON" ]
|
|
165
|
+
if [ "$DECISION" = "block" ] && [ -n "$REASON" ]; then
|
|
166
|
+
echo "$RESPONSE"
|
|
167
|
+
# Exit code 2 tells Claude Code to continue with the reason as instructions
|
|
168
|
+
exit 2
|
|
169
|
+
fi
|
|
166
170
|
fi
|
|
167
171
|
`;
|
|
168
172
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"_comment": "Example Claude Code hooks configuration for progress tracking. Copy relevant sections to ~/.claude/settings.json or .claude/settings.json in your project.",
|
|
4
|
+
|
|
5
|
+
"hooks": {
|
|
6
|
+
"PreToolUse": [
|
|
7
|
+
{
|
|
8
|
+
"matcher": "*",
|
|
9
|
+
"command": "SESSION_NAME=${SESSION_NAME:-$(basename \"$PWD\")} /path/to/call-me/server/hooks-v2/progress-pre-tool.sh"
|
|
10
|
+
}
|
|
11
|
+
],
|
|
12
|
+
"PostToolUse": [
|
|
13
|
+
{
|
|
14
|
+
"matcher": "*",
|
|
15
|
+
"command": "SESSION_NAME=${SESSION_NAME:-$(basename \"$PWD\")} /path/to/call-me/server/hooks-v2/progress-post-tool.sh"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"Stop": [
|
|
19
|
+
{
|
|
20
|
+
"command": "SESSION_NAME=${SESSION_NAME:-$(basename \"$PWD\")} /path/to/call-me/server/hooks-v2/progress-stop.sh"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"_comment": "Optional: Interactive stop hook (waits for user response)",
|
|
24
|
+
"command": "SESSION_NAME=${SESSION_NAME:-$(basename \"$PWD\")} /path/to/call-me/server/hooks-v2/stop-hook.sh"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# PostToolUse progress hook for telegram-claude-daemon
|
|
3
|
+
# Sends tool completion events to update progress display
|
|
4
|
+
#
|
|
5
|
+
# This hook is fire-and-forget - it doesn't block Claude's execution
|
|
6
|
+
|
|
7
|
+
DAEMON_PORT="${TELEGRAM_CLAUDE_PORT:-3333}"
|
|
8
|
+
DAEMON_HOST="${TELEGRAM_CLAUDE_HOST:-localhost}"
|
|
9
|
+
HOOK_URL="http://${DAEMON_HOST}:${DAEMON_PORT}/progress"
|
|
10
|
+
|
|
11
|
+
# Read input from stdin
|
|
12
|
+
INPUT=$(cat)
|
|
13
|
+
|
|
14
|
+
# Extract tool info
|
|
15
|
+
TOOL_NAME=$(echo "$INPUT" | jq -r '.tool_name // .toolName // .name // empty')
|
|
16
|
+
TOOL_RESULT=$(echo "$INPUT" | jq -c '.tool_result // .result // {}')
|
|
17
|
+
|
|
18
|
+
# Check if tool succeeded
|
|
19
|
+
IS_ERROR=$(echo "$INPUT" | jq -r '.is_error // .isError // false')
|
|
20
|
+
if [ "$IS_ERROR" = "true" ]; then
|
|
21
|
+
SUCCESS="false"
|
|
22
|
+
else
|
|
23
|
+
SUCCESS="true"
|
|
24
|
+
fi
|
|
25
|
+
|
|
26
|
+
# Skip if no tool name
|
|
27
|
+
if [ -z "$TOOL_NAME" ]; then
|
|
28
|
+
exit 0
|
|
29
|
+
fi
|
|
30
|
+
|
|
31
|
+
# Skip progress updates for Telegram tools (would be recursive)
|
|
32
|
+
case "$TOOL_NAME" in
|
|
33
|
+
mcp__telegram__*|send_message|continue_chat|notify_user|end_chat)
|
|
34
|
+
exit 0
|
|
35
|
+
;;
|
|
36
|
+
esac
|
|
37
|
+
|
|
38
|
+
# Build payload
|
|
39
|
+
PAYLOAD=$(jq -n \
|
|
40
|
+
--arg type "post_tool" \
|
|
41
|
+
--arg session_name "${SESSION_NAME:-default}" \
|
|
42
|
+
--arg tool_name "$TOOL_NAME" \
|
|
43
|
+
--argjson success "$SUCCESS" \
|
|
44
|
+
--arg timestamp "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
|
|
45
|
+
'{
|
|
46
|
+
type: $type,
|
|
47
|
+
session_name: $session_name,
|
|
48
|
+
tool_name: $tool_name,
|
|
49
|
+
success: $success,
|
|
50
|
+
timestamp: $timestamp
|
|
51
|
+
}')
|
|
52
|
+
|
|
53
|
+
# Fire and forget - send in background and don't wait
|
|
54
|
+
(curl -s -X POST "$HOOK_URL" \
|
|
55
|
+
-H "Content-Type: application/json" \
|
|
56
|
+
-H "X-Session-Name: ${SESSION_NAME:-default}" \
|
|
57
|
+
-d "$PAYLOAD" \
|
|
58
|
+
--max-time 2 2>/dev/null) &
|
|
59
|
+
|
|
60
|
+
# Exit immediately - don't block Claude
|
|
61
|
+
exit 0
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# PreToolUse progress hook for telegram-claude-daemon
|
|
3
|
+
# Sends tool start events to update progress display
|
|
4
|
+
#
|
|
5
|
+
# This hook is fire-and-forget - it doesn't block Claude's execution
|
|
6
|
+
|
|
7
|
+
DAEMON_PORT="${TELEGRAM_CLAUDE_PORT:-3333}"
|
|
8
|
+
DAEMON_HOST="${TELEGRAM_CLAUDE_HOST:-localhost}"
|
|
9
|
+
HOOK_URL="http://${DAEMON_HOST}:${DAEMON_PORT}/progress"
|
|
10
|
+
|
|
11
|
+
# Read input from stdin
|
|
12
|
+
INPUT=$(cat)
|
|
13
|
+
|
|
14
|
+
# Extract tool info
|
|
15
|
+
TOOL_NAME=$(echo "$INPUT" | jq -r '.tool_name // .toolName // .name // empty')
|
|
16
|
+
TOOL_INPUT=$(echo "$INPUT" | jq -c '.tool_input // .toolInput // .input // .arguments // {}')
|
|
17
|
+
|
|
18
|
+
# Skip if no tool name
|
|
19
|
+
if [ -z "$TOOL_NAME" ]; then
|
|
20
|
+
exit 0
|
|
21
|
+
fi
|
|
22
|
+
|
|
23
|
+
# Skip progress updates for Telegram tools (would be recursive)
|
|
24
|
+
case "$TOOL_NAME" in
|
|
25
|
+
mcp__telegram__*|send_message|continue_chat|notify_user|end_chat)
|
|
26
|
+
exit 0
|
|
27
|
+
;;
|
|
28
|
+
esac
|
|
29
|
+
|
|
30
|
+
# Build payload
|
|
31
|
+
PAYLOAD=$(jq -n \
|
|
32
|
+
--arg type "pre_tool" \
|
|
33
|
+
--arg session_name "${SESSION_NAME:-default}" \
|
|
34
|
+
--arg tool_name "$TOOL_NAME" \
|
|
35
|
+
--argjson tool_input "$TOOL_INPUT" \
|
|
36
|
+
--arg timestamp "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
|
|
37
|
+
'{
|
|
38
|
+
type: $type,
|
|
39
|
+
session_name: $session_name,
|
|
40
|
+
tool_name: $tool_name,
|
|
41
|
+
tool_input: $tool_input,
|
|
42
|
+
timestamp: $timestamp
|
|
43
|
+
}')
|
|
44
|
+
|
|
45
|
+
# Fire and forget - send in background and don't wait
|
|
46
|
+
(curl -s -X POST "$HOOK_URL" \
|
|
47
|
+
-H "Content-Type: application/json" \
|
|
48
|
+
-H "X-Session-Name: ${SESSION_NAME:-default}" \
|
|
49
|
+
-d "$PAYLOAD" \
|
|
50
|
+
--max-time 2 2>/dev/null) &
|
|
51
|
+
|
|
52
|
+
# Exit immediately - don't block Claude
|
|
53
|
+
exit 0
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Stop progress hook for telegram-claude-daemon
|
|
3
|
+
# Sends stop events to finalize progress display
|
|
4
|
+
#
|
|
5
|
+
# This hook is fire-and-forget - it doesn't block Claude's execution
|
|
6
|
+
# Note: This is separate from stop-hook.sh which handles interactive stop
|
|
7
|
+
|
|
8
|
+
DAEMON_PORT="${TELEGRAM_CLAUDE_PORT:-3333}"
|
|
9
|
+
DAEMON_HOST="${TELEGRAM_CLAUDE_HOST:-localhost}"
|
|
10
|
+
HOOK_URL="http://${DAEMON_HOST}:${DAEMON_PORT}/progress"
|
|
11
|
+
|
|
12
|
+
# Read input from stdin (if any)
|
|
13
|
+
INPUT=$(cat)
|
|
14
|
+
|
|
15
|
+
# Build payload
|
|
16
|
+
PAYLOAD=$(jq -n \
|
|
17
|
+
--arg type "stop" \
|
|
18
|
+
--arg session_name "${SESSION_NAME:-default}" \
|
|
19
|
+
--arg timestamp "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
|
|
20
|
+
'{
|
|
21
|
+
type: $type,
|
|
22
|
+
session_name: $session_name,
|
|
23
|
+
timestamp: $timestamp
|
|
24
|
+
}')
|
|
25
|
+
|
|
26
|
+
# Fire and forget - send in background and don't wait
|
|
27
|
+
(curl -s -X POST "$HOOK_URL" \
|
|
28
|
+
-H "Content-Type: application/json" \
|
|
29
|
+
-H "X-Session-Name: ${SESSION_NAME:-default}" \
|
|
30
|
+
-d "$PAYLOAD" \
|
|
31
|
+
--max-time 2 2>/dev/null) &
|
|
32
|
+
|
|
33
|
+
# Exit immediately - don't block Claude
|
|
34
|
+
exit 0
|
package/package.json
CHANGED
package/src/daemon/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { existsSync, unlinkSync, writeFileSync, mkdirSync } from 'fs';
|
|
|
13
13
|
import { dirname } from 'path';
|
|
14
14
|
import { SessionManager } from './session-manager.js';
|
|
15
15
|
import { MultiTelegramManager, type HookEvent } from './telegram-multi.js';
|
|
16
|
+
import { ProgressTracker, type ProgressEvent } from './progress-tracker.js';
|
|
16
17
|
import {
|
|
17
18
|
DAEMON_SOCKET_PATH,
|
|
18
19
|
DAEMON_PID_FILE,
|
|
@@ -96,6 +97,16 @@ async function main() {
|
|
|
96
97
|
|
|
97
98
|
telegram.start();
|
|
98
99
|
|
|
100
|
+
// Create progress tracker
|
|
101
|
+
const progressTracker = new ProgressTracker(
|
|
102
|
+
telegram.getBot(),
|
|
103
|
+
telegram.getChatId(),
|
|
104
|
+
sessionManager
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
// Register progress tracker's callback handler for mute buttons
|
|
108
|
+
telegram.registerCallbackInterceptor((query) => progressTracker.handleCallback(query));
|
|
109
|
+
|
|
99
110
|
// Track socket buffers for each connection
|
|
100
111
|
const socketBuffers = new Map<net.Socket, string>();
|
|
101
112
|
|
|
@@ -223,6 +234,41 @@ async function main() {
|
|
|
223
234
|
return;
|
|
224
235
|
}
|
|
225
236
|
|
|
237
|
+
// Progress tracking endpoint
|
|
238
|
+
if (url === '/progress' || url === '/hooks/progress') {
|
|
239
|
+
const event = data as ProgressEvent;
|
|
240
|
+
|
|
241
|
+
console.error(`[HTTP] Progress: ${event.type} - ${event.tool_name || ''} (session: ${sessionName})`);
|
|
242
|
+
|
|
243
|
+
try {
|
|
244
|
+
switch (event.type) {
|
|
245
|
+
case 'start':
|
|
246
|
+
await progressTracker.handleSessionStart(sessionName);
|
|
247
|
+
break;
|
|
248
|
+
case 'pre_tool':
|
|
249
|
+
await progressTracker.handlePreTool(sessionName, event.tool_name!, event.tool_input);
|
|
250
|
+
break;
|
|
251
|
+
case 'post_tool':
|
|
252
|
+
await progressTracker.handlePostTool(sessionName, event.tool_name!, event.success ?? true);
|
|
253
|
+
break;
|
|
254
|
+
case 'stop':
|
|
255
|
+
await progressTracker.handleStop(sessionName);
|
|
256
|
+
break;
|
|
257
|
+
case 'notification':
|
|
258
|
+
await progressTracker.handleNotification(sessionName, event.tool_name || '');
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
263
|
+
res.end(JSON.stringify({ ok: true }));
|
|
264
|
+
} catch (error) {
|
|
265
|
+
console.error('[HTTP] Progress error:', error);
|
|
266
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
267
|
+
res.end(JSON.stringify({ ok: true })); // Don't fail hooks
|
|
268
|
+
}
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
|
|
226
272
|
// Status endpoint
|
|
227
273
|
if (url === '/status') {
|
|
228
274
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
@@ -284,9 +330,10 @@ async function main() {
|
|
|
284
330
|
process.on('SIGINT', shutdown);
|
|
285
331
|
process.on('SIGTERM', shutdown);
|
|
286
332
|
|
|
287
|
-
// Periodic cleanup of dead sessions
|
|
333
|
+
// Periodic cleanup of dead sessions and progress state
|
|
288
334
|
setInterval(() => {
|
|
289
335
|
sessionManager.cleanup();
|
|
336
|
+
progressTracker.cleanup();
|
|
290
337
|
}, 30000);
|
|
291
338
|
}
|
|
292
339
|
|
|
@@ -54,6 +54,7 @@ export class MultiTelegramManager {
|
|
|
54
54
|
private pendingPermissions: Map<string, PendingPermission> = new Map();
|
|
55
55
|
private messageToSession: Map<number, string> = new Map(); // messageId -> sessionId
|
|
56
56
|
private isRunning = false;
|
|
57
|
+
private callbackInterceptors: Array<(query: TelegramBot.CallbackQuery) => Promise<boolean>> = [];
|
|
57
58
|
|
|
58
59
|
constructor(config: MultiTelegramConfig, sessionManager: SessionManager) {
|
|
59
60
|
this.config = {
|
|
@@ -68,6 +69,28 @@ export class MultiTelegramManager {
|
|
|
68
69
|
this.setupCallbackHandler();
|
|
69
70
|
}
|
|
70
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Get the underlying bot instance for advanced operations.
|
|
74
|
+
*/
|
|
75
|
+
getBot(): TelegramBot {
|
|
76
|
+
return this.bot;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get the configured chat ID.
|
|
81
|
+
*/
|
|
82
|
+
getChatId(): number {
|
|
83
|
+
return this.config.chatId;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Register a callback interceptor that handles callback queries before the default handler.
|
|
88
|
+
* Return true to indicate the query was handled and stop further processing.
|
|
89
|
+
*/
|
|
90
|
+
registerCallbackInterceptor(handler: (query: TelegramBot.CallbackQuery) => Promise<boolean>): void {
|
|
91
|
+
this.callbackInterceptors.push(handler);
|
|
92
|
+
}
|
|
93
|
+
|
|
71
94
|
start(): void {
|
|
72
95
|
this.isRunning = true;
|
|
73
96
|
console.error('[MultiTelegram] Bot started');
|
|
@@ -544,6 +567,16 @@ export class MultiTelegramManager {
|
|
|
544
567
|
this.bot.on('callback_query', async (query) => {
|
|
545
568
|
if (!query.data || !query.message) return;
|
|
546
569
|
|
|
570
|
+
// Check interceptors first
|
|
571
|
+
for (const interceptor of this.callbackInterceptors) {
|
|
572
|
+
try {
|
|
573
|
+
const handled = await interceptor(query);
|
|
574
|
+
if (handled) return;
|
|
575
|
+
} catch (error) {
|
|
576
|
+
console.error('[MultiTelegram] Callback interceptor error:', error);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
547
580
|
const [action, messageId] = query.data.split(':');
|
|
548
581
|
const key = messageId;
|
|
549
582
|
|