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
|
@@ -2,9 +2,6 @@ import { InputFile, GrammyError } from 'grammy';
|
|
|
2
2
|
import { config } from '../config.js';
|
|
3
3
|
import { formatMarkdown, markdownToEntities, splitEntityMessage, MAX_MESSAGE_LENGTH } from './markdown.js';
|
|
4
4
|
import { editFormatted, replyFormatted } from './send.js';
|
|
5
|
-
import { stripReasoningSummary } from '../utils/reasoning-summary.js';
|
|
6
|
-
import { shouldPublishTelegraph, createTelegraphPage, createTelegraphFromFile } from './telegraph.js';
|
|
7
|
-
import { isTerminalUIEnabled } from './terminal-settings.js';
|
|
8
5
|
import { getSpinnerFrame, getThinkingVerb, getToolIcon, getToolAction, renderStatusLine, renderBackgroundFooter, extractToolDetail, formatBashCommandBlock, elideToolOutput, stripAnsi, TOOL_ICONS, } from './terminal-renderer.js';
|
|
9
6
|
import { taskTracker } from './task-tracker.js';
|
|
10
7
|
import { taskListDisplay } from './task-list.js';
|
|
@@ -23,24 +20,30 @@ import { getPremiumModel } from '../providers/provider-router.js';
|
|
|
23
20
|
import * as fs from 'fs';
|
|
24
21
|
import * as path from 'path';
|
|
25
22
|
import { isClaudeAuthError } from '../claude/claude-auth.js';
|
|
26
|
-
export const
|
|
23
|
+
export const BRANCH_KEYBOARD = { inline_keyboard: [[{ text: '🌱 Branch', callback_data: 'branch:pick' }]] };
|
|
27
24
|
/**
|
|
28
|
-
* The buttons on the banner where a chat switched conversations:
|
|
25
|
+
* The buttons on the banner where a chat switched conversations: branch that
|
|
29
26
|
* point again, or open the tree of branches it belongs to.
|
|
30
27
|
*/
|
|
31
28
|
export const BRANCH_MARKER_KEYBOARD = {
|
|
32
29
|
inline_keyboard: [[
|
|
33
|
-
{ text: '
|
|
30
|
+
{ text: '🌱 Branch', callback_data: 'branch:pick' },
|
|
34
31
|
{ text: '🌳 Tree', callback_data: 'tree:show' },
|
|
35
32
|
]],
|
|
36
33
|
};
|
|
37
34
|
/**
|
|
38
35
|
* Status-bubble text shown while an ask_user question is waiting on a tap.
|
|
39
|
-
* Replaces the spinner:
|
|
40
|
-
*
|
|
41
|
-
* that is actually parked on the user.
|
|
36
|
+
* Replaces the spinner: nothing else stops the bubble animating "Thinking…"
|
|
37
|
+
* at a turn that is actually parked on the user.
|
|
42
38
|
*/
|
|
43
39
|
const AWAITING_ANSWER_LINE = '⏸️ Waiting for your answer — see the question below ↓';
|
|
40
|
+
/**
|
|
41
|
+
* The status line's offer to move the running command to the background, for
|
|
42
|
+
* as long as Claude Code's own screen makes it: "(ctrl+b to run in
|
|
43
|
+
* background)" there, the command that presses that key here. A command in a
|
|
44
|
+
* message is one tap to send.
|
|
45
|
+
*/
|
|
46
|
+
export const BACKGROUND_HINT_LINE = ' ⎿ /ctrlb to run in background';
|
|
44
47
|
/**
|
|
45
48
|
* Status-bubble text once the action log has taken the live status line over.
|
|
46
49
|
* The log is posted below the bubble and is usually tall enough to push it off
|
|
@@ -58,7 +61,7 @@ const LOG_STATUS_DETAIL_CHARS = 200;
|
|
|
58
61
|
* Register a suggestion in the pending-suggestions store and decide how it
|
|
59
62
|
* reaches the user: on a button when it fits there whole, otherwise on a card
|
|
60
63
|
* of its own. Returns null when there is no suggestion for this turn (the
|
|
61
|
-
* caller still gets its
|
|
64
|
+
* caller still gets its branch button).
|
|
62
65
|
*/
|
|
63
66
|
function planSuggestion(sessionKey, suggestion) {
|
|
64
67
|
const text = flattenSuggestion(suggestion ?? '');
|
|
@@ -68,7 +71,6 @@ function planSuggestion(sessionKey, suggestion) {
|
|
|
68
71
|
const id = storeSuggestion(sessionKey, text, onButton ? 'button' : 'card');
|
|
69
72
|
return { id, text, onButton };
|
|
70
73
|
}
|
|
71
|
-
const TYPING_INTERVAL_MS = 4000; // Send typing every 4 seconds
|
|
72
74
|
const MIN_EDIT_INTERVAL_MS = 10000; // Minimum time between status-only edits (~5 edits/min safe zone)
|
|
73
75
|
/**
|
|
74
76
|
* Minimum time between edits that show more of the reply. Telegram allows a
|
|
@@ -81,10 +83,7 @@ const GROUP_STREAM_EDIT_INTERVAL_MS = 3500;
|
|
|
81
83
|
const MAX_STREAM_EDIT_INTERVAL_MS = 15000;
|
|
82
84
|
/** How long after new text the status line keeps saying "Writing". */
|
|
83
85
|
const WRITING_WINDOW_MS = 4000;
|
|
84
|
-
/**
|
|
85
|
-
* Under a reply that is still being written, where the status line would be
|
|
86
|
-
* without the terminal UI: the text above it isn't final yet.
|
|
87
|
-
*/
|
|
86
|
+
/** On the status line while the reply is being written: the text above it isn't final yet. */
|
|
88
87
|
const STREAMING_INDICATOR = '✍️ Writing…';
|
|
89
88
|
/**
|
|
90
89
|
* Tacked onto the status line's first line while a premium model is on, so a
|
|
@@ -94,64 +93,6 @@ const STREAMING_INDICATOR = '✍️ Writing…';
|
|
|
94
93
|
function premiumBadge(model) {
|
|
95
94
|
return model ? ` · ${PREMIUM_MODEL_ICON} ${model}` : '';
|
|
96
95
|
}
|
|
97
|
-
const MONITOR_TASK_TYPE = 'monitor_mcp';
|
|
98
|
-
/**
|
|
99
|
-
* How a background task is named in its start line and the completion that
|
|
100
|
-
* replaces it, by the SDK's task_type. The same icons as the PTY card's.
|
|
101
|
-
*/
|
|
102
|
-
function taskKind(taskType) {
|
|
103
|
-
switch (taskType) {
|
|
104
|
-
case MONITOR_TASK_TYPE: return { icon: '📡', label: 'Monitor' };
|
|
105
|
-
case 'local_bash': return { icon: '⚙️', label: 'Command' };
|
|
106
|
-
case 'local_agent': return { icon: '🤖', label: 'Subagent' };
|
|
107
|
-
case 'local_workflow': return { icon: '📋', label: 'Workflow' };
|
|
108
|
-
default: return { icon: '⚙️', label: 'Task' };
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
function shortDescription(description) {
|
|
112
|
-
return description.length > 100 ? description.substring(0, 97) + '...' : description;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Publish a long reply as an Instant View page and return the footer line that
|
|
116
|
-
* points at it, or null when the chat hasn't asked for pages, the reply is
|
|
117
|
-
* short, or telegra.ph is unreachable.
|
|
118
|
-
*
|
|
119
|
-
* Every failure path returns null rather than throwing. The page is decoration
|
|
120
|
-
* on an answer that is about to be delivered in full either way, so a Telegraph
|
|
121
|
-
* outage must never cost the user the reply — which is exactly what the old
|
|
122
|
-
* publish-or-nothing flow did when it swapped the text out for a 200-character
|
|
123
|
-
* stub and the link then failed to render.
|
|
124
|
-
*/
|
|
125
|
-
async function publishTelegraphFooter(text, sessionKey) {
|
|
126
|
-
if (!shouldPublishTelegraph(text, sessionKey))
|
|
127
|
-
return null;
|
|
128
|
-
try {
|
|
129
|
-
const pageUrl = await createTelegraphPage('Claude Response', text);
|
|
130
|
-
if (!pageUrl)
|
|
131
|
-
return null;
|
|
132
|
-
return new EntityText().add('📄 ').link('Open in Instant View', pageUrl).build();
|
|
133
|
-
}
|
|
134
|
-
catch (error) {
|
|
135
|
-
console.error('[Telegraph] Failed to publish page:', error instanceof Error ? error.message : error);
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Hang `footer` under the last chunk of a reply, or give it a chunk of its own
|
|
141
|
-
* when appending would push that message past Telegram's limit.
|
|
142
|
-
*
|
|
143
|
-
* Exported for tests: the boundary is the whole point of the function, and it
|
|
144
|
-
* is the one place a bug would silently cost a chunk.
|
|
145
|
-
*/
|
|
146
|
-
export function withTelegraphFooter(parts, footer) {
|
|
147
|
-
if (!footer)
|
|
148
|
-
return parts;
|
|
149
|
-
const last = parts[parts.length - 1];
|
|
150
|
-
if (last !== undefined && last.text.length + 2 + footer.text.length <= config.MAX_MESSAGE_LENGTH) {
|
|
151
|
-
return [...parts.slice(0, -1), new EntityText().append(last).newline(2).append(footer).build()];
|
|
152
|
-
}
|
|
153
|
-
return [...parts, footer];
|
|
154
|
-
}
|
|
155
96
|
// `mcp__telecoder-tools__telecoder_send_file` → `telecoder_send_file`
|
|
156
97
|
function stripMcpServerPrefix(toolName) {
|
|
157
98
|
if (!toolName.startsWith('mcp__'))
|
|
@@ -207,6 +148,11 @@ export function renderStatusBubble(view) {
|
|
|
207
148
|
else {
|
|
208
149
|
b.add(`${getSpinnerFrame(view.spinnerIndex)} ${TOOL_ICONS.thinking} ${getThinkingVerb()}...${premiumBadge(view.premiumModel)}`);
|
|
209
150
|
}
|
|
151
|
+
// What can be done about a command that is taking long comes before a tip
|
|
152
|
+
// about something else. Not while a question is pending: the turn is
|
|
153
|
+
// waiting on the answer, not on the command.
|
|
154
|
+
if (view.backgroundHint && !view.awaitingAnswer)
|
|
155
|
+
b.newline().add(BACKGROUND_HINT_LINE);
|
|
210
156
|
// Mirror Claude Code's live spinner tip under the status line, as the TUI
|
|
211
157
|
// shows it. Suppressed while a question is pending — the tip is whatever was
|
|
212
158
|
// on screen when the model blocked, and it dilutes the one line that matters.
|
|
@@ -251,12 +197,10 @@ export class MessageSender {
|
|
|
251
197
|
*
|
|
252
198
|
* Returns the message_id of the last Telegram message posted, or null if
|
|
253
199
|
* nothing was sent (every attempt failed). Callers that want to attach the
|
|
254
|
-
* /
|
|
200
|
+
* /branch button use this to know which message to anchor onto.
|
|
255
201
|
*/
|
|
256
202
|
async sendMessage(ctx, text) {
|
|
257
|
-
|
|
258
|
-
const parts = withTelegraphFooter(formatMarkdown(text, config.MAX_MESSAGE_LENGTH), await publishTelegraphFooter(text, keyInfo?.sessionKey));
|
|
259
|
-
return this.sendParts(ctx, parts);
|
|
203
|
+
return this.sendParts(ctx, formatMarkdown(text, config.MAX_MESSAGE_LENGTH));
|
|
260
204
|
}
|
|
261
205
|
/** Post `parts` in order; the id of the last one that went out. */
|
|
262
206
|
async sendParts(ctx, parts) {
|
|
@@ -273,19 +217,25 @@ export class MessageSender {
|
|
|
273
217
|
catch { /* give up */ }
|
|
274
218
|
}
|
|
275
219
|
}
|
|
220
|
+
// Posted during a turn, this is the lowest message of the turn so far:
|
|
221
|
+
// finishStreaming anchors the branch button here when nothing follows it.
|
|
222
|
+
const sessionKey = getSessionKeyFromCtx(ctx)?.sessionKey;
|
|
223
|
+
const state = sessionKey ? this.streamStates.get(sessionKey) : undefined;
|
|
224
|
+
if (state && lastMessageId !== null)
|
|
225
|
+
state.lastPostId = lastMessageId;
|
|
276
226
|
return lastMessageId;
|
|
277
227
|
}
|
|
278
228
|
/**
|
|
279
|
-
* Attach a "
|
|
229
|
+
* Attach a "🌱 Branch" button to a past assistant message and record the
|
|
280
230
|
* JSONL truncation point that corresponds to it. Idempotent: calling this
|
|
281
231
|
* twice on the same message just re-records the offset (Telegram returns
|
|
282
232
|
* "message is not modified" on the second edit, which we swallow).
|
|
283
233
|
*
|
|
284
234
|
* Safe to call when there's no active claudeSessionId or JSONL yet — we
|
|
285
235
|
* silently skip in that case so the assistant turn isn't blocked by a
|
|
286
|
-
*
|
|
236
|
+
* branch-tracking edge case.
|
|
287
237
|
*/
|
|
288
|
-
async
|
|
238
|
+
async attachBranchButton(ctx, sessionKey, messageId, suggestion = null) {
|
|
289
239
|
if (!messageId)
|
|
290
240
|
return;
|
|
291
241
|
const session = sessionManager.getSession(sessionKey);
|
|
@@ -302,7 +252,7 @@ export class MessageSender {
|
|
|
302
252
|
conversationId: session.conversationId,
|
|
303
253
|
});
|
|
304
254
|
// A suggestion short enough to read on a button goes on a row above the
|
|
305
|
-
//
|
|
255
|
+
// branch button, so it is the primary call-to-action and branch stays as the
|
|
306
256
|
// secondary affordance. A longer one is not put here at all — it would
|
|
307
257
|
// arrive clipped — and {@link sendSuggestionCard} gives it its own
|
|
308
258
|
// message instead.
|
|
@@ -313,8 +263,8 @@ export class MessageSender {
|
|
|
313
263
|
callback_data: `sgt:${suggestion.id}`,
|
|
314
264
|
}]);
|
|
315
265
|
}
|
|
316
|
-
rows.push([{ text: '
|
|
317
|
-
const replyMarkup = rows.length === 1 ?
|
|
266
|
+
rows.push([{ text: '🌱 Branch', callback_data: 'branch:pick' }]);
|
|
267
|
+
const replyMarkup = rows.length === 1 ? BRANCH_KEYBOARD : { inline_keyboard: rows };
|
|
318
268
|
try {
|
|
319
269
|
await ctx.api.editMessageReplyMarkup(ctx.chat.id, messageId, { reply_markup: replyMarkup });
|
|
320
270
|
}
|
|
@@ -322,7 +272,7 @@ export class MessageSender {
|
|
|
322
272
|
// "message is not modified" or "message to edit not found" — non-fatal.
|
|
323
273
|
const msg = err instanceof Error ? err.message.toLowerCase() : '';
|
|
324
274
|
if (!msg.includes('not modified') && !msg.includes('not found') && !msg.includes('message_id_invalid')) {
|
|
325
|
-
console.debug('[
|
|
275
|
+
console.debug('[Branch] attachBranchButton edit failed:', err instanceof Error ? err.message : err);
|
|
326
276
|
}
|
|
327
277
|
}
|
|
328
278
|
}
|
|
@@ -371,63 +321,20 @@ export class MessageSender {
|
|
|
371
321
|
return false;
|
|
372
322
|
}
|
|
373
323
|
}
|
|
374
|
-
/**
|
|
375
|
-
* Send a markdown file with Telegraph preview option
|
|
376
|
-
*/
|
|
377
|
-
async sendMarkdownFile(ctx, filePath, options = {}) {
|
|
378
|
-
const { useTelegraph = true, sendAsDocument = false } = options;
|
|
379
|
-
try {
|
|
380
|
-
if (!fs.existsSync(filePath)) {
|
|
381
|
-
console.error('[Markdown] File not found:', filePath);
|
|
382
|
-
return false;
|
|
383
|
-
}
|
|
384
|
-
const fileName = path.basename(filePath);
|
|
385
|
-
const content = fs.readFileSync(filePath, 'utf-8');
|
|
386
|
-
// Option 1: Telegraph (Instant View)
|
|
387
|
-
if (useTelegraph) {
|
|
388
|
-
const pageUrl = await createTelegraphFromFile(filePath);
|
|
389
|
-
if (pageUrl) {
|
|
390
|
-
const message = new EntityText()
|
|
391
|
-
.add('📄 ').bold(fileName).newline(2)
|
|
392
|
-
.link('Open in Instant View', pageUrl)
|
|
393
|
-
.build();
|
|
394
|
-
await replyFormatted(ctx, message);
|
|
395
|
-
// Also send as document if requested
|
|
396
|
-
if (sendAsDocument) {
|
|
397
|
-
await this.sendDocument(ctx, filePath, 'Download file');
|
|
398
|
-
}
|
|
399
|
-
return true;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
// Option 2: Send as document
|
|
403
|
-
if (sendAsDocument) {
|
|
404
|
-
return await this.sendDocument(ctx, filePath, `📎 ${fileName}`);
|
|
405
|
-
}
|
|
406
|
-
// Option 3: Send content inline
|
|
407
|
-
await this.sendMessage(ctx, content);
|
|
408
|
-
return true;
|
|
409
|
-
}
|
|
410
|
-
catch (error) {
|
|
411
|
-
console.error('[Markdown] Failed to send:', error);
|
|
412
|
-
return false;
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
324
|
async startStreaming(ctx, prompt) {
|
|
416
325
|
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
417
326
|
if (!keyInfo)
|
|
418
327
|
return;
|
|
419
328
|
const { chatId, threadId, sessionKey } = keyInfo;
|
|
420
|
-
const terminalMode = isTerminalUIEnabled(sessionKey);
|
|
421
329
|
const verbosityFlags = resolveVerbosityFlags(chatId);
|
|
422
330
|
const actionLogEnabled = verbosityFlags.useActionLog && (verbosityFlags.showToolResults || verbosityFlags.showDiffs);
|
|
423
331
|
const premiumModel = getPremiumModel(sessionKey);
|
|
424
332
|
const initialText = `${getSpinnerFrame(0)} ${TOOL_ICONS.thinking} ${getThinkingVerb()}...${premiumBadge(premiumModel)}`;
|
|
333
|
+
// No "typing…": the turn has a live status line — in the bubble, then at
|
|
334
|
+
// the bottom of the action log — and Telegram Desktop draws the typing
|
|
335
|
+
// animation on the CPU for as long as it is up, which renewed every few
|
|
336
|
+
// seconds is the whole turn.
|
|
425
337
|
const message = await ctx.reply(initialText);
|
|
426
|
-
// "typing…" only for a turn with no live status line. Terminal mode has
|
|
427
|
-
// one — in the bubble, then at the bottom of the action log — and Telegram
|
|
428
|
-
// Desktop draws the typing animation on the CPU for as long as it is up,
|
|
429
|
-
// which renewed every few seconds is the whole turn.
|
|
430
|
-
const typingInterval = terminalMode ? null : this.startTypingIndicator(ctx.api, chatId, threadId);
|
|
431
338
|
const now = Date.now();
|
|
432
339
|
const state = {
|
|
433
340
|
chatId,
|
|
@@ -439,14 +346,12 @@ export class MessageSender {
|
|
|
439
346
|
shownContent: '',
|
|
440
347
|
shown: [],
|
|
441
348
|
overflowIds: [],
|
|
349
|
+
lastPostId: null,
|
|
442
350
|
flushTimer: null,
|
|
443
351
|
liveEdits: new Set(),
|
|
444
352
|
ended: false,
|
|
445
353
|
streamIntervalMs: ctx.chat?.type === 'private' ? STREAM_EDIT_INTERVAL_MS : GROUP_STREAM_EDIT_INTERVAL_MS,
|
|
446
354
|
lastUpdate: now,
|
|
447
|
-
typingInterval,
|
|
448
|
-
// Terminal UI mode
|
|
449
|
-
terminalMode,
|
|
450
355
|
spinnerIndex: 0,
|
|
451
356
|
spinnerInterval: null,
|
|
452
357
|
currentOperation: null,
|
|
@@ -454,6 +359,7 @@ export class MessageSender {
|
|
|
454
359
|
rateLimitedUntil: 0,
|
|
455
360
|
lastRateLimitDurationMs: 0,
|
|
456
361
|
tip: null,
|
|
362
|
+
backgroundHint: false,
|
|
457
363
|
actionLogEnabled,
|
|
458
364
|
prompt,
|
|
459
365
|
premiumModel,
|
|
@@ -477,14 +383,12 @@ export class MessageSender {
|
|
|
477
383
|
}
|
|
478
384
|
}
|
|
479
385
|
// Periodic refresh so the elapsed timer and spinner update even during long tool runs
|
|
480
|
-
|
|
481
|
-
state.
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
}, MIN_EDIT_INTERVAL_MS);
|
|
487
|
-
}
|
|
386
|
+
state.spinnerInterval = setInterval(() => {
|
|
387
|
+
state.spinnerIndex += 1;
|
|
388
|
+
if (ctx) {
|
|
389
|
+
this.flushLive(ctx, state).catch(() => { });
|
|
390
|
+
}
|
|
391
|
+
}, MIN_EDIT_INTERVAL_MS);
|
|
488
392
|
}
|
|
489
393
|
stopSpinnerAnimation(state) {
|
|
490
394
|
if (state.spinnerInterval) {
|
|
@@ -496,24 +400,6 @@ export class MessageSender {
|
|
|
496
400
|
state.flushTimer = null;
|
|
497
401
|
}
|
|
498
402
|
}
|
|
499
|
-
startTypingIndicator(api, chatId, threadId) {
|
|
500
|
-
const opts = threadId !== undefined ? { message_thread_id: threadId } : {};
|
|
501
|
-
// Send typing immediately
|
|
502
|
-
api.sendChatAction(chatId, 'typing', opts).catch(() => { });
|
|
503
|
-
// Then send every TYPING_INTERVAL_MS
|
|
504
|
-
return setInterval(() => {
|
|
505
|
-
api.sendChatAction(chatId, 'typing', opts).catch(() => { });
|
|
506
|
-
}, TYPING_INTERVAL_MS);
|
|
507
|
-
}
|
|
508
|
-
stopTypingIndicator(state) {
|
|
509
|
-
if (state.typingInterval) {
|
|
510
|
-
clearInterval(state.typingInterval);
|
|
511
|
-
state.typingInterval = null;
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
stopTypingInterval(interval) {
|
|
515
|
-
clearInterval(interval);
|
|
516
|
-
}
|
|
517
403
|
/**
|
|
518
404
|
* Update the current tool operation (terminal UI mode).
|
|
519
405
|
* Event-driven: triggers a status message edit on each tool change.
|
|
@@ -527,10 +413,8 @@ export class MessageSender {
|
|
|
527
413
|
if (ctx) {
|
|
528
414
|
taskListDisplay.noteToolStart(ctx.api, sessionKey, toolName, sessionManager.getSession(sessionKey)?.claudeSessionId);
|
|
529
415
|
}
|
|
530
|
-
if (!state.terminalMode)
|
|
531
|
-
return;
|
|
532
416
|
const { chatId } = parseSessionKey(sessionKey);
|
|
533
|
-
const verbose = resolveVerbosityFlags(chatId).
|
|
417
|
+
const verbose = resolveVerbosityFlags(chatId).fullToolInputs;
|
|
534
418
|
if (toolName === 'Bash') {
|
|
535
419
|
// Show the full command in a block beneath the header (capped per the
|
|
536
420
|
// verbose flag) instead of just its first line on the `→` row — a leading
|
|
@@ -558,85 +442,6 @@ export class MessageSender {
|
|
|
558
442
|
return;
|
|
559
443
|
state.currentOperation = null;
|
|
560
444
|
}
|
|
561
|
-
/**
|
|
562
|
-
* Apply an SDK task lifecycle event. Updates the per-session task tracker,
|
|
563
|
-
* posts a line when a backgrounded task starts (edited in place when it
|
|
564
|
-
* ends), surfaces Monitor events as their own chat messages, and refreshes
|
|
565
|
-
* the streaming UI footer.
|
|
566
|
-
*/
|
|
567
|
-
async notifyTaskEvent(ctx, sessionKey, event) {
|
|
568
|
-
const wasBackgrounded = event.type === 'updated'
|
|
569
|
-
? taskTracker.getTask(sessionKey, event.taskId)?.isBackgrounded
|
|
570
|
-
: undefined;
|
|
571
|
-
const state = taskTracker.handleEvent(sessionKey, event);
|
|
572
|
-
const isMonitor = state?.taskType === MONITOR_TASK_TYPE;
|
|
573
|
-
if (event.type === 'started' && state?.isBackgrounded) {
|
|
574
|
-
await this.postTaskStarted(ctx, state);
|
|
575
|
-
}
|
|
576
|
-
else if (event.type === 'updated' && state?.isBackgrounded && wasBackgrounded === false
|
|
577
|
-
&& state.status === 'running') {
|
|
578
|
-
// A shell moved to the background partway through says so only here.
|
|
579
|
-
await this.postTaskStarted(ctx, state);
|
|
580
|
-
}
|
|
581
|
-
else if (event.type === 'progress' && state && isMonitor) {
|
|
582
|
-
const eventText = event.summary ?? event.description;
|
|
583
|
-
if (eventText)
|
|
584
|
-
await this.postMonitorEvent(ctx, state, eventText);
|
|
585
|
-
}
|
|
586
|
-
else if (event.type === 'notification' && state) {
|
|
587
|
-
await this.postTaskCompletion(ctx, state);
|
|
588
|
-
taskTracker.remove(sessionKey, event.taskId);
|
|
589
|
-
}
|
|
590
|
-
const streamState = this.streamStates.get(sessionKey);
|
|
591
|
-
if (streamState && streamState.terminalMode) {
|
|
592
|
-
streamState.spinnerIndex += 1;
|
|
593
|
-
this.flushLive(ctx, streamState).catch(() => { });
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
/**
|
|
597
|
-
* Say in the chat what just started in the background, rather than leave it
|
|
598
|
-
* to the footer's count. Silent: the user is in the chat, mid-turn. The
|
|
599
|
-
* line is kept by id so the completion can replace it.
|
|
600
|
-
*/
|
|
601
|
-
async postTaskStarted(ctx, task) {
|
|
602
|
-
if (task.skipTranscript || task.armedMessageId !== undefined)
|
|
603
|
-
return;
|
|
604
|
-
const { icon, label } = taskKind(task.taskType);
|
|
605
|
-
const description = shortDescription(task.description);
|
|
606
|
-
const text = task.taskType === MONITOR_TASK_TYPE
|
|
607
|
-
? `${icon} ${label} "${description}" armed`
|
|
608
|
-
: `${icon} ${label} "${description}" running in background`;
|
|
609
|
-
try {
|
|
610
|
-
const posted = await replyFormatted(ctx, text, { disable_notification: true });
|
|
611
|
-
task.armedMessageId = posted.message_id;
|
|
612
|
-
this.noteInterveningPost(getSessionKeyFromCtx(ctx)?.sessionKey);
|
|
613
|
-
}
|
|
614
|
-
catch (error) {
|
|
615
|
-
console.error('[Task] Failed to post task start:', error instanceof Error ? error.message : error);
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
async postMonitorEvent(ctx, task, eventText) {
|
|
619
|
-
if (task.skipTranscript)
|
|
620
|
-
return;
|
|
621
|
-
// Use action logging if enabled
|
|
622
|
-
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
623
|
-
const sessionKey = keyInfo?.sessionKey;
|
|
624
|
-
if (sessionKey && actionLogger.isActive(sessionKey)) {
|
|
625
|
-
await actionLogger.addMonitorEvent(sessionKey, task, eventText);
|
|
626
|
-
return;
|
|
627
|
-
}
|
|
628
|
-
// Fall back to original behavior
|
|
629
|
-
const truncated = eventText.length > 1000
|
|
630
|
-
? eventText.substring(0, 997) + '...'
|
|
631
|
-
: eventText;
|
|
632
|
-
try {
|
|
633
|
-
await replyFormatted(ctx, `📡 Monitor event: ${truncated}`);
|
|
634
|
-
this.noteInterveningPost(sessionKey);
|
|
635
|
-
}
|
|
636
|
-
catch (error) {
|
|
637
|
-
console.error('[Task] Failed to post monitor event:', error instanceof Error ? error.message : error);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
445
|
/**
|
|
641
446
|
* Post the "🔔 Scheduled: …" header that precedes a scheduled-task fire.
|
|
642
447
|
* The scheduled prompt itself is then enqueued through the normal turn
|
|
@@ -659,18 +464,6 @@ export class MessageSender {
|
|
|
659
464
|
}
|
|
660
465
|
this.noteInterveningPost(getSessionKeyFromCtx(ctx)?.sessionKey);
|
|
661
466
|
}
|
|
662
|
-
/**
|
|
663
|
-
* Post the model's text response from an SDK-driven sub-turn (monitor
|
|
664
|
-
* event echoes, post-task_notification commentary) as its own Telegram
|
|
665
|
-
* message, its markdown rendered as for any reply.
|
|
666
|
-
*/
|
|
667
|
-
async postSubTurnResponse(ctx, text) {
|
|
668
|
-
const trimmed = text.trim();
|
|
669
|
-
if (!trimmed)
|
|
670
|
-
return;
|
|
671
|
-
await this.sendParts(ctx, formatMarkdown(trimmed, config.MAX_MESSAGE_LENGTH));
|
|
672
|
-
this.noteInterveningPost(getSessionKeyFromCtx(ctx)?.sessionKey);
|
|
673
|
-
}
|
|
674
467
|
/**
|
|
675
468
|
* If action-log mode is on for this chat AND the verbosity tier shows tool
|
|
676
469
|
* output, lazily initialize the logger and hand off to `forward`. Returns
|
|
@@ -693,7 +486,7 @@ export class MessageSender {
|
|
|
693
486
|
// ended and the log was collapsed and cleaned up (5s after finishStream),
|
|
694
487
|
// and initializing here would start a *second*, live-looking action log
|
|
695
488
|
// below the collapsed summary. Stragglers post as their own message
|
|
696
|
-
// instead
|
|
489
|
+
// instead.
|
|
697
490
|
const stream = this.streamStates.get(sessionKey);
|
|
698
491
|
if (!stream) {
|
|
699
492
|
console.debug(`[ActionLog] Straggler for ${sessionKey} after log cleanup — posting directly instead of opening a new log`);
|
|
@@ -777,75 +570,6 @@ export class MessageSender {
|
|
|
777
570
|
console.error('[EditDiff] Failed to post:', err instanceof Error ? err.message : err);
|
|
778
571
|
}
|
|
779
572
|
}
|
|
780
|
-
async postTaskCompletion(ctx, task) {
|
|
781
|
-
// Skip ambient/housekeeping tasks and foreground subagents — only
|
|
782
|
-
// backgrounded tasks deserve a separate notification message.
|
|
783
|
-
if (task.skipTranscript)
|
|
784
|
-
return;
|
|
785
|
-
if (!task.isBackgrounded)
|
|
786
|
-
return;
|
|
787
|
-
// Without a start line to replace, an action log takes the completion.
|
|
788
|
-
// With one, the start line is where it goes, so it can't sit on
|
|
789
|
-
// "running" after the task ended.
|
|
790
|
-
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
791
|
-
const sessionKey = keyInfo?.sessionKey;
|
|
792
|
-
if (task.armedMessageId === undefined && sessionKey && actionLogger.isActive(sessionKey)) {
|
|
793
|
-
await actionLogger.addTaskCompletion(sessionKey, task);
|
|
794
|
-
return;
|
|
795
|
-
}
|
|
796
|
-
const isMonitor = task.taskType === MONITOR_TASK_TYPE;
|
|
797
|
-
const { label } = taskKind(task.taskType);
|
|
798
|
-
const statusIcon = task.status === 'completed'
|
|
799
|
-
? (isMonitor ? '📡' : '✅')
|
|
800
|
-
: task.status === 'stopped' ? '🛑' : '❌';
|
|
801
|
-
const verb = task.status === 'completed'
|
|
802
|
-
? (isMonitor ? 'stream ended' : 'completed')
|
|
803
|
-
: task.status === 'stopped' ? 'stopped' : 'failed';
|
|
804
|
-
const elapsedMs = (task.endedAt ?? Date.now()) - task.startedAt;
|
|
805
|
-
const seconds = Math.round(elapsedMs / 1000);
|
|
806
|
-
const duration = seconds >= 60
|
|
807
|
-
? `${Math.floor(seconds / 60)}m ${seconds % 60}s`
|
|
808
|
-
: `${seconds}s`;
|
|
809
|
-
const description = shortDescription(task.description);
|
|
810
|
-
// Single-line format matching Claude Code's TUI:
|
|
811
|
-
// ✅ Subagent "<description>" completed in 54s
|
|
812
|
-
// 📡 Monitor "<description>" stream ended after 12s
|
|
813
|
-
const body = isMonitor
|
|
814
|
-
? `${statusIcon} Monitor "${description}" ${verb} after ${duration}`
|
|
815
|
-
: `${statusIcon} ${label} "${description}" ${verb} in ${duration}`;
|
|
816
|
-
const text = task.error ? `${body}\n⚠️ ${task.error}` : body;
|
|
817
|
-
// If we still know the armed-message id, edit it in place so the chat
|
|
818
|
-
// doesn't keep showing a stale "armed" line. Only post a fresh message
|
|
819
|
-
// (which triggers a Telegram notification and lands at the bottom of the
|
|
820
|
-
// chat) when the task ran long enough that the user likely walked away —
|
|
821
|
-
// matching sendCompletionNotification's threshold — or when there's an
|
|
822
|
-
// error the user needs to see.
|
|
823
|
-
const chatId = ctx.chat?.id;
|
|
824
|
-
const longRunning = elapsedMs >= config.NOTIFICATION_THRESHOLD_SECONDS * 1000;
|
|
825
|
-
const shouldEdit = task.armedMessageId !== undefined && chatId !== undefined;
|
|
826
|
-
const shouldPostFresh = !shouldEdit || longRunning || !!task.error;
|
|
827
|
-
if (shouldEdit) {
|
|
828
|
-
try {
|
|
829
|
-
await editFormatted(ctx.api, chatId, task.armedMessageId, text);
|
|
830
|
-
}
|
|
831
|
-
catch (error) {
|
|
832
|
-
const msg = error instanceof Error ? error.message : String(error);
|
|
833
|
-
// "message is not modified" is benign; anything else still leaves the
|
|
834
|
-
// fresh post below to tell the user, when posting is called for.
|
|
835
|
-
if (!/not modified/i.test(msg))
|
|
836
|
-
console.error('[Task] Failed to edit armed message:', msg);
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
if (!shouldPostFresh)
|
|
840
|
-
return;
|
|
841
|
-
try {
|
|
842
|
-
await replyFormatted(ctx, text);
|
|
843
|
-
this.noteInterveningPost(getSessionKeyFromCtx(ctx)?.sessionKey);
|
|
844
|
-
}
|
|
845
|
-
catch (error) {
|
|
846
|
-
console.error('[Task] Failed to post completion message:', error instanceof Error ? error.message : error);
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
573
|
/** What the status line shows right now. */
|
|
850
574
|
statusView(state) {
|
|
851
575
|
return {
|
|
@@ -855,14 +579,14 @@ export class MessageSender {
|
|
|
855
579
|
elapsedMs: Date.now() - state.operationStartTime,
|
|
856
580
|
pausedMs: state.lastRateLimitDurationMs > 0 ? state.lastRateLimitDurationMs : undefined,
|
|
857
581
|
tip: state.tip,
|
|
858
|
-
|
|
582
|
+
backgroundHint: state.backgroundHint,
|
|
583
|
+
footer: renderBackgroundFooter(taskTracker.getTasks(state.sessionKey)),
|
|
859
584
|
writing: Date.now() - state.contentChangedAt < WRITING_WINDOW_MS,
|
|
860
585
|
premiumModel: state.premiumModel,
|
|
861
586
|
};
|
|
862
587
|
}
|
|
863
588
|
/**
|
|
864
|
-
* The status line as the action log draws it at its bottom
|
|
865
|
-
* a turn without one (terminal UI off).
|
|
589
|
+
* The status line as the action log draws it at its bottom.
|
|
866
590
|
*
|
|
867
591
|
* It shares a message with up to ten actions, so a long command is clipped
|
|
868
592
|
* as compact mode clips it — verbose mode allows 3,500 characters — and a
|
|
@@ -870,8 +594,6 @@ export class MessageSender {
|
|
|
870
594
|
* about the bubble's own edits, which have stopped.
|
|
871
595
|
*/
|
|
872
596
|
logStatusSource(state) {
|
|
873
|
-
if (!state.terminalMode)
|
|
874
|
-
return undefined;
|
|
875
597
|
return () => {
|
|
876
598
|
const view = this.statusView(state);
|
|
877
599
|
const operation = view.operation && {
|
|
@@ -883,22 +605,13 @@ export class MessageSender {
|
|
|
883
605
|
};
|
|
884
606
|
}
|
|
885
607
|
/**
|
|
886
|
-
* The line under the live reply that says it isn't final: the status line
|
|
887
|
-
*
|
|
888
|
-
* carries the status line, or a plain "Writing" otherwise.
|
|
608
|
+
* The line under the live reply that says it isn't final: the status line,
|
|
609
|
+
* or a pointer down to the action log once that carries the status line.
|
|
889
610
|
*/
|
|
890
611
|
liveFooter(state) {
|
|
891
|
-
if (state.
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
return renderStatusBubble(this.statusView(state));
|
|
895
|
-
}
|
|
896
|
-
if (hasPendingQuestionForSession(state.sessionKey))
|
|
897
|
-
return plain(AWAITING_ANSWER_LINE);
|
|
898
|
-
if (!state.content.trim()) {
|
|
899
|
-
return plain(`${getSpinnerFrame(state.spinnerIndex)} ${TOOL_ICONS.thinking} ${getThinkingVerb()}...${premiumBadge(state.premiumModel)}`);
|
|
900
|
-
}
|
|
901
|
-
return new EntityText().italic(STREAMING_INDICATOR).add(premiumBadge(state.premiumModel)).build();
|
|
612
|
+
if (actionLogger.showsStatus(state.sessionKey))
|
|
613
|
+
return plain(LOG_POINTER_LINE);
|
|
614
|
+
return renderStatusBubble(this.statusView(state));
|
|
902
615
|
}
|
|
903
616
|
/**
|
|
904
617
|
* The live messages: the reply so far, split where it outgrows one message,
|
|
@@ -906,7 +619,7 @@ export class MessageSender {
|
|
|
906
619
|
* overflow into messages of their own below it.
|
|
907
620
|
*/
|
|
908
621
|
liveMessages(state, footer) {
|
|
909
|
-
const prose =
|
|
622
|
+
const prose = state.content.trim();
|
|
910
623
|
if (!prose)
|
|
911
624
|
return [footer];
|
|
912
625
|
const room = MAX_MESSAGE_LENGTH - footer.text.length - 2;
|
|
@@ -931,7 +644,7 @@ export class MessageSender {
|
|
|
931
644
|
return;
|
|
932
645
|
// Once the action log is in the chat it carries the status line, which it
|
|
933
646
|
// redraws on its own throttle. The bubble's footer just points down at it.
|
|
934
|
-
if (
|
|
647
|
+
if (actionLogger.showsStatus(state.sessionKey)) {
|
|
935
648
|
await actionLogger.refreshStatus(state.sessionKey, immediate);
|
|
936
649
|
// The turn may have ended while the log was drawn.
|
|
937
650
|
if (state.ended)
|
|
@@ -1066,7 +779,7 @@ export class MessageSender {
|
|
|
1066
779
|
this.flushLive(ctx, state).catch(() => { });
|
|
1067
780
|
}
|
|
1068
781
|
/**
|
|
1069
|
-
* Mirror Claude Code's live spinner tip
|
|
782
|
+
* Mirror Claude Code's live spinner tip under the status line.
|
|
1070
783
|
* Pass null to clear it. Attempts an immediate flush so the tip appears
|
|
1071
784
|
* promptly; the flush respects the normal edit throttle, and the periodic
|
|
1072
785
|
* spinner refresh picks it up otherwise.
|
|
@@ -1076,13 +789,29 @@ export class MessageSender {
|
|
|
1076
789
|
if (!keyInfo)
|
|
1077
790
|
return;
|
|
1078
791
|
const state = this.streamStates.get(keyInfo.sessionKey);
|
|
1079
|
-
if (!state || !state.messageId
|
|
792
|
+
if (!state || !state.messageId)
|
|
1080
793
|
return;
|
|
1081
794
|
if (state.tip === tip)
|
|
1082
795
|
return;
|
|
1083
796
|
state.tip = tip;
|
|
1084
797
|
this.flushLive(ctx, state).catch(() => { });
|
|
1085
798
|
}
|
|
799
|
+
/**
|
|
800
|
+
* Show or drop the status line's offer to move the running command to the
|
|
801
|
+
* background, as Claude Code's own screen starts or stops making it.
|
|
802
|
+
*/
|
|
803
|
+
updateBackgroundHint(ctx, offered) {
|
|
804
|
+
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
805
|
+
if (!keyInfo)
|
|
806
|
+
return;
|
|
807
|
+
const state = this.streamStates.get(keyInfo.sessionKey);
|
|
808
|
+
if (!state || !state.messageId)
|
|
809
|
+
return;
|
|
810
|
+
if (state.backgroundHint === offered)
|
|
811
|
+
return;
|
|
812
|
+
state.backgroundHint = offered;
|
|
813
|
+
this.flushLive(ctx, state).catch(() => { });
|
|
814
|
+
}
|
|
1086
815
|
/**
|
|
1087
816
|
* An ask_user question has just been posted to the chat.
|
|
1088
817
|
*
|
|
@@ -1133,14 +862,13 @@ export class MessageSender {
|
|
|
1133
862
|
const state = this.streamStates.get(sessionKey);
|
|
1134
863
|
if (!state)
|
|
1135
864
|
return;
|
|
1136
|
-
// Stop
|
|
1137
|
-
this.stopTypingIndicator(state);
|
|
865
|
+
// Stop the spinner and any held-back refresh
|
|
1138
866
|
this.stopSpinnerAnimation(state);
|
|
1139
867
|
state.currentOperation = null;
|
|
1140
868
|
await this.endLiveEdits(state);
|
|
1141
|
-
// Track the last Telegram message we posted in this turn so the /
|
|
869
|
+
// Track the last Telegram message we posted in this turn so the /branch
|
|
1142
870
|
// button can be anchored to the final user-visible message (so a tap
|
|
1143
|
-
//
|
|
871
|
+
// branches AT that point, not at some earlier chunk).
|
|
1144
872
|
let lastMessageId = state.messageId;
|
|
1145
873
|
// Registered once, past the early returns above: an entry planned for a
|
|
1146
874
|
// turn that never renders would sit in the store until its TTL with no
|
|
@@ -1170,7 +898,7 @@ export class MessageSender {
|
|
|
1170
898
|
}
|
|
1171
899
|
else {
|
|
1172
900
|
// No intervening posts: the live messages become the answer, edited in place.
|
|
1173
|
-
let parts =
|
|
901
|
+
let parts = formatMarkdown(finalContent, config.MAX_MESSAGE_LENGTH);
|
|
1174
902
|
if (parts.length === 0)
|
|
1175
903
|
parts = [plain('Done.')];
|
|
1176
904
|
try {
|
|
@@ -1197,11 +925,17 @@ export class MessageSender {
|
|
|
1197
925
|
}
|
|
1198
926
|
}
|
|
1199
927
|
}
|
|
1200
|
-
|
|
928
|
+
// Everything the turn had to say went out before a question was asked,
|
|
929
|
+
// and the answer ended it: the final text is empty, and the branch button
|
|
930
|
+
// belongs under that prose, not on the "Done" bubble above it and the
|
|
931
|
+
// question.
|
|
932
|
+
if (!finalContent.trim() && state.lastPostId !== null)
|
|
933
|
+
lastMessageId = state.lastPostId;
|
|
934
|
+
await this.attachBranchButton(ctx, sessionKey, lastMessageId, suggestion);
|
|
1201
935
|
await this.sendSuggestionCard(ctx, suggestion);
|
|
1202
936
|
this.streamStates.delete(sessionKey);
|
|
1203
|
-
//
|
|
1204
|
-
//
|
|
937
|
+
// Draw the live log one last time once any remaining tool results have
|
|
938
|
+
// landed.
|
|
1205
939
|
actionLogger.endTurn(sessionKey);
|
|
1206
940
|
}
|
|
1207
941
|
/**
|
|
@@ -1209,7 +943,7 @@ export class MessageSender {
|
|
|
1209
943
|
* reply had been written, and tear down the per-turn streaming state.
|
|
1210
944
|
* `reason` is either an explicit banner string or the Error that ended the
|
|
1211
945
|
* turn; an Error whose `name` is `ClaudeApiError` gets a distinct banner so
|
|
1212
|
-
* users can tell a Claude Code API failure apart from a /
|
|
946
|
+
* users can tell a Claude Code API failure apart from a /cancel they initiated
|
|
1213
947
|
* themselves.
|
|
1214
948
|
*/
|
|
1215
949
|
async cancelStreaming(ctx, reason = '⚠️ Request cancelled') {
|
|
@@ -1224,8 +958,6 @@ export class MessageSender {
|
|
|
1224
958
|
const { sessionKey } = keyInfo;
|
|
1225
959
|
const state = this.streamStates.get(sessionKey);
|
|
1226
960
|
if (state) {
|
|
1227
|
-
// Stop typing indicator and spinner
|
|
1228
|
-
this.stopTypingIndicator(state);
|
|
1229
961
|
this.stopSpinnerAnimation(state);
|
|
1230
962
|
await this.endLiveEdits(state);
|
|
1231
963
|
if (state.messageId) {
|
|
@@ -1235,8 +967,8 @@ export class MessageSender {
|
|
|
1235
967
|
}
|
|
1236
968
|
}
|
|
1237
969
|
this.streamStates.delete(sessionKey);
|
|
1238
|
-
//
|
|
1239
|
-
//
|
|
970
|
+
// Draw the live log one last time once any remaining tool results have
|
|
971
|
+
// landed.
|
|
1240
972
|
actionLogger.endTurn(sessionKey);
|
|
1241
973
|
}
|
|
1242
974
|
/**
|