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
package/README.md CHANGED
@@ -3,18 +3,18 @@
3
3
  # TeleCoder
4
4
 
5
5
  **Claude Code in Telegram.** The real agent runs on your machine; you drive it from Telegram's
6
- native apps, with a thread per conversation, forks and the full CLI.
6
+ native apps, with a thread per conversation, branches and the full CLI.
7
7
 
8
- [![CI](https://github.com/gitaarik/telecoder/actions/workflows/ci.yml/badge.svg)](https://github.com/gitaarik/telecoder/actions/workflows/ci.yml)
8
+ [![CI](https://github.com/telecoderbot/telecoder/actions/workflows/ci.yml/badge.svg)](https://github.com/telecoderbot/telecoder/actions/workflows/ci.yml)
9
9
  [![npm](https://img.shields.io/npm/v/telecoder?color=cc785c)](https://www.npmjs.com/package/telecoder)
10
10
  [![Node](https://img.shields.io/badge/Node.js-22%2B-339933?logo=node.js&logoColor=white)](https://nodejs.org/)
11
11
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
12
12
 
13
- [Website](https://telecoder.dev) · [Quick start](#quick-start) · [Features](docs/features.md) · [Commands](docs/commands.md) · [Docs](#documentation) · [Changelog](CHANGELOG.md)
13
+ [Website](https://telecoder.dev) · [Quick start](#quick-start) · [Features](site/src/content/docs/guides/features.md) · [Commands](site/src/content/docs/reference/commands.md) · [Docs](#documentation) · [Changelog](CHANGELOG.md)
14
14
 
15
15
  </div>
16
16
 
17
- <!-- Demo GIF goes here: a thread, a fork into a new thread, a permission prompt, a voice note. -->
17
+ <!-- Demo GIF goes here: a thread, a branch into a new thread, a permission prompt, a voice note. -->
18
18
 
19
19
  ---
20
20
 
@@ -30,37 +30,39 @@ TeleCoder puts Claude Code inside them.
30
30
  - **A thread per conversation.** Each thread is its own Claude session, in groups and in
31
31
  private chats. Start a thread and you have a new session; run five tasks side by side and
32
32
  switch between them like chats.
33
- - **Forks.** `/fork` copies the conversation into a new thread; `/spinoff` splits a task off
33
+ - **Branches.** `/branch` copies the conversation into a new thread; `/spinoff` splits a task off
34
34
  with a compacted copy of the context; `/tree` draws the branches and lets you jump between
35
35
  them.
36
- - **The full CLI, not a subset.** In PTY mode TeleCoder drives the real `claude` TUI, so a
37
- project's `CLAUDE.md`, settings, skills and slash commands work as they do in your terminal,
38
- and its permission dialogs arrive as buttons. `/model`, `/effort`, `/compact`, `/context`,
39
- `/cost` and `/resume` are there too. The Agent SDK mode is the lighter default.
36
+ - **The full CLI, not a subset.** TeleCoder drives the real `claude` TUI, so a project's
37
+ `CLAUDE.md`, settings, skills and slash commands work as they do in your terminal, and its
38
+ permission dialogs arrive as buttons. `/model`, `/effort`, `/compact`, `/context`, `/usage`,
39
+ `/rewind` and `/resume` are there too, and `/cc <command>` reaches a Claude Code command
40
+ the bot has its own version of.
40
41
  - **Claude can reach you.** It can ask with buttons, send you files, ask for an API key
41
42
  (your message is deleted the moment it arrives), schedule prompts, and report background
42
43
  tasks as they finish.
43
- - **Built for working away from your desk.** Voice notes in, spoken replies out. `/btw` asks
44
- a side question without stopping the task, `/steer` corrects it mid-turn, and `/later` sets
45
- an idea aside for when Claude is done. Sessions carry on by themselves after a restart.
44
+ - **Built for working away from your desk.** Send voice notes as prompts. `/btw` asks
45
+ a side question without stopping the task, `/steer` corrects it mid-turn, `/later` sets
46
+ an idea aside for when Claude is done, and `/ctrlb` is Claude Code's Ctrl+B. Sessions
47
+ carry on by themselves after a restart.
46
48
  - **More than one bot.** Run a bot per project from one process, and make a new one from
47
49
  chat with `/newbot`, without a BotFather conversation.
48
50
  - **Shareable, carefully.** Admins, guests and approvers, a permission gate on every
49
- transport, a scope guard for paths, and a charter checked before a guest's message runs.
51
+ tool call, a scope guard for paths, and a charter checked before a guest's message runs.
50
52
 
51
- The full list is in [docs/features.md](docs/features.md).
53
+ The full list is on the [Features](site/src/content/docs/guides/features.md) page.
52
54
 
53
55
  ## How it compares
54
56
 
55
57
  - **Claude Code Channels** (the official Telegram and Discord plugin) pushes chat messages
56
58
  into a Claude Code session you started in a terminal. It's a good fit for nudging one running
57
59
  session. TeleCoder starts and keeps its own sessions, so you get as many as you have
58
- threads, plus forks, resume, voice and the commands above.
60
+ threads, plus branches, resume, voice and the commands above.
59
61
  - **Remote Control** lets you look in on a terminal session from the Claude app. Use it when
60
62
  you want the session you already have, on Anthropic's own UI.
61
63
  - **[claude-code-telegram](https://github.com/RichardAtCT/claude-code-telegram)** is the
62
64
  most popular community bot: Python, SDK-based, with cost caps and webhooks. TeleCoder
63
- adds the PTY mode with full CLI parity, threads, forks and multiple bots.
65
+ drives the full CLI itself, and adds threads, branches and multiple bots.
64
66
  - **Web UIs** such as [CloudCLI](https://github.com/siteboon/claudecodeui) give you a
65
67
  browser dashboard with file trees and diffs. TeleCoder gives up the dashboard for native
66
68
  apps, notifications and voice.
@@ -80,31 +82,33 @@ telecoder service install # keep it running, and start it at boot
80
82
 
81
83
  `telecoder init` checks the token with Telegram, learns your user ID when you send the bot
82
84
  `/start`, and writes `~/.telecoder/.env`, readable by you only. Then open your bot in Telegram,
83
- pick a project with `/project` and start talking.
85
+ pick a project with `/dir` and start talking.
84
86
 
85
- `telecoder doctor` checks your setup, `telecoder service logs` follows the output and `/update`
87
+ `telecoder doctor` checks your setup, `telecoder service logs` follows the output and `/botupdate`
86
88
  upgrades from chat. To run from a git checkout instead, see
87
- [docs/install.md](docs/install.md#from-source).
89
+ [Install and run](site/src/content/docs/start/install.md#from-source).
88
90
 
89
91
  ## Documentation
90
92
 
91
- - [Install and run](docs/install.md): prerequisites, the wizard, the background service, running from source
92
- - [Features](docs/features.md): everything TeleCoder does
93
- - [Commands](docs/commands.md): every bot command
94
- - [Multiple bots](docs/multiple-bots.md): `instances.json`, `/newbot` and a home project per bot
95
- - [Providers](docs/providers.md): SDK or PTY, and Claude Code Router for when Max throttles
96
- - [Sharing a bot](docs/sharing.md): admins, guests, group roles, the permission gate and a separate Unix account
97
- - [Configuration](docs/configuration.md): every `.env` setting
98
- - [Security](docs/security.md): what's protected, what's stored and where data goes
99
- - [Architecture and development](docs/architecture.md): how it's built, and how to work on it
93
+ - [Get started](site/src/content/docs/start/get-started.md): a first setup, step by step, from BotFather to threads
94
+ - [Install and run](site/src/content/docs/start/install.md): prerequisites, the wizard, the background service, running from source
95
+ - [Features](site/src/content/docs/guides/features.md): everything TeleCoder does
96
+ - [Commands](site/src/content/docs/reference/commands.md): every bot command
97
+ - [Multiple bots](site/src/content/docs/guides/multiple-bots.md): `instances.json`, `/newbot` and a home project per bot
98
+ - [Providers](site/src/content/docs/guides/providers.md): Claude Code Router for when Max throttles
99
+ - [Sharing a bot](site/src/content/docs/guides/sharing.md): admins, guests, group roles, the permission gate and a separate Unix account
100
+ - [Configuration](site/src/content/docs/reference/configuration.md): every `.env` setting
101
+ - [Security](site/src/content/docs/reference/security.md): what's protected, what's stored and where data goes
102
+ - [Architecture and development](site/src/content/docs/reference/architecture.md): how it's built, and how to work on it
103
+ - [Troubleshooting](site/src/content/docs/help/troubleshooting.md) and [FAQ](site/src/content/docs/help/faq.md)
100
104
  - [Roadmap](ROADMAP.md), [changelog](CHANGELOG.md) and [contributing](CONTRIBUTING.md)
101
105
 
102
106
  ## Project status
103
107
 
104
108
  In active development, and used every day for my own work, including building TeleCoder
105
- itself. The latest release is 1.2.0, on [npm](https://www.npmjs.com/package/telecoder) and
109
+ itself. The latest release is 1.3.0, on [npm](https://www.npmjs.com/package/telecoder) and
106
110
  tagged here; the [changelog](CHANGELOG.md) lists what's in each release. The code is about
107
- 53k lines of TypeScript, plus 31k lines of tests (175 test files, 2,238 tests), and CI runs
111
+ 53k lines of TypeScript, plus 37k lines of tests (203 test files, 2,672 tests), and CI runs
108
112
  the type check, tests and build on every push.
109
113
 
110
114
  TeleCoder is self-hosted: it runs on your machine with your own Claude account, and there is no
@@ -115,8 +119,8 @@ hosted version.
115
119
  TeleCoder began as a fork of [Claudegram](https://github.com/NachoSEO/claudegram) by
116
120
  [@NachoSEO](https://github.com/NachoSEO), MIT-licensed, whose last commit was in March 2026.
117
121
  Claudegram's copyright notice is kept in [LICENSE](LICENSE). Since April 2026 TeleCoder has
118
- been developed independently by [@gitaarik](https://github.com/gitaarik): 450+ commits, adding
119
- about 107k lines and removing 29k. The history since the fork is all in this repository, which
122
+ been developed independently by [@gitaarik](https://github.com/gitaarik): 600+ commits, adding
123
+ about 145k lines and removing 47k. The history since the fork is all in this repository, which
120
124
  was created in July 2026 when the project was renamed, so its GitHub creation date is later than
121
125
  its first commits.
122
126
 
@@ -1,7 +1,6 @@
1
1
  import * as fs from 'fs';
2
2
  import * as path from 'path';
3
3
  import { config } from '../config.js';
4
- import { downloadFileSecure, getTelegramFileUrl } from '../utils/download.js';
5
4
  const GROQ_WHISPER_ENDPOINT = 'https://api.groq.com/openai/v1/audio/transcriptions';
6
5
  const GROQ_WHISPER_MODEL = 'whisper-large-v3-turbo';
7
6
  /**
@@ -39,12 +38,4 @@ export async function transcribeFile(filePath, options) {
39
38
  }
40
39
  return transcript;
41
40
  }
42
- /**
43
- * Download a file from Telegram servers securely.
44
- * Constructs the URL via getTelegramFileUrl and delegates to downloadFileSecure.
45
- */
46
- export function downloadTelegramAudio(botToken, filePath, destPath) {
47
- const fileUrl = getTelegramFileUrl(botToken, filePath);
48
- return downloadFileSecure(fileUrl, destPath);
49
- }
50
41
  //# sourceMappingURL=transcribe.js.map
@@ -4,7 +4,7 @@
4
4
  * Spawned by `claude --mcp-config` when running under PtyProvider, communicates
5
5
  * over stdio. Tools that need bot-side context (Telegram send_file / ask_user /
6
6
  * set_topic, …) POST to the main bot process's loopback IPC server; tools that
7
- * are pure local work (list_projects, publish_telegraph, …) run inline.
7
+ * are pure local work (list_projects, …) run inline.
8
8
  *
9
9
  * Env vars set by PtyProvider when spawning this process. These are an internal
10
10
  * contract between the two — PtyProvider writes them and only this file reads
@@ -15,7 +15,6 @@
15
15
  * inherited from claude's env, never in args
16
16
  * TELECODER_CLAUDE_SESSION_ID claude's session_id; used as the IPC routing key
17
17
  * TELECODER_WORKSPACE_ROOT workspace root for security checks
18
- * TELECODER_TELEGRAPH_ENABLED feature flag for publish_telegraph
19
18
  */
20
19
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
21
20
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
@@ -97,11 +96,6 @@ function ipc(routePath, payload = {}, signal) {
97
96
  req.end(body);
98
97
  });
99
98
  }
100
- // Lazy imports — keep startup fast, and only load modules whose tool is
101
- // actually present in this configuration.
102
- async function importTelegraph() {
103
- return import('../telegram/telegraph.js');
104
- }
105
99
  const server = new McpServer({
106
100
  name: 'telecoder-tools',
107
101
  version: '1.0.0',
@@ -131,8 +125,8 @@ server.tool('telecoder_list_projects', 'List all available projects in the works
131
125
  }
132
126
  });
133
127
  // ── telecoder_ask_user (IPC: long-poll on Telegram button tap) ──────
134
- server.tool('telecoder_ask_user', 'Ask the user a multiple-choice question via a Telegram inline keyboard. Use when you need a clear decision from the user (e.g. picking between approaches, confirming a destructive action, choosing among options) instead of free-text. Pauses the agent loop until the user taps a button or the question times out. Keep the question short and the options crisp — a label of ≤ 25 chars stays on its button; anything longer makes the whole keyboard fall back to lettered buttons (A/B/C) with the full labels listed in the message body. Prefer this over the built-in AskUserQuestion when interacting through TeleCoder. IMPORTANT: `context` is required and carries everything the user needs to decide (the comparison, trade-offs, findings, rationale) — it renders in the SAME message as the buttons. Do NOT write that explanation as prose before calling this tool: text you emit before an ask_user call is not delivered to the user until after they answer, so they would be choosing blind.', {
135
- question: z.string().describe('The question to display to the user. Keep concise (1-2 sentences).'),
128
+ server.tool('telecoder_ask_user', 'Ask the user a multiple-choice question via a Telegram inline keyboard. Use when you need a clear decision from the user (e.g. picking between approaches, confirming a destructive action, choosing among options) rather than asking in prose. Pauses the agent loop until the user answers or the question times out. The user can always answer in their own words instead of tapping, by sending a message; you then get `User answered in their own words: …`, so don\'t add an "Other" option. Keep the question short and the options crisp — a label of ≤ 25 chars stays on its button; anything longer makes the whole keyboard fall back to lettered buttons (A/B/C) with the full labels listed in the message body. Prefer this over the built-in AskUserQuestion when interacting through TeleCoder. Several questions at once: pass `questions` (2-4) instead of `question`/`options` — they arrive as ONE form the user steps through, can revise, and submits; nothing reaches you before Submit. Never fire separate calls in a row for questions that belong together. IMPORTANT: `context` is required and carries everything the user needs to decide (the comparison, trade-offs, findings, rationale) — it renders in the SAME message as the buttons. Do NOT write that explanation as prose before calling this tool: text you emit before an ask_user call is not delivered to the user until after they answer, so they would be choosing blind.', {
129
+ question: z.string().optional().describe('The question to display to the user. Keep concise (1-2 sentences). Required unless `questions` is given.'),
136
130
  context: z
137
131
  .string()
138
132
  .min(1)
@@ -144,10 +138,28 @@ server.tool('telecoder_ask_user', 'Ask the user a multiple-choice question via a
144
138
  }))
145
139
  .min(2)
146
140
  .max(8)
147
- .describe('Between 2 and 8 options for the user to choose from.'),
148
- }, async ({ question, context, options }) => {
141
+ .optional()
142
+ .describe('Between 2 and 8 options for the user to choose from. Required unless `questions` is given.'),
143
+ questions: z
144
+ .array(z.object({
145
+ question: z.string().min(1).describe('One question, 1-2 sentences.'),
146
+ options: z
147
+ .array(z.object({
148
+ label: z.string().describe('Button label; ≤ 25 chars keeps it on its button.'),
149
+ description: z.string().optional().describe('Optional one-line note shown in the body.'),
150
+ }))
151
+ .min(2)
152
+ .max(8),
153
+ }))
154
+ .min(1)
155
+ .max(4)
156
+ .optional()
157
+ .describe('Several related questions as one form, in place of `question`/`options`. The user answers each with a button or in their own words, can go back and change any answer, and nothing is sent until they tap Submit — like AskUserQuestion with several questions. 2-4 questions, 2-8 options each; `context` is shown once at the top.'),
158
+ }, async ({ question, context, options, questions }, extra) => {
149
159
  try {
150
- const result = await ipc('/mcp/ask_user', { question, context, options });
160
+ // The signal lets the bot close the question when claude cancels the
161
+ // call, rather than leave it waiting out the clock.
162
+ const result = await ipc('/mcp/ask_user', { question, context, options, questions }, extra.signal);
151
163
  return toolResult(result);
152
164
  }
153
165
  catch (error) {
@@ -208,7 +220,7 @@ server.tool('telecoder_create_bot', "Create a Telegram bot for one project: send
208
220
  }
209
221
  });
210
222
  // ── telecoder_send_file (IPC: needs bot for Telegram sendDocument) ──
211
- server.tool('telecoder_send_file', 'Send a file from the server to the user via Telegram. The file must be within the current working directory or /tmp. Use this after creating files (SVGs, images, reports, etc.) to deliver them directly to the user. Maximum file size: 50MB.', {
223
+ server.tool('telecoder_send_file', 'Send a file from the server to the user via Telegram. The file must be within the project (or the workspace, for an admin) or /tmp; credential files such as .env or ~/.ssh are never sent. Use this after creating files (SVGs, images, reports, etc.) to deliver them directly to the user. Maximum file size: 50MB.', {
212
224
  file_path: z.string().describe('Absolute or workspace-relative path to the file to send.'),
213
225
  caption: z.string().optional().describe('Optional caption to display with the file in Telegram.'),
214
226
  }, async ({ file_path, caption }) => {
@@ -223,54 +235,27 @@ server.tool('telecoder_send_file', 'Send a file from the server to the user via
223
235
  };
224
236
  }
225
237
  });
226
- // ── telecoder_set_topic (IPC: needs bot for Telegram setMyName) ─────
227
- if (process.env.TELECODER_DYNAMIC_BOT_NAME === 'true') {
228
- server.tool('telecoder_set_topic', 'Update the conversation topic shown in the bot display name. Call this proactively when the work topic changes. Pass an empty string to clear. Keep topics very short (1-4 words, e.g. "auth refactor", "CI fix", "dark mode").', {
229
- topic: z.string().describe('Short topic label (1-4 words). Empty string to clear.'),
230
- }, async ({ topic }) => {
231
- try {
232
- const result = await ipc('/mcp/set_topic', { topic });
233
- return {
234
- content: [{
235
- type: 'text',
236
- text: result.message || (result.success ? `Topic set to "${topic}".` : 'Topic update failed.'),
237
- }],
238
- isError: !result.success,
239
- };
240
- }
241
- catch (error) {
242
- return {
243
- content: [{ type: 'text', text: `set_topic error: ${error instanceof Error ? error.message : String(error)}` }],
244
- isError: true,
245
- };
246
- }
247
- });
248
- }
249
- // ── telecoder_publish_telegraph ─────────────────────────────────────
250
- if (process.env.TELECODER_TELEGRAPH_ENABLED === 'true') {
251
- server.tool('telecoder_publish_telegraph', 'Publish markdown content as a Telegraph (telegra.ph) Instant View page. Returns the URL. Useful for sharing long-form content as a readable link.', {
252
- title: z.string().describe('Page title'),
253
- markdown: z.string().describe('Markdown content for the page'),
254
- }, async ({ title, markdown }) => {
255
- try {
256
- const { createTelegraphPage } = await importTelegraph();
257
- const url = await createTelegraphPage(title, markdown);
258
- if (!url) {
259
- return {
260
- content: [{ type: 'text', text: 'Failed to create Telegraph page.' }],
261
- isError: true,
262
- };
263
- }
264
- return { content: [{ type: 'text', text: `Telegraph page created: ${url}` }] };
265
- }
266
- catch (error) {
267
- return {
268
- content: [{ type: 'text', text: `Telegraph error: ${error instanceof Error ? error.message : String(error)}` }],
269
- isError: true,
270
- };
271
- }
272
- });
273
- }
238
+ // ── telecoder_set_topic (IPC: the topic lives in the bot's state) ────
239
+ server.tool('telecoder_set_topic', 'Update the conversation topic shown in the footer under each reply and as the thread\'s name. Call this proactively when the work topic changes. Pass an empty string to clear. Keep topics very short (1-4 words, e.g. "auth refactor", "CI fix", "dark mode").', {
240
+ topic: z.string().describe('Short topic label (1-4 words). Empty string to clear.'),
241
+ }, async ({ topic }) => {
242
+ try {
243
+ const result = await ipc('/mcp/set_topic', { topic });
244
+ return {
245
+ content: [{
246
+ type: 'text',
247
+ text: result.message || (result.success ? `Topic set to "${topic}".` : 'Topic update failed.'),
248
+ }],
249
+ isError: !result.success,
250
+ };
251
+ }
252
+ catch (error) {
253
+ return {
254
+ content: [{ type: 'text', text: `set_topic error: ${error instanceof Error ? error.message : String(error)}` }],
255
+ isError: true,
256
+ };
257
+ }
258
+ });
274
259
  // ── telecoder_poll_user (IPC: Telegram poll) ────────────────────────
275
260
  server.tool('telecoder_poll_user', 'Ask the user (or a group) a question via a Telegram poll. Prefer this over telecoder_ask_user when (a) multiple chat members should vote, (b) you want vote counts shown alongside, or (c) you need multi-select. Polls are non-anonymous (vote identities visible). Resolves on the first vote — for multi-select, the snapshot at that moment is returned. 2-10 options.', {
276
261
  question: z.string().describe('The poll question. ≤ 300 chars (Telegram cap).'),