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.
Files changed (197) hide show
  1. package/.env.example +142 -130
  2. package/CHANGELOG.md +683 -2
  3. package/README.md +36 -32
  4. package/dist/audio/transcribe.js +0 -9
  5. package/dist/bin/mcp-server.js +46 -61
  6. package/dist/bot/bot.js +162 -181
  7. package/dist/bot/command-catalog.js +263 -0
  8. package/dist/bot/deleted-threads.js +103 -0
  9. package/dist/bot/file-access.js +35 -26
  10. package/dist/bot/handlers/album.handler.js +128 -0
  11. package/dist/bot/handlers/{fork.handler.js → branch.handler.js} +267 -280
  12. package/dist/bot/handlers/command/access.js +1 -1
  13. package/dist/bot/handlers/command/admin.js +86 -110
  14. package/dist/bot/handlers/command/all-view.js +33 -0
  15. package/dist/bot/handlers/command/auto-approve.js +3 -3
  16. package/dist/bot/handlers/command/background.js +37 -0
  17. package/dist/bot/handlers/command/botname.js +76 -0
  18. package/dist/bot/handlers/command/btw.js +20 -69
  19. package/dist/bot/handlers/command/cleanup.js +329 -0
  20. package/dist/bot/handlers/command/model.js +40 -119
  21. package/dist/bot/handlers/command/prefs-scope.js +255 -90
  22. package/dist/bot/handlers/command/project.js +31 -109
  23. package/dist/bot/handlers/command/resume.js +8 -4
  24. package/dist/bot/handlers/command/session.js +74 -213
  25. package/dist/bot/handlers/command/settings.js +92 -447
  26. package/dist/bot/handlers/command/shared.js +32 -35
  27. package/dist/bot/handlers/command/tasks.js +263 -95
  28. package/dist/bot/handlers/command/thread.js +128 -0
  29. package/dist/bot/handlers/command/topic-store.js +14 -53
  30. package/dist/bot/handlers/command/topic.js +8 -61
  31. package/dist/bot/handlers/command/{cost.js → usage.js} +32 -59
  32. package/dist/bot/handlers/command-fallback.js +179 -0
  33. package/dist/bot/handlers/command.handler.js +96 -422
  34. package/dist/bot/handlers/{schedule.handler.js → loop.handler.js} +159 -73
  35. package/dist/bot/handlers/media-fallback.js +12 -7
  36. package/dist/bot/handlers/message/replies.js +10 -87
  37. package/dist/bot/handlers/message/shared.js +9 -31
  38. package/dist/bot/handlers/message/turn-notify.js +15 -49
  39. package/dist/bot/handlers/message/turn-runner.js +18 -103
  40. package/dist/bot/handlers/message.handler.js +59 -52
  41. package/dist/bot/handlers/newbot.handler.js +13 -4
  42. package/dist/bot/handlers/photo.handler.js +88 -129
  43. package/dist/bot/handlers/prompts.handler.js +11 -11
  44. package/dist/bot/handlers/running-note.js +2 -2
  45. package/dist/bot/handlers/session-guard.js +4 -4
  46. package/dist/bot/handlers/suggestion.handler.js +2 -2
  47. package/dist/bot/handlers/tree.handler.js +20 -20
  48. package/dist/bot/handlers/voice.handler.js +23 -85
  49. package/dist/bot/kept-threads.js +51 -0
  50. package/dist/bot/middleware/album-collector.js +69 -0
  51. package/dist/bot/middleware/auth.middleware.js +1 -1
  52. package/dist/bot/middleware/group-mention.middleware.js +11 -5
  53. package/dist/bot/middleware/queued-messages.js +143 -32
  54. package/dist/bot/middleware/stale-filter.js +0 -22
  55. package/dist/build-info.json +5 -5
  56. package/dist/claude/ask-user-form.js +517 -0
  57. package/dist/claude/ask-user.js +94 -26
  58. package/dist/claude/auto-topic-haiku.js +17 -0
  59. package/dist/claude/available-commands.js +22 -19
  60. package/dist/claude/background-hint.js +91 -0
  61. package/dist/claude/{fork-tree.js → branch-tree.js} +9 -9
  62. package/dist/claude/carry-over.js +0 -2
  63. package/dist/claude/ccr-shim.js +12 -10
  64. package/dist/claude/claude-auth.js +6 -10
  65. package/dist/claude/command-parser.js +49 -43
  66. package/dist/claude/cost-overlay-scraper.js +7 -2
  67. package/dist/claude/effort-level.js +5 -0
  68. package/dist/claude/enabled-plugins.js +12 -16
  69. package/dist/claude/in-flight-tracker.js +21 -0
  70. package/dist/claude/mcp-bridge.js +86 -58
  71. package/dist/claude/memory-guard.js +400 -0
  72. package/dist/claude/message-offsets.js +5 -5
  73. package/dist/claude/modal-relay.js +401 -34
  74. package/dist/claude/model-catalog.js +20 -3
  75. package/dist/claude/monitor-relay.js +130 -15
  76. package/dist/claude/native-commands.js +40 -0
  77. package/dist/claude/{pending-forks.js → pending-branches.js} +26 -26
  78. package/dist/claude/permission-gate.js +11 -10
  79. package/dist/claude/permission-mode.js +19 -45
  80. package/dist/claude/prewarm.js +70 -0
  81. package/dist/claude/pty-idle-reaper.js +96 -0
  82. package/dist/claude/pty-provider.js +473 -188
  83. package/dist/claude/pty-spawn-config.js +79 -32
  84. package/dist/claude/pty-watch.js +201 -0
  85. package/dist/claude/request-queue.js +7 -35
  86. package/dist/claude/rewind.js +111 -0
  87. package/dist/claude/scheduled-runner.js +1 -3
  88. package/dist/claude/scheduler.js +6 -2
  89. package/dist/claude/scope-guard.js +8 -3
  90. package/dist/claude/screen-marks.js +83 -0
  91. package/dist/claude/screen-render.js +96 -0
  92. package/dist/claude/session-history.js +4 -2
  93. package/dist/claude/session-jsonl.js +162 -15
  94. package/dist/claude/session-manager.js +29 -8
  95. package/dist/claude/session-move.js +70 -0
  96. package/dist/claude/shell-mode-gate.js +60 -0
  97. package/dist/claude/side-question.js +20 -17
  98. package/dist/claude/stage-images.js +5 -5
  99. package/dist/claude/tasks-overlay-scraper.js +143 -20
  100. package/dist/claude/thread-judge-haiku.js +88 -0
  101. package/dist/claude/tip-scraper.js +3 -4
  102. package/dist/claude/tui-modal.js +272 -27
  103. package/dist/claude/tui-state.js +74 -2
  104. package/dist/claude/turn-end.js +15 -1
  105. package/dist/claude/turn-prose.js +1 -1
  106. package/dist/claude/typed-answer.js +104 -0
  107. package/dist/claude/update-banner-relay.js +1 -1
  108. package/dist/cli/commands/doctor.js +48 -15
  109. package/dist/cli/commands/help.js +11 -2
  110. package/dist/cli/commands/init.js +16 -13
  111. package/dist/cli/commands/service.js +40 -8
  112. package/dist/cli/commands/start.js +10 -0
  113. package/dist/cli/commands/watch.js +322 -0
  114. package/dist/cli/dispatch.js +5 -0
  115. package/dist/cli/init/env-file.js +1 -1
  116. package/dist/cli/init/flow.js +114 -47
  117. package/dist/cli/init/prompter.js +8 -0
  118. package/dist/cli/init/telegram.js +35 -9
  119. package/dist/cli/service/render.js +3 -3
  120. package/dist/config.js +156 -131
  121. package/dist/index.js +107 -31
  122. package/dist/launcher.js +34 -7
  123. package/dist/providers/ccr-introspect.js +1 -8
  124. package/dist/providers/ccr-provider.js +19 -20
  125. package/dist/providers/claude-provider.js +4 -57
  126. package/dist/providers/prefs-sync.js +16 -59
  127. package/dist/providers/provider-router.js +24 -23
  128. package/dist/providers/spawn-settings.js +45 -0
  129. package/dist/providers/user-preferences.js +127 -19
  130. package/dist/restart-when-idle.js +27 -7
  131. package/dist/startup/auto-continue.js +2 -2
  132. package/dist/startup/auto-resume.js +3 -15
  133. package/dist/startup/notices.js +1 -1
  134. package/dist/startup/verify-token.js +4 -4
  135. package/dist/telegram/action-logger.js +3 -165
  136. package/dist/telegram/background-activity-card.js +1 -1
  137. package/dist/telegram/botname-settings.js +71 -125
  138. package/dist/telegram/client-options.js +6 -7
  139. package/dist/telegram/force-reply-tracker.js +55 -16
  140. package/dist/telegram/message-sender.js +92 -360
  141. package/dist/telegram/prompt-label.js +11 -5
  142. package/dist/telegram/streaming-turn.js +5 -7
  143. package/dist/telegram/table-lists.js +56 -0
  144. package/dist/telegram/task-list.js +4 -4
  145. package/dist/telegram/task-tracker.js +45 -126
  146. package/dist/telegram/terminal-renderer.js +1 -5
  147. package/dist/telegram/thread-titles.js +74 -2
  148. package/dist/telegram/threads-setup.js +1 -1
  149. package/dist/utils/admins.js +2 -2
  150. package/dist/utils/bot-icon.js +248 -0
  151. package/dist/utils/bot-token.js +8 -5
  152. package/dist/utils/build-info.js +3 -3
  153. package/dist/utils/caffeinate.js +6 -3
  154. package/dist/utils/claude-env.js +0 -1
  155. package/dist/utils/claude-version.js +2 -2
  156. package/dist/utils/config-home.js +3 -3
  157. package/dist/utils/download.js +41 -15
  158. package/dist/utils/exit-codes.js +11 -0
  159. package/dist/utils/format.js +3 -6
  160. package/dist/utils/home-project.js +1 -1
  161. package/dist/utils/idle-restart.js +1 -1
  162. package/dist/utils/install-mode.js +1 -1
  163. package/dist/utils/instance-config.js +1 -1
  164. package/dist/utils/instances.js +1 -1
  165. package/dist/utils/keyed-settings.js +2 -2
  166. package/dist/utils/memory-pressure.js +60 -0
  167. package/dist/utils/npm-version.js +2 -2
  168. package/dist/utils/resolve-claude-bin.js +13 -24
  169. package/dist/utils/respawn-backoff.js +9 -0
  170. package/dist/utils/stale-launcher.js +1 -1
  171. package/dist/utils/systemd.js +8 -8
  172. package/dist/utils/telegram-proxy.js +72 -0
  173. package/dist/utils/uploads-dir.js +27 -0
  174. package/dist/utils/verbosity.js +8 -8
  175. package/dist/utils/version-check.js +5 -5
  176. package/package.json +3 -4
  177. package/dist/bot/handlers/command/media.js +0 -197
  178. package/dist/bot/handlers/command/streaming-mode.js +0 -16
  179. package/dist/bot/handlers/message/throttle.js +0 -49
  180. package/dist/claude/agent-watchdog.js +0 -162
  181. package/dist/claude/agent.js +0 -1458
  182. package/dist/claude/held-query.js +0 -190
  183. package/dist/claude/mcp-tools.js +0 -354
  184. package/dist/claude/sdk-permission-gate.js +0 -77
  185. package/dist/claude/session-cost.js +0 -41
  186. package/dist/claude/system-prompt.js +0 -162
  187. package/dist/providers/sdk-provider.js +0 -37
  188. package/dist/telegram/telegraph-settings.js +0 -31
  189. package/dist/telegram/telegraph.js +0 -453
  190. package/dist/telegram/terminal-settings.js +0 -25
  191. package/dist/tts/tts-settings.js +0 -62
  192. package/dist/tts/tts.js +0 -245
  193. package/dist/tts/voice-reply.js +0 -78
  194. package/dist/utils/debug-agent.js +0 -117
  195. package/dist/utils/debug-watchdog.js +0 -121
  196. package/dist/utils/project-data-dir.js +0 -33
  197. 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 and Telegram bot display name — the state and the mutators.
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: `agent.ts` and
9
- * `mcp-tools.ts` both need to read and set the topic, and importing it from
10
- * the command barrel closed an import cycle (barrel -> command/shared.ts ->
11
- * claude-provider -> sdk-provider -> agent -> back to the barrel). Nothing
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 and refresh the bot display name accordingly.
56
- * Called whenever the conversation context is wiped (clear, reset, project switch).
26
+ * Clear the session topic. Called whenever the conversation context is wiped
27
+ * (clear, reset, project switch).
57
28
  */
58
- export async function clearTopicAndRefreshBotName(ctx, sessionKey) {
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) and refresh
66
- * the bot display name. Called when resuming/continuing a previous conversation.
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 async function restoreTopicAndRefreshBotName(ctx, sessionKey, topic) {
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 and /botname commands.
2
+ * The /topic command.
3
3
  *
4
- * The topic state itself and the bot-name mutators live in `topic-store.ts`,
5
- * which stays below the provider layer so `agent.ts` and `mcp-tools.ts` can
6
- * read and set the topic without closing an import cycle. This module adds
7
- * the Telegram command surface on top and re-exports the store so the command
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, editCallbackMessage } from '../../../telegram/send.js';
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 { parseCallback } from './shared.js';
16
- import { pushBotName, setSessionTopic } from './topic-store.js';
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. In PTY mode
26
- * there is a live TUI a `/cost` away from drawing exactly those totals, so we
27
- * ask it too and scrape the Session block off the overlay — the same trick
28
- * /tasks uses. That is where "Total cost", the durations, the per-model
29
- * breakdown and the prompt-cache line come from, and it is why the report is
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 { getActiveMethod, getPtyProvider } from '../../../providers/claude-provider.js';
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 { resolveActiveClaudeExecutable } from '../../../utils/resolve-claude-bin.js';
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; the ceiling matches `/context`'s. */
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, present only in PTY mode. When we have it, the
93
- * probe's own `Total ...` rows are dropped rather than printed alongside: they
94
- * belong to the process that ran the lookup, and two contradicting sets of
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, chatCost, session) {
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
- * Which CLI to ask, best first.
219
- *
220
- * Every candidate is spawned as a fresh process with nothing spent in it, so
221
- * the substance of the answer does not depend on which one asks. What does
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
- const preferred = process.env.CLAUDE_BIN || config.CLAUDE_EXECUTABLE_PATH;
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, method) {
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 method === 'pty'
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
- * PTY-only, and best-effort in every failure it can meet: no live session, a
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, method) {
333
+ async function readLiveSessionTotals(sessionKey) {
361
334
  const miss = (reason) => {
362
- console.warn(`[Cost] no live session totals for ${sessionKey}: ${reason} (method=${method})`);
363
- return { session: null, note: explainMissingTotals(reason, method) };
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('[Cost] Could not read the live /cost panel:', sanitizeError(error));
374
- return { session: null, note: explainMissingTotals('unreadable', method) };
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 handleCost(ctx) {
350
+ export async function handleUsage(ctx) {
378
351
  const keyInfo = getSessionKeyFromCtx(ctx);
379
352
  if (!keyInfo)
380
353
  return;
381
- const { chatId, sessionKey } = keyInfo;
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, getActiveMethod(sessionKey)),
365
+ readLiveSessionTotals(sessionKey),
393
366
  ]);
394
367
  await typing?.catch(() => { });
395
- let report = parseCostOutput(raw, getSessionCost(sessionKey), live.session);
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('[Cost] Failed to run /cost:', sanitizeError(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=cost.js.map
382
+ //# sourceMappingURL=usage.js.map