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
|
@@ -1,142 +1,43 @@
|
|
|
1
1
|
import { sessionManager } from '../../claude/session-manager.js';
|
|
2
|
-
import {
|
|
2
|
+
import { getCachedUsage, getActiveProviderName } from '../../providers/provider-router.js';
|
|
3
|
+
import { userPreferences } from '../../providers/user-preferences.js';
|
|
4
|
+
import { describeModelId, isPremiumModel, PREMIUM_MODEL_ICON } from '../../claude/model-catalog.js';
|
|
3
5
|
import { config } from '../../config.js';
|
|
4
6
|
import { messageSender } from '../../telegram/message-sender.js';
|
|
5
|
-
import { closeTurn, relayCatchUpIfMissed } from './message/turn-notify.js';
|
|
6
|
-
import { getUptimeFormatted } from '../middleware/stale-filter.js';
|
|
7
7
|
import { getAvailableCommands } from '../../claude/command-parser.js';
|
|
8
|
-
import { isProcessing
|
|
9
|
-
import { createTelegraphFromFile } from '../../telegram/telegraph.js';
|
|
8
|
+
import { isProcessing } from '../../claude/request-queue.js';
|
|
10
9
|
import { EntityText, joinMessages, trimMessage } from '../../telegram/entities.js';
|
|
11
10
|
import { replyFormatted, replyParts } from '../../telegram/send.js';
|
|
12
|
-
import {
|
|
13
|
-
import { contextHealthColor, fmtTokens, getProgressBar } from '../../utils/format.js';
|
|
11
|
+
import { fmtTokens } from '../../utils/format.js';
|
|
14
12
|
import * as path from 'path';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import { resolveClaudeExecutableForMethod } from '../../utils/resolve-claude-bin.js';
|
|
18
|
-
import { getActiveMethod } from '../../providers/claude-provider.js';
|
|
13
|
+
import { resolveShareableFile } from '../file-access.js';
|
|
14
|
+
import { resolvePtyClaudeBin } from '../../utils/resolve-claude-bin.js';
|
|
19
15
|
import { contextTokens } from '../../providers/types.js';
|
|
20
16
|
import { stopTurn } from '../middleware/queued-messages.js';
|
|
21
17
|
import { groupAvailableCommands } from '../../claude/available-commands.js';
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
18
|
+
import { buildCommandSearchMessage, searchCommands } from '../command-catalog.js';
|
|
19
|
+
import { getSessionKeyFromCtx } from '../../utils/session-key.js';
|
|
20
|
+
import { replyMd, getEffortLabel, effortLevelLabel, withBackToPrevious } from './command/shared.js';
|
|
24
21
|
import { getSessionTopic } from './command/topic.js';
|
|
22
|
+
import { describeSource } from './command/prefs-scope.js';
|
|
25
23
|
import { describeRole } from './command/access.js';
|
|
26
24
|
import { requireActiveSession } from './session-guard.js';
|
|
27
|
-
import { progressCallbacks, withStreamingTurn } from '../../telegram/streaming-turn.js';
|
|
28
25
|
// Re-exported so the modules that already import from this file keep working
|
|
29
26
|
// while the command handlers are split out domain by domain.
|
|
30
27
|
export { parseCallback, projectStatusSuffix, resumeCommandMessage, truncateToBytes, getEffortLabel, withBackToPrevious, } from './command/shared.js';
|
|
31
|
-
export { setSessionTopic, getSessionTopic, getMsSinceTopicSet,
|
|
32
|
-
export {
|
|
28
|
+
export { setSessionTopic, getSessionTopic, getMsSinceTopicSet, clearTopic, restoreTopic, handleTopic, } from './command/topic.js';
|
|
29
|
+
export { handleBotName } from './command/botname.js';
|
|
33
30
|
export { handleAllow, handleDeny, handleMembers } from './command/access.js';
|
|
34
|
-
export {
|
|
35
|
-
export { handleCost, parseCostOutput } from './command/cost.js';
|
|
31
|
+
export { handleUsage, parseCostOutput } from './command/usage.js';
|
|
36
32
|
export { handleTasks, handleTasksCallback, handleShells, handleShellsCallback } from './command/tasks.js';
|
|
37
33
|
export { handleBtw, btwLabel, formatSideAnswer } from './command/btw.js';
|
|
38
|
-
|
|
39
|
-
export {
|
|
40
|
-
export {
|
|
41
|
-
export { handleClear, handleClearCallback, handleContinue, handleRecap, handleHandoff, handleSync, handleSessions, handleTeleport, } from './command/session.js';
|
|
34
|
+
export { handleDir, handleDirCallback, } from './command/project.js';
|
|
35
|
+
export { handleBotUpdate, handleBotUpdateCallback, handleBotStatus, handleBotVersion, handleBotRestart, handleBotRestartCallback, handleRestartCallback, handleStartupCallback, handleBotRebuild, handleBotRebuildCallback, } from './command/admin.js';
|
|
36
|
+
export { handleClear, handleHistory, handleResend, handleTerminal, } from './command/session.js';
|
|
42
37
|
export { handleResume, handleResumeCallback } from './command/resume.js';
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
export {
|
|
46
|
-
export { handleModelCommand, handleModelCallback, handleProviderCommand, handleCcrCommand, handleProviderCallback, handleProviderSwitchCallback, } from './command/model.js';
|
|
47
|
-
export { handlePrefsAllCallback } from './command/prefs-scope.js';
|
|
48
|
-
export function parseContextOutput(raw) {
|
|
49
|
-
const trimmed = raw.trim();
|
|
50
|
-
if (!trimmed) {
|
|
51
|
-
return '⚠️ No context output received.';
|
|
52
|
-
}
|
|
53
|
-
const lines = trimmed
|
|
54
|
-
.split('\n')
|
|
55
|
-
.map((line) => line.trim())
|
|
56
|
-
.filter((line) => line.length > 0);
|
|
57
|
-
let model = '';
|
|
58
|
-
let tokensLine = '';
|
|
59
|
-
const categories = [];
|
|
60
|
-
let inCategories = false;
|
|
61
|
-
for (const line of lines) {
|
|
62
|
-
if (/^model:/i.test(line)) {
|
|
63
|
-
model = line.replace(/^model:/i, '').trim();
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
if (/^tokens:/i.test(line)) {
|
|
67
|
-
tokensLine = line.replace(/^tokens:/i, '').trim();
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
if (/estimated usage by category/i.test(line)) {
|
|
71
|
-
inCategories = true;
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
if (inCategories) {
|
|
75
|
-
if (/^category/i.test(line))
|
|
76
|
-
continue;
|
|
77
|
-
if (/^-+$/.test(line))
|
|
78
|
-
continue;
|
|
79
|
-
const match = line.match(/^(.+?)\s{2,}([0-9.,kKmM]+)\s+([0-9.,]+%)$/);
|
|
80
|
-
if (match) {
|
|
81
|
-
categories.push({ name: match[1].trim(), tokens: match[2], percent: match[3] });
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
const parts = line.split(/\s+/);
|
|
85
|
-
if (parts.length >= 3 && parts[parts.length - 1].endsWith('%')) {
|
|
86
|
-
const percent = parts.pop();
|
|
87
|
-
const tokens = parts.pop();
|
|
88
|
-
const name = parts.join(' ');
|
|
89
|
-
categories.push({ name, tokens, percent });
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (!model && !tokensLine && categories.length === 0) {
|
|
94
|
-
return `## 🧠 Context Usage\n\n\`\`\`\n${trimmed}\n\`\`\``;
|
|
95
|
-
}
|
|
96
|
-
let output = '## 🧠 Context Usage';
|
|
97
|
-
if (model)
|
|
98
|
-
output += `\n- **Model:** ${model}`;
|
|
99
|
-
if (tokensLine)
|
|
100
|
-
output += `\n- **Tokens:** ${tokensLine}`;
|
|
101
|
-
if (categories.length > 0) {
|
|
102
|
-
output += '\n\n### Estimated usage by category';
|
|
103
|
-
for (const category of categories) {
|
|
104
|
-
output += `\n- **${category.name}:** ${category.tokens} (${category.percent})`;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
output += '\n\n_If this looks stale, send a new message then run /context again._';
|
|
108
|
-
return output;
|
|
109
|
-
}
|
|
110
|
-
const SESSION_ID_RE = /^[a-zA-Z0-9_-]{8,128}$/;
|
|
111
|
-
async function runClaudeContext(sessionId, cwd) {
|
|
112
|
-
if (!SESSION_ID_RE.test(sessionId)) {
|
|
113
|
-
throw new Error('Invalid session ID format');
|
|
114
|
-
}
|
|
115
|
-
return new Promise((resolve, reject) => {
|
|
116
|
-
execFile(
|
|
117
|
-
// Match the binary PTY mode spawns — CLAUDE_BIN and CLAUDE_EXECUTABLE_PATH
|
|
118
|
-
// can point at different installs, and this resumes a PTY-written session.
|
|
119
|
-
process.env.CLAUDE_BIN || config.CLAUDE_EXECUTABLE_PATH,
|
|
120
|
-
// --fork-session + --no-session-persistence are load-bearing: a bare
|
|
121
|
-
// `-p --resume <id>` CONTINUES that session and appends its own turn to
|
|
122
|
-
// the JSONL. In PTY mode <id> is the *live* session, so /context would
|
|
123
|
-
// inject a stray turn into the real conversation while the pty process
|
|
124
|
-
// is writing the same file.
|
|
125
|
-
['-p', '--resume', sessionId, '--fork-session', '--no-session-persistence', '/context'], {
|
|
126
|
-
cwd,
|
|
127
|
-
timeout: 20_000,
|
|
128
|
-
maxBuffer: 1024 * 1024,
|
|
129
|
-
env: process.env,
|
|
130
|
-
}, (error, stdout, stderr) => {
|
|
131
|
-
if (error) {
|
|
132
|
-
const message = (stderr || error.message).trim();
|
|
133
|
-
reject(new Error(message || 'Failed to run /context'));
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
resolve((stdout || stderr || '').trim());
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
}
|
|
38
|
+
export { handlePermissionMode, handlePermissionModeCallback, handleEffort, handleEffortCallback, handleVerbosity, handleVerbosityCallback, handleSuggestions, handleSuggestionsCallback, handleFooter, handleFooterCallback, sendStatusLine, } from './command/settings.js';
|
|
39
|
+
export { handleModelCommand, handleModelCallback, handleCcrCommand, handleProviderSwitchCallback, } from './command/model.js';
|
|
40
|
+
export { handlePrefsScopeCallback } from './command/prefs-scope.js';
|
|
140
41
|
export async function handleStart(ctx) {
|
|
141
42
|
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
142
43
|
const effortLabel = keyInfo ? (getEffortLabel(keyInfo.sessionKey) ?? 'Default') : 'Default';
|
|
@@ -144,49 +45,52 @@ export async function handleStart(ctx) {
|
|
|
144
45
|
.add('👋 ').bold('Welcome to TeleCoder!')
|
|
145
46
|
.add('\n\nI bridge your messages to Claude Code running on your local machine.\n\n')
|
|
146
47
|
.bold('Getting Started:')
|
|
147
|
-
.add('\n1. Set your project directory with ').code('/
|
|
48
|
+
.add('\n1. Set your project directory with ').code('/dir /path/to/project')
|
|
148
49
|
.add('\n2. Start chatting with Claude about your code!\n\n')
|
|
149
50
|
.bold('Commands:')
|
|
150
|
-
.add('\n• ').code('/
|
|
151
|
-
.add('\n• ').code('/newproject <name>').add(' - Create a new project')
|
|
51
|
+
.add('\n• ').code('/dir <path>').add(' - Open a project')
|
|
152
52
|
.add('\n• ').code('/clear').add(' - Clear session and start fresh')
|
|
153
|
-
.add('\n• ').code('/
|
|
154
|
-
.add('\n• ').code('/commands').add(' - Show all
|
|
155
|
-
.add(`\n\
|
|
156
|
-
if (isDangerousMode()) {
|
|
157
|
-
welcome.add('\n\n⚠️ ').bold('DANGEROUS MODE ENABLED').add(' - All tool permissions auto-approved');
|
|
158
|
-
}
|
|
53
|
+
.add('\n• ').code('/info').add(' - Show current session info')
|
|
54
|
+
.add('\n• ').code('/commands').add(' - Show all commands; ').code('/commands <words>').add(' searches them')
|
|
55
|
+
.add(`\n\nEffort: ${effortLabel}`);
|
|
159
56
|
const currentConv = keyInfo
|
|
160
57
|
? sessionManager.getSession(keyInfo.sessionKey)?.conversationId
|
|
161
58
|
: undefined;
|
|
162
59
|
const back = withBackToPrevious(welcome.build(), keyInfo?.sessionKey, currentConv);
|
|
163
60
|
await replyFormatted(ctx, back.text, back.options);
|
|
164
61
|
}
|
|
165
|
-
export async function
|
|
62
|
+
export async function handleInfo(ctx) {
|
|
166
63
|
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
167
64
|
if (!keyInfo) {
|
|
168
|
-
await ctx.reply('❌ Could not determine chat context for /
|
|
65
|
+
await ctx.reply('❌ Could not determine chat context for /info.');
|
|
169
66
|
return;
|
|
170
67
|
}
|
|
171
68
|
try {
|
|
172
69
|
const { sessionKey } = keyInfo;
|
|
173
|
-
const { chatId } = parseSessionKey(sessionKey);
|
|
174
70
|
const session = sessionManager.getSession(sessionKey);
|
|
175
71
|
if (!session) {
|
|
176
|
-
await replyMd(ctx, 'ℹ️ No active session.\n\nUse `/
|
|
72
|
+
await replyMd(ctx, 'ℹ️ No active session.\n\nUse `/dir /path/to/project` to get started.');
|
|
177
73
|
return;
|
|
178
74
|
}
|
|
179
|
-
const currentModel = getModel(sessionKey);
|
|
180
75
|
const provider = getActiveProviderName(sessionKey);
|
|
181
|
-
const dangerousMode = isDangerousMode() ? '⚠️ ENABLED' : 'Disabled';
|
|
182
|
-
const effortLabel = getEffortLabel(sessionKey) ?? 'Default';
|
|
183
76
|
const topic = getSessionTopic(sessionKey);
|
|
184
77
|
const projectName = path.basename(session.workingDirectory);
|
|
185
|
-
// On CCR, the
|
|
78
|
+
// On CCR, the model alias doesn't reflect which backend actually served
|
|
186
79
|
// the turn — CCR picks per-request based on its router config. We
|
|
187
80
|
// don't try to discover the true backend (would require log parsing).
|
|
188
81
|
// The "Provider: ccr" line below already signals the routing.
|
|
189
82
|
const cached = getCachedUsage(sessionKey);
|
|
83
|
+
// Effort and model are what the session log says the last reply ran with,
|
|
84
|
+
// each followed by who picked it: the chat, with /effort or /model, or
|
|
85
|
+
// Claude Code. Before the first reply the log has nothing, and saying so
|
|
86
|
+
// beats a bare "Default" that could mean either.
|
|
87
|
+
const chosenEffort = getEffortLabel(sessionKey);
|
|
88
|
+
const askedModel = userPreferences.getModel(sessionKey);
|
|
89
|
+
// The cache's model falls back on the asked-for alias and then on a
|
|
90
|
+
// placeholder when the log names none; neither is a model that served.
|
|
91
|
+
const servedModel = cached?.model && cached.model !== askedModel && cached.model !== 'Claude Code default'
|
|
92
|
+
? cached.model
|
|
93
|
+
: undefined;
|
|
190
94
|
const status = new EntityText().add('📊 ').bold('Session Status').add('\n');
|
|
191
95
|
// One `emoji *Label:* value` line; the value is added by the caller.
|
|
192
96
|
const field = (emoji, label) => status.add(`\n${emoji} `).bold(`${label}:`).add(' ');
|
|
@@ -196,15 +100,35 @@ export async function handleStatus(ctx) {
|
|
|
196
100
|
field('🏷️', 'Topic').add(topic);
|
|
197
101
|
else
|
|
198
102
|
field('🏷️', 'Topic').italic('none');
|
|
199
|
-
field('🎚️', 'Effort')
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
103
|
+
field('🎚️', 'Effort');
|
|
104
|
+
if (chosenEffort)
|
|
105
|
+
status.add(chosenEffort).add(' ').italic(`(${describeSource(sessionKey, 'effort')} with /effort)`);
|
|
106
|
+
else if (cached?.effort)
|
|
107
|
+
status.add(effortLevelLabel(cached.effort)).add(' ').italic("(Claude Code's default)");
|
|
108
|
+
else
|
|
109
|
+
status.italic("Claude Code's default — known after the first reply");
|
|
110
|
+
field('🧠', 'Model');
|
|
111
|
+
if (servedModel) {
|
|
112
|
+
const name = describeModelId(servedModel);
|
|
113
|
+
if (isPremiumModel(servedModel))
|
|
114
|
+
status.add(`${PREMIUM_MODEL_ICON} `);
|
|
115
|
+
status.add(name);
|
|
116
|
+
if (name !== servedModel)
|
|
117
|
+
status.add(' ').code(servedModel);
|
|
118
|
+
if (provider === 'ccr')
|
|
119
|
+
status.add(' ').italic('(routed via CCR)');
|
|
120
|
+
else if (askedModel)
|
|
121
|
+
status.add(' ').italic(`(${describeSource(sessionKey, 'model')} with /model ${askedModel})`);
|
|
122
|
+
else
|
|
123
|
+
status.add(' ').italic("(Claude Code's default)");
|
|
124
|
+
}
|
|
125
|
+
else if (askedModel) {
|
|
126
|
+
status.code(askedModel).add(' ').italic(`(${describeSource(sessionKey, 'model')}, serving from the next reply)`);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
status.italic("Claude Code's default — known after the first reply");
|
|
130
|
+
}
|
|
203
131
|
field('🔌', 'Provider').add(provider);
|
|
204
|
-
field('🆔', 'Session ID').code(session.claudeSessionId ?? session.conversationId);
|
|
205
|
-
field('📁', 'Working Directory').code(session.workingDirectory);
|
|
206
|
-
field('📡', 'Mode').add(config.STREAMING_MODE);
|
|
207
|
-
field(isDangerousMode() ? '⚠️' : '🛡️', 'Dangerous Mode').add(dangerousMode);
|
|
208
132
|
if (cached) {
|
|
209
133
|
// Cache reads and writes are most of the context, and without them this
|
|
210
134
|
// read about 0%. Same sum as the usage footer's.
|
|
@@ -213,93 +137,23 @@ export async function handleStatus(ctx) {
|
|
|
213
137
|
? Math.round((used / cached.contextWindow) * 100)
|
|
214
138
|
: 0;
|
|
215
139
|
field('📐', 'Context').add(`${pct}% (${fmtTokens(used)}/${fmtTokens(cached.contextWindow)})`);
|
|
216
|
-
// Only when something has actually been tallied: PTY mode never receives
|
|
217
|
-
// a cost figure, and a flat $0.0000 there reads as a free conversation
|
|
218
|
-
// rather than as an unanswerable question.
|
|
219
|
-
if (cached.sessionCostTurns > 0) {
|
|
220
|
-
field('💰', 'Session Cost').add(`$${cached.sessionCostUsd.toFixed(4)} (${cached.sessionCostTurns} turns)`);
|
|
221
|
-
}
|
|
222
140
|
}
|
|
223
141
|
// Only in a group, and only for a non-admin — it is the line that explains
|
|
224
|
-
// why /
|
|
225
|
-
// /
|
|
142
|
+
// why /botrestart just refused. Spectators never see it: they can't reach
|
|
143
|
+
// /info in the first place.
|
|
226
144
|
const role = describeRole(ctx);
|
|
227
145
|
if (role && role !== 'admin') {
|
|
228
146
|
field('👤', 'Your role here').add(role);
|
|
229
147
|
}
|
|
230
|
-
|
|
148
|
+
// The session id is one tap away under /footer's "Show session", and
|
|
149
|
+
// the bot's uptime is /botstatus's business.
|
|
231
150
|
field('⏱️', 'Last Activity').add(session.lastActivity.toLocaleString());
|
|
232
|
-
field('⏳', 'Uptime').add(getUptimeFormatted());
|
|
233
151
|
await replyFormatted(ctx, status.build());
|
|
234
152
|
}
|
|
235
153
|
catch (err) {
|
|
236
|
-
console.error('[
|
|
154
|
+
console.error('[Info] Error:', err);
|
|
237
155
|
const msg = err instanceof Error ? err.message : String(err);
|
|
238
|
-
await ctx.reply(`❌ /
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
export async function handlePing(ctx) {
|
|
242
|
-
const uptime = getUptimeFormatted();
|
|
243
|
-
await ctx.reply(`🏓 Pong!\n\nUptime: ${uptime}`);
|
|
244
|
-
}
|
|
245
|
-
export async function handleContext(ctx) {
|
|
246
|
-
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
247
|
-
if (!keyInfo)
|
|
248
|
-
return;
|
|
249
|
-
const { chatId, sessionKey } = keyInfo;
|
|
250
|
-
const session = await requireActiveSession(ctx, sessionKey);
|
|
251
|
-
if (!session)
|
|
252
|
-
return;
|
|
253
|
-
// Try cached SDK usage first (instant, no CLI shell-out)
|
|
254
|
-
const cached = getCachedUsage(sessionKey);
|
|
255
|
-
if (cached) {
|
|
256
|
-
const used = contextTokens(cached);
|
|
257
|
-
const pct = cached.contextWindow > 0
|
|
258
|
-
? Math.round((used / cached.contextWindow) * 100)
|
|
259
|
-
: 0;
|
|
260
|
-
const bar = getProgressBar(pct, contextHealthColor(used, cached.contextWindow));
|
|
261
|
-
const output = `## 🧠 Context Usage\n\n`
|
|
262
|
-
+ `${bar} **${pct}%** of context window\n\n`
|
|
263
|
-
+ `- **Model:** ${cached.model}\n`
|
|
264
|
-
+ `- **Input tokens:** ${fmtTokens(cached.inputTokens)}\n`
|
|
265
|
-
+ `- **Output tokens:** ${fmtTokens(cached.outputTokens)}\n`
|
|
266
|
-
+ `- **Cache read:** ${fmtTokens(cached.cacheReadTokens)}\n`
|
|
267
|
-
+ `- **Cache write:** ${fmtTokens(cached.cacheWriteTokens)}\n`
|
|
268
|
-
+ `- **Context window:** ${fmtTokens(cached.contextWindow)}\n`
|
|
269
|
-
+ `- **Turns this session:** ${cached.numTurns}\n`
|
|
270
|
-
+ `- **Cost this query:** $${cached.totalCostUsd.toFixed(4)}\n`
|
|
271
|
-
+ (cached.sessionCostTurns > 0
|
|
272
|
-
? `- **Cost this chat:** $${cached.sessionCostUsd.toFixed(4)} across ${cached.sessionCostTurns} turns\n`
|
|
273
|
-
: '')
|
|
274
|
-
+ `\n_Data from last query. Send a message then run /context for fresh data._`;
|
|
275
|
-
await messageSender.sendMessage(ctx, output);
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
// Fallback: CLI shell-out approach (Claude only)
|
|
279
|
-
if (!session.claudeSessionId) {
|
|
280
|
-
await replyMd(ctx, '⚠️ No Claude session ID found.\n\nSend a message to Claude after resuming, then run `/context` again.');
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
const ack = await ctx.reply('🧠 Checking context...');
|
|
284
|
-
try {
|
|
285
|
-
const raw = await runClaudeContext(session.claudeSessionId, session.workingDirectory);
|
|
286
|
-
const formatted = parseContextOutput(raw);
|
|
287
|
-
await messageSender.sendMessage(ctx, formatted);
|
|
288
|
-
}
|
|
289
|
-
catch (error) {
|
|
290
|
-
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
291
|
-
const hint = message.toLowerCase().includes('unknown') || message.toLowerCase().includes('command')
|
|
292
|
-
? '\n\nThis CLI may not support `/context` yet.'
|
|
293
|
-
: '';
|
|
294
|
-
await messageSender.sendMessage(ctx, `❌ Failed to fetch context: ${message}${hint}`);
|
|
295
|
-
}
|
|
296
|
-
finally {
|
|
297
|
-
try {
|
|
298
|
-
await ctx.api.deleteMessage(chatId, ack.message_id);
|
|
299
|
-
}
|
|
300
|
-
catch {
|
|
301
|
-
// ignore cleanup errors
|
|
302
|
-
}
|
|
156
|
+
await ctx.reply(`❌ /info failed: ${msg}`).catch(() => { });
|
|
303
157
|
}
|
|
304
158
|
}
|
|
305
159
|
export async function handleCancel(ctx) {
|
|
@@ -321,112 +175,17 @@ export async function handleCancel(ctx) {
|
|
|
321
175
|
}
|
|
322
176
|
}
|
|
323
177
|
export async function handleCommands(ctx) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
* ask the force-reply answers.
|
|
330
|
-
*/
|
|
331
|
-
function modePrompt(emoji, title, workingDirectory, body, ask) {
|
|
332
|
-
const b = new EntityText()
|
|
333
|
-
.add(`${emoji} `).bold(title)
|
|
334
|
-
.add('\n\n').italic(`Project: ${path.basename(workingDirectory)}`);
|
|
335
|
-
if (body) {
|
|
336
|
-
b.add('\n\n');
|
|
337
|
-
if (typeof body === 'string')
|
|
338
|
-
b.add(body);
|
|
339
|
-
else
|
|
340
|
-
b.append(body);
|
|
341
|
-
}
|
|
342
|
-
return b.add('\n\n👇 ').italic(ask).build();
|
|
343
|
-
}
|
|
344
|
-
export async function handlePlan(ctx) {
|
|
345
|
-
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
346
|
-
if (!keyInfo)
|
|
347
|
-
return;
|
|
348
|
-
const { sessionKey } = keyInfo;
|
|
349
|
-
const session = await requireActiveSession(ctx, sessionKey);
|
|
350
|
-
if (!session)
|
|
351
|
-
return;
|
|
352
|
-
const text = ctx.message?.text || '';
|
|
353
|
-
const task = text.split(' ').slice(1).join(' ').trim();
|
|
354
|
-
if (!task) {
|
|
355
|
-
await replyFormatted(ctx, modePrompt('📋', 'Plan Mode', session.workingDirectory, 'Claude will analyze your task and create a detailed implementation plan before coding.', 'Describe your task:'), {
|
|
356
|
-
reply_markup: {
|
|
357
|
-
force_reply: true,
|
|
358
|
-
input_field_placeholder: 'Add user authentication with JWT...',
|
|
359
|
-
selective: true,
|
|
360
|
-
},
|
|
361
|
-
});
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
try {
|
|
365
|
-
await queueRequest(sessionKey, task, async () => {
|
|
366
|
-
await withStreamingTurn(ctx, sessionKey, task, async (abortController) => {
|
|
367
|
-
const response = await sendToAgent(sessionKey, task, {
|
|
368
|
-
...progressCallbacks(ctx),
|
|
369
|
-
abortController,
|
|
370
|
-
telegramCtx: ctx,
|
|
371
|
-
command: 'plan',
|
|
372
|
-
});
|
|
373
|
-
await messageSender.finishStreaming(ctx, response.text);
|
|
374
|
-
await relayCatchUpIfMissed(ctx, sessionKey, response.text || '');
|
|
375
|
-
await maybeSendVoiceReply(ctx, response.text);
|
|
376
|
-
await closeTurn(ctx, sessionKey, response, task);
|
|
377
|
-
});
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
catch (error) {
|
|
381
|
-
if (error.message === 'Queue cleared')
|
|
382
|
-
return;
|
|
383
|
-
await ctx.reply(turnErrorReply(error));
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
export async function handleExplore(ctx) {
|
|
387
|
-
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
388
|
-
if (!keyInfo)
|
|
389
|
-
return;
|
|
390
|
-
const { sessionKey } = keyInfo;
|
|
391
|
-
const session = await requireActiveSession(ctx, sessionKey);
|
|
392
|
-
if (!session)
|
|
393
|
-
return;
|
|
394
|
-
const text = ctx.message?.text || '';
|
|
395
|
-
const question = text.split(' ').slice(1).join(' ').trim();
|
|
396
|
-
if (!question) {
|
|
397
|
-
await replyFormatted(ctx, modePrompt('🔍', 'Explore Mode', session.workingDirectory, 'Claude will search and analyze the codebase to answer your question.', 'What would you like to know?'), {
|
|
398
|
-
reply_markup: {
|
|
399
|
-
force_reply: true,
|
|
400
|
-
input_field_placeholder: 'How does the auth system work?',
|
|
401
|
-
selective: true,
|
|
402
|
-
},
|
|
403
|
-
});
|
|
178
|
+
// `/commands kill` searches names and descriptions — Telegram's own `/`
|
|
179
|
+
// menu only filters on the start of a name.
|
|
180
|
+
const query = (ctx.message?.text ?? '').split(' ').slice(1).join(' ').trim();
|
|
181
|
+
if (query) {
|
|
182
|
+
await replyFormatted(ctx, buildCommandSearchMessage(query, searchCommands(query)));
|
|
404
183
|
return;
|
|
405
184
|
}
|
|
406
|
-
|
|
407
|
-
await queueRequest(sessionKey, question, async () => {
|
|
408
|
-
await withStreamingTurn(ctx, sessionKey, question, async (abortController) => {
|
|
409
|
-
const response = await sendToAgent(sessionKey, question, {
|
|
410
|
-
...progressCallbacks(ctx),
|
|
411
|
-
abortController,
|
|
412
|
-
telegramCtx: ctx,
|
|
413
|
-
command: 'explore',
|
|
414
|
-
});
|
|
415
|
-
await messageSender.finishStreaming(ctx, response.text);
|
|
416
|
-
await relayCatchUpIfMissed(ctx, sessionKey, response.text || '');
|
|
417
|
-
await maybeSendVoiceReply(ctx, response.text);
|
|
418
|
-
await closeTurn(ctx, sessionKey, response, question);
|
|
419
|
-
});
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
catch (error) {
|
|
423
|
-
if (error.message === 'Queue cleared')
|
|
424
|
-
return;
|
|
425
|
-
await ctx.reply(turnErrorReply(error));
|
|
426
|
-
}
|
|
185
|
+
await replyParts(ctx, getAvailableCommands());
|
|
427
186
|
}
|
|
428
187
|
/** Show the current permission-gate state and the patterns it enforces. */
|
|
429
|
-
export async function
|
|
188
|
+
export async function handleGate(ctx) {
|
|
430
189
|
const { isPermissionGateEnabled, isPermissionGateImplicit, listDangerousPatterns } = await import('../../claude/permission-gate.js');
|
|
431
190
|
const { getAdminIds, getApproverIds, getGuestIds, hasGuestUsers, isAdmin, isApprover } = await import('../../utils/admins.js');
|
|
432
191
|
const enabled = isPermissionGateEnabled();
|
|
@@ -441,7 +200,8 @@ export async function handlePermissions(ctx) {
|
|
|
441
200
|
line((b) => b.add('🔐 ').bold('Permission gate').add(` — ${enabled ? '✅ enabled' : '⛔️ disabled'}`));
|
|
442
201
|
line();
|
|
443
202
|
if (enabled) {
|
|
444
|
-
line((b) => b.add('Bash commands matching the patterns below trigger a Telegram approval prompt before
|
|
203
|
+
line((b) => b.add('Bash commands matching the patterns below trigger a Telegram approval prompt before they run: Claude\'s own, and a ')
|
|
204
|
+
.code('!command').add(' someone sends. Other tools auto-allow.'));
|
|
445
205
|
}
|
|
446
206
|
else {
|
|
447
207
|
line((b) => b.add('Disabled. Set ').code('TELECODER_PERMISSION_PROMPTS=1').add(' and restart the bot to enable.'));
|
|
@@ -536,17 +296,17 @@ export async function handleProjectCommands(ctx) {
|
|
|
536
296
|
const { sessionKey } = keyInfo;
|
|
537
297
|
const session = sessionManager.getSession(sessionKey);
|
|
538
298
|
if (!session) {
|
|
539
|
-
await replyMd(ctx, '⚠️ No project set. Use `/
|
|
299
|
+
await replyMd(ctx, '⚠️ No project set. Use `/dir` first.');
|
|
540
300
|
return;
|
|
541
301
|
}
|
|
542
302
|
const { getProjectCommands } = await import('../../claude/project-commands.js');
|
|
543
303
|
const { getAvailableCommands: getClaudeCommands } = await import('../../claude/available-commands.js');
|
|
544
304
|
const { getBotCommandNames } = await import('../../claude/command-parser.js');
|
|
545
305
|
const projectCommands = getProjectCommands(session.workingDirectory);
|
|
546
|
-
// Ask the binary
|
|
547
|
-
//
|
|
548
|
-
//
|
|
549
|
-
const executable =
|
|
306
|
+
// Ask the binary the chat's turns actually run through: command sets differ
|
|
307
|
+
// between releases, and another install's list would name commands that
|
|
308
|
+
// don't exist here.
|
|
309
|
+
const executable = resolvePtyClaudeBin();
|
|
550
310
|
// A cold cache means a probe — a fresh headless process — so show a typing
|
|
551
311
|
// indicator rather than leaving the chat silent for a second or two.
|
|
552
312
|
const typing = ctx.replyWithChatAction?.('typing');
|
|
@@ -600,7 +360,7 @@ export function buildProjectCommandsMessage(input) {
|
|
|
600
360
|
const { skills, plugins, builtIns } = groupAvailableCommands(snapshot);
|
|
601
361
|
// A command TeleCoder registers never reaches Claude Code — grammY matches
|
|
602
362
|
// it first — so listing it as passthrough would be a lie. Name them
|
|
603
|
-
// separately instead, so nobody wonders why /
|
|
363
|
+
// separately instead, so nobody wonders why /model isn't Claude Code's picker.
|
|
604
364
|
const shadowed = snapshot.slashCommands.filter((n) => botCommandNames.has(n)).sort();
|
|
605
365
|
const passthrough = (names) => names.filter((n) => !botCommandNames.has(n));
|
|
606
366
|
const groups = [
|
|
@@ -622,6 +382,8 @@ export function buildProjectCommandsMessage(input) {
|
|
|
622
382
|
line();
|
|
623
383
|
line(commandList(shadowed));
|
|
624
384
|
line();
|
|
385
|
+
line((b) => b.add("For Claude Code's own, put ").code('/cc').add(' in front: ').code(`/cc ${shadowed[0]}`).add('.'));
|
|
386
|
+
line();
|
|
625
387
|
}
|
|
626
388
|
}
|
|
627
389
|
else {
|
|
@@ -655,46 +417,6 @@ function joinWithinLimit(lines, maxLength) {
|
|
|
655
417
|
}
|
|
656
418
|
return trimMessage(joinMessages(kept, '\n'));
|
|
657
419
|
}
|
|
658
|
-
export async function handleLoop(ctx) {
|
|
659
|
-
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
660
|
-
if (!keyInfo)
|
|
661
|
-
return;
|
|
662
|
-
const { sessionKey } = keyInfo;
|
|
663
|
-
const session = await requireActiveSession(ctx, sessionKey);
|
|
664
|
-
if (!session)
|
|
665
|
-
return;
|
|
666
|
-
const text = ctx.message?.text || '';
|
|
667
|
-
const task = text.split(' ').slice(1).join(' ').trim();
|
|
668
|
-
if (!task) {
|
|
669
|
-
await replyFormatted(ctx, modePrompt('🔄', 'Loop Mode', session.workingDirectory, `Claude will work iteratively until done (max ${config.MAX_LOOP_ITERATIONS} iterations).`, 'Describe the task:'), {
|
|
670
|
-
reply_markup: {
|
|
671
|
-
force_reply: true,
|
|
672
|
-
input_field_placeholder: 'Fix all TypeScript errors in src/',
|
|
673
|
-
selective: true,
|
|
674
|
-
},
|
|
675
|
-
});
|
|
676
|
-
return;
|
|
677
|
-
}
|
|
678
|
-
try {
|
|
679
|
-
await queueRequest(sessionKey, task, async () => {
|
|
680
|
-
await withStreamingTurn(ctx, sessionKey, task, async (abortController) => {
|
|
681
|
-
const response = await sendLoopToAgent(sessionKey, task, {
|
|
682
|
-
...progressCallbacks(ctx),
|
|
683
|
-
abortController,
|
|
684
|
-
telegramCtx: ctx,
|
|
685
|
-
});
|
|
686
|
-
await messageSender.finishStreaming(ctx, response.text);
|
|
687
|
-
await maybeSendVoiceReply(ctx, response.text);
|
|
688
|
-
await closeTurn(ctx, sessionKey, response, task);
|
|
689
|
-
});
|
|
690
|
-
});
|
|
691
|
-
}
|
|
692
|
-
catch (error) {
|
|
693
|
-
if (error.message === 'Queue cleared')
|
|
694
|
-
return;
|
|
695
|
-
await ctx.reply(turnErrorReply(error));
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
420
|
export async function handleFile(ctx) {
|
|
699
421
|
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
700
422
|
if (!keyInfo)
|
|
@@ -706,22 +428,11 @@ export async function handleFile(ctx) {
|
|
|
706
428
|
if (!session)
|
|
707
429
|
return;
|
|
708
430
|
if (!filePath) {
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
for (const f of projectFiles.slice(0, 8))
|
|
715
|
-
b.add('\n• ').code(f);
|
|
716
|
-
fileList = b.build();
|
|
717
|
-
}
|
|
718
|
-
await replyFormatted(ctx, modePrompt('📎', 'Download File', session.workingDirectory, fileList, 'Enter the file path:'), {
|
|
719
|
-
reply_markup: {
|
|
720
|
-
force_reply: true,
|
|
721
|
-
input_field_placeholder: 'src/index.ts',
|
|
722
|
-
selective: true,
|
|
723
|
-
},
|
|
724
|
-
});
|
|
431
|
+
await replyFormatted(ctx, new EntityText()
|
|
432
|
+
.add('📎 Usage: ').code('/file <path>')
|
|
433
|
+
.add(', relative to the project, e.g. ').code('/file src/index.ts')
|
|
434
|
+
.add('. Or just ask Claude to send you the file.')
|
|
435
|
+
.build());
|
|
725
436
|
return;
|
|
726
437
|
}
|
|
727
438
|
const fullPath = await resolveShareableFile(ctx, session.workingDirectory, filePath);
|
|
@@ -732,41 +443,4 @@ export async function handleFile(ctx) {
|
|
|
732
443
|
await ctx.reply('❌ Failed to send file. It may be too large (>50MB) or inaccessible.');
|
|
733
444
|
}
|
|
734
445
|
}
|
|
735
|
-
export async function handleTelegraph(ctx) {
|
|
736
|
-
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
737
|
-
if (!keyInfo)
|
|
738
|
-
return;
|
|
739
|
-
const { sessionKey } = keyInfo;
|
|
740
|
-
const text = ctx.message?.text || '';
|
|
741
|
-
const filePath = text.split(' ').slice(1).join(' ').trim();
|
|
742
|
-
// If no argument provided, show the settings menu
|
|
743
|
-
if (!filePath) {
|
|
744
|
-
const menu = buildTelegraphMenu(sessionKey);
|
|
745
|
-
await replyFormatted(ctx, menu.text, {
|
|
746
|
-
reply_markup: menu.keyboard.length > 0 ? { inline_keyboard: menu.keyboard } : undefined,
|
|
747
|
-
});
|
|
748
|
-
return;
|
|
749
|
-
}
|
|
750
|
-
if (await refuseFilePublish(ctx))
|
|
751
|
-
return;
|
|
752
|
-
const session = await requireActiveSession(ctx, sessionKey);
|
|
753
|
-
if (!session)
|
|
754
|
-
return;
|
|
755
|
-
const fullPath = await resolveShareableFile(ctx, session.workingDirectory, filePath);
|
|
756
|
-
if (!fullPath)
|
|
757
|
-
return;
|
|
758
|
-
const ext = path.extname(fullPath).toLowerCase();
|
|
759
|
-
if (ext !== '.md' && ext !== '.markdown') {
|
|
760
|
-
await ctx.reply('⚠️ Telegraph works best with Markdown files (.md)');
|
|
761
|
-
}
|
|
762
|
-
await ctx.reply('📤 Creating Telegraph page...');
|
|
763
|
-
const pageUrl = await createTelegraphFromFile(fullPath);
|
|
764
|
-
if (pageUrl) {
|
|
765
|
-
const fileName = path.basename(fullPath);
|
|
766
|
-
await replyFormatted(ctx, new EntityText().add('📄 ').bold(fileName).add('\n\n').link('Open in Instant View', pageUrl).build());
|
|
767
|
-
}
|
|
768
|
-
else {
|
|
769
|
-
await ctx.reply('❌ Failed to create Telegraph page.');
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
446
|
//# sourceMappingURL=command.handler.js.map
|