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
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* /threaddelete: delete the thread it's sent in, messages and all, and end
|
|
3
|
+
* the session that belonged to it. Works in a private chat's threads and, for
|
|
4
|
+
* a bot allowed to delete messages there, in a group's forum topics.
|
|
5
|
+
*
|
|
6
|
+
* /threadkeep: mark the thread it's sent in so /threadcleanup leaves it alone, with a 📌
|
|
7
|
+
* in front of its name where the bot names it. `/threadkeep off` takes it off.
|
|
8
|
+
*
|
|
9
|
+
* It answers mid-turn, since stopping that turn is part of the point. The
|
|
10
|
+
* thread goes first and its session after, so a thread Telegram won't delete
|
|
11
|
+
* keeps a session that works.
|
|
12
|
+
*/
|
|
13
|
+
import { GrammyError } from 'grammy';
|
|
14
|
+
import { EntityText } from '../../../telegram/entities.js';
|
|
15
|
+
import { replyFormatted, editCallbackMessage } from '../../../telegram/send.js';
|
|
16
|
+
import { getSessionKeyFromCtx, parseSessionKey } from '../../../utils/session-key.js';
|
|
17
|
+
import { sanitizeError } from '../../../utils/sanitize.js';
|
|
18
|
+
import { forgetThread, isThreadGoneError } from '../../deleted-threads.js';
|
|
19
|
+
import { KEEP_MARK, isThreadKept, setThreadKept } from '../../kept-threads.js';
|
|
20
|
+
import { markThreadName } from '../../../telegram/thread-titles.js';
|
|
21
|
+
import { parseCallback } from './shared.js';
|
|
22
|
+
const SKIP_CONFIRM = new Set(['-y', '--yes', 'yes', 'force']);
|
|
23
|
+
/**
|
|
24
|
+
* Delete the thread, then let its session go. What went wrong, or null. Also
|
|
25
|
+
* what /threadcleanup deletes each thread with.
|
|
26
|
+
*/
|
|
27
|
+
export async function deleteThread(api, sessionKey, why = '/threaddelete') {
|
|
28
|
+
const { chatId, threadId } = parseSessionKey(sessionKey);
|
|
29
|
+
if (threadId === undefined)
|
|
30
|
+
return 'not a thread';
|
|
31
|
+
try {
|
|
32
|
+
await api.deleteForumTopic(chatId, threadId);
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
// Already gone, deleted by hand since the confirmation was sent: let go all the same.
|
|
36
|
+
if (!(err instanceof GrammyError && isThreadGoneError(err.description))) {
|
|
37
|
+
console.error(`[ThreadDelete] Deleting ${sessionKey} failed:`, sanitizeError(err));
|
|
38
|
+
return err instanceof GrammyError ? err.description : 'Telegram refused';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
await forgetThread(api, sessionKey, why);
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
export async function handleThreadDelete(ctx) {
|
|
45
|
+
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
46
|
+
if (!keyInfo)
|
|
47
|
+
return;
|
|
48
|
+
const { threadId, sessionKey } = keyInfo;
|
|
49
|
+
if (threadId === undefined) {
|
|
50
|
+
await ctx.reply('ℹ️ Send /threaddelete inside the thread you want to delete.');
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const arg = (ctx.message?.text ?? '').split(' ').slice(1).join(' ').trim().toLowerCase();
|
|
54
|
+
if (SKIP_CONFIRM.has(arg)) {
|
|
55
|
+
const failed = await deleteThread(ctx.api, sessionKey);
|
|
56
|
+
if (failed)
|
|
57
|
+
await ctx.reply(`❌ Couldn't delete this thread: ${failed}`);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const confirm = new EntityText()
|
|
61
|
+
.add('⚠️ ').bold('Delete this thread?')
|
|
62
|
+
.add('\n\nThe thread and all its messages are removed from Telegram, and its Claude session ends. ')
|
|
63
|
+
.add('The conversation itself stays on disk, so ').code('/resume').add(' can still pick it up.\n\n')
|
|
64
|
+
.italic('Telegram can\'t undo this.')
|
|
65
|
+
.add('\n\n💡 Tip: ').code('/threaddelete -y').add(' skips this confirmation.')
|
|
66
|
+
.build();
|
|
67
|
+
await replyFormatted(ctx, confirm, {
|
|
68
|
+
reply_markup: {
|
|
69
|
+
inline_keyboard: [[
|
|
70
|
+
{ text: '🗑️ Yes, delete it', callback_data: 'threaddelete:confirm' },
|
|
71
|
+
{ text: '✗ Cancel', callback_data: 'threaddelete:cancel' },
|
|
72
|
+
]],
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
export async function handleThreadDeleteCallback(ctx) {
|
|
77
|
+
const cb = parseCallback(ctx, 'threaddelete:');
|
|
78
|
+
if (!cb)
|
|
79
|
+
return;
|
|
80
|
+
const { threadId, sessionKey, data } = cb;
|
|
81
|
+
if (data !== 'threaddelete:confirm' || threadId === undefined) {
|
|
82
|
+
await ctx.answerCallbackQuery({ text: 'Kept the thread.' }).catch(() => { });
|
|
83
|
+
await editCallbackMessage(ctx, new EntityText().add('👍 Kept the thread.').build()).catch(() => { });
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const failed = await deleteThread(ctx.api, sessionKey);
|
|
87
|
+
if (failed) {
|
|
88
|
+
await ctx.answerCallbackQuery({ text: 'Couldn\'t delete the thread.' }).catch(() => { });
|
|
89
|
+
await editCallbackMessage(ctx, new EntityText().add(`❌ Couldn't delete this thread: ${failed}`).build()).catch(() => { });
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
await ctx.answerCallbackQuery({ text: 'Thread deleted.' }).catch(() => { });
|
|
93
|
+
}
|
|
94
|
+
const KEEP_OFF = new Set(['off', 'no', 'remove', 'undo']);
|
|
95
|
+
export async function handleThreadKeep(ctx) {
|
|
96
|
+
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
97
|
+
if (!keyInfo)
|
|
98
|
+
return;
|
|
99
|
+
const { threadId, sessionKey } = keyInfo;
|
|
100
|
+
if (threadId === undefined) {
|
|
101
|
+
await ctx.reply('ℹ️ Send /threadkeep inside the thread you want to keep.');
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const arg = (ctx.message?.text ?? '').split(' ').slice(1).join(' ').trim().toLowerCase();
|
|
105
|
+
const keep = !KEEP_OFF.has(arg);
|
|
106
|
+
if (!keep) {
|
|
107
|
+
if (!setThreadKept(sessionKey, false)) {
|
|
108
|
+
await replyFormatted(ctx, new EntityText().add('ℹ️ This thread wasn\'t kept, so ').code('/threadcleanup').add(' can already offer it.').build());
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
await markThreadName(sessionKey, KEEP_MARK, false);
|
|
112
|
+
await replyFormatted(ctx, new EntityText().add('👍 Not kept any more: ').code('/threadcleanup').add(' can offer this thread again.').build());
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (isThreadKept(sessionKey)) {
|
|
116
|
+
await replyFormatted(ctx, new EntityText()
|
|
117
|
+
.add('📌 This thread is already kept. ').code('/threadkeep off').add(' lets ').code('/threadcleanup').add(' offer it again.').build());
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
setThreadKept(sessionKey, true);
|
|
121
|
+
const named = await markThreadName(sessionKey, KEEP_MARK, true);
|
|
122
|
+
const text = new EntityText().add('📌 ').bold('Kept.').add(' ').code('/threadcleanup').add(' leaves this thread alone; ')
|
|
123
|
+
.code('/threadkeep off').add(' undoes it.');
|
|
124
|
+
if (named === 'user-named')
|
|
125
|
+
text.newline(2).italic('The thread\'s name is the one you gave it, so it stays as it is, without the 📌.');
|
|
126
|
+
await replyFormatted(ctx, text.build());
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=thread.js.map
|
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Session topic
|
|
2
|
+
* Session topic — the state and the mutators.
|
|
3
3
|
*
|
|
4
4
|
* The topic is ephemeral per-session state (persisted only through
|
|
5
5
|
* sessionHistory) that several other command domains read and reset — project
|
|
6
|
-
* switches, /clear, and resume all touch it.
|
|
6
|
+
* switches, /clear, and resume all touch it. It shows in the status line and
|
|
7
|
+
* names the thread; the bot's display name is static (see `/botname`).
|
|
7
8
|
*
|
|
8
|
-
* This module is deliberately kept below the provider layer
|
|
9
|
-
*
|
|
10
|
-
* the command barrel
|
|
11
|
-
*
|
|
12
|
-
* here may import `./shared.js` or anything under `providers/`. The /topic and
|
|
13
|
-
* /botname *commands* live in `topic.ts`, which is free to.
|
|
9
|
+
* This module is deliberately kept below the provider layer, so that code
|
|
10
|
+
* under it can read and set the topic without closing an import cycle through
|
|
11
|
+
* the command barrel. Nothing here may import `./shared.js` or anything under
|
|
12
|
+
* `providers/`. The /topic *command* lives in `topic.ts`, which is free to.
|
|
14
13
|
*/
|
|
15
14
|
import * as path from 'path';
|
|
16
|
-
import { config } from '../../../config.js';
|
|
17
15
|
import { sessionManager } from '../../../claude/session-manager.js';
|
|
18
16
|
import { sessionHistory } from '../../../claude/session-history.js';
|
|
19
17
|
import { readLastAiTitle } from '../../../claude/session-jsonl.js';
|
|
20
|
-
import { isBotNameEnabled, rateLimitedSetMyName, notifyBotNameBlock, } from '../../../telegram/botname-settings.js';
|
|
21
18
|
import { syncThreadTitle } from '../../../telegram/thread-titles.js';
|
|
22
19
|
import { isHomeProject } from '../../../utils/home-project.js';
|
|
23
20
|
// Per-session topic (ephemeral — not persisted across restarts)
|
|
@@ -25,50 +22,21 @@ const sessionTopics = new Map();
|
|
|
25
22
|
// Per-session timestamp of last setSessionTopic call. Used by the auto-topic
|
|
26
23
|
// reminder hook to skip the per-turn nudge when the topic was just updated.
|
|
27
24
|
const lastTopicSetAt = new Map();
|
|
28
|
-
/** Build the bot display name from base name and project. Topic now lives in the status line. */
|
|
29
|
-
export function buildBotDisplayName(sessionKey) {
|
|
30
|
-
const session = sessionManager.getSession(sessionKey);
|
|
31
|
-
// A bot made for one project already carries it in its name.
|
|
32
|
-
const project = session?.workingDirectory && !isHomeProject(session.workingDirectory)
|
|
33
|
-
? path.basename(session.workingDirectory)
|
|
34
|
-
: '';
|
|
35
|
-
const parts = [config.BOT_NAME];
|
|
36
|
-
if (project)
|
|
37
|
-
parts.push(project);
|
|
38
|
-
return parts.join(' — ').slice(0, 64);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Push a display name to Telegram (rate-limited) and surface any block notice.
|
|
42
|
-
* Swallows errors — a failed name update should never break the calling flow.
|
|
43
|
-
* `context` is used only for the debug log so failures are attributable.
|
|
44
|
-
*/
|
|
45
|
-
export async function pushBotName(ctx, name, context) {
|
|
46
|
-
try {
|
|
47
|
-
const result = await rateLimitedSetMyName(ctx.api, (n) => ctx.api.setMyName(n), name);
|
|
48
|
-
await notifyBotNameBlock(ctx, result);
|
|
49
|
-
}
|
|
50
|
-
catch (err) {
|
|
51
|
-
console.debug(`[Bot] Failed to set bot name (${context}):`, err instanceof Error ? err.message : err);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
25
|
/**
|
|
55
|
-
* Clear the session topic
|
|
56
|
-
*
|
|
26
|
+
* Clear the session topic. Called whenever the conversation context is wiped
|
|
27
|
+
* (clear, reset, project switch).
|
|
57
28
|
*/
|
|
58
|
-
export
|
|
29
|
+
export function clearTopic(sessionKey) {
|
|
59
30
|
setSessionTopic(sessionKey, '');
|
|
60
|
-
if (!isBotNameEnabled(sessionKey))
|
|
61
|
-
return;
|
|
62
|
-
await pushBotName(ctx, buildBotDisplayName(sessionKey), 'topic clear');
|
|
63
31
|
}
|
|
64
32
|
/**
|
|
65
|
-
* Restore the session topic from the saved value (or clear if absent)
|
|
66
|
-
*
|
|
33
|
+
* Restore the session topic from the saved value (or clear if absent). Called
|
|
34
|
+
* when resuming/continuing a previous conversation.
|
|
67
35
|
*
|
|
68
36
|
* When no persisted topic exists, fall back to Claude Code's `aiTitle` from the
|
|
69
37
|
* session JSONL — better a stale session label than a blank topic line on resume.
|
|
70
38
|
*/
|
|
71
|
-
export
|
|
39
|
+
export function restoreTopic(sessionKey, topic) {
|
|
72
40
|
if (!topic) {
|
|
73
41
|
const session = sessionManager.getSession(sessionKey);
|
|
74
42
|
if (session?.claudeSessionId) {
|
|
@@ -76,14 +44,8 @@ export async function restoreTopicAndRefreshBotName(ctx, sessionKey, topic) {
|
|
|
76
44
|
}
|
|
77
45
|
}
|
|
78
46
|
setSessionTopic(sessionKey, topic || '');
|
|
79
|
-
if (!isBotNameEnabled(sessionKey))
|
|
80
|
-
return;
|
|
81
|
-
await pushBotName(ctx, buildBotDisplayName(sessionKey), 'topic restore');
|
|
82
47
|
}
|
|
83
|
-
/**
|
|
84
|
-
* Set the session topic programmatically (used by MCP tool and auto-resume).
|
|
85
|
-
* Returns the new display name string.
|
|
86
|
-
*/
|
|
48
|
+
/** Set the session topic programmatically (used by the MCP tool and auto-resume). */
|
|
87
49
|
export function setSessionTopic(sessionKey, topic) {
|
|
88
50
|
if (topic) {
|
|
89
51
|
sessionTopics.set(sessionKey, topic);
|
|
@@ -99,7 +61,6 @@ export function setSessionTopic(sessionKey, topic) {
|
|
|
99
61
|
const workingDirectory = sessionManager.getSession(sessionKey)?.workingDirectory;
|
|
100
62
|
const project = workingDirectory && !isHomeProject(workingDirectory) ? path.basename(workingDirectory) : undefined;
|
|
101
63
|
syncThreadTitle(sessionKey, topic, project);
|
|
102
|
-
return buildBotDisplayName(sessionKey);
|
|
103
64
|
}
|
|
104
65
|
/** Get the current session topic. */
|
|
105
66
|
export function getSessionTopic(sessionKey) {
|
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The /topic
|
|
2
|
+
* The /topic command.
|
|
3
3
|
*
|
|
4
|
-
* The topic state itself
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* barrel's public API is unchanged.
|
|
4
|
+
* The topic state itself lives in `topic-store.ts`, which stays below the
|
|
5
|
+
* provider layer so code under it can read and set the topic without closing
|
|
6
|
+
* an import cycle. This module adds the Telegram command surface on top and
|
|
7
|
+
* re-exports the store so the command barrel's public API is unchanged.
|
|
9
8
|
*/
|
|
10
|
-
import { config } from '../../../config.js';
|
|
11
9
|
import { EntityText } from '../../../telegram/entities.js';
|
|
12
|
-
import { replyFormatted
|
|
13
|
-
import { getBotNameSettings, setBotNameEnabled } from '../../../telegram/botname-settings.js';
|
|
10
|
+
import { replyFormatted } from '../../../telegram/send.js';
|
|
14
11
|
import { getSessionKeyFromCtx } from '../../../utils/session-key.js';
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
export { buildBotDisplayName, pushBotName, clearTopicAndRefreshBotName, restoreTopicAndRefreshBotName, setSessionTopic, getSessionTopic, getMsSinceTopicSet, } from './topic-store.js';
|
|
12
|
+
import { setSessionTopic } from './topic-store.js';
|
|
13
|
+
export { clearTopic, restoreTopic, setSessionTopic, getSessionTopic, getMsSinceTopicSet, } from './topic-store.js';
|
|
18
14
|
export async function handleTopic(ctx) {
|
|
19
15
|
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
20
16
|
if (!keyInfo)
|
|
@@ -28,53 +24,4 @@ export async function handleTopic(ctx) {
|
|
|
28
24
|
setSessionTopic(sessionKey, topic);
|
|
29
25
|
await replyFormatted(ctx, topic ? new EntityText().add('✅ Topic: ').bold(topic).build() : '✅ Topic cleared');
|
|
30
26
|
}
|
|
31
|
-
function botNameDescription(enabled) {
|
|
32
|
-
return enabled
|
|
33
|
-
? 'Bot name updates to include the active project when switching'
|
|
34
|
-
: 'Bot name stays as configured in BOT_NAME';
|
|
35
|
-
}
|
|
36
|
-
export async function handleBotName(ctx) {
|
|
37
|
-
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
38
|
-
if (!keyInfo)
|
|
39
|
-
return;
|
|
40
|
-
const { sessionKey } = keyInfo;
|
|
41
|
-
const settings = getBotNameSettings(sessionKey);
|
|
42
|
-
const currentStatus = settings.enabled ? 'ON' : 'OFF';
|
|
43
|
-
const keyboard = [
|
|
44
|
-
[
|
|
45
|
-
{
|
|
46
|
-
text: settings.enabled ? '✓ On' : 'On',
|
|
47
|
-
callback_data: 'botname:on'
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
text: !settings.enabled ? '✓ Off' : 'Off',
|
|
51
|
-
callback_data: 'botname:off'
|
|
52
|
-
},
|
|
53
|
-
],
|
|
54
|
-
];
|
|
55
|
-
const message = new EntityText()
|
|
56
|
-
.add('✏️ ').bold('Dynamic Bot Name')
|
|
57
|
-
.add('\n\nCurrent: ').bold(currentStatus)
|
|
58
|
-
.newline().italic(botNameDescription(settings.enabled))
|
|
59
|
-
.build();
|
|
60
|
-
await replyFormatted(ctx, message, { reply_markup: { inline_keyboard: keyboard } });
|
|
61
|
-
}
|
|
62
|
-
export async function handleBotNameCallback(ctx) {
|
|
63
|
-
const cb = parseCallback(ctx, 'botname:');
|
|
64
|
-
if (!cb)
|
|
65
|
-
return;
|
|
66
|
-
const { sessionKey, data } = cb;
|
|
67
|
-
const newState = data.replace('botname:', '') === 'on';
|
|
68
|
-
setBotNameEnabled(sessionKey, newState);
|
|
69
|
-
const statusText = newState ? 'ON' : 'OFF';
|
|
70
|
-
await ctx.answerCallbackQuery({ text: `Dynamic bot name ${statusText}!` });
|
|
71
|
-
await editCallbackMessage(ctx, new EntityText()
|
|
72
|
-
.add('✅ Dynamic Bot Name ').bold(statusText)
|
|
73
|
-
.newline(2).italic(botNameDescription(newState))
|
|
74
|
-
.build());
|
|
75
|
-
// Reset bot name to base when disabling
|
|
76
|
-
if (!newState) {
|
|
77
|
-
await pushBotName(ctx, config.BOT_NAME, 'disable reset');
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
27
|
//# sourceMappingURL=topic.js.map
|
|
@@ -22,13 +22,11 @@
|
|
|
22
22
|
* `--resume` — nothing here can append a stray turn to a live conversation,
|
|
23
23
|
* and the command answers before a project is even open.
|
|
24
24
|
*
|
|
25
|
-
* What the probe can't have, the chat's own claude still holds
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* fuller in PTY mode than in SDK mode, where the totals stay unanswerable and
|
|
31
|
-
* TeleCoder's own per-turn tally stands in.
|
|
25
|
+
* What the probe can't have, the chat's own claude still holds: a live TUI a
|
|
26
|
+
* `/cost` away from drawing exactly those totals, so we ask it too and scrape
|
|
27
|
+
* the Session block off the overlay — the same trick /tasks uses. That is
|
|
28
|
+
* where "Total cost", the durations, the per-model breakdown and the
|
|
29
|
+
* prompt-cache line come from.
|
|
32
30
|
*
|
|
33
31
|
* Two sources, one report, no overlap: the panel's own limits view is left
|
|
34
32
|
* unscraped (it scrolls off the first screenful anyway) and read from the
|
|
@@ -37,17 +35,15 @@
|
|
|
37
35
|
import { spawn } from 'child_process';
|
|
38
36
|
import * as fs from 'fs';
|
|
39
37
|
import { sessionManager } from '../../../claude/session-manager.js';
|
|
40
|
-
import { config } from '../../../config.js';
|
|
41
|
-
import { getSessionCost } from '../../../claude/session-cost.js';
|
|
42
38
|
import { scrapeCostSession } from '../../../claude/cost-overlay-scraper.js';
|
|
43
|
-
import {
|
|
39
|
+
import { getPtyProvider } from '../../../providers/claude-provider.js';
|
|
44
40
|
import { messageSender } from '../../../telegram/message-sender.js';
|
|
45
41
|
import { getProgressBar } from '../../../utils/format.js';
|
|
46
|
-
import {
|
|
42
|
+
import { resolvePtyClaudeBin } from '../../../utils/resolve-claude-bin.js';
|
|
47
43
|
import { sanitizeError } from '../../../utils/sanitize.js';
|
|
48
44
|
import { getSessionKeyFromCtx } from '../../../utils/session-key.js';
|
|
49
45
|
import { getWorkspaceRoot } from '../../../utils/workspace-guard.js';
|
|
50
|
-
/** The probe answers in ~2s;
|
|
46
|
+
/** The probe answers in ~2s; 20s is ten times that. */
|
|
51
47
|
const COST_TIMEOUT_MS = 20_000;
|
|
52
48
|
/** Output cap, standing in for `execFile`'s `maxBuffer`. */
|
|
53
49
|
const MAX_OUTPUT_BYTES = 1024 * 1024;
|
|
@@ -85,16 +81,13 @@ function renderSessionBlock(session) {
|
|
|
85
81
|
/**
|
|
86
82
|
* Render `claude -p /cost` output as Telegram markdown.
|
|
87
83
|
*
|
|
88
|
-
* `chatCost` is TeleCoder's own running tally for this conversation, used in
|
|
89
|
-
* SDK mode where nothing else can answer what the chat has spent.
|
|
90
|
-
*
|
|
91
84
|
* `session` is the Session block off the live TUI's `/cost` panel — the real
|
|
92
|
-
* totals for this conversation,
|
|
93
|
-
* probe's own `Total ...` rows are dropped rather than printed
|
|
94
|
-
* belong to the process that ran the lookup, and two
|
|
95
|
-
* totals in one message is worse than the one true set.
|
|
85
|
+
* totals for this conversation, when there is a live pty to ask. When we have
|
|
86
|
+
* it, the probe's own `Total ...` rows are dropped rather than printed
|
|
87
|
+
* alongside: they belong to the process that ran the lookup, and two
|
|
88
|
+
* contradicting sets of totals in one message is worse than the one true set.
|
|
96
89
|
*/
|
|
97
|
-
export function parseCostOutput(raw,
|
|
90
|
+
export function parseCostOutput(raw, session) {
|
|
98
91
|
const trimmed = raw.trim();
|
|
99
92
|
if (!trimmed) {
|
|
100
93
|
// The probe failing doesn't make the live totals worthless — they are the
|
|
@@ -206,30 +199,16 @@ export function parseCostOutput(raw, chatCost, session) {
|
|
|
206
199
|
lines.push('');
|
|
207
200
|
lines.push('_Totals cover this lookup only — Claude Code keeps no per-conversation cost once a turn ends._');
|
|
208
201
|
}
|
|
209
|
-
if (chatCost && chatCost.turns > 0) {
|
|
210
|
-
if (lines[lines.length - 1] !== '')
|
|
211
|
-
lines.push('');
|
|
212
|
-
const turns = chatCost.turns === 1 ? '1 turn' : `${chatCost.turns} turns`;
|
|
213
|
-
lines.push(`**This chat:** $${chatCost.usd.toFixed(4)} across ${turns} — TeleCoder's own tally, since the CLI keeps none.`);
|
|
214
|
-
}
|
|
215
202
|
return lines.join('\n').trimEnd();
|
|
216
203
|
}
|
|
217
204
|
/**
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
* depend on it is how much gets printed: the copy bundled with the SDK trails
|
|
223
|
-
* the user's own install by many releases, and older builds reply with a
|
|
224
|
-
* single sentence where current ones break every limit down with its reset
|
|
225
|
-
* time. So ask the install the user maintains — the same `claude` they would
|
|
226
|
-
* type `/cost` into — and keep the bundled binary as the fallback for setups
|
|
227
|
-
* with no CLI on PATH at all.
|
|
205
|
+
* The CLI to ask: the one the ptys run — the same `claude` the user would type
|
|
206
|
+
* `/cost` into. Spawned fresh with nothing spent in it, so the substance of the
|
|
207
|
+
* answer does not depend on the process. A list, for runClaudeCost, which
|
|
208
|
+
* moves on from a candidate that could not be started.
|
|
228
209
|
*/
|
|
229
210
|
function costExecutables() {
|
|
230
|
-
|
|
231
|
-
const bundled = resolveActiveClaudeExecutable();
|
|
232
|
-
return preferred === bundled ? [preferred] : [preferred, bundled];
|
|
211
|
+
return [resolvePtyClaudeBin()];
|
|
233
212
|
}
|
|
234
213
|
/** A CLI that never started, as opposed to one that ran and failed. */
|
|
235
214
|
function isSpawnFailure(error) {
|
|
@@ -328,21 +307,15 @@ function resolveSpawnCwd(sessionCwd) {
|
|
|
328
307
|
* it has always carried. But saying nothing was worse than the missing
|
|
329
308
|
* numbers: a blank where a Session block should be looks like the feature is
|
|
330
309
|
* broken, when three of the four causes clear by themselves.
|
|
331
|
-
*
|
|
332
|
-
* `no-session` under SDK mode is the exception, and the only silent one — that
|
|
333
|
-
* transport has no TUI to read and never will, so there is no news in saying
|
|
334
|
-
* so on every `/cost`.
|
|
335
310
|
*/
|
|
336
|
-
export function explainMissingTotals(reason
|
|
311
|
+
export function explainMissingTotals(reason) {
|
|
337
312
|
switch (reason) {
|
|
338
313
|
case 'turn-active':
|
|
339
314
|
return "This session's totals need the TUI, which is mid-turn — ask again when it finishes.";
|
|
340
315
|
case 'not-ready':
|
|
341
316
|
return "This session's totals need the TUI, which isn't at its prompt — a dialog may be waiting. Ask again in a moment.";
|
|
342
317
|
case 'no-session':
|
|
343
|
-
return
|
|
344
|
-
? "This chat has no live session yet, so there are no totals to read — send a message first."
|
|
345
|
-
: null;
|
|
318
|
+
return "This chat has no live session yet, so there are no totals to read — send a message first.";
|
|
346
319
|
case 'unreadable':
|
|
347
320
|
// The panel is a Claude Code implementation detail and can move between
|
|
348
321
|
// releases. Say that plainly rather than leave a silent gap.
|
|
@@ -352,15 +325,15 @@ export function explainMissingTotals(reason, method) {
|
|
|
352
325
|
/**
|
|
353
326
|
* The chat's own totals, read off the live TUI's `/cost` panel.
|
|
354
327
|
*
|
|
355
|
-
*
|
|
328
|
+
* Best-effort in every failure it can meet: no live session, a
|
|
356
329
|
* turn holding the keyboard, a panel whose layout has moved on. None is worth
|
|
357
330
|
* failing the command over — but each is worth naming, in the log for us and
|
|
358
331
|
* in the report for whoever is looking at the gap.
|
|
359
332
|
*/
|
|
360
|
-
async function readLiveSessionTotals(sessionKey
|
|
333
|
+
async function readLiveSessionTotals(sessionKey) {
|
|
361
334
|
const miss = (reason) => {
|
|
362
|
-
console.warn(`[
|
|
363
|
-
return { session: null, note: explainMissingTotals(reason
|
|
335
|
+
console.warn(`[Usage] no live session totals for ${sessionKey}: ${reason}`);
|
|
336
|
+
return { session: null, note: explainMissingTotals(reason) };
|
|
364
337
|
};
|
|
365
338
|
try {
|
|
366
339
|
const result = await getPtyProvider().runOverlayCommand(sessionKey, '/cost');
|
|
@@ -370,15 +343,15 @@ async function readLiveSessionTotals(sessionKey, method) {
|
|
|
370
343
|
return session ? { session, note: null } : miss('unreadable');
|
|
371
344
|
}
|
|
372
345
|
catch (error) {
|
|
373
|
-
console.warn('[
|
|
374
|
-
return { session: null, note: explainMissingTotals('unreadable'
|
|
346
|
+
console.warn('[Usage] Could not read the live /cost panel:', sanitizeError(error));
|
|
347
|
+
return { session: null, note: explainMissingTotals('unreadable') };
|
|
375
348
|
}
|
|
376
349
|
}
|
|
377
|
-
export async function
|
|
350
|
+
export async function handleUsage(ctx) {
|
|
378
351
|
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
379
352
|
if (!keyInfo)
|
|
380
353
|
return;
|
|
381
|
-
const {
|
|
354
|
+
const { sessionKey } = keyInfo;
|
|
382
355
|
// Deliberately no session guard: limits are account-wide, so the answer is
|
|
383
356
|
// the same — and just as useful — in a chat that has never opened a project.
|
|
384
357
|
const session = sessionManager.getSession(sessionKey);
|
|
@@ -389,16 +362,16 @@ export async function handleCost(ctx) {
|
|
|
389
362
|
// into a process already running, and neither waits on the other.
|
|
390
363
|
const [raw, live] = await Promise.all([
|
|
391
364
|
runClaudeCost(costExecutables(), cwd),
|
|
392
|
-
readLiveSessionTotals(sessionKey
|
|
365
|
+
readLiveSessionTotals(sessionKey),
|
|
393
366
|
]);
|
|
394
367
|
await typing?.catch(() => { });
|
|
395
|
-
let report = parseCostOutput(raw,
|
|
368
|
+
let report = parseCostOutput(raw, live.session);
|
|
396
369
|
if (live.note)
|
|
397
370
|
report += `\n\n_${live.note}_`;
|
|
398
371
|
await messageSender.sendMessage(ctx, report);
|
|
399
372
|
}
|
|
400
373
|
catch (error) {
|
|
401
|
-
console.error('[
|
|
374
|
+
console.error('[Usage] Failed to run /cost:', sanitizeError(error));
|
|
402
375
|
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
403
376
|
const hint = /unknown|unrecognized|command/i.test(message)
|
|
404
377
|
? '\n\nThis Claude Code build may not support `/cost` yet.'
|
|
@@ -406,4 +379,4 @@ export async function handleCost(ctx) {
|
|
|
406
379
|
await messageSender.sendMessage(ctx, `❌ Failed to fetch cost: ${message}${hint}`);
|
|
407
380
|
}
|
|
408
381
|
}
|
|
409
|
-
//# sourceMappingURL=
|
|
382
|
+
//# sourceMappingURL=usage.js.map
|