telecoder 0.0.0-stage → 1.2.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 +363 -0
- package/CHANGELOG.md +1186 -0
- package/LICENSE +22 -0
- package/README.md +126 -2
- package/dist/audio/transcribe.js +50 -0
- package/dist/bin/mcp-server.js +378 -0
- package/dist/bin/tool-result.js +22 -0
- package/dist/bot/access/group-access.js +147 -0
- package/dist/bot/bot.js +592 -0
- package/dist/bot/file-access.js +141 -0
- package/dist/bot/handlers/command/access.js +407 -0
- package/dist/bot/handlers/command/admin.js +827 -0
- package/dist/bot/handlers/command/auto-approve.js +138 -0
- package/dist/bot/handlers/command/btw.js +224 -0
- package/dist/bot/handlers/command/cost.js +409 -0
- package/dist/bot/handlers/command/media.js +197 -0
- package/dist/bot/handlers/command/model.js +305 -0
- package/dist/bot/handlers/command/prefs-scope.js +197 -0
- package/dist/bot/handlers/command/project.js +536 -0
- package/dist/bot/handlers/command/resume.js +321 -0
- package/dist/bot/handlers/command/session.js +438 -0
- package/dist/bot/handlers/command/settings.js +1012 -0
- package/dist/bot/handlers/command/shared.js +210 -0
- package/dist/bot/handlers/command/streaming-mode.js +16 -0
- package/dist/bot/handlers/command/tasks.js +513 -0
- package/dist/bot/handlers/command/topic-store.js +113 -0
- package/dist/bot/handlers/command/topic.js +80 -0
- package/dist/bot/handlers/command.handler.js +772 -0
- package/dist/bot/handlers/fork.handler.js +1109 -0
- package/dist/bot/handlers/media-fallback.js +121 -0
- package/dist/bot/handlers/message/replies.js +133 -0
- package/dist/bot/handlers/message/shared.js +117 -0
- package/dist/bot/handlers/message/throttle.js +49 -0
- package/dist/bot/handlers/message/turn-notify.js +169 -0
- package/dist/bot/handlers/message/turn-runner.js +141 -0
- package/dist/bot/handlers/message.handler.js +107 -0
- package/dist/bot/handlers/newbot.handler.js +221 -0
- package/dist/bot/handlers/photo.handler.js +327 -0
- package/dist/bot/handlers/prompts.handler.js +343 -0
- package/dist/bot/handlers/running-note.js +44 -0
- package/dist/bot/handlers/schedule.handler.js +303 -0
- package/dist/bot/handlers/session-guard.js +78 -0
- package/dist/bot/handlers/suggestion.handler.js +84 -0
- package/dist/bot/handlers/tree.handler.js +480 -0
- package/dist/bot/handlers/view.js +41 -0
- package/dist/bot/handlers/voice.handler.js +209 -0
- package/dist/bot/middleware/admin-only.js +49 -0
- package/dist/bot/middleware/auth.middleware.js +122 -0
- package/dist/bot/middleware/group-mention.middleware.js +139 -0
- package/dist/bot/middleware/group-role.middleware.js +75 -0
- package/dist/bot/middleware/message-batcher.js +87 -0
- package/dist/bot/middleware/queued-messages.js +971 -0
- package/dist/bot/middleware/stale-filter.js +31 -0
- package/dist/build-info.json +8 -0
- package/dist/claude/agent-watchdog.js +162 -0
- package/dist/claude/agent.js +1458 -0
- package/dist/claude/ask-user.js +295 -0
- package/dist/claude/auto-approve.js +225 -0
- package/dist/claude/auto-topic-haiku.js +126 -0
- package/dist/claude/available-commands.js +153 -0
- package/dist/claude/carry-over.js +27 -0
- package/dist/claude/ccr-shim.js +46 -0
- package/dist/claude/charter-judge.js +214 -0
- package/dist/claude/claude-auth.js +121 -0
- package/dist/claude/command-parser.js +200 -0
- package/dist/claude/cost-overlay-scraper.js +129 -0
- package/dist/claude/enabled-plugins.js +56 -0
- package/dist/claude/fork-tree.js +393 -0
- package/dist/claude/held-query.js +190 -0
- package/dist/claude/in-flight-tracker.js +61 -0
- package/dist/claude/ipc-server.js +192 -0
- package/dist/claude/mcp-bridge.js +453 -0
- package/dist/claude/mcp-tools.js +354 -0
- package/dist/claude/message-offsets.js +88 -0
- package/dist/claude/modal-relay.js +450 -0
- package/dist/claude/model-catalog.js +85 -0
- package/dist/claude/monitor-relay.js +597 -0
- package/dist/claude/pending-forks.js +93 -0
- package/dist/claude/pending-suggestions.js +50 -0
- package/dist/claude/permission-gate.js +337 -0
- package/dist/claude/permission-mode.js +178 -0
- package/dist/claude/poll-user.js +51 -0
- package/dist/claude/project-commands.js +69 -0
- package/dist/claude/prompt-hold.js +124 -0
- package/dist/claude/prompt-suggestion-scraper.js +89 -0
- package/dist/claude/pty-provider.js +2214 -0
- package/dist/claude/pty-spawn-config.js +296 -0
- package/dist/claude/pty-stream.js +363 -0
- package/dist/claude/request-queue.js +135 -0
- package/dist/claude/scheduled-runner.js +91 -0
- package/dist/claude/scheduler.js +237 -0
- package/dist/claude/scope-guard.js +274 -0
- package/dist/claude/sdk-permission-gate.js +77 -0
- package/dist/claude/secret-request.js +576 -0
- package/dist/claude/session-cost.js +41 -0
- package/dist/claude/session-history.js +286 -0
- package/dist/claude/session-jsonl.js +920 -0
- package/dist/claude/session-manager.js +195 -0
- package/dist/claude/session-scan.js +270 -0
- package/dist/claude/setup-token.js +285 -0
- package/dist/claude/side-call-options.js +45 -0
- package/dist/claude/side-question.js +249 -0
- package/dist/claude/stage-images.js +62 -0
- package/dist/claude/subagent-tools.js +12 -0
- package/dist/claude/synthetic-ctx.js +51 -0
- package/dist/claude/system-prompt.js +162 -0
- package/dist/claude/tasks-overlay-scraper.js +94 -0
- package/dist/claude/tip-scraper.js +78 -0
- package/dist/claude/tui-modal.js +501 -0
- package/dist/claude/tui-state.js +384 -0
- package/dist/claude/turn-end.js +91 -0
- package/dist/claude/turn-prose.js +64 -0
- package/dist/claude/update-banner-relay.js +70 -0
- package/dist/cli/commands/doctor.js +305 -0
- package/dist/cli/commands/help.js +25 -0
- package/dist/cli/commands/init.js +123 -0
- package/dist/cli/commands/service.js +678 -0
- package/dist/cli/commands/start.js +53 -0
- package/dist/cli/commands/version.js +11 -0
- package/dist/cli/dispatch.js +79 -0
- package/dist/cli/init/env-file.js +99 -0
- package/dist/cli/init/flow.js +638 -0
- package/dist/cli/init/prompter.js +116 -0
- package/dist/cli/init/telegram.js +94 -0
- package/dist/cli/service/render.js +212 -0
- package/dist/cli.js +18 -0
- package/dist/config-report.js +107 -0
- package/dist/config.js +500 -0
- package/dist/index.js +367 -0
- package/dist/launcher.js +933 -0
- package/dist/node-version-check.js +27 -0
- package/dist/providers/ccr-health.js +119 -0
- package/dist/providers/ccr-introspect.js +149 -0
- package/dist/providers/ccr-provider.js +60 -0
- package/dist/providers/claude-provider.js +63 -0
- package/dist/providers/prefs-sync.js +164 -0
- package/dist/providers/project-favorites.js +74 -0
- package/dist/providers/provider-router.js +127 -0
- package/dist/providers/provider-switch.js +91 -0
- package/dist/providers/sdk-provider.js +37 -0
- package/dist/providers/types.js +8 -0
- package/dist/providers/user-preferences.js +214 -0
- package/dist/restart-when-idle.js +153 -0
- package/dist/startup/auto-continue.js +67 -0
- package/dist/startup/auto-resume.js +173 -0
- package/dist/startup/notices.js +120 -0
- package/dist/startup/shared.js +44 -0
- package/dist/startup/verify-token.js +31 -0
- package/dist/telegram/access-request.js +153 -0
- package/dist/telegram/action-logger.js +684 -0
- package/dist/telegram/admin-mention.js +107 -0
- package/dist/telegram/background-activity-card.js +502 -0
- package/dist/telegram/botname-settings.js +336 -0
- package/dist/telegram/button-text.js +26 -0
- package/dist/telegram/client-options.js +27 -0
- package/dist/telegram/deduplication.js +33 -0
- package/dist/telegram/entities.js +295 -0
- package/dist/telegram/force-reply-tracker.js +57 -0
- package/dist/telegram/lettered-options.js +87 -0
- package/dist/telegram/markdown.js +362 -0
- package/dist/telegram/message-sender.js +1287 -0
- package/dist/telegram/prompt-label.js +142 -0
- package/dist/telegram/prompt-suggestion.js +54 -0
- package/dist/telegram/send.js +123 -0
- package/dist/telegram/streaming-turn.js +105 -0
- package/dist/telegram/suggestions-settings.js +30 -0
- package/dist/telegram/task-list.js +367 -0
- package/dist/telegram/task-tracker.js +209 -0
- package/dist/telegram/telegraph-settings.js +31 -0
- package/dist/telegram/telegraph.js +453 -0
- package/dist/telegram/terminal-renderer.js +671 -0
- package/dist/telegram/terminal-settings.js +25 -0
- package/dist/telegram/thread-titles.js +190 -0
- package/dist/telegram/threads-setup.js +117 -0
- package/dist/tts/tts-settings.js +62 -0
- package/dist/tts/tts.js +245 -0
- package/dist/tts/voice-reply.js +78 -0
- package/dist/utils/admins.js +143 -0
- package/dist/utils/agent-timer.js +55 -0
- package/dist/utils/atomic-write.js +24 -0
- package/dist/utils/bot-token.js +74 -0
- package/dist/utils/bounded-map.js +55 -0
- package/dist/utils/build-info.js +57 -0
- package/dist/utils/caffeinate.js +50 -0
- package/dist/utils/claude-env.js +54 -0
- package/dist/utils/claude-version.js +48 -0
- package/dist/utils/config-home.js +62 -0
- package/dist/utils/debug-agent.js +117 -0
- package/dist/utils/debug-watchdog.js +121 -0
- package/dist/utils/download.js +111 -0
- package/dist/utils/exit-codes.js +48 -0
- package/dist/utils/file-type.js +149 -0
- package/dist/utils/format.js +81 -0
- package/dist/utils/home-project.js +30 -0
- package/dist/utils/host-stall.js +51 -0
- package/dist/utils/id-list.js +44 -0
- package/dist/utils/idle-restart.js +92 -0
- package/dist/utils/install-mode.js +63 -0
- package/dist/utils/instance-config.js +148 -0
- package/dist/utils/instances.js +95 -0
- package/dist/utils/json-store.js +140 -0
- package/dist/utils/keyed-settings.js +62 -0
- package/dist/utils/legacy-env.js +35 -0
- package/dist/utils/npm-version.js +134 -0
- package/dist/utils/prefs-relay.js +107 -0
- package/dist/utils/proc-children.js +102 -0
- package/dist/utils/project-data-dir.js +33 -0
- package/dist/utils/reasoning-summary.js +12 -0
- package/dist/utils/resolve-bin.js +86 -0
- package/dist/utils/resolve-claude-bin.js +63 -0
- package/dist/utils/respawn-backoff.js +19 -0
- package/dist/utils/sanitize.js +91 -0
- package/dist/utils/session-key.js +37 -0
- package/dist/utils/stale-launcher.js +109 -0
- package/dist/utils/state-dir-migration.js +92 -0
- package/dist/utils/systemd.js +126 -0
- package/dist/utils/user-roster.js +275 -0
- package/dist/utils/verbosity.js +118 -0
- package/dist/utils/version-check.js +166 -0
- package/dist/utils/workspace-guard.js +44 -0
- package/dist/worker-restart.js +141 -0
- package/instances.json.example +41 -0
- package/package.json +76 -4
|
@@ -0,0 +1,1012 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-chat settings menus: /streaming, /terminalui, /tts, /telegraph,
|
|
3
|
+
* /suggestions, /effort, /verbosity, /method and the status line.
|
|
4
|
+
*
|
|
5
|
+
* They share one shape — render an inline keyboard reflecting current state,
|
|
6
|
+
* flip a setting on tap, re-render — and several need the same pty-restart
|
|
7
|
+
* note when the change only lands on a fresh spawn.
|
|
8
|
+
*/
|
|
9
|
+
import * as path from 'path';
|
|
10
|
+
import { config } from '../../../config.js';
|
|
11
|
+
import { sessionManager } from '../../../claude/session-manager.js';
|
|
12
|
+
import { promptsIn } from '../../../claude/fork-tree.js';
|
|
13
|
+
import { setEffort, getEffort, clearEffort, isValidEffortLevel, getActiveProviderName, } from '../../../providers/provider-router.js';
|
|
14
|
+
import { userPreferences } from '../../../providers/user-preferences.js';
|
|
15
|
+
import { contextTokens } from '../../../providers/types.js';
|
|
16
|
+
import { isPremiumModel, PREMIUM_MODEL_ICON } from '../../../claude/model-catalog.js';
|
|
17
|
+
import { getActiveMethod, getPtyProvider } from '../../../providers/claude-provider.js';
|
|
18
|
+
import { EntityText, joinMessages } from '../../../telegram/entities.js';
|
|
19
|
+
import { replyFormatted, editCallbackMessage } from '../../../telegram/send.js';
|
|
20
|
+
import { taskTracker } from '../../../telegram/task-tracker.js';
|
|
21
|
+
import { promptLabel, cutLabel } from '../../../telegram/prompt-label.js';
|
|
22
|
+
import { getTTSSettings, setTTSEnabled, setTTSVoice, setTTSAutoplay } from '../../../tts/tts-settings.js';
|
|
23
|
+
import { getTerminalUISettings, setTerminalUIEnabled } from '../../../telegram/terminal-settings.js';
|
|
24
|
+
import { getTelegraphSettings, setTelegraphEnabled } from '../../../telegram/telegraph-settings.js';
|
|
25
|
+
import { getSuggestionsSettings, setSuggestionsEnabled } from '../../../telegram/suggestions-settings.js';
|
|
26
|
+
import { VERBOSITY_INFO, isValidVerbosityLevel, getVerbosityLevel, resolveVerbosityFlags, } from '../../../utils/verbosity.js';
|
|
27
|
+
import { contextHealthColor, fmtTokens, getProgressBar } from '../../../utils/format.js';
|
|
28
|
+
import { getSessionKeyFromCtx, parseSessionKey } from '../../../utils/session-key.js';
|
|
29
|
+
import { PERMISSION_MODES, isPermissionModeId, parsePermissionModeArg, permissionModeInfo, transportDefaultMode, } from '../../../claude/permission-mode.js';
|
|
30
|
+
import { replyMd, parseCallback, getEffortLabel, restartPtyForSettingChange, EFFORT_LEVELS, PTY_RESTART_NOTE, } from './shared.js';
|
|
31
|
+
import { getSessionTopic } from './topic.js';
|
|
32
|
+
import { getStreamingMode, setStreamingMode } from './streaming-mode.js';
|
|
33
|
+
import { getBgProcesses } from './tasks.js';
|
|
34
|
+
import { parseScopeArg, applyToAllBots, buildApplyToAllKeyboard, prefsConfirmation, effortResetConfirmation, hasSiblings, } from './prefs-scope.js';
|
|
35
|
+
const OPENAI_TTS_VOICES = [
|
|
36
|
+
'alloy', 'ash', 'ballad', 'coral',
|
|
37
|
+
'echo', 'fable', 'nova', 'onyx',
|
|
38
|
+
'sage', 'shimmer', 'verse', 'marin', 'cedar',
|
|
39
|
+
];
|
|
40
|
+
const GROQ_TTS_VOICES = [
|
|
41
|
+
'autumn', 'diana', 'hannah', 'austin', 'daniel', 'troy',
|
|
42
|
+
];
|
|
43
|
+
function getActiveTTSVoices() {
|
|
44
|
+
return config.TTS_PROVIDER === 'groq' ? GROQ_TTS_VOICES : OPENAI_TTS_VOICES;
|
|
45
|
+
}
|
|
46
|
+
function buildTTSMenu(sessionKey, mode) {
|
|
47
|
+
const settings = getTTSSettings(sessionKey);
|
|
48
|
+
const hasKey = config.TTS_PROVIDER === 'groq' ? !!config.GROQ_API_KEY : !!config.OPENAI_API_KEY;
|
|
49
|
+
const apiStatus = hasKey ? 'configured' : 'missing';
|
|
50
|
+
const providerLabel = config.TTS_PROVIDER === 'groq' ? 'Groq Orpheus' : 'OpenAI';
|
|
51
|
+
const statusLine = settings.enabled ? 'ON' : 'OFF';
|
|
52
|
+
const autoplayLine = settings.autoplay ? 'ON' : 'OFF';
|
|
53
|
+
const header = () => new EntityText().add('🔊 ').bold('Voice Replies').newline(2);
|
|
54
|
+
if (mode === 'voices') {
|
|
55
|
+
const voices = getActiveTTSVoices();
|
|
56
|
+
const voiceRows = [];
|
|
57
|
+
const chunkSize = 3;
|
|
58
|
+
for (let i = 0; i < voices.length; i += chunkSize) {
|
|
59
|
+
const chunk = voices.slice(i, i + chunkSize);
|
|
60
|
+
voiceRows.push(chunk.map((voice) => ({
|
|
61
|
+
text: voice === settings.voice ? `✓ ${voice}` : voice,
|
|
62
|
+
callback_data: `tts:voice:${voice}`,
|
|
63
|
+
})));
|
|
64
|
+
}
|
|
65
|
+
const recommended = config.TTS_PROVIDER === 'groq'
|
|
66
|
+
? 'autumn, troy'
|
|
67
|
+
: 'marin, cedar';
|
|
68
|
+
return {
|
|
69
|
+
text: header().add(`Pick a voice.\nRecommended: ${recommended}.`).build(),
|
|
70
|
+
keyboard: [
|
|
71
|
+
...voiceRows,
|
|
72
|
+
[{ text: 'Back', callback_data: 'tts:back' }],
|
|
73
|
+
],
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const autoplayLabel = settings.autoplay ? '✓ Autoplay' : 'Autoplay';
|
|
77
|
+
return {
|
|
78
|
+
text: header()
|
|
79
|
+
.add('Provider: ').bold(providerLabel).newline()
|
|
80
|
+
.add('Status: ').bold(statusLine).newline()
|
|
81
|
+
.add('Voice: ').bold(settings.voice).newline()
|
|
82
|
+
.add('Autoplay: ').bold(autoplayLine).newline()
|
|
83
|
+
.add('API key: ').bold(apiStatus)
|
|
84
|
+
.build(),
|
|
85
|
+
keyboard: [
|
|
86
|
+
[
|
|
87
|
+
{ text: settings.enabled ? '✓ On' : 'On', callback_data: 'tts:on' },
|
|
88
|
+
{ text: !settings.enabled ? '✓ Off' : 'Off', callback_data: 'tts:off' },
|
|
89
|
+
],
|
|
90
|
+
[
|
|
91
|
+
{ text: `Voice: ${settings.voice}`, callback_data: 'tts:voices' },
|
|
92
|
+
{ text: autoplayLabel, callback_data: 'tts:autoplay' },
|
|
93
|
+
],
|
|
94
|
+
],
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function buildSuggestionsMenu(sessionKey) {
|
|
98
|
+
const settings = getSuggestionsSettings(sessionKey);
|
|
99
|
+
const defaultLabel = config.PROMPT_SUGGESTIONS_DEFAULT ? 'on' : 'off';
|
|
100
|
+
const statusLine = settings.enabled ? 'ON' : 'OFF';
|
|
101
|
+
const text = new EntityText()
|
|
102
|
+
.add('💡 ').bold('Predicted Next Prompt').newline(2)
|
|
103
|
+
.add('Status: ').bold(statusLine).newline()
|
|
104
|
+
.add('Default: ').bold(defaultLabel).newline(2)
|
|
105
|
+
.italic("When enabled, TeleCoder surfaces Claude Code's speculative next-prompt as an inline button under each response. Tap to send it as your next message.")
|
|
106
|
+
.newline(2)
|
|
107
|
+
.italic('Takes effect on the next session spawn (env var is set at spawn time).')
|
|
108
|
+
.build();
|
|
109
|
+
return {
|
|
110
|
+
text,
|
|
111
|
+
keyboard: [
|
|
112
|
+
[
|
|
113
|
+
{ text: settings.enabled ? '✓ On' : 'On', callback_data: 'sugg:on' },
|
|
114
|
+
{ text: !settings.enabled ? '✓ Off' : 'Off', callback_data: 'sugg:off' },
|
|
115
|
+
],
|
|
116
|
+
],
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
export function buildTelegraphMenu(sessionKey) {
|
|
120
|
+
const settings = getTelegraphSettings(sessionKey);
|
|
121
|
+
const globalEnabled = config.TELEGRAPH_ENABLED;
|
|
122
|
+
const globalStatus = globalEnabled ? 'enabled' : 'disabled';
|
|
123
|
+
const statusLine = settings.enabled ? 'ON' : 'OFF';
|
|
124
|
+
const header = () => new EntityText().add('📄 ').bold('Instant View (Telegraph)').newline(2);
|
|
125
|
+
// If global config is disabled, show warning and no toggle
|
|
126
|
+
if (!globalEnabled) {
|
|
127
|
+
return {
|
|
128
|
+
text: header()
|
|
129
|
+
.add('⚠️ ').bold('Disabled globally').newline(2)
|
|
130
|
+
.add('Telegraph is off in the bot configuration. It is opt-in because every page it publishes is public to anyone with the link.\nSet ')
|
|
131
|
+
.code('TELEGRAPH_ENABLED=true').add(' in .env to enable.')
|
|
132
|
+
.build(),
|
|
133
|
+
keyboard: [],
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
text: header()
|
|
138
|
+
.add('Status: ').bold(statusLine).newline()
|
|
139
|
+
.add('Global config: ').bold(globalStatus).newline(2)
|
|
140
|
+
.italic('When enabled, replies over 2500 characters also get an Instant View link under the text. The reply itself is always sent in full either way.')
|
|
141
|
+
.build(),
|
|
142
|
+
keyboard: [
|
|
143
|
+
[
|
|
144
|
+
{ text: settings.enabled ? '✓ On' : 'On', callback_data: 'telegraph:on' },
|
|
145
|
+
{ text: !settings.enabled ? '✓ Off' : 'Off', callback_data: 'telegraph:off' },
|
|
146
|
+
],
|
|
147
|
+
],
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
export async function handleStreaming(ctx) {
|
|
151
|
+
const keyboard = [
|
|
152
|
+
[
|
|
153
|
+
{
|
|
154
|
+
text: getStreamingMode() === 'streaming' ? '✓ Streaming' : 'Streaming',
|
|
155
|
+
callback_data: 'mode:streaming'
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
text: getStreamingMode() === 'wait' ? '✓ Wait' : 'Wait',
|
|
159
|
+
callback_data: 'mode:wait'
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
];
|
|
163
|
+
await replyFormatted(ctx, new EntityText()
|
|
164
|
+
.add('⚙️ ').bold('Response Mode').newline(2)
|
|
165
|
+
.add('Current: ').bold(getStreamingMode()).newline()
|
|
166
|
+
.italic(streamingModeDescription(getStreamingMode()))
|
|
167
|
+
.build(), { reply_markup: { inline_keyboard: keyboard } });
|
|
168
|
+
}
|
|
169
|
+
function streamingModeDescription(mode) {
|
|
170
|
+
return mode === 'streaming' ? 'Updates progressively as Claude types' : 'Shows complete response when done';
|
|
171
|
+
}
|
|
172
|
+
export async function handleModeCallback(ctx) {
|
|
173
|
+
const data = ctx.callbackQuery?.data;
|
|
174
|
+
if (!data || !data.startsWith('mode:'))
|
|
175
|
+
return;
|
|
176
|
+
const newMode = data.replace('mode:', '');
|
|
177
|
+
setStreamingMode(newMode);
|
|
178
|
+
await ctx.answerCallbackQuery({ text: `Mode set to ${newMode}!` });
|
|
179
|
+
await editCallbackMessage(ctx, new EntityText()
|
|
180
|
+
.add('✅ Mode set to ').bold(newMode).newline(2)
|
|
181
|
+
.italic(streamingModeDescription(newMode))
|
|
182
|
+
.build());
|
|
183
|
+
}
|
|
184
|
+
export async function handleTerminalUI(ctx) {
|
|
185
|
+
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
186
|
+
if (!keyInfo)
|
|
187
|
+
return;
|
|
188
|
+
const { sessionKey } = keyInfo;
|
|
189
|
+
const settings = getTerminalUISettings(sessionKey);
|
|
190
|
+
const currentStatus = settings.enabled ? 'ON' : 'OFF';
|
|
191
|
+
const keyboard = [
|
|
192
|
+
[
|
|
193
|
+
{
|
|
194
|
+
text: settings.enabled ? '✓ On' : 'On',
|
|
195
|
+
callback_data: 'terminalui:on'
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
text: !settings.enabled ? '✓ Off' : 'Off',
|
|
199
|
+
callback_data: 'terminalui:off'
|
|
200
|
+
},
|
|
201
|
+
],
|
|
202
|
+
];
|
|
203
|
+
await replyFormatted(ctx, new EntityText()
|
|
204
|
+
.add('🖥️ ').bold('Terminal UI Mode').newline(2)
|
|
205
|
+
.add('Current: ').bold(currentStatus).newline()
|
|
206
|
+
.italic(terminalUIDescription(settings.enabled))
|
|
207
|
+
.build(), { reply_markup: { inline_keyboard: keyboard } });
|
|
208
|
+
}
|
|
209
|
+
function terminalUIDescription(enabled) {
|
|
210
|
+
return enabled
|
|
211
|
+
? 'Shows spinner animations and tool status during operations'
|
|
212
|
+
: 'Classic streaming mode with simple cursor';
|
|
213
|
+
}
|
|
214
|
+
export async function handleTerminalUICallback(ctx) {
|
|
215
|
+
const cb = parseCallback(ctx, 'terminalui:');
|
|
216
|
+
if (!cb)
|
|
217
|
+
return;
|
|
218
|
+
const { sessionKey, data } = cb;
|
|
219
|
+
const newState = data.replace('terminalui:', '') === 'on';
|
|
220
|
+
setTerminalUIEnabled(sessionKey, newState);
|
|
221
|
+
const statusText = newState ? 'ON' : 'OFF';
|
|
222
|
+
await ctx.answerCallbackQuery({ text: `Terminal UI ${statusText}!` });
|
|
223
|
+
await editCallbackMessage(ctx, new EntityText()
|
|
224
|
+
.add('✅ Terminal UI ').bold(statusText).newline(2)
|
|
225
|
+
.italic(terminalUIDescription(newState))
|
|
226
|
+
.build());
|
|
227
|
+
}
|
|
228
|
+
export async function handleTTS(ctx) {
|
|
229
|
+
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
230
|
+
if (!keyInfo)
|
|
231
|
+
return;
|
|
232
|
+
const { sessionKey } = keyInfo;
|
|
233
|
+
const menu = buildTTSMenu(sessionKey, 'main');
|
|
234
|
+
await replyFormatted(ctx, menu.text, {
|
|
235
|
+
reply_markup: { inline_keyboard: menu.keyboard },
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
export async function handleTTSCallback(ctx) {
|
|
239
|
+
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
240
|
+
if (!keyInfo)
|
|
241
|
+
return;
|
|
242
|
+
const { sessionKey } = keyInfo;
|
|
243
|
+
const data = ctx.callbackQuery?.data;
|
|
244
|
+
if (!data || !data.startsWith('tts:'))
|
|
245
|
+
return;
|
|
246
|
+
if (data === 'tts:on') {
|
|
247
|
+
const hasKey = config.TTS_PROVIDER === 'groq' ? !!config.GROQ_API_KEY : !!config.OPENAI_API_KEY;
|
|
248
|
+
const keyName = config.TTS_PROVIDER === 'groq' ? 'GROQ_API_KEY' : 'OPENAI_API_KEY';
|
|
249
|
+
if (!hasKey) {
|
|
250
|
+
await ctx.answerCallbackQuery({ text: `${keyName} missing. Set it in .env and restart.` });
|
|
251
|
+
setTTSEnabled(sessionKey, false);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
setTTSEnabled(sessionKey, true);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
else if (data === 'tts:off') {
|
|
258
|
+
setTTSEnabled(sessionKey, false);
|
|
259
|
+
}
|
|
260
|
+
else if (data === 'tts:autoplay') {
|
|
261
|
+
const current = getTTSSettings(sessionKey);
|
|
262
|
+
setTTSAutoplay(sessionKey, !current.autoplay);
|
|
263
|
+
}
|
|
264
|
+
else if (data.startsWith('tts:voice:')) {
|
|
265
|
+
const voice = data.replace('tts:voice:', '');
|
|
266
|
+
const voices = getActiveTTSVoices();
|
|
267
|
+
if (voices.includes(voice)) {
|
|
268
|
+
setTTSVoice(sessionKey, voice);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
const mode = data === 'tts:voices' || data.startsWith('tts:voice:')
|
|
272
|
+
? 'voices'
|
|
273
|
+
: 'main';
|
|
274
|
+
const menu = buildTTSMenu(sessionKey, mode);
|
|
275
|
+
await ctx.answerCallbackQuery();
|
|
276
|
+
try {
|
|
277
|
+
await editCallbackMessage(ctx, menu.text, {
|
|
278
|
+
reply_markup: { inline_keyboard: menu.keyboard },
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
catch (error) {
|
|
282
|
+
// Ignore "message is not modified" — happens with duplicate callbacks
|
|
283
|
+
if (!(error instanceof Error && error.message.includes('message is not modified'))) {
|
|
284
|
+
throw error;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
export async function handleTelegraphCallback(ctx) {
|
|
289
|
+
const cb = parseCallback(ctx, 'telegraph:');
|
|
290
|
+
if (!cb)
|
|
291
|
+
return;
|
|
292
|
+
const { sessionKey, data } = cb;
|
|
293
|
+
// Don't allow enabling if global config is disabled
|
|
294
|
+
if (data === 'telegraph:on') {
|
|
295
|
+
if (!config.TELEGRAPH_ENABLED) {
|
|
296
|
+
await ctx.answerCallbackQuery({ text: 'Telegraph disabled in config. Set TELEGRAPH_ENABLED=true in .env.' });
|
|
297
|
+
setTelegraphEnabled(sessionKey, false);
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
setTelegraphEnabled(sessionKey, true);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
else if (data === 'telegraph:off') {
|
|
304
|
+
setTelegraphEnabled(sessionKey, false);
|
|
305
|
+
}
|
|
306
|
+
const menu = buildTelegraphMenu(sessionKey);
|
|
307
|
+
await ctx.answerCallbackQuery();
|
|
308
|
+
try {
|
|
309
|
+
await editCallbackMessage(ctx, menu.text, {
|
|
310
|
+
reply_markup: { inline_keyboard: menu.keyboard },
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
// Ignore "message is not modified" — happens with duplicate callbacks
|
|
315
|
+
if (!(error instanceof Error && error.message.includes('message is not modified'))) {
|
|
316
|
+
throw error;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
// ── /effort ──────────────────────────────────────────────────────
|
|
321
|
+
export async function handleEffort(ctx) {
|
|
322
|
+
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
323
|
+
if (!keyInfo)
|
|
324
|
+
return;
|
|
325
|
+
const { chatId, sessionKey } = keyInfo;
|
|
326
|
+
const text = ctx.message?.text || '';
|
|
327
|
+
const parsed = parseScopeArg(text.split(' ').slice(1).join(' '));
|
|
328
|
+
const args = parsed.value.toLowerCase();
|
|
329
|
+
const scope = parsed.scope;
|
|
330
|
+
if (!args) {
|
|
331
|
+
const currentEffort = getEffort(sessionKey) || 'default';
|
|
332
|
+
const keyboard = EFFORT_LEVELS.map((level) => {
|
|
333
|
+
const isCurrent = level.id === currentEffort;
|
|
334
|
+
const label = isCurrent ? `✓ ${level.label}` : level.label;
|
|
335
|
+
return [{ text: label, callback_data: `effort:${level.id}` }];
|
|
336
|
+
});
|
|
337
|
+
// Add auto/reset option
|
|
338
|
+
keyboard.push([{ text: currentEffort === 'default' ? '✓ Auto (default)' : 'Auto (default)', callback_data: 'effort:auto' }]);
|
|
339
|
+
const picker = new EntityText()
|
|
340
|
+
.add('🎯 ').bold('Effort Level').newline(2)
|
|
341
|
+
.italic(`Current: ${currentEffort}`).newline(2);
|
|
342
|
+
for (const l of EFFORT_LEVELS) {
|
|
343
|
+
picker.add('• ').bold(l.label).add(` - ${l.description}\n`);
|
|
344
|
+
}
|
|
345
|
+
picker.add('• ').bold('Auto').add(' - SDK default');
|
|
346
|
+
// Same scoping as /model: the tap sets this bot, the confirmation offers
|
|
347
|
+
// the rest. Stated here so neither scope has to be guessed at.
|
|
348
|
+
if (hasSiblings()) {
|
|
349
|
+
picker.add('\n\nApplies to ').bold(config.BOT_NAME).add(' only — add ').code('all')
|
|
350
|
+
.add(' (').code('/effort high all').add(') or use the button afterwards to set every bot.');
|
|
351
|
+
}
|
|
352
|
+
await replyFormatted(ctx, picker.build(), {
|
|
353
|
+
reply_markup: { inline_keyboard: keyboard },
|
|
354
|
+
});
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
if (args === 'auto' || args === 'default' || args === 'reset') {
|
|
358
|
+
clearEffort(sessionKey);
|
|
359
|
+
const restarted = restartPtyForSettingChange(sessionKey);
|
|
360
|
+
const confirmation = new EntityText().append(effortResetConfirmation());
|
|
361
|
+
if (restarted)
|
|
362
|
+
confirmation.append(PTY_RESTART_NOTE);
|
|
363
|
+
await replyWithScope(ctx, sessionKey, confirmation.build(), 'effort', null, 'auto', scope);
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
// A bare `all` is a scope with no level attached — point at the form that
|
|
367
|
+
// works rather than rejecting it as an unknown level.
|
|
368
|
+
if (args === 'all' || args === 'everywhere') {
|
|
369
|
+
await replyMd(ctx, '`all` sets every bot, but it needs a level to set them to.\n\n' +
|
|
370
|
+
'Try `/effort high all`, or /effort to pick one.');
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
if (!isValidEffortLevel(args)) {
|
|
374
|
+
await replyFormatted(ctx, `❌ Unknown effort level "${args}".\n\nValid: low, medium, high, xhigh, max, auto`);
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
setEffort(sessionKey, args);
|
|
378
|
+
const restarted = restartPtyForSettingChange(sessionKey);
|
|
379
|
+
const info = EFFORT_LEVELS.find(l => l.id === args);
|
|
380
|
+
const confirmation = new EntityText().append(prefsConfirmation('effort', info?.label || args));
|
|
381
|
+
if (restarted)
|
|
382
|
+
confirmation.append(PTY_RESTART_NOTE);
|
|
383
|
+
await replyWithScope(ctx, sessionKey, confirmation.build(), 'effort', args, args, scope);
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Send a settings confirmation, either fanning the change out to the other
|
|
387
|
+
* bots (scope 'all') or offering to. `buttonValue` is what the fan-out button
|
|
388
|
+
* carries — the same spelling the picker uses, so 'auto' rather than null.
|
|
389
|
+
*/
|
|
390
|
+
async function replyWithScope(ctx, sessionKey, confirmation, setting, value, buttonValue, scope) {
|
|
391
|
+
if (scope === 'all') {
|
|
392
|
+
const summary = await applyToAllBots({
|
|
393
|
+
chatId: parseSessionKey(sessionKey).chatId,
|
|
394
|
+
setting,
|
|
395
|
+
value,
|
|
396
|
+
provider: getActiveProviderName(sessionKey),
|
|
397
|
+
});
|
|
398
|
+
await replyFormatted(ctx, new EntityText().append(confirmation).append(summary).build());
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
const keyboard = buildApplyToAllKeyboard(setting, buttonValue);
|
|
402
|
+
await replyFormatted(ctx, confirmation, {
|
|
403
|
+
...(keyboard ? { reply_markup: { inline_keyboard: keyboard } } : {}),
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
export async function handleEffortCallback(ctx) {
|
|
407
|
+
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
408
|
+
if (!keyInfo)
|
|
409
|
+
return;
|
|
410
|
+
const { chatId, sessionKey } = keyInfo;
|
|
411
|
+
const data = ctx.callbackQuery?.data;
|
|
412
|
+
if (!data || !data.startsWith('effort:'))
|
|
413
|
+
return;
|
|
414
|
+
const level = data.replace('effort:', '');
|
|
415
|
+
if (level === 'auto') {
|
|
416
|
+
clearEffort(sessionKey);
|
|
417
|
+
const restarted = restartPtyForSettingChange(sessionKey);
|
|
418
|
+
await ctx.answerCallbackQuery({ text: 'Effort reset to auto!' });
|
|
419
|
+
const keyboard = buildApplyToAllKeyboard('effort', 'auto');
|
|
420
|
+
const confirmation = new EntityText().append(effortResetConfirmation());
|
|
421
|
+
if (restarted)
|
|
422
|
+
confirmation.append(PTY_RESTART_NOTE);
|
|
423
|
+
await editCallbackMessage(ctx, confirmation.build(), {
|
|
424
|
+
...(keyboard ? { reply_markup: { inline_keyboard: keyboard } } : {}),
|
|
425
|
+
});
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
if (!isValidEffortLevel(level)) {
|
|
429
|
+
await ctx.answerCallbackQuery({ text: 'Invalid effort level' });
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
setEffort(sessionKey, level);
|
|
433
|
+
const restarted = restartPtyForSettingChange(sessionKey);
|
|
434
|
+
const info = EFFORT_LEVELS.find(l => l.id === level);
|
|
435
|
+
const displayName = info?.label || level;
|
|
436
|
+
await ctx.answerCallbackQuery({ text: `Effort set to ${displayName}!` });
|
|
437
|
+
const keyboard = buildApplyToAllKeyboard('effort', level);
|
|
438
|
+
const confirmation = new EntityText().append(prefsConfirmation('effort', displayName));
|
|
439
|
+
if (restarted)
|
|
440
|
+
confirmation.append(PTY_RESTART_NOTE);
|
|
441
|
+
await editCallbackMessage(ctx, confirmation.build(), {
|
|
442
|
+
...(keyboard ? { reply_markup: { inline_keyboard: keyboard } } : {}),
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
// ── /statusline ─────────────────────────────────────────────────
|
|
446
|
+
// A small italic message sent after each turn so the user can always see
|
|
447
|
+
// the current effort (and, in future, more stats) right above the compose
|
|
448
|
+
// box without scrolling. Off by default; opt-in via /statusline.
|
|
449
|
+
function shortenModelName(model) {
|
|
450
|
+
// Strip "vendor/" prefix (OpenRouter / CCR style: "anthropic/claude-4-sonnet-...")
|
|
451
|
+
const slashIdx = model.lastIndexOf('/');
|
|
452
|
+
const stripped = slashIdx >= 0 ? model.substring(slashIdx + 1) : model;
|
|
453
|
+
// claude-opus-4-8 → opus-4-8; trim trailing -YYYYMMDD release tags.
|
|
454
|
+
return stripped.replace(/^claude-/, '').replace(/-\d{8}$/, '');
|
|
455
|
+
}
|
|
456
|
+
// The last few prompts rather than only the latest: a turn often starts from
|
|
457
|
+
// an "ok" or a "yeah", which says nothing without the prompts before it.
|
|
458
|
+
const STATUS_LINE_PROMPTS = 5;
|
|
459
|
+
// Past this a prompt shows its start and its end. Most prompts are one
|
|
460
|
+
// paragraph, and across 100 recent sessions 93% of those fit, where 100
|
|
461
|
+
// characters cut a third of them. Five sit under every answer: at 40
|
|
462
|
+
// characters a row they take a median of 15 rows, and at most 40.
|
|
463
|
+
const STATUS_LINE_PROMPT_MAX = 300;
|
|
464
|
+
/**
|
|
465
|
+
* The status line's prompt lines, oldest first so they read in the same order
|
|
466
|
+
* as the chat above them. `prompts` are raw, as the session log keeps them;
|
|
467
|
+
* anything that wasn't a turn, like a /compact, is dropped before the last few
|
|
468
|
+
* are taken, so it doesn't use up one of the lines.
|
|
469
|
+
*/
|
|
470
|
+
export function formatRecentPrompts(prompts) {
|
|
471
|
+
const b = new EntityText();
|
|
472
|
+
prompts
|
|
473
|
+
.flatMap((prompt) => promptLabel(prompt) ?? [])
|
|
474
|
+
.slice(-STATUS_LINE_PROMPTS)
|
|
475
|
+
.forEach((label, i) => {
|
|
476
|
+
if (i > 0)
|
|
477
|
+
b.newline();
|
|
478
|
+
b.italic(`▸ ${cutLabel(label, STATUS_LINE_PROMPT_MAX)}`);
|
|
479
|
+
});
|
|
480
|
+
return b.build();
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* The session's prompts as its log records them, so the list reaches back past
|
|
484
|
+
* a restart and past prompts sent from elsewhere. The turn's own prompt stands
|
|
485
|
+
* in when the log has none to give. A reply no prompt started, like the one to
|
|
486
|
+
* a background task that reported back, has only the log to go by.
|
|
487
|
+
*/
|
|
488
|
+
function recentPrompts(sessionKey, lastPrompt) {
|
|
489
|
+
const session = sessionKey ? sessionManager.getSession(sessionKey) : undefined;
|
|
490
|
+
const logged = session?.claudeSessionId
|
|
491
|
+
? promptsIn(session.workingDirectory, session.claudeSessionId)
|
|
492
|
+
: [];
|
|
493
|
+
if (logged.length > 0)
|
|
494
|
+
return logged;
|
|
495
|
+
return lastPrompt ? [lastPrompt] : [];
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* The usage footer, if there's a figure to show and /verbosity wants it shown.
|
|
499
|
+
* Plain text, whether sent alone or closing the status line.
|
|
500
|
+
*/
|
|
501
|
+
function usageFooter(chatId, usage) {
|
|
502
|
+
if (!usage || !resolveVerbosityFlags(chatId).showUsageFooter)
|
|
503
|
+
return undefined;
|
|
504
|
+
const used = contextTokens(usage);
|
|
505
|
+
const pct = usage.contextWindow > 0 ? Math.round((used / usage.contextWindow) * 100) : 0;
|
|
506
|
+
const bar = getProgressBar(pct, contextHealthColor(used, usage.contextWindow));
|
|
507
|
+
return `${bar} ${pct}% context · ${fmtTokens(used)}/${fmtTokens(usage.contextWindow)} · $${usage.totalCostUsd.toFixed(4)} · ${usage.numTurns} turns`;
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Build the status-line message body.
|
|
511
|
+
* Each enabled line picks its own formatting (italic for topic/stats,
|
|
512
|
+
* mono code span for the resume command so it's easy to copy).
|
|
513
|
+
*
|
|
514
|
+
* Sections are joined with blank lines so the first line (typically the
|
|
515
|
+
* topic) stands alone in Telegram's chat-list preview — that's the only
|
|
516
|
+
* line visible when distinguishing multiple bots in the same project.
|
|
517
|
+
*
|
|
518
|
+
* The usage footer, when the chat shows one, closes the message.
|
|
519
|
+
*
|
|
520
|
+
* `brief` leaves the stats and that footer: see StatusLineOptions.
|
|
521
|
+
*/
|
|
522
|
+
function buildStatusLine(chatId, sessionKey, usage, lastPrompt, brief = false) {
|
|
523
|
+
const sections = [];
|
|
524
|
+
if (!brief && sessionKey && userPreferences.getShowTopicInStatusLine(chatId)) {
|
|
525
|
+
const topic = getSessionTopic(sessionKey);
|
|
526
|
+
if (topic)
|
|
527
|
+
sections.push(new EntityText().italic(`💬 ${topic}`).build());
|
|
528
|
+
}
|
|
529
|
+
if (!brief && userPreferences.getShowPromptInStatusLine(chatId)) {
|
|
530
|
+
const formatted = formatRecentPrompts(recentPrompts(sessionKey, lastPrompt));
|
|
531
|
+
if (formatted.text)
|
|
532
|
+
sections.push(formatted);
|
|
533
|
+
}
|
|
534
|
+
const tail = new EntityText();
|
|
535
|
+
if (!brief && sessionKey && userPreferences.getShowSessionInStatusLine(chatId)) {
|
|
536
|
+
const claudeSessionId = sessionManager.getSession(sessionKey)?.claudeSessionId;
|
|
537
|
+
if (claudeSessionId) {
|
|
538
|
+
tail.add('🔗 ').code(`claude --resume ${claudeSessionId}`).newline();
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
const stats = [];
|
|
542
|
+
// The bot's display name only says where it is now; this stays with each
|
|
543
|
+
// answer for scrolling back. After a switch it already names the new project,
|
|
544
|
+
// where the next message goes, even though the turn ran in the old one.
|
|
545
|
+
const project = sessionKey ? sessionManager.getSession(sessionKey)?.workingDirectory : undefined;
|
|
546
|
+
if (project)
|
|
547
|
+
stats.push(`📁 ${path.basename(project) || project}`);
|
|
548
|
+
const label = getEffortLabel(sessionKey ?? chatId);
|
|
549
|
+
stats.push(label || '🧠 Auto');
|
|
550
|
+
const footer = usageFooter(chatId, usage);
|
|
551
|
+
const provider = getActiveProviderName(sessionKey ?? chatId);
|
|
552
|
+
if (usage) {
|
|
553
|
+
if (usage.model) {
|
|
554
|
+
const shortened = shortenModelName(usage.model);
|
|
555
|
+
// The SDK alias doesn't reflect CCR's actual backend; tag accordingly.
|
|
556
|
+
// A premium model swaps the robot for a badge, so it stands out of the
|
|
557
|
+
// row rather than reading as one more stat.
|
|
558
|
+
if (provider === 'ccr')
|
|
559
|
+
stats.push(`🤖 ${shortened} · CCR`);
|
|
560
|
+
else if (isPremiumModel(usage.model))
|
|
561
|
+
stats.push(`${PREMIUM_MODEL_ICON} ${shortened.toUpperCase()}`);
|
|
562
|
+
else
|
|
563
|
+
stats.push(`🤖 ${shortened}`);
|
|
564
|
+
}
|
|
565
|
+
// The footer gives these two right below, in more detail.
|
|
566
|
+
if (!footer) {
|
|
567
|
+
if (usage.contextWindow > 0) {
|
|
568
|
+
const used = contextTokens(usage);
|
|
569
|
+
const pct = Math.round((used / usage.contextWindow) * 100);
|
|
570
|
+
// The chart while it's healthy; amber or red once it's grown big
|
|
571
|
+
// enough that a /clear or fork is worth thinking about.
|
|
572
|
+
const health = contextHealthColor(used, usage.contextWindow);
|
|
573
|
+
stats.push(`${health === '🟢' ? '📊' : health} ${pct}%`);
|
|
574
|
+
}
|
|
575
|
+
stats.push(`💰 $${usage.totalCostUsd.toFixed(2)}`);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
// Activity counters — only rendered when non-zero so quiet turns stay quiet.
|
|
579
|
+
// Tasks/monitors come from the SDK-side tracker; bg shells from the PTY
|
|
580
|
+
// session's /proc children, so the count auto-falls-back to 0 in SDK mode.
|
|
581
|
+
if (sessionKey) {
|
|
582
|
+
const bg = taskTracker.getBackgroundedTasks(sessionKey);
|
|
583
|
+
const monitorCount = bg.filter((t) => t.taskType === 'monitor_mcp').length;
|
|
584
|
+
const taskCount = bg.length - monitorCount;
|
|
585
|
+
if (taskCount > 0)
|
|
586
|
+
stats.push(`🔄 ${taskCount}`);
|
|
587
|
+
if (monitorCount > 0)
|
|
588
|
+
stats.push(`📡 ${monitorCount}`);
|
|
589
|
+
const claudePid = getPtyProvider().getSessionPid(sessionKey);
|
|
590
|
+
if (claudePid !== undefined) {
|
|
591
|
+
const shellCount = getBgProcesses(claudePid).length;
|
|
592
|
+
if (shellCount > 0)
|
|
593
|
+
stats.push(`🔍 ${shellCount}`);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
tail.italic(stats.join(' · '));
|
|
597
|
+
if (footer)
|
|
598
|
+
tail.newline().add(footer);
|
|
599
|
+
sections.push(tail.build());
|
|
600
|
+
return joinMessages(sections);
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* The message that closes a turn: the status line, with the usage footer at its
|
|
604
|
+
* bottom when the chat shows both. /statusline and /verbosity set them apart,
|
|
605
|
+
* so with the status line off, a chat that shows the footer gets it on its own.
|
|
606
|
+
*
|
|
607
|
+
* `lastPrompt` is the turn's own, for a session whose log has no prompts to
|
|
608
|
+
* list. Leave it out for a reply that no prompt started.
|
|
609
|
+
*/
|
|
610
|
+
export async function sendStatusLine(ctx, chatId, sessionKey, usage, lastPrompt, { brief = false } = {}) {
|
|
611
|
+
try {
|
|
612
|
+
if (userPreferences.getShowStatusLine(chatId)) {
|
|
613
|
+
await replyFormatted(ctx, buildStatusLine(chatId, sessionKey, usage, lastPrompt, brief));
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
const footer = usageFooter(chatId, usage);
|
|
617
|
+
if (footer)
|
|
618
|
+
await ctx.reply(footer);
|
|
619
|
+
}
|
|
620
|
+
catch (err) {
|
|
621
|
+
console.debug('[StatusLine] Failed to send:', err instanceof Error ? err.message : err);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
function buildStatusLineMenu(chatId, sessionKey) {
|
|
625
|
+
const enabled = userPreferences.getShowStatusLine(chatId);
|
|
626
|
+
const showTopic = userPreferences.getShowTopicInStatusLine(chatId);
|
|
627
|
+
const showSession = userPreferences.getShowSessionInStatusLine(chatId);
|
|
628
|
+
const showPrompt = userPreferences.getShowPromptInStatusLine(chatId);
|
|
629
|
+
const keyboard = [
|
|
630
|
+
[
|
|
631
|
+
{ text: enabled ? '✓ Status line: On' : 'Status line: On', callback_data: 'statusline:on' },
|
|
632
|
+
{ text: !enabled ? '✓ Status line: Off' : 'Status line: Off', callback_data: 'statusline:off' },
|
|
633
|
+
],
|
|
634
|
+
[
|
|
635
|
+
{ text: showTopic ? '✓ Show topic: On' : 'Show topic: On', callback_data: 'statusline:topic:on' },
|
|
636
|
+
{ text: !showTopic ? '✓ Show topic: Off' : 'Show topic: Off', callback_data: 'statusline:topic:off' },
|
|
637
|
+
],
|
|
638
|
+
[
|
|
639
|
+
{ text: showPrompt ? '✓ Show last prompts: On' : 'Show last prompts: On', callback_data: 'statusline:prompt:on' },
|
|
640
|
+
{ text: !showPrompt ? '✓ Show last prompts: Off' : 'Show last prompts: Off', callback_data: 'statusline:prompt:off' },
|
|
641
|
+
],
|
|
642
|
+
[
|
|
643
|
+
{ text: showSession ? '✓ Show session: On' : 'Show session: On', callback_data: 'statusline:session:on' },
|
|
644
|
+
{ text: !showSession ? '✓ Show session: Off' : 'Show session: Off', callback_data: 'statusline:session:off' },
|
|
645
|
+
],
|
|
646
|
+
];
|
|
647
|
+
const preview = buildStatusLine(chatId, sessionKey, undefined, 'example prompt for preview');
|
|
648
|
+
const onOff = (on) => (on ? 'ON' : 'OFF');
|
|
649
|
+
const text = new EntityText()
|
|
650
|
+
.add('📍 ').bold('Status Line').newline(2)
|
|
651
|
+
.add('Status line: ').bold(onOff(enabled)).newline()
|
|
652
|
+
.add('Show topic: ').bold(onOff(showTopic)).newline()
|
|
653
|
+
.add('Show last prompts: ').bold(onOff(showPrompt)).newline()
|
|
654
|
+
.add('Show session: ').bold(onOff(showSession)).newline(2)
|
|
655
|
+
.italic('Sends a small italic line after each turn so you can see the current state without scrolling.')
|
|
656
|
+
.add(' ')
|
|
657
|
+
.italic(`Show last prompts lists the last ${STATUS_LINE_PROMPTS} you sent, so an "ok" still shows what it answered. ` +
|
|
658
|
+
'Handy under /verbosity verbose, where the action log can push them off screen.')
|
|
659
|
+
.add(' ')
|
|
660
|
+
.wrap('italic', (b) => b
|
|
661
|
+
.add('The session line shows a copy-pasteable ')
|
|
662
|
+
.code('claude --resume')
|
|
663
|
+
.add(' command for CLI fallback.'))
|
|
664
|
+
.add('\n\nPreview:\n')
|
|
665
|
+
.append(preview)
|
|
666
|
+
.build();
|
|
667
|
+
return { text, keyboard };
|
|
668
|
+
}
|
|
669
|
+
export async function handleStatusLine(ctx) {
|
|
670
|
+
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
671
|
+
if (!keyInfo)
|
|
672
|
+
return;
|
|
673
|
+
const { chatId, sessionKey } = keyInfo;
|
|
674
|
+
const menu = buildStatusLineMenu(chatId, sessionKey);
|
|
675
|
+
await replyFormatted(ctx, menu.text, {
|
|
676
|
+
reply_markup: { inline_keyboard: menu.keyboard },
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
export async function handleStatusLineCallback(ctx) {
|
|
680
|
+
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
681
|
+
if (!keyInfo)
|
|
682
|
+
return;
|
|
683
|
+
const { chatId, sessionKey } = keyInfo;
|
|
684
|
+
const data = ctx.callbackQuery?.data;
|
|
685
|
+
if (!data || !data.startsWith('statusline:'))
|
|
686
|
+
return;
|
|
687
|
+
const action = data.replace('statusline:', '');
|
|
688
|
+
let toastText;
|
|
689
|
+
if (action === 'topic:on' || action === 'topic:off') {
|
|
690
|
+
const newState = action === 'topic:on';
|
|
691
|
+
userPreferences.setShowTopicInStatusLine(chatId, newState);
|
|
692
|
+
toastText = `Show topic ${newState ? 'ON' : 'OFF'}`;
|
|
693
|
+
}
|
|
694
|
+
else if (action === 'session:on' || action === 'session:off') {
|
|
695
|
+
const newState = action === 'session:on';
|
|
696
|
+
userPreferences.setShowSessionInStatusLine(chatId, newState);
|
|
697
|
+
toastText = `Show session ${newState ? 'ON' : 'OFF'}`;
|
|
698
|
+
}
|
|
699
|
+
else if (action === 'prompt:on' || action === 'prompt:off') {
|
|
700
|
+
const newState = action === 'prompt:on';
|
|
701
|
+
userPreferences.setShowPromptInStatusLine(chatId, newState);
|
|
702
|
+
toastText = `Show last prompts ${newState ? 'ON' : 'OFF'}`;
|
|
703
|
+
}
|
|
704
|
+
else if (action === 'on' || action === 'off') {
|
|
705
|
+
const newState = action === 'on';
|
|
706
|
+
userPreferences.setShowStatusLine(chatId, newState);
|
|
707
|
+
toastText = `Status line ${newState ? 'ON' : 'OFF'}`;
|
|
708
|
+
}
|
|
709
|
+
else {
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
712
|
+
const menu = buildStatusLineMenu(chatId, sessionKey);
|
|
713
|
+
await ctx.answerCallbackQuery({ text: toastText });
|
|
714
|
+
await editCallbackMessage(ctx, menu.text, {
|
|
715
|
+
reply_markup: { inline_keyboard: menu.keyboard },
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
// ── /verbosity ──────────────────────────────────────────────────
|
|
719
|
+
// Pick a verbosity tier (quiet | normal | verbose | debug) for this chat.
|
|
720
|
+
// The tier sets defaults for rendering flags (usage footer, compaction
|
|
721
|
+
// notice, completion ping, untruncated tool inputs). Explicit env vars
|
|
722
|
+
// (CONTEXT_SHOW_USAGE, CONTEXT_NOTIFY_COMPACTION, TERMINAL_UI_VERBOSE)
|
|
723
|
+
// still win over the tier. "Default" clears the chat-specific pref so the
|
|
724
|
+
// env-level VERBOSITY_DEFAULT applies.
|
|
725
|
+
function buildVerbosityMenu(chatId) {
|
|
726
|
+
const current = getVerbosityLevel(chatId);
|
|
727
|
+
const hasPref = userPreferences.getVerbosity(chatId) !== undefined;
|
|
728
|
+
const keyboard = VERBOSITY_INFO.map((info) => {
|
|
729
|
+
const isCurrent = info.id === current && hasPref;
|
|
730
|
+
const label = isCurrent ? `✓ ${info.label}` : info.label;
|
|
731
|
+
return [{ text: label, callback_data: `verbosity:${info.id}` }];
|
|
732
|
+
});
|
|
733
|
+
const defaultLabel = !hasPref ? `✓ Default (${config.VERBOSITY_DEFAULT})` : `Default (${config.VERBOSITY_DEFAULT})`;
|
|
734
|
+
keyboard.push([{ text: defaultLabel, callback_data: 'verbosity:default' }]);
|
|
735
|
+
const text = new EntityText()
|
|
736
|
+
.add('🎚️ ').bold('Verbosity').newline(2)
|
|
737
|
+
.add('Current: ').bold(current);
|
|
738
|
+
if (!hasPref)
|
|
739
|
+
text.add(' ').italic('(from env default)');
|
|
740
|
+
text.newline(2);
|
|
741
|
+
for (const info of VERBOSITY_INFO) {
|
|
742
|
+
text.add('• ').bold(info.label).add(` - ${info.description}\n`);
|
|
743
|
+
}
|
|
744
|
+
text.add('• ').bold('Default').add(' - Use the env-level setting (').code('VERBOSITY_DEFAULT').add(')');
|
|
745
|
+
return { text: text.build(), keyboard };
|
|
746
|
+
}
|
|
747
|
+
/** "✅ Verbosity reset to env default (**normal**)", for the command and its button. */
|
|
748
|
+
function verbosityResetText() {
|
|
749
|
+
return new EntityText()
|
|
750
|
+
.add('✅ Verbosity reset to env default (').bold(config.VERBOSITY_DEFAULT).add(')')
|
|
751
|
+
.build();
|
|
752
|
+
}
|
|
753
|
+
/** Confirmation for a chosen level, shared by the command and its buttons. */
|
|
754
|
+
function verbositySetText(level) {
|
|
755
|
+
const info = VERBOSITY_INFO.find((l) => l.id === level);
|
|
756
|
+
return new EntityText()
|
|
757
|
+
.add('✅ Verbosity set to ').bold(info?.label ?? level).newline(2)
|
|
758
|
+
.italic(info?.description ?? '')
|
|
759
|
+
.build();
|
|
760
|
+
}
|
|
761
|
+
export async function handleVerbosity(ctx) {
|
|
762
|
+
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
763
|
+
if (!keyInfo)
|
|
764
|
+
return;
|
|
765
|
+
const { chatId } = keyInfo;
|
|
766
|
+
const arg = (ctx.message?.text || '').split(' ').slice(1).join(' ').trim().toLowerCase();
|
|
767
|
+
if (!arg) {
|
|
768
|
+
const { text, keyboard } = buildVerbosityMenu(chatId);
|
|
769
|
+
await replyFormatted(ctx, text, {
|
|
770
|
+
reply_markup: { inline_keyboard: keyboard },
|
|
771
|
+
});
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
if (arg === 'default' || arg === 'reset' || arg === 'auto') {
|
|
775
|
+
userPreferences.clearVerbosity(chatId);
|
|
776
|
+
await replyFormatted(ctx, verbosityResetText());
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
if (!isValidVerbosityLevel(arg)) {
|
|
780
|
+
await replyFormatted(ctx, `❌ Unknown verbosity level "${arg}".\n\nValid: quiet, normal, verbose, debug, default`);
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
userPreferences.setVerbosity(chatId, arg);
|
|
784
|
+
await replyFormatted(ctx, verbositySetText(arg));
|
|
785
|
+
}
|
|
786
|
+
export async function handleVerbosityCallback(ctx) {
|
|
787
|
+
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
788
|
+
if (!keyInfo)
|
|
789
|
+
return;
|
|
790
|
+
const { chatId } = keyInfo;
|
|
791
|
+
const data = ctx.callbackQuery?.data;
|
|
792
|
+
if (!data || !data.startsWith('verbosity:'))
|
|
793
|
+
return;
|
|
794
|
+
const choice = data.replace('verbosity:', '');
|
|
795
|
+
if (choice === 'default') {
|
|
796
|
+
userPreferences.clearVerbosity(chatId);
|
|
797
|
+
await ctx.answerCallbackQuery({ text: 'Verbosity reset to default' });
|
|
798
|
+
await editCallbackMessage(ctx, verbosityResetText());
|
|
799
|
+
return;
|
|
800
|
+
}
|
|
801
|
+
if (!isValidVerbosityLevel(choice)) {
|
|
802
|
+
await ctx.answerCallbackQuery({ text: 'Invalid verbosity level' });
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
805
|
+
const level = choice;
|
|
806
|
+
userPreferences.setVerbosity(chatId, level);
|
|
807
|
+
const info = VERBOSITY_INFO.find((l) => l.id === level);
|
|
808
|
+
await ctx.answerCallbackQuery({ text: `Verbosity: ${info?.label ?? level}` });
|
|
809
|
+
await editCallbackMessage(ctx, verbositySetText(level));
|
|
810
|
+
}
|
|
811
|
+
export async function handleMethodCommand(ctx) {
|
|
812
|
+
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
813
|
+
if (!keyInfo)
|
|
814
|
+
return;
|
|
815
|
+
const { sessionKey } = keyInfo;
|
|
816
|
+
const descriptions = {
|
|
817
|
+
sdk: "Use Claude Code SDK (default, recommended)",
|
|
818
|
+
pty: "Use interactive PTY session (experimental, for Max subscription)",
|
|
819
|
+
};
|
|
820
|
+
const currentMethod = userPreferences.getMethod(sessionKey) ?? 'sdk';
|
|
821
|
+
const availableMethods = ['sdk', 'pty'];
|
|
822
|
+
const keyboard = availableMethods.map((method) => {
|
|
823
|
+
const label = method === currentMethod ? `✓ ${method}` : method;
|
|
824
|
+
return [{ text: label, callback_data: `method:${method}` }];
|
|
825
|
+
});
|
|
826
|
+
const descriptionText = new EntityText();
|
|
827
|
+
Object.entries(descriptions).forEach(([key, value], i) => {
|
|
828
|
+
if (i > 0)
|
|
829
|
+
descriptionText.newline();
|
|
830
|
+
descriptionText.bold(key).add(`: ${value}`);
|
|
831
|
+
});
|
|
832
|
+
await replyFormatted(ctx, descriptionText.build(), {
|
|
833
|
+
reply_markup: {
|
|
834
|
+
inline_keyboard: keyboard,
|
|
835
|
+
},
|
|
836
|
+
});
|
|
837
|
+
}
|
|
838
|
+
export async function handleMethodCallback(ctx) {
|
|
839
|
+
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
840
|
+
if (!keyInfo)
|
|
841
|
+
return;
|
|
842
|
+
const { sessionKey } = keyInfo;
|
|
843
|
+
const data = ctx.callbackQuery?.data;
|
|
844
|
+
if (!data || !data.startsWith('method:'))
|
|
845
|
+
return;
|
|
846
|
+
const newMethod = data.replace('method:', '');
|
|
847
|
+
if (newMethod === 'sdk' || newMethod === 'pty') {
|
|
848
|
+
userPreferences.setMethod(sessionKey, newMethod);
|
|
849
|
+
}
|
|
850
|
+
await ctx.answerCallbackQuery();
|
|
851
|
+
await editCallbackMessage(ctx, new EntityText().add('✅ Method set to ').bold(newMethod).build());
|
|
852
|
+
}
|
|
853
|
+
export async function handleSuggestions(ctx) {
|
|
854
|
+
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
855
|
+
if (!keyInfo)
|
|
856
|
+
return;
|
|
857
|
+
const { sessionKey } = keyInfo;
|
|
858
|
+
const menu = buildSuggestionsMenu(sessionKey);
|
|
859
|
+
await replyFormatted(ctx, menu.text, {
|
|
860
|
+
reply_markup: { inline_keyboard: menu.keyboard },
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
export async function handleSuggestionsCallback(ctx) {
|
|
864
|
+
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
865
|
+
if (!keyInfo)
|
|
866
|
+
return;
|
|
867
|
+
const { sessionKey } = keyInfo;
|
|
868
|
+
const data = ctx.callbackQuery?.data;
|
|
869
|
+
if (!data || !data.startsWith('sugg:'))
|
|
870
|
+
return;
|
|
871
|
+
if (data === 'sugg:on') {
|
|
872
|
+
setSuggestionsEnabled(sessionKey, true);
|
|
873
|
+
}
|
|
874
|
+
else if (data === 'sugg:off') {
|
|
875
|
+
setSuggestionsEnabled(sessionKey, false);
|
|
876
|
+
}
|
|
877
|
+
const menu = buildSuggestionsMenu(sessionKey);
|
|
878
|
+
await ctx.answerCallbackQuery();
|
|
879
|
+
try {
|
|
880
|
+
await editCallbackMessage(ctx, menu.text, {
|
|
881
|
+
reply_markup: { inline_keyboard: menu.keyboard },
|
|
882
|
+
});
|
|
883
|
+
}
|
|
884
|
+
catch (error) {
|
|
885
|
+
if (!(error instanceof Error && error.message.includes('message is not modified'))) {
|
|
886
|
+
console.error('[Suggestions] Failed to update menu:', error);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* `/mode` — how much claude asks before acting, per chat.
|
|
892
|
+
*
|
|
893
|
+
* The callback prefix is `permmode:` rather than the obvious `mode:`, which
|
|
894
|
+
* still belongs to the streaming toggle this command took its name from. A
|
|
895
|
+
* keyboard from that older menu can be sitting in someone's chat right now,
|
|
896
|
+
* and its buttons carry `mode:streaming`.
|
|
897
|
+
*/
|
|
898
|
+
/**
|
|
899
|
+
* What "Default" actually resolves to for this chat, and why.
|
|
900
|
+
*
|
|
901
|
+
* The menu used to call it "what this bot has always used" — true, and no help
|
|
902
|
+
* at all to someone deciding whether to leave it there. Which mode that is
|
|
903
|
+
* depends on the chat's transport, and on DANGEROUS_MODE when the transport is
|
|
904
|
+
* the SDK, so the row names the mode and the reason rather than making a
|
|
905
|
+
* person read two files to find out what they already picked.
|
|
906
|
+
*/
|
|
907
|
+
function describeTransportDefault(scope) {
|
|
908
|
+
const method = getActiveMethod(scope);
|
|
909
|
+
const label = permissionModeInfo(transportDefaultMode(method, config.DANGEROUS_MODE)).label;
|
|
910
|
+
if (method === 'pty')
|
|
911
|
+
return { label, why: "Claude Code's own default" };
|
|
912
|
+
return { label, why: config.DANGEROUS_MODE ? 'SDK, DANGEROUS_MODE=true' : 'the SDK default' };
|
|
913
|
+
}
|
|
914
|
+
function buildPermissionModeMenu(scope) {
|
|
915
|
+
const current = userPreferences.getPermissionMode(scope);
|
|
916
|
+
const fallback = describeTransportDefault(scope);
|
|
917
|
+
const keyboard = PERMISSION_MODES.map((info) => [{
|
|
918
|
+
text: info.id === current ? `✓ ${info.label}` : info.label,
|
|
919
|
+
callback_data: `permmode:${info.id}`,
|
|
920
|
+
}]);
|
|
921
|
+
keyboard.push([{
|
|
922
|
+
text: `${current ? '' : '✓ '}Default — ${fallback.label}`,
|
|
923
|
+
callback_data: 'permmode:default',
|
|
924
|
+
}]);
|
|
925
|
+
const text = new EntityText().add('🔐 ').bold('Permission mode').add('\n\nCurrent: ');
|
|
926
|
+
// Named the same way whether or not it was chosen: the mode a turn runs in
|
|
927
|
+
// is the useful fact, and "Default" alone never told anyone what that was.
|
|
928
|
+
if (current) {
|
|
929
|
+
text.bold(permissionModeInfo(current).label);
|
|
930
|
+
}
|
|
931
|
+
else {
|
|
932
|
+
text.bold(fallback.label).add(' ').italic(`(default — ${fallback.why})`);
|
|
933
|
+
}
|
|
934
|
+
text.newline(2);
|
|
935
|
+
for (const info of PERMISSION_MODES) {
|
|
936
|
+
text.add('• ').bold(info.label).add(` - ${info.description}\n`);
|
|
937
|
+
}
|
|
938
|
+
text.add('• ').bold('Default').add(' - follow the transport, which here means ')
|
|
939
|
+
.bold(fallback.label)
|
|
940
|
+
.newline(2)
|
|
941
|
+
.italic("Takes effect on your next message. Modes that ask will put Claude Code's own prompts in the chat as buttons.");
|
|
942
|
+
return { text: text.build(), keyboard };
|
|
943
|
+
}
|
|
944
|
+
/** Confirmation text shared by the command and its buttons. */
|
|
945
|
+
function permissionModeSetText(id) {
|
|
946
|
+
const info = permissionModeInfo(id);
|
|
947
|
+
return new EntityText()
|
|
948
|
+
.add('✅ Permission mode set to ').bold(info.label).newline(2)
|
|
949
|
+
.italic(info.description)
|
|
950
|
+
.build();
|
|
951
|
+
}
|
|
952
|
+
/** Same, for the reset — which names the mode it reset *to*, not just "default". */
|
|
953
|
+
function permissionModeResetText(scope) {
|
|
954
|
+
const { label, why } = describeTransportDefault(scope);
|
|
955
|
+
return new EntityText()
|
|
956
|
+
.add('✅ Permission mode reset to the transport default: ').bold(label).newline(2)
|
|
957
|
+
.italic(why)
|
|
958
|
+
.build();
|
|
959
|
+
}
|
|
960
|
+
export async function handlePermissionMode(ctx) {
|
|
961
|
+
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
962
|
+
if (!keyInfo)
|
|
963
|
+
return;
|
|
964
|
+
const { sessionKey } = keyInfo;
|
|
965
|
+
const arg = (ctx.message?.text || '').split(' ').slice(1).join(' ').trim();
|
|
966
|
+
if (!arg) {
|
|
967
|
+
const { text, keyboard } = buildPermissionModeMenu(sessionKey);
|
|
968
|
+
await replyFormatted(ctx, text, {
|
|
969
|
+
reply_markup: { inline_keyboard: keyboard },
|
|
970
|
+
});
|
|
971
|
+
return;
|
|
972
|
+
}
|
|
973
|
+
const lower = arg.toLowerCase();
|
|
974
|
+
if (lower === 'default' || lower === 'reset') {
|
|
975
|
+
userPreferences.clearPermissionMode(sessionKey);
|
|
976
|
+
await replyFormatted(ctx, permissionModeResetText(sessionKey));
|
|
977
|
+
return;
|
|
978
|
+
}
|
|
979
|
+
const parsed = parsePermissionModeArg(arg);
|
|
980
|
+
if (!parsed) {
|
|
981
|
+
const valid = new EntityText().add(`❌ Unknown mode "${arg}".\n\nValid: `);
|
|
982
|
+
for (const m of PERMISSION_MODES)
|
|
983
|
+
valid.code(m.id).add(', ');
|
|
984
|
+
await replyFormatted(ctx, valid.code('default').build());
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
987
|
+
userPreferences.setPermissionMode(sessionKey, parsed);
|
|
988
|
+
await replyFormatted(ctx, permissionModeSetText(parsed));
|
|
989
|
+
}
|
|
990
|
+
export async function handlePermissionModeCallback(ctx) {
|
|
991
|
+
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
992
|
+
if (!keyInfo)
|
|
993
|
+
return;
|
|
994
|
+
const { sessionKey } = keyInfo;
|
|
995
|
+
const data = ctx.callbackQuery?.data;
|
|
996
|
+
if (!data || !data.startsWith('permmode:'))
|
|
997
|
+
return;
|
|
998
|
+
const choice = data.replace('permmode:', '');
|
|
999
|
+
if (choice === 'default') {
|
|
1000
|
+
userPreferences.clearPermissionMode(sessionKey);
|
|
1001
|
+
const { label } = describeTransportDefault(sessionKey);
|
|
1002
|
+
await ctx.answerCallbackQuery({ text: `Default: ${label}` });
|
|
1003
|
+
await editCallbackMessage(ctx, permissionModeResetText(sessionKey));
|
|
1004
|
+
return;
|
|
1005
|
+
}
|
|
1006
|
+
if (!isPermissionModeId(choice))
|
|
1007
|
+
return;
|
|
1008
|
+
userPreferences.setPermissionMode(sessionKey, choice);
|
|
1009
|
+
await ctx.answerCallbackQuery({ text: `Mode: ${permissionModeInfo(choice).label}` });
|
|
1010
|
+
await editCallbackMessage(ctx, permissionModeSetText(choice));
|
|
1011
|
+
}
|
|
1012
|
+
//# sourceMappingURL=settings.js.map
|