telecoder 0.0.0-stage → 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 +375 -0
- package/CHANGELOG.md +1867 -0
- package/LICENSE +22 -0
- package/README.md +130 -2
- package/dist/audio/transcribe.js +41 -0
- package/dist/bin/mcp-server.js +363 -0
- package/dist/bin/tool-result.js +22 -0
- package/dist/bot/access/group-access.js +147 -0
- package/dist/bot/bot.js +573 -0
- package/dist/bot/command-catalog.js +263 -0
- package/dist/bot/deleted-threads.js +103 -0
- package/dist/bot/file-access.js +150 -0
- package/dist/bot/handlers/album.handler.js +128 -0
- package/dist/bot/handlers/branch.handler.js +1096 -0
- package/dist/bot/handlers/command/access.js +407 -0
- package/dist/bot/handlers/command/admin.js +803 -0
- package/dist/bot/handlers/command/all-view.js +33 -0
- package/dist/bot/handlers/command/auto-approve.js +138 -0
- 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 +175 -0
- package/dist/bot/handlers/command/cleanup.js +329 -0
- package/dist/bot/handlers/command/model.js +226 -0
- package/dist/bot/handlers/command/prefs-scope.js +362 -0
- package/dist/bot/handlers/command/project.js +458 -0
- package/dist/bot/handlers/command/resume.js +325 -0
- package/dist/bot/handlers/command/session.js +299 -0
- package/dist/bot/handlers/command/settings.js +657 -0
- package/dist/bot/handlers/command/shared.js +207 -0
- package/dist/bot/handlers/command/tasks.js +681 -0
- package/dist/bot/handlers/command/thread.js +128 -0
- package/dist/bot/handlers/command/topic-store.js +74 -0
- package/dist/bot/handlers/command/topic.js +27 -0
- package/dist/bot/handlers/command/usage.js +382 -0
- package/dist/bot/handlers/command-fallback.js +179 -0
- package/dist/bot/handlers/command.handler.js +446 -0
- package/dist/bot/handlers/loop.handler.js +389 -0
- package/dist/bot/handlers/media-fallback.js +126 -0
- package/dist/bot/handlers/message/replies.js +56 -0
- package/dist/bot/handlers/message/shared.js +95 -0
- package/dist/bot/handlers/message/turn-notify.js +135 -0
- package/dist/bot/handlers/message/turn-runner.js +56 -0
- package/dist/bot/handlers/message.handler.js +114 -0
- package/dist/bot/handlers/newbot.handler.js +230 -0
- package/dist/bot/handlers/photo.handler.js +286 -0
- package/dist/bot/handlers/prompts.handler.js +343 -0
- package/dist/bot/handlers/running-note.js +44 -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 +147 -0
- package/dist/bot/kept-threads.js +51 -0
- package/dist/bot/middleware/admin-only.js +49 -0
- package/dist/bot/middleware/album-collector.js +69 -0
- package/dist/bot/middleware/auth.middleware.js +122 -0
- package/dist/bot/middleware/group-mention.middleware.js +145 -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 +1082 -0
- package/dist/bot/middleware/stale-filter.js +9 -0
- package/dist/build-info.json +8 -0
- package/dist/claude/ask-user-form.js +517 -0
- package/dist/claude/ask-user.js +363 -0
- package/dist/claude/auto-approve.js +225 -0
- package/dist/claude/auto-topic-haiku.js +143 -0
- package/dist/claude/available-commands.js +156 -0
- package/dist/claude/background-hint.js +91 -0
- package/dist/claude/branch-tree.js +393 -0
- package/dist/claude/carry-over.js +25 -0
- package/dist/claude/ccr-shim.js +48 -0
- package/dist/claude/charter-judge.js +214 -0
- package/dist/claude/claude-auth.js +117 -0
- package/dist/claude/command-parser.js +206 -0
- package/dist/claude/cost-overlay-scraper.js +134 -0
- package/dist/claude/effort-level.js +5 -0
- package/dist/claude/enabled-plugins.js +52 -0
- package/dist/claude/in-flight-tracker.js +82 -0
- package/dist/claude/ipc-server.js +192 -0
- package/dist/claude/mcp-bridge.js +481 -0
- package/dist/claude/memory-guard.js +400 -0
- package/dist/claude/message-offsets.js +88 -0
- package/dist/claude/modal-relay.js +817 -0
- package/dist/claude/model-catalog.js +102 -0
- package/dist/claude/monitor-relay.js +712 -0
- package/dist/claude/native-commands.js +40 -0
- package/dist/claude/pending-branches.js +93 -0
- package/dist/claude/pending-suggestions.js +50 -0
- package/dist/claude/permission-gate.js +338 -0
- package/dist/claude/permission-mode.js +152 -0
- package/dist/claude/poll-user.js +51 -0
- package/dist/claude/prewarm.js +70 -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-idle-reaper.js +96 -0
- package/dist/claude/pty-provider.js +2499 -0
- package/dist/claude/pty-spawn-config.js +343 -0
- package/dist/claude/pty-stream.js +363 -0
- package/dist/claude/pty-watch.js +201 -0
- package/dist/claude/request-queue.js +107 -0
- package/dist/claude/rewind.js +111 -0
- package/dist/claude/scheduled-runner.js +89 -0
- package/dist/claude/scheduler.js +241 -0
- package/dist/claude/scope-guard.js +279 -0
- package/dist/claude/screen-marks.js +83 -0
- package/dist/claude/screen-render.js +96 -0
- package/dist/claude/secret-request.js +576 -0
- package/dist/claude/session-history.js +288 -0
- package/dist/claude/session-jsonl.js +1067 -0
- package/dist/claude/session-manager.js +216 -0
- package/dist/claude/session-move.js +70 -0
- package/dist/claude/session-scan.js +270 -0
- package/dist/claude/setup-token.js +285 -0
- package/dist/claude/shell-mode-gate.js +60 -0
- package/dist/claude/side-call-options.js +45 -0
- package/dist/claude/side-question.js +252 -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/tasks-overlay-scraper.js +217 -0
- package/dist/claude/thread-judge-haiku.js +88 -0
- package/dist/claude/tip-scraper.js +77 -0
- package/dist/claude/tui-modal.js +746 -0
- package/dist/claude/tui-state.js +456 -0
- package/dist/claude/turn-end.js +105 -0
- package/dist/claude/turn-prose.js +64 -0
- package/dist/claude/typed-answer.js +104 -0
- package/dist/claude/update-banner-relay.js +70 -0
- package/dist/cli/commands/doctor.js +338 -0
- package/dist/cli/commands/help.js +34 -0
- package/dist/cli/commands/init.js +126 -0
- package/dist/cli/commands/service.js +710 -0
- package/dist/cli/commands/start.js +63 -0
- package/dist/cli/commands/version.js +11 -0
- package/dist/cli/commands/watch.js +322 -0
- package/dist/cli/dispatch.js +84 -0
- package/dist/cli/init/env-file.js +99 -0
- package/dist/cli/init/flow.js +705 -0
- package/dist/cli/init/prompter.js +124 -0
- package/dist/cli/init/telegram.js +120 -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 +525 -0
- package/dist/index.js +443 -0
- package/dist/launcher.js +960 -0
- package/dist/node-version-check.js +27 -0
- package/dist/providers/ccr-health.js +119 -0
- package/dist/providers/ccr-introspect.js +142 -0
- package/dist/providers/ccr-provider.js +59 -0
- package/dist/providers/claude-provider.js +10 -0
- package/dist/providers/prefs-sync.js +121 -0
- package/dist/providers/project-favorites.js +74 -0
- package/dist/providers/provider-router.js +128 -0
- package/dist/providers/provider-switch.js +91 -0
- package/dist/providers/spawn-settings.js +45 -0
- package/dist/providers/types.js +8 -0
- package/dist/providers/user-preferences.js +322 -0
- package/dist/restart-when-idle.js +173 -0
- package/dist/startup/auto-continue.js +67 -0
- package/dist/startup/auto-resume.js +161 -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 +522 -0
- package/dist/telegram/admin-mention.js +107 -0
- package/dist/telegram/background-activity-card.js +502 -0
- package/dist/telegram/botname-settings.js +282 -0
- package/dist/telegram/button-text.js +26 -0
- package/dist/telegram/client-options.js +26 -0
- package/dist/telegram/deduplication.js +33 -0
- package/dist/telegram/entities.js +295 -0
- package/dist/telegram/force-reply-tracker.js +96 -0
- package/dist/telegram/lettered-options.js +87 -0
- package/dist/telegram/markdown.js +362 -0
- package/dist/telegram/message-sender.js +1019 -0
- package/dist/telegram/prompt-label.js +148 -0
- package/dist/telegram/prompt-suggestion.js +54 -0
- package/dist/telegram/send.js +123 -0
- package/dist/telegram/streaming-turn.js +103 -0
- package/dist/telegram/suggestions-settings.js +30 -0
- package/dist/telegram/table-lists.js +56 -0
- package/dist/telegram/task-list.js +367 -0
- package/dist/telegram/task-tracker.js +128 -0
- package/dist/telegram/terminal-renderer.js +667 -0
- package/dist/telegram/thread-titles.js +262 -0
- package/dist/telegram/threads-setup.js +117 -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-icon.js +248 -0
- package/dist/utils/bot-token.js +77 -0
- package/dist/utils/bounded-map.js +55 -0
- package/dist/utils/build-info.js +57 -0
- package/dist/utils/caffeinate.js +53 -0
- package/dist/utils/claude-env.js +53 -0
- package/dist/utils/claude-version.js +48 -0
- package/dist/utils/config-home.js +62 -0
- package/dist/utils/download.js +137 -0
- package/dist/utils/exit-codes.js +59 -0
- package/dist/utils/file-type.js +149 -0
- package/dist/utils/format.js +78 -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/memory-pressure.js +60 -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/resolve-bin.js +86 -0
- package/dist/utils/resolve-claude-bin.js +52 -0
- package/dist/utils/respawn-backoff.js +28 -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/telegram-proxy.js +72 -0
- package/dist/utils/uploads-dir.js +27 -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 +75 -4
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telling a command typed in a bot's "All" view from one typed in a thread.
|
|
3
|
+
*
|
|
4
|
+
* Telegram has no chat-level place to type in a private chat with threads:
|
|
5
|
+
* a message sent from the "All" view opens a new thread, named "New chat",
|
|
6
|
+
* and arrives inside it. A bare `/model fable` there pins that thread like
|
|
7
|
+
* anywhere else, which is how to start one thread on another model while new
|
|
8
|
+
* threads keep the default. A wider level typed there (`/model opus new`)
|
|
9
|
+
* leaves the thread with nothing in it, so that confirmation offers to
|
|
10
|
+
* delete it.
|
|
11
|
+
*/
|
|
12
|
+
import { sessionManager } from '../../../claude/session-manager.js';
|
|
13
|
+
import { hasImplicitName } from '../../../telegram/thread-titles.js';
|
|
14
|
+
import { getSessionKeyFromCtx } from '../../../utils/session-key.js';
|
|
15
|
+
/**
|
|
16
|
+
* Whether this update comes from a private-chat thread opened from the "All"
|
|
17
|
+
* view that no conversation has happened in yet. Works for a typed command,
|
|
18
|
+
* whose creation notice says the name was implicit, and for a button tapped
|
|
19
|
+
* in that thread afterwards, through the name recorded from that notice.
|
|
20
|
+
*/
|
|
21
|
+
export function isFreshAllViewThread(ctx) {
|
|
22
|
+
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
23
|
+
if (!keyInfo || keyInfo.threadId === undefined || keyInfo.chatId <= 0)
|
|
24
|
+
return false;
|
|
25
|
+
const { sessionKey } = keyInfo;
|
|
26
|
+
const created = ctx.message?.reply_to_message?.forum_topic_created;
|
|
27
|
+
if (!created?.is_name_implicit && !hasImplicitName(sessionKey))
|
|
28
|
+
return false;
|
|
29
|
+
if (sessionManager.getSession(sessionKey)?.claudeSessionId)
|
|
30
|
+
return false;
|
|
31
|
+
return sessionManager.getSessionHistory(sessionKey, 1).length === 0;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=all-view.js.map
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `/autoapprove` — open, inspect and close a chat's auto-approve window.
|
|
3
|
+
*
|
|
4
|
+
* The command is deliberately small. Everything about what a window *means*
|
|
5
|
+
* lives in src/claude/auto-approve.ts; this file is the part a person types at,
|
|
6
|
+
* and its job is to make two things impossible to get wrong: how long the
|
|
7
|
+
* window lasts, and what it does not cover. Both are stated when it opens,
|
|
8
|
+
* because that is the only moment someone is definitely reading.
|
|
9
|
+
*/
|
|
10
|
+
import { closeWindow, formatDuration, formatRemaining, getWindow, listAlwaysPrompted, openWindow, parseWindowDuration, } from '../../../claude/auto-approve.js';
|
|
11
|
+
import { isPermissionGateEnabled } from '../../../claude/permission-gate.js';
|
|
12
|
+
import { isAdmin } from '../../../utils/admins.js';
|
|
13
|
+
import { EntityText } from '../../../telegram/entities.js';
|
|
14
|
+
import { replyFormatted } from '../../../telegram/send.js';
|
|
15
|
+
/** How the announcement names whoever opened the window. */
|
|
16
|
+
function describeOpener(ctx) {
|
|
17
|
+
const from = ctx.from;
|
|
18
|
+
if (!from)
|
|
19
|
+
return 'someone';
|
|
20
|
+
return [from.first_name, from.last_name].filter(Boolean).join(' ') || from.username || `user ${from.id}`;
|
|
21
|
+
}
|
|
22
|
+
/** The carve-outs a window never approves, under their heading. */
|
|
23
|
+
function appendCarveOuts(b) {
|
|
24
|
+
b.bold('Still asks, always:');
|
|
25
|
+
for (const reason of listAlwaysPrompted())
|
|
26
|
+
b.add(`\n• ${reason}`);
|
|
27
|
+
return b;
|
|
28
|
+
}
|
|
29
|
+
/** A heading line: the emoji, then the rest in bold. */
|
|
30
|
+
function heading(emoji, text) {
|
|
31
|
+
return new EntityText().add(`${emoji} `).bold(text);
|
|
32
|
+
}
|
|
33
|
+
const END_EARLY = new EntityText()
|
|
34
|
+
.add('End it early with ').code('/autoapprove off').add('.')
|
|
35
|
+
.build();
|
|
36
|
+
export async function handleAutoApprove(ctx) {
|
|
37
|
+
const chatId = ctx.chat?.id;
|
|
38
|
+
if (chatId === undefined)
|
|
39
|
+
return;
|
|
40
|
+
const arg = (ctx.message?.text ?? '').split(' ').slice(1).join(' ').trim();
|
|
41
|
+
const lowered = arg.toLowerCase();
|
|
42
|
+
if (lowered === 'off' || lowered === 'stop' || lowered === 'end') {
|
|
43
|
+
await handleClose(ctx, chatId);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (lowered === 'status') {
|
|
47
|
+
await handleInfo(ctx, chatId);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const duration = parseWindowDuration(arg);
|
|
51
|
+
if (!duration.ok) {
|
|
52
|
+
await ctx.reply(`❌ ${duration.error}`);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
await handleOpen(ctx, chatId, duration.ms);
|
|
56
|
+
}
|
|
57
|
+
async function handleOpen(ctx, chatId, durationMs) {
|
|
58
|
+
const existing = getWindow(chatId);
|
|
59
|
+
const openerName = describeOpener(ctx);
|
|
60
|
+
openWindow(chatId, {
|
|
61
|
+
openedBy: ctx.from?.id ?? 0,
|
|
62
|
+
openedByName: openerName,
|
|
63
|
+
durationMs,
|
|
64
|
+
// Announced rather than silent: a window that lapses unnoticed leaves
|
|
65
|
+
// people tapping prompts they thought were handled, and — worse the other
|
|
66
|
+
// way — a window people believe is shut but is not.
|
|
67
|
+
onExpire: (lapsed) => {
|
|
68
|
+
void announceExpiry(ctx, lapsed);
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
console.log(`[AutoApprove] chat:${chatId} opened by ${ctx.from?.id ?? '?'} for ${formatDuration(durationMs)}`
|
|
72
|
+
+ (existing ? ' (replacing an open window)' : ''));
|
|
73
|
+
const b = heading('⚡', `Auto-approve is on for ${formatDuration(durationMs)}`).add('\n\n');
|
|
74
|
+
if (existing) {
|
|
75
|
+
b.italic(`Replaces the window ${existing.openedByName} opened, which had ${formatRemaining(existing)} left.`)
|
|
76
|
+
.add('\n\n');
|
|
77
|
+
}
|
|
78
|
+
b.add(`Opened by ${openerName}. Guarded commands in this chat will run without ` +
|
|
79
|
+
'asking, and each one is posted here as it happens.\n\n');
|
|
80
|
+
appendCarveOuts(b).add('\n\n').append(END_EARLY);
|
|
81
|
+
if (!isPermissionGateEnabled()) {
|
|
82
|
+
b.add('\n\n⚠️ The permission gate is ').bold('off')
|
|
83
|
+
.add(' in this bot, so nothing was prompting in the first place and this window changes nothing.');
|
|
84
|
+
}
|
|
85
|
+
await replyFormatted(ctx, b.build());
|
|
86
|
+
}
|
|
87
|
+
async function handleClose(ctx, chatId) {
|
|
88
|
+
const closed = closeWindow(chatId);
|
|
89
|
+
if (!closed) {
|
|
90
|
+
await ctx.reply('✅ No auto-approve window is open here.');
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
// Anyone who could open one can close one, including someone else's: a
|
|
94
|
+
// supervision hole should be closable by whoever notices it, not only by
|
|
95
|
+
// whoever left it open.
|
|
96
|
+
const byOther = closed.openedBy !== ctx.from?.id;
|
|
97
|
+
console.log(`[AutoApprove] chat:${chatId} closed by ${ctx.from?.id ?? '?'}${byOther ? ` (opened by ${closed.openedBy})` : ''}`);
|
|
98
|
+
const b = heading('🔒', 'Auto-approve is off.').add(`\n\n${describeTally(closed)}`);
|
|
99
|
+
if (byOther)
|
|
100
|
+
b.add('\n\n').italic(`It was ${closed.openedByName}'s window.`);
|
|
101
|
+
await replyFormatted(ctx, b.build());
|
|
102
|
+
}
|
|
103
|
+
async function handleInfo(ctx, chatId) {
|
|
104
|
+
const window = getWindow(chatId);
|
|
105
|
+
if (!window) {
|
|
106
|
+
const b = heading('🔒', 'Auto-approve is off here.')
|
|
107
|
+
.add('\n\nGuarded commands post an approval prompt, and an admin or approver taps it.')
|
|
108
|
+
.add('\n\nOpen a window with ').code('/autoapprove 30m').add('.');
|
|
109
|
+
if (!isAdmin(ctx.from?.id)) {
|
|
110
|
+
b.add('\n\n').italic('You can open one — approvers may, guests may not.');
|
|
111
|
+
}
|
|
112
|
+
await replyFormatted(ctx, b.build());
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const b = heading('⚡', `Auto-approve is on — ${formatRemaining(window)} left.`)
|
|
116
|
+
.add(`\n\nOpened by ${window.openedByName}. ${describeTally(window)}\n\n`);
|
|
117
|
+
appendCarveOuts(b).add('\n\n').append(END_EARLY);
|
|
118
|
+
await replyFormatted(ctx, b.build());
|
|
119
|
+
}
|
|
120
|
+
function describeTally(window) {
|
|
121
|
+
if (window.approved === 0)
|
|
122
|
+
return 'Nothing has needed approving yet.';
|
|
123
|
+
return window.approved === 1
|
|
124
|
+
? 'It approved 1 command.'
|
|
125
|
+
: `It approved ${window.approved} commands.`;
|
|
126
|
+
}
|
|
127
|
+
async function announceExpiry(ctx, window) {
|
|
128
|
+
console.log(`[AutoApprove] chat:${window.chatId} lapsed after approving ${window.approved}`);
|
|
129
|
+
try {
|
|
130
|
+
await ctx.api.sendMessage(window.chatId, `🔒 Auto-approve has lapsed — guarded commands ask again. ${describeTally(window)}`);
|
|
131
|
+
}
|
|
132
|
+
catch (err) {
|
|
133
|
+
// Fires on a bare timer with nobody to catch it, and a chat that has gone
|
|
134
|
+
// away must not take the process with it.
|
|
135
|
+
console.error('[AutoApprove] expiry notice failed:', err instanceof Error ? err.message : err);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=auto-approve.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* /ctrlb: Claude Code's Ctrl+B, for a chat that has no such key.
|
|
3
|
+
*
|
|
4
|
+
* In a terminal, Ctrl+B moves the shell command or subagent a turn is waiting
|
|
5
|
+
* on to the background: the turn carries on at once, and the command reports
|
|
6
|
+
* back when it ends, as one started in the background does. Here the command
|
|
7
|
+
* does the pressing. The status line offers it while Claude Code's own screen
|
|
8
|
+
* offers the key, and the provider presses it only then.
|
|
9
|
+
*
|
|
10
|
+
* Registered ahead of the per-chat queue: it is for a turn that is running.
|
|
11
|
+
*/
|
|
12
|
+
import { getPtyProvider } from '../../../providers/claude-provider.js';
|
|
13
|
+
import { getSessionKeyFromCtx } from '../../../utils/session-key.js';
|
|
14
|
+
/** What the chat is told for each way a press can go. Exported for tests. */
|
|
15
|
+
export function backgroundReply(result) {
|
|
16
|
+
if (result.ok)
|
|
17
|
+
return '⏬ Moved to the background. Claude carries on without waiting for it · /tasks';
|
|
18
|
+
switch (result.reason) {
|
|
19
|
+
case 'no-session':
|
|
20
|
+
case 'not-offered':
|
|
21
|
+
return 'ℹ️ Nothing to move to the background. That takes a shell command or subagent Claude is waiting on; the live status message offers /ctrlb while there is one.';
|
|
22
|
+
case 'dialog-open':
|
|
23
|
+
return 'ℹ️ Claude Code has a dialog open, which takes the keys. Answer it first.';
|
|
24
|
+
case 'unknown-key':
|
|
25
|
+
return `⚠️ Claude Code names "${result.key}" as its key for this, which the bot can't press.`;
|
|
26
|
+
case 'still-running':
|
|
27
|
+
return "⚠️ Pressed Claude Code's key, but what is running stayed in the foreground.";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export async function handleCtrlB(ctx) {
|
|
31
|
+
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
32
|
+
if (!keyInfo)
|
|
33
|
+
return;
|
|
34
|
+
const result = await getPtyProvider().moveToBackground(keyInfo.sessionKey);
|
|
35
|
+
await ctx.reply(backgroundReply(result));
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=background.js.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The /botname command: the name the bot shows in Telegram.
|
|
3
|
+
*
|
|
4
|
+
* `/botname <name>` saves the name per bot (it wins over `BOT_NAME`) and renames
|
|
5
|
+
* the bot on Telegram. Telegram throttles renames hard, so when it refuses the
|
|
6
|
+
* reply says so and the name is sent again as soon as the cooldown ends.
|
|
7
|
+
* `/botname reset` goes back to `BOT_NAME`; `/botname` alone shows the state.
|
|
8
|
+
*/
|
|
9
|
+
import { config, getBotNameSource, setStoredBotName } from '../../../config.js';
|
|
10
|
+
import { EntityText } from '../../../telegram/entities.js';
|
|
11
|
+
import { replyFormatted } from '../../../telegram/send.js';
|
|
12
|
+
import { pushBotName, getBotNameCooldownUntil, formatCooldownLeft, } from '../../../telegram/botname-settings.js';
|
|
13
|
+
/** Telegram's limit on a bot's name. */
|
|
14
|
+
const MAX_NAME_LENGTH = 64;
|
|
15
|
+
export async function handleBotName(ctx) {
|
|
16
|
+
const text = ctx.message?.text || '';
|
|
17
|
+
const arg = text.split(' ').slice(1).join(' ').trim();
|
|
18
|
+
if (!arg)
|
|
19
|
+
return showBotName(ctx);
|
|
20
|
+
const name = arg === 'reset' ? undefined : arg;
|
|
21
|
+
if (name && name.length > MAX_NAME_LENGTH) {
|
|
22
|
+
await replyFormatted(ctx, `❌ A bot name is at most ${MAX_NAME_LENGTH} characters; this one is ${name.length}.`);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
setStoredBotName(name);
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
await replyFormatted(ctx, `❌ Could not save the name: ${err instanceof Error ? err.message : String(err)}`);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const result = await pushBotName(ctx.api, config.BOT_NAME);
|
|
33
|
+
const msg = new EntityText().add('✅ Bot name: ').bold(config.BOT_NAME);
|
|
34
|
+
if (!name)
|
|
35
|
+
msg.add(' (back to ').code('BOT_NAME').add(')');
|
|
36
|
+
msg.newline().italic(describeResult(result));
|
|
37
|
+
await replyFormatted(ctx, msg.build());
|
|
38
|
+
}
|
|
39
|
+
function describeResult(result) {
|
|
40
|
+
switch (result.status) {
|
|
41
|
+
case 'sent':
|
|
42
|
+
case 'no_change':
|
|
43
|
+
return 'Telegram shows it now.';
|
|
44
|
+
case 'queued':
|
|
45
|
+
return 'Telegram shows it within a minute.';
|
|
46
|
+
case 'newly_blocked':
|
|
47
|
+
case 'still_blocked':
|
|
48
|
+
return `Telegram is rate-limiting renames and still shows the old name. `
|
|
49
|
+
+ `The new one is sent again in ${formatCooldownLeft(result.blockedUntilMs)}.`;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function showBotName(ctx) {
|
|
53
|
+
let live;
|
|
54
|
+
try {
|
|
55
|
+
live = (await ctx.api.getMyName()).name;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
live = undefined;
|
|
59
|
+
}
|
|
60
|
+
const msg = new EntityText().add('✏️ ').bold('Bot name').newline(2);
|
|
61
|
+
msg.add('Telegram shows: ').bold(live ?? '(unknown)').newline();
|
|
62
|
+
const source = getBotNameSource();
|
|
63
|
+
if (source === 'default') {
|
|
64
|
+
msg.add('As chosen in BotFather; ').code('BOT_NAME').add(' is not set.');
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
msg.add(source === 'command' ? 'Set with /botname: ' : 'From BOT_NAME: ').bold(config.BOT_NAME);
|
|
68
|
+
const cooldownUntil = getBotNameCooldownUntil();
|
|
69
|
+
if (live !== undefined && live !== config.BOT_NAME && cooldownUntil !== undefined) {
|
|
70
|
+
msg.newline().add(`⏳ Telegram is rate-limiting renames; it gets this name in ${formatCooldownLeft(cooldownUntil)}.`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
msg.newline(2).italic('/botname <name> renames the bot, /botname reset goes back to BOT_NAME. Admins only.');
|
|
74
|
+
await replyFormatted(ctx, msg.build());
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=botname.js.map
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* /btw — ask a side question without disturbing the main conversation.
|
|
3
|
+
*
|
|
4
|
+
* Runs the question against a fork of the current session, streaming a
|
|
5
|
+
* progress line while it works, so the answer lands without the main turn
|
|
6
|
+
* losing its place.
|
|
7
|
+
*/
|
|
8
|
+
import { sessionManager } from '../../../claude/session-manager.js';
|
|
9
|
+
import { askForkedSideQuestion } from '../../../claude/side-question.js';
|
|
10
|
+
import { messageSender } from '../../../telegram/message-sender.js';
|
|
11
|
+
import { getActiveProviderName } from '../../../providers/provider-router.js';
|
|
12
|
+
import { getCcrShimPath } from '../../../claude/ccr-shim.js';
|
|
13
|
+
import { sanitizeError } from '../../../utils/sanitize.js';
|
|
14
|
+
import { getSessionKeyFromCtx } from '../../../utils/session-key.js';
|
|
15
|
+
// ── /btw ─────────────────────────────────────────────────────────
|
|
16
|
+
export async function handleBtw(ctx) {
|
|
17
|
+
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
18
|
+
if (!keyInfo)
|
|
19
|
+
return;
|
|
20
|
+
const { sessionKey } = keyInfo;
|
|
21
|
+
const text = ctx.message?.text || '';
|
|
22
|
+
const question = text.replace(/^\/btw\s*/i, '').trim();
|
|
23
|
+
if (!question) {
|
|
24
|
+
await ctx.reply('Usage: /btw <your question>\n\nAsk a side question without interrupting the current task.');
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
await askBtw(ctx, sessionKey, question);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Answer `question` alongside the running turn, without it reaching the main
|
|
31
|
+
* conversation. Also what "Ask as /btw" on a queued message calls, with the
|
|
32
|
+
* context of the tap rather than of a typed command.
|
|
33
|
+
*/
|
|
34
|
+
export async function askBtw(ctx, sessionKey, question) {
|
|
35
|
+
const session = sessionManager.getSession(sessionKey);
|
|
36
|
+
if (!session?.claudeSessionId) {
|
|
37
|
+
await ctx.reply('No conversation to ask about yet. Send a message first, then /btw can answer alongside it.');
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const chatId = ctx.chat.id;
|
|
41
|
+
const headline = `💬 /btw — ${btwLabel(question)}`;
|
|
42
|
+
// Labelled ack: this sits alongside the main turn's live status message, so
|
|
43
|
+
// it has to be obvious which one belongs to the side question. It then
|
|
44
|
+
// doubles as the progress line, and finally as a one-line receipt.
|
|
45
|
+
const ack = await ctx.reply(`${headline}\nasking on the side… (main task keeps running)`);
|
|
46
|
+
const progress = new BtwProgressLine(ctx, chatId, ack.message_id, headline);
|
|
47
|
+
try {
|
|
48
|
+
const result = await askForkedSideQuestion({
|
|
49
|
+
question,
|
|
50
|
+
sessionId: session.claudeSessionId,
|
|
51
|
+
cwd: session.workingDirectory,
|
|
52
|
+
// A CCR session's thinking blocks only replay through CCR.
|
|
53
|
+
executable: getActiveProviderName(sessionKey) === 'ccr' ? getCcrShimPath() : undefined,
|
|
54
|
+
onProgress: (p) => progress.update(p),
|
|
55
|
+
});
|
|
56
|
+
await progress.finish(result.toolCount ?? 0, result.elapsedMs ?? 0);
|
|
57
|
+
if (!result.response) {
|
|
58
|
+
await ctx.reply("I don't have enough context to answer that.");
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
await messageSender.sendMessage(ctx, formatSideAnswer(question, result.response));
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
const msg = error instanceof Error ? error.message : 'Unknown error';
|
|
65
|
+
console.error('[btw] Fork error:', sanitizeError(error));
|
|
66
|
+
await progress.fail();
|
|
67
|
+
await ctx.reply(`Failed to answer side question: ${msg}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** Longest slice of the question echoed back in /btw labels. */
|
|
71
|
+
const BTW_LABEL_MAX = 80;
|
|
72
|
+
/**
|
|
73
|
+
* One-line echo of the question, for labels that sit next to live turn output.
|
|
74
|
+
* Formatting characters are dropped — the label is interpolated inside an
|
|
75
|
+
* italic run, and a stray `_` or `*` would unbalance it and fail the parse.
|
|
76
|
+
*/
|
|
77
|
+
export function btwLabel(question) {
|
|
78
|
+
const flat = question.replace(/[_*`[\]]/g, '').replace(/\s+/g, ' ').trim();
|
|
79
|
+
return flat.length > BTW_LABEL_MAX ? `${flat.slice(0, BTW_LABEL_MAX - 1)}…` : flat;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* A /btw answer lands in the middle of a running turn's output, so it has to
|
|
83
|
+
* announce itself — otherwise it reads as something the main task said. The
|
|
84
|
+
* echoed question also tells two concurrent side questions apart.
|
|
85
|
+
*/
|
|
86
|
+
export function formatSideAnswer(question, response) {
|
|
87
|
+
return `💬 **/btw** — _${btwLabel(question)}_\n\n${response}`;
|
|
88
|
+
}
|
|
89
|
+
/** Minimum gap between /btw progress edits — Telegram rate-limits edits hard. */
|
|
90
|
+
const BTW_EDIT_INTERVAL_MS = 2000;
|
|
91
|
+
/** How often the elapsed counter ticks while a single slow tool runs. */
|
|
92
|
+
const BTW_TICK_MS = 5000;
|
|
93
|
+
/**
|
|
94
|
+
* Owns the single `/btw` message across its three lives: ack → live progress →
|
|
95
|
+
* one-line receipt. Keeping it as one message is the point — a side question
|
|
96
|
+
* shouldn't add a second log competing with the running turn's own output.
|
|
97
|
+
*/
|
|
98
|
+
class BtwProgressLine {
|
|
99
|
+
ctx;
|
|
100
|
+
chatId;
|
|
101
|
+
messageId;
|
|
102
|
+
headline;
|
|
103
|
+
latest = null;
|
|
104
|
+
lastRendered = '';
|
|
105
|
+
lastEditAt = 0;
|
|
106
|
+
ticker;
|
|
107
|
+
done = false;
|
|
108
|
+
constructor(ctx, chatId, messageId, headline) {
|
|
109
|
+
this.ctx = ctx;
|
|
110
|
+
this.chatId = chatId;
|
|
111
|
+
this.messageId = messageId;
|
|
112
|
+
this.headline = headline;
|
|
113
|
+
// Repaint on a timer too, so elapsed keeps moving during a long tool call.
|
|
114
|
+
this.ticker = setInterval(() => { void this.render(); }, BTW_TICK_MS);
|
|
115
|
+
}
|
|
116
|
+
update(p) {
|
|
117
|
+
this.latest = p;
|
|
118
|
+
void this.render();
|
|
119
|
+
}
|
|
120
|
+
/** Collapse to a receipt: what the side question did, in one line. */
|
|
121
|
+
async finish(toolCount, elapsedMs) {
|
|
122
|
+
this.stop();
|
|
123
|
+
const detail = toolCount > 0
|
|
124
|
+
? `${toolCount} ${toolCount === 1 ? 'tool' : 'tools'} · ${formatBtwElapsed(elapsedMs)}`
|
|
125
|
+
: formatBtwElapsed(elapsedMs);
|
|
126
|
+
await this.edit(`${this.headline} · ${detail}`);
|
|
127
|
+
}
|
|
128
|
+
async fail() {
|
|
129
|
+
this.stop();
|
|
130
|
+
await this.edit(`${this.headline} · failed`);
|
|
131
|
+
}
|
|
132
|
+
stop() {
|
|
133
|
+
this.done = true;
|
|
134
|
+
if (this.ticker) {
|
|
135
|
+
clearInterval(this.ticker);
|
|
136
|
+
this.ticker = null;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
async render() {
|
|
140
|
+
if (this.done)
|
|
141
|
+
return;
|
|
142
|
+
const now = Date.now();
|
|
143
|
+
if (now - this.lastEditAt < BTW_EDIT_INTERVAL_MS)
|
|
144
|
+
return;
|
|
145
|
+
const p = this.latest;
|
|
146
|
+
const elapsed = formatBtwElapsed(p ? p.elapsedMs : 0);
|
|
147
|
+
const activity = p?.currentTool
|
|
148
|
+
? `🔧 ${p.currentTool}${p.currentHint ? `: ${btwLabel(p.currentHint)}` : ''}`
|
|
149
|
+
: 'thinking…';
|
|
150
|
+
const counter = p && p.toolCount > 0
|
|
151
|
+
? ` · ${p.toolCount} ${p.toolCount === 1 ? 'tool' : 'tools'} · ${elapsed}`
|
|
152
|
+
: ` · ${elapsed}`;
|
|
153
|
+
await this.edit(`${this.headline}\n${activity}${counter}`);
|
|
154
|
+
}
|
|
155
|
+
async edit(text) {
|
|
156
|
+
// Telegram rejects an edit that changes nothing, so skip those outright.
|
|
157
|
+
if (text === this.lastRendered)
|
|
158
|
+
return;
|
|
159
|
+
this.lastEditAt = Date.now();
|
|
160
|
+
this.lastRendered = text;
|
|
161
|
+
try {
|
|
162
|
+
await this.ctx.api.editMessageText(this.chatId, this.messageId, text);
|
|
163
|
+
}
|
|
164
|
+
catch (err) {
|
|
165
|
+
console.debug('[btw] progress edit failed:', err instanceof Error ? err.message : err);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function formatBtwElapsed(ms) {
|
|
170
|
+
const seconds = Math.max(0, Math.round(ms / 1000));
|
|
171
|
+
if (seconds < 60)
|
|
172
|
+
return `${seconds}s`;
|
|
173
|
+
return `${Math.floor(seconds / 60)}m${String(seconds % 60).padStart(2, '0')}s`;
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=btw.js.map
|