telecoder 1.2.0 → 1.3.0
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/.env.example +142 -130
- package/CHANGELOG.md +683 -2
- package/README.md +36 -32
- package/dist/audio/transcribe.js +0 -9
- package/dist/bin/mcp-server.js +46 -61
- package/dist/bot/bot.js +162 -181
- package/dist/bot/command-catalog.js +263 -0
- package/dist/bot/deleted-threads.js +103 -0
- package/dist/bot/file-access.js +35 -26
- package/dist/bot/handlers/album.handler.js +128 -0
- package/dist/bot/handlers/{fork.handler.js → branch.handler.js} +267 -280
- package/dist/bot/handlers/command/access.js +1 -1
- package/dist/bot/handlers/command/admin.js +86 -110
- package/dist/bot/handlers/command/all-view.js +33 -0
- package/dist/bot/handlers/command/auto-approve.js +3 -3
- package/dist/bot/handlers/command/background.js +37 -0
- package/dist/bot/handlers/command/botname.js +76 -0
- package/dist/bot/handlers/command/btw.js +20 -69
- package/dist/bot/handlers/command/cleanup.js +329 -0
- package/dist/bot/handlers/command/model.js +40 -119
- package/dist/bot/handlers/command/prefs-scope.js +255 -90
- package/dist/bot/handlers/command/project.js +31 -109
- package/dist/bot/handlers/command/resume.js +8 -4
- package/dist/bot/handlers/command/session.js +74 -213
- package/dist/bot/handlers/command/settings.js +92 -447
- package/dist/bot/handlers/command/shared.js +32 -35
- package/dist/bot/handlers/command/tasks.js +263 -95
- package/dist/bot/handlers/command/thread.js +128 -0
- package/dist/bot/handlers/command/topic-store.js +14 -53
- package/dist/bot/handlers/command/topic.js +8 -61
- package/dist/bot/handlers/command/{cost.js → usage.js} +32 -59
- package/dist/bot/handlers/command-fallback.js +179 -0
- package/dist/bot/handlers/command.handler.js +96 -422
- package/dist/bot/handlers/{schedule.handler.js → loop.handler.js} +159 -73
- package/dist/bot/handlers/media-fallback.js +12 -7
- package/dist/bot/handlers/message/replies.js +10 -87
- package/dist/bot/handlers/message/shared.js +9 -31
- package/dist/bot/handlers/message/turn-notify.js +15 -49
- package/dist/bot/handlers/message/turn-runner.js +18 -103
- package/dist/bot/handlers/message.handler.js +59 -52
- package/dist/bot/handlers/newbot.handler.js +13 -4
- package/dist/bot/handlers/photo.handler.js +88 -129
- package/dist/bot/handlers/prompts.handler.js +11 -11
- package/dist/bot/handlers/running-note.js +2 -2
- package/dist/bot/handlers/session-guard.js +4 -4
- package/dist/bot/handlers/suggestion.handler.js +2 -2
- package/dist/bot/handlers/tree.handler.js +20 -20
- package/dist/bot/handlers/voice.handler.js +23 -85
- package/dist/bot/kept-threads.js +51 -0
- package/dist/bot/middleware/album-collector.js +69 -0
- package/dist/bot/middleware/auth.middleware.js +1 -1
- package/dist/bot/middleware/group-mention.middleware.js +11 -5
- package/dist/bot/middleware/queued-messages.js +143 -32
- package/dist/bot/middleware/stale-filter.js +0 -22
- package/dist/build-info.json +5 -5
- package/dist/claude/ask-user-form.js +517 -0
- package/dist/claude/ask-user.js +94 -26
- package/dist/claude/auto-topic-haiku.js +17 -0
- package/dist/claude/available-commands.js +22 -19
- package/dist/claude/background-hint.js +91 -0
- package/dist/claude/{fork-tree.js → branch-tree.js} +9 -9
- package/dist/claude/carry-over.js +0 -2
- package/dist/claude/ccr-shim.js +12 -10
- package/dist/claude/claude-auth.js +6 -10
- package/dist/claude/command-parser.js +49 -43
- package/dist/claude/cost-overlay-scraper.js +7 -2
- package/dist/claude/effort-level.js +5 -0
- package/dist/claude/enabled-plugins.js +12 -16
- package/dist/claude/in-flight-tracker.js +21 -0
- package/dist/claude/mcp-bridge.js +86 -58
- package/dist/claude/memory-guard.js +400 -0
- package/dist/claude/message-offsets.js +5 -5
- package/dist/claude/modal-relay.js +401 -34
- package/dist/claude/model-catalog.js +20 -3
- package/dist/claude/monitor-relay.js +130 -15
- package/dist/claude/native-commands.js +40 -0
- package/dist/claude/{pending-forks.js → pending-branches.js} +26 -26
- package/dist/claude/permission-gate.js +11 -10
- package/dist/claude/permission-mode.js +19 -45
- package/dist/claude/prewarm.js +70 -0
- package/dist/claude/pty-idle-reaper.js +96 -0
- package/dist/claude/pty-provider.js +473 -188
- package/dist/claude/pty-spawn-config.js +79 -32
- package/dist/claude/pty-watch.js +201 -0
- package/dist/claude/request-queue.js +7 -35
- package/dist/claude/rewind.js +111 -0
- package/dist/claude/scheduled-runner.js +1 -3
- package/dist/claude/scheduler.js +6 -2
- package/dist/claude/scope-guard.js +8 -3
- package/dist/claude/screen-marks.js +83 -0
- package/dist/claude/screen-render.js +96 -0
- package/dist/claude/session-history.js +4 -2
- package/dist/claude/session-jsonl.js +162 -15
- package/dist/claude/session-manager.js +29 -8
- package/dist/claude/session-move.js +70 -0
- package/dist/claude/shell-mode-gate.js +60 -0
- package/dist/claude/side-question.js +20 -17
- package/dist/claude/stage-images.js +5 -5
- package/dist/claude/tasks-overlay-scraper.js +143 -20
- package/dist/claude/thread-judge-haiku.js +88 -0
- package/dist/claude/tip-scraper.js +3 -4
- package/dist/claude/tui-modal.js +272 -27
- package/dist/claude/tui-state.js +74 -2
- package/dist/claude/turn-end.js +15 -1
- package/dist/claude/turn-prose.js +1 -1
- package/dist/claude/typed-answer.js +104 -0
- package/dist/claude/update-banner-relay.js +1 -1
- package/dist/cli/commands/doctor.js +48 -15
- package/dist/cli/commands/help.js +11 -2
- package/dist/cli/commands/init.js +16 -13
- package/dist/cli/commands/service.js +40 -8
- package/dist/cli/commands/start.js +10 -0
- package/dist/cli/commands/watch.js +322 -0
- package/dist/cli/dispatch.js +5 -0
- package/dist/cli/init/env-file.js +1 -1
- package/dist/cli/init/flow.js +114 -47
- package/dist/cli/init/prompter.js +8 -0
- package/dist/cli/init/telegram.js +35 -9
- package/dist/cli/service/render.js +3 -3
- package/dist/config.js +156 -131
- package/dist/index.js +107 -31
- package/dist/launcher.js +34 -7
- package/dist/providers/ccr-introspect.js +1 -8
- package/dist/providers/ccr-provider.js +19 -20
- package/dist/providers/claude-provider.js +4 -57
- package/dist/providers/prefs-sync.js +16 -59
- package/dist/providers/provider-router.js +24 -23
- package/dist/providers/spawn-settings.js +45 -0
- package/dist/providers/user-preferences.js +127 -19
- package/dist/restart-when-idle.js +27 -7
- package/dist/startup/auto-continue.js +2 -2
- package/dist/startup/auto-resume.js +3 -15
- package/dist/startup/notices.js +1 -1
- package/dist/startup/verify-token.js +4 -4
- package/dist/telegram/action-logger.js +3 -165
- package/dist/telegram/background-activity-card.js +1 -1
- package/dist/telegram/botname-settings.js +71 -125
- package/dist/telegram/client-options.js +6 -7
- package/dist/telegram/force-reply-tracker.js +55 -16
- package/dist/telegram/message-sender.js +92 -360
- package/dist/telegram/prompt-label.js +11 -5
- package/dist/telegram/streaming-turn.js +5 -7
- package/dist/telegram/table-lists.js +56 -0
- package/dist/telegram/task-list.js +4 -4
- package/dist/telegram/task-tracker.js +45 -126
- package/dist/telegram/terminal-renderer.js +1 -5
- package/dist/telegram/thread-titles.js +74 -2
- package/dist/telegram/threads-setup.js +1 -1
- package/dist/utils/admins.js +2 -2
- package/dist/utils/bot-icon.js +248 -0
- package/dist/utils/bot-token.js +8 -5
- package/dist/utils/build-info.js +3 -3
- package/dist/utils/caffeinate.js +6 -3
- package/dist/utils/claude-env.js +0 -1
- package/dist/utils/claude-version.js +2 -2
- package/dist/utils/config-home.js +3 -3
- package/dist/utils/download.js +41 -15
- package/dist/utils/exit-codes.js +11 -0
- package/dist/utils/format.js +3 -6
- package/dist/utils/home-project.js +1 -1
- package/dist/utils/idle-restart.js +1 -1
- package/dist/utils/install-mode.js +1 -1
- package/dist/utils/instance-config.js +1 -1
- package/dist/utils/instances.js +1 -1
- package/dist/utils/keyed-settings.js +2 -2
- package/dist/utils/memory-pressure.js +60 -0
- package/dist/utils/npm-version.js +2 -2
- package/dist/utils/resolve-claude-bin.js +13 -24
- package/dist/utils/respawn-backoff.js +9 -0
- package/dist/utils/stale-launcher.js +1 -1
- package/dist/utils/systemd.js +8 -8
- package/dist/utils/telegram-proxy.js +72 -0
- package/dist/utils/uploads-dir.js +27 -0
- package/dist/utils/verbosity.js +8 -8
- package/dist/utils/version-check.js +5 -5
- package/package.json +3 -4
- package/dist/bot/handlers/command/media.js +0 -197
- package/dist/bot/handlers/command/streaming-mode.js +0 -16
- package/dist/bot/handlers/message/throttle.js +0 -49
- package/dist/claude/agent-watchdog.js +0 -162
- package/dist/claude/agent.js +0 -1458
- package/dist/claude/held-query.js +0 -190
- package/dist/claude/mcp-tools.js +0 -354
- package/dist/claude/sdk-permission-gate.js +0 -77
- package/dist/claude/session-cost.js +0 -41
- package/dist/claude/system-prompt.js +0 -162
- package/dist/providers/sdk-provider.js +0 -37
- package/dist/telegram/telegraph-settings.js +0 -31
- package/dist/telegram/telegraph.js +0 -453
- package/dist/telegram/terminal-settings.js +0 -25
- package/dist/tts/tts-settings.js +0 -62
- package/dist/tts/tts.js +0 -245
- package/dist/tts/voice-reply.js +0 -78
- package/dist/utils/debug-agent.js +0 -117
- package/dist/utils/debug-watchdog.js +0 -121
- package/dist/utils/project-data-dir.js +0 -33
- package/dist/utils/reasoning-summary.js +0 -12
package/dist/bot/bot.js
CHANGED
|
@@ -9,10 +9,10 @@ import { buildSessionKey } from '../utils/session-key.js';
|
|
|
9
9
|
import { authMiddleware } from './middleware/auth.middleware.js';
|
|
10
10
|
import { adminOnly, adminOrApproverOnly } from './middleware/admin-only.js';
|
|
11
11
|
import { trackQueuedMessage, holdQueuedMessage, handleQueuedCallback, handleEditedMessage, handleLater, handleSteer, initParkedMessages, setQueuedDiverters, } from './middleware/queued-messages.js';
|
|
12
|
-
import { handleStart, handleClear,
|
|
13
|
-
import { handleMessage,
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
12
|
+
import { handleStart, handleClear, handleDir, handleDirCallback, handleInfo, handlePermissionMode, handlePermissionModeCallback, handleSuggestions, handleSuggestionsCallback, handleBotStatus, handleBotVersion, handleBotRestart, handleBotRestartCallback, handleRestartCallback, handleStartupCallback, handleUsage, handleBotUpdate, handleBotUpdateCallback, handleCancel, handleCommands, handleModelCommand, handleModelCallback, handlePrefsScopeCallback, handleProviderSwitchCallback, handleCcrCommand, handleResume, handleResumeCallback, handleHistory, handleResend, handleGate, handleProjectCommands, handleTerminal, handleFile, handleFooter, handleFooterCallback, handleBotName, handleTopic, handleBotRebuild, handleBotRebuildCallback, handleBtw, handleEffort, handleEffortCallback, handleTasks, handleTasksCallback, handleShells, handleShellsCallback, handleVerbosity, handleVerbosityCallback, } from './handlers/command.handler.js';
|
|
13
|
+
import { handleMessage, handleNativeCommand } from './handlers/message.handler.js';
|
|
14
|
+
import { handleLoop, handleLoops, handleLoopsCallback } from './handlers/loop.handler.js';
|
|
15
|
+
import { handleBranchCallback, handleBranchAcceptCommand, handleBranchDeclineCommand, handleBranchCommand, handleSpinoffCommand, branchPastRunningTurnIntoThread } from './handlers/branch.handler.js';
|
|
16
16
|
import { askBtw } from './handlers/command/btw.js';
|
|
17
17
|
import { handleNewBot, handleManagedBotCreated } from './handlers/newbot.handler.js';
|
|
18
18
|
import { handleTreeCommand, handleTreeCallback } from './handlers/tree.handler.js';
|
|
@@ -22,21 +22,33 @@ import { handleAutoApprove } from './handlers/command/auto-approve.js';
|
|
|
22
22
|
import { handleSuggestionTapCallback } from './handlers/suggestion.handler.js';
|
|
23
23
|
import { handleVoice } from './handlers/voice.handler.js';
|
|
24
24
|
import { handlePhoto, handleImageDocument, handleTextDocument } from './handlers/photo.handler.js';
|
|
25
|
-
import { handleUnsupportedVideo, handleUnsupportedMediaDocument, } from './handlers/media-fallback.js';
|
|
25
|
+
import { handleUnsupportedVideo, handleUnsupportedAudio, handleUnsupportedMediaDocument, } from './handlers/media-fallback.js';
|
|
26
26
|
import { createBatchMiddleware } from './middleware/message-batcher.js';
|
|
27
|
+
import { albumParts, createAlbumMiddleware } from './middleware/album-collector.js';
|
|
28
|
+
import { handleAlbum } from './handlers/album.handler.js';
|
|
27
29
|
import { countUpdatesInFlight } from '../restart-when-idle.js';
|
|
28
|
-
import { resolvePendingQuestion, getQuestionResponders, getQuestionOptionLabel, appendAnsweredFooter, buildAnswerConfirmation, } from '../claude/ask-user.js';
|
|
30
|
+
import { resolvePendingQuestion, getQuestionResponders, getQuestionOptionLabel, questionOwnerCloses, appendAnsweredFooter, buildAnswerConfirmation, } from '../claude/ask-user.js';
|
|
29
31
|
import { describeResponderRefusal } from '../telegram/admin-mention.js';
|
|
32
|
+
import { handleAskUserFormCallback } from '../claude/ask-user-form.js';
|
|
30
33
|
import { groupMentionMiddleware } from './middleware/group-mention.middleware.js';
|
|
31
34
|
import { groupRoleMiddleware } from './middleware/group-role.middleware.js';
|
|
32
35
|
import { trackForceReplyPrompts } from '../telegram/force-reply-tracker.js';
|
|
33
36
|
import { initThreadTitles } from '../telegram/thread-titles.js';
|
|
37
|
+
import { watchForDeletedThreads } from './deleted-threads.js';
|
|
38
|
+
import { startPtyIdleReaper } from '../claude/pty-idle-reaper.js';
|
|
39
|
+
import { handleThreadDelete, handleThreadDeleteCallback, handleThreadKeep } from './handlers/command/thread.js';
|
|
40
|
+
import { handleThreadCleanup, handleThreadCleanupCallback } from './handlers/command/cleanup.js';
|
|
41
|
+
import { handleCtrlB } from './handlers/command/background.js';
|
|
34
42
|
import { initThreadsSetup } from '../telegram/threads-setup.js';
|
|
35
43
|
import { resolvePendingPoll } from '../claude/poll-user.js';
|
|
36
44
|
import { captureSecretMessages, handleSecretCallback } from '../claude/secret-request.js';
|
|
45
|
+
import { captureTypedAnswers } from '../claude/typed-answer.js';
|
|
37
46
|
import { registerBotCommandName } from '../claude/command-parser.js';
|
|
47
|
+
import { buildCommandMenu, setCommandCatalog } from './command-catalog.js';
|
|
48
|
+
import { handleCommandFixCallback, initCommandFallback } from './handlers/command-fallback.js';
|
|
38
49
|
import { withRunningNote } from './handlers/running-note.js';
|
|
39
|
-
|
|
50
|
+
/** The toast under a button no handler knows, which is one from before an update. */
|
|
51
|
+
export const STALE_BUTTON_NOTE = 'This button is from before an update and no longer works. Send the command again.';
|
|
40
52
|
// Resolve sequentialize constraint: same-chat updates are ordered,
|
|
41
53
|
// but /cancel is registered BEFORE this middleware so it bypasses it.
|
|
42
54
|
async function handleAskUserCallback(ctx) {
|
|
@@ -56,6 +68,7 @@ async function handleAskUserCallback(ctx) {
|
|
|
56
68
|
// `A` `B` `C` with the full text in the message body, and "✅ Answered: A"
|
|
57
69
|
// is not an answer anyone can read back later.
|
|
58
70
|
const optionLabel = getQuestionOptionLabel(id, idx);
|
|
71
|
+
const ownerCloses = questionOwnerCloses(id);
|
|
59
72
|
const outcome = resolvePendingQuestion(id, idx, ctx.from?.id);
|
|
60
73
|
if (outcome === 'expired') {
|
|
61
74
|
await ctx.answerCallbackQuery({ text: 'This question already expired.' });
|
|
@@ -81,6 +94,11 @@ async function handleAskUserCallback(ctx) {
|
|
|
81
94
|
return;
|
|
82
95
|
}
|
|
83
96
|
await ctx.answerCallbackQuery();
|
|
97
|
+
// A question its asker keeps re-posting over the same message (the memory
|
|
98
|
+
// guard's "Check again") is the asker's to mark up and close; an "Answered"
|
|
99
|
+
// footer here would race its next edit.
|
|
100
|
+
if (ownerCloses)
|
|
101
|
+
return;
|
|
84
102
|
const message = ctx.callbackQuery?.message;
|
|
85
103
|
const answerText = optionLabel ?? `option ${idx + 1}`;
|
|
86
104
|
// Strip the keyboard so the user can't tap again, and mark the chosen option
|
|
@@ -149,7 +167,7 @@ export async function createBot(botInfo) {
|
|
|
149
167
|
// Awaited so the bound port is known before anything else tries to spawn a
|
|
150
168
|
// subprocess that needs to reach us.
|
|
151
169
|
await startIpcServer();
|
|
152
|
-
// Support HTTP
|
|
170
|
+
// Support an HTTP or HTTPS proxy for the Telegram API (useful in restricted networks)
|
|
153
171
|
const proxyUrl = telegramProxyUrl();
|
|
154
172
|
if (proxyUrl) {
|
|
155
173
|
// A proxy URL can carry a user and password.
|
|
@@ -162,6 +180,11 @@ export async function createBot(botInfo) {
|
|
|
162
180
|
// Note which messages are ForceReply prompts, so a reply answering one still
|
|
163
181
|
// reaches the handlers in a group that otherwise requires an @mention.
|
|
164
182
|
trackForceReplyPrompts(bot);
|
|
183
|
+
// Telegram says nothing when a thread is deleted, but a send into one fails:
|
|
184
|
+
// take that as the news, and end the session the thread had.
|
|
185
|
+
watchForDeletedThreads(bot);
|
|
186
|
+
// And end PTY claudes left idle, a thread deleted by hand among them.
|
|
187
|
+
startPtyIdleReaper();
|
|
165
188
|
// Auto-retry on transient network errors (ECONNRESET, socket hang up, etc.)
|
|
166
189
|
// Also handles 429 rate limits by respecting Telegram's retry_after
|
|
167
190
|
bot.api.config.use(autoRetry({
|
|
@@ -169,81 +192,16 @@ export async function createBot(botInfo) {
|
|
|
169
192
|
maxDelaySeconds: 60, // Cap retry delay at 60 seconds (will retry sooner rather than wait 900s)
|
|
170
193
|
rethrowInternalServerErrors: false, // Retry on 5xx errors
|
|
171
194
|
}));
|
|
172
|
-
// Register command menu for autocomplete (non-blocking)
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
{ command: 'newproject', description: '📁 Create a new project' },
|
|
177
|
-
{ command: 'newbot', description: '🤖 Create a bot for a project' },
|
|
178
|
-
{ command: 'status', description: '📊 Show current session status' },
|
|
179
|
-
{ command: 'clear', description: '🗑️ Clear conversation history' },
|
|
180
|
-
{ command: 'cancel', description: '⏹️ Stop the current request and drop anything queued' },
|
|
181
|
-
{ command: 'resume', description: '▶️ Resume a session' },
|
|
182
|
-
{ command: 'continue', description: '▶️ Continue last session' },
|
|
183
|
-
{ command: 'botstatus', description: '🩺 Show bot process status' },
|
|
184
|
-
{ command: 'version', description: '🏷️ Show the running version and whether it is the latest' },
|
|
185
|
-
{ command: 'restartbot', description: '🔁 Restart the bot' },
|
|
186
|
-
// An npm install has no source to rebuild; /update replaces it instead.
|
|
187
|
-
...(isCheckout() ? [{ command: 'rebuildbot', description: '🔄 Rebuild and restart with session restore' }] : []),
|
|
188
|
-
{ command: 'context', description: '🧠 Show Claude context usage' },
|
|
189
|
-
{ command: 'cost', description: '💰 Show usage limits and cost' },
|
|
190
|
-
{ command: 'compact', description: '🗜️ Compact the context window' },
|
|
191
|
-
{ command: 'update', description: isCheckout() ? '⬆️ Update the Claude Code CLI' : '⬆️ Update TeleCoder or the Claude Code CLI' },
|
|
192
|
-
{ command: 'plan', description: '📋 Start planning mode' },
|
|
193
|
-
{ command: 'explore', description: '🔍 Explore codebase' },
|
|
194
|
-
{ command: 'loop', description: '🔄 Run in loop mode' },
|
|
195
|
-
{ command: 'sessions', description: '📚 View saved sessions' },
|
|
196
|
-
{ command: 'fork', description: '🍴 Fork this conversation to another bot' },
|
|
197
|
-
{ command: 'spinoff', description: '🍴 Split a task off into a new thread' },
|
|
198
|
-
{ command: 'tree', description: '🌳 Show where this conversation branched, and jump between branches' },
|
|
199
|
-
{ command: 'accept', description: '📦 Accept a pending fork from another bot' },
|
|
200
|
-
{ command: 'decline', description: '🚫 Discard a pending fork' },
|
|
201
|
-
{ command: 'recap', description: '📋 Recap last messages of current session' },
|
|
202
|
-
{ command: 'prompts', description: '💬 List the prompts you sent, and branch from any of them' },
|
|
203
|
-
{ command: 'sync', description: '📨 Resend any missed reply from the session log' },
|
|
204
|
-
{ command: 'handoff', description: '📦 Export the session as a markdown handoff document' },
|
|
205
|
-
{ command: 'schedule', description: '🔔 Schedule a recurring prompt (e.g. every 1h, daily 9am)' },
|
|
206
|
-
{ command: 'schedules', description: '🔔 List active scheduled tasks' },
|
|
207
|
-
{ command: 'unschedule', description: '🔕 Remove a scheduled task by id' },
|
|
208
|
-
{ command: 'projectcommands', description: '📜 List slash commands from .claude/commands/' },
|
|
209
|
-
{ command: 'permissions', description: '🔐 Show the permission-gate state and guarded patterns' },
|
|
210
|
-
{ command: 'users', description: '👥 Show who can use this bot' },
|
|
211
|
-
{ command: 'allow', description: '✅ Let someone in — reply to them, or /allow @user' },
|
|
212
|
-
{ command: 'deny', description: '🚫 Remove someone admitted with /allow' },
|
|
213
|
-
{ command: 'members', description: '👥 Show who may prompt the agent in this group' },
|
|
214
|
-
{ command: 'teleport', description: '🚀 Move session to terminal' },
|
|
215
|
-
...(config.TRANSCRIBE_ENABLED ? [{ command: 'transcribe', description: '🎤 Transcribe audio to text' }] : []),
|
|
216
|
-
{ command: 'file', description: '📎 Download a file from project' },
|
|
217
|
-
{ command: 'telegraph', description: '📄 View markdown with Instant View' },
|
|
218
|
-
{ command: 'suggestions', description: '💡 Toggle predicted next-prompt buttons' },
|
|
219
|
-
{ command: 'model', description: '🤖 Switch AI model' },
|
|
220
|
-
{ command: 'effort', description: '🎯 Set reasoning effort level' },
|
|
221
|
-
{ command: 'verbosity', description: '🎚️ Set verbosity tier (quiet/normal/verbose/debug)' },
|
|
222
|
-
{ command: 'method', description: '🛰️ Switch Claude transport (SDK / PTY)' },
|
|
223
|
-
{ command: 'btw', description: '💬 Side question without interrupting' },
|
|
224
|
-
{ command: 'later', description: '🔔 Set an idea aside for after the turn' },
|
|
225
|
-
{ command: 'steer', description: '⚡ Stop the turn and send this instead' },
|
|
226
|
-
{ command: 'tasks', description: '🔄 List active background tasks' },
|
|
227
|
-
{ command: 'shells', description: '🔍 List & kill background shells (PTY mode)' },
|
|
228
|
-
...(config.CCR_ENABLED ? [{ command: 'provider', description: '🔌 Switch AI provider' }] : []),
|
|
229
|
-
...(config.CCR_ENABLED ? [{ command: 'ccr', description: '🔌 Toggle CCR routing (alt providers)' }] : []),
|
|
230
|
-
{ command: 'mode', description: '🔐 How much Claude asks before acting' },
|
|
231
|
-
{ command: 'autoapprove', description: '⚡ Approve guarded commands for a while' },
|
|
232
|
-
{ command: 'streaming', description: '⚙️ Toggle streaming / wait replies' },
|
|
233
|
-
{ command: 'terminalui', description: '🖥️ Toggle terminal-style display' },
|
|
234
|
-
{ command: 'statusline', description: '📍 Toggle per-turn status line' },
|
|
235
|
-
{ command: 'botname', description: '✏️ Toggle dynamic bot name' },
|
|
236
|
-
{ command: 'topic', description: '💬 Set current work topic in bot name' },
|
|
237
|
-
{ command: 'tts', description: '🔊 Toggle voice replies' },
|
|
238
|
-
{ command: 'ping', description: '🏓 Check if bot is responsive' },
|
|
239
|
-
{ command: 'commands', description: '📜 List all commands' },
|
|
240
|
-
];
|
|
195
|
+
// Register command menu for autocomplete (non-blocking). The list lives in
|
|
196
|
+
// command-catalog.ts, where /commands <search> and the typo fallback read it.
|
|
197
|
+
const commandList = buildCommandMenu();
|
|
198
|
+
setCommandCatalog(commandList);
|
|
241
199
|
bot.api.setMyCommands(commandList).then(() => {
|
|
242
200
|
console.log('📋 Command menu registered');
|
|
243
201
|
}).catch((err) => {
|
|
244
202
|
console.warn('⚠️ Failed to register commands:', err.message);
|
|
245
203
|
});
|
|
246
|
-
// Before everything else, so /
|
|
204
|
+
// Before everything else, so /botrebuild's "when idle" sees an update from
|
|
247
205
|
// the moment it arrives until its reply has gone out.
|
|
248
206
|
bot.use(countUpdatesInFlight);
|
|
249
207
|
// Apply auth middleware to all updates
|
|
@@ -254,9 +212,12 @@ export async function createBot(botInfo) {
|
|
|
254
212
|
// A project bot made by /newbot starts without threads, which only its owner
|
|
255
213
|
// can turn on: tell them how, with the first message they send it.
|
|
256
214
|
initThreadsSetup(bot);
|
|
215
|
+
// Files sent together arrive one message each: gather them into one. Ahead of
|
|
216
|
+
// the mention gate, which reads the caption only one of them carries.
|
|
217
|
+
bot.use(createAlbumMiddleware());
|
|
257
218
|
// In groups, ignore messages that aren't addressed to the bot, so people can
|
|
258
219
|
// talk to each other without triggering a turn. Runs before the command
|
|
259
|
-
// handlers below because they'd otherwise answer a `/
|
|
220
|
+
// handlers below because they'd otherwise answer a `/info@other_bot`
|
|
260
221
|
// aimed at a different bot in the same group.
|
|
261
222
|
bot.use(groupMentionMiddleware);
|
|
262
223
|
// Of the people an allow-listed group lets in, which ones may actually drive
|
|
@@ -273,6 +234,10 @@ export async function createBot(botInfo) {
|
|
|
273
234
|
// the answer can't wait in line behind it either. Commands pass, so /cancel
|
|
274
235
|
// still works.
|
|
275
236
|
bot.use(captureSecretMessages);
|
|
237
|
+
// A message sent while telecoder_ask_user waits on a tap is the answer in
|
|
238
|
+
// the user's own words, and leaves the stream here for the same reason. So
|
|
239
|
+
// does one sent at a Claude Code dialog that takes text.
|
|
240
|
+
bot.use(captureTypedAnswers);
|
|
276
241
|
// Register through `cmd` rather than `bot.command` directly so the set of
|
|
277
242
|
// names TeleCoder claims stays discoverable at runtime. Registration order
|
|
278
243
|
// and placement relative to sequentialize are unchanged — `cmd` calls
|
|
@@ -285,14 +250,12 @@ export async function createBot(botInfo) {
|
|
|
285
250
|
// These commands fire BEFORE sequentialize so they bypass per-chat ordering.
|
|
286
251
|
// This lets them interrupt, inspect, or restart even when a query is hung.
|
|
287
252
|
cmd('cancel', handleCancel);
|
|
288
|
-
cmd('
|
|
289
|
-
cmd('
|
|
290
|
-
cmd('status', withRunningNote(handleStatus));
|
|
291
|
-
cmd('version', withRunningNote(handleVersion));
|
|
253
|
+
cmd('info', withRunningNote(handleInfo));
|
|
254
|
+
cmd('botversion', withRunningNote(handleBotVersion));
|
|
292
255
|
// Lifecycle and transport are admin-only: they act on every session in the
|
|
293
256
|
// bot, not just the caller's.
|
|
294
|
-
cmd('
|
|
295
|
-
cmd('
|
|
257
|
+
cmd('botrestart', adminOnly(handleBotRestart));
|
|
258
|
+
cmd('botrebuild', adminOnly(handleBotRebuild));
|
|
296
259
|
// Access control is admin-only and bypasses sequentialize: a stranger
|
|
297
260
|
// typically turns up mid-turn, and an admin should be able to wave them in
|
|
298
261
|
// without waiting for whatever the group is already running to finish.
|
|
@@ -301,31 +264,45 @@ export async function createBot(botInfo) {
|
|
|
301
264
|
cmd('users', adminOnly(handleUsers));
|
|
302
265
|
cmd('btw', withRunningNote(handleBtw)); // Side question — must bypass queue to work mid-task
|
|
303
266
|
cmd('spinoff', handleSpinoffCommand); // Splits a task off into a new thread — bypasses the queue so it works mid-task
|
|
267
|
+
// Deletes the thread it's sent in, stopping its turn — bypasses the queue so a
|
|
268
|
+
// busy thread can still be deleted. Admin-only: in a group it takes everyone's
|
|
269
|
+
// messages with it.
|
|
270
|
+
cmd('threaddelete', adminOnly(handleThreadDelete));
|
|
271
|
+
// Deletes other threads, never the one it's sent in, and leaves alone any
|
|
272
|
+
// with a turn or messages going — so it has no reason to wait for this
|
|
273
|
+
// thread's turn. Admin-only, like /threaddelete. /threadkeep only flips a mark.
|
|
274
|
+
cmd('threadcleanup', adminOnly(handleThreadCleanup));
|
|
275
|
+
cmd('threadkeep', handleThreadKeep);
|
|
304
276
|
// Sets an idea aside for after the turn, so it can't wait behind that turn. And
|
|
305
277
|
// with nothing running, it's the one message that doesn't start one.
|
|
306
278
|
cmd('later', withRunningNote(handleLater));
|
|
307
279
|
// Stops the turn and sends a message in its place, so it can't wait behind that turn.
|
|
308
280
|
cmd('steer', handleSteer);
|
|
309
281
|
// Read-only, with nothing a running turn could be disturbed by, so they answer
|
|
310
|
-
// mid-turn rather than after it: a fixed list, a look at the
|
|
311
|
-
//
|
|
312
|
-
//
|
|
282
|
+
// mid-turn rather than after it: a fixed list, a look at the bot process, a
|
|
283
|
+
// re-read of the transcript, and one that asks a probe of its own rather
|
|
284
|
+
// than the live session. Anything that changes the session
|
|
313
285
|
// or starts a turn stays behind sequentialize below.
|
|
314
286
|
cmd('commands', withRunningNote(handleCommands));
|
|
315
|
-
cmd('sessions', withRunningNote(handleSessions));
|
|
316
287
|
cmd('botstatus', withRunningNote(handleBotStatus));
|
|
317
|
-
cmd('
|
|
288
|
+
cmd('history', withRunningNote(handleHistory));
|
|
318
289
|
cmd('projectcommands', handleProjectCommands);
|
|
319
|
-
cmd('context', withRunningNote(handleContext));
|
|
320
290
|
cmd('tasks', handleTasks); // Read-only; must bypass queue so it works mid-stream
|
|
321
|
-
cmd('
|
|
291
|
+
cmd('bashes', handleTasks); // Claude Code's alias of /tasks
|
|
292
|
+
// Claude Code's Ctrl+B: moves what the turn is waiting on to the background, so it is for mid-turn only.
|
|
293
|
+
cmd('ctrlb', handleCtrlB);
|
|
294
|
+
// Read-only probe + a peek at the live TUI panel; bypasses the queue so it
|
|
295
|
+
// answers mid-turn. Three names because Claude Code has all three: /cost
|
|
296
|
+
// and /stats are its aliases of /usage.
|
|
297
|
+
cmd('usage', withRunningNote(handleUsage));
|
|
298
|
+
cmd('cost', withRunningNote(handleUsage));
|
|
299
|
+
cmd('stats', withRunningNote(handleUsage));
|
|
322
300
|
cmd('shells', withRunningNote(handleShells)); // Lists/kills OS-level bg processes; must bypass queue to rescue hung sessions
|
|
323
301
|
cmd('members', handleMembers);
|
|
324
|
-
// /
|
|
302
|
+
// /resend exists for the "I think a reply went missing" scenario, which by
|
|
325
303
|
// definition includes hung or sluggish turns — gating it on sequentialize
|
|
326
304
|
// would queue it behind the very turn the user wants to inspect.
|
|
327
|
-
cmd('
|
|
328
|
-
cmd('handoff', handleHandoff);
|
|
305
|
+
cmd('resend', handleResend);
|
|
329
306
|
// /tree and /prompts are read-only until a button is tapped, so they answer
|
|
330
307
|
// mid-turn — "what did I just ask?" comes up while a long turn runs — and the
|
|
331
308
|
// buttons that switch conversations refuse while a reply is running.
|
|
@@ -334,17 +311,11 @@ export async function createBot(botInfo) {
|
|
|
334
311
|
// Display preferences: each only flips a stored setting that a turn reads
|
|
335
312
|
// when it starts, so changing one mid-turn applies from the next turn and
|
|
336
313
|
// has no reason to wait for this one. Their menu buttons likewise.
|
|
337
|
-
cmd('
|
|
314
|
+
cmd('footer', handleFooter);
|
|
338
315
|
cmd('verbosity', handleVerbosity);
|
|
339
|
-
cmd('terminalui', handleTerminalUI);
|
|
340
|
-
cmd('streaming', handleStreaming);
|
|
341
|
-
cmd('tts', handleTTS);
|
|
342
316
|
cmd('suggestions', handleSuggestions);
|
|
343
|
-
bot.callbackQuery(/^
|
|
317
|
+
bot.callbackQuery(/^footer:/, handleFooterCallback);
|
|
344
318
|
bot.callbackQuery(/^verbosity:/, handleVerbosityCallback);
|
|
345
|
-
bot.callbackQuery(/^terminalui:/, handleTerminalUICallback);
|
|
346
|
-
bot.callbackQuery(/^mode:/, handleModeCallback);
|
|
347
|
-
bot.callbackQuery(/^tts:/, handleTTSCallback);
|
|
348
319
|
bot.callbackQuery(/^sugg:/, handleSuggestionsCallback);
|
|
349
320
|
// The same goes for the permission mode, which a turn applies as it starts,
|
|
350
321
|
// and for the bot's and the thread's names.
|
|
@@ -352,48 +323,54 @@ export async function createBot(botInfo) {
|
|
|
352
323
|
// an alias for exactly as long as nothing better wanted it. Permission mode
|
|
353
324
|
// is what people were always going to mean by it.
|
|
354
325
|
cmd('mode', adminOnly(handlePermissionMode));
|
|
355
|
-
cmd('botname', handleBotName);
|
|
326
|
+
cmd('botname', adminOnly(handleBotName));
|
|
356
327
|
cmd('topic', handleTopic);
|
|
357
328
|
bot.callbackQuery(/^permmode:/, adminOnly(handlePermissionModeCallback));
|
|
358
|
-
bot.callbackQuery(/^botname:/, handleBotNameCallback);
|
|
359
329
|
// An auto-approve window matters most mid-turn: that's when the prompts it
|
|
360
330
|
// answers are turning up, and closing one can't wait for the turn either.
|
|
361
331
|
// Admins *and* approvers: opening a window is a decision about prompts, not
|
|
362
332
|
// a power over the bot, so it sits with the people who answer them.
|
|
363
333
|
cmd('autoapprove', adminOrApproverOnly(handleAutoApprove));
|
|
364
|
-
cmd('
|
|
365
|
-
// Nothing here touches the session: a welcome text, a file sent from disk
|
|
366
|
-
//
|
|
334
|
+
cmd('gate', adminOnly(handleGate));
|
|
335
|
+
// Nothing here touches the session: a welcome text, a file sent from disk,
|
|
336
|
+
// and a new bot, which is a process of its own.
|
|
367
337
|
cmd('start', handleStart);
|
|
368
338
|
cmd('file', handleFile);
|
|
369
|
-
cmd('telegraph', handleTelegraph);
|
|
370
|
-
bot.callbackQuery(/^telegraph:/, handleTelegraphCallback);
|
|
371
339
|
// Creating a bot adds a process to the launcher and a token to instances.json.
|
|
372
340
|
cmd('newbot', adminOnly(handleNewBot));
|
|
373
|
-
//
|
|
374
|
-
// when a
|
|
375
|
-
//
|
|
376
|
-
|
|
377
|
-
cmd('
|
|
378
|
-
cmd('
|
|
341
|
+
// Loop commands bypass sequentialize so they remain responsive even
|
|
342
|
+
// when a loop's turn is already running (the cap-enforcing create, the
|
|
343
|
+
// list and its stop buttons all need to work mid-stream). /proactive is
|
|
344
|
+
// Claude Code's alias of /loop.
|
|
345
|
+
cmd('loop', handleLoop);
|
|
346
|
+
cmd('proactive', handleLoop);
|
|
347
|
+
cmd('loops', handleLoops);
|
|
348
|
+
bot.callbackQuery(/^loops:/, handleLoopsCallback);
|
|
379
349
|
// /tasks inline-keyboard buttons (view/back/refresh) also need to bypass
|
|
380
350
|
// sequentialize so they're responsive while a stream is active.
|
|
381
351
|
bot.callbackQuery(/^tasks:/, handleTasksCallback);
|
|
382
352
|
// /shells kill buttons must also bypass sequentialize — the whole point is to
|
|
383
353
|
// rescue a session whose current turn is hung waiting on a bg shell.
|
|
384
354
|
bot.callbackQuery(/^shells:/, handleShellsCallback);
|
|
355
|
+
// "Did you mean" buttons under a mistyped command. Before sequentialize: the
|
|
356
|
+
// tap only re-sends the message, which then waits its turn like any other.
|
|
357
|
+
bot.callbackQuery(/^cmdfix:/, handleCommandFixCallback);
|
|
358
|
+
bot.callbackQuery(/^threaddelete:/, adminOnly(handleThreadDeleteCallback));
|
|
359
|
+
bot.callbackQuery(/^threadcleanup:/, adminOnly(handleThreadCleanupCallback));
|
|
385
360
|
// telecoder_ask_user button taps MUST bypass sequentialize: the agent
|
|
386
361
|
// query is mid-flight and waiting on this exact tap to complete the tool
|
|
387
362
|
// call. If the callback got queued, it'd deadlock behind the query that's
|
|
388
363
|
// waiting for it.
|
|
389
364
|
bot.callbackQuery(/^q:/, handleAskUserCallback);
|
|
365
|
+
// A multi-question form's option, jump and Submit buttons, for the same reason.
|
|
366
|
+
bot.callbackQuery(/^qf:/, handleAskUserFormCallback);
|
|
390
367
|
// The Cancel button under a secret request, for the same reason.
|
|
391
368
|
bot.callbackQuery(/^secret:/, handleSecretCallback);
|
|
392
|
-
// /
|
|
369
|
+
// /branch callbacks bypass sequentialize too: the user often taps Branch on a
|
|
393
370
|
// past message while a turn is running. Picker UI is non-destructive (it
|
|
394
371
|
// just shows another message), and accept/decline operate on file state,
|
|
395
372
|
// not the live agent, so they don't need to wait in line.
|
|
396
|
-
bot.callbackQuery(/^
|
|
373
|
+
bot.callbackQuery(/^branch:/, handleBranchCallback);
|
|
397
374
|
// /tree's buttons likewise: opening a point only redraws the message, and
|
|
398
375
|
// carrying on a branch or branching from a point checks for a running reply
|
|
399
376
|
// itself, so a tap mid-turn gets an answer instead of waiting in line.
|
|
@@ -408,16 +385,17 @@ export async function createBot(botInfo) {
|
|
|
408
385
|
// so it can't wait in line itself.
|
|
409
386
|
bot.on('edited_message', handleEditedMessage);
|
|
410
387
|
initParkedMessages(bot);
|
|
411
|
-
|
|
412
|
-
|
|
388
|
+
initCommandFallback(bot);
|
|
389
|
+
setQueuedDiverters({ btw: askBtw, branch: branchPastRunningTurnIntoThread });
|
|
390
|
+
// Menu buttons for /botrestart and /botrebuild must bypass sequentialize
|
|
413
391
|
// for the same reason their parent commands do: users tap these precisely
|
|
414
392
|
// when the bot is hung, so the callback can't be queued behind the stuck
|
|
415
393
|
// request.
|
|
416
394
|
// Access cards: same reasoning as the commands above — the card lands while
|
|
417
395
|
// a turn is running, and it is the fastest way to answer it.
|
|
418
396
|
bot.callbackQuery(/^access:/, adminOnly(handleAccessCallback));
|
|
419
|
-
bot.callbackQuery(/^
|
|
420
|
-
bot.callbackQuery(/^
|
|
397
|
+
bot.callbackQuery(/^botrestart:/, adminOnly(handleBotRestartCallback));
|
|
398
|
+
bot.callbackQuery(/^botrebuild:/, adminOnly(handleBotRebuildCallback));
|
|
421
399
|
// Batch consecutive text messages BEFORE sequentialize.
|
|
422
400
|
// When Telegram splits a long paste into multiple messages, this combines
|
|
423
401
|
// them into a single prompt. Must run before sequentialize because that
|
|
@@ -433,47 +411,62 @@ export async function createBot(botInfo) {
|
|
|
433
411
|
bot.use(sequentialize(getSequentializeKey));
|
|
434
412
|
bot.use(holdQueuedMessage);
|
|
435
413
|
// Bot command handlers (sequentialized per chat)
|
|
414
|
+
//
|
|
415
|
+
// Where the bot has a command of Claude Code's, it answers to Claude Code's
|
|
416
|
+
// aliases of it too, so that /new does what /clear does rather than
|
|
417
|
+
// reaching Claude Code past the bot's bookkeeping.
|
|
436
418
|
cmd('clear', handleClear);
|
|
419
|
+
cmd('reset', handleClear);
|
|
420
|
+
cmd('new', handleClear);
|
|
437
421
|
// Admin-only now that a group can hold contributors: repointing the bot
|
|
438
|
-
// moves everyone's session, and /
|
|
422
|
+
// moves everyone's session, and /terminal and /gate reach the
|
|
439
423
|
// guardrails rather than the conversation.
|
|
440
|
-
cmd('
|
|
441
|
-
cmd('newproject', adminOnly(handleNewProject));
|
|
424
|
+
cmd('dir', adminOnly(handleDir));
|
|
442
425
|
// /compact is a native Claude Code slash command, not a bot command — route it
|
|
443
426
|
// through the normal message pipeline (handleMessage), which forwards it to
|
|
444
|
-
// the active provider
|
|
445
|
-
//
|
|
446
|
-
//
|
|
447
|
-
//
|
|
427
|
+
// the active provider; the pty runs the real compaction and reports the token
|
|
428
|
+
// reduction. Registering it here (rather than relying on fall-through to the
|
|
429
|
+
// text handler) makes dispatch explicit and lets grammY match the group-chat
|
|
430
|
+
// `/compact@BotName` form.
|
|
448
431
|
cmd('compact', handleMessage, { forwardsToAgent: true });
|
|
449
|
-
|
|
432
|
+
// /context is Claude Code's own, routed the same way: the chat's claude
|
|
433
|
+
// reports what fills its context window, MCP tools and skills included,
|
|
434
|
+
// and the reply is the markdown copy of that report it logs (see
|
|
435
|
+
// commandReplyIn). Like any prompt, it waits for a running turn.
|
|
436
|
+
cmd('context', handleMessage, { forwardsToAgent: true });
|
|
437
|
+
// /rewind is Claude Code's own as well. Its two screens, the prompt to go
|
|
438
|
+
// back to and what to restore, come to the chat through the dialog relay,
|
|
439
|
+
// and rewind.ts reports what was restored, since the command itself prints
|
|
440
|
+
// nothing.
|
|
441
|
+
cmd('rewind', handleMessage, { forwardsToAgent: true });
|
|
442
|
+
cmd('undo', handleMessage, { forwardsToAgent: true });
|
|
443
|
+
cmd('checkpoint', handleMessage, { forwardsToAgent: true });
|
|
444
|
+
// /cd is Claude Code's too: it moves the session to another directory, and
|
|
445
|
+
// the bot follows through the CwdChanged hook (session-move.ts). Registered
|
|
446
|
+
// so the typo fallback, which would take it for /cc, lets it through.
|
|
447
|
+
cmd('cd', handleMessage, { forwardsToAgent: true });
|
|
448
|
+
// /cc <command> is the way past a bot command to Claude Code's own of the
|
|
449
|
+
// same name: `/cc model`, `/cc usage`. What goes to the agent is the
|
|
450
|
+
// command named, so it counts as forwarded, not as a command of the bot's.
|
|
451
|
+
cmd('cc', handleNativeCommand, { forwardsToAgent: true });
|
|
452
|
+
cmd('botupdate', adminOnly(handleBotUpdate));
|
|
450
453
|
cmd('model', handleModelCommand);
|
|
451
454
|
cmd('effort', handleEffort);
|
|
452
|
-
cmd('method', adminOnly(handleMethodCommand));
|
|
453
|
-
if (config.CCR_ENABLED) {
|
|
454
|
-
cmd('provider', adminOnly(handleProviderCommand));
|
|
455
|
-
}
|
|
456
455
|
if (config.CCR_ENABLED) {
|
|
457
456
|
cmd('ccr', adminOnly(handleCcrCommand));
|
|
458
457
|
}
|
|
459
|
-
cmd('plan', handlePlan);
|
|
460
|
-
cmd('explore', handleExplore);
|
|
461
458
|
// Session resume commands
|
|
462
459
|
cmd('resume', handleResume);
|
|
463
|
-
cmd('continue',
|
|
464
|
-
//
|
|
460
|
+
cmd('continue', handleResume); // Claude Code's alias of /resume
|
|
461
|
+
// /branch copies the conversation as it stands; /branchaccept and /branchdecline are the
|
|
465
462
|
// slash-command equivalents of the target-side inline buttons.
|
|
466
|
-
cmd('
|
|
467
|
-
cmd('
|
|
468
|
-
cmd('
|
|
469
|
-
//
|
|
470
|
-
|
|
471
|
-
//
|
|
472
|
-
cmd('
|
|
473
|
-
// Transcribe
|
|
474
|
-
if (config.TRANSCRIBE_ENABLED) {
|
|
475
|
-
cmd('transcribe', handleTranscribe);
|
|
476
|
-
}
|
|
463
|
+
cmd('branch', handleBranchCommand);
|
|
464
|
+
cmd('branchaccept', handleBranchAcceptCommand);
|
|
465
|
+
cmd('branchdecline', handleBranchDeclineCommand);
|
|
466
|
+
// The command line that carries a session on in a terminal. Not /teleport:
|
|
467
|
+
// that name is Claude Code's own (send a session to the cloud, or resume one
|
|
468
|
+
// from claude.ai), and a bot command of that name would keep it out of reach.
|
|
469
|
+
cmd('terminal', adminOnly(handleTerminal));
|
|
477
470
|
// Callback query handler for inline keyboards
|
|
478
471
|
bot.on('callback_query:data', async (ctx) => {
|
|
479
472
|
const data = ctx.callbackQuery.data;
|
|
@@ -483,20 +476,14 @@ export async function createBot(botInfo) {
|
|
|
483
476
|
else if (data.startsWith('provider_switch:')) {
|
|
484
477
|
await adminOnly(handleProviderSwitchCallback)(ctx);
|
|
485
478
|
}
|
|
486
|
-
else if (data.startsWith('
|
|
487
|
-
await
|
|
488
|
-
}
|
|
489
|
-
else if (data.startsWith('prefs_all:')) {
|
|
490
|
-
await handlePrefsAllCallback(ctx);
|
|
479
|
+
else if (data.startsWith('pscope:')) {
|
|
480
|
+
await handlePrefsScopeCallback(ctx);
|
|
491
481
|
}
|
|
492
482
|
else if (data.startsWith('model:')) {
|
|
493
483
|
await handleModelCallback(ctx);
|
|
494
484
|
}
|
|
495
|
-
else if (data.startsWith('
|
|
496
|
-
await
|
|
497
|
-
}
|
|
498
|
-
else if (data.startsWith('project:')) {
|
|
499
|
-
await adminOnly(handleProjectCallback)(ctx);
|
|
485
|
+
else if (data.startsWith('dir:')) {
|
|
486
|
+
await adminOnly(handleDirCallback)(ctx);
|
|
500
487
|
}
|
|
501
488
|
else if (data.startsWith('restart:')) {
|
|
502
489
|
await handleRestartCallback(ctx);
|
|
@@ -504,21 +491,20 @@ export async function createBot(botInfo) {
|
|
|
504
491
|
else if (data.startsWith('startup:')) {
|
|
505
492
|
await handleStartupCallback(ctx);
|
|
506
493
|
}
|
|
507
|
-
else if (data.startsWith('
|
|
508
|
-
await adminOnly(
|
|
494
|
+
else if (data.startsWith('botupdate:')) {
|
|
495
|
+
await adminOnly(handleBotUpdateCallback)(ctx);
|
|
509
496
|
}
|
|
510
497
|
else if (data.startsWith('effort:')) {
|
|
511
498
|
await handleEffortCallback(ctx);
|
|
512
499
|
}
|
|
513
|
-
else if (data.startsWith('method:')) {
|
|
514
|
-
await adminOnly(handleMethodCallback)(ctx);
|
|
515
|
-
}
|
|
516
|
-
else if (data.startsWith('ccr_throttle:')) {
|
|
517
|
-
await handleCcrThrottleCallback(ctx);
|
|
518
|
-
}
|
|
519
500
|
else if (data.startsWith('sgt:')) {
|
|
520
501
|
await handleSuggestionTapCallback(ctx);
|
|
521
502
|
}
|
|
503
|
+
else {
|
|
504
|
+
// Nothing answers to this button: it is on a message from a build that
|
|
505
|
+
// named its buttons differently. Say so rather than leave the tap spinning.
|
|
506
|
+
await ctx.answerCallbackQuery({ text: STALE_BUTTON_NOTE }).catch(() => { });
|
|
507
|
+
}
|
|
522
508
|
// Note: `tasks:` callback queries are handled by the pre-sequentialize
|
|
523
509
|
// bot.callbackQuery handler above so they remain responsive mid-stream.
|
|
524
510
|
});
|
|
@@ -539,28 +525,23 @@ export async function createBot(botInfo) {
|
|
|
539
525
|
// The bot a /newbot button created. The handler checks for an admin itself,
|
|
540
526
|
// and quietly: anyone with a t.me/newbot link can create one.
|
|
541
527
|
bot.on('message:managed_bot_created', handleManagedBotCreated);
|
|
528
|
+
// Files sent together, gathered by the album collector, whatever kind its
|
|
529
|
+
// first part is: ahead of the handlers that would take that part alone.
|
|
530
|
+
bot.filter((ctx) => albumParts(ctx.message) !== undefined, handleAlbum);
|
|
542
531
|
// Handle voice messages
|
|
543
532
|
bot.on('message:voice', handleVoice);
|
|
544
|
-
//
|
|
545
|
-
|
|
533
|
+
// Audio files (music, recordings — not voice notes) have no ingestion path;
|
|
534
|
+
// the handler says so rather than dropping them.
|
|
535
|
+
bot.on('message:audio', handleUnsupportedAudio);
|
|
546
536
|
// Handle images
|
|
547
537
|
bot.on('message:photo', handlePhoto);
|
|
548
538
|
// Handle documents: route by MIME type
|
|
549
|
-
//
|
|
550
|
-
//
|
|
551
|
-
// anything else
|
|
539
|
+
// image/* → image vision
|
|
540
|
+
// audio/*, video/* → explained as unsupported
|
|
541
|
+
// anything else → read as text/PDF/etc.
|
|
552
542
|
bot.on('message:document', async (ctx) => {
|
|
553
543
|
const doc = ctx.message?.document;
|
|
554
544
|
const mime = doc?.mime_type ?? '';
|
|
555
|
-
// Try transcribe-document path first (audio MIME + reply to ForceReply)
|
|
556
|
-
const replyTo = ctx.message?.reply_to_message;
|
|
557
|
-
if (replyTo && replyTo.from?.is_bot && mime.startsWith('audio/')) {
|
|
558
|
-
const replyText = replyTo.text || '';
|
|
559
|
-
if (replyText.includes('Transcribe Audio')) {
|
|
560
|
-
await handleTranscribeDocument(ctx);
|
|
561
|
-
return;
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
545
|
if (mime.startsWith('image/')) {
|
|
565
546
|
await handleImageDocument(ctx);
|
|
566
547
|
return;
|